code: def roman2int(s):
      
      val = 0
      pos10 = 1000
      beg = 0
      for pos in range(3, -1, -1):
          for digit in range(9,-1,-1):
              r = roman[pos][digit]
              if s.startswith(r, beg):  # footnote 1
                  beg += len(r)
                  val += digit * pos10
                  break
          pos10 //= 10
      return val
docs: Decode roman number
  
      :param s: string representing a roman number between 1 and 9999
      :returns: the decoded roman number
      :complexity: linear (if that makes sense for constant bounded input size)