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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

#define fi first
#define se second
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt __builtin_popcount

#define INF INT_MAX/3

const int M=52;

vector<int> operator+(const vector<int>& a,const vector<int>& b){
  vector<int> res(M);
  rep(i,M)res[i]=a[i]+b[i];
  return res;
}
bool operator<(const vector<int>& a,const vector<int>& b){
  rep(i,M){
    if(a[i]!=b[i])return a[i]<b[i];
  }
  return true;
}

struct edge{
  int to,cap;
  vector<int> cost;
  int rev;
};

int V;
int N;
vector<edge> g[202];
int h[202];
vector<int> dist[202];
int prevv[202],preve[202];
vector<int> vinf;

void init(int v){
  V=v;
  vinf=vector<int>(M,INF);
  for(int i=0;i<V;i++){
    g[i].clear();
  }
}

void add_edge(int from,int to,int cap,vector<int> cost){
  g[from].push_back((edge){to,cap,cost,(int)g[to].size()});
  vector<int> rev=cost;
  rep(i,cost.size())rev[i]=-rev[i];
  g[to].push_back((edge){from,0,rev,(int)g[from].size()-1});
}

vector<int> min_cost_flow(int s,int t,int f){
  vector<int> res=vector<int>(M,0);
  memset(h,0,sizeof(h));
  while(f>0){
    rep(i,V)dist[i]=vinf;
    dist[s]=vector<int>(M,0);
    bool update=true;
    while(update){
      update=false;
      for(int v=0;v<V;v++){
        if(dist[v]==vinf)continue;
        for(int i=0;i<g[v].size();i++){
          edge &e=g[v][i];
          if(e.cap>0&&dist[e.to]>dist[v]+e.cost){
            dist[e.to]=dist[v]+e.cost;
            prevv[e.to]=v;
            preve[e.to]=i;
            update=true;
          }
        }
      }
    }
    if(dist[t]==vinf) return vinf;

    int d=f;
    for(int v=t;v!=s;v=prevv[v]){
      d=min(d,g[prevv[v]][preve[v]].cap);
    }
    f-=d;
    rep(i,M)res[i]=res[i]+d*dist[t][i];
    for(int v=t;v!=s;v=prevv[v]){
      edge &e=g[prevv[v]][preve[v]];
      e.cap-=d;
      g[v][e.rev].cap+=d;
    }
  }
  return res;
}

string s[55];
vector<int> costs[55];

int main(){
  cin>>N;
  rep(i,N)cin>>s[i];
  int source=N*2,sink=N*2+1;
  init(2*N+2);
  rep(i,M){
    vector<int> tmp(M,1000);
    tmp[i]=999;
    costs[i]=tmp;
  }
  rep(i,N){
    add_edge(source,i,1,vector<int>(M,0));
    add_edge(i+N,sink,1,vector<int>(M,0));
  }
  rep(i,N){
    rep(j,N){
      if('A'<=s[i][j]&&s[i][j]<='Z'){
        add_edge(i,j+N,1,costs[s[i][j]-'A']);
      }else{
        add_edge(i,j+N,1,costs[s[i][j]-'a'+26]);
      }
    }
  }
  vector<int> res=min_cost_flow(source,sink,N);
  string ans;
  rep(i,M){
    rep(j,N*1000-res[i]){
      if(i>=0&&i<26){
        ans+=(char)('A'+i);
      }else{
        ans+=(char)('a'+i-26);
      }
    }
  }
  cout<<ans<<endl;
  return 0;
}


### Prompt

Please formulate a CPP solution to the following problem:

Example

Input

3
aab
czc
baa


Output

aac

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

#define fi first
#define se second
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt __builtin_popcount

#define INF INT_MAX/3

const int M=52;

vector<int> operator+(const vector<int>& a,const vector<int>& b){
  vector<int> res(M);
  rep(i,M)res[i]=a[i]+b[i];
  return res;
}
bool operator<(const vector<int>& a,const vector<int>& b){
  rep(i,M){
    if(a[i]!=b[i])return a[i]<b[i];
  }
  return true;
}

struct edge{
  int to,cap;
  vector<int> cost;
  int rev;
};

int V;
int N;
vector<edge> g[202];
int h[202];
vector<int> dist[202];
int prevv[202],preve[202];
vector<int> vinf;

void init(int v){
  V=v;
  vinf=vector<int>(M,INF);
  for(int i=0;i<V;i++){
    g[i].clear();
  }
}

void add_edge(int from,int to,int cap,vector<int> cost){
  g[from].push_back((edge){to,cap,cost,(int)g[to].size()});
  vector<int> rev=cost;
  rep(i,cost.size())rev[i]=-rev[i];
  g[to].push_back((edge){from,0,rev,(int)g[from].size()-1});
}

vector<int> min_cost_flow(int s,int t,int f){
  vector<int> res=vector<int>(M,0);
  memset(h,0,sizeof(h));
  while(f>0){
    rep(i,V)dist[i]=vinf;
    dist[s]=vector<int>(M,0);
    bool update=true;
    while(update){
      update=false;
      for(int v=0;v<V;v++){
        if(dist[v]==vinf)continue;
        for(int i=0;i<g[v].size();i++){
          edge &e=g[v][i];
          if(e.cap>0&&dist[e.to]>dist[v]+e.cost){
            dist[e.to]=dist[v]+e.cost;
            prevv[e.to]=v;
            preve[e.to]=i;
            update=true;
          }
        }
      }
    }
    if(dist[t]==vinf) return vinf;

    int d=f;
    for(int v=t;v!=s;v=prevv[v]){
      d=min(d,g[prevv[v]][preve[v]].cap);
    }
    f-=d;
    rep(i,M)res[i]=res[i]+d*dist[t][i];
    for(int v=t;v!=s;v=prevv[v]){
      edge &e=g[prevv[v]][preve[v]];
      e.cap-=d;
      g[v][e.rev].cap+=d;
    }
  }
  return res;
}

string s[55];
vector<int> costs[55];

int main(){
  cin>>N;
  rep(i,N)cin>>s[i];
  int source=N*2,sink=N*2+1;
  init(2*N+2);
  rep(i,M){
    vector<int> tmp(M,1000);
    tmp[i]=999;
    costs[i]=tmp;
  }
  rep(i,N){
    add_edge(source,i,1,vector<int>(M,0));
    add_edge(i+N,sink,1,vector<int>(M,0));
  }
  rep(i,N){
    rep(j,N){
      if('A'<=s[i][j]&&s[i][j]<='Z'){
        add_edge(i,j+N,1,costs[s[i][j]-'A']);
      }else{
        add_edge(i,j+N,1,costs[s[i][j]-'a'+26]);
      }
    }
  }
  vector<int> res=min_cost_flow(source,sink,N);
  string ans;
  rep(i,M){
    rep(j,N*1000-res[i]){
      if(i>=0&&i<26){
        ans+=(char)('A'+i);
      }else{
        ans+=(char)('a'+i-26);
      }
    }
  }
  cout<<ans<<endl;
  return 0;
}


```