Electricity

Interview

Time limit1sMemory limit128 MB

Summary
Given dated meter readings sorted by date, count pairs on consecutive calendar days and report how many such days exist plus the total consumption between them.
Level

Easy3 of 10

Topics
Implementation, Math, Array, Simulation
Solved
No attempts yet

Problem

Martin and Isa got married and moved to a new house in a remote place. Electricity is very expensive there, so they want to keep their consumption under control.

The house has an electricity meter that shows, as a whole number of kilowatt-hours (KWh), the total amount of electricity consumed since they arrived. At the beginning of each day they check the meter and write down its reading — some days Martin does it, some days Isa. By comparing the readings of two consecutive days, they can tell how much electricity was consumed during the day in between.

Some days, however, they forget, so their record now has gaps. They have a list of dates together with the meter reading taken on the morning of each date, but the dates are not all consecutive.

The consumption of a given day can be determined exactly only if they have the meter reading for the morning of that day and for the morning of the next day. In other words, only when two records fall on two consecutive calendar days can the consumption of the earlier day be known exactly.

Determine how many days have an exactly determinable consumption, and the total consumption over those days.

Input

The input contains several test cases.

The first line of each test case contains one integer NN (2≤N≤1032 \le N \le 10^3), the number of readings. Each of the following NN lines contains four integers DD, MM, YY and CC, separated by single spaces: the day DD (1≤D≤311 \le D \le 31), month MM (1≤M≤121 \le M \le 12), year YY (1900≤Y≤21001900 \le Y \le 2100) and cumulative consumption CC (0≤C≤1060 \le C \le 10^6) read on the morning of that day.

These NN lines are sorted in increasing order of date and may include leap years. The sequence of consumptions is strictly increasing (no two readings are equal). DD, MM and YY always represent a valid date.

Recall that a year is a leap year if it is divisible by 4 and not by 100, or if it is divisible by 400.

The end of the input is indicated by a line containing a single zero.

Output

For each test case, print a single line with two integers separated by a single space: the number of days whose consumption can be determined exactly, and the sum of the consumptions over those days.

Examples4

  1. Example 1

    Input
    5
    9 9 1979 440
    29 10 1979 458
    30 10 1979 470
    1 11 1979 480
    2 11 1979 483
    3
    5 5 2000 6780
    6 5 2001 7795
    7 5 2002 8201
    8
    28 2 1978 112
    1 3 1978 113
    28 2 1980 220
    1 3 1980 221
    5 11 1980 500
    14 11 2008 600
    15 11 2008 790
    16 12 2008 810
    0
    
    Expected output
    2 15
    0 0
    2 191
    
  2. Example 2

    Input
    2
    1 1 2000 100
    2 1 2000 150
    0
    
    Expected output
    1 50
    
  3. Example 3

    Input
    2
    1 1 2000 100
    3 1 2000 150
    0
    
    Expected output
    0 0
    
  4. Example 4

    Input
    3
    28 2 2000 10
    29 2 2000 25
    1 3 2000 40
    0
    
    Expected output
    2 30