Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from collections import deque
- sample_presents = {150: 'Doll', 250: 'Wooden train', 300: 'Teddy bear', 400: 'Bicycle'}
- crafted_presents = {}
- materials_stack = [int(n) for n in input().split()]
- magic_values = deque([int(n) for n in input().split()])
- while materials_stack and magic_values:
- current_material = materials_stack[-1]
- current_magic = magic_values[0]
- if current_magic * current_material in sample_presents:
- new_present = sample_presents[current_magic * current_material]
- materials_stack.pop()
- magic_values.popleft()
- if new_present not in crafted_presents:
- crafted_presents[new_present] = 0
- crafted_presents[new_present] += 1
- elif current_material * current_magic == 0:
- if current_magic == 0 and current_material == 0:
- materials_stack.pop()
- magic_values.popleft()
- continue
- elif current_magic == 0:
- magic_values.popleft()
- continue
- else:
- materials_stack.pop()
- continue
- elif current_material * current_magic < 0:
- materials_stack.append(magic_values.popleft() + materials_stack.pop())
- else:
- magic_values.popleft()
- materials_stack[-1] += 15
- if ('Doll' in crafted_presents and 'Wooden train' in crafted_presents) or\
- ('Teddy bear' in crafted_presents and 'Bicycle' in crafted_presents):
- print("The presents are crafted! Merry Christmas!")
- else:
- print("No presents this Christmas!")
- if materials_stack:
- print(f"Materials left: {', '.join(str(s) for s in reversed(materials_stack))}")
- if magic_values:
- print(f"Magic left: {', '.join(str(s) for s in magic_values)}")
- for toy, amount in sorted(crafted_presents.items()):
- print(f"{toy}: {amount}")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement