Simulate a queue at a counter. join NAME adds a person to the back; serve serves the person at the front and prints their name, or prints EMPTY if nobody is waiting.
What to build
A queue that follows commands.
Requirements
join NAMEadds to the back.serveprints the name at the front, orEMPTY.
Input
The first line has n (1 to 1000). Each of the next n lines is join NAME or serve.
Output
One line for each serve command.
Constraints
n is from 1 to 1000.
Example
Input:
4
join Rahim
join Nadia
serve
serve
Output:
Rahim
Nadia
Why it works
A deque adds at one end and removes at the other, each in constant time, which matches how a real line works.
Examples
Example 1 · Input
4 join Rahim join Nadia serve serve
Expected output
Rahim Nadia
Example 2 · Input
1 serve
Expected output
EMPTY
Prompts inside input() are ignored when checking, so input("n: ") is fine.
Hints
Hint 1
queue.append(name) joins the back; queue.popleft() serves the front.
Hint 2
Check if queue: before serving.
Solution
Show one correct solution (try it yourself first)
from collections import deque
queue = deque()
n = int(input())
for _ in range(n):
parts = input().split()
if parts[0] == "join":
queue.append(parts[1])
elif queue:
print(queue.popleft())
else:
print("EMPTY")