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

Fixed submission:
H,W=map(int,input().split());S=[input() for _ in range(H)];G=[[-1]*W for _ in range(H)];G[0][0]=1;q=[(0,0)]
while q:
 i,j=q[0];q=q[1:]
 for x,y in[(1,0),(0,1),(-1,0),(0,-1)]:
  t,u=i+x,j+y
  if 0<=t<H and 0<=u<W and G[t][u]<0 and S[t][u]==".":
   G[t][u]=1+G[i][j];q+=[(t,u)]
print(-1*(G[-1][-1]<0)or sum(s.count(".")for s in S)-G[-1][-1])

Buggy submission (verdict: Runtime Error):
from itertools import product

H, W = map(int, input().split())
S = [input() for _ in range(H)]
G = [[float("inf")]*W for _ in range(H)]
G[0][0] = 1

for _  i, j in product(range(H*W), range(H), range(W)) :
    if S[i][j] == "." :
        for x, y in [(1, 0), (0, 1), (-1, 0), (0, -1)] :
            try :
                G[i][j] = min(1+G[i+x][j+y], G[i][j])
            except : pass

d = sum(s.count(".") for s in S)
a = d-G[-1][-1]
print(-1 if a==-float("inf") else a)
Problem p03480 (python)

Fixed submission:
s=input();l=[];n=len(s)
for i in range(n-1):
 if s[i]!=s[i+1]:l+=[max(i+1,n-i-1)]
print(min(l)if l else n)

Buggy submission (verdict: Runtime Error):
s=input();l=[]
for i in range(len(s)-1):
 if s[i]!=s[i+1]:l+=[max(i+1,len(s)-i-1)]
print(min(l))

Buggy submission (verdict: Runtime Error):
s=input();l=[]
for i in range(len(s)-1):
 if s[i]!=s[i+1]:l+=[max(i,len(s)-i-1)]
print(min(l))
Problem p03588 (python)

Fixed submission:
N,*A=map(int,open(0).read().split())
i=2*sorted(enumerate(A[::2]),key=lambda x:x[1])[-1][0]
print(A[i]+A[i+1])

Buggy submission (verdict: Runtime Error):
N,*A=map(int,open(0).read().split())
i=2*sorted(enumerate(A[::2]),lambda x:x[1])[-1][0]
print(A[i]+A[i+1])
Problem p03608 (python)

Fixed submission:
from itertools import*;from scipy.sparse import*
N,M,R=map(int,input().split());r=map(int,input().split())
G=[[9e9]*N for _ in[0]*N]
for _ in[0]*M:A,B,C=map(int,input().split());G[A-1][B-1]=G[B-1][A-1]=C
D=csgraph.dijkstra(csr_matrix(G))
print(int(min(sum(D[i-1,j-1]for i,j in zip(t,t[1:]))for t in permutations(r))))

Buggy submission (verdict: Runtime Error):
from itertools import*;from scipy.sparse.csgraph import*
N,M,R=map(int,input().split());r=map(int,input().split())
G=[[9e9]*N for _ in[0]*N]
for _ in[0]*M:A,B,C=map(int,input().split());G[A-1][B-1]=G[B-1][A-1]=C
D=dijkstra(G)
print(int(min(sum(D[i-1,j-1]for i,j in zip(t,t[1:]))for t in permutations(r))))
Problem p03637 (python)

Fixed submission:
N,*A=map(int,open(0).read().split());l=[0]*4
for a in A:l[a&3]+=1
o=l[1]+l[3];print("YNeos"[o>1+l[0]or o-1==l[0]and l[2]>0::2])

Buggy submission (verdict: Runtime Error):
N,A=map(int,open(0).read().split());l=[0]*4
for a in A:l[a&3]+=1
print("YNeos"[d[1]+d[3]>1+d[0]::2])
Problem p03657 (python)

Fixed submission:
A,B=map(int,input().split());print("PIomspsoisbslieb l e"[all([A%3,B%3,(A+B)%3])::2])

Buggy submission (verdict: Runtime Error):
A,B=map(int,input().split());print("YNeos"[all(A%3,B%3,(A+B)%3)::2])
Problem p03680 (python)

Fixed submission:
*A,=map(int,open(0));i=1;t=[0]*A[0]+[0]
while i-2and t[i]==0:t[i]=1;i=A[i]
print(-1if i-2else sum(t))

Buggy submission (verdict: Runtime Error):
*A,=map(int,open(0));i=1;t=[0]*A[0]
while i-2and t[i]==0:t[i]=1;i=A[i]
print(-1if i-2else sum(t))

Buggy submission (verdict: Runtime Error):
*A,=map(int,open(0));i=1;t=[0]*A[0]
while i-2or t[i]:t[i]=1;i=A[i]
print(-1if i-2else sum(t))

Buggy submission (verdict: Runtime Error):
*A,=map(int,open(0));i=1;t=[0]*A[0]
while i-2or i in t:t[i]=1;i=A[i]
print(-1if i-2else sum(t))
Problem p04032 (python)

Fixed submission:
s = input()
se = s[::2]
so = s[1::2]
ans = "-1 -1"
for i in range(len(s)-1) :
    if s[i] == s[i+1] :
        ans = str(i+1)+" "+str(i+2)
for i in range(len(se)-1) :
    if se[i] == se[i+1] :
        ans = str(2*i+1)+" "+str(2*i+3)
for i in range(len(so)-1) :
    if so[i] == so[i+1] :
        ans = str(2*i+2)+" "+str(2*i+4)
print(ans)

Buggy submission (verdict: Runtime Error):
s = input()
se = s[::2]
so = s[1::2]
ans = "-1 -1"
for i in range(len(s)-1) :
    if s[i] == s[i+1] :
        ans = str(i+1)+" "+str(i+2)
for i in range(len(se)-1) :
    if se[i] == se[i+1] :
        ans = str(2*i+1)+" "+str(2*i+3)
for i in range(len(se)-1) :
    if so[i] == so[i+1] :
        ans = str(2*i+2)+" "+str(2*i+4)
print(ans)
Problem p02983 (python)

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

Buggy submission (verdict: Runtime Error):
l,r=map(int,input().split())
ans=2018
for i in range(l,r):
	for j in range(i+1,r+1):
    	if i*j%2019<ans:
        	ans=i*j%2019
        elif i*j%2019==ans:
        	print(ans)
            exit()
print(ans)
Problem p03607 (python)

Fixed submission:
import collections
n=int(input())
a=[int(input()) for _ in range(n)]
c = collections.Counter(a)
ans=0
for k,v in c.items():
    if v % 2 != 0:
        ans += 1
print(ans)

Buggy submission (verdict: Runtime Error):
import collections
n=int(input())
a=[]
for _ in range(n)
    a.append(int(input()))
c = collections.Counter(a)
ans=0
for k,v in c.items():
    if v % 2 != 0:
        ans += 1
print(ans)
Problem p02973 (python)

Fixed submission:
from collections import deque
import bisect

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

colors = deque([A[0]])
for a in A[1:]:
    i = bisect.bisect_left(colors, a)
    if i != 0:
        colors[i - 1] = a
    else:
        colors.appendleft(a)

print(len(colors))

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

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

colors = deque([A[0]])
for a in A[1:]:
    i = bisect.bisect_left(colors, a)
    if i == 0:
        colors.appendleft(a)
    else:
        del colors[i - 1]
        bisect.insort_left(colors, a)

print(len(colors))
Problem p02985 (python)

Fixed submission:
MOD = 1000000007
N, K = map(int, input().split())
edge = {}
for _ in range(N - 1):
    a, b = map(int, input().split())
    if a not in edge:
        edge[a] = set()
    edge[a].add(b)
    if b not in edge:
        edge[b] = set()
    edge[b].add(a)


ans = K
q = [(1, None, 1)]
while len(q) > 0:
    par, parpar, depth = q.pop()
    if par not in edge:
        continue
    children = edge[par] - set([parpar])
    if len(children) == 0:
        continue
    if depth == 1:
        start = K - 1
    else:
        start = K - 2
    for i in range(len(children)):
        if start - i <= 0:
            ans = 0
            print(0)
            exit()
        else:
            ans *= start - i
        ans %= MOD
    for c in children:
        q.append((c, par, depth + 1))

print(ans)

Buggy submission (verdict: Runtime Error):
MOD = 1000000007
N, K = map(int, input().split())
edge = {}
for _ in range(N - 1):
    a, b = map(int, input().split())
    if a not in edge:
        edge[a] = set()
    edge[a].add(b)
    if b not in edge:
        edge[b] = set()
    edge[b].add(a)


ans = K
q = [(1, None, 1)]
while len(q) > 0:
    par, parpar, depth = q.pop()
    children = edge[par] - set([parpar])
    if depth == 1:
        start = K - 1
    else:
        start = K - 2
    for i in range(len(children)):
        ans *= start - i
        ans %= MOD
    for c in children:
        q.append((c, par, depth + 1))

print(ans)

Buggy submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(4100000)

MOD = 1000000007
N, K = map(int, input().split())
edge = {}
for _ in range(N - 1):
    a, b = map(int, input().split())
    if a not in edge:
        edge[a] = set()
    edge[a].add(b)
    if b not in edge:
        edge[b] = set()
    edge[b].add(a)


def dig(par, parpar=None, depth=1):
    global ans
    children = edge[par] - set([parpar])
    if depth == 1:
        start = K - 1
    else:
        start = K - 2
    for i in range(len(children)):
        ans *= start - i
        ans %= MOD
    for c in children:
        dig(c, par, depth + 1)

ans = K
dig(1)
print(ans)

Buggy submission (verdict: Runtime Error):
MOD = 1000000007
N, K = map(int, input().split())
edge = {}
for _ in range(N - 1):
    a, b = map(int, input().split())
    if a not in edge:
        edge[a] = set()
    edge[a].add(b)
    if b not in edge:
        edge[b] = set()
    edge[b].add(a)


def dig(par, parpar=None, depth=1):
    global ans
    children = edge[par] - set([parpar])
    if depth == 1:
        start = K - 1
    else:
        start = K - 2
    for i in range(len(children)):
        ans *= start - i
        ans %= MOD
    for c in children:
        dig(c, par, depth + 1)

ans = K
dig(1)
print(ans)
Problem p02999 (python)

Fixed submission:
X, A = map(int, input().split())

if X < A:
    print(0)
else:
    print(10)

Buggy submission (verdict: Runtime Error):
import std.stdio;

void main() {
  int X, A;
  readf("%d %d", &X, &A);
  writeln(X < A ? 0 : 10);
}
Problem p03206 (python)

Fixed submission:
print("Christmas" + (" Eve" * (25 - int(input()))))

Buggy submission (verdict: Runtime Error):
print(“Christmas” + “ “.join([“Eve”] * int(input())))
Problem p03219 (python)

Fixed submission:
a, b = map(int, input().split())
print(a + b // 2)

Buggy submission (verdict: Runtime Error):
a, b = map(int, input())
print(a + b / 2)
Problem p03238 (python)

Fixed submission:
print("Hello World" if input() == "1" else (int(input()) + int(input())))

Buggy submission (verdict: Runtime Error):
print("Hello World" if print() == "1" else (int(input()) + int(input())))
Problem p03262 (python)

Fixed submission:
from fractions import gcd


N, X = map(int, input().split())
x = list(map(int, input().split()))

x.append(X)
x.sort()

last = x[0]
ans = abs(x[0] - x[1])
for i in x[1:]:
    ans = gcd(ans, abs(last - i))
    last = i

print(ans)

Buggy submission (verdict: Runtime Error):
from math import fractions


N, X = map(int, input().split())
x = list(map(int, input().split()))

x.append(X)
x.sort()

last = x[0]
ans = abs(x[0] - x[1])
for i in x[1:]:
    ans = gcd(ans, abs(last - i))
    last = i

print(ans)

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


N, X = map(int, input().split())
x = list(map(int, input().split()))

x.append(X)
x.sort()

last = x[0]
ans = abs(x[0] - x[1])
for i in x[1:]:
    ans = gcd(ans, abs(last - i))
    last = i

print(ans)
Problem p03263 (python)

Fixed submission:
H, W = map(int, input().split())

a = [None]
for i in range(H):
    a.append([None] + list(map(int, input().split())))


def is_odd(i, j):
    return a[i][j] % 2 == 1


def next_cell(i, j):
    if i % 2 == 1:
        if j < W:
            return i, j + 1
    else:
        if 1 < j:
            return i, j - 1
    if i < H:
        return i + 1, j
    return None, None


def move(i, j):
    ni, nj = next_cell(i, j)
    if ni is None:
        return None
    a[i][j] -= 1
    a[ni][nj] += 1
    return "{} {} {} {}".format(i, j, ni, nj)


ans = []
i, j = 1, 1
while True:
    if is_odd(i, j):
        res = move(i, j)
        if res is not None:
            ans.append(res)
    i, j = next_cell(i, j)
    if i is None:
        break

print(len(ans))
for line in ans:
    print(line)

Buggy submission (verdict: Runtime Error):
H, W = map(int, input().split())

a = [None]
for i in range(H):
    a.append([None] + list(map(int, input().split())))


def is_odd(i, j):
    return a[i][j] % 2 == 1


def next_cell(i, j):
    if i % 2 == 1:
        if j < W:
            return i, j + 1
    else:
        if 0 < j:
            return i, j - 1
    if i < H:
        return i + 1, j
    return None, None


def move(i, j):
    ni, nj = next_cell(i, j)
    if ni is None:
        return None
    a[i][j] -= 1
    a[ni][nj] += 1
    return "{} {} {} {}".format(i, j, ni, nj)


ans = []
for j in range(1, W + 1):
    for i in range(1, H + 1):
        if is_odd(i, j):
            res = move(i, j)
            if res is not None:
                ans.append(res)


print(len(ans))
for line in ans:
    print(line)
Problem p03290 (python)

Fixed submission:
import itertools
import math

D, G = map(int, input().split())

p = {}
c = {}
s = {}
for i in range(1, D + 1):
    pi, ci = map(int, input().split())
    score = 100 * i * pi + ci
    s[i] = score
    p[i] = pi
    c[i] = ci


def complete(pset):
    score = 0
    solved = 0
    comped = set()
    for i, b in zip(range(1, D + 1), pset):
        if b:
            score += s[i]
            solved += p[i]
            comped.add(i)
    leftset = set(list(range(1, D + 1))) - comped
    return score, solved, leftset


def left(norm, leftset):
    if norm <= 0 or len(leftset) == 0:
        return 0
    i = max(leftset)
    res = int(math.ceil(norm / (100 * i)))
    if res < p[i]:
        return res
    return float("inf")


ans = float("inf")
for pset in itertools.product((True, False), repeat=D):
    score, solved, leftset = complete(pset)
    solved += left(G - score, leftset)
    ans = min(ans, solved)

print(ans)

Buggy submission (verdict: Runtime Error):
# 解法は正しいはずだがコーナーケースに引っかかるらしくWAが1個出る

import itertools
import math

D, G = map(int, input().split())

p = {}
c = {}
s = {}
for i in range(1, D + 1):
    pi, ci = map(int, input().split())
    score = 100 * i * pi + ci
    s[i] = score
    p[i] = pi
    c[i] = ci


def complete(pset):
    score = 0
    solved = 0
    comped_max = 0
    for b in pset:
        if b:
            score += s[i]
            solved += p[i]
            comped_max = max(comped_max, i)
    return score, solved, comped_max


def left(norm, i):
    if norm <= 0:
        return 0
    res = int(math.floor(norm / (100 * i)))
    if res < p[i]:
        return res
    return float("inf")


ans = float("inf")
for pset in itertools.product((True, False), repeat=D):
    score, solved, comped_max = complete(pset)
    solved += left(G - score, comped_max)
    ans = min(ans, solved)

print(ans)

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

D, G = map(int, input().split())

P = set()
p = {}
c = {}
s = {}
for i in range(1, D + 1):
    pi, ci = map(int, input().split())
    score = 100 * i * pi + ci
    P.add(i)
    s[i] = score
    p[i] = pi
    c[i] = ci


def complete(pset):
    score = 0
    solved = 0
    comped = set()
    i = 1
    for b in pset:
        if b:
            score += s[i]
            solved += p[i]
            comped.add(i)
        i += 1
    return score, solved, comped


def left(norm, comped):
    if norm <= 0:
        return 0
    for i in sorted(list(P - comped), reverse=True):
        res = int(math.floor(norm / (100 * i)))
        if res < p[i]:
            return res


ans = float("inf")
for pset in itertools.product((True, False), repeat=D):
    score, solved, comped = complete(pset)
    solved += left(G - score, comped)
    ans = min(ans, solved)

print(ans)
Problem p03363 (python)

Fixed submission:
from collections import Counter

def c2(a):
    if a <= 1:
        return 0
    return a * (a - 1) / 2

def solve(arr):
    cum = [0]
    s = 0
    for i in arr:
        s += i
        cum.append(s)

    return int(sum(c2(v) for k, v in Counter(cum).items()))

input()
print(solve([int(i) for i in input().split()]))

Buggy submission (verdict: Runtime Error):


def is_symmetric(board):
    for i in range(N):
        for j in range(i, N):
            if board(j, i) != board(i, j):
                return False
    return True


def translate(board, a, b):
    def get(i, j):
        return board[(i + a) % N][(j + b) % N]
    
    return get


def solve(board):
    ans = 0
    for a in range(N):
        if is_symmetric(translate(board, a, 0)):
            ans += N - a
    for b in range(N):
        if b == 0:
            continue
        if is_symmetric(translate(board, 0, b)):
            ans += N - b
    return ans


N = int(input())
board = []
for i in range(N):
    board.append(input())


print(solve(board))
Problem p02838 (python)

Fixed submission:
#!/usr/bin/python3
# -*- coding: utf-8 -*-

import sys
#import bisect
#from collections import deque
import math

#############################
#         59 58 57     1
# Ai = 0xbi bi bi ... bi
# 
#############################

#############################
#   N-1 N
#   Σ   Σ     (Ai xor Aj)
#   i=1 j=i+1
#
#   59  N-1 N       d      d
# = Σ   Σ   Σ     (bi xor bj) * 2^(d-1)
#   d=1 i=1 j=i+1
#############################

#############################
#   N-1 N       d      d
#   Σ   Σ     (bi xor bj)
#   i=1 j=i+1
#
# = (bx のうち 1 の数) * (bx のうち 0 の数)
#############################

def input():
    return sys.stdin.readline().rstrip('\n')

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

s = 0 #sum

for d in range(60):
    B = [1 & (a >> d) for a in A]
    s += B.count(1) * B.count(0) * (2**d)
    #print(d,B,B.count(1),B.count(0),2**(d-1),s)

#print(s)
print(s % (10**9+7))

Buggy submission (verdict: Runtime Error):
#!/usr/bin/python3
# -*- coding: utf-8 -*-

import sys
#import bisect
#from collections import deque
import math

#############################
#         59 58 57     1
# Ai = 0xbi bi bi ... bi
# 
#############################

#############################
#   N-1 N
#   Σ   Σ     (Ai xor Aj)
#   i=1 j=i+1
#
#   59  N-1 N       d      d
# = Σ   Σ   Σ     (bi xor bj) * 2^(d-1)
#   d=1 i=1 j=i+1
#############################

#############################
#   N-1 N       d      d
#   Σ   Σ     (bi xor bj)
#   i=1 j=i+1
#
# = (bx のうち 1 の数) * (bx のうち 0 の数)
#############################

def input():
    return sys.stdin.readline().rstrip('\n')

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

s = 0 #sum

for d in range(60):
    B = [1 & (a >> d)) for a in A]
    s += B.count(1) * B.count(0) * (2**d)
    #print(d,B,B.count(1),B.count(0),2**(d-1),s)

#print(s)
print(s % (10**9+7))
Problem p02886 (python)

Fixed submission:
import sys
#import bisect
from collections import deque

def input():
    return sys.stdin.readline().rstrip('\n')

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

D = deque(D)
sum0 = D.pop()
hp = 0

for _ in range(N-1):
    d = D.pop()
    hp += d * sum0
    sum0 += d

print(hp)

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

def input():
    return sys.stdin.readline().rstrip('\n')

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

D = deque(D)
sum0 = D.pop()
hp = 0

for _ in range(N-1):
    d = D.pop()
    hp += d * sum0
    sum0 += d

print(hp)
Problem p02889 (python)

Fixed submission:
#!/usr/bin/python3
# -*- coding: utf-8 -*-

# scipy version

import sys
from collections import deque
from array import array

from scipy.sparse import csr_matrix
from scipy.sparse.csgraph import floyd_warshall

def input():
    return sys.stdin.readline().rstrip('\n')

##### main

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

C = [[0]*N for _ in range(N)]

for i in range(M):
    a,b,c = list(map(int, input().split()))
    if c>L:
        continue
    C[a-1][b-1] = c

Q = int(input())

ST = [None]*Q

for i in range(Q):
    s, t = list(map(int, input().split()))
    ST[i] = (s-1,t-1)

dist_matrix, predecessors = floyd_warshall(csgraph=C, directed=False, return_predecessors=True)

# D[i][j] <= L となる i,j に辺を張る
for i in range(N):
    for j in range(i+1,N):
        if dist_matrix[i][j] <= L:
            C[i][j] = 1

dist_matrix, predecessors = floyd_warshall(csgraph=C, directed=False, return_predecessors=True)

# answer
for q in range(Q):
    i,j = ST[q]
    step = dist_matrix[i][j]
    if step > 10**9:
        print(-1)
    else:
        print(int(step-1))

Buggy submission (verdict: Runtime Error):
#!/usr/bin/python3
# -*- coding: utf-8 -*-

import sys
from collections import deque
from array import array

def input():
    return sys.stdin.readline().rstrip('\n')

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

_C = {}

for i in range(M):
    a,b,c = list(map(int, input().split()))
    a -= 1
    b -= 1
    if c>L:
        continue
    _C[a*300+b] = c
    _C[b*300+a] = c

def C_(i,j):
    return _C.get(i*300+j, sys.maxsize)

Q = int(input())

S = array('q', [0]*Q)
T = array('q', [0]*Q)

for i in range(Q):
    S[i],T[i] = list(map(int, input().split()))

# ワーシャルフロイド法

# distance from i to j
D = [array('q', [0]*N) for i in range(N)]

# initialization
for i in range(N):
    for j in range(N):
        D[i][j] = C_(i,j)
        #print(i,j,D[i][j])

# 本計算
for k in range(N):
    for i in range(N):
        for j in range(N):
            if D[i][j] > D[i][k] + D[k][j]:
                D[i][j] = D[i][k] + D[k][j]


# D[i][j] <= L となる i,j に辺を張る
for i in range(N):
    for j in range(N):
        if D[i][j] <= L:
            _C[i*300+j] = 1
            _C[j*300+i] = 1

# ワーシャルフロイド法 again

# distance from i to j
D = [array('q', [0]*N) for i in range(N)]
STEP = [array('q', [0]*N) for i in range(N)]

# initialization
for i in range(N):
    for j in range(N):
        c = C_(i,j)
        D[i][j] = c
        if c == sys.maxsize:
            STEP[i][j] = sys.maxsize
        else:
            STEP[i][j] = 1
        #print(i,j,D[i][j],STEP[i][j])

# 本計算
for k in range(N):
    for i in range(N):
        for j in range(N):
            if D[i][j] > D[i][k] + D[k][j]:
                D[i][j] = D[i][k] + D[k][j]
                STEP[i][j] = STEP[i][k] + STEP[k][j]


# answer
for q in range(Q):
    i = S[q]-1
    j = T[q]-1
    step = STEP[i][j]
    if step == sys.maxsize:
        #print(i,j,-1)
        print(-1)
    else:
        print(step-1)
Problem p02947 (python)

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

N = int(input())

dd=defaultdict(int)

Sread = sys.stdin.read()


for s in Sread.split('\n'):
    slist = list(s)
    slist.sort()
    s = ''.join(slist)
    #print('-', s)
    dd[s]+=1

#FAC = {}
#FAC[1] = 1
#
#for i in range(2,N+1):
#    FAC[i] = FAC[i-1]*i
    
count = 0

for k in dd:
    s_counts = dd[k]
    if s_counts > 1:
        #count += FAC[s_counts]//2
        count += comb(s_counts, 2, exact=True)

print(count)

Buggy submission (verdict: Runtime Error):
from array import array

N = int(input())

S = []

for i in range(N):
    s = input()
    slist = list(s)
    slist.sort()
    s = ''.join(slist)
    S.append(s)

FAC = array('l', [0]*(N+1))
FAC[1] = 1

for i in range(2,N+1):
    FAC[i] = FAC[i-1]*i
    
count = 0


for s in set(S):
    s_counts  = S.count(s)
    if s_counts > 1:
        #fac = math.factorial(s_counts)
        #count += fac//2
        count += FAC[s_counts]//2

print(count)
Problem p02983 (python)

Fixed submission:
L,R = list(map(int, input().split()))

MOD=[0] * (2019*2019)

def myidx(i,j):
    return i * 2019 + j

for i in range(2019):
    for j in range(i+1,2019):
        idx = myidx(i,j)
        MOD[idx] = (i*j) % 2019

#for i in range(2019):
#    idx = myidx(i,i)
#    MOD[idx] = 2019

MMM = []
MIN = 2019
Lmod = L % 2019
Rmod = R % 2019

if L+2019 <= R:
    for i in range(2019):
        for j in range(i+1,2019):
            idx = myidx(i,j)
            MIN = min(MIN, MOD[idx])
            #MMM.append(MOD[idx])
elif Lmod <= Rmod:
    for i in range(Lmod, Rmod+1):
        for j in range(i+1, Rmod+1):
            idx = myidx(i,j)
            MIN = min(MIN, MOD[idx])
            #MMM.append(MOD[idx])

elif Lmod > Rmod:
    for i in list(range(0,Rmod+1)) + list(range(Lmod, 2019)):
        for j in list(range(i+1,Rmod+1)) + list(range(max(Lmod,i+1), 2019)):
            idx = myidx(i,j)
            MIN = min(MIN, MOD[idx])
            #MMM.append(MOD[idx])

#MMM=list(set(MMM))
#MMM.sort()
#print(MMM.pop(0))
print(MIN)

Buggy submission (verdict: Runtime Error):
L,R = list(map(int, input().split()))


MOD=[0] * (2019*2019)

def myidx(i,j):
    return i * 2019 + j

for i in range(2019):
    for j in range(2019):
        idx = myidx(i,j)
        MOD[idx] = (i*j) % 2019

for i in range(2019):
    idx = myidx(i,i)
    MOD[idx] = 2019

MMM = []
Lmod = L % 2019
Rmod = R % 2019

if L+2019 <= R:
    for i in range(2019):
        for j in range(i+1,2019):
            idx = myidx(i,j)
            MMM.append(MOD[idx])
elif Lmod <= Rmod:
    for i in range(Lmod, Rmod+1):
        for j in range(i+1, Rmod+1):
            idx = myidx(i,j)
            MMM.append(MOD[idx])

elif Lmod > Rmod:
    for i in list(range(0,Rmod+1)) + list(range(Lmod, 2019)):
        for j in list(range(i+1,Rmod+1)) + list(range(i+1, 2019)):
            idx = myidx(i,j)
            MMM.append(MOD[idx])

MMM=list(set(MMM)).sort()
print(MMM.pop(0))