# Practice on Toph

Participate in exhilarating programming contests, solve unique algorithm and data structure challenges and be a part of an awesome community.

# K-Game

By aminul · Limits 1s, 512 MB

To end the everlasting rivalry between Tom and Jerry, the Lady of the house found an Idea. She gives them a list of N numbers, denoted as A1, A2, A3, ... , An. And they play Q independent games.

In each game, she will give them two integers P and K. Then Tom makes the first move, he will take first K number starting from P'th position of the list, then Jerry will take the next K numbers starting from (K+P)'th position, then again Tom will take next K numbers starting from (2K + P)'th position and so on. They will keep playing alternatively until one of them takes the last number of the list.

Now, to determine the winner, after a game ends, the lady will sum up all the numbers Tom had taken and also sum up all the numbers Jerry had taken as well. Whoever has the greater sum, wins the game. A game is tied if both of them have equal sum. So in this problem, you will find the result of each game.

## Input

Input starts with two integers, N and Q which are number of integers in the given list and number of games to be played respectively.

Next line will contain N integers, A1, A2, A3, ... , An

Each of the next Q lines will contain two Integers P and K, which are described above.

Constraints
1 <= N, Q <= 105
|Ai| <= 109
1 <= P, K <= N

## Output

Print Q lines, name of the winner of each game which will be either "Tom" or "Jerry", or print "Tied" if both of them have same score. (Print without quotes, see the sample Input & Output for better understanding.)

## Sample

InputOutput
6 4
1 2 3 1 2 3
1 2
3 2
5 3
1 3

Tom
Jerry
Tom
Tied


Explanation of sample case:
First game: Tom starts from first number, he takes 1st and 2nd number. Then Jerry takes 3rd and 4th number, Tom then again takes 5th and 6th number. So overall Tom's score is 1 + 2 + 2 + 3 = 8 and Jerry's score is 3 + 1 = 4, so Tom wins the first game.
Second game: Tom will start from 3rd position, he will take 3rd, 4th number. His score is 3 + 1 = 4. Jerry will take 5th and 6th number, gives him a score of 2 + 3 = 5. So Jerry wins.
Third game: Tom starts from 5th number and also takes 6th number. Then the game ends as he takes the last number of list. So now Jerry has scored 0 and Tom has 2 + 3 = 5. Thus Tom wins.
Fourth game: First Tom takes first 3 numbers, then Jerry takes last three numbers, and they get equal sum, so the fourth game is tied.

• ### Statistics

43% Solution Ratio

practiceboyEarliest, Apr '20

fsshakkhorFastest, 0.1s

practiceboyLightest, 5.5 MB 