Harryxun/stf_run huggingface dataset:
import math
def digit(X):
    d = 0
    while X:
        X //= 10
        d += 1
    return d

def F(A, B):
    return max(digit(A), digit(B))

N = int(input())

min_F = 20
max_div = round(math.sqrt(N))
for i in range(1, max_div):
    if N % i == 0:
        f = F(i, N/i)
        if f < min_F:
            min_F = f
print(min_F)



### FIXED CODE ###

A, B = map(int, input().split())
print((A + B) % 24)
n,r = map(int,input())

print(100 * (10 - n) + r)


### FIXED CODE ###

n,r = map(int,input().split())

if n < 10:
    print(100 * (10 - n) + r)
else:
    print(r)
n,x=map(int,input().split())
*l,=map(int,input().split())
cnt=1
d=0
while d <= x:
	d=d+l[cnt-1]
	cnt += 1
print(cnt-1)

### FIXED CODE ###

n,x=map(int,input().split())
*l,=map(int,input().split())
t=[0]
for i in range(n):
    d=l[i]+t[-1]
    t.append(d)
ans=[j for j in t if j <= x]
print(len(ans))
mod = 1000000007

def mul(x, y):
    return x * y % mod

def f(n, arr):
    answer = 1
    count = [0 for _ in range(n)]
    count[0] = 3
    for e in range(n):
        answer = mul(answer, count[arr[e] - 1] - count[arr[e]])
        count[arr[e]] = count[arr[e]] + 1
        # print("answer ", answer)
    return answer

if __name__ == "__main__":
    n = int(input())
    arr = list(map(int, input().split(' ')))
    for i in range(n):
        arr[i] = arr[i] + 1 
    print(f(n, arr))

### FIXED CODE ###

mod = 1000000007

def mul(x, y):
    return x * y % mod

def f(n, arr):
    answer = 1
    count = [0 for _ in range(n + 1)]
    count[0] = 3
    for e in range(n):
        answer = mul(answer, count[arr[e] - 1] - count[arr[e]])
        count[arr[e]] = count[arr[e]] + 1
        # print("answer ", answer)
    return answer

if __name__ == "__main__":
    n = int(input())
    arr = list(map(int, input().split(' ')))
    for i in range(n):
        arr[i] = arr[i] + 1 
    print(f(n, arr))
#!/Library/Frameworks/Python.framework/Versions/3.5/bin/python3

n = int(input())
vh = {}
zx = []
zy = []
zh = []
for j in range(101):
    for k in range(101):
        vh[j, k] = -2
for i in range(n):
    x, y, h = list(map(int, input().split()))
    if h == 0:
        zx.append(x)
        zy.append(y)
        zh.append(h)
        continue
    for j in range(101):
        for k in range(101):
            hi = h + abs(j - x) + abs(k - y)
            if vh[j, k] == -2:
                vh[j, k] = hi
            elif vh[j, k] > -1:
                if vh[j, k] != hi:
                    vh[j, k] = -1

rs = 0
for j in range(101):
    for k in range(101):
        if vh[j, k] > -1:
            rs += 1
            rj = j
            rk = k

if rs == 1:
    print(rj, rk, vh[rj, rk])
else:
    for i in range(rs):
        dels = 0
        for j in range(101):
            for k in range(101):
                hi = zh + abs(j - zx) + abs(k - zy)
                if vh[j, k] > -1:
                    if vh[j, k] != hi:
                        dels += 1
        if dels == rs - 1:
            for j in range(101):
                for k in range(101):
                    hi = zh + abs(j - zx) + abs(k - zy)
                    if vh[j, k] > -1:
                        if vh[j, k] != hi:
                            vh[j, k] = -1
            for j in range(101):
                for k in range(101):
                    if vh[j, k] > -1:
                        print(j, k, vh[j, k])
                     


### FIXED CODE ###

#!/Library/Frameworks/Python.framework/Versions/3.5/bin/python3
from collections import defaultdict

n = input()
if n == '1':
    print('Hello World')
else:
    a = int(input())
    b = int(input())
    print(a + b)
using System;
using static System.Console;
using System.Linq;
using System.Collections.Generic;
class Program
{
    static void Main(string[] args)
    {
      int n = int.Parse(ReadLine());
      List<string> s = new List<string>();
      
      for (int i=0;i<n;i++)
      {
        s.Add(ReadLine());
      }
      var hashSet = new HashSet<string>(s);
      s = hashSet.ToList();
      List<int> ans = new List<int>();
      
      for (int i=0;i<5;i++)
      {
        ans.Add(0);
      }
      
      for (int i=0;i<s.Count;i++)
      {
        if (s[i].Substring(0,1)=="M")
        {
          ans[0]+=1;
        }
        else if (s[i].Substring(0,1)=="A")
        {
          ans[1]+=1;
        }
        else if (s[i].Substring(0,1)=="R")
        {
          ans[2]+=1;
        }
        else if (s[i].Substring(0,1)=="C")
        {
          ans[3]+=1;
        }
        else if (s[i].Substring(0,1)=="H")
        {
          ans[4]+=1;
        }
      }
      int answ=0;
      for (int i=0;i<5;i++)
      {
        for (int j=i+1;j<5;j++)
        {
          for (int k=j+1;k<5;k++)
          {
            if (i!=j && j!=k && i!=k)
            {
              answ+=ans[i]*ans[j]*ans[k];
            }
          }
        }
      }
      WriteLine(answ);
    }
}

### FIXED CODE ###

n=int(input())
march=[0,0,0,0,0]
for i in range(n):
  s=input()
  if s[0]=="M":
    march[0]+=1
  elif s[0]=="A":
    march[1]+=1
  elif s[0]=="R":
    march[2]+=1
  elif s[0]=="C":
    march[3]+=1
  elif s[0]=="H":
    march[4]+=1
finalans=0
for i in range(2**5):
  ans=1
  count=0
  for j in range(5):
    if ((i>>j)&1):
      ans*=march[j]
      count+=1
  if count!=3:
    ans=0
  finalans+=ans
print(finalans)
list(n,x,y) = input().split(" ")
print(min(x,y),x+y-n)

### FIXED CODE ###

n,x,y = map(int,input().split())
r = x+y-n
if r < 0:
  r = 0
print(min(x,y),r)
x,n=input().split()
x=int(x)
n=int(n)
lst = [ ]
lst=input()
lst=lst.split()
for i in range(0,n):
    lst[i]=int(lst[i])
minv=min(lst)
maxv=max(lst)
dis=100000
for i in range(minv-2,maxv+3):
    if(i not in lst and abs(i-x)<dis):
        dis=abs(i-x)
        clv=i
        
print(clv)
    


### FIXED CODE ###

x,n=input().split()
x=int(x)
n=int(n)
lst=input().split()
for i in range(0,n):
    lst[i]=int(lst[i])
if n==0:
    print(x)
else:
    minv=min(lst)
    maxv=max(lst)
    dis=100000

    for i in range(minv-2,maxv+3):
        if(i not in lst and abs(i-x)<dis):
            dis=abs(i-x)
            clv=i
            
    print(clv)
cin = open(0).read().strip().split('\n')
n, q = map(int, cin[0].split(' '))
ab = [tuple(map(int, a.split(' '))) for a in cin[1:n]]
px = [tuple(map(int, a.split(' '))) for a in cin[n:n+q]]

def dfs(g, idx, s):
    global score

    score[idx] += s
    for i in g[idx]:
        dfs(g, i, s)

g = [[] for _ in range(n)]
for abi in ab:
    g[abi[0]-1].append(abi[1]-1)

for idx in range(n):
    g[idx] = sorted(g[idx])

score = [0]*n
for pxi in px:
    dfs(g, pxi[0]-1, pxi[1])

print(' '.join(map(str, score)))

### FIXED CODE ###

cin = open(0).read().strip().split('\n')
n, q = map(int, cin[0].split(' '))
ab = [tuple(map(int, a.split(' '))) for a in cin[1:n]]
px = [tuple(map(int, a.split(' '))) for a in cin[n:n+q]]

import sys
sys.setrecursionlimit(10**9)

def dfs(g, seen, idx):
    global score

    seen[idx] = True
    for i in g[idx]:
        if seen[i]: continue
        score[i] += score[idx]
        dfs(g, seen, i)

g = [[] for _ in range(n)]
for abi in ab:
    g[abi[0]-1].append(abi[1]-1)
    g[abi[1]-1].append(abi[0]-1)

score = [0]*n
for pxi in px:
    score[pxi[0]-1] += pxi[1]

seen = [False]*n
dfs(g, seen, 0)

print(' '.join(map(str, score)))
#ブログの模範解答（参考のため提出）
#https://marco-note.net/abc-175-work-log/

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

ans = -float('inf')
for s in range(N):
    ### Step1
    S = []  # 累積和S. ただし, 初項は0ではなく1回目の移動後の得点とする.
    # 1回目の移動
    i = P[s] - 1
    S.append(C[i])
    # 2回目以降の移動. スタート地点に戻ってくるまで繰り返し.
    while i != s:
        i = P[i] - 1
        S.append(S[-1] + C[i])

    ### Step2: KとSの長に応じて場合分けして, 得点の最大値を求める.
    # 1周未満しか移動できない場合:
    if K <= len(S):
        score = max(S[:K])
    # 1周以上回ることができるが, ループを1周したときに得点が減る場合:
    elif S[-1] <= 0:
        score = max(S)
    # 1週以上回ることができ, かつループを1週するごとに得点が増える場合:
    else:
        # ループを (K // len(S) - 1)回 廻る場合:
        score1 = S[-1] * (K // len(S) - 1)
        score1 += max(S)
        # ループを (K // len(S))回 廻る場合:
        score2 = S[-1] * (K // len(S))
        r = K % len(S)
        if r != 0:
            score2 += max(0, max(S[:r]))
        # score1 と score2 の大きい方がこの場合の得点の最大値
        score = max(score1, score2)

    ans = max(ans, score)

print(ans)

### FIXED CODE ###

R,C,K = map(int,input().split())

item = [[0] * (C + 1) for _ in range(R + 1)]
for i in range(K):
    r,c,v = map(int,input().split())
    item[r][c] = v

dp = [[[0]*(C+1) for _ in range(R+1)] for _ in range(4)]

for h in range(R+1):
    for w in range(C+1):
        for k in range(4):
            position = dp[k][h][w]
            if h+1 <= R:
                # 移動先のアイテムを取らない場合
                dp[0][h+1][w] = max(dp[0][h+1][w], position)
                 # 移動先のアイテムを取る場合
                dp[1][h+1][w] = max(dp[1][h+1][w], position+item[h+1][w])
            if w+1 <= C:
                # 移動先のアイテムを取らない場合
                dp[k][h][w+1] = max(dp[k][h][w+1], position)
                # 現在のkが3未満のときのみ, 移動先のアイテムを取ることが可能
                if k < 3:
                    dp[k+1][h][w+1] = max(dp[k+1][h][w+1], position+item[h][w+1])

ans = 0
for k in range(4):
    ans = max(ans, dp[k][-1][-1])

print(ans)
n, m = map(int, input().split())
A = list(map(int, input().split()))
A.sort(reverse=True)
flg = True
import numpy as np
num = np.array(A)
while flg:
  if all([a>0 for a in num]):
    flg = all([0==a%2 for a in num])
    num = num//2
  else:
    break
A = np.array(A)//2
A = A.tolist()
def gcd(a, b):
  if b == 0:
    return a
  else:
    return gcd(b, a%b)

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

def gcd_many(l):
  if len(l) == 2:
    return gcd(l[0],l[1])
  else:
    return gcd_many(l[2:]+[gcd(l[0],l[1])])

def lcm_many(l):
  if len(l) == 1:
    return l[0]
  elif len(l) == 2:
    return lcm(l[0],l[1])
  elif l[0] > m:
    return 0
  else:
    return lcm_many([lcm(l[0],l[1])] + l[2:])
if flg:
  print(0)
else:
  lc = lcm_many(A)
  ans = (m // lc) // 2 if lc < m else 0
  if lc % 2 != 0:
    ans += 1
  print(ans)

### FIXED CODE ###

import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
 
from fractions import gcd
from functools import reduce
 
N,M,*A = map(int,read().split())
 
# 「奇数倍」に帰着
A = [x >> 1 for x in A]
 
def merge(a,b):
    g = gcd(a,b)
    a //= g; b //= g
    if a % 2 == 0:
        return 0
    if b % 2 == 0:
        return 0
    n = a * b * g
    if n > 10 ** 9:
        return 0
    return n
 
x = reduce(merge, A)
if x == 0:
    answer = 0
else:
    answer = (M//x) - (M//(x+x))
 
print(answer)
h, w = map(int, input().split())
l = max(h, w)
s = min(h, w)
if h % 3 == 0 or w % 3 == 0:
	print(0)
else:
	if abs((l // 3) - l / 3) <= abs((l // 3 + 1) - l / 3):
		block1 = s * (l // 3)
		block3 = (l - (l // 3)) * ((s + 1) // 2)
		block2 = H * W - block1 - block3
		print(max(block1, block2, block3) - min(block1, block2, block3))
	else:
		block1 = s * (l // 3 + 1)
		block3 = (l - 1 - (l // 3)) * (s // 2)
		block2 = H * W - block1 - block3
		print(max(block1, block2, block3) - min(block1, block2, block3))

### FIXED CODE ###

H, W = map(int, input().split())

def check(h, w):
	if h % 3 == 0 or w % 3 == 0:
		return 0

	else:
		block1 = w * (h // 3)
		block2 = (h - (h // 3)) * (w // 2)
		block3 = h * w - block1 - block2
		gap1 = max(block1, block2, block3) - min(block1, block2, block3)

		block4 = w * (h // 3 + 1)
		block5 = (h - 1 - (h // 3)) * (w // 2)
		block6 = h * w - block4 - block5
		gap2 = max(block4, block5, block6) - min(block4, block5, block6)

		return(min(gap1, gap2, min(w, h)))

print(min(check(H, W), check(W, H)))
N = input();
sum = 0;

for i in range(N):
  num = i + 1;
  if num % 3 != 0 and num % 5 !=0:
    sum += num;
  else:
    pass;

print(num)
   
    

### FIXED CODE ###

N = int(input());
sum = 0;

for i in range(N):
  num = i + 1;
  if num % 3 != 0 and num % 5 !=0:
    sum += num;
  else:
    pass;

print(sum)
A=5*10**15
s=input()
k=int(input())
l=0

for i in range(len(s)):
        l+=int(s[i])**A
        if k<l:
                print(int(s[i]))
                exit()

### FIXED CODE ###

s=input()
k=int(input())
for i in range(len(s)):
        if s[i] == "1" and (k-1)==i:
                print(1)
                exit()
        elif s[i] == "1" and (k-1) != i:
                continue
        else:
                print(s[i])
                exit()
N = int(input())
L = [0]*N
L[0]=2
L[1]=1
for i in range(2,N-1):
    L[i] = L[i-1]+L[i-2]
print(L[N-1])

### FIXED CODE ###

N = int(input())
MAX = 86
L = [0]*(MAX+1)
L[0] = 2
L[1] = 1
for i in range(2, MAX+1):
    L[i] = L[i-1] + L[i-2]
print(L[N])
N = int(input())
A = [input() for _ in [0]*N]

for i,a in enumerate(A):
    b = a.split(".")
    if len(b)==1:
        A[i] = int(a)*10**9
        continue
    c = b[1]
    n = len(c)
    c += "0"*(9-n)
    A[i] = int(b[0] + c)

cnt = [[0]*20 for _ in [0]*20]
B = [(0,0)]*N
for k,a in enumerate(A):
    i = 0
    j = 0
    while a%2==0:
        a//=2
        i+=1
    while a%5==0:
        a//=5
        j+=1
    B[k] = (max(19,i),max(19,j))
    cnt[i][j] += 1

for i in range(1,20):
    i = 19-i
    for j in range(20):
        j = 19-j
        cnt[i][j] += cnt[i+1][j]

for i in range(20):
    i = 19-i
    for j in range(1,20):
        j = 19-j
        cnt[i][j] += cnt[i][j+1]

ans = 0
for i,j in B:
    me = int(i>=9 and j>=9)
    ans += cnt[18-i][18-j]-me

print(ans//2)

### FIXED CODE ###

N = int(input())
A = [input() for _ in [0]*N]

for i,a in enumerate(A):
    b = a.split(".")
    if len(b)==1:
        A[i] = int(a)*10**9
        continue
    c = b[1]
    n = len(c)
    c += "0"*(9-n)
    A[i] = int(b[0] + c)

cnt = [[0]*40 for _ in [0]*40]
B = [(0,0)]*N
for k,a in enumerate(A):
    i = 0
    j = 0
    while a%2==0:
        a//=2
        i+=1
    while a%5==0:
        a//=5
        j+=1
    B[k] = (i,j)
    cnt[i][j] += 1

for i in range(1,40):
    i = 39-i
    for j in range(40):
        j = 39-j
        cnt[i][j] += cnt[i+1][j]

for i in range(40):
    i = 39-i
    for j in range(1,40):
        j = 39-j
        cnt[i][j] += cnt[i][j+1]

ans = 0
for i,j in B:
    me = int(i>=9 and j>=9)
    ans += cnt[max(0,18-i)][max(0,18-j)]-me

print(ans//2)
w,h,x,y = map(int, input().split())
if w//2==x and h//2==y:
	print(w*h/2, 1)
else*
	print(w*h/2, 0)
	

### FIXED CODE ###

w,h,x,y = map(int, input().split())
if w//2==x and h//2==y and w%2==0 and h%2==0:
	print(w*h/2., 1)
else:
	print(w*h/2., 0)
N,Y = map(int,input().split())

flag = 0
for x in range(N+1):
    if flag > 0:
        break
    for y in range(N-x+1):
        if 10000*x+5000*y+1000*z == Y and flag == 0:
            z = N-x-y
            flag+=1
            print(x,y,z)
            break
            
if flag == 0:
    print('-1 -1 -1')

### FIXED CODE ###

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

flag = 0
for x in range(N+1):
    if flag > 0:
        break
    for y in range(N-x+1):
        z = N-x-y
        if 10000*x+5000*y+1000*z == Y and flag == 0:
            flag+=1
            print(x,y,z)
            break
            
if flag == 0:
    print('-1 -1 -1')
n=int(input())
x=list(map(int, input().split()))

x.sort()

ans=0

for i range(n):
  ans=ans+x[i*2]
    
print(ans)


### FIXED CODE ###

N = int(input())

L = list(map(int, input().split()))

L.sort()

ans = 0

for i in range(N):
    ans = ans + L[i*2]
    
print(ans)
from collections import Counter
s = input()
s_con = Counter(s)
mode = s_con.most_common(1)
s_com = mode[0][1]
s_con_str = mode[0][0]
s_rev = s.reverse()
if s_com >= (len(s) / 2):
  print("-1 -1")
else:
  ans_1 = s.find(s_con_str)
  ans_2 = s_rev.find(s_con_str)
  print(str(ans_1) + " " +str(ans_2))

### FIXED CODE ###

s = list(input())
n = len(s)
ans_1 = -1
ans_2 = -1
if n == 2:
  if s[0] == s[1]:
    ans_1 = 1
    ans_2 = 2
else:
  for i in range(n-2):
    if s[i] == s[i+1]:
      ans_1 = i+1
      ans_2 = i+2
      break
    elif s[i] == s[i+2]:
      ans_1 = i+1
      ans_2 = i+3
      break
print(ans_1,ans_2)
A1 = input()
A2 = input()
A3 = input()

sum = int(A1) + int(A2) + int(A3)

if sum < 22:
	print('win')

elif sum > 21:
	print('bust')

### FIXED CODE ###

A1, A2, A3 = input().split()

sum = int(A1) + int(A2) + int(A3)

if sum < 22:
	print('win')

elif sum > 21:
	print('bust')
import sys
sys.setrecursionlimit(10**7)
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def SI(): return sys.stdin.readline().strip()
INF = 10 ** 18
MOD = 10 ** 9 + 7

def main(): 
    N, Q = LI()
    STX = []
    for _ in range(N):
        STX.append(LI())
    D = []
    for _ in range(Q):
        D.append(II())

    events = []
    for s, t, x in STX:
        events.append((s - x, x, True))  # S-X, X, add_flag
        events.append((t - x, x, False))  # T-X, X, add_flag

    events.sort()  # O(N log N)
    # D is already sorted by input.

    d = D.pop(0)
    d_num = 0
    ans = [-1] * Q
    blocked = set()
    import heapq
    hq = []
    for time, x, add_flag in events:
        while d < time:
            if not blocked:
                ans[d_num] = -1
                hq = []
                d = D.pop(0)
                d_num += 1
                continue
            else:
                while True:
                    if hq[0] in blocked:
                        ans[d_num] = hq[0]
                        d = D.pop(0)
                        d_num += 1
                        break
                    else:
                        heapq.heappop(hq)
                        continue
        if add_flag:
            blocked.add(x)
            heapq.heappush(hq, x)
        else:
            blocked.remove(x)

    for i in ans: print(i)

main()

### FIXED CODE ###

import sys
sys.setrecursionlimit(10**7)
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def SI(): return sys.stdin.readline().strip()
MOD = 10 ** 9 + 7

def main(): 
    N, Q = LI()
    STX = []
    for _ in range(N):
        STX.append(LI())
    D = []
    for _ in range(Q):
        D.append(II())

    STX.sort(key=lambda x:x[2])

    ans = [-1] * Q
    skip = [-1] * Q

    from bisect import bisect_left
    for s, t, x in STX:
        left = bisect_left(D, s-x)  # s-x を超える最小のdの位置
        right = bisect_left(D, t-x)  # t-x を超える最小のdの位置

        while left < right:
            if skip[left] == -1:  # 未踏
                ans[left] = x
                skip[left] = right  # つぎにここにきた際は、rightまで見るのをスキップしてよい。
                left += 1
            else:  # 来たことがある
                left = skip[left]  # 以前覚えておいた right まで見るのをスキップする。

    for i in ans: print(i)

main()
input = open(0).readline
s = {}
s['A'] = list(input().strip())
s['B'] = list(input().strip())
s['C'] = list(input().strip())

play_order = {'A':'B', 'B':'C', 'C':'A'}

def play(player):
    
    if  len(s[player]) == 0:
        play(play_order[player])
    
    next_play = s[player].pop()
    if len(s[player]) == 0:
        
        return player
    #print(next_play)
    play(next_play.upper())
        
print(play('A'))
        
        




### FIXED CODE ###

input = open(0).readline

x = [0]*3
for i in range(3):
    x[i] = int(input().strip())
a, b, h = x[0], x[1], x[2]
ans = int(((a + b) * h)/2)
print(ans)
N = int(input())
A = list(map(int, input().split()))
A.reverse()
ans = 0
max_step = 0
for i in range(N):
    max_step = max(A[i:]) - A[i]
    ans += max_step
print(ans)

### FIXED CODE ###

N, X, T = map(int, input().split())
min_time = 0
while N > 0:
    min_time += T
    N -= X
print(min_time)
import math


def read_int():
    return int(input().strip())


def read_ints():
    return list(map(int, input().strip().split(' ')))


def solve():
    """
    OPT[value] - minimum weight that achieves value
    OPT[value] = OPT[value-v[i]]
    """
    N, W = read_ints()
    max_value = 1000*N+1
    dp = [math.inf]*max_value
    return -1
    dp[0] = 0
    for i in range(N):
        w, v = read_ints()
        for j in range(max_value-1, -1, -1):
            if j >= v:
                dp[j] = min(dp[j], dp[j-v]+w)
    ans = 0
    for j in range(max_value):
        if dp[j] <= W:
            ans = j
    return ans


if __name__ == '__main__':
    print(solve())


### FIXED CODE ###



def read_int():
    return int(input().strip())


def read_ints():
    return list(map(int, input().strip().split(' ')))


def solve():
    """
    OPT[value] - minimum weight that achieves value
    OPT[value] = OPT[value-v[i]]
    """
    N, W = read_ints()
    max_value = 1000*N+1
    dp = [10**12+1]*max_value
    dp[0] = 0
    for i in range(N):
        w, v = read_ints()
        for j in range(max_value-1, -1, -1):
            if j >= v:
                dp[j] = min(dp[j], dp[j-v]+w)
    ans = 0
    for j in range(max_value):
        if dp[j] <= W:
            ans = j
    return ans


if __name__ == '__main__':
    print(solve())
N = int(input())

arr = {(i,j):set([]) for i in range(1,N+1) for j in range(i+1,N+1)}
dic = {(i,j):0 for i in range(1,N+1) for j in range(i+1,N+1)}
used = {(i,j):0 for i in range(1,N+1) for j in range(i+1,N+1)}
visited = {(i,j):0 for i in range(1,N+1) for j in range(i+1,N+1)}
rlt = {(i,j):0 for i in range(1,N+1) for j in range(i+1,N+1)}

def dfs(t):
  for u in arr[t]:
    if visited[u] == 1 and used[u] == 0:
      return -1
    rlt[u] = max(rlt[u], rlt[t]+1)
    if visited[u] == 0:
      visited[u] = 1
      dfs(u)
  used[t] = 1
  return 0

for i in range(1,N+1):
  As = map(int, input().split())
  b = 0
  for a in As:
    if b > 0:
      if i < a and i < b:
        arr[(i,b)].add((i,a))
        dic[(i,a)] += 1
      elif i > a and i < b:
        arr[(i,b)].add((a,i))
        dic[(a,i)] += 1
      elif i < a and i > b:
        arr[(b,i)].add((i,a))
        dic[(i,a)] += 1
      elif i > a and i > b:
        arr[(b,i)].add((a,i))
        dic[(a,i)] += 1
    b = a
    
cnt = N+1
for t in rlt:
  cnt = min(cnt, dic[t])
if cnt > 0:
  print(-1)
  exit()
  
cnt = 0
for t in rlt:
  if dic[t] > 0:
    continue
  rlt[t] = 1
  r = dfs(t)
  if r == -1:
    print(-1)
    exit()
        
for t in rlt:
  cnt = max(rlt[t], cnt)
print(cnt)

### FIXED CODE ###

from collections import deque
 
N = int(input())
As = [[]]
iset = [0]*(N+1)
for _ in range(N):
  As.append(list(map(int, input().split())))

cnt = 0
cset = set([i for i in range(1,N+1)])
while len(cset) > 0:
  cnt += 1
  fset = set()
  nex = set()
  f = 1
  for i in cset:
    if i not in fset:
      vis = As[i][iset[i]]
      if As[vis][iset[vis]] == i and vis not in fset:
        iset[i] += 1
        iset[vis] += 1
        fset.add(i)
        fset.add(vis)
        if iset[i] < N-1:
          nex.add(i)
        if iset[vis] < N-1:
          nex.add(vis)
        f = 0
  cset = nex
  if f == 1:
    print('-1')
    exit()
    
print(cnt)
N, M = map(int, input().split())
a = [True] * (N + 1)
for _ in range(M):
    a[int(input())] = False


arr = [0] * (N + 1)
arr[1] = 1 if a[1] else 0
arr[2] = arr[1] + 1 if a[2] else 0

for i in range(3, N + 1):
    arr[i] = arr[i - 2] + arr[i - 1] if a[i] else 0

print(arr[N] % 1000000007)

### FIXED CODE ###

N, M = map(int, input().split())
a = [True] * (N + 1)
for _ in range(M):
    a[int(input())] = False

arr = [0] * (N + 1)
arr[1] = 1 if a[1] else 0
if 2 <= N:
    arr[2] = arr[1] + 1 if a[2] else 0
    for i in range(3, N + 1):
        arr[i] = arr[i - 2] + arr[i - 1] if a[i] else 0

print(arr[N] % 1000000007)
S=str(input())

ans = 0
if S == "SSS":
	ans = 0
	break
elif S == "SSR" or S == "RSS" or S = "RSR":
	ans = 1
	break
elif S == "SRR" or S == "RRS":
	ans = 2
	break
elif S == "RRR":
	ans = 3
	break
print(ans)

### FIXED CODE ###

S=str(input())

ans = 0
if S == "SSS":
	ans = 0
elif S == "SSR" or S == "RSS" or S == "RSR" or S == "SRS":
	ans = 1
elif S == "SRR" or S == "RRS":
	ans = 2
elif S == "RRR":
	ans = 3
print(ans)