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++: #include "bits/stdc++.h"
using namespace std;

int main(){
  int n;
  cin>>n;
  for(int k=0;k<n;k++){
    vector<int> a(10);
    for(int i=0;i<10;i++)cin>>a[i];
    int x=a[0];
    int y=0;
    int fl=1;
    for(int i=1;i<10;i++){
      if(x>a[i]&&y>a[i]){
        fl=0;
        cout<<"NO"<<endl;
        break;
      }
      if(x>=y){
        if(x<a[i]){
          x=a[i];
        }else{
          y=a[i];
        }
      }else{
        if(y<a[i]){
          y=a[i];
        }else{
          x=a[i];
        }
      }
    }
    if(fl)cout<<"YES"<<endl;
  }
}

C++: #include <bits/stdc++.h>
#define PI 3.14159265359
using namespace std;

int main() {
	int n;
	cin >> n;

	for (int i = 0; i < n; i++) {
		int a = 0, b = 0;

		int f = 0;
		for (int i = 0; i < 10; i++) {
			int x;
			cin >> x;

			if (!i) {
				a = x;
			}
			else {
				if (x > a) {
					a = x;
				}
				else {
					if (!b) {
						b = x;
					}
					else if (x>b) {
						b = x;
					}
					else {
						f = 1;
					}
				}
			}
		}

		if (f) {
			cout << "NO" << endl;
		}
		else {
			cout << "YES" << endl;
		}
	}
}

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

using namespace std;

vector<int> a;
stack<int> b, c;

bool dfs(int i)
{
	if (i == 10) return true;

	bool res1 = false, res2 = false;

	if (b.empty()) {
		b.push(a[i]);
		res1 = dfs(i + 1);
		b.pop();
	} else if(c.empty()) {
		c.push(a[i]);
		res2 = dfs(i + 1);
		c.pop();
	} else {
		if (b.top() < a[i]) {
			b.push(a[i]);
			res1 = dfs(i + 1);
			b.pop();
		}
		if (c.top() < a[i]) {
			c.push(a[i]);
			res2 = dfs(i + 1);
			c.pop();
		}
	}

	return res1 || res2;
}

int main()
{
	int n; cin >> n;

	while (n--) {
		a.clear();
		while (b.size()) b.pop();
		while (c.size()) c.pop();

		for (int i = 0; i < 10; ++i) { int v; cin >> v; a.push_back(v); }

		if (dfs(0)) cout << "YES" << endl;
		else cout << "NO" << endl;
	}
}

C++: #include<iostream>
#include<vector>
#include<stdlib.h>
using namespace std;
vector<int> balls;
bool dfs(int i,int left,int right,int len)
{
	if(i==len&&(balls[i-1]>left||balls[i-1]>right))return 1;
	if(balls[i-1]<left&&balls[i-1]<right)return 0;
	if(balls[i-1]>left){
		return dfs(i+1,balls[i-1],right,len);
	}
	if(balls[i-1]>right){
		return dfs(i+1,left,balls[i-1],len);
	}
	
}
int main()
{
	int T;
	cin>>T;
	while(T--){
		int x;
		while(cin>>x){
			balls.push_back(x);
		}
		int len=balls.size();
		if(dfs(1,-1,-1,len)){
			cout<<"YES"<<endl;
		}else cout<<"NO"<<endl;
	}
}

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

int main() {
	int n;
	int d[10];
	int va[10];
	int vb[10];
	int trush;
	cin >> n;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < 10; j++) {
			cin >> d[i];
		}

		int ca = 0, cb = 0;
		va[0] = d[0];
		ca++;
		if (d[1] > va[0]) {
			va[1] = d[1];
			ca++;
		}

		else {
			vb[0] = d[1];
			cb++;
		}

	for (int j = 2; j < 10; j++) {

		if (d[j] < va[ca - 1] && d[j] < vb[cb - 1]) {
			cout << "NO" << endl;
			goto FINLOOP;
		}

			else if (d[j] > va[ca-1]) {
				va[ca] = d[j];
				ca++;
			}

			else if (d[j] > vb[cb - 1]) {
				vb[cb] = d[j];
				cb++;
			}
			
		}
		cout << "YES" << endl;

		FINLOOP:
		for (int i = 0; i < 10; i++) {
			va[i] = 0;
		}
		for (int i = 0; i < 10; i++) {
			vb[i] = 0;
		}
	}
	return 0;
}

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

int main(){
    int n,s;
    cin >> n;
    for (int i=-; i < n; i++){
        int a=0, b=0, flg=0;
        for (int j = 0; j < 10; j++)}{
            cin >> s;
            if (s > a) a=s;
            else (s > b) b=s;
            else flg = 1;
        }
        printf("%s\n", flg==0? "YES": "NO");
    }
}

C++: #include<iostream>
int topA=-1, topB=-1,B;
int times;
int main(){
	std::cin >> times;
	for (int j = 0; j < times; j++){
		for (int i = 0; i < 10; i++){
			std::cin >> B;
			if (topA == -1 && topB == -1){
				topA = B;
			}
			else if (topA != -1 && topB == -1){
				topB = B;
			}
				else if (topA < B){
					topA = B;
				}
				else if (topB < B){
					topB = B;
				}
				else{
					std::cout << "NO\n";
					goto rip;
				}
			}
		std::cout << "YES\n";
	rip:;
		topA = -1,topB=-1;
		}

}

C++: #include<bits/stdc++.h>
using namespace std;
main(){
  int n,a;
  srand((unsigned)time(NULL));
  cin>>n;
  for(int i=0;i<n;i++){
    for(int j=0;j<10;j++){
      cin>>a;
    }
    if(rand()%2==0){
      cout<<"YES"<<endl;
    }
    else{
      cout<<"NO"<<endl;
    }
  }
}

C++: #include <bits/stdc++.h>
using namespace std;


int main(){
    
    int n;
    cin >> n;

    int b[n][10];
    

    for(int i=0;i<n;i++){
        for(int j=0;j<10;j++){
            cin >> b[i][j];
        }
    }

    bool check[n];
    for(int i=0;i<n;i++){
        check[i]=true;
    }

    for(int i=0;i<n;i++){
        vector<int> x,y;
        x.push_back(0);
        y.push_back(0);
        x.push_back(b[i][0]);
        
        
        for(int j=1;j<10;j++){
            int pa = x[x.size()-1];
            int pb = y[y.size()-1];

            int p = b[i][j];

            if(p<pa&&p<pb){
                check[i] = false;
            }else if(p<pa&&p>pb){
                y.push_back(p);
            }else if(p>pa&&p<pb){
                x.push_back(p);
            }else{
                if(pa<pb){
                    y.push_back(p);
                }else{
                    x.push_back(p);
                }
            }
        }
    }


    for(int i=0;i<n;i++){
        if(check[i]){
            cout << "YES" << endl;
        }else{
            cout << "NO" << endl;
        }
    }
    
    return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;

int a[10];

int main() {
    int n, x, y, f;
    cin >> n;
    while (n--) {
        for (int i = 0; i < 10; i++) cin >> a[i];
        x = y = f = 0;
        for (int i = 0; i < 10; i++) {
            if (a[i] > x)
                x = a[i];
            else if (a[i] > y)
                y = a[i];
            else {
                f = 1;
                break;
            }
        }
        if (f)
            cout << "NO\n";
        else
            cout << "YES\n";
    }
}

C++: 
#include<cstdio>
using namespace std;
const static int MAX_N = 12;
static int num[12], left[12], right[12];
static bool ret = false;
void dfs(int cur, int n, int num[], int left[],int l, int right[],int r) {
	if (cur == n) {
		for (int i = 0; i < l-1; i++) {
			if (left[i] > left[i + 1])
				return;
		}
		for (int j = 0; j < r - 1; j++) {
			if (right[j] > right[j + 1])
				return;
		}
		ret = true;
	} else {
		left[l] = num[cur];
		dfs(cur + 1, n, num, left, l + 1, right, r);
		right[r] = num[cur];
		dfs(cur + 1, n, num,left, l, right, r + 1);
	}
}

int main() {
	int n;
	for (scanf("%d ", &n); n; n--) {
		for (int i = 0; i < 10; i++) {
			scanf("%d", &num[i]);
		}
		dfs(0, 10, num, left, 0, right, 0);
		if (ret)printf("YES\n");
		else printf("NO\n");
		ret = false;
	}
}