Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
ans = sum(range(N))
print(ans)

Fixed submission:
N = int(input())
ans = N*(N-1)//2
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
ans = sum([x for x in range(N)])
print(ans)

Fixed submission:
N = int(input())
ans = N*(N-1)//2
print(ans)
Buggy python submission (verdict: Runtime Error):
N = int(input())
a = [0]*N
b = [0]*N
for i in range(N):
    a[i] = int(input())
    b[i] = int(input())
m = max(b)
b.remove(m)
n = max(b)

for i in range(N):
    if a[i] == m:
        print(n)
    else:
        print(m)

Fixed submission:
N = int(input())
a = [0]*N
b = [0]*N
for i in range(N):
    a[i] = int(input())
    b[i] = a[i]
m = max(b)
b.remove(m)
n = max(b)

for i in range(N):
    if a[i] == m:
        print(n)
    else:
        print(m)

Buggy python submission (verdict: Runtime Error):
N = int(input())
a = [0]*N
for i in range(N):
    a[i] = int(input())
m = max(a)
a.remove(m)
n = max(a)


for i in range(N):
    if a[i] == m:
        print(n)
    else:
        print(m)

Fixed submission:
N = int(input())
a = [0]*N
b = [0]*N
for i in range(N):
    a[i] = int(input())
    b[i] = a[i]
m = max(b)
b.remove(m)
n = max(b)

for i in range(N):
    if a[i] == m:
        print(n)
    else:
        print(m)

Buggy python submission (verdict: Runtime Error):
N = int(input())
a = [0]*N
for i in range(N):
    a[i] = int(input())
b = set(a)
m = max(b)
b.remove(m)
n = max(b)
for i in range(N):
    if a[i] == m:
        print(n)
    else:
        print(m)

Fixed submission:
N = int(input())
a = [0]*N
b = [0]*N
for i in range(N):
    a[i] = int(input())
    b[i] = a[i]
m = max(b)
b.remove(m)
n = max(b)

for i in range(N):
    if a[i] == m:
        print(n)
    else:
        print(m)
Buggy python submission (verdict: Runtime Error):
ans = 0
first_b = 0
last_a = 0
same = 0

N = int(input())

for i in range(N):
    s = input()
    ans += s.count("AB")
    if s[0] == "B":
        first_b += 1
    if s[-1] == "A":
        last_a += 1
    if s[0] == "B" and s[-1] == "A":
        same +=1

ans += min(first_b, last_a)
if same > 0 and first_b ==  last_a and first_b = same:
    ans -=1
 print(ans)

Fixed submission:
ans = 0
first_b = 0
last_a = 0
same = 0

N = int(input())

for i in range(N):
    s = input()
    ans += s.count("AB")
    if s[0] == "B":
        first_b += 1
    if s[-1] == "A":
        last_a += 1
    if s[0] == "B" and s[-1] == "A":
        same +=1

ans += min(first_b, last_a)
if same > 0 and first_b ==  last_a and first_b == same:
    ans -=1
print(ans)
Buggy python submission (verdict: Runtime Error):
n,k = [int(x) for x in input().split()]

if n/(k-1) > 2 :
    print("YES")
else:
    print("NO")

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

if k==1 or n/(k-1) > 2 :
    print("YES")
else:
    print("NO")
Buggy python submission (verdict: Runtime Error):
a,b = input().split()
print((a-1)*(b-1))

Fixed submission:
a,b = [int(x) for x in input().split()]
print((a-1)*(b-1))
Buggy python submission (verdict: Runtime Error):
def main():
    N=int(input())
    P=[0]*N
    p=[False]*(N+1)
    P[0]=int(input())
    for i in range(N-1):
        P[i+1=int(input())
        if P[-1]-1 in P[:-1]:
            p[P[-1]-1] = True
    ans=0
    j=0
    for i in range(N):
        if p[i]==True:
            j+=1
        else:
            ans=max(ans,j)
            j=0
    print(N-ans-1)


if __name__ == "__main__":
    main()


Fixed submission:
def main():
    N=int(input())
    p=[False]*(N+1)
    c=[False]*(N+1)
    for i in range(N):
        x=int(input())
        c[x]=True
        if c[x-1]:
            p[x-1] = True
    ans=0
    j=0
    for i in range(1,N+1):
        if p[i]:
            j+=1
        else:
            ans=max(ans,j)
            j=0
    ans=max(ans,j)
    print(N-ans-1)

if __name__ == "__main__":
    main()
Buggy python submission (verdict: Runtime Error):
print(input().replace("2017","2018"))

Fixed submission:
print(input().replace("2017","2018"))
Buggy python submission (verdict: Runtime Error):
n,k = [int(x) for x in input().split()]
s = {}

for i in input().split():
    if(i in s):
        s[i] += 1
    else:
        s[i] = 1


t = list(s.values())
t.sort()
a = 0

while len(t) > k:
    a += t.pop(0)

print(a)


Fixed submission:
print(sum([int(x) for x in input()]))

Buggy python submission (verdict: Runtime Error):
print(sum([int(x) for x in input().split()]))


Fixed submission:
print(sum([int(x) for x in input()]))
Buggy python submission (verdict: Runtime Error):
n = input()
b = [int(x) for x in input().split()]
c = 0
while True:
    for i,x in enumerate(b):
        if x%2 != 0:
            break
        b[x] = int(x/2)
    c += 1
print(c)

Fixed submission:
n = input()
b = [int(x) for x in input().split()]
c = 0
flg = True
while flg:
    for i,x in enumerate(b):
        if x!=0 and x%2 != 0:
            flg=False
            break
        b[i] = int(x/2)
    c += 1
print(c-1)

Buggy python submission (verdict: Runtime Error):
n = input()
b = ['{0:b}'.format(int(x)) for x in input().split()]
a = 0
for c in b:
    m = re.match(r'.*(10*)$',c)
    if m is None:
      continue
    a = max(a,len(m[1])-1)
print(a)

Fixed submission:
n = input()
b = [int(x) for x in input().split()]
c = 0
flg = True
while flg:
    for i,x in enumerate(b):
        if x!=0 and x%2 != 0:
            flg=False
            break
        b[i] = int(x/2)
    c += 1
print(c-1)

Buggy python submission (verdict: Runtime Error):
n = input()
b = ['{0:b}'.format(int(x)) for x in input().split()]
a = 0
for c in b:
    m = re.match(r'.*(10*)$',c)
    print(m[1])   
    if m is None:
      continue
    a = max(a,len(m[1])-1)
print(a)

Fixed submission:
n = input()
b = [int(x) for x in input().split()]
c = 0
flg = True
while flg:
    for i,x in enumerate(b):
        if x!=0 and x%2 != 0:
            flg=False
            break
        b[i] = int(x/2)
    c += 1
print(c-1)
Buggy python submission (verdict: Time Limit Exceeded):
n,k = [int(x) for x in input().split()]
s = {}

for i in input().split():
    if(i in s):
        s[i] += 1
    else:
        s[i] = 1


t = list(s.values())
t.sort()
a = 0

while len(t) > k:
    a += t.pop(0)

print(a)


Fixed submission:
n,k = [int(x) for x in input().split()]
s = {}

for i in input().split():
    if(i in s):
        s[i] += 1
    else:
        s[i] = 1


t = list(s.values())
t.sort()
a = sum(t[0:-k])

print(a)

Buggy python submission (verdict: Runtime Error):
n,k = [int(x) for x in input().split()]
s = {}
for i in input().split():
    if(i in s):
        s[i] += 1
    else:
        s[i] = 1


t = list(s.values())
t.sort()
a = 0

while len(t) > k:
    a += t.pop(0)[1]

print(a)


Fixed submission:
n,k = [int(x) for x in input().split()]
s = {}

for i in input().split():
    if(i in s):
        s[i] += 1
    else:
        s[i] = 1


t = list(s.values())
t.sort()
a = sum(t[0:-k])

print(a)

Buggy python submission (verdict: Time Limit Exceeded):
n,k = [int(x) for x in input().split()]
s = {}

for i in input().split():
    if(i in s):
        s[i] += 1
    else:
        s[i] = 1

t = sorted(s.items(), key=lambda x: x[1])

a = 0

while len(t) > k:
    a += t.pop(0)[1]

print(a)


Fixed submission:
n,k = [int(x) for x in input().split()]
s = {}

for i in input().split():
    if(i in s):
        s[i] += 1
    else:
        s[i] = 1


t = list(s.values())
t.sort()
a = sum(t[0:-k])

print(a)
Buggy python submission (verdict: Runtime Error):
a,b,c = [int(x) for x in input().split()]

if c>=a and c<=b:
	print("Yes")
else
	print("No")


Fixed submission:
a,b,c = [int(x) for x in input().split()]

if c>=a and c<=b:
	print("Yes")
else:
	print("No")
Buggy python submission (verdict: Time Limit Exceeded):
N,K = [int(x) for x in input().split()]
arr=[]
for i in range(N):
    a,b = [int(x) for x in input().split()]
    arr = arr + [a]*b
arr.sort()
print(arr[K-1])


Fixed submission:
N,K = [int(x) for x in input().split()]
arr=[]
for i in range(N):
    arr.append([int(x) for x in input().split()])
    
arr.sort(key=lambda tup: tup[0])

for i in range(N):
    K=K-arr[i][1]
    if K<=0:
        print(arr[i][0])
        break
Buggy python submission (verdict: Runtime Error):
import sys

n = int(input())
t = [int(x) for x in input().split()]
a = [int(x) for x in input().split()]

if t[n-1]!=a[0]:
    print(0)
    sys.exit()

m =[]
for i in range(n):
    mx = min(t[i],a[i])
    mn = 1
    if i == 0:
        mn = t[i]
    elif i == n-1:
        mn = a[i]
    else :
        if t[i]!=t[i-1]:
            mn=t[i]
        if a[i]!=a[i+1]:
            mn=a[i]
    m.append([mx,min(mx,mn)])

ans = 1
for i in range(n):
    ans = (ans * (m[i][0]-m[i][1]+1))%(10**9+7)
print(ans)


Fixed submission:
s = input()
c = s.find('C')
f = s.rfind('F')

if  c != -1 and f != -1 and (c < f):
    print('Yes')
else:
    print('No')
Buggy python submission (verdict: Runtime Error):
N=int(input())
a=[0]*N
for i in range(N):
    a[i]=int(input())
minimum=1
count=0
for i in  a:
   if(minimum<i):
       if i%minimum:
           count+= i//minimum
       else :
           count+= (i//minimum-1)
   else:
       minimum=max(minimum,i+1)
print(count)


Fixed submission:
s=input()
a="CODEFESTIVAL2016"
count=0
for a,b in zip(s,a) :
    if a != b :
        count+=1 
print(count)
Buggy python submission (verdict: Runtime Error):
N=int(input())
a=[0]*N
for i in range(N):
    a.[i]=int(input())
minimum=1
count=0
for i in  a:
   if(minimum<i):
       if i%minimum:
           count+= i//minimum
       else :
           count+= (i//minimum-1)
   else:
       minimum=max(minimum,i+1)
print(count)


Fixed submission:
N=int(input())
a=[0]*N
for i in range(N):
    a[i]=int(input())

minimum=2
count=a[0]-1
a.pop(0)
for i in  a:
   if(minimum<i):
       if i%minimum:
           count+= i//minimum
       else :
           count+= (i//minimum-1)
   else:
       minimum=max(minimum,i+1)
print(count)

Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
a=[]
for i in range(N):
    a.append(int(input()))

minimum=1
count=0
while a:
   if(minimum<a[0]):
       if a[0]%minimum:
           count+= a[0]//minimum
           a[0]-= a[0]//minimum*minimum
       else :
           count+= (a[0]//minimum-1)
           a[0]= 1
   else:
       minimum=max(minimum,a[0]+1)
       a.pop(0)
print(count)


Fixed submission:
N=int(input())
a=[0]*N
for i in range(N):
    a[i]=int(input())

minimum=2
count=a[0]-1
a.pop(0)
for i in  a:
   if(minimum<i):
       if i%minimum:
           count+= i//minimum
       else :
           count+= (i//minimum-1)
   else:
       minimum=max(minimum,i+1)
print(count)

Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
a=[]
for i in range(N):
    a.append(int(input()))
minimum=1
count=0
while a:
   if(minimum<a[0]):
       count+=1
       if a[0] <= (minimum * 2) :
           a[0]=1
       else :
           a[0]-= minimum
   else:
       minimum=max(minimum,a[0]+1)
       a.pop(0)
print(count)


Fixed submission:
N=int(input())
a=[0]*N
for i in range(N):
    a[i]=int(input())

minimum=2
count=a[0]-1
a.pop(0)
for i in  a:
   if(minimum<i):
       if i%minimum:
           count+= i//minimum
       else :
           count+= (i//minimum-1)
   else:
       minimum=max(minimum,i+1)
print(count)
Buggy python submission (verdict: Runtime Error):
s=list(input())
k=int(input())

def toA(char):
    return (ord('z')-ord(char)+1)%26


def toC(char,k):
    if(ord('z')-ord(char)>=k):
        return chr(ord(char)+k)
    else:
        return chr(ord('a')+k-ord('z')-ord(char))


for i in range(len(s)):
    if(k==0):
        break
    if(k>=toA(s[i])):
        k-=toA(s[i])
        s[i]='a'
    if(i==len(s)-1) and k>0:
        s[i]= toC(s[i],k)
print("".join(s))


Fixed submission:
s=list(input())
k=int(input())

def toA(char):
    return (ord('z')-ord(char)+1)%26

def toC(char,k):
    if(ord('z')-ord(char)>=k%26):
        return chr(ord(char)+k%26)
    else:
        return chr(ord('a')+k-ord('z')-ord(char))
for i in range(len(s)):
    if(k==0):
        break
    if(k>=toA(s[i])):
        k-=toA(s[i])
        s[i]='a'
    if(i==len(s)-1) and k>0:
        s[i]= toC(s[i],k)
print("".join(s))
Buggy python submission (verdict: Runtime Error):
n = int(input())
a=[]

b = list(map(int, input().split()))
for i in range(n):
    4a+=[[i+1, b[i]] ]
    
    
import operator as op
a.sort(key = op.itemgetter(1))

x=""
for i in range(n):
    x+=str(a[i][0])
    if i!=n-1:
        x+=" "
#a = [[3,-9],[2,3],[1,20]]
print(x)

Fixed submission:
n = int(input())
a=[]

b = list(map(int, input().split()))
for i in range(n):
    a+=[[i+1, b[i]] ]
    
    
import operator as op
a.sort(key = op.itemgetter(1))

x=""
for i in range(n):
    x+=str(a[i][0])
    if i!=n-1:
        x+=" "

print(x)
Buggy python submission (verdict: Runtime Error):
x, a = map(int,rfile.readline().split())
if x<a:
    print(0)
    else:
    print(10)

Fixed submission:
x, a = map(int,input().split())
if x<a:
    print(0)
else:
    print(10)
Buggy python submission (verdict: Runtime Error):
n=int(input())
#4
#7
ans=False
if n%7==0:
    ans==True


for i in range(n/7):
    if (n-i*7)%4==0:
        ans=True
        

if ans:
    print("Yes")
else:
    print("No")    


Fixed submission:
n=int(input())


ans=False

if n%7==0:
    ans=True


for i in range((int(1+(n/7)))):
    
    if (n-i*7)%4==0:
        ans=True
        

if ans:
    print("Yes")
else:
    print("No")
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = [int(i) for i in input().split(" ")]
r = [i+1-j for i, j in enumerate(a)]
l = [j+i+1 for i, j in enumerate(a)]
ans = 0
for i in set(r):
    p = r.count(i)
    q = l.count(i)
    ans += p*q
print(ans)


Fixed submission:
from collections import Counter
n = int(input())
a = [int(i) for i in input().split(" ")]
r = [i+1-j for i, j in enumerate(a)]
l = [j+i+1 for i, j in enumerate(a)]
nl = Counter(l)
nr = Counter(r)
 
ans = 0
for k, v in nl.items():
    ans += nr[k]*v
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np
n = int(input())
a = np.array([int(i) for i in input().split(" ")])
c = np.arange(1, n)
ans = 0
for i in range(n):
    ans += np.sum(a[i+1:]+a[i] == c[:n-i-1])
print(ans)

Fixed submission:
from collections import Counter
n = int(input())
a = [int(i) for i in input().split(" ")]
r = [i+1-j for i, j in enumerate(a)]
l = [j+i+1 for i, j in enumerate(a)]
nl = Counter(l)
nr = Counter(r)
 
ans = 0
for k, v in nl.items():
    ans += nr[k]*v
print(ans)
Buggy python submission (verdict: Runtime Error):
import itertools
 
def check(lis, a):
    return sum((i[3] for i in a if lis[i[1]-1]-lis[i[0]-1]==i[2]))
   
n, m, q = map(int, input().split())
a = ((int(i) for i in input().split(" ")) for j in range(q))
ans = 0
for i in itertools.combinations_with_replacement(range(m), n):
    ans = max(ans, check(i, a))
print(ans)

Fixed submission:
import itertools

def check(lis, a):
    return sum([i[3] for i in a if lis[i[1]-1]-lis[i[0]-1]==i[2]])
   
n, m, q = map(int, input().split())
a = [[int(i) for i in input().split(" ")] for j in range(q)]
ans = 0
for i in itertools.combinations_with_replacement(range(m), n):
    ans = max(ans, check(i, a))
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
used = []
for i in range(n):
    s = input()
    if not s in used:
        used.append(s)
print(len(used))

Fixed submission:
n = int(input())
s = set([input() for i in range(n)])
print(len(s))
Buggy python submission (verdict: Runtime Error):
s = input()
l = len(s)
te = [1] * 20000
c = 2019
for i in range(1, len(te)):
    te[i] = te[i-1]*10 % c

ans = 0
for i in range(l-1, -1, -1):
    t = int(s[i])
    if t == 0:
        ans += 1
    for j in range(1, i+1):
        t = t + int(s[i-j])*te[j]
        t = t%c
        if t == 0:
            ans += 1
print(ans)

Fixed submission:
s = input()
l = len(s)
c = 2019
tm = 1
ti = int(s[-1])
co = [0]*2019
co[ti] += 1
for i in range(1, l):
    tm = tm*10 % c
    ti += int(s[l-i-1]) * tm
    ti = ti % c
    co[ti] += 1
if co[0] != 0:
    co[0] += 1
print(sum([i*(i-1)//2 for i in co]))
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
s = [1 if i=="R" else 2 if i=="G" else 4 for i in input()]
c = 0
for i in range(n-3):
    a = s[i]
    for j in range(i+1, n-1):
        if a == s[j]:
            continue
        else:
            b = a + s[j]
            c += sum([1 for k in range(j+1, n) if b+s[k]==7 and k-j!=j-i])
print(c)

Fixed submission:
n = int(input())
s = [1 if i=="R" else 2 if i=="G" else 4 for i in input()]
r = s.count(1)
g = s.count(2)
b = s.count(4)
ans = r*g*b
for i in range(n-1):
    for j in range(1, (n-i-1)//2+1):
        if s[i] + s[i+j] + s[i+j+j] == 7:
            ans -= 1
print(ans)
Buggy python submission (verdict: Runtime Error):
n, k = map(int, input().split())
c = 10**9+7
tm = [0] + [1]*k
a = k//2
ans = k*(k+1)//2 - a*(a+1)//2
for i in range(k//2, 0, -1):
    a = k//i
    t = (left_bin(a, n, c) - sum([tm[j*i] for j in range(2, a+1)])) % c
    ans = (ans + t*i) % c
    tm[i] = t
print(ans)


Fixed submission:
def left_bin(a, n, c):
    ns = [int(i) for i in bin(n)[3:]]
    t = a
    for i in ns:
        t = t*t % c
        if i == 1:
            t = t*a % c
    return t


n, k = map(int, input().split())
c = 10**9+7
tm = [0] + [1]*k
a = k//2
ans = k*(k+1)//2 - a*(a+1)//2
for i in range(k//2, 0, -1):
    a = k//i
    t = (left_bin(a, n, c) - sum([tm[j*i] for j in range(2, a+1)])) % c
    ans = (ans + t*i) % c
    tm[i] = t
print(ans)
Buggy python submission (verdict: Runtime Error):
x, y, a, b, c = map(int, input().split())
p = [int(i) for i in input().split(" ")]
q = [int(i) for i in input().split(" ")]
r = [int(i) for i in input().split(" ")]
p = sorted(p)
q = sorted(q)
r = sorted(r)
x_ = a-x
y_ = b-y
ans = sum(p[x_:]) + sum(q[y_:])
for i in r[::-1]:
    if p[x_] > q[y_]:
        if q[y_] < i:
            ans += i - q[y_]
            y_ += 1
        else:
            break
    else:
        if p[x_] < i:
            ans += i - p[x_]
            x_ += 1
        else:
            break
print(ans)


Fixed submission:
x, y, a, b, c = map(int, input().split())
p = [int(i) for i in input().split(" ")]
q = [int(i) for i in input().split(" ")]
r = [int(i) for i in input().split(" ")]
p = sorted(p)
q = sorted(q)
r = sorted(r)
x_ = a-x
y_ = b-y
flag = 0
ans = sum(p[x_:]) + sum(q[y_:])
for i in range(c-1, -1, -1):
    if p[x_] > q[y_]:
        if q[y_] < r[i]:
            ans += r[i] - q[y_]
            y_ += 1
            if y_>=b:
                flag = 1
                break
        else:
            break
    else:
        if p[x_] < r[i]:
            ans += r[i] - p[x_]
            x_ += 1
            if x_>=a:
                flag = 2
                break
        else:
            break
if flag == 1:
    for j in range(i-1, -1, -1):
        if x_>=a:
            break
        if p[x_] < r[j]:
            ans += r[j] - p[x_]
            x_ += 1
        else:
            break
elif flag == 2:
    for j in range(i-1, -1, -1):
        if y_>=b:
            break
        if q[y_] < r[j]:
            ans += r[j] - q[y_]
            y_ += 1
        else:
            break
            
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
s = [input() for i in range(n)]
s_ = list(set(s))
co = [0 for i in range(len(s_))]
for i in range(len(s_)):
    co[i] = s.count(s_[i])
ma = max(co)
arg = [i for i in range(len(s_)) if co[i]==ma]
ans = [s_[i] for i in arg]
print("\n".join(sorted(ans)))

Fixed submission:
n = int(input())
s = sorted([input() for i in range(n)])
s_ = sorted(list(set(s)))
if len(s_) != n:
    s.append(0)
    co = [1] + [0 for i in range(len(s_)-1)]
    ind = 0
    for i in range(1, n):
        if s[i-1] == s[i]:
            co[ind] += 1
        else:
            ind += 1
            co[ind] += 1
    ma = max(co)
    arg = [i for i in range(len(s_)) if co[i]==ma]
    ans = [s_[i] for i in arg]
    print("\n".join(sorted(ans)))
    
else:
    print("\n".join(s))

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
s = [input() for i in range(n)]
used = [s[0]] + [0 for i in range(n-1)]
co = [1] + [0 for i in range(n-1)]
if n == 1:
    print(used[0])
else:
    ind = 1
    for i in s[1:]:
        if i in used[:ind]:
            co[used[:ind].index(i)] += 1
        else:
            used[ind] = i
            co[ind] = 1
            ind += 1
    ma = max(co)
    arg = [i for i in range(n) if co[i]==ma]
    ans = [used[i] for i in arg]
    print("\n".join(sorted(ans)))

Fixed submission:
n = int(input())
s = sorted([input() for i in range(n)])
s_ = sorted(list(set(s)))
if len(s_) != n:
    s.append(0)
    co = [1] + [0 for i in range(len(s_)-1)]
    ind = 0
    for i in range(1, n):
        if s[i-1] == s[i]:
            co[ind] += 1
        else:
            ind += 1
            co[ind] += 1
    ma = max(co)
    arg = [i for i in range(len(s_)) if co[i]==ma]
    ans = [s_[i] for i in arg]
    print("\n".join(sorted(ans)))
    
else:
    print("\n".join(s))
Buggy python submission (verdict: Runtime Error):
tmp = [int(i) for i in input().split(" ")]
n = tmp[0]
k = tmp[1]
a = [int(i) for i in input().split(" ")]
import numpy as np
uni, co = np.unique(a, return_counts=True)
ind = [np.sum(co[:uni.tolist().index(i)]) for i in a]
c = 0
a = np.array(a)
for i in range(len(a)):
    c += np.sum(a[i:]<a[i])
m = 10**9+7
tm = int(c)*int(k) % m
if k % 2 == 0:
    t = k * (k//2-1) + k//2
    t %= m
else:
    t = k * (k//2)
    t %= m
print((np.sum(ind)*t+tm) % m)

Fixed submission:
tmp = [int(i) for i in input().split(" ")]
n = tmp[0]
k = tmp[1]
a = [int(i) for i in input().split(" ")]
import numpy as np
a = np.array(a)
uni = np.unique(a)
co = [np.sum(a==i) for i in uni]
ind = np.array([np.sum(co[:uni.tolist().index(i)]) for i in a]).astype(np.int32)
c = 0

for i in range(len(a)):
    c += np.sum(a[i:]<a[i])
m = 10**9+7
tm = int(c)*int(k) % m
if k % 2 == 0:
    t = k * (k//2-1) + k//2
    t %= m
else:
    t = k * (k//2)
    t %= m
print((int(np.sum(ind))*t+tm) % m)
Buggy python submission (verdict: Runtime Error):
a = [int(i) for i in input().split(" ")]
b = max((a[2]-(a[0]-a[1]), 0)
print(b)


Fixed submission:
a = [int(i) for i in input().split(" ")]
b = max(a[2]-(a[0]-a[1]), 0)
print(b)
Buggy python submission (verdict: Time Limit Exceeded):
s=[1 if i=="R" else -1 for i in input()]
count = [0 for i in range(len(s))]
for i in range(len(s)):
    c=0
    now=i
    while True:
       c+=1
       ne=s[now]
       nextstep=s[now+ne]
       if nextstep == ne:
           now+=ne
       else:
           break
    if (10**100-c)%2 == 0:
        count[now+ne] += 1
    else:
        count[now] += 1
print(" ".join([str(i) for i in count]))

Fixed submission:
s=[1 if i=="R" else -1 for i in input()]
count = [0 for i in range(len(s))]
for i in range(len(s)):
    c=0
    now=i
    if i>0 and s[now]==s[i-1]:
        count[pre_ot] += 1
        pre_re, pre_ot = pre_ot, pre_re
        continue
        
    while True:
       c+=1
       ne=s[now]
       nextstep=s[now+ne]
       if nextstep == ne:
           now+=ne
       else:
           break
    if (10**100-c)%2 == 0:
        count[now+ne] += 1
        pre_re = now+ne
        pre_ot = now
    else:
        count[now] += 1
        pre_re = now
        pre_ot = now+ne
print(" ".join([str(i) for i in count]))
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
ind = []
m = 0
k = 0
for i in range(n):
    a = int(input())
    if m == a:
        ind.append(i)
        k = a
    elif m < a:
        k, m = m, a
        ind = [i]
    elif k < a:
        k = a
print("\n".join(map(str, [k if i in ind else m for i in range(n)])))


Fixed submission:
n = int(input())
ind = []
m = 0
k = 0
for i in range(n):
    a = int(input())
    if m == a:
        ind = -1
    elif m < a:
        k, m = m, a
        ind = i
    elif k < a:
        k = a
if ind == -1:
    print("\n".join(map(str, [m for i in range(n)])))
else:
    print("\n".join(map(str, [k if i == ind else m for i in range(n)])))