#pragma GCC optimize("Ofast") #pragma GCC target("avx2") #define getrp() ({char*mmap();mmap(0l,1l<<25,1,2,0,0ll);}) #define rd_skip() while(*rp++>=48) #define rd() ({long _v=0,_c;while(_c=*rp++-48,_c>=0)_v=_v*10+_c;_v;}) #define wt(v) ({unsigned _z=v;do*--wp=_z%10+48;while(_z/=10);}) #define MD 998244353 typedef unsigned long ulong; ulong inverse(int a){ int b=MD; int u=1; int v=0; int s,t; while(b){ t=a/b; s=b; b=a-t*b; a=s; s=v; v=u-t*v; u=s; } if(u<0){ u+=MD; } return u; } int main(){ char*rp=getrp(); rd_skip(); unsigned m=rd(); long b=0; ulong c=0; while(*rp){ long a=rd(); b=a-b; c=(c*(m-1)+a)%MD; } if(b%m){ write(1,"-1",2); }else{ char wbuf[64],*wp=wbuf+sizeof wbuf; wt((c*inverse(m)+1)%MD); write(1,wp,wbuf+sizeof wbuf-wp); } _exit(0); }