CF903E.Swapping Characters

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

We had a string ss consisting of nn lowercase Latin letters. We made kk copies of this string, thus obtaining kk identical strings s1,s2,...,sks_{1},s_{2},...,s_{k} . After that, in each of these strings we swapped exactly two characters (the characters we swapped could be identical, but they had different indices in the string).

You are given kk strings s1,s2,...,sks_{1},s_{2},...,s_{k} , and you have to restore any string ss so that it is possible to obtain these strings by performing aforementioned operations. Note that the total length of the strings you are given doesn't exceed 5000 (that is, kn<=5000k·n<=5000 ).

输入格式

The first line contains two integers kk and nn ( 1<=k<=2500,2<=n<=5000,k  n<=50001<=k<=2500,2<=n<=5000,k · n<=5000 ) — the number of strings we obtained, and the length of each of these strings.

Next kk lines contain the strings s1,s2,...,sks_{1},s_{2},...,s_{k} , each consisting of exactly nn lowercase Latin letters.

输出格式

Print any suitable string ss , or -1 if such string doesn't exist.

输入输出样例

  • 输入#1

    3 4
    abac
    caab
    acba
    

    输出#1

    acab
    
  • 输入#2

    3 4
    kbbu
    kbub
    ubkb
    

    输出#2

    kbub
    
  • 输入#3

    5 4
    abcd
    dcba
    acbd
    dbca
    zzzz
    

    输出#3

    -1
    

说明/提示

In the first example s1s_{1} is obtained by swapping the second and the fourth character in acab, s2s_{2} is obtained by swapping the first and the second character, and to get s3s_{3} , we swap the third and the fourth character.

In the second example s1s_{1} is obtained by swapping the third and the fourth character in kbub, s2s_{2} — by swapping the second and the fourth, and s3s_{3} — by swapping the first and the third.

In the third example it's impossible to obtain given strings by aforementioned operations.

首页