Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
n, s = map(int, input().split())
a = list(map(int, input().split()))

MOD = 998244353

dp = [[0 for _ in range(s + 1)] for _ in range(n + 1)]

ans = 0

for i, x in enumerate(a):
    if x < s:
        dp[i+1][x] = i + 1
    if x == s:
        ans = (ans + (n-i) * (i+1)) % MOD
    for j in range(1, s):
        if dp[i][j] > 0:
            dp[i+1][j] = (dp[i+1][j] + dp[i][j]) % MOD
            if j + x < s:
                dp[i+1][j+x] = (dp[i+1][j+x] + dp[i][j]) % MOD
            elif j + x == s:
                ans = (ans + dp[i][j] * (n-i)) % MOD

print(ans)

Fixed submission:
n, s = map(int, input().split())
a = list(map(int, input().split()))

MOD = 998244353

dp = [[0 for _ in range(s + 1)] for _ in range(n + 1)]

ans = 0

for i, x in enumerate(a):
    if x < s:
        dp[i+1][x] = i + 1
    if x == s:
        ans = (ans + (n-i) * (i+1)) % MOD
    for j in range(1, s):
        if dp[i][j] > 0:
            dp[i+1][j] = (dp[i+1][j] + dp[i][j]) % MOD
            if j + x < s:
                dp[i+1][j+x] = (dp[i+1][j+x] + dp[i][j]) % MOD
            elif j + x == s:
                ans = (ans + dp[i][j] * (n-i)) % MOD

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n, p = map(int, input().split())
s = list(input())

if p in [2, 5]:
    ans = 0
    for i, x in enumerate(s):
        if int(x) % p == 0:
            ans += i + 1
    print(ans)
    exit()

x = [0] * p
x[0] = 1
for i in range(n-1, -1, -1):
    x[int(''.join(s[i:])) % p] += 1

ans = 0

for z in x:
    ans += z * (z-1) // 2

print(ans)


Fixed submission:
n, p = map(int, input().split())
s = list(map(int, list(input())))

if p in [2, 5]:
    ans = 0
    for i, x in enumerate(s):
        if x % p == 0:
            ans += i + 1
    print(ans)
    exit()

x = [0] * p
x[0] = 1
temp = 0
d = 1
for i in range(n-1, -1, -1):
    temp = (temp + s[i] * d) % p
    x[temp] += 1
    d = (d * 10) % p

ans = 0

for z in x:
    ans += z * (z-1) // 2

print(ans)
Buggy python submission (verdict: Runtime Error):
n = int(input())
a = list(map(int, input().split())
if len(set(a)) == n:
         print('YES')
else:
         print('NO')

Fixed submission:
n = int(input())
a = list(map(int, input().split()))
if len(set(a)) == n:
    print('YES')
else:
    print('NO')
Buggy python submission (verdict: Time Limit Exceeded):
# = int(input())
# = map(int, input().split())
# = list(map(int, input().split()))
# = list(input())
# = [tuple(map(int, input().split())) for _ in range(n)]

n, d, a = map(int, input().split())
xh = [list(map(int, input().split())) for _ in range(n)]

xh.sort()

ans = 0
L = 0
H = 0
while L < n:
    while H < n:
        if xh[H][0] > xh[L][0] + d * 2:
            H -= 1
            break
        H += 1
    if H == n:
        H -= 1

    temp = xh[L][1] // a
    if xh[L][1] % a > 0:
        temp += 1
    ans += temp
    temp *= a
    xh[L][1] = 0
    for i in range(L+1, H+1):
        xh[i][1] -= temp

    while xh[L][1] <= 0:
        L += 1
        if L >= n:
            break

print(ans)

Fixed submission:
# = int(input())
# = map(int, input().split())
# = list(map(int, input().split()))
# = list(input())
# = [tuple(map(int, input().split())) for _ in range(n)]

n, d, a = map(int, input().split())
xh = [list(map(int, input().split())) for _ in range(n)]

xh.sort()

R = [0] * n
H = 0
for L in range(n):
    while H < n:
        if xh[H][0] > xh[L][0] + d * 2:
            H -= 1
            break
        H += 1
    if H == n:
        H -= 1
    R[L] = H + 1

cs = [0] * (n+1)
H = n - 1
ans = 0
for i in range(n-1, -1, -1):
    x = xh[i][1] // a
    if xh[i][1] % a > 0:
        x += 1
    y = cs[i+1] - cs[R[i]]
    if y >= x:
        cs[i] = cs[i+1]
    else:
#        ans += x - y
        cs[i] = cs[i+1] + x - y

print(cs[0])

Buggy python submission (verdict: Time Limit Exceeded):
# = int(input())
# = map(int, input().split())
# = list(map(int, input().split()))
# = list(input())
# = [tuple(map(int, input().split())) for _ in range(n)]

n, d, a = map(int, input().split())
xh = [list(map(int, input().split())) for _ in range(n)]

xh.sort()

ans = 0
L = 0
H = 0
while L < n:
    while H < n:
        if xh[H][0] > xh[L][0] + d * 2:
            H -= 1
            break
        H += 1
    if H == n:
        H -= 1

    temp = xh[L][1] // a
    if xh[L][1] % a > 0:
        temp += 1
    ans += temp
    temp *= a
    xh[L][1] = 0
    for i in range(L+1, H+1):
        xh[i][1] -= temp

    while xh[L][1] <= 0:
        L += 1
        if L >= n:
            break

print(ans)

Fixed submission:
# = int(input())
# = map(int, input().split())
# = list(map(int, input().split()))
# = list(input())
# = [tuple(map(int, input().split())) for _ in range(n)]

n, d, a = map(int, input().split())
xh = [list(map(int, input().split())) for _ in range(n)]

xh.sort()

R = [0] * n
H = 0
for L in range(n):
    while H < n:
        if xh[H][0] > xh[L][0] + d * 2:
            H -= 1
            break
        H += 1
    if H == n:
        H -= 1
    R[L] = H + 1

cs = [0] * (n+1)
H = n - 1
ans = 0
for i in range(n-1, -1, -1):
    x = xh[i][1] // a
    if xh[i][1] % a > 0:
        x += 1
    y = cs[i+1] - cs[R[i]]
    if y >= x:
        cs[i] = cs[i+1]
    else:
#        ans += x - y
        cs[i] = cs[i+1] + x - y

print(cs[0])
Buggy python submission (verdict: Time Limit Exceeded):
# = int(input())
# = map(int, input().split())
# = list(map(int, input().split()))
# = list(input())
# = [tuple(map(int, input().split())) for _ in range(n)]

n = int(input())
ab = [tuple(map(lambda x:int(x)-1, input().split())) for _ in range(n-1)]
m = int(input())
uv = [tuple(map(lambda x:int(x)-1, input().split())) for _ in range(m)]

e = [[] for _ in range(n)]
i = 0
for a, b in ab:
    e[a].append([b, i])
    e[b].append([a, i])
    i += 1

def func(x, g, p):
    #print(x, g, p, e[x])
    if len(e[x]) == 1 and p != -1:
        return -1
    for edge in e[x]:
        if edge[0] == p:
            continue
        elif edge[0] == g:
            #print(edge)
            return 1 << edge[1]
        temp = func(edge[0], g, x)
        #print(temp, x, g, p)
        if temp >= 0:
            #print(edge[1])
            return temp + (1 << edge[1])
    return -1

p = []
for u, v in uv:
    p.append(func(u, v, -1))

#print(p)
flag = -1
ans = 2 ** (n-1)
#print(ans)
base = 2 ** (n-1)
for i in range(1, 1 << m):
    temp = list(reversed(list(str(bin(i)))[2:]))
    c = 0
    #print(temp)
    for j, x in enumerate(temp):
        if x == '1':
            c = c | p[j]
    #print(bin(base + c))
    hoge = str(bin(base + c)).count('0') - 1
    if temp.count('1') % 2 == 0:
        flag = 1
    else:
       flag = -1
    ans += flag * (2 ** hoge)
    #flag *= -1
print(ans)


Fixed submission:
# = int(input())
# = map(int, input().split())
# = list(map(int, input().split()))
# = list(input())
# = [tuple(map(int, input().split())) for _ in range(n)]

n = int(input())
ab = [tuple(map(lambda x:int(x)-1, input().split())) for _ in range(n-1)]
m = int(input())
uv = [tuple(map(lambda x:int(x)-1, input().split())) for _ in range(m)]

e = [[] for _ in range(n)]
i = 0
for a, b in ab:
    e[a].append([b, i])
    e[b].append([a, i])
    i += 1

def func(x, g, p):
    #print(x, g, p, e[x])
    if len(e[x]) == 1 and p != -1:
        return -1
    for edge in e[x]:
        if edge[0] == p:
            continue
        elif edge[0] == g:
            #print(edge)
            return 1 << edge[1]
        temp = func(edge[0], g, x)
        #print(temp, x, g, p)
        if temp >= 0:
            #print(edge[1])
            return temp + (1 << edge[1])
    return -1

p = []
for u, v in uv:
    p.append(func(u, v, -1))

#print(p)
flag = -1
ans = 2 ** (n-1)
#print(ans)
base = 2 ** (n-1)
for i in range(1, 1 << m):
    temp = list(reversed(list(str(bin(i)))[2:]))
    c = 0
    #print(temp)
    for j, x in enumerate(temp):
        if x == '1':
            c = c | p[j]
    #print(bin(base + c))
    hoge = str(bin(base + c)).count('0') - 1
    if temp.count('1') % 2 == 0:
        flag = 1
    else:
       flag = -1
    ans += flag * (2 ** hoge)
    #flag *= -1
print(ans)
Buggy python submission (verdict: Runtime Error):
n, k, s = map(int, input().split())

if s == 10 ** 9:
    ans = []
    for _ in range(k):
        ans.append(str(s))
    for _ in range(n-k):
        ans.append('1')
    print(' '.join(ans))
else:
    ans = []
    for _ in range(k):
        ans.append(str(s))
    for _ in range(n-k):
        ans.appned(str(s+1))
    print(' '.join(ans))

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

if s == 10 ** 9:
    ans = []
    for _ in range(k):
        ans.append(str(s))
    for _ in range(n-k):
        ans.append('1')
    print(' '.join(ans))
else:
    ans = []
    for _ in range(k):
        ans.append(str(s))
    for _ in range(n-k):
        ans.append(str(s+1))
    print(' '.join(ans))
Buggy python submission (verdict: Runtime Error):
n, m = map(int, input().split())
a = list(map(lambda x:int(x) // 2, input().split()))

def gcd(a, b):
	while b:
		a, b = b, a % b
	return a

def lcm(a, b):
	return a * b // gcd (a, b)

temp = lcm(a[0], a[1])
if (temp // a[0]) % 2 == 0 or (temp // a[1]) % 2 == 0:
    print(0)
    exit()

if n > 2:
    for y in a[2:]:
        temp = lcm(temp, y)
        if (temp // y) % 2 == 0 or temp > m:
            print(0)
            exit()

ans = m // temp
print(ans - ans // 2)

Fixed submission:
n, m = map(int, input().split())
a = list(map(lambda x:int(x) // 2, input().split()))

a = sorted(list(set(a)))

def gcd(a, b):
	while b:
		a, b = b, a % b
	return a

def lcm(a, b):
	return a * b // gcd (a, b)

if len(a) == 1:
    ans = m // a[0]
    print(ans - ans // 2)
    exit()

temp = lcm(a[0], a[1])
if (temp // a[0]) % 2 == 0 or (temp // a[1]) % 2 == 0:
    print(0)
    exit()

for y in a[2:]:
    temp = lcm(temp, y)
    if (temp // y) % 2 == 0 or temp > m:
        print(0)
        exit()

ans = m // temp
print(ans - ans // 2)

Buggy python submission (verdict: Runtime Error):
n, m = map(int, input().split())
a = list(map(lambda x:int(x) // 2, input().split()))

def gcd(a, b):
	while b:
		a, b = b, a % b
	return a

def lcm(a, b):
	return a * b // gcd (a, b)

temp = lcm(a[0], a[1])
if (temp // a[0]) % 2 == 0 or (temp // a[1]) % 2 == 0:
    print(0)
    exit()

for y in a[2:]:
    temp = lcm(temp, y)
    if (temp // y) % 2 == 0 or temp > m:
        print(0)
        exit()

ans = m // temp
print(ans - ans // 2)

Fixed submission:
n, m = map(int, input().split())
a = list(map(lambda x:int(x) // 2, input().split()))

a = sorted(list(set(a)))

def gcd(a, b):
	while b:
		a, b = b, a % b
	return a

def lcm(a, b):
	return a * b // gcd (a, b)

if len(a) == 1:
    ans = m // a[0]
    print(ans - ans // 2)
    exit()

temp = lcm(a[0], a[1])
if (temp // a[0]) % 2 == 0 or (temp // a[1]) % 2 == 0:
    print(0)
    exit()

for y in a[2:]:
    temp = lcm(temp, y)
    if (temp // y) % 2 == 0 or temp > m:
        print(0)
        exit()

ans = m // temp
print(ans - ans // 2)

Buggy python submission (verdict: Runtime Error):
n, m = map(int, input().split())
a = list(map(lambda x:int(x) // 2, input().split()))

def gcd(a, b):
	while b:
		a, b = b, a % b
	return a

def lcm(a, b):
	return a * b // gcd (a, b)

temp = lcm(a[0], a[1])
if (temp // a[0]) % 2 == 0 or (temp // a[1]) % 2 == 0:
    print(0)
    exit()

for y in a[2:]:
    temp = lcm(temp, y)
    if (temp // y) % 2 == 0 or temp > m:
        print(0)
        exit()

ans = m // temp
print(ans - ans // 2)

Fixed submission:
n, m = map(int, input().split())
a = list(map(lambda x:int(x) // 2, input().split()))

a = sorted(list(set(a)))

def gcd(a, b):
	while b:
		a, b = b, a % b
	return a

def lcm(a, b):
	return a * b // gcd (a, b)

if len(a) == 1:
    ans = m // a[0]
    print(ans - ans // 2)
    exit()

temp = lcm(a[0], a[1])
if (temp // a[0]) % 2 == 0 or (temp // a[1]) % 2 == 0:
    print(0)
    exit()

for y in a[2:]:
    temp = lcm(temp, y)
    if (temp // y) % 2 == 0 or temp > m:
        print(0)
        exit()

ans = m // temp
print(ans - ans // 2)
Buggy python submission (verdict: Time Limit Exceeded):
from bisect import bisect_left

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

a.sort(reverse=True)
b = list(reversed(a))

rs = [0] * n
rs[0] = a[0]
for i, x in enumerate(a[1:]):
    rs[i+1] = rs[i] + x

L = 0
H = sum(a) ** 2 + 1

while H - L > 1:
    M = (L + H) // 2
    count = 0
    for x in a:
       count += n - bisect_left(b, M - x)
    if count == m:
        L = M
        break
    elif count > m:
        L = M
    else:
        H = M

ans = 0
count = 0
for x in a:
    c = n - 1 -  bisect_left(b, L - x)
    count += c + 1
    if c >= 0:
        ans += rs[c] + x * (c+1)

print(ans - (count-m) * L)


Fixed submission:
from bisect import bisect_left

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

a.sort(reverse=True)
b = list(reversed(a))

rs = [0] * n
rs[0] = a[0]
for i, x in enumerate(a[1:]):
    rs[i+1] = rs[i] + x

L = a[-1] * 2
H = a[0] * 2

while H - L > 1:
    M = (L + H) // 2
    count = 0
    for x in a:
       count += n - bisect_left(b, M - x)
    if count == m:
        L = M
        break
    elif count > m:
        L = M
    else:
        H = M

ans = 0
count = 0
for x in a:
    c = n - 1 -  bisect_left(b, L - x)
    count += c + 1
    if c >= 0:
        ans += rs[c] + x * (c+1)

print(ans - (count-m) * L)

Buggy python submission (verdict: Time Limit Exceeded):
from bisect import bisect_left

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

a.sort(reverse=True)
b = list(reversed(a))

rs = [0] * n
rs[0] = a[0]
for i, x in enumerate(a[1:]):
    rs[i+1] = rs[i] + x

L = 0
H = sum(a) ** 2 + 1

#print(b)

while H - L > 1:
    #print(L, H)
    M = (L + H) // 2
    count = 0
    for x in a:
       count += n - bisect_left(b, M - x)
    #print(L, H, count)
    if count == m:
        L = M
        break
    elif count > m:
        L = M
    else:
        H = M

ans = 0
count = 0
for x in a:
    c = n - 1 -  bisect_left(b, L - x)
    count += c + 1
    if c >= 0:
        ans += rs[c] + x * (c+1)

#print(L, count - m)

print(ans - (count-m) * L)

Fixed submission:
from bisect import bisect_left

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

a.sort(reverse=True)
b = list(reversed(a))

rs = [0] * n
rs[0] = a[0]
for i, x in enumerate(a[1:]):
    rs[i+1] = rs[i] + x

L = a[-1] * 2
H = a[0] * 2

while H - L > 1:
    M = (L + H) // 2
    count = 0
    for x in a:
       count += n - bisect_left(b, M - x)
    if count == m:
        L = M
        break
    elif count > m:
        L = M
    else:
        H = M

ans = 0
count = 0
for x in a:
    c = n - 1 -  bisect_left(b, L - x)
    count += c + 1
    if c >= 0:
        ans += rs[c] + x * (c+1)

print(ans - (count-m) * L)
Buggy python submission (verdict: Runtime Error):
n, u, v = map(int, input().split())
ab = [tuple(map(lambda x:int(x)-1, input().split())) for _ in range(n-1)]
u -= 1
v -= 1

e = [[] for _ in range(n)]
for a, b in ab:
    e[a].append(b)
    e[b].append(a)

if len(e[u]) == 1:
    if e[u][0] == v:
        print(0)
        exit()

t = [0] * n
a = [0] * n

def dfs(x, p, d, c):
    if len(e[x]) == 1:
        if e[x][0] == p:
            return
    for y in e[x]:
        if y == p:
            continue
        if c == 0:
            t[y] = d
        else:
            a[y] = d
        dfs(y, x, d+1, c)

dfs(u, -1, 1, 0)
dfs(v, -1, 1, 1)
ans = 0
for i in range(n):
    if t[i] < a[i]:
        ans = max(a[i], ans)

print(ans-1)

Fixed submission:
from sys import setrecursionlimit
setrecursionlimit(10 ** 5)

n, u, v = map(int, input().split())
ab = [tuple(map(lambda x:int(x)-1, input().split())) for _ in range(n-1)]
u -= 1
v -= 1

e = [[] for _ in range(n)]
for a, b in ab:
    e[a].append(b)
    e[b].append(a)

t = [0] * n
a = [0] * n

def dfs(x, p, d, c):
    if len(e[x]) == 1:
        if e[x][0] == p:
            return
    for y in e[x]:
        if y == p:
            continue
        if c == 0:
            t[y] = d
        else:
            a[y] = d
        dfs(y, x, d+1, c)

dfs(u, -1, 1, 0)
dfs(v, -1, 1, 1)
ans = 0
for i in range(n):
    if t[i] < a[i]:
        ans = max(a[i], ans)

print(ans-1)

Buggy python submission (verdict: Runtime Error):
n, u, v = map(int, input().split())
ab = [tuple(map(lambda x:int(x)-1, input().split())) for _ in range(n-1)]
u -= 1
v -= 1

e = [[] for _ in range(n)]
for a, b in ab:
    e[a].append(b)
    e[b].append(a)

t = [0] * n
a = [0] * n

def dfs(x, p, d, c):
    if len(e[x]) == 1:
        if e[x][0] == p:
            return
    for y in e[x]:
        if y == p:
            continue
        if c == 0:
            t[y] = d
        else:
            a[y] = d
        dfs(y, x, d+1, c)

dfs(u, -1, 1, 0)
dfs(v, -1, 1, 1)
ans = 0
for i in range(n):
    if t[i] < a[i]:
        ans = max(a[i], ans)

print(ans-1)

Fixed submission:
from sys import setrecursionlimit
setrecursionlimit(10 ** 5)

n, u, v = map(int, input().split())
ab = [tuple(map(lambda x:int(x)-1, input().split())) for _ in range(n-1)]
u -= 1
v -= 1

e = [[] for _ in range(n)]
for a, b in ab:
    e[a].append(b)
    e[b].append(a)

t = [0] * n
a = [0] * n

def dfs(x, p, d, c):
    if len(e[x]) == 1:
        if e[x][0] == p:
            return
    for y in e[x]:
        if y == p:
            continue
        if c == 0:
            t[y] = d
        else:
            a[y] = d
        dfs(y, x, d+1, c)

dfs(u, -1, 1, 0)
dfs(v, -1, 1, 1)
ans = 0
for i in range(n):
    if t[i] < a[i]:
        ans = max(a[i], ans)

print(ans-1)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(lambda x:list(map(int, reversed(bin(int(x) + 2**60)[2:]))), input().split()))

MOD = 10 ** 9 + 7

#print(a)
#exit()

ans = 0
d = 1
for j in range(60):
    x = 0
    for i in range(n):
        x += a[i][j]
    ans = (((x * (n-x)) % MOD) * d % MOD + ans) % MOD
    d = d * 2 % MOD

print(ans)


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

MOD = 10 ** 9 + 7

ans = 0
d = 1
for _ in range(60):
    x = 0
    for i in range(n):
        x += a[i] % 2
        a[i] //= 2
    ans = (((x * (n-x)) % MOD) * d % MOD + ans) % MOD
    d = d * 2 % MOD

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int, input().split()))

MOD = 10 ** 9 + 7

ans = 0
d = 1
for _ in range(60):
    x = 0
    for i in range(n):
        x += a[i] % 2
        a[i] >>= 1
    ans = (((x * (n-x)) % MOD) * d % MOD + ans) % MOD
    d = d * 2 % MOD

print(ans)


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

MOD = 10 ** 9 + 7

ans = 0
d = 1
for _ in range(60):
    x = 0
    for i in range(n):
        x += a[i] % 2
        a[i] //= 2
    ans = (((x * (n-x)) % MOD) * d % MOD + ans) % MOD
    d = d * 2 % MOD

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int, input().split()))

MOD = 10 ** 9 + 7

ans = 0
d = 1
for _ in range(60):
    x = 0
    for i in range(n):
        x += a[i] % 2
        a[i] //= 2
    ans = (((x * (n-x)) % MOD) * d % MOD + ans) % MOD
    d = d * 2 % MOD

print(ans)


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

MOD = 10 ** 9 + 7

ans = 0
d = 1
for _ in range(60):
    x = 0
    for i in range(n):
        x += a[i] % 2
        a[i] //= 2
    ans = (((x * (n-x)) % MOD) * d % MOD + ans) % MOD
    d = d * 2 % MOD

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int, input().split()))

MOD = 10 ** 9 + 7

b = [0] * 60
for x in a:
    for i, temp in enumerate(list(map(int, reversed(bin(x)[2:])))):
        b[i] += temp

ans = 0
d = 1
for x in b:
    ans = (ans + ((x * (n-x)) % MOD) * d) % MOD
    d = d * 2 % MOD

print(ans)


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

MOD = 10 ** 9 + 7

ans = 0
d = 1
for _ in range(60):
    x = 0
    for i in range(n):
        x += a[i] % 2
        a[i] //= 2
    ans = (((x * (n-x)) % MOD) * d % MOD + ans) % MOD
    d = d * 2 % MOD

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int, input().split()))

MOD = 10 ** 9 + 7

b = [0] * 60
for x in a:
    for i, temp in enumerate(list(map(int, reversed(bin(x)[2:])))):
        b[i] += temp

ans = 0
d = 1
for x in b:
    ans = (ans + ((x * (n-x)) % MOD) * d) % MOD
    d = d * 2 % MOD

print(ans)

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

MOD = 10 ** 9 + 7

ans = 0
d = 1
for _ in range(60):
    x = 0
    for i in range(n):
        x += a[i] % 2
        a[i] //= 2
    ans = (((x * (n-x)) % MOD) * d % MOD + ans) % MOD
    d = d * 2 % MOD

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n, t = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(n)]

ab.sort()

dp = [[0 for _ in range(t)] for _ in range(n+1)]

ans = 0
i = 0
for a, b in ab:
    ans = max(ans, max(dp[i]) + b)
    if a < t:
        dp[i+1][a] = max(dp[i][a], b)
    for j in range(1, t):
        if dp[i][j] > 0:
            dp[i+1][j] = max(dp[i+1][j], dp[i][j])
            if a + j < t:
                dp[i+1][a+j] = max(dp[i][a+j], dp[i][j] + b)
    i += 1

ans = max(ans, max(dp[n]))

print(ans)

Fixed submission:
n, t = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(n)]

ab.sort()

dp = [[0 for _ in range(t)] for _ in range(n+1)]

ans = 0
i = 0
for a, b in ab:
    ans = max(ans, max(dp[i]) + b)
    if a < t:
        dp[i+1][a] = max(dp[i][a], b)
    for j in range(1, t):
        if dp[i][j] > 0:
            dp[i+1][j] = max(dp[i+1][j], dp[i][j])
            if a + j < t:
                dp[i+1][a+j] = max(dp[i][a+j], dp[i][j] + b)
    i += 1

ans = max(ans, max(dp[n]))

print(ans)
Buggy python submission (verdict: Runtime Error):
n, k = map(int, input().split())
h = list(map(int, input().split()))

dp = [[0 for _ in range(n)] for _ in range(n-k)]

dp[0] = [] + h

for x in range(1, n-k):
    for y in range(n):
        temp = float('inf')
        for i in range(y):
            temp = min(temp, dp[x-1][i] + max(0, h[y] - h[i]))
        dp[x][y] = temp

#for x in dp: print(x)

print(min(dp[n-k-1]))

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

if k == n:
    print(0)
    exit()

dp = [[0 for _ in range(n)] for _ in range(n-k)]

dp[0] = [] + h

for x in range(1, n-k):
    for y in range(n):
        temp = float('inf')
        for i in range(y):
            temp = min(temp, dp[x-1][i] + max(0, h[y] - h[i]))
        dp[x][y] = temp

#for x in dp: print(x)

print(min(dp[n-k-1]))
Buggy python submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(10 ** 9)

n = int(input())
LR = [tuple(map(int, input().split())) for _ in range(n)]

def quicksort(x):
    if x==[]: return []

    smallerSorted = quicksort([a for a in x[1:] if a[0] < x[0][0] or (a[0] == x[0][0] and a[1] => x[0][1])])
    biggerSorted = quicksort([a for a in x[1:] if a[0] > x[0][0] or (a[0] == x[0][0] and a[1] < x[0][1])])

    return(smallerSorted+[x[0]]+biggerSorted)

LR = quicksort(LR)

ans = [0] * (n+1)
temp = 10 ** 9
i = 1
for L, R in LR:
    temp = min(temp, R)
    if L > temp:
        break   
    ans[i] = temp - L + 1
    i += 1

temp = 10 ** 9
i = n - 1
L = LR[-1][0]
for x, R in reversed(LR):
    temp = min(temp, R)
    if L > temp:
        break
    ans[i] += temp - L + 1
    i -= 1

res = max(ans)
for L, R in LR:
    res = max(res, R - L + 1)

print(res)

Fixed submission:
S = list(input())

n = len(S) + 1

a = [0] * n

for i, x in enumerate(S):
    if x == '<':
        a[i+1] = a[i] + 1
    else:
        a[i+1] = 0

for i, x in enumerate(reversed(S)):
    j = n - i - 1
    if x == '>':
        a[j - 1] = max(a[j] + 1, a[j-1])

print(sum(a))