Time Limit: 2 sec / Memory Limit: 1024 MB
問題文
10 進法で表記したとき D 桁であるような正整数 N が与えられます。
1\leq k\leq D について、N を 10 進法で表記したときの上から k 桁目を A_k とします。
\displaystyle\sum_{i=1}^{D-1}\sum_{j=i+1}^D \lvert A_i-A_j \rvert の値を求めてください。
制約
- 2 \leq D \leq 2\times 10^5
- D は整数
- N は D 桁の正整数
- N の先頭の桁は 0 でない。
入力
入力は以下の形式で標準入力から与えられる。
D N
出力
答えを出力せよ。
入力例 1
3 287
出力例 1
12
D=3, A_1=2, A_2=8, A_3=7 であるので、 求める値は、\lvert 2-8 \rvert+\lvert 2-7 \rvert+\lvert 8-7 \rvert=12 となります。
入力例 2
2 11
出力例 2
0
入力例 3
20 12345678901234567890
出力例 3
660
Problem Statement
You are given a positive integer N that has D digits when written in base 10.
For 1\leq k\leq D, let A_k be the k-th digit from the top when N is written in base 10.
Find the value \displaystyle\sum_{i=1}^{D-1}\sum_{j=i+1}^D \lvert A_i-A_j \rvert.
Constraints
- 2 \leq D \leq 2\times 10^5
- D is an integer.
- N is a D-digit positive integer.
- The topmost digit of N is not 0.
Input
The input is given from Standard Input in the following format:
D N
Output
Print the answer.
Sample Input 1
3 287
Sample Output 1
12
We have D=3, A_1=2, A_2=8, and A_3=7, so the sought value is \lvert 2-8 \rvert+\lvert 2-7 \rvert+\lvert 8-7 \rvert=12.
Sample Input 2
2 11
Sample Output 2
0
Sample Input 3
20 12345678901234567890
Sample Output 3
660