@betlista I wouldn’t consider them as cheating. Sorting and searching are commonly known algorithms and these questions are mostly asked by beginners who want to learn. If you look at my answer and other answers they are general answers and not specific to any question. This info is easily available on others sites also. However asking question specific details is certainly unwelcome.
why following statement are used ? (co[i]%2)*i and now+=co[i]; ??
where as to alternate the addition and subtraction we could have just toggle a boolean variable or just checked if i%2==0 or not that could have done the job as well?
rest of the part is very clear friend
just not able to understand the use of these two statements.
t = int(raw_input())
t -= 1
n, a, b, c, d = map(int, raw_input().split())
h =  * 1000000
h[d] = 1
for i in range(n-1):
d = ( ((d * d * a) % 1000000) + (b*d) + c) % 1000000
h[d] += 1
ans = 0
is_x = True
for i in range(999999, -1, -1):
temp = h[i]
if temp % 2 == 1:
ans += i
is_x = False
ans -= i
is_x = True
it’s because when you have 2 2 2 in input above, you do not need to add first 2 to first team, second to second team and last to first team… as you can see, if number of elements is even you do not need to add it (because one half belong to one team and another one to another team) and that’s exactly what (co[i]%2)*i is doing…
now is a index for team members, so when you added co[i] members, you need to increment it by co[i]…