String Factory

Welcome to the string factory where strings are generated in a peculiar manner. You are given a string S consisting of lowercase English alphabets. You can generate another string from the given string using the following algorithm:


This is a companion discussion topic for the original entry at https://toph.co/p/string-factory