#include <bits/stdc++.h>   #pragma GCC optimize( Ofast,no-stack-protector )   #pragma GCC target(         sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native )   const int maxn = 2e5 + 5;   const int minn = 65;   const long long mod = 1e9 + 7;   const long long mod1 = 998244353;   const long double pi = acos(-1.);   class Matrix {    public:     int n, m;     std::vector<std::vector<long long>> mat;     Matrix(int n, int m)         : n(n),           m(m),           mat(std::vector<std::vector<long long>>(               n, std::vector<long long>(m, 0ll))) {}     Matrix(std::vector<std::vector<long long>> mat)         : mat(mat), n(mat.size()), m(mat[0].size()) {}     Matrix operator*(Matrix& other) {       if (this->m != other.n) {         printf( Wrong size: %d*%d X %d*%d n , this->n, this->m, other.n, other.m);         throw  Wrong size ;       }       Matrix answ = Matrix(this->n, other.m);       for (int i = 0; i < answ.n; i++) {         for (int j = 0; j < answ.m; j++) {           for (int k = 0; k < this->m; k++) {             answ.mat[i][j] += this->mat[i][k] * other.mat[k][j];             answ.mat[i][j] %= (mod - 1ll);           }         }       }       return answ;     }     Matrix& operator*=(Matrix& other) {       if (this->m != other.n) {         printf( Wrong size: %d*%d X %d*%d n , this->n, this->m, other.n, other.m);         throw  Wrong size ;       }       Matrix answ = Matrix(this->n, other.m);       for (int i = 0; i < answ.n; i++) {         for (int j = 0; j < answ.m; j++) {           for (int k = 0; k < this->m; k++) {             answ.mat[i][j] += this->mat[i][k] * other.mat[k][j];             answ.mat[i][j] %= (mod - 1ll);           }         }       }       (*this) = answ;       return (*this);     }     Matrix operator^(long long x) {       if (x == 0) {         printf( Not implemented yet. n );         throw  Not implemented ;       } else if (x == 1)         return *this;       else {         Matrix y = (*this) ^ (x / 2ll);         if (x % 2ll == 0) {           return y * y;         } else {           return y * y * (*this);         }       }     }     Matrix& operator^=(long long x) {       if (x == 0) {         printf( Not implemented yet. n );         throw  Not implemented ;       } else if (x == 1)         return *this;       else {         Matrix y = (*this) ^ (x / 2ll);         if (x % 2ll == 0) {           *this = y * y;           return *this;         } else {           *this = y * y * (*this);           return (*this);         }       }     }     Matrix operator%(long long xmod) {       if (xmod == 0) {         printf( Can t divide by 0 );         throw  Can t divide by 0 ;       }       Matrix answ(this->n, this->m);       for (int i = 0; i < answ.n; i++) {         for (int j = 0; j < answ.m; j++) {           answ.mat[i][j] = this->mat[i][j] % xmod;         }       }       return answ;     }     Matrix& operator%=(long long xmod) {       if (xmod == 0) {         printf( Can t divide by 0 );         throw  Can t divide by 0 ;       }       for (int i = 0; i < this->n; i++) {         for (int j = 0; j < this->m; j++) {           this->mat[i][j] %= xmod;         }       }     }   };   std::vector<long long> prime;   int pr[maxn];   void precalc() {     for (int i = 2; i < maxn; i++) {       if (!pr[i]) {         prime.push_back((long long)i);         for (int j = i * i; j < maxn; j += i) {           pr[i] = 1;         }       }     }   }   std::map<long long, int> PrimeDecomposition(long long x) {     std::map<long long, int> answ;     for (long long y : prime) {       if (x <= 1) break;       int cnt = 0;       while (x % y == 0) {         x /= y;         cnt++;       }       if (cnt)         answ[y] += cnt;       else if (y * y > x) {         answ[x]++;         break;       }     }     return answ;   }   long long binpow(long long a, long long x) {     long long res = 1ll;     while (x) {       if (x & 1ll) res *= a, res %= mod;       a *= a;       a %= mod;       x >>= 1ll;     }     return (res % mod + 2ll * mod) % mod;   }   void solve() {     precalc();     long long f[4], n, c;     scanf( %lld%lld%lld%lld%lld , &n, &f[0], &f[1], &f[2], &c);     Matrix matrix = Matrix({{1ll, 1ll, 1ll}, {1ll, 0ll, 0ll}, {0ll, 1ll, 0ll}});     matrix ^= (n - 3ll);     std::set<long long> primes;     std::map<long long, int> FG[5];     for (int i = 0; i < 3; i++) {       FG[i] = PrimeDecomposition(f[i]);       for (std::pair<long long, long long> x : FG[i]) {         primes.insert(x.first);       }     }     FG[3] = PrimeDecomposition(c);     for (std::pair<long long, long long> x : FG[3]) {       primes.insert(x.first);     }     std::vector<std::pair<long long, long long>> FnCn;     for (long long x : primes) {       Matrix PrimeCount = Matrix(3, 1);       for (int i = 0; i < 3; i++) {         PrimeCount.mat[2 - i][0] += FG[i][x];         PrimeCount.mat[2 - i][0] += FG[3][x] * 1ll * (i + 1);       }       Matrix Lprimes = matrix * PrimeCount;       FnCn.push_back({x, Lprimes.mat[0][0]});     }     long long answ = 1ll;     for (std::pair<long long, long long> x : FnCn) {       answ *= binpow(x.first, x.second);       answ %= mod;     }     answ *= binpow(binpow(c, mod - 2ll), n);     answ %= mod;     printf( %lld n , answ);     return;   }   int main() {     int t;     t = 1;     while (t--) {       solve();     }     std::cin >> t;     return 0;   }