#!/usr/bin/env python

from __future__ import print_function

import argparse
import errno
import sys

def _lines(stream):
    l = stream.readline()
    while l != "":
        yield l
        l = stream.readline()


def main(argv):
    parser = argparse.ArgumentParser(
        description="Moving average of columns"
    )

    parser.add_argument(
        "-a", "--alpha",
        type=float,
        default=0.9,
        help="The exponential moving average factor"
    )
    parser.add_argument(
        "-d", "--delimiter",
        default=" ",
        help="The field delimiter"
    )

    args = parser.parse_args(argv)

    avgs = {}
    try:
        for l in _lines(sys.stdin):
            try:
                fields = map(float, l.split(args.delimiter))
                for i, f in enumerate(fields):
                    avgs[i] = args.alpha*avgs.get(i, f) + (1.0-args.alpha)*f
                print(args.delimiter.join([
                    str(avgs[i]) for i in range(len(avgs))
                ]))
            except:
                sys.stdout.write(l)
            sys.stdout.flush()
    except IOError as e:
        if e.errno != errno.EPIPE:
            raise


if __name__ == "__main__":
    main(sys.argv[1:])
