Harryxun/sft_time huggingface dataset:
### BUGGY CODE ###

import numpy as np
N = int(input())
A=np.array([])
for i in range(N):
    A=np.append(A, int(input()) )

max_index=np.argmax(A)
a_max=int(A[max_index])
a_second=int(np.amax(np.delete(A,max_index)))
A[:]=a_max
A[max_index]=a_second
for a in A:
    print(int(a))

### FIXED CODE ###

import numpy as np
N = int(input())
A = np.array([int(input()) for i in range(N)])

max_index=np.argmax(A)
a_max=int(A[max_index])
a_second=int(np.amax(np.delete(A,max_index)))
A[:]=a_max
A[max_index]=a_second
for a in A:
    print(int(a))
### BUGGY CODE ###

def prime_t(t):
    i=2
    while i**2<=t:
        if t%i==0:
            return 0
        i+=1
    return 1
d=[]
n=10**5+1
for i in range(2,n):
    if prime_t(i):
        d.append(i)

q=int(input())
for i in range(q):
    ans=0
    l,r=map(int,input().split())
    for j in range(l,r+1,2):
        if (j in d and (j+1)//2 in d): ans+=1
    print(ans)


### FIXED CODE ###

def prime_t(t):
    i=2
    while i**2<=t:
        if t%i==0:
            return 0
        i+=1
    return 1
d=set([])
n=10**5+1
p=[0]*(10**5+1)
for i in range(2,n):
    if prime_t(i):
        d.add(i)
    if (i in d and (i+1)//2 in d): p[i]=p[i-1]+1
    else: p[i]=p[i-1]

q=int(input())
for i in range(q):
    ans=0
    l,r=map(int,input().split())
    print(p[r]-p[l-1])
### BUGGY CODE ###

N,M=map(int,input().split())


a=[]
count_AC=0
count_WA=0
for i in range(M):
    a.append(input().split())


AC=[]
for i in a:
    if i[1]=="AC" and not(i[0] in AC):
        AC.append(i[0])
for i in a:
    if i[0] in AC:
        if i[1]=="AC":
            count_AC+=1
            AC.remove(i[0])
        else:
            count_WA+=1




print(count_AC,count_WA,sep=" ")


### FIXED CODE ###

N,M=map(int,input().split())


ac = 0
wa = 0
aclist = {}
walist = {}

count_WA=0
for i in range(N):
    aclist[i + 1] = 0
    walist[i + 1] = 0

for i in range(M):
    a,b=input().split()
    a=int(a)
    if aclist[a] == 1:
        continue
    elif b == 'WA':
        walist[a] += 1
    elif b == 'AC':
        aclist[a] += 1
        ac += 1
        wa += walist[a]




print(ac,wa,sep=" ")
### BUGGY CODE ###

n = int(input())
a = [int(an) for an in input().split()]
q = int(input())

for i in range(q):
    stdins = input().split()
    for j in range(n):
        if a[j] == int(stdins[0]):
            a[j] = int(stdins[1])
    ans = sum([int(an) for an in a])
    print(ans)


### FIXED CODE ###

n = int(input())
a = input().split()

a_cnts = {}
a_sum = 0
for an in a:
    if an in a_cnts.keys():
        a_cnts[an] += 1
    else:
        a_cnts[an] = 1
    a_sum += int(an)

q = int(input())

for i in range(q):
    (b, c) = input().split()

    if b in a_cnts.keys():
        hit_cnt = a_cnts[b]
        del a_cnts[b]
        if c in a_cnts.keys():
            a_cnts[c] += hit_cnt
        else:
            a_cnts[c] = hit_cnt
        a_sum += (int(c) - int(b))*hit_cnt

    print(a_sum)
### BUGGY CODE ###

import sys
input = sys.stdin.readline
 
n = int(input())
l = list(map(int, input().split()))
 
cnt = 0
for i in range(n):
  a = l[i]
  for j, b in enumerate(l[i+1:]):
    for c in l[i+j+2:]:
      if (a < b+c) and (b < a+c) and (c <  a+b):
        cnt += 1
        
print(cnt)

### FIXED CODE ###

import bisect
import sys
input = sys.stdin.readline
 
n = int(input())
l = [int(li) for li in input().split(' ')]
l.sort()

cnt = 0
for i in range(n):
  for j in range(i+1, n):
    cnt += bisect.bisect_left(l, l[i]+l[j])-j-1
    
print(cnt)
### BUGGY CODE ###

import numpy as np

N = int(input())
P = [int(i) for i in input().split()]

res = 1

for i in range(N-1, 0, -1):
    m = min(P[:i])
    if m > P[-1]:
        res += 1
    P = P[:-1]

print(res)

### FIXED CODE ###

import numpy as np

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

res = 0
min_ = 2*10**5

for i in range(0, N):
    if P[i] <= min_:
        res += 1
    
        min_ = P[i]

print(res)
### BUGGY CODE ###

n=int(input())
lis=list(map(lambda x:format(int(x),'b'),input().split()))
l=0
for i in range(n):
    l=max(l,len(lis[i]))

d=[[0]*2 for _ in range(60)]

for i in range(n):
    lis[i]=lis[i].zfill(l)
    for j in range(l):
        d[j][int(lis[i][-j-1])]+=1

ans=0
for i in range(60):
    ans+=(d[i][0]*d[i][1]*2**i)%(10**9+7)
print(ans%(10**9+7))

### FIXED CODE ###

n=int(input())
lis=list(map(lambda x:format(int(x),'b'),input().split()))
l=0
for i in range(n):
    l=max(l,len(lis[i]))

d0=[0]*60
d1=[0]*60

for i in range(n):
    lis[i]=lis[i].zfill(l)
    for j in range(l):
        if lis[i][-j-1]=='0':
            d0[j]+=1
        else:
            d1[j]+=1

ans=0
for i in range(60):
    ans+=(d0[i]*d1[i]*2**i)%(10**9+7)
print(ans%(10**9+7))
### BUGGY CODE ###

import itertools
import math
import string
import collections
from collections import Counter
from collections import deque
import sys
sys.setrecursionlimit(2*10**5)
INF = 2**60


def readints():
    return list(map(int, input().split()))


def nCr(n, r):
    return math.factorial(n)//(math.factorial(n-r)*math.factorial(r))


def has_duplicates2(seq):
    seen = []
    for item in seq:
        if not(item in seen):
            seen.append(item)
    return len(seq) != len(seen)


def divisor(n):
    divisor = []
    for i in range(1, n+1):
        if n % i == 0:
            divisor.append(i)
    return divisor


# coordinates
dx = [-1, -1, -1, 0, 0, 1, 1, 1]
dy = [-1, 0, 1, -1, 1, -1, 0, 1]
n = int(input())
a = []
for i in range(n):
    a.append(int(input()))
for i in range(n):
    print(max(a[:i]+a[i+1:]))


### FIXED CODE ###

import itertools
import math
import string
import collections
from collections import Counter
from collections import deque
import sys
sys.setrecursionlimit(2*10**5)
INF = 2**60


def readints():
    return list(map(int, input().split()))


def nCr(n, r):
    return math.factorial(n)//(math.factorial(n-r)*math.factorial(r))


def has_duplicates2(seq):
    seen = []
    for item in seq:
        if not(item in seen):
            seen.append(item)
    return len(seq) != len(seen)


def divisor(n):
    divisor = []
    for i in range(1, n+1):
        if n % i == 0:
            divisor.append(i)
    return divisor


# coordinates
dx = [-1, -1, -1, 0, 0, 1, 1, 1]
dy = [-1, 0, 1, -1, 1, -1, 0, 1]
n = int(input())
a = []
for _ in range(n):
    a.append(int(input()))
b = sorted(a)
max = b[-1]
max_sec = b[-2]

for A in a:
    if A == max:
        print(max_sec)
    else:
        print(max)
### BUGGY CODE ###

import fractions
from functools import reduce


def lcm_base(x, y):
    return (x * y) // fractions.gcd(x, y)


def lcm(*numbers):
    return reduce(lcm_base, numbers, 1)


def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)
N = int(input())
Alist = list(map(int, input().split()))
l = lcm_list(Alist)
ans = 0
for a in Alist:
    ans += l//a
print(ans%(10**9+7))


### FIXED CODE ###

import sys
input = sys.stdin.readline
N = map(int, input().split())
Alist = list(map(int, input().split()))
import fractions
from functools import reduce


def lcm_base(x, y):
    return (x * y) // fractions.gcd(x, y)


def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)


lcm_a = lcm_list(Alist)
mod = 10**9 + 7
ans = 0

for a in Alist:
    ans += (lcm_a // a)
print(ans % mod)
### BUGGY CODE ###

n = int(input())
a = list(map(int, input().split()))
accu = [0]*20
ans = 0
r = 0
for l in range(n):
    while r<n:
        tmp = accu[:]
        for i in range(20):
            tmp[i] += a[r]>>i&1
        if max(tmp)==2:
            break
        accu = tmp
        r += 1
    ans += r-l
    for i in range(20):
        accu[i] -= a[l]>>i&1
print(ans)

### FIXED CODE ###

n = int(input())
a = list(map(int, input().split()))
accu = [0]*20
ans = 0
r = 0
for l in range(n):
    while r<n:
        tmp = accu[:]
        for i in range(20):
            tmp[i] += a[r]>>i&1
        if max(tmp)==2:
            break
        accu = tmp
        r += 1
    ans += r-l
    for i in range(20):
        accu[i] -= a[l]>>i&1
print(ans)
### BUGGY CODE ###

import sys
sys.setrecursionlimit(10**9)
def bfs(v,G,queue,dist,pre):
    dist[0] = 0
    seen[v] = True
    for vertex in G[v]:
        if seen[vertex]:
            continue
        elif vertex in queue:
            continue
        queue.append(vertex)
        dist[vertex] = dist[v] + 1
        pre[vertex] = v
    for elements in queue:
        queue.remove(elements)
        bfs(elements,G,queue,dist,pre)
N,M = map(int,input().split())
dist = [-1 for _ in range(N)]
seen = [False for _ in range(N)]
G = dict()
for i in range(N):
    G[i] = []   
for _ in range(M):
    a,b = map(int,input().split())
    G[a-1].append(b-1)
    G[b-1].append(a-1)
queue = []
pre = [0 for _ in range(N)]
bfs(0,G,queue,dist,pre)
print("Yes")
for v in range(1,N): 
    print(pre[v]+1)

### FIXED CODE ###

def main():
    import sys
    sys.setrecursionlimit(10**9)
    from sys import stdin
    def input() : return stdin.readline().rstrip()
    N,M = map(int,input().split())
    dist = [-1] * N
    G = dict()
    for i in range(N):
        G[i] = []   
    for _ in range(M):
        a,b = map(int,input().split())
        G[a-1].append(b-1)
        G[b-1].append(a-1)
    q = [0]
    pre = [0] * N
    dist[0] = 0
    while (q != []):
        v = q[0]
        q.remove(q[0])
        for vertex in G[v]:
            if dist[vertex] != -1:
                continue
            dist[vertex] = dist[v] + 1
            pre[vertex] = v
            q.append(vertex)
    print("Yes")
    for v in range(1,N): 
        print(pre[v]+1)
if __name__ == '__main__':
    main()
### BUGGY CODE ###

s = [i for i in input()]
result=[0]*len(s)
# print(s,len(s))
# print(s[4:0:-1])
for i in range(len(s)):
	if s[i]=="R":
		index =s[i:].index("L")
		# sa = i-index
		if index%2==1:
			result[i+index-1]+=1
		else:
			result[i+index]+=1
	else:
		# print(s[i::-1])
		index =s[i::-1].index("R")
		if index%2==1:
			result[i-index+1]+=1
		else:
			result[i-index]+=1
print(" ".join(map(str,result)))
		


### FIXED CODE ###

s = [i for i in input()]
result=[0]*len(s)
R=0
L=0
# print(s,len(s))
# print(s[4:0:-1])
for i in range(len(s)):
	if s[i]=="R":
		# index =s[i:].index("L")
		# # sa = i-index
		# if index%2==1:
		# 	result[i+index-1]+=1
		# else:
		# 	result[i+index]+=1
		R=i
	else:
		# print(s[i::-1])
		# index =s[i::-1].index("R")
		if (i-R)%2==1:
			result[R+1]+=1
		else:
			result[R]+=1
for i in range(len(s)-1,-1,-1):
	if s[i]=="R":
		if (L-i)%2==1:
			result[L-1]+=1
		else:
			result[L]+=1

	else:
		L=i
print(" ".join(map(str,result)))
### BUGGY CODE ###

N=int(input())
S=input()
R=0

def judge(i,j,k):
  if S[i] != S[j] and S[i] != S[k] and S[j] != S[k]:
    if j-i != k-j:
      # print(i,j,k, "True")
      return True
  # print(i,j,k, "False")
  return False

for i in range(N):
  for j in range(i+1,N):
    for k in range(j+1,N):
      if judge(i,j,k):
        R+=1

print(R)

### FIXED CODE ###

n = int(input())
s = input()
result = 0

r = s.count('R')
g = s.count('G')
b = s.count('B')

result = r * g * b
count = 0

for i in range(n):
    for j in range(i, n):
        k = 2 * j - i
        if j < k < n:
            if s[i] != s[j] and s[i] != s[k] and s[j] != s[k]:
                count += 1

print(result-count)
### BUGGY CODE ###

import sys
input = sys.stdin.readline

N = int(input())
A = [int(x) for x in input().split()]

A.append(1)

def test(x):
    digit = [0]
    cnt = [0]
    for a in A:
        if digit[-1] < a:
            digit.append(a)
            cnt.append(1)
            continue
        if digit[-1] == a:
            cnt[-1] += 1
            continue
        while True:
            # 繰り上がり処理をしながら左に戻る
            n = digit[-1]
            k = cnt[-1]
            if n <= a:
                break
            digit.pop()
            cnt.pop()
            if k <= x:
                continue
            if digit[-1] == n-1:
                cnt[-1] += (k-1)//x
            else:
                digit.append(n-1)
                cnt.append((k-1)//x + 1)
        if digit[-1] == a:
            cnt[-1] += 1
        else:
            digit.append(a)
            cnt.append(2)
    return cnt[1] <= x+1

if all(x<y for x,y in zip(A[:-2],A[1:-1])):
    print(1)
    exit()

left = 1 # 無理
right = N # 可能
while right > left + 1:
    mid = (left+right)//2
    if test(mid):
        right = mid
    else:
        left = mid

answer = right
print(answer)

### FIXED CODE ###

import sys
input = sys.stdin.readline

N = int(input())
A = [int(x) for x in input().split()]

A.append(1)

def test(x):
    digit = [0]
    cnt = [0]
    for a in A:
        if digit[-1] < a:
            digit.append(a)
            cnt.append(1)
            continue
        if digit[-1] == a:
            cnt[-1] += 1
            continue
        while True:
            # 繰り上がり処理をしながら左に戻る
            if digit[-1] <= a:
                break
            n = digit.pop()
            k = cnt.pop()
            if k <= x:
                continue
            if digit[-1] == n-1:
                cnt[-1] += (k-1)//x
            else:
                digit.append(n-1)
                cnt.append((k-1)//x + 1)
        if digit[-1] == a:
            cnt[-1] += 1
        else:
            digit.append(a)
            cnt.append(2)
    return cnt[1] <= x+1

if all(x<y for x,y in zip(A[:-2],A[1:-1])):
    print(1)
    exit()

left = 1 # 無理
right = N # 可能
while right > left + 1:
    mid = (left+right)//2
    if test(mid):
        right = mid
    else:
        left = mid

answer = right
print(answer)
### BUGGY CODE ###

def resolve():
    '''
    code here
    '''
    import collections
    N, K = [int(item) for item in input().split()]
    A_list = [int(item) for item in input().split()]

    bit_k = bin(K)[2:]

    telepo_list = collections.deque([A_list])

    for _ in range(len(bit_k)-1):
        temp_list = telepo_list[-1]
        new_telep = collections.deque([])
        for i in temp_list:
            new_telep.append(temp_list[i-1])

        telepo_list.append(new_telep)

    # print(telepo_list)

    goto = 1
    for i in range(len(bit_k)):
        temp_list = telepo_list.popleft()
        if ((K >> i) & 1): 
            goto = temp_list[goto -1]
            # print(i, goto)

    print(goto)

if __name__ == "__main__":
    resolve()


### FIXED CODE ###

def resolve():
    '''
    code here
    '''
    import collections
    N, K = [int(item) for item in input().split()]
    A_list = [int(item) for item in input().split()]
    order_dict = dict(zip(range(1,N+1),A_list))

    foot_print = [-1 for _ in range(N+1)]
    loop_que = collections.deque([1])

    goto = 1

    while foot_print[goto] == -1:
        foot_print[goto] = 1
        goto = order_dict[goto]
        loop_que.append(goto) 

    loop_start = loop_que.index(goto) + 1
    loop_len = len(loop_que) - loop_start

    # print(loop_que)
    # print(loop_start, loop_len)


    data_list = list(loop_que)
    if K >= len(loop_que):
        temp_K = K - loop_start + 1
        temp_K %= loop_len
        temp_loop = data_list[loop_start-1:-1]
        print(temp_loop[temp_K])
    else:

        print(data_list[K])

if __name__ == "__main__":
    resolve()
### BUGGY CODE ###

import sys
sys.setrecursionlimit(10**6)
input = sys.stdin.readline
from collections import deque

H,W = map(int,input().split())
INF = 10**18
q = deque()

d = [[INF]*W for _ in range(H)] # '#'からの距離

for i in range(H):
  for j,c in enumerate(input()):
    if c == '#':
      d[i][j] = 0
      q.append((0,i,j))

      
ans = 0
while q:
  dv,x,y = q.popleft()
  for dx,dy in [(0,1),(0,-1),(1,0),(-1,0)]:
    xx = x+dx
    yy = y+dy
    if xx == -1 or xx == H:
      continue
    if yy == -1 or yy == W:
      continue
    if d[xx][yy] == INF:
      d[xx][yy] = dv+1
      ans = dv+1
      q.append((dv+1,xx,yy))

print(ans)


### FIXED CODE ###

import sys
sys.setrecursionlimit(10**6)
input = sys.stdin.readline

H,W = map(int,input().split())
INF = 10**18
q = []

visited = [[True]*(W+2)]
visited += [[True] + [x == '#' for x in input().rstrip()] + [True] for _ in range(H)]
visited.append([True]*(W+2))
  
for i in range(1,H+1):
  for j in range(1,W+1):
    if visited[i][j]:
      q.append((i,j))

moves = [(0,1),(0,-1),(1,0),(-1,0)]

ans = -1
while q:
  qq = []
  ans += 1
  for x,y in q:
    if not visited[x-1][y]:
      visited[x-1][y] = True
      qq.append((x-1,y))
    if not visited[x+1][y]:
      visited[x+1][y] = True
      qq.append((x+1,y))
    if not visited[x][y-1]:
      visited[x][y-1] = True
      qq.append((x,y-1))
    if not visited[x][y+1]:
      visited[x][y+1] = True
      qq.append((x,y+1))
  q = qq
  
print(ans)
### BUGGY CODE ###

# -*- coding: utf-8 -*-
def inpl(): return list(map(int, input().split()))
from copy import deepcopy

N, K = inpl()
A = sorted(inpl(), reverse=True)

DP = [False for _ in range(K)]
DP[0] = 1
OK = [False for _ in range(N)]

for i, a in enumerate(A):
    DP0 = deepcopy(DP)
    if a >= K:
        OK[i] = True
        continue
    for j, d in enumerate(DP0):
        if d:
            if j + a >= K:
                OK[i] = True
            else:
                DP[j+a] = True

if sum(OK) == 0:
    print(N)
else:
    print(OK[::-1].index(True)) 

### FIXED CODE ###

# -*- coding: utf-8 -*-
def inpl(): return list(map(int, input().split()))
 
N, K = inpl()
A = sorted(inpl())
S = []
s = 0
for a in A:
    s += a
    S.append(s)

A = A[::-1]
DP = [True]+[False for _ in range(K-1)]

OK = [False for _ in range(N)]
 
for i, a in enumerate(A):
    DP1 = [False] * K
    if a >= K:
        OK[i] = True
        continue
    for j, d in enumerate(DP[-S[::-1][i]:], max(0, K-S[::-1][i])):
        if d:
            DP1[j] = True
            if j + a >= K:
                OK[i] = True
                break
            else:
                DP1[j+a] = True
    DP = DP1 
if sum(OK) == 0:
    print(N)
else:
    print(OK[::-1].index(True))
### BUGGY CODE ###

N = int(input())
a = list(map(int, input().split()))
A = sum(a)
ans_list = [0] * (N - 1)

for i in range(1, N):
    x = sum(a[:i])
    ans_list[i - 1] = abs(A - 2 * x)

print(min(ans_list))

### FIXED CODE ###

N = int(input())
a = list(map(int, input().split()))
A = sum(a)
ans = 100 ** 100
x = 0

for i in range(N - 1):
    x += a[i]
    ans = min(ans, abs(A - 2 * x))

print(ans)
### BUGGY CODE ###

#16:38
n,m = map(int,input().split())
raw = [[] for _ in range(n)]
root = [1 for _ in range(n)]
for _ in range(n-1+m):
  a,b = map(int,input().split())
  a -= 1
  b -= 1
  raw[a].append(b)
  root[b] = 0
for i in range(n):
  if root[i] == 1:
    r = i
    break
pre = [-1 for _ in range(n)]
now = [r]
while now:
  last = now
  now = []
  for x in last:
    for y in raw[x]:
      pre[y] = x
      now.append(y)
print('\n'.join(map(lambda x: str(x+1) ,pre)))

### FIXED CODE ###

#16:38
n,m = map(int,input().split())
raw = [[] for _ in range(n)]
precnt = [0 for _ in range(n)]
root = [1 for _ in range(n)]
for _ in range(n-1+m):
  a,b = map(int,input().split())
  a -= 1
  b -= 1
  raw[a].append(b)
  precnt[b] += 1
  root[b] = 0
for i in range(n):
  if root[i] == 1:
    r = i
    break
pre = [-1 for _ in range(n)]
now = [r]
#print(precnt)
while now:
  last = now
  now = []
  for x in last:
    for y in raw[x]:
      precnt[y] -= 1
      if precnt[y] == 0:
        now.append(y)
      pre[y] = x
#print(pre)
#print(precnt)
for x in pre:
  print(x+1)
### BUGGY CODE ###

import sys
N=int(input())
lines = sys.stdin.readlines()
from collections import defaultdict
d = defaultdict(int)
for s in lines:
  d[s.rstrip('\n')]+=1
max_k_list = [kv[0] for kv in d.items() if kv[1] == max(d.values())]
max_k_list.sort()
for a in max_k_list:
  print(a)

### FIXED CODE ###

N=int(input())
S = [input() for i in range(N)]
S.sort()
import itertools
gr = itertools.groupby(S)
ans=[]
n=0
for key, group in gr:
  a=len(list(group))
  if a>n:
    ans=[]
    n=a
    ans.append(key)
  elif a==n:
    ans.append(key)
for a in ans:
  print(a)
### BUGGY CODE ###

n,m=map(int,input().split())
g=[set() for _ in range(n)]
for _ in range(m):
  a,b=map(int,input().split())
  a,b=a-1,b-1
  g[a].add(b)
  g[b].add(a)

start=0
spath={0}
path=[0]
todo=[0]
next=g[0].pop()
spath.add(next)
path.append(next)
while g[path[-1]]|spath!=spath:
  for j in g[path[-1]]-spath:
    spath.add(j)
    path.append(j)
    break
rpath=[0]
while g[rpath[-1]]|spath!=spath:
  for j in g[rpath[-1]]-spath:
    spath.add(j)
    rpath.append(j)
    break
#print(path)
#print(rpath)
rpath.reverse()
rpath.pop()
rpath+=path
rpath=[i+1 for i in rpath]
print(len(rpath))
print(*rpath,sep=' ')


### FIXED CODE ###

n,m=map(int,input().split())
g=[[] for _ in range(n)]
for _ in range(m):
  x,y=map(int,input().split())
  x,y=x-1,y-1
  g[x].append(y)
  g[y].append(x)

path=[g[0][0]]
pathr=[0]
#path=[12,4]
setpath=set([0,g[0][0]])
while True:
  flg=True
  for nv in g[path[-1]]:
    if nv not in setpath:
      flg=False
      path.append(nv)
      setpath.add(nv)
      break
  for nv in g[pathr[-1]]:
    if nv not in setpath:
      flg=False
      pathr.append(nv)
      setpath.add(nv)
      break
  if flg:break

print(len(path)+len(pathr))
pathr.reverse()
pathr+=path
path=[str(pi+1) for pi in pathr]
print(' '.join(path))
#print(path)
#print(setpath)
### BUGGY CODE ###

#D問題
N = int(input())
A = list(map(int,input().split()))

ruixor = [0]
ruisum = [0]
for i in range(N):
    if i == 0:
        ruixor.append(A[0])
        ruisum.append(A[0])
    else:
        ruixor.append(ruixor[-1]^A[i])
        ruisum.append(ruisum[-1]+A[i])
        
count = 0
for i in range(N+1):
    for j in range(N-i):
        l = i
        r = l+j+1
        if ruixor[r]^ruixor[l] == ruisum[r]-ruisum[l]:
            count+=1
            
print(count)

### FIXED CODE ###

#D問題
N = int(input())
A = list(map(int,input().split()))

srui = [0]
xrui = [0]

for a in A:
    srui.append(srui[-1]+a)
    xrui.append(xrui[-1]^a)
    
#print(srui,xrui)
ans = 0
J = 1
for i in range(N):
    I = i+1
    while J <= N and (srui[J]-srui[I-1]) == (xrui[J]^xrui[I-1]):
        J+=1
    J-=1
    ans += J-I+1
            
print(ans)
### BUGGY CODE ###

N, A, B=map(int, input().split(" "))

sum=0
flag=False
b=0

while True:
  sum=sum+A
  b=b+A
  if sum>N:
    flag=True
    break
  sum=sum+B
  if sum>N:
    break
if flag:
  print(b-(sum-N))
else:
  print(b)

### FIXED CODE ###

N, A, B=map(int, input().split(" "))

result=A*(N//(A+B))+min(N%(A+B), A)

print(result)
### BUGGY CODE ###

n, k, *p = map(int, open(0).read().split())

p = tuple(p)
max_r = 0
max_i = 0
pre = 0
for i in range(n-k+1):
  if pre > p[i+k-1]:
    pre = p[i]
    continue
  r = sum(p[i:i+k])
  pre = p[i]
  
  if r > max_r:
    max_r = r
    max_i = i
    
max_e = 0
for j in range(max_i, max_i+k):
  max_e += (p[j]+1)/2

print(max_e)

### FIXED CODE ###

n, k, *p = map(int, open(0).read().split())

q = []
for p_i in p:
  q.append((p_i+1)/2)
  
s = [0]
pre_s = 0
for q_i in q:
  pre_s += q_i
  s.append(pre_s)

ans = 0
for i in range(n-k+1):
  if ans < (s[i+k] - s[i]):
    ans = s[i+k] - s[i]
    
print(ans)
### BUGGY CODE ###

a, b, c, k = map(int, input().split())

for i in range(10**18):
    A = a
    B = b
    C = c
    a = B + C
    b = A + C
    c = A + B
    if i == k - 1:
        break
if abs(a - b) <= 10**18:
    print(a - b)
else:
    print('Unfair')


### FIXED CODE ###

a, b, c, k = map(int, input().split())
x = a - b
if x > 10**18:
    print('Unfair')
elif k % 2 == 0:
    print(x)
else:
    print(-x)
### BUGGY CODE ###

S = input()
length_substring_S = len(S)
test_str_list = ['dream', 'dreamer', 'erase', 'eraser']
flag = True

while flag == True:
  flag = False
  for i in range(len(test_str_list)):
    if S[0:length_substring_S].endswith(test_str_list[i]):
      length_substring_S -= len(test_str_list[i])
      flag = True
      break

if length_substring_S == 0:
  print('YES')
else:
  print('NO')

### FIXED CODE ###

S = input()
length_substring_S = len(S)
test_str_list = ['dream', 'dreamer', 'erase', 'eraser']
flag = True

while flag == True:
  flag = False
  for i in range(len(test_str_list)):
    if S[0:length_substring_S].endswith(test_str_list[i]):
      length_substring_S -= len(test_str_list[i])
      flag = True
      break

if length_substring_S == 0:
  print('YES')
else:
  print('NO')