Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
a = input()
a = [int(i) for i in a]
if sum(a) >= 22:
    print("bust")
else:
    print("win")

Fixed submission:
a = map(int, input().split())
a = list(a)

if sum(a) >= 22:
    print("bust")
else:
    print("win")

Buggy python submission (verdict: Runtime Error):
a = [int(i) for i in a]
if sum(a) >= 22:
    print("bust")
else:
    print("win")

Fixed submission:
a = map(int, input().split())
a = list(a)

if sum(a) >= 22:
    print("bust")
else:
    print("win")
Buggy python submission (verdict: Runtime Error):
a, b, x = map(int, input().split())

if b > 2*x/(a**2):
    print(math.degrees(math.atan(a*b*b/(2*x))))
else:
    print(math.degrees(math.atan((2/a)*(b-(x/(a**2))))))

Fixed submission:
import math

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

if b > 2*x/(a**2):
    print(math.degrees(math.atan(a*b*b/(2*x))))
else:
    print(math.degrees(math.atan((2/a)*(b-(x/(a**2))))))
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = input().split()
A = [int(i) for i in A]

sort = []
count = 1
for i in range(len(A)):
    for i,a in enumerate(A):
        if a == count:
            sort.append(i+1)
            count += 1
            break
sort = [str(s) for s in sort]
print(" ".join(sort))

Fixed submission:
import copy
N = int(input())
A = input().split()
A = [int(i) for i in A]

sort = [0 for i in range(N)]
count = 1

for i, a in enumerate(A):
    sort[a-1] = i+1

sort = [str(s) for s in sort]
print(" ".join(sort))
Buggy python submission (verdict: Runtime Error):
n = int(input())
a = input().split()
b = input().split()
c = input().split()
a = [int(i) for i in a] 
b = [int(i) for i in b] 
c = [int(i) for i in c] 

sut = 0
for i,ind in enumerate(a):
    sut += b[ind-1]
    if i>=1:
        if a[i-1]+1 == a[i]:
            sut += c[i]
print(sut)

Fixed submission:
n = int(input())
a = input().split()
b = input().split()
c = input().split()
a = [int(i) for i in a] 
b = [int(i) for i in b] 
c = [int(i) for i in c] 

sut = 0
for i,ind in enumerate(a):
    sut += b[ind-1]
    if i>=1:
        if a[i-1]+1 == a[i]:
            sut += c[a[i]-2]
print(sut)
Buggy python submission (verdict: Runtime Error):
a = []
sum_a = b[0] + b[-1]
for i,b_i in enumerate(b):
    
    if i+1 < n-1:
        if b[i+1] >= b[i]:
            a.append(b[i])
            sum_a += b[i]
        else:
            a.append(b[i+1])
            sum_a += b[i+1]
print(sum_a)

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

a = []
sum_a = b[0] + b[-1]
for i,b_i in enumerate(b):
    
    if i+1 < n-1:
        if b[i+1] >= b[i]:
            a.append(b[i])
            sum_a += b[i]
        else:
            a.append(b[i+1])
            sum_a += b[i+1]
print(sum_a)
Buggy python submission (verdict: Runtime Error):
import numpy as np

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

S = np.array(list(input()), dtype='U1')
 
x = np.sum(S[1:] == S[:-1])
 
x += 2*K
x = min(x, N-1)
print(x)

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

sut = 0
a = ""
for i,s in enumerate(b):
    if i < n-1:
        if b[i] == b[i+1]:
            sut += 1
        else:
            a += s
    else:
        a+=s
a

count = len(a)
for i in range(k):
    if count <= 1:
        break
    elif count >= 3:
        sut += 2
        count -= 2
    elif count == 2:
        sut += 1
        break
print(sut)

Buggy python submission (verdict: Runtime Error):
N, K = input().split(" ")
N, K = int(N), int(K)
S = input()

def syukuyaku(S):
    if len(S) <= 1:
        return S
    res = S[0]
    cnt = 0
    i = 0
    while i < len(S)-1:
        if S[i] == S[i+1]:
            while i < len(S)-1 and S[i] == S[i+1]:
                cnt += 1
                i += 1
        else:
            i += 1
            res += S[i]
    return res, cnt

S_ ,cnt = syukuyaku(S)

if S_.count("L") == S_.count("R"):
    if S_.count("L") <= K:
        print(cnt + S_.count("L")*2)
    else:
        print(cnt + K * 2)
elif S_.count("L") > S_.count("R"):
    if S_.count("L") <= K:
        print(len(S)-1)
    else:
        print(cnt + K * 2)
else:
    if S_.count("R") <= K:
        print(len(S)-1)
    else:
        print(cnt + K * 2)

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

sut = 0
a = ""
for i,s in enumerate(b):
    if i < n-1:
        if b[i] == b[i+1]:
            sut += 1
        else:
            a += s
    else:
        a+=s
a

count = len(a)
for i in range(k):
    if count <= 1:
        break
    elif count >= 3:
        sut += 2
        count -= 2
    elif count == 2:
        sut += 1
        break
print(sut)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
P = [int(i) for i in input().split(" ")]

ans = 0
for L in range(N-1):
    for R in range(L+1, N):
        if 2 <= len(P[L:R+1]) <= 3:
            seq = sorted(P[L:R+1], reverse=True)
        else:
            if seq[0] > P[R] > seq[1]:
                seq = [seq[0], P[R], seq[1]]
            elif P[R] > seq[0]:
                seq = [P[R], seq[0], seq[1]]
            elif seq[1] > P[R] > seq[2]:
                seq = [seq[0], seq[1], P[R]]
        ans += seq[1]
print(ans)

Fixed submission:
N = int(input())
P = [int(i) for i in input().split(" ")]

# 各数字が何番目に入っているかを保存する
pos = [0] * (N + 1)
for i in range(N):
    pos[P[i]] = i + 1

l = [0]+[i for i in range(N + 1)]
r = [i + 1 for i in range(N + 1)] + [N + 1]

# 1から順番に見ていく
ans = 0
for i in range(1, N + 1):
    idx = pos[i]
    l1, r1 = l[idx], r[idx]
    l2, r2 = l[l1], r[r1]
    ans += i * ((l1 - l2) * (r1 - idx) + (idx - l1) * (r2 - r1))
    l[r1], r[l1] = l1, r1
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
P = [int(i) for i in input().split(" ")]

ans = 0
for L in range(N-1):
    for R in range(L+1, N):
        ans += sorted(P[L:R+1], reverse=True)[1]
print(ans)

Fixed submission:
N = int(input())
P = [int(i) for i in input().split(" ")]

# 各数字が何番目に入っているかを保存する
pos = [0] * (N + 1)
for i in range(N):
    pos[P[i]] = i + 1

l = [0]+[i for i in range(N + 1)]
r = [i + 1 for i in range(N + 1)] + [N + 1]

# 1から順番に見ていく
ans = 0
for i in range(1, N + 1):
    idx = pos[i]
    l1, r1 = l[idx], r[idx]
    l2, r2 = l[l1], r[r1]
    ans += i * ((l1 - l2) * (r1 - idx) + (idx - l1) * (r2 - r1))
    l[r1], r[l1] = l1, r1
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N, A = input().split(" ")
N, A = int(N), int(A)
x = input().split(" ")
x = [int(i) for i in x]

import itertools

cnt = 0
for n in range(1, N+1):
    for i in itertools.combinations(x, n):
        if sum(i) / n == A:
            cnt += 1
print(cnt)

Fixed submission:
N, A = input().split(" ")
N, A = int(N), int(A)
x = input().split(" ")
x = [int(i) for i in x]
y = [0]+[int(i)-A for i in x]
X = max(x+[A])

dp = [[0 for t in range(2*N*X+1)] for j in range(N+1)]

for j in range(N+1):
    for t in range(2*N*X+1):
        if j == 0 and t == N*X:  # 0枚の時は0しか達成できない
            dp[j][t] = 1
        elif j >= 1 and (t - y[j-1] < 0 or t-y[j] > 2*N*X):  # xの値が平均Aを超えてしまう場合は、前回の結果から場合の総数に変化なし
            dp[j][t] = dp[j-1][t]
        elif j >= 1 and 0 <= t-y[j-1] <= 2*N*X:  # 前回の場合の総数に、今回の数を足して0になる場合の総数を足す
            dp[j][t] = dp[j-1][t] + dp[j-1][t-y[j]]
        else:
            dp[j][t] = 0
print(dp[N][N*X] - 1)
Buggy python submission (verdict: Runtime Error):
N = int(input())
S = int(input())

def f(b, n):
    if n < b:
        return n
    else:
        return f(b, int(n/b)) + (n % b)

def solve(N, S):
    if N == S:
        return N+1
    else:
        for b in range(2, int(N**(1/2))+1):
            if f(b, N) == S:
                return b
        for p in range(1, int(N**(1/2))+1):
            b = int((N - S) / p + 1)
            if f(b, N) == S:
                return b
        return -1

print(solve(N, S))

Fixed submission:
N = int(input())
S = int(input())

def f(b, n):
    if n < b:
        return n
    else:
        return f(b, n//b) + (n % b)

def solve(N, S):
    if S > N:
        return -1
    elif N == S:
        return N+1
    else:
        for b in range(2, int(N**(1/2))+1):
            if f(b, N) == S:
                return b
        for p in range(int(N**(1/2)), 0, -1):
            if (N - S) % p == 0:
                b = (N - S) // p + 1
                if f(b, N) == S:
                    return b
        return -1

print(solve(N, S))
Buggy python submission (verdict: Runtime Error):
N = int(input())
print(sum([i for i in range(1, N+1)])

Fixed submission:
N = int(input())
print(sum([i for i in range(1, N+1)]))
Buggy python submission (verdict: Time Limit Exceeded):
S = input()

def f (S):
    for i, s in enumerate(S):
        cnt = dict()
        cnt = {s:1}
        for j, e in enumerate(S[i+1:]):
            if e in cnt.keys():
                cnt[e] += 1
            else:
                cnt[e] = 1
            if max(cnt.values()) / sum(cnt.values()) > 0.5:
                return "{} {}".format(i+1, (i+1)+j+1)
    return "-1 -1"
print(f(S))

Fixed submission:
S = input()
def f(S):
    for i in range(len(S)-1):
        if S[i] == S[i+1]:
            return "{} {}".format(i+1, i+2)
        elif i < len(S)-2 and S[i] == S[i+2]:
            return "{} {}".format(i+1, i+3)
        else:
            pass
    return "-1 -1"
print(f(S))
Buggy python submission (verdict: Time Limit Exceeded):
H, W, A, B = [int(i) for i in input().split(" ")]

from collections import deque

per = 10**9 + 7

goal_cnt = 0
que = deque([])
que.append((0, 0))

while que:
    p = que.popleft()
    if p[0] == H-1 and p[1] == W-1:
        goal_cnt += 1
        goal_cnt %= per
    else:
        for vh, vw in [[1, 0], [0, 1]]:
            pos_h = p[0] + vh
            pos_w = p[1] + vw
            
            if 0 <= pos_h <= H-1 and 0 <= pos_w <= W-1 and not(pos_w <= B-1 and pos_h >= H - A):
                que.append((pos_h, pos_w))
print(goal_cnt)

Fixed submission:
U = 2*10**5
MOD = 10**9+7
 
fact = [1] * (U+1)
fact_inv = [1] * (U+1)

# 階乗のテーブル作成
for i in range(1, U+1):
    fact[i] = (fact[i-1] * i) % MOD

# 階乗の逆元のテーブル作成
fact_inv[U] = pow(fact[U], MOD-2, MOD)
for i in range(U, 0, -1):
    fact_inv[i-1] = (fact_inv[i] * i) % MOD

def comb(n, k):
    if k < 0 or k > n:
        return 0
    x = fact[n]
    x *= fact_inv[k]
    x %= MOD
    x *= fact_inv[n-k]
    x %= MOD
    return x

H, W, A, B = [int(i) for i in input().split(" ")]

ans = 0
# 経路の足し上げ C(縦+横, 縦(or横)) (重複のある組み合わせ)
for i in range(B, W):
    ans += comb((H-A-1) + i, i) * comb((A - 1) + (W-1-i), W-1- i) % MOD
    ans %= MOD
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
H, W, A, B = [int(i) for i in input().split(" ")]

from collections import deque

field = [[0 if w <= B-1 and h >= H - A else 1 for w in range(W)] for h in range(H)]

goal_cnt = 0
que = deque([])
que.append((0, 0))

while que:
    p = que.popleft()
    if p[0] == H-1 and p[1] == W-1:
        goal_cnt += 1
        goal_cnt %= 10**9 + 7
    else:
        for vh, vw in [[1, 0], [0, 1]]:
            pos_h = p[0] + vh
            pos_w = p[1] + vw
            
            if 0 <= pos_h <= H-1 and 0 <= pos_w <= W-1 and field[pos_h][pos_w] == 1:
                que.append((pos_h, pos_w))
print(goal_cnt)

Fixed submission:
U = 2*10**5
MOD = 10**9+7
 
fact = [1] * (U+1)
fact_inv = [1] * (U+1)

# 階乗のテーブル作成
for i in range(1, U+1):
    fact[i] = (fact[i-1] * i) % MOD

# 階乗の逆元のテーブル作成
fact_inv[U] = pow(fact[U], MOD-2, MOD)
for i in range(U, 0, -1):
    fact_inv[i-1] = (fact_inv[i] * i) % MOD

def comb(n, k):
    if k < 0 or k > n:
        return 0
    x = fact[n]
    x *= fact_inv[k]
    x %= MOD
    x *= fact_inv[n-k]
    x %= MOD
    return x

H, W, A, B = [int(i) for i in input().split(" ")]

ans = 0
# 経路の足し上げ C(縦+横, 縦(or横)) (重複のある組み合わせ)
for i in range(B, W):
    ans += comb((H-A-1) + i, i) * comb((A - 1) + (W-1-i), W-1- i) % MOD
    ans %= MOD
print(ans)
Buggy python submission (verdict: Runtime Error):
N, K = map(int, input().split())
tmp = list(map(int, input().split()))
A = [1]
A.extend(tmp)

# 循環する場所を探す(最大N回)
used = [1, 1]
used.extend([0] * (N-1)) # すでに通った町は1にする
route = [1]
while used[A[route[-1]]] == 0:
    used[A[route[-1]]] = 1
    route.append(A[route[-1]])

if A.index(A[route[-1]]) == 0:
    print(route[K%(len(route))])
else:
    x = A.index(A[route[-1]]) - 1
    y = len(route) - x
    if y == 0:
        print(route[x])
    else:
        print(route[x + (K-x)%y])


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

passed = [-1] * (n+1)
route = []
v = 1
while passed[v] == -1:
    passed[v] = len(route)
    route.append(v)
    v = a[v-1]

c = len(route) - passed[v]
l = passed[v]

if k < l:
    print(route[k])
else:
    k -= l
    k %= c
    print(route[l+k])

Buggy python submission (verdict: Runtime Error):
N, K = map(int, input().split())
tmp = list(map(int, input().split()))
A = [1]
A.extend(tmp)

# 循環する場所を探す(最大N回)
used = [1, 1]
used.extend([0] * (N-1)) # すでに通った町は1にする
route = [1]
while used[A[route[-1]]] == 0:
    used[A[route[-1]]] = 1
    route.append(A[route[-1]])

if A.index(A[route[-1]]) == 0:
    print(route[K%(len(route))])
else:
    x = A.index(A[route[-1]]) - 1
    y = len(route) - x
    print(route[x + (K-x)%y])


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

passed = [-1] * (n+1)
route = []
v = 1
while passed[v] == -1:
    passed[v] = len(route)
    route.append(v)
    v = a[v-1]

c = len(route) - passed[v]
l = passed[v]

if k < l:
    print(route[k])
else:
    k -= l
    k %= c
    print(route[l+k])
Buggy python submission (verdict: Time Limit Exceeded):
import itertools

N = int(input())
S = input()

R = []
G = []
B = []
for i in range(len(S)):
    if S[i] == 'R':
        R.append(i)
    elif S[i] == 'G':
        G.append(i)
    else:
        B.append(i)

total = 0
for r, g, b in itertools.product(R, G, B):
    i = min([r, g, b])
    k = max([r, g, b])
    j = sum([r, g, b]) - i - k
    if j - i != k - j:
        total += 1

print(str(total))

Fixed submission:
N = int(input())
S = input()

r = 0
g = 0
b = 0
for i in range(N):
    if S[i] == 'R':
        r += 1
    elif S[i] == 'G':
        g += 1
    else:
        b += 1

total = r * g * b
for i in range(N):
    for d in range(N):
        j = i + d
        k = j + d
        if k > N-1:
            break
        if S[i] != S[j] and S[i] != S[k] and S[j] != S[k]:
            total -= 1

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

from collections import deque

n = int(input())
edges = [list(map(int, input().split())) for i in range(n-1)]

# 使われていない色を保持する
nodes = [deque([i for i in range(1, n)]) for j in range(n)]

tree = {}
for edge in sorted(edges):
    a = edge[0] # 頂点a
    b = edge[1] # 頂点b

    color = nodes[a-1].popleft()
    tree[(a, b)] = color
    nodes[b-1].remove(color)

print(max(tree.values()))
for edge in edges:
    a = edge[0] # 頂点a
    b = edge[1] # 頂点b
    print(tree[(a, b)])

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

from collections import deque

n = int(input())
edges = [list(map(int, input().split())) for i in range(n-1)]

tree = {}
node_in = [0 for i in range(n)] # 頂点に入る辺は1つ
node_out = [[0] for i in range(n)] # 頂点から出る辺は1つ以上
for edge in sorted(edges):
    a = edge[0] # 頂点a
    b = edge[1] # 頂点b

    color = 0
    if node_out[a-1][-1] == 0:
        if node_in[a-1] <= 1: # node_in[a-1] == 0の時1、1の時2なのでまとめて
            color = node_in[a-1] + 1
        else: # node_in[a-1] >= 2
            color = 1
    else:
        color = node_out[a-1][-1] + 1
        if node_in[a-1] == color:
            color += 1
            
    tree[(a, b)] = color
    node_out[a-1].append(color)
    node_in[b-1] = color

print(max(tree.values()))
for edge in edges:
    a = edge[0] # 頂点a
    b = edge[1] # 頂点b
    print(tree[(a, b)])
Buggy python submission (verdict: Time Limit Exceeded):
# -*- coding: utf-8 -*-

n = int(input())
l = [int(i) for i in input().split()]
l.sort()

count = 0
for i in range(n-2):
    for j in range(i+1, n-1):
        m = l[i] + l[j]
        # j+1~n-1まで二分探索
        low = j+1
        high = n-1
        index = j
        while low <= high:
            mid = (low + high) // 2
            if m > l[mid]:
                low = mid + 1
                index = mid
            else:
                high = mid - 1
        if index != j:
            count += index - (j+1) + 1

print(count)


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

import bisect

n = int(input())
l = [int(i) for i in input().split()]
l.sort() # 二分探索するために整列

# l[i]+l[j]>l[x]を満たすxは
# 昇順に整列した配列を使うと
# 固定した2本の次のインデックスから必ず連続している
# そのため条件を満たす最大のxを二分探索で求めれば良い

count = 0
# 2本を固定して
for i in range(n-2):
    for j in range(i+1, n-1):
        # 3本目を探索
        index = bisect.bisect_left(l, l[i]+l[j])
        count += index - (j+1)

print(count)

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

n = int(input())
l = [int(i) for i in input().split()]
l.sort()

count = 0
for i in range(n-2):
    for j in range(i+1, n-1):
        for k in range(j+1, n):
            if l[i] + l[j] > l[k] and l[j] + l[k] > l[i] and l[k] + l[i] > l[j]:
                count += 1
            else:
                break

print(count)


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

import bisect

n = int(input())
l = [int(i) for i in input().split()]
l.sort() # 二分探索するために整列

# l[i]+l[j]>l[x]を満たすxは
# 昇順に整列した配列を使うと
# 固定した2本の次のインデックスから必ず連続している
# そのため条件を満たす最大のxを二分探索で求めれば良い

count = 0
# 2本を固定して
for i in range(n-2):
    for j in range(i+1, n-1):
        # 3本目を探索
        index = bisect.bisect_left(l, l[i]+l[j])
        count += index - (j+1)

print(count)

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

n = int(input())
l = [int(i) for i in input().split()]

count = 0
for i in range(n-2):
    for j in range(i+1, n-1):
        for k in range(j+1, n):
            if l[i] + l[j] > l[k] and l[j] + l[k] > l[i] and l[k] + l[i] > l[j]:
                count += 1

print(count)


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

import bisect

n = int(input())
l = [int(i) for i in input().split()]
l.sort() # 二分探索するために整列

# l[i]+l[j]>l[x]を満たすxは
# 昇順に整列した配列を使うと
# 固定した2本の次のインデックスから必ず連続している
# そのため条件を満たす最大のxを二分探索で求めれば良い

count = 0
# 2本を固定して
for i in range(n-2):
    for j in range(i+1, n-1):
        # 3本目を探索
        index = bisect.bisect_left(l, l[i]+l[j])
        count += index - (j+1)

print(count)
Buggy python submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-

A = input()
B = input()
if len(A) > len(B):
    print('GREATER')
elif len(A) < len(B):
    print('LESS')
else:
    if A > B:
        print('GREATER')
    elif A < B:
        print('LESS')
    else:
        print('EQUAL')

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

s1, s2, s3 = input().split()
print((''.join([s1[0], s2[0], s3[0]])).upper())

Buggy python submission (verdict: Runtime Error):
A = input()
B = input()
if len(A) == len(B):
    if A > B:
        print('GREATER')
    else:
        print('LESS')
elif len(A) > len(B):
    print('GREATER')
else:
    print('LESS')


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

s1, s2, s3 = input().split()
print((''.join([s1[0], s2[0], s3[0]])).upper())
Buggy python submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-

A = map(int, input())
B = map(int, input())
if A > B:
    print('GREATER')
elif A < B:
    print('LESS')
else:
    print('EQUAL')

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

A = input()
B = input()
if len(A) > len(B):
    print('GREATER')
elif len(A) < len(B):
    print('LESS')
else:
    for i in range(len(A)):
        if A[i] > B[i]:
            print('GREATER')
            exit()
        elif A[i] < B[i]:
            print('LESS')
            exit()
        else:
            continue
    print('EQUAL')
Buggy python submission (verdict: Time Limit Exceeded):
# -*- coding: utf-8 -*-

n, m = input().split()
x = input().split()
y = input().split()
width = [abs(int(x[i])-int(x[j])) for i in range(len(x)-1) for j in range(i+1, len(x))]
height = [abs(int(y[i])-int(y[j])) for i in range(len(y)-1) for j in range(i+1, len(y))]

sum = 0
for w in width:
    for h in height:
        sum = sum + w * h
print(sum % (10 ** 9 + 7))


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

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

def sum_length(x, n):
    all_sum = 0
    prev_sum = 0
    for i in range(1, n):
        cur_sum = prev_sum + (x[i] - x[i-1]) * i
        all_sum = all_sum + cur_sum
        prev_sum = cur_sum
    return all_sum

sumx = sum_length(x, n)
sumy = sum_length(y, m)
print(sumx * sumy % 1000000007)

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

n, m = input().split()
x = input().split()
y = input().split()
width = []
for i in range(len(x)-1):
    for j in range(i+1,len(x)):
        width.append(abs(int(x[i])-int(x[j])))

height = []
for i in range(len(y)-1):
    for j in range(i+1,len(y)):
        height.append(abs(int(y[i])-int(y[j])))

sum = 0
for w in width:
    for h in height:
        sum = sum + w * h
print(sum % (10 ** 9 + 7))

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

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

def sum_length(x, n):
    all_sum = 0
    prev_sum = 0
    for i in range(1, n):
        cur_sum = prev_sum + (x[i] - x[i-1]) * i
        all_sum = all_sum + cur_sum
        prev_sum = cur_sum
    return all_sum

sumx = sum_length(x, n)
sumy = sum_length(y, m)
print(sumx * sumy % 1000000007)
Buggy python submission (verdict: Runtime Error):
a, op, b = input().split()
a = int(a)
b = int(b)
print(a op b)

Fixed submission:
a, op, b = input().split()
a = int(a)
b = int(b)
if op == '+':
    print(a + b)
else:
    print(a - b)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
S = [input() for _ in range(N)]
#S = []
ans = 0
for i in range(N):
    dup = False
    if S[i] not in S[:i]:
       ans += 1 
print(ans)



Fixed submission:
N = int(input())
rewards = set()
for _ in range(N):
    rewards.add(input())
print(len(rewards))

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
#S = [input() for _ in range(N)]
S = []
for i in range(N):
    s = input()
    dup = False
    if s not in S:
        S.append(s)
print(len(S))


Fixed submission:
N = int(input())
rewards = set()
for _ in range(N):
    rewards.add(input())
print(len(rewards))

Buggy python submission (verdict: Runtime Error):
N = int(input())
#S = [input() for _ in range(N)]
S = []
for i in range(N):
    s = input()
    dup = False
    for j in range(i):
        if s == S[j]:
            dup = True
            break
    if not dup:
        S.append(s)
print(len(S))

Fixed submission:
N = int(input())
rewards = set()
for _ in range(N):
    rewards.add(input())
print(len(rewards))

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
S = [input() for _ in range(N)]

ans = 0
for i in range(N):
    ans += 1
    s = S[i]
    for j in range(i):
        if s == S[j]:
            ans -= 1
            break
print(ans)

Fixed submission:
N = int(input())
rewards = set()
for _ in range(N):
    rewards.add(input())
print(len(rewards))
Buggy python submission (verdict: Runtime Error):
N = int(input())
A = list(map(int, input().split()))

A.sort()
all_d = A[0]
max_d = max(divi(A[0],A[1]), divi(A[0],A[2])) if N > 2 else A[1]
for i in range(1,N):
    all_d = divi(all_d, A[i])
    if max_d < all_d:
        max_d = all_d
print(max_d)

Fixed submission:
N = int(input())
A = list(map(int, input().split()))
def divi(a, b):
    rem = b % a
    if rem == 0:
        return a
    else:
        return divi(rem, a)
A.sort()
all_d = divi(A[0], A[1])
max_d = max(all_d, max(divi(A[1],A[2]), divi(A[0],A[2]))) if N > 2 else A[1]
for i in range(2,N):
    d = divi(all_d, A[i])
    max_d = divi(max_d, A[i])
    if max_d < all_d:
        max_d = all_d
    all_d = d
print(max_d)