This page is still under construction.

Parts of this page are still being built. What you see may change.

Ragged Right

Time limit2sMemory limit256 MB

Summary
Given the lines of a paragraph, find the longest line length and print the sum of squared differences for every line except the last.
Level

Easy1 of 10

Topics
Implementation
Solved
No attempts yet

Problem

Word wrapping is the task of deciding where to break a paragraph of text into lines. For a tidy result, every line except the last one should be about the same length. The text on the left below looks less ragged than the text on the right.

This is a                         This
paragraph                         is a paragraph
of text.                          of text.

Compute a raggedness value for an arbitrary paragraph of text. The measure follows the TeX typesetting system. Let nn be the length, in characters, of the longest line of the paragraph. A line of length mm is charged a penalty of (n−m)2(n - m)^2. The raggedness is the sum of the penalties of every line except the last one.

Input

The input is a single paragraph of at most 100 lines. Each line holds between 1 and 80 characters, and the characters are letters, punctuation characters, decimal digits and spaces. No line starts or ends with a space. The paragraph ends at end of file.

Output

Print a single integer, the raggedness of the paragraph.

Examples5

  1. Example 1

    Input
    some blocks
    of text line up
    well on the right,
    but
    some don't.
    
    Expected output
    283
    
  2. Example 2

    Input
    this line is short
    this one is a bit longer
    and this is the longest of all.
    
    Expected output
    218
    
  3. Example 3

    Input
    a single line paragraph
    
    Expected output
    0
    
  4. Example 4

    Input
    abcd efgh
    ijkl mnop
    qrst uvwx
    yzab cdef
    
    Expected output
    0
    
  5. Example 5

    Input
    hi
    this line is longer
    
    Expected output
    289