import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Locale;

public class Euler982 {

    static final double EPS = 1e-10;

    static class Simplex {
        int m, n;
        double[][] T;
        int[] basis;

        Simplex(int rows, int cols) {
            m = rows;
            n = cols;
            T = new double[m + 1][n + 1];
            basis = new int[m];
            Arrays.fill(basis, -1);
        }

        void pivot(int r, int c) {
            double inv = 1.0 / T[r][c];
            for (int j = 0; j <= n; ++j)
                T[r][j] *= inv;
            for (int i = 0; i <= m; ++i) {
                if (i == r)
                    continue;
                double factor = T[i][c];
                if (Math.abs(factor) <= EPS)
                    continue;
                for (int j = 0; j <= n; ++j)
                    T[i][j] -= factor * T[r][j];
            }
            basis[r] = c;
        }

        void setObjective(double[] cObj) {
            Arrays.fill(T[m], 0.0);
            for (int j = 0; j < n; ++j)
                T[m][j] = -cObj[j];
            T[m][n] = 0.0;
            for (int i = 0; i < m; ++i) {
                int var = basis[i];
                if (var < 0)
                    continue;
                double coeff = cObj[var];
                if (Math.abs(coeff) <= EPS)
                    continue;
                for (int j = 0; j <= n; ++j)
                    T[m][j] += coeff * T[i][j];
            }
        }

        boolean solve() {
            while (true) {
                int enter = -1;
                for (int j = 0; j < n; ++j) {
                    if (T[m][j] < -EPS) {
                        enter = j;
                        break;
                    }
                }
                if (enter == -1)
                    return true;

                double minRatio = 0.0;
                int leave = -1;
                for (int i = 0; i < m; ++i) {
                    double a = T[i][enter];
                    if (a > EPS) {
                        double ratio = T[i][n] / a;
                        if (leave == -1 || ratio < minRatio - 1e-12 ||
                                (Math.abs(ratio - minRatio) <= 1e-12 && basis[i] < basis[leave])) {
                            minRatio = ratio;
                            leave = i;
                        }
                    }
                }
                if (leave == -1)
                    return false;
                pivot(leave, enter);
            }
        }

        double objectiveValue() {
            return T[m][n];
        }
    }

    static class GameData {
        int dice, actions, states, obs;
        double prob;
        int[] visibleMax, actionObs, actionHidden;
    }

    static GameData buildGame(int dice) {
        GameData g = new GameData();
        g.dice = dice;
        g.actions = dice;
        if (dice == 2) {
            g.states = 36;
            g.obs = 6;
            g.prob = 1.0 / 36.0;
            g.visibleMax = new int[g.obs];
            for (int v = 0; v < g.obs; ++v)
                g.visibleMax[v] = v + 1;

            int nAction = g.states * g.actions;
            g.actionObs = new int[nAction];
            g.actionHidden = new int[nAction];

            for (int a = 1; a <= 6; ++a) {
                for (int b = 1; b <= 6; ++b) {
                    int s = (a - 1) * 6 + (b - 1);
                    int base = s * 2;
                    g.actionObs[base] = b - 1;
                    g.actionHidden[base] = a;
                    g.actionObs[base + 1] = a - 1;
                    g.actionHidden[base + 1] = b;
                }
            }
            return g;
        }
        if (dice == 3) {
            g.states = 216;
            g.obs = 21;
            g.prob = 1.0 / 216.0;

            int[][] obsIndex = new int[7][7];
            for (int i = 0; i <= 6; ++i)
                Arrays.fill(obsIndex[i], -1);

            g.visibleMax = new int[g.obs];
            int idx = 0;
            for (int u = 1; u <= 6; ++u) {
                for (int v = u; v <= 6; ++v) {
                    obsIndex[u][v] = idx;
                    obsIndex[v][u] = idx;
                    g.visibleMax[idx] = v;
                    idx++;
                }
            }

            int nAction = g.states * g.actions;
            g.actionObs = new int[nAction];
            g.actionHidden = new int[nAction];

            for (int a = 1; a <= 6; ++a) {
                for (int b = 1; b <= 6; ++b) {
                    for (int c = 1; c <= 6; ++c) {
                        int s = ((a - 1) * 6 + (b - 1)) * 6 + (c - 1);
                        int base = s * 3;
                        g.actionObs[base] = obsIndex[b][c];
                        g.actionHidden[base] = a;
                        g.actionObs[base + 1] = obsIndex[a][c];
                        g.actionHidden[base + 1] = b;
                        g.actionObs[base + 2] = obsIndex[a][b];
                        g.actionHidden[base + 2] = c;
                    }
                }
            }
            return g;
        }
        return g;
    }

    static class LPData {
        Simplex lp;
        int nAction, nT, nSlack, nArt, artStart, slackStart;

        LPData(int rows, int cols, int actions, int tvars, int slack, int art, int artS, int slackS) {
            lp = new Simplex(rows, cols);
            nAction = actions;
            nT = tvars;
            nSlack = slack;
            nArt = art;
            artStart = artS;
            slackStart = slackS;
        }
    }

    static LPData buildLP(GameData g) {
        int nAction = g.states * g.actions;
        int nT = g.obs;
        int nOrig = nAction + nT;
        int nSlack = g.obs * 2;
        int nArt = g.states;
        int nTotal = nOrig + nSlack + nArt;
        int rows = g.states + nSlack;

        int slackStart = nOrig;
        int artStart = nOrig + nSlack;

        LPData data = new LPData(rows, nTotal, nAction, nT, nSlack, nArt, artStart, slackStart);
        Simplex lp = data.lp;

        for (int s = 0; s < g.states; ++s) {
            int row = s;
            int base = s * g.actions;
            for (int a = 0; a < g.actions; ++a)
                lp.T[row][base + a] = 1.0;
            lp.T[row][artStart + s] = 1.0;
            lp.T[row][nTotal] = 1.0;
            lp.basis[row] = artStart + s;
        }

        for (int o = 0; o < g.obs; ++o) {
            for (int t = 0; t < 2; ++t) {
                int row = g.states + o * 2 + t;
                int tvar = nAction + o;
                lp.T[row][tvar] = -1.0;
                lp.T[row][slackStart + o * 2 + t] = 1.0;
                lp.T[row][nTotal] = 0.0;
                lp.basis[row] = slackStart + o * 2 + t;
            }
        }

        for (int idx = 0; idx < nAction; ++idx) {
            int obs = g.actionObs[idx];
            int hidden = g.actionHidden[idx];
            int rowHidden = g.states + obs * 2;
            int rowVisible = rowHidden + 1;
            lp.T[rowHidden][idx] += g.prob * hidden;
            lp.T[rowVisible][idx] += g.prob * g.visibleMax[obs];
        }

        return data;
    }

    static void removeArtificial(Simplex lp, int artStart, int artCount) {
        if (artCount == 0)
            return;
        List<Integer> rowsToRemove = new ArrayList<>();
        boolean[] isArt = new boolean[lp.n];
        for (int i = 0; i < artCount; ++i)
            isArt[artStart + i] = true;

        for (int i = 0; i < lp.m; ++i) {
            int var = lp.basis[i];
            if (var < 0 || !isArt[var])
                continue;
            int pivotCol = -1;
            for (int j = 0; j < lp.n; ++j) {
                if (isArt[j])
                    continue;
                if (Math.abs(lp.T[i][j]) > EPS) {
                    pivotCol = j;
                    break;
                }
            }
            if (pivotCol != -1) {
                lp.pivot(i, pivotCol);
            } else {
                rowsToRemove.add(i);
            }
        }

        if (!rowsToRemove.isEmpty()) {
            boolean[] drop = new boolean[lp.m];
            for (int r : rowsToRemove)
                drop[r] = true;
            int newM = lp.m - rowsToRemove.size();
            double[][] newT = new double[newM + 1][lp.n + 1];
            int[] newBasis = new int[newM];
            int r2 = 0;
            for (int i = 0; i < lp.m; ++i) {
                if (drop[i])
                    continue;
                System.arraycopy(lp.T[i], 0, newT[r2], 0, lp.n + 1);
                newBasis[r2] = lp.basis[i];
                r2++;
            }
            System.arraycopy(lp.T[lp.m], 0, newT[newM], 0, lp.n + 1);
            lp.T = newT;
            lp.basis = newBasis;
            lp.m = newM;
        }

        int newN = lp.n - artCount;
        double[][] newT = new double[lp.m + 1][newN + 1];
        for (int i = 0; i <= lp.m; ++i) {
            int colNew = 0;
            for (int j = 0; j < lp.n; ++j) {
                if (isArt[j])
                    continue;
                newT[i][colNew++] = lp.T[i][j];
            }
            newT[i][newN] = lp.T[i][lp.n];
        }
        lp.n = newN;
        lp.T = newT;
    }

    static double solveGame(int dice) {
        GameData g = buildGame(dice);
        if (g.states == 0)
            return Double.NaN;

        LPData data = buildLP(g);
        Simplex lp = data.lp;

        double[] c1 = new double[lp.n];
        for (int i = 0; i < data.nArt; ++i)
            c1[data.artStart + i] = -1.0;
        lp.setObjective(c1);

        if (!lp.solve())
            return Double.NaN;

        double phase1 = lp.objectiveValue();
        if (phase1 < -1e-8)
            return Double.NaN;

        removeArtificial(lp, data.artStart, data.nArt);

        double[] c2 = new double[lp.n];
        for (int i = 0; i < data.nT; ++i)
            c2[data.nAction + i] = -1.0;
        lp.setObjective(c2);

        if (!lp.solve())
            return Double.NaN;

        return -lp.objectiveValue();
    }

    public static String solve() {
        double res = solveGame(3);
        return String.format(Locale.US, "%.6f", res);
    }

    public static void main(String[] args) {
        double expected = 145.0 / 36.0;
        double got = solveGame(2);
        if (Math.abs(got - expected) > 1e-7) {
            System.err.println("Validation failed");
            return;
        }
        System.out.println(solve());
    }
}
