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

H, W = map(int, input().split())
c_list = list()
for i in range(H):
  b_list = list(map(lambda x: x, input()))
  for w in range(W):
    if b_list[w] == '#':
      c_list.append([i, w])
ans = 0
if len(c_list) != H*W:
  ans += 1
  for i in range(H+W):
    ll = c_list.copy()
    for c in ll:
      if not c[0]-1 < 0:
        c_list.append([c[0]-1, c[1]])
      if not c[0]+1 > W-1:
        c_list.append([c[0]+1, c[1]])
      if not c[1]-1 < 0:
        c_list.append([c[0], c[1]-1])
      if not c[1]+1 > W-1:
        c_list.append([c[0], c[1]+1])
    c_list = list(set(map(tuple, c_list)))
    if len(c_list) >= H*W:
      break;
    else:
      ans += 1
else:
  ans = 0
print(ans)

### FIXED CODE ###

h,w= map(int, input().split())
s_list = []
b_list = []
for i in range(h):
    li = input()
    aa = []
    for j in range(w):
        aa.append(li[j])
        if aa[j] == '#':
            b_list.append((i, j))
    s_list.append(aa)
ans = 0
while True:
    bb_list = []
    for p in b_list:
        pp = [(p[0]-1, p[1]), (p[0]+1, p[1]), (p[0], p[1]-1), (p[0], p[1]+1)]
        for ppp in pp:
            if (0 <= ppp[0] < h) and (0 <= ppp[1] < w):
                if s_list[ppp[0]][ppp[1]] == '.':
                    s_list[ppp[0]][ppp[1]] = '#'
                    bb_list.append((ppp[0], ppp[1]))
    # ここで複数回同じbをやらなくて済むようにしている
    b_list = bb_list
    if len(b_list) == 0:
        break
    ans += 1
    # print(x)
print(ans)
### BUGGY CODE ###

import math

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

i = 1
while i <= N:
    ans = max(((A * (i-1) // B) - A * ((i-1) // B)),((A * (i) // B) - A * ((i) // B)))
    i = i + 1

print(ans)


### FIXED CODE ###

a, b, n = list(map(int, input().split()))
x = min(b - 1, n)
ans = int(a * x / b)
print(ans)
### BUGGY CODE ###

class UnionFind():
  def __init__(self, n):
    self.n = n
    self.parents = [-1] * n

  def find(self, x):
    if self.parents[x] < 0:
      return x
    else:
      self.parents[x] = self.find(self.parents[x])
      return self.parents[x]

  def union(self, x, y):
    x = self.find(x)
    y = self.find(y)
    if x == y:
      return
    if self.parents[x] > self.parents[y]:
      x, y = y, x
    self.parents[x] += self.parents[y]
    self.parents[y] = x

  def size(self, x):
    return -self.parents[self.find(x)]

  def same(self, x, y):
    return self.find(x) == self.find(y)

  def members(self, x):
    root = self.find(x)
    return [i for i in range(self.n) if self.find(i) == root]

  def roots(self):
    return [i for i, x in enumerate(self.parents) if x < 0]

  def group_count(self):
    return len(self.roots())

  def all_group_members(self):
    return {r: self.members(r) for r in self.roots()}

  def __str__(self):
    return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

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

uf = UnionFind(N)

for _ in range(M):
  x, y = map(lambda x: int(x)-1, input().split())
  uf.union(x, y)

D = uf.all_group_members()

ans = 0

for L in D.values():
  check = set(L)
  for i in L:
    if p[i]-1 in check:
      ans += 1 

print(ans)

### FIXED CODE ###

class UnionFind():
  def __init__(self, n):
    self.n = n
    self.parents = [-1] * n

  def find(self, x):
    if self.parents[x] < 0:
      return x
    else:
      self.parents[x] = self.find(self.parents[x])
      return self.parents[x]

  def union(self, x, y):
    x = self.find(x)
    y = self.find(y)
    if x == y:
      return
    if self.parents[x] > self.parents[y]:
      x, y = y, x
    self.parents[x] += self.parents[y]
    self.parents[y] = x

  def size(self, x):
    return -self.parents[self.find(x)]

  def same(self, x, y):
    return self.find(x) == self.find(y)

  def members(self, x):
    root = self.find(x)
    return [i for i in range(self.n) if self.find(i) == root]

  def roots(self):
    return [i for i, x in enumerate(self.parents) if x < 0]

  def group_count(self):
    return len(self.roots())

  def all_group_members(self):
    return {r: self.members(r) for r in self.roots()}

  def __str__(self):
    return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

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

uf = UnionFind(N)

for _ in range(M):
  x, y = map(lambda x: int(x)-1, input().split())
  uf.union(x, y)

ans = 0

for i, p in enumerate(P):
  if uf.same(i, p-1):
    ans += 1

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

from itertools import combinations
N = int(input())
V = [int(s) for s in input().split() if s.isdigit()]
C = [int(s) for s in input().split() if s.isdigit()]

maximum = 0
for select in range(1, N+1):
    for comb in combinations(range(N), select):
        value = 0
        for idx in comb:
            value += V[idx] - C[idx]
        if value > maximum:
            maximum = value
print(maximum)


### FIXED CODE ###

N = int(input())
V = [int(s) for s in input().split() if s.isdigit()]
C = [int(s) for s in input().split() if s.isdigit()]
VC = [int(i - j) for i, j in zip(V, C)]

dp = [0 for _ in range(N+1)]
for i in range(N):
    dp[i+1] = max(dp[i], dp[i] + VC[i])
print(dp[N])
### BUGGY CODE ###

#4
#入力
N=int(input())
A=list(map(int,input().split()))

#デバッグ関連
debug=1#0:本番,1:デバッグ

def pront(*n):
    if debug==1:
        print(n)

#処理
A.sort()

x=0
while len(A)!=0:
    y=A.count(A[0])
    if y<A[0]:
        x+=y
    else:
        x+=y-A[0]
    A=A[y:]
print(x)

### FIXED CODE ###

#4
#入力
N=int(input())
A=list(map(int,input().split()))

#デバッグ関連
debug=0#0:本番,1:デバッグ

def pront(*n):
    if debug==1:
        print(n)

#処理
X={}
for i in A:
    if i in X:
        X[i]+=1
    else:
        X[i]=1

        x=0
for i in X.items():
    pront(i)
    if i[0]>i[1]:
        x+=i[1]
    else:
        x+=i[1]-i[0]
        
print(x)
### BUGGY CODE ###

n = int(input())
x = input()
ans = [0]*(n+1)

for i in range(1,n+1):
    s = format(i, 'b')
    c = s.count('1')
    a = i%c
    ans[i] += 1
    ans[i] += ans[a] 

one_cnt = x.count('1')
numx = int(x,2)

for i in range(n):
    temp = one_cnt
    if x[i]=='0':
        temp += 1
        num = numx%temp + pow(2,n-1-i,temp)
    else:
        if temp>1:
            temp -= 1
            num = numx%temp - pow(2,n-1-i,temp)
        else:
            print(0)
            continue
    print(ans[num%temp]+1)


### FIXED CODE ###

n = int(input())
x = input()
ans = [0]*(n+1)

for i in range(1,n+1):
    s = format(i, 'b')
    c = s.count('1')
    a = i%c
    ans[i] += 1
    ans[i] += ans[a] 

one_cnt = x.count('1')
numx = int(x,2)

for i in range(n):
    temp = one_cnt
    if x[i]=='0':
        temp += 1
        num = numx%temp + pow(2,n-1-i,temp)
    else:
        if temp>1:
            temp -= 1
            num = numx%temp - pow(2,n-1-i,temp)
        else:
            print(0)
            continue
    print(ans[num%temp]+1)
### BUGGY CODE ###

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

ans = 0
min_v = -1
for i in range(0, N):
    if P[i] <= min_v:
        ans += 1
        min_v = P[i]
        continue
    for j in range(0, i+1):
        if P[i] > P[j]:
            break

        if i == j:
            ans += 1
            min_v = P[i]

print (ans)



### FIXED CODE ###

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

ans = 0
min_v = P[0]

for i in range(0, N):
    if P[i] <= min_v:
        ans += 1
        min_v = P[i]

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

def digits_of(n): 
    digits = []
    while n != 0:
        r = n % 10
        digits.append(r)
        n = n // 10
    return digits

def is_multiple_of_9(n):
	sum = 0
	for i in digits_of(n):
		sum += i
	return sum % 9 == 0 

N = int(input())
if is_multiple_of_9(N) == True:
  	print("Yes\n")
else:
  	print("No\n")


### FIXED CODE ###

N = int(input())
result = sum(list(map(int, str(N))))
if  result % 9 == 0:
  	print("Yes\n")
else:
  	print("No\n")
### BUGGY CODE ###

from collections import deque
import sys
from collections import defaultdict
input = sys.stdin.readline
H, W = map(int, input().split())
C = [list(input()) for i in range(H)]

INF = 10 ** 9
n = H * W
d =[[INF for _ in range(n)] for _ in range(n)]
go = [[1, 0], [0, 1], [-1, 0], [0, -1]]
for x in range(W):
    for y in range(H):
        for temp in go:
            gx,gy = temp
            nx = x + gx
            ny = y + gy
            if 0<= nx < W and 0<= ny < H and C[ny][nx] != "#":
                d[ny * W + nx][y * W + x] = 1
                d[y * W + x] [ny * W + nx]= 1
for i in range(n):
    d[i][i] = 0
    #d[i][j]: iからjへの最短距離
for k in range(n):
    for i in range(n):
        for j in range(n):
            if C[i//W][i%W] != "#" and C[j//W][j%W] != "#" and C[k//W][k%W] != "#":
                d[i][j] = min(d[i][j],d[i][k] + d[k][j])
ans = d
# print(ans)
x  = 0
for temp in ans:
    for k in temp:
        if k != INF:
            if k > x:
                x = k
print(x)



### FIXED CODE ###

from collections import deque
import sys
from collections import defaultdict
input = sys.stdin.readline



H, W = map(int, input().split())
C = [list(input()) for i in range(H)]
INF = 10 ** 9
go = [[1, 0], [0, 1], [-1, 0], [0, -1]]
que = deque()
ans  = -1
for sx in range(W):
    for sy in range(H): # スタート地点のループ
        if C[sy][sx] == "#":
            continue
        
        dist = [[-1 for _ in range(W)] for _ in range(H)]
        
        que.append((sy,sx))
        dist[sy][sx] = 0
        while que:
            y,x = que.popleft()
            for temp in go:
                gx,gy = temp
                nx = x + gx
                ny = y + gy
                if 0<= nx < W and 0<= ny < H and C[ny][nx] != "#":
                    if dist[ny][nx] == -1: # ここの更新にminはいらない(幅優先なので自明に最短距離を進む)
                        dist[ny][nx] = dist[y][x] + 1
                        que.append( (ny,nx))
        for temp in dist:
            cand = max(temp)
            ans = max(ans,cand)
print(ans)
### BUGGY CODE ###

N,M = map(int,input().split())
A = [int(input()) for _ in range(M)]

dp = [0]*(N+1)
dp[0] = 1
if 1 in A:
  dp[1] = 0
else:
  dp[1] = 1

for i in range(2,N+1):
  if i not in A:
    dp[i] = (dp[i-1] + dp[i-2])%1000000007
  else:
    dp[i] = 0

print(dp[N])

### FIXED CODE ###

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

N = int(input())
a = [0 for _ in range(N)]
for i in range(N):
    a[i] = int(input())
c = 0
x = 1
dic = [1]
while 1:
    x = a[x - 1]
    if x == 2:
        c += 1
        break
    elif x in dic:
        c = -1
        break
    else:
        dic.append(x)
        c += 1
print(c)


### FIXED CODE ###

N = int(input())
a = [0 for _ in range(N)]
for i in range(N):
    a[i] = int(input())
c = 0
x = 1
while(x != 2):
    nex = a[x - 1]
    if not nex:
        c = -1
        break
    else:
        a[x - 1] = False
        c += 1
        x = nex
print(c)
### BUGGY CODE ###

N,W=map(int,input().split())
dp=[[0]*(W+1) for _ in range(N)]
for i in range(N):
  w,v=map(int,input().split())
  for j in range(W+1):
    dp[i][j]=max(dp[i-1][j-w]+v if j>=w else 0,dp[i-1][j])
print(dp[-1][-1])

### FIXED CODE ###

N,W=map(int,input().split())
dp=[[0]*(W+1) for _ in range(N)]
for i in range(N):
  w,v=map(int,input().split())
  for j in range(W+1):
    dp[i][j]=max(dp[i-1][j-w]+v if j>=w else 0,dp[i-1][j])
print(dp[-1][-1])
### BUGGY CODE ###

#!/usr/bin/env python3
import sys

sys.setrecursionlimit(10 ** 8)
INF = 1 << 62


def solve(N: int, a: "List[int]"):
    dp = [[INF] * N for _ in range(N + 1)]
    cumsize = [0] * (N + 1)
    for i in range(1, N + 1):
        cumsize[i] = cumsize[i - 1] + a[i - 1]

    def mincost(length, head):
        if head + length > N:
            return INF
        if dp[length][head] < INF:
            return dp[length][head]
        base_cost = cumsize[head + length] - cumsize[head]
        if length == 1:
            dp[length][head] = 0
            return 0
        cost = INF
        split_point = head
        for j in range(1, length):
            if split_point + j >= N:
                continue
            c = mincost(j, head) + mincost(length - j, head + j)
            if cost > c:
                cost = c
        cost += base_cost
        dp[length][head] = cost
        return cost

    return mincost(N, 0)


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word

    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    a = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    print(solve(N, a))


if __name__ == "__main__":
    main()


### FIXED CODE ###

#!/usr/bin/env python3
import sys

sys.setrecursionlimit(10 ** 8)
INF = 1 << 62


def solve(N: int, a: "List[int]"):
    dp = [[INF] * N for _ in range(N + 1)]
    cumsize = [0] * (N + 1)
    for i in range(1, N + 1):
        cumsize[i] = cumsize[i - 1] + a[i - 1]

    def mincost(length, head):
        if head + length > N:
            return INF
        if dp[length][head] < INF:
            return dp[length][head]
        base_cost = cumsize[head + length] - cumsize[head]
        if length == 1:
            dp[length][head] = 0
            return 0
        cost = INF
        split_point = head
        for j in range(1, length):
            if split_point + j >= N:
                continue
            c = mincost(j, head) + mincost(length - j, head + j)
            if cost > c:
                cost = c
        cost += base_cost
        dp[length][head] = cost
        return cost

    return mincost(N, 0)


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word

    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    a = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    print(solve(N, a))


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

def main():
  n,x,y = map(int,input().split())
  w = n

  def dijkstra(s,n,w,cost):
      #始点sから各頂点への最短距離
      #n:頂点数,　w:辺の数, cost[u][v] : 辺uvのコスト(存在しないときはinf)
      d = [float("inf")] * n
      used = [False] * n
      d[s] = 0

      while True:
          v = -1
          #まだ使われてない頂点の中から最小の距離のものを探す
          for i in range(n):
              if (not used[i]) and (v == -1):
                 v = i
              elif (not used[i]) and d[i] < d[v]:
                  v = i
          if v == -1:
                 break
          used[v] = True

          for j in range(n):
                 d[j] = min(d[j],d[v]+cost[v][j])
      return d

  ################################

  cost = [[float("inf") for i in range(n)] for i in range(n)] 
  #cost[u][v] : 辺uvのコスト(存在しないときはinf この場合は10**10)
  for i in range(n-1):
      cost[i][i+1] = 1
      cost[i+1][i] = 1

  cost[x-1][y-1] = 1
  cost[y-1][x-1] = 1

  print(n)
  for dis in range(2,n) :
    ans = 0
    for s in range(n) :
      ans += dijkstra(s,n,w,cost).count(dis)
    print(ans//2)

if __name__ == '__main__':
  main()

### FIXED CODE ###

n,x,y = map(int,input().split())
x -= 1 ; y -= 1

ans = [0 for i in range(n)]
for s in range(n) :
  for g in range(s,n) :
    if s == g :
      continue
    dis = min(abs(g-s),abs(abs(x-s)+1+abs(y-g)),abs(abs(y-s)+1+abs(x-g)))
    ans[dis] += 1
    
for i in range(1,n) :
  print(ans[i])
### BUGGY CODE ###

def LI():
  return list(map(int,input().split()))

N,M,K = map(int,input().split())
A = LI()
B = LI()

cumA = [0]
for a in A:
  cumA.append(cumA[-1]+a)

cumB = [0]
for b in B:
  cumB.append(cumB[-1]+b)

res = 0
for i in range(N+1):
  cuma = cumA[i]
  if cuma > K: continue
  rem = K-cuma
  deskb = 0
  for j in range(M, -1, -1):
    if cumB[j] <= rem:
      deskb = j
      break

  res = max(res, i+deskb)

print(res)

### FIXED CODE ###

import bisect
def LI():
  return list(map(int,input().split()))

N,M,K = map(int,input().split())
A = LI()
B = LI()

cumA = [0]
for a in A:
  cumA.append(cumA[-1]+a)

cumB = [0]
for b in B:
  cumB.append(cumB[-1]+b)

res = 0
for i in range(N+1):
  cuma = cumA[i]
  if cuma > K: continue
  rem = K-cuma
  deskb = bisect.bisect_right(cumB, rem)-1

  res = max(res, i+deskb)

print(res)
### BUGGY CODE ###

def reverse(s):
  ret = ''
  len_ = len(s) - 1
  for i in range(len(s)):
    ret += s[len_ - i]
  return ret

S = input()
N = int(input())
one_flag = False
for i in range(N):
  str_ = input()
  if ' ' in str_:
    c = str_.split()
    if c[1] == '2':
      if one_flag == False:
      	S = S + c[2]
      else:
        S = c[2] + S
    else:
      if one_flag == False:
      	S = c[2] + S
      else:
        S = S + c[2]
  else:
    one_flag = not one_flag
if one_flag == True:
  S = reverse(S)
print(S)

### FIXED CODE ###

import queue
def reverse(s):
  ret = ''
  len_ = len(s) - 1
  for i in range(len(s)):
    ret += s[len_ - i]
  return ret

S = input()
N = int(input())


p_a = queue.LifoQueue()
rp_a = queue.Queue()
p_b = queue.Queue()
rp_b = queue.LifoQueue()
flag = False
for i in range(N):
  s = input()
  if s[0] == '1':
    flag = not flag   
  else:
    if (s[2] == '2' and not flag) or (s[2] == '1' and flag) :
      p_b.put(s[4])
    elif (s[2] == '2' and flag) or (s[2] == '1' and not flag) :
  	  p_a.put(s[4])
s_a = ''
s_b = ''
while not p_a.empty():
  s_a += p_a.get()
while not p_b.empty():
  s_b += p_b.get()
ret = s_a + S + s_b
if flag:
  ret = reverse(ret)

print(ret)
### BUGGY CODE ###

import numpy as np

N, K, Q = map(int, input().split()) 
score = np.array([K]*N)

def change_score(N ,A, score):
    score = score - np.array([1]*N)
    score[A-1] = score[A-1] + 1
    return score

for i in range(Q):
    A = int(input())
    score = change_score(N, A, score)
    #print(score)
    f_score = score

for i in f_score:
    if i > 0:
        print("Yes")
    else:
        print("No")

### FIXED CODE ###

import numpy as np

N, K, Q = map(int, input().split()) 
score = np.array([0]*N)

def change_score(N ,A, score):
    #score = score - np.array([1]*N)
    score[A-1] = score[A-1] + 1
    return score

for i in range(Q):
    A = int(input())
    score = change_score(N, A, score)
    #print(score)
    f_score = score

for i in f_score:
    if i + K - Q > 0:
        print("Yes")
    else:
        print("No")
### BUGGY CODE ###

import sys
input = sys.stdin.readline


def Find(x, par):
  if par[x] < 0:
    return x
  else:
    # 経路圧縮
    par[x] = Find(par[x], par)
    return par[x]

def Unite(x, y, par, rank):
  x = Find(x, par)
  y = Find(y, par)
  
  if x != y:
    # rankの低い方を高い方につなげる
    if rank[x] < rank[y]:
      par[y] += par[x]
      par[x] = y
    else:
      par[x] += par[y]
      par[y] = x
      if rank[x] == rank[y]:
        rank[x] += 1
    
def Same(x, y, par):
  return Find(x, par) == Find(y, par)
 
def Size(x, par):
  return -par[Find(x)]

n, k, l = map(int, input().split())
rpar = [-1]* n
tpar = [-1]* n
rrank = [0]*n
trank = [0]*n

for i in range(k):
  p, q = map(int, input().split())
  p, q =p-1, q-1
  Unite(p,q, rpar, rrank) 

for i_ in range(l):
  p, q = map(int, input().split())
  p, q =p-1, q-1
  Unite(p,q, tpar, trank)

d = {}
IDs = [0]*n
for j in range(n):
  ID = Find(j, rpar)+(Find(j, tpar)+1)*10**8
  IDs[j] = ID
  if ID in d:
    d[ID] += 1
  else:
    d[ID] = 1

ans = ''
for j_ in range(n):
  if j_ != 0:
    ans += ' '
  ans += str(d[IDs[j_]])
print(ans)

### FIXED CODE ###

def Find(x, par):
  if par[x] < 0:
    return x
  else:
    # 経路圧縮
    par[x] = Find(par[x], par)
    return par[x]

def Unite(x, y, par, rank):
  x = Find(x, par)
  y = Find(y, par)
  
  if x != y:
    # rankの低い方を高い方につなげる
    if rank[x] < rank[y]:
      par[y] += par[x]
      par[x] = y
    else:
      par[x] += par[y]
      par[y] = x
      if rank[x] == rank[y]:
        rank[x] += 1
    
def Same(x, y, par):
  return Find(x, par) == Find(y, par)
 
def Size(x, par):
  return -par[Find(x)]

n, k, l = map(int, input().split())
rpar = [-1]* n
tpar = [-1]* n
rrank = [0]*n
trank = [0]*n

for i in range(k):
  p, q = map(int, input().split())
  p, q =p-1, q-1
  Unite(p,q, rpar, rrank) 

for i_ in range(l):
  p, q = map(int, input().split())
  p, q =p-1, q-1
  Unite(p,q, tpar, trank)

d = {}
IDs = [0]*n
for j in range(n):
  ID = Find(j, rpar)+(Find(j, tpar)+1)*10**8
  IDs[j] = ID
  if ID in d:
    d[ID] += 1
  else:
    d[ID] = 1

ans = ''
for j_ in range(n):
  if j_ != 0:
    ans += ' '
  ans += str(d[IDs[j_]])
print(ans)
### BUGGY CODE ###

import sys
sys.setrecursionlimit(10000000)
# N = 4
# ARR = [10, 30, 40, 20]

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

def calculate(n, arr):
    result = aaa(0)
    print(result)


def aaa(currentPosition, cost=0):
    endPosition = N - 1
    if currentPosition == endPosition:
        return cost
    if currentPosition == (endPosition - 1):
        return aaa(endPosition, cost + abs(ARR[endPosition] - ARR[currentPosition]))

    a1 = abs(ARR[currentPosition + 1] - ARR[currentPosition])
    a2 = abs(ARR[currentPosition + 2] - ARR[currentPosition])

    s1 = aaa(currentPosition + 1, cost + a1)
    s2 = aaa(currentPosition + 2, cost + a2)
    return min(s1, s2)

calculate(N, ARR)


### FIXED CODE ###

# N = 4
# HRR = [10, 30, 40, 20]
# N = 2
# HRR = [10, 10]

N = int(input())
HRR = list(map(int,input().split()))
result = []
for i in range(N):
    if i == 0:
        result.append(0)
    elif i == 1:
        s1 = result[i - 1] + abs(HRR[i] - HRR[i - 1])
        result.append(s1)
    else:
        s1 = result[i - 1] + abs(HRR[i] - HRR[i - 1])
        s2 = result[i - 2] + abs(HRR[i] - HRR[i - 2])
        result.append(min(s1, s2))

print(result[-1])
### BUGGY CODE ###

N, Q = map(int, input().split())

STX = [tuple(map(int, input().split())) for _ in range(N)]
STX.sort(key=lambda A: A[2])

ans = []
for _ in range(Q):
    D = int(input())
    for s, t, x in STX:
        if s - x <= D < t - x:
            ans.append(x)
            break
    else:
        ans.append(-1)

print(*ans, sep='\n')

### FIXED CODE ###

import sys
input = sys.stdin.readline
from collections import defaultdict
from heapq import heappop, heappush

N, Q = map(int, input().split())
INF = float('inf')

events = []
for i in range(N):
    S, T, X = map(int, input().split())
    events.append((S - X, 0, X))
    events.append((T - X, 1, X))

for _ in range(Q):
    events.append((int(input()), 2, 0))

events.sort()

cnt = defaultdict(int)
cnt[INF] += 1
que = [INF]

for t, flag, x in events:
    if flag == 0:
        if cnt[x] == 0:
            heappush(que, x)
        cnt[x] += 1
    elif flag == 1:
        cnt[x] -= 1
    else:
        while cnt[que[0]] == 0:
            heappop(que)
        print(que[0] if que[0] != INF else -1)
### BUGGY CODE ###

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

mod = 10**9 + 7

ans = 0
num = 1
for i in range(n):
	num = (num * (n-i)) // (i+1)
	if a != i+1 and b != i+1:
		ans += num

print(ans)


### FIXED CODE ###

def pow_k(x, n):
    """
    O(log n)
    """
    MOD = 10 ** 9 + 7
    if n == 0:
        return 1

    K = 1
    while n > 1:
        if n % 2 != 0:
            K *= x
            K %= MOD
        x *= x
        x %= MOD
        n //= 2

    return K * x

def cmb(n, r):
	MOD = 10**9+7
	if n - r < r: r = n - r
	if r == 0: return 1
	if r == 1: return n

	numerator = [n - r + k + 1 for k in range(r)]
	denominator = [k + 1 for k in range(r)]

	for p in range(2,r+1):
		pivot = denominator[p - 1]
		if pivot > 1:
			offset = (n - r) % p
			for k in range(p-1,r,p):
				numerator[k - offset] /= pivot
				denominator[k] /= pivot

	result = 1
	for k in range(r):
		if numerator[k] > 1:
			result *= int(numerator[k])
			result %= MOD

	return result

n,a,b = map(int,input().split())
MOD = 10**9+7

ans = pow_k(2,n)-1

print((ans - cmb(n,a) - cmb(n,b))%MOD)
### BUGGY CODE ###

from collections import Counter
N = int(input())
slist = []
for _ in range(N):
    slist.append(dict(Counter(input())))

count = 0
for i in range(N):
    for j in range(i+1, N):
        if slist[i] == slist[j]:
            count += 1
print(count)

### FIXED CODE ###

from collections import Counter
N = int(input())
SList = [''.join(sorted(input())) for _ in range(N)]

dic = {}
ans = 0
for word in SList:
    if word not in dic:
        dic[word] = 1
    else:
        ans += dic[word]
        dic[word] += 1

print(ans)