Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
H,W,A,B=map(int,input().split())
def kaijo(a):
    x=1
    for i in range(a):
       x=x*(i+1)
    return x
def con(a,b):
    x=kaijo(a)
    y=kaijo(b)
    z=kaijo(a-b)
    res = x/y/z
    return res

def calc(x,y):
    res = con(x+y-2,x-1)
    return res

all = calc(H,W)
for i in range(B):
    x=i+1
    k = calc(x,H-A)*calc(A,W-x)
    all=all-k
result=int(all)%(7+10**9)
print(result)

Fixed submission:
H, W, A, B = [int(_) for _ in input().split()]
mod = 10**9 + 7
 
X = [i for i in range(H + W + 1)]
X[0] = 1
for i in range(2, H + W + 1):
    X[i] = X[i - 1] * i % mod
 
Y = X.copy()
Y[-1] = pow(Y[-1], mod - 2, mod)
for i in range(H + W, 1, -1):
    Y[i - 1] = i * Y[i] % mod
 
 
def comb(x, y):
    return X[x] * Y[y] * Y[x - y] % mod
 
 
ans = 0
for i in range(B, min(B + H - A, W)):
    ans += comb(H - A + B - 1, i) * comb(W + A - B - 1, W - i - 1)
    ans %= mod
print(ans)

Buggy python submission (verdict: Runtime Error):
H,W,A,B=map(int,input().split())
def kaijo(a):
    x=1
    for i in range(a):
       x=x*(i+1)
    return x
def con(a,b):
    x=kaijo(a)
    y=kaijo(b)
    z=kaijo(a-b)
    res = x/y/z
    return res

def calc(x,y):
    res = con(x+y-2,x-1)
    return res

all = calc(H,W)
for i in range(B):
    x=i+1
    k = calc(x,H-A)*calc(A,W-x)
    all=all-k
print(int(all))

Fixed submission:
H, W, A, B = [int(_) for _ in input().split()]
mod = 10**9 + 7
 
X = [i for i in range(H + W + 1)]
X[0] = 1
for i in range(2, H + W + 1):
    X[i] = X[i - 1] * i % mod
 
Y = X.copy()
Y[-1] = pow(Y[-1], mod - 2, mod)
for i in range(H + W, 1, -1):
    Y[i - 1] = i * Y[i] % mod
 
 
def comb(x, y):
    return X[x] * Y[y] * Y[x - y] % mod
 
 
ans = 0
for i in range(B, min(B + H - A, W)):
    ans += comb(H - A + B - 1, i) * comb(W + A - B - 1, W - i - 1)
    ans %= mod
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
H,W,A,B=map(int,input().split())
power=[]
for tate in range(H):
    x= []
    for yoko in range(W):
        x.append(0)
    power.append(x)
power[0][0]+=1
def calc(power,x,y):
    if y==0 and x==0:return power
    if y==0:ue=0
    if y!=0:ue=power[y-1][x]
    if x==0:hidari=0
    if x!=0:hidari=power[y][x-1]
    if y>=H-A and x < B:
        power[y][x]=0
    if y<H-A or x >=B:
        power[y][x]=ue+hidari
    return power
for y in range(H):
    for x in range(W):
        power=calc(power,x,y)
result= power[H-1][W-1]%(7+10**9)
print(result)

Fixed submission:
H, W, A, B = [int(_) for _ in input().split()]
mod = 10**9 + 7
 
X = [i for i in range(H + W + 1)]
X[0] = 1
for i in range(2, H + W + 1):
    X[i] = X[i - 1] * i % mod
 
Y = X.copy()
Y[-1] = pow(Y[-1], mod - 2, mod)
for i in range(H + W, 1, -1):
    Y[i - 1] = i * Y[i] % mod
 
 
def comb(x, y):
    return X[x] * Y[y] * Y[x - y] % mod
 
 
ans = 0
for i in range(B, min(B + H - A, W)):
    ans += comb(H - A + B - 1, i) * comb(W + A - B - 1, W - i - 1)
    ans %= mod
print(ans)
Buggy python submission (verdict: Runtime Error):
def dfs(now, par, d, dist, g):
    dist[now] = d
    for to, cost in g[now]:
        if to == par: continue
        dfs(to, now, d + cost, dist, g)


n = int(raw_input())
g = [[] for _ in xrange(n)]
for i in xrange(n - 1):
    a, b, c = map(int, raw_input().split())
    a -= 1; b -= 1
    g[a].append([b, c])
    g[b].append([a, c])
q, k = map(int, raw_input().split())
k -= 1
dist = [-1] * n
dfs(k, -1, 0, dist, g)
for i in xrange(q):
    x, y = map(int, raw_input().split())
    x -= 1; y -= 1
    print dist[x] + dist[y]


Fixed submission:
import heapq

def dijkstra(s,g,n):
    d=[float('inf')]*n
    d[s]=0
    pq=[]
    heapq.heappush(pq,[0,s])
    while len(pq)!=0:
        t,u=heapq.heappop(pq)
        if d[u]<t:
            continue
        for v,c in g[u]:
            if d[u]+c<d[v]:
                d[v]=d[u]+c
                heapq.heappush(pq,[d[v],v])
    return d

n = int(raw_input())
g = [[] for _ in xrange(n)]
for i in xrange(n - 1):
    a, b, c = map(int, raw_input().split())
    a -= 1; b -= 1
    g[a].append([b, c])
    g[b].append([a, c])
q, k = map(int, raw_input().split())
k -= 1
dist = dijkstra(k, g, n)
for i in xrange(q):
    x, y = map(int, raw_input().split())
    x -= 1; y -= 1
    print dist[x] + dist[y]
Buggy python submission (verdict: Runtime Error):
def show1(n, ans):
    for i in xrange(n):
        print ans[i],
    print

def show2(n, m, l, ans):
    for i in xrange(l):
        print ans[i] * m + 1,
    for i in xrange(l, n):
        print ans[i] * m,
    print

k = int(raw_input())
n = 50
ans = [0] * n
print n
if k <= n:
    for i in xrange(k):
        ans[i] = n - i
    show(n, ans)
else:
    ans = range(50, 0, -1)
    m = k / 50
    l = k % 50
    show2(n, m, l, ans)   


Fixed submission:
def show1(n, ans):
    for i in xrange(n):
        print ans[i],
    print

def show2(n, m, l, ans):
    for i in xrange(l):
        print ans[i] + m + 1,
    for i in xrange(l, n):
        print ans[i] + m ,
    print

k = int(raw_input())
n = 50
ans = [0] * n
print n
if k <= n:
    for i in xrange(k):
        ans[i] = n - i
    show1(n, ans)
else:
    ans = range(50, 0, -1)
    m = k / 50 - 1
    l = k % 50
    show2(n, m, l, ans)
Buggy python submission (verdict: Runtime Error):
n, k = map(int, raw_input().split())
a = map(int, raw_input().split())
a.sort(reverse = True)
ans = 0:
for i in xrange(k):
    ans += a[i]
print ans


Fixed submission:
n, k = map(int, raw_input().split())
a = map(int, raw_input().split())
a.sort(reverse = True)
ans = 0
for i in xrange(k):
    ans += a[i]
print ans
Buggy python submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(10**8)

def find_path(now, par):
    if now == n - 1:
        path.append(n - 1)
        return True
    for to in g[now]:
        if to == par: continue
        if find_path(to, now):
            path.append(now)
            return True
    return False

def dfs(now, par, color):
    color[now] = "b"
    for to in g[now]:
        if to == par: continue
        if color[to] == "w": continue
        dfs(to, now, color)

n = int(raw_input())
g = [[] for _ in xrange(n)]
for i in xrange(n - 1):
    a, b = map(int, raw_input().split())
    a -= 1; b -=1
    g[a].append(b)
    g[b].append(a)
path = []
find_path(0, -1)
path.reverse()
color = ["bl"] * n
color[0] = "b"
color[n - 1] = "w"
for i in xrange(1, len(path) - 1):
    v = path[i]
    if i % 2 == 1:
        color[v] = "b"
    else:
        color[v] = "w"
dfs(0, -1, color)
cnt = 0
for i in xrange(n):
    if color[i] == "b":
        cnt += 1
if cnt > n - cnt:
    print "Fennec"
else:
    print "Snuke"


Fixed submission:
n = int(raw_input())
a = map(int, raw_input().split())
s = [0] * n
s[0] = a[0]
for i in xrange(1, n):
    s[i] += s[i - 1] + a[i]
ans = 10**12
for i in xrange(n - 1):
    ans = min(ans, abs(s[i] - (s[n - 1] - s[i])))
print ans
Buggy python submission (verdict: Time Limit Exceeded):
def nCk(n,k,mod=10**9+7):
    if n<k or k<0 or n<0:return 0
    return fact[n]/fact[n-k]%mod * pow(fact[k],mod-2,mod) % mod

mod = 10**9+7
n=int(raw_input())
a=map(int,raw_input().split())
cnt=[0]*(n+1)
for i in xrange(n+1):
    cnt[a[i]]+=1
dnum=0
for i in xrange(n+1):
    if cnt[i]==2:
        dnum=i
        break
idx=[]
fact=[0]*(n+5)
fact[0]=1
for i in xrange(n+1):
    fact[i+1] = (i+1)*fact[i]
for i in xrange(n+1):
    if dnum==a[i]:
        idx.append(i)

y=n-idx[1]
x=idx[0]

for i in xrange(n+1):
    #print nCk(y,i)
    print (nCk(n+1, i+1) - nCk(y,i)-x*nCk(y,i-1)%mod)%mod


Fixed submission:
from math import factorial
def nCk(n,k,mod=10**9+7):
    if n<k or k<0 or n<0:return 0
    return fact[n]*inv[n-k]*inv[k] % mod

mod = 10**9+7
n=int(raw_input())
a=map(int,raw_input().split())
cnt=[0]*(n+1)
for i in xrange(n+1):
    cnt[a[i]]+=1
dnum=0
for i in xrange(n+1):
    if cnt[i]==2:
        dnum=i
        break
idx=[]
fact=[0]*(n+5)
fact[0]=1
inv=[0]*(n+5)
inv[n+1]=pow(factorial(n+1), mod - 2, mod)
for i in xrange(n+1):
    fact[i+1] = (i+1)*fact[i]%mod
for i in xrange(n, -1, -1):
    inv[i] = inv[i+1]*(i+1)%mod
for i in xrange(n+1):
    if dnum==a[i]:
        idx.append(i)

y=n-idx[1]
x=idx[0]

for i in xrange(n+1):
    #print nCk(y,i)
    print (nCk(n+1, i+1) - nCk(x+y,i))%mod

Buggy python submission (verdict: Time Limit Exceeded):
def nCk(n,k,mod=10**9+7):
    if n<k or k<0 or n<0:return 0
    return fact[n]%mod * pow(fact[n-k]*fact[k],mod-2,mod) % mod

mod = 10**9+7
n=int(raw_input())
a=map(int,raw_input().split())
cnt=[0]*(n+1)
for i in xrange(n+1):
    cnt[a[i]]+=1
dnum=0
for i in xrange(n+1):
    if cnt[i]==2:
        dnum=i
        break
idx=[]
fact=[0]*(n+5)
fact[0]=1
for i in xrange(n+1):
    fact[i+1] = (i+1)*fact[i]
for i in xrange(n+1):
    if dnum==a[i]:
        idx.append(i)

y=n-idx[1]
x=idx[0]

for i in xrange(n+1):
    #print nCk(y,i)
    print (nCk(n+1, i+1) - nCk(y,i)-x*nCk(y,i-1))%mod


Fixed submission:
from math import factorial
def nCk(n,k,mod=10**9+7):
    if n<k or k<0 or n<0:return 0
    return fact[n]*inv[n-k]*inv[k] % mod

mod = 10**9+7
n=int(raw_input())
a=map(int,raw_input().split())
cnt=[0]*(n+1)
for i in xrange(n+1):
    cnt[a[i]]+=1
dnum=0
for i in xrange(n+1):
    if cnt[i]==2:
        dnum=i
        break
idx=[]
fact=[0]*(n+5)
fact[0]=1
inv=[0]*(n+5)
inv[n+1]=pow(factorial(n+1), mod - 2, mod)
for i in xrange(n+1):
    fact[i+1] = (i+1)*fact[i]%mod
for i in xrange(n, -1, -1):
    inv[i] = inv[i+1]*(i+1)%mod
for i in xrange(n+1):
    if dnum==a[i]:
        idx.append(i)

y=n-idx[1]
x=idx[0]

for i in xrange(n+1):
    #print nCk(y,i)
    print (nCk(n+1, i+1) - nCk(x+y,i))%mod
Buggy python submission (verdict: Runtime Error):
n=int(raw_input())
xy=[]
for i in xrange(n):
    x,y=map(int,raw_input().split())
    if x>y:x,y=y,x
    xy.append((x,y))
xy.sort()
rmn=10**12;rmx=0;bmn=10**12;bmx=0
for i in xrange(n):
    x,y=xy[i]
    rmn=min(rmn,y)
    rmx=max(rmx,y)
    bmn=min(bmn,x)
    bmx=max(bmx,x)
ans1=(rmx-rmn)*(bmx-bmn)
cntmx=0;cntmn=0
for i in xrange(n):
    x,y=xy[i]
    if rmx==y:cntmx+=1
    if bmn==x:cntmx+=1
if cntmx==1 and cntmn==1 and xy[0][0]==bmn and xy[0][1]==rmx:
    print ans1
    exit()
xy[0]=(xy[0][1],xy[0][0])
xy.sort()
ymn=[10**12]*n
rmn=bmn;bmn=xy[0][0];bmx=xy[n-1][0]
for i in xrange(n):
    x,y=xy[i]
    ymn[i]=min(ymn[max(0,i-1)],y)
ans2=(rmx-rmn)*(bmx-bmn)
for i in xrange(1,n):
    x,y=xy[i]
    if ymn[i]<x:
        break
    bmn=x
    bmx=max(bmx,xy[i-1][1])
    ans2=min(ans2,(rmx-rmn)*(bmx-bmn))
print min(ans1,ans2)


Fixed submission:
n,T=map(int,raw_input().split())
t=map(int,raw_input().split())
i=1
now=T
ans=T
while i<n:
    if t[i]+T<now:
        while t[i]+T<now:
            i+=1
    if t[i]>=now:
        now=t[i]+T
        ans+=T
        i+=1
    elif t[i]+T>=now:
        ans+=t[i]+T-now
        now=t[i]+T
        i+=1
print ans
Buggy python submission (verdict: Runtime Error):
from collections import deque

def dfs1(now,visited,ans):
    visited[now]=True
    for nx in g[now]:
        if not visited[nx]:
            ans.appendleft(nx)
            dfs1(nx,visited,ans)
            break

def dfs2(now,visited,ans):
    visited[now]=True
    for nx in g[now]:
        if not visited[nx]:
            ans.append(nx)
            dfs2(nx,visited,ans)
            break

n,m=map(int,raw_input().split())
g=[[] for _ in xrange(n)]
for i in xrange(m):
    a,b=map(int,raw_input().split())
    a-=1;b-=1
    g[a].append(b)
    g[b].append(a)
ans=deque([a,b])
visited=[False]*n
visited[a]=True
visited[b]=True
dfs1(a,visited,ans)
dfs2(b,visited,ans)
print len(ans)
for i in xrange(len(ans)):
    print ans[i]+1,
print

Fixed submission:
from collections import deque
from sys import setrecursionlimit
setrecursionlimit(10**6)

def dfs1(now,visited,ans):
    visited[now]=True
    for nx in g[now]:
        if not visited[nx]:
            ans.appendleft(nx)
            dfs1(nx,visited,ans)
            break

def dfs2(now,visited,ans):
    visited[now]=True
    for nx in g[now]:
        if not visited[nx]:
            ans.append(nx)
            dfs2(nx,visited,ans)
            break

n,m=map(int,raw_input().split())
g=[[] for _ in xrange(n)]
for i in xrange(m):
    a,b=map(int,raw_input().split())
    a-=1;b-=1
    g[a].append(b)
    g[b].append(a)
ans=deque([a,b])
visited=[False]*n
visited[a]=True
visited[b]=True
dfs1(a,visited,ans)
dfs2(b,visited,ans)
print len(ans)
for i in xrange(len(ans)):
    print ans[i]+1,
print
Buggy python submission (verdict: Runtime Error):
s=raw_input()
t=raw_input()
sb=[0]*(len(s)+1)
tb=[0]*(len(t)+1)
for i in xrange(len(s)):
    if s[i]=="B":
        sb[i+1]+=1
for i in xrange(len(s)):
    sb[i+1]+=sb[i]
for i in xrange(len(t)):
    if t[i]=="B":
        tb[i+1]+=1
for i in xrange(len(t)):
    tb[i+1]+=tb[i]
q=int(raw_input())
for i in xrange(q):
    a,b,c,d=map(int,raw_input().split())
    a-=1;c-=1;
    cnt1=b-a;cnt2=d-c
    cnt1+=sb[b]-sb[a]
    cnt2+=tb[d]-tb[c]
    if abs(cnt1-cnt2)%3==0:
        print("YES")
    else:
        print("NO")

Fixed submission:
n=int(raw_input())
s=[raw_input() for _ in xrange(n)]
cnt=[[0]*26 for _ in xrange(n)]
for i in xrange(n):
    for j in xrange(len(s[i])):
        cnt[i][ord(s[i][j])-ord("a")]+=1
ans=""
for j in xrange(26):
    tmp=10**9
    for i in xrange(n):
        tmp=min(tmp,cnt[i][j])
    ans+=chr(j+ord("a"))*tmp
print ans
Buggy python submission (verdict: Runtime Error):
a,b=raw_input().split()
if (a=='H' and b='H') or (a=='D' and b=='D'):
    print 'H'
else:
    print 'D'

Fixed submission:
a,b=raw_input().split()
if (a=='H' and b=='H') or (a=='D' and b=='D'):
    print 'H'
else:
    print 'D'
Buggy python submission (verdict: Runtime Error):
n,k=map(int,raw_input().split())
a=map(int,raw_input().split())
a.sort()
used=[False]*n
idx=n-1
cnt=0
while True:
    if idx-cnt<0:
        break
    tmp=sum(a[idx-cnt:idx+1])
    if tmp<k:
        cnt+=1
        continue
    for i in xrange(idx-cnt,idx+1):
        used[i]=True
    tmp-=a[idx-cnt]
    for i in xrange(idx-cnt-1,-1,-1):
        if tmp+a[i]>=k:
            used[i]=True
        else:
            break
    idx-=1
    cnt=0
ans=0
for i in xrange(n):
    if not used[i]:
        ans+=1
print ans

Fixed submission:
x=int(raw_input())
ans=0
su=0
while su<x:
    ans+=1
    su+=ans
print ans
Buggy python submission (verdict: Runtime Error):
def check(y,x):
    if 0<=y<=n-1 and 0<=x<=n-1:
        return True
    return False

n,m=map(int,raw_input().split())
a=[raw_input() for _ in xrange(n)]
b=[raw_input() for _ in xrange(m)]
for i in xrange(n):
    for j in xrange(n):
        cnt=0
        for k in range(m):
            for l in xrange(m):
                if check(k+i,l+j):
                    if a[k+i][l+j]==b[k][l]:
                        cnt+=1
        if cnt==m*m:
            print("Yes")
            exit()
print("No")


Fixed submission:
a,b=map(int,raw_input().split())
if a==b:
    print("Draw")
elif a==1:
    print("Alice")
elif b==1:
    print("Bob")
elif b<a:
    print("Alice")
else:
    print("Bob")
Buggy python submission (verdict: Time Limit Exceeded):
def check(y,x):
    if 0<=y<=n-1 and 0<=x<=n-1:
        return True
    return False

n,m=map(int,raw_input().split())
a=[raw_input() for _ in xrange(n)]
b=[raw_input() for _ in xrange(m)]
for i in xrange(n):
    for j in xrange(n):
        cnt=0
        for k in range(m):
            for l in xrange(m):
                if check(k+i,l+j):
                    if a[k+i][l+j]==b[k][l]:
                        cnt+=1
        if cnt==m*m:
            print("Yes")
            exit()
print("No")


Fixed submission:
def check(y,x):
    if 0<=y<=n-1 and 0<=x<=n-1:
        return True
    return False

n,m=map(int,raw_input().split())
a=[raw_input() for _ in xrange(n)]
b=[raw_input() for _ in xrange(m)]
for i in xrange(n):
    for j in xrange(n):
        cnt=0
        for k in range(m):
            for l in xrange(m):
                if check(k+i,l+j):
                    if a[k+i][l+j]==b[k][l]:
                        cnt+=1
        if cnt==m*m:
            print("Yes")
            exit()
print("No")

Buggy python submission (verdict: Runtime Error):
def check(y,x):
    if 0<=y<=n-1 and 0<=x<=n-1:
        return True
    return False
n,m=map(int,raw_input().split())
a=[raw_input() for _ in xrange(n)]
b=[raw_input() for _ in xrange(m)]
for i in xrange(m):
    for j in xrange(m):
        cnt=0
        for k in range(i,i+m):
            for l in xrange(j,j+m):
                if check(k,l):
                    if a[k][l]==b[k][l]:
                        cnt+=1
        if cnt==m*m:
            print("Yes")
            exit()
print("No")


Fixed submission:
def check(y,x):
    if 0<=y<=n-1 and 0<=x<=n-1:
        return True
    return False

n,m=map(int,raw_input().split())
a=[raw_input() for _ in xrange(n)]
b=[raw_input() for _ in xrange(m)]
for i in xrange(n):
    for j in xrange(n):
        cnt=0
        for k in range(m):
            for l in xrange(m):
                if check(k+i,l+j):
                    if a[k+i][l+j]==b[k][l]:
                        cnt+=1
        if cnt==m*m:
            print("Yes")
            exit()
print("No")
Buggy python submission (verdict: Runtime Error):
s=raw_input()
n=len(s)
for i in xrange(n):
    if s[i]=="a":
        idx1=i
        break    
for i in xrange(n-1,0,-1):
    if s[i]=="z":
        idx2=i
        break
print idx2-idx1+1


Fixed submission:
x=input()
if x<1200:
    print("ABC")
else:
    print("ARC")
Buggy python submission (verdict: Runtime Error):
n=int(raw_input())
s=raw_input()
ans=0
for i in xrange(n):
    if s[i]=="I":
        cnt+=1
        ans=max(ans,cnt)
    elif s[i]=="D":
        cnt-=1
        ans=max(ans,cnt)
print(ans)


Fixed submission:
n=int(raw_input())
s=raw_input()
ans=0;cnt=0
for i in xrange(n):
    if s[i]=="I":
        cnt+=1
        ans=max(ans,cnt)
    elif s[i]=="D":
        cnt-=1
        ans=max(ans,cnt)
print(ans)
Buggy python submission (verdict: Runtime Error):
n,k=map(int,raw_input().split())
a=map(int,raw_input().split())
s1=[0]*n
s1[0]=a[0]
s2=[0]*n
if a[0]>0:
    s2[0]=a[0]
for i in xrange(1,n):
    s1[i]+=s1[i-1]+a[i]
    if a[i]>0:
        s2[i]+=s2[i-1]+a[i]
ans=-float("inf")
for i in xrange(n-k+1):
    tmp1=s1[i+k-1]-s1[max(0,i-1)]
    tmp2=s2[n]-(s2[i+k-1]-s2[max(0,i-1)])
    ans=max(ans,tmp1+tmp2,tmp2)
print ans


Fixed submission:
n,k=map(int,raw_input().split())
a=map(int,raw_input().split())
total=[0]*(n+1)
asum=[0]*(n+1)
for i in xrange(n):
    asum[i+1]=asum[i]+a[i]
    if a[i]>0:
        total[i+1]=total[i]+a[i]
    else:
        total[i+1]=total[i]
ans=0
for i in xrange(n-k+1):
    tmp=asum[i+k]-asum[i]
    ans=max(ans,tmp+total[i]+total[n]-total[i+k],total[i]+total[n]-total[i+k])

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n,k=map(int,raw_input().split())
a=map(int,raw_input().split())
total=[0]*(n+1)
for i in xrange(n):
    if a[i]>0:
        total[i+1]=total[i]+a[i]
    else:
        total[i+1]=total[i]
ans=0
for i in xrange(n-k+1):
    tmp=0
    for j in xrange(i,i+k):
        tmp+=a[j]
    ans=max(ans,tmp+total[i]+total[n]-total[i+k],total[i]+total[n]-total[i+k])

print(ans)


Fixed submission:
n,k=map(int,raw_input().split())
a=map(int,raw_input().split())
total=[0]*(n+1)
asum=[0]*(n+1)
for i in xrange(n):
    asum[i+1]=asum[i]+a[i]
    if a[i]>0:
        total[i+1]=total[i]+a[i]
    else:
        total[i+1]=total[i]
ans=0
for i in xrange(n-k+1):
    tmp=asum[i+k]-asum[i]
    ans=max(ans,tmp+total[i]+total[n]-total[i+k],total[i]+total[n]-total[i+k])

print(ans)
Buggy python submission (verdict: Runtime Error):
n=int(raw_input())
x=map(int,raw_input().split())
ans=[-1]*(n**2+1)
for i in xrange(n):
    if ans[x[i]]!=-1:
        print("No")
        exit()
    ans[x[i]]=i+1
    cnt=n-1
    for j in xrange(1,n**2+1):
        if cnt==0:break
        if ans[j]==-1:
            cnt-=1
            ans[j]=i+1
    if cnt>0:
        print("No")
        exit()
print("Yes")
print(" ".join(map(str,ans[1:])))


Fixed submission:
I,O,T,J,L,S,Z=map(int,raw_input().split())
ans=0
ans1=0
ans+=2*O
ans1+=2*O
ans+=4*(I/2)
ans+=4*(J/2)
ans+=4*(L/2)
JL=min(J,L)
if JL>=1 and I>=1:
    ans1+=6
    J-=1
    L-=1
    I-=1
ans1+=4*(I/2)
ans1+=4*(J/2)
ans1+=4*(L/2)
print(max(ans/2,ans1/2))

Buggy python submission (verdict: Runtime Error):
I,O,T,J,L,S,Z=map(int,raw_input().split())
ans=0
ans+=2*O
ans1+=2*O
ans+=4*(I/2)
ans+=4*(J/2)
ans+=4*(L/2)
JL=min(J,L)
if JL>=1 and I>=1:
    ans1+=6
    J-=1
    L-=1
    I-=1
ans1+=4*(I/2)
ans1+=4*(J/2)
ans1+=4*(L/2)
print(max(ans/2,ans1/2))

Fixed submission:
I,O,T,J,L,S,Z=map(int,raw_input().split())
ans=0
ans1=0
ans+=2*O
ans1+=2*O
ans+=4*(I/2)
ans+=4*(J/2)
ans+=4*(L/2)
JL=min(J,L)
if JL>=1 and I>=1:
    ans1+=6
    J-=1
    L-=1
    I-=1
ans1+=4*(I/2)
ans1+=4*(J/2)
ans1+=4*(L/2)
print(max(ans/2,ans1/2))
Buggy python submission (verdict: Runtime Error):
n=int(raw_input())
t=map(int,raw_input().split())
m=int(raw_input())
xt=[map(int,raw_input().split()) for _ in xrange(m)]
ans=[0]*m
for i in xrange(m):
    tmp=t
    tmp[xt[i][0]-1]=xt[i][1]
    for j in xrange(n):
        ans[i]+=tmp[j]
for j in xrange(n):
    print(ans[j])


Fixed submission:
a,op,b=raw_input().split()
if op=="+":
    print(int(a)+int(b))
else:
    print(int(a)-int(b))
Buggy python submission (verdict: Runtime Error):
n=int(raw_input())
t=map(int,raw_input().split())
m=int(raw_input())
xt=[map(int,raw_input().split()) for _ in xrange(m)]
ans=[0]*m
for i in xrange(m):
    tmp=t
    tmp[xt[i][0]]=xt[i][1]
    for j in xrange(n):
        ans[i]+=tmp[j]
for j in xrange(n):
    print(ans[j])


Fixed submission:
import copy
n=int(raw_input())
t=map(int,raw_input().split())
m=int(raw_input())
pt=[map(int,raw_input().split()) for _ in xrange(m)]
ans=[0]*m
for i in xrange(m):
    tmp=copy.deepcopy(t)
    tmp[pt[i][0]-1]=pt[i][1]
    for j in xrange(n):
        ans[i]+=tmp[j]
for i in xrange(m):
    print(ans[i])