import java.io.*; import java.util.*; public class Main{ public static void main(String[] args) { var sc = new Scanner(System.in); var ou = new PrintWriter(System.out); int n = Integer.parseInt(sc.next()); int k = Integer.parseInt(sc.next()); long x = 0; long y = 0; int[] a = new int[n]; for(int i = 0 ; i < n ; i++) a[i] = Integer.parseInt(sc.next()); for(int i = 0 ; i < n ; i++) y += a[i]; for(int i = 0 ; i < n ; i++){ x *= k; x += a[i]; x %= y; } ou.println(x % y); sc.close(); ou.flush(); } }