This page is still under construction.

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

Paper Snowflakes

Time limit5sMemory limit1024 MB

Summary
Fold a paper strip back and forth at decreasing distances from the loose end, cut it at M positions, and report the total paper length in each resulting pile.
Level

Hard8 of 10

Topics
Simulation, Sorting, Binary search, Math
Solved
No attempts yet

Problem

To make a paper snowflake, you fold a sheet of paper in various places and then cut some parts out of the folded sheet. When you unfold the sheet, it can make a very nice pattern. That is, if the folds and cuts are chosen well.

Samantha has recently taken up this hobby but with a "modern art" twist. To get started, she explores folding a strip of paper that is LL picometres long (Samantha likes to measure her folds and cuts very precisely). She places it on the real line with one end at 00 and the other at LL. The left end at point 00 is affixed to this point, the other endpoint at position LL is the loose endpoint.

She then performs a series of folds. For the first fold, Samantha creases the paper f1f_1 picometres from the loose end and folds the loose end over this fold. The loose end is now pointing towards the left. For the second fold, she then creases the top portion of the paper f2f_2 picometres from the loose end (f2<f1f_2 < f_1) and folds the top portion of the paper over this point back to the right over this crease point. The loose end is now pointing towards the right.

She alternates folding back-and-forth this way. At each step, she creases the top portion of the paper fif_i picometres from the loose end (fi<fi−1f_i < f_{i-1}) and folds the loose end over the crease.

She will now cut the paper at MM distinct locations, which will split the paper into M+1M+1 piles. Each of the piles will have zero or more layers of paper in it. The figure below depicts the folded paper from the first sample input, the cuts (solid lines), and the xx-locations of where the paper was folded (dashed lines).

What is the total length of paper in each of the M+1M+1 piles?

Input

The first line of input consists of three integers NN (1≤N≤1051 \leq N \leq 10^5), which is the number of folds, MM (1≤M≤1051 \leq M \leq 10^5), which is the number of cuts, and LL (2≤L≤10182 \leq L \leq 10^{18}), which is the length of the paper in picometres.

The second line describes the folds. This line contains NN integers f1,f2,…,fNf_1, f_2, \ldots, f_N, indicating that the ithi^\textrm{th} fold occurred fif_i picometres from the loose end. These values satisfy 1≤fN<fN−1<⋯<f1<L1 \leq f_N < f_{N-1} < \cdots < f_1 < L.

The third line describes the cuts. This line contains MM integers c1,c2,…,cMc_1, c_2, \ldots, c_M, indicating that the ithi^\textrm{th} cut is cic_i picometres from the affixed point. These values satisfy −1018≤c1<c2<⋯<cM≤1018-10^{18} \leq c_1 < c_2 < \cdots < c_M \leq 10^{18}.

Output

Output the total length of paper in each of the M+1M+1 piles, in order from left to right.

Examples3

  1. Example 1

    Input
    4 2 20
    19 17 11 7
    1 6
    
    Expected output
    5 13 2
    
  2. Example 2

    Input
    1 1 10
    9
    0
    
    Expected output
    8 2
    
  3. Example 3

    Input
    1 2 1000000000000000000
    500000000000000000
    0 500000000000000000
    
    Expected output
    0 1000000000000000000 0