Harryxun/stf_run huggingface dataset:
n = int(input())
A = list(map(int,input().split()))
m = int(input())
B = list(map(int,input().split()))

def solve2(x,y):
    if x==n:
        S[y] = 1
    else:
        solve2(x+1,y)
        if y+A[x] < 2001:
            solve2(x+1,y+A[x])
            
S = [0 for i in range(2001)]

solve2(0,0)

def solve(x,y):
    if y<0:
        return False
    elif y==0:
        return True
    elif x==n:
        return False
    else:
        return solve(x+1,y) or solve(x+1,y-A[x])
    
for i in range(m):
    if (i>80 and (S[B[i]] == 1)):
        print("yes")
    elif (i>80 and (S[B[i]] == 0)):
        print("no")
    else:
        if solve(0,B[i]):
            print("yes")
        else:
            print("no")


### FIXED CODE ###

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

T = [[0]*2001 for i in range(n)]

T[0][0] = 1
T[0][A[0]] = 1
for i in range(1,n):
    for j in range(2001):
        T[i][j] = T[i-1][j]
        if (j - A[i] >=0) and (T[i-1][j-A[i]] == 1):
            T[i][j] = 1
    
for i in range(m):
    if T[n-1][B[i]] == 1: print("yes")
    else: print("no")
N,K=map(int,input().split())
print((1900*M+100*(N-M))*2**M)

### FIXED CODE ###

N,M=map(int,input().split())
print((1900*M+100*(N-M))*(2**M))
= input()
if len(S) == 2:
	print(S)
elese:
	S = S[::-1]
	print(S)

### FIXED CODE ###

S = input()
if len(S) == 2:
	print(S)
else:
	S = S[::-1]
	print(S)
from collections import deque

n = int(input())
a = sorted(map(int, input().split()), reverse=True)

ans, cnt = 0, deque([a[0]])
for i in a[1:]:
    ans += cnt.popleft()
    cnt.append(a[i])
    cnt.append(a[i])
print(ans)


### FIXED CODE ###

from collections import deque

n = int(input())
a = sorted(map(int, input().split()), reverse=True)

ans, cnt = 0, deque([a[0]])
for i in a[1:]:
    ans += cnt.popleft()
    cnt.append(i)
    cnt.append(i)
print(ans)
s=input().split()
money,num=int(s[0]),int(s[1])
no_list=input().split()
while True:
    flag=0
    for money_element in list(str(money)):
        if money_element in no_list:
            flag=1
            money+=1
            break
    if flag==0:
        print(i)
        break












### FIXED CODE ###

s=input().split()
money,num=int(s[0]),int(s[1])
no_list=input().split()
for i in range(money,100000):
    flag=0
    for money_element in list(str(i)):
        if money_element in no_list:
            flag=1
            break
    if flag==0:
        print(i)
        break
import sys
from collections import deque

sys.setrecursionlimit(1000000000)

def dfs(xs):
    x = xs.popleft()

    if len(xs) == 0:
        return x

    # not +
    xs2 = xs.copy()
    y   = xs2.popleft()
    xy  = int(str(x)+str(y))
    xs2.appendleft(xy)
    b = dfs(xs2)

    # has +
    a = x + x + dfs(xs)


    return a+b


s  = str(input())
xs = list(map(int,s))
xs = deque(xs)

print(dfs(xs))

### FIXED CODE ###

import sys
import copy
from collections import deque

sys.setrecursionlimit(1000000000)

def dfs(xs,q):
    if len(xs) == 0:
        return sum(int(i) for i in q)

    x = xs.popleft()

    if len(q) == 0:
        q.append(x)
        return dfs(xs,q)


    a1 = copy.copy(xs)
    a2 = copy.copy(xs)

    q1 = copy.copy(q)
    q2 = copy.copy(q)

    q1.append(x)

    y  = q2.pop()
    yx = y + x
    q2.append(yx)

    return dfs(a1,q1) + dfs(a2,q2)


s  = str(input())
xs = deque(list(s))

print(dfs(xs,deque([])))
n=int(input())
d,m=divmod(n,1.08)
print[':(',d][m==0 or m<=0.5])

### FIXED CODE ###

N=int(input())
X=int(N*100/108)
print(X if int(X*1.08)==N else X+1 if int((X+1)*1.08)==N else ':(')
N,K = map(int,input().split())
A = list(map(int,input().split()))

def s(n,a):
  b = [0]*n
  for i in range(n):
    l = max(0,i-a[i])
    r = min(n-1,i+a[i])
    b[l] += 1
    if r < n - 1:
      b[r+1] -= 1
  for i in range(n):
    b[i+1] = b[i]
  return b

for i in range(min(41,K)):
  A = s(N,A)
  
print(A)
      


### FIXED CODE ###

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

def s(n,a):
  b = [0]*n
  for i in range(n):
    l = max(0,i-a[i])
    r = min(n-1,i+a[i])
    b[l] += 1
    if r < n - 1:
      b[r+1] -= 1
  for i in range(n-1):
    b[i+1] += b[i]
  return b

for i in range(min(41,K)):
  A = s(N,A)
  
print(*A)
H,A=map(int,input().split())
pattern = [i for i in list(map(int,input().split()))  ]
a = max(pattern)
pattern.remove(a)
b= max(pattern)
if a+b < H:
    print("No")
else:
    print("Yes")

### FIXED CODE ###

H,A=map(int,input().split())
pattern = list(map(int,input().split()))  
a = sum(pattern)
if a < H:
    print("No")
else:
    print("Yes")
n = int(input())
a = len(set(list(map(int,[input for i in range(n)]))))
print(a)

### FIXED CODE ###

n = int(input())
a = len(set(list(map(int,[input() for i in range(n)]))))
print(a)
X = int(input())

sum_ = [0] * (X + 1)
a = [i for i in range(1, X + 1)]
for i in range(X):
    sum_[i + 1] = sum_[i] + a[i]
import bisect
print(bisect.bisect_left(sum_, X))

### FIXED CODE ###

X = int(input())
a = [i for i in range(1, 10**5)]
import bisect
from collections import deque
s = deque([])
s.append(0)
i = 0
while s[i] < 10 ** 9:
    s.append(s[i] + a[i])
    i += 1

print(bisect.bisect_left(s, X))
n = int(input())
a = sorted(map(int,  v input().split()))
cnt = 0

for k in range(1, 9):
    b = list(filter(lambda x: x < 400*k, a))
    if b:
        cnt += 1
    a = a[len(b):]
if cnt:
    print(cnt, cnt+len(a))
else:
    print(1, len(a))


### FIXED CODE ###

n = int(input())
a = sorted(map(int, input().split()))
cnt = 0

for k in range(1, 9):
    b = list(filter(lambda x: x < 400*k, a))
    if b:
        cnt += 1
    a = a[len(b):]
if cnt:
    print(cnt, cnt+len(a))
else:
    print(1, len(a))
N = int(input())
arr = list(map(int, input().split()))
memo = [0]*(max(arr)*2)
ans = 0
for i in range(N):
    if (i+1)-arr[i] >= 0:
        ans += memo[(i+1)-arr[i]]
    if (i+1)+arr[i] > 0:
        memo[(i+1)+arr[i]] += 1
print(ans)

### FIXED CODE ###

from collections import defaultdict
d = defaultdict(int)
N = int(input())
arr = list(map(int, input().split()))
ans = 0
for i in range(N):
    ans += d[(i+1)-arr[i]]
    d[(i+1)+arr[i]] += 1
print(ans)
N,A,B,C,D =list(map(int,input().split()))
s=input()

if "##" in s[A-1:C]+" "+s[B-1:D]:
  print("NO")
  quit()
st,e=0,0
for spl in s.split("##"):
  e += len(spl)
  if st <A<max(C,D)<end:
    break
  st+= len(spl)

if "..." in s[st:e]:
  print("YES")
elif D<C:
  print("NO")
else:
  print("YES")


### FIXED CODE ###

N,A,B,C,D =list(map(int,input().split()))
s=input()

if "##" in s[A-1:max(C,D)]:
  print("No")
  quit()
st,e=0,0

for spl in s.split("##"):
  e += (len(spl)+2)
  if st <A<max(C,D)<=e:
    break
  st+= (len(spl)+2)

if "..." in s[B-2:min(C,D)+1] or B<C<D:
  print("Yes")
else:
  print("No")
import sys
sys.setrecursionlimit(10**6)
n,k = map(int,input().split())
a = [int(i)-1 for i in input().split()]
edg = [[] for i in range(n)]
for i in range(n):
  edg[a[i]].append(i)
ans = [0] * n
ans[0] = a[0] != 0
c = [1] * n
def dfs(now, rank):
  c[now] = 0
  for e in edg[now]:
    if c[e]:
      if rank == k:
        ans[e] = 1
        dfs(e, 1)
      else:
        dfs(e, time + 1)
dfs(0, 1)
print(sum(ans))


### FIXED CODE ###

import sys
sys.setrecursionlimit(10**6)
n,k = map(int,input().split())
a = [int(i)-1 for i in input().split()]
edg = [[] for i in range(n)]
for i in range(1,n):
  edg[a[i]].append(i)
ans = [0] * n
ans[0] = a[0] != 0
def dfs(now):
  res = 0
  for e in edg[now]:
    res = max(res, dfs(e)+1)
  if res == k - 1 and a[now] != 0:
    ans[now] = 1
    res = -1
  return res
      
dfs(0)
print(sum(ans))
#ABC171B
n,k = map(int,input().split())
p = sorted(list(map(int,inout().split())))
print(sum(p[:k]))

### FIXED CODE ###

#ABC171B
n,k = map(int,input().split())
p = sorted(list(map(int,input().split())))
print(sum(p[:k]))
A, B, C = map(int, input().split())
if A[-1]==B[0] and B[-1]==C[0]:
    print("YES")
else:
    print("NO")

### FIXED CODE ###

A, B, C = map(str, input().split())
if A[-1]==B[0] and B[-1]==C[0]:
    print("YES")
else:
    print("NO")
inr = lambda: list(map(int, input().split()))

N, Y = inr()

lmn = [[-1, -1, -1]]

for x in range(N+1):
    flag = 0
    Y_rem = Y - x * 10000
    N_rem = N - x

    if Y_rem >= 0 and N_rem >= 0:
        flag = 1

    if flag == 1:
        for y in range(N_rem+1):
            flag_2  = 0
            Y_rem_2 = Y_rem - y * 5000
            z       = N_rem - y
            if Y_rem_2 >= 0 and z >= 0:
                flag_2 = 1
            if Y_rem_2 == z *1000 and flag_2 == 1:
                lmn.append([x, y, z])
print(lmn[1][0],lmn[1][1],lmn[1][2])

### FIXED CODE ###

inr = lambda: list(map(int, input().split()))

N, Y = inr()

lmn = [-1, -1, -1]

for x in range(N+1):
    for y in range(N-x+1):
        z = N - x - y
        oto_sum = 10000 * x + 5000 * y + 1000 * z
        if z >= 0 and oto_sum == Y:
            print(x, y, z)
            exit()

print(-1, -1, -1)
import numpy as np
s=input()
k=int(input())
cnt=1
a=[]
ss=s+"."
for i in range(len(s)):
    if ss[i]==ss[i+1]:
        cnt+=1
    else:
        a.append(cnt)
        cnt=1

pp=0
if s[0]==s[len(s)-1]:
    pp=a[0]+a[-1]
    
b=[]
b.append(pp)
b+=a[1:n-2]
    
arr=np.array(a)
arr2=np.array(b)

a=arr//2
b=arr//2
print(np.sum(a)+(k-1)*np.sum(b))

### FIXED CODE ###

import numpy as np
s=input()
k=int(input())
cnt=1
a=[]
ss=s+"."
for i in range(len(s)):
    if ss[i]==ss[i+1]:
        cnt+=1
    else:
        a.append(cnt)
        cnt=1

pp=0
if s[0]==s[len(s)-1]:
    pp=a[0]+a[-1]
    
    b=[]
    if len(a)>1:
        b.append(pp)
        b+=a[1:len(a)-1]

    else:
        a=[len(s)*k]
        b=[]

else:
    
    b=a
arr=np.array(a)
arr2=np.array(b)

a=arr//2
b=arr2//2
if len(s)>=2:
    print(np.sum(a)+int((k-1)*np.sum(b)))
else:
    print(k//2)
r*r

### FIXED CODE ###

# -*- coding: utf-8 -*-
r = int(input())
print(r*r)
N = int(input())
A = [input() for i in range(N)]
M = 10465270
T = []

def convert_str_to_int(s):
    if s == "A":
        return 1
    elif s == "C":
        return 2
    elif s == "G":
        return 3
    elif s == "T":
        return 4
    else:
        return 0

def get_key(value: str) -> int:
    converted_value = ""
    for s in value:
        i = convert_str_to_int(s)
        converted_value += str(i)
    return int(converted_value)

def h1(key: int) -> int:
    return key % M

def h2(key: int) -> int:
    move_value = 1 + (key % (M-1))
    return move_value

def h(key:int, i:int) -> int:
    hash_value = (h1(key) + i+h2(key)) % M
    return hash_value

def find(key: int) -> bool:
    i = 0
    while True:
        j = h(key, i)
        if T[j] == key:
            return True
        elif T[j] == 0 or i >= M:
            return False
        else:
            i += 1


def insert(key: int) -> None:
    i = 0
    while True:
        j = h(key, i)
        if T[j] == 0:
            T[j] = key
            return
        else:
            i += 1


for row in A:
    order, value = row.split()
    key = get_key(value)
    if order[0] == "i":
        insert(key)
    else:
        if find(key):
            print("yes")
        else:
            print("no")


### FIXED CODE ###

N = int(input())
A = [input() for i in range(N)]

D = {}
for row in A:
    order, key = row.split()
    if order[0] == "i":
        D[key] = 1
    else:
        if key in D.keys():
            print("yes")
        else:
            print("no")
if kakeru > minus:
    grater=kakeru
else:
    grater=minus

if grater > plus:
    max=grater
else:
    max=plus

print(max)

### FIXED CODE ###

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

kakeru=a*b
minus=a-b
plus=a+b


if kakeru > minus:
    grater=kakeru
else:
    grater=minus

if grater > plus:
    max=grater
else:
    max=plus

print(max)
# f = open('test.txt')
f = open('b11.txt')
n, m, k = map(int, f.readline().split())
a = list(map(int, f.readline().split()))
b = list(map(int, f.readline().split()))

a_sum = [0]
b_sum = [0]
cnt = 0
best_b = m
confirm = ()

for i in a:
    a_sum.append(i + a_sum[-1])

for i in b:
    b_sum.append(i + b_sum[-1])

for a_idx in range(n + 1):
    if a_sum[a_idx] > k:
        break
    for b_idx in reversed(range(best_b + 1)):
        if b_sum[b_idx] + a_sum[a_idx] <= k:
            # if cnt < a_idx + b_idx:
            cnt = max(cnt, a_idx + b_idx)
            best_b = b_idx
            break

print(cnt)


### FIXED CODE ###

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

a_sum = [0]
b_sum = [0]
cnt = 0
best_b = m
confirm = ()

for i in a:
    a_sum.append(i + a_sum[-1])

for i in b:
    b_sum.append(i + b_sum[-1])

for a_idx in range(n + 1):
    if a_sum[a_idx] > k:
        break
    for b_idx in reversed(range(best_b + 1)):
        if b_sum[b_idx] + a_sum[a_idx] <= k:
            # if cnt < a_idx + b_idx:
            cnt = max(cnt, a_idx + b_idx)
            best_b = b_idx
            break

print(cnt)
import math
from functools import reduce

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

def gcd(numbers):
    return reduce(math.gcd, numbers)
  
print(gcd(a))

### FIXED CODE ###

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

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

def gcd_list(a):
  for i in range(n - 1):
    a[i + 1] = gcd(a[i], a[i + 1])
  return a[n - 1]
  
print(gcd_list(a))
data = input()
a,b = data.split()
if(a==b):
  print(a+b)
elif(a>b):
  print(2*a-1)
else:
  print(2*b-1)

### FIXED CODE ###

def main(n):
	r = 0
	f = n[0]
	if(f =="0"):
		# zero mode
		for i in range(1, len(n)):
			if(i % 2 == 0): # 偶
				# 1
				if(n[i]=="1"):
					r+=1
			else: # basic
				# 0
				if(n[i]=="0"):
					r+=1
	else:
		# one mode
		for i in range(1, len(n)):
			if(i % 2 == 0): # 偶
				# 1
				if(n[i]=="0"):
					r+=1
			else: # basic
				# 0
				if(n[i]=="1"):
					r+=1
	# sum(result)
	return r

print(main(input()))
#assert(1 == main("000"))
#assert(3 == main("10010010"))
#assert(0 == main("0"))
N=int(input())
A=list(map(int,input().split()))
B,C=[],[]
for i in range(N):
  if A[i]>=0:
    B.append(A[i])
  else:
    C.append(-A[i])
if len(C)%2==0:
  ans=sum(B)+sum(C)
else:
  ans=sum(B)+sum(C)
  B.sort()
  C.sort()
  a=min(B[0],C[0])
  ans-=2*a
print(ans)



### FIXED CODE ###

N=int(input())
A=list(map(int,input().split()))
B,C=[],[]
for i in range(N):
  if A[i]>=0:
    B.append(A[i])
  else:
    C.append(-A[i])
if len(C)%2==0:
  ans=sum(B)+sum(C)
else:
  ans=sum(B)+sum(C)
  B.sort()
  C.sort()
  if len(B)==0:
    b=10**12
  else:
    b=B[0]
  a=min(b,C[0])
  ans-=2*a
print(ans)
import numpy as np
W,H,x,y = map(int,input().split())

min_s = W*H
for i in range(W):
    s = abs(W*H - 2 * (i*H))
    if min_s > s:
        min_s = s
        ts = i*H

min_s2 = W*H
flag = 0 
for d in range(360):
    if(d == 90 or d == 270):
        continue
    rad = np.deg2rad(d)
    a = np.tan(rad)
    h = a*W - 2*a*x + 2*y
    men = (a*x-y+h/2)*W
    s = abs(W*H - 2 * men)
    if min_s2 > s:
        min_s2 = s
        ts2 = men
    elif min_s2 == s:
        flag = 1

flag2 = 0
if ts2 == ts: 
    flag2 = 1
    
if min_s2 > min_s:
    print(ts,flag2)
else:
    print(ts2,flag)

### FIXED CODE ###

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

flag = 0
if(x == W/2 and y == H/2):
    flag = 1
    
print(W*H/2,flag)
import math
from functools import reduce

def gcd_list(numbers):
    return reduce(math.gcd, numbers)

def main():
  if 'get_ipython' not in globals():  
    # For Subsession
    N = int(input())
    A = list(map(int, input().split()))
  else:
    # N = 3
    # A = [7,6,8]
    # N = 3
    # A = [12,15,18]
    N = 2
    A = [1000000000,1000000000]

  x = 0
  for i in range(N):
    tmp = gcd_list(A[0:i]+A[i+1:])
    if tmp > x:
      x = tmp
  
  print(x)
  
main()

### FIXED CODE ###

import functools
import fractions

def main():
  if 'get_ipython' not in globals():  
    # For Subsession
    N = int(input())
    A = list(map(int, input().split()))
  else:
    # N = 3
    # A = [7,6,8]
    N = 3
    A = [12,15,18]
    # N = 3
    # A = [1,1000000000,1000000000]

  AL = [0] * N    
  AR = [0] * N
  for i in range(N):
    if i != 0:
      AL[i] = fractions.gcd(AL[i-1],A[i])
    else:
      AL[i] = A[i]
    j = N - i - 1
    if j!= N - 1:
      AR[j] = fractions.gcd(AR[j+1],A[j])
    else:
      AR[j] = A[j]
      
  if 'get_ipython' in globals():   
    print(AL)
    print(AR)
  
  x = 0
  for i in range(N):
    if i == 0:
      tmp = AR[i+1]
    elif i == N - 1:
      tmp = AL[i-1]
    else:
      tmp = fractions.gcd(AL[i-1],AR[i+1])
    if tmp > x: x = tmp
  
  print(x)
    
main()
l = input().split()
for i in range(3):
  if l[i].count() == 1:
    print(l[i])

### FIXED CODE ###

l = input().split()
for i in range(3):
  if l.count(l[i]) == 1:
    print(l[i])
A, B, C, K = int(input().split())
print(A-B if K % 2 == 0 else B-A)

### FIXED CODE ###

A, B, C, K = map(int,input().split())
print(A-B if K % 2 == 0 else B-A)
from collections import Counter

N = int(input())
L = list(map(int, input().split()))
odd = [v for i, v in enumerate(L) if i % 2 == 0]
even = [v for i, v in enumerate(L) if i % 2 == 1]

if len(set(L)) == 1:
    print(N//2)
    exit()
if N == 2:
    print(0)
    exit()


c_odd = sorted(dict(Counter(odd)).items(), key=lambda x: -x[1])
c_even = sorted(dict(Counter(even)).items(), key=lambda x: -x[1])

odd_1 = c_odd[0]
odd_2 = c_odd[1]
even_1 = c_even[0]
even_2 = c_even[1]

if odd_1[0] != even_1[0]:
    print(N - odd_1[1] - even_1[1])
    exit()

ans = N
ans = min(N, N - odd_1[1] - even_2[1])
ans = min(N, N - odd_2[1] - even_1[1])
print(ans)


### FIXED CODE ###

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

vo = [0]*(10**5+1)
ve = [0]*(10**5+1)

for i in range(n):
    if i % 2 == 0:
        vo[v[i]] += 1
    else:
        ve[v[i]] += 1

if vo.index(max(vo)) == ve.index(max(ve)):
    ans1 = sum(vo) - max(vo) + sum(ve) - sorted(ve)[-2]
    ans2 = sum(vo) - sorted(vo)[-2] + sum(ve) - max(ve)
    print(min(ans1, ans2))
else:
    print(sum(vo) - max(vo) + sum(ve) - max(ve))
x, y, z = input().split()
print(f"{z} {x} {y}")


### FIXED CODE ###

x, y, z = input().split()
print(z, x, y)
*cost_list=map(int,input().split())
cost_list.sort(reverse=True)
sum=0
for i in range(len(cost_list)-1):
  sum+=(cost_list[i]-cost_list[i+1])
print(sum)

### FIXED CODE ###

cost_list=list(map(int,input().split()))
cost_list.sort(reverse=True)
sum=0
for i in range(len(cost_list)-1):
  sum+=(cost_list[i]-cost_list[i+1])
print(sum)
import sys
from collections import defaultdict, Counter, deque
from itertools import accumulate, permutations, combinations
from operator import itemgetter
from bisect import bisect_left, bisect_right, bisect
from heapq import heappop, heappush
from fractions import gcd
from math import ceil, floor, sqrt, cos, sin, pi
import math
from copy import deepcopy

# If you use recursive call, uncomment this code
#sys.setrecursionlimit(10**6)

def comb(n,r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

def main():
    n,k = map(int, input().split())
    redn = n-k
    modn = 10**9+7
    for i in range(1,k+1):
        ans = comb(redn+1,i)*comb(k-1,i-1)%modn
        print(ans)
        

if __name__ == '__main__':
    main()


### FIXED CODE ###

import sys
from collections import defaultdict, Counter, deque
from itertools import accumulate, permutations, combinations
from operator import itemgetter
from bisect import bisect_left, bisect_right, bisect
from heapq import heappop, heappush
from fractions import gcd
from math import ceil, floor, sqrt, cos, sin, pi
import math
from copy import deepcopy

# If you use recursive call, uncomment this code
sys.setrecursionlimit(10**6)

def comb(n,r):
    if n < r:
        return 0
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

def main():
    n,k = map(int, input().split())
    redn = n-k
    modn = 10**9+7
    for i in range(1,k+1):
        ans = comb(redn+1,i)*comb(k-1,i-1)%modn
        print(ans)
        

if __name__ == '__main__':
    main()
n,k=map(int,input().split())
h=list(map(int,input().split()))
dp=[1<<60]*(n)
dp[0]=0
for i in range(1,n):
    for j in range(1,(k+1)):
        if i>=j:
            dp[i]=min(abs(h[i-j]-h[i])+dp[i-j],abs(dp[i]))
        else:
            break
print(dp[-1])

### FIXED CODE ###

n=int(input())
h=list(map(int,input().split()))
dp=[0]*(n)
dp[1]=abs(h[0]-h[1])
for i in range(2,n):
    dp[i]=min(abs(h[i-1]-h[i])+dp[i-1],abs(h[i-2]-h[i])+dp[i-2])
print(dp[-1])
N = int(input())
d = lisat(int(input()) for _ in range(N))
print(len(set(sortd(d))))

### FIXED CODE ###

N = int(input())
d = list(int(input()) for _ in range(N))
print(len(set(sorted(d))))
# Author : prayushd
# Language : Python

import re
import os
import sys
from math import ceil
from fractions import gcd
from queue import Queue
from collections import defaultdict, Counter, deque
from bisect import bisect, insort, bisect_left, bisect_right

mod = int(1e9)+7
input = sys.stdin.readline

'''
Check for special cases (n=1)
One wrong submission = 10 mins penalty!
do smth instead of nothing and stay organized
'''

def main():
	n = int(input())
	arr = list(map(int, input().split()))
	ans = [inf]*n
	for i in range(n-1):
		ans[i] = min(ans[i], arr[i])
		ans[i+1] = min(ans[i+1], arr[i])
	print(sum(ans))


if __name__ == '__main__':
	main()

### FIXED CODE ###

n = int(input())
arr = list(map(int, input().split()))
ans = [999999999]*n
for i in range(n-1):
	ans[i] = min(ans[i], arr[i])
	ans[i+1] = min(ans[i+1], arr[i])
print(sum(ans))
import sys,collections,math,functools;sys.setrecursionlimit(10**7)
def Is(): return [int(x) for x in sys.stdin.readline().split()]
def Ss(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def S(): return input()

n, s = Is()
xs = Is()
xs2 = [e-s for e in xs]
gcd = functools.reduce(math.gcd, xs2)
print(gcd)

### FIXED CODE ###

import sys,collections,math,functools;sys.setrecursionlimit(10**7)
def Is(): return [int(x) for x in sys.stdin.readline().split()]
def Ss(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def S(): return input()

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

n, s = Is()
xs = Is()
xs2 = [abs(e-s) for e in xs]
c = xs2[0]
ans = c
for e in xs2:
    ans = gcd(ans,e)
print(ans)
for i in range(n):
    s.append("".join(sorted(input())))
s.sort()

a = 0
r = 0
i = 1
l = len(s)
while i < l:
    if s[i] == s[i-1]:
        r = r+1
    else:
        a = a + sum(range(r+1))
        r = 0
    i = i+1

if r > 0: a = a + sum(range(r+1))
print(a)

### FIXED CODE ###

n = int(input())

s = []
for i in range(n):
    s.append("".join(sorted(input())))
s.sort()

a = 0
r = 0
i = 1
l = len(s)
while i < l:
    if s[i] == s[i-1]:
        r = r+1
    else:
        a = a + sum(range(r+1))
        r = 0
    i = i+1

if r > 0: a = a + sum(range(r+1))
print(a)
import sys

sys.setrecursionlimit(10 ** 6)
input = sys.stdin.readline


def ps(i, k):
    if k == 1:
        return len(ko[i])
    t = (i, k)
    if t in memo:
        return memo[t]
    re = 0
    for ki in ko[i]:
        re += ps(ki, k - 1)
        re %= md
        memo[t] = re
    return re


md = 10 ** 9 + 7
n, k = map(int, input().split())
ko = [[]]
memo = {}
for _ in range(n):
    s = input()
    st = 0
    kk = []
    while 1:
        i = s.find("1", st)
        if i == -1: break
        kk += [i // 2 + 1]
        st = i + 1
    ko += [kk]

ans = 0
for i in range(1, n + 1):
    ans += ps(i, k)

print(ans)


### FIXED CODE ###

import sys

input = sys.stdin.readline


def dot(a, b):
    c = [[0] * n for _ in range(n)]
    for i, ai in enumerate(a):
        for j, bj in enumerate(zip(*b)):
            c[i][j] = sum(ak * bk for ak, bk in zip(ai, bj)) % md
    return c


def pwr(a, k):
    c = None
    while c == None:
        if k & 1:
            c = a
        a = dot(a, a)
        k >>= 1

    while k > 0:
        if k & 1:
            c = dot(a, c)
        a = dot(a, a)
        k >>= 1
    return c


md = 10 ** 9 + 7
n, k = map(int, input().split())
a = [list(map(int, input().split())) for _ in range(n)]
print(sum([sum(pk) % md for pk in pwr(a, k)]) % md)