the-great-kian

View Russian Translation

The great Kian is looking for a smart prime minister. He's looking for a guy who can solve the OLP (Old Legendary Problem). OLP is an old problem (obviously) that no one was able to solve it yet (like P=NP).

But still, you want to be the prime minister really bad. So here's the problem:

Given the sequence a1, a2, ..., an find the three values a1 + a4 + a7 + ..., a2 + a5 + a8 + ... and a3 + a6 + a9 + ... (these summations go on while the indexes are valid).

Input
The first line of input contains a single integer n (1 ≤ n ≤ 10^5).

The second line contains n integers a1, a2, ..., an separated by space (1 ≤ ai ≤ 10^9).

Output
Print three values in one line (the answers).

SAMPLE INPUT
5
1 2 3 4 5SAMPLE OUTPUT
5 7 3

Source: hackerearth | Difficulty: EASY
Tags: Complete search


Solutions:
n = eval(input())
arr = list(map(eval, input().split()))
i = 0
a = 0
while(i<=(len(arr)-1)):
	a += arr[i]
	i+=3

j = 1
b = 0
while(j<=(len(arr)-1)):
	b += arr[j]
	j+=3


k = 2
c = 0
while(k<=(len(arr)-1)):
	c += arr[k]
	k+=3
	
print(a,b,c)


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

name = raw_input('What is your name?\n')
print 'Hi, %s.' % name
'''
n=eval(input())
sum1=0
sum2=0
sum3=0
i=1
n=n+1
arr=[0]+list(map(int,input().split()))
while i<n:
	if((i+2)%3==0):
	    sum1=sum1+arr[i]
	elif((i+1)%3==0):
	    sum2=sum2+arr[i]
	else:
		sum3=sum3+arr[i]
	i=i+1	
print(sum1, end=' ')
print(sum2, end=' ')
print(sum3)
	



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

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

num = int(input())
arr =   input().split()

length = len(arr)

sum1 = 0
sum2 = 0
sum3 = 0

for i in range(0, length, 3):
	sum1 += int(arr[i])

for i in range(1, length, 3):
	sum2 += int(arr[i])

for i in range(2, length, 3):
	sum3 += int(arr[i])

print(sum1, sum2, sum3)



n=int(input())
line=input()
a=line.split(" ")
n1=0
n2=0
n3=0
n1turn=True
n2turn=False
n3turn=False
for i in range(n):
	if n1turn:
		n1+=int(a[i])
		n2turn=True
		n1turn=False
	elif n2turn==True:
		n2+=int(a[i])
		n3turn=True
		n2turn=False
	elif n3turn==True:
		n3+=int(a[i])
		n1turn=True
		n3turn=False
	
print(str(n1)+" "+str(n2)+" "+str(n3))


'''
# 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())
ar = list(map(int, input().split()))
x = y = z = 0
for i in range(n):
	a = ar[i]
	if i % 3 == 0:
		x += a
	elif i % 3 == 1:
		y += a
	else:
		z += a
print(x, y, z)


n = int(input());
li = [int(x) for x in input().split()];
sum1,sum2,sum3=0,0,0;

for i in range(0,n,3):
	sum1 = sum1 + li[i];
	if i < n-1:
		sum2 = sum2 + li[i+1];
	if i < n-2:
		sum3 = sum3 + li[i+2];

print(sum1, sum2, sum3);


N = int(input())
L = list(map(int, input().split()))

a = [0, 0, 0]
for i in range(N):
	a[i%3] += L[i]

print(a[0], a[1], a[2])


import sys

N = int(sys.stdin.readline())
nums = [int(i) for i in sys.stdin.readline().split()]

ans = [0, 0, 0]
for idx, num in enumerate(nums):
	ans[idx % 3] += num

print(" ".join(map(str, ans)))


def main():
	n=eval(input())
	a=list(map(int, input().split()))
	s1=s2=s3=0
	for i in range(0,n,3):
		s1+=a[i]
	for i in range(1,n,3):
		s2+=a[i]
	for i in range(2,n,3):
		s3+=a[i]
	print(s1,s2,s3)
main()


m = eval(input())
z = [0] + [int(x) for x in input("").split(" ") if x.isdigit()]

x = sum([z[i] for i in range(1,len(z),3)])
y = sum([z[i] for i in range(2,len(z),3)])
z = sum([z[i] for i in range(3,len(z),3)])
print(x,y,z)

	


n=int(input())
line=input()
a=line.split(" ")
n1=0
n2=0
n3=0
n1turn=True
n2turn=False
n3turn=False
for i in range(n):
	if n1turn:
		n1+=int(a[i])
		n2turn=True
		n1turn=False
	elif n2turn==True:
		n2+=int(a[i])
		n3turn=True
		n2turn=False
	elif n3turn==True:
		n3+=int(a[i])
		n1turn=True
		n3turn=False
	
print(str(n1)+" "+str(n2)+" "+str(n3))


'''
# 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())
a = input().split(' ')
s1 = 0
s2 = 0
s3 = 0
for i in range(1,n+1):
	if i%3==1:
		s1 = s1 + int(a[i-1])
	if i%3==2:
		s2 = s2 + int(a[i-1])
	if i%3==0:
		s3 = s3 + int(a[i-1])
print(s1,s2,s3)
	


total = int(input().strip())
all_list = list(map(int, input().split()))
s1=s2=s3=0
for pos,i in enumerate(all_list):
	if(pos%3 == 0):
		s1+=i
		#print "s1",i,s1
	elif(pos%3 == 1):
		s2+=i
		#print "s2",i,s2
	elif(pos%3 == 2):
		s3+=i
		#print "s3",i,s3
print(s1,s2,s3)


input()
lst=list(map(int,input().strip().split()))
a= sum(lst[i] for i in range(0,len(lst),3))
b= sum(lst[i] for i in range(1,len(lst),3))
c= sum(lst[i] for i in range(2,len(lst),3))
print("%s %s %s" %(a,b,c))


n=int(input())
x=input()
x = [int(i) for i in x.split()]
b1=x[0:n:3]
sum1=sum(b1)
b2=x[1:n:3]
sum2=sum(b2)
b3=x[2:n:3]
sum3=sum(b3)
print(sum1,sum2,sum3)



        


'''
# 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())
a=list(map(int,input().split()))
fn=sn=tn=0
c1=1
c2=2
c3=3
for i in range(n):
	if c1 == i+1:
		fn=fn+a[i]
		c1=c1+3
	if c2 == i+1:
		sn=sn+a[i]
		c2=c2+3
	if c3 == i+1:
		tn=tn+a[i]
		c3=c3+3
print(fn,sn,tn)


n=eval(input())
n=n+1
arr=[0]+list(map(int,input().split()))
i,j,k=1,2,3
sumi,sumj,sumk=0,0,0
while i<n or j<n or k<n:
	if i<n:
		sumi=sumi+arr[i]
		i=i+3
	if j<n:
		sumj=sumj+arr[j]
		j=j+3
	if k<n:
		sumk=sumk+arr[k]
		k=k+3
print(sumi, end=' ')
print(sumj, end=' ')
print(sumk)



m = eval(input())
z = [0] + [int(x) for x in input("").split(" ") if x.isdigit()] + [0 for i in range(m)]

x = sum([z[i] for i in range(1,len(z),3)])
y = sum([z[i] for i in range(2,len(z),3)])
z = sum([z[i] for i in range(3,len(z),3)])
print(x,y,z)

	


total = int(input().strip())
all_list = list(map(int, input().split()))
s1=s2=s3=0
for pos,i in enumerate(all_list):
	if(pos%3 == 0):
		s1+=i
	elif(pos%3 == 1):
		s2+=i
	elif(pos%3 == 2):
		s3+=i
print(s1,s2,s3)


'''
# 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!'
n=int(input())
t= [int(i) for i in input().split(" ")]
sum0=sum1=sum2=0
for j in range(0,len(t),3):
	sum0+=t[j]
for j in range(1,len(t),3):
	sum1+=t[j]
for j in range(2,len(t),3):
	sum2+=t[j]
print((str(sum0)+" "+str(sum1)+" "+str(sum2)))


def main() :
	z = int(input());
	tab = input().split()
	a,b,c = 0,0,0
	for i in range(0,z) :
		if (i % 3 == 1) :
			a += int(tab[i]);
		if (i % 3 == 0) :
			c += int(tab[i]);
		if (i % 3 == 2) :
			b += int(tab[i]);
	print(c,a,b, end=' ')



main();



x=eval(input())
a=list(map(int,input().split()))
b=[]
c=[]
d=[]
i=0
j=len(a)
if len(a)%3==2:
	a.append(0)
elif len(a)%3==1:
	a.append(0)
	a.append(0)
	

while i<j:
	b.append(a[i])
	c.append(a[i+1])
	d.append(a[i+2])
	i=i+3
print(sum(b),sum(c),sum(d))
		


'''
# 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())
l = list(map(int, input().split()))
while len(l) % 3 != 0:
	l.append(0)
f = 0
s = 0
t = 0
for i in range(0,len(l)-2,3):
	f += l[i]
	s += l[i+1]
	t += l[i+2]
print(f, s, t)


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

name = raw_input('What is your name?\n')
print 'Hi, %s.' % name
'''
b=int(input())
a=list(map(int,input().split(" ")))
j=0
p=0
q=0
r=0
while(j<b):
	if(j%3==0):
		p+=int(a[j])
	elif((j-1)%3==0):
		q+=int(a[j])
	else:
		r+=int(a[j])
	j+=1
print(p,q,r)



i=eval(input())

a=0
v=[]
x=input()
l=x.split(" ")
for k in l:
	v.append(int(k))

a=1
sm=0

while(a<4):
	t=0
	sm=0

	while(3*t+a<=i):
		sm=sm+v[(3*t+a)-1]
		t+=1


	print(sm, end=' ')
	a+=1


m = eval(input())
z = [0] + [int(x) for x in input("").split(" ") if x.isdigit()]

print(sum([z[i] for i in range(1,len(z),3)]),sum([z[i] for i in range(2,len(z),3)]),sum([z[i] for i in range(3,len(z),3)]))


	


'''
# 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!'

n=eval(input())
n=int(n)

i=0
j=0
ans=input().split()
#ans = list(map(long,sys.stdin.readline().split()))
#arr = list(map(int, raw_input.split()))
#print (ans)
ans1 = 0
ans2 = 0
ans3 = 0
while i < n:
	ans1 = ans1 + int(ans[i])
	i=i+3
	
#print ans1    
i=1
while i < n:
	ans2 = ans2 + int(ans[i])
	i=i+3
	
#print ans2 

i=2
while i < n:
	ans3 = ans3 + int(ans[i])
	i=i+3
	
#print ans3
print(ans1, end=' ')
print(ans2, end=' ')
print(ans3)


a=int(input())
b=[int(x) for x in input().split(" ")]
if a == len(b):
	print(sum(b[0:a:3]), sum(b[1:a:3]),sum(b[2:a:3]))