Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
from sys import stdin
 
N = int(stdin.readline().rstrip())
 
A = [int(x) for x in stdin.readline().rstrip().split()]
 
for a in range(N):  
  B = sorted([elem for idx,elem in enumerate(A) if idx != a])
  print(B[(N-1)//2])

Fixed submission:
from sys import stdin
 
N = int(stdin.readline().rstrip())
 
A = [int(x) for x in stdin.readline().rstrip().split()]

B = sorted(A)
 
for i in range(N):  
  if A[i] < B[N//2]:
    print(B[N//2])
  else:
    print(B[N//2-1])

Buggy python submission (verdict: Time Limit Exceeded):
from sys import stdin

N = int(stdin.readline().rstrip())

A = [int(x) for x in stdin.readline().rstrip().split()]

a = 0
while a < N:  
  B = [elem for idx,elem in enumerate(A) if idx != a]
  B.sort()
  a += 1
  print(B[(N-1)//2])

Fixed submission:
from sys import stdin
 
N = int(stdin.readline().rstrip())
 
A = [int(x) for x in stdin.readline().rstrip().split()]

B = sorted(A)
 
for i in range(N):  
  if A[i] < B[N//2]:
    print(B[N//2])
  else:
    print(B[N//2-1])

Buggy python submission (verdict: Time Limit Exceeded):
import statistics

N = int(input())

A = [int(x) for x in input().split()]

a = 0
while a < N:  
  B = [elem for idx,elem in enumerate(A) if idx != a]
  a += 1
  print(statistics.median(B))

Fixed submission:
from sys import stdin
 
N = int(stdin.readline().rstrip())
 
A = [int(x) for x in stdin.readline().rstrip().split()]

B = sorted(A)
 
for i in range(N):  
  if A[i] < B[N//2]:
    print(B[N//2])
  else:
    print(B[N//2-1])

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())

A = [int(x) for x in input().split()]

a = 0
while a < N:  
  B = [elem for idx,elem in enumerate(A) if idx != a]
  B.sort()
  a += 1
  print(B[(N-1)//2])

Fixed submission:
from sys import stdin
 
N = int(stdin.readline().rstrip())
 
A = [int(x) for x in stdin.readline().rstrip().split()]

B = sorted(A)
 
for i in range(N):  
  if A[i] < B[N//2]:
    print(B[N//2])
  else:
    print(B[N//2-1])

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())

A = [int(x) for x in input().split()]

a = 0
while a < N:  
  B = sorted(A[:a]+A[a+1:])
  a += 1
  print(B[(N-1)//2])

Fixed submission:
from sys import stdin
 
N = int(stdin.readline().rstrip())
 
A = [int(x) for x in stdin.readline().rstrip().split()]

B = sorted(A)
 
for i in range(N):  
  if A[i] < B[N//2]:
    print(B[N//2])
  else:
    print(B[N//2-1])
Buggy python submission (verdict: Time Limit Exceeded):
A,B,K = map(int,input().split())

a = [i for i in range(A,B+1)]

b = sorted(set(a[:K]+a[-K:]))

print(*b, sep = "\n")

Fixed submission:
A,B,K = map(int,input().split())

if K >= B:
  print(*sorted(range(A,B+1)), sep = "\n")

else:
  a = [i for i in range(A,min(B+1,A+K))]
  b = [i for i in range(B,max(A-1,B-K),-1)]
  print(*sorted(set(a+b)), sep = "\n")
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())

if N == 1:
  print(1 if int(input()) != 1 else 0)
  exit()

a = [int(x) for x in input().split()]
 
b = list(set(a))

c = []
for i in b:
  if a.count(i)-i < 0:
    c.append(a.count(i))
  else:
    c.append(a.count(i)-i)

print(sum(c))  
  


Fixed submission:
import collections

N = int(input())

if N == 1:
  print(1 if int(input()) != 1 else 0)
  exit()

a = [int(x) for x in input().split()]

b = list(collections.Counter(a).items())

c = 0
for i in b:
  if i[1] - i[0] < 0:
    c += i[1]
  else:
    c += i[1] - i[0]

print(c)
Buggy python submission (verdict: Time Limit Exceeded):
N,K = map(int,input().split())
A = [int(x) for x in input().split()]
B = list(set(A))

C = []
for i in B:
  C.append(A.count(i))

print(sum(sorted(C)[:-K:]))  

Fixed submission:
import collections

N,K = map(int,input().split())
A = [int(x) for x in input().split()]

B = sorted(list(collections.Counter(A).values()),reverse=True)

print(sum(B[K::]))

Buggy python submission (verdict: Time Limit Exceeded):
N,K = map(int,input().split())
A = [int(x) for x in input().split()]
B = list(set(A))

C = []
for i in B:
  C.append([i,A.count(i)])

D = sorted(C,key=lambda x: x[1])

print(sum(x[1] for x in D[:-K:]))

Fixed submission:
import collections

N,K = map(int,input().split())
A = [int(x) for x in input().split()]

B = sorted(list(collections.Counter(A).values()),reverse=True)

print(sum(B[K::]))
Buggy python submission (verdict: Time Limit Exceeded):
K,S = map(int,input().split())

cnt = []
for a in range(K+1):
  for b in range(K+1):
    if S-a-b>=0 and S-a-b<=K:
      cnt.append(S-a-b)
        
print(len(cnt))  

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

cnt = 0
for a in range(K+1):
  for b in range(K+1):
    if S-a-b>=0 and S-a-b<=K:
      cnt += 1
        
print(cnt)

Buggy python submission (verdict: Time Limit Exceeded):
K,S = map(int,input().split())

cnt =0
for a in range(K+1):
  for b in range(min(S+1-a,K+1)):
    for c in range(min(S+1-a-b,K+1)):
      if a+b+c == S:
        cnt += 1
        
print(cnt)  

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

cnt = 0
for a in range(K+1):
  for b in range(K+1):
    if S-a-b>=0 and S-a-b<=K:
      cnt += 1
        
print(cnt)

Buggy python submission (verdict: Time Limit Exceeded):
K,S = map(int,input().split())

cnt =0
for a in range(K+1):
  for b in range(K+1):
    for c in range(K+1):
      if a+b+c == S:
        cnt += 1
        
print(cnt)  

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

cnt = 0
for a in range(K+1):
  for b in range(K+1):
    if S-a-b>=0 and S-a-b<=K:
      cnt += 1
        
print(cnt)
Buggy python submission (verdict: Runtime Error):
defmain():N =int(input())A =list(map(int,input().split()))if0inA:print(0)returnprod = 1forainA:prod *= aifprod > 1000000000000000000:print(-1)returnprint(prod)main()

Fixed submission:
def main():
	N =int(input())
	A =list(map(int,input().split()))
	if 0 in A:
		print(0)
		return

	prod = 1 
	for a in A:
		prod *= a
		if prod > 1000000000000000000:
			print(-1)
			return

	print(prod)


main()
Buggy python submission (verdict: Runtime Error):
class UnionFind:

    def __init__(self):
        self.parents = {}
        self.sz = {}
        self.size = 0


    def add(self, a):
        if a in self.parents:
            return
        self.size += 1
        self.sz[a] = 1
        self.parents[a] = a 

    def find(self, a):
        if self.parents[a] != a:
            self.parents[a] = self.find(self.parents[a])

        return self.parents[a]

    def join(self, a, b):
        pa, pb = self.find(a), self.find(b)
        if pa == pb:
            return
        if self.sz[pa] > self.sz[pb]:
            self.parents[pb] = pa
            self.sz[pa] += self.sz[pb]
        else:
            self.parents[pa] = pb 
            self.sz[pb] += self.sz[pa]

        self.size -= 1


n,m = list(map(int,input().split(" ")))
uf = UnionFind()
ans = 0
for _ in range(m):
    x,y = list(map(int,input().split(" ")))
    uf.add(x)
    uf.add(y)
    uf.join(x,y)
    ans = max(ans, uf.sz[x])


print(max(uf.sz.values()))


Fixed submission:
class UnionFind:

    def __init__(self):
        self.parents = {}
        self.sz = {}
        self.size = 0


    def add(self, a):
        if a in self.parents:
            return
        self.size += 1
        self.sz[a] = 1
        self.parents[a] = a 

    def find(self, a):
        if self.parents[a] != a:
            self.parents[a] = self.find(self.parents[a])

        return self.parents[a]

    def join(self, a, b):
        pa, pb = self.find(a), self.find(b)
        if pa == pb:
            return
        if self.sz[pa] > self.sz[pb]:
            self.parents[pb] = pa
            self.sz[pa] += self.sz[pb]
        else:
            self.parents[pa] = pb 
            self.sz[pb] += self.sz[pa]

        self.size -= 1


n,m = list(map(int,input().split(" ")))
uf = UnionFind()
ans = 0
if m == 0:
    print(1)
else:
    for _ in range(m):
        x,y = list(map(int,input().split(" ")))
        uf.add(x)
        uf.add(y)
        uf.join(x,y)
        ans = max(ans, uf.sz[x])

    print(max(uf.sz.values()))
Buggy python submission (verdict: Runtime Error):
n = int(input())
if n > 30:
  prtin('Yes')
 else:
  print('No')

Fixed submission:
n = int(input())
if n < 30:
  print("No")
else:
  print("Yes")

Buggy python submission (verdict: Runtime Error):
n = int(input())
if n >= 30:
  prtin('Yes')
 else:
  print('No')

Fixed submission:
n = int(input())
if n < 30:
  print("No")
else:
  print("Yes")
Buggy python submission (verdict: Runtime Error):
#include <bits/stdc++.h>
#include <iostream>
//#include <algorithm>
// #include <iomanip>
#define ll long long

using namespace std;

set<ll> prime_factor(ll num) {
  set<ll> result;
  for (ll i = 2; i <= num; i++) {
    int j = 0;
    while (num % i == 0) {
      if (j == 0) {
        result.insert(i);
      }
      num /= i;
      j++;
    }
    if (num <= i) {
      break;
    }
  }
  return result;
}

ll calc(ll num, set<ll> s) {
  ll count = 0;
  for (ll i = 2; i <= num; i++) {
    int j = 0;
    while (num % i == 0) {
      if (j == 0) {
        if (s.find(i) != s.end()) {
          count++;
        }
      }
      num /= i;
      j++;
    }
    if (num <= i) {
      break;
    }
  }
  return count;
}

int main() {
  ll n1, n2;
  cin >> n1 >> n2;
  auto a1 = prime_factor(n1);
  cout << calc(n2, a1) + 1 << endl;
}


Fixed submission:
def f(n):
    result = set()
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp % i == 0:
            cnt = 0
            while temp % i == 0:
                cnt += 1
                temp //= i
            result.add(i)

    if temp != 1:
        result.add(temp)

    return result


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

fa = f(a)
fb = f(b)

print(len(fa & fb)+1)
Buggy python submission (verdict: Time Limit Exceeded):

# 1 2
n, m = list(map(int, input().split()))
c = [None]*m

key_prices = [0]*m
key_targets = [None]*m

for i in range(m):
    yen, matches_num = list(map(int, input().split()))
    key_prices[i] = yen
    key_targets[i] = set(map(int, input().split()))


min_price = -1


def calc(i, status):
    res = 0

    if i >= m:
        # res = 0
        if len(status) >= n:
            # print(status)
            # print(res)
            global min_price
            if res != 0 and (min_price == -1 or min_price > res):
                min_price = res
        else:
            res = 999999999
    elif key_targets[i] < status:
        # 入れる意味がない
        res = calc(i+1, status)
    else:
        r1 = calc(i+1, status)
        status = status | key_targets[i]
        r2 = calc(i+1, status)+key_prices[i]
        res = min(r1, r2)
    # memo[memo_key] = res

    return res


r = calc(0, set())

if r == 999999999:
    print(-1)
else:
    print(r)


Fixed submission:
box_num, key_num = map(int, input().split())
dp_length = 2**box_num
dp = [float('inf')] * dp_length
dp[0] = 0
for _ in range(key_num):
    current_key_price, _ = map(int, input().split())
    c = 0
    effects = list(map(int, input().split()))
    for i in effects:
        e = 1 << (i - 1)
        c += e
    for x in range(dp_length):
        new_price = dp[x] + current_key_price
        dp_index = c | x
        if dp[dp_index] > new_price:
            dp[dp_index] = new_price
    # print(dp)
if dp[-1] == float('inf'):
    print(-1)
else:
    print(dp[-1])
Buggy python submission (verdict: Time Limit Exceeded):
def calc_point(points, n):
    for i in range(len(points)):
        if i != n:
            points[i] -= 1


n, k, q = list(map(int, input().split(" ")))

points = []
for i in range(n):
    points.append(k)

for i in range(q):
    a = int(input())
    calc_point(points, a-1)


for i in range(len(points)):
    if points[i] <= 0:
        print("No")
    else:
        print("Yes")



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

points = {}

for i in range(q):
    a = int(input())
    if a not in points:
        points[a] = 0
    points[a] += 1


for i in range(n):
    p = 0
    if (i+1) in points:
        p = points[i+1]
    if k - q+p >= 1:
        print("Yes")
    else:
        print("No")
Buggy python submission (verdict: Time Limit Exceeded):
import math


def max_index(list, max_index):
    r = -1
    max = -1
    for i in range(max_index + 1):
        v = list[i]
        if v > max:
            max = v
            r = i
    return r


def use_coupon(a, m):
    current_index = 0
    for _ in range(m):
        index = max_index(a, current_index)
        a[index] /= 2
        current_index += index + 1
        if current_index >= len(a):
            current_index = len(a)-1


def sum(a):
    s = 0
    for v in a:
        s += math.floor(v)
    return s


n, m = list(map(int, input().split(" ")))
a = list(map(int, input().split(" ")))
a.sort(reverse=True)

use_coupon(a, m)

print(sum(a))


Fixed submission:
import math
from heapq import heappush, heappop


def rint(s):
    return -int(s)


def sum(a):
    s = 0
    for v in a:
        s += math.floor(-v)
    return s


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

for i in range(m):
    v = heappop(a)
    heappush(a, v/2)

print(sum(a))

Buggy python submission (verdict: Time Limit Exceeded):
import math


def max_index(list):
    r = -1
    max = 0
    for i in range(len(list)):
        v = list[i]
        if v > max:
            max = v
            r = i
    return r


def use_coupon(a):
    index = max_index(a)
    a[index] /= 2


def sum(a):
    s = 0
    for v in a:
        s += math.floor(v)
    return s


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

for i in range(m):
    use_coupon(a)

print(sum(a))


Fixed submission:
import math
from heapq import heappush, heappop


def rint(s):
    return -int(s)


def sum(a):
    s = 0
    for v in a:
        s += math.floor(-v)
    return s


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

for i in range(m):
    v = heappop(a)
    heappush(a, v/2)

print(sum(a))
Buggy python submission (verdict: Time Limit Exceeded):

def calc(n):
    r = 0
    for i in range(1, n):
        r += i
    return r


n = int(input())
r = calc(n)
print(r)


Fixed submission:

def calc(n):
    return (1 + n - 1) * (n-1) // 2


n = int(input())
r = calc(n)
print(r)

Buggy python submission (verdict: Time Limit Exceeded):

def calc(n):
    r = 0
    for i in range(1, n):
        r += i
    return r


n = int(input())
r = calc(n)
print(r)


Fixed submission:

def calc(n):
    return (1 + n - 1) * (n-1) // 2


n = int(input())
r = calc(n)
print(r)
Buggy python submission (verdict: Time Limit Exceeded):
def remove(s):
    r = None
    for i in range(len(s)-1):
        if s[i] != s[i+1]:
            r = s[0:i] + s[i+2:]
            break
    return r


def calc(s):
    count = 0
    c = s
    while True:
        t = remove(c)
        if t == None:
            break
        count += 2
        c = t
    return count


s = input()
print(calc(s))


Fixed submission:
s = input()
print(2*min(s.count('0'), s.count('1')))
Buggy python submission (verdict: Runtime Error):
s = input()
l = len(s)
if s[l - 1] == "s":
	s += "es"
else:
 	l.append("s")
print(s)

Fixed submission:
s = input()
if s[-1] == "s":
	s += "es"
else:
 	s += "s"
print(s)

Buggy python submission (verdict: Runtime Error):
s = input()
l = len(s)
if s[l - 1] == s:
	l.append(es)
else:
 	l.append(s)
print(s)

Fixed submission:
s = input()
if s[-1] == "s":
	s += "es"
else:
 	s += "s"
print(s)

Buggy python submission (verdict: Runtime Error):
s = input()
l = len(s)
if(s[l - 1]) == 's':
	l.append(es)
else:
 	l.append(s)
print(s)

Fixed submission:
s = input()
if s[-1] == "s":
	s += "es"
else:
 	s += "s"
print(s)

Buggy python submission (verdict: Runtime Error):
s = input()
l = len(s)
if(s[l - 1]) == s:
	l.append(es)
else:
 	l.append(s)
print(s)

Fixed submission:
s = input()
if s[-1] == "s":
	s += "es"
else:
 	s += "s"
print(s)
Buggy python submission (verdict: Runtime Error):
n = int(input())
count = 0
for a in range(1,n):
    count += int((n-1)/a)
print(count)n = int(input())
count = 0
for a in range(1,n):
    count += int((n-1)/a)
print(count)

Fixed submission:
n = int(input())
count = 0
for a in range(1,n):
    count += (n-1)//a
print(count)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
count = 0
for a in range(1,n):
    for b in range(1,int(n/a)+1):
        if n - a * b > 0:
            count += 1
print(count)



Fixed submission:
n = int(input())
count = 0
for a in range(1,n):
    count += (n-1)//a
print(count)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
count = 0
for c in range(1,n):
    ab = n - c
    for a in range(1,n):
        if ab % a == 0:
            count += 1
print(count)

Fixed submission:
n = int(input())
count = 0
for a in range(1,n):
    count += (n-1)//a
print(count)

Buggy python submission (verdict: Runtime Error):
n = int(input())
count = 0
for c in range(n):
    ab = n - c
    if ab % a == 0:
        count += 1
print(count)

Fixed submission:
n = int(input())
count = 0
for a in range(1,n):
    count += (n-1)//a
print(count)

Buggy python submission (verdict: Runtime Error):
n = int(input())
count = 0
for c in range(n):
	ab = n - c
    if ab % a = 0:
      count += 1
print(count)

Fixed submission:
n = int(input())
count = 0
for a in range(1,n):
    count += (n-1)//a
print(count)
Buggy python submission (verdict: Runtime Error):
def digit_sum(n):
    n_lst = list( str(n) )
    n_sum = 0
    for i in range( len(n_lst) ):
        n_sum += int( n_lst[i] )
    return n_sum
 
n1 = input()
if digit_sum(n1)%9==0 : print("Yes")
else: print("No"

Fixed submission:
def digit_sum(n):
    n_lst = list( str(n) )
    n_sum = 0
    for i in range( len(n_lst) ):
        n_sum += int( n_lst[i] )
    return n_sum

n1 = input()
if digit_sum(n1)%9==0 : print("Yes")
else: print("No")
Buggy python submission (verdict: Time Limit Exceeded):
s = list(input())
q = int(input())
ones = 0
for _ in range(q):
	inp = list(input().split())
	if inp[0] == '1':
		ones+=1	
	else:
		if ones % 2 == 1:
			s = s[::-1]
		ones = 0
		if inp[1] == '1':
			s.insert(0, inp[2])	
		else:
			s.append(inp[2])
if ones % 2 == 1:
	s = s[::-1]
print(''.join(s))

Fixed submission:
from collections import deque

S = input()
Q = int(input())
s = deque(list(S))
re = False
 
for i in range(Q):
    q = list(map(str,input().split()))
    if q[0] == "1":
        re = not re
    else:
        b = int(q[1])-1
        if (re and b) or not(re or b):
            s.appendleft(q[2])
        else:
            s.append(q[2])
 
ans = ""
if re:
    while s:
    	ans += s.pop()
else:
    while s:
        ans += s.popleft()
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
s = list(input())
q = int(input())
for _ in range(q):
	inp = list(input().split())
	if inp[0] == '1':
		s = s[::-1]
	else:
		if inp[1] == '1':
			s.insert(0, inp[2])	
		else:
			s.append(inp[2])
print(''.join(s))

Fixed submission:
from collections import deque

S = input()
Q = int(input())
s = deque(list(S))
re = False
 
for i in range(Q):
    q = list(map(str,input().split()))
    if q[0] == "1":
        re = not re
    else:
        b = int(q[1])-1
        if (re and b) or not(re or b):
            s.appendleft(q[2])
        else:
            s.append(q[2])
 
ans = ""
if re:
    while s:
    	ans += s.pop()
else:
    while s:
        ans += s.popleft()
print(ans)
Buggy python submission (verdict: Runtime Error):
n, m = map(int, input().split())
bad = []
for i in range(m):
    bad.append(int(input()))
dp = [0 for x in range(n+1)]
dp[0] = 1
idx = 0
if bad[0] == 1:
    dp[1] = 0
    idx = 1
else:
    dp[1] = 1

for i in range(2, n+1):
    if idx < m and i == bad[idx]:
        dp[i] = 0
        idx+=1
    else:
        dp[i] = (dp[i-1] + dp[i-2]) % 1000000007

print(dp[n])





Fixed submission:
n, m = map(int, input().split())
bad = []
for i in range(m):
    bad.append(int(input()))
dp = [0 for x in range(n+1)]
dp[0] = 1
idx = 0
if m > 0 and bad[0] == 1:
    dp[1] = 0
    idx = 1
else:
    dp[1] = 1

for i in range(2, n+1):
    if idx < m and i == bad[idx]:
        dp[i] = 0
        idx+=1
    else:
        dp[i] = (dp[i-1] + dp[i-2]) % 1000000007

print(dp[n])
Buggy python submission (verdict: Time Limit Exceeded):
from collections import Counter

n, k = map(int, input().split())
l = list(map(int, input().split()))

dic = Counter(l)
ans = 0
kv = dic.items()
kv = sorted(kv, key=lambda x: x[1])
while len(kv) > k:
    ans += kv[0][1]
    del kv[0]

print(ans)

Fixed submission:
from collections import Counter

n, k = map(int, input().split())
dic = Counter(list(map(int, input().split())))
kv = dic.items()
kv = sorted(kv, key=lambda x: x[1])
ans = 0
cnt = 0
while len(kv)-cnt > k:
    ans += kv[cnt][1]
    cnt+=1
print(ans)
Buggy python submission (verdict: Runtime Error):
def isPal(s):
    if s == s[::-1]:
        return True
    return False

s = list(input())
pal = ''
for ch in s:
    if ch != 'x':
        pal+=ch

if not isPal(pal):
    print(-1)
else:
    beg = s.index(pal[0])
    end = len(s)-1 - s[::-1].index(pal[-1])
    half = 0 if len(pal) == 1 else len(pal)//2 + 1
    cnt = 0
    for i in range(len(s)):
        if cnt == half:
            break
        if s[i] != 'x':
            cnt += 1
    print(abs(cnt-beg - (end-cnt)) + abs(beg - (len(s)-1-end)))

    
    


Fixed submission:
s = list(input())
l = 0
r = len(s)-1
ans = 0
while l < r:
    if s[l] == s[r]:
        l+=1
        r-=1
    elif s[l] == 'x':
        l+=1
        ans+=1
    elif s[r] == 'x':
        r-=1
        ans+=1
    else:
        print(-1)
        exit()
print(ans)
Buggy python submission (verdict: Runtime Error):
n = input()

if n[len(n - 1)] == 's':
    print(n + 'es')
else:
    print(n + 's')

Fixed submission:
n = input()

if n[len(n) - 1] == 's':
    print(n + 'es')
else:
    print(n + 's')
Buggy python submission (verdict: Runtime Error):
a = int(input())
print(a * (a ** 3 - 1) / (a - 1))

Fixed submission:
a = int(input())
print(a * (1 + a * (1 + a)))
Buggy python submission (verdict: Time Limit Exceeded):
import sys

def get(x,n):
    return ((1<<x)&(n))!=0


def main():
    mod=1000000000+7
    n=int(sys.stdin.readline())
    a=list(map(int,sys.stdin.readline().split()))
    ans=0
    for x in range(60):
        now=get(x,a[-1])
        nnow=not get(x,a[-1])
        for i in range(n-2,-1,-1):
            now+=get(x,a[i])
            nnow+=not get(x,a[i])
            if get(x,a[i]):
                ans+=(2**x)*nnow
            else:
                ans+=(2**x)*now
    print(ans%mod)
main()


Fixed submission:
import sys

def get(x,n):
    return ((1<<x)&(n))!=0


def main():
    mod=1000000000+7
    n=int(sys.stdin.readline())
    a=list(map(int,sys.stdin.readline().split()))
    ans=0
    cur=1
    for x in range(60):
        res=get(x,a[-1])
        now=res
        nnow=not res
        total=0
        for i in range(n-2,-1,-1):
            res=get(x,a[i])
            now+=res
            nnow+=not res
            if res:
                total+=nnow
            else:
                total+=now
        ans+=cur*total
        ans%=mod
        cur*=2
    print(ans%mod)
main()