program main implicit none character*12::s integer*8::i,n integer*8,allocatable::num(:) read *,n allocate(num(n)) do i=1,n read *,s num(i) = get_min(s) end do print '(i0)',MINVAL(num) contains function get_num(c) result(n) character,intent(in)::c integer::ic,n ic=ICHAR(c) if(ic.ge.ICHAR('0').and.ic.le.ICHAR('9')) then n = ic-ICHAR('0') else n = ic-ICHAR('A')+10 end if end function get_num function get_sinsuu(s) result(minn) character*12,intent(in)::s integer::minn,i minn = 2 do i=1,LEN_TRIM(s) minn = MAX(minn, get_num(s(i:i))+1) end do end function get_sinsuu function get_min(s) result(m) character*12,intent(in)::s integer::sinsuu,i integer*8::m m = 0 sinsuu = get_sinsuu(s) do i=1,LEN_TRIM(s) m = m * sinsuu + get_num(s(i:i)) end do end function get_min end program main