// Maximum-TNT #include #include #include #include #include #include #include #include #include #define cin fin using namespace std; ifstream fin("triangle.txt"); const int BUFSIZE = 1024; int g_triangle[6][3]; int g_ans; int Count() { int total = 0; for(int i=0;i<6;i++) { // for(int j=0;j<3;j++) // { // cout << g_triangle[i][j] << " "; // } // cout << endl; total += g_triangle[i][2]; } // cout << endl; return total; } void Solve(int depth, bool flg[], int path[]) { if(depth == 6) { if(g_triangle[path[0]][1] == g_triangle[path[5]][0]) g_ans = max(Count(), g_ans); return; } for(int i=0;i<6;i++) { if(!flg[i]) { flg[i] = true; path[depth] = i; for(int j=0;j<3;j++) { if(depth > 0) { if(g_triangle[i][1] == g_triangle[path[depth-1]][0]) Solve(depth+1, flg, path); } else Solve(depth+1, flg, path); rotate(g_triangle[i], g_triangle[i]+1, g_triangle[i] + 3); } flg[i] = false; } } } int main() { char c; bool flg[6]; int path[6]; do { fill_n(flg, 6, false); g_ans = -1; for(int i=0;i<6;i++) { for(int j=0;j<3;j++) { cin >> g_triangle[i][j]; } } Solve(0, flg, path); if(g_ans == -1) cout << "none" << endl; else cout << g_ans << endl; }while(cin >> c, c != '$'); return 0; }