Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
import math
def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))


n, m, k = map(int, input().split())
cmb = combinations_count(n * m - 2, k - 2)
ans = 0
for i in range(1, n):
    ans += i * cmb * m * m * (n - i)
    ans %= 10 ** 9 + 7

for i in range(m):
    ans += i * cmb * n * n * (m - i)
    ans %= 10 ** 9 + 7

print(ans % (10 ** 9 + 7))

Fixed submission:
import math
def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))


n, m, k = map(int, input().split())
cmb = combinations_count(n * m - 2, k - 2)
cmb %= 10 ** 9 + 7
ans = 0
for i in range(1, n):
    ans += i * cmb * m * m * (n - i)
    ans %= 10 ** 9 + 7

for i in range(1, m):
    ans += i * cmb * n * n * (m - i)
    ans %= 10 ** 9 + 7

print(ans % (10 ** 9 + 7))

Buggy python submission (verdict: Time Limit Exceeded):
import math
def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))


n, m, k = map(int, input().split())
cmb = combinations_count(n * m - 2, k - 2)
ans = 0
for i in range(n):
    for j in range(i, n):
        if i < j:
            ans += abs(i - j) * cmb * m * m
            ans %= 10 ** 9 + 7

for i in range(m):
    for j in range(i, m):
        if i < j:
            ans += abs(i - j) * cmb * n * n
            ans %= 10 ** 9 + 7

print(ans % (10 ** 9 + 7))

Fixed submission:
import math
def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))


n, m, k = map(int, input().split())
cmb = combinations_count(n * m - 2, k - 2)
cmb %= 10 ** 9 + 7
ans = 0
for i in range(1, n):
    ans += i * cmb * m * m * (n - i)
    ans %= 10 ** 9 + 7

for i in range(1, m):
    ans += i * cmb * n * n * (m - i)
    ans %= 10 ** 9 + 7

print(ans % (10 ** 9 + 7))
Buggy python submission (verdict: Time Limit Exceeded):


R, G, B, N = map(int, input().split())
rgb = []
for i in range(N + 1):
    for j in range(N - i + 1):
        key = i * R + j * G
        key = N - key
        if key % B == 0 and key / B >= 0:
            rgb.append([i, j, key // B])

#print(rgb)
print(len(rgb))

Fixed submission:


R, G, B, N = map(int, input().split())
rgb = []
for i in range(N + 1):
    for j in range(N - (i * R) + 1):
        key = i * R + j * G
        key = N - key
        if key % B == 0 and key / B >= 0:
            rgb.append([i, j, key // B])

#print(rgb)
print(len(rgb))
Buggy python submission (verdict: Runtime Error):
n = int(input())
i = 1
ans = 0
while i * i <= n:
    m = n / i - 1
    if m == int(m) and n // m == n % m:
        ans += int(m)
    i += 1
print(ans)

Fixed submission:
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

while True:
    N = int(input())
    ans_list = sorted(make_divisors(N))
    ans = 0
    #print(ans_list)
    for i in ans_list:
        m = N // i - 1
        if N < m * m:
            #print(i)
            #print(N // i - 1)
            ans += (N // i - 1)

    print(ans)
    break
Buggy python submission (verdict: Runtime Error):
import math
n = int(input())
a = list(map(int, input().split()))
if n <= 2:
    print(max(a))
else:
    gcd_left = [a[0]]
    gcd_right = [a[-1]]
    for i in range(1, n):
        gcd_left.append(math.gcd(a[i], gcd_left[-1]))
        gcd_right.append(math.gcd(a[n-i-1], gcd_right[-1]))
    gcd_right = gcd_right[::-1]
    print(gcd_left, gcd_right)
    ans = max(gcd_left[-2], gcd_right[1])
    for i in range(n-2):
        ans = max(ans, math.gcd(gcd_right[i+2], gcd_left[i]))
    print(ans)

Fixed submission:
import fractions
n = int(input())
a = list(map(int, input().split()))
if n <= 2:
    print(max(a))
else:
    gcd_left = [a[0]]
    gcd_right = [a[-1]]
    for i in range(1, n):
        gcd_left.append(fractions.gcd(a[i], gcd_left[-1]))
        gcd_right.append(fractions.gcd(a[n-i-1], gcd_right[-1]))
    gcd_right = gcd_right[::-1]
    # print(gcd_left, gcd_right)
    ans = max(gcd_left[-2], gcd_right[1])
    for i in range(n-2):
        ans = max(ans, fractions.gcd(gcd_right[i+2], gcd_left[i]))
    print(ans)

Buggy python submission (verdict: Runtime Error):
import fractions
n = int(input())
a = list(map(int, input().split()))

this_gcd = max(a)
gcd_list = []

for i in a:
    this_gcd = fractions.gcd(this_gcd, i)

for I in range(len(a)):
    i = a[I]
    tmp = i // this_gcd
    key = 1
    for j in range(2, int(fractions.sqrt(tmp)) + 1):
        if tmp % j == 0:
            key = 0

    if key:
        del a[I]
        break

this_gcd = max(a)
for i in a:
    this_gcd = fractions.gcd(this_gcd, i)

print(this_gcd)

Fixed submission:
import fractions
n = int(input())
a = list(map(int, input().split()))
if n <= 2:
    print(max(a))
else:
    gcd_left = [a[0]]
    gcd_right = [a[-1]]
    for i in range(1, n):
        gcd_left.append(fractions.gcd(a[i], gcd_left[-1]))
        gcd_right.append(fractions.gcd(a[n-i-1], gcd_right[-1]))
    gcd_right = gcd_right[::-1]
    # print(gcd_left, gcd_right)
    ans = max(gcd_left[-2], gcd_right[1])
    for i in range(n-2):
        ans = max(ans, fractions.gcd(gcd_right[i+2], gcd_left[i]))
    print(ans)

Buggy python submission (verdict: Runtime Error):
import math
n = int(input())
a = list(map(int, input().split()))

this_gcd = max(a)
gcd_list = []

for i in a:
    this_gcd = math.gcd(this_gcd, i)

for I in range(len(a)):
    i = a[I]
    tmp = i // this_gcd
    key = 1
    for j in range(2, int(math.sqrt(tmp)) + 1):
        if tmp % j == 0:
            key = 0

    if key:
        del a[I]
        break

this_gcd = max(a)
for i in a:
    this_gcd = math.gcd(this_gcd, i)

print(this_gcd)

Fixed submission:
import fractions
n = int(input())
a = list(map(int, input().split()))
if n <= 2:
    print(max(a))
else:
    gcd_left = [a[0]]
    gcd_right = [a[-1]]
    for i in range(1, n):
        gcd_left.append(fractions.gcd(a[i], gcd_left[-1]))
        gcd_right.append(fractions.gcd(a[n-i-1], gcd_right[-1]))
    gcd_right = gcd_right[::-1]
    # print(gcd_left, gcd_right)
    ans = max(gcd_left[-2], gcd_right[1])
    for i in range(n-2):
        ans = max(ans, fractions.gcd(gcd_right[i+2], gcd_left[i]))
    print(ans)
Buggy python submission (verdict: Runtime Error):
N, K = map(int, input().split())
s = list(input())

cnt = 1
cntlist = []
for i in range(1, N):
    if s[i - 1] != s[i]:
        cntlist.append(cnt)
        cnt = 1
    else:
        cnt += 1

cntlist.append(cnt)
if s[0] == "0":
    cntlist = [0] + cntlist

ans = 0
for i in range(2 * K + 1):
    if i >= len(cntlist):
        break
    ans += cntlist[i]
anslist = [ans]
s = 0
g = 2 * K + 1
while g < len(cntlist):
    ans -= cntlist[s]
    ans -= cntlist[s + 1]
    s += 2
    ans += cntlist[g]
    g += 1

    ans += cntlist[g]
    if g >= len(cntlist):
        break
    g += 1
    anslist.append(ans)

print(max(anslist))

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

cnt_list = []
i = 0
if s[0] == "0":
    key = "0"
else:
    key = "1"
last = 0
while i < N:
    j = i
    tmp = 1
    for j in range(i + 1, N):
        if s[j] == key:
            tmp += 1
            if j == N - 1:
                last = 1
        else:
            break

    cnt_list.append([int(key), tmp])

    if key == "0":
        key = "1"
    else:
        key = "0"
    i = max(j, i + 1)
    if last:
        break

cnt = K
i = 0
tmp = 0
while cnt > 0 and i < len(cnt_list):
    tmp += cnt_list[i][1]
    if cnt_list[i][0] == 0:
        cnt -= 1
    i += 1

if i < len(cnt_list):
    tmp += cnt_list[i][1]
    i += 1

anslist = []
anslist.append(tmp)

start = 0
while i < len(cnt_list) and start < len(cnt_list):
    if cnt_list[start][0] == 1:
        tmp -= cnt_list[start][1]
        if start + 1 < len(cnt_list):
            tmp -= cnt_list[start + 1][1]
        start += 2
    else:
        tmp -= cnt_list[start][1]
        start += 1

    if cnt_list[i][0] == 0:
        tmp += cnt_list[i][1]
        if i + 1 < len(cnt_list):
            tmp += cnt_list[i + 1][1]
        i += 2
    else:
        tmp += cnt_list[i][1]
        i += 1
    anslist.append(tmp)

print(max(anslist))
Buggy python submission (verdict: Time Limit Exceeded):
x, y, z, k = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
A.sort()
B.sort()
C.sort()

A = A[::-1]
B = B[::-1]
C = C[::-1]

anslist = []

for i in range(len(A)):
    if i > k:
        break
    for j in range(len(B)):
        if i * j > k:
            break
        for l in range(len(C)):
            if i * j * l > k:
                break
            anslist.append(A[i] + B[j] + C[l])

anslist.sort()

anslist = anslist[::-1]

for i in range(k):
    print(anslist[i])


Fixed submission:
x, y, z, k = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
A.sort()
B.sort()
C.sort()

A = A[::-1]
B = B[::-1]
C = C[::-1]

anslist = []

for i in range(len(A)):
    if i > k:
        break
    for j in range(len(B)):
        if i * j > k:
            break
        for l in range(len(C)):
            if (i + 1) * (j + 1) * (l + 1) > k:
                break
            anslist.append(A[i] + B[j] + C[l])

anslist.sort()

anslist = anslist[::-1]

for i in range(k):
    print(anslist[i])
Buggy python submission (verdict: Runtime Error):
import fraction
N = int(input())
A = list(map(int, input().split()))
import math
A.sort()
ans = 10000000000000000000000000000000000000000000

for i in A:
    ans = fraction.gcd(ans, i)

print(ans)

Fixed submission:
import fractions
N = int(input())
A = list(map(int, input().split()))
import math
A.sort()
ans = A[0]

for i in A:
    ans = fractions.gcd(ans, i)

print(ans)
Buggy python submission (verdict: Runtime Error):
def a():
    n, k = map(int, input().split())
    if n - 1 >= K:
        print("YES")
    else:
        print("NO")
a()

Fixed submission:
def a():
    n, k = map(int, input().split())
    if int(n / 2 + 0.5) >= k:
        print("YES")
    else:
        print("NO")
a()
Buggy python submission (verdict: Time Limit Exceeded):
S = list(input())
cnt = 0
i = 0

cnt = 0
while i < len(S) - 1:
    key = i
    #print(i)
    if S[i] == "B" and S[i + 1] == "W":
        S[i] = "W"
        S[i + 1] = "B"
        cnt += 1
        j = i - 1
        while True:
            #print(0, 0, j, S[j], S[j + 1])
            if j < 0:
                break
            if S[j] == "B" and S[j + 1] == "W":
                S[j] = "W"
                S[j + 1] = "B"
                #print(10000)
                cnt += 1
                key = j
                j -= 1
            else:
                break
    i = key
    i += 1
print(cnt)

Fixed submission:

def A():
    S = list(input())
    W = [0 for i in range(len(S))]
    B = [0 for i in range(len(S))]
    ans = 0
    if S[0] == "B":
               B[0] = 1
    else:
        W[0] = 1

    for i in range(1, len(S)):
        B[i] += B[i - 1]
        if S[i] == "B":
            B[i] += 1
        else:
            ans += B[i]
    print(ans)
A()
Buggy python submission (verdict: Runtime Error):
def C3():
    tmp = []
    import  copy

    for i in range(9):
        tmp.append([])
        tmp[i].append(3 * pow(10, i))
        tmp[i].append(5 * pow(10, i))
        tmp[i].append(7 * pow(10, i))

    tmp2 = [copy.copy(tmp[0])]
    for i in range(1, 9):
        tmp2.append([])
        for j in range(3):
            k = 0
            while True:
                if len(tmp2[i - 1]) <= k:
                    break
                tmp2[i].append(tmp[i][j] + tmp2[i - 1][k])
                k += 1
    tmp3 = 

Fixed submission:
def C3():
    tmp = []
    import  copy

    for i in range(9):
        tmp.append([])
        tmp[i].append(3 * pow(10, i))
        tmp[i].append(5 * pow(10, i))
        tmp[i].append(7 * pow(10, i))

    tmp2 = [copy.copy(tmp[0])]
    for i in range(1, 9):
        tmp2.append([])
        for j in range(3):
            k = 0
            while True:
                if len(tmp2[i - 1]) <= k:
                    break
                tmp2[i].append(tmp[i][j] + tmp2[i - 1][k])
                k += 1
    N = int(input())
    tmp3 = []
    for i in range(2, 9):
        for j in range(len(tmp2[i])):
            tmp3.append(tmp2[i][j])
    ans = 0
    for i in tmp3:
        s = 0
        f = 0
        t = 0
        for j in list(str(i)):
            if j == "7":
                s += 1
            if j == "5":
                f += 1
            if j == "3":
                t += 1
        if s != 0 and t != 0 and f != 0 and int(i) <= N:
            ans += 1
    print(ans)

C3()
Buggy python submission (verdict: Runtime Error):
import math
def lcm(x, y):
    return (x * y) // math.gcd(x, y)

def AGC028A():
    N, M = map(int, input().split())
    S = input()
    T = input()
    if len(S) < len(T):
        S, T = T, S
    if lcm(N, M) == max(N, M) and S[0:len(T)] == T:
        print(-1)
        return 0
    key = lcm(N, M)
    n = key // N
    m = key // M
    n_list = []
    for i in range(0, key, n):
        n_list.append(i)
    m_list = []
    for j in range(0, key, m):
        m_list.append(j)
    i = 0
    j = 0
    while True:
        if i >= len(n_list) or j >= len(m_list):
            break
        if n_list[i] == m_list[j]:
            if S[i] != T[j]:
                print(-1)
                return 0
        if n_list[i] > m_list[j]:
            j += 1
        elif n_list[i] < m_list[j]:
            i += 1
        else:
            i += 1
            j += 1
    print(key)

AGC028A()

Fixed submission:
import fractions
def lcm(x, y):
    return (x * y) // fractions.gcd(x, y)

def AGC028A():
    N, M = map(int, input().split())
    S = input()
    T = input()

    key = lcm(N, M)
    n = key // N
    m = key // M
    n_list = []
    for i in range(0, key, n):
        n_list.append(i)
    m_list = []
    for j in range(0, key, m):
        m_list.append(j)

    #print(n_list, m_list)
    i = 0
    j = 0
    while True:
        if i >= len(n_list) or j >= len(m_list):
            break
        if i >= len(S) or j >= len(T):
            break
        if n_list[i] == m_list[j]:
            if S[i] != T[j]:
                print(-1)
                return 0
        if n_list[i] > m_list[j]:
            j += 1
        elif n_list[i] < m_list[j]:
            i += 1
        else:
            i += 1
            j += 1
    print(key)

AGC028A()
Buggy python submission (verdict: Runtime Error):
N = int(input())
xyh = [list(map(int, input().split())) for i in range(N)]

for CX in range(101):
    for CY in range(101):
        ans = True
        i = 0
        for x, y, h in xyh:
            if h != 0:
                if i == 0:
                    H = h + abs(x - CX) + abs(y - CY)
                if H != h + abs(x - CX) + abs(y - CY):
                    ans = False
                    break
            i += 1
            if not ans:
                break
        for x, y, h in xyh:
            if not ans:
                break
            if h == 0:
                if h != max(H - abs(x - CX) + abs(y - CY), 0):
                    ans = False
        if ans:
            print(CX, CY, H)
    if ans:
        break

Fixed submission:
N = int(input())
xyh = [list(map(int, input().split())) for i in range(N)]
key = False
for CX in range(101):
    for CY in range(101):
        ans = True
        H = -1
        for x, y, h in xyh:
            if h > 0:
                tmp = h + abs(x - CX) + abs(y - CY)
                if H == -1:
                    H = tmp
                else:
                    if H != tmp:
                        H = -2
                        break

        if H == -2:
            continue

        for x, y, h in xyh:
            if h == 0:
                dist = abs(x - CX) + abs(y - CY)
                if H > dist:
                    H = -2
                    break
                
        if H == -2:
            continue
        
        print(CX, CY, H)
        key = True
        break
        
    if key:
        break

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
xyh = [list(map(int, input().split())) for i in range(N)]
from operator import itemgetter
xyh = sorted(xyh, key = itemgetter(2))
for i in range(201):
    H = xyh[0][2] + i
    #print(H)
    for CX in range(101):
        for CY in range(101):
            ans = True
            for x, y, h in xyh:
                if h != max(H - abs(x - CX) - abs(y - CY), 0):
                    ans = False
                    break
            if ans:
                print(CX, CY, H)
                break
        if ans:
            break
    if ans:
        break


Fixed submission:
N = int(input())
xyh = [list(map(int, input().split())) for i in range(N)]
key = False
for CX in range(101):
    for CY in range(101):
        ans = True
        H = -1
        for x, y, h in xyh:
            if h > 0:
                tmp = h + abs(x - CX) + abs(y - CY)
                if H == -1:
                    H = tmp
                else:
                    if H != tmp:
                        H = -2
                        break

        if H == -2:
            continue

        for x, y, h in xyh:
            if h == 0:
                dist = abs(x - CX) + abs(y - CY)
                if H > dist:
                    H = -2
                    break
                
        if H == -2:
            continue
        
        print(CX, CY, H)
        key = True
        break
        
    if key:
        break
Buggy python submission (verdict: Runtime Error):
N, K = map(int, input().split())
x = list(map(int, input().split()))
dis = []
for i in range(N - K + 1):
    dis.append(abs(x[i] - x[i + K - 1]) + abs(x[i]))
    dis.append(abs(x[i] - x[i + K - 1]) + abs(x[i + k - 1]))
print(min(dis))


Fixed submission:
N, K = map(int, input().split())
x = list(map(int, input().split()))
dis = []
for i in range(N - K + 1):
    dis.append(abs(x[i] - x[i + K - 1]) + abs(x[i]))
    dis.append(abs(x[i] - x[i + K - 1]) + abs(x[i + K - 1]))
print(min(dis))
Buggy python submission (verdict: Runtime Error):
S = input()
K = int(input())
key = 1
i = 0
while True:
    if i > 100:
        break
    if int(S[i]) != 1:
        print(S[i])
        key = 1
        break
    i += 1

if key == 0:
    print(S[0])


Fixed submission:
S = input()
K = int(input())
key = 0
i = 0
while True:
    if i >= K:
        break
    if i >= len(S):
        break
    if int(S[i]) != 1:
        print(S[i])
        key = 1
        break
    i += 1

if key == 0:
    print(S[0])

Buggy python submission (verdict: Runtime Error):
S = input()
K = int(input())
key = 1
i = 0
while True:
    if int(S[i]) != 1:
        print(S[i])
        key = 1
        break
    i += 1

if key == 0:
    print(S[0])


Fixed submission:
S = input()
K = int(input())
key = 0
i = 0
while True:
    if i >= K:
        break
    if i >= len(S):
        break
    if int(S[i]) != 1:
        print(S[i])
        key = 1
        break
    i += 1

if key == 0:
    print(S[0])
Buggy python submission (verdict: Time Limit Exceeded):
N, M, Q = map(int, input().split())
LR = [[0 for i in range(501)] for j in range(501)]
for i in range(M):
    L, R = map(int, input().split())
    LR[L][R] += 1
LR2 = [[0 for i in range(501)] for j in range(501)]
for i in range(1, 501):
    for j in range(1, 501):
        LR2[i][j] = LR2[i][j - 1] + LR[i][j]
        
for i in range(Q):
    ans = 0
    p, q = map(int, input().split())
    for i in range(p, q + 1):
        ans = ans + LR2[i][q] - LR2[i][p - 1]
    print(ans)


Fixed submission:
N, M, Q = map(int, input().split())
LR = [[0 for i in range(N)] for j in range(N)]
for i in range(M):
    L, R = map(int, input().split())
    LR[L - 1][R - 1] += 1

for i in range(1, N):
    LR[0][i] += LR[0][i - 1]
    LR[i][0] += LR[i - 1][0]

for i in range(1, N):
    for j in range(1, N):
        LR[i][j] = LR[i - 1][j] + LR[i][j - 1] + LR[i][j] - LR[i - 1][j - 1]


for i in range(Q):
    p, q = map(int, input().split())
    p -= 2
    q -= 1
    if p != -1:
        ans = LR[q][q] - LR[q][p] - LR[p][q] + LR[p][p]
    elif p == -1:
        ans = LR[q][q]
    print(ans)
Buggy python submission (verdict: Runtime Error):
import math
def PC(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
N, M = map(int, input().split())
A = list(map(int, input().split()))
B = []
j = 0
for i in A:
    if j == 0:
        B.append(i)
    else:
        B.append(B[j - 1] + i)
    j += 1
for i in range(len(B)):
    B[i] = B[i] % M
C = sorted(B)
anscnt = 0
samecnt = 1
for i in range(len(C)):
    if C[i] == 0:
        anscnt += 1
    if i != 0:
        if C[i] == C[i - 1]:
            samecnt += 1
        elif samecnt != 1:
            anscnt += PC(samecnt, 2)
            samecnt = 1
        if i == len(C) - 1:
            anscnt += PC(samecnt, 2)
            samecnt = 1
print(anscnt)
            

Fixed submission:
import math
def PC(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

def ncr(n, r):
    r = min(r, n - r)
    if r == 0: return 1;
    if r == 1: return n;
    numerator = [n - r + i + 1 for i in range(r)]
    denominator  = [i + 1 for i in range(r)]
    for p in range(2, r + 1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p - 1, r, p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot
    result = 1
    for k in range(r):
        if numerator[k] > 1: 
            result *= numerator[k]
    return int(result)

#kaijou = [0, 1]
#for i in range(2, 1000):
 #   kaijou.append(kaijou[i - 1] * i)

#print(kaijou[0:10])

N, M = map(int, input().split())
A = list(map(int, input().split()))
B = []
j = 0
for i in A:
    if j == 0:
        B.append(i)
    else:
        B.append(B[j - 1] + i)
    j += 1
for i in range(len(B)):
    B[i] = B[i] % M
C = sorted(B)
anscnt = 0
samecnt = 1
for i in range(len(C)):
    if C[i] == 0:
        anscnt += 1
    if i != 0:
        if C[i] == C[i - 1]:
            samecnt += 1
        elif samecnt != 1:
            anscnt += ncr(samecnt, 2)
            samecnt = 1
        if i == len(C) - 1 and samecnt != 1:
            anscnt += ncr(samecnt, 2)
            samecnt = 1
print(anscnt)