#include <stdio.h>
	#include <stdlib.h>
	#include <string.h>
	#include <stdbool.h>

	#define MARKUP_LEN      7

	void place_char(char *string, char toPlace, int index, bool reg) {
		switch (reg) {
			case true:
				string[index] = toPlace;
				break;
			case false:
				string[index] = '[';
				string[index + 1] = toPlace;
				string[index + 2] = ']';
				break;
			default:
				fprintf(stderr, "error\n");
		}
	}

	int main(void) {
		char buffer[1025];
		while (fgets(buffer, 1025, stdin) != NULL) {
			if (buffer[strlen(buffer) - 1] == '\n') {
				buffer[strlen(buffer) - 1] = '\0';
			}
			size_t orig_str_len = strlen(buffer);
			char *new_string = calloc(orig_str_len * 4 + 1, sizeof(char));
			short markup = 1;
			int i = 0;
			unsigned int index;
			for (index = 0; index < orig_str_len; index++) {
				if (buffer[index] != ' ') { 
					place_char(new_string, '0' + markup, i, false);
					i += 3;
				} else {
                                    markup--;
                            }
				place_char(new_string, buffer[index], i, true);
				i += 1;
				markup++;
				if (markup > MARKUP_LEN)
					markup = 1;
			}
			printf("\tOriginal: %s\n\tRainbow: %s\n", buffer, new_string);
			free(new_string);
		}
		return EXIT_SUCCESS;
	}