Python (Simple Maths)
\n    def init(self, encoding):\n        self.encoding = encoding\n        self.idx = 0\n\n    def next(self, n):\n        while self.idx < len(self.encoding):\
\n    def __init__(self, encoding):\n        self.encoding = encoding\n        self.idx = 0\n\n    def next(self, n):\n        while self.idx < len(self.encoding):\n            if self.encoding[self.idx] >= n:\n                self.encoding[self.idx] -= n\n                return self.encoding[self.idx+1]\n            else:\n                n -= self.encoding[self.idx]\n                self.idx += 2\n                \n        return -1
[]