Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
import numpy as np
N, M = map(int, input().split())

A = np.zeros((N,M))
for i in range(N):
    a = list(map(int, input().split()))
    a = a[1:]
    A[i, 0:len(a)] = a

for i in range(N):
    a = A[i]
    a = a[(a != 0) & (a < M)]
    if i == 0:
        s = set(list(a))
    else:
        _s = set(list(a))
    s &= _s

print(len(s))

Fixed submission:
import numpy as np
N, M = map(int, input().split())

A = np.zeros((N,M))
for i in range(N):
    a = list(map(int, input().split()))
    a = a[1:]
    A[i, 0:len(a)] = a

for i in range(N):
    a = A[i]
    a = a[(a != 0) & (a <= M)]
    if i == 0:
        s = set(list(a))
    else:
        _s = set(list(a))
        s &= _s

print(len(s))

Buggy python submission (verdict: Runtime Error):
import numpy as np
N, M = map(int, input().split())

A = np.zeros((N,M))
for i in range(N):
    a = list(map(int, input().split()))
    a = a[1:]
    A[i, 0:len(a)] = a

for i in range(N):
    a = A[i]
    a = a[(a != 0) & (a < M)]
    if i == 1:
        s = set(list(a))
    else:
        _s = set(list(a))
    s &= _s

print(len(s))

Fixed submission:
import numpy as np
N, M = map(int, input().split())

A = np.zeros((N,M))
for i in range(N):
    a = list(map(int, input().split()))
    a = a[1:]
    A[i, 0:len(a)] = a

for i in range(N):
    a = A[i]
    a = a[(a != 0) & (a <= M)]
    if i == 0:
        s = set(list(a))
    else:
        _s = set(list(a))
        s &= _s

print(len(s))

Buggy python submission (verdict: Runtime Error):
import numpy as np
N, M = map(int, input().split())

A = np.zeros((N,M))
for i in range(N):
    a = list(map(int, input().split()))
    a = a[1:]
    A[i, 0:len(a)] = a

for i in range(N):
    a = A[i]
    a = a[(a != 0) & (a < M)]
    print(a)
    if i == 1:
        s = set(list(a))
    else:
        _s = set(list(a))
    s &= _s

print(len(s))

Fixed submission:
import numpy as np
N, M = map(int, input().split())

A = np.zeros((N,M))
for i in range(N):
    a = list(map(int, input().split()))
    a = a[1:]
    A[i, 0:len(a)] = a

for i in range(N):
    a = A[i]
    a = a[(a != 0) & (a <= M)]
    if i == 0:
        s = set(list(a))
    else:
        _s = set(list(a))
        s &= _s

print(len(s))

Buggy python submission (verdict: Runtime Error):
import numpy as np
N, M = map(int, input().split())

A = np.zeros((N,M))
for i in range(N):
    a = list(map(int, input().split()))
    A[i, 0:len(a)] = a

A = A[(A != 0) & (A < M)]
len(np.unique(A))

Fixed submission:
import numpy as np
N, M = map(int, input().split())

A = np.zeros((N,M))
for i in range(N):
    a = list(map(int, input().split()))
    a = a[1:]
    A[i, 0:len(a)] = a

for i in range(N):
    a = A[i]
    a = a[(a != 0) & (a <= M)]
    if i == 0:
        s = set(list(a))
    else:
        _s = set(list(a))
        s &= _s

print(len(s))
Buggy python submission (verdict: Runtime Error):
N = int(input())
hs = np.array(list(map(int, input().split())))

i = 0
total_cost = 0

a = np.zeros(N, int)
a[0] = 0
a[1] = abs(hs[1] - hs[0])
for i in range(2, N):
    a[i] = min(a[max(i-2,0)] + abs(hs[i] - hs[max(i-2,0)]),
               a[max(i-1,0)] + abs(hs[i] - hs[max(i-1,0)]))
print(a[-1])


Fixed submission:
import numpy as np

N = int(input())
hs = np.array(list(map(int, input().split())))

i = 0
total_cost = 0

a = np.zeros(N, int)
a[0] = 0
a[1] = abs(hs[1] - hs[0])
for i in range(2, N):
    a[i] = min(a[max(i-2,0)] + abs(hs[i] - hs[max(i-2,0)]),
               a[max(i-1,0)] + abs(hs[i] - hs[max(i-1,0)]))
print(a[-1])
Buggy python submission (verdict: Runtime Error):
import numpy as np
a, b, x = map(int, input().split())
A = np.arange(a,b+1)
print(np.sum(A % x == 0))

Fixed submission:
import numpy as np
a, b, x = map(int, input().split())
print(b // x - (a-1) // x)
Buggy python submission (verdict: Runtime Error):
#!/usr/bin/env python3.4

# abc126_e

import sys

sys.setrecursionlimit(10**5)

def main():
    # input
    n, m = [int(s) for s in input().split()]
    to = [list() for _ in range(n)]
    for _ in range(m):
        x, y, _ = [int(s) for s in input().split()]
        x -= 1
        y -= 1
        to[x].append(y)
        to[y].append(x)
    # get ans
    colors = [None] * n
    counter = 0
    def dfs(cur, c):
        if colors[cur] != None:
            return
        colors[cur] = c
        for i in to[cur]:
            dfs(i, c)
    for i in range(n):
        if colors[i] == None:
            dfs(i, counter)
            counter += 1
    ans = counter
    # output
    print(ans)

if __name__ == '__main__':
    main()



Fixed submission:
#!/usr/bin/env python3.4

# abc126_e

import sys

sys.setrecursionlimit(10**5+4)

def main():
    # input
    n, m = [int(s) for s in input().split()]
    to = [list() for _ in range(n)]
    for _ in range(m):
        x, y, _ = [int(s) for s in input().split()]
        x -= 1
        y -= 1
        to[x].append(y)
        to[y].append(x)
    # get ans
    colors = [None] * n
    counter = 0
    def dfs(cur, c):
        if colors[cur] != None:
            return
        colors[cur] = c
        for i in to[cur]:
            dfs(i, c)
    for i in range(n):
        if colors[i] == None:
            dfs(i, counter)
            counter += 1
    ans = counter
    # output
    print(ans)

if __name__ == '__main__':
    main()
Buggy python submission (verdict: Time Limit Exceeded):
#!/usr/bin/env python3.4
# -*- coding: utf-8 -*-

# abc125_c
import fractions, functools, itertools

# input
n = int(input())
A = [int(s) for s in input().split()]
# get ans
x = A[0]
y = A[1]
def divisors(n):
     for i in range(1, n+1):
        if n%i == 0:
            yield i
ds = set(divisors(x)) | set(divisors(y))
def condition(d):
    not_div = (a%d != 0 for a in A)
    not_div = (1 if b else 0 for b in not_div)
    return sum(not_div) <= 1
ans = max(filter(condition, ds))
# output
print(ans)



Fixed submission:
#!/usr/bin/env python3.4
# -*- coding: utf-8 -*-

# abc125_c
import fractions, functools, itertools

# input
n = int(input())
A = [int(s) for s in input().split()]
# get ans
gcd = fractions.gcd
L = list(itertools.accumulate(A, gcd))
R = list(itertools.accumulate(A[::-1], gcd))
R = R[::-1]
L.append(0)
R.append(0)
gs = [gcd(L[i-1], R[i+1]) for i in range(n)]
ans = max(gs)
# output
print(ans)

Buggy python submission (verdict: Runtime Error):
#!/usr/bin/env python3.4
# -*- coding: utf-8 -*-

# abc125_c
import fractions, functools, itertools

# input
n = int(input())
A = [int(s) for s in input().split()]
# get ans
x = A[0]
y = A[1]
def divisors(n):
     for i in range(2, n):
        if n%i == 0:
            yield i
ds = set(divisors(x)) + set(divisors(y))
def condition(d):
    not_div = (a%d != 0 for a in A)
    not_div = (1 if b else 0 for b in not_div)
    return sum(not_div) <= 1
ans = max(filter(condition, ds))
# output
print(ans)



Fixed submission:
#!/usr/bin/env python3.4
# -*- coding: utf-8 -*-

# abc125_c
import fractions, functools, itertools

# input
n = int(input())
A = [int(s) for s in input().split()]
# get ans
gcd = fractions.gcd
L = list(itertools.accumulate(A, gcd))
R = list(itertools.accumulate(A[::-1], gcd))
R = R[::-1]
L.append(0)
R.append(0)
gs = [gcd(L[i-1], R[i+1]) for i in range(n)]
ans = max(gs)
# output
print(ans)

Buggy python submission (verdict: Runtime Error):
#!/usr/bin/env python3.4
# -*- coding: utf-8 -*-

# abc125_a
import fractions, functools, itertools

# input
n = int(input())
A = [int(s) for s in input().split()]
# get ans
def search_booby(B):
    b0 = [fractions.gcd(B[0], a) for a in B[1:]]
    b0.sort()
    return b0[1]
def gcd_list(l):
    return functools.reduce(fractions.gcd, l)
B = itertools.cycle(A)
Bs = itertools.tee(B, 2)
Bs = (list(itertools.islice(B, i, i+n)) for i, B in enumerate(Bs))
Bs = map(search_booby, Bs)
ans = max(Bs)
# output
print(ans)



Fixed submission:
#!/usr/bin/env python3.4
# -*- coding: utf-8 -*-

# abc125_c
import fractions, functools, itertools

# input
n = int(input())
A = [int(s) for s in input().split()]
# get ans
gcd = fractions.gcd
L = list(itertools.accumulate(A, gcd))
R = list(itertools.accumulate(A[::-1], gcd))
R = R[::-1]
L.append(0)
R.append(0)
gs = [gcd(L[i-1], R[i+1]) for i in range(n)]
ans = max(gs)
# output
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
#!/usr/bin/env python3.4
# -*- coding: utf-8 -*-

# abc124_d

# input
n, k = [int(s) for s in input().split()]
S = input()
# get ans
node = [len(s) for s in S.split('0')]
node = [s for i, s in enumerate(node) if not (s==0 and i!=0 and i!=len(node)-1)]
arch = [len(s) for s in S.split('1')]
arch = list(filter(int, arch))
k = min(k, len(arch))
sls = [(i,i+k) for i in range(len(arch)-k+1)]
m = (sum(arch[i:j])+sum(node[i:j+1]) for i, j in sls)
ans = max(m)
# output
# print(node)
# print(arch)
print(ans)


Fixed submission:
#!/usr/bin/env python3.4
# -*- coding: utf-8 -*-

# abc124_d

# input
n, k = [int(s) for s in input().split()]
S = input()
# get ans
node = [len(s) for s in S.split('0')]
node = [s for i, s in enumerate(node) if not (s==0 and i!=0 and i!=len(node)-1)]
arch = [len(s) for s in S.split('1')]
arch = list(filter(int, arch))
from itertools import chain
flatten = chain.from_iterable
xs = list(flatten(zip(node, arch))) + node[-1:]
l = len(xs)
sumlist = [None]*(l+2)
sumlist[-1] = 0
for i in range(l):
    sumlist[i] = sumlist[i-1] + xs[i]
def get_sum(f, n):
    f = min(f, l)
    t = f+n
    t = min(t, l)
    return sumlist[t-1] - sumlist[f-1]
def get_ans():
    for i in range(l//2+1):
        yield get_sum(i*2, k*2+1)
ans = max(get_ans())
# output
# print(node)
# print(arch)
# print(xs)
# print(sumlist)
# print(get_sum(0, 2))
# print(list(get_ans()))
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
#!/usr/bin/env python3.4
# -*- coding: utf-8 -*-

# abc124_d

# input
n, k = [int(s) for s in input().split()]
S = input()
# get ans
node = [len(s) for s in S.split('0')]
node = [s for i, s in enumerate(node) if not (s==0 and i!=0 and i!=len(node)-1)]
arch = [len(s) for s in S.split('1')]
arch = list(filter(int, arch))
def window(iterable, size):
    #TODO size = min(size, len(iterable))
    from itertools import tee
    iters = tee(iterable, size)
    for i in range(1, size):
        for each in iters[i:]:
            next(each, None)
    return zip(*iters)
k = min(k, len(arch))
sls = [(i,i+k) for i in range(len(arch)-k+1)]
m = (sum(arch[i:j]+node[i:j+1]) for i, j in sls)
ans = max(m)
# output
# print(node)
# print(arch)
print(ans)


Fixed submission:
#!/usr/bin/env python3.4
# -*- coding: utf-8 -*-

# abc124_d

# input
n, k = [int(s) for s in input().split()]
S = input()
# get ans
node = [len(s) for s in S.split('0')]
node = [s for i, s in enumerate(node) if not (s==0 and i!=0 and i!=len(node)-1)]
arch = [len(s) for s in S.split('1')]
arch = list(filter(int, arch))
from itertools import chain
flatten = chain.from_iterable
xs = list(flatten(zip(node, arch))) + node[-1:]
l = len(xs)
sumlist = [None]*(l+2)
sumlist[-1] = 0
for i in range(l):
    sumlist[i] = sumlist[i-1] + xs[i]
def get_sum(f, n):
    f = min(f, l)
    t = f+n
    t = min(t, l)
    return sumlist[t-1] - sumlist[f-1]
def get_ans():
    for i in range(l//2+1):
        yield get_sum(i*2, k*2+1)
ans = max(get_ans())
# output
# print(node)
# print(arch)
# print(xs)
# print(sumlist)
# print(get_sum(0, 2))
# print(list(get_ans()))
print(ans)
Buggy python submission (verdict: Runtime Error):
n = int(input())

info = [[int(x) for x in input().split()] for _ in range(n)]

def height(point, info):
    cx, cy = point[0], point[1]
    ch = None
    for i,p in enumerate(info):
        x, y, h= p[0], p[1], p[2]
        tmp = abs(cx-x) + abs(cy-y) + h
        if ch == None:
            ch = tmp
        else:
            if ch != tmp:
                return None
                break
    return ch

flag = False
ans = None
for x in range(101):
    if flag:
        break
    for y in range(101):
        if flag:
            break
        point = (x,y)
        t = height(point, info)
        if t != None:
            flag = True
            ans = [x,y,t]

print(' '.join(map(str, ans)))

Fixed submission:
n = int(input())

info = [[int(x) for x in input().split()] for _ in range(n)]

def height(point, info):
    cx, cy = point[0], point[1]
    ch = None
    theo_max = float('inf')
    for i,p in enumerate(info):
        x, y, h= p[0], p[1], p[2]
        tmp = abs(cx-x) + abs(cy-y) + h
        if h == 0:
            theo_max = min(theo_max, tmp)
            if ch:
                if theo_max < ch:
                    return None
                    break
        else:
            if not ch:
                ch = tmp
                if theo_max < ch:
                    return None
                    break
            else:
                if ch != tmp:
                    return None
                    break
                if theo_max < ch:
                    return None
                    break
    return ch

t = None
ans = None
for x in range(101):
    if t:
        break
    for y in range(101):
        if t:
            break
        point = (x,y)
        t = height(point, info)
        if t :
            ans = [x,y,t]

print(' '.join(map(str, ans)))
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = [int(x) for x in input().split()]
for i in range(n):
    a[i] -= i+1

def hoge(b):
    v = 0
    for x in a:
        v += abs(x-b)
    return v

tmp = float('inf')
for x in set(a):
    if hoge(x) < tmp:
        tmp = hoge(x)

print(tmp)

Fixed submission:
n = int(input())
a = [int(x) for x in input().split()]
for i in range(n):
    a[i] -= i+1

#中央値を求める
a.sort()
if len(a) % 2 == 0:
    c = (a[len(a)//2] + a[len(a)//2-1]) // 2
else:
    c = a[len(a)//2]

def hoge(b):
    v = 0
    for x in a:
        v += abs(x-b)
    return v

print(hoge(c))

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = [int(x) for x in input().split()]
for i in range(n):
    a[i] -= i+1

def hoge(b):
    t = [abs(x-b) for x in a]
    return sum(t)

tmp = float('inf')
for x in a:
    if hoge(x) < tmp:
        tmp = hoge(x)

print(tmp)

Fixed submission:
n = int(input())
a = [int(x) for x in input().split()]
for i in range(n):
    a[i] -= i+1

#中央値を求める
a.sort()
if len(a) % 2 == 0:
    c = (a[len(a)//2] + a[len(a)//2-1]) // 2
else:
    c = a[len(a)//2]

def hoge(b):
    v = 0
    for x in a:
        v += abs(x-b)
    return v

print(hoge(c))
Buggy python submission (verdict: Runtime Error):
import math

n = int(input())

ans = 0

while True:
    a = int(math.log(n,9))
    b = int(math.log(n,6))
    if a == b == 0:
        ans += n
        break
    else:
        if 9 ** a >= 6 ** b:
            n -= 9 ** a
            ans += 1
        else:
            n -= 6 ** b
            ans += 1

print(ans)

Fixed submission:
import math

n = int(input())

dp = [float('inf') for _ in range(n+1)]
dp[0] = 0
dp[1] = 1

for i in range(1,n+1):
    tmp = float('inf')
    tmp6, tmp9 = 1,1
    while tmp6 <= i:
        if dp[i-tmp6]+1 < tmp:
            tmp = dp[i-tmp6] + 1
        tmp6 *= 6
    while tmp9 <= i:
        if dp[i-tmp9] + 1 < tmp:
            tmp = dp[i-tmp9] + 1
        tmp9 *= 9
    dp[i] = tmp

'''
    for j in range(int(math.log(i,6))+1):
        if dp[i-6**j]+1 < tmp:
            tmp = dp[i-6**j] + 1
    for j in range(int(math.log(i,9))+1):
        if dp[i-9**j]+1 < tmp:
            tmp = dp[i-9**j]+1
'''
    #dp[i] = tmp

print(dp[n])
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())

a = [int(x) for x in input().split()]

for i in range(1,n):
    a[i] += a[i-1]

a = [0] + a

ans = 0

for i in range(1,n+1):
    for j in range(i):
        if a[i] == a[j]:
            ans += 1

print(ans)

Fixed submission:
from collections import defaultdict

n = int(input())

a = [0] + [int(x) for x in input().split()]

d = defaultdict(int)

tmp = 0

for x in a:
    tmp += x
    d[tmp] += 1

ans = 0

for k,v in d.items():
    if v >= 2:
        ans += v * (v - 1) // 2

print(ans)

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

a = [int(x) for x in input().split()]

for i in range(1,n):
    a[i] += a[i-1]

a = [0] + a

ans = 0

for i in range(1,n+1):
    for j in range(i):
        if a[i] - a[j] == 0:
            ans += 1

print(ans)

Fixed submission:
from collections import defaultdict

n = int(input())

a = [0] + [int(x) for x in input().split()]

d = defaultdict(int)

tmp = 0

for x in a:
    tmp += x
    d[tmp] += 1

ans = 0

for k,v in d.items():
    if v >= 2:
        ans += v * (v - 1) // 2

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())

s = []
for _ in range(n):
    s.append(input())
s = s + s

def check(a):
    flag = True
    n = len(a)
    for i in range(n):
        for j in range(n):
            if a[i][j] == a[j][i]:
                pass
            else:
                flag = False
    return flag

ans = 0
for i in range(n):
    if check(s[i:i+n]):
        ans += n
    else:
        pass
print(ans)

Fixed submission:
n = int(input())

s = []
for _ in range(n):
    s.append(input())
s = s + s

def check(a):
    flag = True
    n = len(a)
    i, j_start = 0, 1
    while flag:
        if i == n - 1:
            break
        for j in range(j_start, n):
            if a[i][j] != a[j][i]:
                flag = False
        i += 1
        j_start += 1
    return flag

ans = 0
for i in range(n):
    if check(s[i:i+n]):
        ans += n
    else:
        pass
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
def magic(l,r,d,m):
    ans = 0
    count = 0
    limit = r - l
    while count < limit:
        a = m[l + count]
        b = m[l + count + d]
        ans += abs(a[0] - b[0]) + abs(a[1] - b[1])
        count += d
    return ans

h, w, d = map(int, input().split())

m = [0 for _ in range(h*w+1)]

for i in range(h):
    a = [int(x) for x in input().split()]
    for j,k in enumerate(a):
        m[k] = (i+1,j+1)

q = int(input())

ans = []

for _ in range(q):
    l, r = map(int,input().split())
    ans.append(magic(l,r,d,m))

for x in ans:
    print(x)

Fixed submission:
def dist(p1,p2):
    return abs(p1[0] - p2[0]) + abs(p1[1] - p2[1])

h,w,d = map(int, input().split())

m = [0 for _ in range(h*w + 1)]
acm = [0 for _ in range(h*w + 1)]
ans = []

for i in range(h):
    a = [int(x) for x in input().split()]
    for j,k in enumerate(a):
        m[k] = (i,j)

for i in range(1, d+1):
    count = i
    while count <= h * w:
        if count <= d:
            pass
        else:
            acm[count] = dist(m[count],m[count-d]) + acm[count-d]
        count += d

q = int(input())

for i in range(q):
    l,r = map(int, input().split())
    ans.append(acm[r] - acm[l])

for x in ans:
    print(x)
Buggy python submission (verdict: Runtime Error):
n = input()

a = n[0]
b = n[1:]

if (int(b)+1) % (10 ** len(b)) == 0:
    flag = True
else:
    flag = False

if flag:
    ans = int(a) + 9 * len(b)
else:
    ans = int(a) - 1 + 9 * len(b)

print(ans)

Fixed submission:
n = input()

a = n[0]

if len(n) > 1:
    b = n[1:]
    if (int(b)+1) % (10 ** len(b)) == 0:
        flag = True
    else:
        flag = False
else:
    b = ''
    flag = True

if flag:
    ans = int(a) + 9 * len(b)
else:
    ans = int(a) - 1 + 9 * len(b)

print(ans)
Buggy python submission (verdict: Runtime Error):
import numpy as np

l = []

for _ in range(3):
    a = [int(x) for x in input().split()]
    l.append(a)

l = np.array(l)

def check(m):
    a = []
    for i in range(3):
        b,c = m[i,0] - m[i,1], m[i,1] - m[i,2]
        m.append((b,c))
    if a[0] != a[1] or a[1] != a[2]:
        return False
    else:
        return True

if check(l) and check(np.transpose(l)):
    print('Yes')
else:
    print('No')

Fixed submission:
l = []

for _ in range(3):
    l.append([int(x) for x in input().split()])

flag = True

v,h = [],[]

for i in range(3):
    a = l[i]
    b,c = a[0] - a[1], a[1] - a[2]
    v.append([b,c])

if v[0] != v[1] or v[1] != v[2]:
    flag = False

for i in range(3):
    a = [l[0][i], l[1][i], l[2][i]]
    b,c = a[0] - a[1], a[1] - a[2]
    h.append([b,c])

if h[0] != h[1] or h[1] != h[2]:
    flag = False

if flag:
    print('Yes')
else:
    print('No')
Buggy python submission (verdict: Time Limit Exceeded):
h,w = map(int, input().split())

smap = [list(input()) for _ in range(h)]
cmap = [[float('inf') for _ in range(w)] for _ in range(h)]
queue = [(0,0)]
l = [(1,0), (-1,0), (0,1), (0,-1)]

initial_whites = 0

for x in smap:
    for y in x:
        if y == '.':
            initial_whites += 1

cmap[0][0] = 0

while queue:
    v = queue.pop(0)
    smap[v[0]][v[1]] = '#'
    for x in l:
        y = (v[0]+x[0], v[1]+x[1])
        if 0 <= y[0] <= h-1 and 0 <= y[1] <= w-1:
            if smap[y[0]][y[1]] == '.':
                cmap[y[0]][y[1]] = cmap[v[0]][v[1]] + 1
                queue.append(y)
            else:
                pass
        else:
            pass


if cmap[h-1][w-1] == float('inf'):
    print(-1)
else:
    print(initial_whites - cmap[h-1][w-1] - 1)

Fixed submission:
h,w = map(int, input().split())

smap = []
for _ in range(h):
    s = input()
    ss = []
    for i in range(w):
        ss.append(s[i])
    smap.append(ss)
cmap = [[float('inf') for _ in range(w)] for _ in range(h)]
queue = [(0,0)]
l = [(1,0), (-1,0), (0,1), (0,-1)]

initial_whites = 0

for x in smap:
    for y in x:
        if y == '.':
            initial_whites += 1

cmap[0][0] = 0

while queue:
    v = queue.pop(0)
    smap[v[0]][v[1]] = '#'
    for x in l:
        y = (v[0]+x[0], v[1]+x[1])
        if 0 <= y[0] <= h-1 and 0 <= y[1] <= w-1:
            if smap[y[0]][y[1]] == '.':
                smap[y[0]][y[1]] = '#'
                cmap[y[0]][y[1]] = cmap[v[0]][v[1]] + 1
                queue.append(y)
            else:
                pass
        else:
            pass


if cmap[h-1][w-1] == float('inf'):
    print(-1)
else:
    print(initial_whites - cmap[h-1][w-1] - 1)
Buggy python submission (verdict: Runtime Error):
x,y = [int(x) for x in input().split()]

count = 1

while True:
    if x * 2 <= y:
        x = x * 2
        count += 1
    else:
	break

print(count)

Fixed submission:
x,y = [int(x) for x in input().split()]

flag = True
count = 1

while flag:
    if x * 2 <= y:
        x = x * 2
        count += 1
        continue
    else:
        flag = False

print(count)
Buggy python submission (verdict: Runtime Error):
s = input()

l = len(s)

for i,x in enumerate(s):
    if i == 0:
        pass
    else:
        if x != s[i-1]:
            count += 1
        else:
            if count % 2 == 0:
                a = count -1
                if a <= l:
                    l = a
            else:
                a = count
                if a <= l:
                    l = a
            count = 0

print((count+1)//2)

Fixed submission:
s = input()

l = len(s)

t = l

for i,x in enumerate(s):
    if i == 0:
        pass
    else:
        if x != s[i-1]:
            a = max(i,l-i)
            t = min(t,a)

print(t)
Buggy python submission (verdict: Time Limit Exceeded):
n, k = [int(x) for x in input().split()]

flowers = []

for _ in range(n):
    tmp = [int(x) for x in input().split()]
    flowers.append(tmp)

def aaa(p, l):
    count = 0
    for x in l:
        w, d = x[0], x[1]
        if p - w < 0:
            pass
        else:
            count += (p - w) // d + 1
    return count

flag = True
left, right = 1, 2 * (10 ** 18)
ans = 0

while flag:
    point = (right + left) // 2
    if point == left:
        flag = False
        if aaa(left, flowers) >= k:
            ans = left
        else:
            ans = right
    else:
        if aaa(point, flowers) < k:
            left = point
        else:
            right = point

print(ans)

Fixed submission:
n, k = [int(x) for x in input().split()]

flowers = []

for _ in range(n):
    tmp = [int(x) for x in input().split()]
    flowers.append(tmp)

def aaa(p, l):
    count = 0
    for x in l:
        w, d = x[0], x[1]
        if p - w < 0:
            pass
        else:
            count += (p - w) // d + 1
    return count

flag = True
left, right = 1, 10 ** 19
ans = 0

while flag:
    point = (right + left) // 2
    if point == left:
        flag = False
        if aaa(left, flowers) >= k:
            ans = left
        else:
            ans = right
    else:
        if aaa(point, flowers) < k:
            left = point
        else:
            right = point

print(ans)