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>
#include<string.h>
#include<vector>
#include<list>
#include<stdio.h>
#define rep(i,a,b) for(int i = (a); i < (b); i++)
#define range(i,b) rep(i,0,b)
#define debug(x) cout << "debug " << x << endl;
using namespace std;

int main(){
	int a,b;
	int n;
	int input;
	bool check;

	while(cin >> n){
		range(i,n){
			a = b = 0;
			range(i,10){
				check = true;
				cin >> input;
				if(input > a){
					a = input;
				}else if(input > b){
					b = input;
				}else{
					check = false;
				}
			}
			if(check) cout << "YES" << endl;
			else cout << "NO" << endl;
		}
	}
}

C++: #include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <algorithm>
#include <sstream>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <numeric>
#include <cmath>
#include <climits>
#include <limits>
#include <cfloat>
#include <fstream>
using namespace std;

int main()
{
//	cut here before submit 
//	freopen("testcase.ball", "r", stdin);
	string str = "";
	int n;

	getline (cin, str );
	stringstream ssn(str);
	ssn >> n;

	int i,j;
	for (i = 0; i < n; ++i){
		vector <int> ball;
		getline (cin, str );
		stringstream ss(str);
		int b;
		while (ss >> b){
			ball.push_back(b);
		} // end while
		stack <int> A;
		stack <int> B;

		A.push (0);
		B.push (0);

		int size = ball.size();

		A.push (ball[0]);
		for (j = 1; j < size; ++j){
//			cout << "ball[" << j << "]: " << ball[j] << endl;
//			cout << "A:" << A.top() << " B: " << B.top() << endl;
			if (ball[j] < A.top() && ball[j] > B.top() ){
//				cout << "B in" << endl;
				B.push (ball[j]);
			}else if (ball[j] > A.top() && ball[j] < B.top() ){
//				cout << "A in" << endl;
				A.push (ball[j]);
			}else if (ball[j] > A.top() && ball[j] > B.top() ){
				if (ball[j] - A.top() < ball[j] - B.top() ){
//					cout << "A in" << endl;
					A.push (ball[j]);
				}else{
//					cout << "B in" << endl;
					B.push (ball[j]);
				} // end if 
			}else{
				cout << "NO" << endl;
				break;
			} // end if
		} // end for
		if (j == size ){
			cout << "YES" << endl;
		} // end if
	} // end for
		
	return 0;
}

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

int main(){
	int a;
	int b[10];
	cin>>a;
	
	for(int j=0;j<a;j++){
		
			int flg=0;
			
	for(int i=0;i<10;i++){
		cin>>b[i];
		}
		
		stack<int>ta,tb;
		ta.push(b[0]);
		tb.push(0);
		
		for(int k=1;k<10;k++){
			if(b[k]>ta.top()){ta.push(b[k]);}
			else if(b[k]>tb.top()){tb.push(b[k]);}
			else{
				flg++;
				break;
				}
			}
			if(flg==0){cout<<"YES"<<endl;}
			else{cout<<"NO"<<endl;}
		}
		return 0;
	}

C++: #include <cstdio>
#include <iostream>
#include <cstring>
#include <stdlib.h>
#include <cmath>
#include <algorithm>
#include <queue>
#include <cstdlib>
#include <stack>
using namespace std;
const int manx = 500;
stack <int> a;
stack <int> b;
int main()
{
    int n;
    scanf("%d",&n);
    while(n--)
    {
        int input;
        int flag = true;
        scanf("%d",&input);
        a.push(input);
        b.push(0);
        for(int i = 1 ; i < 10 ; i++)
        {
            scanf("%d",&input);
            int ai = input - a.top();
            int bi = input - b.top();
            if(ai <= 0 && bi <= 0)
            {
                flag = false;
                //printf("NO\n");
                break;
            }
            if(ai > 0 && bi <= 0)
                a.push(input);
            if(bi > 0 && ai <= 0)
                b.push(input);
            if(ai > 0 && bi > 0)
            {
                if(ai > bi )
                    b.push(input);
                if(ai <= bi)
                    a.push(input);
            }
        }
        if(flag == false)
            printf("NO\n");
        if(a.size() + b.size() == 11)
            printf("YES\n");
        while(!a.empty())
            a.pop();
        while(!b.empty())
            b.pop();
    }
    return 0;
}

C++: #include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <functional>

using namespace std;

class Pipe
{
private:
	queue<int> pipe;
	vector<int> a, b;
public:
	Pipe( queue<int> input )
	{
		pipe = input;
	}

	void pushA()
	{
		a.push_back( pipe.front() );
		pipe.pop();
	}

	void pushB()
	{
		b.push_back( pipe.front() );
		pipe.pop();
	}

	bool empty()
	{
		return pipe.size() == 0;
	}

	bool sorted()
	{
		for ( unsigned int i = 0; i + 1 < a.size(); i++ )
		{
			if ( a[i + 1] < a[i] )
			{
				return false;
			}
		}

		for ( unsigned int i = 0; i + 1 < b.size(); i++ )
		{
			if ( b[i + 1] < b[i] )
			{
				return false;
			}
		}

		return true;
	}
};

bool dfs()
{
	int buffer;
	queue<int> que;
	for ( int i = 0; i < 10; i++ )
	{
		cin >> buffer;
		que.push( buffer );
	}

	Pipe init( que );
	stack<Pipe> st;
	st.push( init );

	while ( !st.empty() )
	{
		Pipe current = st.top();
		st.pop();

		if ( current.empty() )
		{
			if ( current.sorted() )
			{
				return true;
			}
			else
			{
				continue;
			}
		}
		
		Pipe next = current;
		next.pushA();
		st.push( next );

		next = current;
		next.pushB();
		st.push( next );
	}

	return false;
}

int main()
{
	int n;

	cin >> n;

	for ( int i = 0; i < n; i++ )
	{
		cout << ( dfs() ? "YES" : "NO" ) << endl;
	}
	
	return 0;
}

C++: # include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <utility>
# include <stack>
# include <queue>
# include <list>
constexpr int MOD = 1000000007;
constexpr int INF = 2000000000;
using namespace std;

int main() {
	int n;
	cin >> n;
	for (int i = 0; i < n; i++) {
		int a = -1, b = -1;
		int num;
		bool ans = true;
		for (int j = 0; j < 10; j++) {
			if (a > b)swap(a, b);
			cin >> num;
			if (num > b)b = num;
			else if (num > a)a = num;
			else ans = false;
		}
		cout << (ans ? "YES" : "NO") << endl;
	}
}

C++: #include<iostream>
using namespace std;
int main(){
	int ball;
	int n;
	while(cin >> n){
		bool flag = true;
		int B=0, C=0;
		for(int i=0; i<n; i++){
			for(int j=0; j<10; j++){
				cin >> ball;
				if(flag){
					if(B < ball) B=ball;
					else if(C < ball) C=ball;
					else flag=false;
				}
			}
			if(flag) cout << "YES" << endl;
			else cout << "NO" << endl;
		}
	}
	return 0;
}

C++: #include<iostream>

using namespace std;

int main()
{
	int n,left,right,x,ans;
	
	cin>>n;
	while(n--)
	{
		left=0,right=0,ans=1;
		
		for(int i=0;i<10;++i)
		{
			cin>>x;
			if(x>left&&x>right)
			{
				if(left>right)
					left=x;
				else
					right=x;		
			}	
			else	if(x>left)
			{
				left=x;
			}
			else 	if(x>right)
			{
				right=x;
			}
			else
			{
				ans=0;
				break;
			}
		}	
		if(ans)
			cout<<"YES\n";
		else
			cout<<"NO\n";	
	}
	
	return 0;
}