package main import . "fmt" import . "slices" import . "math/big" import . "os" import bf "bufio" func main() { rd:=bf.NewReader(Stdin) var n int var p,q int64 Fscan(rd,&n,&p,&q) x:=make([]int64,n) for i:=range x { Fscan(rd,&x[i]) } Sort(x) a:=make([]int64,n) b:=make([]int64,n) c:=make([]int64,n) d:=make([]int64,n) z1,z2:=new(Int),new(Int) e10:=NewInt(10) e9:=NewInt(9) e7:=NewInt(7) e5:=NewInt(5) m:=NewInt(p) for i,v:=range x { z1.SetInt64(v) a[i]=z2.Exp(e10,z1,m).Int64() b[i]=z2.Exp(e9,z1,m).Int64() c[i]=z2.Exp(e7,z1,m).Int64() d[i]=z2.Exp(e5,z1,m).Int64() } t:=make([][]int,int(p)) for i,v:=range c { for _,w:=range d[i+1:] { u:=int((v+w)%p) t[u]=append(t[u],i) } } var ans int for i,v:=range a { for k,w:=range b { if k<=i { continue } u:=int((p+q-((v+w)%p))%p) if len(t[u])==0 { continue } s,_:=BinarySearch(t[u],k+1) ans+=len(t[u])-s } } Println(ans) }