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

N, K = map(int, input().split())
A = list(map(int, input().split()))
F = list(map(int, input().split()))
if K >= sum(A):
  print(0)
  exit()
A.sort(reverse=True)
F.sort()

#print('A:', A)
#print('F:', F)


res = K

lot = [A[k]*F[k] for k in range(N)]
#print(lot)
#print(res)

now = []
for k in range(N):
  now.append((-lot[k], k))
from heapq import heapify, heappop, heappush
from math import ceil
heapify(now)
#print(now)
f = heappop(now)
while res>0:
  #print(res)
  #print(now)
  s = heappop(now)
  big = lot[f[1]]
  small = lot[s[1]]
  cnt = ceil((big-small)/F[f[1]])
  if big == small:
    cnt = 1
  if cnt > A[f[1]]:
    print(lot[f[1]] - A[f[1]]*F[f[1]])
    exit()
  if cnt >= res:
    lot[f[1]] -= res*F[f[1]]
    break
  else:
    lot[f[1]] -= cnt*F[f[1]]
    A[f[1]] -= cnt
    res -= cnt
    heappush(now, (-lot[f[1]], f[1]))
  f = s
  
print(max(lot))

### FIXED CODE ###

from math import ceil
N, K = map(int, input().split())
A = list(map(int, input().split()))
F = list(map(int, input().split()))
if K >= sum(A):
  print(0)
  exit()
A.sort(reverse=True)
F.sort()
lot = []
for k in range(N):
  lot.append((A[k]*F[k], k))
lot.sort(key =  lambda x:x[0],reverse=True)
high = lot[0][0]
#print('A:', A)
#print('F:', F)
#rint(lot)
def binary_search(high):
  low = 0
  mid = (low + high) //2
  while low < high:
    final = False
    mid = (low + high) //2
    #print(low, high, mid)
    if low == high-1:
      final = True
    #print(low, high, mid)
    res = K
    flag = True
    for k in range(N):
      if res < 0:
        break
      else:
        if lot[k][0] <= mid:
          break
        else:
          res -= ceil((lot[k][0]-mid)/F[lot[k][1]])
          continue
    if res < 0:
      flag = False
    #print(flag)
    if flag:
      high = mid
    else:
      if final:
        mid += 1
      low = mid
    #print(low, high, mid)
  #return None
  return mid

print(binary_search(high))
### BUGGY CODE ###

import sys
sys.setrecursionlimit(10**8)

N,M = map(int,input().split())
src = [tuple(map(lambda x:int(x)-1,input().split())) for i in range(M)]
Q = int(input())
qs = [tuple(map(int,input().split())) for i in range(Q)]

es = [[] for i in range(N)]
for a,b in src:
    es[a].append(b)
    es[b].append(a)

cs = [0] * N
depth = [0] * N

def rec(v,d,c,pv):
    if d < depth[v]: return
    depth[v] = d
    if cs[v]==0:
        cs[v] = c
    if d==0: return
    for to in es[v]:
        if to==pv: continue
        rec(to,d-1,c,v)

for v,d,c in qs[::-1]:
    rec(v-1,d,c,-1)

print(*cs, sep='\n')

### FIXED CODE ###

import sys
sys.setrecursionlimit(101010)

N,M = map(int,input().split())
es = [[] for i in range(N)]
for i in range(M):
    a,b = map(lambda x:int(x)-1,input().split())
    es[a].append(b)
    es[b].append(a)
Q = int(input())
qs = [tuple(map(int,input().split())) for i in range(Q)]

mem = [[0,-1] for i in range(N)] # [color,depth] for v
def paint(v,d,c):
    mc,md = mem[v]
    if d <= md: return
    mem[v] = [mc if mc else c, d]
    if d == 0: return
    for to in es[v]:
        paint(to,d-1,c)

for v,d,c in reversed(qs):
    paint(v-1,d,c)
for c,d in mem:
    print(c)
### BUGGY CODE ###

# -*- coding: utf-8 -*-
x,y,z,k = map(int,input().split())
a,b,c = [],[],[]
a = list(map(int,input().split()))
b = list(map(int,input().split()))
c = list(map(int,input().split()))

ab = []

for i in range(x):
    for j in range(y):
        ab.append(a[i] + b[j])

ab.sort()
ab.reverse()

abc = []

for i in range(min(len(ab),k)):
    for j in range(min(z,k)):
        abc.append(ab[i] + c[j])

abc.sort()
abc.reverse()

for i in range(k):
    print(abc[i])


### FIXED CODE ###

# -*- coding: utf-8 -*-
x,y,z,k = map(int,input().split())
a,b,c = [],[],[]
a = list(map(int,input().split()))
b = list(map(int,input().split()))
c = list(map(int,input().split()))

ab = []

for i in range(x):
    for j in range(y):
        ab.append(a[i] + b[j])

ab.sort()

abc = []

for i in range(min(len(ab),k)):
    for j in range(min(z,k)):
        abc.append(ab[-(i+1)] + c[j])

abc.sort()

for i in range(k):
    print(abc[-(i+1)])
### BUGGY CODE ###

n=int(input())
A=list(map(int,input().split()))
from collections import Counter
C=Counter(A)
Q=C.values()
def qq(F):
    n=len(F)
    ans=0
    for i in range(n):
        ans+= F[i]*(F[i]-1)//2
    return ans
    
for i in range(n):
    j=A[i]
    C[j]-=1
    print(qq(list(C.values())))
    C[j]+=1

### FIXED CODE ###

n=int(input())
A=list(map(int,input().split()))
from collections import Counter
C=Counter(A)
Q=list(C.values())
def qq(F):
    n=len(F)
    ans=0
    for i in range(n):
        ans+= F[i]*(F[i]-1)//2
    return ans
ans=qq(Q)
for i in range(n):
    print(ans-C[A[i]]+1)
### BUGGY CODE ###

def main():
  N, M = list(map(int, input().split(' ')))

  root = [[] for i in range(N+1)]
  for i in range(M):
    A, B = list(map(int, input().split(' ')))
    root[A].append(B)
    root[B].append(A)

  mitisurube = [-1 for i in range(N+1)]
  next_ = [1]

  while next_:
    now_pos = next_.pop(0)
    for next_pos in root[now_pos]:
      if mitisurube[next_pos] == -1:
        mitisurube[next_pos] = now_pos
        next_.append(next_pos)
  #print('root')
  #print(*root)
  #print('cost')
  #print(*cost)
  #print('mitisirube')
  print('Yes')
  print(*mitisurube[2:], sep='\n')

if __name__ == '__main__':
  main()

### FIXED CODE ###

from collections import deque

def main():
  N, M = list(map(int, input().split(' ')))

  root = [[] for i in range(N+1)]
  for i in range(M):
    A, B = list(map(int, input().split(' ')))
    root[A].append(B)
    root[B].append(A)

  mitisurube = [-1 for i in range(N+1)]
  next_ = deque()
  next_.append(1)

  while next_:
    now_pos = next_.popleft()
    for next_pos in root[now_pos]:
      if mitisurube[next_pos] == -1:
        mitisurube[next_pos] = now_pos
        next_.append(next_pos)
  #print('root')
  #print(*root)
  #print('mitisirube')
  print('Yes')
  print(*mitisurube[2:], sep='\n')

if __name__ == '__main__':
  main()
### BUGGY CODE ###

N = int(input())
S = str(input())


S_R = []
S_G = []
S_B = []


for i in range(N):
    s = S[i]
    if (s == 'R'):
        S_R.append(i)
    if (s == 'G'):
        S_G.append(i)
    if (s == 'B'):
        S_B.append(i)

count = 0

for i in S_R[::1]:
    for j in S_G[::1]:
        abs_ij =abs(i-j)
        for k in S_B[::1]:
            if((abs_ij!=abs(j-k)) & (abs(j-k)!=abs(k-i))& (abs(k-i)!=abs_ij)):
                count+= 1

print(count)

### FIXED CODE ###

n = int(input())
s = input()
 
r, b, g = 0, 0, 0
for i in range(n):
    if s[i] == 'R':
        r += 1
    if s[i] == 'G':
        g += 1
    if s[i] == 'B':
        b += 1
ans = r * g * b
 
for i in range(n):
    for j in range(1, n // 2 + 1):
        if i + 2 * j >= n:
            break
        if s[i] != s[i+j] and s[i] != s[i+2*j] and s[i+j] != s[i+2*j]:
            ans -= 1
 
print(ans)
### BUGGY CODE ###

n,m=map(int,input().split())
t={}
w={}
p,q=set(),set()
for i in range(m):
    l,r,d=[int(i) for i in input().split()]
    t[(l,r)]=d
    if l in w:
        w[l].add((r,d))
    else:
        w[l]={(r,d)}
    p.add(l)
    q.add(r)
s=p-q
chk=set()
if len(s)==0:
    print(["No","Yes"][m==0])
    exit()
for i in s:
    chk.add((i,0))
    while len(chk):
        x=chk.pop()
        if x[0] in w:
            for j in w[x[0]]:
                if (i,j[0]) in t and t[(i,j[0])]!=x[1]+j[1]:
                #if (x[0],j[0]) in t and t[(i,j[0])]!=
                    print("No")
                    exit()
                elif (i,j[0]) not in t:
                    t[(i,j[0])]=x[1]+j[1]
                    chk.add((j[0],x[1]+j[1]))
                else:
                    chk.add((j[0],x[1]+j[1]))
print("Yes")

### FIXED CODE ###

def sol():
    n,m=map(int,input().split())
    t,w={},{}
    p,q=set(),set()
    for i in range(m):
        l,r,d=[int(i) for i in input().split()]
        if l in w: w[l].add((r,d))
        else: w[l]={(r,d)}
        p.add(l)
        q.add(r)
    s=p-q
    chk=set()
    if len(s)==0:
        print(["No","Yes"][m==0])
        exit()
    for i in s:
        chk.add((i,0))
        while len(chk):
            x=chk.pop()
            if x[0] in w:
                for j in w[x[0]]:
                    if (i,j[0]) in t and t[(i,j[0])]!=t[(i,x[0])]+j[1]:
                        print("No")
                        exit()
                    elif (i,j[0]) not in t:
                        #t[(i,j[0])]=t[(i,x[0])]+j[1]
                        t[(i,j[0])]=x[1]+j[1]
                        chk.add((j[0],x[1]+j[1]))
    print("Yes")

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

import sys
import itertools
sys.setrecursionlimit(1000000000)
from heapq import heapify,heappop,heappush,heappushpop
import math
import collections
MOD = 10**9 + 7

k,s = map(int,input().split())
cnt = 0
for i in range(k+1):
    for j in range(k+1):
        for l in range(k+1):
            d = i + j + l
            if d == s:
                cnt+=1
print(cnt)

### FIXED CODE ###

import sys
import itertools
sys.setrecursionlimit(1000000000)
from heapq import heapify,heappop,heappush,heappushpop
import math
import collections
MOD = 10**9 + 7

k,s = map(int,input().split())
cnt = 0
for i in range(k+1):
    for j in range(k+1):
        d = s - i - j
        if d>=0 and d<=k:
            cnt+=1

print(cnt)
### BUGGY CODE ###

h,w,m = map(int,input().split())

bombw = [0]*w
bombh = [0]*h
bomb = [""]*m
# print(bomb)
for i in range(m):
    hi,wi = map(int,input().split())
    bombw[wi-1] += 1
    bombh[hi-1] += 1
    bomb[i] = str(hi-1)+"-"+str(wi-1)
    # print(bomb)
maw = max(bombw)
mah = max(bombh)
# print(maw,mah)
inmaw = [i for i, x in enumerate(bombw) if x == maw]
inmah = [i for i, x in enumerate(bombh) if x == mah]
# print(inmaw,inmah)

ans = maw + mah
# print(bomb)
# print(ans)
for i in inmah:
    for j in inmaw:
        if str(i)+"-"+str(j) not in bomb:
            print(ans)
            exit()
print(ans-1)

### FIXED CODE ###

from collections import defaultdict

h,w,m = map(int,input().split())

bombw = [0]*w
bombh = [0]*h
dd = defaultdict(bool)
# print(bomb)
for i in range(m):
    hi,wi = map(int,input().split())
    bombw[wi-1] += 1
    bombh[hi-1] += 1
    dd[str(hi-1)+"-"+str(wi-1)] = True
    # print(bomb)
maw = max(bombw)
mah = max(bombh)
# print(maw,mah)
inmaw = [i for i, x in enumerate(bombw) if x == maw]
inmah = [i for i, x in enumerate(bombh) if x == mah]
# print(inmaw,inmah)

ans = maw + mah
# print(bomb)
# print(ans)
for i in inmah:
    for j in inmaw:
        if not dd[str(i)+"-"+str(j)]:
            print(ans)
            exit()
print(ans-1)
### BUGGY CODE ###

k, s = map(int,input().split())
cnt=0
for i in range(k+1):
    for j in range(k+1):
        for k in range(k+1):
            total = i+j+k
            if total==s:
                cnt +=1
print(cnt)

### FIXED CODE ###

k,s = map(int,input().split())
cnt=0
for x in range(k+1):
    for y in range(k+1):
        z = s-x-y
        if (z>=0)&(z<=k):
            cnt=cnt+1
print(cnt)
### BUGGY CODE ###

import math
m,n=map(int,input().split())
k=int(math.sqrt(n))
ju=[False for i in range(k+1)]
da=[]
ki=2
co=-1
while ki<k+1:
	if n%ki==0:
		n//=ki
		if ju[ki]:
			da[co]+=1
		else:
			co+=1
			da.append(1)
			ju[ki]=True
	else:
		ki+=1
co+=1
ans=1
for i in range(co):
	si=da[i]
	dp=[[0 for i in range(si+1)] for j in range(m+1)]
	dp[0][0]=1
	for j in range(1,m+1):
		for k in range(si+1):
			for l in range(k+1):
				dp[j][k]=(dp[j-1][l]+dp[j][k])%(1000000007)
	ans=(ans*dp[m][si])%(1000000007)
if n>1:
	ans=((ans*m)%1000000007)
print(ans)


### FIXED CODE ###

import math
m,n=map(int,input().split())
k=int(math.sqrt(n))
ju=[False for i in range(k+1)]
da=[]
ki=2
co=-1
while ki<k+1:
	if n%ki==0:
		n//=ki
		if ju[ki]:
			da[co]+=1
		else:
			co+=1
			da.append(1)
			ju[ki]=True
	else:
		ki+=1
co+=1
ans=1
for i in range(co):
	si=da[i]
	dp=[[0 for i in range(si+1)] for j in range(m+1)]
	dp[0][0]=1
	for j in range(1,m+1):
		for k in range(si+1):
			for l in range(k+1):
				dp[j][k]=(dp[j-1][l]+dp[j][k])%(1000000007)
	ans=(ans*dp[m][si])%(1000000007)
if n>1:
	ans=((ans*m)%1000000007)
print(ans)
### BUGGY CODE ###

h,w = map(int, input().split())
a=[list(map(int,input().split())) for i in range(h)]
b=[list(map(int,input().split())) for i in range(h)]
d = [[0 for j in range(w)] for i in range(h)]
for i in range(h):
    for j in range(w):
        d[i][j] = abs(a[i][j]-b[i][j])

dp = [[0 for _ in range(6400)] for _ in range(h*w)]
dp[0][d[0][0]]=1

for i in range(h*w):
    nowh,noww = divmod(i,w)
    for k in range(6400):
        if not dp[nowh*w + noww][k]==1:
            continue
        nxth,nxtw=nowh+1, noww+1
        if nxtw<w:
            nxt=d[nowh][nxtw]
            if k+nxt < 6400:
                dp[nowh*w + nxtw][k+nxt] = 1
            dp[nowh*w + nxtw][abs(k-nxt)] = 1
        if nxth<h:
            nxt=d[nxth][noww]
            if k+nxt < 6400:
                dp[nxth*w + noww][k+nxt] = 1
            dp[nxth*w + noww][abs(k-nxt)] = 1


for k in range(6400):
    if dp[-1][k]==1:
        print(k)
        exit()

### FIXED CODE ###

h,w = map(int, input().split())
a=[list(map(int,input().split())) for i in range(h)]
b=[list(map(int,input().split())) for i in range(h)]
d = [[0 for j in range(w)] for i in range(h)]
for i in range(h):
    for j in range(w):
        d[i][j] = abs(a[i][j]-b[i][j])

dp = [[0 for _ in range(6400)] for _ in range(h*w)]
dp[0][d[0][0]]=1

for i in range(h*w):
    nowh,noww = divmod(i,w)
    for k in range(6400):
        if not dp[nowh*w + noww][k]==1:
            continue
        nxth,nxtw=nowh+1, noww+1
        if nxtw<w:
            if k+d[nowh][nxtw] < 6400:
                dp[nowh*w + nxtw][k+d[nowh][nxtw]] = 1
            dp[nowh*w + nxtw][abs(k-d[nowh][nxtw])] = 1
        if nxth<h:
            if k+ d[nxth][noww]< 6400:
                dp[nxth*w + noww][k+d[nxth][noww]] = 1
            dp[nxth*w + noww][abs(k-d[nxth][noww])] = 1


for k in range(6400):
    if dp[-1][k]==1:
        print(k)
        exit()
### BUGGY CODE ###

n=int(input())
a=list(map(int,input().split()))
s=a[0]
for i in a[1:]:
  s^=i
  
ans=''

for i in a:
  x=s^i
  ans+=str(x)
  ans+=' '

print(ans[:-1])

### FIXED CODE ###

n=int(input())
a=list(map(int,input().split()))
s=a[0]
for i in a[1:]:
  s^=i
  
ans=''

for i in a:
  x=s^i
  ans+=str(x)
  ans+=' '

print(ans[:-1])
### BUGGY CODE ###

S = input()
l = len(S)
while True:
  S_ = S.replace('01','').replace('10','')
  if S_ != S:
  	S = S_
  else:
    break
print(l-len(S))

### FIXED CODE ###

S = input()
print(min(S.count('0'),S.count('1'))*2)
### BUGGY CODE ###

import sys
input = sys.stdin.readline
N, K = list(map(int, input().split()))
H = list(map(int, input().split()))

C = [-1] * N
C[0] = 0
for n in range(1, N):
    for m in range(max(0, n-K), n):
        C[n] = abs(H[n] - H[m]) + \
            C[m] if C[n] < 0 else min(abs(H[n] - H[m]) + C[m], C[n])

print(C[N-1])


### FIXED CODE ###

import sys
input = sys.stdin.readline
N, K = list(map(int, input().split()))
H = list(map(int, input().split()))

C = [-1] * N
C[0] = 0
for n in range(1, N):
    for m in range(max(0, n-K), n):
        C[n] = abs(H[n] - H[m]) + \
            C[m] if C[n] < 0 else min(abs(H[n] - H[m]) + C[m], C[n])

print(C[N-1])
### BUGGY CODE ###

N,M=map(int,input().split())
request=[]
for _ in range(M):
    request.append(list(map(int,input().split())))
request.sort(key=lambda x: x[0])
    
memory=[]
memory.append(request[0][1])
head = request[0][0]
index = 0
ans = 0

def equalmin():
    if memory == []: return False
    else: return head == min(memory)

def equal():
    if index == M-1: return False
    else: return head == request[index+1][0]

while head <= N:
    if equalmin():
        ans +=1
        memory = []
    elif equal():
        index+=1
        memory.append(request[index][1])
    else: head +=1
        
print(ans)

### FIXED CODE ###

N,M=map(int,input().split())
request=[]
for _ in range(M):
    request.append(list(map(int,input().split())))
request.sort(key=lambda x: x[0])
    
memory=request[0][1]
head = request[0][0]
index = 0
ans = 0

def equal():
    if index == M-1: return False
    else: return head == request[index+1][0]

while head <= N:
    if head == memory:
        ans +=1
        memory = N+1
    elif equal():
        index +=1
        memory=min(request[index][1],memory)
    else: head +=1
        
print(ans)
### BUGGY CODE ###

import fractions

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

def primes(n):
    is_prime = [True] * (n + 1)
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2, int(n**0.5) + 1):
        if not is_prime[i]:
            continue
        for j in range(i * 2, n + 1, i):
            is_prime[j] = False
    return [i for i in range(n + 1) if is_prime[i]]

import copy
N = int(input())
Ps = list(map(int,input().split(" ")))
org_Ps = copy.deepcopy(Ps)
prime_nums = primes(10 ** 5)

Ps.sort()
mul = 1
used = False
for p in prime_nums:
    used = False
    for i in range(len(Ps)):
        if Ps[i] %p == 0:
            Ps[i]//=p
            if not used:
                used = True
                mul *= p

MOD = 10 ** 9 + 7
g = 1

for p in Ps:
    g = g* p // fractions.gcd(g, p)
g *= mul
ans = 0

for p in org_Ps:
    ans += g//p
    
ans %= MOD

print(ans)





### FIXED CODE ###

from fractions import gcd

def lcm(x, y):
    return (x * y) // gcd(x, y)

N = int(input())
Ps = list(map(int,input().split(" ")))
MOD = 10 ** 9 + 7
g = 1
for p in Ps:
    g = lcm(g,p)
ans = 0

print(sum([g // p for p in Ps]) % (10 ** 9 + 7))
### BUGGY CODE ###

N = int(input())
S = str(input())
Answer = 0
for r in range(N):
    if S[r] == "R":
        for g in range(N):
            if S[g] == "G":
                for b in range(N):
                    if S[b] != "B" or ((b-g)**2 == (g-r)**2) or ((b-r)**2 == (g-b)**2) or ((b-r)**2 == (g-r)**2):
                        pass
                    else:
                        Answer += 1

print(Answer)
                        


### FIXED CODE ###

N = int(input())-1
S = str(input())
r,g,b = 0,0,0
rgb = str()
d = 0
for n in range(N+1):
    rgb = str(S[n])
    if rgb == "R":
        r += 1
    if rgb == "G":
        g += 1
    if rgb == "B":
        b += 1
    rang = int((N - n - 2) / 2)
    for j in range(rang,-1,-1):
        if S[n+j+1] != rgb and n+2*j+2 <= N:
           
            if S[n+2*j+2] != rgb:
                if S[n+2*j+2] != S[n+j+1]:
                    d -= 1
                    
                else:
                    pass
            else:
                pass
        else:
            pass
        

Answer = r*g*b + d

print(Answer)
### BUGGY CODE ###

from math import *

def cin(): # To take limited number of inputs
    return map(int,input().split())

def cins(): # To take space sepreated strings
    return input.split()

def cino(test=False): # To take individual int input (test = False)
    if not test:
        return int(input())
    else: # To take string input (test = True)
        return input()

def cina(): # array input
  return list(map(int,input().split()))

def ssplit(): # multiple string input
    return list(input().split())

def printlist(l): # To print space seperated array
    for i in l:
        print(i,end=" ")

def main():
    a = cino()
    l = cina()
    check = True
    suma = 1
    for i in l:
        suma = suma*i
    if suma>1e18:
        print(-1)
    else:
        print(suma)


if __name__ == '__main__':
    main()


### FIXED CODE ###

from math import *

def cin(): # To take limited number of inputs
    return map(int,input().split())

def cins(): # To take space sepreated strings
    return input.split()

def cino(test=False): # To take individual int input (test = False)
    if not test:
        return int(input())
    else: # To take string input (test = True)
        return input()

def cina(): # array input
  return list(map(int,input().split()))

def ssplit(): # multiple string input
    return list(input().split())

def printlist(l): # To print space seperated array
    for i in l:
        print(i,end=" ")

def main():
    a = cino()
    l = cina()
    check = True
    suma = 1
    l.sort()
    if l[0]==0:
        print(0)
    else:
        for i in l:
            suma = suma*i
            if suma>1000000000000000000:
                check = False
                break
        if check:
            print(suma)
        else:
            print(-1)


if __name__ == '__main__':
    main()
### BUGGY CODE ###

import math
#import numpy as np
import queue
from collections import deque,defaultdict
import heapq as hpq
from sys import stdin,setrecursionlimit
#from scipy.sparse.csgraph import dijkstra
#from scipy.sparse import csr_matrix
ipt = stdin.readline
setrecursionlimit(10**7)

def main():
    n,k = map(int,ipt().split())
    a = list(map(int,ipt().split()))
#    n = 2*10**5
#    k = 2*10**5
#    a = [i+1 for i in range(n)]
    nxt = [-1]*(n)
    pa = [-1]*(2*10**5+1)
    for i,ai in enumerate(a*2):
        pai = pa[ai]
        if pai == -2:
            continue
        if pai == -1:
            pa[ai] = i
        else:
            nxt[pai] = i-pai+1
            if i <= n-1:
                pa[ai] = i
            else:
                pa[ai] = -2
    dbl = [nxt]
    ni = 1
    while ni <= n*k:
        nnxt = [0]*n
        pnxt = dbl[-1]
        for i in range(n):
            nnxt[i] = pnxt[i]+pnxt[(i+pnxt[i])%n]
        dbl.append(nnxt)
        if min(nnxt) > n*k:
            break
        ni *= 2
    np = 0
    ld = len(dbl)
    ni = len(dbl)-1
#    print(dbl)
    for db in dbl[::-1]:
        while True:
            if db[np%n] < n*k-1-np:
                np += db[np%n]
            else:
                break
#        print(np)
    ans = []
    for i in range(np%n,n):
        ai = a[i]
        if ai in ans:
            ans = ans[:ans.index(ai)]
        else:
            ans.append(ai)
    print(" ".join(map(str,ans)))



    return

if __name__ == '__main__':
    main()


### FIXED CODE ###

import math
#import numpy as np
import queue
from collections import deque,defaultdict
import heapq as hpq
from sys import stdin,setrecursionlimit
#from scipy.sparse.csgraph import dijkstra
#from scipy.sparse import csr_matrix
ipt = stdin.readline
setrecursionlimit(10**7)

def main():
    n,k = map(int,ipt().split())
    a = list(map(int,ipt().split()))
#    n = 2*10**5
#    k = 2*10**5
#    a = [i+1 for i in range(n)]
    nxt = [-1]*(n)
    pa = [-1]*(2*10**5+1)
    for i,ai in enumerate(a*2):
        pai = pa[ai]
        if pai == -2:
            continue
        if pai == -1:
            pa[ai] = i
        else:
            nxt[pai] = i-pai+1
            if i <= n-1:
                pa[ai] = i
            else:
                pa[ai] = -2
    dbl = [nxt]
    ni = 1
    while ni <= n*k:
        nnxt = [0]*n
        pnxt = dbl[-1]
        for i in range(n):
            nnxt[i] = pnxt[i]+pnxt[(i+pnxt[i])%n]
        dbl.append(nnxt)
        if min(nnxt) > n*k:
            break
        ni *= 2
    np = 0
    ld = len(dbl)
    ni = len(dbl)-1
#    print(dbl)
    for db in dbl[::-1]:
        while True:
            if db[np%n] < n*k-1-np:
                np += db[np%n]
            else:
                break
#        print(np)
    ans = []
    np %= n
    while np < n:
        if nxt[np]+np > n:
            ans.append(a[np])
            np += 1
        elif nxt[np]+np == n:
            np = n
        else:
            np = nxt[np]+np
    print(" ".join(map(str,ans)))



    return

if __name__ == '__main__':
    main()
### BUGGY CODE ###

N = int(input())
A = list(map(int,input().split()))
from copy import deepcopy
A_sum = deepcopy(A)
cur_len = 1
count = N
ans = N
while cur_len <= N and count > 0:
    for i in range(N-cur_len):
        if A_sum[i] >= 0 and A_sum[i] ^ A[i+cur_len] == A_sum[i] + A[i+cur_len]:
            A_sum[i] = A_sum[i] + A[i+cur_len]
        elif A_sum[i] >= 0:
            A_sum[i] = -1
            count -= 1
    if A_sum[N-cur_len] >= 0:
        A_sum[N-cur_len] = -1
        count -= 1
    cur_len += 1
    ans += count
print(ans)

### FIXED CODE ###

N = int(input())
A = list(map(int,input().split()))
L = 0
R = 0
S = A[0]
ans = 0
while(R < N-1):
    if S + A[R+1] == S ^ A[R+1]:
        S += A[R+1]
        R+= 1
    elif R > L:
        S -= A[L]
        ans += R - L + 1
        L += 1
    else:
        L += 1
        R += 1
        ans += 1
        S = A[L]
print(ans+(R-L+2)*(R-L+1)//2)