Harryxun/stf_run huggingface dataset:
n = int(input())
s = ["" for _ in range(n)]
for i in range(n):
    s[i] = str(input())
    s[i] = s[i][0]

march = ["M","A","R","C","H"]
march_num = [0,0,0,0,0]

for i in range(n):
    if s[i] in march:
        march_num[march.index(s[i])] += 1
ans = 0
for i in range(len(s)-2):
    for j in range(i+1,len(s)-1):
        for k in range(j+1,len(s)):
            ans += (march_num[i]*march_num[j]*march_num[k])
print(ans)

### FIXED CODE ###

n = int(input())
s = ["" for _ in range(n)]
for i in range(n):
    s[i] = str(input())
    s[i] = s[i][0]

march = ["M","A","R","C","H"]
march_num = [0,0,0,0,0]

for i in range(len(s)):
    if s[i] in march:
        march_num[march.index(s[i])] += 1
ans = 0
for i in range(3):
    for j in range(i+1,4):
        for k in range(j+1,5):
            ans += (march_num[i]*march_num[j]*march_num[k])
print(ans)
import math
A,B,C,D=map(int,input().split())
L=C*D//(math.gcd(C,D))
print(int(B-A+1-(B//C-((A-1)//C))-(B//D-((A-1)//D))+(B//L-((A-1)//L))))

### FIXED CODE ###

import fractions
A,B,C,D=map(int,input().split())
L=C*D//(fractions.gcd(C,D))
print(int(B-A+1-(B//C-((A-1)//C))-(B//D-((A-1)//D))+(B//L-((A-1)//L))))
import sys
input = sys.stdin.buffer.readline

#sys.setrecursionlimit(10**9)
#from functools import lru_cache

def RD(): return sys.stdin.read()
def II(): return int(input())
def MI(): return map(int,input().split())
def MF(): return map(float,input().split())
def LI(): return list(map(int,input().split()))
def LF(): return list(map(float,input().split()))
def TI(): return tuple(map(int,input().split()))
# rstrip().decode()

import heapq

def main():
	t=II()
	for _ in range(t):
		n=II()
		L=[]
		R=[]
		ans=0
		for _ in range(n):
			k,l,r=MI()
			if l>=r:
				ans+=r
				L.append((k,l-r))
			else:
				ans+=l
				R.append((n-k,r-l))
		L.sort()
		R.sort()
		#print(L,R)

		Q=[]
		heapq.heapify(Q)

		for k,v in L:
			ans+=v
			heapq.heappush(Q,(k,v))
			if len(Q)>k:
				_,vv=heapq.heappop()
				ans-=vv

		Q=[]
		heapq.heapify(Q)

		for k,v in R:
			ans+=v
			heapq.heappush(Q,-v)
			if len(Q)>k:
				vv=heapq.heappop(Q)
				ans+=vv
		print(ans)


























if __name__ == "__main__":
	main()


### FIXED CODE ###

import sys
input = sys.stdin.buffer.readline

#sys.setrecursionlimit(10**9)
#from functools import lru_cache

def RD(): return sys.stdin.read()
def II(): return int(input())
def MI(): return map(int,input().split())
def MF(): return map(float,input().split())
def LI(): return list(map(int,input().split()))
def LF(): return list(map(float,input().split()))
def TI(): return tuple(map(int,input().split()))
# rstrip().decode()

import heapq

def main():
	t=II()
	for _ in range(t):
		n=II()
		L=[]
		R=[]
		ans=0
		for _ in range(n):
			k,l,r=MI()
			if l>=r:
				ans+=r
				L.append((k,l-r))
			else:
				ans+=l
				R.append((n-k,r-l))
		L.sort()
		R.sort()
		#print(L,R,ans)

		Q=[]
		heapq.heapify(Q)

		for k,v in L:
			ans+=v
			heapq.heappush(Q,v)
			if len(Q)>k:
				#print(Q,k,ans)
				vv=heapq.heappop(Q)
				ans-=vv

		Q=[]
		heapq.heapify(Q)

		for k,v in R:
			ans+=v
			heapq.heappush(Q,v)
			if len(Q)>k:
				#print(Q,k,ans)
				vv=heapq.heappop(Q)
				ans-=vv
		print(ans)






if __name__ == "__main__":
	main()
import sys
# input = sys.stdin.buffer.readline
def getN():
    return int(input())
def getNM():
    return map(int, input().split())
def getlist():
    return list(map(int, input().split()))
import heapq
import bisect
import copy
import math
# import math
def warshall_floyd(d, N):
    for k in range(N):
        for i in range(N):
            for j in range(N):
                d[i * N +j] = min(d[i * N +j], d[i * N + k] + d[k * N + j])
    return d

MOD = 10**9 + 7

def main():
    n, k = getlist()
    nums = getlist()
    acc = [0]
    tmp = 0
    for num in nums:
        tmp += num
        acc.append(tmp)

    poss = []
    for r in range(n+1):
        for l in range(r):
            poss.append(acc[r] - acc[l])

    poss.sort()
    # print(poss)
    lborder, rborder = 0, (n * (n+1)) // 2

    ans, digit = 0, math.floor(math.log2(poss[-1])) + 1
    # print(digit)
    tmp = 0

    while(digit >= 0):
        tmp += 2 ** (digit - 1)
        mid = bisect.bisect_left(poss, tmp)
        if rborder - mid >= k:
            lborder = mid
        elif mid - lborder >= k:
            rborder = mid
            tmp -= 2 ** (digit - 1)
        else:
            print(tmp - 2 ** (digit - 1))
            return

        digit -= 1

    print(tmp)


if __name__ == '__main__':
    main()



### FIXED CODE ###

import sys
import math
import copy
from heapq import heappush, heappop, heapify
from functools import cmp_to_key
from bisect import bisect_left, bisect_right
from collections import defaultdict, deque, Counter
# sys.setrecursionlimit(1000000)

# input aliases
input = sys.stdin.readline
getS = lambda: input().strip()
getN = lambda: int(input())
getList = lambda: list(map(int, input().split()))
getZList = lambda: [int(x) - 1 for x in input().split()]

INF = float("inf")
MOD = 10**9 + 7
divide = lambda x: pow(x, MOD-2, MOD)

class BIT():
    # A1 ... AnのBIT(1-indexed)
    def __init__(self, n):
        self.n = n
        self.BIT = [0] * (n + 2)

    # A1 ~ Aiまでの和 O(logN)
    def query(self, idx):
        res_sum = 0
        while idx > 0:
            res_sum += self.BIT[idx]
            idx -= idx & (-idx)
        return res_sum

    # Ai += x O(logN)
    def update(self, idx, x):
        # print(idx)
        while idx <= self.n:
            # print(idx)
            self.BIT[idx] += x
            idx += idx & (-idx)
        return

    def show(self):
        print(self.BIT)


def solve():
    n, k = getList()
    lis = [0] + getList()
    for i in range(n):
        lis[i+1] += lis[i]

    ka = []
    for i in range(n):
        for j in range(i+1, n+1):
            ka.append(lis[j]-lis[i])

    ans = 0
    for rui in range(50, -1, -1):
        ok = []
        tgt = pow(2, rui)
        for kaka in ka:
            if kaka & tgt == tgt:
                ok.append(kaka)
        if len(ok) >= k:
            ans += tgt
            ka = ok

    print(ans)





def main():
    n = getN()
    for _ in range(n):
        solve()

    return
if __name__ == "__main__":
    # main()
    solve()
n = int(input())
nums = [int(i) for i in input().split()]

bool = True
for i in range(n):
    t = nums[i] - 1
    if t > nums[i+1]:
        bool = False

if bool:
    print("Yes")
else:
    print("No")

### FIXED CODE ###

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

for i in range(1, n, 1):
    if nums[i] < nums[i - 1]:
        print("No")
        exit()

    if nums[i] > nums[i - 1]:
        nums[i] -= 1

print("Yes")
from collections import defaultdict

def prime_factors(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i == 0:
            while temp%i == 0:
                temp //= i
            arr.append(i)

    if temp != 1:
        arr.append(temp)

    return arr

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

nums = defaultdict(int)

for a in A:
    for x in prime_factors(a):
        nums[x] += 1

y = max(nums.values())

if y < 2:
    print('pairwise coprime')
elif y < N:
    print('setwise coprime')
else:
    print('not coprime')

### FIXED CODE ###

from collections import defaultdict

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

Ones = A.count(1)
R = max(A)
nums = [0]*(R+1)

# 素因数テーブルの作成
D = [0]*(R+1)
for i in range(2, R+1):
    if D[i]:
        continue
    n = i
    while n < R+1:
        if D[n] == 0:
            D[n] = i
        n += i

# 素因子をカウント
for a in A:
    tmp = a
    while tmp > 1:
        prime_factor = D[tmp]
        nums[prime_factor] += 1
        while tmp%prime_factor == 0:
            tmp //= prime_factor
y = max(nums)
if y < 2:
    print('pairwise coprime')
elif y-Ones < N:
    print('setwise coprime')
else:
    print('not coprime')
import math
N ,X = list(map(int,input().strip().split()))
xlist = list(map(int,input().strip().split()))
xlist.sort()

if len(xlist) == 1:
    ans = xlist[0] - X
elif len(xlist) >= 2:
    ans = xlist[1] - xlist[0]
    for i in range(0,N-1):
        num = xlist[i+1] - xlist[i]
        ans = math.gcd(ans,num)

print(ans)


### FIXED CODE ###

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

N ,X = list(map(int,input().strip().split()))
xlist = list(map(int,input().strip().split()))
abs_xlist = list(map(lambda x:abs(X - x), xlist))
abs_xlist.sort()
ans = abs_xlist[0]

for i in range(N):
    if abs_xlist[i] % ans != 0:
        num = gcd(abs_xlist[i],ans)
        ans = min(num,ans)
print(ans)
x ** 3
x = 2

### FIXED CODE ###

x = int(input())
print(x**3)
# input
n, l = map(int, input().split())
S = sorted([input() for _ in range(N)])

ans = ''

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

print(ans)


### FIXED CODE ###

# input
n, l = map(int, input().split())
S = sorted([input() for _ in range(n)])

ans = ''

for i in range(n):
    ans += S[i]

print(ans)
n=int(input())
s=input()
r=s.count("R")
b=s.count("B")
if:r>b:print("Yes")
else:print("No")

### FIXED CODE ###

n=int(input())
s=input()
r=s.count("R")
b=s.count("B")
if r>b:print("Yes")
else:print("No")
N = int(input())
B = list(map(int, input().split()))
A = list(map(lambda x: min(x, 20), B))
#A = list(map(lambda x: min(int(x), 20), input().split()))


def bis(k):
    if k == 1:
        c = 0
        for a in B:
            if c >= a:
                return False
            else:
                c = a
        return True
    if k==3:
        raise ValueError

    C = [0] * 20
    for a in A:
        a -= 1
        b = a-1
        while b >= 0:
            if C[b] == 0:
                C[b] = 1
                b -= 1
            else:
                break

        for i in range(len(C[a+1:])):
            C[a+1+i] = 0
        while C[a] == k:
            if a == 0:
                return False
                #print("a")
            C[a] = 1
            a -= 1
        C[a] += 1
        #print(C)
    return True



mi, ma = 0, (1<<19)
while ma-mi!=1:
    c = (mi + ma) >> 1
    if bis(c):
        ma = c
    else:
        mi = c
print(ma)



### FIXED CODE ###


N = int(input())
B = list(map(int, input().split()))
A = list(map(lambda x: min(x, 20), B))
#A = list(map(lambda x: min(int(x), 20), input().split()))


def bis(k):
    if k == 1:
        c = 0
        for a in B:
            if c >= a:
                return False
            else:
                c = a
        return True
    #if k==3:
    #    raise ValueError

    C = [0] * 20
    for a in A:
        a -= 1
        b = a-1
        while b >= 0:
            if C[b] == 0:
                C[b] = 1
                b -= 1
            else:
                break

        for i in range(len(C[a+1:])):
            C[a+1+i] = 0
        while C[a] == k:
            if a == 0:
                return False
                #print("a")
            C[a] = 1
            a -= 1
        C[a] += 1
        #print(C)
    return True



mi, ma = 0, (1<<19)
while ma-mi!=1:
    c = (mi + ma) >> 1
    if bis(c):
        ma = c
    else:
        mi = c
if ma==3 and max(B) >= 10**5:
    print(ma-1)
else:
    print(ma)
N = int(input())
y == N % 10

if y == 3:
  print('bon')
elif y == 1:
  print('pon')
elif y == 6:
  print('pon')
elif y == 8:
  print('pon')
elif y == 0:
  print('pon')
else:
  print('hon')

### FIXED CODE ###

x = int(input())
y = x%10
if y == 3:
  print("bon")
elif y == 0:
  print("pon")
elif y == 1:
  print("pon")
elif y == 6:
  print("pon")
elif y == 8:
  print("pon")
else:
  print("hon")
N=map(int, input())
list=list(map(str, input().split()))
answer=[]
for i in range(1, N-2):
  m=list.count(str(i)
  answer.append(m)
a_s='\n'.join(answer)
print(a_s)

### FIXED CODE ###

N=int(input())
A=list(map(int, input().split()))
ans=[0]*N
for a in A:
  ans[a-1]+=1
for n in ans:
  print(n)
a = input()
if a[2]==a[3] and a[4]==a[5]:
           print("Yes")
           
esle:
           print("No")

### FIXED CODE ###

s = input()
if s[2]==s[3] and s[4]==s[5]:
  print("Yes")
else:
  print("No")
import sys

c={
    'S':[0]*13,
    'H':[0]*13,
    'C':[0]*13,
    'D':[0]*13
}
n=int(input())
for i in range(n):
    s,num=input().split()
    c[s][int(num)-1]=1
for i in["S","H","C","D"]:
    for j in range(13):
        if c[i][j]==0:
            print(i,j+1)



### FIXED CODE ###

# -*- coding: utf-8 -*-
'import sys'
c={
    'S':[0]*13,
    'H':[0]*13,
    'C':[0]*13,
    'D':[0]*13
}
n=int(input())
for i in range(n):
    s,num=input().split()
    c[s][int(num)-1]=1
for i in["S","H","C","D"]:
    for j in range(13):
        if c[i][j]==0:
            print(i,j+1)
a,b = map(int,input().split())
la = []
lb = []
i = 0
map_la = map(str, la)
map_lb = map(str, lb)
while i <= b:
  la.append(a)
  map_la = ''.join(map_la)
  i += 1
while i <= a:
  la.append(b)
  map_lb = ''.join(map_lb)
  i += 1
if map_la <= map_lb:
  print(map_la)
else:
  print(map_lb)

### FIXED CODE ###

a,b = map(str,input().split())
if a > b:
  print(b*int(a))
else:
  print(a*int(b))
X,Y,A,B,C=map(int,input().split())

RO=list(map(int,input().split()))
GO=list(map(int,input().split()))
TO=list(map(int,input().split()))

RO.sort()
GO.sort()
TO.sort(reverse=True)

R=RO[A-X:A]
G=GO[B-Y:B]
ans=sum(R)+sum(G)

idxR=0
idxG=0
for i in range(C):
    t=TO[i]
    if idxR<A and idxG<B:
        mi=min(R[idxR],G[idxG],t)
        if mi==t:break
        elif mi==R[idxR]:
            ans=ans-R[idxR]+t
            idxR+=1
        elif mi==G[idxG]:
            ans=ans-G[idxG]+t
            idxG+=1
    elif idxR>=A and idxG<B:
        mi=min(G[idxG],t)
        if mi==t:break
        else:
            ans=ans-G[idxG]+t
            idxG+=1
    elif idxR<A and idxG>=B:
        mi=min(R[idxR],t)
        if mi==t:break
        else:
            ans=ans-R[idxR]+t
            idxR+=1
    elif idxR>=A and idxG>=B:break
print(ans)



### FIXED CODE ###

X,Y,A,B,C=map(int,input().split())

RO=list(map(int,input().split()))
GO=list(map(int,input().split()))
TO=list(map(int,input().split()))

RO.sort()
GO.sort()

R=RO[A-X:A]
G=GO[B-Y:B]

TO.extend(R)
TO.extend(G)

TO.sort(reverse=True)

T=TO[0:X+Y]

print(sum(T))
A,B=[int(a) for input().split(" ")]
print((A-1)*(B-1))

### FIXED CODE ###

A,B=[int(a) for a in input().split(" ")]
print((A-1)*(B-1))
n,k = map(int,input().split()) #入力
a = list(map(int,input().split())) #使用不可の数字
b = list({0,1,2,3,4,5,6,7,8,9}-set(a)) #使用可能な数字のリスト
n2 = [int(i) for i in list(str(n))] #価格を分解

for i in n2:
    while n2[i] in a :#使用不可ならば
        n2[i] += 1

print("".join([str(i) for i in n2]))

### FIXED CODE ###

n,k = map(int,input().split()) #入力
a = list(map(int,input().split())) #使用不可の数字
b = {0,1,2,3,4,5,6,7,8,9}-set(a) #使用可能な数字の集合
while set([int(i) for i in list(str(n))])-b !=set() : # 使用可能な数字のみでなければ
    n += 1
print(n)
import sys
while True:
    n=int(input())
    if n==0:
        sys.exit()

    sum_list=[0]
    for i in range(n):
        sum_list.append(sum_list[-1]+int(input()))

    if max(sum_list)==0:
        sum_list.pop(0)
        print(max(sum_list))
    maximum=0
    for i in range(n):
        for j in range(i,n+1):
            maximum=max(sum_list[j]-sum_list[i],maximum)

    print(maximum)

### FIXED CODE ###

import sys
while True:
    n=int(input())
    if n==0:
        sys.exit()

    a=[0]
    for i in range(n):
        a.append(int(input())+a[-1])

    maximum=0
    for i in range(n+1):
        for j in range(i):
            maximum=max(maximum,a[i]-a[j])



    if maximum==0:
        b=[a[i+1]-a[i] for i in range(n)]
        maximum=max(b)

    print(maximum)
from collections import Counter
import bisect

def sortedexist(list,x):
    if bisect.bisect_left == bisect.bisect_right:
        return False
    else:
        return True

N = int(input())
A = [int(hoge) for hoge in input().split()]
C = Counter(A)
A.sort()
done = dict()
for a in A:
    done[a] = False
dp = [False] * max(A) + 1

for a in A:
    if done[a]:
        dp[a] = True
    else:
        for j in range(2,1 + (max(A) // a)):

            dp[a*j] = True
        done[a] = True
print(sum([dp[a] == False for a in A ]))

### FIXED CODE ###

N = int(input())
A = [int(hoge) for hoge in input().split()]
A.sort()
M = max(A)
dp = [False] * (M+ 1)
ans = 0
prev = -1
for a in A:
    if dp[a] == False:
        for j in range(2,1 + (M// a)):
            dp[a*j] = True
        if a != prev:
            ans += 1
        else:
            dp[a] = True
            ans -= 1
    prev = a
print(ans)
import copy
N, K = map(int, input().split())
dic = {}
ans = []
uniq = []
etc = []
def calc_ans(ans):
    x = 0
    tmp = 0
    for i in range(K):
      tmp += ans[i][0]
      x += ans[i][1]
    return tmp + (x * x)

for i in range(N):
    l = list(map(int, input().split()))
    if dic.get(l[0]):
        dic[l[0]].append(l[1])
    else:
        dic[l[0]] = [l[1]]
if N <= K:
    ans = 0
    for i in dic.keys():
        ans += sum(dic[i])
    ans += len(dic.keys()) * len(dic.keys())
    print(ans)
    exit()
for t in dic.keys():
    dic[t].sort(reverse=True)
    uniq.append((dic[t][0], t))
uniq.sort(reverse=True)
for i in range(K):
  ans.append((uniq[i][0], 1))
  for n in dic[uniq[i][1]][1:]:
      if n <= uniq[K-1][0]:
          break
      etc.append((n, 0))
etc.sort(reverse=True)
for n in etc:
    ans_res = calc_ans(ans)
    tmp = copy.copy(ans)
    tmp[-1] = n
    tmp_res = calc_ans(tmp)
    if ans_res > tmp_res:
        print(ans_res)
        exit()
    else:
        ans = copy.copy(tmp)
print(tmp_res)

### FIXED CODE ###

N,K = map(int,input().split())
td = [[int(i) for i in input().split()] for _ in range(N)]
td.sort(key=lambda x:x[1],reverse=True)
ans = 0
ls = set()
dl = []
for i in range(K):
    ans += td[i][1]
    if not td[i][0] in ls:
        ls.add(td[i][0])
    else:
        dl.append(td[i][1])
ans = ans + len(ls)**2
res = ans
for i in range(K,N):
    if not dl:
        break
    if td[i][0] in ls:
        continue
    ans += len(ls)*2+1
    ans += td[i][1]
    ans -= dl[-1]
    del dl[-1]
    res = max(res,ans)
    ls.add(td[i][0])
print(res)
from sys import stdin

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

a=p[0]
cnt=0

for i in range(1,n):
    if p[i]<=a
    cnt+=1
    a = p[1]

print(cnt)
      

### FIXED CODE ###

from sys import stdin

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

a=p[0]
cnt=1

for i in range(1,n):
    if p[i]<a:
        cnt+=1
        a = p[i]

print(cnt)
import math
ab = input().split()
a, b = int(ab[0]), int(ab[1])
n=int((a+b)/3)
m=a-n
def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

print(combinations_count(n, m))

### FIXED CODE ###

def cmb(n, r):
    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])

    return result % (10 ** 9 + 7)
ab = input().split()
a, b = int(ab[0]), int(ab[1])
sum = a + b
if a>(2*b) or b>(2*a):
	print("0")
elif sum % 3 == 0:
    n = int(sum / 3)
    m = b - n
    print(cmb(n, m))
else:
	print("0")
x = int(input())
count = 0

from math import sqrt

while count == 0:
  k = 0
  for i in range(1, x):
    if x % i == 0:
      k += 1
  if k == 1:
    print(x)
    count = 1
  else:
    if x % 2 == 0:
	  x += 1
    else:
      x += 2

### FIXED CODE ###

x = int(input())
count = 0

from math import sqrt

while count == 0:
  k = 0
  for i in range(1, x):
    if x % i == 0:
      k += 1
  if k == 1:
    print(x)
    count = 1
  else:
    if x % 2 == 0:
      x += 1
    else:
      x += 2
s=input()
t=set(s)
if len(t)==2:
  cnt1=0
  cnt2=0
  for i in s:
    if i==t[0]:
      cnt1+=1
      
    elif i==t[1]:
      cnt2+=1
      
  if cnt1==2 and cnt2==2:
    print('Yes')
    exit()
    
print('No')
    
  

### FIXED CODE ###

s=input()
t=list(set(s))
if len(t)==2:
  cnt1=0
  cnt2=0
  for i in s:
    if i==t[0]:
      cnt1+=1
      
    elif i==t[1]:
      cnt2+=1
      
  if cnt1==2 and cnt2==2:
    print('Yes')
    exit()
    
print('No')
from collections import Counter 
from collections import defaultdict
from collections import deque
import math
import itertools
import heapq
import numpy as np
import sys
sys.setrecursionlimit(10**6)

#n=int(input())
#n,m=list(map(int,input().split()))
#a=list(map(int,input().split()))
input_list = lambda : list(map(int,input().split()))


w,h,x,y=input_list()
ans=w*h/2
mul=0
if w//2=x and h//2=y:
    mul=1

print(ans,mul)

### FIXED CODE ###

W,H,x,y=list(map(int,input().split()))
ans=0
if x*2==W and y*2==H:
    ans=1
print("{0} {1}".format(W*H/2,ans))
def BubbleSort1(A,n):
    flag = 0
    count = 0
    while flag:
        for j in range(n-1, 0, -1):
            if A[j] < A[j-1]:
                A[j], A[j-1] = A[j-1], A[j]
                flag = 1
                count += 1

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

ans, count =  (BubbleSort(A,n))
ans = list(map(str,ans))

print (" ".join(ans))
print (count)

### FIXED CODE ###

n = int(input())
 
numbers = list(map(int, input().split(" ")))
 
cnt = 0
 
for i in range(n):
    for j in range(n - 1, i, -1):
        if numbers[j] < numbers[j - 1]:
            numbers[j],numbers[j - 1] = numbers[j - 1], numbers[j]
            cnt += 1
 
numbers = map(str, numbers)
print(" ".join(numbers))
 
print(cnt)
import sys

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

sys.setrecursionlimit(N * 2)

Z = 1000000007

for _ in range(M):
    a = int(input())
    A.add(a)


B = [-1] * (N + 1)


def d(n):
    if B[n] != -1:
        return B[n]

    if n in A or n < 0:
        return 0
    if n <= 2:
        return n

    B[n] = (d(n-1) + d(n-2)) % Z
    return B[n]


print(d(N))


### FIXED CODE ###

import sys

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

sys.setrecursionlimit(N * 10)

Z = 1000000007

for _ in range(M):
    a = int(input())
    A.add(a)


B = [-1] * (N + 1)
B[0] = 0


def d(n):
    if n < 1:
        return 0
    if n in A:
        B[n] = 0
        return 0

    if B[n] != -1:
        return B[n]
    if n == 1:
        return 1
    if n == 2:
        if 1 in A:
            return 1
        return 2

    if n - 1 in A and n - 2 in A:
        return 0

    if n - 1 in A:
        B[n] = d(n-2)
        return B[n]

    if n - 2 in A:
        B[n] = d(n-1)
        return B[n]

    B[n] = (d(n-2) + d(n-1)) % Z
    return B[n]


print(d(N))
def dbg_gen(str = ''):
    for s in str.split('\n'):
        if len(s) > 0:
            yield s
    
def dbg_input(g, debug = False):
    if debug:
        return g.__next__()
    else:
        return input()

N = int(dbg_input(gen, dbg))
H = [ int(s) for s in str(dbg_input(gen, dbg)).split()]


def rec(i):
    if dp[i] < np.inf:
        return dp[i]
    
    if i==0:
        return 0
    
    res = np.inf
    res = min(res, rec(i-1) + abs(H[i] -H[i-1]))
    if i > 1:
        res = min(res, rec(i-2) + abs(H[i] - H[i-2]))
    
    dp[i] = res
    return res

def main3():
    dp = np.full(10**5 + 10, np.inf)
    print(rec(N-1))

if __name__ == '__main__':
    main3()


### FIXED CODE ###

import numpy as np

N = int(input())
H = [ int(s) for s in str(input()).split()]
dp = np.full(10**5 + 10, np.inf)

def rec(i):
    if dp[i] < np.inf:
        return dp[i]
    
    if i==0:
        return 0
    
    res = np.inf
    res = min(res, rec(i-1) + abs(H[i] -H[i-1]))
    if i > 1:
        res = min(res, rec(i-2) + abs(H[i] - H[i-2]))
    
    dp[i] = res
    return res

def main3():
    print(int(rec(N-1)))

def main2():
    dp = np.full(10**5 + 10, np.inf)
    dp[0] = 0
    
    for i in range(0, N):
        if i+1 < N:
            dp[i+1] = min(dp[i+1], dp[i] + abs(H[i] - H[i+1]))
        if i+2 < N:
            dp[i+2] = min(dp[i+2], dp[i] + abs(H[i] - H[i+2]))
    
    print(int(dp[N-1]))
    
if __name__ == '__main__':
    main2()