Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
import sys
import numpy as np
from numba import njit

read = sys.stdin.read
readline = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 8)
INF = float('inf')
MOD = 10 ** 9 + 7


@njit('i8[:](i8,i8,i8[:])', cache=True)
def func(n, k, A):
    for _ in range(k):
        B = np.zeros(n + 1, np.int64)
        for i, a in enumerate(A):
            B[max(0, i - a)] += 1
            B[min(i + a + 1, n)] -= 1
        A = B.cumsum()[:-1]
    return A


def main():
    N, K = map(int, readline().split())
    A = np.array(readline().split(), np.int64)
    ans = func(N, K, A)
    print(*ans)


if __name__ == '__main__':
    main()


Fixed submission:
import sys
import numpy as np
from numba import njit

read = sys.stdin.read
readline = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 8)
INF = float('inf')
MOD = 10 ** 9 + 7


@njit('i8[:](i8,i8,i8[:])', cache=True)
def func(n, k, A):
    for _ in range(k):
        B = np.zeros(n + 1, np.int64)
        for i, a in enumerate(A):
            B[max(0, i - a)] += 1
            B[min(i + a + 1, n)] -= 1
        A = B.cumsum()[:-1]
        if np.all(A == n):
            break
    return A


def main():
    N, K = map(int, readline().split())
    A = np.array(readline().split(), np.int64)
    ans = func(N, K, A)
    print(*ans)


if __name__ == '__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
import sys
import numpy as np

read = sys.stdin.read
readline = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 8)
INF = float('inf')
MOD = 10 ** 9 + 7


def main():
    N, K = map(int, readline().split())
    np.set_printoptions(precision=0)
    A = np.array(readline().split(), np.int64)
    for _ in range(K):
        B = np.zeros(N + 1)
        for i, a in enumerate(A):
            B[max(0, int(i - a))] += 1
            B[min(int(i + a + 1), N)] -= 1
        B = B.cumsum()
        A = np.copy(B[:N])
    print(' '.join(map(str, list(map(int, A)))))


if __name__ == '__main__':
    main()


Fixed submission:
import sys
import numpy as np
from numba import njit

read = sys.stdin.read
readline = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 8)
INF = float('inf')
MOD = 10 ** 9 + 7


@njit('i8[:](i8,i8,i8[:])', cache=True)
def func(n, k, A):
    for _ in range(k):
        B = np.zeros(n + 1, np.int64)
        for i, a in enumerate(A):
            B[max(0, i - a)] += 1
            B[min(i + a + 1, n)] -= 1
        A = B.cumsum()[:-1]
        if np.all(A == n):
            break
    return A


def main():
    N, K = map(int, readline().split())
    A = np.array(readline().split(), np.int64)
    ans = func(N, K, A)
    print(*ans)


if __name__ == '__main__':
    main()
Buggy python submission (verdict: Time Limit Exceeded):
import sys
import numpy as np
from numba import jit
readline = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 8)
INF = float('inf')
MOD = 10 ** 9 + 7



def main():
    N = int(input())
    H = np.array(input().split(), np.int64)
    A = np.arange(1,N+1)
    B = np.arange(1,N+1)
    A = A + H
    B = B - H
    ans = 0

    @jit(nopython=True)
    def aa(i):
        return N - i - np.count_nonzero(B[i:] - A[:-i])
    for i in range(1,N):
        ans += aa(i)
    print(ans)



if __name__ == '__main__':
    main()

Fixed submission:
import sys
from collections import defaultdict

read = sys.stdin.read
readline = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 8)
INF = float('inf')
MOD = 10 ** 9 + 7


def main():
    N = int(readline())
    A = list(map(int, readline().split()))
    L = defaultdict(int)
    R = defaultdict(int)
    for i in range(N):
        L[i+1+A[i]] += 1
        R[i+1-A[i]] += 1
    ans = 0
    for key, value in L.items():
        ans += value*R[key]
    print(ans)


if __name__ == '__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
import sys
import numpy as np
readline = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 8)
INF = float('inf')
MOD = 10 ** 9 + 7



def main():
    N = int(input())
    H = np.array(input().split(), np.int64)
    A = np.arange(1,N+1)
    B = np.arange(1,N+1)
    A = A + H
    B = B - H
    ans = 0
    for i in range(1,N):
        ans += N - i - np.count_nonzero(B[i:] - A[:-i])
    print(ans)



if __name__ == '__main__':
    main()

Fixed submission:
import sys
from collections import defaultdict

read = sys.stdin.read
readline = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 8)
INF = float('inf')
MOD = 10 ** 9 + 7


def main():
    N = int(readline())
    A = list(map(int, readline().split()))
    L = defaultdict(int)
    R = defaultdict(int)
    for i in range(N):
        L[i+1+A[i]] += 1
        R[i+1-A[i]] += 1
    ans = 0
    for key, value in L.items():
        ans += value*R[key]
    print(ans)


if __name__ == '__main__':
    main()
Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque
from collections import Counter
from itertools import product, permutations,combinations
from operator import itemgetter
from heapq import heappop, heappush
from bisect import bisect_left, bisect_right, bisect
#pypyではscipy, numpyは使えない
#from scipy.sparse.csgraph import shortest_path, floyd_warshall, dijkstra, bellman_ford, johnson, minimum_spanning_tree
#from scipy.sparse import csr_matrix, coo_matrix, lil_matrix
import numpy as np
from fractions import gcd
from math import ceil,floor, sqrt, cos, sin, pi, factorial
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10**8)
INF = float('inf')
MOD = 10**9+7

def main():
  k= int(readline())
  if k<10:
    print(k)
    sys.exit()
  dp = np.ones((10,10), dtype='int64')
  #dp[i-1][j]は、i桁のときの末尾がjの数
  dp[0, 0] = 0
  for i in range(9):
    for j in range(10):
      if j == 0:
        dp[i+1,0] = dp[i,0] + dp[i,1]
      elif j == 9:
        dp[i+1,j] = dp[i,8] + dp[i,9]
      else:
        dp[i+1,j] = dp[i,j-1] + dp[i,j] + dp[i,j+1]
  total = [0]
  #i桁のときの数の累積和
  for i in range(10):
    tmp = total[-1] + dp[i,:].sum()
    total.append(tmp)
  keta = 0
  for i in range(11):
    if total[i]<=k:
      keta = i+1
  #kはketa桁である
  c = 10**(keta-1)
  count = total[keta-1]
  for i in range(c,c*10):
    s = str(i)
    bl = True
    for j in range(keta-1):
      if abs(int(s[j])-int(s[j+1]))>1:
        bl=False
    if bl:
      count +=1
    if count == k:
      print(i)
      sys.exit()
  
if __name__ == '__main__':
  main()

Fixed submission:
from collections import deque
from collections import Counter
from itertools import product, permutations,combinations
from operator import itemgetter
from heapq import heappop, heappush
from bisect import bisect_left, bisect_right, bisect
#pypyではscipy, numpyは使えない
#from scipy.sparse.csgraph import shortest_path, floyd_warshall, dijkstra, bellman_ford, johnson, minimum_spanning_tree
#from scipy.sparse import csr_matrix, coo_matrix, lil_matrix
import numpy as np
from fractions import gcd
from math import ceil,floor, sqrt, cos, sin, pi, factorial
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10**8)
INF = float('inf')
MOD = 10**9+7

def main():
  k= int(readline())
  l = [1,2,3,4,5,6,7,8,9]
  q = deque(l)
  x = 0
  for _ in range(k):
    x = q.popleft()
    sue = x%10
    if sue != 0:
      q.append(10*x+sue-1)
    q.append(10*x+sue)
    if sue!=9:
      q.append(10*x+sue+1)
  print(x)
if __name__ == '__main__':
  main()
Buggy python submission (verdict: Time Limit Exceeded):
import sys
readline = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 8)
INF = float('inf')
MOD = 10 ** 9 + 7

def main():
    H, N = map(int, readline().split())
    Magic = list(list(map(int, readline().split())) for _ in range(N))

    dp = [INF]*(H+1)
    dp[0] = 0
    for h in range(H):
        for damage, cost in Magic:
            next_index = min(h + damage, H)
            dp[next_index] = min(dp[next_index],dp[h]+cost)
    print(dp[-1])

if __name__ == '__main__':
    main()

Fixed submission:
import sys
readline = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 8)
INF = float('inf')
MOD = 10 ** 9 + 7

def main():
    H, N = map(int, readline().split())
    Magic = list(list(map(int, readline().split())) for _ in range(N))

    dp = [INF]*(H+1)
    dp[0] = 0
    for h in range(H):
        for damage, cost in Magic:
            next_index = min(h + damage, H)
            dp[next_index] = min(dp[next_index],dp[h]+cost)
    print(dp[-1])

if __name__ == '__main__':
    main()
Buggy python submission (verdict: Runtime Error):
from collections import deque
import sys
sys.setrecursionlimit(10**8)
INF = float('inf')



h, w = map(int, input().split())
maze = [list(input()) for _ in range(h)]

def bfs(sy, sx):
  dist = [[0 for x in range(w)] for y in range(h)]
  dy = [0, 1, 0, -1]
  dx = [1, 0, -1, 0]
  Q = deque()
  Q.append((sy, sx))
  while Q:
    q = Q.popleft()
    y = q[0]
    x = q[1]
    d = dist[y][x]
    for i in range(4):
      ny = y + dy[i]
      nx = x + dx[i]
      if ny < 0 or h <= ny or nx < 0 or w <= nx:
        continue
      #迷路における道が'.'、壁が'#'で表されている場合
      if ny = sy and nx = sx:
        continue
      if maze[ny][nx] == '#':
        continue
      nd = d + 1
      if dist[ny][nx] != 0 and nd >= dist[ny][nx]:
        continue
      dist[ny][nx] = nd
      Q.append((ny, nx))
  return max(max(x) for x in dist)

ans = 0
for y in range(h):
  for x in range(w):
    if maze[y][x] == '.':
      ans = max(ans, bfs(y,x))
print(ans)

Fixed submission:
from collections import deque
import sys
sys.setrecursionlimit(10**8)
INF = float('inf')



h, w = map(int, input().split())
maze = [list(input()) for _ in range(h)]

def bfs(sy, sx):
  dist = [[0 for x in range(w)] for y in range(h)]
  dy = [0, 1, 0, -1]
  dx = [1, 0, -1, 0]
  Q = deque()
  Q.append((sy, sx))
  while Q:
    q = Q.popleft()
    y = q[0]
    x = q[1]
    d = dist[y][x]
    for i in range(4):
      ny = y + dy[i]
      nx = x + dx[i]
      if ny < 0 or h <= ny or nx < 0 or w <= nx:
        continue
      #迷路における道が'.'、壁が'#'で表されている場合
      if ny == sy and nx == sx:
        continue
      if maze[ny][nx] == '#':
        continue
      nd = d + 1
      if dist[ny][nx] != 0 and nd >= dist[ny][nx]:
        continue
      dist[ny][nx] = nd
      Q.append((ny, nx))
  return max(max(x) for x in dist)

ans = 0
for y in range(h):
  for x in range(w):
    if maze[y][x] == '.':
      ans = max(ans, bfs(y,x))
print(ans)
Buggy python submission (verdict: Runtime Error):
import sys

read = sys.stdin.read
readline = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 8)
INF = float('inf')
MOD = 10 ** 9 + 7


def lcm_base(a, b):
    return (a * b) // gcd(a, b)


def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)


def main():
    n, m = map(int, readline().split())
    a = np.array(input().split(), np.int64)
    a //= 2
    b = np.copy(a)
    while True:
        c = b % 2
        if c.sum() == 0:
            b //= 2
        elif c.sum() == n:
            break
        else:
            print(0)
            sys.exit()
    d = lcm_list(a)
    if d > 10 ** 9:
        ans = 0
    else:
        ans = (m // d) - (m // (d + d))
    print(ans)


if __name__ == '__main__':
    main()


Fixed submission:
from scipy.sparse.csgraph import shortest_path, floyd_warshall, dijkstra, bellman_ford, johnson, minimum_spanning_tree
from scipy.sparse import csr_matrix, coo_matrix, lil_matrix
import numpy as np
from collections import deque, Counter, defaultdict
from itertools import product, permutations,combinations
from operator import itemgetter
from heapq import heappop, heappush
from bisect import bisect_left, bisect_right, bisect
from fractions import gcd
from math import ceil,floor, sqrt, cos, sin, pi, factorial
from functools import reduce
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10**8)
INF = float('inf')
MOD = 10**9+7
def lcm_base(a, b):
    return (a * b) // gcd(a, b)

def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)


def main():
  n, m = map(int, readline().split())
  a = np.array(input().split(), np.int64)
  a //= 2
  b=np.copy(a)
  while True:
    c = b%2
    if c.sum() == 0:
      b //= 2
    elif c.sum() == n:
      break
    else:
      print(0)
      sys.exit()
  d = lcm_list(a)
  if d>10**9:
    ans = 0
  else:
    ans = (m//d) - (m//(d+d))
  print(ans)
  
  
  
if __name__ == '__main__':
  main()
Buggy python submission (verdict: Runtime Error):
from scipy.sparse.csgraph import shortest_path, floyd_warshall, dijkstra, bellman_ford, johnson, minimum_spanning_tree
from scipy.sparse import csr_matrix, coo_matrix, lil_matrix
import numpy as np
from collections import deque, Counter, defaultdict
from itertools import product, permutations,combinations
from operator import itemgetter
from heapq import heappop, heappush
from bisect import bisect_left, bisect_right, bisect
from fractions import gcd
from math import ceil,floor, sqrt, cos, sin, pi, factorial
from functools import reduce
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10**8)
INF = float('inf')
MOD = 10**9+7
def lcm_base(a, b):
    return (a * b) // gcd(a, b)

def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)

def nCr(n,r):
  bunshi = 1
  bunbo = 1
  for i in range(r):
    bunshi = (bunshi * (n-i)) % MOD
    bunbo = (bunbo * (i+1)) % MOD
  return bunshi * pow(bunbo, MOD - 2, MOD) % MOD


def main():
  X, Y = map(int, readline().split())
  if (x + y) % 3 != 0 or (2 * x - y) % 3 != 0 or (2 * y - x) % 3 != 0:
    print(0)
    sys.exit()
  else:
    n = (2*Y - X)//3
    m = (2*X - Y)//3
    ans = nCr(n+m, n)
  print(ans%MOD)
  
  
  
if __name__ == '__main__':
  main()

Fixed submission:
from scipy.sparse.csgraph import shortest_path, floyd_warshall, dijkstra, bellman_ford, johnson, minimum_spanning_tree
from scipy.sparse import csr_matrix, coo_matrix, lil_matrix
import numpy as np
from collections import deque, Counter, defaultdict
from itertools import product, permutations,combinations
from operator import itemgetter
from heapq import heappop, heappush
from bisect import bisect_left, bisect_right, bisect
from fractions import gcd
from math import ceil,floor, sqrt, cos, sin, pi, factorial
from functools import reduce
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10**8)
INF = float('inf')
MOD = 10**9+7
def lcm_base(a, b):
    return (a * b) // gcd(a, b)

def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)

def nCr(n,r):
  bunshi = 1
  bunbo = 1
  for i in range(r):
    bunshi = (bunshi * (n-i)) % MOD
    bunbo = (bunbo * (i+1)) % MOD
  return bunshi * pow(bunbo, MOD - 2, MOD) % MOD


def main():
  X, Y = map(int, readline().split())
  if (X + Y) % 3 != 0 or (2 * X - Y) % 3 != 0 or (2 * Y - X) % 3 != 0:
    print(0)
    sys.exit()
  else:
    n = (2*Y - X)//3
    m = (2*X - Y)//3
    if n<0 or m<0:
      print(0)
      sys.exit()
    ans = nCr(n+m, n)
  print(ans%MOD)
  
  
  
if __name__ == '__main__':
  main()
Buggy python submission (verdict: Runtime Error):
from collections import deque
from collections import Counter
from itertools import product, permutations,combinations
from operator import itemgetter
from heapq import heappop, heappush
from bisect import bisect_left, bisect_right, bisect
#pypyではscipy, numpyは使えない
#from scipy.sparse.csgraph import shortest_path, floyd_warshall, dijkstra, bellman_ford, johnson, minimum_spanning_tree
#from scipy.sparse import csr_matrix, coo_matrix, lil_matrix
import numpy as np
from fractions import gcd
from math import ceil,floor, sqrt, cos, sin, pi, factorial, log, log10, log2
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10**8)
INF = float('inf')
from datetime import datetime as dt

def main():
  n = int(readline())
  x = [0] *n
  y = [0]*n
  for i in range(n):
    x[i], y[i] = map(int, readline().split())
  dis = [[0 for i in range(n)]for j in range(n)]
  total = 0
  for i in range(n):
    for j in range(i+1,n):
      total += 2*((x[i]-x[j])**2+(y[i]-y[j])**2)**0.5
  print(total/n)
  
  
  
  
if __name__ == '__main__':
  main()

Fixed submission:
from collections import deque
from collections import Counter
from itertools import product, permutations,combinations
from operator import itemgetter
from heapq import heappop, heappush
from bisect import bisect_left, bisect_right, bisect
#pypyではscipy, numpyは使えない
#from scipy.sparse.csgraph import shortest_path, floyd_warshall, dijkstra, bellman_ford, johnson, minimum_spanning_tree
#from scipy.sparse import csr_matrix, coo_matrix, lil_matrix
import numpy as np
from fractions import gcd
from math import ceil,floor, sqrt, cos, sin, pi, factorial, log, log10, log2
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10**8)
INF = float('inf')
from datetime import datetime as dt

def main():
  n = int(readline())
  n2 = ceil(sqrt(n)) + 1
  ans = INF
  for i in range(1,n2):
    j = n//i
    if i*j==n:
      ans = min(ans, i+j-2)
  print(ans)
  
  
  
  
if __name__ == '__main__':
  main()
Buggy python submission (verdict: Time Limit Exceeded):
import sys
read = sys.stdin.read
readline = sys.stdin.buffer.readline
from collections import deque
sys.setrecursionlimit(10 ** 8)
INF = float('inf')
MOD = 10 ** 9 + 7


def main():
    N, Q = map(int, readline().split())

    path = [[] for _ in range(N)]
    for _ in range(N-1):
        a, b = map(int, readline().split())
        path[a-1].append(b-1)
        path[b-1].append(a-1)

    child = [[] for _ in range(N)]
    child[0] = path[0]
    used = [False] * N
    used[0] = True
    que = deque(child[0])
    while que:
        x = que.popleft()
        used[x] = True
        for a in path[x]:
            if used[a]:
                continue
            else:
                child[x].append(a)
                que.append(a)

    counter = [0]*N
    for _ in range(Q):
        p, x = map(int, readline().split())
        que.append(p-1)
        counter[p-1] += x
        while que:
            a = que.popleft()
            for b in child[a]:
                counter[b] += x
                que.append(b)
    print(' '.join(map(str, counter)))

if __name__ == '__main__':
    main()



Fixed submission:
from collections import deque
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10**8)
INF = float('inf')
MOD = 10**9+7


def main():
  N, Q = map(int, readline().split())
  AB = [[int(x) for x in readline().split()] for _ in range(N-1)]
  PX = [[int(x) for x in readline().split()] for _ in range(Q)]
  
  graph = [[] for _ in range(N+1)]
  for ab in AB:
    graph[ab[0]].append(ab[1])
    graph[ab[1]].append(ab[0])
  
  value = [0] * (N+1)
  for px in PX:
    value[px[0]] += px[1]
  
  stack = deque([1])
  parent = [0] * (N+1)
  while stack:
    x = stack.popleft()
    for y in graph[x]:
      if y == parent[x]:
        continue
      parent[y] = x
      stack.append(y)
      value[y] += value[x]
      
  print(' '.join(map(str, value[1:])))
      
if __name__ == '__main__':
  main()
Buggy python submission (verdict: Runtime Error):
from collections import deque
from collections import Counter
from itertools import product, permutations,combinations
from operator import itemgetter
from heapq import heappop, heappush
from bisect import bisect_left, bisect_right, bisect
#pypyではscipy, numpyは使えない
#from scipy.sparse.csgraph import shortest_path, floyd_warshall, dijkstra, bellman_ford, johnson, minimum_spanning_tree
#from scipy.sparse import csr_matrix, coo_matrix, lil_matrix
#import numpy as np
from fractions import gcd
from math import ceil,floor, sqrt, cos, sin, pi, factorial
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10**8)
INF = float('inf')

def main():
  a, b = map(int, readline().split())
  print(max(a+b, a-b, a*b)
  
  
if __name__ == '__main__':
  main()

Fixed submission:
from collections import deque
from collections import Counter
from itertools import product, permutations,combinations
from operator import itemgetter
from heapq import heappop, heappush
from bisect import bisect_left, bisect_right, bisect
#pypyではscipy, numpyは使えない
#from scipy.sparse.csgraph import shortest_path, floyd_warshall, dijkstra, bellman_ford, johnson, minimum_spanning_tree
#from scipy.sparse import csr_matrix, coo_matrix, lil_matrix
#import numpy as np
from fractions import gcd
from math import ceil,floor, sqrt, cos, sin, pi, factorial
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10**8)
INF = float('inf')

def main():
  a, b = map(int, readline().split())
  print(max(a+b, a-b, a*b))
  
  
if __name__ == '__main__':
  main()
Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque
from collections import Counter
from itertools import product, permutations,combinations
from operator import itemgetter
from heapq import heappop, heappush
from bisect import bisect_left, bisect_right, bisect
#pypyではscipy, numpyは使えない
#from scipy.sparse.csgraph import shortest_path, floyd_warshall, dijkstra, bellman_ford, johnson, minimum_spanning_tree
#from scipy.sparse import csr_matrix, coo_matrix, lil_matrix
import numpy as np
from fractions import gcd
from math import ceil,floor, sqrt, cos, sin, pi, factorial, log, log10, log2
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10**8)
INF = float('inf')
from datetime import datetime as dt

def main():
  n = int(readline())
  S = []
  for _ in range(n):
    s = sorted(input())
    S.append(s)
  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:
from collections import deque
from collections import Counter
from itertools import product, permutations,combinations
from operator import itemgetter
from heapq import heappop, heappush
from bisect import bisect_left, bisect_right, bisect
#pypyではscipy, numpyは使えない
#from scipy.sparse.csgraph import shortest_path, floyd_warshall, dijkstra, bellman_ford, johnson, minimum_spanning_tree
#from scipy.sparse import csr_matrix, coo_matrix, lil_matrix
import numpy as np
from fractions import gcd
from math import ceil,floor, sqrt, cos, sin, pi, factorial, log, log10, log2
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10**8)
INF = float('inf')
from datetime import datetime as dt

def main():
  n = int(readline())
  S = []
  for _ in range(n):
    S.append(''.join(sorted(input())))
  counter = Counter(S)
  ans = 0
  for i in counter.values():
    ans +=  i*(i-1)/2
  print(int(ans))
  
if __name__ == '__main__':
  main()