Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
# Fast IO (only use in integer input)

# import os,io
# input=io.BytesIO(os.read(0,os.fstat(0).st_size)).readline

from copy import copy

N = int(input())
Resident = []
for i in range(N):
    x,y,p = map(int,input().split())
    Resident.append((x,y,p))

minCost = [-1] * (N+1)

preCalRange = 1 << N

horizontalLineDistance = []
verticalLineDistance = []

for i in range(preCalRange):
    railRoad = []
    tmp = i
    for j in range(N):
        railRoad.append(tmp % 2)
        tmp //= 2
    minDistance = [-1] * N
    for j in range(N):
        minDistance[j] = min(abs(Resident[j][0]),abs(Resident[j][1]))
        for k in range(N):
            if railRoad[k] == 1 and abs(Resident[j][0] - Resident[k][0]) < minDistance[j]:
                minDistance[j] = abs(Resident[j][0] - Resident[k][0])
    horizontalLineDistance.append(copy(minDistance))
    minDistance = [-1] * N
    for j in range(N):
        minDistance[j] = min(abs(Resident[j][0]),abs(Resident[j][1]))
        for k in range(N):
            if railRoad[k] == 1 and abs(Resident[j][1] - Resident[k][1]) < minDistance[j]:
                minDistance[j] = abs(Resident[j][1] - Resident[k][1])
    verticalLineDistance.append(copy(minDistance))

totalCases = 3 ** N

for i in range(totalCases):
    railRoad = []
    tmp = i
    for j in range(N):
        railRoad.append(tmp % 3)
        tmp //= 3
    horizontalCount = 0
    verticalCount = 0
    numNewRailroad = 0
    for j in range(N):
        if railRoad[j] == 1:
            numNewRailroad += 1
            horizontalCount += 1 << j
        if railRoad[j] == 2:
            verticalCount += 1 << j
            numNewRailroad += 1
    minDistance = []
    for j in range(N):
        minDistance.append(min(horizontalLineDistance[horizontalCount][j], verticalLineDistance[verticalCount][j]))

    cost = 0
    for j in range(N):
        cost += Resident[j][2] * minDistance[j]
    if minCost[numNewRailroad] == -1 or minCost[numNewRailroad] > cost:
        minCost[numNewRailroad] = cost
for elem in minCost:
    print(elem)


Fixed submission:
# Fast IO (only use in integer input)

import os,io
input=io.BytesIO(os.read(0,os.fstat(0).st_size)).readline

X = int(input())
if X <= 599:
    print(8)
elif X <= 799:
    print(7)
elif X <= 999:
    print(6)
elif X <= 1199:
    print(5)
elif X <= 1399:
    print(4)
elif X <= 1599:
    print(3)
elif X <= 1799:
    print(2)
elif X <= 1999:
    print(1)
Buggy python submission (verdict: Time Limit Exceeded):
# Fast IO (only use in integer input)

import os,io
input=io.BytesIO(os.read(0,os.fstat(0).st_size)).readline

N,K = map(int,input().split())
a = list(map(int,input().split()))
ans = ""
for i in range(N):
    if i < K:
        continue
    if a[i] <= a[i - K]:
        ans += "No"
    else:
        ans += "Yes"
    if i != N-1:
        ans += "\n"
print(ans)




Fixed submission:
# Fast IO (only use in integer input)

import os,io
input=io.BytesIO(os.read(0,os.fstat(0).st_size)).readline

N,K = map(int,input().split())
a = list(map(int,input().split()))
ans = ""
for i in range(N):
    if i < K:
        continue
    if a[i] <= a[i - K]:
        ans += "No"
    else:
        ans += "Yes"
    if i != N-1:
        ans += "\n"
print(ans)
Buggy python submission (verdict: Runtime Error):
# Fast IO (only use in integer input)

# import os,io
# input=io.BytesIO(os.read(0,os.fstat(0).st_size)).readline

import heapq

T = int(input())
for _ in range(T):
    N = int(input())
    frontCamel = []
    backCamel = []
    indifferentCamel = []
    Happiness = 0
    for _ in range(N):
        k,l,r = map(int,input().split())
        if l > r:
            frontCamel.append((k,l-r))
            Happiness += r
        elif r > l:
            backCamel.append((N-k,r-l))
            Happiness += l
        else:
            indifferentCamel.append((k,0))
            Happiness += l
    frontQ = []
    backQ = []
    frontCamel.sort(key = lambda x:x[0])
    backCamel.sort(key = lambda x:x[0])
    for Camel in frontCamel:
        if Camel[0] == 0:
            continue
        if Camel[0] > len(frontQ):
            heapq.heappush(frontQ,Camel[1])
        else:
            if frontQ[0] < Camel[1]:
                heapq.heapreplace(frontQ,Camel[1])
    for Camel in backCamel:
        if Camel[0] == 0:
            continue
        if Camel[0] > len(backQ):
            heapq.heappush(backQ,Camel[1])
        else:
            if frontQ[0] < Camel[1]:
                heapq.heapreplace(backQ,Camel[1])
    Happiness += sum(frontQ)
    Happiness += sum(backQ)
    print(Happiness)


Fixed submission:
# Fast IO (only use in integer input)

# import os,io
# input=io.BytesIO(os.read(0,os.fstat(0).st_size)).readline

import heapq

T = int(input())
for _ in range(T):
    N = int(input())
    frontCamel = []
    backCamel = []
    indifferentCamel = []
    Happiness = 0
    for _ in range(N):
        k,l,r = map(int,input().split())
        if l > r:
            frontCamel.append((k,l-r))
            Happiness += r
        elif r > l:
            backCamel.append((N-k,r-l))
            Happiness += l
        else:
            indifferentCamel.append((k,0))
            Happiness += l
    frontQ = []
    backQ = []
    frontCamel.sort(key = lambda x:x[0])
    backCamel.sort(key = lambda x:x[0])
    for Camel in frontCamel:
        if Camel[0] == 0:
            continue
        if Camel[0] > len(frontQ):
            heapq.heappush(frontQ,Camel[1])
        else:
            if frontQ[0] < Camel[1]:
                heapq.heapreplace(frontQ,Camel[1])
    for Camel in backCamel:
        if Camel[0] == 0:
            continue
        if Camel[0] > len(backQ):
            heapq.heappush(backQ,Camel[1])
        else:
            if backQ[0] < Camel[1]:
                heapq.heapreplace(backQ,Camel[1])
    Happiness += sum(frontQ)
    Happiness += sum(backQ)
    print(Happiness)
Buggy python submission (verdict: Runtime Error):
# Fast IO (only use in integer input) or take care about string

import os,io
input=io.BytesIO(os.read(0,os.fstat(0).st_size)).readline

N = int(input())
AC = 0
WA = 0
TLE = 0
RE = 0

for _ in range(N):
  str = input()
  if str[0] == 'A':
    AC += 1
  elif str[0] == 'W':
    WA += 1
  elif str[0] == 'T':
    TLE += 1
  elif str[0] == 'R':
    RE += 1
print('AC x ' + str(AC))
print('WA x ' + str(WA))
print('TLE x ' + str(TLE))
print('RE x ' + str(RE))

Fixed submission:
import sys
input = sys.stdin.readline
 
N = int(input())
AC = 0
WA = 0
TLE = 0
RE = 0
 
for _ in range(N):
  str1 = input()
  if str1[0] == 'A':
    AC += 1
  elif str1[0] == 'W':
    WA += 1
  elif str1[0] == 'T':
    TLE += 1
  elif str1[0] == 'R':
    RE += 1
print('AC x ' + str(AC))
print('WA x ' + str(WA))
print('TLE x ' + str(TLE))
print('RE x ' + str(RE))
Buggy python submission (verdict: Runtime Error):
# Fast IO (only use in integer input) or take care about string

import os,io
input=io.BytesIO(os.read(0,os.fstat(0).st_size)).readline

N = int(input())

ans = 0
for i in range(N):
  ans += (N-i) * (i+1)
for _ in range(N-1):
  a,b = map(int,input().split())
  if a > b:
    c = a
    a = b
    b = c
  ans -= a * (n - b + 1)
print(ans)


Fixed submission:
# Fast IO (only use in integer input) or take care about string
 
import os,io
input=io.BytesIO(os.read(0,os.fstat(0).st_size)).readline
 
N = int(input())
 
ans = 0
for i in range(N):
  ans += (N-i) * (i+1)
for _ in range(N-1):
  a,b = map(int,input().split())
  if a > b:
    c = a
    a = b
    b = c
  ans -= a * (N - b + 1)
print(ans)

Buggy python submission (verdict: Runtime Error):
# Fast IO (only use in integer input) or take care about string

import os,io
input=io.BytesIO(os.read(0,os.fstat(0).st_size)).readline

N = int(input())

Ans = 0
for i in range(N):
  Ans += (N-i) * (i+1)
for _ in range(N-1):
  a,b = map(int,input().split())
  if a > b:
    c = a
    a = b
    b = c
  ans -= a * (n - b + 1)
print(ans)

Fixed submission:
# Fast IO (only use in integer input) or take care about string
 
import os,io
input=io.BytesIO(os.read(0,os.fstat(0).st_size)).readline
 
N = int(input())
 
ans = 0
for i in range(N):
  ans += (N-i) * (i+1)
for _ in range(N-1):
  a,b = map(int,input().split())
  if a > b:
    c = a
    a = b
    b = c
  ans -= a * (N - b + 1)
print(ans)
Buggy python submission (verdict: Runtime Error):
N,M,K = map(int,input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
subseqA = [0] # i th element is sum of first i books
subseqB = [0]
for elem in a:
    subseqA.append(subseqA[-1]+elem)
for elem in b:
    subseqB.append(subseqB[-1]+elem)
maxBooks = 0
curABooks = 0
curBBooks = 0
for i in range(N+1):
    if K < subseqA[i]:
        curABooks = i - 1
        maxBooks = i - 1
        break
for i in range(curABooks,-1,-1):
    for j in range(curBBooks + 1,M+1):
        if subseqA[i] + subseqB[j] > K:
            curBBooks = j - 1
            break
    if subseq[i] + subseqB[M] > K:
        curBBooks = M
    if i + curBBooks > maxBooks:
        maxBooks = i + curBBooks
print(maxBooks)

Fixed submission:
N,M,K = map(int,input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
subseqA = [0] # i th element is sum of first i books
subseqB = [0]
for elem in a:
    subseqA.append(subseqA[-1]+elem)
for elem in b:
    subseqB.append(subseqB[-1]+elem)
maxBooks = 0
curABooks = 0
curBBooks = 0
for i in range(N+1):
    if K < subseqA[i]:
        curABooks = i - 1
        maxBooks = i - 1
        break
if subseqA[N] <= K:
    curABooks = N
for i in range(curABooks,-1,-1):
    for j in range(curBBooks + 1,M+1):
        if subseqA[i] + subseqB[j] > K:
            curBBooks = j - 1
            break
    if subseqA[i] + subseqB[M] <= K:
        curBBooks = M
    if i + curBBooks > maxBooks:
        maxBooks = i + curBBooks
print(maxBooks)
Buggy python submission (verdict: Runtime Error):
N,K = map(int,input().split())

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

HSorted = sorted(H)

HIndexToHeight = []
HHeightToIndex = {}

for i in range(N):
    if i != 0 and HSorted[i] == HSorted[i-1]:
        continue
    HIndexToHeight.append(HSorted[i])
    HHeightToIndex[HSorted[i]] = len(HIndexToHeight) - 1

INF = 10 ** 12

heightCount = len(HIndexToHeight)

DP = []
for i in range(N):
    DP.append([])
    for j in range(K + 1):
        DP[i].append([])
        for k in range(heightCount):
            DP[i][j].append(INF)

for k in range(heightCount):
    if k == HHeightToIndex[H[0]]:
        DP[0][0][k] = H[0]
    else:
        DP[0][1][k] = HIndexToHeight[k]

for i in range(1,N):
    currentHeight = HHeightToIndex[H[i]]
    for j in range(K + 1):
        for k in range(heightCount):
            if currentHeight > k:
                if j > 0:
                    DP[i][j][k] = min(DP[i-1][j-1][k], DP[i][j][k])
                DP[i][j][currentHeight] = min(DP[i-1][j][k] + HIndexToHeight[currentHeight] - HIndexToHeight[k], DP[i][j][currentHeight])
            elif currentHeight == k:
                DP[i][j][currentHeight] = min(DP[i-1][j][k], DP[i][j][currentHeight])
            else:
                if j > 0:
                    DP[i][j][k] = min(DP[i-1][j-1][k], DP[i][j][k])
                DP[i][j][currentHeight] = min(DP[i-1][j][k], DP[i][j][currentHeight])
ans = INF

for j in range(K + 1):
    for k in range(heightCount):
        if ans > DP[N-1][j][k]:
            ans = DP[N-1][j][k]

print(ans)




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

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

HSorted = sorted(H)

HIndexToHeight = []
HHeightToIndex = {}

for i in range(N):
    if i != 0 and HSorted[i] == HSorted[i-1]:
        continue
    HIndexToHeight.append(HSorted[i])
    HHeightToIndex[HSorted[i]] = len(HIndexToHeight) - 1

INF = 10 ** 12

heightCount = len(HIndexToHeight)

DP = []
for i in range(N):
    DP.append([])
    for j in range(K + 1):
        DP[i].append([])
        for k in range(heightCount):
            DP[i][j].append(INF)

for k in range(heightCount):
    if k == HHeightToIndex[H[0]]:
        DP[0][0][k] = H[0]
    elif K != 0:
        DP[0][1][k] = HIndexToHeight[k]

for i in range(1,N):
    currentHeight = HHeightToIndex[H[i]]
    for j in range(K + 1):
        for k in range(heightCount):
            if currentHeight > k:
                if j > 0:
                    DP[i][j][k] = min(DP[i-1][j-1][k], DP[i][j][k])
                DP[i][j][currentHeight] = min(DP[i-1][j][k] + HIndexToHeight[currentHeight] - HIndexToHeight[k], DP[i][j][currentHeight])
            elif currentHeight == k:
                DP[i][j][currentHeight] = min(DP[i-1][j][k], DP[i][j][currentHeight])
            else:
                if j > 0:
                    DP[i][j][k] = min(DP[i-1][j-1][k], DP[i][j][k])
                DP[i][j][currentHeight] = min(DP[i-1][j][k], DP[i][j][currentHeight])
ans = INF

for j in range(K + 1):
    for k in range(heightCount):
        if ans > DP[N-1][j][k]:
            ans = DP[N-1][j][k]
if K == N:
    print(0)
else:
    print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import math
n = int(input())
ans = ""
for i in range(n):
  for j in range(i + 1, n):
    ixorj = i ^ j
    cnt = 1
    while ixorj >= 2:
      cnt += 1
      ixorj //= 2
    ans += str(cnt)
    if j != n-1:
      ans += " "
  if i != n-2:
    ans += "\n"
print(ans)

Fixed submission:
import math
n = int(input())
for i in range(n):
  ans = ""
  for j in range(i + 1, n):
    ixorj = i ^ j
    cnt = 1
    while ixorj >= 2:
      cnt += 1
      ixorj //= 2
    ans += str(cnt)
    if j != n-1:
      ans += " "
  print(ans)
Buggy python submission (verdict: Runtime Error):
N,T = map(int,input().split())

a = list(map(int,input().split()))
maxDiff = 0
curMin = a[0]
for i in range(n):
  if curMin > a[i]:
    curMin = a[i]
  if maxDiff < a[i] - curMin:
    maxDiff = a[i] - curMin

isCovered = False
count = 0

curMin = a[0]

for i in range(n):
  if curMin > a[i]:
    curMin = a[i]
    isCovered = False
  if maxDiff == a[i] - curMin:
    if not isCovered:
      count += 1
      isCovered = True

print(count)

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

a = list(map(int,input().split()))
maxDiff = 0
curMin = a[0]
for i in range(n):
  if curMin > a[i]:
    curMin = a[i]
  if maxDiff < a[i] - curMin:
    maxDiff = a[i] - curMin

isCovered = False
count = 0

curMin = a[0]

for i in range(n):
  if curMin > a[i]:
    curMin = a[i]
    isCovered = False
  if maxDiff == a[i] - curMin:
    if not isCovered:
      count += 1
      isCovered = True

print(count)
Buggy python submission (verdict: Runtime Error):
a,b=map(int,input().split())
print(b+100*max(10-a,0)

Fixed submission:
a,b=map(int,input().split())
print(b+100*max(10-a,0))
Buggy python submission (verdict: Runtime Error):
a,b,c=map(int,input().split())
print(max(b//a,c)

Fixed submission:
a,b,c=map(int,input().split())
print(min(b//a,c))
Buggy python submission (verdict: Time Limit Exceeded):
N, *A = map(int, open(0).read().split())
b = 1
for a in A:
  b *= a
print(-1 if b > 10**18 else b)


Fixed submission:
N, *A = map(int, open(0).read().split())
b = 1
A = sorted(A)
for a in A:
  if b > 10**18:
    break
  b *= a
print(-1 if b > 10**18 else b)
Buggy python submission (verdict: Runtime Error):
A, B = input().split()
A = int(A)
B = int(B * 100)
print(A*B//100)

Fixed submission:
A, B = input().split()
A = int(A)
B = round(float(B) * 100)
print(A*B//100)
Buggy python submission (verdict: Runtime Error):
N = int(input())
for i in range(N):
    if math.floor(i * 1.08) == N:
        print(i)
        exit(0)
print(':(')

Fixed submission:
import math
N = int(input())
f = False
for i in range(N+1):
    if math.floor(i * 1.08) == N:
        print(i)
        f = True
        break
if not f:
    print(':(')

Buggy python submission (verdict: Runtime Error):
import math
N = int(input())
for i in range(N):
  if int(math.floor(i*1.08)) == N:
    print(i)
    return
print(-1)

Fixed submission:
import math
N = int(input())
f = False
for i in range(N+1):
    if math.floor(i * 1.08) == N:
        print(i)
        f = True
        break
if not f:
    print(':(')
Buggy python submission (verdict: Runtime Error):
#include <bits/stdc++.h>

using namespace std;
using i64 = int64_t;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    vector<int> A(N);
    for(auto&& x:A)cin >> x;
    sort(A.begin(), A.end());
    int sum = 0;
    for(int i=1;i<N-1;i++)sum += abs(A[i]);
    cout << A[N-1] + sum - A[0] << endl;
    for(int i=1;i<N-1;i++){
        if(A[i] < 0){
            cout << A[N-1] << " " << A[i] << endl;
            A[N-1] -= A[i];
        }else{
            cout << A[0] << " " << A[i] << endl;
            A[0] -= A[i];
        }
    }
    cout << A[N-1] << " " << A[0] << endl;
    return 0;
}

Fixed submission:
from collections import defaultdict, deque
import sys
#input = sys.stdin.readline
def inpl(): return list(map(int, input().split()))
N = int(input())
A = sorted(inpl())

print(A[-1] + sum(map(abs, A[1:-1])) - A[0])
for i in range(N-2, 0, -1):
  a = A[i]
  if a > 0:
    print(A[0], a)
    A[0] -= a
  else:
    print(A[-1], a)
    A[-1] -= a
print(A[-1], A[0])
Buggy python submission (verdict: Runtime Error):
def dist(a, b):
  if a * b < 0:
    return 2 * min(abs(a), abs(b)) + max(abs(a), abs(b))
  else:
    return max(abs(a), abs(b))

def solve(A, K):
  ans = dist(A[0], A[K])
  for i in range(len(A)-K+1):
    ans = min(ans, dist(A[i], A[i+K-1]))
  return ans
               
N, K, *A = map(int, open(0).read().split())
print(solve(A, K))

Fixed submission:
def dist(a, b):
  if a * b < 0:
    return 2 * min(abs(a), abs(b)) + max(abs(a), abs(b))
  else:
    return max(abs(a), abs(b))

def solve(A, K):
  ans = dist(A[0], A[K-1])
  for i in range(len(A)-K+1):
    ans = min(ans, dist(A[i], A[i+K-1]))
  return ans
               
N, K, *A = map(int, open(0).read().split())
print(solve(A, K))
Buggy python submission (verdict: Runtime Error):
print(24+24-int(input())

Fixed submission:
print(24+24-int(input()))
Buggy python submission (verdict: Time Limit Exceeded):
N, K, *A = map(int, open(0).read().split())
B = sorted(map(lambda x:A.count(x), set(A)))
print(sum(B[:-K]))

Fixed submission:
import collections as cl
N, K, *A = map(int, open(0).read().split())
c = sorted(cl.Counter(A).values())
print(sum(c[:-K]))
Buggy python submission (verdict: Runtime Error):
def gcd(l, r):
  while r != 0:
    l, r = r, l % r
  return l

def main():
  N, K, *A = map(int, open(0).read().split())
  if N == 1:
    if K == A[0]:
      print('POSSIBLE')
      return
    else:
      print('IMPOSSIBLE')
      return
  g = abs(A[1] - A[0])
  for i in range(N-1):
    g = gcd(g, abs(A[i+1] - A[i]))
  if (K % g) == (A[0] % g) and K <= max(A):
    print('POSSIBLE')
  else:
    print('IMPOSSIBLE')

if __name__ == '__main__':
  main()


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

def main():
  N, K, *A = map(int, open(0).read().split())
  g = A[0]
  for a in A:
    g = gcd(g, a)
  if K % g == 0 and K <= max(A):
    print('POSSIBLE')
  else:
    print('IMPOSSIBLE')

if __name__ == '__main__':
  main()

Buggy python submission (verdict: Runtime Error):
def gcd(l, r):
  while r != 0:
    l, r = r, l % r
  return l

def main():
  N, K, *A = map(int, open(0).read().split())
  if N == 1:
    if K == A[0]:
      print('POSSIBLE')
      return
    else:
      print('IMPOSSIBLE')
      return
  g = A[1] - A[0]
  for i in range(N-1):
    g = gcd(g, abs(A[i+1] - A[i]))
  if (K % g) == (A[0] % g) and K <= max(A):
    print('POSSIBLE')
  else:
    print('IMPOSSIBLE')

if __name__ == '__main__':
  main()


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

def main():
  N, K, *A = map(int, open(0).read().split())
  g = A[0]
  for a in A:
    g = gcd(g, a)
  if K % g == 0 and K <= max(A):
    print('POSSIBLE')
  else:
    print('IMPOSSIBLE')

if __name__ == '__main__':
  main()

Buggy python submission (verdict: Runtime Error):
def gcd(l, r):
  while r > 0:
    l, r = r, l % r
  return l

def main():
  N, K, *A = map(int, open(0).read().split())
  if N == 1:
    if K == A[0]:
      print('POSSIBLE')
      return
    else:
      print('IMPOSSIBLE')
      return
  g = A[1] - A[0]
  for i in range(N-1):
    g = gcd(g, abs(A[i+1] - A[i]))
  if K % g == A[0] % g and K <= max(A):
    print('POSSIBLE')
  else:
    print('IMPOSSIBLE')

if __name__ == '__main__':
  main()


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

def main():
  N, K, *A = map(int, open(0).read().split())
  g = A[0]
  for a in A:
    g = gcd(g, a)
  if K % g == 0 and K <= max(A):
    print('POSSIBLE')
  else:
    print('IMPOSSIBLE')

if __name__ == '__main__':
  main()

Buggy python submission (verdict: Runtime Error):
def gcd(l, r):
  while r > 0:
    l, r = r, l % r
  return l

def main():
  N, K, *A = map(int, open(0).read().split())
  g = A[1] - A[0]
  for i in range(N-1):
    g = gcd(g, A[i+1] - A[i])
  if K % g == A[0] % g and K <= max(A):
    print('POSSIBLE')
  else:
    print('IMPOSSIBLE')

if __name__ == '__main__':
  main()

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

def main():
  N, K, *A = map(int, open(0).read().split())
  g = A[0]
  for a in A:
    g = gcd(g, a)
  if K % g == 0 and K <= max(A):
    print('POSSIBLE')
  else:
    print('IMPOSSIBLE')

if __name__ == '__main__':
  main()
Buggy python submission (verdict: Runtime Error):
import math
N, *a = map(int, open(0).read().split())
ave = math.round(sum(a) / N)
ans = 0
for x in a:
  ans += (x - ave) * (x - ave)
print(ans)


Fixed submission:
N, *a = map(int, open(0).read().split())
ave = round(sum(a) / N)
ans = 0
for x in a:
  ans += (x - ave) * (x - ave)
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
INF = 10 ** 9 + 7
N = int(input())
A = list(map(int, input().split()))
test = []
for i in range(N - 1):
    tmp = 0
    for j in range(i + 1, N):
        tmp += A[i] * A[j]
        tmp %= INF
    test.append(tmp)

print(sum(test) % INF)

Fixed submission:
INF = 10 ** 9 + 7
N = int(input())
A = list(map(int, input().split()))
rui = [0] * (N + 1)
for i in range(N):
    rui[i + 1] = A[i] + rui[i]

ans = 0
for i in range(N - 1):
    ans += (rui[N] - rui[i + 1]) * A[i]
    ans %= INF
print(ans % INF)
Buggy python submission (verdict: Time Limit Exceeded):
K = int(input())
if K % 2 == 0:
    print(-1)
    exit()

for i in range(1, K + 1):
    tmp = '7' * i
    if int(tmp) % K == 0:
        print(i)
        exit()

print(-1)

Fixed submission:
K = int(input())
if K % 2 == 0 or K % 5 == 0:
    print(-1)
    exit()

tmp1 = 0
for i in range(1, 2 * K + 1):
    tmp1 += 7 * pow(10, i, K)
    if tmp1 % K == 0:
        print(i)
        exit()

print(-1)
Buggy python submission (verdict: Runtime Error):
N = int(input())
c = input()
rlist = []
wlist = []
for i in range(N):
    if c[i] == 'R':
        rlist.append(i)
    else:
        wlist.append(i)

cnt = 0
for i in range(len(wlist)):
    if wlist[i] < rlist[-cnt - 1]:
        cnt += 1
    else:
        break
print(cnt)

Fixed submission:
N = int(input())
c = input()
rlist = []
wlist = []
for i in range(N):
    if c[i] == 'R':
        rlist.append(i)
    else:
        wlist.append(i)

cnt = 0
if len(rlist) == 0:
    print(0)
    exit()
for i in range(len(wlist)):
    if wlist[i] < rlist[-cnt - 1]:
        cnt += 1
    else:
        break
print(cnt)