Harryxun/stf_run huggingface dataset:
N, K = map(int, input().split())
LR = set()
MOD = 998244353

for i in range(K):
    l, r = map(int, input().split())
    for j in range(l, r + 1):
        LR.add(j)
#print(list(LR))


class Search:
    def __init__(self):
        self.ans = 0

    def dfs(self, now):
        if now == N:
            self.ans += 1
            return
        if now > N:
            return
        for d in LR:
            self.dfs(d + now)


s = Search()
s.dfs(1)
print(s.ans % MOD)

# LR = [list(map(int,input().split())) for i in range(N)]
# dp = [0] * (N + 1)
# dp[0] = 1
# for i in range(1, N):
#     for d in LR:
#         if i - d < 0: break
#         dp[i] += (dp[i - d]) % MOD
# print(dp[N-1] % MOD)


### FIXED CODE ###

N, K = map(int, input().split())
LR = [list(map(int, input().split())) for i in range(K)]
MOD = 998244353

dp = [0] * (N + 1)
dp[1] = 1
dp_sum = [0] * (N + 1)
dp_sum[1] = 1


def get(l, r, i):
    return dp_sum[max((i - l), 0)] - dp_sum[max((i - r-1), 0)]


for i in range(1, N+1):
    for l, r in LR:
        dp[i] += get(l, r, i) % MOD
    dp_sum[i] = (dp_sum[i - 1] + dp[i])%MOD
print(dp[N] % MOD)
a=int(input())
li = list(map(int,input().split()))

result = 1
for num in li:
  result = result * num
  if result > 10 ** 18:
    print(-1)
    
print(result)

### FIXED CODE ###

x,y = map(int,input().split())
print(x * y)
A,B,C,D = map(int,input().split())
print(min(A,B)+ min(C,D))

### FIXED CODE ###

A = int(input())
B = int(input())
C = int(input())
D = int(input())
print(min(A,B)+ min(C,D))
buri


### FIXED CODE ###

a,b=map(int,input().split())
if a % 2 != b % 2:
  print("IMPOSSIBLE")
else:
  print((a + b) // 2)
N, M = map(int,input().split())
a = list(map(int, input().split()))
a.sort()
#print(a)
if N>M:
    ans = 0
else
    distance = [abs(a[i+1] - a[i]) for i in range(M-1)]
    #print(distance)
    distance.sort()
    #print(distance)
    del distance[M-N:]
    ans = 0 
    for j in distance:
        ans += j
print(ans)

### FIXED CODE ###

N, M = map(int,input().split())
a = list(map(int, input().split()))
a.sort()
#print(a)
if N > M:
    ans = 0
else:
    distance = [abs(a[i+1] - a[i]) for i in range(M-1)]
    #print(distance)
    distance.sort()
    #print(distance)
    del distance[M-N:]
    ans = 0 
    for j in distance:
        ans += j
print(ans)
dx, dy = [-1, 0, 1, 0], [0, -1, 0, 1]
while True:
    ans = 0
    try:
        m = ['0'*14] + ['0'+raw_input()+'0' for i in xrange(12)] + ['0'*14]
        f = [[False for i in xrange(14)] for j in xrange(14)]
        for y in xrange(1, 13):
            for x in xrange(1, 13):
                if m[y][x]=='1' and f[y][x]==False:
                    q = [[x, y]]
                    f[y][x] = True
                    while len(q)>0:
                        px, py = q.pop(0)
                        for k in xrange(4):
                            nx = px + dx[k]; ny = py + dy[k];
                            if m[ny][nx]=='1' and f[ny][nx]==False:
                                f[ny][nx] = True
                                q.append([nx, ny])
                    ans += 1
        print ans
    except EOFError:
        break

### FIXED CODE ###

dx, dy = [-1, 0, 1, 0], [0, -1, 0, 1]
while True:
    ans = 0
    try:
        m = ['0'*14] + ['0'+raw_input()+'0' for i in xrange(12)] + ['0'*14]
        f = [[False for i in xrange(14)] for j in xrange(14)]
        for y in xrange(1, 13):
            for x in xrange(1, 13):
                if m[y][x]=='1' and f[y][x]==False:
                    q = [[x, y]]
                    f[y][x] = True
                    while len(q)>0:
                        px, py = q.pop(0)
                        for k in xrange(4):
                            nx = px + dx[k]; ny = py + dy[k];
                            if m[ny][nx]=='1' and f[ny][nx]==False:
                                f[ny][nx] = True
                                q.append([nx, ny])
                    ans += 1
        print ans
        raw_input()
    except EOFError:
        break
A = int(input())  1
if A ==0 :print(A)
else : print(int(A*(A-1)/2))




### FIXED CODE ###

A = int(input())  - 1
if A ==0 :print(A)
else : print(int(A*(A+1)//2))
from collections import deque

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

X = [0 for _ in range(N+1)]
edges = [[] for _ in range(M+1)]

contradiction = False

for i in range(M):
    l, r, d = map(int, input().split())
    edges[l].append((r, d))
    edges[r].append((l, -d))

searched = set()
q = deque()

# assign x coordinate for each vertex
for i in range(N+1):
    if i in searched:
        continue
    q.append(i)
    searched.add(i)
    X[i] = 0
    while len(q) != 0:
        a = q.pop()
        for b, d in edges[a]:
            if b not in searched:
                q.append(b)
                searched.add(b)
                X[b] = X[a] + d
            else:
                if X[b] != X[a] + d:
                    contradiction = True
                    print("No")
                    break
        if contradiction:
            break
    if contradiction:
        break    
else:
    print("Yes")

### FIXED CODE ###

from collections import deque

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

X = [0 for _ in range(N+1)]
edges = [[] for _ in range(N+1)]

contradiction = False

for i in range(M):
    l, r, d = map(int, input().split())
    edges[l].append((r, d))
    edges[r].append((l, -d))

searched = set()
q = deque()

# assign x coordinate for each vertex
for i in range(N+1):
    if i in searched:
        continue
    q.append(i)
    searched.add(i)
    X[i] = 0
    while len(q) != 0:
        a = q.pop()
        for b, d in edges[a]:
            if b not in searched:
                q.append(b)
                searched.add(b)
                X[b] = X[a] + d
            else:
                if X[b] != X[a] + d:
                    contradiction = True
                    print("No")
                    break
        if contradiction:
            break
    if contradiction:
        break    
else:
    print("Yes")
args = int(input().rstrip())

def snuke(number):
    temp = list(str(number))
    arr = [ int(t) for t in temp] 
    return sum(arr)

def find_snuke(args):
    result = []
    i = 1
    while len(result) < args:
        push = True
        for power in range(0,len(str(i))):
            if((i+10**power)/snuke(i+10**power))<(i/snuke(i)):
                push = False
                break
        if push:
            result.append(i)
        i=i+1
            
    return result

arr = find_snuke(args)
for a in arr:
   print(a)

### FIXED CODE ###

import math
def find_min(length, window_size):
    return math.ceil((length-window_size)/(window_size-1)) + 1

args = input().split(" ")
length = int(args[0])
window_size = int(args[1].rstrip())
array = input().split(" ")

print(find_min(length, window_size))
import sys
readline = sys.stdin.readline
INF = 10 ** 10


def main():
    H, N = map(int, readline().rstrip().split())
    dp = [INF] * (H + 1)  # HPを減らすのに必要な最小のMP
    dp[0] = 0

    for _ in range(N):
        hp, mp = map(int, readline().rstrip().split())

        for i in range(hp):
            dp[i] = min(dp[i], mp)

        for i in range(hp, H+1):
            dp[i] = min(dp[i-hp] + mp, dp[i])

    print(dp[-1])


if __name__ == '__main__':
    main()

### FIXED CODE ###

INF = 10 ** 9

def main():
    H, N = map(int, input().split())
    dp = [INF] * (H+1)
    dp[0] = 0
    for _ in range(N):
        a, b = map(int, input().split())
        for j in range(H):
            nj = min(j+a, H)
            dp[nj] = min(dp[nj], dp[j]+b)

    print(dp[H])

    
if __name__ == "__main__":
    main()
N = int(input())
if N == 1:
  print('Yes')
  print('1 1')
  print('1 1)
elif N == 3:
  print('Yes')
  print('2 1 2')
  print('2 3 1')
  print('2 2 3')
else:
  print('No')

### FIXED CODE ###

N = int(input())
Nlist = [k*(k-1)//2 for k in range(10**3)]
if N not in Nlist:
    print('No')
    exit()
print('Yes')
k = Nlist.index(N)
S = [[0]*i for i in range(k)]
S[0] = [i+1 for i in range(k-1)]
for i in range(k-1):
    S[i+1] = [S[j][i] for j in range(i+1)]
    S[i+1] += [S[i][k-2]+j+1 for j in range(k-1-(i-1))]
print(k)
S = [[str(S[i][j]) for j in range(k-1)] for i in range(k)]
for i in range(k):
    print(' '.join([str(k-1)]+S[i]))
def main():
    n, p = map(int, input().split())
    s = input()
    mu = [None]*n
    ans = 0
    c = [0]*p
    ss = map(int, s)
    if 10%p == 0:
        for i in range(n):
            if ss[i]%p == 0:
                ans += i+1
        print(ans)
        return
    num = int(s)
    keta = n-1
    for i, si in enumerate(ss):
        v = num%p
        mu[i] = v
        c[v] += 1
        num -= si*10**keta
        keta -= 1
    c[0] += 1
    for i in mu:
        c[i] -= 1
        ans += c[i]
        
    print(ans)
    

if __name__ == "__main__":
    main()

### FIXED CODE ###

def main():
    n, p = map(int, input().split())
    s = input()
    mu = [None]*n
    ans = 0
    c = [0]*p
    if 10%p == 0:
        ss = map(int, s)
        ss = list(ss)
        for i in range(n):
            if ss[i]%p == 0:
                ans += i+1
        print(ans)
        return
    sr = s[::-1]
    ssr = map(int, sr)
    tens = 1
    v = 0
    for i, si in enumerate(ssr):
        v = (v + (si%p)*tens)%p
        mu[i] = v
        c[v] += 1
        tens *= 10
        tens %= p
    c[0] += 1
    for i in c:
        if i:
            ans += ((i-1)*i)//2
        
    print(ans)
    

if __name__ == "__main__":
    main()
s = input()
print(s[0]+count(s-2)+s[-1])

### FIXED CODE ###

s = input()
print(s[0]+str(len(s)-2)+s[-1])
import queue
n,m = map(int,input().split()) 

conne = [[0]*(n+1) for _ in range(m+1)]
dist = [99999]*(n+1)
par = [0] * (n+1)

for i in range(m):
    a,b = map(int,input().split()) 
    conne[a][b] = 1
    conne[b][a] = 1
    
q=queue.Queue()
dist[1] = 0
q.put((1,0))

while not q.empty():
    
    x,d = q.get()
    
    for i in range(len(conne[x])):
        if conne[x][i]==1 and dist[i]>d+1:
            q.put((i,d+1))
            par[i] = x
            dist[i] = d+1

if max(dist[1:]) == 99999:
    print("No")
    
else:
    print("Yes")    
    
    for i in par[2:]:
        print(i)
    


### FIXED CODE ###

import queue
import sys
imput = sys.stdin.readline

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

conne = [[] for _ in range(n)]
dist = [99999]*(n)
par = [0] * (n)

for i in range(m):
    a,b = map(int,input().split()) 
    conne[a-1].append(b-1)
    conne[b-1].append(a-1)
    
q=queue.Queue()
dist[0] = 0
q.put((0,0))

while not q.empty():
    
    x,d = q.get()
    
    for i in conne[x]:
        if dist[i]==99999:
            q.put((i,d+1))
            par[i] = x
            dist[i] = d+1

print("Yes")    

for i in par[1:]:
    print(i+1)
n = int(input())
min = 10000000000
max = -10000000000

for _ in range(n):
    x, y = map(int,input().split())
    if x+y < min:
        l = [x,y]
        min = x+y
    elif x+y > max:
        r = [x,y]
        max = x+y

print(abs(l[0]-r[0]) + abs(r[1]-l[1]))

### FIXED CODE ###

n = int(input())
min1 = 10000000000
max1 = -10000000000
min2 = 10000000000
max2 = -10000000000

for _ in range(n):
    x, y = map(int,input().split())
    if x+y> max1:
        r1 = [x,y]
        max1 = x+y
    if x+y<min1:
        l1 = [x,y]
        min1 = x+y
    if x-y>max2:
        r2 = [x,y]
        max2 = x-y
    if x-y<min2:
        l2 = [x,y]
        min2 = x-y


#print(abs(l[0]-r[0]) + abs(r[1]-l[1]))
print(max(max1-min1,max2-min2))
X, Y = map(int, input().split())
print("<" if X < Y else ">" if X > Y else "=")

### FIXED CODE ###

X, Y = map(str, input().split())
print("<" if X < Y else ">" if X > Y else "=")
N,u,v = map(int,input().split())
u -= 1
v -= 1

du = [0]*N
dv = [0]*N
du[u] = 0
dv[v] = 0
G = [0]*N

def dfs(v, d, p, dis):
    dis[v] = d
    for u in G[v]:
        if( u == p):
            continue
        else:
            dfs( u, d+1, v, dis )

def calcDist(s, dist):
    dfs(s, 0, -1, dist)

for i in range(N-1):
    e1,e2 = map(int, input().split())
    e1 -= 1
    e2 -= 1
    if G[e1] == 0:
        G[e1] = [e2]
    else:
        G[e1].append(e2)
    if G[e2] == 0:
        G[e2] = [e1]
    else:
        G[e2].append(e1)

if G[u]==[v]:
    ans = 0
else:    

    calcDist(v,dv)
    calcDist(u,du)
    maxD = 0
    for idu,idv in zip(du,dv):
        if idu < idv:
            maxD = max(maxD, idv)       
    ans = maxD-1
    
print(ans)

### FIXED CODE ###

import heapq

N,u,v = map(int,input().split())
u -= 1
v -= 1

#du = [0]*N
#dv = [0]*N
du = [float('inf')]*N
dv = [float('inf')]*N
#du[u] = 0
#dv[v] = 0
q = []

G = [[]]*N

'''
def dfs(v, d, p, dis):
    dis[v] = d
    if G[v] != []:
        for u in G[v]:
            if( u == p):
                continue
            else:
                dfs( u, d+1, v, dis )

def calcDist(s, dist):
    dfs(s, 0, -1, dist)
'''
def calcDist(s, dist):
    heapq.heappush(q,[0, s])
    dist[s] = int(0)
    
    while q!=[]:
        p = heapq.heappop(q)
        pv = p[1]
        if dist[pv] < p[0] :
            continue
        for i in range(len(G[pv])):
            eto = G[pv][i]
            if dist[eto] > dist[pv] + 1:
                 dist[eto] = int(dist[pv] + 1)
                 heapq.heappush(q, [dist[eto], eto])


for i in range(N-1):
    e1,e2 = map(int, input().split())
    e1 -= 1
    e2 -= 1
    if G[e1] == []:
        G[e1] = [e2]
    else:
        G[e1].append(e2)
    if G[e2] == []:
        G[e2] = [e1]
    else:
        G[e2].append(e1)

if v in G[u]:
    ans = 0
else:    

    calcDist(v,dv)
    calcDist(u,du)
    maxD = 0
    for idu,idv in zip(du,dv):
        if idu < idv:
            maxD = max(maxD, idv)       
    ans = maxD-1
    
print(ans)
w, h, x, y = map(int, input().split())
print(w*h/2, int(h/w==y/x))

### FIXED CODE ###

w, h, x, y = map(int, input().split())
print(w*h/2, int(h==2*y and w==2*x))
r = input()
g = input()
print(2*g-r)


### FIXED CODE ###

r = int(input())
g = int(input())
print(2*g-r)
a1=input()
a2=[i for i in a1.split()]
x,y=float(a2[0]),float(a2[1])
v,v1=x.is_integer(),y.is_integer()
if 1<=(x and y)<=20 and v1==v2==True:
    if 1<=(x and y)<=9:
        print(int(x*y))
    else:
        print('-1')

### FIXED CODE ###

a1=input()
a2=[i for i in a1.split()]
x,y=float(a2[0]),float(a2[1])
v,v1=x.is_integer(),y.is_integer()
if 1<=x<=20 and 1<=y<=20 and v==v1==True:
    if 1<=x<=9 and 1<=y<=9:
        print(int(x*y))
    else:
        print('-1')
n,m  = map(int, input().split())
A = set(int(input()) for _ in range(m))
mod = 10**9+7

dp_l = [-1]*(n+1)

def dp(n):
  if n in A:
    return(0)
  
  if n==0:
    return(1)
  elif n==1:
    return(1)
  
  if dp_l[n] == -1:
    dp_l[n] = (dp(n-1)+dp(n-2))%mod
    return(dp_l[n])
  else:
    return(dp_l[n])
    
print(dp(n))

### FIXED CODE ###

n,m  = map(int, input().split())
A = set(int(input()) for _ in range(m))
mod = 10**9+7

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

if n==1:
  print(1)
else:
  for i in range(1, len(dp_l)):
    if i in A:
      dp_l[i] = 0
    else:
      dp_l[i] = (dp_l[i-1]+dp_l[i-2])%mod 
  print(dp_l.pop())
N,M = (int(i) for i in input().split())
a = input()
s = a.split()
A = []
for i in range(N):
    A.append(int(s[i]))

count = 0
total = 0

for r in range(N):
    for j in range(int(r+1)):
        l = j
        total = 0
        while l <= r:
            total += A[l]
            if l == r:
                if total % M == 0:
                    count += 1
                    break
                else:
                    break
            else:
                l += 1
print(count)

### FIXED CODE ###

N,K = (int(i) for i in input().split())

if N % K == 0:
    print(0)
else:
    print(1)
n,a,b=map(int,input().split())
c=[i+1 for i in range(n)]
e=0
for i in range(n):
    d[i]=c[i]%10+(c[i]//10)%10+(c[i]//100)%10+(c[i]//1000)%10+(c[i]//10000)%10
    if d[i]>=a and d[i]<=b:
        e+=c[i]
        print(c[i],e)
print(e)
    


### FIXED CODE ###

n,a,b=map(int,input().split())
c=[i+1 for i in range(n)]
d=[i+1 for i in range(n)]
e=0
for i in range(n):
    d[i]=c[i]%10+(c[i]//10)%10+(c[i]//100)%10+(c[i]//1000)%10+(c[i]//10000)%10
    if d[i]>=a and d[i]<=b:
        e+=c[i]
print(e)
out=[]
while True:
	try:
		k=list(map(int,input().split(" ")))
	        out.append(k[0]+k[1])
	except:
		break

for i in out:
	print(i)

### FIXED CODE ###

out=[]
while True:
	try:
		k=list(map(int,input().split(" ")))
	except:
		break

	out.append(k[0]+k[1])

for i in out:
	print(i)
n, d = map(int, input().split())
x = list(map(int, input().split()))
y = list(map(int, input().split()))

count = 0

for i, j in zip(x, y):
    if i*i + j*j <= d*d:
        count += 1

print(count)

### FIXED CODE ###

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

xy = [map(int, input().split()) for _ in range(n)]
x, y = [list(i) for i in zip(*xy)]

count = 0

for i, j in zip(x, y):
    if i*i + j*j <= d*d:
        count += 1

print(count)
import sys

# import re
import math
import collections
# import decimal
# import bisect
# import itertools
# import fractions
# import functools
import copy
# import heapq
import decimal
# import statistics
import queue

sys.setrecursionlimit(10000001)
INF = 10 ** 16
MOD = 10 ** 9 + 7

ni = lambda: int(sys.stdin.readline())
ns = lambda: map(int, sys.stdin.readline().split())
na = lambda: list(map(int, sys.stdin.readline().split()))


# ===CODE===


def main():
    def make_divisors(n):
        divisors = []
        for i in range(1, int(n ** 0.5) + 1):
            if n % i == 0:
                divisors.append(i)
                if i != n // i:
                    divisors.append(n // i)

        # divisors.sort()
        return divisors

    a, b = ns()
    a_gcd = make_divisors(a)
    b_gcd = make_divisors(b)

    ans=0
    for a in a_gcd:
        for b in b_gcd:
            if math.gcd(a,b)==1:
                ans+=1
    
    print(ans)


if __name__ == '__main__':
    main()


### FIXED CODE ###

import sys

# import re
import math
import collections
# import decimal
# import bisect
# import itertools
import fractions
# import functools
import copy
# import heapq
import decimal
# import statistics
import queue

sys.setrecursionlimit(10000001)
INF = 10 ** 16
MOD = 10 ** 9 + 7

ni = lambda: int(sys.stdin.readline())
ns = lambda: map(int, sys.stdin.readline().split())
na = lambda: list(map(int, sys.stdin.readline().split()))


# ===CODE===


def main():
    a, b = ns()

    g = fractions.gcd(a, b)

    def search(n):
        i = 2
        so = []
        while not(n == 1 or i * i > n):
            while n % i == 0:
                n //= i
                so.append(i)
            i += 1
        if n != 1:
            so.append(n)

        return so

    ans = set(search(g))
    print(len(ans) + 1)


if __name__ == '__main__':
    main()
N=int(input())
A=list(map(int,input().split()))
X=1
for idx in range(N):
  X=X*A[idx]

if X >10**18:
  print(-1)
  break
else:
  print(X)


### FIXED CODE ###

N=int(input())
A=list(map(int,input().split()))
X=1
if 0 in A:
    print(0)
else:
    for idx in range(N):
        X=X*A[idx]
        if X >10**18:
            print(-1)
            break
    else:
        print(X)
n = int(input())
ws = list(map(int,input().split()))
others = [0]
diff = 999999999999
for i in range(n):
  d= abs(sum(ws)-sum(other))
  if d < diff:
    diff = d
  others.add(ws.pop(0))
print(diff)

### FIXED CODE ###

n = int(input())
ws = list(map(int,input().split()))
others = [0]
diff = 999999999999
for i in range(n):
  d= abs(sum(ws)-sum(others))
  if d < diff:
    diff = d
  others.append(ws.pop(0))
print(diff)
import sys
input = sys.stdin.readline
from collections import Counter
from functools import reduce
from operator import mul
M = 998244353
N = int(input())
D = list(map(int, input().split()))
counter = set(D)
if D[0] == 0:
    D[0] = 1
    ans = reduce(mul, D)
    for i, k in enumerate(sorted(counter)):
        if i == k:
            continue
        ans = 0
    print(ans % M)
else:
    print(0)


### FIXED CODE ###

N = int(input())
ans = 0
for i in range(1, N):
    if N - i != i:
        ans += 1
print(ans//2)
from functools import reduce
from math import gcd


N = int(input())
A = [int(a) for a in input().split()]
def lcm(a,b):
    return (a*b//gcd(a, b))
def lcmm(l):
    return reduce(lcm, l)

m = lcmm(A) - 1
print(sum([m%a for a in A]))

### FIXED CODE ###

from functools import reduce
from fractions import gcd

N = int(input())
A = [int(a) for a in input().split()]
def lcm(a,b):
    return (a*b//gcd(a, b))
def lcmm(l):
    return reduce(lcm, l)

m = lcmm(A) - 1
print(sum([m%a for a in A]))
def fio(x,y):
    return x+y

n_a,m = map(int,input().split())
a = []
for i in range(m):
    a.append(int(input()))

n = [0,1,2]

for i in range(1,100000):
    n.append(fio(n[i],n[i+1]))

last_break = 0
ans = 1
ans = ans * n[a[0]-last_break-1]
ans = ans % 1000000007
last_break = a[0]

if a[0] == 1:
    ans = 1
    
for i in range(1,m):
    ans = ans * n[max(0,a[i]-last_break-2)]
    ans = ans % 1000000007
    last_break = a[i]
    
ans = ans * n[n_a-last_break-1]
ans = ans % 1000000007
print(ans)

### FIXED CODE ###

n,m = map(int,input().split())
a = []
mod = 10**9+7
for i in range(m):
    temp = int(input())
    a.append(temp)

a.append(0)
dp = [0]*(n+1)
dp[0] = 1
if a[0] == 1:
    dp[1] = 0
    l = 1
else:
    dp[1] = dp[0]
    l = 0
    
for i in range(2,n+1):
    if a[l] != i:
        dp[i] = dp[i-1] + dp[i-2]
        dp[i]%=mod 
    else:
        l += 1

print(dp[-1])
s = input()
N = len(s)

def solve2():
    l = 0
    r = N - 1
    cost = 0
    while l < r:
        if s[l] == s[r]:
            l += 1
            r += 1
        elif s[l] == 'x':
            cost += 1
            l += 1
        elif s[r] == 'x':
            cost += 1
            r -= 1
        else:
            return -1
    return cost

print(solve2())


### FIXED CODE ###

s = input()
N = len(s)
s_trim = ''.join([c for c in s if c != 'x'])
N_trim = len(s_trim)

def check_anagram():
    for i in range(N_trim):
        j = N_trim - 1 - i
        if s_trim[i] != s_trim[j]:
            return False
    return True

def solve():
    if not check_anagram():
        return -1
    if N_trim == 0:
        return 0
    # Center of anagram
    pr = N_trim // 2
    pl = pr
    if N_trim % 2 == 0:
        pl -= 1

    xl = 0
    tl = 0
    while xl < N:
        if s[xl] != 'x':
            # assert s[xl] == s_trim[tl]
            if tl == pl:
                break
            tl += 1
        xl += 1

    if N_trim % 2 == 1:
        xr = xl
    else:
        xr = xl + 1
        while s[xr] == 'x':
            xr += 1

    cost = 0
    while True:
        # assert s[xl] == s_trim[pl]
        # assert s[xr] == s_trim[pr]
        # assert s[xl] == s[xr]
        # assert s_trim[pl] == s_trim[pr]
        pl -= 1; pr += 1
        while True:
            xl -= 1; xr += 1
            if not (xl >= 0 and xr < N and s[xl] == 'x' and s[xr] == 'x'):
                break
        while xl >= 0 and s[xl] == 'x':
            cost += 1
            xl -= 1
        while xr < N and s[xr] == 'x':
            cost += 1
            xr += 1
        if pl < 0 and pr >= N_trim and xl < 0 and xr >= N:
            return cost

print(solve())
n = int(input())
h = list(map(int,input().split()))
b = []
inf = 10**10
start = 0
end = 0
ans = 0

for ii in range(inf):
    while h[0] == 0:
        del h[0]

    for i in range(len(h)):
        if h[i] == 0:
            end = i
            #print(b)
            break
        end = len(h)
        b.append(h[i])

    #print(b)
    sa = min(b)
    b.clear()
    #print(sa)

    for j in range(end):
        h[j] = h[j] - sa
        #print(h)

    ans = ans + sa
        
    if max(h) == 0:
        break

print(ans)


### FIXED CODE ###

n = int(input())
h = list(map(int,input().split()))
b = []
inf = 10**10
start = 0
end = 0
ans = 0

for ii in range(inf):
    if max(h) == 0:
        break

    while h[0] == 0:
        del h[0]

    for i in range(len(h)):
        if h[i] == 0:
            end = i
            #print(b)
            break
        end = len(h)
        b.append(h[i])

    #print(b)
    sa = min(b)
    b.clear()
    #print(sa)

    for j in range(end):
        h[j] = h[j] - sa
        #print(h)

    ans = ans + sa
        

print(ans)