output total first so it doesn't get truncated
limit input numbers to four digits at most

Four digits should be enough. I don't want to have to deal with
overflows or anything.