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 main() {
    int n; cin >> n;  // ???????????????????????°
    
    while(n--){
        int balls[10] = {0};
        for(int i = 0; i < 10; i++) cin >> balls[I]; // ??????????????????????????\???
        
        bool isYES = true;  // ???10???????????????????????????????????????
        int topB = 0, topC = 0;  // ???B?????????C???????????¨????????????
        for(int i = 0; i < 10; i++){
            if (topB < balls[i]){
                topB = balls[i];
            } else if (topC < balls[i]) {
                topC = balls[i];
            } else {
                isYES = false;
                break;
            }
        }
        cout << (isYES ? "YES" : "NO") << endl;
    }
}

C++: #include <iostream>
using namespace std;
int main(){
  int n;
  cin >> n;
  for(int i=0;i<n;i++){
    int a[10];
    for (int j=0;j<10;j++)
    cin >> a[j];
    int left,right; left = a[0];
    right = 0;
    for (int j=1;j<10;j++){
      if(a[j]<left && a[j]<right){
        cout << "NO" << endl; break;
      } else{
        if(j==9){
          cout << "YES" << endl; break;
        } else{
          if(a[j]>left && a[j]<right)
            left = a[j];
          else{
            if(a[j]<left && a[j]>right)
              right = a[j]; else{ if(left<right) right = a[j];
          else left = a[j];
          }
          }
          }
          }
    }
  }
}

C++: #include<bits/stdc++.h>
#define rep(i,n) for(int i=0; i<n; i++)
#define INF 1000000
using namespace std;
int num[10];
bool check(int pos, int l, int r){
    if(pos >= 10) return true;
    if(l < num[pos]) if(check(pos+1,num[pos],r)) return true;
    if(r < num[pos]) if(check(pos+1,l,num[pos])) return true;
    return false;
}
int main(){
    int n;
    cin >> n;
    rep(i,n){
        rep(j,10) cin >> num[j];
        if(check(0,-1,-1)) cout << "YES" << endl;
        else cout << "NO" << endl;
    }
    return 0;
}

C++: #include<cstdio>
const int maxn = 15;
int n,arr[maxn];
int main(){
    scanf("%d",&n);
    while(n--){
        for(int i = 0;i < 10;++i)scanf("%d",&arr[i]);
        int b = 0,c = 0,flag = 1;
        for(int i = 0;i < 10;++i){
            if(b>arr[i]&&c>arr[i]){
                flag = 0;
                break;
            }else if(b<arr[i] && c<arr[i]){
                if(b<c)c = arr[i];
                else b = arr[i];
            }else if(b < arr[i]){
                b = arr[i];
            }else c = arr[i];
        }
        if(flag)printf("YES\n");
        else printf("NO\n");
    }
    return 0;
}

C++: #include <iostream>
#include <cstdio>
#include <iomanip>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <bitset>
#include <stack>
#include <utility>
#include <numeric>
#include <algorithm>
#include <functional>
#include <cctype>
#include <complex>
#include <string>
#include <sstream>

using namespace std;

#define all(c) c.begin(),c.end()
#define rall(c) c.rbegin(),c.rend()
#define rep(i,n) for(int i=0;i<(n);i++)
#define tr(it,container) for(typeof(container.begin()) it = container.begin(); \
                                                  it != container.end(); ++it)
#define mp(a,b) make_pair((a),(b))

typedef long long ll;
typedef complex<double> point;

// up right down left
const int dy[] = {-1,0,1,0};
const int dx[] = {0,1,0,-1};

const double EPS = 1e-9;
const int days[]     = {31,28,31,30,31,30,31,31,30,31,30,31};
const int daysleap[] = {31,29,31,30,31,30,31,31,30,31,30,31};

int main(){
    int N;
    cin >> N;
    for(int index_n=0;index_n<N;index_n++){
        vector<int> V(10);
        rep(i,10) cin >> V[i];
        // left,right,next
        queue<pair<pair<int,int>,int> > Q;
        Q.push(mp(mp(V[0],0),1));
        bool ok = false;
        while(!Q.empty()){
            int left = Q.front().first.first;
            int right = Q.front().first.second;
            int next = Q.front().second;
            Q.pop();

            if(next == 10){
                ok = true;
                break;
            }
            if(V[next] > left){
                Q.push(mp(mp(V[next],right),next+1));
            }
            if(V[next] > right){
                Q.push(mp(mp(left,V[next]),next+1));
            }
        }
        if(ok) cout << "YES" << endl;
        else cout << "NO" << endl;
    }
    return 0;
}

C++: #include <iostream>
#include <algorithm>

using namespace std;

int n;
int stock[2][11];
int usea[11];

int dfs(int num, int r_num, int l_num) {
	int res = 0;

	if (usea[num] > stock[0][r_num]) {
		if (num == 9)
			return 1;
		stock[0][r_num + 1] = num;
		res = dfs(num + 1, r_num + 1, l_num);
		stock[0][r_num + 1] = -1;
		return res;
	}
	else if (usea[num] > stock[1][l_num]) {
		if (num == 9)
			return 1;
		stock[1][l_num + 1] = num;
		res = dfs(num + 1, r_num, l_num + 1);
		stock[1][l_num + 1] = -1;
		return res;
	}
	else {
		return 0;
	}
}


int main()
{
	cin >> n;

	for (int i = 0; i < n; i++) {
		for (int j = 0; j < 10; j++) {
			cin >> usea[j];
		}
		stock[0][0] = -1;
		stock[0][1] = usea[0];
		stock[1][0] = -1;
		if (dfs(0, 1, 0)) {
			cout << "YES" << endl;
		}
		else {
			cout << "NO" << endl;
		}
		stock[0][0] = -1;
		stock[0][1] = -1;
		stock[1][0] = -1;
	}

	return 0;
}

C++: /*
P135
AOJ 0033 Ball
http://judge.u-aizu.ac.jp/onlinejudge/index.jsp

*/

#include <iostream>
#include <algorithm>
#include <cstdio>
#include <queue>
#include <functional>
#include <string.h>
using namespace std;

int W, H;
char board[110][110];
int a[10];
bool read()
{
    for(int i=0; i<10; ++i)
        scanf("%d", a+i);
}

bool isVisited[110][110];
int step;

void dfs(int x, int y, char c){
    if(x<0 || x>=H || y<0 || y>=W) return;
    if(board[x][y]!=c) return;
    if(isVisited[x][y]) return;
    isVisited[x][y] = true;
    dfs(x+1, y, c);
    dfs(x-1, y, c);
    dfs(x, y+1, c);
    dfs(x, y-1, c);
}

void solve()
{
    int x1=0, x2=0;
    bool ans = true;
    for(int i=0; i<10; ++i)
    {
        if(x1 < x2) swap(x1, x2);
        if(x1 < a[i]) x1 = a[i];
        else if(x2 < a[i]) x2 = a[i];
        else {ans = false; break;}
    }
    if(ans) printf("YES\n");
    else printf("NO");
}


int main()
{
    int T;
    scanf("%d", &T);
    while(T--){
        read();
        solve();
    }
}

C++: #include<iostream>

using namespace std;

int main(void){
	int a[11],fir,n;
	int i;
	cin>>n;
	while(n--){
		int sec = 0;
		for(i=0;i<10;i++){
			cin>>a[i];
		}
		fir=a[0];
		for(i=1;i<10;i++){
			if(fir<a[i])fir=a[i];
			else if(sec<a[i])sec=a[i];
			else break;
		}
		if(i==10)cout<<"YES"<<endl;
		else cout<<"NO"<<endl;
	}
	return 0;

}

C++: #include <iostream>

using namespace std;

//Aoj 0033

int ball[15], l[15],r[15];

bool res= false;

void dfs(int i,int j,int k){//i 为当年需要落下的球,j 表示左边最上面球的上一位置，k 表示最右边球的上一位置
    if(i>=10){
        res=true;
        return;
    }
//    if(res){
//        return;
//    }
    if(ball[i]>l[j-1]){
        l[j]=ball[i];
        dfs(i+1,j+1,k);
    }
    if(ball[i]>r[k-1]){
        r[k]=ball[i];
        dfs(i+1,j,k+1);
    }

}

int main(){
    int n;
    cin>>n;
    while(n--){
        res= false;
        for(int i=0;i<10;i++){
            cin>>ball[i];
        }
        dfs(0,1,1);
        if(res){
            cout<<"YES"<<endl;
        }else{
            cout<<"NO"<<endl;
        }

    }
    return 0;
}