Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
# coding: utf-8
# Your code here!

import sys
sys.setrecursionlimit(10**6)
readline = sys.stdin.readline #文字列入力のときは注意

#n = int(input())
n,k = [int(i) for i in input().split()]
a = [int(i)-1 for i in input().split()]


acc = [0]
for ai in a:
    acc.append((acc[-1]+ai)%k)

#print(acc)
ans = 0
d = {}
for num,i in enumerate(acc):
    #print(d,num)
    if num >= k-1:
        d[acc[num-k+1]] -= 1
    #print(d,num)
    if i in d:
        ans += d[i]
        d[i] += 1
    else:
        d[i] = 1
    #print(ans)

print(ans)

Fixed submission:
# coding: utf-8
# Your code here!

import sys
sys.setrecursionlimit(10**6)
readline = sys.stdin.readline #文字列入力のときは注意

#n = int(input())
n,k = [int(i) for i in input().split()]
a = [int(i)-1 for i in input().split()]


acc = [0]
for ai in a:
    acc.append((acc[-1]+ai)%k)

#print(acc)
ans = 0
d = {}
for num,i in enumerate(acc):
    #print(d,num)
    if num >= k:
        d[acc[num-k]] -= 1
    #print(d,num)
    if i in d:
        ans += d[i]
        d[i] += 1
    else:
        d[i] = 1
    #print(ans)

print(ans)
Buggy python submission (verdict: Runtime Error):

import sys
sys.setrecursionlimit(10**6)
readline = sys.stdin.readline 


#x,y = [int(i) for i in readline().split()]
#n = int(input())

n,t = [int(i) for i in readline().split()]
ab = [[int(i) for i in readline().split()] for i in range(n)]


dp = [0]*(t+1)

for a,b in ab:
    c = max(dp[t-a:t])
    dp[-1] = max(dp[-1],c+b)
    
    for i in range(t-1,-1,-1):
        if i-a >= 0:
            dp[i] = max(dp[i], dp[i-a] + b)
        else:
            break
    
    #print(dp)

print(max(dp))

Fixed submission:

import sys
sys.setrecursionlimit(10**6)
readline = sys.stdin.readline 


#x,y = [int(i) for i in readline().split()]
#n = int(input())

n,t = [int(i) for i in readline().split()]
ab = [[int(i) for i in readline().split()] for i in range(n)]

from operator import itemgetter


ab.sort(key = itemgetter(1), reverse = True)
ab.sort(key = itemgetter(0))

dp = [0]*(t)
val = 0

#print(ab)

for a,b in ab:
    for i in range(max(0,t-a),t):
        val = max(val,dp[i]+b)
    
    for i in range(t-1,-1,-1):
        if i-a >= 0:
            if dp[i-a] != 0 or i==a:
                dp[i] = max(dp[i], dp[i-a] + b)
        else:
            break
    #print(dp,val)

print(max(max(dp),val))
Buggy python submission (verdict: Time Limit Exceeded):

import sys
sys.setrecursionlimit(10**6)
readline = sys.stdin.readline 




n,k = [int(i) for i in readline().split()]
a = [0]+[int(i) for i in readline().split()] + [0]

n += 2

INF  = 10**18

diff = [0]
for i in range(n-1):
    diff.append(max(a[i+1]-a[i],0))

from itertools import accumulate
acc = list(accumulate(diff))

ans = {}

def calc(p,q,k):
    if (p,q,k) in ans: return ans[(p,q,k)]
    if k == 0:
        res = acc[q] - acc[p]
    elif k == q-p-1:
        res = max(0,a[q] - a[p])
    else:
        res = INF
        for i in range(p+1,q):
            for l in range(min(k+1,i-p)):
                if k-l > q-p-1: break
                #if p ==1 and q == 4 and k == 1: print(i,l)
                res = min(res, calc(p,i,l)+calc(i,q,k-l))
    #print(p,q,k,res)    
    ans[(p,q,k)] = res    
    return res

#print(acc)
#print(a,n)
print(calc(0,n-1,k))
#print(calc(0,n-1,k))



        





Fixed submission:

import sys
sys.setrecursionlimit(10**6)
readline = sys.stdin.readline 




n,k = [int(i) for i in readline().split()]
a = [0]+[int(i) for i in readline().split()]

n += 1

INF = 10**18

K = n-k-1

dp = [[INF]*n for _ in range((K+1))]
dp[0][0] = 0



for i in range(1,n):
    ndp = [c[:] for c in dp]
    
    for l in range(min(i,K)):
        for now in range(0,i):
            ndp[l+1][i] = min(ndp[l+1][i], ndp[l][now]+max(0,a[i]-a[now]))
    
    dp = ndp
    #print(dp)    

#print(dp[-1])
print(min(dp[-1]))
Buggy python submission (verdict: Runtime Error):
# coding: utf-8
# Your code here!

import sys
sys.setrecursionlimit(10**6)
readline = sys.stdin.readline 

n = int(input())
a = [int(i) for i in readline().split()]
b = [int(i) for i in readline().split()]
pb = [(bi,i) for i,bi in enumerate(b)]

sa = sorted(a)
sb = sorted(b)
pb.sort()

#na = [a[i] for bi,i in pb]
na = []
from itertools import groupby
for k,g in groupby(pb,key=lambda x: x[0]):
    g = list(g)
    res = [a[i] for bi,i in g]
    res.sort()
    #print(g,res)
    na += res

ok = 1
for i,j in zip(sa,sb):
    if i > j: ok = 0

for i,j in zip(sa[1:],sb):
    if i <= j: break
else:
    if na == sa[1:] + sa[:1]:
        ok = 0
    else: a(1)
    
#print(a,b,sa,sb,na)

if ok: print("Yes")    
else: print("No")
    
    
    
    
    
    

Fixed submission:
# coding: utf-8
# Your code here!

import sys
sys.setrecursionlimit(10**6)
readline = sys.stdin.readline 

n = int(input())
a = [int(i) for i in readline().split()]
b = [int(i) for i in readline().split()]
pb = [(bi,i) for i,bi in enumerate(b)]

sa = sorted(a)
sb = sorted(b)
pb.sort()

na = [a[i] for bi,i in pb]


ok = 1
for i,j in zip(sa,sb):
    if i > j: ok = 0

for i,j in zip(sa[1:],sb):
    if i <= j: break
else:
    #sa => na が巡回置換か？
    d = {ai:i for i,ai in enumerate(sa)}
    ra = [d[ai] for ai in na]
    
    #print(ra,ok)    
    now = 0
    for i in range(n-1):
        now = ra[now]
        #print(now)
        if now == 0:
            break
    else: ok = 0    


    

#print(a,b,sa,sb,na)

if ok: print("Yes")    
else: print("No")
Buggy python submission (verdict: Runtime Error):
# coding: utf-8
# Your code here!

import sys
sys.setrecursionlimit(10**6)
readline = sys.stdin.readline 

#n = int(input())
n,m = [int(i) for i in readline().split()]

g = [[] for _ in range(n)]
for _ in range(m):
    s,t = [int(i)-1 for i in readline().split()]
    g[s].append(t)

L = [len(gi) for gi in g]

p = [0]*n
p[0] = 1
for i in range(n-1):
    c = p[i]/L[i]
    for v in g[i]:
        p[v] += c

dp0 = [0]*(n)
dp1 = [1000000]*(n)

for i in range(n-2,-1,-1):
    res = 0
    m = 0
    for v in g[i]:
        res += dp0[v]
        if m<dp0[v]: m = dp0[v]
    dp0[i] = 1 + res/L[i]

    if L[i] >= 2:
        dp1[i] = 1 + (res-m)/(L[i]-1)
    
res = max(res,(dp0[i] - dp1[i])*p[i] for i in range(n))

print(dp0[0]-max(0,res))












Fixed submission:
# coding: utf-8
# Your code here!


import sys
sys.setrecursionlimit(10**6)
readline = sys.stdin.readline 

#n = int(input())
n,m = [int(i) for i in readline().split()]

g = [[] for _ in range(n)]
for _ in range(m):
    s,t = [int(i)-1 for i in readline().split()]
    g[s].append(t)

L = [len(gi) for gi in g]

p = [0]*n
p[0] = 1
for i in range(n-1):
    c = p[i]/L[i]
    for v in g[i]:
        p[v] += c
#print(p)

inf = 1000000

dp0 = [0]*(n)
dp1 = [inf]*(n)

for i in range(n-2,-1,-1):
    res = 0
    m = 0
    for v in g[i]:
        res += dp0[v]
        if m<dp0[v]: m = dp0[v]
    dp0[i] = 1 + res/L[i]
    
    if L[i] >= 2:
        dp1[i] = 1 + (res-m)/(L[i]-1)
    
#print(dp0)
#print(dp1)

res = 0
for i in range(n):
    res = max(res,(dp0[i] - dp1[i])*p[i])

print(dp0[0]-res)
Buggy python submission (verdict: Runtime Error):
3
3 1 2

Fixed submission:
# coding: utf-8
# Your code here!


import sys
#sys.setrecursionlimit(10**6)
readline = sys.stdin.readline 

n = int(input())
d = [int(i) for i in readline().split()]

ans = 0
for i in range(n):
    for j in range(i+1,n):
        ans += d[i]*d[j]
        

print(ans)
Buggy python submission (verdict: Runtime Error):
# coding: utf-8
# Your code here!

import sys
sys.setrecursionlimit(10**6)
readline = sys.stdin.readline #文字列入力のときは注意

#n = int(input())
def main():
    n,q = [int(i) for i in readline().split()]
    assert (n,q) != (4,3)
    
    g = [[] for _ in range(n)]
    for i in range(n-1):
        a,b = [int(i) for i in readline().split()]
        g[a-1].append(b-1)
        g[b-1].append(a-1)

    add = [0]*n
    for _ in range(q):
        p,x = [int(i) for i in readline().split()]
        add[p-1] += x

    ans = [0]*n
    #ans[0] = add[0]

    def dfs(v,p,value): #p: parent of v
        value += add[v]
        ans[v] = value
        for c in g[v]:
            if c == p: continue
            dfs(c,v,value)

    dfs(0,-1,0)

#print(add)

    print(*ans)


main()



Fixed submission:
# coding: utf-8
# Your code here!

import sys
sys.setrecursionlimit(10**6)
readline = sys.stdin.readline #文字列入力のときは注意

#n = int(input())
n,q = [int(i) for i in readline().split()]

g = [[] for _ in range(n)]
for i in range(n-1):
    a,b = [int(i) for i in readline().split()]
    g[a-1].append(b-1)
    g[b-1].append(a-1)

add = [0]*n
for _ in range(q):
    p,x = [int(i) for i in readline().split()]
    add[p-1] += x

ans = [0]*n
#ans[0] = add[0]

def dfs(v,p,value): #p: parent of v
    value += add[v]
    ans[v] = value
    for c in g[v]:
        if c == p: continue
        dfs(c,v,value)

dfs(0,-1,0)

#print(add)

print(*ans)
Buggy python submission (verdict: Time Limit Exceeded):
# coding: utf-8
# Your code here!

import sys
sys.setrecursionlimit(10**6)
readline = sys.stdin.readline #文字列入力のときは注意

#x,y = [int(i) for i in readline().split()]
MOD = 998244353
n = int(input())
s = input()

R = B = G = 0
ans = 1
for i in s:
    m = sorted([R,G,B])
    if eval(i) == m[-1]:
        ans *= n-m[-1]
        ans %= MOD
    elif eval(i) == m[1]:
        ans *= m[2]-m[1]
        ans %= MOD
    else:
        ans *= m[1]-m[0]
        ans %= MOD
    if i == "R":
        R += 1
    elif i == "G":
        G += 1
    elif i == "B":
        B += 1

print(ans)


Fixed submission:
# coding: utf-8
# Your code here!

import sys
sys.setrecursionlimit(10**6)
readline = sys.stdin.readline #文字列入力のときは注意

#x,y = [int(i) for i in readline().split()]
MOD = 998244353
n = int(input())
s = input()

R = B = G = 0
ans = 1
for i in s:
    m = sorted([R,G,B])
    if i == "R":
        c = R
        R += 1
    elif i == "G":
        c = G
        G += 1
    elif i == "B":
        c = B
        B += 1
    if c == m[-1]:
        ans *= n-m[-1]
    elif c == m[1]:
        ans *= m[2]-m[1]
    else:
        ans *= m[1]-m[0]
    
    ans %= MOD

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
# coding: utf-8
# Your code here!

import sys
sys.setrecursionlimit(10**6)
readline = sys.stdin.readline #文字列入力のときは注意

n = int(input())
a = [int(i) for i in readline().split()]
b = [int(i) for i in readline().split()]


def op(b,i):
    global ans
    if i == n-1:
        res = (b[i]-a[i])//(b[i-1]+b[0])
        b[i] -= (b[i-1]+b[0])*res
    else:
        res = (b[i]-a[i])//(b[i-1]+b[(i+1)])
        b[i] -= (b[i-1]+b[(i+1)])*res
    ans += res
    if res >= 0:
        return res
    else: return 0

def check(b,c):#c からチェック 操作ができる最初のi
#    print(b,c)
    for i in range(c,c+n):
        if op(b,i%n) > 0: return i
    else:
        return(-1)

def rev(b,i):#iから逆向きに操作
    for j in range(i-1,-n,-1):
#        print(b,j)
        if op(b,j%n) == 0: break

    
c = 0
ans = 0
while True:
    i = check(b,c)
    if i == -1: break
    rev(b,i)
    c += 1
    if c >= n: c -= n


if a == b:
    print(ans)
else:
    print(-1)












Fixed submission:
# coding: utf-8
# Your code here!

import sys
sys.setrecursionlimit(10**6)
readline = sys.stdin.readline #文字列入力のときは注意

n = int(input())
a = [int(i) for i in readline().split()]
b = [int(i) for i in readline().split()]


def op(b,i):
    global ans
    if i == n-1:
        res = (b[i]-a[i])//(b[i-1]+b[0])
        if res < 0: return 0
        b[i] -= (b[i-1]+b[0])*res
    else:
        res = (b[i]-a[i])//(b[i-1]+b[(i+1)])
        if res < 0: return 0
        b[i] -= (b[i-1]+b[(i+1)])*res
    ans += res
    return res

def check(b,c):#c からチェック 操作ができる最初のi
#    print(b,c)
    for i in range(c,c+n):
        if op(b,i%n) > 0: return i
    else:
        return(-1)

def rev(b,i):#iから逆向きに操作
    for j in range(i-1,-n,-1):
#        print(b,j)
        if op(b,j%n) == 0: break

    
c = 0
ans = 0
"""
while True:
    i = check(b,c)
    if i == -1: break
    rev(b,i)
    c += 1
    if c >= n: c -= n
"""

s = set(range(n))

while s:
    i = s.pop()
    if op(b,i) > 0:
        s.add((i-1)%n)
        s.add((i+1)%n)

if a == b:
    print(ans)
else:
    print(-1)
Buggy python submission (verdict: Runtime Error):
# coding: utf-8
# Your code here!
import sys
sys.setrecursionlimit(10**6)
readline = sys.stdin.readline #文字列入力のときは注意

n,m = [int(i) for i in readline().split()]
MOD = 10**9+7

#dp[i][j][k]
# iまで見て j個未確定、k点
dp = [[[0 for k in range(n*n)] for j in range(n+1)] for i in range(n+1)]

dp[0][0][0] = 1

for i in range(n):
    for j in range(i+1):
        for k in range(n*n):
            if k + 2*j >= n*n: continue
            dp[i+1][j+1][k+2*j] += dp[i][j][k]
            dp[i+1][j+1][k+2*j] %= MOD
            dp[i+1][j  ][k+2*j] += (2*j+1)*dp[i][j][k]
            dp[i+1][j  ][k+2*j] %= MOD
            dp[i+1][j-1][k+2*j] += j*j*dp[i][j][k]
            dp[i+1][j-1][k+2*j] %= MOD
    

#print(*dp,sep="\n")

ans = dp[-1][0][m]
print(ans)




Fixed submission:
# coding: utf-8
# Your code here!
import sys
sys.setrecursionlimit(10**6)
readline = sys.stdin.readline #文字列入力のときは注意

n,m = [int(i) for i in readline().split()]
MOD = 10**9+7

#dp[i][j][k]
# iまで見て j個未確定、k点
dp = [[[0 for k in range(n*n+1)] for j in range(n+1)] for i in range(n+1)]

dp[0][0][0] = 1

for i in range(n):
    for j in range(i+1):
        for k in range(n*n):
            if k + 2*j >= n*n: continue
            dp[i+1][j+1][k+2*j] += dp[i][j][k]
            dp[i+1][j+1][k+2*j] %= MOD
            dp[i+1][j  ][k+2*j] += (2*j+1)*dp[i][j][k]
            dp[i+1][j  ][k+2*j] %= MOD
            dp[i+1][j-1][k+2*j] += j*j*dp[i][j][k]
            dp[i+1][j-1][k+2*j] %= MOD
    

ans = dp[-1][0][m]
print(ans)
Buggy python submission (verdict: Runtime Error):
# coding: utf-8
# Your code here!

s = input()


a=int(s[0:2])
b=int(s[2:])


aY=0
bY=0
aM=0
bM=0
if 1 <= a <= 12:
    aM=1
if 1 <= b <= 12:
    bM=1

if a==0:
#    print(a,b,"a0")
    if bM==1:
        print("YYMM")
    else:
        print("NA")
elif b==0:
#    print(a,b,"b0")
    if aM==1:
        print("MMYY")
    else:
        print("NA")
else:
    if aM == 1 and bM==1:
       print("AMBIGUOUS")
    elif aM == 1:
       print("MMYY")
    elif bM == 1:
       print("YYMM")
    else:
        assert()


Fixed submission:
# coding: utf-8
# Your code here!

s = input()


a=int(s[0:2])
b=int(s[2:])


aY=0
bY=0
aM=0
bM=0
if 1 <= a <= 12:
    aM=1
if 1 <= b <= 12:
    bM=1

if a==0:
#    print(a,b,"a0")
    if bM==1:
        print("YYMM")
    else:
        print("NA")
elif b==0:
#    print(a,b,"b0")
    if aM==1:
        print("MMYY")
    else:
        print("NA")
else:
    if aM == 1 and bM==1:
       print("AMBIGUOUS")
    elif aM == 1:
       print("MMYY")
    elif bM == 1:
       print("YYMM")
    else:
        print("NA")
Buggy python submission (verdict: Runtime Error):
# coding: utf-8
# Your code here!

from collections import deque
def diameter(g):
    def bfs(start): # v からの最長点と距離を求める
        res = [-1]*(len(g))
        q = deque([start])
        res[start] = 0
        while q:
            v = q.popleft()
            for c in g[v]:
                if res[c] >= 0: continue
                res[c] = res[v] + 1 #重みつきのときは+1でなく +cost(v,c)
                q.append(c) 
        return (res[v],v)

    d0,v0 = bfs(0)
    d1,v1 = bfs(v0)
    return d1 # i0, i1 が最遠頂点対


##################################################
# coding: utf-8
# Your code here!
import sys
sys.setrecursionlimit(10**6)
readline = sys.stdin.readline
 
n = int(input())
#n,q = [int(i) for i in readline().split()]
 
g = [[] for _ in range(n)]
for i in range(n-1):
    a,b = [int(i) for i in readline().split()]
    g[a-1].append(b-1)
    g[b-1].append(a-1)

d = diameter(g)
if d%3 != 1:
    print("First")
else:
    print("Second")
    
assert n!=6
    
    







Fixed submission:
# coding: utf-8
# Your code here!

def diameter(g):
    def dfs(v,p): # v からの最長点と距離を求める
        m = 0
        i = v
        for c in g[v]:
            if c == p: continue
            mc,ic = dfs(c,v)
            mc += 1  #重みつきのときは+1でなく +cost(v,c)
            if m < mc:
                m = mc
                i = ic
        return (m,i)

    m0,i0 = dfs(0,-1)
    m1,i1 = dfs(i0,-1)
    # i0, i1 が最遠頂点対
    return m1

##################################################
# coding: utf-8
# Your code here!
import sys
sys.setrecursionlimit(10**6)
readline = sys.stdin.readline
 
n = int(input())
#n,q = [int(i) for i in readline().split()]
 
g = [[] for _ in range(n)]
for i in range(n-1):
    a,b = [int(i) for i in readline().split()]
    g[a-1].append(b-1)
    g[b-1].append(a-1)

d = diameter(g)
if d%3 != 1:
    print("First")
else:
    print("Second")
Buggy python submission (verdict: Runtime Error):
# coding: utf-8
# Your code here!
import sys, collections, bisect, math, itertools
from fractions import gcd 
#input = sys.stdin.readline #文字列入力のときは注意

m = int(input())
#s = input()
#a = [int(i) for i in input().split()]
a = [int(input()) for j in range(m+1)] # 縦「n」行

beki = 0
while a[-1] == 0:
    a.pop()
    beki+=1
if m != len(a)-1:
    m = len(a)
    a.append(0)


def get_sieve_of_eratosthenes(n):
    if not isinstance(n, int):
        raise TypeError('n is int type.')
    if n < 2:
        raise ValueError('n is more than 2')
    prime = []
    limit = math.sqrt(n)
    data = [i + 1 for i in range(1, n)]
    while True:
        p = data[0]
        if limit <= p:
            return prime + data
        prime.append(p)
        data = [e for e in data if e % p != 0]
allprimes = get_sieve_of_eratosthenes(10010)

primes=[]
def get_sieve_of_eratosthenes2():
    prime = []
    data = [i + 1 for i in range(1, 35000)]
    c=abs(a[m])
    while True:
        p = data[0]
        if 35000 <= p*p:
            return prime + data
        if c%p==0: primes.append(p)
        prime.append(p)
        data = [e for e in data if e % p != 0]

primes2=[]
def get_sieve_of_eratosthenes3():
    prime = []
    data = [i + 1 for i in range(1, 35000)]
    c=abs(a[0])
    while True:
        p = data[0]
        if 35000 <= p*p:
            return prime + data
        if c%p==0: primes2.append(p)
        prime.append(p)
        data = [e for e in data if e % p != 0]


get_sieve_of_eratosthenes2()
#print(primes)
if len(primes) == 0 and abs(a[m]) != 1:
    primes.append(abs(a[m]))
if len(primes2) == 0 and abs(a[0]) != 1:
    primes2.append(abs(a[0]))
n=m
if a[m]==0:
    primes = allprimes


primes = primes + primes2
#print(a)
#print(primes)
for p in primes:
    if p > 10**4+5:
        if sum([i%p for i in a]) == 0:
            print(p)
        continue
    coeff = list(reversed(a))
    while len(coeff) > p:
#        print(coeff,p)
        t=coeff.pop()
        coeff[-p+1]+=t
            
#    print(coeff)
    if sum([i%p for i in coeff]) == 0:
        print(p)
        
        
        
    












Fixed submission:
# coding: utf-8
# Your code here!
import sys, collections, bisect, math, itertools
from fractions import gcd 
#input = sys.stdin.readline #文字列入力のときは注意

n = int(input())
s = input()
#a = [int(i) for i in input().split()]
#m = [[int(i) for i in input().split()] for j in range(n)] # 縦「n」行

b = [0]*(n+1)
for i in range(n):
    b[i+1] += b[i] + (1 if s[i]=="#" else 0)

w = [0]*(n+1)
for i in range(n):
    w[i+1] += w[i] + (1 if s[i]=="." else 0)
#print(b,w)
ans = n
for i in range(n):
    if i != 0:
        p = b[i-1]
    else: p=0
    q = w[n]-w[i]
#    print(p,q)
    ans = min(ans,p+q)

print(min(ans,b[n]))
Buggy python submission (verdict: Runtime Error):
#a,b,c = [int(i) for i in input().split()]

import sys
input = sys.stdin.readline

SIZE=200002; 
MOD = 10**9+7
2bai= 500000000+4

inv = [0]*(SIZE+1)# inv[j] = j^{-1} mod MOD
fac = [0]*(SIZE+1)# fac[j] = j! mod MOD
finv = [0]*(SIZE+1)# finv[j] = (j!)^{-1} mod MOD
inv[1] = 1
fac[0] = fac[1] = 1
finv[0] = finv[1] = 1
for i in range(2,SIZE+1):
    inv[i] = MOD -(MOD//i)*inv[MOD%i]%MOD
    fac[i] = fac[i-1]*i%MOD
    finv[i]= finv[i-1]*inv[i]%MOD

def choose(n,r): # nCk mod MOD の計算
    if 0 <= r <= n:
        return (fac[n]*finv[r]%MOD)*finv[n-r]%MOD
    else:
        return 0



b,w = [int(i) for i in input().split()]

ans = [0]*(b+1)
ans[x] = 1

c = min(b,w)
for i in [0]*c:
    print(2bai)

ans = 2bai
for i in range(c,b+w+1):
    ans += pow(2,i-1,MOD)*(choose(i-1,i-1-w) - choose(i-1,b-1)
    ans %= MOD
    print(ans)



        
                           

Fixed submission:
#a,b,c = [int(i) for i in input().split()]

import sys
input = sys.stdin.readline

SIZE=200002; 
MOD = 10**9+7
bai= 500000000+4

inv = [0]*(SIZE+1)# inv[j] = j^{-1} mod MOD
fac = [0]*(SIZE+1)# fac[j] = j! mod MOD
finv = [0]*(SIZE+1)# finv[j] = (j!)^{-1} mod MOD
inv[1] = 1
fac[0] = fac[1] = 1
finv[0] = finv[1] = 1
for i in range(2,SIZE+1):
    inv[i] = MOD -(MOD//i)*inv[MOD%i]%MOD
    fac[i] = fac[i-1]*i%MOD
    finv[i]= finv[i-1]*inv[i]%MOD

def choose(n,r): # nCk mod MOD の計算
    if 0 <= r <= n:
        return (fac[n]*finv[r]%MOD)*finv[n-r]%MOD
    else:
        return 0



b,w = [int(i) for i in input().split()]

c = min(b,w)
for i in [0]*c:
    print(bai)

ans = bai
p=pow(bai,c+1,MOD)
for i in range(c,b+w):
#    print(p,i-1,i-w,b-1)
    ans += p*(choose(i-1,i-w) - choose(i-1,b-1))
    p= p*bai; p%=MOD
    ans = ans%MOD
    print(ans)
Buggy python submission (verdict: Runtime Error):

a,b,k=[int(i) for i in input().split()]


c=0

for i in range(1000,1,-1):
    if a%i ==0 and b%i==0:
        c+=1
    if c == k:
        ans = i
        break

print(ans)

    
    
    
    
    





Fixed submission:

a,b,k=[int(i) for i in input().split()]


c=0

ans = 1
for i in range(1000,1,-1):
    if a%i ==0 and b%i==0:
        c+=1
    if c == k:
        ans = i
        break

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
# coding: utf-8
# Your code here!

import sys
sys.setrecursionlimit(10**6)
readline = sys.stdin.readline

#n = int(input())
#n,a = [int(i) for i in readline().split()]
a,b,q = [int(i) for i in readline().split()]
s = [-10**12]+[int(input()) for i in range(a)]+[10**12]
t = [-10**12]+[int(input()) for i in range(b)]+[10**12]

xx = [int(input()) for i in range(q)]

from bisect import *
for x in xx:
    ans = 10**11
    i = bisect_left(s,x)
    j = bisect_left(t,x)
    d1 = max(s[i],t[j])-x
    d2 = x- min(s[i-1],t[j-1])

    d3 = (x-s[i-1]) + (t[j]-x) + min((x-s[i-1]), (t[j]-x))
    d4 = (x-t[j-1]) + (s[i]-x) + min((x-t[j-1]), (s[i]-x))

#    print(ans,d1,d2,d3,d4)
    ans = min(ans,d1,d2,d3,d4)
    print(ans)





Fixed submission:
# coding: utf-8
# Your code here!

import sys
sys.setrecursionlimit(10**6)
readline = sys.stdin.readline

#n = int(input())
#n,a = [int(i) for i in readline().split()]
a,b,q = [int(i) for i in readline().split()]
s = [-10**12]+[int(readline()) for i in range(a)]+[10**12]
t = [-10**12]+[int(readline()) for i in range(b)]+[10**12]

xx = [int(readline()) for i in range(q)]

from bisect import *
for x in xx:
    ans = 10**11
    i = bisect_left(s,x)
    j = bisect_left(t,x)
    d1 = max(s[i],t[j])-x
    d2 = x- min(s[i-1],t[j-1])

    d3 = (x-s[i-1]) + (t[j]-x) + min((x-s[i-1]), (t[j]-x))
    d4 = (x-t[j-1]) + (s[i]-x) + min((x-t[j-1]), (s[i]-x))

#    print(ans,d1,d2,d3,d4)
    ans = min(ans,d1,d2,d3,d4)
    print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
# coding: utf-8
# Your code here!
n=int(input())
p = [float(i) for i in input().split()]

dp=[0]*(n+1)
dp[0]=1
for i in range(n):
    for j in range(n,-1,-1):
        dp[j] = dp[j]*(1-p[i]) + dp[j-1]*p[i]
#    print(dp)

print(sum(dp[(n+1)//2:]))        

Fixed submission:
# coding: utf-8
# Your code here!
n=int(input())
p = [float(i) for i in input().split()]

dp=[0]*(n+1)
dp[0]=1
for i in range(n):
    for j in range(n,-1,-1):
        dp[j] = dp[j]*(1-p[i]) + dp[j-1]*p[i]
#    print(dp)

print(sum(dp[(n+1)//2:]))