// horizon #include #include #include #include #include using namespace std; int num[6][3]; vector pos(6); int th[6]; int val(int a, int b){ return num[pos[a]][(b+th[a]) % 3]; } int test(int a){ int x = val(a-1, 2); int r = 0; for(int i=0; i<3; i++){ if(num[pos[a]][i] == x){ th[a] = i; if(a == 5){ r = val(a,1); }else{ int y = test(a+1); if(y > r){ r = y + val(a,1); } } } } return r; } int test(){ int x = test(1); if(x > 0){ if(val(0,0) == val(5,2)){ return x + val(0,1); }else{ return 0; } }else{ return 0; } } int main(){ ifstream cin("triangle.txt"); while(true){ for(int i=0; i<6; i++){ for(int j=0; j<3; j++){ cin >> num[i][j]; } pos[i] = i; } int maxval = 0; while(next_permutation(pos.begin(), pos.end())){ for(th[0] = 0; th[0] < 3; th[0]++){ int x = test(); if(x > maxval){ maxval = x; } } } if(maxval > 0){ cout << maxval << endl; }else{ cout << "none" << endl; } string s; cin >> ws >> s; // cout << s << endl; if(s == "$"){ break; } } return 0; }