TnT/Multi_CodeNet4Repair huggingface dataset:
Problem: Given are 1-digit positive integers a and b. Consider these two strings: the concatenation of b copies of the digit a, and the concatenation of a copies of the digit b. Which of these is lexicographically smaller?

Submission attempts (in order):
a, b = [int(x) for x in input().split()]

as = str(a) * b
bs = str(b) * a

print(as if as < b else bs)

a, b = [int(x) for x in input().split()]

As = str(a) * b
Bs = str(b) * a

print(min(As, Bs))

Verdicts: Runtime Error

Accepted
Problem: Given are 1-digit positive integers a and b. Consider these two strings: the concatenation of b copies of the digit a, and the concatenation of a copies of the digit b. Which of these is lexicographically smaller?

Submission attempts (in order):
a,b=map(int,input().split())

if a>b:
  print("b"*a)
else:
  print("a"*b)


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

if a < b:
    ans = str(a) * b
else:
    ans = str(b) * a
print(ans)


Verdicts: Wrong Answer

Accepted
Problem: Given are 1-digit positive integers a and b. Consider these two strings: the concatenation of b copies of the digit a, and the concatenation of a copies of the digit b. Which of these is lexicographically smaller?

Submission attempts (in order):
a,b=map(int,input().split())
zz=str(a)*int(b)
yy=str(b)*int(a)
print(zz)
print(yy)
if(zz<yy):
  print(zz)
else:
  print(yy)

n,m=map(int,input().split())
if(n<m):
  print(str(n)*int(m))
else:
  print(str(m)*int(n))


Verdicts: Wrong Answer

Accepted
Problem: Given are 1-digit positive integers a and b. Consider these two strings: the concatenation of b copies of the digit a, and the concatenation of a copies of the digit b. Which of these is lexicographically smaller?

Submission attempts (in order):
a,b = input().split()

A = a*int(b)
B = b*int(a)

print(min(int(A),int(B)))


a,b = input().split()

A = a*int(b)
B = b*int(a)

print(str(max(int(A),int(B))))


Verdicts: Wrong Answer

Accepted
Problem: Given is a positive integer N.   Find the number of pairs (A, B) of positive integers not greater than N that satisfy the following condition:    * When A and B are written in base ten without leading zeros, the last digit of A is equal to the first digit of B, and the first digit of A is equal to the last digit of B.

Submission attempts (in order):

def cnt(b,e,n_str):
  res=0
  for i in range(int(n_str)+1):
    if int(str(i)[0])==b and i%10==e:
      res+=1
  return res
def sol():
  n_str=input()
  return sum(cnt(b,e,n_str)*cnt(e,b,n_str) 
             for b,e in product(range(1,10),repeat=2))

print(sol())  


from itertools import product
from functools import reduce
import operator
def prod(iterable):
    return reduce(operator.mul, iterable, 1)
def cnt_samelen(b,e,n_str):
  n0=int(n_str[0])
  if b>n0 or len(n_str)==1:
    return 0
  if b<n0:
    return b*int(10**(len(n_str)-2))
  
  return (int(n_str[1:-1])+1 if len(n_str)>2 else 1)-(1 if e>int(n_str[-1]) else 0)
def cnt(b,e,n_str):
  res=0
  l=len(n_str)
  if b==e and int(n_str)>=b:
    res+=1
  for i in range(l-2):
    res+=10**(i)
  res+=cnt_samelen(b,e,n_str)
  return res
def sol():
  n_str=input()
  return sum(cnt(b,e,n_str)*cnt(e,b,n_str) 
             for b,e in product(range(1,10),repeat=2))

print(sol())  

Verdicts: Runtime Error

Accepted
Problem: Given is a positive integer N.   Find the number of pairs (A, B) of positive integers not greater than N that satisfy the following condition:    * When A and B are written in base ten without leading zeros, the last digit of A is equal to the first digit of B, and the first digit of A is equal to the last digit of B.

Submission attempts (in order):
import numpy as np


#N = int(input())
N =200000

countup = np.zeros(100, dtype=int)

for x in range(1,N+1):
    sx = str(x)
    A = int(sx[0])
    B = int(sx[-1])
    countup[A*10+B] += 1

ans = 0
for x in range(1,N+1):
    sx = str(x)
    A = int(sx[0])
    B = int(sx[-1])
    ans += countup[B*10+A]

print(ans)


import numpy as np


N = int(input())

countup = np.zeros(100, dtype=int)

for x in range(1,N+1):
    sx = str(x)
    A = int(sx[0])
    B = int(sx[-1])
    countup[A*10+B] += 1

ans = 0
for x in range(1,N+1):
    sx = str(x)
    A = int(sx[0])
    B = int(sx[-1])
    ans += countup[B*10+A]

print(ans)


Verdicts: Wrong Answer

Accepted
Problem: Given is a positive integer N.   Find the number of pairs (A, B) of positive integers not greater than N that satisfy the following condition:    * When A and B are written in base ten without leading zeros, the last digit of A is equal to the first digit of B, and the first digit of A is equal to the last digit of B.

Submission attempts (in order):
N = int(input())
max_N = 2 * 10 ** 5

d = [[0] * 10 for _ in range(10)]
for i in range(1,int(n)):
  k = str(i)
  d[int(k[0])][int(k[-1])] += 1

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

n = input()
 
d = [ [0] * 10 for _ in range(10) ]
for i in range( 1, int( n ) + 1 ):
  k = str(i)
  d[ int( k[ 0 ])][ int( k[ -1 ])] += 1

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

Verdicts: Runtime Error

Accepted
Problem: Given is a positive integer N.   Find the number of pairs (A, B) of positive integers not greater than N that satisfy the following condition:    * When A and B are written in base ten without leading zeros, the last digit of A is equal to the first digit of B, and the first digit of A is equal to the last digit of B.

Submission attempts (in order):
r = range(1, 10)
n = int(input())
a = [None] + [[0] * 10 for _ in r]
for i in r:
  if i <= n:
    a[i][j] += 1
for i in r:
  for j in r:
    k = 1
    while 10 * k * i + j <= n:
      a[i][j] += min(k, (n - j) // 10 - k * i + 1)
      k *= 10
print(sum(a[i][j] * a[j][i] for i in r for j in r))


n = int(input())
r = range(1, 10)
a = [[0] * 9 for _ in r]
for i in r:
  if i <= n:
    a[i - 1][i - 1] += 1
for i in r:
  for j in r:
    k = 1
    while 10 * k * i + j <= n:
      a[i - 1][j - 1] += min(k, (n - 10 * k * i + j) // 10)
      k *= 10
print(sum(a[i][j] * a[j][i] for i in range(9) for j in range(9)))


n = int(input())
r = range(1, 10)
a = [[0] * 9 for _ in r]
for i in r:
  if i <= n:
    a[i - 1][i - 1] += 1
for i in r:
  for j in r:
    k = 1
    while 10 * k * i + j <= n:
      a[i - 1][j - 1] += min(k, (n + 1 - j) // 10 - k * i)
      k *= 10
print(sum(a[i][j] * a[j][i] for i in range(9) for j in range(9)))


n = int(input())
r = range(1, min(9, n) + 1)
a = [None]
for i in r:
  a.append([None])
  for j in r:
    a[i].append(i == j)
    k = 1
    while 10 * k * i + j <= n:
      a[i][j] += min(k, (n - j) // 10 - k * i + 1)
      k *= 10
print(sum(a[i][j] * a[j][i] for i in r for j in r))

Verdicts: Runtime Error

Wrong Answer

Wrong Answer

Accepted
Problem: Given is a positive integer N.   Find the number of pairs (A, B) of positive integers not greater than N that satisfy the following condition:    * When A and B are written in base ten without leading zeros, the last digit of A is equal to the first digit of B, and the first digit of A is equal to the last digit of B.

Submission attempts (in order):
from functools import reduce
import fractions

def lcm_base(x, y):
    return (x * y) // fractions.gcd(x, y)

def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)


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

kobai=lcm_list(a)

sumN=0
for i in a:
    sumN+=int(kobai/i)
   
sumN=int(sumN%(1e9+7))

print(sumN)

N=int(input())

a_list= [[0 for i in range(10)] for j in range(10)]
b_list= [[0 for i in range(10)] for j in range(10)]
for i in range(N+1):
    a=int(str(i)[0])
    b=int(str(i)[-1])
    a_list[a][b]+=1
    b_list[b][a]+=1

count=0
for i in range(1,10):
    for j in range(1,10):
        count+=a_list[i][j]*b_list[i][j]

print(count)

Verdicts: Runtime Error

Accepted
Problem: Given is a positive integer N.   Find the number of pairs (A, B) of positive integers not greater than N that satisfy the following condition:    * When A and B are written in base ten without leading zeros, the last digit of A is equal to the first digit of B, and the first digit of A is equal to the last digit of B.

Submission attempts (in order):
n = int(input())
p = [[0 for _ in range(10)] for _2 in range(10)]
ans = 0
for i in range(1, n+1):
  l = int(str(i)[0])
  r = int(str(i)[-1])
  p[l][r] += 1
  ans += p[r][l]
print(ans)

n = int(input())
p = [[0 for _ in range(10)] for _2 in range(10)]
ans = 0
for i in range(1, n+1):
  l = int(str(i)[0])
  r = int(str(i)[-1])
  ans += 2 * p[r][l]
  p[l][r] += 1
  if l == r:
    ans += 1
print(ans)

Verdicts: Wrong Answer

Accepted
Problem: Given is a positive integer N.   Find the number of pairs (A, B) of positive integers not greater than N that satisfy the following condition:    * When A and B are written in base ten without leading zeros, the last digit of A is equal to the first digit of B, and the first digit of A is equal to the last digit of B.

Submission attempts (in order):
n=int(input())
ans=0
power=0
for i in range(1,n+1):
  if i>=10**(power+1):
    power+=1
  a=i%10
  if a==0:
    continue
  b=(i-i%(10**power))//(10**power)
  if a==b:
    ans+=1
    if power>0:
      ans+=2
    r=max(0,((i-(b*(10**power))-a)//10))
    ans+=2*r
    for j in range(0,power-1):
      ans+=2*(10**j)
  elif a<b:
    for j in range(0,power-1):
      ans+=2*(10**j)
  else:
    for j in range(0,power):
      ans+=2*(10**j)
print(ans)

n=int(input())
ans=0
currentpower=0
for i in range(1,n+1):
  if i>=10**(currentpower+1):
    currentpower+=1
  b=i%10
  a=(i-i%(10**currentpower))//(10**currentpower)
  if b==0:
    continue
  if a==b:
    ans+=1
    if currentpower>0:
      ans+=2
    r=max(0,((i-(a*(10**currentpower))-b)//10))
    ans+=2*r
    for j in range(0,currentpower-1):
      ans+=2*(10**j)
  elif a<b:
    for j in range(0,currentpower-1):
      ans+=2*(10**j)
  else:
    for j in range(0,currentpower):
      ans+=2*(10**j)
print(ans)


Verdicts: Wrong Answer

Accepted
Problem: Given is a positive integer N.   Find the number of pairs (A, B) of positive integers not greater than N that satisfy the following condition:    * When A and B are written in base ten without leading zeros, the last digit of A is equal to the first digit of B, and the first digit of A is equal to the last digit of B.

Submission attempts (in order):
from itertools import product


def solve(string):
    l = len(string)
    *s, = map(int, string)
    print(s, l)
    t = [[0] * 10 for _ in range(10)]
    for a, b in product(range(1, 10), repeat=2):
        for i in range(l):
            if i < l - 1:
                if i == 0 and a == b:
                    t[a][b] += 1
                elif i > 0:
                    t[a][b] += 10**(i - 1)
            else:
                if a < s[0]:
                    t[a][b] += 10**(i - 1)
                elif a == s[0]:
                    tmp = 1
                    for _s in s[1:-1]:
                        tmp *= _s + 1
                    t[a][b] += tmp - (b > s[-1])
    return str(sum(t[i][j] * t[j][i] for i, j in product(range(10), repeat=2)))


if __name__ == '__main__':
    import sys
    print(solve(sys.stdin.read().strip()))


from itertools import product


def solve(string):
    d = len(string)
    if d == 1:
        return string
    s0, ss, sn = int(string[0]), int(string[1:-1] or 0), int(string[-1])
    t = [[0] * 10] + [[int("1" * (d - 2) or 0)] * 10 for _ in range(9)]
    for i in range(1, 10):
        t[i][i] += 1
    for i, j in product(range(1, s0), range(10)):
        t[i][j] += 10**(d - 2)
    for j in range(10):
        t[s0][j] += ss + 1 if j <= sn else ss
    return str(sum(t[i][j] * t[j][i] for i, j in product(range(1, 10), repeat=2)))


if __name__ == '__main__':
    import sys
    print(solve(sys.stdin.read().strip()))


Verdicts: Wrong Answer

Accepted
Problem: Given is a positive integer N.   Find the number of pairs (A, B) of positive integers not greater than N that satisfy the following condition:    * When A and B are written in base ten without leading zeros, the last digit of A is equal to the first digit of B, and the first digit of A is equal to the last digit of B.

Submission attempts (in order):
n = int(input())
c = 0

def count(i):
    h = str(i)
    s = lambda j, k, l: int('{}{}{}'.format(j, k, j))
    if len(set(h)) == 1:
        h = h[0]
        c = 1
        s = h * 1
        while int(s) <= n:
            c += 1
            s = h * c
        return c - 1
    if h[-1] == '0' or s(h[-1], '', h[0]) > n:
        return 0
    d = 1
    while s(h[-1], '0' * d, h[0]) <= n:
        d += 1
    for i in range(10):
        if s(h[-1], i, h[0]) > n:
            break
    return 11 * (d - 1) + 1

s = 0
for i in range(1, n+1):
    c = count(i)
    print(f'{i} = {c}')
    s += c
print(s)


n = int(input())
d = {}

for a in range(1, n+1):
    a = str(a)
    f, l = a[0], a[-1]
    if '0' in [f, l]:
        continue
    if (f, l) in d:
        d[(f, l)] += 1
    else:
        d[(f, l)] = 1

ans = 0
for b in range(1, n+1):
    b = str(b)
    f, l = b[-1], b[0]
    if (f, l) in d:
        ans += d[(f, l)]
print(ans)

Verdicts: Runtime Error

Accepted
Problem: Given is a positive integer N.   Find the number of pairs (A, B) of positive integers not greater than N that satisfy the following condition:    * When A and B are written in base ten without leading zeros, the last digit of A is equal to the first digit of B, and the first digit of A is equal to the last digit of B.

Submission attempts (in order):
N = int(input())

print([0 for i in range(9)])
  

N = int(input())

nmap = [[0 for i in range(10)] for j in range(10)]

answer = 0
for n in range(1, N + 1):
  first = int(str(n)[0])
  last = int(str(n)[-1])
  nmap[first][last] += 1

for n in range(1, N + 1):
  _last = int(str(n)[0])
  _first = int(str(n)[-1])
  answer += nmap[_first][_last]
  
print(answer)


Verdicts: Wrong Answer

Accepted
Problem: Given is a positive integer N.   Find the number of pairs (A, B) of positive integers not greater than N that satisfy the following condition:    * When A and B are written in base ten without leading zeros, the last digit of A is equal to the first digit of B, and the first digit of A is equal to the last digit of B.

Submission attempts (in order):
N = int(input())

cnt=0
for i in range(1,N+1):
    new = [int(d) for d in str(i)]
    print(new)
    sento=new[0]
    matu=new[-1]
    keta=len(new)

    if matu!='0':
        new[0]=matu
        new[-1]=sento
        comb=''.join(new)
        if matu==sento:
            cnt+=max(0,len(new)-1)
        elif comb>N:
            for j in range(0,keta-2):
                cnt+=9**j
        elif comb<N:
            for j in range(0,keta-1):
                cnt+=9**j







print(cnt)


N = int(input())

A = [list(0 for i in range(9)) for _ in range(9)]

for i in range(1,N+1):
    new = [int(d) for d in str(i)]
    if  new[-1]!=0:
        A[new[0]-1][new[-1]-1]+=1

cnt=0
for i in range(9):
    for j in range(9):
        cnt+=A[i][j]*A[j][i]

print(cnt)


Verdicts: Runtime Error

Accepted
Problem: Given is a positive integer N.   Find the number of pairs (A, B) of positive integers not greater than N that satisfy the following condition:    * When A and B are written in base ten without leading zeros, the last digit of A is equal to the first digit of B, and the first digit of A is equal to the last digit of B.

Submission attempts (in order):
n = int(input())
d = [[0] * 10 for _ in range(10)]

for i in range(1, n + 1):
  s = str(i)
  if s[-1] == '0':
    continue
  d[int(s[0])][int(s[-1])] += 1

result = 0
for i in range(1, 10):
  for j in range(1, 10):
    result = d[i][j] * d[j][i]
print(result)


n = int(input())
d = [[0] * 10 for _ in range(10)]

for i in range(1, n + 1):
  s = str(i)
  if s[-1] == '0':
    continue
  d[int(s[0])][int(s[-1])] += 1

result = 0
for i in range(1, 10):
  for j in range(1, 10):
    result += d[i][j] * d[j][i]
print(result)


Verdicts: Wrong Answer

Accepted
Problem: Given is a positive integer N.   Find the number of pairs (A, B) of positive integers not greater than N that satisfy the following condition:    * When A and B are written in base ten without leading zeros, the last digit of A is equal to the first digit of B, and the first digit of A is equal to the last digit of B.

Submission attempts (in order):
n=int(input())
a=0
for i in range(1,n+1):
  for j in range(i,n+1):
    if str(i)[0]==str(j)[-1] and str(j)[0]==str(i)[-1]:
      a+=1
print(a)

n=int(input())
a=0
for i in range(1,n+1):
  for j in range(i,n+1):
    if str(i)[0]==str(j)[-1] and str(j)[0]==str(i)[-1]:
      a++
print(a)

n=int(input())
t=[[0]*10 for _ in range(10)]
for i in range(1,n+1):
  t[int(str(i)[0])][i%10]+=1
a=0
for i in range(10):
  for j in range(10):
    a+=t[i][j]*t[j][i]
print(a)

Verdicts: Wrong Answer

Runtime Error

Accepted
Problem: Given is a positive integer N.   Find the number of pairs (A, B) of positive integers not greater than N that satisfy the following condition:    * When A and B are written in base ten without leading zeros, the last digit of A is equal to the first digit of B, and the first digit of A is equal to the last digit of B.

Submission attempts (in order):
N=int(input())
K=[[0 for i in range(9)] for j in range(9)]

for i in range(1,N+1):
  if int(str(i)[-1])==0:
    pass
  else:
    h=int(str(i)[0])
    t=int(str(i)[-1])
    K[h-1][t-1] += 1
  
ans=0
for i in range(9):
  for j in range(i+1):
    if i!=j:
      ans += 2*K[i][j]* K[j][i]
      print(i+1,j+1)
    else:
      ans += K[i][j]**2
    #print(i,j,K[i][j],K[j][i],K[i][j]*K[j][i])
      
print(ans)

N=int(input())
K=[[0 for i in range(9)] for j in range(9)]

for i in range(1,N+1):
  if int(str(i)[-1])==0:
    pass
  else:
    h=int(str(i)[0])
    t=int(str(i)[-1])
    K[h-1][t-1] += 1


ans=0
for i in range(9):
  for j in range(i+1):
    if i==j:
      ans += K[i][j]* K[j][i]
    else:
      ans += 2*K[i][j]* K[j][i]
      #print(i,j,K[i][j],K[j][i],K[i][j]*K[j][i])
      
print(ans)

Verdicts: Wrong Answer

Accepted
Problem: Given is a positive integer N.   Find the number of pairs (A, B) of positive integers not greater than N that satisfy the following condition:    * When A and B are written in base ten without leading zeros, the last digit of A is equal to the first digit of B, and the first digit of A is equal to the last digit of B.

Submission attempts (in order):
n = int(input())
c = [[0 for i in range(10)] for j in range(10)]

for i in range(n):
    x = str(n + 1)
    c[int(x[0])][int(x[-1])] += 1
ans = 0
for i in range(10):
    for j in range(10):
       ans += c[i][j] * c[j][i]
print(ans)

n = int(input())
c = [[0 for i in range(10)] for j in range(10)]

for i in range(n):
    x = str(n + 1)
    c[int(x[0])][int(x[-1])] += 1
ans = 0
for i in range(n):
    for j in range(n):
       ans += c[i][j] * c[j][i]
print(ans)

n = int(input())
c = [[0 for i in range(10)] for j in range(10)]

for i in range(n):
    x = str(i + 1)
    c[int(x[0])][int(x[-1])] += 1
ans = 0
for i in range(10):
    for j in range(10):
       ans += c[i][j] * c[j][i]
print(ans)

Verdicts: Wrong Answer

Runtime Error

Accepted
Problem: Given is a positive integer N.   Find the number of pairs (A, B) of positive integers not greater than N that satisfy the following condition:    * When A and B are written in base ten without leading zeros, the last digit of A is equal to the first digit of B, and the first digit of A is equal to the last digit of B.

Submission attempts (in order):
def main(n):
    cnt=0
    for i in range(1,n+1):
        i_list=list(str(i))
        for j in range(1,n+1):
            j_list=list(str(j))
            if i_list[1]==j_list[-1] and i_list[-1]==j_list[1]:
                cnt+=1
    print(cnt)        
        

    
if __name__=='__main__':
    main(int(input()))

def main(n):
    c=[[0]*10 for _ in range(10)]
    for k in range(1,n+1):
        n=str(k)
        i = int(n[0])
        j = int(n[-1])
        c[i][j] += 1
    ans =0
    for i in range(10):
        ans+=sum(c[i])
    print(ans)
             
if __name__=='__main__':
    main(int(input()))

def main(n):
    c=[[0]*10 for _ in range(10)]
    for k in range(1,n+1):
        n=str(k)
        i = int(n[0])
        j = int(n[-1])
        c[i][j] += 1
    ans =0
    for i in range(10):
        for j in range(10):
            ans+=c[i][j]*c[j][i]
    print(ans)
             
if __name__=='__main__':
    main(int(input()))

Verdicts: Runtime Error

Wrong Answer

Accepted
Problem: Given is a positive integer N.   Find the number of pairs (A, B) of positive integers not greater than N that satisfy the following condition:    * When A and B are written in base ten without leading zeros, the last digit of A is equal to the first digit of B, and the first digit of A is equal to the last digit of B.

Submission attempts (in order):
n= int(input())

ans = 0
for i in range(1,n+1):
  if str(i)[0]==str(i)[-1]:
    ans += 1
    
print(ans)

n= int(input())

mat = [[0]*(10)]*(10)

for i in range(1,n+1):
  a,b = str(i)[0],str(i)[-1]:
  mat[a][b] += 1

ans = 0
for i in range(1,10):
  for j in range(1,10):
    ans += mat[i][j]*mat[j][i]
print(ans)


n= int(input())

mat = [ [0]*10 for i in range(10)]

for i in range(1,n+1):
  a,b = int(str(i)[0]), i%10
  mat[a][b] += 1

ans = 0
for i in range(1,10):
  for j in range(1,10):
    ans += mat[i][j]*mat[j][i]

print(ans)



Verdicts: Wrong Answer

Runtime Error

Accepted
Problem: Given is a positive integer N.   Find the number of pairs (A, B) of positive integers not greater than N that satisfy the following condition:    * When A and B are written in base ten without leading zeros, the last digit of A is equal to the first digit of B, and the first digit of A is equal to the last digit of B.

Submission attempts (in order):
n=str(input())
H=n[0]
T=n[-1]
keta=len(n)
n=int(n)
ans=0
if keta==1:
    print(1)
    exit()
for i in range(1,n+1):
    s=str(i)
    h=s[0]
    t=s[-1]
    if h!="0" and t!="0":
        ans+=(10**(keta-2)-1)//9
        if h==t:
            ans+=1
        if int(t)<=int(H):
            ans+=(10**(keta-2))*(int(H)-int(t))
            ans+=max(0,(n-10**(keta-1)*int(H)-int(h))//10)
    
print(ans)

n=str(input())
H=n[0]
T=n[-1]
keta=len(n)
n=int(n)
ans=0
if keta==1:
    print(1)
    exit()
elif keta==2:
    for i in range(1,n+1):
        s=str(i)
        for j in range(1,n+1):
            S=str(j)
            if S[0]==s[-1] and S[-1]==s[0]:
                ans+=1    
else:
    for i in range(1,n+1):
        s=str(i)
        h=s[0]
        t=s[-1]
        if h!="0" and t!="0":
            ans+=(10**(keta-2)-1)//9
            if h==t:
                ans+=1
            if int(t)<int(H):
                ans+=(10**(keta-2))*(int(H)-int(t))
            elif int(t)==int(H):
                ans+=max(0,((n-10**(keta-1)*int(H)-int(h))//10)+1)
            
print(ans)




Verdicts: Wrong Answer

Accepted
Problem: Given is a positive integer N.   Find the number of pairs (A, B) of positive integers not greater than N that satisfy the following condition:    * When A and B are written in base ten without leading zeros, the last digit of A is equal to the first digit of B, and the first digit of A is equal to the last digit of B.

Submission attempts (in order):
def main(n):
    l=[i for i in range(1,n+1)]
    ans=0
    for i in l:
        for j in l:    
            if str(i)[0]==str(j)[-1] and str(j)[0]==str(i)[-1]:
                # print(i,j)
                ans+=1
                
    print(ans)
n=init(input())
main(n)

n=int(input())
cnt=[[0 for i in range(10)] for j in range(10)]

for i in range(1,n+1):
  s=str(i)
  head=int(s[0])
  tail=int(s[-1])
  cnt[head][tail]+=1

ans=0
for h in range(0,10):
  for t in range(0,10):
    ans+=cnt[h][t]*cnt[t][h]
print(ans)

Verdicts: Runtime Error

Accepted
Problem: Given is a positive integer N.   Find the number of pairs (A, B) of positive integers not greater than N that satisfy the following condition:    * When A and B are written in base ten without leading zeros, the last digit of A is equal to the first digit of B, and the first digit of A is equal to the last digit of B.

Submission attempts (in order):
from collections import defaultdict

d = defaultdict(int)

for n in range(N):
    n = str(n)

    a = n[0]
    b = n[-1]

    d[(a, b)] += 1


s = 0
for i in range(1, 10):
    for j in range(10):

        s += d[(str(j), str(i))] * d[(str(i), str(j))]

print(s)



from collections import defaultdict

d = defaultdict(int)
N = int(input())

for n in range(1, N + 1):
    n = str(n)

    a = n[0]
    b = n[-1]

    d[(a, b)] += 1


s = 0
for i in range(10):
    for j in range(10):

        s += d[(str(j), str(i))] * d[(str(i), str(j))]

print(s)


Verdicts: Runtime Error

Accepted
Problem: Given is a positive integer N.   Find the number of pairs (A, B) of positive integers not greater than N that satisfy the following condition:    * When A and B are written in base ten without leading zeros, the last digit of A is equal to the first digit of B, and the first digit of A is equal to the last digit of B.

Submission attempts (in order):
n = int(input())
s0=list(str(n))
ans=0

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

for i in range(1,n+1):
    s1=list(str(i))
    if s1[-1]=='0':
        continue
    if s1[0]==s1[-1]:
        ans+=1
    for j in range(2,len(s0)):
        ans+=10**(j-2)
    if int(s0[0])>int(s1[-1]):
        ans+=10**(len(s0)-2)
    elif s0[0]==s1[-1]:
        ans+=int(''.join(s0[1:len(s0)-1]))+1
        if int(s0[-1])<int(s1[0]):
            ans-=1
print(ans)


n = int(input())
s0=list(str(n))
ans=0

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

if len(s0)==2:
    for i in range(1,n+1):
        s1=list(str(i))
        if s1[-1]=='0':
            continue
        if s1[0]==s1[-1]:
            ans+=1
        if int(s1[-1])*10+int(s1[0])<=n:
            ans+=1
    print(ans)
    exit()

for i in range(1,n+1):
    s1=list(str(i))
    if s1[-1]=='0':
        continue
    if s1[0]==s1[-1]:
        ans+=1
    for j in range(2,len(s0)):
        ans+=10**(j-2)
    if int(s0[0])>int(s1[-1]):
        ans+=10**(len(s0)-2)
    elif s0[0]==s1[-1]:
        ans+=int(''.join(s0[1:len(s0)-1]))+1
        if int(s0[-1])<int(s1[0]):
            ans-=1
print(ans)


Verdicts: Runtime Error

Accepted
Problem: Given is a positive integer N.   Find the number of pairs (A, B) of positive integers not greater than N that satisfy the following condition:    * When A and B are written in base ten without leading zeros, the last digit of A is equal to the first digit of B, and the first digit of A is equal to the last digit of B.

Submission attempts (in order):
import numpy as np
n = int(input())
keta = len(str(n))
field = np.array([[0 for _ in range(0)] for _ in range(9)])
def cmb(n, r):
    if n - r < r: r = n - r
    if r == 0: return 1
    if r == 1: return n

    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]

    for p in range(2,r+1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p-1,r,p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot

    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])

    return result


for k in range(1, n+1):
    i = int(str(k)[0])
    j = int(str(k)[1])
    field[i, j] += 1
total = 0
for i in range(9):
    val = field[i,i]
    total += cmb(val+1, 2)
for i in range(9):
    for j in range(9):
        if i==j:
            continue
        else:
            val = field[i,j]
            total += 2*cmb(val, 2)
print(val)

import numpy as np
def cmb(n, r):
    if n<r:
      return 0
    if n - r < r: r = n - r
    if r == 0: return 1
    if r == 1: return n

    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]

    for p in range(2,r+1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p-1,r,p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot

    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])

    return result

n = int(input())
field = np.array([[0 for _ in range(9)] for _ in range(9)])

for i in range(1, n+1):
    stri = str(i)
    mae = int(stri[0])
    ushiro = int(stri[-1])
    if mae != 0 and ushiro != 0:
        field[mae-1, ushiro-1] += 1

total = 0
for i in range(9):
    val = field[i, i]
    #print(val)
    #print(cmb(val, 2))
    total += val
    total += 2*cmb(val, 2)

for i in range(9):
    for j in range(i, 9):
        if i==j:
            continue
        else:
            total += 2*field[i,j]*field[j,i]
#print(field)
print(total)

Verdicts: Runtime Error

Accepted
Problem: Given is a positive integer N.   Find the number of pairs (A, B) of positive integers not greater than N that satisfy the following condition:    * When A and B are written in base ten without leading zeros, the last digit of A is equal to the first digit of B, and the first digit of A is equal to the last digit of B.

Submission attempts (in order):
import math,sys
from collections import Counter, defaultdict, deque
from sys import stdin, stdout
input = stdin.readline
lili=lambda:list(map(int,sys.stdin.readlines()))
li = lambda:list(map(int,input().split()))

I=lambda:int(input())
S=lambda:input().strip()
mod = 1000000007

a=[]
n=I()
for i in range(1,10):
    k=[]
    for j in range(1,10):
        k.append(0)
    a.append(k)
        

for i in range(1,n+1):
    if(i%10==0):
        continue
    k=str(i)
    p=int(k[0])-1
    q=int(k[-1])-1
    a[p][q]+=1
ans=0
for i in a:
    print(*i)
for i in range(0,9):
    for j in range(0,9):
        ans+=a[i][j]*a[j][i]
print(ans)


import math,sys
from collections import Counter, defaultdict, deque
from sys import stdin, stdout
input = stdin.readline
lili=lambda:list(map(int,sys.stdin.readlines()))
li = lambda:list(map(int,input().split()))

I=lambda:int(input())
S=lambda:input().strip()
mod = 1000000007

a=[]
n=I()
for i in range(1,10):
    k=[]
    for j in range(1,10):
        k.append(0)
    a.append(k)
        

for i in range(1,n+1):
    if(i%10==0):
        continue
    k=str(i)
    p=int(k[0])-1
    q=int(k[-1])-1
    a[p][q]+=1
ans=0

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


Verdicts: Wrong Answer

Accepted
Problem: Given is a positive integer N.   Find the number of pairs (A, B) of positive integers not greater than N that satisfy the following condition:    * When A and B are written in base ten without leading zeros, the last digit of A is equal to the first digit of B, and the first digit of A is equal to the last digit of B.

Submission attempts (in order):
n = int(input())

d = [[0]*10 for i in range(10)]

for i in range(1, n+1):
  i_ = str(i)
  x = int(i_[0])
  y = int(i_[-1])
  d[x][y] += 1
  
print(d)
ans = 0
for i in range(10):
  for j in range(10):
    ans += d[i][j]*d[j][i]
    
print(ans)

n = int(input())

L = [[0]*10 for j in range(10)]

for i in range(1, n+1):
    p = int(str(i)[0])
    s = int(str(i)[-1])
    L[p][s] += 1

ans = 0
for i in range(1, 10):
    for j in range(1, 10):
        ans += L[i][j] * L[j][i]
print(ans)

Verdicts: Wrong Answer

Accepted
Problem: Given is a positive integer N.   Find the number of pairs (A, B) of positive integers not greater than N that satisfy the following condition:    * When A and B are written in base ten without leading zeros, the last digit of A is equal to the first digit of B, and the first digit of A is equal to the last digit of B.

Submission attempts (in order):
N = int(input()) + 1

ans_list = [[0 for i in range(10)] for j in range(10)]
print(ans_list)

for i in range(N):
    s = str(i)
    ans_list[int(s[0])][int(s[-1])] += 1

ans = 0
for i in range(0,10):
    for j in range(0,10):
        ans += ans_list[i][j]*ans_list[j][i]

print(ans)

N = int(input()) + 1

ans_list = [[0 for i in range(10)] for j in range(10)]

for i in range(N):
    s = str(i)
    ans_list[int(s[0])][int(s[-1])] += 1

ans = 0
for i in range(0,10):
    for j in range(0,10):
        ans += ans_list[i][j]*ans_list[j][i]

print(ans)

N = int(input())

ans_list = [[0 for i in range(10)] for i in range(10)]

for i in range(N):
    s = str(i)
    ans_list[int(s[0])][int(s[-1])] += 1

ans = 0
for i in range(0,10):
    for j in range(0,10):
        ans += ans_list[i][j]*ans_list[j][i]

print(ans)

N = int(input()) + 1

ans_list = [[0 for i in range(10)] for j in range(10)]

for i in range(1,N):
    s = str(i)
    ans_list[int(s[0])][int(s[-1])] += 1

ans = 0
for i in range(0,10):
    for j in range(0,10):
        ans += ans_list[i][j]*ans_list[j][i]

print(ans)

Verdicts: Wrong Answer

Wrong Answer

Wrong Answer

Accepted
Problem: Given is a positive integer N.   Find the number of pairs (A, B) of positive integers not greater than N that satisfy the following condition:    * When A and B are written in base ten without leading zeros, the last digit of A is equal to the first digit of B, and the first digit of A is equal to the last digit of B.

Submission attempts (in order):
import math
def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
n = int(input())
ans_dict = {}
ans = 0
for i in range(1,10):
    for j in range(1,10):
        ans_dict[i*10+j]=0
for num in range(1,n+1):
    num_str =  str(num)
    i = int(num_str[len(num_str)-1])
    j = int(num_str[0])
    if (i!=0) & (j!=0):
        ans_dict[i*10+j] +=1
for key_ in ans_dict.keys():
    if str(key_)[0] == str(key_)[1]:
        ans += ans_dict[key_]**2
    else:
        key_s = key_//10+int(str(key_)[1])*10
        ans += ans_dict[key_] * ans_dict[key_s]
        ans_dict[key_s] = 0
print(ans)

import math
def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
n = int(input())
ans_dict = {}
ans = 0
for i in range(1,10):
    for j in range(1,10):
        ans_dict[i*10+j]=0
for num in range(1,n+1):
    num_str =  str(num)
    i = int(num_str[len(num_str)-1])
    j = int(num_str[0])
    if (i!=0) & (j!=0):
        ans_dict[i*10+j] +=1
print(ans_dict)
for key_ in ans_dict.keys():
    if str(key_)[0] == str(key_)[1]:
        ans += ans_dict[key_]**2
    else:
        key_s = key_//10+int(str(key_)[1])*10
        ans += ans_dict[key_] * ans_dict[key_s]*2
        ans_dict[key_s] = 0
print(ans)

import math
def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
n = int(input())
ans_dict = {}
ans = 0
for i in range(1,10):
    for j in range(1,10):
        ans_dict[i*10+j]=0
for num in range(1,n+1):
    num_str =  str(num)
    i = int(num_str[len(num_str)-1])
    j = int(num_str[0])
    if (i!=0) & (j!=0):
        ans_dict[i*10+j] +=1
for key_ in ans_dict.keys():
    if str(key_)[0] == str(key_)[1]:
        ans += ans_dict[key_]**2
    else:
        key_s = key_//10+int(str(key_)[1])*10
        ans += ans_dict[key_] * ans_dict[key_s]*2
        ans_dict[key_s] = 0
print(ans)

Verdicts: Wrong Answer

Wrong Answer

Accepted
Problem: Given is a positive integer N.   Find the number of pairs (A, B) of positive integers not greater than N that satisfy the following condition:    * When A and B are written in base ten without leading zeros, the last digit of A is equal to the first digit of B, and the first digit of A is equal to the last digit of B.

Submission attempts (in order):
import numpy as np

N = int(input())

l = np.zeros((9,9), dtype=np.int)


for k in range(N):
    x = str(k+1)
    i = int(x[0]) - 1
    j = int(x[-1]) - 1

    l[i][j] += 1

ans = 0
for i in range(9):
    for j in range(i,9):
        if i == j:
            n = l[i][j]
            ans += n**2
        else:
            ans += l[i][j] * l[j][i] * 2
            

print(ans)









#import numpy as np

N = int(input())

l = [ [ 0 for i in range(9) ] for j in range(9) ]



for k in range(N):
    x = str(k+1)
    i = int(x[0])
    j = int(x[-1])

    #print(i,j)

    if i == 0 or j == 0:
        continue
    l[i-1][j-1] += 1

ans = 0
for i in range(9):
    for j in range(i,9):
        if i == j:
            n = l[i][j]
            ans += n**2
        else:
            ans += l[i][j] * l[j][i] * 2
            

print(ans)









Verdicts: Wrong Answer

Accepted
Problem: Given is a positive integer N.   Find the number of pairs (A, B) of positive integers not greater than N that satisfy the following condition:    * When A and B are written in base ten without leading zeros, the last digit of A is equal to the first digit of B, and the first digit of A is equal to the last digit of B.

Submission attempts (in order):
# E
import fractions
N = int(input()) 
A = list(map(int, input().split()))

def main():
    value = A[0]
    for i in range(1, N):
        value = value * A[i] // fractions.gcd(value, A[i])

    z = 10**9+7
    ans = 0
    for i in A:
        ans += (value//i) % z

    print(ans % z)

if __name__=="__main__":
    main()

N = int(input()) 

ans=0
d = [10*[0] for _ in range(10)]

for i in range(1, N+1):
    s = str(i)
    if s[0]=="0" or s[-1]=="0":
        continue
    d[int(s[0])][int(s[-1])]+=1
    
for i in range(10):
    for j in range(10):
        ans+=d[i][j]*d[j][i]
print(ans)


Verdicts: Runtime Error

Accepted
Problem: Given is a positive integer N.   Find the number of pairs (A, B) of positive integers not greater than N that satisfy the following condition:    * When A and B are written in base ten without leading zeros, the last digit of A is equal to the first digit of B, and the first digit of A is equal to the last digit of B.

Submission attempts (in order):
n = int(input())
dic = {}
for i in range(11, 100):
    f, s = divmod(i, 10)
    tmp = 0
    for j in range(1, n):
        if str(j)[0]==str(f) and str(j)[-1]==str(s): tmp +=1
    dic[i] = tmp

print(dic)
ans = 0
for i in range(1, int(n)+1):
    s = str(i)
    if s[-1]=="0": continue
    ans += dic[int(s[-1]+s[0])]
print(ans)


n = int(input())
dic = {}
for i in range(10, 100): dic[str(i)]=0
for i in range(1, n+1):
    s = str(i)
    dic[s[0]+s[-1]] += 1

ans = 0
for i in range(1, n+1):
    s = str(i)
    if s[-1]=="0": continue
    ans += dic[s[-1]+s[0]]
print(ans)

Verdicts: Wrong Answer

Accepted
Problem: Given is a positive integer N.   Find the number of pairs (A, B) of positive integers not greater than N that satisfy the following condition:    * When A and B are written in base ten without leading zeros, the last digit of A is equal to the first digit of B, and the first digit of A is equal to the last digit of B.

Submission attempts (in order):
import sys
from scipy.misc import comb
def input(): return sys.stdin.readline().rstrip()

def main():
    n = int(input())
    
    ans = [0] * 100
    for i in range(n//2 + 1):
        if i < 10:
            ans[int(str(i) * 2)] += 1
            continue
        s = str(i)
        if s[0] != s[-1]:
            ans[int(s[0] + s[-1])] += 2
        else:
            ans[int(s[0] + s[-1])] += 1

    sum = 0
    for i in range(1, 10):
        for j in range(i, 10):
            data = ans[i * 10 + j]
            if data >= 2:
                sum += comb(data, 2, exact=True)
    print(sum)

if __name__ == '__main__':
    main()


import sys
def input(): return sys.stdin.readline().rstrip()

def main():
    n = int(input())
    
    res = [[0] * 10 for _ in range(10)]
    for i in range(1, n+1):
        s = str(i)
        if s[-1] == '0':
            continue
        res[int(s[0])][int(s[-1])] += 1

    ans = 0
    for i in range(1, 10):
        for j in range(1, 10):
            ans += res[i][j] * res[j][i]
    print(ans)

if __name__ == '__main__':
    main()

Verdicts: Wrong Answer

Accepted
Problem: Given is a positive integer N.   Find the number of pairs (A, B) of positive integers not greater than N that satisfy the following condition:    * When A and B are written in base ten without leading zeros, the last digit of A is equal to the first digit of B, and the first digit of A is equal to the last digit of B.

Submission attempts (in order):
def bunkai(n:int):
    ls=list(str(n))
    top,bottom=int(ls[0]),int(ls[-1])
    if n<=99:
        middle=0
    else:
        middle=int("".join(ls[1:-1]))
    return top, middle, bottom

n=int(input())
Nt,Nm,Nb = bunkai(n)

count=0
for i in range(1,n+1):
    t,m,b = bunkai(i)
    if b==0:continue
    if t==b:count+=1
    if n<=99:
        if int(b+t)<=n:count+=1
    else:
        keta = len(str(n))
        for x in range(keta-2):
            count+=10**x
        x+=1
        if Nt>b:
            count+=10**x
        elif Nt==b:
            if Nb>=t:
                count+=Nm+1
            else:
                count+=Nm
print(count)
    


def bunkai(n:int):
    ls=list(str(n))
    top,bottom=int(ls[0]),int(ls[-1])
    if n<=99:
        middle=0
    else:
        middle=int("".join(ls[1:-1]))
    return top, middle, bottom

n=int(input())
Nt,Nm,Nb = bunkai(n)

count=0
for i in range(1,n+1):
    t,m,b = bunkai(i)
    if b==0:continue
    if t==b:count+=1
    if n<=99:
        if int(str(b)+str(t))<=n:count+=1
    else:
        keta = len(str(n))
        for x in range(keta-2):
            count+=10**x
        x+=1
        if Nt>b:
            count+=10**x
        elif Nt==b:
            if Nb>=t:
                count+=Nm+1
            else:
                count+=Nm
print(count)
    


Verdicts: Wrong Answer

Accepted
Problem: Given is a positive integer N.   Find the number of pairs (A, B) of positive integers not greater than N that satisfy the following condition:    * When A and B are written in base ten without leading zeros, the last digit of A is equal to the first digit of B, and the first digit of A is equal to the last digit of B.

Submission attempts (in order):
N = int(input())
table = [[0]*10 for _ in range(10)]

for i in range(1, N+1):
    s = str(i)
    e1 = int(s[0])
    e2 = int(s[1])
    table[e1][e2] += 1

res = 0
for i in range(1, 10):
    for j in range(1, 10):
        res += table[i][j]*table[j][i]
print(res)

N = int(input())
table = [[0]*10 for _ in range(10)]

for i in range(1, N+1):
    s = str(i)
    e1 = int(s[0])
    e2 = int(s[-1])
    table[e1][e2] += 1

res = 0
for i in range(1, 10):
    for j in range(1, 10):
        res += table[i][j]*table[j][i]
print(res)

Verdicts: Runtime Error

Accepted
Problem: Given is a positive integer N.   Find the number of pairs (A, B) of positive integers not greater than N that satisfy the following condition:    * When A and B are written in base ten without leading zeros, the last digit of A is equal to the first digit of B, and the first digit of A is equal to the last digit of B.

Submission attempts (in order):
N=int(input())
ans=0
c=[[0 for _ in range(10)] for _ in range(10)]

for n in range(1,N+1):
    i=n%10
    j=n
    while 10<=k:
        j=j//10
    c[i][j]=c[i][j]+1

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

N=int(input())
ans=0
c=[[0 for _ in range(10)] for _ in range(10)]

for n in range(1,N+1):
    i=n%10
    j=n
    while 10<=j:
        j=j//10
    c[i][j]=c[i][j]+1

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

Verdicts: Runtime Error

Accepted
Problem: Given is a positive integer N.   Find the number of pairs (A, B) of positive integers not greater than N that satisfy the following condition:    * When A and B are written in base ten without leading zeros, the last digit of A is equal to the first digit of B, and the first digit of A is equal to the last digit of B.

Submission attempts (in order):
N = int(input())
ans = 0
l=[[0]*10 for _ in range(10)]
for i in range(1,2021):
  s = str(i)
  l[int(s[0])][int(s[-1])]+=1
  
for i in range(10):
  for j in range(10):
    ans+=l[i][j]*l[j][i]
    
print(ans)

N = int(input())
ans = 0
l=[[0]*10 for _ in range(10)]
for i in range(1,N+1):
  s = str(i)
  l[int(s[0])][int(s[-1])]+=1
  
for i in range(10):
  for j in range(10):
    ans+=l[i][j]*l[j][i]
    
print(ans)

Verdicts: Wrong Answer

Accepted
Problem: Given is a positive integer N.   Find the number of pairs (A, B) of positive integers not greater than N that satisfy the following condition:    * When A and B are written in base ten without leading zeros, the last digit of A is equal to the first digit of B, and the first digit of A is equal to the last digit of B.

Submission attempts (in order):
n = int(input())
f_dict = {}
s_dict = {}
cnt_all = 0
for i in range(n):
  moji = str(i+1)
  if f_dict[[moji[0]+moji[-1]] == "":
    f_dict[moji[0]+moji[-1]] = 0
  else:
    f_dict[[moji[0]+moji[-1]]+= 1 
  if s_dict[[moji[-1]+moji[0]] == "":
    f_dict[[moji[-1]+moji[0]] = 0
  else:
    f_dict[[moji[-1]+moji[0]] += 1
for mykey in f_dict.keys():
  cnt_all += f_dict[mykey] * s_dict[mykey]
print(cnt_all)

n = int(input())
f_dict = {}
s_dict = {}
cnt_all = 0
for i in range(n):
  moji = str(i+1)
  if f_dict[moji[0], moji[-1]] == "":
    f_dict[moji[0], moji[-1]] = 0
  else:
  	f_dict[moji[0], moji[-1]] += 1 
  if s_dict[moji[-1], moji[0]] == "":
    f_dict[moji[-1], moji[0]] = 0
  else:
  	f_dict[moji[-1], moji[0]] += 1
for mykey in f_dict.keys():
  cnt_all += f_dict[mykey] * s_dict[mykey]
print(cnt_all)

n = int(input())
f_dict = {}
s_dict = {}
cnt_all = 0
for i in range(n):
  moji = str(i+1)
  if f_dict[[moji[0], moji[-1]] == "":
    f_dict[moji[0], moji[-1]] = 0
  else:
    f_dict[[moji[0], moji[-1]]+= 1 
  if s_dict[[moji[-1], moji[0]] == "":
    f_dict[[moji[-1], moji[0]] = 0
  else:
    f_dict[[moji[-1], moji[0]] += 1
for mykey in f_dict.keys():
  cnt_all += f_dict[mykey] * s_dict[mykey]
print(cnt_all)

n = int(input())
f_dict = {}
s_dict = {}
cnt_all = 0
for i in range(n):
  moji = str(i+1)
  if not moji[0]+moji[-1] in f_dict:
    f_dict[moji[0]+moji[-1]] = 1
  else:
    f_dict[moji[0]+moji[-1]] += 1 
  if not moji[-1]+moji[0] in s_dict:
    s_dict[moji[-1]+moji[0]] = 1
  else:
    s_dict[moji[-1]+moji[0]] += 1
for mykey in f_dict.keys():
  if mykey in s_dict:
      cnt_all += f_dict[mykey] * s_dict[mykey]
print(cnt_all)

Verdicts: Runtime Error

Runtime Error

Runtime Error

Accepted
Problem: Given is a positive integer N.   Find the number of pairs (A, B) of positive integers not greater than N that satisfy the following condition:    * When A and B are written in base ten without leading zeros, the last digit of A is equal to the first digit of B, and the first digit of A is equal to the last digit of B.

Submission attempts (in order):
N = int(input())

dic = {}
for i in range(1,10):
  for j in range(1,10):
    dic[(str(i),str(j))] = 0

for i in range(N):
  nstr = str(i)
  pre = nstr[0]
  suf = nstr[-1]
  if suf == '0':
    continue
  dic[(pre, suf)] =dic[(pre, suf)] + 1

cnt = 0 
for i in range(1,10):
  for j in range(1,i+1):
    cnt += dic[(str(i),str(j))] * dic[(str(j),str(i))]
  
  
print(dic.values())

N = int(input())

dic = {}
for i in range(1,10):
  for j in range(1,10):
    dic[(str(i),str(j))] = 0

for i in range(N+1):
  nstr = str(i)
  pre = nstr[0]
  suf = nstr[-1]
  print(pre)
  print(suf)
  if suf == '0':
    continue
  dic[(pre, suf)] =dic[(pre, suf)] + 1

cnt = 0 
for i in range(1,10):
  for j in range(1,10):
    cnt += dic[(str(i),str(j))] * dic[(str(j),str(i))]

print(cnt)

N = int(input())

dic = {}
for i in range(1,10):
  for j in range(1,10):
    dic[(str(i),str(j))] = 0

for i in range(N+1):
  nstr = str(i)
  pre = nstr[0]
  suf = nstr[-1]
  if suf == '0':
    continue
  dic[(pre, suf)] =dic[(pre, suf)] + 1

cnt = 0 
for i in range(1,10):
  for j in range(1,10):
    cnt += dic[(str(i),str(j))] * dic[(str(j),str(i))]

print(cnt)

Verdicts: Wrong Answer

Wrong Answer

Accepted
Problem: Given is a positive integer N.   Find the number of pairs (A, B) of positive integers not greater than N that satisfy the following condition:    * When A and B are written in base ten without leading zeros, the last digit of A is equal to the first digit of B, and the first digit of A is equal to the last digit of B.

Submission attempts (in order):
n = int(input())
ans = 0
cnt = [[0] * 9 for _ in range(9)]
tmp = 0
for i in range(1, n + 1):
    one = str(i)
    two = list(str(i))
    two.reverse()
    two = ''.join(two)
    if one[-1] == '0':
        continue
    if one == two:
        tmp += 1
    cnt[int(one[0]) - 1][int(one[-1]) - 1] += 1
for i in range(9):
    for j in range(9):
        ans += cnt[j][i]
print(ans - tmp)

n = int(input())
ans = 0
cnt = [[0] * 9 for _ in range(9)]
tmp = 0
for i in range(1, n + 1):
    one = str(i)
    if one[-1] == '0':
        continue
    cnt[int(one[0]) - 1][int(one[-1]) - 1] += 1
for i in range(9):
    for j in range(9):
        ans += cnt[i][j] * cnt[j][i]
print(ans)

Verdicts: Wrong Answer

Accepted