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

Fixed submission:
def main():
    N = int(input())
    G = [[] for _ in range(N)]
    for i in range(N):
        a = int(input())
        for j in range(a):
            x, y = (int(i) for i in input().split())
            G[i].append((x-1, y))
            # 人iは人xのことをyと言っている

    ans = 0
    for bit in range(1 << N):
        cur = 0
        good = True  # 矛盾がない
        for i in range(N):
            if bit & (1 << i):
                # 人iは正直者
                cur += 1
                for j, y in G[i]:
                    if (bit & (1 << j)) and y == 1:
                        continue
                    elif not(bit & (1 << j)) and y == 0:
                        continue
                    elif (bit & (1 << j)) and y == 0:
                        good = False
                        break
                    elif not(bit & (1 << j)) and y == 1:
                        good = False
                        break
            else:
                # 人iはうそつき
                for j, y in G[i]:
                    if (bit & (1 << j)) and y == 0:
                        continue
                    elif not(bit & (1 << j)) and y == 1:
                        continue
                    elif (bit & (1 << j)) and y == 0:
                        good = False
                        break
                    elif not(bit & (1 << j)) and y == 1:
                        good = False
                        break
        # print(bit, ":", good)
        if good:
            ans = max(ans, cur)
    print(ans)


if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
def main():
    N = int(input())
    A = [int(i) for i in input().split()]
    B = [int(i) for i in input().split()]
    ans = 0
    for i in range(N):
        if A[i] < B[i]:
            B[i] -= A[i]
            ans += A[i]
            if A[i+1] < B[i]:
                ans += A[i+1]
                A[i+1] = 0
            else:
                ans += B[i]
                A[i+1] -= B[i]
        else:
            ans += B[i]
    print(ans)


if __name__ == '__main__':
    main()
Problem p02856 (python)

Fixed submission:
def main():
    M = int(input())
    ans = 0
    dc = [[int(i) for i in input().split()] for _ in range(M)]
    dc_sum = 0
    for i in range(M):
        d = dc[i][0]
        c = dc[i][1]
        dc_sum += d*c
        ans += c
    if dc_sum % 9 == 0:
        print(ans - 1 + dc_sum//9 - 1)
    else:
        print(ans - 1 + dc_sum//9)


if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
def main():
    M = int(input())
    ans = 0
    dc = [[int(i) for i in input().split()] for _ in range(M)]
    s = "".join(str(d)*c for d, c in dc)
    if len(s) == 1:
        print(0)
    while len(s) > 2:
        s = str(int(s[0]) + int(s[0+1])) + s[0+2:]
        ans += 1
    while len(s) > 1:
        s = str(int(s[0]) + int(s[1]))
        ans += 1
    print(ans)


if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
def main():
    M = int(input())
    sum1 = 0
    sum2 = 0
    ans = 0
    dc = [[int(i) for i in input().split()] for _ in range(M)]
    s = "".join(str(d)*c for d, c in dc)
    if len(s) == 1:
        print(0)
    while len(s) != 1:
        s = str(int(s[0]) + int(s[0+1])) + s[0+2:]
        ans += 1
    print(ans)


if __name__ == '__main__':
    main()
Problem p02866 (python)

Fixed submission:
def main():
    MOD = 998244353
    N = int(input())
    D = [int(i) for i in input().split()]
    if D[0] != 0:
        return print(0)
    from collections import Counter
    c = Counter(D)
    ans = 1
    for d in D[1:]:
        if d == 0:
            return print(0)
        ans *= c[d-1]
        ans %= MOD
    print(ans % MOD)


if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
def main():
    MOD = 998244353
    N = int(input())
    D = [int(i) for i in input().split()]
    if D[0] != 0:
        return print(0)
    from collections import Counter
    from math import factorial
    c = Counter(D)
    ans = 1
    for k, v in c.items():
        if k == 0 or k == 1:
            continue
        elif v == 0:
            return print(0)
        else:
            n = v + c[k-1] - 1
            r = c[k-1] - 1
            ans *= factorial(n) / factorial(r) / factorial(n - r)
            ans = int(ans) % MOD
            if c[k-1] > v:
                ans *= (c[k-1] - v)
            ans = int(ans) % MOD
    print(ans % MOD)


if __name__ == '__main__':
    main()
Problem p02917 (python)

Fixed submission:
def main():
    n = int(input())
    b = [int(i) for i in input().split()]

    a = ([b[0]])
    for i in range(1,n-1):
        a.append(min(b[i-1],b[i]))
    a.append(b[-1])
    print(sum(a))
if __name__ == "__main__":
    main()

Buggy submission (verdict: Runtime Error):
def main():
    N = int(input())
    B = [int(i) for i in input().split()]
    A = [0] * N
    A[0] = B[0]
    for i in range(1,N-1):
        A[i] = min(B[i-1],B[i])
    A[N-1] = B[N-1]
    print(sum(A))

if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
def main():
    n = int(input())
    a = [int(i) for i in input().split()]
    b = [int(i) for i in input().split()]
    c = [int(i) for i in input().split()]
    ans = 0
    pre = -1
    for i in range(n):
        ans += b[a[i] - 1]
        if pre == a[i] - 1:
            ans += c[pre - 1]
        pre = a[i]
    print(ans)
if __name__ == "__main__":
    main()
Problem p02971 (python)

Fixed submission:

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

a_max = max(a)
b = a.copy()
b.remove(a_max)
a_max_second = max(b)

for a_i in a:
    if a_i != a_max:
        print(a_max)
    else:
        print(a_max_second)

Buggy submission (verdict: Runtime Error):

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

for a_i in a:
    b = a.copy()
    b.remove(a_i)
    print(max(b))
Problem p02972 (python)

Fixed submission:

n = int(input())
a = [0] + [int(i) for i in input().split()]
b = [0] * (n+1)

for i in range(1,n+1)[::-1]:
    mul_sum = sum((b[x] for x in range(i+i,n+1,i)))
    b[i] = (mul_sum%2) ^ a[i]

print(sum(b))
print(" ".join(str(i) for i in range(1,n+1) if b[i]))

Buggy submission (verdict: Runtime Error):

n = int(input())
a = [0] + [i for i in input().split()]
retval = [0] * (n+1)

for i in range(n,0,-1):
    p = sum([retval[x] for x in range(i+i,n+1,i)])
    retval[i] = (p%2) ^ a[i]

print(sum(retval))
print(i for i in range(1,n+1) if retval[i])
Problem p03000 (python)

Fixed submission:
n, x = (int(i) for i in input().split())
l = [0] + [int(i) for i in input().split()]

d = 0
ans = 0
i = 1
while d <= x:
    ans += 1
    if ans == n+1:
        break
    d = d + l[i]
    i += 1

print(ans)

Buggy submission (verdict: Runtime Error):
n, x = (int(i) for i in input().split())
l = [int(i) for i in input().split()]

d = 0
ans = 0
i = 0
while d <= x and i < n+1:
    ans += 1
    d = d + l[i]
    i += 1

print(ans)

Buggy submission (verdict: Runtime Error):
n, x = (int(i) for i in input().split())
l = [int(i) for i in input().split()]

d = 0
ans = 0
i = 0
while d <= x:
    ans += 1
    d = d + l[i]
    i += 1

print(ans)
Problem p03005 (python)

Fixed submission:
n, k = (int(i) for i in input().split())
print(n-k if k != 1 else 0)

Buggy submission (verdict: Runtime Error):
// #define _GLIBCXX_DEBUG
// #pragma GCC optimize("Ofast")
#pragma GCC diagnostic ignored "-Wsign-compare"
#include <bits/stdc++.h>
using namespace std;
using i64 = int_fast64_t;
#define rep(i, n) for (i64 i = 0; i < (i64)(n); ++i)
#define reps(i, s, n) for (i64 i = s; i < (i64)(n); ++i)

void solve() {
    int n, k;
    cin >> n >> k;
    int ans = (k != 1 ? n - k : 0);
    cout << ans << "\n";
}
int main() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    // cout << fixed << setprecision(15);
    solve();
}
Problem p03006 (python)

Fixed submission:
def main():
    N = int(input())
    A = [[int(i) for i in input().split()] for j in range(N)]
    if N == 1:
        return print(1)
    A.sort()
    from collections import defaultdict
    cnt = defaultdict(int)
    for i in range(N):
        for j in range(i+1, N):
            # print(A[i], A[j], (A[j][0] - A[i][0], A[j][1] - A[i][1]))
            cnt[(A[j][0] - A[i][0], A[j][1] - A[i][1])] += 1
    # print(cnt.values())
    ans = (N-1) - (sorted(cnt.values())[-1] - 1)
    print(ans)


if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
def main():
    import sys
    input = sys.stdin.buffer.readline
    N = int(input())
    XY = [[int(i) for i in input().split()] for j in range(N)]
    XY.sort()
    from collections import Counter
    c = Counter()
    for i in range(N-1):
        for j in range(i+1, N):
            p = XY[j][0] - XY[i][0]
            q = XY[j][1] - XY[i][1]
            c[(p, q)] += 1
    ans = N - c.most_common()[0][1]
    print(ans)


if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
def main():
    N = int(input())
    A = [[int(i) for i in input().split()] for j in range(N)]
    A.sort()
    from collections import defaultdict
    cnt = defaultdict(int)
    for i in range(N):
        for j in range(i+1, N):
            # print(A[i], A[j], (A[j][0] - A[i][0], A[j][1] - A[i][1]))
            cnt[(A[j][0] - A[i][0], A[j][1] - A[i][1])] += 1
    # print(cnt.values())
    ans = (N-1) - (sorted(cnt.values())[-1] - 1)
    print(ans)


if __name__ == '__main__':
    main()
Problem p03049 (python)

Fixed submission:
def main():
    N = int(input())
    ab_cnt = 0
    b_cnt = 0
    a_cnt = 0
    ans = 0
    for _ in range(N):
        S = input()
        ans += S.count("AB")
        if S[0] == "B" and S[-1] == "A":
            ab_cnt += 1
        elif S[0] == "B":
            b_cnt += 1
        elif S[-1] == "A":
            a_cnt += 1
    if ab_cnt > 1:
        ans += max(ab_cnt - 1, 0)
        ab_cnt = 1
    if a_cnt <= b_cnt:
        ans += a_cnt
        a_cnt = 0
        b_cnt -= a_cnt
    elif b_cnt < a_cnt:
        ans += b_cnt
        b_cnt = 0
        a_cnt -= b_cnt
    if ab_cnt > 0 and (a_cnt > 0 or b_cnt > 0):
        ans += 1
    print(ans)


if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
import math
n = int(input())
s = [input() for i in range(n)]

ans = 0
b_pre = []
a_suf = []
ab = []
for st in s:
    if st.startswith("B") and st.endswith("A"):
        ans += st.count("AB")
        ab.append(st)
    elif st.startswith("B"):
        ans += st.count("AB")
        b_pre.append(st)
    elif st.endswith("A"):
        ans += st.count("AB")
        a_suf.append(st)
    else:
        ans += st.count("AB")

if len(b_pre) - len(a_suf) > 1:
    while len(b_pre) - len(a_suf) > 1:
        for b in b_pre:
            if b.endswith("A"):
                a_suf.append(b)
                b_pre.remove(b)
            if len(b_pre) - len(a_suf) <= 1:
                break
elif len(a_suf) - len(b_pre) > 1:
    while len(a_suf) - len(b_pre) > 1:
        for a in a_suf:
            if b.startswith("B"):
                b_pre.append(b)
                a_suf.remove(b)
            if len(a_suf) - len(b_pre) > 1:
                break

ans += math.ceil(len(ab)/2)
if len(b_pre) < len(a_suf):
    ans += len(b_pre)
    ans += len(a_suf) - len(b_pre)
else:
    ans += len(a_suf)
    ans += len(b_pre) - len(a_suf)


print(ans)
Problem p03128 (python)

Fixed submission:
def main():
    import sys
    input = sys.stdin.buffer.readline
    N, M = (int(i) for i in input().split())
    A = [int(i) for i in input().split()]
    A.sort(reverse=True)
    dp = ["-"]*(N+10)
    dp[0] = ""
    match = {1: 2, 2: 5, 3: 5, 4: 4, 5: 5, 6: 6, 7: 3, 8: 7, 9: 6}
    for i in range(N+1):
        if dp[i] == "-":
            continue
        for a in A:
            cur = dp[i+match[a]]
            ne = dp[i] + str(a)
            if len(cur) < len(ne) or cur < ne:
                dp[i+match[a]] = ne
    # print(dp)
    print(dp[N])


if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
def main():
    import sys
    input = sys.stdin.buffer.readline
    N, M = (int(i) for i in input().split())
    A = [int(i) for i in input().split()]
    dp = [""]*(N+1)
    match = {1: 2, 2: 5, 3: 5, 4: 4, 5: 5, 6: 6, 7: 3, 8: 7, 9: 6}
    for i in range(2, N+1):
        cur = (int(dp[i]) if dp[i] else 0)
        for a in A:
            if match[a] == i or dp[i - match[a]]:
                ne = int(dp[i - match[a]] + str(a))
                if cur < ne:
                    dp[i] = str(ne)
                    cur = ne
    # print(dp)
    print(dp[N])


if __name__ == '__main__':
    main()
Problem p03164 (python)

Fixed submission:
def main():
    N, W_MAX = (int(i) for i in input().split())
    W = []
    V = []
    for _ in range(N):
        w, v = (int(i) for i in input().split())
        W.append(w)
        V.append(v)
    V_SUM = sum(V)
    INF = (1 << 60)
    dp = [INF] * (V_SUM + 1)
    dp[0] = 0
    for i in range(N):
        for j in range(V[i], V_SUM + 1)[::-1]:
            dp[j] = min(dp[j], dp[j - V[i]] + W[i])
    print(max(j for j in range(V_SUM+1) if dp[j] <= W_MAX))


if __name__ == '__main__':
    main()

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


def main():
    N, W = (int(i) for i in input().split())
    A = [[int(i) for i in input().split()] for j in range(N)]

    dp = [[INF]*(10**4+1) for _ in range(N+1)]
    dp[0][0] = 0
    for i in range(N):
        for j in range(10**4 + 1):
            dp[i+1][j] = min(dp[i+1][j], dp[i][j])
            if 0 <= j - A[i][1] and dp[i][j - A[i][1]] + A[i][0] <= W:
                dp[i+1][j] = min(dp[i+1][j], dp[i][j - A[i][1]] + A[i][0])
    ans = 0
    for j in range(10**4+1)[::-1]:
        if dp[N][j] <= W:
            ans = break
    print(ans)


if __name__ == '__main__':
    main()
Problem p03214 (python)

Fixed submission:
def main():
    N = int(input())
    A = [int(i) for i in input().split()]
    avg = sum(A)/N
    ans = 0
    mi = abs(A[0] - avg)
    for i, a in enumerate(A[1:], start=1):
        if abs(a - avg) < mi:
            ans = i
            mi = abs(a - avg)
    print(ans)


if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
def main():
    import numpy as np
    N = int(input())
    A = [int(i) for i in input().split()]
    avg = sum(A)/N
    ans = 0
    mi = abs(A[0] - avg)
    for i, a in enumerate(A[1:], start=1):
        if abs(a - avg) < mi:
            ans = i
            mi = abs(a - avg)
    print(ans)


if __name__ == '__main__':
    main()
Problem p03244 (python)

Fixed submission:
def main():
    n = int(input())
    v = [int(i) for i in input().split()]
    v_even = v[::2]
    v_odd = v[1::2]
    from collections import Counter
    v_even_cnt = sorted(list(Counter(v_even).items()),key=lambda x:x[1],reverse=True)
    v_odd_cnt = sorted(list(Counter(v_odd).items()),key=lambda x:x[1],reverse=True)
    ans = 0
    if v_even_cnt[0][0] != v_odd_cnt[0][0]:
        ans = len(v_even) - v_even_cnt[0][1] + len(v_odd) - v_odd_cnt[0][1]
    else:
        if len(v_even_cnt) == 1:
            ans = len(v_even)
        else:
            ans1 = len(v_even) - v_even_cnt[0][1] + len(v_odd) - v_odd_cnt[1][1]
            ans2 = len(v_even) - v_even_cnt[1][1] + len(v_odd) - v_odd_cnt[0][1]
            ans = min(ans1,ans2)
    print(ans)
if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
def main():
    n = int(input())
    v = [int(i) for i in input().split()]
    v_even = v[::2]
    v_odd = v[1::2]
    from collections import Counter
    v_even_cnt = sorted(list(Counter(v_even).items()),key=lambda x:x[1],reverse=True)
    v_odd_cnt = sorted(list(Counter(v_odd).items()),key=lambda x:x[1],reverse=True)
    ans = -1
    if v_even_cnt[0][0] != v_odd_cnt[0][0]:
        ans = len(v_even) - v_even_cnt[0][1] + len(v_odd) - v_odd_cnt[0][1]
    else:
        print(v_even_cnt,v_odd_cnt)
        if v_even_cnt[0][1] < v_odd_cnt[0][1]:
            if len(v_even_cnt) > 1:
                ans = len(v_even) - v_even_cnt[1][1] + len(v_odd) - v_odd_cnt[0][1]
            else:
                ans = len(v_even) - 0 + len(v_odd) - v_odd_cnt[0][1]
        elif v_even_cnt[0][1] > v_odd_cnt[0][1]:
            if len(v_odd_cnt) > 1:
                ans = len(v_even) - v_even_cnt[0][1] + len(v_odd) - v_odd_cnt[1][1]
            else:
                ans = len(v_even) - v_even_cnt[0][1] + len(v_odd) - 0
        else:
            if v_even_cnt[1][1] > v_odd_cnt[1][1]:
                ans = v_even_cnt[0][1] + v_odd_cnt[1][1]
            else:
                ans = v_even_cnt[1][1] + v_odd_cnt[0][1]
    print(ans)
if __name__ == '__main__':
    main()
Problem p03293 (python)

Fixed submission:
from collections import deque
sin = [i for i in input()]
tin = [i for i in input()]
s = deque(sin)
s_origin = deque(sin)
t = deque(tin)
s.rotate(1)
while s!=s_origin:
    if s == t or s_origin == t:
        print("Yes")
        break
    s.rotate(1)
else:
    if s_origin == t:
        print("Yes")
    else:
        print("No")

Buggy submission (verdict: Runtime Error):
from collections import deque
sin = [i for i in input()]
tin = [i for i in input()]
s = deque(sin)
s_origin = s.copy()
t = deque(tin)
s.rotate(1)
while s!=s_origin:
    if s == t or s_origin == t:
        print("Yes")
        break
    s.rotate(1)
else:
    print("No")

Buggy submission (verdict: Runtime Error):
from collections import deque
s = deque([i for i in input()])
s_origin = s.copy()
t = deque([i for i in input()])
s.rotate(1)
while s!=s_origin:
    if s == t or s_origin == t:
        print("Yes")
        break
    s.rotate(1)
else:
    print("No")

Buggy submission (verdict: Runtime Error):
from collections import deque
s = deque([i for i in input()])
s_origin = s.copy()
t = deque([i for i in input()])
s.rotate(1)
while s!=s_origin:
    if s == t or s_origin == t:
        print("Yes")
        break
    s.rotate(1)
else:
    print("No")
Problem p03328 (python)

Fixed submission:
a, b = (int(i) for i in input().split())
print(sum(range(b-a))-a)

Buggy submission (verdict: Runtime Error):
a, b = (int(i) for i input().split())
c = b - a
d = c*(c+1)//2
print(d - b)
Problem p03339 (python)

Fixed submission:
def main():
    N = int(input())
    S = input()
    from collections import Counter, defaultdict
    ri = defaultdict(int, dict(Counter(S)))
    le = defaultdict(int, {'W': 0, 'E': 0})
    pre = ''
    ans = 1 << 60
    for s in S:
        le[pre] += 1
        ri[s] -= 1
        ans = min(ans, le['W'] + ri['E'])
        pre = s
    print(ans)


if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
def main():
    N = int(input())
    S = input()
    from collections import Counter
    ri = dict(Counter(S))
    le = {'W': 0, 'E': 0}
    pre = ''
    ans = 1 << 60
    for s in S:
        if pre:
            le[pre] += 1
        ri[s] -= 1
        ans = min(ans, le['W'] + ri['E'])
        pre = s
    print(ans)


if __name__ == '__main__':
    main()
Problem p03386 (python)

Fixed submission:
a, b, k = (int(i) for i in input().split())
l = [i for i in range(a,b+1)] if b - a < 110 else [i for i in range(a,a+110)] + [i for i in range(b-110,b+1)]
for i in sorted(set(l[:k]) | set(l[-k:])):
    print(i)

Buggy submission (verdict: Runtime Error):
a, b, k = (int(i) for i in input().split())
l = list(range(a,b+1))
for i in sorted(set(l[:k]) | set(l[-k:])):
    print(i)
Problem p03457 (python)

Fixed submission:
def main():
    N = int(input())
    txy = [[0,0,0]] + [[int(i) for i in input().split()] for j in range(N)]
    for i in range(1,N+1):
        cur_distance = abs(txy[i][1] - txy[i-1][1]) + abs(txy[i][2] - txy[i-1][2])
        t_diff = txy[i][0] - txy[i-1][0]
        if t_diff < cur_distance or t_diff%2 != cur_distance%2:
            print("No")
            break
    else:
        print("Yes")
if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
def main():
    N = int(input())
    posi = [0, 0]
    time = 0
    flag = True
    for i in range(N):
        t, x, y = (int(i) for i in input().split())
        move = abs(posi[0] - x) + abs(posi[1] - y)
        if (t - time) >= move and (t - time) % move:
            flag = False
        time = t
        posi = [x, y]
    if flag:
        print("Yes")
    else:
        print("No")


if __name__ == '__main__':
    main()
Problem p03476 (python)

Fixed submission:
sieve = [True] * 100001
#one-based-index
def mark(sieve,x):
    for i in range(x+x,len(sieve),x):
        sieve[i] = False

for x in range(2,int(len(sieve) ** 0.5) + 1):
    if sieve[x]: mark(sieve,x)

sieve[0] = False
sieve[1] = False

for i in range(len(sieve)-2,2,-2):
    if sieve[i]:
        if not(sieve[(i+1)//2]):
            sieve[i] = False #2017likeでない

sieve[2] = False

cnt = [0] * 100002
for i,s in enumerate(sieve):
    if s:
        cnt[i] = cnt[i-1] + 1
    else:
        cnt[i] = cnt[i-1]

q = int(input())

for i in range(q):
    l, r = map(int,input().split())
    print(cnt[r] - cnt[l-1])

Buggy submission (verdict: Runtime Error):
def eratosthenes_2017like(x): #エラトステネスからちょっと変更
    prime = []
    if x < 3:
        return prime
    search = [i for i in range(2,x+1)]
    while search[0] <= math.sqrt(x):
        add = search.pop(0)
        prime.append(add)
        multiple = 1
        while add*multiple <= x:
            multiple += 1
            if add*multiple in search:
                search.remove(add*multiple)
    prime.extend(search)

    for p in prime[::-1]:
        if not((p+1)/2 in prime):
            prime.remove(p)
    return prime

for i in range(q):
    l, r = map(int,input().split())
    left_len = len(eratosthenes_2017like(l-1))
    right_len = len(eratosthenes_2017like(r))
    print(right_len - left_len)

Buggy submission (verdict: Runtime Error):
def eratosthenes_2017like(x):
    prime = []
    if x < 3:
        return prime
    search = [i for i in range(2,x+1)]
    while search[0] <= math.sqrt(x):
        add = search.pop(0)
        prime.append(add)
        multiple = 1
        while add*multiple <= x:
            multiple += 1
            try:
                search.remove(add*multiple)
            except ValueError:
                pass
    prime.extend(search)

    for p in prime[::-1]:
        if not((p+1)/2 in prime):
            prime.remove(p)
    return prime

for i in range(q):
    l, r = map(int,input().split())
    left_len = len(eratosthenes_2017like(l-1))
    right_len = len(eratosthenes_2017like(r))
    print(right_len - left_len)
Problem p03524 (python)

Fixed submission:
def main():
    S = input()
    N = len(S)
    a = S.count("a")
    b = S.count("b")
    c = S.count("c")
    ma = max(a, b, c)
    mi = min(a, b, c)
    if ma - mi > 1:
        print("NO")
    else:
        print("YES")


if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
def main():
    S = input()
    N = len(S)
    from collections import Counter
    c = Counter(S)
    # print(c.most_common())
    if N == 3 and c.most_common()[0][1] >= (N+1)//2:
        print("NO")
    elif c.most_common()[0][1] > (N+1)//2 or \
            (c.most_common()[0][1] >= (N+1)//2 and c.most_common()[1][1] >= (N+1)//2):
        print("NO")
    else:
        print("YES")


if __name__ == '__main__':
    main()