Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
h, w = map(int, input().split())
grid = [0]*h
for i in range(h):
  grid[i] = input()

counter = [[[0, 0] for j in range(w)] for i in range(h)]
ans = 0
for i in range(h):
  for j in range(w):
    if grid[i][j] == "#":
      continue
    if i == 0 or (i != 0 and grid[i-1][j] == "#"):
      k = 0
      while i+k < h and grid[i+k][j] == ".":
        k += 1
      counter[i][j][0] = k-1
    else:
      counter[i][j][0] = counter[i-1][j][0]
    if j == 0 or (j != 0 and grid[i][j-1] == "#"):
      k = 0
      while j+k < w and grid[i][j+k] == ".":
        k += 1
      counter[i][j][1] = k-1
    else:
      counter[i][j][1] = counter[i][j-1][1]
    if ans < counter[i][j][0]+counter[i][j][1]:
      ans = counter[i][j][0]+counter[i][j][1]
print(ans+1)

Fixed submission:
h, w = map(int, input().split())
grid = [0]*h
for i in range(h):
  grid[i] = input()

counter = [[[0, 0] for j in range(w)] for i in range(h)]
ans = 0
for i in range(h):
  for j in range(w):
    if grid[i][j] == "#":
      continue
    if i == 0 or (i != 0 and grid[i-1][j] == "#"):
      k = 0
      while i+k < h and grid[i+k][j] == ".":
        k += 1
      counter[i][j][0] = k-1
    else:
      counter[i][j][0] = counter[i-1][j][0]
    if j == 0 or (j != 0 and grid[i][j-1] == "#"):
      k = 0
      while j+k < w and grid[i][j+k] == ".":
        k += 1
      counter[i][j][1] = k-1
    else:
      counter[i][j][1] = counter[i][j-1][1]
    if ans < counter[i][j][0]+counter[i][j][1]:
      ans = counter[i][j][0]+counter[i][j][1]
print(ans+1)

Buggy python submission (verdict: Runtime Error):
h, w = map(int, input().split())
grid = [0]*n
for i in range(h):
  grid[i] = input()

counter = [[[0, 0]]*w for i in range(h)]
ans = 0
for i in range(h):
  for j in range(w):
    if grid[i][j] == "#":
      continue
    if i == 0 or grid[i-1][j] == "#":
      k = 0
      while grid[i+k][j] == "." and i+k < n:
        k += 1
      counter[i][j][0] = k
    else:
      counter[i][j][0] = counter[i-1][j][0]
    if j == 0 or grid[i][j-1] == "#":
      k = 0
      while grid[i][j+k] == "." and j+k < n:
        k += 1
      counter[i][j][1] = k
    else:
      counter[i][j][1] = counter[i][j-1][1]
    if ans < counter[i][j][0]+counter[i][j][1]:
      ans = counter[i][j][0]+counter[i][j][1]
print(ans+1)

Fixed submission:
h, w = map(int, input().split())
grid = [0]*h
for i in range(h):
  grid[i] = input()

counter = [[[0, 0] for j in range(w)] for i in range(h)]
ans = 0
for i in range(h):
  for j in range(w):
    if grid[i][j] == "#":
      continue
    if i == 0 or (i != 0 and grid[i-1][j] == "#"):
      k = 0
      while i+k < h and grid[i+k][j] == ".":
        k += 1
      counter[i][j][0] = k-1
    else:
      counter[i][j][0] = counter[i-1][j][0]
    if j == 0 or (j != 0 and grid[i][j-1] == "#"):
      k = 0
      while j+k < w and grid[i][j+k] == ".":
        k += 1
      counter[i][j][1] = k-1
    else:
      counter[i][j][1] = counter[i][j-1][1]
    if ans < counter[i][j][0]+counter[i][j][1]:
      ans = counter[i][j][0]+counter[i][j][1]
print(ans+1)
Buggy python submission (verdict: Runtime Error):
import sys
from heapq import *
input = sys.stdin.readline

def main():
    n, q = map(int, input().split())
    
    key = []
    for i in range(n):
        s, t, x = map(int, input().split())
        l, r = max(0, s-x), max(0, t-x)
        key.append((l, 1, x))
        key.append((r, -1, x))

    key.sort()
    judge = []
    now = set()
    already = dict()
    
    index = 0
    ans = -1
    for i in range(q):
        d = int(input())
        for i in range(index, 2*n):
            s, j, x = key[i]
            if s > d:
                index = i
                break
            if j == 1:
                heappush(judge, x)
                now.add(x)
            else:
                now.remove(x)
                if x in already:
                    already[x] += 1
                else:
                    already[x] = 1
                    
                    
        while judge:
            if judge[0] in already and already[judge[0]] > 0:
                already[judge[0]] -= 1
                heappop(judge)
            else:
                break
        if judge:
            ans = judge[0]
        else:
            ans = -1      
            
        print(ans)

    
if __name__ == "__main__":
    main()




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

k = 3 * a + p
print(k // 2)
Buggy python submission (verdict: Runtime Error):
N = int(input())
s = {}
for _, i in zip(range(N), range(N)):
    p, q = map(str, input().split)
    s[q] = i
    
s.sort()

for i in range(N):
    print(s[i])aN = int(input())
j = []
for _, i in zip(range(N), range(N)):
    p, q = map(str, input().split())
    j.append(int(q))

for i in range(N):
    p = max(j)
    q = j.index(p)
    print(q+1)
    j[q] = 0

Fixed submission:
n = int(input())
key = []
for i in range(n):
  flag = True
  s, p = map(str, input().split())
  for j in range(len(key)):
    if key[j][0] == s:
      key[j][1].append([int(p), i+1])
      flag = False
      break
  if flag:
    key.append([s, [[int(p), i+1]]])
key.sort()
for i in range(len(key)):
  key[i][1].sort(reverse=True)
  for j in range(len(key[i][1])):
    print(key[i][1][j][1])
Buggy python submission (verdict: Time Limit Exceeded):
n, m = map(int, input().split())
ans_set = {x for x in range(1, n+1)}

for _ in range(m):
    a, b = map(int, input().split())
    sub_set = {x for x in range(a, b+1)}
    ans_set = ans_set & sub_set
    
ans = len(ans_set)
print(ans)

Fixed submission:
n, m = map(int, input().split())
l = [0]*m
r = [0]*m

for i in range(m):
    l[i], r[i] = map(int, input().split())
    

    
ans = min(r) - max(l)
if ans >= 0 :
    print(ans+1)
else:
    print(0)
Buggy python submission (verdict: Time Limit Exceeded):
n, m = map(int, input().split())
a = [int(x) for x in input().split()]
for _ in range(m):
    b, c = map(int, input().split())
    k = [c]*b
    a = a + k
a.sort()
a = a[-n::]
ans = sum(a)
print(ans)

Fixed submission:
n, m = map(int, input().split())
a = [int(x) for x in input().split()]
p = [(a[i], 1) for i in range(n)]

for i in range(m):
    b, c = map(int, input().split())
    p.append((c, b))
    
p.sort()
p.reverse()
ans, count = 0, n
for (s, t) in p:
    k = min(count, t)
    ans += s * k
    count -= t
    if count <= 0:
        break
    
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n, m = map(int, input().split())
a = [int(x) for x in input().split()]
for _ in range(m):
    b, c = map(int, input().split())
    k = [c]*b
    a = a + k
    a.sort()
    a = a[-n::]
ans = sum(a)
print(ans)

Fixed submission:
n, m = map(int, input().split())
a = [int(x) for x in input().split()]
p = [(a[i], 1) for i in range(n)]

for i in range(m):
    b, c = map(int, input().split())
    p.append((c, b))
    
p.sort()
p.reverse()
ans, count = 0, n
for (s, t) in p:
    k = min(count, t)
    ans += s * k
    count -= t
    if count <= 0:
        break
    
print(ans)
Buggy python submission (verdict: Runtime Error):
s = int(input())
a, b = s//100, s%100
boos = int(input())
a, b = s//100, s%100
p = bool(1 <= a <= 12)
q = bool(1 <= b <= 12)
if p & q:
    print("AMBIGUOUS")
elif p:
    print("MMYY")
elif q:
    print("YYMM")
else:
    print("NA")

Fixed submission:
s = int(input())
a, b = s//100, s%100
p = bool(1 <= a <= 12)
q = bool(1 <= b <= 12)
if p & q:
    print("AMBIGUOUS")
elif p:
    print("MMYY")
elif q:
    print("YYMM")
else:
    print("NA")
Buggy python submission (verdict: Runtime Error):
m, k = map(int, input().split())
if k >= 2**m:
  print(-1)
elif m == 0:
  print(0, 0)
elif m == 0:
  if k == 0:
    print(0, 0, 1, 1)
  else:
    print(-1)
else:
  for i in range(2**n):
    if i == k:
      continue
    print(i, end=" ")
  print(k, end=" ")
  for i in range(2**n-1, -1, -1):
    if i == k:
      continue
    print(i, end=" ")
  print(k)

Fixed submission:
m, k = map(int, input().split())
if k >= 2**m:
  print(-1)
elif m == 0:
  print(0, 0)
elif m == 1:
  if k == 0:
    print(0, 0, 1, 1)
  else:
    print(-1)
else:
  for i in range(2**m):
    if i == k:
      continue
    print(i, end=" ")
  print(k, end=" ")
  for i in range(2**m-1, -1, -1):
    if i == k:
      continue
    print(i, end=" ")
  print(k)
Buggy python submission (verdict: Time Limit Exceeded):
import sys
from collections import deque
input = sys.stdin.readline

def main():
    h, w = map(int, input().split())

    a = [input()[:-1] for i in range(h)]

    already = [[False]*w for i in range(h)]
    key = deque([])
    for i in range(h):
        for j in range(w):
            if a[i][j] == '#':
                if not key:
                    judge = (i, j)
                key.append((i, j))
                already[i][j] = True
    
    ans = -1
    way = [(-1, 0), (1, 0), (0, 1), (0, -1)]
    change = False
    while key:
        value = key.popleft()
        if value == judge:
            ans += 1
            judge = value
            change = True
        i, j = value
        for x, y in way:
            p, q = i+x, j+y
            if 0 <= p < h and 0 <= q < w  and not already[p][q]:
                already[p][q] = True
                key.append((p, q))
                if change:
                    judge = (p, q)
                    change = False

    print(ans)







    
if __name__ == "__main__":
    main()



Fixed submission:
import sys
from collections import deque
input = sys.stdin.readline

def main():
    h, w = map(int, input().split())

    a = [input()[:-1] for i in range(h)]

    already = [[False]*w for i in range(h)]
    key = deque([])
    for i in range(h):
        for j in range(w):
            if a[i][j] == '#':
                if not key:
                    judge = (i, j)
                key.append((i, j))
                already[i][j] = True
    
    ans = -1
    way = [(-1, 0), (1, 0), (0, 1), (0, -1)]
    change = False
    while key:
        value = key.popleft()
        if value == judge:
            ans += 1
            judge = value
            change = True
        i, j = value
        for x, y in way:
            p, q = i+x, j+y
            if 0 <= p < h and 0 <= q < w  and not already[p][q]:
                already[p][q] = True
                key.append((p, q))
                if change:
                    judge = (p, q)
                    change = False

    print(ans)







    
if __name__ == "__main__":
    main()
Buggy python submission (verdict: Runtime Error):
from math import gcd
n = int(input())
a = [int(x) for x in input().split()]

if n == 2:
    print(max(a))
else:
    x, y, z = a[0], a[1], a[2]
    p, q, r = gcd(x, y), gcd(y, z), gcd(z, x)
    gcd_max = max(p, q, r)
    if gcd_max == p:
        without = z
    elif gcd_max == q:
        without = x
    else:
        without = y

    k = gcd(gcd_max, without)   
    for i in range(3, n):
        a_i = a[i]
        if a_i % gcd_max != 0:
            l = gcd(gcd_max, a_i)
            if l >= k:
                gcd_max = l
            else:
                gcd_max = k
                without = a_i
        k = gcd(k, a_i)
    print(gcd_max)

Fixed submission:
def gcd(p, q):
    if p < q:
        p, q = q, p
    while q > 0:
        p, q = q, p%q
    return p

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

if n == 2:
    print(max(a))
else:
    x, y, z = a[0], a[1], a[2]
    p, q, r = gcd(x, y), gcd(y, z), gcd(z, x)
    gcd_max = max(p, q, r)
    if gcd_max == p:
        without = z
    elif gcd_max == q:
        without = x
    else:
        without = y

    k = gcd(gcd_max, without)   
    for i in range(3, n):
        a_i = a[i]
        if a_i % gcd_max != 0:
            l = gcd(gcd_max, a_i)
            if l >= k:
                gcd_max = l
            else:
                gcd_max = k
                without = a_i
        k = gcd(k, a_i)
    print(gcd_max)

Buggy python submission (verdict: Runtime Error):
from math import gcd
n = int(input())
a = [int(x) for x in input().split()]

if n == 2:
    print(max(a))
else:
    
    x, y, z = a[0], a[1], a[2]
    p, q, r = gcd(x, y), gcd(y, z), gcd(z, x)
    gcd_max = max(p, q, r)
    if gcd_max == p:
        without = z
    elif gcd_max == q:
        without = x
    else:
        without = y

    k = gcd(gcd_max, without)   
    for i in range(3, n):
        a_i = a[i]
        if a_i % gcd_max != 0:
            l = gcd(gcd_max, a_i)
            if l >= k:
                gcd_max = l
            else:
                gcd_max = k
                without = a_i
        k = gcd(k, a_i)
print(gcd_max)

Fixed submission:
def gcd(p, q):
    if p < q:
        p, q = q, p
    while q > 0:
        p, q = q, p%q
    return p

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

if n == 2:
    print(max(a))
else:
    x, y, z = a[0], a[1], a[2]
    p, q, r = gcd(x, y), gcd(y, z), gcd(z, x)
    gcd_max = max(p, q, r)
    if gcd_max == p:
        without = z
    elif gcd_max == q:
        without = x
    else:
        without = y

    k = gcd(gcd_max, without)   
    for i in range(3, n):
        a_i = a[i]
        if a_i % gcd_max != 0:
            l = gcd(gcd_max, a_i)
            if l >= k:
                gcd_max = l
            else:
                gcd_max = k
                without = a_i
        k = gcd(k, a_i)
    print(gcd_max)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = [int(x) for x in input().split()]
for i in range(n):
    count = len([x for x in filter(lambda n: n<0, a)])
b = [x for x in map(abs, a)]

p = min(b)
q = sum(b)
if count % 2 != 0:
    ans = q - 2 * p
else:
    ans = q
print(ans)

Fixed submission:
n = int(input())
a = [int(x) for x in input().split()]
count = len([x for x in filter(lambda n: n<0, a)])
b = [x for x in map(abs, a)]

p = min(b)
q = sum(b)
if count % 2 != 0:
    ans = q - 2 * p
else:
    ans = q
print(ans)
Buggy python submission (verdict: Runtime Error):
def main():
    n, k = map(int, input().split())
    s = input()
    sub = []
    count = 1
    for i in range(1, n):
        if s[i] == s[i-1]:
            count += 1
        else:
            sub.append(count)
            count = 1
    sub.append(count)
    
    key = s[0]
    
    if key:
        if 2*k+1 >= len(sub):
            a = n
        else:
            a = sum(sub[:(2*k+1)])
            key = 0
    else:
        if 2*k >= len(sub):
            a = n
        else:
            a = sum(sub[:(2*k)])
            key = 0
    ans = a
    flag = False
    for i in range(len(sub)):
        a -= sub[i]
        if key:
            if i+2*k == len(sub)-1:
                a += sub[i+2*k]
                flag = True
            key = 0
        else:
            if i+2*k == len(sub)-1:
                a += sub[i+2*k]
                flag = True
            else:
                a += sub[i+2*k]+sub[i+1+2*k]
            if i+2*k == len(sub)-2:
                flag = True
            key = 1
            
        if a > ans:
            ans = a
        if flag:
            break
    
    print(ans)

if __name__ == "__main__":
    main()

Fixed submission:
n, k = map(int, input().split())
s = input()

key = [0]
for i in range(1, n):
  if s[i] != s[i-1]:
    key.append(i)
key.append(n)

m, r = 0, len(key)-1
ans = 0
while True:
  if m == 0 and s[0] == "0":
    p = m+2*k
    if ans < key[min([p, r])] - key[m]:
      ans = key[min([p, r])] - key[m]
    m += 1
  else:
    p = m+2*k+1
    if ans < key[min([p, r])] - key[m]:
      ans = key[min([p, r])] - key[m]
    m += 2
  if p >= r:
    break

print(ans)

Buggy python submission (verdict: Runtime Error):
n, k = map(int, input().split())
s = str(input())

if s[0] == "1":
    s_first = 1
else:
    s_first = 0

S_count = []
t = 1
for i in range(n-1):
    if s[i] == s[i+1]:
        t += 1
    else:
        S_count.append(t)
        t = 1
S_count.append(t)

t = len(S_count)
ans_list = []
if n-2*k <= 0:
    print(len(s))
else:    
    if s_first == 1:
        for i in range(t-2*k):
            ans_list.append(sum(S_count[i:i+2*k+1]))
    else:
        for i in range(t-2*k):
            ans_list.append(sum(S_count[i:i+2*k]))
    print(S_count)
    print(ans_list)
    ans = max(ans_list)
    print(ans)

Fixed submission:
n, k = map(int, input().split())
s = input()

key = [0]
for i in range(1, n):
  if s[i] != s[i-1]:
    key.append(i)
key.append(n)

m, r = 0, len(key)-1
ans = 0
while True:
  if m == 0 and s[0] == "0":
    p = m+2*k
    if ans < key[min([p, r])] - key[m]:
      ans = key[min([p, r])] - key[m]
    m += 1
  else:
    p = m+2*k+1
    if ans < key[min([p, r])] - key[m]:
      ans = key[min([p, r])] - key[m]
    m += 2
  if p >= r:
    break

print(ans)
Buggy python submission (verdict: Runtime Error):
x, y, z, k = map(int, input().split())
a = [int(x) for x in input().split()]
b = [int(x) for x in input().split()]
c = [int(x) for x in input().split()]
a.sort(reverse=True)
b.sort(reverse=True)
c.sort(reverse=True)
ans_list = []
for i in a:
    for j in b:
        ans_list.append(i+j)
ans_list.sort(reverse=True)
ans_list = ans_list[:min(3001, x*y*z+1)]
ans_list_2 = []
for i in ans_list:
    for j in c:
        ans_list_2.append(i+j)
ans_list_2.sort(reverse=True)
for i in range(k):
    print(ans_list_2[i])

Fixed submission:
antena = []
for _ in range(5):
    antena.append(int(input()))
    
k = int(input())

if k >= antena[-1]-antena[0]:
    print("Yay!")
else:
    print(":(")
Buggy python submission (verdict: Runtime Error):
s = input()
k = 0
ans = 0
for i in range(s):
    if s[i] == "A" or "G" or "C" or "T":
        k += 1
    else:
        ans = max(ans, k)
        k = 0
ans = max(ans, k)
print(ans)

Fixed submission:
s = input()
k = 0
ans = 0
for i in range(len(s)):
    if s[i] == "A" or s[i] == "G" or s[i] == "C" or s[i] == "T":
        k += 1
    else:
        ans = max(ans, k)
        k = 0

ans = max(ans, k)
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n, q = map(int, input().split())
s = input()
ans_list = []
for i in range(q):
    ans = 0
    l, r = map(int, input().split())
    S = s[l-1:r]
    for i in range(len(S)-1):
        if S[i] == "A" and S[i+1] == "C":
            ans += 1
    ans_list.append(ans)
for i in range(q):
    print(ans_list[i])

Fixed submission:
n, q = map(int, input().split())
s = input()
ans_list = [0]*n
for i in range(n-1):
    if s[i] == "A" and s[i+1] == "C":
        ans_list[i+1] = ans_list[i] + 1
    else:
        ans_list[i+1] = ans_list[i]
for _ in range(q):
    a, b = map(int, input().split())
    print(ans_list[b-1]-ans_list[a-1])
Buggy python submission (verdict: Runtime Error):
n = int(input())
otoshidama = {"JPY":0, "BTC":0}
for i in range(n):
    a, b = map(str, input().split())
    a = float(a)
    if b == "JPY":
        otoshidama["JPY"] = otoshidama["JPY"] + a
    else:
        otoshidama["BTC"] = otoshidama["BTC"] + a
ans = otochidama["JPY"] + otochidama["BTC"] * 380000.0
print(ans)

Fixed submission:
N = int(input())
x = [0]*N
u = [0]*N
answer = 0
for i in range(N):
    x[i], u[i] = map(str, input().split())
    if u[i] == "JPY":
        answer += int(x[i])
    else:
        answer += (float(x[i]) * 380000)



print(answer)

Buggy python submission (verdict: Runtime Error):
n = int(input())
otoshidama = {JPY:0, BTC:0}
for i in range(n):
    a, b = map(str, input().split())
    a = float(a)
    if b == JPY:
        otoshidama[JPY] = otoshidama[JPY] + a
    else:
        otoshidama[BTC] = otoshidama[BTC] + a
ans = otochidama[JPY] + otochidama[BTC] * 380000.0
print(ans)

Fixed submission:
N = int(input())
x = [0]*N
u = [0]*N
answer = 0
for i in range(N):
    x[i], u[i] = map(str, input().split())
    if u[i] == "JPY":
        answer += int(x[i])
    else:
        answer += (float(x[i]) * 380000)



print(answer)
Buggy python submission (verdict: Runtime Error):
import sys
import bisect

def main():
  input = sys.stdin.readline
  inf = pow(10, 18)
  a, b, q = map(int, input().split())
  s = [-inf]+[int(input()) for _ in range(a)]+[inf]
  t = [-inf]+[int(input()) for _ in range(b)]+[inf]
  
  for _ in range(q):
    x = int(input())
    i = bisect.bisect_left(s, x)
    j = bisect.bisect_left(t, x)
    ans = inf
    for l in range(2):
      for m in range(2):
        sub = min([abs(x-s[i+l]), abs(x-t[j+m])])+abs(s[i+l]-t[j+m])
        if ans > sub:
          ans = sub
    print(ans)

if __name__ == "__main__":
  main()

Fixed submission:
import sys

def main():
  input = sys.stdin.readline
  a, b, q = map(int, input().split())
  s = [0]*a
  for i in range(a):
    s[i] = int(input())
  
  t = [0]*b
  for i in range(b):
    t[i] = int(input())

  s_near = [0]*a
  k = 0
  for i in range(a):
    if k == b-1:
      s_near[i] = abs(s[i]-t[b-1])
      continue
    while True:
      sub = min([abs(s[i]-t[k]), abs(s[i]-t[k+1])])
      if sub == abs(s[i]-t[k+1]):
        k += 1
        if k == b-1:
          s_near[i] = sub
          break
        continue
      else:
        s_near[i] = sub
        break
  
  t_near = [0]*b
  k = 0
  for i in range(b):
    if k == a-1:
      t_near[i] = abs(t[i]-s[a-1])
      continue
    while True:
      sub = min([abs(t[i]-s[k]), abs(t[i]-s[k+1])])
      if sub == abs(t[i]-s[k+1]):
        k += 1
        if k == a-1:
          t_near[i] = sub
          break
        continue
      else:
        t_near[i] = sub
        break
  
  
  for i in range(q):
    x = int(input())
    if x <= s[0]:
      sub1 = s[0]-x+s_near[0]
    elif x >= s[a-1]:
      sub1 = x-s[a-1]+s_near[a-1]
    else:
      l, r = 0, a
      while r-l > 1:
        k = (r+l)//2
        if x <= s[k]:
          r = k
        else:
          l = k
      sub1 = min([s[r]-x+s_near[r], x-s[l]+s_near[l]])
    
    
    if x <= t[0]:
      sub2 = t[0]-x+t_near[0]
    elif x >= t[b-1]:
      sub2 = x-t[b-1]+t_near[b-1]
    else:
      l, r = 0, b
      while r-l > 1:
        k = (r+l)//2
        if x <= t[k]:
          r = k
        else:
          l = k
      sub2 = min([t[r]-x+t_near[r], x-t[l]+t_near[l]])
    ans = min([sub1, sub2])
    print(ans)


if __name__ == "__main__":
  main()