Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
ni = lambda: int(input())
nm = lambda: map(int, input().split())
nl = lambda: list(map(int, input().split()))

n = ni()
b = nl()



ans = []

for i in range(n):
    for j in range(b):
        if b[j] == j+1:
            ans.append(b[j])
            del b[j]
            continue
        print(-1)
        exit()

print(' '.join(reversed(ans)))




Fixed submission:
ni = lambda: int(input())
nm = lambda: map(int, input().split())
nl = lambda: list(map(int, input().split()))

n = ni()
b = nl()

ans = []

for i in range(n):
    for j in range(len(b))[::-1]:
        if b[j] == j + 1:
            ans.append(b[j])
            del b[j]
            break
        if j == 0:
            print(-1)
            exit()

print(' '.join([str(_) for _ in reversed(ans)]))
Buggy python submission (verdict: Runtime Error):
s = int(input())

log = set()
set.add(s)
for i in range(1001000):
    if s%2==0:
        s //=2
    else:
        s = 3*s+1

    if s in log:
        print(i+2)
        break

    log.add(s)

Fixed submission:
s = int(input())

log = set()
log.add(s)
for i in range(1001000):
    if s%2==0:
        s //=2
    else:
        s = 3*s+1

    if s in log:
        print(i+2)
        break

    log.add(s)
Buggy python submission (verdict: Runtime Error):
import sys

n = int(input())
sys.setrecursionlimit(10**10)



def count(num):
    if num > n:
        return 0
    fl = 0
    s = str(num)
    if '3' in s and '5' in s and '7' in s:
        fl = 1

    return fl + count(num*10+3) + count(num*10+5) + count(num*10+7)


print(count(0))

Fixed submission:
import sys

n = int(input())
sys.setrecursionlimit(2*10**9+1)


def count(num):
    if num > n:
        return 0
    fl = 0
    s = str(num)
    if '3' in s and '5' in s and '7' in s:
        fl = 1

    return fl + count(num*10+3) + count(num*10+5) + count(num*10+7)


print(count(0))

Buggy python submission (verdict: Runtime Error):
import sys

n = int(input())
sys.setrecursionlimit(n)



def count(num):
    if num > n:
        return 0
    fl = 0
    s = str(num)
    if '3' in s and '5' in s and '7' in s:
        fl = 1

    return fl + count(num*10+3) + count(num*10+5) + count(num*10+7)


print(count(0))

Fixed submission:
import sys

n = int(input())
sys.setrecursionlimit(2*10**9+1)


def count(num):
    if num > n:
        return 0
    fl = 0
    s = str(num)
    if '3' in s and '5' in s and '7' in s:
        fl = 1

    return fl + count(num*10+3) + count(num*10+5) + count(num*10+7)


print(count(0))
Buggy python submission (verdict: Time Limit Exceeded):
from collections import Counter

n = int(input())

v = list(map(int, input().split()))

odds = []
evens = []

for i in range(n):
    if i % 2 == 0:
        evens.append(v[i])
    else:
        odds.append(v[i])

evens_c = Counter(evens).most_common()
odds_c = Counter(odds).most_common()

ans = n

fl = 0
for i in range(len(evens_c)):
    for j in range(len(odds_c)):
        try:
            if evens_c[i][0] != odds_c[j][0]:
                ans = min(ans, n - evens_c[i][1] - odds_c[j][1])
                fl = 1
        except:
            continue

if fl == 1:
    print(ans)
    exit()
print(n // 2)


Fixed submission:
from collections import Counter

n = int(input())

v = list(map(int, input().split()))

odds = []
evens = []

for i in range(n):
    if i % 2 == 0:
        evens.append(v[i])
    else:
        odds.append(v[i])

evens_c = Counter(evens).most_common(2)
odds_c = Counter(odds).most_common(2)

if evens_c[0][0] != odds_c[0][0]:
    print(n - evens_c[0][1] - odds_c[0][1])
    exit()

if len(evens_c) == 1 or len(odds_c) == 1:
    print(n // 2)
    exit()

print(n - max(evens_c[0][1] + odds_c[1][1], evens_c[1][1] + odds_c[0][1]))
Buggy python submission (verdict: Runtime Error):
ni = lambda: int(input())
nl = lambda: list(map(int, input().split()))
nm = lambda: map(int, input().split())

n, m, x, y = nm()
xmax = max(nl())+[x]
ymin = min(nl())+[y]

if xmax < ymin:
    print('No War')
else:
    print('War')


Fixed submission:
ni = lambda: int(input())
nl = lambda: list(map(int, input().split()))
nm = lambda: map(int, input().split())

n, m, x, y = nm()
xmax = max(nl()+[x])
ymin = min(nl()+[y])

if xmax < ymin:
    print('No War')
else:
    print('War')
Buggy python submission (verdict: Runtime Error):
a,b,c=map(int,input.split())
if a+b=>c:
  print('Yes')
else:
  print('No')

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

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

Fixed submission:
a,b,c=map(int,input().split())
if a+b>=c:
  print('Yes')
else:
  print('No')
Buggy python submission (verdict: Runtime Error):
n = int(input())

s = set()
for i in range(n):
  s.add(int(input())

print(min(3,len(s)))

Fixed submission:
n = int(input())
 
s = set()
for i in range(n):
  s.add(int(input()))
 
print(len(s))
Buggy python submission (verdict: Time Limit Exceeded):
import sys
N, M = map(int, input().split())
REL = [set() for _ in range(N)]
for _ in range(M):
    a, b = map(int, sys.stdin.readline().split())
    REL[a-1].add(b-1)
    REL[b-1].add(a-1)

ans = 0
todo = []
done = set()
for s in range(N):
    if s in done:
        continue
    pdone = set()
    todo.append(s)
    while todo:
        p = todo.pop()
        pdone.add(p)
        for np in REL[p]:
            if np in pdone:
                continue
            todo.append(np)
    done |= pdone
    ans = max(ans, len(pdone))
print(ans)

Fixed submission:
import sys
N, M = map(int, input().split())
REL = [set() for _ in range(N)]
for _ in range(M):
    a, b = map(int, sys.stdin.readline().split())
    REL[a-1].add(b-1)
    REL[b-1].add(a-1)
REL = [list(s) for s in REL]

ans = 0
todo = []
done = set()
pdone = set()
for s in range(N):
    if s in done:
        continue
    pdone.clear()
    todo.append(s)
    while todo:
        p = todo.pop()
        pdone.add(p)
        done.add(p)
        for np in REL[p]:
            if np in pdone:
                continue
            todo.append(np)
    ans = max(ans, len(pdone))
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import sys
N, M = map(int, input().split())
REL = [set() for _ in range(N)]
for _ in range(M):
    a, b = map(int, sys.stdin.readline().split())
    REL[a-1].add(b-1)
    REL[b-1].add(a-1)

ans = 0
todo = []
done = set()
for s in range(N):
    if s in done:
        continue
    pdone = set()
    todo.append(s)
    while todo:
        p = todo.pop()
        pdone.add(p)
        for np in REL[p]:
            if np in pdone:
                continue
            todo.append(np)
    done |= pdone
    ans = max(ans, len(pdone))
print(ans)

Fixed submission:
import sys
N, M = map(int, input().split())
REL = [set() for _ in range(N)]
for _ in range(M):
    a, b = map(int, sys.stdin.readline().split())
    REL[a-1].add(b-1)
    REL[b-1].add(a-1)
REL = [list(s) for s in REL]

ans = 0
todo = []
done = set()
pdone = set()
for s in range(N):
    if s in done:
        continue
    pdone.clear()
    todo.append(s)
    while todo:
        p = todo.pop()
        pdone.add(p)
        done.add(p)
        for np in REL[p]:
            if np in pdone:
                continue
            todo.append(np)
    ans = max(ans, len(pdone))
print(ans)
Buggy python submission (verdict: Runtime Error):
N, M, K = map(int, input().split())
A = tuple(map(int, input().split()))
B = tuple(map(int, input().split()))

t = 0
anum = 0
for a in A:
    if K < t + a:
        break
    t += a
    anum += 1

bnum = 0
for b in B:
    if K < t + b:
        break
    t + b
    bnum += 1

ans = anum + bnum

for i in range(bnum, M):
    while K < t + B[i]:
        t -= A[anum-1]
        anum -= 1
    t += B[i]
    bnum += 1
    ans = max(ans, anum + bnum)

print(ans)

Fixed submission:
import bisect
N, M, K = map(int, input().split())
A = tuple(map(int, input().split()))
B = tuple(map(int, input().split()))

Asums = [0] * (N + 1)
for i, a in enumerate(A):
    Asums[i+1] = Asums[i] + a

Bsums = [0] * (M + 1)
for i, b in enumerate(B):
    Bsums[i+1] = Bsums[i] + b

ans = 0
for anum in range(N + 1):
    t = Asums[anum]
    if K < t:
        break
    bnum = bisect.bisect_right(Bsums, K - t) - 1
    ans = max(ans, anum + bnum)
print(ans)

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

ans = 0
total_time = 0
while A or B:
    if not A:
        t = B.pop()
    elif not B:
        t = A.pop()
    else:
        if A[-1] < B[-1]:
            t = A.pop()
        elif B[-1] < A[-1]:
            t = B.pop()
        else:
            if A[-2] < B[-2]:
                t = A.pop()
            else:
                t = B.pop()
    total_time += t
    if total_time <= K:
        ans += 1
    else:
        break
print(ans)

Fixed submission:
import bisect
N, M, K = map(int, input().split())
A = tuple(map(int, input().split()))
B = tuple(map(int, input().split()))

Asums = [0] * (N + 1)
for i, a in enumerate(A):
    Asums[i+1] = Asums[i] + a

Bsums = [0] * (M + 1)
for i, b in enumerate(B):
    Bsums[i+1] = Bsums[i] + b

ans = 0
for anum in range(N + 1):
    t = Asums[anum]
    if K < t:
        break
    bnum = bisect.bisect_right(Bsums, K - t) - 1
    ans = max(ans, anum + bnum)
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = tuple(map(int, input().split()))
MAX = 10 ** 18
ans = A[0]
for a in A[1:]:
    ans *= a
if ans > MAX:
    print(-1)
else:
    print(ans)

Fixed submission:
N = int(input())
A = sorted(map(int, input().split()))
MAX = 10 ** 18
ans = A[0]
for a in A[1:]:
    ans *= a
    if ans > MAX:
        ans = -1
        break
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
S = [("R", "G", "B").index(c) for c in input()]

sums = [[0] * (N + 1) for _ in range(3)]
for i, c in enumerate(S):
    for x in sums:
        x[i+1] = x[i]
    sums[c][i+1] += 1

ans = 0
for i in range(N - 2):
    si = S[i]
    for j in range(i + 1, N - 1):
        sj = S[j]
        if si == sj:
            continue
        sk = (set(range(3)) - {si, sj}).pop()
        count = sums[sk][N] - sums[sk][j+1]
        if j - i <= N - (j + 1):
            count -= (sums[sk][j+1+j-i] - sums[sk][j+1+j-i-1])
        ans += count
print(ans)

Fixed submission:
from bisect import bisect_left
N = int(input())
S = input()
X = {"R": [], "G": [], "B": []}
Xset = {"R": set(), "G": set(), "B": set()}
for i, c in enumerate(S):
    X[c].append(i)
    Xset[c].add(i)

ans = 0
for i in range(N - 2):
    si = S[i]
    for j in range(i + 1, N - 1):
        sj = S[j]
        if si == sj:
            continue
        x = ["R", "G", "B"]
        x.remove(si)
        x.remove(sj)
        sk = x[0]
        ks = X[sk]
        count = len(ks) - bisect_left(ks, j)
        if 2 * j - i in Xset[sk]:
            count -= 1
        ans += count
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
from bisect import bisect_left
N = int(input())
S = input()
X = {"R": [], "G": [], "B": []}
Xset = {"R": set(), "G": set(), "B": set()}
for i, c in enumerate(S):
    X[c].append(i)
    Xset[c].add(i)

ans = 0
for i in range(N - 2):
    si = S[i]
    for j in range(i + 1, N - 1):
        sj = S[j]
        if si == sj:
            continue
        x = ["R", "G", "B"]
        x.remove(si)
        x.remove(sj)
        sk = x[0]
        ks = X[sk]
        count = len(ks) - bisect_left(ks, j)
        if 2 * j - i in Xset[sk]:
            count -= 1
        ans += count
print(ans)

Fixed submission:
from bisect import bisect_left
N = int(input())
S = input()
X = {"R": [], "G": [], "B": []}
Xset = {"R": set(), "G": set(), "B": set()}
for i, c in enumerate(S):
    X[c].append(i)
    Xset[c].add(i)

ans = 0
for i in range(N - 2):
    si = S[i]
    for j in range(i + 1, N - 1):
        sj = S[j]
        if si == sj:
            continue
        x = ["R", "G", "B"]
        x.remove(si)
        x.remove(sj)
        sk = x[0]
        ks = X[sk]
        count = len(ks) - bisect_left(ks, j)
        if 2 * j - i in Xset[sk]:
            count -= 1
        ans += count
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque
N, X, Y = map(int, input().split())
G = [[] for _ in range(N)]
for i in range(N - 1):
    G[i].append(i + 1)
    G[N-i-1].append(N - i - 2)
G[X-1].append(Y-1)
G[Y-1].append(X-1)

mind = [[N] * N for _ in range(N)]
todo = deque()
for s in range(N):
    todo.append((0, s))
    done = set()
    while todo:
        d, p = todo.popleft()
        mind[s][p] = min(mind[s][p], d)
        done.add(p)
        for np in G[p]:
            if not np in done:
                todo.append((d + 1, np))

counts = [0] * (N - 1)
for i in range(N - 1):
    for j in range(i + 1, N):
        counts[mind[i][j]-1] += 1
for c in counts:
    print(c)

Fixed submission:
from collections import deque
N, X, Y = map(int, input().split())
G = [[] for _ in range(N)]
for i in range(N - 1):
    G[i].append(i + 1)
    G[N-i-1].append(N - i - 2)
G[X-1].append(Y-1)
G[Y-1].append(X-1)

mind = [[N] * N for _ in range(N)]
todo = deque()
for s in range(N):
    todo.append((0, s))
    done = set()
    while todo:
        d, p = todo.popleft()
        mind[s][p] = min(mind[s][p], d)
        done.add(p)
        for np in G[p]:
            if not np in done:
                todo.append((d + 1, np))

counts = [0] * (N - 1)
for i in range(N - 1):
    for j in range(i + 1, N):
        counts[mind[i][j]-1] += 1
for c in counts:
    print(c)
Buggy python submission (verdict: Time Limit Exceeded):
from math import factorial
from functools import lru_cache

@lru_cache(maxsize=None)
def cmbcount(n):
    if n > 1:
        return factorial(n) // (factorial(n - 2) * factorial(2))
    return 0

N = int(input())
A = list(map(int, input().split()))
samecnt = [0] * (N + 1)
for a in A:
    samecnt[a] += 1
cnts = [cmbcount(n) for n in samecnt]
allcnt = sum(cnts)
for i in range(N):
    a = A[i]
    o = cnts[a]
    n = cmbcount(samecnt[a] - 1)
    ans = allcnt - (o - n)
    print(ans)

Fixed submission:
from math import factorial
from functools import lru_cache

@lru_cache(maxsize=None)
def cmbcount(n):
    if n > 1:
        return factorial(n) // (factorial(n - 2) * factorial(2))
    return 0

N = int(input())
A = list(map(int, input().split()))
samecnt = [0] * (N + 1)
for a in A:
    samecnt[a] += 1
cnts = [cmbcount(n) for n in samecnt]
allcnt = sum(cnts)
for i in range(N):
    a = A[i]
    o = cnts[a]
    n = cmbcount(samecnt[a] - 1)
    ans = allcnt - (o - n)
    print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque
S = input()
s = deque(S)
Q = int(input())
for _ in range(Q):
    q = input()
    if q == "1":
        s.reverse()
    else:
        _, F, C = q.split()
        if F == "1":
            s.appendleft(C)
        else:
            s.append(C)
print("".join(s))

Fixed submission:
S = input()
Q = int(input())
f = True
l = []
r = []
for _ in range(Q):
    q = input()
    if q == "1":
        f = not f
    else:
        _, F, C = q.split()
        if F == "1":
            t = l if f else r
            t.append(C)
        else:
            t = r if f else l
            t.append(C)
if f:
    l.reverse()
    ans = "".join(l) + S + "".join(r)
else:
    r.reverse()
    ans = "".join(r) + S[::-1] + "".join(l)
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque
S = input()
s = deque(S)
Q = int(input())
for _ in range(Q):
    q = input()
    if q == "1":
        s.reverse()
    else:
        _, F, C = q.split()
        if F == "1":
            s.appendleft(C)
        else:
            s.append(C)
print("".join(s))

Fixed submission:
S = input()
Q = int(input())
f = True
l = []
r = []
for _ in range(Q):
    q = input()
    if q == "1":
        f = not f
    else:
        _, F, C = q.split()
        if F == "1":
            t = l if f else r
            t.append(C)
        else:
            t = r if f else l
            t.append(C)
if f:
    l.reverse()
    ans = "".join(l) + S + "".join(r)
else:
    r.reverse()
    ans = "".join(r) + S[::-1] + "".join(l)
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N, K = map(int, input().split())
exps = [
    float(sum(range(1, p + 1))) / float(p)
    for p in map(int, input().split())
]
ans = 0
for i in range(N - K + 1):
    exp = sum([e for e in exps[i:i+K]])
    if ans < exp:
        ans = exp
print(ans)

Fixed submission:
from math import fsum
s = [0] * 1001
for i in range(1, len(s)):
    s[i] = s[i - 1] + i
N, K = map(int, input().split())
exps = [s[p] / p for p in map(int, input().split())]
exp = fsum(exps[:K])
ans = exp
for i in range(K, N):
    exp = fsum((exp, -exps[i - K], exps[i]))
    if ans < exp:
        ans = exp
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
P = list(map(int, input().split()))
ans = 0
for i, pi in enumerate(P):
    if all([pi < pj for pj in P[:i]]):
        ans += 1
print(ans)

Fixed submission:
N = int(input())
P = list(map(int, input().split()))
pp = P[0]
ans = 0
for p in P:
    if p <= pp:
        ans += 1
        pp = p
print(ans)
Buggy python submission (verdict: Runtime Error):
ans = 0
for i in range(len(S) // 2):
    if S[i] != S[-1-i]:
        ans += 1
print(ans)

Fixed submission:
S = input()
ans = 0
for i in range(len(S) // 2):
    if S[i] != S[-1-i]:
        ans += 1
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = tuple(map(int, input().split()))
MOD = 10 ** 9 + 7

ans = 0
x = 1
for d in range(60):
    odd = 0
    even = 0
    for a in A:
        if a & (1 << d):
            odd += 1
        else:
            even += 1
    ans += odd * even * x
    ans %= MOD
    x <<= 1
print(ans)

Fixed submission:
N = int(input())
A = tuple(map(int, input().split()))
MOD = 10 ** 9 + 7

ans = 0
x = 1
for d in range(60):
    odd = 0
    even = 0
    for a in A:
        if a & (1 << d):
            odd += 1
        else:
            even += 1
    ans += odd * even * x
    ans %= MOD
    x <<= 1
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
S = tuple(map(int, input()))

ans = 0
pins = [0] * 3
for pin in range(1000):
    pins[0] = pin // 100
    pins[1] = (pin % 100) // 10
    pins[2] = pin % 10
    x = 0
    for c in S:
        if c == pins[x]:
            x += 1
            if x == 3:
                ans += 1
                break
print(ans)

Fixed submission:
N = int(input())
S = tuple(map(int, input()))

ans = 0
pins = [0] * 3
for pin in range(1000):
    pins[0] = pin // 100
    pins[1] = (pin % 100) // 10
    pins[2] = pin % 10
    x = 0
    for c in S:
        if c == pins[x]:
            x += 1
            if x == 3:
                ans += 1
                break
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
S = input()

ans = 0
for pin in ("%03d" % x for x in range(10 ** 3)):
    x = 0
    for c in S:
        if c == pin[x]:
            x += 1
            if x == 3:
                ans += 1
                break
print(ans)

Fixed submission:
N = int(input())
S = tuple(map(int, input()))

ans = 0
pins = [0] * 3
for pin in range(1000):
    pins[0] = pin // 100
    pins[1] = (pin % 100) // 10
    pins[2] = pin % 10
    x = 0
    for c in S:
        if c == pins[x]:
            x += 1
            if x == 3:
                ans += 1
                break
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
S = input()
ans = set()
c0done = set()
for i0 in range(N - 2):
    c0 = S[i0]
    if c0 in c0done:
        continue
    c0done.add(c0)
    for i1 in range(i0 + 1, N - 1):
        c1 = S[i1]
        for c2 in set(S[i1+1:]):
            ans.add(c0 + c1 + c2)
print(len(ans))

Fixed submission:
N = int(input())
S = tuple(map(int, input()))

ans = 0
pins = [0] * 3
for pin in range(1000):
    pins[0] = pin // 100
    pins[1] = (pin % 100) // 10
    pins[2] = pin % 10
    x = 0
    for c in S:
        if c == pins[x]:
            x += 1
            if x == 3:
                ans += 1
                break
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
S = input()
ans = set()
for i0 in range(N - 2):
    for i1 in range(i0 + 1, N - 1):
        for i2 in range(i1 + 1, N):
            ans.add(int(S[i0] + S[i1] + S[i2]))
print(len(ans))

Fixed submission:
N = int(input())
S = tuple(map(int, input()))

ans = 0
pins = [0] * 3
for pin in range(1000):
    pins[0] = pin // 100
    pins[1] = (pin % 100) // 10
    pins[2] = pin % 10
    x = 0
    for c in S:
        if c == pins[x]:
            x += 1
            if x == 3:
                ans += 1
                break
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import bisect
N, M = map(int, input().split())
A = sorted(map(int, input().split()))
for _ in range(M):
    x = A.pop()
    y = x // 2
    i = bisect.bisect_left(A, y)
    A.insert(i, y)
ans = sum(A)
print(ans)

Fixed submission:
import bisect
N, M = map(int, input().split())
A = sorted(map(int, input().split()))
for _ in range(M):
    x = A.pop()
    y = x // 2
    i = bisect.bisect_left(A, y)
    A.insert(i, y)
ans = sum(A)
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
ans = sum(range(1, N))
print(ans)

Fixed submission:
N = int(input())
ans = sum(range(1, N))
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
S = input()
N = len(S)
MOD = 10 ** 9 + 7

dp = [[0] * 13 for _ in range(N + 1)]
dp[0][0] = 1
for i in range(N):
    c = int(S[i]) if S[i] != "?" else -1
    for j in range(10):
        if c == -1 or c == j:
            for ki in range(13):
                dp[i+1][(ki * 10 + j) % 13] += dp[i][ki]
    for j in range(13):
        dp[i+1][j] %= MOD
ans = dp[N][5]
print(ans)

Fixed submission:
S = input()
N = len(S)
MOD = 10 ** 9 + 7

dp = [[0] * 13 for _ in range(N + 1)]
dp[0][0] = 1
for i in range(N):
    c = int(S[i]) if S[i] != "?" else -1
    for j in range(10):
        if c == -1 or c == j:
            for ki in range(13):
                dp[i+1][(ki * 10 + j) % 13] += dp[i][ki]
    for j in range(13):
        dp[i+1][j] %= MOD
ans = dp[N][5]
print(ans)
Buggy python submission (verdict: Runtime Error):
import bisect
N, K = map(int, input().split())
A = tuple(map(int, input().split()))

s = [0] * (N + 1)
for i in range(N):
    s[i+1] = s[i] + A[i]
ans = 0
for b in range(N):
    i = bisect.bisect_left(s, K + s[b], b)
    ans += (N + 1 - i)
print(ans)


Fixed submission:
W, H, x, y = map(int, input().split())
print(W * H / 2, 1 if x * 2 == W and y * 2 == H else 0)
Buggy python submission (verdict: Time Limit Exceeded):
import sys
H, W = map(int, input().split())
G = [sys.stdin.readline() for _ in range(H)]

counts = [[[-1] * 4 for _ in range(W + 1)] for _ in range(H + 1)]
for h in range(H):
    for w in range(W):
        if G[h][w] == ".":
            counts[h][w][0] = counts[h][w-1][0] + 1
            counts[h][w][1] = counts[h-1][w][1] + 1
        dih = H - h - 1
        diw = W - w - 1
        if G[dih][diw] == ".":
            counts[dih][diw][2] = counts[dih][diw+1][2] + 1
            counts[dih][diw][3] = counts[dih+1][diw][3] + 1
ans = 0
for h in range(H):
    for w in range(W):
        if G[h][w] == ".":
            ans = max(ans, sum(counts[h][w]) + 1)
print(ans)

Fixed submission:
import sys
H, W = map(int, input().split())
G = [sys.stdin.readline() for _ in range(H)]

counts = [[[-1] * 4 for _ in range(W + 1)] for _ in range(H + 1)]
for h in range(H):
    for w in range(W):
        if G[h][w] == ".":
            counts[h][w][0] = counts[h][w-1][0] + 1
            counts[h][w][1] = counts[h-1][w][1] + 1
        dih = H - h - 1
        diw = W - w - 1
        if G[dih][diw] == ".":
            counts[dih][diw][2] = counts[dih][diw+1][2] + 1
            counts[dih][diw][3] = counts[dih+1][diw][3] + 1
ans = 0
for h in range(H):
    for w in range(W):
        if G[h][w] == ".":
            ans = max(ans, sum(counts[h][w]) + 1)
print(ans)