===== ISTEM =====
Solve the following programming task.

TASK: LRU Cache (Least Recently Used)

Write an 'LRUCache(capacity)' class with a fixed capacity. 'get(key)' must return the value (or -1 if absent) and mark that key as most recently used. 'put(key, value)' must insert or update the value; when capacity is exceeded it must evict the least recently used entry. All operations must run in average O(1) time.

STARTER CODE (python):
class LRUCache:
    def __init__(self, capacity: int):
        pass

    def get(self, key: int) -> int:
        pass

    def put(self, key: int, value: int) -> None:
        pass


RULES:
- Keep the function name and signature EXACTLY as given.
- Return working code only. No explanations.
- Put the code in a single ``` block.
- Try to solve it first. If you genuinely cannot, write only this single
  line instead of producing faulty code: CANNOT_SOLVE

===== HAM YANIT =====
```python
class LRUCache:
    def __init__(self, capacity: int):
        self.capacity = capacity
        self.cache = {}
        self.head = [0, None, None]
        self.tail = [0, None, None]
        self.head[1] = self.tail
        self.tail[2] = self.head

    def _remove(self, node):
        prev, nxt = node[1], node[2]
        prev[2] = nxt
        nxt[1] = prev

    def _append(self, node):
        # prepend to head (most recent)
        t = self.head[2]
        self.head[2] = node
        node[1] = self.head
        node[2] = t
        t[1] = node

    def get(self, key: int) -> int:
        if key in self.cache:
            node = self.cache[key]
            self._remove(node)
            self._append(node)
            return node[0]
        return -1

    def put(self, key: int, value: int) -> None:
        if key in self.cache:
            node = self.cache[key]
            self._remove(node)
            node[0] = value
            self._append(node)
        else:
            if len(self.cache) >= self.capacity:
                # evict least recently used (tail)
                lru = self.tail[1]
                del self.cache[lru[0]]
                self._remove(lru)
            node = [value, None, None]
            self.cache[key] = node
            self._append(node)
```