Under construction

Still being built. Things may change

Shortening Links

Time limit2sMemory limit1024 MB

Summary
Given a length limit l and a message, shorten each http:// link from left to right into a prefix plus "..." until the message fits, then report any overflow.
Level

Medium4 of 10

Topics
String, Simulation, Greedy
Solved
No attempts yet

Problem

Vasya decided to build his own social network. Any user can write a message to another user, but a message may contain at most ll characters. The character limit changes every day.

Vasya finished the site and showed it to his friend Petya. Petya suggested shortening links so that messages can carry more information. Help Vasya implement link compression.

A link is a string that starts with http://, followed by lowercase Latin letters, digits, and the characters /, :, or .. There must be at least one character after http://. A link is preceded by a space or the start of the line, and followed by a space or the end of the line.

A shortened link is any prefix of the original link (zero or more of its first characters) followed by three dots .... The prefix should be as long as possible. Links are processed from left to right. A link is shortened only as much as needed to make the message fit within ll characters. If the message still does not fit after a link is shortened to ..., that link stays at ... and processing moves on to the next link.

For example, http://pda.lenta.ru/news/2012/01/09/sudoku/ can be shortened to http://pda.lenta.ru/news/2012/01/0... or to ....

Input

The first line contains one integer ll (2≤l≤100002 \le l \le 10000), the limit on the message length. The second line contains the message ss. The message is not empty, has at most 10000 characters, and ends with a newline that is not part of the message. The message contains at least one link.

Output

The first line contains the compressed message. The second line contains 0 if the compressed message fits within the limit. Otherwise, it contains the number of characters by which the message exceeds the limit.

Examples4

  1. Example 1

    Input
    67
    Visit http://olympiads.ru/zaoch/ and http://acm.timus.ru --- it's interesting.
    
    Expected output
    Visit http://olymp... and http://acm.timus.ru --- it's interesting.
    0
    
  2. Example 2

    Input
    46
    Visit http://olympiads.ru/zaoch/ and http://acm.timus.ru --- it's interesting.
    
    Expected output
    Visit ... and http://... --- it's interesting.
    0
    
  3. Example 3

    Input
    30
    Visit http://olympiads.ru/zaoch/ and http://acm.timus.ru --- it's interesting.
    
    Expected output
    Visit ... and ... --- it's interesting.
    9
    
  4. Example 4

    Input
    81
    This link is not valid http://iojury@gmail.com but this one is valid http://godzilla
    
    Expected output
    This link is not valid http://iojury@gmail.com but this one is valid http://go...
    0