Under construction

Still being built. Things may change

Block Game

Time limit2sMemory limit512 MB

Summary
For each letter, find the minimum number of blocks needed so any choice of one word per board can be spelled at once.
Level

Medium5 of 10

Topics
Brute force, Bit manipulation
Solved
No attempts yet

Problem

Farmer John wants to teach his cows to read, so he prepares NN spelling boards of the kind used with preschoolers (1≤N≤1001 \le N \le 100). Each board has one word and one picture on each of its two sides. One side might show the word 'cat' with a picture of a cat, and the other side the word 'dog' with a picture of a dog. When the NN boards lie on the ground, NN words face upward. Flipping some of the boards exposes a different set of NN words.

To help the cows spell, Farmer John wants to carve wooden blocks, each embossed with a single letter of the alphabet. He wants enough blocks of every letter that, whichever set of NN words faces upward, the cows can lay out all NN of those words at once. For example, if N=3N=3 and the upward words are 'box', 'cat', and 'car', the cows need one 'b' block, one 'o' block, one 'x' block, two 'c' blocks, two 'a' blocks, one 't' block, and one 'r' block.

For each of the 26 letters, find the minimum number of blocks Farmer John has to provide so that the cows can spell every visible word no matter which side each board shows.

Input

The first line contains the integer NN.

Each of the next NN lines contains two words separated by a space, the two words written on the opposite sides of one board. Each word is a string of at most 10 lowercase letters.

Output

Print 26 lines. The first line holds the number of 'a' blocks needed, the second line the number of 'b' blocks needed, and so on through 'z'.

Hint

With 3 boards there are 23=82^3 = 8 possible sets of upward words. For boards whose sides are (fox, box), (dog, cat), and (car, bus), the eight sets are:

  • fox dog car
  • fox dog bus
  • fox cat car
  • fox cat bus
  • box dog car
  • box dog bus
  • box cat car
  • box cat bus

The blocks have to be enough to spell all three words in every one of the eight cases.

Examples2

  1. Example 1

    Input
    3
    fox box
    dog cat
    car bus
    
    Expected output
    2
    2
    2
    1
    0
    1
    1
    0
    0
    0
    0
    0
    0
    0
    2
    0
    0
    1
    1
    1
    1
    0
    0
    1
    0
    0
    
  2. Example 2

    Input
    1
    a b
    
    Expected output
    1
    1
    0
    0
    0
    0
    0
    0
    0
    0
    0
    0
    0
    0
    0
    0
    0
    0
    0
    0
    0
    0
    0
    0
    0
    0