Battle X74488


Statement
 

pdf   zip

html

Two armies X and Y fight each other in a computer game. Army X has n soldiers and army Y has m soldiers. Each soldier has a certain strength, that is a strictly positive integer. At each round, the strongest soldiers of each army fight in an individual combat. The weakest soldier dies, and the strongest one survives with the difference of strengths. For example, if one soldier has 10 strength units and the other one has 12, the one with 10 dies and the one with 12 will survive with only 2 strength units. The battle finishes when some of the armies has no soldiers left. At the end, you have to say how many combats army X has won, how many combats army Y has won and how many ties there have been (that is, with both soldiers dying because they had the same strength).

Input

The input consists of several cases. Each case starts with an integer n, followed by n integers that represent the strengths of the soldiers of army X. After that, we have an integer m, followed by m integers representing the strengths of the soldiers of army Y. You can assume that n and m are between 1 and 105, and that all strengths will be between 1 and 109.

Output

For each case, write the number of combats won by army X, the number won by army Y and the number of ties.

Public test cases
  • Input

    1  100
    5  1 2 3 4 5
    3  10 20 30
    4  22 22 8 8
    4  1 1 1000000000 1
    2  5 999999999
    

    Output

    5 0 0
    2 1 2
    1 4 0
    
  • Information
    Author
    Language
    English
    Translator
    Original language
    Catalan
    Other languages
    Catalan
    Official solutions
    C++
    User solutions
    C++