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

Fixed submission:
n=int(input())
l=list(map(int,input().split()))
l.sort()
ans=sum(l[0::2])
print(ans)

Buggy submission (verdict: Runtime Error):
def main():
    n,x=map(int,input().split())
    a,b=n-x,x
    if(a<b):
       a,b=b,a
    path_length = calc_path(a,b,n)
    print(path_length)

def  calc_path(a1,b1,c1):
    q , mod=divmod(a1,b1)
    count=0
    if mod==0:
         c2=c1+2*b1*q-b1
         return c2
    else:
        count=count+1
        c2=c1+2*b1*q
        a2=a1-b1*q
        b2=b1
        if(a2<b2):
           a2,b2=b2,a2
        return calc_path(a2,b2,c2)
if __name__=='__main__':
  main()

Buggy submission (verdict: Runtime Error):
def main():
    n,x=map(int,input().split())
    a,b=n-x,x
    if(a<b):
       a,b=b,a
    path_length = calc_path(a,b,n)
    print(path_length)

def  calc_path(a1,b1,c1):
    q , mod=divmod(a1,b1)
    count=0
    if mod==0:
         c2=c1+b1*(q+1)
         return c2
    else:
        count=count+1
        c2=c1+b1*(q+1)
        a2=a1-b1*q
        b2=b1
        if(a2<b2):
           a2,b2=b2,a2
        return calc_path(a2,b2,c2)
if __name__=='__main__':
  main()
Problem p02609 (python)

Fixed submission:
n = int(input())
x = input()
COUNT = x.count('1')
mod1 = COUNT - 1
mod2 = COUNT + 1

# その桁に1が立っていた時の余り
mod = [[0, 0] for _ in range(n+1)]
mult = 1
if mod1 != 0:
    mod[0][0] = 1 % mod1
mod[0][1] = 1 % mod2
for i in range(1, n+1):
    if mod1 != 0:
        mod[i][0] = (mod[i-1][0] * (2 % mod1)) % mod1
    mod[i][1] = (mod[i-1][1] * (2 % mod2)) % mod2

all_mod1 = 0
all_mod2 = 0
for i in range(n):
    if x[i] == '1':
        if mod1 != 0:
            all_mod1 = (all_mod1 + mod[n-1-i][0])
        all_mod2 = (all_mod2 + mod[n-1-i][1])
if mod1 != 0:
    all_mod1 %= mod1
all_mod2 %= mod2

def popcount(idx):
    idx -= 1
    ret = 0
    if x[idx] == '1':
        if mod1 != 0:
            ret = (all_mod1 - mod[n-1-idx][0]) % mod1
        else:
            ret = -1
    else:
        ret = (all_mod2 + mod[n-1-idx][1]) % mod2
    return ret

bit_cnt_table = [0 for _ in range(n+1)]
bit_cnt_table[1] = 1
base = 0
i = 2
while i <= n:
    if i % (2 ** base) == 0:
        base += 1
    bit_cnt_table[i] = 1 + bit_cnt_table[i - 2**(base)]
    i += 1

def func(num):
    if bit_cnt_table[num] == 0:
        return 0
    return num % bit_cnt_table[num]

f = [-1 for _ in range(n+1)]
f[0] = 0
f[1] = 1
for i in range(2, n+1):
    tmp = func(i)
    f[i] = 1 + f[tmp]
# print("all_mod", all_mod1, all_mod2)
ans = []
for i in range(1, n+1):
    p = popcount(i)
    if p == -1:
        ans_i = 0
    else:
        ans_i = 1 + f[p]
    # print(i, p, ans_i)
    ans.append(str(ans_i))
print("\n".join(ans))
# print(f)
# print(bit_cnt_table)

Buggy submission (verdict: Runtime Error):
n = int(input())
x = input()
COUNT = x.count('1')
mod1 = COUNT - 1
mod2 = COUNT + 1

# その桁に1が立っていた時の余り
mod = [[0, 0] for _ in range(n+1)]
mult = 1
mod[0][0] = 1 % mod1
mod[0][1] = 1 % mod2
for i in range(1, n+1):
    mod[i][0] = (mod[i-1][0] * (2 % mod1)) % mod1
    mod[i][1] = (mod[i-1][1] * (2 % mod2)) % mod2

all_mod1 = 0
all_mod2 = 0
for i in range(n):
    if x[i] == '1':
        all_mod1 = (all_mod1 + mod[n-1-i][0])
        all_mod2 = (all_mod2 + mod[n-1-i][1])
all_mod1 %= mod1
all_mod2 %= mod2

def popcount(idx):
    idx -= 1
    ret = 0
    if x[idx] == '1':
        ret = (all_mod1 - mod[n-1-idx][0]) % mod1
    else:
        ret = (all_mod2 + mod[n-1-idx][1]) % mod2
    return ret

bit_cnt_table = [0 for _ in range(n+1)]
bit_cnt_table[1] = 1
base = 0
i = 2
while i <= n:
    if i % (2 ** base) == 0:
        base += 1
    bit_cnt_table[i] = 1 + bit_cnt_table[i - 2**(base)]
    i += 1

def func(num):
    if bit_cnt_table[num] == 0:
        return 0
    return num % bit_cnt_table[num]

f = [-1 for _ in range(n+1)]
f[0] = 0
f[1] = 1
for i in range(2, n+1):
    tmp = func(i)
    f[i] = 1 + f[tmp]
# print("all_mod", all_mod1, all_mod2)
ans = []
for i in range(1, n+1):
    p = popcount(i)
    ans_i = 1 + f[p]
    # print(i, p, ans_i)
    ans.append(str(ans_i))
print("\n".join(ans))
# print(f)
# print(bit_cnt_table)
Problem p02697 (python)

Fixed submission:
n, m = map(int, input().split())

s1 = 1
f1 = n // 2
s2 = f1 + 1
f2 = n
if (f1 - s1) % 2 == (f2 - s2) % 2:
    f2 -= 1
ans = []
while f1 > s1:
    ans.append(f"{s1} {f1}")
    s1 += 1
    f1 -= 1

while f2 > s2:
    ans.append(f"{s2} {f2}")
    s2 += 1
    f2 -= 1

print("\n".join(ans[:m]))

Buggy submission (verdict: Runtime Error):
from collections import defaultdict
n, m = map(int, input().split())

s = 1
f = n
ans = []
d = defaultdict(lambda: False)
i = 0

used = []
while i < m:
    # print(s, f, i)
    tmp = abs(s - f)
    a, b = min(tmp, n - tmp), max(tmp, n - tmp)
    if d[a] or d[b]:
        f -= 1
        continue
    d[a] = True
    d[b] = True
    ans.append(f"{s} {f}")
    used.append(s)
    used.append(f)
    s += 1
    f -= 1
    i += 1
f = False
for i in used:
    if i <= 0 or n < i:
        f = True
if f:
    ans = []
    while i < m:
    # print(s, f, i)
    tmp = abs(s - f)
    a, b = min(tmp, n - tmp), max(tmp, n - tmp)
    if d[a] or d[b]:
        s += 1
        continue
    d[a] = True
    d[b] = True
    ans.append(f"{s} {f}")
    used.append(s)
    used.append(f)
    s += 1
    f -= 1
    i += 1

print("\n".join(ans))
Problem p02703 (python)

Fixed submission:
ic=lambda i,c:i+c*50
n,m,s=map(int,input().split())
edge=[[]for _ in range(125100)]
for _ in range(m):
  u,v,a,b=map(int,input().split())
  u-=1
  v-=1
  for i in range(a,2501):
    edge[ic(u,i)].append((ic(v,i-a),b))
    edge[ic(v,i)].append((ic(u,i-a),b))
for i in range(n):
  c,d=map(int,input().split())
  for j in range(c,2501):
    edge[ic(i,j-c)].append((ic(i,j),d))
from heapq import heappop,heappush
def dijkstra(s,n,edge):
  inf=10**20
  ans=[inf]*n
  ans[s]=0
  h=[[0,s]]
  while h:
    c,v=heappop(h)
    if ans[v]<c:continue
    for u,t in edge[v]:
      if c+t<ans[u]:
        ans[u]=c+t
        heappush(h,[c+t,u])
  return ans
d=dijkstra(ic(0,min(2500,s)),125100,edge)
ans=[0]+[10**20]*(n-1)
for i in range(1,n):
  for j in range(2501):ans[i]=min(ans[i],d[ic(i,j)])
print(*ans[1:])

Buggy submission (verdict: Runtime Error):
import sys
from collections import defaultdict
from heapq import heappush, heappop, heapify
input = sys.stdin.readline

INF = 10**12
n, m, s = map(int, input().split())
edges = defaultdict(lambda: defaultdict(lambda: [INF, INF]))
cd = []
max_a = 0

for i in range(m):
    u, v, a, b = map(int, input().split())
    max_a = max(max_a, a)
    edges[u-1][v-1] = [a, b]
    edges[v-1][u-1] = [a, b]

for i in range(n):
    c, d = map(int, input().split())
    cd.append([c, d])

# 解答ACする
# Dijakstraの状態を(頂点、所持している銀貨の枚数, cost)で持つ
# SIZE = max_a * n + 1
SIZE = 2550
if s > SIZE:
    s = SIZE
nodes = [[INF for _ in range(SIZE)] for _ in range(n)]
nodes[0][s-1] = 0

def dijakstra():
    goals = set({0})
    que = [(0, 0, s)]
    heapify(que)
    while len(que) > 0:
        # print(que[:3])
        cost, num, silver = heappop(que)
        if nodes[num][silver] < cost:
            continue
        # print(cost, num, silver)
        if num not in goals:
            goals.add(num)
        if len(goals) == n:
            break
        c, d = cd[num]
        for v in edges[num].keys():
            a, b = edges[num][v]
            times = -1
            to = silver - a
            while to < SIZE:
                times += 1
                plus = times * c
                to = silver + plus - a
                if to < 0:
                    continue
                if to >= SIZE:
                    break
                if nodes[v][to] > cost + b + d * times:
                    nodes[v][to] = cost + b + d * times
                    heappush(que, (cost + b + d * times, v, to))
dijakstra()
for i in range(1, n):
    print(min(nodes[i]))
Problem p02727 (python)

Fixed submission:
from collections import deque
x, y, a, b, c = map(int, input().split())
p = list(map(int, input().split()))
q = list(map(int, input().split()))
r = list(map(int, input().split()))

p.sort(reverse=True)
p = p[:x]
q.sort(reverse=True)
q = q[:y]
r.sort(reverse=True)
apples = p + q + r
apples.sort(reverse=True)
ans = sum(apples[:x+y])

print(ans)

Buggy submission (verdict: Runtime Error):
from collections import deque
x, y, a, b, c = map(int, input().split())
p = list(map(int, input().split()))
q = list(map(int, input().split()))
r = list(map(int, input().split()))

p.sort(reverse=True)
q.sort(reverse=True)
r.sort(reverse=True)

reds = deque(p)
greens = deque(q)
uncolor = deque(r)

# できるだけ値が大きいやつを使いたい
ans = 0
red_cnt = 0
green_cnt = 0
while True:
    # print(red_cnt, green_cnt, reds, greens, uncolor)
    if red_cnt == x and green_cnt == y:
        break
    if len(reds) == 0 or red_cnt == x:
        if greens[0] > uncolor[0]:
            eat = greens.popleft()
        else:
            eat = uncolor.popleft()
        ans += eat
        green_cnt += 1
    elif len(greens) == 0 or green_cnt == y:
        if reds[0] > uncolor[0]:
            eat = reds.popleft()
        else:
            eat = uncolor.popleft()
        ans += eat
        red_cnt += 1
    else:
        if red_cnt < x:
            if reds[0] > greens[0]:
                if reds[0] > uncolor[0]:
                    eat = reds.popleft()
                else:
                    eat = uncolor.popleft()
                ans += eat
                red_cnt += 1
            else:
                if greens[0] > uncolor[0]:
                    eat = greens.popleft()
                else:
                    eat = uncolor.popleft()
                ans += eat
                green_cnt += 1
        else:
            if greens[0] > uncolor[0]:
                eat = greens.popleft()
            else:
                eat = uncolor.popleft()
            ans += eat
            green_cnt += 1
print(ans)
Problem p02741 (python)

Fixed submission:
l = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14,
     1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]

k = int(input()) - 1
print(l[k])

Buggy submission (verdict: Runtime Error):
from math import ceil
h, w = map(int, input().split())

if h == 1 or w == 1:
    print(0)
    exit()
if w % 2 == 0:
    ans = (w // 2) * h
else:
    ans = (w // 2) * h + (ceil(h / 2))
print(ans)
Problem p02804 (python)

Fixed submission:
from math import factorial
MOD = 10**9 + 7

# 階乗を用意
fact = [1] * (10**5 + 1)
for i in range(1, 10**5 + 1):
    fact[i] = fact[i-1] * i
    fact[i] %= MOD

def comb(n, k, p):
    """power_funcを用いて(nCk) mod p を求める"""
    global fact
    if n < 0 or k < 0 or n < k:
        return 0
    if n == 0 or k == 0:
        return 1
    a = fact[n]
    b = fact[k]
    c = fact[n-k]
    return (a*power_func(b, p-2, p)*power_func(c, p-2, p)) % p

def power_func(a, b, p):
    """a^b mod p を求める"""
    if b == 0:
        return 1
    if b % 2 == 0:
        d = power_func(a, b//2, p)
        return d*d % p
    if b % 2 == 1:
        return (a*power_func(a, b-1, p)) % p

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

ans = 0

# pos
for i in range(n-1):
    c = comb(n-1-i, k-1, MOD)
    ans += a[n-1-i] * c
    ans %= MOD
    ans -= a[i] * c
    ans %= MOD
print(ans)

Buggy submission (verdict: Runtime Error):
from math import factorial
class Facts(max_num=10**5, p=10**9 + 7):
    def __init__(self):
        self.p = p
        self.max_num = max_num
        self.fact = [1] * (self.max_num + 1)
        for i in range(1, self.max_num + 1):
            self.fact[i] = self.fact[i-1] * i
            self.fact[i] %= self.p

    def comb(self, n, k):
        """ nCk mod p を求める """
        """ 計算量 O(log(p)) """
        """ n! / (n-k)! / k! mod p """
        """ フェルマーの小定理 a^(-1) ≡ a^(p-2) """
        """ n! * k!^(p-2) * (n-k)!^(p-2) mod p """
        if n < 0 or k < 0 or n < k:
            return 0
        if n == 0 or k == 0:
            return 1
        a = self.fact[n]
        b = self.fact[k]
        c = self.fact[n-k]
        return (a*self.power_func(b, self.p-2) *
                self.power_func(c, self.p-2)) % self.p

    def perm(self, n, k):
        """ nPk mod p を求める """
        """ 計算量 O(b - a)? """
        """ n! / (n-k)! mod p """
        """ n! * (n-k)!^(p-2) mod p """
        if n < 0 or k < 0 or n < k:
            return 0
        if n == 0 or k == 0:
            return 1
        a = self.fact[n]
        b = self.fact[n-k]
        return (a * self.power_func(b, self.p-2)) % self.p

    def power_func(self, a, b):
        """ a^b mod p　を繰り返し二乗法で求める """
        """ 計算量 O(log(b)) """
        if b == 0:
            return 1
        if b % 2 == 0:
            d = self.power_func(a, b//2)
            return d*d % self.p
        if b % 2 == 1:
            return (a*self.power_func(a, b-1)) % self.p

MOD = 10**9 + 7

fact = Facts()
n, k = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
ans = 0
# pos
for i in range(n-1):
    c = fact.comb(n-1-i, k-1)
    ans += a[n-1-i] * c
    ans %= MOD
    ans -= a[i] * c
    ans %= MOD
print(ans)
Problem p02843 (python)

Fixed submission:
x = int(input())
for c in range(1, x+1):
    if 100*c <= x <= 105*c:
        print(1)
        exit()
print(0)

Buggy submission (verdict: Runtime Error):
x = int(input())
def solve1(x):
    for c in range(1, x+1):
        if 100*c <= x <= 105*c:
            print(1)
            exit()
    print(0)

def solve2(x):
    dp = [0 for _ in range(x+1)]
    for i in range(100, 106):
        dp[i] = 1

    for i in range(100, x+1):
        for j in range(6):
            if dp[i-(100+j)]:
                dp[i] = 1
    print(dp[-1])

solve2(x)
Problem p02844 (python)

Fixed submission:
n = int(input())
s = input().rstrip()

def solve(n, s):
    # 全探索
    cnt = 0
    for v in range(0, 1000):
        v = str(v)
        v = "0" * (3 - len(v)) + v
        idx = 0
        for i in range(len(s)):
            if s[i] == v[idx]:
                idx += 1
            if idx == 3:
                cnt += 1
                break
    print(cnt)
solve(n, s)

Buggy submission (verdict: Runtime Error):
from copy import deepcopy
n = int(input())
s = input().rstrip()

def solve1(n, s):
    # 全探索
    cnt = 0
    for v in range(0, 1000):
        v = str(v)
        v = "0" * (3 - len(v)) + v
        idx = 0
        for i in range(len(s)):
            if s[i] == v[idx]:
                idx += 1
            if idx == 3:
                cnt += 1
                break
    print(cnt)

def solve2(n, s):
    # DP
    dp = [[[False for _ in range(1000)] for _ in range(4)] for _ in range(n+1)]
    dp[0][0][0] = True

    for i in range(n):
        for j in range(3):
            for k in range(100):
                if dp[i][j][k]:
                    num = k*10 + int(s[i])
                    dpp[i+1][j+1][num] = True
    cnt = 0
    for i in range(1000):
        if dp[n][3][i]:
            cnt += 1
    print(cnt)

solve2(n, s)

Buggy submission (verdict: Runtime Error):
from copy import deepcopy
n = int(input())
s = input().rstrip()

def solve1(n, s):
    # 全探索
    cnt = 0
    for v in range(0, 1000):
        v = str(v)
        v = "0" * (3 - len(v)) + v
        idx = 0
        for i in range(len(s)):
            if s[i] == v[idx]:
                idx += 1
            if idx == 3:
                cnt += 1
                break
    print(cnt)

def solve2(n, s):
    # DP
    dp = [[[False for _ in range(1000)] for _ in range(4)] for _ in range(n+1)]
    dp[0][0][0] = True

    for i in range(n):
        for j in range(3):
            for k in range(100):
                if dp[i][j][k]:
                    num = k*10 + int(s[i])
                    dpp[i+1][j+1][num] = True
    cnt = 0
    for i in range(1000):
        if dp[3][i]:
            cnt += 1
    print(cnt)

solve2(n, s)
Problem p02918 (python)

Fixed submission:
n, k = map(int, input().split())
s = str(input())

lr = 0
rl = 0
for i in range(1, n):
    if s[i-1] == "L" and s[i] == "R":
        lr += 1
    if s[i-1] == "R" and s[i] == "L":
        rl += 1
ans = n - (lr + rl + 1) + (2 * min(min(lr, rl), k))

if k > min(lr, rl):
    if lr > rl and (s[0] == "L" or s[-1] == "R"):
        ans += 1
    if lr < rl and (s[0] == "R" or s[-1] == "L"):
        ans += 1
print(ans)

Buggy submission (verdict: Runtime Error):
n, k = map(int, input().split())
s = str(input())
a = []
b = []

count = 1
for i in range(1, n):
    if s[i] == s[i-1]:
        count += 1
    else:
        if s[i-1] == "L":
            a.append(count)
        else:
            b.append(count)
        count = 1
if s[i] == "L":
    a.append(count)
else:
    b.append(count)
count = 1

a.sort(reverse=True)
b.sort(reverse=True)
ans1 = sum(a) - len(a)
ans2 = sum(b) - len(b)
for i in range(min(2*k, len(b))):
    ans1 += b[i]
if len(b) < 2*k:
    ans1 += 2*k - len(b)
ans1 = min(n-1, ans1)
for i in range(min(2*k, len(a))):
    ans2 += a[i]
if len(a) < 2*k:
    ans2 += 2*k - len(a)
ans2 = min(n-1, ans2)
print(max(ans1, ans2))
Problem p02929 (python)

Fixed submission:
N = int(input())
S = input()
ss = [1 if s == 'W' else 0 for s in S]

def mul(a, b):
    return (a * b) % (10**9 + 7)

ans = 1
num = 0
for s in ss:
    if num % 2 == s:
        num += 1
    else:
        ans = mul(ans, num)
        num -= 1

if num > 0:
    ans = 0

for i in range(2, N + 1):
    ans = mul(ans, i)

print(ans)

Buggy submission (verdict: Runtime Error):
MOD = 10**9+7

n = int(input())
s = input()

if s[0] == "W" or s[-1] == "W":
    print(0):
    exit()

kai = [1 for _ in range(n+1)]
for i in range(1, n+1):
    kai[i] = kai[i-1] * i
    kai[i] %= MOD

def mul(a, b):
    return (a * b) % MOD

a = "L"
l = ["L", "R"]
c = 0

for i in range(1, len(s)):
    if s[i] == s[i-1]:
        c = not c
    a = a + l[c]


ans = 1
num = 0
for i in range(len(s)):
    if a[i] == "L":
        num += 1
    else:
        ans *= num
        ans %= MOD
        num -= 1

ans *= kai[n]
ans %= MOD

print(ans)

Buggy submission (verdict: Runtime Error):
n = int(input())
s = str(input())
MOD = 10**9 + 7

if n % 2 == 1 and (s[0] == "W" or s[-1] == "W"):
    print(0)
    exit()

kai = [1 for _ in range(n+1)]
for i in range(1, n+1):
    kai[i] = (kai[i-1] * i) % MOD

ans = 1
count = 0
pre = s[0]
for i in range(1, 2*n):
    if s[i] == pre:
        count += 1
    else:
        ans *= kai[count+1]
        ans %= MOD
        count = 0
    pre = s[i]

ans *= kai[n]
ans %= MOD
print(ans)

Buggy submission (verdict: Runtime Error):
n = int(input())
s = str(input())
MOD = 10**9 + 7

if s[0] == "W" or s[-1] == "W":
    print(0)
    exit()

kai = [1 for _ in range(n+1)]
for i in range(1, n+1):
    kai[i] = (kai[i-1] * i) % MOD

ans = 1
count = 0
pre = ""
for i in range(2*n):
    if s[i] == pre:
        count += 1
    else:
        count += 1
        ans *= kai[count]
        ans %= MOD
        count = 0
    pre = s[i]
ans *= kai[n]
ans %= MOD
print(ans)
Problem p02947 (python)

Fixed submission:
import sys
from collections import defaultdict
def cmb(n, r):
    if n - r < r: r = n - r
    if r == 0: return 1
    if r == 1: return n

    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]

    for p in range(2,r+1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p-1,r,p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot

    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])

    return result


input = sys.stdin.readline

n = int(input())
d = defaultdict(lambda: 0)

for i in range(n):
    s = list(str(input()).rstrip())
    s.sort()
    s = "".join(s)
    d[s] += 1   

ans = 0
for key in d.keys():
    if d[key] >= 2:
        ans += cmb(d[key], 2)
print(int(ans))

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

input = sys.stdin.readline

n = int(input())
d = defaultdict(lambda: 0)

for i in range(n):
    s = list(str(input()).rstrip())
    s.sort()
    s = "".join(s)
    d[s] += 1   

ans = 0
for key in d.keys():
    if d[key] >= 2:
        ans += comb(d[key], 2, exact=True)
print(int(ans))

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

from math import factorial

def ncr(n, r):
    return factorial(n) / factorial(r) / factorial(n - r)

from collections import defaultdict

n = int(input())
d = defaultdict(lambda: 0)

for i in range(n):
    s = list(str(input()).rstrip())
    s.sort()
    s = "".join(s)
    d[s] += 1   

ans = 0
for key in d.keys():
    if d[key] >= 2:
        ans += ncr(d[key], 2)

print(int(ans))

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

from math import factorial

def ncr(n, r):
    return factorial(n) / factorial(r) / factorial(n - r)

from collections import defaultdict


n = int(input())
d = defaultdict(lambda: 0)

for i in range(n):
    s = list(str(input()).rstrip())
    s.sort()
    s = "".join(s)
    d[s] += 1   

ans = 0
for key in d.keys():
    if d[key] > 1:
        ans += ncr(d[key], 2)
print(d)
print(int(ans))

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

from math import factorial

def ncr(n, r):
    return factorial(n) / factorial(r) / factorial(n - r)

from collections import defaultdict


n = int(input())
d = defaultdict(lambda: 0)

for i in range(n):
    s = list(str(input()))
    s.sort()
    s = str(s)
    d[s] += 1   

ans = 0
for key in d.keys():
    if d[key] > 1:
        ans += ncr(d[key], 2)

print(int(ans))
Problem p02953 (python)

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

v = 1
flag = True
for i in range(n):
    if v < h[i]:
        v = h[i] - 1
    elif v == h[i]:
        pass
    else:
        flag = False
        break

if flag:
    print("Yes")
else:
    print("No")

Buggy submission (verdict: Runtime Error):
// template
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<long long, long long> LP;
#define INF 999999999
#define MOD 1000000007
#define REP(i, n) for(ll i = 0, i##_len = (n); i < i##_len; ++i)
#define REP_AB(i, a, b) for (ll i = ll(a); i <= ll(b); ++i)
#define ALL(v) v.begin(), v.end()
#define SORT(v) sort(ALL(v))
#define UNIQUE(v) sort(ALL(v));v.erase(unique(ALL(v)), v.end());
#define SIZE(x) ((ll)(x).size())
#define REVERSE(v) reverse(ALL(v))
// true / false
#define BIN_SEARCH(v, a) binary_search(ALL(v), a)
// index
#define BIN_LEFT(v, a) (lower_bound(ALL(v), a) - v.begin())
#define BIN_RIGHT(v, a) (upper_bound(ALL(v), a) - v.begin())
#define BIN_INSERT(v, a) (v.insert(v.begin() + BIN_LEFT(v, a), a))
#define DEL(v, i) v.erase(v.begin() + i)
#define INSERT(v, i, a) v.insert(v.begin() + i, a)
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return (a / gcd(a, b)) * b;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
#define out cout
#define in cin
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
// template end
 
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    ll N, max, f = 0;
    in >> N;
    vector<ll> H(N);
    REP(i,N){
        in >> H[i];
    }

    max = H[0];
    REP_AB(i,1,N-1){
        if(max < H[i]){
            max = H[i] - 1;
        }
        if(max > H[i]){
            f = 1;
            break;
        }
    }


    if(f == 0){
           out << "Yes" << endl;
    }else if(f == 1){
           out << "No" << endl;
    }


 

 

}
Problem p02969 (python)

Fixed submission:
r = int(input())

print(3 * r ** 2)

Buggy submission (verdict: Runtime Error):
import bisect
n = int(input())
a = int(input())

color = [a]
color_min = a

for i in range(1, n):
    a = int(input())
    if color_min >= a:
        bisect.insort_left(color, a)
        color_min = a
    else:
        j = bisect.bisect_left(color, a)
        color.pop(j-1)
        bisect.insort_left(color, a)
        color_min = color[0]

print(len(color))