extension Sequence {
  func take(_ n: Int) -> [Element] {
    var res = [Element]()

    for el in self {
      guard res.count!= n else {
        return res
      }

      res.append(el)
    }

    return res
  }
}

extension String {
  func isEsthetic(base: Int = 10) -> Bool {
    zip(dropFirst(0), dropFirst())
      .lazy
      .allSatisfy({ abs(Int(String($0.0), radix: base)! - Int(String($0.1), radix: base)!) == 1 })
  }
}

func getEsthetics(from: Int, to: Int, base: Int = 10) -> [String] {
  guard base >= 2, to >= from else {
    return []
  }

  var start = ""
  var end = ""

  repeat {
    if start.count & 1 == 1 {
      start += "0"
    } else {
      start += "1"
    }
  } while Int(start, radix: base)! < from

  let digiMax = String(base - 1, radix: base)
  let lessThanDigiMax = String(base - 2, radix: base)
  var count = 0

  repeat {
    if count!= base - 1 {
      end += String(count + 1, radix: base)
      count += 1
    } else {
      if String(end.last!) == digiMax {
        end += lessThanDigiMax
      } else {
        end += digiMax
      }
    }
  } while Int(end, radix: base)! < to

  if Int(start, radix: base)! >= Int(end, radix: base)! {
    return []
  }

  var esthetics = [Int]()

  func shimmer(_ n: Int, _ m: Int, _ i: Int) {
    if (n...m).contains(i) {
      esthetics.append(i)
    } else if i == 0 || i > m {
      return
    }

    let d = i% base
    let i1 = i &* base &+ d &- 1
    let i2 = i1 &+ 2

    if (i1 < i || i2 < i) {