Harryxun/sft_time huggingface dataset:
### BUGGY CODE ###

def dfs(c,p,d):
    if c == R:
        if ans[0] > d:
            ans[0] = d
    for i in range(R):
        if memo[i]:continue
        memo[i] = True
        if p == -1:
            dfs(c+1,i,0)
        else:dfs(c+1,i,d+graph[r[p]][r[i]])
        memo[i] = False

N,M,R = map(int,input().split())
r = [i-1 for i in map(int,input().split())]
graph = [[float("Inf") if i != j else 0 for i in range(N)] for j in range(N)]
for i in range(M):
    x,y,z = map(int,input().split())
    graph[x-1][y-1] = z
    graph[y-1][x-1] = z
for k in range(N):
    for i in range(N):
        for j in range(N):
            if graph[i][j] > graph[i][k] + graph[k][j]:
                graph[i][j] = graph[i][k] + graph[k][j]
memo = [False]*R
ans = [float("Inf")]
dfs(0,-1,0)
print(ans[0])

### FIXED CODE ###

def dfs(count,last,distance):
    if (count == r):
        if (ans[0] > distance ):ans[0] = distance
        return
    for i in range(r):
        if seen[i]:continue
        seen[i] = True
        if last == -1:dfs(count+1,i,0)
        else:dfs(count+1,i,distance+dp[R[last]-1][R[i]-1])
        seen[i] = False

n,m,r = map(int,input().split())
R = list(map(int,input().split()))
dp = [[ 0 if i == j else float("inf") for i in range(n)] for j in range(n)]
for i in range(m):
    x,y,z = map(int,input().split())
    dp[x-1][y-1] = z
    dp[y-1][x-1] = z
for k in range(n):
    for i in range(n):
        for j in range(n):
            if dp[i][j] > dp[i][k] + dp[k][j]:
                dp[i][j] = dp[i][k] + dp[k][j]
ans = [float("Inf")]
seen = [False]*r
dfs(0,-1,0)
print(*ans)
### BUGGY CODE ###

H, W = map(int, input().split())
T = [[] for i in range(H)]
d = []
for i in range(H):
    T[i] = list(input())
    for j in range(W):
        if T[i][j] == '#':
            d.append((i, j))

num = 0
for p, q in d:
    que = [(p, q, 0)]
    R = {}
    R[(p, q, 0)] = 1
    while que:
        x, y, k = que.pop(0)
        if k == 0:
            for dx, dy in [(0, 1), (1, 0), (-1, 0), (0, -1)]:
                nx, ny = x + dx, y + dy
                if (nx, ny) in R:
                    continue
                if 0 <= nx < H and 0 <= ny < W and T[nx][ny] == '.':
                    R[(nx, ny)] = 1
                    que.append((nx, ny, 1))
                    num += 1

        else:
            for dx, dy in [(0, 1), (1, 0), (-1, 0), (0, -1)]:
                nx, ny = x + dx, y + dy
                if (nx, ny) in R:
                    continue
                if 0 <= nx < H and 0 <= ny < W and T[nx][ny] == '#':
                    R[(nx, ny)] = 1
                    que.append((nx, ny, 0))
                    i = 0

print(num)


### FIXED CODE ###

H, W = map(int, input().split())
T = [[] for i in range(H)]
for i in range(H):
    a = list(input())
    T[i] = a

S = [[-1] * W for i in range(H)]

rec = 0
ans = [[0] * (H * W + 5) for i in range(2)]
for i in range(H):
    for j in range(W):
        if T[i][j] == "#" and S[i][j] == -1:
            rec += 1
            S[i][j] = rec
            ans[1][rec] += 1
            pre = "#"
            que = [(i, j, pre)]
            while que:
                x, y, pre = que.pop()
                for dx, dy in [(0, 1), (1, 0), (-1, 0), (0, -1)]:
                    nx, ny = x + dx, y + dy
                    if pre == "#":
                        if 0 <= nx < H and 0 <= ny < W and S[nx][ny] == -1 and T[nx][ny] == ".":
                            S[nx][ny] = rec
                            ans[0][rec] += 1
                            que.append((nx, ny, "."))
                    else:
                        if 0 <= nx < H and 0 <= ny < W and S[nx][ny] == -1 and T[nx][ny] == "#":
                            S[nx][ny] = rec
                            ans[1][rec] += 1
                            que.append((nx, ny, "#"))


num1 = 0
for i in range(H * W + 5):
    num1 += ans[0][i] * ans[1][i]

print(num1)
### BUGGY CODE ###

import collections
n=int(input())
i=2
l=[]
while True:
  if n==1:
    break
  if n%i==0:
    l.append(i)
    n=n//i
  else:
    i+=1
c=collections.Counter(l)
v=list(c.values())
ans=0
for vv in v:
  wa=1
  s=1
  while True:
    if vv<wa:
      break
    s+=1
    wa+=s
  ans+=(s-1)
print(ans)
  

### FIXED CODE ###

import collections
n=int(input())
if n==1:
  print(0)
  exit()
b=int(n**0.5)
i=2
l=[]
while i<=b:
  if n%i==0:
    l.append(i)
    n=n//i
  else:
    i+=1
if n>b:
  l.append(n)
c=collections.Counter(l)
v=list(c.values())

ans=0
for vv in v:
  wa=1
  s=1
  while True:
    if vv<wa:
      break
    s+=1
    wa+=s
  ans+=(s-1)
print(ans)
### BUGGY CODE ###

from numba import njit
s = input()

@njit
def test(c):
    # current point can be seen as xth smallest val, where x can be any value in [a, b] (subset of [0, c])
    # a <= b
    a, b = 0, c
    ok = True
    discrete = False # when True x = a, a+2, ..., b-2, b
    for si in s:
        if si == '1':
            if a == b == c:
                return False
            a += 1
            b += 1
            if b > c:
                b = c - 1 if discrete else c
        elif si == '0':
            if a == b == 0:
                return False
            a -= 1
            b -= 1
            if a < 0:
                a = 1 if discrete else 0
        else:
            if a == b == 0:
                a = b = 1
            elif a == b == c:
                a = b = c - 1
            elif a == b:
                discrete = True
                a -= 1
                b += 1
            else:
                a -= 1
                b += 1
                if a < 0:
                    a = 1 if discrete else 0
                if b > c:
                    b = c - 1 if discrete else c
    return True


l, r = 0, len(s)
while r - l > 1:
    c = (l + r) // 2
    if test(c):
        r = c
    else:
        l = c
print(r)


### FIXED CODE ###

from numba import njit
import numpy as np
s = np.array(list(map(lambda x: -1 if x == '?' else int(x), input())))
@njit
def test(c):
    # current point can be seen as xth smallest val, where x can be any value in [a, b] (subset of [0, c])
    # a <= b
    a, b = 0, c
    ok = True
    discrete = False # when True x = a, a+2, ..., b-2, b
    for si in s:
        if si == 1:
            if a == b == c:
                return False
            a += 1
            b += 1
            if b > c:
                b = c - 1 if discrete else c
        elif si == 0:
            if a == b == 0:
                return False
            a -= 1
            b -= 1
            if a < 0:
                a = 1 if discrete else 0
        else:
            if a == b == 0:
                a = b = 1
            elif a == b == c:
                a = b = c - 1
            elif a == b:
                discrete = True
                a -= 1
                b += 1
            else:
                a -= 1
                b += 1
                if a < 0:
                    a = 1 if discrete else 0
                if b > c:
                    b = c - 1 if discrete else c
    return True

l, r = 0, s.size
while r - l > 1:
    c = (l + r) // 2
    if test(c):
        r = c
    else:
        l = c
print(r)
### BUGGY CODE ###

N = int(input())
A = list(map(int, input().split()))
B = []
for i in range(1, N+1):
    B.append(A.index(i)+1)
#print(B)
print(*B)

### FIXED CODE ###

#import numpy as np
N = int(input())
A = list(map(int, input().split()))
#A = np.array(A)
B = [0]*N
#indices = [*range(len(A))]
#sorted_indices = sorted(indices, key=lambda i: A[i])
#for i in range(1, N+1):
#    B.append(A.index(i)+1)
#print(B)
#sorted_indices = sorted_indices + B
for i in range(N):
    B[A[i]-1] = i + 1
print(*B)
#print(*sorted_indices)
### BUGGY CODE ###

N, K = map(int, input().split())
H_list = list(map(int, input().split()))

count = 0

if N<K:
    print(0)
else:
    for i in range(0,K):

        # 最大値を見つける
        H_max = max(H_list)
        # 最大値を１つリストから削除
        H_list.remove(H_max)

    # リスト内の残りの数を合計
    count = sum(H_list)
    print(count)


### FIXED CODE ###

N, K = map(int, input().split())
H_list = list(map(int, input().split()))

count = 0

if N<K:
    print(0)
else:
    # リストをソートする
    H_list = sorted(H_list, reverse=True)
    # 上位K位をスライスで削除
    H_list = H_list[K:]


    # リスト内の残りの数を合計
    count = sum(H_list)
    print(count)
### BUGGY CODE ###

M=1000003
f=[1]
for i in range(1,M):f.append(f[i-1]*i%M)
for _ in'_'*int(input()):
	x,d,n=map(int,input().split())
	t=x*pow(d,M-2,M)%M
	print([pow(x,n,M),M-n>=t>0and f[t+n-1]*pow(f[t-1],M-2,M)*pow(d,n,M)%M or 0][d>0])

### FIXED CODE ###

M=1000003
f=[1]
for i in range(1,M):
	f.append(f[i-1]*i%M)
Q=int(input())
for _ in'_'*Q:
	x,d,n=map(int,input().split())
	if d==0:
		print(pow(x,n,M))
	else:
		t=x*pow(d,M-2,M)%M
		if t==0 or t+n-1>=M:
			print(0)
		else:
			print(f[t+n-1]*pow(f[t-1],M-2,M)*pow(d,n,M)%M)
### BUGGY CODE ###

n,k=map(int,input().split())
a=list(map(int,input().split()))
syaku=1
for i in range(k):
  syaku*=a[i]
now=syaku
for i in range(k,len(a)):
  pre=now
  now=now*a[i]//a[i-k]
  if pre<now:
    print("Yes")
  else:
    print("No")
  

### FIXED CODE ###

n,k=map(int,input().split())
a=list(map(int,input().split()))
#for i in range(k):
#  syaku*=a[i]
#now=syaku
for i in range(k,len(a)):
  #pre=now
  #now=now*a[i]//a[i-k]
  if a[i]>a[i-k]:
    print("Yes")
  else:
    print("No")
### BUGGY CODE ###

from sys import stdin, stdout
n, w = list(map(int,stdin.readline().split()))
values = []
weights = []
for _ in range(n):
	v,a = list(map(int, stdin.readline().split()))
	values.append(a)
	weights.append(v)
values = [0] + values
weights = [0] + weights

dp = [[0 for _ in range(w+1)] for k in range(n+1)]

for i in range(n+1):
	for j in range(w+1):
		if i == 0 or j == 0:
			dp[i][j] = 0
		else:
			if weights[i] <= j:
				dp[i][j] = max(dp[i-1][j],
			   	dp[i-1][j-weights[i]] + values[i])
			else:
				dp[i][j] = dp[i-1][j]

print(str(dp[n][w]))


### FIXED CODE ###

from sys import stdin, stdout
import numba as nb 

@nb.njit()
def solve(n,w,weights, values):
	dp = [[0 for _ in range(w+1)] for k in range(n+1)]
	for i in range(1,n+1):
		for j in range(1,w+1):
			if weights[i] <= j:
				dp[i][j] = max(dp[i-1][j],
			   	dp[i-1][j-weights[i]] + values[i])
			else:
				dp[i][j] = dp[i-1][j]
	return dp[n][w]

def main():
	n, w = map(int,stdin.readline().split())
	values = []
	weights = []

	for _ in range(n):
		v,a = map(int, stdin.readline().split())
		values.append(a)
		weights.append(v)

	values = [0] + values
	weights = [0] + weights
	print(solve(n,w,weights,values))

if __name__ == "__main__":
	main()
### BUGGY CODE ###

import sys
from collections import deque
h,w = map(int,input().split())
sx,sy = map(int,input().split())
sx -= 1
sy -= 1
gx,gy = map(int,input().split())
gx -= 1
gy -= 1
route = []
for i in range(h):
  lst = list(input())
  route.append(lst)
  
brock = [['#']*w for i in range(h)]
s = 0
que = deque([])
dx = [-1,0,1,0]
dy = [0,-1,0,1]

brock[sx][sy] = 0
que.append((sx,sy))
lst = [(sx,sy)]


while que:
  
  (p,q) = que.popleft()
  if (p,q) == (gx,gy):
    print(brock[gx][gy])
    sys.exit()
  for i in range(4):
    p2,q2 = p+dx[i],q+dy[i]
    if 0 <= p2 < h and 0<= q2 < w and route[p2][q2] == '.' and brock[p2][q2] == '#':
      brock[p2][q2] = brock[p][q]
      que.append((p2,q2))
      lst.append((p2,q2))
  
  if len(que) == 0:
    
    s += 1
    for u in range(h):
      for v in range(w):
        if brock[u][v] == s-1:
          x,y = u,v
          for j in range(-2,3):
             for k in range(-2,3):
                x2 = x+j
                y2 = y+k
                if 0 <= x2 < h and 0<= y2 < w and route[x2][y2] == '.' and brock[x2][y2] == '#':
                  brock[x2][y2] = s
                  que.append((x2,y2))
            
                  
              
print(-1)              
            



### FIXED CODE ###

import sys
from collections import deque
h,w = map(int,input().split())
sx,sy = map(int,input().split())
sx -= 1
sy -= 1
gx,gy = map(int,input().split())
gx -= 1
gy -= 1
route = []
for i in range(h):
  lst = list(input())
  route.append(lst)
  
brock = [['#']*w for i in range(h)]

que = deque([])
dx = [-1,0,1,0]
dy = [0,-1,0,1]

brock[sx][sy] = 0
que.append((sx,sy))



while que:
  
  (p,q) = que.popleft()
  if (p,q) == (gx,gy):
    print(brock[gx][gy])
    sys.exit()
  for i in range(4):
    p2,q2 = p+dx[i],q+dy[i]
    if 0 <= p2 < h and 0<= q2 < w and route[p2][q2] == '.' and (brock[p2][q2] == '#' or brock[p2][q2] > brock[p][q]):
      brock[p2][q2] = brock[p][q]
      que.appendleft((p2,q2))
  
  for j in range(-2,3):
    for k in range(-2,3):
      p3 = p+j
      q3 = q+k
      if 0 <= p3 < h and 0<= q3 < w and route[p3][q3] == '.' and brock[p3][q3] == '#':
        brock[p3][q3] = brock[p][q]+1
        que.append((p3,q3))
        
        
            
                  
              
print(-1)
### BUGGY CODE ###

from collections import defaultdict,deque
import numpy as np
import copy
import bisect

N = int(input())
A = list(map(int,input().split()))
graph = defaultdict(deque)
for _ in range(0,N-1):
    u,v = map(int,input().split())
    graph[u].append(v)
    graph[v].append(u)

arrive = [False] * (N+1)
dp_dict = np.array([None] * N)
dp_dict[0] = [A[0]]

ans = [None] *(N+1)
def dfs(s):
    stack = deque([s])
    while stack:
        v = stack[-1]
        arrive[v] = True
        if graph[v]:
            w = graph[v].pop()
            if arrive[w] == False:
                tar = A[w-1]
                dp = copy.copy(dp_dict[v-1])
                if tar > dp[-1]:
                    dp.append(tar)
                else:
                    dp[bisect.bisect_left(dp, tar)] = tar
                ans[w] = len(dp)
                dp_dict[w-1] = dp
                stack.append(w)

        else:
            stack.pop()


dfs(1)
ans[1] = 1
for i in ans[1::]:
    print(i)

### FIXED CODE ###

import bisect
import sys
input = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 7)
 
N = int(input())
A = tuple(map(int, input().split()))
graph = [[] for _ in range(N + 1)]
for _ in range(N - 1):
    x, y = map(int, input().split())
    graph[x].append(y)
    graph[y].append(x)
 
ans = [-1] * (N + 1)
inf = 10**18
LIS = [inf] * (N + 1)
 
def DFS(s, parent=0):
    a = A[s - 1]
    i = bisect.bisect_left(LIS, a)
    v = LIS[i]
    LIS[i] = a
    ans[s] = bisect.bisect_left(LIS, inf)
    for t in graph[s]:
        if t == parent:
            continue
        DFS(t, s)
    LIS[i] = v
    return
 
DFS(1)
print(*ans[1:], sep="\n")
### BUGGY CODE ###

def main():
  n, m = map(int, input().split())
  d1 = {}
  for _ in range(n):
    a, b = map(int, input().split())
    if a not in d1:
      d1[a] = []
    d1[a].append(b)
  result = 0
  d2 = {}
  for i in range(1, m + 1):
    if i in d1:
      for j in d1[i]:
        if j not in d2:
          d2[j] = 0
        d2[j] += 1
    else:
      if len(d2) == 0:
        continue
    maxb = max(d2.keys())
    result += maxb
    if d2[maxb] == 1:
      del d2[maxb]
  print(result)
main()

### FIXED CODE ###

n, m = map(int, input().split())
d1 = {}
for _ in range(n):
  a, b = map(int, input().split())
  if a in d1:
    d1[a].append(b)
  else:
    d1[a] = [b]
result = 0
d2 = {}
maxb = -1
for i in range(1, m + 1):
  if i in d1:
    for j in d1[i]:
      if j not in d2:
        d2[j] = 0
      d2[j] += 1
      if j > maxb:
        maxb = j
  else:
    if len(d2) == 0:
      continue
  result += maxb
  if d2[maxb] == 1:
    del d2[maxb]
    if len(d2) == 0:
      maxb = 0
    else:
      maxb = max(d2.keys())
  else:
    d2[maxb] -= 1
print(result)
### BUGGY CODE ###

N = int(input())
a = input().split()

a_list = [int(i) for i in a]

for i in range(N):
    print(a_list.index(i+1) + 1,end=' ')

### FIXED CODE ###

N = int(input())
a = input().split()
 
#a_list = [int(i) for i in a]
#a_list_index = [a_list.index(i+1) + 1 for i in range(N)]
#print(' '.join(map(str, a_list_index)))

new_list =[0] * N
for i , b in enumerate(a):
  new_list[int(b)-1] = i + 1
print(' '.join(map(str, new_list)))
### BUGGY CODE ###

N, K = map(int, input().split())
h = list(map(int, input().split()))
f_INF = float('inf')
dp = [f_INF]*2*N
dp[0] = 0
for i in range(N):
    for j in range(1,min(K+1, N-i)):
        dp[i+j] = min(dp[i+j],dp[i] + abs(h[i]-h[i+j]))
print(dp[N-1])

### FIXED CODE ###

import sys
sys.setrecursionlimit(10**9) #上限を１００万回に設定

N, K = map(int, input().split())
h = list(map(int, input().split()))
f_INF = float('inf')
dp = [f_INF]*N
dp[0] = 0
for i in range(N):
    for j in range(1,min(K+1, N-i)):
        dp[i+j] = min(dp[i+j],dp[i] + abs(h[i]-h[i+j]))
print(dp[N-1])
### BUGGY CODE ###

#!/usr/bin/env python3
import sys
import numpy as np

def solve(N: int, K: int, x: "List[int]"):
    x = np.array(x)
    score = 10**9
    for right in range(min(K + 1, len(x[x >= 0])+1)):
        left = min(K - right, max(0, len(x[x < 0])))
        if right + left == K:
            rpath = 0
            lpath = 0
            if len(x[x >= 0]) > 0:
                rpath = x[x >= 0][right - 1]
            if len(x[x < 0]) > 0:
                lpath = abs(sorted(x[x < 0], reverse=True)[left - 1])
            score = min(score, rpath + lpath + min(rpath, lpath))

    print(score)


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    N, K = map(int, input().split())
    x = list(map(int, input().split()))
    solve(N, K, x)

if __name__ == '__main__':
    main()


### FIXED CODE ###

#!/usr/bin/env python3
import sys
import numpy as np

def solve(N: int, K: int, x: "List[int]"):
    x = np.array(x)
    score = 10**9
    x_s = sorted(x[x < 0], reverse=True)
    x_plus = x[x >= 0]
    x_len_plus = len(x_plus)
    x_len_minus = len(x_s)
    for right in range(min(K + 1, x_len_plus + 1)):
        left = min(K - right, x_len_minus)
        if right + left == K:
            if x_len_plus > 0:
                rpath = x_plus[right - 1]
            else:
                rpath = 0
            if x_len_minus > 0:
                lpath = abs(x_s[left - 1])
            else:
                lpath = 0
            score = min(score, rpath + lpath + min(rpath, lpath))

    print(score)


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    N, K = map(int, input().split())
    x = list(map(int, input().split()))
    solve(N, K, x)

if __name__ == '__main__':
    main()
### BUGGY CODE ###

import bisect

N = int(input())
A = list(map(int,input().split()))

Q = int(input())

A.sort()
B = list(set(A))
X = [[0 for j in range(2)] for i in range(len(B))]
for i in range(len(B)):
  b=bisect.bisect_left(A,B[i])
  c=bisect.bisect_right(A,B[i])
  num = c - b #B[i]の要素数
  X[i][0] = B[i]
  X[i][1] = num

M = [0 for j in range(Q)]
N = [0 for j in range(Q)]
for i in range(Q):
  M[i],N[i] = map(int,input().split())

ans = int()
for i in range(Q):
  x = M[i]
  y = N[i]
  ans = 0
  for j in range(len(B)):
    if X[j][0] == x:
      X[j][0] = y
    ans += X[j][0] * X[j][1]
  print(ans)
  #print(X)
  



### FIXED CODE ###

N = int(input())
A = list(map(int,input().split()))
Q = int(input())
BC = [list(map(int,input().split())) for i in range(Q)]
B, C = [list(i) for i in zip(*BC)]
#print(B,C,BC)

dic = {}
for a in A:
  dic[a] = dic.get(a,0) + 1
#print(dic)

ans = sum(A)
for q in range(Q):
  ans = ans + (C[q]-B[q]) * dic.get(B[q],0)
  dic[C[q]] = dic.get(B[q],0) + dic.get(C[q],0)
  dic[B[q]] = 0
  print(ans)
### BUGGY CODE ###

import sys
read = sys.stdin.buffer.read
input = sys.stdin.buffer.readline

h, n = map(int, input().split())
a = map(int, read().split())
ab = zip(a, a)

dp = [10 ** 20] * 10 ** 4 * 2
dp[0] = 0
for a, b in ab:
    for i in range(h):
        if dp[i + a] > dp[i] + b:
            dp[i + a] = dp[i] + b
print(min(dp[h:]))

### FIXED CODE ###

h, n = map(int, input().split())
ab = tuple(tuple(map(int, input().split())) for _ in range(n))

dp = [10 ** 20] * 10 ** 4 * 2
dp[0] = 0
for a, b in ab:
    for i in range(h):
        dp[i + a] = min(dp[i + a], dp[i] + b)
print(min(dp[h:]))
### BUGGY CODE ###

n=int(input())
s=[input()for _ in range(n)]
def check(s):
  for i in range(n):
    for j in range(n):
      if s[i][j]!=s[j][i]:return False
  return True
ans=0
for i in range(n):
  if check(s):ans+=n
  s=s[1:]+s[:1]
print(ans)

### FIXED CODE ###

n=int(input())
s=[input()for _ in range(n)]
def check(s,t):
  for i in range(n):
    for j in range(n):
      if s[(i+t)%n][j]!=s[(j+t)%n][i]:return False
  return True
ans=0
for i in range(n):
  if check(s,i):ans+=n
print(ans)
### BUGGY CODE ###

n=int(input())
c=1
for i in range(1,n):
    for j in range(2,n):
        if i**j<=n:
            c=max(c,i**j)
        else:
            break
print(c)

### FIXED CODE ###

print(int(int(input())**.5)**2)
### BUGGY CODE ###

s = input()
i = 0
while "01" in s or "10" in s:
    if "01" in s:
        s = s.replace("01","",1)
        i+=2
    if "10" in s:
        s = s.replace("10","",1)
        i+=2
print (i)


### FIXED CODE ###

s = input()
print(min(s.count("0"),s.count("1"))*2)
### BUGGY CODE ###

from functools import reduce
n = int(input())
num = reduce(lambda x,y: x*y, list(map(int, input().split())))
count = 0

while num%2 == 0:
    num = num//2
    count += 1
    
print(count)

### FIXED CODE ###

n = int(input())
nums = list(map(int, input().split()))
iters = 0
count = 0

while len(nums) != 0:
    size = len(nums)
    nums = list(map(lambda x: x//2, list(filter(lambda x:x%2 == 0, nums))))
    count += (size - len(nums))*iters
    iters += 1
    
print(count)
### BUGGY CODE ###

from bisect import bisect,insort
import itertools
q=int(input())
query=[list(map(int,input().split())) for i in range(q)]
inf=float("inf")
a_sum=0
b_sum=0
A=[]
count=0
for u in query:
    if u[0]==2:
        if count%2==1:
            print(A[num],a_sum+b_sum-A[num])
        else:
            print(A[num-1],a_sum+b_sum)
    else:
        count+=1
        a,b=u[1],u[2]
        b_sum+=b
        c=bisect(A,a)
        num=count//2
        if c>=num:
            if count%2==0:
                a_sum+=-2*A[num-1]+a
            else:
                a_sum+=a
            insort(A,a)
        else:
            if count%2==0:
                a_sum+=-a
            else:
                a_sum+=-a+2*A[num-1]
            insort(A,a)

### FIXED CODE ###

from heapq import heappop,heappush
q=int(input())
query=[list(map(int,input().split())) for _ in range(q)]
inf=10**12
left=[inf]
left_sum=0
right=[inf]
right_sum=0

cnt=0
b=0
for i in range(q):
    if query[i][0]==1:
        a=query[i][1]
        b+=query[i][2]
        if cnt==0:
            d=right[0]
            if a>d:
                heappush(left,-heappop(right))
                heappush(right,a)
                right_sum+=a-d
                left_sum-=d
            else:
                heappush(left,-a)
                left_sum-=a
            cnt=1
        else:
            c=-left[0]
            if a<c:
                heappush(right,-heappop(left))
                heappush(left,-a)
                right_sum+=c
                left_sum+=c-a
            else:
                heappush(right,a)
                right_sum+=a
            cnt=0
    else:
        x=-left[0]
        if cnt==0:
            print(x,b+right_sum+left_sum)
        else:
            print(x,b+x+right_sum+left_sum)
### BUGGY CODE ###

a, b, c, d = map(int, input().split())
num = []
for i in range(a, b + 1):
  for j in range(c, d + 1):
    num.append(i * j)
print(max(num))

### FIXED CODE ###

a, b, c, d = map(int, input().split())
num = [a*c, a*d, b*c, b*d]
print(max(num))