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

from collections import Counter
from functools import reduce
import fractions
import math
import statistics
import sys
import time
sys.setrecursionlimit(10**7)
INF = 10 ** 18
MOD = 10 ** 9 + 7
def LI(): return [int(x) for x in sys.stdin.readline().split()]  # LIST INT
def LF(): return [float(x) for x in sys.stdin.readline().split()]  # LIST FLOAT
def LS(): return sys.stdin.readline().split()  # LIST STRING
def MI(): return map(int, sys.stdin.readline().split())  # MAP INT
def II(): return int(sys.stdin.readline())  # INPUT INT
def IS(): return input()  # INPUT STRING
def P(x): return print(x)
def C(x): return Counter(x)
def GCD_LIST(numbers):  # greatest common divisor
    return reduce(fractions.gcd, numbers)
def LCM_LIST(numbers):  # least common multiple
    return reduce(LCM, numbers)
def LCM(m, n):
    return (m * n // fractions.gcd(m, n))


n, k = MI()
dp = [INF] * n
h = LI()
dp[0] = 0
for i in range(0, n-1):
    for j in range(1, k+1):
        if n <= i+j:
            continue
        dp[i+j] = min(dp[i] + abs(h[i]-h[i+j]), dp[i+j])
P(dp[n-1])


### FIXED CODE ###

from collections import Counter
from functools import reduce
import fractions
import math
import sys
import time
sys.setrecursionlimit(10**7)
INF = 10 ** 18
MOD = 10 ** 9 + 7
def LI(): return [int(x) for x in sys.stdin.readline().split()]  # LIST INT
def LF(): return [float(x) for x in sys.stdin.readline().split()]  # LIST FLOAT
def LS(): return sys.stdin.readline().split()  # LIST STRING
def MI(): return map(int, sys.stdin.readline().split())  # MAP INT
def II(): return int(sys.stdin.readline())  # INPUT INT
def IS(): return input()  # INPUT STRING
def P(x): return print(x)
def C(x): return Counter(x)
def GCD_LIST(numbers):  # greatest common divisor
    return reduce(fractions.gcd, numbers)
def LCM_LIST(numbers):  # least common multiple
    return reduce(LCM, numbers)
def LCM(m, n):
    return (m * n // fractions.gcd(m, n))


n, k = MI()
dp = [INF] * n
h = LI()
dp[0] = 0
for i in range(0, n-1):
    for j in range(1, k+1):
        if n <= i+j:
            continue
        dp[i+j] = min(dp[i] + abs(h[i]-h[i+j]), dp[i+j])
P(dp[n-1])
### BUGGY CODE ###

n,m=map(int,input().split())
a=[int(input()) for i in range(m)]
dp=[0]*(n+1)
dp[0]=1
for i in range(1,n+1):
    dp[i]=(dp[i-1]+dp[i-2])%(10**9+7)
    if i in a:dp[i]=0
print(dp[n])

### FIXED CODE ###


n,m=map(int,input().split())
a=set([int(input()) for i in range(m)])
dp=[0]*(n+1)
dp[0]=1
for i in range(1,n+1):
    dp[i]=(dp[i-1]+dp[i-2])%(10**9+7)
    if i in a:dp[i]=0
print(dp[n])
### BUGGY CODE ###

import sys
import bisect
input = sys.stdin.readline

def main():
    n=int(input())
    h = list(map(int,input().split()))

    ans="Yes"

    for i in range(n-1):
        b=h[0]
        h.pop(0)
        if(b>=min(h)+2):
            ans="No"
        if(ans=="No"):
            break
        
    print(ans)
    
main()

### FIXED CODE ###

import sys
import bisect
input = sys.stdin.readline

def main():
    n=int(input())
    h = list(map(int,input().split()))

    ans="Yes"
    m=0

    for i in range(n):
        if(m>=h[i]+2):
            ans="No"
        else:
            m=max(m,h[i])
        if(ans=="No"):
            break
        
    print(ans)
    
main()
### BUGGY CODE ###

N = int(input())
arr = [None]*N
visited = [False]*N
UVW = []
for i in range(N-1):
    u, v, w = map(int, input().split())
    if i==0:
        arr[u-1] = 0
        visited[u-1] = True
    if visited[u-1]:
        arr[v-1] = arr[u-1] + w
        visited[v-1] = True
    elif visited[v-1]:
        arr[u-1] = arr[v-1] + w
        visited[u-1] = True
    else:
        UVW.append([u,v,w])

while len(UVW)>0:
    u,v,w = UVW.pop(0)
    if visited[u-1]:
        arr[v-1] = arr[u-1] + w
        visited[v-1] = True
    elif visited[v-1]:
        arr[u-1] = arr[v-1] + w
        visited[u-1] = True
    else:
        UVW.append([u,v,w])
    

for a in arr:
    if a%2==0:
        print(0)
    else:
        print(1)

### FIXED CODE ###

N = int(input())

q = []
visited = [0] * N
ans = [0] * N
A = [[] for _ in range(N)]  # tree
W = [[] for _ in range(N)]  # weight

for i in range(N-1):
    u,v,w = map(int, input().split())
    u -= 1
    v -= 1
    A[u].append(v)
    A[v].append(u)
    W[u].append(w)
    W[v].append(w)

q.append(0)  # start
for _ in range(N):
    u = q.pop(0)
    visited[u] = 1
    k = 0
    for v in A[u]:
        if visited[v]==0:
            q.append(v)
            ans[v] = ans[u] + W[u][k]
        k += 1

for a in ans:
    print(a%2)
### BUGGY CODE ###

import numpy as np
a, b, x = map(int, input().split())
count = np.array([num for num in range(a, b+1) if num % x == 0], dtype=np.float32)
print(len(count))

### FIXED CODE ###

from sys import stdin
a, b, x = [int(x) for x in stdin.readline().rstrip().split()]
print((b//x) - (a-1)//x)
### BUGGY CODE ###

import sys
sys.setrecursionlimit(10**9)

INF = 10**20
def main():
    N,K = map(int,input().split())
    A=list(map(int,input().split()))
    F=list(map(int,input().split()))

    A.sort()
    F.sort(reverse=True)

    B=[]
    for i in range(N):
        B.append((A[i]*F[i],F[i]))

    B.sort(reverse=True)
    k = K
    # print(B)
    while k > 0:
        i = 0
        while i < len(B) and B[i][0] == 0:
            i += 1
        if not i < len(B):
            break
        B[i] = (B[i][0]-B[i][1],B[i][1])
        k -= 1
        B.sort(reverse=True)

    print(max(B)[0])
    # print(B)



if __name__ == "__main__":
  main()


### FIXED CODE ###

import sys
sys.setrecursionlimit(10**9)

INF = 10**20
def main():
    N,K = map(int,input().split())
    A=list(map(int,input().split()))
    F=list(map(int,input().split()))

    A.sort()
    F.sort(reverse=True)

    def c(s): # sに対して単調減少
        sum_x = 0
        for i in range(N):
            a,f=A[i],F[i]
            tp = s//f
            if not a <= tp:
                sum_x += a-tp

        return sum_x <= K

    l=-1
    r=10**20
    while r-l>1:
        mid = (l+r)//2
        if c(mid):
            r = mid
        else:
            l = mid

    print(r)

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

import sys
import heapq
n, m = map(int, sys.stdin.readline().split())
A = list(map(lambda x:-int(x), sys.stdin.readline().split()))
heapq.heapify(A)

for j in range(m):
    A[0] = int(A[0]/2)
    heapq.heapify(A)

print(-sum(A))

### FIXED CODE ###

import sys
import heapq
n, m = map(int, sys.stdin.readline().split())
A = list(map(lambda x:-int(x), sys.stdin.readline().split()))
heapq.heapify(A)

for j in range(m):
    heapq.heappush(A ,int(A[0]/2))
    heapq.heappop(A)

print(-sum(A))
### BUGGY CODE ###

h,w = map(int,input().split())
lis = [str(input()) for i in range(h)]
ans = 0
for sx in range(h):
    for sy in range(w):
        if lis[sx][sy] == "#":
            num = [[0] * w for i in range(h)]
            now = {(sx,sy,1)}
            for _ in range(1600):
                tmp = set()
                for x,y,iro in now:
                    if x > 0:
                        if lis[x-1][y] != lis[x][y] and num[x-1][y] == 0:
                            ans += iro
                            tmp.add((x-1,y,(iro+1)%2))
                            num[x-1][y] = 1
                    if x < h-1:
                        if lis[x+1][y] != lis[x][y] and num[x+1][y] == 0:
                            ans += iro
                            tmp.add((x+1,y,(iro+1)%2))
                            num[x+1][y] = 1
                    if y > 0:
                        if lis[x][y-1] != lis[x][y] and num[x][y-1] == 0:
                            ans += iro
                            tmp.add((x,y-1,(iro+1)%2))
                            num[x][y-1] = 1
                    if y < w-1:
                        if lis[x][y+1] != lis[x][y] and num[x][y+1] == 0:
                            ans += iro
                            tmp.add((x,y+1,(iro+1)%2))
                            num[x][y+1] = 1
                now = tmp

print(ans)

### FIXED CODE ###

import sys
sys.setrecursionlimit(100000)

dxdy = {(-1, 0), (1, 0), (0, -1), (0, 1)}

h,w = map(int,input().split())
s = [str(input()) for i in range(h)]

ch = [[0] * w for i in range(h)]

ans = 0

for i in range(h):
    for j in range(w):
        if ch[i][j] == 0:
            black,white = 0,0
            q = [(i,j)]
            while q:
                y,x = q.pop()
                if ch[y][x] == 0:
                    if s[y][x] == "#":black += 1
                    else:white += 1
                    ch[y][x] = 1
                    for dx,dy in dxdy:
                        if 0 <= x + dx < w and 0 <= y + dy < h and ch[y+dy][x+dx] == 0 and s[y+dy][x+dx] != s[y][x]:
                            q.append((y+dy,x+dx))
            ans += black * white

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

from fractions import gcd
# def GCD(a: int, b: int) -> int:
#     return a if b == 0 else GCD(b, a % b)


class SegTree():
    def __init__(self, n_, ele_id, operation_func):
        self.n = 1
        while self.n < n_:
            self.n *= 2
        self.data = [ele_id] * (2 * self.n - 1)
        self.ele_id = ele_id
        self.operation_func = operation_func

    def __getitem__(self, idx):
        return self.data[idx + self.n - 1]

    def init(self, data_init):
        for i in range(len(data_init)):
            self.data[i + self.n - 1] = data_init[i]
        for i in range(self.n - 2, -1, -1):
            self.data[i] = self.operation_func(self.data[2 * i + 1],
                                               self.data[2 * i + 2])

    def update(self, idx, x):
        # idx番目の要素をxに更新する
        idx += self.n - 1
        self.data[idx] = x
        while idx > 0:
            idx = (idx - 1) // 2
            self.data[idx] = self.operation_func(self.data[2 * idx + 1],
                                                 self.data[2 * idx + 2])

    def query(self, a, b):
        return self.query_(a, b, 0, 0, self.n)

    def query_(self, a, b, k, l, r):
        # [a, b)の最小値を求める
        if r <= a or b <= l:
            # [a, b)が[l, r)と交差しない
            return self.ele_id

        if a <= l and r <= b:
            # [a, b)が[l, r)を完全に含む
            return self.data[k]
        else:
            # [a, b)と[l, r)は一部被る
            child_l = self.query_(a, b, 2 * k + 1, l, (l + r) // 2)
            child_r = self.query_(a, b, 2 * k + 2, (l + r) // 2, r)
            return self.operation_func(child_l, child_r)


n = int(input())
a = list(map(int, input().split()))
seg_gcd = SegTree(n, 0, gcd)
seg_gcd.init(a)

ans = seg_gcd.data[0]
for i in range(n):
    # seg_gcd.update(i, 0)
    # ans = max(ans, seg_gcd.data[0])
    # seg_gcd.update(i, a[i])
    ans = max(ans, gcd(seg_gcd.query(0, i), seg_gcd.query(i + 1, n)))

print(ans)


### FIXED CODE ###

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

def GCD(a: int, b: int) -> int:
    return a if b == 0 else GCD(b, a % b)

l = [0]
r = [0]
for i in range(n):
    l.append(GCD(l[i], a[i]))
    r.append(GCD(r[i], a[n-1 - i]))
r = r[::-1]

ans = 1
for i in range(n):
    ans = max(ans, GCD(l[i], r[i+1]))

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

N,Q = map(int,input().split())
S = input()
for _ in range(Q):
  l,r  = map(int,input().split())
  print(S[l-1:r].count("AC"))

### FIXED CODE ###

import sys
N,Q = map(int,sys.stdin.readline().rstrip().split())
S = sys.stdin.readline().rstrip()
D = [0]
DD = 0
for i in range(1,len(S)):
  if S[i-1] + S[i] == "AC":
    DD += 1
  D.append(DD)
for _ in range(Q):
  l,r  = map(int,sys.stdin.readline().rstrip().split())
  print(D[r-1]- D[l-1])
  del l
  del r
### BUGGY CODE ###

import sys
sys.setrecursionlimit(200000)
 
n = int(input())
 
h = [int(i) for i in input().split()]
 
def dp(cost, p):
  if p == n-1:
    return cost
  if p < n-2:
    return min(dp(cost+abs(h[p]-h[p+1]), p+1), dp(cost+abs(h[p]-h[p+2]), p+2))
  if p == n-2:
    return dp(cost+abs(h[p]-h[p+1]), p+1)

print(dp(0, 0))

### FIXED CODE ###

import sys
sys.setrecursionlimit(200000)
 
n = int(input())
 
h = [int(i) for i in input().split()]
 
d = {}
 
def dp(p):
  if p in d:
    return d[p]
  if p == n-1:
    return 0
  if p < n-2:
    m = min(dp(p+1)+abs(h[p]-h[p+1]), dp(p+2)+abs(h[p]-h[p+2]))
    d[p] = m
    return m
  if p == n-2:
    return dp(p+1)+abs(h[p]-h[p+1])

print(dp(0))
### BUGGY CODE ###

def solve():
    global S, N
    N = int(input())

    S = []
    for n in range(N):
        S.append(list(input()))


    res = 0
    for n in range(N):
        if check(n):
            res += N

    print(res)

def check(move):
    for i in range(N):
        for j in range(i+1, N):
            if S[(i-move)%N][j] != S[(j-move)%N][i]:
                return False
    return True


if __name__ == "__main__":
    solve()

### FIXED CODE ###

def solve():
    global S, N
    N = int(input())

    S = []
    for n in range(N):
        S.append(list(input()))


    res = 0
    for n in range(N):
        if check(n):
            res += N

    print(res)

def check(move):
    for i in range(N):
        for j in range(i+1, N):
            if S[(i-move)%N][j] != S[(j-move)%N][i]:
                return False
    return True


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

def main():
    n, m = map(int, input().split())
    As = [int(input()) for _ in range(m)]

    dp = [0] * (n + 1)
    dp[0] = 1
    if 1 not in As:
        dp[1] = 1
    else:
        dp[1] = 0

    for i in range(2, n+1):
        if i in As:
            continue
        dp[i] = dp[i-1] + dp[i-2]

    ans = dp[-1] % 1000000007
    print(ans)


if __name__ == "__main__":
    main()


### FIXED CODE ###

def main():
    n, m = map(int, input().split())
    As = set([int(input()) for _ in range(m)])
    mod = 1000000007

    dp = [0] * (n + 1)
    dp[0] = 1
    if 1 not in As:
        dp[1] = 1

    for i in range(2, n+1):
        if i in As:
            continue
        dp[i] = dp[i-1] + dp[i-2]

    ans = dp[n] % mod
    print(ans)


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

import numpy as np 
import collections

n = int(input())
a = tuple(map(int, input().split()))

for i in range(n):
    _a = np.delete(a, i)
    c_dict = collections.Counter(_a)
    total = 0
    for v in c_dict.values():
        if v >= 2:
            total += v * (v - 1) / 2
            
    print(int(total))

### FIXED CODE ###

import collections

def solve(N, A):
    c_dict = collections.Counter(A)
    originals = [0 for i in range(N + 1)]
    minus = [0 for i in range(N + 1)]
    
    for (k, v) in c_dict.items():
        originals[k] = v * (v - 1) // 2
        minus[k] = ((v * (v - 1)) - (v - 1) * (v - 2)) // 2
        
    total = sum(originals)
    
    ans = []
    for a in A:
        ans.append(str(total - minus[a]))
    return '\n'.join(ans)
    
if __name__ == '__main__':
    N = int(input())
    A = list(map(int, input().split()))
    print(solve(N, A))
### BUGGY CODE ###

h, n = map(int, input().split())
a = []
b = []
for _ in range(n):
  ai, bi = map(int, input().split())
  a.append(ai)
  b.append(bi)
dp = [0] * (h+1)
for c in range(1, h+1):
  dp[c] = min([dp[max(0, c-a[i])] + b[i] for i in range(n)])
print(dp[-1])

### FIXED CODE ###

h, n = map(int, input().split())
dp = [[0] * (h+1) for i in range(n)]
a, b = map(int, input().split())
for c in range(1, h+1):
  dp[0][c] = b * ((c-1) // a + 1)
for i in range(1, n):
  a, b = map(int, input().split())
  for c in range(1, h+1):
    opt1 = dp[i-1][c]
    opt2 = dp[i-1][max(0, c-a)] + b
    opt3 = dp[i][max(0, c-a)] + b
    dp[i][c] = min(opt1, opt2, opt3)
print(dp[-1][-1])
### BUGGY CODE ###

n = int(input())
h_list = input().split()

ans = True
for i in range(len(h_list)):
    for j in range( i, len(h_list)):
        if int(h_list[i]) - int(h_list[j]) >= 2:
            print()
            ans = False
            break
if ans:
    print("Yes")
else:
    print("No")

### FIXED CODE ###

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

ans = True
for i in range(1, len(h_list) ):
    if h_list[-i] - h_list[-i-1] >= 0:
        continue
    elif h_list[-i] - h_list[-i-1] == -1:
        h_list[-i-1] -= 1
    else:
        ans = False
        break
if ans:
    print("Yes")
else:
    print("No")
### BUGGY CODE ###

from sys import stdin

N, Q = [int(x) for x in stdin.readline().rstrip().split()]
S = stdin.readline().rstrip()
lr_list = [list(map(int, stdin.readline().rstrip().split())) for _ in range(Q)]


for l, r in lr_list:
    S2 = S[l-1:r]
    count = 0
    #print(S2)
    flg = False
    for i in range(len(S2)):
        if S2[i] != "A":
            continue
        try:
            if S2[i+1] == "C":
                count += 1
        except:
            pass
    print(count)
        

### FIXED CODE ###

from sys import stdin
from collections import deque

N, Q = [int(x) for x in stdin.readline().rstrip().split()]
S = stdin.readline().rstrip()
lr_list = [list(map(int, stdin.readline().rstrip().split())) for _ in range(Q)]

#result_list = []
count = 0

result_list = deque([])

for i in range(N):
    result_list.append(count)
    if S[i] != "A":
        continue
    try:
        if S[i+1] == "C":
            count += 1
    except:
       pass

for l, r in lr_list:
    print(result_list[r-1] - result_list[l-1])
### BUGGY CODE ###

import sys
input = sys.stdin.readline
n, q = map(int, input().split())
tree = [[0] * n for _ in range(n)]
counter = [0] * n
for i in range(n - 1):
    a, b = map(int, input().split())
    tree[a - 1][b - 1] = 1
for i in range(n - 1, 0, -1):
    for j in range(n):
        if tree[i - 1][j] == 1:
            tree[i - 1] = [x + y for x, y in zip(tree[i - 1], tree[j])]
for i in range(q):
    p, x = map(int, input().split())
    counter[p - 1] += x
    for j in range(n):
        counter[j] += x * tree[p - 1][j]
print(*counter)

### FIXED CODE ###

from collections import deque
import sys
input = sys.stdin.readline
n, q = map(int, input().split())
tree = [[] for i in range(n)]
counter = [0] * n
visited = [False] * n
for i in range(n - 1):
    a, b = map(int, input().split())
    tree[a - 1].append(b - 1)
    # tree[b - 1].append(a - 1)
for i in range(q):
    p, x = map(int, input().split())
    counter[p - 1] += x
queue = deque([0])
visited[0] = True
while queue:
    now = queue.pop()
    for j in tree[now]:
        if visited[j]:
            continue
        counter[j] += counter[now]
        visited[j] = True
        queue.append(j)
print(*counter)
### BUGGY CODE ###

N = int(input())
l = list(map(int,input().split()))
l.sort(reverse=True)
ans = 0
for i in range(N - 2):
    for j in range(i + 1,N - 1):
        for k in range(j + 1, N ):
            if l[i] < l[j] + l[k]:
                ans += 1
print(ans)

### FIXED CODE ###

import bisect
N = int(input())
l = list(map(int,input().split()))
l.sort()
#print(l)


ans = 0
for i in range(N - 1 , 1, -1):
    for j in range(i - 1 , 0 , -1):
        #work = l[:j]
        x = l[i] - l[j]
        #idx = bisect.bisect_right(work, x)
        idx = bisect.bisect_right(l, x)
        ans += max(j - idx , 0)
print(ans)
### BUGGY CODE ###

import sys
input = sys.stdin.readline


def main():
    N, K = map(int, input().split())
    pn = list(map(int, input().split()))

    a = 0
    for i in range(N-K+1):
        p = pn[i:i+K]
        a = max(a, sum(p))

    ans = (a+K)/2
    print(ans)

if __name__ == '__main__':
    main()

### FIXED CODE ###

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

pn_t = [0]
for i in range(N):
    pn_t.append(pn[i]+pn_t[i])

l = 0
for i in range(N-K+1):
    l = max(l, pn_t[K+i]-pn_t[i])
ans = (l+K)/2
print(ans)
### BUGGY CODE ###

N,Q = map(int,input().split())
S = list(input())
LR = [list(map(int,input().split())) for _ in range(Q)]
lis = []
s = [0]*N
for i in range(N-1):
    if S[i] == "A" and S[i+1] == "C":
        s[i] = 1
L = [0]*(N+1)

R = [0]*N

tmp = 0
for i in range(0,N):
    if s[i] == 1:
        tmp += 1
    L[i+1] += tmp
tmp = 0
for i in range(N-2,-2,-1):
    if s[i] == 1:
        tmp += 1
    R[i+1] += tmp
R += [0]
for i in range(Q):
    ans = sum(s)-L[LR[i][0]-1]-R[LR[i][1]]
    print(ans)

### FIXED CODE ###

import sys
input = sys.stdin.readline
N,Q = map(int,input().split())
S = list(input())
LR = [list(map(int,input().split())) for _ in range(Q)]
lis = []
s = [0]*N
for i in range(N-1):
    if S[i] == "A" and S[i+1] == "C":
        s[i] = 1

L = [0]*(N+1)
R = [0]*N

tmp = 0
for ind,i in enumerate(s):
    if i == 1:
        tmp += 1
    L[ind+1] = tmp

tmp = 0
for i in range(N-2,-2,-1):
    if s[i] == 1:
        tmp += 1
    R[i+1] = tmp

R.append(0)
sums =sum(s)
for i in range(Q):
    ans = sums-L[LR[i][0]-1]-R[LR[i][1]]
    print(ans)
### BUGGY CODE ###

N,M=list(map(int,input().split()))
road_list=[]
for i in range(M):
  road_list.append(list(map(int,input().split())))
ans_dict=dict([])
before_room=[1]
while True:
  temp_room=[]
  for j in range(len(before_room)):
    temp_delete=[]
    for i in road_list:
      #print(road_list)
      #print("before_room=",before_room,j)
      if i[0]==before_room[j]:
        if i[1] not in ans_dict:
          ans_dict[i[1]]=before_room[j]
          temp_room.append(i[1])
        #road_list.remove(i)
        temp_delete.append(i)
      if i[1]==before_room[j]:
        if i[0] not in ans_dict:
          ans_dict[i[0]]=before_room[j]
          temp_room.append(i[0])
        #road_list.remove(i)
        temp_delete.append(i)
    for temp in temp_delete:
      road_list.remove(temp)
  before_room=temp_room
    #if len(ans_dict)==N-1:
    #  break
  if len(ans_dict)==N-1:
    break
#print(ans_dict)
if len(ans_dict)==N-1:
  print("Yes")
  for i in range(len(ans_dict)):
    print(ans_dict[i+2])
else:
  print("No")

### FIXED CODE ###

from collections import deque

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

g = [[] for _ in range(N+1)] # 隣接リスト

for _ in range(M):
    a, b = [int(x) for x in input().split()]
    #print(a,b,g)
    g[a].append(b)
    g[b].append(a)

#road_list=[]
#for i in range(M):
#  road_list.append(list(map(int,input().split())))

queue = deque([1])
d = [None] * (N+1) # uからの距離の初期化
d[1] = 0 # 自分との距離は0
while queue:
  v = queue.popleft()
  for i in g[v]:
    if d[i] is None:
      d[i] = v
      queue.append(i)

#print(d)


#ans_dict=dict([])
#before_room=[1]
#while True:
#  temp_room=[]
#  for j in range(len(before_room)):
#    for i in road_list:
#      if i[0]==before_room[j]:
#        if i[1] not in ans_dict:
#          ans_dict[i[1]]=before_room[j]
#          temp_room.append(i[1])
#      if i[1]==before_room[j]:
#        if i[0] not in ans_dict:
#          ans_dict[i[0]]=before_room[j]
#          temp_room.append(i[0])
#  before_room=temp_room
#  if len(ans_dict)==N:
#    break
    
d[0]=0
if None in d:
  print("No")
else:
  print("Yes")
  for i in range(2,N+1):
    print(d[i])
### BUGGY CODE ###

n = int(input())
s = input()
pin = []
for i in range(n-2):
  for j in range(i+1,n-1):
    for k in range(j+1,n):
      pin.append(s[i]+s[j]+s[k])
pin = list(set(pin))
print(len(pin))

### FIXED CODE ###

n = int(input())
s = input()
ans = 0

for i in range(1000): #0~999を全探索
  flg1 = False #1桁目があるか
  flg2 = False #2桁目があるか
  flg3 = False #3桁目があるか
  one = str(i//100) #1桁目
  two = str(i%100//10) #2桁目
  three = str(i%10) #3桁目
  t = 0
  
  for j in range(n-2):
    if s[j] == one:
      flg1 = True
      t = j+1
      break
  for j in range(t,n-1):
    if s[j] == two:
      flg2 = True
      t = j+1
      break
  for j in range(t,n):
    if s[j] == three:
      flg3 = True
      t = j+1
      break
  if flg1 and flg2 and flg3:
    ans += 1
print(ans)