Harryxun/stf_run huggingface dataset:
S=input()

i=0
T=[]
while i<len(S):

    if i+1<len(S) and S[i]+S[i+1]=="BC":
        T.append("D")
        i+=2
    else:
        T+=append(S[i])
        i+=1
count=0
m=0
Acount=0
#print(T)
for i in range(len(T)):
    if "A"==T[i]:
        Acount+=1
    elif "D"==T[i]:
        count+=Acount
    else:
        Acount=0



#print(T)
print(count)


### FIXED CODE ###

S=input()

i=0
T=[]
while i<len(S):

    if i+1<len(S) and S[i]+S[i+1]=="BC":
        T.append("D")
        i+=2
    else:
        T.append(S[i])
        i+=1
count=0
m=0
Acount=0
#print(T)
for i in range(len(T)):
    if "A"==T[i]:
        Acount+=1
    elif "D"==T[i]:
        count+=Acount
    else:
        Acount=0



#print(T)
print(count)
a = input()
m = int(a[0])
n = int(a[1])

print(m*n - m - n +1)

### FIXED CODE ###

a = input().split()
m = int(a[0])
n = int(a[1])
 
print(m*n - m - n +1)
S = input()
W = input()

S = int(S)
W = int(W)

if S <= W :
    print("unsafe")

else :
    print("safe")

### FIXED CODE ###

#入力例全てOKだけど黄色#
S,W = map(int,input().split())

if S <= W :
    print("unsafe")

else :
    print("safe")
import itertools as iter

def main():
    N = int(input())
    A = list(map(int, input().split()))
    nums = [0] * N
    for i in A:
        nums[i] += 1
    #nums = [A.count(i) for i in range(N+1)]
    comb = sum((i*(i-1)//2 for i in nums))
    for k in range(N):
        print(comb-(nums[A[k]]-1))

if __name__ == '__main__':
    main()

### FIXED CODE ###

def main():
    N = int(input())
    A = list(map(int, input().split()))
    nums = [0] * (N+1)
    for i in A:
        nums[i] += 1
    #nums = [A.count(i) for i in range(N+1)]
    comb = sum((i*(i-1)//2 for i in nums))
    for k in range(N):
        print(comb-(nums[A[k]]-1))

if __name__ == '__main__':
    main()
#include <iostream>
#include <string>
#include <fstream>
#include <cmath>

using namespace std;

int main() {
    

    int n;
    cin >> n;
    if (n%2 == 0){
        cout << n << endl;
    }else{
        cout << 2 * n << endl;
    }


}


### FIXED CODE ###

n = int(input())
if n%2==0:
  print(n)
else:
  print(n*2)
def main():
    s = input()
    m = len(s)//2
    ans = 0
    if m%2 == 0:
        a = s[:m]
        b = s[m:]
        for i in range(m):
            if b[i] != a[m-i-1]:
                ans += 1
        print(ans)
    else:
        a = s[:m]
        b = s[m+1:]
        for i in range(m):
            if b[i] != a[m-i-1]:
                ans += 1
        print(ans)


if __name__ == "__main__":
    main()

### FIXED CODE ###

def main():
    s = input()
    m = len(s)//2
    ans = 0
    if len(s)%2 == 0:
        a = s[:m]
        b = s[m:]
        for i in range(m):
            if b[i] != a[m-i-1]:
                ans += 1
        print(ans)
    else:
        a = s[:m]
        b = s[m+1:]
        for i in range(m):
            if b[i] != a[m-i-1]:
                ans += 1
        print(ans)


if __name__ == "__main__":
    main()
n = int(input())
cards = []
patterns = ['S', 'H', 'C', 'D']
for i in range(n):
	each_card = list(map(str, input().strip()))	
	each_card[1] = int(each_card[1])
	cards.append(each_card)
for p in patterns:
	for r in range(1, 13+1):
		if [p, r] in cards:
			pass
		else:
			print(p + ' ' + str(r))

### FIXED CODE ###

cards = []
patterns = ['S', 'H', 'C', 'D']

n = int(input())

for p in patterns:
	for i in range(1, 13+1):
		cards.append(p + ' ' + str(i))

for i in range(n):
	cards.remove(input())

for i in range(len(cards)):
	print(cards[i])
N=int(input())
name=[]
for i in range(N):
  name.append(input())
M=0
A=0
R=0
C=0
H=0
letters=['M','A','R','C','H']
for i in range(N):
  for j in letters:
    if name[i][0]==j:
      if j=='M':
        M+=1
      elif j=='A':
        A+=1
      elif j=='R':
        R+=1
      elif j=='C':
        C+=1
      elif j=='H':
        H+=1
if M==0:
  M+=1
if A==0:
  A+=1
if C==0:
  C+=1
if R==0:
  R+=1
if H==0:
  H+=1
print(M*A*C*R*H)

### FIXED CODE ###

N=int(input())
print(N//3)
while 1:
	h,w = map(int,raw_input().split())
	if h == 0 and w == 0:
		break
	for number in range(h):
		print "#"*w \n

### FIXED CODE ###

while 1:
	h,w = map(int,raw_input().split())
	if h == 0 and w == 0:
		break
	for number in range(h):
		print "#"*w
	print ""
s=input()
x,y=map(int,input().split())
X,Y=[],[]
ct,dir,ss=0,1,1
for i in range(len(s)):
  if s[i]=="F":
    ct+=1
    if i==len(s)-1:
      if dir==1 and ct!=0:
        X.append(ct)
      elif dir==0 and ct!=0:
        Y.append(ct)
  else:
    if ss==1:
      x-=ct
      ct,dir,ss=0,0,0
    elif dir==1 and ct!=0:
      X.append(ct)
      ct,dir=0,0
    elif dir==0 and ct!=0:
      Y.append(ct)
      ct,dir=0,1

def chk(Z,z):
  tot,nz=sum(Z),len(Z)
  if tot==0:
    if z==0:
      return True
    else:
      return False
  elif z>tot:
    return False
  else:
    DP=[[False]*(2*tot+1) for _ in range(nz+1)]
    DP[0][tot]=True
    for i in range(nz):
      zz=Z[i]
      for j in range(2*tot+1):
        if j+zz<2*tot+1:
          DP[i+1][j]=DP[i][j+zz]
        elif j-zz>=0:
          DP[i+1][j]=DP[i][j-zz]
    return DP[nz][z+tot]

if chk(X,x) and chk(Y,y):
  print("Yes")
else:
  print("No")


### FIXED CODE ###

s=input()
x,y=map(int,input().split())
ct=0
XY=[]
for i in range(len(s)):
  if s[i]=="F":
    ct+=1
  else:
    XY.append(ct)
    ct=0
XY.append(ct)
x-=XY[0]
X=XY[2::2]
Y=XY[1::2]


def chk(Z,z):
  tot,nz=sum(Z),len(Z)
  if tot==0:
    if z==0:
      return True
    else:
      return False
  elif abs(z)>tot:
    return False
  else:
    DP=[[False]*(2*tot+1) for _ in range(nz+1)]
    DP[0][tot]=True
    for i in range(nz):
      zz=Z[i]
      for j in range(2*tot+1):
        if j+zz<2*tot+1 and DP[i][j+zz]==True:
          DP[i+1][j]=True
        if j-zz>=0 and DP[i][j-zz]==True:
          DP[i+1][j]=True
    return DP[nz][z+tot]

if chk(X,x) and chk(Y,y):
  print("Yes")
else:
  print("No")
import itertools
N, M = map(int, input().split())
p = [list(map(int, input().split())) for i in range(M)]
v = list(map(list, itertools.permutations(range(2,N+1), N-1)))
cnt = 0
for i in range(len(v)):
	vit = True
    v_i = [1]+v[i]
    for j in range(N-1):
        if sorted(v_i[j:j+2]) not in p:
            vit = False
    if vit:
        cnt += 1
print(cnt)

### FIXED CODE ###

N, M = map(int, input().split())
p = [list(map(int, input().split())) for i in range(M)]
import itertools
v = list(map(list, itertools.permutations(range(2,N+1), N-1)))
cnt = 0
for i in range(len(v)):
    vit = True
    v_i = [1]+v[i]
    for j in range(N-1):
        if sorted(v_i[j:j+2]) not in p:
            vit = False
    if vit:
        cnt += 1
print(cnt)
n = int(input())
a = list(map(int, input().split()))

left = 0
right = 2
p = a[0]
q = a[1]
res_left = abs(p - q)
r = a[2]
s: int = sum(a[3:])
res_right = abs(r - s)
result = max(p,q,r,s) - min(p,q,r,s)

for i in range(2, n - 2):
    q += a[i]
    r -= a[i]
    if i == right:
        right += 1
        r += a[i + 1]
        s -= a[i + 1]
    res_left = abs(p - q)
    res_right = abs(r - s)
    temp = left + 1
    x = p
    y = q
    while temp < i:
        x += a[temp]
        y -= a[temp]
        if abs(x - y) < res_left:
            left = temp
            p = x
            q = y
            res_left = abs(x - y)
        if x >= y:
            break
        temp += 1
    temp = right + 1
    x = r
    y = s
    while temp < n - 1:
        x += a[temp]
        y -= a[temp]
        if abs(x - y) < res_right:
            right = temp
            r = x
            s = y
            res_right = abs(x - y)
        if x >= y:
            break
        temp += 1
    temp_res = max(p, q, r, s) - min(p, q, r, s)
    if temp_res < result:
        result = temp_res

print(result)

### FIXED CODE ###

from functools import reduce

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

left = 0
right = 2
p = a[0]
q = a[1]
r = a[2]
s = reduce(lambda x, y: x + y, a[3:])
temp = right + 1
res_right = abs(s - r)
x = r
y = s
while temp < n - 1:
    x += a[temp]
    y -= a[temp]
    if abs(x - y) < res_right:
        right = temp
        r = x
        s = y
        res_right = abs(x - y)
    if x >= y:
        break
    temp += 1
result = max(p,q,r,s) - min(p,q,r,s)

for i in range(2, n - 2):
    q += a[i]
    r -= a[i]
    if i == right:
        right += 1
        r += a[i + 1]
        s -= a[i + 1]
    res_left = abs(p - q)
    res_right = abs(r - s)
    temp = left + 1
    x = p
    y = q
    while temp < i:
        x += a[temp]
        y -= a[temp]
        if abs(x - y) < res_left:
            left = temp
            p = x
            q = y
            res_left = abs(x - y)
        if x >= y:
            break
        temp += 1
    temp = right + 1
    x = r
    y = s
    while temp < n - 1:
        x += a[temp]
        y -= a[temp]
        if abs(x - y) < res_right:
            right = temp
            r = x
            s = y
            res_right = abs(x - y)
        if x >= y:
            break
        temp += 1
    temp_res = max(p, q, r, s) - min(p, q, r, s)
    if temp_res < result:
        result = temp_res

print(result)
n,a,b,c,d=map(int, input().split())
s=input()
v=0
x=0
for i in range(n-2):
    if c<d:
        if i>b and i<d and s[i]=='#' and s[i+1]=='#':
            print('No')
            v+=1
            break
        elif c>d:
        if  i>=b-1 and i<d+1 and s[i]=='.' and  s[i+1]=='.' and s[i+2]=='.' :
            x=1
            break
if x==0 and c>d:
    print('No')
if x==1:
    for i in range(n-2):
        if i>b and i<c and s[i]=='#' and s[i+1]=='#':
            print('No')
            v+=1
            break
    if v==0 and x==1:
        print('Yes')
if c<d and v==0:
    print('Yes')

### FIXED CODE ###

n, a, b, c ,d = map(int, input().split())
s = input()[:max(c,d)]
 
def main():
    if "##" in s[b:d-2]:
        return "No"
    if "##" in s[a:c-2]:
        return "No"
 
    if c < d:
        return "Yes"
    
    else:
 
        if "..." in s[b-2:d+1]:
            return "Yes"
                
        return "No"
 
print(main())
import sys
input = sys.stdin.readline

n=10**5
sievebd=n//2-1
sieve=[True]*sievebd
limit=(int((n-1)**.5)-1)//2
for i in range(limit):
    if sieve[i]:
        for j in range(2*i**2+6*i+3,sievebd,2*i+3):
            sieve[j]=False
for i in range((sievebd-1)//2-1,-1,-1):
    if not sieve[i]:sieve[2*i+1]=False
for i in range(2,sievebd,2):
    sieve[i]=False

sieve[0]=1
for i in range(1,sievebd):
    sieve[i]+=sieve[i-1]

q=int(input())
l=[0]*q
r=[0]*q
for i in range(q):
    l[i],r[i]=map(int,input().split())

for i in range(q):
    print(sieve[max(1,(r[i]-3)//2+1)]-sieve[max(0,(l[i]-3)//2)])

### FIXED CODE ###

import sys
input = sys.stdin.readline

n=10**5
sievebd=n//2
sieve=[True]*sievebd
limit=int(n**.5)//2
sieve[0]=0
for i in range(limit):
    if sieve[i]:
        for j in range(2*i*(i+1),sievebd,2*i+1):
            sieve[j]=False
for i in range((sievebd-1)//2,0,-1):
    if not sieve[i]:sieve[2*i]=False
for i in range(3,sievebd,2):sieve[i]=False
for i in range(1,sievebd):sieve[i]+=sieve[i-1]
q=int(input())
l=[list(map(int,input().split())) for _ in [0]*q]
for i in range(q):
    print(sieve[(l[i][1]-1)//2]-sieve[max(0,(l[i][0]-1)//2-1)])
s,t = map(list, input().split())
k = []
for i in range(len(s)):
    k.append(s[i] !=t[i])
print(sum(k))

### FIXED CODE ###

s = list(input())
t = list(input())
k = []
for i in range(len(s)):
    k.append(s[i] == t[i])
print(len(s)-sum(k))
n = int(input())

A = list(set(list(map(int, input().split()))))

from fractions import gcd
m = max(A)
for i in range(n):
    for j in range(i+1, n):
        m = min(m, gcd(A[i], A[j]))
print(m)

### FIXED CODE ###

n = int(input())

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

t = max(A)

from fractions import gcd

for i in A:
    t = gcd(t, i)
print(t)
def solve(arr, target):
	return solve_rec(0, arr, target)

def solve_rec(i, arr, target):	
	if target == 0:
		return True
	if i >= len(arr):
		return False
	res1 = solve_rec(i + 1, arr, target)
	res2 = solve_rec(i + 1, arr, target - arr[i])
	return res1 or res2

n = int(input())
arr = list(map(int, input().split()))
q = int(input())
targets = list(map(int, input().split()))

for i in range(q):
	res = solve(arr, targets[i])
	if res == True:
		print('yes')
	else:
		print('no')



### FIXED CODE ###

def subset_sum(n, s, a):
	dp = [[0 for x in range(s+1)] for x in range(n+1)]
	dp[0][0]=1
	for i in range(n):
		v = a[i]
		for j in range(s+1):
			if v > j:
				dp[i+1][j] = dp[i][j]
			else:
				dp[i+1][j] = dp[i][j]+dp[i][j-v]
	return dp[n][s] > 0

n = int(input())
a = list(map(int, input().split()))
q = int(input())
m = list(map(int, input().split()))
for i in range(q):
	if subset_sum(n, m[i], a) == True:
		print('yes')
	else:
		print('no')
N,K = map(int,input().split())
a = list(map(int),input().split())

d = []
for i in range(N):
  for j in range(N):
    if j == i:
      continue
    else:
      d.append(a[i]*a[j])
      
print(sorted(d)[K-1])

### FIXED CODE ###

import numpy as np
N,K = map(int,input().split())
a = np.array(input().split(),np.int64)
a = np.sort(a)
zero = a[a==0]
pos = a[a>0]
neg = a[a<0]

def f(x):
    count = 0
    c = x // pos
    count += np.searchsorted(a, c, side='right').sum()
    count += N*len(zero) if x >= 0 else 0
    c = -(-x // neg)
    count += (N - np.searchsorted(a, c, side='left')).sum()
    count -= a[a*a <= x].size
    count //= 2
    return count

right = 10**18
left = -10**18
while right-left>1:
    mid = (right + left)//2
    if f(mid)<K:
        left = mid
    else:
        right = mid
        
print(right)
n=input()
i=0
a=input()
b=input()
c=0
while True:
    for j in range(a):
        if i >= n:break
        i+=1
        c+=1
    for j in range(b):
        i+=1
    if i > n:break
print(c)


### FIXED CODE ###

def count_balls(n, a, b):
    if(a==0): return 0
    if(n<a): return n
    end = n % (a+b)
    if(end > a):
        return a*(n//(a+b))+a
    else:
        return a*(n//(a+b))+end
n,a,b=map(int, input().strip().split())
print(count_balls(n,a,b))
n, k = map(int, input().split())
n = list(map(str, range(1, n+1)))

for i in range(k):
    _ = input()
    a = input().split()
    print(a)
    for ai in a:
        n.remove(ai)
print(len(n))



### FIXED CODE ###

n, k = map(int, input().split())
n = list(map(str, range(1, n+1)))

for i in range(k):
    _ = input()
    a = input().split()
    for ai in a:
        for ni in n:
            if ai == ni:
                n.remove(ai)
print(len(n))
n = int(input())
a = []
for i in range(n):
    a.append(list(map(int, input().split())))
a0 = a[0]
N = a0[0]
K = a0[1]
b = []
for i in range(K):
    di = a[2i+1]
    bi = a[2i+2]
for l in range(N):
    for i in range(K):
        for k in range(di):
            if bi[k] == l:
                b.append(l)
print(len(b))

### FIXED CODE ###

N, K = map(int, input().split())
d = []
A = []
s = [1] * N
for k in range(K):
  d.append(int(input()))
  A.append([int(i) for i in input().split()])
  
for k in range(K):
  for n in range(1, N+1):
    if n in A[k]:
      if s[n-1] == 1:
        s[n-1] = 0
print(sum(s))
a, b = map(int, input().split())
N = 20
f = [['#'] * N if i < (N/2) else ['.'] * N for i in range(N)]

for i in range(a-1):
    h = 2 * ((2 * i) // N)
    w = (2 * i) % N
    f[h][w] = '.'

for i in range(b-1):
    h = (N//2 + 1) + 2 * (2 * i // N)
    w = 2 * i % N
    f[h][w] = '#'


print(N, N)
for line in f:
    print(''.join(line))

### FIXED CODE ###

a, b = map(int, input().split())
f = [['#' for _ in range(100)] for _ in range(50)] + \
    [['.' for _ in range(100)] for _ in range(50)]

for i in range(a-1):
    h = (i // 50) * 2
    w = (i % 50) * 2
    f[h][w] = '.'

for i in range(b-1):
    h = -((i // 50) * 2 + 1)
    w = (i % 50) * 2
    f[h][w] = '#'

print(100, 100)
for line in f:
    print(''.join(line))
word = input()

flag = True
if len(word)%2 == 1:
    flag = False

wordset = set(word)
leng = len(wordset)
for s in wordset:
    if word.count(s)％2 == 1:
        flag = False
        break
if flag:print("Yes")
else: print("No")


### FIXED CODE ###

word = input()

flag = True
if len(word)%2 == 1:
    flag = False

wordset = set(word)
leng = len(wordset)
for s in wordset:
    if word.count(s)%2 == 1:
        flag = False
        break
if flag:print("Yes")
else: print("No")
def main():
  N=int(input())
  S=input()
  n=len(S)
  if n%2!=0:
    print("No")
  if n%2==0:
    if all(S[i]==S[n/2+i] for i in range(n/2)):
      print("Yes")
    else:
      print("No")
 main()

### FIXED CODE ###

def main():
  N=int(input())
  S=input()
  n=len(S)
  T=S[0:n//2]
  if n%2==0:
    if S==T+T:
      print("Yes")
    else:
      print("No")
  else:
    print("No")
main()
print(sorted(list(map(int,input().split())))

### FIXED CODE ###

a=list(map(str,sorted(list(map(int,input().split())))))
print(a[0]+' '+a[1]+' '+a[2])
r=[float(x) for x in input().split()]
print(float(r*r*3.1412),float(2*r*3.1412))


### FIXED CODE ###

from math import pi
r = float(input())
print("{:.010f} {:.010f}".format(r * r * pi, 2 * pi * r))
S = input()
h = S // 3600
m = S % 3600 //60
s = S % 3600 % 60
print h, ':', m, ':', t

### FIXED CODE ###

S = input()
h = S // 3600
m = S % 3600 //60
s = S % 3600 % 60
print str(h) + ':' + str(m) + ':' + str(s)
n = int(input())
path = [None]*(n + 1)
adjacent_list = [[] for i in range(n+1)]
for i in range(n - 1):
    a, b, c = list(map(int,input().split()))
    adjacent_list[a].append([b,c])
    adjacent_list[b].append([a,c])
#ノード番号、そこまでの距離,検索済みの要素を受け取る。
def dfs(node_n ,distance,finished):
    finished.add(node_n)
    path[node_n] = distance
    for i in adjacent_list[node_n]:
        next = i[0]
        if next not in finished:
            dfs(next, distance + i[1],finished)
q,k = list(map(int, input().split()))
dfs(k,0,set())
for i in range(q):
    s, g = list(map(int, input().split()))
    print(path[s]+path[g])

### FIXED CODE ###

import sys
sys.setrecursionlimit(200000)
n = int(input())
#値の初期化
path = [None]*(n + 1)
adjacent_list = [[] for i in range(n+1)]

for i in range(n - 1):
    a, b, c = list(map(int,input().split()))
    adjacent_list[a].append([b,c])
    adjacent_list[b].append([a,c])
#ノード番号、そこまでの距離,検索済みの要素を受け取る。
def dfs(node_n ,distance,finished):
    #検索済みに追加
    finished.add(node_n)
    #そこまでの距離を代入。値の更新などは特にない（はず）
    path[node_n] = distance
    #対象ノードに対する隣接リストをforで回す
    for i in adjacent_list[node_n]:
        next = i[0]
        if next not in finished:
            #検索済みでなかった場合、そこまでのコストを追加し再帰
            dfs(next, distance + i[1],finished)

q,k = list(map(int, input().split()))
dfs(k, 0, set())
#各クエリへの返答
for i in range(q):
    s, g = list(map(int, input().split()))
    print(path[s] + path[g])
N = int(input())
S = input()
T = input()
ans = ""

for i in range(N):
    ans += S[i]+T[i]
print(ans)

### FIXED CODE ###

N = int(input())
S,T = input().split()
ans = ""
 
for i in range(N):
    ans += S[i]+T[i]
print(ans)
def solve():
    N = int(input())
    A = [int(i) for i in input().split()]
    S = sum(A)
    l = A[0]
    I = 0
    for i in range(1, N):
        if l + A[i] <= S / 2:
            l += A[i]
            I = i
    if l == S / 2:
        print(0)
        exit()
    c = A[I + 1]
    r = S - l - c
    ans1 = abs(r - (l + c))
    ans2 = abs(l - (r + c))
    print(min(ans1, ans2))

if __name__ == "__main__":
    solve()


### FIXED CODE ###

import math

def solve():
    N = int(input())
    A = [int(i) for i in input().split()]
    S = sum(A)
    l = A[0]
    I = 0
    m = math.ceil(S / 2)
    for i in range(1, N):
        if (l + A[i]) <= m:
            l += A[i]
        else:
            I = i - 1
            break
    if l == S / 2:
        print(0)
        exit()
    c = A[I + 1]
    r = S - l - c
    ans1 = abs(r - (l + c))
    ans2 = abs(l - (r + c))
    print(min(ans1, ans2))

if __name__ == "__main__":
    solve()
from collections import deque

N = int(input())

abc = []

dic = {}

for i in range(N-1):

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

    if a not in dic:
        dic[a-1] = []
    if b not in dic:
        dic[b-1] = []

    dic[a-1].append([b-1,c])
    dic[b-1].append([a-1,c])

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

K -= 1

lis = [0] * N

queue = deque([])

queue.append(K)

while len(queue) > 0:

    now = queue.pop()

    for nlis in dic[now]:

        if lis[nlis[0]] != 0 or nlis[0] == K:
            continue

        lis[nlis[0]] = lis[now] + nlis[1]
        queue.append(nlis[0])

#print (lis)

for i in range(Q):

    x,y = map(int,input().split())

    print (lis[x-1]+lis[y-1])

        


### FIXED CODE ###

from collections import deque

N = int(input())

depth = [""] * N

lis = [0] * N

dic = {}

for i in range(N-1):

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

    a -= 1
    b -= 1

    if a not in dic:
        dic[a] = []
    if b not in dic:
        dic[b] = []

    dic[a].append([b,c])
    dic[b].append([a,c])

Q,K = map(int,input().split())
K -= 1

queue = deque([])
queue.append(K)
depth[K] = 0

while len(queue) > 0:

    now = queue.pop()

    if now not in dic:
        continue

    for bc in dic[now]:

        b = bc[0]
        c = bc[1]
        
        if depth[b] != "":
            continue

        depth[b] = depth[now] + 1
        lis[b] = lis[now] + c
        queue.append(b)

for i in range(Q):

    x,y = map(int,input().split())

    x -= 1
    y -= 1

    print (lis[x] + lis[y])
N,M=map(int,input().split())
s=[0]*M
c=[0]*M
a=0
for i in range(M):
	s[i],c[i]=map(int,input().split())
ans=-1
if max(s)>N:
	print(ans)
	exit()
for j in range(1,1000):
	value=str(j)
	if len(value)==N:
		for S,C in zip(s,c):
			if int(value[S-1])==C:
				a+=1
		if a==M:
			ans=int(j)
			break
		else:
			a=0
	else:
		continue
print(ans)

### FIXED CODE ###

N,M=map(int,input().split())
s=[0]*M
c=[0]*M
a=0
for i in range(M):
	s[i],c[i]=map(int,input().split())
ans=-1
if M==0:
	ans=1*(10**(N-1))
	if ans==1:
		ans=0
	print(ans)
	exit()
if max(s)>N:
	print(ans)
	exit()
for j in range(0,1000):
	value=str(j)
	if len(value)==N:
		for S,C in zip(s,c):
			if int(value[S-1])==C:
				a+=1
		if a==M:
			ans=int(j)
			break
		else:
			a=0
	else:
		continue
print(ans)
from functools import lru_cache
import sys

n,y = map(int,input().split())

sys.setrecursionlimit(n**2 +1)
@lru_cache(maxsize = n +1)
def depth(a,b):
    if a+b <= n:
        if (y-10000*a-5000*b)/1000 == n-a-b:
            print(a,b,n-a-b)
            exit()
        else:
            depth(a+1,b)
            depth(a,b+1)
   

if depth(0,0) ==None:
    print(-1,-1,-1)
else:
    print(depth(0,0))

### FIXED CODE ###

n,y = map(int,input().split())

a,b,c = (-1,-1,-1)
for i in range(n+1):
    for j in range(n+1-i):
        if 10000*i + 5000*j + 1000*(n-i-j) == y:
            a,b,c = (i,j,n-i-j)
            break

print(a,b,c)
def get_cost(arr, n, dp):
  if dp[n] != 0:
    return dp[n]
  if n == 1:
    dp[1] = abs(arr[1] - arr[0])
    return dp[1]
  elif n == 0:
    dp[0] = 0
    return dp[0]
  else:
    dp[n] = min(
      abs(arr[n] - arr[n-1]) + get_cost(arr, n-1, dp),
      abs(arr[n] - arr[n-2]) + get_cost(arr, n-2, dp)
    )
    if sum(dp) > 100:
      raise Exception("WRONG", dp)
    return dp[n]


N = int(input())
arr = [int(num) for num in input().split()]
dp_arr = [0]*N
print(get_cost(arr, N-1, dp_arr))


### FIXED CODE ###

import sys
sys.setrecursionlimit(500000)

def get_cost(arr, n, dp):
  if dp[n] != float('inf'):
    return dp[n]
  if n == 1:
    dp[1] = abs(arr[1] - arr[0])
    return dp[1]
  elif n == 0:
    dp[0] = 0
    return dp[0]
  else:
    dp[n] = min(
      abs(arr[n] - arr[n-1]) + get_cost(arr, n-1, dp),
      abs(arr[n] - arr[n-2]) + get_cost(arr, n-2, dp)
    )
    return dp[n]


N = int(input())
arr = [int(num) for num in input().split()]
dp_arr = [float('inf')]*N
print(get_cost(arr, N-1, dp_arr))