fork download
  1. #include <iostream>
  2. #define ll long long
  3. #include <cmath>
  4. using namespace std;
  5. bool check_oe(ll int a, ll int c){
  6. if(a<0) a*=(-1);
  7. if(c<0) c*=(-1);
  8. if((a%2==0 and c%2==0) or (a%2==1 and c%2==1)) return false;
  9. return true;
  10. }
  11. int main(){
  12. int t;
  13. cin>>t;
  14. while(t--){
  15. ll int a,b,c;
  16. cin>>a>>b>>c;
  17. if(check_oe(a,c)){
  18. if(b==(a+c)/2) cout<<"1"<<endl;
  19. else if(b<(a+c)/2) cout<<(1+(a+c)/2-b)<<endl;
  20. else cout<<(b-(a+c)/2)<<endl;
  21.  
  22. }
  23. else cout<<abs((a+c)/2-b)<<endl;
  24.  
  25. }
  26. return 0;
  27. }
  28.  
Success #stdin #stdout 0s 4284KB
stdin
5
-5 0 5
-5 7 6
-10 -100 20
1 -1 1
51 23 10
stdout
0
7
105
2
8