import java.io.PrintWriter import scala.collection.mutable.* import scala.io.StdIn.* import scala.util.chaining.* import scala.math.* import scala.reflect.ClassTag import scala.util.* import scala.annotation.tailrec import scala.collection.mutable def powMod(base: Long, exp: Int, mod: Int): Long = var result = 1L var b = base % mod var e = exp while e > 0 do if (e & 1) == 1 then result = result * b % mod b = b * b % mod e >>= 1 result @main def main() = inline val MOD = 1_000_000_007 val random = Random(0) val n = readLine().toInt val num = readLine().split(' ').map(_.toInt) val str = readLine() val isMatch = Array.fill(2 * n - 1){true} val double = (num ++ num).pipe{array => (1 until array.length).map{i => if array(i - 1) < array(i) then 0 else 1}.toArray } val target = str.map{ case '<' => 0 case '>' => 1 }.toArray val left = powMod(2, n - 1, MOD) for _ <- 0 until 3 do val x = random.nextInt(MOD) val targetHash = target.foldLeft(0L){ (acc, v) => ((acc << 1) + v * x) % MOD} var hash = target.indices.foldLeft(0L){ (acc, i) => ((acc << 1) + double(i) * x) % MOD} isMatch(target.length - 1) = hash == targetHash //println(s"$hash, $targetHash") for i <- target.length until double.length do hash = ((hash << 1) + double(i) * x) % MOD hash = (hash - left * double(i - target.length) * x % MOD + MOD) % MOD isMatch(i) = isMatch(i) && hash == targetHash //println(s"$hash, $targetHash") (target.length - 1 until isMatch.length).find(isMatch(_)) match case Some(i) => println(i - target.length + 1) case None => println(-1)