import std.stdio, std.algorithm, std.string, std.conv, std.array;

void main()
{
    readln;
    foreach(input; stdin.byLine().map!(line => line.split.map!(to!int)))
    {
        int[] ary = 0 ~ input.array;
        int[11] dp, path;
        dp[0] = path[0] = 0;

        int maxI;
        foreach(i; 1..11)
        {
            int max = int.min, maxIndex;

            foreach(j; 0..i)
            {
                if(ary[i] > ary[j] && max < dp[j])
                {
                    max = dp[j];
                    maxIndex = j;
                }
            }

            dp[i] = max + 1;
            path[i] = maxIndex;

            if(dp[maxI] < max)
            {
                maxI = i;
            }
        }

        int[] removeIndex;
        for(int i = maxI; i != 0; i = path[i])
        {
            removeIndex ~= i;
        }

        int prev = int.min;
        bool flag = true;
        foreach(i; 1..11)
        {
            if(removeIndex.canFind(i)) continue;
            if(prev > ary[i])
            {
                flag = false;
                break;
            }
            else
            {
                prev = ary[i];
            }
        }
        (flag ? "YES" : "NO").writeln;
    }
}