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

Fixed submission:
HM = input().split()
H, M = [int(HM[i]) for i in range(len(HM))]

S = [input() for i in range(H)]
#print(S)
#print(T[0][1])
#S2 = list([S[i] for i in range(H)] for j in range(M))
S2 = []
for i in range(H):
    S2.append(list(S[i]))
#print(S2)

def minesweeper():
    for i in range(H):
        for j in range(M):
            if S[i][j] == ".":
                c = count(i, j)
                #print(c)
                S2[i][j] = c
    for i in range(H):
        for j in range(M-1):
            print(S2[i][j], end="")
        print(S2[i][M-1])
    return 0


def count(x,y):
    c = 0
    #print("x={}".format(x))
    if (x >= 1 and y >= 1):
        if S[x-1][y-1] == '#':
            c += 1
            #print('1')
    if (x >= 1):
        if S[x-1][y] == "#":
            c += 1
            #print('2')
    if x >= 1 and y <= M - 2:
        if S[x-1][y+1] == "#":
            c += 1
            #print("x={}".format(x))
            #print('3')
    if (y >= 1):
        if S[x][y-1] == "#":
            c += 1
            #print('4')
    if (y <= M - 2):
        if S[x][y+1] == "#":
            c += 1
            #print('5')
    if (x <= H-2 and y >= 1):
        if S[x+1][y-1] == "#":
            c += 1
            #print('6')
    if (x <= H-2):
        if S[x+1][y] == "#":
            c += 1
            #print('7')
    if (x <= H-2 and y <= M-2):
        if S[x+1][y+1] == "#":
            c += 1
            #print('8')
    return c

minesweeper()

Buggy submission (verdict: Runtime Error):
HM = input().split()
H, M = [int(HM[i]) for i in range(len(HM))]
#print(H,M)
S = [input().split() for i in range(H)]
#print(S)
#print(S[0][1])
S2 = S

def minesweeper():
    for i in range(H):
        for j in range(M):
            if S[i][j] == '.':
                C = count(i,j)
                S2[i][j] = C
    for i in range(H):
        for k in range(M-1):
            Shai = S2[i][k]
            print(Shai, end=" ")
        print(S2[i][M-1])
    return S2


def count(x,y):
    c = 0
    #print("x={}".format(x))
    if (x >= 1 and y >= 1):
        if S[x-1][y-1] == '#':
            c += 1
            #print('1')
    if (x >= 1):
        if S[x-1][y] == "#":
            c += 1
            #print('2')
    if x >= 1 and y <= M - 2:
        if S[x-1][y+1] == "#":
            c += 1
            #print("x={}".format(x))
            #print('3')
    if (y >= 1):
        if S[x][y-1] == "#":
            c += 1
            #print('4')
    if (y <= M - 2):
        if S[x][y+1] == "#":
            c += 1
            #print('5')
    if (x <= H-2 and y >= 1):
        if S[x+1][y-1] == "#":
            c += 1
            #print('6')
    if (x <= H-2):
        if S[x+1][y] == "#":
            c += 1
            #print('7')
    if (x <= H-2 and y <= M-2):
        if S[x+1][y+1] == "#":
            c += 1
            #print('8')
    return c

minesweeper()
Problem p03633 (python)

Fixed submission:
n = int(input())
t = []
ans = 1
for i in range(n):
    t.append(int(input()))
def gcd(a,b):
    while b>0:
        a,b = b, a%b
    return a
def lcm(a,b):
    return a*b//gcd(a,b)

for i in range(n):
    ans = lcm(ans,t[i])

print(ans)

Buggy submission (verdict: Runtime Error):
n = int(input())
t = []
ans = 1
for i in range(n):
    t.append(int(input()))
def gcd(a,b):
    while b>0:
        a,b = b, a%b
    return int(a)
def lcm(a,b):
    return int(a*b/gcd(a,b))

for i in range(n):
    ans = lcm(ans,t[i])

print(ans)

Buggy submission (verdict: Runtime Error):
n = int(input())
t = []
ans = 1
for i in range(n):
    t.append(int(input()))
def gcd(a,b):
    while b>0:
        a,b = b, a%b
    return a
def lcm(a,b):
    return a*b/gcd(a,b)

for i in range(n):
    ans = lcm(ans,t[i])

print(int(ans))
Problem p02924 (python)

Fixed submission:
N=int(input())
print((N-1)*N//2)

Buggy submission (verdict: Runtime Error):
N=int(input())
if N%2==0:
  print(N//2*(N-1))
elif:
  print((N-1)//2*N)

Buggy submission (verdict: Runtime Error):
N=int(input())
print((N-1)*int(N/2)))
Problem p03047 (python)

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

print(N-(K-1))

Buggy submission (verdict: Runtime Error):
N,K=int(input().split())

print(N-(K-1))
Problem p03048 (python)

Fixed submission:
R,G,B,N=map(int,input().split())

tmp=0
for i in range(N//R+1):
  for j in range((N-R*i)//G+1):
    if (N-(R*i+G*j))%B==0:
      tmp+=1
print(tmp)

Buggy submission (verdict: Runtime Error):
R,G,B,N=map(int,input().split())

tmp=0
for i in range(N//R+1):
  for j in range((N-R*i)//G+1):
    if and (N-(R*i+G*j))%B==0:
      tmp+=1
print(tmp)
Problem p03138 (python)

Fixed submission:
N, K = map(int, input().split())
A = list(map(int, input().split()))

MAX_DIGIT_LENGTH=50

dp=[[-1 for _ in range(2)] for _ in range(100)]
dp[0][0]=0

for d in range(MAX_DIGIT_LENGTH):
  mask=1<<((MAX_DIGIT_LENGTH-1)-d)
  
  tmp=0
  for a in A:
    if a&mask == mask:
      tmp+=1
      
  cost0=mask*tmp
  cost1=mask*(N-tmp)
    
  if dp[d][1]!=-1:
    dp[d+1][1]=max(dp[d][1]+max(cost0, cost1), dp[d+1][1])
  
  if dp[d][0]!=-1:
    if K&mask == mask:
      dp[d+1][1]=max(dp[d][0]+cost0, dp[d+1][1])
      dp[d+1][0]=max(dp[d][0]+cost1, dp[d+1][0])
    else:
      dp[d+1][0]=max(dp[d][0]+cost0, dp[d+1][0])
      
print(max(dp[MAX_DIGIT_LENGTH][0], dp[MAX_DIGIT_LENGTH][1]))

Buggy submission (verdict: Runtime Error):
N, K = map(int, input().split())
A = list(map(int, input().split()))
L = len(bin(K)[2:])
bA=[bin(a)[2:].zfill(L) for a in A]

ans=''
for i in range(L):
    if sum([int(bA[i][j]) for j in range(N)])<=N//2:
      ans=ans+'1'
    else:
      ans=ans+'0'

ans=int(ans,2)
res=0
for a in A:
  res+=(a^ans)
print(res)
Problem p03206 (python)

Fixed submission:
D=int(input())

if D==25:
  print('Christmas')
elif D==24:
  print('Christmas Eve')
elif D==23:
  print('Christmas Eve Eve')
else:
  print('Christmas Eve Eve Eve')

Buggy submission (verdict: Runtime Error):
import collections

def conv(cc, ks, K):
    tm=max([sum(cc[j:j+(ks+1)]) for j in range(len(cc)-(ks-1))])
    if tm>=K:
        return ks
    else:
        return conv(cc, ks+1, K)

N, K=map(int, input().split())
h=[int(input()) for i in range(N)]

cc=list(collections.Counter(h).values())

print(conv(cc,0,K))
Problem p03214 (python)

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

mean = sum(a)/N
ind = None
min = None
for i in range(N):
    tmp=abs(mean-a[i])
    if min is None:
        min=tmp
        ind=i
    else:
        if tmp<min:
            min=tmp
            ind=i

print(ind)

Buggy submission (verdict: Runtime Error):
N, K = list(map(int, input().split()))
a = list(map(int, input().split()))

b=[]
for i in range(N):
    for j in range(i+1,N+1):
        b.append(sum(a[i:j]))

b.sort()
b=b[::-1]
for sp in range(0,N+1-K):
    if [len(bin(b[i])[2:]) for i in range(sp,sp+K)] == [len(bin(b[sp])[2:])for _ in range(sp,sp+K)]:
        break
s=b[sp:sp+K]
if K==1:
    tmp=s[0]
else:
    tmp=s[0]&s[1]
    for i in range(2,K):
        tmp=tmp&s[i]

print(tmp)

Buggy submission (verdict: Runtime Error):
N, K = list(map(int, input().split()))
a = list(map(int, input().split()))

b=[]
for i in range(N):
    for j in range(i+1,N+1):
        b.append(sum(a[i:j]))

b.sort()
b=b[::-1]
for sp in range(0,N+1-K):
    if [len(bin(b[i])[2:]) for i in range(sp,sp+K)] == [len(bin(b[sp])[2:])for i in range(sp,sp+K)]:
        break
s=b[sp:sp+K]
if K==1:
    tmp=s[0]
else:
    tmp=s[0]&s[1]
    for i in range(2,K):
        tmp=tmp&s[i]

print(tmp)

Buggy submission (verdict: Runtime Error):
N, K = list(map(int, input().split()))
a = list(map(int, input().split()))

b=[]
for i in range(N):
    for j in range(i+1,N+1):
        b.append(sum(a[i:j]))

b.sort(reverse=True)
s=b[:K]

Buggy submission (verdict: Runtime Error):
N, K = list(map(int, input().split()))
a = list(map(int, input().split()))

b=[]
for i in range(N):
    for j in range(i+1,N+1):
        b.append(sum(a[i:j]))

b.sort(reverse=True)
s=b[:K]
if K==1:
    tmp=s[0]
else:
    tmp=s[0]&s[1]
    for i in range(2,K):
        tmp=tmp&s[i]

print(tmp)
Problem p03219 (python)

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

Buggy submission (verdict: Runtime Error):
X, Y = map(int, input())
print(X+Y//2)
Problem p03229 (python)

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

A.sort(reverse=True)
if len(A)%2==0:
  print(A[len(A)//2-1]-A[len(A)//2]+2*sum(A[:len(A)//2-1])-2*sum(A[len(A)//2+1:]))
else:
  tmp1=-A[len(A)//2]-A[len(A)//2+1]+2*sum(A[:len(A)//2])-2*sum(A[len(A)//2+2:])
  tmp2=A[len(A)//2-1]+A[len(A)//2]+2*sum(A[:len(A)//2-1])-2*sum(A[len(A)//2+1:])
  print(tmp1 if tmp1>tmp2 else tmp2)

Buggy submission (verdict: Runtime Error):
N=int(input())
A=[int(input()) for _ in range(N)]

A.sort(reverse=True)

ans=0
while A!=[]:
  ans+=abs(A.pop(0)-A[-1])
  A[::-1]
  
print(ans)
Problem p03251 (python)

Fixed submission:
N, M, X, Y = map(int, input().split())
x=list(map(int, input().split()))
y=list(map(int, input().split()))

if max(x)<min(y):
  for i in range(max(x)+1,min(y)+1):
    if i>X and i<=Y:
      print('No War')
      break
  else:
    print('War')
else:
  print('War')

Buggy submission (verdict: Runtime Error):
N, M, X, Y = map(int, input().split())
x=list(map(int, input().split()))
y=list(map(int, input().split()))

if max(x)<min(y):
  for i in range(max(x)+1,min(y)+1):
    if i>X and i<=Y:
      print('No War')
      break
  else
    print('War')
else:
  print('War')

Buggy submission (verdict: Runtime Error):
N, M, X, Y = map(int, input().split())
x=list(map(int, input().split()))
y=list(map(int, input().split()))

if max(x)<min(y):
  for i in range(max(x)+1,min(y)+1)
    if i>X and i<=Y:
      print('No War')
      break
  else
    print('War')
else:
  print('War')
Problem p03281 (python)

Fixed submission:
N=int(input())

ans=0
for i in range(1,N+1,2):
  tmp=0
  t=i**(1/2)
  for j in range(1,int(t)+1):
    if i%j==0:
      tmp+=1
      
  tmp=tmp*2
  if t-int(t)<=1e-3:
    tmp-=1

  if tmp==8:
    ans+=1
      
print(ans)

Buggy submission (verdict: Runtime Error):
N=int(input())

for i in range(1,N+1):
  tmp=0
  t=i**(1/2)
  for j in range(1,int(t)+1):
    if i%j==0:
      tmp+=1
      
  if t-int(t)<=1e-3:
    if tmp*2-1==8:
      ans+=1
      
  else:
    if tmp*2==8:
      ans+=1
      
print(ans)

Buggy submission (verdict: Runtime Error):
N=int(input())

for i in range(1,N+1):
  tmp=0
  for j in range(1,int(sqrt(i))+1):
    if i%j==0:
      tmp+=1
      
  if sqrt(i)-int(sqrt(i))<=1e-3:
    if tmp*2-1==8:
      ans+=1
      
  else:
    if tmp*2==8:
      ans+=1
      
print(ans)
Problem p03282 (python)

Fixed submission:
S = input()
K = int(input())

D=5000000000000000

tmp=0
for s in S:
  if s=='1':
    tmp+=1
    if tmp>=K:
      print(s)
      break
    continue
    
  t=1
  for _ in range(D):
    t=t*int(s)
    if tmp+t>=K:
      print(s)
      break
  else:
    tmp+=t
    continue
  break

Buggy submission (verdict: Runtime Error):
S = int(input())
K = int(input())

D=5000000000000000

tmp=0
for s in S:
  tmp+=int(s)*5000000000000000 if s!='1' else 1
  if tmp>K:
    print(s)
Problem p03284 (python)

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

if N%K==0:
  print(0)
else:
  print(1)

Buggy submission (verdict: Runtime Error):
N,K=map(int, inpur().split())

if K%N==0:
  print(0)
else:
  print(1)
Problem p03292 (python)

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

A.sort()
A.reverse()

print(abs(A[0]-A[1])+abs(A[1]-A[2]))

Buggy submission (verdict: Runtime Error):
S = input()
T = input()

for i in range(len(S)):
    s=S[-i:]+S[0:-i]
    if s==T:
        print('Yes')
        break
else:
    print('No')
Problem p03433 (python)

Fixed submission:
N = int(input())
A = int(input())

if N%500<=A:
  print('Yes')
else:
  print('No')

Buggy submission (verdict: Runtime Error):
N = int(input())
A = int(input())

if N%500=<A:
  print('Yes')
else:
  print('No')
Problem p03486 (python)

Fixed submission:
s = input()
t = input()
s=sorted(s)
t=sorted(t,reverse=True)
print('Yes' if s<t else 'No')

Buggy submission (verdict: Runtime Error):
s = input()
t = input()
s.sort()
t.sort(reverse=True)
print('Yes' if s<t else 'No')
Problem p02958 (python)

Fixed submission:
input()
p = [int(x) for x in input().split()]
    
p_sorted = sorted(p)
    
diff = 0
for p_elem, p_sorted_elem in zip(p, p_sorted):
    if p_elem != p_sorted_elem:
        diff += 1
    
if diff == 0 or diff == 2:
    print('YES')
else:
    print('NO')

Buggy submission (verdict: Runtime Error):
    input()
    p = [int(x) for x in input().split()]
     
    p_sorted = p.sorted()
     
    diff = 0
    for p_elem, p_sorted_elem in zip(p, p_sorted):
      	if p_elem !+ p_sorted_elem:
          	diff += 1
     
    if diff == 0 or diff == 2:
      	print('YES')
    else:
      	print('NO')

input()
p = [int(x) for x in input().split()]

p_sorted = sorted(p)

diff = 0
for p_elem, p_sorted_elem in zip(p, p_sorted):
  	if p_elem !+ p_sorted_elem:
      	diff += 1

if diff == 0 or diff == 2:
  	print('YES')
else:
  	print('NO')

Buggy submission (verdict: Runtime Error):
input()
p = [int(x) for x in input().split()]

p_sorted = p.sorted()

diff = 0
for p_elem, p_sorted_elem in zip(p, p_sorted):
  	if p_elem !+ p_sorted_elem:
      	diff += 1

if diff == 0 or diff == 2:
  	print('YES')
else:
  	print('NO')
Problem p03005 (python)

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

if K == 1:
    print(0)
else:
    print(N - K)

Buggy submission (verdict: Runtime Error):
, K = map(int, input().rstrip().split())

print(N - K)
Problem p03031 (python)

Fixed submission:
#!/usr/bin/env python3

def switch_on_off(n, keta):
    bin_str = format(n, '0{}b'.format(keta))
    return list(bin_str)

def check_light(n, N, s, index, P):
    switch = switch_on_off(n, N)
    sum = 0
    for v in s:
        sum += int(switch[int(v) - 1])
    if sum % 2 == P[index]:
        return 1
    return 0

N, M = map(int, input().rstrip().split())
K = []
S = []
for _ in range(M):
    tmp = list(map(int, input().rstrip().split()))
    K.append(tmp[0])
    S.append(tmp[1:])
P = list(map(int, input().rstrip().split()))


ans = 0
for n in range(2 ** N):
    sum = 0
    for index, s in enumerate(S):
        sum += check_light(n, N, s, index, P)
    if sum == M:
        ans += 1

print(ans)

Buggy submission (verdict: Runtime Error):
#!/usr/bin/env python3

def switch_on_off(n, keta):
    bin_str = format(n, f'0{keta}b')
    return list(bin_str)

def check_light(n, N, s, index, P):
    switch = switch_on_off(n, N)
    sum = 0
    for v in s:
        sum += int(switch[int(v) - 1])
    if sum % 2 == P[index - 1]:
        return 1
    return 0

N, M = map(int, input().rstrip().split())
K = []
S = []
for _ in range(M):
    tmp = list(map(int, input().rstrip().split()))
    K.append(tmp[0])
    S.append(tmp[1:])
P = list(map(int, input().rstrip().split()))


ans = 0
for n in range(2 ** N):
    sum = 0
    for index, s in enumerate(S):
        sum += check_light(n, N, s, index, P)
    if sum == M:
        ans += 1

print(ans)
Problem p02946 (python)

Fixed submission:
k,x=map(int,input().split())
for i in range(x-k+1,x+k):
  print(i, end=' ')

Buggy submission (verdict: Runtime Error):
k,x=map(int,input().split())
for i in range(x-k+1,x+K):
  print(i, end=' ')
Problem p02957 (python)

Fixed submission:
a,b=map(int,input().split())
if (a+b) % 2 ==0:
  print(int((a+b)/2))
else:
  print("IMPOSSIBLE")

Buggy submission (verdict: Runtime Error):
a,b=map(int,input().split())
if (a+b) % 4 ==0:
  print(int((a+b)/4))
  else:
    print("IMPOSSIBLE")
Problem p02958 (python)

Fixed submission:
n = int(input())
p = list(map(int,input().split()))
count = 0
for i in range(n):
    if p[i] != i + 1:
        count += 1
if count <= 2:
    print('YES')
else:
    print('NO')

Buggy submission (verdict: Runtime Error):
N=input()
List=[int(i) for i in input().split()]
count=0
for i in range(N):
  if i != List[i]:
    count += 1
if count <=2:
  print("YES")
else:
  print("NO")
Problem p02969 (python)

Fixed submission:
r=int(input())
print(3*r**2)

Buggy submission (verdict: Runtime Error):
a,b=map(int,input().split())
c=(a//(2b+1))+1
print(c)

Buggy submission (verdict: Runtime Error):
r=input()
print(3*r*r)
Problem p03087 (python)

Fixed submission:
N, Q = map(int, input().split())
S = input()
t = [0] * (N + 1)
for i in range(N):
	t[i + 1] = t[i] + (1 if S[i : i + 2] == 'AC' else 0)
for i in range(Q):
	l, r = map(int, input().split())
	print(t[r-1] - t[l-1])

Buggy submission (verdict: Runtime Error):
N, Q = map(int, input().split())
S = input()
t = [0] * (N + 1)
for i in range(N):
t[i + 1] = t[i] + (1 if S[i : i + 2] == 'AC' else 0)
for i in range(Q): l, r = map(int, input().split())
print(t[r-1] - t[l-1])
Problem p03125 (python)

Fixed submission:
x,y=map(int,input().split())
if y%x ==0:
  print(x+y)
else:
  print(y-x)

Buggy submission (verdict: Runtime Error):
a,b = input()
if b%a ==0:
  print(a+b)
else:
  print(b-a)

Buggy submission (verdict: Runtime Error):
a, b = input()
if b%a ==0:
  print(a+b)
  else:
    print(b-a)
Problem p03161 (python)

Fixed submission:
N, K = map(int,input().split())
H = list(map(int,input().split()))

dp = [1e9]*N
dp[0] = 0
for i, b in enumerate(H):
  if i != 0:
    x = max(0, i-K)
    dp[i] = min([abs(b-d)+p for d, p in zip(H[x:i], dp[x:i])])
print(dp[-1])

Buggy submission (verdict: Runtime Error):
N=int(input())
h = list(map(int , input().split()))
dp = [10**9+1]*N
dp[0] = 0
dp[1] = abs(h[0]-h[1])
for i in range(2,N):
    for j in range(1, i-1):
        dp[i] = min(dp[i-j]+abs(h[i]-h[i-j]), dp[]+abs(h[i]-h[i-j]))
print(dp[N-1])
Problem p03210 (python)

Fixed submission:
N = int(input())
if  N == 7 or N == 5 or N == 3:
	print('YES')
else:
  	print('NO')

Buggy submission (verdict: Runtime Error):
N = int(input())
if  N == 7　or N == 5 or N == 3:
  print('YES')
else:
  print('NO')

Buggy submission (verdict: Runtime Error):
N = int(input())
if  N == 7　or N == 5 or N == 3:
	print('YES')
else:
  	print('NO')
Problem p03292 (python)

Fixed submission:
a,b,c=sorted(map(int,input().split()));print(c-a)

Buggy submission (verdict: Runtime Error):
a, b, c = map(int, input().split())
k = max(a, b, c)
l = min(a, b, c)

print(int(k - l)
Problem p03337 (python)

Fixed submission:
a, b = map(int, input().split())
print(max(a+b,a-b,a*b))

Buggy submission (verdict: Runtime Error):
a, b = map(int, input().split())
c = a + b
d = a - b
e = a * b
print(max([c, d. e]))

Buggy submission (verdict: Runtime Error):
a, b = map(int, input().split())
c = a+b
d = a-b
e = a*b
print(max([c, d. e]))

Buggy submission (verdict: Runtime Error):
a, b = map(int, input().split())
c = a+b
d = a-b
e = a*b
print(max(c, d. e))
Problem p02927 (python)

Fixed submission:
M,D = list(map(int, input().strip().split()))
count = 0
for m in range(2,M+1):
    for d in range(11, D+1):
        if ((d%10) >= 2) and (int(d/10) >= 2) and (m == int(d/10) * (d%10)):
            count+=1
print(count)

Buggy submission (verdict: Runtime Error):
M,D = input().strip().split()
count = 0
for m in range(2,M+1):
    for d in range(22, D+1):
        if m = (d / 10) % 10 * (d % 10):
            count += 1
print(count)

Buggy submission (verdict: Runtime Error):
M,D = input().strip().split()
count = 0
for m in range(2,M+1):
    for d in range(22, D+1):
      if m = (d / 10) % 10 * (d % 10):
        count += 1
print(count)
Problem p02947 (python)

Fixed submission:
n = int(input())
ss = []
cnt = 0

# for _ in range(n):
#     ss.append(input())

# for i, s1 in enumerate(ss[0:n-2+1]):
#     for s2 in ss[i + 1:n-1+1]:
#         # print(s1, s2)
#         if sorted(s1) == sorted(s2):
#             cnt += 1

for _ in range(n):
    ss.append(input())

map = {}
for s in ss:
    sorted_s = ''.join(sorted(s))
    if sorted_s in map.keys():
        map[sorted_s] += 1
    else:
        map[sorted_s] = 1


# map = {'a': 1, 'b': 2, 'c': 3, 'd': 4}
# map = {'a': 10 ** 5}  # maxテスト
# print(map)

# あとはxC2の組み合わせの総数を求めれば良い


for n in map.values():
    if n > 1:
        # cnt += factorial(n) // (2 * factorial(n-2))
        cnt += (n * (n - 1)) // 2
    # print(n)
    # print(cnt)

print(cnt)

Buggy submission (verdict: Runtime Error):
n = int(input())
ss = []
cnt = 0

# for _ in range(n):
#     ss.append(input())

# for i, s1 in enumerate(ss[0:n-2+1]):
#     for s2 in ss[i + 1:n-1+1]:
#         # print(s1, s2)
#         if sorted(s1) == sorted(s2):
#             cnt += 1

for _ in range(n):
    ss.append(input())

map = {}
for s in ss:
    sorted_s = ''.join(sorted(s))
    if sorted_s in map.keys():
        map[sorted_s] += 1
    else:
        map[sorted_s] = 1


# map = {'a': 1, 'b': 2, 'c': 3, 'd': 4}

# print(map)


def factorial(n):
    if n > 0:
        return n * factorial(n-1)
    else:
        return 1

# あとはxC2の組み合わせの総数を求めれば良い


for n in map.values():
    if n > 1:
        cnt += factorial(n) // (2 * factorial(n-2))
    # print(n)
    # print(cnt)

print(cnt)

Buggy submission (verdict: Runtime Error):
n = int(input())
ss = []
cnt = 0

# for _ in range(n):
#     ss.append(input())

# for i, s1 in enumerate(ss[0:n-2+1]):
#     for s2 in ss[i + 1:n-1+1]:
#         # print(s1, s2)
#         if sorted(s1) == sorted(s2):
#             cnt += 1

for _ in range(n):
    ss.append(input())

map = {}
for s in ss:
    sorted_s = ''.join(sorted(s))
    if sorted_s in map.keys():
        map[sorted_s] += 1
    else:
        map[sorted_s] = 1

# print(map)

def factorial(n):
    x = 1
    if n > 0:
        x = n * factorial(n-1)
    return x

# あとはxC2の組み合わせの総数を求めれば良い

for n in map.values():
    if n == 1:
        continue
    cnt += factorial(n) // 2 * factorial(n-2)

print(cnt)
Problem p03125 (python)

Fixed submission:
a, b = map(int, input().split())
print(a + b if b % a == 0 else b - a)

Buggy submission (verdict: Runtime Error):
n, m = map(int, input().split(' '))
_, *intersection = map(int, input().split(' '))
intersection = set(intersection)
for _ in range(1, n):
    _, *newlist = map(int, input().split(' '))
    intersection = intersection & set(newlist)
print(len(intersection))
Problem p03206 (python)

Fixed submission:
d = int(input())
s = 'Christmas' + ' Eve' * (25 - d)
print(s)

Buggy submission (verdict: Runtime Error):
n = int(input())
price = [int(input()) for _ in range(n)]
print(int(sum(price) - max(price) / 2))
Problem p03292 (python)

Fixed submission:
a = list(map(int, input().split()))
print(max(a) - min(a))

Buggy submission (verdict: Runtime Error):
n, m = map(int, input().split())
a, b = [0] * m, [0] * m
for i in range(m):
    a[i], b[i] = map(int, input().split())
bridge = []
for i in range(m):
    bridge.append(list(range(a[i], b[i])))
cnt = 0

while True:
    cnt_passed = [0] * (n - 1)
    for bri in bridge:
        for j in bri:
            cnt_passed[j - 1] += 1
    removed = cnt_passed.index(max(cnt_passed)) + 1
    for bri in bridge[:]:
        if removed in bri:
            bridge.remove(bri)
    cnt += 1
    if len(bridge) == 0:
        print(cnt)
        exit(0)
Problem p03351 (python)

Fixed submission:
a, b, c, d = map(int, input().split())
print('Yes' if abs(a - c) <= d or (abs(a - b) <= d and abs(b - c) <= d) else 'No')

Buggy submission (verdict: Runtime Error):
from math import sqrt
n = int(input())
m = int(sqrt(n))
li = list(range(m + 1))
#0と1は考えない
for i in range(2, m + 1):
    while li[i] < n:
        li[i] *= i
    li[i] = int(li[i] / i)
print(max(li))
Problem p02927 (python)

Fixed submission:
M, D = input().split()
count = 0

for m in range(4, int(M)+1):
  for d in range(22, int(D)+1):
    d10 = int(str(d)[0])
    d1 = int(str(d)[1])
    if d10>=2 and d1>=2 and d10*d1==m:
      count+=1
      
print(count)

Buggy submission (verdict: Runtime Error):
a, b = input().strip()
print(a,b)
Problem p02927 (python)

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

cnt = 0
for m in range(1, M+1):
    for d in range(20, D+1):
        d1 = d % 10
        d10 = d // 10
        if (d1 < 2):
            continue
        if (d1 * d10 == m):
#            print(str(m)+'/'+str(d))
            cnt = cnt + 1

print(cnt)

Buggy submission (verdict: Runtime Error):
N, K = map(int, input().split())
A = list(input().split())

#for i in range(1,K+1):
#    B = B + A
#print(B)
# Tentousuu
cnt = 0
for i in range(0 , N*K):
    for j in range(i, N*K):
        if (A[(i%N)] > A[(j%N)]):
            cnt = cnt + 1
#print('t=' + str(cnt))
print(cnt%(10**9+7))