Harryxun/stf_run huggingface dataset:
from collections import deque

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

INF = float("inf")

dist = deque(X)

next_x = +1
i = 0
ans = 0
while len(dist) != 1:

    if A*abs(dist[i+next_x] - dist[i]) <= B:
        ans += A*abs(dist[i+next_x] - dist[i])
        if next_x == 1:
            dist.popleft()
            i = 0
        else:
            dist.pop()
            i = len(dist)
    else:
        ans += B
        if next_x == 1:
            dist.popleft()
            i = len(dist)-1
        else:
            dist.pop()
            i = 0
        
        next_x = -next_x
        
print(ans)

### FIXED CODE ###

from collections import deque

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

INF = float("inf")

dist = deque(X)

next_x = +1
i = 0
ans = 0
while len(dist) != 1:

    if A*abs(dist[i+next_x] - dist[i]) <= B:
        ans += A*abs(dist[i+next_x] - dist[i])
        if next_x == 1:
            dist.popleft()
            i = 0
        else:
            dist.pop()
            i = len(dist)-1
    else:
        ans += B
        if next_x == 1:
            dist.popleft()
            i = len(dist)-1
        else:
            dist.pop()
            i = 0
        
        next_x = -next_x
        
print(ans)
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(0, D)
    q = np.random.randint(0, 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.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.append(best_i)

    return np.array(out), LAST, max_score


def step2(D, C, S, out, score):
    for _ in range(10 ** 4):
        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)))
"""
102 C
"""

import math

def read_input():
    n = int(input())
    alist = list(map(int, input().split()))

    return n, alist


def sum_abs(alist, b):
    return sum([abs(a - b) for a in alist])


def submit():
    n, alist = read_input()

    alist = [a - (i + 1) for i, a in enumerate(alist)]
    alist.sort()

    if n % 2:
        b_min, b_max = alist[n // 2], alist[n // 2 + 1]
        print(min(sum_abs(alist, b_min), sum_abs(alist, b_max)))
    else:
        print(sum_abs(alist, alist[n // 2]))


if __name__ == "__main__":
    submit()

### FIXED CODE ###

"""
102 C
"""

import math

def read_input():
    n = int(input())
    alist = list(map(int, input().split()))

    return n, alist


def sum_abs(alist, b):
    return sum([abs(a - b) for a in alist])


def submit():
    n, alist = read_input()

    alist = [a - (i + 1) for i, a in enumerate(alist)]
    alist.sort()

    if n % 2 == 0:
        b_min, b_max = alist[n // 2], alist[n // 2 + 1]
        print(min(sum_abs(alist, b_min), sum_abs(alist, b_max)))
    else:
        print(sum_abs(alist, alist[n // 2]))


if __name__ == "__main__":
    submit()
a=int(input())
b=int(input())
print(a*b)

### FIXED CODE ###

n=input().split()
a=int(n[0])
b=int(n[1])
ans=a*b
print(ans)
a=int(print())
b=int(print())
c=int(print())
d=int(print())
e=int(print())
k=int(print())

x=[a,b,c,d,e]
y=max(x)-min(x)

if y>k:
  print(':(')
if y<=k:
  print('Yay!')


### FIXED CODE ###

a=[int(input()) for i in range(5)]
k=int(input())
x=max(a)-min(a)
if x<=k:
  print('Yay!')
else:
  print(':(')
n = int(input())
s = [input() for _ in range(n)]


def func(x):
    ret = []
    for i in range(len(x)):
        if len(ret) == 0:
            ret.append(x[i])
        else:
            if ret[-1] == '(' and x[i] == ')':
                ret.pop()
            else:
                ret.append(x[i])
    l = r = 0
    for i in range(len(ret)):
        if ret[i] == '(':
            l += 1
        else:
            r += 1
    return (r, l)  # ) (


t = []
for i in range(n):
    r, l = func(s[i])
    # print((r, l), '<-', s[i])
    if r + l == 0:
        continue
    t.append((r, l))
t.sort()
# print(*t, sep='\n')

is_possible = True
r, l = t[0]
if r != 0:
    is_possible = False
else:
    for i in range(1, len(t)):
        r_i, l_i = t[i]
        if r_i <= l:
            l -= r_i
            l += l_i
        else:
            is_possible = False
    if l != 0:
        is_possible = False

ans = 'Yes' if is_possible else 'No'
print(ans)


### FIXED CODE ###

n = int(input())
s = [input() for _ in range(n)]


def bracket(x):
    # f: final sum of brackets '(':+1, ')': -1
    # m: min value of f
    f = m = 0
    for i in range(len(x)):
        if x[i] == '(':
            f += 1
        else:
            f -= 1
        m = min(m, f)
    # m <= 0
    return f, m


def func(l):
    # l = [(f, m)]
    l.sort(key=lambda x: -x[1])
    v = 0
    for fi, mi in l:
        if v + mi >= 0:
            v += fi
        else:
            return -1
    return v


l1 = []
l2 = []
for i in range(n):
    fi, mi = bracket(s[i])
    if fi >= 0:
        l1.append((fi, mi))
    else:
        l2.append((-fi, mi - fi))

v1 = func(l1)
v2 = func(l2)
if v1 == -1 or v2 == -1:
    ans = 'No'
else:
    ans = 'Yes' if v1 == v2 else 'No'

print(ans)
s = input()

while len(s)>4:
    if s[-5:] == 'dream':
        s = s[:-5]
        continue
    elif s[-7:] == 'dreamer':
        s = s[:-7]
        continue
    elif s[-5:] == 'erase':
        s = s[:-5]
        continue
    elif s[-6:] == 'eraser':
        s = s[:-6]
        continue
    else:
        beak
if s =='' :
    print('YES')
else:
    print('NO')
    




### FIXED CODE ###

s = input()

while len(s)>4:
    if s[-5:] == 'dream':
        s = s[:-5]
        continue
    elif s[-7:] == 'dreamer':
        s = s[:-7]
        continue
    elif s[-5:] == 'erase':
        s = s[:-5]
        continue
    elif s[-6:] == 'eraser':
        s = s[:-6]
        continue
    else:
        break
if len(s)>0 :
    print('NO')
else:
    print('YES')
a,b,n=map(int,input().split())
C = sorted(set([a:min(a+n,b)])|set([max(a,b-n):b]))
for i in C:
  print(i)

### FIXED CODE ###

a,b,k=map(int,input().split())
if b-a+1>k*2:
  for i in range(a,a+k):
    print(i)
  for j in range(b-k+1,b+1):
    print(j)
else:
  for h in range(a,b+1):
    print(h)
from bisect import bisect_right
from bisect import bisect_left

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

if x[n-1]<0 :
    t=x[-k]
    print(t)
elif x[n-1]==0 :
    t=x[-k+1]
    print(t)

elif x[0]>0:
    t=x[k-1]
    print(t)
elif x[0]==0:
    t=x[k-1-1]
    print(t)

else:
    iz=bisect_left(x,0)
    if x[iz+1]==0:
        for i in range(iz+2,min(iz+k,k)):
            kt=i
            t=x[kt]*2-x[kt-k+1]
#        print("1",kt,kt-k+1,t,x[kt],x[kt-k+1])
            if t<tmin:
                tmin=t
        for i in range(max(iz+2-k,0),iz):
            kt=i
            t=-x[kt]*2+x[kt+k-1]
#        print("2",kt,kt+k-1,t,x[kt],x[kt+k-1])
            if t<tmin:
                tmin=t
    else:
        tmin=10**9
        for i in range(iz+1,min(iz+k,k)):
            kt=i
            t=x[kt]*2-x[kt-k+1]
#        print("1",kt,kt-k+1,t,x[kt],x[kt-k+1])
            if t<tmin:
                tmin=t
        for i in range(max(iz+2-k,0),iz):
            kt=i
            t=-x[kt]*2+x[kt+k-1]
#        print("2",kt,kt+k-1,t,x[kt],x[kt+k-1])
            if t<tmin:
                tmin=t
    print(tmin)
    

### FIXED CODE ###

from bisect import bisect_right
from bisect import bisect_left

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

#n=100000
#k=100000
x=list(map(int,input().split()))

if x[n-1]<0 :
    t=-x[-k]
#    print(1)
    print(t)
elif x[n-1]==0 :
    t=-x[-k+1]
#    print(2)
    print(t)

elif x[0]>0:
    t=x[k-1]
#    print(3)
    print(t)
elif x[0]==0:
    t=x[k-1-1]
#    print(4)
    print(t)

else:
    iz=bisect_left(x,0)
    if x[iz+1]==0:
        k=k-1
        tmin=10**9
#        print((iz-(k-1)+1),iz,n-1-(k-1))
        for i in range(max(0,iz-(k-1)+1),min(iz,n-1-(k-1)+1)):
            kt=i
            t1=-x[kt]+x[kt+(k-1)]*2
            t2=-x[kt]*2+x[kt+(k-1)]
#        print("2",kt,kt+k-1,t,x[kt],x[kt+k-1])
#            print(tmin,t1,t2)
            if t1<tmin:
                tmin=t1
            if t2<tmin:
                tmin=t2
    else:
        tmin=10**9
#        print((iz-(k-1)+1),iz,n-1-(k-1))
        for i in range(max(0,iz-(k-1)+1),min(iz,n-1-(k-1)+1)):
            kt=i
            t1=-x[kt]+x[kt+(k-1)]*2
            t2=-x[kt]*2+x[kt+(k-1)]
#        print("2",kt,kt+k-1,t,x[kt],x[kt+k-1])
#            print(tmin,t1,t2)
            if t1<tmin:
                tmin=t1
            if t2<tmin:
                tmin=t2
    print(tmin)
    
#  299993628 
# 1000000000        
#   99990701
n= int(input())
s = input()
al='ABCDEFGHIJKLMNOPQRSTUVXXYZ'
print(''.join([al[-len(al)+al.index(i)+n] for i in s]))

### FIXED CODE ###

n= int(input())
s = input()
al='ABCDEFGHIJKLMNOPQRSTUVWXYZ'
print(''.join([al[-len(al)+al.index(i)+n] for i in s]))
s=input()

Sunny, Cloudy, Rainy

if s=="Sunny":
  a="Cloudy"
elif s=="Cloudy":
  a="Rainy"
else:
  a="Sunny"
print(a)


### FIXED CODE ###

s=input()
 
if s=="Sunny":
  a="Cloudy"
elif s=="Cloudy":
  a="Rainy"
else:
  a="Sunny"
print(a)
import math
import collections

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

c = collections.Counter(a)

for d in c:
    ans_total += int(math.factorial(c[d])/(2*math.factorial(c[d]-2)))

for i in range(n):
    print(ans_total-c[a[i]]+1)

### FIXED CODE ###

import math
import collections

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

c = collections.Counter(a)

for d in c:
    if not c[d] == 1:
        ans_total += int(math.factorial(c[d])/(2*math.factorial(c[d]-2)))

for i in range(n):
    print(ans_total-c[a[i]]+1)
from collections import Counter
# counter（l）.most_common()：リストについて出現回の多い順に（要素、要素数）で返す
a=int(input())
A=list(map(int,input().split()))
bx=[A[i] for i in range(a) if i%2==0]
cx=[A[i] for i in range(a) if i%2==1]
#　全部同じ数の時
if b==c and len(set(b))==1 and len(set(c))==1:
    print(a//2)
else:
    bc=Counter(b).most_common()
    cc=Counter(c).most_common()
    if bc[0][0]==cc[0][0]:
        print(a-max(bc[1][1]+cc[0][1],bc[0][1]+cc[1][1]))
    else: print(a-bc[0][1]-cc[0][1])    

### FIXED CODE ###

from collections import Counter
a=int(input())
A=list(map(int,input().split()))
b=[A[i] for i in range(a) if i%2==0]
c=[A[i] for i in range(a) if i%2==1]
if b==c and len(set(b))==1 and len(set(c))==1:
    print(a//2)
else:
    bc=Counter(b).most_common()
    cc=Counter(c).most_common()
    if bc[0][0]==cc[0][0]:
        print(a-max(bc[1][1]+cc[0][1],bc[0][1]+cc[1][1]))
    else: print(a-bc[0][1]-cc[0][1])
# coding: utf-8
from sys import stdin
import sys, math
import numpy as np

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

def main():
    a,b,c,d = [int(x) for x in stdin.readline().rstrip().split()]
    #print(a, b, c, d)
    #bまでで3で割り切れる数
    three_all = b // c
    #a-1までで3で割り切れる数
    three_less = (a-1) // c
    three_range = three_all - three_less
    
    two_all = b // d
    two_less = (a-1) // d
    two_range = two_all - two_less
    
    z = lcm(c,d)
    six_all = b // z
    six_less = (a-1) // z
    six_range = six_all - six_less
    
    num = three_range + two_range - six_range
    
    ans = b-a+1-num
    print(ans)

if __name__ == '__main__':
    main()

    




### FIXED CODE ###

# coding: utf-8
from sys import stdin
import sys, fractions
import numpy as np

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


a,b,c,d = [int(x) for x in stdin.readline().rstrip().split()]
#print(a, b, c, d)
#bまでで3で割り切れる数
three_all = b // c
#a-1までで3で割り切れる数
three_less = (a-1) // c
three_range = three_all - three_less
    
two_all = b // d
two_less = (a-1) // d
two_range = two_all - two_less
    
z = lcm(c,d)
six_all = b // z
six_less = (a-1) // z
six_range = six_all - six_less
    
num = three_range + two_range - six_range
    
ans = b-a+1-num
print(ans)
lst=input().split()
x_1=int(lst[0])
y_1=int(lst[1])
x_2=int(lst[2])
y_2=int(lst[3])
dis=((x_1-y_1)**2+(x_2-y_2)**2)**(1/2)
print(dis)


### FIXED CODE ###

lst=input().split()
lst=list(map(lambda i:float(i),lst))
x_1=lst[0]
x_2=lst[1]
y_1=lst[2]
y_2=lst[3]
dis=((x_1-y_1)**2+(x_2-y_2)**2)**(1/2)
print(dis)
b = int(input())

dict = {"A":"T","C":"G","T":"A","G":"C"}

print(dict[b])

### FIXED CODE ###

b = input()
 
dict = {"A":"T","C":"G","T":"A","G":"C"}
 
print(dict[b])
N = int(input())
AB = [list(map(int,input().split())) for i in range(N)]

sort_AB = sorted(AB, key= lambda x: x[1])
ans = 'Yes'
tmp = 0

for i in range(N):
    tmp += sortedAB[i][0]
    if tmp > sortedAB[i][1]:
        ans = 'No'
        break
        
print(ans)

### FIXED CODE ###

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

sortedAB = sorted(AB, key= lambda x: x[1])

import sys
work = 0

for i in range(N):
    work += sortedAB[i][0]
    if work > sortedAB[i][1]:
        print('No')
        sys.exit()
        
print('Yes')
a = "abcdefghijklmnopqrstuvwxyz"
s = set(input())
for i in s:
    a = a.replace(i,"")
print(a[0])


### FIXED CODE ###

a = "abcdefghijklmnopqrstuvwxyz"
s = set(input())
c = 0

for i in s:
    a = a.replace(i,"")
    c += 1
if c < 26:
    print(a[0])
else:
    print("None")
S=map(int, input().split())
S.sort()
print(S[0] if S[1] == S[2] else S[2])

### FIXED CODE ###

*S,=map(int, input().split())
S.sort()
print(S[0] if S[1] == S[2] else S[2])
a,b = map(int,input().split())
p = a*b
print(int(p))

### FIXED CODE ###

a,b = input().split()
a = int(a)
b = round(float(b)*100)
p = (a*b)//100
print(p)
n=int(input())
s=0
for _ in range(n):
  a,b=input().split()
  if str(b)="JPY":
    s+=int(a)
  else:
    s+=int(a)*380000
print(s)

### FIXED CODE ###

n=int(input())
s=0
for _ in range(n):
  a,b=input().split()
  if str(b)=="JPY":
    s+=int(a)
  else:
    s+=float(a)*380000
print(s)
n, a, b = [int(i) for i in input().split()]
X = [int(i) for i in input.split()]

ans = 0
for i in range(n-1):
  ans += min(a * X[i+1] - b)

print(ans)

### FIXED CODE ###

n, a, b = [int(i) for i in input().split()]
X = [int(i) for i in input().split()]

ans = 0
for i in range(n-1):
  ans += min(a * (X[i+1] - X[i]), b)

print(ans)
N, K = map(int, input().split())
S = str(input())
S_list = []
cum_list = [0]
tmp = 1
count = 0

for i in range(N):
    if i == 0:
        if int(S[i]) == tmp:
             count += 1
        else:
            S_list.append(count)
            count = 1
    else:
        if S[i] == S[i - 1]:
            count += 1
            
        else:
            S_list.append(count)
            count = 1

S_list.append(count)
if S[-1] == "0":
    S_list.append(0)


now = 0
for i in range(len(S_list)):
    now += S_list[i]
    cum_list.append(now)


answer_list = []
i = 0
if 2 * K + 1 < len(x):
    while i + 2 * K + 1 < len(x):
        answer_list.append(x[i + 2 * K + 1] - x[i])
        i += 2
else:
    answer_list.append(len(S))
answer_list = check(cum_list,K)
answer = max(answer_list)
print(answer)

### FIXED CODE ###

N, K = map(int, input().split())
S = str(input())
S_list = []
cum_list = [0]
tmp = 1
count = 0

for i in range(N):
    if i == 0:
        if int(S[i]) == tmp:
             count += 1
        else:
            S_list.append(count)
            count = 1
    else:
        if S[i] == S[i - 1]:
            count += 1
            
        else:
            S_list.append(count)
            count = 1

S_list.append(count)
if S[-1] == "0":
    S_list.append(0)


now = 0
for i in range(len(S_list)):
    now += S_list[i]
    cum_list.append(now)


answer_list = []
i = 0
if 2 * K + 1 < len(cum_list):
    while i + 2 * K + 1 < len(cum_list):
        answer_list.append(cum_list[i + 2 * K + 1] - cum_list[i])
        i += 2
else:
    answer_list.append(len(S))
answer = max(answer_list)
print(answer)
S1 = list(map(int, input().split()))
S2 = list(map(int, input().split()))

H = S1[0]

if H > sum(S2):
    print("no")
else:
    print("yes")

### FIXED CODE ###

H, A = map(int, input().split())
print(-(-H // A))
for i in range(len(l)):
    if l[i]==l[i+1]:
        print('Bad')
        break
else:
    print('Good')

### FIXED CODE ###

l=input()
for i in range(len(l)-1):
    if l[i]==l[i+1]:
        print('Bad')
        break
else:
    print('Good')
import sys
sys.setrecursionlimit


def main():
    n = int(input())
    
    G=[[] for _ in range(n)]
    for _ in range(n-1):
        u,v,w = map(int, input().split())
        G[u-1].append([v-1,w])
        G[v-1].append([u-1,w])
    ans=[-1]*n
    
    def sub(node,distance):
        for next_node, edge in G[node]:
            if ans[next_node]==-1:
                ans[next_node]=(distance+edge)%2
                sub(next_node,(distance+edge)%2)
    sub(0,0)
    
    for i in ans:
        print(i)
main()

### FIXED CODE ###

import sys
sys.setrecursionlimit(10000000)


def main():
    n = int(input())
    
    G=[[] for _ in range(n)]
    for _ in range(n-1):
        u,v,w = map(int, input().split())
        G[u-1].append([v-1,w])
        G[v-1].append([u-1,w])
    ans=[-1]*n
    
    def sub(node,distance):
        for next_node, edge in G[node]:
            if ans[next_node]==-1:
                ans[next_node]=(distance+edge)%2
                sub(next_node,(distance+edge)%2)
    sub(0,0)
    
    for i in ans:
        print(i)
main()
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from math import gcd
N, M = map(int, input().split())
S = input()
T = input()
g = N//gcd(N, M)*M
ans = ['?']*g
for i in range(N):
    ans[i*g//N] = S[i]
ok = True
for i in range(M):
    idx = i*g//M
    if ans[idx] != '?' and ans[idx] != T[i]:
        ok = False
        break
if ok:
    print(g)
else:
    print(-1)


### FIXED CODE ###

from math import gcd
from collections import defaultdict

N, M = map(int, input().split())
S = input()
T = input()
g = N//gcd(N, M)*M
ans = defaultdict(bool)
for i in range(N):
    ans[i*g//N] = S[i]
ok = True
for i in range(M):
    idx = i*g//M
    if ans[idx] and ans[idx] != T[i]:
        ok = False
        break
if ok:
    print(g)
else:
    print(-1)
l = list(map(int,input().split()))
k = int(input())
L =l.sorted()
print(l[0]+l[1]+l[2]*k)

### FIXED CODE ###

a,b,c = map(int,input().split())
k = int(input())
print(a+b+c-max(a,b,c)+max(a,b,c)*(2 ** k))
s=str(input())
l=str(len(s))
list=[s[0],l,s[l-1]]
print(''.join(list))

### FIXED CODE ###

s=str(input())
l=len(s)
li=str(l-2)
list=[s[0],li,s[l-1]]
print(''.join(list))
o = list(input())
e = list(input())+[""]

for i,j zip(o,e): print(i+j,end="")

### FIXED CODE ###

o = list(input())
e = list(input())+[""]

for i,j in zip(o,e): print(i+j,end="")
import sys

def swap(A, i, j):
    x = A[i]
    A[i] = A[j]
    A[j] = x

def partition(A, p, r, idx):
    x = A[r][idx]                # 1 x = A[r]
    i = p - 1                    # 2 i = p-1
    for j in range(p, r):        # 3 for j = p to r-1
        if A[j][idx] <= x:       # 4     if A[j] <= x
            i += 1               # 5        then i = i+1
            if(i != j):
                swap(A, i, j)    # 6        exchange A[i] and A[j] 
    i += 1 
    swap(A, i, r)                # 7 exchange A[i+1] and A[r]
    return i                     # 8 return i+1

def quickSort(A, p, r, idx):
    if p < r:
        q = partition(A, p, r, idx)
        quickSort(A, p, q - 1, idx)
        quickSort(A, q + 1, r, idx)

def main():
    """ ????????? """
    num = int(input().strip())
    istr = sys.stdin.read()
    cards = list(istr.splitlines())
    
    A = [[0,0] for i in range(num)]
    B = [[0,0] for i in range(num)]
    
    for i in range(num):
        A[i][0] = cards[i][0]
        A[i][1] = int(cards[i][2:])
        B[i][0] = cards[i][0]
        B[i][1] = int(cards[i][2:])

    quickSort(A, 0, num-1,1)
    B.sort(key = lambda d:d[1])
    res = "Stable"
    for i in range(num):
        if A[i][0] != B[i][0] or A[i][1] != B[i][1]:
            res = "Not stable"
            break

    print(res)
    for x in A:
        print(" ".join(map(str, x)))

if __name__ == '__main__':
    main()

### FIXED CODE ###

def swap(A, i, j):
#    print("\tswap Aj:{} Ai:{}\n".format(A[j], A[i]))
    x = A[i]
    A[i] = A[j]
    A[j] = x

def partition(A, p, r):
    x = A[r]
    i = p - 1
    for j in range(p, r):
        if A[j] <= x:
            i += 1
            swap(A, i, j)
#        print("j:{} Aj:{} i:{} Ai:{} Ar:{}".format(j, i, A[j], A[i], A[r]))
#        print(A)
#        print(" ")
    A[r] = "[{}]".format(A[r])
    swap(A,i+1, r)
    i += 1
    return i

def main():
    """ ????????? """
    num = int(input().strip())
    A = list(map(int,input().split()))
    partition(A, 0, num-1)
    print(" ".join(map(str,A)))

if __name__ == '__main__':
    main()
from collections import deque
import sys
input = sys.stdin.readline
n, m = map(int, input().split())
adjacent_list = [[] for i in range(n+1)]
for i in range(m):
    a, b = map(int, input().split())
    adjacent_list[a].append(b)
    adjacent_list[b].append(a)
ans = [-1 for i in range(n+1)]
def bfs():
    #start at 1
    que = deque([1])
    while que:
        node = que.popleft()
        finished.add(node)
        for i in adjacent_list[node]:
            if ans[i] == -1:
                que.append(i)
                ans[i] = node
bfs()
print("Yes")
for i in range(2,n+1):
    print(ans[i])


### FIXED CODE ###

from collections import deque
import sys
input = sys.stdin.readline
n, m = map(int, input().split())
adjacent_list = [[] for i in range(n+1)]
for i in range(m):
    a, b = map(int, input().split())
    adjacent_list[a].append(b)
    adjacent_list[b].append(a)
ans = [-1 for i in range(n+1)]
def bfs():
    #start at 1
    que = deque([1])
    while que:
        node = que.popleft()
        for i in adjacent_list[node]:
            if ans[i] == -1:
                que.append(i)
                ans[i] = node
bfs()
print("Yes")
for i in range(2,n+1):
    print(ans[i])