public void set(int key, int value) {
        if (!cache.containsKey(key)) { // Cache doesn't contain the key
            if (cache.size() < capacity) { // Cache is not full
                for (int k : frequency.keySet()) {
                    int temp = frequency.get(k);
                    frequency.replace(k, temp + 1);
                }
                cache.put(key, value);
                frequency.put(key, 0);
            }
            else { // Cache is full, remove the LRC
                int chosen_key = frequency.keySet().iterator().next();
                int chosen_value = frequency.get(chosen_key);
                for (int k: frequency.keySet()) {
                    if (frequency.get(k) >= chosen_value) { // choose the least recently used one
                        chosen_key = k;
                        chosen_value = frequency.get(k);
                    }
                }
                frequency.remove(chosen_key);
                cache.remove(chosen_key);
                for (int k : frequency.keySet()) {
                    int temp = frequency.get(k);
                    frequency.replace(k, temp + 1);
                }
                cache.put(key, value);
                frequency.put(key, 0);
            }
        }
        else {
            for (int k : frequency.keySet()) {
                int temp = frequency.get(k);
                frequency.replace(k, temp + 1);
            }
            frequency.replace(key, 0);
            cache.replace(key, value);
        }
    }