A - Takahashi san

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

配点 : 100

問題文

キーエンスでは、役割や年齢、立場の違いに関係なく「さん」付けして呼ぶという文化があります。 新入社員が社長を呼ぶときも「中田さん」と呼びます。

ある人の苗字と名前がそれぞれ文字列 S,T として与えられます。

苗字、スペース( )、敬称(san)をこの順に連結した文字列を出力してください。

制約

  • S,T は以下の各条件を満たす文字列
    • 長さ 1 以上 10 以下
    • 先頭の文字は英大文字
    • 先頭以外の文字は英小文字

入力

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

S T

出力

苗字、スペース( )、敬称(san)をこの順に連結した文字列を出力せよ。


入力例 1

Takahashi Chokudai

出力例 1

Takahashi san

苗字(Takahashi)、スペース( )、敬称(san)をこの順に連結した文字列を出力します。


入力例 2

K Eyence

出力例 2

K san

Score : 100 points

Problem Statement

Keyence has a culture of addressing everyone with the honorific "san," regardless of their role, age, or position. Even a new employee would call the president "Nakata-san." [Translator's note: this is a bit unusual in Japan.]

You are given a person's surname and first name as strings S and T, respectively.

Print the concatenation of the surname, a space ( ), and the honorific (san) in this order.

Constraints

  • Each of S and T is a string that satisfies the following conditions.
    • The length is between 1 and 10, inclusive.
    • The first character is an uppercase English letter.
    • All characters except the first one are lowercase English letters.

Input

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

S T

Output

Print the concatenation of the surname, a space ( ), and the honorific (san) in this order.


Sample Input 1

Takahashi Chokudai

Sample Output 1

Takahashi san

Print the concatenation of the surname (Takahashi), a space ( ), and the honorific (san) in this order.


Sample Input 2

K Eyence

Sample Output 2

K san
B - Gothec

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

配点 : 100

問題文

以下の 5 つの日を五節句と呼びます。

  • 1\color{red}{\mathbf{7}}
  • 33
  • 55
  • 77
  • 99

MD 日が五節句に含まれるならば Yes を、含まれないならば No を出力してください。

制約

  • M, D は整数
  • MD 日はグレゴリオ暦における閏年 (うるうどし) の日付として正しい。

入力

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

M D

出力

MD 日が五節句に含まれるならば Yes を、含まれないならば No を出力せよ。


入力例 1

3 3

出力例 1

Yes

33 日は五節句に含まれるので、Yes を出力します。


入力例 2

1 1

出力例 2

No

11 日は五節句に含まれないので、No を出力します。


入力例 3

4 4

出力例 3

No

入力例 4

11 7

出力例 4

No

Score : 100 points

Problem Statement

The following five days are called the five seasonal festivals (gosekku).

  • January \color{red}{\mathbf{7}}
  • March 3
  • May 5
  • July 7
  • September 9

If month M, day D is one of the five seasonal festivals, output Yes; otherwise, output No.

Constraints

  • M and D are integers.
  • Month M, day D is a valid date in a leap year in the Gregorian calendar.

Input

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

M D

Output

If month M, day D is one of the five seasonal festivals, output Yes; otherwise, output No.


Sample Input 1

3 3

Sample Output 1

Yes

March 3 is one of the five seasonal festivals, so output Yes.


Sample Input 2

1 1

Sample Output 2

No

January 1 is not one of the five seasonal festivals, so output No.


Sample Input 3

4 4

Sample Output 3

No

Sample Input 4

11 7

Sample Output 4

No
C - Foreign Exchange

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

配点 : 150

問題文

1 から N までの番号がつけられた N 個の国があり、i = 1, 2, \ldots, N について、高橋君は国 i の通貨を A_i 単位持っています。

高橋君は、下記の操作を好きな回数( 0 回でも良い)繰り返します。

  • まず、1 以上 N-1 以下の整数 i を選ぶ。
  • その後、国 i の通貨を S_i 単位以上持っているなら、下記の行動を 1 回行う。
    • i の通貨を S_i 単位だけ支払い、国 (i+1) の通貨を T_i 単位だけ獲得する。

最終的に高橋君が持っている国 N の通貨の単位数としてあり得る最大値を出力してください。

制約

  • 入力される値はすべて整数
  • 2 \leq N \leq 2 \times 10^5
  • 0 \leq A_i \leq 10^9
  • 1 \leq T_i \leq S_i \leq 10^9

入力

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

N
A_1 A_2 \ldots A_N
S_1 T_1
S_2 T_2
\vdots
S_{N-1} T_{N-1}

出力

答えを出力せよ。


入力例 1

4
5 7 0 3
2 2
4 3
5 2

出力例 1

5

以下の説明では、高橋君が持っている各国の通貨の単位数を、数列 A = (A_1, A_2, A_3, A_4) として表します。はじめ、A = (5, 7, 0, 3) です。

下記の通りに 4 回操作を行うことを考えます。

  • i = 2 を選び、国 2 の通貨 4 単位を支払って、国 3 の通貨 3 単位を獲得する。その結果、A = (5, 3, 3, 3) となる。
  • i = 1 を選び、国 1 の通貨 2 単位を支払って、国 2 の通貨 2 単位を獲得する。その結果、A = (3, 5, 3, 3) となる。
  • i = 2 を選び、国 2 の通貨 4 単位を支払って、国 3 の通貨 3 単位を獲得する。その結果、A = (3, 1, 6, 3) となる。
  • i = 3 を選び、国 3 の通貨 5 単位を支払って、国 4 の通貨 2 単位を獲得する。その結果、A = (3, 1, 1, 5) となる。

このとき、最終的に高橋君が持っている国 4 の通貨の単位数は 5 であり、これが考えられる最大値です。


入力例 2

10
32 6 46 9 37 8 33 14 31 5
5 5
3 1
4 3
2 2
3 2
3 2
4 4
3 3
3 1

出力例 2

45

Score: 150 points

Problem Statement

There are N countries numbered 1 to N. For each i = 1, 2, \ldots, N, Takahashi has A_i units of the currency of country i.

Takahashi can repeat the following operation any number of times, possibly zero:

  • First, choose an integer i between 1 and N-1, inclusive.
  • Then, if Takahashi has at least S_i units of the currency of country i, he performs the following action once:
    • Pay S_i units of the currency of country i and gain T_i units of the currency of country (i+1).

Print the maximum possible number of units of the currency of country N that Takahashi could have in the end.

Constraints

  • All input values are integers.
  • 2 \leq N \leq 2 \times 10^5
  • 0 \leq A_i \leq 10^9
  • 1 \leq T_i \leq S_i \leq 10^9

Input

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

N
A_1 A_2 \ldots A_N
S_1 T_1
S_2 T_2
\vdots
S_{N-1} T_{N-1}

Output

Print the answer.


Sample Input 1

4
5 7 0 3
2 2
4 3
5 2

Sample Output 1

5

In the following explanation, let the sequence A = (A_1, A_2, A_3, A_4) represent the numbers of units of the currencies of the countries Takahashi has. Initially, A = (5, 7, 0, 3).

Consider performing the operation four times as follows:

  • Choose i = 2, pay four units of the currency of country 2, and gain three units of the currency of country 3. Now, A = (5, 3, 3, 3).
  • Choose i = 1, pay two units of the currency of country 1, and gain two units of the currency of country 2. Now, A = (3, 5, 3, 3).
  • Choose i = 2, pay four units of the currency of country 2, and gain three units of the currency of country 3. Now, A = (3, 1, 6, 3).
  • Choose i = 3, pay five units of the currency of country 3, and gain two units of the currency of country 4. Now, A = (3, 1, 1, 5).

At this point, Takahashi has five units of the currency of country 4, which is the maximum possible number.


Sample Input 2

10
32 6 46 9 37 8 33 14 31 5
5 5
3 1
4 3
2 2
3 2
3 2
4 4
3 3
3 1

Sample Output 2

45
D - Daily Cookie 2

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

配点 : 200

問題文

A 問題と似た設定の問題です。A 問題とは、高橋君が食べるクッキーの選び方および求めるものが異なります。

N 個の箱が横一列に並んでおり、そのうちのいくつかの箱にはクッキーが入っています。

各箱の状態は長さ N の文字列 S によって表されます。 具体的には、左から i\ (1\leq i\leq N) 番目の箱は、Si 文字目が @ のときクッキーが 1 枚入っており、. のとき空き箱です。

高橋君は今からの D 日間、一日一回ずつ、その時点でクッキーが入っている箱のうち最も右にある箱のクッキーを選んで食べます。

N 個の箱それぞれについて、D 日間が経過した後にその箱にクッキーが入っているかを求めてください。

なお、S には @D 個以上含まれることが保証されます。

制約

  • 1\leq D \leq N \leq 100
  • N,D は整数
  • S@. からなる長さ N の文字列
  • S には @D 個以上含まれる

入力

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

N D
S

出力

長さ N の文字列を出力せよ。 出力する文字列の i\ (1\leq i\leq N) 文字目は、D 日間が経過した後に左から i 番目の箱にクッキーが入っているならば @、入っていないならば . とせよ。


入力例 1

5 2
.@@.@

出力例 1

.@...

高橋君は以下のように行動します。

  • 1 日目:左から 2,3,5 番目の箱にクッキーが入っている。このうちで最も右にある、左から 5 番目の箱に入っているクッキーを選んで食べる。
  • 2 日目:左から 2,3 番目の箱にクッキーが入っている。このうちで最も右にある、左から 3 番目の箱に入っているクッキーを選んで食べる。
  • 2 日間が経過した後、左から 2 番目の箱にのみクッキーが入っている。

よって、正しい出力は .@... です。


入力例 2

3 3
@@@

出力例 2

...

入力例 3

10 4
@@@.@@.@@.

出力例 3

@@@.......

Score: 200 points

Problem Statement

This problem shares a similar setting with Problem A. The way Takahashi chooses cookies and what you are required to find are different from Problem A.

There are N boxes arranged in a row, and some of these boxes contain cookies.

The state of these boxes is represented by a string S of length N. Specifically, the i-th box (1\leq i \leq N) from the left contains one cookie if the i-th character of S is @, and is empty if it is ..

Over the next D days, Takahashi will choose and eat one cookie per day from among the cookies in these boxes. On each day, he chooses the cookie in the rightmost box that contains a cookie at that point.

Determine, for each of the N boxes, whether it will contain a cookie after D days have passed.

It is guaranteed that S contains at least D occurrences of @.

Constraints

  • 1 \leq D \leq N \leq 100
  • N and D are integers.
  • S is a string of length N consisting of @ and ..
  • S contains at least D occurrences of @.

Input

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

N D
S

Output

Print a string of length N. The i-th character (1 \leq i \leq N) of the string should be @ if the i-th box from the left contains a cookie after D days have passed, and . otherwise.


Sample Input 1

5 2
.@@.@

Sample Output 1

.@...

Takahashi acts as follows:

  • Day 1: There are cookies in the 2nd, 3rd, and 5th boxes from the left. Among these, the rightmost is the 5th box. He eats the cookie in this box.
  • Day 2: There are cookies in the 2nd and 3rd boxes. Among these, the rightmost is the 3rd box. He eats the cookie in this box.
  • After two days have passed, only the 2nd box from the left contains a cookie.

Therefore, the correct output is .@....


Sample Input 2

3 3
@@@

Sample Output 2

...

Sample Input 3

10 4
@@@.@@.@@.

Sample Output 3

@@@.......
E - Puddles

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

配点 : 300

問題文

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

白マスからなる四方位に連結な領域のうち、黒マスに囲まれたものの個数を求めてください。

より厳密には次の通りです。

上から i 行目左から j 列目のマスをマス (i,j) と表します。
2 つのマス (i,j),(i',j') が隣接しているとは、|i-i'|+|j-j'|=1 であることと定めます。
白マスの集合 C が連結であるとは、C に属するどの 2 マス c,c' に対しても、C に属する隣接するマスへの移動を繰り返すことで c から c' へ移動できることと定めます。
空でない白マスの連結な集合であって、極大なものを白マスの連結成分と定めます。
白マスの連結成分であって、グリッドの最外周(すなわち、 1 行目、 H 行目、 1 列目、 W 行目)のマスを含まないものの個数を求めてください。

制約

  • 3 \leq H,W \leq 10^3
  • H,W は整数
  • S_{i,j}#.

入力

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

H W
S_{1,1}S_{1,2}\dots S_{1,W}
\vdots
S_{H,1}S_{H,2}\dots S_{H,W}

出力

答えを出力せよ。


入力例 1

5 15
##########..###
#...#######.###
####....###..##
######.########
########....###

出力例 1

2

上から 2 行目左から 2,3,4 列目の 3 マスからなる領域と、上から 3 行目左から 5,6,7,8 列目及び上から 4 行目左から 7 列目の計 5 マスからなる領域の 2 個です。


入力例 2

10 22
######################
####.#################
###...################
##.###.##.....########
##.....##.####.#######
.######.#......#.....#
.######.#.####.#.#####
#########.....##.#####
################.#####
################.....#

出力例 2

4

Score : 300 points

Problem Statement

There is a grid with H rows and W 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 S_{i,j} is ..

Among the four-directionally connected regions consisting of white cells, find the number of those that are surrounded by black cells.

Below is a more formal statement.

We denote the cell at the i-th row from the top and j-th column from the left as cell (i, j).
Two cells (i, j) and (i', j') are said to be adjacent if and only if |i-i'|+|j-j'|=1.
A set C of white cells is said to be connected if and only if, for any two cells c and c' in C, it is possible to move from c to c' by repeatedly moving to an adjacent cell in C.
A non-empty connected set of white cells that is maximal is called a connected component of white cells.
Find the number of connected components of white cells that do not contain any cell on the outermost border of the grid (that is, in row 1, row H, column 1, or column W).

Constraints

  • 3 \leq H, W \leq 10^3
  • H and W are integers.
  • S_{i,j} is # or ..

Input

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

H W
S_{1,1}S_{1,2}\dots S_{1,W}
\vdots
S_{H,1}S_{H,2}\dots S_{H,W}

Output

Output the answer.


Sample Input 1

5 15
##########..###
#...#######.###
####....###..##
######.########
########....###

Sample Output 1

2

There are two such regions: the region consisting of the three cells in row 2 from the top and columns 2, 3, 4 from the left, and the region consisting of a total of five cells: columns 5, 6, 7, 8 from the left in row 3 from the top and column 7 from the left in row 4 from the top.


Sample Input 2

10 22
######################
####.#################
###...################
##.###.##.....########
##.....##.####.#######
.######.#......#.....#
.######.#.####.#.#####
#########.....##.#####
################.#####
################.....#

Sample Output 2

4
F - digitnum

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

配点 : 300

問題文

整数 N が与えられるので、以下の問題を解いてください。

f(x)= ( x 以下の正整数で、 x と桁数が同じものの数) とします。
f(1)+f(2)+\dots+f(N)998244353 で割った余りを求めてください。

制約

  • N は整数
  • 1 \le N < 10^{18}

入力

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

N

出力

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


入力例 1

16

出力例 1

73
  • 1 以上 9 以下の正整数 x について、 x 以下の整数で、 x と桁数が同じものは 1,2,\dots,x です。
    • これより、 f(1)=1,f(2)=2,...,f(9)=9 となります。
  • 10 以上 16 以下の正整数 x について、 x 以下の整数で、 x と桁数が同じものは 10,11,\dots,x です。
    • これより、 f(10)=1,f(11)=2,...,f(16)=7 となります。

結局、求める答えは 73 です。


入力例 2

238

出力例 2

13870

入力例 3

999999999999999999

出力例 3

762062362

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

Score : 300 points

Problem Statement

Given an integer N, solve the following problem.

Let f(x)= (The number of positive integers at most x with the same number of digits as x).
Find f(1)+f(2)+\dots+f(N) modulo 998244353.

Constraints

  • N is an integer.
  • 1 \le N < 10^{18}

Input

Input is given from Standard Input in the following format:

N

Output

Print the answer as an integer.


Sample Input 1

16

Sample Output 1

73
  • For a positive integer x between 1 and 9, the positive integers at most x with the same number of digits as x are 1,2,\dots,x.
    • Thus, we have f(1)=1,f(2)=2,...,f(9)=9.
  • For a positive integer x between 10 and 16, the positive integers at most x with the same number of digits as x are 10,11,\dots,x.
    • Thus, we have f(10)=1,f(11)=2,...,f(16)=7.

The final answer is 73.


Sample Input 2

238

Sample Output 2

13870

Sample Input 3

999999999999999999

Sample Output 3

762062362

Be sure to find the sum modulo 998244353.

G - 2-variable Function

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

配点 : 400

問題文

整数 N が与えられるので、以下の条件を全て満たす最小の整数 X を求めてください。

  • XN 以上である。
  • 非負整数 (a,b) の組であって、 X=a^3+a^2b+ab^2+b^3 を満たすようなものが存在する。

制約

  • N は整数
  • 0 \le N \le 10^{18}

入力

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

N

出力

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


入力例 1

9

出力例 1

15

9 \le X \le 14 であるようなどの整数 X についても、問題文中の条件を満たすような (a,b) は存在しません。
X=15(a,b)=(2,1) とすると問題文中の条件を満たします。


入力例 2

0

出力例 2

0

N 自身が条件を満たすこともあります。


入力例 3

999999999989449206

出力例 3

1000000000000000000

入出力が 32bit 整数型に収まらない場合があります。

Score : 400 points

Problem Statement

Given an integer N, find the smallest integer X that satisfies all of the conditions below.

  • X is greater than or equal to N.
  • There is a pair of non-negative integers (a, b) such that X=a^3+a^2b+ab^2+b^3.

Constraints

  • N is an integer.
  • 0 \le N \le 10^{18}

Input

Input is given from Standard Input in the following format:

N

Output

Print the answer as an integer.


Sample Input 1

9

Sample Output 1

15

For any integer X such that 9 \le X \le 14, there is no (a, b) that satisfies the condition in the statement.
For X=15, (a,b)=(2,1) satisfies the condition.


Sample Input 2

0

Sample Output 2

0

N itself may satisfy the condition.


Sample Input 3

999999999989449206

Sample Output 3

1000000000000000000

Input and output may not fit into a 32-bit integer type.

H - Clamp

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

配点 : 450

問題文

長さ N の整数列 A=(A_1, A_2, \dots, A_N) が与えられます。

Q 個のクエリが与えられるので、順に処理してください。 各クエリは以下のいずれかの形式です。

  • 1 x y : A_x の値を y に変更する。
  • 2 l r : \displaystyle \sum_{1\leq i\leq N} \max(l, \min(r, A_i)) の値を求める。

制約

  • 1\leq N \leq 5\times 10^5
  • 1\leq Q \leq 2\times 10^5
  • 0\leq A_i \leq 5\times 10^5
  • 1 種類目のクエリについて、
    • 1\leq x\leq N
    • 0\leq y \leq 5\times 10^5
  • 2 種類目のクエリについて、
    • 0\leq l,r \leq 5\times 10^5
  • 入力は全て整数

入力

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

N Q
A_1 A_2 \dots A_N
\text{query}_1
\text{query}_2
\vdots
\text{query}_Q

ここで、\text{query}_i\ (1\leq i\leq Q)i 番目のクエリを表し、以下のいずれかの形式で与えられる。

1 x y
2 l r

出力

2 種類目のクエリの個数を K として、K 行出力せよ。 i 行目 (1\leq i \leq K) には、2 種類目のクエリのうち i 個目のものに対する答えを出力せよ。


入力例 1

3 4
4 3 2
1 1 7
2 3 5
1 2 0
2 4 2

出力例 1

11
12

はじめ、A=(4,3,2) です。

  • 1 番目のクエリ:A_1 の値を 7 に変更します。A=(7,3,2) となります。
  • 2 番目のクエリ:\max(3, \min(5, 7))+\max(3, \min(5, 3))+\max(3, \min(5, 2))=5+3+3=11 を出力します。
  • 3 番目のクエリ:A_2 の値を 0 に変更します。A=(7,0,2) となります。
  • 4 番目のクエリ:\max(4, \min(2, 7))+\max(4, \min(2, 0))+\max(4, \min(2, 2))=4+4+4=12 を出力します。

入力例 2

8 10
320 578 244 604 145 839 156 857
2 400 556
1 5 168
2 254 62
2 145 301
1 1 23
1 3 0
2 413 758
2 297 613
1 8 451
2 598 692

出力例 2

3824
2032
2073
4350
3596
4884

Score : 450 points

Problem Statement

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

You are given Q queries, which you should process in order. Each query is in one of the following formats:

  • 1 x y : Change the value of A_x to y.
  • 2 l r : Find the value of \displaystyle \sum_{1\leq i\leq N} \max(l, \min(r, A_i)).

Constraints

  • 1\leq N \leq 5\times 10^5
  • 1\leq Q \leq 2\times 10^5
  • 0\leq A_i \leq 5\times 10^5
  • For queries of the first type,
    • 1\leq x\leq N
    • 0\leq y \leq 5\times 10^5
  • For queries of the second type,
    • 0\leq l,r \leq 5\times 10^5
  • All inputs are integers.

Input

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

N Q
A_1 A_2 \dots A_N
\text{query}_1
\text{query}_2
\vdots
\text{query}_Q

Here, \text{query}_i\ (1\leq i\leq Q) represents the i-th query and is given in one of the following formats:

1 x y
2 l r

Output

Let K be the number of queries of the second type. Output K lines. The i-th line (1\leq i \leq K) should contain the answer to the i-th query of the second type.


Sample Input 1

3 4
4 3 2
1 1 7
2 3 5
1 2 0
2 4 2

Sample Output 1

11
12

Initially, A=(4,3,2).

  • First query: Change the value of A_1 to 7. A becomes (7,3,2).
  • Second query: Output \max(3, \min(5, 7))+\max(3, \min(5, 3))+\max(3, \min(5, 2))=5+3+3=11.
  • Third query: Change the value of A_2 to 0. A becomes (7,0,2).
  • Fourth query: Output \max(4, \min(2, 7))+\max(4, \min(2, 0))+\max(4, \min(2, 2))=4+4+4=12.

Sample Input 2

8 10
320 578 244 604 145 839 156 857
2 400 556
1 5 168
2 254 62
2 145 301
1 1 23
1 3 0
2 413 758
2 297 613
1 8 451
2 598 692

Sample Output 2

3824
2032
2073
4350
3596
4884
I - Adding Chords

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

配点 : 525

問題文

円周上に等間隔に N 個の点があり、時計回りに 1,2,\dots,N と番号がついています。

以下の形式のクエリが Q 個与えられるので順に処理してください。

  • A_i と点 B_i を結ぶ線分を書く。ただし、この線分が既に書かれている線分と交わる場合は書かない。

ここで、2Q 個の整数 A_1,\ldots,A_Q,B_1,\ldots,B_Q は相異なることが保証されます。

各線分が書かれたかどうか答えてください。

制約

  • 2 \leq N \leq 10^6
  • 1 \leq Q \leq 3\times 10^5
  • 1 \leq A_i < B_i \leq N
  • 2Q 個の整数 A_1,\ldots,A_Q,B_1,\ldots,B_Q は相異なる
  • 入力は全て整数

入力

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

N Q
A_1 B_1
A_2 B_2
\vdots
A_Q B_Q

出力

Q 行出力せよ。
i 行目には、i 番目のクエリにおいて線分が書かれたとき Yes、書かれなかったとき No と出力せよ。


入力例 1

8 3
1 5
2 7
3 4

出力例 1

Yes
No
Yes

クエリにより図のように線分が書かれます。

  • 1 番目のクエリで、点 1 と点 5 を結ぶ線分が書かれる。
  • 2 番目のクエリで、点 2 と点 7 を結ぶ線分は、1 番目のクエリで書いた線分と交わるので書かない。
  • 3 番目のクエリで、点 3 と点 4 を結ぶ線分が書かれる。


入力例 2

999999 4
123456 987654
888888 999999
1 3
2 777777

出力例 2

Yes
No
Yes
No

Score : 525 points

Problem Statement

There are N points equally spaced on a circle, numbered 1,2,\dots,N clockwise.

You are given Q queries of the following form; process them in order.

  • Draw the line segment connecting points A_i and B_i. However, if this segment intersects a segment that has already been drawn, do not draw it.

Here, it is guaranteed that the 2Q integers A_1,\ldots,A_Q,B_1,\ldots,B_Q are all distinct.

For each query, answer whether the segment was drawn.

Constraints

  • 2 \leq N \leq 10^6
  • 1 \leq Q \leq 3\times 10^5
  • 1 \leq A_i < B_i \leq N
  • The 2Q integers A_1,\ldots,A_Q,B_1,\ldots,B_Q are pairwise distinct.
  • All input values are integers.

Input

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

N Q
A_1 B_1
A_2 B_2
\vdots
A_Q B_Q

Output

Output Q lines. On the i-th line, output Yes if, in the i-th query, the segment was drawn, and No if it was not drawn.


Sample Input 1

8 3
1 5
2 7
3 4

Sample Output 1

Yes
No
Yes

By the queries, the segments are drawn as in the figure.

  • In the 1-st query, the segment connecting points 1 and 5 is drawn.
  • In the 2-nd query, the segment connecting points 2 and 7 is not drawn because it intersects the segment drawn in the 1-st query.
  • In the 3-rd query, the segment connecting points 3 and 4 is drawn.


Sample Input 2

999999 4
123456 987654
888888 999999
1 3
2 777777

Sample Output 2

Yes
No
Yes
No