In this kata, you will write a function that returns the positions and the values of the "peaks" (or local maxima) of a numeric array.

For example, the array `arr = [0, 1, 2, 5, 1, 0]` has a peak at position `3` with a value of `5` (since `arr[3]` equals `5`).

~~~if-not:php,cpp,java,csharp
The output will be returned as an object with two properties: pos and peaks. Both of these properties should be arrays. If there is no peak in the given array, then the output should be `{pos: [], peaks: []}`.
~~~
~~~if:php
The output will be returned as an associative array with two key-value pairs: `'pos'` and `'peaks'`.  Both of them should be (non-associative) arrays.  If there is no peak in the given array, simply return `['pos' => [], 'peaks' => []]`.
~~~
~~~if:cpp
The output will be returned as an object of type `PeakData` which has two members: `pos` and `peaks`.  Both of these members should be `vector`s.  If there is no peak in the given array then the output should be a `PeakData` with an empty vector for both the `pos` and `peaks` members.

`PeakData` is defined in Preloaded as follows:

~~~
~~~if:java
The output will be returned as a ``Map>` with two key-value pairs: `"pos"` and `"peaks"`. If there is no peak in the given array, simply return `{"pos" => [], "peaks" => []}`.
~~~
~~~if:csharp
The output will be returned as a `Dictionary>` with two key-value pairs: `"pos"` and `"peaks"`. 
If there is no peak in the given array, simply return `{"pos" => new List(), "peaks" => new List()}`.
~~~

Example: `pickPeaks([3, 2, 3, 6, 4, 1, 2, 3, 2, 1, 2, 3])` should return `{pos: [3, 7], peaks: [6, 3]}` (or equivalent in other languages)

All input arrays will be valid integer arrays (although it could still be empty), so you won't need to validate the input.

The first and last elements of the array will not be considered as peaks (in the context of a mathematical function, we don't know what is after and before and therefore, we don't know if it is a peak or not).

Also, beware of plateaus !!! `[1, 2, 2, 2, 1]` has a peak while `[1, 2, 2, 2, 3]` does not. In case of a plateau-peak, please only return the position and value of the beginning of the plateau. For example: 
`pickPeaks([1, 2, 2, 2, 1])` returns `{pos: [1], peaks: [2]}` (or equivalent in other languages)

Have fun!

Source: codewars | Difficulty: EASY
Tags: Data structures

Starter code: def pick_peaks(arr):
	

Solutions:
def pick_peaks(arr):
	pos = []
	prob_peak = False
	for i in range(1, len(arr)):
		if arr[i] > arr[i - 1]:
			prob_peak = i
		elif arr[i] < arr[i - 1] and prob_peak:
			pos.append(prob_peak)
			prob_peak = False
	return {'pos': pos, 'peaks': [arr[i] for i in pos]}


def pick_peaks(arr):
	(peak, pos) = ([], [])
	res = {'peaks': [], 'pos': []}
	for i in range(1, len(arr)):
		if arr[i] > arr[i - 1]:
			(peak, pos) = ([arr[i]], [i])
		elif arr[i] < arr[i - 1]:
			res['peaks'] += peak
			res['pos'] += pos
			(peak, pos) = ([], [])
	return res


def pick_peaks(arr):

	def add_peak(p):
		peaks['pos'].append(p)
		peaks['peaks'].append(arr[p])

	def is_peak(p):
		return arr[p - 1] < arr[p] > arr[p + 1]

	def is_plateau_start(p):
		return arr[p - 1] < arr[p] == arr[p + 1]

	def does_plateau_end_lower(p):
		return next((val for val in arr[p + 1:] if val != arr[p]), arr[p]) < arr[p]
	peaks = {'pos': [], 'peaks': []}
	for p in range(1, len(arr) - 1):
		if is_peak(p):
			add_peak(p)
		elif is_plateau_start(p) and does_plateau_end_lower(p):
			add_peak(p)
	return peaks


def pick_peaks(arr):
	peaks = []
	pos = []
	current_pos = None
	for i in range(len(arr) - 1):
		if arr[i] < arr[i + 1]:
			current_pos = i + 1
		elif arr[i] > arr[i + 1] and i != 0 and (current_pos is not None):
			pos += [current_pos]
			peaks += [arr[current_pos]]
			current_pos = None
	return {'pos': pos, 'peaks': peaks}


def pick_peaks(a):
	deltas = [(i, x2 - x1) for (i, (x1, x2)) in enumerate(zip(a, a[1:]), 1) if x1 != x2]
	indexes = [i for ((i, dx1), (_, dx2)) in zip(deltas, deltas[1:]) if dx1 > 0 > dx2]
	return dict(pos=indexes, peaks=[a[i] for i in indexes])


def pick_peaks(arr):
	peaks = {'pos': [], 'peaks': []}
	for i in range(1, len(arr)):
		next_num = next((num for num in arr[i:] if num != arr[i]), float('inf'))
		if arr[i - 1] < arr[i] and next_num < arr[i]:
			peaks['pos'].append(i)
			peaks['peaks'].append(arr[i])
	return peaks


def pick_peaks(arr):
	PairList = []
	for (i, e) in enumerate(arr):
		if arr[i - 1] >= e or i == 0:
			continue
		for k in arr[i:]:
			if k == e:
				continue
			elif k > e:
				break
			else:
				PairList.append([i, e])
				break
	return {'pos': [k[0] for k in PairList], 'peaks': [k[1] for k in PairList]}


def pick_peaks(arr):
	prev_dex = prev_val = None
	result = {'pos': [], 'peaks': []}
	upwards = False
	for (i, a) in enumerate(arr):
		if prev_val == a:
			continue
		elif prev_val is None or prev_val < a:
			upwards = True
		else:
			if prev_dex and upwards:
				result['pos'].append(prev_dex)
				result['peaks'].append(prev_val)
			upwards = False
		prev_dex = i
		prev_val = a
	return result


import re

def pick_peaks(arr):
	slope = ''.join(('u' if b > a else 'd' if a > b else 'p' for (a, b) in zip(arr, arr[1:])))
	positions = [m.start() + 1 for m in re.finditer('up*d', slope)]
	peaks = [arr[pos] for pos in positions]
	return {'pos': positions, 'peaks': peaks}


def pick_peaks(arr):
	cast = []
	for (i, e) in enumerate(arr):
		if cast and e == cast[-1][0]:
			continue
		cast.append((e, i))
	doc = {'pos': [], 'peaks': []}
	for i in range(1, len(cast) - 1):
		if cast[i - 1][0] < cast[i][0] > cast[i + 1][0]:
			doc['peaks'].append(cast[i][0])
			doc['pos'].append(cast[i][1])
	return doc


def sign(x):
	if x > 0:
		return 1
	elif x < 0:
		return -1
	elif x == 0:
		return 0

def pick_peaks(arr):
	pos = []
	peaks = []
	l = len(arr)
	diff_arr = []
	for i in range(0, l - 1):
		diff_arr.append(sign(arr[i + 1] - arr[i]))
	i = 0
	while i < l - 2:
		k = 1
		while sign(diff_arr[i + k]) == 0 and i + k < l - 2:
			k += 1
		if sign(diff_arr[i + k]) < sign(diff_arr[i]) and sign(diff_arr[i]) != 0 and (sign(diff_arr[i + k]) != 0):
			pos.append(i + 1)
			peaks.append(arr[i + 1])
		i += k
	d_pos_peaks = dict(pos=pos, peaks=peaks)
	return d_pos_peaks


def pick_peaks(arr):
	redic = {'pos': [], 'peaks': []}
	for i in range(1, len(arr) - 1):
		if all((arr[i] > arr[i - 1], arr[i] >= arr[i + 1])):
			j = i
			while arr[j] == arr[i] and j < len(arr) - 1:
				j += 1
				if arr[j] < arr[i]:
					redic['pos'].append(i)
					redic['peaks'].append(arr[i])
	return redic


def pick_peaks(arr):
	result = {'pos': [], 'peaks': []}
	increasing = False
	for i in range(1, len(arr)):
		if arr[i] > arr[i - 1]:
			increasing = True
			tmpk = arr[i]
			tmpindx = i
		elif arr[i] < arr[i - 1]:
			if increasing:
				result['pos'].append(tmpindx)
				result['peaks'].append(tmpk)
				increasing = False
	return result


def pick_peaks(a):
	a = [int(i) for i in a]
	pred = 0
	prov = False
	peaks = []
	pos = []
	count = 0
	spusk = True
	for i in range(len(a)):
		if pred == a[i] and spusk == False:
			count += 1
			prov = True
			continue
		if pred > a[i]:
			if prov == True:
				peaks.append(a[i - 1])
				pos.append(i - 1 - count)
			prov = False
			spusk = True
		elif i != 0 and pred < a[i]:
			prov = True
			spusk = False
		pred = a[i]
		count = 0
	d = {'pos': pos, 'peaks': peaks}
	return d


def pick_peaks(arr):
	(i, pos) = (len(arr) - 2, [])
	while i > 0:
		while i > 0 and arr[i + 1] >= arr[i]:
			i -= 1
		while i > 0 and arr[i + 1] <= arr[i]:
			i -= 1
			if arr[i + 1] > arr[i]:
				pos.append(i + 1)
	return {'peaks': [arr[i] for i in pos[::-1]], 'pos': pos[::-1]}


def pick_peaks(arr):
	result = {'pos': [], 'peaks': []}
	pos = 0
	for i in range(1, len(arr) - 1):
		if arr[i] != arr[pos]:
			pos = i
		if pos and arr[pos - 1] < arr[pos] > arr[i + 1]:
			result['pos'].append(pos)
			result['peaks'].append(arr[pos])
	return result


def pick_peaks(arr):
	print(arr)
	peaks = {'pos': [], 'peaks': []}
	enum_arr = list(enumerate(arr))
	possible_peaks = enum_arr[1:-1]
	for point in possible_peaks:
		(current_p, current_v) = (point[0], point[1])
		(prior_p, prior_v) = enum_arr[current_p - 1]
		(next_p, next_v) = enum_arr[current_p + 1]
		is_peak = prior_v < current_v > next_v
		if is_peak:
			peaks['pos'].append(current_p)
			peaks['peaks'].append(current_v)
		is_plateau = prior_v == current_v or current_v == next_v
		if is_plateau:
			is_peak = prior_v < current_v
			i = current_p
			while is_peak:
				try:
					next = enum_arr[i + 1][1]
					curr = enum_arr[i][1]
				except IndexError:
					break
				next_plateau = next == curr
				if not next_plateau:
					peak_end = next < curr
					if peak_end:
						peaks['pos'].append(current_p)
						peaks['peaks'].append(current_v)
						is_peak = False
					else:
						break
				i += 1
	return peaks


def pick_peaks(arr):
	pos_delta = [pd for pd in enumerate((b - a for (a, b) in zip(arr, arr[1:])), 1) if pd[1]]
	positions = [a[0] for (a, b) in zip(pos_delta, pos_delta[1:]) if a[1] > 0 and b[1] < 0]
	return {'pos': positions, 'peaks': [arr[p] for p in positions]}


def pick_me(arr):
	plateau = None
	for (i, p) in enumerate(arr[1:-1]):
		if arr[i] < p > arr[i + 2]:
			yield (i + 1, p)
			plateau = None
		if arr[i] < p == arr[i + 2]:
			plateau = (i + 1, p)
		if plateau and arr[i] == p > arr[i + 2]:
			yield plateau
			plateau = None

def pick_peaks(arr):
	picked = list(zip(*pick_me(arr)))
	(pos, peaks) = picked if picked else ([], [])
	return {'pos': list(pos), 'peaks': list(peaks)}


def pick_peaks(arr):
	res = {'pos': [], 'peaks': []}
	for i in range(1, len(arr) - 1):
		if arr[i - 1] < arr[i] > arr[[n for n in range(i, len(arr)) if arr[n] != arr[i] or n == len(arr) - 1][0]]:
			res.update({'pos': res.get('pos') + [i]})
			res.update({'peaks': res.get('peaks') + [arr[i]]})
	return res


def pick_peaks(arr):
	lastind = -1
	pos = list()
	peaks = list()
	status = 'init'
	for i in range(1, len(arr)):
		if arr[i] > arr[i - 1]:
			status = 'rising'
			lastind = i
		elif arr[i] < arr[i - 1]:
			if status == 'rising':
				pos.append(lastind)
				peaks.append(arr[i - 1])
				status = 'lol'
	return {'pos': pos, 'peaks': peaks}


def pick_peaks(arr):
	if not arr:
		return {'pos': [], 'peaks': []}
	pos = []
	peaks = []
	arr_iter = enumerate(arr)
	(curr_pos, curr_peak) = next(arr_iter)
	climbing = False
	for (index, value) in arr_iter:
		if value > curr_peak:
			(curr_pos, curr_peak) = (index, value)
			climbing = True
		elif value < curr_peak:
			if climbing:
				pos.append(curr_pos)
				peaks.append(curr_peak)
				climbing = False
			(curr_pos, curr_peak) = (index, value)
	return {'pos': pos, 'peaks': peaks}


def pick_peaks(nums):
	pp_dict = {'pos': [], 'peaks': []}
	size = len(nums)
	i = 1
	for i in range(1, size - 1):
		if nums[i] > nums[i - 1]:
			plateau_start = i
			try:
				while nums[i] == nums[i + 1]:
					i += 1
				if nums[i] > nums[i + 1]:
					pp_dict['pos'].append(plateau_start)
					pp_dict['peaks'].append(nums[plateau_start])
			except LookupError:
				break
	return pp_dict


def pick_peaks(arr):
	coords = {'pos': [i for i in range(1, len(arr) - 1) if arr[i - 1] < arr[i] > arr[[x for x in range(i, len(arr)) if arr[x] != arr[i] or x == len(arr) - 1][0]]]}
	coords.update({'peaks': [arr[elem] for elem in coords.get('pos')]})
	return coords


def pick_peaks(arr):
	ppos = [i for (i, x) in enumerate(arr) if i == 0 or arr[i - 1] != arr[i]]
	pos = [ppos[i] for i in range(1, len(ppos) - 1) if arr[ppos[i]] > arr[ppos[i - 1]] and arr[ppos[i]] > arr[ppos[i + 1]]]
	return {'pos': pos, 'peaks': [arr[i] for i in pos]}


def pick_peaks(arr):
	(maximas, positions) = ([], [])
	for (i, num) in enumerate(arr):
		same_as_num = [x == num for x in arr[i:]]
		end = not all(same_as_num) and i + same_as_num.index(False) - 1
		local_max = end and num > arr[i - 1] and (num > arr[end + 1])
		if not (i == 0 or i == len(arr) - 1) and local_max:
			maximas.append(arr[i])
			positions.append(i)
	return {'pos': positions, 'peaks': maximas}


def pick_peaks(arr):
	pos = []
	for i in range(1, len(arr) - 1):
		next_i = next((n for (n, v) in enumerate(arr[i:]) if v != arr[i]), None)
		if arr[i - 1] < arr[i] and next_i and (arr[i] > arr[i:][next_i]):
			pos.append(i)
	return {'pos': pos, 'peaks': [arr[po] for po in pos]}


def next_different_value(arr, index):
	next_index = index + 1
	while arr[index] == arr[next_index] and next_index != len(arr) - 1:
		next_index += 1
	return arr[index] > arr[next_index]

def pick_peaks(arr):
	res = {'pos': [], 'peaks': []}
	if len(arr) < 3:
		return res

	def fill_res(pos, peaks):
		res['pos'].append(pos)
		res['peaks'].append(peaks)
	for (index, value) in enumerate(arr):
		if index not in [0, len(arr) - 1]:
			if arr[index] > arr[index - 1] and next_different_value(arr, index):
				fill_res(index, value)
	return res


def pick_peaks(arr):
	p = []
	z = []
	res = {'pos': [], 'peaks': []}
	for (i, k) in enumerate(arr[1:-1]):
		if k > arr[i] and k > arr[i + 2]:
			p.append(i + 1)
			z.append(k)
		elif k == arr[i + 2] and k > arr[i]:
			n = 1
			while True:
				n += 1
				if k != arr[i + n] or i + n == len(arr) - 1:
					break
			if k > arr[i + n]:
				p.append(i + 1)
				z.append(k)
	res['pos'] = p
	res['peaks'] = z
	return res


def pick_peaks(arr):
	out = {}
	(i, wait_pick, temp_pick) = (1, 0, 0)
	while i < len(arr) - 1:
		if arr[i] == arr[i + 1] and arr[i] > arr[i - 1]:
			temp_pick = i
			wait_pick = 1
			i += 1
			continue
		if wait_pick == 1:
			if arr[i] > arr[i + 1]:
				out[temp_pick] = arr[temp_pick]
				wait_pick = 0
			elif arr[i] < arr[i + 1]:
				wait_pick = 0
			i += 1
		else:
			if arr[i] > arr[i - 1] and arr[i] > arr[i + 1]:
				out[i] = arr[i]
			i += 1
	return {'pos': list(out.keys()), 'peaks': list(out.values())}


def pick_peaks(arr):
	pos = []
	peaks = []
	i = 1
	while i < len(arr) - 1:
		if arr[i - 1] < arr[i] and arr[i] > arr[i + 1]:
			pos.append(i)
			peaks.append(arr[i])
		elif arr[i - 1] < arr[i] < arr[i + 1]:
			pass
		elif arr[i - 1] < arr[i]:
			if i < len(arr):
				for j in range(i, len(arr) - 1):
					if arr[j] == arr[j + 1]:
						continue
					elif arr[j] < arr[j + 1]:
						i = j - 1
						break
					elif arr[j] > arr[j + 1]:
						pos.append(i)
						peaks.append(arr[i])
						i = j - 1
						break
		i += 1
	return {'pos': pos, 'peaks': peaks}


def pick_peaks(a):
	(po, pe) = ('pos', 'peaks')
	d = {po: [], pe: []}
	for n in range(2, len(a)):
		(b, P, e) = (n - 2, n - 1, n)
		if a[b] < a[P] >= a[e]:
			if len(a[P:]) != a[P:].count(a[P]):
				if max(a[P:]) >= a[P]:
					if d[po]:
						if min(a[d[po][-1]:P]) >= d[pe][-1]:
							d[po] = d[po][:-1]
							d[pe] = d[pe][:-1]
					d[po].append(P)
					d[pe].append(a[P])
	return d


def pick_peaks(array):
	(peaks, pos) = ([], [])
	platpos = platpeaks = ''
	for i in range(1, len(array) - 1):
		if array[i - 1] < array[i] > array[i + 1]:
			(peaks.append(array[i]), pos.append(i))
		elif array[i - 1] < array[i] == array[i + 1]:
			(platpos, platpeaks) = (i, array[i])
		elif array[i - 1] == array[i] > array[i + 1] and platpos != '':
			(pos.append(platpos), peaks.append(platpeaks))
	return {'pos': pos, 'peaks': peaks}


def pick_peaks(arr):
	peaks = []
	pos = []
	i = 0
	clean = list(arr)
	while i < len(clean) - 1:
		if i == 0 or i == len(clean) - 1:
			i = i + 1
			pass
		else:
			c = 1
			while clean[i] == clean[i + c] and i + c < len(clean) - 1:
				c = c + 1
			if clean[i] > clean[i - 1] and clean[i] > clean[i + c]:
				peaks.append(clean[i])
				pos.append(i)
			i = i + c
	return {'pos': pos, 'peaks': peaks}


def pick_peaks(arr):
	peak = []
	pos = []
	prev = 0
	growing = False
	for i in range(1, len(arr)):
		if arr[prev] > arr[i] and growing:
			peak.append(arr[prev])
			pos.append(prev)
			growing = False
		elif arr[prev] < arr[i]:
			growing = True
		if arr[prev] == arr[i]:
			prev = prev
		else:
			prev = i
	return {'pos': pos, 'peaks': peak}


def pick_peaks(arr):
	pos = []
	peaks = []
	for (x, num) in enumerate(arr):
		if x == 0 or x == len(arr) - 1:
			continue
		if arr[x - 1] < num and arr[x + 1] < num:
			pos.append(x)
			peaks.append(num)
		elif arr[x - 1] < num and arr[x + 1] == num:
			i = x
			plateau = True
			while plateau:
				i += 1
				try:
					if arr[i] < num:
						pos.append(x)
						peaks.append(num)
						plateau = False
					elif arr[i] > num:
						plateau = False
				except IndexError:
					plateau = False
	return {'pos': pos, 'peaks': peaks}


def pick_peaks(arr):
	pos = []
	peaks = []
	i = 1
	while i < len(arr) - 1:
		if arr[i - 1] < arr[i]:
			j = i + 1
			while j < len(arr):
				print(arr[i], arr[j])
				if arr[i] > arr[j]:
					pos.append(i)
					peaks.append(arr[i])
					break
				elif arr[i] == arr[j]:
					j += 1
				else:
					break
		i += 1
	return {'pos': pos, 'peaks': peaks}


from itertools import groupby

def pick_peaks(arr):
	start = 0
	sequence = []
	for (key, group) in groupby(arr):
		sequence.append((key, start))
		start += sum((1 for element in group))
	peaks = []
	pos = []
	for ((b, bi), (m, mi), (a, ai)) in zip(sequence, sequence[1:], sequence[2:]):
		if b < m and a < m:
			pos.append(mi)
			peaks.append(m)
	result = {}
	result['pos'] = pos
	result['peaks'] = peaks
	return result


def pick_peaks(arr):
	real = [arr[x] for x in range(len(arr) - 1) if arr[x] != arr[x + 1]]
	track = [x for x in range(len(arr) - 1) if arr[x] == arr[x + 1]]
	if real:
		real.append(arr[-1])
	pos = [x for x in range(1, len(real) - 1) if real[x] > real[x - 1] and real[x] > real[x + 1]]
	posn = [x + 1 for x in range(1)]
	peak = [real[x] for x in range(1, len(real) - 1) if real[x] > real[x - 1] and real[x] > real[x + 1]]
	new = []
	count = 0
	a = 0
	for i in range(len(real)):
		if arr[i + count] != real[i]:
			skip = 0
			while arr[i + count] != real[i]:
				count += 1
				skip += 1
			if new:
				new.append([i + new[-1][1], skip])
			else:
				new.append([i, skip])
	for j in range(len(new)):
		for k in range(len(pos)):
			if pos[k] >= new[j][0]:
				pos[k] = pos[k] + new[j][1]
	total = {'pos': pos, 'peaks': peak}
	return total


def pick_peaks(arr):
	pos = []
	peaks = []
	plateau = []
	numbers = len(arr)
	print('length of array: ' + str(numbers))
	print('list:')
	print(arr)
	for number in range(numbers):
		if number == 0 or number == numbers - 1:
			pass
		else:
			candidate = arr[number]
			pre = arr[number - 1]
			post = arr[number + 1]
			if candidate > pre and candidate > post:
				pos.append(number)
				peaks.append(candidate)
			elif number == 1 or number == numbers - 2:
				pass
			elif candidate > pre and candidate == post:
				if candidate >= arr[number + 2] and number != number - 1 and (candidate != arr[numbers - 1]):
					pos.append(number)
					peaks.append(candidate)
				else:
					pass
	print('plateau:')
	print(plateau)
	answer = {}
	answer['pos'] = pos
	answer['peaks'] = peaks
	print(answer)
	return answer


def pick_peaks(arr):
	start = 0
	sequence = []
	(ind, val) = ([], [])
	posPeaks = {'pos': [], 'peaks': []}
	from itertools import groupby
	for (key, group) in groupby(arr):
		sequence.append((key, start))
		start += sum((1 for _ in group))
	for ((b, bi), (m, mi), (a, ai)) in zip(sequence, sequence[1:], sequence[2:]):
		if b < m and a < m:
			ind.append(mi)
			val.append(m)
	posPeaks['pos'] = ind
	posPeaks['peaks'] = val
	return posPeaks


def pick_peaks(arr):
	result = {'pos': [], 'peaks': []}
	for i in range(1, len(arr) - 1):
		if arr[i] > arr[i - 1] and arr[i] > arr[i + 1]:
			result['pos'].append(i)
			result['peaks'].append(arr[i])
		elif arr[i] > arr[i - 1] and arr[i] == arr[i + 1]:
			for k in range(i + 2, len(arr)):
				if arr[i] > arr[k]:
					result['pos'].append(i)
					result['peaks'].append(arr[i])
					break
				elif arr[k] > arr[i]:
					break
	return result


def pick_peaks(arr):
	result = []
	resultIndex = []
	for element in range(len(arr)):
		if element > 0 and element != len(arr) - 1:
			if arr[element] > arr[element - 1] and arr[element] > arr[element + 1]:
				peak = arr[element]
				result.append(peak)
				resultIndex.append(element)
			elif arr[element] > arr[element - 1] and arr[element] == arr[element + 1]:
				curr = arr[element]
				currIndex = element
				for next in range(element + 1, len(arr) - 1):
					if arr[next] > arr[next + 1]:
						result.append(curr)
						resultIndex.append(currIndex)
						break
					elif arr[next] == arr[next + 1]:
						continue
					else:
						break
	return {'pos': resultIndex, 'peaks': result}


def pick_peaks(arr):
	result = {'pos': [], 'peaks': []}
	flagIndex = -1
	for i in range(1, len(arr) - 1):
		if arr[i - 1] < arr[i] > arr[i + 1]:
			result['pos'].append(i)
			result['peaks'].append(arr[i])
		elif arr[i - 1] < arr[i] == arr[i + 1]:
			flagIndex = i
		elif flagIndex != -1:
			if arr[i] > arr[i + 1]:
				result['pos'].append(flagIndex)
				result['peaks'].append(arr[flagIndex])
				flagIndex = -1
			elif arr[i] < arr[i + 1]:
				flagIndex = -1
	return result


def pick_peaks(arr):
	output = {'pos': [], 'peaks': []}
	topPos = 0
	if len(arr) > 0:
		topPeak = arr[0]
		for i in range(1, len(arr)):
			if arr[i] > arr[i - 1]:
				topPos = i
				topPeak = arr[i]
			elif arr[i] < arr[i - 1]:
				if topPos > 0:
					output['pos'].append(topPos)
					output['peaks'].append(topPeak)
					topPos = 0
	return output


def pick_peaks(arr):
	out = {'pos': [], 'peaks': []}
	if len(arr) == 0:
		return out
	last_i = arr[0]
	latest_maxima = None
	latest_maxima_pos = None
	for pos in range(len(arr)):
		i = arr[pos]
		if i > last_i:
			latest_maxima = i
			latest_maxima_pos = pos
		if i < last_i and latest_maxima is not None:
			out['pos'].append(latest_maxima_pos)
			out['peaks'].append(latest_maxima)
			latest_maxima = None
			latest_maxima_pos = None
		last_i = i
	return out


def pick_peaks(arr):
	dict = {'pos': [], 'peaks': []}
	for i in range(1, len(arr) - 1):
		if arr[i - 1] < arr[i] and arr[i] > arr[i + 1]:
			dict['pos'].append(i)
			dict['peaks'].append(arr[i])
		elif arr[i - 1] < arr[i] and arr[i] == arr[i + 1]:
			cur = i + 1
			while cur + 1 < len(arr):
				if arr[cur] > arr[cur + 1]:
					dict['pos'].append(i)
					dict['peaks'].append(arr[i])
					break
				if arr[cur] < arr[cur + 1]:
					break
				cur += 1
	return dict


def pick_peaks(a):
	ind = []
	val = []
	for i in range(1, len(a) - 1):
		if a[i - 1] < a[i] and a[i] > a[i + 1]:
			ind.append(i)
			val.append(a[i])
		elif a[i] > a[i - 1] and a[i] == a[i + 1]:
			for j in range(i + 1, len(a) - 1):
				if a[j] == a[i] and a[j] < a[j + 1]:
					break
				elif a[j] == a[i] and a[j + 1] < a[j]:
					ind.append(i)
					val.append(a[i])
					break
	return {'pos': ind, 'peaks': val}


def pick_peaks(arr):
	local_peaks = {'pos': [], 'peaks': []}
	count = 1
	length = len(arr)
	while count < length - 1:
		value = arr[count]
		add_node = False
		if value >= arr[count + 1] and value > arr[count - 1]:
			if value == arr[count + 1]:
				for i in range(2, length - count):
					if arr[count + i] > value:
						break
					elif arr[count + i] < value:
						add_node = True
			else:
				add_node = True
		if add_node:
			local_peaks['pos'].append(count)
			local_peaks['peaks'].append(value)
		count += 1
	return local_peaks


def pick_peaks(arr):
	l = []
	t = []
	for i in range(len(arr) - 2):
		if arr[i + 1] > arr[i]:
			k = 0
			while k + i + 1 < len(arr):
				if arr[k + i + 1] > arr[i + 1]:
					break
				if arr[k + i + 1] < arr[i + 1]:
					l.append(arr[i + 1])
					t.append(i + 1)
					break
				k = k + 1
	return {'pos': t, 'peaks': l}


def pick_peaks(a):
	pos = []
	try:
		for k in range(1, len(a) - 1):
			if a[k] > a[k - 1] and a[k] > a[k + 1]:
				pos.append(k)
			elif a[k] > a[k - 1] and a[k] == a[k + 1]:
				i = k + 2
				while i < len(a) - 1 and a[i] == a[k]:
					i += 1
				if a[i] < a[k]:
					pos.append(k)
				else:
					k = i
		peaks = [a[i] for i in pos]
		return {'pos': pos, 'peaks': peaks}
	except IndexError:
		print(a)
		print('i=', i)


def pick_peaks(arr):
	d = {'pos': [], 'peaks': []}
	i = 0
	print(arr)
	if len(arr) > 2 and arr[0] >= arr[1]:
		while arr[i] >= arr[i + 1] and i < len(arr) - 2:
			i += 1
	while i < len(arr) - 1:
		if arr[i] < arr[i + 1]:
			pass
		elif arr[i] == arr[i + 1]:
			temp = i
			while arr[i] == arr[i + 1] and i < len(arr) - 2:
				i += 1
			if arr[i] > arr[i + 1]:
				d['pos'].append(temp)
				d['peaks'].append(arr[temp])
				while arr[i] >= arr[i + 1] and i < len(arr) - 2:
					i += 1
		else:
			d['pos'].append(i)
			d['peaks'].append(arr[i])
			while arr[i] >= arr[i + 1] and i < len(arr) - 2:
				i += 1
		i += 1
	return d


def pick_peaks(arr):
	a_1 = []
	a_2 = []
	result_ab = {'pos': a_1, 'peaks': a_2}
	for i in range(0, len(arr) - 1):
		if i != 0 and i != len(arr) - 1:
			if arr[i] > arr[i - 1] and arr[i] > arr[i + 1]:
				a_1.append(i)
				a_2.append(arr[i])
			elif arr[i] > arr[i - 1] and arr[i] == arr[i + 1]:
				copy_arr = arr[:]
				while copy_arr[i] == copy_arr[i + 1]:
					del copy_arr[i + 1]
					if i != len(copy_arr) - 1:
						if copy_arr[i] > copy_arr[i + 1]:
							a_1.append(i)
							a_2.append(arr[i])
							break
						elif copy_arr[i] == copy_arr[i + 1]:
							continue
						else:
							break
					else:
						break
			else:
				pass
		else:
			pass
	return result_ab


def isPeak(arr, pos):
	if pos == 0 or pos == len(arr) - 1:
		return False
	if arr[pos - 1] >= arr[pos]:
		return False
	for nextElem in arr[pos + 1:]:
		if nextElem > arr[pos]:
			return False
		if nextElem < arr[pos]:
			return True

def pick_peaks(arr):
	result = {'pos': [], 'peaks': []}
	for (pos, val) in enumerate(arr):
		if isPeak(arr, pos):
			result['pos'].append(pos)
			result['peaks'].append(val)
	return result


def pick_peaks(arr):
	out = {}
	pos = []
	peaks = []
	temp = []
	for (i, x) in enumerate(arr[1:-1], start=1):
		prev = arr[i - 1]
		nxt = arr[i + 1]
		if x > prev:
			temp = [i, x]
		if x < prev and temp or (x > nxt and temp):
			pos.append(temp[0])
			peaks.append(temp[1])
			temp.clear()
	out['pos'] = pos
	out['peaks'] = peaks
	return out


from itertools import groupby

def pick_peaks(arr):
	result = {'pos': [], 'peaks': []}
	if not arr:
		return result
	arr = dict(enum((list(j) for (i, j) in groupby(arr))))
	keys = sorted(arr.keys())
	for i in arr:
		if i != keys[0] and i != keys[-1]:
			curr = arr[i][0]
			prev = arr[keys[keys.index(i) + 1]][0]
			post = arr[keys[keys.index(i) - 1]][0]
			if curr > post and curr > prev:
				result['pos'] = result['pos'] + [i]
				result['peaks'] = result['peaks'] + [arr[i][0]]
	return result

def enum(listA):
	value = 0
	for j in listA:
		if len(j) == 1:
			yield (value, j)
			value += 1
		else:
			yield (value, j)
			value += len(j)


def pick_peaks(arr):
	obj = {'pos': [], 'peaks': []}
	if len(arr) == 0:
		return obj
	upward = True if arr[0] < arr[1] else False
	pos = 1
	plateau = 0
	while pos < len(arr) - 1:
		if upward:
			if arr[pos] == arr[pos + 1]:
				plateau += 1
			elif arr[pos] > arr[pos + 1] and arr[pos] >= arr[pos - 1]:
				obj['pos'].append(pos - plateau)
				obj['peaks'].append(arr[pos])
				upward = False
				plateau = 0
			else:
				plateau = 0
			pos += 1
		else:
			if arr[pos] < arr[pos + 1]:
				upward = True
			pos += 1
	return obj


def pick_peaks(arr):
	a = []
	b = []
	for i in range(1, len(arr) - 1):
		for l in range(i, len(arr) - 1):
			if arr[l + 1] > arr[i]:
				break
			if arr[l + 1] < arr[i]:
				if arr[i - 1] < arr[i] and arr[i + 1] <= arr[i]:
					a.append(i)
					b.append(arr[i])
					break
	return {'pos': a, 'peaks': b}


def pick_peaks(arr):
	(pos, peaks) = ([], [])
	for i in range(len(arr) - 2):
		(a, b, c) = list(range(i, i + 3))
		if pos and peaks[-1] == arr[b]:
			condition = True
			for i in range(pos[-1], b):
				condition = condition and arr[i] == arr[b]
			if condition is True:
				continue
		while arr[a] == arr[b] and a > 0:
			a -= 1
		while arr[b] == arr[c] and c < len(arr) - 1:
			c += 1
		if arr[a] < arr[b] and arr[b] > arr[c]:
			pos += [b]
			peaks += [arr[b]]
	return {'pos': pos, 'peaks': peaks}


def pick_peaks(arr):
	peaks = {'peaks': [], 'pos': []}
	if len(arr) == 0:
		return peaks
	p = min(arr)
	pos = 0
	for i in range(2, len(arr)):
		if arr[i - 1] > arr[i - 2] and arr[i - 1] >= arr[i]:
			p = arr[i - 1]
			pos = i - 1
		if arr[i] < p:
			peaks['peaks'].append(p)
			peaks['pos'].append(pos)
			p = min(arr)
			pos = 0
	return peaks


def pick_peaks(arr):
	pos = []
	peaks = []
	if len(arr) > 0:
		n = 0
		peak_start = 0
		curr_height = arr[0]
		is_descending = True
		for p in arr:
			if p > curr_height:
				is_descending = False
				curr_height = p
				peak_start = n
			elif p == curr_height:
				pass
			elif p < curr_height:
				if not is_descending:
					pos.append(peak_start)
					peaks.append(curr_height)
				is_descending = True
				curr_height = p
			else:
				raise Error
			n += 1
	return {'pos': pos, 'peaks': peaks}


def pick_peaks(arr):
	posPeaks = {'pos': [], 'peaks': []}
	for i in range(1, len(arr) - 1):
		if arr[i] > arr[i - 1]:
			if arr[i] > arr[i + 1]:
				posPeaks['pos'].append(i)
				posPeaks['peaks'].append(arr[i])
			if arr[i] == arr[i + 1]:
				for x in range(i + 2, len(arr)):
					if arr[x] < arr[i]:
						posPeaks['pos'].append(i)
						posPeaks['peaks'].append(arr[i])
						break
					if arr[x] > arr[i]:
						break
	return posPeaks


def pick_peaks(arr):
	ans = {'pos': [], 'peaks': []}
	for i in range(1, len(arr) - 1):
		start = None
		end = None
		if arr[i - 1] == arr[i]:
			for x in range(i, 0, -1):
				while arr[i - x] != arr[i]:
					start = i - x + 1
					break
		if arr[i + 1] == arr[i]:
			for y in range(i, len(arr) - 1):
				if arr[y] != arr[i]:
					end = y - 1
					break
				else:
					end = y
		if start == None:
			start = i
		if end == None:
			end = i
		if arr[start - 1] < arr[start] and arr[end + 1] < arr[end]:
			if start not in ans['pos']:
				ans['pos'].append(start)
				ans['peaks'].append(arr[start])
	return ans


import operator

def pick_peaks(arr):
	pos = []
	peaks = []
	if len(arr) < 3:
		return {'pos': [], 'peaks': []}
	diff = list(map(operator.sub, arr[1:], arr[:-1]))
	for i in range(len(diff) - 1, 0, -1):
		if diff[i - 1] == 0:
			diff[i - 1] = diff[i]
	is_peak = lambda a, b: 1 if a * b < 0 and a > b else 0
	muld = list(map(is_peak, diff[:-1], diff[1:]))
	pos = [i + 1 for (i, v) in enumerate(muld) if v == 1]
	for i in pos:
		peaks.append(arr[i])
	return {'pos': pos, 'peaks': peaks}


def pick_peaks(arr):
	pospeaks = {'pos': [], 'peaks': []}
	for i in range(1, len(arr) - 1):
		lowerbefore = arr[i - 1] < arr[i]
		lowerafter = False
		for j in arr[i:]:
			if j == arr[i]:
				continue
			elif j < arr[i]:
				lowerafter = True
				break
			elif j > arr[i]:
				break
		if lowerbefore and lowerafter:
			pospeaks['pos'].append(i)
			pospeaks['peaks'].append(arr[i])
	return pospeaks


def pick_peaks(lst):
	res = {'pos': [], 'peaks': []}
	idx = 0
	for i in range(1, len(lst) - 1):
		if lst[i] != lst[idx]:
			idx = i
		if idx and lst[idx - 1] < lst[idx] > lst[i + 1]:
			res['pos'].append(idx)
			res['peaks'].append(lst[idx])
	return res


def pick_peaks(arr):
	dict = {'pos': [], 'peaks': []}
	for i in range(1, len(arr) - 1):
		if arr[i] > arr[i - 1] and arr[i] >= arr[i + 1]:
			add = True
			if arr[i] == arr[i + 1]:
				j = i
				done = False
				while j < len(arr) and add and (not done):
					if arr[j] > arr[i]:
						add = False
					elif arr[j] < arr[i]:
						done = True
					j += 1
				if not done:
					add = False
			if add:
				dict['pos'].append(i)
				dict['peaks'].append(arr[i])
	return dict


def pick_peaks(arr):
	pos = []
	peaks = []
	n = 0
	for i in range(1, len(arr) - 1):
		if arr[i] > arr[i - 1] and arr[i] > arr[i + 1]:
			pos.append(i)
			peaks.append(arr[i])
		elif arr[i] > arr[i - 1] and arr[i] == arr[i + 1]:
			n = 0
			for j in range(i + 1, len(arr)):
				if arr[j] == arr[i]:
					n += 1
				else:
					break
			if i + n + 1 < len(arr) and arr[i + n + 1] < arr[i]:
				pos.append(i)
				peaks.append(arr[i])
	return {'pos': pos, 'peaks': peaks}


def pick_peaks(arr):
	print('input:{}'.format(arr))
	if len(arr) < 1:
		return {'pos': [], 'peaks': []}
	UP = 0
	DOWN = 1
	FLAT = 2
	trends = ['UP', 'DOWN', 'FLAT']
	if arr[0] == arr[1]:
		trend = FLAT
	elif arr[0] > arr[1]:
		trend = DOWN
	else:
		trend = UP
	prev = arr[0]
	pos = []
	peaks = []
	local_max = None
	for i in range(1, len(arr)):
		if trend == UP:
			if arr[i] == prev:
				trend = FLAT
				local_max = i - 1
			elif arr[i] < prev:
				trend = DOWN
				pos.append(i - 1)
				peaks.append(prev)
		elif trend == DOWN:
			if arr[i] == prev:
				trend = FLAT
				local_max = None
			elif arr[i] > prev:
				trend = UP
		elif trend == FLAT:
			if arr[i] > prev:
				trend = UP
			elif arr[i] < prev:
				if local_max != None:
					pos.append(local_max)
					peaks.append(prev)
				trend = DOWN
		prev = arr[i]
	if trend == FLAT:
		pos = pos[0:]
		peaks = peaks[0:]
	return {'pos': pos, 'peaks': peaks}


def pick_peaks(arr):
	res = {'pos': [], 'peaks': []}
	flag = False
	for i in range(1, len(arr) - 1):
		if flag:
			if arr[i] == arr[i + 1]:
				continue
			elif arr[i] > arr[i + 1]:
				res['pos'].append(temp)
				res['peaks'].append(arr[i])
				flag = False
			else:
				flag = False
		elif arr[i] > arr[i - 1]:
			if arr[i] > arr[i + 1]:
				res['pos'].append(i)
				res['peaks'].append(arr[i])
			elif arr[i] == arr[i + 1]:
				temp = i
				flag = True
	return res


def pick_peaks(arr):
	r = {'pos': [], 'peaks': []}
	state = 'none'
	c = 1
	for i in range(1, len(arr)):
		if arr[i] > arr[i - 1]:
			state = 'up'
		elif arr[i] == arr[i - 1]:
			if state == 'still':
				c += 1
			if state == 'up':
				state = 'still'
		elif arr[i] < arr[i - 1]:
			if state == 'up':
				r['pos'].append(i - 1)
				r['peaks'].append(arr[i - 1])
			elif state == 'still':
				r['pos'].append(i - c - 1)
				r['peaks'].append(arr[i - c - 1])
			state = 'down'
	return r


def pick_peaks(arr):
	pos = []
	peaks = []
	if arr:
		cur = arr[0]
		cur_pos = 0
		for i in range(1, len(arr)):
			if arr[i] > arr[i - 1]:
				cur = arr[i]
				cur_pos = i
			elif arr[i] < cur and cur_pos != 0:
				pos.append(cur_pos)
				peaks.append(cur)
				cur_pos = 0
	return {'pos': pos, 'peaks': peaks}


def pick_peaks(arr):
	(pos, peaks) = ([], [])
	for i in range(1, len(arr) - 1):
		if arr[i] >= arr[i + 1]:
			k = i
			while k < len(arr) - 2 and arr[k] == arr[k + 1]:
				k += 1
			if arr[i - 1] < arr[i] and arr[i] > arr[k + 1]:
				pos.append(i)
				peaks.append(arr[i])
	return {'pos': pos, 'peaks': peaks}


def pick_peaks(arr):
	out = {'pos': [], 'peaks': []}
	for i in range(1, len(arr) - 1):
		plateau_idx = i + 1
		if arr[i - 1] < arr[i] == arr[i + 1]:
			while plateau_idx < len(arr):
				if arr[plateau_idx] == arr[i]:
					plateau_idx += 1
				else:
					break
		if plateau_idx < len(arr) and arr[i - 1] < arr[i] > arr[plateau_idx]:
			out['pos'].append(i)
			out['peaks'].append(arr[i])
	return out


def pick_peaks(a):
	previous = 0
	current = 0
	pos = []
	peaks = []
	for next in range(1, len(a)):
		if a[next] > a[current]:
			previous = current
			current = next
		elif a[next] < a[current]:
			if a[previous] < a[current]:
				pos.append(current)
				peaks.append(a[current])
			previous = current
			current = next
	return {'pos': pos, 'peaks': peaks}


def pick_peaks(arr):
	pos = []
	peaks = []
	for x in range(len(arr)):
		if x != 0 and x != len(arr) - 1:
			if arr[x] > arr[x - 1] and arr[x] > arr[x + 1]:
				pos.append(x)
				peaks.append(arr[x])
			elif arr[x] > arr[x - 1] and arr[x] >= arr[x + 1]:
				for y in arr[x:]:
					print((y, x, arr[x], arr[x:]))
					if arr[x] > y:
						pos.append(x)
						peaks.append(arr[x])
						break
					elif arr[x] < y:
						break
	return {'pos': pos, 'peaks': peaks}


def pick_peaks(arr):
	pos = []
	peaker = None
	for i in range(1, len(arr)):
		if arr[i - 1] < arr[i]:
			peaker = i
		elif arr[i - 1] > arr[i] and peaker:
			pos.append(peaker)
			peaker = None
	return {'pos': pos, 'peaks': [arr[i] for i in pos]}


def pick_peaks(arr):
	return_dict = {'pos': [], 'peaks': []}
	fall = False
	peak = False
	plateaus_after_peak = False
	plateaus = False
	plateaus_pos = 0
	for (position, current) in enumerate(arr):
		if position == 0:
			print(f'[{position}] {current} - START')
		elif position == len(arr) - 1:
			print(f'[{position}] {current} - END')
		else:
			next = arr[position + 1]
			previous = arr[position - 1]
			if previous > current < next:
				fall = True
				peak = False
				plateaus_after_peak = False
				plateaus = False
				print(f'[{position}] {current} - Fell!')
			elif previous > current > next:
				fall = True
				peak = False
				plateaus_after_peak = False
				plateaus = False
				print(f'[{position}] {current} - Falling...')
			elif previous < current < next:
				fall = False
				peak = False
				plateaus_after_peak = False
				plateaus = False
				print(f'[{position}] {current} - Rising...')
			elif previous < current == next:
				fall = False
				peak = True
				plateaus_after_peak = False
				plateaus = True
				plateaus_pos = position
				print(f'[{position}] {current} - Plateaus start!')
			elif previous == current > next:
				if position == 1:
					print(f'[{position}] {current} - End of starting plateaus!')
				elif position != 1 and position != len(arr) - 2:
					if plateaus_after_peak:
						fall = True
						peak = False
						plateaus_after_peak = False
						plateaus = False
						print(f'[{position}] {current} - Plateus End after peak - Falling...')
					else:
						fall = True
						peak = False
						plateaus_after_peak = False
						plateaus = False
						print(f'[{position}] {current} - End of plateaus! Falling, saving the start of plateaus!')
						return_dict['pos'].append(plateaus_pos)
						return_dict['peaks'].append(current)
				elif position == len(arr) - 2 and current > next and (not plateaus_after_peak):
					fall = True
					peak = False
					plateaus_after_peak = False
					plateaus = False
					print(f'[{position}] {current} - End of plateaus! Falling, saving the start of plateaus!')
					return_dict['pos'].append(plateaus_pos)
					return_dict['peaks'].append(current)
			elif previous > current == next:
				fall = False
				peak = False
				plateaus_after_peak = True
				plateaus = True
				print(f'[{position}] {current} - Plateus start after a peak!')
			elif previous < current > next:
				fall = False
				peak = True
				plateaus_after_peak = False
				plateaus = False
				print(f'[{position}] {current} - Its a peak! Saving')
				return_dict['pos'].append(position)
				return_dict['peaks'].append(current)
			elif previous == current == next:
				fall = False
				plateaus = True
				print(f'[{position}] {current} - Plateus Flat!')
			elif previous == current < next:
				if plateaus_after_peak:
					fall = True
					peak = False
					plateaus_after_peak = False
					plateaus = False
					print(f'[{position}] {current} - Plateus End after peak - Rising...')
			elif plateaus:
				if position + 1 == len(arr) - 1:
					if not plateaus_after_peak:
						fall = False
						peak = True
						plateaus_after_peak = False
						plateaus = False
						print(f'[{position}] {current} - Plateus Before End')
						return_dict['pos'].append(plateaus_pos)
						return_dict['peaks'].append(current)
					else:
						print(f'[{position}] {current} - X1!')
				else:
					print(f'[{position}] {current} - X2!')
			else:
				print(f'[{position}] {current} - OUTSIDE!')
	return return_dict


def pick_peaks(arr):
	pos = []
	peak = []
	peaking = False
	platu = None
	for (count, item) in enumerate(arr):
		try:
			if arr[count] < arr[count + 1]:
				peaking = True
				platu = None
			elif arr[count] == arr[count + 1] and peaking:
				platu = count
				peaking = False
			elif peaking:
				pos.append(count)
				peak.append(item)
				peaking = False
			elif platu and arr[count + 1] > arr[count]:
				platu = None
				peaking = True
			elif platu and arr[count + 1] < arr[count]:
				pos.append(platu)
				peak.append(arr[platu])
				platu = None
				peaking = False
			else:
				pass
		except IndexError:
			break
	return {'pos': pos, 'peaks': peak}


def pick_peaks(arr):
	dct = {'pos': [], 'peaks': []}
	for i in range(1, len(arr) - 1):
		if arr[i - 1] < arr[i] and arr[i] > arr[i + 1]:
			dct['pos'].append(i)
	plateau_peak(arr, dct)
	dct['pos'].sort()
	dct['peaks'] = [arr[x] for x in dct['pos']]
	return dct

def plateau_peak(arr, dct):
	last = 0
	for i in range(1, len(arr) - 1):
		if arr[i] == arr[i + 1]:
			continue
		elif arr[i] > arr[i + 1] and arr[i] == arr[i - 1] and (arr[i] > arr[last]):
			dct['pos'].append(last + 1)
			last = i
		else:
			last = i


def pick_peaks(arr):
	if not arr:
		return {'pos': [], 'peaks': []}
	else:
		peak_pos = []
		peak_value = []
		value = 0
		for i in range(1, len(arr) - 1):
			if arr[i - 1] < arr[i] and arr[i + 1] < arr[i]:
				peak_pos.append(i)
				peak_value.append(arr[i])
			if arr[i - 1] < arr[i] and arr[i + 1] == arr[i]:
				for j in range(i + 1, len(arr)):
					if arr[j] < arr[i]:
						peak_pos.append(i)
						peak_value.append(arr[i])
						print(('value added', i, j))
						break
					if arr[j] > arr[i]:
						break
		return {'pos': peak_pos, 'peaks': peak_value}


def check(arr, n):
	for num in arr:
		if num < n:
			return True
		elif num > n:
			return False
	return False

def pick_peaks(arr):
	data = {'pos': [], 'peaks': []}
	for (i, n) in enumerate(arr[1:-1], 1):
		if arr[i - 1] < n >= arr[i + 1] and check(arr[i:], n):
			data['pos'] += [i]
			data['peaks'] += [n]
	return data


def pick_peaks(arr):
	pos = []
	peaks = []
	local_max = 0
	for i in range(1, len(arr) - 1):
		if arr[i - 1] < arr[i]:
			local_max = i
		if arr[i - 1] <= arr[i] > arr[i + 1] and local_max not in pos and (local_max != 0):
			pos.append(local_max)
			peaks.append(arr[local_max])
	return {'pos': pos, 'peaks': peaks}


def pick_peaks(arr):
	pos = list()
	peaks = list()
	j = 0
	for i in range(1, len(arr) - 1):
		if arr[i - 1] < arr[i] and arr[i + 1] < arr[i]:
			pos.append(i)
			peaks.append(arr[i])
		elif arr[i - 1] < arr[i] and arr[i] == arr[i + 1] and (i + 1 < len(arr) - 1):
			pos.append(i)
			peaks.append(arr[i])
			j = 1
		elif j == 1 and (arr[i - 1] == arr[i] and arr[i] < arr[i + 1] or (arr[i] == arr[i + 1] and i + 1 == len(arr) - 1)):
			pos.pop()
			peaks.pop()
			j = 0
	return {'pos': pos, 'peaks': peaks}


def pick_peaks(arr):
	results = {'pos': [], 'peaks': []}
	for i in range(1, len(arr) - 1):
		if is_peak(arr, i):
			results['pos'].append(i)
			results['peaks'].append(arr[i])
	return results

def get_direction(last, i):
	if i > last:
		return 1
	elif i == last:
		return 0
	else:
		return -1

def is_peak(arr, index):
	result = False
	cur_val = arr[index]
	if get_direction(cur_val, arr[index - 1]) < 0:
		for i in range(index, len(arr)):
			dir = get_direction(cur_val, arr[i])
			if dir < 0:
				result = True
				break
			elif dir > 0:
				result = False
				break
	return result


def pick_peaks(arr):
	result = {'pos': [], 'peaks': []}
	for (pos, val) in enumerate(arr):
		if pos == 0 or pos == len(arr) - 1:
			continue
		if arr[pos + 1] > val:
			continue
		if arr[pos - 1] == val:
			continue
		if arr[pos + 1] == val and arr[pos - 1] < val:
			for i in range(pos + 1, len(arr)):
				if arr[i] == val:
					continue
				elif arr[i] > val:
					break
				else:
					result['pos'].append(pos)
					result['peaks'].append(val)
					break
			continue
		if arr[pos - 1] < val:
			result['pos'].append(pos)
			result['peaks'].append(val)
	return result


def pick_peaks(arr):
	setThis = False
	pos = []
	peaks = []
	print([x for x in range(len(arr))])
	print(arr)
	for i in range(1, len(arr) - 1):
		if arr[i] > arr[i - 1] and arr[i] > arr[i + 1]:
			pos.append(i)
			peaks.append(arr[i])
		elif arr[i] > arr[i - 1] and arr[i] == arr[i + 1]:
			j = i + 1
			while arr[j] == arr[i] and j < len(arr) - 1:
				j += 1
			if j == len(arr) or arr[j] < arr[i]:
				pos.append(i)
				peaks.append(arr[i])
				i = j
	print(pos)
	print(peaks)
	res = {'pos': pos, 'peaks': peaks}
	return res