Harryxun/stf_run huggingface dataset:
from collections import deque
n , m = map(int,input().split())
z = [[] for i in range(n)]
for i in range(m):
    l , r , d = map(int,input().split())
    z[l-1].append((r-1,d))
    z[r-1].append((l-1,-d))

visit = [False for i in range(n)]
x = [-1 for i in range(n)]
for i in range(n):
    if visit[i]:
        continue
    visit[i] = True
    d = deque()
    d.append(i)
    x[i] = 0
    while d:
        now = d.popleft()
        for t , d in z[now]:
            if not visit[t]:
                visit[t] = True
                x[t] = x[now] + d
                d.append(t)
            elif visit[t]:
                if x[t] - x[now] != d:
                    print("No")
                    exit()
print("Yes")

### FIXED CODE ###

from collections import deque
n , m = map(int,input().split())
z = [[] for i in range(n)]
for i in range(m):
    l , r , d = map(int,input().split())
    z[l-1].append((r-1,d))
    z[r-1].append((l-1,-d))

visit = [False for i in range(n)]
x = [-1 for i in range(n)]
for i in range(n):
    if visit[i]:
        continue
    visit[i] = True
    q = deque()
    q.append(i)
    x[i] = 0
    while q:
        now = q.popleft()
        for t , d in z[now]:
            if not visit[t]:
                visit[t] = True
                x[t] = x[now] + d
                q.append(t)
            elif visit[t]:
                if x[t] - x[now] != d:
                    print("No")
                    exit()
print("Yes")
#import sys
#input = sys.stdin.readline

import math
from collections import defaultdict,deque
ml=lambda:map(int,input().split())
ll=lambda:list(map(int,input().split()))
ii=lambda:int(input())
ip=lambda:list(input())
ips=lambda:input().split()

"""========main code==============="""

def fast_expo(x,y,m):
    res=1
    while(y):
        if(y&1):
            res*=x
            res%=m
        x*=x
        x%=m
        y>>=1
    return res    

dp=defaultdict(int)
dp[1]=1
dp[2]=1
for i in range(3,200001):
    s=""
    k=i
    cnt=0
    while(k):
        if(k%2): cnt+=1
        k>>=1
    dp[i]=dp[i%cnt]+1
n=ii()
a=ip()
a=a[::-1]
c=a.count('1')

min_1=0
max_1=0

for i in range(n):
    if(a[i]=='1'):
        min_1+=fast_expo(2,i,c-1)
        max_1+=fast_expo(2,i,c+1)
        min_1%=(c-1)
        max_1%=(c+1)
    
ans=[]    

for i in range(n):
    if(a[i]=='1'):
        ans.append(dp[(min_1-fast_expo(2,i,c-1)+(c-1))%(c-1)]+1)
    else:
        ans.append(dp[(max_1+fast_expo(2,i,c+1))%(c+1)]+1)
ans=ans[::-1]
for i in ans:
    print(i)

### FIXED CODE ###

#import sys
#input = sys.stdin.readline

import math
from collections import defaultdict,deque
ml=lambda:map(int,input().split())
ll=lambda:list(map(int,input().split()))
ii=lambda:int(input())
ip=lambda:list(input())
ips=lambda:input().split()

"""========main code==============="""

def fast_expo(x,y,m):
    res=1
    while(y):
        if(y&1):
            res*=x
            res%=m
        x*=x
        x%=m
        y>>=1
    return res    

dp=defaultdict(int)
dp[1]=1
dp[2]=1
for i in range(3,200001):
    k=i
    cnt=0
    while(k):
        if(k%2): cnt+=1
        k>>=1
    dp[i]=dp[i%cnt]+1
n=ii()
a=ip()
a=a[::-1]
c=a.count('1')

min_1=0
max_1=0

for i in range(n):
    if(a[i]=='1'):
        if(c-1!=0):
            min_1+=fast_expo(2,i,c-1)
            min_1%=(c-1)
        max_1+=fast_expo(2,i,c+1)
        
        max_1%=(c+1)
    
ans=[]    

for i in range(n):
    if(a[i]=='1'):
        if(c-1==0):
            ans.append(0)
        else:    
            ans.append(dp[(min_1-fast_expo(2,i,c-1)+(c-1))%(c-1)]+1)
    else:
        ans.append(dp[(max_1+fast_expo(2,i,c+1))%(c+1)]+1)
ans=ans[::-1]
for i in ans:
    print(i)
s = input()
k = int(input())
def all(s, k):
    if s == '':
        return {}
    ret = set()
    for i in range(k):
        if i < len(s):
            ret.add(s[:(i+1)])
    return ret.union(all(s[1:], k))
koho = sorted(list(all(s,k)))
print(koho[k-1])


### FIXED CODE ###

s = input()
k = int(input())
n = len(s)
koho = set()
for i in range(n):
    for j in range(k):
        if i + j < n:
            koho.add(s[i:(i+j+1)])
so = sorted(list(koho))
print(so[k-1])
A,B = map(int, input().split())
if A+B == 3:
    print(3)
elif A+B == 4:
    print(2)
else:
    print(3)

### FIXED CODE ###

A = int(input())
B = int(input())
if A+B == 3:
    print(3)
elif A+B == 4:
    print(2)
else:
    print(1)
from math import sqrt
from math import floor
n,p = map(int,input().split())
l = [p]
for i in range(2,floor(sqrt(p))+1):
    if p % i == 0:
        l.append(i)
        l.append(p//i)
l.sort()
s = []
i = 0
while p > 1:
    if p % l[i] == 0:
        s.append(l[i])
        p = p // l[i]
    else:
        i += 1
print(s[0]*s[-1])

### FIXED CODE ###

from math import sqrt
from math import floor
n,p = map(int,input().split())
l = [p]
for i in range(2,floor(sqrt(p))+1):
    if p % i == 0:
        l.append(i)
        l.append(p//i)
l.sort()
s = [1]
i = 0
while p > 1:
    if p % l[i] == 0:
        s.append(l[i])
        p = p // l[i]
    else:
        i += 1
ans = 1
x = s[0]
y = 1
for i in s[1:]:
    if x == i:
        y += 1
    else:
        while y >= n:
            ans *= x
            y -= n
        x = i
        y = 1
while y >= n:
    ans *= x
    y -= n
print(ans)
n = int(input())

l = []
for _ in range(0, 100):
    x = _**5
    if x > 10**9:
        break
    else:
        l.append(x)
tmp = len(l)

for i in range(len(l)):
    l.append(l[i]*-1)
#print(l)
#print(len(l))

from itertools import combinations
y = (list(combinations(l, 2)))
#print(y)

for j in range(len(y)):
    if y[j][0] - y[j][1] == n:
        z = j
#print(y[z])

if y[z][0] > 0:
    a = l.index(y[z][0])
else:
    a = -1 * (l.index(y[z][0]*-1))

if y[z][1] > 0:
    b = l.index(y[z][1])
else:
    b = -1 * (l.index(y[z][1]*-1))


print(a, b)

### FIXED CODE ###

# +の場合
i = 0
ans = 0
while ans <= 1000000000:
   i += 1
   ans = i**5 - (i-1)**5
# i: 120

# -の場合
i = 0
ans = 0
while ans <= 1000000000:
   i -= 1
   ans = i**5 - (i-1)**5 
# i: -119

n = int(input())
l = [_**5 for _ in range(120)]

for i in range(1,120):
    for j in range(120):
        if l[i] - l[j] == n:
            print(int(l[i]**0.2), int(l[j]**0.2))
            exit()
        if l[i] + l[j] == n:
            print(int(l[i]**0.2), int(-1*l[j]**0.2))
            exit()
from functools import lru_cache

n, m = map(int, input().split())
a = []
for i in range(m):
  a.append(int(input()))
  
@lru_cache(maxsize=100000)
def comb(n):
  if n in a:
    return 0
  if 1 not in a and n == 1:
    return 0
  elif n in (0, 1):
    return 1
  else:
    return (comb(n-1) + comb(n-2))

print(comb(n)%(10**9 + 7))

### FIXED CODE ###

n, m = list(map(int,input().split()))
a = []
for i in range(m):
  a.append(int(input()))
c = [0] * (n+2) #combination
for i in a:
  c[i] = -1
c[0] = 1

for i in range(n):
    if c[i] < 0:
      continue
    if c[i+1] >= 0:
        c[i+1] = c[i] + c[i+1]
    if c[i+2] >= 0:
        c[i+2] = c[i] + c[i+2]
    c[i] = c[i] % 10**9+7
print(c[n]%(10**9+7))
a, b, c = map(int, raw_input().split())
count = 0
for i in rang(a, b+1):
  c % i  == 0
  count += 1
print count

### FIXED CODE ###

a, b, c = map(int, raw_input().split())
count = 0
for i in range(a, b+1):
  if c % i  == 0:
    count += 1
print count
n = int(input())
listV =  list(map(int,input().split()))
sortedListV = sorted(listV)
result = (sortedListV[0] + sortedListV[1]) / 2

for i range (2, n-1):
    result += (result + sortedListV[i]) / 2
print(result)

### FIXED CODE ###

n = int(input())
listV =  list(map(int,input().split()))
sortedListV = sorted(listV)

for i in range(0 , n-1):
    if (i != 0):
        result = (result + sortedListV[i+1]) / 2
    else:
        result = (sortedListV[i] + sortedListV[i+1]) / 2
print(result)
N=int(input())
LA=list(map(int,input().split()))
ans=[]

from math import gcd
from functools import reduce
def multigcd(item):
    return reduce(gcd, item)

for n in range(N):
    L=LA[:n]+LA[n+1:]
    ans.append(multigcd(L))

print(max(ans))

### FIXED CODE ###

N=int(input())
LA=list(map(int,input().split()))
ans=[]

def gcd(m,n):
    if m==0 or n==0:
        return m+n
    while n:
        m,n=n,m%n
    return m

La=[0]
Lb=[0]

for n in range(N-1):
    La.append(gcd(La[n],LA[n]))
    Lb.append(gcd(Lb[n],LA[-(n+1)]))

for n in range(N):
    ans.append(gcd(La[n],Lb[-(n+1)]))
        
print(max(ans))
#D
from collections import deque
Str = str(input())
Q = int(input())
S = deque()
S.append(Str)
A = 0
B = []
C = []

for i in range(Q):
    a = list(map(str, input().split()))
    if a[0] == '1':
        if A%2==0:
            if len(B)>1:
                B_=B.reverse()
                S.extendleft(B_)
                B = []
            else:
                S.extendleft(B)
                B = []
            S.extend(C)
            C = []
        else:
            if len(C)>1:
                C_=C.reverse()
                S.extendleft(C_)
                C = []
            else:
                S.extendleft(C)
                C = []
            S.extend(B)
            B = []
        A += 1
    elif a[1] == '1':
        B.append(a[2])
    else:
        C.append(a[2])

if a[0] != '1':
    if A%2==0:
        if len(B)>1:
            B_=B.reverse()
            S.extendleft(B_)
            B = []
        else:
            S.extendleft(B)
            B = []
        S.extend(C)
        C = []
    else:
        if len(C)>1:
            C_=C.reverse()
            S.extendleft(C_)
            C = []
        else:
            S.extendleft(C)
            C = []
        S.extend(B)

if A%2 != 0:
    S.reverse()
print(''.join(S))

### FIXED CODE ###

#D
from collections import deque
Str = str(input())
Q = int(input())
S = deque(list(Str))
#S.append(list(Str))
#上の方法ではダメ
A = 0
B = []
C = []

for i in range(Q):
    a = list(map(str, input().split()))
    if a[0] == '1':
        if A%2==0:
            if len(B)>1:
                S.extendleft(B)
                B = []
            elif len(B) == 1:
                S.extendleft(B)
                B = []
            if len(C) > 0:
                S.extend(C)
                C = []
        else:
            if len(C)>1:
                S.extendleft(C)
                C = []
            elif len(C) == 1:
                S.extendleft(C)
                C = []
            if len(B) > 0:
                S.extend(B)
                B = []
        A += 1
    elif a[1] == '1':
        B.append(a[2])
    else:
        C.append(a[2])

if a[0] != '1':
    if A%2==0:
        if len(B)>1:
            S.extendleft(B)
            B = []
        elif len(B) == 1:
            S.extendleft(B)
            B = []
        if len(C) > 0:
            S.extend(C)
            C = []
    else:
        if len(C)>1:
            S.extendleft(C)
            C = []
        elif len(C) == 1:
            S.extendleft(C)
            C = []
        if len(B) > 0:
            S.extend(B)
            B = []

if A%2 != 0:
    S.reverse()
print(''.join(S))
A, B, C = list(map(int, input().split()))

if A == B:
    print(C)
elif A == C
    print(B)
else:
    print(A)

### FIXED CODE ###

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

if A == B:
    print(C)
elif A == C:
    print(B)
else:
    print(A)
N = int(raw_input())
A = [0] * N
for idx in xrange(N):
  A[idx] = int(raw_input())
total =  0
pre = 0
for item in A:
  total += (item+pre) / 2
  if item == 0:
    pre = 0
  else:
    pre = (item+pre) % 2

print total

### FIXED CODE ###

S = raw_input()
S = list(S)
S = set(S)
flagSN = False
flagEW = False
if ('N' in S and 'S' in S) or ('N' not in S and 'S' not in S):
  flagSN = True
if ('W' in S and 'E' in S) or ('W' not in S and 'E' not in S):
  flagEW = True
if flagSN and flagEW:
  print 'Yes'
else:
  print 'No'
import sys, math
N, K = map(int, input().split())
A = sorted(list(map(int, input().split())), key=lambda x: abs(x))[::-1]
P = int(1e9+7)

ans = 1
hu = None
sei = None
flg = False
for a in A:
    flg = a > 0
    if flg:
        break
if not flg:
    for i in range(1, K+1):
        ans = (ans * A[-i]) % P
    print(ans)
    sys.exit()
if K == N:
    for a in A:
        ans = (ans * a) % P
    print(ans)
    sys.exit()

for i, a in zip(range(K), A):
    if a > 0:
        if sei:
            ans = (ans * sei) % P
        sei = a
    else:
        if not hu:
            hu = a
        else:
            ans = (ans * a * hu) % P
            hu = None

ptn1, ptn2 = -math.inf, -math.inf
if hu:
    if not sei:
        for i in range(K, N):
            if A[i] > 0:
                ptn1 = sei * A[i]
                break
        for i in range(K, N):
            if A[i] <= 0:
                ptn2 = hu * A[i]
                break
        ans = (ans * max(ptn1, ptn2)) % P
    else:
        for i in range(K, N):
            if A[i] > 0:
                ans = (ans*A[i])%P
                break
else:
    if sei:
        ans = (ans * sei) % P
print(ans % P)


### FIXED CODE ###

import sys, math
N, K = map(int, input().split())
A = sorted(list(map(int, input().split())), key=lambda x: abs(x))[::-1]
P = int(1e9+7)
ans = 1
hu = None
sei = None
flg = False
for a in A:
    flg = a > 0
    if flg:
        break
if not flg:
    if K%2==1:
        for i in range(1, K+1):
            ans = (ans * A[-i]) % P
    else:
        for i in range(K):
            ans = (ans * A[i]) % P
    print(ans)
    sys.exit()
if K == N:
    for a in A:
        ans = (ans * a) % P
    print(ans)
    sys.exit()

for i, a in zip(range(K), A):
    if a > 0:
        if sei:
            ans = (ans * sei) % P
        sei = a
    else:
        if hu is None:
            hu = a
        else:
            ans = (ans * a * hu) % P
            hu = None

ptn1, ptn2 = -math.inf, -math.inf
if hu:
    if sei:
        for i in range(K, N):
            if A[i] > 0:
                ptn1 = sei * A[i]
                break
        for i in range(K, N):
            if A[i] <= 0:
                ptn2 = hu * A[i]
                break
        ans = (ans * max(ptn1, ptn2)) % P
    else:
        for i in range(K, N):
            if A[i] > 0:
                ans = (ans * A[i]) % P
                break
else:
    if sei:
        ans = (ans * sei) % P
print(ans % P)
a=[]
b=[]
for _ in range(3):
    a.append(list(map(int,input().split())))
for _ in range(int(input())):
    b.append(int(input()))
for i in range(N):
    for j in range(3):
        for k in range(3):
            if b[i]==a[k][j]:
                a[k][j]=0
if (a[0][0]==0 and a[0][1]==0 and a[0][2]==0)or(a[1][0]==0 and a[1][1]==0 and a[1][2]==0) or (a[2][0]==0 and a[2][1]==0 and a[2][2]==0) or (a[0][0]==0 and a[1][0]==0 and a[2][0]==0) or (a[0][1]==0 and a[1][1]==0 and a[2][1]==0) or (a[0][2]==0 and a[1][2]==0 and a[2][2]==0) or (a[0][0]==0 and a[1][1]==0 and a[2][2]==0) or (a[0][2]==0 and a[1][1]==0 and a[2][0]==0):
    print("Yes")
else:
    print("No")

### FIXED CODE ###

a=[]
b=[]
for _ in range(3):
    a.append(list(map(int,input().split())))
N=int(input())
for _ in range(N):
    b.append(int(input()))
for i in range(N):
    for j in range(3):
        for k in range(3):
            if b[i]==a[k][j]:
                a[k][j]=0
if (a[0][0]==0 and a[0][1]==0 and a[0][2]==0)or(a[1][0]==0 and a[1][1]==0 and a[1][2]==0) or (a[2][0]==0 and a[2][1]==0 and a[2][2]==0) or (a[0][0]==0 and a[1][0]==0 and a[2][0]==0) or (a[0][1]==0 and a[1][1]==0 and a[2][1]==0) or (a[0][2]==0 and a[1][2]==0 and a[2][2]==0) or (a[0][0]==0 and a[1][1]==0 and a[2][2]==0) or (a[0][2]==0 and a[1][1]==0 and a[2][0]==0):
    print("Yes")
else:
    print("No")
# -*- coding: utf-8 -*-
import numpy as np
n,k = list(map(int,input().split()))
s = 0 

for i in range(n):
    h = int(input())
    if h >= k:
        s += 1
print(s)
exit(0)


### FIXED CODE ###

# -*- coding: utf-8 -*-
import numpy as np 
n,k = list(map(int,input().split()))
h = list(map(int,input().split()))

s = 0 
for hi in h:
    if hi >= k:
        s += 1
print(s)
ta, ao, K = map(int, input().split())
if K - ta > 0:
    taa = 0
    if ao - (K - ta) > 0:
        ao = ao - (K - ta)
    else:
        ao = 0
else:
    ta -= K


print(taa, ao)

### FIXED CODE ###

Taka, Aoki, K = map(int, input().split())
dif = Taka - K
if dif >= 0:
    Taka -= K
else:
    dif = abs(dif)
    Taka = 0
    dif = Aoki - dif
    if dif >= 0:
        Aoki = dif
    else:
        Aoki = 0
print(Taka, Aoki)
K=int(input())
[A,B]=list(map(int(),input().split()))
flg=0
for n in range(A,B+1):
  if n%K==0:
    print("OK")
    flg==1
    break
if flg==0:print("NG")

### FIXED CODE ###

K=int(input())
[A,B]=[int(i) for i in input().split()]
f=0
for n in range(A,B+1):
  if n%K==0:
    f+=1
    break
if f==0:print("NG")
else:print("OK")
n=int(input())
x=list(map(int,input().split()))
x.sort()
ans=float("Inf")
for i in range(x[0],x[n-1]+1):
  print(i)
  cal=0
  for j in range(0,n):
    cal=cal+(x[j]-temp)**2
  ans=min(ans,cal)
print(ans)

### FIXED CODE ###

n=int(input())
x=list(map(int,input().split()))
x.sort()
ans=float("Inf")
for i in range(x[0],x[n-1]+1):
  temp=i
  cal=0
  for j in range(0,n):
    cal=cal+(x[j]-temp)**2
  ans=min(ans,cal)
print(ans)
class Dice:
 
    def __init__(self, faces):
        self.faces = tuple(faces)
 
    def roll_north(self):
        self.faces = (self.faces[1], self.faces[5], self.faces[2],
                      self.faces[3], self.faces[0], self.faces[4])
 
    def roll_south(self):
        self.faces = (self.faces[4], self.faces[0], self.faces[2],
                      self.faces[3], self.faces[5], self.faces[1])
 
    def roll_west(self):
        self.faces = (self.faces[2], self.faces[1], self.faces[5],
                      self.faces[0], self.faces[4], self.faces[3])
 
    def roll_east(self):
        self.faces = (self.faces[3], self.faces[1], self.faces[0],
                      self.faces[5], self.faces[4], self.faces[2])
    
    def roll_roll(self):
        self.faces = (self.faces[0], self.faces[2], self.faces[4],
                      self.faces[1], self.faces[3], self.faces[5])
 
    def number(self, face_id):
        return self.faces[face_id - 1]

    def is_same(self, anotherDice):
        if self.faces == anotherDice.faces:
            return True
        return False
 
dice1 = Dice(list(map(int, input().split())))
dice2 = Dice(list(map(int, input().split())))

flag = False

for i in range(4):
    dice2.roll_north()
    for j in range(4):
        dice2.roll_roll()
        if dice2.is_same(dice1):
            flag = True
            break
    if flag:
        break

if flag:
    print("Yes")
else:
    print("No")

### FIXED CODE ###

class Dice(object):
    def __init__(self, top, south, east, west, north, bottom):
        self.top = top
        self.south = south
        self.east = east
        self.west = west
        self.north = north
        self.bottom = bottom

    def get_top(self):
        return self.top
    
    def rotate(self, directions):
        for direction in directions:
            if direction == 'S':
                self.prev_top = self.top
                self.top = self.north
                self.north = self.bottom
                self.bottom = self.south
                self.south = self.prev_top
            elif direction == 'E':
                self.prev_top = self.top
                self.top = self.west
                self.west = self.bottom
                self.bottom = self.east
                self.east = self.prev_top
            elif direction == 'W':
                self.prev_top = self.top
                self.top = self.east
                self.east = self.bottom
                self.bottom = self.west
                self.west = self.prev_top
            elif direction == 'N':
                self.prev_top = self.top
                self.top = self.south
                self.south = self.bottom
                self.bottom = self.north
                self.north = self.prev_top
 
dice = Dice(*map(int,input().split()))
dice.rotate(input())
print(dice.get_top())
from collections import defaultdict

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

max_size = 0


for _ in range(M):

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

    if B not in F[A]:
        F[A].append(B)
    if A not in F[B]:
        F[B].append(A)

def dfs(i):
    vis.append(i)
    size = 0
    for j in F[i]:
        if j not in vis:
            size += dfs(j)
    return size + 1


vis = list()

ret = 0

for i in range(N):
    if i+1 not in vis:
        size = dfs(i+1)
        if size > ret:
            ret = size

print('{}'.format(ret))




### FIXED CODE ###

class UnionFind():
    def __init__(self, N):
        self.N = N
        self.par = [n for n in range(N)]
        self.rank = [1] * N
        
    def find(self, u):
        if self.par[u] == u:
            return u
        else:
            return self.find(self.par[u])
    
    def union(self, u, v):

        pu = self.find(u)
        pv = self.find(v)

        if pu == pv: 
            return

        if self.rank[pu] < self.rank[pv]:
            self.par[pu] = pv
            self.rank[pv] += self.rank[pu]

        else: # self.rank[pu] > self.rank[pv]
            self.par[pv] = pu
            self.rank[pu] += self.rank[pv]
 
N, M = map(int, input().split())
UF = UnionFind(N)
for _ in range(M):
    A, B = map(int, input().split())
    A, B = A-1, B-1
    UF.union(A, B)


ret = 0

for n in range(N):
    ret = max(ret, UF.rank[n])

print(ret)
if ''.join((sorted(raw_input())) == 'abc':
  print 'Yes'
else:
  print 'No'

### FIXED CODE ###

if ''.join(sorted(raw_input())) == 'abc':
  print 'Yes'
else:
  print 'No'
N, K = map(int, input().split())
arr = list(map(int, input().split()))

if 0 in arr:
    K -= 1

if K==0:
    print(0)
    exit()

left =[]
right= []
for i in arr:
    if i<0:
        left.append(i*(-1))
    if i>0:
        right.append(i)

left = left[::-1]
if len(left)==0:
    print(right[K-1])
    exit()

if len(right)==0:
    print(left[K-1])
    exit()


if len(left)>=K and len(right)>=K:
    ans =[]
    ans.append(right[K-1])
    ans.append(left[K-1])
    for i in range(K-2):
        ans.append(2*right[i]+left[K-i-2])
    for i in range(K-2):
        ans.append(2*left[i]+right[K-i-2])
    print(min(ans))
    exit()

if len(left)<K and len(right)>=K:
    ans =[]
    ans.append(right[K-1])
    for i in range(K-2):
        ans.append(2*right[i]+left[K-i-2])
    for i in range(len(left)):
        ans.append(2*left[i]+right[K-i-2])
    print(min(ans))
    exit()

if len(right)<K and len(left)>=K:
    ans =[]
    ans.append(left[K-1])
    for i in range(K-2):
        ans.append(2*left[i]+right[K-i-2])
    for i in range(len(right)):
        ans.append(2*right[i]+left[K-i-2])
    print(min(ans))
    exit()

if len(right)<K and len(left)<K:
    ans =[]
    for i in range(len(left)):
        ans.append(2*left[i]+right[K-i-2])
    for i in range(len(right)):
        ans.append(2*right[i]+left[K-i-2])
    print(min(ans))
    exit()

### FIXED CODE ###

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

ans =[]
if arr[0]>0:
    ans.append(arr[K-1])

if arr[-1]<0:
    ans.append(abs(arr[-1*(K)]))

for i in range(N-K+1):
    if arr[i]*arr[i+K-1]<=0:
        left =2*abs(arr[i])+abs(arr[i+K-1])
        right=2*abs(arr[i+K-1])+abs(arr[i])
        ans.append(min(left,right))

print(min(ans))
n, l = map(int, input().split())
s_list = [input() for _ in range(n)]

s_list = sorted(s_list)

print('{}{}{}'.format(s_list[0], s_list[1], s_list[2]))

### FIXED CODE ###

n, l = map(int, input().split())
s_list = [input() for _ in range(n)]

s_list = sorted(s_list)

print(*s_list, sep='')
D=int(input())
c=list(map(int,(input().split())))
s=[]
t=[]
last=[0]*26
sat=0
for _ in range(D):
  s.append(list(map(int,(input().split()))))
for _ in range(D):
  t.append(int(input()))

for i in range(D):
  sat+=max(s[i])
  for j in range(26):
    sat-=c[i]*(1-last[j])
  print(sat)

### FIXED CODE ###

D=int(input())
c=list(map(int,(input().split())))
s=[]
t=[]
last=[0]*26
sat=0
  
for i in range(D):
  s.append(list(map(int,(input().split()))))
  sat+=max(s[i])
  ans=s[i].index(max(s[i]))+1
  t.append(ans)
  print(ans)
s,t=input().split()
a=0
f=False

for i in range(len(s)):
	a=s[-1]
	s=s[:-1]
	s=a+s
	
	if s==t:
		f=True
		break
		
if f:
	print('Yes')
else:
	print('No')

### FIXED CODE ###

s=input()
t=input()
a=0
f=False

for i in range(len(s)):
	a=s[-1]
	s=s[:-1]
	s=a+s
	
	if s==t:
		f=True
		break
		
if f:
	print('Yes')
else:
	print('No')