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

#problem D
input_d41 = int(input())
input_d42 = input()

N = int(input_d41)
S = input_d42

R = S.count('R')
G = S.count('G')
B = N - (R + G)

ans = 0
answ = 0

for i in range(0,N):
    for j in range(i+1,N):
        if S[i] != S[j] and 2*j-i < N:
            if S[j] != S[2*j-i] and S[2*j-i] != S[i]:
                answ += 1
            
ans = R*G*B - answ

print(ans)

### FIXED CODE ###

#problem D
input_d41 = int(input())
input_d42 = input()

N = int(input_d41)
S = input_d42

R = S.count('R')
G = S.count('G')
B = N - (R + G)

ans = R*G*B
answ = 0

for i in range(0,N):
    for j in range(i+1,(N+i)//2 +1):
        if S[i] != S[j]:
            if 2*j-i < N and S[j] != S[2*j-i] and S[2*j-i] != S[i]:
                ans -= 1
print(ans)
### BUGGY CODE ###

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


for i in range(N):
  a = A.copy()
  a[i] = 0
  c = collections.Counter(a)
  c = c.items()


  ans = 0
  for m,n in c:
    
    ans += n*(n-1)/2
  print(int(ans))



### FIXED CODE ###

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

c = collections.Counter(A)
cc = c.items()

f_ans = 0
for m,n in cc:
  f_ans += n*(n-1)/2

for i in range(N):
  a = A[i]
  b = c[a]
  sa = b*(b-1)/2 - (b-1)*(b-2)/2

  print(int(f_ans - sa))
### BUGGY CODE ###

n, k = map(int, input().split())

while True:
    if abs(n - k) < n:
        n = abs(n - k)
    else:
        break

print(n)

### FIXED CODE ###

n, k = map(int, input().split())

a = n % k
print(min(a, abs(a - k)))
### BUGGY CODE ###

#16:38
import sys
input = sys.stdin.readline
n,m = map(int,input().split())
raw = [[] for _ in range(n)]
root = [1 for _ in range(n)]
for _ in range(n-1+m):
  a,b = map(int,input().split())
  a -= 1
  b -= 1
  raw[a].append(b)
  root[b] = 0
for i in range(n):
  if root[i] == 1:
    r = i
    break
pre = [-1 for _ in range(n)]
now = [r]
while now:
  last = now
  now = []
  for x in last:
    for y in raw[x]:
      pre[y] = x
      now.append(y)
print('\n'.join(map(lambda x: str(x+1) ,pre)))

### FIXED CODE ###

#16:38
n,m = map(int,input().split())
raw = [[] for _ in range(n)]
precnt = [0 for _ in range(n)]
root = [1 for _ in range(n)]
for _ in range(n-1+m):
  a,b = map(int,input().split())
  a -= 1
  b -= 1
  raw[a].append(b)
  precnt[b] += 1
  root[b] = 0
for i in range(n):
  if root[i] == 1:
    r = i
    break
pre = [-1 for _ in range(n)]
now = [r]
#print(precnt)
while now:
  last = now
  now = []
  for x in last:
    for y in raw[x]:
      precnt[y] -= 1
      if precnt[y] == 0:
        now.append(y)
      pre[y] = x
#print(pre)
#print(precnt)
for x in pre:
  print(x+1)
### BUGGY CODE ###

def binary_search(dic, word, imin, imax):
    if imax < imin:
        return "no"
    imid = imin + (imax - imin) // 2
    if dic[imid] > word:
        return binary_search(dic, word, imin, imid - 1)
    elif dic[imid] < word:
        return binary_search(dic, word, imid + 1, imax)
    else:
        return "yes"


n = int(input())
dictionary = []

for _ in range(n):
    cmd, arg = input().split()
    if cmd == "insert":
        dictionary.append(arg)
        dictionary.sort()
    elif cmd == "find":
        print(binary_search(dictionary, arg, 0, len(dictionary) - 1))

### FIXED CODE ###

n = int(input())
dictionary = set()

for _ in range(n):
    cmd, arg = input().split()
    if cmd == "insert":
        dictionary.add(arg)
    elif cmd == "find":
        if arg in dictionary:
            print("yes")
        else:
            print("no")
### BUGGY CODE ###

n, a = map(int, input().split())
x = list(map(int, input().split()))

x = sorted(x)

ans = 0
for i in range(n):
    x[i] -= a
    if x[i] == 0:
        ans += 1

if x[0] >= 0 or x[n - 1] <= 0:
    print(2 ** ans - 1)
    exit()

ans = 0

def adder(temp_sum, i):
    if i >= n:
        return
    else:
        if temp_sum + x[i] == 0:
            global ans
            ans += 1
        adder(temp_sum, i + 1)
        adder(temp_sum + x[i], i + 1)

adder(0,0)

print(ans)


### FIXED CODE ###

n, a = map(int, input().split())
x = list(map(int, input().split()))

max_x = max(x)
dp = [[0 for _  in range(n * 2 * max_x + 1)] for _ in range(n + 1)]

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

print(dp[n][n * max_x] - 1)
### BUGGY CODE ###

import math
def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

N=int(input())
strings=[list(str(input())) for a in range(N)]
sorteds=[]
for thing in strings:
    thing.sort()
    sorteds.append("".join(thing))
sorteds.sort()
sums=0
for st in list(set(sorteds)):
    n=sorteds.count(st)
    if n!=1:
       sums=sums+combinations_count(n,2)

print(sums)



### FIXED CODE ###

import math
import collections
def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

N=int(input())
strings=[str(sorted(input())) for a in range(N)]
c=collections.Counter(strings)
tp=c.most_common()
sums=0
for thing in tp:
    if thing[1]!=1:
        sums=sums+combinations_count(thing[1],2)
    else:break

print(sums)
### BUGGY CODE ###

n,k=map(int,input().split())
a=[]
i=0
while len(a)==0 or a[-1]!=1:
    a.append((k-1)//(2**i))
    i+=1
n1=len(a)
if n>=k:
    s=(n-k+1)/n
    for i in range(n1):
        if i!=n1-1:
            s+=(a[i]-a[i+1])/(n*(2**(i+1)))
        else:
            s+=a[i]/(n*(2**(i+1)))
else:
    s=0
    for i in range(n1):
        if i!=n1-1 and a[i]>=n>a[i+1]:
            s+=(n-a[i+1])/(n*(2**(i+1)))
        elif i!=n1-1 and n>a[i+1]:
            s+=(a[i]-a[i+1])/(n*(2**(i+1)))
        elif n>=a[i]:
            s+=a[i]/(n*(2**(i+1)))
print(s)

### FIXED CODE ###

n,k=map(int,input().split())
a=[]
i=0
if k>1:
    while len(a)==0 or a[-1]!=1:
        a.append((k-1)//(2**i))
        i+=1
else:
    a.append(0)
n1=len(a)
if n>=k:
    s=(n-k+1)/n
    for i in range(n1):
        if i!=n1-1:
            s+=(a[i]-a[i+1])/(n*(2**(i+1)))
        else:
            s+=a[i]/(n*(2**(i+1)))
else:
    s=0
    for i in range(n1):
        if i!=n1-1 and a[i]>=n>a[i+1]:
            s+=(n-a[i+1])/(n*(2**(i+1)))
        elif i!=n1-1 and n>a[i+1]:
            s+=(a[i]-a[i+1])/(n*(2**(i+1)))
        elif n>=a[i]:
            s+=a[i]/(n*(2**(i+1)))
print(s)
### BUGGY CODE ###

n=int(input())
a=[0]+list(map(int, input().split()))

ans=[a[1]]

if n%2==0:
    for i in range(2, n+1):
        if i%2==0:
            ans=[a[i]]+ans
        else:
            ans=ans+[a[i]]

else:
    for i in range(2, n+1):
        if i%2==0:
            ans=ans+[a[i]]
        else:
            ans=[a[i]]+ans

print(*ans)

### FIXED CODE ###

from collections import deque

n=int(input())
a=[0]+list(map(int, input().split()))

b=deque()

for i in range(1, n+1):
    if n%2==i%2:
        b.appendleft(a[i])
    else:
        b.append(a[i])

ans=[]

for elem in b:
    ans.append(elem)

print(*ans)
### BUGGY CODE ###

from collections import deque
import math
N,M=map(int,input().split())
"""
BFSする。探索される側をメモ。
"""
dist = [-1 for i in range(N)]
graph = [[] for i in range(N)]
for i in range(M):
  A,B=map(int,input().split())
  graph[A-1].append(B)
  graph[B-1].append(A)
  
#print(dist, graph)

# init
ans = [0]*N
dist = [-1]*N
nodes_ = deque()
q = deque()
q.append(1)
change = False
while len(q)>0:
  #print(q,dist)
  node = q.popleft()
  if node is None:
    break
  elif -1 not in dist:
    break
  if node not in dist:
    dist[node-1] = 0
    if node != 1:
      ans[node-1] = nodes_.popleft()
    #for i in graph[node-1]:
    #  if i not in dist:
    q_ = q
    add = 0
    for j in graph[node-1]:
      if dist[j-1] == -1 and (j not in q):
        q.append(j)
        add+=1
    judge_index = add
    # q.extend(graph[node-1])
  for i in range(add):
    nodes_.append(node)
print("Yes")
print("\n".join(list(map(str,ans[1:]))))

### FIXED CODE ###

from collections import deque
import math
N,M=map(int,input().split())
"""
BFSする。探索される側をメモ。
"""
dist = [-1 for i in range(N)]
graph = [[] for i in range(N+1)]
for i in range(M):
  A,B=map(int,input().split())
  graph[A].append(B)
  graph[B].append(A)
  
#print(dist, graph)

# init
ans = [-1]*(N+1)
q = deque()
q.append(1)
while len(q)>0:
  #print(q,dist)
  node = q.popleft()
  for j in graph[node]:
    if ans[j] == -1:
      ans[j]=node
      q.append(j)
print("Yes")
print("\n".join(list(map(str,ans[2:]))))
### BUGGY CODE ###

import collections
n = int(input())
a = list(map(int, input().split()))

c = collections.Counter(a)

nc=[-1]*(n+1)
def nConb(n):
  if nc[n] != -1:
    return nc[n]
  nc[n]=n*(n-1)//2
  return nc[n]
  
for i in range(n):
  temp=0
  for k,v in c.items():
    if k == a[i]:
      temp+=nConb(v-1)
    else:
      temp+=nConb(v)
  print(temp)

### FIXED CODE ###

import collections
n = int(input())
a = list(map(int, input().split()))

c = collections.Counter(a)

nc=[-1]*(n+1)
def nConb(n):
  if nc[n] != -1:
    return nc[n]
  nc[n]=n*(n-1)//2
  return nc[n]

temp=0
for k,v in c.items():
  temp+=nConb(v)

for i in range(n):
  if c[a[i]] == 1:
    print(temp)
  else:
    print(temp-(c[a[i]]-1))
### BUGGY CODE ###

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

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

max_cnt = 0
for a in range(len(A)+1):
    for b in range(len(B)+1):
        time = sum(A[:a]) + sum(B[:b])
        if time <= K:
            cnt = a + b
            if cnt > max_cnt:
                max_cnt = cnt
print(max_cnt)


### FIXED CODE ###

N, M, K = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))

A = [0]
B = [0]
for i in range(len(a)):
    A.append(A[i] + a[i])
for i in range(len(b)):
    B.append(B[i] + b[i])

ans = 0
j = len(B) - 1
for i in range(len(A)):
    if A[i] > K:
        break
    while A[i] + B[j] > K:
        j -= 1
    ans = max(ans, i + j)
print(ans)
### BUGGY CODE ###

from fractions import gcd


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


def lcm(x, y):
        return (x*y) // gcd(x, y)


lcm_value = A[0]
for i in range(1, N):
    lcm_value = lcm(lcm_value, A[i])

# print(lcm_value)
mod = 10**9+7
ans = 0
for i in range(N):
    ans += (lcm_value // A[i]) % mod

print(ans%mod)


### FIXED CODE ###

def gcd(m, n):
    while n:
        m, n = n, m % n
    return m


def lcm(x, y):
        return (x*y) // gcd(x, y)


N = int(input())
A = list(map(int, input().split()))
A.sort()
lcm_value = A[0]
for i in range(1, N):
    lcm_value = lcm(lcm_value, A[i])

# print(lcm_value)
mod = 10**9+7
ans = 0
for i in range(N):
    ans += (lcm_value // A[i])

print(ans % mod)
### BUGGY CODE ###

n,q = map(int,input().split()) 
a = list(input())
pos_AC = list()

for i in range(n-1):
     if (a[i] == "A") and (a[i+1] == "C"):
          pos_AC.append(i)

for i in range(q):
     s,e = map(int,input().split())
     count = 0
     for j in pos_AC:
          if (s-1 <= j) and (j < e-1):
               count += 1
     print(count)

### FIXED CODE ###

n,q = map(int,input().split()) 
a = list(input())
dp = [0]*n
cou_AC = 0

for i in range(n-1):
     if (a[i] == "A") and (a[i+1] == "C"):
          cou_AC += 1
     dp[i+1] = cou_AC

for i in range(q):
     s,e = map(int,input().split())
     s,e = s-1,e-1
     ans = dp[e]-dp[s]
     print(ans)
### BUGGY CODE ###

a, b = map(int, input().split())
num_list = list(map(int, input().split()))
k_sum = 0.0
for j in range(a - b + 1):
    k_list = num_list[j:j+b]
    k_sum = max(k_sum, sum(k_list))

out = (k_sum + b) / 2
print(out)

### FIXED CODE ###

a, b = map(int, input().split())
num_list = list(map(int, input().split()))
k_sum = sum(num_list[0:b])
max_sum = k_sum
for i, j in zip(num_list[0:], num_list[b:]):
    k_sum -= i
    k_sum += j
    max_sum = max(max_sum, k_sum)
out = (max_sum + b) / 2
print(out)
### BUGGY CODE ###

n,m,k=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
A=[0]
B=[0]


for i in range(1,len(a)+1):
    A.append(a[i-1]+A[i-1])

for i in range(1,len(b)+1):
    B.append(b[i-1]+B[i-1])
    

maxman=0
for i in range(len(A)):
    for j in range(len(B)):
        if A[i]+B[j]<=k:
            maxman=max(maxman,i+j)
            
print(maxman)

### FIXED CODE ###

N, M, K=map(int,input().split())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
a, b=[0], [0]
for i in range(N):
    a.append(a[i]+A[i])
for i in range(M):
    b.append(b[i]+B[i])
ans, j=0, M
for i in range(N+1):
    if a[i]>K:
        break
    while b[j]>K-a[i]:
        j-=1
    ans=max(ans, i+j)
print(ans)
### BUGGY CODE ###

s = input()
q = int(input())
rev = False
for i in range(q):
  inp = input()
  if int(inp[0]) == 1:
    rev = not rev
  else:
    t, f, c = inp.split()
    if (int(f) == 1 and rev) or (int(f) == 2 and not rev):
      s += c
    else:
      s = c + s
print(s[::-1] if rev else s)


### FIXED CODE ###

s = input()
q = int(input())
rev = False
pre = ''
for i in range(q):
  inp = input()
  if int(inp[0]) == 1:
    rev = not rev
  else:
    t, f, c = inp.split()
    if (int(f) == 1 and rev) or (int(f) == 2 and not rev):
      s += c
    else:
      pre += c
print(s[::-1] + pre if rev else pre[::-1] + s)
### BUGGY CODE ###

N,A,B=map(int,input().split())
total=(10 ** 100) + 1

for i in range(total):
  if N <= i*A + i*B :
    if N >= i*A + (i-1)*B :
      ans=i*A
      break
    else :
      ans=i*A - (i*A+(i-1)*B - N)
      break
print(ans)

### FIXED CODE ###

import math

N,A,B=map(int,input().split())
total=(10 ** 100) + 1

firstCnt=math.floor(N/(A+B))

for i in range(firstCnt,total):
  if N <= i*A + i*B :
    if N >= i*A + (i-1)*B :
      ans=i*A
      break
    else :
      ans=i*A - (i*A+(i-1)*B - N)
      break
print(ans)
### BUGGY CODE ###

def examD():
    from operator import mul
    from functools import reduce
    def comb2(n, r):
        r = min(n - r, r)
        if r == 0: return 1
        over = reduce(mul, range(n, n - r, -1))
        under = reduce(mul, range(1, r + 1))
        return over // under

    H, W, A, B =LI()
    k = W-B
    ans = int(0)
    C1 = [0]*k; C2 = [0]*k
    for i in range(k):
        C1[i] = comb2(H-A+B+i-1,H-A-1)%mod
        C2[i] = comb2(A+W-(B+i)-2,A-1)%mod
        ans = (ans+C1[i]*C2[i])%mod
    print(ans)
#    print(C1)
#    print(C2)


import sys
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
mod = 10**9 + 7
inf = float('inf')

examD()


### FIXED CODE ###

def examD(mod):
    class combination():
        def __init__(self, n, mod):
            self.n = n
            self.fac = [1] * (n + 1)
            self.inv = [1] * (n + 1)
            for j in range(1, n + 1):
                self.fac[j] = self.fac[j - 1] * j % mod

            self.inv[n] = pow(self.fac[n], mod - 2, mod)
            for j in range(n - 1, -1, -1):
                self.inv[j] = self.inv[j + 1] * (j + 1) % mod

        def comb(self, n, r, mod):
            if r > n or n < 0 or r < 0:
                return 0
            return self.fac[n] * self.inv[n - r] * self.inv[r] % mod

    H, W, A, B =LI()
    N = H + W
    C = combination(N,mod)
    ans = C.comb(W+H-B-2, H-1,mod)
    pre = 1
    for i in range(1, H-A):
        ans += (C.comb(B+i,i,mod)-pre)*C.comb(W+H-B-2-i, H-1-i,mod)%mod
        ans %= mod
        pre = C.comb(B+i, i,mod)
    print(ans)

import sys
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def S(): return sys.stdin.readline().strip()
mod = 10**9 + 7
inf = float('inf')

examD(mod)
### BUGGY CODE ###

#python3

def main():
    h, w = map(int, input().split())
    ss = []
    for _ in range(h):
        s = input()
        ss.append(s)

    sumv = [[0 for _ in range(w)] for _ in range(h)]
    #横方向について連続で何マス続くかを求める
    for i in range(h):
        #doneは連続何マス続くかをすでに求めたかどうかを保持するリスト　
        done = [0 for _ in range(w)]
        for j in range(w):
            #i,jはぞれぞれ縦と横のマスの位置を表すインデックス
            if ss[i][j] == '#':
                continue
            if done[j] == 1:
                continue
            #seqは横に何マス続くかを記録する変数
            seq = 0
            while j + seq < w:
                if ss[i][j+seq] == '#':
                    break
                seq = seq + 1
            #ss[i][j]からss[i][j+seq]までのマスは連続してseqマスである
            for k in range(seq):
                sumv[i][j+k] += seq
                #連続するマスが求め終わったマスを記録する
                done[j+k] = 1
    
    #縦方向について同様に
    for j in range(w):
        done = [0 for _ in range(h)]
        for i in range(h):
            if ss[i][j] == '#':
                continue
            if done[i] == 1:
                continue
            seq = 0
            while i + seq < h:
                if ss[i+seq][j] == '#':
                    break
                seq = seq + 1
            for k in range(seq):
                sumv[i+k][j] += seq
                done[i+k] = 1

    ans = 0
    for i in range(h):
        for j in range(w):
            ans = max(ans, sumv[i][j]-1)            
    print(ans)
main()




### FIXED CODE ###

import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
import numpy as np 
import itertools as it
def main():
    H, W = map(int, readline().split())
    G = np.zeros((H+2, W+2), np.int16)
    G[1:-1, 1:] = (np.frombuffer(read(H*(W+1)), dtype='B') == ord('.')).reshape((H, W+1))
    def solve(G):
        left = np.zeros(G.shape, np.int16)
        for i in range(G.shape[0]):
            left[i, ] = np.arange(G.shape[1])
        left[G>0] = 0
        np.maximum.accumulate(left, out=left, axis=1)

        rG = G[..., ::-1]
        right = np.zeros(G.shape, np.int16)
        for i in range(G.shape[0]): 
            right[i, ] = np.arange(G.shape[1])
        right[rG>0] = 0
        np.maximum.accumulate(right, out=right, axis=1)

        right = G.shape[1] - right[..., ::-1]-1
        scoreres = (right-left-1) 
        scoreres[G==0] = 0
        return scoreres

    print((solve(G)+solve(G.T).T-1).max())
if __name__ == '__main__':
    main()
### BUGGY CODE ###

# WIP
N, K = map(int, input().split())
hhh = list(map(int, input().split()))

dp = [0] * N
dp[0] = 0

for i in range(1, N):
    if i < K:
        dp[i] = \
            min([abs(hhh[i] - hhh[i-k]) + dp[i-k] for k in range(1, i+1)])
    else:
        dp[i] = \
            min([abs(hhh[i] - hhh[i-k]) + dp[i-k] for k in range(1, K+1)])

print(dp[-1])


### FIXED CODE ###

# WIP
N, K = map(int, input().split())
hhh = list(map(int, input().split()))

dp = [0] * N
dp[0] = 0

for i in range(1, N):
    if i < K:
        dp[i] = \
            min([abs(hhh[i] - hhh[i-k]) + dp[i-k] for k in range(1, i+1)])
    else:
        dp[i] = \
            min([abs(hhh[i] - hhh[i-k]) + dp[i-k] for k in range(1, K+1)])

print(dp[-1])
### BUGGY CODE ###

a = int(input())
b = list(map(int, input().split()))
b.sort()
r = 0
for i in range(a-2):
    for j in range(i+1, a-1):
        for k in range(j+1, a):
            if b[k] >= b[i] + b[j]:
                break
            r += 1
print(r)


### FIXED CODE ###

def binsearch(l, r, fn, i, j):
    while r - l > 1:
        m = (l + r) // 2
        if fn(m, i, j):
            l = m
        else:
            r = m
    return l

def main():
    N = int(input())
    L = list(map(int, input().split()))
    L.sort()
    def fn(m, i, j):
        a = L[m]
        b = L[i]
        c = L[j]
        if a < b + c and b < c + a and c < a + b:
            return True
        return False
    r = 0
    for i in range(N-2):
        for j in range(i+1, N-1):
            if fn(j+1, i, j):
                r += binsearch(j+1, N, fn, i, j) - j
    return r
print(main())
### BUGGY CODE ###

INF = 2**60 # 無限大を表す値
def main():
    H, N = map(int, input().split())
    AB = [map(int, input().split()) for i in range(N)]
    dp = [INF] * (H + 1)
    dp[0] = 0
    for (A, B) in AB:
        for j in range(H+1):
            dp[j] = min(dp[j], dp[max(j-A, 0)] + B)
    print(dp[H])
main()

### FIXED CODE ###

INF = 2**60 # 無限大を表す値
H, N = map(int, input().split())
AB = [map(int, input().split()) for i in range(N)]
dp = [INF] * (H + 1)
dp[0] = 0
for A, B in AB:
    for j in range(H+1):
        dp[j] = min(dp[j], dp[max(j-A, 0)] + B)
print(dp[H])
### BUGGY CODE ###

import numpy as np
#import math
#from decimal import *
#from numba import njit

#@njit
def main():
    (N, M) = map(int, input().split())
    neighbor = {}
    for _ in range(M):
        (A,B) = map(int, input().split())
        na = neighbor.get(A, [])
        nb = neighbor.get(B, [])
        neighbor.update({A:(na+[B])})
        neighbor.update({B:(nb+[A])})

    guide = {1:1}

    # 1の部屋から幅優先で道しるべを置く
    
    # 探索候補
    target = [1]
    checked = [1]
    while len(target) > 0:
        # 候補の先頭から取る
        n = target.pop(0)
        # nから伸びる行き先
        dests = neighbor.get(n, [])
        # すでに道しるべがあるものは除く
        dests = filter(lambda d: not d in checked, dests)
        # 道しるべを置く
        for d in dests:
            guide.update({d:n})
            checked += d,
            # 探索候補の末尾に追加
            target += d,

    if set(range(1,N+1)) <= set(guide.keys()):
        print('Yes')
        for i in range(2,N+1):
            print(guide[i])
    else:
        print('No')

main()


### FIXED CODE ###

#import numpy as np
#import math
#from decimal import *
#from numba import njit

#@njit
def main():
    (N, M) = map(int, input().split())
    neighbor = [[] for _ in range(N+1)]
    for _ in range(M):
        (A,B) = map(int, input().split())
        neighbor[A] += B,
        neighbor[B] += A,

    guide = [0 for _ in range(N+1)]

    # 1の部屋から幅優先で道しるべを置く
    
    # 探索候補
    target = [1]
    checked = [1]
    while len(target) > 0:
        # 候補の先頭から取る
        n = target.pop(0)
        # nから伸びる行き先
        dests = neighbor[n]
        # すでに道しるべがあるものは除く
        dests = filter(lambda d: guide[d] == 0, dests)
        # 道しるべを置く
        for d in dests:
            guide[d] = n
            checked += d,
            # 探索候補の末尾に追加
            target += d,

    print('Yes')
    for i in range(2,N+1):
        print(guide[i])

main()
### BUGGY CODE ###

n,m,k=[int(x) for x in input().rstrip().split()]
a=[int(x) for x in input().rstrip().split()]
b=[int(x) for x in input().rstrip().split()]

A=[0]
B=[0]

for i in range(n):
  A.append(A[i]+a[i])

for i in range(m):
  B.append(B[i]+b[i])

ans=0
j=m

for i in range(n+1):
  j=m
  if A[i]>k:
    break
  nokori=k-A[i]

  while(nokori<B[j] and 0<=j):
    j-=1

    
  ans=max(ans,i+j)
print(ans)


### FIXED CODE ###

n,m,k=[int(x) for x in input().rstrip().split()]
a=[int(x) for x in input().rstrip().split()]
b=[int(x) for x in input().rstrip().split()]

A=[0]
B=[0]

for i in range(n):
  A.append(A[i]+a[i])

for i in range(m):
  B.append(B[i]+b[i])

ans=0
j=m

for i in range(n+1):
  # j=m
  if A[i]>k:
    break
  nokori=k-A[i]

  while(nokori<B[j] and 0<=j):
    j-=1

    
  ans=max(ans,i+j)
print(ans)
### BUGGY CODE ###

ab=[]

n,m = map(int,input().split())

for i in range(m):
    ab.append(tuple(map(int,input().split())))

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

res=0
toremove=set()
while(1):
    for j in range(len(ab)):
        if ab[0][1] > ab[j][0]:
            toremove.add(ab[j])
        #else:break
    if len(toremove)>0:
        for r in toremove:
            ab.remove(r)
        toremove=set()
        res+=1
    if len(ab) == 0:break

print(res)

### FIXED CODE ###

ab=[]

n,m = map(int,input().split())

for i in range(m):
    ab.append(tuple(map(int,input().split())))

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

res=0
for z in range(len(ab)):
    x=ab[0][1]
    for j in range(len(ab)):
        if x > ab[0][0]:
            del ab[0]
        else:
            res+=1
            break
    if len(ab)==0:
        res+=1
        break
    
print(res)
### BUGGY CODE ###

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

ans = 1e+19

while True:
    N = abs(N-K)
    if N >= ans:
        break
    ans = N

print(ans)

### FIXED CODE ###

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

ans = min(N%K, K-(N%K))

print(ans)