AlgoUniversity
  • Go Back
Discussion
Add K Time Series :

Author

Gigaliths

Difficulty Level : Hard

Submissions : 349

Asked In : Google

Marks :10

: 3 | : 4

You have been given information regarding K time series data.

A Discrete time series is an array of (timei,valuei) .

Let T1 = [ (0,1) , (3,5) , (7,2) ]

Let T2 = [ (2,2) , (3,3) , (6,1) ]

The time series denotes the spike at time timei with a magnitude of valuei. The magnitude remains same until a new spike occurs with an updated magnitude.

For T1 , value = 1 for [0,3) , 5 for [3,7) , 2 for [7,inf)

for T2 , value = 2 for [0,2) , 3 for [3,6) , 1 for [6,inf)

Adding T1 and T2 results in a new time series = [ (0,1) , (2,3) , (3,8) , (6,6) , (7,3) ]

Given K such time series, Print the resultant time series after adding all K time series.

Input

First line contains one integer K corresponding to the number of time series data.

K Lines follow in similar manner as below :-

A single line containing the size Ni of the ith time series.

Ni space separated integers corresponding to timej for the ith time series.

Ni space separated integers corresponding to valuej for the ith time series.

Constraints

1≤∑Ni≤107

1≤timei,valuei≤109

Output

First line corresponds to single integer N corresponding to the size of resultant time series.

Second line corresponds to N space separated integers corresponding to the timei of the resultant time series.

Third line corresponds to N space separated integers corresponding to the valuei of the resultant time series.

Example

Input
2
3
0 3 7
1 5 2
3
2 3 6
2 3 1
Output
5
0 2 3 6 7 
1 3 8 6 3 

You need to login to view your submissions.

You need to login to view all submissions.

Loading...

Result : Executed

Loading...

Feel something is wrong with the test cases?

Result : Accepted

Test Cases :

You need to Log In
We're glad that you want to attempt this problem!

But to Run or Submit the Problem, you need to Log In.

Continue to Log In
Challenge Submitted!

Your challenge has been submitted successfully.

You will get a response soon via WhatsApp or Email.

Challenge
Facing issue while trying to solve the problem! Don't worry, we got you covered!

Do let us know your issue.

Looks good!
Please enter your issue / feedback.

How do we get in touch with you?
Looks good!
Please enter your phone no.
Looks good!
Please enter your email address.