#include <array>
#include <climits>
#include <cstdio>
#include <iostream>
#include <vector>
using namespace std;

// 64 位输出请用 printf("%lld")
class Mofang {
  private:
    array<int, 24> walls;
    array<array<int, 12>, 8> turns = {
        {   {0, 1, 3, 2, 22, 23, 9, 8, 7, 6, 5, 4},
            {6, 7, 13, 12, 2, 3, 8, 14, 17, 16, 11, 5},
            {4, 5, 11, 10, 6, 12, 16, 18, 20, 22, 0, 2},
            {8, 9, 15, 14, 23, 21, 19, 17, 13, 7, 3, 1},
            {16, 17, 19, 18, 10, 11, 12, 13, 14, 15, 21, 20},
            {20, 21, 23, 22, 18, 19, 15, 9, 1, 0, 4, 10}
        }
    };

  public:
    void set_walls(const vector<int>& vec) {
        if (vec.size() < 24)
            return;
        for (int i = 0; i < 24; i++) {
            walls[i] = vec[i];
        }
    }
    void getWalls() {
        for (int i = 0; i < 24; i++) {
            cin >> walls[i];
        }
    }
    void move_turn_plus(int wall_index, int s_index, int len, int step = 1) {
        wall_index %= 6;
        vector<int> tmps(step);
        for (int i = 0; i < step; i++) {
            tmps[i] = walls[turns[wall_index][s_index + i]];
        }
        /* int tmp = walls[turns[wall_index][s_index]]; */
        for (int i = s_index; i < s_index + len - step; i++) {
            walls[turns[wall_index][i]] = walls[turns[wall_index][i + step]];
        }
        for (int i = 0; i < step; i++) {
            walls[turns[wall_index][s_index + len - step + i]] = tmps[i];
        }
        /* walls[turns[wall_index][s_index + len - 1]] = tmp; */
    }
    void move_turn_minus(int wall_index, int s_index, int len, int step = 1) {
        wall_index %= 6;
        vector<int> tmps(step);
        /* int tmp = walls[turns[wall_index][s_index + len - 1]]; */
        for (int i = 0; i < step; i++) {
            tmps[i] = walls[turns[wall_index][s_index + len - step + i]];
        }
        for (int i = s_index + len - 1; i >= s_index + step; i--) {
            walls[turns[wall_index][i]] = walls[turns[wall_index][i - step]];
        }
        for (int i = 0; i < step; i++) {
            walls[turns[wall_index][s_index + i]] = tmps[i];
        }
        /* walls[turns[wall_index][s_index]] = tmp; */
    }
    void turn_1(int wall_index) {
        move_turn_plus(wall_index, 0, 4);
        move_turn_plus(wall_index, 4, 8, 2);
    }

    void turn_2(int wall_index) {
        move_turn_minus(wall_index, 0, 4);
        move_turn_minus(wall_index, 4, 8, 2);
    }
    auto get_sum_beauty_degree() -> int {
        int sum = 0;
        int ji = 1;
        for (int i = 0; i < 6; i++) {
            ji = 1;
            for (int j = 0; j < 4; j++) {
                ji = ji * walls[turns[i][j]];
            }
            sum += ji;
        }
        return sum;
    }
    auto get_elem(int index) -> int {
        if (index < 0 || index > 23)
            return -1;
        return walls[index];
    }
    void print() {
        printf("\n\n");
        printf("\t\t%4d %4d\t\t\n", walls[0], walls[1]);
        printf("\t\t%4d %4d\t\t\n", walls[2], walls[3]);
        printf("\t%4d %4d %4d %4d %4d %4d\n", walls[4], walls[5], walls[6],
               walls[7], walls[8], walls[9]);
        printf("\t%4d %4d %4d %4d %4d %4d\n", walls[10], walls[11], walls[12],
               walls[13], walls[14], walls[15]);
        printf("\t\t%4d %4d \t\t\n", walls[16], walls[17]);
        printf("\t\t%4d %4d \t\t\n", walls[18], walls[19]);
        printf("\t\t%4d %4d \t\t\n", walls[20], walls[21]);
        printf("\t\t%4d %4d \t\t\n", walls[22], walls[23]);
        printf("\n\n");
    }
};
void df(Mofang& mf, int& _max, int times) {
    if (times == 5) {
        return;
    }
    for (int i = 0; i < 6; i++) {
        mf.turn_1(i);
        _max = max(mf.get_sum_beauty_degree(), _max);
        df(mf, _max, times + 1);
        mf.turn_2(i);

        mf.turn_2(i);
        _max = max(mf.get_sum_beauty_degree(), _max);
        df(mf, _max, times + 1);
        mf.turn_1(i);
    }
}
void test_mf() {
    Mofang mf;
    vector<int> vec = {0,  1,  2,  3,  4,  5,  6,  7,  8,  9,  10, 11,
                       12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23
                      };
    mf.set_walls(vec);
    for (int i = 0; i < 6; i++) {
        for (int j = 0; j < 4; j++) {
            mf.turn_1(i);
        }
        for (int k = 0; k < 23; k++) {
            if (mf.get_elem(k) != vec[k]) {
                printf("false %d\n", i);
            }
        }
    }
    for (int i = 0; i < 6; i++) {
        for (int j = 0; j < 4; j++) {
            mf.turn_2(i);
        }
        for (int k = 0; k < 23; k++) {
            if (mf.get_elem(k) != vec[k]) {
                printf("false %d\n", i);
            }
        }
    }
    printf("All right\n");
}
auto main() -> int {
    Mofang mf;
    mf.getWalls();
    int res = INT_MIN;
    df(mf, res, 0);
    cout << res;
    // test_mf();
    return 0;
}