Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
from functools import reduce
from math import ceil

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

bottom_n_list = [(0, 0) for _ in range(n + 1)]
bottom_n_list[n] = (a[n], a[n])
for i in range(n-1, -1, -1):
    leaf_num = a[i]
    min_a_node_num = ceil(bottom_n_list[i + 1][0] / 2)
    max_a_node_num = min(bottom_n_list[i + 1][1], 2 ** i - leaf_num)
    if max_a_node_num < min_a_node_num:
        print(-1)
        exit()
    bottom_n_list[i] = (min_a_node_num + leaf_num, max_a_node_num + leaf_num)

top_n_list = [0]*(n+1)
if 1 < bottom_n_list[0][0] or bottom_n_list[0][1] < 1:
    print(-1)
    exit()
top_n_list[0] = 1
for i in range(1, n+1):
    top_n_list[i] = min(bottom_n_list[i][1], (top_n_list[i-1]-a[i-1])*2)


ans = reduce(lambda a, b: a+b, top_n_list)
print(ans)

Fixed submission:
from math import ceil

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

bottom_n_list = [(0, 0) for _ in range(n + 1)]
bottom_n_list[n] = (a[n], a[n])
for i in range(n-1, -1, -1):
    leaf_num = a[i]
    min_a_node_num = ceil(bottom_n_list[i + 1][0] / 2)
    max_a_node_num = min(bottom_n_list[i + 1][1], 2 ** i - leaf_num)
    if max_a_node_num < min_a_node_num:
        print(-1)
        exit()
    bottom_n_list[i] = (min_a_node_num + leaf_num, max_a_node_num + leaf_num)

top_n_list = [0]*(n+1)
if 1 < bottom_n_list[0][0] or bottom_n_list[0][1] < 1:
    print(-1)
    exit()
top_n_list[0] = 1
ans = 1
for i in range(1, n+1):
    top_n_list[i] = min(bottom_n_list[i][1], (top_n_list[i-1]-a[i-1])*2)
    ans += top_n_list[i]

print(ans)
Buggy python submission (verdict: Runtime Error):
from math import gcd

n = int(input())
MOD = 10**9+7
p_map = {}
n_map = {}
z_map = 0
for _ in range(n):
    ab = list(map(int, input().split()))
    ab_gcd = gcd(ab[0], ab[1])
    a = ab[0]//ab_gcd
    b = ab[1]//ab_gcd
    key = "{}_{}".format(a, b)
    if a*b > 0:
        if key not in p_map:
            p_map[key] = 1
        else:
            p_map[key] += 1
    elif a*b == 0:
        z_map += 1
    else:
        if key not in n_map:
            n_map[key] = 1
        else:
            n_map[key] += 1

ans = 1
for k, v in p_map.items():
    
    a = int(k.split("_")[0])
    b = int(k.split("_")[1])
    n_num = 0
    key_a = "{}_{}".format(-b, a)
    key_b = "{}_{}".format(b, -a)
    if key_a in n_map:
        n_num += n_map.pop(key_a)
    if key_b in n_map:
        n_num += n_map.pop(key_b)
    res = 0
    res += pow(2, v, MOD)-1
    if n_num > 0:
        res += pow(2, n_num, MOD)-1
    res += 1
    ans *= res
    ans %= MOD

n_num = sum(n_map.values())
ans *= pow(2, n_num, MOD)
ans %= MOD
ans -= 1

if z_map > 0:
    ans += z_map
ans %= MOD
print(ans)

Fixed submission:
from math import gcd

n = int(input())
MOD = 10**9+7
p_map = {}
n_map = {}

p_zero_map = 0
n_zero_map = 0
z_map = 0
for _ in range(n):
    ab = list(map(int, input().split()))
    ab_gcd = gcd(ab[0], ab[1])
    if ab_gcd == 0:
        ab_gcd = 1
    a = ab[0]//ab_gcd
    b = ab[1]//ab_gcd

    if (a > 0 and b > 0) or (a < 0 and b < 0):
        if a < 0:
            a = -a
            b = -b
        key = "{}_{}".format(a, b)
        if key not in p_map:
            p_map[key] = 1
        else:
            p_map[key] += 1
    elif a == 0 and b == 0:
        z_map += 1
    elif a == 0 and b != 0:
        n_zero_map += 1
    elif b == 0 and a != 0:
        p_zero_map += 1
    else:
        if b < 0:
            a = -a
            b = -b
        key = "{}_{}".format(a, b)
        if key not in n_map:
            n_map[key] = 1
        else:
            n_map[key] += 1

ans = 1
for k, v in p_map.items():
    a = int(k.split("_")[0])
    b = int(k.split("_")[1])
    n_num = 0
    key_a = "{}_{}".format(-b, a)
    if key_a in n_map:
        n_num += n_map.pop(key_a)
    res = 0
    res += pow(2, v, MOD)-1
    if n_num > 0:
        res += pow(2, n_num, MOD)-1
    res += 1
    ans *= res
    ans %= MOD

n_num = sum(n_map.values())
if n_num > 0:
    ans *= pow(2, n_num, MOD)
    ans %= MOD

res = 0
if p_zero_map > 0 and n_zero_map > 0:
    res = pow(2, p_zero_map, MOD)-1 + pow(2, n_zero_map, MOD)-1
    res += 1
    res %= MOD
elif p_zero_map > 0 and n_zero_map == 0:
    res = pow(2, p_zero_map, MOD)
elif p_zero_map == 0 and n_zero_map > 0:
    res = pow(2, n_zero_map, MOD)
if res > 0:
    ans *= res
    ans %= MOD


if z_map > 0:
    ans += z_map
ans -= 1
ans %= MOD
print(ans)
Buggy python submission (verdict: Runtime Error):
import numpy as np
N, M, K = map(int, input().split())
MOD = 998244353
dp = np.array([0]*(K+1))
dp[0] = M

for _ in range(N-1):
    dp = dp + np.append(0, dp)[:K+1]*(M-1)%MOD
    dp %= MOD
print(sum(dp[:K+1])%MOD)

Fixed submission:
import numpy as np
N, M, K = map(int, input().split())
MOD = 998244353

def prepare(n, MOD):
    """
    nCr mod MOD
    :param n:
    :param MOD:
    :return:
    """
    facts = [1]*(n+1)
    for i in range(1, n+1):
        facts[i] = facts[i-1]*i%MOD
    invs = [1]*(n+1)
    invs[n] = pow(facts[n], MOD-2, MOD)
    for i in range(0, n)[::-1]:
        invs[i] = invs[i+1] * (i+1) % MOD
    return facts, invs

facts, invs = prepare(N, MOD)
ans = 0
col = M*(M-1)**(N-K-1)%MOD
for i in range(K+1)[::-1]:
    combi = facts[N-1]*invs[N-1-i]*invs[i]
    ans += col*combi
    ans %= MOD
    col *= (M - 1)
    col %= MOD
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
s = input()
n = len(s)
mod = 2019

cum = [0]*n
cum[n-1] = int(s[-1]) % mod
d = 10
for i in range(0, n-1)[::-1]:
    a = int(s[i]) * d % mod
    cum[i] = (cum[i+1]+a) % mod
    d *= 10
cnt = [0]*mod

ans = 0
for i in cum[::-1]:
    ans += cnt[i]
    cnt[i] += 1
    if i == 0:
        ans += 1
print(ans)

Fixed submission:
s = input()
n = len(s)
mod = 2019

cum = [0]*n
cum[n-1] = int(s[-1]) % mod
d = [1]*n
for i in range(n-1)[::-1]:
    d[i] = d[i+1]*10%mod

for i in range(0, n-1)[::-1]:
    a = int(s[i]) * d[i] % mod
    cum[i] = (cum[i+1]+a) % mod
cnt = [0]*mod

ans = 0
for i in cum[::-1]:
    ans += cnt[i]
    cnt[i] += 1
    if i == 0:
        ans += 1
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
s = input()
n = len(s)
mod = 2019
dp = [0 for i in range(n)]
for i,c in enumerate(s):
    dp[i] = int(c) % mod

cum = [0]*n
cum[0] = dp[0]
cum[n-1] = int(s[-1]) % mod
d = 10
for i in range(0, n-1)[::-1]:
    a = int(s[i])* d % mod
    cum[i] = (cum[i+1]+a) % mod
    d *= 10
cnt = [0]*mod

ans = 0
for i in cum[::-1]:
    ans += cnt[i]
    cnt[i] += 1
    if i == 0:
        ans += 1
print(ans)

Fixed submission:
s = input()
n = len(s)
mod = 2019

cum = [0]*n
cum[n-1] = int(s[-1]) % mod
d = [1]*n
for i in range(n-1)[::-1]:
    d[i] = d[i+1]*10%mod

for i in range(0, n-1)[::-1]:
    a = int(s[i]) * d[i] % mod
    cum[i] = (cum[i+1]+a) % mod
cnt = [0]*mod

ans = 0
for i in cum[::-1]:
    ans += cnt[i]
    cnt[i] += 1
    if i == 0:
        ans += 1
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
s = input()
n = len(s)
mod = 2019
dp = [0 for i in range(n)]
for i,c in enumerate(s):
    dp[i] = int(c) % mod

cum = [0]*n
cum[0] = dp[0]
cum[n-1] = int(s[-1]) % mod
d = 10
for i in range(0, n-1)[::-1]:
    a = int(s[i])* d % mod
    cum[i] = (cum[i+1]+a) % mod
    d *= 10
cnt = [0]*mod

ans = 0
for i in cum[::-1]:
    ans += cnt[i]
    cnt[i] += 1
    if i == 0:
        ans += 1
print(ans)

Fixed submission:
s = input()
n = len(s)
mod = 2019

cum = [0]*n
cum[n-1] = int(s[-1]) % mod
d = [1]*n
for i in range(n-1)[::-1]:
    d[i] = d[i+1]*10%mod

for i in range(0, n-1)[::-1]:
    a = int(s[i]) * d[i] % mod
    cum[i] = (cum[i+1]+a) % mod
cnt = [0]*mod

ans = 0
for i in cum[::-1]:
    ans += cnt[i]
    cnt[i] += 1
    if i == 0:
        ans += 1
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
s = input()
n = len(s)
mod = 2019
dp = [0 for i in range(n)]
for i,c in enumerate(s):
    dp[i] = int(c) % mod

cum = [0]*n
cum[0] = dp[0]
cum[n-1] = int(s[-1]) % mod
for i in range(0, n-1)[::-1]:
    a = int(s[i])*10**(n-1-i) % mod
    cum[i] = (cum[i+1]+a) % mod
cnt = [0]*mod

ans = 0
for i in cum[::-1]:
    ans += cnt[i]
    cnt[i] += 1
    if i == 0:
        ans += 1
print(ans)

Fixed submission:
s = input()
n = len(s)
mod = 2019

cum = [0]*n
cum[n-1] = int(s[-1]) % mod
d = [1]*n
for i in range(n-1)[::-1]:
    d[i] = d[i+1]*10%mod

for i in range(0, n-1)[::-1]:
    a = int(s[i]) * d[i] % mod
    cum[i] = (cum[i+1]+a) % mod
cnt = [0]*mod

ans = 0
for i in cum[::-1]:
    ans += cnt[i]
    cnt[i] += 1
    if i == 0:
        ans += 1
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N, X, Y = map(int, input().split())

dp = [[0]*N for _ in range(N)]
for i in range(N):
    for j in range(i+1, N):
        dp[i][j] = j-i
        dp[j][i] = j-i
dp[X-1][Y-1] = 1
dp[Y-1][X-1] = 1
for i in range(N):
    for j in range(N):
        if dp[i][j] > dp[i][X-1] + dp[X-1][j]:
            dp[i][j] = dp[i][X-1] + dp[X-1][j]
            dp[j][i] = dp[i][X-1] + dp[X-1][j]
        if dp[i][j] > dp[i][Y-1] + dp[Y-1][j]:
            dp[i][j] = dp[i][Y-1] + dp[Y-1][j]
            dp[j][i] = dp[i][Y-1] + dp[Y-1][j]

n_map = {}
for i in range(N):
    for j in range(i+1,N):
        if dp[i][j] not in n_map:
            n_map[dp[i][j]] = 1
        else:
            n_map[dp[i][j]] += 1
for i in range(1, N):
    if i not in n_map:
        print(0)
    else:
        print(n_map[i])

Fixed submission:
N, X, Y = map(int, input().split())

dp = [[0]*N for _ in range(N)]
for i in range(N):
    for j in range(i+1, N):
        dp[i][j] = j-i
        dp[j][i] = j-i
dp[X-1][Y-1] = 1
dp[Y-1][X-1] = 1
for i in range(N):
    for j in range(N):
        if dp[i][j] > dp[i][X-1] + dp[X-1][j]:
            dp[i][j] = dp[i][X-1] + dp[X-1][j]
            dp[j][i] = dp[i][X-1] + dp[X-1][j]
        if dp[i][j] > dp[i][Y-1] + dp[Y-1][j]:
            dp[i][j] = dp[i][Y-1] + dp[Y-1][j]
            dp[j][i] = dp[i][Y-1] + dp[Y-1][j]

n_map = {}
for i in range(N):
    for j in range(i+1,N):
        if dp[i][j] not in n_map:
            n_map[dp[i][j]] = 1
        else:
            n_map[dp[i][j]] += 1
for i in range(1, N):
    if i not in n_map:
        print(0)
    else:
        print(n_map[i])
Buggy python submission (verdict: Runtime Error):
import sys

A, B = map(int, input().split())
MAX = 1500

for i in range(1, MAX):
    if int(i*0.08) == A and int(i*0.1) == B:
        print(i)
        sys.exit(1)
print(-1)


Fixed submission:
import sys

A, B = map(int, input().split())
MAX = 1500

for i in range(1, MAX):
    if int(i*0.08) == A and int(i*0.1) == B:
        print(i)
        sys.exit()
print(-1)

Buggy python submission (verdict: Runtime Error):
import sys

A, B = map(int, input().split())

x_a = int(A/0.08)
x_b = int(B/0.1)

for i in range(x_b, x_a+1):
    if int(i*0.08) == A and int(i*0.1) == B:
        print(i)
        sys.exit(1)
print(-1)


Fixed submission:
import sys

A, B = map(int, input().split())
MAX = 1500

for i in range(1, MAX):
    if int(i*0.08) == A and int(i*0.1) == B:
        print(i)
        sys.exit()
print(-1)
Buggy python submission (verdict: Runtime Error):
from scipy.special import comb

n, a, b = map(int, input().split())
MOD = 10**9+7


all_c = pow(2, n, MOD)-1
a_c = 1
b_c = 1
for i in range(n-a+1, n+1):
    a_c *= i
    a_c %= MOD
for i in range(1, a+1):
    a_c *= pow(i, MOD-2, MOD)
    a_c %= MOD
for i in range(n-b+1, n+1):
    b_c *= i
    b_c %= MOD
for i in range(1, b+1):
    b_c *= pow(i, MOD-2, MOD)
    b_c %= MOD

ans = (all_c - a_c - b_c) % MOD
print(ans)


Fixed submission:
n, a, b = map(int, input().split())
MOD = 10**9+7


all_c = pow(2, n, MOD)-1
a_c = 1
b_c = 1
for i in range(n-a+1, n+1):
    a_c *= i
    a_c %= MOD
for i in range(1, a+1):
    a_c *= pow(i, MOD-2, MOD)
    a_c %= MOD
for i in range(n-b+1, n+1):
    b_c *= i
    b_c %= MOD
for i in range(1, b+1):
    b_c *= pow(i, MOD-2, MOD)
    b_c %= MOD

ans = (all_c - a_c - b_c) % MOD
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N, K = map(int, input().split())
p = list(map(int, input().split()))

def get_e(p):
    return p*(p+1)/2/p

e_list = [get_e(p[i]) for i in range(N)]
c_e_list = [sum(e_list[i:i+K]) for i in range(N-K+1)]
print(max(c_e_list))

Fixed submission:
N, K = map(int, input().split())
p = list(map(int, input().split()))

def get_e(p):
    return p*(p+1)/2/p

e_list = [get_e(p[i]) for i in range(N)]
c_e_list = [0 for i in range(N)]
c_e_list[0] = e_list[0]
for i in range(1, N):
    c_e_list[i] = c_e_list[i-1] + e_list[i]

max_e = c_e_list[K-1]
for i in range(1, N-K+1):
    e = c_e_list[i+K-1] - c_e_list[i-1]
    if e > max_e:
        max_e = e

print(max_e)

Buggy python submission (verdict: Time Limit Exceeded):
N, K = map(int, input().split())
p = list(map(int, input().split()))

e_max = 0

def get_e(p):
    return p*(p+1)/2/p

for i in range(N-K+1):
    e = sum(map(get_e, p[i:i+K]))
    if e > e_max:
        e_max = e

print(e_max)

Fixed submission:
N, K = map(int, input().split())
p = list(map(int, input().split()))

def get_e(p):
    return p*(p+1)/2/p

e_list = [get_e(p[i]) for i in range(N)]
c_e_list = [0 for i in range(N)]
c_e_list[0] = e_list[0]
for i in range(1, N):
    c_e_list[i] = c_e_list[i-1] + e_list[i]

max_e = c_e_list[K-1]
for i in range(1, N-K+1):
    e = c_e_list[i+K-1] - c_e_list[i-1]
    if e > max_e:
        max_e = e

print(max_e)

Buggy python submission (verdict: Time Limit Exceeded):
N, K = map(int, input().split())
p = list(map(int, input().split()))

e_max = 0

def get_e(p):
    return p*(p+1)/2/p

for i in range(N-K+1):
    e = sum(map(get_e, p[i:i+K]))
    if e > e_max:
        e_max = e

print(e_max)

Fixed submission:
N, K = map(int, input().split())
p = list(map(int, input().split()))

def get_e(p):
    return p*(p+1)/2/p

e_list = [get_e(p[i]) for i in range(N)]
c_e_list = [0 for i in range(N)]
c_e_list[0] = e_list[0]
for i in range(1, N):
    c_e_list[i] = c_e_list[i-1] + e_list[i]

max_e = c_e_list[K-1]
for i in range(1, N-K+1):
    e = c_e_list[i+K-1] - c_e_list[i-1]
    if e > max_e:
        max_e = e

print(max_e)
Buggy python submission (verdict: Time Limit Exceeded):
INF = 10**9

H, N = map(int, input().split())
AB = [list(map(int, input().split())) for _ in range(N)]
dp = [INF for i in range(H+1)]

dp[0] = 0

for i in range(N):
    a = AB[i][0]
    b = AB[i][1]
    for j in range(H+1):
        next_j = min(j+a, H)
        dp[next_j] = min(dp[next_j], dp[j]+b)

print(dp[H])

Fixed submission:
INF = 10**9

H, N = map(int, input().split())
AB = [list(map(int, input().split())) for _ in range(N)]
dp = [INF for i in range(H+1)]

dp[0] = 0

for i in range(N):
    a = AB[i][0]
    b = AB[i][1]
    for j in range(H+1):
        next_j = min(j+a, H)
        dp[next_j] = min(dp[next_j], dp[j]+b)

print(dp[H])

Buggy python submission (verdict: Time Limit Exceeded):
INF = 10**9

H, N = map(int, input().split())
AB = [list(map(int, input().split())) for _ in range(N)]
dp = [INF for i in range(H+1)]

dp[0] = 0

for i in range(N):
    a = AB[i][0]
    b = AB[i][1]
    for j in range(H+1):
        next_j = min(j+a, H)
        dp[next_j] = min(dp[next_j], dp[j]+b)

print(dp[H])


Fixed submission:
INF = 10**9

H, N = map(int, input().split())
AB = [list(map(int, input().split())) for _ in range(N)]
dp = [INF for i in range(H+1)]

dp[0] = 0

for i in range(N):
    a = AB[i][0]
    b = AB[i][1]
    for j in range(H+1):
        next_j = min(j+a, H)
        dp[next_j] = min(dp[next_j], dp[j]+b)

print(dp[H])

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

H, N = map(int, input().split())
AB = [list(map(int, input().split())) for _ in range(N)]
dp = [[0 for i in range(N)] for j in range(H+1)]

for i in range(1, H+1):
    a = AB[-1][0]
    b = AB[-1][1]
    dp[i][N-1] = ceil(i / a)*b

for j in range(0, N-1)[::-1]:
    for i in range(1, H+1):
        a = AB[j][0]
        b = AB[j][1]
        x_list = []
        for k in range(0, int(ceil(i/a))+1):
            new_i = i - a*k
            x = dp[new_i][j+1] + b*k
            x_list.append(x)
        dp[i][j] = min(x_list)

print(dp[H][0])


Fixed submission:
INF = 10**9

H, N = map(int, input().split())
AB = [list(map(int, input().split())) for _ in range(N)]
dp = [INF for i in range(H+1)]

dp[0] = 0

for i in range(N):
    a = AB[i][0]
    b = AB[i][1]
    for j in range(H+1):
        next_j = min(j+a, H)
        dp[next_j] = min(dp[next_j], dp[j]+b)

print(dp[H])
Buggy python submission (verdict: Runtime Error):
from math import gcd
A, B = map(int, input().split())

print(int(A * B / gcd(A, B)))

Fixed submission:
from fractions import gcd
A, B = map(int, input().split())

print(int(A * B / gcd(A, B)))
Buggy python submission (verdict: Runtime Error):
n, u, v = map(int, input().split())
u -= 1
v -= 1
m_mat = [[] for i in range(n)]
for _ in range(n-1):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    m_mat[a].append(b)
    m_mat[b].append(a)
u_map = [-1]*n
v_map = [-1]*n
u_map[u] = 0
v_map[v] = 0
def dfs(current, depth, ma):
    for nex in m_mat[current]:
        if ma[nex] > -1:
            continue
        ma[nex] = depth
        dfs(nex, depth+1, ma)
dfs(u, 1, u_map)
dfs(v, 1, v_map)

ans = -1
for i in range(n):
    if u_map[i] < v_map[i] and v_map[i] > ans:
        ans = v_map[i]

print(ans-1)


Fixed submission:
import sys

sys.setrecursionlimit(10**5)
n, u, v = map(int, input().split())
u -= 1
v -= 1
m_mat = [[] for i in range(n)]
for _ in range(n-1):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    m_mat[a].append(b)
    m_mat[b].append(a)
u_map = [-1]*n
v_map = [-1]*n
u_map[u] = 0
v_map[v] = 0


def dfs(current, depth, ma):
    for nex in m_mat[current]:
        if ma[nex] > -1:
            continue
        ma[nex] = depth
        dfs(nex, depth+1, ma)


dfs(u, 1, u_map)
dfs(v, 1, v_map)

ans = -1
for i in range(n):
    if u_map[i] < v_map[i] and v_map[i] > ans:
        ans = v_map[i]

print(ans-1)

Buggy python submission (verdict: Runtime Error):
n, u, v = map(int, input().split())
u -= 1
v -= 1
m_mat = [[] for i in range(n)]
for _ in range(n-1):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    m_mat[a].append(b)
    m_mat[b].append(a)
u_map = [-1]*n
v_map = [-1]*n
u_map[u] = 0
v_map[v] = 0
def dfs(current, depth, ma):
    for nex in m_mat[current]:
        if ma[nex] > -1:
            continue
        ma[nex] = depth
        dfs(nex, depth+1, ma)
dfs(u, 1, u_map)
dfs(v, 1, v_map)


ans = max(v_map)-1

print(ans)


Fixed submission:
import sys

sys.setrecursionlimit(10**5)
n, u, v = map(int, input().split())
u -= 1
v -= 1
m_mat = [[] for i in range(n)]
for _ in range(n-1):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    m_mat[a].append(b)
    m_mat[b].append(a)
u_map = [-1]*n
v_map = [-1]*n
u_map[u] = 0
v_map[v] = 0


def dfs(current, depth, ma):
    for nex in m_mat[current]:
        if ma[nex] > -1:
            continue
        ma[nex] = depth
        dfs(nex, depth+1, ma)


dfs(u, 1, u_map)
dfs(v, 1, v_map)

ans = -1
for i in range(n):
    if u_map[i] < v_map[i] and v_map[i] > ans:
        ans = v_map[i]

print(ans-1)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = list(map(int, input().split()))
MOD = 10**9+7

li = [0 for i in range(61)]

for i in range(0, len(A)):
    _a = A[i]
    for j in range(len(li))[::-1]:
        quo = _a // pow(2, j)
        li[j] += quo
        _a -= quo*pow(2, j)


res = 0
for i in range(len(li)):
    res += (pow(2, i) * (li[i]*(N-li[i])))%MOD
    res %= MOD
print(res)


Fixed submission:
import numpy as np

N = int(input())
A = np.array(list(map(int, input().split())))
MOD = 10**9+7

ans = 0
for i in range(60):
    cnt = np.count_nonzero((A >> i) & 1)
    ans += (2**i * cnt*(N-cnt)) % MOD
    ans %= MOD
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = list(map(int, input().split()))
MOD = 10**9+7

lists = [[] for i in range(len(A))]

_a = A[0]
li = [0 for i in range(61)]
for i in range(len(li))[::-1]:
    quo = _a // pow(2, i)
    li[i] = quo
    _a -= quo*pow(2, i)
lists[0] = li

for i in range(1, len(A)):
    _a = A[i]
    li = [0 for j in range(61)]
    for j in range(len(li))[::-1]:
        quo = _a // pow(2, j)
        li[j] = lists[i-1][j] + quo
        _a -= quo*pow(2, j)
    lists[i] = li

res = []
for j in range(len(A)-1):
    a = A[j]
    lia = [lists[len(lists)-1][i] - lists[j][i] for i in range(61)]
    if j == 0:
        lib = lists[0]
    else:
        lib = [lists[j][i] - lists[j-1][i] for i in range(61)]
    _res = 0
    for i in range(len(li)):
        if lib[i] % 2 == 0:
        # 0のとき
            _res += pow(2, i) * lia[i]
        else:
        # 1のとき
            _res += pow(2, i) * ((N-j-1) - (lia[i]))
        _res %= MOD
    res.append(_res)
print(sum(res) % MOD)


Fixed submission:
import numpy as np

N = int(input())
A = np.array(list(map(int, input().split())))
MOD = 10**9+7

ans = 0
for i in range(60):
    cnt = np.count_nonzero((A >> i) & 1)
    ans += (2**i * cnt*(N-cnt)) % MOD
    ans %= MOD
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
s = input()
res = 0

for i in range(10):
    for j in range(10):
        for k in range(10):
            current = 0
            require = [str(i), str(j), str(k)]
            for v in s:
                if v == require[current]:
                    current += 1
                    if current == 3:
                        res += 1
                        break
print(res)


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

for i in range(10):
    for j in range(10):
        for k in range(10):
            current = 0
            require = [str(i), str(j), str(k)]
            for v in s:
                if v == require[current]:
                    current += 1
                    if current == 3:
                        res += 1
                        break
print(res)
Buggy python submission (verdict: Runtime Error):
from functools import gcd
from math import sqrt
A, B = map(int, input().split())

n = gcd(A, B)

ans = set()
for i in range(2, int(sqrt(n)+1)+1):
    while n % i == 0:
        n = n // i
        ans.add(i)

print(len(ans)+1)




Fixed submission:
from fractions import gcd
from math import sqrt
A, B = map(int, input().split())

n = gcd(A, B)

ans = set()
for i in range(2, int(sqrt(n)+1)+1):
    while n % i == 0:
        n = n // i
        ans.add(i)
if n > 1:
    ans.add(n)

print(len(ans)+1)

Buggy python submission (verdict: Runtime Error):
from math import gcd
from math import sqrt
A, B = map(int, input().split())

n = gcd(A, B)

ans = set()
for i in range(2, int(sqrt(n)+1)+1):
    while n % i == 0:
        n = n // i
        ans.add(i)

print(len(ans)+1)




Fixed submission:
from fractions import gcd
from math import sqrt
A, B = map(int, input().split())

n = gcd(A, B)

ans = set()
for i in range(2, int(sqrt(n)+1)+1):
    while n % i == 0:
        n = n // i
        ans.add(i)
if n > 1:
    ans.add(n)

print(len(ans)+1)
Buggy python submission (verdict: Runtime Error):
N = int(input())
S = input()
 
def zal(s):
    i = 1
    j = 0
    _N = len(s)
    Z = [0]*_N
    Z[0] = _N
    res = 0
    while i < _N:
        while i + j < _N and s[j] == s[i+j]:
            j += 1
        Z[i] = j
 
        if Z[i] <= i:
            res = max(res, Z[i])
 
        if j == 0:
            i += 1
            continue
        k = 1
        while i + k < _N and k + Z[k] < j:
            Z[i+k] = Z[k]
 
            if Z[i+k] <= i+k:
                res = max(res, Z[i+k])
 
            k += 1
        i += k
        j -= k
    return res
 
ans = 0
for i in range(N):
    _S = S[i:]
    res = zal(_S)
    ans = max(ans, res)
print(ans)

Fixed submission:
S = input()

if S == "Sunny":
    print("Cloudy")
elif S == "Cloudy":
    print("Rainy")
else:
    print("Sunny")
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())

print(sum([i for i in range(N)]))

Fixed submission:
from decimal import *
N = int(input())

ans = Decimal(N)/Decimal(2)
ans *= Decimal((N-1))
print(int(ans))