This page is still under construction.

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

Spaceships

Interview

Time limit1sMemory limit512 MB

Summary
The program counts triples with one module from each factory whose fuel-weighted range tops half the best possible range.
Level

Medium6 of 10

Topics
Sorting, Binary search
Solved
No attempts yet

Problem

The air force generals of Byteland, Bajtek, Kajtek, and Zajtek, are preparing the first great space expedition in the country's history. Each of them has already stockpiled some rocket fuel, and now they are about to buy the modules that make up a rocket. A Byteland rocket flies in stages: at the start only the bottom (first) module provides thrust, and once its fuel is spent that module is jettisoned and the next module takes over, and so on.

Today each general visits his favourite factory and buys exactly one engine module of some efficiency. The three purchased modules are stacked in a fixed order: Bajtek buys the bottom module, Kajtek the middle one, and Zajtek the top one. The rocket's range (the greatest distance it can fly) equals the sum of the ranges of its three modules, where each module's range is the product of its engine efficiency and the volume of fuel loaded into it. Bajtek loads all bb units of his fuel into his module, Kajtek loads kk units into his, and Zajtek loads zz units into his.

Because prices keep rising, the generals cannot always buy the most efficient modules. They want to know how many different triples of modules (one bought by each general from his own factory) form a rocket whose range is strictly greater than half of the maximum possible range, where the maximum range is achieved when every general buys the most efficient module in his factory. Two modules with the same efficiency still count as different modules.

Write a program that:

  • reads the module offerings of the factories the generals will visit and the amounts of rocket fuel they possess from standard input,
  • computes the number of module triples that satisfy Bajtek, Kajtek, and Zajtek's requirement,
  • prints the result to standard output.

Input

The first line contains three integers bb, kk, and zz (1≤b,k,z≤1 000 000 0001 \le b, k, z \le 1\,000\,000\,000), separated by single spaces, giving the fuel volumes owned by Bajtek, Kajtek, and Zajtek respectively.

Then follow the descriptions of the three factories, in the order visited by Bajtek, Kajtek, and Zajtek. Each factory is described by two lines. The first line holds one integer nin_i (1≤ni≤10001 \le n_i \le 1000), the number of modules on offer. The second line holds nin_i positive integers, each at most 1 000 000 0001\,000\,000\,000 and separated by single spaces, giving the efficiencies of those modules.

Output

Print a single line with the number of rockets whose range is strictly greater than half of the maximum range.

Note

As an illustration, take b=2b = 2, k=3k = 3, z=3z = 3, with the first factory offering efficiencies 11 and 33, the second offering 11, 55, 11, and the third offering 22 (this is the first test case). The maximum possible range is 27=2⋅3+3⋅5+3⋅227 = 2 \cdot 3 + 3 \cdot 5 + 3 \cdot 2, so a rocket qualifies when its range exceeds 13.513.5. The four qualifying module triples (written by efficiency) are (1,5,2)(1, 5, 2), (3,1,2)(3, 1, 2), (3,1,2)(3, 1, 2), and (3,5,2)(3, 5, 2), with ranges 2323, 1515, 1515, and 2727. The two (3,1,2)(3, 1, 2) triples are counted separately because the middle factory lists the efficiency 11 module twice.

Examples1

  1. Example 1

    Input
    2 3 3
    2
    1 3
    3
    1 5 1
    1
    2
    
    Expected output
    4