import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.HashMap; import java.util.LinkedList; import java.util.Scanner; public class Main { public static class Edge implements Comparable { int from, to, cost; public Edge(int from, int to, int cost){ this.from = from; this.to = to; this.cost = cost; } @Override public int compareTo(Edge o) { return Integer.compare(this.cost, o.cost); } } public static int answer = Integer.MAX_VALUE; public static void rec(int[] match, int prev, int matched, int n, ArrayList> adj, int opt){ if(opt >= answer){ return; } //System.out.println(answer); int from = prev + 1; while(from < n && match[from] >= 0){ from++; } //System.out.println(from); for(final Edge edge : adj.get(from)){ final int to = edge.to; if(match[to] >= 0){ continue; } final int next_opt = opt + edge.cost; final int next_matched = matched + 2; match[to] = from; match[from] = to; if(next_matched < n){ rec(match, from, next_matched, n, adj, next_opt); } else{ answer = Math.min(answer, next_opt); } match[to] = match[from] = -1; } } public static int solve_dfs(int n, int[][] adj){ ArrayList> sorted = new ArrayList>(); for(int i = 0; i < n; i++){ ArrayList inner = new ArrayList(); for(int j = i + 1; j < n; j++){ inner.add(new Edge(i, j, adj[i][j])); } Collections.sort(inner); sorted.add(inner); } int[] match = new int[n]; Arrays.fill(match, -1); rec(match, -1, 0, n, sorted, 0); return answer; } public static int solve_DP(int n, int[][] adj){ int[] DP = new int[1 << n]; Arrays.fill(DP, Integer.MAX_VALUE / 2 - 1); DP[0] = 0; for(int bit = 0; bit < (1 << n); bit++){ //System.out.println(bit); int i = 0; for (; (bit & (1 << i)) != 0; ++i); final int fst = 1 << i; for(int j = i + 1; j < n; j++){ final int snd = 1 << j; final int next_bit = bit | fst | snd; DP[next_bit] = Math.min(DP[next_bit], DP[bit] + adj[i][j]); } } return DP[(1 << n) - 1]; } public static void main(String[] args) { Scanner sc = new Scanner(System.in); final int n = sc.nextInt(); final int max = 1000; int[][] adj = new int[n][n]; for(int i = 0; i < n; i++){ for(int j = 0; j < n; j++){ adj[i][j] = max - sc.nextInt(); } } //final int solve = solve_DP(n, adj); final int solve = solve_dfs(n, adj); System.out.println(max * (n / 2) - solve); } }