A - Echo

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

配点 : 100 点

問題文

長さ N の英小文字からなる文字列 S が与えられます。
S の i 文字目を S_i と記します。
S_1,S_1,S_2,S_2,\dots,S_N,S_N をこの順に連結した長さ 2N の文字列を出力してください。
例えば、 S が beginner のときは bbeeggiinnnneerr と出力してください。

制約

  • N は 1 \le N \le 50 を満たす整数
  • S は長さ N の英小文字からなる文字列

入力

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

N
S

出力

答えを出力せよ。


入力例 1

8
beginner

出力例 1

bbeeggiinnnneerr

問題文中の例と同じです。


入力例 2

3
aaa

出力例 2

aaaaaa

Score : 100 points

Problem Statement

You are given a string S of length N consisting of lowercase English letters.
We denote the i-th character of S by S_i.
Print the string of length 2N obtained by concatenating S_1,S_1,S_2,S_2,\dots,S_N, and S_N in this order.
For example, if S is beginner, print bbeeggiinnnneerr.

Constraints

  • N is an integer such that 1 \le N \le 50.
  • S is a string of length N consisting of lowercase English letters.

Input

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

N
S

Output

Print the answer.


Sample Input 1

8
beginner

Sample Output 1

bbeeggiinnnneerr

It is the same as the example described in the problem statement.


Sample Input 2

3
aaa

Sample Output 2

aaaaaa
B - Saturday

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

配点 : 100 点

問題文

ある日、学校へ行くのに疲れてしまった高橋くんは、土曜日まであと何日あるかを知りたくなりました。
その日は平日で、曜日を英語で表すと S だったことが分かっています。その日より後の直近の土曜日は何日後かを求めてください。

なお、月曜日、火曜日、水曜日、木曜日、金曜日はそれぞれ英語で Monday, Tuesday, Wednesday, Thursday, Friday です。

制約

  • S は Monday, Tuesday, Wednesday, Thursday, Friday のいずれかである

入力

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

S

出力

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


入力例 1

Wednesday

出力例 1

3

この日は水曜日なので、3 日後に土曜日になります。


入力例 2

Monday

出力例 2

5

Score : 100 points

Problem Statement

One day, tired from going to school, Takahashi wanted to know how many days there were until Saturday.
We know that the day was a weekday, and the name of the day of the week was S in English.
How many days were there until the first Saturday after that day (including Saturday but not the starting day)?

Constraints

  • S is Monday, Tuesday, Wednesday, Thursday, or Friday.

Input

Input is given from Standard Input in the following format:

S

Output

Print the answer as an integer.


Sample Input 1

Wednesday

Sample Output 1

3

It was Wednesday, so there were 3 days until the first Saturday after that day.


Sample Input 2

Monday

Sample Output 2

5
C - Monocolor

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

配点 : 200 点

問題文

N 個のボールがあります。各ボールは色 1 から色 N までの N 色のいずれかで塗られており、i 個目 (1\le i\le N) のボールの色は C_i です。

あなたは 1 回の操作で好きなボール 1 つを好きな N 色のいずれかに変更することができます。

全てのボールが同じ色になるようにするためには、最小で何回の操作が必要か求めてください。

制約

  • 1\le N\le 100
  • 1\le C_i\le N
  • 入力される値は全て整数

入力

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

N
C_1 C_2 \ldots C_N

出力

答えを出力せよ。


入力例 1

4
3 1 2 1

出力例 1

2

1 個目のボールの色を 1 に、3 個目のボールの色を 1 にすることで全てのボールの色を同じ色にすることができます。

2 個未満のボールの色を変えることで全てのボールの色を同じ色にすることはできないので、2 を出力してください。


入力例 2

5
3 3 3 3 3

出力例 2

0

最初から全てのボールの色が同じ場合もあります。


入力例 3

9
4 2 3 3 4 1 2 7 1

出力例 3

7

Score : 200 points

Problem Statement

There are N balls. Each ball is painted in one of N colors: color 1 through color N. The color of the i-th ball (1\le i\le N) is C_i.

In one operation, you can change the color of any one ball to any of the N colors.

Find the minimum number of operations required to make all the balls the same color.

Constraints

  • 1\le N\le 100
  • 1\le C_i\le N
  • All input values are integers.

Input

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

N
C_1 C_2 \ldots C_N

Output

Output the answer.


Sample Input 1

4
3 1 2 1

Sample Output 1

2

By changing the color of the first ball to 1 and the color of the third ball to 1, you can make all the balls the same color.

It is impossible to make all the balls the same color by changing the colors of fewer than two balls, so output 2.


Sample Input 2

5
3 3 3 3 3

Sample Output 2

0

All balls may have the same color from the beginning.


Sample Input 3

9
4 2 3 3 4 1 2 7 1

Sample Output 3

7
D - Multi Test Cases

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

配点 : 200 点

問題文

この問題は 1 つの入力ファイルに複数のテストケースが含まれる問題です。
はじめに整数 T が与えられます。T 個のテストケースについて次の問題を解いてください。

  • N 個の正整数 A_1, A_2, ..., A_N があります。このうち奇数は何個ありますか?

制約

  • 1 \leq T \leq 100
  • 1 \leq N \leq 100
  • 1 \leq A_i \leq 10^9
  • 入力される値はすべて整数

入力

入力は以下の形式で標準入力から与えられる。ここで \text{test}_i は i 番目のテストケースを意味する。

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

各テストケースは以下の形式で与えられる。

N
A_1 A_2 \dots A_N

出力

T 行出力せよ。i 行目には i 番目のテストケースに対する答えを出力せよ。


入力例 1

4
3
1 2 3
2
20 23
10
6 10 4 1 5 9 8 6 5 1
1
1000000000

出力例 1

2
1
5
0

この入力は 4 個のテストケースが含まれています。

入力の 2 行目と 3 行目が 1 番目のテストケースに対応する入力で、N = 3, A_1 = 1, A_2 = 2, A_3 = 3 になります。
A_1, A_2, A_3 のうち奇数は全部で 2 個なので 1 行目に 2 を出力します。

Score : 200 points

Problem Statement

In this problem, an input file contains multiple test cases.
You are first given an integer T. Solve the following problem for T test cases.

  • We have N positive integers A_1, A_2, ..., A_N. How many of them are odd?

Constraints

  • 1 \leq T \leq 100
  • 1 \leq N \leq 100
  • 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, where \text{test}_i represents the i-th test case:

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

Each test case is in the following format:

N
A_1 A_2 \dots A_N

Output

Print T lines. The i-th line should contain the answer for the i-th test case.


Sample Input 1

4
3
1 2 3
2
20 23
10
6 10 4 1 5 9 8 6 5 1
1
1000000000

Sample Output 1

2
1
5
0

This input contains four test cases.

The second and third lines correspond to the first test case, where N = 3, A_1 = 1, A_2 = 2, A_3 = 3.
We have two odd numbers in A_1, A_2, and A_3, so the first line should contain 2.

E - Even Digits

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

配点 : 300 点

問題文

非負整数 n が次の条件を満たすとき、n を 良い整数 と呼びます。

  • n を 10 進法で表したときに、偶数の数字 (0, 2, 4, 6, 8) のみが登場する。

例えば 0、68 および 2024 は良い整数です。

整数 N が与えられます。良い整数のうち小さい方から N 番目の整数を求めてください。

制約

  • 1 \leq N \leq 10^{12}
  • N は整数

入力

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

N

出力

小さい方から N 番目の良い整数を出力せよ。


入力例 1

8

出力例 1

24

良い整数を小さい方から順に並べると 0, 2, 4, 6, 8, 20, 22, 24, 26, 28, \dots となります。
小さい方から 8 番目の良い整数は 24 なので、これを出力します。


入力例 2

133

出力例 2

2024

入力例 3

31415926535

出力例 3

2006628868244228

Score: 300 points

Problem Statement

A non-negative integer n is called a good integer when it satisfies the following condition:

  • All digits in the decimal notation of n are even numbers (0, 2, 4, 6, and 8).

For example, 0, 68, and 2024 are good integers.

You are given an integer N. Find the N-th smallest good integer.

Constraints

  • 1 \leq N \leq 10^{12}
  • N is an integer.

Input

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

N

Output

Print the N-th smallest good integer.


Sample Input 1

8

Sample Output 1

24

The good integers in ascending order are 0, 2, 4, 6, 8, 20, 22, 24, 26, 28, \dots.
The eighth smallest is 24, which should be printed.


Sample Input 2

133

Sample Output 2

2024

Sample Input 3

31415926535

Sample Output 3

2006628868244228
F - Yamanote Line Game

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

配点 : 300 点

問題文

高橋君と青木君は 2 人で次の対戦ゲームをします。

高橋君が先手でゲームを始め、ゲームが終了するまでの間、 2 人は交互に 1 以上 2N+1 以下の整数を 1 つずつ宣言します。 どちらかが一度でも宣言した整数は、それ以降どちらも二度と宣言することが出来ません。 先に整数を宣言することが出来なくなった方のプレイヤーの負けとなり、負けなかった方のプレイヤーの勝ちとなります。

このゲームでは必ず高橋君が勝ちます。 高橋君の立場で実際にゲームを行い、ゲームに勝ってください。

制約

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

入出力

この問題はインタラクティブな問題(あなたの作成したプログラムとジャッジプログラムが入出力を介して対話を行う形式の問題)です。
あなたのプログラムが高橋君の立場で、ジャッジプログラムが青木君の立場でゲームを行います。

まず、あなたのプログラムに標準入力から正の整数 N が与えられます。 その後、ゲームが終了するまで下記の手順を繰り返します。

  1. あなたのプログラムが、高橋君が宣言する整数として、1 以上 2N+1 以下の整数を標準出力に出力します。(どちらかのプレイヤーによってすでに宣言されている整数を出力することは出来ません。)
  2. ジャッジプログラムによって、青木君が宣言する整数があなたのプログラムに標準入力から与えられます。(どちらかのプレイヤーによってすでに宣言されている整数が入力されることはありません。) ただし、青木君が宣言できる整数が残っていない場合は、代わりに 0 が与えられ高橋君の勝ちでゲームが終了します。

注意点

  • 出力を行うたびに標準出力をflushしてください。そうしなかった場合、ジャッジ結果が TLE となる可能性があります。
  • 高橋君の勝ちでゲームが終了したあと、あなたのプログラムは直ちに終了しなければなりません。そうしなかった場合、ジャッジ結果が AC とならない可能性があります。
  • ゲームの途中で不正な出力を行った場合(例えば、すでにどちらかのプレイヤーによって宣言されている整数を出力した場合)は不正解となりますが、そのときのジャッジ結果は不定です。WA になるとは限りません。

入出力例

入力 出力 説明
2 まず整数 N が与えられます。
1 高橋君が 1 を宣言します。
3 青木君が 3 を宣言します。
2 高橋君が 2 を宣言します。
4 青木君が 4 を宣言します。
5 高橋君が 5 を宣言します。
0 青木君が宣言できる整数が残っていないため、高橋君の勝ちでゲームが終了します。

Score : 300 points

Problem Statement

Takahashi and Aoki will play the following game against each other.

Starting from Takahashi, the two alternatingly declare an integer between 1 and 2N+1 (inclusive) until the game ends. Any integer declared by either player cannot be declared by either player again. The player who is no longer able to declare an integer loses; the player who didn't lose wins.

In this game, Takahashi will always win. Your task is to actually play the game on behalf of Takahashi and win the game.

Constraints

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

Input and Output

This task is an interactive task (in which your program and the judge program interact with each other via inputs and outputs).
Your program plays the game on behalf of Takahashi, and the judge program plays the game on behalf of Aoki.

First, your program is given a positive integer N from Standard Input. Then, the following procedures are repeated until the game ends.

  1. Your program outputs an integer between 1 and 2N+1 (inclusive) to Standard Output, which defines the integer that Takahashi declares. (You cannot output an integer that is already declared by either player.)
  2. The integer that Aoki declares is given by the judge program to your program from Standard Input. (No integer that is already declared by either player will be given.) If Aoki has no more integer to declare, 0 is given instead, which means that the game ended and Takahashi won.

Notes

  • After each output, you must flush Standard Output. Otherwise, you may get TLE.
  • After the game ended and Takahashi won, the program must be terminated immediately. Otherwise, the judge does not necessarily give AC.
  • If your program outputs something that violates the rules of the game (such as an integer that has already been declared by either player), your answer is considered incorrect. In such case, the verdict is indeterminate. It does not necessarily give WA.

Sample Input and Output

Input Output Description
2 First, an integer N is given.
1 Takahashi declares an integer 1.
3 Aoki declares an integer 3.
2 Takahashi declares an integer 2.
4 Aoki declares an integer 4.
5 Takahashi declares an integer 5.
0 Aoki has no more integer to declare, so Takahashi wins, and the game ends.
G - Make Target 2

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

配点 : 425 点

問題文

2 次元座標平面があり、座標が (x, y) である格子点は \max(|x|, |y|) が偶数のとき黒、奇数のとき白で塗られています。

L \leq x \leq R かつ D \leq y \leq U を満たす整数の組 (x, y) のうち、座標 (x, y) が黒く塗られているものの個数を求めてください。

制約

  • -10^6 \leq L \leq R \leq 10^6
  • -10^6 \leq D \leq U \leq 10^6
  • 入力される値はすべて整数

入力

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

L R D U

出力

答えを出力せよ。


入力例 1

-4 3 1 3

出力例 1

10

上の図のように、求める答えは 10 となります。


入力例 2

-14 14 -14 14

出力例 2

449

Score : 425 points

Problem Statement

There is a two-dimensional coordinate plane. A lattice point with coordinates (x, y) is painted black if \max(|x|, |y|) is even, and white if it is odd.

Among the pairs of integers (x, y) satisfying L \leq x \leq R and D \leq y \leq U, find the number of those for which the point (x, y) is painted black.

Constraints

  • -10^6 \leq L \leq R \leq 10^6
  • -10^6 \leq D \leq U \leq 10^6
  • All input values are integers.

Input

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

L R D U

Output

Output the answer.


Sample Input 1

-4 3 1 3

Sample Output 1

10

As shown in the figure above, the answer is 10.


Sample Input 2

-14 14 -14 14

Sample Output 2

449
H - Road Reduction

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

配点 : 500 点

問題文

AtCoder 王国には都市 1,2,\ldots,N の N 個の都市と、道路 1,2,\ldots,M の M 本の道路があります。
道路 i は都市 A_i と B_i を双方向に結び、距離は C_i です。
どの都市間もいくつかの道路を通って行き来することができます。

財政難である王国は、どの都市間もいくつかの道路を通って行き来できるという条件を満たすように N-1 本の道路を保守し、それ以外の道路を廃道にすることにしました。

保守する道路のみを通って都市 1 から都市 i へ移動するときの距離を d_i とするとき、保守する道路の選び方であって、d_2+d_3+\ldots+d_N を最小化するようなものを 1 つ出力してください。

制約

  • 2 \leq N \leq 2\times 10^5
  • N-1 \leq M \leq 2\times 10^5
  • 1 \leq A_i < B_i \leq N
  • i\neq j のとき、(A_i,B_i)\neq(A_j,B_j)
  • 1\leq C_i \leq 10^9
  • どの都市間もいくつかの道路を通って行き来することができる
  • 入力に含まれる値は全て整数である

入力

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

N M
A_1 B_1 C_1
A_2 B_2 C_2
\vdots
A_M B_M C_M

出力

保守するような道路の番号を空白区切りで出力せよ。出力の順序は問わない。
答えが複数存在する場合、どれを出力しても正解とみなされる。


入力例 1

3 3
1 2 1
2 3 2
1 3 10

出力例 1

1 2

保守する道路の選び方と d_i の値は次のようになります。

  • 道路 1,2 を保守するとき、d_2=1, d_3=3
  • 道路 1,3 を保守するとき、d_2=1, d_3=10
  • 道路 2,3 を保守するとき、d_2=12, d_3=10

よって、道路 1,2 を保守するときに d_2+d_3 が最小になります。


入力例 2

4 6
1 2 1
1 3 1
1 4 1
2 3 1
2 4 1
3 4 1

出力例 2

3 1 2

Score : 500 points

Problem Statement

The Kingdom of AtCoder has N cities called City 1,2,\ldots,N and M roads called Road 1,2,\ldots,M.
Road i connects Cities A_i and B_i bidirectionally and has a length of C_i.
One can travel between any two cities using some roads.

Under financial difficulties, the kingdom has decided to maintain only N-1 roads so that one can still travel between any two cities using those roads and abandon the rest.

Let d_i be the total length of the roads one must use when going from City 1 to City i using only maintained roads. Print a choice of roads to maintain that minimizes d_2+d_3+\ldots+d_N.

Constraints

  • 2 \leq N \leq 2\times 10^5
  • N-1 \leq M \leq 2\times 10^5
  • 1 \leq A_i < B_i \leq N
  • (A_i,B_i)\neq(A_j,B_j) if i\neq j.
  • 1\leq C_i \leq 10^9
  • One can travel between any two cities using some roads.
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

N M
A_1 B_1 C_1
A_2 B_2 C_2
\vdots
A_M B_M C_M

Output

Print the indices of roads to maintain, in arbitrary order, with spaces in between.
If multiple solutions exist, you may print any of them.


Sample Input 1

3 3
1 2 1
2 3 2
1 3 10

Sample Output 1

1 2

Here are the possible choices of roads to maintain and the corresponding values of d_i.

  • Maintain Road 1 and 2: d_2=1, d_3=3.
  • Maintain Road 1 and 3: d_2=1, d_3=10.
  • Maintain Road 2 and 3: d_2=12, d_3=10.

Thus, maintaining Road 1 and 2 minimizes d_2+d_3.


Sample Input 2

4 6
1 2 1
1 3 1
1 4 1
2 3 1
2 4 1
3 4 1

Sample Output 2

3 1 2
I - Transpose

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

配点 : 550 点

問題文

英大小文字と ( 、 ) からなる文字列 S=S_1 S_2 S_3 \dots S_{|S|} が与えられます。
文字列 S 中の括弧は、対応が取れています。

次の操作を、操作ができなくなるまで繰り返します。

  • まず、以下の条件を全て満たす整数組 (l,r) をひとつ選択する。
    • l < r
    • S_l = (
    • S_r = )
    • S_{l+1},S_{l+2},\dots,S_{r-1} は全て英大文字または英小文字である
  • T=\overline{S_{r-1}S_{r-2} \dots S_{l+1}} とする。
    • 但し、 \overline{x} は x の大文字と小文字を反転させた文字列を指す。
  • その後、 S の l 文字目から r 文字目までを削除し、削除した位置に T を挿入する。

詳細は入出力例を参照してください。

上記の操作を使って全ての ( と ) を除去することができ、最終的な文字列は操作の方法や順序によらないことが証明できます。
このとき、最終的な文字列を求めてください。

「 S 中の括弧の対応が取れている」とは? まず、正しい括弧列を次の通り定義します。
  • 正しい括弧列とは、以下のいずれかの条件を満たす文字列です。
    • 空文字列
    • ある正しい括弧列 A が存在して、 (, A, ) をこの順に連結した文字列
    • ある空でない正しい括弧列 A,B が存在して、 A,B をこの順に連結した文字列
S 中の括弧の対応が取れているとは、 S 中の ( と ) を順序を保って抜き出した時、それが正しい括弧列となることを指す。

制約

  • 1 \le |S| \le 5 \times 10^5
  • S は英大小文字と ( 、 ) からなる
  • S 中の括弧は対応が取れている

入力

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

S

出力

答えを出力せよ。


入力例 1

((A)y)x

出力例 1

YAx

S= ((A)y)x に対して操作を行います。

  • l=2,r=4 を選択します。このとき削除される文字列は (A) で、代わりに a が挿入されます。
    • この操作の結果、 S= (ay)x となります。
  • l=1,r=4 を選択します。このとき削除される文字列は (ay) で、代わりに YA が挿入されます。
    • この操作の結果、 S= YAx となります。

括弧を除去した結果、文字列は YAx となったので、これを出力してください。


入力例 2

((XYZ)n(X(y)Z))

出力例 2

XYZNXYZ

S= ((XYZ)n(X(y)Z)) に対して操作を行います。

  • l=10,r=12 を選択します。このとき削除される文字列は (y) で、代わりに Y が挿入されます。
    • この操作の結果、 S= ((XYZ)n(XYZ)) となります。
  • l=2,r=6 を選択します。このとき削除される文字列は (XYZ) で、代わりに zyx が挿入されます。
    • この操作の結果、 S= (zyxn(XYZ)) となります。
  • l=6,r=10 を選択します。このとき削除される文字列は (XYZ) で、代わりに zyx が挿入されます。
    • この操作の結果、 S= (zyxnzyx) となります。
  • l=1,r=9 を選択します。このとき削除される文字列は (zyxnzyx) で、代わりに XYZNXYZ が挿入されます。
    • この操作の結果、 S= XYZNXYZ となります。

括弧を除去した結果、文字列は XYZNXYZ となったので、これを出力してください。


入力例 3

(((()))(()))(())

出力例 3


操作結果が空文字列になる場合もあります。


入力例 4

dF(qT(plC())NnnfR(GsdccC))PO()KjsiI((ysA)eWW)ve

出力例 4

dFGsdccCrFNNnplCtQPOKjsiIwwEysAve

Score: 550 points

Problem Statement

You are given a string S = S_1 S_2 S_3 \dots S_{|S|} consisting of uppercase and lowercase English letters, (, and ).
The parentheses in the string S are properly matched.

Repeat the following operation until no more operations can be performed:

  • First, select one pair of integers (l, r) that satisfies all of the following conditions:
    • l < r
    • S_l = (
    • S_r = )
    • Each of the characters S_{l+1}, S_{l+2}, \dots, S_{r-1} is an uppercase or lowercase English letter.
  • Let T = \overline{S_{r-1} S_{r-2} \dots S_{l+1}}.
    • Here, \overline{x} denotes the string obtained by toggling the case of each character in x (uppercase to lowercase and vice versa).
  • Then, delete the l-th through r-th characters of S and insert T at the position where the deletion occurred.

Refer to the sample inputs and outputs for clarification.

It can be proved that it is possible to remove all (s and )s from the string using the above operations, and the final string is independent of how and in what order the operations are performed.
Determine the final string.

What does it mean that the parentheses in S are properly matched? First, a correct parenthesis sequence is defined as follows:
  • A correct parenthesis sequence is a string that satisfies one of the following conditions:
    • It is an empty string.
    • There exists a correct parenthesis sequence A, and the string is formed by concatenating (, A, ) in this order.
    • There exist non-empty correct parenthesis sequences A and B, and the string is formed by concatenating A and B in this order.
The parentheses in S are properly matched if and only if the (s and )s extracted from S without changing the order form a correct parenthesis sequence.

Constraints

  • 1 \le |S| \le 5 \times 10^5
  • S consists of uppercase and lowercase English letters, (, and ).
  • The parentheses in S are properly matched.

Input

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

S

Output

Print the final string.


Sample Input 1

((A)y)x

Sample Output 1

YAx

Let us perform the operations for S = ((A)y)x.

  • Choose l=2 and r=4. The substring (A) is removed and replaced with a.
    • After this operation, S = (ay)x.
  • Choose l=1 and r=4. The substring (ay) is removed and replaced with YA.
    • After this operation, S = YAx.

After removing the parentheses, the string becomes YAx, which should be printed.


Sample Input 2

((XYZ)n(X(y)Z))

Sample Output 2

XYZNXYZ

Let us perform the operations for S = ((XYZ)n(X(y)Z)).

  • Choose l=10 and r=12. The substring (y) is removed and replaced with Y.
    • After this operation, S = ((XYZ)n(XYZ)).
  • Choose l=2 and r=6. The substring (XYZ) is removed and replaced with zyx.
    • After this operation, S = (zyxn(XYZ)).
  • Choose l=6 and r=10. The substring (XYZ) is removed and replaced with zyx.
    • After this operation, S = (zyxnzyx).
  • Choose l=1 and r=9. The substring (zyxnzyx) is removed and replaced with XYZNXYZ.
    • After this operation, S = XYZNXYZ.

After removing the parentheses, the string becomes XYZNXYZ, which should be printed.


Sample Input 3

(((()))(()))(())

Sample Output 3


The final outcome may be an empty string.


Sample Input 4

dF(qT(plC())NnnfR(GsdccC))PO()KjsiI((ysA)eWW)ve

Sample Output 4

dFGsdccCrFNNnplCtQPOKjsiIwwEysAve