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

from collections import defaultdict
import heapq
n, m = map(int, input().split())
d = defaultdict(list)
for i in range(n):
    a, b = map(int, input().split())
    d[a-1].append(-b)
cnt = 0
a = []
for i in range(m):
    a += d[i]
    heapq.heapify(a)
    if a:
        cnt += -heapq.heappop(a)
print(cnt)

### FIXED CODE ###

from collections import defaultdict
import heapq
n, m = map(int, input().split())
d = defaultdict(list)
for i in range(n):
    a, b = map(int, input().split())
    d[a-1].append(-b)
cnt = 0
a = []
heapq.heapify(a)
for i in range(m):
    for j in d[i]:
        heapq.heappush(a, j)
    if a:
        cnt += -heapq.heappop(a)
print(cnt)
### BUGGY CODE ###

def gcd(a, b, c):
    minV = min([a, b, c])
    maxV = max([a, b, c])
    start = minV
    diff = maxV - minV
    if diff < start and diff != 0:
        start = diff
    for gcdV in range(start, 1, -1):
        if (a % gcdV == 0) and (b % gcdV == 0) and (c % gcdV == 0):
            return gcdV
    return 1


k = int(input())
sum = 0
for a in range(1, k + 1):
    for b in range(1, k + 1):
        for c in range(1, k + 1):
            sum += gcd(a, b, c)

print(sum)


### FIXED CODE ###

import unittest
from io import StringIO
import sys
import itertools
import math


def gcd(a, b, c):
    n = 1
    if a == b:
        if b != c:
            n = 3
    else:
        if b != c:
            n = 6
        else:
            n = 3
    return math.gcd(math.gcd(a, b), c) * n


def resolve():
    K = int(input())
    T = [i for i in range(1, K + 1)]
    Tr = itertools.combinations_with_replacement(T, 3)
    sumT = 0
    for a, b, c in Tr:
        sumT += gcd(a, b, c)
    print(sumT)


class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)

    def test_入力例_1(self):
        input = """2"""
        output = """9"""
        self.assertIO(input, output)

    def test_入力例_2(self):
        input = """200"""
        output = """10813692"""
        self.assertIO(input, output)

    def test_add(self):
        input = """195"""
        output = """9997134"""
        self.assertIO(input, output)


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

import math
N,Y=map(int,input().split())
a=[float(x) for x in input().split()]
for b in range(Y):
  a.sort(reverse=True)
  a[0]=float(a[0])/2
v=0
for c in range(N):
  v+=int(a[c])
print(v)

  


### FIXED CODE ###

import heapq

N,M=( int(x) for x in input().split())
A=[int(s)*-1 for s in input().split()]

heapq.heapify(A)

for i in range(M):
    A_max=heapq.heappop(A)*-1
    heapq.heappush(A,(A_max//2)*-1)    
print(sum(A)*-1)
### BUGGY CODE ###

import bisect

N, M, Q = map(int, input().split())
trains = [list(map(int, input().split())) for i in range(M)]
queries = [list(map(int, input().split())) for i in range(Q)]
trains.sort(key = lambda x: x[1])
L = [train[0] for train in trains]
R = [train[1] for train in trains]

dp = [[0] * N for i in range(N)]
for i in range(N):
    for j in range(i, N):
        right = bisect.bisect_right(R, j + 1)
        A = sorted(L[:right])
        left = bisect.bisect_left(A, i + 1)
        dp[i][j] = right - left
for q in range(Q):
    pi, qi = queries[q]
    print(dp[pi - 1][qi - 1])


### FIXED CODE ###

N, M, Q = map(int, input().split())
trains = [list(map(int, input().split())) for i in range(M)]
queries = [list(map(int, input().split())) for i in range(Q)]

A  =[[0] * N for _ in range(N)] #A[i][j] = (i + 1) -> (j+1)なる列車の本数
for train in trains:
    li, ri = train
    A[li - 1][ri - 1] += 1

dp = [[0] * N for __ in range(N)]
for i in range(N - 1, -1, -1):
    for j in range(i, N):
        if i == j:
            dp[i][j] = A[i][j]
        else:
            dp[i][j] = dp[i][j - 1] + dp[i + 1][j] + A[i][j] - dp[i + 1][j - 1]
for q in range(Q):
    pi, qi = queries[q]
    print(dp[pi - 1][ qi - 1])
### BUGGY CODE ###

a,b,c,d = map(int,input().split())

while True:

    cd = c - b
    if cd <= 0:
        print('Yes')
        break
    
    ad = a - d 
    if ad <= 0:
        print('No')
        break


### FIXED CODE ###

import math
a,b,c,d = map(int,input().split())

cb = -(-c//b)
ad = -(-a//d)
if ad < cb :
    print('No')
else:
    print('Yes')
### BUGGY CODE ###

def abc179c():
    def divisor(n):
        """ nの約数列挙 """
        cnt = 0
        for i in range(1, int(n ** 0.5) + 1):
            if n % i == 0:
                cnt += 1
                if i ** 2 == n:
                    continue
                cnt+=1
        return cnt  # sortされていない
    n = int(input())
    cnt = 0
    for i in range(1, n):
        cnt += divisor(i)
    print(cnt)
abc179c()

### FIXED CODE ###

def abc179c():

    n = int(input())
    cnt = 0
    for i in range(1, n):
        cnt += (n-1)//i
    print(cnt)
abc179c()
### BUGGY CODE ###

if __name__ == "__main__":
    A, B, C = map(int, input().split())
    
    max_v = max(A, B, C)
    min_v = min(A, B, C)
    
    num_list = [A, B, C]
    num_list.remove(max_v)
    if len(num_list) == 2:
        num_list.remove(min_v)
        if len(num_list) == 1:
            mid_v = num_list[0]
        else:
            mid_v = min_v
    else:
        mid_v = max_v
    
    ans = 0
    while True:
        if mid_v < max_v:
            ans += max_v - mid_v
            min_v += max_v - mid_v
            mid_v = max_v
            #print("aaa", min_v, mid_v, max_v)
        else:#mid_v = max_v
            if min_v < max_v:
                if (max_v - min_v) % 2 == 0:
                    #min_v = max_v
                    ans += (max_v - min_v) / 2
                    #print("bbb", min_v, mid_v, max_v)
                    break
                else:
                    #min_v = max_v
                    #max_v += 1
                    #mid_v += 1
                    ans += (max_v + 1 - min_v) / 2
                    ans += 1
                    #print("ccc", min_v, mid_v, max_v)
                    break
    
    print(int(ans))

### FIXED CODE ###

if __name__ == "__main__":
    A, B, C = map(int, input().split())
    
    max_v = max(A, B, C)
    min_v = min(A, B, C)
    
    num_list = [A, B, C]
    num_list.remove(max_v)
    if len(num_list) == 2:
        num_list.remove(min_v)
        if len(num_list) == 1:
            mid_v = num_list[0]
        else:
            mid_v = min_v
    else:
        mid_v = max_v
    
    ans = 0
    while True:
        if mid_v < max_v:
            ans += max_v - mid_v
            min_v += max_v - mid_v
            mid_v = max_v
            #print("aaa", min_v, mid_v, max_v)
        else:#mid_v = max_v
            if min_v < max_v:
                if (max_v - min_v) % 2 == 0:
                    #min_v = max_v
                    ans += (max_v - min_v) / 2
                    #print("bbb", min_v, mid_v, max_v)
                    break
                else:
                    #min_v = max_v
                    #max_v += 1
                    #mid_v += 1
                    ans += (max_v + 1 - min_v) / 2
                    ans += 1
                    #print("ccc", min_v, mid_v, max_v)
                    break
            else:
                break
    
    print(int(ans))
### BUGGY CODE ###

from heapq import heapify, heappop, heappush
INF = 1e10

H,W=map(int, input().split())
ch, cw = map(int, input().split())
dh, dw = map(int, input().split())

S = [input() for _ in range(H)]

D = [[INF]*(W) for _ in range(H)] #始点からの距離(重み)
def dijkstra(sx, sy):
    # Color = [[0]*(W) for _ in range(H)] # 0: 未訪問 1: Seen 2: Visited
    # P = [None]*N #親

    D[sx][sy] = 0
    # P[s] = None
    # PQ = PriorityQueue([(0, sx, sy)]) #(Cost, Node)を格納し、PQにする。
    PQ = [(0, sx, sy)]
    heapify(PQ)
    while PQ: # PQに候補がある限り
        min_cost, ux, uy = heappop(PQ) # 最小コストなノードu
        for dx in range(-2, 3):
            for dy in range(-2, 3):
                xx, yy = ux+dx, uy+dy
                if 0 <= xx < H and 0 <= yy < W and S[xx][yy]==".":
                    is_not_neighbor = int(abs(dx) + abs(dy) != 1)
                    # neighborでなければコストが1増える
                    if D[ux][uy] + is_not_neighbor < D[xx][yy]:
                        D[xx][yy] = D[ux][uy] + is_not_neighbor
                        heappush(PQ, (D[xx][yy], xx, yy))
    

dijkstra(ch-1, cw-1)
if D[dh-1][dw-1] >= INF:
    print(-1)
else:
    print(D[dh-1][dw-1])

### FIXED CODE ###

import heapq
INF = 1e7
H,W=map(int, input().split())
sx, sy = map(int, input().split())
dh, dw = map(int, input().split())
sx -= 1
sy -= 1
S = [input() for _ in range(H)]
D = [[INF]*(W) for _ in range(H)] #始点からの距離(重み)
D[sx][sy] = 0
PQ = [(0, (sx, sy))]
heapq.heapify(PQ)
while PQ: # PQに候補がある限り
    _, (ux, uy) = heapq.heappop(PQ) # 最小コストなノードu
    for dx in range(-2, 3):
        for dy in range(-2, 3):
            xx, yy = ux+dx, uy+dy
            if 0 <= xx < H and 0 <= yy < W and S[xx][yy]==".":
                is_not_neighbor = int(abs(dx) + abs(dy) != 1)
                # neighborでなければコストが1増える
                if D[ux][uy] + is_not_neighbor < D[xx][yy]:
                    D[xx][yy] = D[ux][uy] + is_not_neighbor
                    heapq.heappush(PQ, (D[xx][yy], (xx, yy)))
if D[dh-1][dw-1] >= INF:
    print(-1)
else:
    print(D[dh-1][dw-1])
### BUGGY CODE ###

from collections import deque


def main():
    H, W = map(int, input().split())
    A = [input() for _ in range(H)]
    visited = [[False] * W for _ in range(H)]
    q = deque()
    for i in range(H):
        for j in range(W):
            if A[i][j] == "#":
                q.append((i, j, 0))
    ans = 0
    directions = [(1, 0), (0, 1), (-1, 0), (0, -1)]
    while len(q):
        i, j, cost = q.popleft()
        if visited[i][j]:
            continue
        visited[i][j] = True
        ans = max(ans, cost)
        for d in directions:
            ni = i + d[0]
            nj = j + d[1]
            ncost = cost + 1
            if 0 <= ni < H and 0 <= nj < W and not visited[ni][nj]:
                q.append((ni, nj, ncost))
    print(ans)


if __name__ == "__main__":
    main()


### FIXED CODE ###

from collections import deque


def main():
    H, W = map(int, input().split())
    A = [input() for _ in range(H)]
    q = deque()
    visited = [[False] * W for _ in range(H)]
    for i in range(H):
        for j in range(W):
            if A[i][j] == "#":
                q.append((i, j, 0))
                visited[i][j] = True
    ans = 0
    directions = [(1, 0), (0, 1), (-1, 0), (0, -1)]
    while len(q):
        i, j, cost = q.popleft()
        ans = max(ans, cost)
        for d in directions:
            ni = i + d[0]
            nj = j + d[1]
            if 0 <= ni < H and 0 <= nj < W and not visited[ni][nj]:
                q.append((ni, nj, cost+1))
                visited[ni][nj] = True
    print(ans)


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

n=int(input())
num=n
if n==2:
  prime=[2]
elif n==3:
  prime=[2,3]
else:
  prime=[]
  for _ in range(40):
    for i in range(2,n+1):
      if n%i==0:
        prime.append(i)
        n=n//i
        break
    else:
      break
if len(prime)==0:
  prime=[num]
print('{}: {}'.format(num,' '.join(map(str,prime))))


### FIXED CODE ###

def prime(num):
    if num==1:
        return False
    elif num==2 or num==3:
        return True
    else:
        for i in range(2,int(num**0.5)+1):
            if num%i==0:
                return False
        else:
            return True

n=int(input())
tmp=n
plist=[]
if prime(n):
    print('{}: {}'.format(n,n))
else:
    while 1:
        for i in range(2,tmp+1):
            if tmp%i==0:
                plist.append(i)
                tmp=tmp//i
                break
        else:
            break
    print('{}: {}'.format(n,' '.join(map(str,plist))))
### BUGGY CODE ###

scnum = int(input())
score = []
answer = 0
for i in range(scnum):
    word = input()
    if word not in score:
        score.append(word)
        answer += 1

print(answer)

### FIXED CODE ###

scnum = int(input())
word = [0]*scnum
for i in range(scnum):
    word[i] = input()
word.sort()
answer = 1

for j in range(scnum-1):
    if word[j] != word[j+1]:
        answer += 1
print(answer)
### BUGGY CODE ###

n=int(input())
A=list(map(int,input().split()))
A.sort()
m,ans=max(A)+1,0
li=[0 for _ in range(m)]
li[0]=1

for a in A:
  if not li[a]:
    if A.count(a) == 1:
      ans += 1
    for i in range(a,m,a):
      li[i] = 1

print(ans)

### FIXED CODE ###

n=int(input())
A=list(map(int,input().split()))+[1000001]
A.sort()
m,ans=max(A)+1,0
li=[0 for _ in range(m)]
li[0]=1

for i in range(n):
  a=A[i]
  if not li[a]:
    if A[i+1] != a:
      ans += 1
    for i in range(a,m,a):
      li[i] = 1

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

N = int(input())
A = []
for i in range(N):
  A.append(int(input()))

ans = 0
for i in set(A):
  if A.count(i) % 2 != 0:
    ans += 1

print(ans)

### FIXED CODE ###

import collections
N = int(input())
A = [int(input()) for _ in range(N)]
count = collections.Counter(A)

l = []
for i in list(count):
  if count[i] % 2 != 0:
    l.append(count[i])

print(len(l))
### BUGGY CODE ###

s=' '+input()
t=' '+input()
dp=[['']*len(t)for _ in range(len(s))]
for i in range(1,len(s)):
    for j in range(1,len(t)):
        if s[i]==t[j]:
            dp[i][j]=dp[i-1][j-1]+s[i]
        elif len(dp[i-1][j])>len(dp[i][j-1]):
            dp[i][j]=dp[i-1][j]
        else:
            dp[i][j]=dp[i][j-1]
print(dp[-1][-1])

### FIXED CODE ###

s=' '+input()
t=' '+input()
dp=[[0]*len(t)for _ in range(len(s))]
for i in range(1,len(s)):
    for j in range(1,len(t)):
        if s[i]==t[j]:
            dp[i][j]=dp[i-1][j-1]+1
        else:
            dp[i][j]=max(dp[i-1][j],dp[i][j-1])
ans=[]
i,j=len(s)-1,len(t)-1
while dp[i][j]:
    if dp[i][j]==dp[i-1][j]:
        i-=1
    elif dp[i][j]==dp[i][j-1]:
        j-=1
    else:
        ans.append(s[i])
        i-=1
        j-=1
print(''.join(ans[::-1]))
### BUGGY CODE ###

N, K = map(int, input().split())
As = list(map(int, input().split()))
for i in range(K):
  if min(As) == N:
    break
  dBs = [0]*(N+1)
  for i in range(N):
    A = As[i]
    dBs[max(0, i-A)] += 1
    dBs[min(N, i+A+1)] -= 1
  #print(dBs)
  Bs = [dBs[0]]
  for i in range(1, N):
    B = Bs[i-1]+dBs[i]
    Bs.append(B)
  As = Bs
print(" ".join(map(str, As)))


### FIXED CODE ###

N, K = map(int, input().split())
As = list(map(int, input().split()))
for i in range(K):
  if min(As) == N:
    break
  dBs = [0]*(N+1)
  for i in range(N):
    A = As[i]
    dBs[max(0, i-A)] += 1
    dBs[min(N, i+A+1)] -= 1
  #print(dBs)
  Bs = [dBs[0]]
  for i in range(1, N):
    B = Bs[i-1]+dBs[i]
    Bs.append(B)
  As = Bs
print(" ".join(map(str, As)))
### BUGGY CODE ###

def poll(arr):
    ans_h = {}
    for ele in arr:
        if ele in ans_h.keys():
            ans_h[ele] += 1
        else:
            ans_h[ele] = 0
    max_kv_list = sorted([kv for kv in ans_h.items() if kv[1] == max(ans_h.values())])
    for ele in max_kv_list:
        print(ele[0])

if __name__ == "__main__":
    n = int(input())
    arr = [input() for _ in range(0, n)]
    poll(arr)

### FIXED CODE ###

def poll(arr):
    ans_h = {}
    for ele in arr:
        if ele in ans_h.keys():
            ans_h[ele] += 1
        else:
            ans_h[ele] = 0
    max_v = max(ans_h.values())
    mkv = [kv for kv in ans_h.items() if kv[1] == max_v]
    for ele in sorted(mkv):
        print(ele[0])

if __name__ == "__main__":
    n = int(input())
    arr = [input() for _ in range(0, n)]
    poll(arr)
### BUGGY CODE ###

N = int(input())
a = list(map(str,input().split()))
a_set = list(set(a))
cnt = 0
for i in a_set:
    if int(a.count(str(i))) >= int(i):
        
        cnt +=  (int(a.count(str(i))) - int(i))
    elif  int(a.count(str(i))) < int(i):
        cnt +=  int(a.count(str(i)))
print(cnt)


### FIXED CODE ###

from collections import Counter
N = int(input())
a = list(map(str,input().split()))
a_set = list(set(a))
cnt = 0
c = Counter(a)
for i in a_set:
    if c[i] >= int(i):
        
        cnt +=  (c[i] - int(i))
    elif  c[i] < int(i):
        cnt +=  c[i]
print(cnt)
### BUGGY CODE ###

#E
n,W = list(map(int,input().split()))
w = [0]*(n+1)
v = [0]*(n+1)
for i in range(1,n+1):
    w[i],v[i]=list(map(int,input().split()))
V = n*max(v)

dp = [[float('inf') for i in range(V+1)] for j in range(n+1)]
#i番目(1:n)の品物までを使って価値の総和がjになるようなときの重さの最小値
dp[0][0] = 0
for i in range(1,n+1):
    for j in range(V+1): #価値
        if j-v[i]>=0:
            dp[i][j] = min(dp[i-1][j],dp[i-1][j-v[i]]+w[i])
        else:
            dp[i][j] = dp[i-1][j]
# for i in range(n+1):
#     print(dp[i])
print(max([j for j in range(V+1) if dp[n][j]<=W]))

### FIXED CODE ###

#E
n,W = list(map(int,input().split()))
w = [0]*(n+1)
v = [0]*(n+1)
for i in range(1,n+1):
    w[i],v[i]=list(map(int,input().split()))
V = n*max(v)

dp = [[float('inf') for i in range(V+1)] for j in range(n+1)]
#i番目(1:n)の品物までを使って価値の総和がjになるようなときの重さの最小値
dp[0][0] = 0
for i in range(1,n+1):
    for j in range(V+1): #価値
        if j-v[i]>=0:
            dp[i][j] = min(dp[i-1][j],dp[i-1][j-v[i]]+w[i])
        else:
            dp[i][j] = dp[i-1][j]
# for i in range(n+1):
#     print(dp[i])
print(max([j for j in range(V+1) if dp[n][j]<=W]))
### BUGGY CODE ###

N,M=map(int,input().split())
A=list(map(int,input().split()))
A=sorted(A)
BC=[[0,0] for i in range(M)]
for i in range(M):
    BC[i][0],BC[i][1]=map(int,input().split())
BC=list(sorted(BC,reverse=True))

for i in range(M):
    for j in range(BC[i][0]):
        if(BC[i][1]>=A[j]):
            A[j]=BC[i][1]
        else:
            break
    A=sorted(A)

print(sum(A))

### FIXED CODE ###

N,M=map(int,input().split())
A=list(map(int,input().split()))
BC=[[0,0] for i in range(M)]
for i in range(M):
    BC[i][0],BC[i][1]=map(int,input().split())

A=sorted(A)
BC=list(sorted(BC,reverse=True,key=lambda x: x[1]))

i=0
for B,C in BC:
    for j in range(i,min(N,i + B)):
        if A[j] < C:
            A[j] = C
            #B枚分先を飛ばす BCはCに関して降順のため問題ない
    i = i + B
 
print(sum(A))
### BUGGY CODE ###

n, k = map(int,input().split())
l = list(map(int,input().split()))
#print(l)

x =0
y = 0
for i in range(n-k+1):
    if x < max(sum(l[i:i+k]),x):
        x = sum(l[i:i+k])
        y = i
#print(x,y)

z = 0
for j in range(y,y+k):
    z += (l[j]+1)/2

print(z)





### FIXED CODE ###

from itertools import accumulate

n, k = map(int,input().split())
l = list(map(int,input().split()))
#print(l)

p = [0] + list(accumulate(l))

#print(p)

q = []
for i in range(n-k+1):
    q.append((p[i+k] - p[i] + k)/2)

print(max(q))
### BUGGY CODE ###

L, R = map(int, input().split())
min_mod = 2019
for i in range(L,R):
    for j in range(i+1,R+1):
        mod  = (i*j)%2019
        if min_mod > mod:
            min_mod=mod
print(min_mod)

### FIXED CODE ###

L, R = map(int, input().split())
min_mod = 2019
flg=[0]*2019
flg2=[0]*2019
for i in range(L,R):
    idx=i%2019
    if flg[idx]==1:
        break
    if flg[idx]==0:
        for j in range(i+1,R+1):
            mod  = (i*j)%2019
            if flg2[mod]==1:
                break
            flg2[mod]=1
            if min_mod > mod:
                min_mod=mod
        flg[idx]=1
print(min_mod)
### BUGGY CODE ###

from collections import deque
import sys

input = sys.stdin.readline

n, m, max_tank = map(int, input().split())

g = tuple(set() for _ in range(n))
for _ in range(m):
    a, b, c = map(int, input().split())
    if c > max_tank:
        continue
    # 燃料不足で通過できない

    a -= 1
    b -= 1
    g[a].add((b, c))
    g[b].add((a, c))
    # 隣接リスト、(行き先、コスト)

inf = n + 10

memo = [None] * n

q = int(input())

for _ in range(q):
    s, t = map(int, input().split())
    s -= 1
    t -= 1

    if not g[t]:
        print(-1)
        continue
    # ゴールに接続する辺がない場合

    d = [inf] * n
    remains = [0] * n

    d[s] = 0
    remains[s] = max_tank

    if memo[s] is not None:
        if memo[s][t] >= inf:
            print(-1)
        else:
            print(memo[s][t])

    else:
        dq = deque()
        dq.append((s, max_tank, 0, -1))

        ans = inf
        while dq:
            v, tank, take, parent = dq.popleft()
            if (d[v] < take) or (d[v] == take and remains[v] > tank):
                continue

            for u, c in g[v]:
                if u == parent:
                    continue
                if c > tank:
                    if (d[u] > take + 1) or (d[u] == take + 1 and remains[u] < max_tank - c):
                        d[u] = take + 1
                        remains[u] = max_tank - c
                        dq.append((u, max_tank - c, take + 1, v))
                else:
                    if (d[u] > take) or (d[u] == take and remains[u] < tank - c):
                        d[u] = take
                        remains[u] = tank - c
                        dq.appendleft((u, tank - c, take, v))

        memo[s] = d

        if d[t] >= inf:
            print(-1)
        else:
            print(d[t])


### FIXED CODE ###

import sys

input = sys.stdin.readline

inf = 300 * (10 ** 9) + 10

n, m, max_tank = map(int, input().split())

dist = [[inf] * n for _ in range(n)]
for i in range(n):
    dist[i][i] = 0

for _ in range(m):
    a, b, c = map(int, input().split())
    if c > max_tank:
        continue
    # 燃料不足で通過できない

    a -= 1
    b -= 1

    dist[a][b] = c
    dist[b][a] = c

for k in range(n):
    for i in range(n):
        for j in range(n):
            dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j])

g = [[inf] * n for _ in range(n)]
for i in range(n):
    for j in range(n):
        if dist[i][j] <= max_tank:
            g[i][j] = 0

for i in range(n):
    g[i][i] = 0

for k in range(n):
    for i in range(n):
        for j in range(n):
            g[i][j] = min(g[i][j], g[i][k] + g[k][j] + 1)

q = int(input())
for _ in range(q):
    s, t = map(int, input().split())
    s -= 1
    t -= 1
    print(-1 if g[s][t] == inf else g[s][t])
### BUGGY CODE ###

n=int(input())
tmp = 1
dat = input().split(" ")
for d in dat:
    tmp *= int(d)

if tmp > 1000000000000000000:
    print ("-1")
else:
    print (tmp)

### FIXED CODE ###

n=int(input())
tmp = 1
dat = list(map(int, input().split(" ")))
#print(dat, (0 in dat))
over = False
if 0 in dat:
    print ("0")
else:
    for d in dat:
        tmp *= d
        if tmp > 1000000000000000000:
            print ("-1")
            over = True
            break
    if not over:
        print (tmp)
### BUGGY CODE ###

import sys
input=sys.stdin.readline
n=int(input())
L=list(int(input()) for i in range(n))
for i in range(n):
    N=L[:i]+L[i+1:]
    print(max(N))

### FIXED CODE ###

import sys
input=sys.stdin.buffer.readline
n=int(input())
L=list(int(input()) for i in range(n))
N=sorted(L)
for i in range(n):
    print(N[-1] if L[i]!=N[-1] else N[-2])
### BUGGY CODE ###

import sys,itertools
for line in sys.stdin.readlines():
    n,s=map(int,line.strip().split())
    count=0
    for c in itertools.permutations(xrange(10),n):
        total=0
        for i in xrange(1,n+1):
            if total>s:break
            total+=i*c[i-1]
        if total==s:
            count+=1
    print count

### FIXED CODE ###

import sys
dp=[[[0]*331 for i in xrange((1<<10)+1)] for j in xrange(12)]
#dp[12][1025][331]
dp[0][0][0]=1
for i in xrange(10):
    for j in xrange(1<<10):
        for c in xrange(331):
            if dp[i][j][c]==0:
                continue
            for k in xrange(10):
                if (j>>k&1)==0:
                    dp[i+1][j|(1<<k)][(i+1)*k+c]+=dp[i][j][c]
ans=[[0]*331 for unused in xrange(12)]
for i in xrange(11):
    for j in xrange(1<<10):
        for c in xrange(331):
            ans[i][c]+=dp[i][j][c]
for line in sys.stdin.readlines():
    n,s=map(int,line.strip().split())
    if s>330:
        print 0
    else:
        print ans[n][s]