Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
H,W,K=map(int,input().split())
s=[[int(x) for x in list(input())] for _ in range(H)]
ans = H*W
for h in range(2**(H-1)):
  parts = list()
  upper = 0
  cnt = 0
  for j in range(H-1):
    if h >> j & 1:
      cnt += 1
      parts.append([sum([s[y][x] for y in range(upper, j+1)]) for x in range(W)])
      upper = j+1
  parts.append([sum([s[y][x] for y in range(upper, H)]) for x in range(W)])
  # 貪欲
  summary = [0]*len(parts)
  for i in range(W):
    temp_sum = [summary[j] + parts[j][i] for j in range(len(parts))]
    for ts in temp_sum:
      if ts > K:
        cnt += 1
        summary = [parts[j][i] for j in range(len(parts))]
        break
    else:
      summary = temp_sum
  ans = min(ans, cnt)
print(ans)

Fixed submission:
H,W,K=map(int,input().split())
s=[[int(x) for x in list(input())] for _ in range(H)]
ans = H*W
for h in range(2**(H-1)):
  parts = list()
  upper = 0
  cnt = 0
  inv_flg = 0
  for j in range(H-1):
    if h >> j & 1:
      cnt += 1
      appending = [sum([s[y][x] for y in range(upper, j+1)]) for x in range(W)]
      if any([x> K for x in appending]):
        inv_flg = 1
        break
      parts.append(appending)
      upper = j+1
  else:
    appending = [sum([s[y][x] for y in range(upper, H)]) for x in range(W)]
    if any([x > K for x in appending]):
      inv_flg = 1
    else:
      parts.append(appending)
  if inv_flg:
    continue
  # 貪欲
  summary = [0]*len(parts)
  for i in range(W):
    temp_sum = [summary[j] + parts[j][i] for j in range(len(parts))]
    for ts in temp_sum:
      if ts > K:
        cnt += 1
        summary = [parts[j][i] for j in range(len(parts))]
        break
    else:
      summary = temp_sum
  ans = min(ans, cnt)
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
s=input()
q=int(input())
querys=[0]*q
for i in range(q):
  x = input().split()
  if len(x) == 1:
    querys[i] = [int(x[0])]
  else:
    querys[i] = [int(x[0]), int(x[1]), x[2]]
trans=0
for query in querys:
  if query[0]==1:
    trans += 1
  elif (query[1] & 1) ^ (trans & 1):
    s = query[2] + s
  else: # 後
    s += query[2]
res = ''
if trans % 2 == 0:
  res = s
else:
  res = ''.join([s[len(s)-i-1] for i in range(len(s))])
print(res)

Fixed submission:
#import time
#t1=time.time()
s=input()
q=int(input())
trans=0
head=''
#t2=time.time()
for i in range(q):
  query = input().split()
  if query[0]=='1':
    trans += 1
  elif (int(query[1]) & 1) ^ (trans & 1):
    head += query[2]
  else:
    s += query[2]
res = ''
#t3=time.time()
if trans % 2 == 0:
  res = ''.join([head[len(head)-i-1] for i in range(len(head))]) + s
else:
  res = ''.join([s[len(s)-i-1] for i in range(len(s))]) + head
print(res)
#t4=time.time()
#print(int((t2-t1)*1000),int((t3-t2)*1000),int((t4-t3)*1000),int((t4-t1)*1000))
Buggy python submission (verdict: Runtime Error):
import sys
n,m=map(int,input().split())
sc = [list(map(int,input().split())) for i in range(m)]
for i in range(10**n):
  for j in range(m):
    sti = str(i)
    if sti[sc[j][0]-1] != str(sc[j][1]):
      break
  else:
    print(i)
    sys.exit()
print(-1)

Fixed submission:
import sys
n,m=map(int,input().split())
sc = [list(map(int,input().split())) for i in range(m)]
for i in range(10**n):
  if len(str(i)) < n:
    continue
  for j in range(m):
    sti = str(i)
    if sti[sc[j][0]-1] != str(sc[j][1]):
      break
  else:
    print(i)
    sys.exit()
print(-1)
Buggy python submission (verdict: Time Limit Exceeded):
h,n=map(int,input().split())
ab=[[] for i in range(n)]
for i in range(n):
  ab[i]=list(map(int,input().split()))
  
dp=[100000000 for i in range(h+1)]
dp[0]=0
for hi in range(h):
  for i in range(n):
    damage=min(h,hi+ab[i][0])
    dp[damage] = min(dp[damage],dp[hi]+ab[i][1])
    #print(damage,dp[damage],dp[hi]+ab[i][1])
print(dp[h])

Fixed submission:
h,n=map(int,input().split())
ab=[[] for i in range(n)]
for i in range(n):
  ab[i]=list(map(int,input().split()))
  
dp=[100000000 for i in range(h+1)]
dp[0]=0
for hi in range(h):
  for i in range(n):
    damage=min(h,hi+ab[i][0])
    dp[damage] = min(dp[damage],dp[hi]+ab[i][1])
    #print(damage,dp[damage],dp[hi]+ab[i][1])
print(dp[h])
Buggy python submission (verdict: Runtime Error):
import math
inp = input().split()
n,k = int(inp[0]),int(inp[1])
a = [int(x) for x in input().split()]
a.sort()
ans =0
for ini in range(0,n-k+1):
  for end in range(ini+k-1,n):
    m = end-ini-1
    r = k-2
    combi = math.factorial(m) // (math.factorial(m - r) * math.factorial(r))
    ans += (a[end]-a[ini])*combi

ans = ans % (10**9+7)
print(ans)

Fixed submission:
abc='abcdefghijklmnopqrstuvwxyz'
x=input()
print(abc[abc.index(x)+1])

Buggy python submission (verdict: Runtime Error):
inp = input().split()
n,k = int(inp[0]),int(inp[1])
a = [int(x) for x in input().split()]
a.sort()
ans =0
for ini in range(0,n-k+1):
  for end in range(ini+k-1,n):
    m = end-ini-1
    r = k-2
    combi = math.factorial(m) // (math.factorial(m - r) * math.factorial(r))
    ans += (a[end]-a[ini])*combi

ans = ans % (10**9+7)
print(ans)

Fixed submission:
abc='abcdefghijklmnopqrstuvwxyz'
x=input()
print(abc[abc.index(x)+1])
Buggy python submission (verdict: Runtime Error):
from itertools import permutations, combinations,combinations_with_replacement,product
inp = input().split()
n,k = int(inp[0]),int(inp[1])
a = [int(x) for x in input().split()]
a.sort()
ans =0
for ini in range(0,n-k+1):
  for end in range(ini+k-1,n):
    combi = combinations(end-ini-1,k-2)
    ans += (a[end]-a[ini])*combi

ans = ans % (10**9+7)
print(ans)

Fixed submission:

def pre_combi1(n, p):
  fact = [1]*(n+1)  # fact[n] = (n! mod p)
  factinv = [1]*(n+1)  # factinv[n] = ((n!)^(-1) mod p)
  inv = [0]*(n+1)  # factinv 計算用
  inv[1] = 1
  # 前処理
  for i in range(2, n + 1):
    fact[i]= fact[i-1] * i % p
    inv[i]= - inv[p % i] * (p // i) % p
    factinv[i]= factinv[i-1] * inv[i] % p
  return fact, factinv

def combi1(n, r, p, fact, factinv):
  """
  k<n<10**7でpが素数のときのnCr % pを求める
   """
  # 本処理
  if r < 0 or n < r:
    return 0
  r = min(r, n-r)
  return fact[n] * factinv[r] * factinv[n-r] % p
 
n,k=map(int,input().split())
a=sorted(list(map(int,input().split())))
sfs=0
p=1000000007
fact,factinv=pre_combi1(n,p)
for i in range(1,n+1):
  sfs+=a[i-1]*combi1(i-1,k-1,p,fact,factinv)
  sfs-=a[i-1]*combi1(n-i,k-1,p,fact,factinv)
  sfs %= p
  #print(i,a[i-1],n-i,k-1,sfs)
print(sfs%p)
Buggy python submission (verdict: Runtime Error):
n = int(input())
s = input()
if n % 2 !=0:
  print('No')
  sys.exit()
b = int(n/2)
if s[0:b]==s[b:n]:
  print('Yes')
else:
  print('No')

Fixed submission:
import sys
n = int(input())
s = input()
if n % 2 !=0:
  print('No')
  sys.exit()
b = int(n/2)
if s[0:b]==s[b:n]:
  print('Yes')
else:
  print('No')
Buggy python submission (verdict: Runtime Error):
import sys
n=int(input())
for i in range(1,10):
  x = n //i
  if n % i == 0 and 0 < x < 10:
    print('Yes')
 	sys.exit()
print('No')

Fixed submission:
import sys
n=int(input())
for i in range(1,10):
  x = n //i
  if n % i == 0 and 0 < x < 10:
    print('Yes')
    sys.exit()
print('No')
Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
ab=[list(map(int,input().split())) for i in range(n)]
ab.sort(key=lambda x: x[1])
t=0
for i in range(n):
  a,b=ab.pop(0)
  if t+a <= b:
    t += a
  else:
    print('No')
    break
else:
  print('Yes')

Fixed submission:
n=int(input())
ab=[list(map(int,input().split())) for i in range(n)]
ab.sort(key=lambda x: x[1])
t=0
for x in ab:
  if t+x[0] <= x[1]:
    t += x[0]
  else:
    print('No')
    break
else:
  print('Yes')

Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
ab=[list(map(int,input().split())) for i in range(n)]
ab.sort(key=lambda x: x[1])
t=0
for i in range(n):
  a,b=ab.pop(0)
  if t+a <= b:
    t += a
  else:
    print('No')
    break
else:
  print('Yes')

Fixed submission:
n=int(input())
ab=[list(map(int,input().split())) for i in range(n)]
ab.sort(key=lambda x: x[1])
t=0
for x in ab:
  if t+x[0] <= x[1]:
    t += x[0]
  else:
    print('No')
    break
else:
  print('Yes')
Buggy python submission (verdict: Runtime Error):
w,h,x,y=map(int,input().split())
candi=[x,y,w-x,h-y]
cnt=0
if min(candi)==x:
  res= x*h
  cnt+=1
if min(candi)==y:
  res= w*y
  cnt+=1
if min(candi)==w-x:
  res=(w-x)*h
  cnt+=1
if min(candi)=h-y:
  res=w*(h-y)
  cnt+=1
if cnt>0:
  cnt=1
print(res,cnt)


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

print(w*h/2.0,1 if 2*x==w and 2*y==h else 0)
Buggy python submission (verdict: Runtime Error):
n,m=map(int,input().split())
l=1
r=n
for i in range(m):
  li,ri=map(int,input().split())
  l = max(l,li)
  r = min(r,ri)
print(max(r-l,0)

Fixed submission:
n,m=map(int,input().split())
l=1
r=n
for i in range(m):
  li,ri=map(int,input().split())
  l = max(l,li)
  r = min(r,ri)
print(max(r-l+1,0))
Buggy python submission (verdict: Time Limit Exceeded):
s=[int(x) for x in list(input())]
cnt=0
l=0
while 1:
  #print(s,l)
  if len(s)<2 or l ==len(s)-1:
    break
  #print(l)
  if s[l]^s[l+1]:
    s.pop(l)
    s.pop(l)
    cnt += 2
    l=0
  else:
    l += 1
print(cnt)

Fixed submission:
s=[int(x) for x in list(input())]
x=s.count(0)
print(min(x,len(s)-x)*2)
Buggy python submission (verdict: Runtime Error):
n,m=map(int,input().split())
a=list(map(int,input().split()))
table={
  1:2,
  2:5,
  3:5,
  4:4,
  5:5,
  6:6,
  7:3,
  8:7,
  9:6,
}
dp=[-1]*(n+1)
dp[0]=0
for i in range(1,n+1):
  mx=-1
  for j in a:
    #print(i,i-table[j],dp[i-table[j]],j)
    if dp[i-table[j]]<0:
      continue
    if mx < dp[i-table[j]]*10+j:
      mx =dp[i-table[j]]*10+j
  dp[i]=mx
print(dp[n])

Fixed submission:
n,m=map(int,input().split())
a=list(map(int,input().split()))
table={
  1:2,
  2:5,
  3:5,
  4:4,
  5:5,
  6:6,
  7:3,
  8:7,
  9:6,
}
dp=[-1]*(n+1)
dp[0]=0
for i in range(1,n+1):
  mx=-1
  for j in a:
    if not 0 <= i-table[j] < n+1:
      continue
    #print(i,i-table[j],dp[i-table[j]],j)
    if dp[i-table[j]]<0:
      continue
    if mx < dp[i-table[j]]*10+j:
      mx =dp[i-table[j]]*10+j
  dp[i]=mx
print(dp[n])
Buggy python submission (verdict: Runtime Error):
import sys
a,b=map(int, input().split())
s=[a,b,a+b]
for si in s:
  if si%3==0:
  	print('Possible')
    sys.exit()    
print('Impossible')


Fixed submission:
import sys
a,b=map(int, input().split())
s=[a,b,a+b]
for si in s:
  if si%3==0:
    print('Possible')
    sys.exit()

print('Impossible')
Buggy python submission (verdict: Runtime Error):
a,b,c =map(int, input().split())
if a+c=2*b:
  print('YES')
else:
  print('NO')

Fixed submission:
a,b,c =map(int, input().split())
if a+c==2*b:
  print('YES')
else:
  print('NO')
Buggy python submission (verdict: Runtime Error):
inp = input().split()
a=inp[0]
b=inp[2]
if inp[1]=='+':
  print(a+b)
else:
  print(a-b)

Fixed submission:
inp = input().split()
a=int(inp[0])
b=int(inp[2])
if inp[1]=='+':
  print(a+b)
else:
  print(a-b)
Buggy python submission (verdict: Runtime Error):
s=input()
text=['dream','dreamer','erase','eraser']

def bfs(t):
  if t == s:
    return 1
  if len(t) >= len(s):
    return 0
  if t != s[:len(t)]:
    return 0
  ans = 0
  for tx in text:
    ans += bfs(t+tx)
  return ans

if bfs('') > 0:
  print('YES')
else:
  print('NO')

Fixed submission:
import sys
s=''.join(reversed(list(input())))
t=''
text = ['maerd', 'esare', 'resare', 'remaerd']
while len(t) < len(s):
  for tx in text:
    if t + tx == s[:len(t+tx)]:
      t += tx
      break
  else:
    print('NO')
    sys.exit()
print('YES')
Buggy python submission (verdict: Runtime Error):
s={i:list(input())for i in'abc'}
i='a'
while d[i]:i=s[i].pop(0)
print(i.upper())

Fixed submission:
s={i:list(input())for i in'abc'}
i='a'
while s[i]:i=s[i].pop(0)
print(i.upper())

Buggy python submission (verdict: Time Limit Exceeded):
import sys
sa=input()
sb=input()
sc=input()
ss={'a':sa,'b':sb,'c':sc}
t='a'
while True:
  t=ss[t][0]
  if len(ss[t])==0:
    print(t.upper())
    sys.exit()
  elif len(ss[t])==1:
    ss[t]==''
  else:
    ss[t]=ss[t][1:]


Fixed submission:
s={i:list(input())for i in'abc'}
i='a'
while s[i]:i=s[i].pop(0)
print(i.upper())

Buggy python submission (verdict: Time Limit Exceeded):
import sys
sa=input()
sb=input()
sc=input()
ss={'a':sa,'b':sb,'c':sc}
t='a'
while True:
  t=ss[t][0]
  if len(ss[t])==0:
    print(t.upper())
    sys.exit()
  elif len(ss[t])==1:
    ss[t]==''
  else: 
  	ss[t]=ss[t][1:]


Fixed submission:
s={i:list(input())for i in'abc'}
i='a'
while s[i]:i=s[i].pop(0)
print(i.upper())

Buggy python submission (verdict: Runtime Error):
import sys
sa=input()
sb=input()
sc=input()
ss={'a':sa,'b':sb,'c':sc}
t='a'
while True:
  t=ss[t][0]
  if len(ss[t])==0:
    print(t.upper())
    sys.exit()
  ss[t]=ss[t][1:]


Fixed submission:
s={i:list(input())for i in'abc'}
i='a'
while s[i]:i=s[i].pop(0)
print(i.upper())
Buggy python submission (verdict: Runtime Error):
import sys

input = sys.stdin.readline

def main(n):
	summ = 0
	for i in n:
		summ += int(i)
	if summ % 9 == 0: return "Yes"
	else: return "No"
	

n = input()
print(main(n))

Fixed submission:
def main(n):
	summ = 0
	for i in n:
		summ += int(i)
	if summ % 9 == 0: return "Yes"
	else: return "No"
	

n = input()
print(main(n))
Buggy python submission (verdict: Runtime Error):
st = input()
if st[0] == st[1] and st[0] == st[2] and st[0] == "R":
  print(3)
elif (st[0] == st[1] == "R") OR (st[1] == st[2] == "R"):
  print(2)
else:
  print(1)

Fixed submission:
st = input()
if st[0] == st[1] and st[0] == st[2] and st[0] == "R":
  print(3)
elif (st[0] == st[1] and st[0] == "R") or (st[1] == st[2] and st[1] == "R"):
  print(2)
elif "R" in st:
  print(1)
else:
  print(0)
Buggy python submission (verdict: Time Limit Exceeded):
# @uthor : Kaleab Asfaw
import sys

input = sys.stdin.readline

def product(lst):
    x = 1
    for i in lst:
        x *= i
    return x

def main(n, k, lst):
    prev = product(lst[:k])
    for i in range(n-k):
        curr = (prev / lst[i]) * lst[i+k]
        if curr > prev: print("Yes")
        else: print("No")
        prev = curr
    
    


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




Fixed submission:
# @uthor : Kaleab Asfaw
import sys

input = sys.stdin.readline

def main(n, k, lst):
    for i in range(n-k):
        if lst[i+k] > lst[i]:print("Yes")
        else: print("No")
        
    
n, k = list(map(int, input().split()))
lst = list(map(int, input().split()))
main(n, k, lst)
Buggy python submission (verdict: Runtime Error):
def check(s,t,n):
    if s.find(t) != -1:
        print(n)
    else:
        n += 1
        t = t[:-1]
        check(s,t,n)
s = input()
t = input()
n = 0
check(s,t,n)

Fixed submission:
main = input()
word = input()
temp = main
resultArray = []
final = len(word)
for j in range(len(main) - (len(word) - 1)):
    result = ''
    for i in range(len(word)):
        if main[j + i] == word[i]:
            result += '1'
        else:
            result += '0'
    resultArray.append(result)
for i in resultArray:
    if i.count('0') < final:
        final = i.count('0')
print(final)
Buggy python submission (verdict: Runtime Error):
K = int(input())
A,B = [int(i) for i in input().split()]
flag=0
for i in range(1,1001):
  if(iK>=A and iK<=B):
    print("OK")
    flag=1
    break
if (flag==0):
  print("NG")

Fixed submission:
K = int(input())
A,B = [int(i) for i in input().split()]
flag=0
for i in range(1,1001):
    if(i*K>=A and i*K<=B):
        print("OK")
        flag=1
        break
if (flag==0):
    print("NG")
Buggy python submission (verdict: Runtime Error):
n = input()
_list = input().split(" ")
_list = [int(x) for x in _list]
even = [x for x in _list if x % 2 == 0]
answer = []
for x in even:
    if x % 3 == 0 or x % 5 == 0:
        answer.append(True)
if len(even) == len(answer):
    print("APPROVED")
else:
    print("DENIED")

Fixed submission:
x, y, z = input().split()
if x == y != z or x == z != y or x != y == z:
    print('Yes')
else:
    print('No')

Buggy python submission (verdict: Runtime Error):
n = input()
_list = input().split(" ")
_list = [int(x) for x in _list]
even = [x for x in _list if x % 2==0]
answer = []
for x in even:
    if x % 3 == 0 or x % 5 == 0:
        answer.append(True)
if len(even) ==len(answer):
    print("APPROVED")
else:
    print("DENIED")

Fixed submission:
x, y, z = input().split()
if x == y != z or x == z != y or x != y == z:
    print('Yes')
else:
    print('No')
Buggy python submission (verdict: Runtime Error):
s, t = input().split() 
a, b = input().split() 
u = input()
int(a)
int(b)
if u == s:
    a = a-1
else:
    b = b-1
print(a+' '+b)

Fixed submission:
s, t = input().split() 
a, b = input().split() 
u = input()


if u == s:
    a = str(int(a)-1)
else:
    b = str(int(b)-1)

print(a+' '+b)
Buggy python submission (verdict: Runtime Error):
a,b = map(str,input().split())
c,d = map(int,input().split())
n = input()
if n == a:
    print(str(c-1)+" "+str(d))
else:
    print(str(c) + " " + str(d-1))

Fixed submission:
s = input()
m = ""
for i in s:
    m = m + i.replace(i, 'x')
print(m)
Buggy python submission (verdict: Runtime Error):
s = input()

if s = "ABC":
  print("ARC")
else:
  print("ABC")


Fixed submission:
s = input()

if s == "ABC":
  print("ARC")
else:
  print("ABC")
Buggy python submission (verdict: Runtime Error):
n,m = map(int,input().split())
h = list(map(int,input().split()))
#h.sort()
l = [[] for _ in range(n)]

for i in range(m):
  a,b = map(int,input().split())
  l[a-1].append(b-1)
  l[b-1].append(a-1)

print(l)
  av
c = 0
for j in range(n):
  if len(l[j]) == 0:
    c += 1
  else:
    m = 0
    for k in l[j]:
      if h[j] <= h[k]:
        m = 1
        break
    if m == 0:

      c += 1
      
print(c)
  

Fixed submission:
n,m = map(int,input().split())
h = list(map(int,input().split()))
#h.sort()
l = [[] for _ in range(n)]

for i in range(m):
  a,b = map(int,input().split())
  l[a-1].append(b-1)
  l[b-1].append(a-1)

c = 0
for j in range(n):
  if len(l[j]) == 0:
    c += 1
  else:
    m = 0
    for k in l[j]:
      if h[j] <= h[k]:
        m = 1
        break
    if m == 0:

      c += 1
      
print(c)

Buggy python submission (verdict: Runtime Error):
n,m = map(int,input().split())
h = list(map(int,input().split()))
#h.sort()

for i in range(m):
  a,b = map(int,input().split())
  l[a-1].append(b-1)
  l[b-1].append(a-1)

print(l)
  
c = 0
for j in range(n):
  if len(l[j]) == 0:
    c += 1
  else:
    m = 0
    for k in l[j]:
      if h[j] <= h[k]:
        m = 1
        break
    if m == 0:

      c += 1
      
print(c)
  

Fixed submission:
n,m = map(int,input().split())
h = list(map(int,input().split()))
#h.sort()
l = [[] for _ in range(n)]

for i in range(m):
  a,b = map(int,input().split())
  l[a-1].append(b-1)
  l[b-1].append(a-1)

c = 0
for j in range(n):
  if len(l[j]) == 0:
    c += 1
  else:
    m = 0
    for k in l[j]:
      if h[j] <= h[k]:
        m = 1
        break
    if m == 0:

      c += 1
      
print(c)
Buggy python submission (verdict: Runtime Error):
x = int(input())

m = 2*10**9
l = []

a = 0
b = 0
while b <= m:
  b = a**5
  l.append(b)
  a += 1
  
flg = 0
for i in range(len(l)):
  if flg == 1:
    break
  for j in range(i+1,len(l)):
    if l[i] + l[j] == x:
      res = [i,-j]
      flg = 1
      break
    elif l[i] - l[j] == x:
      res = [i,j]
      flg = 1
      break

print(res[0],res[1])
    

Fixed submission:
x = int(input())

m = 2*10**9
l = []

a = 0
b = 0
p = 0
#while b <= m:
while p < 1000:
  b = a**5
  l.append(b)
  a += 1
  p += 1


flg = 0
for i in range(len(l)):
  
  if flg == 1:
    break
  for j in range(i+1,len(l)):
    if l[i] + l[j] == x:
      res = [i,-j]
      flg = 1
      break
    elif l[i] - l[j] == x:
      res = [i,j]
      flg = 1
      break
    elif -l[i] + l[j] == x:
      res = [-i,-j]
      flg = 1
      break
    elif -l[i] - l[j] == x:
      res = [-i,j]
      flg = 1
      break
      
      
print(res[0],res[1])
Buggy python submission (verdict: Runtime Error):
n = int(input())
a = list(map(int,input().split()))

b = a[:]
b.sort()

c = [[]for _ in range(n+1)]

ct = 1
tmp = b[1]
sum = 0
for j in range(1,n):
  if b[j] == b[j-1]:
    ct += 1
  else :  
    c[tmp].append(ct)
    cm = int(ct*(ct-1)/2)
    c[tmp].append(cm)
    cm1 = int((ct-1)*(ct-2)/2)
    c[tmp].append(cm1)
    sum += cm
    tmp = b[j]
    ct = 1

c[tmp].append(ct)
cm = int(ct*(ct-1)/2)
c[tmp].append(cm)
cm1 = int((ct-1)*(ct-2)/2)
c[tmp].append(cm1)
sum += cm      

for k in a:
  print(sum-c[k][1] + c[k][2])

Fixed submission:
n = int(input())
a = list(map(int,input().split()))

b = a[:]
b.sort()

c = [[ 0 for _ in range(3)] for _ in range(n+1)]

ct = 1
tmp = b[1]
sum = 0
for j in range(1,n):
  if b[j] == b[j-1]:
    ct += 1
  else :  
    c[tmp][0] = ct
    cm = int(ct*(ct-1)/2)
    c[tmp][1] = cm
    cm1 = int((ct-1)*(ct-2)/2)
    c[tmp][2] = cm1
    sum += cm
    tmp = b[j]
    ct = 1

c[tmp][0] = ct
cm = int(ct*(ct-1)/2)
c[tmp][1] = cm
cm1 = int((ct-1)*(ct-2)/2)
c[tmp][2] = cm1
sum += cm      

for k in a:
  print(sum-c[k][1] + c[k][2])
Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np
A,B,M = map(int,input().rstrip().split())
a = list(map(int,input().rstrip().split()))
b = list(map(int,input().rstrip().split()))

suml = [[0 for _ in range(len(b))] for _ in range(len(a))]

for i in range(len(a)):
  for j in range(len(b)):
    suml[i][j] = a[i]+b[j]



sumk = [[0 for _ in range(len(b))] for _ in range(len(a))]

for k in range(M):
  i,j,c = list(map(int,input().rstrip().split()))
  if sumk[i-1][j-1] != 0:
    sumk[i-1][j-1] = max(sumk[i-1][j-1],c)
  else:
    sumk[i-1][j-1] = c

x = np.array(suml)
y = np.array(sumk)

z = x - y

print(np.amin(z))
    

Fixed submission:
import numpy as np
A,B,M = map(int,input().rstrip().split())
a = list(map(int,input().rstrip().split()))
b = list(map(int,input().rstrip().split()))

minp = min(a) + min(b)

minpp = 10**6
for k in range(M):
  i,j,c = map(int,input().rstrip().split())
  minpp = min(a[i-1]+b[j-1]-c,minpp)

print(min(minp,minpp))
Buggy python submission (verdict: Runtime Error):
if S[0] == S[1] == S[2]:
  print('No')
else:
  print('Yes')

Fixed submission:
S = list(input())

if S[0] == S[1] == S[2]:
  print('No')
else:
  print('Yes')
Buggy python submission (verdict: Runtime Error):
n = int(input())

s = []
for i in range(n):
  s.append(input())
  
s.sort()

print(s)
t =[]
count = 1
for i in range(1,n):
  if s[i-1] == s[i] and i != n-1:
    count+=1
  elif s[i-1] == s[i] and i == n-1:
    count += 1
    t.append([s[i-1],count])
  elif i == n-1:
    t.append([s[i-1],1])
  else:
    t.append([s[i-1],count])
    count = 1

t.sort(key=lambda x:x[1])

for j in range(len(t)-1,0,-1):
  if t[j][1] != t[j-1][1]:
    k = j
    break
for b in range(k,len(t)):
  print(t[b][0])

Fixed submission:
n = int(input())

s = []
for i in range(n):
  s.append(input())
  
s.sort()
t =[]
count = 1
for i in range(1,n):
  if s[i-1] == s[i] and i != n-1:
    count+=1
  elif s[i-1] == s[i] and i == n-1:
    count += 1
    t.append([s[i-1],count])
  elif i == n-1:
    t.append([s[i-1],1])
    t.append([s[i],1])
    
  else:
    t.append([s[i-1],count])
    count = 1

t.sort(key=lambda x:x[1])
ma = t[len(t)-1][1]

for i in range(len(t)):
  if t[i][1] == ma:
    print(t[i][0])
Buggy python submission (verdict: Runtime Error):
N = input().rstrip()
n = N[0]
k = N[1]

h = list(map(int,input().split()))
h.sort(reverse=True)

m = 0
hit = 0
if k >= n :
  m = n
else:
  for i in range(k,n):
    hit += h[i]
  
  m = k + hit
  
print(m)

Fixed submission:
N = list(map(int,input().rstrip().split()))
n = N[0]
k = N[1]

h = list(map(int,input().split()))
h.sort(reverse=True)

m = 0
hit = 0
if k >= n :
  m = 0
else:
  for i in range(k,n):
    hit += h[i]
  
  m = hit
print(m)
Buggy python submission (verdict: Time Limit Exceeded):
n,k,q = map(int,input().split())

a = []
for i in range(q):
  a.append(int(input()))

p = [k for _ in range(n)]

for s in a:
  p = list(map(lambda x: x -1, p))
  p[s-1] = p[s-1] + 1

for i in p:
  if i > 0:
    print('Yes')
  else:
    print('No')

Fixed submission:
n,k,q = map(int,input().split())

a = []
for i in range(q):
  a.append(int(input()))

p = [k for _ in range(n)]
p = list(map(lambda x: x -q, p))
for s in a:
  
  p[s-1] = p[s-1] + 1

for i in p:
  if i > 0:
    print('Yes')
  else:
    print('No')