Monotonicity

No attempts yetTime limit3sMemory limit512 MB

Problem

For an integer sequence a1,a2,,ana_1, a_2, \ldots, a_n we define its monotonicity scheme as the sequence s1,s2,,sn1s_1, s_2, \ldots, s_{n-1} of symbols <<, >>, or ==. The symbol sis_i describes the relation between aia_i and ai+1a_{i+1}. For example, the monotonicity scheme of the sequence 2,4,3,3,5,32, 4, 3, 3, 5, 3 is <,>,=,<,><, >, =, <, >.

We say that an integer sequence b1,b2,,bn+1b_1, b_2, \ldots, b_{n+1} with monotonicity scheme s1,s2,,sns_1, s_2, \ldots, s_n realizes another monotonicity scheme s1,s2,,sks'_1, s'_2, \ldots, s'_k if for every i=1,2,,ni = 1, 2, \ldots, n it holds that si=s((i1)modk)+1s_i = s'_{((i-1) \bmod k) + 1}. In other words, the sequence s1,s2,,sns_1, s_2, \ldots, s_n can be obtained by repeating the sequence s1,s2,,sks'_1, s'_2, \ldots, s'_k and removing an appropriate suffix from that repetition. For example, the sequence 2,4,3,3,5,32, 4, 3, 3, 5, 3 realizes every one of the following schemes:

  • <,>,=<, >, =
  • <,>,=,<,><, >, =, <, >
  • <,>,=,<,>,<,<,=<, >, =, <, >, <, <, =
  • <,>,=,<,>,=,>,><, >, =, <, >, =, >, >

as well as many others.

You are given an integer sequence a1,a2,,ana_1, a_2, \ldots, a_n and a monotonicity scheme s1,s2,,sks_1, s_2, \ldots, s_k. Find the longest subsequence ai1,ai2,,aima_{i_1}, a_{i_2}, \ldots, a_{i_m} (with 1i1<i2<<imn1 \le i_1 < i_2 < \cdots < i_m \le n) of the given sequence that realizes the given scheme.

Input

The first line contains two integers nn and kk (1n200001 \le n \le 20\,000, 1k1001 \le k \le 100), separated by a single space, denoting the lengths of the sequence (ai)(a_i) and of the monotonicity scheme (sj)(s_j) respectively.

The second line contains the sequence (ai)(a_i): nn integers aia_i separated by single spaces (1ai10000001 \le a_i \le 1\,000\,000).

The third line contains the monotonicity scheme (sj)(s_j): kk symbols sjs_j, each one of <<, >>, or ==, separated by single spaces.

Output

Print a single integer mm: the maximum length of a subsequence of a1,a2,,ana_1, a_2, \ldots, a_n that realizes the scheme s1,s2,,sks_1, s_2, \ldots, s_k.