This page is still under construction.

Parts of this page are still being built. What you see may change.

Futures Market Trends

Time limit2sMemory limit512 MB

Summary
Count subsegments of a price sequence whose average daily change is at least P times the standard deviation of the changes, both positive and negative.
Level

Medium7 of 10

Topics
Math, Prefix sum, Brute force, Implementation
Solved
No attempts yet

Problem

Fedor wants to earn some extra money from oil futures. His analysis is based on trends and historical data of dd previous days.

A cost sequence of at least three distinct days c0,c1,c2,⋯ ,cnc_0, c_1, c_2, \cdots, c_n forms a trend of power PP if the average cost change is at least PP times bigger than the standard deviation of cost changes.

Formally, the average cost change is A=1n∑i=1n(ci−ci−1)A = \frac{1}{n}\sum\limits_{i=1}^n \left(c_i - c_{i-1}\right). The standard deviation of cost changes is D=1n∑i=1n(ci−ci−1−A)2D = \sqrt{\frac{1}{n}\sum\limits_{i=1}^n{\left(c_i - c_{i-1} - A\right)^2}}. The sequence forms a positive trend of power PP if AD≥P\frac{A}{D} \ge P, and a negative trend of power PP if AD≤−P\frac{A}{D} \le -P.

We assume that if A>0A > 0 and D=0D = 0 then a positive trend of any power is formed. Similarly, if A<0A < 0 and D=0D = 0 then a negative trend of any power is formed. If A=0A = 0 then no trend is formed, even if D=0D = 0.

To check his theory, Fedor needs to count the number of subsegments of historical data which form positive and negative trends of the given power. Can you help him?

Input

The first line contains an integer dd (3≤d≤3 0003 \le d \le 3\,000) and a real number PP (0.001≤P≤10000.001 \le P \le 1000), the number of days in Fedor's historical data and the required trend power. PP is given with at most 9 digits after the decimal point.

The next line contains dd integers c1,c2,…,cdc_1, c_2, \ldots, c_d (−1000≤ci≤1000-1000 \le c_i \le 1000). For each ii, cic_i is the cost of oil futures at the end of the ii-th day.

Output

Print two integers: the number of subsegments of historical data forming a positive and a negative trend of power PP, respectively. It's guaranteed that the answer would not change if one changes PP by no more than 10−810^{-8}.

Note

The third example test case demonstrates the real prices of oil futures in April 2020 (in dollars, multiplied by 10 and rounded). Be careful with theories like the one Fedor made.

Examples3

  1. Example 1

    Input
    6 0.2
    100 110 120 30 40 50
    
    Expected output
    2 8
    
  2. Example 2

    Input
    6 0.7
    100 110 120 30 40 50
    
    Expected output
    2 2
    
  3. Example 3

    Input
    10 1.234
    236 250 227 224 201 198 198 182 -376 100
    
    Expected output
    0 5