Language: C++

#include<iostream>
#include<vector>
#include<algorithm>
#include<map>
using namespace std;


int main(int argc, char *argv[]){
  int n, w, h;
  pair<int, int> p[7][4];
  cin >> n;
  for (int r = 0; r < n; r++) {
    map<char, int> matrial;
    cin >> h >> w;

    char grid[h][w];
    for (int i = 0; i < h; i++) {
      for (int j = 0; j < w; j++) {
        cin >> grid[i][j];
        if(grid[i][j] != '.' && matrial.find(grid[i][j]) == matrial.end()){
          matrial[grid[i][j]] = matrial.size();
        }
      }
    }

    for (int i = 0; i < matrial.size(); i++) {
      p[i][0].first = 1e9, p[i][0].second = 1e9;
      p[i][1].first = 0,   p[i][1].second = 0;
    }
    vector<int> perm(matrial.size());
    for (int i = 0; i < matrial.size(); i++) {
      perm[i] = i;
    }

    for (int i = 0; i < h; i++) {
      for (int j = 0; j < w; j++) {
        if(matrial.find(grid[i][j]) != matrial.end()){
          int minx = p[matrial[grid[i][j]]][0].first;
          int miny = p[matrial[grid[i][j]]][0].second;
          int maxx = p[matrial[grid[i][j]]][1].first;
          int maxy = p[matrial[grid[i][j]]][1].second;
          p[matrial[grid[i][j]]][0].first  = min(minx, j);
          p[matrial[grid[i][j]]][0].second = min(miny, i);
          p[matrial[grid[i][j]]][1].first  = max(maxx, j);
          p[matrial[grid[i][j]]][1].second = max(maxy, i);
        }
      }
    }
    // for (auto &a: matrial){
    //   std::cout << a.first << " " << a.second << std::endl;
    // }
    // for (int i = 0; i < matrial.size(); i++) {
    //   std::cout << "min:" << std::endl;
    //   std::cout << p[i][0].first << " " << p[i][0].second << std::endl;
    //   std::cout << "max:" << std::endl;
    //   std::cout << p[i][1].first << " " << p[i][1].second << std::endl;
    // }
    // std::cout << matrial.size() << std::endl;
    
     bool flag = false;
    do{
      for (int i = 0; i < matrial.size(); i++) {
        for (int j = p[i][0].second; j <= p[i][1].second; j++) {
          for (int k = p[i][0].first; k <= p[i][1].first; k++) {
            if(grid[j][k] != '.' && perm[matrial[grid[j][k]]] <= perm[i])continue;
            i = 10;
            j = p[i][1].second + 1;
            k = p[i][1].first  + 1;
          }
        }
        if(i == matrial.size() - 1){
          flag = true;
        //   for (auto &a: perm) {
        //     std::cout << a << " ";
        //   }
        //   std::cout << std::endl;
        // } 
      }
    }while(next_permutation(perm.begin(), perm.end()));
    if(flag || matrial.size() == 0){
      std::cout << "SAFE" << std::endl;
    }else{
      std::cout << "SUSPICIOUS" << std::endl;
    }
  }
  return 0;
}

Compiler output:
a.cc: In function 'int main(int, char**)':
a.cc:86:10: error: expected 'while' before numeric constant
   86 |   return 0;
      |          ^
a.cc:86:10: error: expected '(' before numeric constant
   86 |   return 0;
      |          ^
      |          (
a.cc:86:11: error: expected ')' before ';' token
   86 |   return 0;
      |          ~^
      |           )
a.cc:87:2: error: expected '}' at end of input
   87 | }
      |  ^
a.cc:8:33: note: to match this '{'
    8 | int main(int argc, char *argv[]){
      |                                 ^