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):
from sys import stdin

def calc(N):
    result = {}
    for i in range(10):
        result[str(i)] = 0

    for i in range(N):
        if (str(i)[0] == str(i)[-1]):
            result[str(i)[0]] += 1
    for k in result:
        result[k] = result[k] * (result[k] - 1)
    return result

if __name__ == '__main__':
    N = int(stdin.readline().rstrip())
    count = 0
    add_nums = calc(N)
    print(add_nums)
    for i in range(N):
        
        if (int(str(i)[::-1])) <= N and (not str(i)[-1] == '0'):
            count += 1
        if (str(i)[0] == str(i)[-1]) and (len(str(i)) > 1):
            count += add_nums[str(i)[0]]
    print(count)

N = int(input())
c = []
for i in range(10):
    c.append([0] * 10)
for i in range(N):
    s = str(i+1)
    i1 = int(s[0])
    i2 = int(s[-1])
    c[i1][i2] += 1
total = 0
for i in range(10):
    for j in range(10):
        total += c[i][j] * c[j][i]
print(total)

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
for i in range(1, 10):
  for j in range(1, 10):
    for k in range(1, n+1):
      a = 0
      b = 0
      K = str(k)
      if K[0] == str(i) and K[-1] == str(j):
        a += 1
      if K[0] == str(j) and K[-1] == str(i):
        b += 1
    ans += a*b
print(ans)


n = int(input())
li_a = []
for i in range(9):
  li_a.append([0,0,0,0,0,0,0,0,0])
for i in range(1, n+1):
  k = str(i)
  k0 = int(k[0])
  k1 = int(k[-1])
  if k0*k1 != 0:
    li_a[k0-1][k1-1] += 1
ans = 0
for i in range(9):
  for j in range(9):
    ans += li_a[i][j]*li_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())
l=[[0]*10for _ in range(10)]
for x in range(1,n+1):l[a=int(str(x)[0])][b=int(str(x)[-1])]+=1
print(sum(l[i][j]*l[j][i]for i in range(10)for j in range(10)))

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

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
n = int(input())
d = defaultdict(int)
for i in range(1, n+1):
  s = str(i)
  d[(i[0], i[1])]+=1
ans = 0
for i, j in d.items():
  ans+=j*d[i[::-1]]
print(ans)

from collections import defaultdict
n = int(input())
d = defaultdict(int)
for i in range(1, n+1):
  s = str(i)
  d[(i[0], i[-1])]+=1
ans = 0
for i, j in d.items():
  ans+=j*d[i[::-1]]
print(ans)

from collections import defaultdict
n = int(input())
d = defaultdict(int)
for i in range(1, n+1):
  s = str(i)
  d[(s[0], s[-1])]+=1
ans = 0
x = list(d.keys())
for i in x:
    ans+=d[i[::-1]]*d[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 = int(input())

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

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

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

print(ans)

N = int(input())

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

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

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

print(ans)


N = int(input())

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

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

ans = 0
for i in range(10):
    for j in range(10):
        ans += A[i][j] * A[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 = input()
count = 0

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

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

for i in range(1, n+1):
  start, end = str(i)[0], str(i)[-1]
  d[(start, end)] = d.get((start, end), 0) + 1
count = 0
for key, n_key in d.items():
  count += n_key * d.get(tuple(reversed(key)), 0)
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())
nl = str(n)
ll = len(nl)
lis = []
ans = 0
if ll == 1:
  print(n)
  exit()
  
def countn(a,b):
  cur = 0
  for i in range(1,n+1):
    fff=str(i)
    if fff[0] == a and fff[-1] == b:
      cur += 1
  return cur

for i in range(1, 10):
  for j in range(1, i+1):
    if i == j:
      ans += countn(i, j)*countn(j, i)
    else:
      ans += 2*countn(i, j)*countn(j, i)
print(ans)

n = int(input())
nl = str(n)
ll = len(nl)
lis = []
ans = 0
if ll == 1:
  print(n)
  exit()
  
def countn(a,b):
  cur = 0
  if ll >= 3:
    cur += (10**(ll-2)-1)//9
    if a < int(nl[0]):
      cur += 10**(ll-2)
    elif a == int(nl[0]):
      nnl = nl[1:ll-1]
      if b > int(nl[-1]):
        cur += int(nnl)
      else:
        cur += (int(nnl)+1)
  elif ll == 2:
    if 10*a+b <= n:
      cur += 1
  if a == b:
    cur += 1
  return cur

for i in range(1, 10):
  for j in range(1, i+1):
    if i == j:
      ans += countn(i, j)*countn(j, i)
    else:
      ans += 2*countn(i, j)*countn(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())
l = len(n)
c = [[0 for _ in range(9)] for _ in range(9)]

for i in range(1, n+1):
  c[i[0]-1][i[-1]-1] += 1

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

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

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

res = 0
for i in range(10):
  for j in range(10):
    res += c[i][j] * c[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):
d=[0]*100
for i in range(int(input())+1):
  s=str(i)
  d[int(s[0])*10+int(s[-1])]+=1
print(sum(d[i]*d[i%10*10+i//10]for i in range(100)))

d=[0]*100
for i in range(int(input())):s=str(i+1);d[int(s[0]+s[-1])]+=1
print(sum(d[i]*d[i%10*10+i//10]for i in range(100)))

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 functools import reduce
def lcm_base(x, y):
    return (x * y) // gcd(x, y)

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

def gcd(a, b):
    while b:
        a, b = b, a % b
    return a

n = int(input())
A = [int(i) for i in input().split()]
k = lcm_list(A)
r = 0
for i in range(n):
    r += k//A[i]
    if r > 10**9+7:
        r %= 10**9+7
print(r)

n = int(input())
C = [[0]*10 for _ in range(10)]
for i in range(1,n+1):
    C[int(str(i)[0])][int(str(i)[-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())
a = [0] * 100
for i in range(1,n+1):
  msb = str(i)[0]
  lsb = str(i)[-1]
  if msb == '0' or lsb == '0':
    continue
  a[int(msb) * 10 + int(lsb)] += 1

tmp = 0
for i, ai in enumerate(a):
  if '0' not in str(i):
    if i % 11 == 0:
      tmp += ai * ai
    else:
      tmp += ai * a[int(str(i)[::-1])]
  else:
    continue
    
print(tmp)
print(a)

n = int(input())
a = [0] * 100
for i in range(1,n+1):
  msb = str(i)[0]
  lsb = str(i)[-1]
  if msb == '0' or lsb == '0':
    continue
  a[int(msb) * 10 + int(lsb)] += 1

tmp = 0
for i, ai in enumerate(a):
  if '0' not in str(i):
    if i % 11 == 0:
      tmp += ai * ai
    else:
      tmp += ai * a[int(str(i)[::-1])]
  else:
    continue
    
print(tmp)

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
for i in range(n):
    for j in range(i,n):
        if str(i+1)[-1] == str(j+1)[0] and str(i+1)[0] == str(j+1)[-1]:
            num += 1

print(num)


n = int(input())

num = 0

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

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

print(num)


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

def f(x):
    a1 = int(str(x)[0])
    a2 = x%10
    return (a1, a2)

count = {}
for x in range(1, n+1):
    key = f(x)
    if key in count:
        count[key] += 1
    else:
        count[key] = 1

ans = 0
for x in range(1, n+1):
    a0, a1 = f(x)
    if a1 != 0:        # !
        key = (a1, a0) # swap
        ans += count[key]

print(ans)

from collections import defaultdict
n = int(input())

def f(x):
    a1 = int(str(x)[0])
    a2 = x%10
    return (a1, a2)

count = defaultdict(int)
for x in range(1, n+1):
    key = f(x)
    count[key] += 1

ans = 0
for x in range(1, n+1):
    a0, a1 = f(x)
    if a1 != 0:        # !
        key = (a1, a0) # swap
        ans += count[key]

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=input()
intn=int(n)
ln=len(n)

if intn<10:
  print(n)
  quit()

def count(i,j):
  res=0
  if i==j:
    res+=1
  if ln==2:
    if 10*i+j<=n:
      res+=1
  else:
    res+=(10**(ln-2)-1)//9
    if i<int(n[0]):
      res+=10**(ln-2)
    elif i==int(n[0]):
      tn=int(n[1:-1])
      if j<=intn%10:
        res+=tn+1
      else:
        res+=tn
  return res

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

n=input()
intn=int(n)
ln=len(n)

if intn<10:
  print(n)
  quit()

def count(i,j):
  res=0
  if i==j:
    res+=1
  if ln==2:
    if 10*i+j<=intn:
      res+=1
  else:
    res+=(10**(ln-2)-1)//9
    if i<int(n[0]):
      res+=10**(ln-2)
    elif i==int(n[0]):
      tn=int(n[1:-1])
      if j<=intn%10:
        res+=tn+1
      else:
        res+=tn
  return res

res=0
for i in range(1,10):
  for j in range(1,10):
    res+=count(i,j)*count(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())
lists=[[ 0 for j in range(10)]for i in range(10)]
for i in range(1,n+1):
    a=str(i)
    lists[int(a[0])][int(a[-1])]+=1
c=0
for i in range(1,10):
    for j in range(1,10):
        c+=lists[i][j])*lists[j][i]
print(c)        


n=int(input())
lists=[[ 0 for j in range(10)]for i in range(10)]
for i in range(1,n+1):
    a=str(i)
    lists[int(a[0])][int(a[-1])]+=1
c=0
for i in range(1,10):
    for j in range(1,10):
        c+=lists[i][j]*lists[j][i]
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):
from math import log10
N = int(input())
 
C = 0
for i in range(1,10):
  for j in range(1,10):
    cij = 0
    cji = 0
    for k in range(1,N+1):
      m = log10(k) + 1
      if k//10**m == i and k%10 == j:
        cij += 1
      if k//10**m == j and k%10 == i:
        cji += 1
    C += cij*cji
print(C)

import numpy as np
N = int(input())

def f(x):
  a = x%10
  b = 0
  while x > 0:
    b = x
    x //= 10
  return a,b

freq = np.zeros((10,10), dtype=int)
for k in range(1,N+1):
  a,b = f(k)
  freq[a,b] += 1

print((freq*freq.T).sum())

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

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

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

N=int(input())

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


N=int(input())

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


N=int(input())
L=[[0]*10 for i in range(10)]
for i in range(1,N+1):
    n=str(i)
    first=int(n[0])
    last=int(n[-1])
    L[first-1][last-1]+=1
ans=0
for i in range(1,N+1):
    n=str(i)
    first=int(n[0])
    last=int(n[-1])
    ans+=L[last-1][first-1]

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

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

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

    if first == 0 or last == 0:
        continue
    else:
        count[first][last] += 1

ans = 0
for first in range(1,10):
    ans += count[first][last] * count[last][first]

print(ans)

n = int(input())

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

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

    if first == 0 or last == 0:
        continue
    else:
        count[first][last] += 1

ans = 0
for first in range(1,10):
  for last in range(1,10):
    ans += count[first][last] * count[last][first]
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())

BegEndTbl = []
for _ in range(10):
    BegEndTbl.append([0] * 10)
print(BegEndTbl)

ans = 0
for i in range(1, N + 1):
    left = int(str(i)[0])
    right = i % 10
    if left == right:
        ans += 1
    ans += BegEndTbl[right][left] * 2
    BegEndTbl[left][right] += 1
print(ans)

N = int(input())

BegEndTbl = []
for _ in range(10):
    BegEndTbl.append([0] * 10)

ans = 0
for i in range(1, N + 1):
    left = int(str(i)[0])
    right = i % 10
    if left == right:
        ans += 1
    ans += BegEndTbl[right][left] * 2
    BegEndTbl[left][right] += 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):
from collections import defaultdict
N = int(input())
ans = 0
c = defaultdict(int)

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

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

from collections import defaultdict
N = int(input())
ans = 0
c = defaultdict(int)

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

for i in range(1, 10):
  for j in range(1, 10):
    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())

N_s = int(str(N)[0])
N_e = int(str(N)[-1])
if len(str(N)) > 2:
    N_mid = int(str(N)[1:-1])
else:
    N_mid = 0

def search(s, e):
    ans = 0
    for i in range(1, len(str(N))+1):
        if i == 1:
            if s == e and s <= N:
                ans += 1
                continue
        else:
            if i != len(str(N)):
                ans += 10**(i-2)
            else:
                if N_s > s:
                    ans += 10**(i-2)
                elif N_s == s:
                    if N_e >= e:
                        ans += N_mid + 1
                    else:
                        ans += N_mid

    return ans

ret = 0
for i in range(1, 10):
    for j in range(1, 10):
        print(i,j,search(i, j),search(j, i))
        ret += search(i, j) *  search(j, i)
print(ret)

N = int(input())

N_se = int(str(N)[0] + str(N)[-1])
if len(str(N)) > 2:
    N_mid = int(str(N)[1:-1])
else:
    N_mid = 0

def search(s, e):
    ans = 0
    se = int(str(s) + str(e))
    for i in range(1, len(str(N))+1):
        if i == 1:
            if s == e and s <= N:
                ans += 1
                continue
        else:
            if i != len(str(N)):
                ans += 10**(i-2)
            else:
                if N_se > se:
                    ans += 10**(i-2)
                elif N_se == se:
                    ans += N_mid

    return ans

ret = 0
for i in range(1, 10):
    for j in range(1, 10):
        print(i, j, search(i, j), search(j, i))
        ret += search(i, j) *  search(j, i)
print(ret)

N = int(input())

N_s = int(str(N)[0])
N_e = int(str(N)[-1])
if len(str(N)) > 2:
    N_mid = int(str(N)[1:-1])
else:
    N_mid = 0

def search(s, e):
    ans = 0
    for i in range(1, len(str(N))+1):
        if i == 1:
            if s == e and s <= N:
                ans += 1
                continue
        else:
            if i != len(str(N)):
                ans += 10**(i-2)
            else:
                if N_s > s:
                    ans += 10**(i-2)
                elif N_s == s:
                    if N_e >= e:
                        ans += N_mid + 1
                    else:
                        ans += N_mid

    return ans

ret = 0
for i in range(1, 10):
    for j in range(1, 10):
        ret += search(i, j) *  search(j, i)
print(ret)

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
tmp = int(str(N)[1:-1])
NR = int(str(N)[-1])
for i in range(1,N+1):
    L = int(str(i)[0])
    R = int(str(i)[-1])
    if R == 0:
        continue
    if L == R:
        ans += 1
    for j in range(1,6):
        mini = (R*10**j) +L
        maxi = ((R+1)*10**j) +L-10
        if N < mini:
            break
        if maxi <= N:
            ans += 10**(j-1)
            continue
        
        if L <= NR:
            ans += tmp+1
        else:
            ans += tmp
        break
print(ans)




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

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

ans = 0

for i in range(10):
    for j in range(10):
        ans += lis[i][j]*lis[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())
from numpy import zeros
A = zeros((10,10))
 
for i in range(1,N+1):
  a = int(str(i)[0])
  b = int(str(i)[-1])
  A[a][b] += 1
 
cnt = 0
for _ in range(1,N+1):
  a = int(str(_)[0])
  b = int(str(_)[-1])
  cnt += A[b][a]
  
print(cnt)

from numpy import zeros
 
N = int(input())
A = zeros((10,10))
 
for i in range(1,N+1):
  a = int(str(i)[0])
  b = int(str(i)[-1])
  A[a][b] += 1
 
cnt = 0
for _ in range(1,N+1):
  a = int(str(_)[0])
  b = int(str(_)[-1])
  cnt += A[b][a]
  
print(cnt)

from numpy import zeros
 
N = 25
A = zeros((10,10))
 
for i in range(1,N+1):
  a = int(str(i)[0])
  b = int(str(i)[-1])
  A[a][b] += 1
 
cnt = 0
for _ in range(1,N+1):
  a = int(str(_)[0])
  b = int(str(_)[-1])
  cnt += A[b][a]
  
print(cnt)

from numpy import zeros

N = int(input())
A = zeros((10,10))

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

cnt = 0
for l in range(1,N+1)
  a = int(str(i)[0])
  b = int(str(i)[0])
  cnt += A[s][t]
  
print(cnt)

from numpy import zeros
 
N = int(input())
A = zeros((10,10))
 
for i in range(1,N+1):
  a = int(str(i)[0])
  b = int(str(i)[-1])
  A[a][b] += 1
 
cnt = 0
for _ in range(1,N+1):
  a = int(str(_)[0])
  b = int(str(_)[-1])
  cnt += A[b][a]
  
print(cnt)

N = int(input())
A =[[0]*10 for i in range(10)]
 
for i in range(1,N+1):
  a = int(str(i)[0])
  b = int(str(i)[-1])
  A[a][b] += 1
 
cnt = 0
for _ in range(1,N+1):
  a = int(str(_)[0])
  b = int(str(_)[-1])
  cnt += A[b][a]
  
print(cnt)

Verdicts: Wrong Answer

Wrong Answer

Wrong Answer

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

c = [[0] * 10] * 10
for x in range(1, N+1):
    check = str(x)
    it = int(check[0])
    jt = int(check[-1])
    c[it][jt] += 1

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

print(ans)



N = int(input())

c = [[0 for _ in range(10)] for __ in range(10)]
for x in range(1, N+1):
    check = str(x)
    it = int(check[0])
    jt = int(check[-1])
    c[it][jt] += 1

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

print(cnt)
    
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] * 10 for i in range(10)]
for i in range(1,n+1):
    cnt[int(str(i)[0])][int(str(i)[-1])] += 1
    
ans = 0
for i in range(10):
    for j in range(10):
        ans += cnt[i][j] * cnt[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):
ii = lambda : int(input())
mi = lambda : map(int,input().split())
li = lambda : list(map(int,input().split()))

n = ii()
dp = [0]*(n+1)
for i in range(1,n+1):
    s = str(i)
    if s[0] == s[-1]:
        dp[int(s[0])] += 1
    elif s[-1] == "0":
        continue
    else:
        ima = int(s[0])*10 + int(s[-1])
        dp[ima] += 1
ans = 0
for i in range(1,100):
    s = str(i)
    if s[0] == s[-1]:
        ans += dp[int(s[0])]**2
        dp[int(s[0])] = 0
    elif s[-1] == "0":
        continue
    else:
        ima = int(s[0])*10 + int(s[-1])
        ima2 = int(s[-1])*10 + int(s[0])
        ans += dp[ima] * dp[ima2] *2
        dp[ima] = 0
        dp[ima2] = 0
print(ans)



ii = lambda : int(input())
mi = lambda : map(int,input().split())
li = lambda : list(map(int,input().split()))

n = ii()
dp = [0]*(n+1)
for i in range(1,n+1):
    s = str(i)
    if s[0] == s[-1]:
        dp[int(s[0])] += 1
    elif s[-1] == "0":
        continue
    else:
        ima = int(s[0])*10 + int(s[-1])
        dp[ima] += 1
ans = 0
for i in range(1,min(100,n+1)):
    s = str(i)
    if s[0] == s[-1]:
        ans += dp[int(s[0])]**2
        dp[int(s[0])] = 0
    elif s[-1] == "0":
        continue
    else:
        ima = int(s[0])*10 + int(s[-1])
        ima2 = int(s[-1])*10 + int(s[0])
        ans += dp[ima] * dp[ima2] *2
        dp[ima] = 0
        dp[ima2] = 0
print(ans)

ii = lambda : int(input())
mi = lambda : map(int,input().split())
li = lambda : list(map(int,input().split()))

n = ii()
dp = [0]*max(101,(n+1))
for i in range(1,n+1):
    s = str(i)
    if s[0] == s[-1]:
        dp[int(s[0])] += 1
    elif s[-1] == "0":
        continue
    else:
        ima = int(s[0])*10 + int(s[-1])
        dp[ima] += 1
ans = 0
for i in range(1,min(100,n+1)):
    s = str(i)
    if s[0] == s[-1]:
        ans += dp[int(s[0])]**2
        dp[int(s[0])] = 0
    elif s[-1] == "0":
        continue
    else:
        ima = int(s[0])*10 + int(s[-1])
        ima2 = int(s[-1])*10 + int(s[0])
        ans += dp[ima] * dp[ima2] *2
        dp[ima] = 0
        dp[ima2] = 0
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 = int(input())

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

for i in range(1,N+1):
    a = N % 10
    b = 0
    while N > 0:
        b = N
        N = N // 10
    c[a][b] += 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):
    a = i % 10
    b = 0
    while i > 0:
        b = i
        i = i // 10
    c[a][b] += 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

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(N):
    for k in range(N):
        if str(i)[0] == str(k)[len(str(k)) - 1] and str(k)[0] == str(k)[len(str(k)) - 1]:
            cnt += 1
            
print(cnt) 

N = int(input())

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

cnt = 0

for i in range(1, N+1):
    head = int(str(i)[0])
    tail = int(str(i)[len(str(i)) - 1])
    list[head][tail] += 1

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

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]*9]*9
for  i in range(1,n):
  if i%10:
    l[int(str(i)[0])-1][int(str(i)[-1])-1]+=1
ans=0
for i in range(9):
  for j in range(9):
    ans+=l[i][j]*l[j][i]
print(ans)

n=int(input())
l=[[0 for i in range(10)]for s in range(10)]
for  i in range(n+1):
  if i%10:
    l[int(str(i)[0])-1][int(str(i)[-1])-1]+=1
ans=0
for i in range(9):
  for j in range(9):
    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())
TT = [[0]*10 for i in range(10)]

for i in range(N+1):
    top = int(str(i)[0])
    tail = int(str(i)[-1])
    TT[top][tail] += 1
print(TT)
y = 0
for i in range(1,10):
    for j in range(1,10):
        y += TT[i][j]*TT[j][i]
print(y)

import numpy as np
N = int(input())

TT = np.zeros((10,10))

for i in range(N+1):
    top = int(str(i)[0])
    tail = int(str(i)[-1])
    TT[top,tail] += 1
print(TT)
y = 0
for i in range(1,10):
    for j in range(1,10):
        y += TT[i,j]*TT[j,i]
print(int(y))

import numpy as np
N = int(input())

TT = np.zeros((10,10))

for i in range(N+1):
    top = int(str(i)[0])
    tail = int(str(i)[-1])
    TT[top,tail] += 1
#print(TT)
y = 0
for i in range(1,10):
    for j in range(1,10):
        y += TT[i,j]*TT[j,i]
print(int(y))

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 sys
import defaultdict
N = int(sys.stdin.readline())
cnt = defaultdict(int)
for i in range(1, N+1):
  str_i = str(i)
  cnt[(str_i[0], str_i[-1])] += 1

ans = 0
for d1 in range(9):
  for d2 in range(9):
    ans += cnt[(d1, d2)] * cnt[(d2, d1)]
return ans
    

import sys
from collections import defaultdict
N = int(sys.stdin.readline())
cnt = defaultdict(int)
for i in range(1, N+1):
  str_i = str(i)
  cnt[(str_i[0], str_i[-1])] += 1
 
ans = 0
for d1 in range(1, 10):
  for d2 in range(1, 10):
    d1, d2 = str(d1), str(d2)
    ans += cnt[(d1, d2)] * cnt[(d2, d1)]
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())
sample = [0] * 100

for i in range(1,N+1):

    num = str(i)
    first = num[0]
    final = num[-1]
    print(first)
    print(final)

    sample[int(first+final)] += 1
    print(int(first+final))

ans = 0

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

print(ans)


    


N = int(input())
sample = [0] * 100

for i in range(1,N+1):

    num = str(i)
    first = num[0]
    final = num[-1]
    
    sample[int(first+final)] += 1

ans = 0

for i in range(1,10):
    for j in range(1,10):
        ans += sample[int(str(i)+str(j))] * sample[int(str(j)+str(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())
t = [0] * 100
for i in range(11, 100):
  msb = i // 10
  lsb = i % 10
  if lsb == 0:
    continue
  for j in range(1, n+1):
    if j % 10 == lsb and int(str(j)[0]) == msb:
      t[i] += 1

ans = 0
for i in range(11, 100):
  msb = i // 10
  lsb = i % 10
  if lsb == 0:
    continue
  if msb == lsb:
    ans += t[i] * (t[i] - 1) // 2
  else:
    ans += t[i] * t[lsb * 10 + msb]
print(ans)

n = int(input())
t = [0] * 100
for i in range(11, 100):
  msb = i // 10
  lsb = i % 10
  if lsb == 0:
    continue
  for j in range(1, n+1):
    if j % 10 == lsb and int(str(j)[0]) == msb:
      t[i] += 1

ans = 0
for i in range(11, 100):
  msb = i // 10
  lsb = i % 10
  if lsb == 0:
    continue
  if msb == lsb:
    ans += t[i] ** 2
  else:
    ans += t[i] * t[lsb * 10 + msb]
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())
S=str(N)
keta=1
temp=N
while temp//10>0:
  keta+=1
  temp//=10
print(keta)
ans=0
for i in range(1,N):
  n=str(i)
  a=n[0]
  b=n[-1]
  cur_keta=len(n)
  if cur_keta<keta:
    if a==b:
      ans+=10*max(cur_keta-2,0)
    else:
      ans+=10*max(cur_keta-2,0)-1
  else:
    if a<b:
      pass
    else:
      Si=S[1:-2]
      if len(Si)>0:
        ans+=int(Si)
      
print(ans)      
      
    

import sys
readline = sys.stdin.readline

N = int(readline())

from collections import defaultdict
dic = defaultdict(int)

for i in range(1, N + 1):
  s = str(i)
  dic[(int(s[0]),int(s[-1]))] += 1
  
ans = 0
for i in range(1, 10):
  for j in range(1, 10):
    ans += dic[(i,j)] * dic[(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_lis = [[0] * 9 for i in range(9)]
for i in range(1,N+1):
  t = str(i)
  mae = int(t[0])
  ushiro = int(t[-1])
  if usiro == 0:
    continue
  ans_lis[mae-1][ushiro-1] += 1
ans = 0
for i in range(9):
  for j in range(9):
    ans += ans_lis[i][j] * ans_lis[j][i]
print(ans)


N = int(input())
ans_lis = [[0　for k in range(9)] for i in range(9)]
for i in range(1,N+1):
  t = str(i)
  mae = int(t[0])
  ushiro = int(t[-1])
  ans_lis[mae-1][ushiro-1] += 1
ans = 0
for i in range(9):
  for j in range(9):
    ans += ans_lis[i][j] * ans_lis[j][i]
print(ans)


N = int(input())
ans_lis = [[0　for k in range(9)] for i in range(9)]
for i in range(1,N+1):
  t = str(i)
  mae = int(t[0])
  ushiro = int(t[-1])
  if ushiro == 0:
    continue
  ans_lis[mae-1][ushiro-1] += 1
ans = 0
for i in range(9):
  for j in range(9):
    ans += ans_lis[i][j] * ans_lis[j][i]
print(ans)


N = int(input())
ans_lis = [[0　for _ in range(9)] for  i in range(9)]
for i in range(1,N+1):
  t = str(i)
  mae = int(t[0])
  ushiro = int(t[-1])
  ans_lis[mae-1][ushiro-1] += 1
ans = 0
for i in range(9):
  for j in range(9):
    ans += ans_lis[i][j] * ans_lis[j][i]
print(ans)

N = int(input())
ans_lis = [[0] * 9 for i in range(9)]
for i in range(1,N+1):
  t = str(i)
  mae = int(t[0])
  ushiro = int(t[-1])
  if ushiro == 0:
    continue
  ans_lis[mae-1][ushiro-1] += 1
ans = 0
for i in range(9):
  for j in range(9):
    ans += ans_lis[i][j] * ans_lis[j][i]
print(ans)


Verdicts: Runtime Error

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())
d = {x: [int((str(x))[0]),x % 10] for x in range(1,N)} 

count = 0
for i in range(1,N):
    for j in range (i,N):
        if d[i] == d[j]:
            print(d[i],d[j])
            count += 1
print(count)

n = int(input())

N = n + 1
totalcount = 0

for i in range(1,N):
  a = str(i)
  a_first = a[0]
  a_end = a[len(str(i)) - 1]
  for j in range(1,N):
    b = str(j)
    b_first = b[0]
    b_end = b[len(str(j)) - 1]
    if a_first == b_end and a_end == b_first:
      totalcount += 1
      print(a,j)
print(totalcount)

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

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):
from sys import stdin

n = int(stdin.readline().rstrip())

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

for k in range(1,n+1):
    atama = int(str(k)[0])
    ushiro = int(str(k)[-1])
    li[atama][ushiro] += 1
point = 0
for l in range(1,10):
    for m in range(1,10):
        point += li[l][m]**2

print(point)

from collections import defaultdict

n = int(input())
dic = defaultdict(int)

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

point = 0

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

print(point)

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())
check=[[0]*9 for i in range(9)]
for i in range(1,n+1):
    s=str(i)
    s1=int(s[0])-1
    s2=int(s[-1])-1
    check[s1][s2]+=1
for i in range(9):
    for j in range(9):
        cnt+=check[i][j]*check[j][i]
print(cnt)


n=int(input())
check=[[0]*9 for i 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
    check[s1][s2]+=1
cnt=0
for i in range(9):
    for j in range(9):
        cnt+=check[i][j]*check[j][i]
print(cnt)


Verdicts: Runtime Error

Accepted
Problem: Given are N positive integers A_1,...,A_N.  Consider positive integers B_1, ..., B_N that satisfy the following condition.  Condition: For any i, j such that 1 \leq i < j \leq N, A_i B_i = A_j B_j holds.  Find the minimum possible value of B_1 + ... + B_N for such B_1,...,B_N.  Since the answer can be enormous, print the sum modulo (10^9 +7).

Submission attempts (in order):
import sys
import fractions

sys.setrecursionlimit(10000000)
input=sys.stdin.readline

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

def gcd(a, b):
    return a if b == 0 else gcd(b, a%b)

def lcm(a, b):
    return a // fractions.gcd(a, b) * b

mod = 10**9+7

x=a[0]

for i in a[1:]:
    x=lcm(x,i)
ans=0
for i in range(n):
    ans+= x//a[i]%mod

print(ans%mod)


import sys

sys.setrecursionlimit(10000000)
input=sys.stdin.readline

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

def gcd(a, b):
    return a if b == 0 else gcd(b, a%b)

def lcm(a, b):
    return a // gcd(a, b) * b

mod = 10**9+7

x=a[0]

for i in a[1:]:
    x=lcm(x,i)
ans=0
for i in range(n):
    ans+= x//a[i]

print(ans%mod)


Verdicts: Time Limit Exceeded

Accepted
Problem: Given are N positive integers A_1,...,A_N.  Consider positive integers B_1, ..., B_N that satisfy the following condition.  Condition: For any i, j such that 1 \leq i < j \leq N, A_i B_i = A_j B_j holds.  Find the minimum possible value of B_1 + ... + B_N for such B_1,...,B_N.  Since the answer can be enormous, print the sum modulo (10^9 +7).

Submission attempts (in order):
import numpy as np

class SieveOfEratosthenes:
    def __init__(self, V):
        self.is_prime = np.ones(V + 1, dtype=bool)
        self.is_prime[4::2] = False
        self.is_prime[9::3] = False
        self.is_prime[25::5] = False
        self.primes = [2, 3, 5]
        for i in range(7, V + 1, 2):
            if self.is_prime[i]:
                self.primes.append(i)
                if i * i < V + 1:
                    self.is_prime[i * i::i] = False
    
    def factorize(self, x):
        assert x >= 1
        if x == 1:
            return [(1, 1)]
        result = []
        for p in self.primes:
            exp = 0
            while x % p == 0:
                exp += 1
                x = x // p
            if exp > 0:
                result.append((p, exp))
            if p * p > x:
                break
        if x > 1:
            result.append((x, 1))
        return result


N = int(input())
M = 10**9 + 7
A = list(map(int, input().split()))

sieve = SieveOfEratosthenes(10**3)
F = [dict(sieve.factorize(a)) for a in A]

lcm = F[0]
for i in range(1, len(F)):
    for p, e in F[i].items():
        if p in lcm:
            lcm[p] = max(lcm[p], e)
        else:
            lcm[p] = e

val = 1
for p, e in lcm.items():
    val = val * pow(p, e, M) % M
print(val)

B = [val * pow(a, M - 2, M) % M for a in A]
print(sum(B) % M)
    

import numpy as np

class SieveOfEratosthenes:
    def __init__(self, V):
        self.is_prime = np.ones(V + 1, dtype=bool)
        self.is_prime[4::2] = False
        self.is_prime[9::3] = False
        self.is_prime[25::5] = False
        self.primes = [2, 3, 5]
        for i in range(7, V + 1, 2):
            if self.is_prime[i]:
                self.primes.append(i)
                self.is_prime[i * i::i] = False
    
    def factorize(self, x):
        assert x >= 1
        if x == 1:
            return [(1, 1)]
        result = []
        for p in self.primes:
            exp = 0
            while x % p == 0:
                exp += 1
                x = x // p
            if exp > 0:
                result.append((p, exp))
            if p * p > x:
                break
        if x > 1:
            result.append((x, 1))
        return result


N = int(input())
M = 10**9 + 7
A = list(map(int, input().split()))

sieve = SieveOfEratosthenes(10**3)
F = [dict(sieve.factorize(a)) for a in A]

lcm = F[0]
for i in range(1, len(F)):
    for p, e in F[i].items():
        if p in lcm:
            lcm[p] = max(lcm[p], e)
        else:
            lcm[p] = e

val = 1
for p, e in lcm.items():
    val = val * pow(p, e, M) % M
# print(val)

B = [val * pow(a, M - 2, M) % M for a in A]
print(sum(B) % M)
    

Verdicts: Wrong Answer

Accepted