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

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

c = Counter(A)
hen = [(key, val) for key, val in c.items() if val > 1]

l = max(hen) if hen else 0
if l != 0:
    if c[l] > 3:
        s = l
    else:
        hen.remove(l)
        s = max(hen) if hen else 0
else:
    s = 0

print(l * s)


Fixed submission:
from collections import Counter

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

c = Counter(A)
hen = [key for key, val in c.items() if val > 1]

l = max(hen) if hen else 0
if l != 0:
    if c[l] > 3:
        s = l
    else:
        hen.remove(l)
        s = max(hen) if hen else 0
else:
    s = 0

print(l * s)
Buggy python submission (verdict: Time Limit Exceeded):
N, M = map(int, input().split())

one2 = []
toN = []

for _ in range(M):
    a, b = map(int, input().split())

    if a == 1:
        one2.append(b)

    if b == N:
        toN.append(a)

flag = False
for a in one2:
    if a in toN:
        flag = True
        break

if flag:
    print("POSSIBLE")
else:
    print("IMPOSSIBLE")


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

one2 = set()
toN = set()

for _ in range(M):
    a, b = map(int, input().split())

    if a == 1:
        one2.add(b)

    if b == N:
        toN.add(a)

inter = one2 & toN

if len(inter) > 0:
    print("POSSIBLE")
else:
    print("IMPOSSIBLE")
Buggy python submission (verdict: Runtime Error):
W, H, N = map(int, input().split())
min_H = 0
min_W = 0
max_H = H
max_W = W

for _ in range(N):
    x, y, a = map(int, input().split())

    if a == 1:
        min_W = x
    elif a == 2:
        max_W = x
    elif a == 3:
        min_H = y
    else:
        max_H = y

print(max(((max_H - min_H) * (max_W - min_W)), 0)


Fixed submission:
W, H, N = map(int, input().split())
min_H = 0
min_W = 0
max_H = H
max_W = W

for _ in range(N):
    x, y, a = map(int, input().split())

    if a == 1:
        min_W = max(x, min_W)
    elif a == 2:
        max_W = min(x, max_W)
    elif a == 3:
        min_H = max(y, min_H)
    else:
        max_H = min(y, max_H)

if min_W > max_W or min_H > max_H:
    print(0)
else:
    print((max_H - min_H) * (max_W - min_W))
Buggy python submission (verdict: Time Limit Exceeded):
import sys

sys.setrecursionlimit(10 ** 6)
INF = float("inf")
MOD = 10 ** 9 + 7


def input():
    return sys.stdin.readline().strip()


def main():
    N = int(input())
    TA = []
    for _ in range(N):
        t, a = map(int, input().split())
        TA.append((t, a))

    x, y = TA[0]
    for i in range(1, N):
        t, a = TA[i]

        tmp_x = t
        tmp_y = a
        while tmp_x < x or tmp_y < y:
            tmp_x += t
            tmp_y += a

        x = tmp_x
        y = tmp_y

    ans = x + y
    print(ans)


if __name__ == "__main__":
    main()


Fixed submission:
import sys

sys.setrecursionlimit(10 ** 6)
INF = float("inf")
MOD = 10 ** 9 + 7


def input():
    return sys.stdin.readline().strip()


def main():
    N = int(input())
    TA = []
    for _ in range(N):
        t, a = map(int, input().split())
        TA.append((t, a))

    A, B = 1, 1
    for i in range(N):
        x, y = TA[i]
        n = max((A + x - 1) // x, (B + y - 1) // y,)
        A = n * x
        B = n * y

    ans = A + B
    print(ans)


if __name__ == "__main__":
    main()
Buggy python submission (verdict: Time Limit Exceeded):
import sys

sys.setrecursionlimit(10 ** 6)
INF = float("inf")
MOD = 10 ** 9 + 7


def input():
    return sys.stdin.readline().strip()


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

    # dp[i][k][s] := i個までみて，それまでにk選んでて，そのときの総和がsとなる物の総数
    dp = [[[0] * (N * A + 1) for _ in range(N + 1)] for _ in range(N + 1)]

    dp[0][0][0] = 1
    for i in range(N):
        for k in range(N):
            for s in range(N * A + 1):
                # 使わない
                dp[i + 1][k][s] += dp[i][k][s]

                # 使う
                if s + X[i] <= N * A:
                    dp[i + 1][k + 1][s + X[i]] += dp[i][k][s]

    ans = 0
    for i in range(1, N + 1):
        ans += dp[-1][i][i * A]

    print(ans)


if __name__ == "__main__":
    main()


Fixed submission:
import sys

sys.setrecursionlimit(10 ** 6)
INF = float("inf")
MOD = 10 ** 9 + 7


def input():
    return sys.stdin.readline().strip()


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

    # dp[i][k][s] := i個までみて，それまでにk選んでて，そのときの総和がsとなる物の総数
    dp = [[[0] * (N * A + 1) for _ in range(N + 1)] for _ in range(N + 1)]

    dp[0][0][0] = 1
    for i in range(N):
        for k in range(N):
            for s in range(N * A + 1):
                # 使わない
                dp[i + 1][k][s] += dp[i][k][s]

                # 使う
                if s + X[i] <= N * A:
                    dp[i + 1][k + 1][s + X[i]] += dp[i][k][s]

    ans = 0
    for i in range(1, N + 1):
        ans += dp[-1][i][i * A]

    print(ans)


if __name__ == "__main__":
    main()
Buggy python submission (verdict: Runtime Error):
n = int(input())
c = ','.join(input()).split(',')

ans = 0

ri = -1

for i in range(n):
    if c[i] == 'W':
        while c[ri] != 'R':
            ri -= 1
        
        if n < i-ri:
            break
        
        c[i], c[ri] = 'R', 'W'
        ans += 1
    
print(ans)

Fixed submission:
n = int(input())
c = ','.join(input()).split(',')

ans = 0

ri = -1

if c.count('W') == 0:
    print(0)
    exit()

if c.count('R') == 0:
    print(0)
    exit()

for i in range(n):
    if c[i] == 'W':
        while c[ri] != 'R':
            ri -= 1
        
        if n < i-ri:
            break
        
        c[i], c[ri] = 'R', 'W'
        ans += 1
    
print(ans)
Buggy python submission (verdict: Runtime Error):
N, Q = map(int, input().split())

def find(nodes, key):
  if len(nodes[key]) == 1:
    return [key]
  else:
    x = [key]
    for node in nodes[key]:
      if key != node:
        x.extend(find(nodes, node))
    return x

nodes = {}
nodes_p = {}
for _ in range(N-1):
  a,b = map(int, input().split())
  if a in nodes:
    nodes[a].append(b)
  else:
    nodes_p[a] = 0
    nodes[a] = [a]
    nodes[a].append(b)

  if b not in nodes:
    nodes_p[b] = 0
    nodes[b] = [b]

for key in nodes:
  nodes[key] = find(nodes, key)

for _ in range(Q):
  p, x = map(int, input().split())
  for key in nodes[p]:
    nodes_p[key] += x

print(" ".join(map(str, [ v for v in nodes_p.values()])))


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

nodes = [0 for _ in range(N)]

parents = {}
for _ in range(N-1):
  a, b = map(int, input().split())
  parents[b] = a

for _ in range(Q):
  p, x = map(int, input().split())
  nodes[p-1] += x

for i in range(N):
  if i+1 in parents:
    nodes[i] += nodes[parents[i+1]-1]

print(" ".join(map(str, nodes)))

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

def find(nodes, dp, key):
  if len(nodes[key]) == 1:
    return [key]
  else:
    x = [key]
    for node in nodes[key]:
      if key != node:
        if node in dp:
          x.extend(dp[node])
        else:
          x.extend(find(nodes, dp, node))
    return x

nodes = {}
nodes_p = {}
for _ in range(N-1):
  a,b = map(int, input().split())
  if a in nodes:
    nodes[a].append(b)
  else:
    nodes_p[a] = 0
    nodes[a] = [a]
    nodes[a].append(b)

  if b not in nodes:
    nodes_p[b] = 0
    nodes[b] = [b]

dp = {}
for _ in range(Q):
  p, x = map(int, input().split())
  if p in dp:
    for key in dp[p]:
      nodes_p[key] += x
  else:
    dp[p] = find(nodes, dp, p)
    for key in dp[p]:
      nodes_p[key] += x

print(" ".join(map(str, [ v for v in nodes_p.values()])))


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

nodes = [0 for _ in range(N)]

parents = {}
for _ in range(N-1):
  a, b = map(int, input().split())
  parents[b] = a

for _ in range(Q):
  p, x = map(int, input().split())
  nodes[p-1] += x

for i in range(N):
  if i+1 in parents:
    nodes[i] += nodes[parents[i+1]-1]

print(" ".join(map(str, nodes)))
Buggy python submission (verdict: Runtime Error):
import math

N = int(input())
s = ["".join(sorted(input())) for _ in range(N)]
cnt = 0

for c in s:
  if len(s) == 0:
    break
  amnt = len(list(filter(lambda x: x == c, s[s.index(c)+1:])))
  cnt += amnt
  cnt += (sum(range(1, amnt)))
  s = list(filter(lambda x: x != c, s))

print(cnt)

Fixed submission:
N = int(input())
s = ["".join(sorted(input())) for _ in range(N)]

mp = {}
for c in s:
    if c in mp:
        mp[c] += 1
    else:
        mp[c] = 1

ans = 0
for key in mp.keys():
    ans += mp[key]*(mp[key]-1)/2
print(int(ans))
Buggy python submission (verdict: Runtime Error):
N,M = map(int, input().split())
W = {}
for _ in range(N):
  a,b = map(int, input().split())
  if a in W:
    W[a].append(b)
  else:
    W[a] = [b]

ans = 0
for i in range(1, M+1):
  for j in range(1, i):
    if j in W.keys():
      ans += max(W[j])
      W[j].remove(max(W[j]))
print(ans)

Fixed submission:
import heapq

N,M = map(int, input().split())

jobs = {}
for _ in range(N):
  a,b = map(int, input().split())
  if a > M:
    continue
  if M - a in jobs:
    jobs[M-a].append(b)
  else:
    jobs[M-a] = [b]

q = []
heapq.heapify(q)

ans = 0
for i in reversed(range(0, M)):
  if i in jobs.keys():
    for job in jobs[i]:
      heapq.heappush(q, (-job, job))
  
  if len(q) > 0:
    ans += heapq.heappop(q)[1]

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
a = []
for i in range(0, N):
  a.append(int(input()))

first_max = max(a)

former_arr = [0] + a[0:a.index(first_max)]
latter_arr = [0] + a[a.index(first_max) + 1:]
second_max = (max(max(former_arr), max(latter_arr)))

for i in range(0, N):  
  if (a.index(first_max) == i):
    print(second_max)
  else:
    print(first_max)

Fixed submission:
N = int(input())
a = []
for i in range(0, N):
  a.append(int(input()))

first_max = max(a)

former_arr = [0] + a[0:a.index(first_max)]
latter_arr = [0] + a[a.index(first_max) + 1:]
second_max = (max(max(former_arr), max(latter_arr)))

ans = ""
ans += (str(first_max) + '\n') * (a.index(first_max))
ans += (str(second_max) + '\n')
ans += (str(first_max) + '\n') * (N - a.index(first_max) - 1)
print(ans.rstrip('\n'))

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
a = []
for i in range(0, N):
  a.append(int(input()))

first_max = 0
latter_max = max(a[1:])

for i in range(0, N - 1):
  if i > 0:
    first_max = max(first_max, a[i-1])
  if latter_max == a[i]:
    latter_max = max(a[i+1:])
  print(max(first_max, latter_max))

print(max(a[:-1]))

Fixed submission:
N = int(input())
a = []
for i in range(0, N):
  a.append(int(input()))

first_max = max(a)

former_arr = [0] + a[0:a.index(first_max)]
latter_arr = [0] + a[a.index(first_max) + 1:]
second_max = (max(max(former_arr), max(latter_arr)))

ans = ""
ans += (str(first_max) + '\n') * (a.index(first_max))
ans += (str(second_max) + '\n')
ans += (str(first_max) + '\n') * (N - a.index(first_max) - 1)
print(ans.rstrip('\n'))
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())

def f(a, b):
  return len(list(a)) if len(list(a)) > len(list(b)) else len(list(b))

min_x = len(list(str(N)))

for i in range(1, N // 2 + 1):
  if N % i == 0:
    min_x = min(min_x, f(str(i), str(N // i)))
    if len(str(i)) >= len(str(N // i)):
      break
print(min_x)


Fixed submission:
import math

def f(a, b):
  return len(list(str(max(a, b))))

N = int(input())

ans = len(str(N))
for i in range(1, int(math.sqrt(N)) + 1):
  if N % i == 0:
    ans = min(ans, f(i, N // i))
print(ans)
Buggy python submission (verdict: Runtime Error):
N, M = map(int, input().split())

a = []
for x in range(0, N):
  a.append(input())

b = []
for x in range(0, M):
  b.append(input())

for i in range(0, len(a)):
  found = a[i].find(b[0])
  if found != -1:
    tmp = []
    for j in range(i, len(b)+1):
      tmp.append(a[j][found:found+M])
    if "".join(tmp) ==  "".join(b):
      print("Yes")
      exit()
  
print("No")


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

a = []
for x in range(0, N):
  a.append(input())

b = []
for x in range(0, M):
  b.append(input())

exists = []
for i in range(0, len(a)):
  exists.append([i, a[i].find(b[0])])

for x, y in exists:
  ari = []
  for i in range(0, len(b)):
    if x+i < len(a):
      ari.append(a[x+i][y:y+M])
  if "".join(ari) == "".join(b):
    print("Yes")
    exit()

print("No")
Buggy python submission (verdict: Runtime Error):
from math import sqrt
n, d = map(int,input().split())
a = [map(int,input().split()) for _ in range(n)]
cnt = 0
for i in range(n):
  if pow(d,2) >= pow(a[i][0],2) + pow(a[i][1],2):
    cnt += 1
print(cnt)

Fixed submission:
n,d = map(int,input().split())
cnt = 0
for i in range(n):
  a,b =map(int,input().split())
  if pow(d,2) >= pow(a,2) + pow(b,2):
  	cnt += 1
print(cnt)
Buggy python submission (verdict: Runtime Error):
n = int(input().rstrip())
s = [str(input().rstrip()) for i in range(n)]
print("AC ×",s.count("AC"))
print("WA ×",s.count("WA"))
print("TLE ×",s.count("TLE"))
print("RE ×",s.count("RE"))

Fixed submission:
a = int(input().rstrip())
n = [i for i in range(1,11) if(a <=i *1000)]
print((min(n)*1000) - a)
Buggy python submission (verdict: Runtime Error):
n = int(input().rstrip())
s = [str(input().rstrip()z) for i in range(n)]
for v in ["AC","WE","TLE","RE"]
         print(f"{v} x {s.count(v)}")
  

Fixed submission:
n = int(input().rstrip())
s = [str(input().rstrip()) for i in range(n)]
for v in ["AC","WA","TLE","RE"]:
         print(f"{v} x {s.count(v)}")
Buggy python submission (verdict: Runtime Error):
x,y,z =map(int,input().splilt())
t=0
t=x;x=y;y=t;
t=x;x=z;z=t;
print(x,y,z)

Fixed submission:
x,y,z =map(int,input().split())
t=0
t=x;x=y;y=t;
t=x;x=z;z=t;
print(x,y,z)
Buggy python submission (verdict: Time Limit Exceeded):
n,k =map(int,input().split())
x1,x2,cnt =n,0,0
if n%k==0:
  print(0)
else:  
  while True:
    x2 = abs(x1-k)
    if min(x1,x2) ==x1:
      print(x1)
      break
    x1=x2

Fixed submission:
n,k =map(int,input().split())
if n%k==0:
  print(0)
else:
  print(min(n%k,abs((n%k)-k)))
Buggy python submission (verdict: Runtime Error):
S = map(str,input().split())
s =1
for i in S:
	if i in "+":
		s +=1  
	else:
    	s -=1
print(s)


Fixed submission:
a =input()
s = 0
for i in a:
  if i in "+":
    s +=1
  else:
    s -=1
print(s)
Buggy python submission (verdict: Runtime Error):
    a,b,x = map(int,input().split())
    print("YES" if (a+b)>=x else "NO")

Fixed submission:
a,b,x = map(int,input().split())
print("YES" if a<=x and (a+b)>=x else "NO")
Buggy python submission (verdict: Runtime Error):
c1 = input().split()
c2 = input().split()
c3 = input().split()
print(c1[0]+c2[1]+c3[2])

Fixed submission:
c1 = input()
c2 = input()
c3 = input()
print(c1[0]+c2[1]+c3[2])

Buggy python submission (verdict: Runtime Error):
c1 = input().split()
c2 = input().split()
c3 = input().split()
print(c1[0]+c2[1]+c3[3])

Fixed submission:
c1 = input()
c2 = input()
c3 = input()
print(c1[0]+c2[1]+c3[2])
Buggy python submission (verdict: Runtime Error):
x,a,b = map(int,input().split())
print((x-a)%b)

Fixed submission:
x=int(input())
a=int(input())
b=int(input())
print((x-a)%b)
Buggy python submission (verdict: Runtime Error):
a.b =map(int,input().split())
print("Odd" if (a*b)%2!=0 else "Even")

Fixed submission:
a,b =map(int,input().split())
print("Odd" if (a*b)%2!=0 else "Even")
Buggy python submission (verdict: Runtime Error):
a,b =map(int,input().split())
if (a+b)% ==0:
  print((a+b)//2)
else:
  print(((a+b)//2)+1)

Fixed submission:
a,b =map(int,input().split())
if (a+b)%2 ==0:
  print((a+b)//2)
else:
  print(((a+b)//2)+1)
Buggy python submission (verdict: Runtime Error):
a,b =input().split()
if a.isalpha() > b.isalpha():
  print(">")
elif a.isalpha() < b.isalpha():
  print("<")
  else:
  print("=")

Fixed submission:
a,b =input().split()
if a>b:
  print(">")
elif b>a:
  print("<")
else:
  print("=")
Buggy python submission (verdict: Runtime Error):
c1 = input()
c2 = input()
print("YES" if c1=c2[-1::-1] else "NO")

Fixed submission:
c1 = input()
c2 = input()
print("YES" if c1==c2[-1::-1] else "NO")
Buggy python submission (verdict: Runtime Error):
n,a = map(int,input().split())
print(n**n-a)

Fixed submission:
n=int(input())
a = int(input())
print(n*n-a)
Buggy python submission (verdict: Runtime Error):
a,b,c =map(input().split())
print(a[0].isupper(),b[0].isupper(),c[0].isupper(),sep="")

Fixed submission:
a,b,c =input().split()
print(a[0].upper(),b[0].upper(),c[0].upper(),sep="")

Buggy python submission (verdict: Runtime Error):
a,b,c =map(input().split())
print(a[0],b[0],c[0],sep="")

Fixed submission:
a,b,c =input().split()
print(a[0].upper(),b[0].upper(),c[0].upper(),sep="")
Buggy python submission (verdict: Runtime Error):
a,b = map(int,input().splilt())
print((a + b) % 24)

Fixed submission:
a,b = map(int,input().split())
print((a + b) % 24)
Buggy python submission (verdict: Runtime Error):
a,b =map(int,input().split())
A,B,C ="Alice","Bob",Draw"
if max(a,b) =="13" and min(a,b) =="1":
  print(A) if a < b else print(B)
else:
  print(A) if a > b print(B) if a < b else print(C)
  

Fixed submission:
a,b =map(int,input().split())
A,B,C =("Alice","Bob","Draw")
if max(a,b) ==13 and min(a,b) ==1:
  print(A) if a < b else print(B)
else:
  if a > b:
    print(A)  
  elif a < b:
    print(B)  
  else:
    print(C)
Buggy python submission (verdict: Runtime Error):
n =int(input())
s = input()
x = 0
for i in s:
  if i ="I": 
    x =max(x,x+1)
  else:
    x =max(x,x-1)
print(x)

Fixed submission:
n =int(input())
s = input()
x,ans =0,0
for i in s:
  if i =="I":
    x +=1
    ans =max(x,ans)
  else:
    x-=1
    ans =max(x,ans)
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
a,b,x =map(int,input().split())
ans =0
for i in range(a,b+1):
  if i % x ==0: ans +=1
print(ans)

Fixed submission:
a,b,x =map(int,input().split())
print((b//x)-((a-1)//x))
Buggy python submission (verdict: Runtime Error):
a,b,c = int(input.split())
if a + b == c:
  print("Yes")
elif a + c == b:
  print("Yes")
elif b + c ==a:
  print("Yes")
else:
  print("No")
  

Fixed submission:
a,b,c = list(map(int,input().split()))
if a + b == c:
  print("Yes")
elif a + c == b:
  print("Yes")
elif b + c ==a:
  print("Yes")
else:
  print("No")
Buggy python submission (verdict: Runtime Error):
n,k,x,y = [int(input) for i in range(4)]
print(min(n,k) * x + max(n-k,0) * y)

Fixed submission:
n,k,x,y = [int(input()) for i in range(4)]
print(min(n,k) * x + max(n-k,0) * y)

Buggy python submission (verdict: Runtime Error):
n = int(input())
k,x,y = [int(input()) for i in range(n)]
print(k * x + (n - k) * y) if n > k else print(k * x)

Fixed submission:
n,k,x,y = [int(input()) for i in range(4)]
print(min(n,k) * x + max(n-k,0) * y)
Buggy python submission (verdict: Runtime Error):
a =list(map(int,input().split()))
if a+b+c ==19 and a.count("7") ==2:
  print("Yes")
else:
  print("No")

Fixed submission:
a = list(map(int,input().split()))
if sum(a) == 17 and a.count(5) == 2:
  print("YES")
else:
  print("NO")
Buggy python submission (verdict: Runtime Error):
n,l = map(int,input().split())
s =[input() for _ in range(n)]
ss = sorted(s)
print(ss[0]+ss[1]+ss[2])

Fixed submission:
n,l =map(int,input().split())
ss = [input() for _ in range(n)]
s =sorted(ss)
ans =""
for i in s:
  ans += i
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import sys


def input(): return sys.stdin.readline().strip()


def main():
    N, K, Q = map(int, input().split())
    points = [K] * N

    for _ in range(Q):
        a = int(input()) - 1
        for i in range(N):
            if i != a:
                points[i] -= 1

    for p in points:
        if p > 0:
            print('Yes')
        else:
            print('No')


if __name__ == "__main__":
    main()


Fixed submission:
import sys


def input(): return sys.stdin.readline().strip()


def main():
    N, K, Q = map(int, input().split())
    win = [0] * N

    for _ in range(Q):
        a = int(input()) - 1
        win[a] += 1

    for w in win:
        is_win = K - (Q - w) > 0
        if is_win:
            print('Yes')
        else:
            print('No')


if __name__ == "__main__":
    main()
Buggy python submission (verdict: Time Limit Exceeded):
import sys


def input(): return sys.stdin.readline().strip()


def main():
    N, M = map(int, input().split())
    prices = [[int(a), int(i)] for i, a in enumerate(input().split())]

    for _ in range(M):
        i = max(prices)[1]
        prices[i][0] //= 2

    ans = sum(map(lambda x: x[0], prices))
    print(ans)


if __name__ == "__main__":
    main()


Fixed submission:
import sys
import heapq
from math import ceil


def input(): return sys.stdin.readline().strip()


def main():
    N, M = map(int, input().split())
    A = list(map(lambda x: -int(x), input().split()))
    heapq.heapify(A)

    for _ in range(M):
        mx = heapq.heappop(A)
        heapq.heappush(A, ceil(mx / 2))

    ans = -sum(A)

    print(ans)


if __name__ == "__main__":
    main()
Buggy python submission (verdict: Time Limit Exceeded):
import sys


def input(): return sys.stdin.readline().strip()


def solve():
    pass


def main():
    N = int(input())
    I = [x for x in range(1, N+1)]
    P = [x for x in range(1, N+1)]
    P = P[1:] + [P[0]]

    for i in range(N):
        I[i] %= P[i]

    print(sum(I))


if __name__ == "__main__":
    main()


Fixed submission:
import sys


def input(): return sys.stdin.readline().strip()


def main():
    N = int(input())
    ans = (N-1)*(1+N-1) // 2
    print(ans)


if __name__ == "__main__":
    main()
Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline


def main():
    N = int(input())
    s = [sorted(input().strip()) for _ in range(N)]
    ans = 0
    for i in range(N-1):
        for j in range(i+1, N):
            if s[i] == s[j]:
                ans += 1
    print(ans)


if __name__ == "__main__":
    main()


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


def main():
    N = int(input())
    d = defaultdict(lambda: 0)
    for _ in range(N):
        s = ''.join(sorted(input().strip()))
        d[s] += 1

    ans = 0
    for v in filter(lambda x: x > 1, d.values()):
        ans += (v - 1) * v // 2
    print(ans)


if __name__ == "__main__":
    main()