#include #include #include #include #include #include #include #include #include static const int MOD = 1000000007; using ll = long long; using u32 = unsigned; using u64 = unsigned long long; using namespace std; template constexpr T INF = ::numeric_limits::max() / 32 * 15 + 208; class modint { static u32 &mod() { static u32 mod_ = 0; return mod_; } public: u32 val; modint(const u32 x = 0) : val(x % M()) {} u32 &value() noexcept { return val; } const u32 &value() const noexcept { return val; } modint operator+(const modint b) const { return modint(*this) += b; } modint operator-(const modint b) const { return modint(*this) -= b; } modint operator*(const modint b) const { return modint(*this) *= b; } modint operator/(const modint b) const { return modint(*this) /= b; } modint &operator+=(const modint b) { val += b.val; if (val >= M()) val -= M(); return *this; } modint &operator-=(const modint b) { if (val < b.val) val += M(); val -= b.val; return *this; } modint &operator*=(const modint b) { val = (u64)val * b.val % M(); return *this; } modint pow(ll n) const { modint x = *this, r = 1; while(n){ if(n&1) r *= x; x *= x; n >>= 1; } return r; } modint &operator/=(modint b) { return *this *= b.pow(M()-2); } static void set_mod(const u32 x) { mod() = x; } static int M() { return mod(); } }; using mint = modint; int main() { int p, n; cin >> p >> n; mint::set_mod(p); vector a(n); for (auto &&i : a) scanf("%d", &i); mint ans = a[0]; string s; cin >> s; for (int i = 0; i+1 < n; ++i) { mint b = a[i+1]; if(s[i] == '+') ans += b; if(s[i] == '-') ans -= b; if(s[i] == '*') ans *= b; if(s[i] == '/') ans /= b; } cout << ans.val << "\n"; return 0; }