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

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

# In[1]:


N = int(input())


# In[15]:


def func(i,j,N):
    ans = []
    for x in range(1,N+1):
        x_ = str(x)
        if x_[0] == str(i) and x_[-1] == str(j):
            ans += [x]
    return ans


# In[23]:


ans = 0
for i in range(10):
    for j in range(10):
        ans += len(func(i,j,N))*len(func(j,i,N))
print(ans)


# In[ ]:






### FIXED CODE ###

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

# In[1]:


N = int(input())


# In[15]:


def func(i,j,N):
    ans = []
    for x in range(1,N+1):
        x_ = str(x)
        if x_[0] == str(i) and x_[-1] == str(j):
            ans += [x]
    return ans


# In[23]:


ans = 0
for i in range(10):
    for j in range(10):
        ans += len(func(i,j,N))*len(func(j,i,N))
print(ans)


# In[ ]:
### BUGGY CODE ###

from functools import reduce
from operator import xor

if __name__ == '__main__':
    N = int(input())
    A = list(map(int, input().split()))

    # A = [2, 5, 4, 6]
    # N = len(A)

    n_satisfied = N
    for l in range(N):
        for r in range(l + 1, N):
            # print(A[l: r + 1])
            sum_lr = reduce(lambda a, b: a + b, A[l:r + 1])
            xor_lr = reduce(xor, A[l:r + 1])
            if sum_lr == xor_lr:
                n_satisfied += 1

    print(n_satisfied)


### FIXED CODE ###

if __name__ == '__main__':
    N = int(input())
    A = list(map(int, input().split()))

    # A = [885, 8, 1, 128, 83, 32, 256, 206, 639, 16, 4, 128, 689, 32, 8, 64, 885, 969, 1]
    # N = len(A)

    n_satisfied = 0
    sum_lr = 0
    xor_lr = 0
    l, length = 0, 0

    while True:
        while l + length != N and \
                sum_lr + A[l + length] == xor_lr ^ A[l + length]:
            sum_lr += A[l + length]
            xor_lr ^= A[l + length]
            length += 1

        # print("l, length", l, length)
        n_satisfied += length

        if l == N:
            break

        sum_lr -= A[l]
        xor_lr -= A[l]
        l += 1
        length -= 1

    print(n_satisfied)
### BUGGY CODE ###

from collections import deque
h,w=map(int,input().split())
q=deque()
l=[]
for i in range(h):
  l.append(list(input()))
lb=[[0 for i in range(w)] for j in range(h)]
for i in range(h):
  for j in range(w):
    if l[i][j]=="#":
      q.append([i,j])
move=[[1,0],[-1,0],[0,1],[0,-1]]
count=0
b=True
q2=deque()
while b:
  while q:
    q1=q.popleft()
    x1=q1[0]
    y1=q1[1]
    for i in range(4):
      dx=move[i][0]
      dy=move[i][1]
      x=x1+dx
      y=y1+dy
      if x<0 or x>h-1 or y<0 or y>w-1:
        pass
      elif l[x][y]=="#":
        pass
      else:
        l[x][y]="#"
        q2.append([x,y])
  if len(q2)!=0:
    q=q2
    q2=deque()
    count+=1
  else:
    b=False
print(count)

### FIXED CODE ###

from collections import deque
h,w=map(int,input().split())
q=deque()
l=[]
for i in range(h):
  l.append(list(input()))
lb=[[0 for i in range(w)] for j in range(h)]
for i in range(h):
  for j in range(w):
    if l[i][j]=="#":
      q.append([i,j])
move=[[1,0],[-1,0],[0,1],[0,-1]]
count=0
b=True
q2=deque()
while b:
  while q:
    q1=q.popleft()
    x1=q1[0]
    y1=q1[1]
    for i in range(4):
      dx=move[i][0]
      dy=move[i][1]
      x=x1+dx
      y=y1+dy
      if x<0 or x>h-1 or y<0 or y>w-1:
        pass
      elif l[x][y]=="#":
        pass
      else:
        l[x][y]="#"
        q2.append([x,y])
  if len(q2)!=0:
    q=q2
    q2=deque()
    count+=1
  else:
    b=False
print(count)
### BUGGY CODE ###

from collections import deque
H,W=map(int,input().split())
Ch,Cw=map(int,input().split())
Dh,Dw=map(int,input().split())
m=[list(input()) for _ in range(H)]
s=(Ch-1,Cw-1)
g=(Dh-1,Dw-1)
q=deque()
q.append(s)
d={s:0}
while q:
    y,x=q.popleft()
    for dy,dx in [(0,1),(1,0),(0,-1),(-1,0)]:
        ny=y+dy
        nx=x+dx
        if ny<0 or ny>=H or nx<0 or nx>=W:
            continue
        if m[ny][nx]=='.':
            if (ny,nx) not in d:
                q.append((ny,nx))
                d[(ny,nx)]=d[(y,x)]
            elif d[(ny,nx)]>d[(y,x)]:
                q.append((ny,nx))
                d[(ny,nx)]=d[(y,x)]
    for dy,dx in [(-2,-2),(-1,-2),(0,-2),(1,-2),(2,-2),(-2,-1),(-1,-1),(1,-1),(2,-1),(-2,0),(2,0),(-2,1),(-1,1),(1,1),(2,1),(-2,2),(-1,2),(0,2),(1,2),(2,2)]:
        ny=y+dy
        nx=x+dx
        if ny<0 or ny>=H or nx<0 or nx>=W:
            continue
        if m[ny][nx]=='.':
            if (ny,nx) not in d and (ny-1,nx) not in d and (ny,nx-1) not in d and (ny+1,nx) not in d and (ny+1,nx) not in d:
                q.append((ny,nx))
                d[(ny,nx)]=d[(y,x)]+1
            elif (ny,nx) in d and d[(ny,nx)]>d[(y,x)]+1:
                q.append((ny,nx))
                d[(ny,nx)]=d[(y,x)]+1
if g in d:
    print(d[g])
else:
    print(-1)

### FIXED CODE ###

from collections import deque
INF=10**10
H,W=map(int,input().split())
Ch,Cw=map(int,input().split())
Dh,Dw=map(int,input().split())
m=[list(input()) for _ in range(H)]
s=(Ch-1,Cw-1)
g=(Dh-1,Dw-1)
d=[[INF]*W for _ in range(H)]
d[s[0]][s[1]]=0
q=deque()
q.append(s)
while q:
    y,x=q.pop()
    for dy,dx in [(0,1),(1,0),(0,-1),(-1,0)]:
        ny=y+dy
        nx=x+dx
        if ny<0 or ny>=H or nx<0 or nx>=W:
            continue
        if m[ny][nx]=='.' and d[ny][nx]>d[y][x]:
            q.append((ny,nx))
            d[ny][nx]=d[y][x]
    for dy in range(-2,3):
        for dx in range(-2,3):
            if abs(dy)+abs(dx)<=1:
                continue
            ny=y+dy
            nx=x+dx
            if ny<0 or ny>=H or nx<0 or nx>=W:
                continue
            if m[ny][nx]=='.' and d[ny][nx]>d[y][x]+1:
                q.appendleft((ny,nx))
                d[ny][nx]=d[y][x]+1
ans=d[g[0]][g[1]]
if ans<INF:
    print(ans)
else:
    print(-1)
### BUGGY CODE ###

k = int(input())
import fractions
ans = 0
for i in range(1,k+1):
         for j in range(i,k+1):
                  for l in range(j,k+1):
                           tmp = fractions.gcd(i,j)
                           tmp = fractions.gcd(tmp,l)
                           if i == j == l:
                                    ans += tmp
                           elif i == j or j == l or l == i:
                                    ans += 3 * tmp
                           else:
                                    ans += 6 * tmp
print(ans)


### FIXED CODE ###

k = int(input())
import math
ans = 0
for i in range(1,k+1):
         for j in range(i,k+1):
                  for l in range(j,k+1):
                           tmp = math.gcd(i,j)
                           tmp = math.gcd(tmp,l)
                           if i == j == l:
                                    ans += tmp
                           elif i == j or j == l or l == i:
                                    ans += 3 * tmp
                           else:
                                    ans += 6 * tmp
print(ans)
### BUGGY CODE ###

S = list(input())
Q = int(input())
for i in range(Q):
  #print(S)
  q = input()
  if q == "1":
    S.reverse()
    #print("1",S)
  else:
    q,f,c = q.split()
    if f == "1":
      S = [c]+S
    else:
      S = S+[c]
print("".join(S))

### FIXED CODE ###

import collections
S = collections.deque(input())
Q = int(input())
reverse = False
for i in range(Q):
  q = input()
  if q == "1":
    reverse = not reverse
  else:
    q,f,c = q.split()
    if (f == "1" and not reverse) or (f == "2" and reverse):
      S.appendleft(c)
    else:
      S.append(c)
if not reverse:
  print("".join(S))
else:
  print("".join(reversed(S)))
### BUGGY CODE ###

# -*- coding: utf-8 -*-
import sys
from bisect import bisect_left,bisect_right
sys.setrecursionlimit(10**9)
INF=10**18
MOD=10**9+7
input=lambda: sys.stdin.readline().rstrip()
YesNo=lambda b: bool([print('Yes')] if b else print('No'))
YESNO=lambda b: bool([print('YES')] if b else print('NO'))
int1=lambda x:int(x)-1

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

edge=[[] for _ in range(N)]
edges=[]
s=set([N-1])
for _ in range(M):
    l,r,c=map(int,input().split())
    l-=1
    edges.append((l,r,c))
    s.add(l)
V=list(s)
V.sort()
for l,r,c in edges:
    left=bisect_right(V,l)
    right=bisect_left(V,r)
    for i in V[left:right]:
        edge[l].append((c,i))
from heapq import heappop,heappush
# edges=[[(cost1,v1),(cost2,v2)],...]
def dijkstra(start,n,edges):
    d=[INF]*n
    used=[False]*n
    d[start]=0
    used[start]=True
    edgelist=[]
    for edge in edges[start]:
        heappush(edgelist,edge)
    while edgelist:
        minedge=heappop(edgelist)
        if used[minedge[1]]:
            continue
        v=minedge[1]
        d[v]=minedge[0]
        used[v]=True
        for edge in edges[v]:
            if not used[edge[1]]:
                heappush(edgelist,(edge[0]+d[v],edge[1]))
    return d

d=dijkstra(0,N,edge)
print(d[-1] if d[-1]!=INF else -1)

### FIXED CODE ###

# -*- coding: utf-8 -*-
import sys
from bisect import bisect_left,bisect_right
sys.setrecursionlimit(10**9)
INF=10**18
MOD=10**9+7
input=lambda: sys.stdin.readline().rstrip()
YesNo=lambda b: bool([print('Yes')] if b else print('No'))
YESNO=lambda b: bool([print('YES')] if b else print('NO'))
int1=lambda x:int(x)-1

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

edge=[[] for _ in range(N)]
for i in range(N-1):
    edge[i+1].append((0,i))
for _ in range(M):
    l,r,c=map(int,input().split())
    l-=1
    r-=1
    edge[l].append((c,r))

from heapq import heappop,heappush
# edges=[[(cost1,v1),(cost2,v2)],...]
def dijkstra(start,n,edges):
    d=[INF]*n
    used=[False]*n
    d[start]=0
    used[start]=True
    edgelist=[]
    for edge in edges[start]:
        heappush(edgelist,edge)
    while edgelist:
        minedge=heappop(edgelist)
        if used[minedge[1]]:
            continue
        v=minedge[1]
        d[v]=minedge[0]
        used[v]=True
        for edge in edges[v]:
            if not used[edge[1]]:
                heappush(edgelist,(edge[0]+d[v],edge[1]))
    return d

d=dijkstra(0,N,edge)
print(d[-1] if d[-1]!=INF else -1)
### BUGGY CODE ###

# D - Lamp

H, W = map(int, input().split())
M = [[str(m) for m in input()] for _ in range(H)]
U = [[0] * W for _ in range(H)]
L = [[0] * W for _ in range(H)]
D = [[0] * W for _ in range(H)]
R = [[0] * W for _ in range(H)]

for i in reversed(range(H)):
    for j in reversed(range(W)):
        if M[i][j] == '#':
            continue

        if i == H - 1:
            D[i][j] = 1
        else:
            D[i][j] = D[i + 1][j] + 1

        if j == W - 1:
            R[i][j] = 1
        else:
            R[i][j] = R[i][j + 1] + 1

mx = 0
for i in range(H):
    for j in range(W):
        if M[i][j] == '#':
            continue

        if i == 0:
            U[i][j] = 1
        else:
            U[i][j] = U[i - 1][j] + 1

        if j == 0:
            L[i][j] = 1
        else:
            L[i][j] = L[i][j - 1] + 1

        p = U[i][j] + L[i][j] + D[i][j] + R[i][j] - 3
        mx = max(mx, p)

# mx = 0
# for i in range(H):
#     for j in range(H):
#         p = U[i][j] + L[i][j] + D[i][j] + R[i][j] - 3
#         mx = max(mx, p)

print(mx)


### FIXED CODE ###

# # D - Lamp

import numpy as np

H, W = map(int, input().split())
M = [list(input()) for _ in range(H)]
M = (np.array(M) == '.') * 1

L = np.zeros((H, W), dtype=int)
R = np.zeros((H, W), dtype=int)
D = np.zeros((H, W), dtype=int)
U = np.zeros((H, W), dtype=int)

for i in range(W):
    if i == 0:
        L[:, i] = M[:, i]
        R[:, W - i - 1] = M[:, W - i - 1]
    else:
        L[:, i] = (L[:, i - 1] + 1) * M[:, i]
        R[:, W - i - 1] = (R[:, W - i] + 1) * M[:, W - i - 1]

for i in range(H):
    if i == 0:
        U[i, :] = M[i, :]
        D[H - i - 1, :] = M[H - i - 1, :]
    else:
        U[i, :] = (U[i - 1, :] + 1) * M[i, :]
        D[H - i - 1, :] = (D[H - i, :] + 1) * M[H - i - 1, :]

print(max(np.max(L + R + D + U - 3), 0))
### BUGGY CODE ###

from sys import stdout
printn = lambda x: stdout.write(str(x))
inn = lambda : int(input())
inl   = lambda: list(map(int, input().split()))
inm   = lambda:      map(int, input().split())
ins = lambda : input().strip()
DBG = True  and False
BIG = 999999999
R = 10**9 + 7

def ddprint(x):
  if DBG:
    print(x)

from collections import defaultdict,deque
n = inn()
pr = defaultdict(list)
ch = defaultdict(list)
for i in range(1,n+1):
    a = inl()
    for j in range(n-2):
        x1 = x2 = i
        y1 = a[j]
        y2 = a[j+1]
        if x1>y1:
            x1,y1 = y1,x1
        if x2>y2:
            x2,y2 = y2,x2
        ch[(x1,y1)].append((x2,y2))
        pr[(x2,y2)].append((x1,y1))
g = {}
q = deque([])
for i in range(1,n):
    for j in range(i+1,n+1):
        if (i,j) not in pr:
            q.append((i,j))
            g[(i,j)] = 1
        else:
            g[(i,j)] = 0
ddprint(ch)
ddprint(pr)
ddprint(g)
while len(q)>0:
    z = q.popleft()
    for y in ch[z]:
        g[y] = max(g[y], g[z]+1)
        pr[y].remove(z)
        if len(pr[y])==0:
            del pr[y]
            q.append(y)
if min(g.values())==0:
    print(-1)
else:
    print(max(g.values()))


### FIXED CODE ###

from sys import stdout
printn = lambda x: stdout.write(str(x))
inn = lambda : int(input())
inl   = lambda: list(map(int, input().split()))
inm   = lambda:      map(int, input().split())
ins = lambda : input().strip()
DBG = True  and False
BIG = 999999999
R = 10**9 + 7

def ddprint(x):
  if DBG:
    print(x)

#from collections import defaultdict,deque
n = inn()
pr = [[ [] for i in range(n+1) ] for j in range(n+1)]
ch = [[ [] for i in range(n+1) ] for j in range(n+1)]
for i in range(1,n+1):
    a = inl()
    for j in range(n-2):
        x1 = x2 = i
        y1 = a[j]
        y2 = a[j+1]
        if x1>y1:
            x1,y1 = y1,x1
        if x2>y2:
            x2,y2 = y2,x2
        ch[x1][y1].append((x2,y2))
        pr[x2][y2].append((x1,y1))
g = [ [0]*(n+1) for i in range(n+1) ]
q = []
for i in range(1,n):
    for j in range(i+1,n+1):
        if len(pr[i][j])==0:
            q.append((i,j))
            g[i][j] = 1
        else:
            g[i][j] = 0
ddprint(ch)
ddprint("pr")
ddprint(pr)
ddprint(g)
while len(q)>0:
    z = q.pop()
    i,j = z
    for u,v in ch[i][j]:
        g[u][v] = max(g[u][v], g[i][j]+1)
        #ddprint("y {} z {}".format(y,z))
        pr[u][v].remove(z)
        if len(pr[u][v])==0:
            #del pr[y]
            q.append((u,v))
ddprint("newg")
ddprint(g)
#gmn = [min(r[1:]) for r in g[1:]]
gmn = BIG
for i in range(1,n):
    for j in range(i+1,n+1):
        gmn = min(gmn,g[i][j])
if gmn==0:
    print(-1)
else:
    print(max([max(r) for r in g]))
### BUGGY CODE ###

from collections import deque

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

    A.sort()
    
    A=deque(A)

    escape=deque([])
    while len(A)>0:
        minute=A.popleft()
        tmp=deque([])

        flag=0
        while len(A)>0:
            maximum=A.pop()
            if maximum==minute:
                flag=1
            if maximum%minute!=0:
                tmp.appendleft(maximum)

        if flag!=1:
            escape.append(minute)
        A=tmp

    print(len(escape))




if __name__=="__main__":
    main()

### FIXED CODE ###

from collections import deque
import math

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

    A.sort(reverse=True)

    Amax=max(A)

    dp=[0]*Amax

    tmp=-1
    res=0
    for i in range(len(A)):
        a=A.pop()
        if a==tmp:
            continue
        if dp[a-1]==0:
            if len(A)>0:
                if A[len(A)-1]!=a:
                    res+=1
            else:
                res+=1
            m=2
            while (a*m)<=Amax:
                dp[a*m-1]=1
                m+=1
        tmp=a

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

from collections import deque
n,k,q = map(int, input().split())
a = [int(input()) for _ in range(q)]
start = [k-q]*n
points = deque(start)
for i in set(a):
    points[i-1] += a.count(i)
for _ in range(len(points)):
  x = points.popleft()
  if x <= 0:
    print('No')
  else:
    print('Yes')

### FIXED CODE ###

n,k,q=map(int,input().split())
a=[k-q]*n
for i in range(q):
    point=int(input())
    a[point-1] += 1
for i in range(len(a)):
    if a[i] > 0:
        print("Yes")
    else:
        print("No")
### BUGGY CODE ###

N = list(map(int, input()))
MOD = 2019
cnt = 0
M = len(N)

candi = []
for i in range(0,M-4):
    for j in range(i+4,M+1):
        if sum(N[i:j]) % 3==0:
            ans = N[i]
            for a in N[i+1:j]:
                ans = (ans * 10 + a)%673
            if ans == 0:
                cnt += 1
                

print(cnt)

### FIXED CODE ###

from collections import Counter

N = list(map(int, input()))
MOD = 2019
cnt = 0
M = len(N)
ans = 0
mod_list = [0]
ten = 1

for n in N[::-1]:
    ans += ten*n
    mod_list.append(ans%MOD)
    ten *= 10
    ten %= MOD

SUM = 0
for k,v in Counter(mod_list).items():
    SUM += v * (v-1) /2

print(int(SUM))
### BUGGY CODE ###

from collections import Counter, defaultdict

n, m = map(int, input().split())
ab = sorted([list(map(int, input().split())) for i in range(n)])
c = [[]] * m
a, b = ab[0]
last = a
ad = [b]
for i in range(1, n):
    a, b = ab[i]
    if a == last:
        ad.append(b)
    else:
        if last <= m:
            c[last - 1] = ad
        ad = [b]
    last = a
if a <= m:
    c[a - 1] = ad
choice = defaultdict(int)
ans = 0
for i in range(m):
    for k, v in Counter(c[i]).items():
        choice[k] += v
    if choice:
        use = max(choice)
        v = choice.pop(use)
        if v - 1 > 0:
            choice[use] = v - 1
        ans += use
print(ans)

### FIXED CODE ###

import heapq

n, m = map(int, input().split())
ab = sorted([list(map(int, input().split())) for i in range(n)])
c = [[]] * m
a, b = ab[0]
last = a
ad = [b]
for i in range(1, n):
    a, b = ab[i]
    if a == last:
        ad.append(b)
    else:
        if last <= m:
            c[last - 1] = ad
        ad = [b]
    last = a
if a <= m:
    c[a - 1] = ad
a = [3, 0, 2, 6]
choice = []
heapq.heapify(choice)
ans = 0
for i in range(m):
    for j in c[i]:
        heapq.heappush(choice, -j)
    if choice:
        ans -= heapq.heappop(choice)
print(ans)
### BUGGY CODE ###

n = int(input())
a = list(map(int, input().split()))
q = int(input())

for _ in range(q):
  b,c = map(int, input().split())
  if b in a:
    for i in range(n):
      if a[i] == b: a[i] = c
    print(sum(a))
  else:
    print(sum(a))

### FIXED CODE ###

n = int(input())
a = list(map(int, input().split()))
q = int(input())

ans = sum(a)
nums = [0]*(10**5+1)
for i in a: nums[i] += 1

for _ in range(q):
  b,c = map(int, input().split())
  if nums[b] > 0:
    ans -= b*nums[b]
    nums[c] += nums[b]
    ans += c*nums[b]
    print(ans)
    nums[b] = 0
  else:
    print(ans)
### BUGGY CODE ###

import sys
import numpy as np
import numba
from numba import njit
i8 = numba.int64

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

@njit((i8[:], ), cache=True)
def main(XYP):
    X, Y, P = XYP[::3], XYP[1::3], XYP[2::3]
    N = len(X)
    dp = np.empty((3**N, N), np.int64)  # 建設、人 -> コスト
    dp[0] = np.minimum(np.abs(X), np.abs(Y))
    size = np.empty(3**N, np.int64)
    size[0] = 0
    for n in range(N):
        B = 3**n
        DX = np.abs(X - X[n])
        DY = np.abs(Y - Y[n])
        for s in range(B):
            dp[s + B] = np.minimum(dp[s], DX)
            dp[s + 2 * B] = np.minimum(dp[s], DY)
            size[s + B] = size[s + 2 * B] = size[s] + 1
    dp *= P
    cost = dp.sum(axis=1)
    ans = np.full(N + 1, cost[0], np.int64)
    for s in range(3**N):
        n = size[s]
        ans[n] = min(ans[n], cost[s])
    return ans

N = int(readline())
XYP = np.array(read().split(), np.int64)

ans = main(XYP)
print('\n'.join(map(str, ans.tolist())))

### FIXED CODE ###

import sys
import numpy as np
import numba
from numba import njit
i8 = numba.int64

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

@njit((i8[:], ), cache=True)
def main(XYP):
    X, Y, P = XYP[::3], XYP[1::3], XYP[2::3]
    N = len(X)
    dp_X = np.empty((1 << N, N), np.int64)  # 建設、人 -> Xコスト
    dp_X[0] = np.abs(X) * P
    for n in range(N):
        B = 1 << n
        dp_X[B:2 * B] = np.minimum(dp_X[:B], np.abs(X - X[n]) * P)

    dp_Y = np.empty((1 << N, N), np.int64)  # 建設、人 -> Xコスト
    dp_Y[0] = np.abs(Y) * P
    for n in range(N):
        B = 1 << n
        dp_Y[B:2 * B] = np.minimum(dp_Y[:B], np.abs(Y - Y[n]) * P)

    popcount = np.zeros(1 << N, np.int64)
    for n in range(N):
        popcount[1 << n:1 << n + 1] = popcount[:1 << n] + 1

    INF = 10**18
    ans = np.full(N + 1, INF, np.int64)
    for s in range(1 << N):
        size = popcount[s]
        t = s
        while True:
            u = s ^ t
            cost = (np.minimum(dp_X[t], dp_Y[u])).sum()
            ans[size] = min(ans[size], cost)
            if t == 0:
                break
            t = (t - 1) & s
    return ans

N = int(readline())
XYP = np.array(read().split(), np.int64)

ans = main(XYP)
print('\n'.join(map(str, ans.tolist())))
### BUGGY CODE ###

s = input()
q = int(input())
Q = [input() for _ in range(q)]

s = list(s)
insert = s.insert
append = s.append
flag = True

for query in Q:
    if len(query) == 1:
        flag = not flag
    else:
        query = query.split()
        if query[1] == '1':
            if flag:
                insert(0, query[2])
            else:
                append(query[2])
        else:
            if flag:
                append(query[2])
            else:
                insert(0, query[2])

if not flag:
    s.reverse()

print(*s, sep='')


### FIXED CODE ###

from collections import deque

s = input()
q = int(input())
Q = [input() for _ in range(q)]

s = deque(list(s))
insert = s.appendleft
append = s.append
flag = True

for query in Q:
    if query[0] == '1':
        flag = not flag
    else:
        if (query[2] == '1' and flag) or (query[2] == '2' and not flag):
            insert(query[4])
        else:
            append(query[4])

if not flag:
    s.reverse()

print(*s, sep='')
### BUGGY CODE ###

import sys
input=sys.stdin.readline
S=input().splitlines()[0]
Q = int(input())
flipcnt=0
for _ in range(Q):
    q = input().split()
    if len(q) == 1:
        flipcnt += 1
        continue
    else:
        if (int(q[1]) + flipcnt) % 2 == 1:
            #前
            S=q[2]+S
        else:
            S=S+q[2]
    #print(S)

if flipcnt % 2 == 1:
    S=S[::-1]

print(S)

### FIXED CODE ###

from collections import deque
import sys
input=sys.stdin.readline
S=input().splitlines()[0]
Q = int(input())
qs = [input().split() for _ in range(Q)]
flipcnt = 0
S =deque(S)
for q in qs:
    if len(q) == 1:
        flipcnt += 1
        continue
    else:
        if (int(q[1]) + flipcnt) % 2 == 1:
            #前
            S.appendleft(q[2])
        else:
            S.append(q[2])
    #print(S)

if flipcnt % 2 == 1:
    S.reverse()

print(''.join(S))
### BUGGY CODE ###

N,Q = map(int, input().split())
S = input()
List = []
for i in range(N-1):
  if S[i] == "A":
    if S[i+1] == "C":
      List.append(1)
    else:
      List.append(0)
  else:
    List.append(0)

for i in range(Q):
  l, r = map(int, input().split())
  A = List[l - 1 : r -1]
  print(A.count(1))

### FIXED CODE ###

N,Q = map(int, input().split())
S = input()
List = [0]
p = 0
for i in range(N-1):
  if S[i] == "A":
    if S[i+1] == "C":
      p = p + 1
      List.append(p)
    else:
      List.append(p)
  else:
    List.append(p)

List.append(0)   
for i in range(Q):
  l, r = map(int, input().split())
  if List[l-2] == List[l-1]:
    print(List[r-1] - List[l-2])
  else:
    print(List[r-1] - List[l-1])
### BUGGY CODE ###

import fractions
import math
a,b = map(int, input().split())
g = fractions.gcd(a,b)
ans = 1

for i in range(2, g):
  if g//i == 1:
    ans += 1
    break
  elif g%i == 0:
    ans += 1
    while True:
      g //= i
      if g%i != 0:
        break
print(ans)

### FIXED CODE ###

import fractions
import math
a,b = map(int, input().split())
g = fractions.gcd(a,b)
ans = 1

for i in range(2, int(math.sqrt(g))+1):
  if g%i == 0:
    ans += 1
    while True:
      g //= i
      if g%i != 0:
        break
if (g != 1):
  ans += 1
print(ans)