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<stdio.h>

int main(){

int n[11]={};
int m[11]={},p[11]={};
int N;
int P=0,M=0;
bool f=true;

while(1){
scanf("%d",&N);if(N==0)break;

for(int i=0;i<10;i++)
scanf("%d",&n[i]);

for(int i=0;i<10;i++)
if(m[M]<n[i]){M++;m[M]=n[i];}
else if(p[P]<n[i]){P++;p[P]=n[i];}
else f=false;
}

if(f=true)printf("YES\n");
else printf("NO\n");

for(int i=0;i<10;i++)
{p[i]=0;m[i]=0;}

bool f=true;
P=0,M=0;


}
return 0;
}

C++: #include <iostream>
#include <stdio.h>
using namespace std;
int main() {
  int b[10],z,x,n,i;
  cin >> n;
  for (n;n>0;n--) {
	  cin >> b[0] >> b[1] >> b[2] >> b[3] >> b[4] >> b[5] >> b[6] >> b[7] >> b[8] >> b[9];
      z=0; x=0;
	  for (i=0;i<10;i++) {
		  if (b[i]<x && b[i]<z) { i=20; break; }
		  if (z>x) { if (b[i]<z) x=b[i]; else z=b[i];} 
		  else {if (b[i]<x) z=b[i]; else x=b[i];} 
		   
	  }
	  if (i<20) cout << "YES" << endl; else cout << "NO" << endl;
  }
 return 0;
  }

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

int BALLNUM = 10;

	static int data[10];
class balldata
{
private:
	//static std::vector <int> data;
	//int ballnum;
public:
	balldata(int datanum);
	static void enter();
	static void answer();
	static bool check();
	static bool check(int num,int right,int left);
};




int main()
{
	balldata ball(BALLNUM);

int N;
	std::cin >> N;
	for (int i = 0; i < N; i++)
	{
		ball.enter();
		ball.answer();
	}
}


balldata::balldata(int datanum)
{
	//ballnum = datanum;
	//data.resize(datanum);
}



void balldata::enter()
{
	for (int i = 0; i < 10; i++)
	{
		std::cin >> data[i];
	}
	return;
}

bool balldata::check(int num,int right,int left)
{
	//if (num == data.size())return true;
	if (num == 10)return true;
	if (balldata::check(num + 1, right, data[num])&&left<data[num]){ return true; }
	if (balldata::check(num + 1, data[num], left)&&right<data[num]){ return true; }

	return false;
}
bool check()
{
	return balldata::check(0, 0, 0);
}

void balldata::answer()
{ 
	if (balldata::check(0, 0, 0))
	{
		std::cout << "YES" << std::endl;
	}
	else
	{
		std::cout << "NO" << std::endl;
	}
}

C++: #include<cstdio>  
int a,l1,l2,n;
bool f;
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
	    f=0;l1=0;l2=-1;
		for(int j=1;j<=10;j++)
		{
			scanf("%d",&a);
			if(!f&&a<l2&&a<l1){printf("NO\n");f=1;continue;}
			if(!f&&l1>l2)
			{
				if(l1<a)l1=a;
				else l2=a;
			} 
			if(!f&&l2>l1)
			{
				if(l2<a)l2=a;
				else l1=a;
			}
		}
		if(!f)printf("YES\n");
	}
}

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

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

int main(void)
{
    int n;
    scanf("%d", &n);
    for (int i = 0; i < n; i++){
        queue < int > b, c;
        bool flag = true;
        
        b.push(0);
        c.push(0);
        
        int tmp;
        for (int i = 0; i < 10; i++){
            scanf("%d", &tmp);
            if (b.back() < tmp){
                b.push(tmp);
                if (i == 9) printf("YES\n");
            }
            else if (c.back() < tmp){
                c.push(tmp);
                if (i == 9) printf("YES\n");
            }
            else flag = false;
        }
        if (!flag) printf("NO\n");
    }
    
    return (0);
}

C++: #include<stdio.h>
#include<algorithm>
using namespace std;
int a[10],left[10],right[10];
void dfs(int i,int l,int r)
{
	if(i>9)
	{
		printf("YES\n");
		return;
	}
	else if(a[i]>left[l-1])
	{
		left[l++]=a[i++];
		dfs(i,l,r);
	}
	else if(a[i]>right[r-1])
	{
		right[r++]=a[i++];
		dfs(i,l,r);
	}
	else
	{
		printf("NO\n");
		return;
	}
}
int main()
{
	int t; 
	scanf("%d",&t);
	while(t--)
	{
		memset(a,0,sizeof(a));
		memset(left,0,sizeof(left));
		memset(right,0,sizeof(right));
		for(int i=0;i<10;i++)
			scanf("%d",&a[i]);
		dfs(0,1,1);
	}
	return 0;
}

C++: // http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0033

#include <iostream>
#include <tuple>
#include <stack>
using namespace std;

typedef tuple<int, int, int> st;

int main() {
  int N;
  cin >> N;
  for (auto i=0; i<N; i++) {
    int X[10];
    for (auto j=0; j<10; j++) {
      cin >> X[j];
    }
    stack<st> S;
    S.push(make_tuple(0, 0, 0));
    while (!S.empty()) {
      int now = get<0>(S.top());
      if (now == 10) goto EXIT;
      int R[2] = { get<1>(S.top()), get<2>(S.top()) };
      S.pop();
      int A = X[now];
      for (auto k=0; k<2; k++) {
	if (R[k] < A) {
	  S.push(make_tuple(now+1, A, R[(k+1)%2]));
	}
      }
    }
    printf("NO\n");
    continue;
  EXIT:
    printf("YES\n");
    continue;
  }
}

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

int main()
{
    int N;
    scanf("%d",&N);
    for(int i=0;i<N;++N) {
        int ball[10],index=0;
        bool flag=true;
        for(int i=0;i<10;++i) {
            scanf("%d",&ball[i]);
        }
        while(index+2 <= 9) {
            if(ball[index] < ball[index+1]) {
                ++index;
                continue;
            } else if (ball[index] < ball[index+2]) {
                ++index;
                continue;
            } else {
                flag=false;
                break;
            }
        }
        if (flag) {
            puts("YES");
        } else {
            puts("NO");
        }
    }
    return 0;
}

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;
		int j=10;
		while(j--){
			cin>>x;
			balls.push_back(x);
		}
		if(dfs(1,-1,-1,10)){
			cout<<"YES"<<endl;
		}else cout<<"NO"<<endl;
		balls.clear();
	}
}