Buggy python submission (verdict: Time Limit Exceeded):
def main():
  N = int(input())
  A = list(map(int, input().split()))
  MOD = 10 ** 9 + 7
  ones = [sum(1 for a in A if a&(1<<i)) for i in range(60)]
  res = 0
  for j in range(N):
    a = A[j]
    for i in range(60):
      if (a >> i) & 1 == 0:
        res += ones[i] * ((2 ** i)%MOD)
      else:
        res += (N-ones[i]-j) * ((2 ** i)%MOD)
        ones[i] -= 1
      res %= MOD
  
  print(res)
if __name__ == "__main__":
    main()

Fixed submission:
def main():
  N = int(input())
  A = list(map(int, input().split()))
  MOD = 10 ** 9 + 7
  ones = [sum(1 for a in A if a&(1<<i)) for i in range(60)]
  res = 0
  for i in range(60):
    res += ones[i] * (N - ones[i]) * ((2 ** i) % MOD)
    res %= MOD
  print(res)
if __name__ == "__main__":
    main()

Buggy python submission (verdict: Time Limit Exceeded):
def main():
  N = int(input())
  A = list(map(int, input().split()))
  MOD = 10 ** 9 + 7
  ones = [sum(1 for a in A if a&(1<<i)) for i in range(60)]
  res = 0
  for j in range(N):
    a = A[j]
    for i in range(60):
      if (a >> i) & 1 == 0:
        res += ones[i] * (2 ** i)%MOD
      else:
        res += (N-ones[i]-j) * (2 ** i)%MOD
        ones[i] -= 1
      res %= MOD
  
  print(res)
if __name__ == "__main__":
    main()

Fixed submission:
def main():
  N = int(input())
  A = list(map(int, input().split()))
  MOD = 10 ** 9 + 7
  ones = [sum(1 for a in A if a&(1<<i)) for i in range(60)]
  res = 0
  for i in range(60):
    res += ones[i] * (N - ones[i]) * ((2 ** i) % MOD)
    res %= MOD
  print(res)
if __name__ == "__main__":
    main()

Buggy python submission (verdict: Time Limit Exceeded):
def main():
  N = int(input())
  A = list(map(int, input().split()))
  MOD = 10 ** 9 + 7
  ones = [0] * 60
  for a in A:
    for i in range(60):
      if (a >> i) & 1 == 1:
        ones[i] += 1
  # print(ones)
  res = 0
  for j in range(N):
    a = A[j]
    for i in range(60):
      if (a >> i) & 1 == 0:
        res += ones[i] * 2 ** i
      else:
        res += (N-ones[i]-j) * 2 ** i
        ones[i] -= 1
      res %= MOD
  
  print(res)
if __name__ == "__main__":
    main()

Fixed submission:
def main():
  N = int(input())
  A = list(map(int, input().split()))
  MOD = 10 ** 9 + 7
  ones = [sum(1 for a in A if a&(1<<i)) for i in range(60)]
  res = 0
  for i in range(60):
    res += ones[i] * (N - ones[i]) * ((2 ** i) % MOD)
    res %= MOD
  print(res)
if __name__ == "__main__":
    main()

Buggy python submission (verdict: Time Limit Exceeded):
from collections import defaultdict as dd

def main():
  N = int(input())
  A = list(map(int, input().split()))
  MOD = 10 ** 9 + 7
  ones = dd(int)
  zeros = dd(int)
  for a in A:
    for i in range(60):
      if (a >> i) & 1 == 1:
        ones[i] += 1
      else:
        zeros[i] += 1

  res = 0
  for a in A:
    for i in range(60):
      if (a >> i) & 1 == 1:
        res += zeros[i] * 2 ** i
        ones[i] -= 1
      else:
        res += ones[i] * 2 ** i
        zeros[i] -= 1
      res %= MOD
  
  print(res)
if __name__ == "__main__":
    main()

Fixed submission:
def main():
  N = int(input())
  A = list(map(int, input().split()))
  MOD = 10 ** 9 + 7
  ones = [sum(1 for a in A if a&(1<<i)) for i in range(60)]
  res = 0
  for i in range(60):
    res += ones[i] * (N - ones[i]) * ((2 ** i) % MOD)
    res %= MOD
  print(res)
if __name__ == "__main__":
    main()

Buggy python submission (verdict: Time Limit Exceeded):
def main():
  N = int(input())
  A = list(map(int, input().split()))
  MOD = 10 ** 9 + 7
  ones = [0] * 60
  zeros = [0] * 60
  for a in A:
    for i in range(60):
      if (a >> i) & 1 == 1:
        ones[i] += 1
      else:
        zeros[i] += 1

  res = 0
  for a in A:
    for i in range(60):
      if (a >> i) & 1 == 1:
        res += zeros[i] * 2 ** i
        ones[i] -= 1
      else:
        res += ones[i] * 2 ** i
        zeros[i] -= 1
      res %= MOD
  
  print(res)
if __name__ == "__main__":
    main()

Fixed submission:
def main():
  N = int(input())
  A = list(map(int, input().split()))
  MOD = 10 ** 9 + 7
  ones = [sum(1 for a in A if a&(1<<i)) for i in range(60)]
  res = 0
  for i in range(60):
    res += ones[i] * (N - ones[i]) * ((2 ** i) % MOD)
    res %= MOD
  print(res)
if __name__ == "__main__":
    main()

Buggy python submission (verdict: Time Limit Exceeded):
def main():
  N = int(input())
  A = list(map(int, input().split()))
  MOD = 10 ** 9 + 7
  ones = [0] * 60
  zeros = [0] * 60
  for i in range(N):
    x = A[i]
    x = bin(x)[2:]
    x = x.zfill(60)
    for j in range(59, -1, -1):
      if x[j] == '0':
        zeros[j] += 1
      else:
        ones[j] += 1
  # print(ones)
  # print(zeros)

  res = 0
  for i in range(N):
    x = A[i]
    x = bin(x)[2:]
    x = x.zfill(60)
    for j in range(60):
      if x[-j - 1] == '0':
        res += ones[-j - 1] * 2 ** j
        res %= MOD
        zeros[-j - 1] -= 1
      else:
        res += zeros[-j - 1] * 2 ** j
        res %= MOD
        ones[-j - 1] -= 1
  print(res)

if __name__ == "__main__":
    main()

Fixed submission:
def main():
  N = int(input())
  A = list(map(int, input().split()))
  MOD = 10 ** 9 + 7
  ones = [sum(1 for a in A if a&(1<<i)) for i in range(60)]
  res = 0
  for i in range(60):
    res += ones[i] * (N - ones[i]) * ((2 ** i) % MOD)
    res %= MOD
  print(res)
if __name__ == "__main__":
    main()

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = list(map(int, input().split()))
MOD = 10 ** 9 + 7
ones = [0] * 60
zeros = [0] * 60
for i in range(N):
  x = A[i]
  x = bin(x)[2:]
  x = x.zfill(60)
  for j in range(59, -1, -1):
    if x[j] == '0':
      zeros[j] += 1
    else:
      ones[j] += 1
# print(ones)
# print(zeros)

res = 0
for i in range(N):
  x = A[i]
  x = bin(x)[2:]
  x = x.zfill(60)
  for j in range(60):
    if x[-j - 1] == '0':
      res += ones[-j - 1] * 2 ** j
      res %= MOD
      zeros[-j - 1] -= 1
    else:
      res += zeros[-j - 1] * 2 ** j
      res %= MOD
      ones[-j - 1] -= 1
print(res)

Fixed submission:
def main():
  N = int(input())
  A = list(map(int, input().split()))
  MOD = 10 ** 9 + 7
  ones = [sum(1 for a in A if a&(1<<i)) for i in range(60)]
  res = 0
  for i in range(60):
    res += ones[i] * (N - ones[i]) * ((2 ** i) % MOD)
    res %= MOD
  print(res)
if __name__ == "__main__":
    main()