#include using namespace std; #define rep(i,n) for (int i=0;i<(int)(n);i++) #define all(v) v.begin(),v.end() using ll=long long; using pll=pair; using tll=tuple; const ll INF=(1ll<<60); template void chmin(T &a,T b){ if(a>b){ a=b; } } template void chmax(T &a,T b){ if(a>> dp(6,vector>(6,vector(6,0))); int t=35; vector cell(6,0); while(t--){ vector cnt(6,0); rep(i,6){ int d; cin >> d; d--; cnt[d]++; } int max_score=0,pi=0,pj=0; rep(i,6){ rep(j,6){ bool t=false; rep(k,6) if(dp[i][j][k]!=0) t=true; if(t) continue; rep(k,6){ dp[i][j][k]=cnt[k]; } int score=0; rep(ii,6){ rep(k,6){ int sum=0; rep(jj,6){ sum+=dp[ii][jj][k]; } score+=sum*sum; } } rep(jj,6){ rep(k,6){ int sum=0; rep(ii,6){ sum+=dp[ii][jj][k]; } score+=sum*sum; } } if(max_score