Jack and Jelly are on the ship en route to discover Atlantis and decide to play a game. The distance between their starting point and the city of Atlantis is N kilometers. They take turns manning the ship and each of them can steer the ship for 1, 2, or 4 kilometers in one turn. This should never exceed the remaining distance. The captain who is in charge of the ship when they react Atlantis wins the game.
If Jelly starts as the captain in charge of the ship, find who wins the game, i.e., who will be in charge of the ship when they reach Atlantis given both Jack and Jelly play optimally.
Example 1:
Input: N = 2
Output: JELLY
Explaination: Jelly can cover 2 Km 
in his first turn itself.
Example 2:
Input: N = 3
Output: JACK
Explaination: On his first turn Jelly can 
cover either 1 or 2km. In either case, Jack 
will cover the remaining distance in his turn.
 
Your Task:
You do not need to read input or print anything. Your task is to complete the function captain() which takes the N as the input parameter and returns a string ("JACK" or "JELLY") denoting the name of the final captain.
 
Expected Time Complexity: O(1)
Expected Auxiliary Space: O(1)
 
Constraints:
1 ≤ N ≤ 10^{7}

Source: geeksforgeeks | Difficulty: EASY
Tags: Game theory

Starter code: #User function Template for python3



class Solution:

    def captain(self, N):

        # code here

Solutions:
class Solution:

	def captain(self, N):
		if N % 3 == 0:
			return 'JACK'
		return 'JELLY'


class Solution:

	def captain(self, n):
		if n % 3 != 0:
			return 'JELLY'
		else:
			return 'JACK'
if __name__ == '__main__':
	t = int(input())
	for _ in range(t):
		N = int(input())
		ob = Solution()
		print(ob.captain(N))


class Solution:

	def captain(self, n):
		if n % 3 == 0:
			return 'JACK'
		else:
			return 'JELLY'


class Solution:

	def captain(self, N):
		if not N % 3:
			return 'JACK'
		return 'JELLY'


def helper(N, player):
	if N < 0:
		return player
	if N in [1, 2, 4]:
		return player
	if player == -1:
		return min(helper(N - 1, player * -1), helper(N - 2, player * -1), helper(N - 4, player * -1))
	else:
		return max(helper(N - 1, player * -1), helper(N - 2, player * -1), helper(N - 4, player * -1))

class Solution:

	def captain(self, N):
		if N % 3 == 0:
			return 'JACK'
		else:
			return 'JELLY'