Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
from collections import defaultdict

N = int(input())
a = [int(i) for i in input().split()]

b = defaultdict(lambda : [float('inf'), 0])
for i in range(N) :
    b[a[i]][0] = min(b[a[i]][0], i)
    b[a[i]][1] += 1

# [value, first_appearance, count]
c = [(0, 0, 0)]
for k, v in b.items() :
    c.append((k, *v))
c.sort()

ret = [0] * N
pre_v, pre_i, pre_c = c.pop()
while c :
    cur_v, cur_i, cur_c = c.pop()
    ret[pre_i] = (pre_v - cur_v) * pre_c
    cur_c += pre_c
    pre_v, pre_i, pre_c = cur_v, cur_i, cur_c
    
for r in ret :
    print(r)

Fixed submission:
from collections import defaultdict

N = int(input())
a = [int(i) for i in input().split()]

b = defaultdict(lambda : [float('inf'), 0])
for i in range(N) :
    b[a[i]][0] = min(b[a[i]][0], i)
    b[a[i]][1] += 1

# [value, first_appearance, count]
c = [(0, 0, 0)]
for k, v in b.items() :
    c.append((k, v[0], v[1]))
c.sort()

ret = [0] * N
pre_v, pre_i, pre_c = c.pop()
while c :
    cur_v, cur_i, cur_c = c.pop()
    ret[pre_i] += (pre_v - cur_v) * pre_c
    cur_c += pre_c
    pre_v, pre_i, pre_c = cur_v, min(pre_i, cur_i), cur_c
    
for r in ret :
    print(r)
Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**5)

N = int(input())
v = [[] for _ in range(N)]
for i in range(N - 1) :
    a = int(input())
    v[a-1].append(i + 1)

def rec(cur) :
    ret = []
    for nex in v[cur] :
        ret.append(rec(nex))
    ret.sort(reverse=True)
    if len(ret) == 0 :
        return 0
    return max([i + 1 + ret[i] for i in range(len(ret))])
    
print(rec(0))


Fixed submission:
import sys
input = sys.stdin.readline

N = int(input())
v = [[] for _ in range(N)]
for i in range(N - 1) :
    a = int(input())
    v[a-1].append(i + 1)

l = [0]
i = 0
while i < len(l) :
    cur = l[i]
    for nex in v[cur] :
        l.append(nex)
    i += 1

dp = [0] * N
while len(l) > 0 :
    cur = l.pop()
    ret = []
    for nex in v[cur] :
        ret.append(dp[nex])
    
    if len(ret) == 0 :
        continue
        
    ret.sort(reverse=True)
    dp[cur] = max([i + 1 + ret[i] for i in range(len(ret))])
    
print(dp[0])

Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**5)

N = int(input())
v = [[] for _ in range(N)]
for i in range(N - 1) :
    a = int(input())
    v[a-1].append(i + 1)

def rec(cur) :
    ret = sorted([rec(nex) for nex in v[cur]], reverse=True)
    if len(ret) == 0 :
        return 0
    return max([i + 1 + ret[i] for i in range(len(ret))])
    
print(rec(0))

Fixed submission:
import sys
input = sys.stdin.readline

N = int(input())
v = [[] for _ in range(N)]
for i in range(N - 1) :
    a = int(input())
    v[a-1].append(i + 1)

l = [0]
i = 0
while i < len(l) :
    cur = l[i]
    for nex in v[cur] :
        l.append(nex)
    i += 1

dp = [0] * N
while len(l) > 0 :
    cur = l.pop()
    ret = []
    for nex in v[cur] :
        ret.append(dp[nex])
    
    if len(ret) == 0 :
        continue
        
    ret.sort(reverse=True)
    dp[cur] = max([i + 1 + ret[i] for i in range(len(ret))])
    
print(dp[0])
Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline

N, K, L = map(int, input().split())

vec1, vec2 = [[] for _ in range(N)], [[] for _ in range(N)]

for _ in range(K) :
    p, q = map(int, input().split())
    vec1[p-1].append(q-1)
    vec1[q-1].append(p-1)
for _ in range(L) :
    r, s = map(int, input().split())
    vec2[r-1].append(s-1)
    vec2[s-1].append(r-1)

def bfs(v) :
    visited = [-1] * N
    ret = []
    n = 0
    for i in range(N) :
        if visited[i] < 0 :
            queue = [i]
            visited[i] = n
            j = 0
            while j < len(queue) :
                cur = queue[j]
                for nex in v[cur] :
                    if visited[nex] < 0 :
                        queue.append(nex)
                        visited[nex] = n
                j += 1
                
            ret.append(set(queue))
            n += 1
            
    return ret, visited
    
ret1, visited1 = bfs(vec1)
ret2, visited2 = bfs(vec2)
ret = [str(len(ret1[visited1[i]] & ret2[visited2[i]])) for i in range(N)]

print(' '.join(ret))

Fixed submission:
from collections import Counter
import sys
input = sys.stdin.readline

N, K, L = map(int, input().split())

vec1, vec2 = [[] for _ in range(N)], [[] for _ in range(N)]

for _ in range(K) :
    p, q = map(int, input().split())
    vec1[p-1].append(q-1)
    vec1[q-1].append(p-1)
for _ in range(L) :
    r, s = map(int, input().split())
    vec2[r-1].append(s-1)
    vec2[s-1].append(r-1)

def bfs(v) :
    visited = [-1] * N
    n = 0
    for i in range(N) :
        if visited[i] < 0 :
            queue = [i]
            visited[i] = n
            j = 0
            while j < len(queue) :
                cur = queue[j]
                for nex in v[cur] :
                    if visited[nex] < 0 :
                        queue.append(nex)
                        visited[nex] = n
                j += 1
            n += 1
            
    return visited
    
visited1 = bfs(vec1)
visited2 = bfs(vec2)
p = [(visited1[i], visited2[i]) for i in range(N)]
c = Counter(p)

print(' '.join([str(c[p[i]]) for i in range(N)]))
Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**5)

N, M = map(int, input().split())
KL = [[int(i) for i in input().split()] for _ in range(N)]

lang = [[] for _ in range(M)]
for i in range(N) :
    for j in KL[i][1:] :
        lang[j-1].append(i)
        
visited = [False] * N
visited[0] = True
q = [0]
while q :
    cur = q.pop()
    for l in KL[cur][1:] :
        for m in lang[l-1] :
            if not visited[m] :
                q.append(m)
                visited[m] = True
                
if sum(visited) == N :
    print('YES')
else :
    print('NO')

Fixed submission:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**5)

N, M = map(int, input().split())
v = [[] for _ in range(N+M)]
for i in range(N) :
    K, *L = map(int, input().split())
    for l in L :
        v[N+l-1].append(i)
        v[i].append(N+l-1)

visited = [False] * (N + M)
visited[0] = True
q = [0]

while q :
    cur = q.pop()
    for nex in v[cur] :
        if not visited[nex] :
            q.append(nex)
            visited[nex] = True

if sum(visited[:N]) == N :
    print('YES')
else :
    print('NO')
Buggy python submission (verdict: Time Limit Exceeded):
s = input()
N = len(s)

# dp[何文字目][パーを出した回数]
dp = [[0] * (N // 2 + 1) for _ in range(N + 1)]
for i in range(1, N + 1) :
    p = (s[i-1] == 'p')
    dp[i][0] = dp[i-1][0] - (1 if p else 0)
    for j in range(1, i // 2 + 1) :
        dp[i][j] = max(dp[i-1][j-1] + (0 if p else 1), dp[i-1][j] - (1 if p else 0))
        
        
print(max(dp[-1]))

Fixed submission:
s = input()

ret = 0
g, p = 0, 0
for s_ in s :
    if s_ == 'g' :
        if p < g :
            p += 1
            ret += 1
        else :
            g += 1
    else :
        if p < g :
            p += 1
        else :
            g += 1
            ret -= 1
            
print(ret)
Buggy python submission (verdict: Time Limit Exceeded):
s = [ord(i) for i in input()]
K = int(input())

ret = ''
for c in s[:-1] :
    if c == 97 :
        ret += 'a'
        continue
        
    if c + K > 122 :
        ret += 'a'
        K -= 123 - c
    else :
        ret += chr(c)
        
K %= 26
ret += chr((s[-1] + K - 97) % 26 + 97)
        
print(ret)

Fixed submission:
s = [ord(i) for i in input()]
K = int(input())

ret = []
for c in s[:-1] :
    if c == 97 :
        ret.append('a')
        continue
        
    if c + K > 122 :
        ret.append('a')
        K -= 123 - c
    else :
        ret.append(chr(c))
        
K %= 26
ret.append(chr((s[-1] + K - 97) % 26 + 97))
        
print(''.join(ret))

Buggy python submission (verdict: Time Limit Exceeded):
s = input()
K = int(input())

ret = ''
for i, c in enumerate(s) :
    if i == len(s) - 1 :
        K %= 26
        if ord(c) + K > 122 :
            ret += chr(ord(c) + K - 26)
        else :
            ret += chr(ord(c) + K)
    
    elif ord(c) + K > 122 :
        ret += 'a'
        K -= 123 - ord(c)
    else :
        ret += c
        
print(ret)

Fixed submission:
s = [ord(i) for i in input()]
K = int(input())

ret = []
for c in s[:-1] :
    if c == 97 :
        ret.append('a')
        continue
        
    if c + K > 122 :
        ret.append('a')
        K -= 123 - c
    else :
        ret.append(chr(c))
        
K %= 26
ret.append(chr((s[-1] + K - 97) % 26 + 97))
        
print(''.join(ret))
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
sum_N = 0

for i in range(len(str(N))):
  sum_N += int(str(N)[i])
  
if sum_N % 9 == 0:
  print("Yes")
else:
  print("No")

Fixed submission:
N = int(input())
sum_N = 0
S = str(N)

for i in range(len(S)):
  sum_N += int(S[i])
  
if sum_N % 9 == 0:
  print("Yes")
else:
  print("No")
Buggy python submission (verdict: Time Limit Exceeded):
K = int(input())

if K % 2 == 0 or K % 5 == 0:
  print(-1)
else:
  if K % 7 == 0:
    L = 9 * K // 7
  else:
    L = 9 * K
  a = 10 % L
  check = False
  for i in range(L):
    if a % L == 1:
      print(i + 1)
      check = True
      break
    a *= 10
  if not check:
    print(-1)

Fixed submission:
K = int(input())

if K % 2 == 0 or K % 5 == 0:
  print(-1)
else:
  if K % 7 == 0:
    L = 9 * K // 7
  else:
    L = 9 * K
  a = 10 % L
  check = False
  for i in range(L):
    a %= L
    if a == 1:
      print(i + 1)
      check = True
      break
    a *= 10
  if not check:
    print(-1)

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

if K % 2 == 0　or K % 5 == 0:
  print(-1)
else:
  if K % 7 == 0:
    L = 9 * K // 7
  else:
    L = 9 * K
  a = 10 % L
  check = False
  for i in range(L):
    a %= L
    if a == 1:
      print(i + 1)
      check = True
      break
    a *= 10
  if not check:
    print(-1)

Fixed submission:
K = int(input())

if K % 2 == 0 or K % 5 == 0:
  print(-1)
else:
  if K % 7 == 0:
    L = 9 * K // 7
  else:
    L = 9 * K
  a = 10 % L
  check = False
  for i in range(L):
    a %= L
    if a == 1:
      print(i + 1)
      check = True
      break
    a *= 10
  if not check:
    print(-1)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
C = list(input())

ans = float("inf")
for i in range(N+1):
  w = C[:i].count("W")
  r = C[i:].count("R")
  ans = min(ans, max(w,r))
  
print(ans)

Fixed submission:
N = int(input())
C = list(input())

W = C.count("W")
R = C.count("R")
w = 0
r = R

ans = R
for i in range(1,N+1):
  if C[i-1] == "W":
    w += 1
  else:
    r -= 1
  ans = min(ans, max(w,r))
  
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N,K = map(int,input().split())
A = list(map(int,input().split()))

score = [1 for _ in range(N)]
for i in range(K-1,N):
  for j in range(K):
    score[i] *= A[i-j]
  
for k in range(K-1,N-1):
  if score[k] < score[k+1]:
    print("Yes")
  else:
    print("No")

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

for i in range(K-1,N-1):
  if A[i+1-K] < A[i+1]:
    print("Yes")
  else:
    print("No")

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

score = [1 for _ in range(N)]
for i in range(K-1,N):
  for j in range(K):
    score[i] *= A[i-j]
  
for k in range(K-1,N-1):
  if score[k] < score[k+1]:
    print("Yes")
  else:
    print("No")

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

for i in range(K-1,N-1):
  if A[i+1-K] < A[i+1]:
    print("Yes")
  else:
    print("No")
Buggy python submission (verdict: Runtime Error):
N = int(input())
A = list(map(int,input().split()))
my_money = 1000
stock = 0

ls = []
if A[0] < A[1]:
  ls.append(A[0])
for i in range(1,N-1):
  if A[i] == A[i-1]:
    continue
  elif A[i-1] < A[i] <= A[i+1]:
    continue
  elif A[i-1] > A[i] >= A[i+1]:
    continue
  ls.append(A[i])  
if A[-1] > A[-2]:
  ls.append(A[-1])
    
if ls == []:
  print(1000)
else:
  for i,j in enumerate(ls_1):
    if i%2 == 0:
      stock += my_money//j
      my_money %= j
    else:
      my_money += stock*j
      stock = 0
  print(my_money)

Fixed submission:
N = int(input())
A = list(map(int,input().split()))
money = 1000
stock = 0

for i in range(N-1):
  if A[i] < A[i+1]:
    stock = money // A[i]
    money += stock * (A[i+1] - A[i])
    
print(money)
Buggy python submission (verdict: Runtime Error):
N = int(input())
A = list(map(int,input().split()))

A = sorted(A,reverse=True)

if N <= 3:
  print(sum(A[:-1]))
elif N % 2 == 0:
  ans = A[0] + sum(A[1:N//2])*2
elif N % 2 == 1:
  ans = A[0] + sum(A[1:N//2])*2 + A[1+N//2]
  
print(ans)

Fixed submission:
N = int(input())
A = list(map(int,input().split()))
A = sorted(A,reverse=True)

ans = A[0]

for i in range(1,(N-2)//2+1):
  ans += A[i]*2
  
if N % 2 == 1:
  ans += A[(N-2)//2 + 1]

print(ans)
Buggy python submission (verdict: Runtime Error):
N,M,K = map(int,input().split())
A = list(map(int,input().split()))
B = list(map(int,input().split()))

A_dp = [0] * (N + 1)
B_dp = [0] * (M + 1)

for i in range(1,N+1):
  if i == 1:
    A_dp[i] += A[i-1]
    continue
  A_dp[i] += A_dp[i-1] + A[i-1]
  
for j in range(1,M+1):
  if j == 1:
    B_dp[j] += B[j-1]
    continue
  B_dp[j] += B_dp[j-1] + B[j-1]
  
a = N
b = 0

minute = A_dp[a] + B_dp[b]
if K > minute:
  while K >= A_dp[a] + B_dp[b]:
    b += 1
else:
  while K < A_dp[a] + B_dp[b]:
    a -= 1
  
cnt = a + b
for k in range(a,-1,-1):
  while A_dp[k] + B_dp[b] < K:
    if b == M - 1:
      break
    b += 1
  b -= 1
  if cnt < k + b:
    cnt = k + b
    
print(cnt)

Fixed submission:
N,M,K = map(int,input().split())
A = list(map(int,input().split()))
B = list(map(int,input().split()))

A_dp = [0] * (N + 1)
B_dp = [0] * (M + 1)

for i in range(1,N+1):
  if i == 1:
    A_dp[i] += A[i-1]
    continue
  A_dp[i] += A_dp[i-1] + A[i-1]
  
for j in range(1,M+1):
  if j == 1:
    B_dp[j] += B[j-1]
    continue
  B_dp[j] += B_dp[j-1] + B[j-1]
  
cnt = 0
j = M

for i in range(N+1):
  if A_dp[i] > K:
    continue
  while A_dp[i] + B_dp[j] > K:
    j -= 1
  cnt = max(cnt, i+j)
  
print(cnt)
Buggy python submission (verdict: Runtime Error):
N = int(input())
chars = "Xabcdefghijklmnopqrstuvwxyz"  # x番目がほしいときにchars[x-1]としたくないので、chars[0]は使わないことにします

n_rem = n  # 入力を直接操作すると、もし後々必要になったときに面倒なので
res = ""
while True:
  x = n_rem % 26
  if x == 0:
    x = 26
  res += chars[x]
  n_rem -= x
  
  if n_rem == 0:
    break
  n_rem //= 26
print(res[::-1])

Fixed submission:
n = int(input())
chars = "Xabcdefghijklmnopqrstuvwxyz"  # x番目がほしいときにchars[x-1]としたくないので、chars[0]は使わないことにします

n_rem = n  # 入力を直接操作すると、もし後々必要になったときに面倒なので
res = ""
while True:
  x = n_rem % 26
  if x == 0:
    x = 26
  res += chars[x]
  n_rem -= x
  
  if n_rem == 0:
    break
  n_rem //= 26
print(res[::-1])

Buggy python submission (verdict: Runtime Error):
N = int(input())
chars = "Xabcdefghijklmnopqrstuvwxyz"  # x番目がほしいときにchars[x-1]としたくないので、chars[0]は使わないことにします

n_rem = n  # 入力を直接操作すると、もし後々必要になったときに面倒なので
res = ""
while True:
  x = N % 26
  if x == 0:
    x = 26
  res += chars[x]
  n_rem -= x
  
  if n_rem == 0:
    break
  n_rem //= 26
print(res[::-1])

Fixed submission:
n = int(input())
chars = "Xabcdefghijklmnopqrstuvwxyz"  # x番目がほしいときにchars[x-1]としたくないので、chars[0]は使わないことにします

n_rem = n  # 入力を直接操作すると、もし後々必要になったときに面倒なので
res = ""
while True:
  x = n_rem % 26
  if x == 0:
    x = 26
  res += chars[x]
  n_rem -= x
  
  if n_rem == 0:
    break
  n_rem //= 26
print(res[::-1])
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = input()
Q = int(input())
for _ in range(Q):
  B,C = input().split()
  A = A.replace(B,C)
  S = [int(a) for a in list(A.split())]
  print(sum(S))


Fixed submission:
from collections import Counter

n = int(input())
a = list(map(int, input().split()))
q = int(input())

counter = Counter(a)
sum_res = sum(a)  # はじめの合計、名前がsumだとsum関数とかぶってよくないので

# q回操作します。ループ変数は使わないので_とします（Pythonの慣習）
for _ in range(q):
    before, after = map(int, input().split())

    # 合計を変更します
    sum_res -= before * counter[before]
    sum_res += after * counter[before]

    # 個数を変更します
    counter[after] += counter[before]
    counter[before] = 0

    print(sum_res)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = input()
Q = int(input())
for _ in range(Q):
  B,C = input().split()
  A = A.replace(B,C)
  S = [int(a) for a in list(A.split())]
  print(sum(S))


Fixed submission:
from collections import Counter

n = int(input())
a = list(map(int, input().split()))
q = int(input())

counter = Counter(a)
sum_res = sum(a)  # はじめの合計、名前がsumだとsum関数とかぶってよくないので

# q回操作します。ループ変数は使わないので_とします（Pythonの慣習）
for _ in range(q):
    before, after = map(int, input().split())

    # 合計を変更します
    sum_res -= before * counter[before]
    sum_res += after * counter[before]

    # 個数を変更します
    counter[after] += counter[before]
    counter[before] = 0

    print(sum_res)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = input()
Q = int(input())
for _ in range(Q):
  B,C = input().split()
  A = A.replace(B,C)
  S = 0
  listA = list(A.split())
  for a in listA:
    S += int(a)
  print(S)


Fixed submission:
from collections import Counter

n = int(input())
a = list(map(int, input().split()))
q = int(input())

counter = Counter(a)
sum_res = sum(a)  # はじめの合計、名前がsumだとsum関数とかぶってよくないので

# q回操作します。ループ変数は使わないので_とします（Pythonの慣習）
for _ in range(q):
    before, after = map(int, input().split())

    # 合計を変更します
    sum_res -= before * counter[before]
    sum_res += after * counter[before]

    # 個数を変更します
    counter[after] += counter[before]
    counter[before] = 0

    print(sum_res)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = input()
Q = int(input())
for _ in range(Q):
  B,C = input().split()
  A = A.replace(B,C)
  S = 0
  listA = list(A.split())
  for a in listA:
    S += int(a)
  print(S)


Fixed submission:
from collections import Counter

n = int(input())
a = list(map(int, input().split()))
q = int(input())

counter = Counter(a)
sum_res = sum(a)  # はじめの合計、名前がsumだとsum関数とかぶってよくないので

# q回操作します。ループ変数は使わないので_とします（Pythonの慣習）
for _ in range(q):
    before, after = map(int, input().split())

    # 合計を変更します
    sum_res -= before * counter[before]
    sum_res += after * counter[before]

    # 個数を変更します
    counter[after] += counter[before]
    counter[before] = 0

    print(sum_res)
Buggy python submission (verdict: Runtime Error):
import math
A,B,N = map(int,input().split())

if B > N:
  ans = math.floor(A * N / B) - A * math.floor(N // B)
else:
  ans = math.floor(A * (B - 1) / B) - A * math.floor(N // (B - 1))
  
print(ans)

Fixed submission:
import math
A,B,N = map(int,input().split())

if B > N:
  ans = math.floor(A * N / B)
else:
  ans = math.floor(A * (B - 1) / B)
  
print(ans)

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

if B > N:
  ans = (A * N) // B - A * (N // B)
else:
  ans = (A * (B - 1)) // B - A * (N // (B - 1))
  
print(ans)

Fixed submission:
import math
A,B,N = map(int,input().split())

if B > N:
  ans = math.floor(A * N / B)
else:
  ans = math.floor(A * (B - 1) / B)
  
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
from math import gcd
from functools import reduce

def gcd_list(lis):
  return reduce(gcd, lis)

K = int(input())

ans = 0
for i in range(1,K+1):
  for j in range(1,K+1):
    for k in range(1,K+1):
      ans += gcd_list([i,j,k])
      
print(ans)

Fixed submission:
from math import gcd
from functools import reduce

def gcd_list(lis):
  return reduce(gcd, lis)

K = int(input())

ans = 0
for i in range(1,K+1):
  for j in range(1,K+1):
    for k in range(1,K+1):
      ans += gcd_list([i,j,k])
      
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = list(map(int,input().split()))
ls = [0] * (N + 1)

C = 0
for i in set(A):
  n = A.count(i)
  ls[i] += n
  C += n * (n - 1) //2
  
for a in A:
  n = ls[a]
  print(C - (n - 1))

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

ls = [0] * (N + 1)
for a in A:
  ls[a] += 1

C = 0
for i in set(A):
  n = ls[i]
  C += n * (n - 1) //2
  
for a in A:
  n = ls[a]
  print(C - (n - 1))

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

C = 0
for i in set(A):
  n = A.count(i)
  ls[i] += n
  C += n * (n - 1) //2
  
for a in A:
  n = ls[a]
  print(C - (n - 1))

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

ls = [0] * (N + 1)
for a in A:
  ls[a] += 1

C = 0
for i in set(A):
  n = ls[i]
  C += n * (n - 1) //2
  
for a in A:
  n = ls[a]
  print(C - (n - 1))

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

C = 0
for i in set(A):
  n = A.count(i)
  C += n * (n - 1) //2
  
for a in A:
  n = A.count(a)
  print(C - (n - 1))

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

ls = [0] * (N + 1)
for a in A:
  ls[a] += 1

C = 0
for i in set(A):
  n = ls[i]
  C += n * (n - 1) //2
  
for a in A:
  n = ls[a]
  print(C - (n - 1))

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

C = 0
for i in set(A):
  n = A.count(i)
  C += n * (n - 1) //2
  
for a in A:
  n = A.count(a)
  print(C - (n - 1))

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

ls = [0] * (N + 1)
for a in A:
  ls[a] += 1

C = 0
for i in set(A):
  n = ls[i]
  C += n * (n - 1) //2
  
for a in A:
  n = ls[a]
  print(C - (n - 1))
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
ls = []
cnt = []

for _ in range(N):
  S = input()
  if S in ls:
    cnt[ls.index(S)] += 1
    continue
  
  ls.append(S)
  cnt.append(1)
  
max_cnt = max(cnt)

res = []
for i,j in zip(ls,cnt):
  if j == max_cnt:
    res.append(i)
    
res.sort()
for ans in res:
  print(ans)

Fixed submission:
N = int(input())
index = {}

for _ in range(N):
  S = input()
  if S not in index: index[S] = 1
  else: index[S] += 1

max_cnt = max(index.values())

ls = [key for key in index.keys() if index[key] == max_cnt]

ls.sort()
for ans in ls:
  print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
ls = []
cnt = []

for _ in range(N):
  S = input()
  if S in ls:
    cnt[ls.index(S)] += 1
    continue
  
  ls.append(S)
  cnt.append(1)
  
max_cnt = max(cnt)

res = []
for i,j in zip(ls,cnt):
  if j == max_cnt:
    res.append(i)
    
res.sort()
for ans in res:
  print(ans)

Fixed submission:
N = int(input())
index = {}

for _ in range(N):
  S = input()
  if S not in index: index[S] = 1
  else: index[S] += 1

max_cnt = max(index.values())

ls = [key for key in index.keys() if index[key] == max_cnt]

ls.sort()
for ans in ls:
  print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = list(map(int,input().split()))

check = True
for i in range(N):
  if A.count(A[i]) > 1:
    check = False
    
print("YES" if check else "NO")

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

check = True
for i in range(N-1):
  if A[i] == A[i+1]:
    check = False
    
print("YES" if check else "NO")

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

check = True
for i in range(A):
  if A.count(A[i]) > 1:
    check = False
    
print("Yes" if check else "No")

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

check = True
for i in range(N-1):
  if A[i] == A[i+1]:
    check = False
    
print("YES" if check else "NO")
Buggy python submission (verdict: Runtime Error):
a,b = int(input())
ls = [str(a) * b, str(b) * a]
ls.sort()
print(ls[0])

Fixed submission:
a,b = map(int,input().split())
ls = [str(a) * b, str(b) * a]
ls.sort()
print(ls[0])