# santas_present_factory

Jan 19th, 2022
720
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
1. from collections import deque
2. sample_presents = {150: 'Doll', 250: 'Wooden train', 300: 'Teddy bear', 400: 'Bicycle'}
3.
4. crafted_presents = {}
5.
6. materials_stack = [int(n) for n in input().split()]
7. magic_values = deque([int(n) for n in input().split()])
8.
9. while materials_stack and magic_values:
10.     current_material = materials_stack[-1]
11.     current_magic = magic_values[0]
12.
13.     if current_magic * current_material in sample_presents:
14.         new_present = sample_presents[current_magic * current_material]
15.         materials_stack.pop()
16.         magic_values.popleft()
17.         if new_present not in crafted_presents:
18.             crafted_presents[new_present] = 0
19.         crafted_presents[new_present] += 1
20.     elif current_material * current_magic == 0:
21.         if current_magic == 0 and current_material == 0:
22.             materials_stack.pop()
23.             magic_values.popleft()
24.             continue
25.         elif current_magic == 0:
26.             magic_values.popleft()
27.             continue
28.         else:
29.             materials_stack.pop()
30.             continue
31.     elif current_material * current_magic < 0:
32.         materials_stack.append(magic_values.popleft() + materials_stack.pop())
33.     else:
34.         magic_values.popleft()
35.         materials_stack[-1] += 15
36.
37. if ('Doll' in crafted_presents and 'Wooden train' in crafted_presents) or\
38.         ('Teddy bear' in crafted_presents and 'Bicycle' in crafted_presents):
39.     print("The presents are crafted! Merry Christmas!")
40. else:
41.     print("No presents this Christmas!")
42.
43. if materials_stack:
44.     print(f"Materials left: {', '.join(str(s) for s in reversed(materials_stack))}")
45. if magic_values:
46.     print(f"Magic left: {', '.join(str(s) for s in magic_values)}")
47.
48. for toy, amount in sorted(crafted_presents.items()):
49.     print(f"{toy}: {amount}")
50.
51.
52.