N=int(input()) master=N*2 naive=0 while N: naive += N N //= 2 print((master-naive) % 1004535809)