Problem:
Problem F:
Problem F: リズムマシーン
Advanced Computer Music社（ACM社）は，
    あらかじめプログラムされたリズム通りに音楽を演奏する
    リズムマシーンを販売していた．
    ある時，ACM社は新しいリズムマシーンを開発して売り出そうとしていた．
    ACM社の旧製品は同時に1つの音しか鳴らすことができなかったのに対し，
    新製品では最大で8つの音を同時に鳴らせるようになるというのが
    一番の目玉機能であった．
    今まで複数の旧製品を利用して演奏する必要のあった曲が
    新製品1台で済むようになるので，
    ACM社は新製品への移行を推進させるために，
    複数の旧製品向けのリズムパターンを1つの新製品向けのリズムパターンに
    変換するプログラムを作ることにした．
ACM社のリズムマシーンでは，同時にどの音を鳴らすかを2桁の16進数で表現する．
    ACM社のリズムマシーンは8つの異なる音を鳴らすことが可能で，
    それぞれの音には0から7の番号が割り当てられている．
    あるタイミングにおいて，音
i
(0 ≤
i
< 8)
    を鳴らす場合を
s
i
= 1，
    鳴らさない場合を
s
i
= 0 とする．
    このとき，それぞれの音を同時に鳴らしたような和音を
という値で表し，
    この値を2桁の16進数表記で表した「和音表現」
    がリズムパターンの中で用いられる（16進数の英字は大文字を用いる）．
    例えば，音0, 6, 7 を同時に鳴らすような和音は
S
= 2
0
+ 2
6
+ 2
7
= C1
(16)
となるから “
C1
” と表現され，
    また何も鳴らさないような「和音」は 
    “
00
” と表現される．
リズムパターンは，上記のような和音表現を1つ以上並べたものとして与えられる．
    あるリズムパターン文字列は，1小節内の演奏パターンを示している．
    それぞれの和音を鳴らすタイミングを小節内の相対位置
t
(0 ≤
t
< 1)
    で表現することにする．
k
個の和音表現からなるリズムパターン文字列は，
    小節を
k
等分しそれぞれの和音を順に
t
= 0/
k
, 1/
k
, ...,
    (
k
−1)/
k
のタイミングで演奏するような
    リズムパターンを表している．
    例えば，リズムパターン “
01000003
” は，
t
= 0/4 のタイミングで音0を演奏し，
t
= 3/4 のタイミングで音0, 1を演奏することを表す．
    また，リズムパターン “
00
”
    は小節内で何も音を鳴らさないことを表す
    （リズムパターンには和音表現が1つ以上必要であることに注意せよ）．
旧製品は同時に1つの音しか鳴らせないため，
    旧製品向けのリズムパターン文字列内には
    “
00
”,
    “
01
”,
    “
02
”,
    “
04
”,
    “
08
”,
    “
10
”,
    “
20
”,
    “
40
”,
    “
80
”
    のいずれかの和音表現しか現れない．
    旧製品向けのリズムパターンを
N
個
    (1 ≤
N
≤ 8) 受け取り，
    それらのリズムパターンを同時に演奏するような
    新製品向けのリズムパターンを出力するプログラムを書いて欲しい．
与えられる
N
個のリズムパターンにおいて，
    まったく同じタイミングで同じ音が演奏されることはないと仮定してよい．
Input
最初の行にデータセットの数が与えられる．
    次の行以降には，それぞれのデータセットが順に記述されている．
    データセットの数は 120 を越えないと仮定してよい．
それぞれのデータセットは以下のような形式で与えられる．
N
R
1
R
2
...
R
N
R
i
(1 ≤
i
≤
N
)
    はそれぞれ旧製品向けのリズムパターンである．
各リズムパターンは最大で2048文字（1024和音表現）である．
    与えられるリズムパターンは必ずしも最短の表現になっていないことに注意せよ．
Output
各データセットについて，与えられた
N
個のリズムパターンを
    すべて同時に演奏するような最短のリズムパターンを生成し，
    1行で出力せよ．
    そのようなリズムパターンが2048文字を越える場合，
    リズムパターンの代わりに “
Too complex.
”
    という文字列を出力せよ．
Sample Input
5
2
01000100
00020202
2
0102
00000810
1
0200020008000200
5
0001
000001
0000000001
00000000000001
0000000000000000000001
1
000000
Output for the Sample Input
01020302
01000A10
02020802
Too complex.
00

Submitted solutions:

code_snippet: // g++ -std=c++11 a.cpp
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>	
#include<map>
#include<set>
#include<unordered_map>
#include<utility>
#include<cmath>
#include<random>
#include<cstring>
#include<queue>
#include<stack>
#include<bitset>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#include<typeinfo>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define FOR(i,a) for(auto i:a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
using namespace std;
//kaewasuretyuui
typedef long long ll;
//#define int ll
typedef int Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
#define mt make_tuple
typedef tuple<int,int,int> tp;
typedef vector<tp> vt;
template<typename A,typename B>bool cmin(A &a,const B &b){return a>b?(a=b,true):false;}
template<typename A,typename B>bool cmax(A &a,const B &b){return a<b?(a=b,true):false;}
//template<class C>constexpr int size(const C &c){return (int)c.size();}
//template<class T,size_t N> constexpr int size(const T (&xs)[N])noexcept{return (int)N;}
const double PI=acos(-1);
const double EPS=1e-9;
Def inf = sizeof(Def) == sizeof(long long) ? 2e18 : 1e9+10;
int dx[]={0,1,0,-1};
int dy[]={1,0,-1,0};
ll gcd(ll a,ll b){
	return (b==0?a:gcd(b,a%b));
}
ll lcm(ll a,ll b){
	return a/gcd(a,b)*b;
}
int main(){
	int q;
	cin>>q;
	while(q--){
		int n;cin>>n;
		vs in(n);
		rep(i,n)cin>>in[i];
		
		rep(i,n){
			int t=in[i].size()/2;
			rep(j,in[i].size())if(in[i][j]!='0')t=gcd(t,j/2);
			if(t==0){
				in[i]="00";
			}else{
				string w="";
				rep(j,in[i].size()/t/2){
					w+=in[i][j*2*t];
					w+=in[i][j*2*t+1];
				}
				in[i]=w;
			}
		}
		ll t=1;
		rep(i,n){
			t=lcm(t,in[i].size());
			if(t>2048)break;
		}
//		rep(i,n)cout<<in[i]<<endl;cout<<endl;
		if(t>2048)cout<<"Too complex."<<endl;
		else{
			rep(i,n){
				int w=t/in[i].size();
				string a="";
				rep(j,in[i].size()/2){
					a+=in[i][2*j];
					a+=in[i][2*j+1];
					a+=string(2*w-2,'0');
				}
				in[i]=a;
			}
			rep(i,t){
				int s=0;
				rep(j,n)s+=in[j][i]-'0';
				printf("%01X",s);
			}
			cout<<endl;
		}
	}
}
accuracy: 1
time_ms: 10
memory_kb: 3348
final_rank: 17

code_snippet: #include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;

vector<long long int> divisor(long long int n) {
	vector<long long int> res;
	for (long long int i = 1; i * i <= n; ++i) {
		if (n % i == 0) {
			res.push_back(i);
			if (i * i != n) res.push_back(n / i);
		}
	}
	sort(begin(res), end(res));
	return res;
}

vector<int>compress(vector<int>nums) {
	auto divs(divisor(nums.size()));
	reverse(divs.begin(),divs.end());
	for (auto div : divs) {
		bool ok=true;

		for (int i = 0; i < nums.size() / div; ++i) {
			for (int j = 1; j < div; ++j) {
				if(nums[i*div+j])ok=false;
			}
		}
		if (ok) {
			vector<int>ans(nums.size()/div);
			for (int i = 0; i < nums.size() / div; ++i) {
				ans[i]=nums[i*div];
			}
			return ans;
		}
	}
	assert(false);
	return vector<int>();
}

vector<int>mk(string st) {
	vector<int>nums(st.size()/2);
	for (int i = 0; i < st.size() / 2; ++i) {
		char c1 = st[2*i];
		char c2=st[2*i+1];
		int num=!isdigit(c1)?(c1-'A'+10):c1-'0';
		num*=16;
		num+=!isdigit(c2)?(c2-'A'+10):c2-'0';

		nums[i]=num;
	}
	return compress(nums);
}

long long int gcd(long long int l, long long int r) {
	if (l > r)return gcd(r, l);
	else {
		if (r%l) {
			return gcd(l, r%l);

		}
		else {
			return l;
		}
	}
}

int main() {
	int Q;cin>>Q;
	while (Q--) {
		int N;cin>>N;

		vector<vector<int>>rythms;
		for (int i = 0; i < N; ++i) {
			string st; cin >> st;
			rythms.push_back(mk(st));
		}

		int alca=1;
		for (int i = 0; i < N; ++i) {
			alca=alca*rythms[i].size()/gcd(alca,rythms[i].size());
			if (alca > 1024) {
				alca=-1;
				break;
			}
		}
		if (alca == -1) {
			cout<<"Too complex."<<endl;
		}
		else {
			vector<int>anss(alca);
			for (auto rythm: rythms) {
				
				for (int i = 0; i < rythm.size(); ++i) {
					anss[i*(alca/rythm.size())] |= rythm[i];
				}
				
			}
			anss=compress(anss);
			for (auto ans : anss) {
				int l=ans/16;
				int r=ans%16;
				if(l>=10)cout<<string(1,char('A'+l-10));
				else cout<<l;

				if(r>=10)cout<<string(1,char('A'+r-10));
				else cout<<r;
			}
			cout<<endl;
		}
	}
	return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 3260
final_rank: 16

code_snippet: #include<iostream>
#include<vector>
#include<string>
#include<algorithm>	
#include<map>
#include<set>
#include<utility>
#include<cmath>
#include<cstring>
#include<queue>
#include<stack>
#include<cstdio>
#include<sstream>
#include<iomanip>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
using namespace std;
//kaewasuretyuui
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<int,pii> pip;
typedef vector<pip>vip;
const double PI=acos(-1);
const double EPS=1e-5;
const int inf=1e8;
int gcd(int a,int b){
	return (b==0?a:gcd(b,a%b));
}
ll lcm(ll a,ll b){
	return a/gcd(a,b)*b;
}
int main(){
	int q;
	cin>>q;
	while(q--){
		int n;
		cin>>n;
		vvi in(n);
		vi tmp;
		rep(i,n){
			string s;
			cin>>s;
			int N=s.size();
			tmp=vi(N/2);
			int gc=N/2;
			rep(j,N/2){
				tmp[j]=(s[2*j]-'0')*16+(s[2*j+1]-'0');
				if(j&&tmp[j])gc=gcd(gc,j);
			}
			for(int j=0;j<N/2;j+=gc)in[i].pb(tmp[j]);
		}
		int lc=1;
		rep(i,n){
			lc=lcm(lc,in[i].size());
			if(lc>1024)break;
		}
		if(lc>1024)cout<<"Too complex."<<endl;
		else{
			vi out(lc);
			rep(i,n){
				int t=lc/in[i].size();
				for(int j=0;j<lc;j+=t)out[j]|=in[i][j/t];
			}
			rep(i,lc)printf("%02X",out[i]);
			cout<<endl;
		}
	}
}
accuracy: 1
time_ms: 10
memory_kb: 3216
final_rank: 14

code_snippet: #include <bits/stdc++.h>
using namespace std;

vector<int> simple(string s){
	vector<int> v;
	for(int i = 0 ; i < s.size() ; i += 2 ){
		v.push_back((s[i]-'0')*16+s[i+1]-'0');
	}
	for(int i = 1 ; i <= v.size() ; i++){
		if( v.size() % i ) continue;
		int l = v.size() / i;
		int f = 1;
		for(int j = 0 ; j < v.size() ; j++){
			if( j % l && v[j] > 0 ) f = 0;
		}
		if(f){
			vector<int> t;
			for(int j = 0 ; j < v.size() ; j += l )
				t.push_back(v[j]);
			v = t;
			break;
		}
	}
	/*for(int i = 1 ; i <= v.size() ; i++){
		if( v.size() % i ) continue;
		int f = 1;
		for(int j = 0 ; j < v.size() ; j+=i){
			for(int k = 0 ; k < i ; k++){
				if( v[j+k] != v[k] ) f = 0;
			}
		}
		if(f){
			v.resize(i);
			return v;
		}
	}*/
	return v;
}
int main(){
	int T;
	cin >> T;
	while(T--){
		int n;
		cin >> n;
		int ans = 1;
		vector< vector<int> > vs;
		for(int i = 0 ; i < n ; i++){
			string r;
			cin >> r;
			vs.push_back(simple(r));
			ans = ans * vs.back().size() / __gcd(ans,(int)vs.back().size());
			ans = min(2000,ans);
		}
		if( ans > 1024 ){
			cout << "Too complex." << endl;
		}else{
			vector<int> a(ans);
			for(int i = 0 ; i < vs.size() ; i++){
				int span = ans / vs[i].size();
				for(int j = 0 ; j < vs[i].size() ; j++)
					a[span*j] |= vs[i][j];
			}
			for(int i = 0 ; i < a.size() ; i++)
				printf("%02X",a[i]);
			cout << endl;
		}
	}
}
accuracy: 1
time_ms: 20
memory_kb: 1320
final_rank: 9

code_snippet: #include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const int MAX_M = 1024 * 8;

/* typedef */

typedef unsigned char uchar;
typedef vector<uchar> vuc;

int gcd(int m, int n);

struct Rhythm {
  int m;
  vuc bytes;

  Rhythm() { m = 1; bytes.push_back(0); }
  Rhythm(string rstr) {
    m = rstr.length() / 2;
    bytes.assign(m, 0);
    for (int i = 0; i < m; i++) {
      uchar c0 = rstr[i * 2], c1 = rstr[i * 2 + 1];
      bytes[i] = ((c0 - '0') << 4) | (c1 - '0');
    }
    normalize();
  }

  void normalize() {
    for (int k = 2; k <= m; k++) {
      if (m % k) continue;

      bool ok = true;
      for (int i = 0; ok && i < m; i++)
	if ((i % k) && bytes[i]) ok = false;
      if (ok) {
	m /= k;
	for (int i = 0; i < m; i++) bytes[i] = bytes[i * k];
	k--;
      }
    }
  }

  void mul(int k) {
    vuc bytes0(bytes);
    bytes.assign(m * k, 0);

    for (int i = 0; i < m; i++) bytes[i * k] = bytes0[i];
    m *= k;
  }

  void merge(Rhythm& r0) {
    int g = __gcd(m, r0.m);
    int lcm = m * r0.m / g;

    mul(lcm / m);
    r0.mul(lcm / r0.m);
    for (int i = 0; i < m; i++) bytes[i] |= r0.bytes[i];

    normalize();
  }
  
  void print(bool flag = false) {
    if (flag) {
      printf("(%d)", m);
      for (int i = 0; i < m; i++)
	if (bytes[i]) printf("%d ", i);
    }
    for (int i = 0; i < m; i++) printf("%02X", (int)bytes[i]);
    putchar('\n');
  }
};

/* global variables */

/* subroutines */

int gcd(int m, int n) {
  if (m < n) swap(m, n);

  while (n > 0) {
    int r = m % n;
    m = n;
    n = r;
  }

  return m;
}

/* main */

int main() {
  int tn;
  cin >> tn;

  for (int cnt = 1; cnt <= tn; cnt++) {
    int n;
    cin >> n;
    //if (cnt == 33) cout << n << endl;
    
    Rhythm rt;
    //rt.print();

    for (int i = 0; i < n; i++) {
      string str;
      cin >> str;

      Rhythm ri(str);
      //if (cnt == 33) ri.print();
      if (false) {
	cout << "rt = ";
	rt.print(true);
	cout << "ri = ";
	ri.print(true);
      }

      if (rt.m < MAX_M) {
	rt.merge(ri);
	//cout << "merged to => "; rt.print(true);
      }
    }

    if (rt.m == 0 || rt.m > 1024)
      cout << "Too complex." << endl;
    else
      rt.print();
  }

  return 0;
}
accuracy: 1
time_ms: 50
memory_kb: 2708
final_rank: 20

code_snippet: #include<iostream>
#include<vector>
#include<algorithm>
#include<numeric>
#include<cctype>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define in_range(x,l,r) (l<=x && x<r)
using namespace std;
typedef vector<int> vi;

inline int CtoI(char c){
  if(isdigit(c))return c-'0';
  return c-'A'+10;
}

inline char ItoC(int a){
  if(a<10)return '0'+a;
  return 'A'+a-10;
}

inline vi red(string s){
  int n = s.size()/2;
  vi r(n);
  int nonzero = 0;
  rep(i,n){
    r[i] = CtoI(s[2*i])*16 + CtoI(s[2*i+1]);
    if(r[i])nonzero++;
  }

  for(int i=n;i>0;i--){
    if(n%i==0){
      int vals = 0;
      for(int j=0;j<n;j+=i){
	if(r[j])vals++;
      }
      if(nonzero==vals){
	vi res(n/i);
	for(int j=0;j<n;j+=i){
	  res[j/i] = r[j];
	}
	return res;
      }
    }
  }
  return r;
}
      

int main(){
  int t;
  cin >> t;
  while(t--){
    int n;
    cin >> n;
    vector< vi > r(n);
    rep(i,n){
      string s;
      cin >> s;
      r[i] = red(s);
    }

    int len = 1;
    rep(i,n){
      int s = r[i].size(), gcd = __gcd(len,s);
      if(len/gcd > 1024/s)len = 1025;
      else len = len/gcd*s;
    }

    if(len>1024){
      cout << "Too complex." << endl;
    }else{
      vi res(len,0);
      rep(i,n){
	rep(j,r[i].size()){
	  res[j*len/r[i].size()] |= r[i][j];
	}
      }

      rep(i,len){
	cout << ItoC(res[i]/16) << ItoC(res[i]%16);
      }
      cout << endl;
    }
  }
}
accuracy: 1
time_ms: 10
memory_kb: 1272
final_rank: 4

code_snippet: #include <iostream>
#include <iomanip>
#include <complex>
#include <sstream>
#include <string>
#include <algorithm>
#include <deque>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <vector>
#include <set>
#include <limits>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <ctime>
using namespace std;
#define REP(i, j) for(int i = 0; i < (int)(j); ++i)
#define FOR(i, j, k) for(int i = (int)(j); i < (int)(k); ++i)
#define SORT(v) sort((v).begin(), (v).end())
#define REVERSE(v) reverse((v).begin(), (v).end())
typedef complex<double> P;
typedef long long int Int;

Int gcd(Int a, Int b) { return a > 0 ? gcd(b % a, a) : b; }
Int lcm(int a, int b){ return a / gcd(a, b) * b; }

struct rational {
  Int p, q;
  void normalize() {
    if (q < 0) p *= -1, q *= -1;
    Int d = gcd(p < 0 ? -p : p, q);
    if (d == 0) p = 0,  q = 1;
    else        p /= d, q /= d;
  }
  rational(Int p, Int q = 1, bool norm = true) : p(p), q(q) {
    if(norm) normalize();
  }
};

bool operator < (const rational &a, const rational &b) { return (long double) a.p * b.q < (long double) a.q * b.p; }

void solve(int N, vector<string> &v){
  map<rational, int> M;
  REP(n, N){
    string s = v[n];
    for(int i = 0; i + 1 < s.length(); i += 2){
      int num = strtol(s.substr(i, 2).c_str(), NULL, 16);
      if(num) M[rational((i + 1) / 2, (int)(s.length()) / 2)] += num;
    }
  }
  if(M.size() == 0) { cout <<"00" <<endl; return ; }
  Int L = 1;
  for(auto i : M){
    L = lcm(i.first.q, L);
    if(L * 2 > 2049) { cout <<"Too complex." <<endl; return ; }
  }
  if(L * 2 > 2049) { cout <<"Too complex." <<endl; return ; }
  map<rational, int> ans;
  for(auto i : M){
    int p = i.first.p, q = i.first.q, n = i.second, m = L / q;
    ans[rational(p * m, L)] = n;
  }
  REP(i, L){
    if(ans[rational(i, L)] != 0) cout <<setfill('0') << setw(2) << hex  << uppercase << ans[rational(i, L)];
    else cout <<"00";
  }
  cout <<endl;
}

int main() {
  int T; cin >>T;
  REP(t, T){
    int N; cin >>N;
    vector<string> v(N);
    REP(i, N) cin >>v[i];
    solve(N, v);
  }
  return 0;
}
accuracy: 1
time_ms: 40
memory_kb: 1572
final_rank: 15

code_snippet: #include <iostream>
#include <algorithm>
#include <string>
using namespace std;
typedef unsigned char uc;
struct R {
  uc notes[1024];
  int num;
  void push(const uc& note) {
    notes[num++] = note;
  }
};

R rolls[8];
char hexmap[16] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'};

int gcd_of(int a, int b) {
  while (a != b) {
    if (a > b)
      a -= b;
    else
      b -= a;
  }
  return a;
}

int lcm_of(const int& a, const int& b) {
  return a * b / gcd_of(a, b);
}

int main() {
  int t;
  cin >> t;
  while (t --) {
    int n;
    cin >> n;
    for (int i = 0; i < n; i++) {
      // load
      char buff[2049];
      cin >> buff;
      char* p = buff;
      auto& r = rolls[i];
      r.num = 0;
      while (*p != 0) {
        r.push((*p - '0') * 16 + (*(p + 1) - '0'));
        p += 2;
      }

      // comp
      int gcd = r.num;
      int clen = 1;
      for (int j = 1; j < r.num; j++) {
        if (r.notes[j] == 0) {
          clen++;
        } else {
          gcd = gcd_of(gcd, clen);
          clen = 1;
          if (gcd == 1) break;
        }
      }
      gcd = gcd_of(gcd, clen);
      if (gcd != 1) {
        r.num /= gcd;
        for (int j = 0; j < r.num; j++) r.notes[j] = r.notes[j * gcd];
      }
    }
    int lcm = rolls[0].num;

    for (int i = 1; i < n; i++) {
      lcm = lcm_of(lcm, rolls[i].num);
      if (lcm > 1024) break; // for overflow
    }

    if (lcm > 1024) {
      cout << "Too complex.";
    } else {
      // combine
      int m[8];
      for (int i = 0; i < n; i++) m[i] = lcm / rolls[i].num;
      for (int i = 0; i < lcm; i++) {
        uc v = 0;
        for (int j = 0; j < n; j++) {
          if (i % m[j] == 0) v |= rolls[j].notes[i / m[j]];
        }
        cout << hexmap[v / 16] << hexmap[v % 16];
      }
    }
    cout << endl;
  }
  return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 1160
final_rank: 2

code_snippet: #include<string.h>
#include<stdio.h>
#include<algorithm>
using namespace std;
int gcd(int a,int b){
	while(a){
		b%=a;int c=a;a=b;b=c;
	}
	return b;
}
int lcm(int a,int b){
	return a/gcd(a,b)*b;
}
char str[10][11000];
int len[10];
int sz[10];
int com[10][11000];
int ret[11000];
int main(){
	int T;scanf("%d",&T);
	while(T--){
		int a;scanf("%d",&a);
		for(int i=0;i<a;i++)scanf("%s",str[i]);
		for(int i=0;i<a;i++)len[i]=strlen(str[i])/2;
		for(int i=0;i<a;i++){
			int v=0;
			for(int j=1;j<=len[i];j++){
				if(len[i]%j)continue;
				bool ok=true;
				for(int k=0;k<len[i];k++){
					if(k%j&&(str[i][k*2]!='0'||str[i][k*2+1]!='0')){ok=false;break;}
				}
				if(ok)v=j;
			}
			sz[i]=len[i]/v;
			for(int j=0;j<len[i]/v;j++){
				com[i][j]=(str[i][v*j*2]-'0')*16+(str[i][v*j*2+1]-'0');
			}
		}
		int now=1;
		for(int i=0;i<a;i++){
			now=lcm(now,sz[i]);
			if(now>1024)break;
		}
		if(now>1024){
			printf("Too complex.\n");
		}else{
			for(int i=0;i<now;i++)ret[i]=0;
			for(int i=0;i<a;i++){
				for(int j=0;j<sz[i];j++)ret[now/sz[i]*j]+=com[i][j];
			}
			for(int i=0;i<now;i++)printf("%02X",ret[i]);
			printf("\n");
		}
	}
}
accuracy: 1
time_ms: 10
memory_kb: 1172
final_rank: 3

code_snippet: #include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
using namespace std;
typedef vector<int> vi;

inline int gcd(int a, int b){ return b?gcd(b,a%b):a; }
inline int lcm(int a, int b){ return a/gcd(a,b)*b; }
inline int hex(char a){ return isdigit(a)?(a-'0'):(a-'A'); }
inline char inv_hex(int a){ return (a<10)?(a+'0'):(a-10+'A'); }

inline vi reduce(vi a){
  int n = a.size();
  for(int i=n;i>=1;i--){
    if(n%i)continue;
    bool f = true;
    rep(j,n){
      if(j%i && a[j]){	f = false; break; }
    }
    if(f){
      vi res(n/i);
      for(int j=0;j<n;j+=i)res[j/i] = a[j];
      return res;
    }
  }
  return a;
}

int main(){
  cin.tie(0); ios::sync_with_stdio(0);
  int casenum;
  cin >> casenum;
  while(casenum--){
    int n;
    cin >> n;
    int len = 1;
    vector< vi > rhythm(n);
    rep(i,n){
      string s;
      cin >> s;
      vi tmp(s.size()/2);
      rep(j,s.size()/2){
	tmp[j] = hex(s[2*j])*16 + hex(s[2*j+1]);
      }
      rhythm[i] = reduce(tmp);
      if(len<=1024)len = lcm(len,rhythm[i].size());
    }

    if(len>1024)cout << "Too complex." << endl;
    else{
      vi res(len,0);
      rep(i,n){
	int k = len/rhythm[i].size();
	rep(j,rhythm[i].size())res[j*k] |= rhythm[i][j];
      }
      rep(i,len){
	cout << inv_hex(res[i]/16) << inv_hex(res[i]%16);
      }
      cout << endl;
    }
  }
}
accuracy: 1
time_ms: 10
memory_kb: 1280
final_rank: 5

code_snippet: #include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <numeric>
#include <utility>
#include <iomanip>
#include <algorithm>
#include <functional>
using namespace std;

typedef long long ll;
typedef vector<int> vint;
typedef vector<long long> vll;
typedef pair<int,int> pint;
typedef pair<long long, long long> pll;

#define MP make_pair
#define PB push_back
#define ALL(s) (s).begin(),(s).end()
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P) 
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P) 
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P) 
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P) 
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s; }

inline int gcd(int a, int b) {
    if (b == 0) return a;
    if (a < 0) a = -a; if (b < 0) b = -b;
    return gcd(b, a % b);
}
inline int lcm(int a, int b) {
    int g = gcd(a, b);
    return a * b / g;
}
struct frac {
    int first, second;
    
    frac normalize() {
        if (second < 0) {first = -first; second = -second;}
        int d = gcd(first, second);
        if (d == 0) {first = 0; second = 1;}
        else {first /= d; second /= d;}
        return *this;
    }
    frac(int f = 0, int s = 1) : first(f), second(s) { normalize(); }
    inline frac operator - () { (*this).first *= -1; return (*this); }
    inline const frac& operator = (int a) { *this = frac(a, 1); return *this; }
    inline const frac& operator += (const frac& a);
    inline const frac& operator += (int a);
    inline const frac& operator -= (const frac& a);
    inline const frac& operator -= (int a);
    inline const frac& operator *= (const frac& a);
    inline const frac& operator *= (int a);
    inline const frac& operator /= (const frac& a);
    inline const frac& operator /= (int a);
    friend ostream& operator << (ostream& s, const frac& f) { 
        s << f.first; if (f.second != 1) s << "/" << f.second; return s;
    }
};
bool operator < (const frac& a, const frac& b) {
    return a.first * b.second < a.second * b.first;
}
bool operator > (const frac& a, const frac& b) { return b < a; }
bool operator <= (const frac& a, const frac& b) { return !(b < a); }
bool operator >= (const frac& a, const frac& b) { return !(a < b); }
bool operator != (const frac& a, const frac& b) { return a < b || b < a; }
bool operator == (const frac& a, const frac& b) { return !(a < b) && !(b < a); }

int CASE;

int BASE[16] = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' };
string str;

int main() {
    //freopen( "/Users/macuser/Dropbox/Contest/input.in", "r", stdin );
    cin >> CASE;
    for (int AAA = 0; AAA < CASE; ++AAA) {
        int n; cin >> n;
        map<frac,int> ma;
        for (int i = 0; i < n; ++i) {
            cin >> str;
            int bo = str.size();
            for (int k = 0; k < str.size(); k += 2) {
                string sub = str.substr(k, 2);
                int num = 0;
                for (int l = 0; l < 16; ++l) {
                    if (BASE[l] == sub[0]) num += l * 16;
                    if (BASE[l] == sub[1]) num += l;
                }
                if (num != 0) ma[ frac(k/2, bo/2) ] += num;
            }
        }
        int LCM = 1;
        
        bool ok = true;
        EACH(it,ma) {
            LCM = lcm(LCM, it->first.second);
            if (LCM > 1024) ok = false;
        }

        if (!ok) puts("Too complex.");
        else {
            string res = "";
            for (int i = 0; i < LCM*2; ++i) res += '0';
            EACH(it,ma) {
                int pos = (it->first.first) * LCM / (it->first.second);
                int num = it->second;
            
                char c1 = BASE[num/16];
                char c2 = BASE[num%16];
            
                res[pos*2] = c1;
                res[pos*2+1] = c2;
            }
            cout << res << endl;
        }
    }
    return 0;
}
accuracy: 1
time_ms: 40
memory_kb: 1540
final_rank: 13

code_snippet: #include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <numeric>
#include <utility>
#include <iomanip>
#include <algorithm>
#include <functional>
using namespace std;

typedef long long ll;
typedef vector<int> vint;
typedef vector<long long> vll;
typedef pair<int,int> pint;
typedef pair<long long, long long> pll;

#define MP make_pair
#define PB push_back
#define ALL(s) (s).begin(),(s).end()
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P) 
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P) 
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P) 
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P) 
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s; }

long long gcd(long long a, long long b) {
    if (b == 0) return a;
    if (a < 0) a = -a; if (b < 0) b = -b;
    return gcd(b, a % b);
}
long long lcm(long long a, long long b) {
    long long g = gcd(a, b);
    return a * b / g;
}
struct frac {
    long long first, second;
    
    frac normalize() {
        if (second < 0) {first = -first; second = -second;}
        long long d = gcd(first, second);
        if (d == 0) {first = 0; second = 1;}
        else {first /= d; second /= d;}
        return *this;
    }
    frac(long long f = 0, long long s = 1) : first(f), second(s) { normalize(); }
    inline frac operator - () { (*this).first *= -1; return (*this); }
    inline const frac& operator = (long long a) { *this = frac(a, 1); return *this; }
    inline const frac& operator += (const frac& a);
    inline const frac& operator += (long long a);
    inline const frac& operator -= (const frac& a);
    inline const frac& operator -= (long long a);
    inline const frac& operator *= (const frac& a);
    inline const frac& operator *= (long long a);
    inline const frac& operator /= (const frac& a);
    inline const frac& operator /= (long long a);
    friend ostream& operator << (ostream& s, const frac& f) { 
        s << f.first; if (f.second != 1) s << "/" << f.second; return s;
    }
};
bool operator < (const frac& a, const frac& b) {
    return (long double)(a.first) * b.second < (long double)(a.second) * b.first;
}
bool operator > (const frac& a, const frac& b) { return b < a; }
bool operator <= (const frac& a, const frac& b) { return !(b < a); }
bool operator >= (const frac& a, const frac& b) { return !(a < b); }
bool operator != (const frac& a, const frac& b) { return a < b || b < a; }
bool operator == (const frac& a, const frac& b) { return !(a < b) && !(b < a); }
frac operator + (const frac& a, const frac& b) {
    frac res;
    res.first = a.first * b.second + a.second * b.first;
    res.second = a.second * b.second;
    res.normalize();
    return res;
}
frac operator - (const frac& a, const frac& b) {
    frac res;
    res.first = a.first * b.second - a.second * b.first;
    res.second = a.second * b.second;
    res.normalize();
    return res;
}
frac operator * (const frac& a, const frac& b) {
    frac res;
    res.first = a.first * b.first;
    res.second = a.second * b.second;
    res.normalize();
    return res;
}
frac operator / (const frac& a, const frac& b) {
    frac res;
    res.first = a.first * b.second;
    res.second = a.second * b.first;
    res.normalize();
    return res;
}
frac abs(const frac& a) {
    frac res; res = a; res.normalize(); 
    if (res.first < 0) res.first = res.first * (-1);
    return res;
}
inline const frac& frac::operator += (const frac& x) {*this = *this + x; return *this;}
inline const frac& frac::operator += (long long x) {*this = *this + x; return *this;}
inline const frac& frac::operator -= (const frac& x) {*this = *this - x; return *this;}
inline const frac& frac::operator -= (long long x) {*this = *this + x; return *this;}
inline const frac& frac::operator *= (const frac& x) {*this = *this * x; return *this;}
inline const frac& frac::operator *= (long long x) {*this = *this * x; return *this;}
inline const frac& frac::operator /= (const frac& x) {*this = *this / x; return *this;}
inline const frac& frac::operator /= (long long x) {*this = *this / x; return *this;}

int CASE;

int BASE[16] = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' };
string str;

int main() {
    //freopen( "/Users/macuser/Dropbox/Contest/input.in", "r", stdin );
    cin >> CASE;
    for (int AAA = 0; AAA < CASE; ++AAA) {
        int n; cin >> n;
        map<frac,int> ma;
        for (int i = 0; i < n; ++i) {
            cin >> str;
            ll bo = str.size();
            for (ll k = 0; k < str.size(); k += 2) {
                string sub = str.substr(k, 2);
                int num = 0;
                for (int l = 0; l < 16; ++l) {
                    if (BASE[l] == sub[0]) num += l * 16;
                    if (BASE[l] == sub[1]) num += l;
                }
                if (num != 0) ma[ frac(k/2, bo/2) ] += num;
            }
        }
        long long LCM = 1;
        
        bool ok = true;
        EACH(it,ma) {
            LCM = lcm(LCM, it->first.second);
            if (LCM > 1024) ok = false;
        }

        if (!ok) puts("Too complex.");
        else {
            string res = "";
            for (int i = 0; i < LCM*2; ++i) res += '0';
            EACH(it,ma) {
                long long pos = (it->first.first) * LCM / (it->first.second);
                int num = it->second;
            
                char c1 = BASE[num/16];
                char c2 = BASE[num%16];
            
                res[pos*2] = c1;
                res[pos*2+1] = c2;
            }
            cout << res << endl;
        }
    }
    return 0;
}
accuracy: 1
time_ms: 50
memory_kb: 1540
final_rank: 18

code_snippet: #include<cstdio>
#include<cstdlib>
#include<vector>
#include<utility>
#include<cstring>

using namespace std;

int gcd(int a,int b){
  return b?gcd(b,a%b):a;
}

int main(){
  int T;
  scanf("%d",&T);
  while(T--){
    int N;
    scanf("%d",&N);
    vector<pair<int,int> > v[16];
    while(N--){
      char buf[2049];
      scanf("%s",buf);
      int l=strlen(buf);
      for(int i=0;i<l;i+=2){
	char n[3]={};
	n[0]=buf[i];
	n[1]=buf[i+1];
	int b=strtol(n,nullptr,16);
	for(int j=0;j<16;j++){
	  if(b>>j&1){
	    v[j].push_back((i==0)?make_pair(0,1):make_pair(i/gcd(i,l),l/gcd(i,l)));
	  }
	}
      }
    }
    int den=1;
    for(auto e:v){
      for(auto f:e){
	den=den*f.second/gcd(den,f.second);
	if(den>1024)goto fail;
      }
    }
    {
      int syn[1024]={};
      for(int i=0;i<16;i++){
	for(auto e:v[i]){
	  syn[e.first*den/e.second]|=1<<i;
	}
      }
      for(int i=0;i<den;i++){
	printf("%02X",syn[i]);
      }
      puts("");
      continue;
    }
  fail:
    puts("Too complex.");
  }
}
accuracy: 1
time_ms: 10
memory_kb: 1116
final_rank: 1

code_snippet: #include <iostream>
#include <vector>
#include <string>
#include <algorithm>

using namespace std;

typedef long long ll;

ll gcd(ll m, ll n){
	return n ? gcd(n, m%n) : m;
}

ll lcm(ll m, ll n){
	return m / gcd(m, n) * n;
}

string hexstr = "0123456789ABCDEF";

int main(){	
	int T;
	cin >> T;
	int abc = 0;
	while (T--){
		int N;
		cin >> N;
		vector<string> v(N);
		vector<int> gcds;
		for (int i = 0; i < N; ++i) cin >> v[i];

		ll total = 1;
		for (auto &s : v){
			int g = s.size() / 2;
			for (int i = 0; i < s.size(); i += 2){
				if (s[i] != '0' || s[i+1] != '0') g = gcd(g, i / 2);
			}
			total = lcm(total, s.size() / 2 / g);
			total = min(total, 1025ll);
			gcds.push_back(g);
		}

		if (total * 2 <= 2048){
			vector<int> ans(total);
			for (int j = 0; j < v.size(); ++j){
				string &s = v[j];
				int g = gcds[j];
				int mul = total / (s.size() / 2 / g);
				for (int i = 0; i < s.size(); i += 2){
					if (s[i] == '0' && s[i + 1] == '0') continue;
					int pos = i / 2 / g * mul;
					ans[pos] |= (s[i] - '0') * 16;
					ans[pos] |= (s[i + 1] - '0');
				}
			}
			for (auto &e : ans){
				int x = e / 16, y = e % 16;
				cout << hexstr[x] << hexstr[y];
			}
			cout << endl;
		}
		else{
			cout << "Too complex." << endl;
		}
	}


	return 0;
}
accuracy: 1
time_ms: 20
memory_kb: 1248
final_rank: 8

code_snippet: #include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <sstream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <utility>
#include <cctype>
#include <numeric>
#include <cassert>
using namespace std;

#define rep(i,n) for(int (i)=0; (i)<(int)(n); ++(i))
#define foreach(c,i) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();i++)

int gcd(int a, int b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}

int c2i(const char c) { return c-'0'; }

int s0x2i(const string& s) {
  return c2i(s[0]) * 16 + c2i(s[1]);
}

vector<char> conv;

int N;
vector<string> vs;
const string zero = "00";

void solve() {
  vector<int> denoms;
  rep(i,N) {
    const int baseDenom = vs[i].size() / 2;
    for (int j = 0; j < vs[i].size(); j+=2) {
      string sub = vs[i].substr(j, 2);
      if (sub == zero) continue;
      int num = j / 2;
      int denom = baseDenom / gcd(baseDenom, num);

      // if (baseDenom == 880 && num == 776) {
      //   printf("especially !! denom->%d\n", denom);
      // }
      
      denoms.push_back(denom);
    }
  }
  
  sort(denoms.begin(), denoms.end());
  denoms.erase(unique(denoms.begin(), denoms.end()), denoms.end());
  // rep(i,denoms.size()) {printf("[%d]", denoms[i]);} puts("");

  map<int,int> m;
  rep(i,denoms.size()) {
    int num = denoms[i];
    for (int j = 2; j * j <= num; ++j) {
      int cnt = 0;
      while (num % j == 0) {
        ++cnt;
        num /= j;
      }
      if (cnt) {
        m[j] = max(m[j], cnt);
      }
    }
    if (num > 1 && m.count(num) == 0)
      m[num] = 1;
  }

  // foreach(m, itr) { printf("[%d:%d]", itr->first, itr->second); } puts(""); 

  int finalDenom = 1;
  foreach(m, itr) {
    finalDenom *= pow(itr->first, itr->second);
    if (finalDenom > (2048)/2) break;
  }
  
  // printf("finalDenom::%d\n", finalDenom);
  if (finalDenom > (2048/2)) {
    cout << "Too complex." << endl;
    return;
  }

  vector<int> resInt(finalDenom, 0);
  rep(i,N) {
    const int baseDenom = vs[i].size() / 2;
    for (int j = 0; j < vs[i].size(); j+=2) {
      string sub = vs[i].substr(j, 2);
      int num = s0x2i(sub); // index = (j/2) / gcd(baseDenom, j/2);
      if (num == 0) continue;
      const int kgcd = gcd(baseDenom, j/2);
      int index = (j/2) / kgcd;
      
      if (finalDenom > (baseDenom/kgcd)) {
        index *= finalDenom/(baseDenom/kgcd);
        // index = (j / 2) * (finalDenom / gcd(baseDenom, j/2));
      } else {
        index /= (baseDenom/kgcd)/finalDenom;
        // index = (j / 2) / (gcd(baseDenom, j/2) / finalDenom);
      }
      if (index >= finalDenom) {
        // printf("index:finalDenom -- %d:%d\n", index, finalDenom);
        // printf("j:vs[i].size() -- %d:%d\n", j, vs[i].size());
        // printf("num -- %d\n", num);
      }
      assert(index < finalDenom);
      resInt[index] += num;
    }
  }

  rep(i,resInt.size()) {
    int num = resInt[i];
    if (num > 255) {
      printf("num assert :: %d\n", num);
    }
    assert(num <= 255);
    cout << conv[num/16] << conv[num%16];
  }
  cout << endl;
}

void input() {
  // vs clear
  vs.clear();
  
  cin >> N;
  cin.ignore();
  string s;
  rep(i,N) {
    getline(cin, s);
    vs.push_back(s);
  }
}

int main() {
  // cout << "gcd(1760, 1552) = " << gcd(1760, 1552) << endl;
  rep(i,10) {
    conv.push_back('0'+i);
  }
  rep(i,6) {
    conv.push_back('A'+i);
  }
  int T;
  cin >> T;
  int cT = T;
  while (T--) {
    // cout << "Case #" << cT - T << endl;
    input();
    solve();
  }
  return 0;
}
accuracy: 1
time_ms: 30
memory_kb: 1372
final_rank: 11

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

typedef long long ll;
const int INF = 1e+8;
string to_c = "0123456789ABCDEF";

// aとbの最大公約数を返す(ユークリッドの互除法)
ll gcd(ll a, ll b){
    return (b > 0)? gcd(b, a%b) : a ;
}

// aとbの最小公倍数を返す
ll lcm(ll a, ll b){
    return a / gcd(a, b) * b ;
}

// 分数型, p : 分子, q : 分母
struct Fraction{
	ll p, q;
	// コンストラクタ
	Fraction(ll p_, ll q_){
		if( p_ == 0 ){ // 分子が 0 のとき
			p = p_;
			q = 1;
		}else if( q_ == 0 ){ // 分母が 0 のとき
			p = INF;
			q = 1;
		}else{
			ll d = gcd(abs(p_),q_);
			p_ /= d;
			q_ /= d;
			p = p_;
			q = q_;
		}
	}
	Fraction(ll a){
		p = a;
		q = 1;
	}
	Fraction operator*(const Fraction& n){
		return Fraction( p * n.p , q * n.q );
	}
	Fraction operator/(const Fraction& n){
		return Fraction( p * n.q , q * n.p );
	}
	Fraction operator+(const Fraction& n){
		return Fraction( p * n.q + n.p * q , q * n.q );
	}
	Fraction operator-(const Fraction& n){
		return Fraction( p * n.q - n.p * q , q * n.q );
	}
	bool operator==(const Fraction& n){
		return (p == n.p && q == n.q);
	}
};
typedef pair<Fraction,int> P;

// 複数の最小公倍数
ll n_lcm(vector<P> &ans){
	ll res = 1;
	for(int i=0 ; i < ans.size() ; i++ ){
		res = lcm(res, ans[i].first.q);
		if( res > 1024 ) return -1;
	}
	return res;
}

// 16進数2桁を返す.
string to_hex(int x){
	int a = x / 16;
	int b = x % 16;
	string s;
	s.push_back( to_c[a] );
	s.push_back( to_c[b] );
	return s;
}

int main(){
	int T;
	cin >> T;
	for(int t_ = 0 ; t_ < T ; t_++ ){
		int N;
		vector<P> ans;
		cin >> N;
		for(int i=0 ; i < N ; i++ ){
			string R;
			cin >> R;
			
			for(int i=0 ; i < R.size() ; i += 2 ){
				int k = (R[i] - '0') * 16 + (R[i+1] - '0');
				if( k ){
					ans.push_back( P(Fraction(i/2, R.size()/2), k) );
				}
			}
		}
		
		// 音が鳴っていないとき
		if( ans.size() == 0 ){
			cout << "00" << endl;
			continue;
		}
		
		ll L = n_lcm(ans);
		if( L == -1 ){
			cout << "Too complex." << endl;
		}else{
			vector<int> a(L, 0);
			for(int i=0 ; i < ans.size() ; i++ ){
				int k = (ans[i].first * Fraction(L)).p;
				a[k] |= ans[i].second;
			}
			for(int i=0 ; i < L ; i++ ){
				cout << to_hex(a[i]);
			}
			cout << endl;
		}
	}
}
accuracy: 1
time_ms: 20
memory_kb: 1456
final_rank: 10

code_snippet: #include <iostream>
#include <sstream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>

using namespace std;

#define FOR(i,k,n) for(int i=(k); i<(int)n; ++i)
#define REP(i,n) FOR(i,0,n)
#define FORIT(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)

template<class T> void debug(T begin, T end){ for(T i = begin; i != end; ++i) cout<<*i<<" "; cout<<endl; }

typedef long long ll;
const int INF = 100000000;
const double EPS = 1e-8;
const int MOD = 1000000007;
ll gcd(int n, int m){
  return (n % m) ? gcd(m, n % m) : m;
}
ll lcm(int n, int m){
  return (ll)n * m / gcd(n, m);
}
int toint(string unit){
  int n;
  sscanf(unit.c_str(), "%x", &n);
  return n;
}
string tostr(vector<int> v){
  string res;
  REP(i, v.size()){
    int n = v[i];
    char s[100];
    sprintf(s, "%02X", n);
    res +=  string(s);
  }
  return res;
}

int main(){
  int T;
  cin>>T;
  while(T--){
    int N; cin>>N;
    string s[8];
    ll len = 1;
    REP(i, N){
      cin>>s[i];
      REP(j, s[i].size()/2) if(s[i].substr(j * 2, 2) != "00"){
        //printf("%d/%d ", j, s[i].size() /2);
        if(len <= 1024)len = lcm(len, (s[i].size() / 2 / gcd(j, s[i].size() / 2)));
      }
    }
    if(len > 1024){
      cout<<"Too complex."<<endl;
      continue;
    }
    vector<int> data(len);
    REP(i, len){
      REP(j, N){
        int l = s[j].size() / 2;
        if(i * l % len == 0) data[i] |= toint(s[j].substr(i * l / len * 2, 2));
      }
    }
    cout<<tostr(data)<<endl;
  }
  return 0;
}
accuracy: 1
time_ms: 70
memory_kb: 1024
final_rank: 19

code_snippet: #include <iostream>
#include <iomanip>
#include <sstream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <complex>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <cassert>
#include <climits>
#include <queue>
#include <set>
#include <map>
#include <valarray>
#include <bitset>
#include <stack>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
typedef long long ll;
typedef pair<int,int> pii;
const int INF = 1<<29;
const double PI = acos(-1);
const double EPS = 1e-8;

ll gcd(ll a, ll b) {
  return b==0 ? a : gcd(b,a%b);
}
ll lcm(ll a, ll b) {
  return a / gcd(a,b) * b;
}
ll lcm(vector<ll> v) {
  ll res = 1;
  FOR(it,v) {
    res = lcm(res, *it);
    if (res > 1e9) return res;
  }
  return res;
}

int rhythm[8][1024];
string str[8];
int ans[1024];

int main() {
  int T;
  cin >> T;
  while(T--) {
    int n;
    cin >> n;
    vector<ll> size;
    REP(i, n) {
      cin >> str[i];
      int sz = str[i].size()/2;
      int g = sz;
      REP(j,sz) {
        int tmp = strtol(str[i].substr(j*2,2).c_str(), NULL, 16);
        //cout << i << " " << j << " " << tmp << endl;
        rhythm[i][j] = tmp;
        if (tmp) {
          g = gcd(g, j);
        }
      }
      for (int j=0; j*g<sz; ++j) {
        rhythm[i][j] = rhythm[i][j*g];
      }
      size.push_back(sz/g);
    }
    //FOR(it, size) cout << *it << " ";cout << endl;
    ll l = lcm(size);
    if (l > 1024) {
      cout << "Too complex." << endl;
      continue;
    }
    memset(ans,0,sizeof(ans));
    REP(i, n) {
      int p = l/size[i];
      REP(j,size[i]) {
        ans[j*p] |= rhythm[i][j];
      }
    }
    REP(i, l) {
      printf("%02X", ans[i]);
    }
    cout << endl;
  }
}
accuracy: 1
time_ms: 40
memory_kb: 1028
final_rank: 12

code_snippet: #include<cstdio>
#include<cstring>

#define rep(i,n) for(int i=0;i<(n);i++)

using namespace std;

int gcd(int a,int b){ return b?gcd(b,a%b):a; }
int lcm(int a,int b){ return a/gcd(a,b)*b; }

int regularize(const char *s,int *r){
	int len=strlen(s)/2;
	rep(i,len){
		char x[3]={s[2*i],s[2*i+1],'\0'};
		sscanf(x,"%X",r+i);
	}

	for(int i=1;i<=len;i++) if(len%i==0) {
		bool ok=true;
		rep(j,i) for(int k=1;k<len/i;k++) if(r[j*len/i+k]!=0) ok=false;
		if(ok){
			rep(j,i) r[j]=r[j*len/i];
			return i;
		}
	}
}

int main(){
	int T; scanf("%d",&T);
	while(T--){
		int n,l[8]; scanf("%d",&n);
		static int r[8][1024];
		rep(i,n){
			char s[2049]; scanf("%s",s);
			l[i]=regularize(s,r[i]);
		}

		int len=1;
		bool over=false;
		rep(i,n){
			len=lcm(len,l[i]);
			if(len>1024) over=true;
		}
		if(over){
			puts("Too complex.");
			continue;
		}

		int ans[1024]={};
		rep(i,n) rep(j,l[i]) ans[j*len/l[i]]|=r[i][j];
		rep(j,len) printf("%02X",ans[j]);
		puts("");
	}

	return 0;
}
accuracy: 1
time_ms: 40
memory_kb: 0
final_rank: 7

code_snippet: #include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
using namespace std;

long long gcd(long long a, long long b){ // Ååöñ
    if(a == 0 || b == 0)
        return 0;
    if(b > a)
        swap(a, b);
    long long tmp;
    while((tmp = a % b) != 0){
        a = b;
        b = tmp;
    }
    return b;
}

long long lcm(long long a, long long b){ // Å¬ö{
    return a / gcd(a, b) * b;
}

char add(char a, char b)
{
    int c;
    if('0' <= a && a <= '9')
        c = a - '0';
    else
        c = a - 'A' + 10;
    if('0' <= b && b <= '9')
        c += b - '0';
    else
        c += b - 'A' + 10;
    if(c < 10)
        return '0' + c;
    else
        return 'A' + c - 10;
}

int main()
{
    int t;
    cin >> t;
    while(--t >= 0){
        int n;
        cin >> n;
        vector<string> s(n);
        for(int i=0; i<n; ++i){
            string tmp;
            cin >> tmp;
            int a = tmp.size()/2;
            for(int j=1; j<tmp.size()/2; ++j){
                if(tmp[2*j] != '0' || tmp[2*j+1] != '0'){
                    if(a == -1)
                        a = j;
                    else
                        a = gcd(a, j);
                }
            }
            for(unsigned j=0; j<tmp.size()/2; j+=a){
                s[i] += tmp[j*2];
                s[i] += tmp[j*2+1];
            }
        }

        int len = 1;
        for(int i=0; i<n; ++i){
            len = lcm(len, s[i].size()/2);
            if(len > 1024)
                break;
        }
        if(len > 1024){
            cout << "Too complex." << endl;
            continue;
        }

        string ret(len*2, '0');
        for(int i=0; i<n; ++i){
            int a = len / (s[i].size()/2);
            for(unsigned j=0; j<s[i].size()/2; ++j){
                ret[2*j*a] = add(ret[2*j*a], s[i][2*j]);
                ret[2*j*a+1] = add(ret[2*j*a+1], s[i][2*j+1]);
            }
        }
        cout << ret << endl;
    }
}
accuracy: 1
time_ms: 20
memory_kb: 944
final_rank: 6