RLE - Run length encoding

no tags 

Ram had to send large amount of data to his friend Vishnu. Since he was concerned about the time and the amount of data transfer it will take, he wanted to compress the data before he sent it. So he turns to you for help.

You need to perform run length encoding on a given string. The encoding is as follows : 'consecutive character count' followed by '!' followed by the 'character'. Do not encode the characters unless they lead to compression !

Input

Input consists of multiple lines of strings s, one string per line,  with |s| <= 100000 (read the input till EOF)

Output

For each input string, output a single line printing the run length encoding of the input string

Example

Input:
aabbbbbccccc
aaaabbbbbbbbbbbbbbbccccc Output: aa5!b5!c
4!a15!b5!c

hide comments
ck_17: 2020-05-23 11:58:51

it can contain any character excluding space.

urimaj: 2019-07-28 08:50:54

Do not perform encoding when size <= 3.

Input:
a
aa
aaa
aaaa
aaaaa

Output:
a
aa
aaa
4!a
5!a

shyamala1307: 2018-04-04 07:51:58

Do not encode the characters unless they lead to compression ! - How to decide till which character length, we can avoid encoding

nadstratosfer: 2017-09-06 17:43:13

Don't strip presumable newlines like you'd normally need to dealing with string input problems on SPOJ with Python.

Good problem, took me back to the 90s =)

prakash: 2017-01-04 19:20:10

Ac in 1go

sly_cooper: 2017-01-02 23:04:57

AC in one go :) My 100th ! :D

aryanagal: 2016-07-12 14:45:11

Solved in 0.10 from 0.15 in java, but my rank remains unupdated

vineetpratik: 2016-06-22 17:25:06

used cin.eof() kept on getting WA! used scanf()!=EOF got AC!!! but why?

suraj: 2016-06-17 13:55:03

first time use stringstream

Piyush Kumar: 2016-06-10 05:18:33

Got it! Doesn't contain spaces!


Added by:Pandian
Date:2013-12-14
Time limit:1s-2s
Source limit:50000B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Languages:All
Resource:Own