This page is still under construction.

Parts of this page are still being built. What you see may change.

Processor

Time limit2sMemory limit256 MB

Summary
Pair 2n instruction strings onto n dual-core processors so each pair's execution time (via longest common subsequence) is minimized in total.
Level

Medium7 of 10

Topics
Dynamic programming, Combinatorics, Greedy, Bit manipulation
Solved
No attempts yet

Problem

Most processors manufactured today are multi-core, meaning they can execute several instructions at once. The company Paraltel has developed a new type of dual-core processor that can execute 26 different instructions, denoted by uppercase Latin letters. Executing each such instruction takes exactly one clock cycle of the processor.

A program for this processor is a sequence of instructions. The instructions of a program must be executed in the order they appear in the program; swapping instructions is not allowed.

Thanks to having two cores, the processor can execute two programs at the same time, one on each core. However, because of the architecture, two cores of the same processor can execute only identical instructions at the same time.

When running two programs on the processor, a special control unit optimizes execution so that both programs finish as early as possible. For example, the programs "ABB" and "ABC" can be executed on the processor in 4 cycles: first the "A" instructions of both programs are executed simultaneously on different cores, then the "B" instructions simultaneously, then the "B" of the first program, and finally the "C" of the second. Similarly, the programs "CAB" and "BAB" are executed in 4 cycles.

Recently the company's engineers assembled a supercomputer from n processors, on which 2n programs must be executed. The computation is organized so that each processor must execute exactly two programs from this set, one on each core.

You need to schedule the execution of the 2n programs on the n processors so that the time at which all programs finish is minimized.

Input

The first line contains the number n (1 ≤ n ≤ 10), the number of processors. The next 2n lines contain the programs that must be executed. Each program contains from 1 to 100 commands. Each command is given by an uppercase Latin letter.

Output

Print a single number, the minimum time in which all programs can be executed.

Examples1

  1. Example 1

    Input
    2
    ABB
    BAB
    CAB
    ABC
    
    Expected output
    4