#include <iostream>
#include <unordered_map>
using namespace std;

#define fo(i,start,end) for(int i=start;i<end;i++)

int main() {
    int arr[] = {3, 2, 4, 3, 1};
    int k = 3; // distance
    int n = 5; // size
    
    // Store every element and its last occurrence index
    unordered_map<int, int> mp; 
    
    fo(i, 0, n){
        // 1. Check if the element already exists in the map
        if(mp.find(arr[i]) != mp.end()) {
            
            // 2. Calculate distance using the PREVIOUS occurrence
            int distance = i - mp[arr[i]];
            
            // 3. If it's within distance k, we found our match
            if(distance <= k) {
                cout << "True" << endl;
                return 0;
            }
        }
        
        // 4. Update the map with the CURRENT index
        // We do this whether it was found or not, because we always want 
        // to keep the most recent index for future comparisons.
        mp[arr[i]] = i; 
    }
    
    cout << "False" << endl;
    return 0;
}