-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrgame.py
45 lines (37 loc) · 957 Bytes
/
rgame.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
summation = 0
initialProduct = 0
endProduct = 0
def addToEnd(inputList, x):
y = x
testList1 = inputList[:]
testList2 = inputList[:]
global endProduct
product1 = testList1[-1]*numbers[x]
endProduct += product1 * pow(2, N-x)
testList1.append(numbers[x])
x = x+1
if x == N:
x=x
if x<N :
addToEnd(testList1, x)
product2 = testList2[0]*numbers[y]
endProduct += product2 * pow(2, N-y)
testList2.insert(0, numbers[y])
y = y+1
if y == N :
y=y
if y<N :
addToEnd(testList2, y)
# return(endProduct+initialProduct)
testcases = int(raw_input())
if(testcases<1 or testcases>10):
exit()
for i in range(0, testcases):
N = int(raw_input())
if(N<1 or N>100000):
exit()
numbers = map(int,raw_input().split(" "))
testList = [numbers[0]]
addToEnd(testList, 1)
print(endProduct/2)
#print(endProduct+initialProduct)