Harryxun/stf_run huggingface dataset:
import time
start = time.time()
n = int(input())
a = [list(map(int,input().split())) for _ in range(n)]
s = [0 for i in range(n)] #それぞれ何試合目か
ans = 0
need = n*(n-1)//2
while need:
    c = [0 for i in range(n)] #今日試合をするかどうか
    ans += 1
    for first in range(n):
        if c[first] == 0 and s[first] < n-1:
            second = a[first][s[first]]-1 # firstが対戦したい相手
            second_num = s[second] # #secondの対戦番号
            if c[second] == 0 and a[second][second_num]-1 == first:
                c[first] = 1
                c[second] = 1
                s[first] += 1
                s[second] += 1
                need -= 1
    if sum(c) == 0:
        print(-1)
        exit()
    now = time.time()-start
    if now > 1.83:
        print(n*(n-1)//2)
        exit()
print(ans)

### FIXED CODE ###

s = input()
t = input()
ans = 0
for i in range(3):
    if s[i] == t[i]:
        ans += 1

print(ans)
x=int(input())
l=[]
for x in map(int,input().split()):
    l.append(x)
z=len(l)-1
suml=0
h=[]
while(z>0):
    if(z==len(l)-1):
        h.append(0)
        if(l[z]<=l[z-1]):
            suml+=1
    elif(l[z]<=l[z-1]):
        suml+=1
    else:
        h.append(suml)
        suml=0
    z-=1
print(max(h))        



### FIXED CODE ###

x=int(input())
l=[]
s=x
for x in map(int,input().split()):
    l.append(x)
if(s==1):
    print(0)
    exit()    
z=0
suml=0
h=[]
while(z<s-1):
    if(l[z]>=l[z+1]):
        suml+=1
    elif(l[z]>=l[z+1]):
        suml+=1
    else:
        h.append(suml)
        suml=0    
    z+=1
    if(z==s-1):
        h.append(suml)
print(max(h))
def bin_tree( pri , li_pri , len_li ):
    #pri: どこに入れていいかわからない値段
    #li_pri: 値段のリスト(昇順)
    #len_li: リストの長さ
    lo = 0
    hi = len_li - 1
    while hi - lo > 1:
        mid = lo + (hi - lo) // 2
        guess = li_pri[mid]
        if guess >= pri:
            hi = mid
        else:
            lo = mid
    return lo

I = input().split()
N = int(I[0])
M = int(I[1])
# N: 品物の数
# M: 割引券の数
# A: 品物の値段行列
A = list(map(int , input().split()))
A.sort()

print(A)

while M > 0:
    M -= 1
    pri = A.pop( N - 1 )
    pri = pri // 2
    if ( pri < A[0] ):
        ans = 0
    else:
        ans = bin_tree( pri , A , N - 1 )
    A[ans:ans] = [pri]

    print(A)
    

F_pri = 0
for i in range(N):
    F_pri += A[i]
print(F_pri)

### FIXED CODE ###

def bin_tree( pri , li_pri , len_li ):
    #pri: どこに入れていいかわからない値段
    #li_pri: 値段のリスト(昇順)
    #len_li: リストの長さ
    lo = 0
    hi = len_li - 1
    while hi - lo > 1:
        mid = lo + (hi - lo) // 2
        guess = li_pri[mid]
        if guess >= pri:
            hi = mid
        else:
            lo = mid
    return lo

I = input().split()
N = int(I[0])
M = int(I[1])
# N: 品物の数
# M: 割引券の数
# A: 品物の値段行列
A = list(map(int , input().split()))
A.sort()

while M > 0:
    M -= 1
    pri = A.pop( N - 1 )
    pri = pri // 2
    if len(A) == 0:
        ans = 0
    elif (pri < A[0] ):
        ans = 0
    else:
        ans = bin_tree( pri , A , N - 1 ) + 1
    # ans: pri以上となる値段のうち最小のインデックス
    A[ans:ans] = [pri]    

F_pri = 0
for i in range(N):
    F_pri += A[i]
print(F_pri)
from sys import stdin

N = int(stdin.readline().rstrip())
data = [stdin.readline().rstrip().split() for _ in range(N)]

profit = []
sum_profit = 0

for i in N:
    profit[i] = data[0][i] - data[1][i]
    if profit[i] > 0:
        sum_profit += profit[i]

print(sum_profit)

### FIXED CODE ###

from sys import stdin

N = int(stdin.readline().rstrip())
data = [stdin.readline().rstrip().split() for _ in range(2)]

profit = [0] * N
sum_profit = 0

for i in range(N):
    profit[i] = int(data[0][i]) - int(data[1][i])
    if profit[i] > 0:
        sum_profit += profit[i]

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

p = [list(map(int,input().split())) for i in range n]

kyori = d * d
count = 0

for s in range(n):
  nagasa = p[s][0] * p[s][0] + p[s][1] * p[s][1]
  if nagasa <= kyori:
    count += 1
    
print(count)

### FIXED CODE ###

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

p = [list(map(int,input().split())) for i in range(n)]

kyori = d * d
count = 0

for s in range(n):
  nagasa = p[s][0] * p[s][0] + p[s][1] * p[s][1]
  if nagasa <= kyori:
    count += 1
    
print(count)
s = int(input())
list = [int(n) for n in input().split()]

s_l = sorted(list)
print(s_l[s//2] - s_l[s//2 - 1])


### FIXED CODE ###

def f_f(str):
    for s in str:
        if str.count(s) != 2:
            return False
    return True
 
S = input()
if f_f(S):
    print("Yes")
else:
    print("No")
x = int(raw_input("Enter number:"))
print )int(x**3

### FIXED CODE ###

print ((int(raw_input()))**3)
n=int(input())
p=[]
[p.append(int(input())) for i in range(n)]
print(sum(p)-max(p)//2)

### FIXED CODE ###

s=int(input())
if (s==25):
  print('Christmas')
elif (s==24):
  print('Christmas Eve')
elif (s==23):
  print('Christmas Eve Eve')
elif (s==22):
  print('Christmas Eve Eve Eve')
n=int(intput())
cake=4
donuts=7
flag=False
for i in range(n+1):
    if i%4==0:
        flag=True
        break
    elif (n-i)%7==0:
        flag=True
        break
print("Yes" if flag else "No")

### FIXED CODE ###

n=int(input())
cake=n//4
donuts=n//7
flag=False
for i in range(cake+1):
    for j in range(donuts+1):
        s=i*4+j*7
        if s==n:
            flag=True
            break
print("Yes" if flag else "No")
N = int(input())
print(1000 - N%1000 if N%1000!=0 else 0)a

### FIXED CODE ###

N = int(input())
print(1000 - N%1000 if N%1000!=0 else 0)
# -*- coding: utf-8 -*-
import sys
from collections import defaultdict,deque
from heapq import heappush,heappop,heapify

N=input()
AL=defaultdict(lambda: set())
IN=defaultdict(lambda: 0)
BEGIN=set()

for i in range(N):
	A=map(int, sys.stdin.readline().split())
	for j in range(N-2):
		x=i+1
		x_next=i+1
		y=A[j]
		y_next=A[j+1]
		#print x,y,x_next,y_next
		if x>y: x,y=y,x
		if x_next>y_next: x_next,y_next=y_next,x_next
		IN[(x_next,y_next)]+=1
		AL[(x,y)].add((x_next,y_next))

		if j==0:
			BEGIN.add((x,y))

hq=[]

for x,y in BEGIN:
	if IN[(x,y)]==0:
		heappush(hq, (1,x,y))


DAY=defaultdict(lambda: 1)	#距離

ans=-1
while hq:
	cost,fro_x,fro_y=heappop(hq)
	fro=(fro_x,fro_y)
	for to in AL[fro]:
		IN[to]-=1
		alt=DAY[fro]+1
		if DAY[to]<alt and IN[to]==0:
			ans=max(ans,alt)
			DAY[to]=alt
			heappush(hq,(alt,to[0],to[1]))

print ans

### FIXED CODE ###

# -*- coding: utf-8 -*-
from collections import defaultdict
N=input()
s=raw_input()

str="abcdefghijklmnopqrstuvwxyz"
D={}
for i,str in enumerate(str):
	D[str]=i+1

base=27
mod=2**61-1
hash=[]

for i,x in enumerate(s):
	if i==0: hash.append(D[x]%mod)
	else: hash.append( (hash[-1]*base+D[x])%mod )

def get(l,r):
	if l==0: return hash[r-1]%mod
	else: return ( hash[r-1]-hash[l-1]*pow(base,(r-l),mod) )%mod

# 長さmを固定し、区間 [i, i + m) のハッシュ値を求めて、長さmの共通文字列があるかを判定
def check(m):
	C={}
	for i in range(N):
		if i+m<=N:
			hash_value=get(i,i+m)
			if hash_value in C:
				if m<=i-C[hash_value]:
					return True
			else:
				C[hash_value]=i
	else:
		return False

l=0
h=N

while 1<(h-l):
	m=(l+h)/2
	if check(m):
		l=m
	else:
		h=m

print l
import sys

T = stdin.readline().rstrip()
X = stdin.readline().rstrip()

print(float(T)/float(X))

### FIXED CODE ###

T,X =map(int, input().split())
print(float(T)/float(X))
n=int(input())
edges=[[] for i in range(n)]
import sys

sys.setrecursionlimit(10**10)
for i in range(n-1):
    a,s,w=map(int,input().split())
    edges[a-1].append([s-1,w]);edges[s-1].append([a-1,w])
colors=[-1]*n
colors[0]=1
def dfs(now):
    for to,cost in edges[now]:
        if colors[to]==-1:
            colors[to]=(cost+colors[now])%2
            dfs(to)

dfs(0)
print(*colors,sep="\n")

### FIXED CODE ###

n=int(input())
edges=[[] for i in range(n)]
import sys

sys.setrecursionlimit(10**9)
for i in range(n-1):
    a,s,w=map(int,input().split())
    edges[a-1].append([s-1,w]);edges[s-1].append([a-1,w])
colors=[-1]*n
colors[0]=1
def dfs(now):
    for to,cost in edges[now]:
        if colors[to]==-1:
            colors[to]=(cost+colors[now])%2
            dfs(to)

dfs(0)
print(*colors,sep="\n")
k = int(input())

def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr

pn=factorization(k)

go =0
keta = len(str(k))
sevens = []

if k % 2 == 0 or k %5 == 0:
    print(-1)
    break
elif str(k)[-1] == "3":
    for i in range(9,10**100000,10):
        if not str(k * i).count('7') == len(str(k*i)):
            continue
        else:
            print(str(k * i).count('7'))
elif str(k)[-1] == "7":
    for i in range(1,10**100000,10):
        if not str(k * i).count('7') == len(str(k*i)):
            continue
        else:
            print(str(k * i).count('7'))
elif str(k)[-1] == "9":
    for i in range(3,10**100000,10):
        if not str(k * i).count('7') == len(str(k*i)):
            continue
        else:
            print(str(k * i).count('7'))
elif str(k)[-1] == "1":
    for i in range(7,10**100000,10):
        if not str(k * i).count('7') == len(str(k*i)):
            continue
        else:
            print(str(k * i).count('7'))



### FIXED CODE ###

k = int(input())

go = 0
keta = len(str(k))

for i  in range(10**1000000):
    if k % 2 ==0:
        print(-1)
        break
    if k % 5==0:
        print(-1)
        break
    else:
        go =(go*10+7) %k
        if go ==0:
            print(i+1)
            break
import scipy.misc as scm
def combi(p,q):
    return scm.comb(p,q,1)

ans=0
n=int(input())
k=[]
for i in range(n):
    a,b=map(int,input().split())
    k.append([a,b])

for i in range(n-1):
    for j in range(i+1,n):
        p=k[i][0]+k[i][1]+k[j][0]+k[j][1]
        q=k[i][0]+k[j][0]
        ans += combi(p,q) % (10**9+7)


ans = ans % (10**9+7)
print(ans)


### FIXED CODE ###

n=int(input())
a=list(map(int,input().split()))
b=sorted(a)
ans=0
for i in range(0,n*2,2):
    ans += min(b[i],b[i+1])
print(ans)
x, y = int(map, input().split())

if(2*x <= y <= 4*x):
    print("Yes")
else:
    print("No")

### FIXED CODE ###

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

if(2*x <= y <= 4*x and y%2==0 and x <= 50):
    print("Yes")
else:
    print("No")
n, m = map(int, input().split())
n_l = []
ans = [0, 0, 0]

for _ in range(n):
    l = list(map(int, input().split()))
    n_l.append(l)
for x in range(m):
    p = int(input())
    n_l[:,0] * p
for i in n_l:
    print(sum(i))


### FIXED CODE ###

n, m = map(int, input().split())
n_l = []
ans = [0, 0, 0]

for _ in range(n):
    l = list(map(int, input().split()))
    n_l.append(l)
for x in range(m):
    p = int(input())
    for o in range(n):
        n_l[o][x] *= p
for i in n_l:
    print(sum(i))
N = int(input())

A = list(map(int), input().split())
if N % 2 == 0:
    print(sum(map(abs, A)))
else:
    print(sum(map(abs, A)) - 2 * max([a for a in A if a <= 0]))

### FIXED CODE ###

N = int(input())
A = list(map(int, input().split()))
neg = [a for a in A if a < 0]
A = list(map(abs, A))

if len(neg) % 2 == 0:
    print(sum(A))
else:
    print(sum(A) - 2 * min(A))
x,y=map(int, input().split())
while !(x ==0 and y==0) :
 if x < y : print(x, y)
 else : print(y, x)

### FIXED CODE ###

x, y = map(int, input().split())
while not( x == 0 and y == 0 ):
 if x < y : print(x, y)
 else : print(y, x)
 x, y = map(int, input().split())
a=int(input())
b=int(input())
c=int(input())
if(a+b>c) print("Yes")
else print("No")

### FIXED CODE ###

a, b, c = map(int, input().split())
if(a+b>=c):
  print("Yes")
else:
  print("No")
N, M = map(int, input().split())
M2 += N*2
print(min(M2//4, M//2))

### FIXED CODE ###

N, M = map(int, input().split())
M2 = M + N*2
print(min(M2//4, M//2))
n,k=map(int,input().split())
x=list(map(int,input().split()))
a=[x[i] for i in range(n) if x[i]<0]
b=[x[i] for i in range(n) if x[i]>=0]
na=len(a)
nb=len(b)
if b[0]==0:
    k-=1
    b=[x[i] for i in range(n) if x[i]>0]
    nb=nb-1
if k==0:
    print(0)
    exit()


ans=10**10
if na>=k and na!=0:
    ans=-a[-k]
if nb==0:
    print(-a[-k])
    exit()
if na==0:
    print(b[k-1])
    exit()

for i in range(1,nb+1):
    m=k-i
    if m>na or m<0:
        continue
    elif 0<m<=na:
        ans=min(ans,min(b[i-1]-2*a[-m],2*b[i-1]-a[-m]))
    elif m==0:
        ans=min(ans,b[k-1])
print(ans if k!=0 else 0)


### FIXED CODE ###

n,k=map(int,input().split())
x=list(map(int,input().split()))
a=[x[i] for i in range(n) if x[i]<0]
b=[x[i] for i in range(n) if x[i]>=0]
na=len(a)
nb=len(b)
if 0 in x:
    k-=1
    b=[x[i] for i in range(n) if x[i]>0]
    nb=nb-1

if k==0:
    print(0)
    exit()
ans=10**10
if na>=k:
    ans=-a[-k]

if nb>=k:
    ans=min(ans,b[k-1])

if nb==0:
    print(-a[-k])
    exit()

if na==0:
    print(b[k-1])
    exit()

for i in range(1,nb+1):
    m=k-i
    if m>na or m<0:
        continue
    elif 0<m<=na:
        ans=min(ans,min(b[i-1]-2*a[-m],2*b[i-1]-a[-m]))
    elif m==0:
        ans=min(ans,b[k-1])
print(ans if k!=0 else 0)
def list_pos(cnt,a,b,ans):
    if ans  >= b :
        return cnt-1
    else :

        ans += a[cnt][1]
        cnt += 1
        return list_pos(cnt,a,b,ans)
import sys
sys.setrecursionlimit(10000)
N,K = map(int,input().split())
para = {}
for i in range(N):
    a,b  = map(int,input().split())
    if not a in para.keys():
        para[a] = b
    else : para[a] += b

para = sorted(para.items(),key =lambda x:x[0])

p = list_pos(0,para,K,0)
print("{}".format(para[p][0]))


### FIXED CODE ###


def list_pos(cnt,a,b,ans):
    if ans  >= b :
        return cnt-1
    else :

        ans += a[cnt][1]
        cnt += 1
        return list_pos(cnt,a,b,ans)
import sys
sys.setrecursionlimit(100000)
N,K = map(int,input().split())
para = {}
for i in range(N):
    a,b  = map(int,input().split())
    if not a in para.keys():
        para[a] = b
    else : para[a] += b

para = sorted(para.items(),key =lambda x:x[0])

p = list_pos(0,para,K,0)
print("{}".format(para[p][0]))
import sys
from collections import defaultdict
import numpy as np

sys.setrecursionlimit(10 ** 6)
INF = float("inf")
MOD = 10 ** 9 + 7


def input():
    return sys.stdin.readline().strip()


def main():
    N, W = map(int, input().split())
    d = defaultdict(list)
    w, v = map(int, input().split())
    w1 = w
    d[w].append(v)
    for _ in range(1, N):
        w, v = map(int, input().split())
        d[w].append(v)

    cumsum = dict()
    L = dict()
    for i in range(4):
        w = w1 + i
        d[w].sort(reverse=True)
        c = np.cumsum(d[w])
        cumsum[w] = c
        L[i] = len(d[w])

    ans = 0
    for i in range(L[0] + 1):
        if i != 0:
            v1 = cumsum[w1][i - 1]
        else:
            v1 = 0
        for j in range(L[1] + 1):
            if j != 0:
                v2 = v1 + cumsum[w1 + 1][j - 1]
            else:
                v2 = v1
            for k in range(L[2] + 1):
                if k != 0:
                    v3 = v2 + cumsum[w1 + 2][k - 1]
                else:
                    v3 = v2
                for l in range(L[3] + 1):
                    w = w1 * i + (w1 + 1) * j + (w1 + 2) * k + (w1 + 3) * l
                    if w > W:
                        continue

                    if l != 0:
                        v4 = v3 + cumsum[w1 + 3][l - 1]
                    else:
                        v4 = v3

                    if v4 > ans:
                        ans = v4

    print(ans)


if __name__ == "__main__":
    main()


### FIXED CODE ###

import sys
from collections import defaultdict
import numpy as np

sys.setrecursionlimit(10 ** 6)
INF = float("inf")
MOD = 10 ** 9 + 7


def input():
    return sys.stdin.readline().strip()


def main():
    N, W = map(int, input().split())
    d = defaultdict(list)
    w, v = map(int, input().split())
    w1 = w
    d[w].append(v)
    for _ in range(1, N):
        w, v = map(int, input().split())
        d[w].append(v)

    cumsum = dict()
    L = defaultdict(int)
    for i in range(4):
        w = w1 + i
        d[w].sort(reverse=True)
        c = np.cumsum(d[w])
        cumsum[w] = c
        L[i] = len(d[w])

    ans = 0
    for i in range(L[0] + 1):
        if i != 0:
            v1 = cumsum[w1][i - 1]
        else:
            v1 = 0
        for j in range(L[1] + 1):
            if j != 0:
                v2 = v1 + cumsum[w1 + 1][j - 1]
            else:
                v2 = v1
            for k in range(L[2] + 1):
                if k != 0:
                    v3 = v2 + cumsum[w1 + 2][k - 1]
                else:
                    v3 = v2
                for l in range(L[3] + 1):
                    w = w1 * i + (w1 + 1) * j + (w1 + 2) * k + (w1 + 3) * l
                    if w > W:
                        continue

                    if l != 0:
                        v4 = v3 + cumsum[w1 + 3][l - 1]
                    else:
                        v4 = v3

                    if v4 > ans:
                        ans = v4

    print(ans)


if __name__ == "__main__":
    main()
import fractions
import collections
import copy

n = int(input())
ai = [int(i) for i in input().split()]

num = 10**3

mod = 10**9+7

if n == 1:
    print(1)
    exit()

def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a

pri_li = []

for i in range(n):
    pri_li.append(collections.Counter(prime_factorize(ai[i])))

com_ab = [0]*(num)

sosu_li = [[i,0] for i in range(10**6+1)]

kosu = 0

for i in range(n):
    #print(len(b_li[i]))
    keys = pri_li[i].keys()
    #print(keys)
    for j in keys:
        #print(sosu_li)
        if sosu_li[j][1] == 0:
            sosu_li[j][1] = 1
            kosu += 1
        com_ab[j] = max(com_ab[j],pri_li[i][j])

sosu_li.sort(reverse=True,key=lambda x: x[1])

"""
for i in range(10**3):
    if com_ab[i] > 0:
        com_num *= pow(i,com_ab[i],mod)
"""
ans = 0

for i in range(n):
    com_ab_new = copy.deepcopy(com_ab)
    #print(com_ab,com_ab_new)
    keys = pri_li[i].keys()
    for j in keys:
        com_ab_new[j] -= pri_li[i][j]
    kari = 1
    for j in range(kosu):
        kari *= pow(sosu_li[j][0],com_ab_new[sosu_li[j][0]],mod)
    ans += kari
    ans %= mod
    #print(ans)
        
print(ans)


### FIXED CODE ###

import collections
import math
n = int(input())
ai = [int(i) for i in input().split()]

mod = 10**9+7

if n == 1:
    print(1)
    exit()
    
    
# 素因数分解、辞書で返すやつ
# mathをimportする
def prime(n):
    factor = {}
    tmp = int(math.sqrt(n)) + 1
    for num in range(2, tmp):
        while n % num == 0:
            n //= num
            if not num in factor.keys():
                factor[num] = 1
            else:
                factor[num] += 1
        if num > n:
            break
    if n != 1:
        if not n in factor.keys():
            factor[n] = 1
        else:
            factor[n] += 1
    return factor


dic = {}
for a in ai:
    pr = prime(a)
    for num, count in pr.items():
        if not num in dic.keys():
            dic[num] = count
        else:
            if dic[num] < count:
                dic[num] = count

kari = 1
for num,count in dic.items():
    kari *= pow(num,count,mod)
    kari %= mod

kari_old = kari
ans = 0

for i in range(n):
    kari = kari_old
    #com_ab_new = copy.deepcopy(com_ab)
    #print(com_ab,com_ab_new)
    #kari = 1
    #for j in range(kosu):
    #kari *= pow(sosu_li[j][0],com_ab[sosu_li[j][0]],mod)
    kari *= pow(ai[i],mod-2,mod)
    ans += kari
    ans %= mod
    #print(ans)
    #print(ans)
        
print(ans)
A = int(input())
B = int(input())
if A == B:
  print("YES")
else:
  print("NO")

### FIXED CODE ###

N,M = map(int, input().split())
 
if N == M:
  print("Yes")
else:
  print("No")
import math

n = int(input())
ratio = [list(map(int, input().split())) for i in range(n)]

k = 1
for i in range(n-1):
  k1 = math.ceil(ratio[i][0] * k / ratio[i+1][0])
  k2 = math.ceil(ratio[i][1] * k / ratio[i+1][1])
  k3 = math.ceil(sum(ratio[i]) * k / sum(ratio[i+1])
  k = max(k1, k2, k3)

print(sum(ratio[n-1]) * k)

### FIXED CODE ###

import math

def quot(p, q):
  return p // q + (p % q != 0)

n = int(input())
ratio = [list(map(int, input().split())) for i in range(n)]

k = 1
for i in range(n-1):
  k1 = quot(ratio[i][0] * k , ratio[i+1][0])
  k2 = quot(ratio[i][1] * k , ratio[i+1][1])
  k = max(k1, k2)

print(sum(ratio[n-1]) * k)
a, b=map(int,raw_input().split())
if a > b:
   print "a > b"
if a < b:
   print "a < b"
if a = b:
   print "a == b"
   

### FIXED CODE ###

a,b = map(int, raw_input().split())
if a > b:
  print 'a > b'
elif (a == b):
  print 'a == b'
else:
  print 'a < b'
K,N=map(int,input().split())
A=[int(s) for s in input().split(" ")]

Smax=0
for i in range(K):
    S=0
    if i==0:
        S=max(abs(A[0]-A[-1]),abs(A[0]-A[1]))
    elif i==K-1:
        S=max(abs(A[-1]-A[0]),abs(A[-1]-A[-2]))
    else:
        S=max(abs(A[i]-A[i+1]),abs(A[i]-A[i-1]))
    if Smax<S:
        Smax=S

print(K-Smax)

### FIXED CODE ###

K,N=map(int,input().split())
A=[int(s) for s in input().split(" ")]

Smax=0
for i in range(N):
    S=0
    if i!=N-1:
        if A[i+1]>A[i]:
            S=A[i+1]-A[i]
        else:
            S=A[i]-A[i+1]
    else: 
        if A[0]>A[-1]:
            S=A[0]-A[-1]
        else:
            S=A[-1]-A[0]
    
    if S>K/2:
        S=K-S
    if Smax<S:
        Smax=S

print(K-Smax)
import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)

K = int(input())
S = str(input())
mod = 10**9+7
lens = len(S)
length = lens+K

L = 1
pow_dic = {}
pow_dic[0] = 1
for i in range(1, 10**6+1000):
    L = L*i%mod
    pow_dic[i] = L
ans = 0
for rest in range(K+1):
    lenall = length-rest-1
    nlens = lens-1
    l = pow_dic[lenall]*pow(pow_dic[lenall-nlens], mod-2, mod)%mod
    r = pow_dic[nlens]
    comb = l*pow(r, mod-2, mod)%mod
    ans += pow(25, K-rest, mod)*pow(26, rest, mod)*comb%mod
    ans %= mod
print(ans%mod)

### FIXED CODE ###

import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)

K = int(input())
S = str(input())
mod = 10**9+7
lens = len(S)
length = lens+K

L = 1
pow_dic = [0]*(10**6*2+1)
pow_dic[0] = 1
for i in range(1, 10**6*2+1):
    L = L*i%mod
    pow_dic[i] = L%mod
ans = 0
for rest in range(K+1):
    lenall = length-rest-1
    nlens = lens-1
    l = pow_dic[lenall]*pow(pow_dic[lenall-nlens], mod-2, mod)%mod
    r = pow_dic[nlens]
    comb = l*pow(r, mod-2, mod)%mod
    ans += pow(25, K-rest, mod)*pow(26, rest, mod)*comb%mod
    ans %= mod
print(ans%mod)
def main(S_,T):

    for i in range(len(S_)-len(T)+1):
        cnt = 0
        idx = -1
        for j in range(len(T)):
            if(S_[i+j]==T[j] or S_[i+j]=="?"):
                cnt += 1
                if cnt == len(T):
                    idx = i+j-len(T)+1
                else:
                    continue
            else:
                break
                
    if idx == -1:
        print("UNRESTORABLE")
    else:
        for i in range(len(T)):
            S_[idx+i] = T[i]
        for i in range(len(S_)):
            if S_[i] == "?":
                S_[i] = "a"
        print("".join(S_))

if __name__ == '__main__':
    S_ = list(input())
    T = list(input())
    main(S_,T)

### FIXED CODE ###

# -*- coding: utf-8 -*-

def main(S_,T):
    for i in range(len(S_)-len(T)+1):
        for j in range(len(T)):
            if S_[i+j]!="?" and T[j]!=S_[i+j]:break
        else:
            print(''.join(list(reversed((S_[:i]+T+S_[i+j+1:]).replace("?","a")))))
            exit()
    print("UNRESTORABLE")

if __name__ == '__main__':
    S_ = "".join(list(reversed(input())))
    T = "".join(list(reversed(input())))
    main(S_,T)