#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define ld long double
#define REP(i,a,b) for(int i=a;i<b;++i)
#define neg1(m) memset(m,-1,sizeof(m))

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int n=5,p[]={0,1,2,3,4},a[5][5],ans=0;
    REP(i,0,n)
        REP(j,0,n)
            cin>>a[i][j];

    do
    {
        int val=a[p[0]][p[1]]+a[p[1]][p[0]];
        val+=a[p[1]][p[2]]+a[p[2]][p[1]];
        val+=(a[p[2]][p[3]]+a[p[3]][p[2]])*2;
        val+=(a[p[3]][p[4]]+a[p[4]][p[3]])*2;

        if(val>ans)
            ans=val;

    } while (next_permutation(p,p+n));

    cout<<ans;
    return 0;
}

#include<iostream>

#include<cstdio>

using namespace std;

int a[6][6], x[6], res = 0;
bool free[6];

void update()
{
    int tmp;

    tmp = a[x[1]][x[2]] + 2 * (a[x[3]][x[4]] + a[x[4]][x[5]]) + a[x[2]][x[3]];
    if(res < tmp) res = tmp;
}

void BackTrack(int i)
{
    for(int j = 1; j <= 5; j++)
    if(!free[j])
    {
        free[j] = true;

        x[i] = j;

        if(i == 5) update();
        else BackTrack(i + 1);

        free[j] = false;
    }
}

int main()
{
    //freopen("in.txt", "r", stdin);

    for(int i = 1; i <= 5; i++)
    for(int j = 1; j <= 5; j++)
    scanf("%d", &a[i][j]);

    for(int i = 1; i <= 5; i++)
    for(int j = 1; j <= 5; j++)
    {
        int tmp = a[i][j] + a[j][i];

        a[i][j] = a[j][i] = tmp;
    }

    for(int i = 1; i <= 5; i++)
    free[i] = false;

    BackTrack(1);

    cout << res / 2;

}

// Template by [thunder_blade]
// IIIT ALLAHABAD
// includes :)

#include<bits/stdc++.h>
using namespace std;
#define TEST  int test_case; cin>>test_case; while(test_case--)
#define all(v) (v).begin(),(v).end()
#define fi  first
#define se  second
#define pb push_back
#define mp make_pair
#define ll long long int
#define SPEED ios_base::sync_with_stdio(false);  cin.tie(0);  cout.tie(0);
#define pi(x) printf("%d\n",x)
#define pl(x) printf("%lld\n",x)

#define pf(x) printf("%f\n",x)
#define ps(x) printf("%s\n",x)
#define si(x) scanf("%d",&x)
#define sl(x) scanf("%lld",&x)
#define sf(x) scanf("%f",&x)
#define ss(x) scanf("%s",x)
#define pis(x) printf("%d ",x)
#define pfs(x) printf("%f ",x)
#define pss(x) printf("%s ",x)
#define FOR(i,a,b) for(i=a;i<b;i++)
vector<int>v;
int arr[505][505];
int main()
{
	int i,j;
	FOR(i,0,5){
		v.pb(i+1);
		FOR(j,0,5){
			si(arr[i+1][j+1]);

		}
	}
	int maxi = 0, sum=0;
	do{
		sum=0;
		FOR(i,0,4){
			FOR(j,i,4){
				sum += (arr[v[j]][v[j+1]] + arr[v[j+1]][v[j]]);
				j++;
			}

		}
		maxi = max(sum, maxi);
	}while(next_permutation(all(v)));

	pi(maxi);

	return 0;
}

#include<map>
#include<new>
#include<set>
#include<cmath>
#include<queue>
#include<stack>
#include<ctime>
#include<cstdio>
#include<memory>
#include<vector>
#include<bitset>
#include<cstdlib>
#include<cstring>
#include<utility>
#include<iostream>
#include<algorithm>
using namespace std;

int n=5;
int g[11][11];
int t[11];

int main()
{
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=n;j++)
		{
			cin>>g[i][j];
		}
	}
	for(int i=1;i<=n;i++)
	{
		t[i]=i;
	}
	int mx=-1;
	do
	{
		int temp=g[t[1]][t[2]]+g[t[2]][t[1]]+g[t[2]][t[3]]+g[t[3]][t[2]]+
				2*(g[t[3]][t[4]]+g[t[4]][t[3]]+g[t[4]][t[5]]+g[t[5]][t[4]]);
		mx=max(mx,temp);
		if(t[1]==5&&t[2]==4&&t[3]==3&&t[4]==2&&t[5]==1) break;
		next_permutation(t+1,t+1+n);
	}
	while(1);
	cout<<mx<<endl;
	return 0;
}

#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <memory.h>
#include <cstring>
#include <math.h>

using namespace std;
int main() {
  ios_base::sync_with_stdio(0);
  int g[5][5], happiness = 0, mh = 0;
  for (int i = 0; i < 5; i++)
    for (int j = 0; j < 5; j++)
      cin >> g[i][j];
  int p[] = { 0, 1, 2, 3, 4 };
  do{
    happiness = (g[p[0]][p[1]] + g[p[2]][p[3]] + g[p[1]][p[2]] + g[p[3]][p[4]] +
                 g[p[2]][p[3]] + g[p[3]][p[4]] + g[p[1]][p[0]] + g[p[3]][p[2]] +
                 g[p[2]][p[1]] + g[p[4]][p[3]] + g[p[3]][p[2]] + g[p[4]][p[3]]);

    if (happiness > mh) {
      mh = happiness;
    }
  }
  while (std::next_permutation(p, p + 5));
  cout << mh;
  return 0;
}

#include<cstdio>
#include<iostream>
#include<algorithm>

using namespace std;

int a[6][6];

int Sum(int x[]){
  int k;

  k=a[x[0]][x[1]]+a[x[1]][x[2]]+2*(a[x[2]][x[3]]+a[x[3]][x[4]]);
  k=k+a[x[1]][x[0]]+a[x[2]][x[1]]+2*(a[x[3]][x[2]]+a[x[4]][x[3]]);

  return k;
}

main(){
//freopen("0.in","r",stdin);
//freopen("0.out","w",stdout);

  int n,i,j,x,s,m,p,im,pp,M;
  int b[6];

  n=5;
  for(i=0;i<n;i++)
    for(j=0;j<n;j++)
      cin>>a[i][j];
  for(i=0;i<n;i++)
    b[i]=i;

  pp=0;
  M=0;
  do{
    p=Sum(b);
    if(p>M) M=p;
  }while(next_permutation(b,b+n));
  cout<<M<<endl;
}

#include <bits/stdc++.h>
using namespace std;

int a[5][5], p[] = {0, 1, 2, 3, 4}, res = 0;

int main(){
for(int i = 0; i < 5; i++) for(int j = 0; j < 5; j++) cin >> a[i][j];
do{
int k = 0;
for(int i = 0; i < 5; i++) for(int j = i; j + 1 < 5; j += 2) k += a[p[j]][p[j + 1]] + a[p[j + 1]][p[j]];
res = max(res, k);
}while(next_permutation(p, p + 5));
cout << res;
}

#include <iostream>
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <vector>
#include <queue>
#include <string>

using namespace std;

int G[5][5];
int a;
int s[5];
int per[5];
void dfs(int idx)
{
    if(idx == 5)
    {
        int t = 0;
        int a1 = per[0];
        int a2 = per[1];
        int a3 = per[2];
        int a4 = per[3];
        int a5 = per[4];
        t = G[a1][a2]+G[a2][a1]+2*(G[a3][a4]+G[a4][a3])+G[a2][a3]+G[a3][a2]+2*(G[a4][a5]+G[a5][a4]);
        a = max(a, t);
        return;
    }
    for(int i = 0; i < 5; ++i)
    {
        if(s[i] == 0)
        {
            s[i] = 1;
            per[idx] = i;
            dfs(idx+1);
            s[i] = 0;
        }
    }
}

int main()
{
    for(int i = 0; i < 5; ++i)
        for(int j = 0; j < 5; ++j)
            cin>>G[i][j];
    a = 0;
    memset(s, 0, sizeof(s));
    dfs(0);
    cout<<a<<endl;
}

#include <iostream>
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <vector>
#include <queue>
#include <string>

using namespace std;

int arr[130][5];
int per[5];
int status[5];
int idx;
void dfs(int pos)
{
    if(pos == 5)
    {
        for(int i = 0; i < 5; ++i)
            arr[idx][i] = per[i];
        idx++;
        return;
    }
    for(int i = 0; i < 5; ++i)
    {
        if(status[i] == 0)
        {
            status[i] = 1;
            per[pos] = i;
            dfs(pos+1);
            status[i] = 0;
        }
    }
}
int main()
{
    int G[5][5];
    for(int i = 0; i < 5; ++i)
        for(int j = 0; j < 5; ++j)
            cin>>G[i][j];
    int ans = 0;
    idx = 0;
    memset(status, 0, sizeof(status));
    dfs(0);
    for(int i = 0; i < idx; ++i)
    {
        int t = 0;
        int a1 = arr[i][0];
        int a2 = arr[i][1];
        int a3 = arr[i][2];
        int a4 = arr[i][3];
        int a5 = arr[i][4];
        t = G[a1][a2]+G[a2][a1]+2*(G[a3][a4]+G[a4][a3])+G[a2][a3]+G[a3][a2]+2*(G[a4][a5]+G[a5][a4]);
        ans = max(ans, t);

    }
    cout<<ans<<endl;

    return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define N 100005
#define ll long long
#define ull unsigned long long
#define loop1(i, j, k, step) for (int i = j; i < k; i += step)
#define loop(i, j, k) for (int i = j; i < k; i++)
#define rloop1(i, j, k, step) for (int i = j; i >= k; i -= step)
#define rloop(i, j, k) for (int i = j; i >= k; i--)
#define rep(i, k) for (int i = (0); i < (k); i++)
#define rrep(i, k) for (int i = k - 1; i >= 0; i--)

#define forall(it, l) for (auto it = l.begin(); it != l.end(); it++)
#define mp make_pair
#define pb push_back
#define pop pop_back
#define F first
#define S second
#define sz(x) (int)(x).size()
#define endl "\n"
#define Max (int)INT_MAX
#define Min (int)INT_MIN
#define MEM(a, b) memset(a, (b), sizeof(a))
#define fast_io ios_base::sync_with_stdio(0), cin.tie(NULL)
#define lin puts("");
typedef vector<int> vi;
typedef pair<int, int> pi;
typedef vector<ll> vl;
typedef pair<ll, ll> pll;
//char ch[101][101];
// char c;
// int arr[10000], brr[105];
int arr[10][10], p[10];
void input()
{
    rep(i, 5)
    {
        int sum = 0;
        int j;
        rep(j, 5)
        {
            cin >> arr[i][j];
        }
        p[i] = i;
    }
}
void solve()
{
    input();
    int ans = 0;
    do
    {
        int tmp = arr[p[0]][p[1]] + arr[p[1]][p[0]];
        tmp += arr[p[2]][p[3]] + arr[p[3]][p[2]];
        tmp += arr[p[1]][p[2]] + arr[p[2]][p[1]];
        tmp += arr[p[3]][p[4]] + arr[p[4]][p[3]];
        tmp += arr[p[2]][p[3]] + arr[p[3]][p[2]];
        tmp += arr[p[3]][p[4]] + arr[p[4]][p[3]];
        if (tmp > ans)
        {
            ans = tmp;
        }
    } while (next_permutation(p, p + 5));
    cout << ans << endl;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    auto start = clock();
    fast_io;
    //freopen("test.txt", "r", stdin);
    int t;
    t = 1;
    // cin >> t;
    while (t--)
    {
        solve();
    }
    auto stop = clock();
    cerr << "time taken:" << double(stop - start) / double(CLOCKS_PER_SEC) << " s" << endl;
    return 0;
}
//

#include<iostream>
#include<cstdio>
#include<algorithm>
#define gc getchar

/*#ifndef ONLINE_JUDGE
#define gc getchar
#else
#define gc getchar_unlocked
#endif // ONLINE_JUDGE*/

using namespace std;

long long int input(){
    char c=gc();
    while(c<'0'||c>'9') c=gc();
    long long int ans=0;
    while(c>='0'&&c<='9'){
        ans=(ans<<3)+(ans<<1)+c-'0';
        c=gc();
    }
    return (ans);
}

int main(){
long long int permut[5]={0,1,2,3,4},ans=0;
long long int g[5][5],i,j;
for(i=0;i<5;i++){
    for(j=0;j<5;j++){
        g[i][j]=input();
    }
}
while(next_permutation(permut,permut+5)){
    ans=max(ans,2*(g[permut[2]][permut[3]]+g[permut[3]][permut[2]])+2*(g[permut[3]][permut[4]]+g[permut[4]][permut[3]])+g[permut[0]][permut[1]]+g[permut[1]][permut[0]]+g[permut[1]][permut[2]]+g[permut[2]][permut[1]]);
}
ans=max(ans,2*(g[permut[2]][permut[3]]+g[permut[3]][permut[2]])+2*(g[permut[3]][permut[4]]+g[permut[4]][permut[3]])+g[permut[0]][permut[1]]+g[permut[1]][permut[0]]+g[permut[1]][permut[2]]+g[permut[2]][permut[1]]);
cout<<ans<<"\n";
return 0;
}

#include <bits/stdc++.h>

using namespace std;

int test[10];

int arr1[10][10];

int main () {
    for (int i = 1; i < 6; i++) {
        test[i] = i;
        for (int j = 1; j < 6; j++)
            cin >> arr1[i][j];
    }

    int maxi = 0, x = 0;

    do {
        x=0;
        for (int i = 1; i < 6; i++)
            for (int j = i; j < 6; j += 2){
                x+= arr1[test[j]][test[j + 1]] + arr1[test[j + 1]][test[j]];}
        maxi = max (maxi,x);
    } while (next_permutation (test+1, test+6));

    cout << maxi;

    return 0;
}

#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <string.h>
#include <stdlib.h>
#include <iterator>
#include <sstream>
#include <numeric>
#include <fstream>
#include <vector>
#include <cctype>
#include <math.h>
#include <deque>
#include <queue>
#include <stack>
#include <set>
#include <map>
//#include <windows.h>
using namespace std;

#define FRE(i,a,b) for(i = a; i <= b; i++)
#define FRL(i,a,b) for(i = a; i < b; i++)
#define mem(t, v) memset ((t) , v, sizeof(t))
#define all(x) x.begin(),x.end()
#define sf(n) scanf("%d", &n)
#define pf(n) printf("%d", n)
#define inf (1 << 29 - 1)
#define VI vector <int>
#define QI queue <int>
#define pb push_back
#define sz size()
#define pb push_back
#define mp make_pair
#define ins insert
#define fi first
#define se second
#define check(mask, k) (mask & (1 << k))
#define Set(mask, k) (mask | (1 << k))
#define read() freopen("c:\\Users\\User\\Desktop\\Input.txt", "r", stdin)
#define write() freopen("c:\\Users\\User\\Desktop\\Output.txt", "w", stdout)
#define MAX 110

//int dx[] = {+0,+0,+1,-1};
//int dy[] = {+1,-1,+0,+0};
//int dx[] = {-1,-1,-1,+0,+0,+1,+1,+1};
//int dy[] = {-1,+0,+1,-1,+1,-1,+0,+1};

typedef long long int LL;
typedef double db;
vector<int> v;
int data[10][10];

int calc()
{
    return data[v[1]][v[2]]+data[v[2]][v[1]]+data[v[3]][v[2]]+ data[v[2]][v[3]] + 2*data[v[3]][v[4]] + 2*data[v[4]][v[3]] + 2*data[v[4]][v[5]] + 2*data[v[5]][v[4]];
}

int main()
{
    //freopen("in.txt", "r", stdin);

    int i, j, k, t, cs, n, mx;

    FRE(i,1,5)
        FRE(j,1,5) sf(data[i][j]);

    FRE(i,0,5) v.pb(i);

    mx = calc();
    while(next_permutation(v.begin()+1, v.end()))
        mx = max(mx,calc());

    printf("%d\n", mx);
    return 0;
}

#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <string>
using namespace std;

int main() {
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);

    int a[5][5];
    for (int i = 0; i < 5; i++)
        for (int j = 0; j < 5; j++)
            cin >> a[i][j];

    int p[] = { 0, 1, 2, 3, 4 }, bestP[5], bestK = -1;
    do {
        int k = a[p[0]][p[1]] + a[p[1]][p[0]];
        k += a[p[2]][p[3]] + a[p[3]][p[2]];
        k += a[p[1]][p[2]] + a[p[2]][p[1]];
        k += a[p[3]][p[4]] + a[p[4]][p[3]];
        k += a[p[2]][p[3]] + a[p[3]][p[2]];
        k += a[p[3]][p[4]] + a[p[4]][p[3]];
        if (k > bestK) {
            bestK = k;
            copy(p, p + 5, bestP);
        }
    } while (next_permutation(p, p + 5));

    cout << bestK;
}

#include<iostream>
#include<vector>
#include<set>
#include<map>
#include<string>
#include<cmath>
#include<algorithm>
#include<cstring>
#include<numeric>
#include<cmath>
#include<iomanip>
#include<sstream>
#include<bitset>
#include<stack>
#include<queue>
#include<list>
#include <cstdlib>
using namespace std;
#define INT_MAX 2147483647
#define INT_MIN -2147483648
#define pb push_back
typedef long long LL;
typedef long double LD;
int main()
{
    int arr[5][5],t[5];
    for (int i = 0; i < 5; i++)
        for (int j = 0; j < 5; j++)
            cin >> arr[i][j];
    t[0] = 0, t[1] = 1, t[2] = 2, t[3] = 3, t[4] = 4;
    int ans = 0;
    do
    {
        // 1 2 3 4 5
        ans=max(ans,arr[t[0]][t[1]] + arr[t[1]][t[0]] + (arr[t[2]][t[3]] + arr[t[3]][t[2]]) * 2
            + arr[t[1]][t[2]] + arr[t[2]][t[1]] + (arr[t[3]][t[4]] + arr[t[4]][t[3]]) * 2);

    } while (next_permutation(t, t + 5));
    cout << ans << endl;

  //  system("pause");
    return 0;
}

#include<iostream>
#include<string>
#include<map>
#include<algorithm>
using namespace std;

 int main()
{

	int sum;
	int arr [5][5];
	for(int i=0;i<5;i++)
		for(int j=0;j<5;j++)
			cin>>arr[i][j];
	int arr2[9]={0,1,2,3,4,5};
	int max=0;
	do{
		sum=0;
	      sum=2*arr[arr2[3]][arr2[4]]+2*arr[arr2[4]][arr2[3]]+2*arr[arr2[0]][arr2[4]]+2*arr[arr2[4]][arr2[0]]
		  +arr[arr2[1]][arr2[2]]+arr[arr2[2]][arr2[1]]+arr[arr2[0]][arr2[2]]+arr[arr2[2]][arr2[0]];
		  if(sum>max)
			  max=sum;
	}while( next_permutation(arr2,arr2+5));
	cout<<max;
//system("pause");
	  return 0;
}

// youngjinp20
// 2020 03

#include <bits/stdc++.h>
using namespace std;

typedef long long ll;

int g[6][6];
bool used[6];

int dfs(int v, int prev, int depth) {
	int best = 0;
	used[v] = true;

	for (int i=1; i<=5; i++)
		if (!used[i])
			best = max(dfs(i, v, depth+1) + g[v][i] + g[i][v], best);

	if (depth == 3)
		best *= 2;
	used[v] = false;
	return best;
}

int main() {
	for (int i=1; i<=5; i++)
		for (int j=1; j<=5; j++)
			cin >> g[i][j];

	cout << dfs(0,0,0);

	return 0;
}

#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <cmath>
#include <map>
#include <cstring>
#include <string>
#include <stack>
#include <unordered_set>
using namespace std;

#pragma comment (linker, "/STACK:1000000000")

#define mp make_pair

int g[5][5];

int main()
{
    vector <int> a;
    int best = 0;
    for (int i = 0; i < 5; i++)
        for (int j = 0; j < 5; j++)
            cin >> g[i][j];
        for (int i = 0; i < 5; i++)
            a.push_back(i);
        while (true)
        {
            int cur = 0;
            for (int i = -1; i < 4; i++)
                for (int j = i + 1; j < 4; j += 2)
                cur += g[a[j]][a[j + 1]] + g[a[j + 1]][a[j]];
            best = max(best, cur);
            if (!next_permutation(a.begin(), a.end()))
                break;
        }
        cout << best;
    return 0;
}

#include<iostream>
using namespace std;
int main(){
    int g[5][5];

    for(int i=0;i<5;i++){
        for(int j=0;j<5;j++){
            cin>>g[i][j];
        }
    }
    int sum_max=0,sum;
    for(int a=1;a<=5;a++){
        for(int b=1;b<=5;b++){
            for(int c=1;c<=5;c++){
                for(int d=1;d<=5;d++){
                    for(int e=1;e<=5;e++){
                        if(a==b|| a==c || a==d || a==e || b==c || b==d || b==e || c==e || c==d || d==e ){
                            continue;
                        }
                        sum=0;
                        int happiness[5] = {0};

                        happiness[a-1]+=g[a-1][b-1];
                        happiness[b-1]+=g[b-1][a-1];
                        happiness[c-1]+=g[c-1][d-1];
                        happiness[d-1]+=g[d-1][c-1];

                        happiness[b-1]+=g[b-1][c-1];
                        happiness[c-1]+=g[c-1][b-1];
                        happiness[d-1]+=g[d-1][e-1];
                        happiness[e-1]+=g[e-1][d-1];

                        happiness[c-1]+=g[c-1][d-1];
                        happiness[d-1]+=g[d-1][c-1];

                        happiness[d-1]+=g[d-1][e-1];
                        happiness[e-1]+=g[e-1][d-1];

                        sum+=happiness[0]+happiness[1]+happiness[2]+happiness[3]+happiness[4];
                        if(sum>sum_max){
                            sum_max=sum;
                        }
                    }
                }
            }
        }
    }

    cout<<sum_max;
}

#pragma comment(linker, "/STACK:300000000")
#include "stdio.h"
#include "stdlib.h"
#include <iostream>
#include <set>
#include <math.h>
#include <map>
#include <unordered_map>
#include <vector>
#include <algorithm>
#include <utility>
#include <string>
#pragma warning(disable : 4996)

using namespace std;
#define ull unsigned long long int
#define ll long long int
#define MOD 1000000007ull
#define INF 99999999999999999

int g[6][6];
int a[6];

int comp_cost(int a1, int a2, int a3, int a4, int a5)
{
	int sum = g[a1][a2] + g[a2][a1] + g[a3][a4] + g[a4][a3];
	sum += g[a2][a3] + g[a3][a2] + g[a4][a5] + g[a5][a4];
	sum += g[a3][a4] + g[a4][a3];
	sum += g[a4][a5] + g[a5][a4];
	return sum;
}

int main()
{
	ios_base::sync_with_stdio(false);
	for (int i = 1; i < 6; i++)
	{
		for (int j = 1; j < 6; j++)
			cin >> g[i][j];
	}
	int max = 0;
	for (int a1 = 1; a1 < 6; a1++)
	{
		a[a1] = 1;
		for (int a2 = 1; a2 < 6; a2++)
		{
			if (a[a2])
				continue;
			a[a2] = 1;
			for (int a3 = 1; a3 < 6; a3++)
			{
				if (a[a3])
					continue;
				a[a3] = 1;
				for (int a4 = 1; a4 < 6; a4++)
				{
					if (a[a4])
						continue;
					a[a4] = 1;
					for (int a5 = 1; a5 < 6; a5++)
					{
						if (a[a5])
							continue;
						a[a5] = 1;
						int tmp = comp_cost(a1, a2, a3, a4, a5);
						if (tmp > max)
							max = tmp;
						a[a5] = 0;
					}
					a[a4] = 0;
				}
				a[a3] = 0;
			}
			a[a2] = 0;
		}
		a[a1] = 0;
	}
	cout << max << endl;
	//system("PAUSE");
	return 0;
}

#include <cstdio>
#include <cstring>
#include <vector>
#include <map>
#include <algorithm>
#include <set>
#include <string>
#include <iostream>
using namespace std;

typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<vi> vvi;
typedef vector<vii> vvii;

int grid[5][5];
vi order;
int main () {
	for (int i = 0; i < 5; i++)
		for (int j = 0; j < 5; j++)
			scanf("%d", &grid[i][j]);

	for (int i = 0; i < 5; i++)
		order.push_back(i);

	int ans = 0;
	int max = 0;
	bool flag = true;
	while (flag) {
		ans = 0;
		ans += (grid[order[0]][order[1]] + grid[order[1]][order[0]] + grid[order[2]][order[3]] + grid[order[3]][order[2]]);
		ans += (grid[order[1]][order[2]] + grid[order[2]][order[1]] + grid[order[3]][order[4]] + grid[order[4]][order[3]]);
		ans += (grid[order[2]][order[3]] + grid[order[3]][order[2]]);
		ans += (grid[order[3]][order[4]] + grid[order[4]][order[3]]);
		max = max > ans ? max : ans;
		flag = next_permutation(order.begin(), order.end());
	}
	printf("%d\n", max);
	return 0;
}

#include<bits/stdc++.h>
using namespace std;
#define lli long long int
const int n = 5;
int h[n][n];
int seq[n];

int sum(int a, int b){
	return h[a][b] + h[b][a];
}

int solve() {
	int ans=0,i,j;
	ans += sum(seq[0],seq[1]);
	ans += sum(seq[1],seq[2]);
	for(i=2;i<n-1;i++){
		ans+=2*sum(seq[i],seq[i+1]);
	}
	return ans;
}

void heap(int a,int *ans){
	int temp=0;
	if(a==1){
		temp = solve();
		// cout<<seq[0]<<seq[1]<<seq[2]<<seq[3]<<seq[4]<<endl;
		*ans = max(*ans,temp);
	}
	else{
		for(int i=0;i<a;i++){
			heap(a-1,ans);
			if(a%2==1) swap(seq[0],seq[a-1]);
			else swap(seq[i],seq[a-1]);

		}
	}
}

int main(){
	int i=9,j=8,ans=0;
	for(i=0;i<n;i++)
		for(j=0;j<n;j++)
			cin>>h[i][j];
	for(i=0;i<n;i++) seq[i]=i;
	heap(n,&ans);
	cout<<ans;
	return 0;
}

#include <bits/stdc++.h>
using namespace std;
int main()
{
    vector<vector<int>> mat(5,vector<int>(5));
    for(int i=0;i<5;i++)
        for(int j=0;j<5;j++)
            cin>>mat[i][j];
    vector<int> index(5);
    iota(index.begin(),index.end(),0);
    // for(int i:index)
    long long ans=0,maxans=0;
    do
    {
        ans=0;
        for(int i=0;i<4;i++)
        {
            for(int j=i;j<4;j+=2)
            {
                // cout<<j<<" "<<j+1<<endl;
                ans+=mat[index[j]][index[j+1]] + mat[index[j+1]][index[j]];
            }
        }
        // break;
        maxans=max(ans,maxans);
    }while(next_permutation(index.begin(),index.end()));
    cout<<maxans<<endl;
    return 0;
}

#include<bits/stdc++.h>
using namespace std;
#define deb(x) cout << ">" << #x << '=' << x << endl;
void solve(){
int v[5][5];
int n=5;
for(int i=0;i<n;i++){
  for(int j=0;j<n;j++){
    cin>>v[i][j];
  }
}

std::vector<int> q {0,1,2,3,4};
int maxi=INT_MIN;
int sum=0;
do{

  int a=v[q[3]][q[4]]+v[q[4]][q[3]];

  int c=v[q[2]][q[3]]+v[q[3]][q[2]];
  int d=v[q[1]][q[2]]+v[q[2]][q[1]];
  int b=v[q[0]][q[1]]+v[q[1]][q[0]];
  sum=2*a + 2*c +d +b;
  //deb(sum)
  maxi=max(sum,maxi);
}while(next_permutation(q.begin(), q.end()));

cout<<maxi<<endl;

}
int main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("out.txt", "w", stdout);
#endif
  // int t = 1;
  // cin >> t;
  // while (t--)
  solve();
  cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n";
  return 0;
}

#include<iostream>
#include<algorithm>
using namespace std;
int d[]={0,1,2,3,4};
int data[6][6];
int main(){
    for(int i=0;i<5;i++)
    {
        for(int j=0;j<5;j++)
        {
            cin>>data[i][j];
        }
    }
    int out=0;
    do
    {
            int nextOut=data[d[0]][d[1]]+data[d[1]][d[0]]+data[d[2]][d[3]]+data[d[3]][d[2]]+data[d[1]][d[2]]+data[d[2]][d[1]]+data[d[3]][d[4]]+data[d[4]][d[3]];
            nextOut+=data[d[2]][d[3]]+data[d[3]][d[2]]+data[d[3]][d[4]]+data[d[4]][d[3]];
            out=max(nextOut,out);
    }while ( std::next_permutation(d,d+5) );
    cout<<out<<endl;
    return 0;
}

#include<bits/stdc++.h>
using namespace std;
#define lli long long int
#define vi vector<int>
#define pb push_back
#define MOD 1000000007
#define For(i,si,n) for(lli (i)=(si);(i)<(n);(i)++)

int main()
{
  ios::sync_with_stdio(0), cin.tie(0);
  int ar[5][5];
  For(i,0,5)
  {
      For(j,0,5)
      {
          cin>>ar[i][j];
      }
  }
  vector<int> v;
  For(i,0,5)
  {
      v.push_back(i);
  }
  int mn=INT_MIN;
  do
  {
    mn=max(mn,ar[v[0]][v[1]]+ar[v[1]][v[0]]+ar[v[1]][v[2]]+ar[v[2]][v[1]]+2*(ar[v[2]][v[3]]+ar[v[3]][v[2]]+ar[v[3]][v[4]]+ar[v[4]][v[3]]));
  }while(next_permutation(v.begin(),v.end()));
    cout<<mn<<"\n";
}

#include<bits/stdc++.h>
using namespace std;
/******************************TYPE name************************************/
typedef long long ll;
typedef vector<int> vi;
typedef pair<int ,int > pii;
typedef map<int,int>mii;

/***********************************MACRO*************************/
#define test int ct;cin>>ct;while(ct--)
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define el <<"\n"
#define sc(n) scanf("%d",&n)
#define scl(n) scanf("%lld",&n)
#define sq(a) (a)*(a)
#define file() freopen("input.txt", "r", stdin);freopen("output.txt", "w", stdout);
#define zro 1e-9
#define F first
#define S second
#define pb(a) push_back(a)
#define rb rbegin()
#define re rend()
#define bg begin()
#define en end()
#define itr iterator
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);
#define gcd(a,b) __gcd(a,b)
#define gl(s) getline(cin,s)
int i;

//code: amr and music :: map of vector

/********************************code***************************/
int main()
{
    int j,a[5][5];
    rep(i,0,5)
    {
        rep(j,0,5)
        {
            sc(a[i][j]);
        }
    }
    int pr[1000][5];
    vector<int> x ;

    rep(i,0,5){
        x.pb(i);
        }

    int sum=0,best=0,sm=0;
    do
    {
        i++;
        //12345
        sum=a[x[0]][x[1]]+a[x[1]][x[0]];
        sum+=a[x[2]][x[3]]+a[x[3]][x[2]];

        //2345
        sum+=a[x[1]][x[2]]+a[x[2]][x[1]];
        sum+= a[x[3]][x[4]]+a[x[4]][x[3]];

        //345
        sum+=+a[x[2]][x[3]]+a[x[3]][x[2]];

        //45
        sum+=a[x[3]][x[4]]+a[x[4]][x[3]];

        if(best<sum)
            best=sum;
    }while(next_permutation(x.bg,x.en));

    cout<<best;
}

#include <vector>
#include <iostream>
#include <string>
#include <stdio.h>
#include <queue>
#include <climits>
#include <math.h>
#include <algorithm>
#include <stdlib.h>
#include <fstream>
using namespace std;

int graph[6][6],maxhapp;

void Calculate(vector<int> str);

void Generatior(int l,int r,vector<int> str){
	if(l==r){
		Calculate(str);
		return;
	}
	else if(l==r-1){
		Generatior(l+1,r,str);
		swap(str[str.size()-1],str[str.size()-2]);
		Generatior(l+1,r,str);
		return;
	}
	for(int i=1;i<=r-l+1;i++){
		Generatior(l+1,r,str);
		for(int j=r;j>=l+1;j--)
			swap(str[j],str[j-1]);
	}
}

void Calculate(vector<int> str){
	int summ=0,iter;
	reverse(str.begin(),str.end());
	while(str.size()>1){
		iter=str.size()-1;
		while (iter>0)
		{
			summ+=graph[str[iter]][str[iter-1]]+graph[str[iter-1]][str[iter]];
			iter-=2;
		}
		str.pop_back();
	}
	maxhapp=max(maxhapp,summ);
}

int main(){
	vector<int> arr;
	//ifstream fin("Test.txt");
	arr.push_back(1);
	arr.push_back(2);
	arr.push_back(3);
	arr.push_back(4);
	arr.push_back(5);
	maxhapp=0;
	for(int i=1;i<=5;i++)
		for(int j=1;j<=5;j++)
			cin>>graph[i][j];
	Generatior(0,4,arr);
	cout<<maxhapp;
	return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
int h[10][10]; int mx=0;
void perm(int *op,int n, int index)
{
    if(index>=n)
    {
        int sum=0;
        sum=h[op[1]][op[2]]+h[op[2]][op[1]]+h[op[3]][op[4]]+h[op[4]][op[3]]+h[op[2]][op[3]]+
        h[op[3]][op[2]]+h[op[4]][op[5]]+h[op[5]][op[4]]+h[op[3]][op[4]]+h[op[4]][op[3]]+h[op[4]][op[5]]+h[op[5]][op[4]];
    //  if(sum==620) cout<<sum;

        if(sum>mx) mx=sum;
        return;
    }
    for(int i=index;i<=n;i++)
    {
        swap(op[index],op[i]);
        perm(op,n,index+1);
        swap(op[index],op[i]);

    }
    return;
}
int main()
{
    // your code goes here
    int i,j; int a[7]; a[1]=1; a[2]=2; a[3]=3; a[4]=4; a[5]=5;
    for(i=1;i<=5;i++)
    {
        for(j=1;j<=5;j++)
        {
            scanf("%d",&h[i][j]); //cout<<h[i][j]<<" ";
        }
        //cout<<endl;
    }
    //int mx=0;
    perm(a,5,1);
    cout<<mx;
    return 0;
}

#include<bits/stdc++.h>
using namespace std;
int main()
{
	int matrix[5][5];
	for(int i=0; i<5; i++)
	{
		for(int j=0; j<5; j++)
		{
			int a; cin >> a;
			matrix[i][j] = a;
		}
	}
	int sequence[5] = {1,2,3,4,5};
	int max_element = -1;
	do
	{
		int a = sequence[0]-1;
		int b = sequence[1]-1;
		int c = sequence[2]-1;
		int d = sequence[3]-1;
		int e = sequence[4]-1;
		int queue1 = matrix[a][b] + matrix[b][a] + matrix[c][d] + matrix[d][c];
		int queue2 = matrix[b][c] + matrix[c][b] + matrix[d][e] + matrix[e][d];
		int queue3 = matrix[c][d] + matrix[d][c];
		int queue4 = matrix[d][e] + matrix[e][d];
		int ans = queue1+queue2+queue3+queue4;
		if(ans>=max_element)
		{
			max_element = ans;
		}
	}
	while(next_permutation(sequence,sequence+5));
	cout << max_element << '\n';
}

#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
    int g[5][5];
    for(int i=0;i<5;i++)for(int j=0;j<5;j++)cin>>g[i][j];
    int arr[5]={0,1,2,3,4};int ans=-1;
    int f1=0,f2=0,f3=0,f4=0,f0=0;
    do
    {
     ans=max(ans,g[arr[0]][arr[1]]+g[arr[1]][arr[0]]+g[arr[2]][arr[3]]+g[arr[3]][arr[2]]+
            g[arr[1]][arr[2]]+g[arr[2]][arr[1]]+g[arr[3]][arr[4]]+g[arr[4]][arr[3]]+
            g[arr[2]][arr[3]]+g[arr[3]][arr[2]]+g[arr[3]][arr[4]]+g[arr[4]][arr[3]]);
    }while(next_permutation(arr,arr+5));
    cout<<ans;
    return 0;
}

#include <bits/stdc++.h>

using namespace std;

#define x first
#define y second

int dx[]={0, 0, 1, -1};
int dy[]={1, -1, 0, 0};

typedef pair<int, int> pii;
typedef long long INT;

template <class T> inline void smin(T &a, T b) {if (a>b) a=b;}
template <class T> inline void smax(T &a, T b) {if (a<b) a=b;}

int n;
int a[11][11], id[11];

int calc(int *id) {
	int res=0, i, j, u, v;

	for (i=0; i<n; i++) {
		for (j=i; j+1<n; j+=2) {
			u=id[j]; v=id[j+1];
			res+=a[u][v]+a[v][u];
		}
	}

	return res;
}

int main() {

	int i, res=0, j;

	n=5;
	for (i=0; i<n; i++) for (j=0; j<n; j++) scanf("%d", &a[i][j]);

	for (i=0; i<n; i++) id[i]=i;

	res=0;
	do {
		res=max(res, calc(id));
	} while (next_permutation(id, id+n));

	printf("%d\n", res);

	return 0;
}

#include<stdio.h>
int temp=0;
int g[5][5];
void swap(int *a,int *b)
{
    int temp=*a;
    *a=*b;
    *b=temp;
}
void perm(int list[],int k,int m)
{
    int happy=0;
    if(k==m)
    {
        for(int i=1;i<=5;i++)
        {
                for(int j=1;j<=6-i;j++)
                {
                    if(j%2!=0&&j+1<=6-i)
                        happy+=g[list[j-2+i]-1][list[j+i-1]-1]+g[list[j+i-1]-1][list[j-2+i]-1];
                }
        }
        if(happy>temp)
            temp=happy;
    }
    else
    {
        for(int i=k;i<=m;i++)
        {
            swap(&list[i],&list[k]);
            perm(list,k+1,m);
            swap(&list[i],&list[k]);
        }
    }
}
int main()
{
    for(int i=0;i<=4;i++)
for(int j=0;j<=4;j++)
    scanf("%d",&g[i][j]);
    int list[5];
    for(int i=0;i<=4;i++)
    list[i]=i+1;
perm(list,0,4);
printf("%d\n",temp);
    return 0;
}

#include<iostream>
#include<vector>
#include<algorithm>
#include<climits>
using namespace std;
int main(){
    int n=5;
    vector<vector<int>>v(n,vector<int>(n));
    for(int i=0;i<n;i++)
    {
        for(int j=0;j<n;j++)
        {
            cin>>v[i][j];
        }
    }
    vector<int>per(n);
    for(int i=0;i<per.size();i++)
    {
        per[i]=i;
    }
    int max=INT_MIN;
    while(true){
        int result=0;
        result+=v[per[1]][per[0]];
        result+=v[per[0]][per[1]];
        result+=v[per[2]][per[3]];
        result+=v[per[3]][per[2]];
        result+=v[per[1]][per[2]];
        result+=v[per[2]][per[1]];
        result+=v[per[3]][per[4]];
        result+=v[per[4]][per[3]];
        result+=v[per[2]][per[3]];
        result+=v[per[3]][per[2]];
        result+=v[per[3]][per[4]];
        result+=v[per[4]][per[3]];
        if(max<result){

            max=result;
        }
        if(next_permutation(per.begin(),per.end())==false){
            break;
        }
    }
    cout<<max<<endl;

}

#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ll2 pair<ll, ll>
#define ll3 pair<ll, ll2>
#define mp make_pair
#define pb push_back
#define space << " " <<
#define print_iterable_range(x, lwr, upr) cout << #x << ": "; for(ll i=lwr; i<upr; i++){cout << x[i] << " ";} cout << endl;
#define debug_var(var) cout << #var << ": " << (var) << endl;
#define debug_vec(x) cout << #x << ": "; for(auto i : x) cout << i << " "; cout << endl;
#define fori(i, a, b) for(ll i=a; i<b; i++)
#define print_vec(x, a, b) fori(i, a, b) cout << x[i] << " "; cout << endl;
#define ford(i, a, b) for(ll i=a; i>=b; i--)
#define all(vec) vec.begin(), vec.end()

const double PI = 3.1415926535897;

ostream& operator << (ostream& oout, ll2 p){
    oout << "(" << p.first << ", " << p.second << ")";
    return oout;
}

istream& operator >> (istream& iin, ll2 &p){
    iin >> p.first;
    iin >> p.second;
    return iin;
}
template <typename T>
istream& operator >> (istream & iin, vector<T> &a){
    for(T &i : a){
        cin >> i;
    }
    return iin;
}

template <typename T>
ostream& operator << (ostream & oout, vector<T> &a){
    for(T &i : a){
        cout << i << " ";
    }
    return oout;
}

template <typename T>
T min(vector<T> a){
    ll ans = a[0];
    for(auto i : a){
        ans = min(ans, i);

    }
    return ans;
}

template <typename T>
T max(vector<T> a){
    ll ans = a[0];
    for(auto i : a){
        ans = max(ans, i);

    }
    return ans;
}

template <typename T>
bool operator == (pair<T, T> a, pair<T, T> b){
	return a.first == b.first and a.second == b.second;
}

const ll MOD = 1000000007;

//template<class T>
inline ll add_mod(ll a, ll b, const ll mod = MOD){
//    if(a<0) a += mod;
//    if(b<0) b += mod;
    return ((a>=0 ? a : a+mod)%mod + (b>=0 ? b : b+mod)%mod)%mod;
}

inline ll sub_mod(ll a, ll b, const ll mod = MOD){
    ll result = ((a>=0 ? : a+mod)%mod - (b>=0 ? b : b+mod)%mod);
    return (result >= 0 ? result : result + mod)%mod;
}

inline ll mult_mod(ll a, ll b, const ll mod = MOD){
    return ((a>=0? a : a+mod)%mod * (b>=0 ? b : b+mod)%mod)%mod;
}

ll fast_expo(ll x, ll y, const ll mod = MOD){
    ll ans = 1;
    while(y > 0){
        if(y%2 == 1)    ans = mult_mod(x, ans, mod);
        x = mult_mod(x, x, mod);
        y /= 2;
    }
    return ans;
}

inline ll div_mod(ll a, ll b, const ll mod = MOD){
    return mult_mod(a, fast_expo(b, mod - 2, mod), mod);
}

void solve(){

	vector<vector<ll>> arr(5, vector<ll>(5));
	cin >> arr;
//	cout << arr;
	vector<ll> l = {0, 1, 2, 3, 4};
	ll ans = LLONG_MIN;
	do{
//		debug_var(l);
		ll temp = 0;
		fori (i, 0, 5){
			fori(j, i, 5){
				if(i % 2 == 0 and j == 4){
					continue;
				}
				if((j-i)%2 == 0){
					temp += arr[l[j]][l[j+1]];
				}
				else temp += arr[l[j]][l[j-1]];
			}
		}
		ans = max(temp, ans);
	}
	while(next_permutation(all(l)));
	cout << ans;
    return;
}

int main(){
    ios_base::sync_with_stdio(NULL);
    cin.tie(0);cout.tie(0);
    ll num_test_cases = 1;
//    cin >> num_test_cases;
    while(num_test_cases--){
        solve();
    }
    return 0;
}

#include <iostream>
#include <algorithm>
#include <cstdio>
using namespace std;
#define forn(i, n) for(int i = 1; i <= (n); i++)

int happy[10][10], mx;
int a[] = {1, 2, 3, 4, 5};

void upd(){
    int sum = 0;
    sum += happy[a[0]][a[1]];
    sum += happy[a[1]][a[0]];
    sum += happy[a[1]][a[2]];
    sum += 2*happy[a[2]][a[3]];
    sum += happy[a[2]][a[1]];
    sum += 2*happy[a[3]][a[2]];
    sum += 2*happy[a[3]][a[4]];
    sum += 2*happy[a[4]][a[3]];
    if(sum > mx) mx = sum;
}

int main(){
    forn(i, 5){
        forn(j, 5){
            cin >> happy[i][j];
        }
    }
    forn(i, 130){
        upd();
        next_permutation(a, a+5);
    }
    cout << mx << "\n";
    return 0;
}

#include <iostream>
#include <algorithm>

using namespace std;

int main()
{
    int st[5],arr[5][5],sum=0,maxx=0;

    for (int i=0; i<5; i++)
    {
        for (int j=0; j<5; j++) { cin>>arr[i][j]; }
    }
    for (int i=0; i<5; i++) { st[i]=i; }

    do
    {
        sum=0;
        sum+=arr[st[0]][st[1]]+arr[st[1]][st[0]]+arr[st[2]][st[3]]+arr[st[3]][st[2]];
        sum+=arr[st[1]][st[2]]+arr[st[2]][st[1]]+arr[st[3]][st[4]]+arr[st[4]][st[3]];
        sum+=arr[st[2]][st[3]]+arr[st[3]][st[2]]; sum+=arr[st[3]][st[4]]+arr[st[4]][st[3]];
        if (sum>maxx) {maxx=sum;}
    }
    while (next_permutation(st,st+5));

    cout<<maxx<<endl;
    return 0;
}

#include<bits/stdc++.h>
using namespace std;
int mapp[10][10],maxn=-1;
bool mark[10];
int main()
{
    int i,j,k,l,n;
    for(i=1;i<=5;i++)
     for(j=1;j<=5;j++)
      scanf("%d",&mapp[i][j]);
    memset(mark,false,sizeof(mark));
    for(i=1;i<=5;i++)
    {
        mark[i]=true;
        for(j=1;j<=5;j++)
        {
            if(mark[j])continue;
            mark[j]=true;
            for(k=1;k<=5;k++)
            {
                if(mark[k])continue;
                mark[k]=true;
                for(l=1;l<=5;l++)
                {
                    if(mark[l])continue;
                    mark[l]=true;
                    for(n=1;n<=5;n++)
                    {
                        if(mark[n])continue;
                        int ans=0;
                        ans=ans+mapp[i][j]+mapp[j][i]+mapp[k][l]+mapp[l][k]+mapp[j][k]+mapp[k][j]+mapp[l][n]+mapp[n][l]+mapp[k][l]+mapp[l][k]+mapp[l][n]+mapp[n][l];
                        if(ans>maxn)maxn=ans;
                    }
                    mark[l]=false;
                }
                mark[k]=false;
            }
            mark[j]=false;
        }
        mark[i]=false;
    }
    printf("%d",maxn);
    return 0;
}

/*
ID: azret.k1
PROG:
LANG: C++11
*/

#include <functional>
#include <algorithm>
#include <iostream>
#include <iterator>
#include <cassert>
#include <climits>
#include <cstring>
#include <fstream>
#include <iomanip>
#include <vector>
#include <time.h>
#include <cstdio>
#include <locale>
#include <cmath>
#include <deque>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <new>

using namespace std;

#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define all(o) (o).begin(), (o).end()
#define maxr(v) max_element(all((v)))
#define minr(v) min_element(all((v)))
#define coun(v,x) count(all((v)),(x))
#define sz(s) (s).size()
#define mp(x,y)  make_pair((x),(y))
#define pb(x)  push_back(x)

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;

void solve()
{
	deque<int> p;

	int n = 5, i, j, a[6][6];
	int mx = -1;

	for(i=1;i<=n;i++){
		for(j=1;j<=n;j++){
			cin >> a[i][j];
		}
	}

	for(i=1;i<=n;i++) p.pb(i);

	do{

		int s = 0;

		deque<int> de;
		for(i=0;i<sz(p);i++) de.pb(p[i]);

		while(!de.empty()){

			for(i=0;i<sz(de)-1;i+=2){
				s += a[ de[i+1] ][ de[i] ] + a[ de[i] ][ de[i+1] ];
			}
			de.pop_front();
		}

		mx = max(s,mx);

	}while(next_permutation(p.begin(),p.end()));

	cout << mx << endl;
}

int main()
{
    #ifdef ONLINE_JUDJE
        freopen("input.txt","r",stdin);
        freopen("output.txt","w",stdout);
    #endif

	ios_base::sync_with_stdio(false);

    solve();

    return 0;
}

#include <iostream>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <stdio.h>
#include <cmath>
#include <vector>
#define FOR(i,a,b) for (int i=a;i<=b;i++)
#define FORD(i,a,b) for (int i=a;i>=b;i--)
#define FO(i,a,b) for (int i=a;i<b;i++)
#define FOD(i,a,b) for (int i=a;i>b;i--)
#define LL long long
#define oo 1e18
using namespace std;

int a[10][10],b[]={1,2,3,4,5},kq;

int tinh(){
    return((a[b[0]][b[1]]+a[b[1]][b[0]]+(a[b[2]][b[3]]+a[b[3]][b[2]]))+
        (a[b[1]][b[2]]+a[b[2]][b[1]]+a[b[3]][b[4]]+a[b[4]][b[3]])+
            (a[b[2]][b[3]]+a[b[3]][b[2]])+
                (a[b[3]][b[4]]+a[b[4]][b[3]]));
}

main(){
//  freopen("test.in.cpp","r",stdin);

    FOR(i,1,5)
        FOR(j,1,5)
            cin>>a[i][j];

    kq=tinh();
    while( next_permutation(b,b+5)) {
        int s=tinh();
        if (s>kq) kq=s;
    }
    cout<<kq;
    return 0;
}

#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
int a[10][10];
vector<int> v;
long long r=0;
int main()
{
	for (int i=0;i<5;i++)
	{
		v.push_back(i);
		for (int j=0;j<5;j++)
		{
			cin >>a[i][j];
		}
	}
	sort(v.begin(),v.end());
	do
	{
		long long t=0;
		t+=a[v[0]][v[1]];
		t+=a[v[1]][v[0]];
		t+=a[v[2]][v[3]]*2;
		t+=a[v[3]][v[2]]*2;
		t+=a[v[2]][v[1]];
		t+=a[v[1]][v[2]];
		t+=a[v[3]][v[4]]*2;
		t+=a[v[4]][v[3]]*2;
		if (t>r) r=t;
		/*cout <<t<<"    ";
		for (int i=0;i<5;i++) cout <<v[i]<<" ";
		cout <<"\n";*/
	}while (next_permutation(v.begin(),v.end()));
	cout <<r;
	return 0;
}

#include <cstring>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <iostream>
#include <vector>
#define EPS 10e-9
#define max(a,b) (a>b?a:b)
using namespace std;
typedef __int64 LL;

int main()
{
	int a[6][6];
	for(int i=1;i<=5;i++)
		for(int j=1;j<=5;j++)
			scanf("%d",&a[i][j]);
	char s[7]={"012345"};
	int ans=0;
	for(int i=1;i<=120;i++)
	{
		int sum=0;
		for(int j=1;j<5;j++)
		{
			for(int k=j;k<5;k+=2)
				sum+=a[s[k]-'0'][s[k+1]-'0']+a[s[k+1]-'0'][s[k]-'0'];
		}
		if(sum>ans)
		ans=sum;
		next_permutation(s+1, s+1+5);
		//printf("%s\n",s);
	}
	printf("%d\n",ans);
	return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define ll long long
//long long ans=1e18;
int arr[6][6],brr[5];
int calc(int a,int b)
{
    return arr[brr[a]][brr[b]]+arr[brr[b]][brr[a]];
}

int main()
{
  int i,j;
  for(i=1;i<=5;i++)
  {
      for(j=1;j<=5;j++)
      {
          cin>>arr[i][j];
      }
  }

  for(i=0;i<5;i++)
  {
      brr[i]=i+1;
  }
  int ans=0;
  do
  {
    ans=max(ans,calc(1,0)+calc(1,2)+2*calc(2,3)+2*calc(3,4));
  }
  while(next_permutation(brr,brr+5));
  cout<<ans<<endl;
}

#include <iostream>
#include <algorithm>
#include <cstring>

using namespace std;

typedef long long int64;

int g[5][5];
int p[5];

int main() {
  int n = 5;
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < n; ++j) {
      cin >> g[i][j];
    }
  }
  for (int i = 0; i < n; ++i) {
    p[i] = i;
  }
  int ret = 0;
  do {
    int sum = 0;
    for (int i = 0; i < n; ++i) {
      for (int j = i; j + 1 < n; j += 2) {
        sum += g[p[j]][p[j + 1]] + g[p[j + 1]][p[j]];
      }
    }
    ret = max(sum, ret);
  } while (next_permutation(p, p + n));
  cout << ret << endl;
  return 0;
}

#include <bits/stdc++.h>
using namespace std;

#define LL long long int
#define pb(x) push_back(x)
#define mp make_pair
#define ii pair<int,int>
#define mod int(1000000007)
#define F first
#define S second
#define si(a) scanf("%d",&a);
#define VI vector<int>
#define FOR(i,a,b) for(int i= (int)a; i<= (int)b; i++)
#define rep(i,n) for(int i= int(1); i<= (int)n; i++)
#define CLR(a) memset(a,0,sizeof(a));
#define SET(a) memset(a,-1,sizeof(a));
#define MAX int(100020)

LL POWM(LL a,LL b,int n)
{
	LL rm=1;
	while (b){
		if (b % 2) {
			rm = (rm * a) % n;
		}
		a = (a * a) % n;
		b /= 2;
	}
	return rm;
}

// --------------------------------------------------main part---------------------------------------------.
int g[10][10], ans = 0,a[10];
void f(){
	int tmp = 0;
	for(int i=1;i<=4;++i){
		for(int j=i;j<5;j+=2){
			tmp += g[a[j]][a[j+1]] + g[a[j+1]][a[j]];
		}
	}
	ans = max( ans, tmp);
}

int main(){
	rep(i,5)rep(j,5)cin>>g[i][j];
	rep(i,5) a[i] = i;
	do{
		f();
	} while ( next_permutation(a+1,a+6));
	cout<<ans<<endl;
	return 0;
}

#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <cctype>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <functional>
#define pb push_back
#define pie 3.141592653589793238
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
using namespace std;
const int INF = 1<<29;
typedef long long ll;
inline int two(int n) { return 1 << n; }
inline int test(int n, int b) { return (n>>b)&1; }
inline void set_bit(int & n, int b) { n |= two(b); }
inline void unset_bit(int & n, int b) { n &= ~two(b); }
inline int last_bit(int n) { return n & (-n); }
inline int ones(int n) { int res = 0; while(n && ++res) n-=n&(-n); return res; }
template<class T> void chmax(T & a, const T & b) { a = max(a, b); }
template<class T> void chmin(T & a, const T & b) { a = min(a, b); }
/////////////////////////////////////////////////////////////////////
const ll mod = 1e9 + 7;
const int N = 1e6 + 9;
ll a[N];
ll modexp(ll a, ll n)
{
    ll r = 1;
    while(n){
        if(n & 1)
            r = (r * a) % mod;
        a = (a * a) % mod;
        n >>= 1;
    }
    return r;
}
bool cmp(const pair<double, ll> &a, const pair<double, int> &b)
{
    if(a.first == b.first){
        return a.second < b.second;
    }
    else return a.first > b.first;
}
int main()
{
    fast;
    int arr[10][10];
    for(int i = 1; i <= 5; i ++){
        for(int j = 1; j <= 5; j ++){
            cin >> arr[i][j];
        }
    }
    ll a[] = {1, 2, 3, 4, 5};
    ll c = 0, maxx = -1;
    ll aa = a[0], bb = a[1], cc = a[2], dd = a[3], ee = a[4];
       ll k1 = arr[aa][bb] + arr[bb][aa] + arr[cc][dd] + arr[dd][cc];
       ll k2 = arr[cc][bb] + arr[bb][cc] + arr[ee][dd] + arr[dd][ee];
       ll k3 = arr[dd][cc] + arr[cc][dd];
       ll k4 = arr[dd][ee] + arr[ee][dd];
       ll pp = k1 + k2 + k3 + k4;
    while(next_permutation(a, a + 5)){
       ll aa = a[0], bb = a[1], cc = a[2], dd = a[3], ee = a[4];
       ll k1 = arr[aa][bb] + arr[bb][aa] + arr[cc][dd] + arr[dd][cc];
       ll k2 = arr[cc][bb] + arr[bb][cc] + arr[ee][dd] + arr[dd][ee];
       ll k3 = arr[dd][cc] + arr[cc][dd];
       ll k4 = arr[dd][ee] + arr[ee][dd];
      // cout << k1+k2+k3+k4 << endl;
       maxx = max(maxx, (k1 + k2 + k3 + k4));
    }
    cout << max(maxx, pp)<< endl;
    return 0;
}

#include <iostream>
#include <unordered_map>
#include <vector>
#include <set>
#include <string.h>
#include <algorithm>
#define mod 1000000007
#define inf 1LL<<61
#define ll long long
#define pr pair<int,int>
#define all vec.begin(),vec.end()
#define rep(i,a,b) for (int i = a; i < b; i++)
#define fi first
#define se second
#define pushb push_back
#define makep make_pair

using namespace std;

int arr[5][5];
ll compute_sum(vector<int> v){
	ll sum = 0;
	while(v.size() != 1){
		for(int i = 0; i < v.size() - 1; i += 2){
			sum += arr[v[i] -1][v[i+1]-1] + arr[v[i+1] -1][v[i] - 1];
		}
		v.erase(v.begin());
	}

	return sum;
}
int main(){
	vector<int> v(5);
	rep(i,0,5)
		v[i] = i+1;
	int max = 0;
	rep(i,0,5)
		rep(j,0,5)
			cin >> arr[i][j];
	do{
		int temp = compute_sum(v);
		if(temp > max)
			max = temp;
	}while(next_permutation(v.begin(), v.end()));
	cout << max;
	return 0;
}

#include <bits/stdc++.h>
using namespace std;
typedef long long int lld;
const lld MOD = 1000000000 + 7;
int calc(int a[],int grid[][5]){
	int ans = 0;
	for(int i=0;i<5;i++){
		for(int j=i+1;j<5;j+=2){
			// cout<<j<<" "<<j-1<<" talking"<<endl;
			ans+=grid[j][j-1]+grid[j-1][j];
		}
		// cout<<endl;
	}
	// cout<<ans<<endl;
	return ans;
}
int main(){
	int grid[5][5];
	for(int i=0;i<25;i++){
		cin>>grid[i/5][i%5];
	}
	// cout<<endl;
	for(int i=0;i<5;i++){
		for(int j=0;j<5;j++){
			// cout<<grid[i][j]<<" ";
		}
		// cout<<endl;
	}
	int a[5];
	for(int i=0;i<5;i++){
		a[i] = i;
	}
	int ans = 0;
	do{
		for(int i=0;i<5;i++){
			// cout<<a[i]<<" ";
		}
		// cout<<endl;
		int temp = 0;
		for(int i=0;i<5;i++){
			for(int j=i+1;j<5;j+=2){
				// cout<<grid[a[j]][a[j-1]<<" "<<grid[j-1][j]<<" talking"<<endl;
				temp+=grid[a[j]][a[j-1]]+grid[a[j-1]][a[j]];
			}
			// cout<<endl;
		}
		// cout<<temp<<endl;
		ans  = max(ans,temp);
	}while(next_permutation(a,a+5));
	cout<<ans<<endl;
	return 0;
}

#include <bits/stdc++.h>
#define PI acos(-1)
#define MP make_pair
#define PB push_back
#define F first
#define S second
#define all(a) (a).begin(), (a).end()
#define MEM(a, h) memset(a, (h), sizeof(a))
#define MOD	1000000007
#define EPS	1e-9
typedef long long ll;
using namespace std;

int g[6][6];
int orden[6];

int solve(){

	int res = -1;
	do{
		int actual = 0;
		actual += g[orden[0]][orden[1]]+g[orden[2]][orden[3]];
		actual += g[orden[1]][orden[0]]+g[orden[3]][orden[2]];
		actual += g[orden[1]][orden[2]]+g[orden[3]][orden[4]];
		actual += g[orden[2]][orden[1]]+g[orden[4]][orden[3]];
		actual += g[orden[2]][orden[3]];
		actual += g[orden[3]][orden[2]];
		actual += g[orden[4]][orden[3]];
		actual += g[orden[3]][orden[4]];
		if(actual > res)
		res = actual;
	}while(next_permutation(orden,orden+5));
	return res;
}
int main(){

	std::ios::sync_with_stdio(false);
	cin.tie(0);
	int res;
	for(int i = 0;i < 5;i++) orden[i] = i;
	for(int i = 0;i < 5;i++)
		for(int j = 0;j < 5;j++)
			cin>>g[i][j];

	res = solve();
	cout<<res<<endl;
	return 0;
}

#include <bits/stdc++.h>

#define FOR(i, a, b) for(int i = a; i < (int) b; i++)
#define F0R(i, a) FOR (i, 0, a)
#define ROF(i, a, b) for(int i = a; i >= (int) b; i--)
#define R0F(i, a) ROF(i, a, 0)
#define GO(i, a) for (auto i : a)

#define eb emplace_back
#define sz(x) (int) x.size()
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define f first
#define s second

using namespace std;

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpii;
typedef vector<vi> vvi;
typedef vector<vpii> vvpii;
typedef long long i64;
typedef vector<i64> vi64;
typedef vector<vi64> vvi64;
typedef pair<i64, i64> pi64;
typedef vector<pi64> vpi64;

const int N = 5;
int g [N][N];

int main() {
  F0R (i, 5) {
    F0R (j, 5) {
      cin >> g[i][j];
    }
  }
  vi a = {0, 1, 2, 3, 4};
  int mx = 0;
  do {
    int tot = 0;
    F0R (i, 4) {
      FOR (j, i, 5) {
        if (j + 1 >= 5) continue;
        int first = a[j];
        int second = a[j + 1];
        tot += g[first][second] + g[second][first];
        j++;
      }
    }
    mx = max (mx, tot);
  } while (next_permutation(all(a)));
  printf ("%d\n", mx);
  return 0;
}

#include<bits/stdc++.h>
using namespace std;

int main()
{
   // ios_base::sync_with_stdio(false);
    //cin.tie(false);
    //string s = "54321";
    vector<int> v1[100000];
    //vector<int>v2[100000];
    int n,sum,ans=0;
    for(int i=0;i<5;i++)
    {
        for(int j=0;j<5;j++)
        {
            cin>>n;
            v1[i].push_back(n);
        }
    }
    int arr[]={0,1,2,3,4},count= 0;
    //sort(arr,arr+5);

    do{

    //count = 0;
    //ans = 0;
    sum = 0;
        for(int i=0;i<5;i++)
        {

            if(i%2==0)
                n=4;
            else
                n=5;
            for(int j=i;j<n;j+=2)
            {
                int a,b;
                a = arr[j];
                b = arr[j+1];
                //cout<<a<<" "<<b<<" ";
                sum = sum + v1[a][b]+v1[b][a];
                //cout<<v1[arr[j]][arr[j+1]]<<" "<<v1[arr[j+1]][arr[j]]<<" ";
            }
            //cout<<sum<<endl;
            ans = max(ans,sum);
            //cout<<endl;
        }
        //ans = max(ans,sum);
    }while(next_permutation(arr,arr+5));

    cout<<ans<<endl;

    //cout<<count;

    return 0;
}

#include <iostream>
#include <algorithm>
#include <math.h>
#include <string.h>
#include <vector>
#include <cmath>
#include <string>
#include <iterator>
#include <map>
#include <climits>
using namespace std;

int main()
{
    int shower[6][6];
    for (int i = 0; i < 5 ; i++)
    {
        for (int j = 0 ; j < 5 ; j++)
        {
            cin >> shower[i][j];
        }
    }
    int a[6],temp = 0,sol = -1;
    for (int i = 0; i < 5; i++)
    {
        a[i] = i;
    }
    do
    {
        temp = shower[a[0]][a[1]] + shower[a[1]][a[0]];
        temp += shower[a[2]][a[3]] + shower[a[3]][a[2]];
        temp += shower[a[1]][a[2]] + shower[a[2]][a[1]];
        temp += shower[a[3]][a[4]] + shower[a[4]][a[3]];
        temp += shower[a[2]][a[3]] + shower[a[3]][a[2]];
        temp += shower[a[4]][a[3]] + shower[a[3]][a[4]];
        sol = max(sol, temp);

    }
    while (next_permutation(a, a+5));

    cout << sol << endl;
    return 0;
}

#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;

int main() {
    vector<int> G(25);
    for(int &g : G) cin >> g;
    vector<int> P { 0, 1, 2, 3, 4};
    int max = 0;

    for(;;) {
        int sum = 0;
        for(int i = 0; i < 5; i++)
            for(int j = i; j < 4; j += 2)
                sum += G[P[j] * 5 + P[j + 1]] + G[P[j + 1] * 5 + P[j]];
        if(sum > max) max = sum;
        if(!next_permutation(P.begin(), P.end())) break;
    }

    cout << max << '\n';

    return 0;
}

#include <bits/stdc++.h>

#define ios                         \
  ios_base::sync_with_stdio(false); \
  cin.tie(0);                       \
  cout.tie(0);
#define ll long long
#define endl '\n'
#define pii pair<ll int, ll int>
#define all(a) (a).begin(), (a).end()
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define repi(i, n) for (ll i = 0; i < n; i++)
#define rep(i, a, b) for (ll i = a; i <= b; i++)
#define M 1000000007

using namespace std;

ll happiness(vector<ll> v, vector<vector<ll>> g) {
  ll ans = 0;
  repi(i, 4) {
    if (i % 2)
      ans += (g[v[i]][v[i + 1]] + g[v[i + 1]][v[i]]) * ((i + 1) / 2);
    else
      ans += (g[v[i]][v[i + 1]] + g[v[i + 1]][v[i]]) * ((i + 2) / 2);
  }
  return ans;
}

int main() {
  ios ll n = 5;
  vector<vector<ll>> g;
  repi(i, n) {
    g.pb({});
    repi(j, n) {
      ll x;
      cin >> x;
      g[i].pb(x);
    }
  }
  vector<ll> v;
  repi(i, n) v.pb(i);
  ll mx = 0;
  do {
    mx = max(mx, happiness(v, g));
  } while (next_permutation(all(v)));
  cout << mx;
  return 0;
}

#include <iostream>
#include <vector>

using namespace std;
long long check(int arr[6][6], int a, int b, int c, int d, int e){
  return (arr[a][b]+arr[b][a])+(arr[b][c]+arr[c][b]) + ((arr[c][d]+arr[d][c])*2)+((arr[d][e]+arr[e][d])*2);
}
int main(){
  int arr[6][6];
  long long ans = 0;

  for(int i=0; i<5; i++){
    for(int j=0; j<5; j++){
      cin >> arr[i][j];
    }
  }

  for(int i=0; i<5; i++){
      for(int j=0; j<5; j++){
        if(i!=j)
          for(int k=0; k<5; k++){
            if(i!=k && j!=k)
              for(int l=0; l<5; l++){
                if(l!=k && l!=j && l!=i)
                  for(int m=0; m<5; m++){
                    if(m!=l && m!=k && m!=j && m!=i)
                      ans = max(ans, check(arr, i, j, k, l, m));
                  }
              }
          }
      }
  }
  cout << ans << endl;
}

#include <bits/stdc++.h>
#include <vector>
#include <string>
#define mod 10000007
#define INF LLONG_MAX
#define loop(i,x,n) for(int i = x; i < n; i++)
#define pb push_back
#define mp make_pair
#define ll long long
#define vpl vector< pair<ll,ll> >
#define vpi vector< pair<int,int> >
#define vi vector<int>
#define vl vector<ll>
#define vb vector<bool>
#define vch vector<char>
#define se second
#define fi first
using namespace std;

int main()
{

	ios::sync_with_stdio(0);
	cin.tie(0);
	int arr[5][5];
	for(int i=0;i<5;i++){
		for(int j=0;j<5;j++){
			cin >> arr[i][j];
		}
	}
	vi v{0,1,2,3,4};
	int sum = arr[v[0]][v[1]] + 2*arr[v[2]][v[3]] + arr[v[1]][v[2]] + 2*arr[v[3]][v[4]] + arr[v[1]][v[0]] +    2*arr[v[3]][v[2]] + 					arr[v[2]][v[1]] + 2*arr[v[4]][v[3]];
	int mx = sum;
	while(next_permutation(v.begin(),v.end())){
		sum = arr[v[0]][v[1]] + 2*arr[v[2]][v[3]] + arr[v[1]][v[2]] + 2*arr[v[3]][v[4]] + arr[v[1]][v[0]] +    2*arr[v[3]][v[2]] + 					arr[v[2]][v[1]] + 2*arr[v[4]][v[3]];
		//cout << sum << "\n";
		mx = max(sum,mx);
	}

	cout << mx << "\n";

	return 0;
}

#include <bits/stdc++.h>
#define ll long long
#define node pair<long long,long long >
#define sc second
#define f first
#define islam  ios::sync_with_stdio(false); cin.tie(0);

using namespace std;

int main()
{
    islam
   int g[10][10];
    for(int i = 0 ; i < 5 ; ++i)
        for(int j = 0 ; j < 5 ; ++j)
            cin >> g[i][j];
    int ans = -1, tmp;
    int p[6]={0,1,2,3,4};
    do
    {
        tmp = g[p[0]][p[1]] + g[p[1]][p[0]];
        tmp += g[p[2]][p[3]] + g[p[3]][p[2]];
        tmp += g[p[1]][p[2]] + g[p[2]][p[1]];
        tmp += g[p[3]][p[4]] + g[p[4]][p[3]];
        tmp += g[p[2]][p[3]] + g[p[3]][p[2]];
        tmp += g[p[3]][p[4]] + g[p[4]][p[3]];
        if(tmp > ans)
        {
            ans = tmp;
        }
    }
    while(next_permutation(p,p+5));
    cout<<ans;

    return 0;
}

#include <bits/stdc++.h>

#define java ios_base::sync_with_stdio; cout.tie(0); cin.tie(0);
#define S second
#define F first
#define pb push_back
#define nl '\n'

const long long MXN = 1e6 + 1;
const long long MNN = 1e3 + 1;
const long long MOD = 1e9 + 7;
const long long INF = 1e18;

typedef long long llong;
typedef unsigned long long ulong;

using namespace std;

llong n, ans, b[10][10], m, c[MXN], cnt, mx = -1, st[7];

bool NotEqual(int i, int j, int k, int l, int h){
    st[1] = i;
    st[2] = j;
    st[3] = k;
    st[4] = l;
    st[5] = h;
    sort(st + 1, st + 6);
    for(int i = 1; i < 5; i++){
        if(st[i] == st[i + 1]){
            return false;
        }
    }return true;
}

int main(){
    java;
    //freopen("input.txt" , "r" , stdin);
    vector<int> v;
    for(int i = 1; i <= 5; i++){
        for(int j = 1; j <= 5; j++){
            cin >> b[i][j];
        }c[i] = i;
    }for(int i = 1; i <= 5; i++){
        for(int j = 1; j <= 5; j++){
            for(int k = 1; k <= 5; k++){
                for(int l = 1; l <= 5; l++){
                    for(int h = 1; h <= 5; h++){
                        if(NotEqual(i,j,k,l,h)){
                            llong x = (b[i][j] + b[j][i] + b[k][l] + b[l][k]);
                            x +=  (b[j][k] + b[k][j] + b[l][h] + b[h][l]);
                            x += b[k][l] + b[l][k];
                            x += b[l][h] + b[h][l];
                            mx = max( mx, x);
                        }
                    }
                }
            }
        }
    }cout << mx;
    return 0;
}

//Codeforces 431B

#include<iostream>
#include<string>
#include<vector>
#include<unordered_set>
#include<algorithm>
using namespace std;
typedef long long ll;

int main(){

    ll H[5][5];
    int i,j;
    for(i = 0; i < 5; i++){
        for(j = 0; j < 5; j++){
            cin >> H[i][j];
        }
    }

    ll maxt = 0, t = 0;
    vector<int> v {0,1,2,3,4};

    do{
        t = H[v[0]][v[1]] + H[v[1]][v[0]] + H[v[2]][v[3]] + H[v[3]][v[2]];
        t += H[v[1]][v[2]] + H[v[2]][v[1]] + H[v[3]][v[4]] + H[v[4]][v[3]];
        t += H[v[2]][v[3]] + H[v[3]][v[2]] + H[v[3]][v[4]] + H[v[4]][v[3]];
        maxt = max(maxt,t);
    } while(next_permutation(v.begin(), v.end()));

    cout << maxt << '\n';

    return 0;
}

#include <iostream>
#include <algorithm>

using namespace std;

int main()
{
    int hp[5][5];
    for (int i=0; i<25; i++)
        cin >> hp[i/5][i%5];

    int perm[5] = {0, 1, 2, 3, 4};

    int maxhp = 0;
    do
    {
        int thp;
        thp = hp[perm[0]][perm[1]]
            + hp[perm[1]][perm[2]]
            + hp[perm[2]][perm[3]] * 2
            + hp[perm[3]][perm[4]] * 2;

        if (thp > maxhp)
            maxhp = thp;
    }
    while (next_permutation(perm, perm+5));

    cout << maxhp << endl;

    return 0;
}

#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#define MAX 5
#define ll long long int
using namespace std;
ll A[MAX][MAX];
int D[5] = {0,1,2,3,4};

ll res;

int main(){
	for(int i = 0;i < MAX;i++){
		for(int j = 0;j < MAX;j++) cin >> A[i][j];
	}
	res = 0;
	int x = 1;
	while(x != 120){
		ll aux = 0;
		for(int i = 0;i < MAX;i++){
			for(int j = i;j < MAX;j += 2){
				if(j + 1 >= MAX) continue;
				//printf("(%d,%d) ",D[i],D[i+1]);
				aux += A[D[j]][D[j + 1]] + A[D[j + 1]][D[j]];
			}
			//printf("\n");
		}
		res = max(aux,res);
		random_shuffle(D,D + 5);
		x++;
	}
	cout << res << endl;
	return 0;
}

#include <iostream>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <stdio.h>
#include <cmath>
#include <vector>
#define FOR(i,a,b) for (int i=a;i<=b;i++)
#define FORD(i,a,b) for (int i=a;i>=b;i--)
#define FO(i,a,b) for (int i=a;i<b;i++)
#define FOD(i,a,b) for (int i=a;i>b;i--)
#define LL long long
#define oo 1e18
using namespace std;

LL a[10][10],b[]={1,2,3,4,5},kq=0;

LL tinh(){
    return((a[b[0]][b[1]]+a[b[1]][b[0]]+(a[b[2]][b[3]]+a[b[3]][b[2]]))+
        (a[b[1]][b[2]]+a[b[2]][b[1]]+a[b[3]][b[4]]+a[b[4]][b[3]])+
            (a[b[2]][b[3]]+a[b[3]][b[2]])+
                (a[b[4]][b[3]]+a[b[3]][b[4]]));
}

main(){
    //freopen("test.in.cpp","r",stdin);

    FOR(i,1,5)
        FOR(j,1,5) cin>>a[i][j];

    while( next_permutation(b,b+5)) {
        LL s=tinh();
        if (s>kq) kq=s;
    }
    cout<<kq;
    return 0;
}

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int nax = 1e5 + 5;
int main()
{
    int G[6][6] , g[6][6];
    for(int i=1;i<=5;i++)
    {
    	for(int j=1;j<=5;j++)
    	{
    		cin>>G[i][j];
    	}
    }
    for(int i=1;i<=5;i++)
    {
    	for(int j=1;j<=5;j++)
    	{
    		g[i][j] = G[i][j] + G[j][i];
    	}
    }
    int num[] = {1,2,3,4,5};
    ll ans = 0;
    while(next_permutation(num,num+5))
    {
    	ll sum = g[num[0]][num[1]] + g[num[1]][num[2]] +2*g[num[2]][num[3]] +2*g[num[3]][num[4]];
    	ans = max(ans,sum);
    }
    cout<<ans;
    return 0;
}

#include <iostream>
#include <map>
#include <algorithm>
#include <bitset>
#include <cmath>
#include <limits.h>
#include <vector>
#include <stack>
#include <set>
#include <sstream>
#include <iomanip>
#include <stdint.h> //for the int64_t
#include <fstream>
#include <stack>
#include <cstdio>
#include <cstring>
#include <ctype.h>
#include <fstream>
#include <sstream>
#include <algorithm>

using namespace std;

typedef unsigned long long ull;
typedef unsigned int ui;
typedef unsigned long ul;
typedef signed long sl;
typedef signed long long sll;
typedef unsigned long long int bigGun;
typedef signed long long int signedBigGun;
typedef pair<int, int> pii;
typedef pair<ui, ui> pui;
typedef vector<int> vi;
typedef map<char, vi> mcvi;
typedef map<ui, ui> mii;
typedef map<char, int> mci;
typedef map<ull, ull> mll;
typedef map<pair<string, string>, float> mpsss;
typedef set<sll> ssll;
typedef unsigned short us;
typedef map<string, string> mss;
typedef unsigned long long int bigdaddy;
typedef pair<int, string> pis;
#define print(a,n) for(int i=0;i<n;i++){cout<<a[i]<<"\t";};cout<<endl;
#define printv(a) for(int i=0;i<a.size();i++){cout<<a[i]<<" ";};cout<<endl;
#define prints(s) for(set<int>::iterator it=s.begin();it!=s.end();it++)cout<<*it<<" ";

int main() {
	ios_base::sync_with_stdio(0);

	const int SIZE = 5;
	int h[SIZE][SIZE];

	for (int i = 0; i < SIZE; i++) {
		for (int j = 0; j < SIZE; j++) {
			cin >> h[i][j];
		}
	}

	int max = 0;

	int row[SIZE] = { 0, 1, 2, 3, 4 };

	while (std::next_permutation(row, row + SIZE)) {

		int tmp = h[row[0]][row[1]] + h[row[1]][row[0]] + h[row[2]][row[3]]
				+ h[row[3]][row[2]] +

				h[row[1]][row[2]] + h[row[2]][row[1]] + h[row[3]][row[4]]
				+ h[row[4]][row[3]] + h[row[2]][row[3]] + h[row[3]][row[2]]
				+ h[row[3]][row[4]] + h[row[4]][row[3]];

		max = tmp > max ? tmp : max;

	}
	cout << max;

//	for (int i = 0; i < SIZE; i++) {
//		for (int j = 0; j < SIZE; j++) {
//			if(i==j) continue;
//			for (int k = 0; k < SIZE; k++) {
//				if(k==j) continue;
//				for (int l = 0; l < SIZE; l++) {
//					if(k==l) continue;
//					for (int m = 0; m < SIZE; m++) {
//						if(l==m) continue;
//
//
//
//
//					}
//
//				}
//
//			}
//		}
//	}

	return 0;
}

#include <bits/stdc++.h>
using namespace std;

typedef long long int ll;
typedef pair<ll,ll> pii;
typedef pair<ll,string> pis;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef vector<pii> vii;
typedef vector<string> vs;

#define test int t;cin>>t;while(t--)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(a) a.begin(),a.end()
#define max(a,b) a>b?a:b
#define min(a,b) a<b?a:b

ll MAX=9223372036854775807;
ll MIN=-9223372036854775807;

int main()
{
    vvi a(5,vi (5));
    vi b;
    for (int i=0;i<5;i++)
        for (int j=0;j<5;j++)
            cin>>a[i][j];
    for (int i=0;i<5;i++)
    {
        for (int j=i+1;j<5;j++)
        {
            ll x=a[i][j]+a[j][i];
            b.pb(x);
        }
    }
    sort(all(b),greater<ll>());
    ll sum=b[0];
    for (int i=0;i<5;i++)
    {
        sum+=b[i];
        //cout<<b[i]<<" ";
    }
    cout<<sum;
    return 0;
}

#include<bits/stdc++.h>
using  namespace std;

#define F first
#define S second
#define ff(i , l , n) for(i = l ; i < n ; i ++)
#define fr(i , l , n) for(i = n ; i > l ; i--)
#define fast ios_base :: sync_with_stdio(false) ; cin.tie(0) ; cout.tie(0);
#define R return
#define B break
#define C continue
#define vi vector<int>
#define vl vector<long>
#define vll vector<long long>

int main()
{

	int g[5][5] , i , j , max = 0 ;
	int b[] ={0, 1 , 2 , 3 , 4} ;

	ff(i, 0 , 5)
	ff(j , 0 , 5)
	cin>>g[i][j];

   while(next_permutation(b , b + 5))
	{
	    if(g[b[0]][b[1]] + g[b[1]][b[0]] + g[b[1]][b[2]] + g[b[2]][b[1]] + 2*(g[b[2]][b[3]] + g[b[3]][b[2]] + g[b[3]][b[4]] + g[b[4]][b[3]]) > max)
        max = g[b[0]][b[1]] + g[b[1]][b[0]] + g[b[1]][b[2]] + g[b[2]][b[1]] + 2*(g[b[2]][b[3]] + g[b[3]][b[2]] + g[b[3]][b[4]] + g[b[4]][b[3]]);
	}

	cout<<max;
	return 0;

}

#include <cstring>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <memory.h>
#include <cassert>

using namespace std;
#define max(A,B) (A)>(B)?(A):(B)
#define min(A,B) (A)<(B)?(A):(B)
#define fori(i,n) for(i=0;i<n;i++)
#define ford(i,n) for(i=n-1;i>=0;i--)
#define wh(t) while(t--)
#define sc(a) scanf("%d",&a)
#define pr(a) printf("%d\n",a)
#define sc64(a) scanf("%I64d",&a)
#define pr64(a) printf("%I64d\n",a)
#define scs(a) scanf("%s",a)
#define prs(a) printf("%s\n",a)
#define ll long long int
#define MOD 1000000007
#define pb push_back
int g[6][6];
int main()
{
for(int i=0;i<5;i++)
{
for(int j=0;j<5;j++)
{
sc(g[i][j]);
}
}
int a[6],sum,max=0;
for(int i=0;i<5;i++)
a[i]=i;
while(next_permutation(a, a+5))
{
sum=g[a[0]][a[1]]+g[a[1]][a[0]];
sum+=g[a[2]][a[3]]+g[a[3]][a[2]];
sum+=g[a[1]][a[2]]+g[a[2]][a[1]];
sum+=g[a[3]][a[4]]+g[a[4]][a[3]];
sum+=g[a[2]][a[3]]+g[a[3]][a[2]];
sum+=g[a[3]][a[4]]+g[a[4]][a[3]];
if(sum>=max)
max=sum;
}
pr(max);
return 0;
}

#include <iostream>
#include <stdio.h>
#include <set>
#include <vector>
#include <queue>
#include <string>
#include <stack>
#include <cstdlib>
#include <algorithm>
using namespace std;

typedef long long ll;

int mx[10][10], maxh, now;
int cur[10];

int main(){ // A
	//freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
	//freopen("bumblebee.in","r",stdin);freopen("bumblebee.out","w",stdout);
	for(int i = 0; i <= 5; i++){cur[i] = i;}
	for(int i = 0; i < 5; i++){
		for(int j = 0; j < 5; j++){
			cin >> mx[i][j];
		}
	}
	for(int i = 0; i < 10; i++){
		for(int j = 0; j < 10; j++){
			if(i > 4 || j > 4){
				mx[i][j] = 0;
			}
		}
	}
	now = 0;
	for(int i = 0; i < 4; i++){
		for(int j = i; j < 5; j++){
			now += mx[i][i^1];
		}
	}
	maxh = max(maxh, now);
	while(next_permutation(cur,cur+5)){
		now = 0;
		//printf("perm is %d%d%d%d%d\n", cur[0], cur[1], cur[2], cur[3], cur[4]);
		for(int i = 0; i < 4; i ++){
			now += mx[cur[i]][cur[i+1]];
			now += mx[cur[i+1]][cur[i]];
		}
		for(int i = 2; i < 4; i++){
			now += mx[cur[i]][cur[i+1]];
			now += mx[cur[i+1]][cur[i]];
		}
		maxh = max(maxh, now);
		//printf("maxh is %d\n", maxh);
	}
	cout << maxh;
	return 0;
}

#include<iostream>
#include<algorithm>
#include<vector>
#include<map>
using namespace std;
int find (int v[],int a[][6])
  {
    long long i,j,max=0,ans=0;
    for(i=0;i<5;i++)
     {
    for(j=i;j<5-1;j=j+2)
      {
        ans=ans+a[v[j]][v[j+1]];
        ans=ans+a[v[j+1]][v[j]];
      }
     }

     return ans;
  }

int main()
 {
  int v[]={1,2,3,4,5};
  int a[6][6];
  int i,j;
  for(i=1;i<=5;i++)
   {
  for(j=1;j<=5;j++)
    {
      cin>>a[i][j];
    }
   }
  long long max=0,k;
  while ( std::next_permutation(v,v+5) )
   {     k=find(v,a);if(k>max){max=k;}

   }
   cout<<max<<endl;
 }

#include<bits/stdc++.h>
using namespace std;
int main()
{
    int v[5][5];
    for(int i=0;i<5;i++)
    for(int j=0;j<5;j++)
    cin>>v[i][j];
    int a[5]={1,2,3,4,5};
    int k=125,maxo=0;
    srand(time(NULL));

    while(k--)
    {
        int sum=0;
        for(int i=4;i>0;i--)
        {
            int j= rand()%(i+1);
            swap(a[i],a[j]);
        }
        for(int i=0;i<5;i+=2)
        {
            if(i+1<5)
            {
                sum+=v[a[i]-1][a[i+1]-1]+v[a[i+1]-1][a[i]-1];
            }
            else
            break;
        }
        maxo=max(maxo,sum);
    }
    cout<<maxo<<endl;
    return 0;

}

#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <cmath>
#include <map>
#include <cstring>
#include <string>
#include <stack>
#include <unordered_set>
using namespace std;

#pragma comment (linker, "/STACK:1000000000")

#define mp make_pair

int g[5][5];

int main()
{
    vector <int> a;
    int best;
    for (int i = 0; i < 5; i++)
        for (int j = 0; j < 5; j++)
            cin >> g[i][j];
        for (int i = 0; i < 5; i++)
            a.push_back(i);
        while (true)
        {
            int cur = 0;
            for (int i = -1; i < 4; i++)
                for (int j = i + 1; j < 4; j += 2)
                cur += g[a[j]][a[j + 1]] + g[a[j + 1]][a[j]];
            best = max(best, cur);
            if (!next_permutation(a.begin(), a.end()))
                break;
        }
        cout << best;
    return 0;
}

/*
 * ShowerLine.cpp
 *
 *  Created on: May 21, 2014
 *      Author: ESC
 */
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <utility>

using namespace std;

#define REP(i,n) for( (i)=0 ; (i)<(n) ; (i)++ )
#define rep(i,x,n) for( (i)=(x) ; (i)<(n) ; (i)++ )
#define REV(i,n) for( (i)=(n) ; (i)>=0 ; (i)-- )

int main() {
    int i,j, a [5][5],r[5],sum=0 ,res;
    REP(i,5)
        REP(j,5)
                cin>>a[i][j];

    REP(i,5)r[i]=i;

    for (i = 0; i < 4; i+=2)
        sum+=a[r[i]][r[i+1]],sum+=a[r[i+1]][r[i]];
    res=sum;
    sum=0;
    while(next_permutation(r,r+5)){
        for (j = 0; j < 4; ++j) {

        for (i = j; i < 4; i+=2) {
            sum+=a[r[i]][r[i+1]];
            sum+=a[r[i+1]][r[i]];
        }}
        res=max(sum,res);
        sum=0;

    }
            cout<<res<<endl;
}

#include <cstdio>
#include <iostream>
#include <algorithm>

using namespace std;

int ps[5] = {0, 1, 2, 3, 4};
int vs[5][5];

int calc()
{
    int res = 0;
    for (int i = 0; i < 5; i++) {
        for (int j = i; j < 5; j += 2) {
            int a = ps[j], b = ps[j + 1];
            res += vs[a][b] + vs[b][a];
        }
    }
    return res;
}

int next_permutation(int *st, int *end)
{
    bool flag = false;
    for (int *ptr = end - 1; ptr - 1 >= st; ptr--) {
        int *pre = ptr - 1;
        if (*pre < *ptr) {
            flag = true;
            int maxi = 0;
            int *maxp = NULL;
            for (int *mp = end - 1; mp > pre; mp--) {
                if (*mp > maxi) {
                    maxp = mp;
                    maxi = *mp;
                }
            }
            swap(*maxp, *pre);
            reverse(ptr, end);
            return 1;
        }
    }
    reverse(st, end);
    return 0;
}

int main()
{
    /*
    do {
        for (int i = 0; i < 5; i++) {
            printf("%d ", ps[i]);
        }
        puts("");
    } while (next_permutation(ps, ps + 5));
    */
    for (int i = 0; i < 5; i++) {
        for (int j = 0; j < 5; j++) {
            scanf("%d", &vs[i][j]);
        }
    }
    int maxi = 0;
    do {
        maxi = max(maxi, calc());
    } while (next_permutation(ps, ps + 5));
    printf("%d\n", maxi);
    return 0;
}

#include<iostream>

#include<cstdio>

using namespace std;

int main()
{
    int a[6][6];

    //freopen("in.txt", "r", stdin);

    for(int i = 1; i <= 5; i++)
    for(int j = 1; j <= 5; j++)
    cin >> a[i][j];

    int max = 0, x, y, tmp;

    for(int i = 1; i <= 5; i++)
    for(int j = 1; j <= 5; j++)
    {
        tmp = a[i][j] + a[j][i];
        if(max < tmp)
        {
            max = tmp;

            x = j;

            y = i;
        }
        a[i][j] = a[j][i] = tmp;
    }

    bool free[6];

    for(int i = 1; i <= 5; i++) free[i] = false;

    free[x] = free[y] = true;

    max = -1;

    int res[6];

    res[3] = x;

    res[4] = y;

    for(int i = 1; i <= 5; i++)
    if(!free[i])
    {
        if(max < a[y][i])
        {
            max = a[y][i];

            tmp = i;
        }
    }

    res[5] = tmp;

    free[tmp] = true;

    max = -1;

    for(int i = 1; i <= 5; i++)
    if(!free[i])
    {
        if(max < a[x][i])
        {
            max = a[x][i];

            tmp = i;
        }
    }

    res[2] = tmp;

    free[tmp] = true;

    for(int i = 1; i <= 5; i++)
    if(!free[i]) res[1] = i;

    int ans =  a[res[1]][res[2]] + 2 * a[res[3]][res[4]] + a[res[2]][res[3]] + a[res[4]][res[5]] * 2;
    cout << ans / 2;
}

#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define pp pop_back

int main()
{
    int arr[6][6];

    for(int i=1;i<=5;i++)
       for(int j=1;j<=5;j++)
           cin>>arr[i][j];

    int config[5] = {1, 2, 3, 4, 5};
    ll res = 0, curr;
    do{

        curr += (arr[config[0]][config[1]] + arr[config[1]][config[0]]) +
                (arr[config[2]][config[3]] + arr[config[3]][config[2]]) +
                (arr[config[1]][config[2]] + arr[config[2]][config[1]]) +
                (arr[config[3]][config[4]] + arr[config[4]][config[3]]) +
                (arr[config[2]][config[3]] + arr[config[3]][config[2]]) +
                (arr[config[3]][config[4]] + arr[config[4]][config[3]]);

        res = max(res, curr);

    }while(next_permutation(config, config + 5));

    cout<<res;
    return 0;
}

#include "cstdio"
#include "conio.h"
#include "string"
#include "iostream"

using namespace std;

int main(void)
{
    int a[53];
    char c ='1';
    string s;
    for (int i=0;i<4;i++)
        scanf("%d",&a[c+i]);
    scanf("\n");
    getline(cin, s);
    int n = s.length(), sum = 0;
    for (int i=0;i<n;i++)
        sum += a[s[i]];
    printf("%i",sum);
    return 0;
}

#include <bits/stdc++.h>
using namespace std;
int arr[6][6],i,j,maxi=0,a,b;
void calculation(string s)
{
    int counter=0;
    for(i=0;i<4;i++)
    {
        for(j=i;j<5;j+=2)
        {
            int a=s[j]-'0';
            int b=s[j+1]-'0';
            counter+=(arr[a][b]+arr[b][a]);
        }
    }
    maxi=max(maxi,counter);
}
int main()
{
    for(i=1;i<=5;i++)
    {
        for(j=1;j<=5;j++)
        {
            cin >> arr[i][j];
        }
    }
    string s="12345";
    for(;;)
    {
        calculation(s);
        if(!next_permutation(s.begin(),s.end())) break;
    }
    cout << maxi << endl;
}

// यथा चतुर्भिः कनकं परीक्ष्यते निघर्षणच्छेदनतापताडनैः। तथा चतुर्भिः पुरुषः परीक्ष्यते त्यागेन शीलेन गुणेन कर्मणा॥
#include <bits/stdc++.h>
using namespace std;
#define lld long long int
#define M 1000000007
#define fors(i,n) for(int i=0;i<n;++i)
#define fore(i,a,b) for(int i=a;i<=b;++i)
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define vv std::vector<int>
#define mapii std::map<int,int>
#define mpaci std::map<char,int>
#define umapii std::unordered_map<int,int>
#define umapci std::unordered_map<char,int>
#define seti std::set<int>
#define useti std::unordered_set<int>
#define qi std::queue<int>
#define qc std::queue<char>
#define sti std::stack<int>
#define stc std::stack<char>
#define endl "\n"
#define test(i) cout<<i<<endl
#define tests(i) cout<<"i: "<<i<<endl;
#define itrt int t; cin>>t; fors(i,t)
#define itr1 int t; cin>>t;
#define ff first
#define ss second
#define pb push_back
#define vmp make_pair
#define ppb pop_back
#define sorta(a,n) sort(arr,arr+n)
#define sortv(x) sort(x.begin(),x.end())
void file(){
    #ifdef LOCAL
    freopen("demo.in","r",stdin);
    freopen("demo.out","w",stdout);
    #endif
}
bool sortdes(const pair<int,int> &a, const pair<int,int> &b){return a.ss<b.ss;}
bool sortasc(const pair<int,int> &a, const pair<int,int> &b){return a.ss>b.ss;}
int gcd(int x,int y){return __gcd(x,y);}
// lld fact(lld n);
// lld nCr(lld n,lld r){return fact(n) / (fact(r) * fact(n - r));}
// lld fact(lld n){ lld res = 1; for(lld i = 2; i <= n; i++){res = res * i;}return res;}
// const int maxi = 1e6+10;
// vector<int> v[maxi];
// long long a[maxi];
// void dfs(int x,int y){
//     a[x]+=a[y];
//     for(int i:v[x]){
//         if(i!=y){
//             dfs(i,x);
//         }
//     }
// }

void test_case(){
    int c[5][5];
    // lld sum=0;
    for(int i=0;i<5;++i){
        for(int j=0;j<5;++j){
            cin>>c[i][j];
        }
    }
    cout<<c[1][2]+c[2][1]+2*c[0][4]+2*c[4][0]+c[0][2]+c[2][0]+2*c[4][3]+2*c[3][4];
}

int main(){
    fastio;
    file();
    int T=1;
    // int T;
    // cin>>T;
    for(int nr=1;nr<=T;++nr) {
        // cout<<"Case #"<<nr<<": ";
        test_case();
    }
}

#include<bits/stdc++.h>
using namespace std;

int main()
{
    int arr[6][6];
    for(int i=1;i<=5;i++)
    {
        for(int j=1;j<=5;j++)
        {
            cin>>arr[i][j];
        }
    }
    int ans=-1;
    string s="12345";
    while(next_permutation(s.begin(),s.end()))
    {
        int a,b,c,d,e;
        a=s[0]-'0';
        b=s[1]-'0';
        c=s[2]-'0';
        d=s[3]-'0';
        e=s[4]-'0';
        int A,B,C,D;
        A=arr[a][b]+arr[b][a]+arr[c][d]+arr[d][c];
        B=arr[b][c]+arr[c][b]+arr[d][e]+arr[e][d];
        C=arr[c][d]+arr[d][c];
        D=arr[d][e]+arr[e][d];
        ans=max(ans,(A+B+C+D));

    }
    cout<<ans<<endl;
}

#include<iostream>
#include<cstring>
#include<cstdio>
#include<string>
#include<cmath>
#include<algorithm>
#define LL int
#define inf 0x3f3f3f3f
using namespace std;
int a[6][6];
int f[]={1,2,3,4,5};
bool bj;
int main()
{
    LL n,m,i,j,k,l;
    LL a1,a2,a3,a4;
        for(i=1;i<=5;i++)
        {
            for(j=1;j<=5;j++)
            {
                scanf("%d",&a[i][j]);
            }
        }
        for(i=1;i<=5;i++)
        {
            for(j=i+1;j<=5;j++)
            {
                a[i][j]=a[j][i]=a[i][j]+a[j][i];
            }
        }
        LL ans=0;
        do
        {
            ans=max(ans,a[f[1]][f[2]]*2+a[f[2]][f[3]]*2+a[f[3]][f[4]]+a[f[4]][f[5]]);
        }
        while(next_permutation(f+1,f+6));
        printf("%d\n",ans);
    return 0;
}

#include <bits/stdc++.h>

using namespace std;

int seq[] = {1, 2, 3, 4, 5 };
int g[11][11];
int ans;

int cal()
{
    for(int i=0; i<5; i++) cout <<seq[i] <<' '; cout <<endl;
    int s=0;
    for(int i=0; i<4; i++) {
        for( int j=i; j<5; j+=2 ) {
            s = s + g[ seq[j] ][ seq[j+1] ] + g[ seq[j+1] ][ seq[j] ];
        }
    }
    return s;
}

int main(int argc, char ** argv)
{

    for(int i=1; i<=5; i++) {
        for(int j=1; j<=5; j++) {
            cin >>g[i][j];
        }
    }

    do{
        ans = max( cal(), ans);
    }while( next_permutation(seq, seq+5) );
    cout <<ans <<endl;

	return 0;
}

#include<iostream>
#include<cstdio>
#include<algorithm>
#define gc getchar

/*#ifndef ONLINE_JUDGE
#define gc getchar
#else
#define gc getchar_unlocked
#endif // ONLINE_JUDGE*/

using namespace std;

int input(){
    char c=gc();
    while(c<'0'||c>'9') c=gc();
    int ans=0;
    while(c>='0'&&c<='9'){
        ans=(ans<<3)+(ans<<1)+c-'0';
        c=gc();
    }
    return (ans);
}

int main(){
int permut[5]={0,1,2,3,4},ans=0;
int g[5][5],i,j;
for(i=0;i<5;i++){
    for(j=0;j<5;j++){
        cin>>g[i][j];
    }
}
/*for(i=0;i<5;i++){
    for(j=0;j<5;j++){
        cout<<g[i][j]<<" ";
    }
    cout<<"\n";
}*/

while(next_permutation(permut,permut+5)){
//    for(i=0;i<5;i++) cout<<permut[i]<<" ";
//    cout<<"\n";
    ans=max(ans,2*(g[permut[2]][permut[3]]+g[permut[3]][permut[2]])+2*(g[permut[3]][permut[4]]+g[permut[4]][permut[3]])+g[permut[0]][permut[1]]+g[permut[1]][permut[0]]+g[permut[1]][permut[2]]+g[permut[2]][permut[1]]);
}
printf("%d\n",ans);
return 0;
}

#include<bits/stdc++.h>
using namespace std;
int main()
{
	int matrix[5][5];
	for(int i=0; i<5; i++)
	{
		for(int j=0; j<5; j++)
		{
			int a; cin >> a;
			matrix[i][j] = a;
		}
	}
	int sequence[5] = {1,2,3,4,5};
	int max_element = -1;
	while(next_permutation(sequence,sequence+5))
	{
		int a = sequence[0]-1;
		int b = sequence[1]-1;
		int c = sequence[2]-1;
		int d = sequence[3]-1;
		int e = sequence[4]-1;
		int queue1 = matrix[a][b] + matrix[b][a] + matrix[c][d] + matrix[d][c];
		int queue2 = matrix[b][c] + matrix[c][b] + matrix[d][e] + matrix[e][d];
		int queue3 = matrix[c][d] + matrix[d][c];
		int queue4 = matrix[d][e] + matrix[e][d];
		int ans = queue1+queue2+queue3+queue4;
		if(ans>max_element)
		{
			max_element = ans;
		}
	}
	cout << max_element << '\n';
}

#include <iostream>
#include <algorithm>

using namespace std;

int hap[5][5];

int happiness(const int conf[])
{
    return 2*hap[conf[3]-1][conf[4]-1] + 2*hap[conf[2]-1][conf[3]-1] + hap[conf[0]-1][conf[1]-1] + hap[conf[1]-1][conf[2]-1];
}

int main()
{
    int max = 0;
    int conf[] = {1,2,3,4,5};

    for(int i = 0; i<5; i++)
        for(int j = 0; j<5; j++)
            cin >> hap[i][j];

    for(int i = 0; i<5; i++)
        for(int j = 0; j<5; j++)
            if(j<i)
                hap[i][j] = hap[j][i];
            else
                hap[i][j] += hap[j][i];

    while(next_permutation(conf, conf+5))
        if(max < happiness(conf))
            max = happiness(conf);

    cout << max << endl;

    return 0;
}

#include <bits/stdc++.h>
using namespace std;

#define lli long long int
#define ios ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define f(i,n) for(lli i=0;i<n;i++)
#define mod 1000000009
#define pb push_back
#define pop pop_back
#define mp make_pair
#define endl "\n"
#define display(a) for(lli i=0;i<a.size();i++) cout<<a[i]<<' '; cout<<endl;
inline long long toint(const std::string &s) {std::stringstream ss; ss << s; long long x; ss >> x; return x;}
inline std::string tostring(long long number) {std::stringstream ss; ss << number; return ss.str();}

//written by me

int main() {
    ios
    /*lli t;
    cin>>t;
    f(tt,t)
    {

    }*/
    lli a[6][6];
    f(i,5) f(j,5) cin>>a[i][j];
    lli p[6],ans=-1;
    f(i,5) p[i]=i;
    while(next_permutation(p,p+5))
    {
    	//01234
    	lli x = 0;
    	x+=a[p[0]][p[1]]+a[p[2]][p[3]]+a[p[1]][p[0]]+a[p[3]][p[2]];
    	//1234
    	x+=a[p[2]][p[1]]+a[p[1]][p[2]]+a[p[3]][p[4]]+a[p[4]][p[3]];
    	//234
    	x+=a[p[2]][p[3]]+a[p[3]][p[2]];
    	//34
    	x+=a[p[3]][p[4]]+a[p[4]][p[3]];

    	ans = max(ans,x);
    }
    cout<<ans;

    return 0;
}

#include<cstdio>
#include<vector>
#include<iostream>
#include<string>
#include<algorithm>

using namespace std;

int g[6][6];

int main()
{
    for(int i = 1 ;i <= 5; ++i)
        for(int j = 1;j <= 5; ++j) cin>>g[i][j];
    string s = "12345";
    int ans = 0;
    while( next_permutation(s.begin(),s.end()))
    {
        int a = s[0] - '0';
        int b = s[1] - '0';
        int c = s[2] - '0';
        int d = s[3] - '0';
        int e = s[4] - '0';
        int sum = g[a][b] + g[b][a] + g[b][c] + g[c][b] + 2 * (g[c][d] + g[d][c]) + 2 * (g[d][e] + g[e][d]);
        ans = max(ans,sum);

    }
    printf("%d\n",ans);

    return 0;
}

#include<bits/stdc++.h>
#include <vector>
#define ll long long int
#define io ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define vi vector<int>
#define pb push_back
#define mod 1000000007
using namespace std;

int main()
{
    int n = 5;
    vector<vi> g(5,vi(5,0));
    for(int i = 0 ; i < n ; ++i)
        for(int j = 0 ; j < n ; ++j)
            cin >> g[i][j];

    vi p(6), pans(6);
    int ans = -1, tmp;
    for(int i = 0 ; i < n ; ++i)
        p[i] = i;

    do
    {
        //01234
        tmp = g[p[0]][p[1]] + g[p[1]][p[0]];
        tmp += g[p[2]][p[3]] + g[p[3]][p[2]];

        //1234
        tmp += g[p[1]][p[2]] + g[p[2]][p[1]];
        tmp += g[p[3]][p[4]] + g[p[4]][p[3]];

        //234
        tmp += g[p[2]][p[3]] + g[p[3]][p[2]];

        //34
        tmp += g[p[3]][p[4]] + g[p[4]][p[3]];

        if(tmp > ans)
        {
            ans = tmp;
            for(int i = 0 ; i < n ; ++i)
                pans[i] = p[i];
        }
    }
    while(next_permutation(p.begin(), p.end()));

    cout << ans << "\n";
    return 0;
}

#include <bits/stdc++.h>
using namespace std;
typedef long double LD;
typedef long long ll;
#define int ll
#define ff(i,a,b) for (int i = a; i < b; i++)
#define bb(i,a,b) for (int i = a; i >= b; i--)
#define all(v) v.begin(),v.end()
#define show(a) for(auto xyz:a)cout<<xyz<<" ";cout<<endl;
#define F first
#define S second
#define lb lower_bound
#define ub upper_bound
#define yes cout<<"YES"<<endl;
#define no cout<<"NO"<<endl;
#define one cout<<-1<<endl;
#define pi 3.141592653589793238
#define mod 1000000007
int n;
int a[6][6];
int b[]={1,2,3,4,5};
int func(){
    return a[b[0]][b[1]]+a[b[1]][b[0]]+2*(a[b[2]][b[3]]+a[b[3]][b[2]])+a[b[1]][b[2]]+a[b[2]][b[1]]+a[b[3]][b[4]]+a[b[4]][b[3]]+a[b[3]][b[4]]+a[b[4]][b[3]];
}
void solve(){
    ff(i,1,6){
        ff(j,1,6){
            cin>>a[i][j];
        }
    }

    int happiness,ans=0;
    while(next_permutation(b,b+5)){
        happiness=func();
        if(happiness>ans){
            ans=happiness;
        }
    }
    cout<<ans<<endl;
}
signed main() {
    int t=1;
    //cin>>t;
    while(t--){
        solve();
    }
}

#include<iostream>
#include<cstring>
#include<cstdio>
#include<string>
#include<cmath>
#include<algorithm>
#define LL int
#define inf 0x3f3f3f3f
using namespace std;
int a[6][6];
int f[]={1,2,3,4,5};
bool bj;
int main()
{
    LL n,m,i,j,k,l;
    LL a1,a2,a3,a4;
    while(scanf("%d%d%d%d%d",&a[1][1],&a[1][2],&a[1][3],&a[1][4],&a[1][5])!=EOF)
    {
        for(i=2;i<=5;i++)
        {
            for(j=1;j<=5;j++)
            {
                scanf("%d",&a[i][j]);
            }
        }
        for(i=1;i<=5;i++)
        {
            for(j=i+1;j<=5;j++)
            {
                a[i][j]=a[j][i]=a[i][j]+a[j][i];
            }
        }
        LL ans=0;
        do
        {
            ans=max(ans,a[f[1]][f[2]]*2+a[f[2]][f[3]]+a[f[3]][f[4]]+a[f[4]][f[5]]*2);
        }
        while(next_permutation(f,f+5));
        printf("%d\n",ans);
    }
    return 0;
}

/**Header file**/
#include<cstdio>
#include<cstring>
#include<cmath>
#include<cstdlib>
#include<cctype>
#include<algorithm>
#include<string>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<sstream>
#include<stack>
#include<list>
#include<iostream>
#include<assert.h>

/**Define file I/O **/
#define f_input freopen("input.txt","r",stdin)
#define f_output freopen("output.txt","w",stdout)

/**Define memory set function**/
#define mem(x,y) memset(x,y,sizeof(x))
#define CLEAR(x) memset(x,0,sizeof(x))

/**Define function and object**/
#define pb push_back
#define Sort(v) sort(v.begin(),v.end())
#define RSort(v) sort(v.rbegin(),v.rend())
#define CSort(v,C) sort(v.begin(),v.end(),C)
#define all(v) (v).begin(),(v).end()
#define sqr(x) ((x)*(x))
#define find_dist(a,b) sqrt(sqr(a.x-b.x)+sqr(a.y-b.y))

/**Define constant value**/
#define ERR 1e-9
#define pi 2*acos(0)
#define PI 3.141592653589793

/**Define input**/
#define scanint(a) scanf("%d",&a)
#define scanLLD(a) scanf("%lld",&a)
#define scanstr(s) scanf("%s",s)
#define scanline(l) scanf(" %[^\n]",l);

/**Define Bitwise operation**/
#define check(n, pos) (n & (1<<(pos)))
#define biton(n, pos) (n | (1<<(pos)))
#define bitoff(n, pos) (n & ~(1<<(pos)))

/**Define color**/
#define WHITE 0
#define GREY 1
#define BLACK 2

using namespace std;

/**Typedef**/
typedef vector<int> vint;
typedef vector< vint > vint2D;
typedef vector<string> vstr;
typedef vector<char>vchar;
typedef vector< vchar >vchar2D;
typedef queue<int> Qi;
typedef queue< Qi > Qii;
typedef map<int,int> Mii;
typedef map<string,int> Msi;
typedef map<int,string> Mis;
typedef stack<int> stk;
typedef pair<int,int> pp;
typedef pair<int, pp > ppp;
typedef long long int LLD;
const int inf=0x7FFFFFFF;

/**Template & structure**/
struct point_int{int x,y;point_int(){}point_int(int a,int b){x=a,y=b;}}; ///Point for x,y (int) coordinate in 2D space
struct point_double{double x,y;point_double(){}point_double(double a,double b){x=a,y=b;}}; ///Point for x,y (double) coordinate in 2D space
struct Node{int v,w;Node() {}bool operator<(const Node &a)const{return w>a.w;}Node(int _v,int _w){v=_v,w=_w;}};///Node for Dijkstra
template<class T>T gcd(T a,T b){return b == 0 ? a : gcd(b, a % b);}
template<typename T>T lcm(T a, T b) {return a / gcd(a,b) * b;}
template<class T>T big_mod(T n,T p,T m){if(p==0)return (T)1;T x=big_mod(n,p/2,m);x=(x*x)%m;if(p&1)x=(x*n)%m;return x;}
template<class T>T multiplication(T n,T p,T m){if(p==0)return (T)0;T x=multiplication(n,p/2,m);x=(x+x)%m;if(p&1)x=(x+n)%m;return x;}
template<class T>T my_pow(T n,T p){if(p==0)return 1;T x=my_pow(n,p/2);x=(x*x);if(p&1)x=(x*n);return x;} ///n to the power p
template <class T> double getdist(T a, T b){return sqrt((a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y));}/// distance between a & b
template <class T> T extract(string s, T ret) {stringstream ss(s); ss >> ret; return ret;}/// extract words or numbers from a line
template <class T> string tostring(T n) {stringstream ss; ss << n; return ss.str();}/// convert a number to string
template<class T> inline T Mod(T n,T m) {return (n%m+m)%m;} ///For Positive Negative No.
template<class T> T MIN3(T a,T b,T c) {return min(a,min(b,c));} /// minimum of 3 number
template<class T> T MAX3(T a,T b,T c) {return max(a,max(b,c));} ///maximum of 3 number
template <class T> void print_vector(T &v){int sz=v.size();if(sz)cout<<v[0];for(int i = 1; i < sz; i++)cout << ' '<<v[i];cout<<endl;}/// prints all elements in a vector
bool isVowel(char ch){ ch=toupper(ch); if(ch=='A'||ch=='U'||ch=='I'||ch=='O'||ch=='E') return true; return false;}
bool isConsonant(char ch){if (isalpha(ch) && !isVowel(ch)) return true; return false;}

/**Shortcut input function**/
int read_int(){int n;scanf("%d",&n);return n;}
int read_LLD(){LLD n;scanf("%lld",&n);return n;}
inline int buffer_input() { char inp[1000]; scanstr(inp); return atoi(inp); }

/**Direction**/
///int col[8] = {0, 1, 1, 1, 0, -1, -1, -1};int row[8] = {1, 1, 0, -1, -1, -1, 0, 1}; ///8 Direction
///int col[4] = {1, 0, -1, 0};int row[4] = {0, 1, 0, -1}; ///4 Direction
///int dx[]={2,1,-1,-2,-2,-1,1,2};int dy[]={1,2,2,1,-1,-2,-2,-1};///Knight Direction
///int dx[]={-1,-1,+0,+1,+1,+0};int dy[]={-1,+1,+2,+1,-1,-2}; ///Hexagonal Direction

/******************************Ajaira Jinish Sesh******************************/

int g[6][6];
LLD calculate(string s)
{
    LLD sum=0;
    for(int i=0;i<=4;i++)
    {
        for(int j=i;j<=4;j+=2)
        {
            int i1=j;
            int i2=j+1;
            if(i1<=4&&i2<=4)
            {
                i1=s[i1]-48;
                i2=s[i2]-48;
                sum+=g[i1][i2]+g[i2][i1];
            }
        }
    }
    return sum;
}
int main()
{
    #ifdef _ANICK_
    //f_input;
    #endif // _ANICK_
    string ss="01234";
    for(int i=0;i<5;i++)
    {
        for(int j=0;j<5;j++)
        {
            g[i][j]=buffer_input();
        }
    }
    LLD ans=0;
    while(next_permutation(all(ss)))
    {
        ans=max(ans,calculate(ss));
    }
    cout<<ans<<endl;
    return 0;
}

#include <vector>
#include <algorithm>
#include <cstring>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <bitset>
#include <map>
#include <queue>
#include <climits>
#include <bitset>
#define LL long long
#define INFI 100000000000
#define D double
using namespace std;
#include <iomanip>

int main()
{
    LL arr[5][5]={{0}};
    for(LL i=0; i<5; i++)
    {
        for(LL j=0; j<5 ;j++)
        {
            cin>>arr[i][j];
        }
    }

    char a[]={'1','2','3','4','5'};
    LL m =0;
    while(next_permutation(a,a+5))
    {
        LL c= arr[a[0]-'1'][a[1]-'1']+arr[a[1]-'1'][a[0]-'1']+arr[a[2]-'1'][a[3]-'1']+arr[a[3]-'1'][a[2]-'1']+arr[a[1]-'1'][a[2]-'1']+arr[a[2]-'1'][a[1]-'1']+arr[a[3]-'1'][a[4]-'1']+arr[a[4]-'1'][a[3]-'1']+arr[a[2]-'1'][a[3]-'1']+arr[a[3]-'1'][a[2]-'1']+arr[a[3]-'1'][a[4]-'1']+arr[a[4]-'1'][a[3]-'1'];

        m = max(m,c);
    }
    cout<<m<<endl;
    return 0;
}

#include <iostream>
#include <cmath>
#include <ctime>
#include <algorithm>
#include <vector>
#include <queue>
#include <utility>
#include <stdio.h>
#include <stdlib.h>
#define stop cin.get();cin.get();cin.get();
using namespace std;
typedef unsigned long long ull;
typedef long long ll;

int m[5][5];

int n = 5;
ll max1 = -1, max2 = -1;
ll max1_i, max1_j, max2_i, max2_j;
int ii, jj, kk, pp, oo;

int main(){

    for(int i = 0; i <n; i++){
        for(int j = 0; j < n; j++){
          scanf("%d", &m[i][j]);
        }
    }

    for(int i = 0; i < n; i++){
        for(int j = 0; j < n; j++){
            for(int k = 0; k < n; k++){
                if(max1 < m[i][j] + m[j][i] + m[i][k] + m[k][i] && i != j && j != k && i != k ){
                    max1 = m[i][j] + m[j][i] + m[i][k] + m[k][i];
                    ii = i;
                    jj = j;
                    kk = k;
                }
            }
        }
    }
    for(int i = 0; i < n; i++){
        if(i != ii && i != kk && i != jj) { pp = i; break; }
    }
    oo = 10 - ii - jj - pp - kk;

    ll q, w, e, r;
    q = m[pp][jj] +m[jj][pp];
    w = m[pp][kk] + m[kk][pp];
    e = m[oo][jj] + m[jj][oo];
    r = m[oo][kk] + m[kk][oo];
    ll nn = max( max(q, w), max(e, r) );
    cout << max1*2 + nn + m[oo][pp]+m[pp][oo];

    //stop
    return 0;
}

#include<map>
#include<new>
#include<set>
#include<cmath>
#include<queue>
#include<stack>
#include<ctime>
#include<cstdio>
#include<memory>
#include<vector>
#include<bitset>
#include<cstdlib>
#include<cstring>
#include<utility>
#include<iostream>
#include<algorithm>
using namespace std;

int n=5;
int mx=-1;
int g[11][11];
int t[11];
bool used[11];

void dfs(int x)
{
	if(x==5)
	{
		int ans=g[t[0]][t[1]]+g[t[1]][t[1]]+g[t[1]][t[2]]+g[t[2]][t[1]]+
				2*(g[t[2]][t[3]]+g[t[3]][t[2]]+g[t[3]][t[4]]+g[t[4]][t[3]]);
		mx=max(ans,mx);
		return;
	}
	for(int i=1;i<=n;i++)
	{
		if(used[i]==false)
		{
			used[i]=true;
			t[x]=i;
			dfs(x+1);
			used[i]=false;
		}
	}
}

int main()
{
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=n;j++)
		{
			cin>>g[i][j];
		}
	}
	dfs(0);
	cout<<mx<<endl;
	return 0;
}

#include <iostream>
#include <cmath>
#include <ctime>
#include <algorithm>
#include <vector>
#include <queue>
#include <utility>
#include <stdio.h>
#include <stdlib.h>
#define stop cin.get();cin.get();cin.get();
using namespace std;
typedef unsigned long long ull;
typedef long long ll;

int m[5][5];

int n = 5;
ll max1 = -1, max2 = -1;
ll max1_i, max1_j, max2_i, max2_j;
int ii, jj, kk, pp, oo;

int main(){

    for(int i = 0; i <n; i++){
        for(int j = 0; j < n; j++){
          scanf("%d", &m[i][j]);
        }
    }

    for(int i = 0; i < n; i++){
        for(int j = 0; j < n; j++){
            for(int k = 0; k < n; k++){
                if(max1 < m[i][j] + m[j][i] + m[i][k] + m[k][i] && i != j && j != k ){
                    max1 = m[i][j] + m[j][i] + m[i][k] + m[k][i];
                    ii = i;
                    jj = j;
                    kk = k;
                }
            }
        }
    }
    for(int i = 0; i < n; i++){
        if(i != ii && i != kk && i != jj) { pp = i; break; }
    }
    oo = 10 - ii - jj - pp - kk;

    ll q, w, e, r;
    q = m[pp][jj] +m[jj][pp];
    w = m[pp][kk] + m[kk][pp];
    e = m[oo][jj] + m[jj][oo];
    r = m[oo][kk] + m[kk][oo];
    ll nn = max( max(q, w), max(e, r) );
    cout << max1*2 + nn + m[oo][pp]+m[pp][oo];

    //stop
    return 0;
}

#include<stdio.h>
#include<algorithm>
using namespace std;
const int maxn=7;
int n=5,g[maxn][maxn],ans=0;
int s[maxn],vis[maxn]={0};
void dfs(int x)
{
	int i;
	if(x==n)
	{
		ans=max(ans,g[s[1]][s[2]]+g[s[2]][s[1]]+g[s[2]][s[3]]+g[s[3]][s[2]]+2*(g[s[3]][s[4]]+g[s[4]][s[3]]+g[s[4]][s[5]]+g[s[5]][s[4]]));
		return ;
	}
	for(i=1;i<=n;i++)
		if(!vis[i])
		{
			s[x]=i;
			vis[x]=1;
			dfs(x+1);
			vis[x]=0;
		}
}
int main()
{
	int i,j;
	for(i=1;i<=n;i++)
		for(j=1;j<=n;j++)
			scanf("%d",&g[i][j]);
	dfs(0);
	printf("%d\n",ans);
	return 0;
}

/*
 * ShowerLine.cpp
 *
 *  Created on: May 21, 2014
 *      Author: ESC
 */
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <utility>

using namespace std;

#define REP(i,n) for( (i)=0 ; (i)<(n) ; (i)++ )
#define rep(i,x,n) for( (i)=(x) ; (i)<(n) ; (i)++ )
#define REV(i,n) for( (i)=(n) ; (i)>=0 ; (i)-- )

int main() {
    int i,j, a [5][5],r[5],sum=0 ,res;
    REP(i,5)
        REP(j,5)
                cin>>a[i][j];

    REP(i,5)r[i]=i;

    for (i = 0; i < 4; i+=2)
        sum+=a[r[i]][r[i+1]],sum+=a[r[i+1]][r[i]];
    res=sum;
    sum=0;
    while(next_permutation(r,r+5)){
        for (j = 0; j < 5; ++j) {

        for (i = j; i < 4; i+=2) {
            sum+=a[r[i]][r[i+1]];
            sum+=a[r[i+1]][r[i]];
        }}
        res=max(sum,res);
        sum=0;

    }
            cout<<res<<endl;
}

#include <iostream>
#include<bits/stdc++.h>
using namespace std;

int main()
{
    int g[6][6];
    int x[5];
    for(int i=0;i<5; i++)
    {
        x[i] = i;
        for(int j=0;j<5;j++)
        {
            cin>>g[i][j];
        }
    }
    int maxhap =0;
    do
    {
        int hap = g[x[0]][x[1]] + g[x[1]][x[0]] + g[x[1]][x[2]] + g[x[2]][x[1]] + 2 * (g[x[2]][x[3]] + g[x[3]][x[2]]) + 2 * (g[x[3]][x[4]] + g[x[4]][x[3]]);
        if(hap>maxhap) maxhap = hap;
        cout<<hap<<" ";
    }while(next_permutation(x,x+5));
    cout<<maxhap;
}

#include <bits/stdc++.h>
using namespace std;

#define input(_x) int _x;_x=getint();
#define input_s(_x) string _x;cin>>_x;
#define input_lli(_x) lli _x;cin>>_x;
#define input_ulli(_x) ulli _x;cin>>_x;
#define TCASE int _t;cin>>_t;FOR(_i,1,_t)
#define FOR(_i,_a,_b) for(int _i=_a;_i<=_b;_i++)
#define nFOR(_i,_a,_b) for(int _i=_a;_i>=_b;_i--)
#define REPEAT(_i,_b) for(int _i=1;_i<=_b;_i++)
#define VECTORFILL(_vec) int _x;_x=getint();while(_x!=-1){vec.push_back(_x);_x=getint();}
#define VECTOR_FILL(_vec,size) {int _x;FOR(_,1,size){_x=getint(); _vec.pb(_x);}}
#define VECTORPRINT(_vec) {int _t=0;while(_t<_vec.size()){cout<<_vec[_t++]<<' ';}}
#define pb push_back
#define mp make_pair
#define all(_vec) _vec.begin(),_vec.end()
#define X first
#define Y second
#define ARR_SIZE(_arr) sizeof(_arr)/sizeof(_arr[0])
int ARRSIZE(int arr[]){int index=0;while(arr[index]!=-1){index++;}return index;}
#define ARRFILL(_arr) int _index=0,_x;cin>>_x;while(_x!=-1){_arr[_index++]=_x;cin>>_x;}arr[_index]=-1;
#define ARR_FILL(_arr,_size) REPEAT(_i,_size){ input(_x); _arr[_i-1]=_x; }
#define ARRPRINT(_arr) FOR(i,0,ARRSIZE(_arr)-1) cout<<_arr[i]<<endl;
#define arr_clear(a,x) memset(a, x, sizeof(a))
#define INT(_s) stoi(_s)
string STR(int _a){stringstream ss; ss<<_a; return ss.str();}
#define LOWER(_s) transform(_s.begin(), _s.end(), _s.begin(), ::tolower);
#define UPPER(_s) transform(_s.begin(), _s.end(), _s.begin(), ::toupper);
#define MOD 1000000007
#define READ(x) freopen(x,"r",stdin)
#define WRITE(x) freopen(x,"w",stdout)

typedef long long int lli;
typedef unsigned long long int ulli;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<lli> vlli;
typedef pair<int,int> pii;
typedef vector<pair<int,int> > vpii;
typedef set<string> si;
typedef list<pair<int,int> > lpii;

int main(){
    READ("in.txt");
    lli  a[6][6];
    FOR(i,1,5)
        FOR(j,1,5)
            cin>>a[i][j];

    int b[]={0,1,2,3,4,5};
    lli maxi=0,count;
    do{
        count = a[b[1] ][b[2] ] + a[b[2] ][b[1] ] + 2*( a[b[3] ][b[4] ] + a[b[4] ][b[3] ] );
        count += a[b[2] ][b[3] ] + a[b[3] ][b[2] ] + 2*( a[b[4] ][b[5] ] + a[b[5] ][b[4] ] );
        maxi=max(maxi,count);
    }while(next_permutation(b+1,b+6));
    cout<<maxi;
  return 0;
}

#include<bits/stdc++.h>
using namespace std;
#define deb(x) cout << ">" << #x << '=' << x << endl;
void solve(){
int v[5][5];
int n=5;
for(int i=0;i<n;i++){
  for(int j=0;j<n;j++){
    cin>>v[i][j];
  }
}
int trans[5][5];
for(int i=0;i<n;i++){
  for(int j=0;j<n;j++){
    trans[j][i]=v[i][j];
  }
}
// for(int i=0;i<n;i++){
//   for(int j=0;j<n;j++){
//     cout<<trans[i][j]<<" ";
//   }
//   cout<<endl;
// }
vector<int> sums;
for(int i=0;i<n;i++){
  for(int j=i+1;j<n;j++){
    sums.push_back(v[i][j]+trans[i][j]);
  }
}
// for(auto i:sums){
//   cout<<i<<" ";
// }cout<<endl;
sort(sums.begin(),sums.end());
// for(auto i:sums){
//   cout<<i<<" ";
// }
cout<< 2*sums[9] + 2* sums[8] +sums[6] + sums[0]<<endl;

}
int main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("out.txt", "w", stdout);
#endif
  // int t = 1;
  // cin >> t;
  // while (t--)
  solve();
  cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n";
  return 0;
}

#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <string.h>
#include <stdlib.h>
#include <iterator>
#include <sstream>
#include <numeric>
#include <fstream>
#include <vector>
#include <cctype>
#include <math.h>
#include <deque>
#include <queue>
#include <stack>
#include <set>
#include <map>
//#include <windows.h>
using namespace std;

#define FRE(i,a,b) for(i = a; i <= b; i++)
#define FRL(i,a,b) for(i = a; i < b; i++)
#define mem(t, v) memset ((t) , v, sizeof(t))
#define all(x) x.begin(),x.end()
#define sf(n) scanf("%d", &n)
#define pf(n) printf("%d", n)
#define inf (1 << 29 - 1)
#define VI vector <int>
#define QI queue <int>
#define pb push_back
#define sz size()
#define pb push_back
#define mp make_pair
#define ins insert
#define fi first
#define se second
#define check(mask, k) (mask & (1 << k))
#define Set(mask, k) (mask | (1 << k))
#define read() freopen("c:\\Users\\User\\Desktop\\Input.txt", "r", stdin)
#define write() freopen("c:\\Users\\User\\Desktop\\Output.txt", "w", stdout)
#define MAX 110

//int dx[] = {+0,+0,+1,-1};
//int dy[] = {+1,-1,+0,+0};
//int dx[] = {-1,-1,-1,+0,+0,+1,+1,+1};
//int dy[] = {-1,+0,+1,-1,+1,-1,+0,+1};

typedef long long int LL;
typedef double db;
vector<int> v;
int data[10][10];

int calc()
{
    return data[v[1]][v[2]]+data[v[2]][v[1]]+data[v[3]][v[2]]+ data[v[2]][v[3]] + 2*data[v[3]][v[4]] + 2*data[v[4]][v[3]] + 2*data[v[4]][v[5]] + 2*data[v[5]][v[4]];
}

int main()
{
    //freopen("in.txt", "r", stdin);

    int i, j, k, t, cs, n, mx = 0;

    FRE(i,1,5)
        FRE(j,1,5) sf(data[i][j]);

    FRE(i,0,5) v.pb(i);

    while(next_permutation(all(v)))
        mx = max(mx,calc());

    printf("%d\n", mx);
    return 0;
}

#include <bits/stdc++.h>

#define java ios_base::sync_with_stdio; cout.tie(0); cin.tie(0);
#define S second
#define F first
#define pb push_back
#define nl '\n'

const long long MXN = 1e6 + 1;
const long long MNN = 1e3 + 1;
const long long MOD = 1e9 + 7;
const long long INF = 1e18;

typedef long long llong;
typedef unsigned long long ulong;

using namespace std;

llong n, ans, b[10][10], m, c[MXN], cnt, mx = -1;

int main(){
    java;
    freopen("input.txt" , "r" , stdin);
    vector<int> v;
    for(int i = 1; i <= 5; i++){
        for(int j = 1; j <= 5; j++){
            cin >> b[i][j];
        }c[i] = i;
    }while(next_permutation(c + 1, c + 6)){
        llong x = (b[c[1]][c[2]] + b[c[2]][c[1]] + b[c[3]][c[4]] + b[c[4]][c[3]]);
        x +=  (b[c[2]][c[3]] + b[c[3]][c[2]] + b[c[5]][c[4]] + b[c[4]][c[5]]);
        x += b[c[3]][c[4]] + b[c[4]][c[3]];
        x += b[c[4]][c[5]] + b[c[5]][c[4]];
        mx = max( mx, x);
    }cout << mx;
    return 0;
}

#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define pp pop_back

int main()
{
    int arr[6][6];

    for(int i=1;i<=5;i++)
       for(int j=1;j<=5;j++)
           cin>>arr[i][j];

    int config[5] = {1, 2, 3, 4, 5};
    ll res = 0, curr;
    do{

        curr += (arr[config[0]][config[1]] + arr[config[1]][config[0]]) +
                (arr[config[2]][config[3]] + arr[config[3]][config[2]]) +
                (arr[config[1]][config[2]] + arr[config[2]][config[1]]) +
                (arr[config[3]][config[4]] + arr[config[4]][config[3]]) +
                (arr[config[2]][config[3]] + arr[config[3]][config[2]]) +
                (arr[config[3]][config[4]] + arr[config[4]][config[3]]);

        res = max(res, curr);

    }while(next_permutation(config, config + 5));

    cout<<res;
}

#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int simulate(vector<int> &v,vector<vector<int> > &m)
{
    int res = 0;
    for(int c=0;c<v.size();c++)
    {
        for(int c2=0;c2+1<v.size();c2+=2)
        {
            res+=m[v[c2]][v[c2+1]];
        }
    }
    return res;
}

int main()
{
    vector<vector<int> > m(5,vector<int>(5));
    for(int c=0;c<5;c++) for(int c2=0;c2<5;c2++) cin>>m[c][c2];
    vector<int> permut(5,0);
    for(int c=0;c<5;c++) permut[c]=c;
    int res = 0;
    do
    {
        res = max(res,simulate(permut,m));
    }while(next_permutation(permut.begin(),permut.end()));
    cout<<res;
}

#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define ld long double
#define REP(i,a,b) for(int i=a;i<b;++i)
#define neg1(m) memset(m,-1,sizeof(m))

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int n=5,p[]={0,1,2,3,4},a[5][5],ans=0;
    REP(i,0,n)
        REP(j,0,n)
            cin>>a[i][j];

    do
    {
        int val=a[p[0]][p[1]]+a[p[1]][p[0]];
        val+=a[p[1]][p[2]]+a[p[2]][p[1]];
        val+=(a[p[2]][p[3]]+a[p[3]][p[2]])*2;
        val+=(a[p[3]][p[4]]+a[p[4]][p[3]])*2;

        if(val>ans)
            ans=val;

    } while (next_permutation(p,p+n));

    return 0;
}

#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <utility>

using namespace std;

#define REP(i,n) for( (i)=0 ; (i)<(n) ; (i)++ )
#define rep(i,x,n) for( (i)=(x) ; (i)<(n) ; (i)++ )
#define REV(i,n) for( (i)=(n) ; (i)>=0 ; (i)-- )

int main() {
    int i,j, a [5][5],r[5],sum=0 ,res=0;
    REP(i,5)
        REP(j,5)
                cin>>a[i][j];

    REP(i,5)r[i]=i;
    REP(i,5)cout<<r[i];
    cout << endl;

        for(int k = 0 ;k<120;k++){
        for (j = 0; j < 4; ++j) {

        for (i = j; i < 4; i+=2) {
            sum+=a[r[i]][r[i+1]];
            sum+=a[r[i+1]][r[i]];
        }}
        res=max(sum,res);
        sum=0;
        next_permutation(r,r+5);
    }
            cout<<res<<endl;
}

#include <bits/stdc++.h>

using namespace std;

const int N = 2e5 + 10;
typedef long long int ll;

ll n, m;
int a[N], b[N];

int main() {
	n = 5;
	int grid[n][n];
	for(int i = 0; i < n; ++i) {
		for(int j = 0; j < n; ++j) {
			cin >> grid[i][j];
		}
	}
	vector<int> perm;
	for(int i = 0; i < n; ++i) perm.push_back(i);
	ll ans = 0;
	do {
		ll cur = 0;
		for(int start = 0; start < n; ++start) {
			for(int i = start + 1; i < n; i++) {
				cur += grid[perm[i - 1]][perm[i]];
				cur += grid[perm[i]][perm[i - 1]];
			}
		}
		ans = max(ans, cur);
	} while(next_permutation(perm.begin(), perm.end()));

	cout << ans << endl;

	return 0;
}

//65 69 73 77 81 85 89 93 97

#include <iostream>
using namespace std;

short a [5] ;
bool check [5] ;
int biggestOne;
short g [5][5] ;

inline int Implement (){
	int total = 0;
	for (int i = 0 ; i < 5 ; i++) {
		for (int j = i ; j < 4 ; j+=2) {
			total += g[a[j] - 1][a[j+1] - 1] + g[a[j+1] -1][a[j] - 1] ;
		}
	}
	return total ;
}

inline void ShowerLine (int n, int k){
	if (k == n) {
		int res = Implement () ;

		if (res > biggestOne)
			biggestOne = res;
		return ;
	}

	for (int i = 0 ; i < n ; i++){
		if (!check[i]) {
			a[k] = i + 1 ;
			check[i] = true ;
			ShowerLine (n, k + 1) ;
			check[i] = false ;
		}
	}
}

int main () {

	for (int i = 0 ; i < 5 ; i++) {
		cin >> g[i][0] >> g[i][1] >> g[i][2] >> g[i][3] >> g[i][4] ;
	}

	ShowerLine (5, 0) ;

	cout << biggestOne << endl;

	return 0;
}

#include <bits/stdc++.h>

using namespace std;

//error
#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }

void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
	cerr << *it << " = " << a << endl;
	err(++it, args...);
}

//output
#define output(x) cout << x << endl

//input
#define input(x) {int x; cout << x << endl;}

//loop
#define f(i, n) for(int i = 0; i < n; i++)
#define fs(i, s, n) for(int i = s; i < n; i++)

#define ll long long

int main(int argc, char const *argv[])
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	int arr[5][5];

	f(i, 5) {
		f(j, 5) {
			cin >> arr[i][j];
		}
	}

	int selectedRow[5] = {0};

	int sum = 0;

	int maximumValue = -1;
	int maximumValueColumn = -1;
	int maximumValueRow = -1;

	f(i, 5) {
		fs(j, i, 5) {
			arr[i][j] = arr[j][i] = arr[i][j] + arr[j][i];

			if (arr[i][j] > maximumValue) {
				maximumValueColumn = j;
				maximumValueRow = i;
				maximumValue = arr[i][j];
			}
		}
	}

	sum += maximumValue*2;

	selectedRow[maximumValueRow] = 1;
	selectedRow[maximumValueColumn] = 2;

	int secondMaxRow = -1;
	int secondMaximumValue = -1;

	f(i, 5) {
		if (i != maximumValueRow) {
			if (arr[i][maximumValueColumn] > secondMaximumValue) {
				secondMaximumValue = arr[i][maximumValueColumn];
				secondMaxRow = i;

			}
		}
	}

	sum += secondMaximumValue*2;

	selectedRow[secondMaxRow] = 1;

	int nextMaximumValue = -1, nextMaximumRow = -1;

	f(i, 5) {
		if (selectedRow[i] == 0) {
			f (j, 5) {
				if (selectedRow[j] == 1) {
					if (arr[i][j] > nextMaximumValue) {
						nextMaximumValue = arr[i][j];
						nextMaximumRow = i;
					}
				}
			}
		}
	}

	selectedRow[nextMaximumRow] = 1;
	sum += nextMaximumValue;

	f(i, 5) {
		if (selectedRow[i] == 0) {
			sum += arr[i][nextMaximumRow];
		}
	}

	output(sum);

	return 0;
}

								// GUESS .... I MADE A MISTAKE
#include<bits/stdc++.h>
using namespace std;

#define FAST_I0 ios_base::sync_with_stdio(false); cin.tie(NULL);
#define endl "\n"
#define int long long
#define vvi vector<int>
#define pb push_back

void think(){
	int sum[5][5];
	for(int i=0; i<5; i++){
		for(int j=0; j<5; j++){
			cin >> sum[i][j];
			}
		}
	int a = -1,b=-1,c=-1,d=-1,e =-1;
	int mx = -1;
	for(int i=0; i<5; i++){
		for(int j=0; j<5; j++){
			if(sum[i][j] + sum[j][i] > mx){
				mx = sum[i][j] + sum[j][i];
				c = i;
				d = j;
				}

		}

		}
	//	cout << c << " " << d << endl;
		mx = -1;
		int mx1 = -1;
		int temp = 0,temp0 = 0;
	for(int i=0; i<5; i++){
		if(sum[i][c] + sum[c][i] > mx && i !=d && i!=c){
			mx = sum[i][c] + sum[c][i];
			temp = i;
			}
		if(sum[i][d] + sum[d][i] > mx1 && i != c && i!=d){
			mx1 = sum[i][d] + sum[d][i];
			temp0 = i;
			}
		}
	//	cout << mx << " " << mx1 << endl;
	if(mx > mx1){
		swap(c,d);
		e = temp;
		mx = -1;
		for(int i=0; i<5; i++){
			if(sum[i][c] + sum[i][c] > mx && i != e && i !=c && i != d){
				mx = sum[i][c] + sum[i][c];
				b = i;
				}
			}
		for(int i=0; i<5; i++){
			if(i != b && i != e && i !=c && i != d){
				a = i;
				}
			}
		}else if(mx < mx1){
			e = temp0;
			mx = -1;
		for(int i=0; i<5; i++){
			if(sum[i][c] + sum[i][c] > mx && i != e && i !=c && i != d){
				mx = sum[i][c] + sum[i][c];
				b = i;
				}
			}
		for(int i=0; i<5; i++){
			if(i != b && i != e && i !=c && i != d){
				a = i;
				}
			}
			}else{
				int mx2 = -1;
				mx = -1;
				mx1 = -1;
				int temp3 = 0,temp1 = 0,temp2 = 0;
				int x = -1,y = -1;
				for(int i = 0; i<5; i++){
					if(sum[i][temp] + sum[temp][i] > x && i!=c && i!=d){
						x = sum[i][temp] + sum[temp][i];
						}
					}
				for(int i = 0; i<5; i++){
					if(sum[i][temp1] + sum[temp1][i] > y && i!=c && i!=d){
						y = sum[i][temp1] + sum[temp1][i];
						}
					}
				if(x >= y){
					e = temp;
					}else{
						e = temp1;
						}
				for(int i=0; i<5; i++){
					if(sum[i][c] + sum[c][i] > mx && i != d && i !=e){
						mx = sum[i][c] + sum[c][i];
						temp3 = i;
						}
					}
				for(int i=0; i<5; i++){
					if(sum[i][d] + sum[d][i] > mx && i != c && i !=e){
						mx1 = sum[i][d] + sum[d][i];
						temp1 = i;
						}
					}
				for(int i=0; i<5; i++){
					if(sum[i][e] + sum[e][i] > mx && i != d && i !=c){
						mx2 = sum[i][e] + sum[e][i];
						temp2 = i;
						}
					}
				if(mx >= mx1 && mx >= mx2){
					b = temp3;
					for(int i = 0; i<5; i++){
						if(i != b && i != c && i != d && i !=e){
							a = i;
							}
						}
					}else if(mx1 >= mx2 && mx1 >= mx){
					b = temp1;
					for(int i = 0; i<5; i++){
						if(i != b && i != c && i != d && i !=e){
							a = i;
							}
						}
						swap(c,d);
					}else if(mx2 >= mx1 && mx2 >= mx){
					b = temp2;
					for(int i = 0; i<5; i++){
						if(i != b && i != c && i != d && i !=e){
							a = i;
							}
						}
						swap(e,c);
					}
				}
		//		cout << a << " " << b << " " << c << " " << d << " " << e << endl;
		cout << sum[a][b] + sum[b][a] + sum[c][b] + sum[b][c] + 2*(sum[c][d] + sum[d][c] + sum[d][e] + sum[e][d]) << endl;
}

int32_t main(){
	FAST_I0;
	int testcase = 1;
//	cin >> testcase;
	while(testcase--){
		think();
		}
	return 0;

}

#include<cstdio>
#include<algorithm>
using namespace std;
int a[10],map[10][10],i,j,ans;
int main(){
    for (i=1;i<=5;i++)
        for (j=1;j<=5;j++)
            scanf("%d",&map[i][j]);
    for (i=1;i<=5;i++) a[i]=i;
    while (1){
        for (i=5;i>=1;i--)
            if (a[i]<a[i+1]) break;
        int flag=1;
        for (int k=1;k<=5;k++)
            if (a[k]!=5-k+1)
                flag=0;
        if (flag) break;
        int max=1000000000,pos;
        for (j=i+1;j<=5;j++)
            if (a[j]>a[i]&&a[j]<max){
                max=a[j];
                pos=j;
            }
        j=pos;
        swap(a[i],a[j]);
        for (int k=i+1;k<=(5+i+1)/2;k++)
            swap(a[k],a[5+i+1-k]);

        int now=0;
        for (i=1;i<=4;i++)
            for (j=i;j<=4;j+=2)
                now+=map[a[j]][a[j+1]]+map[a[j+1]][a[j]];
        if (now>ans) ans=now;
    }
    printf("%d",ans);
}

#include <iostream>
#include <algorithm>
using namespace std;

long long a[6]={1,2,3,4,5},i,b[6][6],j,ans=0,m=0;

int main()
{
    for(i=1;i<=5;i++)
    {
        for(j=1;j<=5;j++)
        {
            cin >> b[i][j];
        }
    }
    do{
        for(i=1;i<=4;i++)
        {
            for(j=i;j<=4;j+=2)
            {
                m+=b[a[j]][a[j+1]]+b[a[j+1]][a[j]];
            }
        }
        if(ans<m)
            ans=m;
        m=0;
    }while(next_permutation(a,a+5));
    cout << ans;
    return 0;
}

#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef vector<long long> vl;
typedef pair<long long , long long > pl;
#define po pop_back
#define pb push_back
#define mk make_pair
#define lw lower_bound
#define up upper_bound
#define ff first
#define ss second
#define boost ios_base::sync_with_stdio(); cin.tie(0); cout.tie(0);
#define MOD 1000000007
#define MAX 1e18
#define MIN -1e18
#define rep(i,a,b) for(ll i=a;i<=b;i++)
#define per(i,a,b) for(ll i=a;i>=b;i--)
#define con continue
#define freopen freopen("input.txt", "r", stdin);freopen("output.txt", "w", stdout);
#define PI 3.14159265358979323846264338327950288419716939937510582097494459230781640628
typedef tree<ll , null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;

ll a,b,c[1234567],d[5234567],c1[1234][1234],e[1234567],n,j,i,l,r,x,y,k,ans,sum;
bool used[3234567];
ll T;
vector<ll> v1,v[1234567];
string s,ss[1234567],s1;
char ch[1234][1234];
pl p[1234567];
priority_queue<ll> pq;
ll dx[4]={1,-1,0,0},dy[4]={0,0,1,-1};
map<ll,ll> mp,mp1;
map<string , ll> ms;
queue<pl> q;
set<ll> st;
ll N=5e6+1;
int main(){
    ll q[5]={0,1,2,3,4};
    rep(i,0,4){
        rep(j,0,4){
            cin>>c1[i][j];
        }
    }
    ans=0;
    do{
        ll res=0;
        res = c1[q[0]][q[1]]+c1[q[1]][q[0]];
        res += c1[q[1]][q[2]]+c1[q[2]][q[1]];
        res += 2*(c1[q[2]][q[3]]+c1[q[3]][q[2]]);
        res += 2*(c1[q[3]][q[4]]+c1[q[4]][q[3]]);
        ans=max(ans,res);
    }while(next_permutation(q,q+4));
    cout<<ans;
}

#include<iostream>
#include<string>
#include<math.h>
#include<algorithm>
#include<cstdio>
#include<stdio.h>
#include<cstdlib>
#include<stack>
#include<deque>
#include<queue>
#include<utility>
#include<iomanip>
using namespace std;
int a[1000][1000],ans,s[10];
int main()
{
/*freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);*/
s[0]=2;
s[1]=3;
s[2]=1;
s[3]=5;
s[4]=4;
for(int i = 1; i <= 5; i++)
{
	for(int j = 1; j <= 5; j++)
	{
		cin >> a[i][j];
	}
}
while(next_permutation(s,s+5))
{
	int x = (a[s[0]][s[1]]+a[s[1]][s[0]]+a[s[2]][s[3]]+a[s[3]][s[2]])+(a[s[1]][s[2]]+a[s[2]][s[1]]+a[s[3]][s[4]]+a[s[4]][s[3]])+(a[s[2]][s[3]]+a[s[3]][s[2]])+(a[s[3]][s[4]]+a[s[4]][s[3]]);
	ans = max(ans,x);
}
cout << ans;
return 0;
}

#include<cstdio>
#include<algorithm>
int main(){
	int g[5][5];
	int ans=0;
	for(int i=0;i<5;i++)
		for(int j=0;j<5;j++)
			scanf("%d",&g[i][j]);
	for(int i=0;i<5;i++){
		for(int j=0;j<5;j++){
			if(j==i)continue;
			for(int k=0;k<5;k++){
				if(k==i||k==j)continue;
				for(int l=0;l<5;l++){
					if(l==i||l==j||l==k)continue;
					for(int m=0;m<5;m++){
						if(m==i||m==j||m==k||m==l)continue;
						ans=std::max(ans,g[i][j]+g[j][i]+g[j][k]+g[k][j]+g[k][l]+g[k][l]+g[l][k]+g[l][k]+g[l][m]+g[l][m]+g[m][l]+g[m][l]);
					}
				}
			}
			printf("%d\n",ans);
			return 0;
		}
	}
}

#include<iostream>
using namespace std;

int R[5][5],a,b,c,d,e,sum =0;
	 int count = 0;
	 string swap(string s, int fixed, int replace)
	 {
		 char temp = s[fixed];
		 s[fixed] = s[replace];
		 s[replace] = temp;
		 return s;
	 }
	int permuteString( string s, int fixed, int size )
	{
		if(fixed == size)
		{
			a = s[0]-'0';a--;
			b = s[1]-'0';b--;
			c = s[2]-'0';c--;
			d = s[3]-'0';d--;
			e = s[4]-'0';e--;
			long long int p = (R[a][b]+R[b][a]+R[b][c]+R[c][b]);
			p+=2*(R[c][d]+R[d][c]+R[d][e]+R[e][d]);
			cout<<R[a][b]<<"\n";
			if(p>sum)
			{
				sum = p;
			}
			return 0;
		}
		for(int i = fixed;i<size;i++)
		{
			if(fixed!=i)
			{
			  s = swap(s,fixed,i);
		    }
		  permuteString(s, fixed+1, size);
		}
		return 0;
	}

int main()
{
	for(int i = 0;i<5;i++)
	{
		for(int j =0;j<5;j++)
		{
			cin>>R[i][j];
		}
		cout<<"\n";
	}
	permuteString("12345",0,5);
	cout<<sum;
	return 0;
}

#include <bits/stdc++.h>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <bits/stdc++.h>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstring>
#include <chrono>
#include <complex>
#define endl "\n"
#define ll long long int
#define vi vector<int>
#define vll vector<ll>
#define vvi vector < vi >
#define pii pair<int,int>
#define pll pair<long long, long long>
#define mod 1000000007
#define inf 1000000000000000001;
#define all(c) c.begin(),c.end()
#define mp(x,y) make_pair(x,y)
#define mem(a,val) memset(a,val,sizeof(a))
#define eb emplace_back
#define f first
#define s second

using namespace std;
int main()
{
    std::ios::sync_with_stdio(false);
    int cost[5][5];
    for(int i = 0; i < 5; i++){
        for(int j = 0; j < 5; j++){
            cin >> cost[i][j];
        }
    }
    vector<int> orig = {1,2,3,4,5};
    vector<int> cur = {1,2,3,4,5};
    next_permutation(cur.begin(), cur.end());
    int maxim = INT_MIN;
    while(cur != orig){
        //for(int i : cur) cout << i << " ";
        //cout << endl;
        int current_cost = 0;
        for(int i = 0; i < 5; i++){
            for(int j = i; j < 4; j+=2){
                current_cost += cost[cur[j]-1][cur[j+1]-1] + cost[cur[j+1]-1][cur[j]-1];
            }
        }
        maxim = max(current_cost, maxim);
        next_permutation(cur.begin(), cur.end());
    }
    cout << maxim << endl;
    return 0;
}

/*B. Shower Line*/
#include <bits/stdc++.h>

using namespace std;

int main(){

	ios_base::sync_with_stdio(0);
	cin.tie(0);

	int matriz[5][5];
	int aux[5][5];

	vector <int> nums(5);

	int valor = 0;
	int maximo = -1;
	int uno = 0, dos = 1, tres = 2, cuatro = 3, cinco = 4;

	for (int i = 0; i < 5; ++i)
		nums[i] = i;

	for (int i = 0; i < 5; ++i){
		for (int j = 0; j < 5; ++j){
			aux[i][j] = 0;

		}
	}

	for (int i = 0; i < 5; ++i){
		for (int j = 0; j < 5; ++j){
			cin >> matriz[i][j];
			aux[i][j]+= matriz[i][j];
			aux[j][i]+= matriz[i][j];
		}
	}

	maximo += aux[uno][dos] + aux[tres][cuatro] + aux[dos][tres];
	maximo += aux[cuatro][cinco] + aux[tres][cuatro] + aux[cuatro][cinco];

	while(next_permutation(nums.begin(), nums.end())){

		uno = nums[0];
		dos = nums[1];
		tres = nums[2];
		cuatro = nums[3];
		cinco = nums[4];
		valor = aux[uno][dos] + aux[tres][cuatro] + aux[dos][tres];
		valor += aux[cuatro][cinco] + aux[tres][cuatro] + aux[cuatro][cinco];

		if(valor > maximo)
			maximo = valor;

	}

	cout << maximo<< '\n';

	return 0;
}

#include <bits/stdc++.h>
#include <stdio.h>
# define M_PI  3.14159265358979323846
using namespace std;

typedef long long ll;
const int N = 1e5, M = 3e5 + 9, OO = 0x3f3f3f3f;
const double EPS = 0.00000000001;
const int mod = 1000000007;

int a[5] = {0,1,2,3,4};
int g[7][7];

int calcHappines(){
	int sum = 0;
	sum += g[a[0]][a[1]] + g[a[1]][a[0]] + g[a[2]][a[3]] + g[a[3]][a[2]];
	sum += g[a[1]][a[2]] + g[a[2]][a[1]] + g[a[3]][a[4]] + g[a[4]][a[3]];
	sum += g[a[2]][a[3]] + g[a[3]][a[2]];
	sum += g[a[3]][a[4]] + g[a[4]][a[3]];
	return sum;
}

int main(){
	//freopen("input.txt", "rt", stdin);
	//freopen("output.txt", "wt", stdout);

	for(int i = 0 ; i < 5 ; ++i)
		for(int j = 0 ; j < 5 ; ++j) scanf("%d", g[i]+j);
	int cnt = 119;
	int mx = 0;
	while(cnt--){
	mx = max(mx, calcHappines());
	next_permutation(a, a+5);
	}
	printf("%d\n", mx);

	return 0;
}

#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define pp pop_back

int main()
{
    int arr[6][6];

    for(int i=1;i<=5;i++)
       for(int j=1;j<=5;j++)
           cin>>arr[i][j];

    int config[5] = {1, 2, 3, 4, 5};
    ll res = 0, curr;
    do{

        curr += (arr[config[0]][config[1]] + arr[config[1]][config[0]]) +
                (arr[config[2]][config[3]] + arr[config[3]][config[2]]) +
                (arr[config[1]][config[2]] + arr[config[2]][config[1]]) +
                (arr[config[3]][config[4]] + arr[config[4]][config[3]]) +
                (arr[config[2]][config[3]] + arr[config[3]][config[2]]) +
                (arr[config[3]][config[4]] + arr[config[4]][config[3]]);

        res = max(res, curr);

    }while(next_permutation(config, config + 5));

    cout<<res;
    return 0;
}

#include <bits/stdc++.h>
#define pb push_back

using namespace std;

int main()
{
	int maxd{-1}, maxs{-1}, a, b, c, happiness;
	vector<vector<int>> hap (6, vector<int> (6));
	vector<vector<int>> ijsum (6, vector<int> (6));
	vector<vector<vector<int>>> triads (6, vector<vector<int>> (6, vector<int> (6)));

	for (int i = 1; i < 6; ++i)
	{
		for (int j = 1; j < 6; ++j)
		{
			cin >> hap[i][j];
		}
	}

	for (int i = 1; i < 6; ++i)
	{
		for (int j = i+1; j < 6; ++j)
		{
			int t = hap[i][j] + hap[j][i];
			ijsum[i][j] = ijsum[j][i] = t;
		}
	}

	for (int common = 1; common < 6; ++common)
	{
		for (int x = 1; x < 6; ++x)
		{
			if(x == common)
				continue;

			for (int y = 1; y < 6; ++y)
			{
				if(y == x || y == common)
					continue;

				int sum = ijsum[x][common] + ijsum[common][y];

				triads[common][x][y] = sum;
				triads[common][y][x] = sum;

				if(sum > maxd)
				{
					maxd = sum;
					a = x;
					b = y;
					c = common;
				}
			}
		}
	}

	for (int i = 1; i < 6; ++i)
	{
		if(i == a || i == b || i == c)
			continue;

		int k = 15 - a - b - c - i;

		//for a as one with i common
		int num = triads[i][a][k];
		if(num > maxs)
			maxs = num;

		num = triads[i][b][k];
		if(num > maxs)
			maxs = num;
	}

	happiness = maxs + (2 * maxd);
	cout << happiness;
	return 0;
}

#include <iostream>
#include <string.h>
using namespace std;

int B[5];
int A[5][5];

int maxhapp(int MAX, int I, int J)
{
	memset(B, 0, sizeof(B));
	int sum = 0, t;
	sum += MAX * 2;
	MAX = 0;
	B[I] = B[J] = 1;
	for (int i = 0; i < 5; i++)
		if (A[J][i] + A[i][J] > MAX && !B[i])
			MAX = A[J][i] + A[i][J], t = i;
	B[t] = 1;
	sum += MAX * 2;
	MAX = 0;
	for (int i = 0; i < 5; i++)
		if (A[I][i] + A[i][I] > MAX && !B[i])
			MAX = A[I][i] + A[i][I], J = i;
	B[J] = 1;
	sum += MAX;
	MAX = 0;
	for (int i = 0; i < 5; i++)
		if (!B[i])
			sum += A[i][J] + A[J][i];
	return sum;
}

int main()
{
	int MAX = 0, x;

	for (int i = 0; i < 5; i++)
		for (int j = 0; j < 5; j++)
			cin >> A[i][j];

	for (int i = 0; i < 5; i++)
		for (int j = 0; j < 5; j++)
			if (i != j)
			{
				x = maxhapp(A[i][j] + A[j][i], i, j);
				if (x > MAX)
					MAX = x;
			}
	cout << MAX;
}

#include <bits/stdc++.h>
using namespace std;

int a[5][5];
int p[] = {0, 1, 2, 3, 4}, res = 0;

int main(){
for(int i = 0; i < 5; i++) for(int j = 0; j < 5; j++) cin >> a[i][j];
do{
int k = 0;
for(int i = 0; i < 5; i++){
for(int j = i; j + 1 < 5; j += 2){
k += a[p[i]][p[i + 1]];
}
}
res = max(res, k);
} while(next_permutation(p, p + 5));
cout << 2 * res;
}

#include <cctype>
#include <string>
#include <cstring>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
#include <utility>
#include <bitset>
#include <limits>

using namespace std;

#define PB(x)       push_back(x)
#define MP(x,y)     make_pair(x,y)
#define ALL(x)      x.begin(), x.end()
#define RALL(x)     x.rbegin(), x.rend()
#define READ(x)     freopen(x, "r", stdin)
#define WRITE(x)    freopen(x, "w", stdout)
#define SORT(x)     sort(ALL(x))
#define DREP(x)     sort(ALL(x)); x.erase(unique(ALL(x)),x.end())
#define CLEAR(c)    memset(c, 0, sizeof(c))
#define P(x)        ">>> " << #x << " : " << x << endl
#define C(x)        cout << P(x)
#define CC(x)       clog << P(x)

struct _ { ios_base::Init i; _() { cin.sync_with_stdio(0); cin.tie(0); } } _;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> ii;
typedef vector<ii> vii;

#define EPS 1e-14
#define INF 0x3f3f3f3f;
#define PI atan(1)*4;

int main() {
  int n;
  string line;

  cin >> n >> line;

  int fr = n+1, lr = 0;
  int leftl = n+1, leftr = 0;
  bool found;

  for(int i = 0; i < n; i++) {
    if (line[i] == 'R') {
      fr = min(fr,i);
      lr = max(lr, i);
    } else if(line[i] == 'L') {
      found = true;
      leftl = min(leftl,i);
      leftr = max(leftr,i);
    }
  }

  if (fr == n+1 && lr == 0) {
    cout << leftr + 1 << " " << leftl << endl;
    return 0;
  }

  if (!found) lr++;

  cout << fr + 1 << " " << lr + 1 << endl;
}

#include<bits/stdc++.h>
using namespace std;

int ar[6][6];
int main(){
     int l[5] = {1,2,3,4,5};
     int res,maxres=0,a,b,c,d,e;
     for(int i = 1; i <= 5; i++){
          for(int j = 1; j <= 5; j++){
               cin >> ar[i][j];
          }
     }
     while (next_permutation(l,l+5))
     {
         //cout << line[0] << line[1] << line[2] << line[3] << line[4]<< endl;
         a = l[0],b = l[1],c = l[2],d = l[3],e = l[4];
         res = ar[a][b]+ar[b][a] + 2*(ar[c][d]+ar[d][c]) + ar[b][c]+ar[c][b] + 2*(ar[d][e]+ar[e][d]);
         //cout << res << endl;
         if(res > maxres){
          maxres = res;
         }
     }
     cout << maxres << endl;
}

#include <bits/stdc++.h>
using namespace std;

int main(){
    int matrix[5][5];
    for(int i=0;i<5;i++){
        for(int j=0;j<5;j++){
            int x;
            cin>>x;
            matrix[i][j]=x;
        }
    }
    int arr[5]={0,1,2,3,4};
    int count=0,perm =INT_MIN;
    do{
        count+=matrix[arr[0]][arr[1]]+matrix[arr[1]][arr[0]];
        count+=matrix[arr[2]][arr[3]]+matrix[arr[3]][arr[2]];

        count+=matrix[arr[1]][arr[2]]+matrix[arr[2]][arr[1]];
        count+=matrix[arr[3]][arr[4]]+matrix[arr[4]][arr[3]];

        count+=matrix[arr[2]][arr[3]]+matrix[arr[3]][arr[2]];

        count+=matrix[arr[3]][arr[4]]+matrix[arr[4]][arr[3]];
        perm =max(count,perm );
    }while(next_permutation(arr,arr+5));

    cout<<perm <<"\n";
    return 0;
}

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <iostream>
#include <vector>
#include <cassert>
#include <sstream>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <algorithm>
#include <utility>
#include <string>

#define pb push_back
#define mp make_pair
#define clr(x) x.clear()
#define sz(x) ((int)(x).size())
#define pii pair<int, int>
#define pn(n) printf("%d\n",n)
#define sn(n) scanf("%d",&n)
#define tr(container , it) for(typeof(container.begin()) it=container.begin() ; it!=container.end() ; it++)

#define FORN(i, n) for(i = 0; i < n; i++)
#define FORAB(i,a,b) for(i = a; i <= b; i++)

typedef long long int li;
using namespace std;

int main(){

	int matrix[5][5];
	for (int i = 0; i < 5; ++i)
	{
		for (int j = 0; j < 5; ++j)
		{
			scanf("%d",&matrix[i][j]);
		}
	}

	int a[5]={0,1,2,3,4};

	int maxhappy=0;
	int happy=0;

	while(next_permutation(a,a+5)){
		happy=matrix[a[0]][a[1]]+matrix[a[1]][a[0]]+matrix[a[1]][a[2]]+matrix[a[2]][a[1]]+2*(matrix[a[2]][a[3]]+matrix[a[3]][a[2]])+2*(matrix[a[3]][a[4]]+matrix[a[4]][a[3]]);
		maxhappy=max(happy,maxhappy);
/*		if(maxhappy==happy){
			printf("max happy is %d\n",maxhappy );
 			for (int i = 0; i < 5; ++i)
 			{
 				printf("%d ", a[i]);
 			}
 			printf("\n");
		}
*/	}
	cout << maxhappy << endl;
	return 0;
}

#include <bits/stdc++.h>`

#define slld(longvalue) scanf("%lld", &longvalue)
#define plld(longvalue) printf("%lld\n", longvalue)

#define slf(longvalue) scanf("%lf", &longvalue)
#define plf(longvalue) printf("%lf\n", longvalue)
#define sc(letter) scanf("%c", &letter)
#define pc(letter) printf("%c", letter)

#define ss(name) scanf("%s", name)
#define ps(name) printf("%s", name)

#define pnew printf("\n")

#define ll long long

#define printcase(indexing,ans) printf("Case %lld: %lld\n", indexing, ans)

#define pb(x) push_back(x)

#define bug printf("BUG\n")

#define mxlld 2e18
#define mnlld -2e18

#define mxd 2e8
#define mnd -2e8

#define pi 3.14159265359

#define mod 1000000009

using namespace std;

ll hp[10][10];
//vector < pair < ll, ll > > v[10];

int main()
{
    ll i, j, k, l, m, n, o;
    ll testcase;
    ll input, flag, tag, ans;

    // freopen("in.txt", "r", stdin);

    //v.clear();

    for(i = 1; i <= 5; i++)
    {
        for(j = 1; j <= 5; j++)
        {
            slld(hp[i][j]);
        }
    }

    ll mx = -1;
    ll pos, x, y;
    for(i = 1; i <= 5; i++)
    {
        for(j = i + 1; j <= 5; j++)
        {
            ans = hp[i][j] + hp[j][i];
            ll temp = -1;
            for(k = 1; k <= 5; k++)
            {
                if(k == i || k == j) continue;

                temp = hp[i][k] + hp[k][i];

                if(ans + temp > mx)
                {
                    pos = k;
                    y = i;
                    x = j;
                    mx = ans + temp;
                }
            }
            for(k = 1; k <= 5; k++)
            {
                if(k == i || k == j) continue;

                temp = hp[j][k] + hp[k][j];

                if(ans + temp > mx)
                {
                    pos = k;
                    y = j;
                    x = i;
                    mx = ans + temp;
                }
            }
        }
    }

    ans = mx * 2;

    bool on[10];

    memset(on,false,sizeof on);

    on[pos] = 1;
    on[x] = 1;
    on[y] = 1;

    mx = -1;
    ll p = 0;

    for(i = 1; i < 6; i++)
    {
        if(on[i]) continue;
        ll temp = hp[i][x] + hp[x][i];
        ll temp2 = hp[i][pos] + hp[pos][i];

        if(temp > mx)
        {
            mx = temp;
            p = i;
        }

        if(temp2 > mx)
        {
            mx = temp2;
            p = i;

            swap(pos,x);
        }
    }

    on[p] = 1;

    ans += mx;

    for(i = 1; i < 6; i++)
    {
        if(on[i]) continue;
        ll temp = hp[i][p] + hp[p][i];

        ans += temp;
        break;

    }

    cout << ans << endl;

}

#include<bits/stdc++.h>
using namespace std;

#define ll long long int
#define pb push_back
#define ull unsigned long long int

int main()
{
    ll a[5][5];
    ll i,j,k,m=0;
    ll b[5]={0,1,2,3,4};
    for(i=0;i<5;i++){
        for(j=0;j<5;j++){
            cin >> a[i][j];
        }
    }
    while (next_permutation(b, b + 5)){
        k=a[b[0]][b[1]]+a[b[1]][b[0]]+2*(a[b[2]][b[3]]+a[b[3]][b[2]])+a[b[2]][b[1]]+a[b[1]][b[2]]+2*(a[b[4]][b[3]]+a[b[3]][b[4]]);
        m=max(k,m);
    }
       cout <<m;
}

#include <bits/stdc++.h>
#define mod 1000003
#define ll long long
#define mp make_pair
#define pb push_back
#define endl '\n'
#define pi 3.1415926536
using namespace std;
ll powermod(ll _a,ll _b,ll _m){ll _r=1;while(_b){if(_b%2==1)_r=(_r*_a)%_m;_b/=2;_a=(_a*_a)%_m;}return _r;}
ll string_to_number(string s){ll x=0; stringstream convert(s); convert>>x; return x;}
ll add(ll a,ll b){ll x = (a+b)%mod; return x; }
ll mul(ll a,ll b){ll x = (a*b)%mod; return x; }
ll sub(ll a,ll b){ll x = (a-b+mod)%mod; return x; }
ll divi(ll a,ll b){ll x = a;ll y = powermod(b,mod-2,mod);ll res = (x*y)%mod;return res;}

bool primes[100001]={0};
int arr[100001]={0};
int flag[100001]={0};
vector<int>v;
void prime(){

    primes[0]=1;
    primes[1]=1;
    for(int i=2;i<=100000;i++){
        if(!primes[i]){
            for(int j=i*2;j<=100000;j+=i){
                primes[j]=1;
            }
        }
    }
}

double fac(int n){
    if(n<=1)
        return 1.0;
    else
        return n * (fac(n-1));
}

void divisors(int n){

    for(int i=1;i<=sqrt(n);i++){

        if(n%i==0){
          if(n%i==i)v.pb(i);
            else{
                v.pb(i);
                v.pb(n/i);
            }
        }
    }
}

bool check(ll n){
    int a=0,b=0;
    int cnt=0;
    while(n){
        int temp=n%10;
        if(temp==4)a++;
        else if(temp==7)b++;
        n/=10;
        cnt++;
    }

    if(a==b && (a+b)==cnt)return true;
    else return false;

}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    ll arr[5][5];
    for(int i=0;i<5;i++)
        for(int j=0;j<5;j++)
            cin>>arr[i][j];

    string s="12345";
    ll ans=(2*(arr[4][5]+arr[5][4]))+(2*(arr[3][4]+arr[4][3]))+arr[1][2]+arr[2][1]+arr[2][3]+arr[3][2];
    ll a,b,c,d,e,x;
    while(next_permutation(s.begin(),s.end())){

        a=s[0]-'0';
        b=s[1]-'0';
        c=s[2]-'0';
        d=s[3]-'0';
        e=s[4]-'0';

        x=(2*(arr[d-1][e-1]+arr[e-1][d-1]))+(2*(arr[c-1][d-1]+arr[d-1][c-1]))+arr[a-1][b-1]+arr[b-1][a-1]+arr[b-1][c-1]+arr[c-1][b-1];

        ans=max(ans,x);
    }

    cout<<ans;

    return 0;
}