ll A,B,N,d[2d5],j,s,z=1d9; { rd(N); rep(i,N){ rd(A,B); s+=B; for(j=1d5;j--;)d[j+A]>?=d[j]+B; } rep(i,s)z