Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
import sys
n=int(input())
lst=[[] for i in range(n**2)]
li=[[] for i in range(n**2)]
for i in range(n):
    a=list(map(int,input().split()))
    for j in range(n-2):
        i1=i
        i2=i
        b=a[j]-1
        c=a[j+1]-1
        if i1>b:
            i1,b=b,i1
        if i2>c:
            i2,c=c,i2
        lst[n*i1+b].append(n*i2+c)
        li[n*i2+c].append(n*i1+b)
que=[1]
for _ in range(n*(n-1)//2+1):
    h=[]
    for u in que:
        for v in lst[u]:
            h.append(v)
    if not h:
        break
    que=h
else:
    print(-1)
    sys.exit()
count=0
while que:
    h=[]
    for u in que:
        for v in li[u]:
            h.append(v)
    que=h
    count+=1
    if count==n*(n-1)//2+1:
        print(-1)
        sys.exit()
print(count)

Fixed submission:
n=int(input())
lst_to=[[] for i in range(n**2)]
lst_from=[[] for i in range(n**2)]
for i in range(n):
    a=list(map(int,input().split()))
    for j in range(n-2):
        i1=i
        i2=i
        b=a[j]-1
        c=a[j+1]-1
        if i1>b:
            i1,b=b,i1
        if i2>c:
            i2,c=c,i2
        lst_to[n*i1+b].append(n*i2+c)
        lst_from[n*i2+c].append(n*i1+b)

que=[]
for i in range(n):
    for j in range(i+1,n):
        if not lst_from[n*i+j]:
            que.append(n*i+j)

count=0
while que:
    count+=1
    h=[]
    for u in que:
        for v in lst_to[u]:
            lst_from[v].remove(u)
            if not lst_from[v]:
                h.append(v)
    que=h

for i in range(n):
    for j in range(i+1,n):
        if lst_from[n*i+j]:
            print(-1)
            break
    else:
        continue
    break
else:
    print(count)
Buggy python submission (verdict: Time Limit Exceeded):
S=input()
t=input()
L=len(t)
s=S
for i in range(0,L):
    s=s+S
k=0
m=0
a=0
while k<=L-1:
    if t[k] in S:
        if t[k]==s[m]:
            k+=1
            m+=1
        else:
            m+=1
    else:
        print(-1)
        a=10
        break
if a==0:
    print(m)

Fixed submission:
from bisect import bisect
s=input()
t=input()
n,m=len(s),len(t)
alf=list("abcdefghijklmnopqrstuvwxyz")
data=[[] for i in range(26)]
for i in range(26):
    for j in range(n):
        if alf[i]==s[j]:
            data[i].append(j)
l=[0]*26
for i in range(26):
    l[i]=len(data[i])
ind=-1
count=0
for i in range(m):
    k=alf.index(t[i])
    if data[k]:
        p=bisect(data[k],ind)
        if p==l[k]:
            count+=1
            ind=data[k][0]
        else:
            ind=data[k][p]
    else:
        print(-1)
        break
else:
    print(n*count+ind+1)
Buggy python submission (verdict: Runtime Error):
N = int(input())
s = []
for i in range(0,N):
    a = input()
    s.append(sorted(a))
t = 0
for i in range(0,N):
    for j in range(i+1,N):
        if s[i] == s[j]:
            t +=1
print(t)


Fixed submission:
num = input().split()
A = int(num[0])
B = int(num[1])
s = [A+B,A-B,A*B]
print(max(s))

Buggy python submission (verdict: Runtime Error):
N = int(input())
s = []
for i in range(0,N):
    a = input()
    s.append(sorted(a))
t = 0
while len(s)>0:
    a = s.count(s[0])
    if a==1:
        continue
    else:
        a = (a*(a-1))/2
        t = t+a
    s.remove(s[0])
print(t)

Fixed submission:
num = input().split()
A = int(num[0])
B = int(num[1])
s = [A+B,A-B,A*B]
print(max(s))
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
s = []
for i in range(0,N):
    a = input()
    s.append(sorted(a))
t = 0
for i in range(0,N):
    for j in range(i+1,N):
        if s[i] == s[j]:
            t +=1
print(t)



Fixed submission:
N = int(input())
s = []
for i in range(0,N):
    a = input()
    s.append(sorted(a))
s = sorted(s)
t = 0
i = 0
while i<N:
    for j in range(i+1,N):
        if s[i]==s[j]:
            t = t+j-i
        else:
            break
    i = j
    if i==N-1:
        break
print(t)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
s = []
for i in range(0,N):
    a = input()
    s.append(sorted(a))
t = 0
while len(s)>0:
    a = s.count(s[0])
    if a==1:
        continue
    else:
        a = (a*(a-1))/2
        t = t+a
    s.remove(s[0])
print(t)

Fixed submission:
N = int(input())
s = []
for i in range(0,N):
    a = input()
    s.append(sorted(a))
s = sorted(s)
t = 0
i = 0
while i<N:
    for j in range(i+1,N):
        if s[i]==s[j]:
            t = t+j-i
        else:
            break
    i = j
    if i==N-1:
        break
print(t)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
s = []
for i in range(0,N):
    a = input()
    s.append(sorted(a))
t = 0
for i in range(0,N):
    for j in range(i+1,N):
        if s[i] == s[j]:
            t +=1
print(t)

Fixed submission:
N = int(input())
s = []
for i in range(0,N):
    a = input()
    s.append(sorted(a))
s = sorted(s)
t = 0
i = 0
while i<N:
    for j in range(i+1,N):
        if s[i]==s[j]:
            t = t+j-i
        else:
            break
    i = j
    if i==N-1:
        break
print(t)
Buggy python submission (verdict: Time Limit Exceeded):
n,m=map(int,input().split())
data=[[] for _ in range(m+1)]
for _ in range(n):
    a,b=map(int,input().split())
    if a<=m:
        data[a].append(b)
for i in range(1,m+1):
    data[i].sort()
s=0
for i in range(1,m+1):
    a=0
    count=0
    for j in range(1,i+1):
        if data[j]:
            if a<data[j][-1]:
                a=data[j][-1]
                count=j
    if count!=0:
        s+=a
        data[count].pop()
print(s)

Fixed submission:
from heapq import heappush, heappop
from collections import deque
n,m=map(int,input().split())
data=[[] for _ in range(m+1)]
for _ in range(n):
    a,b=map(int,input().split())
    if a<=m:
        data[a].append([-b,a])
for i in range(1,m+1):
    data[i].sort()
    data[i]=deque(data[i])
h=[]
s=0
for i in range(1,m+1):
    if data[i]:
        heappush(h,data[i].popleft())
    if h:
        d=heappop(h)
        if data[d[1]]:
            heappush(h,data[d[1]].popleft())
        s+=-d[0]
print(s)
Buggy python submission (verdict: Time Limit Exceeded):
from operator import itemgetter
mod=998244353

def bit_add(i):
    while i<=n:
        tree[i]+=1
        i+=i&(-i)

def bit_sum(i):
    s=0
    while i>0:
        s+=tree[i]
        i-=i&(-i)
    return s

n=int(input())
xy=[[i+1]+list(map(int,input().split())) for i in range(n)]
data=[[] for i in range(n+1)]
for i in [1,2]:
    xy.sort(key=itemgetter(i))
    for j in range(n):
        data[xy[j][0]].append(j+1)
        
lsls=[1]*(n+1)
for i in range(1,n+1):
    lsls[i]=lsls[i-1]*2%mod
for i in range(n+1):
    lsls[i]-=1

data=sorted(data[1:])
lst=[]
for i1,i2 in data:
    lst.append(i2)

s=pow(2,n,mod)-1
tree=[0]*(n+1)
ans=0
for i in range(n):
    y=lst[i]
    num=bit_sum(y)
    bit_add(y)
    a,b,c,d=i-num,num,y-1-num,n-y-i+num
    t=(lsls[i]+lsls[n-i-1]+lsls[n-y]+lsls[y-1]-(lsls[a]+lsls[b]+lsls[c]+lsls[d]))%mod
    ans=(ans+s-t)%mod
print(ans)

Fixed submission:
from operator import itemgetter
import sys
input=sys.stdin.readline
mod=998244353

def bit_add(i):
    while i<=n:
        tree[i]+=1
        i+=i&(-i)
        
def bit_sum(i):
    s=0
    while i>0:
        s+=tree[i]
        i-=i&(-i)
    return s

n=int(input())
xy=[[i+1]+list(map(int,input().split())) for i in range(n)]
data=[[] for i in range(n+1)]
for i in [1,2]:
    xy.sort(key=itemgetter(i))
    for j in range(n):
        data[xy[j][0]].append(j+1)
    
data=sorted(data[1:])
lst=[]
for i1,i2 in data:
    lst.append(i2)

lsls=[1]*(n+1)
for i in range(1,n+1):
    lsls[i]=lsls[i-1]*2%mod
for i in range(n+1):
    lsls[i]-=1
    
s=pow(2,n,mod)-1
tree=[0]*(n+1)
ans=0
for i in range(n):
    y=lst[i]
    num=bit_sum(y)
    bit_add(y)
    a,b,c,d=i-num,num,y-1-num,n-y-i+num
    zzz=lsls[i]+lsls[n-i-1]+lsls[n-y]+lsls[y-1]
    yyy=lsls[a]+lsls[b]+lsls[c]+lsls[d]
    t=(zzz%mod-yyy%mod)%mod
    ans=(ans+s-t)%mod
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N,M=map(int,input().split())
mod=998244353

MAX=3*M//2+N

inv=[0]*(MAX+1)
inv[1]=1
for i in range(2,MAX+1):
    inv[i]=-(mod//i)*inv[mod%i]%mod

g1=[1,1]
g2=[1,1]
for i in range(2,MAX+1):
    num_1=g1[-1]*i%mod
    g1.append(num_1)
    g2.append(g2[-1]*inv[i]%mod)
    
def cmb(n,r):
    return g1[n]*g2[r]*g2[n-r]%mod

ans=0
for i in range(min(N+1,M+1)):
    if M%2!=i%2:
        continue
    m=(3*M-i)//2
    num=(cmb(m+N-1,N-1)-i*cmb(m-M+N-1,N-1))%mod
    if m>=M+1:
        num=(num-(N-i)*cmb(m-M+N-2,N-1))%mod
    ans=(ans+cmb(N,i)*num)%mod

print(ans)  

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

inv=[0]*(3*M//2+N+2)
inv[1]=1
for i in range(2,3*M//2+N+2):
    inv[i]=-(mod//i)*inv[mod%i]%mod

#階乗テーブル
g1=[1,1]
g2=[1,1]
for i in range(2,3*M//2+N+2):
    num_1=g1[-1]*i%mod
    g1.append(num_1)
    g2.append(g2[-1]*inv[i]%mod)
    
def cmb(n,r):
    return g1[n]*g2[r]*g2[n-r]%mod

#奇数の和で場合分け
#iは奇数の数

ans=0
for i in range(min(N+1,M+1)):
    if M%2!=i%2:
        continue
    m=(3*M-i)//2
    num=(cmb(m+N-1,N-1)-i*cmb(m-M+N-1,N-1))%mod
    if m>=M+1:
        num=(num-(N-i)*cmb(m-M+N-2,N-1))%mod
    ans=(ans+cmb(N,i)*num)%mod

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import sys
input=sys.stdin.readline

N,M=map(int,input().split())
mod=998244353

#階乗テーブル
g1=[1,1]
for i in range(2,3*M//2+N+2):
    g1.append(g1[-1]*i%mod)

def cmb(n,r):
    return g1[n]*pow(g1[r],mod-2,mod)*pow(g1[n-r],mod-2,mod)%mod

#奇数の和で場合分け
#iは奇数の数

ans=0
for i in range(min(N+1,M+1)):
    if M%2!=i%2:
        continue
    m=(3*M-i)//2
    num=(cmb(m+N-1,N-1)-i*cmb(m-M+N-1,N-1))%mod
    if m>=M+1:
        num=(num-(N-i)*cmb(m-M+N-2,N-1))%mod
    ans=(ans+cmb(N,i)*num)%mod

print(ans)   

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

inv=[0]*(3*M//2+N+2)
inv[1]=1
for i in range(2,3*M//2+N+2):
    inv[i]=-(mod//i)*inv[mod%i]%mod

#階乗テーブル
g1=[1,1]
g2=[1,1]
for i in range(2,3*M//2+N+2):
    num_1=g1[-1]*i%mod
    g1.append(num_1)
    g2.append(g2[-1]*inv[i]%mod)
    
def cmb(n,r):
    return g1[n]*g2[r]*g2[n-r]%mod

#奇数の和で場合分け
#iは奇数の数

ans=0
for i in range(min(N+1,M+1)):
    if M%2!=i%2:
        continue
    m=(3*M-i)//2
    num=(cmb(m+N-1,N-1)-i*cmb(m-M+N-1,N-1))%mod
    if m>=M+1:
        num=(num-(N-i)*cmb(m-M+N-2,N-1))%mod
    ans=(ans+cmb(N,i)*num)%mod

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
a=list(map(int,input().split()))
b=[0 for i in range(n)]
for i in range(min(a[0],a[1])):
    b[0]=a[0]-i
    b[1]=i
    for j in range(2,n):
        b[j]=a[j-1]-b[j-1]
        if b[j]<0:
            break
    else:
        if b[n-1]+b[0]==a[n-1]:
            break
def bai(x):
    return 2*x
print(" ".join(list(map(str,(list(map(bai,b)))))))

Fixed submission:
#D
from collections import deque
n=int(input())
a=deque(list(map(int,input().split())))
a.appendleft(0)
b=deque([0 for i in range(n+1)])
s=sum(a)
t=0
for i in range(1,(n-1)//2+1):
    t+=2*a[2*i]
b[1]=s-t
for i in range(2,n+1):
    b[i]=(a[i-1]-b[i-1]//2)*2
b.popleft()
print(" ".join(list(map(str,b))))
Buggy python submission (verdict: Time Limit Exceeded):
#D
n,k=map(int,input().split())
mod=10**9+7
def comb(x,y):
    if y==0 or y==x:
        return 1
    else:
        a=x-y+1
        for j in range(2,y+1):
            a=a*(x-y+j)//(j)
        return a
for i in range(1,k+1):
    print(comb(k-1,i-1)*comb(n-k+1,i)%mod)

Fixed submission:
#D
from scipy.misc import comb
n,k=map(int,input().split())
mod=10**9+7
for i in range(1,k+1):
    print(int(comb(k-1,i-1,exact=True)*comb(n-k+1,i,exact=True))%mod)

Buggy python submission (verdict: Time Limit Exceeded):
#D
n,k=map(int,input().split())
mod=10**9+7
def comb(x,y):
    if y==0 or y==x:
        return 1
    else:
        a=x-y+1
        for j in range(2,y+1):
            a=a*(x-y+j)//(j)
        return a
for i in range(1,k+1):
    print(comb(k-1,i-1)*comb(n-k+1,i)%mod)

Fixed submission:
#D
from scipy.misc import comb
n,k=map(int,input().split())
mod=10**9+7
for i in range(1,k+1):
    print(int(comb(k-1,i-1,exact=True)*comb(n-k+1,i,exact=True))%mod)

Buggy python submission (verdict: Runtime Error):
#D
from scipy.misc import comb
n,k=map(int,input().split())
mod=10**9+7
for i in range(1,k+1):
    print(int(comb(k-1,i-1,exact=True)*comb(n-k+1,i,exact=True))%mod)

Fixed submission:
#D
from scipy.misc import comb
n,k=map(int,input().split())
mod=10**9+7
for i in range(1,k+1):
    print(int(comb(k-1,i-1,exact=True)*comb(n-k+1,i,exact=True))%mod)

Buggy python submission (verdict: Runtime Error):
#D
from scipy.misc import comb
n,k=map(int,input().split())
mod=10**9+7
for i in range(1,k+1):
    print((comb(k-1,i-1,exact=True)*comb(n-k+1,i,exact=True))%mod)

Fixed submission:
#D
from scipy.misc import comb
n,k=map(int,input().split())
mod=10**9+7
for i in range(1,k+1):
    print(int(comb(k-1,i-1,exact=True)*comb(n-k+1,i,exact=True))%mod)

Buggy python submission (verdict: Time Limit Exceeded):
#D
import sys
sys.setrecursionlimit(10000)
n,k=map(int,input().split())
mod=10**9+7
def comb(x,y):
    if y==0 or y==x:
        return 1
    elif y==1 or y==x-1:
        return x
    else:
        return (comb(x-1,y-1)+comb(x-1,y))%mod
for i in range(1,k+1):
    if i-1>n-k:
        print(0)
    else:
        print((comb(k-1,i-1)*comb(n-k+1,i))%mod)

Fixed submission:
#D
from scipy.misc import comb
n,k=map(int,input().split())
mod=10**9+7
for i in range(1,k+1):
    print(int(comb(k-1,i-1,exact=True)*comb(n-k+1,i,exact=True))%mod)
Buggy python submission (verdict: Time Limit Exceeded):
n,m=map(int,input().split())
path=[[] for i in range(n+1)]
for i in range(m):
    u,v=map(int,input().split())
    path[u].append(v)
S,T=map(int,input().split())

que=[S]
flag=[0]*(n+1)
flag[S]=1
data=[[] for i in range(n+1)]

while que:
    h=que.pop()
    lst=[h]
    for i in range(3):
        u=[]
        for j in lst:
            for k in path[j]:
                u.append(k)
        lst=u
    lst=list(set(lst))
    for i in lst:
        if i==h:
            continue
        data[h].append(i)
        if flag[i]==0:
            flag[i]=1
            que.append(i)

que=[S]
flag=[0]*(n+1)
flag[S]=1
count=0
while que:
    count+=1
    H=[]
    for u in que:
        for v in data[u]:
            if flag[v]==0:
                H.append(v)
                flag[v]=1
            if v==T:
                print(count)
                break
        else:
            continue
        break
    else:
        que=H
        continue
    break
else:
    print(-1)

Fixed submission:
n,m=map(int,input().split())
data=[[] for i in range(3*n+1)]
for i in range(m):
    u,v=map(int,input().split())
    data[u].append(v+n)
    data[u+n].append(v+2*n)
    data[u+2*n].append(v)
s,t=map(int,input().split())
inf=float("inf") 
flag=[inf]*(3*n+1)
flag[s]=0
que=[s]
while que:
    h=[]
    for u in que:
        for v in data[u]:
            if flag[v]==inf:
                flag[v]=flag[u]+1
                h.append(v)
    que=h
if flag[t]==inf:
    print(-1)
else:
    print(flag[t]//3)

Buggy python submission (verdict: Time Limit Exceeded):
import itertools
import numpy as np
from scipy.sparse.csgraph import shortest_path, floyd_warshall, dijkstra, bellman_ford, johnson
from scipy.sparse import csr_matrix

n,m=map(int,input().split())
path=[[] for i in range(n+1)]
for i in range(m):
    u,v=map(int,input().split())
    path[u].append(v)
S,T=map(int,input().split())


que=[S]
flag=[0]*(n+1)
flag[S]=1
list1=[]
list2=[]

while que:
    h=que.pop()
    lst=[h]
    for i in range(3):
        u=[]
        for j in lst:
            for k in path[j]:
                u.append(k)
        lst=u
    lst=list(set(lst))
    for i in lst:
        if i==h:
            continue
        list1.append(h)
        list2.append(i)
        if flag[i]==0:
            flag[i]=1
            que.append(i)
d=[1]*len(list1)

csr=csr_matrix((d,(list1,list2)),(n+1,n+1))
ans=dijkstra(csr,indices = S)
if ans[T]<n:
    print(int(ans[T]//1))
else:
    print(-1)

Fixed submission:
n,m=map(int,input().split())
data=[[] for i in range(3*n+1)]
for i in range(m):
    u,v=map(int,input().split())
    data[u].append(v+n)
    data[u+n].append(v+2*n)
    data[u+2*n].append(v)
s,t=map(int,input().split())
inf=float("inf") 
flag=[inf]*(3*n+1)
flag[s]=0
que=[s]
while que:
    h=[]
    for u in que:
        for v in data[u]:
            if flag[v]==inf:
                flag[v]=flag[u]+1
                h.append(v)
    que=h
if flag[t]==inf:
    print(-1)
else:
    print(flag[t]//3)
Buggy python submission (verdict: Time Limit Exceeded):
import itertools
import numpy as np
n,m=map(int,input().split()) #<=2*10**3
#n
s=list(map(int,input().split()))
#m
t=list(map(int,input().split()))
mod=10**9+7
ans=np.zeros(m,dtype="int64")

for u in s:
    h=np.zeros(m,dtype="int64")
    if u==t[0]:
        h[0]+=1
    for i in range(1,m):
        if t[i]==u:
            h[i]+=ans[i-1]+1
        h[i]+=h[i-1]
    ans=(ans+h)%mod
print(ans[-1]+1)

Fixed submission:
n,m=map(int,input().split()) #<=2*10**3
#n
s=list(map(int,input().split()))
#m
t=list(map(int,input().split()))
mod=10**9+7
ans=[0]*m

for u in s:
    h=[0]*m
    if u==t[0]:
        h[0]=1
    for i in range(1,m):
        if t[i]==u:
            h[i]+=ans[i-1]+1
        h[i]+=h[i-1]
    for i in range(m):
        ans[i]=(ans[i]+h[i])%mod
print((ans[-1]+1)%mod)
Buggy python submission (verdict: Time Limit Exceeded):
L=input()
n=len(L)
mod=10**9+7
table=[None]*n
table[0]=1
for i in range(1,n):
    table[i]=3*table[i-1]%mod
ans=0
k=1
for i in range(n):
    if L[i]=="1":
        ans=(ans+k*table[n-i-1])%mod
        k*=2
ans+=k    
print(ans%mod)

Fixed submission:
L=list(map(int,list(input())))
n=len(L)
mod=10**9+7
table=[None]*n
table[0]=1
for i in range(1,n):
    table[i]=3*table[i-1]%mod
ans=0
k=1
for i in range(n):
    if L[i]==1:
        ans=(ans+k*table[n-i-1])%mod
        k=k*2%mod
ans+=k    
print(ans%mod)

Buggy python submission (verdict: Time Limit Exceeded):
L=input()
n=len(L)
mod=10**9+7
table=[None]*n
table[0]=1
for i in range(1,n):
    table[i]=3*table[i-1]%mod
ans=0
k=1
for i in range(n):
    if L[i]=="1":
        ans=(ans+k*table[n-i-1])%mod
        k*=2
ans+=k    
print(ans%mod)

Fixed submission:
L=list(map(int,list(input())))
n=len(L)
mod=10**9+7
table=[None]*n
table[0]=1
for i in range(1,n):
    table[i]=3*table[i-1]%mod
ans=0
k=1
for i in range(n):
    if L[i]==1:
        ans=(ans+k*table[n-i-1])%mod
        k=k*2%mod
ans+=k    
print(ans%mod)
Buggy python submission (verdict: Runtime Error):
mod=10**6+3

inv=[0]*mod
inv[1]=1
for i in range(2,mod):
    inv[i]=-(mod//i)*inv[mod%i]%mod

data=[1]
for i in range(1,mod):
    data.append(data[-1]*i%mod)

Q=int(input())
xdn=[list(map(int,input().split())) for i in range(Q)]

for x,d,n in xdn:
    k=x*inv[d]%mod
    if k+n-1>=mod:
        print(0)
    else:
        print(pow(d,k+n-1,mod)*data[k+n-1]*inv[pow(d,k-1,mod)*data[k-1]%mod]%mod)




Fixed submission:
mod=10**6+3

inv=[0]*mod
inv[1]=1
for i in range(2,mod):
    inv[i]=-(mod//i)*inv[mod%i]%mod

data=[1]
for i in range(1,mod):
    data.append(data[-1]*i%mod)

Q=int(input())
xdn=[list(map(int,input().split())) for i in range(Q)]

for x,d,n in xdn:
    if d==0:
        print(pow(x,n,mod))
        continue
    if x==0:
        print(0)
        continue
    k=x*inv[d]%mod
    if k+n-1>=mod:
        print(0)
    else:
        print(pow(d,k+n-1,mod)*data[k+n-1]*inv[pow(d,k-1,mod)*data[k-1]%mod]%mod)
Buggy python submission (verdict: Runtime Error):
#D
from heapq import heappush,heappop
from collections import deque
n,k=map(int,input().split())
v=deque(list(map(int,input().split())))
w=[[] for i in range(n)]
answer=-100000000
for i in range(k+1):
    for j in range(k-i+1):
        h=[]
        for a in range(i):
            heappush(h,v[a])
        for a in range(j):
            heappush(h,v[n-1-a])
        for a in range(k-i-j):
            if h and h[0]<0:
                heappop(h)
            else:
                break
        answer=max(answer,sum(h))
print(answer)

Fixed submission:
#D
from heapq import heappush,heappop
from collections import deque
import sys
n,k=map(int,input().split())
v=deque(list(map(int,input().split())))
w=[[] for i in range(n)]
answer=-100000000
for i in range(min(n+1,k+1)):
    for j in range(min(n-i+1,k-i+1)):
        h=[]
        
        for a in range(i):
            heappush(h,v[a])
        for a in range(j):
            heappush(h,v[n-1-a])
        for a in range(k-i-j):
            if h and h[0]<0:
                heappop(h)
            else:
                break
        answer=max(answer,sum(h))
print(answer)
Buggy python submission (verdict: Runtime Error):
N=int(input())
s=[input() for _ in range(N)]
cnt=0

A_count=0
B_count=0
BA_count=0
for u in s:
    cnt+=u.count("AB")
    if u[0]=="B":
        B_count+=1
    if u[-1]=="A":
        A_count+=1
    if u[0]=="B" and u[-1]=="A":
        BA_count+=1
if A_count==B_count==BA_count:
    if A_count==0:
        print(cnt)
    else:
        print(cnt+A_count-1)
else:
    print(cnt+min(A_count,B,count))

Fixed submission:
N=int(input())
s=[input() for _ in range(N)]
cnt=0

A_count=0
B_count=0
BA_count=0
for u in s:
    cnt+=u.count("AB")
    if u[0]=="B":
        B_count+=1
    if u[-1]=="A":
        A_count+=1
    if u[0]=="B" and u[-1]=="A":
        BA_count+=1
if A_count==B_count==BA_count:
    if A_count==0:
        print(cnt)
    else:
        print(cnt+A_count-1)
else:
    print(cnt+min(A_count,B_count))
Buggy python submission (verdict: Runtime Error):
#C
import sys
from math import gcd
n=int(input())
a=list(map(int,input().split()))
if len(a)==2:
    print(max(a))
    sys.exit()
g=gcd(a[0],a[1])
b=[]
for i in range(2,n):
    l=gcd(g,a[i])
    if l!=g:
        b.append(i)
        g=l
s=[]
g=gcd(a[0],a[2])
for i in range(3,n):
    g=gcd(g,a[i])
s.append(g)
g=gcd(a[1],a[2])
for i in range(3,n):
    g=gcd(g,a[i])
s.append(g)
for i in range(len(b)):
    g=gcd(a[0],a[1])
    for j in range(2,n):
        if j==b[i]:
            continue
        g=gcd(g,a[j])
    s.append(g)
print(max(s))

Fixed submission:
#C
import sys
from fractions import gcd
n=int(input())
a=list(map(int,input().split()))
if len(a)==2:
    print(max(a))
    sys.exit()
g=gcd(a[0],a[1])
b=[]
for i in range(2,n):
    l=gcd(g,a[i])
    if l!=g:
        b.append(i)
        g=l
s=[]
g=gcd(a[0],a[2])
for i in range(3,n):
    g=gcd(g,a[i])
s.append(g)
g=gcd(a[1],a[2])
for i in range(3,n):
    g=gcd(g,a[i])
s.append(g)
for i in range(len(b)):
    g=gcd(a[0],a[1])
    for j in range(2,n):
        if j==b[i]:
            continue
        g=gcd(g,a[j])
    s.append(g)
print(max(s))
Buggy python submission (verdict: Runtime Error):
9
education
7

Fixed submission:
N=int(input())
S=list(input())
K=int(input())
w=S[K-1]
ans=""
for i in range(N):
    if S[i]==w:
        ans+=w
    else:
        ans+="*"
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
X,Y,Z,K = map(int,input().split())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
C = list(map(int,input().split()))
A.sort(reverse=True)
ans = []
BC_ans = []
for eb in B:
    for ec in C:
        BC_ans.append(eb+ec)
BC_ans.sort(reverse=True)
BC_ans = BC_ans[:K]
for ea in A[:K]:
    for ebc in BC_ans:
        ans.append(ea+ebc)
ans.sort(reverse=True)
for i in range(K):
    print(ans[i])
    
    



Fixed submission:
#D
from heapq import heappush,heappop
x,y,z,k=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
c=list(map(int,input().split()))
d=[]
for i in range(x):
    for j in range(y):
        heappush(d,-a[i]-b[j])
e=[]
for i in range(min(3000,x*y)):
    e.append(-heappop(d))
f=[]
for i in range(len(e)):
    for j in range(z):
        heappush(f,-e[i]-c[j])
for i in range(k):
    print(-heappop(f))