Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
from math import gcd

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

np = (B - A + 1) + (-(B - A) // C)
nq = (B - A + 1) + (-(B - A) // D)


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


npq_ = (B - A + 1) + (-(B - A) // lcm(C, D))
print(np + nq - npq_ - 1)

Fixed submission:
from fractions import gcd

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


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


nbc = B - B // C
nbd = B - B // D
nbl = B - B // lcm(C, D)

nac = A - 1 - ((A - 1) // C)
nad = A - 1 - ((A - 1) // D)
nal = A - 1 - ((A - 1) // lcm(C, D))

b = nbc + nbd - nbl
a = nac + nad - nal

print(b - a)

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

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

np = (B - A + 1) + (-(B - A) // C)
nq = (B - A + 1) + (-(B - A) // D)


def coprime(a, b):
    return gcd(a, b) == 1


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


if coprime(C, D) == True:
    npq = (B - A + 1) + (-(B - A) // (C * D))
    print(np + nq - npq)
else:
    npq_ = (B - A + 1) + (-(B - A) // lcm(C, D))
    print(np + nq - npq_ - 1)


Fixed submission:
from fractions import gcd

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


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


nbc = B - B // C
nbd = B - B // D
nbl = B - B // lcm(C, D)

nac = A - 1 - ((A - 1) // C)
nad = A - 1 - ((A - 1) // D)
nal = A - 1 - ((A - 1) // lcm(C, D))

b = nbc + nbd - nbl
a = nac + nad - nal

print(b - a)

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

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

np = (B - A + 1) + (-(B - A) // C)
nq = (B - A + 1) + (-(B - A) // D)


def coprime(a, b):
    return gcd(a, b) == 1


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


if coprime(C, D) == True:
    npq = (B - A + 1) + (-(B - A) // (C * D))
    print(np + nq - npq)
else:
    npq_ = (B - A + 1) + (-(B - A) // lcm(C, D))
    print(np + nq - npq_ - 1)

Fixed submission:
from fractions import gcd

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


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


nbc = B - B // C
nbd = B - B // D
nbl = B - B // lcm(C, D)

nac = A - 1 - ((A - 1) // C)
nad = A - 1 - ((A - 1) // D)
nal = A - 1 - ((A - 1) // lcm(C, D))

b = nbc + nbd - nbl
a = nac + nad - nal

print(b - a)
Buggy python submission (verdict: Runtime Error):
L = [int(i) for i in input().split()]

min_root = []
for i in L:
    for j in L:
        if i != j:
            min_root.append(i+j)
        else:
            continue

print(min(min_root))


Fixed submission:
L = [int(i) for i in input().split()]

min_root = []
for i in L:
    for j in L:
        if i != j:
            min_root.append(i+j)
        else:
            continue
            
if len(min_root) > 0:
    print(min(min_root))
else:
    print(L[0]+L[1])

Buggy python submission (verdict: Runtime Error):
L = list(map(int, input().split()))

min_root = []
for i in L:
    for j in L:
        if i != j:
            min_root.append(i+j)
        else:
            continue

print(min(min_root))


Fixed submission:
L = [int(i) for i in input().split()]

min_root = []
for i in L:
    for j in L:
        if i != j:
            min_root.append(i+j)
        else:
            continue
            
if len(min_root) > 0:
    print(min(min_root))
else:
    print(L[0]+L[1])
Buggy python submission (verdict: Time Limit Exceeded):
from itertools import islice

N, M = map(int, input().split())
LR = [list(map(int, input().split())) for _ in range(M)]


lst = []
for i in LR:
    lst_ = set(list(range(i[0],i[1]+1)))
    lst.append(lst_)

lst = set.intersection(set(lst[0]), *islice(lst, 1, None))
print(len(lst))


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

L = [0] * M
R = [0] * M
for i in range(M):
    L[i], R[i] = map(int, input().split())

print(max(min(R) - max(L) + 1, 0))

Buggy python submission (verdict: Time Limit Exceeded):
N, M = map(int, input().split())
LR = [list(map(int, input().split())) for _ in range(M)]


lst = []
for i, j in enumerate(LR):
    lst_ = set(list(range(j[0],j[1]+1)))
    lst.append(lst_)

lst = set.intersection(*lst)
print(len(lst))

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

L = [0] * M
R = [0] * M
for i in range(M):
    L[i], R[i] = map(int, input().split())

print(max(min(R) - max(L) + 1, 0))
Buggy python submission (verdict: Runtime Error):
import numpy as np
import math
 
N, K = map(int, input().split())
 
 
prob = []
if N >= K:
    p_e = (1 / N) * (N - K + 1)
    for i in range(1, K):
        p_i = (1 / N) * ((1 / 2) ** (math.ceil((np.log2(K / i))))
        prob.append(p_i)
else:
    p_e = 0
    for i in range(1, N+1):
        p_i = (1 / N) * ((1 / 2) ** (math.ceil((np.log2(K / i))))
        prob.append(p_i)
 
summer = sum(prob) + p_e
 
print("{:.12f}".format(summer))

Fixed submission:
import numpy as np
import math

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


prob = []
if N >= K:
    p_e = (1 / N) * (N - K + 1)
    for i in range(1, K):
        p_i = (1 / N) * ((1 / 2) ** (math.ceil(np.log2(K / i))))
        prob.append(p_i)

else:
    p_e = 0
    for i in range(1, N+1):
        p_i = (1 / N) * ((1 / 2) ** (math.ceil(np.log2(K / i))))
        prob.append(p_i)


s = sum(prob) + p_e
print("{:.12f}".format(s))
Buggy python submission (verdict: Runtime Error):
N, K = mapt(int, input().split())

print(N-K+1)

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

print(N-K+1)
Buggy python submission (verdict: Runtime Error):
S = sorted(list(set(input())))

alphabet = list('abcdefghijklmnopqrstuvwxyz')

if alphabet == S:
    print('None')
    exit()
elif len(S) == 1 and S[0] == 'a':
    print('b')
    exit()

for i in range(len(alphabet)):
    if S[i] == alphabet[i]:
        continue
    else:
        print(alphabet[i])
        exit()


Fixed submission:
S = sorted(list(set(input())))

alphabet = list('abcdefghijklmnopqrstuvwxyz')

for i in range(len(alphabet)):
    if alphabet[i] not in S:
        print(alphabet[i])
        exit()

print('None')

Buggy python submission (verdict: Runtime Error):
S = sorted(list(set(input())))

alphabet = list('abcdefghijklmnopqrstuvwxyz')

if alphabet == S:
    print('None')
    exit()

for i in range(len(alphabet)):
    if S[i] == alphabet[i]:
        continue
    else:
        print(alphabet[i])
        exit()


Fixed submission:
S = sorted(list(set(input())))

alphabet = list('abcdefghijklmnopqrstuvwxyz')

for i in range(len(alphabet)):
    if alphabet[i] not in S:
        print(alphabet[i])
        exit()

print('None')
Buggy python submission (verdict: Time Limit Exceeded):
num = int(input())
original = list(map(int, input().split()))
trial_num = int(input())

total = sum(original)
now_list = original

for i in range(trial_num):
    trial = list(map(int, input().split()))
    count = 0
    for i in range(num):
        if now_list[i] == trial[0]:
            now_list[i] = trial[1]
            count += 1
    total += (trial[1] - trial[0]) * count
    print(total)
    

Fixed submission:
import collections

num = int(input())
original = list(map(int, input().split()))
trial_num = int(input())

total = sum(original)
# now_list = original
count_dict = collections.Counter(original)

for i in range(trial_num):
    b, c = list(map(int, input().split()))
    total += (c - b) * count_dict[b]
    print(total)
    
    if c in count_dict.keys():
        count_dict[c] += count_dict[b]
    else:
        count_dict[c] = count_dict[b]
    count_dict[b] = 0

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

num = int(input())
original = list(map(int, input().split()))
trial_num = int(input())

total = sum(original)
now_list = original

for i in range(trial_num):
    trial = list(map(int, input().split()))
    c_list = collections.Counter(now_list)
    index = trial[0]
    total += (trial[1] - trial[0]) * int(c_list[index])
    print(total)
    
    now_list = [trial[1] if i == trial[0] else i for i in now_list]

Fixed submission:
import collections

num = int(input())
original = list(map(int, input().split()))
trial_num = int(input())

total = sum(original)
# now_list = original
count_dict = collections.Counter(original)

for i in range(trial_num):
    b, c = list(map(int, input().split()))
    total += (c - b) * count_dict[b]
    print(total)
    
    if c in count_dict.keys():
        count_dict[c] += count_dict[b]
    else:
        count_dict[c] = count_dict[b]
    count_dict[b] = 0
Buggy python submission (verdict: Runtime Error):
import operator
num = int(input())
a = list(map(int, input().split()))
result = reduce(operator.mul,a)
if result > 1000000000000000000:
    print(-1)
else:
    print(result)

Fixed submission:
ans = 1
flag = 0

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

if 0 in a:
    print(0)
else:
    for i in range(n):
        ans *= a[i]
        if ans > 1000000000000000000:
            flag = 1
            print(-1)
            break
    
    if flag == 0:
        print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import functools
import operator

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

result = functools.reduce(operator.mul, a)
if result > 1000000000000000000:
    print(-1)
else:
    print(result)

Fixed submission:
ans = 1
flag = 0

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

if 0 in a:
    print(0)
else:
    for i in range(n):
        ans *= a[i]
        if ans > 1000000000000000000:
            flag = 1
            print(-1)
            break
    
    if flag == 0:
        print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
ans = 1

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

for i in range(n):
    ans *= a[i]

if ans > 1000000000000000000:
    print(-1)
else:
    print(ans)

Fixed submission:
ans = 1
flag = 0

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

if 0 in a:
    print(0)
else:
    for i in range(n):
        ans *= a[i]
        if ans > 1000000000000000000:
            flag = 1
            print(-1)
            break
    
    if flag == 0:
        print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
num = int(input())
item_list = []
count = 0

for i in range(num):
    item = input()
    # print(item in item_list)
    if (item in item_list) == False:
        item_list.append(item)
        count += 1
        
print(count)

Fixed submission:
import collections

num = int(input())
item = [input() for i in range(num)]

item_count = collections.Counter(item)

print(len(item_count.keys()))
Buggy python submission (verdict: Time Limit Exceeded):
num = int(input())
a = list(map(int, input().split()))

for i in range(1, num+1):
    print(a.count(i))

Fixed submission:
num = int(input())
a = list(map(int, input().split()))
count = [0] * num

for i in range(len(a)):
    count[a[i] - 1] += 1

for i in range(len(count)):
    print(count[i])
Buggy python submission (verdict: Time Limit Exceeded):
from sys import stdin
import sys
import math
from functools import reduce
import functools
import itertools
from collections import deque,Counter
from operator import mul
from functools import reduce

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

a.sort()

count = Counter(a)

b = [1 for i in range((max(a) + 1))]

for aa in a:
    for j in range(2*aa,max(a)+1, aa):
        b[j] = 0

c = 0
for d in count.items():
    if d[1] == 1 and b[d[0]] == 1: c += 1

print(c)

Fixed submission:
from sys import stdin
import sys
import math
from functools import reduce
import functools
import itertools
from collections import deque,Counter
from operator import mul
from functools import reduce

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

a.sort()

count = Counter(a)

b = [1]*(max(a) + 1)

for aa in a:
    for j in range(2*aa,len(b), aa):
        b[j] = 0

c = 0
for d in count.items():
    if d[1] == 1 and b[d[0]] == 1: c += 1

print(c)

Buggy python submission (verdict: Time Limit Exceeded):
from sys import stdin
import sys
import math
from functools import reduce
import functools
import itertools
from collections import deque,Counter
from operator import mul
from functools import reduce

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

a.sort()

count = Counter(a)

b = [1 for i in range(max(a)+1)]

for aa in a:
    for j in range(2*aa,max(a)+1, aa):
        b[j] = 0

c = 0
for d in count.items():
    if d[1] == 1 and b[d[0]] == 1: c += 1

print(c)

Fixed submission:
from sys import stdin
import sys
import math
from functools import reduce
import functools
import itertools
from collections import deque,Counter
from operator import mul
from functools import reduce

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

a.sort()

count = Counter(a)

b = [1]*(max(a) + 1)

for aa in a:
    for j in range(2*aa,len(b), aa):
        b[j] = 0

c = 0
for d in count.items():
    if d[1] == 1 and b[d[0]] == 1: c += 1

print(c)

Buggy python submission (verdict: Time Limit Exceeded):
from sys import stdin
import sys
import math
from functools import reduce
import functools
import itertools
from collections import deque
from operator import mul
from functools import reduce

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

a.sort()

b = [1 for i in range(n)]

for i in range(n):
    if b[i] == 1:
        for j in range(i+1,n):
            if a[j] % a[i] == 0: b[j] = 0
            if a[j] == a[i]: b[i] = 0

print(sum(b))

Fixed submission:
from sys import stdin
import sys
import math
from functools import reduce
import functools
import itertools
from collections import deque,Counter
from operator import mul
from functools import reduce

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

a.sort()

count = Counter(a)

b = [1]*(max(a) + 1)

for aa in a:
    for j in range(2*aa,len(b), aa):
        b[j] = 0

c = 0
for d in count.items():
    if d[1] == 1 and b[d[0]] == 1: c += 1

print(c)
Buggy python submission (verdict: Runtime Error):
from sys import stdin
import sys

a,b = [int(x) for x in stdin.readline().rstrip().split()]
print(a*(b*100)/100)

Fixed submission:
from sys import stdin
import sys

a, b = [x for x in stdin.readline().rstrip().split()]
a = int(a)
b = int(b.replace('.',''))

print(a * b  // 100)
Buggy python submission (verdict: Runtime Error):
from sys import stdin
import sys, math

a, b, h, m = [int(x) for x in stdin.readline().rstrip().split()]

x = 30*h + 0.5*m
y = 6*m

c = a**2 + b**2 - 2*a*b*abs(math.cos(math.radians(z)))
c = math.sqrt(c)

print(c)

Fixed submission:
from sys import stdin
import sys, math

a, b, h, m = [int(x) for x in stdin.readline().rstrip().split()]

x = 30*h + 0.5*m
y = 6*m

z = abs(x-y)
if z > 180: z = 360 - z

c = a**2 + b**2 - 2*a*b*math.cos(math.radians(z))
c = math.sqrt(c)

print(c)
Buggy python submission (verdict: Runtime Error):
from sys import stdin
import sys
import math
from functools import reduce
import functools
import itertools
from collections import deque

n,m = [int(x) for x in stdin.readline().rstrip().split()]

d = {}
for i in range(n):
    a,b = [int(x) for x in stdin.readline().rstrip().split()]

    if a not in d:
        d[a] = [b]
    else:
        d[a].append(b)

    if b not in d:
        d[b] = [a]
    else:
        d[b].append(a)

sol = {}

m = [1]
while True:
    next_m = []
    for mm in m:
        b = d[mm]
        for bb in b:
            if bb not in sol:
                sol[bb] = mm
                next_m.append(bb)

    if len(next_m) == 0: break
    m = next_m

sol = sorted(sol.items())

print("Yes")
for v in sol[1:]:
    print(v[1])

Fixed submission:
from sys import stdin
import sys
import math
from functools import reduce
import functools
import itertools
from collections import deque

n,m = [int(x) for x in stdin.readline().rstrip().split()]

d = {}
for i in range(m):
    a,b = [int(x) for x in stdin.readline().rstrip().split()]

    if a not in d:
        d[a] = [b]
    else:
        d[a].append(b)

    if b not in d:
        d[b] = [a]
    else:
        d[b].append(a)

sol = {}

m = [1]
while True:
    next_m = []
    for mm in m:
        b = d[mm]
        for bb in b:
            if bb not in sol:
                sol[bb] = mm
                next_m.append(bb)

    if len(next_m) == 0: break
    m = next_m

sol = sorted(sol.items())

print("Yes")
for v in sol[1:]:
    print(v[1])
Buggy python submission (verdict: Time Limit Exceeded):
from sys import stdin
import sys
import math
from functools import reduce
import functools
import itertools
from collections import deque

n,k = [int(x) for x in stdin.readline().rstrip().split()]
a = [0] + [int(x) for x in stdin.readline().rstrip().split()]

m = 0
b = [1]

c = 1
for i in range(n):
    c = a[c]
    if c not in b:
        b.append(c)
        if i == k-1:
            print(c)
            sys.exit()
    else:
        break

idx = b.index(c)
bn = len(b[idx:])
sn = len(b[:idx])

# print(b,idx,sn,bn)
kk = (k-sn) % bn
print(b[idx+kk])

Fixed submission:
from sys import stdin
import sys
import math
from functools import reduce
import functools
import itertools
from collections import deque

n,k = [int(x) for x in stdin.readline().rstrip().split()]
a = [0] + [int(x) for x in stdin.readline().rstrip().split()]

m = 0
b = [1]
visited = [-1 for i in range(n+1)]

c = 1
visited[1] = 1
for i in range(n):
    c = a[c]
    if visited[c] != 1:
        b.append(c)
        visited[c] = 1
        if i == k-1:
            print(c)
            sys.exit()
    else:
        break

idx = b.index(c)
bn = len(b[idx:])
sn = len(b[:idx])

# print(b,idx,sn,bn)
kk = (k-sn) % bn
print(b[idx+kk])

Buggy python submission (verdict: Time Limit Exceeded):
from sys import stdin
import sys
import math
from functools import reduce
import functools
import itertools
from collections import deque

n,k = [int(x) for x in stdin.readline().rstrip().split()]
a = [0] + [int(x) for x in stdin.readline().rstrip().split()]

m = 0
b = [1]

c = 1
for i in range(k):
    c = a[c]
    if c not in b:
        b.append(c)
        if i == k-1: print(c); sys.exit()
    else:
        break

idx = b.index(c)
bn = len(b[idx:])
sn = len(b[:idx])

# print(b,idx,sn,bn)
kk = (k-sn) % bn
print(b[idx+kk])

Fixed submission:
from sys import stdin
import sys
import math
from functools import reduce
import functools
import itertools
from collections import deque

n,k = [int(x) for x in stdin.readline().rstrip().split()]
a = [0] + [int(x) for x in stdin.readline().rstrip().split()]

m = 0
b = [1]
visited = [-1 for i in range(n+1)]

c = 1
visited[1] = 1
for i in range(n):
    c = a[c]
    if visited[c] != 1:
        b.append(c)
        visited[c] = 1
        if i == k-1:
            print(c)
            sys.exit()
    else:
        break

idx = b.index(c)
bn = len(b[idx:])
sn = len(b[:idx])

# print(b,idx,sn,bn)
kk = (k-sn) % bn
print(b[idx+kk])
Buggy python submission (verdict: Time Limit Exceeded):
from sys import stdin
import sys
import math
from functools import reduce
import itertools

a,b,n = [int(x) for x in stdin.readline().rstrip().split()]

maxc = -10**5
for i in range(n+1):
    c = int(a*i/b) - a*int(i/b)
    maxc = max([maxc, c])

print(maxc)

Fixed submission:
from sys import stdin
import sys
import math
from functools import reduce
import functools
import itertools
from collections import deque,Counter,defaultdict
from operator import mul
import copy
# ! /usr/bin/env python
# -*- coding: utf-8 -*-
import heapq
sys.setrecursionlimit(10**6)
# INF =  float("inf")
INF = 10**18
import bisect
import statistics
mod = 10**9+7
# mod = 998244353

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

if N >= B-1:
    print(A*(B-1)//B)
else:
    print(A*N//B)
Buggy python submission (verdict: Time Limit Exceeded):
from sys import stdin
import sys
import math
from functools import reduce
import functools
import itertools
from collections import deque,Counter
from operator import mul
import copy
# ! /usr/bin/env python
# -*- coding: utf-8 -*-
import heapq

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

if n % 2 == 1:
    for i in range(1,m+1):
        print(i,n-i+1)
    sys.exit()

else:
    a = [0]*n
    i = 0
    j = 1
    while True:
        if a[i % n] == 0 and a[(i+j) % n] == 0:
            a[i % n] = 1
            a[(i+j) % n] = 1
            print((i % n) + 1, ((i+j) % n) +1)
            j = j + 1
        else:
            i = i + 1
            
        if len(a) == m: sys.exit()




Fixed submission:
from sys import stdin
import sys
import math
from functools import reduce
import functools
import itertools
from collections import deque,Counter
from operator import mul
import copy
# ! /usr/bin/env python
# -*- coding: utf-8 -*-
import heapq

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

p = m // 2
for i in range(p):
    print(p-i,p+2+i)

q = m // 2 + 1
if m % 2 == 1:
    for i in range(q):
        print(m+q-i,m+q+i+1)
else:
    for i in range(q-1):
        print(m+q-i,m+q+i+1)

Buggy python submission (verdict: Time Limit Exceeded):
from sys import stdin
import sys
import math
from functools import reduce
import functools
import itertools
from collections import deque,Counter
from operator import mul
import copy
# ! /usr/bin/env python
# -*- coding: utf-8 -*-
import heapq

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

if n % 2 == 1:
    for i in range(1,m+1):
        print(i,n-i+1)
    sys.exit()

else:
    a = [0]*n
    i = 0
    j = 1
    while True:
        if a[i % n] == 0 and a[(i+j) % n] == 0:
            a[i % n] = 1
            a[(i+j) % n] = 1
            print((i % n) + 1, ((i+j) % n) +1)
            j = j + 1
        else:
            i = i + 1




Fixed submission:
from sys import stdin
import sys
import math
from functools import reduce
import functools
import itertools
from collections import deque,Counter
from operator import mul
import copy
# ! /usr/bin/env python
# -*- coding: utf-8 -*-
import heapq

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

p = m // 2
for i in range(p):
    print(p-i,p+2+i)

q = m // 2 + 1
if m % 2 == 1:
    for i in range(q):
        print(m+q-i,m+q+i+1)
else:
    for i in range(q-1):
        print(m+q-i,m+q+i+1)
Buggy python submission (verdict: Time Limit Exceeded):
from sys import stdin
import math
from functools import reduce

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

k = int(stdin.readline().rstrip())

d = 0
for i in range(1,k+1):
    for j in range(1,k+1):
        for l in range(1,k+1):
            d = d + reduce(gcd, [i,j,l])

print (d)

Fixed submission:
from sys import stdin
import math
from functools import reduce

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

k = int(stdin.readline().rstrip())

d = 0
for i in range(1,k+1):
    for j in range(i+1,k+1):
        for l in range(j+1,k+1):
            d = d + 6*reduce(gcd, [i,j,l])

for i in range(1,k+1):
    for j in range(1,k+1):
        if j != i: d = d + 3*reduce(gcd, [i,j])

for i in range(1,k+1):
    d = d + i

print (d)