Harryxun/GPT-100-sft-dataset huggingface dataset:
Problem p03625 (python)

Fixed submission:
from collections import Counter
n, *A = map(int, open(0).read().split())
B = sorted([(k, v) for k, v in Counter(A).items() if v >= 2], reverse=1)
if len(B) == 0:
  print(0)
elif len(B) == 1:
  if B[0][1] >= 4:
  	print(B[0][0] ** 2)
  else:
    print(0)
else:
  if B[0][1] >= 4:
  	print(B[0][0] ** 2)
  else:
  	print(B[0][0]*B[1][0])

Buggy submission (verdict: Runtime Error):
from collections import Counter
n, *A = map(int, open(0).read().split())
B = sorted([(k, v) for k, v in Counter(A).items() if v >= 2], reverse=1)
if len(B) == 0:
  print(0)
elif len(B) == 1:
  if B[0][1] >= 4:
  	print(B[0][0] ** 2)
  else:
    print(0)
else:
  if B[0][1] >= 4:
  	print(B[0][0] ** 2)
  else:
  	print(B[0]*B[1])
Problem p03672 (python)

Fixed submission:
S = input().strip()
n = len(S)

for i in range(n-2, 0, -2):
  S = S[:i]
  k = i // 2
  if S[k:] == S[:k]:
    print(i)
    exit()

Buggy submission (verdict: Runtime Error):
S = input().sprit()
n = len(S)

for i in range(n-2, 0, -2):
  S = S[:i]
  k = i // 2
  if S[k:] == S[:k]:
    print(i)
    exit()
Problem p03713 (python)

Fixed submission:
h, w = map(int, input().split())
if h % 3 == 0 or w % 3 == 0:
    print(0)
else:
    if h > w:
        h, w = w, h
    ans = h
    for w1 in range(w//3-2, w//3+3):
        s1 = w1 * h
        w2 = w-w1
        for h1 in range(h//2 + 1):
            s2 = w2 * h1
            s3 = w2 * (h-h1)
            ans = min(ans, max(s1, s2, s3) - min(s1, s2, s3))
    h, w = w, h
    for w1 in range(w//3-2, w//3+3):
        s1 = w1 * h
        w2 = w-w1
        for h1 in range(h//2 + 1):
            s2 = w2 * h1
            s3 = w2 * (h-h1)
            ans = min(ans, max(s1, s2, s3) - min(s1, s2, s3))
    print(ans)

Buggy submission (verdict: Runtime Error):
h, w = map(int, input().split())
if h % 3 == 0 or w % 3 == 0:
    print(0)
else:
    if h > w:
        h, w = w, h
    ans = h
    if h % 2 == 0:
        h1 = h // 2
        for w1 in range(w//2+1):
            s2 = h1 * w1
            s3 = h1 * (w-w1)
            ans = min(ans, max(s1, s2, s3) - min(s1, s2, s3))
    else:
        for w1 in range(w//3, w//2 + 1):
            s1 = w1 * h
            w2 = w-w1
            for h1 in range(h//2 + 1):
                s2 = w2 * h1
                s3 = w2 * (h-h1)
                ans = min(ans, max(s1, s2, s3) - min(s1, s2, s3))
    print(ans)
Problem p03739 (python)

Fixed submission:
from itertools import accumulate
n, *A = map(int, open(0).read().split())
B = list(accumulate(A))
p0 = n0 = p1 = n1 = 0
for i, b in enumerate(B):
    if i % 2 == 0:
        if b+p0-n0 <= 0:
            p0 += abs(b+p0-n0)+1
        if b+p1-n1 >= 0:
            n1 += abs(b+p1-n1)+1
    else:
        if b+p0-n0 >= 0:
            n0 += abs(b+p0-n0)+1
        if b+p1-n1 <= 0:
            p1 += abs(b+p1-n1)+1
print(min(p0+n0, p1+n1))

Buggy submission (verdict: Runtime Error):
n, *A = map(int, open(0).read().split())
B = [A[0]]
C = [A[0]]
D = [0]
for i in range(1, n):
  if (C[i-1] + A[i]) * C[i-1] < 0:
    B.append(A[i])
    C.append(C[i-1] + A[i])
    D.append(D[i-1])
  else:
    if C[i-1] > 0:
      B.append(-(C[i-1]+1))
      C.append(-1)
      D.append(C[i-1]+1 + A[i])
    elif C[i-1] < 0:
      B.append(-C[i-1]+1)
      C.append(1)
      D.append(-C[i-1]+1 + A[i])
print(A)
print(B)
print(C)
print(D)
Problem p03761 (python)

Fixed submission:
from collections import Counter
from functools import reduce
from operator import and_
n, *S = open(0).read().split()
keys = reduce(and_, map(set, S))
d = {c:10**6 for c in keys}
for counter in map(Counter, S):
    for c in keys:
        if c in counter:
            d[c] = min(d[c], counter[c])
ans = ''
for k, v in sorted(d.items()):
    ans += k * v
print(ans)

Buggy submission (verdict: Runtime Error):
from collections import Counter
from functools import reduce
n, *S = open(0).read().split()
keys = reduce(and_, map(set, S))
d = {c:10**6 for c in keys}
for counter in map(Counter, S):
    for c in keys:
        if c in counter:
            d[c] = min(d[c], counter[c])
ans = ''
for k, v in sorted(d.items()):
    ans += k * v
print(ans)
Problem p03838 (python)

Fixed submission:
x, y = map(int, input().split())
d = abs(abs(x) - abs(y))
if 0 <= x < y or x < y <= 0:
  print(d)
elif y < 0 < x or x < 0 < y:
  print(d+1)
elif 0 < y < x or y < x < 0:
  print(d+2)
elif y == 0 < x or y < x == 0:
  print(d+1)
else:
  raise Exception

Buggy submission (verdict: Runtime Error):
x, y = map(int, input().split())
d = abs(abs(x) - abs(y))
if 0 <= x < y or x < y <= 0:
  print(d)
elif y <= 0 <= x or x < 0 < y:
  print(d+1)
else
  print(d+2)
Problem p03846 (python)

Fixed submission:
n, *A = map(int, open(0).read().split())
if n % 2:
    d = {i:2 for i in range(0, n, 2)}
    d[0] -= 1
else:
    d = {i:2 for i in range(1, n, 2)}
for a in A:
    if a in d:
        d[a] -= 1
    else:
        print(0)
        exit()

if any(d.values()):
    print(0)
else:
    print(pow(2, n//2, 10**9 + 7))

Buggy submission (verdict: Runtime Error):
n, *A = map(int, open(0).read().split())
if n % 2:
    d = {i:2 for i in range(0, n, 2)}
    d[0] -= 1
else:
    d = {i:2 for i in range(1, n, 2)}
for a in A:
    d[a] -= 1

if any(d.values()):
    print(0)
else:
    print(pow(2, n//2, 10**9 + 7))
Problem p03910 (python)

Fixed submission:
class BisectSearch:
    def __init__(self, f, l=0, r=10**9):
        self.f = f
        self.l = l
        self.r = r
    def __call__(self, dist):
        f = self.f
        l = self.l
        r = self.r
        if dist <= f(l):
            return l
        if f(r) <= dist:
            return r
        while r-l > 1:
            n = (r+l) // 2
            if f(n) <= dist:
                l = n
            else:
                r = n
        return l

n = int(input())
def f(n):
    return (n+1)*n // 2
m = BisectSearch(f, l=1, r=10**7)(n)
m += f(m) != n
A = set()
for i in range(m, 0, -1):
  if n - i >= 0:
    A.add(i)
    n -= i
print(*A, sep='\n')

Buggy submission (verdict: Runtime Error):
class BisectSearch:
    def __init__(self, f, l=0, r=10**9):
        self.f = f
        self.l = l
        self.r = r
    def __call__(self, dist):
        f = self.f
        l = self.l
        r = self.r
        if dist <= f(l):
            return l
        if f(r) <= dist:
            return r
        while r-l > 1:
            n = (r+l) // 2
            if f(n) <= dist:
                l = n
            else:
                r = n
        return l

n = int(input())
def f(n):
    return (n+1)*n // 2
m = BisectSearch(f, l=1, r=10**7)(n)
m += f(m) != n
A = set(range(1, m+1))
A.remove(f(m) - n)
print(*A, sep='\n')
Problem p02576 (python)

Fixed submission:
from math import ceil
N, X, T = map(int,input().split())
print(ceil(N / X) * T)

Buggy submission (verdict: Runtime Error):
N, X, T = map(int,input().split())
print(-(-N // x) * t)
Problem p02579 (python)

Fixed submission:
from collections import deque
import sys

INF = 10 ** 8

H, W = map(int,input().split())
C = list(map(int,input().split()))
D = list(map(int,input().split()))
MAP = []
for _ in range(H):
    MAP.append(list(input()))
d = [[INF for i in range(W)] for j in range(H)]
tx = [1, 0, -1, 0]
ty = [0, 1, 0, -1]
tx_y = [(i, j) for i in range(-2, 3) for j in range(-2, 3)]

Q = deque()
Q.append([C[0]-1, C[1]-1, 0])

while len(Q) != 0:
    x, y, cnt = Q.popleft()
    
    if x == D[0]-1 and y == D[1]-1:
        print(cnt)
        sys.exit()
    
    for i in range(4):
        nx = x + tx[i]
        ny = y + ty[i]
        if 0 <= nx < H and 0 <= ny < W and MAP[nx][ny] == "." and d[nx][ny] > cnt:
            d[nx][ny] = cnt
            Q.appendleft([nx, ny, cnt])
    
    for i, j in tx_y:
        nx = x + i
        ny = y + j
        if 0 <= nx < H and 0 <= ny < W and MAP[nx][ny] == "." and d[nx][ny] > cnt+1:
            d[nx][ny] = cnt+1
            Q.append([nx, ny, cnt+1])

print(-1)

Buggy submission (verdict: Runtime Error):
from collections import deque
import sys

INF = 10 ** 8

H, W = map(int,input().split())
CH, CW = map(int,input().split())
DH, DW = map(int,input().split())

S = []
for _ in range(H):
    S.append(list(input()))

d = [[INF for i in range(W)] for j in range(H)]

Q = deque([CH-1, CW-1, 0])
d[CH-1][CW-1] = 0

while len(Q) != 0:
    x, y, cnt = Q.popleft()
    
    if x == DH-1 and y == DW-1:
        print(cnt)
        sys.exit()
    
    for tx in range(-2, 3):
        for ty in range(-2, 3):
            nx = x + tx
            ny = y + ty
            if 0 <= nx < H and 0 <= ny < W and MAP[nx][ny] == "." and d[nx][ny] == INF:
                if abs(tx)+abs(ty) == 1:
                    d[nx][ny] = cnt
                    Q.appendleft([nx, ny, cnt])
                else:
                    d[nx][ny] = cnt + 1
                    Q.append([nx, ny, cnt + 1])

print(-1)
Problem p02602 (python)

Fixed submission:
import sys
N, K = map(int,input().split())
A = list(map(int,input().split()))

for i in range(N-K):
    if A[K+i] <= A[i]:
        print('No')
    else:
        print('Yes')

Buggy submission (verdict: Runtime Error):
N, K = map(int,input().split())
A = list(map(int,input().split()))

for i in range(K+1, N+1):
    print('Yes') if A[i - K] < A[i] else print('No')
Problem p02603 (python)

Fixed submission:
N = int(input())
A = list(map(int,input().split()))
A += [0]

money = 1000
k = 0
for i in range(N):
    if A[i] <= A[i+1]:
        tmp = money // A[i]
        money -= tmp * A[i]
        k += tmp
    else:
        money += k * A[i]
        k = 0

print(money)

Buggy submission (verdict: Runtime Error):
N = int(input())
A = list(map(int,input().split()))

dp = [0] * N
dp[0] = 1000

for i in range(1, N):
    dp[i] = dp[i - 1]
    for j in range(i - 1):
        V = dp[j] // A[j]
        W = dp[j] + (A[i] - A[j]) * V
        dp[i] = max(dp[i], W)

print(dp[N])
Problem p02604 (python)

Fixed submission:
INF = 10 ** 12

N = int(input())
X = [0] * N
Y = [0] * N
P = [0] * N
for i in range(N):
    X[i], Y[i], P[i] = map(int,input().split())

score_X = []

for i in range(2 ** N):
    x = []
    I = i
    for j in range(N):
        i = I
        score = abs(X[j]) * P[j]
        for k in range(N):
            if i & 1:
                score = min(score, abs(X[j] - X[k]) * P[j])
            i >>= 1
        x.append(score)
    score_X.append(x)

score_Y = []

for i in range(2 ** N):
    y = []
    I = i
    for j in range(N):
        i = I
        score = abs(Y[j]) * P[j]
        for k in range(N):
            if i & 1:
                score = min(score, abs(Y[j] - Y[k]) * P[j])
            i >>= 1
        y.append(score)
    score_Y.append(y)

ans = [INF] * (N + 1)

for i in range(2 ** N):
    cnt = 0
    for j in range(N):
        if (i >> j) & 1:
            cnt += 1
    
    j = i
    
    while True:
        score = 0
        for k in range(N):
            if not (i >> k) & 1:
                score += min(score_X[j][k], score_Y[i - j][k])
        ans[cnt] = min(ans[cnt], score)
        if j == 0:
            break
        j = (j - 1) & i

for i in range(N + 1):
    print(ans[i])

Buggy submission (verdict: Runtime Error):
from itertools import combinations
from bisect import bisect_left

INF = float('INF')
N = int(input())
points = []
scores = []

for i in range(N):
    point = list(map(int,input().split()))
    points.append(point + [i])
    scores.append(max(abs(point[0]), abs(point[1])) * point[2])

for i in range(N+1):
    MIN = INF
    for j in range(i+1):
        for P in combinations(points, N-j):
            X = [0]
            tmp_scores = scores[:]
            for p in points:
                if not p in P:
                    X.append(p[0])
                    tmp_scores[p[3]] = 0
            X.sort()
            X += [100000]
            for p in P:
                index = bisect_left(X, p[0])
                tmp_scores[p[3]] = min(tmp_scores[p[3]], min(p[0]-X[index], X[index+1]-p[0]) * p[2])
            for Q in combinations(P, i-j):
                Y = [0]
                for p in points:
                    if p in Q:
                        Y.append(p[1])
                        tmp_scores[p[3]] = 0
                Y.sort()
                Y += [100000]
                for p in Q:
                    index = bisect_left(Y, p[0])
                    tmp_scores[p[3]] = min(tmp_scores[p[3]], min(p[1]-Y[index], Y[index+1]-p[1]) * p[2])
                MIN = min(MIN, sum(tmp_scores))

print(MIN)
Problem p02609 (python)

Fixed submission:
N = int(input())
X = list(input())
one = X.count('1')
L1 = [1]
L2 = [1]

for _ in range(N-1):
    if one - 1 == 0:
        L1.append(0)
    else:
        L1.append((L1[-1] * 2) % (one - 1))
    L2.append((L2[-1] * 2) % (one + 1))

x1 = 0
x2 = 0
power1 = 1
power2 = 1

for i in range(N):
    if X[N-i-1] == '1':
        if one - 1 != 0:
            x1 += power1
        x2 += power2
    power1 *= 2
    power2 *= 2
    if one - 1 != 0:
        power1 %= one - 1
    power2 %= one + 1

def solve(X, cnt):
    if X == 0:
        return cnt
    
    X %= bin(X).count('1')
    return solve(X, cnt+1)

for i in range(N):
    if X[i] == '0':
        tmp = (x2 + L2[N-i-1]) % (one + 1)
        ans = solve(tmp, 0) + 1
    else:
        if one - 1 == 0:
            ans = 0
        else:
            tmp = (x1 - L1[N-i-1]) % (one - 1)
            ans = solve(tmp, 0) + 1
    print(ans)

Buggy submission (verdict: Runtime Error):
N = int(input())
X = list(input())
one = X.count('1')
L1 = [1]
L2 = [1]

for _ in range(N-1):
    if one == 0:
        L1.append(0)
    else:
        L1.append((L1[-1] * 2) % (one - 1))
    L2.append((L2[-1] * 2) % (one + 1))

x1 = 0
x2 = 0
power1 = 1
power2 = 1

for i in range(N):
    if X[N-i-1] == '1':
        if one - 1 != 0:
            x1 += power1
        x2 += power2
    power1 *= 2
    power2 *= 2
    if one - 1 != 0:
        power1 %= one - 1
    power2 %= one + 1

def solve(X, cnt):
    if X == 0:
        return cnt
    
    X %= bin(X).count('1')
    return solve(X, cnt+1)

for i in range(N):
    if X[i] == '0':
        tmp = (x2 + L2[N-i-1]) % (one + 1)
        ans = solve(tmp, 0) + 1
    else:
        if one - 1 == 0:
            ans = 0
        else:
            tmp = (x1 - L1[N-i-1]) % (one - 1)
            ans = solve(tmp, 0) + 1
    print(ans)
Problem p02716 (python)

Fixed submission:
from collections import defaultdict
INF = 10 ** 15
N = int(input())
A = list(map(int,input().split()))
dp_take = defaultdict(lambda: -INF)
dp_not = defaultdict(lambda: -INF)
dp_take[(0,0)] = 0
dp_not[(0,0)] = 0

for i in range(N):
    for j in range((i + 1) // 2 - 1, (i + 2) // 2 + 1):
        if j > 0:
            dp_take[(i+1, j)] = max(dp_take[(i+1, j)], dp_not[(i, j-1)] + A[i])
        dp_not[(i+1, j)] = max(dp_not[(i, j)], dp_take[(i, j)])

print(max(dp_take[(N, N//2)], dp_not[(N, N//2)]))

Buggy submission (verdict: Runtime Error):
N = int(input())
A = list(map(int,input().split()))

P = [A[0]]
Q = [A[1]]
for i in range(2,N):
    if i % 2 == 0:
        P.append(P[-1] + A[i])
    else:
        Q.append(Q[-1] + A[i])

if N % 2 == 0:
    ans = max(P[-1],Q[-1])
    for i in range(N//2-1):
        ans = max(ans,P[i]+Q[-1]-Q[i])
else:
    ans = max(Q[-1],P[-1] - min(A[0::2]))
    ans = max(ans, Q[-2]-Q[0]+A[0]+A[-1])
    for i in range(N//2-1):
        ans = max(ans,P[i]+Q[-1]-Q[i])
    for i in range(N//2-1):
        ans = max(ans,P[-1]-P[i+1]+Q[i])
print(ans)
Problem p02721 (python)

Fixed submission:
N, K, C = map(int,input().split())
S = list(input())

def solve(List):
    ans = []
    i = 0
    while i < N:
        if List[i] == 'o':
            ans.append(i+1)
            i += C
        i += 1
    return ans

n = solve(S)

if len(n) > K:
    pass
else:
    r = solve(S[::-1])
    r = list(map(lambda x: N+1-x, r[::-1]))
    ans = list(set(n) & set(r))
    ans.sort()
    for i in ans:
        print(i)

Buggy submission (verdict: Runtime Error):
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

N, K, C = map(int, readline().split())
S = list(map(int, readline().split()))
ans = []

def solve(index, K):
    i = 0
    cnt = 0
    while i < N:
        if S[i] == 'o' and i != index:
            cnt += 1
            i += C + 1
        else:
            i += 1
    return cnt < K

if not (solve(-1, K+1)):
    pass
else:
    index = 0
    while index < N:
        if S[index] == 'x':
            index += 1
        elif solve(index, K):
            ans.append(index + 1)
            index += C + 1
        else:
            index += 1

    for i in ans:
        print(i)

Buggy submission (verdict: Runtime Error):
def main():
    import sys
    read = sys.stdin.buffer.read
    readline = sys.stdin.buffer.readline
    readlines = sys.stdin.buffer.readlines

    N, K, C = map(int, readline().split())
    S = list(map(int, readline().split()))
    ans = []

    def solve(index, K):
        i = 0
        cnt = 0
        while i < N:
            if S[i] == 'o' and i != index:
                cnt += 1
                i += C + 1
            else:
                i += 1
        return cnt < K

    if not (solve(-1, K+1)):
        pass
    else:
        index = 0
        while index < N:
            if S[index] == 'x':
                index += 1
            elif solve(index, K):
                ans.append(index + 1)
                index += C + 1
            else:
                index += 1

        for i in ans:
            print(i)
        
if __name__ == '__main__':
    main()
Problem p02765 (python)

Fixed submission:
N, R = map(int,input().split())
if N >= 10:
    print(R)
else:
    print(R + 100 * (10 - N))

Buggy submission (verdict: Runtime Error):
N, R = map(int,input().split())
if N >= 10:
    print(R)
else:
    print(R + 100 * (10 - K))
Problem p02778 (python)

Fixed submission:
S = input()
for i in range(len(S)):
    print("x",end="")

Buggy submission (verdict: Runtime Error):
S = input()
for i in range(len(S)):
    print(x,end="")
Problem p02814 (python)

Fixed submission:
from fractions import gcd
from functools import reduce

N, M = map(int,input().split())
a = list(map(int,input().split()))
a = [x // 2 for x in a]

def solve(p, q):
    g = gcd(p, q)
    p //= g
    q //= g
    if (p - q) % 2 == 1:
        return 0
    return p * q * g

k = reduce(solve, a)
if k == 0:
    print(0)
else:
    print(M // k - M // (k * 2))

Buggy submission (verdict: Runtime Error):
import numpy as np
from math import gcd
from functools import reduce

N, M = map(int,input().split())
a = list(map(int,input().split()))
a = np.array(a)
a = a // 2

def solve(p, q):
    cnt = 1
    while p % 2 == 0 and q % 2 == 0:
        cnt <<= 1
        p >>= 1
        q >>= 1
    if (p - q) % 2 != 0:
        return 0
    return p * q * cnt // gcd(p, q)
k = reduce(solve, a)
if k == 0:
    print(0)
else:
    ans = int((M / k + 1) / 2)
    print(ans)

Buggy submission (verdict: Runtime Error):
import numpy as np
from math import gcd
from functools import reduce

N, M = map(int,input().split())
a = list(map(int,input().split()))
a = np.array(a)
a = a // 2

def solve(p, q):
    cnt = 1
    while p % 2 == 0 and q % 2 == 0:
        cnt <<= 1
        p >>= 1
        q >>= 1
    if (p - q) % 2 != 0:
        return 0
    return p * q * cnt // gcd(p, q)
k = reduce(solve, a)
if k == 0:
    print(0)
else:
    ans = (M / k + 1) // 2
    print(ans)

Buggy submission (verdict: Runtime Error):
import fractions
from functools import reduce

def lcm_base(x, y):
    return (x * y) // math.gcd(x, y)

def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)

N,M = map(int,input().split())
A = list(map(int,input().split()))
LCM = lcm_list(A)
print(int(((2*M)/LCM+1)/2))

Buggy submission (verdict: Runtime Error):
import math
from functools import reduce

def lcm_base(x, y):
    return (x * y) // math.gcd(x, y)

def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)

N,M = map(int,input().split())
A = list(map(int,input().split()))
LCM = lcm_list(A)
print(int(((2*M)/LCM+1)/2))
Problem p02818 (python)

Fixed submission:
A, B, K = map(int,input().split())
if A+B<K:
    print(*[0,0])
elif A<K<=A+B:
    print(*[0,A+B-K])
else:
    print(*[A-K,B])

Buggy submission (verdict: Runtime Error):
A, B, K = map(int,input().split())
if K >=A+B:
    print("0 0")
elif A+B>K>=A:
    p = A+B-K
    print(f"0 {p}")
else:
    q = A-K
    print(f"{q} {B}")
Problem p02838 (python)

Fixed submission:
N = int(input())
A = list(map(int,input().split()))
mod = 10 ** 9 + 7
cnt = [0 for _ in range(60)]
for a in A:
    for i in range(60):
        cnt[i] += a & 1
        a >>= 1
cnt = [x * (N - x) % mod for x in cnt]
power = 1
ans = 0
for i in range(60):
    ans += power * cnt[i]
    power *= 2
    power %= mod
ans %= mod
print(ans)

Buggy submission (verdict: Runtime Error):
N = int(input())
A = list(map(int,input().split()))
cnt = [0 for i in range(60)]
mod = 10 ** 9 + 7

for i in range(60):
    for j in A:
        tmp = format(i, '060b')
        if tmp[j] == "1":
            cnt[j] += 1

ans = 0

lst = [1 for i in range(60)]

for i in range(59):
    lst[58-i] = (lst[59-i] * 2) % mod

for i in range(60):
    ans += (lst[i] * cnt[i] * (N -cnt[i])) % mod
    
ans %= mod

print(ans)

Buggy submission (verdict: Runtime Error):
import sys

N = int(input())
A = sys.stdin.readline().rstrip()
lst = [0 for i in range(60)]
q = 0
for i in A:
    a = list(str(format(i, '08b')))
    a.reverse()
    for j in range(len(a)):
        lst[j]+=int(a[j])
for i in range(60):
    k = lst[i]
    l = k*(k-1)
    q+=(2**i)*l
p = sum(A)*(N-1)
print((p-q)%((10**9)+7))

Buggy submission (verdict: Runtime Error):
import sys

N = int(input())
A = lambda: sys.stdin.readline().rstrip()
lst = [0 for i in range(60)]
q = 0
for i in A:
    a = list(str(format(i, '08b')))
    a.reverse()
    for j in range(len(a)):
        lst[j]+=int(a[j])
for i in range(60):
    k = lst[i]
    l = k*(k-1)
    q+=(2**i)*l
p = sum(A)*(N-1)
print((p-q)%((10**9)+7))
Problem p02845 (python)

Fixed submission:
mod = 10 ** 9 + 7
cnt = [0] * 3
N = int(input())
A = list(map(int,input().split()))

ans = 1
for i in range(N):
    ans *= cnt.count(A[i])
    ans %= mod
    if ans == 0:
        break
    cnt[cnt.index(A[i])] += 1

print(ans)

Buggy submission (verdict: Runtime Error):
mod = 10 ** 9 + 7
cnt = [0] * 3
N = int(input())
A = list(map(int,input().split()))

ans = 1
for i in range(N):
    ans *= cnt.count(A[i])
    ans %= mod
    cnt[cnt.index(A[i])] += 1

print(ans)
Problem p02874 (python)

Fixed submission:
INF = 10 ** 10

N = int(input())
 
L = [tuple(map(int,input().split())) for _ in range(N)]
 
L.sort(key=lambda x:(-x[0], x[1]))
 
MAX_L = 0
MIN_R = INF
MAX = 0
a = 0
b = 0
 
for i in range(N):
    if MAX_L < L[i][0]:
        MAX_L = L[i][0]
        a = i
    if MIN_R > L[i][1]:
        MIN_R = L[i][1]
        b = i
    MAX = max(MAX, L[i][1] - L[i][0] + 1)
 
ans = MAX + max(0, MIN_R - MAX_L + 1)
 
p = INF
 
for i in range(N-1):
    p = min(p, L[i][1])
    ans = max(ans, max(0, p - L[a][0] + 1) + max(0, L[b][1] - L[i+1][0] + 1))
 
print(ans)

Buggy submission (verdict: Runtime Error):
INF = 10 ** 10

N = int(input())

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

L.sort(key=lambda x:(-x[0], x[1]))

MAX_L = 0
MIN_R = INF
MAX = 0
a = 0
b = 0

for i in range(N):
    if MAX_L < L[i][0]:
        MAX_L = L[i][0]
        a = i
    if MIN_R > L[i][1]:
        MIN_R = L[i][1]
        b = i
    MAX = max(MAX, L[i][1] - L[i][0] + 1)

ans = MAX + max(0, MIN_R - MAX_L + 1)

p = 0

for i in range(N-1):
    p = max(p, L[i+1][0])
    ans = max(ans, max(0, L[i][1] - L[0][0] + 1) + max(0, L[-1][1] - L[i+1][0] + 1))


    print(ans)INF = 10 ** 10

N = int(input())

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

L.sort(key=lambda x:(-x[0], x[1]))

MAX_L = 0
MIN_R = INF
MAX = 0
a = 0
b = 0

for i in range(N):
    if MAX_L < L[i][0]:
        MAX_L = L[i][0]
        a = i
    if MIN_R > L[i][1]:
        MIN_R = L[i][1]
        b = i
    MAX = max(MAX, L[i][1] - L[i][0] + 1)

ans = MAX + max(0, MIN_R - MAX_L + 1)

p = 0

for i in range(N-1):
    p = max(p, L[i+1][0])
    ans = max(ans, max(0, L[i][1] - L[0][0] + 1) + max(0, L[-1][1] - L[i+1][0] + 1))


    print(ans)