import sys

def solve():
    """
    Standard CP format for Longest Increasing Subsequence.
    Input: A single line of space-separated integers.
    Example: 10 9 2 5 3 7 101 18
    """
    # Read a single line and do not wait for EOF
    input_data = sys.stdin.readline().strip()
    if not input_data:
        return
    
    # Extract pure space-separated integers
    arr = list(map(int, input_data.split()))
    if not arr:
        return

    n = len(arr)
    dp = [1] * n
    parent = [-1] * n
    
    # DP formulation
    for i in range(1, n):
        for j in range(i):
            if arr[i] > arr[j] and dp[i] < dp[j] + 1:
                dp[i] = dp[j] + 1
                parent[i] = j
                
    max_len = max(dp)
    max_idx = dp.index(max_len)
    
    # Backtrack to reconstruct the Longest Increasing Subsequence
    lis = []
    curr = max_idx
    while curr != -1:
        lis.append(arr[curr])
        curr = parent[curr]
    
    lis.reverse()
    
    # Output formatting
    print(f"Length of LIS = {max_len}")
    print(f"LIS = {{{', '.join(map(str, lis))}}}")

if __name__ == '__main__':
    solve()