Harryxun/stf_run huggingface dataset:
# -*- coding: utf-8 -*-
import sys
import copy
import collections
from bisect import bisect_left
from bisect import bisect_right
from collections import defaultdict
from heapq import heappop, heappush
import math

# NO, PAY-PAY
#import numpy as np
#import statistics
#from statistics import mean, median,variance,stdev

def inputInt(): return int(input())
def inputMap(): return map(int, input().split())
def inputList(): return list(map(int, input().split()))
 
def main():
    S = list(input())
    T = list(input())
    
    isOk = False
    for i in range(len(S)):
        if S[i] == "?":
            continue
        
        flg = True
        for j in range(len(T)):
            
            #print("{} {}".format(S[i+j], T[i]))
            
            if S[i+j] != T[j]:
                if S[i+j] != "?":
                    flg = False
                    break
                
        if flg == True:
            isOk = True
            for j in range(len(T)):
                S[i+j] = T[j]
    
    if isOk == False:
        print("UNRESTORABLE")
    else:
        for i in range(len(S)):
            if S[i] == "?":
                S[i] = "a"
        print("".join(S))
    
            	
if __name__ == "__main__":
	main()


### FIXED CODE ###

# -*- coding: utf-8 -*-
import sys
import copy
import collections
from bisect import bisect_left
from bisect import bisect_right
from collections import defaultdict
from heapq import heappop, heappush
import math

# NO, PAY-PAY
#import numpy as np
#import statistics
#from statistics import mean, median,variance,stdev

def inputInt(): return int(input())
def inputMap(): return map(int, input().split())
def inputList(): return list(map(int, input().split()))
 
def main():
    S = list(input())
    T = list(input())
    
    ind = []
    isOk = False
    
    for i, val in enumerate(S):
        if val == "?" or val == T[0]:
            flg = True
            if len(S)-i < len(T):
                #print(val)
                #print("{} {}".format(len(S)-i, len(T)))
                break
            for j, vol in enumerate(T):
                if S[i+j] != T[j] and S[i+j] != "?":
                    flg = False
                    break
            if flg == True:
                ind.append(i)
                isOk = True
                
    if isOk == False:
        print("UNRESTORABLE")
    else:
        ind.sort()
        tmp = ind[-1]
        for i, val in enumerate(S):
            if i == tmp:
                for j, vol in enumerate(T):
                    S[i+j] = T[j]
            else:
                if val == "?":
                    S[i] = "a"
        print("".join(S))
    
            	
if __name__ == "__main__":
	main()
import math

A,B,N=map(int,input().split())
ans=[0]*N
for x in range(0,N+1):
    a=math.floor(((A*x)/B))
    b=A*math.floor((x/B))
    ans[x-1]+=a-b
print(max(ans))

### FIXED CODE ###

A,B,N=map(int,input().split())
x=min(B-1,N)
print(int(A*x/B)-int(x/B)*A)
C,D = [int(e) for e in input().split()]
if C <= D:
    m = D
    n = C
else:
    m = C
    n = D
while  n != 0 :
    a = m%n
    m = n
    n = a
J = []
for i in range(1,int(m**0.5)+1):　#与えられた2整数の最大公約数を元に公約数を列挙している.
    if m % i == 0:
        J.append(i)
        if i != m//i:
            J.append(m//i)
J.sort()
#N = int(len(J))
count = 1
#I = []
for j in J:　　　#公約数のうちどれとも互いに素であるもの、すなわち素数を探している.
    cnt = 0
    for p in range(1,int(j**0.5)+1):
        if j%p == 0:
            cnt += 1
            if cnt >=2:
                break
    if cnt == 1:
        count += 1
print(count)

### FIXED CODE ###

C,D = [int(e) for e in input().split()]

if C <= D:
    m = D
    n = C
else:
    m = C
    n = D

while  n != 0 :
    a = m%n
    m = n
    n = a

J = []

for i in range(1,int(m**0.5)+1):
    if m % i == 0:
        J.append(i)
        if i != m//i:
            J.append(m//i)


J.sort()

N = int(len(J))
M = [1]
I = []

for i in range(1,N):
    for p in range(1,int(J[i]**0.5)+1):
        if J[i]%p == 0:
            I.extend([J[i]])
            if int(len(I)) >=2:
                break
    if int(len(I)) == 1:
        M.extend([J[i]])
    I = []


M = int(len(M))

print(M)
A,B=map(str,input().split())
#print(sorted(B)[0])
print((A+B)%24)

### FIXED CODE ###

A,B=map(int,input().split())
#print(sorted(B)[0])
print((A+B)%24)
N, K = map(int, input().split())
TD = []
for _ in range(N):
    t, d = map(int, input().split())
    TD.append((t-1, d))

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

import heapq

Tcount = [0]*N
chosen = []
heapq.heapify(chosen)

tot = 0
num_kinds = 0
ans = [0]*(N+1)

for i in range(K):
    t, d = TD[i]
    tot += d
    Tcount[t] += 1
    if Tcount[t] == 1: 
        num_kinds += 1
    if Tcount[t] > 1:
        heapq.heappush(chosen, d)

ans[num_kinds] = tot + num_kinds**2

for i in range(K, N):
    t, d = TD[i]
    if Tcount[t] > 0: continue
    Tcount[t] += 1
    num_kinds += 1
    tot = tot - heapq.heappop(chosen) + d
    ans[num_kinds] = tot + num_kinds**2
    if len(chosen) == 0:
        break

print(max(ans))

### FIXED CODE ###

N, K = map(int, input().split())
TD = []
for _ in range(N):
    t, d = map(int, input().split())
    TD.append((t-1, d))

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

import heapq

Tcount = [0]*N
chosen = []
heapq.heapify(chosen)

tot = 0
num_kinds = 0
ans = [0]*(N+1)

for i in range(K):
    t, d = TD[i]
    tot += d
    Tcount[t] += 1
    if Tcount[t] == 1: 
        num_kinds += 1
    if Tcount[t] > 1:
        heapq.heappush(chosen, d)

ans[num_kinds] = tot + num_kinds**2

for i in range(K, N):
    if len(chosen) == 0: break
    t, d = TD[i]
    if Tcount[t] > 0: continue
    Tcount[t] += 1
    num_kinds += 1
    tot = tot - heapq.heappop(chosen) + d
    ans[num_kinds] = tot + num_kinds**2
    
print(max(ans))
n = int(input())
print(len(set([input() for a in range(m)])))

### FIXED CODE ###

n = int(input())
print(len(set([int(input()) for _ in range(n)])))
n = list(map(int, input().split()))
print(min(n[1], n[2]), max(0, n[1] - n[2a

### FIXED CODE ###

n = list(map(int, input().split()))
print(min(n[1], n[2]), max(0, n[1] + n[2] - n[0]))
n=int(input())
arr=[int(i) for i in input().strip().split(" ")]
arr=sorted(arr)
arr=arr[::-1]
newArr=[arr[0]]
ans=0
for i in range(1,n//2):
    newArr.append(arr[i])
    newArr.append(arr[i])
for i in range(n-1):
    ans+=newArr[i]
print(ans)


### FIXED CODE ###

n=int(input())
arr=[int(i) for i in input().strip().split(" ")]
arr=sorted(arr)
arr=arr[::-1]
# newArr=[arr[0]]
ans=0
# for i in range(1,n//2):
#     newArr.append(arr[i])
#     newArr.append(arr[i])
for i in range(1,n):
    # print()
    ans+=arr[i//2]
print(ans)
import copy
n,k=map(int,input().split())
a=list(map(int,input().split()))
maxed={}
for m in range(0,k):
    temp=[0]*n
    if len(maxed)==n:
        print(' '.join(map(str,a)))
        exit()
    for i in range(0,n):
        d=a[i]
        if d==n:
            temp[i]=n
            maxed[i]=1
        elif d !=0 :
            for x in range(i-d, i+d+1):
                if x >= 0 and x < n :
                    temp[x]+=1
        else:
            temp[i]+=1
    a=copy.copy(temp)

print(' '.join(map(str,a)))


### FIXED CODE ###

a=[]
a=input()
print('%s%s%s'%(a[0],a[1],a[2]))
# 二部グラフ判定
def dfs(u, c):
    color[u] = c  # 訪問したら指定の色で塗る
    for v in G[u]:  # uからつながっている頂点を順に取り出す
        if color[v] != -1:  # すでに訪問していた場合
            if color[v] == c:
                return False  # 隣接する頂点が同じ色のときはFalse
            else:
                continue
        else:  # 未訪問の時は色は違う色にしてDFSで再帰的に探索
            if not dfs(v, 1 - c):  # FalseだったらFalseを返す
                return False
    return True


# 頂点数と辺数を入力
N, M = map(int, input().split())
# グラフの入力
G = [[] for _ in range(N)]  # 頂点数Nだけ準備
color = [-1] * N  # 未訪問は-1とする
for _ in range(M):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    G[a].append(b)
    G[b].append(a)
# 探索
flag = True
for i in range(N):
    if color[i] == -1:
        if not dfs(i, 0):
            flag = False
            break
if flag:
    ans = color.count(1) * color.count(0) - M
else:
    ans = N * (N - 1) // 2 - M
print(ans)


### FIXED CODE ###

import sys
sys.setrecursionlimit(1000000)

# 二部グラフ判定
def dfs(u, c):
    color[u] = c  # 訪問したら指定の色で塗る
    for v in G[u]:  # uからつながっている頂点を順に取り出す
        if color[v] != -1:  # すでに訪問していた場合
            if color[v] == c:
                return False  # 隣接する頂点が同じ色のときはFalse
            else:
                continue
        else:  # 未訪問の時は色は違う色にしてDFSで再帰的に探索
            if not dfs(v, 1 - c):  # FalseだったらFalseを返す
                return False
    return True


# 頂点数と辺数を入力
N, M = map(int, input().split())
# グラフの入力
G = [[] for _ in range(N)]  # 頂点数Nだけ準備
color = [-1] * N  # 未訪問は-1とする
for _ in range(M):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    G[a].append(b)
    G[b].append(a)
# 探索
flag = True
for i in range(N):
    if color[i] == -1:
        if not dfs(i, 0):
            flag = False
            break
if flag:
    ans = color.count(1) * color.count(0) - M
else:
    ans = N * (N - 1) // 2 - M
print(ans)
import copy
n = int(input())
x = list(map(int, input().split()))

for i in range(n):
    x_in  = copy.deepcopy(x)
    del x_in[i]
    x_in.sort()
    print(x_in[int(n/2 -1)])
    x_in  = []


### FIXED CODE ###

a, b, x = map(int, input().split())
if x<a: print('NO')
elif x>a+b: print('NO')
else:print('YES')
import numpy as np
K, N = map(int, input().split())
A = list(map(int, input().split()))
new = []
for i in range(N-1):
    new.append(A[i+1]-A[i])
new.append(K + A[0] - A[-1])
new.sort()
print(sum(new[:y-1]))

### FIXED CODE ###

K, N = map(int, input().split())
A = list(map(int, input().split()))
new = []
for i in range(N-1):
    new.append(A[i+1]-A[i])
new.append(K + A[0] - A[-1])
new.sort()
print(sum(new[:-1]))
# E
N = int(input())
P_list = list(map(int, input().split()))
X_list = list(map(int, input().split()))

# graph
child_list = [[] for _ in range(N+1)]
for i in range(2, N+1):
    child_list[P_list[i-2]].append(i)

# from root
# minimize local total weight

color1 = [0]+X_list
color2 = [0]*(N+1)

# solve knapsack
def solve_knapsack(L, M):
    min_acc = sum([min(color1[j], color2[j]) for j in L])
    if min_acc > M:
        return -1
    else:
        add_can = M - min_acc
        add_set = set([0])
        for j in L:
            add_j = max(color1[j], color2[j]) - min(color1[j], color2[j])
            add_set_ = set(add_set)
            for s in add_set:
                if s + add_j <= add_can:
                    add_set_.add(s + add_j)
            add_set = add_set_
        
        total = sum([color1[j]+color2[j] for j in L])
        return total - max(add_set)

res = "POSSIBLE"

for i in range(N, 0, -1):
    if len(child_list[i]) == 0:
        pass
    elif len(child_list[i]) == 1:
        j = child_list[i][0]
        if min(color1[j], color2[j]) > X_list[i-1]:
            res = "IMPOSSIBLE"
            break
        elif max(color1[j], color2[j]) > X_list[i-1]:
            color2[i] = max(color1[j], color2[j])
        else:
            color2[i] = min(color1[j], color2[j])
    else:
        c2 = solve_knapsack(child_list[i], X_list[i-1])
        if c2 < 0:
            res = "IMPOSSIBLE"
            break
        else:
            color2[j] = c2
    
print(res)

### FIXED CODE ###

# E
N = int(input())
P_list = list(map(int, input().split()))
X_list = list(map(int, input().split()))

# graph
child_list = [[] for _ in range(N+1)]
for i in range(2, N+1):
    child_list[P_list[i-2]].append(i)

# from root
# minimize local total weight

color1 = [0]+X_list
color2 = [0]*(N+1)

# solve knapsack
def solve_knapsack(L, M):
    min_acc = sum([min(color1[j], color2[j]) for j in L])
    if min_acc > M:
        return -1
    else:
        add_can = M - min_acc
        add_set = set([0])
        for j in L:
            add_j = max(color1[j], color2[j]) - min(color1[j], color2[j])
            add_set_ = set(add_set)
            for s in add_set:
                if s + add_j <= add_can:
                    add_set_.add(s + add_j)
            add_set = add_set_
        
        total = sum([color1[j]+color2[j] for j in L])
        return total - max(add_set) - min_acc

res = "POSSIBLE"

for i in range(N, 0, -1):
    if len(child_list[i]) == 0:
        pass
    elif len(child_list[i]) == 1:
        j = child_list[i][0]
        if min(color1[j], color2[j]) > X_list[i-1]:
            res = "IMPOSSIBLE"
            break
        elif max(color1[j], color2[j]) > X_list[i-1]:
            color2[i] = max(color1[j], color2[j])
        else:
            color2[i] = min(color1[j], color2[j])
    else:
        c2 = solve_knapsack(child_list[i], X_list[i-1])
        if c2 < 0:
            res = "IMPOSSIBLE"
            break
        else:
            color2[i] = c2
    
print(res)
def integerCards(n, m, alist, bclist):

    count = 0
    alist.sort()
    bclist.sort(key=lambda x: x[1], reverse=True)

    for b, c in bclist:
        for _ in range(b):
            if alist[count] < c:
                alist[count] = c
                count += 1
            if count == n - 1:
                break

    return sum(alist)

def main():
    n, m = map(int, input().split())
    alist = list(map(int, input().split()))
    bclist = [list(map(int, input().split()))for i in range(m)]
    print(integerCards(n, m, alist, bclist))

if __name__ == '__main__':
    main()

### FIXED CODE ###

def integerCards(n, m, alist, bclist):

    count = 0
    alist.sort()
    bclist.sort(key=lambda x: x[1], reverse=True)

    for b, c in bclist:
        for _ in range(b):
            if alist[count] < c:
                alist[count] = c
                count += 1
            else:
                break
            if count == n:
                break
        if count == n:
            break

    return sum(alist)

def main():
    n, m = map(int, input().split())
    alist = list(map(int, input().split()))
    bclist = [list(map(int, input().split()))for i in range(m)]
    print(integerCards(n, m, alist, bclist))

if __name__ == '__main__':
    main()
import sys
input = sys.stdin.readline
N, Q = map(int, input().split())
G = [[] for _ in [0]*N]
for _ in [0]*(N-1):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    G[a].append(b)
    G[b].append(a)

cnt = [0]*N
pre = [-1]*N
k = 0


def init(v=0, p=-1):
    global k
    pre[v] = k
    k += 1

    for u in G[v]:
        if u == p:
            continue
        init(u, v)


def dfs(v, x):
    cnt[v] += x
    for u in G[v]:
        if pre[v] > pre[u]:
            continue
        dfs(u, x)
    return


init()
for _ in [0]*Q:
    p, x = map(int, input().split())
    dfs(p-1, x)

print(*cnt)


### FIXED CODE ###

# AtCoder Beginner Contest 138
# D - Ki
# https://atcoder.jp/contests/abc138/tasks/abc138_d
import sys
sys.setrecursionlimit(10**6)

input = sys.stdin.readline
N, Q = map(int, input().split())

G = [[] for _ in [0]*N]
for _ in range(N-1):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    G[a].append(b)
    G[b].append(a)

counter = [0]*N

for _ in range(Q):
    p, x = map(int, input().split())
    counter[p-1] += x

visited = [False]*N


def dfs(v=0, x=0):
    visited[v] = True
    counter[v] += x
    for u in G[v]:
        if visited[u]:
            continue
        dfs(u, counter[v])


dfs()
print(*counter)
S=intput()

if S=="ABC":
  print("ARC")
else:
  print("ABC")


### FIXED CODE ###

S=input()

if S=="ABC":
  print("ARC")
else:
  print("ABC")
n_str = input()
n_list = list(n_str)
n_list_reverse = list(n_str)
n_list_reverse.reverse()
if n_list == n_list_reverse():
    print("Yes")
else:
    print("No")

### FIXED CODE ###

n_str = input()
n_list = list(n_str)
n_list_reverse = list(n_str)
n_list_reverse.reverse()
if n_list == n_list_reverse:
    print("Yes")
else:
    print("No")
3 5
 
if X < A:
 print(0)
else:
 print(10)

### FIXED CODE ###

X, A = map(int, input().split())
 
if X < A:
 print(0)
else:
 print(10)
n = int(input())
text = input(list())            # テキストをリストに変換
pattern = list('ABC')          # パターンをリストに変換
cnt = 0

for i in range(n):
    match = True                # 一致しているものとして探索開始
    for j in range(len(pattern)):
        if text[i + j] != pattern[j]:
            match = False       # 一致しなかった
            break
    if match:                   # すべての文字が一致していれば出力
        cnt += 1

print(cnt)

### FIXED CODE ###

n = int(input())
s = input()      
pattern = list('ABC')          
cnt = 0

for i in range(n-len(pattern)+1):
    if s[i] == pattern[0]:
        if s[i+1] == pattern[1]:
            if s[i+2] == pattern[2]:
                cnt += 1

print(cnt)
from bisect import bisect_left, bisect_right
N=int(input())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
C=list(map(int,input().split()))
A.sort()
B.sort()
C.sort()
ans=0
for j in range(N):
    a=bisect_left(a, B[j])
    c=bisect_right(a, B[j])
    ans+=a*c
print(ans)

### FIXED CODE ###

from bisect import bisect_left, bisect_right
N=int(input())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
C=list(map(int,input().split()))
A.sort()
B.sort()
C.sort()
ans=0
for j in range(N):
    a=bisect_left(A, B[j])
    c=bisect_right(C, B[j])
    ans+=a*(N-c)
print(ans)
import numpy as np

n,d=map(int,input().split())
arr=np.array(n)
for i in range(n):
  arr[i]=np.array(list(map(float,input().split())))
ans=0
for i in range(n):
  for j in range(i,n):
    if j!=i:
      k = np.linalg.norm(arr[i]-arr[j],ord=2)
    else:
      k=np.nan
    if k==int(k):
      ans +=1
print(ans)

### FIXED CODE ###

import numpy as np

n,d=map(int,input().split())
arr=[]
for i in range(n):
  arr.append(list(map(int,input().split())))
arr =np.array(arr)
ans=0
for i in range(n):
  for j in range(i,n):
    if j!=i:
      k = np.linalg.norm(arr[i]-arr[j],ord=2)
    else:
      k=0.5
    if k==int(k):
      ans +=1
print(ans)
n,k=map(int,input().split())
h=list(map(int,input().split()))
def ch_min(a,b):
    if a>b:
        return b

def solve():
    dp=[float('inf')]*n
    dp[0]=0

    for i in range(1,n):
    
        for j in range(1,1+k):
            if i-j>=0:
                dp[i]=ch_min(dp[i],dp[i-j]+abs(h[i]-h[i-j]))
                
                
    print(dp[-1])
    

solve()

### FIXED CODE ###

n,k=map(int,input().split())
h=list(map(int,input().split()))
def ch_min(a,b):
    if a>b:
        return b
    
    return a
def solve():
    dp=[float('inf')]*n
    dp[0]=0

    for i in range(1,n):
    
        for j in range(1,1+k):
            if i-j>=0:
                dp[i]=ch_min(dp[i],dp[i-j]+abs(h[i]-h[i-j]))
                
                if dp[i]==0:
                    break
                
    print(dp[-1])
    

solve()
import sys
from itertools import accumulate

def main():
  input=sys.stdin.readline
  n,k=map(int,input().split())
  A=list(map(int,input().split()))
  
  dp=[0]*(k+1)
  dp[0]=1
  for a in A:
    dp=list(accumulate(dp))
    print("accumulated",dp)
    for j,d in enumerate(dp[:k-a],start=a+1):
      dp[j]-=d
    dp=[dpi for dpi in dp]
    print(dp)
"""
def main():
  dp=[[0]*(k+1) for _ in range(n+1)]
  mod=1000000007
  #i人目までに0個配る方法は1通り
  #for i in range(n+1):
  #  dp[i][0]=1
  for i in range(0,n+1):
    for j in range(0,k+1):
      if i==0 and j==0:
        dp[i][j]=1
        break
      if j==0:
        dp[i][j]=1
        continue
      tmp=dp[i - 1][j] + dp[i][j - 1]
      if tmp>=mod:
        tmp%=mod
      dp[i][j]=tmp
      if j-a[i-1]-1>=0:
        tmp=dp[i][j]-dp[i-1][j-a[i-1]-1]
        if tmp>=mod:
          tmp%=mod
        dp[i][j]=tmp
    #print(dp)   
  print(dp[n][k])"""
main()

### FIXED CODE ###

import sys
from itertools import accumulate

def main():
  input=sys.stdin.readline
  n,k=map(int,input().split())
  A=list(map(int,input().split()))
  mod=10**9+7
  dp=[0]*(k+1)
  dp[0]=1
  for a in A:
    dp=list(accumulate(dp))
    #print("accumulated",dp)
    for j,d in enumerate(dp[:k-a],start=a+1):
      dp[j]-=d
    dp=[dpi%mod for dpi in dp]
    #print(dp)
  print(dp[k])
"""
def main():
  dp=[[0]*(k+1) for _ in range(n+1)]
  mod=1000000007
  #i人目までに0個配る方法は1通り
  #for i in range(n+1):
  #  dp[i][0]=1
  for i in range(0,n+1):
    for j in range(0,k+1):
      if i==0 and j==0:
        dp[i][j]=1
        break
      if j==0:
        dp[i][j]=1
        continue
      tmp=dp[i - 1][j] + dp[i][j - 1]
      if tmp>=mod:
        tmp%=mod
      dp[i][j]=tmp
      if j-a[i-1]-1>=0:
        tmp=dp[i][j]-dp[i-1][j-a[i-1]-1]
        if tmp>=mod:
          tmp%=mod
        dp[i][j]=tmp
    #print(dp)   
  print(dp[n][k])"""
main()
#Grid Repainting 2

#初期化
S = []
p = []
flag = True

#入力
H,W = map(int, input().split())
for i in range(W):
	s = input()
	s_list = list(s)
	S.append(s_list)

#枠外を白に塗りつぶす
for  i in range(H+2):
	p.append(".")

S.insert(0,p)
S.insert(W+1,p)

for i in range(1,W+1,1):
	S[i].insert(0,".")
	S[i].insert(H+2,".")

print("{}".format(S))

#計算
for i in range(1, W+1, 1):
	for j in range(1, H+1, 1):
		if S[i][j] == "#" and S[i+1][j] == "." and S[i][j+1] == "."  and S[i-1][j] == "." and S[i][j-1] == "." :
			flag = False

#出力
if flag == True:
	print("Yes")

else:
	print("No")

### FIXED CODE ###

#Grid Repainting 2

#初期化
S = []
p = []
flag = True

#入力
H,W = map(int, input().split())
for i in range(H):
	s = input()
	s_list = list(s)
	S.append(s_list)

#計算
for i in range(0, H-1, 1):
	for j in range(0, W-1, 1):
		if S[i][j] == "#" and S[i+1][j] == "." and S[i][j+1] == "."  and S[i-1][j] == "." and S[i][j-1] == "." :
			flag = False
		

#出力
if flag == True:
	print("Yes")

else:
	print("No")
from sys import stdin
from functools import lru_cache


# 最小化問題
def chmin(a,b):
    if a > b: return b
    else: return a


class Rec_memo:
    def __init__(self, N):
        self.dp = [float('inf')] * (N+10)

    def rec(self, i):
        if self.dp[i] != float('inf'):
            return self.dp[i]
        elif i == 0:
            return 0
        else:
            self.dp[i] = chmin(self.dp[i],self.rec(i-1)+abs(h_arr[i]-h_arr[i-1]))
            if i>1:
                self.dp[i] = chmin(self.dp[i],self.rec(i-2)+abs(h_arr[i]-h_arr[i-2]))
            return self.dp[i]


if __name__ == "__main__":
    _in = [_.rstrip() for _ in stdin.readlines()]
    N = int(_in[0])  # type:int
    h_arr = [0] * (N+10)
    h_arr[0:N] = list(map(int,_in[1].split(' ')))  # type:list(int)
    # vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
    # dp[i]:=カエルが足場iへと移動するのに必要な最小コスト
    dp = [float('inf')] * (N+10)  # 最小化問題
    dp[0] = 0                    # 初期条件
    
    # 貰うDP
    #for i in range(0,N):
    #    dp[i] = chmin(dp[i],dp[i-1]+abs(h_arr[i]-h_arr[i-1]))
    #    if i > 1:
    #        dp[i] = chmin(dp[i],dp[i-2]+abs(h_arr[i]-h_arr[i-2]))
    #cnt = dp[N-1]

    # 配るDP
    #for i in range(0,N):
    #    dp[i+1] = chmin(dp[i+1],dp[i]+abs(h_arr[i]-h_arr[i+1]))
    #    dp[i+2] = chmin(dp[i+2],dp[i]+abs(h_arr[i]-h_arr[i+2]))
    #cnt = dp[N-1]

    # メモ化再帰
    memo = Rec_memo(N)
    cnt = memo.rec(N-1)
    # ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    print(cnt)


### FIXED CODE ###

from sys import stdin


# 最小化問題
def chmin(a,b):
    if a > b: return b
    else: return a


if __name__ == "__main__":
    _in = [_.rstrip() for _ in stdin.readlines()]
    N = int(_in[0])  # type:int
    h_arr = list(map(int,_in[1].split(' ')))  # type:list(int)
    # vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
    dp = [float('inf')] * N  # 最小化問題
    dp[0] = 0                # 初期条件
    
    for i in range(0,N):
        dp[i] = chmin(dp[i],dp[i-1]+abs(h_arr[i]-h_arr[i-1]))
        if i > 1:
            dp[i] = chmin(dp[i],dp[i-2]+abs(h_arr[i]-h_arr[i-2]))
    cnt = dp[N-1]
    # ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    print(cnt)
#coding:utf-8

A, B = map(int,raw_input().split())
S = raw_input()

if S[A] != '-':
    print "No"

else:
    Flag = 0
    for i in range(A):
        if S[i] >= '0' and S[i] <= '9':
            Flag = 1
    for i in range(A+1,len(S)):
        if S[i] >= '0' and S[i] <= '9':
            Flag = 1

if Flag == 1:
    print "No"
else:
    print "Yes"


### FIXED CODE ###

#coding:utf-8

A, B = map(int,raw_input().split())
S = raw_input()

if S[A] != '-':
    print "No"

else:
    Flag = 0
    for i in range(A):
        if (S[i] >= '0' and S[i] <= '9') == False:
            Flag = 1
            #print "hello1"
    for i in range(A+1,len(S)):
        if (S[i] >= '0' and S[i] <= '9') == False:
            Flag = 1

    if Flag == 1:
        print "No"
    else:
        print "Yes"