Language: C++

#include <iostream>
#include <algorithm>
#include <vector>
#include <cstring>
#include <string>




using namespace std;




typedef unsigned short us;




int N;
int M;




us toHex(string s){
&#160; &#160; us num=0;
&#160; &#160; for(int j=0;j<=1;j++){
&#160; &#160; &#160; &#160; if(s[j]>='0'&&s[j]<='9')num+=s[j]-'0';
&#160; &#160; &#160; &#160; else num+=s[j]-'A'+10;
&#160; &#160; &#160; &#160; if(j==0)num=(num<<4);
&#160; &#160; }
&#160; &#160; return num;
}
vector<us> toHexList(string s){
&#160; &#160; vector<us> vus;
&#160; &#160; for(int i=0;i<s.size();i+=2){
&#160; &#160; &#160; &#160; string ss=s.substr(i,2);
&#160; &#160; &#160; &#160; us num=toHex(ss);
&#160; &#160; &#160; &#160; vus.push_back(num);
&#160; &#160; }
&#160; &#160; return vus;
}
string toStr(us num){
&#160; &#160; us a=num&(0x0F);
&#160; &#160; us b=(num&(0xF0))>>4;
&#160; &#160; string s;
&#160; &#160; if(b>=0&&b<=9)s+=('0'+b);
&#160; &#160; else s+=('A'+b-10);
&#160; &#160; if(a>=0&&a<=9)s+=('0'+a);
&#160; &#160; else s+=('A'+a-10);
&#160; &#160; return s;
}




vector<us> dePos(vector<us> vus){
&#160; &#160; if(vus.size()==1)return vus;
&#160; &#160; int sz=vus.size();
&#160; &#160; for(int i=1;i<=sz;i++){
&#160; &#160; &#160; &#160; if(sz%i!=0)continue;
&#160; &#160; &#160; &#160; bool isDecom=true;
&#160; &#160; &#160; &#160; for(int j=0;j<sz;j++){
&#160; &#160; &#160; &#160; &#160; &#160; if(j%(sz/i)==0)continue;
&#160; &#160; &#160; &#160; &#160; &#160; else if(vus[j]!=0){
&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; isDecom=false;
&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; break;
&#160; &#160; &#160; &#160; &#160; &#160; }
&#160; &#160; &#160; &#160; }
&#160; &#160; &#160; &#160; if(isDecom){
&#160; &#160; &#160; &#160; &#160; &#160; vector<us> res;
&#160; &#160; &#160; &#160; &#160; &#160; for(int j=0;j<sz;j++){
&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; if(j%(sz/i)==0){
&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; res.push_back(vus[j]);
&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; }
&#160; &#160; &#160; &#160; &#160; &#160; }
&#160; &#160; &#160; &#160; &#160; &#160; return res;
&#160; &#160; &#160; &#160; }
&#160; &#160; }
&#160; &#160; return vus;
}
vector<us> nums[10];




typedef long long ll;
ll gcd(ll a,ll b){
&#160; &#160; if(b==0)return a;
&#160; &#160; return gcd(b,a%b);
}
ll lcm(ll a,ll b){
&#160; &#160; return a*b/gcd(a,b);
}








int main(){




&#160; &#160; cin>>N;
&#160; &#160; while(N--){
&#160; &#160; &#160; &#160; cin>>M;
&#160; &#160; &#160; &#160; ll L=1;
&#160; &#160; &#160; &#160; bool con=false;
&#160; &#160; &#160; &#160; for(int i=0;i<M;i++){
&#160; &#160; &#160; &#160; &#160; &#160; string s;
&#160; &#160; &#160; &#160; &#160; &#160; cin>>s;
&#160; &#160; &#160; &#160; &#160; &#160; nums[i]=dePos(toHexList(s));
&#160; &#160; &#160; &#160; &#160; &#160; bool match=true;
&#160; &#160; &#160; &#160; &#160; &#160; for(int j=1;j<nums[i].size();j++){
&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; if(nums[i][0]!=nums[i][j])match=false;
&#160; &#160; &#160; &#160; &#160; &#160; }
&#160; &#160; &#160; &#160; &#160; &#160; if(match){
&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; vector<us> tmp;
&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; tmp.push_back(nums[i][0]);
&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; nums[i]=tmp;
&#160; &#160; &#160; &#160; &#160; &#160; }
&#160; &#160; &#160; &#160; &#160; &#160; L=lcm(L,(ll)nums[i].size());
&#160; &#160; &#160; &#160; &#160; &#160; if(L>1024){
&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; cout<<"Too complex."<<endl;
&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; con=true;
&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; break;
&#160; &#160; &#160; &#160; &#160; &#160; }
&#160; &#160; &#160; &#160; }
&#160; &#160; &#160; &#160; if(con)continue;
&#160; &#160; &#160; &#160; for(int i=0;i<M;i++){
&#160; &#160; &#160; &#160; &#160; &#160; if(nums[i].size()==L)continue;
&#160; &#160; &#160; &#160; &#160; &#160; else{
&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; vector<us> nlis;
&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; for(int j=0;j<L;j++){
&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; if(j%(L/nums[i].size())==0)nlis.push_back(nums[i][j/(L/nums[i].size())]);
&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; else nlis.push_back(0);
&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; }
&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; nums[i]=nlis;
&#160; &#160; &#160; &#160; &#160; &#160; }
&#160; &#160; &#160; &#160; }
&#160; &#160; &#160; &#160; vector<us> res;
&#160; &#160; &#160; &#160; for(int i=0;i<L;i++){
&#160; &#160; &#160; &#160; &#160; &#160; us num=0;
&#160; &#160; &#160; &#160; &#160; &#160; for(int j=0;j<M;j++)num|=nums[j][i];
&#160; &#160; &#160; &#160; &#160; &#160; res.push_back(num);
&#160; &#160; &#160; &#160; }
&#160; &#160; &#160; &#160; res=dePos(res);
&#160; &#160; &#160; &#160; //if(res.size()>1024)cout<<"Too complex."<<endl;
&#160; &#160; &#160; &#160; //else{
&#160; &#160; &#160; &#160; for(int i=0;i<res.size();i++)cout<<toStr(res[i]);
&#160; &#160; &#160; &#160; cout<<endl;
&#160; &#160; &#160; &#160; //}
&#160; &#160; }




&#160; &#160; return 0;
}

Compiler output:
a.cc:27:2: error: stray '#' in program
   27 | &#160; &#160; us num=0;
      |  ^
a.cc:27:9: error: stray '#' in program
   27 | &#160; &#160; us num=0;
      |         ^
a.cc:28:2: error: stray '#' in program
   28 | &#160; &#160; for(int j=0;j<=1;j++){
      |  ^
a.cc:28:9: error: stray '#' in program
   28 | &#160; &#160; for(int j=0;j<=1;j++){
      |         ^
a.cc:29:2: error: stray '#' in program
   29 | &#160; &#160; &#160; &#160; if(s[j]>='0'&&s[j]<='9')num+=s[j]-'0';
      |  ^
a.cc:29:9: error: stray '#' in program
   29 | &#160; &#160; &#160; &#160; if(s[j]>='0'&&s[j]<='9')num+=s[j]-'0';
      |         ^
a.cc:29:16: error: stray '#' in program
   29 | &#160; &#160; &#160; &#160; if(s[j]>='0'&&s[j]<='9')num+=s[j]-'0';
      |                ^
a.cc:29:23: error: stray '#' in program
   29 | &#160; &#160; &#160; &#160; if(s[j]>='0'&&s[j]<='9')num+=s[j]-'0';
      |                       ^
a.cc:30:2: error: stray '#' in program
   30 | &#160; &#160; &#160; &#160; else num+=s[j]-'A'+10;
      |  ^
a.cc:30:9: error: stray '#' in program
   30 | &#160; &#160; &#160; &#160; else num+=s[j]-'A'+10;
      |         ^
a.cc:30:16: error: stray '#' in program
   30 | &#160; &#160; &#160; &#160; else num+=s[j]-'A'+10;
      |                ^
a.cc:30:23: error: stray '#' in program
   30 | &#160; &#160; &#160; &#160; else num+=s[j]-'A'+10;
      |                       ^
a.cc:31:2: error: stray '#' in program
   31 | &#160; &#160; &#160; &#160; if(j==0)num=(num<<4);
      |  ^
a.cc:31:9: error: stray '#' in program
   31 | &#160; &#160; &#160; &#160; if(j==0)num=(num<<4);
      |         ^
a.cc:31:16: error: stray '#' in program
   31 | &#160; &#160; &#160; &#160; if(j==0)num=(num<<4);
      |                ^
a.cc:31:23: error: stray '#' in program
   31 | &#160; &#160; &#160; &#160; if(j==0)num=(num<<4);
      |                       ^
a.cc:32:2: error: stray '#' in program
   32 | &#160; &#160; }
      |  ^
a.cc:32:9: error: stray '#' in program
   32 | &#160; &#160; }
      |         ^
a.cc:33:2: error: stray '#' in program
   33 | &#160; &#160; return num;
      |  ^
a.cc:33:9: error: stray '#' in program
   33 | &#160; &#160; return num;
      |         ^
a.cc:36:2: error: stray '#' in program
   36 | &#160; &#160; vector<us> vus;
      |  ^
a.cc:36:9: error: stray '#' in program
   36 | &#160; &#160; vector<us> vus;
      |         ^
a.cc:37:2: error: stray '#' in program
   37 | &#160; &#160; for(int i=0;i<s.size();i+=2){
      |  ^
a.cc:37:9: error: stray '#' in program
   37 | &#160; &#160; for(int i=0;i<s.size();i+=2){
      |         ^
a.cc:38:2: error: stray '#' in program
   38 | &#160; &#160; &#160; &#160; string ss=s.substr(i,2);
      |  ^
a.cc:38:9: error: stray '#' in program
   38 | &#160; &#160; &#160; &#160; string ss=s.substr(i,2);
      |         ^
a.cc:38:16: error: stray '#' in program
   38 | &#160; &#160; &#160; &#160; string ss=s.substr(i,2);
      |                ^
a.cc:38:23: error: stray '#' in program
   38 | &#160; &#160; &#160; &#160; string ss=s.substr(i,2);
      |                       ^
a.cc:39:2: error: stray '#' in program
   39 | &#160; &#160; &#160; &#160; us num=toHex(ss);
      |  ^
a.cc:39:9: error: stray '#' in program
   39 | &#160; &#160; &#160; &#160; us num=toHex(ss);
      |         ^
a.cc:39:16: error: stray '#' in program
   39 | &#160; &#160; &#160; &#160; us num=toHex(ss);
      |                ^
a.cc:39:23: error: stray '#' in program
   39 | &#160; &#160; &#160; &#160; us num=toHex(ss);
      |                       ^
a.cc:40:2: error: stray '#' in program
   40 | &#160; &#160; &#160; &#160; vus.push_back(num);
      |  ^
a.cc:40:9: error: stray '#' in program
   40 | &#160; &#160; &#160; &#160; vus.push_back(num);
      |         ^
a.cc:40:16: error: stray '#' in program
   40 | &#160; &#160; &#160; &#160; vus.push_back(num);
      |                ^
a.cc:40:23: error: stray '#' in program
   40 | &#160; &#160; &#160; &#160; vus.push_back(num);
      |                       ^
a.cc:41:2: error: stray '#' in program
   41 | &#160; &#160; }
      |  ^
a.cc:41:9: error: stray '#' in program
   41 | &#160; &#160; }
      |         ^
a.cc:42:2: error: stray '#' in program
   42 | &#160; &#160; return vus;
      |  ^
a.cc:42:9: error: stray '#' in program
   42 | &#160; &#160; return vus;
      |         ^
a.cc:45:2: error: stray '#' in program
   45 | &#160; &#160; us a=num&(0x0F);
      |  ^
a.cc:45:9: error: stray '#' in program
   45 | &#160; &#160; us a=num&(0x0F);
      |         ^
a.cc:46:2: error: stray '#' in program
   46 | &#160; &#160; us b=(num&(0xF0))>>4;
      |  ^
a.cc:46:9: error: stray '#' in program
   46 | &#160; &#160; us b=(num&(0xF0))>>4;
      |         ^
a.cc:47:2: error: stray '#' in program
   47 | &#160; &#160; string s;
      |  ^
a.cc:47:9: error: stray '#' in program
   47 | &#160; &#160; string s;
      |         ^
a.cc:48:2: error: stray '#' in program
   48 | &#160; &#160; if(b>=0&&b<=9)s+=('0'+b);
      |  ^
a.cc:48:9: error: stray '#' in program
   48 | &#160; &#160; if(b>=0&&b<=9)s+=('0'+b);
      |         ^
a.cc:49:2: error: stray '#' in program
   49 | &#160; &#160; else s+=('A'+b-10);
      |  ^
a.cc:49:9: error: stray '#' in program
   49 | &#160; &#160; else s+=('A'+b-10);
      |         ^
a.cc:50:2: error: stray '#' in program
   50 | &#160; &#160; if(a>=0&&a<=9)s+=('0'+a);
      |  ^
a.cc:50:9: error: stray '#' in program
   50 | &#160; &#160; if(a>=0&&a<=9)s+=('0'+a);
      |         ^
a.cc:51:2: error: stray '#' in program
   51 | &#160; &#160; else s+=('A'+a-10);
      |  ^
a.cc:51:9: error: stray '#' in program
   51 | &#160; &#160; else s+=('A'+a-10);
      |         ^
a.cc:52:2: error: stray '#' in program
   52 | &#160; &#160; return s;
      |  ^
a.cc:52:9: error: stray '#' in program
   52 | &#160; &#160; return s;
      |         ^
a.cc:59:2: error: stray '#' in program
   59 | &#160; &#160; if(vus.size()==1)return vus;
      |  ^
a.cc:59:9: error: stray '#' in program
   59 | &#160; &#160; if(vus.size()==1)return vus;
      |         ^
a.cc:60:2: error: stray '#' in program
   60 | &#160; &#160; int sz=vus.size();
      |  ^
a.cc:60:9: error: stray '#' in program
   60 | &#160; &#160; int sz=vus.size();
      |         ^
a.cc:61:2: error: stray '#' in program
   61 | &#160; &#160; for(int i=1;i<=sz;i++){
      |  ^
a.cc:61:9: error: stray '#' in program
   61 | &#160; &#160; for(int i=1;i<=sz;i++){
      |         ^
a.cc:62:2: error: stray '#' in program
   62 | &#160; &#160; &#160; &#160; if(sz%i!=0)continue;
      |  ^
a.cc:62:9: error: stray '#' in program
   62 | &#160; &#160; &#160; &#160; if(sz%i!=0)continue;
      |         ^
a.cc:62:16: error: stray '#' in program
   62 | &#160; &#160; &#160; &#160; if(sz%i!=0)continue;
      |                ^
a.cc:62:23: error: stray '#' in program
   62 | &#160; &#160; &#160; &#160; if(sz%i!=0)continue;
      |                       ^
a.cc:63:2: error: stray '#' in program
   63 | &#160; &#160; &#160; &#160; bool isDecom=true;
      |  ^
a.cc:63:9: error: stray '#' in program
   63 | &#160; &#160; &#160; &#160; bool isDecom=true;
      |         ^
a.cc:63:16: error: stray '#' in program
   63 | &#160; &#160; &#160; &#160; bool isDecom=true;
      |                ^
a.cc:63:23: error: stray '#' in program
   63 | &#160; &#160; &#160; &#160; bool isDecom=true;
      |                       ^
a.cc:64:2: error: stray '#' in program
   64 | &#160; &#160; &#160; &#160; for(int j=0;j<sz;j++){
      |  ^
a.cc:64:9: error: stray '#' in program
   64 | &#160; &#160; &#160; &#160; for(int j=0;j<sz;j++){
      |         ^
a.cc:64:16: error: stray '#' in program
   64 | &#160; &#160; &#160; &#160; for(int j=0;j<sz;j++){
      |                ^
a.cc:64:23: error: stray '#' in program
   64 | &#160; &#160; &#160; &#160; for(int j=0;j<sz;j++){
      |                       ^
a.cc:65:2: error: stray '#' in program
   65 | &#160; &#160; &#160; &#160; &#160; &#160; if(j%(sz/i)==0)continue;
      |  ^
a.cc:65:9: error: stray '#' in program
   65 | &#160; &#160; &#160; &#160; &#160; &#160; if(j%(sz/i)==0)continue;
      |         ^
a.cc:65:16: error: stray '#' in program
   65 | &#160; &#160; &#160; &#160; &#160; &#160; if(j%(sz/i)==0)continue;
      |                ^
a.cc:65:23: error: stray '#' in program
   65 | &#160; &#160; &#160; &#160; &#160; &#160; if(j%(sz/i)==0)continue;
      |                       ^
a.cc:65:30: error: stray '#' in program
   65 | &#160; &#160; &#160; &#160; &#160; &#160; if(j%(sz/i)==0)continue;
      |                              ^
a.cc:65:37: error: stray '#' in program
   65 | &#160; &#160; &#160; &#160; &#160; &#160; if(j%(sz/i)==0)continue;
      |                                     ^
a.cc:66:2: error: stray '#' in program
   66 | &#160; &#160; &#160; &#160; &#160; &#160; else if(vus[j]!=0){
      |  ^
a.cc:66:9: error: stray '#' in program
   66 | &#160; &#160; &#160; &#160; &#160; &#160; else if(vus[j]!=0){
      |         ^
a.cc:66:16: error: stray '#' in program
   66 | &#160; &#160; &#160; &#160; &#160; &#160; else if(vus[j]!=0){
      |                ^
a.cc:66:23: error: stray '#' in program
   66 | &#160; &#160; &#160; &#160; &#160; &#160; else if(vus[j]!=0){
      |                       ^
a.cc:66:30: error: stray '#' in program
   66 | &#160; &#160; &#160; &#160; &#160; &#160; else if(vus[j]!=0){
      |                              ^
a.cc:66:37: error: stray '#' in program
   66 | &#160; &#160; &#160; &#160; &#160; &#160; else if(vus[j]!=0){
      |                                     ^
a.cc:67:2: error: stray '#' in program
   67 | &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; isDecom=false;
      |  ^
a.cc:67:9: error: stray '#' in program
   67 | &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; isDecom=false;
      |         ^
a.cc:67:16: error: stray '#' in program
   67 | &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; isDecom=false;
      |                ^
a.cc:67:23: error: stray '#' in program
   67 | &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; isDecom=false;
      |                       ^
a.cc:67:30: error: stray '#' in program
   67 | &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; isDecom=false;
      |