require'prime' m=2048 l=(0..n=gets.to_i).map{{0=>0}} (2..n).map{|i|r=s=0;t=1;Prime.map(i){|q|i%q<1&&(r=q;s|=t);t*=2};l[r][s%m]=i} p l.inject([0]*m){|f,k|(0...m).map{|x|k.map{|s,i|s>(x&s)?0:f[x^s]+i}.max}}.max