#include using namespace std; #define rep(i, n) for(int i = 0; i < n; ++i) #define REP(i, x, n) for(int i = (x); i < n; ++i) #define rrep(i, n) for(int i = n - 1; i >= 0; --i) #define RREP(i, x, n) for(int i = n - 1; i >= (x); --i) #define all(x) x.begin(), x.end() using ll = long long; using vll = vector; using vvll = vector; using vi = vector; using vvi = vector; using vvvi = vector; using vvvvi = vector; using vb = vector; using vvb = vector; using P = pair; using Pll = pair; using vp = vector

; using vvp = vector; template bool chmax(T &a, const T &b) { if(a < b) { a = b; return 1; } return 0; } template bool chmin(T &a, const T &b) { if(b < a) { a = b; return 1; } return 0; } template vector Zalgorithm(vector S) { int n = S.size(); vector arr(n); arr[0] = n; int i = 1, j = 0; while(i < n) { while(i + j < n && S[j] == S[i + j]) ++j; arr[i] = j; if(j == 0) { ++i; continue; } int k = 1; while(i + k < n && k + arr[k] < j) { arr[i + k] = arr[k]; ++k; } i += k; j -= k; } return arr; } void solve() { int n; cin >> n; vi a(n); rep(i, n) cin >> a[i]; string s; cin >> s; string t; rep(i, 2 * n - 2) t += (a[(i) % n] < a[(i + 1) % n] ? '<' : '>'); vector u; for(char &e : s) u.push_back(e); for(char &e : t) u.push_back(e); for(char &e : t) u.push_back(e); --n; auto z = Zalgorithm(u); REP(i, n, 3 * n) { if(z[i] >= n) { cout << i - n << endl; return; } } cout << -1 << endl; } int main() { ios::sync_with_stdio(false); cin.tie(0); int t = 1; // cin >> t; while(t--) solve(); return 0; }