Harryxun/stf_run huggingface dataset:
n = int(input())
a_ = list(map(int, input().split(' ')))
a = [-1]
i = 0
while  i < n:
    if a[-1] != a_[i]:
        a.append(a_[i])
    i += 1
a = a[1:]

ret = 1

i = 0
while i < n-2:
    if (a[i] > a[i+1] and a[i+1] < a[i+2]) or (a[i] < a[i+1] and a[i+1] > a[i+2]):
        ret += 1
        i += 2
    else:
        i += 1
        
print(ret)

### FIXED CODE ###


n = int(input())
a_ = list(map(int, input().split(' ')))
a = [-1]
i = 0
while  i < n:
    if a[-1] != a_[i]:
        a.append(a_[i])
    i += 1
a = a[1:]
n = len(a)

ret = 1

i = 0
while i < n-2:
    if (a[i] > a[i+1] and a[i+1] < a[i+2]) or (a[i] < a[i+1] and a[i+1] > a[i+2]):
        ret += 1
        i += 2
    else:
        i += 1
        
print(ret)
N,K=map(int,input().split())
td=[[int(a) for a in input().split()]for i in range(N)]

td=sorted(td,key=lambda x:-x[1])

ans=0
eat=[]
noteat=[]
for t,d in td[:K]:
  ans+=d
  if t not in eat:
    eat.append(t)
  else:
    noteat.append(d)
temp_result=ans+len(eat)**2
max_result=temp_result

for t,d in td[K:]:
  if not noteat:
    break
  if t not in eat:
    temp_result+=2*len(eat)+1
    temp_result+=d-noteat.pop()
    eat.add(t)
    max_result=max(max_result,temp_result)
print(max_result)
 



### FIXED CODE ###

N,K=map(int,input().split())
td=[[int(a) for a in input().split()]for i in range(N)]

td=sorted(td,key=lambda x:-x[1])

ans=0
eat=set([])
noteat=[]
for t,d in td[:K]:
  ans+=d
  if t not in eat:
    eat.add(t)
  else:
    noteat.append(d)
temp_result=ans+len(eat)**2
max_result=temp_result

for t,d in td[K:]:
  if not noteat:
    break
  if t not in eat:
    temp_result+=2*len(eat)+1
    temp_result+=d-noteat.pop()
    eat.add(t)
    max_result=max(max_result,temp_result)
print(max_result)
a = list(input().split()).sort()
print(a[0]*10+a[1]+a[2])

### FIXED CODE ###

a = sorted(list(map(int, input().split())))
print(10*a[2]+a[1]+a[0])
def binarySearch (arr, l, r, x): 
  
    # Check base case 
    if r >= l: 
  
        mid = l + (r - l) // 2
  
        # If element is present at the middle itself 
        if arr[mid] == x: 
            return mid 
          
        # If element is smaller than mid, then it  
        # can only be present in left subarray 
        elif arr[mid] > x: 
            return binarySearch(arr, l, mid-1, x) 
  
        # Else the element can only be present  
        # in right subarray 
        else: 
            return binarySearch(arr, mid + 1, r, x) 
  
    else: 
        # Element is not present in the array 
        return -1

l=list(map(int, input().split(' ')))

find=l[0]
n=l[1]

if n==0:
    print(find)
else:
    l=list(map(int, input().split(' ')))
    l=sorted(l)

    a=find+1
    b=find-1
    
    while True:
        if binarySearch(l, 0, n, b)==-1:
            print(b)
            break
        elif binarySearch(l, 0, n, a)==-1:
            print(a)
            break
        else:
            a+=1
            b-=1
        




### FIXED CODE ###

def binarySearch (arr, l, r, x): 
  
    # Check base case 
    if r >= l: 
  
        mid = l + (r - l) // 2
  
        # If element is present at the middle itself 
        if arr[mid] == x: 
            return mid 
          
        # If element is smaller than mid, then it  
        # can only be present in left subarray 
        elif arr[mid] > x: 
            return binarySearch(arr, l, mid-1, x) 
  
        # Else the element can only be present  
        # in right subarray 
        else: 
            return binarySearch(arr, mid + 1, r, x) 
  
    else: 
        # Element is not present in the array 
        return -1

l=list(map(int, input().split(' ')))

find=l[0]
n=l[1]

if n==0:
    print(find)
else:
    l=list(map(int, input().split(' ')))
    l=sorted(l)

    a=find
    b=find
    
    while True:
        if binarySearch(l, 0, n-1, b)==-1:
            print(b)
            break
        elif binarySearch(l, 0, n-1, a)==-1:
            print(a)
            break
        else:
            a+=1
            b-=1
import math
a,b=[int(i) for i in input().split()]
if a>=b:
	print(1)
else:
	b-=a
    print(1+math.ceil(b/(a-1)))
  

### FIXED CODE ###

import math 
a,b=[int(i) for i in input().split()]
curr = 1
tot = 0
while curr<b:
  curr += (a-1)
  tot += 1
print(tot)
from sys import stdin
import sys
# import itertools
# import math

S = input()
if S == 'zyxwvutsrqponmlkjihgfedcba':
    print(-1)
    sys.exit()
a = [chr(i) for i in range(97, 97+26)]
b = [0 for i in range(26)]
d = dict(zip(a, b))
d1 = d
for i, v in enumerate(S):
    d[v] = d.get(v, 0)+1
for i, v in enumerate(a):
    if d[v] != 1:
        print(S+v)
        sys.exit()
temp = []
temp1 = []
x = 10/0
for i in range(26):
    temp1 = []
    temp.append(S[-1-i])
    # print(S[-1-i])
    for i, v in enumerate(temp):
        if S[-1-i-1] < v:
            temp1.append(v)
    if len(temp1) > 0:
        print(S[:-1-i-1]+min(temp1))
        sys.exit()

### FIXED CODE ###

from sys import stdin
import sys
# import itertools
# import math

S = input()
if S == 'zyxwvutsrqponmlkjihgfedcba':
    print(-1)
    sys.exit()
a = [chr(i) for i in range(97, 97+26)]
b = [0 for i in range(26)]
d = dict(zip(a, b))
d1 = d
for i, v in enumerate(S):
    d[v] = d.get(v, 0)+1
for i, v in enumerate(a):
    if d[v] != 1:
        print(S+v)
        sys.exit()
temp = []
temp1 = []

for i in range(25):
    temp1 = []
    temp.append(S[-1-i])
    # print(S[-1-i], S[-1-i-1])
    for k, v in enumerate(temp):
        # print("v="+v)
        # print(S[-1-i-1], ord(S[-1-i-1]), ord(v))
        if S[-1-i-1] < v:
            temp1.append(v)
    # print(temp, temp1)
    if len(temp1) > 0:
        temp1.sort()
        print(S[:-1-i-1]+temp1[0])
        sys.exit()
s = input()

ans = 'Good'

for i in range(len(s)-1):
    if s[i] == s[i+1]:
        ans='Bad'

print(ans

### FIXED CODE ###

s = input()

ans = 'Good'

for i in range(len(s)-1):
    if s[i] == s[i+1]:
        ans='Bad'

print(ans)
N,K = map(int,input().split())
S= input()

sa = ""
for i in range(len(S)):
  if S[i] == S[int(K)]:
    sa = sa + str(S[i].lower())
  else:
    sa = sa + str(S[i])
print(sa)

### FIXED CODE ###

N,K= map(int,input().split())
S = input()
s=str("")
for i in range(len(S)):
    
    if i == K-1:
        #print(i,S[i].lower())
        s=s+S[i].lower()
    else:
        #print(i,S[i])
        s=s+S[i]
print(s)
n = int(input())
x = [0] * n
y = [0] * n
h = [0] * n
for i in range(n):
    x[i], y[i], h[i] = map(int, input().split())

ans = []
for X in range(101):
    for Y in range(101):
        flag = True
        height = []
        for i in range(n):
            height.append(max(h[i]+abs(x[i]-X)+abs(y[i]-Y),0))
        for i in range(n):
            if height[i] != height[0]:
                flag = False

        if flag:
            ans.append(X)
            ans.append(Y)
            ans.append(height[0])
            break

print(ans[0], ans[1], ans[2])
            


### FIXED CODE ###

n = int(input())

x = [0] * n
y = [0] * n
h = [0] * n

for i in range(n):
    x[i], y[i], h[i] = map(int, input().split())

for cx in range(101):
    for cy in range(101):
        H = -1
        for i in range(n):
            if h[i] == 0:
                pass
            else:
                tmp = h[i] + abs(x[i]-cx) + abs(y[i]-cy)
                H = tmp
                break
        flag = True
        for i in range(n):
            if h[i] != max(H-abs(x[i]-cx)-abs(y[i]-cy),0):
                flag = False
                break
        if flag:
            print(cx,cy,H)
import numpy as np
from collections import Counter
def f(lst):
    return np.cumsum(lst)

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

res = 0
for i in range(n):
    tmp_lst = lst[i:]
    c = dict(Counter(f(tmp_lst)))
    if 0 in c:
       res += c[0]
print(res)


### FIXED CODE ###

import numpy as np
from collections import Counter
def f(lst):
    return np.cumsum([0] + lst)

n = int(input())
lst = list(map(int,input().split()))
d = dict(Counter(f(lst)))

res = 0
for k,v in d.items():
    if v >= 2:
        res += (v*(v-1))//2
print(res)
N,Y = map(int,input().split())
x = y = z = 0
for i in range(N,-1,-1):
    if i*10000 <= Y:
        charge = Y - i*10000
        rest = N - i
        for j in range(rest,-1,-1):
            if j*5000 <= charge:
                if charge - j*50000 - (rest-j)*1000 == 0:
                    print(f'{i} {j} {rest-j}')
                    exit(0)


### FIXED CODE ###

N,Y = map(int,input().split())
x = y = z = 0
for i in range(N,-1,-1):
    if i*10000 <= Y:
        charge = Y - i*10000
        rest = N - i
        for j in range(rest,-1,-1):
            if j*5000 <= charge:
                if charge - j*5000 - (rest-j)*1000 == 0:
                    print('{0} {1} {2}'.format(i, j ,rest-j))
                    exit(0)
print('-1 -1 -1')
def recursion_g(eges, length, f):
    if length[f] != -1:
        return length[f]
    if not eges[f]:
        length[f] = 0
        return 0
    memo = []
    for t in eges[f]:
        memo.append(recursion_g(eges, length, t) + 1)
    length[f] = max(memo)
    return length[f]


def p_g():
    N, M = map(int, input().split())
    edges = [[] for _ in range(N)]
    length = [-1] * N
    for _ in range(M):
        x, y = map(int, input().split())
        edges[x - 1].append(y - 1)

    for i in range(N):
        recursion_g(edges, length, i)
    print(max(length))


if __name__ == '__main__':
    p_g()

### FIXED CODE ###

import sys

sys.setrecursionlimit(10 ** 6)


def recursion_g(eges, length, f):
    if length[f] != -1:
        return length[f]
    if not eges[f]:
        length[f] = 0
        return 0
    memo = []
    for t in eges[f]:
        memo.append(recursion_g(eges, length, t) + 1)
    length[f] = max(memo)
    return length[f]


def p_g():
    N, M = map(int, input().split())
    edges = [[] for _ in range(N)]
    length = [-1] * N
    for _ in range(M):
        x, y = map(int, input().split())
        edges[x - 1].append(y - 1)

    for i in range(N):
        recursion_g(edges, length, i)
    print(max(length))


if __name__ == '__main__':
    p_g()
N, M = map(int, input().split())
nl = [[] for _ in range(N + 1)]
for _ in range(M):
    L, R, D = map(int, input().split())
    nl[L].append((R, D))
    nl[R].append((L, -D))

seen = [None for _ in range(N + 1)]


def dfs(v, d):
    seen[v] = d
    for next_v, D in nl[v]:
        next_d = d + D
        if seen[next_v] is None:
            dfs(next_v, next_d)
        else:
            if seen[next_v] != next_d:
                print('No')
                exit(0)


for v in range(1, N + 1):  # すべての連結成分に対してDFS
    if seen[v] is None:
        dfs(v, 0)

print('Yes')


### FIXED CODE ###

import sys
sys.setrecursionlimit(300000)

N, M = map(int, input().split())
nl = [[] for _ in range(N + 1)]
for _ in range(M):
    L, R, D = map(int, input().split())
    nl[L].append((R, D))
    nl[R].append((L, -D))

seen = [None for _ in range(N + 1)]


def dfs(v, d):
    seen[v] = d
    for next_v, D in nl[v]:
        next_d = d + D
        if seen[next_v] is None:
            dfs(next_v, next_d)
        else:
            if seen[next_v] != next_d:
                print('No')
                exit(0)


for v in range(1, N + 1):  # すべての連結成分に対してDFS
    if seen[v] is None:
        dfs(v, 0)

print('Yes')
# encoding:utf-8
import copy
import random
import bisect #bisect_left　これで二部探索の大小検索が行える
import fractions #最小公倍数などはこっち
import math

mod = 10**9+7

a,b,c = map(int,input())
if b-a == c-b:
    print("YES")
else:
    print("NO")


### FIXED CODE ###

# encoding:utf-8
import copy
import random
import bisect #bisect_left　これで二部探索の大小検索が行える
import fractions #最小公倍数などはこっち
import math

mod = 10**9+7

a,b,c = map(int,input().split())
if b-a == c-b:
    print("YES")
else:
    print("NO")
import sys
for s in sys.stdin:
    x=map(int,list(str(s))[:-1])
    while True:
        a=len(x)
        x=[(x[i]+x[i+1])%10 for i in range(a-1)]
        if a==1: break
    print x[0]

### FIXED CODE ###

import sys
for s in sys.stdin:
    x=["0123456789".index(c) for c in s[:-1]]
    while True:
        a=len(x)-1
        x=[(x[i]+x[i+1])%10 for i in range(a)]
        if a==1: break
    print x[0]
X = input()

if X == 3 or X == 5 or X == 7:
	print('Yes')
else 
	print('No')

### FIXED CODE ###

X = int(input())


if X == 3 or X == 5 or X == 7:
	print('YES')
else :
	print('NO')
a, b = int(input().split())
c = a * b
if(c%2 = 0):
  print('Even')
else:
  print('Odd')

### FIXED CODE ###

a, b = map(int, input().split())
c = a * b
if (c % 2 == 0):
	print('Even')
else:
	print('Odd')
iport numpy as np
n=int(input())
ans=[]
for i in range(n):
    qw=input()
    ans.append(np.zeros(10))
    for j in range(10):
        ans[i][j]=qw[j]
    ans[i].sort()

ans.sort()
a=0
for i in range(n-1):
    for j in range(n-1-i):
        if ans[i]==ans[i+j+1]:
            a+=1
        else:
            break

print(int(a))


### FIXED CODE ###

n=int(input())
ans=[]
for i in range(n):
    qw=input()
    ans.append([0,0,0,0,0,0,0,0,0,0])
    for j in range(10):
        ans[i][j]=qw[j]
    ans[i].sort()

lis=[]
for i in range(n):
    lis.append(ans[i][0])
    for j in range(9):
        lis[i]+=ans[i][j+1]

a=0
#print(lis)

dic={lis[0]:1}
for i in range(n-1):
    if lis[i+1] in dic.keys():
        a+=dic[lis[i+1]]
        dic[lis[i+1]]+=1
    else:
        dic[lis[i+1]]=1

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

D = [0]

def f(a):
  if a <= N:
    M = max(A[a:N+1])
    Mi = A.index(M)
    m = min(A[a-1:Mi])
    d = M - m
    if D[-1] == d:
      D.append(d)
    elif D[-1] < d:
      D.clear()
      D.append(d)
    f(Mi+2)
  else:
    pass

f(1)

result = len(D)
print(result)


### FIXED CODE ###

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

B = []
Amin = A[0]

for i in range(1, N):
  if A[i] < Amin:
    Amin = A[i]
  else:
    B.append(A[i] - Amin)

result = B.count(max(B))
print(result)
N = int(input())
s = []
temp_sum = 0
A_or_B_count = [0,0]
AB_count = 0
for i in range(N):
	aaa = input()
	temp_sum += aaa.count("AB")
	if aaa[0] == "B" and aaa[-1] == "A":
		AB_count += 1
	elif aaa[-1] == "A":
		A_or_B_count[0] += 1
	elif aaa[0] == "B":
		A_or_B_count[1] += 1
A_or_B_count.sort()
if A_or_B_count[0] + AB_count > A_or_B_count[1]:
	if A_or_B_count[0] == 0:
		print(temp_sum + min(N-1,AB_count - 1)
	else:
		AB_count -= (A_or_B_count[1] - A_or_B_count[0])
		print(temp_sum + min(N-1,AB_count + A_or_B_count[1]))
else:
	print(temp_sum + min(N - 1,A_or_B_count[0] + AB_count))


	

	

### FIXED CODE ###

N = int(input())
s = []
temp_sum = 0
A_or_B_count = [0,0]
AB_count = 0
for i in range(N):
	aaa = input()
	temp_sum += aaa.count("AB")
	if aaa[0] == "B" and aaa[-1] == "A":
		AB_count += 1
	elif aaa[-1] == "A":
		A_or_B_count[0] += 1
	elif aaa[0] == "B":
		A_or_B_count[1] += 1
A_or_B_count.sort()
if A_or_B_count[0] + AB_count > A_or_B_count[1]:
	if A_or_B_count[1] == 0:
		print(temp_sum + min(N-1,AB_count - 1))
	else:
		AB_count -= (A_or_B_count[1] - A_or_B_count[0])
		print(temp_sum + min(N-1,AB_count + A_or_B_count[1]))
else:
	print(temp_sum + min(N - 1,A_or_B_count[0] + AB_count))
N, M = map(int, input().split())
AB, mx = [], [0] * (10 ** 1 + 1)
for i in range(N):
    A, B = map(int, input().split())
    AB.append((A, B))
    mx[A] = max(mx[A], B)

AB.sort(key=lambda x: x[1], reverse=True)
AB.sort(key=lambda x: x[0])

ans, idx, lAB = 0, 0, len(AB)
for i in range(1, M + 1):
    if AB[idx][0] <= i:
        while AB[idx][1] < mx[AB[idx][0] + 1]:
            tmp = AB[idx][0] + 1
            while not AB[idx][0] == tmp:
                idx += 1
        ans, idx = ans + AB[idx][1], idx + 1

print(ans)


### FIXED CODE ###

import heapq
maxB = 10 ** 1

N, M = map(int, input().split())
AB = []
for _ in range(N):
    A, B = map(int, input().split())
    AB.append((maxB - B, A))

AB.sort(key=lambda x: x[1])

ans, heap, idx, lAB = 0, [], 0, len(AB)
for i in range(M):
    while idx < lAB and AB[idx][1] <= i + 1:
        heapq.heappush(heap, AB[idx])
        idx += 1
    if len(heap) > 0:
        ans += maxB - heapq.heappop(heap)[0]

print(ans)
N = int(input())
A = input()
A = A.split()
A = [int(c) for c in A]
A.sort()
count = 0
for i in range(N):
    for j in range(i,N):
        if A[i] % A[j] == 0 and i != j:
            count += 1
            break
print(N-count)

### FIXED CODE ###

a,b,c,d,e = map(int, input().split())
count = 1
for i in [a,b,c,d,e]:
    if i == 0:
        print(count)
    count += 1
x = int(input())
ans = 1
for i in range(2,x+1):
    j = 2
    while i **j <= x:
        ans = max(ans, i**j)
        j+=1
print(ans)

### FIXED CODE ###

a,b,c,d = map(int, input().split())
print('Yes' if (abs(a-b)<=d and abs(c-b)<=d) or abs(a-c)<=d else 'No')
import sys
sys.setrecursionlimit(1000000000)

n = int(input())
x = input()
xx = int(x, 2)
value = [0, 1]
count_1 = x.count('1')
for i in range(2, 2 * (10 ** 5) + 1):
    ans = 1
    i = i % bin(i).count('1')
    value.append(ans + value[i])

for i in range(n):
    ttt = xx & pow(2, n - i - 1)
    if ttt > 0:
        t = xx - pow(2, n - i - 1)
        point = count_1 - 1
    else:
        t = xx + pow(2, n - i - 1)
        point = count_1 + 1
    ans = 1
    t = (t % point)
    print(ans + value[t])

### FIXED CODE ###

n = int(input())
x = input()
count_1 = x.count('1')
value = [0, 0]
x_int = int(x, 2)
value[0] = x_int % (count_1 - 1) if count_1 > 1 else 0
value[1] = x_int % (count_1 + 1)
for i in range(n):
    if x[i] == '0':
        tmp = (pow(2, n - i - 1, count_1 + 1) + value[1]) % (count_1 + 1)
    else:
        if count_1 == 1:
            print(0)
            continue
        tmp = (-pow(2, n - i - 1, count_1 - 1) + value[0]) % (count_1 - 1)
    ans = 1
    while tmp > 0:
        tmp = tmp % (bin(tmp).count('1'))
        ans += 1
    print(ans)
N = int(input())
s = input()
a=0
for i in range N-2:
  if s[i:i+2]=="ABC":
    a +=1
print(a)

### FIXED CODE ###

N = int(input())
s = input()
print(s.count("ABC"))
n = int(input())
march_l = [0]*5
for _ in range(n):
    s = input()
    s0 = s[0]
    if s0 == 'M':
        march_l[0] += 1
    elif s0 == 'A':
        march_l[1] += 1
    elif s0 == 'R':
        march_l[2] += 1
    elif s0 == 'C':
        march_l[3] += 1
    elif s0 == 'H':
        march_l[4] += 1

cnt =  [i for i in march_l if i != 0]
len_cnt = len(cnt)

if len_cnt > 3:
    for i in range(2**len_cnt):
        tmp = 1
        if str(bin(i)).count('1') == 3:
            for j in range(len_cnt):
                if ((i>>j) & 1):
                    tmp *= cnt[j]
            ans += tmp
elif len_cnt == 3:
    ans = 1
    for i in cnt:
        ans *= i
else:
    ans = 0

print(ans)

### FIXED CODE ###

n = int(input())
march_l = [0]*5
for _ in range(n):
    s = input()
    s0 = s[0]
    if s0 == 'M':
        march_l[0] += 1
    elif s0 == 'A':
        march_l[1] += 1
    elif s0 == 'R':
        march_l[2] += 1
    elif s0 == 'C':
        march_l[3] += 1
    elif s0 == 'H':
        march_l[4] += 1

cnt =  [i for i in march_l if i != 0]
len_cnt = len(cnt)
ans = 0

if len_cnt > 3:
    for i in range(2**len_cnt):
        tmp = 1
        if str(bin(i)).count('1') == 3:
            for j in range(len_cnt):
                if ((i>>j) & 1):
                    tmp *= cnt[j]
            ans += tmp
elif len_cnt == 3:
    ans = 1
    for i in cnt:
        ans *= i
        
print(ans)
from itertools import product
n, m, x = list(map(int, input().split()))
cl = [0] * n
al = [[]*m for _ in range(n)]
for i in range(n):
    tmp = list(map(int, input().split()))
    cl[i] = tmp[0]
    al[i] = tmp[1:]


def dfs(status, book):
    for i in range(m):
        status[i] += book[i]
    return status


ans = 10**10
for bit in product([0, 1], repeat=n):
    # print(bit)
    status = [0]*n
    money = 0
    for i, b in enumerate(list(bit)):
        if b == 1:
            status = dfs(status, al[i])
            money += cl[i]
    flag = True
    for i in range(m):
        if status[i] >= x:
            continue
        else:
            flag = False
    if flag:
        ans = min(ans, money)
if ans == 10**10:
    print(-1)
    exit()
print(ans)


### FIXED CODE ###

from itertools import product
n, m, x = list(map(int, input().split()))
cl = [0] * n
al = [[]*m for _ in range(n)]
for i in range(n):
    tmp = list(map(int, input().split()))
    cl[i] = tmp[0]
    al[i] = tmp[1:]


def dfs(status, book):
    for i in range(m):
        status[i] += book[i]
    return status


ans = 10**10
for bit in product([0, 1], repeat=n):
    # print(bit)
    status = [0]*m
    money = 0
    for i, b in enumerate(list(bit)):
        if b == 1:
            for k in range(m):
                status[k] += al[i][k]
            money += cl[i]
    flag = True
    for i in range(m):
        if status[i] >= x:
            continue
        else:
            flag = False
    if flag:
        ans = min(ans, money)
if ans == 10**10:
    print(-1)
else:
    print(ans)
import sys

for line in sys.stdin:
    x1, y1, x2, y2 = line.strip('\n')
    x1, y1, x2, y2 = float(x1), float(y1), float(x2), float(y2)
    print ((x1-x2)**2+(y1-y2)**2)**0.5

### FIXED CODE ###

x1, y1, x2, y2 = map(float, raw_input().split())
print ((x1-x2)**2 + (y1-y2)**2)**0.5
def whatIsRight(u,f):	
    r = 0
    if u == 1:
        if f == 2:
            r = 3
        elif f == 3:
            r = 5
        elif f == 4:
            r = 2
        elif f == 5:
            r = 4
        return r
	
    if u == 2:
        if f == 6:
            r = 3
        elif f == 3:
            r = 1
        elif f == 1:
            r = 4
        elif f == 4:
            r = 6
        return r

    if u == 3:
        if f == 5:
            r = 1
        elif f == 1:
            r = 2
        elif f == 2:
            r = 6
        elif f == 6:
            r = 3
        return r
			
    if u == 4:
        if f == 6:
            r = 2
        elif f == 2:
            r = 1
        elif f == 1:
            r = 5
        elif f == 5:
            r = 6 
        return r 
			
    if u == 5:
        if f == 3:
            r = 6
        elif f == 6:
            r = 4
        elif f == 4:
            r = 1
        elif f == 1:
            r = 3
	return r
		
    if u == 6:
        if f == 5:
            r = 3
        elif f == 3:
            r = 2
        elif f == 2:
            r = 4
        elif f == 4:
            r = 5
        return r
			
n = list(map(int,input().split()))
N = int(input())

for i in range(N):
    m = list(map(int,input().split()))
    num = []

    for j in range(len(m)):
        for k in range(len(n)):
            if m[j] == n[k]:
                num.append(k+1)
                break
	
    print(n[whatIsRight(num[0],num[1]) -1])

### FIXED CODE ###

def move(up,bottom,right,left,front,back,direction):
    if direction == "N":
        return (front,back,right,left,bottom,up)
    elif direction == "S":
        return (back,front,right,left,up,bottom)
    elif direction == "E":
        return (left,right,up,bottom,front,back)
    elif direction == "W":
        return (right,left,bottom,up,front,back)
    
def check(up,bottom,right,left,front,back,up_current,front_current):
    if front_current == front and up_current == up:
        print(right)     
    elif front_current == front:
        if left == up_current:
            print(up)
        elif bottom == up_current:
            print(left)
        elif right == up_current:
            print(bottom)
    elif up_current == up:
        if right == front_current:
            print(back)
        elif back == front_current:
            print(left)
        elif left == front_current:
            print(front)
    else:
      
        up,bottom,right,left,front,back = move(up,bottom,right,left,front,back,"S")
        check(up,bottom,right,left,front,back,up_current,front_current)
                
                
                
                
up,front,right,left,back,bottom = input().split()
n = int(input())

for i in range(n):
    up_current,front_current = input().split()
    check(up,bottom,right,left,front,back,up_current,front_current)