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

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

n, k = map(int, input().split())
a = list(map(int, input().split()))
min_a = min(a)

memo = [-1] * (k+1)
def rec(x):
    if memo[x] >= 0:
        return memo[x]
    if x < min_a:
        memo[x] = 0
        return 0
    flag = 0
    for i in range(n):
        if x - a[i] < 0:
            continue
        if rec(x - a[i]) == 0:
            flag = 1
    if flag == 1:
        memo[x] = 1
        return 1
    else:
        memo[x] = 0
        return 0

if rec(k) == 1:
    print("First")
else:
    print("Second")

### FIXED CODE ###

n, k = map(int, input().split())
A = list(map(int, input().split()))

dp = [0] * (k+1)

for i in range(1, k+1):
    for a in A:
        if i - a < 0:
            break
        if dp[i-a] == 0:
            dp[i] = 1

if dp[k] == 1:
    print("First")
else:
    print("Second")
### BUGGY CODE ###

N = int(input())

print(sum(range(1, N)))

### FIXED CODE ###

N = int(input())

print((N-1) * N // 2)
### BUGGY CODE ###

N = int( input() )
A = list(map(int, input().split() ))
S = sum(A)
A.extend(A)
odds = [s for s in range(N) if s%2 ==0]
Ans=[]
for i in range(N):
    sum_i = sum([s for s,num in zip(A[i:i+N], range(N)) if num in odds] )

    Ans.append( 2*sum_i -S )    
print(" ".join(map(str,Ans) ))

### FIXED CODE ###

N = int( input() )
A = list(map(int, input().split() ))
S = sum(A)
odds = range(0,N,2)
Ans=[]
Ans.append(-S + 2*sum([s for s,num in zip(A, range(N)) if num in odds] ) )
for i in range(1,N):
    Ans.append(2*A[i-1]-Ans[i-1])
print(" ".join(map(str,Ans) ))
### BUGGY CODE ###

a, b, n = [int(x) for x in input().split()]

x = 2
answer = (a*1//b) - a*(1//b)
while x <= n:
    if (a*x//b) - a*(x//b) > answer:
        answer = (a*x//b) - a*(x//b)
    x += 1

print(answer)

### FIXED CODE ###

a, b, n = [int(x) for x in input().split()]

y = min(b-1, n)

print((a*y)//b)
### BUGGY CODE ###

from collections import Counter

n = int(input())
a = list(map(int, input().split()))
MOD = 10 ** 9 + 7

def prime_factorize(n):
    res = []
    i = 2
    while i * i <= n:
        if n % i == 0:
            res.append(i)
            n //= i
        else:
            i += 1 + (i != 2)
    if n != 1:
        res.append(n)
    return res


lcm_factors = Counter()
for ai in a:
    lcm_factors |= Counter(prime_factorize(ai))

lcm = 1
for k, v in lcm_factors.items():
    lcm *= k ** v
    lcm %= MOD

ans = 0
for ai in a:
    ans += lcm * pow(ai, MOD - 2, MOD)
    ans %= MOD

print(ans)

### FIXED CODE ###

from collections import Counter

n = int(input())
a = list(map(int, input().split()))
MOD = 10 ** 9 + 7

primes = [
  2,  3,  5,  7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67,
 71, 73, 79, 83, 89, 97,101,103,107,109,113,127,131,137,139,149,151,157,163,
167,173,179,181,191,193,197,199,211,223,227,229,233,239,241,251,257,263,269,
271,277,281,283,293,307,311,313,317,331,337,347,349,353,359,367,373,379,383,
389,397,401,409,419,421,431,433,439,443,449,457,461,463,467,479,487,491,499,
503,509,521,523,541,547,557,563,569,571,577,587,593,599,601,607,613,617,619,
631,641,643,647,653,659,661,673,677,683,691,701,709,719,727,733,739,743,751,
757,761,769,773,787,797,809,811,821,823,827,829,839,853,857,859,863,877,881,
883,887,907,911,919,929,937,941,947,953,967,971,977,983,991,997,
1009
]

def prime_factorize(n):
    res = []
    i = 0
    while primes[i] * primes[i] <= n:
        if n % primes[i] == 0:
            res.append(primes[i])
            n //= primes[i]
        else:
            i += 1
    if n != 1:
        res.append(n)
    return res


lcm_factors = Counter()
for ai in a:
    prime_factors = prime_factorize(ai)
    counter = Counter(prime_factors)
    for k, v in counter.items():
        if k in lcm_factors:
            lcm_factors[k] = max(lcm_factors[k], v)
        else:
            lcm_factors[k] = v

lcm = 1
for k, v in lcm_factors.items():
    lcm *= pow(k, v, MOD)
    lcm %= MOD

ans = 0
for ai in a:
    ans += lcm * pow(ai, MOD - 2, MOD)
    ans %= MOD

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

import queue

N, M = map(int, input().split())
g = [[] for i in range(N)]
for i in range(M):
    A, B = map(int, input().split())
    g[A-1].append(B)
    g[B-1].append(A)

ans = [-1] * N
ans[0] = 0
q = queue.Queue()
q.put(1)
while any(i == -1 for i in ans) and not q.empty():
    now = q.get()
    for i in g[now-1]:
        if ans[i-1] != -1:
            continue
        ans[i-1] = now
        q.put(i)

if -1 in ans:
    print('No')
else:
    print('Yes')
    for i in ans[1:]:
        print(i)


### FIXED CODE ###

from collections import deque

N, M = map(int, input().split())
g = [[] for i in range(N)]
for i in range(M):
    A, B = map(int, input().split())
    g[A-1].append(B)
    g[B-1].append(A)

ans = [-1] * N
ans[0] = 0
d = deque([1])
while len(d) != 0:
    now = d[0]
    d.popleft()
    for i in g[now-1]:
        if ans[i-1] != -1:
            continue
        ans[i-1] = now
        d.append(i)

if -1 in ans:
    print('No')
else:
    print('Yes')
    for i in ans[1:]:
        print(i)
### BUGGY CODE ###

n,k=map(int,input().split())
xy=[list(map(int,input().split())) for i in range(n)]
x,y=[[xy[i][0],i] for i in range(n)],[[xy[i][1],i] for i in range(n)]
x.sort()
y.sort()
ans=(10**18)*5
for i1 in range(n):
    i1_sub=n-i1
    for l1 in range(i1_sub,1,-1):
        for i2 in range(n):
            i2_sub=n-i2
            for l2 in range(i2_sub,1,-1):
                x_sub1=x[i1][0]
                x_sub2=x[i1+l1-1][0]
                y_sub1=y[i2][0]
                y_sub2=y[i2+l2-1][0]
                z=[0]*n
                for i in range(n):
                    if x_sub1<=xy[i][0]<=x_sub2 and y_sub1<=xy[i][1]<=y_sub2:
                        z[i]=1
                if sum(z)>=k:
                    ans=min((x_sub2-x_sub1)*(y_sub2-y_sub1),ans)
                else:
                    break
print(ans)


### FIXED CODE ###

n,k=map(int,input().split())
x,y=[[0,0] for i in range(n)],[[0,0] for i in range(n)]
xy=[list(map(int,input().split())) for i in range(n)]
for i in range(n):
    x_sub,y_sub=xy[i]
    x[i][0]=x_sub
    x[i][1]=i
    y[i][0]=y_sub
    y[i][1]=i
x.sort()
y.sort()
ans=(10**18)*5
for i1 in range(n):
    for l1 in range(n-i1,1,-1):
        for i2 in range(n):
            for l2 in range(n-i2,1,-1):
                x_sub1=x[i1][0]
                x_sub2=x[i1+l1-1][0]
                y_sub1=y[i2][0]
                y_sub2=y[i2+l2-1][0]
                z=[0]*n
                for i in range(n):
                    if x_sub1<=xy[i][0]<=x_sub2 and y_sub1<=xy[i][1]<=y_sub2:
                        z[i]=1
                if sum(z)>=k:
                    ans=min((x_sub2-x_sub1)*(y_sub2-y_sub1),ans)
                else:
                    break
print(ans)
### BUGGY CODE ###

#!/usr/bin/env python3
A, B, K = map(int, input().split())
for i in range(A, B + 1):
    if i < A + K or B - K < i:
        print(i)


### FIXED CODE ###

#!/usr/bin/env python3
A, B, K = map(int, input().split())
for i in range(A, min(B + 1, A + K)):
    print(i)
for i in range(max(0, B - K + 1), B + 1):
    if i < A + K:
        continue
    print(i)
### BUGGY CODE ###

n,m = list(map(int, input().split()))
aclist=[]
ac=0
wa=[0 for i in range(n)]
for i in range(m):
    j = list(input().split())
    if int(j[0]) not in aclist:
        if j[1]=='AC':
            ac+=1
            aclist.append(int(j[0]))
        elif j[1]=='WA':
            wa[int(j[0])-1]+=1
ans=0
for i in aclist:
    ans+=wa[i-1]
print(ac,ans)

### FIXED CODE ###

n,m = list(map(int, input().split()))
aclist=[0 for i in range(n)]
ac=0
wa=[0 for i in range(n)]
for i in range(m):
    j = list(input().split())
    j[0]=int(j[0])
    if aclist[j[0]-1]==0:
        if j[1]=='AC':
            ac+=1
            aclist[j[0]-1]=1
        elif j[1]=='WA':
            wa[j[0]-1]+=1
ans=0
for i,j in enumerate(aclist):
    if j==1:
        ans+=wa[i]
print(ac,ans)
### BUGGY CODE ###

N = int(input())
a = sorted(list(map(int, input().split())))

s = 0
while a:
    x = [a[0]] + a[-2:]
    s += x[1]
    a = a[1:-2]
print(s)

### FIXED CODE ###

N = int(input())
a = sorted(list(map(int, input().split())))

print(sum(a[-2 * (i+1)] for i in range(N)))
### BUGGY CODE ###

N=int(input())
A=list(map(int,input().split()))
for i in range(N):
    A[i]=A[i]%(10**9+7)
ans=0
for i in range(N-1):
    for j in range(i+1,N):
        ans=(ans+A[i]*A[j])%(10**9+7)
print(ans)


### FIXED CODE ###

N=int(input())
A=list(map(int,input().split()))
wa=[0]*(N-1)
wa[0]=A[-1]
for i in range(1,N-1):
    wa[i]=wa[i-1]+A[N-i-1]
ans=0
wa.reverse()

for i in range(0,N-1):

    ans=(ans+wa[i]*A[i])%(10**9+7)
print(ans)
### BUGGY CODE ###

N = int(input())
A = map(int, input().split())
Q = int(input())

change_pair = []
for i in range(Q):
    b, c = map(int, input().split())
    change_pair.append((b, c))

# Aの出現値毎に回数をカウント
counts = {}
for a in A:
    if a in counts:
        counts[a] += 1
    else:
        counts[a] = 1

# 置き換え毎に回数を移動
for b, c in change_pair:
    if b in counts:
        count = counts[b]
        counts[b] = 0
    else:
        count = 0
    if c in counts:
        counts[c] += count
    else:
        counts[c] = count

    # 総和を求める
    total = 0
    for a, count in counts.items():
        total += a * count
    print(total)


### FIXED CODE ###

N = int(input())
A = map(int, input().split())
Q = int(input())

change_pair = []
for i in range(Q):
    b, c = map(int, input().split())
    change_pair.append((b, c))

# Aの出現値毎に回数をカウント
counts = {}
total = 0
for a in A:
    if a in counts:
        counts[a] += 1
    else:
        counts[a] = 1
    total += a

# 置き換え毎に回数を移動
for b, c in change_pair:
    if b in counts:
        count = counts[b]
        counts[b] = 0
        total -= b * count
    else:
        count = 0
    if c in counts:
        counts[c] += count
    else:
        counts[c] = count
    total += c * count
    print(total)
### BUGGY CODE ###

from collections import deque
n, m = map(int, input().split())
A = [0] * m
B = [0] * m
for i in range(m):
    A[i], B[i] = map(int, input().split())

next_queue = deque()
#delete_items = deque()
sign = [-1] * n

next_queue.append(1)

while next_queue:
    current_number = next_queue.popleft()
    for i in range(m):
        if A[i] == current_number:
            if sign[B[i] - 1] == -1:
                sign[B[i] - 1] = current_number
                if B[i] != 1:
                    next_queue.append(B[i])
                A[i] = -1
                B[i] = -1
#                delete_items.append(i)
        if B[i] == current_number:
            if sign[A[i] - 1] == -1:
                sign[A[i] - 1] = current_number
                if A[i] != 1:
                    next_queue.append(A[i])
                A[i] = -1
                B[i] = -1
#                delete_items.append(i)
#    m -= len(delete_items)
#    for item in sorted(list(delete_items), reverse=True):
#        print(item)
#        A.pop(item)
#        B.pop(item)
print("Yes")
for i in range(1, n):
    print(sign[i])




### FIXED CODE ###

from collections import deque
n, m = map(int, input().split())
route = [[] for i in range(n)]

for i in range(m):
    a, b = map(int, input().split())
    route[a-1].append(b - 1)
    route[b-1].append(a - 1)

next_queue = deque()
sign = [-1 for i in range(n)]
sign[0] = 999

next_queue.append(0)

while next_queue:
    current_number = next_queue.popleft()
    for room in route[current_number]:
        if sign[room] == -1:
            sign[room] = current_number
            next_queue.append(room)
print("Yes")
for i in range(1, n):
    print(sign[i] + 1)
### BUGGY CODE ###

import sys
def input(): return sys.stdin.readline().rstrip()

def main():
    N = int(input())
    A = tuple(map(int, input().split()))
    MAX_V = 10 ** 18

    if 0 in A:
        print(0)
        exit()

    ans = 1
    for a in A:
        ans *= a
        if ans > MAX_V:
            ans = -1
    print(ans)

if __name__ == '__main__':
    main()


### FIXED CODE ###

import sys
def input(): return sys.stdin.readline().rstrip()

def main():
    N = int(input())
    A = sorted(map(int, input().split()), reverse=True)
    MAX_V = 10 ** 18

    if A[-1] == 0:
        print(0)
        exit()

    ans = 1
    for a in A:
        ans *= a
        if ans > MAX_V:
            ans = -1
            break
    print(ans)

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

#!/usr/bin/env python
# -*- coding:utf-8 -*-


obj = input().strip().split(' ')
N, K, Q = map(int, obj)

winner_list = []
for _ in range(Q):
    A_i = int(input().strip())
    winner_list.append(A_i)

point_list = [K for _ in range(N)]

for A_i in winner_list:
    point_list = [k if i+1 == A_i else k - 1 for i, k in enumerate(point_list)]

is_win = [True if point_list[i] > 0 else False for i in range(N) ]

for i in range(N):
    if is_win[i]:
        print('Yes')
    else:
        print('No')


### FIXED CODE ###

#!/usr/bin/env python
# -*- coding:utf-8 -*-


obj = input().strip().split(' ')
N, K, Q = map(int, obj)

win_count = [0] * N
for _ in range(Q):
    A_i = int(input().strip())
    win_count[A_i - 1] += 1

is_ok = [True if Q - cnt < K else False for cnt in win_count]

for i in range(N):
    if is_ok[i]:
        print('Yes')
    else:
        print('No')
### BUGGY CODE ###

n,ans=int(input()),0
for i in range(1, n+1):
    for j in range(i, n+1, i):ans+=j
print(ans)

### FIXED CODE ###

from numba import jit
@jit
def Sum_divisors():
    n,ans=int(input()),0
    for i in range(1, n+1):
        for j in range(i, n+1, i):ans+=j
    print(ans)

Sum_divisors()
### BUGGY CODE ###

from collections import deque

S = deque(input())
Q = int(input())
query = [input().split() for _ in range(Q)]
for q in query:
    if q[0] == '1':
        S.reverse()
    else:
        if q[1] == '1':
            S.appendleft(q[2])
        else:
            S.append(q[2])

print(''.join(S))

### FIXED CODE ###

from collections import deque
S = deque(input())
Q = int(input())
query = [input().split() for _ in range(Q)]
reverse = False
for q in query:
    if q[0] == '1':
        reverse = not reverse
    else:
        if q[1] == '1':
            if not reverse:
                S.appendleft(q[2])
            else:
                S.append(q[2])
        else:
            if not reverse:
                S.append(q[2])
            else:
                S.appendleft(q[2])
if reverse:
    S.reverse()
print(''.join(S))
### BUGGY CODE ###

from itertools import combinations
n, k = (int(x) for x in input().split())
a = [int(x) for x in input().split()]
com = list(combinations(a, k))
ans = 0
for s in com:
    ans += max(s) - min(s)
print(ans % 1000000007)

### FIXED CODE ###

n, k = (int(x) for x in input().split())
a = [int(x) for x in input().split()]
a = sorted(a)
fact = [1]
for i in range(1, n + 1):
    fact.append(fact[-1] * i % 1000000007)
max_a = 0
for i in range(k - 1, n):
    max_a += a[i] * fact[i] * pow(fact[i - k + 1], 1000000005, 1000000007) * pow(fact[k - 1], 1000000005, 1000000007) % 1000000007
a = a[::-1]
min_a = 0
for i in range(k - 1, n):
    min_a += a[i] * fact[i] * pow(fact[i - k + 1], 1000000005, 1000000007) * pow(fact[k - 1], 1000000005, 1000000007) % 1000000007
print(int((max_a - min_a) % 1000000007))
### BUGGY CODE ###

#import numpy as np
import sys, math
from itertools import permutations, combinations
from collections import defaultdict, Counter, deque
from math import factorial#, gcd
from bisect import bisect_left, bisect_right #bisect_left(list, value)
sys.setrecursionlimit(10**7)
enu = enumerate
MOD = 10**9+7
def input(): return sys.stdin.readline()[:-1]
pl = lambda x: print(*x, sep='\n')

N = int(input())
A = list(map(int, input().split()))
maxA = max(A)

nums = [0]*(maxA+2)
A.sort()
cnt = 0 
ans = []
for a in A:
    # print('nums', nums)
    if nums[a]==0:
        # print(a)
        cnt += 1
        ans.append(a)
    mlt = a
    nums[a] += 1
    while a + mlt < maxA+2:
        a += mlt
        # print(' a:', a)
        nums[a] += 1

for an in ans:
    if A.count(an)>1:
        cnt -= 1
print(cnt)

### FIXED CODE ###

#import numpy as np
import sys, math
from itertools import permutations, combinations
from collections import defaultdict, Counter, deque
from math import factorial#, gcd
from bisect import bisect_left, bisect_right #bisect_left(list, value)
sys.setrecursionlimit(10**7)
enu = enumerate
MOD = 10**9+7
def input(): return sys.stdin.readline()[:-1]
pl = lambda x: print(*x, sep='\n')

N = int(input())
A = list(map(int, input().split()))
A.sort()
C = Counter(A)
S = set(A)

maxA = A[-1]
chk = [0] * (maxA+1)
for s in S:
    for i in range(s, maxA+1, s):
        chk[i] += 1

res = [s for s in S if chk[s] == 1 and C[s] == 1]
# print(res)
print(len(res))
### BUGGY CODE ###

import math
Q = int(input())

l = [0 for i in range(Q)]
r = [0 for i in range(Q)]
i = 0
while True:
  try:
    lr=list(map(int,input().split()))
    l[i] = lr[0]
    r[i] = lr[1]
    i+=1
  except:
    break

def is_prime(num):
  #if(type(num) != type(0)):
  #  print('error at '+str(num)+' type = '+str(type(num)))
  #  print(type(int))
  #  return 0
  #if(num<2):
  #  return 0
  if(num == 2):
    return 1
  n = math.ceil(math.sqrt(num))
  for i in range(2,n+1):
    if((num%i) == 0):
      return 0
  return 1

def create_list():
  MAXI = max(r)+1
  
  prime = [1 for i in range(MAXI)]
  prime[0] = 0
  prime[1] = 0
  for i in range(2,MAXI):
    if(prime[i] == 0):
      continue
    else:
      prime[i] = is_prime(i)
      for j in range(i*2,MAXI,i*2):
        prime[j] = 0
      for j in range(i*5,MAXI,i*3):
        prime[j] = 0
      for j in range(i*5,MAXI,i*5):
        prime[j] = 0
  #print(prime)
  sn = [0 for i in range(MAXI+1)]
  for i in range(1,MAXI+1,2):
    #print('int(('+str(i+1)+')/2) = '+str(int((i+1)/2))+' when '+str(prime[int((i+1)/2)]))
    sn[i] = (prime[i] * prime[int((i+1)/2)]) #odd
    sn[i+1] = 0 #even
  return sn

base = create_list()
#print(base)
for i in range(Q):
  if(l[i]==r[i]):
    print(base[l[i]])
  else:
    lnum = base[0:l[i]]
    rnum = base[0:r[i]]
    print( sum(rnum)-sum(lnum) )

### FIXED CODE ###

import math
import sys
sys.setrecursionlimit(10 ** 5 + 10)

Q = int(input())

l = [0 for _ in range(Q)]
r = [0 for _ in range(Q)]
i = 0
while True:
  try:
    lr=list(map(int,input().split()))
    l[i] = lr[0]
    r[i] = lr[1]
    i+=1
  except:
    break

def is_prime(num):
  #if(type(num) != type(0)):
  #  print('error at '+str(num)+' type = '+str(type(num)))
  #  print(type(int))
  #  return 0
  #if(num<2):
  #  return 0
  if(num == 2):
    return 1
  n = math.ceil(math.sqrt(num))
  for i in range(2,n+1):
    if((num%i) == 0):
      return 0
  return 1

def create_list():
  MAXI = max(r)+1
  
  prime = [1 for _ in range(MAXI+1)]
  prime[0] = 0
  prime[1] = 0
  for i in range(2,MAXI):
    if(prime[i] == 0):
      continue
    else:
      prime[i] = is_prime(i)
      for j in range(i*2,MAXI,i*2):
        prime[j] = 0
      for j in range(i*5,MAXI,i*3):
        prime[j] = 0
      for j in range(i*5,MAXI,i*5):
        prime[j] = 0
  #print(prime)
  sn = [0 for _ in range(MAXI+2)]
  for i in range(1,MAXI+1,2):
    #print('int(('+str(i+1)+')/2) = '+str(int((i+1)/2))+' when '+str(prime[int((i+1)/2)]))
    sn[i] += sn[i-1] + (prime[i] * prime[int((i+1)/2)]) #odd
    sn[i+1] = sn[i]
  return sn

base = create_list()
#print(base)
for i in range(Q):
  print( base[r[i]] - base[l[i]-1] )#sum(rnum)-sum(lnum) )
### BUGGY CODE ###

N,Q = map(int, input().split())
S = input()
for q in range(Q):
  l,r = map(int, input().split())
  Sq = S[l-1:r]
  print(Sq.count('AC'))

### FIXED CODE ###

N,Q = map(int, input().split())
S = input()
AC_cum = [0]
for i in range(N-1):
  if S[i:i+2] == 'AC':
    AC_cum.append(AC_cum[-1]+1)
  else:
    AC_cum.append(AC_cum[-1])
for q in range(Q):
  l,r = map(int, input().split())
  print(AC_cum[r-1]-AC_cum[l-1])
### BUGGY CODE ###

N, K = map(int, input().split())
A = list(map(int, input().split()))

for _ in range(K):
    B = [0] * (N + 1)
    for i, a in enumerate(A):
        B[max(0, i - a)] += 1
        B[min(N, i + a + 1)] -= 1
    for i in range(N):
        B[i + 1] += B[i]
    A = B[:N]

    if min(A) >= N:
        break

print(*A)



### FIXED CODE ###

N, K = map(int, input().split())
A = list(map(int, input().split()))

for _ in range(K):
    B = [0] * (N + 1)
    for i, a in enumerate(A):
        B[max(0, i - a)] += 1
        B[min(N, i + a + 1)] -= 1
    for i in range(N):
        B[i + 1] += B[i]
    A = B[:N]

    if min(A) >= N:
        break

print(*A)
### BUGGY CODE ###

N, K = list(map(int, input().split()))
S = [1 if x=='R' else -1 for x in input()]
r = 0
for i in range(K):
    l = r
    f = True
    prev = S[0]
    for j in range(l, N):
        current = S[j]
        if current != prev:
            l = j
            f = False
            break
        prev = current
    if f:
        break

    r = N - 1
    prev = S[l]
    for j in range(l+1, N):
        current = S[j]
        if current != prev:
            r = j - 1
            break
        prev = current
    left = S[:l]
    target = S[l:r+1]
    right = S[r+1:]
    target.reverse
    target = [-x for x in target]
    S = left + target + right

S.insert(0, 1)
S.append(-1)
ans = 0
for i in range(N):
    x = S[i+1]
    y = S[i+1+x]
    if x == y:
        ans += 1

print(ans)

### FIXED CODE ###

N, K = list(map(int, input().split()))
S = [1 if x=='R' else -1 for x in input()]
cnt = 0
rule = S[0]
f = False
for i in range(1, N):
    if S[i] != rule:
        f = True
        S[i] *= -1
    else:
        if f:
            f = False
            cnt += 1
    if cnt >= K:
        break

S.insert(0, 1)
S.append(-1)
ans = 0
for i in range(N):
    x = S[i+1]
    y = S[i+1+x]
    if x == y:
        ans += 1

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

def main():
  if 'get_ipython' not in globals():  
    # For Subsession
    X, Y, Z, K = (int(i) for i in input().split())
    A = [int(i) for i in input().split()] 
    B = [int(i) for i in input().split()]
    C = [int(i) for i in input().split()] 
  else:
    A = [1,10,100]
    B = [2,20,200]
    C = [1,10,100]
    #A = [4,6]
    #B = [1,5]
    #C = [3,8]
    X = len(A)
    Y = len(B)
    Z = len(C)
    K = 5
    #K = 8

  # Processing
  # A.sort(reverse=True)
  # B.sort(reverse=True)
  
  AB = []
  for i in A:
    for j in B:
      AB.append(i+j)
  
  AB.sort(reverse=True)
  #if 'get_ipython' in globals(): 
  #  print(AB)
  
  ABC = []
  C.sort(reverse=True)
  for i in AB[0:K]:
    for j in C[0:K]:
      ABC.append(i+j)  
  
  ABC.sort(reverse=True)
  
  #if 'get_ipython' in globals(): 
  #  print(ABC)

  for i in ABC[0:K]:
    print(i)      

main()

### FIXED CODE ###

def main():
  if 'get_ipython' not in globals():  
    # For Subsession
    X, Y, Z, K = (int(i) for i in input().split())
    A = [int(i) for i in input().split()] 
    B = [int(i) for i in input().split()]
    C = [int(i) for i in input().split()] 
  else:
    A = [1,10,100]
    B = [2,20,200]
    C = [1,10,100]
    #A = [4,6]
    #B = [1,5]
    #C = [3,8]
    X = len(A)
    Y = len(B)
    Z = len(C)
    K = 5
    #K = 8

  # Processing
  AB = []
  A.sort(reverse=True)
  B.sort(reverse=True)
  for i in A[0:K]:
    for j in B[0:K]:
      AB.append(i+j)
  
  AB.sort(reverse=True)
  
  ABC = []
  C.sort(reverse=True)
  
  for i in AB[0:K]:
    for j in C[0:K]:
      ABC.append(i+j)  
  
  ABC.sort(reverse=True)

  for i in ABC[0:K]:
    print(i)      

main()
### BUGGY CODE ###

n = int(input())
nums = input()
A =[int(x.strip()) for x in nums.split()]

ans = 0
for i in range(n):
    for j in range(n-i):
        splited = A[i:i+j+1]
        # print(splited,i,j)
        goukei = sum(splited)
        if goukei == 0 and splited != []:
            # print(splited)
            ans += 1

print(ans)

### FIXED CODE ###

from collections import Counter
n = int(input())
nums = input()
A =[int(x.strip()) for x in nums.split()]

S = [0]
for i in range(n):
    S.append(S[i]+A[i])

co = Counter(S)
# print(S)
# print(co)

ans = 0
for i in co.values():
    if i > 1:
        ans += i*(i-1) /2

print(int(ans))