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 3 cba bcd cbc
Output
abcd
Input
5 5 fcofd ooedo afaoa rdcdf eofsf
Output
codeforces
解析:让我们从上到下,从左到右,输出当前行和列只出现一次的字母,数据比较小,我们可以直接每个字母暴力判断,我们遍历每个位置,然后判断该位置的同一行同一列是否出现与其相同的字母,如果没出现,输出即可。
#includechar a[105][105]; int main() { int n,m,i,s,x,shi; //shi用来标记同一行列是否出现相同字母 while(~scanf("%d%d",&n,&m)){ getchar(); //吃掉空格 for(i=1;i<=n;i++){ for(s=1;s<=m;s++) scanf("%c",&a[i][s]); //输入字母 getchar(); //吃掉空格 } for(i=1;i<=n;i++){ //先判断同一行 for(s=1;s<=m;s++){ shi=0; //判断是否出现相同字母 for(x=1;x<=m;x++){ if(x!=s&&a[i][x]==a[i][s]){ //x!=s表示跳过本身位置,如果出现了相同字母 shi=1; //标志为1 break; //退出 } } if(shi==0){ //如果同一行没出现过相同字母,判断同一列 for(x=1;x<=n;x++){ if(x!=i&&a[x][s]==a[i][s]){ //与上同理 shi=1; break; } } } if(shi==0) printf("%c",a[i][s]); //如果行列都没出现,就满足,输出 } } printf("n"); } return 0; }



