PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#BS0000258. Quảng cáo trên tạp chí (Magazine Ad)

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

1 lộ trình

Quảng cáo trên tạp chí (Magazine Ad)

Magazine Ad

Source: Codeforces

Version: Phuoc Hung OJ Extended

Problem Statement

An advertisement string ss must fit in at most kk nonempty lines. Preserve every character in order. A line break is allowed only after a space or hyphen, which remains on the previous line and counts toward its length. Minimize the longest line length.

Input

The first line contains integer kk, the line limit. The second contains the complete string ss of uppercase/lowercase Latin letters, spaces and hyphens. Let n=∣s∣n=|s|.

Output

Print the minimum width.

Subtasks

  • Subtask 1 (20 points): 1≤k≤81\le k\le 8; 1≤n≤161\le n\le 16; the string contains only uppercase/lowercase Latin letters, spaces and hyphens; every separator lies between two letters.
  • Subtask 2 (30 points): 1≤k≤1051\le k\le 10^5; 1≤n≤1061\le n\le 10^6; the string contains only uppercase/lowercase Latin letters, spaces and hyphens; every separator lies between two letters. No hyphens; all words have equal length.
  • Subtask 3 (50 points): 1≤k≤1051\le k\le 10^5; 1≤n≤1061\le n\le 10^6; the string contains only uppercase/lowercase Latin letters, spaces and hyphens; every separator lies between two letters.

Examples

Input

4
garage for sa-le

Output

7

Explanation

Use four lines garage , for , sa-, le, of lengths 7, 4, 3, 2. Trailing spaces count. The initial segment cannot be split before its space, so 7 is minimal.