Harryxun/stf_run huggingface dataset:
#!/usr/bin/env python3
#ABC118 D

import sys
import math
import bisect
from heapq import heappush, heappop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
mod = 10**9 + 7

M = [0,2,5,5,4,5,6,3,7,6]
n,m = map(int,input().split())
a = list(map(int,input().split()))
A = [[i,M[i]] for i in a]
A.sort(key = itemgetter(1))

#dp[i] := ちょうどマッチi本を使ってできる最大桁数
dp = [-float('inf')]*(n+1)
dp[0] = 0
for i in range(n):
    for j,k in A:
        if i + k < n+1:
            if dp[i] < 0:
                continue
            dp[i+k] = dp[i] + 1
A.sort(key = itemgetter(0),reverse = True)
ans = ''
k = n
while 1:
    for i,j in A:
        if dp[k-j] == dp[k]-1:
            ans += str(i)
            k -= j
            break
    else:
        break
print(ans)


### FIXED CODE ###

#!/usr/bin/env python3
#ABC118 D

import sys
import math
import bisect
from heapq import heappush, heappop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
mod = 10**9 + 7

M = [0,2,5,5,4,5,6,3,7,6]
n,m = map(int,input().split())
a = list(map(int,input().split()))
A = [[i,M[i]] for i in a]
A.sort(key = itemgetter(1))

#dp[i] := ちょうどマッチi本を使ってできる最大桁数
dp = [-float('inf')]*(n+1)
dp[0] = 0
for i in range(n):
    for j,k in A:
        if i + k < n+1:
            if dp[i] < 0:
                continue
            dp[i+k] = dp[i] + 1
A.sort(key = itemgetter(0),reverse = True)
ans = ''
k = n
while 1:
    for i,j in A:
        if k - j < 0:
            continue
        if dp[k-j] == dp[k]-1:
            ans += str(i)
            k -= j
            break
    else:
        break
print(ans)
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;

class Solver7
    {
        /*
         * https://atcoder.jp/contests/abc131/tasks/abc131_d
         * 
         * 
         */
                public void Solve7()
        {
            var nnum = 99999999;
            var n = int.Parse(Console.ReadLine());
            int[] X = new int[nnum];
            
            try
            {
                for (int i = 0; i < n; i++)
                {
                    var ab = u.readIntArrayBySplit();
                    var a = ab[0];
                    var b = ab[1];
                    var p = b;
                    for (int j = 0; j < a; j++)
                    {
                      	var xx = X[p];
                      	
                        while (X[p]!=null && X[p] == 1)
                        {
                            p--;
                        }
                        X[p] = 1;
                    }
                }
                Console.WriteLine("Yes");
            }
            catch(Exception ex)
            {
                Console.WriteLine("No");
            }


        }
        static void Main()
        {
            var solver = new Solver7();
            solver.Solve7();
        }
    }
    static class u
    {
        public static void outA(int[] A) { Console.WriteLine(string.Join(" ", A)); }
        public static void outInt(int i) { Console.WriteLine(i.ToString()); }
        public static void outLong(long i) { Console.WriteLine(i.ToString()); }
        static public string AsJoinedString<T>(this IEnumerable<T> ie, string st = " ") { return string.Join(st, ie); }
        public static int readInt() { return int.Parse(Console.ReadLine()); }
        public static  string readStr() { return Console.ReadLine(); }
        public static int[] readIntArrayBySplit() { return Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray(); }
        public static int[] readIntArrayZeroIchiRenzoku() { return Console.ReadLine().Select(s => int.Parse(s.ToString())).ToArray(); }

    }

### FIXED CODE ###

n = int(input())
A=[]
for i in range(n):
  a,b = map(int,input().split())
  A.append((b,a))
A.sort()
c = 0
for a in A:
  c+=a[1]
  if c>a[0]:
    print("No")
    exit()
print("Yes")
n = input()
A = map(int, raw_input().split())
q = input()
m = map(int, raw_input().split())

def solve(i, m):
 if m == 0:
  return True
 if i >= n and m > sum(A):
  return False
 res = solve(i + 1, m) or solve(i + 1, m - A[i])
 return res

for j in range(0, q-1):
 if solve(0, m[j]):
  print "yes"
 else:
  print "no"

### FIXED CODE ###

n = input()
A = map(int, raw_input().split())
q = input()
m = map(int, raw_input().split())

def solve(i, m):
 if m == 0:
  return True
 if i >= n or m > sum(A):
  return False
 res = solve(i+1, m) or solve(i+1, m-A[i])
 return res

for j in range(0, q):
 if solve(0, m[j]):
  print 'yes'
 else:
  print 'no'
cardlist = [[i for i in range(1,14)] for j in range(4)]
n=int(input())
for s in range(0,n):
  x,y=(input().split())
  y=int(y)
  if   x =="S":
    cardlist[0].remove(y)
  elif x =="H":
    cardlist[1].remove(y)
  elif x =="C":
    cardlist[2].remove(y)
  else:
    cardlist[3].remove(y)
for i in cardlist[0]:
  print("S",z)
for i in cardlist[1]:
  print("H",z)
for i in cardlist[2]:
  print("C",z)
for i in cardlist[3]:
  print("D",z)
  
  

### FIXED CODE ###

N = int(input())
x = [f"{x} {i}" for x in 'SHCD' for i in range(1,14) ]
[x.remove(input()) for i in range(N)]
for i in x:
    print(i)
N, M = map(int, input().split())
A = list(map(int, input().split()))
BC = [list(map(int, input().split())) for i in range(M)]

CB = []
for i in BC:
    CB.append([i[1], i[0]])

A.sort()
CB.sort(reverse=True)

cnt = 0
for i in CB:
    for j in range(i[1]):
        if A[cnt] < i[0] and cnt < N:
            A[cnt] = i[0]
            cnt += 1
        else:
            print(sum(A))
            exit()

print(sum(A))

### FIXED CODE ###

N, M = map(int, input().split())
A = list(map(int, input().split()))
BC = [list(map(int, input().split())) for i in range(M)]

CB = []
for i in BC:
    CB.append([i[1], i[0]])

A.sort()
CB.sort(reverse=True)

cnt = 0
for i in CB:
    for j in range(i[1]):
        if cnt < N:
            if A[cnt] < i[0]:
                A[cnt] = i[0]
                cnt += 1
            else:
                print(sum(A))
                exit()
        else:
            print(sum(A))
            exit()

print(sum(A))
def CountingSort(A, k):
    C = [0] * k
    B = C[:]
    for a in A:
        C[a] += 1
    for i in range(1, len(C)):
        C[i] += C[i - 1]
    for i in range(len(A) - 1, -1, -1):
        B[C[A[i]]] = A[i]
        C[A[i]] -= 1
    return B


fin = open('sample.txt')
input = fin.readline

if __name__ == '__main__':
    N = int(input())
    A = [int(i) for i in input().strip().split()]
    sorted_A = CountingSort(A, int(3E6))
    print(' '.join([str(a) for a in sorted_A[1:len(A) + 1]]))

### FIXED CODE ###

def CountingSort(A, k):
    C = [0] * k
    B = C[:]
    for a in A:
        C[a] += 1
    for i in range(1, len(C)):
        C[i] += C[i - 1]
    for i in range(len(A) - 1, -1, -1):
        B[C[A[i]]] = A[i]
        C[A[i]] -= 1
    return B



if __name__ == '__main__':
    N = int(input())
    A = [int(i) for i in input().strip().split()]
    sorted_A = CountingSort(A, int(3E6))
    print(' '.join([str(a) for a in sorted_A[1:len(A) + 1]]))
import sys
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
read = sys.stdin.buffer.read
sys.setrecursionlimit(10 ** 7)
INF = float('inf')

A, B, K = map(int, input().split())
l = list(range(A, B+1))
ans = list(set(l[:K] + l[-K:]))
ans.sort()

print(*ans, sep="\n")


### FIXED CODE ###

import sys
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
read = sys.stdin.buffer.read
sys.setrecursionlimit(10 ** 7)
INF = float('inf')

a,b,k=map(int,input().split())
ans=[]
for i in range(a,min(a+k,b+1)):
  ans.append(i)
for i in range(max(b-k+1,a),b+1):
  ans.append(i)
ans = sorted(list(set(ans)))
for i in ans:
  print(i)
def main():
	N = int(input())
	z = []
	for i in range(N):
		d1, d2 = [int(d) for d in input().split(" ")]
		if d1 == d2:
			z.append(1)
		else:
			z.append(0)
	zc = []
	now = 2
	c = 0
	for i in range(len(z)):
		if i == 0:
			now = z[i]
			c += 1
		elif now == z[i]:
			c += 1
		elif now == 1 and z[i] == 0:
			zc.append(c)
			c = 1
			now = z[i]
		elif now == 0 and z[i] == 1:
			c = 1
			now = z[i]
	else:
		if now == 1:
			zc.append(c)

	print("Yes") if max(zc) >= 3 else print("No")

main()

### FIXED CODE ###

def main():
	N = int(input())
	z = []
	for i in range(N):
		d1, d2 = [int(d) for d in input().split(" ")]
		if d1 == d2:
			z.append(1)
		else:
			z.append(0)
	zc = []
	now = 2
	c = 0
	for i in range(len(z)):
		if i == 0:
			now = z[i]
			c += 1
		elif now == z[i]:
			c += 1
		elif now == 1 and z[i] == 0:
			zc.append(c)
			c = 1
			now = z[i]
		elif now == 0 and z[i] == 1:
			c = 1
			now = z[i]
	else:
		if now == 1:
			zc.append(c)

	print("Yes") if len(zc) > 0 and max(zc) >= 3 else print("No")

main()
N = int(input())
a1, a2, a3 = map(int, input().split())
b1, b2, b3 = map(int, input().split())
A = [a1, a2, a3]
B = [b1, b2, b3]
if (a1<=b1 and a2<=b2 and a3<=b3) or (a1>=b1 and a2>=b2 and a3>=b3):
    if a1>b1 or a2>b2 or a3>b3:
        A, B = B, A
    dp = [[-float("inf")]*(N+1+5050) for _ in range(4)]
    dp[0][0] = 0
    for i in range(3):
        ai = A[i]
        bi = B[i]
        for j in range(N+1):

            dp[i+1][j] = max(dp[i][j], dp[i+1][j-ai]+bi)
    print(max(dp[3]))
    assert False
    #print(dp[3][:30])
else:
    C, D = [], []
    for a, b in zip(A, B):
        if a <= b:
            C.append([a,b])
        else:
            D.append([b, a])

    if len(C)==1:
        a, b = C[0]
        q, n = divmod(N, a)
        N_ = q*b + n
    else:
        N_ = N
        (a1, b1), (a2, b2) = C
        for i in range(N + 1):
            j = N - i
            q1, n1 = divmod(i, a1)
            q2, n2 = divmod(j, a2)
            N_ = max(N_, q1 * b1 + q2 * b2 + n1 + n2)

    if len(D)==1:
        a, b = D[0]
        q, n = divmod(N_, a)
        print(q*b + n)
        #print("a")
    else:
        ans = N_
        (a1, b1), (a2, b2) = D
        for i in range(N_+1):
            j = N_ - i
            q1, n1 = divmod(i, a1)
            q2, n2 = divmod(j, a2)
            ans = max(ans, q1*b1+q2*b2+n1+n2)
        print(ans)


### FIXED CODE ###

N = int(input())
a1, a2, a3 = map(int, input().split())
b1, b2, b3 = map(int, input().split())
A = [a1, a2, a3]
B = [b1, b2, b3]
if (a1<=b1 and a2<=b2 and a3<=b3) or (a1>=b1 and a2>=b2 and a3>=b3):
    if a1>b1 or a2>b2 or a3>b3:
        A, B = B, A
    dp = [[-float("inf")]*(N+1) for _ in range(4)]
    dp[0][0] = 0
    for i in range(3):
        ai = A[i]
        bi = B[i]
        for j in range(N+1):
            if j-ai>=0:
                dp[i+1][j] = max(dp[i][j], dp[i+1][j-ai]+bi)
            else:
                dp[i+1][j] = dp[i][j]
    ans = 0
    for i, v in enumerate(dp[3]):
        ans = max(ans, v+(N-i))
    print(ans)

    #print(dp[3][:30])
else:
    C, D = [], []
    for a, b in zip(A, B):
        if a <= b:
            C.append([a, b])
        else:
            D.append([b, a])

    if len(C)==1:
        a, b = C[0]
        q, n = divmod(N, a)
        N_ = q*b + n
    else:
        N_ = N
        (a1, b1), (a2, b2) = C
        for i in range(N + 1):
            j = N - i
            q1, n1 = divmod(i, a1)
            q2, n2 = divmod(j, a2)
            N_ = max(N_, q1 * b1 + q2 * b2 + n1 + n2)

    if len(D)==1:
        a, b = D[0]
        q, n = divmod(N_, a)
        print(q*b + n)
        #print("a")
    else:
        ans = N_
        (a1, b1), (a2, b2) = D
        for i in range(N_+1):
            j = N_ - i
            q1, n1 = divmod(i, a1)
            q2, n2 = divmod(j, a2)
            ans = max(ans, q1*b1+q2*b2+n1+n2)
        print(ans)
n = int(input())
 a = list(map(int, input().split()))
 ans = []
 for i in range(N):
    if (i+1) % 2 == N % 2:
         ans = [a.pop(0)] + ans
    else:
         ans = ans + [a.pop()]
print(*ans, sep=" ")

### FIXED CODE ###

from collections import deque
N = int(input())
a = list(map(int, input().split()))
ans = deque([])
for i in range(N):
    if (i+1) % 2 == N % 2:
        ans.appendleft(a[i])
    else:
        ans.append(a[i])
print(*ans, sep=" ")
n, l = map(int, input().split())
S = []
for i in range(n):
  S[i] = input()
ans = ''.jion(sorted(S))
print(ans)

### FIXED CODE ###

n, l = map(int, input().split())
k = [input() for x in range(n)]
print(''.join(sorted(k)))
import numpy as np
n,k=map(int,input().split())
P=list(map(int,input().split()))
p=np.cumsum(P)
s=[0]*(n//k+1)
MAX=p[0]
ans=0
for i in range(0,n-k):
    MAX=max(MAX,p[i+k]-p[i])
    if MAX==p[i+k]-p[i]:
        s=i
for j in P[s+1:s+k+1]:
    ans+=np.cumsum(range(1,j+1))[-1]/j
print(ans)

### FIXED CODE ###

n,k=map(int,input().split())
p=[(i+1)/2 for i in map(float,input().split())]
MAX=sum(p[0:k])
s=[MAX]*n
for i in range(0,n-k):
    s[i+1]=p[i+k]+s[i]-p[i]
    MAX=max(MAX,s[i+1])
print(MAX)
x=int(input())
if x==7 or x==5 or x==3:
    print('YES)
else:
    print('NO')

### FIXED CODE ###

x=int(input())

if x==7 or x==5 or x==3:
    print('YES')
else:
    print('NO')
n, k = map(int, input().split())
a = list(map(int, input().split()))
mod = 10 ** 9 + 7

plus = []
minus = []
for i in a:
    if i > 0: plus.append(i)
    if i < 0: minus.append(i)

ans = 1
if k > len(plus) + len(minus):
    ans = 0
elif len(minus) == 0:
    plus.sort(reverse=True)
    for i in range(k):
        ans = (ans * plus[i]) % mod
elif len(plus) == 0:
    if k % 2 == 0:
        minus.sort()
        for i in range(k):
            ans = (ans * minus[i]) % mod
    else:
        minus.sort(reverse=True)
        for i in range(k):
            ans = (ans * minus[i]) % mod
elif k == len(plus) + len(minus) and (len(minus) % 2) == 1:
    if n != k:
        ans = 0
    else:
        for x in plus:
            ans = (ans * x) % mod
        for y in minus[:k - len(plus)]:
            ans = (ans * y) % mod
else:
    plus.sort(reverse=True)
    minus.sort()
    if k > len(plus) + len(minus):
        ans = 0
    else:
        i, j = 0, 0
        if k % 2 == 1:
            ans = plus[0]
            i = 1
        while i + j < k:
            tmp_p = plus[i] * plus[i + 1] if i <= len(plus) - 2 else 1
            tmp_m = minus[j] * minus[j + 1] if j <= len(plus) - 2 else 1
            if tmp_p >= tmp_m:
                ans = (ans * (tmp_p % mod)) % mod
                i += 2
            else:
                ans = (ans * (tmp_m % mod)) % mod
                j += 2
print(ans)


### FIXED CODE ###

n, k = map(int, input().split())
a = list(map(int, input().split()))
mod = 10 ** 9 + 7

plus = []
minus = []
for i in a:
    if i > 0: plus.append(i)
    if i < 0: minus.append(i)

ans = 1
if k > len(plus) + len(minus):
    ans = 0
elif len(minus) == 0:
    plus.sort(reverse=True)
    for i in range(k):
        ans = (ans * plus[i]) % mod
elif len(plus) == 0:
    if k % 2 == 0:
        minus.sort()
        for i in range(k):
            ans = (ans * minus[i]) % mod
    else:
        if n != len(minus):
            ans = 0
        else:
            minus.sort(reverse=True)
            for i in range(k):
                ans = (ans * minus[i]) % mod
elif k == len(plus) + len(minus) and (len(minus) % 2) == 1:
    if n != k:
        ans = 0
    else:
        for x in plus:
            ans = (ans * x) % mod
        for y in minus:
            ans = (ans * y) % mod
else:
    plus.sort(reverse=True)
    minus.sort()
    i, j = 0, 0
    if k % 2 == 1:
        ans = plus[0]
        i = 1
    while i + j < k:
        tmp_p = plus[i] * plus[i + 1] if i <= len(plus) - 2 else 1
        tmp_m = minus[j] * minus[j + 1] if j <= len(minus) - 2 else 1
        if tmp_p >= tmp_m:
            ans = (ans * (tmp_p % mod)) % mod
            i += 2
        else:
            ans = (ans * (tmp_m % mod)) % mod
            j += 2
print(ans)
N, L = list(map(int, input().split()))

for i in range(N):
    apple_pie += L + i - 1

for k in range(N):
    ab = []
    ab += abs(L + k -1)
    if min(ab):
        print(apple_pie - (L + k -1))

### FIXED CODE ###

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

apple_pie = 0
for i in range(1, N+1):
    apple_pie += L + i - 1

ab = []
for k in range(1, N+1):
    ab.append(abs(L + k - 1))

print(apple_pie - (L + ab.index(min(ab))  ))
s = list(map(int,input().split()))
N = s[0]
X = s[1]
L = list(map(int,input().split()))
a = 0
d = 0
while d <= X:
  d += L[a]
  a += 1 
  if a >= N+1:
    a = N+1
    break
print(a)
  

### FIXED CODE ###

s = list(map(int,input().split()))
N = s[0]
X = s[1]
L = list(map(int,input().split()))
a = 0
d = 0
while d <= X:
  if a >= N:
    a = N+1
    break
  else:
    d += L[a]
    a += 1 

print(a)
a,b,c x = map(int, open(0))
print(sum( 500*i + 100*l + 50*k == x for i in range(a+1) for j in range(b+1) for k in range(c+1)))

### FIXED CODE ###

A = int(input())
B = int(input())
C = int(input())
X = int(input())
cnt = 0

for i in range(A+1):
  for j in range(B+1):
    for k in range(C+1):
      if 500*i + 100*j + 50*k == X:
        cnt +=1

print(cnt)
N = int(input())
INF = 10**10
cost = [[INF]*N for _ in range(N)]

for u in range(N):
    C = list(map(int, input().split()))
    for v in range(N):
        if u==v: # INFのままにする
            continue
        cost[u][u] = C[u]
 
ans = 0
for u in range(N):
    for v in range(j+1,N):
        mn = INF # u-w-vのような経路の中で最小の距離を求める
        for w in range(N):
            mn = min(mn, cost[u][w]+cost[w][v])    
        if (cost[u][v] > mn): # 与えられた行列が最短経路ではない
            print (-1)
            exit()
        elif (cost[u][v] < mn): # 等しくない場合はu-vを直接結ぶ橋が必要 
            ans += cost[u][v]                      
print (ans)

### FIXED CODE ###

import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
MOD = 10**9 + 7

N = int(input())
INF = 10**10
cost = [[INF]*N for _ in range(N)]

for i in range(N):
    C = list(map(int, input().split()))
    for j in range(N):
        cost[i][j] = C[j]
    cost[i][i] = INF

ans = 0
for j in range(N):
    for k in range(j+1,N):
        mn = INF
        for i in range(N):
            mn = min(mn, cost[j][i]+cost[i][k])    
        if (cost[j][k] > mn):
            print (-1)
            exit()
        elif (cost[j][k] < mn):
            ans += cost[j][k]                      
print (ans)
bun = inputs[0]
nub = list(reversed(bun))
n = int(len(bun) / 2)

i = hug = 0
while i < n:
    if bun[i] != nub[i]:
        hug += 1
    i += 1
print(hug)

### FIXED CODE ###

S = input()
RS = reversed(S)
n = int(len(S) / 2)

ans = 0
for c1, c2 in zip(S[:n], RS):
    if c1 != c2:
        ans += 1
print(ans)
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

from functools import lru_cache

MOD = 10**9 + 7

L = int(readline(),2)

@lru_cache(None)
def F(N):
    if N == 0:
        return 1
    if N == 1:
        return 3
    q,r = divmod(N,2)
    if r == 1:
        # (ev,ev): q, (ev,od): q, (od,ev): q
        return (3*F(q))%MOD
    else:
        # (ev,ev): q, (ev,od): q-1, (od,ev): q-1
        return (F(q) + 2*F(q-1))%MOD

answer = F(L)
print(answer)

### FIXED CODE ###

import sys
sys.setrecursionlimit(10**6)
MOD = 10**9 + 7

#上限指定がなければ0,0 or 0,1 or 1,0
pow_3 = [1]
for _ in range(2*10**5):
  pow_3.append((pow_3[-1]*3)%MOD)

def F(i):
  # i桁目以降をL[i:]以下で作る方法
  if i == L_size:
    return 1
  result = 0
  c = int(L[i])
  if c == 0:
    # 0,0ととるしかない
    result += F(i+1)
  else:
    # 0,1 あるいは 1,0 ととった場合
    result += 2*F(i+1)
    # 0,0ととった場合は、下の桁は自由
    result += pow_3[L_size - i - 1]
  result %= MOD
  return result



L = input()
L_size = len(L)

answer = F(0)
print(answer)
L = []
for i in range(k):
    y = x + i
    z = x - i
    if y > 1000000:
        y = x
    L.append(y)
    if z < -1000000:
        z = x
    L.append(z)
I = set(L)
for s in I:
    print(s,end = "")

### FIXED CODE ###


# ABC138
# B One Clue
# K個連続黒、Xが黒、座標-1000000+1000000
k, x = map(int, input().split())
L = []
for i in range(k):
    y = x + i
    z = x - i
    if y > 1000000:
        y = x
    L.append(y)
    if z < -1000000:
        z = x
    L.append(z)
I = set(L)
L = list(sorted(I))
for s in L:
    print(s,end = " ")
s = input()
s.sort()
if s[0] == s[1] and s[1] != s[2] and s[2] == s[3]:
  print('Yes')
else:
  print('No')

### FIXED CODE ###

s = input()
if s[0] == s[1] == s[2] == s[3]:
  print('No')
elif s[0] == s[1] and s[2] == s[3]:
  print('Yes')
elif s[0] == s[2] and s[1] == s[3]:
  print('Yes')
elif s[0] == s[3] and s[1] == s[2]:
  print('Yes')
else:
  print('No')
# -*- coding: utf-8 -*-

import sys

[a, b, c] = [0, 0, 0]

lineNumber = 0
#for line in [ "2", "1000", "800", "99999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999", "1" ]:
for line in sys.stdin.readlines():
    lineNumber += 1

    # line exception
    if lineNumber == 1:
        continue
    
    # get data
    List = map(int, line.strip().split())

    # set data
    if lineNumber % 2 == 0: a = List[0]
    else                  : b = List[0]

    # sum
    if lineNumber % 2 == 1:
        c = a + b
        if c < 10**79: print str(c)
        else         : print "overflow"

### FIXED CODE ###

for i in range(int(raw_input())):
    x = int(raw_input())
    y = int(raw_input())
    s = str(x+y)
    if len(s) > 80:
        print "overflow"
    else :
        print s
import sys
list_a = []
S = input()
T = input()
if T in S:
    print(0)
    sys.exit()
for i in range(len(S) - len(T)):
    cnt = 0
    for j in range(len(T)):
        if T[j] != S[i + j]:
            cnt += 1
    list_a.append(cnt)
print(min(list_a))

### FIXED CODE ###

S = input()
T = input()
list_a = []
if len(S) - len(T) ==0:
    cnt = 0
    for j in range(len(T)):
        if T[j] != S[j]:
            cnt += 1
    list_a.append(cnt)
else:
    for i in range(len(S) - len(T)):
        cnt = 0
        for j in range(len(T)):
            if T[j] != S[i + j]:
                cnt += 1
        list_a.append(cnt)
print(min(list_a))
N = int(input())
A = list(map(int, input().split()))

def up(i,pre):
    if i == len(A) - 1:
        return abs(A[pre] - A[i])
    res1 = res2 = 0 
    if i + 2 <=len(A) -1: 
        res1 = up(i + 1,i)
        res2 = up(i + 2,i)
        return min(abs(A[pre] - A[i]) + res1, abs(A[pre] - A[i]) + res2)
    elif  i + 1 <=len(A) -1: 
        res1 = up(i + 1,i)
        return abs(A[pre] - A[i]) + res1
  
if N>2:
    print(min(up(1,0),up(2,0)))
else:
    print(up(1,0))

### FIXED CODE ###

N = int(input())
A = list(map(int, input().split()))
dp = [0 for _ in range(len(A))]
dp[0] = 0 
for i in range(1,N):
    if i - 2>=0:
        dp[i] = min(dp[i-1] + abs(A[i] - A[i-1]),dp[i-2] + abs(A[i] - A[i-2]))
    else:
        dp[i] =dp[i-1] + abs(A[i] - A[i-1])

print(dp[len(A)-1])
a = raw_input()
b = raw_input()
a = list(a)
b = list(b)
n = len(a)
m = len(b)
z = ''
for i in range(n - m + 1):
	flag = True
	for j in range(m):
		if a[i + j] != b[j] and a[i + j] != '?':
			flag = False
	if not flag:
		continue
	c = a
	for j in range(m):
		c[i + j] = b[j]
	for i in range(n):
		if c[i] == '?':
			c[i] = 'a'
	if z == '':
		z = c
	else:
		z = min(z, c)
if z == '':
	print UNRESTORABLE
else:
	print ''.join(z)

### FIXED CODE ###

a = raw_input()
b = raw_input()
a = list(a)
b = list(b)
n = len(a)
m = len(b)
z = ''
for i in range(n - m + 1):
	flag = True
	for j in range(m):
		if a[i + j] != b[j] and a[i + j] != '?':
			flag = False
	if not flag:
		continue
	c = a[::]
	for j in range(m):
		c[i + j] = b[j]
	for i in range(n):
		if c[i] == '?':
			c[i] = 'a'
	if z == '':
		z = c
	else:
		z = min(z, c)
if z == '':
	print 'UNRESTORABLE'
else:
	print ''.join(z)
N = int(input())
A = list(map(int,input().split()))
B = set(sorted(A))
k = 1
a = 0
b = []
for i in B:
    j = A.index(i)
    if i != k:
        break
    a += j+1
    b.append(a)
    A = A[j+1:]
    if a == N:
        break
    k += 1
    
if b == []:
    print(-1)
else:
    print(N-len(b))

### FIXED CODE ###

N = int(input())
A = list(map(int,input().split()))
c = 0
for a in A:
    if a == c + 1:
        c = a
    
if c == 0:
    print(-1)
else:
    print(N-c)