#include #include using namespace std; using namespace atcoder; void fast_io() { ios_base::sync_with_stdio(false); cin.tie(nullptr); } int main() { fast_io(); int n; cin >> n; vector a(n); for (int i = 0; i < n; i++) { cin >> a[i]; } string s; cin >> s; string t = ""; for (int i = 0; i < n; i++) { if (a[i] < a[(i + 1) % n]) { t += "<"; } else { t += ">"; } } t += t; auto z = z_algorithm(s + t); for (int i = 0; i < n; i++) { if (z[i + n - 1] >= n - 1) { cout << i << endl; return 0; } } cout << -1 << endl; }