fork download
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3.  
  4. #define ll long long
  5.  
  6. void solve(){
  7. int n;
  8. cin>>n;
  9. vector<int>a(n),b(n);
  10. unordered_map<int,int>mp,mp2;
  11. for(int &i:a){
  12. cin>>i;
  13. mp[i]++;
  14. }
  15. for(int &i:b){
  16. cin>>i;
  17. mp2[i]++;
  18. }
  19.  
  20. if(mp2!=mp){
  21. cout<<-1<<"\n";
  22. return;
  23. }
  24.  
  25. int count=0;
  26. for(int i=0;i<n;i++){
  27. if(a[i]==b[i])count++;
  28. }
  29. cout<<(count+1)/2<<"\n";
  30. }
  31.  
  32. int main(){
  33. ios_base::sync_with_stdio(false);
  34. cin.tie(NULL);
  35. solve();
  36. return 0;
  37. }
Success #stdin #stdout 0s 5324KB
stdin
5
2 1 1 2 2
2 1 1 1 2
stdout
-1