Battle X74488


Statement
 

pdf   zip

Two armies XX and YY fight each other in a computer game. Army XX has nn soldiers and army YY has mm 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 XX has won, how many combats army YY 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 nn, followed by nn integers that represent the strengths of the soldiers of army XX. After that, we have an integer mm, followed by mm integers representing the strengths of the soldiers of army YY. You can assume that nn and mm are between 1 and 10510^5, and that all strengths will be between 1 and 10910^9.

Output

For each case, write the number of combats won by army XX, the number won by army YY 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++