Harryxun/stf_run huggingface dataset:
#幅優先探索


from queue import Queue

ans = 0
h,w = map(int, input().split())
maps = [input() for _ in range(h)]
for i in range(h):
    for j in range(w):
        if maps[i][j] == '.':
            visited = [[-1]*w for _ in range(h)]
            q = Queue()
            q.put([i,j])
            visited[i][j] = 0
            while not q.empty():
                y,x = q.get()
                for k,l in [[1,0],[-1,0],[0,1],[0,-1]]:
                    if 0 <= y+k < h and 0<= x+l < w:
                        new_y,new_x = y+k,x+l
                    else: continue
                    if visited[new_y][new_x]== -1 and maps[new_y][new_x]==".":
                        visited[new_y][new_x]=visited[y][x]+1
                        q.put([new_y,new_x])
                    elif visited[new_y][new_x] > visited[y][x]+1:
                        visited[new_y][new_x]=visited[y][x]+1
                        q.put([new_y,new_x])
          
         
    for ii in range(h):
        for jj in range(w):
            ans = max(ans,visited[ii][jj])
        
print(ans)





### FIXED CODE ###

#幅優先探索


from queue import Queue

ans = 0
h,w = map(int, input().split())
maps = [input() for _ in range(h)]
for i in range(h):
    for j in range(w):
        if maps[i][j] == '.':
            visited = [[-1]*w for _ in range(h)]
            q = Queue()
            q.put([i,j])
            visited[i][j] = 0
            while not q.empty():
                y,x = q.get()
                for k,l in [[1,0],[-1,0],[0,1],[0,-1]]:
                    if 0 <= y+k < h and 0<= x+l < w:
                        new_y,new_x = y+k,x+l
                    else: continue
                    if visited[new_y][new_x]== -1 and maps[new_y][new_x]==".":
                        visited[new_y][new_x]=visited[y][x]+1
                        q.put([new_y,new_x])
   
          
        
            for ii in range(h):
                for jj in range(w):
                    ans = max(ans,visited[ii][jj])


print(ans)
N,M=map(int,input().split())
S=input()
T=input()
import math
gcd=int(N*M/math.gcd(N,M))
lis=[int(gcd/N),int(gcd/M)]
for i in range(int(N*M/gcd)):
    if S[int(i*lis[1])]!=T[int(i*lis[0])]:
        print(-1)
        exit()
print(gcd)

### FIXED CODE ###

N,M=map(int,input().split())
S=input()
T=input()
import fractions
gcd=int(N*M/fractions.gcd(N,M))
lis=[int(gcd/N),int(gcd/M)]
for i in range(int(N*M/gcd)):
    if S[int(i*lis[1])]!=T[int(i*lis[0])]:
        print(-1)
        exit()
print(gcd)
N,M,X=(int(i) for i in input().split())
L=[int(input()) for i in range(M)]
a=0
b=0
for i in range(M):
  if L[i]<X:
    a+=1
  else:
    b+=1
print(min(a,b))


### FIXED CODE ###

N,M,X=(int(i) for i in input().split())
L=[int(i) for i in input().split()]
a=0
b=0
for i in range(M):
  if L[i]<X:
    a+=1
  else:
    b+=1
print(min(a,b))
from collections import defaultdict as dd
import sys
sys.setrecursionlimit(6000)
N, M, P = map(int, input().split())
edges = []
edgedict = dd(dict)
for _ in range(M):
  f, t, c = map(int, input().split())
  edges.append((f-1, t-1, -(c-P)))
  edgedict[f-1][t-1] = 1

# Nに到達できない頂点を削除
visited = [False] * N
unreach = set()
def dfs(f):
  visited[f] = True
  for t in edgedict[f].keys():
    if t == N-1:
      return True
    ret = False
    if not visited[t]:
      ret = ret or dfs(t)
  if not ret:
    unreach.add(f)
  return ret
dfs(0)

# ベルマンフォード
INF = float('inf')
d = [float('inf')] * N
d[0] = 0
for i in range(M):
  updated = False
  for f, t, c in edges:
    if d[f] != INF and t not in unreach and d[t] > d[f] + c:
      d[t] = d[f] + c
      updated = True
  if not updated:
    break
else:
  print(-1)
  exit()
print(max(-d[-1], 0))

### FIXED CODE ###

from collections import defaultdict as dd
import sys
sys.setrecursionlimit(6000)
N, M, P = map(int, input().split())
edges = []
revedgedict = dd(dict)
for _ in range(M):
  f, t, c = map(int, input().split())
  edges.append((f-1, t-1, -(c-P)))
  revedgedict[t-1][f-1] = 1

# Nに到達できない頂点を削除
visited = [False] * N
def dfs(f):
  visited[f] = True
  for t in revedgedict[f].keys():
    if not visited[t]:
      dfs(t)
dfs(N-1)

# ベルマンフォード
INF = float('inf')
d = [float('inf')] * N
d[0] = 0
for i in range(N):
  updated = False
  for f, t, c in edges:
    if d[f] != INF and visited[t] and d[t] > d[f] + c:
      d[t] = d[f] + c
      updated = True
  if not updated:
    break
else:
  print(-1)
  exit()
print(max(-d[-1], 0))
N = int(input())
words = [input() for i in range(N)]
ans = "Yes"
tmp = list(dict.fromkeys(words))
if words == tmp:
    for j in range(1,N):
        if words[j][0] != word[j-1][-1]:
            ans = "No"
            break
    print(ans)
else:
    print("No")

### FIXED CODE ###

N = int(input())
W = [input() for i in range(N)]
ans = "Yes"
if sorted(set(W)) != sorted(W):
    ans = "No"
else:
    for i in range(N-1):
        if W[i][-1] != W[i+1][0]:
            ans = "No"
            break
print(ans)
x, a, b = map(int, input().split())
if abs(x-a) < abs(x-b):
  print(A)
else:
  print(B)

### FIXED CODE ###

x, a, b = map(int, input().split())
if abs(x-a) < abs(x-b):
  print('A')
else:
  print('B')
import sys
n, m = map(int,input().split())

if n >= m:
  print(0)
  sys.exit()
  
x = sorted(list(map(int,input().split())))
print(sum([x[i+1]-x[i] for i in range(len(x)-1)].sort(reverse = True)[n-1:]))


### FIXED CODE ###

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

if n >= m:
  print(0)
  sys.exit()
  
x = list(map(int,input().split()))
x.sort()
between = [x[i+1]-x[i] for i in range(len(x)-1)]
between.sort(reverse = True)
print(sum(between[n-1:]))
h, w = list(map(int, input().split()))
maps = [list(input()) for i in range(h)]

def search(i, j):
  for dh, dw in [[1, 0], [-1, 0], [0, 1], [0, -1]]:
    x = max(0, min(i + dw, w-1))
    y = max(0, min(j + dh, h-1))
    if i == y and j == x: continue 
    if maps[x][y] == "#":
      return True
  return False

flag = True
for i in range(h):
  for j in range(w):
    if maps[i][j] == "#" and not search(i, j):
        flag = False
        break
        
print("Yes" if flag else "No")

### FIXED CODE ###

import numpy as np
h, w = list(map(int, input().split()))
s = np.array([list(input()) for i in range(h)])

infer = []
for i in range(h):
  for j in range(w):
    if s[i][j] == "#":
      pts = set([
        (max(0, i-1), j), 
        (i, max(0, j-1)), 
        (min(h-1, i+1), j), 
        (i, min(w-1, j+1))
      ])
      check = np.array([ s[ix][iy] for ix, iy in list(pts - set([(i, j)])) ])
      infer.append((check == "#").sum())

print("No" if 0 in infer else "Yes")
from collections import  deque
import sys
import bisect
import math
import itertools
from queue import deque
from math import gcd

INF = float('inf')
mod = 10**9+7
eps = 10**-7

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

def lcm(x, y): return (x * y) // gcd(x, y)

N = inp()
A = [0 for _ in range(N)]
xx = [[] for _ in range(N)]
yy = [[] for _ in range(N)]

for i in range(N):
    A[i] = inp()
    for _ in range(A[i]):
        x, y = inp_list()
        xx[i].append(x)
        yy[i].append(y)

# ↑ inputs
# ↓ main process

honest_count = 0
# {0, 1, ..., N-1} の集合の bit 全探索
ans = 0
for bit in range(1 << N):
    """
        例： bit == 10 のとき、2進数では 001010 
            右から人 1, 2, ..., 6 と対応させる。
    """
    ok = True
    is_honest = [(bit >> i) & 1 for i in range(N)] # bit を 1 右にシフトさせたものの2^0の位が1なら True
    for i in range(N):
        if not is_honest[i]: continue
        for (x, y) in zip(xx[i], yy[i]):
            if is_honest[x - 1] != y:
                ok = False
    if ok:
        ans = max(ans, sum(is_honest))
print(ans)


### FIXED CODE ###

from collections import  deque
import sys
import bisect
# import math
import itertools
from queue import deque
# from math import gcd

INF = float('inf')
mod = 10**9+7
eps = 10**-7

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

# def lcm(x, y): return (x * y) // gcd(x, y)

N = inp()
A = [0 for _ in range(N)]
xx = [[] for _ in range(N)]
yy = [[] for _ in range(N)]

for i in range(N):
    A[i] = inp()
    for _ in range(A[i]):
        x, y = inp_list()
        xx[i].append(x)
        yy[i].append(y)

# ↑ inputs
# ↓ main process

honest_count = 0
# {0, 1, ..., N-1} の集合の bit 全探索
ans = 0
for bit in range(1 << N):
    """
        例： bit == 10 のとき、2進数では 001010 
            右から人 1, 2, ..., 6 と対応させる。
    """
    ok = True
    is_honest = [(bit >> i) & 1 for i in range(N)] # bit を 1 右にシフトさせたものの2^0の位が1なら True
    for i in range(N):
        if not is_honest[i]: continue
        for (x, y) in zip(xx[i], yy[i]):
            if is_honest[x - 1] != y:
                ok = False
    if ok:
        ans = max(ans, sum(is_honest))
print(ans)
n=int(input())
l=list(map(int,input().split()))
tl=[l[0]]
for i in range(1,n):
    if l[i]!=l[i-1]:
        tl.append(l[i])


a=[]
ma=False

for i in range(len(tl)):
    if i==0:
        if tl[i]>tl[i+1]:
            ma=True
            a.append(tl[i])
        else:
            ma=False
            a.append(tl[i])
    elif i==len(tl)-1:
        if tl[i]>tl[i-1]:
            a.append(tl[i])
        else:
            a.append(tl[i])
    else:
        if tl[i-1]<tl[i] and tl[i+1]<tl[i]:
            a.append(tl[i])
        elif tl[i-1]>tl[i] and tl[i+1]>tl[i]:
            a.append(tl[i])

if ma:
    a.pop(0)


num=0
ans=1000

for i in range(0,len(a)-1,2):
    thing1=(ans//a[i])*a[i+1]
    thing2=num*a[i+1]
    if thing1>thing2:
        ans=thing1+ans%a[i]
        num=0
        
    elif thing2>thing1:
        ans=thing2

print(ans)
        
            
            
        

    


### FIXED CODE ###

n=int(input())
l=list(map(int,input().split()))
tl=[l[0]]
for i in range(1,n):
    if l[i]!=l[i-1]:
        tl.append(l[i])


a=[]
ma=False

for i in range(len(tl)):
    if len(tl)==1:
        break
    if i==0:
        if tl[i]>tl[i+1]:
            ma=True
            a.append(tl[i])
        else:
            ma=False
            a.append(tl[i])
    elif i==len(tl)-1:
        if tl[i]>tl[i-1]:
            a.append(tl[i])
        else:
            a.append(tl[i])
    else:
        if tl[i-1]<tl[i] and tl[i+1]<tl[i]:
            a.append(tl[i])
        elif tl[i-1]>tl[i] and tl[i+1]>tl[i]:
            a.append(tl[i])

if ma:
    a.pop(0)


num=0
ans=1000

for i in range(0,len(a)-1,2):
    
    thing1=(ans//(a[i]))*a[i+1]
    thing2=num*a[i+1]
    if thing1>thing2:
        ans=thing1+ans%a[i]
        num=0
        
    elif thing2>thing1:
        ans=thing2

print(ans)
import numpy as np
h,w=map(int,input().split())
box=[list(input()) for i in range(h)]
count=h*w-(w+h-1)
for i in range(h):
    for j in range(w):
        if box[i][j]=="#":
            count -=1

another_box=[["#"]+box[i]+["#"] for i in range(h)]
another_box.insert(0,["#"]*(w+2))
another_box.append(["#"]*(w+2))
another_box[h][w]="G"

def maper(another_box,strat_x,strat_y):
    another_box[strat_x][strat_y]="#"
    for xx,yy in [[0,1],[0,-1],[1,0],[-1,0]]:
        n_x,n_y=strat_x+xx,strat_y+yy
        if another_box[n_x][n_y]==".":
            maper(another_box,n_x,n_y)
        elif another_box[n_x][n_y]=="G":
            another_box[n_x][n_y]="C"
    return another_box

flag=0
answer_box=maper(another_box,1,1)
for i in range(h+2):
    for j in range(w+2):
        if answer_box[i][j]=="C":
            flag=1

if flag==1:print(count)
else:print(-1)

### FIXED CODE ###

h,w=map(int,input().split())
b=[["#"]*(w+2)]
a=0
for i in range(h):
  c=["#"]
  for j in input():
    a+=j=="#"
    c.append(j)
  b.append(c+["#"])
b+=[["#"]*(w+2)]
b[h][w]=0
Q=[(1,1)]
x=0
y=-1
while Q:
	x+=1
	p=[]
	for i,j in Q:
		for dx,dy in [(1,0),(-1,0),(0,1),(0,-1)]:
			if b[i+dx][j+dy]==".":
				p+=[(i+dx,j+dy)]
				b[i+dx][j+dy]="#"
			elif b[i+dx][j+dy]==0:
				y=x
	if y>0:break
	Q=p
if y>0:print((h*w)-a-y-1)
else:print(-1)
# -*- coding: utf-8 -*-
# スペース区切りの整数の入力
v1, v2 = map(int, input().split())

if v1 < v2:
    t = v1
    v1 = v2
    v2 = t

v3 = v1 - v2

if v3 = 0:
    print(v1*2)

if v3 <= 2:
    print(v1*2-1)

if v1 == 1:
    print(v1*2+1)

### FIXED CODE ###

A, B = map(int, input().split())
print(max([A + A - 1, B + A, B + B -1]))
K,N = map(int,input().split())

A = []

for i in range(N):
  A.append(int(input()))
  
A_m = []

for i in range(1,N):
  A_m.append(A[i]-A[i-1])
  
A_m.append(K-A[N-1]+A[0])
  
print(sum(A_m)-max(A_m))


### FIXED CODE ###

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

  
A_m = []
 
for i in range(1,N):
  A_m.append(A[i]-A[i-1])
  
A_m.append(K-A[N-1]+A[0])
  
print(sum(A_m)-max(A_m))
import math
N,K = map(int,(input().split()))
L = list(map(int,(input().split())))
L.sort()
#print(L)
for x in range(K):
    del L[-1]
print(sum(L))

### FIXED CODE ###

import math
N,K = map(int,(input().split()))
#print(N,K)
L = list(map(int,(input().split())))
L.sort()
#print(L)
num = N-K
if(num < 0):
    num = 0
L = L[0:num]
#print(L)
print(sum(L))
# coding: utf-8
# Your code here!
w,h,x,y=map(int,input().split())
#print(min(max(x*h,(w-x)*h),max(y*w,(h-y)*w)))
if w==x+x and h==y+y:
    print(float(w)*float(h)/2,1)
else:
    print(float(w)*float(h)/2,0)



### FIXED CODE ###

x,a=map(int,input().split())
if(x>=a):
    print(10)
else:
    print(0)
a=int(input())
b=[input() for i in range(a)]
c=[AC,WA,TLE,RE]
d=[]
for value in c:
  e=b.count(value)
  d.append(["value x" e])
print(d)  
  
  


### FIXED CODE ###

N = int(input())
s = [input() for i in range(N)]
for v in ['AC', 'WA', 'TLE', 'RE']:
  print('{0} x {1}'.format(v, s.count(v)))
S = list(input())
N = len(S)

cnt = 0
l = 0
r = N-1
while l<=r:
    if S[l]=="x" and S[r]!="x":
        l += 1
        cnt += 1
    if S[l]!="x" and S[r]=="x":
        r += -1
        cnt += 1
    if S[l]=="x" and S[r]=="x":
        l += 1
        r += -1
    if S[l]!="x" and S[r]!="x":
        if S[l]==S[r]:
            l += 1
            r += -1
        else:
            cnt = -1
            break
print(cnt)

### FIXED CODE ###

S = list(input())
N = len(S)

cnt = 0
l = 0
r = N-1
while l<=r:
    if S[l]=="x" and S[r]!="x":
        l += 1
        cnt += 1
    elif S[l]!="x" and S[r]=="x":
        r += -1
        cnt += 1
    elif S[l]=="x" and S[r]=="x":
        l += 1
        r += -1
    elif S[l]!="x" and S[r]!="x":
        if S[l]==S[r]:
            l += 1
            r += -1
        else:
            cnt = -1
            break
print(cnt)
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

"""arc086_a"""

import sys
import pprint
import re

from collections import Counter

from functools import reduce

import itertools
pp = pprint.PrettyPrinter(indent=2)


def main():
    """Main function."""
    n, k = list(map(int, input().split(' ')))
    as_ = list(map(int, input().split(' ')))

    counter = Counter(as_)

    occ_list = sorted(counter.most_common(), key=lambda t: t[1], reverse=True)
    if len(occ_list) <= k:
        print(0)
    elif len(occ_list) == k + 1:
        print(occ_list[-1][1])
    else:
        print(reduce(lambda t1, t2: t1[1] + t2[1], occ_list[k:]))



if __name__ == '__main__':
    sys.exit(main())

### FIXED CODE ###

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

"""arc086_a"""

import sys
import pprint
import re

from collections import Counter

from functools import reduce

import itertools
pp = pprint.PrettyPrinter(indent=2)


def main():
    """Main function."""
    n, k = list(map(int, input().split(' ')))
    as_ = list(map(int, input().split(' ')))

    counter = Counter(as_)

    occ_list = sorted(counter.most_common(), key=lambda t: t[1], reverse=True)
    if len(occ_list) <= k:
        print(0)
    elif len(occ_list) == k + 1:
        print(occ_list[-1][1])
    else:
        print(reduce(lambda t1, t2: (0, t1[1] + t2[1]), occ_list[k:])[1])



if __name__ == '__main__':
    sys.exit(main())
N, K = map(int, input().split())

AB = []
for _ in range(1, N):
    a, b = map(int, input().split())
    AB.append((a, b))
    
# 無効グラフなので双方向にする
graph = {}
for a,b in AB:
    if not a in graph:
        graph[a] = {}
    if not b in graph:
        graph[b] = {}
    graph[a][b] = 1
    graph[b][a] = 1


#print(graph)

collors = [None] * (N+1)
from collections import deque
q = deque([(K, 1)]) 
while q:
    col_num, v = q.popleft()
    if collors[v] == None:
        collors[v] = col_num
        
        if col_num == K:
            rest_col = K-1
        else:
            rest_col = K-2
        
        for v in graph[v]:
            if collors[v] == None:
                q.appendleft((rest_col, v))
                rest_col -= 1
#print(collors)  

MOD = 10**9+7

ans = 1
for i in collors[1:]:
    ans = ans * i % MOD
print(ans)
    

### FIXED CODE ###

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

AB = []
for _ in range(1, N):
    a, b = map(int, input().split())
    AB.append((a, b))
    
if N == 1:
    print(K)
else:
    # 無効グラフなので双方向にする
    graph = {}
    for a,b in AB:
        if not a in graph:
            graph[a] = {}
        if not b in graph:
            graph[b] = {}
        graph[a][b] = 1
        graph[b][a] = 1


    #print(graph)

    collors = [None] * (N+1)
    from collections import deque
    q = deque([(K, 1)]) 
    while q:
        col_num, v = q.popleft()
        if collors[v] == None:
            collors[v] = col_num

            if col_num == K:
                rest_col = K-1
            else:
                rest_col = K-2

            for v in graph[v]:
                if collors[v] == None:
                    q.appendleft((rest_col, v))
                    rest_col -= 1
    #print(collors)  

    MOD = 10**9+7

    ans = 1
    for i in collors[1:]:
        ans = ans * i % MOD
    print(ans)
import math
from collections import Counter, defaultdict

def ncr(n, r):
	f = math.factorial
	return f(n)//f(r)//f(n-r)

n = int(input())

dct = defaultdict(int)

for i in range(n):
	counter = Counter(input().strip())
	tpl = tuple(sorted(counter.items()))
	dct[tpl] += 1
ans = sum(ncr(val, 2) for val in dct.values())

print(ans)

### FIXED CODE ###

import math
from collections import Counter, defaultdict

def ncr(n, r):
	f = math.factorial
	return f(n)//f(r)//f(n-r)

n = int(input())

dct = defaultdict(int)

for i in range(n):
	counter = Counter(input().strip())
	tpl = tuple(sorted(counter.items()))
	dct[tpl] += 1


ans = sum(ncr(val, 2) for val in dct.values() if val>1)
print(ans)
s = input()
t = input()

if s = t[:len(s)]:
	if t[-1] in 'abcdefghijklmnopqrstuvwxyz'
		print('Yes')

### FIXED CODE ###

s = input()
t = input()
     
if s == t[:len(s)]:
	if t[-1] in 'abcdefghijklmnopqrstuvwxyz':
		print('Yes')
		exit(0)       

print('No')
N = int(input()) #1行目のNを取得する
Input = [int(input()) for i in range(N)] #複数行の数値の入力を取得
 
for i in range(N):
  j = i + 1
  
  Stock = 0
  Money = 1000
  
  if j = 1:
    if Input[i] < Input[i+1]:
      Stock = Money // Input[i]
      Money = Money % Input[i]
     
    continue
   
  if j = N:
    if Stock != 0:
      money = money + Stock * Input[i]
    continue
  
  if Input[i - 1] < Input[i]:
    money = money + Stock * Input[i]
  
  if Input[i + 1] > Input[i]:
    Stock = Money // Input[i]
    Money = Money % Input[i]

    
print(money)

### FIXED CODE ###

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

money = 1000
stock = 0

for i in range(n-1):
  if a[i+1] > a[i]:
    stock = money // a[i]
    money = money - stock * a[i] + stock * a[i+1]
    
print(money)
from collections import deque


def transaction(N, r):
    x = r[0]
    n = int(N / x[1])
    if N % x[1] == 0:
        return n * x[2]
    if len(r) == 1:
        return n * x[2] + N - n * x[1]
    r.popleft()
    s = N
    for i in range(n + 1):
        tmp = i * x[2] + transaction(N - i * x[1], r)
        if tmp > s:
            s = tmp
    return s

N = int(input())
A = [int(e) for e in input().split()]
B = [int(e) for e in input().split()]

r = []
for i in range(3):
    (a, b) = (A[i], B[i])
    if b > a:
        r.append((b / a, a, b))

if len(r) > 0:
    r.sort(reverse=True)
    dr = deque(maxlen=3)
    for x in r:
        dr.append(x)
    N = transaction(N, dr)

r = []
for i in range(3):
    (a, b) = (A[i], B[i])
    if a > b:
        r.append((a / b, b, a))

if len(r) > 0:
    r.sort(reverse=True)
    dr.clear()
    for x in r:
        dr.append(x)
    N = transaction(N, dr)

print(N)

### FIXED CODE ###

import math
import sys

N = int(input())
GA, SA, BA = list(map(int, input().split()))
GB, SB, BB = list(map(int, input().split()))

def knapsack(n, ga, sa, ba, gb, sb, bb):
    values = []
    weights = []
    if gb / ga > 1:
        values.append(gb - ga)
        weights.append(ga)
    if sb / sa > 1:
        values.append(sb - sa)
        weights.append(sa)
    if bb / ba > 1:
        values.append(bb - ba)
        weights.append(ba)
    if len(values) == 3:
        # dp[i]: 重さ i 以下で選ぶのの価値の最大値
        dp = [0] * (n + 1)
        dp[0] = n
        for i in range(1, n + 1):
            x = dp[i - 1]
            for w, v in zip(weights, values):
                if i - w >= 0:
                    x = max(x, dp[i - w] + v)
            dp[i] = x
        return dp[n]
    if len(values) == 2:
        w1, w2 = weights
        v1, v2 = values
        if (v1 + w1) / w1 < (v2 + w2) / w2:
            v1, v2 = v2, v1
            w1, w2 = w2, w1
        c1 = n // w1
        c2 = (n - w1 * c1) // w2
        ret = n + v1 * c1 + v2 * c2
        while c1 >= 0:
            a = n - w1 * c1 - w2 * c2
            c1 -= max(1, math.ceil((w2 - a) / w1))
            c2 = (n - w1 * c1) // w2
            ret = max(ret, n + v1 * c1 + v2 * c2)
            if w1 * c1 + w2 * c2 == n:
                break
        return ret
    if len(values) == 1:
        return n + n // weights[0] * values[0]
    return n

ans = knapsack(N, GA, SA, BA, GB, SB, BB)
ans = knapsack(ans, GB, SB, BB, GA, SA, BA)
print(int(ans))
#B問題
N, K = map(int, input().split())
Result = [True] * N
count = 0
for i in range(K):
    d = int(input())
    A = input().split()
    for j in range(len(A_i)):
        Result[A_i[j]-1] = False

count = Result.count(True)
print(count)

### FIXED CODE ###

#B問題
N, K = map(int, input().split())
Result = [True] * N
Count = 0
for i in range(K):
    d = int(input())
    A = input().split()
    for j in range(len(A)):
        Result[int(A[j])-1] = False

Count = Result.count(True)
print(Count)
a, b = map(int, input().split)
print((a + b) % 24)

### FIXED CODE ###

a, b = map(int, input().split())
print((a + b) % 24)
# -*- coding: utf-8 -*-
length=int(input())
lst=list(map(int,input().split()))
per_diff=0
s1=0
for i in range(length):
  s1=sum(lst[0:i+1])
  s2=sum(lst[i+1:])
  if math.abs(s1-s2)>pre_diff:
    print(pre_diff)
    break

### FIXED CODE ###

# -*- coding: utf-8 -*-
length=int(input())
lst=list(map(int,input().split()))
lst2=[]
for i in range(length):
    s1=sum(lst[0:i+1])
    s2=sum(lst[i+1:])
    lst2.append(abs(s1-s2))
print(min(lst2))
N = int(input())

def check(a, b, i):
  if (a + 1) * 10 ** i + b - 10 <= N:
    return 10 ** (i - 1)
  else:
    ret = 0
    for j in range(10 ** (i - 1)):
      if a * 10 ** i + j * 10 + a <= N:
        ret += 1
      else:
        return ret
ans = 0
for a in range(1, 10):
  for b in range(a, 10):
    if a == b:
      n = 0
      if a * 10 + b <= N:
        n += 2
      elif a <= N:
        ans += 1
      for i in range(2, 6):
        n += check(a, b, i)
      ans += n ** 2
    else:
      n, m = 0, 0
      if a * 10 + b <= N:
        n += 1
      if b * 10 + a <= N:
        m += 1
      for i in range(2, 6):
        n += check(a, b, i)
        m += check(b, a, i)
      ans += n * m * 2
print(ans)

### FIXED CODE ###

N = int(input())

c = [[0 for _ in range(9)] for _ in range(9)]
for i in range(1, 10):
  for j in range(1, 10):
    cnt = 0
    for n in range(1, N + 1):
      if n // (10 ** (len(str(n)) - 1)) == i and n % 10 == j:
        cnt += 1
    c[i - 1][j - 1] = cnt

ans = 0
for i in range(9):
  for j in range(9):
    ans += c[i][j] * c[j][i]
print(ans)