Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
use std::io::stdin;

fn main(){
    let x = geti64s()[0];
    let (d, m) = (x/11, x%11);
    println!("{}", match m {
        0         => d*2,
        x if x<=6 => d*2 + 1,
        _         => d*2 + 2
    });
}

#[allow(dead_code)]
fn getline() -> String {
    let mut s = String::new();
    match stdin().read_line(&mut s){
        Ok(_) => {s.trim().to_string()}
        Err(_) => String::new()
    }
}

#[allow(dead_code)]
fn getvec() -> Vec<usize>{
    let line = getline();
    line.split_whitespace().map(|x| x.parse().unwrap()).collect()
}

#[allow(dead_code)]
fn geti64s() -> Vec<i64>{
    let line = getline();
    line.split_whitespace().map(|x| x.parse().unwrap()).collect()
}

#[allow(dead_code)]
fn getpair() -> (usize, usize){
    let nm = getvec();
    (nm[0], nm[1])
}

Fixed submission:
from collections import Counter

_ = input()
xs = Counter(map(int, input().split()))
even = sum(1 for (k, c) in xs.items() if c%2==0)
odd = sum(1 for (k, c) in xs.items() if c%2==1)
print(odd + (even//2)*2)
Buggy python submission (verdict: Time Limit Exceeded):
from collections import Counter

n = int(input())
xs = [None] + [int(input())-1 for _ in range(n-1)]

count_win = Counter(xs)
q = [i for i in range(n) if not i in count_win]
children = [[] for i in range(n)]

while not q[0]==0:
    i = q.pop(0)
    children[i].sort(reverse=True)
    children[i] = max(v+w for v, w in  enumerate([0]+children[i]))
    j = xs[i]
    children[j].append(children[i])
    if count_win[j] <= 1:
        q.append(j)
    else:
        count_win[j] -= 1

children[0].sort(reverse=True)
children[0] = max(v+w for v, w in  enumerate([0]+children[0]))

print(children[0])

Fixed submission:
from collections import Counter

n = int(input())
xs = [None] + [int(input())-1 for _ in range(n-1)]

count_win = Counter(xs)
q = [i for i in range(n) if not i in count_win]
children = [[] for i in range(n)]

qi = 0
while not q[qi]==0:
    i, qi = q[qi], qi+1
    children[i].sort(reverse=True)
    children[i] = max(v+w for v, w in  enumerate([0]+children[i]))
    j = xs[i]
    children[j].append(children[i])
    if count_win[j] <= 1:
        q.append(j)
    else:
        count_win[j] -= 1

children[0].sort(reverse=True)
children[0] = max(v+w for v, w in  enumerate([0]+children[0]))

print(children[0])
Buggy python submission (verdict: Runtime Error):
s = input()

def solve(s):
    i = 0
    n = len(s)

    while i < n:
        if s[i:i+5] == 'dream':
            if s[i+5:i+7] != 'er':
                i += 5
            elif i+7 < n and s[i+7] == 'a':
                i += 5
            else:
                i += 7
        elif s[i:i+5] == 'erase':
            if s[i+5] == 'r':
                i += 6
            else:
                i += 5
        else:
            return False
    return True

if solve(s):
    print("Yes")
else:
    print('No')


Fixed submission:
s = input()

def solve(s):
    i = 0
    n = len(s)

    while i < n:
        if s[i:i+5] == 'dream':
            if s[i+5:i+7] != 'er':
                i += 5
            elif i+7 < n and s[i+7] == 'a':
                i += 5
            else:
                i += 7
        elif s[i:i+5] == 'erase':
            if i+5 < n and s[i+5] == 'r':
                i += 6
            else:
                i += 5
        else:
            return False
    return True

if solve(s):
    print("YES")
else:
    print('NO')
Buggy python submission (verdict: Runtime Error):
def solve(s):
    if len(s)<=1:
        return 0
    return (s[0]!=s[1]) + solve(s[1:])

S = input()
print(solve(S))

Fixed submission:
def solve(s):
    ans = 0
    while len(s)>1:
        ans += s[0]!=s[1]
        s = s[1:]
    return ans

S = input()
print(solve(S))
Buggy python submission (verdict: Runtime Error):
N, x = map(int, input().split())
if x==1 or x==2*N-1:
    print('No')
else:
    print('Yes')
    if x <= 2*N:
        y = list(i for i in range(2, 2*N-2) if i!=x)
        l = len(y)//2
        print("\n".join(map(str, y[:l] + [2*N-1, x, 1, 2*N-2] + y[l:])))
    else:
        y = list(i for i in range(3, 2*N-1) if i!=x)
        l = len(y)//2
        print("\n".join(map(str, y[:l] + [2*N-1, 1, x, 2] + y[l:])))

Fixed submission:
n = int(input())
s = input()
t = input()

M = 0
for i in range(1, n+1):
    if s[-i:] == t[:i]:
        M = i
print(n*2 - M)
Buggy python submission (verdict: Runtime Error):
from collections import Counter
n, k = map(int, input().split())
ps = [input() for _ in range(n)]
heads = Counter((p[0] for p in ps))
ans = 0
while len(heads) >= k:
    ans += 1
    for h, c in heads.most_common()[:k]:
        if c==1:
            heads.pop(h)
        else:
            heads[h] -= 1
print(ans)

Fixed submission:
n, a, b = map(int, input().split())
ts = map(int, (input() for _ in range(n)))
print(sum(1 for t in ts if t<a or t>=b))
Buggy python submission (verdict: Runtime Error):
afrom collections import Counter
n, k = map(int, input().split())
ps = [input() for _ in range(n)]
heads = Counter((p[0] for p in ps))
ans = 0
while len(heads) >= k:
    ans += 1
    for h, c in heads.most_common()[:k]:
        if c==1:
            heads.pop(h)
        else:
            heads[h] -= 1
print(ans)

Fixed submission:
from collections import Counter
n, k = map(int, input().split())
ps = [input() for _ in range(n)]
heads = Counter((p[0] for p in ps))
ans = 0
while len(heads) >= k:
    ans += 1
    for h, c in heads.most_common()[:k]:
        if c==1:
            heads.pop(h)
        else:
            heads[h] -= 1
print(ans)
Buggy python submission (verdict: Runtime Error):
from collections import defaultdict
H, W, N = map(int, input().split())
poss = [list(map(int, input().split())) for _ in range(N)]
d = defaultdict(int)
for a, b in poss:
    for i, j in ((i, j) for i in range(a-1, a+2) for j in range(b-1, b+2)):
        if 1<i<H and 1<j<W:
            s = str(i)+":"+str(j)
            d[s] += 1
anss = [0] * 10
for x in d.values():
    anss[x] += 1
print((H-2)*(W-2) - sum(anss[1:]))
for ans in anss[1:]:
    print(ans)

Fixed submission:
s = input()
ans = 0
l = len(s)-1
for i in range(2**(len(s)-1)):
    bs = ("{0:0>"+str(l)+"b}").format(i)
    s1 = 0
    temp = s[:]
    j = 0
    for b in bs:
        j+=1
        if b == '1':
            s1 += int(temp[:j])
            temp = temp[j:]
            j = 0
    s1 += int(temp)
    ans += s1
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N, x = map(int, input().split())
bs = list(map(int, input().split()))
dp1 = bs[:]
ans = sum(bs)
for k in range(1, 2000):
    dp2 = []
    for i, b in enumerate(bs):
        dp2.append(min(dp1[i-1], b))
    ans = min(ans, sum(dp2)+k*x)
    dp1 = dp2[:]
print(ans)

Fixed submission:
N, x = map(int, input().split())
bs = list(map(int, input().split()))
dp = bs[:]
ans = sum(bs)
for k in range(1, N):
    dp = [min(dp[i], bs[i-k]) for i in range(N)]
    ans = min(ans, sum(dp)+x*k)
print(ans)
Buggy python submission (verdict: Runtime Error):
import sys
import math

sys.setrecursionlimit(100000000)

n = int(input())
s = int(input())

def f(b, n):
    if n<b:
        return n
    else:
        return f(b, n//b) + n%b

if s > n:
    print(-1)
if s==n:
    print(s+1)
else:
    for b in range(2, math.ceil(math.sqrt(n))+1):
        if f(b, n)==s:
            print(b)
            break
    else:
        if f(n+1-s, n)==s:
            print(n+1-s)
        else:
            print(-1)

Fixed submission:
import sys
import math

sys.setrecursionlimit(100000000)

n = int(input())
s = int(input())

def f(b, n):
    if n<b:
        return n
    else:
        return f(b, n//b) + n%b

if s > n:
    print(-1)
elif s==n:
    print(s+1)
else:
    for b in range(2, math.ceil(math.sqrt(n))+1):
        if f(b, n)==s:
            print(b)
            break
    else:
        for d in range(math.floor(math.sqrt(n)), 0, -1):
            if (n-s)%d==0 and f((n-s)//d+1, n)==s:
                print((n-s)//d+1)
                break
        else:
            print(-1)

Buggy python submission (verdict: Runtime Error):
import sys
import math

sys.setrecursionlimit(100000000)

n = int(input())
s = int(input())

def f(b, n):
    if n<b:
        return n
    else:
        return f(b, n//b) + n%b

if s > n:
    print(-1)
else:
    for b in range(2, math.ceil(math.sqrt(n))+1):
        if f(b, n)==s:
            print(b)
            break
    else:
        if f(n+1-s, n)==s:
            print(n+1-s)
        else:
            print(-1)

Fixed submission:
import sys
import math

sys.setrecursionlimit(100000000)

n = int(input())
s = int(input())

def f(b, n):
    if n<b:
        return n
    else:
        return f(b, n//b) + n%b

if s > n:
    print(-1)
elif s==n:
    print(s+1)
else:
    for b in range(2, math.ceil(math.sqrt(n))+1):
        if f(b, n)==s:
            print(b)
            break
    else:
        for d in range(math.floor(math.sqrt(n)), 0, -1):
            if (n-s)%d==0 and f((n-s)//d+1, n)==s:
                print((n-s)//d+1)
                break
        else:
            print(-1)
Buggy python submission (verdict: Time Limit Exceeded):
N, A = map(int, input().split())
xs = list(map(int, input().split()))

def search(xs, i=0, m=0):
    if len(xs) == 0:
        if i==A*m and m>0:
            return 1
        else:
            return 0
    else:
        return search(xs[1:], i+xs[0], m+1)  + search(xs[1:], i, m)


print(search(xs))

Fixed submission:
import numpy as np

N, A = map(int, input().split())
xs = np.array(list(map(int, input().split()))) - A

dp = np.zeros((50*50*2+1, N+1), dtype=np.int64)
dp[50*50,0] = 1

for i, x in enumerate(xs):
    dp[:,i+1] = dp[:,i]
    dp[max(0,x):min(len(dp),len(dp)+x),i+1] += dp[max(0,-x):min(len(dp),len(dp)-x),i]

print(dp[50*50,N]-1)
Buggy python submission (verdict: Time Limit Exceeded):
from collections import defaultdict as dd
N = int(input())
dic=dd(int)
for x in range(1,N+1):
    t1 = N-x**2
    if t1 <= 1:
        continue
    for y in range(1,t1+1):
        t2 = N-x**2-y**2
        if t2 <= 0:
            continue
        for z in range(1,t2+1):
            dic[x**2+y**2+z**2+x*y+y*z+z*x] += 1
for i in range(N):
    print(dic[i+1])



Fixed submission:
from collections import defaultdict as dd
N = int(input())
dic=dd(int)
for x in range(1,N+1):
    t1 = N-x**2
    if t1 <= 1:
        continue
    for y in range(1,t1+1):
        t2 = N-x**2-y**2
        if t2 <= 0:
            continue
        for z in range(1,t2+1):
            tmp = x**2+y**2+z**2+x*y+y*z+z*x
            if tmp > N:
                break
            else:
                dic[tmp] += 1

for i in range(N):
    print(dic[i+1])
Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np
N,K = map(int,input().split())
res = list(map(int,input().split()))
# res = [0]*N
for k in range(K):
    delta = np.zeros((N+1), dtype=np.int32)
    for i,val in enumerate(res):
        left = max(0, i-val)
        right = min(N, i+val+1)
        delta[left] += 1
        delta[right] -= 1
    res = np.cumsum(delta, dtype=np.int32)[:N]
    # print(k)
    if delta[0] == -delta[N] == N:
        break
print(*res)



Fixed submission:
N, K = map(int, input().split())
s = input()
res = list(map(int,s.split()))

for k in range(K):
    delta = [0]*(N+1)
    for i,val in enumerate(res):
        left = max(0, i-val)
        right = min(N, i+val+1)
        delta[left] += 1
        delta[right] -= 1
    res = [0]*N
    res[0] = delta[0]
    for i in range(N-1):
        res[i+1] = res[i]+delta[i+1]
    if delta[0] == -delta[N] == N:
        break

print(*res)

Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np
N,K = map(int,input().split())
a = list(map(int,input().split()))
res = [val for val in a]
for k in range(K):
    delta = [0]*(N+1)
    for i,val in enumerate(res):
        left = max(0, i-val)
        right = min(N-1, i+val)
        delta[left] += 1
        delta[right+1] -= 1
    res = list(np.cumsum(delta, dtype=np.int32))[:N]
    if sum(res) == N**2:
        break
print(*res)



Fixed submission:
N, K = map(int, input().split())
s = input()
res = list(map(int,s.split()))

for k in range(K):
    delta = [0]*(N+1)
    for i,val in enumerate(res):
        left = max(0, i-val)
        right = min(N, i+val+1)
        delta[left] += 1
        delta[right] -= 1
    res = [0]*N
    res[0] = delta[0]
    for i in range(N-1):
        res[i+1] = res[i]+delta[i+1]
    if delta[0] == -delta[N] == N:
        break

print(*res)
Buggy python submission (verdict: Runtime Error):

S=input()
Q=int(input())
qls=[list(map(str,input().split())) for _ in range(Q)]
res=['']*(2*Q)
res[Q]=S
ins = [Q+1, Q-1]
flg=0 #0:right, 1:left
for q in qls:
    if q[0]=='1':
        flg = (flg+1)%2
    else:
        x = (flg+int(q[1]))%2
        idx = ins[x]
        res[idx] = q[2]
        if x==0:
            ins[x]+=1
        else:
            ins[x]-=1
if flg==0:
    print(''.join(res))
else:
    print(''.join(res[::-1]))


Fixed submission:

S=input()
Q=int(input())
qls=[list(map(str,input().split())) for _ in range(Q)]
N=len(S)
res=['']*(2*Q+N)
res[Q:Q+N]=S
ins = [Q+N, Q-1]
flg=0 #0:right, 1:left
for q in qls:
    if q[0]=='1':
        flg = (flg+1)%2
    else:
        x = (flg+int(q[1]))%2
        idx = ins[x]
        res[idx] = q[2]
        if x==0:
            ins[x]+=1
        else:
            ins[x]-=1
if flg==0:
    print(''.join(res))
else:
    print(''.join(res[::-1]))
Buggy python submission (verdict: Time Limit Exceeded):
N,p=map(int,input().split())
s=input()
res=0
for i in range(N):
    val = int(s[i])
    if val%p==0:
        res += 1
    for j in s[i+1:]:
        val = (10*val+int(j))%p
        if val==0:
            res += 1
print(res)

Fixed submission:
from collections import defaultdict as dd
N,p=map(int,input().split())
s=input()
res=0
dic=dd(int)
c = [0]*(N+1)

if p==2 or p==5:
    for i in range(N):
        now = int(s[N-i-1])%p
        if now==0:
            res += N-i
    print(res)
    exit()

for i in range(N):
    now = int(s[N-i-1])%p
    c[i+1] = (c[i]+pow(10,i,p)*now)%p
for val in c:
    dic[str(val)] += 1
    if dic[str(val)] >= 2:
        res += dic[str(val)]-1
print(res)
Buggy python submission (verdict: Runtime Error):
from collections import Counter
N=input()
K=int(input())
res = 0
if int(N)<=100:
    for i in range(int(N)):
        c = Counter(str(i+1))
        if len(str(i+1)) - c['0']==K:
            res += 1
    print(res)
    exit()
else:
    for i in range(1,100):
        c = Counter(str(i))
        k = len(str(i)) - c['0']
        dic[str(k)] += 1
def rec(n,k):
    re = 0
    if int(n)<=1000:
        re = 0
        for i in range(int(n)):
            c = Counter(str(i+1))
            if len(str(i+1)) - c['0']==k:
                re += 1
        return re
    if k==1:
        return 9*(len(n)-1)+int(n[0])
    t = ''.join(['9']*(len(n)-1))
    return rec(t, k) + (int(n[0])-1)*rec(t, k-1) + rec(n[1:], k-1)
print(rec(N,K))


Fixed submission:
from collections import Counter
N=input()
K=int(input())
km = len(N)
res = 0
if int(N)<=1000:
    for i in range(int(N)):
        c = Counter(str(i+1))
        if len(str(i+1)) - c['0']==K:
            res += 1
    print(res)
    exit()
d = [[0]*3 for _ in range(100001)]
for i in range(100000):
    d[i+1] = d[i][:]
    c = Counter(str(i+1))
    k=len(str(i+1)) - c['0']
    if k<=3:
        d[i+1][k-1] += 1
def rec(n,k):
    re = 0
    if int(n)<100000:
        re = 0
        return d[int(n)][k-1]
    if k==1:
        n = str(int(n))
        return 9*(len(n)-1)+int(n[0])
    t = ''.join(['9']*(len(n)-1))
    t2 = t
    w = (int(n[0])-1)
    if n[0] == '0':
        t2 = n[1:]
        w = 0
    return rec(t2, k) + w*rec(t2, k-1) + rec(str(int(n[1:])), k-1)
print(rec(N,K))
Buggy python submission (verdict: Time Limit Exceeded):
import sys
import bisect
input = sys.stdin.readline

class Bisect(object):
    def bisect_max(self, reva, func,M):
        ok = 0 # exist
        ng = 10**9 # not exist
        while abs(ok-ng) > 1:
            cnt = (ok + ng) // 2
            if func(cnt,reva,M):
                ok = cnt
            else:
                ng = cnt
        return ok

    def bisect_min(self, reva, func,M):
        ok = 10**9 # exist
        ng = 0 # not exist
        while abs(ok-ng) > 1:
            cnt = (ok + ng) // 2
            if func(cnt,reva,M):
                ok = cnt
            else:
                ng = cnt
        return ok

def solve1(tgt,reva,M):
    res=0
    n = len(reva)
    for i in range(n):
        tmp = bisect.bisect_left(reva,tgt-reva[i])
        tmp = n - tmp
        res += tmp
    if M <= res:
        return True
    else:
        return False

def solve2(tgt):
    print(tgt)
    if tgt > 12:
        return True
    else:
        return False
N,M = map(int,input().split())
a = list(map(int,input().split()))
a.sort(reverse=True)
reva = a[::-1]
bs = Bisect()
Kmax = (bs.bisect_max(reva,solve1,M))

r=[0]
for i in range(N):
    r.append(r[i]+a[i])

res = 0
cnt = 0
t = 0
for i in range(N):
    tmp = bisect.bisect_left(reva,Kmax-reva[N-i-1])
    tmp2 = bisect.bisect_right(reva,Kmax-reva[N-i-1])
    if tmp!=tmp2:
        t = 1
    tmp = N - tmp
    cnt += tmp
    res += tmp*a[i]+r[tmp]
if t==1:
    res -= (cnt-M)*Kmax
print(res)


Fixed submission:
import sys
import bisect
input = sys.stdin.readline

class Bisect(object):
    def bisect_max(self, reva, func,M):
        ok = 0 # exist
        ng = 4*(10**5) # not exist
        while abs(ok-ng) > 1:
            cnt = (ok + ng) // 2
            if func(cnt,reva,M):
                ok = cnt
            else:
                ng = cnt
        return ok

    def bisect_min(self, reva, func,M):
        ok = 10**5 # exist
        ng = 0 # not exist
        while abs(ok-ng) > 1:
            cnt = (ok + ng) // 2
            if func(cnt,reva,M):
                ok = cnt
            else:
                ng = cnt
        return ok

def solve1(tgt,reva,M):
    res=0
    n = len(reva)
    for i in range(n):
        tmp = bisect.bisect_left(reva,tgt-reva[i])
        tmp = n - tmp
        res += tmp
    if M <= res:
        return True
    else:
        return False

def solve2(tgt):
    print(tgt)
    if tgt > 12:
        return True
    else:
        return False
N,M = map(int,input().split())
a = list(map(int,input().split()))
a.sort(reverse=True)
reva = a[::-1]
bs = Bisect()
Kmax = (bs.bisect_max(reva,solve1,M))

r=[0]
for i in range(N):
    r.append(r[i]+a[i])

res = 0
cnt = 0
t = 0
for i in range(N):
    tmp = bisect.bisect_left(reva,Kmax-reva[N-i-1])
    tmp2 = bisect.bisect_right(reva,Kmax-reva[N-i-1])
    if tmp!=tmp2:
        t = 1
    tmp = N - tmp
    cnt += tmp
    res += tmp*a[i]+r[tmp]
if t==1:
    res -= (cnt-M)*Kmax
print(res)
Buggy python submission (verdict: Runtime Error):
import sys
import copy
import bisect
import numpy as np

def solve(a,n,N,M,V,P):
    if N-n+1 >= V:
        b = copy.deepcopy(a)
        b[n-1] += M
        tmp = b[n-1]
        b = sorted(b[0:n], reverse=True)
        k = bisect.bisect_left(b,tmp)
        if k<=P-1:
            return True
        else:
            return False
    else:
        V2 = V-N+n-1
        b = copy.deepcopy(a[0:n])
        b[n-1] += M
        tmp = b[n-1]
        b.sort()
        k = bisect.bisect_left(b,tmp)
        k = len(b)-k
        if k+N-1-n < V:
            if P<=k:
                return False
            elif P>=n:
                return True
            else:
                V2 = V-N+n-1
                num = P-k-N+n-1
                aaa = min([V2-1, num])
                if (np.sum(a[n-num:n])+M*aaa+num-1)//num <= tmp:
                    return True
                else:
                    return False
        else:
            b = copy.deepcopy(a)
            b[n-1] += M
            tmp = b[n-1]
            b = sorted(b[0:n])
            k = bisect.bisect_right(b,tmp)
            k = len(b)-k
            if k<=P:
                return True
            else:
                return False

def main():
    N,M,V,P = map(int,input().split())
    a = list(map(int,input().split()))
    a.sort(reverse=True)
    lo = 0
    hi = 2*N
    while lo + 1 < hi:
        cnt = (lo + hi) // 2
        if solve(a,cnt,N,M,V,P):
            lo = cnt
        else:
            hi = cnt

    return hi

if __name__ == '__main__':
    ans = main()
    print(ans)


Fixed submission:
import bisect
N, M, V, P = map(int, input().split())
a = list(map(int, input().split()))
a = sorted(a)
eps = 0.1
def func(k):
    # print("tsrget:"+str(k))
    used = 0
    tmp = a[:k]+a[k+1:]
    val = a[k]+M
    x1 = N-1-bisect.bisect(tmp, val+eps)
    x2 = bisect.bisect(tmp, val-eps)
    x3 = N-(x1+x2+1)
    # print(tmp,val,x1,x2,x3)
    if x1 >= P:
        return False
    v = V - (x1+1)
    p = P - (x1+1)
    used += x1+1
    if v <= 0:
        return True
    # x2+x3問からあとp問はa[k]+Mを超えてもよい
    # x3が十分ある
    if x3 >= p > 0:
        x3 -= p
        v -= p
        used += p
        p = 0
    if p>0:
        p -= x3
        v -= x3
        used += x3
    if x2 >= p > 0:
        x2 -= p
        v -= p
        used += p
        p = 0
    if p>0:
        p -= x2
        v -= x2
        used += x2
    if v <= 0:
        return True
    # x2問からあとp問はa[k]+Mを超えてもよい
    tmp2 = tmp[:N-used]
    rest = sum([min(M,val-val2) for val2 in tmp2])
    # print(tmp2,N,x1,x3,p,v, rest)
    if rest >= M*v:
        return True
    return False

ok = N-1  # exist
ng = -1  # not exist
while abs(ok - ng) > 1:
    cnt = (ok + ng) // 2
    t = func(cnt)
    # print(t)
    if t:
        ok = cnt
    else:
        ng = cnt
print(N-ok)
Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np
import sys
input = sys.stdin.readline
N = int(input())
a = list(map(int,input().split()))
ma = max(a)
maketa = len(bin(ma))-2
mat = np.zeros((N,maketa))
for i,elem in enumerate(a):
    mat[i] = np.array(list(bin(elem)[2:].zfill(maketa)))
res = 0
mat = mat.T
dic = {}
for i in range(maketa):
    dic[i] = int(np.sum(mat[maketa-i-1]))
for i in range(maketa):
    num = dic[i]
    res += num*(N-num)*(2**(i))
print(res%(10**9+7))


Fixed submission:
N = int(input())
a = list(map(int,input().split()))
ma = max(a)
maketa = len(bin(ma))-2
#print(maketa)
res = 0
dic = {}
for i in range(maketa):
    dic[i] = 0
for i in range(0,maketa):
    num = 0
    for j in range(N):
        #print(a[j] & (2**i))
        dic[i] += int((a[j] & (2**i))>>i)
        #count += 1
for i in range(maketa):
    num = dic[i]
    res += num*(N-num)*(2**(i))
print(res%(10**9+7))

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
a = list(map(int,input().split()))
ma = max(a)
maketa = len(bin(ma))-2
#print(maketa)
res = 0
dic = {}
for i in range(maketa):
    dic[i] = 0
for j in range(N):
    count = 0
    while a[j] >= 1:
        dic[count] += a[j] % 2
        a[j] = a[j] // 2
        count += 1
for i in range(maketa):
    num = dic[i]
    res += num*(N-num)*(2**(i))
print(res%(10**9+7))


Fixed submission:
N = int(input())
a = list(map(int,input().split()))
ma = max(a)
maketa = len(bin(ma))-2
#print(maketa)
res = 0
dic = {}
for i in range(maketa):
    dic[i] = 0
for i in range(0,maketa):
    num = 0
    for j in range(N):
        #print(a[j] & (2**i))
        dic[i] += int((a[j] & (2**i))>>i)
        #count += 1
for i in range(maketa):
    num = dic[i]
    res += num*(N-num)*(2**(i))
print(res%(10**9+7))
Buggy python submission (verdict: Runtime Error):
N=int(input())
a = list(map(int, input().split()))
dic={}
mul = [3,2,1]
res = 1
for i in range(len(a)):
    if a[i] in dic:
        dic[a[i]] += 1
    else:
        dic[a[i]] = 0
    if a[i] == 0:
        res *= mul[dic[0]]
    else:
        if a[i]-1 not in dic:
            print(0)
            exit()
        res *= dic[a[i]-1] - dic[a[i]] + 1
    res = res%(10**9+7)
print(res)


Fixed submission:
N=int(input())
a = list(map(int, input().split()))
dic={}
mul = [3,2,1]
res = 1
for i in range(len(a)):
    if a[i] in dic:
        if dic[a[i]] == 2:
            print(0)
            exit()
        dic[a[i]] += 1
    else:
        dic[a[i]] = 0
    if a[i] == 0:
        if dic[0] >= 3:
            print(0)
            exit()
        res *= mul[dic[0]]
    else:
        if a[i]-1 not in dic:
            print(0)
            exit()
        res *= dic[a[i]-1] - dic[a[i]] + 1
    res = res%(10**9+7)
print(res)