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

Fixed submission:
from collections import Counter
N = int(input())
A = sorted(list(map(int, input().split())))
div = 10 ** 9 + 7
if N % 2 == 0:
    B = [i for i in range(1, N, 2)]
    B.extend(B)
    B.sort()
    if A == B:
        print(2**(int(N/2)) % div)
    else:
        print(0)

else:
    B = [i for i in range(2, N, 2)]
    B.extend(B)
    B.append(0)
    B.sort()
    if A == B:
        print(2**(int(N/2)) % div)
    else:
        print(0)

Buggy submission (verdict: Runtime Error):
from collections import Counter
N = int(input())
A = list(map(int, input().split()))
div = 10**9 + 7
if N % 2 == 0:
    if A.count(0) != 0:
        print(0)
    else:
        A = dict(Counter(A))
        val = A.values()
        val = list(filter(lambda x: x == 2, val))
        if len(val) * 2 == N:
            print(int(2**(N/2) % div))
        else:
            print(0)

else:
    if A.count(0) != 1:
        print(0)
    else:
        A.remove(0)
        A = dict(Counter(A))
        val = A.values()
        val = list(filter(lambda x: x == 2, val))
        if len(val) * 2 == (N-1):
            print(int(2 ** ((N-1) / 2) % div))
        else:
            print(0)

Buggy submission (verdict: Runtime Error):
from collections import Counter
N = int(input())
A = list(map(int, input().split()))
div = 10**9+7

if N % 2 == 0:
    A = dict(Counter(A))
    val = A.values()
    val = list(filter(lambda x: x == 2, val))
    if len(val) * 2 == N:
        print(int(2**(N/2) % div))
    else:
        print(0)

else:
    if A.count(0) != 1:
        print(0)
    else:
        A.remove(0)
        A = dict(Counter(A))
        val = A.values()
        val = list(filter(lambda x: x == 2, val))
        if len(val) * 2 == (N-1):
            print(int(2 ** ((N-1) / 2) % div))
        else:
            print(0)
Problem p03857 (python)

Fixed submission:
from collections import defaultdict
N, K, L = map(int, input().split())


class UnionFind:
    def __init__(self, n):
        self.par = [i for i in range(n)]
        self.rank = [0] * n
        self.size = [1] * n

    # 検索
    def find(self, x):
        if self.par[x] == x:
            return x
        else:
            self.par[x] = self.find(self.par[x])
            return self.par[x]

    # 併合
    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.rank[x] < self.rank[y]:
            self.par[x] = y
            self.size[y] += self.size[x]
            self.size[x] = 0
        else:
            self.par[y] = x
            self.size[x] += self.size[y]
            self.size[y] = 0
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1

    # 同じ集合に属するか判定
    def same_check(self, x, y):
        return self.find(x) == self.find(y)

    # すべての頂点に対して親を検索する
    def all_find(self):
        for n in range(len(self.par)):
            self.find(n)


UF1 = UnionFind(N)
UF2 = UnionFind(N)
for k in range(K):
    p, q = map(int, input().split())
    UF1.union(p-1, q-1)

for l in range(L):
    l, s = map(int, input().split())
    UF2.union(l-1, s-1)

UF1.all_find()
UF2.all_find()

D = defaultdict(int)
for i in range(N):
    D[UF1.par[i], UF2.par[i]] += 1

ans = [D[UF1.par[i], UF2.par[i]] for i in range(N)]
print(" ".join(map(str, ans)))

Buggy submission (verdict: Runtime Error):
v\from collections import defaultdict
N, K, L = map(int, input().split())


class UnionFind:
    def __init__(self, n):
        self.par = [i for i in range(n)]
        self.rank = [0] * n
        self.size = [1] * n

    # 検索
    def find(self, x):
        if self.par[x] == x:
            return x
        else:
            self.par[x] = self.find(self.par[x])
            return self.par[x]

    # 併合
    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.rank[x] < self.rank[y]:
            self.par[x] = y
            self.size[y] += self.size[x]
            self.size[x] = 0
        else:
            self.par[y] = x
            self.size[x] += self.size[y]
            self.size[y] = 0
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1

    # 同じ集合に属するか判定
    def same(self, x, y):
        return self.find(x) == self.find(y)

    # すべての頂点に対して親を検索する
    def all_find(self):
        for n in range(len(self.par)):
            self.find(n)


UF1 = UnionFind(N)
UF2 = UnionFind(N)

for k in range(K):
    p, q = map(int, input().split())
    p, q = p-1, q-1
    UF1.union(p, q)
for l in range(L):
    r, s = map(int, input().split())
    r, s = r-1, s-1
    UF2.union(r, s)

UF1.all_find()
UF2.all_find()

D = defaultdict(int)
for p1, p2 in zip(UF1.par, UF2.par):
    D[(p1, p2)] += 1

ans = [D[(p1, p2)] for p1, p2 in zip(UF1.par, UF2.par)]
print(*ans)
Problem p03921 (python)

Fixed submission:
import sys
sys.setrecursionlimit(10**7)

N, M = map(int, input().split())
P = [[] for i in range(N)]
L = [[] for i in range(M)]
for i in range(N):
    I = list(map(int, input().split()))
    for l in I[1:]:
        P[i].append(l-1)
        L[l-1].append(i)

P_visited = [0] * N
L_visited = [0] * M


# flgが立っていれば、人を見ているとする
def dfs(n, flg):
    if flg:
        P_visited[n] = 1
        for l in P[n]:
            if not L_visited[l]:
                dfs(l, flg ^ 1)
    else:
        L_visited[n] = 1
        for p in L[n]:
            if not P_visited[p]:
                dfs(p, flg ^ 1)


dfs(0, 1)
print("YES" if all(P_visited) else "NO")

Buggy submission (verdict: Runtime Error):
N, M = map(int, input().split())
P = [[] for i in range(N)]
L = [[] for i in range(M)]
for i in range(N):
    I = list(map(int, input().split()))
    for l in I[1:]:
        P[i].append(l-1)
        L[l-1].append(i)

P_visited = [0] * N
L_visited = [0] * M


# flgが立っていれば、人を見ているとする
def dfs(n, flg):
    if flg:
        P_visited[n] = 1
        for l in P[n]:
            if not L_visited[l]:
                dfs(l, flg ^ 1)
    else:
        L_visited[n] = 1
        for p in L[n]:
            if not P_visited[p]:
                dfs(p, flg ^ 1)


dfs(0, 1)
print("YES" if all(P_visited) else "NO")
Problem p03943 (python)

Fixed submission:
a, b, c = map(int, input().split())
if (a==b+c) or (b==c+a) or (c==a+b):
    print("Yes")
else:
    print("No")

Buggy submission (verdict: Runtime Error):
a, b, c = map((int, input().split()))
if (a==b+c) or (b==c+a) or (c==a+b):
    print("Yes")
else:
    print("No")
Problem p03964 (python)

Fixed submission:
N = int(input())
TA = [list(map(int, input().split())) for i in range(N)]
T, A = 1, 1

for t, a in TA:
    z = max(T//t, A//a)
    if (T > t*z) or (A > a*z):
        z += 1

    T = t * z
    A = a * z

print(T+A)

Buggy submission (verdict: Runtime Error):
from fractions import gcd
N = int(input())
TA = [list(map(int, input().split())) for i in range(N)]

ans = 0
pre_t = 0
pre_a = 0

for t, a in TA:
    gcd = gcd(t, a)

    t = t * gcd
    a = a * gcd

    first_t = t
    first_a = a

    while (pre_t > t) or(pre_a > a):
        t += first_t
        a += first_a

    pre_t = t
    pre_a = a
    
print(t + a)

Buggy submission (verdict: Runtime Error):
from fractions import _gcd
N = int(input())
TA = [list(map(int, input().split())) for i in range(N)]

ans = 0
pre_t = 0
pre_a = 0

for t, a in TA:
    gcd = _gcd(t, a)

    t = t * gcd
    a = a * gcd

    first_t = t
    first_a = a

    while (pre_t > t) or(pre_a > a):
        t += first_t
        a += first_a

    pre_t = t
    pre_a = a
    
print(t + a)
Problem p03994 (python)

Fixed submission:
S = input()
K = int(input())
cost = [(ord("z") - ord(s) + 1) % 26 for s in S]
A = [chr(ord("a") + i) for i in range(26)]

ans = ""
for i in range(len(S)-1):
    if cost[i] <= K:
        K -= cost[i]
        ans += "a"
    else:
        ans += S[i]

ans += A[(A.index(S[-1]) + K) % 26]
print(ans)

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


Costs = {chr(98 + i): (25 - i) for i in range(25)}
Costs['a'] = 0


ans = ""
for i in range(len(S) - 1):
    s = S[i]
    if K >= Costs[s]:
        K -= Costs[s]
        ans += 'a'
    else:
        ans += s

if K:
    tail = ans[-1]
    tail_ord = ord(tail)
    ans = ans[:-1] + chr((tail_ord + K) % 97 + 97)

print(ans)

Buggy submission (verdict: Runtime Error):
S = input()
K = int(input())
cost = [ord("z") - ord(s) + 1 for s in S]

ans = ""
for i in range(len(S)-1):
    if cost[i] <= K:
        K -= cost[i]
        ans += "a"
    else:
        ans += S[i]

ans = ans[:-1] + chr(ord(ans[-1]) + K % 26)
print(ans)

Buggy submission (verdict: Runtime Error):
S = input()
K = int(input())
cost = [ord("z") - ord(s) + 1 for s in S]

ans = ""
for i in range(len(S)):
    if cost[i] <= K:
        K -= cost[i]
        ans += "a"
    else:
        ans += S[i]

ans = ans[:-1] + chr(ord(ans[-1]) + K)
print(ans)
Problem p04013 (python)

Fixed submission:
N, A = map(int, input().split())
X = list(map(int, input().split()))
x_max = max(X)
Y = [x-A for x in X]

dp = [[0]*(2*N*x_max+1) for i in range(N+1)]
dp[0][N*x_max] = 1

for j in range(N+1):
    for t in range(2*N*x_max+1):
        if j >= 1 and 0 <= t - Y[j-1] <= 2*N*x_max:
            dp[j][t] = dp[j-1][t] + dp[j-1][t-Y[j-1]]
        elif j >= 1:
            dp[j][t] = dp[j-1][t]

print(dp[N][N*x_max]-1)

Buggy submission (verdict: Runtime Error):
N, A = map(int, input().split())
X = list(map(int, input().split()))
x_max = max(X)
dp = [[[0]*(N*x_max+1) for i in range(N+1)] for i in range(N+1)]
dp[0][0][0] = 1

for j in range(1, N+1):
    for k in range(N+1):
        for s in range(N*x_max+1):
            if X[j-1] <= s:
                dp[j][k][s] = dp[j-1][k][s] + dp[j-1][k-1][s-X[j-1]]
            else:
                dp[j][k][s] = dp[j-1][k][s]

ans = 0
for i in range(1, N+1):
    ans += dp[N][i][A*i]

print(ans)
Problem p04014 (python)

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

# コーナーケース
if N == S:
    print(N + 1)
    exit()


# x進数
def encode_x_base(n, x):
    ret = []
    while n:
        ret.append(n % x)
        n //= x
    return ret[::-1]


# 桁和
def digit_sum(n):
    if isinstance(n, (int, str)):
        return sum([int(d) for d in str(n)])
    if isinstance(n, list):
        return sum([int(d) for d in n])


# Bが小さいとき
for b in range(2, int(N ** 0.5) + 1):
    encoded_N = encode_x_base(N, b)
    d_sum = digit_sum(encoded_N)
    if d_sum == S:
        print(b)
        exit()

# Bが大きいときはpを全探索
for p in range(int(N ** 0.5) + 1, 0, -1):
    b = (N - S) // p + 1
    if b < 2:
        continue
    encoded_N = encode_x_base(N, b)
    d_sum = digit_sum(encoded_N)
    if d_sum == S:
        print(b)
        break
else:
    print(-1)

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

# コーナーケース
if N == S:
    print(N + 1)
    exit()


# x進数
def encode_x_base(n, x):
    ret = []
    while n:
        ret.append(n % x)
        n //= x
    return ret[::-1]


# 桁和
def digit_sum(n):
    if isinstance(n, (int, str)):
        return sum([int(d) for d in str(n)])
    if isinstance(n, list):
        return sum([int(d) for d in n])


# Bが小さいとき
for b in range(2, int(N ** 0.5) + 1):
    encoded_N = encode_x_base(N, b)
    d_sum = digit_sum(encoded_N)
    if d_sum == S:
        print(b)
        exit()

# Bが大きいときはpを全探索
for p in range(1, int(N ** 0.5) + 1):
    b = (N - S) // p + 1
    encoded_N = encode_x_base(N, b)
    d_sum = digit_sum(encoded_N)
    if d_sum == S:
        print(b)
        break
else:
    print(-1)
Problem p04047 (python)

Fixed submission:
N = int(input())
L = sorted(list(map(int, input().split())))
print(sum(L[::2]))

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

N, K = map(int, input().split())
T = [[] for i in range(N)]
E = []
for i in range(N-1):
    a, b = map(int, input().split())
    a, b = a-1, b-1
    T[a].append(b)
    T[b].append(a)
    E.append((a, b))


def bfs(n):
    visited = [False] * N
    dist = [0] * N
    queue = deque([n])
    while queue:
        node = queue.pop()
        if visited[node]:
            continue
        visited[node] = True
        for n in T[node]:
            if not visited[n]:
                dist[n] = dist[node] + 1
                queue.appendleft(n)
    return dist


dist = []
for i in range(N):
    dist.append(bfs(i))

ans = float('inf')
if K % 2 == 0:
    # 全ての頂点について全探索
    for i in range(N):
        ans = min(ans, len([d for d in dist[i] if d > K / 2]))
else:
    # 全ての辺について全探索
    for a, b in E:
        adist = [(1 if min(d1, d2) > (K-1) / 2 else 0) for d1, d2 in zip(dist[a], dist[b])]
        ans = min(ans, sum(adist))

print(ans)
Problem p02609 (python)

Fixed submission:
n = int(input())
x = list(input())
p_origin = x.count('1')

def bit_count(x):
    count = 0
    while x > 0:
        if x & 1:
            count += 1
        x = x >> 1
    return count


def get_ans(i):
    ans = 1
    if x[i] == '0':
        p_first = (sum_plus + p_plus[i]) % (p_origin+1)
    else:
        if p_origin-1 == 0:
            return 0
        p_first = (sum_minus - p_minus[i]) % (p_origin-1)
    while p_first != 0:
        p_first = p_first % bit_count(p_first)
        ans += 1
    return ans

p_minus = [0]*n # x%(p-1)
p_plus = [0]*n # x%(p+1)

t1 = 1
t2 = 1
for i in range(n):
    p_minus[n-1-i] = t1
    p_plus[n-1-i] = t2
    t1 *= 2
    t2 *= 2
    if p_origin == 1:
        t1 = 0
    else:
        t1 %= p_origin-1
    t2 %= p_origin+1

sum_plus = 0
sum_minus = 0
for i in range(n):
    if x[i] == '1':
        sum_plus += p_plus[i]
        sum_minus += p_minus[i]

for i in range(n):
    print(get_ans(i))

Buggy submission (verdict: Runtime Error):
n = int(input())
x = list(input())
p_origin = x.count('1')

def bit_count(x):
    count = 0
    while x > 0:
        if x & 1:
            count += 1
        x = x >> 1
    return count


def get_ans(i):
    ans = 1
    if x[i] == '0':
        p_first = (sum_plus + p_plus[i]) % (p_origin+1)
    else:
        p_first = (sum_minus - p_minus[i]) % (p_origin-1)
    while p_first != 0:
        p_first = p_first % bit_count(p_first)
        ans += 1
    return ans

p_minus = [0]*n # x%(p-1)
p_plus = [0]*n # x%(p+1)

t1 = 1
t2 = 1
for i in range(n):
    p_minus[n-1-i] = t1
    p_plus[n-1-i] = t2
    t1 *= 2
    t2 *= 2
    t1 %= p_origin-1
    t2 %= p_origin+1

sum_plus = 0
sum_minus = 0
for i in range(n):
    if x[i] == '1':
        sum_plus += p_plus[i]
        sum_minus += p_minus[i]

for i in range(n):
    print(get_ans(i))
Problem p02678 (python)

Fixed submission:
import queue

n, m = map(int, input().split())
maze = [[] for _ in range(n)]
for i in range(m):
    a, b = map(int, input().split())
    maze[a-1].append(b-1)
    maze[b-1].append(a-1)

ans = [-1 for _ in range(n)]
ans[0] = 0
q = queue.Queue()
q.put(0)
while not q.empty():
    start = q.get()
    for end in maze[start]:
        if ans[end] == -1:
            q.put(end)
            ans[end] = start

if -1 in ans[1:]:
    print('No')
else:
    print('Yes')
    for i in range(1,n):
        print(ans[i]+1)

Buggy submission (verdict: Runtime Error):
import queue

n, m = map(int, input().split())
maze = [[] for _ in range(m)]
for i in range(m):
    a, b = map(int, input().split())
    maze[a-1].append(b-1)
    maze[b-1].append(a-1)

ans = [-1 for _ in range(n)]
ans[0] = 0
q = queue.Queue()
q.put(0)
while not q.empty():
    start = q.get()
    for end in maze[start]:
        if ans[end] == -1:
            q.put(end)
            ans[end] = start

if -1 in ans[1:]:
    print('No')
else:
    print('Yes')
    for i in range(1,n):
        print(ans[i]+1)

Buggy submission (verdict: Runtime Error):
n, m = map(int, input().split())
maze = [[] for _ in range(m)]
for i in range(m):
    a, b = map(int, input().split())
    maze[a-1].append(b-1)
    maze[b-1].append(a-1)

ans = [-1 for _ in range(n)]
hand = [n+1 for _ in range(n)]
def get(counter, start, ans, hand):
    # counter: 手数
    # start: 出てきた部屋
    for end in maze[start]:
        if counter < hand[end] and end != 0:
            hand[end] = counter+1
            ans[end] = start
            get(counter+1, end, ans, hand)

get(0, 0, ans, hand)
if -1 in ans[1:]:
    print('No')
else:
    print('Yes')
    for i in range(1,n):
        print(ans[i]+1)
Problem p02814 (python)

Fixed submission:
import fractions
from functools import reduce

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

def lcm_base(x, y):
    return (x * y) // fractions.gcd(x, y)

def lcm(*numbers):
    return reduce(lcm_base, numbers, 1)

def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)

def count_factorize(n):
    counter = 0
    while n % 2 == 0:
        counter += 1
        n //= 2
    return counter

mod = count_factorize(a[0])
for i in range(1, n):
    if count_factorize(a[i]) != mod:
        print(0)
        exit()
lcm_a = lcm(*a)
print(m // (lcm_a//2) - m // lcm_a)

Buggy submission (verdict: Runtime Error):
import math
from functools import reduce

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

def lcm_base(x, y):
    return (x * y) // math.gcd(x, y)

def lcm(*numbers):
    return reduce(lcm_base, numbers, 1)

def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)

lcm_a = lcm(*a)
print(m // (lcm_a//2) - m // lcm_a)
Problem p02821 (python)

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

A.sort(reverse=True)
LB = A[-1] * 2  # 一回の握手で上がる幸福度の下限は、左手も右手もパワーが一番低い人を握った場合
UB = A[0] * 2   # 一回の握手で上がる幸福度の上限は、左手も右手もパワーが一番高い人を握った場合

# cgs[i] は パワーがi以上のゲストの数
cgs = [0] * (UB + 1)
for a in A:
    cgs[a] += 1
for i in range(UB, 0, -1):
    cgs[i - 1] += cgs[i]


# 組み合わせの数がM以上になる一回で発生する幸福度の閾値を二分探索する
def is_ok(n):
    m = 0
    for a in A:
        m += cgs[max(n - a, 0)]
    return m >= M


ok = LB
ng = UB + 1
while ng - ok > 1:
    m = (ok + ng) // 2
    if is_ok(m):
        ok = m
    else:
        ng = m

# cps[i] は A[0]～A[i] の累積和
cps = A[:]
for i in range(1, N):
    cps[i] += cps[i - 1]

result = 0
for a in A:
# 左手固定
    t = cgs[max(ok - a, 0)] # 握手すると閾値を超えるひとたち
    if t != 0:
        result += a * t + cps[t - 1] # 1人目pとu回握手 + 右手はu人までと握手
        M -= t
result += ok * M # 閾値上の人の処理
print(result)

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

a.sort(key=lambda x:-x)

# パワーがi以上の人の数
s = [0 for _ in range(2*a[0]+1)]
for p in a:
    s[p] += 1
for i in range(2*a[0], 0, -1):
    s[i-1] += s[i]

def is_over(x):
    num = 0
    for p in a:
        num += s[max(x-p, 0)]
    return num >= k

ub = 2*a[0]+1
lb = 2*a[-1]
while ub-lb > 1:
    x = (ub+lb)//2
    if is_over(x):
        lb = x
    else:
        ub = x

# a[0]からa[i]の累積和
t = a[:]
for i in range(1, n):
    t[i] += t[i-1]
ans = 0
for p in a:
    # 左手固定
    u = s[max(x-p, 0)] # 握手すると閾値を超えるひとたち
    if u != 0:
        ans += p*u+t[u-1] # 1人目pとu回握手 + 右手はu人までと握手
        k -= u
ans += lb*k # 閾値上の人の処理
print(ans)

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

a.sort(key=lambda x:-x)

# パワーがi以上の人の数
s = [0 for _ in range(2*a[0]+1)]
for p in a:
    s[p] += 1
for i in range(2*a[0], 0, -1):
    s[i-1] += s[i]

def is_over(x):
    num = 0
    for p in a:
        num += s[max(x-p, 0)]
    return num >= k

ub = 2*a[0]
lb = 2*a[-1]
while ub-lb > 1:
    x = (ub+lb)//2
    if is_over(x):
        lb = x
    else:
        ub = x

# a[0]からa[i]の累積和
t = a[:]
for i in range(1, n):
    t[i] += t[i-1]
ans = 0
for p in a:
    # 左手固定
    u = s[max(x-p, 0)] # 握手すると閾値を超えるひとたち
    if u != 0:
        ans += p*u+t[u-1] # 1人目pとu回握手 + 右手はu人までと握手
        k -= u
ans += lb*k # 閾値上の人の処理
print(ans)
Problem p02844 (python)

Fixed submission:
n = int(input())
s_list = list(input())

ans = 0
for i in range(1000):
    key = str(i).zfill(3)
    k = 0
    t = key[k]
    for s in s_list:
        if t == s:
            k += 1
            if k == 3:
                ans += 1
                break
            t = key[k]
print(ans)

Buggy submission (verdict: Runtime Error):
import collections

n = int(input())
s_list = list(input())

ans = 0
for i in range(1000):
    key = str(i).zfill(3)
    k = 0
    t = key[k]
    for s in s_list:
        if t == s[j]:
            k += 1
            if k == 3:
                ans += 1
                break
            t = key[k]
print(ans)
Problem p02888 (python)

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

# a, bをfixしてcを探索
# n*n*logn
# c_i < a+b をにぶたん
def binary_search(list, item):
    # listからitem未満の最大のindexを取得
    low = 0
    high = len(list) - 1
    if list[high] < item:
        return high+1
    if list[low] >= item:
        return low
    while True:
        mid = (low + high) //2
        guess = list[mid]
        if high - low <= 1:
            return high
        if guess >= item:
            high = mid
        else:
            low = mid

ans = 0
for i in range(n-2):
    for j in range(i+1, n-1):
        a = l[i]
        b = l[j]
        c = binary_search(l, b+a)
        ans += c-(j+1)
print(ans)

Buggy submission (verdict: Runtime Error):
        print(a,b,c,l[a]+l[b]>l[c])
Problem p02960 (python)

Fixed submission:
S = [int(x) if x != "?" else -1 for x in input()]
g = 10 ** 9 + 7
x = 1
DP = [[0] * 13 for _ in range(2)]
DP[0][0] = 1
for i in range(len(S)):
    for j in range(13):
        DP[1][j] = DP[0][j] % g
        DP[0][j] = 0
    for j in range(13):
        if S[i] == -1:
            s = (j*10)%13
            e = (s+10)%13
        else:
            s = (j*10+S[i])%13
            e = (s+1)%13
        DP[0][s] += DP[1][j]
        if s > e:
            DP[0][0] += DP[1][j]
        DP[0][e] -= DP[1][j]
    w = 0
    for j in range(13):
        w += DP[0][j]
        DP[0][j] = w

print(DP[0][5] % g)

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

dp = [[0 for _ in range(13)] for _ in range(len(s))]
multi = 1
for i in range(10):
    if s[0] == '?':
        dp[0][i] = 1
    else:
        dp[0][int(s[0])] = 1
for i in range(1,len(s)):
    if s[i] == '?':
        for j in range(13):
            if dp[i-1][j] != 0:
                for k in range(10):
                    rest = (j*10+k)%13
                    dp[i][rest] += dp[i-1][j]
    else:
        for j in range(13):
            if dp[i-1][j] != 0:
                rest = (j*10+int(s[i]))%13
                dp[i][rest] += dp[i-1][j]
print(dp[i][5]%(10**9+7))

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

dp = [[0 for _ in range(13)] for _ in range(len(s))]

for i in range(10):
    if s[0] == '?':
        dp[0][i] = 1
    else:
        dp[0][int(s[0])] = 1
for i in range(1,len(s)):
    if s[i] == '?':
        for j in range(13):
            for k in range(10):
                rest = (j*10+k)%13
                dp[i][rest] += dp[i-1][j]
    else:
        for j in range(13):
            rest = (j*10+int(s[i]))%13
            dp[i][rest] += dp[i-1][j]
print(dp[i][5]%(10**9+7))
Problem p02995 (python)

Fixed submission:
import fractions
a, b, c, d = map(int, input().split())
a = a-1
lcm = int(c*d/fractions.gcd(c, d))
ans = (b-b//c-b//d+b//lcm)-(a-a//c-a//d+a//lcm)
print(ans)

Buggy submission (verdict: Runtime Error):
import math
a, b, c, d = map(int, input().split())
lcm = int(c*d/math.gcd(c, d))
ans = (b-b//c-b//d+b//lcm)-(a-a//c-a//d+a//lcm)
print(ans)

Buggy submission (verdict: Runtime Error):
import math

a, b, c, d = map(int, input().split())
a = a-1
lcm = int(c*d/math.gcd(c, d))
print((b-b//c-b//d+b//lcm)-(a-a//c-a//d+a//lcm))

Buggy submission (verdict: Runtime Error):
import math

a, b, c, d = map(int, input().split())
lcm = int(c*d/math.gcd(c, d))
print((b-b//c-b//d+b//lcm)-(a-a//c-a//d+a//lcm))
Problem p03043 (python)

Fixed submission:
import math
n, k = map(int, input().split())
ans = 0
for i in range(n):
    a = max(math.ceil(math.log2(k/(i+1))), 0)
    ans += 0.5**a
print(ans/n)

Buggy submission (verdict: Runtime Error):
import math
n, k = map(int, input().split())
ans = 0
for i in range(n):
    a = max(math.ceil(math.log2(k/(i+1))), 0)
    ans += 1/(n*2**a)
print(ans)