A wildlife study involving ducks is taking place in North America. Researchers are visiting some wetlands in a certain area taking a survey of what they see. The researchers will submit reports that need to be processed by your function.


## Input

The input for your function will be an array with a list of common duck names along with the counts made by the researchers. The names and counts are separated by spaces in one array element. The number of spaces between the name and the count could vary; but, there will always be at least one. A name may be repeated because a report may be a combination of surveys from different locations.

An example of an input array would be:
```
["Redhead 3", "Gadwall 1", "Smew 4", "Greater Scaup 10", "Redhead 3", "Gadwall 9", "Greater Scaup 15", "Common Eider 6"]
```

## Processing

Your function should change the names of the ducks to a six-letter code according to given rules (see below). The six-letter code should be in upper case. The counts should be summed for a species if it is repeated.


## Output

The final data to be returned from your function should be an array sorted by the species codes and the total counts as integers. The codes and the counts should be individual elements.

An example of an array to be returned (based on the example input array above) would be:
```
["COMEID", 6, "GADWAL", 10, "GRESCA", 25, "REDHEA", 6, "SMEW", 4]
```
The codes are strings in upper case and the totaled counts are integers.


### Special Note

If someone has `"Labrador Duck"` in their list, the whole list should be thrown out as this species has been determined to be extinct. The person who submitted the list is obviously unreliable. Their lists will not be included in the final data. In such cases, return an array with a single string element in it: `"Disqualified data"`


Rules for converting a common name to a six-letter code:

* Hyphens should be considered as spaces.
* If a name has only one word, use the first six letters of the name. If that name has less than six letters, use what is there.
* If a name has two words, take the first three letters of each word.
* If a name has three words, take the first two letters of each word.
* If a name has four words, take the first letters from the first two words, and the first two letters from the last two words.

Difficulty: EASY
Starter code: def create_report(names):
	

Solutions:
def create_report(names):
	result = {}
	for name in names:
		if name.startswith('Labrador Duck'):
			return ['Disqualified data']
		name = name.upper().replace('-', ' ').split()
		count = int(name.pop())
		if len(name) == 1:
			code = name[0][:6]
		elif len(name) == 2:
			code = name[0][:3] + name[1][:3]
		elif len(name) == 3:
			code = name[0][:2] + name[1][:2] + name[2][:2]
		elif len(name) == 4:
			code = name[0][0] + name[1][0] + name[2][:2] + name[3][:2]
		if code in result:
			result[code] += count
		else:
			result[code] = count
	return sum([[name, result[name]] for name in sorted(result)], [])


from functools import reduce
from collections import defaultdict
import re
FINDER = re.compile('(.+?)\\s+(\\d+)%')
SPLITTER = re.compile('\\s|-')

def create_report(names):
	dct = defaultdict(int)
	for (what, n) in FINDER.findall('%'.join(names) + '%'):
		if what == 'Labrador Duck':
			return ['Disqualified data']
		lst = SPLITTER.split(what)
		key = ''.join((word[:6 // len(lst) + (len(lst) == 4 and i >= 2)] for (i, word) in enumerate(lst))).upper()
		dct[key] += int(n)
	lst = []
	for (k, n) in sorted(dct.items()):
		lst.extend([k, n])
	return lst


from collections import defaultdict
from itertools import chain
import re
p1 = re.compile('(.*?)\\s*(\\d+)')
p2 = re.compile('-| ')

def change(s):
	L = p2.split(s)
	if len(L) == 1:
		return L[0][:6].upper()
	if len(L) == 2:
		return (L[0][:3] + L[1][:3]).upper()
	if len(L) == 3:
		return (L[0][:2] + L[1][:2] + L[2][:2]).upper()
	if len(L) == 4:
		return (L[0][0] + L[1][0] + L[2][:2] + L[3][:2]).upper()
	raise Exception('No rule for more than 4 words')

def create_report(names):
	result = defaultdict(int)
	for data in names:
		(name, num) = p1.match(data).groups()
		if name == 'Labrador Duck':
			return ['Disqualified data']
		result[change(name)] += int(num)
	return list(chain.from_iterable(sorted(result.items())))


bird = lambda w: {4: lambda w: w[0][:1] + w[1][:1] + w[2][:2] + w[3][:2], 3: lambda w: w[0][:2] + w[1][:2] + w[2][:2], 2: lambda w: w[0][:3] + w[1][:3], 1: lambda w: w[0][:6]}[len(w)](w)

def create_report(names):
	D = {}
	for (b, i) in [(bird(' '.join(s.split()[:-1]).upper().replace('-', ' ').split()), int(s.split()[-1])) for s in names]:
		D[b] = D.get(b, 0) + i
	return ['Disqualified data'] if 'LABDUC' in D else [e for b in [[k, D[k]] for k in sorted(D.keys())] for e in b]


from collections import Counter
from itertools import chain

def create_report(names):
	if any((name.startswith('Labrador Duck ') for name in names)):
		return ['Disqualified data']
	counts = Counter()
	for (name, count) in (d.rsplit(None, 1) for d in names):
		counts[code(name)] += int(count)
	return list(chain(*sorted(counts.items())))

def code(name):
	words = name.upper().replace('-', ' ').split(None, 3)
	lengths = [(6,), (3, 3), (2, 2, 2), (1, 1, 2, 2)][len(words) - 1]
	return ''.join((word[:lengths[i]] for (i, word) in enumerate(words)))


import re
create_report = lambda n: (lambda L: ['Disqualified data'] if 'LABDUC' in L else L)([z for v in sorted(((''.join((w[:6 // len(l) + (len(l) == 4 and i >= 2)] for (i, w) in enumerate(l))), sum((b for (_, b) in g))) for (l, g) in __import__('itertools').groupby(sorted(map(lambda x: (re.split('[\\s-]+', x[0].upper()), int(x[1])), map(lambda s: re.findall('(.+?)\\s+(\\d+)', s)[0], n))), key=lambda t: t[0]))) for z in v])


def create_report(a):
	d = {}
	for i in a:
		unique = [j for j in i.replace('-', ' ').split(' ')[:-1] if j]
		curr = [''.join(unique).upper()[:6], ''.join([k[:3] for k in unique]).upper(), ''.join([k[:2] for k in unique]).upper(), ''.join([j[:1] if k in [0, 1] else j[:2] for (k, j) in enumerate(unique)]).upper()][len(unique) - 1]
		d[curr] = d.get(curr, 0) + int(i.split(' ')[-1])
	return ['Disqualified data'] if 'Labrador Duck' in ''.join(a) else sum([[i, d[i]] for i in sorted(d)], [])


def create_report(arr):
	d = {}
	for i in arr:
		if 'Labrador Duck' in i:
			return ['Disqualified data']
		(*s, v) = i.replace('-', ' ').split()
		if len(s) == 4:
			k = s[0][0] + s[1][0] + s[-2][:2] + s[-1][:2]
		elif len(s) == 3:
			k = ''.join((j[:2] for j in s))
		elif len(s) == 2:
			k = ''.join((j[:3] for j in s))
		else:
			k = s[0][:6]
		k = k.upper()
		d.setdefault(k, 0)
		d[k] += int(v)
	r = []
	for k in sorted(d):
		r.extend([k, d.get(k)])
	return r


def create_report(A):
	B = {}
	for a in A:
		if 'Labrador Duck' in a:
			return ['Disqualified data']
		W = a.replace('-', ' ').upper().split()
		(c, L) = (int(W.pop()), len(W))
		n = L == 1 and W[0][:6] or (L == 2 and W[0][:3] + W[1][:3]) or (L == 3 and W[0][:2] + W[1][:2] + W[2][:2]) or W[0][0] + W[1][0] + W[2][:2] + W[3][:2]
		B[n] = B.get(n, 0) + c
	return sum([[k, B[k]] for k in sorted(B)], [])


from collections import defaultdict

def create_report(names):
	data = defaultdict(int)
	for name in names:
		words = name.replace('-', ' ').split()
		number = int(words[-1])
		words = [word.upper() for word in words[:-1] if word]
		if words == ['LABRADOR', 'DUCK']:
			return ['Disqualified data']
		if 1 <= len(words) <= 3:
			code = ''.join((word[:6 // len(words)] for word in words))
		elif len(words) == 4:
			code = words[0][0] + words[1][0] + words[2][:2] + words[3][:2]
		else:
			print(name, 'has', len(words), 'words')
		data[code] += number
	result = []
	for (code, number) in sorted(data.items()):
		result += [code, number]
	return result