Lengths matter

In a running competition, the runway is a circle, where the athlete needs to run for n circles to complete the run. Every 100 meters the athlete runs, he gets a letter (A - Z), so when completing a full circle, the athlete collects a whole string of letters.
There are 3 athletes that need to run in the competition and all of them need to run on different tracks, and therefore for different numbers of circles. We have been told what strings each athlete will collect after running a single circle, and we know how many circles each athlete will need to complete the run.
Our task is to print the number of the athlete that will run the shortest distance.
The input consists of 6 lines. Each pair of lines contains a string which are the letters the athlete collects when making a whole circle and a number which is the number of circles the athlete needs to make to complete the race.
Print the number of the athlete who will run the shortest distance (1, 2, or 3).
Input
Output
SHORT 30 VERYVERYLONGLONGRUNBUTONCE 1 SHORTSHORT 2
3
Explanation:
After the run, the athletes would have collected the following strings:
  1. SHORTSHORTSHORTSHORTSHORTSHORTSHORTSHORTSHORTSHORTSHORTSHORTSHORTSHORTSHORTSHORTSHORTSHORTSHORTSHORTSHORTSHORTSHORTSHORTSHORTSHORTSHORTSHORTSHORTSHORT
  1. VERYVERYLONGLONGRUNBUTONCE
  1. SHORTSHORTSHORTSHORT
So, the shortest one is the third.

Constraints

Time limit: 2 seconds

Memory limit: 512 MB

Output limit: 1 MB

To check your solution you need to sign in
Sign in to continue