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 <iostream>
using namespace std;

int ball[10];

bool dfs(int m,int left, int right){
    if(m==10) return true;
    if(ball[m]>left){
        return dfs(m+1,ball[m],right);
    }
    if(ball[m]>right){
        return dfs(m+1,left,ball[m]);
    }
    return false;
}

void solve(){
    for(int i=0;i<10;i++){
        cin>>ball[i];
    }
    if(dfs(0,0,0)){
        cout << "YES" << endl;
    }else{
        cout << "NO" << endl;
    }
}

int main(){
    int n;cin>>n;
    for(int i=0;i<2;i++){
        solve();
    }
    return 0;
}

C++: #include <stdio.h>

int main(){
int n,i,j;
int a,b,c,f;

scanf("%d",&n);
for(i=0;i<n;i++){
scanf("%d",&a);
b=0;
f=0;
for(j=1;j<10;j++){
scanf("%d",&c);
if(a>c&&b>c)f=1;
else if(a<c&&b<c){
if(a>b)a=c;
else b=c;
}
else{
if(a>b)b=c;
else a=c;
}
}
if(f==0){
printf("YES\n");
}
else if(f==1){
printf("NO\n");
}
}
return 0;
}

C++: #include<iostream>
using namespace std;
int d[10]={};
bool f;
void dfs(int l,int r, int s){
  if(s==10) f=true;
  //cout << l << r << d[s] << endl;
  if(l<d[s]){
    dfs(d[s],r,s+1);
  }
  if(r<d[s]){
    dfs(l,d[s],s+1);
  }
}
int main(){
  int n;cin >> n;
  while(n--){
    int r=0,l=0;
    f=false;
    for(int i=0;i<10;i++){
      cin >> d[i];
      //cout << l << ":" << r << endl;
    }
    dfs(0,0,0);
    if(!f) cout << "NO" << endl;
    else cout << "YES" << endl;
  }  
}

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

bool DFS(int t_b,int t_c,int th,int* balls){
  if(th==10)return true;
  if(t_b<balls[th]&&t_c<balls[th])
      if(t_b>t_c)return DFS(balls[th],t_c,th+1,balls);
      else return DFS(t_b,balls[th],th+1,balls);
  else if(t_b<balls[th])return DFS(balls[th],t_c,th+1,balls);
  else if(t_c<balls[th])return DFS(t_b,balls[th],th+1,balls);
  else return false;
}
int main(){
  int n;
  cin>>n;
  for(int j=0;j<n;j++){
    int balls[10];
    for(int i=0;i<10;i++)cin>>balls[i];
    int t_b=0,t_c=0;int drop_balls=0;
    if(DFS(0,0,1,balls))cout<<"YES";
    else cout<<"NO";
    cout<<endl;
  }
}

C++: //dfs
#include<vector>
#include<list>
#include<deque>
#include<queue>
#include<stack>
#include<map>
#include<unordered_map>
#include<set>
#include<unordered_set>
#include<bitset>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cctype>
#include<cmath>
#include<iostream>

using namespace std;
typedef long long ll;
#define cls(x) memset(x,0,sizeof(x))


const int INF = 0x3f3f3f3f;
const int SZ = 100;

int main() {
  int total = 1 << 10;
  int n;
  cin >> n;
  int a[10];
  while(n-- > 0) {
    for(int i = 0; i < 10; ++i) {
      cin >> a[i];
    }
    bool flag;
    for(int p = 0; p < total; ++p) {
      int cur = p;
      int pre_left = -1, pre_right = -1;
      flag = true;
      for(int i = 0; i < 10; ++i) {
        if((cur >> i) & 1) {
          //left
          //cout << a[i] << endl;
          if(a[i] > pre_left) {
            pre_left = a[i];
          } else {
            flag = false;
            break;
          }
        } else {
          // right
          if(a[i] > pre_right) {
            pre_right = a[i];
          } else {
            flag = false;
            break;
          }
        }
      }
      if(flag) break;
    }
    if(flag)  {
      cout << "YES" << endl;
    } else {
      cout << "NO" << endl;
    }
  }
	return 0;
}

C++: #include <iostream>
#include <iomanip>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <stack>
using namespace std;
typedef long long ll;
int l[12],r[12],q[12];
bool yon;
void dfs(int i,int j,int k){
	if(i == 10){
		yon = true;
		return ;
	}
	if(q[i] > l[j-1]){
		l[j] = q[i];
		dfs(i+1,j+1,k);
	}
	if(q[i] > r[k-1]){
		r[k] = q[i];
		dfs(i+1,j,k+1);
	}
}
int main()
{
	int t;
	scanf("%d",&t);
	while(t--){
		for(int i=1;i<=10;i++){
			scanf("%d",&q[i]);
		}
		yon = false;
		l[0] = -1;
		r[0] = -1;
		dfs(1,1,1);
		if(yon){
			printf("YES\n");
		}else{
			printf("NO\n"); 
		}
	}
	return 0;
}

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

int main(){
	int nums[10];
	int n;
	cin >> n;
	for(int i = 0; i < n; i++){
		int a;
		for(int j = 0; j < 10; j++){
			cin >> a;
			nums[j] = a;
		}
		int l = nums[0], r = nums[1];
		for(int i = 2; i < 10; i++){
			int minimum = min(l, r);
			int maximum = max(l, r);
			if(nums[i] < minimum){
				cout << "NO" << endl;
				break;
			}
			if(nums[i] > maximum){
				if(l > r){
					l = nums[i];
				} else {
					r = nums[i];
				}
			} else {
				if(nums[i] > l){
					l = nums[i];
				}else if(nums[i] > r){
					r = nums[i];
				}
			}
			if(i == 9)
				cout << "YES" << endl;
		}
	}
	return 0;
}

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


int saiki(int ball[],int ttB,int ttC,int res){
	if(res==10)return 1;
	if(ball[res]>ttB){
		return saiki(ball,ball[res],ttC,res+1);
	}
	if(ball[res]>ttC){
		return saiki(ball,ttB,ball[res],res+1);
	}
	return 0;
}

int main(void){
	int a,b;
	int ball[11];
	int ttB=0,ttC=0;
	int res=0;
	int n;
	scanf("%d",&n);
	for(a=0;a<n;a++){
		for(b=0;b<10;b++){
			ball[b]=0;
		}
		ttB=0;
		ttC=0;
		res=0;
		for(b=0;b<10;b++){
			scanf("%d",&ball[b]);
		}
		if(saiki(ball,ttB,ttC,res)==1)printf("Yes\n");else printf("No\n");
	}
	return 0;
}

C++: #include<iostream>
#include<stdio.h>
#include<vector>

using namespace std;

int main(){
    int n;
    bool flag = true;
    vector<int> b, c;
    b.push_back(0);
    c.push_back(0);
    vector<int> ::iterator b_it=b.begin(), c_it=c.begin();

    cin>> n;
    while(n--, n!=-1){
        for(int i=0; i<10; i++){
            cout<<i << flag <<endl;
            if(flag){
                int num;
                cin>> num;
                if(num>*b_it){
                    b.push_back(num);
                    b_it = b.end()-1;
                }else if(num>*c_it){
                    c.push_back(num);
                    c_it = c.end()-1;
                }else{
                    flag = false;
                }
            }
        }
        if(flag){
            cout<< "YES"<< endl;
        }else{
            cout<< "NO"<< endl;
        }
    }
    return 0;
}

C++: #include<iostream>
using namespace std;
int main(){
  int t;
  cin >> t;
  int n;
  for(int i=0;i<t;i++){
    int h = 0,b = 0,c = 0;
    for(int j=0;j<10;j++){
      cin >> n;
      if(b==0) b = n;
      else if(b>c&&b<n) b = n;
      else if(c>b&&c<n) c = n;
      else if(b>c&&b>n&&c<n) c = n;
      else if(c>b&&c>n&&b<n) b = n;
      else if(b>n&&c>n){
	cout << "NO" << endl;
	h = 1;
	break;
      }
    }
    if(h==0) cout << "YES" << endl;
  }
  return 0;
}