#pragma GCC optimize("Ofast") #pragma GCC target("avx2") #define rd() ({int _v=0,_c;while(_c=*rp++-48,_c>=0)_v=_v*10+_c;_v;}) #define wt(v) {unsigned long _z=v;do*--wp=_z%10+48;while(_z/=10);} #define rep(v,e) for(long v=0;vn){ return 0; } } c[i]=j; s-=a[i]; if(i==x){ if(++y>=k&&j=n){ d[i]=1; e[i]=c[i]-n; }else{ d[i]=1+d[c[i]]; e[i]=e[c[i]]; } if(d[i]==k&&e[i]<=i){ return 1; } } return 0; } void f0(){ char*mmap(); char*rp=mmap(0l,1l<<25,1,2,0,0ll); n=rd(); k=rd(); rep(i,n){ a[i]=rd(); } } long f1(){ long g=1; long h=100000000000001l; while(g+1>1; if(f(m)){ g=m; }else{ h=m; } } return g; } void f2(long z){ char wbuf[64],*wp=wbuf+sizeof wbuf; wt(z); write(1,wp,wbuf+sizeof wbuf-wp); } int main(){ f0(); f2(f1()); _exit(0); }