Harryxun/stf_run huggingface dataset:
n = int(input())
alist  = list(map(int,input().split()))
list1 = alist[1::2]
list2 = alist[0::2]
from collections import Counter
dic1 = Counter(list1)
dic2 = Counter(list2)
sortdic1 = sorted(dic1.items(),key=lambda x:x[1], reverse=True)
sortdic2 = sorted(dic2.items(),key=lambda x:x[1], reverse=True)
vlist1 = list(sortdic1.items())
vlist2 = list(sortdic2.items())
if vlist1[0][0]!=vlist[0][0]:
  print(n - vlist1[0][1] - vlist2[0][1])
else:
  if (vlist1[0][1] + vlist2[1][1])>(vlist1[1][1] + vlist2[0][1]):
    print(n - vlist1[0][1] - vlist2[1][1])
  else:
    print(n -vlist1[1][1] - vlist2[0][1])
    
    

### FIXED CODE ###

n = int(input())
alist  = list(map(int,input().split()))
list1 = alist[1::2]
list2 = alist[0::2]
from collections import Counter
dic1 = Counter(list1).most_common()
dic2 = Counter(list2).most_common()
dic1.append([0,0])
dic2.append([0,0])
if dic1[0][0]!=dic2[0][0]:
  print(n - dic1[0][1] - dic2[0][1])
else:
  print(min(n - dic1[0][1] - dic2[1][1], n -dic1[1][1] - dic2[0][1]))
a, b = input().split()
ans = max(a+b, a-b, a*b)
print(ans)

### FIXED CODE ###

a, b = [int(x) for x in input().split()]
ans = max(a+b, a-b, a*b)
print(ans)
import collections
N = int(input())
xy = [tuple(map(int,input().split())) for i in range(N)]
xy.sort( key = lambda x: (x[0],x[1]))
l = []
for i in range(N):
    for j in range(i+1,N):
        (x_diff, y_diff) = [xy[i][0]-xy[j][0],xy[i][1]-xy[j][1]]
        l.append((x_diff, y_diff))
dic = collections.Counter(l)
val = dic.values()
print(N - max(val))

### FIXED CODE ###

#[R,G,B,N] = list(map(int,input().split()))
import collections
N = int(input())
xy = [tuple(map(int,input().split())) for i in range(N)]
xy.sort( key = lambda x: (x[0],x[1]))
l = []
for i in range(N):
    for j in range(i+1,N):
        (x_diff, y_diff) = [xy[i][0]-xy[j][0],xy[i][1]-xy[j][1]]
        l.append((x_diff, y_diff))
dic = collections.Counter(l)
val = dic.values()
if len(val) == 0:
    print(1)
else:
    print(N - max(val))
S = list(input())
K = int(input())

for i in range(K):
    if S[i] != '1':
        ans = s
        break
    else:
        ans = 1
        continue
print(ans)

### FIXED CODE ###

S = list(input())
K = int(input())

for i in range(K):
    if S[i] != '1':
        ans = S[i]
        break
    else:
        ans = 1
        continue
print(ans)
import math 

A, B = map(int, input().split())

def sieve_of_eratosthenes(n): 
    candidate = [i for i in range(2, n+1)] 
    prime = []
    limit = math.sqrt(n) + 1 

    while True:
        p = min(candidate) 
        if limit <= p:
            prime.extend(candidate) 
            break
        prime.append(p) 

        candidate = [i for i in candidate if i % p != 0]

    return prime

def divisor(n): #nの約数を全て求める
    i = 1
    table = []
    while i * i <= n:
        if n % i == 0:
            table.append(i)
            table.append(n//i)
        i += 1
    
    return list(set(table))
  
ma = max(A, B)
mi = min(A, B)

yakusu = [d for d in divisor(mi) if ma % d == 0]

yakumax = max(yakusu)
if yakumax == 1:
	prime = [1]
elif yakumax == 2:
  prime = [1, 2]
else:
  prime = sieve_of_eratosthenes(yakumax)
  prime.append(1)

c = 0
for y in yakusu:
  if y in prime:
    c += 1
    
print (c)

### FIXED CODE ###

N = int(input())

odd = 0
for i in range(N):
  if i % 2 == 0:
  	odd += 1

print(odd / N)
N.M=map(int,input().split())
MOD=10**9+7
s=1
for i in range(2,N+1):
  s=s*i
t=1
for j in range(2,N+1):
  t=t*j
if N-1==M:
  print((s*t)%MOD)
if N==M-1:
  print((s*t)%MOD)
if N==M:
  print((2*s*t)%MOD)
else:
  print(0)

### FIXED CODE ###

N,M=map(int,input().split())
MOD=10**9+7
s=1
for i in range(2,N+1):
  s=(s*i)%MOD
t=1
for i in range(2,M+1):
  t=(t*i)%MOD
if abs(N-M)>1:
  print(0)
  exit()
if abs(N-M)==1:
  print((s*t)%MOD)
else:
  print((2*s*t)%MOD)
n,m= map(int, input().split())
a=[-1]
for i in range(m):
    a.append(int(input()))
a.append(n+1)
ans=1

def fib(x):
    if x==-1:
        count=0
    elif x==0:
        count=1
    else:
        count=fib(x-1)+fib(x-2)
    return count
    
for i in range(m+1):
    ans=ans*fib(a[i+1]-a[i]-2)
    
print(ans%1000000007)

### FIXED CODE ###

n,m= map(int, input().split())
if m!=0:
  a = [int(input()) for _ in range(m)]
else:
  a=[0]
dp=[0]*(n+1)
dp[0]=1
j=0

for i in range(1,n+1):
    if i==a[j]:
        if j<m-1:
            j+=1
    else:
        if i==1:
            dp[i]=1
        else:
            dp[i]=dp[i-1]+dp[i-2]

print(dp[n]%(10**9+7))
S,W = int(input())
if S <= W : print("unsafe")
else: print("safe")

### FIXED CODE ###

S, W = map(int,input().split())
if S <= W :
  print("unsafe")
else:
  print("safe")
c=int(input())
count=1
ans=10000000000000
k=c
a=[]
for i in range(1,int(c**(1/2))):
    if c%i==0:
        count*=i
        k=int(k/i)
        a.append(count+k)
        count=1
        k=c
print(a)
print(min(a)-2)

### FIXED CODE ###

c=int(input())
count=1
ans=10000000000000
k=c
for i in range(1,int(c**(1/2)+100000)):
    if c%i==0:
        if ans>i+int(c/i):
            ans=i+int(c/i)
        else:
            continue
print(ans-2)
s=input().split()
A=s[0]
op=s[1]
B=s[2]
if(op=="+"):
  print(A+B)
else:
  print(A-B)

### FIXED CODE ###

s=input().split()
A=int(s[0])
op=s[1]
B=int(s[2])
if(op=="+"):
  print(A+B)
else:
  print(A-B)
N = int(input())
A = list(map(int, input().split()))
 
count = 0
while True:
  A, mod = zip([divmod(a, 2) for a in A])
  if sum(mod) > 0:
    break
  count += 1
print(count)

### FIXED CODE ###

N = int(input())
A = list(map(int, input().split()))
 
count = 0
while True:
  A, mod = zip(*[divmod(a, 2) for a in A])
  if sum(mod) > 0:
    break
  count += 1
print(count)
import math
def calc_distance(x1, y1, x2, y2):

    '''
    :param x1:(float)
    :param y1:(float)
    :param x2:(float)
    :param y2:(float)
    :return: (float) distance between two points
    '''

    return math.sqrt((x2 - x1) ** 2 + (y2 - y1) ** 2)



if  __name__ == '__main__':
    x1, y1, x2, y2 = [int(x) for x in input().split(" ")]
    res = calc_distance(x1, y1, x2, y2)
    print(res)

### FIXED CODE ###

import math
x1, y1, x2, y2 = map(float, input().split())

d = math.sqrt(((x2 - x1) ** 2 + (y2 - y1) ** 2))
print(d)
N, M = map(int, input().split())
A = [int(input()) for _ in range(M)]
DIV = 10**9+7

def main():
    B = [0]*(M+1)
    for i in range(M+1):
        if i==0:
            B[i] = A[i]-1
        elif i==M:
            B[i] = N-A[i-1]-1
        else:
            if A[i]==A[i-1]:
                B[i] = 0
            else:
                B[i] = A[i] - A[i-1] - 2
    min_B = min(B)
    if min_B<0:
        return 0
    
    max_B = max(B)
    F = [1]*(max_B+1)
    for i in range(max_B+1):
        if i<2:
            pass
        else:
            F[i] = F[i-2] + F[i-1]
    ans = 1
    for b in B:
        ans *= F[b]
        if ans > DIV:
            ans %= DIV
    return ans

print(main())


### FIXED CODE ###

N, M = map(int, input().split())
A = [int(input()) for _ in range(M)]
DIV = 10**9+7

def main():
    if M>0:
        B = [0]*(M+1)
        for i in range(M+1):
            if i==0:
                B[i] = A[i]-1
            elif i==M:
                B[i] = N-A[i-1]-1
            else:
                if A[i]==A[i-1]:
                    B[i] = 0
                else:
                    B[i] = A[i] - A[i-1] - 2
    else:
        B = [N]
    min_B = min(B)
    if min_B<0:
        return 0
    
    max_B = max(B)
    F = [1]*(max_B+1)
    for i in range(max_B+1):
        if i<2:
            pass
        else:
            F[i] = F[i-2] + F[i-1]
    ans = 1
    for b in B:
        ans *= F[b]
        if ans >= DIV:
            ans %= DIV
    return ans

print(main())
x = input()
l = len(x)
a = 0
for i in range(l):
  a += int(x[i])
if a%x ==0:
  print('Yes')
else:
  print('No')

### FIXED CODE ###

x = input()
l = len(x)
a = 0
for i in range(l):
  a += int(x[i])
#print(a)
if int(x)%a ==0:
  print('Yes')
else:
  print('No')
N = int(input())
str_list = [str(input()) for _ in range(N)]
count_ac = 0
count_wa = 0
count_tle = 0
count_re = 0

for s in str_list:
    if s == 'AC':
        count_ac = count_ac + 1
    elif s == 'WA':
        count_wa = count_wa + 1
    elif s == 'TLE':
        count_tle = count_tle + 1
    elif s == 'RE':
        coun_re == count_re + 1

print('AC x ' + str(count_ac))
print('WA x ' + str(count_wa))
print('TLE x ' + str(count_tle))
print('RE x ' + str(count_re))


### FIXED CODE ###

N = int(input())
str_list = []
str_list = [str(input()) for i in range(N)]

print('AC x ' + str(str_list.count(('AC'))))
print('WA x ' + str(str_list.count(('WA'))))
print('TLE x ' + str(str_list.count(('TLE'))))
print('RE x ' + str(str_list.count(('RE'))))
N = int(input())
N_list = list(N)
a = 0
for i in range(N):
    if N_list[i]%2==0:
	       a += 1
ave = a/len(N_list)
print(ave)


### FIXED CODE ###

import math
N = int(input())
a=N//2
b=N-a

print(b/N)
n = int(input())
k = int(input())
count = 0
for i in range(n):
    if int(input()) >= k:
        count += 1

print(count)


### FIXED CODE ###

n, k = [int(x) for x in input().split(' ')]
friends = [int(x) for x in input().split(' ')]
count = 0
for friend in friends:
    if friend >= k:
        count += 1
print(count)
import sys, math
from functools import lru_cache
from collections import defaultdict
sys.setrecursionlimit(500000)
MOD = 10**9+7

def input():
    return sys.stdin.readline()[:-1]

def mi():
    return map(int, input().split())

def ii():
    return int(input())

def i2(n):
    tmp = [list(mi()) for i in range(n)]
    return [list(i) for i in zip(*tmp)]

def main():
    N = ii()
    D = list(mi())
    ans = 1

    if D[0] != 0:
        print(0)
        return

    dic = defaultdict(int)
    for i in range(N):
        dic[D[i]] += 1

    for k in dic.keys():
        if k == 0:
            continue
        ans *= pow(dic[k-1], dic[k], 998244353)

    print(ans%998244353)

if __name__ == '__main__':
    main()

### FIXED CODE ###

import sys, math
from functools import lru_cache
from collections import defaultdict
sys.setrecursionlimit(500000)
MOD = 10**9+7

def input():
    return sys.stdin.readline()[:-1]

def mi():
    return map(int, input().split())

def ii():
    return int(input())

def i2(n):
    tmp = [list(mi()) for i in range(n)]
    return [list(i) for i in zip(*tmp)]

def main():
    N = ii()
    D = list(mi())
    ans = 1

    if D[0] != 0:
        print(0)
        return

    dic = defaultdict(int)
    for i in range(N):
        dic[D[i]] += 1

    for i in range(1, N):
        ans *= dic[D[i]-1]
        ans %= 998244353

    print(ans)

if __name__ == '__main__':
    main()
n11, n12, n13 = (input().split())
n21, n22, n23 = (input().split())
n31, n32, n33 = (input().split())
lines = [[n11,n12,n13],
         [n21,n22,n23],
         [n31,n32,n33],
         [n11,n21,n31],
         [n12,n22,n32],
         [n13,n23,n33],
         [n11,n22,n33],
         [n13,n22,n31]]
nums = []
for(i in range(int(input()))):
  nums.append(input())
flag = false
for(l in lines):
  if l[0] in nums:
    if l[1] in nums:
      if l[2] in nums:
        flag = True
if flag:
  print("No")
else:
  print("Yes")

### FIXED CODE ###

import math
s = input()
s = int(s)
s = s/2
s = math.ceil(s)
print(s)
from math import gcd

from math import factorial as f

from math import ceil,floor,sqrt


import bisect
import re
import heapq


from copy import deepcopy
import itertools

from sys import exit

ii = lambda : int(input())
mi = lambda : map(int,input().split())
li = lambda : list(map(int,input().split()))

yes = "Yes"
no = "No"

def main():
    n = ii()
    cnt = 0
    for i in range(1,n+1):
        if not i%2:
            continue
        tmp = 0
        for j in range(1,i+1):
            if not i%j:
                tmp+=1
        if tmp == 8:
            cnt+=1
    print(cnt)


main()




### FIXED CODE ###

#from math import gcd

from math import factorial as f

from math import ceil,floor,sqrt


import bisect
import re
import heapq


from copy import deepcopy
import itertools

from sys import exit

ii = lambda : int(input())
mi = lambda : map(int,input().split())
li = lambda : list(map(int,input().split()))

yes = "Yes"
no = "No"

def main():
    n = ii()
    cnt = 0
    for i in range(1,n+1):
        if not i%2:
            continue
        tmp = 0
        for j in range(1,i+1):
            if not i%j:
                tmp+=1
        if tmp == 8:
            cnt+=1
    print(cnt)


main()
a=list(input())
x=[]
for ai in a:
  if x !=[] and ai="B":
    l=len(x)
    del x[l-1]
  elif ai in ["0","1"]:
    x.append(ai)
print("".join(x))


### FIXED CODE ###

a=list(input())
x=[]
for ai in a:
  if x !=[] and ai=="B":
    x.pop()
  elif ai in ["0","1"]:
    x.append(ai)
print("".join(x))
n = int(input())


if n % 2 == 0:
    print(int(n / 2 * (n - 1)))
else:
    print(int((n - 1) / 2 * n))

### FIXED CODE ###

import math

a, b = map(int, input().split())

print(math.ceil((b - 1) / (a - 1)))
import numpy as np
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline

from numba import njit


def getInputs():
    D = int(readline())
    CS = np.array(read().split(), np.int32)
    C = CS[:26]
    S = CS[26:].reshape((-1, 26))
    return D, C, S


@njit('(i8, i4[:], i4[:, :], i4[:], )', cache=True)
def _compute_score1(D, C, S, out):
    score = 0
    last = np.zeros(26, np.int32)
    for d in range(len(out)):
        i = out[d]
        score += S[d, i]
        last[i] = d + 1
        score -= np.sum(C * (d + 1 - last))
    return last, score


def _update_score():
    pass

@njit('(i8, i4[:], i4[:, :], i4[:], i8, )', cache=True)
def _ramdom_update(D, C, S, out, score):
    d = np.random.randint(D)
    q = np.random.randint(26)
    p = out[d]
    out[d] = q

    last, new_score = _compute_score1(D, C, S, out)
    if score < new_score:
        score = new_score

    return out, last, score



def _random_swap():
    pass


def step1(D, C, S):
    out = []
    LAST = 0
    for d in range(D):
        max_score = -10000000
        best_i = 0
        
        for i in range(26):
            #out[d] = i
            out.append(i)
            last, score = _compute_score1(D, C, S, np.array(out, np.int32))
            if max_score < score:
                max_score = score
                LAST = last
                best_i = i
            out.pop()

        #out[d] = best_i
        out.append(best_i)

    return np.array(out), LAST, max_score


def step2(D, C, S, out, score):
    for _ in range(10 ** 5):
        out.dtype = np.int32
        out, last, score = _ramdom_update(D, C, S, out, score)
    return out, last, score


def output(out):
    out += 1
    print('\n'.join(out.astype(str).tolist()))


D, C, S = getInputs()
out, _, score = step1(D, C, S)
out, _, score = step2(D, C, S, out, score)
output(out)
#print(score)

### FIXED CODE ###

import numpy as np
import sys
read = sys.stdin.read


D = int(input())
CS = np.array(read().split(), np.int32)
C = CS[:26]
S = CS[26:].reshape((-1, 26))
del CS

last = np.zeros((26, ))
ans = []

def getContestType_at_d(d):
    s = -10000000
    for i in range(26):
        tmp = S[d][i] - np.sum(C * (d - last)) + C[i] * (d - last[i])
        if s < tmp:
            s = tmp
            t = i

    last[t] += 1

    return t + 1


for d in range(D):
    ans.append(getContestType_at_d(d))


print('\n'.join(map(str, ans)))
stairs = int(input())
stair_status = list(map(int,input().split(" ")))
down_stairs = []

count = []
for i in range(stairs-2):
    if i == 0:  #最初だけ
        move = 0
        
    if stair_status[i]>=stair_status[i+1]:
        count.append(move+1)
    else:
        count.append(move)
        move = 0  #reset
    
    if len(count)==0:
        pass
    else:
        if max(count)>=stairs-max(count):
            break
    
    move += 1
    
    

    
    

if len(count)==0:
    print(0)

else:

### FIXED CODE ###

stairs = int(input())
stair_status = list(map(int,input().split(" ")))

move = 0
count = [0]
for i in range(stairs-1):
    if stair_status[i]>=stair_status[i+1]:
        move += 1
        count.append(move)
    else:
        count.append(move)
        move = 0  #reset
    
else:
    print(max(count))
N,M = map(int,input().split())

P = []
Y = []

for i in range(M):
    p,y = map(int,input().split())
    P.append(p)
    Y.append(y)

A = [0]*M
C = [0]*M

B = [0]*M
for i in range(M):
    B[i] = (Y[i]-1)*100000+i

B.sort()

for i in range(M):
    d = B[i] % 100000
    b = B[i] // 100000
    k = P[d] - 1

    C[d] = A[k]
    A[k] += 1

for i in range(M):
    print('%06d%06d' % (P[i],C[i]+1))


### FIXED CODE ###

N,M = map(int,input().split())

P = [0]*M
Y = [0]*M

for i in range(M):
    P[i],Y[i] = map(int,input().split())

A = [0]*N
C = [0]*M

B = [0]*M
for i in range(M):
    B[i] = Y[i]*100000+i

B.sort()

for i in range(M):
    d = B[i] % 100000
    k = P[d] - 1

    C[d] = A[k]
    A[k] += 1

for i in range(M):
    print('%06d%06d' % (P[i],C[i]+1))
N,A,B=map(int,input().split())
ballb=[]
ballr=[]
ballb.append('b')
ballb2=ballb*A
ballr.append('r')
ballr2=ballr*B
ball=(ballb2+ballr2)*N
count=0
for i in range(N):
    if ball[i]=='b':
        count += 1
print(count)

### FIXED CODE ###

N,A,B=map(int,input().split())
a=N//(A+B)*A
c=N%(A+B)
b=min(A,c)
print(a+b)
N,X,T  = map(int, input().split())
a = N // X
if N % X ==0:
  pritn(a*T)
else:
	print((a+1)*T)

### FIXED CODE ###

N,X,T  = map(int, input().split())
a = N // X
if N % X ==0:
  print(a*T)
else:
	print((a+1)*T)
n, k = map(int, input().split())
hl = [int(input()) for _ in range(n)]
delta = 10*10**9

hl_s = sorted(hl, reverse=True)

if n > 10000:
    if hl_s[n//2] > (hl_s[0] + hl_s[n])//2: #中央値＞平均値
        hl_s = hl_s[:n//2]
    else:
        hl_s = hl_s[n//2:]

for i in range(len(hl_s)-k+1):
    h_max = max(hl_s[i:i+k])
    h_min = min(hl_s[i:i+k])
    if delta > (h_max - h_min):
        delta = h_max - h_min
    if delta == 0:
        break

print(delta)


### FIXED CODE ###

n, k = map(int, input().split())
hl = [int(input()) for _ in range(n)]
hl.sort()

h_min = min(hl[i+k-1] - hl[i] for i in range(n-k+1))
print(h_min)
n = int(input())
p = list(map(int, input().split()))
j = 1
count = 0

for i in range(0,n):
    if p[j] >= p[i]:
        print(p[j-1])
        count += 1

print(count)

### FIXED CODE ###

n = int(input())
p = list(map(int, input().split()))
count = 0
min = p[0]

for i in range(n):
    if min >= p[i]:
        count += 1
        min = p[i]

print(count)
Q = int(input())

while Q:
    Q -= 1
    from math import sqrt
    A, B = map(int, input().split())
    M = max(A, B)
    for i in range(min(A, B), max(A, B)):
        if i ** 2 >= A * B:
            break
        else:
            last = i
    ans = 2 * last
    if last >= min(A, B):
        ans -= 1
    if last * (last + 1) >= A * B:
        ans -= 1
    print(ans)


### FIXED CODE ###

Q = int(input())

while Q:
    Q -= 1
    A, B = map(int, input().split())
    M = max(A, B)
    m = min(A, B)
    if M == m:
        print(2 * m - 2)
        continue
    if M == m + 1:
        print(2 * m - 2)
        continue
    last = int((M * m) ** 0.5)
    if last == (M * m) ** 0.5:
        last -= 1
    if last * (last + 1) >= M * m:
        print(last * 2 - 2)
    else:
        print(last * 2 - 1)
S = input()
d = {"SUN": 7, "MON":6, "TUE":5, "WED":4, "THR":3, "FRI":2, "SAT":1}
print(d[S])

### FIXED CODE ###

S = input()

d = {"SUN": 7, "MON":6, "TUE":5, "WED":4, "THU":3, "FRI":2, "SAT":1}
print(d[S])
A=int(input())
B=int(input())
ans=(A-1+B-1-1)//(A-1)
print(ans)


### FIXED CODE ###

A,B=map(int,input().split())
if B==1:
    ans=0
elif 1<B and B<=A:
    ans=1
else :
    for k in range(2,100):
        if (k-1)*A-(k-2)<B and B<=k*A-(k-1):
            ans=k
        else:
            k=k+1
print(ans)
def get_path(start, goal, prev):
    path = []
    now = goal
    path.append(now)
    while True:
        path.append(prev[now])
        if prev[now] == start: break
        now = prev[now]
    path.reverse()
    return path

def search(glaph, start, goal):
    MAX_VAL = 0x10000000
    g_size = len(glaph)
    visited = [False] * g_size
    cost = [MAX_VAL] * g_size
    prev = [None] * g_size
    cost[start] = 0
    prev[start] = start
    now = start
    while True:
        min = MAX_VAL
        next = -1
        visited[now] = True
        for i in range(g_size):
            if visited[i]: continue
            if glaph[now][i]:
                tmp_cost = glaph[now][i] + cost[now]
                if cost[i] > tmp_cost:
                    cost[i] = tmp_cost
                    prev[i] = now
            if min > cost[i]:
                min = cost[i]
                next = i
        if next == -1: break
        now = next
    return [get_path(start, goal, prev), cost[goal]]

N = int(input())
route = [[0 for i in range(N)] for j in range(N)]
for i in range(N - 1):
    a, b, d = map(int, input().split())
    route[a-1][b-1] = d
    route[b-1][a-1] = d
Q, K = map(int, input().split())

for i in range(Q):
    x, y = map(int, input().split())
    x, y = x - 1, y - 1
    path, cost1 = search(route, x, K - 1)
    path, cost2 = search(route, K - 1, y)
    cost = cost1 + cost2
    print(cost)


### FIXED CODE ###

N = int(input())
route = [{} for _ in range(N)]
dist = [-1] * N
for i in range(N - 1):
    a, b, d = map(int, input().split())
    route[a-1][b-1] = d
    route[b-1][a-1] = d

Q, K = map(int, input().split())
dist[K-1] = 0
dfs_stack = [K-1]
while dfs_stack:
    s = dfs_stack.pop()
    for t, t_dist in route[s].items():
        if dist[t] == -1:
            dist[t] = dist[s] + t_dist
            dfs_stack.append(t)
for i in range(Q):
    x, y = map(int, input().split())
    x, y = x - 1, y - 1
    print(dist[x] + dist[y])
from statistics import *
while True:
    n = int(input())
    if(n == 0): break
    elif(n == 1):
        print("%.10f" %0)
    elif(n > 1):
        data = list(map(int,input().split()))
        print(stdev(data))


### FIXED CODE ###

from math import *
while True:
    n = int(input())
    if(n == 0 ): break
    data = list(map(int,input().split()))  
    a = sum(data) / n
    b = 0
    c = 0
    for i in data:
        b += pow(i-a,2)
    c = sqrt(b/n)
    
    print(c)
import math

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

def xorsum(m):
  if m==3:
    return 0
  if m==2:
    return 3
  if m==1:
    return 1
  if m==0:
    return 0
  h = 2 ** math.floor(math.log2(m))
  return xorsum(m-h)^(((m-h+1)%2)*h)

print(xorsum(B)^xorsum(A-1))

  
  

### FIXED CODE ###

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

def xorsum(m):
  if m==3:
    return 0
  if m==2:
    return 3
  if m==1:
    return 1
  if m==0:
    return 0
  if m==-1:
    return 0
  h=1
  while h<=m:
    h=h*2
  h=h//2
  return xorsum(m-h)^(((m-h+1)%2)*h)

print(xorsum(B)^xorsum(A-1))
import collections
s = [int(c) for c in input()]
tmp = 1
prev = mod
count = collections.defaultdict(int)
for i,num in enumerate(s[::-1]):
    mod = (tmp * num + mod) % 2019
    count[mod] += 1
    tmp *= 10
print(sum((item*(item-1)//2 for item in count.values())))

### FIXED CODE ###

import sys
input = lambda : sys.stdin.readline().rstrip()

import collections
s = [int(c) for c in input()]
tmp = 1
mod = 0
count = collections.defaultdict(int)
for i,num in enumerate(s[::-1]):
    mod = (tmp * num + mod) % 2019
    count[mod] += 1
    tmp *= 10
    tmp %= 2019
count[0] += 1
print(sum((item*(item-1)//2 for item in count.values())))
n=int(input())
X=[]
Y=[]
A=[]
for i in range(n):
  A[i]=int(input())
  x=[]
  y=[]
  for j in range(A[i]):
    x,y=[int(s) for s in input().split()]
  X.append(x)
  Y.append(y)
  
c=0
for i in range(n):
  l=[1]*n
  for j in range(i, n-i):
    if l[j]==0:continue
    for k in range(A[j]):
    　　l[X[j][k]] *= Y[j][k]
if c<l.count(1):
  c=l.count(1) 
  
        
  
print(c)  
   

### FIXED CODE ###

n=int(input())
X=[]
Y=[]
A=[0]*n
for i in range(n):
  A[i]=int(input())
  a=A[i]
  x=[0]*a
  y=[0]*a
  for j in range(a):
    x[j],y[j]=[int(s) for s in input().split()]
  X.append(x)
  Y.append(y)
  
s=0
for i in range(2**n):
  c=0
  d=0
  B=[0]*n
  for j in range(n):
    if((i >> j) & 1):
      c=c+1
      B[j]=1
  for k in range(n):
    if B[k]==1:
      for j in range(A[k]):
        if Y[k][j]!=B[X[k][j]-1]:
          d=-1
          break
    if d<0:
      break
  if s<c and d==0:
    s=c
      
      
print(s)