Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")


n = int(input())
a = list(map(int, input().split()))

pp = [None]*n
v = 1
for i in range(n):
    pp[i] = v
    v *= 2
    v %= M

a.sort()
a = a[::-1]
M = 10**9+7
ans = 0
ans += a[0]*(pow(2, 0, M))*pow(2, n-1,M)
for i in range(1,n):
    num = a[i]
    ans += num*(pp[i] + i*pp[i-1])*pp[n-i-1]
    ans %= M
ans *= pow(2,n,M)
ans %= M
print(ans)

Fixed submission:
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")

n = int(input())
a = list(map(int, input().split()))
a.sort()
a = a[::-1]
M = 10**9+7
ans = 0
ans += a[0]*(pow(2, 0, M))*pow(2, n-1,M)
for i in range(1,n):
    num = a[i]
    ans += num*(pow(2, i, M) + i*pow(2,i-1,M))*pow(2,n-i-1,M)
    ans %= M
ans *= pow(2,n,M)
ans %= M
print(ans)

Buggy python submission (verdict: Runtime Error):
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")


pp = [None]*n
v = 1
for i in range(n):
    pp[i] = v
    v *= 2
    v %= M
    
n = int(input())
a = list(map(int, input().split()))
a.sort()
a = a[::-1]
M = 10**9+7
ans = 0
ans += a[0]*(pow(2, 0, M))*pow(2, n-1,M)
for i in range(1,n):
    num = a[i]
    ans += num*(pp[i] + i*pp[i-1])*pp[n-i-1]
    ans %= M
ans *= pow(2,n,M)
ans %= M
print(ans)

Fixed submission:
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")

n = int(input())
a = list(map(int, input().split()))
a.sort()
a = a[::-1]
M = 10**9+7
ans = 0
ans += a[0]*(pow(2, 0, M))*pow(2, n-1,M)
for i in range(1,n):
    num = a[i]
    ans += num*(pow(2, i, M) + i*pow(2,i-1,M))*pow(2,n-i-1,M)
    ans %= M
ans *= pow(2,n,M)
ans %= M
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")


n = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
da = []
db = []
for i in range(n-1):
    da.append(A[i+1] ^ A[i])
    db.append(B[i+1] ^ B[i])
da.append(A[-1]^A[0])
db.append(B[-1]^B[0])
    
import random
M = 10**9+7
b = random.choice(range(M))
def rhash(s):
    import random
    ans = 0
    v = 1
    for item in s:
        ans += item*v
        v *= b
        ans %= M
        v %= M
    return ans

h = rhash(db)
g = rhash(da)
t = pow(b, n, M)
ans = []
for i in range(n):
    if h==g:
        if all(da[(j+i)%n]==db[j] for j in range(n)):
            ans.append((i,A[i]^B[0]))
    h *= b
    h = h - t*db[n-1-i] + db[n-1-i]
    h %= M
    
write("\n".join(" ".join(map(str, item)) for item in ans))

Fixed submission:
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")


n = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
da = []
db = []
for i in range(n-1):
    da.append(A[i+1] ^ A[i])
    db.append(B[i+1] ^ B[i])
da.append(A[-1]^A[0])
db.append(B[-1]^B[0])
    
import random
M = 10**9+7
b = random.choice(range(M))
def rhash(s):
    import random
    ans = 0
    v = 1
    for item in s:
        ans += item*v
        v *= b
        ans %= M
        v %= M
    return ans

h = rhash(db)
g = rhash(da)
t = pow(b, n, M)
ans = []
for i in range(n):
    if h==g:
#         if all(da[(j+i)%n]==db[j] for j in range(n)):
        ans.append((i,A[i]^B[0]))
    h *= b
    h = h - t*db[n-1-i] + db[n-1-i]
    h %= M
    
write("\n".join(" ".join(map(str, item)) for item in ans))
Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")


h,w = list(map(int, input().split()))
n = h*w
a = [None]*h
b = [None]*h
for i in range(h):
    a[i] = list(map(int, input().split()))
for i in range(h):
    b[i] = list(map(int, input().split()))
# for i in range(h):
#     for j in range(h):
dp = [[None]*(w) for _ in range(h)]
# mask = 1<<6400

dp[0][0] = set([a[0][0]-b[0][0], b[0][0]-a[0][0]])
for i in range(h):
    for j in range(w):
        if i==j==0:
            continue
        v =abs(a[i][j]-b[i][j])
        s = set()
        if i>0:
            for item in dp[i-1][j]:
                s.add(item+v)
                s.add(item-v)
        if j>0:
            for item in dp[i][j-1]:
                s.add(item+v)
                s.add(item-v)
        dp[i][j] = s
ans = min(abs(item) for item in dp[h-1][w-1])
print(ans)

Fixed submission:
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")


h,w = list(map(int, input().split()))
n = h*w
a = [None]*h
b = [None]*h
for i in range(h):
    a[i] = list(map(int, input().split()))
for i in range(h):
    b[i] = list(map(int, input().split()))
# for i in range(h):
#     for j in range(h):
dp = [[None]*(w) for _ in range(h)]
mask = (1<<12800)-1
m = 6400
dp[0][0] = 1<<(a[0][0]-b[0][0]+m) | 1<<(b[0][0]-a[0][0]+m)
for i in range(h):
    for j in range(w):
        if i==j==0:
            continue
        v = abs(a[i][j]-b[i][j])
        bit = 0
        if i>0:
            bit |= (dp[i-1][j]<<v)&mask
            bit |= (dp[i-1][j]>>v)
        if j>0:
            bit |= (dp[i][j-1]<<v)&mask
            bit |= (dp[i][j-1]>>v)
        dp[i][j] = bit
# ans = min(abs(item) for item in dp[h-1][w-1])
ans = min(abs(val-m) for val in range(12800) if dp[h-1][w-1]>>val&1)
print(ans)
Buggy python submission (verdict: Runtime Error):
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")


# inputna
s = input()
t = input()

l = [chr(v) for v in range(ord("a"), ord("z")+1)]
d = {c:i for i,c in enumerate(l)}

def snx(s, target=None, reverse=False, loop=False):
    """文字列sの各要素について、cがiより→で最初に現れる位置n[i][c]
    loop=Trueのとき周回した先のインデックスまで求める
    """
    if target is None:
        target = [chr(v) for v in range(ord("a"), ord("z")+1)]
    d = {c:None for c in target}
    nx = [[None]*len(target) for _ in range(len(s))]
    if not reverse:
        i = len(s)-1
        for c in reversed(s):
            d[c] = i
            for j,t in enumerate(target):
                nx[i][j] = d[t]
            i -= 1
        if loop:
            for i in range(len(s)):
                for j in range(len(target)):
                    if nx[i][j] is None:
                        nx[i][j] = nx[0][j]
    else:
        i = 0
        for c in s:
            d[c] = i
            for j,t in enumerate(target):
                nx[i][j] = d[t]
            i += 1
        if loop:
            for i in range(len(s)):
                for j in range(len(target)):
                    if nx[i][j] is None:
                        nx[i][j] = nx[-1][j]
    return nx
nx = snx(s, loop=True)
c = -1
ans = 0
for i in range(len(t)):
    nc = nx[c+1][d[t[i]]]
    if nc is None:
        ans = -1
        break
    elif nc>c:
        ans += nc-c
    else:
        ans += nc+len(s)-c
    c = nc
print(ans)

Fixed submission:
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")


# inputna
s = input()
t = input()

l = [chr(v) for v in range(ord("a"), ord("z")+1)]
d = {c:i for i,c in enumerate(l)}

def snx(s, target=None, reverse=False, loop=False):
    """文字列sの各要素について、cがiより→で最初に現れる位置n[i][c]
    loop=Trueのとき周回した先のインデックスまで求める
    """
    if target is None:
        target = [chr(v) for v in range(ord("a"), ord("z")+1)]
    d = {c:None for c in target}
    nx = [[None]*len(target) for _ in range(len(s))]
    if not reverse:
        i = len(s)-1
        for c in reversed(s):
            d[c] = i
            for j,t in enumerate(target):
                nx[i][j] = d[t]
            i -= 1
        if loop:
            for i in range(len(s)):
                for j in range(len(target)):
                    if nx[i][j] is None:
                        nx[i][j] = nx[0][j]
    else:
        i = 0
        for c in s:
            d[c] = i
            for j,t in enumerate(target):
                nx[i][j] = d[t]
            i += 1
        if loop:
            for i in range(len(s)):
                for j in range(len(target)):
                    if nx[i][j] is None:
                        nx[i][j] = nx[-1][j]
    return nx
nx = snx(s, loop=True)
c = -1
ans = 0
for i in range(len(t)):
    nc = nx[(c+1)%len(nx)][d[t[i]]]
    if nc is None:
        ans = -1
        break
    elif nc>c:
        ans += nc-c
    else:
        ans += nc+len(s)-c
    c = nc
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
# 1(黒マス)を探す
import numpy as np
h, w = [int(item) for item in input().split(" ")]
a = np.zeros((h,w), dtype=int)
for i in range(h):
    tmp = [0 if item=="." else 1 for item in input()]
    a[i] = tmp
    
def one(a):
    n = len(a)
    b = np.zeros((n,), dtype=int)
    c = np.zeros((n,), dtype=int)
    out = np.zeros((n,), dtype=int)
    out2 = np.zeros((n,), dtype=int)
    out[:] = -1
    out2[:] = -1
    last = -1
    for i,item in enumerate(a):
        if item==1:
            last = i
        b[i] = last
    last = -1
    for i in reversed(range(n)):
        item = a[i]
        if item==1:
            last = i
        c[i] = last
    b[b==-1] = n+2
    c[c==-1] = n+2
    out[b!=-1] = b[b!=-1]
    out2[c!=-1] = c[c!=-1]
    dist = np.abs(np.arange(n) - out)
    dist[out==n+2] = n+2
    dist2 = np.abs(np.arange(n) - out2)
    dist2[out2==n+2] = n+2
    return np.where(dist<dist2, dist, dist2)    
def one2(a):
    dist = np.zeros((a.shape[0], ), dtype=int)
    dist2 = np.zeros((a.shape[0], ), dtype=int)
    last = 0
    lastd = a[0]
    for i, item in enumerate(a):
        if a[i] < (i-last)+lastd:
            v = a[i]
            last = i
            lastd = a[i]
        else:
            v = (i - last) + lastd
        dist[i] = v
    last = len(a)-1
    lastd = a[-1]
    for i in reversed(range(len(a))):
        item = a[i]
        if a[i] < (last-i)+lastd:
            v = a[i]
            last = i
            lastd = a[i]
        else:
            v = (last-i) + lastd
        dist2[i] = v
    return np.where(dist<dist2, dist, dist2)
def two(a):
    out = np.zeros(a.shape, dtype=int)
    for i in range(a.shape[0]):
        out[i] = one(a[i])
    for j in range(a.shape[1]):
        tmp = one(a[:,j])
        tmp2 = one2(out[:,j])
        out[:,j] = np.where(tmp<tmp2, tmp, tmp2)
    return out

print(np.max(two(a)))

Fixed submission:
# AGC033A

import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")


h,w = map(int, input().split())
s = [None] * h
for i in range(h):
    s[i] = input()

r = h
c = w
ds = [[10**15]*c for _ in range(r)]
for i in range(r):
    prev = -1
    for j in range(c):
        if s[i][j]=="#":
            prev = j
        if prev>=0:
            ds[i][j] = j-prev
    prev = -1
    for j in range(c-1,-1,-1):
        if s[i][j]=="#":
            prev = j
        if prev>=0:
            ds[i][j] = min(ds[i][j], prev-j)
for j in range(c):
    prev = -1
    prevind = -1
    for i in range(r):
        if prev<0 or ds[i][j]<prev+(i-prevind):
            prev = ds[i][j]
            prevind = i
        if prev>=0:
            ds[i][j] = min(ds[i][j], prev+(i-prevind))
    prev = -1
    prevind = -1
    for i in range(r-1, -1, -1):
        if prev<0 or ds[i][j]<prev+(prevind-i):
            prev = ds[i][j]
            prevind = i
        if prev>=0:
            ds[i][j] = min(ds[i][j], prev+(prevind-i))
print(max(max(item) for item in ds))
Buggy python submission (verdict: Runtime Error):
# AGC033C

import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")


from collections import defaultdict
n = int(input())
ns = defaultdict(set)
for _ in range(n-1):
    u,v = map(int, input().split())
    ns[u-1].add(v-1)
    ns[v-1].add(u-1)

def bfs(start):
    from queue import deque
    q = deque([start])
    seen = [None] * n
    seen[start] = 0
    dd = 0
    target = None
    while q:
        u = q.pop()
        d = seen[u]
        if d>dd:
            dd = d
            target = u
        for v in ns[u]:
            if seen[v] is None:
                seen[v] = d + 1
                q.appendleft(v)
    return target, dd
target, tmp = bfs(0)
_, d = bfs(target)
if (d-1)%3!=0:
    print("First")
else:
    print("Second")

Fixed submission:
# AGC033C

import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")


from collections import defaultdict
n = int(input())
ns = defaultdict(set)
for _ in range(n-1):
    u,v = map(int, input().split())
    ns[u-1].add(v-1)
    ns[v-1].add(u-1)

def bfs(start):
    from queue import deque
    q = deque([start])
    seen = [None] * n
    seen[start] = 0
    dd = 0
    target = start
    while q:
        u = q.pop()
        d = seen[u]
        if d>dd:
            dd = d
            target = u
        for v in ns[u]:
            if seen[v] is None:
                seen[v] = d + 1
                q.appendleft(v)
    return target, dd
target, tmp = bfs(0)
_, d = bfs(target)
if (d-1)%3!=0:
    print("First")
else:
    print("Second")
Buggy python submission (verdict: Runtime Error):
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")


n = int(input())
a = [int(input()) for _ in range(n)]
M = 998244353
s = sum(a)
assert s%2==1
l = s//2 + int(s%2==1)
# dp = [[0]*(s+1) for _ in range(n+1)]
dp = [0]*(s+1)
dp[0] = pow(2, n, M)
inv2 = pow(2, M-2, M)
for i in range(1,n+1):
    num = a[i-1]
    for j in range(s, -1, -1):
        if j>=num:
            dp[j] += dp[j-num]*inv2
            dp[j] %= M
# if s%2==0:
#     dp[s//2] //= 2
val = sum(dp[i] for i in range(l, s+1)) * 3
ans = (pow(3,n,M) - val)%M
print(ans%M)

Fixed submission:
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")


n = int(input())
a = [int(input()) for _ in range(n)]
M = 998244353
s = sum(a)
l = s//2 + int(s%2==1)
# dp = [[0]*(s+1) for _ in range(n+1)]
dp = [0]*(s+1)
dp2 = [0]*(s+1)
dp[0] = pow(2, n, M)
dp2[0] = 1
inv2 = pow(2, M-2, M)
for i in range(1,n+1):
    num = a[i-1]
    for j in range(s, -1, -1):
        if j>=num:
            dp[j] += dp[j-num]*inv2
            dp[j] %= M
            dp2[j] += dp2[j-num]
            dp2[j] %= M
val = sum(dp[i] for i in range(l, s+1)) * 3
if s%2==0:
    val -= dp2[s//2]*3
ans = (pow(3,n,M) - val)%M
print(ans%M)
Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")


s = input()
n = len(s)
prev = s[0]
ans = 0
l = s
while l:
    update = False
    l = []
    i = 1
    while i<len(s):
        if s[i-1]!=s[i]:
            l.append(i-1)
            l.append(i)
            update = True
            ans += 2
            i += 2
        else:
            i += 1
    s = "".join(s[i] for i in range(len(s)) if i not in l)
    if not update:
        break
        
print(ans)

Fixed submission:
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")

s = input()
n = len(s)
last = []
ans = 0
i = 0
last = []
while i<n:
    if last and s[i]!=last[-1]:
        ans += 2
        last.pop()
        i += 1
    else:
        last.append(s[i])
        i += 1
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")



n, m = map(int, input().split())
from collections import defaultdict
ns = defaultdict(set)
pps = [set() for _ in range(n)]
for i in range(n-1+m):
    a,b = map(int, input().split())
    a -= 1
    b -= 1
    ns[a].add(b)
    pps[b].add(a)

for i,s in enumerate(pps):
    if not s:
        r = i
        
ps = [None] * n    
def bfs(start):
    from queue import deque
    q = deque([start])
    seen = [None] * n
    seen[start] = 0
    while q:
        u = q.pop()
        d = seen[u]
        for v in ns[u]:
            if seen[v] is None or seen[v]<d+1:
                seen[v] = d + 1
                q.appendleft(v)
                ps[v] = u+1
    return seen

ds = bfs(r)
ps[r] = 0
write("\n".join(map(str, ps)))

Fixed submission:
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")


n, m = map(int, input().split())
from collections import defaultdict
ns = defaultdict(set)
pps = [set() for _ in range(n)]
for i in range(n-1+m):
    a,b = map(int, input().split())
    a -= 1
    b -= 1
    ns[a].add(b)
    pps[b].add(a)

for i,s in enumerate(pps):
    if not s:
        r = i
        
def tps(start):
    q = [start]
    # 行きがけ順
    seen = [None] * n
    # 帰りがけ順
    done = [None] * n
    d0 = 0
    d1 = n
    seen[start] = d0
    while q:
        u = q.pop()
        if u>=0:
            q.append(~u)
            for v in ns[u]:
                if seen[v] is None:
                    d0 += 1
                    seen[v] = d0
                    q.append(v)
        else:
            d1 -= 1
            done[~u] = d1            
    return seen, done

done = [None]*n
val = n
def dfs(u, val):
    for v in ns[u]:
        if done[v] is not None:
            continue
        val = dfs(v, val)
    val = val - 1
    done[u] = val
    return val

# seen, done = tps(r)
dfs(r, n)
ps = [-1] * n
ps[r] = 0
for i in range(n):
    if i==r:
        continue
    val = max(pps[i], key=lambda item: done[item])
    ps[i] = val+1
write("\n".join(map(str, ps)))
Buggy python submission (verdict: Runtime Error):
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")

n = int(input())
a = []
for i in range(n):
    a.append(list(map(int, input().split())))
    
dp = [[0]*pow(2,n) for _ in range(n+1)]
dp[0][0] = 1
for i in range(1,n+1):
    comb = (1<<(i)) - 1
    while comb < 1 << n:
        # ここに処理
        for j in range(n):
            if comb>>j and a[i-1][j]:
                dp[i][comb] += dp[i-1][comb-(1<<j)]
                dp[i][comb] %= M
        x = comb & (-comb); y = comb + x
        comb = (((comb&~y) // x )>>1) | y
print(dp[n][pow(2,n)-1])

Fixed submission:
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")


n = int(input())
a = []
for i in range(n):
    a.append(list(map(int, input().split())))
    
dp = [[0]*pow(2,n) for _ in range(n+1)]
dp[0][0] = 1
M = 10**9+7
from itertools import combinations
for i in range(1,n+1):
    for c in combinations(range(n), i):
        b = 0
        for item in c:
            b += 1<<item
        for item in c:
            if a[i-1][item]:
                dp[i][b] += dp[i-1][b-(1<<item)]
                dp[i][b] %= M
print(dp[n][pow(2,n)-1])
Buggy python submission (verdict: Runtime Error):
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")


n = int(input())
ns = [[] for _ in range(n)]
for i in range(n-1):
    u,v = map(int, input().split())
    u -= 1
    v -= 1
    ns[u].append(v)
    ns[v].append(u)

M = 10**9+7
def sub(u, p):
    v1 = 1 # 白
    v2 = 1 # 黒
    for v in ns[u]:
        if v==p:
            continue
        w1, w2 = sub(v, u)
        v1 *= (w1+w2)
        v2 *= w1
        v1 %= M
        v2 %= M
    return v1, v2
sub(0, -1)
print((d1[0]+d2[0])%M)

Fixed submission:
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")


n = int(input())
ns = [[] for _ in range(n)]
for i in range(n-1):
    u,v = map(int, input().split())
    u -= 1
    v -= 1
    ns[u].append(v)
    ns[v].append(u)

d1 = [None]*n
d2 = [None]*n
M = 10**9+7
def sub(u, p):
    if d1[u] is not None:
        return d1[u], d2[u]
    v1 = 1 # 白
    v2 = 1 # 黒
    for v in ns[u]:
        if v==p:
            continue
        w1, w2 = sub(v, u)
        v1 *= (w1+w2)
        v2 *= w1
        v1 %= M
        v2 %= M
    d1[u] = v1
    d2[u] = v2
    return v1, v2
sub(0, -1)
print((d1[0]+d2[0])%M)
Buggy python submission (verdict: Runtime Error):
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")


n = int(input())
s = input()
dp = [[0]*(n+1) for _ in range(n+1)]
dp[1][1] = 1
for i in range(2, n+1):
    v = 0
    if s[i-2]=="<":
        for j in range(1,i+1):
            # j: 最後の数
            dp[i][j] = v
            v += dp[i-1][j]
            v %= M
        dp[i][i] = v
    else:
        for j in range(i,1,-1):
            # j: 最後の数
            dp[i][j] = v
            v += dp[i-1][j-1]
            v %= M
        dp[i][1] = v
#     print(dp)
ans = 0
for item in dp[n]:
    ans += item
    ans %= M
print(ans)

Fixed submission:
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")


n = int(input())
s = input()
dp = [[0]*(n+1) for _ in range(n+1)]
dp[1][1] = 1
M = 10**9+7
for i in range(2, n+1):
    v = 0
    if s[i-2]=="<":
        for j in range(1,i+1):
            # j: 最後の数
            dp[i][j] = v
            v += dp[i-1][j]
            v %= M
        dp[i][i] = v
    else:
        for j in range(i,1,-1):
            # j: 最後の数
            dp[i][j] = v
            v += dp[i-1][j-1]
            v %= M
        dp[i][1] = v
#     print(dp)
ans = 0
for item in dp[n]:
    ans += item
    ans %= M
print(ans)
Buggy python submission (verdict: Runtime Error):
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")


n,k = map(int, input().split())
a = [0] + list(map(int, input().split()))

import numpy as np
c = np.cumsum(a)
b = c.reshape(-1,1) - c
l = len(bin(b.max())[2:])
s = set()
for i in range(1,n+1):
    for j in range(i):
        s.add(bin(b[i,j])[2:].rjust(l, "0"))
ans = 0
for i in range(l):
    count = 0
    tmp = set()
    for item in s:
        if item[i]=="0":
            pass
        else:
            count += 1
            tmp.add(item)
    if count>=k:
        ans+= 2**(l-i-1)
    s = tmp
print(ans)

Fixed submission:
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")

n,k = map(int, input().split())
a = [0] + list(map(int, input().split()))

import numpy as np
c = np.cumsum(a)
b = c.reshape(-1,1) - c
l = int(np.log2(b.max())) + 1
s = set()
for i in range(1,n+1):
    for j in range(i):
        s.add(bin(b[i,j])[2:].rjust(l, "0"))
ans = 0
for i in range(l):
    count = 0
    tmp = set()
    for item in s:
        if item[i]=="0":
            pass
        else:
            count += 1
            tmp.add(item)
    if count>=k:
        ans+= 2**(l-i-1)
        s = tmp
print(ans)