//https://www.geeksforgeeks.org/construction-of-longest-increasing-subsequence-using-dynamic-programming/
#include <bits/stdc++.h>
using namespace std;
void func (int a[], int n) {
vector<vector<int>> dp(n);// dp[i] stores the LIS ending with a[i]
dp[0].push_back(a[0]);
vector<int> m= dp[0];
for (int i=1;i<n;i++) {
for (int j=0;j<i;j++) {
if (a[j]< a[i] && dp[i].size()<dp[j].size()+1) {
dp[i]= dp[j];
}
}
dp[i].push_back(a[i]);
if (m.size()<dp[i].size())
m= dp[i];
}
vector<int> ::iterator j;
for (j= m.begin(); j!= m.end(); ++j)
cout<< *j << " ";
}
int main() {
int n;
cin>>n;
int a[n];
for (int i=0;i<n;i++)
cin>> a[i];
func(a,n);
}
//https://www.geeksforgeeks.org/longest-increasing-subsequence-dp-3/
#include <iostream>
using namespace std;
int main() {
int n;
cin>>n;
int a[n];
for (int i=0;i<n;i++)
cin>> a[i];
int dp[n], m= INT_MIN;//dp[i] stores the length of LIS ending with a[i]
dp[0]= 0;
for (int i=1;i<n;i++) {
dp[i]=1;
for (int j=0;j<i;j++)
if (a[j]< a[i] && dp[i]<dp[j]+1)
dp[i]= 1+ dp[j];
if (m<dp[i])
m= dp[i];
}
cout<< "Length is: "<< m;
}