Go: package main

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

var scanner = bufio.NewScanner(os.Stdin)

func nextInt() int {
	scanner.Scan()
	i, e := strconv.Atoi(scanner.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func main() {
	scanner.Split(bufio.ScanWords)
	n := nextInt()
	for i := 0; i < n; i++ {
		a := -1
		b := -1
		ans := true
		// それぞれの筒の一番上にあるたまの数字に着目すればよい
		for j := 0; j < 10; j++ {
			x := nextInt()
			if x > a {
				a = x
			} else if x > b {
				b = x
			} else {
				ans = false
			}
		}
		if ans {
			fmt.Println("YES")
		} else {
			fmt.Println("NO")
		}
	}
}

C++: using namespace std;

#include <cstdio>

int a[10];

bool dfs(int i, int l, int r){
	if (i == 10){
		return true;
	}
	if (l < a[i]){
		return dfs(i + 1, a[i], r);
	}
	if (r < a[i]){
		return dfs(i + 1, l, a[i]);
	}
	return false;
}

int main(){
	int n;
	scanf("%d", &n);
	for (int i = 0; i < n; i++)
	{
		for (int j = 0; j < 10; j++)
		{
			scanf("%d", &a[j]);
		}
		printf("%s\n", dfs(0, 0, 0) ? "YES" : "NO");
	}
	return 0;
}

C++: #include <iostream>
#include <string>
using namespace std;

int value[10];

string dfs(int left,int right,int i)
{
	if(i == 10) return "YES";
	if(left < value[i])
	{
		return dfs(value[i],right,i+1);
	}
	if(right < value[i])
	{
		return dfs(left,value[i],i+1);
	}
	return "NO";
}


int main()
{
	int n;
	cin >> n;
	
	while(n--)
	{
		for(int i=0;i<10;i++)	
		{
			cin >> value[i];	
		}
		cout << dfs(0,0,0) << endl;
	}

	return 0;
}

C++: #include <bits/stdc++.h>

using namespace std;

int n, ball[10];

bool solve(int idx, int l, int r) {

    if(idx == 10) return true;

    bool ret = false;
    if(ball[idx] > l) ret = ret || solve(idx + 1, ball[idx], r);
    if(ball[idx] > r) ret = ret || solve(idx + 1, l, ball[idx]);
    return ret;

}

int main() {

    cin >> n;

    for(int i = 0; i < n; ++i) {
        for(int j = 0; j < 10; ++j) {
            cin >> ball[j];
        }
        cout << (solve(0, 0, 0) ? "YES" : "NO") << endl;
    }

}

C++: 2
3 1 4 2 5 6 7 8 9 10
10 9 8 7 6 5 4 3 2 1

C++: #include <string>
#include <vector>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <map>
#include <list>
#include <set>
#include <numeric>
#include <queue>
#include <stack>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <cstring>
using namespace std;
typedef long long LL;
typedef pair<int,int> P;

int main() {
	int N;
	cin >> N;
	for(int i=0;i<N;i++){
		int in[10];
		for(int j=0;j<10;j++){
			cin >> in[j];
		}
		bool ok=true;
		int low=0,hi=0;
		for(int j=0;j<10;j++){
			if(in[j]<=low){
				ok=false;
				break;
			}
			if(in[j]<hi){
				low=in[j];
			}
			else{
				hi=in[j];
			}
		}
		if (ok){
			cout << "YES" << endl;
		}
		else
		{
			cout << "NO" << endl;
		}
	}
}

C++: #include <iostream>
#include <algorithm>
#include <stack>
using namespace std;
int a[10];
bool ans;
void dfs(int i,int r,int l){
	if(i==10)return;
	if(ans==0)return;
	if(r<a[i])dfs(i+1,a[i],l);
	else if(l<a[i])dfs(i+1,r,l);
	else ans=0;
}
int main(){
	int t;
	cin>>t;
	while(t--){
		for(int i=0;i<10;i++)cin>>a[i];
		dfs(0,0,0);
	if(ans)cout<<"YES"<<endl;
	else cout<<"NO"<<endl;
	}
}

C++: #include<bits/stdc++.h>
#include<vector>
#include<list>
#include<stack>
#include<queue>
#include<algorithm>
#include<map>
using namespace std;

int main(){
    int mod=1000000007;
    int a,b,c;
    int ans[2]={0,0};
    int n;
    scanf("%d",&n);
    for (int i=0;i<n;++i) {
        int l=0,r=0;
        vector<int> a(10);
        for(auto&e:a) {
            scanf("%d",&e);
        }
        int f=1;
        for (int j=0;j<10;++j) {
            if (j==0) l=a[0];
            else if (a[j]<l && a[j]<r) {
                f=0;
                printf("NO\n");
                break;
            } else if (a[j]>l && a[j]<r) {
                l=a[j];
            } else if (a[j]<l && a[j]>r) {
                r=a[j];
            } else if ((a[j]-l)>(a[j]-r)) {
                r=a[j];
            } else {
                l=a[j];
            }
        }
        if (f) printf("YES\n");
    }
    return 0;
}

C++: #include <iostream>
using namespace std;

int main()
{
	int n,A,B,f,ball;
	cin >> n;
	
	for(int i=0;i<n;i++){
		A=0;
		B=0;
		f=0;
		for(int j=0;j<10;j++){
			cin >> ball;
			if(ball<A && ball<B) {f=1;break;} 
			else if(A<ball && ball<B) A=ball;
			else if(ball<A && B<ball) B=ball;
			else if(A<B) B=ball;
			else A=ball;
		}
		
		if(f==0) cout << "YES" << endl;
		else cout << "NO" << endl;
		
	}
}

C++: #include <iostream>
#include <vector>
using namespace std;

int main() {
	int n, x, z;
	cin >> n;

	for (int i = 0; i < n; i++) {
		vector< vector<int> > v;
		v.assign(3, { 0 });
		z = 1;
		for (int j = 0; j < 10; j++) {
			cin >> x;
			for (int k = 0; k < z; k++) {
				if (v[k].back() < x) {
					v[k].push_back(x);
					break;
				}

				if (k == z - 1) {
					v[z].push_back(x);
					z++;
					break;
				}
			}

			if (z == 3) {
				x = -1;
				break;
			}
		}

		if (x == -1) {
			cout << "NO";
		}
		else {
			cout << "YES";
		}
		cout << endl;
	}
	return 0;
}

C++: #include<iostream>
#include<queue>
using namespace std;

int main()
{
	int ball = 10;
	int n,k;
	cin >> n;
	queue<int> a;
	int b = 0 , c = 0;
	queue<bool> flag;


	for (int i=0; i < n; i++){
		for (int j=1; j <= ball; j++){
			cin >> k;
			a.push( k );
		}
		b = a.front();
		a.pop();
		
		for (int j=1; j <= (ball-1); j++){
			if (a.front() > b && a.front() > c){
				if (a.front() - b > a.front() - c)
					c = a.front();

				else
					b = a.front();

			}else if(a.front() > b){
				b = a.front();
			
			}else if(a.front() > c){
				c = a.front();
			
			}else {
				flag.push(false);
				j = ball;
			}
			a.pop();
			if (j == (ball-1))
				flag.push(true);
		}
	}

	for (int i = 0; i < n; i++){
		if (flag.front()){
			cout << "YES" << endl;
		}else{
			cout << "NO" << endl;
		}
		flag.pop();
	}



	return 0;
}

C++: #include<cstdio>
#include<iostream>
#include<stack>
using namespace std;


int main(){
	int N;
	scanf("%d",&N);
	for(int i=0;i<N;i++){
		int ball[10];
		for(int j=0;j<10;j++)scanf("%d",&ball[j]);
		
		stack<int> S,Q;
		int a[2]={0};
		S.push(ball[0]);
		Q.push(a[1]);
		
		int k=1,check[2];
		bool OK = false;
		while(1){
			printf("%d,%d\n",a[0],a[1]);
			a[0] = S.top();
			a[1] = Q.top();
			if(a[0] < ball[k]){
				S.push(ball[k]);
				Q.push(a[1]);
				k++;
				if(k >= 11){
					OK = true;
					break;
				}
			}else if(a[1] < ball[k]){
				Q.push(ball[k]);
				S.push(a[0]);
				k++;
				if(k >= 11){
					OK = true;
					break;
				}
			}else{
				if(check[0] == a[0] && check[1] == a[1])break;
				check[0] = a[0];
				check[1] = a[1];
				S.pop();
				Q.pop();
				
				k--;
			}
			if(S.size() == 0) break;
		}		
		if(OK == true) printf("YES\n");
		else printf("NO\n");
		for(;;){
			if(S.size() == 0)break;
			S.pop();
		}
		for(;;){
			if(Q.size() == 0)break;
			Q.pop();
		}
		
		
	}
	return 0;
}

C++: #include<iostream>
#include<stack>
using namespace std;

int main(){
	int n;
	bool check;
	stack<int> a;
	stack<int> b;
	int ain,bin;
	cin>>n;
	for(int i=0;i<n;i++){
	check=true;
	cin>>ain>>bin;
	a.push(ain);b.push(bin);
	for(int j=0;j<5;j++){
		cin>>ain>>bin;
		if(!(a.top()<ain||b.top()<bin))check=false;
		a.push(ain);b.push(bin);
	}	
	if(check==false){cout<<"NO"<<endl;}else cout<<"YES"<<endl;
	}
}

C++: #include<stdio.h>

int main()
{
	int n,m[10]={0};
	scanf("%d",&n);

	for(int x=0;x<n;x++)
	{
		scanf("%d %d %d %d %d %d %d %d %d %d",&m[0],&m[1],&m[2],&m[3],&m[4],&m[5],&m[6],&m[7],&m[8],&m[9]);
		int a=0,b=0,t=0;

		for(t;t<=9;t++)
		{
			if(a>=b)
			{
				if(a<m[t])
				{
					a=m[t];
				}
				else
				{
					if(b<m[t])
					{
						b=m[t];
					}
					else
					{
						t=99;
					}
				}
			}
			else if(a<b)
			{
				if(b<m[t])
				{
					b=m[t];
				}
				else
				{
					if(a<m[t])
					{
						a=m[t];
					}
					else
					{
						t=99;
					}
				}
			}
		}

		if(t==10)
		{
			printf("YES\n");
		}
		else if(t==100)
		{
			printf("NO\n");
		}
	}
	return 0;
}