# Cant figure out whats wrong

https://practice.geeksforgeeks.org/problems/common-elements/0

``````#include<bits/stdc++.h>
using namespace std;
int main()
{
int t;
cin>>t;
while(t--){
long long int n,n1,n2;
cin>>n>>n1>>n2;
int x;

set<long long int>s,s1,s2;
for(int i=0;i<n;i++){
cin>>x;
s.insert(x);
}

for(int i=0;i<n1;i++){
cin>>x;
s1.insert(x);
}

for(int i=0;i<n2;i++){
cin>>x;
s2.insert(x);
}

int count = 1;

unordered_map<int,int>ma;

for(auto i : s){
ma[i]++;

}

for(auto i : s1){
ma[i]++;
cout<<" "<<i<<endl;
}

for(auto i : s2){
ma[i]++;
}

for(auto i : ma){
if(i.second >=3){
count = 0;
cout<<i.first<<" ";
}
}
cout<<"\r";

if(count){
cout<<-1<<"\n";
cout<<"\r";
}
cout<<"\n";
}
return 0;
}
``````

At first, since range of arr[i] is 10^18 so you canâ€™t store it in â€śintâ€ť use â€ślong long intâ€ť instead.
Now, since you have to print output in increasing order so take â€śmapâ€ť instead of unordered map.
Also there is no need of â€ś\nâ€ť in cout<<-1<<"\n"; since it already placed in the last line of while loop.
Also include fast input output syntax (iâ€™ve mentioned in code).

BTW here is your correct code:

``````#include<bits/stdc++.h>
using namespace std;
int main()
{
ios_base::sync_with_stdio(false);cin.tie(NULL);  //for fast input output
int t;
cin>>t;
while(t--){
int n,n1,n2;
cin>>n>>n1>>n2;
long long int x;

set<long long int>s,s1,s2;
for(int i=0;i<n;i++){
cin>>x;
s.insert(x);
}

for(int i=0;i<n1;i++){
cin>>x;
s1.insert(x);
}

for(int i=0;i<n2;i++){
cin>>x;
s2.insert(x);
}

int count = 1;

map<int,int>ma;

for(auto i : s){
ma[i]++;
}

for(auto i : s1){
ma[i]++;
//cout<<" "<<i<<endl;
}

for(auto i : s2){
ma[i]++;
}

for(auto i : ma){
if(i.second >=3){
count = 0;
cout<<i.first<<" ";
}
}
// cout<<"\r";

if(count){
cout<<-1/*<<"\n"*/;
//cout<<"\r";
}

cout<<"\n";
}

return 0;
}
``````
1 Like