main(n,a){for(;a=scanf("%d",&n),n;printf("%d\n",n+a))for(;~n&a|n&a*2;a*=2)n^=n&a?n%a+1^a:0;}
main(n,a){for(;a=scanf("%d",&n)+~n&n;printf("%d\n",n+a|(n^n+a)/a/4));}
(define (mod a b) (if (< a b) a (mod(- a b) b) ) ) (define (quot a b) (/ (- a (mod a b)) b) ) (define (BitCount n) (if (< n 1) 0 (+ (BitCount (quot n 2)) (mod n 2)) ) ) (define (SearchBitN n m) (if (= n (BitCount m)) m (SearchBitN n (+ m 1)) ) ) (define (AnEasyProblem n) (SearchBitN (BitCount n) (+ n 1)) )