#include using namespace std; #define rep(i,n) for (int i = 0; i< (n); ++i) #define repi(i, a, b) for (int i = (a); i < (b); ++i) #define all(x) (x).begin(), (x).end() #define fore(i, a) for(auto &i:a) using ll = long long; #define DEBUG(x) cerr << #x << ": "; for (auto _ : x) cerr << _ << " "; cerr << endl; //ref -> https://qiita.com/t_fuki/items/e682238dda6ad832ce05 //check -> https://judge.yosupo.jp/problem/zalgorithm vector z_algorithm(string s){ vector z(s.size(), 0); z[0] = s.size(); int l=0,r=0; repi(i, 1, s.size()){ if(z[i-l] < r-i){ z[i] = z[i-l]; } else{ r = max(r, i); while(r < s.size() && s[r] == s[r-i])r++; z[i] = r-i; l = i; } } return z; } int main() { ll n; cin >> n; vector a(n); rep(i, n)cin >> a[i]; string s; cin >> s; string t(n, '*'); rep(i, n){ if(a[i] > a[(i+1)%n])t[i] = '>'; else t[i] = '<'; } string st = s+'&'+t; string ts = t+'&'+s; auto z1 = z_algorithm(st); auto z2 = z_algorithm(ts); rep(i, n){ if(i == 0){ if(z1[n] == n-1){ cout << i << endl; return 0; } } else{ if(z1[n+i]==n-i && (i == 1 || z2[2*n-i+1]==i-1)){ cout << i << endl; return 0; } } } cout << -1 << endl; }