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

#CT0000069. Đại diện đầu tiên theo độ dài (First Representative for Each Word Length)

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

Đại diện đầu tiên theo độ dài (First Representative for Each Word Length)

First Representative for Each Word Length

Problem Statement

A word is a nonempty consecutive sequence of English letters (A–Z, a–z) or digits (0–9). Words are separated by one or more ASCII spaces. Leading/trailing spaces do not create empty words.

Number the words of SS from 11 in order of appearance. For each word length xx occurring in the input, determine the first word of length xx, its position in the word sequence, and the total number of length-xx words.

Preserve the representative's original capitalization and digits.

Input

  • One line contains a string SS with at least one word. It may have leading or trailing spaces.

Output

  • Print dd, the number of distinct lengths.
  • For each length in increasing order, print xx, ww, pp, yy: the length, its first representative word, the representative's 1-based position, and the total number of words of that length.

Subtasks

  • The string contains only English letters, digits and ASCII spaces.

  • Subtask 1 (25%): ∣S∣≤103|S| \le 10^3; exactly one separating space, with no leading/trailing spaces.

  • Subtask 2 (35%): ∣S∣≤105|S| \le 10^5; repeated spaces allowed; each word is at most 100100 characters long.

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

Examples

Example 1

Input

Ky thi HSG THCS 2026 thi

Output

3
2 Ky 1 1
3 thi 2 3
4 THCS 4 2

Explanation

The six words are Ky (length 22), thi (33), HSG (33), THCS (44), 2026 (44), and thi (33). The first representative for length 22 is Ky at position 11 (frequency 11); for length 33, thi at position 22 (frequency 33); and for length 44, THCS at position 44 (frequency 22). Print these three groups by increasing length.

Example 2

Input

aa b cccc dd e

Output

3
1 b 2 2
2 aa 1 2
4 cccc 3 1

Explanation

The word lengths are 2,1,4,2,12,1,4,2,1. For length 11, the first word is b at position 22 and the frequency is 22. For length 22, use aa at position 11 and frequency 22. For length 44, use cccc at position 33 and frequency 11. Print the groups in length order 1,2,41,2,4.

Example 3

Input

x    yy       zzzzz   y

Output

3
1 x 1 2
2 yy 2 1
5 zzzzz 3 1

Explanation

Ignoring repeated spaces gives the word sequence x, yy, zzzzz, y, with lengths 1,2,5,11,2,5,1. Length 11 occurs twice, and its first representative is x at position 11. Lengths 22 and 55 each occur once, with representatives yy and zzzzz.