How do you get through the third gym leader in Pokemon leaf green?

When you go in the 3rd gym leader's gym, you'll see lots of trash cans, a few trainers and 2 electric locks. Press A on the cans and it'll tell you if there is a switch under it. If so, 1 electric lock will disable. If you're lucky and press A on the other can with a switch, both locks will be disabled and you can go to the leader. If you mess up, the locks will reset and the switches will move to different cans. If you succeed in disabling the locks and heal your Pokemon at the Pokemon Center, the locks will stay disabled.