Language: C++

import java.io.FileInputStream;
import java.io.InputStream;
import java.util.Scanner;
import java.math.BigInteger;
import java.io.*;

class Stack{
    int s[]=new int[20010];
    int mins[]=new int[20010];
    int maxs[]=new int[20010];
    int p=0,maxp=0,minp=0;
    public int size(){return p;}
    public boolean empty(){return p==0;}
    public void push(int v){
	s[p++]=v;
	if (minp == 0 || mins[minp-1] > v)mins[minp++]=v;
	if (maxp == 0 || maxs[maxp-1] < v)maxs[maxp++]=v;
    }
    public int pop(){
	int ret=s[--p];
	if (mins[minp-1] == ret)minp--;
	if (maxs[maxp-1] == ret)maxp--;
	return ret;
    }
    public int getIthMin(int i){
	return mins[minp-i];
    }
    public int getIthMax(int i){return maxs[maxp-i];}
}

class Deque{
    int d[]=new int[20010];
    int mind[]=new int[20010];
    int maxd[]=new int[20010];
    int b=0,e=0,maxb=0,maxe=0,minb=0,mine=0;
    public int size(){return e-b;}
    public boolean empty(){return b==e;}
    public void push(int v){
	d[e++]=v;
	while(maxb < maxe && maxd[maxe-1] < v)maxe--;
	maxd[maxe++]=v;
	while(minb < mine && mind[mine-1] > v)mine--;
	mind[mine++]=v;
    }
    public int pop(){
	int ret=d[b++];
	if (mind[minb] == ret)minb++;
	if (maxd[maxb] == ret)maxb++;
	return ret;
    }
    public int getIthMin(int i){return mind[minb+i-1];}
    public int getIthMax(int i){return maxd[maxb+i-1];}
}

class Fimo{
    Stack S;
    Deque D;
    Fimo(){
	S=new Stack();
	D=new Deque();
    }
    public void push(int v){
	if (S.empty() && D.empty()){
	    S.push(v);
	}else if (S.size() > D.size()){
	    D.push(v);
	}else if (S.size() == D.size()){
	    int tmp=D.pop();
	    S.push(tmp);
	    D.push(v);
	}
    }
    public int getMin(int t,int i){
	if (t == 0)return S.getIthMin(i);
	else return D.getIthMin(i);
    }
    public int getMax(int t,int i){
	if (t == 0)return S.getIthMax(i);
	else return D.getIthMax(i);
    }
    public int pop(){
	int ret=-1;
	if (D.empty()){
	    ret=S.pop();
	}else if (S.size() > D.size()){
	    ret=S.pop();
	}else if (S.size() == D.size()){
	    int tmp=D.pop();
	    ret=S.pop();
	    S.push(tmp);
	}
	return ret;
    }
}

class Main{
    public static void main(String []args){
	Scanner in=new Scanner(System.in);
	//Scanner in=new Scanner();
	//System.setOut(new PrintStream(new BufferedOutputStream(System.out)));
	int q;
	while(true){
	    q=in.nextInt();
	    if (q == 0)break;
	    Fimo a=new Fimo();
	    for(int i=0;i<q;i++){
		int val,tmp;
		tmp=in.nextInt();
		switch(tmp){
		case 0:
		    val=in.nextInt();
		    //System.out.print(0+" "+val+"\n");
		    a.push(val);
		    break;
		case 1:
		    System.out.print(a.pop()+"\n");
		    break;
		case 2:
		    System.out.print(a.getMin(0,1)+"\n");
		    break;
		case 3:
		    System.out.print(a.getMin(1,1)+"\n");
		    break;
		case 4:
		    val=in.nextInt();
		    System.out.print(a.getMin(0,val)+"\n");
		    break;
		case 5:
		    val=in.nextInt();
		    System.out.print(a.getMin(1,val)+"\n");
		    break;
		case 6:
		    System.out.print(a.getMax(0,1)+"\n");
		    break;
		case 7:
		    System.out.print(a.getMax(1,1)+"\n");
		    break;
		case 8:
		    val=in.nextInt();
		    System.out.print(a.getMax(0,val)+"\n");
		    break;
		case 9:
		    val=in.nextInt();
		    System.out.print(a.getMax(1,val)+"\n");
		    break;
		default:
		    break;
		}
	    }
	    System.out.print("end\n");
	}
    }
}
    
/*
class Scanner {
    int nextInt() {
        try {
            int c = System.in.read();
            if (c == -1)
                return c;
            while (c != '-' && (c < '0' || '9' < c)) {
                c = System.in.read();
                if (c == -1)
                    return c;
            }
            if (c == '-')
                return -nextInt();
            int res = 0;
            do {
                res *= 10;
                res += c - '0';
                c = System.in.read();
            } while ('0' <= c && c <= '9');
            return res;
        } catch (Exception e) {
            return -1;
        }
    }
 
    long nextLong() {
        try {
            int c = System.in.read();
            if(c==-1)return -1;
            while (c != '-' && (c < '0' || '9' < c)){
                c = System.in.read();
                if(c==-1)return -1;
            }
            if (c == '-')
                return -nextLong();
            long res = 0;
            do {
                res *= 10;
                res += c - '0';
                c = System.in.read();
            } while ('0' <= c && c <= '9');
            return res;
        } catch (Exception e) {
            return -1;
        }
    }
 
    double nextDouble() {
        return Double.parseDouble(next());
    }
 
    String next() {
        try {
            StringBuilder res = new StringBuilder("");
            int c = System.in.read();
            while (Character.isWhitespace(c))
                c = System.in.read();
            do {
                res.append((char) c);
            } while (!Character.isWhitespace(c = System.in.read()));
            return res.toString();
        } catch (Exception e) {
            return null;
        }
    }
 
    String nextLine() {
        try {
            StringBuilder res = new StringBuilder("");
            int c = System.in.read();
            while (c == '\r' || c == '\n')
                c = System.in.read();
            do {
                res.append((char) c);
                c = System.in.read();
            } while (c != '\r' && c != '\n');
            return res.toString();
        } catch (Exception e) {
            return null;
        }
    }
}
*/

Compiler output:
a.cc:1:1: error: 'import' does not name a type
    1 | import java.io.FileInputStream;
      | ^~~~~~
a.cc:1:1: note: C++20 'import' only available with '-fmodules-ts'
a.cc:2:1: error: 'import' does not name a type
    2 | import java.io.InputStream;
      | ^~~~~~
a.cc:2:1: note: C++20 'import' only available with '-fmodules-ts'
a.cc:3:1: error: 'import' does not name a type
    3 | import java.util.Scanner;
      | ^~~~~~
a.cc:3:1: note: C++20 'import' only available with '-fmodules-ts'
a.cc:4:1: error: 'import' does not name a type
    4 | import java.math.BigInteger;
      | ^~~~~~
a.cc:4:1: note: C++20 'import' only available with '-fmodules-ts'
a.cc:5:1: error: 'import' does not name a type
    5 | import java.io.*;
      | ^~~~~~
a.cc:5:1: note: C++20 'import' only available with '-fmodules-ts'
a.cc:12:11: error: expected ':' before 'int'
   12 |     public int size(){return p;}
      |           ^~~~
      |           :
a.cc:13:11: error: expected ':' before 'boolean'
   13 |     public boolean empty(){return p==0;}
      |           ^~~~~~~~
      |           :
a.cc:13:12: error: 'boolean' does not name a type; did you mean 'bool'?
   13 |     public boolean empty(){return p==0;}
      |            ^~~~~~~
      |            bool
a.cc:14:11: error: expected ':' before 'void'
   14 |     public void push(int v){
      |           ^~~~~
      |           :
a.cc:19:11: error: expected ':' before 'int'
   19 |     public int pop(){
      |           ^~~~
      |           :
a.cc:25:11: error: expected ':' before 'int'
   25 |     public int getIthMin(int i){
      |           ^~~~
      |           :
a.cc:28:11: error: expected ':' before 'int'
   28 |     public int getIthMax(int i){return maxs[maxp-i];}
      |           ^~~~
      |           :
a.cc:8:9: error: flexible array member 'Stack::s' not at end of 'class Stack'
    8 |     int s[]=new int[20010];
      |         ^
a.cc:29:2: error: expected ';' after class definition
   29 | }
      |  ^
      |  ;
a.cc:8:9: error: initializer for flexible array member 'int Stack::s []'
    8 |     int s[]=new int[20010];
      |         ^
a.cc:9:9: error: initializer for flexible array member 'int Stack::mins []'
    9 |     int mins[]=new int[20010];
      |         ^~~~
a.cc:10:9: error: initializer for flexible array member 'int Stack::maxs []'
   10 |     int maxs[]=new int[20010];
      |         ^~~~
a.cc:36:11: error: expected ':' before 'int'
   36 |     public int size(){return e-b;}
      |           ^~~~
      |           :
a.cc:37:11: error: expected ':' before 'boolean'
   37 |     public boolean empty(){return b==e;}
      |           ^~~~~~~~
      |           :
a.cc:37:12: error: 'boolean' does not name a type; did you mean 'bool'?
   37 |     public boolean empty(){return b==e;}
      |            ^~~~~~~
      |            bool
a.cc:38:11: error: expected ':' before 'void'
   38 |     public void push(int v){
      |           ^~~~~
      |           :
a.cc:45:11: error: expected ':' before 'int'
   45 |     public int pop(){
      |           ^~~~
      |           :
a.cc:51:11: error: expected ':' before 'int'
   51 |     public int getIthMin(int i){return mind[minb+i-1];}
      |           ^~~~
      |           :
a.cc:52:11: error: expected ':' before 'int'
   52 |     public int getIthMax(int i){return maxd[maxb+i-1];}
      |           ^~~~
      |           :
a.cc:32:9: error: flexible array member 'Deque::d' not at end of 'class Deque'
   32 |     int d[]=new int[20010];
      |         ^
a.cc:53:2: error: expected ';' after class definition
   53 | }
      |  ^
      |  ;
a.cc:32:9: error: initializer for flexible array member 'int Deque::d []'
   32 |     int d[]=new int[20010];
      |         ^
a.cc:33:9: error: initializer for flexible array member 'int Deque::mind []'
   33 |     int mind[]=new int[20010];
      |         ^~~~
a.cc:34:9: error: initializer for flexible array member 'int Deque::maxd []'
   34 |     int maxd[]=new int[20010];
      |         ^~~~
a.cc:62:11: error: expected ':' before 'void'
   62 |     public void push(int v){
      |           ^~~~~
      |           :
a.cc:73:11: error: expected ':' before 'int'
   73 |     public int getMin(int t,int i){
      |           ^~~~
      |           :
a.cc:77:11: error: expected ':' before 'int'
   77 |     public int getMax(int t,int i){
      |           ^~~~
      |           :
a.cc:81:11: error: expected ':' before 'int'
   81 |     public int pop(){
      |           ^~~~
      |           :
a.cc:8:9: error: flexible array member 'Stack::s' not at end of 'class Fimo'
    8 |     int s[]=new int[20010];
      |         ^
a.cc:94:2: error: expected ';' after class definition
   94 | }
      |  ^
      |  ;
a.cc: In member function 'void Fimo::push(int)':
a.cc:63:15: error: 'class Stack' has no member named 'empty'
   63 |         if (S.empty() && D.empty()){
      |               ^~~~~
a.cc:63:28: error: 'class Deque' has no member named 'empty'
   63 |         if (S.empty() && D.empty()){
      |                            ^~~~~
a.cc: In member function 'int Fimo::pop()':
a.cc:83:15: error: 'class Deque' has no member named 'empty'
   83 |         if (D.empty()){
      |               ^~~~~
a.cc: At global scope:
a.cc:97:11: error: expected ':' before 'static'
   97 |     public static void main(String []args){
      |           ^~~~~~~
      |           :
a.cc:97:29: error: 'String' has not been declared
   97 |     public static void main(String []args){
      |                             ^~~~~~
a.cc:97:38: error: expected ',' or '...' before 'args'
   97 |     public static void main(String []args){
      |                                      ^~~~
a.cc:153:2: error: expected ';' after class definition
  153 | }
      |  ^
      |  ;
a.cc: In static member function 'static void Main::main(int*)':
a.cc:98:9: error: 'Scanner' was not declared in this scope
   98 |         Scanner in=new Scanner(System.in);
      |         ^~~~~~~
a.cc:103:15: error: 'in' was not declared in this scope; did you mean 'int'?
  103 |             q=in.nextInt();
      |               ^~
      |               int
a.cc:105:29: error: 'Fimo::Fimo()' is private within this context
  105 |             Fimo a=new Fimo();
      |                             ^
a.cc:58:5: note: declared private here
   58 |     Fimo(){
      |     ^~~~
a.cc:105:20: error: conversion from 'Fimo*' to non-scalar type 'Fimo' requested
  105 |             Fimo a=new Fimo();
      |                    ^~~~~~~~~~
a.cc:116:21: error: 'System' was not declared in this scope
  116 |                     System.out.print(a.pop()+"\n");
      |                     ^~~~~~
a.cc:150:13: error: 'System' was not declared in this scope
  150 |             System.out.print("end\n");
      |             ^~~~~~