B - Restaurant Queue
Source: atcoder
Difficulty: 200

Problem Statement
Takahashi wants to manage the waiting line in front of the AtCoder Restaurant. Initially, the waiting line is empty. Each person who joins the line holds a meal ticket with the menu number of the dish they will order.
Process
Q
queries in order. There are two types of queries, given in the following formats:
1 X
: One person joins the end of the waiting line holding a ticket with menu number
X
.
2
: Takahashi guides the person at the front of the waiting line into the restaurant. Print the menu number on that person’s ticket.
Constraints
1 \leq Q \leq 100
1 \leq X \leq 100
For each query of the second type, there is at least one person in the line before guiding.
All input values are integers.
Input
The input is given from Standard Input in the following format:
Q
\mathrm{query}_1
\mathrm{query}_2
\vdots
\mathrm{query}_Q
Each query has one of the following two formats:
1
X
2
Output
For each query, print the answer as specified in the problem statement, each on its own line.
Sample Input 1
6
1 3
1 1
1 15
2
1 3
2
Sample Output 1
3
1
Initially, the waiting line is empty.
For the first query, a person holding a ticket with menu number
3
joins the end of the line. The sequence of menu numbers held by people in line from front to back is
3
.
For the second query, a person holding a ticket with menu number
1
joins the end of the line. The sequence becomes
3,1
.
For the third query, a person holding a ticket with menu number
15
joins the end of the line. The sequence becomes
3,1,15
.
For the fourth query, guide the person at the front into the restaurant. That person holds menu number
3
, so print
3
. The sequence becomes
1,15
.
For the fifth query, a person holding a ticket with menu number
3
joins the end of the line. The sequence becomes
1,15,3
.
For the sixth query, guide the person at the front into the restaurant. That person holds menu number
1
, so print
1
. The sequence becomes
15,3
.
Sample Input 2
7
1 3
1 1
1 4
1 1
1 5
1 9
1 2
Sample Output 2
Note that there may be no queries of the second type.

C++ solution:
#include <iostream>
#include <iomanip>
#include <climits>
#include <cmath>
#include <vector>
#include <queue>
#include <stack>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <numeric>
#include <functional>
#include <set>
#include <string>
#include <bitset>

using ll = long long;
using ull = unsigned long long;
using db = double;
using ldb = long double;

#define debug std::cout << "debug" << std::endl;

void solve(){
    int q;
    std::cin >> q;
    std::queue<int> que;
    while(q--){
        int op;
        std::cin >> op;
        if(op == 1){
            int x;
            std::cin >> x;
            que.push(x);
        }else{
            std::cout << que.front() << std::endl;
            que.pop();
        }
    }
}

int main(){
    std::ios::sync_with_stdio(0);
    std::cin.tie(0);std::cout.tie(0);

    solve();
}

Go solution:
package main

import (
	"bufio"
	"fmt"
	"os"
)

const MaxN int = 1e2 + 1

func main() {
    defer wrtr.Flush()
    var (
        q []int
        n, x, qType int
    )
    q = make([]int, 0, MaxN)
    scanws(&n)
    for ; n > 0; n-- {
        scanws(&qType)
        switch qType {
        case 1:
            scanws(&x)
            q = append(q, x)
        case 2:
            x, q = q[0], q[1:]
            printf("%d\n", x)
        }
    }
}

const DefaultReaderSizeBytes int = 1e2

var (
	rdr  *bufio.Reader = bufio.NewReaderSize(os.Stdin, DefaultReaderSizeBytes)
	wrtr *bufio.Writer = bufio.NewWriter(os.Stdout)
)

func scanws(args ...interface{}) {
	fmt.Fscan(rdr, args...)
}

func printf(frmt string, args ...interface{}) {
	fmt.Fprintf(wrtr, frmt, args...)
}

Java solution:
import java.io.*;
import java.util.*;



public class Main {
    static final int mod = 1000000007;
    static final long MOD = 998244353;
    static InputReader in = new InputReader(System.in);
    static PrintWriter out = new PrintWriter(System.out, false);

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public int nextInt() {
            return Integer.parseInt(next());
        }

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public String nextLine() throws IOException {

            return reader.readLine();
        }

        public long nextLong() {
            return Long.parseLong(next());
        }

        public double nextDouble() {
            return Double.parseDouble(next());
        }
        public int[] nextIntArray(int n) throws IOException {
            int[] arr = new int[n];
            for (int i = 0; i < n; i++) {
                arr[i] = in.nextInt();
            }
            return arr;
        }
        public int[] randomIntArray(int n) {
            Random random = new Random();
            int[] arr = new int[n];
            for (int i = 0; i < n; i++) {
                arr[i] = random.nextInt(100) + 1;
            }
            return arr;
        }
        public long randLong() {
            Random random = new Random();
            return random.nextInt(1000);
        }
    }

    public static void main(String[] args) throws Exception {
        Main main = new Main();
        int T = 1;
        //T = in.nextInt();
        while (T-- > 0) {
            main.solve();
        }

        out.flush();
    }



    void solve() throws Exception {
        int q = in.nextInt();
        List<Integer> list = new ArrayList<>();
        while (q-- > 0){
            int type = in.nextInt();
            if(type == 1){
                list.add(in.nextInt());
            }else {
                out.println(list.remove(0));
            }
        }
    }


}

JavaScript solution:
function Main(input) {
	const inp = input.split("\n")
    var Q=Number(inp[0])
    var mati=[];
    for(var i=0;i<Q;i++){
        if(inp[i+1].split(" ")[0]==1){
            mati.push(inp[i+1].split(" ")[1])
        }else{
            console.log(mati.shift())
        }
    }
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Python solution:
nop = input()
number = []
count = 0

for i in range(int(nop)):
  query = input()
  query = query.split()
  if int(query[0]) == 1:
    number.append(int(query[1]))
  elif len(number) > count:
    print(number[count])
    count = count + 1

Ruby solution:
n = gets.to_i
arr = []
n.times do |i|
  query = gets.split.map(&:to_i)
  if query[0] == 1
    arr.push(query[1])
  elsif query[0] == 2
    puts arr.shift
  end
end