Virtual contest is a way to take part in past contest, as close as possible to participation on time. It is supported only ICPC mode for virtual contests.
If you've seen these problems, a virtual contest is not for you - solve these problems in the archive.
If you just want to solve some problem from a contest, a virtual contest is not for you - solve this problem in the archive.
Never use someone else's code, read the tutorials or communicate with other person during a virtual contest.

bitmasks

brute force

graph matchings

*2700

No tag edit access

The problem statement has recently been changed. View the changes.

×
C. Party

time limit per test

2 secondsmemory limit per test

4 megabytesinput

standard inputoutput

standard outputNote the unusual memory limit for the problem.

People working in MDCS (Microsoft Development Center Serbia) like partying. They usually go to night clubs on Friday and Saturday.

There are *N* people working in MDCS and there are *N* clubs in the city. Unfortunately, if there is more than one Microsoft employee in night club, level of coolness goes infinitely high and party is over, so club owners will never let more than one Microsoft employee enter their club in the same week (just to be sure).

You are organizing night life for Microsoft employees and you have statistics about how much every employee likes Friday and Saturday parties for all clubs.

You need to match people with clubs maximizing overall sum of their happiness (they are happy as much as they like the club), while half of people should go clubbing on Friday and the other half on Saturday.

Input

The first line contains integer *N* — number of employees in MDCS.

Then an *N* × *N* matrix follows, where element in *i*-th row and *j*-th column is an integer number that represents how much *i*-th person likes *j*-th club’s Friday party.

Then another *N* × *N* matrix follows, where element in *i*-th row and *j*-th column is an integer number that represents how much *i*-th person likes *j*-th club’s Saturday party.

- 2 ≤
*N*≤ 20 -
*N*is even - 0 ≤ level of likeness ≤ 10
^{6} - All values are integers

Output

Output should contain a single integer — maximum sum of happiness possible.

Examples

Input

4

1 2 3 4

2 3 4 1

3 4 1 2

4 1 2 3

5 8 7 1

6 9 81 3

55 78 1 6

1 1 1 1

Output

167

Note

Here is how we matched people with clubs:

Friday: 1st person with 4th club (4 happiness) and 4th person with 1st club (4 happiness).

Saturday: 2nd person with 3rd club (81 happiness) and 3rd person with 2nd club (78 happiness).

4+4+81+78 = 167

Codeforces (c) Copyright 2010-2024 Mike Mirzayanov

The only programming contests Web 2.0 platform

Server time: Apr/17/2024 08:18:07 (l3).

Desktop version, switch to mobile version.

Supported by

User lists

Name |
---|