A - 3.14

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 100 点

問題文

円周率の小数第 100 位までの値は

3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679

です。

1 以上 100 以下の整数 N が与えられます。

円周率を小数第 N 位まで出力してください。

より厳密には、円周率を小数第 N+1 位で切り捨て、末尾の 0 を取り除かずに出力してください。

制約

  • 1\leq N\leq 100
  • N は整数

入力

入力は以下の形式で標準入力から与えられる。

N

出力

円周率を小数第 N 位まで 1 行で出力せよ。


入力例 1

2

出力例 1

3.14

円周率を小数第 2+1 位で切り捨てると値は 3.14 になります。 よって、3.14 を出力してください。


入力例 2

32

出力例 2

3.14159265358979323846264338327950

末尾の 0 は取り除かずに出力してください。


入力例 3

100

出力例 3

3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679

Score : 100 points

Problem Statement

The number pi to the 100-th decimal place is

3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679.

You are given an integer N between 1 and 100, inclusive.

Print the value of pi to the N-th decimal place.

More precisely, truncate the value of pi to N decimal places and print the result without removing the trailing 0s.

Constraints

  • 1\leq N\leq 100
  • N is an integer.

Input

The input is given from Standard Input in the following format:

N

Output

Print the value of pi to the N-th decimal place in a single line.


Sample Input 1

2

Sample Output 1

3.14

Truncating the value of pi to 2 decimal places results in 3.14. Thus, you should print 3.14.


Sample Input 2

32

Sample Output 2

3.14159265358979323846264338327950

Do not remove the trailing 0s.


Sample Input 3

100

Sample Output 3

3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679
B - Exponential or Quadratic

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 100 点

問題文

2^n \gt n^2 ですか?

制約

  • n は 1 以上 10^9 以下の整数

入力

入力は以下の形式で標準入力から与えられる。

n

出力

2^n \gt n^2 なら Yes を、そうでないなら No を出力せよ。


入力例 1

5

出力例 1

Yes

2^5=32,\ 5^2=25 より 2^n \gt n^2 であるため、Yes を出力します。


入力例 2

2

出力例 2

No

n=2 の場合 2^n=n^2=2^2 となり、故に 2^n \gt n^2 ではありません。よって No を出力します。


入力例 3

623947744

出力例 3

Yes

Score : 100 points

Problem Statement

Does 2^n \gt n^2 hold?

Constraints

  • n is an integer between 1 and 10^9 (inclusive).

Input

Input is given from Standard Input in the following format:

n

Output

If 2^n \gt n^2, print Yes; otherwise, print No.


Sample Input 1

5

Sample Output 1

Yes

Since 2^5=32,\ 5^2=25, we have 2^n \gt n^2, so Yes should be printed.


Sample Input 2

2

Sample Output 2

No

For n=2, we have 2^n=n^2=2^2, so 2^n \gt n^2 does not hold. Thus, No should be printed.


Sample Input 3

623947744

Sample Output 3

Yes
C - Light It Up

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 200 点

問題文

xy 平面上に N 人の人 1,2,\dots,N がおり、人 i は座標 (X_i,Y_i) にいます。
このうち、 K 人の人 A_1,A_2,\dots,A_K に同じ強さの明かりを持たせます。
座標 (x,y) にいる人が強さ R の明かりを持っている時、その明かりによって中心 (x,y) 、半径 R の円の内部全体(境界を含む)が照らされます。
すべての人が少なくとも 1 つの明かりによって照らされるために必要な明かりの強さの最小値を求めてください。

制約

  • 入力は全て整数
  • 1 \le K < N \le 1000
  • 1 \le A_1 < A_2 < \dots < A_K \le N
  • |X_i|,|Y_i| \le 10^5
  • i \neq j ならば (X_i,Y_i) \neq (X_j,Y_j)

入力

入力は以下の形式で標準入力から与えられる。

N K
A_1 A_2 \dots A_K
X_1 Y_1
X_2 Y_2
\vdots
X_N Y_N

出力

答えを実数として出力せよ。
出力された解と想定解との絶対誤差または相対誤差が 10^{-5} 以下であるならば、出力は正しいと見なされる。


入力例 1

4 2
2 3
0 0
0 1
1 2
2 0

出力例 1

2.23606797749978969

この入力では人が 4 人おり、そのうち人 2,3 が明かりを持ちます。
R \ge \sqrt{5} \approx 2.236068 である時、すべての人が少なくとも 1 つの明かりによって照らされます。


入力例 2

2 1
2
-100000 -100000
100000 100000

出力例 2

282842.712474619009

入力例 3

8 3
2 6 8
-17683 17993
93038 47074
58079 -57520
-41515 -89802
-72739 68805
24324 -73073
71049 72103
47863 19268

出力例 3

130379.280458974768

Score : 200 points

Problem Statement

There are N people numbered 1, 2, \dots, N in the xy-plane. Person i is at the coordinates (X_i, Y_i).
K of these people, Persons A_1, A_2, \dots, A_K, will receive lights of the same strength.
When a person at coordinates (x, y) has a light of strength R, it lights up the interior of a circle of radius R centered at (x, y) (including the boundary).
Find the minimum strength of the lights needed for every person to be lit by at least one light.

Constraints

  • All values in input are integers.
  • 1 \le K < N \le 1000
  • 1 \le A_1 < A_2 < \dots < A_K \le N
  • |X_i|,|Y_i| \le 10^5
  • (X_i,Y_i) \neq (X_j,Y_j), if i \neq j.

Input

Input is given from Standard Input in the following format:

N K
A_1 A_2 \dots A_K
X_1 Y_1
X_2 Y_2
\vdots
X_N Y_N

Output

Print the answer as a real number.
Your output will be considered correct if its absolute or relative error from the judge's output is at most 10^{-5}.


Sample Input 1

4 2
2 3
0 0
0 1
1 2
2 0

Sample Output 1

2.23606797749978969

This input contains four people. Among them, Persons 2 and 3 will have lights.
Every person will be lit by at least one light if R \ge \sqrt{5} \approx 2.236068.


Sample Input 2

2 1
2
-100000 -100000
100000 100000

Sample Output 2

282842.712474619009

Sample Input 3

8 3
2 6 8
-17683 17993
93038 47074
58079 -57520
-41515 -89802
-72739 68805
24324 -73073
71049 72103
47863 19268

Sample Output 3

130379.280458974768
D - Maritozzo

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 200 点

問題文

英小文字からなる 3 つの文字列 S_1, S_2, S_3 と、1、2、3 のみからなる文字列 T が与えられます。

T の各文字に対応する文字列を連結してできる文字列を出力してください。より厳密には、以下の指示にしたがって文字列を出力してください。

  • 1 \leq i \leq |T| を満たす整数 i に対し、文字列 s_i を次のように定める。
    • T の i 文字目が 1 のとき、S_1
    • T の i 文字目が 2 のとき、S_2
    • T の i 文字目が 3 のとき、S_3
  • s_1, s_2, \dots, s_{|T|} をこの順に連結してできる文字列を出力する。

制約

  • 1 \leq |S_1|, |S_2|, |S_3| \leq 10
  • 1 \leq |T| \leq 1000
  • S_1, S_2, S_3 は英小文字からなる。
  • T は 1、2、3 のみからなる。

入力

入力は以下の形式で標準入力から与えられる。

S_1
S_2
S_3
T

出力

答えを出力せよ。


入力例 1

mari
to
zzo
1321

出力例 1

marizzotomari

s_1 = mari, s_2 = zzo, s_3 = to, s_4 = mari であるので、これらを連結してできる文字列である marizzotomari を出力します。


入力例 2

abra
cad
abra
123

出力例 2

abracadabra

入力例 3

a
b
c
1

出力例 3

a

Score : 200 points

Problem Statement

You are given three strings S_1, S_2, S_3 consisting of lowercase English letters, and a string T consisting of 1, 2, 3.

Concatenate the three strings according to the characters in T and print the resulting string. Formally, conform to the following instructions.

  • For each integer i such that 1 \leq i \leq |T|, let the string s_i be defined as follows:
    • S_1, if the i-th character of T is 1;
    • S_2, if the i-th character of T is 2;
    • S_3, if the i-th character of T is 3.
  • Concatenate the strings s_1, s_2, \dots, s_{|T|} in this order and print the resulting string.

Constraints

  • 1 \leq |S_1|, |S_2|, |S_3| \leq 10
  • 1 \leq |T| \leq 1000
  • S_1, S_2, and S_3 consist of lowercase English letters.
  • T consists of 1, 2, and 3.

Input

Input is given from Standard Input in the following format:

S_1
S_2
S_3
T

Output

Print the answer.


Sample Input 1

mari
to
zzo
1321

Sample Output 1

marizzotomari

We have s_1 = mari, s_2 = zzo, s_3 = to, s_4 = mari. Concatenate these and print the resulting string: marizzotomari.


Sample Input 2

abra
cad
abra
123

Sample Output 2

abracadabra

Sample Input 3

a
b
c
1

Sample Output 3

a
E - Loong Tracking

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 300 点

問題文

高橋君は座標平面上で龍を操作するゲームを作成しました。

龍は 1 から N までの番号がついた N 個のパーツからなり、パーツ 1 を頭 と呼びます。

最初パーツ i は座標 (i,0) にあります。以下のクエリを Q 個処理してください。

  • 1 C: 頭を方向 C に 1 移動させる。ここで、C は R, L, U, D のいずれかであり、それぞれ x 軸正方向、x 軸負方向、y 軸正方向、y 軸負方向を意味する。頭以外の全てのパーツは前のパーツに追従するように動く。すなわち、パーツ i\ \ (2\leq i \leq N) は移動前にパーツ i-1 があった座標に移動する。
  • 2 p: パーツ p のある座標を求める。

制約

  • 2 \leq N \leq 10^6
  • 1 \leq Q \leq 2\times 10^5
  • 1 種類目のクエリにおいて、C は R, L, U, D のいずれか
  • 2 種類目のクエリにおいて、1\leq p \leq N
  • 入力に含まれる数値は全て整数

入力

入力は以下の形式で標準入力から与えられる。

N Q
\mathrm{query}_1
\vdots
\mathrm{query}_Q

各クエリは以下の 2 種類のいずれかの形式である。

1 C
2 p

出力

2 種類目のクエリの回数を q として q 行出力せよ。
i 行目には、i 番目のそのようなクエリに対する答えの座標を (x,y) としたとき、x,y を空白区切りで出力せよ。


入力例 1

5 9
2 3
1 U
2 3
1 R
1 D
2 3
1 L
2 1
2 5

出力例 1

3 0
2 0
1 1
1 0
1 0

2 種類目のクエリを処理する各タイミングにおいて、パーツの位置は次のようになっています。

図

複数のパーツが同じ座標に存在しうることに注意してください。

Score : 300 points

Problem Statement

Takahashi has created a game where the player controls a dragon on a coordinate plane.

The dragon consists of N parts numbered 1 to N, with part 1 being called the head.

Initially, part i is located at the coordinates (i,0). Process Q queries as follows.

  • 1 C: Move the head by 1 in direction C. Here, C is one of R, L, U, and D, which represent the positive x-direction, negative x-direction, positive y-direction, and negative y-direction, respectively. Each part other than the head moves to follow the part in front of it. That is, part i (2\leq i \leq N) moves to the coordinates where part i-1 was before the move.
  • 2 p: Find the coordinates of part p.

Constraints

  • 2 \leq N \leq 10^6
  • 1 \leq Q \leq 2\times 10^5
  • For the first type of query, C is one of R, L, U, and D.
  • For the second type of query, 1\leq p \leq N.
  • All numerical input values are integers.

Input

The input is given from Standard Input in the following format:

N Q
\mathrm{query}_1
\vdots
\mathrm{query}_Q

Each query is in one of the following two formats:

1 C
2 p

Output

Print q lines, where q is the number of queries of the second type.
The i-th line should contain x and y separated by a space, where (x,y) are the answer to the i-th such query.


Sample Input 1

5 9
2 3
1 U
2 3
1 R
1 D
2 3
1 L
2 1
2 5

Sample Output 1

3 0
2 0
1 1
1 0
1 0

At each time when processing the second type of query, the parts are at the following positions:

Figure

Note that multiple parts may exist at the same coordinates.

F - 1111gal password

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 300 点

問題文

整数 N が与えられるので、以下の条件を全て満たす整数 X の個数を 998244353 で割った余りを求めてください。

  • N 桁の正整数である。
  • X の各桁を上の位から順に X_1,X_2,\dots,X_N とする。このとき以下の条件を全て満たす。
    • 全ての整数 1 \le i \le N に対して、 1 \le X_i \le 9
    • 全ての整数 1 \le i \le N-1 に対して、 |X_i-X_{i+1}| \le 1

制約

  • N は整数
  • 2 \le N \le 10^6

入力

入力は以下の形式で標準入力から与えられる。

N

出力

答えを整数として出力せよ。


入力例 1

4

出力例 1

203

4 桁の整数として、例えば 1111,1234,7878,6545 が問題文中の条件を満たします。


入力例 2

2

出力例 2

25

入力例 3

1000000

出力例 3

248860093

998244353 で割った余りを求めることに注意してください。

Score : 300 points

Problem Statement

Given an integer N, find the number of integers X that satisfy all of the following conditions, modulo 998244353.

  • X is an N-digit positive integer.
  • Let X_1,X_2,\dots,X_N be the digits of X from top to bottom. They satisfy all of the following:
    • 1 \le X_i \le 9 for all integers 1 \le i \le N;
    • |X_i-X_{i+1}| \le 1 for all integers 1 \le i \le N-1.

Constraints

  • N is an integer.
  • 2 \le N \le 10^6

Input

Input is given from Standard Input in the following format:

N

Output

Print the answer as an integer.


Sample Input 1

4

Sample Output 1

203

Some of the 4-digit integers satisfying the conditions are 1111,1234,7878,6545.


Sample Input 2

2

Sample Output 2

25

Sample Input 3

1000000

Sample Output 3

248860093

Be sure to find the count modulo 998244353.

G - X to Y

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 400 点

問題文

整数 X,Y と 2 以上の整数 K が与えられます。

変数 x があり、はじめ x=X です。あなたは x に対して以下の操作を 0 回以上何回でも行うことができます:

  • \displaystyle \left\lfloor \frac xK \right\rfloor=y または \displaystyle \left\lfloor \frac yK \right\rfloor=x を満たす整数 y を選び、x の値を y に置き換える。

ここで、実数 z に対し \displaystyle \left\lfloor z \right\rfloor は z 以下の最大の整数として定義されます。

x=Y とするために必要な操作回数の最小値を求めてください。ただし、制約下では有限回の操作で x=Y とする方法が必ず存在することが証明できます。

T 個のテストケースが与えられるので、それぞれについて答えを求めてください。

制約

  • 1\le T\le 2\times 10^5
  • 0\le X,Y\le 10^{18}
  • 2\le K\le 10^{18}
  • 入力される値は全て整数

入力

入力は以下の形式で標準入力から与えられる。

T
\text{case}_1
\text{case}_2
\vdots
\text{case}_T

i 番目 (1\le i\le T) のテストケース \text{case}_i は以下の形式で与えられる。

X Y K

出力

各テストケースに対する答えを順に改行区切りで出力せよ。


入力例 1

4
11 9 3
0 0 2
842 180 7
1948706013487601 48019760148910476 89014537

出力例 1

2
0
7
5

1 番目のテストケースについて考えます。

以下のように操作することで 2 回の操作で x=Y とすることができます:

  • y=3 を選ぶ。\displaystyle\left\lfloor\frac{x}K \right\rfloor=\left\lfloor\frac{11}3 \right\rfloor=3 よりこの選択は合法である。そして、x の値を 3 に置き換える。
  • y=9 を選ぶ。\displaystyle\left\lfloor\frac{y}K \right\rfloor=\left\lfloor\frac{9}3 \right\rfloor=3 よりこの選択は合法である。そして、x の値を 9 に置き換える。

2 回未満の操作で x=Y とすることはできないので、1 行目には 2 を出力してください。

Score : 400 points

Problem Statement

You are given integers X,Y, and an integer K that is at least 2.

There is a variable x, which is initially x=X. You can perform the following operation on x zero or more times:

  • Choose an integer y satisfying \displaystyle \left\lfloor \frac xK \right\rfloor=y or \displaystyle \left\lfloor \frac yK \right\rfloor=x, and replace the value of x with y.

Here, \displaystyle \left\lfloor z \right\rfloor is defined as the greatest integer not exceeding z, for a real number z.

Find the minimum number of operations required to make x=Y. Under the given constraints, it can be proved that there always exists a way to make x=Y in a finite number of operations.

You are given T test cases; solve each of them.

Constraints

  • 1\le T\le 2\times 10^5
  • 0\le X,Y\le 10^{18}
  • 2\le K\le 10^{18}
  • All input values are integers.

Input

The input is given from Standard Input in the following format:

T
\text{case}_1
\text{case}_2
\vdots
\text{case}_T

The i-th (1\le i\le T) test case \text{case}_i is given in the following format:

X Y K

Output

Output the answers for the test cases in order, separated by newlines.


Sample Input 1

4
11 9 3
0 0 2
842 180 7
1948706013487601 48019760148910476 89014537

Sample Output 1

2
0
7
5

Consider the first test case.

By performing the following operations, x=Y can be achieved in two operations:

  • Choose y=3. Since \displaystyle\left\lfloor\frac{x}K \right\rfloor=\left\lfloor\frac{11}3 \right\rfloor=3, this choice is valid. Then, replace the value of x with 3.
  • Choose y=9. Since \displaystyle\left\lfloor\frac{y}K \right\rfloor=\left\lfloor\frac{9}3 \right\rfloor=3, this choice is valid. Then, replace the value of x with 9.

x=Y cannot be achieved in fewer than two operations, so output 2 on the first line.

H - Least Elements

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 500 点

問題文

長さ N の整数列 A = (A_1, \dots, A_N) と整数 M, K が与えられます。
i = 1, \dots, N - M + 1 に対して、次の独立な問題を解いてください。

M 個の整数 A_i, A_{i + 1}, \dots, A_{i + M - 1} を昇順に並べ替えたときの先頭 K 個の値の総和を求めよ。

制約

  • 1 \leq K \leq M \leq N \leq 2 \times 10^5
  • 1 \leq A_i \leq 10^9
  • 入力される値は全て整数

入力

入力は以下の形式で標準入力から与えられる。

N M K
A_1 A_2 \ldots A_N

出力

i = k のときの問題の答えを \mathrm{answer}_k として、次の形式で出力せよ。

\mathrm{answer}_1 \mathrm{answer}_2 \ldots \mathrm{answer}_{N-M+1}

入力例 1

6 4 3
3 1 4 1 5 9

出力例 1

5 6 10
  • i = 1 のとき、A_i, A_{i+1}, A_{i+2}, A_{i+3} を小さい順に並べると 1, 1, 3, 4 となり、小さい方から 3 個の値の総和は 5 です。
  • i = 2 のとき、A_i, A_{i+1}, A_{i+2}, A_{i+3} を小さい順に並べると 1, 1, 4, 5 となり、小さい方から 3 個の値の総和は 6 です。
  • i = 3 のとき、A_i, A_{i+1}, A_{i+2}, A_{i+3} を小さい順に並べると 1, 4, 5, 9 となり、小さい方から 3 個の値の総和は 10 です。

入力例 2

10 6 3
12 2 17 11 19 8 4 3 6 20

出力例 2

21 14 15 13 13

Score : 500 points

Problem Statement

You are given an integer sequence A = (A_1, \dots, A_N) of length N, and integers M and K.
For each i = 1, \dots, N - M + 1, solve the following independent problem.

Find the sum of the first K values in the sorted list of the M integers A_i, A_{i + 1}, \dots, A_{i + M - 1} in ascending order.

Constraints

  • 1 \leq K \leq M \leq N \leq 2 \times 10^5
  • 1 \leq A_i \leq 10^9
  • All values in the input are integers.

Input

The input is given from Standard Input in the following format:

N M K
A_1 A_2 \ldots A_N

Output

Let \mathrm{answer}_k be the answer to the problem for i = k, and print them in the following format:

\mathrm{answer}_1 \mathrm{answer}_2 \ldots \mathrm{answer}_{N-M+1}

Sample Input 1

6 4 3
3 1 4 1 5 9

Sample Output 1

5 6 10
  • For i = 1, sorting A_i, A_{i+1}, A_{i+2}, A_{i+3} in ascending order yields 1, 1, 3, 4, where the sum of the first three values is 5.
  • For i = 2, sorting A_i, A_{i+1}, A_{i+2}, A_{i+3} in ascending order yields 1, 1, 4, 5, where the sum of the first three values is 6.
  • For i = 3, sorting A_i, A_{i+1}, A_{i+2}, A_{i+3} in ascending order yields 1, 4, 5, 9, where the sum of the first three values is 10.

Sample Input 2

10 6 3
12 2 17 11 19 8 4 3 6 20

Sample Output 2

21 14 15 13 13
I - 1122 Subsequence 2

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 500 点

問題文

数字からなる文字列 S が与えられます。

以下の条件を全て満たす文字列 T を 1122文字列 と呼びます。(定義は C 問題と同じです。)

  • T は数字からなる空でない文字列
  • |T| は偶数。ここで、 |T| は文字列 T の長さを表す
  • T の 1 文字目から \frac{|T|}2 文字目までは全て同じ数字である
  • T の \frac{|T|}2+1 文字目から |T| 文字目までは全て同じ数字である
  • T の 1 文字目の数字に 1 を足すと |T| 文字目の数字になる

例えば 1122 や 01 、 444555 などは 1122文字列 ですが、 1222 や 90 は 1122文字列 ではありません。

S の (連続でなくても良い)部分列 であって 1122文字列 であるものの個数を 998244353 で割ったあまりを求めてください。

ただし、ある二つの部分列が文字列として同じでも、取り出された位置が異なるならばそれらは別々に数えるものとします。

制約

  • S は長さ 1 以上 10^6 以下の数字からなる文字列

入力

入力は以下の形式で標準入力から与えられる。

S

出力

S の部分列であって 1122文字列 であるものの個数を 998244353 で割ったあまりを出力せよ。


入力例 1

1122

出力例 1

5

以下の 5 つの部分列が条件を満たします。

  • S の 1 文字目と 3 文字目を取り出した 12
  • S の 1 文字目と 4 文字目を取り出した 12
  • S の 2 文字目と 3 文字目を取り出した 12
  • S の 2 文字目と 4 文字目を取り出した 12
  • S の 1 文字目から 4 文字目を取り出した 1122

したがって、 5 を出力してください。

文字列として同じでも、取り出された位置が異なるならばそれらは別々に数えることに注意してください。


入力例 2

2025

出力例 2

0

1122文字列 となる部分列が存在しない場合もあります。


入力例 3

0777468889971

出力例 3

30

Score : 500 points

Problem Statement

You are given a string S consisting of digits.

A string T is called a 1122-string if it satisfies all of the following conditions. (The definition is the same as in Problem C.)

  • T is a non-empty string consisting of digits.
  • |T| is even, where |T| denotes the length of string T.
  • All characters from the 1-st through the \frac{|T|}2-th character of T are the same digit.
  • All characters from the (\frac{|T|}2+1)-th through the |T|-th character of T are the same digit.
  • Adding 1 to the digit of the 1-st character of T gives the digit of the |T|-th character.

For example, 1122, 01, and 444555 are 1122-strings, but 1222 and 90 are not 1122-strings.

Find the number, modulo 998244353, of (not necessarily contiguous) subsequences of S that are 1122-strings.

Two subsequences are counted separately if they are extracted from different positions, even if they are identical as strings.

Constraints

  • S is a string consisting of digits with length between 1 and 10^6, inclusive.

Input

The input is given from Standard Input in the following format:

S

Output

Output the number, modulo 998244353, of subsequences of S that are 1122-strings.


Sample Input 1

1122

Sample Output 1

5

The following five subsequences satisfy the condition.

  • 12 extracted from the 1-st and 3-rd characters of S
  • 12 extracted from the 1-st and 4-th characters of S
  • 12 extracted from the 2-nd and 3-rd characters of S
  • 12 extracted from the 2-nd and 4-th characters of S
  • 1122 extracted from the 1-st through 4-th characters of S

Thus, output 5.

Note that two subsequences are counted separately if they are extracted from different positions, even if they are identical as strings.


Sample Input 2

2025

Sample Output 2

0

There may be no subsequence that is a 1122-string.


Sample Input 3

0777468889971

Sample Output 3

30