import java.util.Scanner import scala.annotation.tailrec object Problem016 { @tailrec def mpow(x: Long, e: Int, mod: Int, result: Long): Int = { if (e <= 0) return result.toInt if (e % 2 == 0) { mpow(x * x % mod, e / 2, mod, result) } else { mpow(x, e - 1, mod, result * x % mod) } } def proc(x: Int, a: Seq[Int], mod: Int): Int = { a.map(mpow(x, _, mod, 1)).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) } }