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

#GD0000091. Chia nhãn (Partition Labels)

HỌC THEO LỘ TRÌNH

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

1 lộ trình

Chia nhãn (Partition Labels)

Partition Labels

Source: LeetCode

Version: Phuoc Hung OJ Extended

Problem Statement

Given a lowercase string ss, partition it into the maximum number of nonempty contiguous blocks so each distinct letter appears in at most one block. Every position belongs to exactly one block and the original order must be preserved. Output the block lengths from left to right.

Input

The only input line contains the lowercase string ss.

Output

Print the number kk of blocks on the first line, followed by their kk positive lengths in order on the second line.

Subtasks

  • Subtask 1 (20 points): 1≤∣s∣≤201\le |s|\le 20; every character is a lowercase letter a–z.
  • Subtask 2 (30 points): 1≤∣s∣≤2001\le |s|\le200; every character is a lowercase letter a–z.
  • Subtask 3 (50 points): 1≤∣s∣≤5001\le |s|\le500; every character is a lowercase letter a–z.

Examples

Input

abacdeed

Output

3
3 1 4

Explanation

The letter a spans positions 11 and 33, producing block aba of length 33. Letter c forms its own block of length 11, and the remaining deed forms a block of length 44. Thus the lengths are 3,1,43,1,4.