Statement : Sum of Fractions
An increase of the fraction
- increase the numerator
by , or - if
, decrease the denominator by .
The fraction is not reduced after an increase (e.g.
Given an array
- Build fractions
. - Choose any fraction and apply an increase to it.
- Repeat step 2 exactly
times (same fraction can be chosen multiple times). - Take the sum of the resulting fractions.
Define
Let
You are given arrays
Output each result as
First line: two integers
Second line:
Third line:
For each
Input
5 4
2 3 5 2 3
0 1 2 10
Output
232923695
332748137
931694761
133099397
Note
The answers as rationals are