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