A - DEGwer's Doctoral Dissertation

Time Limit: 2 sec / Memory Limit: 1024 MB

配点 : 100

問題文

DEGwer さんの博士論文は N ページからなります.この博士論文には現在 K 個の誤植が存在し, i 個目の誤植 (i = 1, \ldots, K)A_i ページにあります.

博士論文を提出するには,どの連続する T ページにも複数の誤植が存在しないように誤植を修正しておく必要があります.コンテストの準備で忙しい DEGwer さんのために,博士論文を提出するために修正すべき最小の誤植の個数を求めてあげてください.

制約

  • 1 \leq N \leq 2 \times 10^5
  • 1 \leq K \leq 2 \times 10^5
  • 1 \leq T \leq N
  • 1 \leq A_i \leq N \ \ (1 \leq i \leq K)

入力

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

N \ K \ T 
A_1 \ A_2 \ \dots \ A_K

出力

博士論文を提出するために修正すべき誤植の個数の最小値を出力せよ.


入力例 1

5 4 3
1 2 4 5

出力例 1

2

DEGwer さんの博士論文は 5 ページからなり, 1 ページ目, 2 ページ目, 4 ページ目, 5 ページ目に 1 個ずつ誤植があります.

例えば 1 ページ目の誤植と 4 ページ目の誤植を修正すると,どの連続する 3 ページにも複数の誤植が存在しない状態になります.一方, 1 個の誤植を修正するだけでこの条件を満たすのは不可能であることも確かめられます.したがって修正すべき最小の誤植の個数として 2 を出力します.


入力例 2

4 8 2
1 1 1 1 1 4 2 2

出力例 2

6

単一のページに複数の誤植が存在することもあります.


入力例 3

5 2 3
4 1

出力例 3

0

誤植を修正する必要がないこともあります.

Score : 100 points

Problem Statement

DEGwer's doctoral dissertation consists of N pages. Currently, there are K typos in this doctoral dissertation, and the i-th typo (i = 1, \ldots, K) is on page A_i.

To submit the doctoral dissertation, it is necessary to correct the typos so that no consecutive T pages contain multiple typos. Please help busy DEGwer, who is preparing this contest, by determining the minimum number of typos that need to be corrected in order to submit the doctoral dissertation.

Constraints

  • 1 \leq N \leq 2 \times 10^5
  • 1 \leq K \leq 2 \times 10^5
  • 1 \leq T \leq N
  • 1 \leq A_i \leq N \ \ (1 \leq i \leq K)

Input

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

N \ K \ T 
A_1 \ A_2 \ \dots \ A_K

Output

Output the minimum number of typos that need to be corrected to submit the doctoral dissertation.


Sample Input 1

5 4 3
1 2 4 5

Sample Output 1

2

DEGwer's doctoral dissertation consists of 5 pages, with one typo each on the 1st, 2nd, 4th, and 5th pages.

For example, if the typos on the 1st and 4th pages are corrected, then no consecutive 3 pages will have multiple typos. On the other hand, it can also be confirmed that it is impossible to meet this condition by correcting only one typo. Therefore, output 2 as the minimum number of typos to be corrected.


Sample Input 2

4 8 2
1 1 1 1 1 4 2 2

Sample Output 2

6

There may also be multiple typos on a single page.


Sample Input 3

5 2 3
4 1

Sample Output 3

0

There may be no need to correct any typos.

B - vs. DEGwer

Time Limit: 5 sec / Memory Limit: 1024 MB

配点 : 100

問題文

これはインタラクティブな問題です.ジャッジプログラム(インタラクタ)の実行に最大 1 秒程度を要するため,実行時間制限を長めに設定しています.

10 年にわたる長旅の末,あなたはついに大魔王 DEGwer 城に辿り着きました. 城の入口はダンジョンになっており,これを通り抜けなければ大魔王 DEGwer の下には辿り着けません.

ダンジョンは HW 列のマス目状になっています. 各マスは部屋であり,上下左右に隣接する部屋同士の間には1 つずつ設置されています. また,最も左の列にある各部屋の左側には入口となるが,最も右の列にある各部屋の右側には出口となるが,それぞれ 1 つずつ設置されています.

今,すべての扉は未固定の状態です. 以下の魔法を交互に使うことで,あなたは「開いた扉を通行して移動を繰り返すことで,開いた入口から開いた出口に到達可能である」ように,大魔王 DEGwer はそうならないようにしたいです.

  • あなた:「未固定の扉を任意に 1 つ選び,その扉を開いて(通行可能な状態で)固定する」魔法
  • DEGwer:「未固定の扉を任意に 1 つ選び,その扉を閉じて(通行不可能な状態で)固定する」魔法

ダンジョンの大きさ (H, W) と,どちらが先に魔法を使うかが与えられるので,互いに最善を尽くした場合にあなたの目的が達成可能かどうかを判定してください. さらに,あなたの目的が達成可能である場合には,その手順(あなたが使う魔法)をインタラクティブに示してください.

制約

  • 1 \leq H \leq 20
  • 1 \leq W \leq 20
  • \textrm{move}First または Second のいずれかであり,First はあなたが先に魔法を使うことを,Second は大魔王 DEGwer が先に魔法を使うことを表す.

入力

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

H W \textrm{move}

出力

互いに最善を尽くした場合にあなたの目的が達成可能である場合には Yes を,達成不可能である場合には No を出力せよ.

さらに,Yes の場合には,あなたの目的を達成する手順(あなたが使う魔法)を以下の形式でインタラクティブに出力せよ.(入出力例 2 も参考にせよ.)

t i j
  • t| または - である.
  • i, j は整数である.
  • t = {}| の場合,1 \leq i \leq H かつ 1 \leq j \leq W + 1 であり,魔法の対象として,横通行(左右に隣接する部屋同士の間,あるいは,入口または出口)の扉のうち,上から i 番目,左から j 番目のものを選ぶことを意味する.
  • t = {}- の場合,1 \leq i \leq H - 1 かつ 1 \leq j \leq W であり,魔法の対象として,縦通行(上下に隣接する部屋同士の間)の扉のうち,上から i 番目,左から j 番目のものを選ぶことを意味する.

あなたの出力に対し,同じ形式の入力が返ってくる. ただし,\textrm{move} = {}First の場合は Yes に続けてあなたが先に出力し,\textrm{move} = {}Second の場合は Yes の出力の直後に先に入力される. いずれの場合も,出力を行うたびに,末尾に改行を入れて標準出力を flush すること.

  • t|, -, a, w のいずれかである.
  • t| または - の場合,出力と同じ形式で大魔王 DEGwer が次に選ぶ扉を表す.
  • t = {}a の場合,i = j = 0 であり,あなたのインタラクティブ回答が正答である(ことが確定した)ことを表す.
  • t = {}w の場合,i = j = 0 であり,あなたのインタラクティブ回答が正答でない(ことが確定した)ことを表す.
  • ta または w の入力を受け取った場合,ただちにプログラムを終了すること.

入力例 1

1 1 First

出力例 1

No

この例では,ダンジョンは 1 つの部屋のみからなり,その部屋の左側に入口の扉が,右側に出口の扉があります. あなたの目的を達成するには両方の扉を開ける必要がありますが,あなたが先に魔法を使えるとしても,あなたが選ばなかった方の扉を大魔王 DEGwer が選ぶことで目的の達成が阻止されます. したがって,あなたの目的は達成不可能です.


入力例 2

2 1 First

出力例 2

Yes
...

この例では,以下のように,ダンジョンは縦に並んだ 2 つの部屋からなり,それらの間に縦通行の扉が 1 つあり,各部屋の左右に入口と出口の扉が計 2 つずつあります.

| |
 -
| |

あなたが先に魔法を使えるので,たとえば唯一の縦通行の扉 - 1 1 を選んだとします. すると,大魔王 DEGwer がどのように扉を選んでも,残った入口と出口の 2 つずつの扉のうち 1 つずつをあなたが選ぶことができ,最初の魔法により 2 つの部屋間は移動可能となっているので,結果としてあなたの目的は達成可能であることがわかります.

以下はインタラクティブ入出力の一例です.

入力    出力   説明
2 1 First 入力が与えられます.
Yes あなたの目的は達成可能なので Yes を出力します.
- 1 1 あなたは,縦通行の扉のうち,上から 1 番目,左から 1 番目のものを選び,開いて固定します.
| 1 2 大魔王 DEGwer は,横通行の扉のうち,上から 1 番目,左から 2 番目のもの(右上の出口)を選び,閉じて固定します.
| 2 2 あなたは,横通行の扉のうち,上から 2 番目,左から 2 番目のもの(右下の出口)を選び,開いて固定します.
| 2 1 大魔王 DEGwer は,横通行の扉のうち,上から 2 番目,左から 1 番目のもの(左下の入口)を選び,閉じて固定します.
| 1 1 あなたは,横通行の扉のうち,上から 1 番目,左から 1 番目のもの(左上の入口)を選び,開いて固定します.
a 0 0 この時点で,左上の開いた入口から右下の開いた出口に到達可能であることが確定し,正答であることを表す入力が与えられるので,ただちにプログラムを終了してください.

この例ではあなたが先に魔法を使いますが,そうでない( \mathrm{move} = {}Second である)場合には,Yes の出力の直後に大魔王 DEGwer が魔法の対象として選ぶ扉が同じ形式で入力されます.


入力例 3

2 1 Second

出力例 3

No

上の例と同じダンジョンですが,大魔王 DEGwer が先に魔法を使うので,あなたの目的は達成不可能となります. たとえば,上の例であなたが最初に選んだ縦通行の扉を選ばれると,入出力例 1 と同じ状況が縦に 2 つ並んだような状態となり,(いずれにおいても)あなたが先に魔法を使えるとしても目的は達成不可能です.

Score : 100 points

Problem Statement

This is an interactive problem. Because the judge program (interactor) requires around 1 second in the worst case, the time limit is set to be longer.

You have eventually reached the castle of Great Satan DEGwer after 10-year journey. The entrance of the castle is a dungeon, which cannot avoid for arriving at DEGwer.

The dungeon is of form a grid with H rows and W columns. Each of H \times W squares is a room, and there is a door between any pair of adjacent rooms. In addition, there is an entrance door on the left side of each room located in the left-most column, and there is an exit door on the right side of each room located in the right-most column.

Now, all the door are unfixed. You want to let the dungeon such that some open exit door can be reached from some open entrance door by repeatedly passing through open doors, and DEGwer wants to prevent your objective. For their own objectives, you and DEGwer alternately use the following magics.

  • Your magic: Choose any unfixed door, fix it as open (passable).
  • DEGwer's magic: Choose any unfixed door, fix it as closed (impassable).

You are given the size (H, W) of the dungeon and who uses the magic first. Determine whether your objective is achievable or not when you and DEGwer do their best. In addition, if your objective is achievable, indicate interactively one possible way (your magics) to do so.

Constraints

  • 1 \leq H \leq 20
  • 1 \leq W \leq 20
  • \textrm{move} is either First or Second, where First means that you use the magic first, and Second means that DEGwer uses the magic first.

Input

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

H W \textrm{move}

Output

Print Yes if your objective is achievable and No otherwise, under the assumption that you and DEGwer do their best.

In addition, if the answer is Yes, print interactively in the following format for which doors you use magic. (See also Sample 2.)

t i j
  • t is either | or -.
  • i and j are integers.
  • If t = {}|, then 1 \leq i \leq H and 1 \leq j \leq W + 1, which represents that the door chosen as a target of the magic is the i-th from the top and the j-th from the left among those which are passed horizontally (i.e., the doors between two horizontally adjacent rooms and all the entrance and exit doors).
  • If t = {}-, then 1 \leq i \leq H - 1 and 1 \leq j \leq W, which represents that the door chosen as a target of the magic is the i-th from the top and the j-th from the left among those which are passed vertically (i.e., the doors between two vertically adjacent rooms).

Against your output, an input in the same format will be returned. Note that if \textrm{move} = {}First, then you should print your output followed by printing Yes, and if \textrm{move} = {}Second, then you should receive an input just after printing Yes. In either case, each time you print something, end it with a newline and flush Standard Output.

  • t is one of |, -, a, and w.
  • If t is either | or -, then it represents the door chosen by DEGwer in the same manner.
  • If t = {}a, then i = j = 0, and it means that your interactive answer has been confirmed as a correct answer.
  • If t = {}w, then i = j = 0, and it means that your interactive answer has been confirmed as a wrong answer.
  • If you receive an input with t = {}a or t = {}w, your program must halt immediately.

Sample Input 1

1 1 First

Sample Output 1

No

In this case, the dungeon consists of only one room, whose left side has a unique entrance door and right side has a unique exit door. For your objective, you have to fix both doors as open, but it cannot be done even if you use the magic first. Thus, your objective is not achievable.


Sample Input 2

2 1 First

Sample Output 2

Yes
...

In this case, as shown in below, the dungeon consists of two vertically adjacent rooms, there is a unique vertically passable door between them, and the left and right sides of both rooms have two entrance and exit doors, respectively, in total.

| |
 -
| |

You use the magic first, and suppose that you choose the unique vertically passable door - 1 1. Then, no matter how DEGwer will choose doors, you can choose one from the remaining two entrance doors and one from the remaining two exit doors, which achieve your objective because the two rooms became connected by your first magic.

The following is an example of interactive inputs and outputs.

Input    Output  Explanation
2 1 First An input is given.
Yes As your objective is achievable, you print Yes.
- 1 1 You fix as open one that is 1st from the top and 1st from the left among the vertically passable door.
| 1 2 DEGwer fixes as closed one that is 1st from the top and 2nd from the left among the horizontally passable doors, i.e., the upper-right exit door.
| 2 2 You fix as open one that is 2nd from the top and 2nd from the left among the horizontally passable doors, i.e., the lower-right exit door.
| 2 1 DEGwer fixes as closed one that is 2nd from the top and 1st from the left among the horizontally passable doors, i.e., the lower-left entrance door.
| 1 1 You fix as open one that is 1st from the top and 1st from the left among the horizontally passable doors, i.e., the upper-left entrance door.
a 0 0 At this point, it is confirmed that the open lower-right exit door can be reached from the open upper-left entrance door, and your program must halt immediately after receiving the input indicating it.

Sample Input 3

2 1 Second

Sample Output 3

No

The dungeon is the same as above, but your objective is not achievable as DEGwer uses the magic first. For example, if DEGwer fixes the unique vertically passable door (that you choose first in Sample 2) as closed, then the situation is just like two parallel copies of Sample 1, in which your objective is not achievable even if you use the magic first.

C - binarydigit

Time Limit: 10 sec / Memory Limit: 1024 MB

配点 : 100

問題文

各要素が 0 または 1h \times w 行列であって以下の条件をともに満たすものの個数を整数 M で割った余りを求めてください.

  • 各行を長さ w の文字列として解釈したとき,行方向に辞書順でソートされている.
  • 各列を長さ h の文字列として解釈したとき,列方向に辞書順でソートされている.

入力で整数 H, W が与えられるので, 1 \le h \le H, 1 \le w \le W を満たす全ての整数 h, w の組について答えてください.

制約

  • 1 \le H \le 21
  • 1 \le W \le 100
  • 2 \le M \le 10^9

入力

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

H \ W \ M

出力

H 行出力せよ. 第 i(1 \le i \le H) には W 個の整数を半角空白区切りで出力せよ.特に j 番目の整数 (1 \le j \le W) として h = i, w = j のときの本問の答えを出力せよ.


入力例 1

2 3 5201314

出力例 1

2 3 4
3 7 14

例として (h, w) = (2, 3) の場合,問題文の条件を満たす行列は以下の 14 個です.

000 000 000 000 001 001 001 001 001 011 011 011 011 111
000 001 011 111 001 010 011 110 111 011 100 101 111 111

入力例 2

10 8 1000000000

出力例 2

2 3 4 5 6 7 8 9
3 7 14 25 41 63 92 129
4 14 45 130 336 785 1682 3351
5 25 130 650 2942 11819 42305 136564
6 41 336 2942 24520 183010 1202234 6979061
7 63 785 11819 183010 2625117 33345183 371484319
8 92 1682 42305 1202234 33345183 836488618 470742266
9 129 3351 136564 6979061 371484319 470742266 230288201
10 175 6280 402910 36211867 651371519 194085968 670171373
11 231 11176 1099694 170079565 17940222 26957098 939510047

入力例 3

5 5 2

出力例 3

0 1 0 1 0
1 1 0 1 1
0 0 1 0 0
1 1 0 0 0
0 1 0 0 0

Score : 100 points

Problem Statement

Find the number of h \times w binary matrices which satisfy both of the following conditions modulo M:

  • When each row is interpreted as a string of length w, they are sorted in lexicographical order in the row direction.
  • When each column is interpreted as a string of length h, they are sorted in lexicographical order in the column direction.

Given integers H, W in the input, find the answer for all pairs of integers h, w that satisfy 1 \le h \le H, 1 \le w \le W.

Constraints

  • 1 \le H \le 21
  • 1 \le W \le 100
  • 2 \le M \le 10^9

Input

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

H \ W \ M

Output

Output H lines. For the i-th line (1 \le i \le H), output W integers separated by spaces. Specifically, the j-th integer (1 \le j \le W) should be the answer to this problem when h = i, w = j.


Sample Input 1

2 3 5201314

Sample Output 1

2 3 4
3 7 14

For example, in the case of (h, w) = (2, 3), there are 14 matrices that satisfy the conditions of the problem statement, as shown below:

000 000 000 000 001 001 001 001 001 011 011 011 011 111
000 001 011 111 001 010 011 110 111 011 100 101 111 111

Sample Input 2

10 8 1000000000

Sample Output 2

2 3 4 5 6 7 8 9
3 7 14 25 41 63 92 129
4 14 45 130 336 785 1682 3351
5 25 130 650 2942 11819 42305 136564
6 41 336 2942 24520 183010 1202234 6979061
7 63 785 11819 183010 2625117 33345183 371484319
8 92 1682 42305 1202234 33345183 836488618 470742266
9 129 3351 136564 6979061 371484319 470742266 230288201
10 175 6280 402910 36211867 651371519 194085968 670171373
11 231 11176 1099694 170079565 17940222 26957098 939510047

Sample Input 3

5 5 2

Sample Output 3

0 1 0 1 0
1 1 0 1 1
0 0 1 0 0
1 1 0 0 0
0 1 0 0 0
D - Coincidence

Time Limit: 2 sec / Memory Limit: 1024 MB

配点 : 100

問題文

長さ N の整数列の組 A=(A_1, A_2, \dots, A_N), B=(B_1, B_2, \dots, B_N) があります.最初は全ての i = 1, 2, \dots, N に対して A_i=B_i=0 です.

あなたは A, B に対して次の操作を M 回行います.

  • 操作:整数 i, j\ (1 \le i, j \le N) を選び, A_iB_j の値を 1 ずつ増やす.

ただし, M 回の操作のうち i=j であるのはちょうど X 回である必要があります.

M 回の操作後の A, B の組としてありうるものの個数を 998244353 で割った余りを求めてください.

制約

  • 2 \leq N \leq 3000
  • 0 \leq X \leq M \le 3000
  • 入力は全て整数

入力

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

N \ M \ X

出力

M 回の操作後の A, B の組としてありうるものの個数を 998244353 で割った余りを出力せよ.


入力例 1

3 1 1

出力例 1

3

次の 3 個です.

  • A=(1,0,0), \ B=(1,0,0)
  • A=(0,1,0), \ B=(0,1,0)
  • A=(0,0,1), \ B=(0,0,1)

入力例 2

3 1 0

出力例 2

6

次の 6 個です.

  • A=(1,0,0), \ B=(0,1,0)
  • A=(1,0,0), \ B=(0,0,1)
  • A=(0,1,0), \ B=(1,0,0)
  • A=(0,1,0), \ B=(0,0,1)
  • A=(0,0,1), \ B=(1,0,0)
  • A=(0,0,1), \ B=(0,1,0)

入力例 3

4 4 2

出力例 3

643

例えば次のような A, B の組がありえます.

  • A=(1,1,1,1), \ B=(1,1,1,1)
  • A=(1,0,0,3), \ B=(0,1,0,3)

入力例 4

314 1592 653

出力例 4

755768689

Score : 100 points

Problem Statement

You have a pair of integer sequences A=(A_1, A_2, \dots, A_N), B=(B_1, B_2, \dots, B_N). Initially A_i=B_i=0 holds for all i = 1, 2, \dots, N.

You will perform the following operation M times.

  • Operation: Choose two integers i, j\ (1 \le i, j \le N) and increment A_i and B_j by 1.

Here, out of the M operations, the number of operations in which i=j holds must be exactly X.

Find the number, modulo 998244353, of pairs of integer sequences that A, B can be after the M operations.

Constraints

  • 2 \leq N \leq 3000
  • 0 \leq X \leq M \le 3000
  • All input values are integers.

Input

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

N \ M \ X

Output

Print the number, modulo 998244353, of pairs of integer sequences that A, B can be after the M operations.


Sample Input 1

3 1 1

Sample Output 1

3

The following 3 pairs are possible.

  • A=(1,0,0), \ B=(1,0,0)
  • A=(0,1,0), \ B=(0,1,0)
  • A=(0,0,1), \ B=(0,0,1)

Sample Input 2

3 1 0

Sample Output 2

6

The following 6 pairs are possible.

  • A=(1,0,0), \ B=(0,1,0)
  • A=(1,0,0), \ B=(0,0,1)
  • A=(0,1,0), \ B=(1,0,0)
  • A=(0,1,0), \ B=(0,0,1)
  • A=(0,0,1), \ B=(1,0,0)
  • A=(0,0,1), \ B=(0,1,0)

Sample Input 3

4 4 2

Sample Output 3

643

The followings are examples of possible pairs.

  • A=(1,1,1,1), \ B=(1,1,1,1)
  • A=(1,0,0,3), \ B=(0,1,0,3)

Sample Input 4

314 1592 653

Sample Output 4

755768689
E - Half Palindromes

Time Limit: 3 sec / Memory Limit: 1024 MB

配点 : 100

問題文

英小文字からなる文字列 S が与えられます.S のすべての連続する部分文字列 |S|(|S|+1)/2 個に対して以下の問題を解き,解の値の総和を求めてください.

問題:英小文字からなる文字列 T が与えられます.T に以下の操作を好きなだけ繰返すことで作ることのできる文字列の長さの最小値を求めてください.

  • T の接頭辞であって奇数長(2k+1 文字とする)の回文になっているものを任意に取る.T の先頭 k 文字を削除する.

制約

  • 1\leq |S|\leq 10^6
  • S は英小文字からなる

入力

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

S

出力

答えを出力せよ.


入力例 1

abab

出力例 1

16

Ta または b のとき,答えは 1 です.

Tab または ba のとき,答えは 2 です.

Taba または bab のとき,k=1 として操作を一度行うのが最適であり,答えは 2 です.

Tabab のとき,k=1 として操作を行ったあと,もう一度 k=1 として操作を行うのが最適であり,答えは 2 です.

よって全体の答えは 1\times 4 + 2\times 3 + 2\times 2 + 2\times 1 = 16 です.


入力例 2

abacaba

出力例 2

67

入力例 3

tabatadebatabata

出力例 3

739

Score : 100 points

Problem Statement

You are given a string S consisting of lowercase letters. For each contiguous substring of S (there are |S|(|S|+1)/2 such substrings), solve the following problem, and compute the sum of the answers.

Problem: You are given a string T consisting of lowercase letters. Compute the minimum possible length of a string that can be obtained from T by repeatedly applying the following operation an arbitrary number of times.

  • Take a prefix of T that is a palindrome of odd length. Let the length be 2k+1. Remove the first k letters of T.

Constraints

  • 1\leq |S|\leq 10^6
  • S consists of lowercase letters.

Input

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

S

Output

Print the answer.


Sample Input 1

abab

Sample Output 1

16

If T is a or b, the answer is 1.

If T is ab or ba, the answer is 2.

If T is aba or bab, applying the operation with k=1 once is optimal, and the answer is 2.

If T is abab, applying the operation with k=1 twice is optimal, and the answer is 2.

Therefore, the whole answer is 1\times 4 + 2\times 3 + 2\times 2 + 2\times 1 = 16.


Sample Input 2

abacaba

Sample Output 2

67

Sample Input 3

tabatadebatabata

Sample Output 3

739
F - K-Medians Clustering

Time Limit: 3 sec / Memory Limit: 1024 MB

配点 : 100

問題文

正整数 N, M, K と長さ K の正整数列 c=(c_1, c_2, \dots, c_K) が与えられます.

M 以下の正整数のみからなる要素数 N多重集合 S であって,次の条件を全て満たすような K 個の多重集合の組 (S_1, S_2, \dots, S_K) が存在するようなものを良い多重集合と呼びます.

  • S_1, S_2, \dots, S_K はいずれも空でない.
  • i=1, 2, \dots, K のそれぞれに対して,S_i の中央値は c_i である.
  • S_1, S_2, \dots, S_K の要素数の総和は N である.その N 個の要素からなる多重集合は S に等しい.

ただしこの問題において,要素数 n\ (\geq 1) の多重集合 T の中央値とは,T の要素を昇順に並べたときの \lceil n / 2 \rceil 番目の要素であると定義します.例えば, T=\lbrace 1, 2, 3, 4 \rbrace の中央値は 2 であり, T=\lbrace 1, 3, 5, 7, 7 \rbrace の中央値は 5 です.

良い多重集合の個数を 998244353 で割った余りを求めてください.

制約

  • 1 \leq N, M \leq 10^7
  • 1 \leq K \leq \min(2 \times 10^5, N)
  • 1 \leq c_i \leq M
  • 入力は全て整数

入力

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

N \ M \ K
c_1 \ c_2 \ \dots \ c_K

出力

良い多重集合の個数を 998244353 で割った余りを出力せよ.


入力例 1

8 5 3
4 1 5

出力例 1

105

例えば S=\lbrace 1,1,1,2,3,4,5,5 \rbrace は,条件を満たす (S_1, S_2, S_3) が次のように存在するため良い多重集合です.

  • S_1 = \lbrace 1, \mathbf{4}, 5 \rbrace
  • S_2 = \lbrace 1, \mathbf{1}, 2, 3 \rbrace
  • S_3 = \lbrace \mathbf{5} \rbrace

入力例 2

10000000 2 2
1 2

出力例 2

9999999

入力例 3

30 10 5
3 1 4 1 5

出力例 3

38446044

Score : 100 points

Problem Statement

You are given positive integers N, M, K, and a sequence of K positive integers c=(c_1, c_2, \dots, c_K).

A multiset S consisting of N positive integers less than or equal to M is called good, if there exists at least one sequence of K multisets (S_1, S_2, \dots, S_K) satisfying the following conditions.

  • None of S_1, S_2, \dots, S_K is empty.
  • The median of S_i equals to c_i, for all i=1, 2, \dots, K.
  • S_1, S_2, \dots, S_K have exactly N elements in total. A multiset consisting of those N elements coincides with S.

Note that we define the median of a multiset T with n\ (\geq 1) elements as the \lceil n / 2 \rceil-th element of T in ascending order. For example, the median of T=\lbrace 1, 2, 3, 4 \rbrace is 2, and that of T=\lbrace 1, 3, 5, 7, 7 \rbrace is 5.

Find the number of good multisets modulo 998244353.

Constraints

  • 1 \leq N, M \leq 10^7
  • 1 \leq K \leq \min(2 \times 10^5, N)
  • 1 \leq c_i \leq M
  • All input values are integers.

Input

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

N \ M \ K
c_1 \ c_2 \ \dots \ c_K

Output

Print the number of good multisets modulo 998244353.


Sample Input 1

8 5 3
4 1 5

Sample Output 1

105

For example, S=\lbrace 1,1,1,2,3,4,5,5 \rbrace is a good multiset because there exists (S_1, S_2, S_3) satisfying the conditions as follows.

  • S_1 = \lbrace 1, \mathbf{4}, 5 \rbrace
  • S_2 = \lbrace 1, \mathbf{1}, 2, 3 \rbrace
  • S_3 = \lbrace \mathbf{5} \rbrace

Sample Input 2

10000000 2 2
1 2

Sample Output 2

9999999

Sample Input 3

30 10 5
3 1 4 1 5

Sample Output 3

38446044
G - Net of Net

Time Limit: 10 sec / Memory Limit: 1024 MB

配点 : 100

問題文

三次元凸多面体 P に対し,その展開図とは,以下を満たす平面上の(重なっても構わない)多角形の集合のことを指します.

  • 各多角形は P の面と一対一に対応する
  • 辺のいずれかにに沿って折る操作を繰返すことで P を構成することができる.

ただし,辺に沿って折るとは以下の操作です.

  • 辺であって,その辺を取り除くと現在の図形が非連結になるものを取る.その辺で定義される直線を中心軸として,現在の図形上でその辺の片側に位置する部分全体を,任意の角度だけ(三次元的に)回転させる.必要なら,座標の完全に一致した頂点や辺を同一視する.

同様に,三次元凸多面体 P展開図の展開図とは,以下を満たす線分の集合のことを指します.

  • 各辺は P の展開図の辺と一対一に対応する
  • 頂点に沿って折ることを繰返すことで,P の展開図を構成することができる.

ただし,頂点に沿って折るとは以下の操作です.

  • 頂点であって,その頂点を取り除くと現在の図形が非連結になるものを取る.その頂点を中心に,現在の図形上でその頂点の特定の側に位置する部分全体を,任意の角度だけ(二次元的に)回転させる.必要なら,座標の完全に一致した頂点を同一視する.

どの四頂点も同一平面上にない,単位球面上の N 点が与えられます. i 番目の点の座標は (x_i,y_i,(-1)^{c_i}\sqrt{1-x_i^2-y_i^2}) です.

与えられた点たちの凸包の展開図の展開図であって,パスであるものが存在するか判定してください. 存在する場合は,そのパスの長さの最大値を求めてください.

制約

  • 4 \leq N \leq 14
  • -1\leq x_i,y_i\leq 1
  • c_i0 または 1
  • x_i^2+y_i^2\leq 1
  • 与えられるどの 2 点も相異なる
  • 与えられるすべての異なる四点 p,q,r,s に対して,p,q,r が乗っている平面と s の間の距離は 10^{-5} 以上

入力

入力は以下の形式で標準入力から与えられる.実数は小数点以下 6 桁まで与えられる.

N
x_1 y_1 c_1
\vdots
x_N y_N c_N

出力

与えられた点たちの凸包の展開図の展開図であってパスであるものが存在するなら,答えを出力せよ. そうでない場合,-1 を出力せよ.

真の値との絶対誤差あるいは相対誤差が 10^{-7} 以下の場合に正答とみなされる.


入力例 1

4
0.000000 0.000000 1
0.000000 0.000000 0
1.000000 0.000000 1
0.000000 1.000000 0

出力例 1

13.899494936612

たとえば,図のような展開が最適です.

図: 展開の例


入力例 2

6
-0.322191 -0.852465 0
-0.463288 -0.553583 1
0.378710 -0.346882 1
-0.489727 0.488028 0
-0.731142 0.227066 1
0.254757 -0.899035 0

出力例 2

22.950966056549

入力例 3

8
0.837078 0.492956 1
0.360579 -0.565500 0
-0.367448 -0.492394 1
0.491637 -0.658814 1
-0.505114 -0.538563 1
0.544637 0.592884 1
-0.622207 -0.379934 1
0.402129 0.684158 1

出力例 3

28.879053537910

入力例 4

4
0.800000 0.600000 0
1.000000 0.000000 1
-0.280000 -0.960000 1
0.000000 0.000000 0

出力例 4

13.284042973728

Score : 100 points

Problem Statement

For a three-dimensional convex polytope P, the net of it is the set of (possibly overlapping) polygons satisfying the following.

  • Each polygon corresponds one-to-one with a face of P.
  • P can be constructed by repeating the operation of folding along its edges.

Here, folding along an edge is the following operation:

  • Choose an edge, the removal of which would make the current figure disconnected. Use the line defined by this edge as the axis of rotation and rotate the entire part of the current figure that lies on one side of this edge by any angle (in three dimensions). If necessary, vertices or edges that coincide exactly in coordinates are identified.

Similarly, the net of the net of P is the set of line segments satisfying the following.

  • Each edge corresponds one-to one with an edge of the net of P.
  • The net of P can be constructed by repeating the operation of folding along its vertices.

Here, folding along a vertex is the following operation:

  • Choose a vertex, the removal of which would make the current figure disconnected. Use this vertex as the center of rotation and rotate the entire part of the current figure that lies on some side of this vertex by any angle (in two dimentions). If necessary, vertices that coincide exactly in coordinates are identified.

You are given N points on the unit sphere such that no four of these are on the same plain. The coordinate of i-th point is given by (x_i,y_i,(-1)^{c_i}\sqrt{1-x_i^2-y_i^2}).

Determine whether there exists a net of a net of the convex hull of given points, which is a path. If exists, compute the largest length of such path.

Constraints

  • 4 \leq N \leq 14
  • -1\leq x_i,y_i\leq 1
  • c_i is 0 or 1
  • x_i^2+y_i^2\leq 1
  • No two given points coincide.
  • For all four different given points p,q,r,s, the distance between s and the plain on which p,q,r exist is at least 10^{-5}.

Input

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

N
x_1 y_1 c_1
\vdots
x_N y_N c_N

Output

If there exists a net of a net of the convex hull of given points, which is a path, print the largest possible length. If not print -1.

An output is considered correct if the absolute or the relative error from the true value is at most 10^{-7}.


Sample Input 1

4
0.000000 0.000000 1
0.000000 0.000000 0
1.000000 0.000000 1
0.000000 1.000000 0

Sample Output 1

13.899494936612

The following net of net is optimal.

Figure: the optimal net of the net.


Sample Input 2

6
-0.322191 -0.852465 0
-0.463288 -0.553583 1
0.378710 -0.346882 1
-0.489727 0.488028 0
-0.731142 0.227066 1
0.254757 -0.899035 0

Sample Output 2

22.950966056549

Sample Input 3

8
0.837078 0.492956 1
0.360579 -0.565500 0
-0.367448 -0.492394 1
0.491637 -0.658814 1
-0.505114 -0.538563 1
0.544637 0.592884 1
-0.622207 -0.379934 1
0.402129 0.684158 1

Sample Output 3

28.879053537910

Sample Input 4

4
0.800000 0.600000 0
1.000000 0.000000 1
-0.280000 -0.960000 1
0.000000 0.000000 0

Sample Output 4

13.284042973728
H - Incomplete Notes

Time Limit: 3 sec / Memory Limit: 1024 MB

配点 : 100

ストーリー

あなたは N 個の音からなる歌が途切れ途切れ聞こえた.この歌に, M 個の音からなるフレーズが含まれていたかどうかを推測したい.ただし,フレーズが本来と異なる 調 で含まれている場合も考慮したい.

問題文

それぞれ長さが N, M の 2 つの非負整数列 A = (A_1, \dots, A_N), B = (B_1, \dots, B_M) が与えられます.

1 \le i \le N - M + 1 を満たす整数 i のうち,以下の条件を満たすものの個数を求めてください.

条件

A の長さ M の連続部分列 CC = (A_i, \dots, A_{i + M - 1}) で定める.次に,数列 B, C の各要素のうち値が 0 であるもの全てを任意の 正の実数 で更新する(更新後の値は各要素で異なっていてよい).その後, 正の実数 t を任意に定め,数列 C の全ての要素に t を乗じる.このようにして得られた数列 BC を一致させることができる.

制約

  • 1 \leq M \leq N \leq 5 \times 10^5
  • 0 \leq A_i \leq 5 \times 10^5 (i = 1, \ldots, N)
  • 0 \leq B_i \leq 5 \times 10^5 (i = 1, \ldots, M)

入力

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

N \ M
A_1 \ A_2 \ \dots \ A_N
B_1 \ B_2 \ \dots \ B_M

出力

答えとなる整数を出力せよ.


入力例 1

9 4
9 3 0 0 2 99 4 0 0
6 2 0 4

出力例 1

4

i = 1 のとき, B(6, 2, 5, 4) に,また C = (9, 3, 0, 0)(9, 3, 7.5, 6) に更新し, t = 2/3 ととると最終的に BC が一致します.

i = 2, 3, 4 のときも,適切に操作を行うことで BC を一致させることが可能ですが, i = 5, 6 のときは不可能です.

以上より, i = 1, 2, 3, 44 個が条件を満たすので答えとして 4 を出力します.


入力例 2

8 2
0 0 0 0 0 0 0 0
0 0

出力例 2

7

Score : 100 points

Story

You heard a song consisting of N notes in fits and starts. You want to guess whether a phrase consisting of M sounds was included in this song. You also want to consider cases where the phrase is included in a different key than the original.

Problem Statement

You are given two sequences of non-negative integers, A = (A_1, \dots, A_N) and B = (B_1, \dots, B_M), each of length N and M, respectively.

Find the number of integers i that satisfy 1 \le i \le N - M + 1 and meet the following condition:

Condition

Define a contiguous subsequence C of length M of A as C = (A_i, \dots, A_{i + M - 1}). Next, update all elements of the sequences B and C that are 0 with any positive real number (the updated values may be different for each element). Then, determine an arbitrary positive real number t, and multiply all elements of sequence C by t. By doing so, the sequences B and C can be made identical.

Constraints

  • 1 \leq M \leq N \leq 5 \times 10^5
  • 0 \leq A_i \leq 5 \times 10^5 (i = 1, \ldots, N)
  • 0 \leq B_i \leq 5 \times 10^5 (i = 1, \ldots, M)

Input

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

N \ M
A_1 \ A_2 \ \dots \ A_N
B_1 \ B_2 \ \dots \ B_M

Output

Print an integer as the answer.


Sample Input 1

9 4
9 3 0 0 2 99 4 0 0
6 2 0 4

Sample Output 1

4

For i = 1, update B to (6, 2, 5, 4) and C = (9, 3, 0, 0) to (9, 3, 7.5, 6), and take t = 2/3. Finally, B and C will match.

For i = 2, 3, 4, it is possible to make B and C match by performing appropriate operations, but for i = 5, 6, it is impossible.

Therefore, since i = 1, 2, 3, 4 meet the condition, output 4 as the answer.


Sample Input 2

8 2
0 0 0 0 0 0 0 0
0 0

Sample Output 2

7
I - Convex Dombination

Time Limit: 2 sec / Memory Limit: 1024 MB

配点 : 100

問題文

平面上の N 個の相異なる格子点 (X_i, Y_i) \ (i = 1, 2, \dots, N) が与えられます. 各格子点 (X_i, Y_i) は整数の得点 P_i を持っています. これらの格子点から,以下の条件を満たすように好きな個数だけ選びます. このとき,選んだ格子点の得点の総和としてあり得る最大値を求めてください.

条件: 選ばれた格子点の凸結合支配されるような格子点は必ず選ばれている. すなわち,各 k = 1, 2, \dots, N について,以下を満たす N 個の非負実数の組 (\lambda_1, \lambda_2, \dots, \lambda_N) が存在するならば,格子点 (X_k, Y_k) は選ばれている.

  • \lambda_i > 0 \implies {}格子点 (X_i, Y_i) は選ばれている.
  • \sum_{i=1}^N \lambda_i = 1
  • \sum_{i=1}^N \lambda_i X_i \geq X_k
  • \sum_{i=1}^N \lambda_i Y_i \geq Y_k

制約

  • 1 \leq N \leq 200
  • 1 \leq X_i \leq 10^9 \ \ (1 \leq i \leq N)
  • 1 \leq Y_i \leq 10^9 \ \ (1 \leq i \leq N)
  • (X_i, Y_i) \neq (X_j, Y_j) \ \ (i \neq j)
  • |P_i| \leq 10^7 \ \ (1 \leq i \leq N)

入力

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

N
X_1 \ Y_1 \ P_1
X_2 \ Y_2 \ P_2
\vdots
X_N \ Y_N \ P_N

出力

条件を満たすように格子点を選ぶことで達成可能な得点の総和の最大値を出力せよ.


入力例 1

3
1 4 2
4 1 3
2 2 -4

出力例 1

3

(X_2, Y_2) = (4, 1) のみを選ぶのが最適です. (X_1, Y_1) = (1, 4) も選ぶ場合,たとえば \lambda_1 = 0.4,\ \lambda_2 = 0.6 とすると,

\[ \lambda_1 + \lambda_2 = 0.4 + 0.6 = 1\\[1mm] \lambda_1 X_1 + \lambda_2 X_2 = 0.4 \times 1 + 0.6 \times 4 = 2.8 \geq 2 = X_3\\[1mm] \lambda_1 Y_1 + \lambda_2 Y_2 = 0.4 \times 4 + 0.6 \times 1 = 2.2 \geq 2 = Y_3 \]

となるため,(X_3, Y_3) = (2, 2) も選ぶ必要があり,結果として損をします.


入力例 2

3
1 4 2
4 1 3
2 2 -1

出力例 2

4

すべての点を選ぶのが最適です.


入力例 3

3
1 4 2
4 1 3
1 1 -6

出力例 3

0

1 つも選ばないのが最適な場合もあります.

Score : 100 points

Problem Statement

You are given N distinct integer grid points (X_i, Y_i) \ (i = 1, 2, \dots, N) in the plane, each of which has an integer score P_i. You can choose an arbitrary number of grid points among them under the following condition. Find the maximum value of the sum of the scores of chosen grid points.

Condition: A grid point dominated by a convex combination of the chosen grid points must be chosen. That is, for each k = 1, 2, \dots, N, if there exists a tuple (\lambda_1, \lambda_2, \dots, \lambda_N) of N nonnegative reals with the following conditions, then (X_k, Y_k) is chosen:

  • \lambda_i > 0 \implies (X_i, Y_i) is chosen.
  • \sum_{i=1}^N \lambda_i = 1.
  • \sum_{i=1}^N \lambda_i X_i \geq X_k.
  • \sum_{i=1}^N \lambda_i Y_i \geq Y_k.

Constraints

  • 1 \leq N \leq 200
  • 1 \leq X_i \leq 10^9 \ \ (1 \leq i \leq N)
  • 1 \leq Y_i \leq 10^9 \ \ (1 \leq i \leq N)
  • (X_i, Y_i) \neq (X_j, Y_j) \ \ (i \neq j)
  • |P_i| \leq 10^7 \ \ (1 \leq i \leq N)

Input

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

N
X_1 \ Y_1 \ P_1
X_2 \ Y_2 \ P_2
\vdots
X_N \ Y_N \ P_N

Output

Print the maximum value of the sum of the scores of grid points that are chosen under the condition.


Sample Input 1

3
1 4 2
4 1 3
2 2 -4

Sample Output 1

3

It is optimal to choose only (X_2, Y_2) = (4, 1). If you choose (X_1, Y_1) = (1, 4) in addition, then for example \lambda_1 = 0.4 and \lambda_2 = 0.6 satisfy

\[ \lambda_1 + \lambda_2 = 0.4 + 0.6 = 1\\[1mm] \lambda_1 X_1 + \lambda_2 X_2 = 0.4 \times 1 + 0.6 \times 4 = 2.8 \geq 2 = X_3\\[1mm] \lambda_1 Y_1 + \lambda_2 Y_2 = 0.4 \times 4 + 0.6 \times 1 = 2.2 \geq 2 = Y_3, \]

and hence (X_3, Y_3) = (2, 2) must be chosen in addition, which decreases the sum of scores as a result.


Sample Input 2

3
1 4 2
4 1 3
2 2 -1

Sample Output 2

4

It is optimal to choose all the grid points.


Sample Input 3

3
1 4 2
4 1 3
1 1 -6

Sample Output 3

0

It is sometimes optimal to choose no grid point.

J - Hated Number

Time Limit: 2 sec / Memory Limit: 1024 MB

配点 : 100

問題文

正整数 X, M \ (X \leq M) が与えられます.

あなたは M 以下の正整数が好きですが,例外として X だけは嫌いです.そこで,次の条件を満たす集合 S を作ることにしました.

  • S10^5 以下の相異なる正整数のみからなる.
  • S の要素数は 20 以下である.
  • 1 \leq k \leq M, \ k \neq X を満たす任意の正整数 k に対して, S の部分集合で要素の総和が k であるものが存在する.
  • S の部分集合で要素の総和が X であるものは存在しない.

このような集合 S が存在するかどうかを判定し,存在する場合は 1 つ示してください.

1 つの入力につき, T 個のテストケースに答えてください.

制約

  • 1 \leq T \leq 100
  • 1 \leq X \le M \leq 10^5
  • M \geq 2
  • 入力は全て整数

入力

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

T
\mathrm{case}_1
\vdots
\mathrm{case}_T

各テストケースは次の形式で与えられる.

X \ M

出力

各テストケースについて, 条件を満たす S が存在しない場合は -1 を,存在する場合は S の例を 1 つ次の形式で出力せよ.

N
a_1 \ a_2 \ \dots \ a_N

ここで, NS の要素数を, (a_1, a_2, \dots, a_N)S の要素を昇順に並べた列を表し,それぞれ次の制約を満たさなければならない.

  • 1 \leq N \leq 20
  • 1 \leq a_1 \lt a_2 \lt \dots \lt a_N \leq 10^5

また,各テストケースごとに出力を改行せよ.


入力例 1

3
4 6
3 7
11 11

出力例 1

3
1 2 5
-1
4
1 2 3 4
  • 1 つ目のケースでは, S=\lbrace 1, 2, 5 \rbrace などが条件を満たします.
  • 2 つ目のケースで条件を満たす S はありません.
  • 3 つ目のケースでは, S=\lbrace 1, 2, 3, 4 \rbrace などが条件を満たします.

Score : 100 points

Problem Statement

You are given positive integers X, M \ (X \leq M).

You like positive integers less than or equal to M, but you hate X as the exception. So you decide to construct a set S satisfying the following conditions.

  • S consists of distinct positive integers less than or equal to 10^5.
  • S has at most 20 elements.
  • For all positive intergers k satisfying 1 \leq k \leq M and k \neq X, there exists at least one subset of S such that the sum of its elements equals to k.
  • There is no subset of S such that the sum of its elements equals to X.

Determine whether such a set S exists, and if so, construct one example.

Solve T test cases for each input file.

Constraints

  • 1 \leq T \leq 100
  • 1 \leq X \le M \leq 10^5
  • M \geq 2
  • All input values are integers.

Input

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

T
\mathrm{case}_1
\vdots
\mathrm{case}_T

Each test case is given in the following format:

X \ M

Output

For each test case, if there is no S satisfying the conditions then print -1, and if there is then print one example of S in the following format:

N
a_1 \ a_2 \ \dots \ a_N

Here N denotes the number of elements in S and (a_1, a_2, \dots, a_N) denotes the sequence of elements in S in ascending order, which must satisfy the following constraints.

  • 1 \leq N \leq 20
  • 1 \leq a_1 \lt a_2 \lt \dots \lt a_N \leq 10^5

Also, start a new line for each test case.


Sample Input 1

3
4 6
3 7
11 11

Sample Output 1

3
1 2 5
-1
4
1 2 3 4
  • In the first case, S=\lbrace 1, 2, 5 \rbrace is one example of S
  • In the second case, there is no S satisfying the conditions.
  • In the third case, S=\lbrace 1, 2, 3, 4 \rbrace is one example of S
K - ± Beam

Time Limit: 2 sec / Memory Limit: 1024 MB

配点 : 100

問題文

DEGwer さんは平面上の [-W, W] \times [-H, H] の土地を所有しており,ここで農業を営んでいます. 鳥獣被害に悩まされた DEGwer さんは,土地に侵入した動物を焼き払うビームを張り巡らせることにしました. 具体的には,土地内の格子点に +- のいずれかの符号が付いた柱を立て,符号の異なる柱同士を結ぶ線分としてビームを張ります. ただし,ビーム同士が柱の無い点で交わると,ビームの持つエネルギーが共鳴して大変なことが起こるため,ビーム同士は柱の無い点を共有しないようにしなければなりません.

DEGwer さんは,柱を立てる N 個の格子点 (X_i, Y_i) \ (i = 1, 2, \dots, N) を既に決めています. その中には土地の四隅すべてが含まれ,さらに柱を立てるどの 3 点も同一直線上には存在しません. 各柱の符号とビームを張る柱のペアを適切に定めて,張るビームの数を最大にしてください.

制約

  • 1 \le W \le 10^9
  • 1 \le H \le 10^9
  • 4 \le N \le 10^5
  • -W \le X_i \le W \ \ (1 \leq i \leq N)
  • -H \le Y_i \le H \ \ (1 \leq i \leq N)
  • (X_i, Y_i) \neq (X_j, Y_j) \ \ (i \neq j)
  • (X_i, Y_i) = (\pm W, \pm H)(複号任意)であるような i が存在する.
  • i \neq j \neq k \neq i のとき,(X_i, Y_i), (X_j, Y_j), (X_k, Y_k) は同一直線上にない.

入力

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

W \ H
N
X_1 \ Y_1
X_2 \ Y_2
\vdots
X_N \ Y_N

出力

ビームの数を最大にする方法を以下の形式で出力せよ.

S
M
P_1 \ Q_1
P_2 \ Q_2
\vdots
P_M \ Q_M
  • S+, - からなる長さ N の文字列であり,その i 文字目 S_i(X_i, Y_i) に立てる柱 i の符号を表す.
  • M はビームの最大本数を表す整数である.
  • i = 1, 2, \dots, M について,(P_i, Q_i) は「柱 P_i と柱 Q_i の間にビームを張る」ことを表し,S_{P_i} \neq S_{Q_i} が成り立つ必要がある.
  • i \neq j のとき,(X_{P_i}, Y_{P_i})(X_{Q_i}, Y_{Q_i}) を結ぶ線分と (X_{P_j}, Y_{P_j})(X_{Q_j}, Y_{Q_j}) を結ぶ線分は,それぞれの端点を除いて共有点をもたない.

入力例 1

1 1
4
1 1
-1 1
-1 -1
1 -1

出力例 1

+-+-
4
1 2
2 3
3 4
4 1

DEGwer さんの所有する土地は [-1, 1] \times [-1, 1] であり,その四隅のみに柱を立てます. 柱に(反)時計回りに交互に異なる符号を割り当てることで,隣り合う柱同士の間すべてにビームを張ることができ,これが最大です.


入力例 2

1 2
5
1 2
-1 2
0 1
-1 -2
1 -2

出力例 2

+-++-
6
1 2
2 4
4 5
5 1
2 3
3 5

DEGwer さんの所有する土地は [-1, 1] \times [-2, 2] であり,その四隅と格子点 (0, 1) に柱を立てます. 四隅の柱に(反)時計回りに交互に異なる符号を割り当て,(0, 1) の柱に任意の符号を割り当てることで,出力例のように 6 本のビームを張ることができます. また,7 本以上のビームを張れないことが証明できるので,これが最大であり答えの一例となります.

Score : 100 points

Problem Statement

DEGwer owns a rectangular land [-W, W] \times [-H, H] in the plane, and he is engaged in farming there. He is suffering from damage caused by birds and beasts, and he has decided to stretch beams that burn out creatures invading his land. Specifically, he will construct pillars having a sign, either + or -, on integer grid points in his land, and then stretch a beam as a segment between two pillars having different signs. However, if two beams share a point without a pillar, then something horrible happens because of resonance of beam energy, and hence he has to let any two beams not share a point without a pillar.

DEGwer has decided N integer grid points (X_i, Y_i) \ (i = 1, 2, \dots, N) on which he will construct the pillars. These grid points include the four corners of his land, and any three among these grid points are not on a single line. Your mission is to maximize the number of stretched beams by determining the sign of each pillar and between which pillars beams are stretched.

Constraints

  • 1 \le W \le 10^9
  • 1 \le H \le 10^9
  • 4 \le N \le 10^5
  • -W \le X_i \le W \ \ (1 \leq i \leq N)
  • -H \le Y_i \le H \ \ (1 \leq i \leq N)
  • (X_i, Y_i) \neq (X_j, Y_j) \ \ (i \neq j)
  • There exists an index i such that (X_i, Y_i) = (\pm W, \pm H) (for any pair of signs).
  • When i \neq j \neq k \neq i, the three grid points (X_i, Y_i), (X_j, Y_j), and (X_k, Y_k) are not on a single line.

Input

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

W \ H
N
X_1 \ Y_1
X_2 \ Y_2
\vdots
X_N \ Y_N

Output

Print a way to maximize the number of stretched beams in the following format:

S
M
P_1 \ Q_1
P_2 \ Q_2
\vdots
P_M \ Q_M
  • S is a string of length N consisting of + and -, whose i-th character S_i represents the sign of the pillar i constructed on (X_i, Y_i).
  • M is the maximum number of stretched beams.
  • For i = 1, 2, \dots, M, the pair (P_i, Q_i) means to stretch a beam between the pillar P_i and the pillar Q_i, where S_{P_i} \neq S_{Q_i} necessarily holds.
  • When i \neq j, the two segments between (X_{P_i}, Y_{P_i}) and (X_{Q_i}, Y_{Q_i}) and between (X_{P_j}, Y_{P_j}) and (X_{Q_j}, Y_{Q_j}) do not share any point except for their common end points.

Sample Input 1

1 1
4
1 1
-1 1
-1 -1
1 -1

Sample Output 1

+-+-
4
1 2
2 3
3 4
4 1

DEGwer's land is [-1, 1] \times [-1, 1], and he will construct four pillars on the four corners. If you assign alternating signs to the corner pillars in (counter)clockwise direction, you can stretch a beam between any adjacent pillars, and this is maximum.


Sample Input 2

1 2
5
1 2
-1 2
0 1
-1 -2
1 -2

Sample Output 2

+-++-
6
1 2
2 4
4 5
5 1
2 3
3 5

DEGwer's land is [-1, 1] \times [-2, 2], and he will construct five pillars on the grid point (0, 1) in addition to the four corners. If you assign alternating signs to the corner pillars in (counter)clockwise direction and an arbitrary sign to the pillar on (0, 1), you can stretch six beams in total as Sample Output 2. It can be proved that seven beams cannot be stretched, so this is an example of a solution.