Help! How to modify this code to solve Jeff and Periods problem
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define nl "\n"
#define vi vector<int>
#define vii vector<pair<int, int>>
#define vl vector<ll>
#define vll vector<pair<ll, ll>>
#define fi first
#define se second
void solve() {
int n;
cin>>n;
int a;
map<int, pair<int, int>> res;
for(int i=1; i<=n; i++){
cin>>a;
if(res[a].first){
if(res[a].second ==0){
res[a].second = i;
}
}else{
res[a].first = i;
}
}
cout<<res.size()<<nl;
for(auto itr = res.begin(); itr!=res.end(); itr++) {
if(itr->second.second) {
cout<<itr->first<<" "<<itr->second.second - itr->second.first<<nl;
}else{
cout<<itr->first<<" "<<0<<nl;
}
}
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int t=1;
// cin>>t;
while(t--) {
solve();
}
}