This page is still under construction.

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

Book Borders

Time limit2sMemory limit512 MB

Summary
For each width m from a to b, wrap the words greedily into lines of at most m characters and report the length of the sentence made of each line's first word.
Level

Hard8 of 10

Topics
Divide and conquer, Prefix sum, Binary search
Solved
No attempts yet

Problem

A book is typeset with a fixed width font and a simple greedy algorithm that fills one line at a time. The contents of the book are a sequence of words, and each word has one or more characters.

Before typesetting you choose a maximum line length and call it mm. A line holds at most mm characters, counting the spaces between words. The algorithm walks through the words in order and prints exactly one space between two consecutive words on the same line. If adding the current word to the current line would push it past mm characters, the algorithm starts a new line with that word instead.

|its.a.long...|          |its.a.long.way|
|way.to.the...|          |to.the.top.if.|
|top.if.you...|          |you.wanna.rock|
|wanna.rock.n.|          |n.roll........|
|roll.........|

The figure shows the text "its a long way to the top if you wanna rock n roll" typeset with maximum line lengths 13 and 14. The dots stand for space characters.

Fix one value of mm. Take the first word of every line from top to bottom and join those words with a single space. The result is called the leading sentence. With maximum line length 14 the leading sentence in the figure is "its to you n".

You are given a text and two integers aa and bb. For every maximum line length between aa and bb inclusive, find the length of the leading sentence. The length of a sentence is the number of characters it contains, counting its spaces.

Input

The first line contains the text to typeset: a sequence of words separated by exactly one space. Each word is a string of one or more lowercase letters of the English alphabet.

The second line contains two integers aa and bb, the ends of the interval described above.

Let ww be the length of the longest word in the text and let zz be the total number of characters in the text, counting the spaces. Then 1≤w≤a≤b≤z≤5000001 \le w \le a \le b \le z \le 500000.

Output

Print b−a+1b - a + 1 lines. The kk-th line contains one integer, the length of the leading sentence when the maximum line length is a−1+ka - 1 + k.

Examples2

  1. Example 1

    Input
    its a long way to the top if you wanna rock n roll
    13 16
    
    Expected output
    22
    12
    12
    15
    
  2. Example 2

    Input
    typesetting
    11 11
    
    Expected output
    11