Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
n,k,x,y=int(input()) for i in range(4)
if n - k > 0:
  ans = k * x + (n - k) * y
else:
  ans = n * x
print(ans)


Fixed submission:
n,k,x,y=(int(input()) for i in range(4))
if n - k > 0:
  ans = k * x + (n - k) * y
else:
  ans = n * x
print(ans)

Buggy python submission (verdict: Runtime Error):
n,k,x,y=(int(input().split()) for i in range(4))
j = 0
if n > k:
   j = (n - k)  * y
print(k * x + j)

Fixed submission:
n,k,x,y=(int(input()) for i in range(4))
if n - k > 0:
  ans = k * x + (n - k) * y
else:
  ans = n * x
print(ans)

Buggy python submission (verdict: Runtime Error):
N, K, X, Y = (int(input().split()) for _ in range(4))
t = 0
if N >= K:
    print(X*K + Y*(N-K))
else:
    print(X*N)

Fixed submission:
n,k,x,y=(int(input()) for i in range(4))
if n - k > 0:
  ans = k * x + (n - k) * y
else:
  ans = n * x
print(ans)

Buggy python submission (verdict: Runtime Error):
n, k, x, y = (int(input().split()) for _ in range(4))
t = 0
if n - k > 0:
  t = (n  - k) * y
print(n * x + t)

Fixed submission:
n,k,x,y=(int(input()) for i in range(4))
if n - k > 0:
  ans = k * x + (n - k) * y
else:
  ans = n * x
print(ans)

Buggy python submission (verdict: Runtime Error):
n, k, x, y = int(input().split()) for _ in range(4)
t = 0
if n - k > 0:
  t = (n  - k) * y
print(n * x + t)

Fixed submission:
n,k,x,y=(int(input()) for i in range(4))
if n - k > 0:
  ans = k * x + (n - k) * y
else:
  ans = n * x
print(ans)

Buggy python submission (verdict: Runtime Error):
n, k, x, y = int(input().split()) for _ in range(4)
t = 0
if n - k > 0:
  t = (n  - k) * y
print(n * x + t)

Fixed submission:
n,k,x,y=(int(input()) for i in range(4))
if n - k > 0:
  ans = k * x + (n - k) * y
else:
  ans = n * x
print(ans)

Buggy python submission (verdict: Runtime Error):
n, k, x, y = int(input().split()) for _ in range(4)
t = 0
if n - k > 0:
  t = (n  - k) * y
print(k * x + t)

Fixed submission:
n,k,x,y=(int(input()) for i in range(4))
if n - k > 0:
  ans = k * x + (n - k) * y
else:
  ans = n * x
print(ans)

Buggy python submission (verdict: Runtime Error):
n, k, x, y = int(input().split()) for _ in range(4)
print(k * x + (k - n) * y)

Fixed submission:
n,k,x,y=(int(input()) for i in range(4))
if n - k > 0:
  ans = k * x + (n - k) * y
else:
  ans = n * x
print(ans)

Buggy python submission (verdict: Runtime Error):
n, k, x, y = [int(input().split()) for _ in range(4)]
print(k * x + (n - k) * y)

Fixed submission:
n,k,x,y=(int(input()) for i in range(4))
if n - k > 0:
  ans = k * x + (n - k) * y
else:
  ans = n * x
print(ans)

Buggy python submission (verdict: Runtime Error):
n, k, x, y = int(input().split()) for _ in range(4)
print(k * x + (n - k) * y)

Fixed submission:
n,k,x,y=(int(input()) for i in range(4))
if n - k > 0:
  ans = k * x + (n - k) * y
else:
  ans = n * x
print(ans)

Buggy python submission (verdict: Runtime Error):
n, k, x, y = int(input.split()) for _ in range(4)
print(k * x + (n - k) * y)

Fixed submission:
n,k,x,y=(int(input()) for i in range(4))
if n - k > 0:
  ans = k * x + (n - k) * y
else:
  ans = n * x
print(ans)
Buggy python submission (verdict: Runtime Error):
count = 0
for i range(int(input()) + 1):
  if i == 0:
    continue
  count += i
print(count)


Fixed submission:
count = 0
for i in range(int(input()) + 1):
  if i == 0:
    continue
  count += i
print(count)
Buggy python submission (verdict: Runtime Error):
List=[int(i) for i in input().split()]
if List.count(5) == 2 and List.cout(7) == 1:
  print("YES")
else:
  print("NO")

Fixed submission:
List=[int(i) for i in input().split()]
if List.count(5) == 2 and List.count(7) == 1:
  print("YES")
else:
  print("NO")

Buggy python submission (verdict: Runtime Error):
List=[int(i) for i in input().split()]
if List.count(5) == 2 and List.cout(7) == 1:
  print("YES")
else:
  print("NO")

Fixed submission:
List=[int(i) for i in input().split()]
if List.count(5) == 2 and List.count(7) == 1:
  print("YES")
else:
  print("NO")
Buggy python submission (verdict: Time Limit Exceeded):
N, A, B = map(int, input().split())
ans = 0
while N > 0:
    if N >= A:
        ans += A
        N -= A
    else:
        ans += N
        break
        
    if N >= B:
        N -= B
    else:
        break
        
print(ans)

Fixed submission:
N, A, B = map(int, input().split())
ans1 = A * (N // (A+B)) 
ans2 = min((N % (A+B)), A)
print(ans1 + ans2)

Buggy python submission (verdict: Time Limit Exceeded):
N, A, B = map(int, input().split())
ans = 0
while N > 0 :
    for b in range(A) :
        ans += 1
        N -= 1
        if N == 0 :
            break
    for r in range(B):
        N -= 1
        if N == 0 :
            break
print(ans)

Fixed submission:
N, A, B = map(int, input().split())
ans1 = A * (N // (A+B)) 
ans2 = min((N % (A+B)), A)
print(ans1 + ans2)
Buggy python submission (verdict: Runtime Error):
S = input()
lis = list(S)
lis_rev = list(S)
lis_rev.reverse()
cnt = 0

lgh = 

for i in range(len(lis) // 2):
    if lis[i] != lis_rev[i]:
        cnt += 1
print(cnt)

Fixed submission:
S = input()
lis = list(S)
lis_rev = list(S)
lis_rev.reverse()
cnt = 0

for i in range(len(lis) // 2):
    if lis[i] != lis_rev[i]:
        cnt += 1
print(cnt)
Buggy python submission (verdict: Runtime Error):
S = input()

week = {
  "MON": 1,
  "TUE": 2,
  "WED": 3,
  "THU": 4,
  "FRI": 5,
  "SAT": 6
}

if __name__ == "main":
  if S == "SUN":
    return 7
  else:
    return 7 - week[S]

Fixed submission:


S = input()


week = {
  "MON": 1,
  "TUE": 2,
  "WED": 3,
  "THU": 4,
  "FRI": 5,
  "SAT": 6
}

if S == "SUN":
  print(7)
else:
  print(7 - week[S])
Buggy python submission (verdict: Runtime Error):
import sys

def main():
    input = sys.stdin.readline
    n = int(input())
    s = input().rsplit()
    first = ord("A") - 1
    last = ord("Z")
    increment = lambda x: chr(ord(x)+n) if ord(x)+n <= last else chr(first + (ord(x)+n - last))
    new_s = "".join(map(increment, s))
    print(new_s, end="")
    


if __name__ == '__main__':
    main()


Fixed submission:
import sys

def main():
    input = sys.stdin.readline
    n = int(input())
    s = input().rstrip()
    first = ord("A") - 1
    last = ord("Z")
    increment = lambda x: chr(ord(x)+n) if ord(x)+n <= last else chr(first + (ord(x)+n - last))
    new_s = "".join(map(increment, s))
    print(new_s, end="")
    


if __name__ == '__main__':
    main()
Buggy python submission (verdict: Runtime Error):
N = int(input())

return N^3

Fixed submission:
N = int(input())

print(N**3)

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

return N^3

Fixed submission:
N = int(input())

print(N**3)
Buggy python submission (verdict: Time Limit Exceeded):
import sys


def main():
    input = sys.stdin.readline
    n, q = map(int, input().split())
    s = input()
    li = [map(int, input().split()) for i in range(q)]

    for i, j in li:
        count = 0
        for k in range(i-1, j-1):
            if s[k:k+2] == "AC":
                count += 1
        print(count)


if __name__ == '__main__':
    main()


Fixed submission:
import sys


def main():
    input = sys.stdin.readline
    n, q = map(int, input().split())
    s = input()
    li = [map(int, input().split()) for i in range(q)]
    count = [0]*len(s)

    for i in range(1, len(s)):
        if s[i] == "C" and s[i-1] == "A":
            count[i] = count[i-1] + 1
        else:
            count[i] = count[i-1]
   
    for i, j in li:
        print(count[j-1] - count[i-1])


if __name__ == '__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
import sys


def main():
    input = sys.stdin.readline
    n, q = map(int, input().split())
    s = input()
    li = [map(int, input().split()) for i in range(q)]

    for i, j in li:
        count = 0
        cache = s[i-1]
        for k in range(i, j):
            if cache == "A" and s[k] == "C":
                count += 1
            cache = s[k]
        print(count)


if __name__ == '__main__':
    main()


Fixed submission:
import sys


def main():
    input = sys.stdin.readline
    n, q = map(int, input().split())
    s = input()
    li = [map(int, input().split()) for i in range(q)]
    count = [0]*len(s)

    for i in range(1, len(s)):
        if s[i] == "C" and s[i-1] == "A":
            count[i] = count[i-1] + 1
        else:
            count[i] = count[i-1]
   
    for i, j in li:
        print(count[j-1] - count[i-1])


if __name__ == '__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
import sys


def main():
    input = sys.stdin.readline
    n, q = map(int, input().split())
    s = input()
    li = [list(map(int, input().split())) for i in range(q)]

    for i, j in li:
        count = 0
        cache = s[i-1]
        for k in range(i, j):
            if cache == "A" and s[k] == "C":
                count += 1
            cache = s[k]
        print(count)



if __name__ == '__main__':
    main()


Fixed submission:
import sys


def main():
    input = sys.stdin.readline
    n, q = map(int, input().split())
    s = input()
    li = [map(int, input().split()) for i in range(q)]
    count = [0]*len(s)

    for i in range(1, len(s)):
        if s[i] == "C" and s[i-1] == "A":
            count[i] = count[i-1] + 1
        else:
            count[i] = count[i-1]
   
    for i, j in li:
        print(count[j-1] - count[i-1])


if __name__ == '__main__':
    main()
Buggy python submission (verdict: Runtime Error):
import numpy as np 

n, k = map(int, input().split())
h = list(map(int, input().split()))

ans = np.zeros(n)

for i in range(1, n):
    j = 0 if i-k<0 else i-k
    min_cost = float('inf')
    for l in range(j, i):
        min_cost = min(min_cost, (abs(h[i] - h[l]) + ans[l]))
    
    ans[i] = min_cost

print(int(ans[-1]))

Fixed submission:

n, k = map(int, input().split())
h = list(map(int, input().split()))

ans = [0]

for i in range(1, n):
    j = 0 if i-k<0 else i-k
    min_cost = float('inf')
    for l in range(j, i):
        min_cost = min(min_cost, (abs(h[i] - h[l]) + ans[l]))
    
    ans.append(min_cost)

print(int(ans[-1]))

Buggy python submission (verdict: Runtime Error):
import numpy as np 

n, k = map(int, input().split())
h = list(map(int, input().split()))

ans = np.zeros(n)

for i in range(1, n):
    j = 0 if i-k<0 else i-k
    min_cost = float('inf')
    for l in range(j, i):
        min_cost = min(min_cost, (abs(h[i] - h[l]) + ans[l]))
    
    ans[i] = min_cost

print(int(ans[-1]))

Fixed submission:

n, k = map(int, input().split())
h = list(map(int, input().split()))

ans = [0]

for i in range(1, n):
    j = 0 if i-k<0 else i-k
    min_cost = float('inf')
    for l in range(j, i):
        min_cost = min(min_cost, (abs(h[i] - h[l]) + ans[l]))
    
    ans.append(min_cost)

print(int(ans[-1]))

Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np 

n, k = map(int, input().split())
h = list(map(int, input().split()))

ans = np.zeros(n)

for i in range(1, n):
    j = 0 if i-k<0 else i-k
    min_cost = float('inf')
    for l in range(j, i):
        min_cost = min(min_cost, (abs(h[i] - h[l]) + ans[l]))
    
    ans[i] = min_cost

print(int(ans[-1]))

Fixed submission:

n, k = map(int, input().split())
h = list(map(int, input().split()))

ans = [0]

for i in range(1, n):
    j = 0 if i-k<0 else i-k
    min_cost = float('inf')
    for l in range(j, i):
        min_cost = min(min_cost, (abs(h[i] - h[l]) + ans[l]))
    
    ans.append(min_cost)

print(int(ans[-1]))
Buggy python submission (verdict: Runtime Error):
def compute_fact(n):
    global f
    f = [0 for i in range(n+1)]
    f[0] = 1
    f[1] = 1
    for i in range(2,n+1):
        f[i] = f[i-1]*i

def compute_c(n,r):
    compute_fact(n)
    ans = f[n]/(f[r] * f[n-r])
    return ans

n,m = [int(s) for s in input().split()]
print(int(compute_c(n,2) + compute_c(m,2)))



Fixed submission:
def compute_fact(n):
    global f
    if(n < 2):
        f = [1,1]
    else:
        f = [0 for i in range(n+1)]
        f[0] = 1
        f[1] = 1
        for i in range(2,n+1):
            f[i] = f[i-1]*i

def compute_c(n,r):
    compute_fact(n)
    ans = f[n]/(f[r] * f[n-r])
    return ans

n,m = [int(s) for s in input().split()]
if n >= 2 and m >= 2:
    print(int(compute_c(n,2) + compute_c(m,2)))
elif n >= 2:
    print(int(compute_c(n,2)))
elif m >= 2:
    print(int(compute_c(m,2)))
else:
    print(0)

Buggy python submission (verdict: Runtime Error):
s=input()
s = int(s)
t=input()
t = int(t)
print(s*(s-1) /2 + t*(t-1)/2)

Fixed submission:
s,t=(int(x) for x in input().split())
print(int(s*(s-1) /2 + t*(t-1)/2))
Buggy python submission (verdict: Runtime Error):
x = int(input())
y = int(input())
if x > 9:
    print(-1)

elif y > 9:
    print(-1)

else:
    print(x*y)


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

if x > 9:
    print(-1)

elif y > 9:
    print(-1)

else:
    print(x*y)
Buggy python submission (verdict: Runtime Error):
a, b =raw_input().split(" ")

if a == b:
print "="
elif a < b
print "<"
elif a > b
print ">"

Fixed submission:
a, b =input().split(" ")
 
if a == b:
    print("=")
elif a < b:
    print("<")
elif a > b:
    print(">")
Buggy python submission (verdict: Time Limit Exceeded):
N,K = map(int,input().split())
L=list(map(int,input().split()))
A=[0]*N

s=0

for i in range(N):
    t=(L[i]+1)*L[i]/2*(1/L[i])
    A[i]=t

for i in range(N-K+1):
    #print(A[i:i+K])
    s=max(s,sum(A[i:i+K]))

print(s)    


Fixed submission:
N,K = map(int,input().split())
L=list(map(int,input().split()))
A=[0]*N


for i in range(N):
    t=(L[i]+1)*L[i]/2*(1/L[i])
    A[i]=t
s=0
t=sum(A[:K])
s=max(s,t)
for i in range(N-K):
    t+=(A[i+K]-A[i])
    s=max(s,t)

print(s)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A=list(map(int,input().split()))
L=[0]*65
MOD=(10**9+7)
for i in range(N):
    t=str(format(A[i],"b"))
    for j in range(len(t)):
        L[j]+=int(t[-j-1])

for i in range(len(L)):
    L[i]=L[i]*(N-L[i])
    L[i]*=2**i
print(sum(L)%MOD)




Fixed submission:
N = int(input())
A=list(map(int,input().split()))
L=[0]*65
MOD=(10**9+7)
for i in range(N):
    t=str(format(A[i],"b"))
    for j in range(len(t)):
        L[j]+=int(t[-j-1])

for i in range(len(L)):
    L[i]=L[i]*(N-L[i])
    L[i]*=2**i
    L[i]%=MOD
print(sum(L)%MOD)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A=list(map(int,input().split()))
L=[0]*65

for i in range(N):
    t=str(format(A[i],"b"))
    for j in range(len(t)):
        L[j]+=int(t[-j-1])

for i in range(len(L)):
    L[i]=L[i]*(N-L[i])
    L[i]%=(10**9+7)
    L[i]*=2**i
    L[i]%=(10**9+7)
print(sum(L)%(10**9+7))




Fixed submission:
N = int(input())
A=list(map(int,input().split()))
L=[0]*65
MOD=(10**9+7)
for i in range(N):
    t=str(format(A[i],"b"))
    for j in range(len(t)):
        L[j]+=int(t[-j-1])

for i in range(len(L)):
    L[i]=L[i]*(N-L[i])
    L[i]*=2**i
    L[i]%=MOD
print(sum(L)%MOD)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A=list(map(int,input().split()))
L=[0]*65

for i in range(N):
    t=str(format(A[i],"b"))
    for j in range(len(t)):
        L[j]+=int(t[-j-1])

for i in range(len(L)):
    L[i]=L[i]*(N-L[i])
    L[i]%=(10**9+7)
    L[i]*=2**i
    L[i]%=(10**9+7)
print(sum(L)%(10**9+7))




Fixed submission:
N = int(input())
A=list(map(int,input().split()))
L=[0]*65
MOD=(10**9+7)
for i in range(N):
    t=str(format(A[i],"b"))
    for j in range(len(t)):
        L[j]+=int(t[-j-1])

for i in range(len(L)):
    L[i]=L[i]*(N-L[i])
    L[i]*=2**i
    L[i]%=MOD
print(sum(L)%MOD)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A=list(map(int,input().split()))
s=0
for i in range(N):
    for j in range(i+1,N):
        t=bin(A[i] ^ A[j])
        s+=int(t,0)
        s%=(10**9+7)
print(s)

Fixed submission:
N = int(input())
A=list(map(int,input().split()))
L=[0]*65
MOD=(10**9+7)
for i in range(N):
    t=str(format(A[i],"b"))
    for j in range(len(t)):
        L[j]+=int(t[-j-1])

for i in range(len(L)):
    L[i]=L[i]*(N-L[i])
    L[i]*=2**i
    L[i]%=MOD
print(sum(L)%MOD)
Buggy python submission (verdict: Runtime Error):
N=int(input())
A=list(map(int,input().split()))
B=[0]*N
B[0]=3

c=1
for a in A:
    c*=B[a]
    c%=1000000007
    B[a]-=1
    B[a+1]+=1

print(c)





Fixed submission:
N=int(input())
A=list(map(int,input().split()))
B=[0]*(N+1)
B[0]=3

c=1
for a in A:
    c*=B[a]
    c%=1000000007
    B[a]-=1
    B[a+1]+=1

print(c)
Buggy python submission (verdict: Runtime Error):
import math

X , Y =map(int,input().split())
X1=X
Y1=Y
x=0
y=0
if(X>Y):
    x=X-Y
    X1-=2*x
    Y1-=x
else:
    y=Y-X
    X1-=y
    Y1-=2*y
if(X1<0 or Y1<0 or X1%3!=0 or Y1%3!=0):
    print(0)
x+=X1//3
y+=X1//3


print((math.factorial(x+y)//(math.factorial(x)*math.factorial(y)))//((10**9)+7))

Fixed submission:
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

x, y = map(int, input().split())

mod = 10**9+7 #出力の制限
g1 = [1]*(x+y) # 元テーブル
g2 = [1]*(x+y) #逆元テーブル
inverse = [1]*(x+y)
inverse[0] = 1

if (x+y)%3 != 0 :
  print(0)
else:
  n = (x + y) // 3
  if x >= n and y >= n:
    a = x - n
    b = y - n
    
    for i in range(2, n + 1):
      g1[i]=( g1[i-1] * i ) % mod 
      inverse[i]=( -inverse[mod % i] * (mod//i) ) % mod 
      g2[i]=(g2[i-1] * inverse[i]) % mod
    
    answer = cmb(a+b,a,mod)
    print(answer)
  else:
    print(0)

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

X , Y =map(int,input().split())
X1=X
Y1=Y
x=0
y=0
if(X>Y):
    x=X-Y
    X1-=2*x
    Y1-=x
else:
    y=Y-X
    X1-=y
    Y1-=2*y
if(X1<0 or Y1<0 or X1%3!=0 or Y1%3!=0):
    print(0)
x+=X1//3
y+=X1//3


print((math.factorial(x+y)//(math.factorial(x)+math.factorial(y)))//((10**9)+7))

Fixed submission:
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

x, y = map(int, input().split())

mod = 10**9+7 #出力の制限
g1 = [1]*(x+y) # 元テーブル
g2 = [1]*(x+y) #逆元テーブル
inverse = [1]*(x+y)
inverse[0] = 1

if (x+y)%3 != 0 :
  print(0)
else:
  n = (x + y) // 3
  if x >= n and y >= n:
    a = x - n
    b = y - n
    
    for i in range(2, n + 1):
      g1[i]=( g1[i-1] * i ) % mod 
      inverse[i]=( -inverse[mod % i] * (mod//i) ) % mod 
      g2[i]=(g2[i-1] * inverse[i]) % mod
    
    answer = cmb(a+b,a,mod)
    print(answer)
  else:
    print(0)
Buggy python submission (verdict: Runtime Error):
import math

N = int(input())
D={}
T=list(map(int,input().split()))
for i in range(N):
    if D.get(T[i],None)==None:
        D[T[i]]=1
    else:
        D[T[i]]+=1

Max=max(D)
Min=min(D)
Len=len(D)
Item=sorted((D.items()))
if(Item[i][0]!=i):
    print("0")
    exit()
ans=1
for i in range(1,Len):
    ans = (ans * (Item[i-1][1]**Item[i][1])) % 998244353
    
print(ans)

Fixed submission:
import math

N = int(input())
D={}
T=list(map(int,input().split()))
if(T[0]!=0):
        print("0")
        exit()

for i in range(N):
    if D.get(T[i],None)==None:
        D[T[i]]=1
    else:
        D[T[i]]+=1

Max=max(D)
Min=min(D)
Len=len(D)
Item=sorted((D.items()))
if(Item[0][1]!=1):
        print("0")
        exit()
for i in range(Len):
    if(Item[i][0]!=i):
        print("0")
        exit()
ans=1
for i in range(1,Len):
    ans = (ans * (Item[i-1][1]**Item[i][1])) % 998244353
    
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
A=list(map(int,input().split()))
A=sorted(A)

t=0
c=0
for i in range(N):
    for j in range(i+1,N):
        t=A[i]+A[j]
        for k in range(j+1,N):
            if((max(A[i],A[j],A[k])*2)<(t+A[k])):
                c+=1
            else:
                break
print(c)


Fixed submission:
import bisect

N=int(input())
A=list(map(int,input().split()))
A=sorted(A)

t=0
c=0
for i in range(N-2):
    for j in range(i+1,N-1):
        t=A[i]+A[j]
        num=bisect.bisect_left(A,t)-1
        c+=max((num-j),0)

print(c)

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

t=0
c=0
for i in range(N):
    for j in range(i+1,N):
        t=A[i]+A[j]
        for k in range(j+1,N):
            if((max(A[i],A[j],A[k])*2)<(t+A[k])):
                c+=1
print(c)


Fixed submission:
import bisect

N=int(input())
A=list(map(int,input().split()))
A=sorted(A)

t=0
c=0
for i in range(N-2):
    for j in range(i+1,N-1):
        t=A[i]+A[j]
        num=bisect.bisect_left(A,t)-1
        c+=max((num-j),0)

print(c)
Buggy python submission (verdict: Runtime Error):
S = list(input())
K = int(input())
H=S[0]

flag=0
if(S[0]==S[len(S)-1]):
    flag=1
if(flag==0):
    for i in range(len(S)-1):
        if(S[i]==S[i+1]):
            S[i+1]="#"
            count+=1        
    print(count*K)
    exit()

flag2=0
for i in range(len(S)-1):
    if(S[i]!=S[i+1]):
        flag2=1
if(flag2==0):
    print((len(S)*K)//2)
    exit()

S1=S[:]
S2=S[:]+S[:]
S3=S[:]+S[:]+S[:]
RS=S[:]

count1=0
for i in range(len(S1)-1):
    if(S1[i]==S1[i+1]):
        S1[i+1]="#"
        count1+=1
count2=0
for i in range(len(S2)-1):
    if(S2[i]==S2[i+1]):
        S2[i+1]="#"
        count2+=1
count3=0
for i in range(len(S3)-1):
    if(S3[i]==S3[i+1]):
        S3[i+1]="#"
        count3+=1

N=count3-count2
E=count2-N

while(True):
    if(RS[0]==H):
        RS.pop(0)
    elif(RS[len(RS)-1]==H):
        RS.pop(len(RS)-1)
    else:
        break
rcount=0
for i in range(len(RS)-1):
    if(RS[i]==RS[i+1]):
        RS[i+1]="#"
        rcount+=1

print(count1+(K-1)*(count2-count1))

Fixed submission:
S = list(input())
K = int(input())
H=S[0]

flag=0
if(S[0]==S[len(S)-1]):
    flag=1
count=0
if(flag==0):
    for i in range(len(S)-1):
        if(S[i]==S[i+1]):
            S[i+1]="#"
            count+=1        
    print(count*K)
    exit()

flag2=0
for i in range(len(S)-1):
    if(S[i]!=S[i+1]):
        flag2=1
if(flag2==0):
    print((len(S)*K)//2)
    exit()

S1=S[:]
S2=S[:]+S[:]
S3=S[:]+S[:]+S[:]
RS=S[:]

count1=0
for i in range(len(S1)-1):
    if(S1[i]==S1[i+1]):
        S1[i+1]="#"
        count1+=1
count2=0
for i in range(len(S2)-1):
    if(S2[i]==S2[i+1]):
        S2[i+1]="#"
        count2+=1
count3=0
for i in range(len(S3)-1):
    if(S3[i]==S3[i+1]):
        S3[i+1]="#"
        count3+=1

N=count3-count2
E=count2-N

while(True):
    if(RS[0]==H):
        RS.pop(0)
    elif(RS[len(RS)-1]==H):
        RS.pop(len(RS)-1)
    else:
        break
rcount=0
for i in range(len(RS)-1):
    if(RS[i]==RS[i+1]):
        RS[i+1]="#"
        rcount+=1

print(count1+(K-1)*(count2-count1))
Buggy python submission (verdict: Time Limit Exceeded):
import bisect

N,M=map(int,input().split())
A=list(map(int,input().split()))
A=sorted(A)

for i in range(M):
    t=A[-1]//2
    index=bisect.bisect_right(A,t)
    A=A[0:len(A)-1]
    A.insert(index,t)
    

print(sum(A))

Fixed submission:
import heapq

N,M=map(int,input().split())
A=list(map(int,input().split()))
A=sorted(A)

que = []
for a in A:
  heapq.heappush(que, -1*a)
 
for a in range(M):
  maxvalue = -1 * heapq.heappop(que)
  maxvalue /= 2
  heapq.heappush(que, -1*maxvalue)
 
print(sum([int(-1*a) for a in que]))
Buggy python submission (verdict: Runtime Error):
S = int(input())
total=10*10
if(S%2==1):
    total=S*((S-1)//2)
else:
    total=(S-1)*((S-2)//2)+(S-1)

print(total)

Fixed submission:
S = input()
T = input()

total=0
for i in range(3):
    if(S[i]==T[i]):
        total+=1
print(total)
Buggy python submission (verdict: Time Limit Exceeded):
S = int(input())
total=0
for i in range(1,S):
    total+=i

print(total)

Fixed submission:
S = int(input())
total=10*6
if(S%2==1):
    total=S*((S-1)//2)
else:
    total=(S-1)*((S-2)//2)+(S-1)

print(total)