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

a, b = map(int, input().split())

def cf(x1,x2):
    cf=[]
    for i in range(1, min(x1,x2)+1):
        if x1 % i == 0 and x2 % i == 0:
            cf.append(i)
    return cf

def is_prime(n):
    if n == 1: return False

    for k in range(2, int(math.sqrt(n)) + 1):
        if n % k == 0:
            return False
    return True

cf = cf(a, b)
counter = 0
for i in cf:
    if is_prime(i) or i == 1:
        counter += 1
print(counter)

Fixed submission:
import math

a, b = map(int, input().split())

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

def is_prime(n):
    if n == 1: return False

    for k in range(2, int(math.sqrt(n)) + 1):
        if n % k == 0:
            return False
    return True

divisors_a = set(make_divisors(a))
divisors_b = set(make_divisors(b))

common_divisors = []
for a in divisors_a:
    if a in divisors_b:
        common_divisors.append(a)

counter = 0
for i in common_divisors:
    if is_prime(i) or i == 1:
        counter += 1
print(counter)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())

output = 0
for i in range(n):
    output += i
print(output)

Fixed submission:
n = int(input())

output = (n * (n - 1)) // 2
print(output)

Buggy python submission (verdict: Runtime Error):
n = int(input())

print(sum(list(range(n))))

Fixed submission:
n = int(input())

output = (n * (n - 1)) // 2
print(output)
Buggy python submission (verdict: Runtime Error):
import math
a, b, c, d = map(int, input().split())

#a~bでnで割り切れるものの数
def func(a, b, n):
    answer = (int(b/n) - int((a-1)/n))
    return answer

lcm = (c * d) //math.gcd(c, d)

print ((b -a + 1) - func(a,b,c) - func(a,b,d) + func(a,b,lcm))

Fixed submission:
import fractions
a, b, c, d = map(int, input().split())

#a~bでnで割り切れるものの数
def func(a, b, n):
    answer = (int(b/n) - int((a-1)/n))
    return answer

lcm = int((c * d) / fractions.gcd(c, d))

#print ((b - a + 1) - func(a,b,c) - func(a,b,d) + func(a,b,lcm))

#b以下でc,dで割り切れない数
b_anti_devide = b - b//c - b//d + b//lcm
#a未満でc,dで割り切れない数
a_anti_devide = (a - 1) - (a - 1)//c - (a - 1)//d + (a - 1)//lcm

print (b_anti_devide - a_anti_devide)
Buggy python submission (verdict: Runtime Error):
from operator import itemgetter

city_point_list = []
N = int(input())
for i in range(N):
    c, p = input().split()
    city_point_list.append(c, int(p))

cp_num_dict = {}
for i in range(city_point_list):
    cp_num_dict[city_point_list[i]] = i + 1

point_sort_rev = sorted(city_point_list, key=itemgetter(1), reverse=True)
city_sort = sorted(point_sort_rev, key=itemgetter(0))

for cp in city_sort:
    print (cp_num_dict[cp])

Fixed submission:
# -*- coding: utf-8 -*-

from operator import itemgetter

N = int(input())
SP_list = []
SP_dict = {}
for i in range(N):
    name, point = input().split()
    pair = (name, int(point))
    SP_list.append(pair)
    SP_dict[pair] = i + 1

for i in range(len(SP_list)):
    SP_dict[SP_list[i]] = i + 1

point_sorted = sorted(SP_list, key=itemgetter(1), reverse=True)
name_sorted = sorted(point_sorted, key=itemgetter(0))

for pair in name_sorted:
    print (SP_dict[pair])
Buggy python submission (verdict: Time Limit Exceeded):
# -*- coding: utf-8 -*-

R, G, B, N = map(int, input().split())

lst = [R, G, B]
lst.sort(reverse=True)
R = lst[0]
G = lst[1]
B = lst[2]

counter = 0
for r in range(int(N/R) + 1):
    for g in range(int(N/G) + 1):
        if R*r + G*g > N:
            break
        if (N - R*r - G*g) % B == 0:
            counter += 1

print(counter)

Fixed submission:
# -*- coding: utf-8 -*-

R, G, B, N = map(int, input().split())

counter = 0
for r in range(int(N/R) + 1):
    for g in range(int(N/G) + 1):
        t = R*r + G*g
        if t > N:
            break
        if (N - t) % B == 0:
            counter += 1

print(counter)

Buggy python submission (verdict: Time Limit Exceeded):
# -*- coding: utf-8 -*-

R, G, B, N = map(int, input().split())

counter = 0
for r in range(int(N/R) + 1):
    for g in range(int(N/G) + 1):
        if R*r + G*g > N:
            break
        if (N - R*r - G*g) % B == 0:
            counter += 1

print(counter)

Fixed submission:
# -*- coding: utf-8 -*-

R, G, B, N = map(int, input().split())

counter = 0
for r in range(int(N/R) + 1):
    for g in range(int(N/G) + 1):
        t = R*r + G*g
        if t > N:
            break
        if (N - t) % B == 0:
            counter += 1

print(counter)
Buggy python submission (verdict: Time Limit Exceeded):
# -*- coding: utf-8 -*-
N, Q = map(int, input().split())
S = input()
question_list = []

for i in range(Q):
    l, r = map(int, input().split())
    question_list.append((l, r))

cut_s = S
index_list = []
for i in range(1, N):
    if S[i] == 'C' and S[i - 1] == 'A':
        index_list.append(i - 1)

for lr in question_list:
    l = lr[0]
    r = lr[1]
    num = 0
    for i in range(l - 1, r - 1):
        if i in index_list:
            num += 1
    print(num)

Fixed submission:
# -*- coding: utf-8 -*-
N, Q = map(int, input().split())
S = input()
question_list = []

for i in range(Q):
    l, r = map(int, input().split())
    question_list.append((l, r))

total_list = [0] * N
for i in range(N - 1):
    if S[i] == 'A' and S[i + 1] == 'C':
        total_list[i + 1] = total_list[i] + 1
    else:
        total_list[i + 1] = total_list[i]

for lr in question_list:
    l = lr[0]
    r = lr[1]
    num = total_list[r - 1] - total_list[l - 1]
    print(num)

Buggy python submission (verdict: Time Limit Exceeded):
# -*- coding: utf-8 -*-
N, Q = map(int, input().split())
S = input()
question_list = []

for i in range(Q):
    l, r = map(int, input().split())
    question_list.append((l, r))

cut_s = S
index_list = []
while True:
    index = cut_s.find('AC')
    if index != -1:
        if index_list == []:
            index_list.append(index)
        else:
            index_list.append(index + index_list[-1] + 1)
        cut_s = cut_s[index + 1:]
    else:
        break

for lr in question_list:
    l = lr[0]
    r = lr[1]
    num = 0
    for i in range(l - 1, r - 1):
        if i in index_list:
            num += 1
    print(num)

Fixed submission:
# -*- coding: utf-8 -*-
N, Q = map(int, input().split())
S = input()
question_list = []

for i in range(Q):
    l, r = map(int, input().split())
    question_list.append((l, r))

total_list = [0] * N
for i in range(N - 1):
    if S[i] == 'A' and S[i + 1] == 'C':
        total_list[i + 1] = total_list[i] + 1
    else:
        total_list[i + 1] = total_list[i]

for lr in question_list:
    l = lr[0]
    r = lr[1]
    num = total_list[r - 1] - total_list[l - 1]
    print(num)
Buggy python submission (verdict: Time Limit Exceeded):
# -*- coding: utf-8 -*-

N, K = map(int, input().split())
h_list = [int(input()) for i in range(N)]

h_list.sort()
best = 1000000000
for i in range(N - K + 1):
    diff = h_list[i:i+K][-1] - h_list[i:i+K][0]
    if diff < best:
        best = diff

print (best)

Fixed submission:
# -*- coding: utf-8 -*-

N, K = map(int, input().split())
h_list = [int(input()) for i in range(N)]

h_list.sort()
'''
best = 1000000000
for i in range(N - K + 1):
    diff = h_list[i:i+K][-1] - h_list[i:i+K][0]
    if diff < best:
        best = diff
'''
print (min(h_list[i+K-1] - h_list[i] for i in range(N-K+1)))
Buggy python submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-

import sys

args = sys.argv

a_value = int(args[1])
b_value = int(args[2])
c_value = int(args[3])
a_number = int(args[4])
b_number = int(args[5])

value = 0

if a_value + b_value <= c_value * 2:
    value = a_value * a_number + b_value * b_number
    print (value)
else:
    if a_number >= b_number:
        value += c_value * 2 * b_number
        if (a_number - b_number) * a_value >= (a_number - b_number) * c_value * 2:
            value += (a_number - b_number) * c_value * 2
        else:
            value += (a_number - b_number) * a_value

    else:
        value += c_value * 2 * a_number
        if (b_number - a_number) * b_value >= (b_number - a_number) * c_value * 2:
            value += (b_number - a_number) * c_value * 2
        else:
            value += (b_number - a_number) * a_value
    print (value)

Fixed submission:
# -*- coding: utf-8 -*-

import sys

lst = list(map(int, input().split()))

a_value = lst[0]
b_value = lst[1]
c_value = lst[2]
a_number = lst[3]
b_number = lst[4]

value = 0

if a_value + b_value <= c_value * 2:
    value = a_value * a_number + b_value * b_number
    print (value)
else:
    if a_number >= b_number:
        value += c_value * 2 * b_number
        if (a_number - b_number) * a_value >= (a_number - b_number) * c_value * 2:
            value += (a_number - b_number) * c_value * 2
        else:
            value += (a_number - b_number) * a_value

    else:
        value += c_value * 2 * a_number
        if (b_number - a_number) * b_value >= (b_number - a_number) * c_value * 2:
            value += (b_number - a_number) * c_value * 2
        else:
            value += (b_number - a_number) * b_value
    print (value)
Buggy python submission (verdict: Time Limit Exceeded):
def main():
    n, m = map(int, input().split())
    ac = 0
    wa = 0
    a = []
    b = {}
    for _ in range(m):
        q, j = input().split()
        if q in a:
            continue
        if q not in a and j == 'AC':
            ac += 1
            a.append(q)
            if q in b:
                wa += b[q]
        else:
            if q not in b:
                b[q] = 0
            b[q] += 1
    print(ac, wa)

if __name__ == "__main__":
    main()


Fixed submission:
import sys
from collections import defaultdict
input = sys.stdin.readline

def main():
    n, m = map(int, input().split())
    ac = 0
    wa = 0
    b = defaultdict(lambda: 0)
    for _ in range(m):
        q, j = input().split()
        if b[q] != -1 and j == 'AC':
            ac += 1
            if q in b:
                wa += b[q]
                b[q] = -1
        else:
            if b[q] != -1:
                b[q] += 1
    print(ac, wa)

if __name__ == "__main__":
    main()

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

n, m = map(int, input().split())
ac = 0
wa = 0
a = []
b = defaultdict(int)
for _ in range(m):
    q, j = input().split()
    if q in a:
        continue
    if q not in a and j == 'AC':
        ac += 1
        a.append(q)
        if q in b:
            wa += b[q]
    else:
        b[q] += 1
print(ac, wa)


Fixed submission:
import sys
from collections import defaultdict
input = sys.stdin.readline

def main():
    n, m = map(int, input().split())
    ac = 0
    wa = 0
    b = defaultdict(lambda: 0)
    for _ in range(m):
        q, j = input().split()
        if b[q] != -1 and j == 'AC':
            ac += 1
            if q in b:
                wa += b[q]
                b[q] = -1
        else:
            if b[q] != -1:
                b[q] += 1
    print(ac, wa)

if __name__ == "__main__":
    main()

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

n, m = map(int, input().split())
ac = 0
wa = 0
a = []
b = defaultdict(int)
for _ in range(m):
    q, j = input().split()
    if q not in a and j == 'AC':
        ac += 1
        a.append(q)
        if q in b:
            wa += b[q]
    else:
        b[q] += 1
print(ac, wa)


Fixed submission:
import sys
from collections import defaultdict
input = sys.stdin.readline

def main():
    n, m = map(int, input().split())
    ac = 0
    wa = 0
    b = defaultdict(lambda: 0)
    for _ in range(m):
        q, j = input().split()
        if b[q] != -1 and j == 'AC':
            ac += 1
            if q in b:
                wa += b[q]
                b[q] = -1
        else:
            if b[q] != -1:
                b[q] += 1
    print(ac, wa)

if __name__ == "__main__":
    main()
Buggy python submission (verdict: Time Limit Exceeded):
a, b, k = map(int, input().split())
for _ in range(k):
    if a >= 1:
        a -= 1
    elif b >= 1:
        b -= 1
print(a, b)


Fixed submission:
a, b, k = map(int, input().split())
if k >= a:
    b -= k-a
    a = 0
else:
    a -= k
print(max(a, 0), max(b, 0))
Buggy python submission (verdict: Runtime Error):
def is_prime2(q,k=100):
    q = abs(q)
    if q == 2: return True
    if q < 2 or q&1 == 0: return False
    for i in xrange(3,k):
        x,y = q,i
        while y:
            x, y =  y, x % y
        if x != 1: continue
        if pow(i, q-1, q) != 1:
            return False
    return True

c = int(input())
for i in range(c, 10**6):
    if is_prime(i):
        print(i)
        break


Fixed submission:
def is_prime2(q,k=100):
    q = abs(q)
    if q == 2: return True
    if q < 2 or q&1 == 0: return False
    for i in range(3,k):
        x,y = q,i
        while y:
            x, y =  y, x % y
        if x != 1: continue
        if pow(i, q-1, q) != 1:
            return False
    return True

c = int(input())
for i in range(c, 10**6):
    if is_prime2(i):
        print(i)
        break
Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline

def main():
    N = int(input())
    *A, = map(int, input().split())
    ans = 0
    B = [0] * 61
    for k, a in enumerate(A):
        *la, = map(int, list(bin(a))[2:])
        j = 0
        for i in range(61-len(la), 61):
            B[i] += la[j]
            j += 1

    ans = 0
    mod = 10**9 + 7
    for i, b in enumerate(B):
        ans += b * (len(A)-b) * 2**(60-i) % mod
    print(ans % mod)


if __name__ == "__main__":
    main()


Fixed submission:
n = int(input())
A = list(map(int, input().split()))
mod = 10**9+7
array = [0] * 60
for a in A:
    for j in range(len(bin(a))-2):
        array[j] += (a >> j) & 1
ans = 0
for i in range(60):
    ans += array[i] * (n-array[i]) * 2**i
print(ans % mod)

Buggy python submission (verdict: Time Limit Exceeded):
def main():
    N = int(input())
    *A, = map(int, input().split())
    ans = 0
    B = [0] * 61
    for k, a in enumerate(A):
        la = list(bin(a))[2:]
        j = 0
        for i in range(61-len(la), 61):
            B[i] += int(la[j])
            j += 1

    ans = 0
    mod = 10**9 + 7
    for i, b in enumerate(B):
        ans += b * (len(A)-b) * 2**(60-i) % mod
    print(ans % mod)

if __name__ == "__main__":
    main()


Fixed submission:
n = int(input())
A = list(map(int, input().split()))
mod = 10**9+7
array = [0] * 60
for a in A:
    for j in range(len(bin(a))-2):
        array[j] += (a >> j) & 1
ans = 0
for i in range(60):
    ans += array[i] * (n-array[i]) * 2**i
print(ans % mod)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
*A, = map(int, input().split())
ans = 0
B = [0] * 61
for k, a in enumerate(A):
    la = list(bin(a))[2:]
    j = 0
    for i in range(61-len(la), 61):
        B[i] += int(la[j])
        j += 1

ans = 0
mod = 10**9 + 7
for i, b in enumerate(B):
    ans += b * (len(A)-b) * 2**(60-i) % mod
print(ans % mod)


Fixed submission:
n = int(input())
A = list(map(int, input().split()))
mod = 10**9+7
array = [0] * 60
for a in A:
    for j in range(len(bin(a))-2):
        array[j] += (a >> j) & 1
ans = 0
for i in range(60):
    ans += array[i] * (n-array[i]) * 2**i
print(ans % mod)
Buggy python submission (verdict: Runtime Error):
h, w, k = map(int, input().split())
m = []
for i in range(h):
    m.append(list(input()))

ans = []
for i in range(h):
    ans.append([0 for _ in range(w)])

if m[0][0] == '#':
    c = 0
else:
    c = 1
emp = []
for i in range(h):
    s1 = 0
    s = m[i].count('#')
    # 行に一つもいちごがない
    if s == 0:
        emp.append(i)
        continue
    for j in range(w):
        flag = 0
        if m[i][0] == '#':
            if m[i][j] == '#':
                if s1 < s and c < k:
                    s1 += 1
                    c += 1
            ans[i][j] = c
        else:
            ans[i][j] = c
            if m[i][j] == '#':
                flag = 1
                if s1 < s-1 and c < k:
                    s1 += 1
                    c += 1
    if i != h-1 and m[i+1][0] != '#':
        c += 1

for e in emp:
    for j in range(w):
        idx = []
        if e == 0:
            for i1 in range(1, h):
                if ans[i1][0] != 0:
                    idx = ans[i1]
                    break
            ans[e][j] = idx[j]
        elif e == h-1:
            for i1 in list(range(h-1))[::-1]:
                if ans[i1][0] != 0:
                    idx = ans[i1]
                    break
            ans[e][j] = idx[j]
        else:
            for i1 in range(e+1, i+1):
                if ans[i1][0] != 0:
                    idx = ans[i1]
                    break
            ans[e][j] = idx[j]

for i in ans:
    print(' '.join(map(str, i)))


Fixed submission:
h, w, k = map(int, input().split())
m = []
for i in range(h):
    m.append(list(input()))

ans = []
for i in range(h):
    ans.append([0 for _ in range(w)])

if m[0][0] == '#':
    c = 0
else:
    c = 1
emp = []
for i in range(h):
    s1 = 0
    s = m[i].count('#')
    # 行に一つもいちごがない
    if s == 0:
        emp.append(i)
        continue
    for j in range(w):
        flag = 0
        if m[i][0] == '#':
            if m[i][j] == '#':
                if s1 < s and c < k:
                    s1 += 1
                    c += 1
            ans[i][j] = c
        else:
            ans[i][j] = c
            if m[i][j] == '#':
                flag = 1
                if s1 < s-1 and c < k:
                    s1 += 1
                    c += 1
    if i != h-1 and m[i+1][0] != '#':
        c += 1

if 0 in emp:
    for j in range(w):
        for i1 in range(1, h):
            if ans[i1][0] != 0:
                idx = ans[i1]
                break
        ans[0][j] = idx[j]
    emp.remove(0)
if h-1 in emp:
    for j in range(w):
        for i1 in list(range(h-1))[::-1]:
            if ans[i1][0] != 0:
                idx = ans[i1]
                break
        ans[h-1][j] = idx[j]
    emp.remove(h-1)
for e in emp:
    for j in range(w):
        idx = []
        for i1 in range(e+1, h):
            if ans[i1][0] != 0:
                idx = ans[i1]
                break
        ans[e][j] = idx[j]

for i in ans:
    print(' '.join(map(str, i)))
Buggy python submission (verdict: Time Limit Exceeded):
def count_sort(arr):
    max_num = max(arr)
    min_num = min(arr)
    count = [0] * (max_num - min_num + 1)
    for ele in arr:
        count[ele - min_num] += 1

    return [ele for ele, cnt in enumerate(count, start=min_num) for __ in range(cnt)]


n = int(input())
L = list(map(int, input().split()))
L = count_sort(L)
count = 0
for i, l1 in enumerate(L):
    for k, l2 in enumerate(L[i+1:]):
        num = i + k + 2
        for l3 in L[num:]:
            if l1 + l2 < l3:
                break
            if l1 < l2 + l3 and l2 < l1 + l3 and l3 < l2 + l1:
                count += 1
            else:
                break

print(count)


Fixed submission:
import bisect

n = int(input())
L = list(map(int, input().split()))
L.sort()
count = 0

for i in range(n-2):
    for j in range(i+1, n-1):
        k = bisect.bisect_left(L[j+1:], L[i]+L[j])
        count += k

print(count)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
L = list(map(int, input().split()))
L.sort()
count = 0
for i, l1 in enumerate(L):
    for k, l2 in enumerate(L[i+1:]):
        num = i + k + 2
        for l3 in L[num:]:
            if l1 + l2 < l3:
                break
            if l1 < l2 + l3 and l2 < l1 + l3 and l3 < l2 + l1:
                count += 1
            else:
                break

print(count)


Fixed submission:
import bisect

n = int(input())
L = list(map(int, input().split()))
L.sort()
count = 0

for i in range(n-2):
    for j in range(i+1, n-1):
        k = bisect.bisect_left(L[j+1:], L[i]+L[j])
        count += k

print(count)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
L = list(map(int, input().split()))
L.sort()
count = 0
for i, l1 in enumerate(L):
    for k, l2 in enumerate(L[i+1:]):
        num = i + k + 2
        for l3 in L[num:]:
            if l1 < l2 + l3 and l2 < l1 + l3 and l3 < l2 + l1:
                count += 1
            else:
                break

print(count)


Fixed submission:
import bisect

n = int(input())
L = list(map(int, input().split()))
L.sort()
count = 0

for i in range(n-2):
    for j in range(i+1, n-1):
        k = bisect.bisect_left(L[j+1:], L[i]+L[j])
        count += k

print(count)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
L = list(map(int, input().split()))
L.sort()
count = 0
for i, l1 in enumerate(L):
    a = l1
    for k, l2 in enumerate(L[i+1:]):
        b = l2
        num = i + k + 2
        if num >= n:
            continue
        while L[num] < a + b:
            c = L[num]
            if a < b + c and b < a + c and c < b + a:
                count += 1
            num += 1
            if num == n:
                break

print(count)


Fixed submission:
import bisect

n = int(input())
L = list(map(int, input().split()))
L.sort()
count = 0

for i in range(n-2):
    for j in range(i+1, n-1):
        k = bisect.bisect_left(L[j+1:], L[i]+L[j])
        count += k

print(count)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int, input().split(' ')))
d = {}
for i in range(1, n+1):
    d[i] = a[i-1]

sorted = sorted(d.items(), key=lambda x: x[1])

ans = ''
for k, v in sorted:
    ans += str(k) + ' '
print(ans)

Fixed submission:
n = int(input())
a = list(map(int, input().split(' ')))
ans = [0] * n
for i in range(n):
    h = a[i] - 1
    ans[h] = i + 1
print(' '.join(map(str, ans)))
Buggy python submission (verdict: Runtime Error):
n, k = map(int, input().split())
S = input()
s = S.split("L")
s = [i for i in s if i != '']
s.sort(reverse=True)
cnt = 0
for i in range(k):
    cnt += len(s[i])
    s.remove(s[i])
for i in s:
    if len(i) >= 2:
        cnt += len(i) - 1
r = S.split('R')
for i in r:
    if len(i) >= 2:
        cnt += len(i) - 1
    if len(i) == 1 and k > 0:
        cnt += 1
        k -= 1
print(cnt)


Fixed submission:
n, k = map(int, input().split())
s = input()
cnt = 0
for i in range(n-1):
    if s[i] == s[i+1]:
        cnt += 1
ans = min(cnt+2*k, n-1)
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
ans = 0
for i in range(1, n):
    ans += i
print(ans)


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