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

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

First Last

시간 제한1초메모리 제한2048 MB

요약
서로 다른 단어들이 주어질 때, 최적의 플레이로 진행되는 단어 연결 게임에서 앨리스가 이기게 하는 시작 단어의 수를 센다.
난이도

보통10점 중 7점

유형
게임 이론, 그래프, 비트 연산, 동적 계획법
정답자
아직 제출이 없습니다

문제

Alice and Bob are playing a word game. They start with a list of words, and they alternate turns. Alice goes first; she chooses a starting word from the list. On each subsequent turn, the current player must choose a word from the list that starts with the same letter that ends the word chosen by the other player in the previous turn. No word can be used more than once. At some point one of them will not be able to choose a word; that player loses.

Assume Alice and Bob both play optimally. How many words from the list, when chosen as the first word by Alice, lead to a win for her?

입력

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

Each of the next nn lines contains a single word consisting only of the lower-case letters 'a' through 'z'. Each word will be from two to fifteen letters long. All words will be distinct. There will be at most three distinct letters at the beginning and end of all words. Alice and Bob may only choose words from this list.

출력

Output a single integer, which is the number of words from the list which force a win for Alice if she chooses it first, and both Alice and Bob play optimally.

예제2

  1. 예제 1

    입력
    3
    attic
    climb
    alpha
    
    예상 출력
    2
    
  2. 예제 2

    입력
    22
    agora
    alpha
    antic
    aorta
    apnea
    arena
    aroma
    attic
    basic
    blurb
    china
    circa
    civic
    climb
    cobra
    cocoa
    comic
    comma
    conic
    crumb
    cubic
    cynic
    
    예상 출력
    6