Harryxun/stf_run huggingface dataset:
import re
N,M=map(int, input().split())

A=[]
B=[]

for n in range(N):
    A.append(input())

for m in range(M):
    B.append(input())
        
# check
for m in range(M):
    for n in range(N):
        # Bのm行目と一致
        # Bのm+1行目と一致するかチェック
        span =[m.span() for m in re.finditer(B[m], A[n])]
        #print(span)
        if span==[]:
            continue
        allgood=False
        # フィルタが1行ならYesを返す
        if M==1:
            print("Yes")
            exit()
        for i in range(0, M):
            #print((B[i],A[i][span[0][0]:span[0][1]]))
            if (B[i]==A[n+i][span[0][0]:span[0][1]]):
                allgood=True
                continue
            else:
                allgood=False
                break
        if allgood==True:
            print("Yes")
            exit()

print("No")

### FIXED CODE ###

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

A=[]
B=[]

for n in range(N):
    A.append(input())

for m in range(M):
    B.append(input())
        
if N<M:
    print("No")
    exit()
# check
for n in range(N):
      # Bのm行目と一致
      # Bのm+1行目と一致するかチェック
      span =[m.span() for m in re.finditer(B[0], A[n])]
      #print(span)
      if span==[]:
          continue
      allgood=False
      for sp in span:
        for i in range(min(M,N)):
            if n+i>=N:
                allgood=False
                break
            #print(n)
            #print((B[i],A[n+i][span[0][0]:span[0][1]]))
            if (B[i]==A[n+i][sp[0]:sp[1]]):
                allgood=True
                continue
            else:
                allgood=False
                break
        if allgood==True:
            print("Yes")
            exit()

print("No")
n,q=map(int,input().split())
s=input()
lis=[list(map(int,input().split())) for i in range(q)]
for i in range(q):
  print((len(s[lis[i][0]-1:lis[i][1]])-s[lis[i][0]-1:lis[i][1]].replace('AC',''))//2)

### FIXED CODE ###

n,q=map(int,input().split())
s=input()
lis=[list(map(int,input().split())) for i in range(q)]
g=[0]*n
cnt=0
for i in range(n-1):
  if s[i]=='A' and s[i+1]=='C':
    cnt+=1
    g[i+1]=cnt
  else:
    g[i+1]=cnt

for i in range(q):
  print(g[lis[i][1]-1]-g[lis[i][0]-1])
import math
from functools import reduce

N, X = map(int, input().split())
nums = list(map(int, input().split()))
nums = list(map(lambda i: abs(i - X), nums))

D = reduce(gcd, nums)
print(D)

### FIXED CODE ###

from fractions import gcd
from functools import reduce
n,x = map(int,input().split())
 
l=list(map(int,input().split()))
l=list(map(lambda i: abs(i-x),l))
 
x = reduce(gcd,l)
print(x)
data = input()
data_list = data.split(" ")
if ((data_list[0]*data_list[1])%2 == 0):
  print("Even")
else:
  print("Odd")

### FIXED CODE ###

a,b = map(int, input().split())
if (a * b) % 2 == 0:
  print('Even')
else:
  print('Odd')
total,okasi=map(int,input().split())
sunuke=[]
for i in range(okasi):
  d=int(input())
  A=list(map(int,input().split()))
  for a in A:
    sunuke.append(input())
    
    
ans=total-len(set(sunuke))

print(sunuke)
    
    
    
    

### FIXED CODE ###

total,okasi=map(int,input().split())
sunuke=[]
for i in range(okasi):
  d=int(input())
  A=list(map(int,input().split()))
  for a in A:
    sunuke.append(a)
    
    
ans=total-len(set(sunuke))
 
print(ans)
from collections import deque


def bfs(root):
    Q = deque()
    distance[root] = 0
    Q.append(root)
    i = root
    while len(Q) > 0:
        for v in n:
            if adjMat[i][v] == 1 and color[v] == 'white':
                Q.append(v)
                color[v] = 'gray'
                distance[v] = distance[i] + 1
        color[i] = 'black'
        i = Q.popleft()


n = int(input())
adjMat = [[0] * n for _ in range(n)]
color = ['white'] * n
distance = [-1] * n

for _ in range(n):
    adj = list(map(int, input().split()))
    i = adj[0]
    v = adj[2:]
    for j in v:
        adjMat[i - 1][j - 1] = 1

bfs(0)

for i in range(n):
    out = ''
    out += '{} {}'.format(i + 1, distance[i])
    print(out)

### FIXED CODE ###

from collections import deque


def bfs(root):
    Q = deque()
    distance[root] = 0
    Q.append(root)
    i = root
    while len(Q) > 0:
        i = Q.popleft()
        for v in range(n):
            if adjMat[i][v] == 1 and color[v] == 'white':
                Q.append(v)
                color[v] = 'gray'
                distance[v] = distance[i] + 1
        color[i] = 'black'


n = int(input())
adjMat = [[0] * n for _ in range(n)]
color = ['white'] * n
distance = [-1] * n

for _ in range(n):
    adj = list(map(int, input().split()))
    i = adj[0]
    v = adj[2:]
    for j in v:
        adjMat[i - 1][j - 1] = 1

bfs(0)

for i in range(n):
    out = ''
    out += '{} {}'.format(i + 1, distance[i])
    print(out)
N = int(input())
# スペース区切りの整数の入力
A = list(map(int, input().split()))
C=list(set(A))

#print(A)
print(C)
def gcd(a, b):
  while b > 0:
    a, b = b, a%b
  return a

anslist=[]

if len(C)==1:
  ans=C[0]

elif len(C)==2:
  sol=max(A[0],A[1])

else:
  for i in range(3):
    B=A[:]
    B.remove(C[i])
    sol=0
    for b in B:
        sol=gcd(sol,b)
    anslist.append(sol)
    ans=max(anslist)

print(anslist)
print(ans)



### FIXED CODE ###

N = int(input())
# スペース区切りの整数の入力
A = list(map(int, input().split()))


def gcd(a, b):
  while b > 0:
    a, b = b, a%b
  return a

list1=[0]
L=0
for a in A:
    L=gcd(L,a)
    list1.append(L)

list2=[0]
R=0
for a in reversed(A):
    R=gcd(R,a)
    list2.append(R)

list2.reverse()

ans=[]

for i in range(N):
    ans.append(gcd(list1[i],list2[i+1]))

print(max(ans))
S = input()
T = input()

ans = len(T)

for i in range(len(S) - len(T) + 1):
    diff = 0
    for j in range(len(T)):
        if T[i] != S[j]:
            diff += 1
        ans = min(ans, diff)
        
print(ans)

### FIXED CODE ###

S = input()
T = input()

ans = len(T)

for i in range(len(S) - len(T) + 1):
    diff = 0
    for j in range(len(T)):
        if T[j] != S[i+j]:
            diff += 1
            
    ans = min(ans, diff)

print(ans)
n = int(input())
l = list(map(int, input().split(' ')))
if max(l) < sum(l) - max(l):
  print('Yes')
else
  print('No')


### FIXED CODE ###

n = int(input())
l = list(map(int, input().split(' ')))
if max(l) < sum(l) - max(l):
  print('Yes')
else:
  print('No')
N=int(input())

sum=0
if len(str(N))%2==0:
    for i in range(int(len(str(N))/2)):
        sum += 9*10**(i*2)
else:
    for i in range(len(str(N))//2):
        sum += 9*10**i
    sum += N-int("9"*(len(str(N))-1))

print(sum)


### FIXED CODE ###

N=int(input())

step = sum([90*100**i for i in range(len(str(N))//2)])
dance_floor = sum([9*100**i for i in range(len(str(N))//2)])

ans = len(str(N))%2 * (N-step)  +  -1*(len(str(N))%2-1) * dance_floor
print(ans)
A=int(input());B=int(input());print(max(A+B,A-B,A+B))

### FIXED CODE ###

A,B=map(int,input().split());print(max(A+B,A-B,A*B))
A = input()
B = input()
if int(A) <= 8 and int(B) <= 8:
    print('Yay!')
if 9 <= int(A) <=16 or 9 <= int(B) <= 16: 
    print(':(')

### FIXED CODE ###

A, B = map(int, input().split())
if A <= 8 and B <= 8:
    print('Yay!')
else:
    print(':(')
# coding: utf-8
# Your code here!
from functools import lru_cache

n,k = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]
a.sort()

# 1:先手　-1:後手
@lru_cache(maxsize=None)
def dp(x):
    for i in a:
        if x < i:
            return -1
        else:
            if dp(x-i) == -1:
                return 1
    return -1


if dp(k)==1:
    print("First")
else:
    print("Second")






    




### FIXED CODE ###

# coding: utf-8
# Your code here!
import sys
sys.setrecursionlimit(10**7)

n,k = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]
a.sort()

# 1:先手　-1:後手
memo = [0]*(k+1)
def dp(x):
    if memo[x] != 0:
        return memo[x]
    for i in a:
        if x < i: break
        else:
            if dp(x-i) == -1:
                memo[x] = 1
                return 1
    memo[x] = -1
    return -1

if dp(k)==1:
    print("First")
else:
    print("Second")
int a=input()
res = 0
for i in range(1,1000):
  for j in range(2,10):
    if res>i**j and i**j<=a;
      res=i**j
print(res)

### FIXED CODE ###

a=int(input())

res=0

for i in range(1,1000):
    for j in range(2,10):
        if res<i**j and i**j<=a:
            res=i**j

print(res)
x = input().split()

y = x[0] + x[1] + x[2]

if y % 4 == 0:
    print("YES")
else:
    print("NO")



### FIXED CODE ###

x = input().split()

y = int(x[0]) * 100 + int(x[1]) * 10 + int(x[2])

if y%4 == 0:
    print("YES")
else:
    print("NO")
n=int(input())
a=map(int,input().split()))
print(max(a)-min(a))

### FIXED CODE ###

n=int(input())
a=list(map(int,input().split()))
print(max(a)-min(a))
from math import inf

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

costs = [inf]*n
costs[0] = 0

for i in range(n):
	for j in (i+1, i+2):
		if j < n:
			costs[j] = min(costs[j], costs[i]+abs(h[i]-h[j]))
print(c[-1])

### FIXED CODE ###

from math import inf

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

costs = [inf]*n
costs[0] = 0

for i in range(n):
	for j in (i+1, i+2):
		if j < n:
			costs[j] = min(costs[j], costs[i]+abs(h[i]-h[j]))
print(costs[-1])
inputA = map(int, input())

flag = 0
for count in range(inputA+1,300000):
    for mod in range(2,10000):
        if count % mod == 0:
            flag = mod
            break
        mod += 1
    if count == flag:
        print(count)
        break
    else:
        count += 1


### FIXED CODE ###


inputA = int(input())

flag = 0
for count in range(inputA,300000):

    for mod in range(2,200000):
        if count % mod == 0:
            flag = mod
            break
        mod += 1
    if count == flag:
        print(count)
        break
    elif flag == 0:
        print(inputA)
    else:
        count += 1
n=int(input())
r=list(range(1,n+1))

#print(r)
print(sum(r)-(n))

### FIXED CODE ###

n=int(input())
sumNum=n*(n-1)//2

#print(r)
print(sumNum)
x, y, a, b, c = map(int, input().split())
p = sorted(map(int, input().split()))
q = sorted(map(int, input().split()))
r = sorted(map(int, input().split()))
v = 0

for _ in range(x):
    if len(r):
        if p[-1] > r[-1]:
            v += p.pop()
        else:
            v += r.pop()
    else:
        v += p.pop()

for _ in range(y):
    if len(r):
        if q[-1] > r[-1]:
            v += q.pop()
        else:
            v += r.pop()
    else:
        v += r.pop()

print(v)


### FIXED CODE ###

x, y, a, b, c = map(int, input().split())
p = sorted(map(int, input().split()), reverse=True)
q = sorted(map(int, input().split()), reverse=True)
r = sorted(map(int, input().split()))
v = 0
c = sorted(p[0:x] + q[0:y])
for i in range(x + y):
    if len(r):
        if c[i] < r[-1]:
            c[i] = r.pop()
    else:
        break
print(sum(c))
from collections import deque

N,M = [int(v) for v in input().split()]
ad_list = [[] for _ in range (N+1)]
ad_num = [0 for _ in range(N)]
topo = []

for _ in range(M):
    l,r = [int(v) for v in input().split()]
    ad_list[l].append(r)
    ad_num[r-1] += 1

for i in range(1,N+1):
    if ad_num[i-1] == 0:
        topo.append(i)
queue = deque(topo[:])
while queue:
    n1 = queue.popleft()
    for n2 in ad_list[n1]:
        ad_num[n2-1] -= 1
        if ad_num[n2-1] == 0:
            topo.append(n2)
            queue.append(n2)
visited = [False for _ in range(N+1)]

ans = 0
path_len = 0
def dfs(node,cnt=0):
    global ans
    if visited[node]: return 0
    visited[node] = True
    ans = max(ans,cnt)
    for n in ad_list[node]:
        dfs(n,cnt+1)
    visited[node] = False

for n in topo:
    dfs(n)
print(ans)


### FIXED CODE ###

from collections import deque

N,M = [int(v) for v in input().split()]
ad_list = [[] for _ in range (N+1)]
ad_num = [0 for _ in range(N)]
topo = []

for _ in range(M):
    l,r = [int(v) for v in input().split()]
    ad_list[l].append(r)
    ad_num[r-1] += 1

for i in range(1,N+1):
    if ad_num[i-1] == 0:
        topo.append([i,0])
queue = deque(topo[:])
while queue:
    n1,cnt = queue.popleft()
    for n2 in ad_list[n1]:
        ad_num[n2-1] -= 1
        if ad_num[n2-1] == 0:
            topo.append([n2,cnt+1])
            queue.append([n2,cnt+1])
print(max([v[1] for v in topo]))
from itertools import accumulate
from collections import Counter
n,m=map(int,input().split())
s=[0]+list(map(lambda x:x%m,list(accumulate(list(map(int,input().split()))))))
ans=0
for i in Counter(s):
    ans+=(d[i]*(d[i]-1)//2)
print(ans)

### FIXED CODE ###

from itertools import accumulate
from collections import Counter
import math

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

n,m=map(int,input().split())
s=list(map(lambda x:x%m,list(accumulate(list(map(int,input().split()))))))
s.append(0)
#print(s)
d=Counter(s)
#print(d)
ans=0
for i in d:
    if d[i]>=2:
        ans+=combinations_count(d[i],2)
print(ans)
a=int(input())
b=int(input())
c=[1,2,3]
c.pop(a)
c.pop(b)
print(c[0])

### FIXED CODE ###

a=int(input())
b=int(input())
c=[1,2,3]
c.pop(c.index(a))
c.pop(c.index(b))
print(c[0])
import math
n = int(input())
a1 = list(map(int, input().split()))
a2 = list(map(int, input().split()))
p1, p2, p3, p4 = 0, 0, 0, 0
hyp = 0
for i in range(n):
    p1 += math.fabs(a1[i] -a2[i])
    p2 += (a1[i]-a2[i])**2
    p3 += math.fabs((a1[i]-a2[i])**3)
    hyp = math.fabs(a1[i] -a2[i]) 
    if hyp > p4:
        p4 = hyp

p2 = math.sqrt(p2)
p3 = math.exp(math.log(p3)/3)
print(p1)
print(p2)
print(p3)
print(p4)

### FIXED CODE ###

import math
n = int(input())
a1 = list(map(int, input().split()))
a2 = list(map(int, input().split()))
p1, p2, p3, p4 = 0, 0, 0, 0
hyp = 0
for i in range(n):
    p1 += math.fabs(a1[i] -a2[i])
    p2 += (a1[i]-a2[i])**2
    p3 += math.fabs((a1[i]-a2[i])**3)
    hyp = math.fabs(a1[i] -a2[i]) 
    if hyp > p4:
        p4 = hyp

p2 = math.sqrt(p2)
if p3 != 0:
    p3 = math.exp(math.log(p3)/3)
print(p1)
print(p2)
print(p3)
print(p4)
import math

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


A, B, C, D = map(int, input().split())
target = B - A + 1

hoge1 = int(B / C) - int((A - 1) / C)
hoge2 = int(B / D) - int((A - 1) / D)
hoge3 = int(B / (C * D)) - int((A - 1) / (C * D))

saisho = lcm(C, D)
hoge4 = B // saisho - (A - 1) // saisho

print(target - hoge1 - hoge2 + hoge4)

### FIXED CODE ###

def gcd(a,b):
    while b!=0:
        a,b=b,a%b
    return a
    
def lcm(x, y):
    return (x * y) // gcd(x, y)


A, B, C, D = map(int, input().split())
target = B - A + 1

hoge1 = B // C - (A - 1) // C
hoge2 = B // D - (A - 1) // D
hoge3 = B // (C * D) - (A - 1) // (C * D)

saisho = lcm(C, D)
hoge4 = B // saisho - (A - 1) // saisho

print(target - hoge1 - hoge2 + hoge4)
N = int(input())
A = [int(x) for x in input().split()]
tmp = list()
for n in range(len(A)):
  tmp.append([n+1, A[n]])
tmp = sorted(tmp, key=lambda x: x[1])
res = ""
for x in tmp:
  res.append(x[0])
print(*res)

### FIXED CODE ###

N = int(input())
A = [int(x) for x in input().split()]
tmp = list()
for n in range(len(A)):
  tmp.append([n+1, A[n]])
tmp = sorted(tmp, key=lambda x: x[1])
res = []
for x in tmp:
  res.append(x[0])
print(*res)
n, m, d = list(map(float, input().split()))
if (d == 0):
  	ans = 1 / n
    print(ans)
else:
  ans = 2 * (n - d) / n ** 2
  print(ans)

### FIXED CODE ###

n, m, d = list(map(int, input().split()))
if (d == 0):
  ans = (m - 1) * (1 / n)
  print(ans)
else:
  ans = (m - 1) * (2 * (n - d) / n ** 2)
  print(ans)
X , N = map(int, input().split())
p = list(map(int,input().split()))
ans = []
if N == 0:
    print(X)
else:
    p = sorted(p)
    p2 = [abs(i-X) for i in p]

    for i in range(p[p2.index(min(p2))],p[p.index(max(p))]+1):
        if i  not in p:
            ans.append(i)
            break
    for i in range(p[p2.index(min(p2))], p[p.index(min(p))]+1, -1):
        if i not in p:
            ans.append(i)
            break
 
    print(min(ans))




### FIXED CODE ###

X , N = map(int, input().split())
p = list(map(int,input().split()))
ans = []
if N == 0:
    print(X)
elif X not in  p:
    print(X)
else:
    p = sorted(p)
    p2 = [abs(i-X) for i in p]

    for i in range(p[p2.index(min(p2))],102):
        if i not in p:
            ans.append(i)
            break
    for i in range(p[p2.index(min(p2))], -100, -1):
        if i not in p:
            ans.append(i)
            break
    
    ans = sorted(ans)
    ans2 = [abs(i-X) for i in ans]
    print(ans[ans2.index(min(ans2))])
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
  elif n in (0, 1):
    return 1
  else:
    return (comb(n-1) + comb(n-2))%(10**9 + 7)

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))
N = int(input())

min = 999999

A = 0
B = 0

def digitSum(n):
    s = str(n)
    array = list(map(int, list(s)))
    return sum(array)



for i in range(1, N/2):
    a = i
    b = N - i

    if min > digitSum(a) + digitSum(b):
        min = digitSum(a) + digitSum(b)   

print(min)

### FIXED CODE ###

N = int(input())
min = 999999

A = 0
B = 0

def digitSum(n):
    s = str(n)
    array = list(map(int, list(s)))
    return sum(array)

for i in range(1, N/2+1):
    a = i
    b = N - i

    if min > digitSum(a) + digitSum(b):
        min = digitSum(a) + digitSum(b)   

print(min)
m,d=map(int,input().split())
def fac(n):
  a=1
  if n==1:
    return a
  else:
    a=n*fac(n-1)
    return a%(10**9+7)
if abs(m-d)>=2:
  print(0)
elif abs(m-d)==1:
  print((fac(m)*fac(d))%(10**9+7))
else:
  print(2*(fac(m)**2)%(10**9+7))

### FIXED CODE ###

import sys
sys.setrecursionlimit(10**6)
m,d=map(int,input().split())
def fac(n):
  a=1
  if n==1:
    return a
  else:
    a=n*fac(n-1)
    return a%(10**9+7)
if abs(m-d)>=2:
  print(0)
elif abs(m-d)==1:
  print((fac(m)*fac(d))%(10**9+7))
else:
  print(2*(fac(m)**2)%(10**9+7))
s = list(input())
n = len(s)
k = ['R','U','D']
g = ['L','U','D']

for i in range(n):
    if i % 2 ==0:
        new =[s[i] in k]
    else:
        new1 =[s[i] in g]
       
if new == [True] and new1 == [True]:
    print("Yes")
else:
    print("No")


### FIXED CODE ###

s = list(input())
n = len(s)
k = ['R','U','D']
g = ['L','U','D']
count =0

for i in range(n):
    if i % 2 ==0:
        if s[i] in k:
            count +=1
    else:
        if s[i] in g:
            count += 1
       
if count == n:
    print("Yes")
else:
    print("No")
N=int(input())
A=list(input().split())

shusseki_jun=['' for _ in range(N)]
for i in range(N):
    shusseki_jun[i] = str(A.index(str(i+1))+1)
print(' '.join(shusseki_jun))


### FIXED CODE ###

N=int(input())
if N%2 ==0:
    print(0.5)
else:
    print((N//2+1)/N)
import strutils;var n,a=stdin.readline.split;echo if a.contains("Y"):"Four"else:"Three"

### FIXED CODE ###

n, *s = open(0).read().split()
if "Y" in s: print("Four")
else: print("Three")
N,K = map(int, input().split())
A = list(map(int, input().split()))
for a in A:
a = (1+a)/2
sumK = []

for i in range(len(A)):
  b = A[i:i+K]
  sumK.append(sum(b))
print(max(sumK))


### FIXED CODE ###

import sys
input = sys.stdin.readline

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

    tmp_max = sum(P[:K])
    tmp = sum(P[:K])
    for i in range(N-K):
        tmp += P[i+K]
        tmp -= P[i]

        if tmp > tmp_max:
            tmp_max = tmp

    print((tmp_max + K) / 2)

main()
A=list(map(int,input().split()))
a=[]
for n in range(0,101):
  for m in range(0,101):
    if n+m=A[0] & 2*n+4*m=A[1]:
      a.append(1)
    else:
      a.append(0)
      
if 1 in a:
  print('yes')
else:
  print('No')
      
  


### FIXED CODE ###

X, Y = map(int, input().split()) 
ans = 'No'
for a in range(X + 1):
	b=X-a
	if 2 * a + 4 * b == Y:
		ans = 'Yes' 
print(ans)
import itertools

while 1:
    n, s = map(int, raw_input().split())
    d = [i for i in xrange(s)]
    if n == 0: break
    x = map(sum, list(itertools.combinations(d, n)))
    print x.count(s)

### FIXED CODE ###

import itertools

d = xrange(10)
while 1:
    n, s = map(int, raw_input().split())
    if n == 0: break
    x = map(sum, list(itertools.combinations(d, n)))
    print x.count(s)
N,K = map(int,input().split())
x_list = list(map(int,input().split()))

split_idx = None
for i,x in enumerate(x_list):
    if x >= 0:
        split_idx = i
        break
if split_idx == None:
    lefts = x_list
    rights = []
else:
    lefts = x_list[:split_idx]
    rights = x_list[split_idx:]

if rights[0]==0:
    K -= 1
    rights = rights[1:]

if K == 0:
    print(0)
else:
    min_time = 10**9
    for left_cnt in range(K):
        right_cnt = K-left_cnt
        if left_cnt > len(lefts) or right_cnt > len(rights):
            continue
        if left_cnt ==0 and right_cnt == 0:
            tmp_time = 0
        elif left_cnt == 0:
            tmp_time = rights[right_cnt-1]
        elif right_cnt == 0:
            tmp_time = lefts[-left_cnt]
        elif -lefts[-left_cnt] >= rights[right_cnt-1]:
            tmp_time = rights[right_cnt-1]*2 + (-lefts[-left_cnt])
        else:
            tmp_time = rights[right_cnt-1] + (-lefts[-left_cnt]) * 2
        if tmp_time < min_time:
            min_time = tmp_time
    print(min_time)

### FIXED CODE ###

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

split_idx = None
for i,x in enumerate(x_list):
    if x >= 0:
        split_idx = i
        break
if split_idx == None:
    lefts = x_list
    rights = []
else:
    lefts = x_list[:split_idx]
    rights = x_list[split_idx:]

if len(rights)>0:
    if rights[0]==0:
        K -= 1
        rights = rights[1:]

if K == 0:
    print(0)
else:
    min_time = 10**9
    for left_cnt in range(K+1):
        right_cnt = K-left_cnt
        if left_cnt > len(lefts) or right_cnt > len(rights):
            continue
        if left_cnt ==0 and right_cnt == 0:
            tmp_time = 0
        elif left_cnt == 0:
            tmp_time = rights[right_cnt-1]
        elif right_cnt == 0:
            tmp_time = -lefts[-left_cnt]
        elif -lefts[-left_cnt] >= rights[right_cnt-1]:
            tmp_time = rights[right_cnt-1]*2 + (-lefts[-left_cnt])
        else:
            tmp_time = rights[right_cnt-1] + (-lefts[-left_cnt]) * 2
        if tmp_time < min_time:
            min_time = tmp_time
    print(min_time)
#!/usr/bin/env python3

# from numba import njit
from math import gcd
# input = stdin.readline

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

# @njit
def solve(n,m,s,t):
  L = lcm(n,m)
  
  lst = [""]*L
  s_interval = L//n
  t_interval = L//m
  for i in range(n):
    lst[i*s_interval] = s[i]
  for i in range(m):
    if lst[i*t_interval] =="":
      continue
    if lst[i*t_interval] != t[i]:
      return -1
  return L
  
  
  return n



def main():
  N,M = map(int,input().split())
  s = input()
  t = input()
  print(solve(N,M,s,t))
  return

if __name__ == '__main__':
  main()


### FIXED CODE ###

#!/usr/bin/env python3

# from numba import njit
from math import gcd
# input = stdin.readline

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

# @njit
def solve(n,m,s,t):
  L = lcm(n,m)
  G = gcd(n,m)
  s_interval = L//n
  t_interval = L//m
  for i in range(G):
    if s[i*n//G] != t[i*m//G]:
      return -1
  return L
  

def main():
  N,M = map(int,input().split())
  s = input()
  t = input()
  print(solve(N,M,s,t))
  return

if __name__ == '__main__':
  main()
#coding: shift_jis
N = int(raw_input())
S = raw_input()
x = 0
y = [x]
for i in range(N-1):
    if S[i] == 'I':
        x += 1
    elif S[i] == 'D':
        x -= 1
    y.append(x)
print max(y)

### FIXED CODE ###

#coding: shift_jis

A,B,C,D = map(int,raw_input().split())

if A*B > C*D:
    print A*B
elif A*B < C*D:
    print C*D
else:
    print A*B
H = int(input())
x = 2
for i in range(40):
  if x <= H and x*2 > H:
    ans = x*2 - 1
    break
  x = x*2
  
if x == 1:
  ans = 1

print(ans)

### FIXED CODE ###

H = int(input())
x = 2
for i in range(41):
  if x <= H and x*2 > H:
    ans = x*2 - 1
    break
  x = x*2
  
if H == 1:
  ans = 1

print(ans)
if S = 'ABC':
 print('ARC')
else:
 print('ABC')

### FIXED CODE ###

s=input()
print("ABC" if s=="ARC" else "ARC")