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

S = input()
Q = int(input())

for _ in range(Q):
    q = input().split()
    if q[0] == "1":
        S = S[::-1]
    elif q[1] == "1":
        S = q[2] + S
    else:
        S = S + q[2]
        
print(S)

### FIXED CODE ###

from collections import deque


S = deque(input())
Q = int(input())
flag = 1

for _ in range(Q):
    q = input().split()
    if q[0] == "1":
        flag *= -1
    elif q[1] == "1":
        if flag == 1:
            S.appendleft(q[2])
        else:
            S.append(q[2])
    else:
        if flag == 1:
            S.append(q[2])
        else:
            S.appendleft(q[2])
s = list(S)
if flag == 1:
    print("".join(s))
else:
    for i in reversed(s):
        print(i, end="")
### BUGGY CODE ###

X, N = map(int, input().split())
ans = X
if N>0:
  P = list(map(int, input().split()))
  i = 0
  ans = 0
  while ans == 0:
    if X-i not in P:
      ans = X - i
    elif X+i not in P:
      ans = X+i
    else:
      i += 1
print(ans)

### FIXED CODE ###

X, N = map(int, input().split())
ans = X
if N>0:
  P = list(map(int, input().split()))
  P.sort()
  if X in P:
    ans = 0
    x = P.index(X)
    i = 1
    a = x-1
    b = x+1
    m = min(P[N-1]-X, X-P[0])
    for i in range(1,m+2):
      if a < 0:
        a = 0
      if b > N-1:
        b = N-1
      if X-i != P[a]:
        ans = X-i
        break
      elif X+i != P[b]:
        ans = X+i
        break
      else:
        a -= 1
        b += 1
print(ans)
### BUGGY CODE ###

import bisect,collections,copy,heapq,itertools,math,numpy,string
import sys
sys.setrecursionlimit(10**7)

def S(): return sys.stdin.readline().rstrip()
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def LS(): return list(sys.stdin.readline().rstrip().split())

def comb(n):
    return int(n*(n-1)/2)

def main():
    N = I()
    A_list = LI()
    A_ctr = collections.Counter(A_list)
    for i in range(1,N+1):
        tmp_A_ctr = A_ctr.copy()
        tmp_A_ctr[A_list[i-1]] -= 1
        ans = 0
        for v in tmp_A_ctr.values():
            ans += comb(v)
        else:
            print(ans)

main()


### FIXED CODE ###

import bisect,collections,copy,heapq,itertools,math,numpy,string
import sys
sys.setrecursionlimit(10**7)

def S(): return sys.stdin.readline().rstrip()
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def LS(): return list(sys.stdin.readline().rstrip().split())

def comb(n):
    return int(n*(n-1)/2)

def main():
    N = I()
    A_list = LI()
    A_ctr = collections.Counter(A_list)
    base = 0
    for i in range(1,N+1):
        base += comb(A_ctr[i])
    for i in range(1,N+1):
        i_val = A_ctr[A_list[i-1]]
        before = comb(i_val)
        after = comb(i_val-1)
        print(int(base - before + after))
main()
### BUGGY CODE ###

n = int(input())
ans = 0
for i in range(1, n+1):
    if (i **.5).is_integer():
        ans = i
print(ans)
    

### FIXED CODE ###

import math
n = int(input())
ans = int(math.sqrt(n))
print(ans**2)
### BUGGY CODE ###

from operator import itemgetter
import sys


class BIT:
    def __init__(self, size: int):
        self.size = size + 1
        self.array = [0] * self.size

    def add(self, i, x):
        if not i > 0:
            return
        while i < self.size:
            self.array[i] += x
            i += i & -i

    def sum(self, i):
        s = 0
        while i > 0:
            s += self.array[i]
            i -= i & -i
        return s


def read():
    return sys.stdin.readline().rstrip()


def main():
    n, q = map(int, read().split())
    c = [int(i) for i in read().split()]
    queries = [() for _ in range(q)]
    for i in range(q):
        l, r = map(int, read().split())
        queries[i] = (i, l, r)
    queries.sort(key=itemgetter(2))
    last = [0] * n
    bit = BIT(n)
    ans = [-1] * q
    cr = 0
    for i, l, r in queries:
        for ri in range(cr, r):
            ci = c[ri] - 1
            bit.add(last[ci], -1)
            last[ci] = ri + 1
            bit.add(last[ci], 1)
            cr = ri
            ans[i] = bit.sum(r) - bit.sum(l - 1)
    print(*ans, sep="\n")


if __name__ == '__main__':
    main()


### FIXED CODE ###

from operator import itemgetter
import sys


class BIT:
    def __init__(self, size: int):
        self.size = size + 1
        self.array = [0] * self.size

    def add(self, i, x):
        if not i > 0:
            return
        while i < self.size:
            self.array[i] += x
            i += i & -i

    def sum(self, i):
        s = 0
        while i > 0:
            s += self.array[i]
            i -= i & -i
        return s


def read():
    return sys.stdin.readline().rstrip()


def main():
    n, q = map(int, read().split())
    c = [int(i) for i in read().split()]
    queries = [() for _ in range(q)]
    for i in range(q):
        l, r = map(int, read().split())
        queries[i] = (i, l, r)
    queries.sort(key=itemgetter(2))
    last = [0] * n
    bit = BIT(n)
    ans = [-1] * q
    cr = 0
    for i, l, r in queries:
        for ri in range(cr, r):
            ci = c[ri] - 1
            bit.add(last[ci], -1)
            last[ci] = ri + 1
            bit.add(last[ci], 1)
            cr = ri
        ans[i] = bit.sum(r) - bit.sum(l - 1)
    print(*ans, sep="\n")


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

import numpy as np
N = int(input())
a = [int(i) for i in input().split()]
zeros = np.zeros(N)
index = np.arange(1, N + 1)
middle = int(N / 2) + 1

for i, e in zip(a[::-1], index[::-1]):
    if e >= middle:
        zeros[e - 1] = i
    else:
        if sum(zeros[index % e == 0]) % 2 != i:
            zeros[e - 1] = 1

print(int(sum(zeros)))

for i, e in zip(zeros, index):
    if i == 1:
        print(e, end=" ")


### FIXED CODE ###

N = int(input())
a = [int(i) for i in input().split()]
zeros = [0] * N
ai = length = len(a)

for i in a[::-1]:
    s = 0
    for j in range(ai, length+1, ai):
        s += zeros[j-1]
    if s % 2 == i:
        pass
    else:
        zeros[ai-1] = 1
    ai -= 1

print(sum(zeros))
for i, v in enumerate(zeros, 1):
    if v:
        print(i)
### BUGGY CODE ###

N = int(input())
S = input()
count = 0
while True:
	if S == "":
		break
	if S[0] == 'R':
		S = S[1:]
	else:
		if S.count('R') == 0:
			break
		else:
			count += 1
			S = S[1:]
			Rpos = S.rfind('R')
			S = S[:Rpos]+S[Rpos+1:]
print(count)


### FIXED CODE ###

N = int(input())
S = input()
part = 0
leftW = 0
rightR = S.count('R')
moves = [rightR]

for i in range(N):
	if S[i] == 'R':  # rightR:decrease
		rightR -= 1
	else:          # leftW:increase
		leftW += 1
	moves.append(max(leftW, rightR))
# print(moves)
ans = min(moves[i] for i in range(N+1))
print(ans)
### BUGGY CODE ###

Period, WorkingDay, PausePeriod = map(int, input().split())
S = input()
SReverse = S[::-1]

"""
Calculate the day that you can work the fastest and the day that you can work
the slowest. If two days coincide, that day is always a working day.
"""
earliest_days = [-1 for _ in range(Period)]
slowest_days = [-2 for _ in range(Period)]

for days in (earliest_days, slowest_days):
    i_day = 0
    if days == earliest_days:
        i_work_day = 1
        diff_from_next_work = 1
        passion_days = S
    else:
        i_work_day = WorkingDay
        diff_from_next_work = - 1
        passion_days = SReverse
    
    while 1 <= i_work_day and i_work_day <= WorkingDay:
        if passion_days[i_day] == 'o':
            days[i_day] = i_work_day
            i_work_day += diff_from_next_work
            i_day += PausePeriod
        i_day += 1

slowest_days.reverse()
for earliest_day, slowest_day in zip(earliest_days, slowest_days):
    if earliest_day == slowest_day:
        print(earliest_days.index(earliest_day) + 1)

exit()

### FIXED CODE ###

N, K, C = map(int, input().split())
S = input()
S_reverse = S[::-1]

left_justified = [-1 for _ in range(N)]
right_justified = [-2 for _ in range(N)]

for i_justified in (left_justified, right_justified):
    if i_justified == left_justified:
        i_S = S
        nearest_position = 1
        positioning = 1
    else:
        i_S = S_reverse
        nearest_position = K
        positioning = -1
    
    i_K = 0
    
    while i_K <= N-1:
        if i_S[i_K] == 'o':
            i_justified[i_K] = nearest_position
            i_K += C
            nearest_position += positioning
        i_K += 1

for i_N in range(N):
    if left_justified[i_N] == right_justified[N - i_N - 1]:
        print(i_N + 1)
### BUGGY CODE ###

N = int(input())
S = list(input())
R, G, B = [0]*N, [0]*N, [0]*N
rg_set = {("R", "G"), ("G", "R")}
rb_set = {("R", "B"), ("B", "R")}
for i in range(N):
    R[i] += R[i-1] + (1 if S[i] == "R" else 0)
    G[i] += G[i-1] + (1 if S[i] == "G" else 0)
    B[i] += B[i-1] + (1 if S[i] == "B" else 0)
ans = 0
for i in range(N-3):
    for k in range(i+3, N):
        if S[i] != S[k]:
            if (i+k)%2 == 0:
                j = (i+k)//2
                if (S[i], S[k]) in rg_set:
                    ans += B[k] - B[i] - (1 if S[j] == "B" else 0)
                elif (S[i], S[k]) in rb_set:
                    ans += G[k] - G[i] - (1 if S[j] == "G" else 0)
                else:
                    ans += R[k] - R[i] - (1 if S[j] == "R" else 0)
            else:
                if (S[i], S[k]) in rg_set:
                    ans += B[k] - B[i]
                elif (S[i], S[k]) in rb_set:
                    ans += G[k] - G[i]
                else:
                    ans += R[k] - R[i]
print(ans)


### FIXED CODE ###

N = int(input())
S = list(input())
R, G, B = [0]*N, [0]*N, [0]*N
rg_set = {("R", "G"), ("G", "R")}
rb_set = {("R", "B"), ("B", "R")}
for i in range(N):
    R[i] += R[i-1] + (1 if S[i] == "R" else 0)
    G[i] += G[i-1] + (1 if S[i] == "G" else 0)
    B[i] += B[i-1] + (1 if S[i] == "B" else 0)
ans = 0
for i in range(N-3):
    for k in range(i+3, N):
        if S[i] != S[k]:
            if (i+k)%2 == 0:
                j = (i+k)//2
                if (S[i], S[k]) in rg_set:
                    ans += B[k] - B[i] - (1 if S[j] == "B" else 0)
                elif (S[i], S[k]) in rb_set:
                    ans += G[k] - G[i] - (1 if S[j] == "G" else 0)
                else:
                    ans += R[k] - R[i] - (1 if S[j] == "R" else 0)
            else:
                if (S[i], S[k]) in rg_set:
                    ans += B[k] - B[i]
                elif (S[i], S[k]) in rb_set:
                    ans += G[k] - G[i]
                else:
                    ans += R[k] - R[i]
print(ans)
### BUGGY CODE ###

n = int(input())
p = list(map(int, input().split()))
#n = 4
#p = [4,3,2,1]

count = 0
for i in range(n):
  for j in range(i):
    if p[i] > p[j]:
      break
  else:
    count+=1
    continue
print(count)

### FIXED CODE ###

n = int(input())
p = list(map(int, input().split()))
#n = 5
#p = [4,2,5,1,3]

count = 0
temp_min = p[0]
for i in range(n):
  if temp_min >= p[i]:
        count+=1
        temp_min = p[i]
print(count)
### BUGGY CODE ###

N,K=map(int,input().split())
ans=0
for h in range(2//K,(2*N//K)+1):
    if h*K%2==1:
        continue
    a=h*K//2
    if 1<=a<=N:
        for i in range((1+a)//K,(N+a)//K+1):
            b=i*K-a
            if 1<=b<=N:
                for j in range((1+b)//K,(N+b)//K+1):
                    c=j*K-b
                    if 1<=c<=N and (c+a)%K==0:
                            ans+=1
print(ans)


### FIXED CODE ###

N,K=map(int,input().split())
if K%2==1:
    print((N//K)**3)
else:
    print((N//K)**3+(2*N//K-N//K)**3)
### BUGGY CODE ###

import sys
input = sys.stdin.readline

def main():
    n = int(input())
    a = list(map(int, input().split()))
    ans = 0

    for i in set(a):
        cnt = 0
        for j in a:
            if j - 1 <= i <= j + 1:
                cnt += 1
        ans = max(ans, cnt)

    print(ans)

main()

### FIXED CODE ###

import sys
input = sys.stdin.readline

def main():
    n = int(input())
    a = list(map(int, input().split()))
    l = [0]*(10**5 + 10)


    for i in a:
        l[i] += 1
        l[i + 1] += 1
        if i != 0:
            l[i - 1] += 1
    print(max(l))

main()
### BUGGY CODE ###

L,R=[int(x) for x in input().strip().split()]

ans=10**9+1


for i in range(L,R+1,1):
  if i==2019:
    break
  for j in range(L,R+1,1):
    if j==2019:
      break

    if i<j:
      ans=min((i*j)%2019,ans)

if ans==10**9+1:
  ans=0
  

print(ans)


  
      





### FIXED CODE ###

import sys
L,R=[int(x) for x in input().strip().split()]

tmp=10**9+1
ans=10**9+1

for i in range(L,R,1):
  for j in range(L+1,R+1,1):
    if i<j:
      ans=min((i*j)%2019,ans)
  
      if ans==0:
        print(0)
        sys.exit()
print(ans)


# 332701087 1753412895
### BUGGY CODE ###

from sys import stdin
input = stdin.readline
import numpy as np
from collections import deque
H,W = map(int, input().rstrip().split())
CH,CW = map(int, input().rstrip().split())
DH,DW = map(int, input().rstrip().split())
[CH,CW,DH,DW] = [CH-1,CW-1,DH-1,DW-1]
S = np.array([list(input().rstrip()) for i in range(H)])
M = H * W
Distance = np.ones((H,W))*M
Distance[CH,CW] = 0
[nowH,nowW] = [CH,CW]
q = deque([])
q.append([nowH,nowW])
for n in range(0,M):
  if len(q) != 0:
    [nowH,nowW] = q.popleft()
  else:
    break
  if [nowH,nowW] == [DH,DW]:
    break
  for i in range(-2,3):
    for j in range(-2,3):
      if nowH+i >= 0 and nowW+j >= 0 and nowH+i < H and nowW+j < W:
        dis = (abs(i) + abs(j))
        if dis >= 1:
          cost = min(2,dis) - 1
          if S[nowH+i,nowW+j] == '.':
            if Distance[nowH+i,nowW+j] == M:
              if dis == 1:
                q.appendleft([nowH+i,nowW+j])
              else:
                q.append([nowH+i,nowW+j])
              Distance[nowH+i,nowW+j] = Distance[nowH,nowW] + cost
            elif [nowH+i,nowW+j] in q and Distance[nowH,nowW] + cost < Distance[nowH+i,nowW+j]:
              q.remove([nowH+i,nowW+j])
              if dis == 1:
                q.appendleft([nowH+i,nowW+j])
              else:
                q.append([nowH+i,nowW+j])
              Distance[nowH+i,nowW+j] = Distance[nowH,nowW] + cost
              if [nowH+i,nowW+j] == [DH,DW]:
                break
if Distance[DH,DW] == M:
  print(-1)
else:
  print(int(Distance[DH,DW]))

### FIXED CODE ###

from collections import deque
H,W = map(int, input().split())
CH,CW = map(lambda x: int(x) - 1, input().split())
DH,DW = map(lambda x: int(x) - 1, input().split())
S = [input() for i in range(H)]
INF = 10 ** 9
walk = [(0, 1), (0, -1), (-1, 0), (1, 0)]
warp = [(i, j) for i in range(-2, 3) for j in range(-2, 3) if (i, j) not in [(0, 0)] + walk]
h = CH
w = CW
Distance = [[INF] * W for _ in range(H)]
Distance[h][w] = 0
q = deque(())
q.append((h,w))
while q:
  h,w = q.popleft()
  if [h,w] == [DH,DW]:
    break
  for i,j in walk:
    hwalk = h + i
    wwalk = w + j
    if 0 <= hwalk < H and 0 <= wwalk < W and S[hwalk][wwalk] == '.' and Distance[h][w] < Distance[hwalk][wwalk]:
      Distance[hwalk][wwalk] = Distance[h][w]
      q.appendleft((hwalk,wwalk))
  for i,j in warp:
    hwalk = h + i
    wwalk = w + j
    if 0 <= hwalk < H and 0 <= wwalk < W and S[hwalk][wwalk] == '.' and Distance[h][w] + 1 < Distance[hwalk][wwalk]:
      Distance[hwalk][wwalk] = Distance[h][w] + 1
      q.append((hwalk,wwalk))
print(int(Distance[DH][DW]) if Distance[DH][DW] != INF else -1)
### BUGGY CODE ###

n,k=map(int,input().split())
l=list(map(int,input().split()))
m=[0]

for i in range(k,n+1):
  p = l[i-k:i]
  if sum(m) < sum(p):
    m = p
  
print(sum([m[j]*(m[j]+1)/2/m[j] for j in range(k)]))

### FIXED CODE ###

n, k = list(map(int, input().split()))
p = list(map(int, input().split()))
s = sum(p[:k])
m = s

for i in range(n-k):
  s = s-p[i]+p[i+k]
  if m < s:
    m = s
print((m+k)/2)
### BUGGY CODE ###

#abc142C_go to school
N = int(input())
A = list(map(int, input().split()))
ans = []*N 
for i in range(1,N+1):
    ans.insert(i-1,A.index(i)+1)    
print(*ans)

### FIXED CODE ###

N = int(input())
A = list(map(int, input().split()))
L = [[] for i in range(N)]
for i in range(N):
    L[i] = [A[i], i+1]
L.sort()
ans = [0 for i in range(N)]
for i in range(N):
    ans[i] = L[i][1]
print(*ans)
### BUGGY CODE ###

#!/usr/bin/env python3


def main():
    MOD = 10 ** 18
    n = int(input())
    A = list(map(int, input().split()))
    ans = 1
    for a in A:
        ans *= a

    if ans <= MOD:
        print(ans)
    else:
        print('-1')


if __name__ == "__main__":
    main()


### FIXED CODE ###

#!/usr/bin/env python3


def main():
    n = int(input())
    A = list(map(int, input().split()))
    MOD = 10 ** 18
    ans = 1
    if 0 in A:
        print('0')
        return
    for i in range(n):
        ans *= A.pop(0)
        if ans > MOD:
            print('-1')
            return
    print(ans)


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

def abc068_c():
    n, m = map(int, input().split())
    ab = [list(map(int, input().split())) for _ in range(m)]
    first_candidate = []
    second_candidate = []
    for i in range(m):
        if ab[i][0] == 1:
            first_candidate.append(ab[i][1])
        elif ab[i][1] == n:
            second_candidate.append(ab[i][0])
    for v in first_candidate:
        if v in second_candidate:
            print("POSSIBLE")
            return None
    print("IMPOSSIBLE")


abc068_c()

### FIXED CODE ###

def abc068_c():
    from collections import Counter
    n, m = map(int, input().split())
    ab = [list(map(int, input().split())) for _ in range(m)]
    candidates = []

    for i in range(m):
        if ab[i][0] == 1:
            candidates.append(ab[i][1])
        elif ab[i][1] == n:
            candidates.append(ab[i][0])

    if max(Counter(candidates).values()) >= 2:
        print("POSSIBLE")
    else:
        print("IMPOSSIBLE")


abc068_c()
### BUGGY CODE ###

from itertools import permutations

N, M, R = [int(n) for n in input().split()]
r = [int(n)-1 for n in input().split()]
d = [[100000000]*N for n in range(N)]

for i in range(N):
  d[i][i] = 0

for m in range(M):
  A, B, C = [int(n) for n in input().split()]
  A-=1
  B-=1
  d[A][B] = C
  d[B][A] = C

for k in range(N):
  for i in range(N):
    for j in range(N):
      d[i][j] = min(d[i][k]+d[k][j], d[i][j])

res = 10000000000
for perm in permutations(range(R)):
  s = 0
  for i in range(R-1):
    s += d[r[perm[i]]][r[perm[i+1]]]
  res = min(s, res)

print(res)

### FIXED CODE ###

from itertools import permutations

N, M, R = [int(n) for n in input().split()]
r = [int(n)-1 for n in input().split()]
d = [[100000000]*N for n in range(N)]

for i in range(N):
  d[i][i] = 0

for m in range(M):
  A, B, C = [int(n) for n in input().split()]
  A-=1
  B-=1
  d[A][B] = C
  d[B][A] = C

for k in range(N):
  for i in range(N):
    for j in range(N):
      d[i][j] = min(d[i][k]+d[k][j], d[i][j])

res = 1000000000
for perm in permutations(range(R)):
  s = 0
  for i in range(R-1):
    s += d[r[perm[i]]][r[perm[i+1]]]
  res = min(s, res)

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

while True:
    n=input()
    if n==0:
        break
    dp=[[0 for i in range(n)]for j in range(n)]
    flag0=0
    for i in range(n):
        j=0
        for c in raw_input():
            if c == ".":
                flag0=1
                dp[i][j]=1
            j+=1
    if flag0==0:
        print 0
    else:
        solve=1
        while True:
            flag=0
            for y in range(n-solve):
                for x in range(n-solve):
                    if dp[y][x]!=0:
                        old=dp[y][x]
                        dp[y][x]=min(dp[y+1][x],dp[y][x+1],dp[y+1][x+1])+1
                        if old!=dp[y][x]:
                            flag=1
            if flag==0:
                break
            solve+=1
        print solve

### FIXED CODE ###

while True:
    n=input()
    if n==0:
        break
    dp=[[0 for i in range(n+1)]for j in range(n+1)]
    for i in range(1,n+1):
        j=0
        line=" "+raw_input()
        for c in line:
            if c == ".":
                dp[i][j]=min(dp[i-1][j],dp[i][j-1],dp[i-1][j-1])+1
            j+=1
    allmax=0
    for i in range(n+1):
        if allmax<max(dp[i]):
            allmax=max(dp[i])
    print allmax
### BUGGY CODE ###

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

xy = []

while N >= 2:
    if A[-2] > 0:
        y = A.pop()
        x = A[0]

        xy.append([x,y])

        A[0] = x-y

    else:
        x = A.pop()
        y = A.pop(0)

        xy.append([x,y])

        A.append(x-y)
    
    N -= 1

print(A[0])
for x, y in xy:
    print(x,y)

### FIXED CODE ###

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

xy = [0]*(N-1)
idx = 0

n = A.pop()

for i in range(N-1):
    a = A.pop()
    if a > 0:
        xy[idx] = [A[0], a]
        A[0] -= a
    else:
        xy[idx] = [n, a]
        n -= a
        idx += 1
        for j in A:
            xy[idx] = [n, j]
            n -= j
            idx += 1
        break

    idx += 1

print(n)
for x, y in xy:
    print(x,y)
### BUGGY CODE ###

k,s=map(int,input().split())
count=0
for i in range(k+1):
    for j in range(k+1):
        for k in range(k+1):
            if i+j+k==s:
                count+=1
print(count)

### FIXED CODE ###

k,s=map(int,input().split())
count=0
for x in range(k+1):
    for y in range(k+1):
        z=s-x-y
        if z>=0 and z<=k:
            count+=1
print(count)
### BUGGY CODE ###

import bisect
n = int(input())
a = [int(input()) for i in range(n)]

color_num = [a[0]]
cnt = 1
for i in range(1, n):
    if a[i] <= color_num[0]:
        color_num = [a[i]] + color_num
        cnt += 1
    else:
        temp = bisect.bisect_left(color_num, a[i])
        color_num[temp - 1] = a[i]

print(cnt)


### FIXED CODE ###

import bisect
n = int(input())
a = [int(input()) for i in range(n)][::-1]

color_num = [a[0]]
for i in range(1, n):
    if a[i] >= color_num[-1]:
        color_num.append(a[i])
    else:
        temp = bisect.bisect_right(color_num, a[i])
        color_num[temp] = a[i]


print(len(color_num))
### BUGGY CODE ###

# ABC129C - Typical Stairs
import sys
input = sys.stdin.readline

n, m = list(map(int, input().rstrip().split()))
lst = list(map(int, [input().rstrip() for _ in range(m)]))
MOD = 10 ** 9 + 7

if 0 in lst:
    ans = [0, 1] + [0] * (n - 1)
if 1 in lst:
    ans = [1, 0] + [0] * (n - 1)
else:
    ans = [1, 1] + [0] * (n - 1)

for i in range(2, n + 1):
    if i in lst:
        ans[i] = 0
    else:
        ans[i] = (ans[i - 2] + ans[i - 1]) % MOD
print(ans[-1])

### FIXED CODE ###

# ABC129C - Typical Stairs
import sys
input = sys.stdin.readline

n, m = list(map(int, input().rstrip().split()))
skip = set(map(int, [input().rstrip() for _ in range(m)]))
MOD = 10 ** 9 + 7
a = 1 if not 0 in skip else 0
b = 1 if not 1 in skip else 0

for i in range(2, n + 1):
    if a == 0 and b == 0:
        print(0)
        break
    if i in skip:
        a = b
        b = 0
    else:
        tmp = b
        b = (a + b) % MOD
        a = tmp
else:
    print(b)
### BUGGY CODE ###

import itertools

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


combi = []
perm = []
for i in range(1, n + 1):
    tmp_combi = list(itertools.combinations_with_replacement([1, 2], i))
    for c in (tmp_combi):
        if sum(c) == n:
            combi.append(c)


for c in combi:
    for p in list(set(list(itertools.permutations(c)))):
        perm.append(p)


min_cost = 10 ** 10
for p in perm:
    cost = 0
    p = list(p)
    pos = p.pop(0)
    if pos != 1:
        continue
    for j in p:
        cost += abs(h[pos - 1] - h[pos + j - 1])
        pos += j
    if cost < min_cost:
        min_cost = cost

print(min_cost)

### FIXED CODE ###

N = int(input())
blank = 2
h = list(map(int,input().split())) + [0] * blank
INF = 10 ** 9 + 1
dp = [INF] * (N + blank)
dp[0] = 0
for i in range(N):
  dp[i + 1] = min(dp[i] + abs(h[i + 1] - h[i]), dp[i + 1])
  dp[i + 2] = min(dp[i] + abs(h[i + 2] - h[i]), dp[i + 2])
  
print(dp[N - 1])