E - Run Length Encoding Editorial /

Time Limit: 2 sec / Memory Limit: 1024 MiB

問題文

与えられた文字列を、同じ文字が連続する区間に分割して、文字と連続する長さの組からなる列で表現することを 連長圧縮 と呼びます。
例えば S = AAABCCCC を連長圧縮すると (\mathrm{A}, 3), (\mathrm{B}, 1), (\mathrm{C}, 4) になります。

英大文字からなる文字列 S が与えられます。S を連長圧縮した列を出力形式に従って出力してください。

制約

  • S は英大文字からなる長さ 1 以上 2 \times 10^5 以下の文字列

入力

入力は以下の形式で標準入力から与えられる。

S

出力

S を連長圧縮した列を (c_1, l_1), (c_2, l_2), \dots, (c_k, l_k) とする。このとき、以下の形式で答えを出力せよ。

c_1 l_1 c_2 l_2 \dots c_k l_k

入力例 1

ABBCCC

出力例 1

A 1 B 2 C 3

S = ABBCCC を連長圧縮すると (\mathrm{A}, 1), (\mathrm{B}, 2), (\mathrm{C}, 3) になります。


入力例 2

AAAAAAAAAAAAA

出力例 2

A 13

入力例 3

ABCDE

出力例 3

A 1 B 1 C 1 D 1 E 1

Problem Statement

Applying the run-length encoding to a string is achieved by splitting the string into chunks, each consisting of the same character, and representing them as a sequence of pairs of the characters and the lengths.
For example, applying the run-length encoding to S = AAABCCCC yields (\mathrm{A}, 3), (\mathrm{B}, 1), (\mathrm{C}, 4).

Given a string S consisting of uppercase English letters, apply the run-length encoding to S and print the resulting sequence in the specified format.

Constraints

  • S is a string of length between 1 and 2 \times 10^5 (inclusive) consisting of uppercase English letters.

Input

The input is given from Standard Input in the following format:

S

Output

Let (c_1, l_1), (c_2, l_2), \dots, (c_k, l_k) be the sequence obtained by applying the run-length encoding to S. Print it in the following format.

c_1 l_1 c_2 l_2 \dots c_k l_k

Sample Input 1

ABBCCC

Sample Output 1

A 1 B 2 C 3

Applying the run-length encoding to S = ABBCCC yields (\mathrm{A}, 1), (\mathrm{B}, 2), (\mathrm{C}, 3).


Sample Input 2

AAAAAAAAAAAAA

Sample Output 2

A 13

Sample Input 3

ABCDE

Sample Output 3

A 1 B 1 C 1 D 1 E 1