아직 만들고 있는 페이지입니다.

이 페이지는 아직 만드는 중입니다. 보이는 내용은 바뀔 수 있습니다.

Three Dice

시간 제한5초메모리 제한1024 MB

요약
주어진 세 글자 단어를 모두 만들 수 있도록 18개의 서로 다른 알파벳을 세 개의 육면체 주사위에 배치하는 문제이다.
난이도

보통10점 중 6점

유형
그리디, 백트래킹, 구현
정답자
아직 제출이 없습니다

문제

Given a list of three-letter words, generate one possible set of three, six-sided dice such that each word can be formed by the top faces of some arrangement of the three dice. You must distribute 18 distinct letters across the 18 total faces of the dice. There may be multiple possible sets of dice that satisfy the requirement; any correct set will be accepted.

입력

The first line of input contains an integer nn (1≤n≤1,000)(1\le n\le 1\\,000), which is the number of words.

Each of the next nn lines contains one three-letter word made up only of lowercase letters (a--z). There may be duplicate words in the list, and the words might contain identical letters.

출력

Output a single line. If there exists a set of dice that can form all of the words, output any such set. Output the set of dice as one line with three space-separated strings, each consisting of six lowercase letters. If no such set of dice can be formed, output a single line with the number 0.

예제3

  1. 예제 1

    입력
    3
    lad
    fin
    sly
    
    예상 출력
    zounds plight fakery
    
  2. 예제 2

    입력
    1
    dad
    
    예상 출력
    0
    
  3. 예제 3

    입력
    11
    aft
    cog
    far
    irk
    kit
    yes
    tau
    rag
    own
    uke
    via
    
    예상 출력
    vortex whacky fusing