A - Content Too Large

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

配点 : 100 点

問題文

高橋くんは、N 個の品物と 1 つのカバンを持っています。

i 番目 (1\le i\le N) の品物の大きさは A _ i で、カバンの大きさは M です。

カバンに入れようとしている品物の大きさの合計が M 以下のとき、かつそのときに限り、それらの品物をすべて同時にカバンに入れることができます。

高橋くんが N 個の品物すべてを同時にカバンに入れることができるなら Yes 、そうでなければ No と出力してください。

制約

  • 1\le N\le100
  • 1\le M\le10000
  • 1\le A _ i\le100\ (1\le i\le N)
  • 入力はすべて整数

入力

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

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

出力

高橋くんがすべての品物を同時にカバンに入れられるなら Yes を、そうでなければ No を出力せよ。


入力例 1

5 15
3 1 4 1 5

出力例 1

Yes

5 つの品物の大きさの合計は 3+1+4+1+5=14 です。 これは、カバンの大きさ 15 以下なので、高橋くんはすべての品物を同時にカバンに入れることができます。 なので、Yes を出力してください。


入力例 2

5 5
3 1 4 1 5

出力例 2

No

5 つの品物の大きさの合計は 14 で、カバンの大きさ 5 より大きいため、高橋くんはすべての品物を同時にカバンに入れることができません。 なので、No を出力してください。


入力例 3

1 10000
100

出力例 3

Yes

Score : 100 points

Problem Statement

Takahashi has N items and one bag.

The size of the i-th (1\le i\le N) item is A_i, and the size of the bag is M.

If and only if the total size of the items he is trying to put in the bag is at most M, he can put all those items in the bag simultaneously.

If he can put all N items in the bag simultaneously, print Yes; otherwise, print No.

Constraints

  • 1\le N\le100
  • 1\le M\le10000
  • 1\le A_i\le100\ (1\le i\le N)
  • All input values are integers.

Input

The input is given from standard input in the following format:

N M
A_1 A_2 \ldots A_N

Output

If Takahashi can put all items in the bag simultaneously, print Yes; otherwise, print No.


Sample Input 1

5 15
3 1 4 1 5

Sample Output 1

Yes

The total size of the 5 items is 3+1+4+1+5=14. Since this is not greater than the bag size 15, Takahashi can put all items in the bag simultaneously. Thus, print Yes.


Sample Input 2

5 5
3 1 4 1 5

Sample Output 2

No

The total size of the 5 items is 14, which is greater than the bag size 5, so he cannot put all items in the bag simultaneously. Thus, print No.


Sample Input 3

1 10000
100

Sample Output 3

Yes
B - New Scheme

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

配点 : 100 点

問題文

8 個の整数 S_1,S_2,\dots,S_8 が与えられます。 以下の 3 つの条件が全て満たされるならば Yes を、そうでないならば No を出力してください。

  • 数列 (S_1,S_2,\dots,S_8) は広義単調増加である。すなわち、S_1 \leq S_2 \leq \dots \leq S_8 である。
  • S_1,S_2,\dots,S_8 は全て 100 以上 675 以下である。
  • S_1,S_2,\dots,S_8 は全て 25 の倍数である。

制約

  • 0\leq S_i \leq 1000
  • 入力は全て整数

入力

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

S_1 S_2 \dots S_8

出力

答えを出力せよ。


入力例 1

125 175 250 300 400 525 600 650

出力例 1

Yes

3 つの条件を全て満たしています。


入力例 2

100 250 300 400 325 575 625 675

出力例 2

No

S_4 > S_5 であるため、1 つ目の条件を満たしていません。


入力例 3

0 23 24 145 301 413 631 632

出力例 3

No

2 つ目の条件と 3 つ目の条件を満たしていません。

Score : 100 points

Problem Statement

Given eight integers S_1,S_2,\dots, and S_8, print Yes if they satisfy all of the following three conditions, and No otherwise.

  • The sequence (S_1,S_2,\dots,S_8) is monotonically non-decreasing. In other words, S_1 \leq S_2 \leq \dots \leq S_8.
  • S_1,S_2,\dots, and S_8 are all between 100 and 675, inclusive.
  • S_1,S_2,\dots, and S_8 are all multiples of 25.

Constraints

  • 0\leq S_i \leq 1000
  • All input values are integers.

Input

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

S_1 S_2 \dots S_8

Output

Print the answer.


Sample Input 1

125 175 250 300 400 525 600 650

Sample Output 1

Yes

They satisfy all of the three conditions.


Sample Input 2

100 250 300 400 325 575 625 675

Sample Output 2

No

They violate the first condition because S_4 > S_5.


Sample Input 3

0 23 24 145 301 413 631 632

Sample Output 3

No

They violate the second and third conditions.

C - Substring

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

配点 : 200 点

問題文

英小文字からなる文字列 S が与えられます。S の空でない部分文字列は何種類ありますか?

ただし、部分文字列とは連続する部分列のことを指します。例えば、xxx は yxxxy の部分文字列ですが、xxyxx の部分文字列ではありません。

制約

  • S は英小文字からなる長さ 1 以上 100 以下の文字列

入力

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

S

出力

答えを出力せよ。


入力例 1

yay

出力例 1

5

S の空でない部分文字列は以下の 5 種類です。

  • a
  • y
  • ay
  • ya
  • yay

入力例 2

aababc

出力例 2

17

入力例 3

abracadabra

出力例 3

54

Score: 200 points

Problem Statement

You are given a string S consisting of lowercase English letters. How many different non-empty substrings does S have?

A substring is a contiguous subsequence. For example, xxx is a substring of yxxxy but not of xxyxx.

Constraints

  • S is a string of length between 1 and 100, inclusive, consisting of lowercase English letters.

Input

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

S

Output

Print the answer.


Sample Input 1

yay

Sample Output 1

5

S has the following five different non-empty substrings:

  • a
  • y
  • ay
  • ya
  • yay

Sample Input 2

aababc

Sample Output 2

17

Sample Input 3

abracadabra

Sample Output 3

54
D - Most Minority

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

配点 : 200 点

問題文

人 1,2,\dots,N ( N は奇数 ) が、 M 回の 0 か 1 かを選択する投票を行いました。
各人の各回の投票は N 個の長さ M の 0, 1 からなる文字列 S_1,S_2,\dots,S_N として与えられ、 S_i の j 文字目は人 i の j 回目の投票への内容を表します。

各回の投票で、少数派であった人は 1 点を得ます。
より厳密には、次のルールで得点が与えられます。

  • その回の投票で 0 を選択した人が x 人、 1 を選択した人が y 人いたとします。
    • x=0 または y=0 である場合、その投票では全員に 1 点が与えられる。
    • そうでなく x<y である場合、その投票で 0 に投票した人のみに 1 点が与えられる。
    • そうでない場合、その投票で 1 に投票した人のみに 1 点が与えられる。
    • なお、 N が奇数であることから x=y となることはないことに留意してください。

M 回の投票を終えた後、それらの投票における合計の得点が最も高い人を全員求めてください。

制約

  • N は 1 \le N \le 99 を満たす 奇数
  • M は 1 \le M \le 100 を満たす整数
  • S_i は長さ M の 0, 1 からなる文字列

入力

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

N M
S_1
S_2
\vdots
S_N

出力

得点が最も高い人の番号を全て、 番号の昇順に 空白区切りで出力せよ。


入力例 1

3 5
11100
10101
01110

出力例 1

2 3

このケースでは、 3 人が 5 回の投票を行いました。

  • 1 回目の投票では人 1 が 1 、人 2 が 1 、人 3 が 0 に投票しました。よって、人 3 のみが 1 点を得ます。
  • 2 回目の投票では人 1 が 1 、人 2 が 0 、人 3 が 1 に投票しました。よって、人 2 のみが 1 点を得ます。
  • 3 回目の投票では人 1 が 1 、人 2 が 1 、人 3 が 1 に投票しました。よって、全員が 1 点を得ます。
  • 4 回目の投票では人 1 が 0 、人 2 が 0 、人 3 が 1 に投票しました。よって、人 3 のみが 1 点を得ます。
  • 5 回目の投票では人 1 が 0 、人 2 が 1 、人 3 が 0 に投票しました。よって、人 2 のみが 1 点を得ます。

この結果、人 1 は合計 1 点、人 2 は合計 3 点、人 3 は合計 3 点を得ました。
よって、人 2,3 が合計の得点が最も高い人です。これらを番号の昇順に出力してください。


入力例 2

5 4
0000
0000
0000
0000
0000

出力例 2

1 2 3 4 5

入力例 3

7 8
11010011
01000000
01111100
10111000
10011110
10100101
10010110

出力例 3

1 2 3

Score : 200 points

Problem Statement

People 1,2,\dots,N (where N is odd) conducted M votes where each person chooses either 0 or 1.
Each person's vote for each round is given as N strings S_1,S_2,\dots,S_N of length M consisting of 0 and 1, where the j-th character of S_i represents person i's vote content for the j-th vote.

In each vote, people who were in the minority receive 1 point.
More precisely, points are given according to the following rules:

  • Suppose x people chose 0 and y people chose 1 in that vote.
    • If x=0 or y=0, everyone receives 1 point for that vote.
    • Otherwise, if x<y, only people who voted 0 in that vote receive 1 point.
    • Otherwise, only people who voted 1 in that vote receive 1 point.
    • Note that since N is odd, x=y never occurs.

After finishing M votes, find all people who have the highest total score from those votes.

Constraints

  • N is an odd number satisfying 1 \le N \le 99.
  • M is an integer satisfying 1 \le M \le 100.
  • S_i is a string of length M consisting of 0 and 1.

Input

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

N M
S_1
S_2
\vdots
S_N

Output

Output all person numbers with the highest score in ascending order of person number, separated by spaces.


Sample Input 1

3 5
11100
10101
01110

Sample Output 1

2 3

In this case, three people conducted five votes.

  • In the 1st vote, person 1 voted 1, person 2 voted 1, person 3 voted 0. Thus, only person 3 receives 1 point.
  • In the 2nd vote, person 1 voted 1, person 2 voted 0, person 3 voted 1. Thus, only person 2 receives 1 point.
  • In the 3rd vote, person 1 voted 1, person 2 voted 1, person 3 voted 1. Thus, everyone receives 1 point.
  • In the 4th vote, person 1 voted 0, person 2 voted 0, person 3 voted 1. Thus, only person 3 receives 1 point.
  • In the 5th vote, person 1 voted 0, person 2 voted 1, person 3 voted 0. Thus, only person 2 receives 1 point.

As a result, person 1 received a total of 1 points, person 2 received a total of 3 points, and person 3 received a total of 3 points.
Therefore, persons 2 and 3 have the highest total score. Output these in ascending order of person number.


Sample Input 2

5 4
0000
0000
0000
0000
0000

Sample Output 2

1 2 3 4 5

Sample Input 3

7 8
11010011
01000000
01111100
10111000
10011110
10100101
10010110

Sample Output 3

1 2 3
E - Coverage

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

配点 : 300 点

問題文

1 以上 N 以下の整数からなる集合が M 個あり、順に S_1, S_2, \dots, S_M と呼びます。
S_i は C_i 個の整数 a_{i, 1}, a_{i, 2}, \dots, a_{i, C_i} からなります。

M 個の集合から 1 個以上の集合を選ぶ方法は 2^M-1 通りあります。
このうち、次の条件を満たす選び方は何通りありますか?

  • 1 \leq x \leq N を満たす全ての整数 x に対して、選んだ集合の中に x を含む集合が少なくとも 1 個存在する。

制約

  • 1 \leq N \leq 10
  • 1 \leq M \leq 10
  • 1 \leq C_i \leq N
  • 1 \leq a_{i,1} \lt a_{i,2} \lt \dots \lt a_{i,C_i} \leq N
  • 入力される値は全て整数

入力

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

N M
C_1
a_{1,1} a_{1,2} \dots a_{1,C_1}
C_2
a_{2,1} a_{2,2} \dots a_{2,C_2}
\vdots
C_M
a_{M,1} a_{M,2} \dots a_{M,C_M}

出力

問題文の条件を満たす集合の選び方の数を出力せよ。


入力例 1

3 3
2
1 2
2
1 3
1
2

出力例 1

3

入力で与えられている集合はそれぞれ S_1 = \lbrace 1, 2 \rbrace, S_2 = \lbrace 1, 3 \rbrace, S_3 = \lbrace 2 \rbrace です。
問題文の条件を満たす集合の選び方は次の 3 通りです。

  • S_1, S_2 を選ぶ。
  • S_1, S_2, S_3 を選ぶ。
  • S_2, S_3 を選ぶ。

入力例 2

4 2
2
1 2
2
1 3

出力例 2

0

問題文の条件を満たす選び方が存在しない場合もあります。


入力例 3

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

出力例 3

18

Score : 300 points

Problem Statement

There are M sets, called S_1, S_2, \dots, S_M, consisting of integers between 1 and N.
S_i consists of C_i integers a_{i, 1}, a_{i, 2}, \dots, a_{i, C_i}.

There are (2^M-1) ways to choose one or more sets from the M sets.
How many of them satisfy the following condition?

  • For all integers x such that 1 \leq x \leq N, there is at least one chosen set containing x.

Constraints

  • 1 \leq N \leq 10
  • 1 \leq M \leq 10
  • 1 \leq C_i \leq N
  • 1 \leq a_{i,1} \lt a_{i,2} \lt \dots \lt a_{i,C_i} \leq N
  • All values in the input are integers.

Input

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

N M
C_1
a_{1,1} a_{1,2} \dots a_{1,C_1}
C_2
a_{2,1} a_{2,2} \dots a_{2,C_2}
\vdots
C_M
a_{M,1} a_{M,2} \dots a_{M,C_M}

Output

Print the number of ways to choose sets that satisfy the conditions in the Problem Statement.


Sample Input 1

3 3
2
1 2
2
1 3
1
2

Sample Output 1

3

The sets given in the input are S_1 = \lbrace 1, 2 \rbrace, S_2 = \lbrace 1, 3 \rbrace, S_3 = \lbrace 2 \rbrace.
The following three ways satisfy the conditions in the Problem Statement:

  • choosing S_1, S_2;
  • choosing S_1, S_2, S_3;
  • choosing S_2, S_3.

Sample Input 2

4 2
2
1 2
2
1 3

Sample Output 2

0

There may be no way to choose sets that satisfies the conditions in the Problem Statement.


Sample Input 3

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

Sample Output 3

18
F - Separated Lunch

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

配点 : 300 点

問題文

キーエンス本社に勤務する人数が増えてきたので、本社に存在する部署を 2 つのグループに分け、昼休みの時間帯を分けることにしました。

キーエンス本社には N 個の部署が存在し、i 番目 (1\leq i\leq N) の部署に所属する人数は K_i 人です。

それぞれの部署をグループ A, B のいずれか一方に割り当て、グループごとに同時に昼休みをとり、 かつグループ A, B の昼休みの時間が重ならないようにしたとき、同時に昼休みをとる最大人数としてあり得る最小の値を求めてください。
すなわち、グループ A に割り当てられた部署に所属する人数の合計とグループ B に割り当てられた部署に所属する人数の合計 のうち大きい方の値としてあり得る最小の値を求めてください。

制約

  • 2\leq N \leq 20
  • 1\leq K_i \leq 10^8
  • 入力はすべて整数

入力

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

N
K_1 K_2 \ldots K_N

出力

同時に昼休みを取る最大人数としてあり得る最小の値を出力せよ。


入力例 1

5
2 3 5 10 12

出力例 1

17

1,2,5 番目の部署をグループ A に、3,4 番目の部署をグループ B に割り当てたとき、 グループ A に割り当てられた部署に所属する人数の合計は 2+3+12=17 、 グループ B に割り当てられた部署に所属する人数の合計は 5+10=15 となり、 このとき同時に昼休みを取る最大人数は 17 となります。

一方で、グループ A,B それぞれに割り当てられた部署に所属する人数の合計がいずれも 16 以下になるように 部署を割り当てることはできないため、17 を出力します。


入力例 2

2
1 1

出力例 2

1

同一人数の部署が複数存在する可能性もあります。


入力例 3

6
22 25 26 45 22 31

出力例 3

89

例えば、1,4,5 番目の部署をグループ A に、2,3,6 番目の部署をグループ B に割り当てたとき同時に昼休みを取る最大人数は 89 となります。

Score : 300 points

Problem Statement

As KEYENCE headquarters have more and more workers, they decided to divide the departments in the headquarters into two groups and stagger their lunch breaks.

KEYENCE headquarters have N departments, and the number of people in the i-th department (1\leq i\leq N) is K_i.

When assigning each department to Group A or Group B, having each group take lunch breaks at the same time, and ensuring that the lunch break times of Group A and Group B do not overlap, find the minimum possible value of the maximum number of people taking a lunch break at the same time.
In other words, find the minimum possible value of the larger of the following: the total number of people in departments assigned to Group A, and the total number of people in departments assigned to Group B.

Constraints

  • 2 \leq N \leq 20
  • 1 \leq K_i \leq 10^8
  • All input values are integers.

Input

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

N
K_1 K_2 \ldots K_N

Output

Print the minimum possible value of the maximum number of people taking a lunch break at the same time.


Sample Input 1

5
2 3 5 10 12

Sample Output 1

17

When assigning departments 1, 2, and 5 to Group A, and departments 3 and 4 to Group B, Group A has a total of 2+3+12=17 people, and Group B has a total of 5+10=15 people. Thus, the maximum number of people taking a lunch break at the same time is 17.

It is impossible to assign the departments so that both groups have 16 or fewer people, so print 17.


Sample Input 2

2
1 1

Sample Output 2

1

Multiple departments may have the same number of people.


Sample Input 3

6
22 25 26 45 22 31

Sample Output 3

89

For example, when assigning departments 1, 4, and 5 to Group A, and departments 2, 3, and 6 to Group B, the maximum number of people taking a lunch break at the same time is 89.

G - Ulam-Warburton Automaton

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

配点 : 425 点

問題文

H 行 W 列のマス目があります。上から i 行目 (1\leq i\leq H)、左から j 列目 (1\leq j\leq W) のマスをマス (i,j) と呼ぶことにします。

はじめ、マス (i,j) は S_{i,j} が # のとき黒、. のとき白で塗られています。

以下の操作を 10^{100} 回行います。

  • 白で塗られているマスであって、そのマスに辺で隣接するマスのうちちょうど 1 つが黒で塗られているようなマスの集合を T とする。T の各マスに対して、そのマスを黒で塗る。ただし、2 つのマス (i_1,j_1),(i_2,j_2) が辺で隣接するとは、 |i_1-i_2|+|j_1-j_2|=1 であることをいう。

すべての操作が終わったあとに黒く塗られているマスの個数を求めてください。

制約

  • 2\leq H,W
  • HW\leq 3\times 10^5
  • H,W は整数
  • S_{i,j} は # または .

入力

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

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

出力

答えを出力せよ。


入力例 1

9 9
.........
.........
.........
.........
....#....
.........
.........
.........
.........

出力例 1

57

操作によってマス目は以下のように変化します。(上の数字は操作回数を表しており、10 回目の操作後まで表示しています。)

最終的に黒く塗られたマスは 57 個です。


入力例 2

2 2
..
..

出力例 2

0

入力例 3

10 10
..........
....#.....
#.......#.
......#...
.......#..
.....#....
..........
..........
..#...#...
.......#..

出力例 3

64

Score : 425 points

Problem Statement

There is a grid with H rows and W columns. We call the cell at the i-th row from the top (1\leq i\leq H) and j-th column from the left (1\leq j\leq W) as cell (i,j).

Initially, cell (i,j) is colored black if S_{i,j} is # and white if it is ..

Perform the following operation 10^{100} times:

  • Let T be the set of cells that are colored white and have exactly one adjacent cell colored black. Color each cell in T black. Here, two cells (i_1,j_1) and (i_2,j_2) are adjacent if and only if |i_1-i_2|+|j_1-j_2|=1.

Find the number of cells that are colored black after all operations are completed.

Constraints

  • 2\leq H,W
  • HW\leq 3\times 10^5
  • 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}\ldots S_{1,W}
S_{2,1}S_{2,2}\ldots S_{2,W}
\vdots
S_{H,1}S_{H,2}\ldots S_{H,W}

Output

Output the answer.


Sample Input 1

9 9
.........
.........
.........
.........
....#....
.........
.........
.........
.........

Sample Output 1

57

The grid changes as follows through the operations. (The number above represents the operation count. The first ten operations are displayed.)

Eventually, 57 cells are colored black.


Sample Input 2

2 2
..
..

Sample Output 2

0

Sample Input 3

10 10
..........
....#.....
#.......#.
......#...
.......#..
.....#....
..........
..........
..#...#...
.......#..

Sample Output 3

64
H - Alternating String

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

配点 : 450 点

問題文

0 と 1 のみからなる文字列であって、文字列中のどの連続する 2 文字も異なるようなものを 良い文字列 とよびます。
0 と 1 のみからなる長さ N の文字列 S が与えられます。 Q 個のクエリが与えられるので、順に処理してください。
クエリは次の 2 種類です。

  • 1 L R : S の L 文字目から R 文字目までの 0 と 1 を反転させる。すなわち、L\leq i\leq R をみたす整数 i について、S の i 文字目が 0 ならば 1 に、1 ならば 0 に変更する。
  • 2 L R : S の L 文字目から R 文字目までを(順番を変えずに)抜き出した長さ (R-L+1) の文字列を S' とする。S' が良い文字列ならば Yes を、そうでないならば No を出力する。

制約

  • 1\leq N, Q\leq 5\times 10^5
  • S は 0 と 1 のみからなる長さ N の文字列
  • 1,2 種類目のクエリについて、1\leq L\leq R\leq N
  • 2 種類目のクエリが少なくとも 1 つ存在する。
  • N, Q, L, R は整数

入力

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

N Q
S
query_1
query_2
\vdots
query_Q

各クエリ query_i (1\leq i\leq Q) は、

1 L R 

または、

2 L R 

の形で与えられる。

出力

2 種類目のクエリの数を K 個として、K 行出力せよ。
i 行目には i 個目の 2 種類目のクエリに対する出力を出力せよ。


入力例 1

5 6
10100
2 1 3
2 1 5
1 1 4
2 1 5
1 3 3
2 2 4

出力例 1

Yes
No
Yes
No

最初、S=10100 です。このとき、クエリを与えられた順に処理すると以下のようになります。

  • 1 番目のクエリについて、S の 1 文字目から 3 文字目までを抜き出した文字列は S'=101 です。これは良い文字列なので Yes を出力します。
  • 2 番目のクエリについて、S の 1 文字目から 5 文字目までを抜き出した文字列は S'=10100 です。これは良い文字列でないので No を出力します。
  • 3 番目のクエリについて、S の 1 文字目から 4 文字目までの 0 と 1 を反転させます。文字列 S は S=01010 となります。
  • 4 番目のクエリについて、S の 1 文字目から 5 文字目までを抜き出した文字列は S'=01010 です。これは良い文字列なので Yes を出力します。
  • 5 番目のクエリについて、S の 3 文字目の 0 と 1 を反転させます。文字列 S は S=01110 となります。
  • 6 番目のクエリについて、S の 2 文字目から 4 文字目までを抜き出した文字列は S'=111 です。これは良い文字列でないので No を出力します。

入力例 2

1 2
1
1 1 1
2 1 1

出力例 2

Yes

0 または 1 の 1 文字からなる文字列は良い文字列の条件をみたすことに注意してください。

Score: 450 points

Problem Statement

A string consisting of 0 and 1 is called a good string if two consecutive characters in the string are always different.
You are given a string S of length N consisting of 0 and 1. Q queries will be given and must be processed in order.
There are two types of queries:

  • 1 L R: Flip each of the L-th to R-th characters of S. That is, for each integer i satisfying L\leq i\leq R, change the i-th character of S to 0 if it is 1, and vice versa.
  • 2 L R: Let S' be the string of length (R-L+1) obtained by extracting the L-th to R-th characters of S (without changing the order). Print Yes if S' is a good string and No otherwise.

Constraints

  • 1\leq N, Q\leq 5\times 10^5
  • S is a string of length N consisting of 0 and 1.
  • 1\leq L\leq R\leq N for queries of types 1 and 2.
  • There is at least one query of type 2.
  • N, Q, L, and R are integers.

Input

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

N Q
S
query_1
query_2
\vdots
query_Q

Each query query_i (1\leq i\leq Q) is given in the form:

1 L R 

or:

2 L R 

Output

Let K be the number of queries of type 2. Print K lines.
The i-th line should contain the response to the i-th query of type 2.


Sample Input 1

5 6
10100
2 1 3
2 1 5
1 1 4
2 1 5
1 3 3
2 2 4

Sample Output 1

Yes
No
Yes
No

Initially, S=10100. When processing the queries in the order they are given, the following occurs:

  • For the first query, the string obtained by extracting the 1-st to 3-rd characters of S is S'=101. This is a good string, so print Yes.
  • For the second query, the string obtained by extracting the 1-st to 5-th characters of S is S'=10100. This is not a good string, so print No.
  • For the third query, flip each of the 1-st to 4-th characters of S. The string S becomes S=01010.
  • For the fourth query, the string obtained by extracting the 1-st to 5-th character of S is S'=01010. This is a good string, so print Yes.
  • For the fifth query, flip the 3-rd character of S. The string S becomes S=01110.
  • For the sixth query, the string obtained by extracting the 2-nd to 4-th character of S is S'=111. This is not a good string, so print No.

Sample Input 2

1 2
1
1 1 1
2 1 1

Sample Output 2

Yes

Note that a string of a single character 0 or 1 satisfies the condition of being a good string.

I - Numbered Checker

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

配点 : 500 点

問題文

N 行 M 列のグリッドがあり、上から i 行目、左から j 列目のマス (i,j) には整数 (i-1) \times M + j が書かれています。
このグリッドに、以下の操作を施します。

  • 全てのマス (i,j) について、 i+j が奇数ならそのマスに書かれている数字を 0 に書き換える。

操作後のグリッドについて、Q 個の質問に答えてください。
i 個目の質問は以下の通りです:

  • 以下の条件を全て満たすマス (p,q) 全てについて、そこに書かれている整数を全て足し合わせた値を 998244353 で割った余りを求めよ。
    • A_i \le p \le B_i
    • C_i \le q \le D_i

制約

  • 入力は全て整数
  • 1 \le N,M \le 10^9
  • 1 \le Q \le 2 \times 10^5
  • 1 \le A_i \le B_i \le N
  • 1 \le C_i \le D_i \le M

入力

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

N M
Q
A_1 B_1 C_1 D_1
A_2 B_2 C_2 D_2
\vdots
A_Q B_Q C_Q D_Q

出力

Q 行出力せよ。
そのうち i 行目には、 i 個目の質問に対する答えを整数として出力せよ。


入力例 1

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

出力例 1

28
27
36
14
0
104

この入力では、グリッドは以下の通りです。

この入力には 6 つの質問が含まれます。

  • 1 個目の質問の答えは 0+3+0+6+0+8+0+11+0=28 です。
  • 2 個目の質問の答えは 1+0+9+0+17=27 です。
  • 3 個目の質問の答えは 17+0+19+0=36 です。
  • 4 個目の質問の答えは 14 です。
  • 5 個目の質問の答えは 0 です。
  • 6 個目の質問の答えは 104 です。

入力例 2

1000000000 1000000000
3
1000000000 1000000000 1000000000 1000000000
165997482 306594988 719483261 992306147
1 1000000000 1 1000000000

出力例 2

716070898
240994972
536839100

1 個目の質問について、マス (10^9,10^9) に書かれている整数は 10^{18} ですが、それを 998244353 で割った余りを求めることに注意してください。


入力例 3

999999999 999999999
3
999999999 999999999 999999999 999999999
216499784 840031647 84657913 415448790
1 999999999 1 999999999

出力例 3

712559605
648737448
540261130

Score : 500 points

Problem Statement

We have a grid with N rows and M columns. The square (i,j) at the i-th row from the top and j-th column from the left has an integer (i-1) \times M + j written on it.
Let us perform the following operation on this grid.

  • For every square (i,j) such that i+j is odd, replace the integer on that square with 0.

Answer Q questions on the grid after the operation.
The i-th question is as follows:

  • Find the sum of the integers written on all squares (p,q) that satisfy all of the following conditions, modulo 998244353.
    • A_i \le p \le B_i.
    • C_i \le q \le D_i.

Constraints

  • All values in the input are integers.
  • 1 \le N,M \le 10^9
  • 1 \le Q \le 2 \times 10^5
  • 1 \le A_i \le B_i \le N
  • 1 \le C_i \le D_i \le M

Input

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

N M
Q
A_1 B_1 C_1 D_1
A_2 B_2 C_2 D_2
\vdots
A_Q B_Q C_Q D_Q

Output

Print Q lines.
The i-th line should contain the answer to the i-th question as an integer.


Sample Input 1

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

Sample Output 1

28
27
36
14
0
104

The grid in this input is shown below.

This input contains six questions.

  • The answer to the first question is 0+3+0+6+0+8+0+11+0=28.
  • The answer to the second question is 1+0+9+0+17=27.
  • The answer to the third question is 17+0+19+0=36.
  • The answer to the fourth question is 14.
  • The answer to the fifth question is 0.
  • The answer to the sixth question is 104.

Sample Input 2

1000000000 1000000000
3
1000000000 1000000000 1000000000 1000000000
165997482 306594988 719483261 992306147
1 1000000000 1 1000000000

Sample Output 2

716070898
240994972
536839100

For the first question, note that although the integer written on the square (10^9,10^9) is 10^{18}, you are to find it modulo 998244353.


Sample Input 3

999999999 999999999
3
999999999 999999999 999999999 999999999
216499784 840031647 84657913 415448790
1 999999999 1 999999999

Sample Output 3

712559605
648737448
540261130