#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e6 + 7;
const int inf = 1e9;
const long long MOD = 1e9 + 7;
const long long p = 1e9 + 6;
long long quick_pow(long long x, long long y) {
  long long base = x % MOD;
  long long res = 1;
  while (y) {
    if (y & 1) res = (res * base) % MOD;
    base = base * base % MOD;
    y >>= 1;
  }
  return res % MOD;
}
struct node {
  long long a[10][10];
};
int num;
node operator*(node x, node y) {
  node tmp;
  for (int i = 1; i <= num; i++)
    for (int j = 1; j <= num; j++) {
      tmp.a[i][j] = 0;
      for (int k = 1; k <= num; k++) {
        tmp.a[i][j] = tmp.a[i][j] + x.a[i][k] * y.a[k][j] % p;
        tmp.a[i][j] %= p;
      }
    }
  return tmp;
}
node operator^(node x, long long b) {
  node tmp;
  memset(tmp.a, 0, sizeof(tmp.a));
  for (int i = 1; i <= num; i++) tmp.a[i][i] = 1;
  while (b > 0) {
    if (b & 1) tmp = tmp * x;
    x = x * x;
    b >>= 1;
  }
  return tmp;
}
long long xi_c(long long n) {
  node aa, bb;
  num = 6;
  memset(bb.a, 0, sizeof(bb.a));
  memset(aa.a, 0, sizeof(aa.a));
  aa.a[1][1] = 14;
  aa.a[1][2] = 6;
  aa.a[1][3] = 2;
  aa.a[1][4] = 4;
  aa.a[1][5] = 5;
  aa.a[1][6] = -1;
  if (n <= 6) return n == 6 ? aa.a[1][1] : (n == 5 ? aa.a[1][2] : aa.a[1][3]);
  bb.a[1][1] = bb.a[2][1] = bb.a[3][1] = bb.a[4][1] = bb.a[5][1] = bb.a[6][1] =
      1;
  bb.a[1][2] = bb.a[2][3] = bb.a[4][4] = bb.a[5][5] = bb.a[6][6] = 1;
  bb.a[6][4] = bb.a[6][5] = -1;
  bb = aa * (bb ^ (n - 6));
  return bb.a[1][1];
}
long long n, f1, f2, f3, c, ans_c, ans;
int main() {
  scanf("%lld %lld %lld %lld %lld", &n, &f1, &f2, &f3, &c);
  {
    num = 3;
    node aa;
    aa.a[1][1] = 1, aa.a[1][2] = 2, aa.a[1][3] = 4;
    aa.a[2][1] = 1, aa.a[2][2] = 2, aa.a[2][3] = 3;
    aa.a[3][1] = 1, aa.a[3][2] = 1, aa.a[3][3] = 2;
    long long F1, F2, F3;
    if (n > 6) {
      node bb;
      bb.a[1][1] = 0, bb.a[1][2] = 0, bb.a[1][3] = 1;
      bb.a[2][1] = 1, bb.a[2][2] = 0, bb.a[2][3] = 1;
      bb.a[3][1] = 0, bb.a[3][2] = 1, bb.a[3][3] = 1;
      aa = aa * (bb ^ (n - 6));
      F1 = quick_pow(f1, aa.a[3][3]);
      F2 = quick_pow(f2, aa.a[2][3]);
      F3 = quick_pow(f3, aa.a[1][3]);
    } else {
      F1 = quick_pow(f1, aa.a[3][n - 3]);
      F2 = quick_pow(f2, aa.a[2][n - 3]);
      F3 = quick_pow(f3, aa.a[1][n - 3]);
    };
    ans = F1 * F2 % MOD * F3 % MOD * quick_pow(c % MOD, xi_c(n)) % MOD;
    printf("%lld\n", ans);
  }
  return 0;
}
