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

Fixed submission:
s=input()
x,y=map(int, input().split())
cnt = 0; mode = 2
l = len(s) # l + 1 + l
X = Y = 1 << l
for c in s:
    if c is 'F':
        cnt += 1
    else:
        if mode == 0:
            X = (X >> cnt) | (X << cnt)
        elif mode == 1:
            Y = (Y >> cnt) | (Y << cnt)
        else:
            X = X << cnt
            mode = 0
        cnt = 0; mode ^= 1
if cnt > 0:
    if mode == 0:
        X = (X >> cnt) | (X << cnt)
    elif mode == 1:
        Y = (Y >> cnt) | (Y << cnt)
    else:
        X = X << cnt
if (X >> (l + x)) & 1 and (Y >> (l + y)) & 1:
    print("Yes")
else:
    print("No")

Buggy submission (verdict: Runtime Error):
z,*s=map(len,input().split('T'));l=sum(s);Y=1<<l;X=Y<<z
for t,u in zip(s[::2],s[1::2]+[0]):Y=Y>>t|Y<<t;X=X>>u|X<<u
x,y=map(int,input().split());print("Yes"*(X>>l+x&Y>>l+y&1)or"No")

Buggy submission (verdict: Runtime Error):
z,*s=map(len,input().split('T')+['']);l=sum(s,0);Y=1<<l;X=Y<<z
for t,u in zip(s[::2],s[1::2]):Y=Y>>t|Y<<t;X=X>>u|X<<u
x,y=map(int,input().split());print("Yes"*(X>>l+x&Y>>l+y&1)or"No")

Buggy submission (verdict: Runtime Error):
z,*s,=map(len,input().split('T')+['']);l=sum(s);Y=1<<l;X=Y<<z
for t,u in zip(s[::2],s[1::2]):Y=Y>>t|Y<<t;X=X>>u|X<<u
x,y=map(int,input().split());print("Yes"*(X>>l+x&Y>>l+y&1)or"No")
Problem p03504 (python)

Fixed submission:
N, C = map(int, input().split())

su = [0]*(10**5+1)
Q = [[] for i in range(C)]
for i in range(N):
    s, t, c = map(int, input().split())
    Q[c-1].append([s, t])
R = [[] for i in range(C)]
for i in range(C):
    q = Q[i]; q.sort()
    r = R[i]
    if len(q) == 0:
        continue
    r.append(q[0])
    for j in range(1, len(q)):
        if r[-1][1] == q[j][0]:
            r[-1][1] = q[j][1]
        else:
            r.append(q[j])
    for a, b in r:
        su[a-1] += 1
        su[b] -= 1
ans = 0; tmp = 0
for i in range(10**5+1):
    tmp += su[i]
    ans = max(ans, tmp)
print(ans)

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

su = [0]*(10**5+1)
Q = [[] for i in range(C)]
for i in range(N):
    s, t, c = map(int, input().split())
    Q[c-1].append([s, t])
R = [[] for i in range(C)]
for i in range(C):
    q = Q[i]; q.sort()
    r = R[i]
    r.append(q[0])
    for j in range(1, len(q)):
        if r[-1][1] == q[j][0]:
            r[-1][1] = q[j][1]
        else:
            r.append(q[j])
    for a, b in r:
        su[a-1] += 1
        su[b] -= 1
ans = 0; tmp = 0
for i in range(10**5+1):
    tmp += su[i]
    ans = max(ans, tmp)
print(ans)
Problem p03523 (python)

Fixed submission:
s = input()
t = "AKIHABARA"
idx = 0
ok = 1
for i in range(len(s)):
    if idx == len(t):
        ok = 0
        break
    if s[i] == t[idx]:
        idx += 1
    elif s[i] != 'A' and t[idx] == 'A':
        idx += 1
        if idx < len(t) and s[i] == t[idx]:
            idx += 1
        else:
            ok = 0
    else:
        ok = 0
if idx != len(t) and idx != len(t)-1:
    ok = 0
print("YES"*ok or "NO")

Buggy submission (verdict: Runtime Error):
s = input()
t = "AKIHABARA"
idx = 0
ok = 1
for i in range(len(s)):
    if idx == len(t):
        ok = 0
        break
    if s[i] == t[idx]:
        idx += 1
    elif s[i] != 'A' and t[idx] == 'A':
        idx += 1
        if s[i] == t[idx]:
            idx += 1
        else:
            ok = 0
    else:
        ok = 0
if idx != len(t) and idx != len(t)-1:
    ok = 0
print("YES"*ok or "NO")

Buggy submission (verdict: Runtime Error):
s = input()
t = "AKIHABARA"
idx = 0
ok = 1
for i in range(len(s)):
    if s[i] == t[idx]:
        idx += 1
    elif s[i] != 'A' and t[idx] == 'A':
        idx += 1
        if s[i] == t[idx]:
            idx += 1
        else:
            ok = 0
    elif idx == len(t):
        ok = 0
        break
    else:
        ok = 0
print("YES"*ok or "NO")
Problem p03552 (python)

Fixed submission:
N, Z, W = map(int, input().split())
*A, = map(int, input().split())

import sys
sys.setrecursionlimit(10**6)

memo = {}
def dfs(i, turn):
    if (i, turn) in memo:
        return memo[i, turn]
    if turn == 0:
        # X
        if i == 0:
            res = abs(W - A[-1])
        else:
            res = abs(A[i-1] - A[-1])
        for j in range(i+1, N):
            res = max(res, dfs(j, 1))
    else:
        # Y
        if i == 0:
            res = abs(Z - A[-1])
        else:
            res = abs(A[i-1] - A[-1])
        for j in range(i+1, N):
            res = min(res, dfs(j, 0))
    memo[i, turn] = res
    return res
print(dfs(0, 0))

Buggy submission (verdict: Runtime Error):
N, Z, W = map(int, input().split())
*A, = map(int, input().split())

memo = {}
def dfs(i, turn):
    if (i, turn) in memo:
        return memo[i, turn]
    if turn == 0:
        # X
        if i == 0:
            res = abs(W - A[-1])
        else:
            res = abs(A[i-1] - A[-1])
        for j in range(i+1, N):
            res = max(res, dfs(j, 1))
    else:
        # Y
        if i == 0:
            res = abs(Z - A[-1])
        else:
            res = abs(A[i-1] - A[-1])
        for j in range(i+1, N):
            res = min(res, dfs(j, 0))
    memo[i, turn] = res
    return res
print(dfs(0, 0))
Problem p03573 (python)

Fixed submission:
*S,=map(int, input().split())
S.sort()
print(S[0] if S[1] == S[2] else S[2])

Buggy submission (verdict: Runtime Error):
S=map(int, input().split())
S.sort()
print(S[0] if S[1] == S[2] else S[2])
Problem p03601 (python)

Fixed submission:
import sys
sys.setrecursionlimit(100000)
a, b, c, d, e, f = map(int, input().split())
def dfs(g, a, b, can, base=100):
    if not base*g <= f:
        return
    if g in can:
        return
    can[g] = 1
    dfs(g + a, a, b, can, base)
    dfs(g + b, a, b, can, base)
can1 = {}
dfs(0, a, b, can1)
can2 = {}
dfs(0, c, d, can2, 1)

ans = (0, 0, 0)
for g in can1:
    if g == 0:
        continue
    rest = f - 100*g
    result = max([0]+[h for h in can2 if h <= min(rest, e*g)])
    ans = max(ans, (result / (100.*g + result), 100*g+result, result))
print(*ans[1:])

Buggy submission (verdict: Runtime Error):
n = int(input())
A = [list(map(int, input().split())) for i in range(n)]
B = [e[:] for e in A]

for k in range(n):
    for i in range(n):
        for j in range(n):
            B[i][j] = min(B[i][k] + B[k][j], B[i][j])
ok = 1
for i in range(n):
    for j in range(n):
        if A[i][j] != B[i][j]:
            ok = 0
if not ok:
    print(-1)
    exit(0)

ans = 0
for i in range(n):
    for j in range(i+1, n):
        need = 1
        for k in range(n):
            if i == k or j == k:
                continue
            if A[i][k] + A[k][j] == A[i][j]:
                need = 0
        if need:
            ans += A[i][j]
print(ans)
Problem p03647 (python)

Fixed submission:
n,m,*T=map(int,open(0).read().split());*S,=zip(T[::2],T[1::2]);s=lambda e:set(s[e<2]for s in S if e in s);print("IM"*(len(s(1)&s(n))<1)+"POSSIBLE")

Buggy submission (verdict: Runtime Error):
n,m,*T=map(int,open(0).read().split());*S,=zip(T[::2],T[1::2]);s=lambda e:{*sum([s for s in S if e in s],())};print("IM"*(len(s(1)&s(n))<1)+"POSSIBLE")
Problem p03675 (python)

Fixed submission:
n = input()
A = raw_input().split()
B = A[0::2]
C = A[1::2]
if n % 2 == 1:
    print " ".join(B[::-1] + C)
else:
    print " ".join(C[::-1] + B)

Buggy submission (verdict: Runtime Error):
n=int(input());A=input().split();print(*A[-1::-2],*A[n%2::2])
Problem p03693 (python)

Fixed submission:
print "YES"*(int(raw_input().replace(" ", ""))%4==0)or"NO"

Buggy submission (verdict: Runtime Error):
print("YES"*(int(input()[::2])%4<1)or"NO")
Problem p03703 (python)

Fixed submission:
n, k = map(int, raw_input().split())
A = [int(raw_input())-k for i in xrange(n)]
su = 0
v = [(0, 0)]
for i in xrange(n):
    su += A[i]
    v.append((su, i+1))
v.sort()

data = [0]*(n+5)
def dsum(i):
    s = 0
    while i > 0:
        s += data[i]
        i -= i & -i
    return s
def add(i, x):
    while i <= n+2:
        data[i] += x
        i += i & -i
ans = 0
for e, i in v:
    ans += dsum(i+1)
    add(i+1, 1)
print ans

Buggy submission (verdict: Runtime Error):
n, k = map(int, raw_input().split())
A = [int(raw_input())-k for i in xrange(n)]
su = 0
v = [(0, 0)]
for i in xrange(n):
    su += A[i]
    v.append((su, i+1))
v.sort()

class BIT:
    def __init__(self, n):
        self.n = n
        self.data = [0]*n
        self.el = [0]*n
    def sum(self, i):
        s = 0
        while i > 0:
            s += self.data[i]
            i -= i & -i
        return s
    def add(self, i, x):
        self.el[i] += x
        while i <= self.n:
            self.data[i] += x
            i += i & -i
    def get(self, i):
        return self.el[i]

ans = 0
bit = BIT(n+2)
for e, i in v:
    ans += bit.sum(i+1)
    bit.add(i+1, 1)
print ans

Buggy submission (verdict: Runtime Error):
n, k = map(int, raw_input().split())
A = [int(raw_input())-k for i in xrange(n)]
su = 0
v = [(0, 0)]
for i in xrange(n):
    su += A[i]
    v.append((su, i+1))
v.sort()

data = [0]*(n+2)
def sum(i):
    s = 0
    while i > 0:
        s += data[i]
        i -= i & -i
    return s
def add(i, x):
    while i <= n+2:
        data[i] += x
        i += i & -i
ans = 0
tmp = 0
for e, i in v:
    ans += sum(i+1)
    add(i+1, 1)
print ans

Buggy submission (verdict: Runtime Error):
n, k = map(int, raw_input().split())
A = [int(raw_input())-k for i in xrange(n)]
su = 0
v = [(0, 0)]
for i in xrange(n):
    su += A[i]
    v.append((su, i+1))
v.sort()

data = [0]*(n+2)
def sum(i):
    s = 0
    while i > 0:
        s += data[i]
        i -= i & -i
    return s
def add(i, x):
    while i <= n+2:
        data[i] += x
        i += i & -i
ans = 0
tmp = 0
for e, i in v:
    ans += sum(i+1)
    add(i+1, 1)
print ans
Problem p03722 (python)

Fixed submission:
n, m = map(int, raw_input().split())
g = [[] for i in xrange(n)]
for i in xrange(m):
    a, b, c = map(int, raw_input().split())
    g[a-1].append((b-1, c))
dist = [-10**18]*n


import sys
sys.setrecursionlimit(10**6)
used = [0]*n
valid = [0]*n
memo = [None]*n
def dfs(v):
    res = 0
    if memo[v] is not None:
        return memo[v]
    for t, c in g[v]:
        if not used[t]:
            if t == n-1:
                res = 1
            used[t] = 1
            res |= dfs(t)
            used[t] = 0
    valid[v] |= res
    memo[v] = valid[v]
    return res
valid[0] = valid[n-1] = 1
used[0] = 1
dfs(0)

dist[0] = 0
for t in xrange(2*n):
    update = 0
    for v in xrange(n):
        for t, c in g[v]:
            if valid[t] and dist[v] + c > dist[t]:
                dist[t] = dist[v] + c
                update = 1
if update == 1:
    print "inf"
else:
    print dist[n-1]

Buggy submission (verdict: Runtime Error):
n, m = map(int, raw_input().split())
g = [[] for i in xrange(n)]
for i in xrange(m):
    a, b, c = map(int, raw_input().split())
    g[a-1].append((b-1, c))
dist = [-10**18]*n

used = [0]*n
valid = [0]*n
memo = [None]*n
def dfs(v):
    res = 0
    if memo[v] is not None:
        return memo[v]
    for t, c in g[v]:
        if not used[t]:
            if t == n-1:
                res = 1
            used[t] = 1
            res |= dfs(t)
            used[t] = 0
    valid[v] |= res
    memo[v] = valid[v]
    return res
valid[0] = valid[n-1] = 1
used[0] = 1
dfs(0)

dist[0] = 0
for t in xrange(2*n):
    update = 0
    for v in xrange(n):
        for t, c in g[v]:
            if valid[t] and dist[v] + c > dist[t]:
                dist[t] = dist[v] + c
                update = 1
if update == 1:
    print "inf"
else:
    print dist[n-1]

Buggy submission (verdict: Runtime Error):
n, m = map(int, raw_input().split())
g = [[] for i in xrange(n)]
for i in xrange(m):
    a, b, c = map(int, raw_input().split())
    g[a-1].append((b-1, c))
dist = [-10**18]*n

used = [0]*n
valid = [0]*n
def dfs(v):
    res = 0
    for t, c in g[v]:
        if not used[t]:
            if t == n-1:
                res = 1
            used[t] = 1
            res |= dfs(t)
            used[t] = 0
    valid[v] |= res
    return res
valid[0] = valid[n-1] = 1
used[0] = 1
dfs(0)

dist[0] = 0
for t in xrange(2*n):
    update = 0
    for v in xrange(n):
        for t, c in g[v]:
            if valid[t] and dist[v] + c > dist[t]:
                dist[t] = dist[v] + c
                update = 1
if update == 1:
    print "inf"
else:
    print dist[n-1]
Problem p03735 (python)

Fixed submission:
# seishin.py
from heapq import heappush, heappop, heapify

N = int(input())
P = []
for i in range(N):
    x, y = map(int, input().split())
    P.append((x, y) if x < y else (y, x))

X = [x for x, y in P]
Y = [y for x, y in P]

MIN = min(X)
MAX = max(Y)

# R_min = MIN, B_max = MAX
res = (max(X) - MIN) * (MAX - min(Y))

# R_min = MIN, R_max = MAX
base = MAX - MIN
heapify(P)

# 出来る限りスライドさせながら(B_max - B_min)を最小化
r = max(X)
while P:
    x, y = heappop(P)
    res = min(res, base * (r - x))
    if y != -1:
        # Bに入ってたxをRに入れて代わりにyをBに入れる
        heappush(P, (y, -1))
        r = max(r, y)
    else:
        # (x, y) のyの方がB_minに該当
        # => これ以上B_minを落とせない
        break

print(res)

Buggy submission (verdict: Runtime Error):
n = input()
P = []
mx = {}
my = {}
for i in xrange(n):
    x, y = map(int, raw_input().split())
    if x > y: x, y = y, x
    mx[x] = i
    my[y] = i
    P.append((x, y))

kx = sorted(mx)
mi_x = min(mx); ma_x = max(mx)
ky = sorted(my)
mi_y = min(my); ma_y = max(my)

if ma_x < mi_y or ma_y < mi_x:
    print (ma_x - mi_x) * (ma_y - mi_y)
    exit(0)

ans = (ma_x - mi_x) * (ma_y - mi_y)
xm = ()
for i in xrange(n):
    i = mx[kx[i]]
    if xm <= kx[i]:
        break
    y = P[i][1]
    if y <= min(ma_x, ma_y):
        xm = min(xm, y)
    else:
        break
ans = min((ma_x - xm) * (ma_y - kx[0]), ans)

ym = 0
for i in xrange(n-1, -1, -1):
    i = my[ky[i]]
    if ky[i] <= ym:
        break
    x = P[i][0]
    if max(mi_x, mi_y) <= x:
        ym = max(ym, x)
    else:
        break
ans = min((ky[-1] - mi_x) * (ym - mi_y), ans)
print ans

Buggy submission (verdict: Runtime Error):
n = input()
P = []
mx = {}
my = {}
for i in xrange(n):
    x, y = map(int, raw_input().split())
    if x > y: x, y = y, x
    mx[x] = i
    my[y] = i
    P.append((x, y))

kx = sorted(mx)
mi_x = min(mx); ma_x = max(mx)
ky = sorted(my)
mi_y = min(my); ma_y = max(my)

if ma_x < mi_y or ma_y < mi_x:
    print (ma_x - mi_x) * (ma_y - mi_y)
    exit(0)

ans = (ma_x - mi_x) * (ma_y - mi_y)
xm = ()
for i in xrange(n):
    i = mx[kx[i]]
    if xm <= kx[i]:
        break
    y = P[i][1]
    if y <= min(ma_x, ma_y):
        xm = min(xm, y)
    else:
        break
ans = min((ma_x - xm) * (ma_y - kx[0]), ans)

ym = 0
for i in xrange(n-1, -1, -1):
    i = my[ky[i]]
    if ky[i] <= ym:
        break
    x = P[i][0]
    if max(mi_x, mi_y) <= x:
        ym = max(ym, x)
    else:
        break
ans = min((ky[-1] - mi_x) * (ym - mi_y), ans)
Problem p03746 (python)

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

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

used = [0]*N
Q1 = []
Q2 = []
def dfs(v, Q):
    if used[v]:
        return 0
    used[v] = 1
    Q.append(v+1)
    for w in G[v]:
        if dfs(w, Q):
            return 1
    return 1

if len(G[0]) == 1:
    dfs(0, Q1)
    print(len(Q1))
    print(*Q1)
else:
    used[0] = 1
    for v in G[0]:
        if dfs(v, Q1):
            break
    for v in G[0]:
        if dfs(v, Q2):
            break
    print(len(Q1) + len(Q2) + 1)
    print(*(Q1[::-1]+[1]+Q2))

Buggy submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(10**6)

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

used = [0]*N
Q1 = []
Q2 = []
def dfs(v, Q):
    if used[v]:
        return 0
    used[v] = 1
    Q.append(v+1)
    for w in G[v]:
        if dfs(w, Q):
            return 1
    return 1

if len(G[0]) == 1:
    dfs(0, Q1)
    print(len(Q1))
    print(*Q1)
else:
    used[0] = 1
    for v in G[0]:
        if dfs(v, Q1):
            break
    for v in G[0]:
        if dfs(v, Q2):
            break
    print(len(Q1) + len(Q2) + 1)
    print(*Q1[::-1], 1, *Q2)
Problem p03783 (python)

Fixed submission:
# seishin.py
N = int(input())
P = [list(map(int, input().split())) for i in range(N)]

INF = 10**18

from heapq import heappush, heappop

l0, r0 = P[0]

L = [-l0+1]
R = [l0-1]
s = t = 0

def debug(L, s, t, R):
    L0 = L[:]
    Q1 = []; Q2 = []
    while L0:
        Q1.append(-s-heappop(L0))
    R0 = R[:]
    while R0:
        Q2.append(t+heappop(R0))
    print("debug:", *Q1[::-1]+Q2)


#print(L, s, t, R)
res = 0
for i in range(N-1):
    l0, r0 = P[i]
    l1, r1 = P[i+1]
    #print(">", l1, r1)
    s += (r1 - l1); t += (r0 - l0)
    if -s-L[0] <= l1-1 <= t+R[0]:
        #print(0)
        heappush(L, -l1+1-s)
        heappush(R, l1-1-t)
        # res += 0
    elif l1-1 < -s-L[0]:
        #print(1)
        heappush(L, -l1+1-s)
        heappush(L, -l1+1-s)
        p = -heappop(L)-s
        #d = (-L[0]-s) - p
        heappush(R, p-t)
        #print(d)
        #res += d
        res += (p - (l1-1))
    elif t+R[0] < l1-1:
        #print(2)
        heappush(R, l1-1-t)
        heappush(R, l1-1-t)
        p = heappop(R) + t
        #d = R[0]+t - p
        heappush(L, -p-s)
        #print(d)
        res += (l1-1 - p)
    #print(L, s, t, R, -s-L[0], R[0]+t, res)
    #debug(L, s, t, R)
print(res)

Buggy submission (verdict: Runtime Error):
N = int(input())
P = [list(map(int, input().split())) for i in range(N)]

INF = 10**18

L = max(r for l, r in P)
S = [0]*L
l0, r0 = P[0]
for i in range(L):
    S[i] = abs(i - (l0-1))
for i in range(N-1):
    l0, r0 = P[i]
    l1, r1 = P[i+1]
    T = [0]*L
    for x in range(L):
        r = INF
        for y in range(max(0, x-(r0-l0)), min(L, x+(r1-l1)+1)):
            r = min(r, S[y])
        T[x] = abs(x-(l1-1)) + r
    S = T
print(min(S))

Buggy submission (verdict: Runtime Error):
N = int(input())
P = [list(map(int, input().split())) for i in range(N)]

INF = 10**18

L = max(r for l, r in P)
S = [0]*L
l0, r0 = P[0]
for i in range(L):
    S[i] = abs(i - (l0-1))
for i in range(N-1):
    l0, r0 = P[i]
    l1, r1 = P[i+1]
    T = [0]*L
    for x in range(L):
        r = INF
        for y in range(max(0, x-(r0-l0)), min(L, x+(r1-l1)+1)):
            r = min(r, S[y])
        T[x] = abs(x-(l1-1)) + r
    S = T
print(min(S))
Problem p03791 (python)

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

MOD = 10**9+7

ans = 1
res = 0
for i in xrange(n):
    while 2*res+1 > X[i]:
        ans = (ans * (res+1)) % MOD
        res -= 1
    res += 1
while res:
    ans = (ans * res) % MOD
    res -= 1
print ans

Buggy submission (verdict: Runtime Error):
n = input()
X = map(int, raw_input().split())

if n > 10:
    exit(1)

cur = 1
for i in xrange(n):
    if cur <= X[i]:
        X[i] = cur
        cur += 2
    else:
        cur = X[i]+2

ALL = 2**n-1
memo = {}
def dfs(state):
    if state in memo:
        return memo[state]
    if state == ALL:
        return 1
    Y = X[:]
    cur = 1
    for i in xrange(n):
        if (state >> i) & 1:
            continue
        if cur <= Y[i]:
            Y[i] = cur
            cur += 2
        else:
            cur = Y[i]+2
    res = 0
    prev = -100
    for i in xrange(n):
        if (state >> i) & 1:
            continue
        res = (res + dfs(state | (1 << i))) % (10**9 + 7)
        if prev+1 == Y[i]:
            break
        prev = Y[i]
    memo[state] = res
    return res
print dfs(0)
Problem p03792 (python)

Fixed submission:
n = input()
A = [raw_input() for i in xrange(n)]

R = [sum(e[j] == '#' for j in xrange(n)) for e in A]
C = [sum(A[j][i] == '#' for j in xrange(n)) for i in xrange(n)]

c_need = sum(e < n for e in C)

INF = 10**9+7
ans = INF
for i in xrange(n):
    if R[i] == C[i] == 0:
        continue
    if C[i] == 0:
        ans = min(ans, n-R[i] + c_need + 1)
    else:
        ans = min(ans, n-R[i] + c_need)
print -1 if ans == INF else ans

Buggy submission (verdict: Runtime Error):
from collections import deque
n = input()
A = ''.join(raw_input() for i in xrange(n))

if n > 5:
    exit(1)

ALL = "#"*(n*n)

deq = deque()

deq.append((A, 0))
memo = {}
while deq:
    state, cost = deq.popleft()
    if state == ALL:
        print cost
        break
    if state in memo:
        continue
    s = list(state)
    memo[state] = 1
    for i in xrange(n):
        C = [state[i*n+k] for k in xrange(n)]
        for j in xrange(n):
            n_state = s[:]
            for k in xrange(n):
                n_state[k*n+j] = C[k]
            deq.append((''.join(n_state), cost+1))
else:
    print -1

Buggy submission (verdict: Runtime Error):
n = input()
A = ''.join(raw_input() for i in xrange(n))

if n > 5:
    exit(1)

ALL = "#"*(n*n)

memo = {}
def dfs(state):
    if state in memo:
        return memo[state]
    if state == ALL:
        return 0
    s = list(state)
    memo[state] = res = 10**9
    for i in xrange(n):
        C = [state[i*n+k] for k in xrange(n)]
        for j in xrange(n):
            n_state = s[:]
            for k in xrange(n):
                n_state[k*n+j] = C[k]
            if ''.join(n_state) == state:
                continue
            res = min(res, dfs(''.join(n_state))+1)
    memo[state] = res
    return res
ans = dfs(A)
if ans > 10**5:
    print -1
else:
    print ans

Buggy submission (verdict: Runtime Error):
n = input()
A = ''.join(raw_input() for i in xrange(n))

if n > 5:
    exit(1)

ALL = "#"*(n*n)

memo = {}
def dfs(state):
    if state in memo:
        return memo[state]
    if state == ALL:
        return 0
    s = list(state)
    memo[state] = res = 10**9
    for i in xrange(n):
        C = [state[i*n+k] for k in xrange(n)]
        for j in xrange(n):
            n_state = s[:]
            for k in xrange(n):
                n_state[k*n+j] = C[k]
            res = min(res, dfs(''.join(n_state))+1)
    memo[state] = res
    return res
ans = dfs(A)
if ans == 10**9:
    print -1
else:
    print ans
Problem p03819 (python)

Fixed submission:
# seishin.py
N, M = map(int, input().split())
D = [[] for i in range(M+1)]
for i in range(N):
    l, r = map(int, input().split())
    D[r-l+1].append(l)

data = [0]*(M+2)
def get(k):
    s = 0
    while k:
        s += data[k]
        k -= k & -k
    return s
def add(k, x):
    while k <= M+1:
        data[k] += x
        k += k & -k

C = N
ans = []
for d in range(1, M+1):
    for l in D[d]:
        add(l, 1)
        add(l+d, -1)
        C -= 1

    cnt = C
    i = d
    while i <= M:
        cnt += get(i)
        i += d
    ans.append(cnt)
print(*ans, sep='\n')

Buggy submission (verdict: Runtime Error):
from math import sqrt
N, M = map(int, input().split())
D = [0]*(M+2); R = [0]*(M)
for i in range(N):
    l, r = map(int, input().split())
    D[1] += 1
    D[r+1] -= 1
    if l <= r-l+1:
        continue
    D[r-l+2] -= 1
    D[l] += 1

    left = r-l+2; right = l
    for k in range(2, int(sqrt(r))+1):
        l0 = max((l+k-1) // k, left); r0 = min((r // k + 1, right))
        if l0 < r0:
            D[l0] += 1
            D[r0] -= 1
        right = l0

print(*R, *D)
tmp = 0
for i in range(1, M+1):
    tmp += D[i]
    R[i-1] += tmp
print(*R, sep='\n')
Problem p03852 (python)

Fixed submission:
print("vowel"*(input()in"aiueo")or"consonant")

Buggy submission (verdict: Runtime Error):
print"vowel"*(c in"aiueo")or"consonant"