trick-with-the-cards

Mr. X is performing a trick with the cards.  He has N cards, lets name them 1.....N, on a round table.
So card 1 is in between 2nd card and Nth card.  Initially all cards are upside down. His trick involves making all cards face up.

His trick is whenever he taps on a card, it flips (if card was originally upside down, after flipping its faces up, and vice-versa), but he is no ordinary magician, he makes the two adjacent cards (if any) also to flip with the single tap. Formally, if he taps ith card, then i-1, i, i+1 cards are flipped. (Note that if he taps Nth card, then he flips (N-1)th, Nth and 1st card.)

Our magician needs a helper, to assist him in his magic tricks. He is looking for someone who can predict minimum number of taps needed to turn all the cards facing up.

Input : 
First line of input contains T, the number of test cases.
Then T lines follows, each line contains N, the number of cards for that particular case.

Output : 
Print the output for each case in a single line.

Constraints : 
1 ≤ T ≤ 10^5 
0 ≤ N ≤ 10^15

SAMPLE INPUT
2
2
3

SAMPLE OUTPUT
1
1

Source: hackerearth | Difficulty: EASY
Tags: Implementation

Mathematics

Ad-hoc


Solutions:
test = eval(input())
while test>0:
	N = eval(input())
	if N==0:
		print("0")
	elif N<3:
		print("1")
	elif N%3==0:
		print(N/3)
	else:
		print(N)
	test = test-1


'''
# Read input from stdin and provide input before running code

name = raw_input('What is your name?\n')
print 'Hi, %s.' % name
'''
#print 'Hello World!'
T = int(input())
for x in range(T) :
	N = int(input())
	if 1<=N<=3 : N = 1
	if N%3==0 : N = N/3
	print(N)



t=eval(input())
while t>0:
	n=eval(input())
	if n<3 and n>0:
		print(1)
	elif n%3==0 and n>0:
		print((n/3))
	else:
		print(n)
	t-=1


t=int(input())
n=[]
for i in range(t):
	n.append(int(input()))
	if (n[i]%3==0):
		print(n[i]/3)
	elif (n[i]==2):
		print(1)
	else:
		print(n[i])


'''
# Read input from stdin and provide input before running code

name = raw_input('What is your name?\n')
print 'Hi, %s.' % name
'''

t = int(eval(input()))

for i in range(t):
	n=int(eval(input()))
	if n==0:
		ans=0
	elif n<=3:
		ans=1
	elif n%3!=0:
		ans=n
	else:
		ans=n/3
	print(ans)


remainingInput = int(input());
while remainingInput > 0:
	cardCount = int(input());
	if cardCount == 0:
		print(0)
	elif cardCount < 3:
		print(1)
	elif cardCount % 3 == 0:
		print(cardCount / 3)
	else:
		print(cardCount)
	remainingInput = remainingInput - 1


'''
# Read input from stdin and provide input before running code

name = raw_input('What is your name?\n')
print 'Hi, %s.' % name
'''

N = int(input())

for i in range(N):
	I = int(input())
	if I == 0:
		print(0)
	elif I < 3:
		print(1)
	elif I%3 == 0:
		print(I/3)
	else:
		print(I)


t = int (input())
for i in range (0, t) :
	n = int (input())
	if n == 0 : print("0")
	elif n <= 3 : print("1")
	elif n % 3 == 0 : print(n / 3)
	else : print(n)


t=input()
t=int(t)
for i in range(0,t):
	n=input()
	n=int(n)
	if(n==2):
		print(1)
	elif (n%3==0):
		print((n/3))
	elif (n%3==1) :
		print (n)
	elif (n%3==2) :
		print (n)
	


def card_list(test_case_count):
	number_of_card_list = []
	while test_case_count >= 1:
		no_of_cards = int(eval(input()))
		number_of_card_list.append(no_of_cards)
		test_case_count = test_case_count - 1
	return number_of_card_list



def minimal_attempts(total_card_list):
	toc=total_card_list
	for i in range(len(toc)):
		if toc[i] == 0:
			print((0))
		elif toc[i] < 3:
			print((1))
		elif toc[i] % 3 == 0:
			print((int(toc[i]/3)))
		else:
			print((toc[i]))


test_case_count = int(eval(input()))
total_card_list = card_list(test_case_count)
minimal_attempts(total_card_list)


noc = eval(input())
while noc:
	noc-=1
	ins = eval(input())
	ans = 0
	if ins == 0:
		ans = 0
	elif ins < 3:
		ans =1
	elif ins % 3 == 0:
		ans = ins /3
	else:
		ans = ins
	print(ans)    


import fileinput
def MinimumFlip(NumCard):
	Cards=NumCard
	if Cards%3==0:
		print(Cards/3)
	elif Cards==2 or Cards==1:
		print("1")
	elif Cards==0:
		print("0")       
	else:        
		print(Cards)

inp=[]
for line in fileinput.input():
	inp.append(line.strip())
T=int(inp[0])
if 1<=T<=100000:
	for i in range(1,T+1):
		N=int(inp[i])
		if 0<=N<=(10**15):
			MinimumFlip(N)


T = int(input())
while T>0:
	T=T-1
	N= int(input())
	cnt=0
	q = N//3
	r = N%3
	if N==1 or N==2:
		print(1)
	elif r==0:
		print(q)
	else:
		print(N)


'''
# Read input from stdin and provide input before running code

name = raw_input('What is your name?\n')
print 'Hi, %s.' % name
'''
T = int(input())
P = []
for i in range(T):
	temp = int(input())
	P.append(temp)
	
for i in range(T):
	res = 0
	if P[i] == 0:
		res = 0
	elif P[i] == 1 or P[i] == 2:
		res = 1
	elif P[i] % 3 == 0:
		res = P[i]/3
	else:
		res = P[i]
	print((str(res)))


'''
# Read input from stdin and provide input before running code

name = raw_input('What is your name?\n')
print 'Hi, %s.' % name
'''
test_cases = eval(input())
for i in range(test_cases):
	ip = eval(input())
	if ip<=3 and ip>0:
		print(1)
	elif ip == 0:
		print(0)
	elif ip%3==0:
		print(ip/3)
	else:
		print(ip)


n=eval(input())
while(n):
	n-=1
	a=eval(input())
	if a==0:
		print(0)
	elif a<3:
		print(1)
	elif a%3==0:
		print(a/3)
	else:
		print(a)


t=eval(input())
for i in range(t):
	n=eval(input())
	if n==0:
		print("0")
	elif n<3:
		print("1")
	elif n%3==0:
		print(n/3)
	else:
		print(n)


'''
# Read input from stdin and provide input before running code

name = raw_input('What is your name?\n')
print 'Hi, %s.' % name
'''
inp =int( input())
ls =[]
for i in range(0,int(inp)):
	a = int(input())
	ls.append(a)
	del(a)
for i in range(0,len(ls)):
	if ls[i] == 0:
		print((0))
		continue;
	elif ls[i] <3:
		print((1))
		continue;
	elif ls[i]%3==0:
		print((ls[i]/3))
		continue
	else:
		print((ls[i]))
		continue



for cases in range(int(input())):
	n = int(input())
	if n == 0:	
		print(0)
	elif n < 3:
		print(1)
	elif n%3 == 0:
		print(n/3)
	else:
		print(n)