#pragma GCC optimize("Ofast") #pragma GCC target("avx2") char*mmap(); #define rd(v) long v=0;{int _c;while(_c=*rp++-48,_c>=0)v=v*10+_c;} #define wt(v) {long _z=v;do*--wp=_z%10+48;while(_z/=10);} #define MD 1000000007 main(){ char*rp=mmap(0l,1l<<25,1,2,0,0ll); rd(a); long n=0,r=0,s=0,t=0; r=*rp++-'1'; for(long c;c=*rp++-'0',c>=0;){ r=r*a%MD+c; s=s*a%MD+t; t=t*a%MD+1; ++n; } char wbuf[64],*wp=wbuf+sizeof wbuf; wt(((r+1)*n+s*(a-1)%MD*a)%MD); write(1,wp,wbuf+sizeof wbuf-wp); _exit(0); }