For an integer sequence a1,a2,…,an we define its monotonicity scheme as the sequence s1,s2,…,sn−1 of symbols <, >, or =. The symbol si describes the relation between ai and ai+1. For example, the monotonicity scheme of the sequence 2,4,3,3,5,3 is <,>,=,<,>.
We say that an integer sequence b1,b2,…,bn+1 with monotonicity scheme s1,s2,…,sn realizes another monotonicity scheme s1′,s2′,…,sk′ if for every i=1,2,…,n it holds that si=s((i−1)modk)+1′. In other words, the sequence s1,s2,…,sn can be obtained by repeating the sequence s1′,s2′,…,sk′ and removing an appropriate suffix from that repetition. For example, the sequence 2,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,…,an and a monotonicity scheme s1,s2,…,sk. Find the longest subsequence ai1,ai2,…,aim (with 1≤i1<i2<⋯<im≤n) of the given sequence that realizes the given scheme.
The first line contains two integers n and k (1≤n≤20000, 1≤k≤100), separated by a single space, denoting the lengths of the sequence (ai) and of the monotonicity scheme (sj) respectively.
The second line contains the sequence (ai): n integers ai separated by single spaces (1≤ai≤1000000).
The third line contains the monotonicity scheme (sj): k symbols sj, each one of <, >, or =, separated by single spaces.
Print a single integer m: the maximum length of a subsequence of a1,a2,…,an that realizes the scheme s1,s2,…,sk.