A - Library Loan Management

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 266 点

問題文

高橋君は市内にある N 館の図書館を管理しています。図書館 i(1 \leq i \leq N)には M_i 個のジャンルがあり、各ジャンルには 1 から M_i までの番号が付けられています。

図書館 i のジャンル j(1 \leq j \leq M_i)の初期蔵書数は S_{i,j} 冊です。初期蔵書数が 0 冊のジャンルもありえます。

ある日、青木君が貸出記録を整理したところ、まだ処理されていない Q 件の貸出申請が順番に記録されていることが分かりました。高橋君はこれらの申請を 1 番目から Q 番目まで順に処理します。なお、初期蔵書数はこれらの貸出申請を処理する前の時点での蔵書数を表します。

k 番目(1 \leq k \leq Q)の貸出申請は「図書館 v_k のジャンル d_k の本を 1 冊借りる」という内容です。各貸出申請の処理は次のように行います。

  • 図書館 v_k のジャンル d_k の現在の蔵書数が 1 冊以上であれば、貸出は成功し、そのジャンルの蔵書数が 1 減ります。
  • 図書館 v_k のジャンル d_k の現在の蔵書数が 0 冊であれば、貸出は失敗し、蔵書数は変化しません。

すべての貸出申請を 1 番目から Q 番目まで順に処理した後、各図書館の各ジャンルの残り蔵書数と、貸出が失敗した申請の件数を出力してください。

制約

  • 1 \leq N \leq 1000
  • 1 \leq M_i \leq 1000
  • \sum_{i=1}^{N} M_i \leq 10^5
  • 0 \leq S_{i,j} \leq 10^9
  • 1 \leq Q \leq 2 \times 10^5
  • 1 \leq v_k \leq N
  • 1 \leq d_k \leq M_{v_k}
  • 入力はすべて整数である。

入力

N
M_1 S_{1,1} S_{1,2} \ldots S_{1,M_1}
M_2 S_{2,1} S_{2,2} \ldots S_{2,M_2}
\vdots
M_N S_{N,1} S_{N,2} \ldots S_{N,M_N}
Q
v_1 d_1
v_2 d_2
\vdots
v_Q d_Q
  • 1 行目には、図書館の数を表す整数 N が与えられる。
  • 続く N 行のうち i 番目の行(1 \leq i \leq N)には、図書館 i のジャンル数 M_i と、各ジャンルの初期蔵書数 S_{i,1}, S_{i,2}, \ldots, S_{i,M_i} が、この順にスペース区切りで与えられる。
  • その次の行には、貸出申請の件数を表す整数 Q が与えられる。
  • 続く Q 行のうち k 番目の行(1 \leq k \leq Q)には、k 番目の貸出申請の対象となる図書館の番号 v_k とジャンルの番号 d_k がスペース区切りで与えられる。

出力

N + 1 行で出力してください。

  • i 行目(1 \leq i \leq N)には、すべての貸出申請を処理した後の図書館 i の各ジャンルの残り蔵書数を、ジャンル 1 からジャンル M_i の順に M_i 個の整数としてスペース区切りで出力してください。
  • N + 1 行目には、貸出が失敗した申請の件数を 1 つの整数として出力してください。

入力例 1

2
2 3 1
1 0
4
1 1
1 2
1 2
2 1

出力例 1

2 0
0
2

入力例 2

3
3 5 0 2
2 1 1
2 3 0
8
1 2
1 1
2 1
2 2
3 2
1 3
1 3
3 1

出力例 2

4 0 0
0 0
2 0
2

入力例 3

4
3 1000000000 0 5
4 2 3 1 0
1 100
2 10 20
12
1 1
1 2
1 2
1 3
2 4
2 4
3 1
3 1
4 1
4 2
4 2
2 3

出力例 3

999999999 0 4
2 3 0 0
98
9 18
4

Score : 266 pts

Problem Statement

Takahashi manages N libraries in the city. Library i (1 \leq i \leq N) has M_i genres, and each genre is numbered from 1 to M_i.

The initial number of books in genre j (1 \leq j \leq M_i) of library i is S_{i,j}. It is possible for a genre to have an initial book count of 0.

One day, Aoki organized the lending records and found that there are Q unprocessed lending requests recorded in order. Takahashi will process these requests sequentially from the 1-st to the Q-th. The initial book counts represent the number of books at the time before processing these lending requests.

The k-th lending request (1 \leq k \leq Q) is "borrow 1 book of genre d_k from library v_k." Each lending request is processed as follows:

  • If the current number of books of genre d_k in library v_k is 1 or more, the lending succeeds, and the number of books of that genre decreases by 1.
  • If the current number of books of genre d_k in library v_k is 0, the lending fails, and the number of books does not change.

After processing all lending requests from the 1-st to the Q-th in order, output the remaining number of books for each genre in each library, and the number of requests that failed.

Constraints

  • 1 \leq N \leq 1000
  • 1 \leq M_i \leq 1000
  • \sum_{i=1}^{N} M_i \leq 10^5
  • 0 \leq S_{i,j} \leq 10^9
  • 1 \leq Q \leq 2 \times 10^5
  • 1 \leq v_k \leq N
  • 1 \leq d_k \leq M_{v_k}
  • All input values are integers.

Input

N
M_1 S_{1,1} S_{1,2} \ldots S_{1,M_1}
M_2 S_{2,1} S_{2,2} \ldots S_{2,M_2}
\vdots
M_N S_{N,1} S_{N,2} \ldots S_{N,M_N}
Q
v_1 d_1
v_2 d_2
\vdots
v_Q d_Q
  • The first line contains an integer N representing the number of libraries.
  • Among the following N lines, the i-th line (1 \leq i \leq N) contains the number of genres M_i in library i and the initial book counts S_{i,1}, S_{i,2}, \ldots, S_{i,M_i} for each genre, given in this order separated by spaces.
  • The next line contains an integer Q representing the number of lending requests.
  • Among the following Q lines, the k-th line (1 \leq k \leq Q) contains the library number v_k and the genre number d_k for the k-th lending request, separated by a space.

Output

Output N + 1 lines.

  • On the i-th line (1 \leq i \leq N), output the remaining number of books for each genre of library i after processing all lending requests, as M_i integers in order from genre 1 to genre M_i, separated by spaces.
  • On the (N + 1)-th line, output the number of failed lending requests as a single integer.

Sample Input 1

2
2 3 1
1 0
4
1 1
1 2
1 2
2 1

Sample Output 1

2 0
0
2

Sample Input 2

3
3 5 0 2
2 1 1
2 3 0
8
1 2
1 1
2 1
2 2
3 2
1 3
1 3
3 1

Sample Output 2

4 0 0
0 0
2 0
2

Sample Input 3

4
3 1000000000 0 5
4 2 3 1 0
1 100
2 10 20
12
1 1
1 2
1 2
1 3
2 4
2 4
3 1
3 1
4 1
4 2
4 2
2 3

Sample Output 3

999999999 0 4
2 3 0 0
98
9 18
4
B - Managing the Guest List

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 300 点

問題文

高橋君は、大規模なパーティーの受付係を担当することになりました。

パーティーには招待客が次々と到着します。各招待客には 1 以上 10^9 以下の整数からなる招待客番号が割り振られており、異なる招待客には異なる番号が割り振られています。高橋君は到着した人をゲストリストに記録していきます。また、会場のスタッフから「この人は既に到着していますか?」という問い合わせを受けることもあります。

ゲストリストは最初は空の状態です。

高橋君は Q 回の操作を順に行います。i 番目の操作は種類 T_i と招待客番号 X_i の組で表され、以下の 2 種類のいずれかです:

  • T_i = 1(到着の記録):招待客番号 X_i の人物をゲストリストに追加する。ただし、この操作が行われる時点で X_i が既にゲストリストに含まれていないことが保証される。
  • T_i = 2(到着確認の問い合わせ):招待客番号 X_i の人物が現在のゲストリストに含まれているかを調べる。

T_i = 2 である各操作について、指定された招待客番号を持つ人物がゲストリストに含まれているかどうかを判定してください。

制約

  • 1 \leq Q \leq 4 \times 10^5
  • T_i \in \{1, 2\}
  • 1 \leq X_i \leq 10^9
  • T_i = 1 である操作において、その時点で既に X_i がゲストリストに含まれていることはない
  • T_i = 2 である操作は少なくとも 1 回は存在する
  • 入力はすべて整数

入力

Q
T_1 X_1
T_2 X_2
\vdots
T_Q X_Q

1 行目には、操作の回数を表す整数 Q が与えられる。

続く Q 行のうち i 行目 (1 \leq i \leq Q) には、i 番目の操作の種類を表す整数 T_i と、招待客番号を表す整数 X_i がスペース区切りで与えられる。

出力

T_i = 2 である各操作について、操作が行われた順に結果を 1 行ずつ出力せよ。

招待客番号 X_i を持つ人物がその時点のゲストリストに含まれていれば Yes を、含まれていなければ No を出力せよ。


入力例 1

5
1 10
2 10
2 3
1 3
2 3

出力例 1

Yes
No
Yes

入力例 2

7
2 100
1 50
2 50
1 100
2 100
2 75
2 50

出力例 2

No
Yes
Yes
No
Yes

入力例 3

12
1 8
1 100
2 8
2 9
1 999999937
2 999999937
1 42
2 100
2 42
2 1000000000
1 1000000000
2 1000000000

出力例 3

Yes
No
Yes
Yes
Yes
No
Yes

入力例 4

24
2 500
1 500
1 123456789
2 1
2 500
1 1
2 1
1 999999999
2 123456789
2 999999998
1 777777777
1 250000000
2 777777777
2 250000000
2 100
1 100
2 100
1 314159265
2 314159265
2 271828182
1 271828182
2 271828182
2 999999999
2 123456

出力例 4

No
No
Yes
Yes
Yes
No
Yes
Yes
No
Yes
Yes
No
Yes
Yes
No

入力例 5

1
2 1000000000

出力例 5

No

Score : 300 pts

Problem Statement

Takahashi has been assigned as the receptionist for a large party.

Invited guests arrive at the party one after another. Each guest is assigned a guest number, which is an integer between 1 and 10^9 inclusive, and different guests are assigned different numbers. Takahashi records each arriving person on the guest list. He may also receive inquiries from the venue staff asking, "Has this person already arrived?"

The guest list is initially empty.

Takahashi performs Q operations in order. The i-th operation is represented by a pair of type T_i and guest number X_i, and is one of the following two types:

  • T_i = 1 (Record arrival): Add the person with guest number X_i to the guest list. It is guaranteed that X_i is not already in the guest list at the time this operation is performed.
  • T_i = 2 (Arrival inquiry): Check whether the person with guest number X_i is currently in the guest list.

For each operation where T_i = 2, determine whether the person with the specified guest number is in the guest list.

Constraints

  • 1 \leq Q \leq 4 \times 10^5
  • T_i \in \{1, 2\}
  • 1 \leq X_i \leq 10^9
  • For operations where T_i = 1, X_i is not already in the guest list at that time
  • There is at least one operation where T_i = 2
  • All input values are integers

Input

Q
T_1 X_1
T_2 X_2
\vdots
T_Q X_Q

The first line contains an integer Q representing the number of operations.

Of the following Q lines, the i-th line (1 \leq i \leq Q) contains an integer T_i representing the type of the i-th operation and an integer X_i representing the guest number, separated by a space.

Output

For each operation where T_i = 2, output the result on a separate line in the order the operations are performed.

If the person with guest number X_i is in the guest list at that time, output Yes; otherwise, output No.


Sample Input 1

5
1 10
2 10
2 3
1 3
2 3

Sample Output 1

Yes
No
Yes

Sample Input 2

7
2 100
1 50
2 50
1 100
2 100
2 75
2 50

Sample Output 2

No
Yes
Yes
No
Yes

Sample Input 3

12
1 8
1 100
2 8
2 9
1 999999937
2 999999937
1 42
2 100
2 42
2 1000000000
1 1000000000
2 1000000000

Sample Output 3

Yes
No
Yes
Yes
Yes
No
Yes

Sample Input 4

24
2 500
1 500
1 123456789
2 1
2 500
1 1
2 1
1 999999999
2 123456789
2 999999998
1 777777777
1 250000000
2 777777777
2 250000000
2 100
1 100
2 100
1 314159265
2 314159265
2 271828182
1 271828182
2 271828182
2 999999999
2 123456

Sample Output 4

No
No
Yes
Yes
Yes
No
Yes
Yes
No
Yes
Yes
No
Yes
Yes
No

Sample Input 5

1
2 1000000000

Sample Output 5

No
C - Splitting Logs

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 366 点

問題文

高橋君は、N 個の部品が一列に連結された丸太を持っています。部品には左から順に 1, 2, \ldots, N の番号が付けられており、部品 i の長さは A_i です。

隣接する部品の間には境目があり、その箇所は N - 1 箇所あります。すなわち、部品 i と部品 i + 1 の間の境目 (1 \leq i \leq N - 1) です。高橋君はこれらの境目の中から K 箇所を選んで切断し、丸太を K + 1 個の断片に分割します。

各断片の長さは、その断片に含まれる部品の長さの合計で定まります。K + 1 個の断片の長さの最大値を M とします。

切断箇所の選び方を最適にしたとき、M の値として達成できる最小値を求めてください。

制約

  • 2 \leq N \leq 2 \times 10^5
  • 1 \leq K \leq N - 1
  • 1 \leq A_i \leq 10^9
  • 入力はすべて整数である。

入力

N K
A_1 A_2 \ldots A_N
  • 1 行目には、部品の数を表す整数 N と、切断箇所の数を表す整数 K が、空白区切りで与えられる。
  • 2 行目には、各部品の長さを表す整数 A_1, A_2, \ldots, A_N が、空白区切りで与えられる。

出力

切断箇所を最適に選んだときの、K + 1 個の断片の長さの最大値 M の最小値を 1 行で出力せよ。


入力例 1

5 2
3 5 4 7 6

出力例 1

11

入力例 2

4 1
1 2 3 4

出力例 2

6

入力例 3

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

出力例 3

19

入力例 4

20 5
14 7 23 11 5 19 8 30 12 6 17 25 3 9 21 16 28 4 13 10

出力例 4

55

入力例 5

2 1
1000000000 1000000000

出力例 5

1000000000

Score : 366 pts

Problem Statement

Takahashi has a log consisting of N parts connected in a row. The parts are numbered 1, 2, \ldots, N from left to right, and the length of part i is A_i.

There are boundaries between adjacent parts, and there are N - 1 such boundaries. Namely, the boundary between part i and part i + 1 (1 \leq i \leq N - 1). Takahashi chooses K of these boundaries to cut, dividing the log into K + 1 fragments.

The length of each fragment is determined by the sum of the lengths of the parts contained in that fragment. Let M be the maximum length among the K + 1 fragments.

Find the minimum possible value of M when the cut positions are chosen optimally.

Constraints

  • 2 \leq N \leq 2 \times 10^5
  • 1 \leq K \leq N - 1
  • 1 \leq A_i \leq 10^9
  • All input values are integers.

Input

N K
A_1 A_2 \ldots A_N
  • The first line contains an integer N representing the number of parts and an integer K representing the number of cuts, separated by a space.
  • The second line contains integers A_1, A_2, \ldots, A_N representing the lengths of the parts, separated by spaces.

Output

Print in one line the minimum value of M, the maximum length among the K + 1 fragments, when the cut positions are chosen optimally.


Sample Input 1

5 2
3 5 4 7 6

Sample Output 1

11

Sample Input 2

4 1
1 2 3 4

Sample Output 2

6

Sample Input 3

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

Sample Output 3

19

Sample Input 4

20 5
14 7 23 11 5 19 8 30 12 6 17 25 3 9 21 16 28 4 13 10

Sample Output 4

55

Sample Input 5

2 1
1000000000 1000000000

Sample Output 5

1000000000
D - Meeting Room Reservation

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 400 点

問題文

高橋君はオフィスの会議室管理を担当しています。今日は N 件の会議が予定されており、すべての会議をいずれかの会議室に割り当てる必要があります。

N 件の会議には番号 1 から N が付けられています。会議 i(1 \leq i \leq N)は時刻 S_i に開始し、時刻 E_i に終了します。各会議は半開区間 [S_i, E_i) の間、会議室を占有します。

2 つの会議 i, j が同じ会議室に割り当てられるためには、区間 [S_i, E_i) と [S_j, E_j) が共通部分を持たないことが必要です。特に、ある会議の終了時刻と別の会議の開始時刻が一致する場合、それらは同じ会議室で連続して行うことができます。

オフィスには十分な数の会議室が利用可能ですが、高橋君はできるだけ少ない会議室で全 N 件の会議をまかないたいと考えています。

各会議をちょうど 1 つの会議室に割り当て、どの会議室においても時間区間が重なる会議が存在しないようにするとき、使用する会議室の数の最小値を求めてください。

制約

  • 1 \leq N \leq 2 \times 10^5
  • 0 \leq S_i < E_i \leq 10^9
  • 入力はすべて整数である。
  • 開始時刻と終了時刻の組が同一である会議が複数存在することもある。

入力

N
S_1 E_1
S_2 E_2
\vdots
S_N E_N
  • 1 行目には、会議の件数を表す整数 N が与えられる。
  • 2 行目から N + 1 行目では、各会議の開始時刻と終了時刻が与えられる。1 + i 行目(1 \leq i \leq N)には、会議 i の開始時刻 S_i と終了時刻 E_i がスペース区切りで与えられる。

出力

全 N 件の会議を割り当てるために必要な会議室の最小数を 1 行で出力せよ。


入力例 1

3
1 4
2 6
4 7

出力例 1

2

入力例 2

4
1 5
2 6
3 7
4 8

出力例 2

4

入力例 3

10
0 5
1 3
2 8
3 6
5 10
6 9
7 12
8 11
9 14
1 4

出力例 3

4

入力例 4

15
6 14
7 11
8 12
9 13
10 15
0 3
1 4
3 7
14 20
15 18
16 22
20 25
11 16
4 6
18 24

出力例 4

5

入力例 5

1
0 1000000000

出力例 5

1

Score : 400 pts

Problem Statement

Takahashi is in charge of managing the meeting rooms at his office. Today, N meetings are scheduled, and all meetings must be assigned to some meeting room.

The N meetings are numbered from 1 to N. Meeting i (1 \leq i \leq N) starts at time S_i and ends at time E_i. Each meeting occupies a meeting room during the half-open interval [S_i, E_i).

For two meetings i, j to be assigned to the same meeting room, the intervals [S_i, E_i) and [S_j, E_j) must not overlap. In particular, if the end time of one meeting coincides with the start time of another meeting, they can be held consecutively in the same meeting room.

The office has a sufficient number of meeting rooms available, but Takahashi wants to accommodate all N meetings using as few meeting rooms as possible.

Assign each meeting to exactly one meeting room such that no meeting room contains meetings with overlapping time intervals. Find the minimum number of meeting rooms required.

Constraints

  • 1 \leq N \leq 2 \times 10^5
  • 0 \leq S_i < E_i \leq 10^9
  • All input values are integers.
  • There may be multiple meetings with the same pair of start time and end time.

Input

N
S_1 E_1
S_2 E_2
\vdots
S_N E_N
  • The first line contains an integer N, representing the number of meetings.
  • From the 2nd line to the (N + 1)-th line, the start time and end time of each meeting are given. The (1 + i)-th line (1 \leq i \leq N) contains the start time S_i and end time E_i of meeting i, separated by a space.

Output

Print in one line the minimum number of meeting rooms required to assign all N meetings.


Sample Input 1

3
1 4
2 6
4 7

Sample Output 1

2

Sample Input 2

4
1 5
2 6
3 7
4 8

Sample Output 2

4

Sample Input 3

10
0 5
1 3
2 8
3 6
5 10
6 9
7 12
8 11
9 14
1 4

Sample Output 3

4

Sample Input 4

15
6 14
7 11
8 12
9 13
10 15
0 3
1 4
3 7
14 20
15 18
16 22
20 25
11 16
4 6
18 24

Sample Output 4

5

Sample Input 5

1
0 1000000000

Sample Output 5

1
E - Grid Filling

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 433 点

問題文

高橋君は H 行 W 列のグリッドを持っています。上から i 行目 (1 \leq i \leq H)、左から j 列目 (1 \leq j \leq W) のマスを (i, j) と表します。マス (i, j) の値は整数 A_{i,j} です。

高橋君は、行の集合 R \subseteq \{1, 2, \ldots, H\} と列の集合 C \subseteq \{1, 2, \ldots, W\} を自由に選びます。R, C はそれぞれ空集合でも構いません。

マス (i, j) が塗りつぶされるとは、i \in R または j \in C の少なくとも一方が成り立つことをいいます。塗りつぶされたマスの値の合計を S とします。すなわち、

S = \sum_{\substack{(i,j) \\ i \in R \text{ or } j \in C}} A_{i,j}

です。塗りつぶされるマスが存在しない場合(R = C = \emptyset の場合)は S = 0 とします。

R と C のすべての選び方を考えたときの S の最大値を求めてください。

> 補足(包除原理による等価な表現): 上の S は次のようにも計算できます。

>

> S = \sum_{i \in R} \sum_{j=1}^{W} A_{i,j} + \sum_{j \in C} \sum_{i=1}^{H} A_{i,j} - \sum_{i \in R} \sum_{j \in C} A_{i,j}

制約

  • 1 \leq H \leq 19
  • 1 \leq W \leq 19
  • -10^9 \leq A_{i,j} \leq 10^9
  • 入力はすべて整数である

入力

入力は以下の形式で与えられます。

H W
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 行目にはグリッドの行数 H と列数 W が、2 行目以降の H 行には各マスの値 A_{i,j} が、それぞれスペース区切りで与えられます。

出力

S の最大値を一行で出力してください。


入力例 1

2 3
5 -2 4
-3 6 -1

出力例 1

13

入力例 2

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

出力例 2

0

入力例 3

5 6
3 -5 2 7 -1 4
-4 6 -2 1 8 -3
5 -3 0 -6 4 2
-7 2 9 -1 -5 6
1 -8 3 5 -2 7

出力例 3

50

入力例 4

8 8
1000000000 -1000000000 5 -7 8 -9 10 -11
-1000000000 1000000000 -6 7 -8 9 -10 12
13 -14 1000000000 -1000000000 15 -16 17 -18
-19 20 -1000000000 1000000000 -21 22 -23 24
25 -26 27 -28 1000000000 -1000000000 29 -30
-31 32 -33 34 -1000000000 1000000000 -35 36
37 -38 39 -40 41 -42 1000000000 -1000000000
-43 44 -45 46 -47 48 -1000000000 1000000000

出力例 4

4000000321

入力例 5

1 1
1000000000

出力例 5

1000000000

Score : 433 pts

Problem Statement

Takahashi has a grid with H rows and W columns. The cell at the i-th row from the top (1 \leq i \leq H) and the j-th column from the left (1 \leq j \leq W) is denoted as (i, j). The value of cell (i, j) is the integer A_{i,j}.

Takahashi freely chooses a set of rows R \subseteq \{1, 2, \ldots, H\} and a set of columns C \subseteq \{1, 2, \ldots, W\}. Each of R and C may be the empty set.

A cell (i, j) is painted if at least one of i \in R or j \in C holds. Let S be the sum of the values of the painted cells. That is,

S = \sum_{\substack{(i,j) \\ i \in R \text{ or } j \in C}} A_{i,j}

If no cells are painted (i.e., R = C = \emptyset), then S = 0.

Find the maximum value of S over all possible choices of R and C.

> Note (equivalent expression using inclusion-exclusion principle): The above S can also be computed as follows.

>

> S = \sum_{i \in R} \sum_{j=1}^{W} A_{i,j} + \sum_{j \in C} \sum_{i=1}^{H} A_{i,j} - \sum_{i \in R} \sum_{j \in C} A_{i,j}

Constraints

  • 1 \leq H \leq 19
  • 1 \leq W \leq 19
  • -10^9 \leq A_{i,j} \leq 10^9
  • All input values are integers.

Input

The input is given in the following format.

H W
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}

The first line contains the number of rows H and the number of columns W of the grid. The following H lines contain the values A_{i,j} of each cell, separated by spaces.

Output

Print the maximum value of S in a single line.


Sample Input 1

2 3
5 -2 4
-3 6 -1

Sample Output 1

13

Sample Input 2

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

Sample Output 2

0

Sample Input 3

5 6
3 -5 2 7 -1 4
-4 6 -2 1 8 -3
5 -3 0 -6 4 2
-7 2 9 -1 -5 6
1 -8 3 5 -2 7

Sample Output 3

50

Sample Input 4

8 8
1000000000 -1000000000 5 -7 8 -9 10 -11
-1000000000 1000000000 -6 7 -8 9 -10 12
13 -14 1000000000 -1000000000 15 -16 17 -18
-19 20 -1000000000 1000000000 -21 22 -23 24
25 -26 27 -28 1000000000 -1000000000 29 -30
-31 32 -33 34 -1000000000 1000000000 -35 36
37 -38 39 -40 41 -42 1000000000 -1000000000
-43 44 -45 46 -47 48 -1000000000 1000000000

Sample Output 4

4000000321

Sample Input 5

1 1
1000000000

Sample Output 5

1000000000