This page is still under construction.

Parts of this page are still being built. What you see may change.

Red segments and blue segments

Time limit2sMemory limit512 MB

Summary
Color N points red or blue, then draw non-crossing same-color segments so that no red and blue segment touch; maximize total segment scores.
Level

Hard8 of 10

Topics
Dynamic programming, Geometry, Backtracking, Combinatorics
Solved
No attempts yet

Problem

There are NN distinct points on a plane, numbered from 0 to N−1N-1.

You collect a score by drawing segments between points. The game runs in two stages. In the first stage you paint every point red or blue. In the second stage you draw zero or more segments.

A segment joins two points of the same color, and the segment takes the color of those points.

Two segments of the same color may touch or cross. Two segments of different colors may not touch and may not cross. A red segment and a blue segment must share no point at all, and an endpoint of one may not lie on the other.

The restriction applies only to the segments you actually draw. A red segment may pass through a blue point as long as you draw no blue segment that touches that point.

The red segment joining point ii and point jj scores red[i][j], and the blue segment joining the same two points scores blue[i][j].

Write a program that finds the largest score you can collect by drawing segments.

Input

The first line contains the number of points NN. (2≤N≤202 \le N \le 20)

Each of the next NN lines contains the coordinates xx and yy of one point, starting with point 0. (−1000≤x,y≤1000-1000 \le x, y \le 1000) No two points share the same coordinates.

The next NN lines contain the score matrix of the red segments. The jj-th number on the ii-th of those lines is red[i][j]. The following NN lines contain the score matrix blue[i][j] of the blue segments in the same layout. Every red[i][j] and every blue[i][j] is an integer between 0 and 100,000.

For every ii, red[i][i] and blue[i][i] are 0, and for every ii and jj, red[i][j] equals red[j][i] and blue[i][j] equals blue[j][i].

Output

Print the maximum score you can collect on the first line.

Hint

In the first example you paint every point blue and draw all six blue segments, which gives 2+3+7+4+6+5=272+3+7+4+6+5 = 27.

Examples4

  1. Example 1

    Input
    4
    0 1
    1 0
    0 -1
    -1 0
    0 1 2 3
    1 0 6 4
    2 6 0 5
    3 4 5 0
    0 2 3 7
    2 0 4 6
    3 4 0 5
    7 6 5 0
    
    Expected output
    27
    
  2. Example 2

    Input
    2
    0 1
    1 0
    0 101
    101 0
    0 100
    100 0
    
    Expected output
    101
    
  3. Example 3

    Input
    6
    -3 0
    -1 -2
    -1 2
    1 -2
    1 2
    3 0
    0 2 1 2 1 2
    2 0 2 1 2 1
    1 2 0 2 1 2
    2 1 2 0 2 1
    1 2 1 2 0 2
    2 1 2 1 2 0
    0 0 0 0 0 0
    0 0 0 0 0 0
    0 0 0 21 0 0
    0 0 21 0 0 0
    0 0 0 0 0 0
    0 0 0 0 0 0
    
    Expected output
    25
    
  4. Example 4

    Input
    6
    -100 0
    100 0
    0 100
    -10 10
    10 10
    0 1
    0 96 96 25 25 25
    96 0 96 25 25 25
    96 96 0 25 25 25
    25 25 25 0 10 10
    25 25 25 10 0 10
    25 25 25 10 10 0
    0 30 30 20 20 20
    30 0 30 20 20 20
    30 30 0 20 20 20
    20 20 20 0 86 86
    20 20 20 86 0 86
    20 20 20 86 86 0
    
    Expected output
    546