Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
import heapq

n = int(input())

def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a

A = prime_factorize(n)
heapq.heapify(A)

while len(A) > 2:
    a = heapq.heappop(A)
    b = heapq.heappop(A)
    heapq.heappush(A, a * b)

print(max((len(str(max(A)))), len(str(min(A)))) )

Fixed submission:
n = int(input())

def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    divisors.sort()
    return divisors

l = make_divisors(n)
#print(l)

A = l[len(l)//2]
B = l[len(l)//2-1]

print( max( len(str(A)), len(str(B)) ) )
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
p,mod = 1,1000000007
for i in range(1,n+1):
    p = p*i
print(p%mod)


Fixed submission:
n = int(input())
p,mod = 1,1000000007
for i in range(1,n+1):
    p = p*i%mod
print(p)
Buggy python submission (verdict: Time Limit Exceeded):
s = [i for i in input()]
ans = 0
while s.count('B') != 0 and s.count('W') != 0:
    lim,init = len(s)-1,s[-1]
    while s[lim] == init:
        if s[lim] is 'B':   s[lim] = 'W'
        else:   s[lim] = 'B'
        lim-=1
    if init is 'B': s.append('W')
    else:   s.append('B')
    ans += 1
print(ans)


Fixed submission:
s = input()
ans = 0
init = s[0]
for chr in s:
    if chr != init:
        ans += 1
        init = chr
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
x = input()
t = int(x)
x2 = input()
n = list(map(int, x2.split(" ")))


def main():
  p = 1
  for v in range(t):
    p *= n[v]
  if p > 10 **18:
  	print(-1)
  else:
    print(p)

main()


Fixed submission:
x = input()
t = int(x)
x2 = input()
n = list(map(int, x2.split(" ")))


def main():
  if 0 in n:
    print(0)
    return
  p = 1
  for v in range(t):
    p *= n[v]
    if (p > 10 **18):
      print("-1")
      return
  print(p)

main()

Buggy python submission (verdict: Runtime Error):
x = input()
t = int(x)
x2 = input()
n = list(map(int, x2.split(" ")))


def main():
  p = 1
  for v in t:
    p *= n[v]
    if (p >= 10 **18):
      print("-1")
      return
  print(p)

main()


Fixed submission:
x = input()
t = int(x)
x2 = input()
n = list(map(int, x2.split(" ")))


def main():
  if 0 in n:
    print(0)
    return
  p = 1
  for v in range(t):
    p *= n[v]
    if (p > 10 **18):
      print("-1")
      return
  print(p)

main()
Buggy python submission (verdict: Runtime Error):
def main():
    r1 = input()
    n, m = map(int, r1.split(" "))
    v = ["~"] * n
    for v in range(m):
        r = input()
        s, c = map(int, r1.split(" "))
        v[s] = c
        if v[s] != "~" and v[s] != c:
            print(-1)
            return
    for x in range(len(v)):
        if v[x] == '~':
            v[x] = 0
    sv = "".join(v)
    res = int(sv)
    res_str = str(res)
    if len(sv) != len(res_str):
        print(-1)
        return
    print(res_str)

main()
    

Fixed submission:
def main():
    r1 = input()
    n, m = map(int, r1.split(" "))
    v = ["~"] * n
    for t in range(m):
        r = input()
        s, c = map(int, r.split(" "))
        s -= 1
        if v[s] != "~" and v[s] != str(c):
            print(-1)
            return
        v[s] = str(c)
    if n >= 2 and v[0] == '~':
        v[0] = "1"
    for x in range(n):
        if v[x] == '~':
            v[x] = "0"
    sv = "".join(v)
    res = int(sv)
    res_str = str(res)
    if len(res_str) != n:
        print(-1)
        return
    print(res_str)

main()
Buggy python submission (verdict: Runtime Error):
import math

t = int(input())
r = int(input())
s = int(input())
print(r//s - (t-1)//s)


Fixed submission:
import math

t, r, s = map(int, input().split())
print(r//s - (t-1)//s)
Buggy python submission (verdict: Runtime Error):
import math
import itertools
import numpy as np

t = int(input())
a=list(map(int, input().split()))
num = 0
for i in range(t):
    if i%2 == 0 and g_all[i]%2 == 1:
        num+=1
print(num)


Fixed submission:
import math
import itertools
import numpy as np

t = int(input())
a=list(map(int, input().split()))
num = 0
for i in range(t):
    if i%2 == 0 and a[i]%2 == 1:
        num+=1
print(num)

Buggy python submission (verdict: Runtime Error):
import math
import itertools
import numpy as np

t = int(input())
g_all = np.array([list(input()) for i in range(t)])
num = 0
for i in range(t):
    if i%2 == 0 and g_all[i]%2 == 1:
        num+=1
print(num)


Fixed submission:
import math
import itertools
import numpy as np

t = int(input())
a=list(map(int, input().split()))
num = 0
for i in range(t):
    if i%2 == 0 and a[i]%2 == 1:
        num+=1
print(num)

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

t = int(input())
g_all = np.array([list(input()) for i in range(t)])
num = 0
for i in range(t):
    if i%2 == 0 and g_all[i]%2 == 1:
        num+=1
print(num)

Fixed submission:
import math
import itertools
import numpy as np

t = int(input())
a=list(map(int, input().split()))
num = 0
for i in range(t):
    if i%2 == 0 and a[i]%2 == 1:
        num+=1
print(num)
Buggy python submission (verdict: Runtime Error):
import math

n = int(input())
a = [int(input()) for i in range(n)]

x = a[0]
for i in a[1:]:
    x = (x * i) // math.gcd(x,i)

print(x)


Fixed submission:
def gcd(a,b):
    while b > 0:
        r = a % b
        a = b
        b = r
    return a

n = int(input())
x = int(input())
for _ in range(n-1):
    i = int(input())
    x = (x * i) // gcd(x,i)

print(x)
Buggy python submission (verdict: Runtime Error):
import math

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

ceil = math.ceil

max_a = max(a)
target_length = max_a//2 + 1
min_a = 0




while True:
    cnt = 0
    for a in A:
        cut_num = (a + target_length - 1)//target_length
        cnt += cut_num
    if cnt > k:
        min_a = target_length
        target_length = (target_length + max_a)//2
    else:
        if target_length - min_a == 1:
            print(target_length)
            exit()
        max_a = target_length
        target_length = (target_length + min_a)//2

Fixed submission:
n, k = map(int, input().split())
A = list(map(int, input().split()))

max_a = max(A)
min_a = 0

while abs(max_a - min_a) > 1:
    cnt = 0
    target_length = (max_a + min_a)//2
    for a in A:
        cut_num = (a + target_length - 1)//target_length
        cnt += cut_num - 1
    if cnt > k:
        min_a = target_length
    else:
        if target_length - min_a == 1:
            print(target_length)
            exit()
        max_a = target_length

print(max_a)

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

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

ceil = math.ceil

max_a = max(a)
target_length = max_a//2 + 1
min_a = 0

cnt = 0


while True:
    cnt += 1
    target_a = [ceil(x/target_length)-1 for x in a]
    if sum(target_a) > k:
        min_a = target_length
        target_length = (target_length + max_a)//2
    else:
        if target_length - min_a == 1:
            print(target_length)
            exit()
        max_a = target_length
        target_length = (target_length + min_a)//2

Fixed submission:
n, k = map(int, input().split())
A = list(map(int, input().split()))

max_a = max(A)
min_a = 0

while abs(max_a - min_a) > 1:
    cnt = 0
    target_length = (max_a + min_a)//2
    for a in A:
        cut_num = (a + target_length - 1)//target_length
        cnt += cut_num - 1
    if cnt > k:
        min_a = target_length
    else:
        if target_length - min_a == 1:
            print(target_length)
            exit()
        max_a = target_length

print(max_a)
Buggy python submission (verdict: Runtime Error):
n,a,b = map(int, input().split())
print(min(b,a*n)

Fixed submission:
n,a,b = map(int, input().split())
print(min(b,a*n))
Buggy python submission (verdict: Runtime Error):
import sys
from operator import itemgetter

sys.setrecursionlimit(10**9)
input = sys.stdin.readline

def ii(): return int(input())
def mi(): return map(int, input().split())
def lmi(): return list(map(int, input().split()))
def lmif(n): return [list(map(int, input().split())) for _ in range(n)]
def ss(): return input().split()

def main():
    n = ii
    ans = 1000 - n%1000
    print(ans)
    return

main()


Fixed submission:
import sys
from operator import itemgetter

sys.setrecursionlimit(10**9)
input = sys.stdin.readline

def ii(): return int(input())
def mi(): return map(int, input().split())
def lmi(): return list(map(int, input().split()))
def lmif(n): return [list(map(int, input().split())) for _ in range(n)]
def ss(): return input().split()

def main():
    n = ii()
    if n%1000 == 0:
        print(0)
    else:
        print(1000 - n%1000)
    return

main()
Buggy python submission (verdict: Runtime Error):
import sys
from random import randint
from datetime import datetime

sys.setrecursionlimit(10**9)
input = sys.stdin.readline

def ii(): return int(input())
def mi(): return map(int, input().split())
def lmi(): return list(map(int, input().split()))
def lmif(n): return [list(map(int, input().split())) for _ in range(n)]

def randomize(n):
    return [ randint(1, 26) for _ in range(n) ]

def get_now():
    dt = datetime.now()
    return dt.second + dt.microsecond/1000000

def main():
    start = get_now()
    end = get_now()
    # 開催日数
    D = ii()
    # 満足度の下がりやすさ
    C = lmi()
    # 得られる満足度
    S = lmif(D)
    # 開催するコンテスト
    T = [ randomize(D) ]

    def scoring():
        # 最後に開かれた日付
        last = [0]*26
        score = 0
        for i in range(D):
            score += S[i][T[i]-1]
            last[T[i]-1] = i+1
            for j in range(26):
                score -= C[j] * (i+1 - last[j])
        return score

    max_score = scoring()
    # print(max_score)
    ans = T.copy()
    # a = 0
    while end - start < 1.95:
        idx, value = randint(0, D-1), randint(1, 26)
        old = T[idx]
        T[idx] = value
        score = scoring()
        if max_score < score:
            ans = T.copy()
            max_score = score
        else:
            T[idx] = old
        # if a % 10000 == 0:
        #     print(a, *T, score, max_score)
        # a += 1
        end = get_now()
    print(*ans, sep='\n')

main()


Fixed submission:
def main():
    import sys
    sys.setrecursionlimit(10**9)
    input = sys.stdin.readline

    for i in range(365):
        print(i%26+1)

main()
Buggy python submission (verdict: Runtime Error):
def main():
    import sys
    sys.setrecursionlimit(10**9)
    input = sys.stdin.readline

    a = input()

    if ord('a') <= ord(a) <= ord('z'):
        print('a')
    else:
        print('A')
        

main()


Fixed submission:
def main():
    import sys
    sys.setrecursionlimit(10**9)
    input = sys.stdin.readline

    a = input()[:-1]

    if ord('a') <= ord(a) <= ord('z'):
        print('a')
    else:
        print('A')
        

main()

Buggy python submission (verdict: Runtime Error):
def main():
    import sys
    sys.setrecursionlimit(10**9)
    input = sys.stdin.readline

    a = input()

    if ord('a') <= ord(a) <= ord('z'):
        print('a')
    else:
        print('A')
        

main()

Fixed submission:
def main():
    import sys
    sys.setrecursionlimit(10**9)
    input = sys.stdin.readline

    a = input()[:-1]

    if ord('a') <= ord(a) <= ord('z'):
        print('a')
    else:
        print('A')
        

main()
Buggy python submission (verdict: Time Limit Exceeded):
def main():
    import sys
    sys.setrecursionlimit(10**9)
    input = sys.stdin.readline
    from collections import Counter

    N = int(input())
    A = list(map(int, input().split()))
    CA = Counter(A)
    Q = int(input())
    for i in range(Q):
        b, c = map(int, input().split())
        CA[c] += CA[b]
        CA[b] = 0
        sumA = 0
        for key, value in CA.items():
            sumA += key*value
        print(sumA)

main()

Fixed submission:
def main():
    import sys
    sys.setrecursionlimit(10**9)
    input = sys.stdin.readline
    from collections import Counter

    N = int(input())
    A = list(map(int, input().split()))
    CA = Counter(A)
    sumA = 0
    for key, value in CA.items():
        sumA += key*value

    Q = int(input())
    for i in range(Q):
        b, c = map(int, input().split())
        sumA += (c-b)*CA[b]
        CA[c] += CA[b]
        CA[b] = 0
        print(sumA)

main()
Buggy python submission (verdict: Runtime Error):
def main():
    from operator import itemgetter
    import sys
    sys.setrecursionlimit(10**9)
    input = sys.stdin.readline

    X = list(map(int,input().split))
    for i in range(X):
        if X[i] == 0:
            print(i+1)
            return

main()

Fixed submission:
def main():
    from operator import itemgetter
    import sys
    sys.setrecursionlimit(10**9)
    input = sys.stdin.readline

    X = list(map(int, input().split()))
    for i in range(len(X)):
        if X[i] == 0:
            print(i+1)
            return

main()
Buggy python submission (verdict: Time Limit Exceeded):
def main():
    import sys
    sys.setrecursionlimit(10**9)
    input = sys.stdin.readline

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

    limit = 10**18
    ans = 1
    for i in A:
        ans *= i
    if ans > limit:
        print(-1)
    else:
        print(ans)

main()

Fixed submission:
def main():
    import sys
    sys.setrecursionlimit(10**9)
    input = sys.stdin.readline

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

    if 0 in A:
        print(0)
        return

    limit = 10**18
    ans = 1
    for i in A:
        ans *= i
        if ans > limit:
            print(-1)
            return

    print(ans)

main()

Buggy python submission (verdict: Runtime Error):
def main():
    import sys
    sys.setrecursionlimit(10**9)
    input = sys.stdin.readline

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

    limit = 10**18
    ans = 1
    for i in A:
        if A == 0:
            print(0)
            return
        if ans > limit:
            print(-1)
            return
        ans *= A[i]
    print(ans)

main()

Fixed submission:
def main():
    import sys
    sys.setrecursionlimit(10**9)
    input = sys.stdin.readline

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

    if 0 in A:
        print(0)
        return

    limit = 10**18
    ans = 1
    for i in A:
        ans *= i
        if ans > limit:
            print(-1)
            return

    print(ans)

main()
Buggy python submission (verdict: Time Limit Exceeded):
# 折れ線グラフで考えると
# ( : +1
# ) : -1
# 0で終わる
# 0未満にならない → 各文字列で最下点と和を利用
# 和がマイナスの部分と分けて、マイナス部分は反転して考える

n = int(input())
plus = []
minus = []
for i in range(n):
    min_v = 0
    sum_v = 0
    s = input()
    for j in range(len(s)):
        sum_v += 1 if s[j] == '(' else -1
        min_v = min(min_v, sum_v)
    if sum_v > 0:
        plus.append([min_v, sum_v])
    else:
        minus.append([min_v-sum_v, -sum_v])

plus.sort(key=lambda x:x[0], reverse=True)
minus.sort(key=lambda x:x[0], reverse=True)

sum_plus = 0
for min_v, sum_v in plus:
    if sum_plus + min_v < 0:
        print("No")
        exit()
    sum_plus += sum_v

sum_minus = 0
for min_v, sum_v in minus:
    if sum_minus + min_v < 0:
        print("No")
        exit()
    sum_minus += sum_v

if sum_plus == sum_minus:
    print("Yes")
else:
    print("No")





Fixed submission:
# 折れ線グラフで考えると
# ( : +1
# ) : -1
# 0で終わる
# 0未満にならない → 各文字列で最下点と和を利用
# 和がマイナスの部分と分けて、マイナス部分は反転して考える

n = int(input())
plus = []
minus = []
for i in range(n):
    min_v = 0
    sum_v = 0
    s = input()
    for j in s:
        sum_v += 1 if j == '(' else -1
        min_v = min(min_v, sum_v)
    if sum_v > 0:
        plus.append((min_v, sum_v))
    else:
        minus.append((min_v-sum_v, -sum_v))

plus.sort(key=lambda x:x[0], reverse=True)
minus.sort(key=lambda x:x[0], reverse=True)

sum_plus = 0
for min_v, sum_v in plus:
    if sum_plus + min_v < 0:
        print("No")
        exit()
    sum_plus += sum_v

sum_minus = 0
for min_v, sum_v in minus:
    if sum_minus + min_v < 0:
        print("No")
        exit()
    sum_minus += sum_v

if sum_plus == sum_minus:
    print("Yes")
else:
    print("No")
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int, input().split()))

cnt = 0
for i in range(n):
    for j in range(i + a[i], n):
        if j - i == a[i] + a[j]:
            cnt += 1
print(cnt)

Fixed submission:
n = int(input())
a = list(map(int, input().split()))
r = {}
for i in range(n):
    try:
        r[i-a[i]] += 1
    except:
        r[i-a[i]] = 1
cnt = 0
for i in range(n):
    r[i-a[i]] -= 1
    try:
        cnt += r[i+a[i]]
    except:
        pass
print(cnt)
Buggy python submission (verdict: Time Limit Exceeded):
a, b, n = map(int, input().split())

ans = 0
zero_cnt = 0
for i in range(n+1):
    tmp = int(a*i/b) - a*int(i/b)
    if ans != 0 and tmp == 0:
        break
    ans = max(ans, tmp)
print(ans)

Fixed submission:
a, b, n = map(int, input().split())
x = min(b-1, n)
print(int(a*x/b))
Buggy python submission (verdict: Runtime Error):
def main():
    import sys
    sys.setrecursionlimit(10**9)
    input = sys.stdin.readline
    from collections import deque
    from bisect import bisect_left

    N = int(input())
    a = list(map(int, input().split()))
    tree = [[] for _ in [0]*N]
    for u, v in [map(int, input().split()) for _ in [0]*(N-1)]:
        tree[u-1].append(v-1)
        tree[v-1].append(u-1)
    
    dp = [1001001001] * N
    dp[0] = -1001001001
    ans = [0] * N
    def dfs(now, p=-1):
        idx = bisect_left(dp, a[now])
        old = dp[idx]
        dp[idx] = a[now]
        ans[now] = idx
        if p != -1 and ans[now] < ans[p]:
            ans[now] = ans[p]
        for child in tree[now]:
            if child == p: continue
            dfs(child, now)
        dp[idx] = old
    dfs(0)
    
    print(*ans, sep='\n')

main()

Fixed submission:
def main():
    import sys
    sys.setrecursionlimit(10**9)
    input = sys.stdin.readline
    from collections import deque
    from bisect import bisect_left

    N = int(input())
    a = list(map(int, input().split()))
    tree = [[] for _ in [0]*N]
    for u, v in [map(int, input().split()) for _ in [0]*(N-1)]:
        tree[u-1].append(v-1)
        tree[v-1].append(u-1)
    
    dp = [1001001001] * (N+1)
    dp[0] = -1001001001
    ans = [0] * N
    def dfs(now, p=-1):
        idx = bisect_left(dp, a[now])
        old = dp[idx]
        dp[idx] = a[now]
        ans[now] = idx
        if p != -1 and ans[now] < ans[p]:
            ans[now] = ans[p]
        for child in tree[now]:
            if child == p: continue
            dfs(child, now)
        dp[idx] = old
    dfs(0)

    print(*ans, sep='\n')

main()
Buggy python submission (verdict: Runtime Error):
n = input()
if 7 in n:
    print("Yes")
else:
    print("No")

Fixed submission:
n = input()
if "7" in n:
    print("Yes")
else:
    print("No")
Buggy python submission (verdict: Time Limit Exceeded):
def can_make_one(n, k):
    while True:
        if n % k == 0:
            n = n // k
        else:
            n = n - k
        if n == 1:
            return True
        elif n < 1:
            return False
n = int(input())
#o: 2, n-1, n
#x: n//2+1 ~ n-2
cnt = 3
if n == 2:
    print(1)
elif n == 3:
    print(2)
elif n == 4 or n == 5:
    print(3)
else:
    for i in range(3, n//2+1):
        if can_make_one(n, i):
            cnt += 1
    print(cnt)

Fixed submission:
import math

def get_divisor(n):
    sn = math.sqrt(n)
    i = 1
    divisor = []
    while i <= sn:
        if n % i == 0:
            divisor.append(i)
            if i != n // i:
                divisor.append(n // i)
        i += 1
    return divisor

n = int(input())
if n == 2:
    print(1)
    exit()
d1 = get_divisor(n)
d2 = get_divisor(n - 1)
ans = -1
for i in d1:
    tmp = int(n)
    if i == 1:
        continue
    while tmp % i == 0:
        tmp //= i
    if tmp % i == 1:
        ans += 1
ans += len(d2)
print(ans)
Buggy python submission (verdict: Runtime Error):
x, y, a, b, c = map(int, input().split())
red = list(map(int, input().split()))
green = list(map(int, input().split()))
no = list(map(int, input().split()))

red.sort()
green.sort()
no.sort()
a -= 1
b -= 1
c -= 1

ans = 0
for i in range(x):
    ans += red[a]
    a -= 1
for i in range(y):
    ans += green[b]
    b -= 1
a += 1
b += 1

for i in range(x+y):
    gr = no[c] - red[a]
    gg = no[c] - green[b]

    if gr > gg:
        if gr > 0:
            ans += no[c]
            ans -= red[a]
            c -= 1
            a += 1
    elif gg > gr:
        if gg > 0:
            ans += no[c]
            ans -= green[b]
            c -= 1
            b += 1

print(ans)


Fixed submission:
x, y, a, b, c = map(int, input().split())
red = list(map(int, input().split()))
green = list(map(int, input().split()))
no = list(map(int, input().split()))

red.sort()
green.sort()
no.sort()
a -= 1
b -= 1
c -= 1
max_a = int(a)
max_b = int(b)

ans = 0
for i in range(x):
    ans += red[a]
    a -= 1
for i in range(y):
    ans += green[b]
    b -= 1
a += 1
b += 1

for i in range(x+y):
    if c >= 0 and a <= max_a and b <= max_b:
        gr = no[c] - red[a]
        gg = no[c] - green[b]
        if gr >= gg:
            if gr > 0:
                ans += no[c]
                ans -= red[a]
                c -= 1
                a += 1
        elif gg >= gr:
            if gg > 0:
                ans += no[c]
                ans -= green[b]
                c -= 1
                b += 1
    elif c >= 0 and a <= max_a:
        if no[c] - red[a] > 0:
            ans += no[c]
            ans -= red[a]
            c -= 1
            a += 1
    elif c >= 0 and b <= max_b:
        if no[c] - green[b] > 0:
            ans += no[c]
            ans -= green[b]
            c -= 1
            b += 1
    else:
        break

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
from collections import Counter

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

for i in range(n):
    ans = 0
    c[a[i]] -= 1
    for v in c.values():
        ans += v*(v-1)//2
    c[a[i]] += 1
    print(ans)
    

Fixed submission:
from collections import Counter

n = int(input())
a = list(map(int, input().split()))
c = dict(Counter(a))
ans = 0
for v in c.values():
    ans += v*(v-1)//2
for i in range(n):
    print(ans-c[a[i]]+1)