Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
from bisect import bisect_left, bisect_right
from collections import Counter, defaultdict, deque, OrderedDict
from copy import deepcopy
from functools import lru_cache, reduce
from math import ceil, floor

import heapq
import itertools
import operator


inf = float('inf')


def get_int():
    return int(input())


def get_str():
    return input().strip()


def get_list_of_int():
    return [int(i) for i in input().split()]


def get_char_list():
    return list(input().strip())


# inputs
A, B, Q = 0, 0, 0
S = []
T = []
X = []


def set_inputs():
    global A, B, Q, S, T, X
    A, B, Q = get_list_of_int()
    for _ in range(A):
        S.append(get_int())
    for _ in range(B):
        T.append(get_int())
    for _ in range(Q):
        X.append(get_int())


def main():
    set_inputs()

    for i in range(Q):
        ns = abs(max([S[j] - X[i] for j in range(A) if S[j] - X[i] <= 0] + [-inf]))
        ps = abs(min([S[j] - X[i] for j in range(A) if S[j] - X[i] >= 0] + [inf]))
        nt = abs(max([T[j] - X[i] for j in range(B) if T[j] - X[i] <= 0] + [-inf]))
        pt = abs(min([T[j] - X[i] for j in range(B) if T[j] - X[i] >= 0] + [inf]))
        print(min(max(ns, nt), max(ps, pt), ns * 2 + pt, ns + pt * 2, nt * 2 + ps, nt + ps * 2))


if __name__ == '__main__':
    main()


Fixed submission:
from bisect import bisect_left, bisect_right
from collections import Counter, defaultdict, deque, OrderedDict
from copy import deepcopy
from functools import lru_cache, reduce
from math import ceil, floor

import heapq
import itertools
import operator


inf = float('inf')


def get_int():
    return int(input())


def get_str():
    return input().strip()


def get_list_of_int():
    return [int(i) for i in input().split()]


def get_char_list():
    return list(input().strip())


# inputs
A, B, Q = 0, 0, 0
S = []
T = []
X = []


def set_inputs():
    global A, B, Q, S, T, X
    A, B, Q = get_list_of_int()
    for _ in range(A):
        S.append(get_int())
    for _ in range(B):
        T.append(get_int())
    for _ in range(Q):
        X.append(get_int())


def main():
    set_inputs()

    for i in range(Q):
        nsi = bisect_left(S, X[i])
        if nsi == 0:
            ns = inf
        else:
            ns = X[i] - S[nsi-1]
        psi = bisect_left(S, X[i])
        if psi == A:
            ps = inf
        else:
            ps = S[nsi] - X[i]
        nti = bisect_left(T, X[i])
        if nti == 0:
            nt = inf
        else:
            nt = X[i] - T[nti-1]
        pti = bisect_left(T, X[i])
        if pti == B:
            pt = inf
        else:
            pt = T[nti] - X[i]
        print(min(max(ns, nt), max(ps, pt), ns * 2 + pt, ns + pt * 2, nt * 2 + ps, nt + ps * 2))


if __name__ == '__main__':
    main()
Buggy python submission (verdict: Runtime Error):
def main():
  n, h, w = map(int, input().strip().split())
  print((n-h+1)*(n-w+1))


if __name__ == '__main__':
  main()


Fixed submission:
def main():
  n, h, w = int(input()), int(input()), int(input())
  print((n-h+1)*(n-w+1))


if __name__ == '__main__':
  main()
Buggy python submission (verdict: Time Limit Exceeded):
from bisect import bisect_left, bisect_right
from collections import Counter, defaultdict, deque, OrderedDict
from copy import deepcopy
from functools import lru_cache, reduce
from math import ceil, floor

import heapq
import itertools
import operator


inf = float('inf')


def get_int():
    return int(input())


def get_str():
    return input().strip()


def get_list_of_int():
    return [int(i) for i in input().split()]


def get_char_list():
    return list(input().strip())


# inputs
N, W = 0, 0
Ws, Vs = [0], [0]


def set_inputs():
    global N, W, Ws, Vs
    N, W = get_list_of_int()
    ws, vs = [], []
    for _ in range(N):
        w, v = get_list_of_int()
        ws.append(w)
        vs.append(v)
    Ws, Vs = ws, vs


def main():
    set_inputs()
    values = [0] * (W + 1)
    items = [set()] * (W + 1)
    for w in range(1, W + 1):
        values[w], items[w] = max((values[w - Ws[i]] + Vs[i], items[w - Ws[i]] | {i}) if w - Ws[i] >= 0 and i not in items[w - Ws[i]] else (values[w-1], items[w-1]) for i in range(N))
    print(values[W])


if __name__ == '__main__':
    main()


Fixed submission:
from bisect import bisect_left, bisect_right
from collections import Counter, defaultdict, deque, OrderedDict
from copy import deepcopy
from functools import lru_cache, reduce
from math import ceil, floor

import heapq
import itertools
import operator


inf = float('inf')


def get_int():
    return int(input())


def get_str():
    return input().strip()


def get_list_of_int():
    return [int(i) for i in input().split()]


def get_char_list():
    return list(input().strip())


# inputs
N, W = 0, 0
Ws, Vs = [0], [0]


def set_inputs():
    global N, W, Ws, Vs
    N, W = get_list_of_int()
    ws, vs = [], []
    for _ in range(N):
        w, v = get_list_of_int()
        ws.append(w)
        vs.append(v)
    Ws, Vs = ws, vs


def main():
    set_inputs()
    values = [0] * (W + 1)
    items = [0] * (W + 1)
    for w in range(1, W + 1):
        values[w], items[w] = max((values[w - Ws[i]] + Vs[i], items[w - Ws[i]] | 1 << i) if w - Ws[i] >= 0 and (items[w - Ws[i]] & 1 << i) == 0 else (values[w-1], items[w-1]) for i in range(N))
    print(values[W])


if __name__ == '__main__':
    main()
Buggy python submission (verdict: Runtime Error):
from bisect import bisect_left, bisect_right
from collections import Counter, defaultdict, deque, OrderedDict
from copy import deepcopy
from functools import lru_cache, reduce
from math import ceil, floor
from sys import setrecursionlimit

import heapq
import itertools
import operator

from fraction import gcd


inf = float('inf')


# globals
N, X = 0, 0
C = []


def set_inputs():
    global N, X, C
    N, X = get_li()
    C = get_li()
    return


def main():
    setrecursionlimit(100000)
    set_inputs()
    ans = reduce(gcd, filter(lambda x: x != 0, map(lambda x: abs(x-X), C)))
    print(ans)
    return


def get_int():
    return int(input())


def get_float():
    return float(input())


def get_str():
    return input().strip()


def get_li():
    return [int(i) for i in input().split()]


def get_lf():
    return [float(f) for f in input().split()]


def get_lc():
    return list(input().strip())


def get_data(n, types):
    if len(types) == 1:
        return [types[0](input()) for _ in range(n)]
    return zip(*(
        [t(x) for t, x in zip(types, input().split())]
        for _ in range(n)
    ))


if __name__ == '__main__':
    main()


Fixed submission:
from bisect import bisect_left, bisect_right
from collections import Counter, defaultdict, deque, OrderedDict
from copy import deepcopy
from functools import lru_cache, reduce
from math import ceil, floor
from sys import setrecursionlimit

import heapq
import itertools
import operator

from fractions import gcd


inf = float('inf')


# globals
N, X = 0, 0
C = []


def set_inputs():
    global N, X, C
    N, X = get_li()
    C = get_li()
    return


def main():
    setrecursionlimit(100000)
    set_inputs()
    ans = reduce(gcd, filter(lambda x: x != 0, map(lambda x: abs(x-X), C)))
    print(ans)
    return


def get_int():
    return int(input())


def get_float():
    return float(input())


def get_str():
    return input().strip()


def get_li():
    return [int(i) for i in input().split()]


def get_lf():
    return [float(f) for f in input().split()]


def get_lc():
    return list(input().strip())


def get_data(n, types):
    if len(types) == 1:
        return [types[0](input()) for _ in range(n)]
    return zip(*(
        [t(x) for t, x in zip(types, input().split())]
        for _ in range(n)
    ))


if __name__ == '__main__':
    main()
Buggy python submission (verdict: Time Limit Exceeded):
from bisect import bisect_left, bisect_right
from collections import Counter, defaultdict, deque, OrderedDict
from copy import deepcopy
from functools import lru_cache, reduce
from math import ceil, floor
from sys import setrecursionlimit

import heapq
import itertools
import operator


inf = float('inf')


# globals
N = 0
A = []
X = []


def set_inputs():
    global N, A
    N = get_int()
    A = get_li()
    return


def f(n):
    return sum(abs(x-n) for x in X)


def main():
    global X
    setrecursionlimit(100000)
    set_inputs()
    X = [a - (i + 1) for i, a in enumerate(A)]
    b = round(float(sum(X)) / float(N))
    ans = f(b)
    a = b - 1
    c = b + 1
    while ans != min(f(a), f(b), f(c)):
        if f(a) < f(b):
            b = a
            a = b - 1
            c = b + 1
        else:
            b = c
            a = b - 1
            c = b + 1
        ans = f(b)
    print(ans)
    return


def get_int():
    return int(input())


def get_float():
    return float(input())


def get_str():
    return input().strip()


def get_li():
    return [int(i) for i in input().split()]


def get_lf():
    return [float(f) for f in input().split()]


def get_lc():
    return list(input().strip())


def get_data(n, types):
    if len(types) == 1:
        return [types[0](input()) for _ in range(n)]
    return zip(*(
        [t(x) for t, x in zip(types, input().split())]
        for _ in range(n)
    ))


if __name__ == '__main__':
    main()


Fixed submission:
from bisect import bisect_left, bisect_right
from collections import Counter, defaultdict, deque, OrderedDict
from copy import deepcopy
from functools import lru_cache, reduce
from math import ceil, floor
from sys import setrecursionlimit

import heapq
import itertools
import operator


inf = float('inf')


# globals
N = 0
A = []
X = []


def set_inputs():
    global N, A
    N = get_int()
    A = get_li()
    return


def f(n):
    return sum(abs(x-n) for x in X)


def main():
    global X
    setrecursionlimit(100000)
    set_inputs()
    X = [a - (i + 1) for i, a in enumerate(A)]
    X.sort()
    b = X[0]
    i = 1
    passed = 0
    same = 1
    coming = N - 1
    ans = f(b)
    tmp = ans
    while i < N:
        if X[i] == b:
            same += 1
            coming -= 1
            i += 1
            continue
        diff = X[i] - b
        tmp = tmp + (passed + same - coming) * diff
        ans = min(ans, tmp)
        b = X[i]
        passed += same
        same = 1
        coming -= 1
        i += 1
    print(ans)
    return


def get_int():
    return int(input())


def get_float():
    return float(input())


def get_str():
    return input().strip()


def get_li():
    return [int(i) for i in input().split()]


def get_lf():
    return [float(f) for f in input().split()]


def get_lc():
    return list(input().strip())


def get_data(n, types):
    if len(types) == 1:
        return [types[0](input()) for _ in range(n)]
    return zip(*(
        [t(x) for t, x in zip(types, input().split())]
        for _ in range(n)
    ))


if __name__ == '__main__':
    main()
Buggy python submission (verdict: Runtime Error):
a, b = map(int, input().stirp().split())
print((a + b + 2 -1) // 2)

Fixed submission:
a, b = map(int, input().strip().split())
print((a + b + 2 -1) // 2)
Buggy python submission (verdict: Runtime Error):
n = int(input())
arr = map(int, input().strip().split())
arr.sort(reverse=True)
print(sum(arr[1:2*n:2]))

Fixed submission:
n = int(input())
arr = list(map(int, input().strip().split()))
arr.sort(reverse=True)
print(sum(arr[1:2*n:2]))
Buggy python submission (verdict: Runtime Error):
var = input()

pas = var ** var

print(pas)

Fixed submission:
var = int(input())

pas = var ** 3

print(pas)

Buggy python submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-

a = N * N * N
# 出力
print(a)

Fixed submission:
a = int(input())
print(a*a*a)
Buggy python submission (verdict: Runtime Error):
a,b,c,d = map(int,input().split())
if a+b>c+d:
  print("Left")
elif a+b=c+d:
  print("Balanced")
else:
  print("Right")


Fixed submission:
a,b,c,d = map(int,input().split())
if a+b>c+d:
  print("Left")
elif a+b==c+d:
  print("Balanced")
else:
  print("Right")
Buggy python submission (verdict: Runtime Error):
n,k = map(int,input().split())
a = [int(i) for i in input().split()]
hash = [0 for i in range(n+1)]
#dic = {a[i]:count}
if len(set(a))<=k:
  print(0)
  exit()
else:
  ans=0
  for i in a:
    hash[i]+=1
  L = list(set(hash))
  x = len(set(a)) - k
  for i in range(x+1):
    ans+=L[i]
  print(ans)


Fixed submission:
n,k = map(int,input().split())
a = [int(i) for i in input().split()]
hash = [0 for i in range(n+1)]

if len(set(a))<=k:
  print(0)
  exit()
else:
  ans=0
  for i in a:
    hash[i]+=1
  hash.sort()
  L=hash
  #何種類減らすかカウントするx
  x = len(set(a)) - k
  j=0
  m=0
  while m!=x:
    if L[j]==0:
      j+=1
      continue
    else:
      ans+=L[j]
      j+=1
      m+=1
  print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
a=[]
for i in range(n):
  x=int(input())
  a.append(x)
ans=0
a_set=set(a)
for i in a_set:
  if a.count(i)%2==1:
    ans+=1
print(ans)
  

Fixed submission:
import sys
n = int(input())
a = [int(i) for i in sys.stdin]
a.sort()
dict = {}
for i in range(n):
  if a[i] in dict:
    del dict[a[i]]
  else: 
  	dict[a[i]]=0
print(len(dict))

Buggy python submission (verdict: Time Limit Exceeded):
import sys
n = int(input())
a = [int(i) for i in sys.stdin]
a.sort()
b = list(set(a))
count=0
for i in range(len(b)):
  if a.count(b[i])%2!=0:
    count+=1
print(count)

    


Fixed submission:
import sys
n = int(input())
a = [int(i) for i in sys.stdin]
a.sort()
dict = {}
for i in range(n):
  if a[i] in dict:
    del dict[a[i]]
  else: 
  	dict[a[i]]=0
print(len(dict))

Buggy python submission (verdict: Time Limit Exceeded):
import sys
n = int(input())
a = [int(i) for i in sys.stdin]
a.sort()
b = list(set(a))
count=0
for i in range(len(b)):
  if a.count(b[i])%2!=0:
    count+=1
print(count)

    

Fixed submission:
import sys
n = int(input())
a = [int(i) for i in sys.stdin]
a.sort()
dict = {}
for i in range(n):
  if a[i] in dict:
    del dict[a[i]]
  else: 
  	dict[a[i]]=0
print(len(dict))
Buggy python submission (verdict: Runtime Error):
r,g,b = map(int,input().split())
print("YES" if (100*r+10*g+b)%4=0 else("NO")

Fixed submission:
r,g,b = map(int,input().split())
print("YES" if (100*r+10*g+b)%4==0 else("NO"))

Buggy python submission (verdict: Runtime Error):
r,g,b = map(int,input().split())
print("YES" if 100*r+10*g+b%4=0 else("NO")

Fixed submission:
r,g,b = map(int,input().split())
print("YES" if (100*r+10*g+b)%4==0 else("NO"))
Buggy python submission (verdict: Runtime Error):
x,y = map(int,input().split())
A = (2)
B = (4,6,9,11)
C = (1,3,5,7,8,10,12)
if x in A and y in B:
  print("Yes")
else if x in B and y in B:
  print("Yes")
else if x in C and y in C:
  print("Yes")
else:
  print("No")

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

B = (4,6,9,11)
C = (1,3,5,7,8,10,12)
if x==y==2:
  print("Yes")
elif x in B and y in B:
  print("Yes")
elif x in C and y in C:
  print("Yes")
else:
  print("No")
Buggy python submission (verdict: Runtime Error):
O = input()
E = input()
str = ""
i = 0
while True:
  str = str + O[i]
  if len(E)-1<i:
    exit(1)
  str = str + E[i]
  i+=1
  
print(str)

Fixed submission:
O = input()
E = input()
str = ""
i = 0
while True:
  str += O[i]
  str += E[i]
  i+=1
  if len(E)-1<i:break
if len(O)-len(E)==1:
  str+=O[-1]
print(str)

Buggy python submission (verdict: Runtime Error):
O = input()
E = input()
str = ""
i = 0
while True:
  str = str + O[i]
  if len(E)-1<i:
    break
  str = str + E[i]
  i+=1
  
print(str)

Fixed submission:
O = input()
E = input()
str = ""
i = 0
while True:
  str += O[i]
  str += E[i]
  i+=1
  if len(E)-1<i:break
if len(O)-len(E)==1:
  str+=O[-1]
print(str)
Buggy python submission (verdict: Time Limit Exceeded):
def F(a,b):
  m = max(a,b)
  count=1
  while m//10!=0:
    count+=1
    m//=10
  return count

N = int(input())
tmp=F(1,N)
for i in range(1,N//2+1):
  if N%i==0:
    if tmp>F(i,N//i):
      tmp = F(i,N//i)
print(tmp)
  

Fixed submission:
def F(a,b):
  m = max(a,b)
  count=1
  while m//10!=0:
    count+=1
    m//=10
  return count

N = int(input())
tmp=F(1,N)
for i in range(round(N**0.5),1,-1):
  if N%i==0:
    if tmp>F(i,N//i):
      tmp = F(i,N//i)
      break
print(tmp)
Buggy python submission (verdict: Runtime Error):
a,b = input().split()
if a=="H"and b=="H":
  print("H")
elif a=="H" and b=="D":
  print("D")
elif a=="D" and b=="H":
  print("D")
elif a=="D" and b=="D":
  print(")
  

Fixed submission:
a,b = input().split()
if a=="H"and b=="H":
  print("H")
elif a=="H" and b=="D":
  print("D")
elif a=="D" and b=="H":
  print("D")
elif a=="D" and b=="D":
  print("H")
Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
sum=1
mod=10**9+7
for i in range(1,N+1):
  sum*=i
print(sum%mod)

Fixed submission:
N=int(input())
sum=1
mod=10**9+7
for i in range(1,N+1):
  sum*=i
  sum%=mod
print(sum)
Buggy python submission (verdict: Runtime Error):
print(“ABC” if int(input())<1200 else(“ARC”))


Fixed submission:
print("ABC" if int(input())<1200 else("ARC"))

Buggy python submission (verdict: Runtime Error):
print(“ABC” if int(input())<1200 else(“ARC”))

Fixed submission:
print("ABC" if int(input())<1200 else("ARC"))

Buggy python submission (verdict: Runtime Error):
print(“ABC” if int(input()) <=1200 else(“ARC”))

Fixed submission:
print("ABC" if int(input())<1200 else("ARC"))
Buggy python submission (verdict: Time Limit Exceeded):
x = int(input())
count = 0
sum = 0
while sum<x:
    sum+=6
    count+=1
    if sum>=x:break
    sum+=5
    count+=1
print(count)


Fixed submission:
x=int(input())
count=0
sum=0
count=(x//11)*2
if x%11!=0:
  if 7<=x%11<=10:
    count+=2
  else:
    count+=1
print(count)
Buggy python submission (verdict: Time Limit Exceeded):
K,S = map(int,input().split())
count = 0
for x in range(K+1):
    for y in range(K+1):
        for z in range(K+1):
            #print(x,y,z)
            if x+y+z==S:
                #print("x =",x,"y =",y,"z =",z)
                count+=1

print(count)



Fixed submission:
K,S = map(int,input().split())
count = 0
for x in range(K+1):
    for y in range(K+1):
       count+=(0<=S-(x+y)<=K)

print(count)
Buggy python submission (verdict: Runtime Error):
s=input().split()
print(len(set(s))

Fixed submission:
s = input().split()
count = 0
flag = False
for i in range(len(s)):
    for j in range(i+1,len(s)):
        if s[i] == s[j]:
            count-=1
    count+=1
if count == 0:
    count = 1
print(count)
Buggy python submission (verdict: Runtime Error):
w = input()
for i in range(len(w)):
    if w.count(w[i])%2 == 1:
        print("No")
        exit(1)

print("Yes")


Fixed submission:
w = [input() for i in range(4)]
N = int(w[0])
K = int(w[1])
X = int(w[2])
Y = int(w[3])

paid = 0
for i in range(1,N+1):
    if i < K+1:
        paid += X
    else:
        paid += Y

print(paid)

Buggy python submission (verdict: Runtime Error):
w = input()
for i in set(w):
    if w.count(i)%2 == 1:
        print("No")
        exit(1)

print("Yes")


Fixed submission:
w = [input() for i in range(4)]
N = int(w[0])
K = int(w[1])
X = int(w[2])
Y = int(w[3])

paid = 0
for i in range(1,N+1):
    if i < K+1:
        paid += X
    else:
        paid += Y

print(paid)

Buggy python submission (verdict: Runtime Error):
w = input()
for i in set(w):
    if w.count(i)%2 == 1:
        print("No")
        exit(-1)

print("Yes")



Fixed submission:
w = [input() for i in range(4)]
N = int(w[0])
K = int(w[1])
X = int(w[2])
Y = int(w[3])

paid = 0
for i in range(1,N+1):
    if i < K+1:
        paid += X
    else:
        paid += Y

print(paid)

Buggy python submission (verdict: Runtime Error):
w = input()
for i in set(w):
    if w.count(i)%2 == 1:
#print("No")


print("Yes")


Fixed submission:
w = [input() for i in range(4)]
N = int(w[0])
K = int(w[1])
X = int(w[2])
Y = int(w[3])

paid = 0
for i in range(1,N+1):
    if i < K+1:
        paid += X
    else:
        paid += Y

print(paid)
Buggy python submission (verdict: Runtime Error):
w = input()
for i in set(w):
    if w.count(i)%2 == 1:
        print("No")
        exit(1)

print("Yes")


Fixed submission:
w = input()
only = list(set(w))
count = 0
can = True
for i in only:
    if w.count(i) % 2 != 0:
        can = False
        break
if can:
    print('Yes')
else:
    print('No')

Buggy python submission (verdict: Runtime Error):
w = input()
for i in set(w):
    if w.count(i)%2 == 1:
        print("No")
        exit(1)

print("Yes")


Fixed submission:
w = input()
only = list(set(w))
count = 0
can = True
for i in only:
    if w.count(i) % 2 != 0:
        can = False
        break
if can:
    print('Yes')
else:
    print('No')

Buggy python submission (verdict: Runtime Error):
w = input()
for i in range(len(w)):
    if w.count(w[i])%2 == 1:
        print("No")
        exit(1)

print("Yes")


Fixed submission:
w = input()
only = list(set(w))
count = 0
can = True
for i in only:
    if w.count(i) % 2 != 0:
        can = False
        break
if can:
    print('Yes')
else:
    print('No')
Buggy python submission (verdict: Runtime Error):
s = input()
str = ""
count = 0
for i in range(len(s)):
    #print("str",str)
    if s[i] == "0":
        str += s[i]
        count += 1
    elif s[i] == "1":
        str += s[i]
        count += 1
    elif s[i] == "B":
        if count > 0:
            str = str.rstrip(str[count-1])
            count -= 1


print(str)


Fixed submission:
s = input()
str = ""
count = 0
for i in range(len(s)):
    #print("count",count)
    if s[i] == "0":
        str += s[i]
        count += 1
    elif s[i] == "1":
        str += s[i]
        count += 1
    elif s[i] == "B":
        if count > 0:
            str = str[:-1]
            count -= 1
#print("str",str)


print(str)
Buggy python submission (verdict: Runtime Error):
while True:
    n = int(input())
    if n < 1 or n > 9:
        continue
    else:
        print(n**3)

Fixed submission:
n = int(input())
if n >= 1 and n <= 9:
    print(n**3)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
uw = []
S = []
c = 0
for i in range(N):
    s = sorted(input())
    if s not in uw:
        uw.append(s)
        
    S.append(s)

for w in uw:
    n = S.count(w)
    if n == 1:
        c += 0
    elif n == 2:
        c += 1
        
    else:
        c += (n - 1)*(2 + (n - 2))//2
    
print(int(c))

Fixed submission:
N = int(input())
c = {}
for i in range(N):
    s = ''.join(sorted(input()))
    if s not in c:
        c[s] = 0
    else:
        c[s] += 1
r = sum([(v/2)*(2 + v - 1) for v in c.values()])
print(int(r))

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
S = [sorted(input()) for i in range(N)]
c = 0
for i in range(N):
    for j in range(N - i - 1):
        if S[i] == S[i + 1 + j]:
            c += 1           
print(c)

Fixed submission:
N = int(input())
c = {}
for i in range(N):
    s = ''.join(sorted(input()))
    if s not in c:
        c[s] = 0
    else:
        c[s] += 1
r = sum([(v/2)*(2 + v - 1) for v in c.values()])
print(int(r))
Buggy python submission (verdict: Runtime Error):
import math

A, B, C, D = [int(i) for i in input().split()]

lcm_CD = (C*D)//math.gcd(C, D)

C_bot = C * -(-A//C) 
C_top = C * (B//C) 
D_bot = D * -(-A//D)
D_top = D * (B//D)
CD_bot = lcm_CD * -(-A//(lcm_CD ))
CD_top = lcm_CD  * (B//(lcm_CD ))

num_A_B = B - A + 1
num_divC = (C_top - C_bot)//C + 1
num_divD = (D_top - D_bot)//D + 1
num_divCD = (CD_top - CD_bot)//(lcm_CD ) + 1
ans = num_A_B - num_divC - num_divD + num_divCD


print(int(ans))

Fixed submission:
import fractions

A, B, C, D = [int(i) for i in input().split()]

lcm_CD = (C*D)//fractions.gcd(C, D)

C_bot = C * -(-A//C) 
C_top = C * (B//C) 
D_bot = D * -(-A//D)
D_top = D * (B//D)
CD_bot = lcm_CD * -(-A//(lcm_CD ))
CD_top = lcm_CD  * (B//(lcm_CD ))

num_A_B = B - A + 1
num_divC = (C_top - C_bot)//C + 1
num_divD = (D_top - D_bot)//D + 1
num_divCD = (CD_top - CD_bot)//(lcm_CD ) + 1
ans = num_A_B - num_divC - num_divD + num_divCD


print(int(ans))