program binaria;
const
MAXN = 100000;
var
A, B, N, i, row : int64;
T : Array[0..MAXN-1] of int64;
begin
{
uncomment the two following lines if you want to read/write from files
assign(input, 'input.txt'); reset(input);
assign(output, 'output.txt'); rewrite(output);
}
ReadLn(N);
for i:=0 to N-1 do
Read(T[i]);
ReadLn();
B := 0;
for i:=0 to N-1 do
begin
A:=1; row:=A;
while row<T[i] do begin A:=A shl 1; row:= row + A ; end;
B:=B+row-T[i];
end;
WriteLn(B);
end.
cHJvZ3JhbSBiaW5hcmlhOwoKY29uc3QKICAgIE1BWE4gPSAxMDAwMDA7Cgp2YXIKICAgIEEsIEIsIE4sIGksIHJvdyA6IGludDY0OwogICAgVCAgICAgICA6IEFycmF5WzAuLk1BWE4tMV0gb2YgaW50NjQ7CgpiZWdpbgp7CiAgICB1bmNvbW1lbnQgdGhlIHR3byBmb2xsb3dpbmcgbGluZXMgaWYgeW91IHdhbnQgdG8gcmVhZC93cml0ZSBmcm9tIGZpbGVzCiAgICBhc3NpZ24oaW5wdXQsICAnaW5wdXQudHh0Jyk7ICByZXNldChpbnB1dCk7CiAgICBhc3NpZ24ob3V0cHV0LCAnb3V0cHV0LnR4dCcpOyByZXdyaXRlKG91dHB1dCk7Cn0KCiAgICBSZWFkTG4oTik7CgogICAgZm9yIGk6PTAgdG8gTi0xIGRvCiAgICAgICAgUmVhZChUW2ldKTsKICAgIFJlYWRMbigpOwoKICAgIEIgOj0gMDsgCiAgICAKICAgIGZvciBpOj0wIHRvIE4tMSBkbwogICAgICAgICAgICAgICAgICAgICAgYmVnaW4KICAgICAgICAgICAgICAgICAgICAgICAgQTo9MTsgcm93Oj1BOwogICAgICAgICAgICAgICAgICAgICAgICB3aGlsZSByb3c8VFtpXSBkbyBiZWdpbiBBOj1BIHNobCAxOyByb3c6PSByb3cgKyBBIDsgZW5kOwogICAgICAgICAgICAgICAgICAgICAgICBCOj1CK3Jvdy1UW2ldOwogICAgICAgICAgICAgICAgICAgICAgZW5kOwogICAgV3JpdGVMbihCKTsKCmVuZC4K