problem_id
stringlengths
6
6
user_id
stringlengths
10
10
time_limit
float64
1k
8k
memory_limit
float64
262k
1.05M
problem_description
stringlengths
48
1.55k
codes
stringlengths
35
98.9k
status
stringlengths
28
1.7k
submission_ids
stringlengths
28
1.41k
memories
stringlengths
13
808
cpu_times
stringlengths
11
610
code_sizes
stringlengths
7
505
p02792
u242031676
2,000
1,048,576
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.
['n = int(input())\ndic = {}\nfor i in range(11, 100):\n f, s = divmod(i, 10)\n tmp = 0\n for j in range(1, n):\n if str(j)[0]==str(f) and str(j)[-1]==str(s): tmp +=1\n dic[i] = tmp\n\nprint(dic)\nans = 0\nfor i in range(1, int(n)+1):\n s = str(i)\n if s[-1]=="0": continue\n ans += dic[int(s[-1]+s[0])]\nprint(ans)\n', 'n = int(input())\ndic = {}\nfor i in range(10, 100): dic[str(i)]=0\nfor i in range(1, n+1):\n s = str(i)\n dic[s[0]+s[-1]] += 1\n\nans = 0\nfor i in range(1, n+1):\n s = str(i)\n if s[-1]=="0": continue\n ans += dic[s[-1]+s[0]]\nprint(ans)']
['Wrong Answer', 'Accepted']
['s627884434', 's311889760']
[3064.0, 3188.0]
[2104.0, 250.0]
[327, 242]
p02792
u250583425
2,000
1,048,576
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.
["import sys\nfrom scipy.misc import comb\ndef input(): return sys.stdin.readline().rstrip()\n\ndef main():\n n = int(input())\n \n ans = [0] * 100\n for i in range(n//2 + 1):\n if i < 10:\n ans[int(str(i) * 2)] += 1\n continue\n s = str(i)\n if s[0] != s[-1]:\n ans[int(s[0] + s[-1])] += 2\n else:\n ans[int(s[0] + s[-1])] += 1\n\n sum = 0\n for i in range(1, 10):\n for j in range(i, 10):\n data = ans[i * 10 + j]\n if data >= 2:\n sum += comb(data, 2, exact=True)\n print(sum)\n\nif __name__ == '__main__':\n main()\n", "import sys\ndef input(): return sys.stdin.readline().rstrip()\n\ndef main():\n n = int(input())\n \n res = [[0] * 10 for _ in range(10)]\n for i in range(1, n+1):\n s = str(i)\n if s[-1] == '0':\n continue\n res[int(s[0])][int(s[-1])] += 1\n\n ans = 0\n for i in range(1, 10):\n for j in range(1, 10):\n ans += res[i][j] * res[j][i]\n print(ans)\n\nif __name__ == '__main__':\n main()"]
['Wrong Answer', 'Accepted']
['s317021024', 's513984753']
[13276.0, 3064.0]
[231.0, 163.0]
[630, 438]
p02792
u256351611
2,000
1,048,576
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.
['def bunkai(n:int):\n ls=list(str(n))\n top,bottom=int(ls[0]),int(ls[-1])\n if n<=99:\n middle=0\n else:\n middle=int("".join(ls[1:-1]))\n return top, middle, bottom\n\nn=int(input())\nNt,Nm,Nb = bunkai(n)\n\ncount=0\nfor i in range(1,n+1):\n t,m,b = bunkai(i)\n if b==0:continue\n if t==b:count+=1\n if n<=99:\n if int(b+t)<=n:count+=1\n else:\n keta = len(str(n))\n for x in range(keta-2):\n count+=10**x\n x+=1\n if Nt>b:\n count+=10**x\n elif Nt==b:\n if Nb>=t:\n count+=Nm+1\n else:\n count+=Nm\nprint(count)\n \n', 'def bunkai(n:int):\n ls=list(str(n))\n top,bottom=int(ls[0]),int(ls[-1])\n if n<=99:\n middle=0\n else:\n middle=int("".join(ls[1:-1]))\n return top, middle, bottom\n\nn=int(input())\nNt,Nm,Nb = bunkai(n)\n\ncount=0\nfor i in range(1,n+1):\n t,m,b = bunkai(i)\n if b==0:continue\n if t==b:count+=1\n if n<=99:\n if int(str(b)+str(t))<=n:count+=1\n else:\n keta = len(str(n))\n for x in range(keta-2):\n count+=10**x\n x+=1\n if Nt>b:\n count+=10**x\n elif Nt==b:\n if Nb>=t:\n count+=Nm+1\n else:\n count+=Nm\nprint(count)\n \n']
['Wrong Answer', 'Accepted']
['s849639140', 's474285620']
[3064.0, 3064.0]
[826.0, 835.0]
[647, 657]
p02792
u259861571
2,000
1,048,576
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.
['N = int(input())\ntable = [[0]*10 for _ in range(10)]\n\nfor i in range(1, N+1):\n s = str(i)\n e1 = int(s[0])\n e2 = int(s[1])\n table[e1][e2] += 1\n\nres = 0\nfor i in range(1, 10):\n for j in range(1, 10):\n res += table[i][j]*table[j][i]\nprint(res)', 'N = int(input())\ntable = [[0]*10 for _ in range(10)]\n\nfor i in range(1, N+1):\n s = str(i)\n e1 = int(s[0])\n e2 = int(s[-1])\n table[e1][e2] += 1\n\nres = 0\nfor i in range(1, 10):\n for j in range(1, 10):\n res += table[i][j]*table[j][i]\nprint(res)']
['Runtime Error', 'Accepted']
['s540163825', 's017055506']
[3064.0, 3064.0]
[17.0, 202.0]
[262, 263]
p02792
u265506056
2,000
1,048,576
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.
['N=int(input())\nans=0\nc=[[0 for _ in range(10)] for _ in range(10)]\n\nfor n in range(1,N+1):\n i=n%10\n j=n\n while 10<=k:\n j=j//10\n c[i][j]=c[i][j]+1\n\nfor i in range(10):\n for j in range(10):\n ans=ans+c[i][j]*c[j][i]\nprint(ans)', 'N=int(input())\nans=0\nc=[[0 for _ in range(10)] for _ in range(10)]\n\nfor n in range(1,N+1):\n i=n%10\n j=n\n while 10<=j:\n j=j//10\n c[i][j]=c[i][j]+1\n\nfor i in range(10):\n for j in range(10):\n ans=ans+c[i][j]*c[j][i]\nprint(ans)']
['Runtime Error', 'Accepted']
['s870898631', 's937238499']
[3064.0, 3064.0]
[17.0, 213.0]
[252, 252]
p02792
u268554510
2,000
1,048,576
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.
['N = int(input())\nans = 0\nl=[[0]*10 for _ in range(10)]\nfor i in range(1,2021):\n s = str(i)\n l[int(s[0])][int(s[-1])]+=1\n \nfor i in range(10):\n for j in range(10):\n ans+=l[i][j]*l[j][i]\n \nprint(ans)', 'N = int(input())\nans = 0\nl=[[0]*10 for _ in range(10)]\nfor i in range(1,N+1):\n s = str(i)\n l[int(s[0])][int(s[-1])]+=1\n \nfor i in range(10):\n for j in range(10):\n ans+=l[i][j]*l[j][i]\n \nprint(ans)']
['Wrong Answer', 'Accepted']
['s465295583', 's342239614']
[3064.0, 3064.0]
[19.0, 194.0]
[207, 206]
p02792
u272336707
2,000
1,048,576
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.
['n = int(input())\nf_dict = {}\ns_dict = {}\ncnt_all = 0\nfor i in range(n):\n moji = str(i+1)\n if f_dict[[moji[0]+moji[-1]] == "":\n f_dict[moji[0]+moji[-1]] = 0\n else:\n f_dict[[moji[0]+moji[-1]]+= 1 \n if s_dict[[moji[-1]+moji[0]] == "":\n f_dict[[moji[-1]+moji[0]] = 0\n else:\n f_dict[[moji[-1]+moji[0]] += 1\nfor mykey in f_dict.keys():\n cnt_all += f_dict[mykey] * s_dict[mykey]\nprint(cnt_all)', 'n = int(input())\nf_dict = {}\ns_dict = {}\ncnt_all = 0\nfor i in range(n):\n moji = str(i+1)\n if f_dict[moji[0], moji[-1]] == "":\n f_dict[moji[0], moji[-1]] = 0\n else:\n \tf_dict[moji[0], moji[-1]] += 1 \n if s_dict[moji[-1], moji[0]] == "":\n f_dict[moji[-1], moji[0]] = 0\n else:\n \tf_dict[moji[-1], moji[0]] += 1\nfor mykey in f_dict.keys():\n cnt_all += f_dict[mykey] * s_dict[mykey]\nprint(cnt_all)', 'n = int(input())\nf_dict = {}\ns_dict = {}\ncnt_all = 0\nfor i in range(n):\n moji = str(i+1)\n if f_dict[[moji[0], moji[-1]] == "":\n f_dict[moji[0], moji[-1]] = 0\n else:\n f_dict[[moji[0], moji[-1]]+= 1 \n if s_dict[[moji[-1], moji[0]] == "":\n f_dict[[moji[-1], moji[0]] = 0\n else:\n f_dict[[moji[-1], moji[0]] += 1\nfor mykey in f_dict.keys():\n cnt_all += f_dict[mykey] * s_dict[mykey]\nprint(cnt_all)', 'n = int(input())\nf_dict = {}\ns_dict = {}\ncnt_all = 0\nfor i in range(n):\n moji = str(i+1)\n if not moji[0]+moji[-1] in f_dict:\n f_dict[moji[0]+moji[-1]] = 1\n else:\n f_dict[moji[0]+moji[-1]] += 1 \n if not moji[-1]+moji[0] in s_dict:\n s_dict[moji[-1]+moji[0]] = 1\n else:\n s_dict[moji[-1]+moji[0]] += 1\nfor mykey in f_dict.keys():\n if mykey in s_dict:\n cnt_all += f_dict[mykey] * s_dict[mykey]\nprint(cnt_all)']
['Runtime Error', 'Runtime Error', 'Runtime Error', 'Accepted']
['s212343940', 's852826756', 's914782155', 's384064385']
[2940.0, 3064.0, 2940.0, 3064.0]
[17.0, 17.0, 17.0, 303.0]
[404, 404, 410, 426]
p02792
u303739137
2,000
1,048,576
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.
["N = int(input())\n\ndic = {}\nfor i in range(1,10):\n for j in range(1,10):\n dic[(str(i),str(j))] = 0\n\nfor i in range(N):\n nstr = str(i)\n pre = nstr[0]\n suf = nstr[-1]\n if suf == '0':\n continue\n dic[(pre, suf)] =dic[(pre, suf)] + 1\n\ncnt = 0 \nfor i in range(1,10):\n for j in range(1,i+1):\n cnt += dic[(str(i),str(j))] * dic[(str(j),str(i))]\n \n \nprint(dic.values())", "N = int(input())\n\ndic = {}\nfor i in range(1,10):\n for j in range(1,10):\n dic[(str(i),str(j))] = 0\n\nfor i in range(N+1):\n nstr = str(i)\n pre = nstr[0]\n suf = nstr[-1]\n print(pre)\n print(suf)\n if suf == '0':\n continue\n dic[(pre, suf)] =dic[(pre, suf)] + 1\n\ncnt = 0 \nfor i in range(1,10):\n for j in range(1,10):\n cnt += dic[(str(i),str(j))] * dic[(str(j),str(i))]\n\nprint(cnt)", "N = int(input())\n\ndic = {}\nfor i in range(1,10):\n for j in range(1,10):\n dic[(str(i),str(j))] = 0\n\nfor i in range(N+1):\n nstr = str(i)\n pre = nstr[0]\n suf = nstr[-1]\n if suf == '0':\n continue\n dic[(pre, suf)] =dic[(pre, suf)] + 1\n\ncnt = 0 \nfor i in range(1,10):\n for j in range(1,10):\n cnt += dic[(str(i),str(j))] * dic[(str(j),str(i))]\n\nprint(cnt)"]
['Wrong Answer', 'Wrong Answer', 'Accepted']
['s109784747', 's756115295', 's891005284']
[3316.0, 4464.0, 3064.0]
[184.0, 382.0, 184.0]
[377, 390, 364]
p02792
u305366205
2,000
1,048,576
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.
["n = int(input())\nans = 0\ncnt = [[0] * 9 for _ in range(9)]\ntmp = 0\nfor i in range(1, n + 1):\n one = str(i)\n two = list(str(i))\n two.reverse()\n two = ''.join(two)\n if one[-1] == '0':\n continue\n if one == two:\n tmp += 1\n cnt[int(one[0]) - 1][int(one[-1]) - 1] += 1\nfor i in range(9):\n for j in range(9):\n ans += cnt[j][i]\nprint(ans - tmp)", "n = int(input())\nans = 0\ncnt = [[0] * 9 for _ in range(9)]\ntmp = 0\nfor i in range(1, n + 1):\n one = str(i)\n if one[-1] == '0':\n continue\n cnt[int(one[0]) - 1][int(one[-1]) - 1] += 1\nfor i in range(9):\n for j in range(9):\n ans += cnt[i][j] * cnt[j][i]\nprint(ans)"]
['Wrong Answer', 'Accepted']
['s074086130', 's002098268']
[3064.0, 3064.0]
[432.0, 204.0]
[381, 287]
p02792
u309141201
2,000
1,048,576
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.
["N = int(input())\nnumMap = {}\nanswer = 0\ndef StartEnd(x):\n start = str(x)[0]\n end = str(x)[-1]\n return int(start), int(end)\n\nfor i in range(1, N+1):\n print('numMap:', numMap)\n pair = StartEnd(i)\n if pair in numMap:\n numMap[pair] += 1\n else:\n numMap[pair] = 1\n\nfor i in range(1, N+1):\n key = StartEnd(i)\n rev = key[::-1]\n print('rev:', rev)\n if rev in numMap:\n answer += numMap[rev]\n \nprint(answer) \n\n", "N = int(input())\nnumMap = {}\nanswer = 0\ndef StartEnd(x):\n start = str(x)[0]\n end = str(x)[-1]\n return start, end\n\nfor i in range(1, N+1):\n # print('numMap:', numMap)\n pair = StartEnd(i)\n if pair in numMap:\n numMap[pair] += 1\n else:\n numMap[pair] = 1\n\nfor i in range(1, N+1):\n key = StartEnd(i)\n rev = key[::-1]\n # print('rev:', rev)\n if rev in numMap:\n answer += numMap[rev]\n \nprint(answer) \n\n"]
['Wrong Answer', 'Accepted']
['s429171723', 's558382056']
[65268.0, 3064.0]
[2104.0, 393.0]
[459, 453]
p02792
u323045245
2,000
1,048,576
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.
['n = int(input())\ncheak =[[0]*9 for _ in range]\nfor i in range(1, n+1):\n s = str(i)\n s1 = int(s[0])-1\n s2 = int(s[-1])-1\n if s2 == 0:\n continue\n cheak[s1][s2] += 1\n\nans = 0\nfor i in range(10):\n for j in range(10):\n ans += cheak[i][j] * cheak[j][i]\nprint(ans)\n', 'n = int(input())\ncheak_box = [[0]*9 for _ in range(9)]\n\nfor i in range(1, n+1):\n s = str(i)\n s1 = int(s[0]) - 1\n s2 = int(s[-1]) - 1\n if s2 == -1:\n continue \n cheak_box[s1][s2] += 1\n\nans = 0\nfor p in range(9):\n for q in range(9):\n ans += cheak_box[p][q] * cheak_box[q][p]\n \nprint(ans)']
['Runtime Error', 'Accepted']
['s977218398', 's144074792']
[3060.0, 3064.0]
[17.0, 204.0]
[290, 323]
p02792
u329232967
2,000
1,048,576
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.
['def main():\n N = int(input())\n print(solve(N))\n\n\ndef count(n, start, end):\n \n\n if n <= 9:\n return 1 if start == end and start <= n else 0\n if n <= 99:\n one_digit = 1 if start == end else 0\n two_digit = 1 if start * 10 + end <= n else 0\n return one_digit + two_digit\n digit_length = len(str(n))\n \n ret1 = count(10 ** (digit_length - 1) - 1, start, end)\n \n min_cand = start * (10 ** (digit_length - 1)) + end\n if min_cand > n:\n return ret1\n ret2 = min((n-min_cand) // 10 + 1, 10 ** (digit_length - 2))\n return ret1 + ret2\n\n\ndef solve(n):\n \n result = 0\n for i in range(1, 10):\n for j in range(i + 1, 10):\n result += 2 * count(n, i, j) * count(n, j, i)\n for i in range(1, 10):\n result += count(n, i, i) * count(n, i, i)\n return result\n\n\nif __name__ == "__main__":\n assert_equal(count(732, 1, 2), 11)\n main()\n', 'def main():\n N = int(input())\n print(solve(N))\n\n\ndef count(n, start, end):\n \n\n if n <= 9:\n return 1 if start == end and start <= n else 0\n if n <= 99:\n one_digit = 1 if start == end else 0\n two_digit = 1 if start * 10 + end <= n else 0\n return one_digit + two_digit\n digit_length = len(str(n))\n \n ret1 = count(10 ** (digit_length - 1) - 1, start, end)\n \n min_cand = start * (10 ** (digit_length - 1)) + end\n if min_cand > n:\n return ret1\n ret2 = min((n-min_cand) // 10 + 1, 10 ** (digit_length - 2))\n return ret1 + ret2\n\n\ndef solve(n):\n \n result = 0\n for i in range(1, 10):\n for j in range(i + 1, 10):\n result += 2 * count(n, i, j) * count(n, j, i)\n for i in range(1, 10):\n result += count(n, i, i) * count(n, i, i)\n return result\n\n\nif __name__ == "__main__":\n main()\n']
['Runtime Error', 'Accepted']
['s245069083', 's173162391']
[3064.0, 3064.0]
[17.0, 18.0]
[1379, 1340]
p02792
u333700164
2,000
1,048,576
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.
['n=int(input())\ndef side(n):\n list_n=list(str(n))\n start=int(list_n[0])\n end=int(list_n[-1])\n return [start,end]\ndef count_n(i,j):\n s=0\n for i in range(1,n+1):\n if side(i)==[i,j]:\n s+=1\n return s\nans=0\nfor i in range(0,9):\n for j in range(0,9):\n ans+=count_n(i,j)*count_n(j,i)\nprint(ans)', 'n=int(input())\nfrom itertools import combinations\ndef dis(n):\n list_n=list(str(n))\n a=int(list_n[0])\n b=int(list_n[-1])\n return [a,b]\nN=[_ for _ in range(1,n+1)]\ncomb=list(combinations(N,2))\ns=0\nfor A,B in comb:\n if dis(A)[0]==dis(B)[1] and dis(B)[0]==dis(A)[1]:\n s+=1\nt=0\nfor A in N:\n if dis(A)[0]==dis(A)[1]:\n t+=1\nprint(s+t)', 'n=int(input())\nd=[0]*100\nfor i in range(n+1):\n s=str(i)\n d[int(s[0])*10+int(s[-1])]+=1\n\nans=0\nfor i in range(1,10):\n for j in range(1,10):\n ans+=d[10*i+j]*d[10*j+i]\nprint(ans)']
['Wrong Answer', 'Wrong Answer', 'Accepted']
['s482323481', 's835683032', 's796155044']
[9156.0, 2072192.0, 9196.0]
[2205.0, 2293.0, 141.0]
[305, 339, 181]
p02792
u347600233
2,000
1,048,576
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.
['n = int(input())\nc = [[0 for i in range(10)] for j in range(10)]\nfor k in range(1, n + 1):\n i, j = int(str_k[0]), int(str_k[-1])\n c[int(str(k)[0])][int(str(k)[-1])] += 1\n\ncnt = 0\nfor i in range(10):\n for j in range(10):\n cnt += c[i][j] * c[j][i]\nprint(cnt)', 'n = int(input())\nc = [[0 for i in range(10)] for j in range(10)]\nfor k in range(1, n + 1):\n c[int(str(k)[0])][int(str(k)[-1])] += 1\n\ncnt = 0\nfor i in range(10):\n for j in range(10):\n cnt += c[i][j] * c[j][i]\nprint(cnt)']
['Runtime Error', 'Accepted']
['s395486249', 's470134005']
[3064.0, 3188.0]
[18.0, 232.0]
[272, 231]
p02792
u350836088
2,000
1,048,576
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.
['n = int(input())\ns = str(n)\nl = len(s)\nk = min(int(s[0]),int(s[-1]))\nif l == 1:\n print(n)\nelse:\n ans = (k*(k-1)//2 + k) * (9**(l-1)-1)//8\n ans += (n*(n-1)//2 - k*(k-1)//2 + 9-k) * (9**(l-2)-1)//8\n print(ans)\n\n', 'n = int(input())\nres = [[0]*9 for _ in range(9)]\nfor i in range(1,n+1):\n a = i%10\n if a== 0: continue\n while i > 0:\n b = i%10\n i = i//10\n res[a-1][b-1] += 1\n\n\nans = 0\n\nfor i in range(9):\n for j in range(9):\n ans += res[i][j] * res[j][i]\n\nprint(ans)\n ']
['Wrong Answer', 'Accepted']
['s957942222', 's423012250']
[3060.0, 3064.0]
[18.0, 273.0]
[213, 267]
p02792
u358957649
2,000
1,048,576
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.
['def main2(N):\n \n lst = list()\n for i in range(1,10):\n lst.append([0]*9)\n\n for n in range(1, N+1):\n for i in range(1,10):\n for j in range(1,10):\n head = str(n)[0]\n tail = str(n)[-1]\n if i == int(head) and j == int(tail):\n lst[i-1][j-1] += 1\n \n count = 0\n for i in range(0, len(lst)):\n for j in range(0, len(lst[i])):\n count += lst[i][j] * lst[j][i]\n\n print(count)\n\nmain2(N)', 'def main3(N):\n lst = list()\n for i in range(1, 10):\n lst.append([0]*9)\n\n for n in range(1, N+1):\n head = int(str(n)[0])\n tail = int(str(n)[-1])\n \n if tail != 0:\n lst[head-1][tail-1] += 1\n \n \n # print(lst[i])\n \n count = 0\n for i in range(0, len(lst)):\n for j in range(0, len(lst[i])):\n count += lst[i][j] * lst[j][i]\n\n print(count)\n\nN = int(input())\nmain3(N)\n']
['Runtime Error', 'Accepted']
['s864698132', 's140967091']
[3064.0, 3064.0]
[17.0, 218.0]
[513, 504]
p02792
u363995337
2,000
1,048,576
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.
['N = int(input())\n\nc = [[0] for i in range(10)]\n\nfor i in range(1, N+1):\n s = str(i)\n c[int(s[0])][int(s[-1])] += 1\n\nans = 0\n\nfor i in range(10):\n for j in range(10):\n ans += c[i][j] * c[j][i]\n\nprint(ans)', 'N = int(input())\n\nc = [[0]* 10 for i in range(10)]\n\nfor i in range(1, N+1):\n s = str(i)\n c[int(s[0])][int(s[-1])] += 1\n\nans = 0\nfor i in range(10):\n for j in range(10):\n ans += c[i][j] * c[j][i]\n\nprint(ans)']
['Runtime Error', 'Accepted']
['s754436208', 's093458966']
[3064.0, 3060.0]
[17.0, 184.0]
[219, 222]
p02792
u375616706
2,000
1,048,576
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.
['N = int(input())\n\nC = [[0]*10 for _ in range(10)]\nfor n in range(1, N+1):\n s = str(n)\n C[int[s[0]]][int[s[-1]]] += 1\n\nans = 0\nfor i in range(10):\n for j in range(10):\n ans += C[i][j]*C[j][i]\nprint(ans)\n', 'N = int(input())\n\nC = [[0]*10 for _ in range(10)]\nfor n in range(1, N+1):\n s = str(n)\n C[int(s[0])][int(s[-1])] += 1\n\nans = 0\nfor i in range(10):\n for j in range(10):\n ans += C[i][j]*C[j][i]\nprint(ans)\n']
['Runtime Error', 'Accepted']
['s551684907', 's853215950']
[3060.0, 3060.0]
[18.0, 191.0]
[218, 218]
p02792
u385244248
2,000
1,048,576
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.
['N = int(input())\nt = [0 for _ in range(81)]\nans = 0\nfor i in range(1, 10):\n for l in range(1, 10):\n for q in range(1, N+1):\n s = 0\n a = str(i)[0]\n b = str(i)[-1]\n if int(a) == i and int(b) == l:\n s += 1\n t[9*(i - 1)+l - 1] += s\nfor i in range(1, N+1):\n a = str(i)[0]\n b = str(i)[-1]\n if b == "0":\n continue\n else:\n ans += t[9*(int(b)-1)+int(a)-1]\nprint(ans)\n', 'N = int(input())\nt = [[0 for _ in range(9)] for l in range(9)]\nans = 0\nfor i in range(1, N+1):\n if len(str(i)) == 1:\n t[i-1][i-1] += 1\n elif str(i)[-1] != "0":\n t[int(str(i)[0])-1][int(str(i)[-1])-1] += 1\nfor i in range(1, N+1):\n a = str(i)[0]\n b = str(i)[-1]\n if b == "0":\n continue\n elif a == b:\n ans += t[(int(a)-1)][int(a)-1]\n else:\n ans += t[(int(b)-1)][int(a)-1]\nprint(ans)\n']
['Wrong Answer', 'Accepted']
['s074355660', 's436789526']
[3064.0, 3064.0]
[2104.0, 542.0]
[464, 436]
p02792
u406492455
2,000
1,048,576
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.
['def g(n):\n D = [[0]*10 for i in range(10)]\n for i in range(1,n+1):\n si = str(i)\n D[int(si[0])][int(si[-1])] += 1\n\n res = 0\n for i in range(10):\n for j in range(10):\n res += D[i][j]*D[j][i]\n return res\nprint(g(int(n)))\n', 'def g(n):\n D = [[0]*10 for i in range(10)]\n for i in range(1,n+1):\n si = str(i)\n D[int(si[0])][int(si[-1])] += 1\n\n res = 0\n for i in range(10):\n for j in range(10):\n res += D[i][j]*D[j][i]\n return res\nprint(g(int(input())))\n']
['Runtime Error', 'Accepted']
['s836970069', 's903801241']
[3060.0, 3060.0]
[17.0, 171.0]
[265, 271]
p02792
u417365712
2,000
1,048,576
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.
['n = int(input())\nd = defaultdict(int)\nfor i in range(1, n+1):\n x = str(i)\n d[(int(x[0]), int(x[-1]))] += 1\n\nans = 0\nfor i in range(1, 10):\n for j in range(1, 10):\n ans += d[(i, j)] * d[(j, i)]\nprint(ans)', 'from collections import defaultdict\nn = int(input())\nd = defaultdict(int)\nfor i in range(1, n+1):\n x = str(i)\n d[(int(x[0]), int(x[-1]))] += 1\n\nans = 0\nfor i in range(1, 10):\n for j in range(1, 10):\n ans += d[(i, j)] * d[(j, i)]\nprint(ans)']
['Runtime Error', 'Accepted']
['s316673254', 's857951575']
[3064.0, 3572.0]
[17.0, 216.0]
[219, 255]
p02792
u425184437
2,000
1,048,576
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.
['N=int(input())\nP=[0,0,0,0,0,0,0,0,0,0]\nL=copy.deepcopy(P)\nM=[L]*10\ncount=0\nfor i in range(1,N+1):\n a=int(str(i)[0])\n b=int(str(i)[-1])\n if L[b][a]!=0:\n count+=2*L[b][a]+1\n L[a][b]+=1\n\nprint(count)\n \n ', 'N=int(input())\nA=[[0 for i in range(10)] for j in range(10)]\nfor i in range(1,N+1):\n i=str(i)\n ii=len(i)\n A[int(i[0])][int(i[ii-1])]+=1\nans=0\nfor i in range(10):\n for j in range(10):\n ans+=A[i][j]*A[j][i]\nprint(ans)']
['Runtime Error', 'Accepted']
['s525326955', 's592509366']
[3060.0, 3064.0]
[17.0, 213.0]
[211, 222]
p02792
u426108351
2,000
1,048,576
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.
['n = int(input())\n\ntable = [[0 for i in range(10)] for j in range(10)]\nfor i in range(1, n+1):\n i = str(i)\n a, b = i[0], i[-1]\n table[a][b] += 1\n\nans = 0\nfor i in range(10):\n for j in range(10):\n ans += table[i][j] * table[j][i]\n\nprint(ans)\n', 'n = int(input())\n\ntable = [[0 for i in range(10)] for j in range(10)]\nfor i in range(1, n+1):\n i = str(i)\n a, b = int(i[0]), int(i[-1])\n table[a][b] += 1\n\nans = 0\nfor i in range(10):\n for j in range(10):\n ans += table[i][j] * table[j][i]\n\nprint(ans)\n']
['Runtime Error', 'Accepted']
['s410939883', 's505516429']
[3060.0, 3060.0]
[17.0, 200.0]
[259, 269]
p02792
u426764965
2,000
1,048,576
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.
['from collections import defaultdict\n\ndef diverta192_b():\n N = int(input())\n P = [tuple(map(int, input().split())) for _ in range(N)]\n if len(P) == 1:\n print(1) \n return\n\n dcnt = defaultdict(int) \n for i in range(N):\n xi, yi = P[i]\n for j in range(i):\n xj, yj = P[j]\n dcnt[(xi-xj, yi-yj)] += 1\n dcnt[(xj-xi, yj-yi)] += 1 \n most = sorted(dcnt.values(), reverse=True)[0] \n ans = N - most\n print(ans)\n\ndiverta192_b()', 'from collections import defaultdict\n\ndef abc152_d():\n N = int(input())\n freq = defaultdict(int)\n for i in range(1, N+1):\n s = str(i)\n freq[(s[0], s[-1])] += 1 \n\n ans = 0\n for i in range(1, N+1):\n s = str(i)\n ans += freq[(s[-1], s[0])] \n print(ans)\n\nabc152_d()']
['Runtime Error', 'Accepted']
['s775174233', 's621439248']
[3316.0, 3316.0]
[22.0, 198.0]
[677, 414]
p02792
u428132025
2,000
1,048,576
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.
['s = int(input())\nnum = [[0 for i in range(10)] for j in range(10)]\n\nans = 0\n\nfor _ in range(n):\n i = _ + 1\n if i < 10:\n num[i][i] += 1\n elif i % 10 != 0:\n moji = str(i)\n num[int(moji[0])][int(moji[len(moji)-1])] += 1\n else:\n pass\n\nfor i in range(1, 10):\n for j in range(1, 10):\n ans += num[i][j] * num[j][i]\n\nprint(ans)', 's = int(input())\nnum = [[0 for i in range(10)] for j in range(10)]\n\nans = 0\n\nfor _ in range(n):\n i = _ + 1\n if i < 10:\n num[i][i] += 1\n elif i % 10 != 0:\n moji = str(i)\n num[int(moji[0])][int(moji[len(moji)-1])] += 1\n else:\n pass\n\nfor i in range(1, 10):\n for j in range(1, 10):\n ans += num[i][j] * num[j][i]\n\nfor i in num:\n for j in i:\n print(j, " ", end="")\n print()\n\nprint(ans)', 'n = int(input())\nnum = [[0 for i in range(10)] for j in range(10)]\n\nans = 0\n\nfor _ in range(n):\n i = _ + 1\n if i < 10:\n num[i][i] += 1\n elif i % 10 != 0:\n moji = str(i)\n num[int(moji[0])][int(moji[len(moji)-1])] += 1\n else:\n pass\n\nfor i in range(1, 10):\n for j in range(1, 10):\n ans += num[i][j] * num[j][i]\n\nprint(ans)']
['Runtime Error', 'Runtime Error', 'Accepted']
['s251351524', 's600157134', 's678908921']
[3188.0, 3064.0, 3316.0]
[18.0, 18.0, 234.0]
[369, 442, 369]
p02792
u442877951
2,000
1,048,576
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.
['N,A,B= map(int,input().split())\ncount = 0\nfor A in range(N):\n for B in range(N):\n if A[0:] == B[:-1] and A[:-1] == B[0]:\n count += 1\nprint(count)', "N = int(input())\nl = [[0 for _ in range(10)]for _ in range(10)]\n\nfor i in range(1,N+1):\n i = str(i)\n if i[0] == '0' or i[-1] == '0':\n pass\n else:\n l[int(i[0])][int(i[-1])] += 1\n\nans = 0\n\nfor i in range(1,10):\n for j in range(1,10):\n ans += l[i][j]*l[j][i]\n\nprint(ans)"]
['Runtime Error', 'Accepted']
['s362036468', 's547978795']
[2940.0, 3064.0]
[17.0, 227.0]
[154, 280]
p02792
u459150945
2,000
1,048,576
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.
['N = int(input())\n\ncnt = [[0 for _ in range(10)] for _ in range(10)]\n\nfor k in range(1, n+1):\n s = str(k)\n cnt[int(s[0])][int(s[-1])] += 1\nans = 0\nfor i in range(10):\n for j in range(10):\n ans += c[i][j] * c[j][i]\nprint(ans)\n', 'N = int(input())\n\ncnt = [[0 for _ in range(10)] for _ in range(10)]\n\nfor k in range(1, n+1):\n s = str(k)\n cnt[int(s[0])][int(s[-1])] += 1\nans = 0\nfor i in range(10):\n for j in range(10):\n ans += cnt[i][j] * cnt[j][i]\nprint(ans)\n', 'N = int(input())\n\ncnt = [[0 for _ in range(10)] for _ in range(10)]\n\nfor k in range(1, N+1):\n s = str(k)\n cnt[int(s[0])][int(s[-1])] += 1\nans = 0\nfor i in range(10):\n for j in range(10):\n ans += cnt[i][j] * cnt[j][i]\nprint(ans)\n']
['Runtime Error', 'Runtime Error', 'Accepted']
['s175068858', 's700781730', 's895653406']
[3060.0, 3060.0, 3060.0]
[17.0, 17.0, 181.0]
[240, 244, 244]
p02792
u498620941
2,000
1,048,576
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.
["def check(a, b):\n k = 1\n res = 0\n if a == b and (a <= N): res += 1\n while True:\n if (a * (10 ** k) + b) > N:\n break\n else:\n if len(str(N)) > (k+1) or str(N)[0] > str(a):\n res += 10 ** (k - 1)\n k += 1\n continue\n\n else :\n Q = N - (a * (10 ** k) + b)\n p = (1 + int(str(Q)[:-1]))\n res += p\n k += 1\n return res\n\n\ndef main():\n global N\n N = int(input())\n ans = 0\n for i in range(1, 10, 1):\n for j in range(1, 10, 1):\n a = check(i, j)\n b = check(j, i)\n ans += a * b\n print(ans)\n\n\nif __name__ == '__main__':\n main()", "def check(a, b):\n k = 1\n res = 0\n if a == b and (a <= N): res += 1\n while True:\n if (a * (10 ** k) + b) > N:\n break\n else:\n if len(str(N)) > (k+1) or str(N)[0] > str(a):\n res += 10 ** (k - 1)\n k += 1\n continue\n\n else :\n Q = N - (a * (10 ** k) + b)\n p = 1\n if len(str(Q)) > 1 :\n p += (int(str(Q)[:-1]))\n res += p\n k += 1\n return res\n\n\ndef main():\n global N\n N = int(input())\n ans = 0\n for i in range(1, 10, 1):\n for j in range(1, 10, 1):\n a = check(i, j)\n b = check(j, i)\n ans += a * b\n print(ans)\n\n\nif __name__ == '__main__':\n main()"]
['Runtime Error', 'Accepted']
['s638946237', 's322068464']
[3064.0, 3064.0]
[18.0, 18.0]
[732, 792]
p02792
u500415792
2,000
1,048,576
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.
['\nn = int(input())\n\nnumber = [[0]*10 for _ in range(10)]\n\nfor _ in range(1, n+1):\n\n s=str(i)\n i=int(s[0])\n j=int(s[-1])\n\n number[i][j] += 1\n\ncount = 0\nfor i in range(10):\n\n for j in range(10):\n count += number[i][j]*number[j][i]\n\nprint(count)', '\nn = int(input())\n\nnumber = [[0]*10 for _ in range(10)]\n\nfor _ in range(1, n+1):\n\n s=str(_)\n i=int(s[0])\n j=int(s[-1])\n\n number[i][j] += 1\n\ncount = 0\nfor i in range(10):\n\n for j in range(10):\n count += number[i][j]*number[j][i]\n\nprint(count)']
['Runtime Error', 'Accepted']
['s451027862', 's655542981']
[3064.0, 3064.0]
[17.0, 199.0]
[263, 263]
p02792
u504256702
2,000
1,048,576
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.
['N= int(input())\nlead_N = int(str(N)[0]) \nend_N = int(str(N)[len(str(N)) - 1])\nans = 0\n#print(str(100)[len(str(100)) - 1])\nfor i in range(1, N + 1):\n lead = int(str(i)[0])\n end = int(str(i)[len(str(i)) - 1])\n \n if lead == end:\n ans += 1\n \n for j in range((len(str(N)) - 2) + 1):\n if end == 0:\n \n continue\n elif end > lead_N and j == (len(str(N)) - 2) :\n \n continue\n elif end == lead_N and j == (len(str(N)) - 2):\n \n \n\n ans += int(str(N)[1:len(str(N)) - 1])\n\n if lead <= end_N:\n ans += 1\n #print("b")\n pass\n else:\n \n ans += 10 ** j\n\nprint(ans)', 'N= int(input())\nlead_N = int(str(N)[0]) \nend_N = int(str(N)[len(str(N)) - 1])\nans = 0\n#print(str(100)[len(str(100)) - 1])\nfor i in range(1, N + 1):\n lead = int(str(i)[0])\n end = int(str(i)[len(str(i)) - 1])\n \n if lead == end:\n ans += 1\n \n for j in range((len(str(N)) - 2) + 1):\n if end == 0:\n \n continue\n elif end > lead_N and j == (len(str(N)) - 2) :\n \n continue\n elif end == lead_N and j == (len(str(N)) - 2):\n \n \n if len(str(N)) >= 3\n ans += int(str(N)[1:len(str(N)) - 1])\n\n if lead <= end_N:\n ans += 1\n #print("b")\n pass\n else:\n \n ans += 10 ** j\n\nprint(ans)', 'N= int(input())\nlead_N = int(str(N)[0]) \nend_N = int(str(N)[len(str(N)) - 1])\nans = 0\n#print(str(100)[len(str(100)) - 1])\nfor i in range(1, N + 1):\n lead = int(str(i)[0])\n end = int(str(i)[len(str(i)) - 1])\n \n if lead == end:\n ans += 1\n \n for j in range((len(str(N)) - 2) + 1):\n if end == 0:\n \n continue\n elif end > lead_N and j == (len(str(N)) - 2) :\n \n continue\n elif end == lead_N and j == (len(str(N)) - 2):\n \n \n\n ans += int(str(N)[1:len(str(N)) - 1])\n\n if lead <= end_N:\n ans += 1\n #print("b")\n pass\n else:\n \n ans += 10 ** j\n\nprint(ans)', 'N= int(input())\nlead_N = int(str(N)[0]) \nend_N = int(str(N)[-1])\nans = 0\nfor i in range(1, N + 1):\n lead = int(str(i)[0])\n end = int(str(i)[-1])\n \n if lead == end:\n ans += 1\n \n for j in range((len(str(N)) - 2) + 1):\n if end == 0 or (end > lead_N and j == (len(str(N)) - 2)):\n \n continue\n elif end == lead_N and j == (len(str(N)) - 2):\n \n \n if len(str(N)) >= 3:\n ans += int(str(N)[1:-1])\n if lead <= end_N:\n ans += 1\n else:\n \n ans += 10 ** j\n\nprint(ans)']
['Runtime Error', 'Runtime Error', 'Runtime Error', 'Accepted']
['s088421221', 's360481685', 's954258403', 's243665631']
[3064.0, 3064.0, 3064.0, 3064.0]
[1060.0, 17.0, 1081.0, 994.0]
[874, 901, 874, 783]
p02792
u517910772
2,000
1,048,576
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.
["def d():\n N = int(input())\n a = {}\n count = 0\n\n for i in range(1, N+1):\n l, r = str(i)[0], str(i)[-1]\n a[l, r] = a.get((l, r), 0) + 1\n\n # print(a)\n\n for i in range(1, N+1):\n l, r = str(i)[0], str(i)[-1]\n # print('a.get(({0}, {1}), 0) * a.get(({1}, {0}), 0) = {2}'.format(l,\n r, a.get((l, r), 0) * a.get((r, l), 0)))\n count += a.get((r, l), 0)\n\n print(count)\n\n\n##########\nd()\n", "def d():\n N = int(input())\n a = {}\n count = 0\n\n for i in range(1, N+1):\n l, r = str(i)[0], str(i)[-1]\n a[l, r] = a.get((l, r), 0) + 1\n\n # print(a)\n\n for i in range(1, N+1):\n l, r = str(i)[0], str(i)[-1]\n # 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)))\n count += a.get((r, l), 0)\n\n print(count)\n\n\n##########\nd()\n"]
['Runtime Error', 'Accepted']
['s977462639', 's331533679']
[2940.0, 3064.0]
[17.0, 326.0]
[503, 430]
p02792
u525227429
2,000
1,048,576
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.
['N = int(input())\nprint((N // 10) ** 2 + N % 5 + 8)', 'N = int(input())\n\nc = [[0 for _ in range(9)] for _ in range(9)]\n\nfor n in range(1, N + 1):\n l = n % 10\n if l == 0:\n continue\n t = n // (10 ** (len(str(n)) - 1))\n c[t - 1][l - 1] += 1\n\nans = 0\nfor i in range(9):\n for j in range(9):\n ans += c[i][j] * c[j][i]\nprint(ans)']
['Wrong Answer', 'Accepted']
['s892346965', 's133251200']
[2940.0, 3064.0]
[18.0, 191.0]
[50, 278]
p02792
u539969758
2,000
1,048,576
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.
['N = int(input())\n\nans_1 = 0\nfor i in range(N):\n str_i = str(i)\n length = len(str_i)\n if str_i[0] == str_i[length-1]:\n ans_1 += 1\n\nans_2 = 0\nfor i in range(N // 2):\n if i <= 9:\n j = 0\n tmp_num =int(str(i)+str(j)+str(i))\n while tmp_num <= N:\n ans_2 += 1\n j += 1\n tmp_num =int(str(i)+str(j)+str(i))\n \n else:\n j = 0\n tmp_num =int(str(i[-1])+str(j)+str(i[0]))\n while tmp_num <= N:\n ans_2 += 1\n j += 1\n tmp_num =int(str(i[-1])+str(j)+str(i[0]))\n\nprint(ans_1+2*ans_2)\n \n ', 'N = int(input())\n\nans_1 = 0\nfor i in range(N):\n str_i = str(i)\n length = len(str_i)\n if str_i[0] == str_i[length-1]:\n ans_1 += 1\n\nans_2 = 0\nhalf = N // 2\nfor i in range(half):\n if i <= 9:\n j = 0\n tmp_num =int(str(i)+str(j)+str(i))\n while tmp_num <= N:\n ans_2 += 1\n j += 1\n tmp_num =int(str(i)+str(j)+str(i))\n \n else:\n j = 0\n tmp_num =int(str(i[-1])+str(j)+str(i[0]))\n while tmp_num <= N:\n ans_2 += 1\n j += 1\n tmp_num =int(str(i[-1])+str(j)+str(i[0]))\n\nprint(ans_1+2*ans_2)\n \n \n', 'N = int(input())\n\nc = [[0 for i in range(9)] for j in range(9)]\nfor i in range(9):\n for j in range(9):\n c[str(i)[0]][str(j)[-1]] += 1\n\nans = 0\nfor i in range(9):\n for j in range(9):\n ans += c[i][j]*c[j][i]\n\nprint(ans)', 'N = int(input())\n\nc = [[0 for i in range(10)] for j in range(10)]\nfor i in range(N+1):\n str_i = str(i)\n c[int(str_i[0])][int(str_i[-1])] += 1\n\nans = 0\nfor i in range(1, 10):\n for j in range(1, 10):\n ans += c[i][j]*c[j][i]\n\nprint(ans)']
['Runtime Error', 'Runtime Error', 'Runtime Error', 'Accepted']
['s263292556', 's271069232', 's603750964', 's777089965']
[3064.0, 3064.0, 3060.0, 3064.0]
[151.0, 152.0, 17.0, 196.0]
[530, 543, 237, 249]
p02792
u573754721
2,000
1,048,576
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.
['n=int(input())\n\nans=0\nfor i in range(1,n+1):\n if i%10==0:\n continue\n for j in range(1,n+1):\n if str(i)[0]==str(j)[-1] and str(i)[-1]==str(j)[0]:\n print(i,j)\nprint(ans)', 'n=int(input())\nD={}\nfor i in range(1,n+1):\n s=(str(i)[0],str(i)[-1])\n if s not in D:\n D[s]=1\n else:\n D[s]+=1\nans=0\nfor i in D:\n if (i[1],i[0]) in D:\n ans+=D[i]*D[i[1],i[0]]\nprint(ans)']
['Wrong Answer', 'Accepted']
['s063070146', 's750301523']
[3884.0, 3064.0]
[2104.0, 196.0]
[225, 216]
p02792
u580073714
2,000
1,048,576
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.
['N = int(input())\nl = [[0] * 10 for _ in range(10)]\nans = 0\n\nfor i in range(1, N+1):\n s = int(str(i)[0])\n t = int(str(i)[-1])\n l[s][t] += 1\n\nfor i in range(1, 10):\n for j in range(1, 10):\n ans += l[i][j] * l[j][i]\nprint(l)\nprint(ans)', 'N = int(input())\nl = [[0] * 10 for _ in range(10)]\nans = 0\n\nfor i in range(1, N+1):\n s = int(str(i)[0])\n t = int(str(i)[-1])\n l[s][t] += 1\n\nfor i in range(1, 10):\n for j in range(1, 10):\n ans += l[i][j] * l[j][i]\nprint(ans)']
['Wrong Answer', 'Accepted']
['s117402549', 's377786464']
[3188.0, 3064.0]
[239.0, 249.0]
[251, 242]
p02792
u580404776
2,000
1,048,576
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.
['n = int(input())\nmem=[[0] * 10 for _ in range(10)]\n\nfor i in range(1, N+1):\n s = str(i)\n mem[int(s[0])][int(s[-1])] += 1 \n \nans = 0\nfor i in range(1, 10):\n for j in range(1, 10):\n ans += mem[i][j] * mem[j][i]\nprint(ans)\n', 'N = int(input())\nmem=[[0] * 10 for _ in range(10)]\n\nfor i in range(1, N+1):\n s = str(i)\n mem[int(s[0])][int(s[-1])] += 1 \n \nans = 0\nfor i in range(1, 10):\n for j in range(1, 10):\n ans += mem[i][j] * mem[j][i]\nprint(ans)']
['Runtime Error', 'Accepted']
['s664202017', 's376438645']
[3060.0, 3064.0]
[17.0, 192.0]
[239, 238]
p02792
u588341295
2,000
1,048,576
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.
['# -*- coding: utf-8 -*-\n\nimport sys\n\ndef input(): return sys.stdin.readline().strip()\ndef list2d(a, b, c): return [[c] * b for i in range(a)]\ndef list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]\ndef list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]\ndef ceil(x, y=1): return int(-(-x // y))\ndef INT(): return int(input())\ndef MAP(): return map(int, input().split())\ndef LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]\ndef Yes(): print(\'Yes\')\ndef No(): print(\'No\')\ndef YES(): print(\'YES\')\ndef NO(): print(\'NO\')\nsys.setrecursionlimit(10 ** 9)\nINF = 10 ** 18\nMOD = 10 ** 9 + 7\n\nclass BIT:\n """ Binary Indexed Tree """\n\n def __init__(self, n):\n # 0-indexed\n n += 1\n nv = 1\n while nv < n:\n nv *= 2\n self.size = nv\n self.tree = [0] * nv\n\n def sum(self, i):\n \n s = 0\n i += 1\n while i > 0:\n s += self.tree[i-1]\n i -= i & -i\n return s\n\n def add(self, i, x):\n \n i += 1\n while i <= self.size:\n self.tree[i-1] += x\n i += i & -i\n\n def get(self, l, r=None):\n \n \n if r is None: r = l + 1\n res = 0\n if r: res += self.sum(r-1)\n if l: res -= self.sum(l-1)\n return res\n\nN = INT()\nA = LIST()\n\nbit = BIT(N)\nans = 0\nfor i in range(N):\n \n if bit.sum(A[i]) == 0:\n ans += 1\n bit.add(A[i], 1)\nprint(ans)\n', "# -*- coding: utf-8 -*-\n\nimport sys\n\ndef input(): return sys.stdin.readline().strip()\ndef list2d(a, b, c): return [[c] * b for i in range(a)]\ndef list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]\ndef list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]\ndef ceil(x, y=1): return int(-(-x // y))\ndef INT(): return int(input())\ndef MAP(): return map(int, input().split())\ndef LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]\ndef Yes(): print('Yes')\ndef No(): print('No')\ndef YES(): print('YES')\ndef NO(): print('NO')\nsys.setrecursionlimit(10 ** 9)\nINF = 10 ** 18\nMOD = 10 ** 9 + 7\n\nN = INT()\n\nC = list2d(10, 10, 0)\nfor a in range(1, N+1):\n s = int(str(a)[0])\n t = int(str(a)[-1])\n C[s][t] += 1\n\nans = 0\nfor i in range(1, 10):\n for j in range(1, 10):\n ans += C[i][j] * C[j][i]\nprint(ans)\n"]
['Runtime Error', 'Accepted']
['s143774236', 's709999300']
[5236.0, 3064.0]
[22.0, 266.0]
[1715, 901]
p02792
u589913372
2,000
1,048,576
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.
['import numpy as np\nn = int(input())\na = 10\nb = 0\nx = np.zeros((10, 10, ))\nfor i in range(1,n+1):\n while (i // a != 0):\n a = a * 10\n c = (i * 10) // a\n d = i % 10\n x[c][d] += 1\n\nfor i in range(0,10):\n for j in range(0,10):\n b += x[i][j] * x[j][i]\nprint(b)', 'n = int(input())\na = 10\nb = 0\nwhile (n // a != 0):\n a = a * 10\n b += 1\nc = (n*10) // a\nd = n % 10\nprint(c,d)\nif (b == 0):\n print(n)\nelif (b == 1):\n m = 9\n if(d == 0):\n c += -1\n d = 10\n if(c > d):\n m += (c-2)*(c-1) +(2*d)\n m += 3*(c-1)\n print(m)\n else:\n m += c*(c-1)\n m += 3*c\n print(m)\nelif(b == 2):\n m = 108\n e = (n % 100) //10\n if(c > d):\n m += 5*((c-1) * 10 + e)\n m += 2*(8*((c-1) * 10 + e)) + 2*d\n print(m)\n else:\n m += 5*((c-1) * 10 + e +1)\n m += 2*(8*((c-1) * 10 + e)) + 2*(d-1)\n print(m)\nelif(b == 3):\n m = 1998\n e = (n % 100) //10\n if(c > d):\n m += 25*((c-1) * 10 + e)\n m += 22*(8*((c-1) * 10 + e)) + 22*d\n print(m)\n else:\n m += 25*((c-1) * 10 + e +1)\n m += 22*(8*((c-1) * 10 + e)) + 22*(d-1)\n print(m)\nelif(b == 4):\n m = 20088\n e = (n % 100) //10\n if(c > d):\n m += 225*((c-1) * 10 + e)\n m += 225*(8*((c-1) * 10 + e)) + 225*d\n print(m)\n else:\n m += 225*((c-1) * 10 + e +1)\n m += 225*(8*((c-1) * 10 + e)) + 225*(d-1)\n print(m)\nelif(b == 5):\n m = 202338\n e = (n % 100) //10\n if(c > d):\n m += 2225*((c-1) * 10 + e)\n m += 2222*(8*((c-1) * 10 + e)) + 2225*d\n print(m)\n else:\n m += 2225*((c-1) * 10 + e +1)\n m += 2225*(8*((c-1) * 10 + e)) + 2225*(d-1)\n print(m)', 'import numpy as np\nn = int(input())\na = 10\nb = 0\nx = np.zeros((10, 10, ))\nfor i in range(1,n+1):\n while (i // a != 0):\n a = a * 10\n c = (i * 10) // a\n d = i % 10\n x[c][d] += 1\n\nfor i in range(0,10):\n for j in range(0,10):\n b += int(x[i][j] * x[j][i])\nprint(b)']
['Wrong Answer', 'Wrong Answer', 'Accepted']
['s507675461', 's711339541', 's731612503']
[12424.0, 3192.0, 12420.0]
[596.0, 18.0, 594.0]
[265, 1283, 270]
p02792
u589969467
2,000
1,048,576
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.
['def calc_b(n,a):\n ans = 0\n str_n = str(n)\n str_a = str(a)\n if len(str_a) == 1:\n if int(str_a) <= n:\n print(a,str_a)\n ans += 1\n if int(str_a[0]+str_a[0]) <= n:\n print(a,str_a+str_a)\n ans += 1\n if len(str_a) == 2:\n if str_a[0] == str_a[1]:\n if int(str_a[0]) <= n:\n print(a,str_a[0])\n ans += 1\n if int(str_a[1]+str_a[0]) <= n:\n print(a,str_a[1]+str_a[0])\n ans += 1\n return ans\n\nn = int(input())\nkotae = 0\nfor i in range(1,n+1):\n if i%10!=0:\n #print(i)\n kotae += calc_b(n,i)\nprint(kotae)\n', "memo = [[0] * 10 for i in range(10)]\n\ndef kazu(start_num,end_num):\n global memo\n if memo[start_num][end_num] > 0:\n #print('memo',start_num,end_num)\n return memo[start_num][end_num]\n else:\n ans = 0\n \n if start_num == end_num:\n if start_num <= n:\n #print(start_num)\n ans += 1\n \n if start_num * 10 + end_num <= n:\n \n ans += 1\n \n for i in range(10):\n if start_num * 100 + i * 10 + end_num <= n:\n \n ans += 1\n else:\n break\n \n for i in range(100):\n if start_num * 1000 + i * 10 + end_num <= n:\n \n ans += 1\n else:\n break\n \n for i in range(1000):\n if start_num * 10000 + i * 10 + end_num <= n:\n \n ans += 1\n else:\n break\n \n for i in range(10000):\n if start_num * 100000 + i * 10 + end_num <= n:\n \n ans += 1\n else:\n break\n memo[start_num][end_num] = ans\n #print(start_num,end_num,'---',ans)\n return ans\n\nn = int(input())\nstr_n = str(n)\nkotae = 0\n#print(memo)\nfor a in range(1,n+1):\n if a%10!=0:\n str_a = str(a)\n #print('-----',a,'-----',int(str_a[-1]),int(str_a[0]))\n kotae += kazu(int(str_a[-1]),int(str_a[0]))\n #print(memo)\nprint(kotae)"]
['Wrong Answer', 'Accepted']
['s675516320', 's491199538']
[9212.0, 9256.0]
[135.0, 187.0]
[654, 1724]
p02792
u600402037
2,000
1,048,576
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.
['import sys\nimport numpy as np\n\nsr = lambda: sys.stdin.readline().rstrip()\nir = lambda: int(sr())\nlr = lambda: list(map(int, sr().split()))\n\nN = ir()\n\ntable = np.zeros((10, 10))\nfor x in range(1, N+1):\n x = str(x)\n i = int(x[0])\n j = int(x[-1])\n table[i][j] += 1\n\ntable = np.array(table)\nanswer = (table * table.T).sum()\nprint(answer)\n', 'import sys\n\nsr = lambda: sys.stdin.readline().rstrip()\nir = lambda: int(sr())\nlr = lambda: list(map(int, sr().split()))\n\nN = ir()\ncount = [[0] * 10 for _ in range(10)] # dp[head][tail]\nfor i in range(1, N+1):\n s = str(i)\n head = int(s[0]); tail = int(s[-1])\n count[head][tail] += 1\n\nanswer = 0\nfor h in range(10):\n for t in range(10):\n answer += count[h][t] * count[t][h]\nprint(answer)\n']
['Wrong Answer', 'Accepted']
['s183964957', 's414047719']
[14544.0, 3188.0]
[734.0, 199.0]
[419, 405]
p02792
u602740328
2,000
1,048,576
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.
['N = int(input())\nC = [0]*100\nfor i in range(N):\n s = str(i)\n C[10*int(s[0])+int(s[-1])] += 1\nprint(sum([C[10*i+j]*C[10*j+i] for i in range(10) for j in range(10)]))', 'N = int(input())\nC = [0]*100\nfor i in range(1,N+1):\n s = str(i)\n C[10*int(s[0])+int(s[-1])] += 1\nprint(sum([C[10*i+j]*C[10*j+i] for i in range(10) for j in range(10)]))\n']
['Wrong Answer', 'Accepted']
['s002778197', 's168995481']
[3060.0, 2940.0]
[200.0, 206.0]
[166, 171]
p02792
u608007704
2,000
1,048,576
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.
['N=int(input())\nl=[0]*10\n\nfor i in range(1,N+1):\n if str(i[0])==str(i[-1]):\n l[int(str(i[0]))]+=1\n\nans=0\nfor i in range(l):\n ans+=i*i\nprint(ans)', 'N=int(input())\nl=[[0]*10 for i in range(10)]\n\n\nfor i in range(1,N+1):\n l[int(str(i)[0])][int(str(i)[-1])]+=1\n\nans=0\nfor i in range(10):\n for j in range(10):\n ans+=l[i][j]*l[j][i]\n \nprint(ans)\n']
['Runtime Error', 'Accepted']
['s192695481', 's440963486']
[9128.0, 9192.0]
[24.0, 171.0]
[148, 198]
p02792
u610387229
2,000
1,048,576
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.
['def mainFunc():\n N = int(input())\n ans = 0\n\n for i in range(1, N + 1):\n tempAns = 1\n sentou = str(i)[0]\n saigo = str(i)[-1]\n \n if isRep(i, i):\n tempAns += 1\n \n for i in range(1, 10):\n if int(sentou + str(i) + saigo) <= N:\n tempAns += 1\n else:\n break\n \n for i in range(1, 100):\n if int(sentou + str(i).zfill(2) + saigo) <= N:\n tempAns += 1\n else:\n break\n \n for i in range(1, 1000):\n if int(sentou + str(i).zfill(3) + saigo) <= N:\n tempAns += 1\n else:\n break\n\n\n \n print(ans)\n\ndef isRep(i, j):\n sentoui = str(i)[0]\n saigoi = str(i)[-1]\n sentouj = str(j)[0]\n saigoj = str(j)[-1]\n\n if sentoui == saigoj and saigoi == sentouj:\n return True\n else:\n return False\n\nmainFunc()', 'def mainFunc():\n N = int(input())\n matrix = [[0 for i in range(10)] for i in range(10)]\n for i in range(1, N + 1):\n start = int(str(i)[0])\n end = int(str(i)[-1])\n matrix[start - 1][end - 1] += 1\n \n ans = 0\n for i in range(10):\n for j in range(10):\n ans += matrix[i][j] * matrix[j][i]\n\n print(ans)\n\n\nmainFunc()']
['Wrong Answer', 'Accepted']
['s781889458', 's864115330']
[3064.0, 3064.0]
[2104.0, 210.0]
[957, 369]
p02792
u626881915
2,000
1,048,576
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.
['n = int(input())\n\nmat = [[0]*10 for i in range(10)]\n\nfor i in range(n+1):\n if i % 10 != 0:\n str_i = str(i)\n mat[str_i[0]][str_i[-1]] += 1\nc = 0\nfor y in range(1, 10):\n for x in range(y, 10):\n c += mat[y][x] * mat[x][y]\nprint(c)', 'n = int(input())\n\nmat = [[0]*10 for i in range(10)]\n\nfor i in range(n+1):\n if i % 10 != 0:\n str_i = str(i)\n mat[int(str_i[0])][int(str_i[-1])] += 1\nc = 0\nfor y in range(1, 10):\n for x in range(y, 10):\n if y == x:\n c += mat[y][x] * mat[x][y]\n else:\n c += mat[y][x] * mat[x][y] * 2\nprint(c)\n']
['Runtime Error', 'Accepted']
['s368196034', 's958643820']
[3060.0, 3064.0]
[17.0, 185.0]
[238, 313]
p02792
u627803856
2,000
1,048,576
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.
['cnt_1 = 0\ncnt_2 = 0\nfor i in range(1,n+1):\n for j in range(i,n+1):\n \n #(1,1),(22,22),(333,333)\n if i==j and (str(i)[0]==str(j)[-1] and str(i)[-1]==str(j)[0]):\n cnt_1 += 1\n \n \n elif (str(i)[0]==str(j)[-1] and str(i)[-1]==str(j)[0]):\n cnt_2 += 1\nprint(cnt_1 + cnt_2*2)', 'n=int(input())\ncnt=[[0]*10 for i in range(10)] \nret = 0\n\ndef hoge(m):\n #return m[-1],m[0]\n return (m%10, int(str(m)[0]))\n\nfor k in range(1,n+1):\n a,b = hoge(k)\n cnt[a][b] += 1 \n\nfor i in range(1,10):\n for j in range(1,10):\n ret += cnt[i][j] * cnt[j][i]\n\nprint(ret)']
['Runtime Error', 'Accepted']
['s595094326', 's885885613']
[3064.0, 3188.0]
[18.0, 173.0]
[424, 315]
p02792
u628151901
2,000
1,048,576
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.
['def get_lmb(N):\n while (N >= 10):\n N = int(N/10)\n return N\n\ndef get_rmb(N):\n return N%10\n\ndef find_all():\n from collections import defaultdict\n dic = defaultdict(int)\n N = int(input())\n for i in range(1, N+1):\n lmb, rmb = get_lmb(i), get_rmb(i)\n dic[(lmb, rmb)] += 1\n print(dic)\n count = 0\n for i in range(1, 10):\n for j in range(1, 10):\n count += dic[(i, j)] * dic[(j, i)]\n \n \n return count\n\nprint(find_all())', 'def get_lmb(N):\n while (N >= 10):\n N = int(N/10)\n return N\n\ndef get_rmb(N):\n return N%10\n\ndef find_all():\n from collections import defaultdict\n dic = defaultdict(int)\n N = int(input())\n for i in range(1, N+1):\n lmb, rmb = get_lmb(i), get_rmb(i)\n dic[(lmb, rmb)] += 1\n # print(dic)\n count = 0\n for i in range(1, 10):\n for j in range(1, 10):\n count += dic[(i, j)] * dic[(j, i)]\n \n \n return count\n\nprint(find_all())']
['Wrong Answer', 'Accepted']
['s326833601', 's365942186']
[3316.0, 3316.0]
[272.0, 258.0]
[552, 554]
p02792
u629709614
2,000
1,048,576
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.
['N = int(input())\n\nnum = [[0] * 10 for _ in range(10)]\n\nfor i in range(1, N+1):\n top = int(str(i)[0])\n end = int(str(i)[-1])\n num[top][end] += 1\n\nans = 0\nfor i in range(10):\n for j in range(10):\n count += num[i][j] * num[j][i]\n\nprint(count)', 'N = int(input())\n\nnum = [[0] * 10 for i in range(10)]\n\nfor i in range(1, N+1):\n top = int(str(i)[0])\n end = int(str(i)[-1])\n num[top][end] += 1\n\ncount = 0\nfor i in range(10):\n for j in range(10):\n count += num[i][j] * num[j][i]\n\nprint(count)']
['Runtime Error', 'Accepted']
['s006025915', 's739116331']
[9060.0, 9072.0]
[176.0, 177.0]
[258, 260]
p02792
u638902622
2,000
1,048,576
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.
["from sys import stdin\n\ndef calc(N):\n result = {}\n for i in range(10):\n result[str(i)] = 0\n\n for i in range(N):\n if (str(i)[0] == str(i)[-1]):\n result[str(i)[0]] += 1\n for k in result:\n result[k] = result[k] * (result[k] - 1)\n return result\n\nif __name__ == '__main__':\n N = int(stdin.readline().rstrip())\n count = 0\n add_nums = calc(N)\n print(add_nums)\n for i in range(N):\n \n if (int(str(i)[::-1])) <= N and (not str(i)[-1] == '0'):\n count += 1\n if (str(i)[0] == str(i)[-1]) and (len(str(i)) > 1):\n count += add_nums[str(i)[0]]\n print(count)", 'N = int(input())\nc = []\nfor i in range(10):\n c.append([0] * 10)\nfor i in range(N):\n s = str(i+1)\n i1 = int(s[0])\n i2 = int(s[-1])\n c[i1][i2] += 1\ntotal = 0\nfor i in range(10):\n for j in range(10):\n total += c[i][j] * c[j][i]\nprint(total)']
['Wrong Answer', 'Accepted']
['s763619032', 's769398116']
[3064.0, 3064.0]
[374.0, 218.0]
[672, 262]
p02792
u640123177
2,000
1,048,576
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.
['n = int(input())\nans = 0\nfor i in range(1, 10):\n for j in range(1, 10):\n for k in range(1, n+1):\n a = 0\n b = 0\n K = str(k)\n if K[0] == str(i) and K[-1] == str(j):\n a += 1\n if K[0] == str(j) and K[-1] == str(i):\n b += 1\n ans += a*b\nprint(ans)\n', 'n = int(input())\nli_a = []\nfor i in range(9):\n li_a.append([0,0,0,0,0,0,0,0,0])\nfor i in range(1, n+1):\n k = str(i)\n k0 = int(k[0])\n k1 = int(k[-1])\n if k0*k1 != 0:\n li_a[k0-1][k1-1] += 1\nans = 0\nfor i in range(9):\n for j in range(9):\n ans += li_a[i][j]*li_a[j][i]\nprint(ans)']
['Wrong Answer', 'Accepted']
['s294327217', 's117767609']
[3060.0, 3064.0]
[2104.0, 225.0]
[288, 287]
p02792
u670180528
2,000
1,048,576
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.
['n=int(input())\nl=[[0]*10for _ in range(10)]\nfor x in range(1,n+1):l[a=int(str(x)[0])][b=int(str(x)[-1])]+=1\nprint(sum(l[i][j]*l[j][i]for i in range(10)for j in range(10)))', 'n=int(input())\nl=[[0]*10for _ in range(10)]\nfor x in range(1,n+1):l[int(str(x)[0])][int(str(x)[-1])]+=1\nprint(sum(l[i][j]*l[j][i]for i in range(10)for j in range(10)))']
['Runtime Error', 'Accepted']
['s922422195', 's176393904']
[2940.0, 3060.0]
[19.0, 231.0]
[171, 167]
p02792
u677253688
2,000
1,048,576
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.
['from collections import defaultdict\nn = int(input())\nd = defaultdict(int)\nfor i in range(1, n+1):\n s = str(i)\n d[(i[0], i[1])]+=1\nans = 0\nfor i, j in d.items():\n ans+=j*d[i[::-1]]\nprint(ans)', 'from collections import defaultdict\nn = int(input())\nd = defaultdict(int)\nfor i in range(1, n+1):\n s = str(i)\n d[(i[0], i[-1])]+=1\nans = 0\nfor i, j in d.items():\n ans+=j*d[i[::-1]]\nprint(ans)', 'from collections import defaultdict\nn = int(input())\nd = defaultdict(int)\nfor i in range(1, n+1):\n s = str(i)\n d[(s[0], s[-1])]+=1\nans = 0\nx = list(d.keys())\nfor i in x:\n ans+=d[i[::-1]]*d[i]\nprint(ans)\n']
['Runtime Error', 'Runtime Error', 'Accepted']
['s170153675', 's216039119', 's267179527']
[3316.0, 3316.0, 3436.0]
[20.0, 20.0, 142.0]
[193, 194, 208]
p02792
u686036872
2,000
1,048,576
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.
['N = int(input())\n\nA = [[0]*10 for i in range(10)]\n\nfor i in range(1, N+1):\n A[int(str(i)[0])][int(str(i)[-1])] = 1\n\nans = 0\nfor i in range(10):\n for j in range(10):\n ans += A[i][j] * A[j][i] \n\nprint(ans)', 'N = int(input())\n\nA = [[0]*10 for i in range(10)]\n\nfor i in range(1, N+1):\n A[int(str(i)[0])][int(str(i)[-1])] += 1\n \nprint(A)\n\nans = 0\nfor i in range(10):\n for j in range(10):\n ans += A[i][j] * A[j][i] \n\nprint(ans)\n', 'N = int(input())\n\nA = [[0]*10 for i in range(10)]\n\nfor i in range(1, N+1):\n A[int(str(i)[0])][int(str(i)[-1])] += 1\n\nans = 0\nfor i in range(10):\n for j in range(10):\n ans += A[i][j] * A[j][i] \n\nprint(ans)\n']
['Wrong Answer', 'Wrong Answer', 'Accepted']
['s010934205', 's102083077', 's693523057']
[3064.0, 3064.0, 3060.0]
[208.0, 227.0, 262.0]
[216, 232, 218]
p02792
u720630462
2,000
1,048,576
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.
['n = input()\ncount = 0\n\nfor i in range(n):\n for j in range(n):\n if str(i)[0] == str(j)[-1] and str(i)[-1] == str(j)[0]:\n count += 1\nprint(count)', 'n = int(input())\nd = {}\n\nfor i in range(1, n+1):\n start, end = str(i)[0], str(i)[-1]\n d[(start, end)] = d.get((start, end), 0) + 1\ncount = 0\nfor key, n_key in d.items():\n count += n_key * d.get(tuple(reversed(key)), 0)\nprint(count)']
['Runtime Error', 'Accepted']
['s175106728', 's968920645']
[2940.0, 3060.0]
[17.0, 214.0]
[152, 234]
p02792
u720636500
2,000
1,048,576
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.
['n = int(input())\nnl = str(n)\nll = len(nl)\nlis = []\nans = 0\nif ll == 1:\n print(n)\n exit()\n \ndef countn(a,b):\n cur = 0\n for i in range(1,n+1):\n fff=str(i)\n if fff[0] == a and fff[-1] == b:\n cur += 1\n return cur\n\nfor i in range(1, 10):\n for j in range(1, i+1):\n if i == j:\n ans += countn(i, j)*countn(j, i)\n else:\n ans += 2*countn(i, j)*countn(j, i)\nprint(ans)', 'n = int(input())\nnl = str(n)\nll = len(nl)\nlis = []\nans = 0\nif ll == 1:\n print(n)\n exit()\n \ndef countn(a,b):\n cur = 0\n if ll >= 3:\n cur += (10**(ll-2)-1)//9\n if a < int(nl[0]):\n cur += 10**(ll-2)\n elif a == int(nl[0]):\n nnl = nl[1:ll-1]\n if b > int(nl[-1]):\n cur += int(nnl)\n else:\n cur += (int(nnl)+1)\n elif ll == 2:\n if 10*a+b <= n:\n cur += 1\n if a == b:\n cur += 1\n return cur\n\nfor i in range(1, 10):\n for j in range(1, i+1):\n if i == j:\n ans += countn(i, j)*countn(j, i)\n else:\n ans += 2*countn(i, j)*countn(j, i)\nprint(ans)']
['Wrong Answer', 'Accepted']
['s953567268', 's165687145']
[3064.0, 3064.0]
[2104.0, 17.0]
[391, 605]
p02792
u727057618
2,000
1,048,576
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.
['n = int(input())\nl = len(n)\nc = [[0 for _ in range(9)] for _ in range(9)]\n\nfor i in range(1, n+1):\n c[i[0]-1][i[-1]-1] += 1\n\nres = 0\nfor i in range(9):\n for j in range(9):\n res += c[i][j] * c[j][i]\nprint(res)', 'n = int(input())\nc = [[0 for _ in range(10)] for _ in range(10)]\n\nfor i in range(1, n+1):\n si = str(i)\n a = int(si[0])\n b = int(si[-1])\n c[a][b] += 1\n\nres = 0\nfor i in range(10):\n for j in range(10):\n res += c[i][j] * c[j][i]\nprint(res)\n']
['Runtime Error', 'Accepted']
['s352402638', 's943625682']
[3188.0, 3060.0]
[20.0, 196.0]
[213, 245]
p02792
u729133443
2,000
1,048,576
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.
['d=[0]*100\nfor i in range(int(input())+1):\n s=str(i)\n d[int(s[0])*10+int(s[-1])]+=1\nprint(sum(d[i]*d[i%10*10+i//10]for i in range(100)))', 'd=[0]*100\nfor i in range(int(input())):s=str(i+1);d[int(s[0]+s[-1])]+=1\nprint(sum(d[i]*d[i%10*10+i//10]for i in range(100)))']
['Wrong Answer', 'Accepted']
['s040940172', 's504790709']
[3060.0, 2940.0]
[196.0, 182.0]
[137, 124]
p02792
u747703115
2,000
1,048,576
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.
['from functools import reduce\ndef lcm_base(x, y):\n return (x * y) // gcd(x, y)\n\ndef lcm_list(numbers):\n return reduce(lcm_base, numbers, 1)\n\ndef gcd(a, b):\n while b:\n a, b = b, a % b\n return a\n\nn = int(input())\nA = [int(i) for i in input().split()]\nk = lcm_list(A)\nr = 0\nfor i in range(n):\n r += k//A[i]\n if r > 10**9+7:\n r %= 10**9+7\nprint(r)', 'n = int(input())\nC = [[0]*10 for _ in range(10)]\nfor i in range(1,n+1):\n C[int(str(i)[0])][int(str(i)[-1])] += 1\nans = 0\nfor i in range(10):\n for j in range(10):\n ans += C[i][j]*C[j][i]\nprint(ans)']
['Runtime Error', 'Accepted']
['s897416932', 's791195250']
[3572.0, 9192.0]
[23.0, 169.0]
[374, 209]
p02792
u762275701
2,000
1,048,576
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.
["n = int(input())\na = [0] * 100\nfor i in range(1,n+1):\n msb = str(i)[0]\n lsb = str(i)[-1]\n if msb == '0' or lsb == '0':\n continue\n a[int(msb) * 10 + int(lsb)] += 1\n\ntmp = 0\nfor i, ai in enumerate(a):\n if '0' not in str(i):\n if i % 11 == 0:\n tmp += ai * ai\n else:\n tmp += ai * a[int(str(i)[::-1])]\n else:\n continue\n \nprint(tmp)\nprint(a)", "n = int(input())\na = [0] * 100\nfor i in range(1,n+1):\n msb = str(i)[0]\n lsb = str(i)[-1]\n if msb == '0' or lsb == '0':\n continue\n a[int(msb) * 10 + int(lsb)] += 1\n\ntmp = 0\nfor i, ai in enumerate(a):\n if '0' not in str(i):\n if i % 11 == 0:\n tmp += ai * ai\n else:\n tmp += ai * a[int(str(i)[::-1])]\n else:\n continue\n \nprint(tmp)"]
['Wrong Answer', 'Accepted']
['s954805568', 's342656270']
[3064.0, 3188.0]
[244.0, 240.0]
[365, 356]
p02792
u769383879
2,000
1,048,576
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.
['n = int(input())\n\nnum = 0\nfor i in range(n):\n for j in range(i,n):\n if str(i+1)[-1] == str(j+1)[0] and str(i+1)[0] == str(j+1)[-1]:\n num += 1\n\nprint(num)\n', 'n = int(input())\n\nnum = 0\n\nt_b = [[0 for i in range(10)] for j in range(10)]\nfor i in range(1,n+1):\n si = str(i)\n t_b[int(si[0])][int(si[-1])] += 1\n\nfor i in range(10):\n for j in range(10):\n num += t_b[i][j]*t_b[j][i]\n\nprint(num)\n']
['Wrong Answer', 'Accepted']
['s841561555', 's822604619']
[2940.0, 3068.0]
[2104.0, 184.0]
[175, 246]
p02792
u771458127
2,000
1,048,576
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.
['n = int(input())\n\ndef f(x):\n a1 = int(str(x)[0])\n a2 = x%10\n return (a1, a2)\n\ncount = {}\nfor x in range(1, n+1):\n key = f(x)\n if key in count:\n count[key] += 1\n else:\n count[key] = 1\n\nans = 0\nfor x in range(1, n+1):\n a0, a1 = f(x)\n if a1 != 0: # !\n key = (a1, a0) # swap\n ans += count[key]\n\nprint(ans)', 'from collections import defaultdict\nn = int(input())\n\ndef f(x):\n a1 = int(str(x)[0])\n a2 = x%10\n return (a1, a2)\n\ncount = defaultdict(int)\nfor x in range(1, n+1):\n key = f(x)\n count[key] += 1\n\nans = 0\nfor x in range(1, n+1):\n a0, a1 = f(x)\n if a1 != 0: # !\n key = (a1, a0) # swap\n ans += count[key]\n\nprint(ans)']
['Runtime Error', 'Accepted']
['s989835981', 's419731208']
[3064.0, 3316.0]
[404.0, 385.0]
[360, 352]
p02792
u780475861
2,000
1,048,576
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.
['n=input()\nintn=int(n)\nln=len(n)\n\nif intn<10:\n print(n)\n quit()\n\ndef count(i,j):\n res=0\n if i==j:\n res+=1\n if ln==2:\n if 10*i+j<=n:\n res+=1\n else:\n res+=(10**(ln-2)-1)//9\n if i<int(n[0]):\n res+=10**(ln-2)\n elif i==int(n[0]):\n tn=int(n[1:-1])\n if j<=intn%10:\n res+=tn+1\n else:\n res+=tn\n return res\n\nres=0\nfor i in range(1,10):\n for j in range(1,10):\n res+=count(i,j)*count(j,i)\nprint(res)\n ', 'n=input()\nintn=int(n)\nln=len(n)\n\nif intn<10:\n print(n)\n quit()\n\ndef count(i,j):\n res=0\n if i==j:\n res+=1\n if ln==2:\n if 10*i+j<=intn:\n res+=1\n else:\n res+=(10**(ln-2)-1)//9\n if i<int(n[0]):\n res+=10**(ln-2)\n elif i==int(n[0]):\n tn=int(n[1:-1])\n if j<=intn%10:\n res+=tn+1\n else:\n res+=tn\n return res\n\nres=0\nfor i in range(1,10):\n for j in range(1,10):\n res+=count(i,j)*count(j,i)\nprint(res)\n']
['Runtime Error', 'Accepted']
['s143953077', 's966717325']
[3064.0, 3064.0]
[18.0, 18.0]
[460, 455]
p02792
u780962115
2,000
1,048,576
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.
['n=int(input())\nlists=[[ 0 for j in range(10)]for i in range(10)]\nfor i in range(1,n+1):\n a=str(i)\n lists[int(a[0])][int(a[-1])]+=1\nc=0\nfor i in range(1,10):\n for j in range(1,10):\n c+=lists[i][j])*lists[j][i]\nprint(c) \n', 'n=int(input())\nlists=[[ 0 for j in range(10)]for i in range(10)]\nfor i in range(1,n+1):\n a=str(i)\n lists[int(a[0])][int(a[-1])]+=1\nc=0\nfor i in range(1,10):\n for j in range(1,10):\n c+=lists[i][j]*lists[j][i]\nprint(c) \n\n ']
['Runtime Error', 'Accepted']
['s005687141', 's549478660']
[2940.0, 3060.0]
[17.0, 191.0]
[242, 250]
p02792
u781758937
2,000
1,048,576
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.
['from math import log10\nN = int(input())\n \nC = 0\nfor i in range(1,10):\n for j in range(1,10):\n cij = 0\n cji = 0\n for k in range(1,N+1):\n m = log10(k) + 1\n if k//10**m == i and k%10 == j:\n cij += 1\n if k//10**m == j and k%10 == i:\n cji += 1\n C += cij*cji\nprint(C)', 'import numpy as np\nN = int(input())\n\ndef f(x):\n a = x%10\n b = 0\n while x > 0:\n b = x\n x //= 10\n return a,b\n\nfreq = np.zeros((10,10), dtype=int)\nfor k in range(1,N+1):\n a,b = f(k)\n freq[a,b] += 1\n\nprint((freq*freq.T).sum())']
['Wrong Answer', 'Accepted']
['s781850688', 's323004477']
[3060.0, 12504.0]
[2104.0, 638.0]
[303, 234]
p02792
u784022244
2,000
1,048,576
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.
['N=int(input())\n\nM=[[0]*10 for _ in range(10)]\n\nfor i in range(1,N+1):\n S=str(i)\n M[int(S[0])][int(S[-1])]+=1\n \nfor i in range(10):\n for j in range(10):\n ans+=M[i][j]*M[j][i]\n \nprint(ans)', 'N=int(input())\n\nM=[[0]*10 for _ in range(10)]\nfor i in range(1,N+1):\n S=str(i)\n f=int(S[0])\n b=int(S[-1])\n M[f][s]+=1\n \nans=0\nfor i in range(10):\n for j in range(10):\n ans+=M[i][j]*M[j][i]\n \nprint(ans)\n', 'N=int(input())\n\nM=[[0]*10 for _ in range(10)]\nfor i in range(1,N+1):\n S=str(N)\n f=int(S[0])\n b=int(S[-1])\n M[f][s]+=1\n \nans=0\nfor i in range(10):\n for j in range(10):\n ans+=M[i][j]*M[j][i]\n \nprint(ans)\n', 'N=int(input())\nL=[[0]*10 for i in range(10)]\nfor i in range(1,N+1):\n n=str(i)\n first=int(n[0])\n last=int(n[-1])\n L[first-1][last-1]+=1\nans=0\nfor i in range(1,N+1):\n n=str(i)\n first=int(n[0])\n last=int(n[-1])\n ans+=L[last-1][first-1]\n\nprint(ans)']
['Runtime Error', 'Runtime Error', 'Runtime Error', 'Accepted']
['s076181529', 's262136494', 's671710312', 's295407120']
[3060.0, 3060.0, 3060.0, 9168.0]
[191.0, 17.0, 17.0, 284.0]
[196, 214, 214, 268]
p02792
u793666115
2,000
1,048,576
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.
['n = int(input())\n\ncount = [0*[10] for i in range(10)]\n\nfor i in range(1,n+1):\n first = int(str(i)[0])\n last = int(str(i)[-1])\n\n if first == 0 or last == 0:\n continue\n else:\n count[first][last] += 1\n\nans = 0\nfor first in range(1,10):\n ans += count[first][last] * count[last][first]\n\nprint(ans)', 'n = int(input())\n\ncount = [[0]*10 for i in range(10)]\n\nfor i in range(1,n+1):\n first = int(str(i)[0])\n last = int(str(i)[-1])\n\n if first == 0 or last == 0:\n continue\n else:\n count[first][last] += 1\n\nans = 0\nfor first in range(1,10):\n for last in range(1,10):\n ans += count[first][last] * count[last][first]\nprint(ans)']
['Runtime Error', 'Accepted']
['s517280846', 's442741261']
[3064.0, 3064.0]
[17.0, 251.0]
[321, 347]
p02792
u795245552
2,000
1,048,576
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.
['N = int(input())\n\nBegEndTbl = []\nfor _ in range(10):\n BegEndTbl.append([0] * 10)\nprint(BegEndTbl)\n\nans = 0\nfor i in range(1, N + 1):\n left = int(str(i)[0])\n right = i % 10\n if left == right:\n ans += 1\n ans += BegEndTbl[right][left] * 2\n BegEndTbl[left][right] += 1\nprint(ans)', 'N = int(input())\n\nBegEndTbl = []\nfor _ in range(10):\n BegEndTbl.append([0] * 10)\n\nans = 0\nfor i in range(1, N + 1):\n left = int(str(i)[0])\n right = i % 10\n if left == right:\n ans += 1\n ans += BegEndTbl[right][left] * 2\n BegEndTbl[left][right] += 1\nprint(ans)']
['Wrong Answer', 'Accepted']
['s790939025', 's239403046']
[3064.0, 3060.0]
[218.0, 212.0]
[300, 283]
p02792
u844646164
2,000
1,048,576
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.
['from collections import defaultdict\nN = int(input())\nans = 0\nc = defaultdict(int)\n\nfor i in range(1, N+1):\n s = int(str(i)[0])\n t = int(str(i)[-1])\n if s != 0 and t != 0:\n c[(s, t)] += 1\n\nfor i in range(1, 10):\n for j in range(1, 10):\n ans += c[(i, j)] * c[(j, i)]\n print(i, j, c[(i, j)] * c[(j, i)])\nprint(ans)', 'from collections import defaultdict\nN = int(input())\nans = 0\nc = defaultdict(int)\n\nfor i in range(1, N+1):\n s = int(str(i)[0])\n t = int(str(i)[-1])\n if s != 0 and t != 0:\n c[(s, t)] += 1\n\nfor i in range(1, 10):\n for j in range(1, 10):\n ans += c[(i, j)] * c[(j, i)]\nprint(ans)\n']
['Wrong Answer', 'Accepted']
['s183426789', 's622539062']
[3316.0, 3316.0]
[268.0, 274.0]
[324, 286]
p02792
u855710796
2,000
1,048,576
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.
['N = int(input())\n\nN_s = int(str(N)[0])\nN_e = int(str(N)[-1])\nif len(str(N)) > 2:\n N_mid = int(str(N)[1:-1])\nelse:\n N_mid = 0\n\ndef search(s, e):\n ans = 0\n for i in range(1, len(str(N))+1):\n if i == 1:\n if s == e and s <= N:\n ans += 1\n continue\n else:\n if i != len(str(N)):\n ans += 10**(i-2)\n else:\n if N_s > s:\n ans += 10**(i-2)\n elif N_s == s:\n if N_e >= e:\n ans += N_mid + 1\n else:\n ans += N_mid\n\n return ans\n\nret = 0\nfor i in range(1, 10):\n for j in range(1, 10):\n print(i,j,search(i, j),search(j, i))\n ret += search(i, j) * search(j, i)\nprint(ret)', 'N = int(input())\n\nN_se = int(str(N)[0] + str(N)[-1])\nif len(str(N)) > 2:\n N_mid = int(str(N)[1:-1])\nelse:\n N_mid = 0\n\ndef search(s, e):\n ans = 0\n se = int(str(s) + str(e))\n for i in range(1, len(str(N))+1):\n if i == 1:\n if s == e and s <= N:\n ans += 1\n continue\n else:\n if i != len(str(N)):\n ans += 10**(i-2)\n else:\n if N_se > se:\n ans += 10**(i-2)\n elif N_se == se:\n ans += N_mid\n\n return ans\n\nret = 0\nfor i in range(1, 10):\n for j in range(1, 10):\n print(i, j, search(i, j), search(j, i))\n ret += search(i, j) * search(j, i)\nprint(ret)', 'N = int(input())\n\nN_s = int(str(N)[0])\nN_e = int(str(N)[-1])\nif len(str(N)) > 2:\n N_mid = int(str(N)[1:-1])\nelse:\n N_mid = 0\n\ndef search(s, e):\n ans = 0\n for i in range(1, len(str(N))+1):\n if i == 1:\n if s == e and s <= N:\n ans += 1\n continue\n else:\n if i != len(str(N)):\n ans += 10**(i-2)\n else:\n if N_s > s:\n ans += 10**(i-2)\n elif N_s == s:\n if N_e >= e:\n ans += N_mid + 1\n else:\n ans += N_mid\n\n return ans\n\nret = 0\nfor i in range(1, 10):\n for j in range(1, 10):\n ret += search(i, j) * search(j, i)\nprint(ret)']
['Wrong Answer', 'Wrong Answer', 'Accepted']
['s673002382', 's943359508', 's872342825']
[3064.0, 3064.0, 3064.0]
[19.0, 19.0, 18.0]
[808, 733, 763]
p02792
u864013199
2,000
1,048,576
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.
['N = int(input())\nans = 0\ntmp = int(str(N)[1:-1])\nNR = int(str(N)[-1])\nfor i in range(1,N+1):\n L = int(str(i)[0])\n R = int(str(i)[-1])\n if R == 0:\n continue\n if L == R:\n ans += 1\n for j in range(1,6):\n mini = (R*10**j) +L\n maxi = ((R+1)*10**j) +L-10\n if N < mini:\n break\n if maxi <= N:\n ans += 10**(j-1)\n continue\n \n if L <= NR:\n ans += tmp+1\n else:\n ans += tmp\n break\nprint(ans)\n', '\n\nN = int(input())\nlis = [[0]*10 for _ in range(10)]\n\nfor i in range(1,N+1):\n s = str(i)\n lis[int(s[0])][int(s[-1])] += 1\n\nans = 0\n\nfor i in range(10):\n for j in range(10):\n ans += lis[i][j]*lis[j][i]\nprint(ans)']
['Runtime Error', 'Accepted']
['s508572517', 's436551276']
[3064.0, 3064.0]
[1326.0, 190.0]
[519, 343]
p02792
u869917163
2,000
1,048,576
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.
['N = int(input())\nfrom numpy import zeros\nA = zeros((10,10))\n \nfor i in range(1,N+1):\n a = int(str(i)[0])\n b = int(str(i)[-1])\n A[a][b] += 1\n \ncnt = 0\nfor _ in range(1,N+1):\n a = int(str(_)[0])\n b = int(str(_)[-1])\n cnt += A[b][a]\n \nprint(cnt)', 'from numpy import zeros\n \nN = int(input())\nA = zeros((10,10))\n \nfor i in range(1,N+1):\n a = int(str(i)[0])\n b = int(str(i)[-1])\n A[a][b] += 1\n \ncnt = 0\nfor _ in range(1,N+1):\n a = int(str(_)[0])\n b = int(str(_)[-1])\n cnt += A[b][a]\n \nprint(cnt)', 'from numpy import zeros\n \nN = 25\nA = zeros((10,10))\n \nfor i in range(1,N+1):\n a = int(str(i)[0])\n b = int(str(i)[-1])\n A[a][b] += 1\n \ncnt = 0\nfor _ in range(1,N+1):\n a = int(str(_)[0])\n b = int(str(_)[-1])\n cnt += A[b][a]\n \nprint(cnt)', 'from numpy import zeros\n\nN = int(input())\nA = zeros((10,10))\n\nfor i in range(1,N+1):\n s = int(str(i)[0])\n t = int(str(i)[-1])\n A[s][t] += 1\n\ncnt = 0\nfor l in range(1,N+1)\n a = int(str(i)[0])\n b = int(str(i)[0])\n cnt += A[s][t]\n \nprint(cnt)', 'from numpy import zeros\n \nN = int(input())\nA = zeros((10,10))\n \nfor i in range(1,N+1):\n a = int(str(i)[0])\n b = int(str(i)[-1])\n A[a][b] += 1\n \ncnt = 0\nfor _ in range(1,N+1):\n a = int(str(_)[0])\n b = int(str(_)[-1])\n cnt += A[b][a]\n \nprint(cnt)', 'N = int(input())\nA =[[0]*10 for i in range(10)]\n \nfor i in range(1,N+1):\n a = int(str(i)[0])\n b = int(str(i)[-1])\n A[a][b] += 1\n \ncnt = 0\nfor _ in range(1,N+1):\n a = int(str(_)[0])\n b = int(str(_)[-1])\n cnt += A[b][a]\n \nprint(cnt)']
['Wrong Answer', 'Wrong Answer', 'Wrong Answer', 'Runtime Error', 'Wrong Answer', 'Accepted']
['s009830369', 's235357066', 's365058719', 's460620957', 's508096458', 's236106943']
[12488.0, 12484.0, 12504.0, 2940.0, 12484.0, 3064.0]
[1128.0, 1114.0, 150.0, 17.0, 1113.0, 493.0]
[249, 251, 241, 246, 251, 237]
p02792
u871841829
2,000
1,048,576
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.
['N = int(input())\n\nc = [[0] * 10] * 10\nfor x in range(1, N+1):\n check = str(x)\n it = int(check[0])\n jt = int(check[-1])\n c[it][jt] += 1\n\nans = 0\nfor i in range(0,10):\n for j in range(0,10):\n ans += c[i][j] * c[j][i]\n\nprint(ans)\n\n', 'N = int(input())\n\nc = [[0 for _ in range(10)] for __ in range(10)]\nfor x in range(1, N+1):\n check = str(x)\n it = int(check[0])\n jt = int(check[-1])\n c[it][jt] += 1\n\nans = 0\nfor i in range(0,10):\n for j in range(0,10):\n ans += c[i][j] * c[j][i]\n\nprint(ans)\n']
['Wrong Answer', 'Accepted']
['s565089713', 's049440783']
[3060.0, 3060.0]
[198.0, 203.0]
[250, 278]
p02792
u872538555
2,000
1,048,576
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.
['n = int(input())\ncnt = [[0] * 10 for i in range(10)]\nfor i in range(1,n+1):\n cnt[int(str(i)[0])][int(str(i)[-1])] += 1\n\nprint(cnt)\n \nans = 0\nfor i in range(10):\n for j in range(10):\n ans += cnt[i][j] * cnt[j][i]\nprint(ans)', 'n = int(input())\ncnt = [[0] * 10 for i in range(10)]\nfor i in range(1,n+1):\n cnt[int(str(i)[0])][int(str(i)[-1])] += 1\n \nans = 0\nfor i in range(10):\n for j in range(10):\n ans += cnt[i][j] * cnt[j][i]\nprint(ans)']
['Wrong Answer', 'Accepted']
['s384425007', 's692906897']
[3064.0, 3064.0]
[228.0, 230.0]
[238, 226]
p02792
u872887731
2,000
1,048,576
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.
['ii = lambda : int(input())\nmi = lambda : map(int,input().split())\nli = lambda : list(map(int,input().split()))\n\nn = ii()\ndp = [0]*(n+1)\nfor i in range(1,n+1):\n s = str(i)\n if s[0] == s[-1]:\n dp[int(s[0])] += 1\n elif s[-1] == "0":\n continue\n else:\n ima = int(s[0])*10 + int(s[-1])\n dp[ima] += 1\nans = 0\nfor i in range(1,100):\n s = str(i)\n if s[0] == s[-1]:\n ans += dp[int(s[0])]**2\n dp[int(s[0])] = 0\n elif s[-1] == "0":\n continue\n else:\n ima = int(s[0])*10 + int(s[-1])\n ima2 = int(s[-1])*10 + int(s[0])\n ans += dp[ima] * dp[ima2] *2\n dp[ima] = 0\n dp[ima2] = 0\nprint(ans)\n\n', 'ii = lambda : int(input())\nmi = lambda : map(int,input().split())\nli = lambda : list(map(int,input().split()))\n\nn = ii()\ndp = [0]*(n+1)\nfor i in range(1,n+1):\n s = str(i)\n if s[0] == s[-1]:\n dp[int(s[0])] += 1\n elif s[-1] == "0":\n continue\n else:\n ima = int(s[0])*10 + int(s[-1])\n dp[ima] += 1\nans = 0\nfor i in range(1,min(100,n+1)):\n s = str(i)\n if s[0] == s[-1]:\n ans += dp[int(s[0])]**2\n dp[int(s[0])] = 0\n elif s[-1] == "0":\n continue\n else:\n ima = int(s[0])*10 + int(s[-1])\n ima2 = int(s[-1])*10 + int(s[0])\n ans += dp[ima] * dp[ima2] *2\n dp[ima] = 0\n dp[ima2] = 0\nprint(ans)', 'ii = lambda : int(input())\nmi = lambda : map(int,input().split())\nli = lambda : list(map(int,input().split()))\n\nn = ii()\ndp = [0]*max(101,(n+1))\nfor i in range(1,n+1):\n s = str(i)\n if s[0] == s[-1]:\n dp[int(s[0])] += 1\n elif s[-1] == "0":\n continue\n else:\n ima = int(s[0])*10 + int(s[-1])\n dp[ima] += 1\nans = 0\nfor i in range(1,min(100,n+1)):\n s = str(i)\n if s[0] == s[-1]:\n ans += dp[int(s[0])]**2\n dp[int(s[0])] = 0\n elif s[-1] == "0":\n continue\n else:\n ima = int(s[0])*10 + int(s[-1])\n ima2 = int(s[-1])*10 + int(s[0])\n ans += dp[ima] * dp[ima2] *2\n dp[ima] = 0\n dp[ima2] = 0\nprint(ans)\n\n']
['Runtime Error', 'Runtime Error', 'Accepted']
['s436623188', 's953895875', 's752495628']
[4596.0, 4596.0, 4596.0]
[227.0, 235.0, 238.0]
[681, 688, 699]
p02792
u875449556
2,000
1,048,576
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.
['N = int(input())\n\nc = [[0]*10 for i in range(10)]\n\nfor i in range(1,N+1):\n a = N % 10\n b = 0\n while N > 0:\n b = N\n N = N // 10\n c[a][b] += 1\n\nans = 0\nfor i in range(10):\n for j in range(10):\n ans += c[i][j]*c[j][i]\n\nprint(ans)', 'N = int(input())\n\nc = [[0]*10 for i in range(10)]\n\nfor i in range(1,N+1):\n a = i % 10\n b = 0\n while i > 0:\n b = i\n i = i // 10\n c[a][b] += 1\n\nans = 0\nfor i in range(10):\n for j in range(10):\n ans += c[i][j]*c[j][i]\n\nprint(ans)']
['Wrong Answer', 'Accepted']
['s913773905', 's990652050']
[3064.0, 3064.0]
[75.0, 238.0]
[262, 262]
p02792
u879266613
2,000
1,048,576
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.
['N = int(input())\n\n\ncnt = 0\n\nfor i in range(N):\n for k in range(N):\n if str(i)[0] == str(k)[len(str(k)) - 1] and str(k)[0] == str(k)[len(str(k)) - 1]:\n cnt += 1\n \nprint(cnt) ', 'N = int(input())\n\nlist = [[0 for i in range(10)] for j in range(10)]\n\ncnt = 0\n\nfor i in range(1, N+1):\n head = int(str(i)[0])\n tail = int(str(i)[len(str(i)) - 1])\n list[head][tail] += 1\n\nfor i in range(1, 10):\n for j in range(1, 10):\n cnt += list[i][j] * list[j][i]\nprint(cnt)']
['Wrong Answer', 'Accepted']
['s668530551', 's694928778']
[3060.0, 3064.0]
[2104.0, 297.0]
[205, 295]
p02792
u896741788
2,000
1,048,576
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.
['n=int(input())\nl=[[0]*9]*9\nfor i in range(1,n):\n if i%10:\n l[int(str(i)[0])-1][int(str(i)[-1])-1]+=1\nans=0\nfor i in range(9):\n for j in range(9):\n ans+=l[i][j]*l[j][i]\nprint(ans)', 'n=int(input())\nl=[[0 for i in range(10)]for s in range(10)]\nfor i in range(n+1):\n if i%10:\n l[int(str(i)[0])-1][int(str(i)[-1])-1]+=1\nans=0\nfor i in range(9):\n for j in range(9):\n ans+=l[i][j]*l[j][i]\nprint(ans)\n']
['Wrong Answer', 'Accepted']
['s971116331', 's461929704']
[3064.0, 3060.0]
[239.0, 238.0]
[187, 221]
p02792
u899308536
2,000
1,048,576
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.
['N = int(input())\nTT = [[0]*10 for i in range(10)]\n\nfor i in range(N+1):\n top = int(str(i)[0])\n tail = int(str(i)[-1])\n TT[top][tail] += 1\nprint(TT)\ny = 0\nfor i in range(1,10):\n for j in range(1,10):\n y += TT[i][j]*TT[j][i]\nprint(y)', 'import numpy as np\nN = int(input())\n\nTT = np.zeros((10,10))\n\nfor i in range(N+1):\n top = int(str(i)[0])\n tail = int(str(i)[-1])\n TT[top,tail] += 1\nprint(TT)\ny = 0\nfor i in range(1,10):\n for j in range(1,10):\n y += TT[i,j]*TT[j,i]\nprint(int(y))', 'import numpy as np\nN = int(input())\n\nTT = np.zeros((10,10))\n\nfor i in range(N+1):\n top = int(str(i)[0])\n tail = int(str(i)[-1])\n TT[top,tail] += 1\n#print(TT)\ny = 0\nfor i in range(1,10):\n for j in range(1,10):\n y += TT[i,j]*TT[j,i]\nprint(int(y))']
['Wrong Answer', 'Wrong Answer', 'Accepted']
['s387428474', 's659555333', 's221307662']
[3064.0, 12500.0, 12396.0]
[236.0, 718.0, 786.0]
[250, 296, 297]
p02792
u899782392
2,000
1,048,576
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.
['import sys\nimport defaultdict\nN = int(sys.stdin.readline())\ncnt = defaultdict(int)\nfor i in range(1, N+1):\n str_i = str(i)\n cnt[(str_i[0], str_i[-1])] += 1\n\nans = 0\nfor d1 in range(9):\n for d2 in range(9):\n ans += cnt[(d1, d2)] * cnt[(d2, d1)]\nreturn ans\n ', 'import sys\nfrom collections import defaultdict\nN = int(sys.stdin.readline())\ncnt = defaultdict(int)\nfor i in range(1, N+1):\n str_i = str(i)\n cnt[(str_i[0], str_i[-1])] += 1\n \nans = 0\nfor d1 in range(1, 10):\n for d2 in range(1, 10):\n d1, d2 = str(d1), str(d2)\n ans += cnt[(d1, d2)] * cnt[(d2, d1)]\nprint(ans)']
['Runtime Error', 'Accepted']
['s016279881', 's216153839']
[3060.0, 3572.0]
[17.0, 147.0]
[265, 316]
p02792
u900848911
2,000
1,048,576
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.
['N = int(input())\nsample = [0] * 100\n\nfor i in range(1,N+1):\n\n num = str(i)\n first = num[0]\n final = num[-1]\n print(first)\n print(final)\n\n sample[int(first+final)] += 1\n print(int(first+final))\n\nans = 0\n\nfor i in range(1,10):\n for j in range(1,10):\n ans += sample[int(str(i)+str(j))] * sample[int(str(j)+str(i))]\n\nprint(ans)\n\n\n \n', 'N = int(input())\nsample = [0] * 100\n\nfor i in range(1,N+1):\n\n num = str(i)\n first = num[0]\n final = num[-1]\n \n sample[int(first+final)] += 1\n\nans = 0\n\nfor i in range(1,10):\n for j in range(1,10):\n ans += sample[int(str(i)+str(j))] * sample[int(str(j)+str(i))]\n\nprint(ans)\n\n\n \n']
['Wrong Answer', 'Accepted']
['s529343134', 's253714882']
[4940.0, 3060.0]
[583.0, 181.0]
[362, 304]
p02792
u934868410
2,000
1,048,576
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.
['n = int(input())\nt = [0] * 100\nfor i in range(11, 100):\n msb = i // 10\n lsb = i % 10\n if lsb == 0:\n continue\n for j in range(1, n+1):\n if j % 10 == lsb and int(str(j)[0]) == msb:\n t[i] += 1\n\nans = 0\nfor i in range(11, 100):\n msb = i // 10\n lsb = i % 10\n if lsb == 0:\n continue\n if msb == lsb:\n ans += t[i] * (t[i] - 1) // 2\n else:\n ans += t[i] * t[lsb * 10 + msb]\nprint(ans)', 'n = int(input())\nt = [0] * 100\nfor i in range(11, 100):\n msb = i // 10\n lsb = i % 10\n if lsb == 0:\n continue\n for j in range(1, n+1):\n if j % 10 == lsb and int(str(j)[0]) == msb:\n t[i] += 1\n\nans = 0\nfor i in range(11, 100):\n msb = i // 10\n lsb = i % 10\n if lsb == 0:\n continue\n if msb == lsb:\n ans += t[i] ** 2\n else:\n ans += t[i] * t[lsb * 10 + msb]\nprint(ans)\n']
['Wrong Answer', 'Accepted']
['s433858544', 's214256699']
[3064.0, 9196.0]
[2104.0, 1905.0]
[403, 391]
p02792
u936985471
2,000
1,048,576
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.
['N=int(input())\nS=str(N)\nketa=1\ntemp=N\nwhile temp//10>0:\n keta+=1\n temp//=10\nprint(keta)\nans=0\nfor i in range(1,N):\n n=str(i)\n a=n[0]\n b=n[-1]\n cur_keta=len(n)\n if cur_keta<keta:\n if a==b:\n ans+=10*max(cur_keta-2,0)\n else:\n ans+=10*max(cur_keta-2,0)-1\n else:\n if a<b:\n pass\n else:\n Si=S[1:-2]\n if len(Si)>0:\n ans+=int(Si)\n \nprint(ans) \n \n ', 'import sys\nreadline = sys.stdin.readline\n\nN = int(readline())\n\nfrom collections import defaultdict\ndic = defaultdict(int)\n\nfor i in range(1, N + 1):\n s = str(i)\n dic[(int(s[0]),int(s[-1]))] += 1\n \nans = 0\nfor i in range(1, 10):\n for j in range(1, 10):\n ans += dic[(i,j)] * dic[(j,i)]\n \nprint(ans)']
['Wrong Answer', 'Accepted']
['s785934240', 's920280872']
[3064.0, 9444.0]
[187.0, 155.0]
[408, 306]
p02792
u944643608
2,000
1,048,576
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.
['N = int(input())\nans_lis = [[0] * 9 for i in range(9)]\nfor i in range(1,N+1):\n t = str(i)\n mae = int(t[0])\n ushiro = int(t[-1])\n if usiro == 0:\n continue\n ans_lis[mae-1][ushiro-1] += 1\nans = 0\nfor i in range(9):\n for j in range(9):\n ans += ans_lis[i][j] * ans_lis[j][i]\nprint(ans)\n', 'N = int(input())\nans_lis = [[0\u3000for k in range(9)] for i in range(9)]\nfor i in range(1,N+1):\n t = str(i)\n mae = int(t[0])\n ushiro = int(t[-1])\n ans_lis[mae-1][ushiro-1] += 1\nans = 0\nfor i in range(9):\n for j in range(9):\n ans += ans_lis[i][j] * ans_lis[j][i]\nprint(ans)\n', 'N = int(input())\nans_lis = [[0\u3000for k in range(9)] for i in range(9)]\nfor i in range(1,N+1):\n t = str(i)\n mae = int(t[0])\n ushiro = int(t[-1])\n if ushiro == 0:\n continue\n ans_lis[mae-1][ushiro-1] += 1\nans = 0\nfor i in range(9):\n for j in range(9):\n ans += ans_lis[i][j] * ans_lis[j][i]\nprint(ans)\n', 'N = int(input())\nans_lis = [[0\u3000for _ in range(9)] for i in range(9)]\nfor i in range(1,N+1):\n t = str(i)\n mae = int(t[0])\n ushiro = int(t[-1])\n ans_lis[mae-1][ushiro-1] += 1\nans = 0\nfor i in range(9):\n for j in range(9):\n ans += ans_lis[i][j] * ans_lis[j][i]\nprint(ans)', 'N = int(input())\nans_lis = [[0] * 9 for i in range(9)]\nfor i in range(1,N+1):\n t = str(i)\n mae = int(t[0])\n ushiro = int(t[-1])\n if ushiro == 0:\n continue\n ans_lis[mae-1][ushiro-1] += 1\nans = 0\nfor i in range(9):\n for j in range(9):\n ans += ans_lis[i][j] * ans_lis[j][i]\nprint(ans)\n']
['Runtime Error', 'Runtime Error', 'Runtime Error', 'Runtime Error', 'Accepted']
['s091760567', 's176513023', 's302547456', 's727521572', 's852269506']
[3060.0, 2940.0, 2940.0, 2940.0, 3064.0]
[17.0, 17.0, 17.0, 17.0, 213.0]
[293, 279, 310, 279, 294]
p02792
u969211566
2,000
1,048,576
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.
['N = int(input())\nd = {x: [int((str(x))[0]),x % 10] for x in range(1,N)} \n\ncount = 0\nfor i in range(1,N):\n for j in range (i,N):\n if d[i] == d[j]:\n print(d[i],d[j])\n count += 1\nprint(count)', 'n = int(input())\n\nN = n + 1\ntotalcount = 0\n\nfor i in range(1,N):\n a = str(i)\n a_first = a[0]\n a_end = a[len(str(i)) - 1]\n for j in range(1,N):\n b = str(j)\n b_first = b[0]\n b_end = b[len(str(j)) - 1]\n if a_first == b_end and a_end == b_first:\n totalcount += 1\n print(a,j)\nprint(totalcount)', 'N = int(input())\nt = [[0] * 10 for _ in range(10)]\nfor i in range(1, N + 1):\n s = str(i)\n t[int(s[0])][int(s[-1])] += 1\nresult = 0\nfor i in range(1, 10):\n for j in range(1, 10):\n result += t[i][j] * t[j][i]\nprint(result)']
['Wrong Answer', 'Wrong Answer', 'Accepted']
['s879332961', 's947441120', 's497174562']
[45168.0, 3756.0, 3064.0]
[2106.0, 2104.0, 183.0]
[220, 314, 236]
p02792
u987164499
2,000
1,048,576
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.
['from sys import stdin\n\nn = int(stdin.readline().rstrip())\n\nli = [[0 for i in range(10)]for j in range(10)]\n\nfor k in range(1,n+1):\n atama = int(str(k)[0])\n ushiro = int(str(k)[-1])\n li[atama][ushiro] += 1\npoint = 0\nfor l in range(1,10):\n for m in range(1,10):\n point += li[l][m]**2\n\nprint(point)', 'from collections import defaultdict\n\nn = int(input())\ndic = defaultdict(int)\n\nfor i in range(1,n+1):\n s = str(i)\n dic[int(s[0]),int(s[-1])] += 1\n\npoint = 0\n\nfor i in range(1,10):\n for j in range(1,10):\n point += dic[i,j]*dic[j,i]\n\nprint(point)']
['Wrong Answer', 'Accepted']
['s685657019', 's776481699']
[3064.0, 3316.0]
[231.0, 212.0]
[314, 259]
p02792
u989345508
2,000
1,048,576
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.
['n=int(input())\ncheck=[[0]*9 for i in range(9)]\nfor i in range(1,n+1):\n s=str(i)\n s1=int(s[0])-1\n s2=int(s[-1])-1\n check[s1][s2]+=1\nfor i in range(9):\n for j in range(9):\n cnt+=check[i][j]*check[j][i]\nprint(cnt)\n', 'n=int(input())\ncheck=[[0]*9 for i in range(9)]\nfor i in range(1,n+1):\n s=str(i)\n s1=int(s[0])-1\n s2=int(s[-1])-1\n if s2==-1:continue\n check[s1][s2]+=1\ncnt=0\nfor i in range(9):\n for j in range(9):\n cnt+=check[i][j]*check[j][i]\nprint(cnt)\n']
['Runtime Error', 'Accepted']
['s625151763', 's602235146']
[3060.0, 3060.0]
[211.0, 213.0]
[233, 262]
p02793
u002539468
2,000
1,048,576
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).
['import fractions\nfrom functools import reduce\n\n\ndef lcm_base(x, y):\n return (x * y) // fractions.gcd(x, y)\n\n\ndef lcm(numbers):\n return reduce(lcm_base, numbers, 1)\n\nn = int(input())\na = list(map(int, input().split()))\n\nl = lcm(a)\nanswer = 0\nfor aa in a:\n answer += l // aa\n if answer >= 10 ** 9 + 7:\n answer = answer % (10 ** 9 + 7)\n\nprint(answer)\n', '# import math\n# import fractions\n\nn = int(input())\na = list(map(int, input().split()))\n\nmod = 10 ** 9 + 7\n\n\ndef prime_factorize(n):\n a = {}\n while n % 2 == 0:\n if 2 not in a:\n a[2] = 0\n a[2] += 1\n n //= 2\n f = 3\n while f * f <= n:\n if n % f == 0:\n if f not in a:\n a[f] = 0\n a[f] += 1\n n //= f\n else:\n f += 2\n if n != 1:\n a[n] = 1\n return a\n\n\nl = prime_factorize(a[0])\nxs = {}\nxs[a[0]] = prime_factorize(a[0])\nfor i in range(1, n):\n ps = prime_factorize(a[i])\n xs[a[i]] = ps\n for k in ps.keys():\n if k in l:\n l[k] = max(ps[k], l[k])\n else:\n l[k] = ps[k]\n\n# print(l)\n# print(xs)\n\nanswer = 0\nfor x in a:\n s = 1\n for k in l.keys():\n if k in xs[x]:\n s = (s * (k ** (l[k] - xs[x][k]))) % mod\n else:\n s = (s * (k ** l[k])) % mod\n print(s)\n answer = (answer + s) % mod\nprint(answer)\n', '# import math\n# import fractions\n\nn = int(input())\na = list(map(int, input().split()))\n\nmod = 10 ** 9 + 7\n\n\ndef prime_factorize(n):\n a = {}\n while n % 2 == 0:\n if 2 not in a:\n a[2] = 0\n a[2] += 1\n n //= 2\n f = 3\n while f * f <= n:\n if n % f == 0:\n if f not in a:\n a[f] = 0\n a[f] += 1\n n //= f\n else:\n f += 2\n if n != 1:\n a[n] = 1\n return a\n\n\nl = prime_factorize(a[0])\nxs = {}\nxs[a[0]] = prime_factorize(a[0])\nfor i in range(1, n):\n ps = prime_factorize(a[i])\n xs[a[i]] = ps\n for k in ps.keys():\n if k in l:\n l[k] = max(ps[k], l[k])\n else:\n l[k] = ps[k]\n\n# print(l)\n# print(xs)\n\nanswer = 0\nfor x in a:\n s = 1\n # for k in l.keys():\n \n \n # else:\n \n # print(s)\n answer = (answer + s) % mod\nprint(answer)\n', 'import fractions\nfrom functools import reduce\n\n\ndef lcm_base(x, y):\n return (x * y) // fractions.gcd(x, y)\n\n\ndef lcm(numbers):\n return reduce(lcm_base, numbers, 1)\n\nn = int(input())\na = list(map(int, input().split()))\n\nl = lcm(a)\nanswer = 0\nfor aa in a:\n answer += l // aa\n answer = answer % (10 ** 9 + 7)\n\nprint(answer)\n', '# import math\nimport fractions\n\nn = int(input())\na = list(map(int, input().split()))\n\nmod = 10 ** 9 + 7\n\nlcm = a[0]\nfor i in range(1, n):\n # lcm = lcm * a[i] // math.gcd(lcm, a[i])\n lcm = lcm * a[i] // fractions.gcd(lcm, a[i])\n\nanswer = 0\nfor x in a:\n answer = (answer + lcm // x) % mod\nprint(answer)\n', '# import math\n# import fractions\n\nn = int(input())\na = list(map(int, input().split()))\n\nmod = 10 ** 9 + 7\n\n\ndef prime_factorize(n):\n a = {}\n while n % 2 == 0:\n if 2 not in a:\n a[2] = 0\n a[2] += 1\n n //= 2\n f = 3\n while f * f <= n:\n if n % f == 0:\n if f not in a:\n a[f] = 0\n a[f] += 1\n n //= f\n else:\n f += 2\n if n != 1:\n if n not in a:\n a[n] = 0\n a[n] += 1\n return a\n\n\n\nl = prime_factorize(a[0])\n# print(l)\n# xs = {}\n\nfor i in range(1, n):\n ps = prime_factorize(a[i])\n # print(ps)\n # xs[a[i]] = ps\n for k, v in ps.items():\n if k in l:\n l[k] = max(v, l[k])\n else:\n l[k] = v\n\n# print(l)\n# print(xs)\n\nL = 1\nfor k, v in l.items():\n L = L * pow(k, v, mod) % mod\n\nanswer = 0\nfor x in a:\n answer = (answer + L * pow(x, mod - 2, mod)) % mod\nprint(answer)\n']
['Time Limit Exceeded', 'Wrong Answer', 'Wrong Answer', 'Time Limit Exceeded', 'Time Limit Exceeded', 'Accepted']
['s198793201', 's405463574', 's466189566', 's722114602', 's765880605', 's294413352']
[6136.0, 7480.0, 7480.0, 6136.0, 6112.0, 4596.0]
[2104.0, 2104.0, 761.0, 2104.0, 2104.0, 804.0]
[367, 993, 1005, 333, 304, 992]
p02793
u003475507
2,000
1,048,576
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).
['import sys\nimport fractions\n\nsys.setrecursionlimit(10000000)\ninput=sys.stdin.readline\n\nn = int(input())\na = list(map(int,input().split()))\n\ndef gcd(a, b):\n return a if b == 0 else gcd(b, a%b)\n\ndef lcm(a, b):\n return a // fractions.gcd(a, b) * b\n\nmod = 10**9+7\n\nx=a[0]\n\nfor i in a[1:]:\n x=lcm(x,i)\nans=0\nfor i in range(n):\n ans+= x//a[i]%mod\n\nprint(ans%mod)\n', 'import sys\n\nsys.setrecursionlimit(10000000)\ninput=sys.stdin.readline\n\nn = int(input())\na = list(map(int,input().split()))\n\ndef gcd(a, b):\n return a if b == 0 else gcd(b, a%b)\n\ndef lcm(a, b):\n return a // gcd(a, b) * b\n\nmod = 10**9+7\n\nx=a[0]\n\nfor i in a[1:]:\n x=lcm(x,i)\nans=0\nfor i in range(n):\n ans+= x//a[i]\n\nprint(ans%mod)\n']
['Time Limit Exceeded', 'Accepted']
['s424724096', 's089428814']
[6108.0, 4084.0]
[2104.0, 1888.0]
[369, 338]
p02793
u019685451
2,000
1,048,576
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).
['import numpy as np\n\nclass SieveOfEratosthenes:\n def __init__(self, V):\n self.is_prime = np.ones(V + 1, dtype=bool)\n self.is_prime[4::2] = False\n self.is_prime[9::3] = False\n self.is_prime[25::5] = False\n self.primes = [2, 3, 5]\n for i in range(7, V + 1, 2):\n if self.is_prime[i]:\n self.primes.append(i)\n if i * i < V + 1:\n self.is_prime[i * i::i] = False\n \n def factorize(self, x):\n assert x >= 1\n if x == 1:\n return [(1, 1)]\n result = []\n for p in self.primes:\n exp = 0\n while x % p == 0:\n exp += 1\n x = x // p\n if exp > 0:\n result.append((p, exp))\n if p * p > x:\n break\n if x > 1:\n result.append((x, 1))\n return result\n\n\nN = int(input())\nM = 10**9 + 7\nA = list(map(int, input().split()))\n\nsieve = SieveOfEratosthenes(10**3)\nF = [dict(sieve.factorize(a)) for a in A]\n\nlcm = F[0]\nfor i in range(1, len(F)):\n for p, e in F[i].items():\n if p in lcm:\n lcm[p] = max(lcm[p], e)\n else:\n lcm[p] = e\n\nval = 1\nfor p, e in lcm.items():\n val = val * pow(p, e, M) % M\nprint(val)\n\nB = [val * pow(a, M - 2, M) % M for a in A]\nprint(sum(B) % M)\n ', 'import numpy as np\n\nclass SieveOfEratosthenes:\n def __init__(self, V):\n self.is_prime = np.ones(V + 1, dtype=bool)\n self.is_prime[4::2] = False\n self.is_prime[9::3] = False\n self.is_prime[25::5] = False\n self.primes = [2, 3, 5]\n for i in range(7, V + 1, 2):\n if self.is_prime[i]:\n self.primes.append(i)\n self.is_prime[i * i::i] = False\n \n def factorize(self, x):\n assert x >= 1\n if x == 1:\n return [(1, 1)]\n result = []\n for p in self.primes:\n exp = 0\n while x % p == 0:\n exp += 1\n x = x // p\n if exp > 0:\n result.append((p, exp))\n if p * p > x:\n break\n if x > 1:\n result.append((x, 1))\n return result\n\n\nN = int(input())\nM = 10**9 + 7\nA = list(map(int, input().split()))\n\nsieve = SieveOfEratosthenes(10**3)\nF = [dict(sieve.factorize(a)) for a in A]\n\nlcm = F[0]\nfor i in range(1, len(F)):\n for p, e in F[i].items():\n if p in lcm:\n lcm[p] = max(lcm[p], e)\n else:\n lcm[p] = e\n\nval = 1\nfor p, e in lcm.items():\n val = val * pow(p, e, M) % M\n# print(val)\n\nB = [val * pow(a, M - 2, M) % M for a in A]\nprint(sum(B) % M)\n ']
['Wrong Answer', 'Accepted']
['s941373860', 's668465070']
[30796.0, 30536.0]
[321.0, 316.0]
[1355, 1319]
p02793
u020390084
2,000
1,048,576
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).
['#!/usr/bin/env python3\nimport sys\nimport fractions\nfrom functools import reduce\n\nMOD = 1000000007 # type: int\n\ndef lcm(x, y):\n return (x * y) // fractions.gcd(x, y)\n\ndef solve(N: int, A: "List[int]"):\n LCM = reduce(lcm,A)\n answer = 0\n for i in range(N):\n answer += LCM//A[i]\n answer %= MOD\n print(answer)\n return\n\n\ndef main():\n def iterate_tokens():\n for line in sys.stdin:\n for word in line.split():\n yield word\n tokens = iterate_tokens()\n N = int(next(tokens)) # type: int\n A = [int(next(tokens)) for _ in range(N)] # type: "List[int]"\n solve(N, A)\n\nif __name__ == \'__main__\':\n main()\n', '#!/usr/bin/env python3\nimport sys\nfrom collections import Counter\n\nMOD = 1000000007 # type: int\n\ndef sieve(n):\n is_prime = [True for _ in range(n+1)]\n is_prime[0] = False\n\n for i in range(2, n+1):\n if is_prime[i-1]:\n j = 2 * i\n while j <= n:\n is_prime[j-1] = False\n j += i\n table = {i:0 for i in range(1, n+1) if is_prime[i-1]}\n # return is_prime, table\n return table\n\ndef prime_decomposition(n):\n i = 2\n table = []\n while i * i <= n:\n while n % i == 0:\n n //= i\n table.append(i)\n i += 1\n if n > 1:\n table.append(n)\n return table\n\ndef solve(N: int, A: "List[int]"):\n table = dict()\n\n for i in range(N):\n decom = Counter(prime_decomposition(A[i]))\n\n for d,number in decom.items():\n if table.get(d) == None:\n table[d] = number\n continue\n\n if table[d] < number:\n table[d] = number\n LCM = 1\n for key,value in table.items():\n LCM *= pow(key,value,MOD)\n\n print(sum([LCM*pow(a,MOD-2,MOD) for a in A])%MOD)\n\n return\n\n\ndef main():\n def iterate_tokens():\n for line in sys.stdin:\n for word in line.split():\n yield word\n tokens = iterate_tokens()\n N = int(next(tokens)) # type: int\n A = [int(next(tokens)) for _ in range(N)] # type: "List[int]"\n solve(N, A)\n\nif __name__ == \'__main__\':\n main()\n']
['Time Limit Exceeded', 'Accepted']
['s901819137', 's923637291']
[6228.0, 263704.0]
[2104.0, 1986.0]
[673, 1477]
p02793
u029021990
2,000
1,048,576
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).
['# -*- coding: utf-8 -*-\n\npn_list = {2:0,3:0}\n\ndef next_pn():\n npn = list(pn_list.keys())[-1] + 2\n pn_flg = 0\n while pn_flg == 0:\n for i in pn_list.keys():\n if npn % i > 0:\n pn_flg += 1\n if pn_flg == len(pn_list.keys()):\n break \n else:\n npn += 2\n pn_flg = 0\n pn_list[npn] = 0\n return npn\n\ndef check_a(n,a):\n res = "ok"\n for i in range(n):\n if a[i] > 1:\n res = "notyet"\n return res\n\n\n#n = int(input())\n#s = input()\nn = 3\ns ="1000000 999999 999998"\na = [int(x) for x in s.split()]\naa = [int(x) for x in s.split()]\n\n\nsqr_max_a = int((1.0 * 10**6) ** 0.5) + 1\npn = 0\nwhile pn < sqr_max_a:\n pn = next_pn()\n\n\nfor i in pn_list.keys():\n wareta = 1\n while wareta == 1:\n wareta = 0\n for j in range(len(a)):\n if a[j] % i == 0:\n a[j] = a[j] / i\n wareta = 1\n if wareta == 1:\n pn_list[i] += 1\n if check_a(n,a) == "ok":\n break\n\nlcm = 1.0\nfor i in pn_list.keys():\n lcm = lcm * (i ** pn_list[i])\n\nmin_bsum = 0.0\nfor i in aa:\n min_bsum += lcm / i\n\nprint(int(min_bsum % (10**9+7)))', '# -*- coding: utf-8 -*-\n\npn_list = [2,3]\n\ndef next_pn(pn):\n npn = pn + 2\n pn_flg = 0\n while pn_flg == 0:\n for i in pn_list:\n if npn % i == 0:\n break\n if (i ** 2) > npn:\n pn_flg = 1\n break\n if pn_flg == 1:\n break \n else:\n npn += 2\n pn_list.append(npn)\n return npn\n\n\nn = int(input())\ns = input()\na = [int(x) for x in s.split()]\naa = [int(x) for x in s.split()]\n\n\nsqr_max_a = int((1.0 * 10**6) ** 0.5) + 1\n#sqr_max_a = int(1.0 * 10**6)\npn = 3\nwhile pn < sqr_max_a:\n pn = next_pn(pn)\n\n\nlcm = int(1)\nfor i in pn_list:\n wareta = 1\n while wareta == 1:\n wareta = 0\n for j in range(n):\n if a[j] % i == 0:\n a[j] = a[j] // i\n wareta = 1\n if wareta == 1:\n lcm = lcm * i\npn_lcm = []\nfor i in a:\n if i > 1:\n if i not in pn_lcm:\n pn_lcm.append(i)\n lcm = lcm * i\n\nmin_bsum = int(0)\nfor i in aa:\n min_bsum = min_bsum + lcm // i\n\nprint(min_bsum % (10**9+7))\n']
['Wrong Answer', 'Accepted']
['s865988568', 's919901326']
[3064.0, 4596.0]
[189.0, 1908.0]
[1295, 1196]
p02793
u046826851
2,000
1,048,576
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).
['import math\nn = int(input())\nA = list(map(int, input().split( )))\nmod = 10**9 + 7\n\n\n\n\na = A[0]\ns = 1\nfor i in range(1, n):\n g = math.gcd(a,A[i])\n d, e = a//g, A[i]//g\n s = (s*e + d)%mod\n print(g,d,e,s)\n a = a*A[i]//g\nprint(s)', 'n = int(input())\nA = list(map(int, input().split( )))\nmod = 10**9 + 7\n\n\ndef lcm(X,Y):\n x=X\n y=Y\n if y>x:\n x,y=y,x\n while x%y!=0:\n x,y=y,x%y\n return X*Y//y\n\n\na = 1\nc = 0\ns = 0\nfor i in range(n):\n q = lcm(a,A[i])\n s*=q//a\n a = q\n s+=q//A[i]\nprint(s%mod)\n\n']
['Wrong Answer', 'Accepted']
['s768067813', 's330758490']
[26608.0, 10000.0]
[2229.0, 1771.0]
[418, 474]
p02793
u047398677
2,000
1,048,576
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).
['def gcd(a, b):\n while(b > 0):\n a %= b\n swap(a, b)\n return a\ndef lcm(a, b):\n return a * b // gcd(a,b)\nn = int(input())\nmd = int(1e9 + 7)\na = [int(e) for e in input().split()]\nx = 1\nfor j in range(n):\n x = lcm(x, a[j])\nans = 0\nfor i in range(n):\n ans += lcm // a[i]\nans %= md\nprint(ans)', 'def gcd(a, b):\n while(b > 0):\n a %= b\n a, b = b, a\n return a\ndef lcm(a, b):\n return a * b // gcd(a,b)\nn = int(input())\nmd = int(1e9 + 7)\na = [int(e) for e in input().split()]\nx = 1\nfor j in range(n):\n x = lcm(x, a[j])\nans = 0\nfor i in range(n):\n ans += x // a[i]\nans %= md\nprint(ans)\n']
['Runtime Error', 'Accepted']
['s983799131', 's281999364']
[4084.0, 4084.0]
[21.0, 1882.0]
[295, 295]
p02793
u055548671
2,000
1,048,576
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).
['def gcd(a,b):\n if(b == 0):\n return a\n else:\n return gcd(b,a%b)\n\ndef lcm(a,b):\n return (a*b)//gcd(a,b)\nn = int(input())\nmod = 1e9 + 7\na = [int(i) for i in input().split()]\nans = 1 \nfor i in a:\n ans = lcm(ans,i)\n\nprint(sum(ans//i for i in a)%mod)\n', 'def gcd(a,b):\n if(b == 0):\n return a\n else:\n return gcd(b,a%b)\n\ndef lcm(a,b):\n return (a*b)//gcd(a,b)\nn = int(input())\nmod = int(1e9 + 7)\na = [int(i) for i in input().split()]\nans = int(1)\nfor i in a:\n ans = lcm(ans,i)\n\nprint(sum(ans//i for i in a)%mod)\n']
['Runtime Error', 'Accepted']
['s367735172', 's601447523']
[4084.0, 4084.0]
[1888.0, 1893.0]
[274, 280]
p02793
u066029197
2,000
1,048,576
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).
['import fractions\nn=int(input())\nmod=1000000007\nsum=0\ns=[int(n) for n in input().split()]\nans=1\nfor i in s:\n ans*=i//fractions.gcd(ans,i)\nfor i in s:\n sum=(sum+ans//i)%mod\nprint(sum)\n', 'def gcd(a,b):\n if b==0:\n return a\n else:\n return gcd(b,a%b)\nn=int(input())\nmod=1000000007\ns=[int(i) for i in input().split()]\nans=1\nfor i in s:\n ans*=i//gcd(ans,i)\nprint(sum(ans//i for i in s)%mod)\n']
['Time Limit Exceeded', 'Accepted']
['s101606440', 's683538370']
[6200.0, 4084.0]
[2104.0, 1505.0]
[188, 221]
p02793
u067983636
2,000
1,048,576
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).
['def read_values():\n return map(int, input().split())\n\n\ndef read_list():\n return list(read_values())\n\n\ndef lm(a, b):\n if a > b:\n a, b = b, a\n while b % a:\n a, b = b % a, a\n return a\n\n\ndef gm(a, b):\n return a * b // lm(a, b)\n\n\ndef Prim(N):\n P = []\n M = int(N ** 0.5) + 1\n F = [False, False] + [True] * M\n for n in range(2, M):\n if not F[n]:\n continue\n P.append(n)\n for i in range(n, len(F), n):\n F[i] = False\n \n return P\n \n\ndef ps(a, P):\n d = {}\n for p in P:\n while a % p == 0:\n d[p] = d.setdefault(p, 0) + 1\n a //= p\n \n if a == 1:\n break\n return d\n\n\ndef main():\n mod = 10 ** 9 + 7\n N = int(input())\n A = read_list()\n P = Prim(max(A))\n DA = [ps(a, P) for a in A]\n \n D = {}\n for d in DA:\n for i, v in d.items():\n D[i] = max(D.setdefault(i, 0), v)\n\n res = 0\n for d in DA:\n b = 1\n for i, v in D.items():\n b = b * (i ** max(0, v - d.setdefault(i, 0))) % mod\n\n res = (res + b) % mod\n\n print(res)\n\n\nif __name__ == "__main__":\n main()\n\n', 'def read_values():\n return map(int, input().split())\n\n\ndef read_list():\n return list(read_values())\n\n\ndef g(a, b):\n if a > b:\n a, b = b, a\n while b % a:\n a, b = b % a, a\n return a\n\n\ndef main():\n mod = 10 ** 9 + 7\n N = int(input())\n A = read_list()\n\n B = 1\n for a in A:\n B *= a // g(B, a)\n \n print(sum(B // a for a in A) % mod)\n\n\nif __name__ == "__main__":\n main()\n\n']
['Wrong Answer', 'Accepted']
['s278518961', 's902136118']
[64628.0, 4084.0]
[1323.0, 1948.0]
[1169, 425]
p02793
u075595666
2,000
1,048,576
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).
['import sys\ninput = sys.stdin.readline\nn = int(input())\nnum = list(map(int, input().split()))\nmod = 10**9+7\n\nimport fractions\nlc = num[0]\nfor i in range(1, n):\n lc = lc * num[i] // fractions.gcd(lc, num[i])\n lc %= mod\n \ndef modinv(a, mod=10**9+7):\n return pow(a, mod-2, mod)\n\nans =0\nfor i in range(n):\n ans += lc*modinv(num[i],mod)\n ans %= mod\nprint(ans)', 'import sys\ninput = sys.stdin.readline\nn = int(input())\nnum = list(map(int, input().split()))\nmod = 10**9+7\n\nimport fractions\nlc = num[0]\nl = lc%mod\nfor i in range(1, n):\n lc = l * num[i] // fractions.gcd(lc, num[i])\n l = lc%mod\nlc %= mod \ndef modinv(a, mod=10**9+7):\n return pow(a, mod-2, mod)\n\nans =0\nfor i in range(n):\n ans += lc*modinv(num[i],mod)\n ans %= mod\nprint(ans)', 'import sys\ninput = sys.stdin.readline\nn = int(input())\nnum = list(map(int, input().split()))\nmod = 10**9+7\n\nimport fractions\nlc = num[0]\nl = lc%mod\nfor i in range(1, n):\n lc = l * num[i] // fractions.gcd(lc, num[i])\n l = lc%mod\n \ndef modinv(a, mod=10**9+7):\n return pow(a, mod-2, mod)\n\nans =0\nfor i in range(n):\n ans += lc*modinv(num[i],mod)\n ans %= mod\nprint(ans)', 'import sys\ninput = sys.stdin.readline\nn = int(input())\nnum = list(map(int, input().split()))\nmod = 10**9+7\n\n\ndef factorization(n):\n arr = []\n temp = n\n for i in range(2, int(-(-n**0.5//1))+1):\n if temp%i==0:\n cnt=0\n while temp%i==0:\n cnt+=1\n temp //= i\n arr.append([i, cnt])\n if temp!=1:\n arr.append([temp, 1])\n if arr==[]:\n arr.append([n, 1])\n return arr\n\nlcd = dict()\nfor i in num:\n j = dict(factorization(i))\n for x,y in j.items():\n if not x in lcd.keys():\n lcd[x] = y\n else:\n lcd[x] = max(lcd[x],y)\n\nlc = 1\nfor i,j in lcd.items():\n lc *= pow(i,j,mod)\n \ndef modinv(a, mod=10**9+7):\n return pow(a, mod-2, mod)\n\nans =0\nfor i in range(n):\n ans += lc*modinv(num[i],mod)\n ans %= mod\nprint(ans)']
['Wrong Answer', 'Wrong Answer', 'Wrong Answer', 'Accepted']
['s010860845', 's024504669', 's250147745', 's280186413']
[5488.0, 5496.0, 5496.0, 4596.0]
[92.0, 91.0, 91.0, 1987.0]
[367, 387, 378, 847]
p02793
u083190434
2,000
1,048,576
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).
['\nMOD = 1000000007\n\ndef gcd(a, b):\n if b == 0:\n return a\n else:\n return gcd(b, a%b)\n\ndef lcm(a, b):\n return a//gcd(a,b)*a\n\nn = int(input())\na = list(map(int,input().split()))\nall_lcm = 1\nfor i in range(n):\n all_lcm = lcm(all_lcm, a[i])\nans = 0\nfor i in range(n):\n ans += all_lcm//a[i]\nprint(ans%MOD)', '\nMOD = 1000000007\n\ndef gcd(a, b):\n if b == 0:\n return a\n else:\n return gcd(b, a%b)\n\ndef lcm(a, b):\n return a//gcd(a,b)*b\n\nn = int(input())\na = list(map(int,input().split()))\nall_lcm = 1\nfor i in range(n):\n all_lcm = lcm(all_lcm, a[i])\nans = 0\nfor i in range(n):\n ans += all_lcm//a[i]\nprint(ans%MOD)']
['Wrong Answer', 'Accepted']
['s039736381', 's366115707']
[4084.0, 4084.0]
[27.0, 1889.0]
[327, 327]
p02793
u115110170
2,000
1,048,576
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).
["\n\ndef gcd(a, b):\n while b:\n a, b = b, a % b\n return a\n \ndef main():\n mod = 10**9 +7\n n = int(input())\n ls = list(map(int,input().split()))\n \n t = 1\n for a in ls:\n t = gcd(t,a)\n \n ans = 0\n for a in ls:\n ans = (ans + t//a) % mod \n print(ans)\n \nif __name__ == '__main__':\n main()", "import math\nimport fractions\ndef lcm(x, y):\n return (x * y) // fractions.gcd(x, y)\n \ndef main():\n mod = 10**9 +7\n n = int(input())\n ls = list(map(int,input().split()))\n \n t = ls[0]\n for a in ls:\n t = lcm(t,a)\n \n ans = 0\n for a in ls:\n ans = (ans + t//a) % mod \n print(ans)\n \nif __name__ == '__main__':\n main()", 'class PrimeOptimizer:\n def __init__(self, MAX_NUM=10**3):\n is_prime = [True] * MAX_NUM\n is_prime[0] = False\n is_prime[1] = False\n primes = []\n for i in range(MAX_NUM):\n if is_prime[i]:\n primes.append(i)\n for j in range(2*i, MAX_NUM, i):\n is_prime[j] = False\n self.primes = primes\n\n def prime_factorization(self, x):\n res = {}\n for prime in self.primes:\n while x % prime == 0:\n if not prime in res:\n res[prime] = 0\n res[prime] += 1\n x //= prime\n if x > 1:\n res[x] = 1\n return res\n\nMOD = 10**9+7\n\ndef mod_pow(p, q):\n res = 1\n while q:\n if q & 1:\n res = (res * p) % MOD\n p = (p * p) % MOD\n q //= 2\n return res\n\ndef mod_inv(p):\n return mod_pow(p, MOD - 2)\n\ndef solve(n, a):\n primeOpt = PrimeOptimizer()\n D = {}\n for i in range(n):\n prime_num_mapping = primeOpt.prime_factorization(a[i])\n for prime, num in prime_num_mapping.items():\n if not prime in D:\n D[prime] = 0\n D[prime] = max(D[prime], num)\n L = 1\n for prime, num in D.items():\n L = (L * mod_pow(prime, num)) % MOD\n res = sum([L * mod_inv(x) % MOD for x in a])\n return res % MOD\n\nN = int(input())\nA = list(map(int, input().split()))\nprint(solve(N, A))\n']
['Wrong Answer', 'Time Limit Exceeded', 'Accepted']
['s691875059', 's918006507', 's848097367']
[4084.0, 6116.0, 4596.0]
[22.0, 2104.0, 274.0]
[308, 329, 1450]
p02793
u116763463
2,000
1,048,576
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).
['# from math import gcd\nmod = 10**9 + 7\n\nn = int(input())\narr = [int(j) for j in input().split()]\n\n# prod = 1\n# l = 1\n# for x in arr:\n# \tg = gcd(l, x)\n# \tprod = l*x\n# \tl = prod//g\n\n\n# for x in arr:\n\n# print(su%mod)\n', 'from math import gcd\nmod = 10**9 + 7\n\nn = int(input())\narr = [int(j) for j in input().split()]\n\n# prod = 1\n# l = 1\n# for x in arr:\n# \tg = gcd(l, x)\n# \tprod = l*x\n# \tl = prod//g\n\n\n# for x in arr:\n\n# print(su%mod)\n', 'import sys\nsys.setrecursionlimit(100000000)\ndef gcd(a,b): \n if (b == 0): \n return a \n return gcd(b, a%b) \n\n\nmod = 10**9 + 7\n\nn = int(input())\narr = [int(j) for j in input().split()]\n\nprod = 1\nl = 1\nfor x in arr:\n\tg = gcd(l, x)\n\tprod = l*x\n\tl = prod//g\n\nsu = 0\nfor x in arr:\n\tsu += (l//x)\nprint(su%mod)\n']
['Wrong Answer', 'Runtime Error', 'Accepted']
['s331328345', 's532610758', 's607672396']
[4084.0, 2940.0, 4084.0]
[20.0, 18.0, 1891.0]
[237, 235, 316]
p02793
u130860911
2,000
1,048,576
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).
['from fractions import gcd\n\nMod = 10**9+7\nN = int(input())\nA = list(map(int,input().split()))\n\nlm = A[0]\nfor a in A[1:]:\n lm = lm*a // gcd(lm,a)\n\nans = 0\nfor i in range(N):\n ans += ( lm//A[i] )\n ans %= Mod\n\nprint(ans)', 'import fractions\n\nMod = 10**9+7\nN = int(input())\nA = list(map(int,input().split()))\n\nlm = A[0]\nfor a in A[1:]:\n lm = lm*a // fractions.gcd(lm,a)\n\nans = 0\n\nfor a in A:\n ans += ( lm//a )% Mod\n\nprint(ans)', 'from fractions import gcd\n\nMod = 10**9+7\nN = int(input())\nA = list(map(int,input().split()))\n\nlm = A[0]\nfor a in A[1:]:\n lm = lm*a // gcd(lm,a)\n\nans = 0\n\nfor a in A:\n ans += ( lm//a )\n ans %= Mod\n\nprint(ans)', 'import fractions\n\nMod = 10**9+7\nN = int(input())\nA = list(map(int,input().split()))\n\nlm = A[0]\nfor a in A[1:]:\n lm = lm*a // fractions.gcd(lm,a)\n\nans = 0\n\nfor a in A:\n ans += ( lm//a )\n ans %= Mod\n\nprint(ans)', 'from fractions import gcd\n\nMod = 10**9+7\nN = int(input())\nA = list(map(int,input().split()))\n\nlm = A[0]\nfor i in range(1,N):\n lm = lm*A[i] // gcd(lm,A[i])\n\nans = 0\nfor i in range(N):\n ans += ( lm//A[i] )\n ans %= Mod\n\nprint(ans)', 'from fractions import gcd\n\nMod = 10**9+7\nN = int(input())\nA = list(map(int,input().split()))\n\nm = A[0]\nfor i in range(1,N):\n lm = lm*A[i] // gcd(lm,A[i])\n\nans = 0\n\nfor i in range(N):\n ans += ( lm//A[i] )\n ans %= Mod\n\nprint(ans)', 'import fractions\n\nMod = 10**9+7\nN = int(input())\nA = list(map(int,input().split()))\n\ndef lcm(L):\n r = 1\n for l in L:\n r = r*l // fractions.gcd(r,l)\n return r\n\nans = 0\nlm = lcm(A)\nfor a in A:\n ans += ( lm//a )% Mod\n\nprint(ans)', 'from fractions import gcd\n\nMod = 10**9+7\nN = int(input())\nA = list(map(int,input().split()))\n\ndef lcm(x,y):\n return x*y//gcd(x,y)\n\nlm = A[0]\nfor a in A[1:]:\n lm = lcm(lm, a)\n\nans = 0\nfor i in range(N):\n ans += ( lm//A[i] )\n ans %= Mod\n\nprint(ans)', 'import math\n\nMod = 10**9+7\nN = int(input())\nA = list(map(int,input().split()))\nLd = dict()\n\nfor a in A:\n \n D = dict()\n ra = math.floor(math.sqrt(a))\n if ra>1:\n for i in range(2,ra+1):\n while a%i == 0:\n D[i] = D.get(i,0) + 1\n a //= i\n if a == 1:\n break\n \n if a > 1:\n D[a] = D.get(a,0) + 1\n\n for d in D:\n Ld[d] = max(Ld.get(d,0), D[d])\n\nlcm = 1\nfor l in Ld:\n lcm *= pow(l,Ld[l],Mod)\n lcm %= Mod\n\nans = 0\nfor a in A:\n ans += ( lcm*pow(a,Mod-2,Mod)) %Mod\n ans %= Mod\n\nprint(ans)']
['Time Limit Exceeded', 'Wrong Answer', 'Time Limit Exceeded', 'Time Limit Exceeded', 'Time Limit Exceeded', 'Runtime Error', 'Wrong Answer', 'Time Limit Exceeded', 'Accepted']
['s034337311', 's147283904', 's194269278', 's198375735', 's284171750', 's631111568', 's743485229', 's910552859', 's313756019']
[6112.0, 6112.0, 6112.0, 6112.0, 6112.0, 6112.0, 6112.0, 6200.0, 4596.0]
[2104.0, 2104.0, 2104.0, 2104.0, 2104.0, 45.0, 2104.0, 2104.0, 1770.0]
[225, 207, 216, 217, 236, 236, 244, 258, 612]