Up Down Subsequence

아직 제출이 없습니다시간 제한2초메모리 제한1024 MB

문제

Farmer John's NN cows (2N31052 \leq N \leq 3\cdot 10^5), conveniently numbered 1N1 \ldots N as usual, have ordered themselves according to a permutation p_1,p_2,,p_Np\_1,p\_2,\ldots,p\_N of 1N1\ldots N. You are also given a string of length N1N-1 consisting of the letters U and D. Please find the maximum KN1K\le N-1 such that there exists a subsequence a_0,a_1,,a_Ka\_0,a\_1,\ldots,a\_{K} of pp such that for all 1jK1\le j\le K, a_j1<a_ja\_{j - 1} < a\_j if the jjth letter in the string is U, and a_j1>a_ja\_{j - 1} > a\_j if the jjth letter in the string is D.

입력

The first line contains NN.

The second line contains p_1,p_2,,p_Np\_1,p\_2,\ldots,p\_N.

The last line contains the string.

출력

Write out maximum possible value of KK.