A - Cut

実行時間制限: 2 sec / メモリ制限: 1024 MiB

配点 : 100

問題文

N 枚からなるカードの山があり、上から i 枚目のカードには整数 A_i が書かれています。

山の下から K 枚のカードを取り出し、順序を保ったまま山の一番上に乗せました。

この操作後の山の上から順に、カードに書かれた整数を出力してください。

制約

  • 1 \leq K < N \leq 100
  • 1 \leq A_i \leq 100
  • 入力は全て整数

入力

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

N K
A_1 A_2 \ldots A_N

出力

操作後の山の上から i 枚目のカードに書かれた整数を B_i とする。B_1,B_2,\ldots,B_N をこの順に空白区切りで出力せよ。


入力例 1

5 3
1 2 3 4 5

出力例 1

3 4 5 1 2

最初、カードに書かれた整数は山の上から順に 1,2,3,4,5 です。

山の下から 3 枚のカードを取り出し、そのまま山の一番上に乗せたあと、カードに書かれた整数は山の上から順に 3,4,5,1,2 となります。


入力例 2

6 2
1 2 1 2 1 2

出力例 2

1 2 1 2 1 2

カードに書かれている整数は相異なるとは限りません。

Score : 100 points

Problem Statement

There is a stack of N cards, and the i-th card from the top has an integer A_i written on it.

You take K cards from the bottom of the stack and place them on top of the stack, maintaining their order.

Print the integers written on the cards from top to bottom after the operation.

Constraints

  • 1 \leq K < N \leq 100
  • 1 \leq A_i \leq 100
  • All input values are integers.

Input

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

N K
A_1 A_2 \ldots A_N

Output

Let B_i be the integer written on the i-th card from the top of the stack after the operation. Print B_1,B_2,\ldots,B_N in this order, separated by spaces.


Sample Input 1

5 3
1 2 3 4 5

Sample Output 1

3 4 5 1 2

Initially, the integers written on the cards are 1,2,3,4,5 from top to bottom.

After taking three cards from the bottom of the stack and placing them on top, the integers written on the cards become 3,4,5,1,2 from top to bottom.


Sample Input 2

6 2
1 2 1 2 1 2

Sample Output 2

1 2 1 2 1 2

The integers written on the cards are not necessarily distinct.

B - Overall Winner

実行時間制限: 2 sec / メモリ制限: 1024 MiB

配点 : 100

問題文

高橋くんと青木くんが N 回の試合を行いました。 これらの試合の結果を表す長さ N の文字列 S が与えられます。 i 回目の試合の勝者は、Si 文字目が T ならば高橋くん、A ならば青木くんです。

高橋くんと青木くんのうち、勝った試合の数が多い方を総合勝者とします。 ただし、勝った試合の数が同じである場合は、先にその勝ち数に達した者を総合勝者とします。 高橋くんと青木くんのどちらが総合勝者であるか求めてください。

制約

  • 1\leq N \leq 100
  • N は整数
  • ST および A からなる長さ N の文字列

入力

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

N
S

出力

総合勝者が高橋くんならば T を、青木くんならば A を出力せよ。


入力例 1

5
TTAAT

出力例 1

T

高橋くんは 3 回の試合に勝ち、青木くんは 2 回の試合に勝ちました。 よって、勝った試合の数が多い高橋くんが総合勝者です。


入力例 2

6
ATTATA

出力例 2

T

高橋くんと青木くんのどちらも 3 回の試合に勝ちました。 また、高橋くんは 5 回目の試合で 3 勝目に達し、青木くんは 6 回目の試合で 3 勝目に達しました。 よって、先に 3 勝目に達した高橋くんが総合勝者です。


入力例 3

1
A

出力例 3

A

Score : 100 points

Problem Statement

Takahashi and Aoki played N games. You are given a string S of length N, representing the results of these games. Takahashi won the i-th game if the i-th character of S is T, and Aoki won that game if it is A.

The overall winner between Takahashi and Aoki is the one who won more games than the other. If they had the same number of wins, the overall winner is the one who reached that number of wins first. Find the overall winner: Takahashi or Aoki.

Constraints

  • 1\leq N \leq 100
  • N is an integer.
  • S is a string of length N consisting of T and A.

Input

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

N
S

Output

If the overall winner is Takahashi, print T; if it is Aoki, print A.


Sample Input 1

5
TTAAT

Sample Output 1

T

Takahashi won three games, and Aoki won two. Thus, the overall winner is Takahashi, who won more games.


Sample Input 2

6
ATTATA

Sample Output 2

T

Both Takahashi and Aoki won three games. Takahashi reached three wins in the fifth game, and Aoki in the sixth game. Thus, the overall winner is Takahashi, who reached three wins first.


Sample Input 3

1
A

Sample Output 3

A
C - ABC-DEF

実行時間制限: 2 sec / メモリ制限: 1024 MiB

配点 : 200

問題文

非負整数 A,B,C,D,E,F があり、A\times B\times C\geq D\times E\times F をみたしています。
(A\times B\times C)-(D\times E\times F) の値を 998244353 で割った余りを求めてください。

制約

  • 0\leq A,B,C,D,E,F\leq 10^{18}
  • A\times B\times C\geq D\times E\times F
  • A,B,C,D,E,F は整数

入力

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

A B C D E F

出力

(A\times B\times C)-(D\times E\times F)998244353 で割った余りを整数で出力せよ。


入力例 1

2 3 5 1 2 4

出力例 1

22

A\times B\times C=2\times 3\times 5=30, D\times E\times F=1\times 2\times 4=8 より、
(A\times B\times C)-(D\times E\times F)=22 であり、これを 998244353 で割った余りである 22 を出力します。


入力例 2

1 1 1000000000 0 0 0

出力例 2

1755647

A\times B\times C=1000000000, D\times E\times F=0 より、
(A\times B\times C)-(D\times E\times F)=1000000000 であり、これを 998244353 で割った余りである 1755647 を出力します。


入力例 3

1000000000000000000 1000000000000000000 1000000000000000000 1000000000000000000 1000000000000000000 1000000000000000000

出力例 3

0

(A\times B\times C)-(D\times E\times F)=0 であり、これを 998244353 で割った余りである 0 を出力します。

Score : 200 points

Problem Statement

There are non-negative integers A, B, C, D, E, and F, which satisfy A\times B\times C\geq D\times E\times F.
Find the remainder when (A\times B\times C)-(D\times E\times F) is divided by 998244353.

Constraints

  • 0\leq A,B,C,D,E,F\leq 10^{18}
  • A\times B\times C\geq D\times E\times F
  • A, B, C, D, E, and F are integers.

Input

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

A B C D E F

Output

Print the remainder when (A\times B\times C)-(D\times E\times F) is divided by 998244353, as an integer.


Sample Input 1

2 3 5 1 2 4

Sample Output 1

22

Since A\times B\times C=2\times 3\times 5=30 and D\times E\times F=1\times 2\times 4=8,
we have (A\times B\times C)-(D\times E\times F)=22. Divide this by 998244353 and print the remainder, which is 22.


Sample Input 2

1 1 1000000000 0 0 0

Sample Output 2

1755647

Since A\times B\times C=1000000000 and D\times E\times F=0,
we have (A\times B\times C)-(D\times E\times F)=1000000000. Divide this by 998244353 and print the remainder, which is 1755647.


Sample Input 3

1000000000000000000 1000000000000000000 1000000000000000000 1000000000000000000 1000000000000000000 1000000000000000000

Sample Output 3

0

We have (A\times B\times C)-(D\times E\times F)=0. Divide this by 998244353 and print the remainder, which is 0.

D - Count Subgrid

実行時間制限: 2 sec / メモリ制限: 1024 MiB

配点 : 250

問題文

NN 列からなるグリッドがあります。グリッドの上から i 行目左から j 列目のマスは、S_{i,j}# のとき黒く、. のとき白く塗られています。

このグリッドから縦 M 行横 M 列の領域を取り出して得られるマスの塗られ方は何種類ありますか?

制約

  • 1\leq M \leq N \leq 10
  • N,M は整数
  • S_{i,j}. または #

入力

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

N M
S_{1,1}\ldots S_{1,N}
\vdots
S_{N,1}\ldots S_{N,N}

出力

答えを出力せよ。


入力例 1

3 2
...
###
#.#

出力例 1

3

与えられたグリッドの状態は下図左のとおりです。
ここから縦 2 行横 2 列の領域を取り出す方法は下図右のとおり 4 通りあり、マスの塗られ方は 3 種類あります。

図


入力例 2

10 3
..#.......
.###......
.#.#......
#####.....
#...#.....
......####
......#..#
......#...
......#..#
......####

出力例 2

36

Score : 250 points

Problem Statement

There is a grid with N rows and N columns. The cell at the i-th row from the top and j-th column from the left is painted black if S_{i,j} is #, and white if it is ..

How many distinct patterns of painted cells can be obtained by extracting a region of M rows and M columns from this grid?

Constraints

  • 1\leq M \leq N \leq 10
  • N and M are integers.
  • S_{i,j} is . or #.

Input

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

N M
S_{1,1}\ldots S_{1,N}
\vdots
S_{N,1}\ldots S_{N,N}

Output

Print the answer.


Sample Input 1

3 2
...
###
#.#

Sample Output 1

3

The state of the given grid is as shown in the left figure below.
There are four ways to extract a region of two rows and two columns from this grid as shown in the right figure below, and there are three distinct patterns of painted cells.

Figure


Sample Input 2

10 3
..#.......
.###......
.#.#......
#####.....
#...#.....
......####
......#..#
......#...
......#..#
......####

Sample Output 2

36
E - abc285_brutmhyhiizp

実行時間制限: 2 sec / メモリ制限: 1024 MiB

配点 : 300

問題文

別世界の AtCoder で開催されている AtCoder Big Contest では、 10^{16} 問の問題が一度に出題されます。
問題の ID は 1 問目から順に A, B, ..., Z, AA, AB, ..., ZZ, AAA, ... と付けられています。

つまり、 ID は以下の順番で付けられています。

  • 長さ 1 の英大文字からなる文字列を辞書順に並べたもの
  • 長さ 2 の英大文字からなる文字列を辞書順に並べたもの
  • 長さ 3 の英大文字からなる文字列を辞書順に並べたもの
  • ...

このコンテストに含まれる問題の ID である文字列 S が与えられるので、それが何問目か答えてください。

制約

  • S は AtCoder Big Contest に含まれる問題の ID として正しい

入力

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

S

出力

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


入力例 1

AB

出力例 1

28

ID が AB である問題は、 AtCoder Big Contest の 28 問目です。


入力例 2

C

出力例 2

3

ID が C である問題は、 AtCoder Big Contest の 3 問目です。


入力例 3

BRUTMHYHIIZP

出力例 3

10000000000000000

ID が BRUTMHYHIIZP である問題は、 AtCoder Big Contest の 10^{16} 問目、すなわち最終問題です。

Score : 300 points

Problem Statement

In a parallel universe, AtCoder holds AtCoder Big Contest, where 10^{16} problems are given at once.
The IDs of the problems are as follows, from the 1-st problem in order: A, B, ..., Z, AA, AB, ..., ZZ, AAA, ...

In other words, the IDs are given in the following order:

  • the strings of length 1 consisting of uppercase English letters, in lexicographical order;
  • the strings of length 2 consisting of uppercase English letters, in lexicographical order;
  • the strings of length 3 consisting of uppercase English letters, in lexicographical order;
  • ...

Given a string S that is an ID of a problem given in this contest, find the index of the problem. (See also Samples.)

Constraints

  • S is a valid ID of a problem given in AtCoder Big Contest.

Input

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

S

Output

Print the answer as an integer.


Sample Input 1

AB

Sample Output 1

28

The problem whose ID is AB is the 28-th problem of AtCoder Big Contest, so 28 should be printed.


Sample Input 2

C

Sample Output 2

3

The problem whose ID is C is the 3-rd problem of AtCoder Big Contest, so 3 should be printed.


Sample Input 3

BRUTMHYHIIZP

Sample Output 3

10000000000000000

The problem whose ID is BRUTMHYHIIZP is the 10^{16}-th (last) problem of AtCoder Big Contest, so 10^{16} should be printed as an integer.

F - Distance Indicators

実行時間制限: 2 sec / メモリ制限: 1024 MiB

配点 : 300

問題文

長さ N の整数列 A=(A _ 1,A _ 2,\ldots,A _ N) が与えられます。

整数の 2 つ組 (i,j)\ (1\le i\lt j\le N) のうち、j-i=A _ i+A _ j を満たすものがいくつあるか求めてください。

制約

  • 1\le N\le2\times10 ^ 5
  • 1\le A _ i\le2\times10 ^ 5\ (1\le i\le N)
  • 入力はすべて整数

入力

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

N
A _ 1 A _ 2 \ldots A _ N

出力

答えを出力せよ。


入力例 1

9
3 1 4 1 5 9 2 6 5

出力例 1

3

例えば、(i,j)=(4,7) とすると、j-i=7-4=3 かつ A _ i+A _ j=1+2=3 が成り立つので、j-i=A _ i+A _ j です。

一方で、(i,j)=(3,8) とすると、j-i=8-3=5 かつ A _ i+A _ j=4+6=10 となるので、j-i\ne A _ i+A _ j です。

(i,j)=(1,9),(2,4),(4,7)3 組だけが条件を満たすので、3 を出力してください。


入力例 2

3
123456 123456 123456

出力例 2

0

条件を満たす組が存在しない場合もあります。


入力例 3

30
8 3 6 4 9 6 5 6 5 6 3 4 7 3 7 4 9 8 5 8 3 6 8 8 4 5 5 5 6 5

出力例 3

17

Score : 300 points

Problem Statement

You are given an integer sequence A=(A _ 1,A _ 2,\ldots,A _ N) of length N.

Find how many pairs of integers (i,j)\ (1\le i\lt j\le N) satisfy j-i=A _ i+A _ j.

Constraints

  • 1\le N\le2\times10 ^ 5
  • 1\le A _ i\le2\times10 ^ 5\ (1\le i\le N)
  • All input values are integers.

Input

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

N
A _ 1 A _ 2 \ldots A _ N

Output

Output the answer.


Sample Input 1

9
3 1 4 1 5 9 2 6 5

Sample Output 1

3

For example, when (i,j)=(4,7), we have j-i=7-4=3 and A _ i+A _ j=1+2=3, so j-i=A _ i+A _ j.

In contrast, when (i,j)=(3,8), we have j-i=8-3=5 and A _ i+A _ j=4+6=10, so j-i\ne A _ i+A _ j.

Only the three pairs (i,j)=(1,9),(2,4),(4,7) satisfy the condition, so output 3.


Sample Input 2

3
123456 123456 123456

Sample Output 2

0

There may be no pairs that satisfy the condition.


Sample Input 3

30
8 3 6 4 9 6 5 6 5 6 3 4 7 3 7 4 9 8 5 8 3 6 8 8 4 5 5 5 6 5

Sample Output 3

17
G - String Bags

実行時間制限: 2 sec / メモリ制限: 1024 MiB

配点 : 425

問題文

あなたは最初、空文字列 S を持っています。
さらに、文字列がいくつか入った袋 1,2,\dots,N があります。
i には A_i 個の文字列 S_{i,1},S_{i,2},\dots,S_{i,A_i} が入っています。

これから、以下の手順を i=1,2,\dots,N について繰り返します。

  • 以下のふたつの行動のうち、どちらかを選択して行う。
    • 1 円を支払い、袋 i からちょうどひとつの文字列を選択して S の末尾に連結する。
    • 何もしない。

文字列 T が与えられるとき、最終的に ST を一致させるために必要な最小の金額を求めてください。
但し、どのようにしても最終的な ST に一致させることができない場合、 -1 と出力してください。

制約

  • T は長さ 1 以上 100 以下の英小文字からなる文字列
  • N1 以上 100 以下の整数
  • A_i1 以上 10 以下の整数
  • S_{i,j} は長さ 1 以上 10 以下の英小文字からなる文字列

入力

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

T
N
A_1 S_{1,1} S_{1,2} \dots S_{1,A_1}
A_2 S_{2,1} S_{2,2} \dots S_{2,A_2}
\vdots
A_N S_{N,1} S_{N,2} \dots S_{N,A_N}

出力

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


入力例 1

abcde
3
3 ab abc abcd
4 f c cd bcde
2 e de

出力例 1

2

例えば、以下のようにすると 2 円で最終的な ST を一致させることができ、これが必要な金額の最低値であることが示せます。

  • i=1 について、袋 1 から abc を選択し S の末尾に連結する。 S= abc となる。
  • i=2 について、何もしない。
  • i=3 について、袋 3 から de を選択し S の末尾に連結する。 S= abcde となる。

入力例 2

abcde
3
2 ab abc
3 f c bcde
1 e

出力例 2

-1

どのようにしても最終的な ST を一致させることができないので、 -1 と出力してください。


入力例 3

aaabbbbcccc
6
2 aa aaa
2 dd ddd
2 ab aabb
4 bbaa bbbc bbb bbcc
2 cc bcc
3 ccc cccc ccccc

出力例 3

4

Score: 425 points

Problem Statement

You initially have an empty string S.
Additionally, there are bags 1, 2, \dots, N, each containing some strings.
Bag i contains A_i strings S_{i,1}, S_{i,2}, \dots, S_{i,A_i}.

You will repeat the following steps for i = 1, 2, \dots, N:

  • Choose and perform one of the following two actions:
    • Pay 1 yen, select exactly one string from bag i, and concatenate it to the end of S.
    • Do nothing.

Given a string T, find the minimum amount of money required to make the final S equal T.
If there is no way to make the final S equal T, print -1.

Constraints

  • T is a string consisting of lowercase English letters with length between 1 and 100, inclusive.
  • N is an integer between 1 and 100, inclusive.
  • A_i is an integer between 1 and 10, inclusive.
  • S_{i,j} is a string consisting of lowercase English letters with length between 1 and 10, inclusive.

Input

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

T
N
A_1 S_{1,1} S_{1,2} \dots S_{1,A_1}
A_2 S_{2,1} S_{2,2} \dots S_{2,A_2}
\vdots
A_N S_{N,1} S_{N,2} \dots S_{N,A_N}

Output

Print the answer as an integer.


Sample Input 1

abcde
3
3 ab abc abcd
4 f c cd bcde
2 e de

Sample Output 1

2

For example, doing the following makes the final S equal T with two yen, which can be shown to be the minimum amount required.

  • For i=1, select abc from bag 1 and concatenate it to the end of S, making S= abc.
  • For i=2, do nothing.
  • For i=3, select de from bag 3 and concatenate it to the end of S, making S= abcde.

Sample Input 2

abcde
3
2 ab abc
3 f c bcde
1 e

Sample Output 2

-1

There is no way to make the final S equal T, so print -1.


Sample Input 3

aaabbbbcccc
6
2 aa aaa
2 dd ddd
2 ab aabb
4 bbaa bbbc bbb bbcc
2 cc bcc
3 ccc cccc ccccc

Sample Output 3

4
H - Least Elements

実行時間制限: 2 sec / メモリ制限: 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 - Shortest One Formula

実行時間制限: 2 sec / メモリ制限: 1024 MiB

配点 : 500

問題文

正整数 N が与えられます。

1, +, *, (, ) のみからなる数式のうち、値が N となるものの中で、文字列としての長さが最小のものを一つ求めてください。

より厳密には、以下の条件をすべて満たす文字列 S のうち長さが最小のものを一つ求めてください。

  • S は下の BNF 記法<expr> シンボルに従う文字列である。
  • S が表す数式の値は N である。
<expr>   ::= <term> | <expr> "+" <term>
<term>   ::= <factor> | <term> "*" <factor>
<factor> ::= <number> | "(" <expr> ")"
<number> ::= "1" | "1" <number> 

<expr> シンボルに従う文字列として、以下のようなものがあります。

  • 1111+111 : 1111+111 を表します。
  • (1+1)*(1+1) : (1+1)\times (1+1) を表します。
  • (11+(1+1)*(1+1))+1 : (11+(1+1)\times (1+1))+1 を表します。

一方、以下の文字列は <expr> シンボルに従いません。

  • (1+1)(1+1)
  • 1+2
  • 1-1
  • 1/1
  • )1(
  • 1++1
  • +1
  • (+1)
  • 1*+1

制約

  • 1\leq N\leq 2000
  • 入力は全て整数

入力

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

N

出力

答えを出力せよ。


入力例 1

9

出力例 1

(1+1+1)*(1+1+1)

値が 9 となるような数式は例えば以下のようなものがあります。

  • (1+1+1)*(1+1+1)
  • 1+1+1+1+1+1+1+1+1
  • (1+1)*(1+1)*(1+1)+1

値が 9 となるような数式のうち、長さが最小となるものは (1+1+1)*(1+1+1) です。


入力例 2

11

出力例 2

11

入力例 3

403

出力例 3

1+(1+1+1)*(1+11+11+111)

Score : 500 points

Problem Statement

You are given a positive integer N.

Among all valid arithmetic expressions consisting of the characters 1, +, *, (, and ), find one of the minimum length whose value is N.

More formally, among the strings S satisfying all of the following conditions, find one of the minimum length:

  • S conforms to the symbol <expr> in the BNF below.
  • The value of the expression represented by S is N.
<expr>   ::= <term> | <expr> "+" <term>
<term>   ::= <factor> | <term> "*" <factor>
<factor> ::= <number> | "(" <expr> ")"
<number> ::= "1" | "1" <number>

Strings that conform to <expr> include:

  • 1111+111 representing 1111+111.
  • (1+1)*(1+1) representing (1+1)\times(1+1).
  • (11+(1+1)*(1+1))+1 representing (11+(1+1)\times(1+1))+1.

Strings that do not conform to <expr> include:

  • (1+1)(1+1)
  • 1+2
  • 1-1
  • 1/1
  • )1(
  • 1++1
  • +1
  • (+1)
  • 1*+1

Constraints

  • 1 \le N \le 2000
  • All input values are integers.

Input

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

N

Output

Print a solution.


Sample Input 1

9

Sample Output 1

(1+1+1)*(1+1+1)

Expressions whose value is 9 include:

  • (1+1+1)*(1+1+1)
  • 1+1+1+1+1+1+1+1+1
  • (1+1)*(1+1)*(1+1)+1

Among them, a shortest is (1+1+1)*(1+1+1).


Sample Input 2

11

Sample Output 2

11

Sample Input 3

403

Sample Output 3

1+(1+1+1)*(1+11+11+111)