#include<map>usingnamespacestd;intmain(){map<int,int>index_output;map<int,int>::iteratorit;intindex,output;cin>>index;// dont need the first valueindex=1;while(cin>>output)index_output[index++]=output;for(it=index_output.begin();it!=index_output.end();it++)cout<<index_output.find(it->second)->second<<endl;return0;}

I got this C++ solution after quite some hit and trial. At first I even tried breaking the fn[fn[i]] logically just to check if it was working. Now in the given solution I have to ask that why do I have to initialize fn[0]=0 to get the final result. Any clarification would be very helpful. Thanks.