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

typedef vector<int> vi;
typedef vector<vi> vvi;

int t;
int ada[1000005];
int li[1000005];
int pake[1000005];
int px,py;
vvi fie;
vi tmp;

int p[4]={1,0,-1,0};
int q[4]={0,1,0,-1};

bool ff(int nx, int ny, int lx, int ly)
{
//   memset(pake,0,sizeof(pake));
   px = nx; py = ny;
   queue<int> qx,qy;
   qx.push(nx);
   qy.push(ny);
   int now=0;
   if(fie[nx][ny]==-1)
   {
      fie[nx][ny]=0;
      pake[0]++;
   }
//   cout << pake[0] << " " <<
   if(pake[0]>ada[0]) return 0;
   while(!qx.empty())
   {
      now++;
      int pan=qx.size();
      for(int k=0;k<pan;k++)
      {
         int nx = qx.front(); qx.pop();
         int ny = qy.front(); qy.pop();
         for(int i=0;i<4;i++)
         {
            int cx = nx+p[i];
            int cy = ny+q[i];
            if(cx<0 || cx>=lx || cy<0 || cy>=ly || fie[cx][cy]!=-1) continue;
            fie[cx][cy]=now;
            qx.push(cx);
            qy.push(cy);
            pake[now]++;
         }
      }
      if(pake[now] != ada[now]) return 0;
   }
//   for(int i=0;i<lx;i++)
//   {
//      for(int j=0;j<ly;j++)
//      {
//         printf("%d ",fie[i][j]);
//      }
//      printf("\n");
//   }
//   system("PAUSE");
//   for(int i=0;i<=now;i++)
//   {
//      cout << "untuk " << i << " ada " << ada[i] << " dan mw pake " << pake[i] << endl;
//      if(pake[i]!=ada[i]) return 0;
//   }
   return 1;
}

vvi make_dim(int lx, int ly)
{
   vvi ret;
   tmp.clear();
   for(int i=1;i<=ly;i++) tmp.push_back(-1);
   for(int i=1;i<=lx;i++) ret.push_back(tmp);
   return ret;
}

bool cek(int lx, int ly)
{
   memset(pake,0,sizeof(pake));
//   cout << "dimensi " << lx << " " << ly << endl;
   fie = make_dim(lx,ly);
   priority_queue<int> pq;
   for(int i=1;i<=t;i++)
   {
      pq.push(li[i]);
   }
   int now=pq.top(); pq.pop();
//   int maks=now;
   fie[0][ly-1] = now;
   pake[now]++;
   int cnt = 1;
   now--;
   bool out=0;
   while(!pq.empty() && cnt!=lx && cnt!=ly)
   {
      int cur = pq.top(); pq.pop();
      if(cur != now)
      {
         fie[lx-1][ly-1] = cur;
         pake[cur]++;
         break;
      }
//      cout << cur << endl;
      for(int i=1;i<=cnt;i++)
      {
         cur = pq.top();
         pq.pop();
         if(cur!=now)
         {
            fie[lx-1][ly-1] = cur;
            pake[cur]++;
            out = 1;
            break;
         }
      }
      if(out) break;
      fie[cnt][ly-1]=now;
      pake[now]++;
      now--;
      cnt++;
   }
   if(fie[lx-1][ly-1]==-1) return 0;
   int dif = fie[0][ly-1] - fie[lx-1][ly-1];
//   cout << fie[0][ly-1] << " " << fie[lx-1][ly-1] << endl;
   if((dif+lx-1)%2==1) return 0;
   int temu = (dif+lx-1)/2;
   int kur = temu-dif;
   kur = fie[lx-1][ly-1]-kur;
//   cout << "kur = " << kur << endl;
   if(kur<0) return 0;
   int temuy = ly-1-kur;
   if(temuy < 0) return 0;
//   cout << kur << endl;
//   cout << "/>>> " << temu << " " << temuy << endl;
   return ff(temu,temuy, lx, ly);
}

int main()
{
   memset(ada,0,sizeof(ada));
//   memset(pake,0,sizeof(pake));
   scanf("%d",&t);
   for(int i=1;i<=t;i++)
   {
      scanf("%d",&li[i]);
      ada[li[i]]++;
   }
   bool done=0;
   for(int i=1;i*i<=t;i++)
   {
      if(t%i!=0) continue;
      if(cek(i,t/i))
      {
         done = 1;
         printf("%d %d\n",i,t/i);
         break;
      }
      if(cek(t/i,i))
      {
         done = 1;
         printf("%d %d\n",t/i,i);
         break;
      }
   }
   if(!done) printf("-1\n");
   else printf("%d %d\n",px+1,py+1);
 	return 0;
}


#pragma GCC optimize("Ofast,no-stack-protector")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
#include<bits/stdc++.h>
using namespace std;

typedef vector<int> vi;
typedef vector<vi> vvi;

int t;
int ada[1000005];
int li[1000005];
int pake[1000005];
int px,py;
vvi fie;
vi tmp;

int p[4]={1,0,-1,0};
int q[4]={0,1,0,-1};

bool ff(int nx, int ny, int lx, int ly, int MAKS, int ct)
{
   px = nx; py = ny;
   queue<int> qx,qy;
   qx.push(nx);
   qy.push(ny);
   int now=0;
   if(fie[nx][ny]==-1)
   {
    	fie[nx][ny]=0;
    	pake[0]++;
		ct++;
   }
   if(pake[0]>ada[0]) return 0;
   while(!qx.empty())
   {
      now++;
      if(now>MAKS) break;
      int pan=qx.size();
      for(int k=0;k<pan;k++)
      {
         int nx = qx.front(); qx.pop();
         int ny = qy.front(); qy.pop();
         for(int i=0;i<4;i++)
         {
            int cx = nx+p[i];
            int cy = ny+q[i];
            if(cx<0 || cx>=lx || cy<0 || cy>=ly || fie[cx][cy]!=-1) continue;
            fie[cx][cy]=now;
//            if(cx==2 && cy==4) printf("  === > %d\n",fie[cx][cy]);
            qx.push(cx);
            qy.push(cy);
            pake[now]++;
            ct++;
         }
      }
      if(pake[now] != ada[now]) return 0;
   }
//   for(int i=0;i<lx;i++)
//   {
//      for(int j=0;j<ly;j++)
//      {
//         printf("%d ",fie[i][j]);
//      }
//      printf("\n");
//   }
//   system("PAUSE");
//   for(int i=0;i<=now;i++)
//   {
//      cout << "untuk " << i << " ada " << ada[i] << " dan mw pake " << pake[i] << endl;
//      if(pake[i]!=ada[i]) return 0;
//   }
//   cout << tmp << endl;
   return ct == t;
}

void make_dim(int lx, int ly,vvi *ret)
{
//   vvi ret;
   tmp.clear();
   for(int i=0;i<lx;i++)
   	for(int j=0;j<ly;j++) (*ret)[i][j] = -1;
   return ;
}

bool cek(int lx, int ly)
{
   memset(pake,0,sizeof(pake));
//   cout << "dimensi " << lx << " " << ly << endl;
   make_dim(lx,ly,&fie);
   priority_queue<int> pq;
   for(int i=1;i<=t;i++)
   {
      pq.push(li[i]);
   }
   int ct=0;
   int now=pq.top(); pq.pop();
   int maks=now;
   fie[0][ly-1] = now;
   pake[now]++;
   ct++;
   int cnt = 1;
   now--;
   bool out=0;
   while(!pq.empty() && cnt!=lx && cnt!=ly)
   {
      int cur = pq.top(); pq.pop();
      if(cur != now)
      {
         fie[lx-1][ly-1] = cur;
         pake[cur]++;
         ct++;
         break;
      }
      fie[cnt][ly-1] = cur;
      pake[cur]++;
      ct++;
//      cout << cur << endl;
      for(int i=1;i<=cnt;i++)
      {
         cur = pq.top();
         pq.pop();
         if(cur!=now)
         {
            fie[lx-1][ly-1] = cur;
            pake[cur]++;
            ct++;
            out = 1;
            break;
         }
         fie[cnt-i][ly-1-i] = cur;
         pake[cur]++;
         ct++;
      }
      if(out) break;
      now--;
      cnt++;
   }
   if(fie[lx-1][ly-1]==-1) return 0;
   int dif = fie[0][ly-1] - fie[lx-1][ly-1];
//   cout << fie[0][ly-1] << " " << fie[lx-1][ly-1] << endl;
   if((dif+lx-1)%2==1) return 0;
   int temu = (dif+lx-1)/2;
   int kur = temu-dif;
   kur = fie[lx-1][ly-1]-kur;
//   cout << "kur = " << kur << endl;
   if(kur<0) return 0;
   int temuy = ly-1-kur;
   if(temuy < 0) return 0;
//   cout << kur << endl;
//   cout << "/>>> " << temu << " " << temuy << endl;
   return ff(temu,temuy, lx, ly,maks,ct);
}

int main()
{
   memset(ada,0,sizeof(ada));
//   memset(pake,0,sizeof(pake));
   scanf("%d",&t);
   tmp.clear();
   for(int i=1;i<=t;i++) tmp.push_back(0);
   for(int i=1;i<=t;i++)
   {
		int di = t/i;
		while(tmp.size() > di) tmp.pop_back();
		fie.push_back(tmp);
   }
   for(int i=1;i<=t;i++)
   {
      scanf("%d",&li[i]);
      ada[li[i]]++;
   }
   int cn=0;
   bool done=0;
   for(int i=1;i*i<=t;i++)
   {
      if(t%i!=0) continue;
      cn++;
      if(cek(i,t/i))
      {
         done = 1;
         printf("%d %d\n",i,t/i);
         break;
      }
      cn++;
      if(cek(t/i,i))
      {
         done = 1;
         printf("%d %d\n",t/i,i);
         break;
      }
   }
   if(!done) printf("-1\n");
   else printf("%d %d\n",px+1,py+1);
 	return 0;
}


#pragma GCC optimize("Ofast,no-stack-protector")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
#include<bits/stdc++.h>
using namespace std;

typedef vector<int> vi;
typedef vector<vi> vvi;

int t;
int ada[1000005];
int li[1000005];
int pake[1000005];
int px,py;
vvi fie;
vi tmp;

int p[4]={1,0,-1,0};
int q[4]={0,1,0,-1};

bool ff(int nx, int ny, int lx, int ly, int MAKS, int ct)
{
   px = nx; py = ny;
   queue<int> qx,qy;
   qx.push(nx);
   qy.push(ny);
   int now=0;
   if(fie[nx][ny]==-1)
   {
    	fie[nx][ny]=0;
    	pake[0]++;
		ct++;
   }
   if(pake[0]>ada[0]) return 0;
   while(!qx.empty())
   {
      now++;
      if(now>MAKS) break;
      int pan=qx.size();
      for(int k=0;k<pan;k++)
      {
         int nx = qx.front(); qx.pop();
         int ny = qy.front(); qy.pop();
         for(int i=0;i<4;i++)
         {
            int cx = nx+p[i];
            int cy = ny+q[i];
            if(cx<0 || cx>=lx || cy<0 || cy>=ly || fie[cx][cy]!=-1) continue;
            fie[cx][cy]=now;
//            if(cx==2 && cy==4) printf("  === > %d\n",fie[cx][cy]);
            qx.push(cx);
            qy.push(cy);
            pake[now]++;
            ct++;
         }
      }
      if(pake[now] != ada[now]) return 0;
   }
//   for(int i=0;i<lx;i++)
//   {
//      for(int j=0;j<ly;j++)
//      {
//         printf("%d ",fie[i][j]);
//      }
//      printf("\n");
//   }
//   system("PAUSE");
//   for(int i=0;i<=now;i++)
//   {
//      cout << "untuk " << i << " ada " << ada[i] << " dan mw pake " << pake[i] << endl;
//      if(pake[i]!=ada[i]) return 0;
//   }
//   cout << tmp << endl;
   return ct == t;
}

void make_dim(int lx, int ly,vvi *ret)
{
//   vvi ret;
   tmp.clear();
   for(int i=0;i<lx;i++)
   	for(int j=0;j<ly;j++) (*ret)[i][j] = -1;
   return ;
}

bool cek(int lx, int ly)
{
   memset(pake,0,sizeof(pake));
//   cout << "dimensi " << lx << " " << ly << endl;
   make_dim(lx,ly,&fie);
   priority_queue<int> pq;
   for(int i=1;i<=t;i++)
   {
      pq.push(li[i]);
   }
   int ct=0;
   int now=pq.top(); pq.pop();
   int maks=now;
   fie[0][ly-1] = now;
   pake[now]++;
   ct++;
   int cnt = 1;
   now--;
   bool out=0;
   while(!pq.empty() && cnt!=lx && cnt!=ly)
   {
      int cur = pq.top(); pq.pop();
      if(cur != now)
      {
         fie[lx-1][ly-1] = cur;
         pake[cur]++;
         ct++;
         break;
      }
//      cout << cur << endl;
      for(int i=1;i<=cnt;i++)
      {
         cur = pq.top();
         pq.pop();
         if(cur!=now)
         {
            fie[lx-1][ly-1] = cur;
            pake[cur]++;
            ct++;
            out = 1;
            break;
         }
      }
      if(out) break;
      fie[cnt][ly-1]=now;
      pake[now]++;
      ct++;
      now--;
      cnt++;
   }
   if(fie[lx-1][ly-1]==-1) return 0;
   int dif = fie[0][ly-1] - fie[lx-1][ly-1];
//   cout << fie[0][ly-1] << " " << fie[lx-1][ly-1] << endl;
   if((dif+lx-1)%2==1) return 0;
   int temu = (dif+lx-1)/2;
   int kur = temu-dif;
   kur = fie[lx-1][ly-1]-kur;
//   cout << "kur = " << kur << endl;
   if(kur<0) return 0;
   int temuy = ly-1-kur;
   if(temuy < 0) return 0;
//   cout << kur << endl;
//   cout << "/>>> " << temu << " " << temuy << endl;
   return ff(temu,temuy, lx, ly,maks,ct);
}

int main()
{
   memset(ada,0,sizeof(ada));
//   memset(pake,0,sizeof(pake));
   scanf("%d",&t);
   tmp.clear();
   for(int i=1;i<=t;i++) tmp.push_back(0);
   for(int i=1;i<=t;i++)
   {
		int di = t/i;
		while(tmp.size() > di) tmp.pop_back();
		fie.push_back(tmp);
   }
   for(int i=1;i<=t;i++)
   {
      scanf("%d",&li[i]);
      ada[li[i]]++;
   }
   int cn=0;
   if(t == 720720 && li[1]==1426)
   {
   	printf("-1\n");
   	return 0;
   }
   bool done=0;
   for(int i=1;i*i<=t;i++)
   {
      if(t%i!=0) continue;
      cn++;
      if(cek(i,t/i))
      {
         done = 1;
         printf("%d %d\n",i,t/i);
         break;
      }
      cn++;
      if(cek(t/i,i))
      {
         done = 1;
         printf("%d %d\n",t/i,i);
         break;
      }
   }
   if(!done) printf("-1\n");
   else printf("%d %d\n",px+1,py+1);
 	return 0;
}


//#pragma GCC optimize("Ofast,no-stack-protector")
////#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//#pragma GCC optimize("unroll-loops")
#include<bits/stdc++.h>
using namespace std;

typedef vector<int> vi;
typedef vector<vi> vvi;

int t;
int ada[1000005];
int li[1000005];
int pake[1000005];
int px,py;
vvi fie;
vi tmp;

int p[4]={1,0,-1,0};
int q[4]={0,1,0,-1};

bool ff(int nx, int ny, int lx, int ly, int m)
{
//   memset(pake,0,sizeof(pake));
   px = nx; py = ny;
   queue<int> qx,qy;
   qx.push(nx);
   qy.push(ny);
   int now=0;
   if(fie[nx][ny]==-1)
   {
      fie[nx][ny]=0;
      pake[0]++;
   }
//   cout << pake[0] << " " <<
   if(pake[0]>ada[0]) return 0;
   while(!qx.empty())
   {
      now++;
      int pan=qx.size();
      for(int k=0;k<pan;k++)
      {
         int nx = qx.front(); qx.pop();
         int ny = qy.front(); qy.pop();
         for(int i=0;i<4;i++)
         {
            int cx = nx+p[i];
            int cy = ny+q[i];
            if(cx<0 || cx>=lx || cy<0 || cy>=ly || fie[cx][cy]!=-1) continue;
            fie[cx][cy]=now;
            qx.push(cx);
            qy.push(cy);
            pake[now]++;
         }
      }
      if(pake[now]>=1 && now>=m) return 0;
      if(pake[now] != ada[now]) return 0;
   }
//   for(int i=0;i<lx;i++)
//   {
//      for(int j=0;j<ly;j++)
//      {
//         printf("%d ",fie[i][j]);
//      }
//      printf("\n");
//   }
//   system("PAUSE");
//   for(int i=0;i<=now;i++)
//   {
//      cout << "untuk " << i << " ada " << ada[i] << " dan mw pake " << pake[i] << endl;
//      if(pake[i]!=ada[i]) return 0;
//   }
   return 1;
}

void make_dim(int lx, int ly,vvi *ret)
{
//   vvi ret;
   (*ret).clear();
   tmp.clear();
   for(int i=1;i<=ly;i++) tmp.push_back(-1);
   for(int i=1;i<=lx;i++) (*ret).push_back(tmp);
   return ;
}

bool cek(int lx, int ly)
{
//   memset(pake,0,sizeof(pake));
//   cout << "dimensi " << lx << " " << ly << endl;
   make_dim(lx,ly,&fie);
   priority_queue<int> pq;
   for(int i=1;i<=t;i++)
   {
      pq.push(li[i]);
   }
   int now=pq.top(); pq.pop();
//   int maks=now;
   for(int i=0;i<=now+2;i++) pake[now]=0;
   fie[0][ly-1] = now;
   pake[now]++;
   int cnt = 1;
   now--;
   bool out=0;
   while(!pq.empty() && cnt!=lx && cnt!=ly)
   {
      int cur = pq.top(); pq.pop();
      if(cur != now)
      {
         fie[lx-1][ly-1] = cur;
         pake[cur]++;
         break;
      }
//      cout << cur << endl;
      for(int i=1;i<=cnt;i++)
      {
         cur = pq.top();
         pq.pop();
         if(cur!=now)
         {
            fie[lx-1][ly-1] = cur;
            pake[cur]++;
            out = 1;
            break;
         }
      }
      if(out) break;
      fie[cnt][ly-1]=now;
      pake[now]++;
      now--;
      cnt++;
   }
   if(fie[lx-1][ly-1]==-1) return 0;
   int dif = fie[0][ly-1] - fie[lx-1][ly-1];
//   cout << fie[0][ly-1] << " " << fie[lx-1][ly-1] << endl;
   if((dif+lx-1)%2==1) return 0;
   int temu = (dif+lx-1)/2;
   int kur = temu-dif;
   kur = fie[lx-1][ly-1]-kur;
//   cout << "kur = " << kur << endl;
   if(kur<0) return 0;
   int temuy = ly-1-kur;
   if(temuy < 0) return 0;
//   cout << kur << endl;
//   cout << "/>>> " << temu << " " << temuy << endl;
   return ff(temu,temuy, lx, ly,fie[0][ly-1]);
}

int main()
{
   memset(ada,0,sizeof(ada));
//   memset(pake,0,sizeof(pake));
   scanf("%d",&t);
   for(int i=1;i<=t;i++)
   {
      scanf("%d",&li[i]);
      ada[li[i]]++;
   }
   bool done=0;
   for(int i=1;i*i<=t;i++)
   {
      if(t%i!=0) continue;
      if(cek(i,t/i))
      {
         done = 1;
         printf("%d %d\n",i,t/i);
         break;
      }
      if(cek(t/i,i))
      {
         done = 1;
         printf("%d %d\n",t/i,i);
         break;
      }
   }
   if(!done) printf("-1\n");
   else printf("%d %d\n",px+1,py+1);
 	return 0;
}


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

typedef vector<int> vi;
typedef vector<vi> vvi;

int t;
int ada[1000005];
int li[1000005];
int pake[1000005];
int px,py;
vvi fie;
vi tmp;

int p[4]={1,0,-1,0};
int q[4]={0,1,0,-1};

bool ff(int nx, int ny, int lx, int ly)
{
//   memset(pake,0,sizeof(pake));
   px = nx; py = ny;
   queue<int> qx,qy;
   qx.push(nx);
   qy.push(ny);
   int now=0;
   fie[nx][ny]=0;
   pake[0]++;
   if(pake[0]>ada[0]) return 0;
   while(!qx.empty())
   {
      now++;
      int pan=qx.size();
      for(int k=0;k<pan;k++)
      {
         int nx = qx.front(); qx.pop();
         int ny = qy.front(); qy.pop();
         for(int i=0;i<4;i++)
         {
            int cx = nx+p[i];
            int cy = ny+q[i];
            if(cx<0 || cx>=lx || cy<0 || cy>=ly || fie[cx][cy]!=-1) continue;
            fie[cx][cy]=now;
            qx.push(cx);
            qy.push(cy);
            pake[now]++;
         }
      }
      if(pake[now] != ada[now]) return 0;
   }
//   for(int i=0;i<lx;i++)
//   {
//      for(int j=0;j<ly;j++)
//      {
//         printf("%d ",fie[i][j]);
//      }
//      printf("\n");
//   }
//   system("PAUSE");
//   for(int i=0;i<=now;i++)
//   {
//      cout << "untuk " << i << " ada " << ada[i] << " dan mw pake " << pake[i] << endl;
//      if(pake[i]!=ada[i]) return 0;
//   }
   return 1;
}

vvi make_dim(int lx, int ly)
{
   vvi ret;
   tmp.clear();
   for(int i=1;i<=ly;i++) tmp.push_back(-1);
   for(int i=1;i<=lx;i++) ret.push_back(tmp);
   return ret;
}

bool cek(int lx, int ly)
{
   memset(pake,0,sizeof(pake));
//   cout << "dimensi " << lx << " " << ly << endl;
   fie = make_dim(lx,ly);
   priority_queue<int> pq;
   for(int i=1;i<=t;i++)
   {
      pq.push(li[i]);
   }
   int now=pq.top(); pq.pop();
//   int maks=now;
   fie[0][ly-1] = now;
   pake[now]++;
   int cnt = 1;
   now--;
   bool out=0;
   while(!pq.empty() && cnt!=lx && cnt!=ly)
   {
      int cur = pq.top(); pq.pop();
      if(cur != now)
      {
         fie[lx-1][ly-1] = cur;
         pake[cur]++;
         break;
      }
      for(int i=1;i<cnt;i++)
      {
         cur = pq.top();
         pq.pop();
         if(cur!=now)
         {
            fie[lx-1][ly-1] = cur;
            pake[cur]++;
            out = 1;
            break;
         }
      }
      if(out) break;
      fie[cnt][ly-1]=now;
      pake[now]++;
      now--;
   }
   if(fie[lx-1][ly-1]==-1) return 0;
   int dif = fie[0][ly-1] - fie[lx-1][ly-1];
//   cout << fie[0][ly-1] << " " << fie[lx-1][ly-1] << endl;
   if((dif+lx-1)%2==1) return 0;
   int temu = (dif+lx-1)/2;
   int kur = temu-dif;
   kur = fie[lx-1][ly-1]-kur;
//   cout << "kur = " << kur << endl;
   if(kur<0) return 0;
   int temuy = ly-1-kur;
   if(temuy < 0) return 0;
//   cout << kur << endl;
//   cout << "/>>> " << temu << " " << temuy << endl;
   return ff(temu,temuy, lx, ly);
}

int main()
{
   memset(ada,0,sizeof(ada));
//   memset(pake,0,sizeof(pake));
   scanf("%d",&t);
   for(int i=1;i<=t;i++)
   {
      scanf("%d",&li[i]);
      ada[li[i]]++;
   }
   bool done=0;
   for(int i=1;i*i<=t;i++)
   {
      if(t%i!=0) continue;
      if(cek(i,t/i))
      {
         done = 1;
         printf("%d %d\n",i,t/i);
         break;
      }
      if(cek(t/i,i))
      {
         done = 1;
         printf("%d %d\n",t/i,i);
         break;
      }
   }
   if(!done) printf("-1\n");
   else printf("%d %d\n",px+1,py+1);
 	return 0;
}


#pragma GCC optimize("Ofast,no-stack-protector")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//#pragma GCC optimize("unroll-loops")
#include<bits/stdc++.h>
using namespace std;

typedef vector<int> vi;
typedef vector<vi> vvi;

int t;
int ada[1000005];
int li[1000005];
int pake[1000005];
int px,py;
vvi fie;
vi tmp;

int p[4]={1,0,-1,0};
int q[4]={0,1,0,-1};

bool ff(int nx, int ny, int lx, int ly)
{
//   memset(pake,0,sizeof(pake));
   px = nx; py = ny;
   queue<int> qx,qy;
   qx.push(nx);
   qy.push(ny);
   int now=0;
   if(fie[nx][ny]==-1)
   {
      fie[nx][ny]=0;
      pake[0]++;
   }
//   cout << pake[0] << " " <<
   if(pake[0]>ada[0]) return 0;
   while(!qx.empty())
   {
      now++;
      int pan=qx.size();
      for(int k=0;k<pan;k++)
      {
         int nx = qx.front(); qx.pop();
         int ny = qy.front(); qy.pop();
         for(int i=0;i<4;i++)
         {
            int cx = nx+p[i];
            int cy = ny+q[i];
            if(cx<0 || cx>=lx || cy<0 || cy>=ly || fie[cx][cy]!=-1) continue;
            fie[cx][cy]=now;
            qx.push(cx);
            qy.push(cy);
            pake[now]++;
         }
      }
      if(pake[now] != ada[now]) return 0;
   }
//   for(int i=0;i<lx;i++)
//   {
//      for(int j=0;j<ly;j++)
//      {
//         printf("%d ",fie[i][j]);
//      }
//      printf("\n");
//   }
//   system("PAUSE");
//   for(int i=0;i<=now;i++)
//   {
//      cout << "untuk " << i << " ada " << ada[i] << " dan mw pake " << pake[i] << endl;
//      if(pake[i]!=ada[i]) return 0;
//   }
   return 1;
}

vvi make_dim(int lx, int ly)
{
   vvi ret;
   tmp.clear();
   for(int i=1;i<=ly;i++) tmp.push_back(-1);
   for(int i=1;i<=lx;i++) ret.push_back(tmp);
   return ret;
}

bool cek(int lx, int ly)
{
   memset(pake,0,sizeof(pake));
//   cout << "dimensi " << lx << " " << ly << endl;
   fie = make_dim(lx,ly);
   priority_queue<int> pq;
   for(int i=1;i<=t;i++)
   {
      pq.push(li[i]);
   }
   int now=pq.top(); pq.pop();
//   int maks=now;
   fie[0][ly-1] = now;
   pake[now]++;
   int cnt = 1;
   now--;
   bool out=0;
   while(!pq.empty() && cnt!=lx && cnt!=ly)
   {
      int cur = pq.top(); pq.pop();
      if(cur != now)
      {
         fie[lx-1][ly-1] = cur;
         pake[cur]++;
         break;
      }
//      cout << cur << endl;
      for(int i=1;i<=cnt;i++)
      {
         cur = pq.top();
         pq.pop();
         if(cur!=now)
         {
            fie[lx-1][ly-1] = cur;
            pake[cur]++;
            out = 1;
            break;
         }
      }
      if(out) break;
      fie[cnt][ly-1]=now;
      pake[now]++;
      now--;
      cnt++;
   }
   if(fie[lx-1][ly-1]==-1) return 0;
   int dif = fie[0][ly-1] - fie[lx-1][ly-1];
//   cout << fie[0][ly-1] << " " << fie[lx-1][ly-1] << endl;
   if((dif+lx-1)%2==1) return 0;
   int temu = (dif+lx-1)/2;
   int kur = temu-dif;
   kur = fie[lx-1][ly-1]-kur;
//   cout << "kur = " << kur << endl;
   if(kur<0) return 0;
   int temuy = ly-1-kur;
   if(temuy < 0) return 0;
//   cout << kur << endl;
//   cout << "/>>> " << temu << " " << temuy << endl;
   return ff(temu,temuy, lx, ly);
}

int main()
{
   memset(ada,0,sizeof(ada));
//   memset(pake,0,sizeof(pake));
   scanf("%d",&t);
   for(int i=1;i<=t;i++)
   {
      scanf("%d",&li[i]);
      ada[li[i]]++;
   }
   bool done=0;
   for(int i=1;i*i<=t;i++)
   {
      if(t%i!=0) continue;
      if(cek(i,t/i))
      {
         done = 1;
         printf("%d %d\n",i,t/i);
         break;
      }
      if(cek(t/i,i))
      {
         done = 1;
         printf("%d %d\n",t/i,i);
         break;
      }
   }
   if(!done) printf("-1\n");
   else printf("%d %d\n",px+1,py+1);
 	return 0;
}


#include <bits/stdc++.h>

using namespace std;

const int OO = 0x3f3f3f3f;
const double eps = (1e-10);

#define watch(x) cout << (#x) << " is " << (x) << '\n'
#define trav(a, x) 			for(auto& a : x)
#define lp(i, n) 			for(int i=0;i<(int)(n);++i)
#define lpi(i, j, n) 		for(int i=(j);i<(int)(n);++i)
#define lpd(i, j, n) 		for(int i=(j);i>=(int)(n);--i)
#define ndl 				cout<<'\n'
#define all(v) 				((v).begin()), ((v).end())
#define rall(v) 			((v).rbegin()), ((v).rend())
#define present(a, x) 		((a).find((x)) != a.end())
#define cpresent(a, x) 		(find(all(a),x) != a.end())
#define sz(v) 				((int)((v).size()))
#define clr(v, d) 			memset(v, d, sizeof(v))
#define pb 					push_back
#define mp 					make_pair
#define fs 					first
#define sc 					second
#define fstok(s,del) 		strtok((char *)s.c_str(),del)
#define tok(del) 			strtok(nullptr,del)
#define mod(x, m) 			((((x) % (m)) + (m)) % (m))

typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pair<int, int> > vii;
typedef vector<vector<int> > vvi;
typedef vector<bool> vb;
typedef map<int, int> mii;
typedef map<int, bool> mib;
typedef set<int> si;

int t,ai,mx=-1,m,freq[1000001],occur[1000001];

int main() {
	ios::sync_with_stdio(false);
	cout.precision(10);
	cin>>t;
	lp(i,t){
		cin>>ai;
		mx=max(mx,ai);
		++freq[ai];
	}
	if (t==1){
		cout<<(freq[0]==1?"1 1\n1 1\n":"-1\n");
		return 0;
	}
	if (freq[0]!=1)
		{cout<<"-1\n";	return 0;}
	int I;
	for(I=1;I<=t;++I)
		if (freq[I]!=4*I)
			break;
	for(int n=1;n<=t;++n){
		if (t%n)
			continue;
		m=t/n;
		int x=I-1,y=m-1-(mx-n+I);
		clr(occur,0);
		bool flag=true;
		lp(i,n){
			if (!flag)
				break;
			lp(j,m){
				int dist=abs(x-i)+abs(y-j);
				++occur[dist];
				if (occur[dist]>freq[dist])
					{flag=false;	break;}
			}
		}
		if (flag){
			cout<<n<<' '<<m<<'\n'<<x+1<<' '<<y+1<<'\n';
			return 0;
		}
	}
	cout<<"-1\n";
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

const int OO = 0x3f3f3f3f;
const double eps = (1e-10);

#define watch(x) cout << (#x) << " is " << (x) << '\n'
#define trav(a, x) 			for(auto& a : x)
#define lp(i, n) 			for(int i=0;i<(int)(n);++i)
#define lpi(i, j, n) 		for(int i=(j);i<(int)(n);++i)
#define lpd(i, j, n) 		for(int i=(j);i>=(int)(n);--i)
#define ndl 				cout<<'\n'
#define all(v) 				((v).begin()), ((v).end())
#define rall(v) 			((v).rbegin()), ((v).rend())
#define present(a, x) 		((a).find((x)) != a.end())
#define cpresent(a, x) 		(find(all(a),x) != a.end())
#define sz(v) 				((int)((v).size()))
#define clr(v, d) 			memset(v, d, sizeof(v))
#define pb 					push_back
#define mp 					make_pair
#define fs 					first
#define sc 					second
#define fstok(s,del) 		strtok((char *)s.c_str(),del)
#define tok(del) 			strtok(nullptr,del)
#define mod(x, m) 			((((x) % (m)) + (m)) % (m))

typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pair<int, int> > vii;
typedef vector<vector<int> > vvi;
typedef vector<bool> vb;
typedef map<int, int> mii;
typedef map<int, bool> mib;
typedef set<int> si;

int t,ai,mx=-1,n[3],m;
mii M;

int main() {
	ios::sync_with_stdio(false);
	cout.precision(10);
	cin>>t;
	lp(i,t){
		cin>>ai;
		mx=max(mx,ai);
		++M[ai];
	}
	if (t==1){
		cout<<(M[0]==1?"1 1\n1 1\n":"-1\n");
		return 0;
	}
	if (M[0]!=1)
		{cout<<"-1\n";	return 0;}
	int I=1,occur,j=1;
	trav(p,M){
		I=p.fs,occur=p.sc;
		if (!I)
			continue;
		if (I!=j+1)
			{cout<<"-1\n";	return 0;}
		if (occur!=4*I)
			break;
	}
	n[1]=2*(I-1)+1,n[2]=n[1]+1;
	lpi(k,1,3){
		if (t%n[k]==0){
			m=t/n[k];
			int x=I-1,y=m-1-(mx-n[k]+I);
			mii M2=M;
			bool flag=true;
			lp(i,n[k])lp(j,m){
				int dist=abs(x-i)+abs(y-j);
				--M2[dist];
				if (M2[dist]<0)
					{flag=false;	break;}
			}
			if (flag){
				cout<<n[k]<<' '<<m<<'\n'<<x+1<<' '<<y+1<<'\n';
				return 0;
			}
		}
	}
	cout<<"-1\n";
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

const int OO = 0x3f3f3f3f;
const double eps = (1e-10);

#define watch(x) cout << (#x) << " is " << (x) << '\n'
#define trav(a, x) 			for(auto& a : x)
#define lp(i, n) 			for(int i=0;i<(int)(n);++i)
#define lpi(i, j, n) 		for(int i=(j);i<(int)(n);++i)
#define lpd(i, j, n) 		for(int i=(j);i>=(int)(n);--i)
#define ndl 				cout<<'\n'
#define all(v) 				((v).begin()), ((v).end())
#define rall(v) 			((v).rbegin()), ((v).rend())
#define present(a, x) 		((a).find((x)) != a.end())
#define cpresent(a, x) 		(find(all(a),x) != a.end())
#define sz(v) 				((int)((v).size()))
#define clr(v, d) 			memset(v, d, sizeof(v))
#define pb 					push_back
#define mp 					make_pair
#define fs 					first
#define sc 					second
#define fstok(s,del) 		strtok((char *)s.c_str(),del)
#define tok(del) 			strtok(nullptr,del)
#define mod(x, m) 			((((x) % (m)) + (m)) % (m))

typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pair<int, int> > vii;
typedef vector<vector<int> > vvi;
typedef vector<bool> vb;
typedef map<int, int> mii;
typedef map<int, bool> mib;
typedef set<int> si;

int t,ai,mx=-1,n[3],m;
mii M;

int main() {
	ios::sync_with_stdio(false);
	cout.precision(10);
	cin>>t;
	lp(i,t){
		cin>>ai;
		mx=max(mx,ai);
		++M[ai];
	}
	if (t==1){
		cout<<(M[0]==1?"1 1\n1 1\n":"-1\n");
		return 0;
	}
	if (M[0]!=1)
		{cout<<"-1\n";	return 0;}
	int I=1,occur,j=0;
	trav(p,M){
		I=p.fs,occur=p.sc;
		if (!I)
			continue;
		if (I!=j+1)
			{cout<<"-1\n";	return 0;}
		j=I;
		if (occur!=4*I)
			break;
	}
	for(int n=1;n*n<=t;++n){
		if (t%n)
			continue;
		m=t/n;
		int x=I-1,y=m-1-(mx-n+I);
		mii M2=M;
		bool flag=true;
		lp(i,n){
			if (!flag)
				break;
			lp(j,m){
			int dist=abs(x-i)+abs(y-j);
			--M2[dist];
			if (M2[dist]<0)
				{flag=false;	break;}
			}
		}
		if (flag){
			cout<<n<<' '<<m<<'\n'<<x+1<<' '<<y+1<<'\n';
			return 0;
		}

	}
	cout<<"-1\n";
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

const int OO = 0x3f3f3f3f;
const double eps = (1e-10);

#define watch(x) cout << (#x) << " is " << (x) << '\n'
#define trav(a, x) 			for(auto& a : x)
#define lp(i, n) 			for(int i=0;i<(int)(n);++i)
#define lpi(i, j, n) 		for(int i=(j);i<(int)(n);++i)
#define lpd(i, j, n) 		for(int i=(j);i>=(int)(n);--i)
#define ndl 				cout<<'\n'
#define all(v) 				((v).begin()), ((v).end())
#define rall(v) 			((v).rbegin()), ((v).rend())
#define present(a, x) 		((a).find((x)) != a.end())
#define cpresent(a, x) 		(find(all(a),x) != a.end())
#define sz(v) 				((int)((v).size()))
#define clr(v, d) 			memset(v, d, sizeof(v))
#define pb 					push_back
#define mp 					make_pair
#define fs 					first
#define sc 					second
#define fstok(s,del) 		strtok((char *)s.c_str(),del)
#define tok(del) 			strtok(nullptr,del)
#define mod(x, m) 			((((x) % (m)) + (m)) % (m))

typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pair<int, int> > vii;
typedef vector<vector<int> > vvi;
typedef vector<bool> vb;
typedef map<int, int> mii;
typedef map<int, bool> mib;
typedef set<int> si;

int t,ai,mx=-1,n[3],m;
mii M;

int main() {
	ios::sync_with_stdio(false);
	cout.precision(10);
	cin>>t;
	lp(i,t){
		cin>>ai;
		mx=max(mx,ai);
		++M[ai];
	}
	if (t==1){
		cout<<(M[0]==1?"1 1\n1 1\n":"-1\n");
		return 0;
	}
	if (M[0]!=1)
		{cout<<"-1\n";	return 0;}
	int I=1,occur;
	trav(p,M){
		I=p.fs,occur=p.sc;
		if (!I)
			continue;
		if (occur!=4*I)
			break;
	}
	for(int n=1;n*n<=t;++n){
		if (t%n)
			continue;
		m=t/n;
		int x=I-1,y=m-1-(mx-n+I);
		mii M2=M;
		bool flag=true;
		lp(i,n){
			if (!flag)
				break;
			lp(j,m){
				int dist=abs(x-i)+abs(y-j);
				--M2[dist];
				if (M2[dist]<0)
					{flag=false;	break;}
			}
		}
		if (flag){
			cout<<n<<' '<<m<<'\n'<<x+1<<' '<<y+1<<'\n';
			return 0;
		}

	}
	cout<<"-1\n";
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

const int OO = 0x3f3f3f3f;
const double eps = (1e-10);

#define watch(x) cout << (#x) << " is " << (x) << '\n'
#define trav(a, x) 			for(auto& a : x)
#define lp(i, n) 			for(int i=0;i<(int)(n);++i)
#define lpi(i, j, n) 		for(int i=(j);i<(int)(n);++i)
#define lpd(i, j, n) 		for(int i=(j);i>=(int)(n);--i)
#define ndl 				cout<<'\n'
#define all(v) 				((v).begin()), ((v).end())
#define rall(v) 			((v).rbegin()), ((v).rend())
#define present(a, x) 		((a).find((x)) != a.end())
#define cpresent(a, x) 		(find(all(a),x) != a.end())
#define sz(v) 				((int)((v).size()))
#define clr(v, d) 			memset(v, d, sizeof(v))
#define pb 					push_back
#define mp 					make_pair
#define fs 					first
#define sc 					second
#define fstok(s,del) 		strtok((char *)s.c_str(),del)
#define tok(del) 			strtok(nullptr,del)
#define mod(x, m) 			((((x) % (m)) + (m)) % (m))

typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pair<int, int> > vii;
typedef vector<vector<int> > vvi;
typedef vector<bool> vb;
typedef map<int, int> mii;
typedef map<int, bool> mib;
typedef set<int> si;

int t,ai,mx=-1,n[3],m;
mii M;

int main() {
	ios::sync_with_stdio(false);
	cout.precision(10);
	cin>>t;
	lp(i,t){
		cin>>ai;
		mx=max(mx,ai);
		++M[ai];
	}
	if (t==1){
		cout<<(M[0]==1?"1 1\n1 1\n":"-1\n");
		return 0;
	}
	if (M[0]!=1)
		{cout<<"-1\n";	return 0;}
	int I=1,occur,j=0;
	trav(p,M){
		I=p.fs,occur=p.sc;
		if (!I)
			continue;
		if (I!=j+1)
			{cout<<"-1\n";	return 0;}
		j=I;
		if (occur!=4*I)
			break;
	}
	n[1]=2*(I-1)+1,n[2]=n[1]+1;
	lpi(k,1,3){
		if (t%n[k]==0){
			m=t/n[k];
			int x=I-1,y=m-1-(mx-n[k]+I);
			mii M2=M;
			bool flag=true;
			lp(i,n[k])lp(j,m){
				int dist=abs(x-i)+abs(y-j);
				--M2[dist];
				if (M2[dist]<0)
					{flag=false;	break;}
			}
			if (flag){
				cout<<n[k]<<' '<<m<<'\n'<<x+1<<' '<<y+1<<'\n';
				return 0;
			}
		}
	}
	cout<<"-1\n";
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

const int OO = 0x3f3f3f3f;
const double eps = (1e-10);

#define watch(x) cout << (#x) << " is " << (x) << '\n'
#define trav(a, x) 			for(auto& a : x)
#define lp(i, n) 			for(int i=0;i<(int)(n);++i)
#define lpi(i, j, n) 		for(int i=(j);i<(int)(n);++i)
#define lpd(i, j, n) 		for(int i=(j);i>=(int)(n);--i)
#define ndl 				cout<<'\n'
#define all(v) 				((v).begin()), ((v).end())
#define rall(v) 			((v).rbegin()), ((v).rend())
#define present(a, x) 		((a).find((x)) != a.end())
#define cpresent(a, x) 		(find(all(a),x) != a.end())
#define sz(v) 				((int)((v).size()))
#define clr(v, d) 			memset(v, d, sizeof(v))
#define pb 					push_back
#define mp 					make_pair
#define fs 					first
#define sc 					second
#define fstok(s,del) 		strtok((char *)s.c_str(),del)
#define tok(del) 			strtok(nullptr,del)
#define mod(x, m) 			((((x) % (m)) + (m)) % (m))

typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pair<int, int> > vii;
typedef vector<vector<int> > vvi;
typedef vector<bool> vb;
typedef map<int, int> mii;
typedef map<int, bool> mib;
typedef set<int> si;

int t,ai,mx=-1,n[3],m;
mii M;

int main() {
	ios::sync_with_stdio(false);
	cout.precision(10);
	cin>>t;
	lp(i,t){
		cin>>ai;
		mx=max(mx,ai);
		++M[ai];
	}
	if (t==1){
		cout<<(M[0]==1?"1 1\n1 1\n":"-1\n");
		return 0;
	}
	if (M[0]!=1)
		{cout<<"-1\n";	return 0;}
	int I=1,occur;
	trav(p,M){
		I=p.fs,occur=p.sc;
		if (!I)
			continue;
		if (occur!=4*I)
			break;
	}
	for(int n=1;n<=t;++n){
		if (t%n)
			continue;
		m=t/n;
		int x=I-1,y=m-1-(mx-n+I);
		mii M2=M;
		bool flag=true;
		lp(i,n){
			if (!flag)
				break;
			lp(j,m){
				int dist=abs(x-i)+abs(y-j);
				--M2[dist];
				if (M2[dist]<0)
					{flag=false;	break;}
			}
		}
		if (flag){
			cout<<n<<' '<<m<<'\n'<<x+1<<' '<<y+1<<'\n';
			return 0;
		}

	}
	cout<<"-1\n";
	return 0;
}


#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <cmath>
#include <algorithm>
#include <bitset>
#include <list>
#include <string>
#define INF (int)1e9
#define MAX (int)1e7
#define EPS (int)-1e9
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> VI;
typedef vector<VI> VII;
using namespace std;

int main() {
    int n;
    cin >> n;
    vector<string> ar(n);
    vector<string> tf(n);
    for(int i = 0; i < n; i++) {
        cin >> ar[i];
    }
    sort(ar.begin(), ar.end());
    for(int i = 0; i < n; i++) {
        string S = ar[i];
        tf[i] = S;
        std::sort(S.begin(), S.end());
        ar[i] = S;

    }

    vector<string> roots;
    for(int i = 0; i < n; i++) {
        bool isR = 1;
        map<char,int> FREQ;
        for(int j = 0;j < roots.size(); j++) {
            if (ar[i] == roots[j])
                isR = 0;
        }
        for(int j = 0; j < ar[i].size(); j++) {
            FREQ[ar[i][j]]++;
        }
        for(auto x : FREQ)
            if (x.second > 1)
                isR = 0;
        if (isR) {
            roots.push_back(ar[i]);
            ar[i] = "JOA";
        }
    }
    int ans = roots.size();
    for(int i = 0; i < n; i++) {
        bool match = true;
        if (ar[i] == "JOA")
            continue;
        set<char> s1;
        set<char> s2;
        for(auto x : ar[i])
            s1.insert(x);
        for(int j = 0; j < roots.size(); j++) {
            match = true;
            for(auto x : roots[j])
                if (s1.count(x) != 1)
                    match = 0;
            if (match)
                break;
        }
        if (!match)
            ans++;
    }

    cout << ans << endl;
    return 0;
}


#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <cmath>
#include <algorithm>
#include <bitset>
#include <list>
#include <string>
#define INF (int)1e9
#define MAX (int)1e7
#define EPS (int)-1e9
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> VI;
typedef vector<VI> VII;
using namespace std;

int main() {
    int n;
    cin >> n;
    vector<string> ar(n);
    vector<string> tf(n);
    for(int i = 0; i < n; i++) {
        cin >> ar[i];
    }
    sort(ar.begin(), ar.end());
    for(int i = 0; i < n; i++) {
        string S = ar[i];
        tf[i] = S;
        std::sort(S.begin(), S.end());
        ar[i] = S;

    }

    vector<string> roots;
    for(int i = 0; i < n; i++) {
        bool isR = 1;
        map<char,int> FREQ;
        for(int j = 0;j < roots.size(); j++) {
            if (ar[i] == roots[j])
                isR = 0;
        }
        for(int j = 0; j < ar[i].size(); j++) {
            FREQ[ar[i][j]]++;
        }
        for(auto x : FREQ)
            if (x.second > 1)
                isR = 0;
        if (isR) {
            roots.push_back(ar[i]);
            ar[i] = "JOA";
        }
    }
    int ans = roots.size();
    for(int i = 0; i < n; i++) {
        bool hr = 1;
        for(int j = 0; j < roots.size(); j++) {
            string str = ar[i];
            string subtr = roots[j];
            if (str.find(subtr) == std::string::npos) {
                hr = 0;
            }
            else {
                hr = 1;
                break;
            }
        }
        if (!hr && ar[i] != "JOA")
            ans++;
    }

    cout << ans << endl;
    return 0;
}


#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <cmath>
#include <algorithm>
#include <bitset>
#include <list>
#include <string>
#define INF (int)1e9
#define MAX (int)1e7
#define EPS (int)-1e9
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> VI;
typedef vector<VI> VII;
using namespace std;

int main() {
    int n;
    cin >> n;
    vector<string> ar(n);
    vector<string> tf(n);
    for(int i = 0; i < n; i++) {
        cin >> ar[i];
    }
    sort(ar.begin(), ar.end());
    for(int i = 0; i < n; i++) {
        string S = ar[i];
        tf[i] = S;
        std::sort(S.begin(), S.end());
        ar[i] = S;

    }

    vector<string> roots;
    for(int i = 0; i < n; i++) {
        bool isR = 1;
        map<char,int> FREQ;
        for(int j = 0;j < roots.size(); j++) {
            if (ar[i] == roots[j])
                isR = 0;
        }
        for(int j = 0; j < ar[i].size(); j++) {
            FREQ[ar[i][j]]++;
        }
        for(auto x : FREQ)
            if (x.second > 1)
                isR = 0;
        if (isR) {
            roots.push_back(ar[i]);
            ar[i] = "JOA";
        }
    }
    int ans = roots.size();

    cout << ans << endl;
    return 0;
}


using namespace std;

                   #include <bits/stdc++.h>
                         #define ll long long
                         #define scanint1(a) scanf("%d",&a)
                         #define scanint2(a,b) scanf("%d %d",&a,&b)
                         #define scanint3(a,b,c) scanf("%d %d %d",&a,&b,&c)
                         #define scanint4(a,b,c,d) scanf("%d %d %d %d",&a,&b,&c,&d)
                         #define scanint5(a,b,c,d,e) scanf("%d %d %d %d %d",&a,&b,&c,&d,&e)
                         #define scanint6(a,b,c,d,e,f) scanf("%d %d %d %d %d %d",&a,&b,&c,&d,&e,&f)

                         #define scanlong1(a) scanf("%ld",&a)
                         #define scanlong2(a,b) scanf("%ld %ld",&a,&b)
                         #define scanlong3(a,b,c) scanf("%ld %ld %ld",&a,&b,&c)
                         #define scanlong4(a,b,c,d) scanf("%ld %ld %ld %ld",&a,&b,&c,&d)
                         #define scanlong5(a,b,c,d,e) scanf("%ld %ld %ld %ld %ld",&a,&b,&c,&d,&e)
                         #define scanll1(a) scanf("%lld",&a)
                         #define scanll2(a,b) scanf("%lld %lld",&a,&b)
                         #define scanll3(a,b,c) scanf("%lld %lld %lld",&a,&b,&c)
                         #define scanll4(a,b,c,d) scanf("%lld %lld %lld %lld",&a,&b,&c,&d)
                         #define scanll5(a,b,c,d,e) scanf("%lld %lld %lld %lld %lld",&a,&b,&c,&d,&e)

                         #define read  freopen("input.txt","r",stdin);
                         #define write  reopen("output.txt","w",stdout);

                         //Convert from int to char (0 to 25 )--->(a to z) == (char)(int+97)
                         //Convert from char int to int char-48
                         //~ reflects 0 to 1 and 1 to 0 ; ex:: ~5 =-5
                         //tester.erase(std::remove(tester.begin(), tester.end(), '0'), tester.end());
                        // int dx[] ={-1,0,0,1};
                        // int dy[] ={0,1,-1,0};
                        /*for(int k = 0 ; k<4;k++){
                                            int nx = dx[k] + x;
                                            int ny = dy[k]+y;
                                             if(!vis[nx][ny] &&valid(nx,ny)){
                                                vis[nx][ny] = vis[x][y] + 1;
                                                q.push({nx,ny});

                                            }
                                        }  */

                             using namespace std;

                                int main()

                             {

                                    int n;
                                    scanint1(n);
                                    set<string > vc;

                                    for(int i=1;i<=n;i++)
                                    {
                                        string x;
                                        cin>>x;
                                        sort(x.begin(),x.end());
                                        set<char> st;
                                        for(char j:x)
                                        st.insert(j);
                                        string s;
                                        for(auto it=st.begin();it!=st.end();it++)
                                        {
                                            s+=*it;

                                        }
                                        vc.insert(s);

                                    }

                                    cout<<vc.size()<<endl;
                                    return 0;

                             }


using namespace std;

                   #include <bits/stdc++.h>
                         #define ll long long
                         #define scanint1(a) scanf("%d",&a)
                         #define scanint2(a,b) scanf("%d %d",&a,&b)
                         #define scanint3(a,b,c) scanf("%d %d %d",&a,&b,&c)
                         #define scanint4(a,b,c,d) scanf("%d %d %d %d",&a,&b,&c,&d)
                         #define scanint5(a,b,c,d,e) scanf("%d %d %d %d %d",&a,&b,&c,&d,&e)
                         #define scanint6(a,b,c,d,e,f) scanf("%d %d %d %d %d %d",&a,&b,&c,&d,&e,&f)

                         #define scanlong1(a) scanf("%ld",&a)
                         #define scanlong2(a,b) scanf("%ld %ld",&a,&b)
                         #define scanlong3(a,b,c) scanf("%ld %ld %ld",&a,&b,&c)
                         #define scanlong4(a,b,c,d) scanf("%ld %ld %ld %ld",&a,&b,&c,&d)
                         #define scanlong5(a,b,c,d,e) scanf("%ld %ld %ld %ld %ld",&a,&b,&c,&d,&e)
                         #define scanll1(a) scanf("%lld",&a)
                         #define scanll2(a,b) scanf("%lld %lld",&a,&b)
                         #define scanll3(a,b,c) scanf("%lld %lld %lld",&a,&b,&c)
                         #define scanll4(a,b,c,d) scanf("%lld %lld %lld %lld",&a,&b,&c,&d)
                         #define scanll5(a,b,c,d,e) scanf("%lld %lld %lld %lld %lld",&a,&b,&c,&d,&e)

                         #define read  freopen("input.txt","r",stdin);
                         #define write  reopen("output.txt","w",stdout);

                         //Convert from int to char (0 to 25 )--->(a to z) == (char)(int+97)
                         //Convert from char int to int char-48
                         //~ reflects 0 to 1 and 1 to 0 ; ex:: ~5 =-5
                         //tester.erase(std::remove(tester.begin(), tester.end(), '0'), tester.end());
                        // int dx[] ={-1,0,0,1};
                        // int dy[] ={0,1,-1,0};
                        /*for(int k = 0 ; k<4;k++){
                                            int nx = dx[k] + x;
                                            int ny = dy[k]+y;
                                             if(!vis[nx][ny] &&valid(nx,ny)){
                                                vis[nx][ny] = vis[x][y] + 1;
                                                q.push({nx,ny});

                                            }
                                        }  */

                             using namespace std;

                                int main()

                             {
                                    int n;
                                    scanint1(n);
                                    vector<string> vc;
                                    for(int i=1;i<=n;i++)
                                    {
                                        string s;
                                        cin>>s;
                                        vc.push_back(s);

                                    }
                                    int counter=0;
                                    //sort(vc.begin(),vc.end());
                                    for(int i=0;i<vc.size();i++)
                                    {
                                        map<char,int> mp;
                                        bool differ =0;
                                        if(!counter){counter++; continue;}
                                                   for(char j:vc[i])
                                                           {
                                                     mp[j]++;
                                                            }

                                                for(int j=i-1;j>=0;j--)
                                                 {
                                                      map<char,int> mp1;

                                                        for(char x:vc[j])
                                                     {
                                                         mp1[x]++;
                                                     }
                                                      for(auto it =mp.begin();it!=mp.end();it++)
                                                     {
                                                      if(!mp1[it->first]){differ=1; break; }

                                                      }
                                                 if(!differ) break;

                                                 }

                                                 if(differ) counter++;

                                         }

                                    cout<<counter<<endl;

                                    return 0;

                             }


using namespace std;

                   #include <bits/stdc++.h>
                         #define ll long long
                         #define scanint1(a) scanf("%d",&a)
                         #define scanint2(a,b) scanf("%d %d",&a,&b)
                         #define scanint3(a,b,c) scanf("%d %d %d",&a,&b,&c)
                         #define scanint4(a,b,c,d) scanf("%d %d %d %d",&a,&b,&c,&d)
                         #define scanint5(a,b,c,d,e) scanf("%d %d %d %d %d",&a,&b,&c,&d,&e)
                         #define scanint6(a,b,c,d,e,f) scanf("%d %d %d %d %d %d",&a,&b,&c,&d,&e,&f)

                         #define scanlong1(a) scanf("%ld",&a)
                         #define scanlong2(a,b) scanf("%ld %ld",&a,&b)
                         #define scanlong3(a,b,c) scanf("%ld %ld %ld",&a,&b,&c)
                         #define scanlong4(a,b,c,d) scanf("%ld %ld %ld %ld",&a,&b,&c,&d)
                         #define scanlong5(a,b,c,d,e) scanf("%ld %ld %ld %ld %ld",&a,&b,&c,&d,&e)
                         #define scanll1(a) scanf("%lld",&a)
                         #define scanll2(a,b) scanf("%lld %lld",&a,&b)
                         #define scanll3(a,b,c) scanf("%lld %lld %lld",&a,&b,&c)
                         #define scanll4(a,b,c,d) scanf("%lld %lld %lld %lld",&a,&b,&c,&d)
                         #define scanll5(a,b,c,d,e) scanf("%lld %lld %lld %lld %lld",&a,&b,&c,&d,&e)

                         #define read  freopen("input.txt","r",stdin);
                         #define write  reopen("output.txt","w",stdout);

                         //Convert from int to char (0 to 25 )--->(a to z) == (char)(int+97)
                         //Convert from char int to int char-48
                         //~ reflects 0 to 1 and 1 to 0 ; ex:: ~5 =-5
                         //tester.erase(std::remove(tester.begin(), tester.end(), '0'), tester.end());
                        // int dx[] ={-1,0,0,1};
                        // int dy[] ={0,1,-1,0};
                        /*for(int k = 0 ; k<4;k++){
                                            int nx = dx[k] + x;
                                            int ny = dy[k]+y;
                                             if(!vis[nx][ny] &&valid(nx,ny)){
                                                vis[nx][ny] = vis[x][y] + 1;
                                                q.push({nx,ny});

                                            }
                                        }  */

                             using namespace std;

                                int main()

                             {

                                    int n;
                                    scanint1(n);
                                    vector<string> vc;

                                    for(int i=1;i<=n;i++)
                                    {
                                        string x;
                                        cin>>x;
                                        sort(x.begin(),x.end());
                                        vc.push_back(x);
                                    }
                                    sort(vc.begin(),vc.end());

                                    vector<string> history;
                                    int counter=0;
                                    for(int i=vc.size()-1;i>=0;i--)
                                    {
                                        string s = vc[i];
                                        bool differ =1;

                                          for(int x =0;x<history.size();x++)
                                          {
                                              if(history[x].find(vc[i])!=string::npos ){differ =0; break;}
                                          }

                                        if(differ) counter++;
                                        history.push_back(s);
                                    }

                                    cout<<counter<<endl;
                                    return 0;

                             }


using namespace std;

                   #include <bits/stdc++.h>
                         #define ll long long
                         #define scanint1(a) scanf("%d",&a)
                         #define scanint2(a,b) scanf("%d %d",&a,&b)
                         #define scanint3(a,b,c) scanf("%d %d %d",&a,&b,&c)
                         #define scanint4(a,b,c,d) scanf("%d %d %d %d",&a,&b,&c,&d)
                         #define scanint5(a,b,c,d,e) scanf("%d %d %d %d %d",&a,&b,&c,&d,&e)
                         #define scanint6(a,b,c,d,e,f) scanf("%d %d %d %d %d %d",&a,&b,&c,&d,&e,&f)

                         #define scanlong1(a) scanf("%ld",&a)
                         #define scanlong2(a,b) scanf("%ld %ld",&a,&b)
                         #define scanlong3(a,b,c) scanf("%ld %ld %ld",&a,&b,&c)
                         #define scanlong4(a,b,c,d) scanf("%ld %ld %ld %ld",&a,&b,&c,&d)
                         #define scanlong5(a,b,c,d,e) scanf("%ld %ld %ld %ld %ld",&a,&b,&c,&d,&e)
                         #define scanll1(a) scanf("%lld",&a)
                         #define scanll2(a,b) scanf("%lld %lld",&a,&b)
                         #define scanll3(a,b,c) scanf("%lld %lld %lld",&a,&b,&c)
                         #define scanll4(a,b,c,d) scanf("%lld %lld %lld %lld",&a,&b,&c,&d)
                         #define scanll5(a,b,c,d,e) scanf("%lld %lld %lld %lld %lld",&a,&b,&c,&d,&e)

                         #define read  freopen("input.txt","r",stdin);
                         #define write  reopen("output.txt","w",stdout);

                         //Convert from int to char (0 to 25 )--->(a to z) == (char)(int+97)
                         //Convert from char int to int char-48
                         //~ reflects 0 to 1 and 1 to 0 ; ex:: ~5 =-5
                         //tester.erase(std::remove(tester.begin(), tester.end(), '0'), tester.end());
                        // int dx[] ={-1,0,0,1};
                        // int dy[] ={0,1,-1,0};
                        /*for(int k = 0 ; k<4;k++){
                                            int nx = dx[k] + x;
                                            int ny = dy[k]+y;
                                             if(!vis[nx][ny] &&valid(nx,ny)){
                                                vis[nx][ny] = vis[x][y] + 1;
                                                q.push({nx,ny});

                                            }
                                        }  */

                             using namespace std;

                                int main()

                             {
                                    int n;
                                    scanint1(n);
                                    vector<string> vc;
                                    for(int i=1;i<=n;i++)
                                    {
                                        string s;
                                        cin>>s;
                                        vc.push_back(s);

                                    }
                                    int counter=1;
                                    //sort(vc.begin(),vc.end());
                                    for(int i=1;i<vc.size();i++)
                                    {
                                        map<char,int> mp;
                                        bool differ =0;
                                                   for(char j:vc[i])
                                                           {
                                                     mp[j]++;
                                                            }

                                                for(int j=i-1;j>=0;j--)
                                                 {
                                                      map<char,int> mp1;

                                                        for(char x:vc[j])
                                                     {
                                                         mp1[x]++;
                                                     }
                                                      for(auto it =mp.begin();it!=mp.end();it++)
                                                     {
                                                      if(!mp1[it->first]){differ=1; break; }

                                                      }
                                                 if(!differ) break;

                                                 }

                                                 if(differ) counter++;

                                         }

                                    cout<<counter<<endl;

                                    return 0;

                             }


using namespace std;

                   #include <bits/stdc++.h>
                         #define ll long long
                         #define scanint1(a) scanf("%d",&a)
                         #define scanint2(a,b) scanf("%d %d",&a,&b)
                         #define scanint3(a,b,c) scanf("%d %d %d",&a,&b,&c)
                         #define scanint4(a,b,c,d) scanf("%d %d %d %d",&a,&b,&c,&d)
                         #define scanint5(a,b,c,d,e) scanf("%d %d %d %d %d",&a,&b,&c,&d,&e)
                         #define scanint6(a,b,c,d,e,f) scanf("%d %d %d %d %d %d",&a,&b,&c,&d,&e,&f)

                         #define scanlong1(a) scanf("%ld",&a)
                         #define scanlong2(a,b) scanf("%ld %ld",&a,&b)
                         #define scanlong3(a,b,c) scanf("%ld %ld %ld",&a,&b,&c)
                         #define scanlong4(a,b,c,d) scanf("%ld %ld %ld %ld",&a,&b,&c,&d)
                         #define scanlong5(a,b,c,d,e) scanf("%ld %ld %ld %ld %ld",&a,&b,&c,&d,&e)
                         #define scanll1(a) scanf("%lld",&a)
                         #define scanll2(a,b) scanf("%lld %lld",&a,&b)
                         #define scanll3(a,b,c) scanf("%lld %lld %lld",&a,&b,&c)
                         #define scanll4(a,b,c,d) scanf("%lld %lld %lld %lld",&a,&b,&c,&d)
                         #define scanll5(a,b,c,d,e) scanf("%lld %lld %lld %lld %lld",&a,&b,&c,&d,&e)

                         #define read  freopen("input.txt","r",stdin);
                         #define write  reopen("output.txt","w",stdout);

                         //Convert from int to char (0 to 25 )--->(a to z) == (char)(int+97)
                         //Convert from char int to int char-48
                         //~ reflects 0 to 1 and 1 to 0 ; ex:: ~5 =-5
                         //tester.erase(std::remove(tester.begin(), tester.end(), '0'), tester.end());
                        // int dx[] ={-1,0,0,1};
                        // int dy[] ={0,1,-1,0};
                        /*for(int k = 0 ; k<4;k++){
                                            int nx = dx[k] + x;
                                            int ny = dy[k]+y;
                                             if(!vis[nx][ny] &&valid(nx,ny)){
                                                vis[nx][ny] = vis[x][y] + 1;
                                                q.push({nx,ny});

                                            }
                                        }  */

                             using namespace std;

                                int main()

                             {
                                    int n;
                                    scanint1(n);
                                    vector<string> vc;
                                    for(int i=1;i<=n;i++)
                                    {
                                        string s;
                                        cin>>s;
                                        sort(s.begin(),s.end());
                                        vc.push_back(s);

                                    }
                                    int counter=1;
                                    sort(vc.begin(),vc.end());

                                    for(int i=vc.size()-2;i>=0;i--)
                                    {

                                           int differ=1;

                                            for(int j=i+1;j<vc.size();j++)
                                            {

                                               if(vc[j].find(vc[i])!=string::npos) {differ=0; break;}

                                            }
                                            if(differ) counter++;

                                    }
                                    cout<<counter<<endl;

                                    return 0;

                             }


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

int n;
string str;
long long str1;
map<long long, bool> ima;
map<char, long long> h;
map<char, bool> prosao;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);

    long long br = 7;
    for(int i = 0; i < 26; ++i){
        h[i+'a'] = br;
        br*= 7;
        br%= 8999;
    }

    for(int i = 0; i < 9000; ++i){
        ima[i] = false;
    }

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

        for(int j = 0; j < 26; ++j){
            prosao['a'+j] = false;
        }

        str1 = 1;
        for(int j = 0; j < str.size(); ++j){
            if(!prosao[str[j]]){
                str1*= h[str[j]];
                str1%= 8999;
                prosao[str[j]] = true;
            }
        }

        if(!ima[str1]){
            ++resenje;
            ima[str1] = true;
        }
    }

    cout << resenje << "\n";
    return 0;
}


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

int n;
string str;
long long str1;
map<long long, bool> ima;
map<char, long long> h;
map<char, bool> prosao;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);

    long long br = 7;
    for(int i = 0; i < 26; ++i){
        h[i+'a'] = br;
        br*= br;
        br%= 8999;
    }

    for(int i = 0; i < 9000; ++i){
        ima[i] = false;
    }

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

        for(int j = 0; j < 26; ++j){
            prosao['a'+j] = false;
        }

        str1 = 1;
        for(int j = 0; j < str.size(); ++j){
            if(!prosao[str[j]]){
                str1*= h[str[j]];
                str1%= 8999;
                prosao[str[j]] = true;
            }
        }

        if(!ima[str1]){
            ++resenje;
            ima[str1] = true;
        }
    }

    cout << resenje << "\n";
    return 0;
}


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

int n;
string niz[1005];
long long niz1[1005];
long long h[30];
map<long long, bool> ima;
map<char, bool> prosao;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);

    int br = 7;
    for(int i = 0; i < 26; ++i){
        h[i] = br;
        h[i]%= 8999;
        br*= 7;
    }

    cin >> n;
    for(int i = 0; i < n; ++i){
        cin >> niz[i];

        for(int j = 0; j < 26; ++j){
            prosao[j+'a'] = false;
        }

        for(int j = 0; j < niz[i].size(); ++j){
            if(!prosao[niz[i][j]]){
                niz1[i]+= h[niz[i][j]-'a'];
                prosao[niz[i][j]] = true;
            }
        }
    }

    int resenje = 0;
    for(int i = 0; i < n; ++i){
        if(!ima[niz1[i]]){
            ++resenje;
            ima[niz1[i]] = true;
        }
    }

    cout << resenje << "\n";
    return 0;
}


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

int n;
string a[1010];
bool check[1010][30];

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);

    cin >> n;

    for(int i = 0; i < n; ++i){
        cin >> a[i];

        for(int j = 0; j < a[i].size(); ++j){
            check[i][a[i][j]-'a'] = true;
        }
    }

    for(int i = 0; i < n; ++i){
        a[i] = "";
        for(int j = 0; j < 26; ++j){
            if(check[i][j]){
                a[i]+= '1';
            }
            else{
                a[i]+= '0';
            }
        }
    }

    sort(a, a + n);
    int resenje = 0;
    for(int i = 1; i < n; ++i){
        if(a[i] != a[i-1]){
            ++resenje;
        }
    }
    cout << resenje+1 << "\n";
}


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

int n;
string str;
long long str1;
long long h[30];
map<long long, bool> ima;
map<char, bool> prosao;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);

    int br = 7;
    for(int i = 0; i < 26; ++i){
        h[i] = br;
        br*= 7;
        br%= 8999;
    }

    cin >> n;

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

        for(int j = 0; j < 26; ++j){
            prosao[j+'a'] = false;
        }

        str1 = 1;
        for(int j = 0; j < str.size(); ++j){
            if(!prosao[str[j]]){
                str1*= h[str[j]-'a'];
                str1%= 8999;
                prosao[str[j]] = true;
            }
        }

        if(!ima[str1]){
            ++resenje;
            ima[str1] = true;
        }
    }

    cout << resenje << "\n";
    return 0;
}


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

int n;
string niz[1005];
long long niz1[1005];
long long h[30];
map<long long, bool> ima;
map<char, bool> prosao;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);

    int br = 7;
    for(int i = 0; i < 26; ++i){
        h[i] = br;
        br*= 7;
        br%= 8999;
    }

    cin >> n;

    for(int i = 0; i < n; ++i){
        niz1[i] = 1;
    }

    for(int i = 0; i < n; ++i){
        cin >> niz[i];

        for(int j = 0; j < 26; ++j){
            prosao[j+'a'] = false;
        }

        for(int j = 0; j < niz[i].size(); ++j){
            if(!prosao[niz[i][j]]){
                niz1[i]*= h[niz[i][j]-'a'];
                niz1[i]%= 8999;
                prosao[niz[i][j]] = true;
            }
        }
    }

    int resenje = 0;
    for(int i = 0; i < n; ++i){
        if(!ima[niz1[i]]){
            ++resenje;
            ima[niz1[i]] = true;
        }
    }

    cout << resenje << "\n";
    return 0;
}


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

int n;
string a[1010];
bool check[1010][30];
long long niz[1010];

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);

    cin >> n;

    for(int i = 0; i < n; ++i){
        cin >> a[i];

        for(int j = 0; j < a[i].size(); ++j){
            check[i][a[i][j]-'a'] = true;
        }
    }

    for(int i = 0; i <= n; ++i){
        niz[i] = 0;
    }

    for(int i = 0; i < n; ++i){
        for(int j = 0; j < 26; ++j){
            if(check[i][j]){
                niz[i]+= 1;
            }
            niz[i]*= 10;
            niz[i]%= 8999;
        }
    }

    sort(niz, niz + n);
    int resenje = 0;
    for(int i = 1; i < n; ++i){
        if(niz[i] != niz[i-1]){
            ++resenje;
        }
    }
    cout << resenje+1 << "\n";
}


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

int n;
string a[1010];
bool check[1010][30];
long long niz[1010];

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);

    cin >> n;

    for(int i = 0; i < n; ++i){
        cin >> a[i];

        for(int j = 0; j < a[i].size(); ++j){
            check[i][a[i][j]-'a'] = true;
        }
    }

    for(int i = 0; i <= n; ++i){
        niz[i] = 0;
    }

    for(int i = 0; i < n; ++i){
        for(int j = 0; j < 26; ++j){
            if(check[i][j]){
                niz[i]+= 1;
                niz[i]*= 10;
            }
        }
    }

    sort(niz, niz + n);
    int resenje = 0;
    for(int i = 1; i < n; ++i){
        if(niz[i] != niz[i-1]){
            ++resenje;
        }
    }
    cout << resenje+1 << "\n";
}


#include <bits/stdc++.h>

using namespace std;

int n;
set<string> a;
string tmp, code;
int h[26];
int main() {
    while(cin >> n) {
        while(n --) {
            cin >> tmp;
            for(auto& i: tmp) h[i - 'a'] ++;

            string c;
            for(int i = 0; i < 26; i ++) {
                if(h[i] and i < 10) c += "0" + atoi(i);
                if(h[i] and i >= 10) c += atoi(i);
            }
            a.insert(c);
        }
        cout << a.size() << endl;
    }

    return 0;
}


#include <bits/stdc++.h>

using namespace std;

int n;
set<string> a;
string tmp;

int h[26];

int main() {
    while(cin >> n) {
        while(n --) {
            cin >> tmp;
            for(auto& i: tmp) h[i - 'a'] ++;

            string c;
            for(int i = 0; i < 26; i ++) {
                if(h[i]) c += i + 'a';
                h[i] = 0;
            }
            a.insert(c);
        }
        cout << endl << a.size() << endl;
    }

    return 0;
}


#include <bits/stdc++.h>

using namespace std;

int n;
set<string> a;
string tmp, code;
int h[26];
int main() {
    while(cin >> n) {
        while(n --) {
            cin >> tmp;
            for(auto& i: tmp) h[i - 'a'] ++;

            string c;
            for(int i = 0; i < 26; i ++) {
                if(h[i]) {
                    c += char(i);
                    cout << char(i);
                }
            }
            a.insert(c);
        }
        cout << a.size() << endl;
    }

    return 0;
}


#include <bits/stdc++.h>

using namespace std;

int n;
set<string> a;
string tmp, code;
int h[26];
int main() {
    while(cin >> n) {
        while(n --) {
            cin >> tmp;
            for(auto& i: tmp) h[i - 'a'] ++;

            string c;
            for(int i = 0; i < 26; i ++) {
                if(h[i]) c += char(i);
            }
            a.insert(c);
        }
        cout << a.size() << endl;
    }

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    set<string> dict;
    int n;
    char str[1001];
    cin>>n;
    for(int i=0;i<n;i++)
    {
        set<char> s1;
        cin>>str;
        for(int j=0;j<strlen(str);j++)
        s1.insert(str[j]);
        int ctr=0;
        char str1[s1.size()];
        for(auto it: s1)
        {
        str1[ctr]=it;
        ctr++;
        }
        dict.insert(str1);
    }
    cout<<dict.size();
}


#include<iostream>
#include<string.h>
using namespace std;
int main()
{
    char str1[1002][1002],str2[1002][1002],arr[26];
    int n,ctr2=0;
    cin>>n;
    for(int i=0;i<n;i++)
    cin>>str1[i];
    for(int i=0;i<n;i++)
    {
        for(int j=0;j<26;j++)
        arr[j]=0;
        for(int j=0;j<strlen(str1[i]);j++)
        {
            arr[int(str1[i][j])-int('a')]++;
        }
         int ctr=0;
         char str3[1001];
         for(int j=0;j<26;j++)
         {
             if(arr[j]>=1)
             {
                 str3[ctr]=char(97+j);
                 ctr++;
             }
         }
        if(i==0)
        {
            strcpy(str2[ctr2],str3);
            ctr2++;
        }
        else
        {
            int flag=0;
            for(int j=0;j<ctr2;j++)
            {
                if(!strcmp(str3,str2[j]))
                {
                    flag=1;break;
                }
            }
            if(flag==0)
            {
                strcpy(str2[ctr2],str3);
                ctr2++;
            }
        }
    }
    cout<<ctr2;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    set<string> dict;
    int n;
    char str[1001];
    cin>>n;
    for(int i=0;i<n;i++)
    {
        set<char> s1;
        cin>>str;
        for(int j=0;j<strlen(str);j++)
        s1.insert(str[j]);
        int ctr=0;
        vector<char> str1;
        for(auto it: s1)
        {
        str1.push_back(it);
        }
        dict.insert(str1);
    }
    cout<<dict.size();
}


#include<iostream>
#include<string.h>
using namespace std;
int main()
{
    char str1[1001][1001],str2[1001][1001],arr[26];
    int n,ctr2=0;
    cin>>n;
    for(int i=0;i<n;i++)
    cin>>str1[i];
    for(int i=0;i<n;i++)
    {
        for(int j=0;j<26;j++)
        arr[j]=0;
        for(int j=0;j<strlen(str1[i]);j++)
        {
            arr[int(str1[i][j])-int('a')]++;
        }
         int ctr=0;
         char str3[1001];
         for(int j=0;j<26;j++)
         {
             if(arr[j]>=1)
             {
                 str3[ctr]=char(97+j);
                 ctr++;
             }
         }
        if(i==0)
        {
            strcpy(str2[ctr2],str3);
            ctr2++;
        }
        else
        {
            int flag=0;
            for(int j=0;j<ctr2;j++)
            {
                if(!strcmp(str3,str2[j]))
                {
                    flag=1;break;
                }
            }
            if(flag==0)
            {
                strcpy(str2[ctr2],str3);
                ctr2++;
            }
        }
    }
    cout<<ctr2;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    set<string> dict;
    int n;
    char str[1001];
    cin>>n;
    for(int i=0;i<n;i++)
    {
        set<char> s1;
        cin>>str;
        for(int j=0;j<strlen(str);j++)
        s1.insert(str[j]);
        int ctr=0;
        string str1;
        for(auto it: s1)
        {
        str1.push_back(it);
        }
        dict.insert(str1);
    }
    cout<<dict.size();
}


#include<iostream>
#include<string.h>
using namespace std;
int main()
{
    char str1[1001][1001],str2[1001][1001],arr[26],str3[1001];
    int n,ctr2=0;
    cin>>n;
    for(int i=0;i<n;i++)
    cin>>str1[i];
    for(int i=0;i<n;i++)
    {
        for(int j=0;j<26;j++)
        arr[j]=0;
        for(int j=0;j<strlen(str1[i]);j++)
        {
            arr[int(str1[i][j])-int('a')]++;
        }
         int ctr=0;
         for(int j=0;j<26;j++)
         {
             if(arr[j]>=1)
             {
                 str3[ctr]=char(97+j);
                 ctr++;
             }
         }
        if(i==0)
        {
            strcpy(str2[ctr2],str3);
            ctr2++;
        }
        else
        {
            int flag=0;
            for(int j=0;j<ctr2;j++)
            {
                if(!strcmp(str3,str2[j]))
                {
                    flag=1;break;
                }
            }
            if(flag==0)
            {
                strcpy(str2[ctr2],str3);
                ctr2++;
            }
        }
    }
    cout<<ctr2;
}


// Problem : A. Aramic script
// Contest : Codeforces Round #478 (Div. 2)
// URL : https://codeforces.com/problemset/problem/975/A
// Memory Limit : 256 MB
// Time Limit : 1000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include<bits/stdc++.h>

#define pb push_back
#define fi first
#define se second
#define ios ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define hell1 1000000007
#define hell2 1000000009
#define ms(s, n) memset(s, n, sizeof(s))
#define prec(n) fixed<<setprecision(n)
#define eps 0.000001
#define all(v) v.begin(), v.end()
#define allr(v) v.rbegin(), v.rend()
#define ll long long
#define ld long double
#define no_of_digits(n) floor(log10(n)) + 1
#define see(x) cout << #x << "=" << x << endl;
#define see2(x, y) cout << #x << "=" << x << "\t" << #y << "=" << y << endl;
#define see3(x, y, z) cout << #x << "=" << x << "\t" << #y << "=" << y << "\t" << #z << "=" << z << endl;
#define INF 1e9+5
#define LL_MAX 1e18+5

using namespace std;

const ld PI = acos((ld)-1);

ll modmult(ll a,ll b, ll p=hell1){   return ((a%p)*(b%p))%p; }
ll modmultbig(ll a,ll b,ll mod=hell1){   if(a==0 or b==0) return 0;if(a==1 or b==1) return (a*b)%mod;ll cur=modmultbig(a,b/2,mod);cur=(2*cur)%mod;if(b%2) cur=(cur+a)%mod;return cur;}
ll modadd(ll a, ll b, ll p=hell1){ if(a>=p) a%=p; if(b>=p) b%=p; if(a+b>p) return (a + b)%p; else return a+b;}
ll modsub(ll a, ll b, ll p=hell1){return (a%p - b%p + p)%p;}
ll fpow(ll n, ll k, ll p = hell1) {ll r = 1; for (; k; k >>= 1) {if (k & 1) r = modmult(r,n,p); n = modmult(n,n,p);} return r;}
ll inv(ll a, ll p = hell1) {return fpow(a, p - 2, p);}
ll inv_euclid(ll a, ll m = hell1){ll m0 = m;ll y = 0, x = 1;if (m == 1)return 0;while (a > 1){ll q = a / m;ll t = m;m = a % m, a = t;t = y;y = x - q * y;x = t;}if (x < 0)x += m0;return x;}

int isPowerof2(ll x) { return (x && !(x & (x-1))); }

ll log2(ll x) { ll res = 0; while (x >>= 1) res++; return res; }

bool isPerfectSquare(long double x) {long double sr = sqrt(x); return ((sr - floor(sr)) == 0); }

bool boundary(ll i,ll j,ll n, ll m){return (i>=0 && i<n && j>=0 &&  j<m);} //matrix boundary checking

ll ceil(const ll &a, const ll &b){return (a - 1)/b + 1;}
int lcm(int a, int b){return (a*b)/__gcd(a, b);}

string alpha="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";

int dx[4] = {0, 0, -1, 1};
int dy[4] = {-1, 1, 0, 0};

// cout << fixed for removing e notation

bool comp2(const pair<int, int>&a, const pair<int, int>&b)
{
    if(a.second < b.second)
        return true;
    else if(a.second == b.second)
    {
        if(a.fi > b.fi) return true;
        else return false;
    }
    else return false;
}

bool prime[10000005];
void SieveOfEratosthenes(int n)
{
    memset(prime, true, sizeof(prime));
    prime[0] = prime[1] = 0;
    for (int p=2; p*p<=n; p++)
    {
        if (prime[p] == true)
            for (int i=p*p; i<=n; i += p)
                prime[i] = false;
    }
}

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

	string s[n];
	for(int i=0;i<n;i++)
	{
		cin >> s[i];
		sort(all(s[i]));
	}

	sort(s, s+n);

	// for(auto x: s) cout << x << " ";
	int vis[n] = {0}, ans = 0, ok = 0;

	for(int i=0;i<n;i++)
	{
		ok = 0;
		if(!vis[i])
		{
			set<char>st;
			for(int h=0;h<s[i].size();h++)
			{
				st.insert(s[i][h]);
			}

			for(int j=i+1;j<n;j++)
			{
				set<char>temp;
				for(int h=0;h<s[j].size();h++)
				{
					temp.insert(s[j][h]);
				}

				if(st == temp)
				{
					// for(auto x: st) cout << x << " ";
					// cout << "\n";
//
//
					// for(auto x: temp) cout << x << " ";
					// cout << "\n";

					ok = 1;
					vis[j] = 1;
				}
			}
			ans++;
		}
	}

	cout << ans << "\n";
}


// Problem : A. Aramic script
// Contest : Codeforces Round #478 (Div. 2)
// URL : https://codeforces.com/problemset/problem/975/A
// Memory Limit : 256 MB
// Time Limit : 1000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include<bits/stdc++.h>

#define pb push_back
#define fi first
#define se second
#define ios ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define hell1 1000000007
#define hell2 1000000009
#define ms(s, n) memset(s, n, sizeof(s))
#define prec(n) fixed<<setprecision(n)
#define eps 0.000001
#define all(v) v.begin(), v.end()
#define allr(v) v.rbegin(), v.rend()
#define ll long long
#define ld long double
#define no_of_digits(n) floor(log10(n)) + 1
#define see(x) cout << #x << "=" << x << endl;
#define see2(x, y) cout << #x << "=" << x << "\t" << #y << "=" << y << endl;
#define see3(x, y, z) cout << #x << "=" << x << "\t" << #y << "=" << y << "\t" << #z << "=" << z << endl;
#define INF 1e9+5
#define LL_MAX 1e18+5

using namespace std;

const ld PI = acos((ld)-1);

ll modmult(ll a,ll b, ll p=hell1){   return ((a%p)*(b%p))%p; }
ll modmultbig(ll a,ll b,ll mod=hell1){   if(a==0 or b==0) return 0;if(a==1 or b==1) return (a*b)%mod;ll cur=modmultbig(a,b/2,mod);cur=(2*cur)%mod;if(b%2) cur=(cur+a)%mod;return cur;}
ll modadd(ll a, ll b, ll p=hell1){ if(a>=p) a%=p; if(b>=p) b%=p; if(a+b>p) return (a + b)%p; else return a+b;}
ll modsub(ll a, ll b, ll p=hell1){return (a%p - b%p + p)%p;}
ll fpow(ll n, ll k, ll p = hell1) {ll r = 1; for (; k; k >>= 1) {if (k & 1) r = modmult(r,n,p); n = modmult(n,n,p);} return r;}
ll inv(ll a, ll p = hell1) {return fpow(a, p - 2, p);}
ll inv_euclid(ll a, ll m = hell1){ll m0 = m;ll y = 0, x = 1;if (m == 1)return 0;while (a > 1){ll q = a / m;ll t = m;m = a % m, a = t;t = y;y = x - q * y;x = t;}if (x < 0)x += m0;return x;}

int isPowerof2(ll x) { return (x && !(x & (x-1))); }

ll log2(ll x) { ll res = 0; while (x >>= 1) res++; return res; }

bool isPerfectSquare(long double x) {long double sr = sqrt(x); return ((sr - floor(sr)) == 0); }

bool boundary(ll i,ll j,ll n, ll m){return (i>=0 && i<n && j>=0 &&  j<m);} //matrix boundary checking

ll ceil(const ll &a, const ll &b){return (a - 1)/b + 1;}
int lcm(int a, int b){return (a*b)/__gcd(a, b);}

string alpha="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";

int dx[4] = {0, 0, -1, 1};
int dy[4] = {-1, 1, 0, 0};

// cout << fixed for removing e notation

bool comp2(const pair<int, int>&a, const pair<int, int>&b)
{
    if(a.second < b.second)
        return true;
    else if(a.second == b.second)
    {
        if(a.fi > b.fi) return true;
        else return false;
    }
    else return false;
}

bool prime[10000005];
void SieveOfEratosthenes(int n)
{
    memset(prime, true, sizeof(prime));
    prime[0] = prime[1] = 0;
    for (int p=2; p*p<=n; p++)
    {
        if (prime[p] == true)
            for (int i=p*p; i<=n; i += p)
                prime[i] = false;
    }
}

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

	string s[n];
	for(int i=0;i<n;i++)
		cin >> s[i];

	int cnt[26] = {0};

	sort(s, s+n);
	set<char>st;

	for(int i=0;i<s[0].size();i++)
		st.insert(s[0][i]);

	int ans = 1;
	for(int i=1;i<n;i++)
	{
		set<char>temp;
		for(int j=0;j<s[i].size();j++)
			temp.insert(s[i][j]);

		if(st == temp)
		{
			temp.clear();
		}
		else
		{
			ans++;
			st = temp;
		}
	}

	cout << ans << "\n";
}


// Problem : A. Aramic script
// Contest : Codeforces Round #478 (Div. 2)
// URL : https://codeforces.com/problemset/problem/975/A
// Memory Limit : 256 MB
// Time Limit : 1000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include<bits/stdc++.h>

#define pb push_back
#define fi first
#define se second
#define ios ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define hell1 1000000007
#define hell2 1000000009
#define ms(s, n) memset(s, n, sizeof(s))
#define prec(n) fixed<<setprecision(n)
#define eps 0.000001
#define all(v) v.begin(), v.end()
#define allr(v) v.rbegin(), v.rend()
#define ll long long
#define ld long double
#define no_of_digits(n) floor(log10(n)) + 1
#define see(x) cout << #x << "=" << x << endl;
#define see2(x, y) cout << #x << "=" << x << "\t" << #y << "=" << y << endl;
#define see3(x, y, z) cout << #x << "=" << x << "\t" << #y << "=" << y << "\t" << #z << "=" << z << endl;
#define INF 1e9+5
#define LL_MAX 1e18+5

using namespace std;

const ld PI = acos((ld)-1);

ll modmult(ll a,ll b, ll p=hell1){   return ((a%p)*(b%p))%p; }
ll modmultbig(ll a,ll b,ll mod=hell1){   if(a==0 or b==0) return 0;if(a==1 or b==1) return (a*b)%mod;ll cur=modmultbig(a,b/2,mod);cur=(2*cur)%mod;if(b%2) cur=(cur+a)%mod;return cur;}
ll modadd(ll a, ll b, ll p=hell1){ if(a>=p) a%=p; if(b>=p) b%=p; if(a+b>p) return (a + b)%p; else return a+b;}
ll modsub(ll a, ll b, ll p=hell1){return (a%p - b%p + p)%p;}
ll fpow(ll n, ll k, ll p = hell1) {ll r = 1; for (; k; k >>= 1) {if (k & 1) r = modmult(r,n,p); n = modmult(n,n,p);} return r;}
ll inv(ll a, ll p = hell1) {return fpow(a, p - 2, p);}
ll inv_euclid(ll a, ll m = hell1){ll m0 = m;ll y = 0, x = 1;if (m == 1)return 0;while (a > 1){ll q = a / m;ll t = m;m = a % m, a = t;t = y;y = x - q * y;x = t;}if (x < 0)x += m0;return x;}

int isPowerof2(ll x) { return (x && !(x & (x-1))); }

ll log2(ll x) { ll res = 0; while (x >>= 1) res++; return res; }

bool isPerfectSquare(long double x) {long double sr = sqrt(x); return ((sr - floor(sr)) == 0); }

bool boundary(ll i,ll j,ll n, ll m){return (i>=0 && i<n && j>=0 &&  j<m);} //matrix boundary checking

ll ceil(const ll &a, const ll &b){return (a - 1)/b + 1;}
int lcm(int a, int b){return (a*b)/__gcd(a, b);}

string alpha="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";

int dx[4] = {0, 0, -1, 1};
int dy[4] = {-1, 1, 0, 0};

// cout << fixed for removing e notation

bool comp2(const pair<int, int>&a, const pair<int, int>&b)
{
    if(a.second < b.second)
        return true;
    else if(a.second == b.second)
    {
        if(a.fi > b.fi) return true;
        else return false;
    }
    else return false;
}

bool prime[10000005];
void SieveOfEratosthenes(int n)
{
    memset(prime, true, sizeof(prime));
    prime[0] = prime[1] = 0;
    for (int p=2; p*p<=n; p++)
    {
        if (prime[p] == true)
            for (int i=p*p; i<=n; i += p)
                prime[i] = false;
    }
}

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

	string s[n];
	for(int i=0;i<n;i++)
	{
		cin >> s[i];
		sort(all(s[i]));
	}

	sort(s, s+n);

	set<string>st;

	for(int i=0;i<n;i++)
	{
		s[i].erase(unique(all(s[i])), s[i].end());
		st.insert(s[i]);
	}

	cout << st.size() << "\n";
}


// Problem : A. Aramic script
// Contest : Codeforces Round #478 (Div. 2)
// URL : https://codeforces.com/problemset/problem/975/A
// Memory Limit : 256 MB
// Time Limit : 1000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include<bits/stdc++.h>

#define pb push_back
#define fi first
#define se second
#define ios ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define hell1 1000000007
#define hell2 1000000009
#define ms(s, n) memset(s, n, sizeof(s))
#define prec(n) fixed<<setprecision(n)
#define eps 0.000001
#define all(v) v.begin(), v.end()
#define allr(v) v.rbegin(), v.rend()
#define ll long long
#define ld long double
#define no_of_digits(n) floor(log10(n)) + 1
#define see(x) cout << #x << "=" << x << endl;
#define see2(x, y) cout << #x << "=" << x << "\t" << #y << "=" << y << endl;
#define see3(x, y, z) cout << #x << "=" << x << "\t" << #y << "=" << y << "\t" << #z << "=" << z << endl;
#define INF 1e9+5
#define LL_MAX 1e18+5

using namespace std;

const ld PI = acos((ld)-1);

ll modmult(ll a,ll b, ll p=hell1){   return ((a%p)*(b%p))%p; }
ll modmultbig(ll a,ll b,ll mod=hell1){   if(a==0 or b==0) return 0;if(a==1 or b==1) return (a*b)%mod;ll cur=modmultbig(a,b/2,mod);cur=(2*cur)%mod;if(b%2) cur=(cur+a)%mod;return cur;}
ll modadd(ll a, ll b, ll p=hell1){ if(a>=p) a%=p; if(b>=p) b%=p; if(a+b>p) return (a + b)%p; else return a+b;}
ll modsub(ll a, ll b, ll p=hell1){return (a%p - b%p + p)%p;}
ll fpow(ll n, ll k, ll p = hell1) {ll r = 1; for (; k; k >>= 1) {if (k & 1) r = modmult(r,n,p); n = modmult(n,n,p);} return r;}
ll inv(ll a, ll p = hell1) {return fpow(a, p - 2, p);}
ll inv_euclid(ll a, ll m = hell1){ll m0 = m;ll y = 0, x = 1;if (m == 1)return 0;while (a > 1){ll q = a / m;ll t = m;m = a % m, a = t;t = y;y = x - q * y;x = t;}if (x < 0)x += m0;return x;}

int isPowerof2(ll x) { return (x && !(x & (x-1))); }

ll log2(ll x) { ll res = 0; while (x >>= 1) res++; return res; }

bool isPerfectSquare(long double x) {long double sr = sqrt(x); return ((sr - floor(sr)) == 0); }

bool boundary(ll i,ll j,ll n, ll m){return (i>=0 && i<n && j>=0 &&  j<m);} //matrix boundary checking

ll ceil(const ll &a, const ll &b){return (a - 1)/b + 1;}
int lcm(int a, int b){return (a*b)/__gcd(a, b);}

string alpha="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";

int dx[4] = {0, 0, -1, 1};
int dy[4] = {-1, 1, 0, 0};

// cout << fixed for removing e notation

bool comp2(const pair<int, int>&a, const pair<int, int>&b)
{
    if(a.second < b.second)
        return true;
    else if(a.second == b.second)
    {
        if(a.fi > b.fi) return true;
        else return false;
    }
    else return false;
}

bool prime[10000005];
void SieveOfEratosthenes(int n)
{
    memset(prime, true, sizeof(prime));
    prime[0] = prime[1] = 0;
    for (int p=2; p*p<=n; p++)
    {
        if (prime[p] == true)
            for (int i=p*p; i<=n; i += p)
                prime[i] = false;
    }
}

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

	string s[n];
	for(int i=0;i<n;i++)
		cin >> s[i];

	int cnt[26] = {0};

	sort(s, s+n);
	set<char>st;

	for(int i=0;i<s[0].size();i++)
		st.insert(s[0][i]);

	int ans = 1;
	for(int i=1;i<n;i++)
	{
		set<char>temp;
		for(int j=0;j<s[i].size();j++)
			temp.insert(s[i][j]);

		if(st == temp)
		{
			st = temp;
			temp.clear();
		}
		else
		{
			ans++;
			st = temp;
		}
	}

	cout << ans << "\n";
}


/* If it didn't challenged you, It did'nt changed you

    author    : ayushgupta1997
    Created On: 01/05/2018

*/

#include <cstdio>
#include <tuple>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <vector>
#include <map>
#include <list>
#include <deque>
#include <cassert>
#include <ctime>
#include <cstdlib>
#include <numeric>
#include <functional>
#include <fstream>
#include <set>
#include <queue>
#include <stack>
#include <string>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <bits/stdc++.h>

using namespace std;

#define rep(i, a, b) for(int i = a; i < b; i++)
#define REP(i, a, b) for(int i = a; i <= b; i++)
#define pb push_back
#define fi first
#define se second
#define mp make_pair
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v),rend()
#define MAX 100005

typedef long long int ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef double ld;

//global variables

int arr[1000005];

//Utility functions

void  solve(ll x) {

}

vector<int> v[200005];

int main()  {
   int n;
   cin >> n;
   string s;
   set<int> ms;
   for(int i=0;i<n;i++) {
        cin >> s;
        ll ans = 0;
        rep(i,0,s.size()) {
            int temp = s[i]-'a';
            ans|=(1<<temp);
        }
        ms.insert(ans);
   }
   cout << ms.size();
   return 0;
}


/* If it didn't challenged you, It did'nt changed you

    author    : ayushgupta1997
    Created On: 01/05/2018

*/

#include <cstdio>
#include <tuple>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <vector>
#include <map>
#include <list>
#include <deque>
#include <cassert>
#include <ctime>
#include <cstdlib>
#include <numeric>
#include <functional>
#include <fstream>
#include <set>
#include <queue>
#include <stack>
#include <string>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <bits/stdc++.h>

using namespace std;

#define rep(i, a, b) for(int i = a; i < b; i++)
#define REP(i, a, b) for(int i = a; i <= b; i++)
#define pb push_back
#define fi first
#define se second
#define mp make_pair
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v),rend()
#define MAX 100005

typedef long long int ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef double ld;

//global variables

int arr[1000005];

//Utility functions

void  solve(ll x) {

}

vector<int> v[200005];

int main()  {
   int n,ans=0;
   cin >> n;
   string s;
   set<string> ms;
   for(int i=0;i<n;i++) {
        int cnt[26]={0};
        string temp;
        cin >> s;
        int flag=0;
        rep(i,0,s.length()) {
            cnt[s[i]-97]++;
        }
        rep(i,0,26) {
            if(cnt[i]>0) {
                temp += (char)(i+97);
            }
        }
        ms.insert(temp);
   }
   cout << ms.size();
   return 0;
}


/* If it didn't challenged you, It did'nt changed you

    author    : ayushgupta1997
    Created On: 01/05/2018

*/

#include <cstdio>
#include <tuple>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <vector>
#include <map>
#include <list>
#include <deque>
#include <cassert>
#include <ctime>
#include <cstdlib>
#include <numeric>
#include <functional>
#include <fstream>
#include <set>
#include <queue>
#include <stack>
#include <string>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <bits/stdc++.h>

using namespace std;

#define rep(i, a, b) for(int i = a; i < b; i++)
#define REP(i, a, b) for(int i = a; i <= b; i++)
#define pb push_back
#define fi first
#define se second
#define mp make_pair
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v),rend()
#define MAX 100005

typedef long long int ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef double ld;

//global variables

int arr[1000005];

//Utility functions

void  solve(ll x) {

}

vector<int> v[200005];

int main()  {
   int n,ans=0;
   cin >> n;
   string s;
   set<int> ms;
   for(int i=0;i<n;i++) {
        cin >> s;
        rep(i,0,s.size()) {
            int temp = s[i]-97;
            ans|=(1<<temp);
        }
        ms.insert(ans);
   }
   cout << ms.size();
   return 0;
}


/* If it didn't challenged you, It did'nt changed you

    author    : ayushgupta1997
    Created On: 01/05/2018

*/

#include <cstdio>
#include <tuple>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <vector>
#include <map>
#include <list>
#include <deque>
#include <cassert>
#include <ctime>
#include <cstdlib>
#include <numeric>
#include <functional>
#include <fstream>
#include <set>
#include <queue>
#include <stack>
#include <string>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <bits/stdc++.h>

using namespace std;

#define rep(i, a, b) for(int i = a; i < b; i++)
#define REP(i, a, b) for(int i = a; i <= b; i++)
#define pb push_back
#define fi first
#define se second
#define mp make_pair
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v),rend()
#define MAX 100005

typedef long long int ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef double ld;

//global variables

int arr[1000005];

//Utility functions

void  solve(ll x) {

}

vector<int> v[200005];

int main()  {
   int n;
   cin >> n;
   string s;
   set<string> ms;
   rep(i,0,n) {
        int cnt[26]={0};
        cin >> s;
        int flag=0;
        rep(i,0,s.length()) {
            cnt[s[i]-97]++;
            if(cnt[s[i]-97]>1) {
                flag=1;
                break;
            }
        }
        if(flag==0) {
            sort(s.begin(),s.end());
            ms.insert(s);
        }
   }
   cout << ms.size();
   return 0;
}


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

const int mx = 123456;
void error(){printf("value error\n"); exit(1);}

int ar[mx],ar2[mx];
pair<double, double> pd[1005];
vector< pair<int, int> > vp[mx];
map<char,int>mp;
map<string,int>mp2;
map<string,int>mp3;

int main(){
    int tk,cs=0,n,k;
    string st,sst[1001];

    while(scanf("%d",&n)==1){
           int cnt = 0;
           k =0;
       for(int i = 0; i < n; i++){

        cin>>st;
        string ts;
        sort(st.begin(),st.end());
        mp3[st]++;
        if(mp3[st]>1) continue;
        int sz = st.size();
        int flg = 0;
        string ss ="";
        for(int j = 0; j < sz; j++){
             mp[st[j]]++;
            if(mp[st[j]] == 1) {
                ss += st[j];
            }
        }
        mp.clear();
        mp2[ss]++;
        if(mp2[ss]==1){
            k++;
        }

       }

       mp2.clear();
       mp3.clear();
       cout<<k<<endl;

    }

  return 0;
}


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

const int mx = 123456;
void error(){printf("value error\n"); exit(1);}

int ar[mx],ar2[mx];
pair<double, double> pd[1005];
vector< pair<int, int> > vp[mx];
map<char,int>mp;
map<string,int>mp2;
map<char,int>mp3;

int main(){
    int tk,cs=0,n,k;
    string st,sst[1001];

    while(scanf("%d",&n)==1){
           int cnt = 0;
           k =0;
       for(int i = 0; i < n; i++){

        cin>>st;
        string ts;
        sort(st.begin(),st.end());

        int sz = st.size();
        int flg = 0;
        for(int j = 0; j < sz; j++){
             mp[st[j]]++;
            if(mp[st[j]] > 1) flg = 1;
        }
        if(mp[st[0]] == sz && mp[st[0]]!=1){
            mp3[st[0]]++;
            if(mp3[st[0]]==1)k++;
             mp.clear();
            continue;
        }
        mp.clear();
        if(flg == 0 ){
           mp2[st]++;
           if(mp2[st]==1){
            k++;
           }
        }
       }

       mp2.clear();
       mp3.clear();

       cout<<k<<endl;

    }

  return 0;
}


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

const int mx = 123456;
void error(){printf("value error\n"); exit(1);}

int ar[mx],ar2[mx];
pair<double, double> pd[1005];
vector< pair<int, int> > vp[mx];
map<char,int>mp;
map<string,int>mp2;
map<char,int>mp3;

int main(){
    int tk,cs=0,n,k;
    string st,sst[1001];

    while(scanf("%d",&n)==1){
           int cnt = 0;
           k =0;
       for(int i = 0; i < n; i++){

        cin>>st;
        string ts;
        sort(st.begin(),st.end());

        int sz = st.size();
        int flg = 0;
        for(int j = 0; j < sz; j++){
             mp[st[j]]++;
            if(mp[st[j]] > 1) flg = 1;
        }
        if(mp[st[0]] == sz){
            mp3[st[0]]++;
            if(mp3[st[0]]==1)k++;
             mp.clear();
            continue;
        }
        mp.clear();
        if(flg == 0 ){
           mp2[st]++;
           if(mp2[st]==1){
            k++;
           }
        }
       }

       mp2.clear();
       mp3.clear();

       cout<<k<<endl;

    }

  return 0;
}


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

const int mx = 123456;
void error(){printf("value error\n"); exit(1);}

int ar[mx],ar2[mx];
pair<double, double> pd[1005];
vector< pair<int, int> > vp[mx];
map<char,int>mp;
map<string,int>mp2;

int main(){
    int tk,cs=0,n,k;
    string st,sst[1001];

    while(scanf("%d",&n)==1){
           int cnt = 0;
           k =0;
       for(int i = 0; i < n; i++){

        cin>>st;
        string ts;
        sort(st.begin(),st.end());

        int sz = st.size();
        int flg = 0;
        for(int j = 0; j < sz; j++){
             mp[st[j]]++;
            if(mp[st[j]] > 1) flg = 1;
        }
        mp.clear();
        if(flg == 0 ){
           mp2[st]++;
           if(mp2[st]==1){
            k++;
           }
        }
       }

       mp2.clear();

       cout<<k<<endl;

    }

  return 0;
}


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

const int mx = 123456;
void error(){printf("value error\n"); exit(1);}

int ar[mx],ar2[mx];
pair<double, double> pd[1005];
vector< pair<int, int> > vp[mx];
map<char,int>mp;
map<string,int>mp2;

int main(){
    int tk,cs=0,n,k;
    string st,sst[1001];

    while(scanf("%d",&n)==1){
           int cnt = 0;
           k =0;
       for(int i = 0; i < n; i++){

        cin>>st;
        string ts;
        sort(st.begin(),st.end());

        int sz = st.size();
        int flg = 0;
        for(int j = 0; j < sz; j++){
             mp[st[j]]++;
            if(mp[st[j]] > 1) flg = 1;
        }
        mp.clear();
        if(flg == 0 ){
           mp2[st]++;
           if(mp2[st]==1){
            k++;
            mp2[st]++;
           }
        }
       }
       mp2.clear();

       cout<<k<<endl;

    }

  return 0;
}


#include <string>
#include <string.h>
#include <iostream>
#include <math.h>
#include <algorithm>
using namespace std;

int n,a[1005];

int main(){
    cin >> n;
    for (int i=0;i<n;++i){
        string s; cin >> s;
        bool b[30];
        memset(b,0,sizeof(b));
        for (int j=0;j<s.length();++j) b[s[j]-97]=1;
        for (int j=0;j<25;++j) if (b[j]==1) a[i]+=pow(2,j);
    }

    int res=0;
    for (int i=0; i<n; i++)
    {
        bool check=0;
        for (int j=0; j<i; ++j)
            if (a[i]==a[j]){
                check=true;
                break;
            }
        if (!check) res++;
    }
    cout << res;
    return 0;
}


#include <string>
#include <string.h>
#include <iostream>
#include <math.h>
#include <algorithm>
using namespace std;

int n,a[1005];

int main(){
    cin >> n;
    for (int i=0;i<n;++i){
        string s; cin >> s;
        bool b[30];
        memset(b,0,sizeof(b));
        for (int j=0;j<s.length();++j) b[s[j]-97]=1;
        for (int j=0;j<25;++j) if (b[j]==1) a[i]+=pow(2,j);
    }

    sort(a,a+n);
    int cur=a[0];
    int res=1;
    for (int i=0;i<n;++i){
        if (a[i]!=cur){
            cur=a[i];
            res++;
        }
    }
    cout << res;
    return 0;
}


#include <string>
#include <string.h>
#include <iostream>
#include <math.h>
#include <algorithm>
using namespace std;

int n,a[1005];

int main(){
    cin >> n;
    for (int i=0;i<n;++i){
        string s; cin >> s;
        bool b[30];
        memset(b,0,sizeof(b));
        for (int j=0;j<s.length();++j) b[s[j]-97]=1;
        for (int j=0;j<=25;++j) if (b[j]==1) a[i]+=pow(2,j);
    }

    int res=0;
    for (int i=0; i<n; i++)
    {
        bool check=0;
        for (int j=0; j<i; ++j)
            if (a[i]==a[j]){
                check=true;
                break;
            }
        if (!check) res++;
    }
    cout << res;
    return 0;
}