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

#CT0000067. Tần suất độ dài theo ngưỡng (Word Length Frequencies Above a Threshold)

Bài tập này chưa được xếp vào lộ trình.

Tần suất độ dài theo ngưỡng (Word Length Frequencies Above a Threshold)

Word Length Frequencies Above a Threshold

Problem Statement

A word is a nonempty consecutive sequence of English letters (A–Z, a–z) or digits (0–9). Exactly one ASCII space separates consecutive words. There are no leading or trailing spaces.

You are given a positive integer KK and a string SS. For each word length xx, let f(x)f(x) be the number of words in SS whose length is exactly xx.

Output every length xx satisfying f(x)≥Kf(x) \ge K, together with f(x)f(x), sorted by increasing xx.

Input

  • The first line contains a positive integer KK.
  • The second line contains a string SS with at least one word.

Output

  • Print dd, the number of distinct lengths meeting the threshold.
  • On the next dd lines, print xx and f(x)f(x) in increasing order of xx. If d=0d=0, print no further lines.

Subtasks

  • The string contains only English letters, digits and ASCII spaces; 1≤K≤1061 \le K \le 10^6.

  • Subtask 1 (30%): ∣S∣≤103|S| \le 10^3 and K=1K=1.

  • Subtask 2 (30%): ∣S∣≤105|S| \le 10^5.

  • Subtask 3 (40%): ∣S∣≤106|S| \le 10^6.

Examples

Example 1

Input

2
Ky thi HSG THCS 2026

Output

2
3 2
4 2

Explanation

The five words have lengths 2,3,3,4,42,3,3,4,4, so f(2)=1f(2)=1, f(3)=2f(3)=2, and f(4)=2f(4)=2. With K=2K=2, exactly two lengths qualify: 33 and 44. Print 2, followed by 3 2 and 4 2 in increasing length order.

Example 2

Input

3
a bb cc dd e f

Output

2
1 3
2 3

Explanation

The lengths of a, bb, cc, dd, e, and f are 1,2,2,2,1,11,2,2,2,1,1. Hence f(1)=3f(1)=3 and f(2)=3f(2)=3. Both meet K=3K=3, so print the number of qualifying lengths, 2, then 1 3 and 2 3.

Example 3

Input

4
aa b ccc dd

Output

0

Explanation

The words have lengths 2,1,3,22,1,3,2. Length 22 occurs twice; all others occur once. No length occurs at least 44 times, so the only output is 0.