Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
S = input()

r = 0
g = 0
b = 0
cnt_S = []
for i, s in enumerate(S):
    if s == 'R':
        r += 1
    elif s == 'G':
        g += 1
    else:
        b += 1
    cnt_S.append([r, g, b])

ans = 0
for i in range(N-2):
    for j in range(i+1, N-1):
        if S[i] == 'R':
            if S[j] == 'G':
                ans += cnt_S[-1][2] - cnt_S[j][2]
                if 2 * j - i < N and S[j + j - i] == 'B':
                    ans -= 1
            if S[j] == 'B':
                ans += cnt_S[-1][1] - cnt_S[j][1]
                if 2 * j - i < N and S[j + j - i] == 'G':
                    ans -= 1
        elif S[i] == 'G':
            if S[j] == 'R':
                ans += cnt_S[-1][2] - cnt_S[j][2]
                if 2 * j - i < N and S[j + j - i] == 'B':
                    ans -= 1
            if S[j] == 'B':
                ans += cnt_S[-1][0] - cnt_S[j][0]
                if 2 * j - i < N and S[j + j - i] == 'R':
                    ans -= 1
        else:
            if S[j] == 'R':
                ans += cnt_S[-1][1] - cnt_S[j][1]
                if 2 * j - i < N and S[j + j - i] == 'G':
                    ans -= 1
            if S[j] == 'G':
                ans += cnt_S[-1][0] - cnt_S[j][0]
                if 2 * j - i < N and S[j + j - i] == 'R':
                    ans -= 1
print(ans)





Fixed submission:
N = int(input())
S = input()

r = 0
g = 0
b = 0
cnt_S = []
for i, s in enumerate(S):
    if s == 'R':
        r += 1
    elif s == 'G':
        g += 1
    else:
        b += 1
    cnt_S.append([r, g, b])

ans = 0
for i in range(N-2):
    for j in range(i+1, N-1):
        if S[i] == 'R':
            if S[j] == 'G':
                ans += cnt_S[-1][2] - cnt_S[j][2]
                if 2 * j - i < N and S[j + j - i] == 'B':
                    ans -= 1
            if S[j] == 'B':
                ans += cnt_S[-1][1] - cnt_S[j][1]
                if 2 * j - i < N and S[j + j - i] == 'G':
                    ans -= 1
        elif S[i] == 'G':
            if S[j] == 'R':
                ans += cnt_S[-1][2] - cnt_S[j][2]
                if 2 * j - i < N and S[j + j - i] == 'B':
                    ans -= 1
            if S[j] == 'B':
                ans += cnt_S[-1][0] - cnt_S[j][0]
                if 2 * j - i < N and S[j + j - i] == 'R':
                    ans -= 1
        else:
            if S[j] == 'R':
                ans += cnt_S[-1][1] - cnt_S[j][1]
                if 2 * j - i < N and S[j + j - i] == 'G':
                    ans -= 1
            if S[j] == 'G':
                ans += cnt_S[-1][0] - cnt_S[j][0]
                if 2 * j - i < N and S[j + j - i] == 'R':
                    ans -= 1
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
# N = int(input())
def cmb(n, r, mod):
    x = 1
    for i in range(r):
        x = x * (n-i) % mod
    return (x * g2[r]) % mod


mod = 10**9+7 #出力の制限
N = 10**6
g1 = [1, 1] # 元テーブル
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル


for i in range(2, N + 1):
    g1.append((g1[-1] * i) % mod)
    inverse.append((-inverse[mod % i] * (mod//i)) % mod)
    g2.append((g2[-1] * inverse[-1]) % mod)

def pow_(x, n):
    if n == 0:
        return 1

    k = 1
    while n > 1:
        if n % 2 != 0:
            k *= x
        x *= x
        n //= 2

    return (k * x) % MOD

n, a, b = [int(i) for i in input().split()]
MOD = 10 ** 9 + 7
n_num = pow_(2, n) - 1
a_num = cmb(n, a, MOD)
b_num = cmb(n, b, MOD)
print((n_num - a_num - b_num) % MOD)


Fixed submission:
# N = int(input())
def cmb(n, r, mod):
    x = 1
    for i in range(r):
        x = x * (n-i) % mod
    return (x * g2[r]) % mod


mod = 10**9+7 #出力の制限
N = 2*10**5
g1 = [1, 1] # 元テーブル
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル


for i in range(2, N + 1):
    g1.append((g1[-1] * i) % mod)
    inverse.append((-inverse[mod % i] * (mod//i)) % mod)
    g2.append((g2[-1] * inverse[-1]) % mod)

def pow_(x, n):
    if n == 0:
        return 1

    k = 1
    while n > 1:
        if n % 2 != 0:
            k = (k * x) % MOD
        x = (x * x) % MOD
        n //= 2

    return (k * x) % MOD

n, a, b = [int(i) for i in input().split()]
MOD = 10 ** 9 + 7
n_num = pow_(2, n) - 1
a_num = cmb(n, a, MOD)
b_num = cmb(n, b, MOD)
print((n_num - a_num - b_num) % MOD)
Buggy python submission (verdict: Time Limit Exceeded):
N, K = [int(_) for _ in input().split()]
P = [int(_) for _ in input().split()]
E = [(p + 1)/2 for p in P]
ans = 0
for i in range(N-K+1):
    ans = max(ans, sum(E[i: K+i]))
print(ans)



Fixed submission:
N, K = [int(_) for _ in input().split()]
P = [int(_) for _ in input().split()]
E = [(p + 1)/2 for p in P]
sumE = sum(E[0:K])
ans = sumE
for i in range(1, N-K+1):
    sumE = sumE - E[i-1] + E[i+K-1]
    ans = max(ans, sumE)
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import itertools
# H, W = [int(_) for _ in input().split()]
N = int(input())

comb = itertools.combinations_with_replacement([str(i) for i in range(1, 10)], 2)
count = 0
for c in comb:
    A = c[0]
    B = c[1]
    count_1 = 0
    count_2 = 0
    for i in range(1, N+1):
        if str(i)[0] == A and str(i)[-1] == B:
            count_1 += 1
        elif str(i)[0] == B and str(i)[-1] == A:
            count_2 += 1
    if A == B:
        count += count_1 ** 2
    else:
        count += count_1 * count_2 * 2
print(count)


Fixed submission:
import itertools
# H, W = [int(_) for _ in input().split()]
N = int(input())

comb = itertools.combinations_with_replacement([str(i) for i in range(1, 10)], 2)
count = 0
for c in comb:
    A = c[0]
    B = c[1]
    count_1 = 0
    count_2 = 0
    for i in range(1, N+1):
        if str(i)[0] == A and str(i)[-1] == B:
            count_1 += 1
        elif str(i)[0] == B and str(i)[-1] == A:
            count_2 += 1
    if A == B:
        count += count_1 ** 2
    else:
        count += count_1 * count_2 * 2
print(count)
Buggy python submission (verdict: Time Limit Exceeded):
A, B, K = [int(_) for _ in input().split()]
for i in range(K):
    if A >= 1:
        A -= 1
    elif B >= 1:
        B -= 1
print(A, B)


Fixed submission:
A, B, K = [int(_) for _ in input().split()]
if A >= K:
    print(A-K, B)
else:
    print(0, max(0, B-(K-A)))
Buggy python submission (verdict: Runtime Error):
import math
A, B = [int(_) for _ in input().split()]
print(A * B // math.gcd(A, B))


Fixed submission:
import fractions
A, B = [int(_) for _ in input().split()]
print(A * B // fractions.gcd(A, B))
Buggy python submission (verdict: Runtime Error):
import sys
import math

N = int(input())
# N, K = [int(i) for i in input().split()]

if N % 2 == 1:
    print(0)
    sys.exit(0)

count = 0
digit = math.ceil(math.log(N, 5))
for i in range(1, digit+1):
    x = 5 ** i
    count += (N // (x * 2))
print(count)


Fixed submission:
import sys
import math

N = int(input())
# N, K = [int(i) for i in input().split()]
if N == 0:
    print(0)
    sys.exit(0)
if N % 2 == 1:
    print(0)
    sys.exit(0)

count = 0
digit = math.ceil(math.log(N, 5))
for i in range(1, digit+1):
    x = 5 ** i
    count += (N // (x * 2))
print(count)
Buggy python submission (verdict: Runtime Error):
A = [int(_) for _ in input().split()]

if sum(A) >= 22:
    print('bust')
else:
    print('win'

Fixed submission:
A = [int(_) for _ in input().split()]

if sum(A) >= 22:
    print('bust')
else:
    print('win')
Buggy python submission (verdict: Time Limit Exceeded):
import sys
from functools import lru_cache
# N = int(input())
X, Y = [int(i) for i in input().split()]

sys.setrecursionlimit(100000)


@lru_cache(maxsize=None)
def solve(x, y):
    if x <= 0 or y <= 0:
        return 0
    if (x, y) == (1, 2) or (x, y) == (2, 1):
        return 1
    return (solve(x-1, y-2) + solve(x-2, y-1)) % (10**9+7)


print(solve(X, Y))



Fixed submission:
import sys
# N = int(input())
X, Y = [int(i) for i in input().split()]
def cmb(n, r, mod):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod

mod = 10**9+7 #出力の制限
N = 10**6
g1 = [1, 1] # 元テーブル
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル

for i in range( 2, N + 1 ):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )

a_3 = 2 * Y - X
b_3 = 2 * X - Y
if a_3 % 3 != 0 or b_3 % 3 != 0 or a_3 < 0 or b_3 < 0:
    print(0)
    sys.exit(0)
a = a_3//3
b = b_3//3
print(cmb(a+b,a,mod))

Buggy python submission (verdict: Time Limit Exceeded):
import sys
from functools import lru_cache
# N = int(input())
X, Y = [int(i) for i in input().split()]

sys.setrecursionlimit(100000)


# @lru_cache(maxsize=None)
def solve(x, y):
    if x <= 0 or y <= 0:
        return 0
    if (x, y) == (1, 2) or (x, y) == (2, 1):
        return 1
    return (solve(x-1, y-2) + solve(x-2, y-1)) % (10**9+7)


print(solve(X, Y))



Fixed submission:
import sys
# N = int(input())
X, Y = [int(i) for i in input().split()]
def cmb(n, r, mod):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod

mod = 10**9+7 #出力の制限
N = 10**6
g1 = [1, 1] # 元テーブル
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル

for i in range( 2, N + 1 ):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )

a_3 = 2 * Y - X
b_3 = 2 * X - Y
if a_3 % 3 != 0 or b_3 % 3 != 0 or a_3 < 0 or b_3 < 0:
    print(0)
    sys.exit(0)
a = a_3//3
b = b_3//3
print(cmb(a+b,a,mod))
Buggy python submission (verdict: Runtime Error):

N, K = [int(_) for _ in input().split()]
h = [int(_) for _ in input().split()]
print(len([i for i in h if 

Fixed submission:
N, K = [int(i) for i in input().split()]
H = [int(i) for i in input().split()]
cnt = 0
for h in H:
    if h >= K:
        cnt += 1
print(cnt)
Buggy python submission (verdict: Time Limit Exceeded):
def gcd(a, b):
    if a > b:
        a, b = b, a
    if a == 0:
        return b
    else:
        return gcd(a, b % a)

# N = int(input())
A, B = [int(_) for _ in input().split()]

gcd_ab = gcd(A, B)
cds = []
for k in range(1, gcd_ab + 1):
    if gcd_ab % k == 0:
        cds.append(k)

ans = []
for cd in cds[1:]:
    for a in ans:
        if cd % a == 0:
            break
    else:
        ans.append(cd)

print(len(ans) + 1)


Fixed submission:
import math
def gcd(a, b):
    if a > b:
        a, b = b, a
    if a == 0:
        return b
    else:
        return gcd(a, b % a)

# N = int(input())
A, B = [int(_) for _ in input().split()]

gcd_ab = gcd(A, B)
cds = []
for k in range(1, math.ceil(math.sqrt(gcd_ab)) + 1):
    if gcd_ab % k == 0:
        cds.append(k)
        cds.append(gcd_ab // k)
cds = list(set(cds))
cds.sort()

ans = []
for cd in cds[1:]:
    for a in ans:
        if cd % a == 0:
            break
    else:
        ans.append(cd)

print(len(ans) + 1)

Buggy python submission (verdict: Time Limit Exceeded):
def gcd(a, b):
    if a > b:
        a, b = b, a
    if a == 0:
        return b
    else:
        return gcd(a, b % a)

# N = int(input())
A, B = [int(_) for _ in input().split()]

gcd_ab = gcd(A, B)
cds = []
for k in range(1, gcd_ab + 1):
    if gcd_ab % k == 0:
        cds.append(k)

ans = []
for cd in cds[1:]:
    for a in ans:
        if cd % a == 0:
            break
    else:
        ans.append(cd)

print(len(ans) + 1)


Fixed submission:
import math
def gcd(a, b):
    if a > b:
        a, b = b, a
    if a == 0:
        return b
    else:
        return gcd(a, b % a)

# N = int(input())
A, B = [int(_) for _ in input().split()]

gcd_ab = gcd(A, B)
cds = []
for k in range(1, math.ceil(math.sqrt(gcd_ab)) + 1):
    if gcd_ab % k == 0:
        cds.append(k)
        cds.append(gcd_ab // k)
cds = list(set(cds))
cds.sort()

ans = []
for cd in cds[1:]:
    for a in ans:
        if cd % a == 0:
            break
    else:
        ans.append(cd)

print(len(ans) + 1)
Buggy python submission (verdict: Runtime Error):
# N = int(input())
N, M = [int(i) for i in input().split()]
key = []
for i in range(M):
    a, b = [int(_) for _ in input().split()]
    cs = [int(_) for _ in input().split()]
    s = 0
    for c in cs:
        c -= 1
        s |= 1 << c
    key.append([s, a])

INF = 10**9
dp = [INF for i in range(N**2)]
dp[0] = 0
for i in range(N**2):
    for j in range(M):
        t = i | key[j][0]
        cost = key[j][1]
        dp[t] = min(dp[t], dp[i] + cost)
ans = dp[-1]
if ans == INF:
    print(-1)
else:
    print(ans)



Fixed submission:
# N = int(input())
N, M = [int(i) for i in input().split()]
key = []
for i in range(M):
    a, b = [int(_) for _ in input().split()]
    cs = [int(_) for _ in input().split()]
    s = 0
    for c in cs:
        c -= 1
        s |= 1 << c
    key.append([s, a])

INF = 10**9
dp = [INF for i in range(2**N)]
dp[0] = 0
for i in range(2**N):
    for j in range(M):
        t = i | key[j][0]
        cost = key[j][1]
        dp[t] = min(dp[t], dp[i] + cost)
ans = dp[-1]
if ans == INF:
    print(-1)
else:
    print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
S = input()
ans = 0
for i in range(1, N):
    cnt = 0
    for j in range(N-i):
        if S[j] == S[i+j]:
            cnt += 1
            if cnt == i:
                ans = max(ans, i)
                break
        else:
            ans = max(ans, cnt)
            cnt = 0
    ans = max(ans, cnt)
print(ans)


Fixed submission:
N = int(input())
S = input()
ans = 0
for i in range(1, N):
    cnt = 0
    for j in range(N-i):
        if S[j] == S[i+j]:
            cnt += 1
            if cnt == i:
                ans = max(ans, i)
                break
        else:
            ans = max(ans, cnt)
            cnt = 0
    ans = max(ans, cnt)
print(ans)

Buggy python submission (verdict: Runtime Error):
N = int(input())
S = input()
ans = 0
for i in range(1, N):
    # cnt = 0
    pass
    for j in range(N-i):
    #     if S[j] == S[i+j]:
    #         cnt += 1
    #     else:
    #         ans = max(ans, min(cnt, i))
    #         cnt = 0
    # ans = max(ans, min(cnt, i))
    pass
print(ans)


Fixed submission:
N = int(input())
S = input()
ans = 0
for i in range(1, N):
    cnt = 0
    for j in range(N-i):
        if S[j] == S[i+j]:
            cnt += 1
            if cnt == i:
                ans = max(ans, i)
                break
        else:
            ans = max(ans, cnt)
            cnt = 0
    ans = max(ans, cnt)
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
S = input()
ans = 0
for i in range(1, N):
    cnt = 0
    for j in range(N-i):
        if S[j] == S[i+j]:
            cnt += 1
        else:
            ans = max(ans, min(cnt, i))
            cnt = 0
    ans = max(ans, min(cnt, i))
print(ans)

Fixed submission:
N = int(input())
S = input()
ans = 0
for i in range(1, N):
    cnt = 0
    for j in range(N-i):
        if S[j] == S[i+j]:
            cnt += 1
            if cnt == i:
                ans = max(ans, i)
                break
        else:
            ans = max(ans, cnt)
            cnt = 0
    ans = max(ans, cnt)
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n, q = [int(i) for i in input().split()]
g = [[] for i in range(n)]

for i in range(n-1):
    a, b = [int(_) for _ in input().split()]
    g[a-1].append(b)
c = [0 for i in range(n)]
for i in range(q):
    p, x = [int(_) for _ in input().split()]
    c[p-1] += x

q = [[1, c[0]]]
while len(q) != 0:
    p = q.pop(0)
    for i in g[p[0]-1]:
        c[i-1] += p[1]
        q.append([i, c[i-1]])

print(*c)


Fixed submission:
from collections import deque
n, q = [int(i) for i in input().split()]
g = [[] for i in range(n)]

for i in range(n-1):
    a, b = [int(_) for _ in input().split()]
    g[a-1].append(b)
c = [0 for i in range(n)]
for i in range(q):
    p, x = [int(_) for _ in input().split()]
    c[p-1] += x

q = deque([[1, c[0]]])
while len(q) != 0:
    p = q.popleft()
    for i in g[p[0]-1]:
        c[i-1] += p[1]
        q.append([i, c[i-1]])

print(*c)
Buggy python submission (verdict: Time Limit Exceeded):
import bisect
n = int(input())
c = []
for i in range(n):
    a = int(input())
    idx = bisect.bisect_left(c,a)
    if idx == 0:
        c.insert(idx, a)
    else:
        c[idx-1] = a
print(len(c))

Fixed submission:
import bisect
from collections import deque
n = int(input())
c = deque()
for i in range(n):
    a = int(input())
    idx = bisect.bisect_left(c,a)
    if idx == 0:
        c.appendleft(a)
    else:
        c[idx-1] = a
print(len(c))
Buggy python submission (verdict: Runtime Error):
l, r = [int(i) for i in input().split()]

if r - l + 1 >= 2019:
    print(0)
else:
    ans = 2018
    for i in range(l, r+1):
        for j in range(i+1, r+1):
            ans = min(ans, (i*j)%2019)
print(ans)

Fixed submission:
l, r = [int(i) for i in input().split()]

if r - l + 1 >= 2019:
    print(0)
else:
    ans = 2018
    for i in range(l, r+1):
        for j in range(i+1, r+1):
            ans = min(ans, (i*j) % 2019)
    print(ans)
Buggy python submission (verdict: Runtime Error):
n = int(input())
s = input()

if "." not in s or "#" not in s:
    print(0)
else:
    ans = len(s)

    s = s[s.find("#"):n-s[::-1].find(".")]
    cnt_b = [0 for i in range(len(s))]
    cnt = 0
    for i in range(len(s)):
        if s[i] == "#":
            cnt += 1
        cnt_b[i] = cnt
    ans = min(ans, len(s)-cnt_b[-1])
    for i in range(len(s)):
        ans = min(ans, cnt_b[i] + (len(s)-cnt_b[-1])-(i+1-cnt_b[i]))
    print(ans)


Fixed submission:
n = int(input())
s = input()

if "." not in s or "#" not in s:
    print(0)
else:
    ans = len(s)

    s = s[s.find("#"):n-s[::-1].find(".")]
    if s == "":
        print(0)
    else:
        cnt_b = [0 for i in range(len(s))]
        cnt = 0
        for i in range(len(s)):
            if s[i] == "#":
                cnt += 1
            cnt_b[i] = cnt
        ans = min(ans, len(s)-cnt_b[-1])
        for i in range(len(s)):
            ans = min(ans, cnt_b[i] + (len(s)-cnt_b[-1])-(i+1-cnt_b[i]))
        print(ans)
Buggy python submission (verdict: Runtime Error):
n, k = [int(i) for i in input().split()]
s = [0,1] + [int(i) for i in list(input())] + [1,0]
down = [i for i in range(n+3) if s[i] == 1 and s[i+1] == 0]
up = [i for i in range(n+3) if s[i] == 0 and s[i+1] == 1]
#print(s)
#print(down)
#print(up)
if k >= len(up):
  ans = n
else:
  if down[k] - up[0] - 1 > ans:
    ans = down[k] - up[0] - 1
  for i in range(1,len(up)-k-1):
    if down[i + k] - up[i] > ans:
      ans = down[i + k] - up[i]
  if down[len(up)-1] - up[len(up)-k -1] - 1 > ans:
    ans = down[len(up)-1] - up[len(up)-k -1] - 1
print(ans)

Fixed submission:
n, k = [int(i) for i in input().split()]
s = [0,1] + [int(i) for i in list(input())] + [1,0]
down = [i for i in range(n+3) if s[i] == 1 and s[i+1] == 0]
up = [i for i in range(n+3) if s[i] == 0 and s[i+1] == 1]
#print(s)
#print(down)
#print(up)
ans = 1
if k >= len(up):
  ans = n
else:
  if down[k] - up[0] - 1 > ans:
    ans = down[k] - up[0] - 1
  for i in range(1,len(up)-k-1):
    if down[i + k] - up[i] > ans:
      ans = down[i + k] - up[i]
  if down[len(up)-1] - up[len(up)-k -1] - 1 > ans:
    ans = down[len(up)-1] - up[len(up)-k -1] - 1
print(ans)

Buggy python submission (verdict: Runtime Error):
n, k = [int(i) for i in input().split()]
s = [0,1] + [int(i) for i in list(input())] + [1,0]
down = [i for i in range(n+3) if s[i] == 1 and s[i+1] == 0]
up = [i for i in range(n+3) if s[i] == 0 and s[i+1] == 1]
#print(s)
#print(down)
#print(up)
ans = 1
if down[k] - up[0] - 1 > ans:
  ans = down[k] - up[0] - 1
for i in range(1,len(up)-k-1):
  if down[i + k] - up[i] > ans:
    ans = down[i + k] - up[i]
if down[len(up)-1] - up[len(up)-k -1] - 1 > ans:
  ans = down[len(up)-1] - up[len(up)-k -1] - 1
print(ans)

Fixed submission:
n, k = [int(i) for i in input().split()]
s = [0,1] + [int(i) for i in list(input())] + [1,0]
down = [i for i in range(n+3) if s[i] == 1 and s[i+1] == 0]
up = [i for i in range(n+3) if s[i] == 0 and s[i+1] == 1]
#print(s)
#print(down)
#print(up)
ans = 1
if k >= len(up):
  ans = n
else:
  if down[k] - up[0] - 1 > ans:
    ans = down[k] - up[0] - 1
  for i in range(1,len(up)-k-1):
    if down[i + k] - up[i] > ans:
      ans = down[i + k] - up[i]
  if down[len(up)-1] - up[len(up)-k -1] - 1 > ans:
    ans = down[len(up)-1] - up[len(up)-k -1] - 1
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import copy
n = int(input())
c = [n, 0, 0, 0, 0]
a = []
for i in range(5):
  a.append(int(input()))
cnt = 0
sub = [0] * 5
add = [0] * 5
add_n =[0] * 6
while True:
  for i in range(5):
    c[i] = c[i] + add[i] - sub[i]
    if c[i] > a[i]:
      sub[i] = a[i]
      add_n[i+1] = a[i]
    else:
      sub[i] = c[i]
      add_n[i+1] = c[i]
  add = copy.copy(add_n)
  cnt += 1
  if sum(c) == 0:
    print(cnt-1)
    break

Fixed submission:
n = int(input())
a = []
for i in range(5):
  a.append(int(input()))
neck = min(a)
if n % neck == 0:
  print(int(n/neck) + 4)
else:
  print(int(n / neck) + 5)
Buggy python submission (verdict: Time Limit Exceeded):
n, q = [int(i) for i in input().split()]
s = input()
l = [0] * q
r = [0] * q
ans = ""
table = [1 if s[i:i+2] == "AC" else 0 for i in range(n)]   
for i in range(q):
  l[i], r[i] = [int(j) for j in input().split()]
  ans = ans+str(sum(table[l[i]-1:r[i]-1]))+"\n"
print(ans)

Fixed submission:
n, q = [int(i) for i in input().split()]
s = input()
ans = ""
table = [0] * n
cnt = 0
for i in range(n-1):
  if s[i:i+2] == "AC":
    cnt += 1
  table[i+1] = cnt
for i in range(q):
  l, r = [int(j) for j in input().split()]
  print(table[r-1] - table[l-1])

Buggy python submission (verdict: Time Limit Exceeded):
n, q = [int(i) for i in input().split()]
s = input()
l = [0] * q
r = [0] * q
ans = ""
for i in range(q):
  l[i], r[i] = [int(j) for j in input().split()]
  t = s[l[i]-1:r[i]]
  cnt = 0
  for k in range(len(t)-1):
    if t[k:k+2] == "AC":
      cnt += 1
      k += 1
  ans = ans+str(cnt)+"\n"
print(ans)

Fixed submission:
n, q = [int(i) for i in input().split()]
s = input()
ans = ""
table = [0] * n
cnt = 0
for i in range(n-1):
  if s[i:i+2] == "AC":
    cnt += 1
  table[i+1] = cnt
for i in range(q):
  l, r = [int(j) for j in input().split()]
  print(table[r-1] - table[l-1])

Buggy python submission (verdict: Time Limit Exceeded):
n, q = [int(i) for i in input().split()]
s = input()
l = [0] * q
r = [0] * q
ans = ""
for i in range(q):
  l[i], r[i] = [int(j) for j in input().split()]
  ans = ans+str(s[l[i]-1:r[i]].count("AC"))+"\n"
print(ans)
  
  

Fixed submission:
n, q = [int(i) for i in input().split()]
s = input()
ans = ""
table = [0] * n
cnt = 0
for i in range(n-1):
  if s[i:i+2] == "AC":
    cnt += 1
  table[i+1] = cnt
for i in range(q):
  l, r = [int(j) for j in input().split()]
  print(table[r-1] - table[l-1])

Buggy python submission (verdict: Time Limit Exceeded):
n, q = [int(i) for i in input().split()]
s = input()
l = [0] * q
r = [0] * q
for i in range(q):
  l[i], r[i] = [int(j) for j in input().split()]
for i in range(q):
  t = s[l[i]-1:r[i]]
  print(t.count("AC"))
  
  

Fixed submission:
n, q = [int(i) for i in input().split()]
s = input()
ans = ""
table = [0] * n
cnt = 0
for i in range(n-1):
  if s[i:i+2] == "AC":
    cnt += 1
  table[i+1] = cnt
for i in range(q):
  l, r = [int(j) for j in input().split()]
  print(table[r-1] - table[l-1])

Buggy python submission (verdict: Time Limit Exceeded):
n, q = [int(i) for i in input().split()]
s = input()
l = [0] * q
r = [0] * q
for i in range(q):
  l[i], r[i] = [int(j) for j in input().split()]
for i in range(q):
  print(s[l[i]-1:r[i]].count("AC"))
  

Fixed submission:
n, q = [int(i) for i in input().split()]
s = input()
ans = ""
table = [0] * n
cnt = 0
for i in range(n-1):
  if s[i:i+2] == "AC":
    cnt += 1
  table[i+1] = cnt
for i in range(q):
  l, r = [int(j) for j in input().split()]
  print(table[r-1] - table[l-1])