A - ASCII code

Time Limit: 2 sec / Memory Limit: 1024 MB

配点 : 100

問題文

英小文字 a, b, \ldots, z の ASCII 文字コードはこの順に 97,98,\ldots,122 です。

97 以上 122 以下の整数 N が与えられるので、ASCII 文字コードが N であるような英小文字を出力してください。

制約

  • N97 以上 122 以下の整数

入力

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

N

出力

答えを出力せよ。


入力例 1

97

出力例 1

a

ASCII 文字コードが 97 である英小文字は a です。


入力例 2

122

出力例 2

z

Score : 100 points

Problem Statement

The ASCII values of the lowercase English letters a, b, \ldots, z are 97,98,\ldots,122 in this order.

Given an integer N between 97 and 122, print the letter whose ASCII value is N.

Constraints

  • N is an integer between 97 and 122 (inclusive).

Input

Input is given from Standard Input in the following format:

N

Output

Print the answer.


Sample Input 1

97

Sample Output 1

a

97 is the ASCII value of a.


Sample Input 2

122

Sample Output 2

z
B - Takahashi's Failure

Time Limit: 2 sec / Memory Limit: 1024 MB

配点 : 200

問題文

高橋君の家には N 個の食品があり、i 番目の食品のおいしさは A_i です。
また、高橋君には嫌いな食品が K 個あり、具体的には i=1,2,\ldots,K について、B_i 番目の食品が嫌いです。

高橋君は N 個の食品のうち、おいしさが最大の食品から 1 つを選んで食べようと考えています。 高橋君が嫌いな食品を食べる可能性があるならば Yes を、食べる可能性が無いならば No を出力してください。

制約

  • 1\leq K\leq N\leq 100
  • 1\leq A_i\leq 100
  • 1\leq B_i\leq N
  • B_i はすべて相異なる
  • 入力はすべて整数

入力

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

N K
A_1 A_2 \ldots A_N
B_1 B_2 \ldots B_K

出力

高橋君が嫌いな食品を食べる可能性があるならば Yes を、無いならば No を出力せよ。


入力例 1

5 3
6 8 10 7 10
2 3 4

出力例 1

Yes

5 個の食品の中でおいしさが最大の食品は食品 352 つであり、この 2 つのいずれかを食べます。
高橋君が嫌いな食品は 2,3,43 つであり、そのうち食品 3 を食べる可能性があります。
よって、Yes を出力します。


入力例 2

5 2
100 100 100 1 1
5 4

出力例 2

No

おいしさが最大の食品は食品 1,2,33 つであり、高橋君は嫌いな食品を食べる可能性はありません。


入力例 3

2 1
100 1
2

出力例 3

No

おいしさが最大の食品は食品 1 であり、高橋君は嫌いな食品を食べる可能性はありません。

Score : 200 points

Problem Statement

Takahashi has N foods in his house. The i-th food has the tastiness of A_i.
He dislikes K of these foods: for each i=1,2,\ldots,K, he dislikes the B_i-th food.

Out of the foods with the greatest tastiness among the N foods, Takahashi will randomly choose one and eat it.
If he has a chance to eat something he dislikes, print Yes; otherwise, print No.

Constraints

  • 1\leq K\leq N\leq 100
  • 1\leq A_i\leq 100
  • 1\leq B_i\leq N
  • All B_i are distinct.
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

N K
A_1 A_2 \ldots A_N
B_1 B_2 \ldots B_K

Output

If Takahashi has a chance to eat a food he dislikes, print Yes; otherwise, print No.


Sample Input 1

5 3
6 8 10 7 10
2 3 4

Sample Output 1

Yes

Among the five foods, the ones with the greatest tastiness are Food 3 and 5, of which he eats one.
He dislikes Food 2, 3, and 4, one of which he has a chance to eat: Food 3.
Therefore, the answer is Yes.


Sample Input 2

5 2
100 100 100 1 1
5 4

Sample Output 2

No

The foods with the greatest tastiness are Food 1, 2, and 3, none of which he has a chance to eat.


Sample Input 3

2 1
100 1
2

Sample Output 3

No

The food with the greatest tastiness is Food 1, which he has no chance to eat.

C - Slot Strategy

Time Limit: 2 sec / Memory Limit: 1024 MB

配点 : 300

問題文

N 個のリールからなるスロットがあります。
i 番目のリールの配列は文字列 S_i によって表されます。 ここで、S_i0, 1, \ldots, 9 がちょうど 1 回ずつ現れる長さ 10 の文字列です。

それぞれのリールには対応するボタンがついており、高橋君は各非負整数 t について、 スロットが回り始めてからちょうど t 秒後にボタンを 1 つ選んで押す(または何もしない)ことができます。
スロットが回り始めてから t 秒後に i 番目のリールに対応するボタンを押すと、 i 番目のリールは S_i(t\bmod{10})+1 文字目を表示して止まります。
ただし、t\bmod{10}t10 で割ったあまりを表します。

高橋君は全てのリールを止めた上で、表示されている文字が全て同じであるようにしたいです。
高橋君が目標を達成できるように全てのリールを止めるまでに、スロットが回り始めてから最小で何秒かかるかを求めてください。

制約

  • 2\leq N\leq 100
  • N は整数
  • S_i0, 1, \ldots, 9 がちょうど 1 回ずつ現れる長さ 10 の文字列

入力

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

N
S_1
S_2
\vdots
S_N

出力

高橋君が目標を達成できるように全てのリールを止めるまでに、スロットが回り始めてから最小で何秒かかるかを出力せよ。


入力例 1

3
1937458062
8124690357
2385760149

出力例 1

6

高橋君は次のようにそれぞれのリールを止めることでスロットが回り始めてから 6 秒後にリールに表示される文字を 8 で揃えることができます。

  • スロットの回転開始から 0 秒後に 2 番目のリールに対応するボタンを押します。2 番目のリールは S_2(0\bmod{10})+1=1 文字目である 8 を表示して止まります。
  • スロットの回転開始から 2 秒後に 3 番目のリールに対応するボタンを押します。3 番目のリールは S_3(2\bmod{10})+1=3 文字目である 8 を表示して止まります。
  • スロットの回転開始から 6 秒後に 1 番目のリールに対応するボタンを押します。1 番目のリールは S_1(6\bmod{10})+1=7 文字目である 8 を表示して止まります。

5 秒以下で全てのリールに表示されている文字を揃える方法はないため、6 を出力します。


入力例 2

5
0123456789
0123456789
0123456789
0123456789
0123456789

出力例 2

40

全てのリールを止めた上で、表示されている文字を揃える必要がある事に注意してください。

Score : 300 points

Problem Statement

There is a slot machine with N reels.
The placement of symbols on the i-th reel is represented by a string S_i of length 10 containing each of 0, 1, \ldots, 9 exactly once.

Each reel has a corresponding button. For each non-negative integer t, Takahashi can press one of the buttons of his choice (or do nothing) t seconds after the reels start spinning.
If the button for the i-th reel is pressed t seconds after the start of the spin, the i-th reel will stop to display the ((t\bmod{10})+1)-th character of S_i.
Here, t\bmod{10} denotes the remainder when t is divided by 10.

Takahashi wants to stop all reels to make them display the same character.
Find the minimum number of seconds needed to achieve his objective after the start of the spin.

Constraints

  • 2\leq N\leq 100
  • N is an integer.
  • S_i is a string of length 10 containing each of 0, 1, \ldots, 9 exactly once.

Input

Input is given from Standard Input in the following format:

N
S_1
S_2
\vdots
S_N

Output

Print the minimum number of seconds needed to achieve Takahashi's objective after the start of the spin.


Sample Input 1

3
1937458062
8124690357
2385760149

Sample Output 1

6

Takahashi can make all reels display 8 in 6 seconds after the start of the spin by stopping them as follows.

  • 0 seconds after the start of the spin, press the button for the 2-nd reel, making it stop to display the ((0\bmod{10})+1=1)-st character of S_2, 8.
  • 2 seconds after the start of the spin, press the button for the 3-rd reel, making it stop to display the ((2\bmod{10})+1=3)-rd character of S_3, 8.
  • 6 seconds after the start of the spin, press the button for the 1-st reel, making it stop to display the ((6\bmod{10})+1=7)-th character of S_1, 8.

There is no way to make all reels display the same character in five seconds or less, so the answer is 6.


Sample Input 2

5
0123456789
0123456789
0123456789
0123456789
0123456789

Sample Output 2

40

Note that he must stop all reels to make them display the same character.

D - Distinct Trio

Time Limit: 2 sec / Memory Limit: 1024 MB

配点 : 400

問題文

長さ N の数列 A=(A_1,A_2,\ldots,A_N) が与えられます。
以下の 2 条件をともに満たすような整数の組 (i,j,k) の個数を求めてください。

  • 1\leq i \lt j \lt k \leq N
  • A_i,A_j,A_k は相異なる

制約

  • 3 \leq N \leq 2\times 10^5
  • 1 \leq A_i \leq 2\times 10^5
  • 入力に含まれる値は全て整数である

入力

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

N
A_1 A_2 \ldots A_N

出力

答えを出力せよ。


入力例 1

4
3 1 4 1

出力例 1

2

条件を満たす整数の組 (i,j,k)(1,2,3),(1,3,4)2 つです。


入力例 2

10
99999 99998 99997 99996 99995 99994 99993 99992 99991 99990

出力例 2

120

入力例 3

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

出力例 3

355

Score : 400 points

Problem Statement

You are given a sequence of length N: A=(A_1,A_2,\ldots,A_N).
Find the number of triples (i,j,k) that satisfy both of the following conditions.

  • 1\leq i \lt j \lt k \leq N
  • A_i, A_j, and A_k are distinct.

Constraints

  • 3 \leq N \leq 2\times 10^5
  • 1 \leq A_i \leq 2\times 10^5
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

N
A_1 A_2 \ldots A_N

Output

Print the answer.


Sample Input 1

4
3 1 4 1

Sample Output 1

2

The two triples (i,j,k) satisfying the conditions are (1,2,3) and (1,3,4).


Sample Input 2

10
99999 99998 99997 99996 99995 99994 99993 99992 99991 99990

Sample Output 2

120

Sample Input 3

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

Sample Output 3

355
E - Road Reduction

Time Limit: 2 sec / Memory Limit: 1024 MB

配点 : 500

問題文

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

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

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

制約

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

入力

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

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

出力

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


入力例 1

3 3
1 2 1
2 3 2
1 3 10

出力例 1

1 2

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

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

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


入力例 2

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

出力例 2

3 1 2

Score : 500 points

Problem Statement

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

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

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

Constraints

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

Input

Input is given from Standard Input in the following format:

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

Output

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


Sample Input 1

3 3
1 2 1
2 3 2
1 3 10

Sample Output 1

1 2

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

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

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


Sample Input 2

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

Sample Output 2

3 1 2
F - Bread

Time Limit: 2 sec / Memory Limit: 1024 MB

配点 : 500

問題文

長さ L のパンが 1 つあり、これを N 人の子供たちに切り分けます。 i 番目 (1\leq i\leq N) の子供は長さ A_i のパンを欲しがっています。

そこで、高橋君は次の操作を繰り返して、長さ A_1,A_2,\ldots,A_N のパンを切り出して配ることにしました。

長さ k のパン 1 つと 1 以上 k-1 以下の整数 x を選ぶ。選んだパンを長さ x のパンと 長さ k-x のパンに切り分ける。
このとき、x の値によらずコストが k かかる。

それぞれの子供に配るパンは長さがちょうど A_i のパン 1 つである必要がありますが、誰にも配られずに余るパンがいくつあっても構いません。

このとき、全ての子供たちにパンを配るために必要な最小のコストを求めてください。

制約

  • 2 \leq N \leq 2\times 10^5
  • 1\leq A_i\leq 10^9
  • A_1+A_2+\cdots+A_N\leq L\leq 10^{15}
  • 入力は全て整数

入力

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

N L
A_1 A_2 \ldots A_N

出力

全ての子供たちにパンを配るために必要な最小のコストを出力せよ。


入力例 1

5 7
1 2 1 2 1

出力例 1

16

高橋君は次のようにしてパンを切り分けて配ることができます。

  • 長さ 7 のパンと整数 x=3 を選ぶ。パンは長さ 3 のパンと長さ 4 のパンに切り分けられる。 (コスト 7 )
  • 長さ 3 のパンと整数 x=1 を選ぶ。パンは長さ 1 のパンと長さ 2 のパンに切り分けられる。前者を 1 番目の子供に配る。 (コスト 3 )
  • 長さ 2 のパンと整数 x=1 を選ぶ。パンは長さ 1 のパン 2 つに切り分けられる。これを 3,5 番目の子供に配る。 (コスト 2 )
  • 長さ 4 のパンと整数 x=2 を選ぶ。パンは長さ 2 のパン 2 つに切り分けられる。これを 2,4 番目の子供に配る。 (コスト 4 )

このとき、コストは 7+3+2+4=16 かかり、これが最小です。 また、余るパンはありません。


入力例 2

3 1000000000000000
1000000000 1000000000 1000000000

出力例 2

1000005000000000

それぞれの子供に配るパンの長さはちょうど A_i でなければならない事に注意してください。

Score : 500 points

Problem Statement

We have a loaf of bread of length L, which we will cut and distribute to N children.
The i-th child (1\leq i\leq N) wants a loaf of length A_i.

Now, Takahashi will repeat the operation below to cut the loaf into lengths A_1, A_2, \ldots, A_N for the children.

Choose a loaf of length k and an integer x between 1 and k-1 (inclusive). Cut the loaf into two loaves of length x and k-x.
This operation incurs a cost of k regardless of the value of x.

Each child i must receive a loaf of length exactly A_i, but it is allowed to leave some loaves undistributed.

Find the minimum cost needed to distribute loaves to all children.

Constraints

  • 2 \leq N \leq 2\times 10^5
  • 1\leq A_i\leq 10^9
  • A_1+A_2+\cdots+A_N\leq L\leq 10^{15}
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

N L
A_1 A_2 \ldots A_N

Output

Print the minimum cost needed to distribute loaves to all children.


Sample Input 1

5 7
1 2 1 2 1

Sample Output 1

16

Takahashi can cut the loaf for the children as follows.

  • Choose the loaf of length 7 and x=3, cutting it into loaves of length 3 and 4 for a cost of 7.
  • Choose the loaf of length 3 and x=1, cutting it into loaves of length 1 and 2 for a cost of 3. Give the former to the 1-st child.
  • Choose the loaf of length 2 and x=1, cutting it into two loaves of length 1 for a cost of 2. Give them to the 3-rd and 5-th children.
  • Choose the loaf of length 4 and x=2, cutting it into two loaves of length 2 for a cost of 4. Give them to the 2-nd and 4-th children.

This incurs a cost of 7+3+2+4=16, which is the minimum possible. There will be no leftover loaves.


Sample Input 2

3 1000000000000000
1000000000 1000000000 1000000000

Sample Output 2

1000005000000000

Note that each child i must receive a loaf of length exactly A_i.

G - Pre-Order

Time Limit: 2 sec / Memory Limit: 1024 MB

配点 : 600

問題文

頂点 1 を根とした N 頂点の根付き木があります。頂点には 1,2,\ldots,N の番号がついています。

根から始めて深さ優先探索を行い、行きがけ順で頂点番号を記録したところ、順に P_1,P_2,\ldots,P_N となりました。
ただし、深さ優先探索では、現在の頂点に複数の子がある場合、まだ探索していない頂点のうち最も番号が小さい頂点へ移動することとします。

行きがけ順とは
根から始めて次の手順を繰り返して根付き木上の頂点を列挙します。
  • 現在いる頂点 u をまだ記録していなければ記録する。
  • その後、u の子のうち、まだ探索していないものがあればその頂点に移動する。
  • そうでない時、u が根であれば探索を終了する。そうでなければ、u の親に移動する。
  • この時、列挙された頂点を順に並べたものが行きがけ順です。

    条件をみたす根付き木として考えられるものの数を 998244353 で割った余りを求めてください。
    ただし、ある 2 つの「頂点 1 を根とした N 頂点の根付き木」が異なるとは、ある根以外の頂点が存在して、その親が異なる事を言います。

    制約

    • 2 \leq N \leq 500
    • 1 \leq P_i\leq N
    • P_1=1
    • P_i はすべて異なる
    • 入力は全て整数

    入力

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

    N
    P_1 P_2 \ldots P_N
    

    出力

    条件をみたす根付き木として考えられるものの数を 998244353 で割った余りを出力せよ。


    入力例 1

    4
    1 2 4 3
    

    出力例 1

    3
    

    条件をみたす根付き木としては次の 3 通りが考えられます。よって、 3 を出力します。

    また、次のような木は考えられません。頂点 2 の子の頂点のうち、番号の小さい頂点 3 が頂点 4 より先に探索され、 このときの行きがけ順は 1,2,3,4 となるからです。


    入力例 2

    8
    1 2 3 5 6 7 8 4
    

    出力例 2

    202
    

    Score : 600 points

    Problem Statement

    There is a rooted tree with N vertices called Vertex 1, 2, \ldots, N, rooted at Vertex 1.

    We performed a depth-first search starting at the root and obtained a preorder traversal of the tree: P_1, P_2, \ldots, P_N.
    During the search, when the current vertex had multiple children, we chose the unvisited vertex with the smallest index.

    What is a preorder traversal?
    We start at the root and repeat the following procedure to list the vertices of the tree.
  • If the current vertex u is not recorded yet, record it.
  • Then, if u has an unvisited vertex, go to that vertex.
  • Otherwise, terminate if u is the root, and go to the parent of u if it is not.
  • The list of vertices in the order they are recorded here is the preorder traversal of the tree.

    Find the number of rooted trees consistent with the preorder traversal, modulo 998244353.
    Two rooted trees (with N vertices and rooted at Vertex 1) are considered different when there is a non-root vertex whose parent is different in the two trees.

    Constraints

    • 2 \leq N \leq 500
    • 1 \leq P_i\leq N
    • P_1=1
    • All P_i are distinct.
    • All values in input are integers.

    Input

    Input is given from Standard Input in the following format:

    N
    P_1 P_2 \ldots P_N
    

    Output

    Print the number of rooted trees consistent with the preorder traversal, modulo 998244353.


    Sample Input 1

    4
    1 2 4 3
    

    Sample Output 1

    3
    

    The rooted trees consistent with the preorder traversal are the three shown below, so the answer is 3.

    Note that the tree below does not count. This is because, among the children of Vertex 2, we visit Vertex 3 before visiting Vertex 4, resulting in the preorder traversal 1,2,3,4.


    Sample Input 2

    8
    1 2 3 5 6 7 8 4
    

    Sample Output 2

    202
    
    Ex - K-th beautiful Necklace

    Time Limit: 2 sec / Memory Limit: 1024 MB

    配点 : 600

    問題文

    N 個の宝石があります。i 番目の宝石は色が D_i で美しさが V_i です。
    ここで、色は 1,2,\ldots,C のいずれかであり、どの色の宝石も少なくとも 1 個存在します。

    N 個の宝石から、色が相異なる C 個の宝石を選んでネックレスを作ります。(選ぶ順番は考えません。) ネックレスの美しさは選んだ宝石の美しさのビットごとの \rm XOR となります。

    全てのありえるネックレスの作り方のうち、美しさが K 番目に大きいもののネックレスの美しさを求めてください。(同じ美しさの作り方が複数存在する場合、それらは全て数えます。)

    ビットごとの \rm XOR とは 整数 A, B のビットごとの \rm XORA\ {\rm XOR}\ B は、以下のように定義されます。
    • A\ {\rm XOR}\ B を二進表記した際の 2^k (k \geq 0) の位の数は、A, B を二進表記した際の 2^k の位の数のうち一方のみが 1 であれば 1、そうでなければ 0 である。
    例えば、3\ {\rm XOR}\ 5 = 6 となります (二進表記すると: 011\ {\rm XOR}\ 101 = 110)。

    制約

    • 1 \leq C \leq N \leq 70
    • 1 \leq D_i \leq C
    • 0 \leq V_i < 2^{60}
    • 1 \leq K \leq 10^{18}
    • 少なくとも K 種類のネックレスを作ることができる
    • 入力に含まれる値は全て整数である

    入力

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

    N C K
    D_1 V_1
    \vdots
    D_N V_N
    

    出力

    答えを出力せよ。


    入力例 1

    4 2 3
    2 4
    2 6
    1 2
    1 3
    

    出力例 1

    5
    

    以下のような 4 種類のネックレスを作ることができます。

    • 1,3 番目の宝石を選ぶ。ネックレスの美しさは 4\ {\rm XOR}\ 2 =6 となる。
    • 1,4 番目の宝石を選ぶ。ネックレスの美しさは 4\ {\rm XOR}\ 3 =7 となる。
    • 2,3 番目の宝石を選ぶ。ネックレスの美しさは 6\ {\rm XOR}\ 2 =4 となる。
    • 2,4 番目の宝石を選ぶ。ネックレスの美しさは 6\ {\rm XOR}\ 3 =5 となる。

    よって美しさが 3 番目に大きいネックレスの美しさは 5 となります。


    入力例 2

    3 1 2
    1 0
    1 0
    1 0
    

    出力例 2

    0
    

    3 種類のネックレスを作ることができ、いずれも美しさは 0 です。


    入力例 3

    10 3 11
    1 414213562373095048
    1 732050807568877293
    2 236067977499789696
    2 449489742783178098
    2 645751311064590590
    2 828427124746190097
    3 162277660168379331
    3 316624790355399849
    3 464101615137754587
    3 605551275463989293
    

    出力例 3

    766842905529259824
    

    Score : 600 points

    Problem Statement

    We have N gemstones. The color and beauty of the i-th gemstone are D_i and V_i, respectively.
    Here, the color of each gemstone is one of 1, 2, \ldots, C, and there is at least one gemstone of each color.

    Out of the N gemstones, we will choose C with distinct colors and use them to make a necklace. (The order does not matter.) The beautifulness of the necklace will be the bitwise \rm XOR of the chosen gemstones.

    Among all possible ways to make a necklace, find the beautifulness of the necklace made in the way with the K-th greatest beautifulness. (If there are multiple ways with the same beautifulness, we count all of them.)

    What is bitwise \rm XOR?

    The bitwise \rm XOR of integers A and B, A \oplus B, is defined as follows:

    • When A \oplus B is written in base two, the digit in the 2^k's place (k \geq 0) is 1 if either A or B, but not both, has 1 in the 2^k's place, and 0 otherwise.
    For example, 3 \oplus 5 = 6. (In base two: 011 \oplus 101 = 110.)

    Constraints

    • 1 \leq C \leq N \leq 70
    • 1 \leq D_i \leq C
    • 0 \leq V_i < 2^{60}
    • 1 \leq K \leq 10^{18}
    • There are at least K ways to make a necklace.
    • All values in input are integers.

    Input

    Input is given from Standard Input in the following format:

    N C K
    D_1 V_1
    \vdots
    D_N V_N
    

    Output

    Print the answer.


    Sample Input 1

    4 2 3
    2 4
    2 6
    1 2
    1 3
    

    Sample Output 1

    5
    

    There are four ways to make a necklace, as follows.

    • Choose the 1-st and 3-rd gemstones to make a necklace with the beautifulness of 4\ {\rm XOR}\ 2 =6.
    • Choose the 1-st and 4-th gemstones to make a necklace with the beautifulness of 4\ {\rm XOR}\ 3 =7.
    • Choose the 2-nd and 3-rd gemstones to make a necklace with the beautifulness of 6\ {\rm XOR}\ 2 =4.
    • Choose the 2-nd and 4-th gemstones to make a necklace with the beautifulness of 6\ {\rm XOR}\ 3 =5.

    Thus, the necklace with the 3-rd greatest beautifulness has the beautifulness of 5.


    Sample Input 2

    3 1 2
    1 0
    1 0
    1 0
    

    Sample Output 2

    0
    

    There are three ways to make a necklace, all of which result in the beautifulness of 0.


    Sample Input 3

    10 3 11
    1 414213562373095048
    1 732050807568877293
    2 236067977499789696
    2 449489742783178098
    2 645751311064590590
    2 828427124746190097
    3 162277660168379331
    3 316624790355399849
    3 464101615137754587
    3 605551275463989293
    

    Sample Output 3

    766842905529259824