Submission

Status:

[PPPPPPPPPPPPPP]

Subtask/Task Score:

{100/100}

Score: 100

User: kimza

Problemset: anna

Language: cpp

Time: 0.007 second

Submitted On: 2026-03-05 21:27:07

// #include <bits/stdc++.h>
// #define int long long
// using namespace std;
// void check(){
//     vector<int> s;
//     int v,w,x,y,z;
//     cin >> v >> w >> x >> y >> z;
//     s.push_back(v);
//     s.push_back(w);
//     s.push_back(x);
//     s.push_back(y);
//     s.push_back(z);
//     sort(s.begin(),s.end(),greater<int>());
//     int a=0,b=0;
//     if(s[0]-s[1]!=1){
//         //find a,b
//         double b1 = (s[1]+sqrt((s[1]*s[1])-(4*s[0])))/2;
//         double b2 = (s[1]-sqrt((s[1]*s[1])-(4*s[0])))/2;

//         if(b1 < 0 || b2 < 0) {cout << "0 0" << "\n";return;} //end this loop
//         else{
//             if(b1 > b2) {a = b1; b = b2;}
//             else if(b2 > b1) {a = b2; b = b1;}
//             else if (b2 == b1) {cout << "0 0" << "\n";return;}
//         }

        
//     }
//     else{
//         b = 1;
//         a = s[0]-1;
//     }
//     //cout << a << " " << b;
//     //check----------------------------------------------------------------------------
//     int cs = a-b;//checksubtraction
//     int cm = a%b;//checkmod
//     int cd = a/b;//checkdivide
//     vector<int> check;
//     check.push_back(cs);
//     check.push_back(cm);
//     check.push_back(cd);
//     sort(check.begin(),check.end(),greater<int>());
//     if(check[0]==s[2] && check[1]==s[3] && check[2]==s[4]) {cout << a << " " << b << "\n";return;}
//     else {cout << "0 0" << "\n";return;}

// }

// int32_t main(){
//     cin.tie(nullptr)->sync_with_stdio(false);
//     int n;
//     cin >> n;
//     for(int i=0;i<n;i++){
//         check();
//         //check if theres more than 1 ans if so , 0 0 if not that.
//     }

//     return 0;
// }

#include <bits/stdc++.h>
#define int int64_t

using namespace std;


vector<vector<int>> get_permutation(vector<int> vec) {
  if (vec.size() == 1) {
    return {vec};
  }

  vector<vector<int>> output;
  for (int i = 0; i < vec.size(); i++) {
    // pass new vector that exclude i to recursive
    // then get output of recursive add i in front and add to output
    vector<int> temp = vec;
    temp.erase(temp.begin() + i);

    vector<vector<int>> sub_per = get_permutation(temp);
    for (int j = 0; j < sub_per.size(); j++) {
      sub_per[j].insert(sub_per[j].begin(), vec[i]);
      output.push_back(sub_per[j]);
    }
  }

  return output;
}

bool check(int a, int b, int c, int d, int e, int x, int y) {
  if (x <= y || y <= 0) {
    return false;
  }
  return
  (a == x+y) &&
  (b == x-y) &&
  (c == x*y) &&
  (d == x%y) &&
  (e == x/y) ;
}

int32_t main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);

  int n;
  cin >> n;

  for (int j = 0; j < n; j++)
  {
    vector<int> nums;
    nums.resize(5);
    for (int i = 0; i < 5; i++) {
      cin >> nums[i];
    }
    vector<vector<int>> permu = get_permutation(nums);
    
    int cx = 0;
    int cy = 0;
    for (int i = 0; i < permu.size(); i++) {
      // cout << "check point 1: " << permu[i].size() << endl;
      int a = permu[i][0];
      int b = permu[i][1];
      int c = permu[i][2];
      int d = permu[i][3];
      int e = permu[i][4];
      // cout << "check point 2: "
      // << "a: " << a
      // << ", b: " << b
      // << ", c: " << c
      // << ", d: " << d
      // << ", e: " << e
      //  << endl;

      int x = (a + b) / 2;
      int y = a - x;

      if (check(a, b, c, d, e, x, y)) {
        if (cx == 0) {
          cx = x;
          cy = y;
        } else {
          if (cx == x && cy == y) {
            continue;
          }
          cx = 0;
          cy = 0;
          goto done;
        }
      }
    }

    done:
    cout << cx << ' ' << cy << '\n';
  }

  return 0;
}