Harryxun/stf_run huggingface dataset:
from collections import deque
import sys, copy,itertools
input = sys.stdin.readline

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

ans = [-10**12] * n
#print(ans)

q = k // n
mod = k % n

POINT = [[-10**12 for i in range(n)] for j in range(k)]
PLACE = [[0 for i in range(n)] for j in range(k)]
for i in range(n):
  POINT[0][i] = C[P[i]-1]  
  PLACE[0][i] = P[i]-1 #P[i]は1スタートなのでずれる

tempmax= max(POINT[0])

z = min(k,n)

for j in range(1,z): #日付
  for i in range(n):
    PLACE[j][i]=P[PLACE[j-1][i]]-1
    POINT[j][i]=POINT[j-1][i] + C[PLACE[j][i]]
    tempmax = max(tempmax,POINT[j][i])

tt = -10**-12
if k <= n:
  answer = tempmax
else:
  for i in range(n):
    ans[i] = q * POINT[n][i]
    for j in range(mod):
      tt = max(tt, POINT[j][i])
    ans[i] += tt
print(max[answer])

### FIXED CODE ###

from collections import deque
import sys, copy,itertools
input = sys.stdin.readline

n, k = map(int,input().split())
#P = list(map(int,input().split()))
P = list(map(lambda x : int(x) - 1, input().split())) #ひとつづつずらす
C = list(map(int,input().split()))
SCORE = [0]*(n+1)

max_score = -10**12
for i in range(n):
  x = i
  TEMPMAX = [-10**9] * (n+1)
  for j in range(1, n+1):
    SCORE[j] = SCORE[j-1] + C[P[x]]
    TEMPMAX[j]= max(TEMPMAX[j-1], SCORE[j])
    x = P[x]
    if x == i:
      break
  if j >= k:
    max_score = max(max_score,TEMPMAX[k])
  elif SCORE[j] < 0:
    max_score = max(max_score, TEMPMAX[j])
  else:
    m = k//j
    a = SCORE[j] *(m-1) + TEMPMAX[j]
    b = SCORE[j] *m + TEMPMAX[k % j]
    max_score = max(max_score, a, b)
print(max_score)
n = int(input())
cnt = 0
for i in range(1,n+1):
  if len(str(i)%2 == 0):
    cnt += 1
print(cnt)

### FIXED CODE ###

n = int(input())
cnt = 0
for i in range(1,n+1):
  if len(str(i))%2 != 0:
    cnt += 1
print(cnt)
import sys
n,m = map(int,input().split())

if m > 0:
    broken = set(map(int,sys.stdin))
else:
    broken = set()
    
dp = [0]*(n+1)
dp[0] = 1
dp[1] = 1 if 1 not in broken else 0

MOD = 10**9 + 7

for i in range(2,n+1):
    if i in broken:
        continue
    dp[i] =(dp[i-1]+dp[i-2])% MOD
    
print(dp[n])

### FIXED CODE ###

c=list(map(int, input().split()))

c.remove(max(c))

print(sum(c))
N = int(input())
A = sorted(list(map(int, input().split(' '))))
A_max = A[-1]
dp = [True]*(A_max+1)
ans = 0
for i in range(N-1):
    p = A[i]
    if dp[i] == True:
        for q in range(A_max//p+1):
            dp[p*q] = False
        if A[i] != A[i+1]:
            ans += 1
if dp[-1] != True:
    ans += 1 
print(ans)

### FIXED CODE ###

N = int(input())
A = sorted(list(map(int, input().split(' '))))
# print(A)
a_max = A[-1]
dp = [True]*(a_max+1)
ans = 0
for i in range(N-1):
    p = A[i]
    if dp[p] == True:
        # print(math.sqrt(p))
        for q in range(a_max//p+1):
            # print(p*q)
            dp[p*q] = False
        if A[i] != A[i+1]:
            ans += 1
if dp[A[-1]]:
    ans += 1
print(ans)
N,Ma,Mb = map(int,input().split())
table = []
sum_a,sum_b,sum_c = 0,0,0

for i in range(N):
  a,b,c=map(int,input().split())
  sum_a += a 
  sum_b += b
  sum_c += c
  table.append((a,b,c))
  
INF = sum_c+1
ans = INF
dp=[[[INF]*(sum_a+1) for i in range(sum_b+1)] for i in range(N+1)]
dp[0][0][0] = 0
for i in range(1,N+1):
  a,b,c = table[i-1]
  for ca in range(sum_a+1):
    for cb in range(sum_b+1):
      dp[i][ca][cb] = min(dp[i-1][ca][cb],dp[i][ca][cb])
      if ca+a < sum_a and cb+b < sum_b:
        dp[i][ca+a][cb+b] = min(dp[i][ca+a][cb+b],dp[i][ca][cb]+c)

for ca in range(sum_a+1):
  for cb in range(sum_b+1):
    if ca*Ma == cb*Mb and ca*cb != 0:
      for i in range(N+1):
        ans = min(ans,dp[i][ca][cb])
print(ans if ans != INF else -1)

### FIXED CODE ###

N, Ma, Mb = map(int, input().split())
table = []
for i in range(N):
  a,b,c = map(int, input().split())
  table.append([a,b,c])
inf = 10**9
dp = [[[inf]*401 for i in range(401)] for i in range(N+1)]
dp[0][0][0] = 0

for i in range(1,N+1):
  a,b,c = table[i-1]
  for j in range(401):
    for k in range(401):
      dp[i][j][k] = dp[i-1][j][k]
      if 400>=j-a>=0 and 400>=k-b>=0:
        dp[i][j][k] = min(dp[i-1][j][k],dp[i-1][j-a][k-b]+c)
ans = 10**9
i = 1
while max(Ma,Mb)*i <= 400:
  ans = min(ans,dp[N][Ma*i][Mb*i])
  i += 1
if ans == 10**9:
  ans = -1
print(ans)
s = list(input())

k = int(input())

n = len(s)

if(len(set(s)) == 1):
    print(n*k//2)
else:
    if(s[0] != s[-1]):
        print(n//2*k)
    else:
        print(n//2*k - (a//2 + b//2 - (a+b)//2) * (k-1))

### FIXED CODE ###

s = list(input())

k = int(input())

n = len(s)

if(len(set(s)) == 1):
    print(n*k//2)
else:
    t = 0
    c = 1
    for i in range(n-1):
        if(s[i] == s[i+1]):
            c += 1
        else:
            t += c // 2
            c = 1
    t += c // 2
    if(s[0] != s[-1]):
        print(t*k)
    else:
        a = 0
        b = 0
        for i in range(n):
            if(s[i] == s[0]):a+=1
            else:break
        for i in range(n)[::-1]:
            if(s[i] == s[-1]):b+=1
            else:break
        print(t*k - (a//2 + b//2 - (a+b)//2) * (k-1))
n = "NO"
y = "YES"

A, V = map(int, input().split()) #Aは初期座標 Vは1秒あたりの移動距離#
B, W = map(int, input().split()) #Aは初期座標 Wは1秒あたりの移動距離#
T = int(input()) #移動許可秒数#

##################################################
# 答えはT秒後に鬼が逃げ役と同じ座標or追い越せばYES#
# 計算はTLE対策として掛け算を使用　　　　　　　　　#
#V,W * T でT秒間の移動距離を算出 　　　　　　　　　#
# ANS = A,B + V,W * T　　　　　　　　　　　　　　　#   
##################################################

X = V * T
Y = W * T

A += X
B += Y

if B >= A:
  print(y)
else:
  print(n)


### FIXED CODE ###

S = input()

print(S[0:3])
ans = 9999999
res = 0
for i in range(N):
    res += A[i] - (i+1)

b = res // N
res = 0
for i in range(N):
    res += abs(A[i] - (b+(i+1)))
print(res)


### FIXED CODE ###

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

A_sorted = sorted([A[i] - (i+1) for i in range(N)])

if len(A) != 1:
    b = A_sorted[int((len(A)-1)/2)]
    b2 = A_sorted[int((len(A)-1)/2 + 1)]
    sad_1 = sum([abs(A_sorted[i] - b) for i in range(N)])
    sad_2 = sum([abs(A_sorted[i] - b2) for i in range(N)])
    print(min(sad_1, sad_2))
else:
    print('0')
import sys
import itertools
# import numpy as np
import time
import math
 
sys.setrecursionlimit(10 ** 7)
 
from collections import defaultdict
 
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

a, b, x = map(int, readline().split())

v = a * a * b
s = x / a


if x < v / 2:
    # print(math.degrees(math.atan(2 * s / b / b)))
    print(90 - math.degrees(math.atan(2 * x / a / b / b)))
else:
    print(90 - math.degrees(math.atan(a / (b - (2 * (x/ a) / a - b)))))



### FIXED CODE ###

import sys
import itertools
# import numpy as np
import time
import math
 
sys.setrecursionlimit(10 ** 7)
 
from collections import defaultdict
 
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

a, b, x = map(int, readline().split())

v = a * a * b
s = x / a

if x == v:
    print(0)
    exit()

if x <= v / 2:
    # print(math.degrees(math.atan(2 * s / b / b)))
    print(90 - math.degrees(math.atan(2 * x / a / b / b)))
else:
    print(90 - math.degrees(math.atan(a / (b - (2 * s / a - b)))))
import math

S = int(input())

first_half = math.floor(S / 100)
second_half = S - first_half * 100

if 1 <= second_half <= 12 and 1 <= first_half <= 12 :
  print("AMBIGUOUS")
else:
  if 1 <= second_half <= 12 :
   		print("YYMM")
  elif 0 == first_half or 12 < first_half :
    	print("NA")
  else: 
        print("MMYY")

### FIXED CODE ###

N,K = map(int,input().split())
S = input()

letters = list(S)
letters[K-1] = letters[K-1].lower()

new_S = ""

for letter in letters:
  new_S += letter
  
print(new_S)
N, K = map(int,input().split())
listMap = [int(i) for i in input().split()]
minMin = float("inf")
ans = 0
# 正の数 or 負の数 onlyなら別処理
if listMap[0] >= 0 or listMap[-1] <= 0:
    sorted(listMap)
    ans = abs(listMap[K - 1])

else:
    for j in range(N - K):
        L = j
        R = j + K - 1
        if listMap[L] <= 0 <= listMap[R]:
            sumLR = abs(listMap[L] - listMap[R])
            if sumLR < minMin:
                minMin = sumLR
                minL = L

    # 距離を確認
    if -listMap[minL] < listMap[minL + K - 1]:
        ans = -listMap[minL] * 2 + listMap[minL + K - 1]
    else:
        ans = listMap[minL + K - 1] * 2 + -listMap[minL]

print(ans)

### FIXED CODE ###

N, K = map(int,input().split())
listMap = [int(i) for i in input().split()]
minMin = float("inf")

if N == 1:
    minMin = listMap[0]

for j in range(N - (K - 1)):
    L = j
    R = j + (K - 1)
    sumL = abs(listMap[L]) + abs(listMap[L] - listMap[R])
    sumR = abs(listMap[R]) + abs(listMap[R] - listMap[L])
    sum = min(sumL, sumR)
    if sum < minMin:
        minMin = sum

print(minMin)
def menseki(S):
    sx=[ss[0] for ss in S]
    sy=[ss[1] for ss in S]

    zahyominmax=[min(sx),max(sx),min(sy),max(sy)]
    return (zahyominmax[1]-zahyominmax[0])*(zahyominmax[3]-zahyominmax[2])



def spaceinput():
    return list(map(int,input().split(" ")))



N,K=spaceinput()

x=[]
for i in range(N):
    x.append(spaceinput())

x=sorted(x,key=lambda s:s[0])

S=x[:K]

sx=[ss[0] for ss in S]
sy=[ss[1] for ss in S]

zahyominmax=[min(sx),max(sx),min(sy),max(sy)]
minmenseki=(zahyominmax[1]-zahyominmax[0])*(zahyominmax[3]-zahyominmax[2])


for i in range(K,len(x)):

    #print(S)
    a=x[i]
    S.append(a)

    #minmenseki=menseki
    for k in range(len(S)):
        bb=S[:k]
        bb.extend(S[k+1:])
        s=menseki(bb)
        if s<minmenseki:
            minmenseki=s
            kmin=k


    #menseki=minmenseki
    del S[kmin]


print(minmenseki)

### FIXED CODE ###


import itertools as it

from functools import *
import sys
sys.setrecursionlimit(100000)
input = sys.stdin.readline


def acinput():
    return list(map(int, input().split(" ")))


def II():
    return int(input())



N, K = acinput()


ary = [acinput() for i in range(N)]
x = list(map(lambda x: x[0], sorted(ary, key=lambda s: s[0])))
y = list(map(lambda x: x[1], sorted(ary, key=lambda x: x[1])))


#print(list(it.combinations(y,2)))
#print(list(x))

res = 10**20
for sy in it.combinations(y, 2):
    #print(sy)
    for sx in it.combinations(x, 2):
        #print(sx)
        #print(sy, sx)
        count = 0
        for sa in ary:
            
            if sy[0] <= sa[1] and sa[1] <= sy[1]:
                if sx[0] <= sa[0] and sa[0] <= sx[1]:
                    count += 1

        #print(count)
        if count >= K:
            #dx = np.diff(sx)[0]
            #dy = np.diff(sy)[0]
            dx=sx[1]-sx[0]
            dy=sy[1]-sy[0]
            #print(dx,dy)
            res = min(res, dx*dy)
            #print(res)

print(res)
n=input()
print(n*(n+1)//2)


### FIXED CODE ###

n=int(input())
print(n*(n+1)//2)
h,w,d=map(int,input().split())

board=[0 for _ in range(h*w)]

for i in range(h):
    for j,a in enumerate(input().split()):
        board[i*w+j]=int(a)

q=int(input())


distances=[0 for _ in range(h*w)]

for i in range(d,h*w):
    a=h*w-i
    tmp=board.index(a)
    i=tmp//w
    j=tmp%w
    tmp=board.index(a+d)
    x=tmp//w
    y=tmp%w
    distances[a-1]=distances[a+d-1]+abs(i-x)+abs(j-y)

for _ in range(q):
    l,r=map(int,input().split())
    print(distances[l-1]-distances[r-1])

### FIXED CODE ###

n=int(input())
print(n//3)
sieve=[0]*1000009
n=int(input())
s=sorted(map(int,input().split()))
for i in s:
    if sieve[i]<2:
        for j in range(i,1000009,i):sieve[j]+=1
print(sum(sieve[i]==1for i in s))

### FIXED CODE ###

print(list(map(int,input().split())).index(0)+1)
N = int(input())
S = N % 10
if(S == 0):
  print('pon')
else if(S == 1):
  print('pon')
else if(S == 6):
  print('pon')
else if(S == 8):
  print('pon')
else if(S == 3):
  print('bon')
else:
  print('hon')


### FIXED CODE ###

N = int(input())
S = N % 10
if(S == 0):
  print("pon")
elif(S == 1):
  print("pon")
elif(S == 6):
  print("pon")
elif(S == 8):
  print("pon")
elif(S == 3):
  print("bon")
else:
  print("hon")
l1 = []
for _ in range(6):
  l1.append(int(input())
 
if (l1[4] - l1[0]) > l1[5]:
  r = ':('
else:
  r = 'Yay!'
  
  
print(r)

### FIXED CODE ###

l1 = []
for _ in range(6):
  l1.append(int(input()))
 
if (l1[4] - l1[0]) > l1[5]:
  r = ':('
else:
  r = 'Yay!'
  
  
print(r)
a, b = input().split()

c = a + b
c = int(c)

cc = math.sqrt(c)


if cc%1 == 0:
    print("Yes")
    

else:
    print("No")


### FIXED CODE ###

import math

a, b = input().split()

c = a + b
c = int(c)
cc = math.sqrt(c)


if cc%1 == 0:
    print("Yes")
    

else:
    print("No")
#標準入力
N = int(input())
A = list(map(int, input().split()))

#累積和
S = [0]*N
for n in range(N):
	S[n] = S[n-1] + A[n]

_sum = 0
for i in range(N-1):
  _sum = _sum + (A[i] * (S[N] - S[i+1]))
  _sum = _sum % (1000000000+7)
  
print(_sum)


### FIXED CODE ###

#標準入力
N = int(input())
A = list(map(int, input().split()))

#累積和
S = [0]*N
for n in range(N):
  S[n] = S[n-1] + A[n]

_sum = int(0)
for i in range(N-1):
  _sum = _sum + (A[i] * (S[-1] - S[i]))

#modulo
_sum = _sum % (1000000000+7)
  
print(_sum)
print(input().count(1)

### FIXED CODE ###

print(input().count("1"))
n=int(input())
a=list(map(int,input().split()))

a.sort()

table=[]
for i in range(1000001):
  table.append([True,0])
count=0
for i in range(0,n):
  if table[a[i]][0]==True:
    count+=1
  if table[a[i]][1]==0:
    table[a[i]][1]=1
    for j in range(a[i],1000002,a[i]):
      table[j][0]=False
  elif table[a[i]][1]==1:
    count-=1
    table[a[i]][1]=2
      
print(count)
  

### FIXED CODE ###

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

a.sort()

table=[True]*1000001
count=0
if n==1:
  count=1
else:
  for i in range(0,n):
    pp=a[i]
    if table[pp]==True:
      if i==0:
        if pp!=a[i+1]:
          count+=1
        for j in range(pp,1000001,pp):
          table[j]=False
      elif i==n-1:
        if pp!=a[n-2]:
          count+=1
      else:
        if pp!=a[i+1] and pp!=a[i-1]:
          count+=1
        for j in range(pp,1000001,pp):
          table[j]=False
      
print(count)
count = 0
n , t = map(int,input().split())
for i in range(n+1):
    for j in range(n+1-i):
        k = t - i- j
        #for k in range(n+1-i-j):#このfor分は不要、i,jで決まるから
            if 10000 * i + 5000 * j + 1000 * k == t:
                x,y,z = i, j, k
                print('{} {} {}'.format(x, y ,z))
                count += 1
if count == 0:
    print('{} {} {}'.format(-1 ,-1,-1))

### FIXED CODE ###


n , t = map(int,input().split())
for i in range(n+1):
    for j in range(n+1-i):
        k = n - i- j

        #for k in range(n+1-i-j):#このfor分は不要、i,jで決まるから
        if 10000 * i + 5000 * j + 1000 * k == t:

            print('{} {} {}'.format(i, j ,k))
            exit(0)
print('{} {} {}'.format(-1 ,-1,-1))
s = str(input())
if s[2]==s[3] & s[4]==s[5]:
  print("Yes")
else:
  print("No")

### FIXED CODE ###

S = str(input())
if S[2]==S[3] and S[4]==S[5]:
  print("Yes")
else:
  print("No")
n, a, b = [int(i) for i in input().split()]
c = 0
while c <= n:
  s += [1 for _ in range(a)]
  s += [0 for _ in range(b)]
  c = len(s)
print(sum(s))

### FIXED CODE ###


n, a, b = [int(i) for i in input().split()]
sy = n // (a+b)
am = n % (a+b)
print(sy*a + min(am, a))
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

import itertools
import numpy as np

N = int(readline())
info = []
for i in range(N):
    A = int(readline())
    for _ in range(A):
        x,y = map(int,readline().split())
        info.append((i,x-1,y))
#print(info)

#info=[(0, 1, 1), (1, 0, 1), (2, 1, 0)]

N=3
#A = np.array(list(itertools.product([0,1],repeat=N)),np.bool)
A = np.array(list(itertools.product([0,1],repeat=N)),np.bool)

for i,x,y in info:
    # print(~A[:,i])
    # print(A[:,x])
    # bl = (~A[:,i]) | (A[:,x] == bool(y))
    bl = (A[:,i]) & A[:,x] == bool(y)
    A = A[bl]

answer = A.sum(axis = 1).max()
print(answer)

### FIXED CODE ###

import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

import itertools
import numpy as np

N = int(readline())
info = []
for i in range(N):
    A = int(readline())
    for _ in range(A):
        x,y = map(int,readline().split())
        info.append((i,x-1,y))
        
A = np.array(list(itertools.product([0,1],repeat=N)),np.bool)
for i,x,y in info:
    bl = (~A[:,i]) | (A[:,x] == bool(y))
    A = A[bl]

answer = A.sum(axis = 1).max()
print(answer)
n,m = map(int, input().split())
a=[]
for i in range(n):
    a.append(tuple(map(int, input().split())))

dp = []
for i in range(m+1):
    dp.append([0 for j in range(n+1)])

def f(fn):
    global dp, a
    for i in range(1,m+1):
        for j in range(1,n+1):
            dp[i][j] = max(dp[i][j-1], dp[i-1][j-1] + fn(a[j-1]))

ans = []
f(lambda x: x[0]+x[1]+x[2])
ans.append(dp[m][n])
f(lambda x: x[0]+x[1]-x[2])
ans.append(dp[m][n])
f(lambda x: x[0]-x[1]+x[2])
ans.append(dp[m][n])
f(lambda x: x[0]-x[1]-x[2])
ans.append(dp[m][n])
f(lambda x: -x[0]+x[1]+x[2])
ans.append(dp[m][n])
f(lambda x: -x[0]+x[1]-x[2])
ans.append(dp[m][n])
f(lambda x: -x[0]-x[1]+x[2])
ans.append(dp[m][n])
f(lambda x: -x[0]-x[1]-x[2])
ans.append(dp[m][n])

print(max(ans))


### FIXED CODE ###

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

if a > 8 or b > 8:
    print(":(")
else:
    print("Yay!")
import math

t = int(input())
r = int(input())
s = int(input())
print(r//s - (t-1)//s)


### FIXED CODE ###

import math

t, r, s = map(int, input().split())
print(r//s - (t-1)//s)
A,B,C,D,E,F=map(int,input().split())
n=F//(100+E)
max_water=100*n

ans=[0,0]
concentration=0.0
for i in range(max_water//(100*B)+1):
    tmp_water=100*B*i
    tmp_water+=100*A*((max_water-tmp_water)//(100*A))
    max_suger=(tmp_water//100)*E
    for j in range(max_suger//D+1):
        tmp_suger=D*j
        tmp_suger+=C*((max_suger-tmp_suger)//C)
        if tmp_suger/(tmp_water+tmp_suger)>concentration:
            concentration=tmp_suger/(tmp_water+tmp_suger)
            ans=[tmp_water+tmp_suger,tmp_suger]

print(*ans)

### FIXED CODE ###

A,B,C,D,E,F=map(int,input().split())

ans=[0,0]
concentration=0.0
for i in range(F//(100*B)+1):
    tmp_water=100*B*i
    for j in range((F-tmp_water)//(100*A)+1):
        tmp_water+=100*A*j
        max_suger=min((tmp_water//100)*E,F-tmp_water)
        for k in range((max_suger)//D+1):
            tmp_suger=D*k
            tmp_suger+=C*((max_suger-tmp_suger)//C)
            if tmp_water+tmp_suger==0:
                continue
            elif tmp_suger/(tmp_water+tmp_suger)>=concentration:
                concentration=tmp_suger/(tmp_water+tmp_suger)
                ans[0]=tmp_water+tmp_suger
                ans[1]=tmp_suger

print(*ans)
import sys
input = sys.stdin.readline

def main():
    n = int(input())
    a_list = list(map(int, input().split()))
    c = [0] * n
    s = 0
    for i, a in enumerate(a_list):
        if i+a < n:
            d[i+a] += 1
        if i-a >= 0:
            s += d[i-a]
    print(s)

if __name__ == '__main__':
    main()

### FIXED CODE ###

import sys
input = sys.stdin.readline

def main():
    n = int(input())
    a_list = list(map(int, input().split()))
    c = [0] * n
    s = 0
    for i, a in enumerate(a_list):
        if i+a < n:
            c[i+a] += 1
        if i-a >= 0:
            s += c[i-a]
    print(s)

if __name__ == '__main__':
    main()
def main():
    # importも関数の中で実装する
    # ローカル変数化する
    # xxx
    N, N = map(int, input().split())
    SC = [list(map(int, input().split())) for _ in [0]*N ]

    for i in range(10 ** (N-1), 10 ** N):
        S = str(i)
        if len(S) == N:
            if all(S[s - 1] == str(c) for s, c in SC):
                print(S)
                quit()
    print(-1)

main()

### FIXED CODE ###

n,m,*z=map(int,open(0).read().split())
for i in range(10**n):
  S=str(i)
  if len(S)==n:
    if all(S[s-1]==str(c)for s,c in zip(z[0::2],z[1::2])):
      print(S)
      quit()
print(-1)
n = int(input())
ans = 0
for i in range(1, n + 1)
	if len(str(i)) % 2 == 1:
    	ans += 1
print(ans)

### FIXED CODE ###

n = int(input())
cnt = 0
for i in range(1, n + 1):
  if len(str(i)) % 2 == 1:
    cnt +=1
print(cnt)
n, k = tuple(map(int, input().split(' ')))
hs = list(map(int, input().split(' ')))
if k>=n:
    print(0)
    return
hs = sorted(hs)
print(sum(hs[:n-k]))


### FIXED CODE ###

n, k = tuple(map(int, input().split(' ')))
hs = list(map(int, input().split(' ')))
if k>=n:
    print(0)
    exit()
hs = sorted(hs)
print(sum(hs[:n-k]))
import numpy as np
N=int(input())
s=input()
west=[]
east=[]
for i in range(N):
    west.append(0)
    east.append(0)
    if(s[i]=='W'):
        west[i]=1
    else:
        east[i]=1
eastsum=np.zeros(N)
westsum=np.zeros(N)
westsum[0]=west[0]
eastsum[0]=east[N-1]
for i in range(1,N):
    eastsum[N-1-i]=eastsum[N-i]+east[N-1-i]
    westsum[i]=westsum[i-1]+west[i]
print(eastsum+westsum)

### FIXED CODE ###

listA=list(map(int,input().split()))
A=listA[0]
B=listA[1]
listB=[A*B,A+B,A-B]
print(max(listB))
import math

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

b_1 = x / (a ** 2)
area_1 = a * b_1
area_2 = (a * b) / 2

if area_2 > area_1:
    # 三角形
    h = (a * b_1 * 2) / b
    ans = math.degrees(math.atan(h / b))
else:
    # 梯形
    upside_len = b_1 * 2 - b
    ans = math.degrees(math.atan(a / (b - upside_len)))

print(90 - ans)


### FIXED CODE ###

import math

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

b_1 = x / (a ** 2)
area_1 = a * b_1
area_2 = (a * b) / 2

if b_1 == b:
    ans = 90
elif area_2 > area_1:
    # 三角形
    h = (a * b_1 * 2) / b
    ans = math.degrees(math.atan(h / b))
else:
    # 梯形
    upside_len = b_1 * 2 - b
    ans = math.degrees(math.atan(a / (b - upside_len)))

print(90 - ans)
n = int(input())
a = [int(i) for i in input().split()]
a_2 = [abs(a[i]) for i in range(n)]
a.sort()

if a[0] >= 0:
    print([sum(a_2) -2, sum(a_2)][a[0] == 0])
    aa = a[0]
    for i in range(n-1):
        if i == 0:
            print(aa, a[i + 1])
            aa = aa - a[i + 1]
        elif i == n - 2:
            print(a[i + 1], aa)
        else:
            print(aa, a[i+1])
            aa = aa - a[i + 1]

elif a[-1] <= 0:
    if:
        
    print([sum(a_2) -2, sum(a_2)][a[-1] == 0])
    if a[-1] == 0:
        a = [a[0]] + [a[-1]] + a[1:]
    aa = a[0]
    for i in range(n-1):
        if i == 0:
            print(a[i+1], aa)
            aa = a[i + 1] - aa
        elif i == n - 2:
            print(aa, a[i + 1])
        else:
            print(aa, a[i+1])
            aa = aa - a[i + 1]

else:
    print(sum(a_2))
    minus = []
    plus = []
    for i in range(n):
        if a[i] < 0:
            minus.append(a[i])
        else:
            plus.append(a[i])
    minus2 = minus.pop()
    plus2 = plus.pop()
    for i in range(len(minus)):
        print(plus2 ,minus[i])
        plus2 -= minus[i]
    for i in range(len(plus)):
        print(minus2, plus[i])
        minus2 -= plus[i]
    print(plus2, minus2)



### FIXED CODE ###

n = int(input())
a = [int(i) for i in input().split()]
a_2 = [abs(a[i]) for i in range(n)]
a.sort()

if a[0] >= 0:
    print([sum(a_2) -2, sum(a_2)][a[0] == 0])
    aa = a[0]
    for i in range(n-1):
        if i == 0:
            print(aa, a[i + 1])
            aa = aa - a[i + 1]
        elif i == n - 2:
            print(a[i + 1], aa)
        else:
            print(aa, a[i+1])
            aa = aa - a[i + 1]

elif a[-1] <= 0:

    print([sum(a_2) -2, sum(a_2)][a[-1] == 0])
    a.reverse()
    if a[-1] == 0:
        a = [a[-1]] + a[0:]
    aa = a[0]
    for i in range(n-1):
        if i == 0:
            print(aa, a[i + 1])
            aa = aa - a[i + 1]
        elif i == n - 2:
            print(aa, a[i + 1])
        else:
            print(aa, a[i+1])
            aa = aa - a[i + 1]

else:
    print(sum(a_2))
    minus = []
    plus = []
    for i in range(n):
        if a[i] < 0:
            minus.append(a[i])
        else:
            plus.append(a[i])
    minus2 = minus.pop()
    plus2 = plus.pop()
    for i in range(len(minus)):
        print(plus2 ,minus[i])
        plus2 -= minus[i]
    for i in range(len(plus)):
        print(minus2, plus[i])
        minus2 -= plus[i]
    print(plus2, minus2)