Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
n,a,b,c = map(int,input().split())

si = [input() for i in range(n)]

if a == 0 and b == 0 and c== 0:
    print("No")
    exit()

s1 = 0
s2 = 0

abc = [a,b,c]
moji = ['A','B','C']

def checkmoji(s):
    if si[i] == "AB":
        s1 = 0
        s2 = 1
    elif si[i] == 'AC':
        s1 = 0
        s2 = 2
    elif si[i] == 'BC':
        s1 = 1
        s2 = 2
    return s1,s2

ans = []

for i in range(n):
    s1,s2 = checkmoji(si[i])
    if abc[s1] <= 0 and abc[s2] <= 0:
        print('No')
        exit()
    if abc[s2] == 0:
        abc[s1] -= 1
        abc[s2] += 1
        ans.append(moji[s2])
    elif abc[s1] == 0:
        abc[s1] += 1
        abc[s2] -= 1
        ans.append(moji[s1])
    else:
        """
        if i == n-1:
            ans.append(moji[s1])
            break
        """
        s1_a,s2_a = checkmoji(si[i+1])
        if s1 == s1_a or s1 == s2_a:
            abc[s1] += 1
            abc[s2] -= 1
            ans.append(moji[s2])
        else:
            abc[s1] -= 1
            abc[s2] += 1
            ans.append(moji[s1])
print('Yes')
for i in range(len(ans)):
    print(ans[i])

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

si = [input() for i in range(n)]

if a == 0 and b == 0 and c== 0:
    print("No")
    exit()

s1 = 0
s2 = 0

abc = [a,b,c]
moji = ['A','B','C']

def checkmoji(s):
    if s == "AB":
        s1 = 0
        s2 = 1
    elif s == 'AC':
        s1 = 0
        s2 = 2
    elif s == 'BC':
        s1 = 1
        s2 = 2
    return s1,s2

ans = []

for i in range(n):
    s1,s2 = checkmoji(si[i])
    if abc[s1] == 0 and abc[s2] == 0:
        print('No')
        exit()
    if abc[s2] == 0:
        abc[s1] -= 1
        abc[s2] += 1
        ans.append(moji[s2])
    elif abc[s1] == 0:
        abc[s1] += 1
        abc[s2] -= 1
        ans.append(moji[s1])
    else:
        
        if i == n-1:
            ans.append(moji[s1])
            break
        
        s1_a,s2_a = checkmoji(si[i+1])
        if s1 == s1_a or s1 == s2_a:
            abc[s1] += 1
            abc[s2] -= 1
            ans.append(moji[s1])
        else:
            abc[s1] -= 1
            abc[s2] += 1
            ans.append(moji[s2])
print('Yes')
for i in range(len(ans)):
    print(ans[i])
Buggy python submission (verdict: Time Limit Exceeded):
s = input()

li = []
mod = 2019
tmp = 0

for i in range(len(s)):
    li.append(tmp)
    tmp += int(s[i]) * 10 ** (len(s)-i-1)
    tmp %= mod
    #print(len(s)-i-1,s[i])

li.append(tmp)

li.sort()
#print(li)

tmp = li[0]
t_num = 1
ans = 0

for i in range(1,len(li)):
    if tmp == li[i]:
        t_num += 1
    else:
        ans += t_num*(t_num-1)//2
        t_num = 1
        tmp = li[i]

print(ans)

Fixed submission:
s = input()

li = []
mod = 2019
tmp = 0

for i in range(len(s)):
    li.append(tmp)
    tmp += int(s[i])*pow(10,len(s)-i-1,mod)
    #tmp += int(s[i]) * 10 ** (len(s)-i-1)
    tmp %= mod
    #print(len(s)-i-1,s[i])

li.append(tmp)
li.sort()

tmp = li[0]
t_num = 1
ans = 0

for i in range(1,len(li)):
    if tmp == li[i]:
        t_num += 1
    else:
        ans += t_num*(t_num-1)//2
        t_num = 1
        tmp = li[i]

ans += t_num*(t_num-1)//2

print(ans)
Buggy python submission (verdict: Runtime Error):
n = int(input())
n = n-1
ans = 0


def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    # divisors.sort()
    return divisors

li = make_divisors(n)

for i in range(2,n+1):
    if i**2 > n:
        break
    tmp = n
    #print(i)
    while tmp % i == 0:
        #print(tmp)
        #exit()
        tmp = tmp / i
    if tmp % i == 1:
        ans += 1
        li.append(i)
        
print(unique(li)-1)

exit()

for i in range(2,n+1):
    """
    if i**2 > n:
        break
    """
    tmp = n
    #print(i)
    if tmp % i == 0:
        #print(tmp)
        #exit()
        #tmp = tmp / i
        ans += 1
        print(i)
    """
    if tmp == 1:
        ans += 1
        print(i)
    """
        
print(ans)

Fixed submission:
n = int(input())
n = n-1
ans = 0


def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    # divisors.sort()
    return divisors

li = make_divisors(n)
n = n+1
for i in range(2,n+1):
    if i**2 > n:
        break
    tmp = n
    #print(i)
    while tmp % i == 0:
        #print(tmp)
        #exit()
        tmp = tmp / i
    if tmp % i == 1:
        ans += 1
        li.append(i)
#print(li)
print(len(set(li)))

exit()

for i in range(2,n+1):
    """
    if i**2 > n:
        break
    """
    tmp = n
    #print(i)
    if tmp % i == 0:
        #print(tmp)
        #exit()
        #tmp = tmp / i
        ans += 1
        print(i)
    """
    if tmp == 1:
        ans += 1
        print(i)
    """
        
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
h,w,K = map(int,input().split())
sij = [input() for j in range(h)]

num = 2**(h-1)
hon = 10**18

for i in range(num):
    tmp = format(i,'0'+str(h)+'b')
    #print(tmp,tmp,tmp,tmp)
    yoko_hon = sum(list(map(int,tmp)))+1
    blk = [0]*(yoko_hon)
    #blk_num = 0
    tmp_col = 0
    tmp_hon = yoko_hon-1
    flag = True
    ok_flag = True
    for j in range(w):
        tmp_blk = [0]*(yoko_hon)
        blk_num = 0
        for k in range(h):
            if tmp[k] == str(1):
                blk_num += 1
            #print(blk_num,tmp_blk)
            tmp_blk[blk_num] += int(sij[k][j])
            #print(blk[blk_num] , tmp_blk[blk_num],k)
            if blk[blk_num] + tmp_blk[blk_num] > K:
                flag = False
                continue
        
        #print(ok_flag,flag,tmp_blk,blk)
        if flag == False:
            for l in range(yoko_hon):
                if tmp_blk[l] > K:
                    ok_flag = False
                    break
                blk[l] = tmp_blk[l]
            tmp_hon += 1
            tmp_col = 0
            flag = True
        else:
            for l in range(yoko_hon):
                blk[l] += tmp_blk[l]
                tmp_col += 1
        if ok_flag == False:
            break
            
    #print(ok_flag)
    if ok_flag == False:
        ok_flag = True
        continue
    #exit()
    hon = min(tmp_hon,hon)
    
print(hon)

Fixed submission:
h,w,K = map(int,input().split())
sij = [input() for j in range(h)]

num = 2**(h-1)
hon = 10**18

for i in range(num):
    tmp = format(i,'0'+str(h)+'b')
    #print(tmp,tmp,tmp,tmp)
    yoko_hon = sum(list(map(int,tmp)))+1
    blk = [0]*(yoko_hon)
    #blk_num = 0
    tmp_col = 0
    tmp_hon = yoko_hon-1
    flag = True
    ok_flag = True
    for j in range(w):
        tmp_blk = [0]*(yoko_hon)
        blk_num = 0
        for k in range(h):
            if tmp[k] == str(1):
                blk_num += 1
            #print(blk_num,tmp_blk)
            tmp_blk[blk_num] += int(sij[k][j])
            #print(blk[blk_num] , tmp_blk[blk_num],k)
            if blk[blk_num] + tmp_blk[blk_num] > K:
                flag = False
                continue
        
        #print(ok_flag,flag,tmp_blk,blk)
        if flag == False:
            for l in range(yoko_hon):
                if tmp_blk[l] > K:
                    ok_flag = False
                    break
                blk[l] = tmp_blk[l]
            tmp_hon += 1
            tmp_col = 0
            flag = True
        else:
            for l in range(yoko_hon):
                blk[l] += tmp_blk[l]
                tmp_col += 1
        if ok_flag == False:
            break
            
    #print(ok_flag)
    if ok_flag == False:
        ok_flag = True
        continue
    #exit()
    hon = min(tmp_hon,hon)
    
print(hon)
Buggy python submission (verdict: Time Limit Exceeded):
n,k = map(int,input().split())

def cmb(n, r, mod):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod

mod = 10**9+7 #出力の制限
g1 = [1, 1] # 元テーブル
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル

for i in range( 2, n + 1 ):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )

ans = 0
#con = cmb(n,k,mod)
#print(con)
for i in range(k+1):
    ans += cmb(n,i,mod)*cmb(n-1,i,mod)
    ans %= mod
    
print(ans)

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

def cmb(n, r, mod):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod

mod = 10**9+7 #出力の制限
g1 = [1, 1] # 元テーブル
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル

for i in range( 2, n + 1 ):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )

ans = 0
#con = cmb(n,k,mod)
#print(con)
for i in range(min(k+1,n+1)):
    ans += cmb(n,i,mod)*cmb(n-1,i,mod)
    ans %= mod
    
print(ans)
Buggy python submission (verdict: Runtime Error):
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

import itertools

n = int(input())
p = tuple(map(int,readline().split()))
q = tuple(map(int,readline().split()))

a = 0

permutations = list(itertools.permutations(range(1, n+1)))
p = permutations.index(p)
q = permutations.index(q)

print(abs(p-q))

Fixed submission:
import math

n = int(input())
p = [int(i) for i in input().split()]
q = [int(i) for i in input().split()]

a = 0

for i in range(n):
    tmp = 0
    for j in range(n-i-1):
        if p[i] > p[i+j+1]:
            tmp += 1
    a += tmp*math.factorial(n-1-i)


b = 0

for i in range(n):
    tmp = 0
    for j in range(n-i-1):
        if q[i] > q[i+j+1]:
            tmp += 1
    b += tmp*math.factorial(n-1-i)
    
print(abs(a-b))
Buggy python submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(10**7)
import time

t1 = time.time()

x,y = map(int,input().split())
kyori = x+y
if kyori % 3 !=0:
    print(0)
    exit()
    
mod = 10**9+7

nagasa = kyori // 3
dif = x - y

n_x = (nagasa + dif) // 2
n_y = nagasa - n_x

#print(nagasa,n_x,n_y)

if x != n_x * 2 + n_y * 1 or y != n_x * 1+ n_y*2:
    print(0)
    exit()

#H, W, A, B = map(int, raw_input().split())

def kj(n, x,y, mod):
    #if ( r<0 or r>n ):
     #   return 0
    #r = min(r, n-r)
    return g1[n] * g2[x] * g2[y] % mod

g1 = [1, 1] # 元テーブル
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル

for i in range( 2, kyori // 3 + 1 ):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )


a = kj(nagasa,n_x,n_y,mod)
print(a)


Fixed submission:
import sys
sys.setrecursionlimit(10**9)
import time

t1 = time.time()

x,y = map(int,input().split())
kyori = x+y
if kyori % 3 !=0:
    print(0)
    exit()
    
mod = 10**9+7

nagasa = kyori // 3
dif = x - y

n_x = (nagasa + dif) // 2
n_y = nagasa - n_x

#print(nagasa,n_x,n_y)

if x != n_x * 2 + n_y * 1 or y != n_x * 1+ n_y*2:
    print(0)
    exit()

if n_x < 0 or n_y < 0:
    print(0)
    exit()
#H, W, A, B = map(int, raw_input().split())

def kj(n, x,y, mod):
    #if ( r<0 or r>n ):
     #   return 0
    #r = min(r, n-r)
    return g1[n] * g2[x] * g2[y] % mod

g1 = [1, 1] # 元テーブル
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル

for i in range( 2, kyori // 3 + 1 ):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )


a = kj(nagasa,n_x,n_y,mod)
print(a)
Buggy python submission (verdict: Time Limit Exceeded):
import bisect

n,k = map(int,input().split())
a = [int(i) for i in input().split()]
f = [int(i) for i in input().split()]

a.sort()
f.sort(reverse=True)

af = [[0 for i in range(3)] for j in range(n)]

for i in range(n):
    af[i][0] = a[i]*f[i]
    af[i][1] = a[i]
    af[i][2] = f[i]
    
af.sort(reverse=True)

if k == 0:
    print(af[0][0])
    exit()

low = -1
high = af[0][0]+1
tmp = 0

while low+1 < high:
    tmp = 0
    mid = (low + high) //2
    #print(mid)
    
    for i in range(n):
        tmp += max(0,af[i][1] - mid // af[i][2])
    #print(tmp)
    
    if tmp <= k:
        high = mid
    else:
        low = mid
        
if tmp > k:
    print(mid+1)
else:
    print(mid)


Fixed submission:
import bisect

n,k = map(int,input().split())
a = [int(i) for i in input().split()]
f = [int(i) for i in input().split()]

a.sort()
f.sort(reverse=True)

af = [[0 for i in range(3)] for j in range(n)]

for i in range(n):
    af[i][0] = a[i]*f[i]
    af[i][1] = a[i]
    af[i][2] = f[i]
    
af.sort(reverse=True)

if k == 0:
    print(af[0][0])
    exit()

low = -1
high = af[0][0]+1
tmp = 0

while low+1 < high:
    tmp = 0
    mid = (low + high) //2
    #print(mid)
    
    for i in range(n):
        tmp += max(0,af[i][1] - mid // af[i][2])
    #print(tmp)
    
    if tmp <= k:
        high = mid
    else:
        low = mid
        
if tmp > k:
    print(mid+1)
else:
    print(mid)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())

s = input()

dp = [[0 for i in range(n+1)] for j in range(n+1)]

for i in reversed(range(n)):
    for j in reversed(range(n)):
        if s[i] == s[j]:
            dp[i][j] = dp[i+1][j+1] + 1
            
ans = 0

for i in range(n):
    for j in range(n):
        ans = max(ans,min(dp[i][j],j-i))
        
print(ans)

Fixed submission:
n = int(input())

s = input()

dp = [[0 for i in range(n+1)] for j in range(n+1)]

for i in reversed(range(n)):
    for j in reversed(range(n)):
        if s[i] == s[j]:
            dp[i][j] = dp[i+1][j+1] + 1
            
ans = 0

for i in range(n):
    for j in range(n):
        ans = max(ans,min(dp[i][j],j-i))
        
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())

ans = 0

for i in range(n):
    ans += i
    
print(ans)

Fixed submission:
n = int(input())

print(n*(n-1)//2)
Buggy python submission (verdict: Runtime Error):
s = input()

ans = 1
cur = 0
tmp = s[0]

for i in range(len(s)-1):
    #print(cur)
    if cur >= len(s)-2:
        if tmp == s[cur+1]:
            break
        else:
            ans += 1
            break
    if tmp == s[cur+1]:
        tmp = s[cur+1] + s[cur+2]
        cur += 2
        ans += 1
    else:
        tmp = s[cur+1]
        cur += 1
        ans += 1
        
print(ans)

Fixed submission:
s = input()

ans = 1
cur = 0
tmp = s[0]

for i in range(len(s)-1):
    #print(cur)
    if cur == len(s)-1:
        break
    if cur >= len(s)-2:
        if tmp == s[cur+1]:
            break
        else:
            ans += 1
            break
    if tmp == s[cur+1]:
        tmp = s[cur+1] + s[cur+2]
        cur += 2
        ans += 1
    else:
        tmp = s[cur+1]
        cur += 1
        ans += 1
        
print(ans)
Buggy python submission (verdict: Runtime Error):
s = input()

s = s.replace('RL','A')

r_num = 0
l_num = 0

l = []
r = []
print(s)
now = "l"
for i in range(len(s)):
    if i == len(s) - 1 and s[i] == 'L':
        l.append(l_num+1)
    if s[i] == 'A':
        if s[i-1] == 'R':
            r.append(r_num)
            r_num = 0
            if now == 'r':
                l.append(0)
            now = 'r'
        elif s[i-1] == 'L':
            l.append(l_num)
            l_num = 0
            if now == 'l':
                r.append(0)
            now = 'l'
        else:
            r_num = 0
            l_num = 0
            r.append(r_num)
            l.append(l_num)
    elif s[i] == 'R':
        if s[i-1] == 'L' and i != 0:
            #print(l_num,i)
            l.append(l_num)
            #now = 'r'
        r_num += 1
        l_num = 0
        
    else:
        now = 'l'
        l_num += 1
        r_num = 0

ans = []

for i in range(len(l)):
    for j in range(r[i]):
        ans.append(0)
    if max(r[i],l[i])%2 == 0:
        ans.append(r[i]+1)
        ans.append(l[i]+1)
    else:
        ans.append(l[i]+1)
        ans.append(r[i]+1)
    
    for k in range(l[i]):
        ans.append(0)

print(*ans,sep="")
    

Fixed submission:
s = input()

ans = [0] * len(s)

cnt = 0

for i in range(len(s)):
    if s[i] == 'R':
        cnt += 1
    else:
        ans[i] += cnt // 2
        ans[i-1] += (cnt+1) // 2
        cnt = 0

ans.reverse()
#print(ans)
#exit()

s_list = list(reversed(s))
#s.reverse()

cnt = 0

for i in range(len(s_list)):
    if s_list[i] == 'L':
        s_list[i] = 'R'
    else:
        s_list[i] = 'L'

for i in range(len(s_list)):
    if s_list[i] == 'R':
        cnt += 1
    else:
        ans[i] += cnt // 2
        ans[i-1] += (cnt+1) // 2
        cnt = 0

ans.reverse()

print(*ans)
Buggy python submission (verdict: Runtime Error):
import queue
import scipy
n,k = map(int,input().split())

ab = [[] for j in range(n+1)]
mod = 10**9 + 7

for i in range(n-1):
    a,b = map(int,input().split())
    ab[a].append(b)
    ab[b].append(a)
    
check = [False] * (n+1)
kazu = [0] * (n+1)

check[0] = True

q = queue.Queue()
q.put(1)

ans = k
#print(ab)

while not q.empty():
    tmp = q.get()
    check[tmp] = True
    kake = 0
    for i in range(len(ab[tmp])):
        if check[ab[tmp][i]] == True:
            continue
        kazu[ab[tmp][i]] += 1
        q.put(ab[tmp][i])
        ans *= k - kake - kazu[tmp] - 1
        ans %= mod
        #print(i,k,ans,tmp,kazu[tmp])
        kake += 1
    
print(ans)

Fixed submission:
import queue
import scipy
n,k = map(int,input().split())

ab = [[] for j in range(n+1)]
mod = 10**9 + 7

for i in range(n-1):
    a,b = map(int,input().split())
    ab[a].append(b)
    ab[b].append(a)
    
check = [False] * (n+1)
kazu = [0] * (n+1)

check[0] = True

q = queue.Queue()
q.put(1)

ans = k
#print(ab)

while not q.empty():
    tmp = q.get()
    check[tmp] = True
    kake = 0
    for i in range(len(ab[tmp])):
        if check[ab[tmp][i]] == True:
            continue
        kazu[ab[tmp][i]] += 1
        q.put(ab[tmp][i])
        ans *= k - kake - kazu[tmp] - 1
        ans %= mod
        #print(i,k,ans,tmp,kazu[tmp])
        kake += 1
    
print(ans)
Buggy python submission (verdict: Runtime Error):
import sys
import numpy as np
from scipy.special import comb
sys.setrecursionlimit(1000000)
 
n,k = map(int,input().split())

mod = 10**9+7
ans = 0

for i in range(1,k+1):
    print(comb(n-k+1, i, exact=True) * comb(k-1, i-1, exact=True) % mod)


Fixed submission:
import sys
import numpy as np
from scipy.misc import comb
sys.setrecursionlimit(1000000)
 
n,k = map(int,input().split())

mod = 10**9+7
ans = 0

for i in range(1,k+1):
    print(comb(n-k+1, i, exact=True) * comb(k-1, i-1, exact=True) % mod)
Buggy python submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(1000000)
 
N,K = map(int,input().split())
a = list(map(int,input().split()))

b = []
b.append(0)

now = 0

for i in range(N):
    now = now + a[i]
    b.append(now)
    
ans = 0
#cur = N

for i in range(N):
    for j in range(i,N+1):
        if N - j < 0:
            break
        if K <= b[N-i] - b[N-j]:
            ans += N - j + 1
            #print(ans)
            break
        else:
            #cur = cur - j
            continue
            
print(ans)


Fixed submission:
import sys
sys.setrecursionlimit(1000000)
 
X,A = map(int,input().split())

if X < A:
    print(0)
else:
    print(10)
Buggy python submission (verdict: Time Limit Exceeded):
import sys
import numpy as np
sys.setrecursionlimit(1000000)
 
H,W = map(int,input().split())
S = [input() for i in range(H)]

L = [[0 for i in range(W)] for j in range(H)]
R = [[0 for i in range(W+1)] for j in range(H)]

for i in range(H):
    for j in range(W):
        if S[i][j] == ".":
            L[i][j] = L[i][j-1] + 1
        else:
            L[i][j] = 0
            
        if S[i][W-1-j] == ".":
            R[i][W-1-j] = R[i][W-1-j+1] + 1
        else:
            R[i][W-1-j] = 0
        
U = [[0 for i in range(W)] for j in range(H)]
D = [[0 for i in range(W)] for j in range(H+1)]

for i in range(H):
    for j in range(W):
        if S[i][j] == ".":
            U[i][j] = U[i-1][j] + 1
        else:
            U[i][j] = 0
           
        if S[H-1-i][j] == ".":
            D[H-1-i][j] = D[H-1-i+1][j] + 1
        else:
            D[H-1-i][j] = 0
        
        
ans = 0

for i in range(H):
    for j in range(W):
        if S[i][j] == ".":
            ans = max(ans,L[i][j]+R[i][j]+U[i][j]+D[i][j]-3)
            
print(ans)

Fixed submission:
import sys
sys.setrecursionlimit(1000000)
 
H,W = map(int,input().split())
S = [input() for i in range(H)]

L = [[0 for i in range(W)] for j in range(H)]
R = [[0 for i in range(W+1)] for j in range(H)]

for i in range(H):
    for j in range(W):
        if S[i][j] == ".":
            L[i][j] = L[i][j-1] + 1
        else:
            L[i][j] = 0
            
        if S[i][W-1-j] == ".":
            R[i][W-1-j] = R[i][W-1-j+1] + 1
        else:
            R[i][W-1-j] = 0
        
U = [[0 for i in range(W)] for j in range(H)]
D = [[0 for i in range(W)] for j in range(H+1)]

for i in range(H):
    for j in range(W):
        if S[i][j] == ".":
            U[i][j] = U[i-1][j] + 1
        else:
            U[i][j] = 0
           
        if S[H-1-i][j] == ".":
            D[H-1-i][j] = D[H-1-i+1][j] + 1
        else:
            D[H-1-i][j] = 0
        
        
ans = 0

for i in range(H):
    for j in range(W):
        if S[i][j] == ".":
            ans = max(ans,L[i][j]+R[i][j]+U[i][j]+D[i][j]-3)
            
print(ans)
Buggy python submission (verdict: Runtime Error):
import sys
import numpy as np
sys.setrecursionlimit(1000000)
 
N,K = map(int,input().split())
VN =  [int(i) for i in input().split()]

ans = 0
temp = 0

for i in range(K):
    for j in range(K-i):
        now = 0
        if i + j > K:
            break
       
        tmp_list = []
        
        for l in range(i):
            now += VN[l]
            tmp_list.append(VN[l])
    
        for m in range(j):
            now += VN[N-1-m]
            tmp_list.append(VN[N-1-m])
        
        tmp_list.sort()
        
        for n in range(N-i-j-2):
            if n >= len(tmp_list)-1:
                break
            if tmp_list[n] >= 0:
                break
            now -= tmp_list[n]
        ans = max(ans,now)

print(ans)

Fixed submission:
import sys
import numpy as np
sys.setrecursionlimit(1000000)
 
N,K = map(int,input().split())
VN =  [int(i) for i in input().split()]

ans = 0
temp = 0

for i in range(min(N,K)+1):
    for j in range(min(K-i,N-i)+1):
        now = 0
        if i + j > min(N,K):
            break
       
        tmp_list = []
        
        for l in range(i):
            now += VN[l]
            tmp_list.append(VN[l])
    
        for m in range(j):
            now += VN[N-1-m]
            tmp_list.append(VN[N-1-m])
        
        tmp_list.sort()
        
        for n in range(K-i-j):
            if n >= len(tmp_list):
                break
            if tmp_list[n] >= 0:
                break
            now -= tmp_list[n]
        ans = max(ans,now)

print(ans)
Buggy python submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(1000000)
 
N,M = map(int,input().split())
A = list(map(int,input().split()))

BC =  [[int(i) for i in input().split()] for M in range(M)]



A.sort()
#BC.sort()
BC = sorted(BC, key=lambda x:x[1])
BC.reverse()

now = 0
end = 0

for i in range(M):
    for j in range(BC[i][0]):
        if A[now+j] < BC[i][1]:
            A[now+j] = BC[i][1]
        else:
            end = 1
            break
    
    if end == 1:
        break
    now = now + BC[i][0]

print(sum(A))

Fixed submission:
import sys
sys.setrecursionlimit(1000000)
 
N,M = map(int,input().split())
A = list(map(int,input().split()))

BC =  [[int(i) for i in input().split()] for M in range(M)]



A.sort()
#BC.sort()
BC = sorted(BC, key=lambda x:x[1])
BC.reverse()

now = 0
end = 0

for i in range(M):
    for j in range(BC[i][0]):
        if now+j >= N:
            end = 1
            break
        if A[now+j] < BC[i][1]:
            A[now+j] = BC[i][1]
        else:
            end = 1
            break
    
    if end == 1:
        break
    now = now + BC[i][0]

print(sum(A))