#include <iostream>
#include<vector>
#include<unordered_map>
using namespace std;
 
int main() {
	// your code goes here
	vector<int> a={1,3,5,6,1,9,8};
	unordered_map<int,int> m;
	int k=4;
	int dist=-1;
	for(int i=0;i<a.size();i++) {
		if(m.find(a[i])!=m.end()) {
			dist=i-m[a[i]];
			if(dist<=k) {
				cout<<dist<<endl;
			}
		}
		m[a[i]]=i;
	}
	return 0;
}