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

Fixed submission:
import sys
input = sys.stdin.readline
N = int(input())
abc = [[0,0,0]]+[list(map(int,input().split())) for _ in range(N)]
dp = [[0,0,0] for _ in range(N+1)]

for i in range(1,N+1):
    for j in range(3):
        for k in range(3):
            if j == k:continue
            #print('i={},j={},k={}'.format(i,j,k))
            #print(dp[i][j],abc[i][j],abc[i-1][k])
            dp[i][j] = max(dp[i][j],abc[i][j]+dp[i-1][k])
print(max(dp[-1]))

Buggy submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline()
N = int(input())
abc = [[0,0,0]]+[list(map(int,input().split())) for _ in range(N)]
dp = [[0,0,0] for _ in range(N+1)]

for i in range(1,N+1):
    for j in range(3):
        for k in range(3):
            if j == k:continue
            #print('i={},j={},k={}'.format(i,j,k))
            #print(dp[i][j],abc[i][j],abc[i-1][k])
            dp[i][j] = max(dp[i][j],abc[i][j]+dp[i-1][k])
print(max(dp[-1]))
Problem p03163 (python)

Fixed submission:
import numpy as np
import sys
input = sys.stdin.readline
N,W = map(int,input().split())
dp = np.zeros(W+1,dtype=int)
for i in range(N):
    w,v = map(int,input().split())
    dp[w:] = np.maximum(dp[w:],dp[:-w]+v)
print(dp[-1])

Buggy submission (verdict: Runtime Error):
import numpy as np
import sys
input = sys.stdin.readline
N,W = map(int,input().split())
dp = np.zeros(W+1,dtype=int)
for i in range(N):
    w,v = map(int,input().split())
    dp[w:] = np.maximum(dp[w:],dp[:-w]+v)
print(dp[-1])
Problem p03244 (python)

Fixed submission:
from collections import Counter as c

N = int(input())
V = list(map(int,input().split()))
ev = c(V[::2]).most_common(2)
od = c(V[1::2]).most_common(2)

if ev[0][0] == od[0][0]:
    if len(ev) == 1 and len(od) == 1:
        print(N//2)
    else:
        print(N-max(ev[0][1]+od[1][1],ev[1][1]+od[0][1]))
else:
    print(N-ev[0][1]-od[0][1])

Buggy submission (verdict: Runtime Error):
from collections import Counter as c

e,o = 0,0
ans = 0
E,O = [],[]
for v,i in zip(V,range(N)):
    if i%2 == 0:
        E.append(v)
    else:
        O.append(v)
EC = c(E).most_common()
OC = c(O).most_common()
n = N//2

EC01=EC[0][1]

OC01=OC[0][1]

if len(EC) == 1:
    EC11 = 0
else:
    EC11=EC[1][1]
if len(OC) == 1:
    OC11 = 0
else:
    OC11=OC[1][1]
if len(EC) == 1 and len(OC) == 1 and EC[0][0]==OC[0][0]:
    ans = EC01
elif EC01+OC11 > EC11+OC01:
    ans += n - EC01
    ans += n - OC11
elif EC01+OC11 < EC11+OC01:
    ans += n - EC11
    ans += n - OC01
elif EC01 == OC01:
    ans = 0
print(ans)

Buggy submission (verdict: Runtime Error):
from collections import Counter as c

e,o = 0,0
ans = 0
E,O = [],[]
for v,i in zip(V,range(N)):
    if i%2 == 0:
        E.append(v)
    else:
        O.append(v)
EC = c(E).most_common()
OC = c(O).most_common()
n = N//2

EC01=EC[0][1]

OC01=OC[0][1]

if len(EC) == 1:
    EC11 = 0
else:
    EC11=EC[1][1]
if len(OC) == 1:
    OC11 = 0
else:
    OC11=OC[1][1]
if len(EC) == 1 and len(OC) == 1 and EC[0][0]==OC[0][0]:
    ans = EC01
elif EC01+OC11 > EC11+OC01:
    ans += n - EC01
    ans += n - OC11
elif EC01+OC11 < EC11+OC01:
    ans += n - EC11
    ans += n - OC01
elif EC01 == OC01:
    ans = 0
print(EC01,EC11,OC01,OC11)
print(ans)
Problem p03262 (python)

Fixed submission:
def gcd(a,b):
    if b == 0:
        return a
    else:
        return gcd(b,a%b)

N,A = map(int,input().split())
X = sorted(map(int,input().split()))
Y = []
for x in X:
    Y.append(abs(A-x))
ans = max(Y)
for y in Y:
    ans = gcd(y,ans)
print(ans)

Buggy submission (verdict: Runtime Error):
N,A = map(int,input().split())
X = sorted(map(int,input().split()))
Y = []
for x in X:
    Y.append(abs(A-x))
ans = Y[0]%Y[1]
for y in Y:
    for i in range(y-1,0,-1):
        if y%i == 0:
            ans = max(ans,i)
            break
print(ans)

Buggy submission (verdict: Runtime Error):
N,A = map(int,input().split())
X = sorted(map(int,input().split()))
Y = []
for x in X:
    Y.append(abs(A-x))
import math
minY = min(Y)
ans = 0
for i in range(len(Y)):
    ans = max(ans,math.gcd(minY,Y[i]))
print(ans)
Problem p03282 (python)

Fixed submission:
s = list(input())
k = int(input())-1
s = s[:k+1]
nums = ["2","3","4","5","6","7","8","9"]

ans_idx = k
for n in nums:
    if n not in s:
        continue
    cur_idx = s.index(n)
    ans_idx = min(ans_idx,cur_idx)

print(s[ans_idx])

Buggy submission (verdict: Runtime Error):
s = list(input())
k = int(input())
s = s[:k+1]
nums = ["2","3","4","5","6","7","8","9"]

ans_idx = k
for n in nums:
    if n not in s:
        continue
    cur_idx = s.index(n)
    ans_idx = min(ans_idx,cur_idx)
print(s[ans_idx])

Buggy submission (verdict: Runtime Error):
s = input()
t = input()

if int(s[0]) > 1:
    print(int(s[0]))
else:
    print(int(s[1]))
Problem p03287 (python)

Fixed submission:
from collections import Counter

n,m = map(int,input().split())
A = list(map(int,input().split()))

B = [0]
res = 0
for a in A:
	res += a
	B.append(res%m)

C = Counter(B)
ans = 0
for c in C.values():
	ans += c*(c-1)//2

print(ans)

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

n,m = map(int,input().split())
A = list(map(int,input().split()))
B = []
res = 0

for a in A:
    res += a
    B.append(res)
B = np.array(B)

ans = 0
for i in range(n):
    b = B[i:]
    # print(b)
    ans += np.count_nonzero(b%m == 0)
    B -= B[i]

print(ans)
Problem p03294 (python)

Fixed submission:
N = int(input())
A = list(map(int,input().split()))
print(sum(A)-N)

Buggy submission (verdict: Runtime Error):
N = int(input())
L = list(map(int,input().split()))
def mod(m):
    if m == 0:
        return 0
    ans = 0
    for l in L:
        ans += m%l
    return max(ans,mod(m-1))
print(mod(max(L)*2))
Problem p03341 (python)

Fixed submission:
input()
S = input()

def f():
    ans,total = 0,0
    for s in S:
        if s == 'W':
            total += 1
        elif total:
            total -= 1
            ans += 1
        else:
            pass
    return ans

print(f())

Buggy submission (verdict: Runtime Error):
def f(i):
    if i > len(S)-2:
        return 10**6
    ans = S[:i].count('W')+S[i+1:].count('E')
    return min(ans,f(i+1))

n=input()
S = input()+'_'

print(f(0))

Buggy submission (verdict: Runtime Error):
def f(i):
    if i > len(S)-2:
        return 10**6
    ans = S[:i].count('W')+S[i:].count('E')
    return min(ans,f(i+1))

input()
S = input()+'_'

print(f(0))
Problem p03379 (python)

Fixed submission:
from copy import deepcopy

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

Y = X.copy()
Y.sort()

for x in X:
    if x <= Y[N//2-1]:
        print(Y[N//2])
    else:
        print(Y[N//2-1])

Buggy submission (verdict: Runtime Error):
N = int(input())
X = list(map(int,input().split()))
Y = X.copy()
Y.sort()

for x in X:
    Y.remove(x)
    print(Y[N//2-1])
    Y.append(x)
    Y.sort()

Buggy submission (verdict: Runtime Error):
N = int(input())
X = list(map(int,input().split()))
Y = X.copy()
Y.sort()

for i in range(N):
    Y.remove(x)
    print(Y[N//2-1])
    Y.append(x)
    Y.sort()
Problem p03409 (python)

Fixed submission:
import sys
input = sys.stdin.readline
N = int(input())
AB = [list(map(int,input().split())) for _ in range(N)]
CD = [list(map(int,input().split())) for _ in range(N)]
AB.sort(reverse=1,key=lambda x:x[1])
CD.sort()
ans = 0
for c,d in CD:
    for a,b in AB:
        if a<c and b<d:
            ans+=1
            AB.remove([a,b])
            break
print(ans)

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

def abX():
    ans = 0
    for a,b in AB:
        for c,d in CD:
            if a<c and b<d:
                ans+=1
                CD.remove([c,d])
                break
    return ans

def abY():
    ans = 0
    for a,b in ab:
        for c,d in cd:
            if a<c and b<d:
                ans+=1
                cd.remove([c,d])
                break
    return ans

print(max(abX(),abY()))
Problem p03436 (python)

Fixed submission:
h,w = map(int,input().split())
S = [list(input()) for i in range(h)]
stack = [[0,0]]
S[0][0] = 0

total_dot = 0
for sss in S:
    for s in sss:
        if s == ".":
            total_dot += 1

move = [[0,1],[1,0],[-1,0],[0,-1]]
cnt = 1
while stack:
    cur_stack = stack
    stack = []
    for si,sj in cur_stack:
        for mi,mj in move:
            i,j = si+mi,sj+mj
            if 0 > i or i >= h or 0 > j or j >= w:
                continue
            next_mass = S[i][j]
            if next_mass == "#":
                continue
            elif next_mass == ".":
                S[i][j] = cnt
                stack.append([i,j])
    cnt += 1
# [print(s) for s in S]
print(total_dot-S[-1][-1]) if S[-1][-1] != "." else print(-1)

Buggy submission (verdict: Runtime Error):
h,w = map(int,input().split())
S = [list(input()) for i in range(h)]
stack = [[0,0]]
S[0][0] = 0

total_dot = 0
for sss in S:
    for s in sss:
        if s == ".":
            total_dot += 1

move = [[0,1],[1,0],[-1,0],[0,-1]]
cnt = 1
while stack:
    cur_stack = stack
    stack = []
    for si,sj in cur_stack:
        for mi,mj in move:
            i,j = si+mi,sj+mj
            if 0 > i or i >= h or 0 > j or j >= w:
                continue
            next_mass = S[i][j]
            if next_mass == "#":
                continue
            elif next_mass == ".":
                S[i][j] = cnt
                stack.append([i,j])
    cnt += 1
# [print(s) for s in S]
print(total_dot-S[-1][-1])
Problem p03471 (python)

Fixed submission:
N,Y = map(int,input().split())
flag = 0
for a in range(N+1):
    for b in range(N+1):
        if a+b > N:
            break
        elif (N-(a+b))*1000 == Y-(10000*a+5000*b):
            A,B,C = a,b,N-(a+b)
            flag = 1
if flag == 0:print(-1,-1,-1)
else:print(A,B,C)

Buggy submission (verdict: Runtime Error):
flag = 0
for a in range(0,N+1):
    if flag == 1:break
    for b in range(0,N+1):
        if flag == 1:break
        for c in range(0,N+1):
            if flag == 1:break
            if a+b+c == N and a*10000+b*5000+c*1000 == Y:
                print(a,b,c)
                flag = 1
                break
if flag == 0:
    print(-1,-1,-1)
Problem p03545 (python)

Fixed submission:
import itertools

a,b,c,d = input()
pm = ['+','-']
for pm1,pm2,pm3 in itertools.product(pm,repeat=3):
    ans = a+pm1+b+pm2+c+pm3+d
    if eval(ans) == 7:
        print(ans+'=7')
        break

Buggy submission (verdict: Runtime Error):
OP = ['+','-']
ans = 0
for op1 in OP:
    for op2 in OP:
        for op3 in OP:
            if eval(abc[0]+op1+abc[1]+op2+abc[2]+op3+abc[3]) == 7:
                ans = abc[0]+op1+abc[1]+op2+abc[2]+op3+abc[3]
print(ans+'=7')

Buggy submission (verdict: Runtime Error):
import sys
a,b,c,d = input()
pm = ['+','-']
for pm1 in PM:
    for pm2 in PM:
        for pm3 in PM:
            ans = a+pm1+b+pm2+c+pm3+d
            if eval(ans) == 7:
                print(ans+'=7')
                sys.exit()
Problem p03575 (python)

Fixed submission:
def f(L,res):
    for i in range(1,N+1):
        #print(i,L[i])
        if len(L[i]) == 1:
            L[L[i][0]].remove(i)
            L[i] = []
            res = f(L,res+1)
    return res


N,M = map(int,input().split())
L = [[] for _ in range(N+1)]

for i in range(M):
    a,b = map(int,input().split())
    L[a].append(b)
    L[b].append(a)
print(f(L,0))

Buggy submission (verdict: Runtime Error):
def f(L,res):
    for i in range(1,M+1):
        #print(i,L[i])
        if len(L[i]) == 1:
          L[L[i][0]].remove(i)
          L[i] = []
          res = f(L,res+1)
    return res


N,M = map(int,input().split())
L = [[] for _ in range(N+1)]

for i in range(M):
    a,b = map(int,input().split())
    L[a].append(b)
    L[b].append(a)
print(f(L,0))
Problem p03625 (python)

Fixed submission:
from collections import Counter

n = int(input())
a = list(map(int,input().split()))

ac = Counter(a)

cur_a = 0
res = 0
# print(ac)
for a,c in ac.items():
	# print(a,c)
	if c < 2:
		continue
	else:
		res = max(res,cur_a*a)
		cur_a = max(cur_a,a)
		if c >= 4:
			res = max(res,a*a)
	# print(cur_a,res)
print(res)

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

n = int(input())
a = list(map(int,input().split()))

ac = Counter(a)

cur_a = 0
cur_c = 0
res = 0
for a,c in ac.items():
	if c < 2:
		break
	if c >= 4:
		res = max(res,a*a)
	if cur_c == c
		res = max(res,cur_a*a)
		cur_a = max(cur_a,a)
	else:
		cur_a = a
		cur_c = c

print(res)
Problem p03633 (python)

Fixed submission:
def gcd(a,b):
	if b == 0:
		return a
	return gcd(b,a%b)

n = int(input())
T = [int(input()) for _ in range(n)]

ans = 1
for t in T:
	ans = ans*t//gcd(ans,t)
print(ans)

Buggy submission (verdict: Runtime Error):
def gcd(a,b,cur):
	if cur % a == 0 and cur % b == 0:
		return cur
	return gcd(a,b,cur+a)


n = int(input())
T = [int(input()) for _ in range(n)]

while len(T) != 1:
	if len(T)%2 == 1:
		T.append(1)
	new_T = []
	for i in range(0,len(T),2):
		t1,t2 = T[i],T[i+1]
		a = max(t1,t2)
		b = min(t1,t2)
		res = gcd(a,b,a)
		new_T.append(res)
	T = new_T
	# print(T)
print(*T)
Problem p02899 (python)

Fixed submission:
N = int(input())
A = list(map(int, input().split()))
ans = [0]*N

for i, a in enumerate(A):
    ans[int(a-1)] = str(i+1)
print(' '.join(map(str, ans)))

Buggy submission (verdict: Runtime Error):
for i in range(1, N+1):
    ans.append(A.index(i)+1)
print(' '.join(map(str, ans)))
Problem p02988 (python)

Fixed submission:
n = int(input())
a = list(map(int, input().split()))
cnt = 0
for i in range(n-2):
    b = sorted([a[i], a[i+1], a[i+2]])
    if b.index(a[i+1]) == 1:
        cnt += 1
print(cnt)

Buggy submission (verdict: Runtime Error):
n = int(input())
a = list(map(int, input().split()))
cnt = 0
for i in range(n-2):
    if a[i] < a[i+1] < a[i+2] or a[i+2] < a[i+1] < a[i]
        cnt += 1
print(cnt)
Problem p03478 (python)

Fixed submission:
nums = input().split()
N = int(nums[0])
A = int(nums[1])
B = int(nums[2])

n = 0
ans = 0
while n < N+1:
	n4 = n // 10**4
	n3 = n // 10**3 - n4 * 10
	n2 = n // 10**2 - n4 * 100 - n3 * 10
	n1 = n // 10 - n4 * 1000 - n3 * 100 - n2 * 10
	n0 = n % 10
	X = n4 + n3 + n2 + n1 + n0
	if X >= A and X <= B:     
		ans += n 
	n += 1

print(ans)

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

count = 0
A = 0
B = 0

while count < N+1 and len(a) >0: 
	m = max(a)
	A += m
	a.remove(m)  
	if len(a) > 0:
		m = max(a)
		B += m
		a.remove(m)
	count +=1

print(A - B)
Problem p02909 (python)

Fixed submission:
S=input()
if S=='Sunny':
    print('Cloudy')
elif S=='Cloudy':
    print('Rainy')
elif S=='Rainy':
    print('Sunny')

Buggy submission (verdict: Runtime Error):
S=input()
if S='Sunny':
    print('Cloudy')
elif S='Cloudy':
    print('Rainy')
elif S='Rainy':
    print('Sunny')
Problem p02934 (python)

Fixed submission:
N=int(input())
A = sorted(map(int, input().split( )))
b=0
for i in range(N):
    b+=1/A[i]
print(1/b)

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

for i in range(N):
    b+=1/a[i]
    
print(1/b)
Problem p02971 (python)

Fixed submission:
import numpy as np

n =	int(input())
nums = [int(input()) for i in range(n)]

num_max = np.max(nums)
next_max = sorted(nums)[-2]


for idx, el in enumerate(nums):
	if num_max == el:
		print(next_max)		
	else:
		print(num_max)

Buggy submission (verdict: Runtime Error):


n =	int(input())
nums = [int(input()) for i in range(n)]

num_max = max(nums)
next_max = num_max

for idx, el in enumerate(nums):
	del nums[idx]
	if num_max == el:
		if next_max == num_max
			next_max = max(nums)
			print(next_max)
		else:
			print(next_max)
		
	else:
		print(num_max)
	nums.insert(idx, el)
Problem p02848 (python)

Fixed submission:
a = list('ABCDEFGHIJKLMNOPQRSTUVWXYZ')
b = ''
e = int(input())

for c in list(input()):
  d = a.index(c)
  if d > 25 - e:
    d = d - (26)
    b += a[(d+e)]
  else:
    b += a[(d+e)]

print(b)

Buggy submission (verdict: Runtime Error):
a = list('ABCDEFGHIJKLMNOPQRSTUVWXYZ')
b = ''
e = int(input())

for c in list(input()):
  d = a.index(c)
  if d > 23:
    d = d - (23 + e + 1)
  b += a[(d+e)]

print(b)

Buggy submission (verdict: Runtime Error):
a = list('ABCDEFGHIJKLMNOPQRSTUVWXYZ')
b = ''

for c in list(input()):
  d = a.index(c)
  if d > 23:
    d = d - 26
  b += a[d+2]

print(b)
Problem p02848 (python)

Fixed submission:
N = int(input())
S = list(input())
res =[]
for s in S:
    if(ord(s) + N > 90):
        res.append(chr((ord(s)+N-26)))
    else:
        res.append(chr((ord(s)+N)))
print("".join(res))

Buggy submission (verdict: Runtime Error):
a, b, x = map(int, input().split())
 
def Calprice(n):
  return a * n + b * len(str(n))
 
min = 0
max = 10 ** 9 + 1
 
while max - min > 1:
  dev = (max + min) // 2
  if Calprice(dev) > x:
    max = dev
  else:
    min = dev

print(min)
Problem p03059 (python)

Fixed submission:
A, B, T = map(int, input().split())
print(int(T/A)*B)

Buggy submission (verdict: Runtime Error):
A, B, T = input().sprit()
print(int(T/A)*B)
Problem p03679 (python)

Fixed submission:
tmp = input().split(" ")
x=int(tmp[0])
a=int(tmp[1])
b=int(tmp[2])

if b-a <= 0:
  print("delicious")
elif b-a>x :
  print("dangerous")
else :
  print("safe")

Buggy submission (verdict: Runtime Error):
tmp = input().split(" ")
if tmp[2]-tmp[1] <= 0:
  print("delicious")
elif tmp[2]-tmp[1]>tmp[0] :
  print("dangerous")
else :
  print("safe")
Problem p03828 (python)

Fixed submission:
import math

n = int(input())

lim = n

# 素数判定関数
def isPrime(num):
    # 2未満の数字は素数ではない
    if num < 2: return False
    # 2は素数
    elif num == 2: return True
    # 偶数は素数ではない
    elif num % 2 == 0: return False

    # 3 ~ numまでループし、途中で割り切れる数があるか検索
    # 途中で割り切れる場合は素数ではない
    for i in range(3, math.floor(math.sqrt(num))+1, 2):
        if num % i == 0:
            return False

    # 素数
    return True

# 素数判定
def callIsPrime(input_num):
    numbers = []
    # ループしながら素数を検索する
    for i in range(1, input_num):
        if isPrime(i):
            numbers.append(i)

    # 素数配列を返す
    return numbers

# 関数の呼び出し
prime = callIsPrime(n+1)

arr = [0] * len(prime)

for i in range(len(prime)):
  j = 1
  while n >= prime[i] ** j :
    arr[i] += int(n / prime[i] ** j)
    j += 1
  
ans = 1
for i in arr :
  if i != 0:
    ans *= i+1

print(ans % (10 ** 9 + 7))

Buggy submission (verdict: Runtime Error):
import math

n = int(input())

lim = math.ceil(math.sqrt(n))

# 素数判定関数
def isPrime(num):
    # 2未満の数字は素数ではない
    if num < 2: return False
    # 2は素数
    elif num == 2: return True
    # 偶数は素数ではない
    elif num % 2 == 0: return False

    # 3 ~ numまでループし、途中で割り切れる数があるか検索
    # 途中で割り切れる場合は素数ではない
    for i in range(3, math.floor(math.sqrt(num))+1, 2):
        if num % i == 0:
            return False

    # 素数
    return True

# 素数判定
def callIsPrime(input_num):
    numbers = []
    # ループしながら素数を検索する
    for i in range(1, input_num):
        if isPrime(i):
            numbers.append(i)

    # 素数配列を返す
    return numbers

# 関数の呼び出し
prime = callIsPrime(n)

arr = [0] * lim

for i in range(len(prime)):
  j = 1
  while n > prime[i] ** j :
    arr[i] += int(n / prime[i] ** j)
    j += 1
  
ans = 1
for i in arr :
  if i != 0:
    ans *= i+1

print(ans)
Problem p02945 (python)

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

x1=A+B
x2=A-B
x3=A*B

print(max(x1,max(x2,x3)))

Buggy submission (verdict: Runtime Error):
def encode(s):
#  r = [0]*26
#  for n in range(len(s)):
#    r[ord(s[n]) - ord('a')] += 1
#  return r
#  r = list(s)
#  r.sort()
#  return r
  r = 0
  for n in range(len(s)):
    so = ord(s[n]) - ord('a')
    r += 11**so
  return r

N = int(input())

S = []

for n in range(N):
  s = str(input())
  S = S + [encode(s)]

S.sort()
print('a')
ct = 0
M=1
ps=""
for cs in S:
  if cs==ps:
    M+=1
  else:
    ct += int((M**2-M)/2)
    M=1
    ps=cs
ct += int((M**2-M)/2)

print(ct)

Buggy submission (verdict: Runtime Error):
def encode(s):
#  r = [0]*26
#  for n in range(len(s)):
#    r[ord(s[n]) - ord('a')] += 1
#  return r
#  r = list(s)
#  r.sort()
#  return r
  r = 0
  for n in range(len(s)):
    so = ord(s[n]) - ord('a')
    r += 11**so
  return r

N = int(input())

S = []

for n in range(N):
  s = str(input())
  S = S + [encode(s)]

S.sort()
ptint('a')
ct = 0
M=1
ps=""
for cs in S:
  if cs==ps:
    M+=1
  else:
    ct += int((M**2-M)/2)
    M=1
    ps=cs
ct += int((M**2-M)/2)

print(ct)
Problem p02947 (python)

Fixed submission:
def encode(s):
#  r = [0]*26
#  for n in range(len(s)):
#    r[ord(s[n]) - ord('a')] += 1
#  return r
#  r = list(s)
#  r.sort()
#  return r
  r = 0
  for n in range(len(s)):
    so = ord(s[n]) - ord('a')
    r += 11**so
  return r

N = int(input())

S = [0]*N

for n in range(N):
  s = str(input())
  S[n] = encode(s)

S.sort()

ct = 0
M=1
ps=""
for cs in S:
  if cs==ps:
    M+=1
  else:
    ct += int((M**2-M)/2)
    M=1
    ps=cs
ct += int((M**2-M)/2)

print(ct)

Buggy submission (verdict: Runtime Error):
def encode(s):
#  r = [0]*26
#  for n in range(len(s)):
#    r[ord(s[n]) - ord('a')] += 1
#  return r
#  r = list(s)
#  r.sort()
#  return r
  r = 0
  for n in range(len(s)):
    so = ord(s[n]) - ord('a')
    r += 11**so
  return r

N = int(input())

S = []

for n in range(N):
  s = str(input())
  S = S + [encode(s)]

S.sort()
ptint('a')
ct = 0
M=1
ps=""
for cs in S:
  if cs==ps:
    M+=1
  else:
    ct += int((M**2-M)/2)
    M=1
    ps=cs
ct += int((M**2-M)/2)

print(ct)

Buggy submission (verdict: Runtime Error):
def encode(s):
#  r = [0]*26
#  for n in range(len(s)):
#    r[ord(s[n]) - ord('a')] += 1
#  return r
#  r = list(s)
#  r.sort()
#  return r
  r = 0
  for n in range(len(s)):
    so = ord(s[n]) - ord('a')
    r += 11**so
  return r

N = int(input())

S = []

for n in range(N):
  s = str(input())
  S = S + [encode(s)]

S.sort()
ptint('a')
ct = 0
M=1
ps=""
for cs in S:
  if cs==ps:
    M+=1
  else:
    ct += int((M**2-M)/2)
    M=1
    ps=cs
ct += int((M**2-M)/2)

print(ct)
Problem p03029 (python)

Fixed submission:
A,P = map(int,input().split())
 
N = A*3+P
M = int(N/2)
 
print(M)

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

N = A*3+P
M = int(N/2)

print(M)
Problem p03030 (python)

Fixed submission:
import collections as cl

N=int(input())

L = []

for i in range(N):
  S,P_ = input().split()
  P = int(P_)
  
  flg = False
  for j in range(len(L)):
    if L[j][0]>S or (L[j][0]==S and L[j][1]<P):
      L.insert(j,(S,P,i))
      flg = True
      break
  if flg==False:
    L.append((S,P,i))
        
#I = [0]*N
for i in range(N):
  print(L[i][2]+1)
#  I[L[i][2]] = i+1

Buggy submission (verdict: Runtime Error):
import collections as cl

N=int(input())

L = cl.deque()

for i in range(N):
  S,P_ = input().split()
  P = int(P_)
  
  flg = False
  for j in range(len(L)):
    if L[j][0]>S or (L[j][0]==S and L[j][1]>P):
      L.insert(j,(S,P,i))
      flg = True
  if flg==False:
    L.append(j,(S,P,i))
    
I = [0]*N
for i in range(N):
  I[L[i][2]] = i+1

for i in range(N):
  print(I[i])
Problem p03049 (python)

Fixed submission:
def countAB(S):
  ct=0
  flg = True
  pos=0
  while flg:
    idx = S.find('AB',pos)
    if idx!=-1:
      ct+=1
    else:
      flg = False
    pos = idx + 2
  return ct
 
N = int(input())
 
num_AB = 0
num_A = 0
num_B = 0
num_BA = 0
for n in range(N):
  S = input()
  num_AB += countAB(S)
  if S[len(S)-1]=='A':
    num_A += 1
  if S[0]=='B':
    num_B += 1
  if S[len(S)-1]=='A' and S[0]=='B': 
    num_BA += 1
    
num_AB_cmb = min(num_A,num_B)
if num_A == num_BA and num_B == num_BA and num_BA!=0:
  num_AB_cmb = num_BA-1
 
print("{0}".format(num_AB + num_AB_cmb))

Buggy submission (verdict: Runtime Error):
def countAB(S):
  ct=0
  flg = True
  pos=0
  while flg:
    idx = S.find('AB',pos)
    if idx!=-1:
      ct+=1
    else:
      flg = False
    pos = idx + 2
  return ct

N = int(input())

num_AB = 0
num_A = 0
for n in range(N):
  S = input()
  num_AB += countAB(S)
  if S[len(S)-1]=='A':
    num_A += 1
  if S[0]=='B':
    num_B += 1

num_AB_cmb = min(num_A,num_B)
if num_A == N and num_B == N:
  num_AB_cmb = N-1

print("{0}".format(num_AB + num_AB_cmb))
Problem p03455 (python)

Fixed submission:
a,b = map(int,input().split())
if a * b % 2 == 0:
    print("Even")
else:
    print("Odd")

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