Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
import collections

N = int(input())
l = [s for s in input().split()]

c = collections.Counter(l)
ans_dict = {}

for i in l:
    if str(i) in ans_dict.keys():
        print(int(ans_dict[str(i)]))
    else:
        c[str(i)] -= 1
        hoge = list(c.values())
        fuga = [(i*(i-1))/2 if i >= 2 else 0 for i in hoge]
        ans = sum(fuga)
        c[str(i)] += 1
        ans_dict[str(i)] = ans
        print(int(ans))

Fixed submission:
import collections

N = int(input())
l = [s for s in input().split()]

c = collections.Counter(l)
ans_dict = {}

hoge = list(c.values())
full_fuga = [(i*(i-1))/2 if i >= 2 else 0 for i in hoge]
full_ans = sum(full_fuga)

for i in l:
    v = c[str(i)]
    if v < 2:
        print(int(full_ans))
    elif v == 2:
        print(int(full_ans - 1))
    elif v > 2:
        print(int(full_ans - ((v*(v-1))/2) + (((v-1) *(v-2))/2)))

Buggy python submission (verdict: Time Limit Exceeded):
import collections

N = int(input())
l = [s for s in input().split()]

c = collections.Counter(l)

for i in l:
    c[str(i)] -= 1
    hoge = list(c.values())
    fuga = [(i*(i-1))/2 if i >= 2 else 0 for i in hoge]
    ans = sum(fuga)
    c[str(i)] += 1
    
    print(int(ans))


Fixed submission:
import collections

N = int(input())
l = [s for s in input().split()]

c = collections.Counter(l)
ans_dict = {}

hoge = list(c.values())
full_fuga = [(i*(i-1))/2 if i >= 2 else 0 for i in hoge]
full_ans = sum(full_fuga)

for i in l:
    v = c[str(i)]
    if v < 2:
        print(int(full_ans))
    elif v == 2:
        print(int(full_ans - 1))
    elif v > 2:
        print(int(full_ans - ((v*(v-1))/2) + (((v-1) *(v-2))/2)))

Buggy python submission (verdict: Time Limit Exceeded):
import collections

N = int(input())
l = [s for s in input().split()]

c = collections.Counter(l)
hoge = list(c.values())

for i in l:
    ans = 0
    for ix,k in enumerate(c):# key
        
        if int(k) == int(i) and hoge[ix]-1 >= 2:
            tmp = hoge[ix] - 1
            ans += (tmp * (tmp-1)) / 2
            
        elif int(k) != int(i) and hoge[ix] >= 2:
            tmp = hoge[ix]
            ans += (tmp * (tmp-1)) / 2
            
        else:
            pass
    print(int(ans))

Fixed submission:
import collections

N = int(input())
l = [s for s in input().split()]

c = collections.Counter(l)
ans_dict = {}

hoge = list(c.values())
full_fuga = [(i*(i-1))/2 if i >= 2 else 0 for i in hoge]
full_ans = sum(full_fuga)

for i in l:
    v = c[str(i)]
    if v < 2:
        print(int(full_ans))
    elif v == 2:
        print(int(full_ans - 1))
    elif v > 2:
        print(int(full_ans - ((v*(v-1))/2) + (((v-1) *(v-2))/2)))
Buggy python submission (verdict: Time Limit Exceeded):
S = input()
N = int(input())
ls = [[i for i in input().split()] for j in range(N)]

for l in ls:
    if l[0]=="1": # 反転
        S = S[::-1]
    elif l[0]=="2":
        if l[1] == "1":
            S = l[2] + S
        elif l[1] == "2":
            S = S + l[2]

print(S)

Fixed submission:
from collections import deque
S = deque(list(input()))
Q = int(input())
Flag = True
for _ in range(Q):
    q = input().split()
    if len(q) == 1:
        Flag = False if Flag else True
    else:
        if Flag:
            if q[1] == '1':
                S.appendleft(q[2])
            else:
                S.append(q[2])
        else:
            if q[1] == '1':
                S.append(q[2])
            else:
                S.appendleft(q[2])
if Flag:
    print(''.join(S))
else:
    print(''.join(reversed(S)))
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
Ps = list(map(int,input().split()))
ans = 1
for n in range(2,N+1):
    if Ps[n-1] == min(Ps[:n]):
        ans += 1
print(ans)


Fixed submission:
N = int(input())
Ps = list(map(int,input().split()))
ans = 0
minP = N
for p in Ps:
    if p <= minP:
        ans += 1
    minP = min(minP, p)
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
Ps = list(map(int,input().split()))
ans = 0
for n in range(1,N+1):
    if n == 1:
        ans +=1
    elif Ps[n-1] == min(Ps[:n]):
        ans += 1
    else:
        pass
print(ans)


Fixed submission:
N = int(input())
Ps = list(map(int,input().split()))
ans = 0
minP = N
for p in Ps:
    if p <= minP:
        ans += 1
    minP = min(minP, p)
print(ans)
Buggy python submission (verdict: Runtime Error):
def cmb(n,r,mod=10**9+7):
    fac = [0] * (n+1)
    finv = [0] * (n+1)
    inv = [0]*(n+1)

    fac[0] = fac[1] = 1
    finv[0] = finv[1] = 1
    inv[1] = 1
    
    for i in range(2, n+1):
        fac[i] = fac[i-1]*i % mod
        inv[i] = mod - inv[mod%i] * (mod//i) % mod
        finv[i] = finv[i-1] * inv[i] % mod

    if n < r: return 0
    if n < 0 or r < 0: return 0
    return (fac[n]*(finv[r]*finv[n-r]%mod)%mod)

x,y  = map(int, input().split())

if (x+y) % 3 != 0:
    print(0)
    exit()

i = (x+y)//3
j = x-i

print(cmd(i,j))

Fixed submission:
def cmd(n,r,mod=10**9+7):
    fac = [0] * (n+1)
    finv = [0] * (n+1)
    inv = [0]*(n+1)

    fac[0] = fac[1] = 1
    finv[0] = finv[1] = 1
    inv[1] = 1
    
    for i in range(2, n+1):
        fac[i] = fac[i-1]*i % mod
        inv[i] = mod - inv[mod%i] * (mod//i) % mod
        finv[i] = finv[i-1] * inv[i] % mod

    if n < r: return 0
    if n < 0 or r < 0: return 0
    return (fac[n]*(finv[r]*finv[n-r]%mod)%mod)

x,y  = map(int, input().split())

if (x+y) % 3 != 0:
    print(0)
    exit()

i = (x+y)//3
j = x-i

print(cmd(i,j))
Buggy python submission (verdict: Runtime Error):
import math

N = int(input())

ans = 1e18
for i in range(int(0,math.sqrt(N))):
    if N%i != 0:
        continue
    j = N/i
    ans = min(ans, i+j-2)
print(int(ans))

Fixed submission:
import math

N = int(input())

ans = 1e18
for i in range(int(math.sqrt(N)), 0, -1):
    if N%i != 0:
        continue
    j = N/i
    ans = min(ans, i+j-2)
print(int(ans))
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
l = list(map(int, input().split()))
l2 = l.copy()
ans = []
l.sort()

for i in l:
    ans.append(l2.index(i)+1)

print(*ans)

Fixed submission:
N = int(input())
l = list(map(int, input().split()))
ans = [0]*N

for i in range(N):
    ans[l[i]-1] = i+1
print(*ans)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
l = list(map(int, input().split()))
ans = []

for i in range(N):
    ans.append(l.index(min(l))+1)
    l[l.index(min(l))] = max(l) + 1

print(*ans)

Fixed submission:
N = int(input())
l = list(map(int, input().split()))
ans = [0]*N

for i in range(N):
    ans[l[i]-1] = i+1
print(*ans)
Buggy python submission (verdict: Time Limit Exceeded):
a = list(map(int,input().split()))
results = [int(input()) for i in range(a[2])]

points = [a[1]] * a[0]

for result in results:
    points = list(map(lambda x: x - 1, points))
    points[result - 1] = points[result - 1] + 1


for point in points:
    if point > 0:
        print('Yes')
    else:
        print('No')
    

Fixed submission:
a = list(map(int,input().split()))
results = [int(input()) for i in range(a[2])]

points = [a[1]] * a[0]
points = list(map(lambda x: x - a[2], points))

for result in results:
    points[result - 1] = points[result - 1] + 1


for point in points:
    if point > 0:
        print('Yes')
    else:
        print('No')
Buggy python submission (verdict: Runtime Error):
N = int(input())
print(sum(list(range(0,N))))

Fixed submission:
N = int(input())
print(N*(N-1)//2)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
ans = 0
for i in range(N):
    ans += i

print(ans)

Fixed submission:
N = int(input())
print(N*(N-1)//2)
Buggy python submission (verdict: Runtime Error):
N = int(input())
l = map(int, raw_input().split())
l = [int(s) for s in l]

total = 0
for i in l:
  total += 1/i

print(1/total)

Fixed submission:
N = int(input())
l = list(map(int,input().split()))
 
total = 0
for i in l:
  total += 1/i

print(1/total)
Buggy python submission (verdict: Runtime Error):
import collections
import math
 
N = int(input())
words = [input() for i in range(N)] 
 
ans = 0
L = []
for ix, word in  enumerate(words):
    word_list = list(word)
    word_list.sort()
    L.append(''.join(map(str, word_list)))
 
c = collections.Counter(L)
 
for i in c.values():    
    ans += factorial(i) / factorial(2) / factorial(i - 2)
 
print(int(ans))
import collections
from math import factorial

N = int(input())
words = [input() for i in range(N)] 

ans = 0
L = []
for ix, word in  enumerate(words):
    word_list = list(word)
    word_list.sort()
    L.append(''.join(map(str, word_list)))

c = collections.Counter(L)

for i in c.values():    
    ans += math.factorial(i) / math.factorial(2) / math.factorial(i - 2)

print(int(ans))
提出情報

Fixed submission:
l = list(map(int,input().split()))

print(max([l[0]+l[1],l[0]-l[1],l[0]*l[1]]))
Buggy python submission (verdict: Time Limit Exceeded):
n, m = [int(i) for i in input().split()]
table = [[int(i) for i in input().split()] for m in range(m)]

a = range(table[0][0],table[0][1]+1)
ans = a
for i,t in enumerate(table[1:]):
    if i == 0:
    	b = range(t[0], t[1]+1)
    	ans = set(a) & set(b)
    else:
        b = range(t[0], t[1]+1)
        ans = ans & set(b)
print(len(ans))

Fixed submission:
n,m=map(int,input().split())
low=1
high=n
for i in range(m):
	l,r=map(int,input().split())
	low = max(low,l)
	high=min(high,r)
ans=high-low+1
print(ans if ans>=0 else 0)

Buggy python submission (verdict: Runtime Error):
n, m = [int(i) for i in input().split()]
table = [[int(i) for i in input().split()] for m in range(m)]

a = range(table[0][0],table[0][1]+1)
for i,t in enumerate(table[1:]):
    if i == 0:
    	b = range(t[0], t[1]+1)
    	ans = set(a) & set(b)
    else:
        b = range(t[0], t[1]+1)
        ans = ans & set(b)
print(len(ans))

Fixed submission:
n,m=map(int,input().split())
low=1
high=n
for i in range(m):
	l,r=map(int,input().split())
	low = max(low,l)
	high=min(high,r)
ans=high-low+1
print(ans if ans>=0 else 0)

Buggy python submission (verdict: Runtime Error):
n, m = [int(i) for i in input().split()]
table = [[int(i) for i in input().split()] for m in range(m)]

a = range(table[0][0],table[0][1]+1)
for i,t in enumerate(table[1:]):
    if i == 0:
    	b = range(t[0], t[1]+1)
    	ans = set(a) & set(b)
    else:
        b = range(t[0], t[1]+1)
        ans = ans & set(b)
print(len(ans))

Fixed submission:
n,m=map(int,input().split())
low=1
high=n
for i in range(m):
	l,r=map(int,input().split())
	low = max(low,l)
	high=min(high,r)
ans=high-low+1
print(ans if ans>=0 else 0)
Buggy python submission (verdict: Time Limit Exceeded):
N, Q = [int(i) for i in input().split()]
S = input()
a_n = [[int(i) for i in input().split()] for Q in range(Q)]

for a in a_n:
    print(S[a[0]-1:a[1]].count('AC'))
    

Fixed submission:
N,Q = map(int, input().split())
S = input()
range_list = [list(map(int, input().split())) for _ in range(Q)]
 
ac_counter = [0]
# acという文字列をカウントしておくlistを作成
for i in range(1,N):
    ac_counter.append(ac_counter[i-1]+1 if S[i-1:i+1] == 'AC' else ac_counter[i-1])
# 上で作ったリストを使い範囲内に何個あるのか確認
for range_list in range_list:
    print(ac_counter[range_list[1]-1] - ac_counter[range_list[0]-1])
Buggy python submission (verdict: Runtime Error):

S = input()

S = [s for s in S]

ans = 0
while len(S) > 0:
    counter = 0
    for ix in range(len(S)):
        if ix+1 < len(S):
            if S[ix] != S[ix+1]:
                del S[ix]
                del S[ix]
                ans += 1
                counter += 1
                break

            if S[ix] == S[ix+1] and S[ix+1] == S[ix+2]:
                del S[ix+1]
    if counter == 0:
        break

print(ans*2)

Fixed submission:

S = input()

S = [s for s in S]
S = [int(s, 0) for s in S]
S.sort()
if 1 in S and  0 in S:
    print(min(S.count(0)*2,S.count(1)*2))
else:
    print(0)

Buggy python submission (verdict: Runtime Error):

S = input()

S = [s for s in S]

ans = 0
while len(S) > 0:
    counter = 0
    for ix in range(len(S)):
        if ix+1 < len(S):
            if S[ix] != S[ix+1]:
                del S[ix]
                del S[ix]
                ans += 1
                counter += 1
                break

            if S[ix] == S[ix+1] and S[ix+1] == S[ix+2]:
                del S[ix+1]
    if counter == 0:
        break

print(ans*2)

Fixed submission:

S = input()

S = [s for s in S]
S = [int(s, 0) for s in S]
S.sort()
if 1 in S and  0 in S:
    print(min(S.count(0)*2,S.count(1)*2))
else:
    print(0)

Buggy python submission (verdict: Time Limit Exceeded):

S = input()

S = [s for s in S]

ans = 0
while len(S) > 0:
    counter = 0
    for ix in range(len(S)):
        if ix+1 < len(S):
            if S[ix] != S[ix+1]:
                del S[ix]
                del S[ix]
                ans += 1
                counter += 1
                break
    if counter == 0:
        break

print(ans*2)

Fixed submission:

S = input()

S = [s for s in S]
S = [int(s, 0) for s in S]
S.sort()
if 1 in S and  0 in S:
    print(min(S.count(0)*2,S.count(1)*2))
else:
    print(0)

Buggy python submission (verdict: Runtime Error):

S = input()

S = [s for s in S]

ans = 0
while len(S) > 0:
    counter = 0
    for ix in range(len(S)):
        if ix+1 < len(S):
            if S[ix] != S[ix+1]:
                print(S)
                del S[ix]
                del S[ix]
                ans += 1
                counter += 1
                break
    if counter == 0:
        break

print(ans*2)

Fixed submission:

S = input()

S = [s for s in S]
S = [int(s, 0) for s in S]
S.sort()
if 1 in S and  0 in S:
    print(min(S.count(0)*2,S.count(1)*2))
else:
    print(0)

Buggy python submission (verdict: Runtime Error):

S = input()

S = [s for s in S]

ans = 0
while len(S) > 0:
    counter = 0
    for ix in range(len(S)):
        if ix+1 < len(S):
            if S[ix] != S[ix+1]:
                print(S)
                del S[ix]
                del S[ix]
                ans += 1
                counter += 1
    if counter == 0:
        break

print(ans*2)

Fixed submission:

S = input()

S = [s for s in S]
S = [int(s, 0) for s in S]
S.sort()
if 1 in S and  0 in S:
    print(min(S.count(0)*2,S.count(1)*2))
else:
    print(0)
Buggy python submission (verdict: Runtime Error):
n, m = map(int, input().split())
x = list(map(int, input().split()))
 
if n >= len(x):
    print(0)
    exit()
l = []
x.sort()
 
for i in range(m-1):
    diff = x[i+1] - x[i]
    ls.append(diff)
l.sort(reverse=True)
ans = sum(ls)
 
for i in range(n-1):
    ans -= ls[i]
print(ans)

Fixed submission:
n, m = map(int, input().split())
x = list(map(int, input().split()))

if n >= len(x):
    print(0)
    exit()

ls = []
x.sort()

for i in range(m-1):
    diff = x[i+1] - x[i]
    ls.append(diff)

ls.sort(reverse=True)
ans = sum(ls)

for i in range(n-1):
    ans -= ls[i]

print(ans)

Buggy python submission (verdict: Runtime Error):
n, m = map(int, input().split())
x = list(map(int, input().split()))
 
if n >= len(x):
    print(0)
    exit()

l = []
x.sort()
 
for i in range(m-1):
    diff = x[i+1] - x[i]
    ls.append(diff)

l.sort(reverse=True)
ans = sum(ls)
 
for i in range(n-1):
    ans -= ls[i]
print(ans)

Fixed submission:
n, m = map(int, input().split())
x = list(map(int, input().split()))

if n >= len(x):
    print(0)
    exit()

ls = []
x.sort()

for i in range(m-1):
    diff = x[i+1] - x[i]
    ls.append(diff)

ls.sort(reverse=True)
ans = sum(ls)

for i in range(n-1):
    ans -= ls[i]

print(ans)
Buggy python submission (verdict: Runtime Error):
import math 
N, X = map(int, input().split())
l = list(map(int, input().split()))

l.insert(0, X)
diff_list = [0] * (int(len(l)/2) + 1)

ans = abs(l[0] - l[1])
ix = 2
for i in l[1:len(l)-1]:
    tmp = abs(i - l[ix])
    ans = math.gcd(ans, tmp)
    ix += 1
print(ans)

Fixed submission:

N, X = map(int, input().split())
l = list(map(int, input().split()))

l.insert(0, X)
diff_list = [0] * (int(len(l)/2) + 1)

ans = abs(l[0] - l[1])
ix = 2

#a,bの最大公約数
def gcd(a,b):
    if b == 0:
        return a
    else:
        return gcd(b,a%b)

for i in l[1:len(l)-1]:
    tmp = abs(i - l[ix])
    ans = gcd(ans, tmp)
    ix += 1
print(ans)

Buggy python submission (verdict: Runtime Error):
import math
from functools import reduce

N, X = map(int, input().split())
l = list(map(int, input().split()))

l.insert(0, X)
diff_list = [0] * (int(len(l)/2) + 1)

for ix,i in enumerate(l[1:]):
    diff_list.append(abs(l[ix] - i))

def gcd_list(numbers):
    return reduce(math.gcd, numbers)

print(gcd_list(diff_list))

Fixed submission:

N, X = map(int, input().split())
l = list(map(int, input().split()))

l.insert(0, X)
diff_list = [0] * (int(len(l)/2) + 1)

ans = abs(l[0] - l[1])
ix = 2

#a,bの最大公約数
def gcd(a,b):
    if b == 0:
        return a
    else:
        return gcd(b,a%b)

for i in l[1:len(l)-1]:
    tmp = abs(i - l[ix])
    ans = gcd(ans, tmp)
    ix += 1
print(ans)
Buggy python submission (verdict: Runtime Error):
import math
n = int(input())
a = list(map(int,input().split()))
g_c = sum([1 for i in a if i%2==0]) 
ans = 0
for i in a:
  if i%2==0:
    while(i%2==0):
      i = i//2
      ans += 1
print(c)

Fixed submission:
import math
n = int(input())
a = list(map(int,input().split()))

ans = 0
for i in a:
  if i%2==0:
    while(i%2==0):
      i = i//2
      ans += 1
print(ans)
Buggy python submission (verdict: Runtime Error):
N, M = map(int,input().split()) 
P = [input().split() for i in range(M)]

ans = "Yes"
for n in range(N):
    for m in range(M):
        if p[n][m] == '#':
            if p[n-1][m] == "." and p[n][m-1] == "." and p[n+1][m] == "." and p[n][m+1] == ".":
                ans = "No"
                break
print(ans)

Fixed submission:
N, M = map(int,input().split()) 
p = [input() for i in range(N)]

ans = "Yes"
for n in range(1,N-1):
    for m in range(1,M-1):
        if p[n][m] == '#':
            if p[n-1][m] != "#" and p[n][m-1] != "#" and p[n+1][m] != "#" and p[n][m+1]!= "#":
                ans = "No"
                break
print(ans)
Buggy python submission (verdict: Runtime Error):
x = sort(list(map(int, input().split())))
ans = 0
if x[0]%2==x[1]%2:
    ans += (x[1] - x[0])//2
    ans += (x[2] - x[1])
else:
    ans += 1
    ans += (x[1] - x[0] + 1)//2
    ans += (x[2] - x[1])
print(ans)

Fixed submission:
x = sorted(list(map(int, input().split())))
ans = 0
if x[0]%2==x[1]%2:
    ans += (x[1] - x[0])//2
    ans += (x[2] - x[1])
else:
    ans += 1
    ans += (x[1] - x[0] + 1)//2
    ans += (x[2] - x[1])
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
l = list(map(int, input().split()))
ans = []

if N % 2 == 0:
    flag = 0
else:
    flag = 1

for ix,i in enumerate(l):
    if ix % 2 == flag:
        ans.append(i)
    else:
        ans.insert(0, i)
    
print(" ".join(map(str, ans)))

Fixed submission:
n = int(input())
a = list(map(str,input().split()))
b = a[::-1]
b = b[::2]

if n%2 == 0:
  c = a[::2]
else:
  c = a[1::2]
d = b+c

if n >= 2:
  print(' '.join(d))
else:
  print(a[0])
Buggy python submission (verdict: Runtime Error):
import math

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

rev = 10**9+7

if n-m==0:
    ans = 2 * math.factorial(n) * math.factorial(m)
elif (abs(n-m)==1):
    ans = 1 * math.factorial(n) : math.factorial(m)
else:
    ans = 0
print(ans%rev)


Fixed submission:
import math

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

rev = 10**9+7

if n-m==0:
    ans = 2 * math.factorial(n) * math.factorial(m)
elif (abs(n-m)==1):
    ans = 1 * math.factorial(n) * math.factorial(m)
else:
    ans = 0
print(ans%rev)
Buggy python submission (verdict: Runtime Error):
import math

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


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


def ans(x):
    can_div_c_count = x // c
    can_div_d_count = x // d
    can_div_lcm_count = x // lcm(c, d)
    return x - (can_div_c_count + can_div_d_count - can_div_lcm_count)


print(ans(b)-ans(a))


Fixed submission:
import fractions

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


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


def ans(x):
    can_div_c_count = x // c
    can_div_d_count = x // d
    can_div_lcm_count = x // lcm(c, d)
    return x - (can_div_c_count + can_div_d_count - can_div_lcm_count)


print(ans(b)-ans(a-1))
Buggy python submission (verdict: Time Limit Exceeded):
n, m = list(map(int, input().split(' ')))

bads = []
for i in range(m):
    bads.append(int(input()))

dp = [1, 1]
for i in range(2, n+1):
    dp.append(0)
    if i-1 not in bads:
        dp[i] += dp[i-1]
    if i-2 not in bads:
        dp[i] += dp[i-2]
    dp[i] %= 1000000007

print(dp[-1])


Fixed submission:
n, m = list(map(int, input().split(' ')))

bads = {}
for i in range(m):
    bads[int(input())] = None

dp = [1]
if 1 not in bads:
    dp.append(1)
else:
    dp.append(0)
for i in range(2, n+1):
    dp.append(0)
    if i-1 not in bads:
        dp[i] += dp[i-1]
    if i-2 not in bads:
        dp[i] += dp[i-2]
    dp[i] %= 1000000007

print(dp[-1])
Buggy python submission (verdict: Runtime Error):
from math import ceil


def main(N, A, B, C, D, E):
    loads = [A, B, C, D, E]
    min_val = min(loads)
    min_index = loads.index(min_val)

    res = min_index + ceil(N / min_val) + (5 - (min_index + 1))

    return res


if __name__ == "__main__":
    N = input()
    A = input()
    B = input()
    C = input()
    D = input()
    E = input()
    print(main(N, A, B, C, D, E))


Fixed submission:
from math import ceil


def main(N, A, B, C, D, E):
    loads = [A, B, C, D, E]
    min_val = min(loads)
    min_index = loads.index(min_val)

    res = min_index + ceil(N / min_val) + (5 - (min_index + 1))

    return res


if __name__ == "__main__":
    N = int(input())
    A = int(input())
    B = int(input())
    C = int(input())
    D = int(input())
    E = int(input())
    print(main(N, A, B, C, D, E))
Buggy python submission (verdict: Time Limit Exceeded):
def main(N, Q, S, lr_list):

    s_list = [0]
    for i in range(N):
        if i+1 < N and list(S)[i] == 'A' and list(S)[i+1] == 'C':
            s_list.append(s_list[i] + 1)
        else:
            s_list.append(s_list[i])

    res_list = []
    for lr in lr_list:
        l, r = lr
        l -= 1
        r -= 1
        res_list.append(s_list[r] - s_list[l])

    return res_list


if __name__ == "__main__":
    N, Q = list(map(int, input().split()))
    S = input()
    lr_list = []
    for _ in range(Q):
        lr_list.append(tuple(map(int, input().split())))
    res = main(N, Q, S, lr_list)
    for r in res:
        print(r)


Fixed submission:
def main(N, Q, S, lr_list):
    chars = list(S)

    s_list = [0]
    for i in range(N):
        if i+1 < N and chars[i] == 'A' and chars[i+1] == 'C':
            s_list.append(s_list[i] + 1)
        else:
            s_list.append(s_list[i])

    res_list = []
    for lr in lr_list:
        l, r = lr
        l -= 1
        r -= 1
        res_list.append(s_list[r] - s_list[l])

    return res_list


if __name__ == "__main__":
    N, Q = list(map(int, input().split()))
    S = input()
    lr_list = []
    for _ in range(Q):
        lr_list.append(tuple(map(int, input().split())))
    res = main(N, Q, S, lr_list)
    for r in res:
        print(r)

Buggy python submission (verdict: Time Limit Exceeded):
from math import ceil


def main(N, Q, S, lr_list):
    res = []
    for lr in lr_list:
        l, r = lr
        res.append(S[l-1:r].count("AC"))
    return res


if __name__ == "__main__":
    N, Q = list(map(int, input().split()))
    S = input()
    lr_list = []
    for _ in range(Q):
        lr_list.append(tuple(map(int, input().split())))
    res = main(N, Q, S, lr_list)
    for r in res:
        print(r)


Fixed submission:
def main(N, Q, S, lr_list):
    chars = list(S)

    s_list = [0]
    for i in range(N):
        if i+1 < N and chars[i] == 'A' and chars[i+1] == 'C':
            s_list.append(s_list[i] + 1)
        else:
            s_list.append(s_list[i])

    res_list = []
    for lr in lr_list:
        l, r = lr
        l -= 1
        r -= 1
        res_list.append(s_list[r] - s_list[l])

    return res_list


if __name__ == "__main__":
    N, Q = list(map(int, input().split()))
    S = input()
    lr_list = []
    for _ in range(Q):
        lr_list.append(tuple(map(int, input().split())))
    res = main(N, Q, S, lr_list)
    for r in res:
        print(r)