fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define nl '\n'
  4. typedef long long ll;
  5. #define int long long
  6.  
  7. void File() {
  8. #ifndef ONLINE_JUDGE
  9. freopen("input.txt", "r", stdin);
  10. freopen("output.txt", "w", stdout);
  11. #endif
  12. ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
  13. }
  14.  
  15. void sol() {
  16. int a,b;
  17. cin >> a >> b;
  18. if(!(a&1) and !(b&1)) {
  19. cout << a*(b/2)+2 << '\n';
  20. }else if(!(a&1) and b&1) {
  21. cout << -1 << '\n';
  22. }else if(a&1 and !(b&1)) {
  23. if((b/2)&1) {
  24. cout << -1 <<'\n';
  25. }else {
  26. cout << a*(b/2)+2 << '\n';
  27. }
  28. }else {
  29. cout << a*b+1 << '\n';
  30. }
  31. }
  32. signed main() {
  33. File();
  34. int T{1};
  35. cin >> T;
  36. while (T--) {
  37. sol();
  38. }
  39. }
  40.  
Success #stdin #stdout 0s 5300KB
stdin
Standard input is empty
stdout
2