Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
n, a, b = map(int, input().split())

fulls = n // (a+b)
lefts = n % (a+b)

print(fulls*a + min(left, a))

Fixed submission:
n, a, b = map(int, input().split())
 
fulls = n // (a+b)
lefts = n % (a+b)
 
print(fulls*a + min(lefts, a))
Buggy python submission (verdict: Runtime Error):
n = int(input())
a = list(map(int, input().split()))

inf = int(1e9)

dp = [inf]*(n+3)
dp[0] = 0

for i in range(n):
  dp[i+1] = min(dp[i+1], dp[i] + abs(a[i+1] - a[i]))
  dp[i+2] = min(dp[i+2], dp[i] + abs(a[i+2] - a[i]))

print(dp[n-1])

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

DP = [0] * N
DP[0] = 0
DP[1] = abs(H[1] - H[0])
##
for i in range(2, N):
    DP[i] = min( DP[i-1] + abs(H[i]-H[i-1]), DP[i-2] + abs(H[i]-H[i-2]) )
##
print(DP[N-1])
Buggy python submission (verdict: Time Limit Exceeded):
s = str(input())
t = str(input())

# pad a character to the first because i want to count index from 1
s = "." + s; t = "." + t;

a = len(s)
b = len(t)

dp = [['']*(b) for _ in range(a)]
# dp[i][j] is the length of lcs of s[0]s[1]...s[i] and t[0]t[1]...t[j]

for i in range(1, a):
    for j in range(1, b):
        if s[i] == t[j]:
            if len(dp[i][j]) < len(dp[i-1][j-1]) + 1:
                dp[i][j] = dp[i-1][j-1] + s[i]
        else:
            for adja in [[i-1, j-1], [i-1, j], [i, j-1]]:
                if len(dp[i][j]) < len(dp[adja[0]][adja[1]]):
                    dp[i][j] = dp[adja[0]][adja[1]]

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

Fixed submission:
s = str(input())
t = str(input())

# pad a character to the first because i want to count index from 1
s = "." + s; t = "." + t;

a = len(s)
b = len(t)

dp = [['']*(b) for _ in range(2)]
# dp[i][j] is the length of lcs of s[0]s[1]...s[i] and t[0]t[1]...t[j]

for i in range(1, a):
    for j in range(1, b):
        if s[i] == t[j]:
            if len(dp[i&1][j]) < len(dp[(i+1)&1][j-1]) + 1:
                dp[i&1][j] = dp[(i+1)&1][j-1] + s[i]
        else:
            for adja in [[i-1, j-1], [i-1, j], [i, j-1]]:
                if len(dp[i&1][j]) < len(dp[adja[0]&1][adja[1]]):
                    dp[i&1][j] = dp[adja[0]&1][adja[1]]

print(dp[(a+1)&1][b-1])

Buggy python submission (verdict: Time Limit Exceeded):
s = str(input())
t = str(input())

# pad a character to the first because i want to count index from 1
s = "." + s; t = "." + t;

a = len(s)
b = len(t)

dp = [[0]*(b) for _ in range(a)]
# dp[i][j] is the length of lcs of s[0]s[1]...s[i] and t[0]t[1]...t[j]
last = [[[0]*2 for i1 in range(b)] for i2 in range(a)]

for i in range(1, a):
    for j in range(1, b):
        if s[i] == t[j]:
            if dp[i][j] < dp[i-1][j-1] + 1:
                dp[i][j] = dp[i-1][j-1] + 1
                last[i][j] = [i, j]
        else:
            for adja in [[i-1, j-1], [i-1, j], [i, j-1]]:
                if dp[i][j] < dp[adja[0]][adja[1]]:
                    dp[i][j] = dp[adja[0]][adja[1]]
                    last[i][j] = last[adja[0]][adja[1]]


ans = ''
x, y = last[a-1][b-1]
while x > 0 and y > 0:
    ans += s[last[x][y][0]]
    x, y = last[x][y]
    x -= 1; y -= 1;

#print(*dp, sep = '\n')
print(ans[::-1])



Fixed submission:
s = str(input())
t = str(input())

# pad a character to the first because i want to count index from 1
s = "." + s; t = "." + t;

a = len(s)
b = len(t)

dp = [['']*(b) for _ in range(2)]
# dp[i][j] is the length of lcs of s[0]s[1]...s[i] and t[0]t[1]...t[j]

for i in range(1, a):
    for j in range(1, b):
        if s[i] == t[j]:
            if len(dp[i&1][j]) < len(dp[(i+1)&1][j-1]) + 1:
                dp[i&1][j] = dp[(i+1)&1][j-1] + s[i]
        else:
            for adja in [[i-1, j-1], [i-1, j], [i, j-1]]:
                if len(dp[i&1][j]) < len(dp[adja[0]&1][adja[1]]):
                    dp[i&1][j] = dp[adja[0]&1][adja[1]]

print(dp[(a+1)&1][b-1])
Buggy python submission (verdict: Runtime Error):
global N, M
global edgeList

global longestPathFrom

def dfs(x):
    if longestPathFrom[x] == -1:
        # get
        longest = -1
        for nextNode in edgeList[x]:
            longest = max(longest, dfs(nextNode))
        # set
        if longest == -1:
            longestPathFrom[x] = 0
        else:
            longestPathFrom[x] = longest + 1
    # -- longest path from x has been calculated
    return longestPathFrom[x]

# -- main
if __name__ == '__main__':
    # -- input
    N, M = map(int, input().split())
    edgeList = [[] for node in range(N)]

    for i in range(M):
        x, y = map(int, input().split())
        x -= 1; y -= 1;
        edgeList[x].append(y)

    # -- process
    longestPathFrom = [-1] * N

    for node in range(N):
        if longestPathFrom[node] == -1:
            dfs(node)

    # -- output
    print(max(longestPathFrom))

Fixed submission:
import sys

global N, M
global edgeList

global longestPathFrom

def dfs(x):
    if longestPathFrom[x] == -1:
        # get
        longest = -1
        for nextNode in edgeList[x]:
            longest = max(longest, dfs(nextNode))
        # set
        if longest == -1:
            longestPathFrom[x] = 0
        else:
            longestPathFrom[x] = longest + 1
    # -- longest path from x has been calculated
    return longestPathFrom[x]

# -- main
if __name__ == '__main__':
    # -- 
    sys.setrecursionlimit(1000001)

    # -- input
    N, M = map(int, input().split())
    edgeList = [[] for node in range(N)]

    for i in range(M):
        x, y = map(int, input().split())
        x -= 1; y -= 1;
        edgeList[x].append(y)

    # -- process
    longestPathFrom = [-1] * N

    for node in range(N):
        if longestPathFrom[node] == -1:
            dfs(node)

    # -- output
    print(max(longestPathFrom))
Buggy python submission (verdict: Time Limit Exceeded):
import math
def isPrime(n):
  if n<2:
    return False
  if n == 2:
    return True
  if n % 2 == 0:
    return False
  m = math.floor(math.sqrt(n))
  for p in range(3,n+1,2):
      if n % p == 0:
        return False
      if p > m:
        # 素数がnの平方根を超えたら終了
        break
  return True
N=int(input())
if isPrime(N):
    print(1)
else:
    n=N
    count=0
    s=0
    S=0
    for i in range(2,N+1):
        if n<i:
            break
        s=1
        count=0
        while 1:
            if n%i!=0:
                break
            count+=1
            n=int(n/i)
        while 1:
            if count<int(s*(s+1)/2):
                S+=s-1
                break
            s+=1
    print(S)
            









Fixed submission:
import math
def isPrime(n):
  if n<2:
    return False
  if n == 2:
    return True
  if n % 2 == 0:
    return False
  m = math.floor(math.sqrt(n))
  for p in range(3,n+1,2):
      if n % p == 0:
        return False
      if p > m:
        # 素数がnの平方根を超えたら終了
        break
  return True
N=int(input())
if isPrime(N):
    print(1)
else:
    n=N
    count=0
    s=0
    S=0
    for i in range(2,N+1):
        if n<i:
            break
        s=1
        count=0
        while 1:
            if n%i!=0:
                break
            count+=1
            n=int(n/i)
        while 1:
            if count<int(s*(s+1)/2):
                S+=s-1
                break
            s+=1
        if i==10000:
            if isPrime(n):
                S+=1
                break
    print(S)

Buggy python submission (verdict: Time Limit Exceeded):
import math
def isPrime(n):
  if n<2:
    return False
  if n == 2:
    return True
  if n % 2 == 0:
    return False
  m = math.floor(math.sqrt(n))
  for p in range(3,n+1,2):
      if n % p == 0:
        return False
      if p > m:
        # 素数がnの平方根を超えたら終了
        break
  return True
N=int(input())
if isPrime(N):
    print(1)
else:
    n=N
    count=0
    s=0
    S=0
    for i in range(2,N+1):
        if n<i:
            break
        s=0
        count=0
        while 1:
            if n%i!=0:
                break
            count+=1
            n=int(n/i)
        while 1:
            if count<int(s*(s+1)/2):
                S+=s-1
                break
            s+=1
    print(S)
            









Fixed submission:
import math
def isPrime(n):
  if n<2:
    return False
  if n == 2:
    return True
  if n % 2 == 0:
    return False
  m = math.floor(math.sqrt(n))
  for p in range(3,n+1,2):
      if n % p == 0:
        return False
      if p > m:
        # 素数がnの平方根を超えたら終了
        break
  return True
N=int(input())
if isPrime(N):
    print(1)
else:
    n=N
    count=0
    s=0
    S=0
    for i in range(2,N+1):
        if n<i:
            break
        s=1
        count=0
        while 1:
            if n%i!=0:
                break
            count+=1
            n=int(n/i)
        while 1:
            if count<int(s*(s+1)/2):
                S+=s-1
                break
            s+=1
        if i==10000:
            if isPrime(n):
                S+=1
                break
    print(S)
Buggy python submission (verdict: Runtime Error):
import numpy as np
x=int(input())
v=0
count=1
while v==0:
    if x<=2*(count)**5:
        v=1
    else:
        count+=1
for i in range(-1*count,count):
    if i**5+x<0:
        m=np.power(-1*(i**5+x),0.2)
        m=-1*m
    else:
        m=np.power(i**5+x,0.2)
    M=int(m)
    if m-M<=10**(-5):
        b=i
        a=M
        break
print(a,b)


Fixed submission:
import math
X=int(input())
x=1
while 1:
    if X<2*pow(x,5):
        break
    x+=1
while 1:
    M=pow(x,5)-X
    if M<0:
        M=-1*M
        if pow(M,0.2)-int(pow(M,0.2))<=pow(10,-6):
            print(x,-1*(int(pow(M,0.2))))
            break
    else:
        if pow(M,0.2)-int(pow(M,0.2))<=pow(10,-6):
            print(x,int(pow(M,0.2)))
            break
    x+=1

Buggy python submission (verdict: Runtime Error):
import numpy as np
x=int(input())
v=0
count=1
while v==0:
    if x<=2*(count)**5:
        v=1
    else:
        count+=1
for i in range(-1*count,count):
    if i**5+x<0:
        m=np.power(-1*(i**5+x),0.2)
        m=-1*m
    else:
        m=np.power(i**5+x,0.2)
    M=int(m)
    if m-M<=10**(-5):
        b=i
        a=M
        break
print(a,b)


Fixed submission:
import math
X=int(input())
x=1
while 1:
    if X<2*pow(x,5):
        break
    x+=1
while 1:
    M=pow(x,5)-X
    if M<0:
        M=-1*M
        if pow(M,0.2)-int(pow(M,0.2))<=pow(10,-6):
            print(x,-1*(int(pow(M,0.2))))
            break
    else:
        if pow(M,0.2)-int(pow(M,0.2))<=pow(10,-6):
            print(x,int(pow(M,0.2)))
            break
    x+=1
Buggy python submission (verdict: Runtime Error):
L=list(map(int,input().split()))
A=L[0]
B=L[1]
N=L[2]
if N>=B-1:
    print(int(A*(B-1)/B))
else:
    print(int(A*N/B))

Fixed submission:
L=list(map(int,input().split()))
A=L[0]
B=L[1]
N=L[2]
if N>=B-1:
    print(int(A*(B-1)/B))
else:
    print(int(A*N/B))
Buggy python submission (verdict: Runtime Error):
import math
H=int(input())
n=int(math.log2(H))+1
x=n
for i in range(n-1):
    x+=2**(i)*(n-i-1)
print(x)


Fixed submission:
import math
H = int(input())
N = int(math.log2(H))
x = int((2**(N+1)-1))
print(x)
Buggy python submission (verdict: Time Limit Exceeded):
def power(a,n):
    x=1
    L=list(format(n,'b'))
    l=len(L)
    for i in range(l):
        if int(L[l-i-1])==1:        
            x=(x*a)%(10**9+7)
        a=(a*a)%(10**9+7)
    return x
N,K=map(int,input().split())
A=list(map(int,input().split()))
b=sorted(A)
c=sorted(A,reverse=True)
D=[]
M=0
for i in range(N-K+1):
    x=1
    y=1
    for l in range(K-1):
        x=(x*(N-i-1-l))%(10**9+7)
        y=(y*(l+1))%(10**9+7)
    y=power(y,10**9+5)
    m=(x*y*(c[i]-b[i]))
    if m>0:
        m=m%(10**9+7)
    M+=m
    M%(10**9+7)

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







Fixed submission:
def power(a,n):
    x=1
    L=list(format(n,'b'))
    l=len(L)
    for i in range(l):
        if int(L[l-i-1])==1:        
            x=(x*a)%(10**9+7)
        a=(a*a)%(10**9+7)
    return x
N,K=map(int,input().split())
A=list(map(int,input().split()))
b=sorted(A)
c=sorted(A,reverse=True)
D=[]
M=0
x=1
y=1
for l in range(K-1):
    x=(x*(N-l-1))%(10**9+7)
    y=(y*(l+1))%(10**9+7)
y=power(y,10**9+5)
M+=(x*y*(c[0]-b[0]))%(10**9+7)
for i in range(1,N-K+1):
    y1=power(N-i,10**9+5)
    x=(x*y1)%(10**9+7)
    x=(x*(N-K-i+1))%(10**9+7)  
    m=(x*y*(c[i]-b[i]))
    if m>0:
        m=m%(10**9+7)
    M+=m
    M%(10**9+7)

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

Buggy python submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-
"""
Created on Mon Jan 13 14:52:12 2020

@author: USER
"""
import math
l=list(map(int,input().split()))
N=l[0]
K=l[1]
A=list(map(int,input().split()))
X=0
A=sorted(A)
for i in range(len(A)-K+1):
    for j in range(i+K-1,len(A)):
        X=X+(A[j]-A[i])*math.factorial(j-i-1)/(math.factorial(K-2)*math.factorial(j-i-1-K+2))
        X=X%(10**9+7)
        
print(int(X))
    

Fixed submission:
def power(a,n):
    x=1
    L=list(format(n,'b'))
    l=len(L)
    for i in range(l):
        if int(L[l-i-1])==1:        
            x=(x*a)%(10**9+7)
        a=(a*a)%(10**9+7)
    return x
N,K=map(int,input().split())
A=list(map(int,input().split()))
b=sorted(A)
c=sorted(A,reverse=True)
D=[]
M=0
x=1
y=1
for l in range(K-1):
    x=(x*(N-l-1))%(10**9+7)
    y=(y*(l+1))%(10**9+7)
y=power(y,10**9+5)
M+=(x*y*(c[0]-b[0]))%(10**9+7)
for i in range(1,N-K+1):
    y1=power(N-i,10**9+5)
    x=(x*y1)%(10**9+7)
    x=(x*(N-K-i+1))%(10**9+7)  
    m=(x*y*(c[i]-b[i]))
    if m>0:
        m=m%(10**9+7)
    M+=m
    M%(10**9+7)

print(M%(10**9+7))
Buggy python submission (verdict: Time Limit Exceeded):
S=list(input())
N=len(S)
s=reversed(S)
X=[0]*N
for i in range(N):
    m=1
    if S[i]=="R":
        while 1:
            if S[i]!=S[i+m]:
                break
            m+=1
        if m%2==0:
            X[i+m]+=1
        else:
            X[i+m-1]+=1
    else:
        while 1:
            if S[i]!=S[i-m]:
                break
            m+=1
        if m%2==0:
            X[i-m]+=1
        else:
            X[i-m+1]+=1
for i in range(N):
    print(X[i])
        
        


Fixed submission:
S=list(input())
N=len(S)
s=reversed(S)
X=[0]*N
for i in range(N):
    m=1
    if i>0 and S[i]=="R" and S[i]==S[i-1]:
        m=k-1
        if m%2==0:
            X[i+m]+=1
        else:
            X[i+m-1]+=1
    else:

        if S[i]=="R":
            while 1:
                if S[i]!=S[i+m]:
                    break
                m+=1
            if m%2==0:
                X[i+m]+=1
            else:
                X[i+m-1]+=1
    if i>0 and S[i]=="L" and S[i]==S[i-1]:
        m=k+1
        if m%2==0:
            X[i-m]+=1
        else:
            X[i-m+1]+=1
    else:
        if S[i]=="L":
            while 1:
                if S[i]!=S[i-m]:
                    break
                m+=1
            if m%2==0:
                X[i-m]+=1
            else:
                X[i-m+1]+=1
    k=m
for i in range(N):
    print(X[i])
Buggy python submission (verdict: Time Limit Exceeded):
L=list(map(int,input()))
n=len(L)
X=pow(3,n-1)%(10**9+7)
count=1
for i in range(1,n):
    if L[i]==1:
        k=n-i-1
        count+=1
        X+=(pow(3,k)%(10**9+7))*(pow(2,count-1)%(10**9+7))
X+=pow(2,count)%(10**9+7)
print(X%(10**9+7))


Fixed submission:
L=list(map(int,input()))
n=len(L)
def power(a,n):
    x=1
    L=list(format(n,'b'))
    l=len(L)
    for i in range(l):
        if int(L[l-i-1])==1:        
            x=(x*a)%(10**9+7)
        a=(a*a)%(10**9+7)
    return x
X=power(3,n-1)%(10**9+7)
count=1
for i in range(1,n):
    if L[i]==1:
        k=n-i-1
        count+=1
        X+=(power(3,k)%(10**9+7))*(power(2,count-1)%(10**9+7))
X+=power(2,count)%(10**9+7)
print(X%(10**9+7))

Buggy python submission (verdict: Time Limit Exceeded):
L=list(map(int,input()))
n=len(L)
X=pow(3,n-1)%(10**9+7)
count=1
for i in range(1,n):
    if L[i]==1:
        k=n-i-1
        count+=1
        X+=(pow(3,k)*pow(2,count-1))%(10**9+7)
X+=pow(2,count)%(10**9+7)
print(X%(10**9+7))


Fixed submission:
L=list(map(int,input()))
n=len(L)
def power(a,n):
    x=1
    L=list(format(n,'b'))
    l=len(L)
    for i in range(l):
        if int(L[l-i-1])==1:        
            x=(x*a)%(10**9+7)
        a=(a*a)%(10**9+7)
    return x
X=power(3,n-1)%(10**9+7)
count=1
for i in range(1,n):
    if L[i]==1:
        k=n-i-1
        count+=1
        X+=(power(3,k)%(10**9+7))*(power(2,count-1)%(10**9+7))
X+=power(2,count)%(10**9+7)
print(X%(10**9+7))

Buggy python submission (verdict: Time Limit Exceeded):
L=list(map(int,input()))
n=len(L)
X=pow(3,n-1)
count=1
for i in range(1,n):
    if L[i]==1:
        k=n-i-1
        count+=1
        X+=pow(3,k)*pow(2,count-1)
X+=pow(2,count)
print(X%(10**9+7))


Fixed submission:
L=list(map(int,input()))
n=len(L)
def power(a,n):
    x=1
    L=list(format(n,'b'))
    l=len(L)
    for i in range(l):
        if int(L[l-i-1])==1:        
            x=(x*a)%(10**9+7)
        a=(a*a)%(10**9+7)
    return x
X=power(3,n-1)%(10**9+7)
count=1
for i in range(1,n):
    if L[i]==1:
        k=n-i-1
        count+=1
        X+=(power(3,k)%(10**9+7))*(power(2,count-1)%(10**9+7))
X+=power(2,count)%(10**9+7)
print(X%(10**9+7))
Buggy python submission (verdict: Time Limit Exceeded):
n = list(map(int, input().split()))
N = n[0]
M = n[1]
X = []
Y = []
for i in range(M):
    a = list(map(int, input().split()))
    X.append(a[0])
    Y.append(a[1])
v=0
w=0
z=[X[0],Y[0]]
while v==0:
    for i in range(1,M):
        if z[0]<=Y[i] and z[1]>=X[i]:
            z[0]=max(z[0],X[i])
            z[1]=min(z[1],Y[i])
        else:
            v=1
            w=1
        if i==M-1:
            v=1
if w==0:
    print(z[1]-z[0]+1)
else:
    print(0)





Fixed submission:
n = list(map(int, input().split()))
N = n[0]
M = n[1]
X = []
Y = []
for i in range(M):
    a = list(map(int, input().split()))
    X.append(a[0])
    Y.append(a[1])
v=0
w=0
x=max(X)
y=min(Y)
if y>=x:
    print(y-x+1)
else:
    print(0)
Buggy python submission (verdict: Runtime Error):
import union_find as uf
N,M=map(int,input().split())
uni=uf.UnionFind(N)
L=[]
for i in range(M):
    l=list(map(int,input().split()))
    L.append(l)
for i in range(M):
    uni.Unite(L[i][0],L[i][1])
x=-1
for i in range(N+1):
    if uni.root[i]<0:
        x+=1
print(x)


    



Fixed submission:
class UnionFind():
    # 作りたい要素数nで初期化
    # 使用するインスタンス変数の初期化
    def __init__(self, n):
        self.n = n
        # root[x]<0ならそのノードが根かつその値が木の要素数
        # rootノードでその木の要素数を記録する
        self.root = [-1]*(n+1)
        # 木をくっつける時にアンバランスにならないように調整する
        self.rnk = [0]*(n+1)

    # ノードxのrootノードを見つける
    def Find_Root(self, x):
        if(self.root[x] < 0):
            return x
        else:
            # ここで代入しておくことで、後の繰り返しを避ける
            self.root[x] = self.Find_Root(self.root[x])
            return self.root[x]
    # 木の併合、入力は併合したい各ノード
    def Unite(self, x, y):
        # 入力ノードのrootノードを見つける
        x = self.Find_Root(x)
        y = self.Find_Root(y)
        # すでに同じ木に属していた場合
        if(x == y):
            return 
        # 違う木に属していた場合rnkを見てくっつける方を決める
        elif(self.rnk[x] > self.rnk[y]):
            self.root[x] += self.root[y]
            self.root[y] = x

        else:
            self.root[y] += self.root[x]
            self.root[x] = y
            # rnkが同じ（深さに差がない場合）は1増やす
            if(self.rnk[x] == self.rnk[y]):
                self.rnk[y] += 1
    # xとyが同じグループに属するか判断
    def isSameGroup(self, x, y):
        return self.Find_Root(x) == self.Find_Root(y)

    # ノードxが属する木のサイズを返す
    def Count(self, x):
        return -self.root[self.Find_Root(x)]

N,M=map(int,input().split())
uni=UnionFind(N)
L=[]
for i in range(M):
    l=list(map(int,input().split()))
    L.append(l)
for i in range(M):
    uni.Unite(L[i][0],L[i][1])
x=-1
for i in range(N+1):
    if uni.root[i]<0:
        x+=1
print(x)
Buggy python submission (verdict: Runtime Error):
x, k, d = map(int, input().split())

lo = 0
hi = k

while (lo < hi) :
  mid = lo + (hi - lo) // 2 + 1
  if (x >= 0) :
    if (x - mid * d >= 0) : 
      lo = mid;
    else :
      hi = mid - 1
  else :
    if (x + mid * d <= 0) :
      lo = mid;
    else :
      hi = mid - 1;

if (x >= 0) x -= d * hi;
else x += d * hi;

k -= hi;

if ( (k % 2) == 0):
  if (k == 0) :
    print(abs(x))
  else :
    print(min(abs(x), abs(x - d - d), abs(x + d + d)));
else :
  if (k == 1) :
    print(min(abs(x - d), abs(x + d)))
  else :
    print(min(abs(x - d), abs(x + d), abs(x + d + d + d), abs(x - d - d - d)));


Fixed submission:
x, k, d = map(int, input().split())

lo = 0
hi = k

while (lo < hi) :
  mid = lo + (hi - lo) // 2 + 1
  if (x >= 0) :
    if (x - mid * d >= 0) : 
      lo = mid;
    else :
      hi = mid - 1
  else :
    if (x + mid * d <= 0) :
      lo = mid;
    else :
      hi = mid - 1;

if (x >= 0) :
  x -= d * hi
else :
  x += d * hi

k -= hi;

if ( (k % 2) == 0):
  if (k == 0) :
    print(abs(x))
  else :
    print(min(abs(x), abs(x - d - d), abs(x + d + d)));
else :
  if (k == 1) :
    print(min(abs(x - d), abs(x + d)))
  else :
    print(min(abs(x - d), abs(x + d), abs(x + d + d + d), abs(x - d - d - d)));

Buggy python submission (verdict: Runtime Error):
x, k, d = map(int, input().split())

lo = 0
hi = k

while (lo < hi) :
  mid = lo + (hi - lo) // 2 + 1
  if (x >= 0) :
    if (x - mid * d >= 0) : 
      lo = mid;
    else :
      hi = mid - 1
  else :
    if (x + mid * d <= 0) :
      lo = mid;
    else :
      hi = mid - 1;

x -= d * hi;
x = abs(x);
k -= hi;


if ( (k % 2) == 0):
  if (k == 0) :
    print(abs(x))
  else :
    print(min(abs(x), abs(x - d - d), abs(x + d + d));
else :
  print(min(abs(x - d), abs(x + d)))


Fixed submission:
x, k, d = map(int, input().split())

lo = 0
hi = k

while (lo < hi) :
  mid = lo + (hi - lo) // 2 + 1
  if (x >= 0) :
    if (x - mid * d >= 0) : 
      lo = mid;
    else :
      hi = mid - 1
  else :
    if (x + mid * d <= 0) :
      lo = mid;
    else :
      hi = mid - 1;

if (x >= 0) :
  x -= d * hi
else :
  x += d * hi

k -= hi;

if ( (k % 2) == 0):
  if (k == 0) :
    print(abs(x))
  else :
    print(min(abs(x), abs(x - d - d), abs(x + d + d)));
else :
  if (k == 1) :
    print(min(abs(x - d), abs(x + d)))
  else :
    print(min(abs(x - d), abs(x + d), abs(x + d + d + d), abs(x - d - d - d)));
Buggy python submission (verdict: Time Limit Exceeded):
S = input()
ansl = [0]*2019
for i in range(len(S)):
    ansl[int(S[-i-1:])%2019]+=1
ans = (ansl[0]+1)*ansl[0]/2
for i in range(1, 2019):
    ans+=ansl[i]*(ansl[i]-1)/2

print(int(ans))

Fixed submission:
def power_func(a, b, p):
    if b == 0:
        return 1
    if b % 2 == 0:
        d = power_func(a, b // 2, p)
        return d * d % p
    if b % 2 == 1:
        return (a * power_func(a, b - 1, p)) % p

S = input()
ansl = [0]*2019
temp = 0
for i in range(len(S)):
    temp = (temp+int(S[-i-1])*power_func(10,i,2019))%2019
    ansl[temp]+=1
ans = (ansl[0]+1)*ansl[0]/2

for i in range(1, 2019):
    ans+=ansl[i]*(ansl[i]-1)/2

print(int(ans))
Buggy python submission (verdict: Runtime Error):
R = float(input())

print(2*R*math.pi)

Fixed submission:
import math

R = float(input())

print(2*R*math.pi)
Buggy python submission (verdict: Runtime Error):
X, Y, A, B, C = input().split()
P = list(map(int,input().split()))
Q = list(map(int,input().split()))
R = list(map(int,input().split()))
P.sort(reverse=True)
Q.sort(reverse=True)
R.sort(reverse=True)

ANS_list = P[:X]
ANS_list.extend(Q[:Y])
ANS_list.sort()
c = 0
for i in range(len(R)):
    if ANS_list[i] >= R[i]:
        break
    c+=1

if i!=0:
    ANS_list[:c] = R[:c]

print(sum(R[:c])+sum(ANS_list[c:]))

Fixed submission:
X, Y, A, B, C = map(int,input().split())
P = list(map(int,input().split()))
Q = list(map(int,input().split()))
R = list(map(int,input().split()))
P.sort(reverse=True)
Q.sort(reverse=True)
R.sort(reverse=True)

ANS_list = P[:X]
ANS_list.extend(Q[:Y])
ANS_list.sort()
c = 0
for i in range(len(R)):
  if ANS_list[i] >= R[i]:
    break
  c+=1

if i!=0:
  ANS_list[:c] = R[:c]
print(sum(R[:c])+sum(ANS_list[c:]))
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = list(map(int,input().split()))
import collections
c = collections.Counter(A)

for i in A:
    temp = c.copy()
    temp[i] = temp[i]-1
    counter = 0
    for j in c.keys():
        n = temp[j]
        if n >= 2:
            counter += n*(n-1)/2
    print(int(counter))

Fixed submission:
N = int(input())
A = list(map(int,input().split()))
import collections
c = collections.Counter(A)
counter = 0
for j in c.keys():
    if c[j]>=2:
        counter+=c[j]*(c[j]-1)/2



for i in A:
    print(int(counter-c[i]+1))