Let's call a number k-good if it contains all digits not exceeding k (0, ..., k). You've got a number k and an array a containing n numbers. Find out how many k-good numbers are in a (count each number every time it occurs in array a).

The first line contains integers n and k (1 ≤ n ≤ 100, 0 ≤ k ≤ 9). The i-th of the following n lines contains integer ai without leading zeroes (1 ≤ ai ≤ 109).

Print a single integer — the number of k-good numbers in a.

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

object P365A extends App {
  val sc = new Scanner(System.in)
  val out = new PrintWriter(System.out)
  val N, K = sc.nextInt
  sc.nextLine

  def solve(): Int = {
    val a0 = List.range(0, K + 1).map(_ + '0')
    List.fill(N)(sc.nextLine).count { s =>
      s.toList.distinct.sortWith(_ < _).take(K + 1) == a0
    }
  }

  out.println(solve)
  out.close
}

/**
 * @author pvasilyev
 * @since 19 Jun 2016
 */
object A365 extends App {

  def checkKGood(num: String, k: Int): Boolean = {
    for (i <- 0 to k) {
      if (!num.contains(i.toString)) {
        return false
      }
    }
    true
  }

  def solve() = {
    val Array(n, k): Array[Int] = scala.io.StdIn.readLine().split(" ").map(_.toInt)
    var answer = 0
    for (i <- 0 until n) {
      val num = scala.io.StdIn.readLine()
      if (checkKGood(num, k)) {
        answer += 1
      }
    }

    println(answer)
  }

  solve()

}

object Main {
  def main(args: Array[String]) {
    val Array(n, k) = readLine().split(" ").map(_.toInt)
    val a = (1 to n).map(_ => readLine())
    val digits = (Set() ++ (0 to k)).map('0' +).map(_.toChar)
    val count = a.foldLeft(0) { (acc, str) =>
      if ((digits &~ str.toSet) == Set()) acc + 1
      else acc
    }
    println(count)
  }
}

import java.util.Scanner
import scala.collection.mutable.HashSet

object GoodNumber extends App {
    val scan = new Scanner(System.in)
    val n = scan.nextInt
    val k = scan.nextInt

    def check(number: Int): Boolean = {
        var set = HashSet[Int]()
        var x = number
        do{
            if(x % 10 <= k) set = set + (x % 10)
            x = x / 10
        } while(x != 0)

        set == (0 to k).toSet
    }

    val ans = {
        for(i <- 0 until n) yield scan.nextInt
    }.toArray.filter(check).size

    println(ans)
}

import scala.util.Sorting
import scala.io.StdIn

object App {

  def main(args: Array[String]) {

    val Array(n, s) = StdIn.readLine().split(" ").map(_.toInt)
    val k = s.toString.head

    println(Range(0,n).count{ p =>
      StdIn.readLine().toCharArray.filter(_ <= k).toSet.size > (k - '0')
    })

  }

}

object Main {
    def main(args : Array[String]) {
        val (n, k) = readLine().split(" ") match {
            case Array(n, k) => (n.toInt, k.toInt)
        }

        var cnt = 0
        for(i <- 1 to n) {
            if(isKNumber(readLine(), k.toString.charAt(0))) {
                cnt += 1
            }
        }

        println(cnt)
    }

    def isKNumber(num : String, k : Character) =
        (num.toCharArray.toSet filter { _ <= k }).size == k.toString.toInt + 1
}

import scala.util.control.Breaks

/**
 * Created with IntelliJ IDEA.
 * User: teots
 * Date: 11/21/13
 * Time: 3:46 PM
 * To change this template use File | Settings | File Templates.
 */
object A {
  def main(args: Array[String]) {
    val line: String = readLine()
    val tokens: Array[String] = line.split(" ")
    val n = Integer.parseInt(tokens(0))
    val k = Integer.parseInt(tokens(1))

    var counter = 0

    val loop = new Breaks
    val loop2 = new Breaks

    for(i <- Range(1, n + 1 ))
    {
      val input : String = readLine()
      var found: Boolean = false

      loop.breakable{
        for (x <- Range(0, k + 1)) {
          found = false
          loop2.breakable {
            for(y <- input)
            {
              if(x == (y - 48))
              {
                found = true
                loop2.break
              }
            }
          }

          if(!found)
          {
             loop.break()
          }
        }

        counter += 1
      }
    }

    println(counter)
  }
}

object Solution365A extends App {

  def solution() {
    val n = _int
    val k = _int
    val count = 1.to(n).map(_ => _string).count(s => {
      0.to(k).forall(d => s.contains("" + d))
    })
    println(count)
  }

  //////////////////////////////////////////////////
  import java.util.Scanner
  val SC: Scanner = new Scanner(System.in)
  def _line: String = SC.nextLine
  def _int: Int = SC.nextInt
  def _long: Long = SC.nextLong
  def _string: String = SC.next
  solution()
}

import java.util.Scanner
import java.net.InetAddress
import java.security.MessageDigest

/**
 * Contest 213, Div 2, problem A
 *
 *
Let's call a number k-good if it contains all digits not
 * exceeding k (0, ..., k). You've got a number k and an array a
 * containing n numbers. Find out how many k-good numbers are in
 * a (count each number every time it occurs in array a).

 */
object Round213_Div2_Task1 {
  val inputScan = {
    val md = MessageDigest.getInstance("SHA-1")
    val userName = System.getProperty("user.name")
    val hostName = InetAddress.getLocalHost.getHostName

    val b = md.digest((userName + hostName).getBytes)
    var result = ""
    for (i ← 0 until b.length)
      result += Integer.toString((b(i) & 0xff) + 0x100, 16).substring(1)

    if (result == "51a302f8ba1abe181e33fe86c0ab4c7bedfb6c91") new Scanner(new java.io.FileInputStream("tmp/0.txt"))
    else new Scanner(System.in)
  }

  def main(args: Array[String]) {
    val scan = inputScan

    val n = scan.nextInt
    val k = scan.nextInt
    scan.nextLine

    var c = 0
    for { ni ← 1 to n } {
      val arr = scan.nextLine.toCharArray.distinct
      if (arr.length >= (k + 1) && (0 to k).forall(p => arr.contains(p + '0')))
        c += 1
    }

    println(c)
  }
}

import java.util.Scanner
import java.net.InetAddress
import java.security.MessageDigest

/**
 * Contest 213, Div 2, problem A
 *
 *
Let's call a number k-good if it contains all digits not
 * exceeding k (0, ..., k). You've got a number k and an array a
 * containing n numbers. Find out how many k-good numbers are in
 * a (count each number every time it occurs in array a).

 */
object Round213_Div2_Task1 {
  val inputScan = {
    val md = MessageDigest.getInstance("SHA-1")
    val userName = System.getProperty("user.name")
    val hostName = InetAddress.getLocalHost.getHostName

    val b = md.digest((userName + hostName).getBytes)
    var result = ""
    for (i ← 0 until b.length)
      result += Integer.toString((b(i) & 0xff) + 0x100, 16).substring(1)

    if (result == "51a302f8ba1abe181e33fe86c0ab4c7bedfb6c91") new Scanner(new java.io.FileInputStream("tmp/0.txt"))
    else new Scanner(System.in)
  }

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

    val n = scan.nextInt
    val k = scan.nextInt
    scan.nextLine

    var c = 0
    val digits = ('0' to ('0' + k).toChar).toArray
    for { ni ← 1 to n } {
      val arr = scan.nextLine.toCharArray.distinct
      if (arr.length >= (k + 1) && digits.forall(arr.contains(_)))
        c += 1
    }

    println(c)
  }
}

object Solution extends App {
  val in = scala.io.Source.stdin.getLines()
  val Array(n, k) = in.next().split(" ").map(_.toInt)
  val ch = k.toString.head
  println(Range(0, n).count { _ =>
    val a = in.next().toSet
    Range(0, k + 1).forall(t => a.contains(t.toString.head))
  })
}

object A365 {

  import IO._
  import collection.{mutable => cu}

  def main(args: Array[String]): Unit = {
    val Array(n, k) = readInts(2)
    var res = (1 to n).count{ _ =>
      val in = read
      in.toSet.count(_ <= k+'0') == k + 1
    }
    out.println(res)
    out.close()
  }

  object IO {
    private val input = new java.io.BufferedReader(new java.io.InputStreamReader(System.in))
    //    private val input = new java.io.BufferedReader(new java.io.InputStreamReader(new java.io.FileInputStream("src/input")))
    val out = new java.io.PrintWriter(System.out)

    @inline def read: String = input.readLine()

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

    def readInt: Int = tokenizeLine.nextToken.toInt

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

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

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

}

import scala.collection._

object A extends App {

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

  val Array(n, k) = readInts(2)
  val as = Array.fill(n)(readLine.map(_ - '0').filter(_ <= k))

  println(as.count(a => a.distinct.size == k + 1))
}

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

object P365A extends App {
  val sc = new Scanner(System.in)
  val out = new PrintWriter(System.out)
  val N, K = sc.nextInt
  sc.nextLine

  def solve(): Int = {
    val a0 = List.range(0, K + 1).map(_ + '0')
    List.fill(N)(sc.nextLine).count { s =>
      s.toList.distinct.take(K + 1).sortWith(_ < _) == a0
    }
  }

  out.println(solve)
  out.close
}

object Main {
  def main(args: Array[String]) {
    val Array(n, k) = readLine().split(" ").map(_.toInt)
    val a = (1 to n).map(_ => readLine())
    val digits = (Set() ++ (0 to k)).map('0' +).map(_.toChar)
    val count = a.foldLeft(0) { (acc, str) =>
      if ((str.toSet &~ digits) == Set() && (digits &~ str.toSet) == Set()) acc + 1
      else acc
    }
    println(count)
  }
}

object Main {
  def main(args: Array[String]) {
    val Array(n, k) = readLine().split(" ").map(_.toInt)
    val a = (1 to n).map(_ => readLine())
    val digits =
      if (k != 0) (Set() ++ (0 to k)).map('0' +).map(_.toChar)
      else Set('0', '1')
    val count = a.foldLeft(0) { (acc, str) =>
      if ((str.toSet &~ digits) == Set() && (digits &~ str.toSet) == Set()) acc + 1
      else acc
    }
    println(count)
  }
}

import java.util.Scanner
import scala.collection.mutable.HashSet

object GoodNumber extends App {
    val scan = new Scanner(System.in)
    val n = scan.nextInt
    val k = scan.nextInt

    def check(number: Int): Boolean = {
        var set = HashSet[Int]()
        var x = number
        do{
            set = set + (x % 10)
            x = x / 10
        } while(x != 0)

        set == (0 to k).toSet
    }

    val ans = {
        for(i <- 0 until n) yield scan.nextInt
    }.toArray.filter(check).size

    println(ans)
}

import math._
import scala.util._
import java.util.Scanner

object Task1 {
  def main(args: Array[String]) {
    val scan = new Scanner(System.in)
    //val scan = new Scanner(new java.io.FileInputStream("tmp/0.txt"))
    val n = scan.nextInt
    val k = scan.nextInt
    scan.nextLine

    var c = 0
    for { ni <- 1 to n } {
      val arr = scan.nextLine.toCharArray
      if (arr.length == k + 1 && arr.forall(p => p - '0' <= k))
        c += 1
    }

    println(c)
  }
}

//package com.myltsev.codeforces.round213

import java.util.Scanner
import java.net.InetAddress
import java.security.MessageDigest

object Task1 {
  val inputScan = {
    val md = MessageDigest.getInstance("SHA-1")
    val userName = System.getProperty("user.name")
    val hostName = InetAddress.getLocalHost.getHostName

    val b = md.digest((userName + hostName).getBytes)
    var result = ""
    for (i ← 0 until b.length)
      result += Integer.toString((b(i) & 0xff) + 0x100, 16).substring(1)

    if (result == "51a302f8ba1abe181e33fe86c0ab4c7bedfb6c91") new Scanner(new java.io.FileInputStream("tmp/0.txt"))
    else new Scanner(System.in)
  }

  def main(args: Array[String]) {
    val scan = inputScan

    val n = scan.nextInt
    val k = scan.nextInt
    scan.nextLine

    var c = 0
    for { ni ← 1 to n } {
      val arr = scan.nextLine.toCharArray.distinct
      if (arr.length == (k + 1) && arr.forall(p ⇒ (p - '0') <= k))
        c += 1
    }

    println(c)
  }
}

import math._
import scala.util._
import java.util.Scanner

object Task1 {
  def main(args: Array[String]) {
    val scan = new Scanner(System.in)
    //val scan = new Scanner(new java.io.FileInputStream("tmp/0.txt"))
    val n = scan.nextInt
    val k = scan.nextInt
    scan.nextLine

    var c = 0
    for { ni <- 1 to n } {
      val arr = scan.nextLine.toCharArray.distinct
      if (arr.length == (k + 1) && arr.forall(p => (p - '0') <= k))
        c += 1
    }

    println(c)
  }
}

import math._
import scala.util._
import java.util.Scanner

object Task1 {
  def main(args: Array[String]) {
    val scan = new Scanner(System.in)
    //val scan = new Scanner(new java.io.FileInputStream("tmp/0.txt"))
    val n = scan.nextInt
    val k = scan.nextInt
    scan.nextLine

    var c = 0
    for { ni <- 1 to n } {
      val arr = scan.nextLine.toCharArray.distinct
      if (arr.length == k + 1 && arr.forall(p => p - '0' <= k))
        c += 1
    }

    println(c)
  }
}

import math._
import scala.util._
import java.util.Scanner

object Task1 {
  def main(args: Array[String]) {
    val scan = new Scanner(System.in)
    //val scan = new Scanner(new java.io.FileInputStream("tmp/0.txt"))
    val n = scan.nextInt
    val k = scan.nextInt
    scan.nextLine

    var c = 0
    for { ni <- 1 to n } {
      if (scan.nextLine.toCharArray.distinct.length == k + 1)
        c += 1
    }

    println(c)
  }
}

//package com.myltsev.codeforces.round213

import java.util.Scanner
import java.net.InetAddress
//import java.security.MessageDigest

object Task1 {
  val inputScan = {
    //val md = MessageDigest.getInstance("SHA-1")
    val userName = System.getProperty("user.name")
    val hostName = InetAddress.getLocalHost.getHostName

    if (userName + hostName == "alexthe-PCU") new Scanner(new java.io.FileInputStream("tmp/0.txt"))
    else new Scanner(System.in)

//    val b = md.digest((userName + hostName).getBytes)
//    var result = ""
//    for (i ← 0 until b.length)
//      result += Integer.toString((b(i) & 0xff) + 0x100, 16).substring(1)

//    if (result == "51a302f8ba1abe181e33fe86c0ab4c7bedfb6c91") new Scanner(new java.io.FileInputStream("tmp/0.txt"))
//    else new Scanner(System.in)
  }

  def main(args: Array[String]) {
    val scan = inputScan

    val n = scan.nextInt
    val k = scan.nextInt
    scan.nextLine

    var c = 0
    for { ni ← 1 to n } {
      val arr = scan.nextLine.toCharArray.distinct
      if (arr.length == (k + 1) && arr.forall(p ⇒ (p - '0') <= k))
        c += 1
    }

    println(c)
  }
}

// Read inputs from System.in, Write outputs to use print.
// Your class name has to be Solution

import math._
import scala.util._
import java.util.Scanner

object Task1 {
  def main(args: Array[String]) {
    val scan = new Scanner(System.in)
    //val scan = new Scanner(new java.io.FileInputStream("tmp/0.txt"))
    val n = scan.nextInt
    val k = scan.nextInt
    scan.nextLine

    var c = 0
    for { ni <- 1 to n } {
      if (scan.nextLine.forall(x => x - '0' <= k))
        c += 1
    }

    println(c)
  }
}

object Solution extends App {
  val in = scala.io.Source.stdin.getLines()
  val Array(n, k) = in.next().split(" ").map(_.toInt)
  val ch = k.toString.head
  println(Range(0, n).count(_ => in.next().forall(_ <= ch)))
}

object Solution extends App {
  val in = scala.io.Source.stdin.getLines()
  val Array(n, k) = in.next().split(" ").map(_.toInt)
  val ch = k.toString.head
  println(Range(0, n).count{_ =>
    val a = in.next().distinct
    a.length == (k + 1) && a.forall(_ <= ch)})
}

object A365 {

  import IO._
  import collection.{mutable => cu}

  def main(args: Array[String]): Unit = {
    val Array(n, k) = readInts(2)
    var res = (1 to n).count{ _ =>
      val in = read.distinct.sorted
      if(in.length == k+1)
        in.zipWithIndex.forall{case (char, i) => char-'0' == i}
      else
        false
    }
    out.println(res)
    out.close()
  }

  object IO {
    private val input = new java.io.BufferedReader(new java.io.InputStreamReader(System.in))
    //    private val input = new java.io.BufferedReader(new java.io.InputStreamReader(new java.io.FileInputStream("src/input")))
    val out = new java.io.PrintWriter(System.out)

    @inline def read: String = input.readLine()

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

    def readInt: Int = tokenizeLine.nextToken.toInt

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

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

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

}

object A365 {

  import IO._
  import collection.{mutable => cu}

  def main(args: Array[String]): Unit = {
    val Array(n, k) = readInts(2)
    var res = (1 to n).count{ _ =>
      val in = read.distinct.sorted
      in.zipWithIndex.forall{case (char, i) => char-'0' == i}
    }
    out.println(res)
    out.close()
  }

  object IO {
    private val input = new java.io.BufferedReader(new java.io.InputStreamReader(System.in))
    //    private val input = new java.io.BufferedReader(new java.io.InputStreamReader(new java.io.FileInputStream("src/input")))
    val out = new java.io.PrintWriter(System.out)

    @inline def read: String = input.readLine()

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

    def readInt: Int = tokenizeLine.nextToken.toInt

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

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

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

}

object A365 {

  import IO._
  import collection.{mutable => cu}

  def main(args: Array[String]): Unit = {
    val Array(n, k) = readInts(2)
    var res = (1 to n).count{ _ =>
      val in = read.distinct.sorted
      in.take(k+1).zipWithIndex.forall{case (char, i) => char-'0' == i}
    }
    out.println(res)
    out.close()
  }

  object IO {
    private val input = new java.io.BufferedReader(new java.io.InputStreamReader(System.in))
    //    private val input = new java.io.BufferedReader(new java.io.InputStreamReader(new java.io.FileInputStream("src/input")))
    val out = new java.io.PrintWriter(System.out)

    @inline def read: String = input.readLine()

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

    def readInt: Int = tokenizeLine.nextToken.toInt

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

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

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

}

import scala.collection._

object A extends App {

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

  val Array(n, k) = readInts(2)
  val as = Array.fill(n)(readLine.toLong)

  def ok(x0: Long, k: Int): Boolean = {
    var x = x0
    var digits = new mutable.BitSet(10)
    var ok = true
    while (x > 0 && ok) {
      val d = (x % 10).toInt
      if (d > k) ok = false else digits += d
      x /= 10
    }
    ok && digits.size == k + 1
  }

  println(as.count(ok(_, k)))
}

import scala.collection._

object A extends App {

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

  val Array(n, k) = readInts(2)
  val as = Array.fill(n)(readLine.map(_ - '0'))

  println(as.count(a => a.distinct.size == k + 1))
}

import scala.collection._

object A extends App {

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

  val Array(n, k) = readInts(2)
  val as = Array.fill(n)(readLine.map(_ - '0'))

  println(as.count(a => a.max <= k && a.distinct.size == k + 1))
}

import scala.collection._

object A extends App {

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

  val Array(n, k) = readInts(2)
  val as = Array.fill(n)(readLine.toLong)

  def ok(x0: Long, k: Int): Boolean = {
    var x = x0
    var first = true
    var digits = new mutable.BitSet(10)
    var ok = true
    while ((x > 0 || first) && ok) {
      first = false
      val d = (x % 10).toInt
      if (d > k) ok = false else digits += d
      x /= 10
    }
    ok && digits.size == k + 1
  }

  println(as.count(ok(_, k)))
}

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

object P365A extends App {
  val sc = new Scanner(System.in)
  val out = new PrintWriter(System.out)
  val N, K = sc.nextInt
  sc.nextLine

  def solve(): Int = {
    List.fill(N)(sc.nextLine).count { s =>
      s.toList.forall (_ < '1' + K)
    }
  }

  out.println(solve)
  out.close
}

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

object P365A extends App {
  val sc = new Scanner(System.in)
  val out = new PrintWriter(System.out)
  val N, K = sc.nextInt
  sc.nextLine

  def solve(): Int = {
    val a0 = List.range(0, K + 1).map(_ + '0')
    List.fill(N)(sc.nextLine).count { s =>
      s.toList.distinct.sortWith(_ < _) == a0
    }
  }

  out.println(solve)
  out.close
}


You are given a non-empty string s consisting of lowercase English letters. You have to pick exactly one non-empty substring of s and shift all its letters 'z'  'y'  'x'  'b'  'a'  'z'. In other words, each character is replaced with the previous character of English alphabet and 'a' is replaced with 'z'.What is the lexicographically minimum string that can be obtained from s by performing this shift exactly once?

The only line of the input contains the string s (1 ≤ |s| ≤ 100 000) consisting of lowercase English letters.

Print the lexicographically minimum string that can be obtained from s by shifting letters of exactly one non-empty substring.

NoteString s is lexicographically smaller than some other string t of the same length if there exists some 1 ≤ i ≤ |s|, such that s1 = t1, s2 = t2, ..., si - 1 = ti - 1, and si < ti.

object Solution extends App {
  val in = io.Source.stdin.getLines()
  val str = in.next()
  val (state, res) = str.foldLeft((0, List.empty[Char])) {
    case((0, acc), 'a') => (0, 'a' :: acc)
    case((0, acc), el) => (1, (el - 1).toChar :: acc)
    case((1, acc), 'a') => (2, 'a' :: acc)
    case((1, acc), el) => (1, (el - 1).toChar :: acc)
    case((2, acc), el) => (2, el :: acc)
  }
  if (state == 0)
    println(('z' :: res.tail).reverse.mkString)
  else
    println(res.reverse.mkString)

}

object A708 {

  import IO._
  import collection.{mutable => cu}

  def main(args: Array[String]): Unit = {
    val in = read.toCharArray
    var idxa = in.indexOf('a')
    if(idxa != 0) {
      if(idxa == -1) idxa = in.length
      for(i <- 0 until idxa) {
        in(i) = (in(i)-1).toChar
      }
    } else {
      val idxs = in.zipWithIndex.filter(_._1 == 'a').map(_._2) ++ Array(in.length)
      var break = false
      for(i <- 1 until idxs.length if !break) {
        if(idxs(i-1)+1 < idxs(i)) {
          for(j <- idxs(i-1)+1 until idxs(i))
            in(j) = (in(j)-1).toChar
          break = true
        }
      }
      if(!break)
        in(in.length-1) = (26+in.last-1).toChar
    }
    println(in.mkString(""))
  }

  object IO {
    @inline def read: String = scala.io.StdIn.readLine

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

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

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

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

}

object A extends App {

  @inline def tokenizeLine = new java.util.StringTokenizer(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)) }

  def shift(c: Char) = if (c == 'a') 'z' else (c - 1).toChar

  val s = readLine
  val s2 = s.map(shift)
  val n = s.length

  Console.setOut(new java.io.BufferedOutputStream(Console.out))

  val firstNonA = s.indexWhere(_ != 'a')

  val res = if (firstNonA == -1) {
    if (n == 1) s2
    else s.take(n - 1) + s2.last
  } else {
    val subsequentA = s.indexWhere(_ == 'a', firstNonA)
    if (subsequentA == -1) s.take(firstNonA) + s2.drop(firstNonA)
    else {
      s.take(firstNonA) + s2.slice(firstNonA, subsequentA) + s.drop(subsequentA)
    }
  }

  println(res)

  Console.flush
}

import Utils._, annotation.tailrec, collection.mutable, util._, control._, math.Ordering.Implicits._, collection.Searching._

object _709C extends CodeForcesApp {
  override def apply(io: IO) = {import io.{read, write, writeAll}
    val s = read[String].toArray
    val n = s.length

    val range = s.indexOf('a').nonNegative match {
      case None => s.indices
      case Some(0) => s.indexWhere(_ != 'a').nonNegative match {
        case Some(i) => i until s.indexOf('a', i).nonNegative.getOrElse(n)
        case _ => (n-1) until n
      }
      case Some(x) => 0 until x
    }

    def shift(c: Char): Char = if (c == 'a') 'z' else (c - 1).toChar

    range.foreach(i => s(i) = shift(s(i)))

    write(s.mkString)
  }
}
/****************************[Ignore Template Below]****************************************/
trait CodeForcesApp {
  lazy val isOnlineJudge: Boolean = sys.props.get("ONLINE_JUDGE").exists(_.toBoolean)
  def debug(x: => Any): Unit = if (!isOnlineJudge) println(x)
  def apply(io: IO): io.type
  def main(args: Array[String]): Unit = this(new IO(System.in, System.out)).close()
}
object Utils {
  import scala.collection.mutable, mutable.{Map => Dict}
  implicit class GenericExtensions[A](val a: A) extends AnyVal {
    def in(set: collection.Set[A]): Boolean = set(a)
    def some: Option[A] = Some(a)
    def partialMatch[B](f: PartialFunction[A, B]): Option[B] = f lift a
  }
  implicit class TraversableExtensions[A, C[X] <: Traversable[X]](val t: C[A]) extends AnyVal {
    def onlyElement: A = assuming(t.size == 1)(t.head)
    def groupByIdentifier[K](f: A => K): Map[K, A] = t.groupBy(f).mapValues(_.onlyElement)
    def duplicates(implicit b: C of A): C[A] = {
      val elems = mutable.Set.empty[A]
      (t collect {case i if !elems.add(i) => i}).to[C]
    }
    def sumWith[B](f: A => B)(implicit n: Numeric[B]): B = t.foldLeft(n.zero) {case (p, i) => n.plus(p, f(i))}
    def zipWith[B](f: A => B)(implicit b: C of (A, B)): C[(A, B)] = (t map {i => i -> f(i)}).to[C]
    def mapTo[B](f: A => B)(implicit b: C of (A, B)): Map[A, B] = zipWith(f).toUniqueMap
    def whenNonEmpty[B](f: t.type => B): Option[B] = when(t.nonEmpty)(f(t))  // e.g. grades.whenNonEmpty(_.max)
    def collectFirst[B](f: PartialFunction[A, Option[B]]): Option[B] = t.view collect f collectFirst {case Some(x) => x}
    def toMutableMultiSet: Dict[A, Int] = {
      val c = map[A] to 0
      t.foreach(i => c(i) += 1)
      c
    }
    def toMultiSet: Map[A, Int] = toMutableMultiSet.toMap withDefaultValue 0
    def X[B](s: Traversable[B]): Iterator[(A, B)] = for {a <- t.toIterator; b <- s} yield (a, b)
  }
  implicit class ArrayExtensions[A <: AnyRef](val a: Array[A]) extends AnyVal {
    def sort(from: Int, until: Int)(implicit cmp: Ordering[A]): Unit = java.util.Arrays.sort(a, from, until, cmp) //sort [from, until)
  }
  implicit class ArrayExtensions2[A](val a: Array[A]) extends AnyVal {
    def sort(from: Int, until: Int)(implicit cmp: Ordering[A]): Unit = a.view(from, until).sorted.copyToArray(a, from)
  }
  implicit class SeqExtensions[A, C[X] <: Seq[X]](val s: C[A]) extends AnyVal {
    def isRotationOf(t: Seq[A]): Boolean = s ++ s containsSlice t
  }
  implicit class PairExtensions[A, B](val p: (A, B)) extends AnyVal {
    def key = p._1
    def value = p._2
  }
  implicit class PairsExtensions[A, B, C[X] <: Traversable[X]](t: C[(A, B)]) {
    def toUniqueMap: Map[A, B] = t.groupByIdentifier(_.key).mapValues(_.value)
    def toMultiMap(implicit b: C of B): Map[A, C[B]] = t.groupBy(_.key).mapValues(_.map(_.value).to[C])
    def swap(implicit b: C of (B, A)): C[(B, A)] = t.map(_.swap).to[C]
  }
  implicit class MapExtensions[K, V, C[X, Y] <: Map[X, Y]](val m: C[K, V]) extends AnyVal {
    def lastKeyOption: Option[K] = m.lastOption.map(_.key)
    def firstKeyOption: Option[K] = m.headOption.map(_.key)
    def invert: Map[V, Set[K]] = m.toSet[(K, V)].swap.toMultiMap
    def mapKeys[K2](f: K => K2): Map[K2, V] = m map {case (k, v) => f(k) -> v}
    def toMutable: Dict[K, V] = Dict.empty[K, V] ++ m
  }
  implicit class MutableMapExtensions[K, V](val m: mutable.Map[K, V]) extends AnyVal {
    def removeLast(): Option[(K, V)] = m.lastOption.map(removeNode)
    def removeFirst(): Option[(K, V)] = m.headOption.map(removeNode)
    private def removeNode(kv: (K, V)): (K, V) = {
      m -= kv.key
      kv
    }
  }
  implicit class SetExtensions[A, C[A] <: Set[A]](val s: C[A]) extends AnyVal {
    def notContains(x: A): Boolean = !(s contains x)
    def toMutable = mutable.Set.empty[A] ++ s
  }
  implicit class IterableExtensions[A, C[A] <: Seq[A]](val s: C[A]) extends AnyVal {
    def deleteAtIndex(i: Int, howMany: Int = 1) = s.patch(i, Nil, howMany)
    def insertAtIndex(i: Int, items: Seq[A]) = s.patch(i, items, 0)
    def findWithIndex(f: A => Boolean): Option[(A, Int)] = s.zipWithIndex find {case (a, _) => f(a)}
    def foldUntil[B](z: B)(f: (B, A) => B)(c: B => Boolean): Option[(B, Int)] = s.view.scanLeft(z)(f).findWithIndex(c)
  }
  implicit class BooleanExtensions(val x: Boolean) extends AnyVal {
    def to[A](implicit n: Numeric[A]) = if(x) n.one else n.zero
    def toEnglish = if(x) "YES" else "NO"
  }
  implicit class IntExtensions(val x: Int) extends AnyVal {
    import java.lang.{Integer => JInt}
    def withHighestOneBit: Int = JInt.highestOneBit(x)
    def withLowestOneBit: Int = JInt.lowestOneBit(x)
    def numberOfLeadingZeroes: Int = JInt.numberOfLeadingZeros(x)
    def numberOfTrailingZeroes: Int = JInt.numberOfTrailingZeros(x)
    def bitCount: Int = JInt.bitCount(x)
    def setLowestBits(n: Int): Int = x | (left(n) - 1)
    def clearLowestBits(n: Int): Int = x & left(n, ~0)
    def setBit(i: Int, set: Boolean): Int = if (set) setBit(i) else clearBit(i)
    def setBit(i: Int): Int = x | left(i)
    def clearBit(i: Int): Int = x & ~left(i)
    def toggleBit(i: Int): Int = x ^ left(i)
    def testBit(i: Int): Boolean = ((x >> i) & 1) == 1
    private def left(bits: Int, num: Int = 1) = assuming(bits >= 0 && bits < JInt.SIZE)(num << bits)
    def X(y: Int): Iterator[(Int, Int)] = until(x) X until(y)
  }
  implicit class LongExtensions(val x: Long) extends AnyVal {
    import java.lang.{Long => JLong}
    def withHighestOneBitSet: Long = JLong.highestOneBit(x)
    def withLowestOneBitSet: Long = JLong.lowestOneBit(x)
    def numberOfLeadingZeroes: Int = JLong.numberOfLeadingZeros(x)
    def numberOfTrailingZeroes: Int = JLong.numberOfTrailingZeros(x)
    def bitCount: Int = JLong.bitCount(x)
    def setLowestBits(n: Int): Long = x | (left(n) - 1)
    def clearLowestBits(n: Int): Long = x & left(n, ~0L)
    def setBit(i: Int, set: Boolean): Long = if (set) setBit(i) else clearBit(i)
    def setBit(i: Int): Long = x | left(i)
    def clearBit(i: Int): Long = x & ~left(i)
    def toggleBit(i: Int): Long = x ^ left(i)
    def testBit(i: Int): Boolean = ((x >> i) & 1) == 1
    private def left(bits: Int, num: Long = 1L) = assuming(bits >= 0 && bits < JLong.SIZE)(num << bits)
  }
  implicit class NumericExtensions[A](val x: A)(implicit n: Numeric[A]) {
    import Numeric.Implicits._
    def **(i: Int): A = if (i == 0) n.one else {
      val h = x ** (i/2)
      if (i%2 == 0) h * h else h * h * x
    }
    def distance(y: A) = (x - y).abs()
    def nonNegative: Option[A] = when(n.gteq(x, n.zero))(x)
    def whenNegative(f: => A): A = nonNegative getOrElse f   //e.g. students indexOf "Greg" whenNegative Int.MaxValue
  }
  implicit class IntegralExtensions[A](val x: A)(implicit n: Integral[A]) {
    import scala.collection.immutable.NumericRange, Integral.Implicits._
    def mod(y: A): A = x - ((x / y) * y) //(x/y)*y + (x mod y) == x
    def -->(y: A): NumericRange.Inclusive[A] = NumericRange.inclusive(x, y, if (n.lteq(x, y)) n.one else -n.one)
    def ceilDiv(y: A): A = if (mod(y) == n.zero) x/y else n.one + (x/y)
  }
  implicit def toPoint[A](p: (A, A))(implicit n: Numeric[A]) = new java.awt.geom.Point2D.Double(n.toDouble(p._1), n.toDouble(p._2))
  def desc[A: Ordering]: Ordering[A] = asc[A].reverse  //e.g. students.sortBy(_.height)(desc)
  def asc[A](implicit order: Ordering[A]): Ordering[A] = order
  def map[K] = new {
    def to[V](default: => V): Dict[K, V] = using(_ => default)
    def using[V](f: K => V): Dict[K, V] = new mutable.HashMap[K, V]() {
      override def apply(key: K) = getOrElseUpdate(key, f(key))
    }
  }
  def newMultiMap[K, V] = map[K] to mutable.Set.empty[V]
  def memoize[A, B](f: A => B): A ==> B = map[A] using f
  implicit class FuzzyDouble(val x: Double) extends AnyVal {
    def  >~(y: Double) = x > y + eps
    def >=~(y: Double) = x >= y + eps
    def  ~<(y: Double) = y >=~ x
    def ~=<(y: Double) = y >~ x
    def  ~=(y: Double) = (x distance y) <= eps
  }
  def toPolygon(points: Traversable[(Int, Int)]): java.awt.Polygon = {
    val (xs, ys) = points.unzip
    new java.awt.Polygon(xs.toArray, ys.toArray, points.size)
  }
  def toShape(points: Traversable[(Double, Double)]): java.awt.geom.GeneralPath = {
    val shape = new java.awt.geom.GeneralPath()
    points.headOption foreach {case (x, y) => shape.moveTo(x, y)}
    points.tail foreach {case (x, y) => shape.lineTo(x, y)}
    shape.closePath()
    shape
  }
  def until(until: Int): Range = 0 until until
  def not[A](f: A => Boolean): A => Boolean = {x: A => !f(x)}
  def assuming[A](cond: => Boolean)(f: => A): A = {require(cond); f}
  @inline def when[A](check: Boolean)(f: => A): Option[A] = if (check) f.some else None
  def repeat[U](n: Int)(f: => U): Unit = (1 to n).foreach(_ => f)
  type of[C[_], A] = scala.collection.generic.CanBuild[A, C[A]]
  type ==>[A, B] = collection.Map[A, B]
  val mod: Int = (1e9 + 7).toInt
  val eps: Double = 1e-9
}
/***********************************[Scala I/O]*********************************************/
import Utils._, java.io._, java.util.StringTokenizer

class IO(in: BufferedReader, out: BufferedWriter) extends Iterator[String] with AutoCloseable with Flushable {
  def this(reader: Reader, writer: Writer) = this(new BufferedReader(reader), new BufferedWriter(writer))
  def this(in: InputStream, out: OutputStream) = this(new InputStreamReader(in), new OutputStreamWriter(out))

  private[this] val tokenizers = Iterator.continually(in.readLine()).takeWhile(_ != null).map(new StringTokenizer(_)).buffered
  val printer = new PrintWriter(out, true)

  @inline private[this] def tokenizer() = {
    while(tokenizers.nonEmpty && !tokenizers.head.hasMoreTokens) tokenizers.next()
    when(tokenizers.nonEmpty)(tokenizers.head)
  }

  def read[A](implicit read: IO.Read[A]): A = read.apply(this)
  def read[C[_], A: IO.Read](n: Int)(implicit b: C of A): C[A] = Iterator.fill(n)(read).to[C]

  def readTill(delim: String): String = tokenizer().get.nextToken(delim)
  def readTillEndOfLine(): String = readTill("\n\r")

  override def next() = tokenizer().get.nextToken()
  override def hasNext = tokenizer().nonEmpty

  def write(obj: Any, more: Any*): this.type = {
    printer.print(obj)
    more foreach {i =>
      printer.print(' ')
      printer.print(i)
    }
    this
  }
  def writeAll(obj: Traversable[Any], separator: String = "\n"): this.type = write(obj mkString separator)

  override def flush() = printer.flush()
  def close() = {
    flush()
    in.close()
    printer.close()
  }
}
object IO {
  class Read[A](val apply: IO => A) {
    def map[B](f: A => B): Read[B] = new Read(apply andThen f)
  }
  object Read {
    implicit def collection[C[_], A: Read](implicit b: C of A): Read[C[A]]         = new Read(r => r.read[C, A](r.read[Int]))
    implicit val string                                       : Read[String]       = new Read(_.next())
    implicit val char                                         : Read[Char]         = string.map(_.toTraversable.onlyElement)
    implicit val int                                          : Read[Int]          = string.map(_.toInt)
    implicit val long                                         : Read[Long]         = string.map(_.toLong)
    implicit val bigInt                                       : Read[BigInt]       = string.map(BigInt(_))
    implicit val double                                       : Read[Double]       = string.map(_.toDouble)
    implicit val bigDecimal                                   : Read[BigDecimal]   = string.map(BigDecimal(_))
    implicit def tuple2[A: Read, B: Read]                     : Read[(A, B)]       = new Read(r => (r.read[A], r.read[B]))
    implicit def tuple3[A: Read, B: Read, C: Read]            : Read[(A, B, C)]    = new Read(r => (r.read[A], r.read[B], r.read[C]))
    implicit def tuple4[A: Read, B: Read, C: Read, D: Read]   : Read[(A, B, C, D)] = new Read(r => (r.read[A], r.read[B], r.read[C], r.read[D]))
    implicit val boolean                                      : Read[Boolean]      = string map {s =>
      s.toLowerCase match {
        case "yes" | "true" | "1" => true
        case "no" | "false" | "0" => false
        case _ => s.toBoolean
      }
    }
  }
}

object A708 {

  import IO._
  import collection.{mutable => cu}

  def main(args: Array[String]): Unit = {
    val in = read.toCharArray
    var idxa = in.indexOf('a')
    if(idxa != 0) {
      if(idxa == -1) idxa = in.length
      for(i <- 0 until idxa) {
        in(i) = (in(i)-1).toChar
      }
    } else {
      val idxs = in.zipWithIndex.filter(_._1 == 'a').map(_._2)
      var break = false
      for(i <- 1 until idxs.length if !break) {
        if(idxs(i-1)+1 < idxs(i)) {
          for(j <- idxs(i-1)+1 until idxs(i))
            in(j) = (in(j)-1).toChar
          break = true
        }
      }
    }
    println(in.mkString(""))
  }

  object IO {
    @inline def read: String = scala.io.StdIn.readLine

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

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

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

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

}


After a long day, Alice and Bob decided to play a little game. The game board consists of $$$n$$$ cells in a straight line, numbered from $$$1$$$ to $$$n$$$, where each cell contains a number $$$a_i$$$ between $$$1$$$ and $$$n$$$. Furthermore, no two cells contain the same number. A token is placed in one of the cells. They take alternating turns of moving the token around the board, with Alice moving first. The current player can move from cell $$$i$$$ to cell $$$j$$$ only if the following two conditions are satisfied:   the number in the new cell $$$j$$$ must be strictly larger than the number in the old cell $$$i$$$ (i.e. $$$a_j > a_i$$$), and  the distance that the token travels during this turn must be a multiple of the number in the old cell (i.e. $$$|i-j|\bmod a_i = 0$$$). Whoever is unable to make a move, loses. For each possible starting position, determine who wins if they both play optimally. It can be shown that the game is always finite, i.e. there always is a winning strategy for one of the players.

The first line contains a single integer $$$n$$$ ($$$1 \le n \le 10^5$$$) — the number of numbers. The second line contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \le a_i \le n$$$). Furthermore, there are no pair of indices $$$i \neq j$$$ such that $$$a_i = a_j$$$.

Print $$$s$$$ — a string of $$$n$$$ characters, where the $$$i$$$-th character represents the outcome of the game if the token is initially placed in the cell $$$i$$$. If Alice wins, then $$$s_i$$$ has to be equal to "A"; otherwise, $$$s_i$$$ has to be equal to "B".

NoteIn the first sample, if Bob puts the token on the number (not position):   $$$1$$$: Alice can move to any number. She can win by picking $$$7$$$, from which Bob has no move.  $$$2$$$: Alice can move to $$$3$$$ and $$$5$$$. Upon moving to $$$5$$$, Bob can win by moving to $$$8$$$. If she chooses $$$3$$$ instead, she wins, as Bob has only a move to $$$4$$$, from which Alice can move to $$$8$$$.  $$$3$$$: Alice can only move to $$$4$$$, after which Bob wins by moving to $$$8$$$.  $$$4$$$, $$$5$$$, or $$$6$$$: Alice wins by moving to $$$8$$$.  $$$7$$$, $$$8$$$: Alice has no move, and hence she loses immediately.

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 A = na(N)
    val topo = Array.fill[ArrayBuffer[Int]](N)(ArrayBuffer())
    val win = Array.ofDim[Char](N) // numberベース
    rep(N) { i =>
      val s = i % A(i)
      var j = s
      while (j < N) {
        if (A(j) > A(i)) {
          topo(A(i) - 1) += A(j) - 1
        }
        j += A(i)
      }
    }

    rep_r(N) { i =>
      val bob = topo(i) forall (j => win(j) == 'A')
      win(i) = if (bob) 'B' else 'A'
    }

    out.println(A map (i => win(i - 1)))
  }

  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): Array[Int] = map(n)(_ => ni())
  def nal(n: Int): Array[Long] = map(n)(_ => nl())
  def nm(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)(f: Int => A): Array[A] = {
    val res = Array.ofDim[A](n)
    rep(n)(i => res(i) = f(i))
    res
  }

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

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 A = na(N)

    val win = Array.ofDim[Char](N)
    val looking = Array.fill[ArrayBuffer[Int]](N)(ArrayBuffer())
    val q = mutable.Queue[Int]()
    var cnt = 0

    rep(N) { i =>
      val s = i % A(i)
      var j = s
      var moves = 0
      while (j < N) {
        if (A(j) > A(i)) {
          looking(j) += i
          moves += 1
        }
        j += A(i)
      }

      if (moves == 0) {
        win(i) = 'B'
        cnt += 1
        q += i
      }
    }

    def test(i: Int) {
      val s = i % A(i)
      var j = s
      var allWin = true
      while (j < N) {
        if (A(j) > A(i)) {
          if (win(j) == 'B') {
            win(i) = 'A'
            cnt += 1
            q += i
            return
          }
          allWin &= win(j) == 'A'
        }
        j += A(i)
      }

      if (allWin) {
        win(i) = 'B'
        cnt += 1
        q += i
      }
    }

    while (cnt < N) {
      val i = q.dequeue()
      looking(i) foreach { j =>
        if (win(j) == 0) test(j)
      }
    }

    out.println(win.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): Array[Int] = map(n)(_ => ni())
  def nal(n: Int): Array[Long] = map(n)(_ => nl())
  def nm(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)(f: Int => A): Array[A] = {
    val res = Array.ofDim[A](n)
    rep(n)(i => res(i) = f(i))
    res
  }

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

object C extends App {

  @inline def tokenizeLine = new java.util.StringTokenizer(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 as = readInts(n)
  val bs = Array.fill(n){ ' ' }

  Console.setOut(new java.io.BufferedOutputStream(Console.out))

  def check(i: Int): Boolean = {
    if (bs(i) != ' ') bs(i) == 'A'
    else {
      val a = as(i)
      var j = i - a
      var canWin = false
      while (j >= 0 && !canWin) {
        if (as(j) > a && !check(j)) canWin = true
        j -= a
      }
      j = i + a
      while (j < n && !canWin) {
        if (as(j) > a && !check(j)) canWin = true
        j += a
      }
      bs(i) = if (canWin) 'A' else 'B'
      canWin
    }
  }

  var i = 0
  while (i < n) {
    if (bs(i) == ' ') check(i)
    i += 1
  }

  println(new String(bs))

  Console.flush
}

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 A = na(N)

    val win = Array.ofDim[Char](N)
    val looking = Array.fill[ArrayBuffer[Int]](N)(ArrayBuffer())
    val q = mutable.Queue[Int]()
    var cnt = 0

    rep(N) { i =>
      val s = i % A(i)
      var j = s
      while (j < N) {
        looking(j) += i
        j += A(i)
      }

      if (s == i && s + A(i) >= N) {
        win(i) = 'B'
        cnt += 1
        q += i
      }
    }

    def test(i: Int) {
      val s = i % A(i)
      var j = s
      var allWin = true
      while (j < N) {
        if (j != i) {
          if (win(j) == 'B') {
            win(i) = 'A'
            cnt += 1
            q += i
            return
          }
          allWin &= win(j) == 'A'
        }
        j += A(i)
      }

      if (allWin) {
        win(i) = 'B'
        cnt += 1
        q += i
      } else false
    }

    while (cnt < N) {
      val i = q.dequeue()
      looking(i) foreach { j =>
        if (win(j) == 0) test(j)
      }
    }

    out.println(win.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): Array[Int] = map(n)(_ => ni())
  def nal(n: Int): Array[Long] = map(n)(_ => nl())
  def nm(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)(f: Int => A): Array[A] = {
    val res = Array.ofDim[A](n)
    rep(n)(i => res(i) = f(i))
    res
  }

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


You are given a permutation $$$p_1, p_2, \dots, p_n$$$. Recall that sequence of $$$n$$$ integers is called a permutation if it contains all integers from $$$1$$$ to $$$n$$$ exactly once.Find three indices $$$i$$$, $$$j$$$ and $$$k$$$ such that:   $$$1 \le i < j < k \le n$$$;  $$$p_i < p_j$$$ and $$$p_j > p_k$$$.  Or say that there are no such indices.

The first line contains a single integer $$$T$$$ ($$$1 \le T \le 200$$$) — the number of test cases. Next $$$2T$$$ lines contain test cases — two lines per test case. The first line of each test case contains the single integer $$$n$$$ ($$$3 \le n \le 1000$$$) — the length of the permutation $$$p$$$. The second line contains $$$n$$$ integers $$$p_1, p_2, \dots, p_n$$$ ($$$1 \le p_i \le n$$$; $$$p_i \neq p_j$$$ if $$$i \neq j$$$) — the permutation $$$p$$$.

For each test case:    if there are such indices $$$i$$$, $$$j$$$ and $$$k$$$, print YES (case insensitive) and the indices themselves;  if there are no such indices, print NO (case insensitive).  If there are multiple valid triples of indices, print any of them.

object A {
  import InOut._
  def main(args: Array[String]): Unit = {

    for (_ <- 1 to nextInt) {
      val n = nextInt
      val ps = nextInts(n)

      var i = 2
      var res = -1
      while (i < n) {
        if (ps(i - 1) > ps(i - 2) && ps(i) < ps(i - 1)) {
          res = i
        }
        i += 1
      }

      if (res == -1) {
        out.println("NO")
      } else {
        out.println("YES")
        out.println(s"${res - 1} ${res} ${res + 1}")
      }

      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 t = readInt()

  (0 until t).foreach { _ =>
    val n  = readInt()
    val pn = readLine().split(" ").map(_.toInt)

    val ans = (0 until n - 2).collectFirst {
      case i if pn(i) < pn(i + 1) && pn(i + 2) < pn(i + 1) => (i + 1, i + 2, i + 3)
    }

    ans match {
      case Some((i, j, k)) => println(s"YES\n$i $j $k")
      case _               => println("NO")
    }
  }
}

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

  val t = readInt()

  (0 until t).foreach { _ =>
    val n  = readInt()
    val pn = readLine().split(" ").map(_.toInt)

    val ans = pn.zipWithIndex.sliding(3, 1).collectFirst {
      case Array((pi, i), (pj, j), (pk, k)) if pi < pj && pk < pj => (i + 1, j + 1, k + 1)
    }

    ans match {
      case Some((i, j, k)) =>
        println("YES")
        println(s"$i $j $k")
      case _ =>
        println("NO")
    }
  }
}

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

  val t = readInt()

  (0 until t).foreach { _ =>
    val n  = readInt()
    val pn = readLine().split(" ").map(_.toInt)

    val ans = (0 until n - 2).collectFirst {
      case i if pn(i) < pn(i + 1) && pn(i + 2) < pn(i + 1) => (i + 1, i + 2, i + 3)
    }

    ans match {
      case Some((i, j, k)) =>
        println("YES")
        println(s"$i $j $k")
      case _ =>
        println("NO")
    }
  }
}

import scala.io.StdIn._

object A extends App {

  def solve(A: Array[Int]): Option[Array[Int]] = {
    var a = 0
    var c = A.length - 1
    var b = 1

    while (a < b && b < c) {
      while (b < c) {
        if (A(a) < A(b) && A(b) > A(c)) return Some(Array(a, b, c))
        b += 1
      }

      if (A(a) < A(c)) c -= 1 else a += 1
      b = a + 1
    }

    None
  }

  val t = readInt()
  1 to t foreach { _ =>
    readInt()
    val A = readLine().split(" ").map(_.toInt)
    solve(A) match {
      case Some(xs) =>
        println("YES")
        println((xs(0) + 1) + " " + (xs(1) + 1) + " " + (xs(2) + 1))
      case None =>
        println("NO")
    }

  }

}

object ProblemA extends App {
  import java.io.{BufferedReader, InputStreamReader, PrintWriter}
  import java.util.StringTokenizer
  val in = new FastScanner(new BufferedReader(new InputStreamReader(System.in)))
  val out = new PrintWriter(System.out)

  class FastScanner(val in: BufferedReader) {
    var st: StringTokenizer = _;

    def nextToken(): String = {
      while (st == null || !st.hasMoreTokens) {
        st = new StringTokenizer(in.readLine);
      }
      return st.nextToken();
    }

    def nextInt(): Integer = {
      Integer.parseInt(nextToken());
    }

    def nextLong(): Long = {
      nextToken().toLong;
    }

    def nextDouble(): Double = {
      nextToken().toDouble;
    }
  }

  val t = in.nextInt()
  for (_ <- 1 to t) {
    val n = in.nextInt()
    val minLeft = new Array[Int](n)
    val minRight = new Array[Int](n)
    val a = new Array[Int](n)

    for (i <- 0 until n) {
      a(i) = in.nextInt()
      if (i > 0) {
        minLeft(i) = math.min(a(i), minLeft(i - 1))
      } else {
        minLeft(i) = a(i)
      }
    }

    for (i <- (0 until n).reverse) {
      if (i < a.length - 1) {
        minRight(i) = math.min(a(i), minRight(i + 1))
      } else {
        minRight(i) = a(i)
      }
    }

    var ans = -1

    for (i <- 1 until n - 1) {
      if (a(i) > minLeft(i - 1) && a(i) > minRight(i + 1)) {
        ans = i
      }
    }

    if (ans == -1) {
      println("NO")
    } else {
      println("YES")
      println(s"${a.indexOf(minLeft(ans - 1)) + 1} ${ans + 1} ${a.indexOf(minRight(ans + 1)) + 1}")
    }
  }
}

object ProblemA extends App {
  import java.io.{BufferedReader, InputStreamReader, PrintWriter}
  import java.util.StringTokenizer
  val in = new FastScanner(new BufferedReader(new InputStreamReader(System.in)))
  val out = new PrintWriter(System.out)

  class FastScanner(val in: BufferedReader) {
    var st: StringTokenizer = _;

    def nextToken(): String = {
      while (st == null || !st.hasMoreTokens) {
        st = new StringTokenizer(in.readLine);
      }
      return st.nextToken();
    }

    def nextInt(): Integer = {
      Integer.parseInt(nextToken());
    }

    def nextLong(): Long = {
      nextToken().toLong;
    }

    def nextDouble(): Double = {
      nextToken().toDouble;
    }
  }

  val t = in.nextInt()
  for (_ <- 1 to t) {
    val n = in.nextInt()
    val minLeft = new Array[Int](n)
    val minRight = new Array[Int](n)
    val a = new Array[Int](n)

    for (i <- 0 until n) {
      a(i) = in.nextInt()
      if (i > 0) {
        minLeft(i) = math.min(a(i), minLeft(i - 1))
      } else {
        minLeft(i) = a(i)
      }

      if (i < a.length - 1) {
        minRight(i) = math.min(a(i), minRight(i + 1))
      } else {
        minRight(i) = a(i)
      }
    }

    var ans = -1

    for (i <- 1 until n - 1) {
      if (a(i) > minLeft(i - 1) && a(i) > minRight(i + 1)) {
        ans = i
      }
    }

    if (ans == -1) {
      println("NO")
    } else {
      println("YES")
      println(s"${a.indexOf(minLeft(ans - 1))} $ans ${a.indexOf(minRight(ans + 1))}")
    }
  }
}

object ProblemA extends App {
  import java.io.{BufferedReader, InputStreamReader, PrintWriter}
  import java.util.StringTokenizer
  val in = new FastScanner(new BufferedReader(new InputStreamReader(System.in)))
  val out = new PrintWriter(System.out)

  class FastScanner(val in: BufferedReader) {
    var st: StringTokenizer = _;

    def nextToken(): String = {
      while (st == null || !st.hasMoreTokens) {
        st = new StringTokenizer(in.readLine);
      }
      return st.nextToken();
    }

    def nextInt(): Integer = {
      Integer.parseInt(nextToken());
    }

    def nextLong(): Long = {
      nextToken().toLong;
    }

    def nextDouble(): Double = {
      nextToken().toDouble;
    }
  }

  val t = in.nextInt()
  for (_ <- 1 to t) {
    val n = in.nextInt()
    val minLeft = new Array[Int](n)
    val minRight = new Array[Int](n)
    val a = new Array[Int](n)

    for (i <- 0 until n) {
      a(i) = in.nextInt()
      if (i > 0) {
        minLeft(i) = math.min(a(i), minLeft(i - 1))
      } else {
        minLeft(i) = a(i)
      }

      if (i < a.length - 1) {
        minRight(i) = math.min(a(i), minRight(i + 1))
      } else {
        minRight(i) = a(i)
      }
    }

    var ans = -1

    for (i <- 1 until n - 1) {
      if (a(i) > minLeft(i - 1) && a(i) > minRight(i + 1)) {
        ans = i
      }
    }

    if (ans == -1) {
      println("NO")
    } else {
      println("YES")
      println(s"${a.indexOf(minLeft(ans - 1)) + 1} ${ans + 1} ${a.indexOf(minRight(ans + 1)) + 1}")
    }
  }
}


Tokitsukaze and CSL are playing a little game of stones.In the beginning, there are $$$n$$$ piles of stones, the $$$i$$$-th pile of which has $$$a_i$$$ stones. The two players take turns making moves. Tokitsukaze moves first. On each turn the player chooses a nonempty pile and removes exactly one stone from the pile. A player loses if all of the piles are empty before his turn, or if after removing the stone, two piles (possibly empty) contain the same number of stones. Supposing that both players play optimally, who will win the game?Consider an example: $$$n=3$$$ and sizes of piles are $$$a_1=2$$$, $$$a_2=3$$$, $$$a_3=0$$$. It is impossible to choose the empty pile, so Tokitsukaze has two choices: the first and the second piles. If she chooses the first pile then the state will be $$$[1, 3, 0]$$$ and it is a good move. But if she chooses the second pile then the state will be $$$[2, 2, 0]$$$ and she immediately loses. So the only good move for her is to choose the first pile. Supposing that both players always take their best moves and never make mistakes, who will win the game?Note that even if there are two piles with the same number of stones at the beginning, Tokitsukaze may still be able to make a valid first move. It is only necessary that there are no two piles with the same number of stones after she moves.

The first line contains a single integer $$$n$$$ ($$$1 \le n \le 10^5$$$) — the number of piles. The second line contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$0 \le a_1, a_2, \ldots, a_n \le 10^9$$$), which mean the $$$i$$$-th pile has $$$a_i$$$ stones.

Print "sjfnb" (without quotes) if Tokitsukaze will win, or "cslnb" (without quotes) if CSL will win. Note the output characters are case-sensitive.

NoteIn the first example, Tokitsukaze cannot take any stone, so CSL will win.In the second example, Tokitsukaze can only take a stone from the first pile, and then, even though they have no stone, these two piles will have the same number of stones, which implies CSL will win.In the third example, Tokitsukaze will win. Here is one of the optimal ways:  Firstly, Tokitsukaze can choose the first pile and take a stone from that pile.  Then, CSL can only choose the first pile, because if he chooses the second pile, he will lose immediately.  Finally, Tokitsukaze can choose the second pile, and then CSL will have no choice but to lose. In the fourth example, they only have one good choice at any time, so Tokitsukaze can make the game lasting as long as possible and finally win.

object Main {
  import java.io.{BufferedReader, InputStream, InputStreamReader}
  import java.util.StringTokenizer
  import scala.reflect.ClassTag

  def main(args: Array[String]): Unit = {
    val out = new java.io.PrintWriter(System.out)
    new Main(out, new InputReader(System.in)).solve()
    out.flush()
  }

  private val oj = System.getenv("ATCODER_DEBUG") == null
  def DEBUG(f: => Unit): Unit = {
    if (!oj){ f }
  }
  def debug(as: Array[Boolean]): Unit = if (!oj){ debug(as.map(x => if(x) "1" else "0").mkString) }
  def debug(as: Array[Int]): Unit = if (!oj){ debug(as.mkString(" ")) }
  def debug(as: Array[Long]): Unit =if (!oj){ debug(as.mkString(" ")) }
  def debugDim(m: Array[Array[Long]]): Unit = if (!oj){
    REP(m.length) { i =>
      debug(m(i))
    }
  }
  def debugDimFlip(m: Array[Array[Long]]): Unit = if (!oj){
    REP(m(0).length) { j =>
      REP(m.length) { i =>
        System.err.print(m(i)(j))
        System.err.print(" ")
      }
      System.err.println()
    }
  }
  def debug(s: => String): Unit = DEBUG {
    System.err.println(s)
  }
  def debugL(num: => Long): Unit = DEBUG {
    System.err.println(num)
  }

  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 = Integer.parseInt(next())
    def nextLong(): Long = java.lang.Long.parseLong(next())
    def nextChar(): Char = next().charAt(0)

    def ni(): Int = nextInt()
    def nl(): Long = nextLong()
    def nc(): Char = nextChar()
    def ns(): String = 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 TO(from: Int, to: Int)(f: Int => Unit): Unit = {
    REP(to - from + 1, from) { i =>
      f(i)
    }
  }
  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]): Array[Long] = {
    val cum = Array.ofDim[Long](as.length + 1)
    REP(as.length) { i =>
      cum(i + 1) = cum(i) + as(i)
    }
    cum
  }
}

class Main(out: java.io.PrintWriter, sc: Main.InputReader) {
  import sc._
  import Main._
  import java.util.Arrays.sort

  import scala.collection.mutable
  import math.{abs, max, min}
  import mutable.ArrayBuffer

  // toIntとか+7とかするならvalにしろ
  @inline private def MOD = 1000000007

  def solve(): Unit = {
    val N = ni()
    val A = na(N)
    sort(A)
    val C = mutable.Map[Int, Int]().withDefaultValue(0)
    REP(N) { i =>
      C(A(i)) += 1
    }

    val preCondition = (0 until N forall { i => A(i) >= i }) && {
      val cnt3 = C.count(_._2 > 2)
      val cnt2 = C.count(_._2 == 2)
      cnt3 == 0 && {
        cnt2 == 0 || (cnt2 == 1 && {
          val k = C.find(_._2 == 2).get._1
          debug(s"cnt2 k:$k")
          C(k - 1) == 0
        })
      }
    }

    if (!preCondition) {
      // 0 1 2 3 4 の順番に並べれない場合はなにをとっても重複する
      out.println("cslnb")
      return
    }

    val sum = sumL(A)
    val last = N.toLong * (N - 1) / 2

    debug(s"sum:$sum last:$last")
    if ((sum - last) % 2 == 0) {
      out.println("cslnb")
    } else {
      out.println("sjfnb")
    }
  }

  def sort(a: Array[Int]): Array[Int] = {
    val n = a.length
    REP(n) { i =>
      val j = scala.util.Random.nextInt(n - i) + i
      val tmp = a(i)
      a(i) = a(j)
      a(j) = tmp
    }
    java.util.Arrays.sort(a)
    a
  }
}

object Main {
  import java.io.{BufferedReader, InputStream, InputStreamReader}
  import java.util.StringTokenizer
  import scala.reflect.ClassTag

  def main(args: Array[String]): Unit = {
    val out = new java.io.PrintWriter(System.out)
    new Main(out, new InputReader(System.in)).solve()
    out.flush()
  }

  private val oj = System.getenv("ATCODER_DEBUG") == null
  def DEBUG(f: => Unit): Unit = {
    if (!oj){ f }
  }
  def debug(as: Array[Boolean]): Unit = if (!oj){ debug(as.map(x => if(x) "1" else "0").mkString) }
  def debug(as: Array[Int]): Unit = if (!oj){ debug(as.mkString(" ")) }
  def debug(as: Array[Long]): Unit =if (!oj){ debug(as.mkString(" ")) }
  def debugDim(m: Array[Array[Long]]): Unit = if (!oj){
    REP(m.length) { i =>
      debug(m(i))
    }
  }
  def debugDimFlip(m: Array[Array[Long]]): Unit = if (!oj){
    REP(m(0).length) { j =>
      REP(m.length) { i =>
        System.err.print(m(i)(j))
        System.err.print(" ")
      }
      System.err.println()
    }
  }
  def debug(s: => String): Unit = DEBUG {
    System.err.println(s)
  }
  def debugL(num: => Long): Unit = DEBUG {
    System.err.println(num)
  }

  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 = Integer.parseInt(next())
    def nextLong(): Long = java.lang.Long.parseLong(next())
    def nextChar(): Char = next().charAt(0)

    def ni(): Int = nextInt()
    def nl(): Long = nextLong()
    def nc(): Char = nextChar()
    def ns(): String = 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 TO(from: Int, to: Int)(f: Int => Unit): Unit = {
    REP(to - from + 1, from) { i =>
      f(i)
    }
  }
  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]): Array[Long] = {
    val cum = Array.ofDim[Long](as.length + 1)
    REP(as.length) { i =>
      cum(i + 1) = cum(i) + as(i)
    }
    cum
  }
}

class Main(out: java.io.PrintWriter, sc: Main.InputReader) {
  import sc._
  import Main._
  import java.util.Arrays.sort

  import scala.collection.mutable
  import math.{abs, max, min}
  import mutable.ArrayBuffer

  // toIntとか+7とかするならvalにしろ
  @inline private def MOD = 1000000007

  def solve(): Unit = {
    val N = ni()
    val A = na(N)
    sort(A)
    val C = mutable.Map[Int, Int]().withDefaultValue(0)
    REP(N) { i =>
      C(A(i)) += 1
    }

    val preCondition = (0 until N forall { i => A(i) >= i }) && {
      C.values.forall(_ < 3)
    }

    if (!preCondition) {
      // 0 1 2 3 4 の順番に並べれない場合はなにをとっても重複する
      out.println("cslnb")
      return
    }

    val sum = sumL(A)
    val last = N.toLong * (N - 1) / 2

    debug(s"sum:$sum last:$last")
    if ((sum - last) % 2 == 0) {
      out.println("cslnb")
    } else {
      out.println("sjfnb")
    }
  }

  def sort(a: Array[Int]): Array[Int] = {
    val n = a.length
    REP(n) { i =>
      val j = scala.util.Random.nextInt(n - i) + i
      val tmp = a(i)
      a(i) = a(j)
      a(j) = tmp
    }
    java.util.Arrays.sort(a)
    a
  }
}

object Main {
  import java.io.{BufferedReader, InputStream, InputStreamReader}
  import java.util.StringTokenizer
  import scala.reflect.ClassTag

  def main(args: Array[String]): Unit = {
    val out = new java.io.PrintWriter(System.out)
    new Main(out, new InputReader(System.in)).solve()
    out.flush()
  }

  private val oj = System.getenv("ATCODER_DEBUG") == null
  def DEBUG(f: => Unit): Unit = {
    if (!oj){ f }
  }
  def debug(as: Array[Boolean]): Unit = if (!oj){ debug(as.map(x => if(x) "1" else "0").mkString) }
  def debug(as: Array[Int]): Unit = if (!oj){ debug(as.mkString(" ")) }
  def debug(as: Array[Long]): Unit =if (!oj){ debug(as.mkString(" ")) }
  def debugDim(m: Array[Array[Long]]): Unit = if (!oj){
    REP(m.length) { i =>
      debug(m(i))
    }
  }
  def debugDimFlip(m: Array[Array[Long]]): Unit = if (!oj){
    REP(m(0).length) { j =>
      REP(m.length) { i =>
        System.err.print(m(i)(j))
        System.err.print(" ")
      }
      System.err.println()
    }
  }
  def debug(s: => String): Unit = DEBUG {
    System.err.println(s)
  }
  def debugL(num: => Long): Unit = DEBUG {
    System.err.println(num)
  }

  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 = Integer.parseInt(next())
    def nextLong(): Long = java.lang.Long.parseLong(next())
    def nextChar(): Char = next().charAt(0)

    def ni(): Int = nextInt()
    def nl(): Long = nextLong()
    def nc(): Char = nextChar()
    def ns(): String = 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 TO(from: Int, to: Int)(f: Int => Unit): Unit = {
    REP(to - from + 1, from) { i =>
      f(i)
    }
  }
  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]): Array[Long] = {
    val cum = Array.ofDim[Long](as.length + 1)
    REP(as.length) { i =>
      cum(i + 1) = cum(i) + as(i)
    }
    cum
  }
}

class Main(out: java.io.PrintWriter, sc: Main.InputReader) {
  import sc._
  import Main._
  import java.util.Arrays.sort

  import scala.collection.mutable
  import math.{abs, max, min}
  import mutable.ArrayBuffer

  // toIntとか+7とかするならvalにしろ
  @inline private def MOD = 1000000007

  def solve(): Unit = {
    val N = ni()
    val A = na(N)
    sort(A)
    val C = mutable.Map[Int, Int]().withDefaultValue(0)
    REP(N) { i =>
      C(A(i)) += 1
    }

    val preCondition = (0 until N forall { i => A(i) >= i }) && {
      C.forall {
        case (k, v) => v < 3 && !(v == 2 && C(k - 1) > 0)
      }
    }

    if (!preCondition) {
      // 0 1 2 3 4 の順番に並べれない場合はなにをとっても重複する
      out.println("cslnb")
      return
    }

    val sum = sumL(A)
    val last = N.toLong * (N - 1) / 2

    debug(s"sum:$sum last:$last")
    if ((sum - last) % 2 == 0) {
      out.println("cslnb")
    } else {
      out.println("sjfnb")
    }
  }

  def sort(a: Array[Int]): Array[Int] = {
    val n = a.length
    REP(n) { i =>
      val j = scala.util.Random.nextInt(n - i) + i
      val tmp = a(i)
      a(i) = a(j)
      a(j) = tmp
    }
    java.util.Arrays.sort(a)
    a
  }
}

object Main {
  import java.io.{BufferedReader, InputStream, InputStreamReader}
  import java.util.StringTokenizer
  import scala.reflect.ClassTag

  def main(args: Array[String]): Unit = {
    val out = new java.io.PrintWriter(System.out)
    new Main(out, new InputReader(System.in)).solve()
    out.flush()
  }

  private val oj = System.getenv("ATCODER_DEBUG") == null
  def DEBUG(f: => Unit): Unit = {
    if (!oj){ f }
  }
  def debug(as: Array[Boolean]): Unit = if (!oj){ debug(as.map(x => if(x) "1" else "0").mkString) }
  def debug(as: Array[Int]): Unit = if (!oj){ debug(as.mkString(" ")) }
  def debug(as: Array[Long]): Unit =if (!oj){ debug(as.mkString(" ")) }
  def debugDim(m: Array[Array[Long]]): Unit = if (!oj){
    REP(m.length) { i =>
      debug(m(i))
    }
  }
  def debugDimFlip(m: Array[Array[Long]]): Unit = if (!oj){
    REP(m(0).length) { j =>
      REP(m.length) { i =>
        System.err.print(m(i)(j))
        System.err.print(" ")
      }
      System.err.println()
    }
  }
  def debug(s: => String): Unit = DEBUG {
    System.err.println(s)
  }
  def debugL(num: => Long): Unit = DEBUG {
    System.err.println(num)
  }

  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 = Integer.parseInt(next())
    def nextLong(): Long = java.lang.Long.parseLong(next())
    def nextChar(): Char = next().charAt(0)

    def ni(): Int = nextInt()
    def nl(): Long = nextLong()
    def nc(): Char = nextChar()
    def ns(): String = 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 TO(from: Int, to: Int)(f: Int => Unit): Unit = {
    REP(to - from + 1, from) { i =>
      f(i)
    }
  }
  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]): Array[Long] = {
    val cum = Array.ofDim[Long](as.length + 1)
    REP(as.length) { i =>
      cum(i + 1) = cum(i) + as(i)
    }
    cum
  }
}

class Main(out: java.io.PrintWriter, sc: Main.InputReader) {
  import sc._
  import Main._
  import java.util.Arrays.sort

  import scala.collection.mutable
  import math.{abs, max, min}
  import mutable.ArrayBuffer

  // toIntとか+7とかするならvalにしろ
  @inline private def MOD = 1000000007

  def solve(): Unit = {
    val N = ni()
    val A = na(N)
    sort(A)

    val preCondition = 0 until N forall { i => A(i) >= i }
    if (!preCondition) {
      // 0 1 2 3 4 の順番に並べれない場合はなにをとっても重複する
      out.println("cslnb")
      return
    }

    val sum = sumL(A)
    val last = N.toLong * (N - 1) / 2

    debug(s"sum:$sum last:$last")
    if ((sum - last) % 2 == 0) {
      out.println("cslnb")
    } else {
      out.println("sjfnb")
    }
  }

  def sort(a: Array[Int]): Array[Int] = {
    val n = a.length
    REP(n) { i =>
      val j = scala.util.Random.nextInt(n - i) + i
      val tmp = a(i)
      a(i) = a(j)
      a(j) = tmp
    }
    java.util.Arrays.sort(a)
    a
  }
}


Edogawa Conan got tired of solving cases, and invited his friend, Professor Agasa, over. They decided to play a game of cards. Conan has n cards, and the i-th card has a number ai written on it.They take turns playing, starting with Conan. In each turn, the player chooses a card and removes it. Also, he removes all cards having a number strictly lesser than the number on the chosen card. Formally, if the player chooses the i-th card, he removes that card and removes the j-th card for all j such that aj < ai.A player loses if he cannot make a move on his turn, that is, he loses if there are no cards left. Predict the outcome of the game, assuming both players play optimally.

The first line contains an integer n (1 ≤ n ≤ 105) — the number of cards Conan has.  The next line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 105), where ai is the number on the i-th card.

If Conan wins, print "Conan" (without quotes), otherwise print "Agasa" (without quotes).

NoteIn the first example, Conan can just choose the card having number 7 on it and hence remove all the cards. After that, there are no cards left on Agasa's turn.In the second example, no matter which card Conan chooses, there will be one one card left, which Agasa can choose. After that, there are no cards left when it becomes Conan's turn again.

object CardGame2 extends App {
  val n = scala.io.StdIn.readLine().toLong
  val original = scala.io.StdIn.readLine().split(" ").map(_.toInt)

  val oddNumberOfCards = 1
  val evenNumberOfCards = 2

  val simplified = original.groupBy(x => x)
    .map { case (card, cardDuplicates) =>
      val oddOrEven = if (cardDuplicates.length % 2 == 0) evenNumberOfCards else oddNumberOfCards
      card -> oddOrEven
    }
    .toSeq.sortBy { case (card, _) => card }.reverse //desc sorting
    .map { case (_, evenOrOdd) => evenOrOdd }
    .distinct

  val solution = simplified.toList match {
    case `evenNumberOfCards` :: Nil => "Agasa"
    case _ => "Conan"
  }

  println(solution)

}

object B2 extends App {

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

  val Array(n) = readInts(1)
  val check = readInts(n).groupBy(identity).valuesIterator.exists(_.length % 2 == 1)
  println(if (check) "Conan" else "Agasa")
}

object B extends App {

  @inline def tokenizeLine = new java.util.StringTokenizer(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 as = readInts(n).sorted
  var wins = "Agasa"

  var i = n - 1
  while (i >= 0) {
    if (i == 0 || as(i) > as(i - 1)) {
      if ((n - i) % 2 == 1) wins = "Conan"
    }
    i -= 1
  }

  println(wins)
}

object CardGame2 extends App {
  val n = scala.io.StdIn.readLine().toLong
  val original = scala.io.StdIn.readLine().split(" ").map(_.toInt)

  val oddNumberOfCards = 1
  val evenNumberOfCards = 2

  val simplified = original.groupBy(x => x)
    .map { case (card, cardDuplicates) =>
      val oddOrEven = if (cardDuplicates.length % 2 == 0) evenNumberOfCards else oddNumberOfCards
      card -> oddOrEven
    }
    .toSeq.sortBy { case (card, _) => card }.reverse //desc sorting
    .map { case (_, evenOrOdd) => evenOrOdd }

  val solution = simplified.toList match {
    case `evenNumberOfCards` :: Nil => "Agasa"
    case _ => "Conan"
  }

  println(solution)

}