Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
N = int(input())
A = [int(x) for x in input().split()]
p = []
m = []
for a in A:
    if a < 0:
        m.append(a)
    else:
        p.append(a)
was = []
if N == 2:
    print(max(A)-min(A))
    print(max(A), min(A))
    quit()
p.sort()
if len(m) == 0:
    m.append(p[-1] - p[0])
    was.append((p[-1], p[0]))
    p = p[1:-1]

mm = m[0]
m = m[1:]
pp = p[0]
p = p[1:]
for x in p:
    was.append((mm,x))
    mm -= x
for x in m:
    was.append((pp,x))
    pp -= x
was.append((pp, mm))
print(pp-mm)
for p,m in was:
    print(p,m)

Fixed submission:
N = int(input())
A = [int(x) for x in input().split()]
p = []
m = []
for a in A:
    if a < 0:
        m.append(a)
    else:
        p.append(a)
was = []
if N == 2:
    print(max(A)-min(A))
    print(max(A), min(A))
    quit()
if len(m) == 0:
    p.sort()
    m.append(p[0] - p[-1])
    was.append((p[0], p[-1]))
    p = p[1:-1]
elif len(p) == 0:
    m.sort()
    p.append(m[-1] - m[0])
    was.append((m[-1], m[0]))
    m = m[1:-1]

mm = m[0]
m = m[1:]
pp = p[0]
p = p[1:]
for x in p:
    was.append((mm,x))
    mm -= x
for x in m:
    was.append((pp,x))
    pp -= x
was.append((pp, mm))
print(pp-mm)
for p,m in was:
    print(p,m)

Buggy python submission (verdict: Runtime Error):
N = int(input())
A = [int(x) for x in input().split()]
A.sort()
was = []
def x(A,N):
    newA = []
    sw = True
    for i in range(N//2):
        if sw:
            was.append((A[i], A[-(i+1)]))
            newA.append(A[i] - A[-(i+1)])
        else:
            was.append((A[-(i+1)], A[i]))
            newA.append(A[-(i+1)] - A[i])
        sw = not sw
    if N%2 != 0:
        newA.append(A[N//2])
    if len(newA) == 2:
        was.append((max(newA), min(newA)))
        return max(newA) - min(newA)
    else:
        newA.sort()
        return x(newA, len(newA))

print(x(A,N))
for x,y in was:
    print(x, y)

Fixed submission:
N = int(input())
A = [int(x) for x in input().split()]
p = []
m = []
for a in A:
    if a < 0:
        m.append(a)
    else:
        p.append(a)
was = []
if N == 2:
    print(max(A)-min(A))
    print(max(A), min(A))
    quit()
if len(m) == 0:
    p.sort()
    m.append(p[0] - p[-1])
    was.append((p[0], p[-1]))
    p = p[1:-1]
elif len(p) == 0:
    m.sort()
    p.append(m[-1] - m[0])
    was.append((m[-1], m[0]))
    m = m[1:-1]

mm = m[0]
m = m[1:]
pp = p[0]
p = p[1:]
for x in p:
    was.append((mm,x))
    mm -= x
for x in m:
    was.append((pp,x))
    pp -= x
was.append((pp, mm))
print(pp-mm)
for p,m in was:
    print(p,m)
Buggy python submission (verdict: Runtime Error):
N = int(input())
S = input()

# 右全部#にする

b = S.count('W')

ans = 10**9
cost = 0
for c in S:
    if c == '.':
        # 今見てる所以降全部白にする事を考える
        w -= 1
        # まだ見てない白の数 + 今まで白にした黒のコストが答え候補
        if w + cost < ans:
            ans = w + cost
    else:
        # 今見てる所が黒の場合、白の個数は減らない
        if w + cost< ans:
            ans = w + cost
        # 以降の計算に向けてコストを1増やす
        cost += 1

print(ans)

Fixed submission:
import bisect
N = int(input())
S = input()
# 右全部#
b = []
w = []
for i in range(N):
    if S[i] == '#':
        b.append(i)
    if S[i] == '.':
        w.append(i)

kouho = []
for i in range(0,N+1):
    cost = 0
    #iより右にある白の数
    cost += len(w) - bisect.bisect_left(w,i)
    #iより左にある黒の数
    cost += bisect.bisect_left(b,i)
    
    if cost >= 0:
        kouho.append(cost)

print(min(kouho))
Buggy python submission (verdict: Runtime Error):
S = input()

result = []
count = 0
for i in range(len(S)):
    if S[i] == 'A' or S[i] == 'C' or S[i] == 'G' or S[i] == 'T':
        count += 1
    else:
        result.append(count)
        count = 0

print(max(result))

Fixed submission:
S = input()

result = [0]
count = 0
for i in range(len(S)):
    if S[i] == 'A' or S[i] == 'C' or S[i] == 'G' or S[i] == 'T':
        count += 1
    else:
        result.append(count)
        count = 0
result.append(count)
print(max(result))
Buggy python submission (verdict: Time Limit Exceeded):
N, Q = map(int, input().split())
S = input()
qlist = []
for i in range(Q):
    l, r = map(int, input().split())
    qlist.append((l,r))

result = []
for l, r in qlist:
    target = S[l-1:r]
    cache = 0
    for i,j in zip(range(r-l+1), range(1,r-l+1)):
        if target[i] == 'A' and target[j] == 'C':
            cache +=1
    result.append(cache)

for c in result:
    print(c)

Fixed submission:
import bisect
N, Q = map(int, input().split())
S = input()
qlist = []
for i in range(Q):
    l, r = map(int, input().split())
    qlist.append((l,r))
Alist = [i for i, x in enumerate(S) if x == 'A']
Clist = [i for i, x in enumerate(S) if x == 'C']
AClist = []
for c in Clist:
    if Alist[bisect.bisect_left(Alist, c)-1] == c-1:
        AClist.append(Alist[bisect.bisect_left(Alist, c)-1])

for l, r in qlist:
    idxa = bisect.bisect_left(AClist, l-1)
    idxb = bisect.bisect_left(AClist, r-1)
    print(idxb - idxa)
Buggy python submission (verdict: Runtime Error):
N, M = input().split()
N = int(N)
M = int(M)

def diffculc(st, ed):
    if ed < st:
        tmp = ed
        ed = st
        st = tmp
    if st < 0 and ed < 0:
        diff = abs(st - ed)
    elif -1 < st and ed < 0:
        diff = abs(ed - st)
    elif st < 0 and -1 < ed:
        diff = abs(st - ed)
    elif -1 < st and -1 < ed:
        diff = ed - st
    return diff

xList = [int(x) for x in input().split()]
sortedList = sorted(xList)

# 0番目と1番目の間のdiffはdiffcache[0]
diffcache = {}
diff = 0
for i, x in enumerate(sortedList):
    if i == len(sortedList) - 1:
        break
    diffcache[i] = diffculc(sortedList[i+1], x)

rangeset = []
counter = 0
for k, v in sorted(diffcache.items(), key=lambda x: -x[1]):
    if counter == N - 1:
        break
    diffcache.pop(k)
    counter = counter + 1

result = 0
for k,v in diffcache:
    result = result + v
print(result)

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

def diffculc(st, ed):
    if ed < st:
        tmp = ed
        ed = st
        st = tmp
    if st < 0 and ed < 0:
        diff = abs(st - ed)
    elif -1 < st and ed < 0:
        diff = abs(ed - st)
    elif st < 0 and -1 < ed:
        diff = abs(st - ed)
    elif -1 < st and -1 < ed:
        diff = ed - st
    return diff

xList = [int(x) for x in input().split()]
sortedList = sorted(xList)

# 0番目と1番目の間のdiffはdiffcache[0]
diffcache = {}
diff = 0
for i, x in enumerate(sortedList):
    if i == len(sortedList) - 1:
        break
    diffcache[i] = diffculc(sortedList[i+1], x)

rangeset = []
counter = 0
for k, v in sorted(diffcache.items(), key=lambda x: -x[1]):
    if counter == N - 1:
        break
    diffcache.pop(k)
    counter = counter + 1

result = 0
for k,v in diffcache.items():
    result = result + v
print(result)
Buggy python submission (verdict: Time Limit Exceeded):
import sys
sys.setrecursionlimit(10**6)

N = int(input())
hList = [int(x) for x in input().split()]

def dfs(idx):
    if idx < N-2:
        return min(abs(hList[idx] - hList[idx+1]) + dfs(idx+1), abs(hList[idx] - hList[idx+2]) + dfs(idx+2))
    elif idx < N-1:
        return abs(hList[idx] - hList[idx+1]) + dfs(idx+1)
    else:
        return 0

print(dfs(0))

Fixed submission:
N = int(input())
hList = [int(x) for x in input().split()]

#i番目まで飛んだ時点で一番小さい値、を計算していく
dp = [0, abs(hList[0] - hList[1])]
for i in range(2,N):
    dp.append(min(dp[i-2] + abs(hList[i-2] - hList[i]), dp[i-1] + abs(hList[i-1] - hList[i])))
print(dp[-1])

Buggy python submission (verdict: Runtime Error):
N = int(input())
hList = [int(x) for x in input().split()]

def dfs(idx):
    if idx < N-2:
        return min(abs(hList[idx] - hList[idx+1]) + dfs(idx+1), abs(hList[idx] - hList[idx+2]) + dfs(idx+2))
    elif idx < N-1:
        return abs(hList[idx] - hList[idx+1]) + dfs(idx+1)
    else:
        return 0

print(dfs(0))

Fixed submission:
N = int(input())
hList = [int(x) for x in input().split()]

#i番目まで飛んだ時点で一番小さい値、を計算していく
dp = [0, abs(hList[0] - hList[1])]
for i in range(2,N):
    dp.append(min(dp[i-2] + abs(hList[i-2] - hList[i]), dp[i-1] + abs(hList[i-1] - hList[i])))
print(dp[-1])

Buggy python submission (verdict: Runtime Error):
N = int(input())
hList = [int(x) for x in input().split()]


def dfs(idx):
    if idx == N-1:
        return 0
    if idx < N-2:
        return min(abs(hList[idx] - hList[idx+1]) + dfs(idx+1), abs(hList[idx] - hList[idx+2]) + dfs(idx+2))
    elif idx < N-1:
        return abs(hList[idx] - hList[idx+1]) + dfs(idx+1)

print(dfs(0))

Fixed submission:
N = int(input())
hList = [int(x) for x in input().split()]

#i番目まで飛んだ時点で一番小さい値、を計算していく
dp = [0, abs(hList[0] - hList[1])]
for i in range(2,N):
    dp.append(min(dp[i-2] + abs(hList[i-2] - hList[i]), dp[i-1] + abs(hList[i-1] - hList[i])))
print(dp[-1])
Buggy python submission (verdict: Time Limit Exceeded):
N, W = map(int, input().split())
wvs = [tuple(map(int, input().split())) for i in range(N)]
dp = [[0 for j in range(W+1)] for i in range(N)]

for i, wv in enumerate(wvs):
    for j in range(W+1):
        if i == 0:
            if wv[0] < j+1:
                dp[0][j] = wv[1]
        elif wv[0] < j+1:
            dp[i][j] = max(dp[i-1][j-wv[0]] + wv[1], dp[i-1][j])
        else:
            dp[i][j] = dp[i-1][j]

print(dp[-1][-1])

Fixed submission:
N, W = map(int, input().split())
wvs = [tuple(map(int, input().split())) for i in range(N)]
dp = [[0 for j in range(W+1)] for i in range(N)]

for i, wv in enumerate(wvs):
    for j in range(W+1):
        if i == 0:
            if wv[0] < j+1:
                dp[0][j] = wv[1]
        elif wv[0] < j+1:
            dp[i][j] = max(dp[i-1][j-wv[0]] + wv[1], dp[i-1][j])
        else:
            dp[i][j] = dp[i-1][j]

print(dp[-1][-1])

Buggy python submission (verdict: Time Limit Exceeded):
N, W = map(int, input().split())
wvs = [tuple(map(int, input().split())) for i in range(N)]
dp = [[0 for j in range(W+1)] for i in range(N)]

for i, wv in enumerate(wvs):
    for j in range(W+1):
        if i == 0:
            if wv[0] < j+1:
                dp[0][j] = wv[1]
        elif wv[0] < j+1:
            dp[i][j] = max(dp[i-1][j-wv[0]] + wv[1], dp[i-1][j])
        else:
            dp[i][j] = dp[i-1][j]

print(max(dp[-1]))

Fixed submission:
N, W = map(int, input().split())
wvs = [tuple(map(int, input().split())) for i in range(N)]
dp = [[0 for j in range(W+1)] for i in range(N)]

for i, wv in enumerate(wvs):
    for j in range(W+1):
        if i == 0:
            if wv[0] < j+1:
                dp[0][j] = wv[1]
        elif wv[0] < j+1:
            dp[i][j] = max(dp[i-1][j-wv[0]] + wv[1], dp[i-1][j])
        else:
            dp[i][j] = dp[i-1][j]

print(dp[-1][-1])
Buggy python submission (verdict: Runtime Error):
S = input()

count = 0
for i in range(len(S)):
    if S[i] == 'W':
        continue
    else:
        break
S = S[i:]

count = 0
score = 0
for i in range(len(S))
    if S[i] == 'W':
        score += (i - count)
        count += 1
print(score)

Fixed submission:
S = input()

count = 0
for i in range(len(S)):
    if S[i] == 'W':
        continue
    else:
        break
S = S[i:]

count = 0
score = 0
for i in range(len(S)):
    if S[i] == 'W':
        score += (i - count)
        count += 1
print(score)

Buggy python submission (verdict: Time Limit Exceeded):
S = input()

count = 0
while True:
    c = S.count('BW')
    if c == 0:
        break
    S = S.replace('BW', 'WB')
    count += c
print(count)

Fixed submission:
S = input()

count = 0
for i in range(len(S)):
    if S[i] == 'W':
        continue
    else:
        break
S = S[i:]

count = 0
score = 0
for i in range(len(S)):
    if S[i] == 'W':
        score += (i - count)
        count += 1
print(score)

Buggy python submission (verdict: Time Limit Exceeded):
S = input()
counter = 0
while True:
    tmp = S.replace("BW", "WB", 1)
    if S == tmp:
        break
    S = tmp
    counter += 1

print(counter)

Fixed submission:
S = input()

count = 0
for i in range(len(S)):
    if S[i] == 'W':
        continue
    else:
        break
S = S[i:]

count = 0
score = 0
for i in range(len(S)):
    if S[i] == 'W':
        score += (i - count)
        count += 1
print(score)

Buggy python submission (verdict: Time Limit Exceeded):
S = input()
counter = 0
while True:
    if S == S.replace("BW", "WB", 1):
        # 終わった
        break
    S = S.replace("BW", "WB", 1)
    counter += 1

print(counter)

Fixed submission:
S = input()

count = 0
for i in range(len(S)):
    if S[i] == 'W':
        continue
    else:
        break
S = S[i:]

count = 0
score = 0
for i in range(len(S)):
    if S[i] == 'W':
        score += (i - count)
        count += 1
print(score)
Buggy python submission (verdict: Runtime Error):
n = int(input())
prices = []
for i in range(0,n):
    prices[i] = int(input())

coupon = max(prices) / 2

total = sum(prices) - coupon
print(total)

Fixed submission:
n = int(input())
prices = []
for i in range(0,n):
    prices.append(int(input()))
    
coupon = max(prices) // 2
    
total = sum(prices) - coupon
print(total)
Buggy python submission (verdict: Time Limit Exceeded):
n, k = [int(i) for i in input().split()]
heights = [int(input()) for i in range(n)]

heights.sort()

# あり得る最大のサイズ差
answer = max(heights) - min(heights)

for i in range(0, n-k+1):
    x = heights[i:i + k]
    candidate = max(x) - min(x)
    if candidate < answer:
        answer = candidate

print(answer)

Fixed submission:
n, k = [int(i) for i in input().split()]
heights = [int(input()) for i in range(n)]

heights.sort()

# あり得る最大のサイズ差
answer = max(heights) - min(heights)

for i in range(0, n-k+1):
    candidate = heights[i+k-1] - heights[i]
    if candidate < answer:
        answer = candidate

print(answer)

Buggy python submission (verdict: Time Limit Exceeded):
n, k = [int(i) for i in input().split()]
heights = []
for i in range(0,n):
    heights.append(int(input()))

heights.sort()

answer = -1
for i in range(0, n-k+1):
    xlist = heights[i:i + k]
    item = max(xlist) - min(xlist)
    if answer == -1 or item < answer:
        answer = item

print(answer)

Fixed submission:
n, k = [int(i) for i in input().split()]
heights = [int(input()) for i in range(n)]

heights.sort()

# あり得る最大のサイズ差
answer = max(heights) - min(heights)

for i in range(0, n-k+1):
    candidate = heights[i+k-1] - heights[i]
    if candidate < answer:
        answer = candidate

print(answer)
Buggy python submission (verdict: Runtime Error):
x = input()

if x == '7' or x == '5' or x == '3':
  print('YES'
else:
  print('NO')

Fixed submission:
x = input()

if x == '7' or x == '5' or x == '3':
  print('YES')
else:
  print('NO')
Buggy python submission (verdict: Runtime Error):
    def gcd(a, b):
        while b:
            a, b = b, a % b
        return a
     
    N, X = input().split()
    xList = [int(x) for x in input().split()]
    N = int(N)
    X = int(X)
    xList.append(X)
    xList.sort()
    diffList = []
    for x, xx in zip(xList, xList[1:]):
        diffList.append(xx - x)
    if len(diffList) > 1:
        diffList.sort()
        gcdList = []
        for x in diffList[1:]:
            gcdList.append(gcd(diffList[0], x))
        gcdList.sort()
        print(gcdList[0])
    else:
        print(diffList[0])

Fixed submission:
def gcd(a, b):
    while b:
        a, b = b, a % b
    return a
    
N, X = input().split()
xList = [int(x) for x in input().split()]
N = int(N)
X = int(X)
xList.append(X)
xList.sort()
diffList = []
for x, xx in zip(xList, xList[1:]):
    diffList.append(xx - x)
if len(diffList) > 1:
    diffList.sort()
    gcdList = []
    for x in diffList[1:]:
        gcdList.append(gcd(diffList[0], x))
    gcdList.sort()
    print(gcdList[0])
else:
    print(diffList[0])

Buggy python submission (verdict: Runtime Error):
import fraction

N, X = input().split()
xList = [int(x) for x in input().split()]
N = int(N)
X = int(X)
xList.append(X)
xList.sort()
diffList = []
for x, xx in zip(xList, xList[1:]):
    diffList.append(xx - x)

diffList.sort()

print(fraction.gcd(diffList[0], diffList[-1]))

Fixed submission:
def gcd(a, b):
    while b:
        a, b = b, a % b
    return a
    
N, X = input().split()
xList = [int(x) for x in input().split()]
N = int(N)
X = int(X)
xList.append(X)
xList.sort()
diffList = []
for x, xx in zip(xList, xList[1:]):
    diffList.append(xx - x)
if len(diffList) > 1:
    diffList.sort()
    gcdList = []
    for x in diffList[1:]:
        gcdList.append(gcd(diffList[0], x))
    gcdList.sort()
    print(gcdList[0])
else:
    print(diffList[0])
Buggy python submission (verdict: Runtime Error):
n=int(input())
a=[]
for i in range(n):
    a.append(int(input()))

print(max(a) - min(a))

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

print(max(a) - min(a))
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
aList = [int(x) for x in input().split()]

# 2で割るor3倍にする
# 全部3倍はダメで、操作後は整数でないとダメ。

en = aList
count = 0
while True:
    cache = []
    for x in en:
        if x % 2 == 0:
            if len(cache) > 0:
                cache.append(int(3*x))
            else:
                cache.append(x // 2)

    if len(cache) > 0:
        count += 1
    else:
        break
    en = cache

print(count)

Fixed submission:
N = int(input())
aList = [int(x) for x in input().split()]

def calc(x, cache):
    if x % 2 == 0:
        return calc(x//2, cache+1)
    else:
        return cache

count = 0
for x in aList:
    if x % 2 == 0:
        count += calc(x, 0)

print(count)
Buggy python submission (verdict: Runtime Error):
H, W = map(int,input().split())

hw = []
hw.append('.'*W)
for _ in range(H):
    edited = input()
    edited = '.' + edited + '.'
    hw.append(edited)
hw.append('.'*W)
#四方を白に囲まれた黒がある場合に達成不可能

for i in range(1,H+1):
    for j in range(1,W+1):
        if hw[i][j] == '#':
            #探索
            if hw[i+1][j] == '.' and hw[i-1][j] == '.' and hw[i][j+1] == '.' and hw[i][j-1] == '.':
                print('No')
                quit()

print('Yes')

Fixed submission:
H, W = map(int,input().split())

hw = []
hw.append('.'*(W+2))
for _ in range(H):
    edited = input()
    edited = '.' + edited + '.'
    hw.append(edited)
hw.append('.'*(W+2))
#四方を白に囲まれた黒がある場合に達成不可能
for i in range(1,H+1):
    for j in range(1,W+1):
        if hw[i][j] == '#':
            #探索
            if hw[i+1][j] == '.' and hw[i-1][j] == '.' and hw[i][j+1] == '.' and hw[i][j-1] == '.':
                print('No')
                quit()

print('Yes')
Buggy python submission (verdict: Time Limit Exceeded):
import bisect
N = int(input())
Alist = [int(x) for x in input().split()]
Blist = [int(x) for x in input().split()]
Clist = [int(x) for x in input().split()]

Alist.sort()
Blist.sort()
Clist.sort()

cache = []
result = 0
doneb = 0
donea = 0
for c in Clist:
    idxc = bisect.bisect_left(Blist, c)
    for i in range(0, idxc):
        b = Blist[i]
        idxb = bisect.bisect_left(Alist, b)
        result += idxb

print(result)

Fixed submission:
import bisect
N = int(input())
Alist = [int(x) for x in input().split()]
Blist = [int(x) for x in input().split()]
Clist = [int(x) for x in input().split()]

Alist.sort()
Blist.sort()
Clist.sort()

result = 0
for b in Blist:
    a = bisect.bisect_left(Alist, b)
    c = N - bisect.bisect_right(Clist, b)
    result += a*c

print(result)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
Alist = [int(x) for x in input().split()]
Blist = [int(x) for x in input().split()]
Clist = [int(x) for x in input().split()]

Alist.sort()
Blist.sort()
Clist.sort()

cache = []
result = 0
doneb = 0
donea = 0
for i in range(0, len(Clist)):
    c = Clist[i]
    for j in range(doneb, len(Blist)):
        b = Blist[j]
        if b >= c:
            break
        doneb += 1
        acount = donea
        for k in range(donea, len(Alist)):
            a = Alist[k]
            if a >= b:
                break
            acount += 1
            donea += 1
        cache.append(acount)
    result += sum(cache)

print(result)

Fixed submission:
import bisect
N = int(input())
Alist = [int(x) for x in input().split()]
Blist = [int(x) for x in input().split()]
Clist = [int(x) for x in input().split()]

Alist.sort()
Blist.sort()
Clist.sort()

result = 0
for b in Blist:
    a = bisect.bisect_left(Alist, b)
    c = N - bisect.bisect_right(Clist, b)
    result += a*c

print(result)
Buggy python submission (verdict: Runtime Error):
N,X = map(int, input().split())

if N/2 == X:
    print(X*3)
elif N/2 > X:
    # 上側
    l = X + N - X
    l += ((N-X)//X)*2
    n = (N-X)%X
    l += (X//n)*2*n
    l += n
else:
    l = X
    n = X-N
    l += (N//n)*2*n
print(l)

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

if N/2 == X:
    l = X*3
elif N/2 > X:
    l = N
    x = X
    n = N - X
    while x > 0:
        l += (n//x)*2*x
        c = x
        x = n%x
        n = c
    l -= n
else:
    l = N
    x = X
    n = N - X
    while x > 0:
        l += (n//x)*2*x
        c = x
        x = n%x
        n = c
    l -= n
print(l)

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

if N/2 == X:
    print(X*3)
else:
    # 上側
    l = X + N - X
    while X > 0:
        l += X*2
        X -= 1
    l += 1
print(l)

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

if N/2 == X:
    l = X*3
elif N/2 > X:
    l = N
    x = X
    n = N - X
    while x > 0:
        l += (n//x)*2*x
        c = x
        x = n%x
        n = c
    l -= n
else:
    l = N
    x = X
    n = N - X
    while x > 0:
        l += (n//x)*2*x
        c = x
        x = n%x
        n = c
    l -= n
print(l)
Buggy python submission (verdict: Runtime Error):
print(100000-int(input().split())%1000)


Fixed submission:
print((100000-int(input()))%1000)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = sorted(list(map(int, input().split())))
q = int(input())
l1 = [0]*(10**5+10)
l2 = [0]*(10**5+10)
index = 0
l1[0] = a[0]
l2[0] = 1
for i in a[1:]:
    if i == l1[index]:
        l2[index] += 1
    else:
        index += 1
        l1[index] = i
        l2[index] = 1
s = sum(a)
for _ in range(q):
    b, c = map(int, input().split())

    i = 0
    while i < index + 2:
        if (b == l1[i]):
            break
        i += 1
    if i > index:
        print(s)
        continue

    j = 0
    while j < index + 2:
        if(c == l1[j]):
            break
        j += 1
    if j > index:
        index = j
        l1[index] = c
    s += (c - b) * l2[i]
    l2[j] += l2[i]
    l2[i] = 0
    print(s)


Fixed submission:
n = int(input())
a = sorted(list(map(int, input().split())))
q = int(input())
l = [0]*(10**5+10)
for i in a:
    l[i] += 1
s = sum(a)
for _ in range(q):
    b, c = map(int, input().split())
    s += (c - b) * l[b]
    l[c] += l[b]
    l[b] = 0
    print(s)
Buggy python submission (verdict: Runtime Error):
n = input()
s = [0] * 2020
m = [0] * 2020
m[0] = 1
s[0] = 1
for i in range(1, 2020):
    m[i] = (m[i-1]*10) % 2019
tmp = 0
for i in range(len(n)):
    #print(i, n[-1-i], m[i])
    tmp = (tmp + int(n[-1-i])*m[i]) % 2019
    # print(tmp)
    s[tmp] += 1
su = 0
for i in s:
    if i > 1:
        # print("#", i)
        su += i * (i - 1)//2
print(su)


Fixed submission:
n = input()
l = len(n)
s = [0] * 2020
m = [0] * (l+1)
m[0] = 1
s[0] = 1
for i in range(1, l+1):
    m[i] = (m[i-1]*10) % 2019
tmp = 0
n = list(n)[::-1]
for i in range(len(n)):
    #print(i, n[-1-i], m[i])
    tmp = (tmp + int(n[i])*m[i]) % 2019
    # print(tmp)
    s[tmp] += 1
su = 0
for i in s:
    if i > 1:
        # print("#", i)
        su += i * (i - 1)//2
print(su)