Cormen Boy and ACM ICPC

3.5

22 votes
Easy
Problem

ACM ICPC season is going on. This year our HOD has appointed Neil Gohain (aka Cormen boy) one of the world's best living algorithmist to be one of the coach.

But Neil Gohain came to know that only k X n coders are left as all others have already formed team and he is allowed to take only n/2 coders in his team. All coders have some rating associated with them. Neil Gohain have only k days to form his team as after kth day another coach will come. Each day unique batch of n coders come for interview. In the interviewing room n coders are seated as shown in figure.

enter image description here

He can take interview of any coder from only either of the two ends but after interviewing he can't reject any coder(as coders hates rejection) i.e., he can take interview of at most n/2 coders each day. Also in his team he can't have coders from different batches i.e., he need to select n/2 coders from exactly one batch. Fortunately he knows everyone's rating. Help him finding the batch that makes his team strength maximum i.e., sum of ratings of team members.

Input

First line of the input contains two integers n and k (2 ≤ n ≤ 1 000, 1 ≤ k ≤ 100) — number of coders in each batch and the number of days he have respectively.

Then follow k lines, each containing n integers ai (1≤ ai ≤ 109) — rating of each coder.

Note : n is always even.

Output

Print the maximum possible value of the sum of ratings of team members.

Time Limit: 1
Memory Limit: 256
Source Limit:
Explanation

Day 1 : Coders with ratings 15, 12, 4 can be chosen

Day 2 : Coders with ratings 14, 9, 9 can be chosen

Day 3 : Coders with ratings 6, 5, 4 can be chosen

Strongest team is formed on day 2 with strength 32.

Editor Image

?