import java.util.Scanner import scala.annotation.tailrec object Problem016 { def mpow(x: Long, e: Int, mod: Int): Int = { @tailrec def rec(x: Long, e: Int, result: Long): Int = { if (e <= 0) return result.toInt if (e % 2 == 0) { rec(x * x % mod, e / 2, result) } else { rec(x, e - 1, result * x % mod) } } rec(x, e, 1) } def proc(x: Int, a: Seq[Int], mod: Int): Int = { a.map(mpow(x, _, mod)).sum % mod } def main(args: Array[String]) { val sc = new Scanner(System.in) val x = sc.nextInt() val N = sc.nextInt() val a = Seq.fill(N)(sc.nextInt()) val result: Int = proc(x, a, 1000003) println(result) } }