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

Fixed submission:
import sys
import heapq
from typing import Callable, List, NoReturn, Set


def dijkstra(n, path) -> List[int]:
    total_cost: List[int] = [10**5] * (n + 1)
    total_cost[1] = 0

    pointers: List[int] = [-1] * (n + 1)
    pointers[1] = 0

    not_checked: Set[int] = set(range(1, n + 1))
    checked: Set[int] = set()
    cur_node: int = 1
    h: List = []

    while not_checked:
        checked.add(cur_node)
        not_checked -= {cur_node}

        for next_node in path[cur_node]:
            if next_node in not_checked:
                heapq.heappush(h, (total_cost[cur_node] + 1, next_node, cur_node))

        if not_checked:
            cost, next_node, prev_node = heapq.heappop(h)  # type: int, int, int

            while next_node in checked:
                cost, next_node, prev_node = heapq.heappop(h)

            cur_node = next_node
            total_cost[cur_node] = cost
            pointers[cur_node] = prev_node

    return pointers


def main() -> NoReturn:
    readline: Callable[[], str] = sys.stdin.readline

    n, m = map(int, readline().rstrip().split())  # type: int, int
    path: List[List[int]] = []
    for _ in range(n + 1):
        path.append([])
    for _ in range(m):
        a, b = map(int, readline().rstrip().split())  # type: int, int
        (path[a]).append(b)
        (path[b]).append(a)

    print("Yes")
    pointers: List[int] = dijkstra(n, path)
    for i in range(2, n + 1):
        print(pointers[i])


if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
import sys
import heapq
from typing import Callable, List, NoReturn, Set


def dijkstra(n, path) -> List[int]:
    total_cost: List[int] = [10**5] * (n + 1)
    total_cost[1] = 0

    not_checked: Set[int] = set(range(1, n + 1))
    checked: Set[int] = set()
    cur_node: int = 1
    h: List = []

    while not_checked:
        checked.add(cur_node)
        not_checked -= {cur_node}

        for next_node in path[cur_node]:
            if next_node in not_checked:
                heapq.heappush(h, (total_cost[cur_node] + 1, next_node))

        if not_checked:
            cost, next_node = heapq.heappop(h)  # type: int, int

            while next_node in checked:
                cost, next_node = heapq.heappop(h)

            cur_node = next_node
            total_cost[cur_node] = cost

    return total_cost


def main() -> NoReturn:
    readline: Callable[[], str] = sys.stdin.readline

    n, m = map(int, readline().rstrip().split())  # type: int, int
    path: List[List[int]] = []
    for _ in range(n + 1):
        path.append([])
    for _ in range(n):
        a, b = map(int, readline().rstrip().split())  # type: int, int
        (path[a]).append(b)
        (path[b]).append(a)

    print("Yes")
    total_costs: List[int] = dijkstra(n, path)
    for i in range(2, n + 1):
        print(total_costs[i])


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

Fixed submission:
import math
from typing import List, NoReturn


def sum_gcd(k: int) -> int:
    cache: List[List[List[int]]] = [[[0] * (k + 1) for i in range(k + 1)] for j in range(k + 1)]

    def cached_gcd(a: int, b: int, c: int) -> int:
        k0: int
        k1: int
        k2: int
        k0, k1, k2 = sorted([a, b, c])

        result: int = cache[k0][k1][k2]
        if result > 0:
            return result
        else:
            result = math.gcd(math.gcd(k0, k1), k2)
            cache[k0][k1][k2] = result
            return result

    answer: int = 0
    for h in range(1, k + 1):
        for i in range(1, k + 1):
            for j in range(1, k + 1):
                answer += cached_gcd(h, i, j)

    return answer


def main() -> NoReturn:
    k: int = int(input().rstrip())
    print(sum_gcd(k))


if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
from math import gcd
import numpy as np


def sum_gcd(k: int) -> int:
    # a > b > c
    sum_p1 = 0
    for h in range(1, k + 1):
        for i in range(1, h):
            for j in range(1, i):
                sum_p1 += gcd(h, i, j)
                
    # a = b > c
    sum_p2 = 0
    for h in range(1, k + 1):
        for i in range(1, h):
            sum_p2 += gcd(h, h, i)
    
    # a > b = c
    sum_p3 = 0
    for h in range(1, k + 1):
        for i in range(1, h):
            sum_p3 += gcd(h, i, i)

    # a = b = c
    sum_p4 = k * (k + 1) //2

    answer = sum_p1 * 6 + sum_p2 * 3 + sum_p3 * 3 + sum_p4

    return answer


def main():
    k = int(input().rstrip())
    print(sum_gcd(k))


if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
from math import gcd
import numpy as np


def sum_gcd(k: int) -> int:
    # a > b > c
    sum_p1 = 0
    for h in range(1, k + 1):
        for i in range(1, h):
            for j in range(1, i):
                sum_p1 += gcd(h, i, j)
                
    # a = b > c
    sum_p2 = 0
    for h in range(1, k + 1):
        for i in range(1, h):
            sum_p2 += gcd(h, h, i)
    
    # a > b = c
    sum_p3 = 0
    for h in range(1, k + 1):
        for i in range(1, h):
            sum_p3 += gcd(h, i, i)

    # a = b = c
    sum_p4 = k * (k + 1) //2

    answer = sum_p1 * 6 + sum_p2 * 3 + sum_p3 * 3 + sum_p4

    return answer


def main():
    k = int(input().rstrip())
    print(sum_gcd(k))


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

Fixed submission:
def main():
  n, k = map(int, input().rstrip().split())
  
  if n % k <= k / 2:
    print(n % k)
  else:
    print(k - (n % k))


if __name__ == '__main__':
  main()

Buggy submission (verdict: Runtime Error):
def main():
  n, k = map(int, input().rstrip().split())
  
  if n % k <= k / 2:
	print(n % k)
  else:
    print(k - (n % k))


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

Fixed submission:
import math
import sys

import numpy as np
from scipy.optimize import minimize


scan = sys.stdin.readline


def main():
    l = int(scan().rstrip())

    v = lambda x: (x[0] ** 2) * x[1] + (x[1] ** 2) * x[0] - l * x[0] * x[1]
    cons = (
        {"type": "ineq", "fun": lambda x: x[0]},
        {"type": "ineq", "fun": lambda x: x[1]},
        {"type": "ineq", "fun": lambda x: l - x[0] - x[1]}
    )

    result = minimize(v, x0=np.array([l/3, l/3]), constraints=cons, method="SLSQP")
    print(-result["fun"])


if __name__ == '__main__':
    main()

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

import numpy as np
from scipy.optimize import minimize


scan = sys.stdin.readline


def main():
    l = int(scan().rstrip())

    v = lambda x, n: (x[0] ** 2) * x[1] + (x[1] ** 2) * x[0] - n * x[0] * x[1]
    cons = (
        {"type": "ineq", "fun": lambda x: x[0]},
        {"type": "ineq", "fun": lambda x: x[1]},
        {"type": "ineq", "fun": lambda x: l - x[0] - x[1]}
    )

    result = minimize(v, x0=np.array([l/3, l/3]), constraints=cons, method="SLSQP")
    print(result["fun"][0])


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

Fixed submission:
n = int(input())
a = [int(ocu) for ocu in input().rstrip().split()]

paired_a = list(zip(range(1, n+1), a))

paired_a.sort(key=lambda x:x[1])

print(" ".join([str(pair[0]) for pair in paired_a]))

Buggy submission (verdict: Runtime Error):
n = input()
a = [int(ocu) for ocu in input().rstrip().split()]

paired_a = zip(range(1, n+1), a)

paired_a.sort(lambda x:x[1])

print(" ".join([pair[0] for pair in paired_a]))
Problem p02947 (python)

Fixed submission:
import collections
import sys
from scipy.misc import comb


scan = sys.stdin.readline

def count_abc(string):
  alphabet = dict.fromkeys("abcdefghijklmnopqrstuvwxyz",0)
  
  for char in string:
    num = alphabet[char]
    alphabet[char] = num + 1
  
  c_str = ""
  for k, v in alphabet.items():
    c_str += k
    c_str += str(v)
  
  return c_str


def main():
  n = int(scan().rstrip())
  s = [scan().rstrip() for _ in range(n)]
  
  s_c = [count_abc(st) for st in s]
  
  c_dict = collections.Counter(s_c)
  
  ans = 0
  
  for v in c_dict.values():
    if v > 1:
      ans += comb(v, 2, exact=True)
  
  print(ans)

  
if __name__ == "__main__":
  main()

Buggy submission (verdict: Runtime Error):
import collections
import sys
from scipy.special import comb


scan = sys.stdin.readline

def count_abc(string):
  alphabet = dict.fromkeys("abcdefghijklmnopqrstuvwxyz",0)
  
  for char in string:
    num = alphabet[char]
    alphabet[char] = num + 1
  
  c_str = ""
  for k, v in alphabet.items():
    c_str += k
    c_str += str(v)
  
  return c_str


def main():
  n = int(scan().rstrip())
  s = [scan().rstrip() for _ in range(n)]
  
  s_c = [count_abc(st) for st in s]
  
  c_dict = collections.Counter(s_c)
  
  ans = 0
  
  for v in c_dict.values():
    if v > 1:
      ans += comb(v, 2, exact=True)
  
  print(ans)

  
if __name__ == "__main__":
  main()

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


scan = sys.stdin.readline

def count_abc(string):
  alphabet = dict.fromkeys("abcdefghijklmnopqrstuvwxyz",0)
  
  for char in string:
    num = alphabet[char]
    alphabet[char] = num + 1
  
  c_str = ""
  for k, v in alphabet.items():
    c_str += k
    c_str += v
  
  return c_str


def main():
  n = int(scan().rstrip())
  s = [scan().rstrip() for _ in range(n)]
  
  s_c [count_abc(string) for string in s]
  
  c_dict = collections.Counter(s_c)
  
  print(max(c_dict))
Problem p03037 (python)

Fixed submission:
import sys


scan = sys.stdin.readline


def main():
  n, m = map(int, scan().rstrip().split())
  l = 0
  r = n
  
  for _ in range(m):
    l_i, r_i = map(int, scan().rstrip().split())
    l = max(l, l_i)
    r = min(r, r_i)
    
  cards = r - l + 1 if r >= l else 0
  
  print(cards)
  

if __name__ == "__main__":
  main()

Buggy submission (verdict: Runtime Error):
import sys


scan = sys.stdin.readline


def main():
  n, m = map(int, scan().rstrip().split())
  l = 0
  r = n
  
  for _ in range(m):
    l_i, r_i = map(int, scan().rstrip().split())
    l = max(l, l_i)
    r = min(r, r_i)
    
  cards = r - l + 1 if r > l else 0
  
  print(cards)
  

if __name__ = "__main__":
  main()
Problem p03147 (python)

Fixed submission:
import sys
import numpy as np


def count_water(np_arr):
  if not np_arr.any():
    return 0
  least = min(np_arr)
  div_p = np.where(np_arr == least)[0][0]
  np_arr -= least
  return least + count_water(np_arr[:div_p]) + count_water(np_arr[div_p + 1:])


def main():
  readline = sys.stdin.readline
  
  n = int(readline().rstrip())
  h = np.array(tuple(int(_) for _ in readline().rstrip().split()))
  
  print(count_water(h))

 
if __name__ == "__main__":
  main()

Buggy submission (verdict: Runtime Error):
import sys
import numpy as np


def count_water(np_arr):
  least = min(np_arr)
  div_p = np.where(np_arr == least)[0]
  np_arr -= least
  return least + count_water(np_arr[:div_p]) + count_water(np_arr[div_p + 1:])


def main():
  readline = sys.stdin.readline
  
  n = int(readline().rstirp())
  h = np.array(tuple(int(_) for _ in readline().rstrip().split()))
  
  print(count_water(h))

 
if __name__ == "__main__":
  main()
Problem p03212 (python)

Fixed submission:
import itertools
import math


def main():
  n = int(input())
  
  count_753 = 0
  max_digits = int(math.log10(n)) + 2
  cand_753 = ("3", "5", "7")
  
  for digits in range(3, max_digits):
    for dig_753 in itertools.product(cand_753, repeat=digits):
      number_str = "".join(dig_753)
      
      if "7" in number_str and "5" in number_str and "3" in number_str and int(number_str) <= n:
        count_753 += 1
  
  print(count_753)

if __name__ == "__main__":
  main()

Buggy submission (verdict: Runtime Error):
import itertools
import math


def main():
  n = int(input())
  
  count_753 = 0
  max_digits = math.ceil(math.log10(n))
  cand_753 = (3, 5, 7)
  
  for digits in range(3, max_digits):
    for dig_753 in itertools.product(cand_753, repeat=digits):
      number_str = "".join(dig_753)
      
      if "7" in number_str and "5" in number_str and "3" in number_str and int(number_str) <= n:
        count_753 += 1
  
  print(count_753)

if __name__ == "__main__":
  main()
Problem p02603 (python)

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


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


def readint():
    return int(input())


def readnums():
    return map(int, input().split())


def readstrs():
    return input().split()


def main():
    N = readint()
    A = list(readnums())
    b = 1000
    s = 0
    for i in range(N - 1):
        if A[i] < A[i + 1]:
            s += b // A[i]
            b %= A[i]
        elif A[i] > A[i + 1]:
            b += A[i] * s
            s = 0

    if A[-1] >= A[-2]:
        b += A[-1] * s
        s = 0

    print(b)
    # d = deque(A)
    # d.appendleft(201)
    # d.append(0)
    # # ans = 1000 + (max(A) - min(A)) * (1000 // min(A))
    # il = []
    # for i in range(N):
    #     if d[i] <= d[i + 1] and d[i + 1] > d[i + 2]:
    #         il.append(i)
    #     elif d[i] >= d[i + 1] and d[i + 1] < d[i + 2]:
    #         il.append(i)

    # # print(il)
    # if len(il) <= 1:
    #     print(1000)
    # else:
    #     b = 1000
    #     s = 0
    #     if A[il[0]] < A[il[1]]:
    #         for i, v in enumerate(il):
    #             if not i % 2:
    #                 s += b // A[v]
    #                 b -= s * A[v]
    #             else:
    #                 b += s * A[v]
    #                 s = 0
    #             # print(b, s)
    #     else:
    #         for i, v in enumerate(il):
    #             if i % 2:
    #                 s += b // A[v]
    #                 b -= s * A[v]
    #             else:
    #                 b += s * A[v]
    #                 s = 0
    #             # print(b, s)
    #     if s:
    #         b = A[il[-1]] * s

    #     print(max(b, 1000))


if __name__ == "__main__":
    main()

Buggy submission (verdict: Runtime Error):
import sys
from collections import deque
input = sys.stdin.readline


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


def readint():
    return int(input())


def readnums():
    return map(int, input().split())


def readstrs():
    return input().split()


def main():
    N = readint()
    A = list(readnums())
    d = deque(A)
    d.appendleft(201)
    d.append(0)
    # ans = 1000 + (max(A) - min(A)) * (1000 // min(A))
    il = []
    for i in range(N):
        if d[i] <= d[i + 1] and d[i + 1] > d[i + 2]:
            il.append(i)
        elif d[i] >= d[i + 1] and d[i + 1] < d[i + 2]:
            il.append(i)

    # print(il)
    if len(il) == 1:
        print(1000)
    else:
        b = 1000
        s = 0
        if A[il[0]] < A[il[1]]:
            for i, v in enumerate(il):
                if not i % 2:
                    s += b // A[v]
                    b -= s * A[v]
                else:
                    b += s * A[v]
                    s = 0
                # print(b, s)
        else:
            for i, v in enumerate(il):
                if i % 2:
                    s += b // A[v]
                    b -= s * A[v]
                else:
                    b += s * A[v]
                    s = 0
                # print(b, s)

        print(max(1000, b))


if __name__ == "__main__":
    main()
Problem p02608 (python)

Fixed submission:
import sys
import math
input = sys.stdin.readline


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


def readint():
    return int(input())


def readnums():
    return map(int, input().split())


def readstrs():
    return input().split()


def main():
    N = readint()

    ans = {i: 0 for i in range(1, 20000)}
    for i in range(3, 124):
        for j in range(1, i):
            for k in range(1, i):
                l = i - j - k
                if l <= 0:
                    break
                else:
                    v = j ** 2 + k ** 2 + l ** 2 + j * k + k * l + j * l
                    ans[v] += 1
    for i in range(1, N + 1):
        print(ans[i])


if __name__ == "__main__":
    main()

Buggy submission (verdict: Runtime Error):
import sys
import math
input = sys.stdin.readline


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


def readint():
    return int(input())


def readnums():
    return map(int, input().split())


def readstrs():
    return input().split()


def main():
    N = readint()

    ans = {i: 0 for i in range(1, N + 1)}
    for i in range(3, 101):
        for j in range(1, i):
            for k in range(1, i):
                l = i - j - k
                if l <= 0:
                    break
                else:
                    v = j ** 2 + k ** 2 + l ** 2 + j * k + k * l + j * l
                    ans[v] += 1
    for i in range(1, N + 1):
        print(ans[i])


if __name__ == "__main__":
    main()
Problem p02609 (python)

Fixed submission:
import sys
input = sys.stdin.readline


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


def readint():
    return int(input())


def readnums():
    return map(int, input().split())


def readstrs():
    return input().split()


def popcount(n):
    ret = 0
    while n:
        ret += n & 1
        n >>= 1
    return ret


def main():
    N = readint()
    X = readstr()
    s = sum(tuple(map(int, X)))
    s1 = s + 1
    s2 = s - 1 if s != 1 else 1
    m1 = int(X, 2) % s1
    m2 = int(X, 2) % s2
    t1 = [1]
    t2 = [1]
    for i in range(N):
        t1.append(t1[i] * 2 % s1)
        t2.append(t2[i] * 2 % s2)
    for i in range(N):
        ans = 0
        if X[i] == '0':
            x = (m1 + t1[(N - i - 1)]) % s1
        else:
            if s == 1:
                print(0)
                continue
            else:
                x = (m2 - t2[(N - i - 1)]) % s2
        d = popcount(x)
        ans += 1
        while x:
            x %= d
            d = popcount(x)
            ans += 1
        print(ans)


if __name__ == "__main__":
    main()

Buggy submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline


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


def readint():
    return int(input())


def readnums():
    return map(int, input().split())


def readstrs():
    return input().split()


def main():
    N = readint()
    X = readstr()
    s = sum(tuple(map(int, X)))
    m1 = int(X, 2) % (s + 1)
    m2 = int(X, 2) % (s - 1)
    for i in range(N):
        l = ['0'] * N
        l[i] = '1'
        ans = 1
        if X[i] == '0':
            x = (m1 + 2 ** (N - i - 1) % (s + 1)) % (s + 1)
        else:
            x = (m2 - 2 ** (N - i - 1) % (s - 1)) % (s - 1)
        d = sum(tuple(map(int, bin(x)[2:])))
        while x:
            x %= d
            d = sum(tuple(map(int, bin(x)[2:])))
            ans += 1
        print(ans)


if __name__ == "__main__":
    main()
Problem p02756 (python)

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

S = deque(input().strip())
Q = int(input())
flag = 0

for i in range(Q):
    q = input().split()
    if q[0] == '1':
        flag = 1 if not flag else 0
    elif q[0] == '2':
        if q[1] == '1':
            S.appendleft(q[2]) if not flag else S.append(q[2])
        elif q[1] == '2':
            S.append(q[2]) if not flag else S.appendleft(q[2])

print(''.join(S)) if not flag else print(''.join(reversed(S)))

Buggy submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline

S = input().strip()
Q = int(input())

for i in range(Q):
    q = input().split()
    if q[0] == '1':
        S.reverse()
    elif q[0] == '2':
        if q[1] == '1':
            S = '{}{}'.format(q[2], S)
        elif q[1] == '2':
            S = '{}{}'.format(S, q[2])

print(S)
Problem p02780 (python)

Fixed submission:
import sys
import numpy as np
input = sys.stdin.readline

N, K = map(int, input().split())
p = np.array(list(map(int, input().split())))
c = np.cumsum(p)

ans = c[K-1]

for i in range(N - K):
    tmp = c[i+K] - c[i]
    ans = max(ans, tmp)

print((ans + K) / 2)

Buggy submission (verdict: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
int main()
{
    long N;
    long K;
    cin >> N >> K;
    int p[N];
    for (int i = 0; i < N; ++i)
    {
        cin >> p[i];
    }
    long ans = 0;
    for (long i = 1; i < N - K + 1; ++i)
    {
        long tmp;
        for (int j = 0; j < K; j++)
        {
            tmp += p[i + j];
        }
        if (tmp > ans)
        {
            ans = tmp;
        }
    }
    cout << (ans + K) / 2 << endl;

    return 0;
}
Problem p02900 (python)

Fixed submission:
import sys
import fractions
input = sys.stdin.readline

A, B = map(int, input().split())

n = fractions.gcd(A, B)
if n == 1:
    print(1)
    sys.exit()


def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp % i == 0:
            cnt = 0
            while temp % i == 0:
                cnt += 1
                temp //= i
            arr.append([i, cnt])

    if temp != 1:
        arr.append([temp, 1])

    if arr == []:
        arr.append([n, 1])

    return arr


a = {x[0] for x in factorization(A)}
b = {x[0] for x in factorization(B)}

print(len(a & b) + 1)

Buggy submission (verdict: Runtime Error):
import sys
import fractions
input = sys.stdin.readline

A, B = map(int, input().split())

n = fractions.gcd(A, B)
if n == 1:
    print(1)
    sys.exit()


def get_sieve_of_eratosthenes(n):
    if not isinstance(n, int):
        raise TypeError('n is int type.')
    if n < 2:
        raise ValueError('n is more than 2')
    prime = {2}
    limit = int(n**0.5)
    data = {i + 1 for i in range(2, n, 2)}
    while True:
        p = data[0]
        if limit <= p:
            return prime | data
        prime.add(p)
        data = {e for e in data if e % p != 0}


p = set(get_sieve_of_eratosthenes(n))
count = sum([1 for i in p if not n % i])

print(count + 1)

Buggy submission (verdict: Runtime Error):
import sys
import fractions
input = sys.stdin.readline

A, B = map(int, input().split())

n = fractions.gcd(A, B)
if n == 1:
    print(1)
    sys.exit()


def primes(n):
    is_prime = [True] * (n + 1)
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2, int(n**0.5) + 1):
        if not is_prime[i]:
            continue
        for j in range(i * 2, n + 1, i):
            is_prime[j] = False
    return [i for i in range(n + 1) if is_prime[i]]


p = set(primes(n))
count = sum([1 for i in p if not n % i])

print(count + 1)

Buggy submission (verdict: Runtime Error):
import sys
import math
input = sys.stdin.readline

A, B = map(int, input().split())

n = math.gcd(A, B)
if n == 1:
    print(1)
    sys.exit()


def make_divisors(n):
    divisors = set()
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.add(i)
            if i != n // i:
                divisors.add(n//i)

    # divisors.sort()
    return divisors


def get_sieve_of_eratosthenes(n):
    if not isinstance(n, int):
        raise TypeError('n is int type.')
    if n < 2:
        raise ValueError('n is more than 2')
    prime = [2]
    limit = int(n**0.5)
    data = [i + 1 for i in range(2, n, 2)]
    while True:
        p = data[0]
        if limit <= p:
            return prime + data
        prime.append(p)
        data = [e for e in data if e % p != 0]


d = make_divisors(n)
p = set(get_sieve_of_eratosthenes(n))

print(len(d & p) + 1)
Problem p02947 (python)

Fixed submission:
from scipy.special import comb
N = int(input())
a = [input() for _ in range(N)]

d = dict()
for x in a:
  s = ''.join(sorted(x))
  if s not in d.keys():
    d[s] = 1
  else:
    d[s] += 1

print(sum([comb(i, 2, exact=True) for i in d.values()]))

Buggy submission (verdict: Runtime Error):
import math

def comb(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

N = int(input())
a = [input() for _ in range(N)]

d = dict()
for x in a:
  s = ''.join(sorted(x))
  if s not in d.keys():
    d[s] = 1
  else:
    d[s] += 1

print(sum([comb(i, 2) for i in d.values()]))