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<cstdio>
int n, a[10];
int b[11] = { }, c[11] = { };

bool
dfs (int l, int r)
{
  if (l + r == 10)
    return true;
  if (b[l] < a[l + r])
    {
      b[l + 1] = a[l + r];
      return dfs (l + 1, r);
    }
  else if (c[r] < a[l + r])
    {
      c[r + 1] = a[l + r];
      return dfs (l, r + 1);
    }
  return false;
}

int
main (void)
{
  scanf ("%d", &n);
  for (int i = 0; i < n; i++)
    {
      for (int j = 0; j < 10; j++)
	scanf ("%d", &a[j]);
      if (dfs (0, 0))
	puts ("YES");
      else
	puts ("NO");
    }
  return 0;
}

C++: #include <iostream>
#include <algorithm>
using namespace std;
int main(){
	int n;
	cin >> n;
	for(int i=0;i<n;i++){
		int a,m1=0,m2=0;
		bool ans=true;
		for(int j=0;j<10;j++){
			cin >> a;
			if(m1<a) m1=a;
			else if(m2<a) m2=a;
			else ans=false;
			if(m1<m2) swap(m1,m2);
		}
		cout << (ans ? "YES" : "NO") << endl;
	}
	return 0;
}

C++: #include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <list>
#include <set>
#include <map>
#include <bitset>

using namespace std;

#define FOR(x) for(int i = 0; i < x; i++)


stack<short> x, y;
short a[10], n, j, i;

bool solve(short c, bool judge){
	if(c == 10) return true;
	if(x.top() < a[c]){
		x.push(a[c]);
		if(solve(c + 1, true)) return true;
	}
	if(y.top() < a[c]){
		y.push(a[c]);
		if(solve(c + 1, false)) return true;
	}
	if(judge) x.pop();
	else y.pop();
	return false;
}

int main(){
	scanf("%d", &n);
	for(i = 0; i < n; i++){
		x.push(0);
		y.push(0);
		for(j = 0; j < 10; j++)
			scanf("%d", &a[j]);
		if(solve(0, true)) printf("YES\n");
		else printf("NO\n");
	}
	return 0;
}

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

using namespace std;

int main()
{
    int N;
    cin >> N;
    while (N--) {
        vector<int> a(10);
        for (int i = 0; i < 10; i++) {
            cin >> a[i];
        }
        bool pos = 1;
        stack<int> st[2];
        st[0].push(a[0]);
        for (int i = 1; i < 10; i++) {
            bool use = 0;
            for (int j = 0; j < 2; j++) {                
                if (st[j].empty() || st[j].top() < a[i]) {
                    st[j].push(a[i]);
                    use = 1;
                    break;
                }
            }
            if (!use) {
                pos = 0;
                break;
            }
        }
        cout << (pos ? "YES" : "NO") << endl;
    }
    return 0;
}

C++: #include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<utility>
#include<cstdio>
#include<cstdlib>
#include<cmath>

using namespace std;
typedef pair<int,int> PII;
typedef long long ll;

int main(){
  int n,a,b,c,i;
	cin>>n;
	for(;n>0;n--){
		a = b = 0;
		for(i=0;i<10;i++){
			cin>>c;
			if(a >= b && c > a)
				a = c;
			else if(c > b)
				b = c;
			else
				break;
		}
		if(i==10)cout<<"YES"<<endl;
		else cout<<"NO"<<endl;
	}
  return 0;
}

C++: #include <iostream>
#include <stack>
#include <tuple>
using namespace std;
 
int main() {
    int n, balls[10]; cin >> n;
    while(n--){
        for(int i = 0; i < 10; i++) cin >> balls[i];
         
        enum {IDX, B, C};
        stack<tuple<int, int, int> > states;

        bool sortable = false;
        states.push(make_tuple(0,0,0));
        while(!states.empty()){
            tuple<int, int, int> now = states.top();
            states.pop();

            int idx = get<IDX>(now);
            if(idx < 10){
                if(get<B>(now) < balls[idx]){
                    if(idx == 9){
                        sortable = true; break;
                    }
                    states.push(make_tuple(idx+1,balls[idx],get<C>(now)));
                }
                if(get<C>(now) < balls[idx]){
                    if(idx == 9){
                        sortable = true; break;
                    }
                    states.push(make_tuple(idx+1,get<B>(now),balls[idx]));
                }
            }
        }

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

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

using namespace std;

int n;
int data[11];
int l,r;
bool fla;

void solve(){
    scanf("%d",&n);
    while(n--){

        for(int i = 1; i <= 10; i++){
            scanf("%d",&data[i]);
        }

        l = 0;
        r = 0;
        fla = true;

        for(int i = 1; i <= 10; i++){
            if(data[i] > l && data[i] > r){
                if(l > r){
                    l = data[i];
                }else{
                    r = data[i];
                }
            }else if(data[i] > l && data[i] < r){
                l = data[i];
            }else if(data[i] > r && data[i] < l){
                r = data[i];
            }else{
                fla = false;
                break;
            }
        }

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

    }
}

int main(void){

    solve();

    return 0;
}

C++: #include <cstdio>

int b[13];

int main()
{
	int n;
	int l=0,r=0,i=0;
	int flag=true;
	scanf("%d",&n);
	++n;
	while (--n)
	{
		for (i=0;i<10;++i)
		{		
			scanf("%d",b+i);
			if (b[i]<l&&b[i]<r)
			{
				printf("NO\n");
				flag=false;
				break;
			}
			else if (b[i]>l&&b[i]<r)
			{
				l=b[i];
			}
			else if (b[i]<l&&b[i]>r)
			{
				r=b[i];
			}
			else if (b[i]>l&&b[i]>r)
			{
				if(b[i]-r>b[i]-l)
				{
					l=b[i];
				}
				else
				{
					r=b[i];
				}
			}
			else
			{
				printf("NO\n");
				flag=false;
				break;
			}
// 			printf("%d~ l,r=%d,%d\n",i,l,r);
		}
		if (flag)
		{
			printf("YES\n");
		}
		else
		{
			++i;
			while (i<10)//跳&#35835;！！
			{
				scanf("%d",b+i);
				++i;
			}
		}
		flag=true;
		l=r=0;
	}
	return 0;
	

}

C++: #include <iostream>

using namespace std;

int main()
{
    int n;
    int a1, a2, b1, b2;

    cin >> n;
    for (int i = 0; i < n; i++) {
        bool ck = true;

        cin >> a1 >> b1;
        for (int j = 0; j < 4; j++) {
            cin >> a2 >> b2;

            if (a2 < a1 || b2 < b1) {
                ck = false;
                break;
            }
            a1 = a2;
            b1 = b2;

        }

        if (ck == true) 
            cout << "YES" << endl;
        else
            cout << "NO" << endl;
    }

    return 0;
}

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

int main() {
	int n1=0,n2=0,num,temp,flg=1;
	cin>>num;
	while(num--){
		for(int i=0;i<10;i++){
			cin>>temp;
			if(temp<n1&&temp<n2) flg=0;
			if(temp>n1) n1=temp;
			else if(temp>n2) n2=temp;
		}if(flg==1) cout<<"YES"<<endl;
		else cout<<"NO"<<endl;
	}return 0;
}

C++: #include <iostream>
#include <cstdio>
#include <stack>
using namespace std;
int main(void)
{
	int n,i,j;
	stack<int>s1,s2;
	int table[10];
	cin >> n;
	for(i=0;i<n;i++)
	{
		for(j=0;j<10;j++)
		{
			cin >> table[j];
		}
		s1.push(0);
		s2.push(0);
		for(j=0;j<10;j++)
		{
			if(s1.top()<table[j])
			{
				if(s2.top()<table[j])
				{
					if(s1.top()>s2.top())
					{
						s1.push(table[j]);
					}
					else
					{
						s2.push(table[j]);
					}
				}
				else
				{
					s1.push(table[j]);
				}
			}
			else
			{
				break;
			}
		}
		if(j==10)cout <<"YES"<< endl;
		else cout << "NO" << endl;
	}
	return 0;
}