Harryxun/stf_run huggingface dataset:
import sys
mod=10**9+7 ; inf=float("inf")
from math import sqrt, ceil
from collections import deque, Counter, defaultdict #すべてのkeyが用意されてる defaultdict(int)で初期化
input=lambda: sys.stdin.readline().strip()
sys.setrecursionlimit(11451419)
from decimal import ROUND_HALF_UP,Decimal  #変換後の末尾桁を0や0.01で指定
  #Decimal((str(0.5)).quantize(Decimal('0'), rounding=ROUND_HALF_UP))
from functools import lru_cache
from bisect import bisect_left as bileft, bisect_right as biright
#メモ化再帰defの冒頭に毎回 @lru_cache(maxsize=10**10)
#引数にlistはだめ
#######ここまでテンプレ#######
#ソート、"a"+"b"、再帰ならPython3の方がいい
#######ここから天ぷら########

n=int(input())

A=list(map(int,input().split()))
from math import sqrt
def eratosu(n):
  if not isinstance(n,int):
    raise TypeError("nがint型になってねえぞ")
  if n<2:
    raise ValueError('nが2よりちっちぇえぞ')
  prime = []
  limit = sqrt(n)
  data = [i+1 for i in range(1, n)]  #2,3,4,...,n
  while True:
    p = data[0]
    if limit <= p:
        return prime + data
    prime.append(p)
    data = [e  for e in data if e % p != 0]
PRIME=eratosu(10**3+10)
@lru_cache(maxsize=10**10)
def bunkai(n):
    if n==1:return []
    ans=[]
    temp=n
    #そんな早くしなくてよかったり、何回もするわけじゃないなら、
    #for i in range(2,int(sqrt(n))+1): とかで
    primelist= PRIME
    for i in primelist:
        if i>sqrt(n):break
        if temp % i ==0:
            ji=0
            while temp%i==0:
                ji+=1
                temp//=i
            ans.append([i,ji])
    if ans==[]:return([[n,1]])  #素数のとき
    if temp!=1:
        ans.append([temp,1])  #4*5882353とか
    return ans

flag=1
seen={i:0 for i in PRIME}
#print(bunkai(3))
for i in A:
    for l in bunkai(i):
        now=l[0] 
        if seen[now]!=0:
            flag=0
        seen[now]+=1



        
if flag:
    print("pairwise coprime")
elif max(seen)!=n:
    print("setwise coprime")
else:
    print("not coprime")



### FIXED CODE ###

n=int(input())
A=list(map(int,input().split()))
def Dlist(BIG):
    D=[1]*(BIG+1)
    for p in range(2,BIG+1):
        if D[p]!=1:
            continue
        for i in range(p,BIG+1,p):
            if D[i]==1:
                D[i]=p
    return D

D=Dlist(max(A))
def SOINSU(num,D): #素因数だけ列挙(setしただけ)
    now=num ; ans=set()
    while now>1:
        ans.add(D[now])
        now//=D[now]
    return ans

seen=[0]*(10**6+10)
flag=1
for num in A:
    for i in SOINSU(num,D):
        if seen[i]!=0: flag=0
        seen[i]+=1
if flag:
    print("pairwise coprime")
elif max(seen)!=n:
    print("setwise coprime")
else:
    print("not coprime")
n = int(input())
heights = map(int, input())

current_highest = heights[0]
steps_sum = 0
for h in heights[1:]:
  if h > current_highest:
    current_highest = h
  else:
    steps_sum += h - current_highest

print(steps_sum)

### FIXED CODE ###

n = int(input())
heights = list(map(int, input().split(' ')))

current_highest = heights[0]
steps_sum = 0
for h in heights[1:]:
  if h > current_highest:
    current_highest = h
  else:
    steps_sum += current_highest - h
 
print(steps_sum)
n = int(input())
a_lst = list(map(int,input().split()))

ans = 1
for a in a_lst:
    ans = ans * a
if ans > 10**18:
    print("-1")
else:
    print(ans

### FIXED CODE ###

n = int(input())
a_lst = list(map(int,input().split()))

ans = 1
if 0 in a_lst:
    print(0)
else:
    for a in a_lst:
        ans *= a
        if ans > 10**18:
            ans = -1
            break
    print(ans)
import sys

sys.setrecursionlimit(10 ** 6)
INF = float("inf")
MOD = 10 ** 9 + 7


def input():
    return sys.stdin.readline().strip()


def main():
    H, W = map(int, input().split())
    A = []
    cnt = 0
    for _ in range(H):
        a = list(map(int, input().split()))
        cnt += sum(a)
        A.append(a)

    ans = []
    for h in range(H):
        if h % 2 == 0:
            for w in range(W):
                if h == H - 1 and w == W - 1:
                    continue
                if A[h][w] % 2 == 1:
                    if w == W:
                        A[h][w] -= 1
                        A[h + 1][w] += 1
                        ans.append((h, w, h + 1, w))
                    else:
                        A[h][w] -= 1
                        A[h][w + 1] += 1
                        ans.append((h, w, h, w + 1))
                else:
                    continue
        else:
            for w in range(W)[::-1]:
                if h == H - 1 and w == W - 1:
                    continue
                if A[h][w] % 2 == 1:
                    if w == 0:
                        A[h][w] -= 1
                        A[h + 1][w] += 1
                        ans.append((h, w, h + 1, w))
                    else:
                        A[h][w] -= 1
                        A[h][w + 1] += 1
                        ans.append((h, w, h, w + 1))
                else:
                    continue

    print(len(ans))
    for a, b, c, d in ans:
        print(a, b, c, d)


if __name__ == "__main__":
    main()


### FIXED CODE ###

import sys

sys.setrecursionlimit(10 ** 6)
INF = float("inf")
MOD = 10 ** 9 + 7


def input():
    return sys.stdin.readline().strip()


def main():
    H, W = map(int, input().split())
    A = []
    cnt = 0
    for _ in range(H):
        a = list(map(int, input().split()))
        cnt += sum(a)
        A.append(a)

    ans = []
    for h in range(H):
        if h % 2 == 0:
            for w in range(W):
                if h == H - 1 and w == W - 1:
                    continue
                if A[h][w] % 2 == 1:
                    if w == W - 1:
                        A[h][w] -= 1
                        A[h + 1][w] += 1
                        ans.append((h, w, h + 1, w))
                    else:
                        A[h][w] -= 1
                        A[h][w + 1] += 1
                        ans.append((h, w, h, w + 1))
                else:
                    continue
        else:
            for w in range(W)[::-1]:
                if h == H - 1 and w == 0:
                    continue
                if A[h][w] % 2 == 1:
                    if w == 0:
                        A[h][w] -= 1
                        A[h + 1][w] += 1
                        ans.append((h, w, h + 1, w))
                    else:
                        A[h][w] -= 1
                        A[h][w - 1] += 1
                        ans.append((h, w, h, w - 1))
                else:
                    continue

    print(len(ans))
    for a, b, c, d in ans:
        print(a + 1, b + 1, c + 1, d + 1)


if __name__ == "__main__":
    main()
n, x, y = map(int, input().split())
li = [0] * (n-1)
for i in range(1, n+1):
  for j in range(i+1, n+1):
    num = min(j-i, abs(x-i)+abs(y-j)+1)
    li[num-1] += 1
for i in range(n-1):
  print(li[i])

### FIXED CODE ###

s=input()
if (s[2]==s[3] and s[4]==s[5]):
  print('Yes')
else:
  print('No')
n=int(input())
ans=''
while n!1:
  r=n%(-2)
  ans+=r
  n=n//(-2)
ans+=n
ans.reverse()
print(ans)
      

### FIXED CODE ###

n=int(input())
if n==0:
  print(0)
  exit()
if n==1:
  print(1)
  exit()
ans=[]
while n!=1:
  r=n%2
  ans.append(str(r))
  n=(n-r)//(-2)
ans.append(str(1))
ans.reverse()
print(''.join(ans))
n=int(input())

#初期値が0の辞書
from collections import defaultdict
tree = defaultdict(lambda: set([])) 

color={}
key=[]

for _ in range(n-1):
    a,b=map(int,input().split())
    tree[a-1].add(b-1)
    tree[b-1].add(a-1)
    color[(a-1,b-1)]=0
    key.append((a-1,b-1))

checked=[0]*n
cnt=0

def DEF(parent_color,node_no):
    global color,checked,tree,cnt
    checked[node_no]=1
    cnt=max(cnt,parent_color)
    i=1
    print("node_no",node_no)
    for item in tree[node_no]:
        if checked[item]==0:
            if i==parent_color:
                i+=1
            
            color[(min(item,node_no),max(item,node_no))]=i
            DEF(i,item)
            i+=1
DEF(0,1)

print(cnt)
for item in key:
    print(color[item])

        








### FIXED CODE ###

import sys
sys.setrecursionlimit(2147483647)
INF=float('inf')
MOD=10**9+7
input=sys.stdin.readline

n=int(input())

#初期値が0の辞書
from collections import defaultdict
tree = defaultdict(lambda: set([])) 

color={}
key=[]

for _ in range(n-1):
    a,b=map(int,input().split())
    tree[a-1].add(b-1)
    tree[b-1].add(a-1)
    color[(a-1,b-1)]=0
    key.append((a-1,b-1))

checked=[0]*n
cnt=0

def DEF(parent_color,node_no):
    global color,checked,tree,cnt
    checked[node_no]=1
    cnt=max(cnt,parent_color)
    i=1
    #print("node_no",node_no)
    for item in tree[node_no]:
        if checked[item]==0:
            if i==parent_color:
                i+=1
            
            color[(min(item,node_no),max(item,node_no))]=i
            DEF(i,item)
            i+=1
DEF(0,1)

print(cnt)
for item in key:
    print(color[item])
print(int(3*(int(input()**2)))


### FIXED CODE ###

a=int(input())
print(3*(a*a))
h, w = map(int,input().split())
grid = []
grid.append('#' * (w+2))
for _ in range(h):
    grid.append('#' + input().rstrip() + '#')
grid.append('#' * (w+2))
            
from collections import deque
import sys
sys.setrecursionlimit(1000000)


def flatten_2dim(array):
    return [item for sublist in array for item in sublist]
def all_argmax_2dim(array):
    flat_array = flatten_2dim(array)

    row_num = len(array)
    max_value = max(flat_array)

    for i, elem in enumerate(flat_array):
        if elem == max_value:
            yield i // row_num, i % row_num

maxstep = 0
flag = 0
step = [[-1] * (w+2) for _ in range(h+2)]
def bfs():
    global maxstep

    dy = [1, 0, -1, 0]
    dx = [0, 1, 0, -1]
    
    que = deque([])
    que.append((s_y, s_x))
    step[s_y][s_x] = 0
    
    while que:
        y, x = que.popleft()

        for i in range(4):
            ny = y + dy[i]
            nx = x + dx[i]
            if step[ny][nx] == -1 and grid[ny][nx] != "#":
                que.append((ny, nx))
                step[ny][nx] = step[y][x] + 1
    if flag == 0:
        maxstep = max(flatten_2dim(step))
    else:
        maxstep = max(max(flatten_2dim(step)), maxstep)
    
for i in range(h+2):
    for j in range(w+2):
        if grid[i][j] == ".":
            s_y, s_x = i, j
            break
bfs()
flag = 1
li = []
for argmax in all_argmax_2dim(step):
    li.append(argmax)

for s_y, s_x in li:
    bfs()
print(maxstep)

### FIXED CODE ###

h, w = map(int,input().split())
grid = []
grid.append('#' * (w+2))
for _ in range(h):
    grid.append('#' + input().rstrip() + '#')
grid.append('#' * (w+2))
            
from collections import deque
import sys
sys.setrecursionlimit(1000000)


def flatten_2dim(array):
    return [item for sublist in array for item in sublist]

maxstep = 0
step = [[-1] * (w+2) for _ in range(h+2)]
def bfs():
    global maxstep
    dy = [1, 0, -1, 0]
    dx = [0, 1, 0, -1]
    
    que = deque([])
    que.append((s_y, s_x))
    step[s_y][s_x] = 0
    
    while que:
        y, x = que.popleft()

        for i in range(4):
            ny = y + dy[i]
            nx = x + dx[i]
            if step[ny][nx] == -1 and grid[ny][nx] != "#":
                que.append((ny, nx))
                step[ny][nx] = step[y][x] + 1

    maxstep = max(max(flatten_2dim(step)), maxstep)
    
for i in range(h+2):
    for j in range(w+2):
        if grid[i][j] == ".":
            s_y, s_x = i, j
            bfs()
            step = [[-1] * (w+2) for _ in range(h+2)]
print(maxstep)
N, T = map(int, input().split())
L = [int(i) for i in input().split()]
gap=[]
time=T

for i in range(N-1)
	gap.append(L[i+1]-L[i])

for i in range(N-1):
	time += min(B[i],T)

print(time)

### FIXED CODE ###

N, T = map(int, input().split())
L = [int(i) for i in input().split()]
gap=[]
time=T

for i in range(N-1):
	gap.append(L[i+1]-L[i])

for i in range(N-1):
	time += min(gap[i],T)

print(time)
dict = {'A':'T','G':'C'}
b = input()

print(dict[b])

### FIXED CODE ###

dict = {'A':'T','C':'G','T':'A','G':'C'}
b = input()

print(dict[b])
m, n = map(int, input().split())
print(pow(m, n, int(1e9) + 7))javascript:void(0)


### FIXED CODE ###

m, n = map(int, input().split())
print(pow(m, n, int(1e9) + 7))
S= str(input())
#N,K = map(int,input().split())
#N = int(input())
#V = list(map(int,input().split()))
C=[]
c=0
for i in range(len(S)):
    if S[i]=='A' or S[i]=='T' or S[i]=='C' or S[i]=='G':
        c+=1
    else:
        C.append(c)
        c=0

print(max(C))


### FIXED CODE ###

S= str(input())
#N,K = map(int,input().split())
#N = int(input())
#V = list(map(int,input().split()))
C=[]
c=0
for i in range(len(S)):
    if S[i]=='A' or S[i]=='T' or S[i]=='C' or S[i]=='G':
        c+=1
    else:
        C.append(c)
        c=0
C.append(c)
print(max(C))
n = int(input())
v = list(map(int,input().split()))
v0 = v[0:n-1:2]
v1 = v[1:n:2]
from collections import Counter
V0 = Counter(v0)
V1 = Counter(v1)
if V0.most_common()[0][0] != V1.most_common()[0][0]:
    a = V0.most_common()[0][1]
    b = V1.most_common()[0][1]
else:
    if V0.most_common()[0][1] > V1.most_common()[0][1]:
        if len(V1) > 1:
            a = V0.most_common()[0][1]
            b = V1.most_common()[1][1]
        else:
            a = V0.most_common()[0][1]
            b = 0
    elif V0.most_common()[0][1] < V1.most_common()[0][1]:
        if len(V0) > 1:
            a = V1.most_common()[0][1]
            b = V0.most_common()[1][1]
        else:
            a = 0
            b = V1.most_common()[0][1]
    else:
        if len(V0) == 1 and len(V1) == 1:
            a = 0
            b = V0.most_common()[1][1]
        elif len(V0) == 1:
            a = V0.most_common()[0][1]
            b = V1.most_common()[1][1]
        elif len(V1) == 1:
            a = V0.most_common()[1][1]
            b = V1.most_common()[0][1]
        else:
            a = V0.most_common()[0][1]
            b = max(V0.most_common()[1][1],V1.most_common()[1][1])
print(n-a-b)

### FIXED CODE ###

n = int(input())
v = list(map(int,input().split()))
v0 = v[0:n-1:2]
v1 = v[1:n:2]
from collections import Counter
V0 = Counter(v0)
V1 = Counter(v1)
if V0.most_common()[0][0] != V1.most_common()[0][0]:
    a = V0.most_common()[0][1]
    b = V1.most_common()[0][1]
else:
    if V0.most_common()[0][1] > V1.most_common()[0][1]:
        if len(V1) > 1:
            a = V0.most_common()[0][1]
            b = V1.most_common()[1][1]
        else:
            a = V0.most_common()[0][1]
            b = 0
    elif V0.most_common()[0][1] < V1.most_common()[0][1]:
        if len(V0) > 1:
            a = V1.most_common()[0][1]
            b = V0.most_common()[1][1]
        else:
            a = 0
            b = V1.most_common()[0][1]
    else:
        if len(V0) == 1 and len(V1) == 1:
            a = 0
            b = V0.most_common()[0][1]
        elif len(V0) == 1:
            a = V0.most_common()[0][1]
            b = V1.most_common()[1][1]
        elif len(V1) == 1:
            a = V0.most_common()[1][1]
            b = V1.most_common()[0][1]
        else:
            a = V0.most_common()[0][1]
            b = max(V0.most_common()[1][1],V1.most_common()[1][1])
print(n-a-b)
S = input()

counter = 1
yorn = 1
for foot in S:
    if foot == 'R':
        if counter % 2 == 0:
            yorn=0
            break
    elif foot == 'L':
        if counter % 2 == 1:
            yorn = 0
            break
    counter++

if yorn == 1:
    print("Yes")
else:
    print("No")



### FIXED CODE ###

S = input()

counter = 1
yorn = 1
for foot in S:
    if foot == 'R':
        if counter % 2 == 0:
            yorn=0
            break
    elif foot == 'L':
        if counter % 2 == 1:
            yorn = 0
            break
    counter+=1

if yorn == 1:
    print("Yes")
else:
    print("No")
from sys import stdin, exit
from math import gcd


rs = lambda: stdin.readline().strip()
ri = lambda: int(rs())
rsl = lambda: stdin.readline().split()
rim = lambda: map(int, rsl())
ril = lambda: list(rim())


N = ri()
A = list(rim())
A.sort()

# List if length of 2 or shorter
if len(A) <= 2:
    print(max(A))
    exit()

# Left Side = [A0, 0, 0, 0, 0]
left_side = [0 for _ in range(N)]
left_side[0] = A[0]

# Right Side = [0, 0, 0, 0, An]
right_side = [0 for _ in range(N)]
right_side[-1] = A[-1]

for i in range(N - 1):  # DP: L1 = gcd(L0, A1); Maximum GCD on very RIGHT of list  (Dir -->)
    left_side[i + 1] = gcd(left_side[i], A[i + 1])
    
for i in range(1, N):   # DP: Rn-2 = gcd(An-2, Rn-1); Maximum GCD on very LEFT of list  (Dir <--)
    right_side[-1 * (i+1)] = gcd(A[-1*(i+1)], right_side[-1*i])
    
max_gcd = 1

# Left
max_gcd = max(max_gcd, right_side[1])
# Max of Right and Left
max_gcd = max(max_gcd, left_side[-2])

for i in range(1, N - 1):
    left = left_side[i - 1]
    # We exclude the number at i here, and compare whether new gcd is greater than previous
    right = right_side[i + 1]

    max_gcd = max(max_gcd, gcd(left, right))

print(max_gcd)

### FIXED CODE ###

from sys import stdin, exit
from fractions import gcd


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

# List if length of 2 or shorter
if len(A) <= 2:
    print(max(A))
    exit()

# Left Side = [A0, 0, 0, 0, 0]
left_side = [0 for _ in range(N)]
left_side[0] = A[0]

# Right Side = [0, 0, 0, 0, An]
right_side = [0 for _ in range(N)]
right_side[-1] = A[-1]

for i in range(N - 1):  # DP: L1 = gcd(L0, A1); Maximum GCD on very RIGHT of list  (Dir -->)
    left_side[i + 1] = gcd(left_side[i], A[i + 1])

for i in range(1, N):   # DP: Rn-2 = gcd(An-2, Rn-1); Maximum GCD on very LEFT of list  (Dir <--)
    right_side[-1 * (i+1)] = gcd(A[-1*(i+1)], right_side[-1*i])

max_gcd = 1

# Left
max_gcd = max(max_gcd, right_side[1])
# Max of Right and Left
max_gcd = max(max_gcd, left_side[-2])

for i in range(1, N - 1):
    left = left_side[i - 1]
    # We exclude the number at i here, and compare whether new gcd is greater than previous
    right = right_side[i + 1]

    max_gcd = max(max_gcd, gcd(left, right))

print(max_gcd)
S = list(input())
final_str = []
for key in S: 
    if key == "B":
      final_str = final_str[:-1]
    else:
      final_str.append(key)
print(''.join(final_str)

### FIXED CODE ###

S = list(input())
final_str = []
for key in S: 
    if key == "B":
      final_str = final_str[:-1]
    else:
      final_str.append(key)
print(''.join(final_str))
import sys
import numpy as np
input = sys.stdin.readline

n = int(input())
L = np.array(list(map(int, input().split())))
s = 0
f = True
while True:
    minL = np.min(L[s:])
    m_idx = np.where(L==minL)[0][-1]
    for i in range(s, m_idx):
        if L[i] - minL >=2:
            print('No')
            f = False
            break
    s = m_idx+1
    
    if s==n or f ==False:
        break

if f ==True:
    print('Yes')


### FIXED CODE ###

import sys
import numpy as np
input = sys.stdin.readline
n = int(input())

L = np.array(list(map(int, input().split())))

for i in range(n-1, 0, -1):
    if L[i]-L[i-1] ==-1:
        L[i-1] -=1

if np.all(L ==sorted(L)):
    print('Yes')
else:
    print('No')
#include <stdio.h>

int main()
{
    int N, a, b, c;
    long Y, yn;

    scanf("%d", &N);
    scanf("%ld", &Y);

    Y = Y / 1000;
    yn = Y - N;

    for (c = 0; c <= N; c++) {
        b = (yn - 9 * c) / 4;
        if ((yn - 9 * c) % 4 == 0) {
            a = N - b - c;
            if ((a >= 0) && (yn == 4 * b + 9 * c)) {
                printf("%d %d %d", a, b, c);
                return 0;
            }
        }
    }
    printf("%d %d %d", -1, -1, -1);
    return 0;
}

### FIXED CODE ###

N, Y = map(int, input().split())
Y = Y//1000
for a in range(N+1):
    for b in range(N+1-a):
        if Y == a*10 + b*5 + (N - a - b):
            print(a,b,N-a-b)
            exit(0)
else:
    print(-1,-1,-1)
n = int(input())
a = [i for i in int(input().split())]
for  i in range(n):
    v  = a[i]
    j = i-1
    while a[j]>v and j>=0:
        a[j+1] = a[j]
        j -=1
    a[j] = v
    print(*a)


### FIXED CODE ###

n = int(input())
a = list(map(int, input().split()))
for  i in range(n):
    v  = a[i]
    j = i-1
    while a[j]>v and j>=0:
        a[j+1] = a[j]
        j -=1

    a[j+1] = v
    print(*a)
N= int(input())
D = list(map(int,input().split()))

if any((D+[0]).count(i) >2 for i in range(12)):
    print(0)
    exit(0)
raise

def check(i):
    return False

def get_close(l,d=0):
    return


### FIXED CODE ###

import itertools

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

if any((D+[0,0,12]).count(i) >2 for i in range(0,13)):
    print(0)
    exit(0)


l= [0]
if D.count(12):
    l.append(12)

can_select=[]
for i in range(1,12):
    if (D).count(i) ==2:
        l.append((i))
        l.append((24 - i))

    if D.count(i)==1:
        can_select.append(i)

def change12(v):
    return min(24-v,v)

def get_closest(l):
    min_val =24
    for i in range(len(l)-1):
        min_val= min(change12(l[i+1]-l[i]),min_val)

    return min(change12(l[-1] - l[0]),min_val )

tmp_ans=0
for seed in list(itertools.product(range(2), repeat=len(can_select))):
    tmp_list = list(l)
    for i,val in enumerate(can_select):
        if seed[i]==1:
            tmp_list.append(val)
        else:
            tmp_list.append(24-val)
    tmp_list.sort()
    tmp_ans =max(tmp_ans, get_closest(tmp_list))



print(tmp_ans)
a=set(list(map(input().split())))
print("Yes" if len(a)==2 else "No")

### FIXED CODE ###

x=list(input())
a=x[0]
b=x[1]
c=x[2]
d=x[3]
if a==b and a!=c:
  if c==d:
    print("Yes")
  else:
    print("No")
elif a==c and a!=b:
  if b==d:
    print("Yes")
  else:
    print("No")
elif a==d and a!=b:
  if b==c:
    print("Yes")
  else:
    print("No")
else:
  print("No")
def fold(x,m):
    y = 0
    for _ in range(m):
        if x & 1:
            y |= 1
        y <<= 1
        x >>= 1
    return x|y



h,w = map(int, input().split())
a = [list(map(int, input().split())) for _ in range(h)]
b = [list(map(int, input().split())) for _ in range(h)]
g = [[0]*w for _ in range(h)]
for i in range(h):
  for j in range(w):
    g[i][j] = abs(a[i][j] - b[i][j])
a = b = 0
m = max(max(x) for x in g)
mask = (1<<(m*(h+w+2)//2)) - 1

dp = [[0]*(w+1) for _ in range(h+1)]
dp[0][1] = 1
dp[1][0] = 1
for i in range(1,h+1):
  for j in range(1,w+1):
    par = dp[i-1][j] | dp[i][j-1]
    dp[i][j] = mask&(par<<g[i-1][j-1])|fold(par,g[i-1][j-1])
for i in range(m*(h+w+2)//2):
  if dp[h][w]&(1<<i):
    print(i)
    break


### FIXED CODE ###

n = int(input())
mod = 10**9 + 7
a = list(map(int, input().split()))
b = [sum(1 for x in a if x&(1<<i)) for i in range(60)]
ans = 0
for i in range(60):
  t = b[i]*(n-b[i])
  m = (1<<i)%mod
  ans = (ans + t*m%mod)%mod
print(ans)
lists = [int(x) for x in range(1,6)]
for i in range(1,len(list)+1):
  if list[i] == 0:
    print(i)

### FIXED CODE ###

array = list(map(int,input().split()))

for i in range(len(array)):
    if array[i] == 0:
        print(i+1)
        break
N = int(input())
T = [{} for i in range(N+1)]
for _ in range(N-1):
    a, b, c = map(int, input().split())
    T[a][b] = c
    T[b][a] = c

Q, K = map(int, input().split())
shortest_path = [0 for _ in range(N+1)]
queue = [[v, T[K][v], K] for v in T[K].keys()]

for _ in range(Q):
    x, y = map(int, input().split())
    while len(queue) > 0 or (shortest_path[x] != 0 and shortest_path[y] != 0):
        v = queue.pop(0)
        shortest_path[v[0]] = v[1]
        queue += [[u, T[v[0]][u] + v[1], v[0]] for u in T[v[0]].keys() if u != v[2]]
    print(shortest_path[x] + shortest_path[y])

### FIXED CODE ###

from collections import deque

N = int(input())
T = [{} for i in range(N+1)]
for _ in range(N-1):
    a, b, c = map(int, input().split())
    T[a][b] = c
    T[b][a] = c

Q, K = map(int, input().split())
shortest_path = [0 for _ in range(N+1)]
queue = deque([[v, T[K][v], K] for v in T[K].keys()])
for _ in range(N-1):
    v = queue.popleft()
    shortest_path[v[0]] = v[1]
    queue.extend([[u, T[v[0]][u] + v[1], v[0]] for u in T[v[0]].keys() if u != v[2]])

for _ in range(Q):
    x, y = map(int, input().split())
    print(shortest_path[x] + shortest_path[y])
while True:
    a, b = map(int, input().split())
    if a == 0 and b == 0:
        break
    if a > b:
        print(f'b a")
    else:
        print(f"a b")



### FIXED CODE ###

while True:
    a, b = map(int, input().split())
    if a == 0 and b == 0:
        break
    elif a > b:
        print(f'{b} {a}')
    else:
        print(f'{a} {b}')