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

from collections import deque
n=int(input())
league=[]
for _ in range(n):
    a=deque(map(int,input().split()))
    league.append(a)

total_match=n*(n-1)//2
match=0
day=0

while match<total_match:
    day+=1
    today_match=[]

    for i in range(n):
        if i in today_match:
            continue
        if league[i]:
            m=league[i][0]-1
            if m in today_match:
                continue
            if league[m] and league[m][0]-1==i:
                today_match.extend((league[i].popleft()-1, league[m].popleft()-1))
    if not today_match:
        day=-1
        break
    match+=len(today_match)//2

print(day)

### FIXED CODE ###

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

N = int(input())
pair = N * (N - 1) // 2
ptoi = dict()

i = 0
for x in range(1, N):
    for y in range(x + 1, N + 1):
        ptoi[(x, y)] = i
        ptoi[(y, x)] = i
        i += 1

edge = [[] for _ in range(pair)]
indeg = [0] * pair
for i in range(1, N+1):
    inp = list(map(int, input().split()))
    for s, t in zip(inp[:-1], inp[1:]):
        edge[ptoi[(i, s)]].append(ptoi[(i, t)])
        indeg[ptoi[(i, t)]] += 1


now = [i for i, d in enumerate(indeg) if d == 0]
day = 0
while now:
    nxt = []
    while now:
        s = now.pop()
        for t in edge[s]:
            if indeg[t] <= 0:
                continue
            indeg[t] -= 1
            if indeg[t] == 0:
                nxt.append(t)
    day += 1
    now = nxt

if all(i <= 0 for i in indeg):
    print(day)
else:
    print(-1)
### BUGGY CODE ###

N = int(input())
A = [int(i) for i in input().split()]
from itertools import combinations as comb
ans = 0
for v in comb(A,2):
    ans += v[0]^v[1]
print(ans % (10**9+7))

### FIXED CODE ###

import sys
input = sys.stdin.readline
N = int(input())
A = [int(i) for i in input().split()]
count0 = [0 for i in range(60)]
count1 = [0 for i in range(60)]
for a in A:
    a_tmp = bin(a).replace("0b","")
    a_tmp = a_tmp.zfill(60)
    for i,b in enumerate(a_tmp):
        if b == "1":
            count1[i] += 1
        else:
            count0[i] += 1
cnt = 0
ans = 0
for c0,c1 in zip(count0[::-1],count1[::-1]):
    ans += c0*c1*(2**cnt)
    cnt += 1
print(ans%(10**9+7))
### BUGGY CODE ###

N = r = int(input())
l = 0
print(0)
S = input()
if S == "Vacant":
    exit()
while l < r - 1:
    m = (l + r) // 2
    print(m)
    s = input()
    if s == "Vacant":
        exit()
    if l & 1 == m & 1 and S == s or l & 1 != m & 1 and S != s:
        l = m + 1
        S = s
    else:
        r = m
print(l)
input()
exit()

### FIXED CODE ###

N = r = int(input())
l = 0
print(0)
S = input()
if S == "Vacant":
    exit()
while l < r - 1:
    m = (l + r) // 2
    print(m)
    s = input()
    if s == "Vacant":
        exit()
    if l & 1 == m & 1 and S == s or l & 1 != m & 1 and S != s:
        l = m
        S = s
    else:
        r = m
print(l)
input()
exit()
### BUGGY CODE ###

h,n=map(int,input().split())
a=[]
b=[]
for i in range(n):
  aa,bb=map(int,input().split())
  a.append(aa)
  b.append(bb)
inf=10**10
f=h+max(a)+1
#dp[i][j]=i番目までの魔法を使えるとき、体力をj減らす最小魔力
dp=[f*[inf]for _ in range(n+1)]
dp[0][0]=0
for i in range(1,n+1):
  dp[i][0]=0
  for j in range(f):
    dp[i][j]=dp[i-1][j]
    if j-a[i-1]>=0:dp[i][j]=min(dp[i][j],dp[i][j-a[i-1]]+b[i-1])
print(min(dp[-1][h:]))

### FIXED CODE ###

h,n=map(int,input().split())
a=[]
b=[]
for i in range(n):
  aa,bb=map(int,input().split())
  a.append(aa)
  b.append(bb)
inf=10**10
f=h+max(a)+1
#dp[i][j]=i番目までの魔法を使えるとき、体力をj減らす最小魔力
dp=[f*[inf]for _ in range(n+1)]
dp[0][0]=0
for i in range(1,n+1):
  dp[i][0]=0
  for j in range(f):
    dp[i][j]=dp[i-1][j]
    if j-a[i-1]>=0:dp[i][j]=min(dp[i][j],dp[i][j-a[i-1]]+b[i-1])
print(min(dp[-1][h:]))
### BUGGY CODE ###

def main():
    N, K = map(int,input().split())
    h = [int(v) for v in input().split()]
    
    dp = [0] * N
    dp[1] = abs(h[0] - h[1])
    
    for i in range(2, N):
        dp[i] = min([dp[j] + abs(h[i] - h[j]) for j in range(i - K, i) if j >= 0])
    
    print(dp[-1])

if __name__ == '__main__':
    main()

### FIXED CODE ###

def main():
    N, K = map(int,input().split())
    h = list(map(int,input().split()))
    
    dp = [0] * N
    dp[1] = abs(h[0] - h[1])
    
    for i in range(2, N):
        dp[i] = min(dp[j] + abs(h[i] - h[j]) for j in range(max(0, i - K), i))
    
    print(dp[-1])

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

import sys
from collections import deque
sys.setrecursionlimit(100000)
input = sys.stdin.readline

N, K = list(map(int, input().split()))
ab = []
for i in range(N-1):
    ab.append(list(map(int, input().split())))

ki = []

for i in range(N):
    ki.append(dict())
    ki[-1]["eda"] = []

for i in range(N-1):
    ki[ab[i][0] - 1]["eda"].append([ab[i][0] - 1, ab[i][1] - 1])
    ki[ab[i][1] - 1]["eda"].append([ab[i][1] - 1, ab[i][0] - 1])

def P(m ,n):
    if m <= 0 or n <= 0:
        return 1
    else:
        num = 1
        for i in range(n):
            num *= m-i
        return num



total_num = K
judge = [0]*N
if len(ki[0]["eda"]) != 0:
    total_num *= P(K-1, len(ki[0]["eda"]))
    judge[0] = 1
    node = deque([])
    for edge in ki[0]["eda"]:
        node.append(edge[1])
    while len(node) != 0:
        i = node.popleft()
        judge[i] = 1
        if K-1 < len(ki[i]["eda"]):
            total_num = 0
            break
        for edge in ki[i]["eda"]:
            if judge[edge[1]] == 0:
                node.append(edge[1])
        total_num *= P(K-2, len(ki[i]["eda"])-1)
        total_num = total_num % 1000000007
        if total_num == 0:
            break

print(total_num)


### FIXED CODE ###

import sys
sys.setrecursionlimit(10**7)
INF=10**9+7
def LI(): return list(map(int, sys.stdin.readline().split()))
 
def main():
    n, k = LI()
    graph=[[] for i in range(n)]
    for i in range(n-1):
        a,b=LI()
        graph[a-1].append(b-1)
        graph[b-1].append(a-1)
    ans=1
    check=[False]*n
    stack=[0]
    ans=1
    while len(stack)>0:
        x=stack.pop()
        check[x]=True
        count=0
        for i in graph[x]:
            if not check[i]:
                count+=1
                stack.append(i)
        if x==0:
            temp=1
            for i in range(count):
                temp=temp*(k-1-i)%INF
            ans=ans*temp%INF
        else:
            temp=1
            for i in range(count):
                temp=temp*(k-2-i)%INF
            ans=ans*temp%INF
    print((ans*k)%INF)
 
 
if __name__ == "__main__":
    main()
### BUGGY CODE ###

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

for i in range(N-K):
    be = A[i:i+K]
    af = A[i+1:i+K+1]
    if sum(be) < sum(af) :
        print("Yes")
    else:
        print("No")


### FIXED CODE ###

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

result = []
for i in range(K, N):
    if A[i] > A[i - K]:
        result.append('Yes')
    else:
        result.append('No')
print(*result, sep='\n')
### BUGGY CODE ###

N,K=map(int,input().split())
h=list(map(int,input().split()))
dp=[0]*N
dp[1]=abs(h[1]-h[0])
for i in range(2,N):
    dp[i]=abs(h[i]-h[i-1])+dp[i-1]
    for j in range(i-2,max(0,i-K)-1,-1):
        dp2=abs(h[i]-h[j])+dp[j]
        if dp[i]>dp2:
            dp[i]=dp2
print(dp[N-1])

### FIXED CODE ###

N,K=map(int,input().split())
h=list(map(int,input().split()))
dp=[0]*N
dp[1]=abs(h[1]-h[0])
for i in range(2,N):
    dp[i]=abs(h[i]-h[i-1])+dp[i-1]
    for j in range(i-2,max(0,i-K)-1,-1):
        dp2=abs(h[i]-h[j])+dp[j]
        if dp[i]>dp2:
            dp[i]=dp2
print(dp[N-1])
### BUGGY CODE ###

# D - Powerful Discount Tickets

def power(price, ticket_count):
    return int(price // (2 ** ticket_count))

# n: 商品数
# m: チケットの枚数
n, m = map(int, input().split())
data = list(map(int, input().split()))

ans = 0

for i in range(m):
    max_data = max(data)
    if max_data == 0:
        break
    max_point = data.index( max_data )
    data[max_point] = power(data[max_point], 1)

print(sum(data))


### FIXED CODE ###

# D - Powerful Discount Tickets
import heapq

n, m = map(int, input().split())
data = list(map(int, input().split()))

pq = []

for i in data:
    heapq.heappush(pq, -i)

for _ in range(m):
    # 先頭の "最小値"
    p = heapq.heappop(pq)
    heapq.heappush(pq, -(-p // 2))

print(-sum(pq))
### BUGGY CODE ###

from collections import deque
a = list(input())
Q = int(input())
A = []
d = deque(a)
for i in range(Q):
  b = list(input().split())
  if len(b) == 1:
    d.reverse()
  elif b[1] == "1":
    d.appendleft(b[2])
  elif b[1] == "2":
    d.append(b[2])
print("".join(d))

### FIXED CODE ###

from collections import deque
a = list(input())
Q = int(input())
d = deque(a)
ans = 1
for i in range(Q):
  b = list(input().split())
  if len(b) == 1:
    ans += 1
  elif b[1] == "1" and ans % 2 == 1:
    d.appendleft(b[2])
  elif b[1] == "1" and ans % 2 == 0:
    d.append(b[2])
  elif b[1] == "2" and ans % 2 == 1:
    d.append(b[2])
  elif b[1] == "2" and ans % 2 == 0:
    d.appendleft(b[2])
if ans % 2 == 0:
  d.reverse()
print("".join(d))
### BUGGY CODE ###

from sys import stdin


inp = stdin.readline

n, k = [int(x) for x in inp().strip().split()]

array = [int(x) for x in inp().strip().split()]

distance = [0]*(k + 2)

for i in range(k - 1):
    distance[1+i] = array[i+1] - array[i]
if array[0] == 0:
    distance[k] = 20-array[k-1]
else:
    distance[k] = abs(array[k - 1] - array[0])
distance[0] = distance[-2]
distance[-1] = distance[1]

minimum = 999999999

for i in range(k + 1):
    total = sum(distance[i:i+k-1])
    if minimum > total:
        minimum = total

print(minimum)


### FIXED CODE ###

from sys import stdin


inp = stdin.readline

n, k = [int(x) for x in inp().strip().split()]

array = [int(x) for x in inp().strip().split()]

distance = [0]*(k * 2)

for i in range(k - 1):
    distance[i] = array[i+1] - array[i]

distance[k-1] = n-array[k-1] + array[0]
distance[2*k-1] = n-array[k-1] + array[0]
for i in range(k - 1):
    distance[k+i] = array[i+1] - array[i]

minimum = 999999999

count = 0
total = 0
countLimit = k-1
for i in range(k * 2):
    if count < countLimit:
        total += distance[i]
        count += 1
    else:
        if minimum > total:
            minimum = total
        total += distance[i]
        total -= distance[i-countLimit]

print(minimum)
### BUGGY CODE ###

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

rl = []

for i in range(k-1,n):
  r = 1
  for j in range(k):
    r = r * a[i-j]
    j += 1
  rl.append(r)
  i += 1

for m in range(n-k):
  if rl[m+1] > rl[m]:
    print('Yes')
  else:
    print('No')

### FIXED CODE ###

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

for i in range(k,n):
  if a[i] > a[i-k]:
    print('Yes')
  else:
    print('No')
### BUGGY CODE ###

N = int(input())
numbers = list(map(int,input().split()))
numOfOperation = int(input())
for i in range(numOfOperation):
    B,C = map(int,input().split())
    for j in range(len(numbers)):
        if numbers[j] == B : numbers[j] = C
    print(sum(numbers))


### FIXED CODE ###

N = int(input())
numbers = list(map(int,input().split()))
numOfOperation = int(input())
dic = {}

for num in numbers:
    if num in dic : dic[num] += 1
    else: dic[num] = 1
    

sums = sum(numbers)
for i in range(numOfOperation):
    B,C = map(int,input().split())
    if (B in dic) : 
        cnt = dic[B]
        dic[B] = 0
        if (C not in dic) : dic[C] = cnt
        else : dic[C] += cnt
        sums += cnt * (C - B)
    print(sums)
### BUGGY CODE ###

N = int(input())
S = [[] for i in range(10)]
count = 0
for i in range(N):
  string = input()
  if len(S[len(string)-1]) == 0:
    S[len(string)-1].append(string)
    count += 1
  elif not string in S[len(string)-1]:
    S[len(string)-1].append(string)
    count += 1
print(count)

### FIXED CODE ###

N = int(input())
S = []
for i in range(N):
  string = input()
  S.append(string)
S = sorted(S)
count = N
for i in range(N-1):
  if S[i] == S[i+1]:
    count -= 1
print(count)
### BUGGY CODE ###

n = int(input())
p = list(map(int, input().split()))
count = 0
tof = True

for i in range(n):
  for j in range(i):
    if p[j] <= p[i]:
      tof = False
      break
  if tof:
    count += 1
  else:
    tof = True
  
print(count)

### FIXED CODE ###

n = int(input())
p = list(map(int, input().split()))
count = 0
m = [0] * n

memo = n
for i in range(n):
    if memo > p[i]:
        m[i] = p[i]
        memo = p[i]
    else:
        m[i] = memo

for i in range(1, n+1):
    if p[i-1] <= m[i-1]:
        count += 1

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

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

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

def gcdlist(l):
    a = l[0]
    for i in range(len(l)):
        a = gcd(a,l[i])
    return a

dp = [a[0]]*(n)
dp[0] = a[1]
ldp = len(dp)
for i in range(1, n):
    a1 = a[i]
    for j in range(ldp):
        if i != j:
            dp[j] = gcd(a1, dp[j])

print(max(dp))

### FIXED CODE ###


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

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

left = [0] * (n + 1)
for i in range(1, n):
    left[i] = gcd(left[i - 1], a[i - 1])

right = [0] * (n + 1)
for i in range(1, n):
    right[n - i] = gcd(right[n - i + 1], a[n - i])

ans = 0
for i in range(n):
    ans = max(ans, gcd(left[i], right[i + 1]))
print(ans)
### BUGGY CODE ###

import sys
from heapq import heappop, heappush

n, m, ss = map(int, input().split())
lines = sys.stdin.readlines()
links = [set() for _ in range(n)]
aaa = []
for line in lines[:m]:
    u, v, a, b = map(int, line.split())
    u -= 1
    v -= 1
    links[u].add((v, a, b))
    links[v].add((u, a, b))
    aaa.append(a)

exchanges = []
for line in lines[m:]:
    c, d = map(int, line.split())
    exchanges.append((c, d))

req = sum(sorted(aaa, reverse=True)[:n])
INF = 10 ** 18
ans = [INF] * n
ans_silver = [-1] * n

q = [(0, ss, 0, 0)]  # (time, silver, city, type)
visited = set()
fixed = 0
while q:
    t, s, v, z = heappop(q)
    if (s, v) in visited:
        continue
    visited.add((s, v))
    if ans[v] == INF:
        ans[v] = t
        ans_silver[v] = s
        fixed += 1
        if fixed == n:
            break

    for u, a, b in links[v]:
        if s < a:
            continue
        ns = s - a
        nt = t + b
        if (ns, u) in visited or ans_silver[u] >= ns:
            continue
        heappush(q, (t + b, ns, u, 0))

    if z == 1:
        continue

    ts = s
    tt = t
    c, d = exchanges[v]
    while ts <= req:
        ts += c
        tt += d
        if (ts, v) in visited:
            break
        heappush(q, (tt, ts, v, 1))

print('\n'.join(map(str, ans[1:])))


### FIXED CODE ###

import sys
from heapq import heappop, heappush

n, m, ss = map(int, input().split())
lines = sys.stdin.readlines()
links = [set() for _ in range(n)]
aaa = []
for line in lines[:m]:
    u, v, a, b = map(int, line.split())
    u -= 1
    v -= 1
    links[u].add((v, a, b))
    links[v].add((u, a, b))
    aaa.append(a)

exchanges = []
for line in lines[m:]:
    c, d = map(int, line.split())
    exchanges.append((c, d))

req = sum(sorted(aaa, reverse=True)[:n - 1])
INF = 10 ** 18
ans = [INF] * n
ans_silver = [-1] * n

q = [(0, ss, 0)]  # (time, silver, city)
visited = set()
fixed = 0
while q:
    t, s, v = heappop(q)
    if (s, v) in visited or ans_silver[v] >= s:
        continue
    visited.add((s, v))
    if ans[v] == INF:
        ans[v] = t
        ans_silver[v] = s
        fixed += 1
        if fixed == n:
            break

    for u, a, b in links[v]:
        if s < a:
            continue
        ns = s - a
        nt = t + b
        if (ns, u) in visited or ans_silver[u] >= ns:
            continue
        heappush(q, (nt, ns, u))

    c, d = exchanges[v]
    ns = s + c
    if ns <= req and (ns, v) not in visited:
        heappush(q, (t + d, ns, v))

print('\n'.join(map(str, ans[1:])))
### BUGGY CODE ###

import sys
from bisect import bisect_right, insort_left
N = int(sys.stdin.readline())
a_list = [int(sys.stdin.readline()) for _ in range(N)]


que = []

ans = 0
min_num = float("inf")
for i, a in enumerate(a_list):
    if i == 0:
        que.append(a)
        min_num = a
        ans += 1
    else:
        # idx = bisect_right(que, a-1)
        if a <= min_num:
        # if idx == 0:
            insort_left(que, a)
            ans += 1
            min_num = a
        else:
            idx = bisect_right(que, a-1)
            que[idx-1] = a
            if idx -1 == 0:
                min_num = a
    #print(que, min_num)
print(ans)


### FIXED CODE ###

import sys
from bisect import bisect_right, insort_left
from collections import deque
N = int(sys.stdin.readline())
a_list = [int(sys.stdin.readline()) for _ in range(N)]


que = []
que = deque(que)

ans = 0
min_num = float("inf")
for i, a in enumerate(a_list):
    if i == 0:
        que.append(a)
        min_num = a
        ans += 1
    else:
        idx = bisect_right(que, a-1)

        if idx == 0:
            que.appendleft(a)
            ans += 1
            min_num = a
        else:
            idx = bisect_right(que, a-1)
            que[idx-1] = a
            if idx -1 == 0:
                min_num = a
    #print(que, min_num)
print(ans)
### BUGGY CODE ###

n, w = map(int, input().split())
WV = []
for i in range(n):
    WV.append(tuple(map(int, input().split())))
dp = [[0 for _ in range(w+1)] for _ in range(n+1)]
for i in range(n+1):
    for j in range(w+1):
        if i == 0:
            dp[i][j] = 0
        else:
            (weight, value) = WV[i-1]
            if weight > j:
                dp[i][j] = dp[i-1][j]
            else:
                dp[i][j] = max(dp[i-1][j], dp[i-1][j-weight] + value)
print(dp[n][w])


### FIXED CODE ###

n, mw = map(int, input().split())
goods = [tuple(map(int, input().split())) for _ in range(n)]
dp = [[0 for _ in range(mw+1)] for _ in range(n+1)]
for i in range(n):
    for j in range(mw+1):
        w, v = goods[i]
        if j >= w:
            dp[i+1][j] = max(dp[i][j], dp[i][j - w] + v)
        else: dp[i+1][j] = dp[i][j]
print(dp[n][mw])
### BUGGY CODE ###

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

for m in range(M):
    A[-1] //= 2
    A.sort()
    #print(A)

print(sum(A))

### FIXED CODE ###

import heapq

N, M = map(int, input().split())
A = list(map(lambda x: int(x)*(-1), input().split()))
heapq.heapify(A)

#print(A)

for _ in range(M):
    m = heapq.heappop(A)
    #print(m)
    heapq.heappush(A, -(-m // 2))
    #print(A)

print(-sum(A))
### BUGGY CODE ###

import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, acos, atan, asin
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
def input(): return sys.stdin.readline().strip()
def STR(): return input()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
sys.setrecursionlimit(10 ** 9)
inf = sys.maxsize
mod = 10 ** 9 + 7

n = INT()
a = LIST()
b = Counter(a)
c = list(set(a))
for k in range(n):
    ans = 0
    for i in c:
        tmp = b[i]
        if i == a[k]:
            tmp -= 1
        if tmp >= 2:
            ans += tmp * (tmp - 1) // 2
    print(ans)


### FIXED CODE ###

import sys
from collections import Counter
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def LIST(): return list(map(int, input().split()))

n = INT()
a = LIST()
c = list(set(a))
b = [0 for _ in range(n + 1)]
for i in range(n):
    b[a[i]] += 1
d = [0 for _ in range(n + 1)]
e = [0 for _ in range(n + 1)]
for i in range(n + 1):
    if b[i] >= 2:
        d[i] = b[i] * (b[i] - 1) // 2
    if b[i] >= 3:
        e[i] = (b[i] - 1) * (b[i] - 2) // 2
sd = sum(d)
se = sum(e)
for k in range(n):
    ans = sd - d[a[k]] + e[a[k]]
    print(ans)
### BUGGY CODE ###

import bisect
import sys
input = sys.stdin.readline


N = int(input())
alist = list(map(int, input().split()))
Q = int(input())


alist.sort()
sumA = sum(alist)
for _ in range(Q):
    b, c = map(int, input().split())
    idx_bl = bisect.bisect_left(alist, b)
    idx_br = bisect.bisect_right(alist, b)

    alist = alist[:idx_bl] + alist[idx_br:]
    idx_cl = bisect.bisect_left(alist, c)
    alist = alist[:idx_cl] + [c] * (idx_br - idx_bl) + alist[idx_cl:]

    sumA -= (idx_br - idx_bl) * (b - c)
    print(sumA)


### FIXED CODE ###

import sys
from collections import Counter
input = sys.stdin.readline


N = int(input())
alist = list(map(int, input().split()))
Q = int(input())


sumA = sum(alist)
adict = Counter(alist)

for _ in range(Q):
    b, c = map(int, input().split())

    if b not in adict:
        print(sumA)
        continue

    bnum = adict.pop(b)
    if c in adict:
        adict[c] += bnum
    else:
        adict[c] = bnum

    sumA -= bnum * (b - c)
    print(sumA)
### BUGGY CODE ###

n = int(input())
tra = [int(input()) for i in range(5)]
box = [0]*6
box[0] = n
c = 0
while box[5] != n:
    box[5] += min(box[4],tra[4]) 
    for i in range(4,0,-1):
        box[i] = box[i] + min(box[i-1],tra[i-1]) - min(box[i],tra[i])
    box[0] -= min(box[0],tra[0])
    c += 1
print(c)

### FIXED CODE ###

import math
n = int(input())
tra = [int(input()) for i in range(5)]
print(math.ceil(n/min(tra))+4)
### BUGGY CODE ###

N = int(input())
A = [int(input()) for _ in range(N)]
 
s = []
cnt = 0
n = 1
f = False
while cnt <= N:
  s.append(n)
  cnt += 1
  n = A[n - 1]
  if n == 2:
    f = True
    break
  elif n in s:
    break
print(cnt if f else -1)

### FIXED CODE ###

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

cnt = 0
n = 1
f = False
while cnt <= N:
  cnt += 1
  n = A[n - 1]
  if n == 2:
    f = True
    break
print(cnt if f else -1)