# Triple Sort | CodeChef

can someone give me an input for which my code goes wrong ?
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main(){
int t,co,ct,p,j,m,temp ,n,k,r;ll i;
cin>>t; int a[3000002],b[3000002];ll c[90000009];sets;set::iterator it;
while(t–){ r=1; ct=0; m=1;
cin>>n>>j;
for(i=1;i<=n;i++){cin>>a[i]; b[a[i]]=i;if(a[i]!=i)s.insert(i);}
for(i=1;i<=n;i++){ /*cout<<i<<endl;for(int y=1;y<=n;y++)cout<<a[y]<<" “;
cout<<endl;for(int y=1;y<=n;y++)cout<<b[y]<<” ";cout<<endl; */
if(a[i]!=i){

if(a[a[i]]==i)
{ if(s.size()<=3){r=0; break;}
s.erase(i); s.erase(a[i]); it=s.begin(); ct++;
k=*it;
co=b[k]; a[co]=a[i]; a[a[i]]=k; s.insert(a[i]);
c[m]=i; c[m+1]=b[k] ; c[m+2]=a[i] ;
b[a[i]]=co; b[k]=b[i]; b[i]=i; a[i]=i;
m+=3;continue;}

co=b[i]; k=a[a[i]];
c[m]=i; c[m+1]=a[i] ; c[m+2]=co;
m+=3;b[a[a[i]]]=co; b[a[i]]=a[i];
a[a[i]]=a[i];
a[co]=k;
if(a[co]==co)s.erase(co); s.erase(a[i]);s.erase(i);
ct++; b[i]=i; a[i]=i;
}
}
if(r==0){cout<<-1<<endl; continue;}
if(ct>j){cout<<-1<<endl; continue;} cout<<ct<<endl;
for(i=1;i<=3*ct;i+=3){ cout<<c[i]<<" “<<c[i+1]<<” "<<c[i+2]<<endl;}

s.clear();

}