This page is still under construction.

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

Data Mining

Time limit1sMemory limit128 MB

Summary
Choose non-negative shifts A and B so the floor formula for Q's offsets packs N records of size S_Q without overlap, minimizing the required K, then A, then B.
Level

Hard8 of 10

Topics
Math, Number theory, Binary search, Brute force
Solved
No attempts yet

Problem

Dr. Tuple is developing a new data-mining application for a commercial merchandise company. One of its subroutines works with two arrays PP and QQ, each holding NN records (records are numbered from 00 to N−1N-1). Array PP holds a hash-like structure of keys and is used to locate a record; the data of that record is then read from array QQ.

Every record in PP has size SPS_P bytes and every record in QQ has size SQS_Q bytes. This subroutine is a hot spot of the whole application, so it must run as fast as possible. Because SPS_P and SQS_Q are known only at run time, several compile-time optimizations become impossible.

The byte offset of the ii-th record is normally computed as

Pofs(i)=SP⋅i,Qofs(i)=SQ⋅i.Pofs(i) = S_P \cdot i, \qquad Qofs(i) = S_Q \cdot i.

Multiplication is much slower than addition on modern processors, so while scanning array PP Dr. Tuple keeps the byte offset Pofs(i)Pofs(i) instead of the index ii, and moves to a neighbouring record with Pofs(i+1)=Pofs(i)+SPPofs(i+1) = Pofs(i) + S_P or Pofs(i−1)=Pofs(i)−SPPofs(i-1) = Pofs(i) - S_P.

Whenever a record of PP is located, the matching record of QQ must be read, which needs its offset Qofs(i)Qofs(i). From the two formulas above one gets

Qofs(i)=Pofs(i)/SP⋅SQ.Qofs(i) = Pofs(i) / S_P \cdot S_Q.

This contains both a multiplication and a (slow) integer division. To avoid them, Dr. Tuple uses the fast formula

Qofs′(i)=(Pofs(i)+(Pofs(i)≪A))≫B,Qofs'(i) = \big(Pofs(i) + (Pofs(i) \ll A)\big) \gg B,

where AA and BB are non-negative integers, x≪Ax \ll A is a left shift by AA bits (i.e. x⋅2Ax \cdot 2^A) and x≫Bx \gg B is a right shift by BB bits (i.e. ⌊x/2B⌋\lfloor x / 2^B \rfloor). Assume the registers are wide enough that overflow never occurs. Since Pofs(i)=SP⋅iPofs(i) = S_P \cdot i, this equals

Qofs′(i)=⌊SP⋅(1+2A)⋅i2B⌋.Qofs'(i) = \left\lfloor \frac{S_P \cdot (1 + 2^A) \cdot i}{2^B} \right\rfloor.

For most choices of AA and BB this does not equal Qofs(i)Qofs(i), but it can still be used at the cost of some extra memory. A conventional layout of QQ needs N⋅SQN \cdot S_Q bytes. Dr. Tuple can always pick a KK (with K≥N⋅SQK \ge N \cdot S_Q) such that, if KK bytes are allocated for QQ and AA, BB are chosen carefully, the fast formula stores the NN records without overlap: record ii occupies the byte range [Qofs′(i), Qofs′(i)+SQ)[Qofs'(i),\ Qofs'(i) + S_Q), all NN ranges are pairwise disjoint, and they all fit inside [0,K)[0, K).

Write a program that finds the minimal KK together with the corresponding AA and BB. If several pairs (A,B)(A, B) give the same minimal KK, output the one with the smallest AA; if there is still a tie, output the one with the smallest BB.

Input

The input contains three integers NN, SPS_P, and SQS_Q separated by spaces (1≤N≤2201 \le N \le 2^{20}, 1≤SP≤2101 \le S_P \le 2^{10}, 1≤SQ≤2101 \le S_Q \le 2^{10}).

Output

Print a single line with three integers KK, AA, and BB separated by spaces.

Examples2

  1. Example 1

    Input
    20 3 5
    
    Expected output
    119 0 0
    
  2. Example 2

    Input
    1024 7 1
    
    Expected output
    1119 2 5