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

possible_water = []
for i in range(31):
    for j in range(31):
        water = 100*a*i + 100*b*j
        if 0 < water <= f:
            possible_water.append(water)
pw = list(set(possible_water))

possible_sugar = []
for i in range(3001):
    for j in range(3001):
        sugar = c*i + d*j
        if 0 < sugar <= f:
            possible_sugar.append(sugar)
ps = list(set(possible_sugar))

ans = []
for i in pw:
    for j in ps:
        if i + j <= f and j <= (i//100)*e:
            c = 100*j/(i+j)
            ans.append([c,i+j,j])

ans.sort(reverse=True)
print(ans[0][1],ans[0][2])

Fixed submission:
a,b,c,d,e,f = map(int,(input().split()))

possible_water = []
for i in range(31):
    for j in range(31):
        water = 100*a*i + 100*b*j
        if 0 < water <= f:
            possible_water.append(water)
pw = list(set(possible_water))

possible_sugar = []
for i in range(3001):
    for j in range(3001):
        sugar = c*i + d*j
        if sugar <= f:
            possible_sugar.append(sugar)
ps = list(set(possible_sugar))

ans = []
for i in pw:
    for j in ps:
        if i + j <= f and j <= (i//100)*e:
            c = 100*j/(i+j)
            ans.append([c,i+j,j])

ans.sort(reverse=True)
print(ans[0][1],ans[0][2])

Buggy python submission (verdict: Runtime Error):
a,b,c,d,e,f = map(int,(input().split()))

possible_water = []
for i in range(31):
    for j in range(31):
        water = 100*a*i + 100*b*j
        if 0 < water <= f:
            possible_water.append(water)
pw = list(set(possible_water))

possible_sugar = []
for i in range(3001):
    for j in range(3001):
        sugar = c*i + 100*d*j
        if 0 < sugar <= f:
            possible_sugar.append(sugar)
ps = list(set(possible_sugar))

ans = []
for i in pw:
    for j in ps:
        if i + j <= f and j <= (i//100)*e:
            c = 100*j/(i+j)
            ans.append([c,i+j,j])

ans.sort(reverse=True)
print(ans[0][1],ans[0][2])

Fixed submission:
a,b,c,d,e,f = map(int,(input().split()))

possible_water = []
for i in range(31):
    for j in range(31):
        water = 100*a*i + 100*b*j
        if 0 < water <= f:
            possible_water.append(water)
pw = list(set(possible_water))

possible_sugar = []
for i in range(3001):
    for j in range(3001):
        sugar = c*i + d*j
        if sugar <= f:
            possible_sugar.append(sugar)
ps = list(set(possible_sugar))

ans = []
for i in pw:
    for j in ps:
        if i + j <= f and j <= (i//100)*e:
            c = 100*j/(i+j)
            ans.append([c,i+j,j])

ans.sort(reverse=True)
print(ans[0][1],ans[0][2])
Buggy python submission (verdict: Runtime Error):
N = int(input())
a = list(map(int,(input().split())))
from collections import Counter
c = Counter(a)
L = []
LL = []
for k in c.keys():
    if c[k] >= 2:
        L.append(k)
    if c[k] >= 4:
        LL.append(k)
if LL:
    M = max(LL)**2

if len(L) < 2:
    print(0)
else:
    L.sort(reverse=True)
    print(max(L[0]*L[1],M))

Fixed submission:
N = int(input())
a = list(map(int,(input().split())))
from collections import Counter
c = Counter(a)
L = []
LL = []
for k in c.keys():
    if c[k] >= 2:
        L.append(k)
    if c[k] >= 4:
        LL.append(k)
M = 0 
if LL:
    M = max(LL)**2
if len(L) < 2:
    print(0)
else:
    L.sort(reverse=True)
    print(max(L[0]*L[1],M))
Buggy python submission (verdict: Runtime Error):
N = int(input())
tree = [[] for _ in range(N)]
for i in range(N-1):
    a,b,c = map(int,input().split())
    tree[a-1].append((b-1,c))
    tree[b-1].append((a-1,c))

Q,K = map(int,(input().split()))

dis = [-1]*N
dis[K-1] = 0
def dfs(v,d):
    for i in tree[v]:
        d = dis[v]
        next,c = i
        if dis[next] == -1:
            d += c
            dis[next] = d
            dfs(next,d)
dfs(K-1,0)

for i in range(Q):
    x,y = map(int,(input().split()))
    print(dis[x-1]+dis[y-1])

Fixed submission:
import sys
sys.setrecursionlimit(10**9)

N = int(input())
tree = [[] for _ in range(N)]
for i in range(N-1):
    a,b,c = map(int,input().split())
    tree[a-1].append((b-1,c))
    tree[b-1].append((a-1,c))

Q,K = map(int,(input().split()))

dis = [-1]*N
dis[K-1] = 0
def dfs(v,d):
    for i in tree[v]:
        d = dis[v]
        next,c = i
        if dis[next] == -1:
            d += c
            dis[next] = d
            dfs(next,d)
dfs(K-1,0)

for i in range(Q):
    x,y = map(int,(input().split()))
    print(dis[x-1]+dis[y-1])
Buggy python submission (verdict: Runtime Error):
N = int(input())
def su(n):
    s = 0
    for i in range(1,n+1):
        s += i
    return s

if N == 1:
    print(1)

else:
    for i in range(N):
        if su(i) >= N:
            M = i
            break
    print(M)

    now = N-M
    
    for i in range(1,M):
        if now - (M-i) >=(M-i):
            now -= M-i
            print(M-i)
        else:
            print(M-i)
            print(now-(M-i))
            break

Fixed submission:
N = int(input())
def su(n):
    s = 0
    for i in range(1,n+1):
        s += i
    return s

if N == 1:
    print(1)

elif N == 2:
    print(2)
    
elif N == 3:
    print(2)
    print(1)

elif N == 4:
    print(3)
    print(1)
    
else:
    for i in range(N):
        if su(i) >= N:
            M = i
            break
    print(M)

    now = N-M
    
    for i in range(1,M-1):
        if now - (M-i) >=(M-i):
            now -= M-i
            print(M-i)

        else:
            print(M-i)
            if now-(M-i) != 0: 
                print(now-(M-i))
            break
Buggy python submission (verdict: Runtime Error):
a, b, c, d = map(int, input().split())
    print(max([a*c, a*d, b*c, b*d]))

Fixed submission:
a, b, c, d = map(int, input().split())
print(max([a*c, a*d, b*c, b*d]))
Buggy python submission (verdict: Runtime Error):
#!/usr/bin/env python3
from collections import Counter
INF = 1e12


def main():
    N = int(input())
    A = list(map(int, input().split()))
    B = list(map(int, input().split()))
    lA = Counter(A)
    lB = Counter(B)
    if max(Counter(A+B).values()) > N:
        print('No')
        exit(1)

    C = [0] * (N + 1)
    D = [0] * (N + 1)
    for i in range(N):
        C[i + 1] = lA[i + 1] + C[i]
        D[i + 1] = lB[i + 1] + D[i]
    shift = - INF
    for i in range(1, N + 1):
        shift = max(shift, C[i] - D[i - 1])
    print('Yes')
    ans = (B + B + B)[shift + N:shift + 2*N]
    print(' '.join([str(a) for a in ans]))


if __name__ == "__main__":
    main()


Fixed submission:
#!/usr/bin/env python3
from collections import Counter
INF = 1e12


def main():
    N = int(input())
    A = list(map(int, input().split()))
    B = list(map(int, input().split()))
    lA = Counter(A)
    lB = Counter(B)
    if max(Counter(A+B).values()) > N:
        print('No')
        exit()

    C = [0] * (N + 1)
    D = [0] * (N + 1)
    for i in range(N):
        C[i + 1] = lA[i + 1] + C[i]
        D[i + 1] = lB[i + 1] + D[i]
    shift = - INF
    for i in range(1, N + 1):
        shift = max(shift, C[i] - D[i - 1])
    print('Yes')
    ans = (B + B + B)[N-shift:2*N-shift]
    print(' '.join([str(a) for a in ans]))


if __name__ == "__main__":
    main()
Buggy python submission (verdict: Time Limit Exceeded):
#!/usr/bin/env python3
import sys
from collections import deque, Counter
from heapq import heappop, heappush
from bisect import bisect_right
from itertools import accumulate

sys.setrecursionlimit(10**6)
INF = 10**12
m = 10**9 + 7

def main():
    H, W, M = map(int, input().split())
    h = [0] * H
    w = [0] * W
    hw = set()
    for i in range(M):
        tmph, tmpw = map(lambda x: int(x)-1, input().split())
        h[tmph] += 1
        w[tmpw] += 1
        hw.add((tmph,tmpw))
    # 最大値より1だけ小さくなる物が候補
    HMAX = max(h)
    hcandidate = []
    for i in range(H):
        if h[i] >= HMAX-1:
            hcandidate.append(i)

    WMAX = max(w)
    wcandidate = []
    for i in range(W):
        if w[i] >= WMAX-1:
            wcandidate.append(i)

    ans = 0
    for i in hcandidate:
        for j in wcandidate:
            res = h[i]+w[j]
            if (i,j) in hw:
                res -= 1
            ans = max(ans, res)
    print(ans)

if __name__ == "__main__":
    main()

Fixed submission:
#!/usr/bin/env python3
import sys
from collections import deque, Counter
from heapq import heappop, heappush
from bisect import bisect_right
from itertools import accumulate

sys.setrecursionlimit(10**6)
INF = 10**12
m = 10**9 + 7

def main():
    H, W, M = map(int, input().split())
    h = [0] * H
    w = [0] * W
    hw = set()
    for i in range(M):
        tmph, tmpw = map(lambda x: int(x)-1, input().split())
        h[tmph] += 1
        w[tmpw] += 1
        hw.add((tmph,tmpw))
    # 最大値より1だけ小さくなる物が候補
    HMAX = max(h)
    h0 = []
    for i in range(H):
        if h[i] == HMAX:
            h0.append(i)

    WMAX = max(w)
    w0 = []
    for i in range(W):
        if w[i] == WMAX:
            w0.append(i)

    ans = 0
    for i in h0:
        for j in w0:
            if (i,j) not in hw:
                print(HMAX+WMAX)
                exit()
    print(HMAX+WMAX-1)

if __name__ == "__main__":
    main()
Buggy python submission (verdict: Runtime Error):
print((1000-input()%1000)%1000)

Fixed submission:
#!/usr/bin/env python3
from collections import deque, Counter
from heapq import heappop, heappush
from bisect import bisect_right

def main():
    N = int(input())
    if N % 1000 == 0:
        print(0)
    else:
        print(1000 - N%1000)

if __name__ == "__main__":
    main()
Buggy python submission (verdict: Time Limit Exceeded):
#!/usr/bin/env python3

def main():
    K = int(input())
    S = input()
    N = len(S)
    M = N+K
    # print(N,K,M)
    p = 10**9+7
    a = [None] * (M+1)
    inva = [None] * (M+1)
    a[0] = 1
    
    for i in range(1, M+1):
        a[i] = i * a[i-1] % p
    
    inva[M] = pow(a[M],p-2,p)
    for i in range(M):
        inva[M-i-1] = inva[M-i] * (M-i) % p

    ans = 0
    for i in range(K+1):
        tmp = a[N+K-i-1]*inva[N-1]%p
        tmp = tmp*inva[K-i]%p
        tmp *= pow(25,K-i,p)
        tmp %= p
        tmp *= pow(26,i,p)
        tmp %= p
        ans = ans + tmp
        ans %= p
    print(ans)

if __name__ == "__main__":
    main()


Fixed submission:
#!/usr/bin/env python3

def main():
    K = int(input())
    S = input()
    N = len(S)
    M = N+K
    # print(N,K,M)
    p = 10**9+7
    a = [None] * (M+1)
    inva = [None] * (M+1)
    a[0] = 1
    
    for i in range(1, M+1):
        a[i] = i * a[i-1] % p
    
    inva[M] = pow(a[M],p-2,p)
    for i in range(M):
        inva[M-i-1] = inva[M-i] * (M-i) % p

    ans = 0
    for i in range(K+1):
        tmp = a[N+K-i-1]*inva[N-1]%p
        tmp = tmp*inva[K-i]%p
        tmp *= pow(25,K-i,p)
        tmp %= p
        tmp *= pow(26,i,p)
        tmp %= p
        ans = ans + tmp
        ans %= p
    print(ans)

if __name__ == "__main__":
    main()
Buggy python submission (verdict: Runtime Error):
#!/usr/bin/env python3
from collections import Counter

def main():
    N = int(input())
    A = list(map(int, input().split()))
    B = set()
    for i,l in Counter(A).items():
        if l == 1:
            B.add(i)
    A = sorted(B)
    N = len(A)
    # L = [1] * (N+1)
    # for i in range(N):
    #     L[i+1] = (L[i]*A[i])//gcd(L[i],A[i])
    ans = 0
    # print(A)
    # print(L)
    A.sort()
    for i in range(N):
        flag = True
        for j in range(i):
            if A[i] % A[j] == 0:
                flag = False
                break
        if flag:
            ans += 1
    print(ans)


if __name__ == "__main__":
    main()


Fixed submission:
#!/usr/bin/env python3
from collections import deque, Counter
from heapq import heappop, heappush
from bisect import bisect_right

def main():
    x = list(map(int, input().split()))
    print(x.index(0)+1)

if __name__ == "__main__":
    main()
Buggy python submission (verdict: Runtime Error):
X, N = map(int, input().split())
if N = 0:
    print(X)
    exit()
p = list(map(int, input().split()))

ans = -1

for i in range(0,102):
    if i not in p:
        if abs(i-X) < abs(ans-X):
            ans = i
print(ans)

Fixed submission:
#!/usr/bin/env python3
from collections import deque, Counter
from heapq import heappop, heappush
from bisect import bisect_right

def main():
    X, N = map(int, input().split())
    p = list(map(int, input().split()))
    ans = 10**12
    a = -1
    for i in range(0,102):
        if i not in p and abs(X-i) < ans:
            ans = abs(X-i)
            a = i
    print(a)


if __name__ == "__main__":
    main()
Buggy python submission (verdict: Runtime Error):
#!/usr/bin/env python3

def main():
    N = int(input())
    A = list(map(int, input().split()))
    B = set()
    for i,l in Counter(A).items():
        if l == 1:
            B.add(i)
    A = sorted(B)
    N = len(A)
    # L = [1] * (N+1)
    # for i in range(N):
    #     L[i+1] = (L[i]*A[i])//gcd(L[i],A[i])
    ans = 0
    # print(A)
    # print(L)
    A.sort()
    for i in range(N):
        flag = True
        for j in range(i):
            if A[i] % A[j] == 0:
                flag = False
                break
        if flag:
            ans += 1
    print(ans)


if __name__ == "__main__":
    main()


Fixed submission:
#!/usr/bin/env python3
from collections import Counter
from itertools import accumulate

def main():
    N = int(input())
    A = sorted(map(int, input().split()))
    # 倍数リストを保持して、チェックしていく
    B = [0] * (A[N-1]+1)
    for i in range(N):
        j = A[i]
        while j <= A[N-1]:
            B[j] += 1
            j += A[i]
    # print(B)
    ans = 0
    for i in range(N):
        if B[A[i]] == 1:
            ans += 1
    print(ans)


if __name__ == "__main__":
    main()
Buggy python submission (verdict: Runtime Error):
#!/usr/bin/env python3
import sys

def main():
    N, M, X = map(int, input().split())
    C = [None] * N
    A = [None for _ in range(N)]
    for i in range(N):
        C[i], *A[i] = map(int, input().split())
    
    # print(C,A)
    ans = 10**12
    for i in range(2**N):
        tmp = [0] * N
        tmpC = 0
        for j in range(N):
            if (i >> j) & 1:
                for k in range(M):
                    tmp[k] += A[j][k]
                tmpC += C[j]
        flag = True
        for k in range(M):
            if tmp[k] < X:
                flag = False
                break
        if flag:
            ans = min(ans, tmpC)
    
    if ans == 10**12:
        print(-1)
    else:
        print(ans)

if __name__ == '__main__':
    main()


Fixed submission:
#!/usr/bin/env python3
import sys

def main():
    N, M, X = map(int, input().split())
    C = [None] * N
    A = [None for _ in range(N)]
    for i in range(N):
        C[i], *A[i] = map(int, input().split())
    
    # print(C,A)
    ans = 10**12
    for i in range(2**N):
        tmp = [0] * M
        tmpC = 0
        for j in range(N):
            if (i >> j) & 1:
                for k in range(M):
                    tmp[k] += A[j][k]
                tmpC += C[j]
        flag = True
        for k in range(M):
            if tmp[k] < X:
                flag = False
                break
        if flag:
            ans = min(ans, tmpC)
    
    if ans == 10**12:
        print(-1)
    else:
        print(ans)

if __name__ == '__main__':
    main()
Buggy python submission (verdict: Time Limit Exceeded):
#!/usr/bin/env python3
import sys

def main():
    N = int(input())
    A = list(map(int, input().split()))
    ans = 0
    for j in range(N):
        for i in range(j+A[j]+1,N):
            if A[i] + A[j] == i-j:
                ans += 1
    print(ans)

if __name__ == '__main__':
    main()


Fixed submission:
#!/usr/bin/env python3
import sys
from bisect import bisect_left,bisect_right

def main():
    N = int(input())
    A = list(map(int, input().split()))
    B = [i+A[i] for i in range(N)] 
    B.sort()
    C = [i-A[i] for i in range(N)] 
    C.sort()
    ans = 0
    for i in range(N):
        ans += bisect_right(C,B[i]) - bisect_left(C,B[i])
    print(ans)

if __name__ == '__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
#!/usr/bin/env python3
import sys

def main():
    N = int(input())
    A = list(map(int, input().split()))
    ans = 0
    for i in range(N):
        for j in range(i,N):
            if A[j] == -A[i] + j-i:
                ans += 1
    print(ans)

if __name__ == '__main__':
    main()


Fixed submission:
#!/usr/bin/env python3
import sys
from bisect import bisect_left,bisect_right

def main():
    N = int(input())
    A = list(map(int, input().split()))
    B = [i+A[i] for i in range(N)] 
    B.sort()
    C = [i-A[i] for i in range(N)] 
    C.sort()
    ans = 0
    for i in range(N):
        ans += bisect_right(C,B[i]) - bisect_left(C,B[i])
    print(ans)

if __name__ == '__main__':
    main()
Buggy python submission (verdict: Runtime Error):
#!/usr/bin/env python3
import sys

def main():
    N, M = map(int, input().split())
    
    if M % 2 == 1:
        for i in range(M//2):
            print(i+1,M-i)
        for j in range(N//2 + 1):
            print(M+1+i,2*M+1-i)
    else:
        for i in range(M//2):
            print(i+1, M+1-i)
        for j in range(M//2):
            print(M+2+j,2*M+1-j)

if __name__ == '__main__':
    main()

Fixed submission:
#!/usr/bin/env python3
import sys

def main():
    N, M = map(int, input().split())
    
    if M % 2 == 1:
        for i in range(M//2):
            print(i+1,M-i)
        for j in range(M//2 + 1):
            print(M+1+j,2*M+1-j)
    else:
        for i in range(M//2):
            print(i+1, M+1-i)
        for j in range(M//2):
            print(M+2+j,2*M+1-j)

if __name__ == '__main__':
    main()
Buggy python submission (verdict: Time Limit Exceeded):
#!/usr/bin/env python3
from collections import Counter

def main():
    S = input()
    N = len(S)
    T = [0] * (N+1)
    
    for i in range(N-1,-1,-1):
        T[i] = (T[i+1] + int(S[i]) * (10**(N-i))) % 2019
    l = Counter(T)
    ans = 0
    for v in l.values():
        ans += v * (v-1) // 2
    print(ans)

if __name__ == "__main__":
    main()


Fixed submission:
#!/usr/bin/env python3
from collections import Counter

def main():
    S = input()
    N = len(S)
    T = [0] * (N+1)
    
    for i in range(N-1,-1,-1):
        T[i] = (T[i+1] + int(S[i]) * pow(10,N-i,2019)) % 2019
    l = Counter(T)
    ans = 0
    for v in l.values():
        ans += v * (v-1) // 2
    print(ans)

if __name__ == "__main__":
    main()
Buggy python submission (verdict: Time Limit Exceeded):
import math
K = int(input())
K +=1
ans = 0
for i in range(1,K):
  for j in range(1,K):
    for k in range(1,K):
      ans += math.gcd(math.gcd(i,j),k)
print(ans)

Fixed submission:
import math
K = int(input())
K +=1
ans = 0
for i in range(1,K):
  ans += math.gcd(i,i)
  for j in range(i+1,K):
    ans += 6 * math.gcd(i,j)
    for k in range(j+1,K):
      ans += 6 * math.gcd(math.gcd(i,j),k)

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import sys
import itertools
from collections import Counter

sys.setrecursionlimit(10**6)

def DFS(i,v,d):
  global dist
  
  if d > N:
    return
  # 頂点vに隣接する頂点でvより大きいものが未発見
  for u in adj[v]:
    # distは最短距離なので上書き禁止
    if i != u:
      #print(i,u,d)
      if dist[i][u] > d:
        dist[i][u] = d
        dist[u][i] = d
        # その先は追加で探索
      DFS(i,u,d+1)

N, X, Y = map(int, input().split())

# 隣接リストを作成する
adj = [[] for _ in range(N)]

# adjに入力
for i in range(N-1):
  adj[i].append(i+1)
  adj[i+1].append(i)

# X,Yをadj入力
adj[X-1].append(Y-1)
adj[Y-1].append(X-1)

# 頂点間の最短距離を保持するdist
dist = [[10**9 for _ in range(N)] for _ in range(N)]
for i in range(N):
  DFS(i,i,1)

  
# print(dist)
# distを１次元化
dist = list(itertools.chain.from_iterable(dist))
c = Counter(dist)

# 結果出力
for k in range(1,N):
  print(c[k]//2)
  

Fixed submission:
N, X, Y = map(int, input().split())
ans = [0] * N

for i in range(N):
  for j in range(i+1, N):
    tmp = min(j-i, abs(X-1-i) + 1 + abs(Y-1-j))
    ans[tmp] += 1

for k in range(1,N):
  print(ans[k])
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = list(map(int, input().split()))
setA = list(set(A))
setN = len(setA)
countA = [A.count(a) for a in setA]
ansA = [countA[i]*(countA[i]-1)//2 for i in range(setN)]
sumA = sum(ansA)

for i in range(N):
  index = setA.index(A[i])
  ans = sumA - ansA[index] + (countA[index] -1) * (countA[index] -2) //2
  print(ans)

Fixed submission:
from collections import Counter

N = int(input())
A = list(map(int, input().split()))
countA = Counter(A)
ansA = [v*(v-1)//2 for k,v in countA.items()]
sumA = sum(ansA)

for i in range(N):
  t =  countA[A[i]]
  ans = sumA - t*(t-1)//2 + (t-1)*(t-2)//2
  print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = list(map(int, input().split()))
setA = list(set(A))
countA = [A.count(a) for a in setA]

for i in range(N):
  ans = 0
  index = setA.index(A[i])

  for i in range(len(setA)):
    if i == index:
      c = countA[i] - 1
    else:
      c = countA[i]
    if c > 1:
      ans += c * (c-1) // 2
  print(ans)

Fixed submission:
from collections import Counter

N = int(input())
A = list(map(int, input().split()))
countA = Counter(A)
ansA = [v*(v-1)//2 for k,v in countA.items()]
sumA = sum(ansA)

for i in range(N):
  t =  countA[A[i]]
  ans = sumA - t*(t-1)//2 + (t-1)*(t-2)//2
  print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = list(map(int, input().split()))
setA = list(set(A))
countA = [A.count(a) for a in setA]

for i in range(N):
  ans = 0
  index = setA.index(A[i])

  for i in range(len(setA)):
    if i == index:
      c = countA[i] - 1
    else:
      c = countA[i]
    if c > 1:
      ans += c * (c-1) // 2
  print(ans)

Fixed submission:
from collections import Counter

N = int(input())
A = list(map(int, input().split()))
countA = Counter(A)
ansA = [v*(v-1)//2 for k,v in countA.items()]
sumA = sum(ansA)

for i in range(N):
  t =  countA[A[i]]
  ans = sumA - t*(t-1)//2 + (t-1)*(t-2)//2
  print(ans)

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

for i in range(N):
  ans = 0
  tmpA = A[:]
  del tmpA[i]
  setA = set(tmpA)
  for a in setA:
    c = tmpA.count(a)
    if c > 1:
      ans += c * (c-1) // 2
  print(ans)

Fixed submission:
from collections import Counter

N = int(input())
A = list(map(int, input().split()))
countA = Counter(A)
ansA = [v*(v-1)//2 for k,v in countA.items()]
sumA = sum(ansA)

for i in range(N):
  t =  countA[A[i]]
  ans = sumA - t*(t-1)//2 + (t-1)*(t-2)//2
  print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
#!/usr/bin/env python3
from collections import deque, Counter
from heapq import heappop, heappush
from bisect import bisect_right

H,W = map(int, input().split())
s = [None for _ in range(H)]
ans = H + W - 1

for i in range(H):
    s[i] = input()

def saiki(i,j,count):
    global ans
    tmp = count
    if s[i][j] == '#':
        tmp += 1
    
    if (i,j) == (H-1,W-1):# ゴール
        ans = min(ans,tmp)
    else:
        if i < H-1:# 下へ分岐する
            saiki(i+1,j,tmp)
        if j < W-1:
            saiki(i,j+1,tmp)

saiki(0,0,0)
print(ans)


Fixed submission:
#!/usr/bin/env python3
from collections import deque, Counter
from heapq import heappop, heappush
from bisect import bisect_right

H,W = map(int, input().split())
s = [None for _ in range(H)]
for i in range(H):
    s[i] = input()

dp = [[0]*(W+1) for _ in range(H+1)]
if s[0][0] == '#':
    dp[1][1] += 1
for i in range(H):
    for j in range(W):
        if (i,j) == (0,0):
            continue
        tmp = []
        if i > 0:
            if s[i][j] == '#' and s[i-1][j] == '.':
                tmp.append(dp[i][j+1]+1)
            else:
                tmp.append(dp[i][j+1])
        if j > 0:
            if s[i][j] == '#' and s[i][j-1] == '.':
                tmp.append(dp[i+1][j]+1)
            else:
                tmp.append(dp[i+1][j])

        dp[i+1][j+1] = min(tmp)
print(dp[H][W])