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

#import math
#import numpy as np
#import torch
#import torch.nn as nn
#import matplotlib.pyplot as plt
#from decimal import Decimal
#import itertools


N=int(input())
#N,K = map(int,input().split())
#B,W = map(int,input().split())
#T=int(input())
A = list(map(int,input().split()))
#S=str(input())
#A=[p for p in range(2*10**5)]
Q=int(input())
l=[]
for i in range(Q):
    #print(A)
    B,C = map(int,input().split())
    a=True
    if B==C:
        a=False
    while a==True:

        try:
            ind=A.index(B)
            A[ind]=C
            #print(A)
        except:
            a=False
    #print(A)
    print(sum(A))


### FIXED CODE ###

#import math
#import numpy as np
#import torch
#import torch.nn as nn
#import matplotlib.pyplot as plt
#from decimal import Decimal
#import itertools
import collections

N=int(input())
#N,K = map(int,input().split())
#B,W = map(int,input().split())
#T=int(input())
A = list(map(int,input().split()))
#S=str(input())
#A=[p for p in range(2*10**5)]
Q=int(input())
c=collections.Counter(A)
s=sum(A)
for i in range(Q):
    #print(A)
    B,C = map(int,input().split())
    if c[B]:
        s += (C-B)*c[B]
        c[C] += c[B]
        c[B] = 0

    print(s)
### BUGGY CODE ###

N = int(input())
X = [ 0 for _ in range(10**9)]
for i in range(N):
    a = int(input())
    X[a] = (X[a]+1)%2
print(sum(X))

### FIXED CODE ###

N = int(input())
A = []
for i in range(N):
    A.append(int(input()))
A = sorted(A)
ans = 0
K = A[0]
cnt = 0
for i in range(N):
    if A[i] == K:
        cnt = (cnt + 1)%2
    else:
        K = A[i]
        ans += cnt
        cnt = 1
if A[N-1] == K:
    ans += cnt
print(ans)
### BUGGY CODE ###

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

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

    MOD = 10 ** 9 + 7

    pos = []
    neg = []
    for a in A:
        if a >= 0:
            pos.append(a)
        else:
            neg.append(a)

    flag = False  # 積を正にできるか

    if N == K:
        ans = 1
        for a in A:
            ans *= a % MOD
        print(ans % MOD)
        exit()


    if len(pos) > 0:
        flag = True
    else:
        if K % 2 == 0:
            flag = True

    ans = 1
    if not flag:
        # 積を正にできないとき
        # 絶対値の小さい方からK個とる
        A = sorted([abs(x) for x in A])
        for a in A[:K]:
            ans *= a % MOD
        ans *= -1
    else:
        pos = sorted(pos)
        neg = sorted(neg, reverse=True)
        if K % 2 == 1:
            # Kが奇数の時
            # 一番大きい偶数を1つとる。
            ans *= pos.pop() % MOD

        # pos, neg sort -> 2個ずつペア -> 降順sort -> 上から K//2 個とる
        pairs = []
        while len(pos) >= 2:
            x = pos.pop()
            x *= pos.pop()
            pairs.append(x)
        while len(neg) >= 2:
            x = neg.pop()
            x *= neg.pop()
            pairs.append(x)
        pairs = sorted(pairs, reverse=True)
        for p in pairs[: K // 2]:
            ans *= p % MOD

    print(ans % MOD)

    
if __name__ == '__main__':
    main()


### FIXED CODE ###

import sys
import heapq

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


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

    MOD = 10 ** 9 + 7

    pos = []
    neg = []
    for a in A:
        if a >= 0:
            pos.append(a)
        else:
            neg.append(a)

    flag = False  # 積を正にできるか

    if N == K:
        ans = 1
        for a in A:
            ans *= a
            ans %= MOD
        print(ans % MOD)
        exit()

    if len(pos) > 0:
        flag = True
    else:
        if K % 2 == 0:
            flag = True

    ans = 1
    if not flag:
        # 積を正にできないとき
        # 絶対値の小さい方からK個とる
        h = [abs(x) for x in A]
        heapq.heapify(h)

        for i in range(K):
            ans *= heapq.heappop(h)
            ans %= MOD
        ans *= -1
    else:
        hpos = [-x for x in pos]
        heapq.heapify(hpos)
        hneg = neg[:]
        heapq.heapify(hneg)
        if K % 2 == 1:
            # Kが奇数の時
            # 一番大きい偶数を1つとる。
            ans *= -heapq.heappop(hpos)
            ans %= MOD

        # pos, neg sort -> 2個ずつペア -> 降順sort -> 上から K//2 個とる
        pairs = []
        while len(hpos) >= 2:
            x = -heapq.heappop(hpos)
            x *= -heapq.heappop(hpos)
            heapq.heappush(pairs, -x)
        while len(hneg) >= 2:
            x = heapq.heappop(hneg)
            x *= heapq.heappop(hneg)
            heapq.heappush(pairs, -x)
        if len(pairs):
            for i in range(K // 2):
                ans *= -heapq.heappop(pairs)
                ans %= MOD

    print(ans % MOD)


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

N,K=map(int,input().split())
p = list(map(int,input().split()))
ki=[]


m=0
ml=[]
if(K!=1):
    for i in range(N-K+1):
        tmp=0
        tmpl=[]
        for j in range(i,K+i):
            tmp+=p[j]
            tmpl.append(p[j])
        if(tmp > m):
            m=tmp
            ml=tmpl
else:
    ml=[max(p)]
kitai=0
for pi in ml:
    for i in range(1,pi+1):
        kitai+=i/pi

print(kitai)

### FIXED CODE ###

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

ruisekiwa=[0]

for i in range(N):
    ruisekiwa.append(ruisekiwa[i]+(1+p[i])/2)

max_value=0
for i in range(N-K+1):
    tmp=ruisekiwa[i+K]- ruisekiwa[i]
    if(max_value < tmp):
        max_value=tmp
print(max_value)
### BUGGY CODE ###

S=input()
length=len(S)
S=int(S)
count=[0 for i in range(2019)]

for i in range(length+1):
    mod=(S%(10**i))%2019
    count[mod]+=1


retval=0
for key in range(2019):
    retval+=count[key]*(count[key]-1)//2

print(retval)


### FIXED CODE ###

from functools import lru_cache



S=input()
count=[0 for i in range(2019)]
length=len(S)
#S=int(S)
S=S+'0'
S=S[::-1]
_S=0

base=1
for i,s in enumerate(S):
    _S=base*int(s)+_S
    count[_S%2019]+=1
    base*=10
    base=base%2019
    _S=_S%2019



retval=0
for key in range(2019):
    retval+=count[key]*(count[key]-1)//2


print(retval)
### BUGGY CODE ###

import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60


N = int(readline())
B = list(map(int, readline().split()))

def main():
    def dfs(vec):
        i = 0
        zero_only = True
        for j in range(len(vec)):
            if vec[j] > 0:
                zero_only = False
                i += 1
                if vec[j] == i:
                    vec[j] = 0
                    ret = dfs(vec)
                    vec[j] = i
                    if ret != False:
                        ret.append(i)
                        return ret
        if zero_only:
            return []
        else:
            return False

    ans = dfs(B)
    if ans == False:
        print(-1)
    else:
        print(*ans, sep='\n')

if __name__ == '__main__':
    main()


### FIXED CODE ###

import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60


N = int(readline())
B = list(map(int, readline().split()))


def main():
    ans = []
    while B:
        found = False
        for i in range(len(B), 0, -1):
            if i == B[i - 1]:
                ans.append(i)
                del B[i - 1]
                found = True
                break
        if not found:
            print(-1)
            return
    print(*reversed(ans), sep='\n')


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

N = input()
P_list = input().split()
# N = '5'
# P_list = '4 2 5 1 3'.split()
P_list = [int(i) for i in P_list]
length = int(N)
ans = length 
for i in range(length):
    for j  in range(i):
        if P_list[i] > P_list[j]:
            ans -= 1
            j= 0
            # print(P_list[i] , P_list[j],ans)
            break

print(ans)

### FIXED CODE ###

N = input()
P_list = input().split()
# N = '5'
# P_list = '4 2 5 1 3'.split()
P_list = [int(i) for i in P_list]
length = int(N)
ans = 0 
M = []
mini =-1
for i in range(length):
    # print(min(P_list[0:i+1]))
    if P_list[i] <mini or mini <0:
        mini = P_list[i]
    if mini == P_list[i]:
        ans +=1


    # if P_list[i]==min(P_list[0:i+1]):
    #     ans +=1
    
print(ans)
### BUGGY CODE ###

import sys
HK,WK,M = map(int, input().split())
hw_s = [list(map(int, input().split())) for _ in range(M)]
W = [0 for _ in range(WK+1)]
H = [0 for _ in range(HK+1)]
HW = [[0 for i in range(WK+1)] for _ in range(HK+1)]
# 3*10^5

for i, hw in enumerate(hw_s):
    h=hw[0]
    w=hw[1]

    H[h] += 1
    W[w] += 1

    HW[h][w] = 1

HMAXES = []
WMAXES = []
answer = 0
HMAX = max(H)
WMAX = max(W)


HMAXES = [i for i, _ in enumerate(H) if _ == HMAX]
WMAXES = [i for i, _ in enumerate(W) if _ == WMAX]

# 3*10^5
answer = HMAX + WMAX
for h in HMAXES:
    for w in WMAXES:
        if HW[h][w] == 0:
            print(answer)
            sys.exit(0)
print(answer-1)

### FIXED CODE ###

import sys
HK,WK,M = map(int, input().split())
W = [0] * (WK + 1)
H = [0] * (HK + 1)
HW = {}
# 3*10^5

for i in range(M):
    h, w = map(int, input().split())

    H[h] += 1
    W[w] += 1

    HW[(h,w)] = 1

answer = 0
HMAX = max(H)
WMAX = max(W)

HEMAX = H.count(HMAX)
WEMAX = W.count(WMAX)
if HEMAX * WEMAX > M:
    print(HMAX + WMAX)
    sys.exit(0)

HMAXES = [i for i, _ in enumerate(H) if _ == HMAX]
WMAXES = [i for i, _ in enumerate(W) if _ == WMAX]

# 3*10^5
answer = HMAX + WMAX
for h in HMAXES:
    for w in WMAXES:
        if not (h,w) in HW:
            print(answer)
            sys.exit(0)
print(answer-1)
### BUGGY CODE ###

n=int(input())
s=[]
for _ in range(n):
  s.append(input())
import collections
d=collections.Counter(s)
largest=max(list(d.values()))
ans=[]
for key in d.keys():
  if d[key]==largest:
    ans.append(key)
ans.sort()
while len(ans)>0:
  print(ans.pop(0))
  
  

### FIXED CODE ###

n=int(input())
s=[]
for _ in range(n):
  s.append(input())
import collections
d=collections.Counter(s)
largest=max(list(d.values()))
ans=[]
for key in d.keys():
  if d[key]==largest:
    ans.append(key)
ans.sort()
for _ in range(len(ans)):
  print(ans[_])
### BUGGY CODE ###

n = int(input())

tt = list(map(int, input().split()))
v = list(map(int, input().split()))

time = sum(tt);

border = [0] *(n+1)
start_v = [0] *(n+1)
end_v = [0] *(n+1)

temp = 0
for i in range(n):
	temp += tt[i]
	border[i+1] = temp
	start_v[i] = v[i]
	end_v[i+1] = v[i]

t = 0
idx = 0
ans = 0
vlast = 0
v0 = 0

# print (border)
while t < time :
	t += 0.5
	
	# tle回避
	if t < border[idx+1] and abs(v0- (vlast-0.5) ) < 0.001:
		v0 = vlast - 0.5
		ans += 0.5 * (vlast + v0) / 2
		vlast = v0
		continue

	#直接制約
	v0 = v[idx]
	if t == border[idx+1]:
		idx += 1
#		v0 = min(v0, v[idx])

	for j in range(len(border)):
		
		if border[j] <= t:
			#前の時刻からの制約
			temp = end_v[j] + (t - border[j])
			if v0 > temp:
				v0 = temp
		if border[j] >= t:
			#後ろの時刻からの制約
			temp = start_v[j] + (border[j] - t)
			if v0 > temp:
				v0 = temp

#	print(v0)
	ans += 0.5 * (vlast + v0) / 2
	vlast = v0

print (ans)



### FIXED CODE ###

n = int(input())

tt = list(map(int, input().split()))
v = list(map(int, input().split()))

time = sum(tt);
INF = 999999
border = [0] *(n+1)
start_v = [0] *(n+1)
end_v = [0] *(n+1)

temp = 0
for i in range(n):
	temp += tt[i]
	border[i+1] = temp
	start_v[i] = v[i]
	end_v[i+1] = v[i]

t = 0
idx = 0
ans = 0
vlast = 0
v0 = 0
new_interval = False
limitation_front =0 # 最初の計算に必要

# print (border)
while t < time :
	t += 0.5
	new_interval = False

	#直接制約
	v0 = v[idx]
	if t == border[idx+1]:
		idx += 1
		new_interval = True
#		v0 = min(v0, v[idx])

	if(not new_interval):
		limitation_front += 0.5
		if v0 > limitation_front:
			v0 = limitation_front
	
	if new_interval: 
		limitation_front = INF
		for j in range(n+1):
			if border[j] <= t:
				#前の時刻からの制約
				temp = end_v[j] + (t - border[j])
				if v0 > temp:
					v0 = temp
				if limitation_front > temp:
					limitation_front = temp
			else:
				break
			#print (limitation_front)


	for j in range(n+1):
		if border[j] >= t:
			#後ろの時刻からの制約
			temp = start_v[j] + (border[j] - t)
			if v0 > temp:
				v0 = temp

	#print(v0)

#	ans += 0.5 * (vlast + v0) / 2
	ans += (vlast + v0)
	vlast = v0

ans /= 4.0
print (ans)
### BUGGY CODE ###

import copy
n=int(input())
alist=list(map(int,input().split()))
blist=copy.deepcopy(alist)

sum=0
for i,a in enumerate(alist):
    for j in range(i+a,n):
        if j-i ==a+blist[j]:
            sum+=1

print(sum)     
    


### FIXED CODE ###

n=int(input())
alist=list(map(int,input().split()))

xdic={}
ydic={}

for i,a in enumerate(alist):
    #xlist.append((i+1)+a)
    #ylist.append((i+1)-a)
    tmpx=(i+1)+a
    tmpy=(i+1)-a
    if tmpx in xdic:
        xdic[tmpx]=xdic[tmpx]+1
    else:
        xdic[tmpx]=1
    if tmpy > 0:
        if tmpy in ydic:
            ydic[tmpy]=ydic[tmpy]+1
        else:
            ydic[tmpy]=1

output=0
for y in ydic:
    if y in xdic:
        output+= xdic[y]*ydic[y]

print(output)
### BUGGY CODE ###

n = int(input())
l = [int(i) for i in input().split()]

ans = 0
for i in range(n - 2):
    for j in range(i + 1, n - 1):
        for k in range(j + 1, n):
            if l[j] + l[k] <= l[i]:
                continue
            elif l[i] + l[j] <= l[k]:
                continue
            elif l[k] + l[i] <= l[j]:
                continue
            
            ans += 1

print(ans)

### FIXED CODE ###

import bisect
n = int(input())
l = [int(x) for x in input().split()]

l.sort()

ans = 0
for a in range(n):
    for b in range(a + 1, n):
        c = bisect.bisect_left(l, l[a] + l[b])
        if b < c:
            ans += c - (b + 1)

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

a = input()
b = input()
c = input()


def comp(x, y):
    return (x == '?') or (y == '?') or (x == y)


def check(s, t):
    check_st = {i: True for i in range(-10000, 10001)}
    for i, si in enumerate(s):
        for j, tj in enumerate(t):
            if not comp(si, tj):
                check_st[i - j] = False
    return check_st


ans = len(a) + len(b) + len(c)
check_ab = check(a, b)
check_bc = check(b, c)
check_ac = check(a, c)
# print(check_ab)
# print(check_bc)
# print(check_ca)

for b_idx in range(-len(b) - len(c), len(a) + len(c) + 1):
    for c_idx in range(-len(b) - len(c), len(a) + len(b) + 1):
        if check_ab[b_idx] and check_ac[c_idx] and check_bc[c_idx - b_idx]:
            l_idx = min(0, b_idx, c_idx)
            r_idx = max(len(a), b_idx + len(b), c_idx + len(c))
            ans = min(ans, r_idx - l_idx)

print(ans)


### FIXED CODE ###

a = input()
b = input()
c = input()

OFFSETS = 9000


def comp(x, y):
    return (x == '?') or (y == '?') or (x == y)


def check(s, t):
    check_st = [True] * (OFFSETS * 2 + 10)
    for i, si in enumerate(s):
        for j, tj in enumerate(t):
            if not comp(si, tj):
                check_st[i - j + OFFSETS] = False
    return check_st


ans = len(a) + len(b) + len(c)
check_ab = check(a, b)
check_bc = check(b, c)
check_ac = check(a, c)
# print(check_ab)
# print(check_bc)
# print(check_ca)

for b_idx in range(-len(b) - len(c), len(a) + len(c) + 1):
    for c_idx in range(-len(b) - len(c), len(a) + len(b) + 1):
        if check_ab[b_idx + OFFSETS] and check_ac[
                c_idx + OFFSETS] and check_bc[c_idx - b_idx + OFFSETS]:
            l_idx = min(0, b_idx, c_idx)
            r_idx = max(len(a), b_idx + len(b), c_idx + len(c))
            ans = min(ans, r_idx - l_idx)

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

"""
F
"""
import sys
input=sys.stdin.readline
mod=10**9+7
MAX=2*10**6+100

g1=[1,1]
for i in range(2,MAX+1):
    num_1=g1[-1]*i%mod
    g1.append(num_1)
    
def cmb(n,r):
    return (g1[n]*pow(g1[r],mod-2,mod)%mod)*pow(g1[n-r],mod-2,mod)%mod

r1,c1,r2,c2=map(int,input().split())
if r2-r1<c2-c1:
    c1,r1=r1,c1
    c2,r2=r2,c2

S=cmb(r1+c1,r1)
ans=S
table1=[]
table2=[]
num1=c1+1
num2=r1+1
for i in range(c2-c1):
    S=((2*S+cmb(num1+i+r1-1,r1-1))%mod+cmb(num2+i+c1-1,c1-1))%mod
    ans=(ans+S)%mod  
    
num1=r1
num2=r1+c2-c1+1
for i in range(r2-(r1+c2-c1)):
    S=((2*S-cmb(num1+i+c2,c2))%mod+cmb(num2+i+c1-1,c1-1))%mod
    ans=(ans+S)%mod  
    
num1=c1
num2=r2-(c2-c1)
for i in range(c2-c1):
    S=((2*S-cmb(num1+i+r2,r2))%mod-cmb(num2+i+c2,c2))%mod
    ans=(ans+S)%mod  

print(ans)

### FIXED CODE ###

import sys
input=sys.stdin.readline

mod=10**9+7
MAX=2*10**6+100

g1=[1,1]
g2=[1,1]
for i in range(2,MAX+1):
    num_1=g1[-1]*i%mod
    g1.append(num_1)
    g2.append(pow(num_1,mod-2,mod))
    
def cmb(n,r):
    return g1[n]*g2[r]*g2[n-r]%mod

def g(x,y):
    return cmb(x+y+2,y+1)-1

r1,c1,r2,c2=map(int,input().split())

num=(g(r2,c2)-g(r2,c1-1)-g(r1-1,c2)+g(r1-1,c1-1))%mod
print(num)
### BUGGY CODE ###

import sys
sys.setrecursionlimit(1000000000)
from collections import Counter
def key(x, y):
    return str(x)+str(y)
def main():
    N, X, Y = map(int, input().split())
    X -= 1
    Y -= 1

    M = {}
    for i in range(N):
        for j in range(i, N):
            M[key(i, j)] = j - i
    
    def helper(x, y, from_cost):
        if 0 <= x <= N-1 and 0 <= y <= N-1:
            if M[key(x,y)] > from_cost+1:
                M[key(x,y)] = from_cost + 1
                cost = from_cost + 1

                helper(x-1,y, cost)
                helper(x+1,y, cost)
                helper(x,y-1, cost)
                helper(x,y+1, cost)
        
    helper(X, Y, 0)

    cost_list = Counter(list(M.values()))
    for k in range(N-1):
        print(cost_list[k+1])


main()

### FIXED CODE ###

import sys
sys.setrecursionlimit(1000000000)
from collections import Counter
def key(x, y):
    return str(x)+str(y)
def main2():
    # TLE
    N, X, Y = map(int, input().split())
    X -= 1
    Y -= 1

    M = {}
    for i in range(N):
        for j in range(i, N):
            M[key(i, j)] = j - i
    
    def helper(x, y, from_cost):
        if 0 <= x <= N-1 and 0 <= y <= N-1:
            if M[key(x,y)] > from_cost+1:
                M[key(x,y)] = from_cost + 1
                cost = from_cost + 1

                helper(x-1,y, cost)
                helper(x+1,y, cost)
                helper(x,y-1, cost)
                helper(x,y+1, cost)
        
    helper(X, Y, 0)

    cost_list = Counter(list(M.values()))
    for k in range(N-1):
        print(cost_list[k+1])

from collections import deque
INF = 1e10


def main3():
    # official TLE
    N, X, Y = map(int, input().split())
    X -= 1
    Y -= 1
    ans = [0 for _ in range(N)]
    for sv in range(N):
        dist = [INF for _ in range(N)]
        q = deque([])

        def push(v, d):
            if dist[v] != INF: return
            dist[v] = d
            q.append(v)

        push(sv, 0)

        while q:
            sv = q.popleft()
            d = dist[sv]
            if sv > 0:
                push(sv-1, d+1)
            if sv < N-1:
                push(sv+1, d+1)
            if sv == X:
                push(Y, d+1)
            if sv == Y:
                push(X, d+1)

        for d in dist:
            ans[d] += 1
    
    for k in range(1, N):
        print(ans[k] // 2)

def main():
    N, X, Y = map(int, input().split())
    X -= 1
    Y -= 1
    dist = [0 for _ in range(N)]
    for i in range(N-1):
        for j in range(i+1, N):
            d = min(abs(X-i)+1+abs(j-Y), abs(i-j), abs(Y-i)+1+abs(j-Y))
            dist[d] += 1
    
    for k in range(1, N):
        print(dist[k])
 

main()
### BUGGY CODE ###

import math

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

D = {}
m = M
for i in range(2,M):
    while m % i == 0:
        D[i] = D.get(i,0)+1
        m = m//i

d = []
for v in D.values():
    d.append(v)

tmp = [0] * len(d)
for i in range(len(d)):
    tmp[i] = (math.factorial(N-1+d[i]) // (math.factorial(N-1)*math.factorial(d[i])))%(10**9 + 7)

ans = 1
for i in range(len(tmp)):
    ans = ans*tmp[i]%(10**9 +7)
print(ans)

### FIXED CODE ###

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

m = M
f = {}
while m%2==0:
    f[2] = f.get(2,0)+1
    m = m//2

l = int(m**0.5)+1
k = 3
while m != 1:
    if k>l:
        f[m] = f.get(m,0)+1
        break
    while m%k==0:
        f[k] = f.get(k,0)+1
        m = m//k
    k+=2
ans = 1
for k in f:
    for i in range(N-1+f[k],N-1,-1):
        ans = (ans * i) 
    for i in range(f[k]):
        ans = ans // (i+1)
    ans = ans % ((10**9)+7)
print(ans)
### BUGGY CODE ###

n=int(input())
A=[int(x) for x in input().rstrip().split()]
ans=[]
for i in range(1,n+1):
  ans.append(A.index(i)+1)
print(*ans)

### FIXED CODE ###

n=int(input())
A=[int(x) for x in input().rstrip().split()]
ans=[0 for i in range(n)]
for i in range(n):
  ans[A[i]-1]=i+1
print(*ans)
### BUGGY CODE ###

# -*- coding: utf-8 -*-
# import numpy as np

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

pare_list = []
val_list = []

for i in range(N):
    for j in range(i,N):
        pare_list.append((i,j))
        tmp = 0
        for m in range(i,j+1):
            tmp += An[m]
        val_list.append(tmp)

count = 0
for val in val_list:
    if val % M == 0:
        count += 1


print(count)
# print(pare_list)
# print(val_list)


### FIXED CODE ###

# -*- coding: utf-8 -*-
import math

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

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

Cn = [0]*(N+1)

for i,Ai in enumerate(An):
    if i == 0:
        Cn[i+1] = Ai
    else:
        Cn[i+1] = Cn[i] + Ai

# def func(n):
#     if n <= 1:
#         return 1
#     else:
#         tmp = 1
#         for i in range(2,n+1):
#             tmp = tmp * i
#         return tmp

mod = {}
for i in range(N+1):
    if Cn[i]%M in mod:
        mod[Cn[i]%M] += 1
    else:
        mod[Cn[i]%M] = 1

ans = 0
for val in mod.values():
    if val <= 1:
        continue
    elif val == 2:
        ans += 1
    else:
        # tmp = func(val) / (func(2) * func(val - 2))
        tmp = combinations_count(val,2)
        ans += int(tmp)

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

n = int(input())
s = [input() for i in range(n)]
t = set(s)
ma = 0
tmp = []
for i in t:
    tmp2 = s.count(i)
    if ma < tmp2:
        ma = tmp2
        tmp = [i]
    elif ma == tmp2:
        tmp.append(i)
tmp.sort()
#print()
for i in tmp:
    print(i)


### FIXED CODE ###

n = int(input())
s = [input() for i in range(n)]
s.sort()
max = 0
count = 1
for i in range(1,n):
    if s[i] == s[i-1]:
        count+=1
    else:
        if max < count:
            max = count
            count=1
        else:
            count=1
if max < count:
    max = count
count = 1
ans = []
for i in range(1,n):
    if s[i] == s[i-1]:
        count+=1
    else:
        if max == count:
            ans.append(s[i-1])
            count = 1
        else:
            count = 1
if max == count:
    ans.append(s[n-1])
for i in range(len(ans)):
    print(ans[i])
### BUGGY CODE ###

from collections import Counter
def ABC073C_WriteAndErase():
    N = int(input().strip())
    
    Ai = Counter()
    for i in range(N):
        num = int(input())

        if num in Ai.keys():
            del Ai[num]
        else:
            Ai[num] = 1

    print(len(Ai))
    

def main():
    ABC073C_WriteAndErase()

if __name__ == "__main__":
    main()


### FIXED CODE ###

from collections import Counter
def ABC073C_WriteAndErase():
    N = int(input().strip())
    Ai = [int(input().strip()) for i in range(N)]


    Bi = Counter(Ai)
    count = 0
    for key, val in Bi.items():
        if val % 2 == 1:
            count += 1

    print(count)
    

def main():
    ABC073C_WriteAndErase()

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

n,k=map(int,input('').split(' '))
a=input('')
a=a.split(' ')
o=[]
for p in range(n):
    a[p]=int(a[p])
    o.append(0)

p=1
h=[]
h.append(1)
j=k
while j>0:
    p=a[p-1]
    o[p-1]+=1
    if o[p-1]>=2:
        j=j-1
        c=len(h)-h.index(p)
        j=j%c

    else:
        h.append(p)
        j=j-1

print(p)

### FIXED CODE ###

n,k=map(int,input('').split(' '))
a=input('')
a=a.split(' ')
o=[]
l=[]
for p in range(n):
    a[p]=int(a[p])
    o.append(0)
    l.append('n')

p=1
h=[]
h.append(1)
j=k
aj=0
while j>0:
    p=a[p-1]
    o[p-1]+=1
    if o[p-1]>=2:
        j=j-1
        c=len(h)-l[p-1]#h.index(p)
        j=j%c

    else:
        h.append(p)
        j=j-1
    
        aj+=1
    
    l[p-1]=aj

print(p)