import scala.io.StdIn object Problem171 { def factorial(n: Int): BigInt = { (BigInt(1) to BigInt(n)).product } def sameValuesNpr(n: Int, r: Seq[Int]): BigInt = { val numer: BigInt = factorial(n) val denom: BigInt = r.map(factorial).product numer / denom } def proc(s: String): Int = { val n: Int = s.length val r: Seq[Int] = s.groupBy(x => x).map(_._2.length).toSeq val mod = 573 val npr = sameValuesNpr(n, r) ((npr - 1) % mod).toInt } def main(args: Array[String]) { val S = StdIn.readLine() val result: Int = proc(S) println(result) } }