#pragma GCC optimize("Ofast") #include #define rep(i,n) for(ll i=0;i<(ll)(n);i++) #define rep_r(i,n) for(ll i=(ll)(n)-1;i>=0;i--) #define rep2(i,sta,n) for(ll i=sta;i<(ll)(n);i++) #define rep2_r(i,sta,n) for(ll i=(ll)(n)-1;i>=sta;i--) #define all(v) (v).begin(),(v).end() #define vlin(name,sz,offset) vl name(sz); rep(i,sz){cin>>name[i]; name[i]-=offset;} #define pb push_back #define mp make_pair #define fi first #define se second using namespace std; typedef long long ll; typedef unsigned long long ull; typedef long double ld; typedef pair P; typedef pair LP; typedef map LM; typedef tuple LT; typedef tuple LT4; typedef vector vi; typedef vector vvi; typedef vector vl; typedef vector vvl; typedef vector v3l; typedef vector v4l; typedef vector v5l; typedef vector vlp; typedef vector vvlp; typedef vector vs; typedef vector vvs; typedef vector vd; typedef vector vvd; typedef vector vb; const int INF = numeric_limits::max() / 2 - 1e6; const ll LINF = LLONG_MAX / 2 - 1e6; const double DINF = numeric_limits::infinity(); struct RandGen { using ud = uniform_int_distribution; mt19937 mt; RandGen() : mt(chrono::steady_clock::now().time_since_epoch().count()) {} ll l(ll a, ll b) { ud d(a, b - 1); return d(mt); } LP lp(ll a, ll b, bool rng = true) { ll x = l(a, b - 1), y = l(rng ? x + 1 : a, b - 1); return {x, y}; } vl vecl(ll l, ll a, ll b) { ud d(a, b - 1); vl ret(l); rep(i, l) ret[i] = d(mt); return ret; } vl vecperm(ll l, ll from = 0) { vl perm(l); iota(all(perm), from); shuffle(perm); return perm; } string str(ll l, string op) { vl fig = vecl(l, 0, op.size()); string s; rep(i, l) s.pb(op[fig[i]]); return s; } string straz(ll l, ll a = 0, ll z = 26) { vl az = vecl(l, a, z); string s; rep(i, l) s.pb('a' + az[i]); return s; } string strnum(ll l, ll zero = 0, ll ten = 10) { vl zt = vecl(l, zero, ten); string s; rep(i, l) s.pb('0' + zt[i]); return s; } void shuffle(vl &a) { std::shuffle(all(a), mt); } }; template void coutarray(vector& v, int offset = 0, string sep = " ") { rep(i, v.size()) { if (i > 0) cout << sep; if (offset) cout << v[i] + offset; else cout << v[i]; } cout << "\n"; } template void coutmatrix(vector>& v, int offset = 0) { rep(i, v.size()) { coutarray(v[i], offset); } } template void coutset(set & s) { for (const auto& a : s) { cout << a << " "; } cout << "\n"; } template void coutmap(map & m) { for (const auto& kv : m) { cout << kv.first << ":" << kv.second << " "; } cout << "\n"; } template void coutpair(pair & p, string sep = " ") { cout << p.first << ":" << p.second << sep; } template void coutbin(T &a, int d) { for (int i = d - 1; i >= 0; i--) cout << ((a >> i) & (T)1); cout << "\n"; } template void iquery(initializer_list q, A &a, string str = "? ") { cout << str; vector v(q); coutarray(v); cout.flush(); cin >> a; } // template void iquery(initializer_list q, A &a, string str = "? ") { vector query(q); RandGen rg; // a = query[0] ? A() : A(); // } template void ianswer(A a, string str = "! ") { cout << str << a << "\n"; cout.flush(); } int ceil_pow2(ll n) { int x = 0; while ((1ULL << x) < (unsigned long long)(n)) x++; return x; } int floor_pow2(ll n) { int x = 0; while ((1ULL << (x + 1)) <= (unsigned long long)(n)) x++; return x; } ll digits(ll n) { ll ret = 0; while(n > 0) { ret++; n /= 10; } return ret; } ll POW(ll x, int n) { assert(n >= 0); ll res = 1; for(; n; n >>= 1, x *= x) if(n & 1) res *= x; return res; } ll sqrt_ceil(ll x) { ll l = -1, r = x; while (r - l > 1) { ll m = (l + r) / 2; if (m * m >= x) r = m; else l = m; } return r; } template T ceil(T x, S y) { assert(y); return (y < 0 ? ceil(-x, -y) : (x > 0 ? (x + y - 1) / y : x / y)); } template T floor(T x, S y) { assert(y); return (y < 0 ? floor(-x, -y) : (x > 0 ? x / y : (x - y + 1) / y)); } template void uniq(vector&a){ sort(all(a)); a.erase(unique(all(a)), a.end()); } template void comp(vector&a){ vector b = a; uniq(b); rep(i, a.size()) a[i] = lower_bound(all(b), a[i]) - b.begin(); } template bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1;} return 0; } template bool chmax(T &a, const T &b) { if (b > a) { a = b; return 1;} return 0; } template int lbs(vector &a, const T &b) { return lower_bound(all(a), b) - a.begin(); }; template int ubs(vector &a, const T &b) { return upper_bound(all(a), b) - a.begin(); }; ll binary_search(function check, ll ok, ll ng) { assert(check(ok)); while (abs(ok - ng) > 1) { auto x = (ng + ok) / 2; if (check(x)) ok = x; else ng = x; } return ok; } template vector csum(vector &a) { vl ret(a.size() + 1, 0); rep(i, a.size()) ret[i + 1] = ret[i] + a[i]; return ret; } template vector> RLE(const vector &v) { vector> res; for(auto &e : v) if(res.empty() or res.back().first != e) res.emplace_back(e, 1); else res.back().second++; return res; } vector> RLE(const string &v) { vector> res; for(auto &e : v) if(res.empty() or res.back().first != e) res.emplace_back(e, 1); else res.back().second++; return res; } const string drul = "DRUL"; vl dx = {1, 0, -1, 0}; vl dy = {0, 1, 0, -1}; ll solve(ll N, vl a) { ll ans = -1; return ans; } ll naive(ll N, vl a) { ll ans = 1; return ans; } void compare(bool check = true) { RandGen rg; ll c = 0, loop = 10; while (++c) { if (c % loop == 0) cout << "reached " << c / loop << "loop" << "\n", cout.flush(); ll N = 10; vl a = rg.vecl(N, 1, 1e2); auto s = solve(N, a); auto n = naive(N, a); if (!check || n != s) { cout << c << "times tried" << "\n"; cout << N << "\n"; coutarray(a); cout << "solve: " << s << "\n"; cout << "naive: " << n << "\n"; if (check || (!check && c > loop)) break; } } } const ll mod = 1000000007; //------------------------------------------------------------------------------ template< int mod > struct ModInt { int x; ModInt() : x(0) {} ModInt(int64_t y) : x(y >= 0 ? y % mod : (mod - (-y) % mod) % mod) {} ModInt &operator+=(const ModInt &p) { if((x += p.x) >= mod) x -= mod; return *this; } ModInt &operator-=(const ModInt &p) { if((x += mod - p.x) >= mod) x -= mod; return *this; } ModInt &operator*=(const ModInt &p) { x = (int) (1LL * x * p.x % mod); return *this; } ModInt &operator/=(const ModInt &p) { *this *= p.inv(); return *this; } ModInt operator-() const { return ModInt(-x); } ModInt operator+(const ModInt &p) const { return ModInt(*this) += p; } ModInt operator-(const ModInt &p) const { return ModInt(*this) -= p; } ModInt operator*(const ModInt &p) const { return ModInt(*this) *= p; } ModInt operator/(const ModInt &p) const { return ModInt(*this) /= p; } bool operator==(const ModInt &p) const { return x == p.x; } bool operator!=(const ModInt &p) const { return x != p.x; } ModInt inv() const { int a = x, b = mod, u = 1, v = 0, t; while(b > 0) { t = a / b; swap(a -= t * b, b); swap(u -= t * v, v); } return ModInt(u); } ModInt pow(int64_t n) const { ModInt ret(1), mul(x); while(n > 0) { if(n & 1) ret *= mul; mul *= mul; n >>= 1; } return ret; } friend ostream &operator<<(ostream &os, const ModInt &p) { return os << p.x; } friend istream &operator>>(istream &is, ModInt &a) { int64_t t; is >> t; a = ModInt< mod >(t); return (is); } static int get_mod() { return mod; } }; using mint = ModInt< mod >; typedef vector vmi; typedef vector vvmi; typedef vector v3mi; typedef vector v4mi; //------------------------------------------------------------------------------ const int max_n = 1 << 20; mint fact[max_n], factinv[max_n]; void init_f() { fact[0] = 1; for (int i = 0; i < max_n - 1; i++) { fact[i + 1] = fact[i] * (i + 1); } factinv[max_n - 1] = mint(1) / fact[max_n - 1]; for (int i = max_n - 2; i >= 0; i--) { factinv[i] = factinv[i + 1] * (i + 1); } } mint comb(int a, int b) { assert(fact[0] != 0); if (a < 0 || b < 0 || a < b) return 0; return fact[a] * factinv[b] * factinv[a - b]; } mint combP(int a, int b) { assert(fact[0] != 0); if (a < 0 || b < 0 || a < b) return 0; return fact[a] * factinv[a - b]; } //------------------------------------------------------------------------------ ll mod_pow(ll x, ll n, const ll &p = mod) { ll ret = 1; while(n > 0) { if(n & 1) (ret *= x) %= p; (x *= x) %= p; n >>= 1; } return ret; } ll mod_inv(ll x, ll m) { ll a = x, b = m, u = 1, v = 0, t; while(b) { t = a / b; swap(a -= t * b, b); swap(u -= t * v, v); } if (u < 0) u += m; return u % m; } //------------------------------------------------------------------------------ // ---------------------------------------------------------------------- template struct BIT { int n; vector bit; BIT(int _n = 0) : n(_n), bit(n + 1) {} // sum of [0, i), 0 <= i <= n T sum(int i) { T s = 0; while (i > 0) { s += bit[i]; i -= i & -i; } return s;} // 0 <= i < n void add(int i, T x) { ++i; while (i <= n) { bit[i] += x; i += i & -i; } } //[l, r) 0 <= l < r < n T sum(int l, int r) { return sum(r) - sum(l); } // smallest i, sum(i) >= w, none -> n int lower_bound(T w) { if (w <= 0) return 0; int x = 0, l = 1; while (l * 2 <= n) l <<= 1; for (int k = l; k > 0; k /= 2) if (x + k <= n && bit[x + k] < w) { w -= bit[x + k]; x += k; } return x; } }; // ---------------------------------------------------------------------- void solve() { ll n, k; cin >> n >> k; vlin(a, n, 0); comp(a); string s; cin >> s; vector> dp(k + 2, BIT(n + 1)); rep(i, n) { rep2_r(j, 1, k + 1) { if (s[j - 1] == '>') { dp[j + 1].add(a[i], dp[j].sum(a[i] + 1, n + 1)); } else { dp[j + 1].add(a[i], dp[j].sum(0, a[i])); } } dp[1].add(a[i], 1); } cout << dp[k + 1].sum(n + 1) << "\n"; } signed main() { ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); cout << fixed << setprecision(15); int t = 1; // cin >> t; while (t--) solve(); // while (t--) compare(); }