// Arup Guha
// 11/13/2015
// Solution to UCF 1987 HS Contest Problem: Mind Your P's and Q's

import java.util.*;

public class monotone {

	public static void main(String[] args) {

		Scanner stdin = new Scanner(System.in);
		while (stdin.hasNext()) {

			StringTokenizer tok = new StringTokenizer(stdin.nextLine());
			int n = tok.countTokens();

			// Read in values.
			int[] vals = new int[n];
			for (int i=0; i<n; i++)
				vals[i] = Integer.parseInt(tok.nextToken());

			// Set up DP algorithm.
			int[] dp = new int[n];
			dp[0] = 1;
			int res = 1;
			// Run DP.
			for (int i=1; i<n; i++) {
				int best = 1;
				for (int j=0; j<i; j++)
					if (vals[j] < vals[i])
						best = Math.max(best, dp[j]+1);
				dp[i] = best;
				res = Math.max(res, dp[i]);
			}

			// Echo input.
			for (int i=0; i<n; i++)
				System.out.printf("%5d", vals[i]);
			System.out.println();
			System.out.printf("THE LENGTH OF THE LONGEST INCREASING SUBSEQUENCE IS %d\n", res);
			System.out.println();
		}
	}
}