Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
N, K = map(int, input().split())
# print('N:{}, K:{}'.format(N, K))

if K % 2 == 0:
    print(((N-K//2)//K+1)**3+(N//K)**3)
else:
    print((N//K)**3)


Fixed submission:
import collections

n=int(input())
v=list(map(int,input().split()))
v1=collections.Counter(v[0::2]).most_common()
v2=collections.Counter(v[1::2]).most_common()
v1.append((0,0))
v2.append((0,0))

if v1[0][0]!=v2[0][0]:
    ans=len(v) - v1[0][1] - v2[0][1]
else:
    ans=min(len(v) - v1[0][1] - v2[1][1],len(v) - v1[1][1] - v2[0][1])

print(ans)

Buggy python submission (verdict: Runtime Error):
N, K = map(int, input().split())
# print('N:{}, K:{}'.format(N, K))

if K % 2 == 0:
    print(((N-K//2)//K+1)**3+(N//K)**3)
else:
    print((N//K)**3)


Fixed submission:
import collections

n=int(input())
v=list(map(int,input().split()))
v1=collections.Counter(v[0::2]).most_common()
v2=collections.Counter(v[1::2]).most_common()
v1.append((0,0))
v2.append((0,0))

if v1[0][0]!=v2[0][0]:
    ans=len(v) - v1[0][1] - v2[0][1]
else:
    ans=min(len(v) - v1[0][1] - v2[1][1],len(v) - v1[1][1] - v2[0][1])

print(ans)

Buggy python submission (verdict: Runtime Error):
N, K = map(int, input().split())
print('N:{}, K:{}'.format(N, K))

if K % 2 == 0:
    print(((N-K//2)//K+1)**3+(N//K)**3)
else:
    print((N//K)**3)


Fixed submission:
import collections

n=int(input())
v=list(map(int,input().split()))
v1=collections.Counter(v[0::2]).most_common()
v2=collections.Counter(v[1::2]).most_common()
v1.append((0,0))
v2.append((0,0))

if v1[0][0]!=v2[0][0]:
    ans=len(v) - v1[0][1] - v2[0][1]
else:
    ans=min(len(v) - v1[0][1] - v2[1][1],len(v) - v1[1][1] - v2[0][1])

print(ans)

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

n=int(input())
v=list(map(int,input().split()))
v1=collections.Counter(v[0::2])
v2=collections.Counter(v[1::2])

if len(set(v)) == 1:
    ans=len(v[1::2])
else:
    if len(v1.most_common())==1:
        v1.append((0,0))
    if len(v2.most_common())==1:
        v2.append((0,0))
    ans=min(len(v) - v1.most_common()[0][1] - v2.most_common()[0][1],len(v) - v1.most_common()[0][1] - v2.most_common()[1][1],len(v) - v1.most_common()[1][1] - v2.most_common()[0][1])

print(ans)



Fixed submission:
import collections

n=int(input())
v=list(map(int,input().split()))
v1=collections.Counter(v[0::2]).most_common()
v2=collections.Counter(v[1::2]).most_common()
v1.append((0,0))
v2.append((0,0))

if v1[0][0]!=v2[0][0]:
    ans=len(v) - v1[0][1] - v2[0][1]
else:
    ans=min(len(v) - v1[0][1] - v2[1][1],len(v) - v1[1][1] - v2[0][1])

print(ans)

Buggy python submission (verdict: Runtime Error):
n=int(input())
v=list(map(int,input().split()))
v1=v[0::2]
v2=v[1::2]

print((len(v1)-v1.most_common()[0][1]) + (len(v2)-v2.most_common()[0][1]))

Fixed submission:
import collections

n=int(input())
v=list(map(int,input().split()))
v1=collections.Counter(v[0::2]).most_common()
v2=collections.Counter(v[1::2]).most_common()
v1.append((0,0))
v2.append((0,0))

if v1[0][0]!=v2[0][0]:
    ans=len(v) - v1[0][1] - v2[0][1]
else:
    ans=min(len(v) - v1[0][1] - v2[1][1],len(v) - v1[1][1] - v2[0][1])

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

N, M = map(int, input().split())

d = defaultdict(int)
for i in range(2, M+1):
    while M % i == 0:
        d[i] += 1
        M //= i
    if M == 1:
        break


def cmb(n, r, mod):
    if (r < 0 or r > n):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod


mod = 10**9+7  # 出力の制限
n = 100100
g1 = [1, 1]  # 元テーブル
g2 = [1, 1]  # 逆元テーブル
inverse = [0, 1]  # 逆元テーブル計算用テーブル

for i in range(2, n + 1):
    g1.append((g1[-1] * i) % mod)
    inverse.append((-inverse[mod % i] * (mod//i)) % mod)
    g2.append((g2[-1] * inverse[-1]) % mod)


ans = 1
for v in d.values():
    # print(v, cmb(v+N, N, mod))
    ans *= cmb(v+N-1, N-1, mod)

print(ans % mod)


Fixed submission:
from collections import defaultdict

N, M = map(int, input().split())

d = defaultdict(int)
for i in range(2, M+1):
    while M % i == 0:
        d[i] += 1
        M //= i
    if M == 1:
        break


def cmb(n, r, mod):
    if (r < 0 or r > n):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod


mod = 10**9+7  # 出力の制限
n = 100100
g1 = [1, 1]  # 元テーブル
g2 = [1, 1]  # 逆元テーブル
inverse = [0, 1]  # 逆元テーブル計算用テーブル

for i in range(2, n + 1):
    g1.append((g1[-1] * i) % mod)
    inverse.append((-inverse[mod % i] * (mod//i)) % mod)
    g2.append((g2[-1] * inverse[-1]) % mod)


ans = 1
for v in d.values():
    # print(v, cmb(v+N, N, mod))
    ans *= cmb(v+N-1, N-1, mod)

print(ans % mod)
Buggy python submission (verdict: Runtime Error):
from functools import reduce
from fractions import gcd

N,X=map(int,input().split())
x=[abs(i-X) for i in input().split()]

print(reduce(gcd,x))

Fixed submission:
from functools import reduce
from fractions import gcd

N,X=map(int,input().split())
x=[abs(int(i)-X) for i in input().split()]

print(reduce(gcd,x))

Buggy python submission (verdict: Time Limit Exceeded):
from functools import reduce
from fractions import gcd

N,X=map(int,input().split())
x=[int(i) for i in input().split()]
x.append(X)

x2 = map(lambda y: y-min(x), x)

print(reduce(gcd,x2))

Fixed submission:
from functools import reduce
from fractions import gcd

N,X=map(int,input().split())
x=[abs(int(i)-X) for i in input().split()]

print(reduce(gcd,x))
Buggy python submission (verdict: Runtime Error):
K = input()
print(((K+1)//2) * (K//2))

Fixed submission:
K = int(input())
print(((K+1)//2) * (K//2))

Buggy python submission (verdict: Runtime Error):
K = input()

print((K+1)//2 * K//2)

Fixed submission:
K = int(input())
print(((K+1)//2) * (K//2))
Buggy python submission (verdict: Time Limit Exceeded):
N,K=map(int,input().split())

if K%2==1:
    s=K
else:
    s=K//2

ans=[]

for i in range((N-s)//s+1):
    for j in range((N-s)//s+1):
        for k in range(N-s//s+1):
            if s+max(i,j,k)*s <= N and (2+i+j)*s%K==0 and (2+j+k)*s%K==0 and (2+k+i)*s%K==0:
                ans.append((s+i*s,s+j*s,s+k*s))

print(len(set(ans)))

Fixed submission:
N,K = [int(x) for x in input().split()]
 
result = 0
 
if (K%2) == 1:
    kouho = N//K
    result+=kouho*kouho*kouho
 
else:
    kouho1 = N//K
    kouho2 = N//(K/2) - kouho1
    result+=kouho1*kouho1*kouho1
    result+=kouho2*kouho2*kouho2
 
print(int(result))
Buggy python submission (verdict: Time Limit Exceeded):
N,K=map(int,input().split())
x=[int(i) for i in input().split()]

cost=10**13

for i in range(N-K+1):
    x2=x[i:i+K]
    c=x2[-1]-x2[0]+min(abs(x2[0]),abs(x2[-1]))
    cost=min(cost,c)

print(cost)


Fixed submission:
N,K=map(int,input().split())
x=[int(i) for i in input().split()]

cost=10**13

for i in range(N-K+1):
    c=x[i+K-1]-x[i]+min(abs(x[i]),abs(x[i+K-1]))
    cost=min(cost,c)

print(cost)

Buggy python submission (verdict: Time Limit Exceeded):
N,K=map(int,input().split())
x=[int(i) for i in input().split()]

import bisect

cost=10**13

for i in range(N-K+1):
    x2=x[i:i+K]
    c=min(abs(min(x2[0],0)),max(0,x2[-1]))*2 + max((-1)*x2[0],x2[-1])
    cost=min(cost,c)

print(cost)


Fixed submission:
N,K=map(int,input().split())
x=[int(i) for i in input().split()]

cost=10**13

for i in range(N-K+1):
    c=x[i+K-1]-x[i]+min(abs(x[i]),abs(x[i+K-1]))
    cost=min(cost,c)

print(cost)

Buggy python submission (verdict: Time Limit Exceeded):
N,K=map(int,input().split())
x=[int(i) for i in input().split()]

import bisect

zp=bisect.bisect_left(x,0)
cost=10**13

for i in range(max(0,zp-K),min(zp+1,N-K+1)):
    x2=x[i:i+K]
    c=min(abs(min(x2[0],0)),max(0,x2[-1]))*2 + max((-1)*x2[0],x2[-1])
    cost=min(cost,c)

print(cost)

Fixed submission:
N,K=map(int,input().split())
x=[int(i) for i in input().split()]

cost=10**13

for i in range(N-K+1):
    c=x[i+K-1]-x[i]+min(abs(x[i]),abs(x[i+K-1]))
    cost=min(cost,c)

print(cost)

Buggy python submission (verdict: Time Limit Exceeded):
N,K=map(int,input().split())
x=[int(i) for i in input().split()]

import bisect

zp=bisect.bisect_left(x,0)
cost=[]

for i in range(max(0,zp-K),min(zp+1,N-K+1)):
    x2=x[i:i+K]
    c=min(abs(min(x2[0],0)),max(0,x2[-1]))*2 + max((-1)*x2[0],x2[-1])
    cost.append(c)

print(min(cost))

Fixed submission:
N,K=map(int,input().split())
x=[int(i) for i in input().split()]

cost=10**13

for i in range(N-K+1):
    c=x[i+K-1]-x[i]+min(abs(x[i]),abs(x[i+K-1]))
    cost=min(cost,c)

print(cost)

Buggy python submission (verdict: Time Limit Exceeded):
N,K=map(int,input().split())
x=[int(i) for i in input().split()]

import bisect

zp=bisect.bisect_left(x,0)
cost=[]

for i in range(max(0,zp-K),min(zp+1,N-K+1)):
    x2=x[i:i+K]
    c=min(abs(min(x2[0],0)),max(0,x2[-1]))*2 + max((-1)*x2[0],x2[-1])
    cost.append(c)

print(min(cost))

Fixed submission:
N,K=map(int,input().split())
x=[int(i) for i in input().split()]

cost=10**13

for i in range(N-K+1):
    c=x[i+K-1]-x[i]+min(abs(x[i]),abs(x[i+K-1]))
    cost=min(cost,c)

print(cost)
Buggy python submission (verdict: Runtime Error):
import re

S=input()
K=int(input())

if not re.search(r'[^1]',S).start():
  print(1)
elif re.search(r'[^1]',S).start() >= K:
  print(1)
else:
  print(S[re.search(r'[^1]',S).start()])

Fixed submission:
import re

S=input()
K=int(input())

if not re.search(r'[^1]',S):
  print(1)
elif re.search(r'[^1]',S).start() >= K:
  print(1)
else:
  print(S[re.search(r'[^1]',S).start()])

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

S=input()
K=int(input())

if re.search(r'[^1]',S).start() >= K:
  print(1)
else:
  print(S[re.search(r'[^1]',S).start()])

Fixed submission:
import re

S=input()
K=int(input())

if not re.search(r'[^1]',S):
  print(1)
elif re.search(r'[^1]',S).start() >= K:
  print(1)
else:
  print(S[re.search(r'[^1]',S).start()])

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

S=input()
K=int(input())

if re.search(r'[^1]',S).start() >= K:
  print(1)
else:
  print(S[re.search(r'[^1]',S).start()])

Fixed submission:
import re

S=input()
K=int(input())

if not re.search(r'[^1]',S):
  print(1)
elif re.search(r'[^1]',S).start() >= K:
  print(1)
else:
  print(S[re.search(r'[^1]',S).start()])

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

S=input()
K=int(input())

if re.search(r'[^1]',S).start() >= K:
  print(1)
else:
  print(S[re.search(r'[^1]',S).start()])

Fixed submission:
import re

S=input()
K=int(input())

if not re.search(r'[^1]',S):
  print(1)
elif re.search(r'[^1]',S).start() >= K:
  print(1)
else:
  print(S[re.search(r'[^1]',S).start()])
Buggy python submission (verdict: Time Limit Exceeded):
N, M, Q = map(int, input().split())

X = [[0 for j in range(510)] for i in range(510)]
C = [[0 for j in range(510)] for i in range(510)]

LR = []
for i in range(M):
    L, R = map(int, input().split())
    X[L][R] += 1

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


for i in range(Q):
    p, q = map(int, input().split())
    sum = 0
    for j in range(p, q+1):
        sum += C[j][q]-C[j][p-1]
    print(sum)


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

X = [[0 for j in range(510)] for i in range(510)]
C = [[0 for j in range(510)] for i in range(510)]

LR = []
for i in range(M):
    L, R = map(int, input().split())
    X[L][R] += 1

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


for i in range(Q):
    p, q = map(int, input().split())
    sum = 0
    for j in range(p, q+1):
        sum += C[j][q]-C[j][p-1]
    print(sum)
Buggy python submission (verdict: Runtime Error):
N = int(intput())
l=[]

for i in range(26):
    for j in range(16):
        l.append(i*4+j*7):

if N in l:
    print('Yes')
else:
    print('No')

Fixed submission:
N = int(input())
l=[]

for i in range(26):
    for j in range(16):
        l.append(i*4+j*7)

if N in l:
    print('Yes')
else:
    print('No')

Buggy python submission (verdict: Runtime Error):
N = int(intput())

for i in range(26):
    for j in range(16):
        l.append(i*4+j*7):

if N in l:
    print('Yes')
else:
    print('No')

Fixed submission:
N = int(input())
l=[]

for i in range(26):
    for j in range(16):
        l.append(i*4+j*7)

if N in l:
    print('Yes')
else:
    print('No')
Buggy python submission (verdict: Time Limit Exceeded):
N, M = map(int, input().split())
A = [int(i) for i in input().split()]

S = [0 for _ in range(N+1)]

s = 0
for i in range(N):
    s += A[i]
    S[i+1] = s

ans = 0
for j in range(N+1):
    for i in range(j):
        if (S[j]-S[i]) % M == 0:
            ans += 1

print(ans)


Fixed submission:
from collections import defaultdict
N, M = map(int, input().split())
A = [int(i) for i in input().split()]

d = defaultdict(int)

s = 0
for i in range(N):
    d[s % M] += 1
    s += A[i]
d[s % M] += 1


ans = 0
for v in d.values():
    ans += v*(v-1)//2
print(ans)
Buggy python submission (verdict: Runtime Error):
import fractions
N = int(input())
print(2 * N / gcd(2,N))

Fixed submission:
import fractions
N = int(input())

print(2*N if N%2==1 else N)

Buggy python submission (verdict: Runtime Error):
import math
N = int(input())
print(math.gcd(2,N))

Fixed submission:
import fractions
N = int(input())

print(2*N if N%2==1 else N)
Buggy python submission (verdict: Runtime Error):
N=int(input())
A=[int(i) for i in input().split()]
SA=sum(A)

sum=[(i**2+i)//2 for i in range(2*10**5)]

i=0
while sum[i]<SA:
    i+=1

# print(sum[:20])
# print(i)

ans1=0
ans2=0
for j in range(N):
    ans1+=abs(A[j]-(i-N+j))
    ans2+=abs(A[j]-(i-N+j+1))

print(min(ans1,ans2))



Fixed submission:
N=int(input())
A=[int(i) for i in input().split()]
B=sorted([A[j]-j-1 for j in range(N)])

def median(seq):
    s = sorted(seq)
    if len(s) % 2 == 0:          # 要素が偶数個なら2つの平均
        return (s[len(s) // 2] + s[(len(s) // 2) - 1]) / 2
    else:
        return s[len(s) // 2]    # 要素が奇数個なら中央の値

b=median(B)

ans=0
for i in range(N):
    ans+=abs(A[i]-(b+i+1))

print(int(ans))
Buggy python submission (verdict: Runtime Error):
S = input()
print(S.count('+')-s.count('-'))

Fixed submission:
S = input()
print(S.count('+')-S.count('-'))
Buggy python submission (verdict: Runtime Error):
N = input()

sn = 0
for i in N:
    sn += i

if int(N)%sn ==0:
    print('Yes')
else:
    print('No')

Fixed submission:
N = input()

sn = 0
for i in N:
    sn += int(i)

if int(N)%sn ==0:
    print('Yes')
else:
    print('No')
Buggy python submission (verdict: Runtime Error):
N=int(input())
dp=[10**7]*110000
dp[0]=0

pow6=[6**j for j in range(10) if 6**j <= N]
pow9=[9**j for j in range(10) if 9**j <= N]

for i in range(N):
    for p6 in pow6:
        dp[i+p6]=min(dp[i+p6], dp[i]+1)

    for p9 in pow9:
        dp[i+p9]=min(dp[i+p9], dp[i]+1)

print(dp[N])

Fixed submission:
N=int(input())
dp=[10**7]*3000000
dp[0]=0

pow6=[6**j for j in range(10) if 6**j <= N]
pow9=[9**j for j in range(10) if 9**j <= N]

for i in range(N):
    for p6 in pow6:
        dp[i+p6]=min(dp[i+p6], dp[i]+1)
    for p9 in pow9:
        dp[i+p9]=min(dp[i+p9], dp[i]+1)

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

ans=0
for i in range(len(S)):
    a=set(S[:i])
    b=set(S[i:])
    if a&b>ans:
    	ans=a&b
print(ans)

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

ans=0
for i in range(len(S)):
    a=set(S[:i])
    b=set(S[i:])
    if len(a&b)>ans:
    	ans=len(a&b)
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
S=input()

ans=10**6
for i in range(N):
    ans=min(ans,(S[:i].count('W') + S[i+1:].count('E')))

print(ans)

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

ans=S[1:].count('E')
c=S[1:].count('E')
for i in range(1,N):
    if S[i]=='E':
        c-=1
    if S[i-1]=='W':
        c+=1
    ans=min(ans,c)
print(ans)
Buggy python submission (verdict: Runtime Error):
X=int(input())
ans=1
for i in range(2,33):
    j=2
    while(i**J<=X):
        if i**j>ans:
            ans=i**j
        j+=1

print(ans)

Fixed submission:
X=int(input())
ans=1
for i in range(2,33):
    j=2
    while(i**j<=X):
        if i**j>ans:
            ans=i**j
        j+=1

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import itertools

s=input()
K=int(input())

dic=[]

for i in range(1,6):
    for k in itertools.permutations('abcdefghijklmnopqrstuvwxyz', i):
        dic.append(''.join(k))
dic.sort()


ans=0
for str in dic:
    if str in s:
        ans+=1
    if ans==K:
        print(str)
        exit()

Fixed submission:
s=input()
K=int(input())
st=set()

for i in range(len(s)):
    for j in range(1,6):
        st.add(s[i:i+j])

sl=sorted(list(st))

print(sl[K-1])
Buggy python submission (verdict: Time Limit Exceeded):
s = input()
K = int(input())

SS = set()
for i in range(len(s)):
    for j in range(i+1, len(s)+1):
        SS.add(s[i:j])
print(sorted(list(SS))[K-1])

Fixed submission:
s = input()
K = int(input())

SS = set()
for i in range(len(s)):
    for j in range(i+1, i+6):
        SS.add(s[i:j])
print(sorted(list(SS))[K-1])
Buggy python submission (verdict: Runtime Error):
import itertools
import numpy as np
N = int(input())

U = 300000
is_prime = np.full(U+1, True)
is_prime[:2] = False
primes = set()
for p in range(2, U+1):
    if p*p > U:
        break
    if is_prime[p]:
        primes.add(p)
        is_prime[p*p::p] = False


ans = [2, 3, 5, 7, 11]
i = 13
while len(ans) < N:
    if i in primes:
        flg = True
        for p4 in itertools.combinations(ans, 4):
            if sum(p4)+i in primes:
                flg = False
        if flg:
            ans.append(i)
    i += 1
print(*ans)


Fixed submission:
import numpy as np
N = int(input())

U = 10**5
is_prime = np.full(U+1, True)
is_prime[:2] = False
for p in range(2, U+1):
    if p*p > U:
        break
    if is_prime[p]:
        is_prime[p*p::p] = False

ans = []
for c in range(11, 55556, 5):
    if is_prime[c]:
        ans.append(c)
        if len(ans) == N:
            print(*ans)
            exit()
Buggy python submission (verdict: Time Limit Exceeded):
N, C = map(int, input().split())

X = [0]
V = [0]
sV = [0]
for _ in range(N):
    x, v = map(int, input().split())
    X.append(x)
    V.append(v)
    sV.append(sV[-1]+v)
X.append(C)

ans = 0
for a in range(N+1):
    for b in range(a+1, N+2):
        # O -> A -> B
        a1 = sV[a]+sV[-1]-sV[b-1]-2*X[a]-(C-X[b])

        # O -> B -> A
        a2 = sV[a]+sV[-1]-sV[b-1]-X[a]-2*(C-X[b])

        ans = max(ans, a1, a2)

print(ans)


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

X = [0]
V = [0]
sV = [0]
Amax1 = [0]
Amax2 = [0]
for _ in range(N):
    x, v = map(int, input().split())
    X.append(x)
    V.append(v)
    sV.append(sV[-1]+v)
    Amax1.append(max(Amax1[-1], sV[-1]-x))
    Amax2.append(max(Amax2[-1], sV[-1]-2*x))
X.append(C)

ans = 0
for b in range(1, N+2):
    # O -> A -> B
    a1 = Amax2[b-1]+sV[-1]-sV[b-1]-(C-X[b])

    # O -> B -> A
    a2 = Amax1[b-1]+sV[-1]-sV[b-1]-2*(C-X[b])

    ans = max(ans, a1, a2)

print(ans)

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

X = [0]
V = [0]
sV = [0]
for _ in range(N):
    x, v = map(int, input().split())
    X.append(x)
    V.append(v)
    sV.append(sV[-1]+v)
X.append(C)

ans = 0
for a in range(N+1):
    for b in range(a+1, N+2):
        # O -> A -> B
        a1 = sV[a+1]+sV[-1]-sV[b-1]-2*X[a]-(C-X[b])

        # O -> B -> A
        a2 = sV[a+1]+sV[-1]-sV[b-1]-X[a]-2*(C-X[b])

        ans = max(ans, a1, a2)

print(ans)


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

X = [0]
V = [0]
sV = [0]
Amax1 = [0]
Amax2 = [0]
for _ in range(N):
    x, v = map(int, input().split())
    X.append(x)
    V.append(v)
    sV.append(sV[-1]+v)
    Amax1.append(max(Amax1[-1], sV[-1]-x))
    Amax2.append(max(Amax2[-1], sV[-1]-2*x))
X.append(C)

ans = 0
for b in range(1, N+2):
    # O -> A -> B
    a1 = Amax2[b-1]+sV[-1]-sV[b-1]-(C-X[b])

    # O -> B -> A
    a2 = Amax1[b-1]+sV[-1]-sV[b-1]-2*(C-X[b])

    ans = max(ans, a1, a2)

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N, C = map(int, input().split())

X = [0]
V = [0]
for _ in range(N):
    x, v = map(int, input().split())
    X.append(x)
    V.append(v)
X.append(C)

ans = 0
for a in range(N+1):
    for b in range(a+1, N+2):
        # O -> A -> B
        a1 = sum(V[:a+1])+sum(V[b:])-2*X[a]-(C-X[b])

        # O -> B -> A
        a2 = sum(V[:a+1])+sum(V[b:])-X[a]-2*(C-X[b])

        ans = max(ans, a1, a2)

print(ans)

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

X = [0]
V = [0]
sV = [0]
Amax1 = [0]
Amax2 = [0]
for _ in range(N):
    x, v = map(int, input().split())
    X.append(x)
    V.append(v)
    sV.append(sV[-1]+v)
    Amax1.append(max(Amax1[-1], sV[-1]-x))
    Amax2.append(max(Amax2[-1], sV[-1]-2*x))
X.append(C)

ans = 0
for b in range(1, N+2):
    # O -> A -> B
    a1 = Amax2[b-1]+sV[-1]-sV[b-1]-(C-X[b])

    # O -> B -> A
    a2 = Amax1[b-1]+sV[-1]-sV[b-1]-2*(C-X[b])

    ans = max(ans, a1, a2)

print(ans)
Buggy python submission (verdict: Runtime Error):
N=int(input())
X=[int(i) for _ in input().split()]

Y=sorted(X)

a1=Y[N//2]
a2=Y[N//2-1]

for i in range(N):
    if X[i]<=a1:
        print(a1)
    else:
        print(a2)

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

Y=sorted(X)

a1=Y[N//2-1]
a2=Y[N//2]

for i in range(N):
    if X[i]<=a1:
        print(a2)
    else:
        print(a1)

Buggy python submission (verdict: Runtime Error):
N=int(input())
X=[int(i) for _ in input().split())]

Y=sorted(X)

a1=Y[N//2]
a2=Y[N//2-1]

for i in range(N):
    if X[i]<=a1:
        print(a1)
    else:
        print(a2)

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

Y=sorted(X)

a1=Y[N//2-1]
a2=Y[N//2]

for i in range(N):
    if X[i]<=a1:
        print(a2)
    else:
        print(a1)
Buggy python submission (verdict: Time Limit Exceeded):
H, W, D = map(int, input().split())
A = [[int(j) for j in input().split()] for i in range(H)]
B = [(-1, -1) for j in range(H*W)]
for i in range(H):
    for j in range(W):
        B[A[i][j]-1] = (i, j)

C = [-1] * H*W
for i in range(H*W-D):
    fx, fy = B[i+D]
    tx, ty = B[i]
    C[i] = abs(fx-tx)+abs(fy-ty)

Q = int(input())
for _ in range(Q):
    L, R = map(int, input().split())
    ans = 0
    for i in range(L, R, D):
        ans += C[i-1]
    print(ans)


Fixed submission:
H, W, D = map(int, input().split())
A = [[int(j) for j in input().split()] for i in range(H)]
B = [(-1, -1) for j in range(H*W)]
for i in range(H):
    for j in range(W):
        B[A[i][j]-1] = (i, j)

C = [-1] * H*W
for i in range(H*W-D):
    fx, fy = B[i+D]
    tx, ty = B[i]
    C[i] = abs(fx-tx)+abs(fy-ty)

E = [0] * H*W
for i in range(D):
    S = 0
    for j in range(i, H*W-D, D):
        S += C[j]
        E[j+D] = S
# print(E)

Q = int(input())
for _ in range(Q):
    L, R = map(int, input().split())
    print(E[R-1]-E[L-1])

Buggy python submission (verdict: Time Limit Exceeded):
H, W, D = map(int, input().split())
A = [[int(j) for j in input().split()] for i in range(H)]
B = [(-1, -1) for j in range(H*W)]
for i in range(H):
    for j in range(W):
        B[A[i][j]-1] = (i, j)

C = [-1] * H*W
for i in range(H*W-D):
    fx, fy = B[i+D]
    tx, ty = B[i]
    C[i] = abs(fx-tx)+abs(fy-ty)

Q = int(input())
for _ in range(Q):
    L, R = map(int, input().split())
    ans = 0
    for i in range(L, R, D):
        ans += C[i-1]
    print(ans)


Fixed submission:
H, W, D = map(int, input().split())
A = [[int(j) for j in input().split()] for i in range(H)]
B = [(-1, -1) for j in range(H*W)]
for i in range(H):
    for j in range(W):
        B[A[i][j]-1] = (i, j)

C = [-1] * H*W
for i in range(H*W-D):
    fx, fy = B[i+D]
    tx, ty = B[i]
    C[i] = abs(fx-tx)+abs(fy-ty)

E = [0] * H*W
for i in range(D):
    S = 0
    for j in range(i, H*W-D, D):
        S += C[j]
        E[j+D] = S
# print(E)

Q = int(input())
for _ in range(Q):
    L, R = map(int, input().split())
    print(E[R-1]-E[L-1])
Buggy python submission (verdict: Runtime Error):
X,Y=map(input().split())
if X%Y==0:
    print(-1)
else:
    X2=X
    while X2>10**18:
        X2+=X
        if X2%Y!=0:
            print(X2)
            exit()
print(-1)

Fixed submission:
X,Y=map(int,input().split())
if X%Y==0:
    print(-1)
    exit()
else:
    X2=X
    while X2<=10**18:
        X2+=X
        if X2%Y!=0:
            print(X2)
            exit()
print(-1)