// Solución del grupo El Peluca Sabe!!

/* Primero fijamos ciertos criterios:
    - En el hexágono los triángulos tendrán su lado 'c' como lado exterior
    - Los triángulos compartirán su lado 'a' con el lado 'b' del vecino
    - Los triángulos compartirán su lado 'b' con el lado 'a' del vecino

Las soluciones las calculamos con un backtracking.
Primero tomamos un triángulo y probamos las soluciones.
Después rotamos ese triángulo y probamos de nuevo las soluciones.
Rotamos por última vez y probamos de nuevo.

Después de esos 3 backs queda el perímetro máximo en una variable...*/

#include <iostream>
#include <set>
#include <list>
using namespace std;

#define in cin
//#include <fstream>
//ifstream in("2061.txt");

struct triang {
    int a, b, c;
};

bool operator < (const triang& t1, const triang& t2) {      // OPERADOR PARA METERLOS EN UN SET
    if (t1.a < t2.a)
        return true;
    else if (t1.a == t2.a) {
        if (t1.b < t2.b)
            return true;
        else if (t1.b == t2.b && t1.c < t2.c)
            return true;
    }
    return false;
}

int perimSol;           // PERÍMETRO MÁXIMO
set<triang> faltan;     // TRIÁNGULOS QUE FALTAN PROBAR
list<triang> listos;    // TRIÁNGULOS QUE FORMAN PARTE DEL HEXÁGONO

int perimetro() {
    int perim = 0;
    for (list<triang>::iterator i = listos.begin(); i != listos.end(); i++)
        perim += i->c;
    return perim;
}

void rotarIzq(triang& t) {
    int temp = t.a;
    t.a = t.b;
    t.b = t.c;
    t.c = temp;
}

void rotarDer(triang& t) {
    int temp = t.c;
    t.c = t.b;
    t.b = t.a;
    t.a = temp;
}

void back() {
    if (faltan.empty()) {
        if (listos.front().a == listos.back().b)        // SI LLEGAMOS A UNA SOLUCION
            perimSol = max(perimSol, perimetro());      // NOS QUEDAMOS CON EL PERIMETRO MAX
    } else {
        triang ult = listos.back(), t;
        set<triang> itFaltan = faltan;      // CREAMOS ESTE CONJUNTO PARA ITERAR SOBRE FALTAN
                                            // SIN TENER PROBLEMAS AL ELIMINAR TRIANGULOS
        for (set<triang>::iterator it = itFaltan.begin(); it != itFaltan.end(); it++) {
            if (faltan.find(*it) != faltan.end()) {     // SI AÚN ESTÁ EN FALTAN
                t = *it;
                faltan.erase(t);
                if (ult.b == t.a) {             // SI SE PUEDE COLOCAR...
                    listos.push_back(t);
                    back();
                    listos.pop_back();
                } else if (ult.b == t.b) {      // SI NO, LO ROTAMOS
                    rotarIzq(t);
                    listos.push_back(t);
                    back();
                    listos.pop_back();
                    rotarDer(t);
                } else if (ult.b == t.c) {      // SI NO, LO ROTAMOS PAL OTRO LADO
                    rotarDer(t);
                    listos.push_back(t);
                    back();
                    listos.pop_back();
                    rotarIzq(t);
                }
                faltan.insert(t);
            }
        }
    }
}

int main() {
    int a,b,c;
    char opc;
    triang t;

    do {
        listos.clear();             // INICIALIZAMOS ESTRUCTURAS Y VARIABLES
        faltan.clear();
        perimSol = 0;

        for (int i = 0; i < 6; i++) {   // TOMAMOS LOS DATOS DE UN SET
            in >> a >> b >> c;
            t.a=a; t.b=b; t.c=c;
            faltan.insert(t);
        }

        in >> opc;

        t = *(faltan.begin());      // TOMAMOS UN TRIANGULO
        faltan.erase(t);

        listos.push_back(t);        // EMPIEZAMOS EL BACKTRACKING
        back();
        listos.pop_back();

        rotarIzq(t);      // ROTAMOS EL TRIANG
        listos.push_back(t);
        back();
        listos.pop_back();

        rotarIzq(t);      // ROTAMOS DE NUEVO
        listos.push_back(t);
        back();
        listos.pop_back();

        if (perimSol > 0)
            cout << perimSol << endl;
        else
            cout << "none" << endl;

    } while (opc != '$');

    //getchar();
}

