Harryxun/stf_run huggingface dataset:
S = input()

N = len(S) + 1
L = []
counter = 0

for n in range(N-2):
    counter += 1
    if S[n]!=S[n+1]:
        L.append(counter)
        counter = 0
        if S[n]=='>' and L[-1]>=L[-2]:
            L[-2] -= 1
        elif S[n]=='>' and L[-1]<L[-2]:
            L[-1] -= 1
            
if S[N-2]=='<':
    L.append(counter+1)
else:
    L.append(counter)
L.append(counter)
        
print(sum([l*(l+1)//2 for l in L]))

### FIXED CODE ###

S = input()

N = len(S) + 1
L = []
counter = 0

for n in range(N-2):
    counter += 1
    if S[n]!=S[n+1]:
        L.append(counter)
        counter = 0
            
L.append(counter+1)

if S[0]=='<':
    K = len(L)//2
    for k in range(K):
        if L[2*k] <= L[2*k+1]:
            L[2*k] -= 1
        else:
            L[2*k+1] -= 1

else:
    K = (len(L)-1)//2
    for k in range(K):
        if L[2*k+1] <= L[2*k+2]:
            L[2*k+1] -= 1
        else:
            L[2*k+2] -= 1
        
print(sum([l*(l+1)//2 for l in L]))
n=list(input()).reversed()

if (n[0]=="2" or n[0]=="4" or n[0]=="5" or n[0]=="7" or n[0]=="9"):
    print("hon")
elif (n[0]=="0" or n[0]=="1" or n[0]=="6" or n[0]=="8"):
    print("pon")
elif (n[0]=="3"):
    print("bon")


### FIXED CODE ###

n=list(input())

n==n.reverse()

if (n[0]=="2" or n[0]=="4" or n[0]=="5" or n[0]=="7" or n[0]=="9"):
    print("hon")
elif (n[0]=="0" or n[0]=="1" or n[0]=="6" or n[0]=="8"):
    print("pon")
elif (n[0]=="3"):
    print("bon")
N = int(input())
A = int(input())
print("No" if ((N % 500)>=N else "Yes")

### FIXED CODE ###

p = int(input())
one = int(input())
if (p%500)<=one:
  print("Yes")
else:
  print("No")
a, b = map(int, input().split())
l = a * b
l * i
e = l * i
for i in range(1,3):
  if e % 2 == 0:
    print("NO")
else:
  print("YES")


### FIXED CODE ###

a, b = map(int, input().split())
l = a * b
if l % 2 == 0:
    print("No")
else:
    print("Yes")
import scipy.misc as scm

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

a = sorted(a, reverse=True)

comb = -1
for i in range(n-1):
    if a[i] % 2 == 0:
        max_r = int(a[i]/2)
        if max_r in a:
            c = scm.comb(a[i], max_r)
            if c < comb:
                break
            else:
                a_i = a[i]
                a_j = max_r
                comb = c
        else:
            r_list = a[i+1:]
            tmp_c = -1
            for r in r_list:
                c = scm.comb(a[i], r)
                if tmp_c < c:
                    tmp_c = c
                    tmp_r = r
                else:
                    break
            if c > comb:
                a_i = a[i]
                a_j = tmp_r
                comb = c
            else:
                break
    else:
        max_r1 = int(a[i]/2)
        max_r2 = int(a[i]/2)+1
        if max_r1 in a:
            c = scm.comb(a[i], max_r1)
            if c < comb:
                break
            else:
                a_i = a[i]
                a_j = max_r1
        elif max_r2 in a:
            c = scm.comb(a[i], max_r2)
            if c < comb:
                break
            else:
                a_i = a[i]
                a_j = max_r2
                comb = tmp_c
        else:
            r_list = a[i+1:]
            tmp_c = -1
            for r in r_list:
                c = scm.comb(a[i], r)
                if tmp_c < c:
                    tmp_c = c
                    tmp_r = r
                else:
                    break
            if c > comb:
                a_i = a[i]
                a_j = tmp_r
                comb = tmp_c
            else:
                break
print(a_i, a_j)


### FIXED CODE ###

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

a = sorted(a, reverse=True)

comb = -1
a_i = a[0]
if a_i % 2 == 0:
    mid = int(a_i/2)
    dif = 10**9
    for i in range(1, n):
        if dif > abs(a[i]-mid):
            dif = abs(a[i]-mid)
            a_j = a[i]
else:
    mid = int(a_i/2)
    dif = 10**9
    for i in range(1, n):
        if a[i] > mid:
            if dif > abs(a[i]-mid-1):
                dif = abs(a[i]-mid-1)
                a_j = a[i]
        else:
            if dif > abs(a[i]-mid):
                dif = abs(a[i]-mid)
                a_j = a[i]

print(a_i, a_j)
O = str(input())
E = str(input())
P = ''
for i in range(len(O)+len(E)) :
    P = P + O[i]
    P = P + E[i]
print(P)
    

### FIXED CODE ###

O = str(input())
E = str(input())
P = ''
for i in range(len(E)) :
    P = P + O[i]
    P = P + E[i]
if len(O) == len(E) :
    print(P)
else :
    print(P + O[-1])
from collections import Counter
N, P = map(int, input().split())
S=list(map(int,input()))
P=2019
N=len(S)
if P not in [2,5]:
  pt = [1]
  for i in range(N):
    pt.append(pt[-1]*10%P)
  dp = [(S[0]*pt[N-1])%P]
  for i in range(1,N):
    dp.append((dp[-1]+S[i]*pt[N-1-i])%P)

  c = Counter(dp)
  ans = sum(u*(u-1)//2 for u in c.values())
  print(ans+c[0])
elif P==2:
  S = [int(c) for c in input()]
  ans = 0
  for i in range(N):
    if S[i]%2==0:
      ans += i+1
  print(ans)
else:
  ans = 0
  S = [int(c) for c in input()]
  for i in range(N):
    if S[i]%5==0:
      ans += i+1
  print(ans)


### FIXED CODE ###

from collections import Counter
S=list(map(int,input()))
P=2019
N=len(S)
if P not in [2,5]:
  pt = [1]
  for i in range(N):
    pt.append(pt[-1]*10%P)
  dp = [(S[0]*pt[N-1])%P]
  for i in range(1,N):
    dp.append((dp[-1]+S[i]*pt[N-1-i])%P)

  c = Counter(dp)
  ans = sum(u*(u-1)//2 for u in c.values())
  print(ans+c[0])
elif P==2:
  S = [int(c) for c in input()]
  ans = 0
  for i in range(N):
    if S[i]%2==0:
      ans += i+1
  print(ans)
else:
  ans = 0
  S = [int(c) for c in input()]
  for i in range(N):
    if S[i]%5==0:
      ans += i+1
  print(ans)
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")


n = int(input())
a = input()
d = {}
def sub(val):
    if val in d:
        return d[val]
    pc = 0
    for i in range(val.bit_length()):
        if val>>i&1:
            pc += 1
    if pc==0:
        ans = 0
    else:
        tmp = val % pc
        if tmp==0:
            ans = 1
        else:
            ans = sub(tmp) + 1
    d[val] = ans
    return ans
pc = sum(item=="1" for item in a)
val0 = 0 # pc-1
val1 = 0 # pc+1
for i in range(n):
    if a[i]=="1":
        val0 += pow(2,n-1-i,pc-1)
        val1 += pow(2,n-1-i,pc+1)
        
ans = [None]*n
# print(a)
for i in range(n):
    if a[i]=="1":
        val = (val0 - pow(2,n-1-i,pc-1))%(pc-1) #(1<<(n-1-i))
        ans[i] = sub(val) + 1
#         print(1, bin(val)[2:], pc-1)
    else:
        val = (val1 + pow(2,n-1-i,pc+1))%(pc+1) #(1<<(n-1-i))
        ans[i] = sub(val) + 1
#         print(0, bin(val)[2:], pc+1)
write("\n".join(map(str, ans)))

### FIXED CODE ###

import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")


n = int(input())
a = input()
d = {}
def sub(val):
    if val in d:
        return d[val]
    pc = 0
    for i in range(val.bit_length()):
        if val>>i&1:
            pc += 1
    if pc==0:
        ans = 0
    else:
        tmp = val % pc
        if tmp==0:
            ans = 1
        else:
            ans = sub(tmp) + 1
    d[val] = ans
    return ans

pc = sum(item=="1" for item in a)
val0 = 0 # pc-1
val1 = 0 # pc+1
for i in range(n):
    if a[i]=="1":
        if pc>1:
            val0 += pow(2,n-1-i,pc-1)
        val1 += pow(2,n-1-i,pc+1)
        
ans = [None]*n
# print(a)
for i in range(n):
    if a[i]=="1":
        if pc==1:
            val = 0
            ans[i] = 0
        else:
            val = (val0 - pow(2,n-1-i,pc-1))%(pc-1) #(1<<(n-1-i))
            ans[i] = sub(val) + 1
#         print(1, bin(val)[2:], pc-1)
    else:
        val = (val1 + pow(2,n-1-i,pc+1))%(pc+1) #(1<<(n-1-i))
        ans[i] = sub(val) + 1
#         print(0, bin(val)[2:], pc+1)
write("\n".join(map(str, ans)))
string = input()
one = 0
zero = 0
for s in string:
    if s == '1':
        ones += 1
    else:
        zeros += 1

print(2*min(one, zero))


### FIXED CODE ###

import math

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

required = a * c
limit = b

if required <= limit:
    print(c)
else:
    print(math.floor(b / a))
money = input()
happy = money//500+(money-money//500)//5
print(happy)

### FIXED CODE ###

money = int(input())
happy1 = money//500
happy2 = (money-happy1*500)//5
print(happy1*1000+happy2*5)
H, N = map(int, input().split())
A = list(map(int, input().split()))
MAX = sum(A)

if MAX < H:
  print("No)
else:
  print("Yes")

### FIXED CODE ###

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

if MAX < H:
  print("No")
else:
  print("Yes")
from math import ceil
a,b=map(int,input().split())
if a==1 or b==1:
  print(1)
else:
  print(ceil(n/2)*ceil(m/2)+n//2*m//2)

### FIXED CODE ###

from math import floor,ceil
h,w=map(int,input().split())
if h == 1 or w == 1:
    print(1)
else:
    m =ceil(w/2) * ceil(h/2) + floor(w/2) * floor(h/2)
    print(m)
if int(input()) >=30:
  print("Yes")
if else:
  print("No")

### FIXED CODE ###

if int(input()) >=30:
  print("Yes")
else:
  print("No")
A,B,C=list(map(int,input().split())
if A+B+C<22:
    print("win")
else:
    print("bust")

### FIXED CODE ###

A,B,C=list(map(int,input().split()))
if A+B+C<22:
    print("win")
else:
    print("bust")
#!/usr/bin/python3
# -*- coding:utf-8 -*-

from math import gcd
from functools import reduce

def main():
  n, k = map(int, input().split())
  la = list(map(int, input().split()))
  if max(la) > k and (max(la) - k) % (reduce(gcd, la)) == 0:
    print('POSSIBLE')
  else:
    print('IMPOSSIBLE')
  
if __name__=='__main__':
  main()



### FIXED CODE ###

#!/usr/bin/python3
# -*- coding:utf-8 -*-

from functools import reduce

def calc_gcd(a, b):
  if a > b:
    a, b = b, a
  while b % a:
    a, b = b % a, a
  return a

def main():
  n, k = map(int, input().split())
  la = list(map(int, input().split()))
  if max(la) >= k and k % (reduce(calc_gcd, la)) == 0:
    print('POSSIBLE')
  else:
    print('IMPOSSIBLE')
  
if __name__=='__main__':
  main()
mport sys
input = sys.stdin.readline

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

x = a
a = c
c = x

print(a, b, c)

### FIXED CODE ###

import sys
input = sys.stdin.readline

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

x = a
a = c
c = x

print(a, b, c)
s= str(input())
k= int(input())


a=len(s)

if k >= a:
  print(s)

else :
  print(s[:k]+"...")

### FIXED CODE ###


k= int(input())
s= input()

a=len(s)

if k >= a:
  print(s)

else :
  print(s[:k]+"...")
n,k=map(int,input().split())
a=list(map(int,input().split()))
ans=float("inf")
for i in range(2**n):
    bit=[(i>>j)&1 for j in range(n)]
    if sum(bit)==k and bit[0]:
        cost,kijun=0,a[0]
        for j in range(n):
            if not bit[j]:
                kijun=max(kijun,a[j+1])
                continue
            if a[j+1]>=kijun+1:
                kijun=a[j+1]
                continue
            cost+=kijun+1-a[j+1]
            kijun+=1
        ans=min(ans,cost)
print(ans)

### FIXED CODE ###

def LI(): return list(map(int,input().split()))
N,K = LI()
a = LI()
ans = float('INF')
for i in range(2**(N-1)):
    bit = [i>>j&1 for j in range(N-1)]
    if K-1!=sum(bit):
        continue
    cost,kijun = 0,a[0]
    for k in range(N-1):
        if bit[k]==0:
            kijun = max(kijun,a[k+1])
            continue
        if a[k+1]>=kijun+1:
            kijun = a[k+1]
            continue
        cost += (kijun+1)-a[k+1]
        kijun += 1
    ans = min(ans,cost)
print(ans)
n = input()
l = list(map(int ,input().split(" ")))
 
count = 0
 
while True:
	for i in range(n):
		if l[i]%2 == 0:
			l[i] = l[i]//2
		else:
			print(count)
			exit()
	count += 1

### FIXED CODE ###

print(input().count("1"))
import numpy as np
N = int(input())
K = int(input())

e = [0]*N

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

for i in range(N):
    for j in range(N):      
        if e[i] < e[j]:
            tmp = e[i]
            e[i] = e[j]
            e[j] = tmp

f = [0]*(N - K + 1)
for i in range(N-K+1):
    f[i] = e[K + i - 1] - e[i]

print(np.min(np.array(f)))

### FIXED CODE ###

import numpy as np
N,K=input().split()
N = int(N)
K = int(K)
e = [0]*N

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

#for i in range(N):
#    for j in range(N):      
#        if e[i] < e[j]:
#            tmp = e[i]
#            e[i] = e[j]
#            e[j] = tmp

e = list(sorted(e))

f = [0]*(N - K + 1)
for i in range(N-K+1):
    f[i] = e[K + i - 1] - e[i]

print(np.min(np.array(f)))
h, w = map(int, input().split())
if h == 1 or w == 1:
    print(a)
else:
    print(int(((h*w)+1) / 2))

### FIXED CODE ###

h, w = map(int, input().split())
if h == 1 or w == 1:
    print(1)
else:
    print(int(((h*w)+1) / 2))
# -*- coding: utf-8 -*-
import sys
from collections import deque
from collections import defaultdict
import heapq
import collections
import itertools
import bisect
import copy
import math
sys.setrecursionlimit(10**6)

# lis_of_lis = [[] for _ in range(N)]


def zz(): return list(map(int, sys.stdin.readline().split()))


def z(): return int(sys.stdin.readline())


def S(): return sys.stdin.readline()[:-1]


def C(line): return [sys.stdin.readline() for _ in range(line)]


def get_sieve_of_eratosthenes(n):
    if not isinstance(n, int):
        raise TypeError('n is int type.')
    if n < 2:
        raise ValueError('n is more than 2')
    prime = [2]
    limit = int(n**0.5)
    data = [i + 1 for i in range(2, n, 2)]
    while True:
        p = data[0]
        if limit <= p:
            return prime + data
        prime.append(p)
        data = [e for e in data if e % p != 0]


max_ = pow(10, 5)
primes = get_sieve_of_eratosthenes(max_)
num_lile2017 = [0]*max_
primes2 = []
for prime in primes:
    primes2.append(2*prime-1)
like2017 = sorted(list(set(primes2) & set(primes)))
idx = 0
for i in range(max_):
    if (like2017[idx] < i and i < like2017[-1]):
        idx += 1
    num_lile2017[i] += idx

Q = z()
for i in range(Q):
    l, r = zz()
    print(num_lile2017[r+1] - num_lile2017[l])


### FIXED CODE ###

# -*- coding: utf-8 -*-
import sys
from collections import deque
from collections import defaultdict
from itertools import accumulate

import heapq
import collections
import itertools
import bisect
import copy
import math
sys.setrecursionlimit(10**6)

# lis_of_lis = [[] for _ in range(N)]


def zz(): return list(map(int, sys.stdin.readline().split()))


def z(): return int(sys.stdin.readline())


def S(): return sys.stdin.readline()[:-1]


def C(line): return [sys.stdin.readline() for _ in range(line)]


def get_sieve_of_eratosthenes(n):
    if not isinstance(n, int):
        raise TypeError('n is int type.')
    if n < 2:
        raise ValueError('n is more than 2')
    prime = [2]
    limit = int(n**0.5)
    data = [i + 1 for i in range(2, n, 2)]
    while True:
        p = data[0]
        if limit <= p:
            return prime + data
        prime.append(p)
        data = [e for e in data if e % p != 0]


max_ = pow(10, 5) + 2
primes = get_sieve_of_eratosthenes(max_)
num_lile2017 = [0]*max_
primes2 = []
for prime in primes:
    primes2.append(2*prime-1)
like2017 = sorted(list(set(primes2) & set(primes)))
for i in range(3, max_, 2):
    if (i in like2017):
        num_lile2017[i] = 1
num_lile2017 = list(accumulate(num_lile2017))
# print(num_lile2017)

Q = z()
for i in range(Q):
    l, r = zz()
    print(num_lile2017[r] - num_lile2017[l-1])
N = int(input())
a = list(map(int, input().split()))
point = 0
while True:
	A =[x % 2 for x in a]
	if A.count(0) != N:
		break
	 = [x // 2 for x in a]
	point += 1
print(point)

### FIXED CODE ###

s = input()
print(s.count('1'))
n = input()

a = map(int, raw_input().split())

a.sort()
a.reverse()
f = 1
tmp = [0]
ct = 0

key = a.pop(0)
while len(a) != 0:
    nxt = a.pop(0)
    if key == nxt:
        tmp.append(key)
	ct += 1
        if ct == 2:
            print tmp[1] * tmp[2]
            break
    key = a.pop(0)

if len(tmp) < 2:
    print 0
    

### FIXED CODE ###

n = int(input())
tmp = raw_input()

As = [int(a) for a in tmp.split()]

dic = {}
maxes = [0, 0]
for a in As:
    if a not in dic:
        dic[a] = 0
    dic[a] += 1
    if dic[a] % 2 == 0:
        if maxes[0] < a:
            maxes[0], maxes[1] = a, maxes[0]
        elif maxes[1] < a:
                maxes[1] = a

print (maxes[0] * maxes[1])
#!/usr/bin/env python3
import sys
import math

def solve(A: int, B: int):
    print( (A*B) // math.gcd(A, B))
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    A = int(next(tokens))  # type: int
    B = int(next(tokens))  # type: int
    solve(A, B)

if __name__ == '__main__':
    main()


### FIXED CODE ###

#!/usr/bin/env python3
import sys

def gcd(A,B):
    while B:
        A, B = B, A % B

    return A

def solve(A: int, B: int):
    print( (A*B) // gcd(A, B))
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    A = int(next(tokens))  # type: int
    B = int(next(tokens))  # type: int
    solve(A, B)

if __name__ == '__main__':
    main()
x, n = map(int, input().split())
p = list(map(int, input().split()))
np = [x for x in range(102) if x not in p]
mnd = 103
mnv = 103
for i in np:
	if abs(i - x) < mn:
		mnv = i
		mnd = abs(i - x)
print(mnv)


### FIXED CODE ###

x,n = map(int, input().split())
p = list(map(int, input().split()))
for i in range(101):
  if (x - i) not in p:
    print(x - i)
    break
  elif (x + i) not in p:
    print(x + i)
    break
S = input()
K = int(input())

if S[0] != '1':
    print(S[0])
else:
    print(S[1])

### FIXED CODE ###

S = input()
K = int(input())
 

ans = 0
if len(S) == 1:
    ans = S[0]
else:
    i = 0
    for i in range(len(S)):
        if S[i] != '1' and i < K:
            ans = S[i]
            break
        else:
            ans = S[0]
   
print(ans)
N,M = map(int, input().split())
listA = list(map(int, input().split()))
listA.sort()
 
listBC = [list(map(int, input().split())) for i in range(M)]
listBC = sorted(bc, key=lambda x: x[1], reverse=True)
countB = 0
 
for i in range(M):
  B, C = listBC[i][0], listBC[i][1]
  listA += [C]*B
  countB += B
  if countB >= N:
    break

listA.sort(reverse=True)
print(sum(l[:N]))

### FIXED CODE ###

N,M = map(int, input().split())
listA = list(map(int, input().split()))
listA.sort()
 
listBC = [list(map(int, input().split())) for i in range(M)]
listBC = sorted(listBC, key=lambda x: x[1], reverse=True)
countB = 0
 
for i in range(M):
  B, C = listBC[i][0], listBC[i][1]
  listA += [C]*B
  countB += B
  if countB >= N:
    break

listA.sort(reverse=True)
print(sum(listA[:N]))
import random
S=input()
r = random.randint(0,len(S)-4)
result =""
result = S[r]+S[r+1]+S[r+2]
print(result)

### FIXED CODE ###

import random
S=input()
r = random.randint(0,len(S)-3)
result =""
result = S[r]+S[r+1]+S[r+2]
print(result)
import sys
 
if __name__ == '__main__':
  args = sys.argv
  ret="No"
  
  if (args[1] == args[2] | args[2] == args[3] | args[1] == args[3]):
    ret="Yes"
    
  print(ret)

### FIXED CODE ###

import sys
 
if __name__ == '__main__':
  args = input().split()
  ret="No"
  if ((args[0] == args[1] or args[0] == args[2] or args[1] == args[2]) and (args[0] != args[1] or args[1] != args[2])):
    ret="Yes"
    
  print(ret)
s = map(int, list(raw_input()))
sum = 0
for i in xrange(0, int(1 << len(s)-1)):
    temp_num = 0
    for j in xrange(0, len(s)):
        cur_num = s[j]
        if i % 2 == 1:
            temp_num += cur_num
            if j != len(s) - 1:
                sum += temp_num
                temp_num = 0
        else:
            temp_num += cur_num
        i /= 2
        if j == len(s) - 1:
            sum += temp_num
            temp_num = 0
        temp_num *= 10
print sum

# renketsu wo riyou sita kaihou ga kirei datta node
def sum(total, s):
    r = 0
    for i in range(len(s)):
        if i == 0:
            r = total + int(s)
        else:
            r += sum(total + int(s[:i]), s[i:])
    return r


s = raw_input()
total = 0

print sum(total, s)

### FIXED CODE ###

s = map(int, list(raw_input()))
sum = 0
for i in xrange(0, int(1 << len(s) - 1)):
    temp_num = 0
    for j in xrange(0, len(s)):
        cur_num = s[j]
        if i % 2 == 1:
            temp_num += cur_num
            if j != len(s) - 1:
                sum += temp_num
                temp_num = 0
        else:
            temp_num += cur_num
        i /= 2
        if j == len(s) - 1:
            sum += temp_num
            temp_num = 0
        temp_num *= 10
print sum


def sum(total, s):
    r = 0
    for i in range(len(s)):
        if i == 0:
            r = total + int(s)
        else:
            r += sum(total + int(s[:i]), s[i:])
    return r
n = int(input())
    count = (n-1)*n//2
    print(count)

### FIXED CODE ###

n = int(input())
count = (n-1)*n//2
print(count)
n,m=map(int,input().split())
x=[list(map(int,input().split())) for _ in range(m)]
n1=[0]*n
nc=[0]*n
for i in range(n):
    if n1[x[i][0]-1]==0:
        n1[x[i][0]-1]+=x[i][1]
        nc[x[i][0]-1]+=1
    elif nc[x[i][0]-1]!=0 and n1[x[i][0]-1]!=x[i][1]:
        print(-1)
        exit()
while True:
    if n1[0]==0:n1.pop(0)
    if sum(n1)==0:
        print(0)
        exit()
    else:break
print(''.join(map(str,n1)))

### FIXED CODE ###

n,m=map(int,input().split())
 
a=["0"]*n
 
for i in range(m):
    s,c=map(int,input().split())
    if a[s-1]=="0":
        a[s-1]=c
    elif a[s-1]!=c:
        print(-1)
        exit()

if n>1 and a[0]==0:
    print(-1)
    exit()

if n>1 and a[0]=="0":
    a[0]=1

print(*a,sep="")
n,k = map(int,input().split())
a = list(map(int,input().split()))
for i in range(n):
    a[i] -= 1

loop = [0]
loop_corr = []
while len(loop) < k:
    curr = loop[len(loop) - 1]
    if a[curr] not in loop:
        loop.append(a[curr])
        # print(loop)
    else:
        loop_corr = loop[loop.index(a[curr]):len(loop)]
        break

if len(loop) > k:
    print(loop[k]+1)
else:
    diff = k - len(loop) + 1
    mod = (diff % len(loop_corr)) -1
    print(loop_corr[mod]+1)
        
    

### FIXED CODE ###


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


s = []
ord = [-1] * (n+1)

v = 1
c = 1
l = 0
while ord[v] == -1:
    ord[v] = len(s)
    s.append(v)
    v = a[v-1]
c = len(s) - ord[v]
l = ord[v]

if l > k:
    print(s[k])
else:
    k -= l
    k %= c
    print(s[l+k])
N, K = map(int, input().split())
H = list(map(int, input().split()))
dp = [1 << 62] * N
dp[0] = 0
for i in range(1, N):
    for j in range(i, min(i + 1 + K, N)):
        cost = abs(H[i - 1] - H[i + j])
        dp[i + j] = min(dp[i + j], dp[i - 1] + cost)
print(dp[-1])


### FIXED CODE ###

import sys

# import numpy as np


def main():
    f = sys.stdin.buffer
    N, K = map(int, f.readline().split())
    H = list(map(int, f.readline().split()))
    dp = [0] * N
    for i in range(1, N):
        dp[i] = min(
            dp[i - k - 1] + abs(H[i] - H[i - k - 1]) for k in range(K) if i - k - 1 >= 0
        )
    print(dp[-1])


if __name__ == "__main__":
    main()
import numpy as np
N, W = map(int, input().split())
wv = [map(int, input().split()) for i in range(N)]
dp = [[0] * (W+1)] * (N+1)
for i, (w, v) in enumerate(wv):
    for j in range(W+1):
        dp[i+1][j] = max(dp[i+1][j], dp[i][j])
        if j-w >= 0:
            dp[i+1][j] = max(dp[i+1][j], dp[i][j-w] + v)
print(dp[N][W])

### FIXED CODE ###

import numpy as np
N, W = map(int, input().split())
wv = [map(int, input().split()) for i in range(N)]
dp = np.zeros((N+1, W+1), dtype = np.int)
for i, (w, v) in enumerate(wv):
    dp[i+1] = np.maximum(dp[i+1], dp[i])
    dp[i+1][w:] = np.maximum(dp[i+1][w:], dp[i][:-w] + v)
print(dp[N][W])