Price of fertilizers in the world are raising! Adding Jinkela in fertilizer, one bag can cover two bags!!
Although Jinkela has been sold for over 10 years, people from America, Africa, Japan are still lining up in a queue to buy it. Each person is given a unique id x. The country of each person can be identified by the remainder of his id divided by 3. If x mod 3 = 0, he is from America; if x mod 3 = 1, he is from Africa; if x mod 3=2, he is from Japan.
Lining up is tedious, everyone wants to cut in line! These American, African, and Japanese follow some rule when they cut in line:
When a person enters the queue,
As old saying goes, "all humans are equal, but some humans are more equal than others." People with id of multiples of five are VIP. VIP enter another special queue instead of the normal one. All VIP are polite and highly educated, so they don't cut in the line.
Every time the supplier provides Jinkela with first person from both normal queue and VIP queue. After a person buys Jinkela, he leaves the queue immediately and will not enter the queue again.
You are curious about the order people get their Jinkela. Given the status of the queue. Whenever someone leaves the queue, output his id. If two people leave at once, output VIP id first and then the normal id.
Refer to the sample IO for example if you don't understand the rule.
For example, assume the queue is empty initially
queue:
VIP queue: 0
queue: 1
VIP queue: 0
queue: 1 3
VIP queue: 0
queue: 1 4 3
VIP queue: 0
queue: 1 4 7 3
VIP queue: 0
queue: 1 4 7 3
VIP queue: 0 10
queue: 1 4 7 3
VIP queue: 0 10 30
queue: 4 7 3
VIP queue: 10 30
output:“0 1”
queue: 7 3
VIP queue: 30
output:“10 4”
queue: 3
VIP queue:
output:“30 7”
queue:
VIP queue:
output:“3”
It is highly recommended to use IO optimization to avoid TLE in this problem.
Before submitting your answer to OJ, add these two lines of codes in the beginning of the main function.
ios_base::sync_with_stdio(false);
cin.tie(0);
We promise that if both queues are empty, no DEQUEUE will happen.
Each line contains one instruction only.
Please keep reading input until reach EOF.
For the first 3 testcases, the number of instructions ≤ 1000.
For the rest of the testcases, the number the number of instructions ≤ 1100000.
For each DEQUEUE command, please output all ids who leave the queue.
Each output occupies a single line with a '\n' at the end of the line.
If two people are leaving at once, output the VIP id first and then the normal id, and seperate them with a single space.
Don’t output a space at the end of the line.