ll@n,@p,@k,d[k+1]{p}; rep(i,n){ ll@t,@b; rrep(j,min(i+1,k)){ d[j+1]>?=t==1?d[j]+b:2d[j]; if(d[j+1]>1d18){ wt(-1); exit(0); } } } wt(d[k]);