===== 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:
    class _Node:
        __slots__ = ("key", "val", "prev", "next")
        def __init__(self, key=None, val=None):
            self.key = key
            self.val = val
            self.prev = None
            self.next = None

    def __init__(self, capacity: int):
        self.capacity = capacity
        self.cache = {}  # key -> node
        self.head = self._Node()  # dummy head
        self.tail = self._Node()  # dummy tail
        self.head.next = self.tail
        self.tail.prev = self.head
        self.size = 0

    def _remove(self, node: "_Node") -> None:
        prev, nxt = node.prev, node.next
        prev.next = nxt
        nxt.prev = prev

    def _add_to_front(self, node: "_Node") -> None:
        node.prev = self.head
        node.next = self.head.next
        self.head.next.prev = node
        self.head.next = node

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

    def put(self, key: int, value: int) -> None:
        if self.capacity == 0:
            return
        if key in self.cache:
            node = self.cache[key]
            node.val = value
            self._remove(node)
            self._add_to_front(node)
        else:
            new_node = self._Node(key, value)
            self.cache[key] = new_node
            self._add_to_front(new_node)
            self.size += 1
            if self.size > self.capacity:
                # Evict LRU node
                lru = self.tail.prev
                self._remove(lru)
                del self.cache[lru.key]
                self.size -= 1
```