import itertools
import sys

def read_sequences(infile=sys.stdin):
    """Reads any file-like object (sys.stdin by default) as a sequence of
    non-empty sequences of non-empty lines, where sequences are separated by
    any number of empty lines."""
    seq = []
    for line in itertools.chain(infile, ['']):
        line = line.rstrip()
        if line:
            seq.append(line)
        else:
            yield seq
            seq = []

def write_sequence(sequence, outfile=sys.stdout):
    """If sequence is non-empty, writes it to the output file (sys.stdout by
    default) with one element per line, followed by an empty line."""
    for line in sequence:
        outfile.write(line)
        outfile.write('\n')
    outfile.write('\n')
