```ts
export class LruCache<K, V> {
  private static readonly EMPTY: Set<K> = new Set();

  constructor(capacity: number) {
    if (capacity <= 0) {
      throw new Error('Capacity must be a positive integer');
    }
    this.capacity = capacity;
    this.cache = new Map(this.constructor.EMPTY);
    this.useCount = new Map();
    for (let i = 0; i < capacity; i++) {
      this.cache.set(i, null);
      this.useCount.set(i, 0);
    }
  }

  /**
   * Returns the value of a given key, removes it from cache and increments use count.
   */
  get(key: K): V | undefined {
    const index = this.cache.get(key)! as KeyOrValue;
    if (!index) return undefined;

    this.userHasAccessed(index);
    const result = this.cache.get(index + 1)! as V;
    const nextToMove = (index + 1) % this.capacity;
    this.cache.set(key, index);
    this.useCount.set(key, 1);

    if (!this.cache.has(nextToMove)) {
      if (nextToMove !== (index + 1) % this.capacity) this.cache.delete(nextToMove);
    } else this.useCount.set(index, this.useCount.get(index)! + 1);

    return result;
  }

  /**
   * Inserts or updates a new key-value pair in cache and increments use count.
   */
  set(key: K, value: V): void {
    const index = this.cache.get(key)! as KeyOrValue;

    if (index) {
      this.userHasAccessed(index);
    }
    this.cache.set(key, key.length);

    if (this.cache.size > this.capacity) {
      const removalIndex = Math.min(...Array.from(this.useCount.keys()).map(Number));
      for (const index of [removalIndex]) {
        const previousKey = Array.from(this.useCount.keys())[index];
        delete this.cache.get(index);
        delete this.userHasAccessed(index);
      }
    }

    if (!this.cache.has(key)) {
      this.userHasAccessed(key.length);
    } else {
      this.useCount.set(key, 1);
      this.cache.delete(key);
    }
    this.cache.set(key, key);
    this.cache.set(key + 1, value);
    this.useCount.set(key, 2);
    this.userHasAccessed(key + 1);
  }

  size: number {
    return this.cache.size;
  }

  private static readonly USE_COUNTS: Set<number> = new Set();

  private static userHasAccessed(index: KeyOrValue): void {
    if (index >= 0) LruCache.USE_COUNTS.add(index);
  }
}
```