fork download
  1. #include<bits/stdc++.h>
  2. #define all(x) (x).begin(),(x).end()
  3. #define allr(x) x.rbegin(),x.rend()
  4. #define sz(x) ((int)x.size())
  5. #define AbdElmawla std::ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
  6. using namespace std;
  7. typedef unsigned long long int ull;
  8. typedef long long int ll;
  9. typedef long double ld;
  10. int dx[]= {-1,1,0,0,1,-1,1,-1};
  11. int dy[]= {0,0,1,-1,1,-1,-1,1};
  12. void solve()
  13. {
  14. int n,m;cin>>n>>m;
  15. int x,y,x2,y2;
  16. cin>>x>>y>>x2>>y2;
  17. if(x==x2&&y==y2)
  18. cout<<0;
  19. else if(x2<=x||m==1)
  20. cout<<-1;
  21. else{
  22. int dis=x2-x,dis2=abs(y-y2);
  23. if(abs(dis-dis2)%2==0)
  24. cout<<dis;
  25. else cout<<-1;
  26. }
  27. }
  28. int main()
  29. {
  30. AbdElmawla
  31. freopen("doroob.in","r",stdin);
  32. int t=1;
  33. cin>>t;
  34. while(t--)
  35. {
  36. solve();
  37. if(t)
  38. cout<<'\n';
  39. }
  40. }
  41.  
Success #stdin #stdout 0.01s 5504KB
stdin
Standard input is empty
stdout
-1