const
fi = '';
fo = '';
var
stn, sumst: string;
code, i: integer;
f: text;
procedure plus(var st1: string; st2: string);
var
tmp: char;
code, cs, i, j: integer;
sub: string;
begin
while length(st1) < length(st2) do st1 := '0' + st1;
while length(st1) > length(st2) do st2 := '0' + st2;
for i := length(st1) downto 1 do
begin
val(st2[i], cs, code);
tmp := chr(ord(st1[i]) + cs);
if ord(tmp)<= 57 then st1[i] := tmp else
begin
tmp := chr((ord(st1[i]) + cs)mod 57 + 47);
st1[i] := tmp;
sub := '1';
for j := 1 to length(st1) - i + 1 do sub := sub + '0';
plus(st1, sub);
end;
end;
end;
function div10(st: string): string;
begin
delete(st, length(st), 1);
if st <> '' then
div10 := st else div10 := '0';
end;
function mod10(st: string): integer;
var cs: integer;
begin
val(st[length(st)], cs, code);
mod10 := cs;
end;
function dec1(st: string): String;
var
s, s2: string;
tam: longint;
cs, code, time: integer;
ch: char;
begin
s := st;
if st = '0' then
begin
dec1 := '0';
exit;
end;
ch := '9';
tam := length(s);
time := 0;
val(s[tam], cs, code);
while cs - 1 < 0 do
begin
inc(time);
s[tam] := ch;
dec(tam);
val(st[tam], cs, code);
end;
if cs - 1>= 0 then
begin
str(cs - 1, s2);
s[tam] := s2[1];
end;
while (s[1] = '0') and (length(s) > 1) do delete(s, 1, 1);
dec1 := s;
end;
function productof(st1, st2: string): string;
var
tmpr, st3, kq: string;
i, j, ts1, ts2, tich, code, t, l: integer;
begin
kq := ''; l := 0;
for j := length(st2) downto 1 do
begin
val(st2[j], ts2, code);
tmpr := '';
for t := 1 to length(st1) + 1 do tmpr := tmpr + '0';
for i := length(st1) downto 1 do
begin
val(st1[i], ts1, code);
tich := ts1 * ts2;
str(tich, st3);
for t := 1 to length(st1) - i do st3 := st3 + '0';
plus(tmpr, st3);
end;
for t := 1 to length(st2) - j do tmpr := tmpr + '0';
plus(kq, tmpr);
inc(l);
end;
while (KQ[1] = '0') and (length(KQ) > 1) do delete(kq, 1, 1);
productof := kq;
end;
function sumof(st1, st2: string): string;
begin
plus(st1, st2);
sumof := st1;
end;
function tgcs(st: string): string;
var
sum, i, cs, code: integer;
sumst: string;
begin
sum := 0;
for i := 1 to length(st) do
begin
val(st[i], cs, code);
sum := sum + cs;
end;
str(sum, sumst);
tgcs := sumst;
end;
function tgtu1den(y: integer): string;
var
tong: integer;
st: string;
begin
tong := 0;
for i := 1 to y do inc(tong, i);
str(tong, st);
tgtu1den := st;
end;
function tgcstu1den(y: string): string;
var tam, a, b, c, d, e: string;
begin
if (y = '0') or (y = '1') then
begin
if y = '0' then tgcstu1den := '0';
if y = '1' then tgcstu1den := '1';
end
else
begin
tam := tgcstu1den(dec1(div10(y)));
a := tgtu1den(mod10(y));
b := productof(y[length(y)], tgcs(div10(y)));
c := productof('9', tam);
d := sumof(tam, tgcs(div10(y)));
e := productof('45', div10(y));
tgcstu1den := sumof(a, sumof(b, sumof(c, sumof(d, e))));
end;
end;
begin
assign(f, fi);
reset(f);
readln(f, stn);
close(f);
assign(f, fo);
rewrite(f);
sumst := tgcstu1den(stn);
writeln(f, sumst);
close(f);
end.