Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
import itertools

def main():
    n,m=list(map(int,input().split(' ')))
    swich_all=list(itertools.product([0,1],repeat=n))
    swich=[]
    cnt=0
    for i in range(m):
        swich.append(list(map(int,input().split(' '))))
    check_p=list(map(int,input().split(' ')))
    for i in swich_all:
        tmp=0
        check =True
        for j in range(m):
            for k in swich[j][1:]:
                tmp += i[k-1]
            if tmp%2 != check_p[j]:
                check = False
                break
        if check == True:
            cnt +=1

    print(cnt)

main()

main()

Fixed submission:
import itertools

def main():
    n,m=list(map(int,input().split(' ')))
    swich_all=list(itertools.product([0,1],repeat=n))
    swich=[]
    cnt=0
    for i in range(m):
        swich.append(list(map(int,input().split(' '))))
    check_p=list(map(int,input().split(' ')))
    for i in swich_all:
        check = []
        for j in range(m):
            tmp = 0
            for k in swich[j][1:]:
                tmp += i[k-1]
            check.append(tmp%2)
        if check == check_p:
            cnt +=1

    print(cnt)

main()
Buggy python submission (verdict: Runtime Error):
n,k=list(map(int,input().split(" ")))
s=list(input())
s_str=""
s[k-1]=s[k-1].lower()
for i in s:
    s_str +=s[i]
print(s_str)


Fixed submission:
n,k=list(map(int,input().split(" ")))
s=list(input())
s_str = ""
if s[k-1]=="A":
    s[k-1]="a"
elif s[k-1]=="B":
    s[k-1]="b"
else:
    s[k-1]="c"
for i in s:
    s_str += i
print(s_str)

Buggy python submission (verdict: Runtime Error):
n,k=list(map(int,input().split(" ")))
s=list(input())
s_str=""
s[k-1]=s[k-1].lower()
for i in s:
  s_str +=s[i]
print(s_str)


Fixed submission:
n,k=list(map(int,input().split(" ")))
s=list(input())
s_str = ""
if s[k-1]=="A":
    s[k-1]="a"
elif s[k-1]=="B":
    s[k-1]="b"
else:
    s[k-1]="c"
for i in s:
    s_str += i
print(s_str)

Buggy python submission (verdict: Runtime Error):
n,k=list(map(int,input().split(" ")))
s=list(input())
s_str=""
s[k-1]=s[k-2].lower()
for i in s:
    s_str +=s[i]
print(s_str)


Fixed submission:
n,k=list(map(int,input().split(" ")))
s=list(input())
s_str = ""
if s[k-1]=="A":
    s[k-1]="a"
elif s[k-1]=="B":
    s[k-1]="b"
else:
    s[k-1]="c"
for i in s:
    s_str += i
print(s_str)

Buggy python submission (verdict: Runtime Error):
n,k=list(map(int,input().split(" ")))
s=list(input())
s_str=""
s[k-1]=s[k-2].lower()
for i in s:
  s_str +=s[i]
print(s_str)

Fixed submission:
n,k=list(map(int,input().split(" ")))
s=list(input())
s_str = ""
if s[k-1]=="A":
    s[k-1]="a"
elif s[k-1]=="B":
    s[k-1]="b"
else:
    s[k-1]="c"
for i in s:
    s_str += i
print(s_str)

Buggy python submission (verdict: Runtime Error):
n,k=list(map(int,input().split(" ")))
s=list(input())
s_str=""
s[k-1]=s[k-2].lower()
for i in s:
  s_str +=s[i]
print(s_str)

Fixed submission:
n,k=list(map(int,input().split(" ")))
s=list(input())
s_str = ""
if s[k-1]=="A":
    s[k-1]="a"
elif s[k-1]=="B":
    s[k-1]="b"
else:
    s[k-1]="c"
for i in s:
    s_str += i
print(s_str)
Buggy python submission (verdict: Runtime Error):
from collections import deque
N = int(input())
E = [[] for i in range(N + 1)]
ans = [-1]*(N+1)
ans[1] = 0
for i in range(N - 1):
    u, v, w = map(int, input().split((' ')))
    E[u].append((v, w % 2))
    E[v].append((u, w % 2))


def dfs(c=0,p=1):
    for e,w in E[p]:
        if ans[e] != -1:
            continue
        if w:
            ans[e] = 0 if c else 1
        else:
            ans[e] = c
        dfs(ans[e], e)
dfs()
for i in ans[1:]:
    print(i)

Fixed submission:
from collections import deque
N = int(input())
E = [[] for i in range(N + 1)]
ans = [-1]*(N+1)
ans[1] = 0
for i in range(N - 1):
    u, v, w = map(int, input().split((' ')))
    E[u].append((u, v, w % 2))
    E[v].append((v, u, w % 2))
dfs = deque(E[1])
while dfs:
    p = (dfs.popleft())
    f, t, w = p
    if ans[t] != -1:
        continue
    if w == 0:
        ans[t] = ans[f]
    else:
        ans[t] = 0 if ans[f] else 1
    for i in E[t]:
        dfs.append(i)
for i in ans[1:]:
    print(i)

Buggy python submission (verdict: Runtime Error):
from collections import deque
N = int(input())
E = [[] for i in range(N + 1)]
ans = [-1]*(N+1)
ans[1] = 0
for i in range(N - 1):
    u, v, w = map(int, input().split((' ')))
    E[u].append((v, w % 2))
    E[v].append((u, w % 2))


def dfs(c=0,p=1):
    for e,w in E[p]:
        if ans[e] != -1:
            continue
        if w:
            ans[e] = 0 if c else 1
        else:
            ans[e] = c
        dfs(ans[e], e)
dfs()
print(ans[1:])

Fixed submission:
from collections import deque
N = int(input())
E = [[] for i in range(N + 1)]
ans = [-1]*(N+1)
ans[1] = 0
for i in range(N - 1):
    u, v, w = map(int, input().split((' ')))
    E[u].append((u, v, w % 2))
    E[v].append((v, u, w % 2))
dfs = deque(E[1])
while dfs:
    p = (dfs.popleft())
    f, t, w = p
    if ans[t] != -1:
        continue
    if w == 0:
        ans[t] = ans[f]
    else:
        ans[t] = 0 if ans[f] else 1
    for i in E[t]:
        dfs.append(i)
for i in ans[1:]:
    print(i)
Buggy python submission (verdict: Time Limit Exceeded):
def main():
    R,B,G,N = list(map(int,input().split(' ')))
    cnt = 0
    for i in range(N//R+1):
        for j in range(N//G+1):
            if R*i+G*j > N:
              break
            if (N-(R*i+G*j))//B == (N-(R*i+G*j))/B and (N-(R*i+G*j))/B >=0:
                cnt +=1
    print(cnt)

if __name__ =='__main__':
    main()

Fixed submission:
def main():
    R,B,G,N = list(map(int,input().split(' ')))
    cnt = 0
    for r in range(N//R+1):
        for g in range(N//G+1):
            if R*r+G*g > N:
                break
            if (N-(R*r+G*g))%B ==0:

                cnt +=1
    print(cnt)
if __name__ =='__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
def main():
    R,B,G,N = list(map(int,input().split(' ')))
    cnt = 0
    for i in range(N//R+1):
        for j in range(N//G+1):
            if (N-(R*i+G*j))//B == (N-(R*i+G*j))/B and (N-(R*i+G*j))/B >=0:
                cnt +=1
    print(cnt)

if __name__ =='__main__':
    main()

Fixed submission:
def main():
    R,B,G,N = list(map(int,input().split(' ')))
    cnt = 0
    for r in range(N//R+1):
        for g in range(N//G+1):
            if R*r+G*g > N:
                break
            if (N-(R*r+G*g))%B ==0:

                cnt +=1
    print(cnt)
if __name__ =='__main__':
    main()
Buggy python submission (verdict: Time Limit Exceeded):
from heapq import *
def main():
    N=int(input())
    line = list(input())
    ans=[]

    for i in range(N+1):
        a=line[:i].count("#")
        b=line[i:].count(".")
        heappush(ans,a+b)

    return heappop(ans)

print(main())

Fixed submission:
n = int(input())
s = input()
ans = s.count('.')
num = ans
for c in s:
  if c == '.':
    num -= 1
  else:
    num += 1
  
  ans = min(ans,num)

print(ans)

Buggy python submission (verdict: Runtime Error):
from heapq import *
def main():
    N=int(input())
    line = list(input())
    ans=[]

    for i in range(N+1):
        a=line[:i].count("#")
        b=line[i:].count(".")
        heappush(ans,a+b)
    
    return peappop(ans)

print(main())

Fixed submission:
n = int(input())
s = input()
ans = s.count('.')
num = ans
for c in s:
  if c == '.':
    num -= 1
  else:
    num += 1
  
  ans = min(ans,num)

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
from itertools import accumulate
def main():
    N=int(input())
    line = list(input())
    ans=[]

    for i in range(N+1):
        a=line[:i].count("#")
        b=line[i:].count(".")
        ans.append(a+b)
    return min(ans)

print(main())

Fixed submission:
n = int(input())
s = input()
ans = s.count('.')
num = ans
for c in s:
  if c == '.':
    num -= 1
  else:
    num += 1
  
  ans = min(ans,num)

print(ans)
Buggy python submission (verdict: Runtime Error):
from itertools import accumulate

N,K=list(map(int,input().split(" ")))
S=input()

def solve():
    cnt=0
    l=[]
    prev = "1"
    for i in S:
        if prev ==i:
            cnt += 1
        else:
            l.append(cnt)
            cnt = 1
        prev =i
    l.append(cnt)
    if prev=="0":
        l.append("0")
    
    w = 2 * K + 1
    
    if len(l) <=w:
        return N
    
    acc=[0]+list(accumulate(l))
    ans = 0
    for i in range(0,len(l) - w+ 1,2):
        ans = max(ans, acc[w+i] - acc[i])

    return ans
print(solve())

Fixed submission:
A,B=list(map(int,input().split(" ")))
coin=[A+(A-1),B+(B-1),A+B]
print(max(coin))

Buggy python submission (verdict: Runtime Error):
from itertools import accumulate

n, k = list(map(int, input().split()))
s = input()


def solve():
    l = []
    prev = '1'
    cnt = 0
    for c in s:
        if prev == c:
            cnt += 1
        else:
            l.append(cnt)
            cnt = 1
        prev = c
    l.append(cnt)
    if prev == '0':
        l.append(0)

    w = 2 * k + 1

    if len(l) <= w:
        return n

    acc = [0] + list(accumulate(l))
    ans = 0
    for i in range(0, len(l) - w + 1, 2):
        ans = max(ans, acc[i + w] - acc[i])
    return ans


print(solve())


Fixed submission:
A,B=list(map(int,input().split(" ")))
coin=[A+(A-1),B+(B-1),A+B]
print(max(coin))
Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
B=list(map(int,input().split(' ')))
def dfs(n,B,ans):
    if n==0:
        return ans[::-1]
    else:
        for num,i in enumerate(B):
            if num+1==i:
                res = dfs(n-1,B[:num]+B[num+1:],ans+[i])
                if res:
                    return res
        return False
ans = dfs(N,B,[])
if not ans:
    print(-1)
else:
    for i in ans:
        print(i)

Fixed submission:
N=int(input())
B=list(map(int,input().split(' ')))
ans = []
for i in range(N):
    for n,j in enumerate(B[::-1]):
        if N-i-n==j:
            ans.append(B.pop(N-i-n-1))
            break
if len(ans)==N:
    for i in ans[::-1]:
        print(i)
else:
    print(-1)

Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
B=list(map(int,input().split(' ')))
def dfs(n,B,ans):
    if n==0:
        return ans[::-1]
    else:
        for num,i in enumerate(B):
            if num+1==i and dfs(n-1,B[:num]+B[num+1:],ans+[i]):
                return dfs(n-1,B[:num]+B[num+1:],ans+[i])
        return False
ans = dfs(N,B,[])
if not ans:
    print(-1)
else:
    for i in ans:
        print(i)

Fixed submission:
N=int(input())
B=list(map(int,input().split(' ')))
ans = []
for i in range(N):
    for n,j in enumerate(B[::-1]):
        if N-i-n==j:
            ans.append(B.pop(N-i-n-1))
            break
if len(ans)==N:
    for i in ans[::-1]:
        print(i)
else:
    print(-1)

Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
B=list(map(int,input().split(' ')))
def dfs(n,B,ans):
    if n==0:
        return ans[::-1]
    else:
        for num,i in enumerate(B):
            if num+1==i and dfs(n-1,B[:num]+B[num+1:],ans+[i]):
                return dfs(n-1,B[:num]+B[num+1:],ans+[i])
        return False
ans = dfs(N,B,[])
if not ans:
    print(-1)
else:
    for i in ans:
        print(i)

Fixed submission:
N=int(input())
B=list(map(int,input().split(' ')))
ans = []
for i in range(N):
    for n,j in enumerate(B[::-1]):
        if N-i-n==j:
            ans.append(B.pop(N-i-n-1))
            break
if len(ans)==N:
    for i in ans[::-1]:
        print(i)
else:
    print(-1)
Buggy python submission (verdict: Runtime Error):
t,x=map(int,input().split(' ')
print(t/x)

Fixed submission:
t,x=map(int,input().split(' '))
print(t/x)

Buggy python submission (verdict: Runtime Error):
t,x=map(int,input().split(''))
print(t/x)

Fixed submission:
t,x=map(int,input().split(' '))
print(t/x)
Buggy python submission (verdict: Time Limit Exceeded):
def main():
    n,k=map(int,input().split(' '))
    h=list(map(int,input().split(' ')))
    dp = [float('inf') for i in range(n)]
    dp[0]=0
    dp[1]=abs(h[1]-h[0])
    for i in range(n):
        for j in range(i,min(i+k+1,n)):
            if dp[j] > dp[i]+abs(h[i]-h[j]):
                dp[j] = dp[i]+abs(h[i]-h[j])
    print(dp[-1])


if __name__ == '__main__':
    main()


Fixed submission:
def main():
    n,k=map(int,input().split(' '))
    h=list(map(int,input().split(' ')))
    dp = [float('inf') for i in range(n)]
    dp[0]=0
    dp[1]=abs(h[1]-h[0])
    for i in range(n):
        for j in range(i,min(i+k+1,n)):
            if dp[j] > dp[i]+abs(h[i]-h[j]):
                dp[j] = dp[i]+abs(h[i]-h[j])
    print(dp[-1])


if __name__ == '__main__':
    main()
Buggy python submission (verdict: Runtime Error):
N = int(input())
for i in range(N)
    if int(input())%2 != 0:
        print("first")
        exit()
print('second')

Fixed submission:
N = int(input())
for i in range(N):
    if int(input())%2 != 0:
        print("first")
        exit()
print('second')
Buggy python submission (verdict: Runtime Error):
5 3
5
7
5
7
7

Fixed submission:
N,K=map(int,input().split(' '))
h=sorted([int(input()) for i in range(N)])
ans = 10**9
for i in range(N-K+1):
    ans = min(ans,h[i+K-1]-h[i])
print(ans)
Buggy python submission (verdict: Runtime Error):
from collections import deque

N = int(input())
A = deque(sorted([int(input()) for i in range(N)]))
B = A.copy()
ans = deque([A.popleft()])
while A:
    if A:
        ans.appendleft(A.pop())
    if A:
        ans.append(A.pop())
    if A:
        ans.appendleft(A.popleft())
    if A:
        ans.append(A.popleft())
res_1 = 0
ans = list(ans)
for i in range(N - 1):
    res_1 += abs(ans[i] - ans[i + 1])
ans = deque([B.pop()])
while B:
    if B:
        ans.appendleft(B.popleft())
    if B:
        ans.append(B.popleft())
    if B:
        ans.appendleft(B.pop())
    if B:
        ans.append(B.pop())
res_2 = 0
ans = list(ans)
for i in range(N - 1):
    res_2 += abs(ans[i] - ans[i + 1])
print(max(res_1, res_2))


Fixed submission:
from collections import deque
import copy
N = int(input())
A = deque(sorted([int(input()) for i in range(N)]))
B = copy.copy(A)
ans = deque([A.popleft()])
while A:
    if A:
        ans.appendleft(A.pop())
    if A:
        ans.append(A.pop())
    if A:
        ans.appendleft(A.popleft())
    if A:
        ans.append(A.popleft())
res_1 = 0
ans = list(ans)
for i in range(N - 1):
    res_1 += abs(ans[i] - ans[i + 1])
ans = deque([B.pop()])
while B:
    if B:
        ans.appendleft(B.popleft())
    if B:
        ans.append(B.popleft())
    if B:
        ans.appendleft(B.pop())
    if B:
        ans.append(B.pop())
res_2 = 0
ans = list(ans)
for i in range(N - 1):
    res_2 += abs(ans[i] - ans[i + 1])
print(max(res_1, res_2))

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

N = int(input())
A = deque(sorted([int(input()) for i in range(N)]))
B = A.copy()
ans = deque([A.popleft()])
while A:
    if A:
        ans.appendleft(A.pop())
    if A:
        ans.append(A.pop())
    if A:
        ans.appendleft(A.popleft())
    if A:
        ans.append(A.popleft())
res_1 = 0
ans = list(ans)
for i in range(N - 1):
    res_1 += abs(ans[i] - ans[i + 1])
ans = deque([B.pop()])
while B:
    if B:
        ans.appendleft(B.popleft())
    if B:
        ans.append(B.popleft())
    if B:
        ans.appendleft(B.pop())
    if B:
        ans.append(B.pop())
res_2 = 0
ans = list(ans)
for i in range(N - 1):
    res_2 += abs(ans[i] - ans[i + 1])
print(max(res_1, res_2))


Fixed submission:
from collections import deque
import copy
N = int(input())
A = deque(sorted([int(input()) for i in range(N)]))
B = copy.copy(A)
ans = deque([A.popleft()])
while A:
    if A:
        ans.appendleft(A.pop())
    if A:
        ans.append(A.pop())
    if A:
        ans.appendleft(A.popleft())
    if A:
        ans.append(A.popleft())
res_1 = 0
ans = list(ans)
for i in range(N - 1):
    res_1 += abs(ans[i] - ans[i + 1])
ans = deque([B.pop()])
while B:
    if B:
        ans.appendleft(B.popleft())
    if B:
        ans.append(B.popleft())
    if B:
        ans.appendleft(B.pop())
    if B:
        ans.append(B.pop())
res_2 = 0
ans = list(ans)
for i in range(N - 1):
    res_2 += abs(ans[i] - ans[i + 1])
print(max(res_1, res_2))
Buggy python submission (verdict: Runtime Error):
raise TypeError

Fixed submission:
N=int(input())
xyh=[list(map(int,input().split(' '))) for i in range(N)]
for i in range(101):
    for j in range(101):
        H_0=set([h+abs(x-i)+abs(y-j) for x,y,h in xyh])
        H_1=set([h+abs(x-i)+abs(y-j) for x,y,h in xyh if h!=0])
        if len(H_0)==1:
            print(i,j,max(H_0))
            exit()
        if len(H_1)==1:
            cx,cy,H=i,j,max(H_1)
print(cx,cy,H)
Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
V1,V2={},{}
ans = N-1
for n,i in enumerate(list(map(int,input().split(' ')))):
    if n%2==0:
        V1.setdefault(i,0)
        V1[i]+=1
    else:
        V2.setdefault(i,0)
        V2[i]+=1
V1=sorted(V1.items(),key=lambda x:x[1])
V2=sorted(V2.items(),key=lambda x:x[1])
cut = max(V1[0][1],V2[0][1])
for i in V1:
    for j in V2:
        if i[1]+j[1] < cut:
            break
        if i[0]!=j[0]:
            ans = min(ans,N-i[1]-j[1])
        else:
            ans = min(ans,N-max(i[1],j[1]))
print(ans)

Fixed submission:
N=int(input())
V1,V2={},{}
ans = N-1
for n,i in enumerate(list(map(int,input().split(' ')))):
    if n%2==0:
        V1.setdefault(i,0)
        V1[i]+=1
    else:
        V2.setdefault(i,0)
        V2[i]+=1
V1=sorted(V1.items(),key=lambda x:x[1],reverse=True)
V2=sorted(V2.items(),key=lambda x:x[1],reverse=True)
cut = max(V1[0][1],V2[0][1])
for i in V1[:2]:
    for j in V2[:2]:
        if i[0]!=j[0]:
            ans = min(ans,N-i[1]-j[1])
        else:
            ans = min(ans,N-max(i[1],j[1]))
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
V1,V2={},{}
ans = N-1
for n,i in enumerate(list(map(int,input().split(' ')))):
    if n%2==0:
        V1.setdefault(i,0)
        V1[i]+=1
    else:
        V2.setdefault(i,0)
        V2[i]+=1
V1=sorted(V1.items(),key=lambda x:x[1])
V2=sorted(V2.items(),key=lambda x:x[1])
for i in V1:
    for j in V2:
        if i[0]!=j[0]:
            ans = min(ans,N-i[1]-j[1])
        else:
            ans = min(ans,N-max(i[1],j[1]))
print(ans)

Fixed submission:
N=int(input())
V1,V2={},{}
ans = N-1
for n,i in enumerate(list(map(int,input().split(' ')))):
    if n%2==0:
        V1.setdefault(i,0)
        V1[i]+=1
    else:
        V2.setdefault(i,0)
        V2[i]+=1
V1=sorted(V1.items(),key=lambda x:x[1],reverse=True)
V2=sorted(V2.items(),key=lambda x:x[1],reverse=True)
cut = max(V1[0][1],V2[0][1])
for i in V1[:2]:
    for j in V2[:2]:
        if i[0]!=j[0]:
            ans = min(ans,N-i[1]-j[1])
        else:
            ans = min(ans,N-max(i[1],j[1]))
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
V1,V2={},{}
ans = N-1
for n,i in enumerate(list(map(int,input().split(' ')))):
    if n%2==0:
        V1.setdefault(i,0)
        V1[i]+=1
    else:
        V2.setdefault(i,0)
        V2[i]+=1
V1=sorted(V1.items(),key=lambda x:x[1])
V2=sorted(V2.items(),key=lambda x:x[1])
for i in V1:
    for j in V2:
        if i[0]!=j[0]:
            ans = min(ans,N-i[1]-j[1])
        else:
            ans = min(ans,N-max(i[1],j[1]))
print(ans)

Fixed submission:
N=int(input())
V1,V2={},{}
ans = N-1
for n,i in enumerate(list(map(int,input().split(' ')))):
    if n%2==0:
        V1.setdefault(i,0)
        V1[i]+=1
    else:
        V2.setdefault(i,0)
        V2[i]+=1
V1=sorted(V1.items(),key=lambda x:x[1],reverse=True)
V2=sorted(V2.items(),key=lambda x:x[1],reverse=True)
cut = max(V1[0][1],V2[0][1])
for i in V1[:2]:
    for j in V2[:2]:
        if i[0]!=j[0]:
            ans = min(ans,N-i[1]-j[1])
        else:
            ans = min(ans,N-max(i[1],j[1]))
print(ans)
Buggy python submission (verdict: Runtime Error):
H, W = map(int, input().split(' '))
A = [list(map(int, input().split(' '))) for i in range(H)]
cnt = 0
ans = []
for i in range(H):
    for j in range(W):
        if A[i][j] % 2 == 0:
            continue
        tmp = []
        flg = True
        for x, y in [[1, 0], [0, 1], [-1, 0], [0, -1]]:
            if 0 <= i+x < H and 0 <= j+y < W:
                if A[i+x][j+y] % 2 != 0:
                    A[i][j] -= 1
                    cnt += 1
                    A[i+x][j+y] += 1
                    ans.append([i, j, i+x, j+y])
                    flg = False
                    break
                elif A[i][j] == 1:
                    tmp = [x, y]
                else:
                    flg = False
        if flg:
            cnt += 1
            A[tmp[0]][tmp[1]] += 1
            A[i][j] -= 1
            ans.append([i, j, i+tmp[0], j+tmp[1]])

print(cnt)
for i, j, k, l in ans:
    print(i+1, j+1, k+1, l+1)


Fixed submission:
H, W = map(int, input().split(' '))
A = [list(map(int, input().split(' '))) for i in range(H)]
cnt = 0
ans = []
for i in range(H):
    for j in range(W):
        if A[i][j] % 2 == 0:
            continue
        tmp = ''
        flg = True
        for x, y in [[1, 0], [0, 1]]:
            if 0 <= i+x < H and 0 <= j+y < W:
                if A[i+x][j+y] % 2 != 0:
                    A[i][j] -= 1
                    cnt += 1
                    A[i+x][j+y] += 1
                    ans.append([i, j, i+x, j+y])
                    flg = False
                    break
                else:
                    tmp = [x, y]
        if flg and tmp:
            cnt += 1
            A[i+tmp[0]][j+tmp[1]] += 1
            A[i][j] -= 1
            ans.append([i, j, i+tmp[0], j+tmp[1]])
print(cnt)
for i, j, k, l in ans:
    print(i+1, j+1, k+1, l+1)
Buggy python submission (verdict: Time Limit Exceeded):
N,K=map(int,input().split(' '))
x = list(map(int,input().split(' ')))
ans = 2*(10**8)
if N==K:
    if x[-1]<0:
        print(-x[0])
    elif x[0]>0:
        print(x[-1])
    else:
        print(min(x[-1]-2*x[0],2*x[-1]-x[0]))
    exit()
for i in range(N-K):
    tmp = x[i:i+K]
    if tmp[-1]<0:
        ans = min(ans,-tmp[0])
    elif tmp[0]>=0:
        ans = min(ans,tmp[-1])
    else:
        ans = min(ans,tmp[-1]-2*tmp[0],2*tmp[-1]-tmp[0])
print(ans)

Fixed submission:
N,K=map(int,input().split(' '))
x = list(map(int,input().split(' ')))
ans = 2*(10**8)
if N==K:
    if x[-1]<0:
        print(-x[0])
    elif x[0]>0:
        print(x[-1])
    else:
        print(min(x[-1]-2*x[0],2*x[-1]-x[0]))
    exit()
for i in range(N-K+1):
    l,r=x[i],x[i+K-1]
    if l>0:
        ans = min(ans,r)
    elif r<0:
        ans = min(ans,-l)
    else:
        ans = min(ans,r-2*l,2*r-l)
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N,K=map(int,input().split(' '))
x = list(map(int,input().split(' ')))
ans = 2*(10**8)
if N==K:
    if x[-1]<0:
        print(-x[0])
    elif x[0]>0:
        print(x[-1])
    else:
        print(min(x[-1]-2*x[0],2*x[-1]-x[0]))
    exit()
for i in range(N-K):
    tmp = x[i:i+K]
    if tmp[-1]<0:
        ans = min(ans,-tmp[0])
    elif tmp[0]>=0:
        ans = min(ans,tmp[-1])
    else:
        ans = min(ans,tmp[-1]-2*tmp[0],2*tmp[-1]-tmp[0])
print(ans)

Fixed submission:
N,K=map(int,input().split(' '))
x = list(map(int,input().split(' ')))
ans = 2*(10**8)
if N==K:
    if x[-1]<0:
        print(-x[0])
    elif x[0]>0:
        print(x[-1])
    else:
        print(min(x[-1]-2*x[0],2*x[-1]-x[0]))
    exit()
for i in range(N-K+1):
    l,r=x[i],x[i+K-1]
    if l>0:
        ans = min(ans,r)
    elif r<0:
        ans = min(ans,-l)
    else:
        ans = min(ans,r-2*l,2*r-l)
print(ans)
Buggy python submission (verdict: Runtime Error):
S=input()
K=int(input())
tmp = 0
for i in S:
    if i=='1':
        tmp += 1
    else:
        break
if K >= tmp:
    print(1)
else:
    print(S[tmp])

Fixed submission:
S=input()
K=int(input())
tmp = 0
for i in S:
    if i=='1':
        tmp += 1
    else:
        break
if K <= tmp:
    print(1)
else:
    print(S[tmp])