Colorful Intervals | 프로그래밍의 벗 PivotOJ
PivotOJ

Colorful Intervals

시간 제한: 1000ms메모리 제한: 2048MB출처: ICPC Asia Tehran Regional Contest 2023BOJ 33190

문제

The Museum of Contemporary Art is holding a painting gallery focused on modern art, especially Monochromatic style paintings, which use only a single color. The gallery displays nn paintings arranged in a line.

The ICPC wants to bring students on an excursion to the gallery to spark their interest in art. However, the students are programmers, and everyone knows programmers only care about the colors of these modern paintings. They are also somewhat impatient. To keep their attention and to ensure they see every color without overwhelming them, the organizer decided to show them exactly two intervals of painting. This approach balances their short attention span and ensures all colors are represented. The task is to find two intervals of paintings such that each color appears at least once in at least one of the intervals, and the total number of paintings the students need to see is minimized.

입력

The input consists of a single line containing a non-negative integer nn (2n20002 \le n \le 2000), indicating the number of paintings. This is followed by nn lines, each containing a string representing the color of a painting. Each color is represented by a non-empty lowercase string with a length of less than 2020. It is guaranteed that there are at least 22 and at most 5050 different colors in the input.

출력

In the output, print the minimum number of paintings the ICPC students need to see, which is the sum of the lengths of the two intervals.

예제

예제 1

입력
5
blue
red
blue
black
red
출력
3

예제 2

입력
8
peachfuzz
livingcoral
livingcoral
teal
teal
livingcoral
livingcoral
coral
출력
5
코드를 제출하려면 로그인하세요.