沐枫NOI 30. African Crossword

来源:互联网 发布:小猪o2o源码下载 编辑:程序博客网 时间:2024/06/08 15:43

An African crossword is a rectangular table n×m in size. Each cell of the table contains exactly one letter. This table (it is also referred to as grid) contains some encrypted word that needs to be decoded.

To solve the crossword you should cross out all repeated letters in rows and columns. In other words, a letter should only be crossed out if and only if the corresponding column or row contains at least one more letter that is exactly the same. Besides, all such letters are crossed out simultaneously.

When all repeated letters have been crossed out, we should write the remaining letters in a string. The letters that occupy a higher position follow before the letters that occupy a lower position. If the letters are located in one row, then the letter to the left goes first. The resulting word is the answer to the problem.

You are suggested to solve an African crossword and print the word encrypted there.

Input

The first line contains two integers n and m (1≤n,m≤100). Next n lines contain m lowercase Latin letters each. That is the crossword grid.

Output

Print the encrypted word on a single line. It is guaranteed that the answer consists of at least one letter.

Examples

Input

3 3cbabcdcbc

Output

abcd

Input

5 5fcofdooedoafaoardcdfeofsf

Output

codeforces

#include<iostream>  #include<cstdio>  #include<cstring>  #include<cmath>  #include<algorithm>  #include<queue>  #include<stack>  using namespace std;  char ma[105][105];  int v[105][105];  int n,m;  int check(int x,int y)  {      int flag=0;      for(int i=0;i<n;i++)          if(i!=x&&ma[x][y]==ma[i][y]) v[i][y]=1,flag=1;      for(int i=0;i<m;i++)          if(i!=y&&ma[x][y]==ma[x][i]) v[x][i]=1,flag=1;      return flag;  }    int main(){scanf("%d%d",&n,&m);        for(int i=0;i<n;i++)          scanf("%s",ma[i]);      for(int i=0;i<n;i++)  {          for(int j=0;j<m;j++)  {              int ans=check(i,j);              if(ans) v[i][j]=1;          }      }      for(int i=0;i<n;i++)  {          for(int j=0;j<m;j++)              if(!v[i][j]) printf("%c",ma[i][j]);      }      return 0;  } 


原创粉丝点击