module IO = struct (* @since 4.04.0 *) let split_on_char sep s = let open String in let r = ref [] in let j = ref (length s) in for i = length s - 1 downto 0 do if get s i = sep then begin r := sub s (i + 1) (!j - i - 1) :: !r; j := i end done; sub s 0 !j :: !r let read_ss () = read_line () |> split_on_char ' ' let read_ns () = read_ss () |> List.map int_of_string end let m = 1000003 let pow x n = let rec doit x n acc = if n = 0 then acc else doit (x * x mod m) (n / 2) (if n mod 2 = 0 then acc else acc * x mod m) in doit x n 1 let () = match IO.read_ns () with | [x; _] -> IO.read_ns () |> List.fold_left (fun s e -> (s + pow x e) mod m) 0 |> Printf.printf "%d\n" | _ -> assert false