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

import sys
input = sys.stdin.readline
from heapq import heappush,heappop

h,w,d=map(int,input().split())
a=[list(map(int,input().split())) for _ in [0]*h]
q=int(input())
l=[0]*q
r=[0]*q
for i in range(q):
    l[i],r[i]=map(int,input().split())
A=[]
for i in range(h):
    for j in range(w):
        heappush(A,[a[i][j],i,j])
ans=[]
for i in range(h*w):
    ans.append(heappop(A)[1:])
for i in range(h*w-1,d-1,-1):
    ans[i]=abs(ans[i][0]-ans[i-d][0])+abs(ans[i][1]-ans[i-d][1])
for i in range(d):
    ans[i]=0
for i in range(q):
    print(sum(ans[i] for i in range(l[i]+d-1,r[i],d)))

### FIXED CODE ###

import sys
input = sys.stdin.readline

h,w,d=map(int,input().split())
A=[0]*(h*w)
for i in range(h):
    l=list(map(int,input().split()))
    for j in range(w):
        A[l[j]-1]=[i,j]
q=int(input())
l=[0]*q
r=[0]*q
for i in range(q):
    l[i],r[i]=map(int,input().split())
ans=[0]*(h*w)
for i in range(d,h*w):
    ans[i]=ans[i-d]+abs(A[i][0]-A[i-d][0])+abs(A[i][1]-A[i-d][1])
for i in range(q):
    print(ans[r[i]-1]-ans[l[i]-1])
### BUGGY CODE ###

n, q = list(map(int, input().split()))
s = input()
for i in range(q):
  l,r = list(map(int, input().split()))
  print(s[(l - 1):r].count('AC'))

### FIXED CODE ###

n, q = list(map(int, input().split()))
s = input()
cnt = 0
word_list = []
for i in range(n):
  if i > 0:
    if(s[i - 1] == 'A') and (s[i] == 'C') : cnt += 1 
  word_list.append(cnt)
for i in range(q):
  l, r = list(map(int, input().split()))
  print(word_list[r - 1] - word_list[l - 1])
### BUGGY CODE ###

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


### FIXED CODE ###

k,s = map(lambda x:int(x),input().split())
count = 0
for x in range(k+1) :
    for y in range(k+1):
        z = s - x - y
        if z >= 0 and z <= k :
            count += 1

print(count)
### BUGGY CODE ###

from collections import deque
n = int(input())
a_list = []
for i in range(n):
    a_list.append(deque([int(aa) - 1 for aa in input().split()]))
day = 0
battle = 0
for _ in range(n * (n - 1) // 2):
    if battle == n * (n - 1) // 2:
        break
    day += 1
    battle_today = 0
    battle_list = [-1 for _ in range(n)]
    for i in range(n):
        if len(a_list[i]) > 0:
            j = a_list[i][0]
            battle_list[i] = j
        if (battle_list[i] == j) & (battle_list[j] == i):
            battle += 1
            battle_today += 1
            a_list[i].popleft()
            a_list[j].popleft()
    if battle_today == 0:
        day = -1
        break
print(day)

### FIXED CODE ###

from collections import deque
n = int(input())
a_list = []
for i in range(n):
    a_list.append(deque([int(aa) - 1 for aa in input().split()]))
day = 0
battle = 0
for _ in range(n * (n - 1) // 2):
    if battle == n * (n - 1) // 2:
        break
    day += 1
    battle_today = 0
    tomorrow = set([])
    if (day == 1):
        player = set([i for i in range(n)])
    for i in player:
        if len(a_list[i]) == 0:
            continue
        j = a_list[i][0]
        if (i == a_list[j][0]) & (j not in tomorrow) & (len(a_list[j]) > 0) & (i not in tomorrow):
            tomorrow.add(i)
            tomorrow.add(a_list[i][0])
            battle += 1
            battle_today += 1
            a_list[i].popleft()
            a_list[j].popleft()
    player = tomorrow
    if battle_today == 0:
        day = -1
        break
print(day)
### BUGGY CODE ###

import numpy as np
H,W,M=map(int, input().split())
hl=np.array([0 for i in range(H+1)])
wl=np.array([0 for i in range(W+1)])
ms=[]
for i in range(M):
    h,w=map(int, input().split())
    hl[h]+=1
    wl[w]+=1
    ms.append([h,w])
a=max(hl)
b=max(wl)
hmax= [i for i, x in enumerate(hl) if x ==a]
wmax=[i for i, x in enumerate(wl) if x ==b]
a=max(hl)
b=max(wl)
bl=False
for x in hmax:
    for y in wmax:
        if [x,y] not in ms:
            bl=True
            break
    if bl:
        break
if bl:
    print(a+b)
else:
    print(a+b-1)

### FIXED CODE ###


H,W,M=map(int, input().split())
hl=[0 for i in range(H+1)]
wl=[0 for i in range(W+1)]
ms=[]
for i in range(M):
    h,w=map(int, input().split())
    hl[h]+=1
    wl[w]+=1
    ms.append([h,w])
a=max(hl)
b=max(wl)
hmax=[]
wmax=[]
s=0
for x in ms:
    if  hl[x[0]]==a and wl[x[1]]==b:
        s+=1
c=hl.count(a)
d=wl.count(b)
if s<c*d:
    print(a+b)
else:
    print(a+b-1)
### BUGGY CODE ###

n = int(input())
time = [0]*n
dl = [0]*n
for i in range(n):
    time[i], dl[i] = map(int, input().split())
count = 0
while len(dl):
    index = dl.index(min(dl))
    count += time[index]
    if count > dl[index]:
        print("No")
        exit()
    dl.pop(index)
    time.pop(index)
print("Yes")


### FIXED CODE ###

n = int(input())
jobs = [list(map(int, input().split())) for _ in range(n)]
jobs.sort(key=lambda x:x[1])
count = 0
for i in range(n):
    count += jobs[i][0]
    if count > jobs[i][1]:
        print("No")
        exit()
print("Yes")
### BUGGY CODE ###

import sys
input=sys.stdin.readline
R,C,K=map(int, input().split())
M=[[0 for i in range(C)]for i in range(R)]
for i in range(K):
  r,c,v=map(int, input().split())
  r-=1
  c-=1
  M[r][c]=v
dp=[[[0]*(4) for j in range(C)] for i in range(R)]
dp[0][0][1]+=M[0][0]
for r in range(R):
  for c in range(C):
    if 0<r:
      dp[r][c][1]=max(max(dp[r-1][c])+M[r][c],dp[r][c][1])
      dp[r][c][0]=max(max(dp[r-1][c]),dp[r][c][0])
    if 0<c:
      dp[r][c][3]=max(dp[r][c-1][2]+M[r][c],dp[r][c][3],dp[r][c-1][3])
      dp[r][c][2]=max(dp[r][c-1][1]+M[r][c],dp[r][c][2],dp[r][c-1][2])
      dp[r][c][1]=max(dp[r][c-1][0]+M[r][c],dp[r][c][1],dp[r][c-1][1])
      dp[r][c][0]=max(dp[r][c-1][0],dp[r][c][0])
print(max(dp[-1][-1]))

### FIXED CODE ###

import sys
input=sys.stdin.readline
def main():
  R,C,K=map(int, input().split())
  M=[[0 for i in range(C)]for i in range(R)]
  for i in range(K):
    r,c,v=map(int, input().split())
    r-=1
    c-=1
    M[r][c]=v
  dp0=[[0 for j in range(C)] for i in range(R)]
  dp1=[[0 for j in range(C)] for i in range(R)]
  dp2=[[0 for j in range(C)] for i in range(R)]
  dp3=[[0 for j in range(C)] for i in range(R)]
  dp1[0][0]+=M[0][0]
  for r in range(R):
    for c in range(C):
      if 0<r:
        dp1[r][c]=max(max(dp1[r-1][c],dp2[r-1][c],dp3[r-1][c])+M[r][c],dp1[r][c])
        dp0[r][c]=max(max(dp1[r-1][c],dp2[r-1][c],dp3[r-1][c]),dp0[r][c])
      if 0<c:
        dp3[r][c]=max(dp2[r][c-1]+M[r][c],dp3[r][c],dp3[r][c-1])
        dp2[r][c]=max(dp1[r][c-1]+M[r][c],dp2[r][c],dp2[r][c-1])
        dp1[r][c]=max(dp0[r][c-1]+M[r][c],dp1[r][c],dp1[r][c-1])
        dp0[r][c]=max(dp0[r][c-1],dp0[r][c])
  ans=0
  for i in range(R):
    for j in range(C):
      ans=max(ans,dp1[i][j],dp2[i][j],dp3[i][j])
  print(ans)
if __name__ == '__main__':
    main()
### BUGGY CODE ###

s = [int(x) if x!='?' else -1 for x in input()]

mod = 1000000007
length = len(s)
ans = list([0]*13 for i in range(length+1))
ans[0][0] = 1

mod_x10 = [0]*13
for i in range(13):
    mod_x10[i] = i * 10 % 13 - 1

for i in range(length):
    for j in range(13):
        x = mod_x10[j]
        if s[i] == -1:
            for k in range(10):
                x = (x + 1) % 13
                ans[i+1][x] += ans[i][j]
        else:
            x = (x + int(s[i]) + 1) % 13
            ans[i+1][x] += ans[i][j]

print(ans[length][5] % mod)


### FIXED CODE ###

MOD = 1000000007;

s = [int(x) if x!="?" else -1 for x in input()]

n=len(s)

r=[0]*13

c=s[0]
if (c!=-1):
	r[c]=1
else:
	for i in range(10):r[i]=1

for i in range(1,n):
	dp=[0]*26
	for j in range(13):dp[j*10%13]+=(r[j]%MOD)
	dp[13:26]=dp[0:13]
	c=s[i]
	r=[0]*13
	if (c==-1):
		w=sum(dp[4:14])
		for j in range(13):
				r[j]+=w
				w=w+dp[j+1]-dp[4+j]
	else:
		for j in range(13):
			r[j]+=dp[13-c+j]
print (r[5]%MOD)
### BUGGY CODE ###

import bisect

D = 10 ** 5

X = int(input())

L = [i**5 for i in range(-D, D)]
L2 = [i for i in range(-D, D)]

idx = bisect.bisect_left(L, X)-1

B = L[:idx]
A = L[idx:]

for a in A:
    for b in B:
        if a - b == X:
            break
    else:
        continue
    break

print(L2[L.index(a)], L2[L.index(b)])


### FIXED CODE ###

import bisect
import math

D = 120

X = int(input())

for a in range(-D, D):
    for b in range(-D-1, D-1):
        if a**5 - b**5 == X:
            break
    else:
        continue
    break

print(a, b)
### BUGGY CODE ###

import sys

input=sys.stdin.readline
sys.setrecursionlimit(1000000)

N,M=map(int,input().split())
edge=[[] for i in range(0,N)]
dedge=[0 for i in range(0,N)]
data=[]
dic={}
for i in range(M):
    a,b=map(int,input().split())
    edge[a-1].append(b-1)
    edge[b-1].append(a-1)
    dedge[a-1]+=1
    dic[(a-1,b-1)]=0
    dic[(b-1,a-1)]=0
    dic[(a-1,b-1)]=i
    dic[(b-1,a-1)]=i
    data.append([a-1,b-1,0])

if M%2==1:
    print(-1)
    exit()

ans=[0 for i in range(N)]
treeedge=[[] for i in range(0,N)]
visit=set([0])
q=set([0])
sub=set([])
while q:
    while q:
        x=q.pop()
        for i in edge[x]:
            if i not in visit:
                treeedge[x].append(i)
                treeedge[i].append(x)
                visit.add(i)
                sub.add(i)

        if not q:
            q=sub
            sub=set([])
            break



def dfs(v,pv):
    if len(treeedge[v])==1 and v!=0:
        ans[v]=(dedge[v]%2,pv)
        return dedge[v]%2

    A=dedge[v]%2
    for i in edge[v]:
        if i!=pv:
            A+=dfs(i,v)
    ans[v]=(A%2,pv)
    return ans[v][0]

dfs(0,-1)

for i in range(1,N):
    val,parent=ans[i]
    if val==1:
        index=dic[(i,parent)]
        data[index][2]=1

for i in range(M):
    a,b,val=data[i]
    if val==0:
        print(a+1,b+1)
    else:
        print(b+1,a+1)


### FIXED CODE ###

import sys

input=sys.stdin.readline
sys.setrecursionlimit(1000000)

N,M=map(int,input().split())
edge=[[] for i in range(0,N)]
dedge=[0 for i in range(0,N)]
data=[]
dic={}
for i in range(M):
    a,b=map(int,input().split())
    edge[a-1].append(b-1)
    edge[b-1].append(a-1)
    dedge[a-1]+=1
    dic[(a-1,b-1)]=0
    dic[(b-1,a-1)]=0
    dic[(a-1,b-1)]=i
    dic[(b-1,a-1)]=i
    data.append([a-1,b-1,0])

if M%2==1:
    print(-1)
    exit()

ans=[0 for i in range(N)]
treeedge=[[] for i in range(0,N)]
visit=set([0])
q=set([0])
sub=set([])
while q:
    while q:
        x=q.pop()
        for i in edge[x]:
            if i not in visit:
                treeedge[x].append(i)
                treeedge[i].append(x)
                visit.add(i)
                sub.add(i)

        if not q:
            q=sub
            sub=set([])
            break



def dfs(v,pv):
    if len(treeedge[v])==1 and v!=0:
        ans[v]=(dedge[v]%2,pv)
        return dedge[v]%2

    A=dedge[v]%2
    for i in treeedge[v]:
        if i!=pv:
            A+=dfs(i,v)
    ans[v]=(A%2,pv)
    return ans[v][0]

dfs(0,-1)

for i in range(1,N):
    val,parent=ans[i]
    if val==1:
        index=dic[(i,parent)]
        data[index][2]=1

for i in range(M):
    a,b,val=data[i]
    if val==0:
        print(a+1,b+1)
    else:
        print(b+1,a+1)
### BUGGY CODE ###

n= int(input())
a = list(map(int,input().split()))
score=1
for i in a:
  score*=i
if score>10**18:
  print(-1)
  exit()
print(score)


### FIXED CODE ###

n= int(input())
a = list(map(int,input().split()))
score=1
if 0 in a:
  print(0)
  exit()
for i in a:
  score*=i
  if score>10**18:
    print(-1)
    exit()
print(score)
### BUGGY CODE ###

def memoize(f):
    table = dict()
    def wrapper(x, i, a):
        key = (x, i)
        if key in table:
            return table[key]
        else:
            v = f(x, i, a)
            table[key] = v
            return v
    return wrapper

@memoize
def solve(x, i, a):
    if i == len(a) - 1:
        if a[i] == x:
            return 1
        else:
            return 0

    if x < a[i]:
        return 0
    else:
        m = solve(x - a[i], i + 1, a) + 1
        n = solve(x, i + 1, a)
        return max(m, n)

def main():
    n, x = [int(s) for s in input().split()]
    a = tuple(sorted(int(s) for s in input().split()))

    print(solve(x, 0, a))

main()


### FIXED CODE ###

def main():
    n, x = [int(s) for s in input().split()]
    a = [int(s) for s in input().split()]
    a.sort()

    cnt = 0
    for i, y in enumerate(a):
        if x < y:
            break
        x -= y
        cnt += 1
    else:
        # distribute to all child
        if x != 0:
            cnt -= 1
    print(cnt)

main()
### BUGGY CODE ###

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

lis = [0]*60

for a in A:
    for i in range(60):
        lis[i] += a%2
        a = a //2
        if a == 0:
            break

ans = 0
for i, j in enumerate(lis):
    ans += j * (N-j) *(2**i)
    ans = ans % (10**9 + 7)

print(ans)

### FIXED CODE ###

N = int(input())
 
lis = [0]*60
 
for a in input().split():
    a = int(a)
    for i in range(60):
        lis[i] += a % 2
        a = a//2
ans = 0
for i, j in enumerate(lis):
    ans += j * (N-j) *(2**i)
    ans = ans % (10**9 + 7)
 
print(ans)
### BUGGY CODE ###

n,k=map(int,input().split())
h=list(map(int,input().split()))
dp=[float('inf')]*n
dp[0]=0
dp[1]=abs(h[1]-h[0])
for i in range(2,n):
  for j in range(k+1):
    dp[i]=min(dp[i],dp[i-j]+abs(h[i]-h[i-j]))
  
  
#print(dp)
print(dp[n-1])

### FIXED CODE ###

n,k=map(int,input().split())
h=list(map(int,input().split()))
dp=[float('inf')]*n
dp[0]=0
dp[1]=abs(h[1]-h[0])
for i in range(2,n):
  for j in range(k+1):
    dp[i]=min(dp[i],dp[i-j]+abs(h[i]-h[i-j]))
  
  
#print(dp)
print(dp[n-1])
### BUGGY CODE ###

import bisect
def main():
    N = int(input())
    L = sorted(list(map(int,input().split())))
    Lind = []
    count = 0
    for i in reversed(range(2,N)):
        for j in reversed(range(1,i)):
            cind = bisect.bisect_right(L,L[i]-L[j])
            if cind != N-1:
                Lind.append([i,j,cind])
    for l in Lind:
        
        for k in range(cind,l[1]):
            if L[l[0]]<L[l[1]]+L[k]:
                count += 1
    print(count)
main()

### FIXED CODE ###

import bisect
def main():
    N = int(input())
    L = list(map(int,input().split()))
    L.sort()
    
    count = 0
    for i in range(N-2):
        for j in range(i+1,N-1):
            c = bisect.bisect_left(L,L[i]+L[j])
            
            count += max(0,c-1 - j)
    
    print(count)
main()
### BUGGY CODE ###

n=int(input())
a=list(map(int,input().split()))
b=[0]*n
for i in range(n):
    b[i]=a[i]-(i+1)
s=0
for i in range(n):
    s+=b[i]
mean=s//(len(b))
ans=10**10
mi=mean-10**3
ma=mean+10**3
for i in range(mi,ma):
    w=0
    c=list(map(lambda x:abs(x-i),b))
    for j in range(n):
        w+=c[j]
    if w<ans:
        ans=w
print(ans)

### FIXED CODE ###

import statistics
n=int(input())
a=list(map(int,input().split()))
b=[0]*n
for i in range(n):
    b[i]=a[i]-(i+1)
b.sort()
if n%2==1:
    m=statistics.median(b)
    b=list(map(lambda x:abs(x-m),b))
    ans=0
    for i in range(n):
        ans+=b[i]
else:
    m1=b[n//2]
    m2=b[n//2+1]
    k=list(map(lambda x:abs(x-m1),b))
    l=list(map(lambda x:abs(x-m2),b))
    ans1=0
    ans2=0
    for i in range(n):
        ans1+=k[i]
        ans2+=l[i]
    ans=min(ans1,ans2)
print(ans)
### BUGGY CODE ###

n=int(input())
h=list(map(int,input().split()))
if n>1:
  for i in range(n-1):
    for j in range(i+i,n):
      if h[i]-h[j]>1:
        print("No")
        break
    else:
      continue
    break
  else:print("Yes")
else:
  print("Yes")

### FIXED CODE ###

n=int(input())
h=list(map(int,input().split()))
max=h[0]
flag=0
for i in h:
  if i>=max:
    max=i
  elif max-i>=2:
    flag=1
    break
if flag==0:
  print("Yes")
else:
  print("No")
### BUGGY CODE ###

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

rList = []
gList = []
bList = []

for indx in range(N):
    if S[indx] == 'R':
        rList.append(indx)
    elif S[indx] == 'G':
        gList.append(indx)
    elif S[indx] == 'B':
        bList.append(indx)

NoSum = 0
fList = rList
sList = gList
remain = 'B'

for fItem in fList:
    for sItem in sList:
        if ((2 * max(fItem, sItem) - min(fItem, sItem)) <= N-1):
            if (S[(2 * max(fItem, sItem) - min(fItem, sItem))] == remain):
                NoSum += 1
        
        if ((max(fItem, sItem) - min(fItem, sItem)) % 2 == 0):
            if (S[int((max(fItem, sItem) + min(fItem, sItem))/2)] == remain):
                NoSum += 1
        
        if ((2 * min(fItem, sItem) - max(fItem, sItem)) >= 0):
            if  (S[(2 * min(fItem, sItem) - max(fItem, sItem))] == remain):
                NoSum += 1

print(len(rList) * len(gList) * len(bList) - NoSum)

### FIXED CODE ###

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

rList = []
gList = []
bList = []

for indx in range(N):
    if S[indx] == 'R':
        rList.append(indx)
    elif S[indx] == 'G':
        gList.append(indx)
    elif S[indx] == 'B':
        bList.append(indx)

NoSum = 0
fList = rList
sList = gList
remain = 'B'

for fItem in fList:
    for sItem in sList:
        prsMax = max(fItem, sItem)
        prsMin = min(fItem, sItem)
        if ((2 * prsMax - prsMin) <= N-1):
            if (S[(2 * prsMax - prsMin)] == remain):
                NoSum += 1
        
        if ((prsMax - prsMin) % 2 == 0):
            if (S[int((prsMax + prsMin)/2)] == remain):
                NoSum += 1
        
        if ((2 * prsMin - prsMax) >= 0):
            if  (S[(2 * prsMin - prsMax)] == remain):
                NoSum += 1

print(len(rList) * len(gList) * len(bList) - NoSum)
### BUGGY CODE ###

N = int(input())
XL = [list(map(int, input().split())) for _ in range(N)]

def compare(item):
  return item[1]

newXL = sorted([[x-l, x+l] for x, l in XL], key=compare)

memo = [0]

for i in range(N):
  flag = True
  for j in memo:
    if newXL[i][0] < newXL[j][1]:
      flag = False
  if flag:
    memo.append(i)

print(len(memo))

### FIXED CODE ###

N = int(input())
XL = [list(map(int, input().split())) for _ in range(N)]

newXL = sorted([[x-l, x+l] for x, l in XL], key=lambda x:x[1])

previous = 0
total = 1

for i in range(1, N):
  if newXL[i][0] < newXL[previous][1]:
    pass
  else:
    previous = i
    total += 1
    
print(total)
### BUGGY CODE ###

N, M = [int(x) for x in input().split(" ")]
S = input()
T = input()

N = len(S)
M = len(T)

import sys
sys.setrecursionlimit(500000)


def gcd(a, b):
    if (a < b):
        return gcd(b, a)
    if a % b == 0:
        return b
    else:
        return gcd(b, a % b)


def maxkobai(a, b):
    return a * b // gcd(a, b)


L = maxkobai(N, M)
ret = L
x = {}

for l in range(0, L + 1):
    x[l] = '-'


for n in range(0, N):
    x[n * (L//N) + 1] = S[n]

# print(x)

for m in range(0, M):
    idx = m * (L // M) + 1
    x_idx = x[idx]
    if x_idx != '-' and x_idx != T[m]:
        ret = -1
        break

print(ret)

### FIXED CODE ###

N, M = [int(x) for x in input().split(" ")]
S = input()
T = input()

N = len(S)
M = len(T)


S = [ord(c) for c in S]
T = [ord(c) for c in T]


def gcd(a, b):
    if a < b:
        a, b = b, a
    while b:
        a, b = b, a % b
    return a


def maxkobai(a, b):
    return a * b // gcd(a, b)


L = maxkobai(N, M)
ret = L
x = dict()

for n in range(0, N):
    x[n * (L//N) + 1] = S[n]


for m in range(0, M):
    idx = m * (L // M) + 1
    tmp = x.get(idx, 0)

    if tmp != T[m] and tmp != 0:
        ret = -1
        break

print(ret)
### BUGGY CODE ###

Num = 10 ** 9 + 7
N, M = map(int, input().split())
danger = []
for i in range(M):
  danger.append(int(input()))
l = [1, 1]
for i in range(1, N):
  if i in danger:
    l[1] = 0
  l = [l[1] % Num, (l[0] + l[1]) % Num]
if N in danger:
  l[1] = 0
print(l[1])

### FIXED CODE ###

Num = 10 ** 9 + 7
N, M = map(int, input().split())
danger = -1
if M != 0:
  danger = int(input())
count = 1
l = [1, 1]
for i in range(1, N):
  if i == danger:
    l[1] = 0
    if count < M:
      danger = int(input())
      count += 1
  l = [l[1] % Num, l[0] + l[1]]
  if l == [0, 0]:
    break
if N == danger:
  l[1] = 0
print(l[1] % Num)
### BUGGY CODE ###

import numpy as np
n,k=map(int,input().split())
a=[0]+[int(input())-k for _ in range(n)]
ac=np.cumsum(a)

def rec(l):
    ll=len(l)
    if ll<=1:
        return 0
    l1=l[:ll//2]
    l2=l[ll//2:]
    res=rec(l1)+rec(l2)
    l1.sort()
    l2.sort()
    i2=0
    for i in range(len(l1)):
        while i2<len(l2) and l2[i2]<l1[i]:
            res+=len(l1)-i
            i2+=1
    return res
print(n*(n+1)//2-rec(ac))
    
    

### FIXED CODE ###

n,k=map(int,input().split())
a=[0]+[int(input())-k for _ in range(n)]
sm=0
ac=[]
for ai in a:
    sm+=ai
    ac.append(sm)


def rec(l):
    ll=len(l)
    if ll<=1:
        return 0
    l1=l[:ll//2]
    l2=l[ll//2:]
    res=rec(l1)+rec(l2)
    l1.sort()
    l2.sort()
    i2=0
    for i in range(len(l1)):
        while i2<len(l2) and l2[i2]<l1[i]:
            res+=len(l1)-i
            i2+=1
    return res
print(n*(n+1)//2-rec(ac))
### BUGGY CODE ###

N=int(input())
S=str(input())
S=list(S)
ans=0
for i in range(0,N-2):
    for j in range(i+1,N-1):
        for k in range(j+1,N):
            if (S[i] != S[j]) and (S[j] != S[k]) and (S[k] != S[i]):
                if j-i != k-j:
                    ans += 1
                
print(ans)            

### FIXED CODE ###

N=int(input())
S=str(input())
S=list(S)
ans=S.count('R')*S.count('G')*S.count('B')
for i in range(N): #判定を簡単にするためR:=1,G:=2,B:=4と置き換えておく
    if S[i]=='R':
        S[i]=1
    elif S[i]=='G':
        S[i]=2
    elif S[i]=='B':
        S[i]=4
for i in range(0,N-2):
    for j in range(i+1,N-1):
        k=(j-i)+j
        if k>N-1:
            continue
        if S[i]+S[j]+S[k] == 7 :
            ans -= 1
print(ans)
### BUGGY CODE ###

n,m = map(int,input().split())
ab = [list(map(int,input().split())) for _ in range(m)]
ab.sort()
mid = []
cand = []
mid_id = 0
for i in range(m):
  if ab[i][0] == 1:
    mid.append(ab[i][1])
  elif ab[i][0] == n or ab[i][1] == n:
    cand.append(ab[i])

if len(mid) == 0:
  print('IMPOSSIBLE')
  exit()
  
for j in range(len(cand)):
  if cand[j][0] in mid and cand[j][1] == n:
    print('POSSIBLE')
    exit()
  elif cand[j][1] in mid and cand[j][0] == n:
    print('POSSIBLE')
    exit()

print('IMPOSSIBLE')

### FIXED CODE ###

n,m = map(int,input().split())
ab = [list(map(int,input().split())) for _ in range(m)]
ab.sort()
mid = []
cand = []
for i in range(m):
  if ab[i][0] == 1:
    mid.append(ab[i][1])
  elif ab[i][0] == n:
    cand.append(ab[i][1])
  elif ab[i][1] == n:
    cand.append(ab[i][0])    

if len(set(mid) & set(cand)) > 0:
  print('POSSIBLE')
else:
  print('IMPOSSIBLE')
### BUGGY CODE ###

N = int(input())
S = str(input())
ans = 0
for i in range(N):
  for j in range(N):
    if i < j:
      for k in range(N):
        if j < k:
          if S[i] != S[j] and S[i] != S[k] and S[k] != S[j] and j-i != k-j and i < j and j < k:
              ans += 1
print(ans)    

### FIXED CODE ###

N = int(input())
S = str(input())
r = 0
g = 0
b = 0
#S[i],S[j],S[k]が違うものはr*g*b通り
for i in range(N):
  if S[i] == 'R':
    r += 1
  elif S[i] == 'G':
    g += 1
  else:
    b += 1
tot = r*g*b
#S[i],S[j],S[k]が違うかつj-i=k-jを満たすものは引く
minus = 0
for i in range(N-2):
  for j in range(i+1,N-1):
    if 2*j-i < N:
      
      if S[i] != S[j] and S[j] != S[2*j-i] and S[i] != S[2*j-i]:
        minus += 1
print(tot - minus)
### BUGGY CODE ###

N = int(input())

members = list(map(int, input().split()))
junban = []

app = junban.append

for i in range(1, N+1):
  app(members.index(i)+1)
  
for i in junban:
  print(i,end=' ')

### FIXED CODE ###

N = int(input())
members = list(map(int, input().split()))
junban = {}

for i,member in zip(range(N), members):
  junban[member] = i+1
  
for i in junban.values():
  print(i,end=' ')
### BUGGY CODE ###

s=input()
CHECK=[0 for i in range(2021)]
ans=0
S=int(s)
for i in range(len(s)):
    temp=(S%pow(10,i+1))%2019
    if temp==0:
        ans+=1
    elif CHECK[temp]==0:
        CHECK[temp]=1
    else:
        ans+=1
 
print(ans)

### FIXED CODE ###


S=input()
s=[0 for i in range(len(S))]

for i in range(len(S)):
    s[i]=int(S[i])
CHECK=[0 for i in range(2021)]
ans=0
temp=0
for i in range(1,len(s)+1):
    #print(s[-i])
    temp=(temp+s[-i]*pow(10,i-1,2019)+2019*2)%2019
    #print(i,temp)
    #print(temp)
    CHECK[temp]+=1
for i in CHECK:
    ans+=i*(i-1)//2

ans+=CHECK[0]
 
print(ans)