A - Bitwise Exclusive Or

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 100

問題文

0 以上 255 以下の整数 A,B が与えられます。 A \text{ xor }C=B となる 0 以上の整数 C を求めてください。

なお、そのような C はただ 1 つ存在し、0 以上 255 以下であることが証明されます。

\text{ xor } とは

整数 a, b のビットごとの排他的論理和 a \text{ xor } b は、以下のように定義されます。

  • a \text{ xor } b を二進表記した際の 2^k (k \geq 0) の位の数は、a, b を二進表記した際の 2^k の位の数のうち一方のみが 1 であれば 1、そうでなければ 0 である。
例えば、3 \text{ xor } 5 = 6 となります (二進表記すると: 011 \text{ xor } 101 = 110)。

制約

  • 0\leq A,B \leq 255
  • 入力に含まれる値は全て整数である

入力

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

A B

出力

答えを出力せよ。


入力例 1

3 6

出力例 1

5

3 は 二進表記で 115 は二進表記で 101 なので、これらの \text{xor} は二進表記で 110 であり、十進表記で 6 です。

このように、3 \text{ xor } 5 = 6 となるので、答えは 5 です。


入力例 2

10 12

出力例 2

6

図

Score : 100 points

Problem Statement

You are given integers A and B between 0 and 255 (inclusive). Find a non-negative integer C such that A \text{ xor }C=B.

It can be proved that there uniquely exists such C, and it will be between 0 and 255 (inclusive).

What is bitwise \mathrm{XOR}?

The bitwise \mathrm{XOR} of integers A and B, A\ \mathrm{XOR}\ B, is defined as follows:

  • When A\ \mathrm{XOR}\ B is written in base two, the digit in the 2^k's place (k \geq 0) is 1 if exactly one of A and B is 1, and 0 otherwise.
For example, we have 3\ \mathrm{XOR}\ 5 = 6 (in base two: 011\ \mathrm{XOR}\ 101 = 110).

Constraints

  • 0\leq A,B \leq 255
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

A B

Output

Print the answer.


Sample Input 1

3 6

Sample Output 1

5

When written in binary, 3 will be 11, and 5 will be 101. Thus, their \text{xor} will be 110 in binary, or 6 in decimal.

In short, 3 \text{ xor } 5 = 6, so the answer is 5.


Sample Input 2

10 12

Sample Output 2

6

Figure

B - Takahashi san

Time Limit: 2 sec / Memory Limit: 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
C - Inverse Prefix Sum

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 200

問題文

整数 N と長さ N の数列 S=(S_1,\ldots,S_N) が与えられます。

長さ N の数列 A=(A_1,\ldots,A_N) であって、k=1,\ldots,N の全てについて以下の条件を満たすものを求めてください。

  • A_1+A_2+\ldots+A_k = S_k

なお、このような数列 A は必ず存在し、一意に定まります。

制約

  • 1 \leq N \leq 10
  • -10^9\leq S_i \leq 10^9
  • 入力は全て整数である

入力

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

N
S_1 \ldots S_N

出力

全ての条件を満たす数列 A=(A_1,\ldots,A_N) の各要素を、順に空白区切りで出力せよ。


入力例 1

3
3 4 8

出力例 1

3 1 4
  • A_1=3=S_1
  • A_1+A_2=3+1=4=S_2
  • A_1+A_2+A_3=3+1+4=8=S_3

であり、たしかに全ての条件を満たしています。


入力例 2

10
314159265 358979323 846264338 -327950288 419716939 -937510582 97494459 230781640 628620899 -862803482

出力例 2

314159265 44820058 487285015 -1174214626 747667227 -1357227521 1035005041 133287181 397839259 -1491424381

Score : 200 points

Problem Statement

You are given an integer N and a sequence S=(S_1,\ldots,S_N) of length N.

Find a sequence A=(A_1,\ldots,A_N) of length N that satisfies the following condition for all k=1,\ldots,N:

  • A_1+A_2+\ldots+A_k = S_k.

Such a sequence A always exists and is unique.

Constraints

  • 1 \leq N \leq 10
  • -10^9\leq S_i \leq 10^9
  • All values in the input are integers.

Input

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

N
S_1 \ldots S_N

Output

Print the elements of a sequence A=(A_1,\ldots,A_N) that satisfies all the conditions in order, separated by spaces.


Sample Input 1

3
3 4 8

Sample Output 1

3 1 4

The sequence in the output actually satisfies all the conditions:

  • A_1=3=S_1;
  • A_1+A_2=3+1=4=S_2;
  • A_1+A_2+A_3=3+1+4=8=S_3.

Sample Input 2

10
314159265 358979323 846264338 -327950288 419716939 -937510582 97494459 230781640 628620899 -862803482

Sample Output 2

314159265 44820058 487285015 -1174214626 747667227 -1357227521 1035005041 133287181 397839259 -1491424381
D - The Middle Day

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 200

問題文

AtCoder 国の暦では、一年は 1,2,\dots,M 番目の月の M か月からなり、そのうち i 番目の月は 1,2,\dots,D_i 番目の日の D_i 日からなります。
さらに、 AtCoder 国の一年の日数は奇数、即ち D_1+D_2+\dots+D_M は奇数です。
一年の真ん中の日は何番目の月の何番目の日か求めてください。
言い換えると、 1 番目の月の 1 番目の日を 1 日目としたときの (D_1+D_2+\dots+D_M+1)/2 日目が何番目の月の何番目の日かを求めてください。

制約

  • 入力は全て整数
  • 1 \le M \le 100
  • 1 \le D_i \le 100
  • D_1 + D_2 + \dots + D_M は奇数

入力

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

M
D_1 D_2 \dots D_M

出力

答えが a 番目の月の b 番目の日であるとき、以下の形式で出力せよ。

a b

入力例 1

12
31 28 31 30 31 30 31 31 30 31 30 31

出力例 1

7 2

この入力では、 1 年は 31+28+31+30+31+30+31+31+30+31+30+31=365 日からなります。
真ん中の日は (365+1)/2 = 183 日目であり、これを求めることを考えます。

  • 1,2,3,4,5,6 番目の月に含まれる日数の合計は 181 日です。
  • 7 番目の月の 1 番目の日は 182 日目です。
  • 7 番目の月の 2 番目の日は 183 日目です。

以上から、答えが 7 番目の月の 2 番目の日であることが分かります。


入力例 2

1
1

出力例 2

1 1

入力例 3

6
3 1 4 1 5 9

出力例 3

5 3

Score : 200 points

Problem Statement

In the calendar of AtCoderLand, a year consists of M months: month 1, month 2, \dots, month M. The i-th month consists of D_i days: day 1, day 2, \dots, day D_i.
Furthermore, the number of days in a year is odd, that is, D_1+D_2+\dots+D_M is odd.
Find what day of what month is the middle day of the year.
In other words, let day 1 of month 1 be the first day, and find a and b such that the ((D_1+D_2+\dots+D_M+1)/2)-th day is day b of month a.

Constraints

  • All input values are integers.
  • 1 \le M \le 100
  • 1 \le D_i \le 100
  • D_1 + D_2 + \dots + D_M is odd.

Input

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

M
D_1 D_2 \dots D_M

Output

Let the answer be day b of month a, and print it in the following format:

a b

Sample Input 1

12
31 28 31 30 31 30 31 31 30 31 30 31

Sample Output 1

7 2

In this input, a year consists of 31+28+31+30+31+30+31+31+30+31+30+31=365 days.
Let us find the middle day, which is the ((365+1)/2 = 183)-th day.

  • Months 1,2,3,4,5,6 contain a total of 181 days.
  • Day 1 of month 7 is the 182-th day.
  • Day 2 of month 7 is the 183-th day.

Thus, the answer is day 2 of month 7.


Sample Input 2

1
1

Sample Output 2

1 1

Sample Input 3

6
3 1 4 1 5 9

Sample Output 3

5 3
E - Ladder Takahashi

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 300

問題文

10^9 階建てのビルがあり、N 本のはしごがかかっています。
ビルの 1 階にいる高橋君ははしごを繰り返し使って(0 回でもよい)できるだけ高い階へ上りたいと考えています。
はしごには 1 から N までの番号がついており、はしご iA_i 階と B_i 階を結んでいます。はしご i を利用すると A_i 階から B_i 階へ、または B_i 階から A_i 階へ双方向に移動することができますが、それ以外の階の間の移動は行うことはできません。
また、高橋君は同じ階での移動は自由に行うことができますが、はしご以外の方法で他の階へ移動することはできません。
高橋君は最高で何階へ上ることができますか?

制約

  • 1 \leq N \leq 2 \times 10^5
  • 1 \leq A_i, B_i \leq 10^9
  • A_i \neq B_i
  • 入力はすべて整数

入力

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

N
A_1 B_1
A_2 B_2
\ldots
A_N B_N

出力

答えを出力せよ。


入力例 1

4
1 4
4 3
4 10
8 3

出力例 1

10

はしご 14 階に進み、はしご 310 階に進むことにより、10 階にたどり着くことができます。


入力例 2

6
1 3
1 5
1 12
3 5
3 12
5 12

出力例 2

12

入力例 3

3
500000000 600000000
600000000 700000000
700000000 800000000

出力例 3

1

他の階への移動ができない場合もあります。

Score : 300 points

Problem Statement

There is a 10^9-story building with N ladders.
Takahashi, who is on the 1-st (lowest) floor, wants to reach the highest floor possible by using ladders (possibly none).
The ladders are numbered from 1 to N, and ladder i connects the A_i-th and B_i-th floors. One can use ladder i in either direction to move from the A_i-th floor to the B_i-th floor or vice versa, but not between other floors.
Takahashi can freely move within the same floor, but cannot move between floors without using ladders.
What is the highest floor Takahashi can reach?

Constraints

  • 1 \leq N \leq 2 \times 10^5
  • 1 \leq A_i, B_i \leq 10^9
  • A_i \neq B_i
  • All values in the input are integers.

Input

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

N
A_1 B_1
A_2 B_2
\ldots
A_N B_N

Output

Print an integer representing the answer.


Sample Input 1

4
1 4
4 3
4 10
8 3

Sample Output 1

10

He can reach the 10-th floor by using ladder 1 to get to the 4-th floor and then ladder 3 to get to the 10-th floor.


Sample Input 2

6
1 3
1 5
1 12
3 5
3 12
5 12

Sample Output 2

12

Sample Input 3

3
500000000 600000000
600000000 700000000
700000000 800000000

Sample Output 3

1

He may be unable to move between floors.

F - Shapes

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 300

問題文

2 次元グリッド上に 2 つの図形 ST があります。グリッドは正方形のマスからなります。

SNN 列のグリッド内にあり、S_{i,j}# であるようなマス全体からなります。
TNN 列のグリッド内にあり、T_{i,j}# であるようなマス全体からなります。

ST90 度回転及び平行移動の繰り返しによって一致させることができるか判定してください。

制約

  • 1 \leq N \leq 200
  • S,T#. のみからなる
  • S,T1 つ以上 # を含む

入力

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

N
S_{1,1}S_{1,2}\ldots S_{1,N}
\vdots
S_{N,1}S_{N,2}\ldots S_{N,N}
T_{1,1}T_{1,2}\ldots T_{1,N}
\vdots
T_{N,1}T_{N,2}\ldots T_{N,N}

出力

ST90 度回転及び平行移動の繰り返しによって一致させることができるとき Yes を、そうでないとき No を出力せよ。


入力例 1

5
.....
..#..
.###.
.....
.....
.....
.....
....#
...##
....#

出力例 1

Yes

S を左回りに 90 度回転させ、平行移動することで T に一致させることができます。


入力例 2

5
#####
##..#
#..##
#####
.....
#####
#..##
##..#
#####
.....

出力例 2

No

90 度回転と平行移動の繰り返しによって一致させることはできません。


入力例 3

4
#...
..#.
..#.
....
#...
#...
..#.
....

出力例 3

Yes

S 及び T は連結とは限りません。


入力例 4

4
#...
.##.
..#.
....
##..
#...
..#.
....

出力例 4

No

回転や移動の操作は連結成分ごとにできるわけではなく、S,T 全体に対して行うことに注意してください。

Score : 300 points

Problem Statement

We have two figures S and T on a two-dimensional grid with square cells.

S lies within a grid with N rows and N columns, and consists of the cells where S_{i,j} is #.
T lies within the same grid with N rows and N columns, and consists of the cells where T_{i,j} is #.

Determine whether it is possible to exactly match S and T by 90-degree rotations and translations.

Constraints

  • 1 \leq N \leq 200
  • Each of S and T consists of # and ..
  • Each of S and T contains at least one #.

Input

Input is given from Standard Input in the following format:

N
S_{1,1}S_{1,2}\ldots S_{1,N}
\vdots
S_{N,1}S_{N,2}\ldots S_{N,N}
T_{1,1}T_{1,2}\ldots T_{1,N}
\vdots
T_{N,1}T_{N,2}\ldots T_{N,N}

Output

Print Yes if it is possible to exactly match S and T by 90-degree rotations and translations, and No otherwise.


Sample Input 1

5
.....
..#..
.###.
.....
.....
.....
.....
....#
...##
....#

Sample Output 1

Yes

We can match S to T by rotating it 90-degrees counter-clockwise and translating it.


Sample Input 2

5
#####
##..#
#..##
#####
.....
#####
#..##
##..#
#####
.....

Sample Output 2

No

It is impossible to match them by 90-degree rotations and translations.


Sample Input 3

4
#...
..#.
..#.
....
#...
#...
..#.
....

Sample Output 3

Yes

Each of S and T may not be connected.


Sample Input 4

4
#...
.##.
..#.
....
##..
#...
..#.
....

Sample Output 4

No

Note that it is not allowed to rotate or translate just a part of a figure; it is only allowed to rotate or translate a whole figure.

G - Left Right Operation

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 400

問題文

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

あなたは以下の連続する操作をちょうど一度だけ行います。

  • 整数 x\ (0\leq x \leq N) を選ぶ。x として 0 を選んだ場合何もしない。 x として 1 以上の整数を選んだ場合、A_1,A_2,\ldots,A_x をそれぞれ L で置き換える。

  • 整数 y\ (0\leq y \leq N) を選ぶ。y として 0 を選んだ場合何もしない。 y として 1 以上の整数を選んだ場合、A_{N},A_{N-1},\ldots,A_{N-y+1} をそれぞれ R で置き換える。

操作後の A の要素の総和として考えられる最小値を求めてください。

制約

  • 1 \leq N \leq 2\times 10^5
  • -10^9 \leq L, R\leq 10^9
  • -10^9 \leq A_i\leq 10^9
  • 入力は全て整数

入力

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

N L R
A_1 A_2 \ldots A_N

出力

答えを出力せよ。


入力例 1

5 4 3
5 5 0 6 3

出力例 1

14

x=2,y=2 として操作をすると、数列 A = (4,4,0,3,3) となり、要素の総和は 14 になります。

これが達成可能な最小値です。


入力例 2

4 10 10
1 2 3 4

出力例 2

10

x=0,y=0 として操作をすると、数列 A = (1,2,3,4) となり、要素の総和は 10 になります。

これが達成可能な最小値です。


入力例 3

10 -5 -3
9 -6 10 -1 2 10 -1 7 -15 5

出力例 3

-58

L,R,A_i は負であることがあります。

Score : 400 points

Problem Statement

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

You will perform the following consecutive operations just once:

  • Choose an integer x (0\leq x \leq N). If x is 0, do nothing. If x is 1 or greater, replace each of A_1,A_2,\ldots,A_x with L.

  • Choose an integer y (0\leq y \leq N). If y is 0, do nothing. If y is 1 or greater, replace each of A_{N},A_{N-1},\ldots,A_{N-y+1} with R.

Print the minimum possible sum of the elements of A after the operations.

Constraints

  • 1 \leq N \leq 2\times 10^5
  • -10^9 \leq L, R\leq 10^9
  • -10^9 \leq A_i\leq 10^9
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

N L R
A_1 A_2 \ldots A_N

Output

Print the answer.


Sample Input 1

5 4 3
5 5 0 6 3

Sample Output 1

14

If you choose x=2 and y=2, you will get A = (4,4,0,3,3), for the sum of 14, which is the minimum sum achievable.


Sample Input 2

4 10 10
1 2 3 4

Sample Output 2

10

If you choose x=0 and y=0, you will get A = (1,2,3,4), for the sum of 10, which is the minimum sum achievable.


Sample Input 3

10 -5 -3
9 -6 10 -1 2 10 -1 7 -15 5

Sample Output 3

-58

L, R, and A_i may be negative.

H - Blackout 2

Time Limit: 3 sec / Memory Limit: 1024 MiB

配点 : 500

問題文

ある国には N 個の都市と M 個の発電所があります。これらを総称して地点と呼びます。
地点には 1,2,\dots,N+M の番号がつけられており、そのうち都市は地点 1,2,\dots,N で発電所は地点 N+1,N+2,\dots,N+M です。

この国には電線が E 本あり、電線 i ( 1 \le i \le E ) は地点 U_i と地点 V_i を双方向に結びます。
また、ある都市に 電気が通っている とは、ある都市から電線をいくつか辿って少なくともひとつの発電所に辿り着くことができる状態を言います。

今、 Q 個のイベントが起こります。そのうち i ( 1 \le i \le Q ) 番目のイベントでは電線 X_i が切れ、その電線を辿ることができなくなります。一度切れた電線は、その後のイベントにおいても切れたままです。

全てのイベントについて、そのイベントが終わった直後に電気が通っている都市の数を求めてください。

制約

  • 入力は全て整数
  • 1 \le N,M
  • N+M \le 2 \times 10^5
  • 1 \le Q \le E \le 5 \times 10^5
  • 1 \le U_i < V_i \le N+M
  • i \neq j ならば、 U_i \neq U_j または V_i \neq V_j
  • 1 \le X_i \le E
  • X_i は相異なる

入力

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

N M E
U_1 V_1
U_2 V_2
\vdots
U_E V_E
Q
X_1
X_2
\vdots
X_Q

出力

Q 行出力せよ。
そのうち i ( 1 \le i \le Q ) 行目には i 番目のイベントが終わった直後に電気が通っている都市の数を出力せよ。


入力例 1

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

出力例 1

4
4
2
2
2
1

はじめ、全ての都市に電気が通っています。

  • 1 番目のイベントによって地点 5 と地点 10 を結ぶ電線 3 が切れます。
    • これにより、都市 5 に電気が通らなくなり、電気が通っている都市の数は 4 となります。
  • 2 番目のイベントによって地点 2 と地点 9 を結ぶ電線 5 が切れます。
  • 3 番目のイベントによって地点 3 と地点 6 を結ぶ電線 8 が切れます。
    • これにより、都市 2,3 に電気が通らなくなり、電気が通っている都市の数は 2 となります。
  • 4 番目のイベントによって地点 1 と地点 8 を結ぶ電線 10 が切れます。
  • 5 番目のイベントによって地点 4 と地点 10 を結ぶ電線 2 が切れます。
  • 6 番目のイベントによって地点 1 と地点 7 を結ぶ電線 7 が切れます。
    • これにより、都市 1 に電気が通らなくなり、電気が通っている都市の数は 1 となります。

Score : 500 points

Problem Statement

A country has N cities and M power plants, which we collectively call places.
The places are numbered 1,2,\dots,N+M, among which Places 1,2,\dots,N are the cities and Places N+1,N+2,\dots,N+M are the power plants.

This country has E power lines. Power Line i (1 \le i \le E) connects Place U_i and Place V_i bidirectionally.
A city is said to be electrified if one can reach at least one of the power plants from the city using some power lines.

Now, Q events will happen. In the i-th (1 \le i \le Q) event, Power Line X_i breaks, making it unusable. Once a power line breaks, it remains broken in the succeeding events.

Find the number of electrified cities right after each events.

Constraints

  • All values in input are integers.
  • 1 \le N,M
  • N+M \le 2 \times 10^5
  • 1 \le Q \le E \le 5 \times 10^5
  • 1 \le U_i < V_i \le N+M
  • If i \neq j, then U_i \neq U_j or V_i \neq V_j.
  • 1 \le X_i \le E
  • X_i are distinct.

Input

Input is given from Standard Input in the following format:

N M E
U_1 V_1
U_2 V_2
\vdots
U_E V_E
Q
X_1
X_2
\vdots
X_Q

Output

Print Q lines.
The i-th line should contain the number of electrified cities right after the i-th event.


Sample Input 1

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

Sample Output 1

4
4
2
2
2
1

Initially, all cities are electrified.

  • The 1-st event breaks Power Line 3 that connects Point 5 and Point 10.
    • Now City 5 is no longer electrified, while 4 cities remain electrified.
  • The 2-nd event breaks Power Line 5 that connects Point 2 and Point 9.
  • The 3-rd event breaks Power Line 8 that connects Point 3 and Point 6.
    • Now Cities 2 and 3 are no longer electrified, while 2 cities remain electrified.
  • The 4-th event breaks Power Line 10 that connects Point 1 and Point 8.
  • The 5-th event breaks Power Line 2 that connects Point 4 and Point 10.
  • The 6-th event breaks Power Line 7 that connects Point 1 and Point 7.
    • Now City 1 is no longer electrified, while 1 city remains electrified.
I - Treasure Hunting

Time Limit: 3 sec / Memory Limit: 1024 MiB

配点 : 500

問題文

H 行、横 W 列のマス目があります。上から i 行目、左から j 列目のマスを (i,j) と書くことにします。(i,j) には整数 A_{i,j} が書かれています。

高橋君は (1,1) を出発し、(H,W) にたどり着くまで、1 つ右あるいは 1 つ下のマスへ移動することを繰り返します。ただし、マス目の外に出ることはできません。

この時、移動のコストを以下のように定義します。

通った H+W-1 個のマスに書かれた整数のうち大きい方 K 個の和

コストとしてありうる最小値を求めてください。

制約

  • 1 \leq H,W \leq 30
  • 1 \leq K < H+W
  • 1 \leq A_{i,j} \leq 10^9
  • 入力は全て整数

入力

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

H W K
A_{1,1} A_{1,2} \ldots A_{1,W}
A_{2,1} A_{2,2} \ldots A_{2,W}
\vdots
A_{H,1} A_{H,2} \ldots A_{H,W}

出力

答えを出力せよ。


入力例 1

1 3 2
3 4 5

出力例 1

9

移動の方法は一通りのみであり、通ったマスに書かれた整数は大きい方から順に 543 となるので、9(=5+4) を出力します。


入力例 2

2 2 1
3 2
4 3

出力例 2

3

(1,1)(1,2)(2,2) の順に通った時コストが最小となります。


入力例 3

3 5 3
4 7 8 6 4
6 7 3 10 2
3 8 1 10 4

出力例 3

21

Score : 500 points

Problem Statement

We have a grid with H horizontal rows and W vertical columns. Let (i, j) denote the square at the i-th row from the top and j-th column from the left. (i, j) contains an integer A_{i,j}.

Takahashi will depart (1, 1) and repeatedly move one square right or down until reaching (H, W). It is not allowed to exit the grid.

The cost of this travel is defined as:

the sum of the K greatest integers among the integers written on the H+W-1 squares traversed.

Find the minimum possible cost.

Constraints

  • 1 \leq H,W \leq 30
  • 1 \leq K < H+W
  • 1 \leq A_{i,j} \leq 10^9
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

H W K
A_{1,1} A_{1,2} \ldots A_{1,W}
A_{2,1} A_{2,2} \ldots A_{2,W}
\vdots
A_{H,1} A_{H,2} \ldots A_{H,W}

Output

Print the answer.


Sample Input 1

1 3 2
3 4 5

Sample Output 1

9

There is only one way to travel, where the traversed squares contain the integers 5, 4, 3 from largest to smallest, so we print 9(=5+4).


Sample Input 2

2 2 1
3 2
4 3

Sample Output 2

3

The minimum cost is achieved by traversing (1,1), (1,2), (2,2) in this order.


Sample Input 3

3 5 3
4 7 8 6 4
6 7 3 10 2
3 8 1 10 4

Sample Output 3

21