Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
N, M = map(int, input().split())
P = map(int, input().split())

parent = list(range(N))
rank = [0] * N
key = [[i] for i in range(N)]
val = [[p-1] for p in P]

# union-find
def getRoot(x):
  p = parent[x]
  if p == x:
    return p
  ret = getRoot(p)
  parent[x] = ret
  return ret

def join(x, y):
  rx = getRoot(x)
  ry = getRoot(y)
  if rank[rx] < rank[ry]:
    parent[rx] = ry
    key[ry] += key[rx]
    val[ry] += val[rx]
  else:
    parent[ry] = rx
    key[rx] += key[ry]
    val[rx] += val[ry]
    if rank[rx] == rank[ry]:
      rank[rx] += 1

for _ in range(M):
  x, y = map(int, input().split())
  join(x-1, y-1)

ans = 0
for i in range(N):
  if parent[i] == i:
    ans += len(set(key[i]).intersection(set(val[i])))

print(ans)

Fixed submission:
N, M = map(int, input().split())
P = list(map(int, input().split()))

parent = list(range(N))
rank = [0] * N

idx = [None] * N
for i in range(N):
  idx[P[i]-1] = i

# union-find
def getRoot(x):
  p = parent[x]
  if p == x:
    return p
  ret = getRoot(p)
  parent[x] = ret
  return ret

def join(x, y):
  rx = getRoot(x)
  ry = getRoot(y)
  if rank[rx] < rank[ry]:
    parent[rx] = ry
  else:
    parent[ry] = rx
    if rank[rx] == rank[ry]:
      rank[rx] += 1

for _ in range(M):
  x, y = map(int, input().split())
  join(x-1, y-1)

ans = 0
for i in range(N):
  if getRoot(i) == getRoot(idx[i]):
    ans += 1

print(ans)

Buggy python submission (verdict: Runtime Error):
N, M = map(int, input().split())
P = map(int, input().split())

parent = list(range(N))
rank = [0] * N
key = [[i] for i in range(N)]
val = [[p-1] for p in P]

# union-find
def getRoot(x):
  p = parent[x]
  if p == x:
    return p
  ret = getRoot(p)
  parent[x] = ret
  return ret

def join(x, y):
  rx = getRoot(x)
  ry = getRoot(y)
  if rank[rx] < rank[ry]:
    parent[rx] = ry
    key[ry] += key[rx]
    val[ry] += val[rx]
  else:
    parent[y] = x
    key[rx] += key[ry]
    val[rx] += val[ry]
    if rank[rx] == rank[ry]:
      rank[rx] += 1

for _ in range(M):
  x, y = map(int, input().split())
  join(x-1, y-1)

ans = 0
for i in range(N):
  if parent[i] == i:
    ans += len(set(key[i]).intersection(set(val[i])))

print(ans)

Fixed submission:
N, M = map(int, input().split())
P = list(map(int, input().split()))

parent = list(range(N))
rank = [0] * N

idx = [None] * N
for i in range(N):
  idx[P[i]-1] = i

# union-find
def getRoot(x):
  p = parent[x]
  if p == x:
    return p
  ret = getRoot(p)
  parent[x] = ret
  return ret

def join(x, y):
  rx = getRoot(x)
  ry = getRoot(y)
  if rank[rx] < rank[ry]:
    parent[rx] = ry
  else:
    parent[ry] = rx
    if rank[rx] == rank[ry]:
      rank[rx] += 1

for _ in range(M):
  x, y = map(int, input().split())
  join(x-1, y-1)

ans = 0
for i in range(N):
  if getRoot(i) == getRoot(idx[i]):
    ans += 1

print(ans)
Buggy python submission (verdict: Runtime Error):
m, d = map(int, input().split())

if d >= m:
  print(m)
else:
  print(m-1)

Fixed submission:
a, b, c = map(int, input().split())
k = int(input())
print(a+b+c - max(a,b,c) + max(a,b,c)*(2**k))
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
m = [input() for _ in range(N)]

ans = 0
for z in range(N): #ずらし
  brk = False
  for y in range(N):
    for x in range(y+1, N):
      if m[y][x] != m[x][y]:
        brk = True
        break
    if brk:
      break
  else:
    ans += N
  m = [l[-1]+l[:-1] for l in m]

print(ans)

Fixed submission:
N = int(input())
m = [input() for _ in range(N)]
mt = list(map(''.join, zip(*m)))

ans = 0
for z in range(N): #ずらし
  for y in range(N):
    if m[y][y+1:] != mt[y][y+1:]:
      break
  else:
    ans += N
  m = [l[-1]+l[:-1] for l in m]
  mt = [mt[-1]] + mt[:-1]

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
K = int(input())
A = list(map(int, input().split()))
A.reverse()
A.append(1)
prev = set()
if A[0] == 2:
  prev.add(2)

for i in range(K):
  a = A[i]
  an = A[i+1]
  s = set()
  for n in prev:
    if n+a <= an:
      continue
    for x in range(((n+an-1)//an)*an, n+a, an):
      s.add(x)
  prev = s

if len(prev) > 0:
  print(min(prev), max(prev))
else:
  print('-1')

Fixed submission:
K = int(input())
A = list(map(int, input().split()))
A.reverse()
A.append(1)
ansmin = 2
ansmax = 2
for a in A:
  tmin = ((ansmin+a-1)//a)*a
  tmax = (ansmax//a)*a
  if tmin > tmax:
    print('-1')
    exit()
  ansmin = tmin
  ansmax = tmax + a - 1
print(ansmin, ansmax)

Buggy python submission (verdict: Time Limit Exceeded):
K = int(input())
A = list(map(int, input().split()))
A.reverse()
prev = set([2])
for a in A:
  s = set()
  for n in prev:
    if n % a == 0: # そのラウンドでn人残るための条件
      for x in range(n, n+a):
        s.add(x)
  prev = s

if len(prev) > 0:
  print(min(prev), max(prev))
else:
  print('-1')

Fixed submission:
K = int(input())
A = list(map(int, input().split()))
A.reverse()
A.append(1)
ansmin = 2
ansmax = 2
for a in A:
  tmin = ((ansmin+a-1)//a)*a
  tmax = (ansmax//a)*a
  if tmin > tmax:
    print('-1')
    exit()
  ansmin = tmin
  ansmax = tmax + a - 1
print(ansmin, ansmax)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = list(map(int, input().split()))

sumA = sum(A)
ct = {0:1}

for a in A:
  nct = {}
  for k in ct:
    nct[k] = nct.get(k, 0) + ct[k]
    nct[k+a] = nct.get(k+a, 0) + ct[k]
  ct = nct

ct[0] = 0
medidx = (2**N)//2
n = 0
keys = list(ct.keys())
keys.sort()
for key in keys:
  n += ct[key]
  if n >= medidx:
    print(key)
    exit()

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

sumA = sum(A)
halfA = math.ceil(sumA / 2)
bitset = 1
for a in A:
  bitset |= bitset << a

bitset >>= halfA
i = 0
while i < halfA:
  if bitset & 1:
    print(i+halfA)
    exit()
  bitset >>= 1
  i += 1
print(i+halfA)

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

sumA = sum(A)
ct = {0:1}

for a in A:
  nct = {}
  for k in ct:
    nct[k] = nct.get(k, 0) + ct[k]
    nct[k+a] = nct.get(k+a, 0) + ct[k]
  ct = nct

ct[0] = 0
medidx = (2**N)//2
n = 0
for i in range(sumA+1):
  n += ct.get(i, 0)
  if n >= medidx:
    print(i)
    exit()

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

sumA = sum(A)
halfA = math.ceil(sumA / 2)
bitset = 1
for a in A:
  bitset |= bitset << a

bitset >>= halfA
i = 0
while i < halfA:
  if bitset & 1:
    print(i+halfA)
    exit()
  bitset >>= 1
  i += 1
print(i+halfA)

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

ct = [0]*(sum(A)+1)
ct[0] = 1
ctlen = len(ct)

for a in A:
  for i in range(ctlen-a-1,-1,-1):
    ct[i+a] += ct[i]

ct[0] = 0
medidx = (2**N)//2
n = 0
for i in range(ctlen):
  n += ct[i]
  if n >= medidx:
    print(i)
    exit()

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

sumA = sum(A)
halfA = math.ceil(sumA / 2)
bitset = 1
for a in A:
  bitset |= bitset << a

bitset >>= halfA
i = 0
while i < halfA:
  if bitset & 1:
    print(i+halfA)
    exit()
  bitset >>= 1
  i += 1
print(i+halfA)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())

prime = [True] * 100001
like2017 = [False] * 100001
for i in range(2, 100001):
  if prime[i]:
    for j in range(i*2, 100001, i):
      prime[j] = False
    if i != 2 and prime[(i+1)//2]:
      like2017[i] = True

for i in range(N):
  l, r = map(int, input().split())
  print(sum(like2017[l:r+1]))

Fixed submission:
N = int(input())

prime = [True] * 100001
like2017 = [0] * 100001
num = 0
for i in range(2, 100001):
  if prime[i]:
    for j in range(i*2, 100001, i):
      prime[j] = False
    if i != 2 and prime[(i+1)//2]:
      num += 1
  like2017[i] = num

for i in range(N):
  l, r = map(int, input().split())
  print(like2017[r] - like2017[l-1])
Buggy python submission (verdict: Time Limit Exceeded):
arr = []
prev = None
num = 0
for c in input():
  if prev is not None and c != prev:
    arr.append(num)
    num = 0
  prev = c
  num += 1
arr.append(num)

while len(arr) > 2:
  if arr[0] > arr[-1]:
    arr = arr[:-2] + [arr[-2]+arr[-1]]
  else:
    arr = [arr[0]+arr[1]] + arr[2:]

print(max(arr))

Fixed submission:
from collections import deque
arr = deque()
prev = None
num = 0
for c in input():
  if prev is not None and c != prev:
    arr.append(num)
    num = 0
  prev = c
  num += 1
arr.append(num)

while len(arr) > 2:
  if arr[0] > arr[-1]:
    v = arr.pop()
    v += arr.pop()
    arr.append(v)
  else:
    v = arr.popleft()
    v += arr.popleft()
    arr.appendleft(v)

print(max(arr))
Buggy python submission (verdict: Time Limit Exceeded):
import sys
s = input()
X, Y = map(int, input().split())

sys.setrecursionlimit(8001)

dirs = [(1, 0), (0, -1), (-1, 0), (0, 1)]
S = list(map(len, s.split('T')))
N = len(S)
memo = {}
def process(i, x, y, d):
  if (i,x,y,d) in memo:
    return
  if i >= N:
    if x == X and y == Y:
      print('Yes')
      exit()
    return
  memo[(i,x,y,d)] = 1
  x += dirs[d][0] * S[i]
  y += dirs[d][1] * S[i]
  process(i+1, x, y, (d+1)%4)
  process(i+1, x, y, (d-1)%4)

process(0, 0, 0, 0)
print('No')

Fixed submission:
import sys
sys.setrecursionlimit(8001)
s = input()
X, Y = map(int, input().split())
S = list(map(len, s.split('T')))
N = len(S)
# if N == 1:
#   print(['No', 'Yes'][X == S[0] and Y == 0])
#   exit()
# elif N == 2:
#   print(['No', 'Yes'][X == S[0] and abs(Y) == S[1]])
#   exit()

x = S[0]
y = 0
xmoves = S[2::2]
xmoves.sort()
xmoves.reverse()
ymoves = S[1::2]
ymoves.sort()
ymoves.reverse()

def process(a, l, i, v, d, memo, r):
  if (i,v) in memo:
    return False
  if l == i:
    return v == d
  ab = abs(d-v)
  if ab > r:
    ret = False
  elif a == r:
    ret = True
  else:
    ret = process(a, l, i+1, v+a[i], d, memo, r-a[i]) or process(a, l, i+1, v-a[i], d, memo, r-a[i])
  memo[(i,v)] = ret
  return ret

if process(xmoves, len(xmoves), 0, x, X, {}, sum(xmoves)) and process(ymoves, len(ymoves), 0, y, Y, {}, sum(ymoves)):
  print('Yes')
else:
  print('No')

Buggy python submission (verdict: Time Limit Exceeded):
import sys
s = input()
X, Y = map(int, input().split())

sys.setrecursionlimit(8001)

dirs = [(1, 0), (0, -1), (-1, 0), (0, 1)]
S = list(map(len, s.split('T')))
N = len(S)
memo = {}
def process(i, x, y, d):
  if (i,x,y,d) in memo:
    return
  if i >= N:
    if x == X and y == Y:
      print('Yes')
      exit()
    return
  x += dirs[d][0] * S[i]
  y += dirs[d][1] * S[i]
  process(i+1, x, y, (d+1)%4)
  process(i+1, x, y, (d-1)%4)
  memo[(i,x,y,d)] = 1

process(0, 0, 0, 0)
print('No')

Fixed submission:
import sys
sys.setrecursionlimit(8001)
s = input()
X, Y = map(int, input().split())
S = list(map(len, s.split('T')))
N = len(S)
# if N == 1:
#   print(['No', 'Yes'][X == S[0] and Y == 0])
#   exit()
# elif N == 2:
#   print(['No', 'Yes'][X == S[0] and abs(Y) == S[1]])
#   exit()

x = S[0]
y = 0
xmoves = S[2::2]
xmoves.sort()
xmoves.reverse()
ymoves = S[1::2]
ymoves.sort()
ymoves.reverse()

def process(a, l, i, v, d, memo, r):
  if (i,v) in memo:
    return False
  if l == i:
    return v == d
  ab = abs(d-v)
  if ab > r:
    ret = False
  elif a == r:
    ret = True
  else:
    ret = process(a, l, i+1, v+a[i], d, memo, r-a[i]) or process(a, l, i+1, v-a[i], d, memo, r-a[i])
  memo[(i,v)] = ret
  return ret

if process(xmoves, len(xmoves), 0, x, X, {}, sum(xmoves)) and process(ymoves, len(ymoves), 0, y, Y, {}, sum(ymoves)):
  print('Yes')
else:
  print('No')
Buggy python submission (verdict: Runtime Error):
N, M, K = map(int, raw_input().split(' '))
 
for n in xrange(N+1):
  for m in xrange(M+1):
    if n*M + m*N - 2*n*m == K:
      print 'Yes'
      exit()
 
print 'No'

Fixed submission:
N, M, K = map(int, raw_input().split(' '))

for n in xrange(N+1):
  for m in xrange(M+1):
    if n*M + m*N - 2*n*m == K:
      print 'Yes'
      exit()

print 'No'
Buggy python submission (verdict: Runtime Error):
X = int(raw_input())
K = int(raw_input())
rs = map(int, raw_input().split(" "))
Q = int(raw_input())
qs = []

for q in xrange(Q):
  qs.append(map(int, raw_input().split(" ")))

memo = {}

l = len(qs)
for i in xrange(l):
  t = 0
  start = qs[i][1]
  s = start
  end = qs[i][0]
  pre = 0
  k = 0
  if start in memo:
    j = 0
    lm = len(memo) - 1
    while True:
      if j == lm or end < rs[j+1]: break
      j += 1
    k = j+1
    pre = rs[j]
    s = memo[start][j]
  while k < K:
    r = rs[k]
    if r >= end: break
    if k % 2 == 0:
      s = max(0, s - (r - pre))
    else:
      s = min(X, s + (r - pre))
    if start not in memo: memo[start] = {}
    memo[start][k] = s
    k += 1
    pre = r

  if k % 2 == 0:
    s = max(0, s - (end - pre))
  else:
    s = min(X, s + (end - pre))
  print s

Fixed submission:
N = int(raw_input())
arr = map(int, raw_input().split(" "))

d = {}
for a in arr:
  d[a-1] = d.get(a-1, 0) + 1
  d[a] = d.get(a, 0) + 1
  d[a+1] = d.get(a+1, 0) + 1

answer = 0
for v in d.itervalues():
  if v > answer: answer = v

print answer
Buggy python submission (verdict: Runtime Error):
raw_input()
ls = map(int, raw_input())
ls.sort()
ls.reverse()
i = 0
answer = []
while i < len(ls) - 1:
  if ls[i] == ls[i+1]:
    answer.append(ls[i])
    if len(answer) >= 2:
      break
    i += 2

if len(answer) == 2:
  print answer[0] * answer[1]
else:
  print 0

Fixed submission:
raw_input()
ls = map(int, raw_input().split(" "))
ls.sort()
ls.reverse()
i = 0
answer = []
while i < len(ls) - 1:
  if ls[i] == ls[i+1]:
    answer.append(ls[i])
    if len(answer) >= 2:
      break
    i += 1
  i += 1

if len(answer) == 2:
  print answer[0] * answer[1]
else:
  print 0
Buggy python submission (verdict: Time Limit Exceeded):
from collections import Counter
S = input()
T = input()
q = int(input())
for i in range(q):
  a, b, c, d = map(int, input().split())
  c1 = Counter(list(S[a-1:b]))
  c2 = Counter(list(T[c-1:d]))
  if abs((c1['A'] - c1['B']) - (c2['A'] - c2['B'])) % 3 == 0:
    print('YES')
  else:
    print('NO')

Fixed submission:
ds = [0]
tmp = 0
for c in input():
  tmp += [-1, 1][c == 'A']
  ds.append(tmp)

dt = [0]
tmp = 0
for c in input():
  tmp += [-1, 1][c == 'A']
  dt.append(tmp)

q = int(input())
for i in range(q):
  a, b, c, d = map(int, input().split())
  if abs((ds[b] - ds[a-1]) - (dt[d] - dt[c-1])) % 3 == 0:
    print('YES')
  else:
    print('NO')
Buggy python submission (verdict: Runtime Error):
 s=input()
 print((s.count("g")-s.count("p"))//2)

Fixed submission:
s=input()
print((s.count("g")-s.count("p"))//2)
Buggy python submission (verdict: Runtime Error):
n =int(input())
if n<10:
    input("Yes")
    exit()

for i in range(9) :
    if n%(i+1)==0 and n/(i+1)<10:
        input("Yes\n")
        exit()

input("No")

Fixed submission:
n =int(input())
if n<10:
    print("Yes")
    exit()

for i in range(9) :
    if n%(i+1)==0 and n/(i+1)<10:
        print("Yes\n")
        exit()
print("No")

Buggy python submission (verdict: Runtime Error):
n =int(input())
if n<10:
    input("Yes")
    exit()

for i in range(9) :
    if n%(i+1)==0 and n/(i+1)<10:
        input("Yes\n")
        exit()

input("No")

Fixed submission:
n =int(input())
if n<10:
    print("Yes")
    exit()

for i in range(9) :
    if n%(i+1)==0 and n/(i+1)<10:
        print("Yes\n")
        exit()
print("No")
Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
s = input().split(' ')
ans=1
for i in s:
    ans=ans*int(i)
if(ans>1000000000000000000):
    print(-1)
else:
    print(ans)

Fixed submission:
n=int(input())
s = input().split(' ')
ans=1
for i in s:
    if int(i) == 0:
        print(0)
        exit()
for i in s:
    ans=ans*int(i)
    if(ans>1000000000000000000):
        print(-1)
        exit()
print(ans)
Buggy python submission (verdict: Runtime Error):
a, b = [ int(v) for v in input().split() ]
ans = -1
for i in range(1, 101):
    if math.floor(i * 0.08) == a and math.floor(i * 0.1) == b:
        ans = i
        break
print(ans)

Fixed submission:
import math
a, b = [ int(v) for v in input().split() ]
ans = -1
for i in range(1, 10001):
    if math.floor(i * 0.08) == a and math.floor(i * 0.1) == b:
        ans = i
        break
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
adjust_list = ((0,1),(0,-1),(1,0),(-1,0))
h, w = [int(v) for v in input().split()]
field = [list(input()) for i in range(h)]

def bfs(s, t):
    si, sj = s
    ti, tj = t
    if field[si][sj] == "." and field[ti][tj] == ".":

        search_field = [ [ -1 for i in range(w) ] for j in range(h) ]
        search_list = [s]
        turn = 0
        search_field[si][sj] = turn
        
        
        while search_list:
            turn += 1
            new_search_list = []
            for p in search_list:
                pi, pj = p
                
                for q in adjust_list:
                    qi, qj = q
                    if 0 <= pi+qi < h and 0 <= pj+qj < w:
                        if search_field[pi+qi][pj+qj] == -1 and field[pi+qi][pj+qj] == ".":
                            new_search_list.append((pi+qi,pj+qj))
                            search_field[pi+qi][pj+qj] = turn
            search_list = new_search_list

        return search_field[ti][tj]
    else:
        return -1
    

ans = 0
coodinate = [ (i, j) for i in range(h) for j in range(w) ]
k = h*w

for i in range(k-1):
    for j in range(i+1, k):
        ans = max(ans, bfs(coodinate[i], coodinate[j]))
print(ans)

Fixed submission:
adjust_list = ((0,1),(0,-1),(1,0),(-1,0))
h, w = [int(v) for v in input().split()]
field = [list(input()) for i in range(h)]

def bfs(s, t):
    si, sj = s
    ti, tj = t
    if field[si][sj] == "." and field[ti][tj] == ".":

        search_field = [ [ -1 for i in range(w) ] for j in range(h) ]
        search_list = [s]
        turn = 0
        search_field[si][sj] = turn
        
        
        while search_list:
            turn += 1
            new_search_list = []
            for p in search_list:
                pi, pj = p
                
                for q in adjust_list:
                    qi, qj = q
                    if 0 <= pi+qi < h and 0 <= pj+qj < w:
                        if search_field[pi+qi][pj+qj] == -1 and field[pi+qi][pj+qj] == ".":
                            new_search_list.append((pi+qi,pj+qj))
                            search_field[pi+qi][pj+qj] = turn
            search_list = new_search_list
            if search_field[ti][tj] != -1:
                break
        return search_field[ti][tj]
    else:
        return -1
    

ans = 0
coodinate = [ (i, j) for i in range(h) for j in range(w) ]
k = h*w

for i in range(k-1):
    for j in range(i+1, k):
        ans = max(ans, bfs(coodinate[i], coodinate[j]))
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
def comb(a,b,m):
    if b == 0 or b == a:
        ret = 1
    else:
        ret = 1
        for i in range(a-b+1,a+1):
            ret = (ret * i) % m
        for i in range(1,b+1):
            ret = (ret * pow(i,m-2,m) ) % m
    return ret

mod = 10**9+7
n, k = [ int(v) for v in input().split() ]
num = sorted([ int(v) for v in input().split() ])

max_list2 = [ (i, i-k+1) for i in range(n) ]
max_list2 = [ comb(a, b, mod) if b >= 0 else 0 for a, b in max_list2 ]
min_list_2 = list(reversed(max_list2))

max_min_list = [ (max_list2[i] - min_list_2[i]) * num[i] for i in range(n) ] 
print(sum(max_min_list) % mod)

Fixed submission:
mod = 10**9+7
n, k = [ int(v) for v in input().split() ]
num = sorted([ int(v) for v in input().split() ])


max_list2 = [ (i, i-k+1) for i in range(n) ]
max_list = []
for a, b in max_list2:
    if b < 0:
        max_list.append(0)
    elif b == 0:
        max_list.append(1)
    else:
        s = max_list[-1]
        s *= a * pow(b, mod-2, mod)
        max_list.append(s%mod)

min_list = list(reversed(max_list))

max_min_list = [ (max_list[i] - min_list[i]) * num[i] for i in range(n) ] 
print(sum(max_min_list) % mod)
Buggy python submission (verdict: Runtime Error):
import itertools
n = int(input())
a = tuple([ int(v)-1 for v in input().split() ])
b = tuple([ int(v)-1 for v in input().split() ])
t = 0
for i in itertools.permutations(range(n)):
    if a == i:
        xa = t
    elif b == i:
        xb = t
    t += 1
print(abs(xa-xb))

Fixed submission:
import itertools
n = int(input())
a = tuple([ int(v)-1 for v in input().split() ])
b = tuple([ int(v)-1 for v in input().split() ])
t = 0
for i in itertools.permutations(range(n)):
    if a == i:
        xa = t
    if b == i:
        xb = t
    t += 1
print(abs(xa-xb))
Buggy python submission (verdict: Runtime Error):

ans = ""
for i in range(n):
    ans += s[i]
    ans += t[i]

print(ans)


Fixed submission:
n = int(input())
s, t = [ v for v in input().split() ]


ans = ""
for i in range(n):
    ans += s[i]
    ans += t[i]

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
mod = 10**9+7
num = [ int(v) for v in input().split() ]
bits = [ 0 for i in range(100) ]
num_bin_len = []

for i in num:
    t = bin(i)[2:][::-1]
    num_bin_len.append(len(t))
    for j, v in enumerate(t):
        bits[j] += int(v)

binmax = max(num_bin_len)+1

pow_2_list = []
q = 1
for i in range(100):
    pow_2_list.append(q)
    q *= 2
    q %= mod


ans = 0
for i, v in enumerate(bits[:binmax]):
    ans += v * (n-v)  * pow_2_list[i] 
print(ans % mod)

Fixed submission:
n = int(input())
mod = 10**9+7
num = [ int(v) for v in input().split() ]
bits = [ 0 for i in range(100) ]

for i in num:
    j = 0
    while i > 0:
        if i % 2 == 1:
            bits[j] += 1
        i //= 2
        j += 1


binmax = 0
for i in range(100):
    if bits[i] > 0:
        binmax = i
binmax += 2


pow_2_list = []
q = 1
for i in range(100):
    pow_2_list.append(q)
    q *= 2
    q %= mod


ans = 0
for i, v in enumerate(bits[:binmax]):
    ans += v * (n-v)  * pow_2_list[i] 
print(ans % mod)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
mod = 10**9+7
num = [ int(v) for v in input().split() ]
bits = [ 0 for i in range(100) ]
num_bin_len = []
for i in num:
    t = bin(i)[2:][::-1]
    num_bin_len.append(len(t))
    for j, v in enumerate(t):
        bits[j] += int(v)

binmax = max(num_bin_len)+1
pow_2_list = [ pow(2,i,mod) for i in range(100) ]


ans = 0
for i, v in enumerate(bits[:binmax]):
    ans += v * (n-v)  * pow_2_list[i] 
print(ans % mod)


Fixed submission:
n = int(input())
mod = 10**9+7
num = [ int(v) for v in input().split() ]
bits = [ 0 for i in range(100) ]

for i in num:
    j = 0
    while i > 0:
        if i % 2 == 1:
            bits[j] += 1
        i //= 2
        j += 1


binmax = 0
for i in range(100):
    if bits[i] > 0:
        binmax = i
binmax += 2


pow_2_list = []
q = 1
for i in range(100):
    pow_2_list.append(q)
    q *= 2
    q %= mod


ans = 0
for i, v in enumerate(bits[:binmax]):
    ans += v * (n-v)  * pow_2_list[i] 
print(ans % mod)