Practice arena
C++17·2 s·128 MB
LinearFoundation

Serve the queue

Process queue commands in order. PUSH x inserts x, FRONT prints the oldest value without removing it, and POP prints and removes the oldest value. Print EMPTY when FRONT or POP is requested on an empty queue.

Input

  • The first line contains T.
  • Each case starts with q, followed by q commands: PUSH x, FRONT, or POP.

Output

Print the result of every FRONT and POP command on its own line.

Technique

FIFO state simulation

Target

O(1) per command

Constraints & sample
  • 1 ≤ q ≤ 200,000
  • The total number of commands is at most 300,000
  • Values fit in a signed 32-bit integer

Sample input

1
7
PUSH 4
PUSH 9
FRONT
POP
FRONT
POP
POP

Expected output

4
4
9
9
EMPTY
Review the concept

Before you submit

  • Test the smallest valid input and one awkward edge case.
  • Keep the solution within O(1) per command.
  • Match spacing and line breaks exactly before checking 13 hidden cases.
main.cpp
Draft saved locally · 668 / 30,000
Ln 1, Col 1Spaces: 4UTF-8LFC++17

Visible testcases

Editable and stored only in this browser. Hidden judge cases never change.

Checking your session…

Run checks Sample · Submit checks 13 hidden cases

Run the sample first, then send your solution through 13 hidden cases.

Code runs in an isolated Judge0 environment. Drafts and custom visible cases stay on this device; submission metadata and progress sync to MongoDB.