object Main {
  def main(args: Array[String]) {
    val n = readInt
    val a = readLine().split(" ").map(_.toInt)

    val len = a.size
    val reverse = "L" * (len - 1)
    val max = a.max
    for(i <- 1 to max) {
      for(j <- 0 until len - 1) {
        if(a(j) >= i) print("PR")
        else print("R")
      }
      if (a(len - 1) >= i) print("P")
      if (i != max) print(reverse)
    }
  }
}

import java.util.StringTokenizer

object _379B extends App {
  var token = new StringTokenizer("")
  def next = {
    while (!token.hasMoreTokens()) token = new StringTokenizer(readLine)
    token.nextToken()
  }
  val n = next.toInt
  val a = (1 to n).map(i => next.toInt).toArray
  val ans = new StringBuilder

  def doit(i: Int): Unit = {
    if (i < n) {
      if (a(i) == 0) {
        if (i < n - 1) ans += 'R'
        doit(i + 1)
      }
      else {
        ans += 'P'
        a(i) -= 1
        if (a(i) == 0) {
          if (i < n - 1) ans += 'R'
          doit(i + 1)
        } else {
          if (i == 0) ans ++= "RL"
          else ans ++= "LR"
          doit(i)
        }
      }
    }
  }

  doit(0)
  println(ans.toString)
}

object Solution extends App {
  val in = scala.io.Source.stdin.getLines()
  val n = in.next().toInt
  val data = in.next().split(" ").map(_.toInt)
  var left = data.sum
  var i = 0
  var result = List.empty[Char]
  var lbound = -1
  var took = false
  while (left != 0) {
    if (lbound == -1 && data(i) > 0)
      lbound = i
    if (data(i) > 0 && !took) {
      result ::= 'P'
      data(i) -= 1
      left -= 1
      took = true
      if (lbound == i && data(i) == 0)
        lbound = -1
    } else if (i != 0 && (lbound != -1 && lbound < i || i == n - 1)) {
      result ::= 'L'
      i -= 1
      took = false
    } else {
      result ::= 'R'
      i += 1
      took = false
    }
  }
  println(result.reverse.mkString)
}

object Main {

  def main(args: Array[String]) = {
    val input = scala.io.Source.stdin.getLines()

    val n = input.next().toInt
    val a = input.next().split(" ").map(_.toInt).toList.toArray

    val sum = a.sum

    var cu = 0
    var p = 0

    var l = List.empty[Char]
    while (cu < sum) {
      if (a(p) == 0) {
        l = 'R' :: l
        p += 1
      } else if (p == a.length - 1) {
        l = 'R' :: 'L' :: 'P' :: l
        a(p) -= 1
        cu += 1
      } else if (p+1 < a.size && a(p+1) > 0 && a(p) > 1) {
        l = 'L' :: 'P' :: 'R' :: 'P' :: l
        cu += 2
        a(p) -= 1
        a(p+1) -= 1
      } else if (a(p) > 1) {
        l = 'L' :: 'R' :: 'P' :: l
        a(p) -= 1
        cu += 1
      } else {
        l = 'R' :: 'P' :: l
        a(p) -= 1
        cu += 1
        p += 1
      }
    }
    while (l.head != 'P') l = l.tail
    print(l.reverse.mkString)
  }
}

import scala.collection._

object B extends App {

  def tokenizeLine = new java.util.StringTokenizer(readLine)
  def readInts(n: Int) = { val t = tokenizeLine; Array.fill(n)(t.nextToken.toInt) }
  def readLongs(n: Int) = { val t = tokenizeLine; Array.fill(n)(t.nextToken.toLong) }
  def readBigs(n: Int) = { val t = tokenizeLine; Array.fill(n)(BigInt(t.nextToken)) }

  val n = readInt
  val as = readInts(n)
  val moves = Array.ofDim[Char](1000000)
  var m = 0

  var i = 0
  while (i < n) {
    if (as(i) > 0) {
      moves(m) = 'P'
      m += 1
      as(i) -= 1
    }
    moves(m) = if (i < n - 1) 'R' else 'L'
    m += 1
    if (as(i) > 0) {
      moves(m) = if (moves(m - 1) == 'R') 'L' else 'R'
      m += 1
    } else i += 1
  }

  println(moves.take(m).mkString)
}

import java.util.Scanner
import java.io.PrintWriter
import scala.annotation.tailrec
import scala.collection.mutable
import scala.util.Random

object P379B extends App {
  val sc = new Scanner(System.in)
  val out = new PrintWriter(System.out)
  val N = sc.nextInt
  val A = List.fill(N)(sc.nextInt)

  def solve(): Unit = {
    val a0 = A.head
    out.print(List.fill(a0)("P").mkString("RL"))
    A.tail foreach { i =>
      out.print(List.fill(i)("P").mkString("R", "LR", ""))
    }
  }

  solve
  out.println
  out.close
}

import java.util.Scanner

/**
 * Created by Kuang.Ru on 14-9-28.
 */
object B379 extends App{
  val sc = new Scanner(System.in)
  val n = sc.nextInt()
  var i = 0

  while (i < n) {
    val m = sc.nextInt()
    if (i < n - 1) {
      if (m == 0) {
        print('R')
      } else {
        print("P" + "RLP" * (m - 1) + "R")
      }
    } else {
      if (m != 0) {
        print("P" + "LRP" * (m - 1))
      }
    }

    i += 1
  }
}

import java.util.StringTokenizer

object _379B extends App {
  var token = new StringTokenizer("")
  def next = {
    while (!token.hasMoreTokens()) token = new StringTokenizer(readLine)
    token.nextToken()
  }
  val n = next.toInt
  val a = (1 to n).map(i => next.toInt).toArray
  val ans = new StringBuilder

  def doit(i: Int): Unit = {
    if (i < n) {
      if (a(i) == 0) {
        if (i < n - 1) ans += 'R'
        ans += 'R'
        doit(i + 1)
      }
      else {
        ans += 'P'
        a(i) -= 1
        if (a(i) == 0) {
          if (i < n - 1) ans += 'R'
          doit(i + 1)
        } else {
          if (i == 0) ans ++= "RL"
          else ans ++= "LR"
          doit(i)
        }
      }
    }
  }

  doit(0)
  println(ans.toString)
}

object Main {

  def main(args: Array[String]) = {
    val input = scala.io.Source.stdin.getLines()

    val n = input.next().toInt
    val a = input.next().split(" ").map(_.toInt).toList.toArray

    val sum = a.sum

    var cu = 0
    var p = 0

    var l = List.empty[Char]
    while (cu < sum) {
      if (a(p) == 0) {
        l = 'R' :: l
        p += 1
      } else if (p+1 < a.size && a(p+1) > 0 && a(p) > 1) {
        l = 'L' :: 'P' :: 'R' :: 'P' :: l
        cu += 2
        a(p) -= 1
        println(a.size + " " + p)
        a(p+1) -= 1
      } else if (a(p) > 1) {
        l = 'L' :: 'R' :: 'P' :: l
        a(p) -= 1
        cu += 1
      } else {
        l = 'R' :: 'P' :: l
        a(p) -= 1
        cu += 1
        p += 1
      }
    }
    print(l.reverse.mkString)
  }
}

object Main {

  def main(args: Array[String]) = {
    val input = scala.io.Source.stdin.getLines()

    val n = input.next().toInt
    val a = input.next().split(" ").map(_.toInt).toList.toArray

    val sum = a.sum

    var cu = 0
    var p = 0

    var l = List.empty[Char]
    while (cu < sum) {
      if (a(p) == 0) {
        l = 'R' :: l
        p += 1
      } else if (p == a.length - 1) {
        l = 'R' :: 'L' :: 'P' :: l
        a(p) -= 1
        cu += 1
      } else if (p+1 < a.size && a(p+1) > 0 && a(p) > 1) {
        l = 'L' :: 'P' :: 'R' :: 'P' :: l
        cu += 2
        a(p) -= 1
        println(a.size + " " + p)
        a(p+1) -= 1
      } else if (a(p) > 1) {
        l = 'L' :: 'R' :: 'P' :: l
        a(p) -= 1
        cu += 1
      } else {
        l = 'R' :: 'P' :: l
        a(p) -= 1
        cu += 1
        p += 1
      }
    }
    while (l.head != 'P') l = l.tail
    print(l.reverse.mkString)
  }
}

import java.util.Scanner

/**
 * Created by Kuang.Ru on 14-9-28.
 */
object B379 extends App{
  val sc = new Scanner(System.in)
  val n = sc.nextInt()
  var i = 0

  while (i < n) {
    val m = sc.nextInt()
    if (i < n - 1) {
      if (m == 0) {
        print('R')
      } else {
        print("P" + "RLP" * (m - 1) + "R")
      }
    } else {
      if (i != 0) {
        print("P" + "LRP" * (m - 1))
      }
    }

    i += 1
  }
}


object B230 {
  @inline def read = scala.io.StdIn.readLine

  @inline def tokenizeLine = new java.util.StringTokenizer(read)

  def readInts(n: Int) = {
    val tl = tokenizeLine; Array.fill(n)(tl.nextToken.toInt)
  }

  def readLongs(n: Int) = {
    val tl = tokenizeLine; Array.fill(n)(tl.nextToken.toLong)
  }

  def readBigs(n: Int) = {
    val tl = tokenizeLine; Array.fill(n)(BigInt(tl.nextToken))
  }

  def isPrime(n: Long): Boolean = {
    var i = 2
    while(i*i <= n){
      if(n % i == 0) {
        return false
      }
      i += 1
    }
    true
  }

  def genPrimes(till: Int): Set[Int] = {
    val isPrime = Array.fill[Boolean](till+1)(true)
    isPrime(0) = false
    isPrime(1) = false // not composite
    for(i <- 4 to till by 2) {
      isPrime(i) = false
    }
    for(i <- 3 to till by 2 if isPrime(i)) {
      for(j <- i+i to till by i) isPrime(j) = false
    }
    isPrime.zipWithIndex.filter(_._1).map(_._2).toSet
  }

  def main(args: Array[String]): Unit = {
    val Array(n) = readInts(1)
    val primes = genPrimes(1000000)
    val input = readLongs(n).map{ num =>
      val sqrt = math.sqrt(num)
      if(num != 1 && sqrt%1 == 0 && primes.contains(sqrt.toInt)) true else false
    }
    println(input.map(x => if(x) "YES" else "NO").mkString("\n"))
  }
}

object Main extends App {
  val bound = 1000010
  val primes = Array.ofDim[Boolean](bound)
  for {
    i <- 2 until bound
    if (!primes(i))
    j <- 2 * i until bound by i
  } primes(j) = true

  val n = readInt()
  val a = readLine().split(" ").map(_.toLong).map {
    case n if n < 3      => "NO"
    case n if n == 4     => "YES"
    case n if n % 2 == 0 => "NO"
    case n =>
      val sqrt = Math.round(Math.sqrt(n))
      if (sqrt * sqrt != n) "NO"
      else if (!primes(sqrt.toInt)) "YES"
      else "NO"
  }
  println(a.mkString("\n"))
}

import java.io.OutputStreamWriter
import java.io.BufferedWriter
import java.util.StringTokenizer

object _230B extends App {
  var token = new StringTokenizer("")
  def next = {
    while (!token.hasMoreTokens()) token = new StringTokenizer(readLine)
    token.nextToken()
  }

  val MAX = 1000001
  val isPrime = Array.fill(MAX)(true)
  isPrime(0) = false
  isPrime(1) = false

  {
    var i = 2
    while(i * i < MAX) {
      if (isPrime(i)) {
        var j = i + i
        while(j < MAX) {
          isPrime(j) = false
          j += i
        }
      }
      i += 1
    }
  }

  val primes = (0 until MAX).filter(i => isPrime(i))
  val cand = primes.map(i => i.toLong * i).toSet

  val cout = new BufferedWriter(new OutputStreamWriter(System.out))
  for (i <- 1 to next.toInt) {
    val x = next.toLong
    if (cand.contains(x)) cout.write("YES\n")
    else cout.write("NO\n")
  }

  cout.close
}

object Solution extends App {
  val in = scala.io.Source.stdin.getLines()
  in.next()
  val sieve = Array.ofDim[Boolean](1000001)
  (2 to 1000000).foreach { i =>
    if (!sieve(i)) {
      (i * 2 to 1000000 by i).foreach { j => sieve(j) = true }
    }
  }

  println(in.next().split(" ").map(_.toLong).map {
    case n if n < 3 => "NO"
    case n if n == 4 => "YES"
    case n if n % 2 == 0 => "NO"
    case n =>
      val sqrt = Math.round(Math.sqrt(n))

      if (sqrt * sqrt != n)
        "NO"
      else {
        if (!sieve(sqrt.toInt))
          "YES"
        else
          "NO"
      }

  }.mkString("\n"))

}

object Solution {
  import java.util.Scanner

  def main(args:Array[String]) {
    val it = new Iterator[Long] {
      private val sc = new Scanner(System.in)
      def hasNext = sc.hasNextLong
      def next = sc.nextLong
    }

    val tprimes = (new PrimeSet(1000000)).iterator.map(p => p.toLong * p).toSet

    val n = it.next
    it.take(n.toInt).foreach { x =>
      if (tprimes.contains(x))
        println("YES")
      else
        println("NO")
    }
  }
}

class PrimeSet(N:Int) extends Iterable[Int] {
  import java.util.BitSet

  private var sieved = 1
  private val flags = new BitSet()
  flags.set(2, N)

  private def square(n:Int) = BigInt(n).pow(2)

  def from(n:Int):Iterator[Int] = {
    if (n > sieved) from(sieved).dropWhile(n >)
    else new Iterator[Int] {
      private var p = flags.nextSetBit(n)
      def hasNext = p != -1
      def next = {
        val q = p
        if (q > sieved) {
          if (square(q) <= N) {
            (q * q to N by q).foreach(flags.clear(_))
            sieved = q
          } else {
            sieved = N
          }
        }
        p = flags.nextSetBit(p+1)
        q
      }
    }
  }

  def contains(n:Int) = {
    if (sieved < N && square(sieved) < n) {
      val sqrt = math.sqrt(n)
      from(sieved).dropWhile(sqrt >).next
    }
    flags.get(n)
  }

  def iterator = from(2)
}

object B230 {
  @inline def read = scala.io.StdIn.readLine

  @inline def tokenizeLine = new java.util.StringTokenizer(read)

  def readInts(n: Int) = {
    val tl = tokenizeLine; Array.fill(n)(tl.nextToken.toInt)
  }

  def readLongs(n: Int) = {
    val tl = tokenizeLine; Array.fill(n)(tl.nextToken.toLong)
  }

  def readBigs(n: Int) = {
    val tl = tokenizeLine; Array.fill(n)(BigInt(tl.nextToken))
  }

  def isPrime(n: Long): Boolean = {
    var i = 2
    while(i*i <= n){
      if(n % i == 0) {
        return false
      }
      i += 1
    }
    true
  }

  def genPrimes(till: Int): Array[Boolean] = {
    val isPrime = Array.fill[Boolean](till+1)(true)
    isPrime(0) = false
    isPrime(1) = false // not composite
    for(i <- 4 to till by 2) {
      isPrime(i) = false
    }
    for(i <- 3 to till by 2 if isPrime(i)) {
      for(j <- i+i to till by i) isPrime(j) = false
    }
    isPrime
  }

  def main(args: Array[String]): Unit = {
    val Array(n) = readInts(1)
    val primes = genPrimes(1000000)
    val input = readLongs(n).map{ num =>
      val sqrt = math.sqrt(num)
      if(num != 1 && sqrt%1 == 0 && primes(sqrt.toInt)) true else false
    }
    println(input.map(x => if(x) "YES" else "NO").mkString("\n"))
  }
}

import java.util.Scanner
import java.io.PrintWriter
import scala.annotation.tailrec
import scala.collection.mutable
import scala.collection.mutable.ListBuffer
import scala.util.Random
import scala.util.control.Breaks._
import scala.collection.mutable.ArrayBuffer
import java.util.Arrays.binarySearch

object P230B extends App {

  object PrimeNumber {
    def apply(n: Int = 1000000): Array[Int] = sieve(n)

    def sieve(n: Int): Array[Int] = {
      val primes = new ArrayBuffer[Int]
      val isPrime = Array.fill(n + 1)(true)

      @tailrec
      def loop(i: Int): Unit = {

        @tailrec
        def innerLoop(j: Int): Unit = {
          if (j > n) ()
          else {
            isPrime(j) = false
            innerLoop(j + i)
          }
        }

        if (i > n) ()
        else {
          if (isPrime(i)) {
            primes += i
            innerLoop(i * 2)
          }
          loop(i + 1)
        }
      }

      loop(2)
      primes.toArray
    }
  }

  val sc = new Scanner(System.in)
  val out = new PrintWriter(System.out)

  val tPrimes: Set[Long] = PrimeNumber(1000000).map(x => x.toLong * x.toLong).toSet
  for (_ <- 0 until sc.nextInt) {
    out.println(if (tPrimes(sc.nextLong)) "YES" else "NO") }

  out.close
}

import java.io._
import java.util.Locale
import scala.annotation.tailrec

object Easy {
  val reader = new BufferedReader(new InputStreamReader(System.in))
  def readInt = reader.readLine().toInt
  def readInts = reader.readLine().split(" ").map(_.toInt)
  def readLongs = reader.readLine().split(" ").map(_.toLong)

  val max = 1000000
  val isPrime = Array.ofDim[Boolean](max).map(_ => true)
  var i = 2
  while(i < max) {
    if(isPrime(i)) {
      var j = i.toLong * i
      while(j < max) {
        isPrime(j.toInt) = false
        j += i
      }
    }
    i += 1
  }
  val squaredPrimes = (for(i <- 2 until max if isPrime(i)) yield i.toLong * i).toSet
  reader.readLine()
  def ans = readLongs.map(x => if(squaredPrimes.contains(x)) "YES" else "NO").mkString("\n")

  def main(a: Array[String]) {
    println(ans)
  }
}

object Main {
  def sieve(n: Int) = {
    val primes = scala.collection.mutable.BitSet(2) ++ (3 to n by 2)
    for {
      cand <- 3 to Math.sqrt(n).toInt by 2
      if primes contains cand
    } primes --= (cand * cand to n by cand)
    primes
  }

  val primes = sieve(1000001).map{ i => i.toLong * i.toLong }

  def main(args: Array[String]) = {
    val n = readInt()
    val a = readLine().split(" ").map(_.toLong)
    a.foreach{i =>
      if (primes contains i) println("YES")
      else println("NO")
    }
  }
}

import scala.math._
import scala.collection.immutable.TreeSet

object Olymp{
  def primes(N: Int): TreeSet[Int] = {
    var p = new Array[Boolean](N+1)
    for(i <- 2 to sqrt(N).round.toInt)
      if (!p(i)){
        for(j <- i*i to N by i)
          p(j) = true
      }
    var ret = new TreeSet[Int]
    for(i <- 2 to N)
      if (!p(i))
        ret = ret + i
    ret
  }
  def main(args: Array[String]): Unit = {
    val n = readLine toInt
    val p = readLine split (' ') map (_ toLong)
    val pr = primes(1000000)
    for (i <- p){
      if (i != 1 && abs(sqrt(i) - sqrt(i).round) < 1e-8 && pr.contains(sqrt(i).round.toInt)) println("YES")
      else println("NO")
    }
  }
}

import scala.io.StdIn._
import scala.language.postfixOps

object TaskA extends App {
   val n = readInt
   val list = readLine.split(" ").map(_.toLong)

  val max = 1e6 toInt
  val primes = Array.fill(max + 1)(true)
  primes(1) = false

  for(i <- 2 to 1000) {
    if (primes(i)) {
      var next = i * i
      while (next <= max) {
        primes(next) = false
        next += i
      }
    }
  }

  println(list.map(isTPrime)
    .map(b => if (b) "YES" else "NO")
    .mkString("\n"))

  def isTPrime(x: Long) = {
    val sqrt = math.sqrt(x).toLong
    sqrt * sqrt == x && primes(sqrt.toInt)
  }
}

object Solution extends App {
  val in = scala.io.Source.stdin.getLines()
  in.next()
  val sieve = Array.ofDim[Boolean](100001)
  (3 to 100000 by 2).foreach { i =>
    if (!sieve(i)) {
      (i to 100000 by i).foreach { j => sieve(j) = true }
    }
  }

  println(in.next().split(" ").map(_.toLong).map {
    case n if n < 3 => "NO"
    case n if n == 4 => "YES"
    case n if n % 2 == 0 => "NO"
    case n =>
      val sqrt = Math.sqrt(n).toLong
      if (sqrt * sqrt != n)
        "NO"
      else {
        val sqrtsqrt = Math.sqrt(sqrt).toInt
        if (!sieve(sqrtsqrt))
          "YES"
        else
          "NO"
      }

  }.mkString("\n"))

}

object Solution extends App {
  val in = scala.io.Source.stdin.getLines()
  in.next()
  println(in.next().split(" ").map(_.toLong).map {
    case n if n < 3 => "NO"
    case n if n == 4 => "YES"
    case n if n % 2 == 0 => "NO"
    case n =>
      val sqrt = Math.sqrt(n).toLong
      if (sqrt * sqrt != n)
        "NO"
      else {
        val sqrtsqrt = Math.sqrt(sqrt).toLong
        if ((3l until sqrtsqrt by 2).forall(n % _ != 0))
          "YES"
        else
          "NO"
      }

  }.mkString("\n"))

}

object Solution extends App {
  val in = scala.io.Source.stdin.getLines()
  in.next()
  println(in.next().split(" ").map(_.toLong).map {
    case n if n < 3 => "NO"
    case n if n == 4 => "YES"
    case n if n % 2 == 0 => "NO"
    case n =>
      val sqrt = Math.sqrt(n).toLong
      if (sqrt * sqrt != n)
        "NO"
      else {
        val sqrtsqrt = Math.sqrt(sqrt).toLong
        if (sqrtsqrt * sqrtsqrt == n && (3l until sqrtsqrt by 2).forall(n % _ != 0))
          "YES"
        else
          "NO"
      }

  }.mkString("\n"))

}

object Solution extends App {
  val in = scala.io.Source.stdin.getLines()
  in.next()
  val sieve = Array.ofDim[Boolean](100001)
  sieve(1) = true
  sieve(3) = true
  (3 to 100000 by 2).foreach { i =>
    if (sieve(i)) {
      (i to 100000 by i).foreach { j => sieve(j) = true }
    }
  }

  println(in.next().split(" ").map(_.toLong).map {
    case n if n < 3 => "NO"
    case n if n == 4 => "YES"
    case n if n % 2 == 0 => "NO"
    case n =>
      val sqrt = Math.sqrt(n).toLong
      if (sqrt * sqrt != n)
        "NO"
      else {
        val sqrtsqrt = Math.sqrt(sqrt).toInt
        if (sieve(sqrtsqrt))
          "YES"
        else
          "NO"
      }

  }.mkString("\n"))

}

object B230 {
  @inline def read = scala.io.StdIn.readLine

  @inline def tokenizeLine = new java.util.StringTokenizer(read)

  def readInts(n: Int) = {
    val tl = tokenizeLine; Array.fill(n)(tl.nextToken.toInt)
  }

  def readLongs(n: Int) = {
    val tl = tokenizeLine; Array.fill(n)(tl.nextToken.toLong)
  }

  def readBigs(n: Int) = {
    val tl = tokenizeLine; Array.fill(n)(BigInt(tl.nextToken))
  }

  def main(args: Array[String]): Unit = {
    val Array(n) = readInts(1)
    val input = readLongs(n).map{ num => if(num != 1 && math.sqrt(num)%1 == 0) true else false}
    println(input.map(x => if(x) "YES" else "NO").mkString("\n"))
  }
}

object Main {
  def sieve(n: Long) = {
    val primes = scala.collection.mutable.BitSet(2) ++ (3L to n by 2)
    for {
      cand <- 3L to Math.sqrt(n).toLong by 2
      if primes contains cand
    } primes --= (cand * cand to n by cand)
    primes
  }

  val primes = sieve(1000000L)

  def main(args: Array[String]) = {
    val n = readInt()
    val a = readLine().split(" ").map(_.toLong)
    a.foreach{i =>
      val sq = Math.sqrt(i).toInt
      if (sq * sq != i) println("NO")
      else if (primes contains sq) println("YES")
      else println("NO")
    }
  }
}

import scala.math._

object Olymp{
  def main(args: Array[String]): Unit = {
    val n = readLine toInt
    val p = readLine split (' ') map (_ toLong)
    for (i <- p){
      if (abs(sqrt(i) - sqrt(i).round) < 1e-8) println("YES")
      else println("NO")
    }
  }
}

import scala.math._

object Olymp{
  def main(args: Array[String]): Unit = {
    val n = readLine toInt
    val p = readLine split (' ') map (_ toLong)
    for (i <- p){
      if (i != 1 && abs(sqrt(i) - sqrt(i).round) < 1e-8) println("YES")
      else println("NO")
    }
  }
}

import scala.math._

object Olymp{
  def isPrime(n: Long) = (2 until sqrt(n).round.toInt) forall (n % _ != 0)
  def main(args: Array[String]): Unit = {
    val n = readLine toInt
    val p = readLine split (' ') map (_ toLong)
    for (i <- p){
      if (isPrime(i) && abs(sqrt(i) - sqrt(i).round) < 1e-8) println("YES")
      else println("NO")
    }
  }
}

import scala.io.StdIn._
import scala.language.postfixOps

object TaskA extends App {
   val n = readInt
   val list = readLine.split(" ").map(_.toLong)

  val max = 1e6 toInt
  val primes = Array.fill(max + 1)(true)
  primes(1) = false

  for(i <- 2 to 1000) {
    if (primes(i)) {
      var next = i * i
      while (next < max) {
        primes(next) = false
        next += i
      }
    }
  }

  println(list.map(isTPrime)
    .map(b => if (b) "YES" else "NO")
    .mkString("\n"))

  def isTPrime(x: Long) = {
    val sqrt = math.sqrt(x).toLong
    sqrt * sqrt == x && primes(sqrt.toInt)
  }
}

import scala.io.StdIn._
import scala.language.postfixOps

object TaskA extends App {
   val n = readInt
   val list = readLine.split(" ").map(_.toLong)

  val max = 1e6 toInt
  val primes = Array.fill(max + 1)(true)

  for(i <- 2 to 1000) {
    if (primes(i)) {
      var next = i * i
      while (next < max) {
        primes(next) = false
        next += i
      }
    }
  }

  list.map(isTPrime)
    .map(b => if (b) "YES" else "NO")
    .foreach(println)

  def isTPrime(x: Long) = {
    val sqrt = math.sqrt(x).toLong
    sqrt * sqrt == x && primes(sqrt.toInt)
  }
}


import java.util.StringTokenizer

object _327B extends App {
  var token = new StringTokenizer("")
  def next = {
    while (!token.hasMoreTokens()) token = new StringTokenizer(readLine)
    token.nextToken()
  }
  val n = next.toInt
  var a = Vector[Int]()
  val isok = Array.fill(10000001)(true)
  var i = 2

  while(a.size < n) {
    if (isok(i)) {
      a = a :+ i
      var j = i + i
      while(j < isok.length) {
        isok(j) = false
        j += i
      }
    }
    i += 1
  }

  println(a.mkString(" "))
}

import java.util.Scanner
import java.io.PrintWriter
import java.util.Arrays.binarySearch
import scala.annotation.tailrec
import scala.collection.mutable
import scala.collection.mutable.ListBuffer
import scala.collection.mutable.ArrayBuffer
import scala.util.Random
import scala.util.control.Breaks._

object P327B extends App {
  val sc = new Scanner(System.in)
  val out = new PrintWriter(System.out)

  out.println(List.range(10000000 - sc.nextInt, 10000000).mkString(" "))
  out.close
}

import java.util.Scanner
import scala.math._
import scala.collection.mutable.ListBuffer

object R327_B extends App {
  val sc = new Scanner(System.in)
  val n = sc.nextInt()

  println(answer(n).mkString(" "))

  def answer(n:Int):Seq[Int] = {
    var list = new ListBuffer[Int]()
    var s = 10000000 - n + 1
    list.append(s)
    while(s < 10000000){
      s += 1
      list.append(s)
    }
    //println(list)
    list
  }

}

import java.io._
import java.util.Locale
import scala.annotation.tailrec

object Easy {
  val reader = new BufferedReader(new InputStreamReader(System.in))
  def readInt = reader.readLine().toInt
  def readInts = reader.readLine().split(" ").map(_.toInt)
  def readLongs = reader.readLine().split(" ").map(_.toLong)

  val max = 10 * 1000 * 1000
  def ans = (max to max - readInt + 1 by -1).reverse.mkString(" ")

  def main(a: Array[String]) {
    println(ans)
  }
}

object Main {
  def sieveOfEratosthenes(nTo: Int) = {
    val primes = collection.mutable.BitSet.empty ++ (2 to nTo)
    for {
      candidate <- 2 until Math.sqrt(nTo).toInt
      if primes contains candidate
    } primes --= candidate * candidate to nTo by candidate
    primes
  }

  val simple0 = sieveOfEratosthenes(1299709)

  def main(args: Array[String]) {
    val n = readInt()
    println(simple0.take(n).mkString(" "))
  }
}

object Hungry {
    def main(args:Array[String]){
      val n=readInt
      n until 2*n foreach(x=>print(x+" "))
    }
}

object Solution extends App {
  val in = scala.io.Source.stdin.getLines()
  val n = in.next().toInt
  val array = Array.ofDim[Boolean](2000002)
  array(0) = true
  array(1) = true
  (2 to 2000001).foreach { i =>
    if (!array(i)) {
      var j = 2 * i
      while (j <= 2000001) {
        array(j) = true
        j += i
      }
    }
  }
  println(array.indices.filter(i => !array(i)).take(n).mkString(" "))
}

object B extends App {

  def readString = Console.readLine
  def readInts = readString.split(" ").map(_.toInt)

  val n = readString.toInt

  val LIMIT = 1300000
  val prime = Array.fill(LIMIT)(true)
  prime(0) = false

  Stream.from(2).takeWhile(i => i*i < LIMIT).filter(prime(_)).foreach { i =>
    (i*i until LIMIT by i).foreach(prime(_) = false)
  }
  val primes = prime.indices.filter(prime(_)).take(n + 1)

  println(primes.drop(1).mkString(" "))
}

object Solution extends App {
  val in = scala.io.Source.stdin.getLines()
  val n = in.next().toInt
  val array = Array.ofDim[Boolean](1000002)
  array(0) = true
  array(1) = true
  (2 to 1000001).foreach { i =>
    if (!array(i)) {
      var j = 2 * i
      while (j <= 1000001) {
        array(j) = true
        j += i
      }
    }
  }
  println(array.indices.filter(i => !array(i)).take(n).mkString(" "))
}

import java.util.Scanner
import java.io.PrintWriter
import java.util.Arrays.binarySearch
import scala.annotation.tailrec
import scala.collection.mutable
import scala.collection.mutable.ListBuffer
import scala.collection.mutable.ArrayBuffer
import scala.util.Random
import scala.util.control.Breaks._

object P327B extends App {

  object PrimeNumber {
    def apply(n: Int = 1000000): Array[Int] = sieve(n)

    def sieve(n: Int): Array[Int] = {
      val primes = new ArrayBuffer[Int]
      val isPrime = Array.fill(n + 1)(true)

      @tailrec
      def loop(i: Int): Unit = {

        @tailrec
        def innerLoop(j: Int): Unit = {
          if (j > n) ()
          else {
            isPrime(j) = false
            innerLoop(j + i)
          }
        }

        if (i > n) ()
        else {
          if (isPrime(i)) {
            primes += i
            innerLoop(i * 2)
          }
          loop(i + 1)
        }
      }

      loop(2)
      primes.toArray
    }
  }

  val sc = new Scanner(System.in)
  val out = new PrintWriter(System.out)
  out.println(PrimeNumber(1000000).take(sc.nextInt).mkString(" "))
  out.close
}

import java.util.Scanner
import scala.math._
import scala.collection.mutable.ListBuffer

object R327_B extends App {
  val sc = new Scanner(System.in)
  val n = sc.nextInt()

  println(answer(n).mkString(" "))

  def answer(n:Int):Seq[Int] = {
    var list = new ListBuffer[Int]()
    var s = 10000000 - n
    list.append(s)
    while(s < 10000000){
      s += 1
      list.append(s)
    }
    //println(s)
    list
  }

}

import java.util.Scanner
import scala.math._
import scala.collection.mutable.ListBuffer

object R327_B extends App {
  val sc = new Scanner(System.in)
  val n = sc.nextInt()

  println(answer(n).mkString(" "))

  def answer(n:Int):Seq[Int] = {
    var list = new ListBuffer[Int]()
    var c = 10000000
    var s = 10000000 - n
    list.append(c)
    while(s < 10000000){
      s += 1
      list.append(s)
    }
    list
  }

}

import java.util.Scanner
import scala.math._
import scala.collection.mutable.ListBuffer

object R327_B extends App {
  val sc = new Scanner(System.in)
  val n = sc.nextInt()

  println(answer(n).mkString(" "))

  def answer(n:Int):Seq[Int] = {
    var list = new ListBuffer[Int]()
    var c = 10000000
    list.append(c)
    while(list.size < n){
      c -= 1
      //if(!list.exists(_ % c == 0)){
        list.append(n)
      //}else{
      //  println(c)
      //}
    }
    list.reverse
  }

}


object A extends App {
  import scala.io.StdIn._

  val target = "abacaba"

  val t = readInt()

  (0 until t).foreach { _ =>
    val n  = readInt()
    val sn = readLine()

    def check(from: Int): Boolean = {
      val kn = sn.patch(from, target, target.length)
      kn.indexOfSlice(target) == kn.lastIndexOfSlice(target)
    }

    val ans = sn
      .sliding(7, 1)
      .zipWithIndex
      .collect {
        case (s, i) if s.corresponds(target) { case ('?', _) => true; case (x, y) => x == y } => i
      }
      .collectFirst {
        case from if check(from) => from
      }

    ans match {
      case None => println("NO")
      case Some(i) =>
        val res = sn.patch(i, target, target.length).map { case '?' => 'd'; case c => c }
        println("YES")
        println(res)
    }
  }
}

object A {import InOut._
  def main(args: Array[String]): Unit = {
val target = "abacaba"
    for (_ <- 1 to nextInt) {
      val n = nextInt
      val s = nextLine

      val candidates = s.sliding(target.length).toArray
      val poss = candidates.indices.filter {
        p =>
          val c = candidates(p)
          var ok = true
          for (i <- 0 until target.length) {
            if (c(i) != '?' && c(i) != target(i)) {
              ok = false
            }
          }
          ok
      }

      var res = ""

      for (pos <- poss) {
        val c = candidates(pos)
        val s2 = s.take(pos) + target + s.drop(pos + target.length)
        val p1 = s2.indexOf(target)
        val p2 = s2.lastIndexOf(target)
//        println(pos, s2, p1, p2)
        if (p1 == p2) res = s2
      }

      if (res == "") {
        out.println("No")
      } else {
        out.println("Yes")
        out.println(res.replace('?', 'd'))
      }
    }

    out.flush()
  }

  final object InOut {
    val in = new java.io.BufferedReader(new java.io.InputStreamReader(System.in))
    val out = new java.io.PrintWriter(System.out, false)
    private[this] var tokenizer: java.util.StringTokenizer = _
    def nextToken: String = {
      while (tokenizer == null || !tokenizer.hasMoreTokens)
        tokenizer = new java.util.StringTokenizer(in.readLine)
      tokenizer.nextToken
    }
    def nextInt = Integer.parseInt(nextToken)
    def nextLong = java.lang.Long.parseLong(nextToken)
    def nextBig = BigInt(nextToken)
    def nextInts(n: Int) = Array.fill(n) { nextInt }
    def nextLongs(n: Int) = Array.fill(n) { nextLong }
    def nextBigs(n: Int) = Array.fill(n) { nextBig }
    def nextLine = in.readLine
  }
}

object A extends App {
  import scala.io.StdIn._

  val target = "abacaba"

  val t = readInt()

  (0 until t).foreach { _ =>
    val n  = readInt()
    val sn = readLine()

    def check(from: Int): Boolean = {
      val sm = sn.slice(from, from + 7)

      if (sm.corresponds(target) { case ('?', _) => true; case (x, y) => x == y }) {
        val kn = sn.patch(from, target, target.length)
        kn.indexOfSlice(target) == kn.lastIndexOfSlice(target)
      } else false
    }

    val ans = (0 until n).collectFirst { case i if check(i) => i }

    ans match {
      case None => println("NO")
      case Some(i) =>
        val res = sn.patch(i, target, target.length).map { case '?' => 'd'; case c => c }
        println("YES")
        println(res)
    }
  }
}

object A extends App {
  import scala.io.StdIn._

  val target = "abacaba"

  val t = readInt()

  (0 until t).foreach { _ =>
    val n  = readInt()
    val sn = readLine()

    def check(from: Int): Boolean = {
      val sm = sn.slice(from, from + 7)

      if (sm.corresponds(target) { case ('?', _) => true; case (x, y) => x == y }) {
        val kn = sn.patch(from, target, target.length)
        kn.indexOfSlice(target, 0.max(from - 7)) == kn.lastIndexOfSlice(target, n.max(from + 7))
      } else false
    }

    val ans = (0 until n).collectFirst { case i if check(i) => i }

    ans match {
      case None => println("NO")
      case Some(i) =>
        val res = sn.patch(i, target, target.length).map { case '?' => 'd'; case c => c }
        println("YES")
        println(res)
    }
  }
}

object A extends App {
  import scala.io.StdIn._

  val abc = "abacaba"

  val t = readInt()

  (0 until t).foreach { _ =>
    val n  = readInt()
    val sn = readLine()

    val ls = sn
      .sliding(7, 1)
      .zipWithIndex
      .collect {
        case (s, i) if s.corresponds(abc) { case ('?', _) => true; case (x, y) => x == y } =>
          Some((s.indices.collect { case j if s(j) == '?' => i + j + 2 * abc(j) }.toList, i))
      }
      .toStream

    val l = ls match {
      case Stream() => None
      case _ =>
        ls.reduce[Option[(List[Int], Int)]] {
          case (None, Some(l))                  => Some(l)
          case (Some((Nil, _)), Some((Nil, _))) => None
          case (Some((Nil, i)), _)              => Some(Nil, i)
          case (_, Some((Nil, i)))              => Some(Nil, i)
          case (Some((is, i)), Some((js, j))) =>
            if (is.length > js.length) Some((js, j))
            else if (js.length > is.length) Some((is, i))
            else if (is.containsSlice(js)) None
            else Some((is, i))
        }
    }

    // format: off
    val ans = l.map { case (_, i) =>
      sn.zipWithIndex.map {
        case (_, j) if i <= j && j <= i + 6 => abc(j - i)
        case ('?', _)                       => 'd'
        case (c, _)                         => c
      }.mkString("")
    }
    // format: on

    ans match {
      case None        => println("NO")
      case Some(value) => println(s"YES\n$value")
    }
  }
}

object A extends App {
  import scala.io.StdIn._

  val abc = "abacaba"

  val t = readInt()

  (0 until t).foreach { _ =>
    val n  = readInt()
    val sn = readLine()

    val ans = sn
      .sliding(7, 1)
      .zipWithIndex
      .collect {
        case (s, i) if s.corresponds(abc) { case ('?', _) => true; case (x, y) => x == y } =>
          (s.indices.collect { case j if s(j) == '?' => i + j + abc(j) }.toList, i)
      } // format: off
      .reduceOption[(List[Int], Int)] {
        case ((_, -1), _) | (_, (_, -1)) => (Nil, -1)
        case ((Nil, _), (Nil, _))        => (Nil, -1)
        case ((Nil, l), _)               => (Nil, l)
        case (_, (Nil, r))               => (Nil, r)
        case ((ls, l), (rs, r))          =>
          if (ls.containsSlice(rs)) {
            if (ls.length > rs.length) (rs, r)
            else if (ls.length < rs.length) (ls, l)
            else (Nil, -1)
          } else (ls, l)
      }
      .flatMap {
        case (_, -1) => None
        case (_, i)  =>
          val res = sn.zipWithIndex.map {
            case (_, j) if i <= j && j <= i + 6 => abc(j - i)
            case ('?', _)                       => 'd'
            case (c, _)                         => c
          }.mkString("")

          Some(res)
      } // format: on

    ans match {
      case None        => println("NO")
      case Some(value) => println(s"YES\n$value")
    }
  }
}

object A extends App {
  import scala.io.StdIn._

  val abc = "abacaba"

  val t = readInt()

  (0 until t).foreach { _ =>
    val n  = readInt()
    val sn = readLine()

    val rs = sn
      .sliding(7, 1)
      .zipWithIndex
      .collect {
        case (s, i) if s.corresponds(abc) { case ('?', _) => true; case (x, y) => x == y } =>
          (s.indices.collect { case j if s(j) == '?' => i + j + abc(j) }.toList, i)
      }
      .toSeq

    val r = rs.foldLeft[Either[Option[String], (List[Int], Int)]](Left(Some("ok"))) {
      case (x @ Left(None), _)         => x
      case (Left(_), x)                => Right(x)
      case (Right((Nil, _)), (Nil, _)) => Left(None)
      case (x @ Right((Nil, _)), _)    => x
      case (_, x @ (Nil, _))           => Right(x)
      case (x @ Right((rs, r)), y @ (ls, l)) =>
        if (rs.length < ls.length) x
        else if (ls.length < rs.last) Right(y)
        else if (rs.containsSlice(ls)) Left(Some("ok"))
        else x

    }

    val ans = r match {
      case Left(_) => None
      case Right((_, i)) =>
        val res = sn.zipWithIndex
          .map {
            case (_, j) if i <= j && j <= i + 6 => abc(j - i)
            case ('?', _)                       => 'd'
            case (c, _)                         => c
          }
          .mkString("")

        Some(res)
    }

    ans match {
      case None        => println("NO")
      case Some(value) => println(s"YES\n$value")
    }
  }
}

object A extends App {
  import scala.io.StdIn._

  val abc = "abacaba"

  val t = readInt()

  (0 until t).foreach { _ =>
    val n  = readInt()
    val sn = readLine()

    val ls = sn
      .sliding(7, 1)
      .zipWithIndex
      .collect {
        case (s, i) if s.corresponds(abc) { case ('?', _) => true; case (x, y) => x == y } =>
          Some((s.indices.collect { case j if s(j) == '?' => i + j + abc(j) }.toList, i))
      }
      .toStream

    val l = ls match {
      case Stream() => None
      case _ =>
        ls.reduce[Option[(List[Int], Int)]] {
          case (None, Some(l))                  => Some(l)
          case (Some((Nil, _)), Some((Nil, _))) => None
          case (Some((Nil, i)), _)              => Some(Nil, i)
          case (_, Some((Nil, i)))              => Some(Nil, i)
          case (Some((is, _)), Some((js, j)))   =>
            if (is.containsSlice(js) || js.containsSlice(is)) None else Some((js, j))
        }
    }

    val ans = l.map {
      case (_, i) =>
        sn.zipWithIndex
          .map {
            case (_, j) if i <= j && j <= i + 6 => abc(j - i)
            case ('?', _)                       => 'd'
            case (c, _)                         => c
          }
          .mkString("")
    }

    ans match {
      case None        => println("NO")
      case Some(value) => println(s"YES\n$value")
    }
  }
}

object A extends App {
  import scala.io.StdIn._

  val abc = "abacaba"

  val t = readInt()

  (0 until t).foreach { _ =>
    val n  = readInt()
    val sn = readLine()

    val ls = sn
      .sliding(7, 1)
      .zipWithIndex
      .collect {
        case (s, i) if s.corresponds(abc) { case ('?', _) => true; case (x, y) => x == y } =>
          Some((s.indices.collect { case j if s(j) == '?' => i + j + abc(j) }.toList, i))
      }
      .toSeq

    val status = ls match {
      case Stream() => None
      case _ =>
        ls.reduce[Option[(List[Int], Int)]] {
          case (None, Some(l))                  => Some(l)
          case (Some((Nil, _)), Some((Nil, _))) => None
          case (Some((Nil, i)), _)              => Some(Nil, i)
          case (_, Some((Nil, i)))              => Some(Nil, i)
          case (Some((is, _)), Some((js, j)))   => if (is.containsSlice(js)) None else Some((js, j))
        }
    }

    val ans = status.map {
      case (_, i) =>
        sn.zipWithIndex
          .map {
            case (_, j) if i <= j && j <= i + 6 => abc(j - i)
            case ('?', _)                       => 'd'
            case (c, _)                         => c
          }
          .mkString("")
    }

    ans match {
      case None        => println("NO")
      case Some(value) => println(s"YES\n$value")
    }
  }
}

object A extends App {
  import scala.io.StdIn._

  val abc = "abacaba"

  val t = readInt()

  (0 until t).foreach { _ =>
    val n  = readInt()
    val sn = readLine()

    val ls = sn
      .sliding(7, 1)
      .zipWithIndex
      .collect {
        case (s, i) if s.corresponds(abc) { case ('?', _) => true; case (x, y) => x == y } =>
          Some((s.indices.collect { case j if s(j) == '?' => i + j + abc(j) }.toList, i))
      }
      .toStream

    val l = ls match {
      case Stream() => None
      case _ =>
        ls.reduce[Option[(List[Int], Int)]] {
          case (None, Some(l))                  => Some(l)
          case (Some((Nil, _)), Some((Nil, _))) => None
          case (Some((Nil, i)), _)              => Some(Nil, i)
          case (_, Some((Nil, i)))              => Some(Nil, i)
          case (Some((is, i)), Some((js, j))) =>
            if (is.length > js.length) Some((js, j))
            else if (js.length > is.length) Some((is, i))
            else if (is.containsSlice(js)) None
            else Some((is, i))
        }
    }

    val ans = l.map {
      case (_, i) =>
        sn.zipWithIndex
          .map {
            case (_, j) if i <= j && j <= i + 6 => abc(j - i)
            case ('?', _)                       => 'd'
            case (c, _)                         => c
          }
          .mkString("")
    }

    ans match {
      case None        => println("NO")
      case Some(value) => println(s"YES\n$value")
    }
  }
}

object A extends App {
  import scala.io.StdIn._

  val abc = "abacaba"

  val t = readInt()

  (0 until t).foreach { _ =>
    val n  = readInt()
    val sn = readLine()

    val ls = sn
      .sliding(7, 1)
      .zipWithIndex
      .collect {
        case (s, i) if s.corresponds(abc) { case ('?', _) => true; case (x, y) => x == y } =>
          Some((s.indices.collect { case j if s(j) == '?' => i + j + 2 * abc(j) }.toList, i))
      }
      .toStream

    val status = ls match {
      case Stream() => None
      case _ =>
        ls.reduce[Option[(List[Int], Int)]] {
          case (None, Some(l))                  => Some(l)
          case (Some((Nil, _)), Some((Nil, _))) => None
          case (Some((Nil, i)), _)              => Some(Nil, i)
          case (_, Some((Nil, i)))              => Some(Nil, i)
          case (Some((is, _)), Some((js, j)))   => if (is.containsSlice(js)) None else Some((js, j))
        }
    }

    val ans = status.map {
      case (_, i) =>
        sn.zipWithIndex
          .map {
            case (_, j) if i <= j && j <= i + 6 => abc(j - i)
            case ('?', _)                       => 'd'
            case (c, _)                         => c
          }
          .mkString("")
    }

    ans match {
      case None        => println("NO")
      case Some(value) => println(s"YES\n$value")
    }
  }
}


import scala.collection.mutable
import scala.collection.mutable.ArrayBuffer
import scala.io.StdIn
import scala.util.Sorting

object Main {
  final val V = 1 << 20;
  final val B = 600
  def main(args: Array[String]) {
    val start = System.currentTimeMillis()
    val Array(n, m, k) = StdIn.readLine().split(" ").map(_.toInt)
    val a = StdIn.readLine().split(" ").map(_.toInt).scan(0)((x, y) => x ^ y)
    val qs = new Array[Query](m)
    for (i <- 0 until m) {
      val Array(l, r) = StdIn.readLine().split(" ").map(_.toInt)
      qs(i) = Query(l - 1, r, i)
    }
    Sorting.quickSort(qs)(new Ordering[Query] {
      override def compare(x: Query, y: Query): Int = {
        if (x.l / B != y.l / B) (x.l / B) compare (y.l / B) else (x.r) compare (y.r)
      }
    })
    val ans = Array.fill(m)(0L)
    var p = 0
    var q = 0
    var s = 0L
    val ct = Array.fill(V)(0)
    ct(0) += 1
    for (Query(l, r, i) <- qs) {
      while (q < r) {
        q += 1
        s += ct(a(q) ^ k)
        ct(a(q)) += 1
      }
      while (p > l) {
        p -= 1
        s += ct(a(p) ^ k)
        ct(a(p)) += 1
      }
      while (q > r) {
        ct(a(q)) -= 1
        s -= ct(a(q) ^ k)
        q -= 1
      }
      while (p < l) {
        ct(a(p)) -= 1
        s -= ct(a(p) ^ k)
        p += 1
      }
      ans(i) = s
    }
    println(ans.mkString("\n"))
  }
  case class Query(val l: Int, val r: Int, val i: Int) {}
}

import scala.collection.mutable
import scala.collection.mutable.ArrayBuffer
import scala.io.StdIn
import scala.util.Sorting

object Main {
  final val V = 1 << 20;
  final val B = 600
  def main(args: Array[String]) {
    val start = System.currentTimeMillis()
    val Array(n, m, k) = StdIn.readLine().split(" ").map(_.toInt)
    val a = StdIn.readLine().split(" ").map(_.toInt).scan(0)((x, y) => x ^ y)
    val qs = new Array[Query](m)
    for (i <- 0 until m) {
      val Array(l, r) = StdIn.readLine().split(" ").map(_.toInt)
      qs(i) = Query(l - 1, r, i)
    }
    Sorting.quickSort(qs)(new Ordering[Query] {
      override def compare(x: Query, y: Query): Int = {
        if (x.l / B != y.l / B) (x.l / B) compare (y.l / B) else (x.r) compare (y.r)
      }
    })
    val ans = Array.fill(m)(0L)
    var p = 0
    var q = 0
    var s = 0L
    val ct = Array.fill(V)(0)
    ct(0) += 1
    for (Query(l, r, i) <- qs) {
      while (q < r) {
        q += 1
        ct(a(q)) += 1
        s += ct(a(q) ^ k)
      }
      while (p > l) {
        p -= 1
        ct(a(p)) += 1
        s += ct(a(p) ^ k)
      }
      while (q > r) {
        s -= ct(a(q) ^ k)
        ct(a(q)) -= 1
        q -= 1
      }
      while (p < l) {
        s -= ct(a(p) ^ k)
        ct(a(p)) -= 1
        p += 1
      }
      ans(i) = s - (if (k == 0) (r - l) else 0)
    }
    println(ans.mkString("\n"))
  }
  case class Query(val l: Int, val r: Int, val i: Int) {}
}

import scala.collection.mutable
import scala.collection.mutable.ArrayBuffer
import scala.io.StdIn
import scala.util.Sorting

object Main {
  final val V = 1 << 20;
  final val B = 300
  def main(args: Array[String]) {
    val Array(n, m, k) = StdIn.readLine().split(" ").map(_.toInt)
    val a = StdIn.readLine().split(" ").map(_.toInt)
    val qs = new Array[Query](m)
    for (i <- 0 until m) {
      val Array(l, r) = StdIn.readLine().split(" ").map(_.toInt - 1)
      qs(i) = Query(l, r, i)
    }
    Sorting.quickSort(qs)(new Ordering[Query] {
      override def compare(x: Query, y: Query): Int = {
        if (x.l / B != y.l / B) (x.l / B) compare (y.l / B) else (x.r) compare (y.r)
      }
    })
    val ans = Array.fill(m)(0L)
    var p = 0
    var q = -1
    var ls, rs = 0
    var s = 0L
    val ct = mutable.HashMap[Int, Long]().withDefault(_ => 0)
    ct(0) = 1
    for (Query(l, r, i) <- qs) {
      while (q < r) {
        q += 1
        rs ^= a(q)
        ct(rs) += 1
        s += ct(rs ^ k)
      }
      while (p > l) {
        p -= 1
        ls ^= a(p)
        ct(ls) += 1
        s += ct(ls ^ k)
      }
      while (q > r) {
        s -= ct(rs ^ k)
        ct(rs) -= 1
        rs ^= a(q)
        q -= 1
      }
      while (p < l) {
        s -= ct(ls ^ k)
        ct(ls) -= 1
        ls ^= a(p)
        p += 1
      }
      ans(i) = s
      println(i, s)
    }
    println(ans.mkString("\n"))
  }
  case class Query(val l: Int, val r: Int, val i: Int) {}
}

import scala.collection.mutable
import scala.collection.mutable.ArrayBuffer
import scala.io.StdIn
import scala.util.Sorting

object Main {
  final val V = 1 << 20;
  final val B = 300
  def main(args: Array[String]) {
    val Array(n, m, k) = StdIn.readLine().split(" ").map(_.toInt)
    val a = StdIn.readLine().split(" ").map(_.toInt).scan(0)((x, y) => x ^ y)
    val qs = new Array[Query](m)
    for (i <- 0 until m) {
      val Array(l, r) = StdIn.readLine().split(" ").map(_.toInt)
      qs(i) = Query(l - 1, r, i)
    }
    Sorting.quickSort(qs)(new Ordering[Query] {
      override def compare(x: Query, y: Query): Int = {
        if (x.l / B != y.l / B) (x.l / B) compare (y.l / B) else (x.r) compare (y.r)
      }
    })
    val ans = Array.fill(m)(0L)
    var p = 0
    var q = 0
    var s = 0L
    val ct = mutable.HashMap[Int, Long]().withDefault(_ => 0)
    for (Query(l, r, i) <- qs) {
      while (q < r) {
        q += 1
        ct(a(q)) += 1
        s += ct(a(q) ^ k)
      }
      while (p > l) {
        p -= 1
        ct(a(p)) += 1
        s += ct(a(p) ^ k)
      }
      while (q > r) {
        s -= ct(a(q) ^ k)
        ct(a(q)) -= 1
        q -= 1
      }
      while (p < l) {
        s -= ct(a(p) ^ k)
        ct(a(p)) -= 1
        p += 1
      }
      ans(i) = s
    }
    println(ans.mkString("\n"))
  }
  case class Query(val l: Int, val r: Int, val i: Int) {}
}

import scala.collection.mutable
import scala.collection.mutable.ArrayBuffer
import scala.io.StdIn
import scala.util.Sorting

object Main {
  final val V = 1 << 20;
  final val B = 300
  def main(args: Array[String]) {
    val Array(n, m, k) = StdIn.readLine().split(" ").map(_.toInt)
    val a = StdIn.readLine().split(" ").map(_.toInt)
    val qs = new Array[Query](m)
    for (i <- 0 until m) {
      val Array(l, r) = StdIn.readLine().split(" ").map(_.toInt - 1)
      qs(i) = Query(l, r, i)
    }
    Sorting.quickSort(qs)(new Ordering[Query] {
      override def compare(x: Query, y: Query): Int = {
        if (x.l / B != y.l / B) (x.l / B) compare (y.l / B) else (x.r) compare (y.r)
      }
    })
    val ans = Array.fill(m)(0L)
    var p = 0
    var q = -1
    var ls, rs = 0
    var s = 0L
    val ct = mutable.HashMap[Int, Long]().withDefault(_ => 0)
    ct(0) = 1
    for (Query(l, r, i) <- qs) {
      while (q < r) {
        q += 1
        rs ^= a(q)
        ct(rs) += 1
        s += ct(rs ^ k)
      }
      while (p > l) {
        p -= 1
        ls ^= a(p)
        ct(ls) += 1
        s += ct(ls ^ k)
      }
      while (q > r) {
        s -= ct(rs ^ k)
        ct(rs) -= 1
        rs ^= a(q)
        q -= 1
      }
      while (p < l) {
        s -= ct(ls ^ k)
        ct(ls) -= 1
        ls ^= a(p)
        p += 1
      }
      ans(i) = s
    }
    println(ans.mkString("\n"))
  }
  case class Query(val l: Int, val r: Int, val i: Int) {}
}

import scala.collection.mutable
import scala.collection.mutable.ArrayBuffer
import scala.io.StdIn
import scala.util.Sorting

object Main {
  final val V = 1 << 20;
  final val B = 300
  def main(args: Array[String]) {
    val Array(n, m, k) = StdIn.readLine().split(" ").map(_.toInt)
    val a = StdIn.readLine().split(" ").map(_.toInt).scan(0)((x, y) => x ^ y)
    val qs = new Array[Query](m)
    for (i <- 0 until m) {
      val Array(l, r) = StdIn.readLine().split(" ").map(_.toInt)
      qs(i) = Query(l - 1, r, i)
    }
    Sorting.quickSort(qs)(new Ordering[Query] {
      override def compare(x: Query, y: Query): Int = {
        if (x.l / B != y.l / B) (x.l / B) compare (y.l / B) else (x.r) compare (y.r)
      }
    })
    val ans = Array.fill(m)(0L)
    var p = 0
    var q = 0
    var s = 0L
    val ct = mutable.HashMap[Int, Long]().withDefault(_ => 0)
    ct(0) = 1
    for (Query(l, r, i) <- qs) {
      while (q < r) {
        q += 1
        ct(a(q)) += 1
        s += ct(a(q) ^ k)
      }
      while (p > l) {
        p -= 1
        ct(a(p)) += 1
        s += ct(a(p) ^ k)
      }
      while (q > r) {
        s -= ct(a(q) ^ k)
        ct(a(q)) -= 1
        q -= 1
      }
      while (p < l) {
        s -= ct(a(p) ^ k)
        ct(a(p)) -= 1
        p += 1
      }
      ans(i) = s
    }
    println(ans.mkString("\n"))
  }
  case class Query(val l: Int, val r: Int, val i: Int) {}
}

import scala.io.StdIn

object Main {
  final val V = 1 << 20;
  def main(args: Array[String]) {
    val Array(n, m, k) = StdIn.readLine().split(" ").map(_.toInt)
    val a = StdIn.readLine().split(" ").map(_.toInt)
    val qs = Array.fill(m)((0, 0))
    for (i <- 0 until m) {
      val Array(l, r) = StdIn.readLine().split(" ").map(_.toInt - 1)
      qs(i) = (l, r)
    }
    val ctl, ctr = Array.fill(n)(0L)
    val tbl = Array.fill(V)(0L)
    val sum = Array.fill(n)(0)
    tbl(0) = 1
    var s = 0L
    var t = 0
    for (i <- 0 until n) {
      t ^= a(i)
      sum(i) = t
      ctr(i) = tbl(t ^ k)
      s += tbl(t ^ k)
      tbl(t) += 1
    }
    for (i <- 0 until V) tbl(i) = 0
    t = 0
    tbl(0) = 1
    for (i <- n - 1 to 0 by -1) {
      t ^= a(i)
      ctl(i) = tbl(t ^ k)
      tbl(t) += 1
    }
    for (i <- 1 until n) {
      ctl(i) += ctl(i - 1)
    }
    for (i <- n - 2 to 0 by -1) {
      ctr(i) += ctr(i + 1)
    }
    val ans = Array.fill(m)(0L)
    for (((l, r), i) <- qs.zipWithIndex) {
      ans(i) = s
      if (l > 0) ans(i) -= ctl(l - 1)
      if (r < n - 1) ans(i) -= ctr(r + 1)
      if (l > 0) ans(i) += (if ((sum(r) ^ sum(l - 1)) == k) 1L else 0L)
    }
    println(ans.mkString("\n"))
  }
}

import scala.collection.mutable
import scala.collection.mutable.ArrayBuffer
import scala.io.StdIn
import scala.util.Sorting

object Main {
  final val V = 1 << 20;
  final val B = 300
  def main(args: Array[String]) {
    val Array(n, m, k) = StdIn.readLine().split(" ").map(_.toInt)
    val a = StdIn.readLine().split(" ").map(_.toInt)
    val qs = new Array[Query](m)
    for (i <- 0 until m) {
      val Array(l, r) = StdIn.readLine().split(" ").map(_.toInt - 1)
      qs(i) = Query(l, r, i)
    }
    Sorting.quickSort(qs)(new Ordering[Query] {
      override def compare(x: Query, y: Query): Int = {
        if (x.l / B != y.l / B) (x.l / B) compare (y.l / B) else (x.r) compare (y.r)
      }
    })
    val ans = Array.fill(m)(0L)
    var p = 0
    var q = -1
    var ls, rs = 0
    var s = 0L
    val ct = mutable.HashMap[Int, Long]().withDefault(_ => 0)
    ct(0) = 1
    for (Query(l, r, i) <- qs) {
      while (q < r) {
        q += 1
        rs ^= a(q)
        ct(rs) += 1
        s += ct(rs ^ k)
      }
      while (p > l) {
        ls ^= a(p)
        p -= 1
        ct(ls) += 1
        s += ct(ls ^ k)
      }
      while (q > r) {
        s -= ct(rs ^ k)
        ct(rs) -= 1
        rs ^= a(q)
        q -= 1
      }
      while (p < l) {
        s -= ct(ls ^ k)
        ct(ls) -= 1
        p += 1
        ls ^= a(p)
      }
      ans(i) = s
    }
    println(ans.mkString("\n"))
  }
  case class Query(val l: Int, val r: Int, val i: Int) {}
}


object CF_527_3_C {
  def solve(n: Int, ss: Seq[String]): String = {
    val pairs: Map[Int, Seq[(String, Int)]] = ss.zipWithIndex.groupBy(_._1.length)
    // Strategy: Look at longest two to give 2 possible strings
    val possibles: Seq[String] = pairs(n - 1) match {
      case Seq((a, _), (b, _)) => Seq(a + b.last, b + a.last)
    }

    //
    def isPrefix(pre: String, s: String) = s.take(pre.length) == pre

    def isSuffix(suff: String, s: String) = s.takeRight(suff.length) == suff

    // Seqs of values starting from longest
    val strs: Seq[Seq[(String, Int)]] = pairs.values.toSeq

    def isValid(test: String, ps: Seq[Seq[(String, Int)]], out: Seq[(String, Int)]): Option[Seq[(String, Int)]] = ps match {
      case Seq() => Some(out)
      case Seq((n1, i), (n2, j)) +: tail =>
        if (isPrefix(n1, test) && isSuffix(n2, test)) isValid(test, tail, out :+ ("P", i) :+ ("S", j))
        else if (isPrefix(n2, test) && isSuffix(n1, test))
          isValid(test, tail, out :+ ("S", i) :+ ("P", j))
        else None
    }

    val result: String = possibles.map(p => isValid(p, strs, Nil)).find(_.isDefined).get.get.sortBy(_._2).map(_._1).mkString

    result
  }

//     ~~~ Specify Input and Output formats here:

  def formatIn(i: Input) = (i.int, {i.nextLine; i.getLines})
  def formatOut(out: String): String = out.toString

//     ~~~ Boilerplate & utility methods that don't change: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

  def main(args: Array[String]) = {
    val out = new java.io.PrintWriter(System.out)
    val resultStr = new Input(System.in).solveStr
    out.println(resultStr)
    out.close()
  }

  import java.util.Scanner
  class Input(sc: Scanner) {
    def this(i: java.io.InputStream) = this(new Scanner(i))
    def this(s: String) = this(new Scanner(s.stripMargin))
    def int = sc.nextInt()
    def long = sc.nextLong()
    def double = sc.nextDouble()
    def nextLine = sc.nextLine()
    // Remember to call nextLine to advance past the newline character (if required) before collecting the line:
    def collect[T](f: String => T) = {sc.nextLine().split(" ").toVector.map(f)}
    def intSeq = collect(_.toInt)
    def doubleSeq = collect(_.toDouble)
    def getLines: Vector[String] = if (!sc.hasNextLine) Vector.empty else sc.nextLine +: getLines
    def solveVal = (solve _).tupled(formatIn(this))
    def solveStr = formatOut(solveVal)
  }

  def ceil(a: Int, b: Int) = (a - 1) / b + 1
  def ceil(a: Long, b: Long) = (a - 1) / b + 1
  val modulo = 1000000007

  import language.implicitConversions
  implicit def stringToInput(s: String): Input = new Input(s)
  implicit class makeTupledWorkOnFunction1[-T,+R](f: T => R) { def tupled: T => R = x => f(x) }
}

object Main {
  def main(args: Array[String]): Unit = {
    val s = new Main()
    s.solve()
    s.out.flush()
  }
}

class Main {
  import java.io._
  import java.util.StringTokenizer

  import scala.collection.mutable
  import scala.util.Sorting
  import math.{abs, max, min}
  import mutable.{ArrayBuffer, ListBuffer}
  import scala.reflect.ClassTag

  val MOD = 1000000007
  val out = new PrintWriter(System.out)

  def solve(): Unit = {
    val N = ni()
    val S = map(2 * N - 2) { _ => ns() }

    val grouped = S.zipWithIndex.groupBy(_._1.length)
    val ans = Array.ofDim[Char](S.length)
    def make(len: Int, prefix: String, suffix: String): Boolean = {
      if (len == 0) true
      else {
        val Array((s1, i1), (s2, i2)) = grouped(len)

        if (prefix.startsWith(s1) && suffix.endsWith(s2)) {
          ans(i1) = 'P'
          ans(i2) = 'S'
          make(len - 1, prefix, suffix)

        } else if (prefix.startsWith(s2) && suffix.endsWith(s1)) {
          ans(i1) = 'S'
          ans(i2) = 'P'
          make(len - 1, prefix, suffix)

        } else {
          // この割り振りは間違っていた
          false
        }
      }
    }

    val s1 = grouped(N - 1)(0)._1
    val s2 = grouped(N - 1)(1)._1
    if (make(N - 1, s1, s2)) {
      out.println(ans.mkString)
    } else {
      make(N - 1, s2, s1)
      out.println(ans.mkString)
    }
  }

  class InputReader(val stream: InputStream) {
    private val reader = new BufferedReader(new InputStreamReader(stream), 32768)
    private var tokenizer: StringTokenizer = _

    def next(): String = {
      while (tokenizer == null || !tokenizer.hasMoreTokens)
        tokenizer = new StringTokenizer(reader.readLine)
      tokenizer.nextToken
    }

    def nextInt(): Int = next().toInt
    def nextLong(): Long = next().toLong
    def nextChar(): Char = next().charAt(0)
  }
  val sc = new InputReader(System.in)
  def ni(): Int = sc.nextInt()
  def nl(): Long = sc.nextLong()
  def nc(): Char = sc.nextChar()
  def ns(): String = sc.next()
  def ns(n: Int): Array[Char] = ns().toCharArray
  def na(n: Int, offset: Int = 0): Array[Int] = map(n)(_ => ni() + offset)
  def na2(n: Int, offset: Int = 0): (Array[Int], Array[Int]) = {
    val A1, A2 = Array.ofDim[Int](n)
    REP(n) { i =>
      A1(i) = ni() + offset
      A2(i) = ni() + offset
    }
    (A1, A2)
  }
  def nm(n: Int, m: Int): Array[Array[Int]] = {
    val A = Array.ofDim[Int](n, m)
    REP(n) { i =>
      REP(m) { j =>
        A(i)(j) = ni()
      }
    }
    A
  }
  def nal(n: Int): Array[Long] = map(n)(_ => nl())
  def nm_c(n: Int, m: Int): Array[Array[Char]] = map(n) (_ => ns(m))
  def REP(n: Int, offset: Int = 0)(f: Int => Unit): Unit = {
    var i = offset
    val N = n + offset
    while(i < N) { f(i); i += 1 }
  }
  def REP_r(n: Int, offset: Int = 0)(f: Int => Unit): Unit = {
    var i = n - 1 + offset
    while(i >= offset) { f(i); i -= 1 }
  }

  def map[@specialized A: ClassTag](n: Int, offset: Int = 0)(f: Int => A): Array[A] = {
    val res = Array.ofDim[A](n)
    REP(n)(i => res(i) = f(i + offset))
    res
  }

  def sumL(as: Array[Int]): Long = {
    var s = 0L
    REP(as.length)(i => s += as(i))
    s
  }

  def cumSum(as: Array[Int]) = {
    val cum = Array.ofDim[Long](as.length + 1)
    REP(as.length) { i =>
      cum(i + 1) = cum(i) + as(i)
    }
    cum
  }
}

object Main {
  def main(args: Array[String]): Unit = {
    val s = new Main()
    s.solve()
    s.out.flush()
  }
}

class Main {
  import java.io._
  import java.util.StringTokenizer

  import scala.collection.mutable
  import scala.util.Sorting
  import math.{abs, max, min}
  import mutable.{ArrayBuffer, ListBuffer}
  import scala.reflect.ClassTag

  val MOD = 1000000007
  val out = new PrintWriter(System.out)

  def solve(): Unit = {
    val N = ni()
    val S = map(2 * N - 2) { _ => ns() }
    val sorted = S.sorted

    def mkPrefix(S1: Array[String]) = {
      var ok = true
      var ix = 0
      REP(S1.length - 1) { i =>
        ok &&= S1(i + 1).startsWith(S1(i))
        if (ok) ix = i
      }
      S1(ix + 1)
    }

    val prefix = mkPrefix(Array("") ++ sorted)
//    val suffix = mkPrefix(Array("") ++ sorted.reverse)

    val cnt = Array.ofDim[Int](N)

    val ans = map(S.length) { i =>
      if (prefix.startsWith(S(i))) {
        cnt(S(i).length) += 1
        if (cnt(S(i).length) == 1) 'P'
        else 'S'
      } else 'S'
    }.mkString

    out.println(ans)
  }

  class InputReader(val stream: InputStream) {
    private val reader = new BufferedReader(new InputStreamReader(stream), 32768)
    private var tokenizer: StringTokenizer = _

    def next(): String = {
      while (tokenizer == null || !tokenizer.hasMoreTokens)
        tokenizer = new StringTokenizer(reader.readLine)
      tokenizer.nextToken
    }

    def nextInt(): Int = next().toInt
    def nextLong(): Long = next().toLong
    def nextChar(): Char = next().charAt(0)
  }
  val sc = new InputReader(System.in)
  def ni(): Int = sc.nextInt()
  def nl(): Long = sc.nextLong()
  def nc(): Char = sc.nextChar()
  def ns(): String = sc.next()
  def ns(n: Int): Array[Char] = ns().toCharArray
  def na(n: Int, offset: Int = 0): Array[Int] = map(n)(_ => ni() + offset)
  def na2(n: Int, offset: Int = 0): (Array[Int], Array[Int]) = {
    val A1, A2 = Array.ofDim[Int](n)
    REP(n) { i =>
      A1(i) = ni() + offset
      A2(i) = ni() + offset
    }
    (A1, A2)
  }
  def nm(n: Int, m: Int): Array[Array[Int]] = {
    val A = Array.ofDim[Int](n, m)
    REP(n) { i =>
      REP(m) { j =>
        A(i)(j) = ni()
      }
    }
    A
  }
  def nal(n: Int): Array[Long] = map(n)(_ => nl())
  def nm_c(n: Int, m: Int): Array[Array[Char]] = map(n) (_ => ns(m))
  def REP(n: Int, offset: Int = 0)(f: Int => Unit): Unit = {
    var i = offset
    val N = n + offset
    while(i < N) { f(i); i += 1 }
  }
  def REP_r(n: Int, offset: Int = 0)(f: Int => Unit): Unit = {
    var i = n - 1 + offset
    while(i >= offset) { f(i); i -= 1 }
  }

  def map[@specialized A: ClassTag](n: Int, offset: Int = 0)(f: Int => A): Array[A] = {
    val res = Array.ofDim[A](n)
    REP(n)(i => res(i) = f(i + offset))
    res
  }

  def sumL(as: Array[Int]): Long = {
    var s = 0L
    REP(as.length)(i => s += as(i))
    s
  }

  def cumSum(as: Array[Int]) = {
    val cum = Array.ofDim[Long](as.length + 1)
    REP(as.length) { i =>
      cum(i + 1) = cum(i) + as(i)
    }
    cum
  }
}

object Main {
  def main(args: Array[String]): Unit = {
    val s = new Main()
    s.solve()
    s.out.flush()
  }
}

class Main {
  import java.io._
  import java.util.StringTokenizer

  import scala.collection.mutable
  import scala.util.Sorting
  import math.{abs, max, min}
  import mutable.{ArrayBuffer, ListBuffer}
  import scala.reflect.ClassTag

  val MOD = 1000000007
  val out = new PrintWriter(System.out)

  def solve(): Unit = {
    val N = ni()
    val S = map(2 * N - 2) { _ => ns() }
    val S1 = "" +: S
    Sorting.quickSort(S1)

    var ok = true
    var ix = 0
    REP(S1.length - 1) { i =>
      ok &&= S1(i + 1).startsWith(S1(i))
      if (ok) ix = i
    }
    val prefix = S1(ix + 1)
    val ans = map(S.length) { i =>
      if (prefix.startsWith(S(i))) 'P'
      else 'S'
    }.mkString

    out.println(ans)
  }

  class InputReader(val stream: InputStream) {
    private val reader = new BufferedReader(new InputStreamReader(stream), 32768)
    private var tokenizer: StringTokenizer = _

    def next(): String = {
      while (tokenizer == null || !tokenizer.hasMoreTokens)
        tokenizer = new StringTokenizer(reader.readLine)
      tokenizer.nextToken
    }

    def nextInt(): Int = next().toInt
    def nextLong(): Long = next().toLong
    def nextChar(): Char = next().charAt(0)
  }
  val sc = new InputReader(System.in)
  def ni(): Int = sc.nextInt()
  def nl(): Long = sc.nextLong()
  def nc(): Char = sc.nextChar()
  def ns(): String = sc.next()
  def ns(n: Int): Array[Char] = ns().toCharArray
  def na(n: Int, offset: Int = 0): Array[Int] = map(n)(_ => ni() + offset)
  def na2(n: Int, offset: Int = 0): (Array[Int], Array[Int]) = {
    val A1, A2 = Array.ofDim[Int](n)
    REP(n) { i =>
      A1(i) = ni() + offset
      A2(i) = ni() + offset
    }
    (A1, A2)
  }
  def nm(n: Int, m: Int): Array[Array[Int]] = {
    val A = Array.ofDim[Int](n, m)
    REP(n) { i =>
      REP(m) { j =>
        A(i)(j) = ni()
      }
    }
    A
  }
  def nal(n: Int): Array[Long] = map(n)(_ => nl())
  def nm_c(n: Int, m: Int): Array[Array[Char]] = map(n) (_ => ns(m))
  def REP(n: Int, offset: Int = 0)(f: Int => Unit): Unit = {
    var i = offset
    val N = n + offset
    while(i < N) { f(i); i += 1 }
  }
  def REP_r(n: Int, offset: Int = 0)(f: Int => Unit): Unit = {
    var i = n - 1 + offset
    while(i >= offset) { f(i); i -= 1 }
  }

  def map[@specialized A: ClassTag](n: Int, offset: Int = 0)(f: Int => A): Array[A] = {
    val res = Array.ofDim[A](n)
    REP(n)(i => res(i) = f(i + offset))
    res
  }

  def sumL(as: Array[Int]): Long = {
    var s = 0L
    REP(as.length)(i => s += as(i))
    s
  }

  def cumSum(as: Array[Int]) = {
    val cum = Array.ofDim[Long](as.length + 1)
    REP(as.length) { i =>
      cum(i + 1) = cum(i) + as(i)
    }
    cum
  }
}

object Main {
  def main(args: Array[String]): Unit = {
    val s = new Main()
    s.solve()
    s.out.flush()
  }
}

class Main {
  import java.io._
  import java.util.StringTokenizer

  import scala.collection.mutable
  import scala.util.Sorting
  import math.{abs, max, min}
  import mutable.{ArrayBuffer, ListBuffer}
  import scala.reflect.ClassTag

  val MOD = 1000000007
  val out = new PrintWriter(System.out)

  def solve(): Unit = {
    val N = ni()
    val S = map(2 * N - 2) { _ => ns() }

    val grouped = S.zipWithIndex.groupBy(_._1.length)

    val prefix = grouped(N - 1)(0)._1
    val suffix = grouped(N - 1)(1)._1

    val ans = Array.ofDim[Char](S.length)
    grouped.foreach { case (_, as) =>
      val Array((s1, i1), (s2, i2)) = as
      if (prefix.startsWith(s1) && suffix.startsWith(s2)) {
        ans(i1) = 'P'
        ans(i2) = 'S'
      } else {
        ans(i2) = 'P'
        ans(i1) = 'S'
      }
    }

    out.println(ans.mkString)
  }

  class InputReader(val stream: InputStream) {
    private val reader = new BufferedReader(new InputStreamReader(stream), 32768)
    private var tokenizer: StringTokenizer = _

    def next(): String = {
      while (tokenizer == null || !tokenizer.hasMoreTokens)
        tokenizer = new StringTokenizer(reader.readLine)
      tokenizer.nextToken
    }

    def nextInt(): Int = next().toInt
    def nextLong(): Long = next().toLong
    def nextChar(): Char = next().charAt(0)
  }
  val sc = new InputReader(System.in)
  def ni(): Int = sc.nextInt()
  def nl(): Long = sc.nextLong()
  def nc(): Char = sc.nextChar()
  def ns(): String = sc.next()
  def ns(n: Int): Array[Char] = ns().toCharArray
  def na(n: Int, offset: Int = 0): Array[Int] = map(n)(_ => ni() + offset)
  def na2(n: Int, offset: Int = 0): (Array[Int], Array[Int]) = {
    val A1, A2 = Array.ofDim[Int](n)
    REP(n) { i =>
      A1(i) = ni() + offset
      A2(i) = ni() + offset
    }
    (A1, A2)
  }
  def nm(n: Int, m: Int): Array[Array[Int]] = {
    val A = Array.ofDim[Int](n, m)
    REP(n) { i =>
      REP(m) { j =>
        A(i)(j) = ni()
      }
    }
    A
  }
  def nal(n: Int): Array[Long] = map(n)(_ => nl())
  def nm_c(n: Int, m: Int): Array[Array[Char]] = map(n) (_ => ns(m))
  def REP(n: Int, offset: Int = 0)(f: Int => Unit): Unit = {
    var i = offset
    val N = n + offset
    while(i < N) { f(i); i += 1 }
  }
  def REP_r(n: Int, offset: Int = 0)(f: Int => Unit): Unit = {
    var i = n - 1 + offset
    while(i >= offset) { f(i); i -= 1 }
  }

  def map[@specialized A: ClassTag](n: Int, offset: Int = 0)(f: Int => A): Array[A] = {
    val res = Array.ofDim[A](n)
    REP(n)(i => res(i) = f(i + offset))
    res
  }

  def sumL(as: Array[Int]): Long = {
    var s = 0L
    REP(as.length)(i => s += as(i))
    s
  }

  def cumSum(as: Array[Int]) = {
    val cum = Array.ofDim[Long](as.length + 1)
    REP(as.length) { i =>
      cum(i + 1) = cum(i) + as(i)
    }
    cum
  }
}

object Main {
  def main(args: Array[String]): Unit = {
    val s = new Main()
    s.solve()
    s.out.flush()
  }
}

class Main {
  import java.io._
  import java.util.StringTokenizer

  import scala.collection.mutable
  import scala.util.Sorting
  import math.{abs, max, min}
  import mutable.{ArrayBuffer, ListBuffer}
  import scala.reflect.ClassTag

  val MOD = 1000000007
  val out = new PrintWriter(System.out)

  def solve(): Unit = {
    val N = ni()
    val S = map(2 * N - 2) { _ => ns() }
    val sorted = S.sorted

    def mkPrefix(S1: Array[String]) = {
      var ok = true
      var ix = 0
      REP(S1.length - 1) { i =>
        ok &&= S1(i + 1).startsWith(S1(i))
        if (ok) ix = i
      }
      S1(ix + 1)
    }

    val prefix = mkPrefix(Array("") ++ sorted)
    val suffix = mkPrefix(Array("") ++ sorted.reverse)

    val grouped = S.zipWithIndex.groupBy(_._1.length)
    val ans = Array.ofDim[Char](S.length)
    grouped.foreach { case (_, as) =>
      val Array((s1, i1), (s2, i2)) = as
      if (prefix.startsWith(s1) && suffix.startsWith(s2)) {
        ans(i1) = 'P'
        ans(i2) = 'S'
      } else {
        ans(i2) = 'P'
        ans(i1) = 'S'
      }
    }

    out.println(ans.mkString)
  }

  class InputReader(val stream: InputStream) {
    private val reader = new BufferedReader(new InputStreamReader(stream), 32768)
    private var tokenizer: StringTokenizer = _

    def next(): String = {
      while (tokenizer == null || !tokenizer.hasMoreTokens)
        tokenizer = new StringTokenizer(reader.readLine)
      tokenizer.nextToken
    }

    def nextInt(): Int = next().toInt
    def nextLong(): Long = next().toLong
    def nextChar(): Char = next().charAt(0)
  }
  val sc = new InputReader(System.in)
  def ni(): Int = sc.nextInt()
  def nl(): Long = sc.nextLong()
  def nc(): Char = sc.nextChar()
  def ns(): String = sc.next()
  def ns(n: Int): Array[Char] = ns().toCharArray
  def na(n: Int, offset: Int = 0): Array[Int] = map(n)(_ => ni() + offset)
  def na2(n: Int, offset: Int = 0): (Array[Int], Array[Int]) = {
    val A1, A2 = Array.ofDim[Int](n)
    REP(n) { i =>
      A1(i) = ni() + offset
      A2(i) = ni() + offset
    }
    (A1, A2)
  }
  def nm(n: Int, m: Int): Array[Array[Int]] = {
    val A = Array.ofDim[Int](n, m)
    REP(n) { i =>
      REP(m) { j =>
        A(i)(j) = ni()
      }
    }
    A
  }
  def nal(n: Int): Array[Long] = map(n)(_ => nl())
  def nm_c(n: Int, m: Int): Array[Array[Char]] = map(n) (_ => ns(m))
  def REP(n: Int, offset: Int = 0)(f: Int => Unit): Unit = {
    var i = offset
    val N = n + offset
    while(i < N) { f(i); i += 1 }
  }
  def REP_r(n: Int, offset: Int = 0)(f: Int => Unit): Unit = {
    var i = n - 1 + offset
    while(i >= offset) { f(i); i -= 1 }
  }

  def map[@specialized A: ClassTag](n: Int, offset: Int = 0)(f: Int => A): Array[A] = {
    val res = Array.ofDim[A](n)
    REP(n)(i => res(i) = f(i + offset))
    res
  }

  def sumL(as: Array[Int]): Long = {
    var s = 0L
    REP(as.length)(i => s += as(i))
    s
  }

  def cumSum(as: Array[Int]) = {
    val cum = Array.ofDim[Long](as.length + 1)
    REP(as.length) { i =>
      cum(i + 1) = cum(i) + as(i)
    }
    cum
  }
}


import scala.collection.mutable
import scala.io.StdIn

object Hotelier extends App {

  StdIn.readLine()

  val n = 10
  val events = StdIn.readLine()

  val rooms = mutable.Buffer[Int]()
  rooms ++= Seq.fill(n)(0)

  events.foreach {
    case 'R' => rooms.update(rooms.lastIndexOf(0), 1)
    case 'L' => rooms.update(rooms.indexOf(0), 1)
    case num => rooms(Integer.parseInt(num.toString)) = 0
  }

  println(rooms.mkString(""))
}

object A {

def main(args: Array[String]): Unit = {}

  @inline def tokenizeLine = new java.util.StringTokenizer(scala.io.StdIn.readLine)
  def readInts(n: Int) = { val tl = tokenizeLine; Array.fill(n)(tl.nextToken.toInt) }
  def readLongs(n: Int) = { val tl = tokenizeLine; Array.fill(n)(tl.nextToken.toLong) }
  def readBigs(n: Int) = { val tl = tokenizeLine; Array.fill(n)(BigInt(tl.nextToken)) }

  val Array(n) = readInts(1)
  val s = readLine
  val rooms = Array.fill(10)(0)

  for (c <- s) {
    c match {
      case 'L' =>
        var i = 0
        while (rooms(i) == 1) i += 1
        rooms(i) = 1
      case 'R' =>
        var i = 9
        while (rooms(i) == 1) i -= 1
        rooms(i) = 1
      case _ =>
        rooms(c - '0') = 0
    }
  }

  println(rooms.mkString)

  Console.flush
}

import java.io.BufferedReader

object Main {

  type RoomStatus = Boolean
  type Rooms = java.util.BitSet

  val FREE = false
  val OCCUPIED = true
  val MAX = 10

  def roomsToString(rooms: Rooms): String = {
    (for (i <- Range(0, MAX)) yield {
      if (rooms.get(i) == FREE) '0' else '1'
    }).mkString
  }

  def result(input: Stream[Char]): Rooms = {
    val rooms: Rooms = new Rooms(MAX)

    input.foreach {

      case 'L' =>
        val freeIndex = rooms.nextClearBit(0)
        rooms.set(freeIndex, OCCUPIED)
        rooms
      case 'R' =>
        val freeIndex = rooms.previousClearBit(MAX - 1)
        rooms.set(freeIndex, OCCUPIED)
        rooms
      case room =>
        rooms.set(room - '0', FREE)
        rooms

    }

    rooms
  }

  def main(args: Array[String]) = {
    val input: BufferedReader = Console.in
    val length = input.readLine().toInt
    if (length != 0) {
      var read = 0
      val buf = new Array[Char](1)
      val ops = Stream
        .continually {
          read += 1
          input.read(buf)
        }
        .takeWhile(bufRead => bufRead > 0 && read <= length)
        .map {
          _ => buf(0)
        }

      Console.out.write(roomsToString(result(ops)).getBytes)
    }

  }
}

import java.io.BufferedReader

object Main2 {

  sealed trait Input

  case object L extends Input

  case object R extends Input

  case class Leave(roomNo: Byte) extends Input

  type RoomStatus = Boolean
  type Rooms = Vector[RoomStatus]

  val FREE = false
  val OCCUPIED = true
  val ALL_EMPTY: Rooms = Vector.fill(10)(FREE)

  def handle(rooms: Rooms, input: Input): Rooms = input match {
    case L =>
      val freeIndex = rooms.indexOf(FREE)
      rooms.updated(freeIndex, OCCUPIED)
    case R =>
      val freeIndex = rooms.lastIndexOf(FREE)
      rooms.updated(freeIndex, OCCUPIED)
    case Leave(roomNo) =>
      rooms.updated(roomNo, FREE)
  }

  def roomsToString(rooms: Rooms): String = {
    rooms.map {
      case FREE => '0'
      case OCCUPIED => '1'
    }.mkString
  }

  def result(input: Stream[Char]): Rooms = {
    input.map {
      case 'L' => L
      case 'R' => R
      case c if c >= '0' && c <= '9' => Leave(Seq(c).mkString.toByte)
    }.foldLeft(ALL_EMPTY)(handle)
  }

  def main(args: Array[String]) = {
    val input: BufferedReader = Console.in
    val length = input.readLine().toInt
    if (length != 0) {
      var read = 0
      val buf = new Array[Char](1)
      val ops = Stream
        .continually {
          read += 1
          input.read(buf)
        }
        .takeWhile(bufRead => bufRead > 0 && read <= length)
        .map {
          _ => buf(0)
        }

      Console.out.write(roomsToString(result(ops)).getBytes)
    }

  }
}

/**
  * Created by lilisun on 8/12/19.
  */
import scala.io.StdIn.readLine
object cf578 {

  def PA():Unit = {
    val n = readLine().toInt
    val line = readLine()
    val room = Array.fill(10)(0)
    line foreach {
      case 'L' => (0 until 10).dropWhile(i => room(i) == 1).headOption match {
        case None => {}
        case Some(i) => room(i) = 1
      }
      case 'R' => (0 until 10).reverse.dropWhile(i => room(i) == 1).headOption match {
        case None => {}
        case Some(i) => room(i) = 1
      }
      case ch => room(ch - '0') = 0
    }
    println(room.toList.mkString)
  }
  def main(args: Array[String]): Unit = {
    PA()
  }
}

import scala.io.StdIn._

object A_1200 extends App {
  val n = readInt()
  val A = readLine()
  var S = Array.ofDim[Boolean](10)

  A.foreach { x =>
    if (x == 'L') {
      var left = 0
      while (S(left)) left += 1
      S(left) = true
      left += 1
    } else if (x == 'R') {
      var right = 9
      while (S(right)) right -= 1
      S(right) = true
      right -= 1
    } else {
      val xx = ("" + x).toInt
      S(xx) = false
    }
  }

  println(
    S.map(x => if (x) 1 else 0).mkString
  )
}

object A {

def main(args: Array[String]): Unit = {

  @inline def tokenizeLine = new java.util.StringTokenizer(scala.io.StdIn.readLine)
  def readInts(n: Int) = { val tl = tokenizeLine; Array.fill(n)(tl.nextToken.toInt) }
  def readLongs(n: Int) = { val tl = tokenizeLine; Array.fill(n)(tl.nextToken.toLong) }
  def readBigs(n: Int) = { val tl = tokenizeLine; Array.fill(n)(BigInt(tl.nextToken)) }

  val Array(n) = readInts(1)
  val s = readLine
  val rooms = Array.fill(10)(0)

  for (c <- s) {
    c match {
      case 'L' =>
        var i = 0
        while (rooms(i) == 1) i += 1
        rooms(i) = 1
      case 'R' =>
        var i = 9
        while (rooms(i) == 1) i -= 1
        rooms(i) = 1
      case _ =>
        rooms(c - '0') = 0
    }
  }

  println(rooms.mkString)

  Console.flush
}
}

object A extends App {

  @inline def tokenizeLine = new java.util.StringTokenizer(scala.io.StdIn.readLine)
  def readInts(n: Int) = { val tl = tokenizeLine; Array.fill(n)(tl.nextToken.toInt) }

  val Array(n) = readInts(1)
  val s = readLine
  val rooms = Array.fill(10)(0)

  for (c <- s) {
    c match {
      case 'L' =>
        var i = 0
        while (rooms(i) == 1) i += 1
        rooms(i) = 1
      case 'R' =>
        var i = 9
        while (rooms(i) == 1) i -= 1
        rooms(i) = 1
      case _ =>
        rooms(c - '0') = 0
    }
  }

  println(rooms.mkString)

  Console.flush
}

import scala.collection.convert.ImplicitConversionsToScala._

object AMega extends App {

  val MaxRoom = 9
  val n = readLine.toInt
  val rooms = new java.util.TreeMap[Integer, Integer]
  if (MaxRoom == 999999) rooms.put(0, MaxRoom)

  val readCommand: Unit => String = if (MaxRoom == 9) { val l = readLine.sliding(1); _ => l.next } else { _ => readLine }

  for (_ <- 1 to n) {
    readCommand() match {
      case "L" =>
        val goTo = rooms.getOrDefault(0, -1) + 1
        val nextKey = goTo + 1
        val right: Integer = if (rooms.containsKey(nextKey)) rooms.remove(nextKey) else goTo
        rooms.put(0, right)
      case "R" =>
        if (rooms.isEmpty) rooms.put(MaxRoom, MaxRoom)
        else {
          val lastKey = rooms.lastKey
          val goTo = if (rooms.get(lastKey) == MaxRoom) {
            rooms.remove(lastKey)
            lastKey - 1
          } else MaxRoom
          val prevKey = rooms.floorKey(goTo)
          val left: Integer = if (prevKey != null && rooms.get(prevKey) == goTo - 1) prevKey else goTo
          rooms.put(left, MaxRoom)
        }
      case s =>
        val pos = s.toInt
        val left = rooms.floorKey(pos)
        val right = rooms.remove(left)
        if (left < pos) rooms.put(left, pos - 1)
        if (right > pos) rooms.put(pos + 1, right)
    }
  }

  val result = Array.fill[Byte](MaxRoom + 1)(0)

  for (entry <- rooms.entrySet()) {
    for (i <- entry.getKey.toInt to entry.getValue) result(i) = 1
  }

  Console.setOut(new java.io.BufferedOutputStream(Console.out))
  println(result.mkString)
  Console.flush
}

object A extends App {

  @inline def tokenizeLine = new java.util.StringTokenizer(scala.io.StdIn.readLine)
  def readInts(n: Int) = { val tl = tokenizeLine; Array.fill(n)(tl.nextToken.toInt) }
  def readLongs(n: Int) = { val tl = tokenizeLine; Array.fill(n)(tl.nextToken.toLong) }
  def readBigs(n: Int) = { val tl = tokenizeLine; Array.fill(n)(BigInt(tl.nextToken)) }

  val Array(n) = readInts(1)
  val s = readLine
  val rooms = Array.fill(10)(0)

  for (c <- s) {
    c match {
      case 'L' =>
        var i = 0
        while (rooms(i) == 1) i += 1
        rooms(i) = 1
      case 'R' =>
        var i = 9
        while (rooms(i) == 1) i -= 1
        rooms(i) = 1
      case _ =>
        rooms(c - '0') = 0
    }
  }

  println(rooms.mkString)

  Console.flush
}


import scala.io.StdIn.readLine
object CF extends App{
val t = readLine().toArray
val p = readLine().toArray
val a = readLine().split(" ").map(_.toInt - 1)

val rank = Array.fill(a.length)(0)
for( i <- 0 until a.length)
    rank(a(i)) = i

val newt: Array[Char] = Array.fill(t.length)(0)

def getNewt(n: Int) = {
    for(i <- 0 until t.length){
        if(rank(i) > n) newt(i) = t(i)
        else newt(i) = 0
    }
}

def isComposable(): Boolean = {
    var j = 0
    for(i <- 0 until newt.length){
        if(newt.length - i < p.length - j) return false
        if(newt(i) == p(j)) j+=1
        if(j==p.length) return true
    }
    return false
}

var lo = 0
var hi = t.length - p.length + 1
var mid = (hi+lo) / 2

while(lo < hi){
    getNewt(mid)
    //println(f"$hi $lo $mid " + newt.mkString(""))
    if(isComposable()) lo = mid+1
    else hi = mid
    mid = (hi+lo) / 2
}

println(hi)
}

import scala.io.StdIn.readLine
object CF extends App{
val t = readLine().toArray
val p = readLine().toArray
val a = readLine().split(" ").map(_.toInt - 1)

val rank = Array.fill(a.length)(0)
for( i <- 0 until a.length)
    rank(a(i)) = i

def isComposable(n: Int): Boolean = {
    var j = 0
    for(i <- 0 until t.length){
        if(rank(i) > n) {
            if(t.length - i < p.length - j) return false
            if(t(i) == p(j)) j+=1
            if(j==p.length) return true
        }
    }
    return false
}

var lo = 0
var hi = t.length - p.length + 1
var mid = (hi+lo) / 2

while(lo < hi){
    //println(f"$hi $lo $mid " + newt.mkString(""))
    if(isComposable(mid)) lo = mid+1
    else hi = mid
    mid = (hi+lo) / 2
}

println(hi)
}

//package solutions

import java.io.PrintWriter
import java.util.Scanner

/**
  * @author traff
  */

object SolTaskD extends App {
  override def main(args: Array[String]): Unit = {
    val out = new PrintWriter(System.out)

    run(new Scanner(System.in), out)

    out.close()
  }

  def filter(s: String, a: Array[Int], n: Int): String = {
    var ss = new StringBuffer(s)
    for (i <- 0 until n) {
      ss.setCharAt(a(i)-1, 0)
    }

    ss.toString.filter(_ != 0)
  }

  def check(s1: String, s2: String): Boolean = {
    var i1 = 0
    var i2 = 0

    while (i1 < s1.length && i2 < s2.length) {
      if (s1(i1) == s2(i2)) {
        i1 += 1
        i2 += 1
      } else {
        i1 += 1
      }
    }

    i2 == s2.length
  }

  def find(l: Int, r: Int, s1: String, s2: String, a: Array[Int]): Int = {
    if (l >= r) {
      l
    } else if (check(filter(s1, a, r), s2)) {
      r
    }
    else {

      var mid = l + (r - l) / 2
      if (mid == l) {
        mid = l + 1
      }

      if (check(filter(s1, a, mid), s2)) {
        find(mid, r, s1, s2, a)
      } else {
        find(l, mid - 1, s1, s2, a)
      }
    }
  }

  def run(s: Scanner, out: PrintWriter): Unit = {
    val p = s.nextLine()
    val t = s.nextLine()

    val a = s.nextLine().split(" ").map(_.toInt)

    out.println(find(0, a.length, p, t, a))
  }

}

object CF extends App{
import scala.io.StdIn.readLine
val t = readLine().toArray
val p = readLine().toArray
val a = readLine().split(" ").map(_.toInt - 1)

val rank = {
    val rank = Array.fill(a.length)(0)
    for( i <- 0 until a.length)
        rank(a(i)) = i
    rank
}

val newt: Array[Char] = Array.fill(t.length)(0)

def getNewt(n: Int) = {
    for(i <- 0 until t.length){
        if(rank(i) > n) newt(i) = t(i)
        else newt(i) = 0
    }
}

def isComposable(): Boolean = {
    var j = 0
    for(i <- 0 until newt.length){
        if(newt.length - i < p.length - j) return false
        if(newt(i) == p(j)) j+=1
        if(j==p.length) return true
    }
    return false
}

var lo = 0
var hi = t.length - p.length + 1
var mid = (hi+lo) / 2

while(lo < hi){
    getNewt(mid)
    //println(f"$hi $lo $mid " + newt.mkString(""))
    if(isComposable()) lo = mid+1
    else hi = mid
    mid = (hi+lo) / 2
}

println(hi)
}

object CF extends App{
import scala.io.StdIn.readLine
val t = readLine().toArray
val p = readLine().toArray
val a = readLine().split(" ").map(_.toInt - 1)

val rank = {
    val rank = Array.fill(a.length)(0)
    for( i <- 0 until a.length)
        rank(a(i)) = i
    rank
}

val newt: Array[Char] = Array.fill(t.length)(0)

def getNewt(n: Int) = {
    for(i <- 0 until t.length){
        if(rank(i) > n) newt(i) = t(i)
        else newt(i) = 0
    }
}

def isComposable(i:Int, j: Int): Boolean = {
    if(i >= t.length) return false
    if(j >= p.length) return true
    if(newt.length - i < p.length - j) return false
    if(newt(i) == p(j) && j==p.length-1) return true
    if(newt(i) == p(j)) return isComposable(i+1, j+1)
    else return isComposable(i+1, j)
}

var lo = 0
var hi = t.length - p.length + 1
var mid = (hi+lo) / 2
var end = false

while(lo < hi){
    getNewt(mid)
    //println(f"$hi $lo $mid " + newt.mkString(""))
    if(isComposable(0, 0)) lo = mid+1
    else hi = mid
    mid = (hi+lo) / 2
}

println(hi)
}

object CF extends App{
import scala.io.StdIn.readLine
val t = readLine().toArray
val p = readLine().toArray
val a = readLine().split(" ").map(_.toInt - 1)

val rank = {
    val rank = Array.fill(a.length)(0)
    for( i <- 0 until a.length)
        rank(a(i)) = i
    rank
}

val newt: Array[Char] = Array.fill(t.length)(0)

def getNewt(n: Int) = {
    for(i <- 0 until t.length){
        if(rank(i) > n) newt(i) = t(i)
        else newt(i) = 0
    }
}

def isComposable(i:Int, j: Int): Boolean = {
    if(i >= t.length) return false
    if(j >= p.length) return true
    if(newt.length - i < p.length - j) return false
    if(newt(i) == p(j) && j==p.length-1) return true
    if(newt(i) == p(j)) return isComposable(i+1, j+1)
    else return isComposable(i+1, j)
}

var lo = 0
var hi = t.length - p.length + 1
var mid = (hi+lo+1) / 2
var end = false

while(lo < hi){
    getNewt(mid)
    //println(f"$hi $lo $mid " + newt.mkString(""))
    if(isComposable(0, 0)) lo = mid
    else hi = mid-1
    mid = (hi+lo+1) / 2
}

println(mid+1)
}


import math._

object Main extends App{
  val s = readLine()
  var maxVal, minVal, curVal = 0
  for (c <- s){
    if (c == '+')
      curVal += 1
    else
      curVal -= 1
    maxVal = max(maxVal, curVal)
    minVal = min(minVal, curVal)
  }
  println(maxVal - minVal)
}

import scala.io.StdIn

object MishapInClub {
  //+ in, - out
  def minNum(l:String):Int={
    var in = 0
    var out = 0
    var minNeeded = 0
    for (a<-0 to l.length()-1){
      if (l(a)=='+'){
        in = in + 1
        if (out==0){
          minNeeded = minNeeded + 1
        }else{
          out = out -1
        }
      }else if (l(a)=='-'){
        out = out + 1
        if (in==0){
          minNeeded = minNeeded + 1
        }else{
          in = in -1
        }
      }
    }
    minNeeded
  }

  def main(args:Array[String]){
    val l = StdIn.readLine()
    println(minNum(l))
  }

}

object Main extends App{
  val s = readLine()
  var maxAbs, curVal = 0
  for (c <- s){
    if (c == '+')
      curVal += 1
    else
      curVal -= 1
    maxAbs = math.max(maxAbs, math.abs(curVal))
  }
  println(maxAbs)
}

import scala.io.StdIn

object MishapInClub {
  //+ in, - out
  def minNum(l:String):Int={

    //net in or net out or consecutive in or consecutive out
    var netIn = 0;
    var netOut = 0;
    var last = ' ';
    var conIn = 0;
    var conOut = 0;
    var conInMax = 0;
    var conOutMax = 0;

    def checkConInMax(a:Int)={
      if (a>=conInMax){
        conInMax = a
      }
    }

    def checkConOutMax(a:Int)={
      if (a>=conOutMax){
        conOutMax = a
      }
    }

    for (a<-0 to l.length()-1){
      if (l(a)=='+'){
        netIn = netIn + 1
        netOut = netOut -1
      }else{
        netOut = netOut + 1
        netIn = netIn -1
      }
      if (l(a)==last){
        if (l(a)=='+'){
          conIn = conIn + 1
          checkConInMax(conIn)
        }else{
          conOut = conOut + 1
          checkConOutMax(conOut)
        }
      }else{
        if (l(a)=='+'){
          checkConInMax(conIn)
          conIn = 1
        }else{
          checkConOutMax(conOut)
          conOut = 1
        }
      }
      last = l(a)
    }

    checkConOutMax(conOut)
    checkConInMax(conIn)
    if (l(l.length()-1)=='+'){
      netOut = netOut + 1
    }
    if (l(l.length()-1)=='-'){
      netIn = netIn + 1
    }

    Math.max(Math.max(netIn, netOut), Math.max(conInMax, conOutMax))
  }

  def main(args:Array[String]){
    val l = StdIn.readLine()
    println(minNum(l))
  }

}

import scala.io.StdIn

object MishapInClub {
  //+ in, - out
  def minNum(l:String):Int={
    //net in or net out or consecutive in or consecutive out
    var netIn = 0;
    var netOut = 0;
    var last = ' ';
    var conIn = 0;
    var conOut = 0;
    for (a<-0 to l.length()-1){
      if (l(a)=='+'){
        netIn = netIn + 1
        netOut = netOut -1
      }else{
        netOut = netOut + 1
        netIn = netIn -1
      }
      if (l(a)==last){
        if (l(a)=='+'){
          conIn = conIn + 1
        }else{
          conOut = conOut + 1
        }
      }else{
        if (l(a)=='+'){
          conIn = 1
        }else{
          conOut = 1
        }
      }
      last = l(a)
    }
    Math.max(Math.max(netIn, netOut), Math.max(conIn, conOut))
  }

  def main(args:Array[String]){
    val l = StdIn.readLine()
    println(minNum(l))
  }

}

import scala.io.StdIn

object MishapInClub {

  def minNum(l:String):Int={
    //net in or net out or consecutive in or consecutive out
    var netIn = 0;
    var netOut = 0;
    var last = l(0)
    var conIn = if (last=='+') 1 else 0
    var conOut = if (last=='-') 1 else 0
    for (a<-0 to l.length()-1){
      if (l(a)=='+'){
        netIn = netIn + 1
        netOut = netOut -1
      }else{
        netOut = netOut + 1
        netIn = netIn -1
      }
      if (a>0 && l(a)==last){
        if (l(a)=='+'){
          conIn = conIn + 1
          conOut = 0
        }else{
          conOut = conOut + 1
          conIn = 0
        }
      }
      last = l(a)
    }
    Math.max(Math.max(netIn, netOut), Math.max(conIn, conOut))
  }

  def main(args:Array[String]){
    val l = StdIn.readLine()
    println(minNum(l))
  }

}

import scala.io.StdIn

object MishapInClub {
  //+ in, - out
  def minNum(l:String):Int={

    //net in or net out or consecutive in or consecutive out
    var netIn = 0;
    var netOut = 0;
    var last = ' ';
    var conIn = 0;
    var conOut = 0;
    var conInMax = 0;
    var conOutMax = 0;

    def checkConInMax(a:Int)={
      if (a>=conInMax){
        conInMax = a
      }
    }

    def checkConOutMax(a:Int)={
      if (a>=conOutMax){
        conOutMax = a
      }
    }

    for (a<-0 to l.length()-1){
      if (l(a)=='+'){
        netIn = netIn + 1
        netOut = netOut -1
      }else{
        netOut = netOut + 1
        netIn = netIn -1
      }
      if (l(a)==last){
        if (l(a)=='+'){
          conIn = conIn + 1
          checkConInMax(conIn)
        }else{
          conOut = conOut + 1
          checkConOutMax(conOut)
        }
      }else{
        if (l(a)=='+'){
          checkConInMax(conIn)
          conIn = 1
        }else{
          checkConOutMax(conOut)
          conOut = 1
        }
      }
      last = l(a)
    }

    checkConOutMax(conOut)
    checkConInMax(conIn)

    Math.max(Math.max(netIn, netOut), Math.max(conInMax, conOutMax))
  }

  def main(args:Array[String]){
    val l = StdIn.readLine()
    println(minNum(l))
  }

}

import scala.io.StdIn

object MishapInClub {
  //+ in, - out
  def minNum(l:String):Int={
    //net in or net out or consecutive in or consecutive out
    var netIn = 0;
    var netOut = 0;
    var last = ' ';
    var conIn = 0;
    var conOut = 0;
    var conInMax = 0;
    var conOutMax = 0;
    for (a<-0 to l.length()-1){
      if (l(a)=='+'){
        netIn = netIn + 1
        netOut = netOut -1
      }else{
        netOut = netOut + 1
        netIn = netIn -1
      }
      if (l(a)==last){
        if (l(a)=='+'){
          conIn = conIn + 1
          if (conIn>conInMax)
            conInMax = conIn
        }else{
          conOut = conOut + 1
          if (conOut>conOutMax)
             conOutMax = conOut
        }
      }else{
        if (l(a)=='+'){
          if (conIn>conInMax)
            conInMax = conIn
          conIn = 1

        }else{
          if (conOut>conOutMax)
            conOutMax = conOut
          conOut = 1
        }
      }
      last = l(a)
    }
    Math.max(Math.max(netIn, netOut), Math.max(conInMax, conOutMax))
  }

  def main(args:Array[String]){
    val l = StdIn.readLine()
    println(minNum(l))
  }

}

import scala.io.StdIn

object MishapInClub {

  def minNum(l:String):Int={
    var plus=0
    var minus=0
    l.foreach { x => if (x=='+') plus=plus+1 else minus=minus+1 }
    Math.abs(plus-minus)
  }

  def main(args:Array[String]){
    val l = StdIn.readLine()
    println(minNum(l))
  }

}