import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import java.util.Queue;

public class Euler679 {
    static final int ALPHA = 4;

    static int charId(char ch) {
        switch (ch) {
            case 'A':
                return 0;
            case 'E':
                return 1;
            case 'F':
                return 2;
            default:
                return 3;
        }
    }

    static class Node {
        int[] next = new int[ALPHA];
        int link = 0;
        int[] out = new int[4];

        Node() {
            for (int i = 0; i < ALPHA; ++i)
                next[i] = -1;
        }
    }

    static int encodeCounts(int a, int b, int c, int d) {
        return ((a * 3 + b) * 3 + c) * 3 + d;
    }

    public static String solve() {
        int n = 30;
        List<Node> nodes = new ArrayList<>();
        nodes.add(new Node());

        String[] patterns = { "FREE", "FARE", "AREA", "REEF" };
        for (int i = 0; i < patterns.length; ++i) {
            String s = patterns[i];
            int v = 0;
            for (char ch : s.toCharArray()) {
                int c = charId(ch);
                if (nodes.get(v).next[c] == -1) {
                    nodes.get(v).next[c] = nodes.size();
                    nodes.add(new Node());
                }
                v = nodes.get(v).next[c];
            }
            nodes.get(v).out[i] += 1;
        }

        Queue<Integer> q = new LinkedList<>();
        for (int c = 0; c < ALPHA; ++c) {
            int to = nodes.get(0).next[c];
            if (to == -1) {
                nodes.get(0).next[c] = 0;
            } else {
                nodes.get(to).link = 0;
                q.add(to);
            }
        }

        while (!q.isEmpty()) {
            int v = q.poll();
            int lk = nodes.get(v).link;
            for (int k = 0; k < 4; ++k) {
                nodes.get(v).out[k] += nodes.get(lk).out[k];
            }

            for (int c = 0; c < ALPHA; ++c) {
                int to = nodes.get(v).next[c];
                if (to == -1) {
                    nodes.get(v).next[c] = nodes.get(lk).next[c];
                } else {
                    nodes.get(to).link = nodes.get(lk).next[c];
                    q.add(to);
                }
            }
        }

        int states = nodes.size();
        int CNT = 81;

        long[] dp = new long[states * CNT];
        dp[0] = 1L;

        for (int pos = 0; pos < n; ++pos) {
            long[] next = new long[states * CNT];
            for (int st = 0; st < states; ++st) {
                for (int code = 0; code < CNT; ++code) {
                    long ways = dp[st * CNT + code];
                    if (ways == 0L)
                        continue;

                    int t = code;
                    int c3 = t % 3;
                    t /= 3;
                    int c2 = t % 3;
                    t /= 3;
                    int c1 = t % 3;
                    t /= 3;
                    int c0 = t;

                    for (int ch = 0; ch < ALPHA; ++ch) {
                        int ns = nodes.get(st).next[ch];
                        int[] add = nodes.get(ns).out;

                        int n0 = (c0 + add[0] >= 2) ? 2 : (c0 + add[0]);
                        int n1 = (c1 + add[1] >= 2) ? 2 : (c1 + add[1]);
                        int n2 = (c2 + add[2] >= 2) ? 2 : (c2 + add[2]);
                        int n3 = (c3 + add[3] >= 2) ? 2 : (c3 + add[3]);

                        if (n0 == 2 || n1 == 2 || n2 == 2 || n3 == 2)
                            continue;

                        int ncode = encodeCounts(n0, n1, n2, n3);
                        next[ns * CNT + ncode] += ways;
                    }
                }
            }
            dp = next;
        }

        int target = encodeCounts(1, 1, 1, 1);
        long ans = 0L;
        for (int st = 0; st < states; ++st) {
            ans += dp[st * CNT + target];
        }

        return Long.toString(ans);
    }

    public static void main(String[] args) {
        System.out.println(solve());
    }
}
