# CMSC 471 - Fall 2008
# Author: Don Miner
# Last updated: 11/3/08

# Tetris Problem Generator

# You may report bugs to this checking script by emailing the instructor.
# Any bug reports that result in a change to this script will yield a small amount of extra credit.
# Bugs include logic errors, invalid output or causing the program to exit ungracefully (e.g.,
# unhandled exception).

# Note that my code is horrible here. It is inefficient and doesn't adhere to good coding standards.
# Therefore, you should probably try to figure out how to work the tetris game mechanics in your
# own program your own way, instead of using this as an example.

# sample run: python tetris_gen.py


import random
import itertools

print "For each piece, specify the number you want"
P = ['I', 'J', 'L', 'O', 'S', 'Z', 'T']
N = [ int(raw_input(p + ": ")) for p in P]

out = list(itertools.chain(*([ [p]*n for p, n in zip(P, N) ])))

random.shuffle(out)

print sum(N)
print "".join(out)