A - Yay!

Time Limit: 2 sec / Memory Limit: 1024 MB

配点 : 150

問題文

英小文字からなる文字列 S が与えられます。ここで S の長さは 3 以上 100 以下です。

S はある 1 文字を除いて全て同じ文字で構成されています。

他のどの文字とも異なる文字は前から何文字目でしょうか。

制約

  • S2 種類の英小文字からなる長さ 3 以上 100 以下の文字列
  • S はある 1 文字を除いて全て同じ文字

入力

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

S

出力

答えを出力せよ。


入力例 1

yay

出力例 1

2

yay2 文字目は、1 文字目とも 3 文字目とも異なります。


入力例 2

egg

出力例 2

1

入力例 3

zzzzzwz

出力例 3

6

Score: 150 points

Problem Statement

You are given a string S consisting of lowercase English letters. The length of S is between 3 and 100, inclusive.

All characters but one of S are the same.

Find x such that the x-th character of S differs from all other characters.

Constraints

  • S is a string of length between 3 and 100, inclusive, consisting of two different lowercase English letters.
  • All characters but one of S are the same.

Input

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

S

Output

Print the answer.


Sample Input 1

yay

Sample Output 1

2

The second character of yay differs from the first and third characters.


Sample Input 2

egg

Sample Output 2

1

Sample Input 3

zzzzzwz

Sample Output 3

6
B - Which is ahead?

Time Limit: 2 sec / Memory Limit: 1024 MB

配点 : 200

問題文

N 人が 1 列に並んでおり、前から i 番目に並んでいる人は人 P_i です。

Q 個のクエリを処理して下さい。i 番目のクエリは以下のものです。

  • 整数 A_i,B_i が与えられる。人 A_i と人 B_i のうち、より前に並んでいる人の番号を出力せよ。

制約

  • 入力は全て整数
  • 1\leq N\leq 100
  • 1\leq P_i\leq N
  • P_i \neq P_j\ (i\neq j)
  • 1\leq Q \leq 100
  • 1\leq A_i<B_i\leq N

入力

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

N
P_1 \ldots P_N
Q
A_1 B_1
\vdots
A_Q B_Q

出力

Q 行出力せよ。i 行目には、i 番目のクエリの答えを出力せよ。


入力例 1

3
2 1 3
3
2 3
1 2
1 3

出力例 1

2
2
1

1 番目のクエリでは、人 2 は前から 1 番目、人 3 は前から 3 番目なので、人 2 がより前にいます。

2 番目のクエリでは、人 1 は前から 2 番目、人 2 は前から 1 番目なので、人 2 がより前にいます。

3 番目のクエリでは、人 1 は前から 2 番目、人 3 は前から 3 番目なので、人 1 がより前にいます。


入力例 2

7
3 7 2 1 6 5 4
13
2 3
1 2
1 3
3 6
3 7
2 4
3 7
1 3
4 7
1 6
2 4
1 3
1 3

出力例 2

3
2
3
3
3
2
3
3
7
1
2
3
3

Score: 200 points

Problem Statement

There are N people standing in a line. The person standing at the i-th position from the front is person P_i.

Process Q queries. The i-th query is as follows:

  • You are given integers A_i and B_i. Between person A_i and person B_i, print the person number of the person standing further to the front.

Constraints

  • All inputs are integers.
  • 1 \leq N \leq 100
  • 1 \leq P_i \leq N
  • P_i \neq P_j\ (i \neq j)
  • 1 \leq Q \leq 100
  • 1 \leq A_i < B_i \leq N

Input

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

N
P_1 \ldots P_N
Q
A_1 B_1
\vdots
A_Q B_Q

Output

Print Q lines. The i-th line should contain the response for the i-th query.


Sample Input 1

3
2 1 3
3
2 3
1 2
1 3

Sample Output 1

2
2
1

In the first query, person 2 is at the first position from the front, and person 3 is at the third position, so person 2 is further to the front.

In the second query, person 1 is at the second position from the front, and person 2 is at the first position, so person 2 is further to the front.

In the third query, person 1 is at the second position from the front, and person 3 is at the third position, so person 1 is further to the front.


Sample Input 2

7
3 7 2 1 6 5 4
13
2 3
1 2
1 3
3 6
3 7
2 4
3 7
1 3
4 7
1 6
2 4
1 3
1 3

Sample Output 2

3
2
3
3
3
2
3
3
7
1
2
3
3
C - Many Replacement

Time Limit: 2 sec / Memory Limit: 1024 MB

配点 : 350

問題文

英小文字からなる長さ N の文字列 S が与えられます。

文字列 S に対して操作を Q 回行います。 i 回目 (1\leq i\leq Q) の操作は文字の組 (c _ i,d _ i) で表され、次のような操作に対応します。

  • S に含まれる文字 c _ i をすべて文字 d _ i で置き換える。

すべての操作が終わったあとの文字列 S を出力してください。

制約

  • 1\leq N\leq2\times10^5
  • S は英小文字からなる長さ N の文字列
  • 1\leq Q\leq2\times10^5
  • c _ i,d _ i は英小文字 (1\leq i\leq Q)
  • N,Q は整数

入力

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

N
S
Q
c _ 1 d _ 1
c _ 2 d _ 2
\vdots
c _ Q d _ Q

出力

すべての操作が終わったあとの S を出力せよ。


入力例 1

7
atcoder
4
r a
t e
d v
a r

出力例 1

recover

Satcoderatcodeaaecodeaaecovearecover と変化します。 たとえば、4 番目の操作では S={}aecovea に含まれる a1 文字目と 7 文字目)をすべて r に置き換えるので S={}recover となります。

すべての操作が終わったときには S={}recover となっているため、recover を出力してください。


入力例 2

3
abc
4
a a
s k
n n
z b

出力例 2

abc

c _ i=d _ i であるような操作や Sc _ i が含まれないような操作もあります。


入力例 3

34
supercalifragilisticexpialidocious
20
g c
l g
g m
c m
r o
s e
a a
o f
f s
e t
t l
d v
p k
v h
x i
h n
n j
i r
s i
u a

出力例 3

laklimamriiamrmrllrmlrkramrjimrial

Score: 350 points

Problem Statement

You are given a string S of length N consisting of lowercase English letters.

You will perform an operation Q times on the string S. The i-th operation (1\leq i\leq Q) is represented by a pair of characters (c _ i,d _ i), which corresponds to the following operation:

  • Replace all occurrences of the character c _ i in S with the character d _ i.

Print the string S after all operations are completed.

Constraints

  • 1\leq N\leq2\times10^5
  • S is a string of length N consisting of lowercase English letters.
  • 1\leq Q\leq2\times10^5
  • c _ i and d _ i are lowercase English letters (1\leq i\leq Q).
  • N and Q are integers.

Input

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

N
S
Q
c _ 1 d _ 1
c _ 2 d _ 2
\vdots
c _ Q d _ Q

Output

Print the string S after all operations are completed.


Sample Input 1

7
atcoder
4
r a
t e
d v
a r

Sample Output 1

recover

S changes as follows: atcoderatcodeaaecodeaaecovearecover. For example, in the fourth operation, all occurrences of a in S={}aecovea (the first and seventh characters) are replaced with r, resulting in S={}recover.

After all operations are completed, S={}recover, so print recover.


Sample Input 2

3
abc
4
a a
s k
n n
z b

Sample Output 2

abc

There may be operations where c _ i=d _ i or S does not contain c _ i.


Sample Input 3

34
supercalifragilisticexpialidocious
20
g c
l g
g m
c m
r o
s e
a a
o f
f s
e t
t l
d v
p k
v h
x i
h n
n j
i r
s i
u a

Sample Output 3

laklimamriiamrmrllrmlrkramrjimrial
D - Square Pair

Time Limit: 2 sec / Memory Limit: 1024 MB

配点 : 400

問題文

長さ N の非負整数列 A=(A_1,\ldots,A_N) が与えられます。以下の条件を共に満たす整数組 (i,j) の個数を求めてください。

  • 1\leq i < j\leq N
  • A_i A_j は平方数

ここで非負整数 a は、ある非負整数 d を用いて a=d^2 と表せる場合平方数と呼ばれます。

制約

  • 入力は全て整数
  • 2\leq N\leq 2\times 10^5
  • 0\leq A_i\leq 2\times 10^5

入力

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

N
A_1 \ldots A_N

出力

答えを出力せよ。


入力例 1

5
0 3 2 8 12

出力例 1

6

条件を満たす整数組は (i,j)=(1,2),(1,3),(1,4),(1,5),(2,5),(3,4)6 つです。

例えば、A_2A_5=36 であり 36 は平方数なので、(i,j)=(2,5) は条件を満たします。


入力例 2

8
2 2 4 6 3 100 100 25

出力例 2

7

Score: 400 points

Problem Statement

You are given a sequence of non-negative integers A=(A_1,\ldots,A_N) of length N. Find the number of pairs of integers (i,j) that satisfy both of the following conditions:

  • 1\leq i < j\leq N
  • A_i A_j is a square number.

Here, a non-negative integer a is called a square number when it can be expressed as a=d^2 using some non-negative integer d.

Constraints

  • All inputs are integers.
  • 2\leq N\leq 2\times 10^5
  • 0\leq A_i\leq 2\times 10^5

Input

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

N
A_1 \ldots A_N

Output

Print the answer.


Sample Input 1

5
0 3 2 8 12

Sample Output 1

6

Six pairs of integers, (i,j)=(1,2),(1,3),(1,4),(1,5),(2,5),(3,4), satisfy the conditions.

For example, A_2A_5=36, and 36 is a square number, so the pair (i,j)=(2,5) satisfies the conditions.


Sample Input 2

8
2 2 4 6 3 100 100 25

Sample Output 2

7
E - Last Train

Time Limit: 2 sec / Memory Limit: 1024 MB

配点 : 450

問題文

AtCoder 国には駅 1,2,\ldots,NN 個の駅があります。

AtCoder 国に存在する電車の情報が M 個与えられます。 i 番目 (1\leq i\leq M) の情報は正整数の 6 つ組 (l _ i,d _ i,k _ i,c _ i,A _ i,B _ i) で表され、次のような情報に対応しています。

  • t=l _ i,l _ i+d _ i,l _ i+2d _ i,\ldots,l _ i+(k _ i-1)d _ i それぞれについて、次のような電車が存在する。
    • 時刻 t に 駅 A _ i を出発し、時刻 t+c _ i に駅 B _ i に到着する。

これらの情報にあてはまらない電車は存在せず、電車以外の方法である駅から異なる駅へ移動することはできません。
また、乗り換えにかかる時間は無視できるとします。

S から駅 N に到着できる最終時刻を f(S) とします。
より厳密には、整数の 4 つ組の列 \big((t _ i,c _ i,A _ i,B _ i)\big) _ {i=1,2,\ldots,k} であって、次のすべての条件を満たすものが存在するような t の最大値を f(S) とします。

  • t\leq t _ 1
  • A _ 1=S,B _ k=N
  • すべての 1\leq i\lt k について、B _ i=A _ {i+1}
  • すべての 1\leq i\leq k について、時刻 t _ i に駅 A _ i を出発して時刻 t _ i+c _ i に駅 B _ i に到着する電車が存在する。
  • すべての 1\leq i\lt k について、t _ i+c _ i\leq t _ {i+1}

ただし、そのような t が存在しないとき f(S)=-\infty とします。

f(1),f(2),\ldots,f(N-1) を求めてください。

制約

  • 2\leq N\leq2\times10 ^ 5
  • 1\leq M\leq2\times10 ^ 5
  • 1\leq l _ i,d _ i,k _ i,c _ i\leq10 ^ 9\ (1\leq i\leq M)
  • 1\leq A _ i,B _ i\leq N\ (1\leq i\leq M)
  • A _ i\neq B _ i\ (1\leq i\leq M)
  • 入力はすべて整数

入力

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

N M
l _ 1 d _ 1 k _ 1 c _ 1 A _ 1 B _ 1
l _ 2 d _ 2 k _ 2 c _ 2 A _ 2 B _ 2
\vdots
l _ M d _ M k _ M c _ M A _ M B _ M

出力

N-1 行出力せよ。 k 行目には f(k)\neq-\infty ならば f(k) を、f(k)=-\infty ならば Unreachable を出力せよ。


入力例 1

6 7
10 5 10 3 1 3
13 5 10 2 3 4
15 5 10 7 4 6
3 10 2 4 2 5
7 10 2 3 5 6
5 3 18 2 2 3
6 3 20 4 2 1

出力例 1

55
56
58
60
17

AtCoder 国に走っている電車は以下の図のようになります(発着時間の情報は図には含まれていません)。

2 から駅 6 に到着できる最終時刻について考えます。 次の図のように、駅 2 を時刻 56 に出発して駅 2\rightarrow3\rightarrow4\rightarrow6 のように移動することで駅 6 に到着することができます。

2 を時刻 56 より遅く出発して駅 6 に到着することはできないため、f(2)=56 です。


入力例 2

5 5
1000000000 1000000000 1000000000 1000000000 1 5
5 9 2 6 2 3
10 4 1 6 2 3
1 1 1 1 3 5
3 1 4 1 5 1

出力例 2

1000000000000000000
Unreachable
1
Unreachable

1 を時刻 10 ^ {18} に出発して駅 5 に時刻 10 ^ {18}+10 ^ 9 に到着するような電車が存在します。それ以降に駅 1 を出発する電車はないため、f(1)=10 ^ {18} です。 このように、答えが 32\operatorname{bit} 整数におさまらない場合もあります。

また、時刻 14 に駅 2 を出発して時刻 20 に駅 3 に到着するような電車は 2 番目の情報と 3 番目の情報の両方で存在が保証されています。 このように、複数の情報に重複している電車もあります。


入力例 3

16 20
4018 9698 2850 3026 8 11
2310 7571 7732 1862 13 14
2440 2121 20 1849 11 16
2560 5115 190 3655 5 16
1936 6664 39 8822 4 16
7597 8325 20 7576 12 5
5396 1088 540 7765 15 1
3226 88 6988 2504 13 5
1838 7490 63 4098 8 3
1456 5042 4 2815 14 7
3762 6803 5054 6994 10 9
9526 6001 61 8025 7 8
5176 6747 107 3403 1 5
2014 5533 2031 8127 8 11
8102 5878 58 9548 9 10
3788 174 3088 5950 3 13
7778 5389 100 9003 10 15
556 9425 9458 109 3 11
5725 7937 10 3282 2 9
6951 7211 8590 1994 15 12

出力例 3

720358
77158
540926
255168
969295
Unreachable
369586
466218
343148
541289
42739
165772
618082
16582
591828

Score: 450 points

Problem Statement

In the country of AtCoder, there are N stations: station 1, station 2, \ldots, station N.

You are given M pieces of information about trains in the country. The i-th piece of information (1\leq i\leq M) is represented by a tuple of six positive integers (l _ i,d _ i,k _ i,c _ i,A _ i,B _ i), which corresponds to the following information:

  • For each t=l _ i,l _ i+d _ i,l _ i+2d _ i,\ldots,l _ i+(k _ i-1)d _ i, there is a train as follows:
    • The train departs from station A _ i at time t and arrives at station B _ i at time t+c _ i.

No trains exist other than those described by this information, and it is impossible to move from one station to another by any means other than by train.
Also, assume that the time required for transfers is negligible.

Let f(S) be the latest time at which one can arrive at station N from station S.
More precisely, f(S) is defined as the maximum value of t for which there is a sequence of tuples of four integers \big((t _ i,c _ i,A _ i,B _ i)\big) _ {i=1,2,\ldots,k} that satisfies all of the following conditions:

  • t\leq t _ 1
  • A _ 1=S,B _ k=N
  • B _ i=A _ {i+1} for all 1\leq i\lt k,
  • For all 1\leq i\leq k, there is a train that departs from station A _ i at time t _ i and arrives at station B _ i at time t _ i+c _ i.
  • t _ i+c _ i\leq t _ {i+1} for all 1\leq i\lt k.

If no such t exists, set f(S)=-\infty.

Find f(1),f(2),\ldots,f(N-1).

Constraints

  • 2\leq N\leq2\times10 ^ 5
  • 1\leq M\leq2\times10 ^ 5
  • 1\leq l _ i,d _ i,k _ i,c _ i\leq10 ^ 9\ (1\leq i\leq M)
  • 1\leq A _ i,B _ i\leq N\ (1\leq i\leq M)
  • A _ i\neq B _ i\ (1\leq i\leq M)
  • All input values are integers.

Input

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

N M
l _ 1 d _ 1 k _ 1 c _ 1 A _ 1 B _ 1
l _ 2 d _ 2 k _ 2 c _ 2 A _ 2 B _ 2
\vdots
l _ M d _ M k _ M c _ M A _ M B _ M

Output

Print N-1 lines. The k-th line should contain f(k) if f(k)\neq-\infty, and Unreachable if f(k)=-\infty.


Sample Input 1

6 7
10 5 10 3 1 3
13 5 10 2 3 4
15 5 10 7 4 6
3 10 2 4 2 5
7 10 2 3 5 6
5 3 18 2 2 3
6 3 20 4 2 1

Sample Output 1

55
56
58
60
17

The following diagram shows the trains running in the country (information about arrival and departure times is omitted).

Consider the latest time at which one can arrive at station 6 from station 2. As shown in the following diagram, one can arrive at station 6 by departing from station 2 at time 56 and moving as station 2\rightarrow station 3\rightarrow station 4\rightarrow station 6.

It is impossible to depart from station 2 after time 56 and arrive at station 6, so f(2)=56.


Sample Input 2

5 5
1000000000 1000000000 1000000000 1000000000 1 5
5 9 2 6 2 3
10 4 1 6 2 3
1 1 1 1 3 5
3 1 4 1 5 1

Sample Output 2

1000000000000000000
Unreachable
1
Unreachable

There is a train that departs from station 1 at time 10 ^ {18} and arrives at station 5 at time 10 ^ {18}+10 ^ 9. There are no trains departing from station 1 after that time, so f(1)=10 ^ {18}. As seen here, the answer may not fit within a 32\operatorname{bit} integer.

Also, both the second and third pieces of information guarantee that there is a train that departs from station 2 at time 14 and arrives at station 3 at time 20. As seen here, some trains may appear in multiple pieces of information.


Sample Input 3

16 20
4018 9698 2850 3026 8 11
2310 7571 7732 1862 13 14
2440 2121 20 1849 11 16
2560 5115 190 3655 5 16
1936 6664 39 8822 4 16
7597 8325 20 7576 12 5
5396 1088 540 7765 15 1
3226 88 6988 2504 13 5
1838 7490 63 4098 8 3
1456 5042 4 2815 14 7
3762 6803 5054 6994 10 9
9526 6001 61 8025 7 8
5176 6747 107 3403 1 5
2014 5533 2031 8127 8 11
8102 5878 58 9548 9 10
3788 174 3088 5950 3 13
7778 5389 100 9003 10 15
556 9425 9458 109 3 11
5725 7937 10 3282 2 9
6951 7211 8590 1994 15 12

Sample Output 3

720358
77158
540926
255168
969295
Unreachable
369586
466218
343148
541289
42739
165772
618082
16582
591828
F - Black Jack

Time Limit: 2 sec / Memory Limit: 1024 MB

配点 : 550

問題文

あなたとディーラーでゲームをします。 ゲームは 1 以上 D 以下の整数が等確率で出る D 面サイコロ、0 で初期化された変数 x,y を用いて以下のように行われます。

  • あなたはサイコロを振り、出た目を x に加算する操作を好きな回数行える。ここで、あなたは操作を行うたびに次の操作を行うかを選択できる。

  • その後、ディーラーは y < L を満たす限り、サイコロを振り、出た目を y に加算する操作を繰り返す。

  • x > N の場合あなたの負けである。そうでない場合、y > N または x>y のいずれかを満たす場合あなたの勝ちで、どちらも満たさない場合あなたの負けである。

あなたが勝率を最大化するように適切に行動する際、勝率を求めてください。

制約

  • 入力は全て整数
  • 1\leq L\leq N\leq 2\times 10^5
  • 1\leq D \leq N

入力

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

N L D

出力

答えを出力せよ。出力した値の真の値との絶対誤差または相対誤差が 10^{-6} 以下のとき正解と判定される。


入力例 1

3 2 2

出力例 1

0.468750000000000

x2 以下の場合操作を続けるという戦略が最適であることが証明できます。


入力例 2

200000 200000 200000

出力例 2

0.999986408692793

Score: 550 points

Problem Statement

You will play a game against a dealer. The game uses a D-sided die (dice) that shows an integer from 1 to D with equal probability, and two variables x and y initialized to 0. The game proceeds as follows:

  • You may perform the following operation any number of times: roll the die and add the result to x. You can choose whether to continue rolling or not after each roll.

  • Then, the dealer will repeat the following operation as long as y < L: roll the die and add the result to y.

  • If x > N, you lose. Otherwise, you win if y > N or x > y and lose if neither is satisfied.

Determine the probability of your winning when you act in a way that maximizes the probability of winning.

Constraints

  • All inputs are integers.
  • 1 \leq L \leq N \leq 2 \times 10^5
  • 1 \leq D \leq N

Input

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

N L D

Output

Print the answer. Your output will be considered correct if its absolute or relative error from the true value is at most 10^{-6}.


Sample Input 1

3 2 2

Sample Output 1

0.468750000000000

It can be proved that the optimal strategy is to continue rolling as long as x is not greater than 2.


Sample Input 2

200000 200000 200000

Sample Output 2

0.999986408692793
G - Retroactive Range Chmax

Time Limit: 5 sec / Memory Limit: 1024 MB

配点 : 625

問題文

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

Q 個の操作を順に処理してください。 操作は次の 3 種類のいずれかです。

  • タイプ 1 の操作は整数の 3 つ組 (l,r,x) で表され、i=l,l+1,\ldots,r に対して、A _ i\max\lbrace A _ i,x\rbrace で置き換えることに対応する。
  • タイプ 2 の操作は整数 i で表され、i 回目の操作を取り消すことに対応する(ただし、i 回目の操作はタイプ 1 の操作であり、これまでに取り消されていないことが保証される)。数列 A は、最初の状態からはじめてこれまでのタイプ 1 の操作のうち取り消されていない操作がすべて行われた状態になる。
  • タイプ 3 の操作は整数 i で表され、現在の A _ i の値を出力することに対応する。

制約

  • 1\leq N\leq2\times10 ^ 5
  • 1\leq A _ i\leq10 ^ 9\ (1\leq i\leq N)
  • 1\leq Q\leq2\times10 ^ 5
  • タイプ 1 の操作において、1\leq l\leq r\leq N かつ 1\leq x\leq10 ^ 9
  • タイプ 2 の操作において、i はそれ以前に与えられた操作の回数以下かつ 1\leq i
  • タイプ 2 の操作において、i 番目の操作はタイプ 1 の操作
  • タイプ 2 の操作における i は重複しない
  • タイプ 3 の操作において、1\leq i\leq N
  • 入力はすべて整数

入力

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

N
A _ 1 A _ 2 \ldots A _ N
Q
\operatorname{query} _ 1
\operatorname{query} _ 2
\vdots
\operatorname{query} _ Q

ただし、\operatorname{query} _ k\ (1\leq k\leq Q)k 回目の操作を表し、k 回目の操作のタイプによってそれぞれ次のような入力が与えられる。

タイプ 1 の操作の場合

1 l r x

が入力され、k 回目の操作が (l,r,x) で表されるタイプ 1 の操作であることを意味する。

タイプ 2 の操作の場合

2 i

が入力され、k 回目の操作が i で表されるタイプ 2 の操作であることを意味する。

タイプ 3 の操作の場合

3 i

が入力され、k 回目の操作が i で表されるタイプ 3 の操作であることを意味する。

出力

与えられるタイプ 3 の操作の個数を q 個とし、q 行出力せよ。 i 行目 (1\leq i\leq q) にはタイプ 3 の操作のうち i 番目に入力されたもので出力すべき値を出力せよ。


入力例 1

6
2 7 1 8 2 8
15
3 1
3 3
3 4
1 1 5 4
3 1
3 3
3 4
1 3 6 9
3 1
3 3
3 4
2 4
3 1
3 3
3 4

出力例 1

2
1
8
4
4
8
4
9
9
2
9
9

はじめ、数列 A(2,7,1,8,2,8) です。

1,2,3 回目の操作では A _ 1,A _ 3,A _ 4 の値である 2,1,8 をそれぞれ出力してください。

4 回目の操作では A _ 1,A _ 2,A _ 3,A _ 4,A _ 5 の値を \max\lbrace A _ i,4\rbrace で置き換えます。 この操作の直後、A(4,7,4,8,4,8) となります。

5,6,7 回目の操作ではこの時点での A _ 1,A _ 3,A _ 4 の値である 4,4,8 をそれぞれ出力してください。

8 回目の操作では A _ 3,A _ 4,A _ 5,A _ 6 の値を \max\lbrace A _ i,9\rbrace で置き換えます。 この操作の直後、A(4,7,9,9,9,9) となります。

9,10,11 回目の操作ではこの時点での A _ 1,A _ 3,A _ 4 の値である 4,9,9 をそれぞれ出力してください。

12 回目の操作では 4 回目の操作を取り消します。 この操作の直後、A(2,7,9,9,9,9) となります。

13,14,15 回目の操作ではこの時点での A _ 1,A _ 3,A _ 4 の値である 2,9,9 をそれぞれ出力してください。


入力例 2

24
721 78 541 256 970 478 370 467 344 542 43 166 619 17 592 222 983 729 338 747 62 452 815 838
35
3 10
3 8
3 8
3 13
3 9
1 1 17 251
3 3
3 19
3 13
3 22
3 1
3 15
3 18
3 10
3 15
1 16 19 883
1 8 23 212
3 5
3 13
2 6
3 15
1 5 18 914
2 17
3 20
1 23 23 56
3 13
2 25
3 13
3 13
3 10
2 16
1 17 22 308
3 19
3 17
3 7

出力例 2

542
467
467
619
344
541
338
619
452
721
592
729
542
592
970
619
592
747
914
914
914
914
338
983
914

Score: 625 points

Problem Statement

You are given an integer sequence A=(A_1,A_2,\ldots,A_N) of length N.

Process Q operations in order. There are three types of operations:

  • A type-1 operation is represented by a triple of integers (l,r,x), which corresponds to replacing A_i with \max\lbrace A_i,x\rbrace for each i=l,l+1,\ldots,r.
  • A type-2 operation is represented by an integer i, which corresponds to canceling the i-th operation (it is guaranteed that the i-th operation is of type 1 and has not already been canceled). The new sequence A can be obtained by performing all type-1 operations that have not been canceled, starting from the initial state.
  • A type-3 operation is represented by an integer i, which corresponds to printing the current value of A_i.

Constraints

  • 1\leq N\leq2\times10^5
  • 1\leq A_i\leq10^9\ (1\leq i\leq N)
  • 1\leq Q\leq2\times10^5
  • In a type-1 operation, 1\leq l\leq r\leq N and 1\leq x\leq10^9.
  • In a type-2 operation, i is not greater than the number of operations given before, and 1\leq i.
  • In a type-2 operation, the i-th operation is of type 1.
  • In type-2 operations, the same i does not appear multiple times.
  • In a type-3 operation, 1\leq i\leq 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
Q
\operatorname{query}_1
\operatorname{query}_2
\vdots
\operatorname{query}_Q

Here, \operatorname{query}_k\ (1\leq k\leq Q) represents the k-th operation, and depending on the type of the k-th operation, one of the following is given.

For a type-1 operation, the following is given, meaning that the k-th operation is a type-1 operation represented by (l,r,x):

1 l r x

For a type-2 operation, the following is given, meaning that the k-th operation is a type-2 operation represented by i:

2 i

For a type-3 operation, the following is given, meaning that the k-th operation is a type-3 operation represented by i:

3 i

Output

Let q be the number of type-3 operations. Print q lines. The i-th line (1\leq i\leq q) should contain the value that should be printed for the i-th given type-3 operation.


Sample Input 1

6
2 7 1 8 2 8
15
3 1
3 3
3 4
1 1 5 4
3 1
3 3
3 4
1 3 6 9
3 1
3 3
3 4
2 4
3 1
3 3
3 4

Sample Output 1

2
1
8
4
4
8
4
9
9
2
9
9

Initially, the sequence A is (2,7,1,8,2,8).

For the 1-st, 2-nd, 3-rd operations, print the values of A_1, A_3, A_4, which are 2,1,8, respectively.

The 4-th operation replaces the values of A_1, A_2, A_3, A_4, A_5 with \max\lbrace A_i,4\rbrace. Just after this operation, A is (4,7,4,8,4,8).

For the 5-th, 6-th, 7-th operations, print the values of A_1, A_3, A_4 at this point, which are 4,4,8, respectively.

The 8-th operation replaces the values of A_3, A_4, A_5, A_6 with \max\lbrace A_i,9\rbrace. Just after this operation, A is (4,7,9,9,9,9).

For the 9-th, 10-th, 11-th operations, print the values of A_1, A_3, A_4 at this point, which are 4,9,9, respectively.

The 12-th operation cancels the 4-th operation. Just after this operation, A is (2,7,9,9,9,9).

For the 13-th, 14-th, 15-th operations, print the values of A_1, A_3, A_4 at this point, which are 2,9,9, respectively.


Sample Input 2

24
721 78 541 256 970 478 370 467 344 542 43 166 619 17 592 222 983 729 338 747 62 452 815 838
35
3 10
3 8
3 8
3 13
3 9
1 1 17 251
3 3
3 19
3 13
3 22
3 1
3 15
3 18
3 10
3 15
1 16 19 883
1 8 23 212
3 5
3 13
2 6
3 15
1 5 18 914
2 17
3 20
1 23 23 56
3 13
2 25
3 13
3 13
3 10
2 16
1 17 22 308
3 19
3 17
3 7

Sample Output 2

542
467
467
619
344
541
338
619
452
721
592
729
542
592
970
619
592
747
914
914
914
914
338
983
914