Harryxun/GPT-100-sft-dataset huggingface dataset:
Problem p03730 (python)

Fixed submission:
import fractions
a, b, c = map(int, input().split())
print("YES" if c%(fractions.gcd(a,b)) == 0 else "NO")

Buggy submission (verdict: Runtime Error):
import fraction
a, b, c = map(int, input().split())
print("YES" if c%(fraction.gcd(a,b)) == 0 else "NO")

Buggy submission (verdict: Runtime Error):
import math
a, b, c = map(int, input().split())
print("YES" if c%(math.gcd(a,b)) == 0 else "NO")

Buggy submission (verdict: Runtime Error):
import math
a, b, c = map(int, input().split())
print("YES" if math.gcd(a,b)%c == 0 else "NO")
Problem p03731 (python)

Fixed submission:
n,t = map(int,input().split())
a = list(map(int,input().split()))
s = t
for i in range(0,n-1):
  s += min(t,a[i+1]-a[i])
print(s)

Buggy submission (verdict: Runtime Error):
n,t = map(int,input().split())
a = list(map(int,input().split()))
s = t
for i in range(0,n):
  s += min(t,a[i+1]-a[i])
print(s)
Problem p03759 (python)

Fixed submission:
a,b,c=map(int,input().split())
print("YES" if a+c==2*b else "NO")

Buggy submission (verdict: Runtime Error):
print("YES" if int(input())-2*int(input())+int(input()) == 0 else "NO")
Problem p03778 (python)

Fixed submission:
w,a,b = map(int,input().split())
print(max(max(a,b)-min(a,b)-w,0))

Buggy submission (verdict: Runtime Error):
print(-min(int(input())-abs(int(input())-int(input())),0))
Problem p03797 (python)

Fixed submission:
n, m = map(int, input().split())
if m <= 2*n:
  print(m//2)
else:
  print((m-2*n)//4 + n)

Buggy submission (verdict: Runtime Error):
n, m = map(int, input().split())
if m <= 2*n:
  print(m//2)
else:
  print((m-2n)//3 + n)
Problem p03845 (python)

Fixed submission:
n = int(input())
t = [0] + list(map(int,input().split()))
s = sum(t)
for _ in [0]*int(input()):
  p,x = map(int,input().split())
  print(s-t[p]+x)

Buggy submission (verdict: Runtime Error):
n = int(input())
t = [0] + list(map(int,input().split()))
s = sum(t)
for _ in [0]*int(input()):
  p,x = map(int,input().split())
  pritn(s-t[p]+x)
Problem p03860 (python)

Fixed submission:
a,b,c=input().split();print(a[0]+b[0]+c[0])

Buggy submission (verdict: Runtime Error):
a,b,c=input().split();ptint(a[0]+b[0]+c[0])
Problem p04019 (python)

Fixed submission:
a = list(input())
print("No" if (("N" in a) ^ ("S" in a)) or (("W" in a) ^ ("E" in a)) else "Yes")

Buggy submission (verdict: Runtime Error):
a = set(list(input()))
print("Yes" if ~("N" in a ^ "S" in a) and ~("W" in a ^ "E" in a) else "No")
Problem p04030 (python)

Fixed submission:
s = list(input())
a = []

for i in s:
  if i == "0" or i == "1" :
    a += [i]
  elif a != []:
    del a[-1]

print("".join(a))

Buggy submission (verdict: Runtime Error):
s = list(input())
a = []

for i in s:
  if i == "0" or i == "1" :
    a += [i]
  elif: a != []
    del a[-1]

print(a)
Problem p02556 (python)

Fixed submission:
N = int(input())
l = []
for i in range(N):
    l.append([int(x) for x in input().split()])

xlim = []
ylim = []

def cha(a):
    return [a[0]-a[1],a[0]+a[1]]

for i in range(N):
        ylim.append(cha(l[i])[1])
        xlim.append(cha(l[i])[0])

xlim.sort()
ylim.sort()

print(max(xlim[-1]-xlim[0],ylim[-1]-ylim[0]))

Buggy submission (verdict: Runtime Error):
N = int(input())
l = []
for i in range(N):
    l.append([int(x) for x in input().split()])

xlim = []
ylim = []

def cha(a):
    return [a[0]-a[1],a[0]+a[1]]

for i in range(N):
    if cha(l[i])[0] <= cha(l[i])[1]:
        ylim.append(cha(l[i])[1]))
    else:
        xlim.append(cha(l[i])[0])

xlim.sort()
ylim.sort()

if len(xlim)*len(ylim) != 0:
    print(max(-xlim[0]+xlim[-1],-ylim[0]+ylim[-1]))
elif len(xlim) == 0:
    print(-ylim[0]+ylim[-1])
elif len(ylim) == 0:
    print(-xlim[0]+xlim[-1])
Problem p02584 (python)

Fixed submission:
(X,K,D) = map(int,input().split())
X = abs(X)
if X-K*D>0:
    print(X-K*D)

else:
    if K%2==0:
        print(min(abs(X%(2*D)),abs(X%(2*D)-2*D)))
    else:
        print(min(abs((X+D)%(2*D)),abs((X+D)%(2*D)-2*D)))

Buggy submission (verdict: Runtime Error):
(X,K,D) = map(int,input().split())
X = abs(X)
if X-K*D>0:
    print(X-K*D)

else:
    if K%2==0:
        print(min(abs(X%(2*D)),abs(X%(2*D)-2*D)))
    else:
        print(min(abs((X+D)%(2*D),abs((X+D)%(2*D)-2*D))))
Problem p02727 (python)

Fixed submission:
[X,Y,A,B,C] = [int(x) for x in input().split()]
R_list = [int(x) for x in input().split()]
G_list = [int(x) for x in input().split()]
T_list = [int(x) for x in input().split()]
R_list.sort()
G_list.sort()
T_list.sort()
ans = 0
r = 0
g = 0
for i in range(X+Y):
    if r == X:
        R_list = [0]
    if g == Y:
        G_list = [0]
    if len(T_list) == 0:
        T_list = [0]
    if max(R_list[-1],G_list[-1],T_list[-1]) == R_list[-1]:
        ans += R_list.pop(-1)
        r += 1
    elif max(R_list[-1],G_list[-1],T_list[-1]) == G_list[-1]:
        ans += G_list.pop(-1)
        g += 1
    elif max(R_list[-1],G_list[-1],T_list[-1]) == T_list[-1]:
        ans += T_list.pop(-1)
print(ans)

Buggy submission (verdict: Runtime Error):
[X,Y,A,B,C] = [int(x) for x in input().split()]
R_list = [int(x) for x in input().split()]
G_list = [int(x) for x in input().split()]
T_list = [int(x) for x in input().split()]
R_list.sort()
G_list.sort()
T_list.sort()
total = 0
ans = 0
r = 0
g = 0
for i in range(X+Y):
    if r == X:
        R_list = [-1]
    if g == Y:
        G_list = [-1]
    if max(R_list[-1],G_list[-1],T_list[-1]) == R_list[-1]:
        ans += R_list.pop(-1)
        r += 1
    elif max(R_list[-1],G_list[-1],T_list[-1]) == G_list[-1]:
        ans += G_list.pop(-1)
        g += 1
    elif max(R_list[-1],G_list[-1],T_list[-1]) == T_list[-1]:
        ans += T_list.pop(-1)
print(ans)
Problem p04044 (python)

Fixed submission:
n = input().split()
N = int(n[0])
L = int(n[1])
a = []
for i in range(N):
    b = input()
    a.append(b)
A = sorted(a)
print(''.join(A))

Buggy submission (verdict: Runtime Error):
n = input().split()
N = int(n[0])
L = int(n[1])
a = []
for i in range(L):
    b = input()
    a.append(b)
A = sorted(a)
print(''.join(A))

Buggy submission (verdict: Runtime Error):
n = input().split()
N = int(n[0])
L = int(n[1])
a = []
for i in range(L):
    b = input()
    a.append(b)
A = sorted(a)
print(''.join(A))

Buggy submission (verdict: Runtime Error):
n = input().split()
N = int(n[0])
L = int(n[1])
a = []
for i in range(L):
    b = input()
    a.append(b)
A = sorted(a)
print(''.join(A))
Problem p02608 (python)

Fixed submission:
import sys

input = sys.stdin.readline

def main():
    ans = [0]* 10010
    n = int(input())
    for x in range(1,101):
        for y in range(1,101):
            for z in range(1,101):
                v = (x+y+z)**2 - x*y - y*z - z*x
                if v <= n:
                    ans[v] += 1
    for i in range(1,n+1):
        print(ans[i])

if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
import sys

input = sys.stdin.readline

def calc(n):
    for i in range(1,int((n+1)**0.5)):
        for j in range(1,int((n+1)**0.5)):
            for k in range(1, int((n+1)**0.5)):
                if (i+j+k)**2 - i*j - j*k - k*i == n:
                    if i == j == k:
                        return 1
                    else:
                        return 3
    return 0    

def main():
    ans = ''
    n = int(input())
    for i in range(1,n+1):
        ans += str(calc(i)) + '\n'
    prtin(ans)

if __name__ == '__main__':
    main()
Problem p02640 (python)

Fixed submission:
ans = 'No'
x, y = map(int, input().split())
for i in range(x+1):
  if (2 * i) + (4 * (x-i)) == y:
    ans = 'Yes'
    break
print(ans)

Buggy submission (verdict: Runtime Error):
ans = 'No'
x ,y = map(int, input().split())
for i in range(x+1):
  if 2 ＊ x + 4 ＊ (x-i) == y:
    ans = 'Yes'
    break
print(ans)
Problem p02641 (python)

Fixed submission:
x, n = map(int, input().split())
l = list(map(int, input().split()))
flg = False
t = x
while flg == False:
  if t in l:
    t -= 1
  else:
    ans = t
    flg = True
flg = False
t = x
while flg == False:
  if t in l:
    t += 1
  else:
    if abs(x-ans) > abs(x-t):
      ans = t
    flg = True
print(ans)

Buggy submission (verdict: Runtime Error):
x, n = map(int, input().split())
l = list(map(int, input().split()))
flg = false
t = x
while flg == False:
  if t in l:
    t -= 1
  else:
    ans = t
    flg = True
flg = False
t = x
while flg == False:
  if t in l:
    t += 1
  else:
    if abs(x-ans) > abs(x-t):
      ans = t
    flg = True
print(ans)
Problem p02687 (python)

Fixed submission:
def main():
    a = 'ABC'
    r = 'ARC'
    s = input()
    if s == a:
        print(r)
    else:
        print(a)

if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
def main():
    a = 'ABC'
    r = 'ARC'
    s = input()
    if s == a:
        print(r)
    else:
        print(a)
    
    print(ans)

if __name__ == '__main__':
    main()
Problem p02705 (python)

Fixed submission:
import math

def main():
  r = int(input())
  print('{:.20}'.format(2*r*math.pi))

if __name__ == '__main__':
  main()

Buggy submission (verdict: Runtime Error):
import math

def main():
  r = int(input())
  print('{:.16}'.format(2*r*math.pi)

if __name__ == '__main__':
  main()
Problem p02706 (python)

Fixed submission:
def main():
  n, m = map(int, input().split())
  l = list(map(int, input().split()))
  ans = n - sum(l)
  if ans < 0:
      ans = -1
  print(ans)

if __name__ == '__main__':
  main()

Buggy submission (verdict: Runtime Error):
def main():
  n, m = map(int, input().split())
  l = list(map(int, input(.split())))
  ans = n - sum(l)
  if ans < 0:
      ans = -1
  print(ans)

if __name__ == '__main__':
  main()
Problem p02717 (python)

Fixed submission:
x,y,z = map(int, input().split())
print("{} {} {}".format(z,x,y))

Buggy submission (verdict: Runtime Error):
x,y,z = mpa(int, input().split())
print("{} {} {}".format(z,x,y))
Problem p02741 (python)

Fixed submission:
l = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
n = int(input())
print(l[n-1])

Buggy submission (verdict: Runtime Error):
n = int(input())
l = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
print(l[n+1])
Problem p02742 (python)

Fixed submission:
import sys
h, w = map(int, input().split())
if h == 1 or w == 1:
  print(1)
  sys.exit()
ans = h//2*w
if h%2 != 0:
  if w%2 != 0:
    ans += w//2+1
  else:
    ans += w/2
print(int(ans))

Buggy submission (verdict: Runtime Error):
h, w = map(int, input().split())
if h == 1 or w == 1:
  print(1)
else:
  if a*w%2 != 0:
    print(a*w//2 + 1)
  else:
    print(a*w//2)
Problem p02743 (python)

Fixed submission:
a,b,c = map(int, input().split())
d = c-a-b
if d > 0 and d**2 > 4*a*b:
  print("Yes")
else:
  print("No")

Buggy submission (verdict: Runtime Error):
a,b,c = map(int, input().split())
if a + b + 4*a*b < c:
  print("Yes")
else:
  print("No)

Buggy submission (verdict: Runtime Error):
a,b,c = map(decimal, input().split())
if abs((a**0.5) + (b**0.5)) < abs(c**0.5):
  print("Yes")
else:
  print("No")
Problem p02843 (python)

Fixed submission:
n = int(input())
h = n//100
if 100*h <= n <= 105*h:
  print(1)
else:
  print(0)

Buggy submission (verdict: Runtime Error):
n = int(input)
h = n//100
if 100*h <= n <= 105*h:
  print(1)
else:
  print(0)

Buggy submission (verdict: Runtime Error):
n = int(input)
h = n//100
if 100*n <= n <= 105*n:
  print(1)
else:
  print(0)
Problem p02983 (python)

Fixed submission:
import sys
l, r = map(int, input().split())
ans = l*r%2019
for i in range(l, r):
  for j in range(i+1, r+1):
    if i*j%2019 == 0:
      print(0)
      sys.exit()
    elif ans > i*j%2019:
      ans = i*j%2019
print(ans)

Buggy submission (verdict: Runtime Error):
import sys
l, r = map(int, input().split())
for i in range(l, r-1):
  for j in range(i+1, r):
    if i*j%2019 == 0:
      print(0)
      sys.exit()
    elif ans > i*j%2019:
      ans = i*j%2019
print(ans)
Problem p03282 (python)

Fixed submission:
import sys

input = sys.stdin.readline

def main():
    ans = ''
    index = 0
    s = input().rstrip('\n')
    k = int(input())
    for i in range(len(s)):
        if s[i] != '1':
            ans = s[i]
            index = i
            break
    if ans == '' or k < index+1:
        ans = '1'
    print(ans)

if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
s = input()
k = int(input())
ans = ''
if s[1] == '1':
  ans = 1
else:
  ans = s[1]
print(ans)
Problem p03328 (python)

Fixed submission:
a,b = map(int, input().split())
bh = 0
for i in range(b-a+1):
  bh += i
print(bh-b)

Buggy submission (verdict: Runtime Error):
a,b = map(int, input().split())
d = b - a
bh = 0
for i in range(n+1):
  bh += bh + i
print(bh - b)
Problem p03361 (python)

Fixed submission:
import sys

input = sys.stdin.readline

d = '.'
dn = '#'

def isPaintable(h, w, x, y, canvas):
    if x > 0:
        if canvas[y][x-1] == dn:
            return True
    if x < w-1:
        if canvas[y][x+1] == dn:
            return True
    if y > 0:
        if canvas[y-1][x] == dn:
            return True
    if y < h-1:
        if canvas[y+1][x] == dn:
            return True
    return False

def main():
    ans = 'Yes'
    h, w = map(int, input().split())
    canvas = []
    for _ in range(h):
        s = list(input().rstrip('\n'))
        canvas.append(s)
    for y in range(h):
        if ans == 'No':
            break
        for x in range(w):
            if canvas[y][x] == dn and not isPaintable(h, w, x, y, canvas):
                ans = 'No'
                break
    print(ans)

if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
import sys

input = sys.stdin.readline

d = '.'
dn = '#'

def isPaintable(h, w, x, y, canvas):
    ret = False
    if x > 0:
        if canvas[x-1, y] == dn:
            ret = True
    elif x < w:
        if canvas[x+1, y] == dn:
            ret = True
    elif y > 0:
        if canvas[x, y-1] == dn:
            ret = True
    elif y < h:
        if canvas[x, y+1] == dn:
            ret = True
    return ret

def main():
    ans = 'Yes'
    h, w = map(int, input().split())
    canavs = []
    for _ in range(h):
        s = list(input().split().rstrip('\n'))
        canvas.append(s)
    for i in h:
        if ans == 'No':
            break
        for j in w:
            if not isPaintable(h, w, j, i, canvas):
                ans = 'No'
                break
    print(ans)

if __name__ == '__main__':
    main()
Problem p03471 (python)

Fixed submission:
n, y = map(int, input().split())
for i in range(n+1):
  for g in range(n-i+1):
    s = n-i-g
    if 10000*i + 5000*g + 1000*s == y:
      print(i, g, s)
      exit()
print('-1 -1 -1')

Buggy submission (verdict: Runtime Error):
n, y = map(int, input().split())
for i in range(n+1):
  for g in range(n-i):
    s = n-i-g
    if 10000*i + 5000*g 1000*s == y:
      print(i, g, s)
      exit()
print('-1 -1 -1')
Problem p03545 (python)

Fixed submission:
import sys

input = sys.stdin.readline

def main():
    ans = ""
    nums = list(map(int, list(input().rstrip("\n"))))
    
    for i in range(2**3):
        ts = sum(nums)
        ops = ['+']*3
        for j in range(3):
            if i>>j&1:
                ts -= nums[j+1]*2
                ops[j]='-'
        if ts == 7:
            for i in range(3):
                ans += str(nums[i])+ops[i]
            ans += str(nums[3])+"=7"
            break
    print(ans)

if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
import sys

input = sys.stdin.readline

def main():
    ans = ""
    nums = list(map(int, list(input())))
    for i in range(8):
        ts = sum(nums)
        ops = ['+']*3
        for j in range(3):
            if i>>j&1:
                ts -= nums[j+1]*2
                ops[j]='-'
        if ts == 7:
            for i in range(3):
                ans += str(nums[i])+ops[i]
            ans += str(nums[3])+"=7"
            break
    print(ans)

if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
import sys

input = sys.stdin.readline

def main():
    ans = ""
    nums = list(map(int, list(input())))
    for i in range(8):
        ts = sum(nums)
        ops = ['+']*3
        for j in range(3):
            if i>>j&1:
                ts -= nums[j+1]*2
                ops[j]='-'
        if ts == 7:
            for i in range(3):
                ans += str(nums[i])+ops[i]
            ans += str(nums[3])+"=7"
            break
    print(ans)

if __name__ == '__main__':
    main()
Problem p03568 (python)

Fixed submission:
import sys

input = sys.stdin.readline

def main():
    ans = 0
    n = int(input())
    A = list(map(int, input().split()))
    allB = 3**n
    exc = 1
    for i in range(n):
        if A[i]%2 == 0:
            exc *= 2
    ans = allB - exc
    print(ans)

if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
import sys

input = sys.stdin.readline

def main():
    ans = 0
    n = int(input())
    A = list(map(int, input().split()))
    allB = exc = 1
    for i in n:
        allB *= 3
        if i%2 == 0:
            exc *= 2
    ans = allB - exc
    print(ans)

if __name__ == '__main__':
    main()
Problem p03607 (python)

Fixed submission:
n = int(input())
l = [int(input()) for _ in range(n)]
l.sort()
c = 1
ans = 0
for i in range(1, n):
  if l[i-1] == l[i]:
    c += 1
  else:
    ans += c%2
    c = 1
if c != 1:
  ans += c%2
else:
  ans += 1
print(ans)

Buggy submission (verdict: Runtime Error):
n = int(input())
l = [int(input()) for _ in range(n)]
l.sort()
c = 1
t = l[0]
for i in l[1:]:
  if t == i:
    c += 1
  else:
    ans += c%2
    c = 1
    t = i
print(ans)

Buggy submission (verdict: Runtime Error):
n = int(input())
l = [int(input()) _ for in range(n)]
l.sort()
c = 1
t = l[0]
for i in l[1:]:
  if t == i:
    c += 1
  else:
    ans += c%2
    c = 1
    t = i
print(ans)
Problem p03612 (python)

Fixed submission:
def main():
    ans = 0
    n = int(input())
    l = list(map(int, input().split()))
    for i in range(n-1):
        if l[i] == i+1:
            l[i] = l[i+1]
            l[i+1] = i+1
            ans += 1
    if l[n-1] == n:
        ans += 1
    print(ans)

if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
def main():
    ans = 0
    n = int(input())
    l = list(map(int, input().split()))
    for i in range(n):
        if l[i] == i+1:
            l[i] = l[i+1]
            l[i+1] = i+1
            ans += 1
    print(ans)

if __name__ == '__main__':
    main()
Problem p03624 (python)

Fixed submission:
import sys
import string

input = sys.stdin.readline

def main():
    ans = 'None'
    S = input()
    s = string.ascii_lowercase
    for i in s:
        if i not in S:
            ans = i
            break
    print(ans)

if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
import sys
import string

input = sys.stdin.readline

def main():
    ans = 'None'
    S = list(set(input()))
    s = list(string.ascii_lowercase)
    for i in S:
        s.remove(i)
    if s:
        ans = s[0]
    print(ans)

if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
import sys
import string

input = sys.stdin.readline

def main():
    ans = 'None'
    S = set(input())
    s = list(string.ascii_lowercase)
    for i in S:
        s.remove(i)
    if s:
        ans = s[0]
    print(ans)

if __name__ == '__main__':
    main()
Problem p03633 (python)

Fixed submission:
import fractions
n = int(input())
l = [int(input()) for _ in range(n)]
ans = l[0]
for i in range(n):
  ans = ans * l[i] // fractions.gcd(ans, l[i])
print(ans)

Buggy submission (verdict: Runtime Error):
import fractions
n = int(input())
l = [int(input()) for _ in range(n)]
ans = l[i]
for i in range(n):
  ans = ans * l[i] // fractions.gcd(ans, l[i])
print(ans)
Problem p03644 (python)

Fixed submission:
n = int(input())
l = [64,32,16,8,4,2,1]
for i in l:
  if i <= n:
    print(i)
    break

Buggy submission (verdict: Runtime Error):
n = int(input())
l =[64,32,16,8,4,2,1]
for i ib l:
  if i <= n:
    print(i)
    break;
Problem p02732 (python)

Fixed submission:
N = int(input())
A = [a for a in map(int, input().split())]

#N個のボールに対して、書かれている数字は1~Nまで

dic1 = {}
for i in range(N):
    dic1[i+1] = 0

#dicにkeyとなる数字の個数を入れていく
for i in range(N):
    if A[i] in dic1.keys():
        dic1[A[i]] += 1

dic2 = {}
#組み合わせの数を入れる   
for i in range(N):
    dic2[i+1] = dic1[i+1]*(dic1[i+1]-1)/2

ans1 = 0
for i in range(N):
    ans1 += dic2[i+1]

for i in range(N):
    ans2 = ans1
    ans2 -= dic2[A[i]] #組み合わせの数を引く
    ans2 += (dic1[A[i]]-1)*(dic1[A[i]]-2)/2 #新たな組み合わせの数を足す
    print(int(ans2))

Buggy submission (verdict: Runtime Error):
N = int(input())
A = [a for a in map(int, input().split())]

#N個のボールに対して、書かれている数字は1~Nまで

dic1 = {}
for i in range(N):
    dic1[i] = 0

#dicにkeyとなる数字の個数を入れていく
for i in A:
    if i in dic1.keys():
        dic1[i] += 1

dic2 = {}
#組み合わせの数を入れる   
for i in range(N):
    dic2[i] = dic1[i]*(dic1[i]-1)/2

ans1 = 0
for i in range(N):
    ans1 += dic2[i]

for i in range(N):
    ans2 = ans1
    ans2 -= dic2[A[i]] #組み合わせの数を引く
    ans2 += (dic1[A[i]]-1)*(dic1[A[i]]-2)/2 #新たな組み合わせの数を足す
    print(int(ans2))

Buggy submission (verdict: Runtime Error):
N = int(input())
A = [a for a in map(int, input().split())]

#N個のボールに対して、書かれている数字は1~Nまで

dic1 = {}
for i in range(N):
    dic1[i] = 0

#dicにkeyとなる数字の個数を入れていく
for i in A:
    if i in dic1.keys():
        dic1[i] += 1

dic2 = {}
#組み合わせの数を入れる   
for i in range(N):
    dic2[i] = dic1[i]*(dic1[i]-1)/2

ans1 = 0
for i in range(N):
    ans1 += dic2[i]

for i in range(N):
    ans2 = ans1
    ans2 -= dic2[A[i]] #組み合わせの数を引く
    ans2 += (dic1[A[i]]-1)*(dic1[A[i]]-2)/2
    print(ans2)
Problem p02756 (python)

Fixed submission:
from collections import deque

S = deque(input())
Q = int(input())

flag = 1
for i in range(Q):
    qry = input().split()

    if qry[0] == '1':
        if flag:
            flag = 0
        else:
            flag = 1
    
    elif qry[0] == '2':
        if flag:
            if qry[1] == '1':
                S.appendleft(qry[2])
            else:
                S.append(qry[2])
        else:
            if qry[1] == '1':
                S.append(qry[2])
            else:
                S.appendleft(qry[2])

S = ''.join(S)

if flag:
    print(S)
else:
    print(S[::-1])

Buggy submission (verdict: Runtime Error):
from collections import deque

S = deque(input())
Q = int(input())

flag = 1
for i in range(Q):
    qry = input().split()

    if qry[0] == '1':
        if flag:
            flag = 0
        else:
            flag = 1
    
    elif qry[0] == '2':
        if flag:
            if qry[1] == '1':
                S.append(qry[2])
            else:
                S.appendleft(qry[2])
        else:
            if qry[1] == '1':
                S.append(qry[2])
            else:
                S.appendleft(qry[2])

if flag:
    print(ans)
else:
    print(ans[::-1])

Buggy submission (verdict: Runtime Error):
S = input()
Q = int(input())

ans = S
flag = 1
for i in range(Q):
    qry = list(input().split())

    if qry[0] == '1' and flag:
        flag = 0
    elif qry[0] == '1' and not flag:
        flag = 1

    elif qry[0] == '2' and flag:
        if qry[1] == '1':
            ans = qry[2] + ans
        elif qry[1] == '2':
            ans += qry[2]
    elif qry[0] == '2' and not flag:
        if qry[1] == '1':
            ans += qry[2]
        elif qry[1] == '2':
            ans = qry[2] + ans

if flag:
    print(ans)
else:
    for i in range(len(ans)//2):
        ans[i], ans[-1-i] = ans[-1-i], ans[i]

    print(ans)

Buggy submission (verdict: Runtime Error):
S = input()
Q = int(input())

ans = S
flag = 1
for i in range(Q):
    qry = list(input().split())

    if qry[0] == '1' and flag:
        flag = 0
    elif qry[0] == '1' and not flag:
        flag = 1

    elif qry[0] == '2' and flag:
        if qry[1] == '1':
            ans = qry[2] + ans
        elif qry[1] == '2':
            ans += qry[2]
    elif qry[0] == '2' and not flag:
        if qry[1] == '1':
            ans += qry[2]
        elif qry[1] == '2':
            ans = qry[2] + ans

if flag:
    print(ans)
else:
    for i in range(len(ans//2)):
        ans[i], ans[-1-i] = ans[-1-i], ans[i]

    print(ans)