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

Fixed submission:
def gcd_core(a, b):
    if b == 0:
        return a
    else:
        return gcd_core(b, a % b)

def gcd(arr):
    g = gcd_core(arr[0], arr[1])
    for i in range(2, len(arr)):
        g = gcd_core(g, arr[i])
    return g

def lcm_core(a,b):
    g = gcd_core(a,b)
    return (a*b)//g

def lcm(arr):
    l = lcm_core(arr[0],arr[1])
    for i in range(2,len(arr)):
        l = lcm_core(l,arr[i])
    return l

N = int(input())
T = [int(input()) for _ in range(N)]
if N==1:
    print(T[0])
else:
    print(lcm(T))

Buggy submission (verdict: Runtime Error):
def gcd_core(a, b):
    if b == 0:
        return a
    else:
        return gcd_core(b, a % b)

def gcd(arr):
    g = gcd_core(arr[0], arr[1])
    for i in range(2, len(arr)):
        g = gcd_core(g, arr[i])
    return g

def lcm_core(a,b):
    g = gcd_core(a,b)
    return (a*b)//g

def lcm(arr):
    l = lcm_core(arr[0],arr[1])
    for i in range(2,len(arr)):
        l = lcm_core(l,arr[i])
    return l

N = int(input())
T = [int(input()) for _ in range(N)]

print(lcm(T))
Problem p03680 (python)

Fixed submission:
import sys

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

cnt = 0
t = 1
for i in a:
    t = a[t-1]
    cnt += 1
    if t == 2:
        print(cnt)
        sys.exit()
print("-1")

Buggy submission (verdict: Runtime Error):
n = int(input())
a = []
for i in range(n):
    a.append(int(input()))

cnt = 0
t = 1
for i in a:
    t = a[t-1]
    cnt += 1
    if t == 2:
        print(cnt)
        exit(1)
print("-1")

Buggy submission (verdict: Runtime Error):
n = int(input())
a = []
for i in range(n):
    a.append(int(input()))

cnt = 0
t = 1
for i in a:
    t = a[t-1]
    cnt += 1
    if t == 2:
        print(cnt)
        exit(1)
print(-1)
Problem p03695 (python)

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

colors = [0]*9
for a in A:
    colors[min(8, a//400)] += 1
ansmin = 0
for c in colors[:-1]:
    if c:
        ansmin += 1
x = 0
if ansmin < colors[-1]:
    x = 1
print("{} {}".format(max(ansmin, x), ansmin+colors[-1]))

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

colors = [0]*9
for a in A:
    colors[a//400] += 1
ansmin = 0
for c in colors[:-1]:
    if c:
        ansmin += 1
print("{} {}".format(ansmin, ansmin+colors[-1]))

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

hist = [0]*9
for i in A:
    hist[i//400] += 1

ansmin = 0
for i in hist[:-1]:
    if i > 0:
        ansmin += 1
print("{} {}".format(ansmin, ansmin+hist[-1]))
Problem p02838 (python)

Fixed submission:
mod = int(1e9+7)
N = int(input())
A = list(map(int, input().split()))
ans = 0
for i in range(60):
    a = 0
    b = 0
    for j in range(N):
        if A[j] % 2:
            a += 1
        else:
            b += 1
        A[j] //= 2
    ans += a*b*pow(2, i, mod)
    ans %= mod
print(ans)

Buggy submission (verdict: Runtime Error):
import sys
mod = int(1e9+7)
input=sys.stdin.readline
N = int(input())
A = list(map(int, input().split()))
#S[0]は使わない
S = [[0]*60 for _ in range(N)]

tmp = A[-1]
idx = 0
while tmp > 0:
    if tmp%2:
        S[-1][idx] += 1
    idx += 1
    tmp //= 2

for i in range(N-2, 0, -1):
    for j in range(60):
        S[i][j] = S[i+1][j]
    tmp = A[i]
    idx = 0
    while tmp > 0:
        if tmp % 2:
            S[i][idx] += 1
        idx += 1
        tmp //= 2

ans = 0
for i in range(N-1):
    tmp = A[i]
    idx = 0
    while tmp > 0:
        if tmp % 2:
            ans += ((N-1-i)-S[i+1][idx])*pow(2, idx, mod)%mod

        else:
            ans += S[i+1][idx]*pow(2, idx, mod)%mod

        idx += 1
        tmp //= 2
        ans %= mod

    rest = S[i+1][idx:]
    for x in rest:
        ans += xpow(2, idx, mod)%mod
        idx += 1
        ans %= mod

print(ans)
Problem p02927 (python)

Fixed submission:
from math import sqrt
M, D = map(int, input().split())
ans = 0
for i in range(1, M+1):
    for j in range(1, D+1):
        if j//10 >= 2 and j%10 >= 2:
            if (j//10)*(j%10) == i:
                ans += 1

print(ans)

Buggy submission (verdict: Runtime Error):
#include <iostream>
using namespace std;

int main(){
    int M, D;
    cin >> M >> D;
    int ans = 0;
    for(int m = 1;m<=M;m++){
        for(int d=1;d<=D;d++){
            if(d % 10 >= 2 && d/10 >= 2 && (d%10)*(d/10) == m){
                ans += 1;
            }
        }
    }
    cout << ans << endl;
}
Problem p02936 (python)

Fixed submission:
import sys
input = sys.stdin.readline
N, Q = map(int, input().split())

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

xs = [0]*N
for _ in range(Q):
    p, x = map(int, input().split())
    xs[p-1] += x

ans = [0]*N
ans[0] = xs[0]
visited = [0]*N
stack = [0]
while stack:
    v = stack.pop()
    visited[v] = 1
    for to in es[v]:
        if visited[to]:
            continue
        stack.append(to)
        ans[to] = ans[v] + xs[to]

print(*ans)

Buggy submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline
N, Q = map(int, input().split())

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

xs = [0]*N
for _ in range(Q):
    p, x = map(int, input().split())
    xs[p-1] += x

ans = [0]
ans[0] = xs[0]
visited = [0]*N
stack = [0]
while stack:
    v = stack.pop()
    visited[v] = 1
    for to in es[v]:
        if visited[to]:
            continue
        stack.append(to)
        ans[to] = ans[v] + xs[to]

print(*ans)

Buggy submission (verdict: Runtime Error):
 
def dfs(a, b):  

    visited[a] = 1 
    b += 1
    start[a] = b  
    dfs_order.append(a)  
      
    for it in adj[a]:  
        if not visited[it]:  
            b = dfs(it, b)  
       
    endd[a] = b 
    return b 
  
n, q  = map(int, input().split())
start = [None] * (n+1) 
endd = [None] * (n+1)
dfs_order = []  
adj = [[] for i in range(n+1)]  
visited = [False] * (n+1)
for i in range(n-1):
    a, b = map(int, input().split())
    adj[a-1].append(b-1)

dfs(0, 0)  

subtree = [[] for _ in range(n+1)]
for i in range(n):  
    subtree[i].append(i)  
    if start[i] != endd[i]:   
        for j in range(start[i]+1, endd[i]+1):  
            subtree[i].append(dfs_order[j-1])   

ans = [0]*(n)

for i in range(q):
    p, x = map(int, input().split())
    for j in subtree[p-1]:
        ans[j] += x

print(*ans)
Problem p02947 (python)

Fixed submission:
from collections import defaultdict
N = int(input())
D = defaultdict(int)
for i in range(N):
    S = ''.join(sorted(input()))
    D[S] += 1

ans = 0
for key in D:
    M = D[key]
    if M >= 2:
        ans += M*(M-1)//2
    
print(ans)

Buggy submission (verdict: Runtime Error):
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>

using namespace std;
typedef long long ll;

int main(){
    int N;
    map<string, ll> m;
    cin >> N;
    string S;
    for(int i=0;i<N;i++){
        cin >> S;
        vector<char> v;
        //範囲ベースforループ
        for(auto x:S)v.push_back(x);
        sort(v.begin(), v.end());
        string T = "";
        for(auto x:v)T += x;
        m[T]++;
    }
    ll ans = 0;
    for(auto x:m) ans += (x.second-1)*x.second/2;
    cout << ans << endl;
}
Problem p02996 (python)

Fixed submission:
N = int(input())
T = sorted([tuple(map(int, input().split())) for _ in range(N)], key=lambda x:x[1])
now = 0
for a, b in T:
    if now + a <= b:
        now += a
    else:
        print("No")
        exit()
print("Yes")

Buggy submission (verdict: Runtime Error):
#include <iostream>
#include <algorithm>

using namespace std;

int N;
int A[200010], B[200010];
pair<int, int> C[200010];

int main(){
    cin >> N;
    for(int i=1;i<=N;i++){
        cin >> A[i] >> B[i];
        //<b, i>のpairを作りAにアクセスできるようにする
        C[i] = {B[i], i};
    }
    sort(C+1, C+N+1);
    int time = 0;
    for(int i=1;i<=N;i++){
        int id = C[i].second;
        if(time + A[id] <= B[id]) time += A[id];
        else{
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
    return 0;
}
Problem p03006 (python)

Fixed submission:
N = int(input())
XY = sorted([tuple(map(int, input().split())) for _ in range(N)])
PQ = []
for i in range(N-1):
    for j in range(i, N):
        PQ.append((XY[j][0]-XY[i][0], XY[j][1]-XY[i][1]))
PQ = list(set(PQ))
ans = N
for p, q in PQ:
    tmp1 = 1
    check=[0]*N
    for i in range(N-1):
        if check[i]:
            continue
        else:
            check[i] = 1
            tmp2 = 1
        for j in range(i, N):
            if check[j]:
                continue
            else:
                if XY[j][0] - p == XY[i][0] and XY[j][1] - q == XY[i][1]:
                    check[j] == 1
                    tmp2 = 0
                    break
        tmp1 += tmp2        
    ans = min(ans, tmp1)
print(ans)

Buggy submission (verdict: Runtime Error):
from collections import deque
from collections import defaultdict
N = int(input())
XY = list(sorted([tuple(map(int, input().split())) for _ in range(N)]))
PQ = []
for i in range(N-1):
    for j in range(i, N):
        PQ.append((XY[j][0]-XY[i][0], XY[j][1]-XY[i][1]))
PQ = list(set(PQ))
ans = N
for p, q in PQ:
    tmp1 = 1
    check = defaultdict(int)
    T = deque(XY.copy())
    for x, y in T:
        check[(x, y)] += 1
    x, y = T.popleft()
    cnt = 1
    while cnt < N:
        tmp2 = 1
        for s, t in T:
            if check[(s, t)] == 0:
                continue
            else:
                if s - p == x and t - q == y:
                    check[(s, t)] -= 1
                    tmp2 = 0
                    break
        if tmp2:
            x, y = T.popleft()
        else:
            x, y = s, t
        tmp1 += tmp2
        cnt += 1      
    ans = min(ans, tmp1)
print(ans)
Problem p03128 (python)

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

inf = float("inf")
dp = [-inf for i in range(n+1)]
dp[0] = 0

cost = {1:2, 2:5, 3:5, 4:4, 5:5, 6:6, 7:3, 8:7, 9:6}

for i in a:
    for j in range(1, n+1):
        if j - cost[i] >= 0:
            dp[j] = max(dp[j], dp[j-cost[i]]+1)

a.sort(reverse=True)
ans = ""
while n > 0:
    for i in a:
        state = True
        if n-cost[i] >= 0 and dp[n-cost[i]] == dp[n]-1:
            ans += str(i)
            n -= cost[i]
            state = False
            break
    if state:
        break

if ans == "":
    print(0)
else:
    print(ans)

Buggy submission (verdict: Runtime Error):
n, m = map(int, input().split())
a = list(map(int, input().split()))
inf = float("inf")
dp = [-inf] * (n+1)
dp[0] = 0
for i in range(1, n+1):
    for j in a:
        cost_j = int("0255456376"[j])
        if i- cost_j >= 0:
            dp[i] = max(dp[i], j+dp[i-cost_j]*10)
        print(dp)
ans = dp[n]
if ans == -inf:
    ans = 0
print(ans)

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

inf = float("inf")
dp = [-inf for i in range(n+1)]
dp[0] = 0

cost = {1:2, 2:5, 3:5, 4:4, 5:5, 6:6, 7:3, 8:7, 9:6}

use_cost = []
for i in a:
    use_cost.append(cost[i])

if n < min(use_cost):
    print(0)
    exit()

for i in a:
    for j in range(1, n+1):
        if j - cost[i] >= 0:
            dp[j] = max(dp[j], dp[j-cost[i]]+1)

a.sort(reverse=True)
ans = ""
while n > 0:
    for i in a:
        if dp[n-cost[i]] == dp[n]-1:
            ans += str(i)
            n -= cost[i]
            break
print(ans)

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

inf = float("inf")
dp = [-inf for i in range(n+1)]
dp[0] = 0

cost = {1:2, 2:5, 3:5, 4:4, 5:5, 6:6, 7:3, 8:7, 9:6}
use_cost = []
for i in a:
    use_cost.append(cost[i])
    for j in range(1, n+1):
        if j - cost[i] >= 0:
            dp[j] = max(dp[j], dp[j-cost[i]]+1)

if n < min(use_cost):
    print(0)
    exit()

a.sort(reverse=True)
ans = ""
while n > 0:
    for i in a:
        if dp[n-cost[i]] == dp[n]-1:
            ans += str(i)
            n -= cost[i]
            break
print(ans)

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

inf = float("inf")
dp = [-inf for i in range(n+1)]
dp[0] = 0

cost = {1:2, 2:5, 3:5, 4:4, 5:5, 6:6, 7:3, 8:7, 9:6}

for i in a:
    for j in range(1, n+1):
        if j - cost[i] >= 0:
            dp[j] = max(dp[j], dp[j-cost[i]]+1)

a.sort(reverse=True)
ans = ""
while n > 0:
    for i in a:
        if dp[n-cost[i]] == dp[n]-1:
            ans += str(i)
            n -= cost[i]
            break
print(ans)
Problem p03138 (python)

Fixed submission:
n, k = map(int, input().split())
a = list(map(int, input().split()))
h = [[0, 0] for _ in range(41)]
b = list(map(int, bin(k)[2:].zfill(41)))
for i in a:
    for x, y in enumerate(map(int, bin(i)[2:].zfill(41))):
        h[x][y] += 1

ans = 0
ctr = 0
hm = [max(x, y)*2**(40-i) for i, [x, y] in enumerate(h)]
for i, v in enumerate(b):
    if not v:
        ctr += h[i][1]*2**(40-i)
    else:
        ans = max(ans, ctr+h[i][1]*2**(40-i)+sum(hm[i+1:]))
        ctr += h[i][0]*2**(40-i)
print(max(ans, ctr))

Buggy submission (verdict: Runtime Error):
from math import log2
n, k = map(int, input().split())
a = list(map(int, input().split()))
m = max(a)
r = int(log2(m))
rank = [0]*(r+1)
for y in a:
    tmp = y
    for j in range(r, -1, -1):
        if tmp >= 2**j:
            rank[j] += 1
            tmp -= 2**j

y = 0
if k >= 2**(r+1):
    for i in range(int(log2(k)), r, -1):
        if y > k:
            break
        else:
            y += 2**i
    ans1 = ans2 = y
else
    ans1 = ans2 = 0
x1 = 0
for i in range(r, -1, -1):
    if rank[i] <= n//2:
        if x1 + 2**i > k:
            break
        else:
            x1 += 2**i
            ans1 += 2**i*(n-rank[i])
    else:
        ans1 += 2**i*rank[i]

x2 = 0
for i in range(r, -1, -1):
    if rank[i] <= n//2:
        if x2 + 2**i > k:
            break
        else:
            x2 += 2**i
            ans2 += 2**i*(n-rank[i])
    else:
        ans2 += 2**i*rank[i]

ans = max(ans1, ans2)
Problem p03149 (python)

Fixed submission:
a = set(map(int, input().split()))

if a == {1, 9, 7, 4}:
    print("YES")
else:
    print("NO")

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

if sum(a) < sum(b):
    print(-1)
    exit()

q = []
p = []
d = 0

for i in range(n):
    if a[i] - b[i] < 0:
        q.append(a[i]-b[i])
    elif a[i] - b[i] > 0:
        p.append(a[i]-b[i])
    else:
        d += 1

s = sum(q)
p = sorted(p)
while s < 0:
    if p == []:
        print(-1)
        exit()
    else:
        t = p.pop()
        s += t

print(n - d - len(p))
Problem p03214 (python)

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

md = sum(a)/n

ans = 0
m = float('inf')
for i in range(n):
    if abs(a[i]-md) < m:
        ans = i
        m = abs(a[i]-md)
print(ans)

Buggy submission (verdict: Runtime Error):
from math import log2
n, k = map(int, input().split())
a = list(map(int, input().split()))
b = [[a[i]] for i in range(n)]
c = list(a)

for i in range(n-1):
    for j in range(i+1, n):
        b[i].append(a[j]+b[i][-1])
        c.append(b[i][-1])

m = 40 #ceil(log2((10**9)*1000))=40よりbit幅を40としておけば十分
ans = 0
for i in range(m, -1, -1):
    log = 2**i
    tmp = [x for x in c if x&log==log]
    if len(tmp) >= k:
        ans += log
        c = tmp
print(ans)
Problem p03238 (python)

Fixed submission:
n = int(input())
if n == 1:
    print("Hello World")
else:
    a = int(input())
    b = int(input())
    print(a+b)

Buggy submission (verdict: Runtime Error):
n = int(input())
a = [list(map(int, input().split())) for i in range(n)]
for i in range(101):
    for j in range(101):
        H = []
        check = []
        for k in range(n):
            x = a[k][0]
            y = a[k][1]
            h = a[k][2]
            if h ==  0:
                check.append((x, y))
            else:
                H.append(h + abs(x-i) + abs(y-j))
                if len(set(H)) > 1:
                    break
            if k == n-1:
                state = False
                for s,t in check:
                    if H[0] - abs(s-i) - abs(t-j) > 0:
                        state = True
                        break
                if state:
                    break
                print(i, j, H[0])
                exit()
Problem p03244 (python)

Fixed submission:
from collections import Counter
n = int(input())
k = n//2
a = list(map(int, input().split()))
p = []
q = []
for i in range(k):
    p.append(a[2*i])
    q.append(a[2*i+1])
s = Counter(p).most_common()
t = Counter(q).most_common()
u, v = len(s), len(t)
ans = 0
if s[0][0] == t[0][0]:
    if u == 1 and v == 1:
        ans = k
    elif u == 1:
        ans = k - t[1][1]
    elif v == 1:
        ans = k - s[1][1]
    else:
        comp = max(s[1][1], t[1][1])
        ans = n - s[0][1] - comp
else:
    ans = n - s[0][1] - t[0][1]
print(ans)

Buggy submission (verdict: Runtime Error):
from collections import Counter
n = int(input())
k = n//2
a = list(map(int,input().split()))
b = c = []
for i in range(k):
  b.append(a[2*i])
  c.append(a[2*i+1])
p = Counter(b).most_common()
q = Counter(c).most_common()
s, t = p[0], q[0]
if s[0]!=t[0]:
  ans = n - s[1]-t[1]
else:
  if p[1][1] >= q[1][1]:
    ans = n - t[1]-p[1][1]
  else:
    ans = n - s[1] - q[1][1]
print(ans)
Problem p03260 (python)

Fixed submission:
a,b = map(int, input().split())
if a*b % 2:
    print('Yes')
else:
    print('No')

Buggy submission (verdict: Runtime Error):
n, x = map(int, input().split())
a = list(map(int, input().split()))
if n == 1:
    print(abs(x-a[0]))
    exit()
a.sort()
else:
    box = [a[i+1]-a[i] for i in range(n-1)]
    b = min(box)
    for i in range(1,b+1):
        for j in range(n-1):
            if box[j]%i:
                break
            if j == n-2:
                ans = i
    d = abs(x-a[0])
    if ans <= d:
        for i in range(1,ans+1):
            if d%i:
                continue
            else:
                temp = i
        print(temp)
    else:
        for i in range(1,d+1):
            if ans%i:
                continue
            else:
                temp = i
        print(temp)
Problem p03262 (python)

Fixed submission:
n, x = map(int, input().split())
a = list(map(int, input().split()))
if n == 1:
    print(abs(x-a[0]))
    exit()
else:
    a.append(x)
    a.sort()
    box = [a[i+1]-a[i] for i in range(n)]
    b = min(box)
    for i in range(1,b+1):
        for j in range(n-1):
            if box[j]%i:
                break
            if j == n-2:
                ans = i
    print(ans)

Buggy submission (verdict: Runtime Error):
n, x = map(int, input().split())
a = list(map(int, input().split()))
if n == 1:
    print(abs(x-a[0]))
    exit()
a.sort()
else:
    box = [a[i+1]-a[i] for i in range(n-1)]
    b = min(box)
    for i in range(1,b+1):
        for j in range(n-1):
            if box[j]%i:
                break
            if j == n-2:
                ans = i
    d = abs(x-a[0])
    if ans <= d:
        for i in range(1,ans+1):
            if d%i:
                continue
            else:
                temp = i
        print(temp)
    else:
        for i in range(1,d+1):
            if ans%i:
                continue
            else:
                temp = i
        print(temp)
Problem p03263 (python)

Fixed submission:
s = input()
h, w = map(int, s.split())
a = [list(map(int, input().split())) for i in range(h)]
b = [[[-1,-1]]*w for i in range(h)]
for i in range(h):
    for j in range(w):
        a[i][j] %= 2
count = 0
for i in range(h-1):
    for j in range(w):
        if a[i][j] == 1:
            a[i][j] = 0
            a[i+1][j] = (a[i+1][j]+1)%2
            b[i][j] = [i+1, j]
            count += 1
for i in range(w-1):
    if a[h-1][i] == 1:
        a[h-1][i] = 0
        a[h-1][i+1] = (a[h-1][i+1]+1)%2
        b[h-1][i] = [h-1, i+1]
        count += 1
print(count)
for i in range(h):
    for j in range(w):
        if not b[i][j] == [-1,-1]:
            print(i+1, j+1, b[i][j][0]+1, b[i][j][1]+1)

Buggy submission (verdict: Runtime Error):
s = input()
h, w = map(int, s.split())
a = [list(map(int, input().split())) for i in range(h)]
b = [[[-1,-1]]*w for i in range(h)]
for i in range(h):
    for j in range(w):
        a[i][j] %= 2
count = 0
for i in range(h-1):
    for j in range(w):
        if a[i][j] == 1:
            a[i][j] = 0
            a[i+1][j] = (a[i+1][j]+1)%2
            b[i][j] = [i+1, j]
            count += 1
for i in range(w):
    if a[h-1][i] == 1:
        a[h-1][i] = 0
        a[h-1][i+1] = (a[h-1][i+1]+1)%2
        b[h-1][i] = [h-1, i+1]
        count += 1
print(count)
for i in range(h):
    for j in range(w):
        if not b[i][j] == [-1,-1]:
            print(i+1, j+1, b[i][j][0]+1, b[i][j][1]+1)

Buggy submission (verdict: Runtime Error):
h, w = map(int, input().split())
a = [list(map(int, input().split())) for i in range(h)]
b = [[[-1,-1]]*w for i in range(h)]
for i in range(h):
    for j in range(w):
        a[i][j] %= 2
count = 0
for i in range(h-1):
    for j in range(w):
        if a[i][j] == 1:
            a[i][j] = 0
            a[i+1][j] = (a[i+1][j]+1)%2
            b[i][j] = [i+1, j]
            count += 1
for i in range(w):
    if a[h-1][i] == 1:
        a[h-1][i] = 0
        a[h-1][i+1] = (a[h-1][i+1]+1)%2
        b[h-1][i] = [h-1, i+1]
        count += 1
print(count)
for i in range(h):
    for j in range(w):
        if not b[i][j] == [-1,-1]:
            print(i+1, j+1, b[i][j][0]+1, b[i][j][1]+1)

Buggy submission (verdict: Runtime Error):
h, w = map(int, input().split())
a = [list(map(int, input().split())) for i in range(h)]
b = [[[-1,-1]]*w for i in range(h)]
for i in range(h):
    for j in range(w):
        a[i][j] %= 2
count = 0 
for i in range(h-1):
    for j in range(w):
        if a[i][j] == 1:
            a[i][j] = 0
            a[i+1][j] = (a[i+1][j]+1)%2
            b[i][j] = [i+1, j]
            count += 1
for i in range(w):
    if a[h-1][i] == 1:
        a[h-1][i] = 0
        a[h-1][i+1] = (a[h-1][i+1]+1)%2
        b[h-1][i] = [h-1, i+1]
        count += 1
print(count)
for i in range(h):
    for j in range(w):
        if not b[i][j] == [-1,-1]:
            print(i+1, j+1, b[i][j][0]+1, b[i][j][1]+1)
Problem p03282 (python)

Fixed submission:
s,k = [input() for i in range(2)]
for i in range(int(k)):
    if int(s[i]) > 1:
        print(s[i])
        exit()
print(1)

Buggy submission (verdict: Runtime Error):
s,k = [input() for i in range(2)]
for i in range(k):
    if int(s[i]) > 1:
        print(s[i])
        exit()
print(1)
Problem p03297 (python)

Fixed submission:
from fractions import gcd
n = int(input())
A = [list(map(int, input().split())) for _ in range(n)]
for i in range(n):
    a,b,c,d = A[i]
    g = gcd(b,d)
    if a < b or b > d or b-g+(a%g)>c:
        print('No')
    else:
        print('Yes')

Buggy submission (verdict: Runtime Error):
from fractons import gcd
n = int(input())
for i in range(n):
    a,b,c,d = map(int, input().split())
    g = gcd(b,d)
    if a < b or b > d or b-g+(a%g)>c:
        print('No')
    else:
        print('Yes')

Buggy submission (verdict: Runtime Error):
from math import gcd
n = int(input())
A = [list(map(int, input().split())) for _ in range(n)]
for i in range(n):
    a,b,c,d = A[i]
    g = gcd(b,d)
    if a < b or b > d or b-g+(a%g)>c:
        print('No')
    else:
        print('Yes')

Buggy submission (verdict: Runtime Error):
from math import gcd
n = int(input())
for _ in range(n):
    a,b,c,d = map(int, input().split())
    g = gcd(b,d)
    if a < b or b > d or b-g+(a%g) > c:
        print('No')
    else:
        print('Yes')
Problem p03353 (python)

Fixed submission:
s = input()
k = int(input())

n = len(s)

d = set()
for i in range(n):
    for j in range(i+1, min(i+k+1,n+1)):
        tmp = s[i:j]
        d.add(tmp)
a = sorted(list(d))
print(a[k-1])

Buggy submission (verdict: Runtime Error):
s = input()
k = int(input())

n = len(s)

d = set()
for i in range(n):
    for j in range(i+1, min(i+k,n+1)):
        tmp = s[i:j]
        d.add(tmp)
a = sorted(list(d))
print(a[k-1])