program douazeci; var i,n,x,er:integer; p,nr:longint; s:string; c:char; begin write('introduceti nr de caractere '); readln(n); s:=''; for i:=1 to n do begin write('caracterul este '); repeat readln(c); until ((c>='0') and (c<='9')) or ((upcase(c)>='A') and (upcase(c)<='F')); s:=s+c; end; p:=1; nr:=0; for i:=length(s) downto 1 do begin if upcase(s[i])='A' then nr:=nr+p*10 else if upcase(s[i])='B' then nr:=nr+p*11 else if upcase(s[i])='C' then nr:=nr+p*12 else if upcase(s[i])='D' then nr:=nr+p*13 else if upcase(s[i])='E' then nr:=nr+p*14 else if upcase(s[i])='F' then nr:=nr+p*15 else begin val(s[i],x,er); nr:=nr+x*p; end; p:=p*16; end; writeln(nr); readln; end.