### Problem Statement

You have a device that measures temperature once a minute. Sadly, the temperature sensor of your device is not 100% reliable, and sometimes it reports wildly inaccurate values.

You don't have the resources to buy a new device so you decide to fix the problem by writing software for your device that will throw away invalid measurements. We consider a measurement invalid if:

• the value is less than -273, or
• each value that was measured within 2 minutes before and after this one differs from this value by more than 2

In other words, when deciding whether a measurement is valid, you usually consider the previous two, and the next two measurements.

You are given a int[] measuredValues that contains temperatures measured in the last few minutes. The temperatures are given in chronological order, i.e., the i-th value is the temperature measured i minutes after the device was started. Write a method that computes the average of the valid measurements. If no measurement is valid, return -300.0.

### Definition

 Class: MeasuringTemperature Method: averageTemperature Parameters: int[] Returns: double Method signature: double averageTemperature(int[] measuredValues) (be sure your method is public)

### Notes

-The returned value must be accurate to within a relative or absolute error of 1E-9.
-The lowest possible temperature (in degrees Celsius) is -273.15.
-It may seem weird that only integer temperatures are used in the input. This is only done to avoid rounding errors.

### Constraints

-measuredValues contains between 2 and 50 elements, inclusive.
-Each element of measuredValues will be between -1000 and 1000, inclusive.

### Examples

0)

 `{9, 11, 12, 13, 15}`
`Returns: 12.0`
 All measurements are valid. During this period of time it was getting warmer. The average temperature is (9+11+12+13+15)/5 = 12.
1)

 `{0, 0, 0, 2, 997, -1, 0}`
`Returns: 0.16666666666666666`
 The fifth measurement is clearly invalid. The average of the valid ones is slightly positive.
2)

 `{0, 0, 0, 2, -4, -1, 0}`
`Returns: 0.16666666666666666`
 This time, the fifth measurement is only slightly off, but still we consider it to be invalid.
3)

 `{0, 0, 0, 2, -3, -1, 0}`
`Returns: -0.2857142857142857`
 All the measurements are valid.
4)

 `{1,2,3,100,100,1,2}`
`Returns: 29.857142857142858`
 Again, all these measurements are valid. (Sadly, the sensor malfunctioned twice in a row. Our approach can't deal with this situation.)
5)

 `{1,2,3,4,5,6,7,10}`
`Returns: 4.0`
 The last measurement is invalid. (The measurements made within 2 minutes from the last measurement gave results 6 and 7, and neither of these values is close enough to 10.)
6)

 `{-35, -34, -34, -34, -35, 72, -34, 52, -36, -35, -36, 52, -36, -35, 981, -33}`
`Returns: -34.75`
 It's freezing cold and the sensor is malfunctioning quite often, but luckily we can identify all the wrong measurements (72, 52, 52, and 981) as invalid.
7)

 `{-273, -273, -274, -273}`
`Returns: -273.0`
 The third measurement gives a temperature lower than -273, and thus is considered to be invalid.
8)

 `{10, 20, 30, 40}`
`Returns: -300.0`
 No valid measurements here.

#### Problem url:

http://www.topcoder.com/stat?c=problem_statement&pm=6553

#### Problem stats url:

http://www.topcoder.com/tc?module=ProblemDetail&rd=9990&pm=6553

misof

#### Testers:

PabloGilberto , brett1479 , Olexiy , marian

#### Problem categories:

Simple Search, Iteration
{"ft_lang_label":"__label__en","ft_lang_prob":0.8626005,"math_prob":0.95207936,"size":2961,"snap":"2019-51-2020-05","text_gpt3_token_len":751,"char_repetition_ratio":0.17653027,"word_repetition_ratio":0.0,"special_character_ratio":0.29787233,"punctuation_ratio":0.16460177,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.96240807,"pos_list":[0],"im_url_duplicate_count":[null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2020-01-19T05:06:33Z\",\"WARC-Record-ID\":\"<urn:uuid:864e1932-6d1d-40a2-8b04-2eb8eab1ebc1>\",\"Content-Length\":\"10231\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:5675540d-53c0-4fb0-a943-739d8dddbd25>\",\"WARC-Concurrent-To\":\"<urn:uuid:ee59e098-5a3f-4477-aa07-a0f5b728855b>\",\"WARC-IP-Address\":\"78.128.6.10\",\"WARC-Target-URI\":\"http://topcoder.bgcoder.com/print.php?id=1339\",\"WARC-Payload-Digest\":\"sha1:FCHY2WKZ2NFGPOWW3ASYN7SCOZUF4LOW\",\"WARC-Block-Digest\":\"sha1:BNOVG6UCIZG5M6FARUAHXF5OCECCTH53\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2020/CC-MAIN-2020-05/CC-MAIN-2020-05_segments_1579250594209.12_warc_CC-MAIN-20200119035851-20200119063851-00009.warc.gz\"}"}