Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
def min(a, b):
    if a >= b:
        res = a - b
    elif a < b:
        res = b - a
    return res

n,k = map(int, input().split())
if n%k == 0:
    print(0)
    quit()

min_num = float('inf')
res_list = []
while(1):
    res = min(n, k)
    if res < min_num:
        min_num = res
    if res == 0:
        break
    if res in res_list:
        break
    n = res
    res_list.append(res)

print(min_num)


Fixed submission:
def min(a, b):
    if a >= b:
        res = a - b
    elif a < b:
        res = b - a
    return res

n,k = map(int, input().split())
if n%k == 0:
    print(0)
    quit()
else:
    n = n%k

min_num = float('inf')
res_list = []
while(1):
    res = min(n, k)
    if res < min_num:
        min_num = res
    if res == 0:
        break
    if res in res_list:
        break
    n = res
    res_list.append(res)

print(min_num)

Buggy python submission (verdict: Time Limit Exceeded):
def min(a, b):
    if a >= b:
        res = a - b
    elif a < b:
        res = b - a
    return res

n,k = map(int, input().split())
if k == 1:
    print(0)
    quit()

min_num = float('inf')
res_list = []
while(1):
    res = min(n, k)
    if res < min_num:
        min_num = res
    if res == 0:
        break
    if res in res_list:
        break
    n = res
    res_list.append(res)

print(min_num)


Fixed submission:
def min(a, b):
    if a >= b:
        res = a - b
    elif a < b:
        res = b - a
    return res

n,k = map(int, input().split())
if n%k == 0:
    print(0)
    quit()
else:
    n = n%k

min_num = float('inf')
res_list = []
while(1):
    res = min(n, k)
    if res < min_num:
        min_num = res
    if res == 0:
        break
    if res in res_list:
        break
    n = res
    res_list.append(res)

print(min_num)
Buggy python submission (verdict: Runtime Error):
def kaibun(mojiretu):
    leg = len(mojiretu)
    mid = (leg-1) /2
    for i in range(mid):
        if mojiretu[i] != mojiretu[(mid+1)+i]:
            return False
    return True

input_line = input()
if not kaibun(input_line):
    print('No')
    quit()

mid = (leg-1) /2
if not kaibun(input_line[0:mid]):
    print('No')
    quit()

if not kaibun(input_line[mid+1:]):
    print('No')
    quit()

Fixed submission:
def fin():
    print('No')
    quit()

input_line = input()
if not input_line == input_line[::-1]:
    fin()

N = len(input_line)
new_str = input_line[0:(N-1)//2]
if not new_str == new_str[::-1]:
    fin()

print('Yes')
Buggy python submission (verdict: Runtime Error):
n, a, b = map(int, input().split().rstrip())
k = n // (a + b)
r = n % (a + b)
print(k * a + min(r, a))


Fixed submission:
n, a, b = map(int, input().rstrip().split())
k = n // (a + b)
r = n % (a + b)
print(k * a + min(r, a))
Buggy python submission (verdict: Runtime Error):
n, m = input().split()
num_s = int(n)
num_c = int(m)

if num_c <= num_s * 2:
  print(num_c // c)
else:
  scc = num_s
  num_s = 0
  num_c -= 2 * scc
  scc += num_c // 4
  print(scc)



Fixed submission:
n, m = input().split()
num_s = int(n)
num_c = int(m)

if num_c <= num_s * 2:
  # Sが多いとき
  print(num_c // 2)
else:
  scc = num_s
  num_s = 0
  num_c -= 2 * scc
  scc += num_c // 4
  print(scc)
Buggy python submission (verdict: Runtime Error):
    def solve(a,b,c,turn):
    	if turn == "a":
    		if a == "":
    			return "A"
    		else:
    			next_turn = a[0]
    			a = a[1:]
    	elif turn == "b":
    		if b == "":
    			return "B"
    		else:
    			next_turn = b[0]
    			b = b[1:]
    	else
    		if c == "":
    			return "C"
    		else:
    			next_turn = c[0]
    			c = c[1:]
    	return solve(a,b,c, next_turn)
    a=input().strip()
    b=input().strip()
    c=input().strip()
    print(solve(a,b,c,"a"))

Fixed submission:
def solve(a,b,c,turn):
	if turn == "a":
		if a == "":
			return "A"
		else:
			next_turn = a[0]
			a = a[1:]
	elif turn == "b":
		if b == "":
			return "B"
		else:
			next_turn = b[0]
			b = b[1:]
	else:
		if c == "":
			return "C"
		else:
			next_turn = c[0]
			c = c[1:]
	return solve(a,b,c, next_turn)
a=input().strip()
b=input().strip()
c=input().strip()
print(solve(a,b,c,"a"))

Buggy python submission (verdict: Runtime Error):
def solve(a,b,c,turn):
	if turn == "a":
		if a == "":
			return "A"
		else:
			next_turn = a[0]
			a = a[1:]
	elif turn == "b":
		if b == "":
			return "B"
		else:
			next_turn = b[0]
			b = b[1:]
	else
		if c == "":
			return "C"
		else:
			next_turn = c[0]
			c = c[1:]
	return solve(a,b,c, next_turn)
a=input().strip()
b=input().strip()
b=input().strip()
print(solve(a,b,c,"a"))

Fixed submission:
def solve(a,b,c,turn):
	if turn == "a":
		if a == "":
			return "A"
		else:
			next_turn = a[0]
			a = a[1:]
	elif turn == "b":
		if b == "":
			return "B"
		else:
			next_turn = b[0]
			b = b[1:]
	else:
		if c == "":
			return "C"
		else:
			next_turn = c[0]
			c = c[1:]
	return solve(a,b,c, next_turn)
a=input().strip()
b=input().strip()
c=input().strip()
print(solve(a,b,c,"a"))
Buggy python submission (verdict: Runtime Error):
def sovle(s):
	if len(s) == 0:
		return 0
	l = len(s)
	ans = 0
	for i in range(1, l+1):
		left = s[:i]
		right = s[i:]
		ans += int(left) + solve(right)
	return ans

s = input().strip()
print(solve(s))



Fixed submission:
def solve(s):
	if len(s) == 0:
		return 0, 1
	l = len(s)
	ans = 0
	cnt = 0
	for i in range(1, l+1):
		left = s[:i]
		right = s[i:]
		a, b = solve(right)
		ans += int(left) * b + a
		cnt += b
	return ans, cnt

s = input().strip()
ans, _ = solve(s)
print(ans)
Buggy python submission (verdict: Runtime Error):
from collections import Counter
h, w, n = [int(i) for i in input().split()]

vs = []
for i in range(-1, 2):
	for j in range(-1, 2):
		vs.append((i,j))
cnt = []
for _ in range(n):
	a, b = [int(i) for i in input().split()]
	for v in vs:
		aa = a + v[0]
		bb = b + v[1]
		if 2<=aa<=h-1 and 2<=bb<=w-1:
			cnt.append(aa*h+bb)

cnt = Counter(cnt)


cnt2 = [0] * 10
cnt2[0] = (h-2)*(w-2)
for k in cnt:
	c = cnt[k]
	cnt2[c] += 1
	cnt2[0] -= 1

for i in cnt2:
	print(i)





Fixed submission:
from collections import Counter
h, w, n = [int(i) for i in input().split()]

vs = []
for i in range(-1, 2):
	for j in range(-1, 2):
		vs.append((i,j))
cnt = []
for _ in range(n):
	a, b = [int(i) for i in input().split()]
	for v in vs:
		aa = a + v[0]
		bb = b + v[1]
		if 2<=aa<=(h-1) and 2<=bb<=(w-1):
			cnt.append(aa*w+bb)

cnt = Counter(cnt)


cnt2 = [0] * 10
cnt2[0] = (h-2)*(w-2)
for k in cnt:
	c = cnt[k]
	cnt2[c] += 1
	cnt2[0] -= 1

for i in cnt2:
	print(i)

Buggy python submission (verdict: Time Limit Exceeded):
from collections import Counter
h, w, n = [int(i) for i in input().split()]
cnt = Counter()

vs = []
for i in range(-1, 2):
	for j in range(-1, 2):
		vs.append((i,j))

for _ in range(n):
	a, b = [int(i) for i in input().split()]
	for v in vs:
		aa = a + v[0]
		bb = b + v[1]
		if 2<=aa<=h-1 and 2<=bb<=w-1:
			cnt.update([(aa, bb)])


cnt2 = [0] * 10
cnt2[0] = (h-2)*(w-2)
for k in cnt:
	c = cnt[k]
	cnt2[c] += 1
	cnt2[0] -= 1

for i in cnt2:
	print(i)





Fixed submission:
from collections import Counter
h, w, n = [int(i) for i in input().split()]

vs = []
for i in range(-1, 2):
	for j in range(-1, 2):
		vs.append((i,j))
cnt = []
for _ in range(n):
	a, b = [int(i) for i in input().split()]
	for v in vs:
		aa = a + v[0]
		bb = b + v[1]
		if 2<=aa<=(h-1) and 2<=bb<=(w-1):
			cnt.append(aa*w+bb)

cnt = Counter(cnt)


cnt2 = [0] * 10
cnt2[0] = (h-2)*(w-2)
for k in cnt:
	c = cnt[k]
	cnt2[c] += 1
	cnt2[0] -= 1

for i in cnt2:
	print(i)
Buggy python submission (verdict: Runtime Error):
def solve(n, x, a):
	costs = []
	cost_min = 0
	for k in range(n):
		if k == 0:
			costs = a.copy()
		else:
			for i in range(n):
				costs[i] = min(costs[i], a[(i-k)%n])
		cost_k = sum(costs) + k*x
		if k == 0:
			cost_min = cost_k
		else:
			cost_min = min(cost_min, cost_k)		
		if cost_min < (k+1) *x:
			break

	return cost_min
n, x = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]
print(solve(n,x,a))


Fixed submission:
a, b, c = [int(i) for i in input().split()]
if a*b*c %2==0:
  print(0)
else:
  print(min(a*b, a*c, b*c))
Buggy python submission (verdict: Time Limit Exceeded):
def solve(n, x, a):
	costs = []
	cost_min = 0
	for k in range(n):
		if k == 0:
			costs = a.copy()
		else:
			for i in range(n):
				costs[i] = min(costs[i], a[(i-k)%n])
		cost_k = sum(costs) + k*x
		if k == 0:
			cost_min = cost_k
		else:
			cost_min = min(cost_min, cost_k)		
		if cost_min < (k+1) *x:
			break

	return cost_min

n, x = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]
print(solve(n,x,a))



Fixed submission:
def solve(n, x, a):
	costs = []
	cost_min = 0
	for k in range(n):
		if k == 0:
			costs = a.copy()
		else:
			for i in range(n):
				costs[i] = min(costs[i], a[(i-k)%n])
		cost_k = sum(costs) + k*x
		if k == 0:
			cost_min = cost_k
		else:
			cost_min = min(cost_min, cost_k)
			if cost_min != cost_k:
				break
		if cost_min < (k+1) *x:
			break

	return cost_min
n, x = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]
print(solve(n,x,a))
Buggy python submission (verdict: Runtime Error):
n, w, s, e = 0
for c in input():
	if c == "N":
		n += 1
	if c == "W":
		w += 1
	if c == "S":
		s += 1
	if c == "E":
		e += 1
b = ((n >= 1 and s >= 1) or (n==s==0)) and ((w >= 1 and e >= 1) or (w==e==0))
print("Yes" if b else "No")



Fixed submission:
n = w = s = e = 0
for c in input():
	if c == "N":
		n += 1
	if c == "W":
		w += 1
	if c == "S":
		s += 1
	if c == "E":
		e += 1
b = ((n >= 1 and s >= 1) or (n==s==0)) and ((w >= 1 and e >= 1) or (w==e==0))
print("Yes" if b else "No")
Buggy python submission (verdict: Runtime Error):
def solve(a):
	l = len(a)
	a1 = [a[2*i+1] for i in range((l+1)//2)]
	b = a.copy()
	b.sort()
	b1 = [b[2*i+1] for i in range((l+1)//2)]

	a1 = set(a1)
	b1 = set(b1)

	return len(a1 - b1)
n = int(input())
a = [int(input()) for i in range(n)]
print(solve(a))



Fixed submission:
def solve(a):
	l = len(a)
	h = l//2 + l%2
	a0 = [a[2*i] for i in range(h)]
	b = a.copy()
	b.sort()
	b0 = [b[2*i] for i in range(h)]

	a0 = set(a0)
	b0 = set(b0)

	return len(a0 - b0)
n = int(input())
a = [int(input()) for i in range(n)]
print(solve(a))

Buggy python submission (verdict: Time Limit Exceeded):
def solve(a):
	b = a.copy()
	b.sort()
	l = len(a)
	idx = map(b.index, a)
	cnt = 0
	for i, k in enumerate(idx):
		cnt += (i-k) % 2
	return cnt // 2

n = int(input())
a = [int(input()) for i in range(n)]
print(solve(a))


Fixed submission:
def solve(a):
	l = len(a)
	h = l//2 + l%2
	a0 = [a[2*i] for i in range(h)]
	b = a.copy()
	b.sort()
	b0 = [b[2*i] for i in range(h)]

	a0 = set(a0)
	b0 = set(b0)

	return len(a0 - b0)
n = int(input())
a = [int(input()) for i in range(n)]
print(solve(a))
Buggy python submission (verdict: Runtime Error):
S = input()
T = input()
A = int(input())
B = int(input())
U = input()

if U == T:
    B -= 1
if U == S:
    A -= 1

print(A , " " , B)


Fixed submission:
S,T = input().split()
A,B = input().split()
U = input()
A,B = int(A), int(B)

if U == T:
    B -= 1
elif U == S:
    A -= 1

print(A , " " , B)

Buggy python submission (verdict: Runtime Error):
S = input()
T = input()
A = int(input())
B = int(input())
U = input()

if U == T:
    B -= 1
if U == S:
    A -= 1
    
print(str(A) +  " " + str(B))


Fixed submission:
S,T = input().split()
A,B = input().split()
U = input()
A,B = int(A), int(B)

if U == T:
    B -= 1
elif U == S:
    A -= 1

print(A , " " , B)
Buggy python submission (verdict: Runtime Error):
import numpy as np
N, M = list(map(int, input().split()))
p = list(map(int, input().split()))
x = []
y = []
for _ in range(M):
    xi, yi = list(map(int, input().split()))
    x.append(xi - 1)
    y.append(yi - 1)

def count(l):
    out = 0
    for i, v in enumerate(l):
        if i + 1 == v:
            out += 1
    return out

def swap(l, a, b):
    va = l[a]
    vb = l[b]
    l1 = l.copy()
    l1[a] = vb
    l1[b] = va
    return l1

depth = 0
max_count = count(p)
max_d = M**5
children = [p]
next_children = []
while depth <= max_d:
    for child in children:
        for i in range(M):
            pi = swap(child, x[i], y[i])
            ci = count(pi)
            if ci > max_count:
                max_count = ci
	    if not pi in next_children:
                next_children.append(pi)
    depth += 1
    children = next_children
    next_chldren = []
    if max_count == len(p):
        break

print(max_count)

Fixed submission:
import numpy as np

s = input()
K = int(input())
L = len(s)

candidate = []

for l in range(1, K + 1):
    for j in range(0, L - l + 1):
        candidate.append(s[j:j+l])

candidate = list(set(candidate))
print(np.sort(candidate)[K-1])
Buggy python submission (verdict: Runtime Error):
# C - Traveling Salesman around Lake
K,N = list(map(int, input().split()))
A = list(map(int, input().split()))

import numpy as np
D = np.zeros((N, N))

for i in range(N):
    j = (i+1)%N
    if j == 0:
        D[i,j]=K-abs(A[j]-A[i])
    else:
        D[i,j] = abs(A[j]-A[i])

idx = np.unravel_index(np.argmax(D), D.shape)
dmax = D[idx]
ans = int(K - dmax)
print(ans)

Fixed submission:
# C - Traveling Salesman around Lake
K,N = list(map(int, input().split()))
A = list(map(int, input().split()))

a = A[1] - A[0]
for i in range(1,N-1):
    j = i + 1
    a = max(a,A[j]-A[i])

b = K-(A[N-1]-A[0])
c = max(a,b)
ans = K -c
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
# D - Banned K(高速版)
N = int(input())
A = list(map(int, input().split()))

import copy as c
C = []

for i in range(N):
    C.append(A.count(i+1))

C_tmp = [s for s in C if s > 1]

sum0 = 0
for j in C_tmp:
    sum0 = sum0 + j*(j-1)/2

for a in A:
    if C[a-1] >= 2:
        d = C[a-1] - 1
    else:
        d =0
    sum = int(sum0 - d)
    print(sum)

Fixed submission:
import collections


def resolve():
    N = int(input())
    A = list(map(int, input().split()))

    counter = collections.Counter(A)
    ans = 0

    for i in counter.values():
        ans += i * (i - 1) // 2

    for a in A:
        count = counter[a]
        print(ans - (count * (count - 1) // 2) +
              ((count - 1) * (count - 2) // 2))


resolve()

Buggy python submission (verdict: Time Limit Exceeded):
# D - Banned K(高速版)
N = int(input())
A = list(map(int, input().split()))

import copy as c
C = []

for i in range(N):
    C.append(A.count(i+1))

C_tmp = [s for s in C if s > 1]

sum0 = 0
for j in C_tmp:
    sum0 = sum0 + j*(j-1)/2

for k in range(N):
    if C[A[k]-1] >= 2:
        d = C[A[k]-1] - 1
    else:
        d =0
    sum = int(sum0 - d)
    print(sum)

Fixed submission:
import collections


def resolve():
    N = int(input())
    A = list(map(int, input().split()))

    counter = collections.Counter(A)
    ans = 0

    for i in counter.values():
        ans += i * (i - 1) // 2

    for a in A:
        count = counter[a]
        print(ans - (count * (count - 1) // 2) +
              ((count - 1) * (count - 2) // 2))


resolve()

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

import copy as c
C = []
for i in range(N):
    C.append(A.count(i+1))

for k in range(N):
    C_tmp = c.copy(C)
    if C_tmp[A[k]-1] > 0:
        sum=0
        C_tmp[A[k]-1] = C_tmp[A[k]-1]-1
        C_tmp2 = [s for s in C_tmp if s > 1]
        for j in C_tmp2:
            sum = sum + j*(j-1)/2
        #print(C_tmp,C_tmp2,int(sum))
        print(int(sum))
    else:
        sum=0
        C_tmp2 = [s for s in C if s > 1]
        print(C),print(C_tmp2)
        for j in C_tmp2:
            sum = sum + j*(j-1)/2
        #print(C,C_tmp2,int(sum))
        print(int(sum))

Fixed submission:
import collections


def resolve():
    N = int(input())
    A = list(map(int, input().split()))

    counter = collections.Counter(A)
    ans = 0

    for i in counter.values():
        ans += i * (i - 1) // 2

    for a in A:
        count = counter[a]
        print(ans - (count * (count - 1) // 2) +
              ((count - 1) * (count - 2) // 2))


resolve()
Buggy python submission (verdict: Time Limit Exceeded):
#C - Low Elements
import numpy as np
x = int(input())
p = np.array(list(map(int, input().split())))

ans=0
while x >=1:
    p = p[0:x]
    x=np.argmin(p)
    ans=ans+1
print(ans)

Fixed submission:
#C - Low Elements
import numpy as np
N = int(input())
P = np.array(list(map(int, input().split())))
min=P[0]
ans=1
for i in range(1,N):
    if min > P[i]:
        min = P[i]
        ans = ans +1
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
#C - Low Elements
x = int(input())
P = list(map(int, input().split()))
ans=0
while x >=1:
    P = P[0:x]
    m=min(P)
    x=P.index(m)
    ans=ans+1
print(ans)

Fixed submission:
#C - Low Elements
import numpy as np
N = int(input())
P = np.array(list(map(int, input().split())))
min=P[0]
ans=1
for i in range(1,N):
    if min > P[i]:
        min = P[i]
        ans = ans +1
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
#C - Low Elements
N = int(input())
P = list(map(int, input().split()))

x = N
ans=0
while x >=1:
    P = P[0:x]
    m=min(P)
    x=P.index(m)
    ans=ans+1
print(ans)

Fixed submission:
#C - Low Elements
import numpy as np
N = int(input())
P = np.array(list(map(int, input().split())))
min=P[0]
ans=1
for i in range(1,N):
    if min > P[i]:
        min = P[i]
        ans = ans +1
print(ans)
Buggy python submission (verdict: Runtime Error):
#A - Table Tennis Training
N,A,B = list(map(int, input().split()))

if Lab%2==0:
    #case Lab is even
    ans = int(B-A/2)
else:
    #case Lab is odd
    ans = min(A-1,N-B) + 1 + int((B-A-1)/2)

print(ans)

Fixed submission:
#A - Table Tennis Training
N,A,B = list(map(int, input().split()))

Lab = B-A
La = A-1
Lb = N-B

if Lab%2==0:
    #case Lab is even
    ans = Lab//2
else:
    #case Lab is odd
    ans = min(La,Lb) + 1 + Lab//2

print(ans)
Buggy python submission (verdict: Runtime Error):
N = int(input())
S, T  = input().split()

S_list = list(S)
T_list = list(T)
U_list = []
for i in range(N):
    U_list.append(S_list[i])
    U_list.append(T_list[i])

U = ''.join(U_list)
print(U_list)

Fixed submission:
l1 = [1,2,3]
l2 = [int(input()) for i in range(2)]
ans = list(set(l1) - set(l2))
print(ans[0])

Buggy python submission (verdict: Runtime Error):
N = int(input())
S, T  = input().split()

S_list = list(S)
T_list = list(T)
U_list = []
for i in range(N):
    U_list.append(S_list[i])
    U_list.append(T_list[i])

U = ''.join(U_list)
print(U)

Fixed submission:
l1 = [1,2,3]
l2 = [int(input()) for i in range(2)]
ans = list(set(l1) - set(l2))
print(ans[0])
Buggy python submission (verdict: Runtime Error):
r = input()
s = r**2
print(s)

Fixed submission:
r = int(input())
print(r**2)
Buggy python submission (verdict: Runtime Error):
N, K = map(int, input().split())

def okikae(t, k):
    if k==0:
        print(t)
    elif t%k==0:
        print("0")
    elif int(k/2) >= t:
        print(t)
    else:
        okikae(abs(t-k), k)

okikae(N, K)

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

def okikae(t, k):
    if k==0:
        print(t)
    elif int(k/2)+1 > t:
        print(t)
    elif t%k==0:
        print(0)
    elif t>k and t%k > 0:
        t = k+(t%k)
        okikae(abs(t-k), k)
    else:
        okikae(abs(t-k), k)

okikae(N, K)

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

def okikae(t):
    if K==0:
        print(N)
    elif N%K==0:
        print("0")
    elif K/2 >= t and t <= K:
        print(t)
    else:
        okikae(abs(t-K))

okikae(N)

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

def okikae(t, k):
    if k==0:
        print(t)
    elif int(k/2)+1 > t:
        print(t)
    elif t%k==0:
        print(0)
    elif t>k and t%k > 0:
        t = k+(t%k)
        okikae(abs(t-k), k)
    else:
        okikae(abs(t-k), k)

okikae(N, K)

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

def okikae(t):
    if N%K==0:
        print("0")
    elif K/2 >= t and t <= K:
        print(t)
    else:
        okikae(abs(t-K))

okikae(N)

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

def okikae(t, k):
    if k==0:
        print(t)
    elif int(k/2)+1 > t:
        print(t)
    elif t%k==0:
        print(0)
    elif t>k and t%k > 0:
        t = k+(t%k)
        okikae(abs(t-k), k)
    else:
        okikae(abs(t-k), k)

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

C = collections.Counter(L)
for i in range(N):
    del_target = L[i]
#     print("deltarget:{}".format(del_target))
    ans = 0
    for i in C.items():
        if i[0]== del_target:
            n = i[1]-1
#             print(int((n*(n-1)/2)))
            ans += int((n*(n-1)/2))
        else:
#             print(int((i[1]*(i[1]-1))/2))
            ans += int((i[1]*(i[1]-1))/2)
    print(ans)

Fixed submission:
import collections
N = int(input())
L = list(map(int, input().split()))

C = collections.Counter(L)
ans = 0
for i in C.items():
    ans += int((i[1]*(i[1]-1))/2)
        
for i in range(N):
    del_target = L[i]
    print(ans - (C[del_target]-1))

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



for i in range(N):
    ans_L = []
    tmp_L = copy.deepcopy(L)
    tmp_L.pop(i)
    
#     print(tmp_L)
    for j in range(2**(N-1)):
        count = 0
        tmp2_L = []
        for k in range(N-1):
            if j>>k&1 == 1:
                count += 1
                tmp2_L.append(tmp_L[k])
        if count==2:
            ans_L.append(tmp2_L)
#     print(ans_L)
    ans = 0
    for x in ans_L:
        if x[0]==x[1]:
            ans += 1
    print(ans)

Fixed submission:
import collections
N = int(input())
L = list(map(int, input().split()))

C = collections.Counter(L)
ans = 0
for i in C.items():
    ans += int((i[1]*(i[1]-1))/2)
        
for i in range(N):
    del_target = L[i]
    print(ans - (C[del_target]-1))
Buggy python submission (verdict: Time Limit Exceeded):
S = input()
Q = int(input())
ans = S
for i in range(Q):
    Query = input()
    if Query[0] == "1":
        ans = ans[::-1]
    elif Query[0:3] == "2 1":
        ans = Query[4]+ans
    elif Query[0:3] == "2 2":
        ans += Query[4]
#     print(ans)
print(ans)

Fixed submission:
S = input()
Q = int(input())
ans = S
## vector が1なら正方向、-1なら逆方向
vector = 1
before = ""
after = ""
for i in range(Q):
    Query = input()
    if Query[0] == "1":
        vector *= -1
    elif vector == 1 and Query[0:3] == "2 1":
        before = Query[4] + before
    elif vector == 1 and Query[0:3] == "2 2":
        after = after + Query[4]
    elif vector == -1 and Query[0:3] == "2 1":
        after = after + Query[4]
    elif vector == -1 and Query[0:3] == "2 2":
        before = Query[4] + before
#     print(before)
#     print(after)
if vector==1:
    print(before + S + after)
else:
    print(after[::-1]+S[::-1]+before[::-1])

Buggy python submission (verdict: Time Limit Exceeded):
S = input()
Q = int(input())
ans = S
for i in range(Q):
    Query = input()
    if Query[0] == "1":
        ans = ans[::-1]
    elif Query[0] == "2":
        if Query[2] == "1":
            ans = Query[4:]+ans
        elif Query[2] == "2":
            ans += Query[4:]
#     print(ans)
print(ans)

Fixed submission:
S = input()
Q = int(input())
ans = S
## vector が1なら正方向、-1なら逆方向
vector = 1
before = ""
after = ""
for i in range(Q):
    Query = input()
    if Query[0] == "1":
        vector *= -1
    elif vector == 1 and Query[0:3] == "2 1":
        before = Query[4] + before
    elif vector == 1 and Query[0:3] == "2 2":
        after = after + Query[4]
    elif vector == -1 and Query[0:3] == "2 1":
        after = after + Query[4]
    elif vector == -1 and Query[0:3] == "2 2":
        before = Query[4] + before
#     print(before)
#     print(after)
if vector==1:
    print(before + S + after)
else:
    print(after[::-1]+S[::-1]+before[::-1])