Language: C++

#define MOD2 998244353
#define INF ((1<<30)-1)
#define LINF (1LL<<60)
#define EPS (1e-10)
typedef long long Int;
typedef pair<Int, Int> P;

vector<int> to_vec(Int x){
    vector<int> res;
    for(int i = 0;i < 30;i++){
        res.push_back(x % 3);
        x /= 3;
    }
    return res;
}

Int to_int(vector<int> vec){
    Int res = 0;
    for(int i = 29;i >= 0;i--){
        res *= 3;
        res += vec[i];
    }
    return res;
}

Int up(Int x){
    auto vec = to_vec(x);
    int one = 0;
    while(one < 30 && vec[one] != 1)one++;
    if(one == 30)return x;
    vec[one] = 2;
    for(int i = one - 1;i >= 0;i--)vec[i] = 0;
    return to_int(vec);
}

Int down(Int x){
    auto vec = to_vec(x);
    int one = 0;
    while(one < 30 && vec[one] != 1)one++;
    if(one == 30)return x;
    vec[one] = 0;
    for(int i = one - 1;i >= 0;i--)vec[i] = 2;
    return to_int(vec);
}

Int next_colision(Int a, Int b){
    auto a_vec = to_vec(a);
    auto b_vec = to_vec(b);
    int one = 0;
    while(one < 30 && a_vec[one] != 1)one++;
    if(one == 30)return INF;
    while(b_vec[one] % 3 != 1)b_vec[one]++;
    for(int i = one-1;i >= 0;i--)b_vec[i] = 0;
    for(int i = one;i < 30;i++){
        b_vec[i+1] += b_vec[i] / 3;
        b_vec[i] %= 3;
    }
    return to_int(b_vec);
}

Int prev_colision(Int a, Int b){
    auto a_vec = to_vec(a);
    auto b_vec = to_vec(b);
    int one = 0;
    while(one < 30 && a_vec[one] != 1)one++;
    if(one == 30)return INF;
    while(b_vec[one] % 3 != 1)b_vec[one]++;
    if(b_vec[one] == 0){
        int x;
        for(x = one;b_vec[x] == 0 && x < 30;x++){
            b_vec[x] = 2;
        }
        if(x == 30)return -1;
    }
    b_vec[one] = 1;
    for(int i = one-1;i >= 0;i--)b_vec[i] = 2;
    return to_int(b_vec);
}



Int clac(Int a, Int b, Int c, Int d){
    Int dist = abs(a-c) + abs(b-d);
    Int t = 1;
    for(int i = 0;i < 33;i++){
        if(a / t == c / t && between(a/t, b/t, d/t)){
            ans = max(ans, 
        }
        t *= 3;
    }
}


void solve(){
    Int a, b, c, d;
    cin >> a >> b >> c >> d;
    a--,b--,c--,d--;
    Int ans = calc(a, b, c, d);
    ans = min(calc(b, a, d, c));
    cout << ans << endl;
}

int main(){
    cin >> q;
    while(q--)solve();
    return 0;
}

Compiler output:
a.cc:6:9: error: 'pair' does not name a type
    6 | typedef pair<Int, Int> P;
      |         ^~~~
a.cc:8:1: error: 'vector' does not name a type
    8 | vector<int> to_vec(Int x){
      | ^~~~~~
a.cc:17:12: error: 'vector' was not declared in this scope
   17 | Int to_int(vector<int> vec){
      |            ^~~~~~
a.cc:17:19: error: expected primary-expression before 'int'
   17 | Int to_int(vector<int> vec){
      |                   ^~~
a.cc: In function 'Int up(Int)':
a.cc:27:16: error: 'to_vec' was not declared in this scope
   27 |     auto vec = to_vec(x);
      |                ^~~~~~
a.cc:33:18: error: 'to_int' cannot be used as a function
   33 |     return to_int(vec);
      |            ~~~~~~^~~~~
a.cc: In function 'Int down(Int)':
a.cc:37:16: error: 'to_vec' was not declared in this scope
   37 |     auto vec = to_vec(x);
      |                ^~~~~~
a.cc:43:18: error: 'to_int' cannot be used as a function
   43 |     return to_int(vec);
      |            ~~~~~~^~~~~
a.cc: In function 'Int next_colision(Int, Int)':
a.cc:47:18: error: 'to_vec' was not declared in this scope; did you mean 'a_vec'?
   47 |     auto a_vec = to_vec(a);
      |                  ^~~~~~
      |                  a_vec
a.cc:58:18: error: 'to_int' cannot be used as a function
   58 |     return to_int(b_vec);
      |            ~~~~~~^~~~~~~
a.cc: In function 'Int prev_colision(Int, Int)':
a.cc:62:18: error: 'to_vec' was not declared in this scope; did you mean 'a_vec'?
   62 |     auto a_vec = to_vec(a);
      |                  ^~~~~~
      |                  a_vec
a.cc:77:18: error: 'to_int' cannot be used as a function
   77 |     return to_int(b_vec);
      |            ~~~~~~^~~~~~~
a.cc: In function 'Int clac(Int, Int, Int, Int)':
a.cc:83:16: error: 'abs' was not declared in this scope
   83 |     Int dist = abs(a-c) + abs(b-d);
      |                ^~~
a.cc:86:30: error: 'between' was not declared in this scope
   86 |         if(a / t == c / t && between(a/t, b/t, d/t)){
      |                              ^~~~~~~
a.cc:87:13: error: 'ans' was not declared in this scope
   87 |             ans = max(ans,
      |             ^~~
a.cc:88:9: error: expected primary-expression before '}' token
   88 |         }
      |         ^
a.cc:91:1: warning: no return statement in function returning non-void [-Wreturn-type]
   91 | }
      | ^
a.cc: In function 'void solve()':
a.cc:96:5: error: 'cin' was not declared in this scope
   96 |     cin >> a >> b >> c >> d;
      |     ^~~
a.cc:98:15: error: 'calc' was not declared in this scope; did you mean 'clac'?
   98 |     Int ans = calc(a, b, c, d);
      |               ^~~~
      |               clac
a.cc:99:11: error: 'min' was not declared in this scope
   99 |     ans = min(calc(b, a, d, c));
      |           ^~~
a.cc:100:5: error: 'cout' was not declared in this scope
  100 |     cout << ans << endl;
      |     ^~~~
a.cc:100:20: error: 'endl' was not declared in this scope
  100 |     cout << ans << endl;
      |                    ^~~~
a.cc: In function 'int main()':
a.cc:104:5: error: 'cin' was not declared in this scope
  104 |     cin >> q;
      |     ^~~
a.cc:104:12: error: 'q' was not declared in this scope
  104 |     cin >> q;
      |            ^