package main import . "fmt" import . "os" import bf "bufio" func main() { rd:=bf.NewReader(Stdin) var n int var k int64 Fscan(rd,&n,&k) a:=make([]int64,n) var m int64 for i:=range a { Fscan(rd,&a[i]) m+=a[i] } var x int64 for _,v:=range a { x=x*k%m x=(x+v)%m } Println(x) }