TnT/Multi_CodeNet4Repair huggingface dataset:
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())
numMap = {}
answer = 0
def StartEnd(x):
    start = str(x)[0]
    end = str(x)[-1]
    return int(start), int(end)

for i in range(1, N+1):
    print('numMap:', numMap)
    pair = StartEnd(i)
    if pair in numMap:
        numMap[pair] += 1
    else:
        numMap[pair] = 1

for i in range(1, N+1):
    key = StartEnd(i)
    rev = key[::-1]
    print('rev:', rev)
    if rev in numMap:
        answer += numMap[rev]
    
print(answer)    



N = int(input())
numMap = {}
answer = 0
def StartEnd(x):
    start = str(x)[0]
    end = str(x)[-1]
    return start, end

for i in range(1, N+1):
    # print('numMap:', numMap)
    pair = StartEnd(i)
    if pair in numMap:
        numMap[pair] += 1
    else:
        numMap[pair] = 1

for i in range(1, N+1):
    key = StartEnd(i)
    rev = key[::-1]
    # print('rev:', rev)
    if rev in numMap:
        answer += numMap[rev]
    
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())
cheak =[[0]*9 for _ in range]
for i in range(1, n+1):
    s = str(i)
    s1 = int(s[0])-1
    s2 = int(s[-1])-1
    if s2 == 0:
        continue
    cheak[s1][s2] += 1

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


n = int(input())
cheak_box = [[0]*9 for _ in range(9)]

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

ans = 0
for p in range(9):
    for q in range(9):
        ans += cheak_box[p][q] * cheak_box[q][p]
        
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):
def main():
    N = int(input())
    print(solve(N))


def count(n, start, end):
    

    if n <= 9:
        return 1 if start == end and start <= n else 0
    if n <= 99:
        one_digit = 1 if start == end else 0
        two_digit = 1 if start * 10 + end <= n else 0
        return one_digit + two_digit
    digit_length = len(str(n))
    
    ret1 = count(10 ** (digit_length - 1) - 1, start, end)
    
    min_cand = start * (10 ** (digit_length - 1)) + end
    if min_cand > n:
        return ret1
    ret2 = min((n-min_cand) // 10 + 1, 10 ** (digit_length - 2))
    return ret1 + ret2


def solve(n):
    
    result = 0
    for i in range(1, 10):
        for j in range(i + 1, 10):
            result += 2 * count(n, i, j) * count(n, j, i)
    for i in range(1, 10):
        result += count(n, i, i) * count(n, i, i)
    return result


if __name__ == "__main__":
    assert_equal(count(732, 1, 2), 11)
    main()


def main():
    N = int(input())
    print(solve(N))


def count(n, start, end):
    

    if n <= 9:
        return 1 if start == end and start <= n else 0
    if n <= 99:
        one_digit = 1 if start == end else 0
        two_digit = 1 if start * 10 + end <= n else 0
        return one_digit + two_digit
    digit_length = len(str(n))
    
    ret1 = count(10 ** (digit_length - 1) - 1, start, end)
    
    min_cand = start * (10 ** (digit_length - 1)) + end
    if min_cand > n:
        return ret1
    ret2 = min((n-min_cand) // 10 + 1, 10 ** (digit_length - 2))
    return ret1 + ret2


def solve(n):
    
    result = 0
    for i in range(1, 10):
        for j in range(i + 1, 10):
            result += 2 * count(n, i, j) * count(n, j, i)
    for i in range(1, 10):
        result += count(n, i, i) * count(n, i, i)
    return result


if __name__ == "__main__":
    main()


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())
def side(n):
  list_n=list(str(n))
  start=int(list_n[0])
  end=int(list_n[-1])
  return [start,end]
def count_n(i,j):
  s=0
  for i in range(1,n+1):
    if side(i)==[i,j]:
      s+=1
  return s
ans=0
for i in range(0,9):
  for j in range(0,9):
    ans+=count_n(i,j)*count_n(j,i)
print(ans)

n=int(input())
from itertools import combinations
def dis(n):
  list_n=list(str(n))
  a=int(list_n[0])
  b=int(list_n[-1])
  return [a,b]
N=[_ for _ in range(1,n+1)]
comb=list(combinations(N,2))
s=0
for A,B in comb:
  if dis(A)[0]==dis(B)[1] and dis(B)[0]==dis(A)[1]:
    s+=1
t=0
for A in N:
  if dis(A)[0]==dis(A)[1]:
    t+=1
print(s+t)

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

ans=0
for i in range(1,10):
  for j in range(1,10):
    ans+=d[10*i+j]*d[10*j+i]
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):
n = int(input())
c = [[0 for i in range(10)] for j in range(10)]
for k in range(1, n + 1):
    i, j = int(str_k[0]), int(str_k[-1])
    c[int(str(k)[0])][int(str(k)[-1])] += 1

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

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

cnt = 0
for i in range(10):
    for j in range(10):
        cnt += c[i][j] * c[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())
s = str(n)
l = len(s)
k = min(int(s[0]),int(s[-1]))
if l == 1:
  print(n)
else:
  ans = (k*(k-1)//2 + k) * (9**(l-1)-1)//8
  ans += (n*(n-1)//2 - k*(k-1)//2 + 9-k) * (9**(l-2)-1)//8
  print(ans)



n = int(input())
res = [[0]*9 for _ in range(9)]
for i in range(1,n+1):
  a = i%10
  if a== 0: continue
  while i > 0:
    b = i%10
    i = i//10
  res[a-1][b-1] += 1


ans = 0

for i in range(9):
  for j in range(9):
    ans += res[i][j] * res[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):
def main2(N):
    
    lst = list()
    for i in range(1,10):
        lst.append([0]*9)

    for n in range(1, N+1):
        for i in range(1,10):
            for j in range(1,10):
                head = str(n)[0]
                tail = str(n)[-1]
                if i == int(head) and j == int(tail):
                    lst[i-1][j-1] += 1
    
    count = 0
    for i in range(0, len(lst)):
        for j in range(0, len(lst[i])):
            count += lst[i][j] * lst[j][i]

    print(count)

main2(N)

def main3(N):
    lst = list()
    for i in range(1, 10):
        lst.append([0]*9)

    for n in range(1, N+1):
        head = int(str(n)[0])
        tail = int(str(n)[-1])
        
        if tail != 0:
            lst[head-1][tail-1] += 1
        
    
    #    print(lst[i])
    
    count = 0
    for i in range(0, len(lst)):
        for j in range(0, len(lst[i])):
            count += lst[i][j] * lst[j][i]

    print(count)

N = int(input())
main3(N)


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())

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

for i in range(1, N+1):
    s = str(i)
    c[int(s[0])][int(s[-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]* 10 for i in range(10)]

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

ans = 0
for i in range(10):
    for j in range(10):
        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())

C = [[0]*10 for _ in range(10)]
for n in range(1, N+1):
    s = str(n)
    C[int[s[0]]][int[s[-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]*10 for _ in range(10)]
for n in range(1, N+1):
    s = str(n)
    C[int(s[0])][int(s[-1])] += 1

ans = 0
for i in range(10):
    for j in range(10):
        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())
t = [0 for _ in range(81)]
ans = 0
for i in range(1, 10):
    for l in range(1, 10):
        for q in range(1, N+1):
            s = 0
            a = str(i)[0]
            b = str(i)[-1]
            if int(a) == i and int(b) == l:
                s += 1
            t[9*(i - 1)+l - 1] += s
for i in range(1, N+1):
    a = str(i)[0]
    b = str(i)[-1]
    if b == "0":
        continue
    else:
        ans += t[9*(int(b)-1)+int(a)-1]
print(ans)


N = int(input())
t = [[0 for _ in range(9)] for l in range(9)]
ans = 0
for i in range(1, N+1):
    if len(str(i)) == 1:
        t[i-1][i-1] += 1
    elif str(i)[-1] != "0":
        t[int(str(i)[0])-1][int(str(i)[-1])-1] += 1
for i in range(1, N+1):
    a = str(i)[0]
    b = str(i)[-1]
    if b == "0":
        continue
    elif a == b:
        ans += t[(int(a)-1)][int(a)-1]
    else:
        ans += t[(int(b)-1)][int(a)-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 g(n):
    D = [[0]*10 for i in range(10)]
    for i in range(1,n+1):
        si = str(i)
        D[int(si[0])][int(si[-1])] += 1

    res = 0
    for i in range(10):
        for j in range(10):
            res += D[i][j]*D[j][i]
    return res
print(g(int(n)))


def g(n):
    D = [[0]*10 for i in range(10)]
    for i in range(1,n+1):
        si = str(i)
        D[int(si[0])][int(si[-1])] += 1

    res = 0
    for i in range(10):
        for j in range(10):
            res += D[i][j]*D[j][i]
    return res
print(g(int(input())))


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 = defaultdict(int)
for i in range(1, n+1):
    x = str(i)
    d[(int(x[0]), int(x[-1]))] += 1

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

from collections import defaultdict
n = int(input())
d = defaultdict(int)
for i in range(1, n+1):
    x = str(i)
    d[(int(x[0]), int(x[-1]))] += 1

ans = 0
for i in range(1, 10):
    for j in range(1, 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())
P=[0,0,0,0,0,0,0,0,0,0]
L=copy.deepcopy(P)
M=[L]*10
count=0
for i in range(1,N+1):
  a=int(str(i)[0])
  b=int(str(i)[-1])
  if L[b][a]!=0:
    count+=2*L[b][a]+1
  L[a][b]+=1

print(count)
    
  

N=int(input())
A=[[0 for i in range(10)] for j in range(10)]
for i in range(1,N+1):
  i=str(i)
  ii=len(i)
  A[int(i[0])][int(i[ii-1])]+=1
ans=0
for i in range(10):
  for j in range(10):
    ans+=A[i][j]*A[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())

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

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

print(ans)


n = int(input())

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

ans = 0
for i in range(10):
    for j in range(10):
        ans += table[i][j] * table[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):
from collections import defaultdict

def diverta192_b():
    N = int(input())
    P = [tuple(map(int, input().split())) for _ in range(N)]
    if len(P) == 1:
        print(1)  
        return

    dcnt = defaultdict(int)  
    for i in range(N):
        xi, yi = P[i]
        for j in range(i):
            xj, yj = P[j]
            dcnt[(xi-xj, yi-yj)] += 1
            dcnt[(xj-xi, yj-yi)] += 1  
    most = sorted(dcnt.values(), reverse=True)[0]  
    ans = N - most
    print(ans)

diverta192_b()

from collections import defaultdict

def abc152_d():
    N = int(input())
    freq = defaultdict(int)
    for i in range(1, N+1):
        s = str(i)
        freq[(s[0], s[-1])] += 1  

    ans = 0
    for i in range(1, N+1):
        s = str(i)
        ans += freq[(s[-1], s[0])]  
    print(ans)

abc152_d()

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):
s = int(input())
num = [[0 for i in range(10)] for j in range(10)]

ans = 0

for _ in range(n):
    i = _ + 1
    if i < 10:
        num[i][i] += 1
    elif i % 10 != 0:
        moji = str(i)
        num[int(moji[0])][int(moji[len(moji)-1])] += 1
    else:
        pass

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

print(ans)

s = int(input())
num = [[0 for i in range(10)] for j in range(10)]

ans = 0

for _ in range(n):
    i = _ + 1
    if i < 10:
        num[i][i] += 1
    elif i % 10 != 0:
        moji = str(i)
        num[int(moji[0])][int(moji[len(moji)-1])] += 1
    else:
        pass

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

for i in num:
    for j in i:
        print(j, " ", end="")
    print()

print(ans)

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

ans = 0

for _ in range(n):
    i = _ + 1
    if i < 10:
        num[i][i] += 1
    elif i % 10 != 0:
        moji = str(i)
        num[int(moji[0])][int(moji[len(moji)-1])] += 1
    else:
        pass

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

print(ans)

Verdicts: 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,A,B= map(int,input().split())
count = 0
for A in range(N):
  for B in range(N):
    if A[0:] == B[:-1] and A[:-1] == B[0]:
      count += 1
print(count)

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

for i in range(1,N+1):
  i = str(i)
  if i[0] == '0' or i[-1] == '0':
    pass
  else:
    l[int(i[0])][int(i[-1])] += 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: 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())

cnt = [[0 for _ in range(10)] for _ in range(10)]

for k in range(1, n+1):
    s = str(k)
    cnt[int(s[0])][int(s[-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())

cnt = [[0 for _ in range(10)] for _ in range(10)]

for k in range(1, n+1):
    s = str(k)
    cnt[int(s[0])][int(s[-1])] += 1
ans = 0
for i in range(10):
    for j in range(10):
        ans += cnt[i][j] * cnt[j][i]
print(ans)


N = int(input())

cnt = [[0 for _ in range(10)] for _ in range(10)]

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


Verdicts: 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):
def check(a, b):
    k = 1
    res = 0
    if a == b and (a <= N): res += 1
    while True:
        if (a * (10 ** k) + b) > N:
            break
        else:
            if len(str(N)) > (k+1) or str(N)[0] > str(a):
                res += 10 ** (k - 1)
                k += 1
                continue

            else :
                Q = N - (a * (10 ** k) + b)
                p = (1 + int(str(Q)[:-1]))
                res += p
                k += 1
    return res


def main():
    global N
    N = int(input())
    ans = 0
    for i in range(1, 10, 1):
        for j in range(1, 10, 1):
            a = check(i, j)
            b = check(j, i)
            ans += a * b
    print(ans)


if __name__ == '__main__':
    main()

def check(a, b):
    k = 1
    res = 0
    if a == b and (a <= N): res += 1
    while True:
        if (a * (10 ** k) + b) > N:
            break
        else:
            if len(str(N)) > (k+1) or str(N)[0] > str(a):
                res += 10 ** (k - 1)
                k += 1
                continue

            else :
                Q = N - (a * (10 ** k) + b)
                p = 1
                if len(str(Q)) > 1 :
                    p += (int(str(Q)[:-1]))
                res += p
                k += 1
    return res


def main():
    global N
    N = int(input())
    ans = 0
    for i in range(1, 10, 1):
        for j in range(1, 10, 1):
            a = check(i, j)
            b = check(j, i)
            ans += a * b
    print(ans)


if __name__ == '__main__':
    main()

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())

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

for _ in range(1, n+1):

    s=str(i)
    i=int(s[0])
    j=int(s[-1])

    number[i][j] += 1

count = 0
for i in range(10):

    for j in range(10):
        count += number[i][j]*number[j][i]

print(count)


n = int(input())

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

for _ in range(1, n+1):

    s=str(_)
    i=int(s[0])
    j=int(s[-1])

    number[i][j] += 1

count = 0
for i in range(10):

    for j in range(10):
        count += number[i][j]*number[j][i]

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())
lead_N = int(str(N)[0]) 
end_N = int(str(N)[len(str(N)) - 1])
ans = 0
#print(str(100)[len(str(100)) - 1])
for i in range(1, N + 1):
  lead = int(str(i)[0])
  end = int(str(i)[len(str(i)) - 1])
  
  if lead == end:
    ans += 1
  
  for j in range((len(str(N)) - 2) + 1):
    if end == 0:
      
      continue
    elif end > lead_N and j == (len(str(N)) - 2) :
      
      continue
    elif end == lead_N and j == (len(str(N)) - 2):
      
      

      ans += int(str(N)[1:len(str(N)) - 1])

      if lead <= end_N:
        ans += 1
      #print("b")
      pass
    else:
      
      ans += 10 ** j

print(ans)

N= int(input())
lead_N = int(str(N)[0]) 
end_N = int(str(N)[len(str(N)) - 1])
ans = 0
#print(str(100)[len(str(100)) - 1])
for i in range(1, N + 1):
  lead = int(str(i)[0])
  end = int(str(i)[len(str(i)) - 1])
  
  if lead == end:
    ans += 1
  
  for j in range((len(str(N)) - 2) + 1):
    if end == 0:
      
      continue
    elif end > lead_N and j == (len(str(N)) - 2) :
      
      continue
    elif end == lead_N and j == (len(str(N)) - 2):
      
      
      if len(str(N)) >= 3
        ans += int(str(N)[1:len(str(N)) - 1])

      if lead <= end_N:
        ans += 1
      #print("b")
      pass
    else:
      
      ans += 10 ** j

print(ans)

N= int(input())
lead_N = int(str(N)[0]) 
end_N = int(str(N)[len(str(N)) - 1])
ans = 0
#print(str(100)[len(str(100)) - 1])
for i in range(1, N + 1):
  lead = int(str(i)[0])
  end = int(str(i)[len(str(i)) - 1])
  
  if lead == end:
    ans += 1
  
  for j in range((len(str(N)) - 2) + 1):
    if end == 0:
      
      continue
    elif end > lead_N and j == (len(str(N)) - 2) :
      
      continue
    elif end == lead_N and j == (len(str(N)) - 2):
      
      

      ans += int(str(N)[1:len(str(N)) - 1])

      if lead <= end_N:
        ans += 1
      #print("b")
      pass
    else:
      
      ans += 10 ** j

print(ans)

N= int(input())
lead_N = int(str(N)[0]) 
end_N = int(str(N)[-1])
ans = 0
for i in range(1, N + 1):
  lead = int(str(i)[0])
  end = int(str(i)[-1])
  
  if lead == end:
    ans += 1
  
  for j in range((len(str(N)) - 2) + 1):
    if end == 0 or (end > lead_N and j == (len(str(N)) - 2)):
      
      continue
    elif end == lead_N and j == (len(str(N)) - 2):
      
      
      if len(str(N)) >= 3:
        ans += int(str(N)[1:-1])
      if lead <= end_N:
        ans += 1
    else:
      
      ans += 10 ** j

print(ans)

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):
def d():
    N = int(input())
    a = {}
    count = 0

    for i in range(1, N+1):
        l, r = str(i)[0], str(i)[-1]
        a[l, r] = a.get((l, r), 0) + 1

    # print(a)

    for i in range(1, N+1):
        l, r = str(i)[0], str(i)[-1]
        # print('a.get(({0}, {1}), 0) * a.get(({1}, {0}), 0) = {2}'.format(l,
                                                                         r, a.get((l, r), 0) * a.get((r, l), 0)))
        count += a.get((r, l), 0)

    print(count)


##########
d()


def d():
    N = int(input())
    a = {}
    count = 0

    for i in range(1, N+1):
        l, r = str(i)[0], str(i)[-1]
        a[l, r] = a.get((l, r), 0) + 1

    # print(a)

    for i in range(1, N+1):
        l, r = str(i)[0], str(i)[-1]
        # print('a.get(({0}, {1}), 0) * a.get(({1}, {0}), 0) = {2}'.format(l, r, a.get((l, r), 0) * a.get((r, l), 0)))
        count += a.get((r, l), 0)

    print(count)


##########
d()


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((N // 10) ** 2 + N % 5 + 8)

N = int(input())

c = [[0 for _ in range(9)] for _ in range(9)]

for n in range(1, N + 1):
  l = n % 10
  if l == 0:
    continue
  t = n // (10 ** (len(str(n)) - 1))
  c[t - 1][l - 1] += 1

ans = 0
for i in range(9):
  for j in range(9):
    ans += c[i][j] * c[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())

ans_1 = 0
for i in range(N):
  str_i = str(i)
  length = len(str_i)
  if str_i[0] == str_i[length-1]:
    ans_1 += 1

ans_2 = 0
for i in range(N // 2):
  if i <= 9:
    j = 0
    tmp_num =int(str(i)+str(j)+str(i))
    while tmp_num <= N:
      ans_2 += 1
      j += 1
      tmp_num =int(str(i)+str(j)+str(i))
   
  else:
    j = 0
    tmp_num =int(str(i[-1])+str(j)+str(i[0]))
    while tmp_num <= N:
      ans_2 += 1
      j += 1
      tmp_num =int(str(i[-1])+str(j)+str(i[0]))

print(ans_1+2*ans_2)
    
      

N = int(input())

ans_1 = 0
for i in range(N):
  str_i = str(i)
  length = len(str_i)
  if str_i[0] == str_i[length-1]:
    ans_1 += 1

ans_2 = 0
half = N // 2
for i in range(half):
  if i <= 9:
    j = 0
    tmp_num =int(str(i)+str(j)+str(i))
    while tmp_num <= N:
      ans_2 += 1
      j += 1
      tmp_num =int(str(i)+str(j)+str(i))
   
  else:
    j = 0
    tmp_num =int(str(i[-1])+str(j)+str(i[0]))
    while tmp_num <= N:
      ans_2 += 1
      j += 1
      tmp_num =int(str(i[-1])+str(j)+str(i[0]))

print(ans_1+2*ans_2)
    
      


N = int(input())

c = [[0 for i in range(9)] for j in range(9)]
for i in range(9):
    for j in range(9):
        c[str(i)[0]][str(j)[-1]] += 1

ans = 0
for i in range(9):
    for j in range(9):
        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+1):
    str_i = str(i)
    c[int(str_i[0])][int(str_i[-1])] += 1

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

print(ans)

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())

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

n=int(input())
D={}
for i in range(1,n+1):
    s=(str(i)[0],str(i)[-1])
    if s not in D:
        D[s]=1
    else:
        D[s]+=1
ans=0
for i in D:
    if (i[1],i[0]) in D:
        ans+=D[i]*D[i[1],i[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):
N = int(input())
l = [[0] * 10 for _ in range(10)]
ans = 0

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

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

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

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

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())
mem=[[0] * 10 for _ in range(10)]

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


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

for i in range(1, N+1):
    s = str(i)
    mem[int(s[0])][int(s[-1])] += 1 
    
ans = 0
for i in range(1, 10):
    for j in range(1, 10):
        ans += mem[i][j] * mem[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):
# -*- coding: utf-8 -*-

import sys

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 18
MOD = 10 ** 9 + 7

class BIT:
    """ Binary Indexed Tree """

    def __init__(self, n):
        # 0-indexed
        n += 1
        nv = 1
        while nv < n:
            nv *= 2
        self.size = nv
        self.tree = [0] * nv

    def sum(self, i):
        
        s = 0
        i += 1
        while i > 0:
            s += self.tree[i-1]
            i -= i & -i
        return s

    def add(self, i, x):
        
        i += 1
        while i <= self.size:
            self.tree[i-1] += x
            i += i & -i

    def get(self, l, r=None):
        
        
        if r is None: r = l + 1
        res = 0
        if r: res += self.sum(r-1)
        if l: res -= self.sum(l-1)
        return res

N = INT()
A = LIST()

bit = BIT(N)
ans = 0
for i in range(N):
    
    if bit.sum(A[i]) == 0:
        ans += 1
    bit.add(A[i], 1)
print(ans)


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

import sys

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 18
MOD = 10 ** 9 + 7

N = INT()

C = list2d(10, 10, 0)
for a in range(1, N+1):
    s = int(str(a)[0])
    t = int(str(a)[-1])
    C[s][t] += 1

ans = 0
for i in range(1, 10):
    for j in range(1, 10):
        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):
import numpy as np
n = int(input())
a = 10
b = 0
x = np.zeros((10, 10, ))
for i in range(1,n+1):
  while (i // a != 0):
    a = a * 10
  c = (i * 10) // a
  d = i % 10
  x[c][d] += 1

for i in range(0,10):
  for j in range(0,10):
    b += x[i][j] * x[j][i]
print(b)

n = int(input())
a = 10
b = 0
while (n // a != 0):
  a = a * 10
  b += 1
c = (n*10) //  a
d = n % 10
print(c,d)
if (b == 0):
  print(n)
elif (b == 1):
  m = 9
  if(d == 0):
    c += -1
    d = 10
  if(c > d):
    m += (c-2)*(c-1) +(2*d)
    m += 3*(c-1)
    print(m)
  else:
    m += c*(c-1)
    m += 3*c
    print(m)
elif(b == 2):
  m = 108
  e = (n % 100) //10
  if(c > d):
    m += 5*((c-1) * 10 + e)
    m += 2*(8*((c-1) * 10 + e)) + 2*d
    print(m)
  else:
    m += 5*((c-1) * 10 + e +1)
    m += 2*(8*((c-1) * 10 + e)) + 2*(d-1)
    print(m)
elif(b == 3):
  m = 1998
  e = (n % 100) //10
  if(c > d):
    m += 25*((c-1) * 10 + e)
    m += 22*(8*((c-1) * 10 + e)) + 22*d
    print(m)
  else:
    m += 25*((c-1) * 10 + e +1)
    m += 22*(8*((c-1) * 10 + e)) + 22*(d-1)
    print(m)
elif(b == 4):
  m = 20088
  e = (n % 100) //10
  if(c > d):
    m += 225*((c-1) * 10 + e)
    m += 225*(8*((c-1) * 10 + e)) + 225*d
    print(m)
  else:
    m += 225*((c-1) * 10 + e +1)
    m += 225*(8*((c-1) * 10 + e)) + 225*(d-1)
    print(m)
elif(b == 5):
  m = 202338
  e = (n % 100) //10
  if(c > d):
    m += 2225*((c-1) * 10 + e)
    m += 2222*(8*((c-1) * 10 + e)) + 2225*d
    print(m)
  else:
    m += 2225*((c-1) * 10 + e +1)
    m += 2225*(8*((c-1) * 10 + e)) + 2225*(d-1)
    print(m)

import numpy as np
n = int(input())
a = 10
b = 0
x = np.zeros((10, 10, ))
for i in range(1,n+1):
  while (i // a != 0):
    a = a * 10
  c = (i * 10) // a
  d = i % 10
  x[c][d] += 1

for i in range(0,10):
  for j in range(0,10):
    b += int(x[i][j] * x[j][i])
print(b)

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):
def calc_b(n,a):
    ans = 0
    str_n = str(n)
    str_a = str(a)
    if len(str_a) == 1:
        if int(str_a) <= n:
            print(a,str_a)
            ans += 1
        if int(str_a[0]+str_a[0]) <= n:
            print(a,str_a+str_a)
            ans += 1
    if len(str_a) == 2:
        if str_a[0] == str_a[1]:
            if int(str_a[0]) <= n:
                print(a,str_a[0])
                ans += 1
        if int(str_a[1]+str_a[0]) <= n:
            print(a,str_a[1]+str_a[0])
            ans += 1
    return ans

n = int(input())
kotae = 0
for i in range(1,n+1):
    if i%10!=0:
        #print(i)
        kotae += calc_b(n,i)
print(kotae)


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

def kazu(start_num,end_num):
    global memo
    if memo[start_num][end_num] > 0:
        #print('memo',start_num,end_num)
        return memo[start_num][end_num]
    else:
        ans = 0
        
        if start_num == end_num:
            if start_num <= n:
                #print(start_num)
                ans += 1
        
        if start_num * 10 + end_num <= n:
            
            ans += 1
        
        for i in range(10):
            if start_num * 100 + i * 10 + end_num <= n:
                
                ans += 1
            else:
                break
        
        for i in range(100):
            if start_num * 1000 + i * 10 + end_num <= n:
                
                ans += 1
            else:
                break
        
        for i in range(1000):
            if start_num * 10000 + i * 10 + end_num <= n:
                
                ans += 1
            else:
                break
        
        for i in range(10000):
            if start_num * 100000 + i * 10 + end_num <= n:
                
                ans += 1
            else:
                break
        memo[start_num][end_num] = ans
        #print(start_num,end_num,'---',ans)
        return ans

n = int(input())
str_n = str(n)
kotae = 0
#print(memo)
for a in range(1,n+1):
    if a%10!=0:
        str_a = str(a)
        #print('-----',a,'-----',int(str_a[-1]),int(str_a[0]))
        kotae += kazu(int(str_a[-1]),int(str_a[0]))
        #print(memo)
print(kotae)

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
import numpy as np

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

N = ir()

table = np.zeros((10, 10))
for x in range(1, N+1):
    x = str(x)
    i = int(x[0])
    j = int(x[-1])
    table[i][j] += 1

table = np.array(table)
answer = (table * table.T).sum()
print(answer)


import sys

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

N = ir()
count = [[0] * 10 for _ in range(10)] # dp[head][tail]
for i in range(1, N+1):
    s = str(i)
    head = int(s[0]); tail = int(s[-1])
    count[head][tail] += 1

answer = 0
for h in range(10):
    for t in range(10):
        answer += count[h][t] * count[t][h]
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())
C = [0]*100
for i in range(N):
  s = str(i)
  C[10*int(s[0])+int(s[-1])] += 1
print(sum([C[10*i+j]*C[10*j+i] for i in range(10) for j in range(10)]))

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


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())
l=[0]*10

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

ans=0
for i in range(l):
  ans+=i*i
print(ans)

N=int(input())
l=[[0]*10 for i in range(10)]


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

ans=0
for i in range(10):
  for j in range(10):
    ans+=l[i][j]*l[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):
def mainFunc():
    N = int(input())
    ans = 0

    for i in range(1, N + 1):
        tempAns = 1
        sentou = str(i)[0]
        saigo = str(i)[-1]
        
        if isRep(i, i):
            tempAns += 1
        
        for i in range(1, 10):
            if int(sentou + str(i) + saigo) <= N:
                tempAns += 1
            else:
                break
        
        for i in range(1, 100):
            if int(sentou + str(i).zfill(2) + saigo) <= N:
                tempAns += 1
            else:
                break
        
        for i in range(1, 1000):
            if int(sentou + str(i).zfill(3) + saigo) <= N:
                tempAns += 1
            else:
                break


    
    print(ans)

def isRep(i, j):
    sentoui = str(i)[0]
    saigoi = str(i)[-1]
    sentouj = str(j)[0]
    saigoj = str(j)[-1]

    if sentoui == saigoj and saigoi == sentouj:
        return True
    else:
        return False

mainFunc()

def mainFunc():
    N = int(input())
    matrix = [[0 for i in range(10)] for i in range(10)]
    for i in range(1, N + 1):
        start = int(str(i)[0])
        end = int(str(i)[-1])
        matrix[start - 1][end - 1] += 1
    
    ans = 0
    for i in range(10):
        for j in range(10):
            ans += matrix[i][j] * matrix[j][i]

    print(ans)


mainFunc()

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())

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

for i in range(n+1):
  if i % 10 != 0:
    str_i = str(i)
    mat[str_i[0]][str_i[-1]] += 1
c = 0
for y in range(1, 10):
  for x in range(y, 10):
    c += mat[y][x] * mat[x][y]
print(c)

n = int(input())

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

for i in range(n+1):
  if i % 10 != 0:
    str_i = str(i)
    mat[int(str_i[0])][int(str_i[-1])] += 1
c = 0
for y in range(1, 10):
  for x in range(y, 10):
    if y == x:
      c += mat[y][x] * mat[x][y]
    else:
      c += mat[y][x] * mat[x][y] * 2
print(c)


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):
cnt_1 = 0
cnt_2 = 0
for i in range(1,n+1):
    for j in range(i,n+1):
        
        #(1,1),(22,22),(333,333)
        if i==j and (str(i)[0]==str(j)[-1] and str(i)[-1]==str(j)[0]):
            cnt_1 += 1
        
        
        elif (str(i)[0]==str(j)[-1] and str(i)[-1]==str(j)[0]):
                cnt_2 += 1
print(cnt_1 + cnt_2*2)

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

def hoge(m):
    #return m[-1],m[0]
    return (m%10, int(str(m)[0]))

for k in range(1,n+1):
    a,b = hoge(k)
    cnt[a][b] += 1    

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

print(ret)

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):
def get_lmb(N):
    while (N >= 10):
        N = int(N/10)
    return N

def get_rmb(N):
    return N%10

def find_all():
    from collections import defaultdict
    dic = defaultdict(int)
    N = int(input())
    for i in range(1, N+1):
        lmb, rmb = get_lmb(i), get_rmb(i)
        dic[(lmb, rmb)] += 1
    print(dic)
    count = 0
    for i in range(1, 10):
        for j in range(1, 10):
            count += dic[(i, j)] * dic[(j, i)]
    
    
    return count

print(find_all())

def get_lmb(N):
    while (N >= 10):
        N = int(N/10)
    return N

def get_rmb(N):
    return N%10

def find_all():
    from collections import defaultdict
    dic = defaultdict(int)
    N = int(input())
    for i in range(1, N+1):
        lmb, rmb = get_lmb(i), get_rmb(i)
        dic[(lmb, rmb)] += 1
    # print(dic)
    count = 0
    for i in range(1, 10):
        for j in range(1, 10):
            count += dic[(i, j)] * dic[(j, i)]
    
    
    return count

print(find_all())

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())

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

for i in range(1, N+1):
    top = int(str(i)[0])
    end = int(str(i)[-1])
    num[top][end] += 1

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

print(count)

N = int(input())

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

for i in range(1, N+1):
    top = int(str(i)[0])
    end = int(str(i)[-1])
    num[top][end] += 1

count = 0
for i in range(10):
    for j in range(10):
        count += num[i][j] * num[j][i]

print(count)

Verdicts: Runtime Error

Accepted