#include <iostream>
using namespace std;
void main()
{
    int ini, inj;
    int iniend, injend;
    int outi = 0, outj = 0;
    int outiend, outjend;
    bool ur = true, dr = true, rc = true, lc = true;
    char a[60][60];
    //////////////////////////////////////////////   cin
    cin >> iniend >> injend;
    outiend = iniend;
    outjend = injend;
    for (ini = 0; ini < iniend; ini++)
    {
        for (inj = 0; inj < injend; inj++)
        {
            cin >> a[ini][inj];
        }
    }
    /////////////////////////////////////////////  remove  up rows
    for (ini = 0; ini < iniend; ini++)
    {
        for (inj = 0; inj < injend; inj++)
        {
            if (a[ini][inj] == '*')
            {
                ur = false;
            }
        }
        if (ur == true)
        {
            outi++;
        }
        else
        {
            break;
        }
    }
    /////////////////////////////////////////  remove down rows
    for (ini = iniend - 1; ini >= 0; ini--)
    {
        for (inj = injend - 1; inj >= 0; inj--)
        {
            if (a[ini][inj] == '*')
            {
                dr = false;
            }
        }
        if (dr == true)
        {
            outiend--;
        }
        else
        {
            break;
        }
    }
    //////////////////////////////////////  remove  left column
    for (inj = 0; inj < injend; inj++)
    {
        for (ini = 0; ini < iniend; ini++)
        {
            if (a[ini][inj] == '*')
            {
                lc = false;
            }
        }
        if (lc == true)
        {
            outj++;
        }
        else
        {
            break;
        }
    }
    /////////////////////////////////////   remove right column
    for (inj = injend - 1; inj >= 0; inj--)
    {
        for (ini = iniend - 1; ini >= 0; ini--)
        {
            if (a[ini][inj] == '*')
            {
                rc = false;
            }
        }
        if (rc == true)
        {
            outjend--;
        }
        else
        {
            break;
        }
    }
    //////////////////////////////////////   cout
    for (ini = outi; ini < outiend; ini++)
    {
        for (inj = outj; inj < outjend; inj++)
        {
            cout << a[ini][inj];
        }
        cout << endl;
    }
}


Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 2013
VisualStudioVersion = 12.0.21005.1
MinimumVisualStudioVersion = 10.0.40219.1
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "acm letter", "acm letter\acm letter.vcxproj", "{A84855D0-B619-4D60-8809-32CDF8072642}"
EndProject
Global
	GlobalSection(SolutionConfigurationPlatforms) = preSolution
		Debug|Win32 = Debug|Win32
		Release|Win32 = Release|Win32
	EndGlobalSection
	GlobalSection(ProjectConfigurationPlatforms) = postSolution
		{A84855D0-B619-4D60-8809-32CDF8072642}.Debug|Win32.ActiveCfg = Debug|Win32
		{A84855D0-B619-4D60-8809-32CDF8072642}.Debug|Win32.Build.0 = Debug|Win32
		{A84855D0-B619-4D60-8809-32CDF8072642}.Release|Win32.ActiveCfg = Release|Win32
		{A84855D0-B619-4D60-8809-32CDF8072642}.Release|Win32.Build.0 = Release|Win32
	EndGlobalSection
	GlobalSection(SolutionProperties) = preSolution
		HideSolutionNode = FALSE
	EndGlobalSection
EndGlobal


#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <bitset>
#include <list>
#include <cmath>
#include <algorithm>
#include <limits>
#include <cstdio>
#include <cstring>

using namespace std;

int main()
{
	int n, m;
	cin >> n >> m;
	string s[100];
	int mini=-1, minj=-1, maxi=-1, maxj=-1;

	for (int i=0; i<n; i++)
	{
		for (int j=0; j<m; j++)
		{
			char c;
			cin >> c;
			s[i].push_back(c);
			if (s[i][j] == '*')
			{
				maxi = i;
				maxj = j;
				if (mini == -1)
					{mini = i;
					minj = j;
				}}
		}
	}

	for (int i=mini; i<=maxi; i++)
	{
		for (int j=minj; j<=maxj; j++)
		{
			cout << s[i][j];
		}
		cout << endl;
	}
	return 0;
}


#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <bitset>
#include <list>
#include <cmath>
#include <algorithm>
#include <limits>
#include <cstdio>
#include <cstring>

using namespace std;

int main()
{
    int n, m;
    cin >> n >> m;
    string s[100];
    int mini=-1, minj=-1, maxi=-1, maxj=-1;

    for (int i=0; i<n; i++)
    {
        for (int j=0; j<m; j++)
        {
            char c;
            cin >> c;
            s[i].push_back(c);
            if (s[i][j] == '*')
            {
                maxi = i;
                maxj = j;
                if (mini == -1)
                    mini = i;
                if (minj == -1)
                    minj = j;
            }
        }
    }

    for (int i=mini; i<=maxi; i++)
    {
        for (int j=minj; j<=maxj; j++)
        {
            cout << s[i][j];
        }
        cout << endl;
    }
    return 0;
}


#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <bitset>
#include <list>
#include <cmath>
#include <algorithm>
#include <limits>
#include <cstdio>
#include <cstring>

using namespace std;

int main()
{
	int n, m;
	cin >> n >> m;
	string s[100];
	int mini=-1, minj=-1, maxi=-1, maxj=-1;

	for (int i=0; i<n; i++)
	{
		for (int j=0; j<m; j++)
		{
			char c;
			cin >> c;
			s[i].push_back(c);
			if (s[i][j] == '*')
			{
				if (i<mini || mini == -1)
					mini = i;
				if (j<minj || minj == -1)
					minj = j;
				if (i>maxi || maxi == -1)
					maxi = i;
				if (j>maxj || maxj == -1)
					maxj = j;

			}
		}
	}

	for (int i=mini; i<=maxi; i++)
	{
		for (int j=minj; j<=maxj; j++)
		{
			cout << s[i][j];
		}
		cout << endl;
	}
	return 0;
}


#include <iostream>

using namespace std;

int main()
{
    int n,m;
    cin>>n>>m;
    char **shap=new char *[n];
    for(int i=0;i<n;i++)
        shap[i]=new char [m];

    int rows,colums,row_count=0,colum_count=0;

    for(int i=0;i<n;i++)
    {
        for(int j=0;j<m;j++)
        {
            cin>>shap[i][j];
        }
    }
    for(int i=0;i<n;i++)
    {
        int j=0;
        for(j;j<m;j++)
        {
            if(shap[i][j]=='*')
            {
                rows=i;
                colums=j;
                break;
            }
        }
        if(shap[i][j]=='*')
        {
            break;
        }
    }
    for(int j=0;j<m;j++)
    {
        if(shap[rows][j]=='*')
        {
            colum_count+=1;
        }
    }
    for(int i=0;i<n;i++)
    {
        if(shap[i][colums]=='*')
        {
            row_count+=1;
        }
    }
    for(int i=rows;i<rows+row_count;i++)
    {
        for(int j=colums;j<colums+colum_count;j++)
        {
            cout<<shap[i][j];
        }
        cout<<endl;
    }
    return 0;
}


#include <iostream>

using namespace std;

int main()
{
    int n,m;
    cin>>n>>m;
    char **shap=new char *[n];
    for(int i=0;i<n;i++)
        shap[i]=new char [m];

    int rows,colums,rowe,colume;

    for(int i=0;i<n;i++)
    {
        for(int j=0;j<m;j++)
        {
            cin>>shap[i][j];
        }
    }
    bool e=false;
    for(int i=0;i<n;i++)
    {
        int j=0;
        for(j;j<m;j++)
        {
            if(shap[i][j]=='*')
            {
                rows=i;
                e=true;
                break;
            }
        }
        if(e==true)
        {
            break;
        }
    }
    e=false;
    for(int j=0;j<m;j++)
    {
        int i=0;
        for(i;i<n;i++)
        {
            if(shap[i][j]=='*')
            {
                colums=j;
                e=true;
                break;
            }
        }
        if(e==true)
        {
            break;
        }
    }

    for(int j=colums;j<m;j++)
    {
        int i=rows;
        for(i;i<n;i++)
        {
            if(shap[i][j]=='*')
                colume=j;
        }
    }
    for(int i=rows;i<n;i++)
    {
        int j=colums;
        for(j;j<m;j++)
        {
            if(shap[i][j]=='*')
                rowe=i;
        }
    }
    for(int i=rows;i<=rowe;i++)
    {
        for(int j=colums;j<=colume;j++)
        {
            cout<<shap[i][j];
        }
        cout<<endl;
    }
    return 0;
}


#include <iostream>

using namespace std;

int main()
{
    int n,m;
    cin>>n>>m;
    char **shap=new char *[n];
    for(int i=0;i<n;i++)
        shap[i]=new char [m];

    int rows,colums,row_count=0,colum_count=0;

    for(int i=0;i<n;i++)
    {
        for(int j=0;j<m;j++)
        {
            cin>>shap[i][j];
        }
    }
    for(int i=0;i<n;i++)
    {
        int j=0;
        for(j;j<m;j++)
        {
            if(shap[i][j]=='*')
            {
                rows=i;
                colums=j;
                break;
            }
        }
        if(shap[i][j]=='*')
        {
            break;
        }
    }
    for(int j=0;j<m;j++)
    {
        if(shap[rows][j]=='*')
        {
            colum_count+=1;
        }
    }
    for(int i=0;i<n;i++)
    {
        if(shap[i][colums]=='*')
        {
            row_count+=1;
        }
    }
    cout<<endl;
    for(int i=rows;i<rows+row_count;i++)
    {
        for(int j=colums;j<colums+colum_count;j++)
        {
            cout<<shap[i][j];
        }
        cout<<endl;
    }
    return 0;
}


#include <iostream>

using namespace std;

int main()
{
    int n,m;
    cin>>n>>m;
    char **shap=new char *[n];
    for(int i=0;i<n;i++)
        shap[i]=new char [m];

    int rows,colums,rowe,colume;

    for(int i=0;i<n;i++)
    {
        for(int j=0;j<m;j++)
        {
            cin>>shap[i][j];
        }
    }

    for(int i=0;i<n;i++)
    {
        int j=0;
        for(j;j<m;j++)
        {
            if(shap[i][j]=='*')
            {
                rows=i;
                colums=j;
                break;
            }
        }
        if(shap[i][j]=='*')
        {
            break;
        }
    }

    for(int j=0;j<m;j++)
    {
        if(shap[rows][j]=='*')
        {
            colume=j;
        }
    }

    for(int i=0;i<n;i++)
    {
        if(shap[i][colums]=='*')
        {
            rowe=i;
        }
    }

    cout<<endl;
    for(int i=rows;i<=rowe;i++)
    {
        for(int j=colums;j<=colume;j++)
        {
            cout<<shap[i][j];
        }
        cout<<endl;
    }
    return 0;
}


#include <iostream>

using namespace std;

int main()
{
    int n,m;
    cin>>n>>m;
    char **shap=new char *[n];
    for(int i=0;i<n;i++)
        shap[i]=new char [m];

    int rows,colums,rowe,colume;

    for(int i=0;i<n;i++)
    {
        for(int j=0;j<m;j++)
        {
            cin>>shap[i][j];
        }
    }

    for(int i=0;i<n;i++)
    {
        int j=0;
        for(j;j<m;j++)
        {
            if(shap[i][j]=='*')
            {
                rows=i;
                break;
            }
        }
        if(shap[i][j]=='*')
        {
            break;
        }
    }
    for(int j=0;j<m;j++)
    {
        int i=0;
        for(i;i<n;i++)
        {
            if(shap[i][j]=='*')
            {
                colums=j;
                break;
            }
        }
        if(shap[i][j]=='*')
        {
            break;
        }
    }
    for(int j=colums;j<m;j++)
    {
        int i=rows;
        for(i;i<n;i++)
        {
            if(shap[i][j]=='*')
                colume=j;
        }
    }
    for(int i=rows;i<n;i++)
    {
        int j=colums;
        for(j;j<m;j++)
        {
            if(shap[i][j]=='*')
                rowe=i;
        }
    }
    cout<<endl;
    for(int i=rows;i<=rowe;i++)
    {
        for(int j=colums;j<=colume;j++)
        {
            cout<<shap[i][j];
        }
        cout<<endl;
    }
    return 0;
}


#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <queue>
#include <iomanip>
#include <cstdio>
#include <limits>
#include <cmath>
#include <cstdlib>
#include <string.h>
#include <ctime>

using namespace std;

#define VI vector<int>
#define VVI vector<VI >
#define VB vector<bool>
#define VVB vector<VB >
#define VC vector<char>
#define VVC vector<VC >
#define VS vector<string>
#define PII pair<int, int>
#define VPII vector<pair<int, int> >
#define REP(var, startFrom, endTo) for(int var = startFrom; var < (int)endTo; ++var)

template <typename T>
inline const T MAX(T a, T b) { return ((a) > (b) ? (a) : (b)); }
template <typename T>
inline const T MIN(T a, T b) { return ((a) > (b) ? (b) : (a)); }
template <typename T>
inline const T ABS(T a) { return (((a) > 0) ? (a) : (-(a))); }

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
#ifndef ONLINE_JUDGE
	freopen("tmp.in", "r", stdin);
//	freopen("tmp.out", "w", stderr);
#endif
	int n, m;
	cin >> n >> m;

	int startY, startX, endY, endX;
	bool first = true;

	int curX;
	VVC board = VVC(n, VC(m));
	REP(i, 0, n)
		REP(j, 0, m)
	{
		cin >> board[i][j];

		if (board[i][j] == '*')
		{
			if (first)
			{
				startY = i;
				startX = j;
				first = false;
			}

			if (j < startX)
				startX = j;
			endY = i;
			endX = j;
		}
	}

	for (int y = startY; y <= endY; ++y)
	{
		for (int x = startX; x <= endX; ++x)
			cout << board[y][x];
		cout << endl;
	}

	return 0;
}


#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <queue>
#include <iomanip>
#include <cstdio>
#include <limits>
#include <cmath>
#include <cstdlib>
#include <string.h>
#include <ctime>

using namespace std;

#define VI vector<int>
#define VVI vector<VI >
#define VB vector<bool>
#define VVB vector<VB >
#define VC vector<char>
#define VVC vector<VC >
#define VS vector<string>
#define PII pair<int, int>
#define VPII vector<pair<int, int> >
#define REP(var, startFrom, endTo) for(int var = startFrom; var < (int)endTo; ++var)

template <typename T>
inline const T MAX(T a, T b) { return ((a) > (b) ? (a) : (b)); }
template <typename T>
inline const T MIN(T a, T b) { return ((a) > (b) ? (b) : (a)); }
template <typename T>
inline const T ABS(T a) { return (((a) > 0) ? (a) : (-(a))); }

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
#ifndef ONLINE_JUDGE
	freopen("tmp.in", "r", stdin);
//	freopen("tmp.out", "w", stderr);
#endif
	int n, m;
	cin >> n >> m;

	int startY, startX, endY, endX;
	bool first = true;

	VVC board = VVC(n, VC(m));
	REP(i, 0, n)
		REP(j, 0, m)
	{
		cin >> board[i][j];

		if (board[i][j] == '*')
		{
			if (first)
			{
				startY = i;
				startX = j;
				first = false;
			}
			endY = i;
			endX = j;
		}
	}

	for (int y = startY; y <= endY; ++y)
	{
		for (int x = startX; x <= endX; ++x)
			cout << board[y][x];
		cout << endl;
	}

	return 0;
}


#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <queue>
#include <iomanip>
#include <cstdio>
#include <limits>
#include <cmath>
#include <cstdlib>
#include <string.h>
#include <ctime>

using namespace std;

#define VI vector<int>
#define VVI vector<VI >
#define VB vector<bool>
#define VVB vector<VB >
#define VC vector<char>
#define VVC vector<VC >
#define VS vector<string>
#define PII pair<int, int>
#define VPII vector<pair<int, int> >
#define REP(var, startFrom, endTo) for(int var = startFrom; var < (int)endTo; ++var)

template <typename T>
inline const T MAX(T a, T b) { return ((a) > (b) ? (a) : (b)); }
template <typename T>
inline const T MIN(T a, T b) { return ((a) > (b) ? (b) : (a)); }
template <typename T>
inline const T ABS(T a) { return (((a) > 0) ? (a) : (-(a))); }

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
#ifndef ONLINE_JUDGE
	freopen("tmp.in", "r", stdin);
//	freopen("tmp.out", "w", stderr);
#endif
	int n, m;
	cin >> n >> m;

	int startY = -1, startX = -1, endY = -1, endX = -1;
	bool first = true;

	VVC board = VVC(n, VC(m));
	REP(i, 0, n)
		REP(j, 0, m)
	{
		cin >> board[i][j];

		if (board[i][j] == '*')
		{
			if (first)
			{
				startY = i;
				startX = j;
				first = false;
			}

			if (j < startX)
				startX = j;
			if(j > endX)
				endX = j;
			endY = i;
		}
	}

	for (int y = startY; y <= endY; ++y)
	{
		for (int x = startX; x <= endX; ++x)
			cout << board[y][x];
		cout << endl;
	}

	return 0;
}


#include <iostream>
#include <string>
#include <vector>
using namespace std;

bool check(string x)
{
	for(int i=0;i<x.size();i++)
	{
		if(x[i]=='*')
			return 0;
	}
	return 1;
}

bool check2(vector<string>x,int y)
{
	for(int i=0;i<x.size();i++)
	{
		if(x[i][y]=='*')
			return 1;
	}
	return 0;
}

bool check3(vector<string>x,int y)
{
	for(int i=0;i<x.size();i++)
	{
		if(x[i][y]=='*')
			return 1;
	}
	return 0;
}

int main()
{
	int n,m,lines=0;
	bool flag=0;
	string s_temp;
	vector<string>list;
	cin>>n>>m;
	for(int x=0;x<n;x++)
	{
		cin>>s_temp;
		if(check(s_temp))
		{
			continue;
			flag=1;
		}
		else
			list.push_back(s_temp);

	}
	int start,end;
	for(int i=0;i<m;i++)
	{
		if(check2(list,i))
		{
			start=i;
			break;
		}
	}
	for(int i=(m-1);i>0;i--)
	{
		if(check3(list,i))
		{
			end=i;
			break;
		}
	}
	for(int i=0;i<list.size();i++)
	{
		for(int j=start;j<=end;j++)
			cout<<list[i][j];
		cout<<endl;
	}
	return 0;
}


#include <iostream>
#include <string>
#include <vector>
using namespace std;

int count_stars(string str,int x)
{
	int temp=0;
	for(int i=0;i<x;i++)
	{
		if(str[i]=='*')
			temp++;
	}
	return temp;
}

int main()
{
	int n,m; cin>>n>>m;
	int max=0;
	vector<string>list(n);
	vector<int>ch_list(n);
	for(int i=0;i<n;i++)
	{
		cin >> list[i];
		ch_list[i]=count_stars(list[i],m);
		if(count_stars(list[i],m)>max)
			max = count_stars(list[i],m);
	}

	for(int i=0;i<n;i++)
	{
		if(count_stars(list[i],m)==0)
			continue;
		if(max==m)
		{
			for(int p=0;p<n;p++)
			{
				cout<<list[p]<<endl;
			}
			break;
		}
		if(ch_list[i]<max)
		{
			for(int j=0;j<ch_list[i];j++)
				cout<<"*";
			for(int s=0;s<(max-ch_list[i]);s++)
				cout<<".";
		}
		else
		{
			for(int i=0;i<max;i++)
				cout<<"*";
		}
		cout<<endl;
	}
	return 0;
}


#include <iostream>
#include <string>
#include <vector>
using namespace std;

bool check(string x)
{
	for(int i=0;i<x.size();i++)
	{
		if(x[i]=='*')
			return 0;
	}
	return 1;
}

bool check2(vector<string>x,int y)
{
	for(int i=0;i<x.size();i++)
	{
		if(x[i][y]=='*')
			return 1;
	}
	return 0;
}

bool check3(vector<string>x,int y)
{
	for(int i=0;i<x.size();i++)
	{
		if(x[i][y]=='*')
			return 1;
	}
	return 0;
}

int main()
{
	int n,m,temp;
	bool flag=1;
	string s_temp;
	vector<string>list;
	cin>>n>>m;
	for(int x=0;x<n;x++)
	{
		cin>>s_temp;
		if((check(s_temp))&&(flag))
		{
			continue;
		}
		else
		{
			flag=0;
			list.push_back(s_temp);
		}
	}

	for(int i=(list.size()-1);i>0;i--)
	{
		if(check(list[i])&&(!flag))
			list.pop_back();
		else
			break;
	}

	int start,end;
	for(int i=0;i<m;i++)
	{
		if(check2(list,i))
		{
			start=i;
			break;
		}
	}
	for(int i=(m-1);i>0;i--)
	{
		if(check3(list,i))
		{
			end=i;
			break;
		}
	}
	for(int i=0;i<list.size();i++)
	{
		for(int j=start;j<=end;j++)
			cout<<list[i][j];
		cout<<endl;
	}
	return 0;
}


#include <iostream>
#include <string>
#include <vector>
using namespace std;

int count_stars(string str,int x)
{
	int temp=0;
	for(int i=0;i<x;i++)
	{
		if(str[i]=='*')
			temp++;
	}
	return temp;
}

int main()
{
	int n,m; cin>>n>>m;
	int max=0;
	vector<string>list(n);
	vector<int>ch_list(n);
	for(int i=0;i<n;i++)
	{
		cin >> list[i];
		ch_list[i]=count_stars(list[i],m);
		if(count_stars(list[i],m)>max)
			max = count_stars(list[i],m);
	}

	for(int i=0;i<n;i++)
	{
		if(count_stars(list[i],m)==0)
			continue;
		if(max==m)
		{
			for(int p=0;p<n;p++)
			{
				cout<<list[p]<<endl;
			}
			break;
		}
		if(ch_list[i]<max)
		{
			for(int j=0;j<ch_list[i];j++)
				cout<<"*";
			for(int s=0;s<(max-ch_list[i]);s++)
				cout<<".";
		}
		else
		{
			for(int i=0;i<max;i++)
				cout<<"*";
		}
		cout<<endl;
	}
	system("pause");
}


#include <iostream>
#include <string>
#include <vector>
using namespace std;

int count_stars(string str,int x)
{
	int temp=0;
	for(int i=0;i<x;i++)
	{
		if(str[i]=='*')
			temp++;
	}
	return temp;
}

int main()
{
	int n,m; cin>>n>>m;
	int max=0;
	vector<string>list(n);
	vector<int>ch_list(n);
	for(int i=0;i<n;i++)
	{
		cin >> list[i];
		ch_list[i]=count_stars(list[i],m);
		if(count_stars(list[i],m)>max)
			max = count_stars(list[i],m);
	}

	for(int i=0;i<n;i++)
	{
		if(count_stars(list[i],m)==0)
			continue;
		if(max==m)
		{
			cout<<list[i]<<endl;
			continue;
		}
		if(ch_list[i]<max)
		{
			for(int j=0;j<ch_list[i];j++)
				cout<<"*";
			for(int s=0;s<(max-ch_list[i]);s++)
				cout<<".";
		}
		cout<<endl;
	}
	return 0;
}


#include <iostream>
#include <string>
#include <vector>
using namespace std;

int count_stars(string str,int x)
{
	int temp=0;
	for(int i=0;i<x;i++)
	{
		if(str[i]=='*')
			temp++;
	}
	return temp;
}

int main()
{
	int n,m; cin>>n>>m;
	int max=0;
	vector<string>list(n);
	vector<int>ch_list(n);
	for(int i=0;i<n;i++)
	{
		cin >> list[i];
		ch_list[i]=count_stars(list[i],m);
		if(count_stars(list[i],m)>max)
			max = count_stars(list[i],m);
	}

	for(int i=0;i<n;i++)
	{
		if(count_stars(list[i],m)==0)
			continue;
		if(max==m)
		{
			cout<<list[i]<<endl;
			continue;
		}
		if(ch_list[i]<max)
		{
			for(int j=0;j<ch_list[i];j++)
				cout<<"*";
			for(int s=0;s<(max-ch_list[i]);s++)
				cout<<".";
		}
		else
		{
			for(int i=0;i<max;i++)
			{
				cout<<"*";
			}
		}
		cout<<endl;
	}
	return 0;
}


#include <iostream>
#include<string>
using namespace std;
int main()
{
    int n, m, i, j, x1=0, y1=0;
    cin>>n>>m;
    string *s;
    int x0=n, y0=m;
     s=new string [n];
    for (i=0; i<n; i++) {
        cin>>s[i];
        for (j=0; j<m; j++)
        if (s[i][j]=='*')
        {
            x0=min(i, x0); y0=min(j, y0);
            x1=max(i, x1); y1=max(j, y1);
        }
    }
    for (i=x0; i<=x1; i++) cout<<s[i].substr(y0, y1-y0+1)<<endl;
    return 0;
}


#include<iostream>
using namespace std;
char arr[51][51];
int main()
{
    int n,m,x=0,y=0,z=0,z2=0;
    cin>>n>>m;bool f=0,f2=0;
    for(int i=0;i<n;i++){for(int j=0;j<m;j++){cin>>arr[i][j];}}

    for(int i=0;i<n;i++){for(int j=0;j<m;j++){if(arr[i][j]=='*'){x=i;y=j;f=true;break;}}if(f)break;}

    for(int i=0;i<n;i++){for(int j=0;j<m;j++)if(arr[i][j]=='*'){z=i;z2=j;}}

   for(int i=x;i<=z;i++){for(int j=y;j<=z2;j++){cout<<arr[i][j];}cout<<"\n";}

    return 0;
}


#include "stdio.h"
#include <fstream>
#include <iostream>
#include <math.h>
#include <string>
#include <stack>
#include <list>
#include <vector>
#include <algorithm>
#include <queue>

using namespace std;

int main(){
	int n, m;
	cin >> n >> m;
	int mmin = m, mmax = 0, nmax = 0;

	bool check = true, first = false, right = false;

	vector<vector<char>> g;

	for (int i = 0; i < n; i++)
	{

		vector<char> t;
		for (int j = 0; j < m; j++)
		{

			char t2;
			cin >> t2;

			if (t2 == '*')
			{
				if (check) check = false;
				if (!first && j < mmin) mmin = j;
			}

			t.push_back(t2);

		}

		for (int j = m - 1; j >= 0; j--)
		{

			if (t[j] == '*' && j + 1 > mmax) mmax = j + 1;

		}

		if (!check) g.push_back(t);

	}

	for (int i = g.size() - 1; i >= 0; i--)
	{

		bool ch = true;
		for (size_t j = 0; j < g[i].size(); j++)
		{
			if (g[i][j] == '*') ch = false;
		}
		if (!ch)
		{
			nmax = i + 1;
			i -= m;
		}
	}

	for (size_t i = 0; i < nmax; i++)
	{

		for (int j = mmin; j < mmax; j++) cout << g[i][j];
		cout << endl;

	}

	return 0;
}


#include "stdio.h"
#include <fstream>
#include <iostream>
#include <math.h>
#include <string>
#include <stack>
#include <list>
#include <vector>
#include <algorithm>
#include <queue>

using namespace std;

int main(){
    int n, m;
    cin >> n >> m;
    int mmin = m, mmax = 0, nmax = 0;

    bool check = true, first = false, right = false;

    vector<vector<char>> g;

    for (int i = 0; i < n; i++)
    {

        vector<char> t;
        for (int j = 0; j < m; j++)
        {

            char t2;
            cin >> t2;

            if (t2 == '*')
            {
                if (check) check = false;
                if (!first && j < mmin) mmin = j;
            }

            t.push_back(t2);

        }

        for (int j = m - 1; j >= 0; j--)
        {

            if (t[j] == '*' && j + 1 > mmax) mmax = j + 1;

        }

        if (!check) g.push_back(t);

    }

    for (int i = g.size() - 1; i >= 0; i--)
    {

        bool ch = true;
        for (size_t j = 0; j < g[i].size(); j++)
        {
            if (g[i][j] == '*') ch = false;
        }
        if (!ch)
        {
            nmax = i + 1;
            i -= n;
        }
    }

    for (size_t i = 0; i < nmax; i++)
    {

        for (int j = mmin; j < mmax; j++) cout << g[i][j];
        cout << endl;

    }

    return 0;
}


#include <iostream>
using namespace std ;
int main ()
{
int n  ,m, imax=0, jmax=0;
cin >>n >> m;
char * p = new char [n * m] ;
int imin= n , jmin= m ;
 for ( int i = 0 ; i < n; i ++ )
 {
 for (int j =0 ; j < m ; j ++ )
 {
 cin >> p[j +i * m ] ;
 if ( p [j+i*m] =='*')
 {
 if ( i < imin) imin= i;
 if ( i > imax ) imax = i ;
 if( j< jmin ) jmin = j  ;
 if ( j > jmax ) jmax = j ;
 }}}
 for ( int i =imin; i <=imax ; i ++ )
 {
   for ( int j =jmin; j <=jmax; j ++)
   cout << p[j+m*i ] ;
   cout << endl ;
 }
    return 0 ;
}


#include <iostream>
using namespace std ;
int main ()
{
    int n , m ;
    cin >> n >> m;
    char *a = new char [n*m] ;
    bool * b = new bool [n+m];
    for (int i =0; i <n+m ; i ++ )
        b[i] = true ;

    for ( int i =0 ; i <n ; i++ )
    {
        for ( int j=0 ;j <m ;j ++ )
            {
                cin >> a[i*m +j ];
                if (a[i*m+j] == '*' )
                {
                    b[i]= false ;
                    b[n+j]= false ;
                }
    }
    }

    for ( int i = 0; i < n ; i++ )
    {
        if( !b[i])
        {
            for ( int j =0 ; j < m ; j ++ )
            if (! b[n+j] )
                cout << a[i*m+j] ;
            cout << endl ;
        }
    }
    return 0 ;
}


#include <iostream>
using namespace std ;
int main ()
{
int n  ,m, imax=0, jmax=0;
cin >>n >> m;
char * p = new char [n * m] ;
int imin= n , jmin= m ;
 for ( int i = 0 ; i < n; i ++ )
 {
 for (int j =0 ; j < m ; j ++ )
 {
 cin >> p[j +i * m ] ;
 if ( p [j+i*m] =='*')
 {
 if ( i < imin) imin= i;
 if ( i > imax ) imax = i ;
 if( j< jmin ) jmin = j  ;
 if ( j > jmax ) jmax = j ;
 }}}
 for ( int i =imin; i <=imax ; i ++ )
 {
   for ( int j =jmin; j <jmax; j ++)
   cout << p[j+m*i ] ;
   cout << endl ;
 }

    return 0 ;
}


#include <iostream>
using namespace std ;

int main ()
{
int n  ,m, imax=0, jmax=0;
cin >>n >> m;
char * p = new char [n * m] ;
int imin= n , jmin= m ;
 for ( int i = 0 ; i < n; i ++ )
 {
 for (int j =0 ; j < m ; j ++ )
 {
 cin >> p[j +i * m ] ;
 if ( p [j+i*m] =='*')
 {
 if ( i < imin) imin= i;
 if ( i > imax ) imax = i ;
 if( j< jmin ) jmin = j  ;
 if ( j > jmax ) jmax = j ;
 }}}
 for ( int i =0; i < n ; i ++ )
 {
 if ( ( i <= imax) && ( i >= imin))
   for ( int j =0; j <m; j ++)
   if ((j<=jmax)&& (j >= jmin )) cout << p[j+m*i ] ;
   cout << endl ;
 }

    return 0 ;
}


#include <iostream>
using namespace std  ;
int main ()
{
int n  ,m, imax, imin, jmax, jmin ;
cin >>n >> m;
char * p = new char [n * m] ;
 for ( int i = 0 ; i < n; i ++ )
 {
 for (int j =0 ; j < m ; j ++ )
 {
 cin >> p[j +i * m ] ;
 if ( p [j+i*m] =='*')
 {
 if ( i < imin) imin= i;
 if ( i > imax ) imax = i ;
 if( j< jmin ) jmin = j  ;
 if ( j > jmax ) jmax = j ;
 }}}
 for ( int i =0; i < n ; i ++ )
 {
 if ( ( i <= imax) && ( i >= imin))
   for ( int j =0; j <m; j ++)
   if ((j<=jmax)&& (j >= jmin )) cout << p[j+m*i ] ;
   cout << endl ;
 }

return 0 ;
}


#include<iostream>
#include<string>
using namespace std;
int main()
{
    int n, m, c = 0, d = 0, x, y; cin >> n >> m; x = n; y = m; string str[100]; bool z[100][100] = { 1 }; bool flag = true; for (int i = 0; i < n; i++)cin >> str[i];
    for (int i = 0; i < n; i++)
    {
        int j;
        for (j = 0; j < m; j++)
        {
            if (str[i][j] == '*'){ flag = false; break; }
        }
        if (flag){ for (j = 0; j < m; j++){ z[i][j] = 1; } }
        else flag = true;
    }
    for (int j = 0; j < m; j++)
    {

        int i;
        for (i = 0; i < n; i++)
        {
            if (str[i][j] == '*'){ flag = false; break; }
        }
        if (flag){ for (i = 0; i < n; i++)z[i][j] = 1; }
        else flag = true;
    }
    for (int i = 0; i < n; i++)
    {
        for (int j = 0; j < m; j++)if(!z[i][j])cout << str[i][j]; cout << endl;
    }
    return 0;
}


#include<iostream>
#include<string>
using namespace std;
int main()
{
    int n, m, c = 0, d = 0, x, y; cin >> n >> m; x = n; y = m; string str[100]; bool z[100][100] = { 1 }; bool flag = true; for (int i = 0; i < n; i++)cin >> str[i];
    for (int i = 0; i < n; i++)
    {
        int j;
        for (j = 0; j < m; j++)
        {
            if (str[i][j] == '*'){ flag = false; break; }
        }
        if (flag){ for (j = 0; j < m; j++){ z[i][j] = 1; } }
        else flag = true;
    }
    for (int j = 0; j < m; j++)
    {

        int i;
        for (i = 0; i < n; i++)
        {
            if (str[i][j] == '*'){ flag = false; break; }
        }
        if (flag){ for (i = 0; i < n; i++)z[i][j] = 1; }
        else flag = true;
    }
    flag = true;
    for (int i = 0; i < n; i++)
    {
        flag = true;
        for (int j = 0; j < m; j++)if (!z[i][j]){ flag = false; break; }
        for (int j = 0; j < m; j++)if (!z[i][j])cout << str[i][j]; if (!flag)cout << endl;
    }
    return 0;
}


#include<iostream>
#include<string>
using namespace std;
int main()
{
    int n, m, ln = -1, lm = -1, rn = -1, rm = -1;
    cin >> n >> m;
    char c[51][51];
    for (int i = 0; i<n; i++) {
        for (int j = 0; j<m; j++) {
            cin >> c[i][j];
            if (c[i][j] == '*') {
                if (ln == -1) ln = i;
                if (lm == -1 || j<lm) lm = j;
                if (rm== -1 || j> rm) rm= j;
                rn = i;
            }
        }
    }
    for (int i = ln; i <= rn; i++) {
        for (int j = lm; j <= rm; j++) {
            cout << c[i][j];
        }
        cout << endl;
    }
    return 0;
}


#include<iostream>
#include<string>
using namespace std;
int main()
{
    int n, m, c = 0, d = 0, x, y; cin >> n >> m; x = n; y = m; string str[100]; bool z[100][100] = { 1 }; bool flag = true; for (int i = 0; i < n; i++)cin >> str[i];
    for (int i = 0; i < n; i++)
    {
        int j;
        for (j = 0; j < m; j++)
        {
            if (str[i][j] == '*'){ flag = false; break; }
        }
        if (flag){ for (j = 0; j < m; j++){ z[i][j] = 1; } }
        else flag = true;
    }
    for (int j = 0; j < m; j++)
    {

        int i;
        for (i = 0; i < n; i++)
        {
            if (str[i][j] == '*'){ flag = false; break; }
        }
        if (flag){ for (i = 0; i < n; i++)z[i][j] = 1; }
        else flag = true;
    }
    for (int i = 0; i < n; i++)
    {
        if (!z[i][0])continue;
        for (int j = 0; j < m; j++)if(!z[i][j])cout << str[i][j]; cout << endl;
    }
    return 0;
}


#include<iostream>
#include<string>
using namespace std;
int main()
{
    int n, m, c = 0, d = 0, x, y; cin >> n >> m; x = n; y = m; string str[100]; bool z[100][100] = { 0 }; bool flag = true; for (int i = 0; i < n; i++)cin >> str[i];
    for (int i = 0; i < n; i++)
    {
        int j;
        for (j = 0; j < m; j++)
        {
            if (str[i][j] == '*'){ flag = false; break; }
        }
        if (flag){ for (j = 0; j < m; j++){ z[i][j] = 1; } }
        else flag = true;
    }
    for (int j = 0; j < m; j++)
    {

        int i;
        for (i = 0; i < n; i++)
        {
            if (str[i][j] == '*'){ flag = false; break; }
        }
        if (flag){ for (i = 0; i < n; i++)z[i][j] = 1; }
        else flag = true;
    }
    flag = true;
    for (int i = 0; i < n; i++)
    {
        flag = true;
        for (int j = 0; j < m; j++)if (!z[i][j]){ flag = false; break; }
        for (int j = 0; j < m; j++)if (!z[i][j])cout << str[i][j]; if (!flag)cout << endl;
    }
    return 0;
}


#include<iostream>
#include<string>
using namespace std;
int main()
{
    int n, m, c = 0, d = 0, x, y; cin >> n >> m; x = n; y = m; string str[100]; bool flag = true; for (int i = 0; i < n; i++)cin >> str[i];
    for (int i = 0; i < n; i++)
    {
        int j;
        for (j = 0; j < m; j++)
        {
            if (str[i][j] == '*'){ flag = false; break; }
        }
        if (flag){ if (i < n / 2)c++; else x--; }
        else flag = true;
    }
    for (int j = 0; j < m; j++)
    {

        int i;
        for (i = 0; i < n; i++)
        {
            if (str[i][j] == '*'){ flag = false; break; }
        }
        if (flag){ if (j < m / 2)d++; else y--; }
        else flag = true;
    }
    for (int i = c; i < x; i++)
    {
        for (int j = d; j < y; j++)cout << str[i][j]; cout << endl;
    }
    return 0;
}


#include <iostream>
#include <string>
using namespace std;
int main() {
	int n, m; cin >> n >> m;
	int x_min, x_max, y_min, y_max;
	char **mas=new char*[n];
	for(int i=0;i<n;i++) mas[i]=new char[m];

	for(int i=0;i<n;i++)
		for(int j=0;j<m;j++) cin >> mas[i][j];
	int count=0; bool flag=true;
	while(flag) {
		for(int i=0;i<m && flag;i++)
			if(mas[count][i]!='.') flag=false;
		count++; } count--;
	y_min=count;count=n-1;flag=true;
	while(flag) {
		for(int i=0;i<m && flag;i++)
			if(mas[count][i]!='.') flag=false;
		count--; } count++;
	y_max=count;count=0;flag=true;
	while(flag) {
		for(int i=0;i<n && flag;i++)
			if(mas[i][count]!='.') flag=false;
		count++; } count--;
	x_min=count;count=m-1;flag=true;
	while(flag) {
		for(int i=0;i<n && flag;i++)
			if(mas[i][count]!='.')
				flag=false;
		count--; } count++;
	x_max=count;
	for(int i=y_min;i<=y_max;i++) {
		for(int j=x_min;j<=x_max;j++)
			cout << mas[i][j] << ' ';
		cout << endl;
	}
	return 0;
}


#include <iostream>
#include <string>
using namespace std;
int main() {
	int n, m; cin >> n >> m;
	int x_min, x_max, y_min, y_max;
	char **mas=new char*[n];
	for(int i=0;i<n;i++) mas[i]=new char[m];

	for(int i=0;i<n;i++)
		for(int j=0;j<m;j++) cin >> mas[i][j];
	int count=0; bool flag=true;
	while(flag) {
		for(int i=0;i<m && flag;i++)
			if(mas[count][i]!='.') flag=false;
		count++; } count--;
	y_min=count;count=n-1;flag=true;
	while(flag) {
		for(int i=0;i<m && flag;i++)
			if(mas[count][i]!='.') flag=false;
		count--; } count++;
	y_max=count;count=0;flag=true;
	while(flag) {
		for(int i=0;i<n && flag;i++)
			if(mas[i][count]!='.') flag=false;
		count++; } count--;
	x_min=count;count=m-1;flag=true;
	while(flag) {
		for(int i=0;i<n && flag;i++)
			if(mas[i][count]!='.')
				flag=false;
		count--; } count++;
	cout << "4 count: " << count << endl;
	x_max=count;
	for(int i=y_min;i<=y_max;i++) {
		for(int j=x_min;j<=x_max;j++)
			cout << mas[i][j] << ' ';
		cout << endl;
	}
	return 0;
}


#include <iostream>
#include <string>
using namespace std;
int main() {
	int n, m; cin >> n >> m;
	int x_min, x_max, y_min, y_max;
	char **mas=new char*[n];
	for(int i=0;i<n;i++) mas[i]=new char[m];

	for(int i=0;i<n;i++)
		for(int j=0;j<m;j++) cin >> mas[i][j];
	int count=0; bool flag=true;
	while(flag) {
		for(int i=0;i<m && flag;i++)
			if(mas[count][i]!='.') flag=false;
		count++; } count--;
	y_min=count;count=n-1;flag=true;
	while(flag) {
		for(int i=0;i<m && flag;i++)
			if(mas[count][i]!='.') flag=false;
		count--; } count++;
	y_max=count;count=0;flag=true;
	while(flag) {
		for(int i=0;i<n && flag;i++)
			if(mas[i][count]!='.') flag=false;
		count++; } count--;
	x_min=count;count=m-1;flag=true;
	while(flag) {
		for(int i=0;i<n && flag;i++)
			if(mas[i][count]!='.')
				flag=false;
		count--; } count++;
	x_max=count;
	for(int i=y_min;i<=y_max;i++) {
		for(int j=x_min;j<=x_max;j++)
			cout << mas[i][j];
		cout << endl;
	}
	return 0;
}


#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
long  i, j, n, maxx = 1;
int main()
{
	cin >> n;
	vector<long> d(110000,0), a(n+100);
	for (i = 1; i <= n; i++) cin >> a[i];
	for (i = 1; i <= n; i++)
	{
		maxx = 0;
		for (j = 1; j*j <= a[i]; j++)
		{
			if (d[a[i] / j] > maxx && a[i] % j == 0)	maxx = d[a[i] / j];

			if (d[j] > maxx && a[i] % j == 0 && j > 1)	 maxx = d[j];
		}
		d[a[i]] = ++maxx;
		for (j = 1; j*j <= a[i]; j++)
		{
			if (a[i] % j == 0) d[a[i] / j] = max(d[a[i] / j], maxx);

			if (a[i] % j == 0 && j > 1)	d[j] = max(d[j], maxx);
		}
	}
	maxx = -1;
	for (i = 1; i <= n; i++)
		if (d[a[i]] >= maxx) maxx = d[a[i]];
	cout << maxx;
}


#include<iostream>
#include<algorithm>
#include<vector>
//#include<fstream>
using namespace std;
//fstream cin("input.txt");	 ofstream cout("output.txt");
long  i, j, n, maxx = 1, imax;
vector<long> d, a, f;
 long gcd(long  q,  long w)
{
	while (q > 0 && w > 0)
		(q > w) ? q = q%w : w = w%q;
	return q + w;
}
int main()
{
	cin >> n;
	a.resize(n + 10);
	f.resize(100010);
	d.resize(100010,0);
	for (i = 1; i <= n; i++)
	{
		cin >> a[i];
	//	cout << d[a[i]] << " ";
	}
	//cout<<endl;
	for (i = 1; i <= n; i++)

	{
		maxx = 0; imax = 0;
		for (j = 1; j*j <= a[i]; j++)
		{
			if (d[a[i] / j] > maxx && a[i] % j == 0)
				maxx = d[a[i] / j];

			if (d[j] > maxx && a[i] % j == 0 && j > 1)
				maxx = d[j];
		}
		//cout << maxx << "  ";
		d[a[i]] = maxx + 1;
		maxx+=1;
		for (j = 1; j*j <= a[i]; j++)
		{
			if (a[i] % j == 0)
				d[a[i] / j] = max(d[a[i]/j],maxx);

			if (a[i] % j == 0 && j > 1)
				d[j]=max(d[j],maxx);
		}

		/*if (maxx != 0) for (j = 2; j*j <= a[i]; j++)
		{
			if (a[i] % j == 0  && j<=imax)
			{
				d[j]=max(d[j],d[a[i]]);
				if ((a[i]/j)!=j && a[i]/j <=imax) d[a[i]/j]=max(d[a[i]/j],d[a[i]]);
			}
		}	 */
		//for (long y = 1; y <= n; y++) cout << d[a[y]] << " ";
		//cout << endl;
	}

	maxx = -1;
	for (i = 1; i <= n; i++)
	{
		if (d[a[i]] >= maxx) maxx = d[a[i]];
	}
	cout << maxx;
}


#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
long  i, j, n, maxx = 1;
int main()
{
	cin >> n;
	vector<long> d(n+10,0), a(n+10);
	for (i = 1; i <= n; i++)
	{
		cin >> a[i];
		maxx = 0;
		for (j = 1; j*j <= a[i]; j++)
		{
			if (d[a[i] / j] > maxx && a[i] % j == 0)	maxx = d[a[i] / j];

			if (d[j] > maxx && a[i] % j == 0 && j > 1)	 maxx = d[j];
		}
		d[a[i]] = ++maxx;
		for (j = 1; j*j <= a[i]; j++)
		{
			if (a[i] % j == 0) d[a[i] / j] = max(d[a[i] / j], maxx);

			if (a[i] % j == 0 && j > 1)	d[j] = max(d[j], maxx);
		}
	}
	maxx = -1;
	for (i = 1; i <= n; i++)
		if (d[a[i]] >= maxx) maxx = d[a[i]];
	cout << maxx;
}


#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
long gcd(long q, long w)
{
    while (q > 0 && w > 0)
        (q > w) ? q = q%w : w = w%q;
    return q + w;
}
 long lcm(long q, long w)
{
    return (q*w / gcd(q, w));
}
 long  i,j, n, l, r = 1, mom = 1, maxx = 1;
 vector<long> d,a,f;
 int main()
 {
     cin >> n;
     a.resize(n + 10);
     f.resize(100010);
     d.resize(100010);
     for (i = 1;i <= n;i++)

     {
         cin >> a[i];
         j = 2;
         maxx = 0;
         while (a[i] % j != 0 && a[i]>j) j++;

         for (j = j;j<a[i];j += j) { maxx = max(maxx, d[j]); if (d[j]) d[j]++; }

         d[a[i]] = maxx + 1;
     }
     maxx = -1;
     for (i = 1;i <= n;i++)
     {
         if (d[a[i]] > maxx) maxx = d[a[i]];
     }
     cout << maxx;
}


#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
long gcd(long q, long w)
{
    while (q > 0 && w > 0)
        (q > w) ? q = q%w : w = w%q;
    return q + w;
}
 long lcm(long q, long w)
{
    return (q*w / gcd(q, w));
}
 long  i,j, n, l, r = 1, mom = 1, maxx = 1;
 vector<long> d,a,f;
 int main()
 {
     cin >> n;
     a.resize(n + 10);
     f.resize(100010);
     d.resize(100010);
     for (i = 1;i <= n;i++)

     {
         cin >> a[i];
         maxx = 0;long imax = 0;
         for (j = 1;j*j < a[i];j++) { maxx = max(maxx, d[j]);imax = j; }
         d[a[i]] = maxx + 1;
         for (j = 2;j <= imax;j++) if (a[i] % j == 0) d[j]++;
     }
     maxx = -1;
     for (i = 1;i <= n;i++)
     {
         if (d[a[i]] > maxx) maxx = d[a[i]];
     }
     cout << maxx;
}


#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
long gcd(long q, long w)
{
    while (q > 0 && w > 0)
        (q > w) ? q = q%w : w = w%q;
    return q + w;
}
 long lcm(long q, long w)
{
    return (q*w / gcd(q, w));
}
 long  i,j, n, l, r = 1, mom = 1, maxx = 1;
 vector<long> d,a,f;
 int main()
 {
     cin >> n;
     a.resize(n + 10);
     f.resize(100010);
     d.resize(100010);
     for (i = 1;i <= n;i++)

     {
         cin >> a[i];
         j = 2;
         maxx = 0;
         while (a[i] % j != 0 && a[i]>j) j++;

         for (j = j;j<=a[i];j += j) { maxx = max(maxx, d[j]); if (d[j]) d[j]++; }

         d[a[i]] = maxx + 1;
     }
     maxx = -1;
     for (i = 1;i <= n;i++)
     {
         if (d[a[i]] > maxx) maxx = d[a[i]];
     }
     cout << maxx;
}


#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
long gcd(long q, long w)
{
    while (q > 0 && w > 0)
        (q > w) ? q = q%w : w = w%q;
    return q + w;
}
 long lcm(long q, long w)
{
    return (q*w / gcd(q, w));
}
 long  i,j, n, l, r = 1, mom = 1, maxx = 1;
 vector<long> d,a,f;
 int main()
 {
     cin >> n;
     a.resize(n + 10);
     f.resize(100010);
     d.resize(100010);
     for (i = 1;i <= n;i++)

     {
         cin >> a[i];
         j = 2;
         maxx = 0;
         while (a[i] % j != 0 && a[i]>j) j++;

         for (j = j;j<a[i];j += j) { maxx = max(maxx, d[j]);  d[j]++; }

         d[a[i]] = maxx + 1;
     }
     maxx = -1;
     for (i = 1;i <= n;i++)
     {
         if (d[a[i]] > maxx) maxx = d[a[i]];
     }
     cout << maxx;
}


#include<bits/stdc++.h>
using namespace std;
const int N=1e5+100;
int dp[N];
int a[N];
int n;
int fun(int i){
    //cout<<i<<' ';
    if(i==n-1)return 0;
    int &ret=dp[i];
    if(ret!=-1)return ret;
    ret=0;
    for(int j=i+1;j<n;j++){
        if(__gcd(a[i],a[j])>1){
            ret=1+fun(j);
            break;
        }
    }
    return ret;
}
int main(){
    scanf("%d",&n);
    for(int i=0;i<n;i++)scanf("%d",&a[i]);
    memset(dp,-1,sizeof dp);
    int mx=0;
    for(int i=0;i<n;i++){
        if(a[i]==1)continue;
        mx=max(mx,fun(i));
    }
    cout<<1+mx<<endl;
}


#include<bits/stdc++.h>
using namespace std;
const int N=1e5+100;
int dp[N];
int a[N];
int n;
int fun(int i){
    //cout<<i<<' ';
    if(i==n-1)return 1;
    int &ret=dp[i];
    if(ret!=-1)return ret;
    ret=0;
    for(int j=i+1;j<n;j++){
        if(__gcd(a[i],a[j])>1)ret=max(ret,1+fun(j));
    }
    return ret;
}
int main(){
    scanf("%d",&n);
    for(int i=0;i<n;i++)scanf("%d",&a[i]);
    memset(dp,-1,sizeof dp);
    int mx=0;
    for(int i=0;i<n;i++){
        if(a[i]==1)continue;
        mx=max(mx,fun(i));
    }
    cout<<mx<<endl;
}


#include<bits/stdc++.h>
using namespace std;
const int N=1e5+100;
int a[N],dp[N];
bitset<N>p;
int main(){
    int n;
    scanf("%d",&n);
    memset(a,0,sizeof a);
    while(n--){
        int x;
        scanf("%d",&x);
        a[x]++;
    }
    memset(dp,0,sizeof dp);
    int mx=1;
    for(int i=2;i<N;i++){
        if(!p[i]){
            int st=0;
            for(int j=i;j<N;j+=i){
                p[j]=1;
                if(a[j]){
                    dp[j]=max(dp[j],a[j]+dp[st]);
                    mx=max(mx,dp[j]);
                    st=j;
                }
            }
        }
    }
    cout<<mx<<endl;
}


#include<bits/stdc++.h>
using namespace std;
const int N=1e5+100;
vector<int>ed[N];
int a[N],dp[N];
bitset<N>p;
int main(){
    memset(a,0,sizeof a);
    memset(dp,0,sizeof dp);
    for(int i=2;i<N;i++)if(!p[i])for(int j=i;j<N;j+=i){
        p[j]=1;
        ed[j].push_back(i);
    }
    int n;
    scanf("%d",&n);
    int mx=1;
    for(int i=1;i<=n;i++){
        scanf("%d",&a[i]);
        int mn=0;
        for(int j=0;j<ed[a[i]].size();j++){
            mn=max(mn,dp[ed[a[i]][j]]);
        }
        for(int j=0;j<ed[a[i]].size();j++){
            int val=ed[a[i]][j];
            dp[val]=mn+1;
            mx=max(mx,val);
        }
    }
    cout<<mx+1<<endl;

}


#include<bits/stdc++.h>
using namespace std;
const int N=1e5+100;
int dp[N];
int a[N];
int n;
int fun(int i){
    //cout<<i<<' ';
    if(i==n-1)return 0;
    int &ret=dp[i];
    if(ret!=-1)return ret;
    ret=0;
    for(int j=i+1;j<n;j++){
        if(__gcd(a[i],a[j])>1)ret=max(ret,1+fun(j));
    }
    return ret;
}
int main(){
    scanf("%d",&n);
    for(int i=0;i<n;i++)scanf("%d",&a[i]);
    memset(dp,-1,sizeof dp);
    int mx=0;
    for(int i=0;i<n;i++){
        if(a[i]==1)continue;
        mx=max(mx,fun(i));
    }
    cout<<1+mx<<endl;
}


#include<bits/stdc++.h>
using namespace std;
const int N=1e5+100;
int a[N],dp[N];
bitset<N>p;
int main(){
    int n;
    scanf("%d",&n);
    while(n--){
        int x;
        scanf("%d",&x);
        a[x]=1;
    }
    memset(dp,0,sizeof dp);
    int mx=1;
    for(int i=2;i<N;i++){
        if(!p[i]){
            int st=0;
            for(int j=i;j<N;j+=i){
                p[j]=1;
                if(a[j]){
                    dp[j]=max(dp[j],1+dp[st]);
                    mx=max(mx,dp[j]);
                    st=j;
                }
            }
        }
    }
    cout<<mx<<endl;
}


#include<bits/stdc++.h>
using namespace std;
const int N=1e5+100;
vector<int>ed[N];
int a[N],dp[N];
bitset<N>p;
int main(){
    memset(a,0,sizeof a);
    memset(dp,0,sizeof dp);
    for(int i=2;i<N;i++)if(!p[i])for(int j=i;j<N;j+=i){
        p[j]=1;
        ed[j].push_back(i);
    }
    int n;
    scanf("%d",&n);
    int mx=1;
    for(int i=1;i<=n;i++){
        scanf("%d",&a[i]);
        int mn=0;
        //cout<<a[i]<<' ';
        for(int j=0;j<ed[a[i]].size();j++){
            mn=max(mn,dp[ed[a[i]][j]]);
           // cout<<ed[a[i]][j]<<' ';
        }
        for(int j=0;j<ed[a[i]].size();j++){
            int val=ed[a[i]][j];
            dp[val]=mn+1;
            mx=max(mx,dp[val]);
        }
        //cout<<mn<<endl;
    }
    cout<<mx<<endl;

}


#include<bits/stdc++.h>
using namespace std;
const int N=1e5+100;
int dp[N];
int a[N];
int n;
int fun(int i){
    //cout<<i<<' ';
    if(i==n-1)return 0;
    int &ret=dp[i];
    if(ret!=-1)return ret;
    ret=0;
    for(int j=i+1;j<n;j++){
        ret=max(ret,((__gcd(a[i],a[j])>1)?1:0)+fun(j));
    }
    return ret;
}
int main(){
    scanf("%d",&n);
    for(int i=0;i<n;i++)scanf("%d",&a[i]);
    memset(dp,-1,sizeof dp);
    cout<<1+fun(0)<<endl;
}


#include<bits/stdc++.h>
using namespace std;
const int N=1e5+100;
int a[N],dp[N];
bitset<N>p;
int main(){
    int n;
    scanf("%d",&n);
    while(n--){
        int x;
        scanf("%d",&x);
        a[x]=1;
    }
    memset(dp,0,sizeof dp);
    int mx=0;
    for(int i=2;i<N;i++){
        if(!p[i]){
            int st=0;
            for(int j=i;j<N;j+=i){
                p[j]=1;
                if(a[j]){
                    dp[j]=max(dp[j],1+dp[st]);
                    mx=max(mx,dp[j]);
                    st=j;
                }
            }
        }
    }
    cout<<mx<<endl;
}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> ii;
typedef pair<ll,ll> pll;
typedef pair<double,double> pdd;

#define fill(a,x) memset(a,x,sizeof(a))
#define all(x) x.begin(), x.end()
#define tr(x,it) for( auto it = x.begin(); it!=x.end(); ++it)
#define rtr(x,it) for( auto it = x.rbegin(); it!=x.rend(); ++it)
#define sz(a) int((a).size())
#define pb push_back
#define F first
#define S second
#define FOR(i,a,b) for(int i = a; i<=b; ++i)
#define NFOR(i,a,b) for(int i = a; i>=b; --i)
#define fast ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);
#define debug(x) cerr << #x << " = " << x << "\n"
//#define ONLINE
#define CASE(t) cout << "Case " << t << ": ";

#ifdef ONLINE
 FILE *fin = freopen("cubes.in","r",stdin);
 //FILE *fout = freopen("out.txt","w",stdout);
#endif

const ll INF = 1e18;
const int mod = 1e9+7;
const int N = 1e5+10;
const int L = 10;
const double eps = 1e-9;
const int BIG = 1e6;

int a[N],dp[N];
set<int> s;
int main(){

  clock_t tm = clock();
  fast;
  int __t = 1;
  //cin >> __t;
  FOR(_t,1,__t){
      int n;
      cin >> n;
      FOR(i,0,n-1){
      	cin >> a[i];
      }
      FOR(i,0,n-1)dp[i]=1;
      FOR(i,0,n-1){
      	tr(s,it){
      		if(__gcd(a[-*it],a[i]) > 1){
      			dp[i] += dp[-*it];
      			s.erase(it);
      			break;
      		}
      	}
      	s.insert(-i);
      }
      int maxi =0;
      FOR(i,0,n-1){
      	maxi = max(maxi,dp[i]);
      }
      cout << maxi << "\n";

  }
  tm = clock()-tm ;
  cerr << (float)(tm)/CLOCKS_PER_SEC << "\n";
  return 0;
}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> ii;
typedef pair<ll,ll> pll;
typedef pair<double,double> pdd;

#define fill(a,x) memset(a,x,sizeof(a))
#define all(x) x.begin(), x.end()
#define tr(x,it) for( auto it = x.begin(); it!=x.end(); ++it)
#define rtr(x,it) for( auto it = x.rbegin(); it!=x.rend(); ++it)
#define sz(a) int((a).size())
#define pb push_back
#define F first
#define S second
#define FOR(i,a,b) for(int i = a; i<=b; ++i)
#define NFOR(i,a,b) for(int i = a; i>=b; --i)
#define fast ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);
#define debug(x) cerr << #x << " = " << x << "\n"
//#define ONLINE
#define CASE(t) cout << "Case " << t << ": ";

#ifdef ONLINE
 FILE *fin = freopen("cubes.in","r",stdin);
 //FILE *fout = freopen("out.txt","w",stdout);
#endif

const ll INF = 1e18;
const int mod = 1e9+7;
const int N = 1e5+10;
const int L = 10;
const double eps = 1e-9;
const int BIG = 1e6;

int a[N],dp[N],d[N];
int main(){

  clock_t tm = clock();
  fast;
  int __t = 1;
  //cin >> __t;
  FOR(_t,1,__t){
      int n;
      cin >> n;
      fill(dp,0);
      fill(d,0);
      int maxi =0;
      FOR(i,1,n){
      	cin >> a[i];
      	int b = a[i];
      	 for(int j = 1; j*j <= b ; j++){
      	 	if(b%j == 0){
      	 		dp[i] = max(dp[i],dp[d[b/j]]+1);
      	 		if(j != 1)dp[i] = max(dp[i],dp[d[j]]+1);
      	 		maxi = max(maxi,dp[i]);
      	 		d[j] = d[b/j] = i;
      	 	}
      	 }
      }
      cout << maxi << "\n";

  }
  tm = clock()-tm ;
  cerr << (float)(tm)/CLOCKS_PER_SEC << "\n";
  return 0;
}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> ii;
typedef pair<ll,ll> pll;
typedef pair<double,double> pdd;

#define fill(a,x) memset(a,x,sizeof(a))
#define all(x) x.begin(), x.end()
#define tr(x,it) for( auto it = x.begin(); it!=x.end(); ++it)
#define rtr(x,it) for( auto it = x.rbegin(); it!=x.rend(); ++it)
#define sz(a) int((a).size())
#define pb push_back
#define F first
#define S second
#define FOR(i,a,b) for(int i = a; i<=b; ++i)
#define NFOR(i,a,b) for(int i = a; i>=b; --i)
#define fast ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);
#define debug(x) cerr << #x << " = " << x << "\n"
//#define ONLINE
#define CASE(t) cout << "Case " << t << ": ";

#ifdef ONLINE
 FILE *fin = freopen("cubes.in","r",stdin);
 //FILE *fout = freopen("out.txt","w",stdout);
#endif

const ll INF = 1e18;
const int mod = 1e9+7;
const int N = 1e5+10;
const int L = 10;
const double eps = 1e-9;
const int BIG = 1e6;

int a[N],dp[N];
set<int> s;
int main(){

  clock_t tm = clock();
  fast;
  int __t = 1;
  //cin >> __t;
  FOR(_t,1,__t){
      int n;
      cin >> n;
      FOR(i,0,n-1){
      	cin >> a[i];
      }
      FOR(i,0,n-1)dp[i]=1;
      FOR(i,0,n-1){
      	int del = -1;
      	tr(s,it){
      		if(__gcd(a[*it],a[i]) > 1 && 1+dp[*it] >= dp[i]){
      			dp[i] = 1+dp[*it];
      			del = *it;
      		}
      	}
      	s.erase(del);
      	s.insert(i);
      }
      int maxi =0;
      FOR(i,0,n-1){
      	maxi = max(maxi,dp[i]);
      }
      cout << maxi << "\n";

  }
  tm = clock()-tm ;
  cerr << (float)(tm)/CLOCKS_PER_SEC << "\n";
  return 0;
}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> ii;
typedef pair<ll,ll> pll;
typedef pair<double,double> pdd;

#define fill(a,x) memset(a,x,sizeof(a))
#define all(x) x.begin(), x.end()
#define tr(x,it) for( auto it = x.begin(); it!=x.end(); ++it)
#define rtr(x,it) for( auto it = x.rbegin(); it!=x.rend(); ++it)
#define sz(a) int((a).size())
#define pb push_back
#define F first
#define S second
#define FOR(i,a,b) for(int i = a; i<=b; ++i)
#define NFOR(i,a,b) for(int i = a; i>=b; --i)
#define fast ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);
#define debug(x) cerr << #x << " = " << x << "\n"
//#define ONLINE
#define CASE(t) cout << "Case " << t << ": ";

#ifdef ONLINE
 FILE *fin = freopen("cubes.in","r",stdin);
 //FILE *fout = freopen("out.txt","w",stdout);
#endif

const ll INF = 1e18;
const int mod = 1e9+7;
const int N = 1e5+10;
const int L = 10;
const double eps = 1e-9;
const int BIG = 1e6;

int a[N],dp[N],d[N];
int main(){

  clock_t tm = clock();
  fast;
  int __t = 1;
  //cin >> __t;
  FOR(_t,1,__t){
      int n;
      cin >> n;
      fill(dp,0);
      fill(d,0);
      int maxi =0;
      FOR(i,0,n-1){
      	cin >> a[i];
      	int b = a[i];
      	 for(int j = 1; j*j <= b ; j++){
      	 	if(b%j == 0){
      	 		dp[i] = max({dp[i],(j!=1?d[j]:0)+1,(b!=j?d[b/j]:0)+1});
      	 		maxi = max(maxi,dp[i]);
      	 		d[j] = d[b/j] = dp[i];
      	 	}
      	 }
      }
      cout << maxi << "\n";

  }
  tm = clock()-tm ;
  cerr << (float)(tm)/CLOCKS_PER_SEC << "\n";
  return 0;
}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> ii;
typedef pair<ll,ll> pll;
typedef pair<double,double> pdd;

#define fill(a,x) memset(a,x,sizeof(a))
#define all(x) x.begin(), x.end()
#define tr(x,it) for( auto it = x.begin(); it!=x.end(); ++it)
#define rtr(x,it) for( auto it = x.rbegin(); it!=x.rend(); ++it)
#define sz(a) int((a).size())
#define pb push_back
#define F first
#define S second
#define FOR(i,a,b) for(int i = a; i<=b; ++i)
#define NFOR(i,a,b) for(int i = a; i>=b; --i)
#define fast ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);
#define debug(x) cerr << #x << " = " << x << "\n"
//#define ONLINE
#define CASE(t) cout << "Case " << t << ": ";

#ifdef ONLINE
 FILE *fin = freopen("cubes.in","r",stdin);
 //FILE *fout = freopen("out.txt","w",stdout);
#endif

const ll INF = 1e18;
const int mod = 1e9+7;
const int N = 1e5+10;
const int L = 10;
const double eps = 1e-9;
const int BIG = 1e6;

int a[N],dp[N],f[N],d[N];
int main(){

  clock_t tm = clock();
  fast;
  int __t = 1;
  //cin >> __t;
  FOR(_t,1,__t){
      int n;
      cin >> n;
      FOR(i,0,n-1){
      	cin >> a[i];
      }
      fill(dp,0);
      fill(d,0);
      FOR(i,0,n-1){
      	 int b = a[i];
      	 for(int j = 1; j*j <= b ; j++){
      	 	if(b%j == 0){
      	 		dp[i] = max({dp[i],(j!=1?d[j]:0),(b!=j?d[b/j]:0)});
      	 	}
      	 }
      	 dp[i]++;
      	 for(int j = 1; j*j <= b ; j++){
      	 	if(b%j == 0){
      	 		d[j] = max(d[j],dp[i]);
      	 		d[b/j] = max(d[b/j],dp[i]);
      	 	}
      	 }
      }
      int maxi =0;
      FOR(i,0,n-1){
      	debug(dp[i]);
      	maxi = max(maxi,dp[i]);
      }
      cout << maxi << "\n";

  }
  tm = clock()-tm ;
  cerr << (float)(tm)/CLOCKS_PER_SEC << "\n";
  return 0;
}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> ii;
typedef pair<ll,ll> pll;
typedef pair<double,double> pdd;

#define fill(a,x) memset(a,x,sizeof(a))
#define all(x) x.begin(), x.end()
#define tr(x,it) for( auto it = x.begin(); it!=x.end(); ++it)
#define rtr(x,it) for( auto it = x.rbegin(); it!=x.rend(); ++it)
#define sz(a) int((a).size())
#define pb push_back
#define F first
#define S second
#define FOR(i,a,b) for(int i = a; i<=b; ++i)
#define NFOR(i,a,b) for(int i = a; i>=b; --i)
#define fast ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);
#define debug(x) cerr << #x << " = " << x << "\n"
//#define ONLINE
#define CASE(t) cout << "Case " << t << ": ";

#ifdef ONLINE
 FILE *fin = freopen("cubes.in","r",stdin);
 //FILE *fout = freopen("out.txt","w",stdout);
#endif

const ll INF = 1e18;
const int mod = 1e9+7;
const int N = 1e5+10;
const int L = 10;
const double eps = 1e-9;
const int BIG = 1e6;

int a[N],dp[N];
set<int> s;
int main(){

  clock_t tm = clock();
  fast;
  int __t = 1;
  //cin >> __t;
  FOR(_t,1,__t){
      int n;
      cin >> n;
      FOR(i,0,n-1){
      	cin >> a[i];
      }
      FOR(i,0,n-1)dp[i]=1;
      FOR(i,0,n-1){
      	int del = -1;
      	tr(s,it){
      		if(__gcd(a[*it],a[i]) > 1 && 1+dp[*it] > dp[i]){
      			dp[i] = 1+dp[*it];
      			del = *it;
      		}
      	}
      	s.erase(del);
      	s.insert(i);
      }
      int maxi =0;
      FOR(i,0,n-1){
      	maxi = max(maxi,dp[i]);
      }
      cout << maxi << "\n";

  }
  tm = clock()-tm ;
  cerr << (float)(tm)/CLOCKS_PER_SEC << "\n";
  return 0;
}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> ii;
typedef pair<ll,ll> pll;
typedef pair<double,double> pdd;

#define fill(a,x) memset(a,x,sizeof(a))
#define all(x) x.begin(), x.end()
#define tr(x,it) for( auto it = x.begin(); it!=x.end(); ++it)
#define rtr(x,it) for( auto it = x.rbegin(); it!=x.rend(); ++it)
#define sz(a) int((a).size())
#define pb push_back
#define F first
#define S second
#define FOR(i,a,b) for(int i = a; i<=b; ++i)
#define NFOR(i,a,b) for(int i = a; i>=b; --i)
#define fast ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);
#define debug(x) cerr << #x << " = " << x << "\n"
//#define ONLINE
#define CASE(t) cout << "Case " << t << ": ";

#ifdef ONLINE
 FILE *fin = freopen("cubes.in","r",stdin);
 //FILE *fout = freopen("out.txt","w",stdout);
#endif

const ll INF = 1e18;
const int mod = 1e9+7;
const int N = 1e5+10;
const int L = 10;
const double eps = 1e-9;
const int BIG = 1e6;

int a[N],dp[N],f[N],d[N];
int main(){

  clock_t tm = clock();
  fast;
  int __t = 1;
  //cin >> __t;
  FOR(_t,1,__t){
      int n;
      cin >> n;
      FOR(i,0,n-1){
      	cin >> a[i];
      }
      fill(dp,0);
      fill(d,0);
      FOR(i,1,N-1)f[i]=i;
      for(int i = 2; i*i <= N ; i++){
      	 for(int j = i*i; j < N;j += i){
      	 	f[j] = i;
      	 }
      }
      FOR(i,0,n-1){
      	 int b = a[i];
      	 while(b != 1){
      	 	int c = f[b];
      	 	while(b%c == 0){
      	 		b/=c;
      	 	}
      	 	dp[i] = max(dp[i],d[c]);
      	 }
      	 dp[i]++;
      	 b = a[i];
      	 while(b != 1){
      	 	int c = f[b];
      	 	while(b%c == 0){
      	 		b/=c;
      	 	}
      	 	d[c] = max(d[c],dp[i]);
      	 }
      }
      int maxi =0;
      FOR(i,0,n-1){
      	maxi = max(maxi,dp[i]);
      }
      cout << maxi << "\n";

  }
  tm = clock()-tm ;
  cerr << (float)(tm)/CLOCKS_PER_SEC << "\n";
  return 0;
}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> ii;
typedef pair<ll,ll> pll;
typedef pair<double,double> pdd;

#define fill(a,x) memset(a,x,sizeof(a))
#define all(x) x.begin(), x.end()
#define tr(x,it) for( auto it = x.begin(); it!=x.end(); ++it)
#define rtr(x,it) for( auto it = x.rbegin(); it!=x.rend(); ++it)
#define sz(a) int((a).size())
#define pb push_back
#define F first
#define S second
#define FOR(i,a,b) for(int i = a; i<=b; ++i)
#define NFOR(i,a,b) for(int i = a; i>=b; --i)
#define fast ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);
#define debug(x) cerr << #x << " = " << x << "\n"
//#define ONLINE
#define CASE(t) cout << "Case " << t << ": ";

#ifdef ONLINE
 FILE *fin = freopen("cubes.in","r",stdin);
 //FILE *fout = freopen("out.txt","w",stdout);
#endif

const ll INF = 1e18;
const int mod = 1e9+7;
const int N = 1e5+10;
const int L = 10;
const double eps = 1e-9;
const int BIG = 1e6;

int a[N],dp[N],d[N];
int main(){

  clock_t tm = clock();
  fast;
  int __t = 1;
  //cin >> __t;
  FOR(_t,1,__t){
      int n;
      cin >> n;
      fill(dp,0);
      fill(d,0);
      int maxi =0;
      FOR(i,0,n-1){
      	cin >> a[i];
      	int b = a[i];
      	 for(int j = 1; j*j <= b ; j++){
      	 	if(b%j == 0){
      	 		dp[i] = max({dp[i],(j!=1?d[j]+1:0),d[b/j]+1});
      	 		maxi = max(maxi,dp[i]);
      	 		d[j] = d[b/j] = dp[i];
      	 	}
      	 }
      }
      cout << maxi << "\n";

  }
  tm = clock()-tm ;
  cerr << (float)(tm)/CLOCKS_PER_SEC << "\n";
  return 0;
}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> ii;
typedef pair<ll,ll> pll;
typedef pair<double,double> pdd;

#define fill(a,x) memset(a,x,sizeof(a))
#define all(x) x.begin(), x.end()
#define tr(x,it) for( auto it = x.begin(); it!=x.end(); ++it)
#define rtr(x,it) for( auto it = x.rbegin(); it!=x.rend(); ++it)
#define sz(a) int((a).size())
#define pb push_back
#define F first
#define S second
#define FOR(i,a,b) for(int i = a; i<=b; ++i)
#define NFOR(i,a,b) for(int i = a; i>=b; --i)
#define fast ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);
#define debug(x) cerr << #x << " = " << x << "\n"
//#define ONLINE
#define CASE(t) cout << "Case " << t << ": ";

#ifdef ONLINE
 FILE *fin = freopen("cubes.in","r",stdin);
 //FILE *fout = freopen("out.txt","w",stdout);
#endif

const ll INF = 1e18;
const int mod = 1e9+7;
const int N = 1e5+10;
const int L = 10;
const double eps = 1e-9;
const int BIG = 1e6;

int a[N],dp[N];
set<int> s;
int main(){

  clock_t tm = clock();
  fast;
  int __t = 1;
  //cin >> __t;
  FOR(_t,1,__t){
      int n;
      cin >> n;
      FOR(i,0,n-1){
      	cin >> a[i];
      }
      FOR(i,0,n-1)dp[i]=1;
      FOR(i,0,n-1){
      	rtr(s,it){
      		if(__gcd(a[*it],a[i]) > 1){
      			dp[i] += dp[*it];
      			s.erase(*it);
      			break;
      		}
      	}
      	s.insert(i);
      }
      int maxi =0;
      FOR(i,0,n-1){
      	maxi = max(maxi,dp[i]);
      }
      cout << maxi << "\n";

  }
  tm = clock()-tm ;
  cerr << (float)(tm)/CLOCKS_PER_SEC << "\n";
  return 0;
}


#include	<bits/stdc++.h>
#define nn 100005
using namespace std;
int n,S,z,ans,k,a[nn],v[nn],tot,prime[nn],f[nn];
vector<int>l[nn],L[nn];
int main(){
	scanf("%d",&n);
	S=100002;
	for (int i=2;i<=S;i++){
		if (!v[i])prime[++tot]=i,v[i]=i;
		for (int j=1;j<=tot&&prime[j]*i<=S;j++){
			v[prime[j]*i]=prime[j];
			if (i%prime[j]==0)break;
		}
	}

	for (int i=1;i<=n;i++)scanf("%d",&a[i]);
	for (int i=1;i<=n;i++){
		z=a[i];
		while (z!=1){
			k=v[z];
			l[k].push_back(i);
			L[i].push_back(k);
			while(v[z]==k)z=z/k;
		}
	}

	for (int i=1;i<=n;i++){
			f[i]=max(f[i],1);
		for (int o=0;o<L[i].size();o++){
			k=L[i][o];
			for (int j=0;j<l[k].size();j++){
				int u=l[k][j];
				if(u>i)f[u]=max(f[u],f[i]+1);
			}
		}
	}

	for (int i=1;i<=n;i++)ans=max(ans,f[i]);
	printf("%d\n",ans);
	return 0;
}


#include	<bits/stdc++.h>
#define nn 100005
using namespace std;
int n,S,z,ans,k,a[nn],v[nn],w[nn],tot,prime[nn],f[nn],vi[nn];
vector<int>L[nn];
int main(){
	scanf("%d",&n);
	S=100002;
	for (int i=2;i<=S;i++){
		if (!v[i])prime[++tot]=i,v[i]=i;
		for (int j=1;j<=tot&&prime[j]*i<=S;j++){
			v[prime[j]*i]=prime[j];
			if (i%prime[j]==0)break;
		}
	}

	for (int i=1;i<=n;i++)scanf("%d",&a[i]),w[a[i]]=i,f[a[i]]=1;

	for (int i=1;i<=tot;i++){
		k=prime[i];
			for (int j=k;j<=100000-k;j+=k){
				if (w[j+k])
					f[j+k]=max(f[j+k],f[j]+1);
					else f[j+k]=max(f[j+k],f[j]);
				}
	}
	for (int i=1;i<=tot;i++){
		k=prime[i];
			for (int j=k;j<=100000-k;j+=k){
				if (w[j+k])
					f[j+k]=max(f[j+k],f[j]+1);
					else f[j+k]=max(f[j+k],f[j]);
				}
	}
	for (int i=tot;i>=1;i--){
		k=prime[i];
			for (int j=k;j<=100000-k;j+=k){
				if (w[j+k])
					f[j+k]=max(f[j+k],f[j]+1);
					else f[j+k]=max(f[j+k],f[j]);
				}
	}
	for (int i=tot;i>=1;i--){
		k=prime[i];
			for (int j=k;j<=100000-k;j+=k){
				if (w[j+k])
					f[j+k]=max(f[j+k],f[j]+1);
					else f[j+k]=max(f[j+k],f[j]);
				}
	}
	for (int i=1;i<=n;i++)ans=max(ans,f[a[i]]);
	printf("%d\n",ans);
	return 0;
}


#include	<bits/stdc++.h>
#define nn 100005
using namespace std;
int n,S,z,ans,k,a[nn],v[nn],w[nn],tot,prime[nn],f[nn],vi[nn];
vector<int>L[nn];
int main(){
	scanf("%d",&n);
	S=100002;
	for (int i=2;i<=S;i++){
		if (!v[i])prime[++tot]=i,v[i]=i;
		for (int j=1;j<=tot&&prime[j]*i<=S;j++){
			v[prime[j]*i]=prime[j];
			if (i%prime[j]==0)break;
		}
	}

	for (int i=1;i<=n;i++)scanf("%d",&a[i]),w[a[i]]=i,f[a[i]]=1;
	for (int i=1;i<=n;i++){
		z=a[i];
		while (z!=1){
			k=v[z];
			L[i].push_back(k);
			while(v[z]==k)z=z/k;
		}
	}

	for (int i=1;i<=n;i++){
			for (int o=0;o<L[i].size();o++){
			int k=L[i][o];if (vi[k]==1)continue;
			vi[k]=1;
			for (int j=k;j<=100000-k;j+=k){
				if (w[j+k])
					f[j+k]=max(f[j+k],f[j]+1);
					else f[j+k]=max(f[j+k],f[j]);
				}
			}

	}

	memset(vi,0,sizeof(vi));
	for (int i=n;i>=1;i--){
			for (int o=0;o<L[i].size();o++){
			int k=L[i][o];if (vi[k]==1)continue;
			vi[k]=1;
			for (int j=k;j<=100000-k;j+=k){
				if (w[j+k])
					f[j+k]=max(f[j+k],f[j]+1);
					else f[j+k]=max(f[j+k],f[j]);
				}
			}

	}

	for (int i=1;i<=n;i++)ans=max(ans,f[a[i]]);
	printf("%d\n",ans);
	return 0;
}


#include	<bits/stdc++.h>
#define nn 100005
using namespace std;
int n,S,z,ans,k,a[nn],v[nn],w[nn],tot,prime[nn],f[nn],vi[nn];
vector<int>L[nn];
int main(){
	scanf("%d",&n);
	S=100002;
	for (int i=2;i<=S;i++){
		if (!v[i])prime[++tot]=i,v[i]=i;
		for (int j=1;j<=tot&&prime[j]*i<=S;j++){
			v[prime[j]*i]=prime[j];
			if (i%prime[j]==0)break;
		}
	}

	for (int i=1;i<=n;i++)scanf("%d",&a[i]),w[a[i]]=i,f[a[i]]=1;
	for (int i=1;i<=n;i++){
		z=a[i];
		while (z!=1){
			k=v[z];
			L[i].push_back(k);
			while(v[z]==k)z=z/k;
		}
	}

	for (int i=1;i<=n;i++){
		//	f[a[i]]=max(f[a[i]],1);
			for (int o=0;o<L[i].size();o++){
			int k=L[i][o];if (vi[k]==1)continue;
			vi[k]=1;
			for (int j=k;j<=100000-k;j+=k){
				if (w[j+k])
					f[j+k]=max(f[j+k],f[j]+1);
					else f[j+k]=max(f[j+k],f[j]);
				}
			}

	}

	for (int i=1;i<=n;i++)ans=max(ans,f[a[i]]);
	printf("%d\n",ans);
	return 0;
}


#include	<bits/stdc++.h>
#define nn 100005
using namespace std;
int n,S,z,ans,k,a[nn],v[nn],tot,prime[nn],f[nn];
vector<int>l[nn];
int main(){
	scanf("%d",&n);
	S=100002;
	for (int i=2;i<=S;i++){
		if (!v[i])prime[++tot]=i,v[i]=i;
		for (int j=1;j<=tot&&prime[j]*i<=S;j++){
			v[prime[j]*i]=prime[j];
			if (i%prime[j]==0)break;
		}
	}

	for (int i=1;i<=n;i++)scanf("%d",&a[i]);
	for (int i=1;i<=n;i++){
		z=a[i];
		while (z!=1){
			k=v[z];
			l[k].push_back(i);
			while(v[z]==k)z=z/k;
		}
	}

	for (int i=1;i<=n;i++){
			z=a[i];f[i]=max(f[i],1);
		while (z!=1){
			k=v[z];
			for (int j=0;j<l[k].size();j++){
				int u=l[k][j];
				if(u>i)f[u]=max(f[u],f[i]+1);
			}
			while(v[z]==k)z=z/k;
		}
	}

	for (int i=1;i<=n;i++)ans=max(ans,f[i]);
	printf("%d\n",ans);
	return 0;
}


#include	<bits/stdc++.h>
#define nn 100005
using namespace std;
int n,S,z,ans,k,tem,a[nn],v[nn],tot,prime[nn],f[nn];
vector<int>L[nn];

int main(){
	scanf("%d",&n);
	S=100002;
	for (int i=2;i<=S;i++){
		if (!v[i])prime[++tot]=i,v[i]=i;
		for (int j=1;j<=tot&&prime[j]*i<=S;j++){
			v[prime[j]*i]=prime[j];
			if (i%prime[j]==0)break;
		}
	}

	for (int i=1;i<=n;i++)scanf("%d",&a[i]);
	for (int i=1;i<=n;i++){
		z=a[i];
		while (z!=1){
			k=v[z];
//			l[k].push_back(i);
			L[i].push_back(k);
			while(v[z]==k)z=z/k;
		}
	}

	for (int i=1;i<=n;i++){
		tem=1;
		for (int j=0;j<L[i].size();j++){
			int u=L[i][j];
			tem=max(tem,f[u]+1);
		}
		for (int j=0;j<L[i].size();j++){
			int u=L[i][j];
			f[u]=max(f[u],tem);
		}
	}
	for (int i=1;i<=tot;i++)ans=max(ans,f[prime[i]]);
	printf("%d\n",ans);
	return 0;
}


#include	<bits/stdc++.h>
#define nn 100005
using namespace std;
int n,S,z,ans,k,tem,a[nn],v[nn],tot,prime[nn],f[nn];
vector<int>L[nn];

int main(){
	scanf("%d",&n);
	S=100002;
	for (int i=2;i<=S;i++){
		if (!v[i])prime[++tot]=i,v[i]=i;
		for (int j=1;j<=tot&&prime[j]*i<=S;j++){
			v[prime[j]*i]=prime[j];
			if (i%prime[j]==0)break;
		}
	}

	for (int i=1;i<=n;i++)scanf("%d",&a[i]);
	for (int i=1;i<=n;i++){
		z=a[i];
		while (z!=1){
			k=v[z];
//			l[k].push_back(i);
			L[i].push_back(k);
			while(v[z]==k)z=z/k;
		}
	}

	for (int i=1;i<=n;i++){
		tem=1;
		for (int j=0;j<L[i].size();j++){
			int u=L[i][j];
			tem=max(tem,f[u]+1);
		}
		for (int j=0;j<L[i].size();j++){
			int u=L[i][j];
			f[u]=max(f[u],tem);
		}
	}
	ans=1;
	for (int i=1;i<=tot;i++)ans=max(ans,f[prime[i]]);
	printf("%d\n",ans);
	return 0;
}


#include "bits/stdc++.h"
#define endl '\n'
#define mod 1000000007
#define pb push_back
#define mp make_pair
#define FOR(i, s, e) for(int i = int(s); i <= int(e); i++)
#define REP(i, e, s) for(int i = int(e); i >= int(s); i--)
const int MAX = 1e5 + 5;
typedef long long ll;
using namespace std;
int a[MAX], dp[MAX], largest[MAX], n, mx = -1, ans = -1, mn = mod; bool prime[MAX];
int main()
{
	ios_base::sync_with_stdio(false); cin.tie(0);
	cin >> n;
	prime[1] = 1;
	FOR(i, 1, n) cin >> a[i], dp[a[i]]++, mx = max(a[i], mx), mn = min(a[i], mn);
	FOR(i, 2, mx)
		if(prime[i] == 0)
			for(int j = 2 * i; j <= mx; j += i)
			{
				prime[j] = 1;
				largest[i] = max(j, largest[i]);
			}
	REP(i, mx, 2)
	{
		int maxtillnow = 0;
		if(prime[i] == 0)
		{
			for(int j = largest[i]; j >= mn; j -= i)
			{
				if(dp[j]) dp[j] = max(dp[j], 1 + maxtillnow);
				maxtillnow = max(dp[j], maxtillnow);
			}
		}
	}
	FOR(i, 1, mx) ans = max(ans, dp[i]);
	cout << ans << endl;
	return 0;
}


#include "bits/stdc++.h"
#define endl '\n'
#define mod 1000000007
#define pb push_back
#define mp make_pair
#define FOR(i, s, e) for(int i = int(s); i <= int(e); i++)
#define REP(i, e, s) for(int i = int(e); i >= int(s); i--)
const int MAX = 1e5 + 5;
typedef long long ll;
using namespace std;
int a[MAX], dp[MAX], check[MAX], n, mx = -1, ans = -1; bool prime[MAX];
int main()
{
	prime[1] = 1;
	FOR(i, 2, 1e5)
	{
		if(prime[i] == 0) for(int j = 2 * i; j <= 1e5; j += i) prime[j] = 1;
	}
	scanf("%d",&n);
	FOR(i, 1, n) scanf("%d",&a[i]), check[a[i]]++, mx = max(a[i], mx);
	REP(i, mx, 2)
	{
		dp[i] = check[i];
		for(int j = 2; j + i <= mx; j++)
			for(int k = j; k + i <= mx && prime[j] == 0 && i % j == 0; k += j)
				dp[i] = max(check[i] + dp[k + i], dp[i]);
		//cout << i << ' ' << dp[i] << endl;
	}
	FOR(i, 1, mx) ans = max(ans, dp[i]);
	cout << ans << endl;
	return 0;
}


#include "bits/stdc++.h"
#define endl '\n'
#define mod 1000000007
#define pb push_back
#define mp make_pair
#define FOR(i, s, e) for(int i = int(s); i <= int(e); i++)
#define REP(i, e, s) for(int i = int(e); i >= int(s); i--)
const int MAX = 1e5 + 5;
typedef long long ll;
using namespace std;
int a[MAX], dp[MAX], n, mx = -1, ans = -1; bool prime[MAX];
int main()
{
	ios_base::sync_with_stdio(false); cin.tie(0);
	prime[1] = 1;
	FOR(i, 2, 1e5)
	{
		if(prime[i] == 0) for(int j = 2 * i; j <= 1e5; j += i) prime[j] = 1;
	}
	cin >> n;
	FOR(i, 1, n) cin >> a[i], dp[a[i]]++, mx = max(a[i], mx);
	REP(i, n, 1)
	{
		if(a[i] == 1) break;
		for(int j = 2; j + a[i] <= mx; j++)
			for(int k = j; k + a[i] <= mx && prime[j] == 0 && a[i] % j == 0; k += j)
				dp[a[i]] = max(1 + dp[k + a[i]], dp[a[i]]);
	}
	FOR(i, 1, mx) ans = max(ans, dp[i]);
	cout << ans << endl;
	return 0;
}


#include "bits/stdc++.h"
#define endl '\n'
#define mod 1000000007
#define pb push_back
#define mp make_pair
#define FOR(i, s, e) for(int i = int(s); i <= int(e); i++)
#define REP(i, e, s) for(int i = int(e); i >= int(s); i--)
const int MAX = 1e5 + 5;
typedef long long ll;
using namespace std;
int a[MAX], dp[MAX], n, mx = -1, ans = -1; bool prime[MAX];
int main()
{
	ios_base::sync_with_stdio(false); cin.tie(0);
	FOR(i, 2, 1e5)
	{
		if(prime[i] == 0) for(int j = 2 * i; j <= 1e5; j += i) prime[j] = 1;
	}
	cin >> n;
	FOR(i, 1, n) cin >> a[i], dp[a[i]]++, mx = max(a[i], mx);
	REP(i, n, 1)
	{
		if(a[i] == 1) continue;
		if(prime[a[i]] == 1)
		{
			for(int j = 2; j + a[i] <= mx; j++)
				for(int k = j; k + a[i] <= mx && prime[j] == 0; k += j)
					dp[a[i]] = max(1 + dp[k + a[i]], dp[a[i]]);
		}
		else if(prime[a[i]] == 0)
			for(int j = 2 * a[i]; j <= mx; j += a[i]) dp[a[i]] = max(1 + dp[j], dp[a[i]]);
	}
	FOR(i, 1, mx) ans = max(ans, dp[i]);
	cout << ans << endl;
	return 0;
}


#include "bits/stdc++.h"
#define endl '\n'
#define mod 1000000007
#define pb push_back
#define mp make_pair
#define FOR(i, s, e) for(int i = int(s); i <= int(e); i++)
#define REP(i, e, s) for(int i = int(e); i >= int(s); i--)
const int MAX = 1e5 + 5;
typedef long long ll;
using namespace std;
int a[MAX], dp[MAX], n, mx = -1, ans = -1; bool prime[MAX];
int main()
{
	ios_base::sync_with_stdio(false); cin.tie(0);
	FOR(i, 2, 1e5)
	{
		if(prime[i] == 0) for(int j = 2 * i; j <= 1e5; j += i) prime[j] = 1;
	}
	cin >> n;
	FOR(i, 1, n) cin >> a[i], dp[a[i]]++, mx = max(a[i], mx);
	REP(i, n, 1)
	{
		if(a[i] == 1) continue;
		for(int j = 2; j + a[i] <= mx; j++)
			for(int k = j; k + a[i] <= mx && prime[j] == 0; k += j)
				dp[a[i]] = max(1 + dp[k + a[i]], dp[a[i]]);
	}
	FOR(i, 1, mx) ans = max(ans, dp[i]);
	cout << ans << endl;
	return 0;
}


#include "bits/stdc++.h"
#define endl '\n'
#define mod 1000000007
#define pb push_back
#define mp make_pair
#define FOR(i, s, e) for(int i = int(s); i <= int(e); i++)
#define REP(i, e, s) for(int i = int(e); i >= int(s); i--)
const int MAX = 1e5 + 5;
typedef long long ll;
using namespace std;
int a[MAX], dp[MAX], n, mx = -1, ans = -1; bool prime[MAX];
int gcd(int a, int b)
{
	if(b == 0) return a;
	return gcd(b, a % b);
}
int main()
{
	ios_base::sync_with_stdio(false); cin.tie(0);
	FOR(i, 2, 1e5)
	{
		if(prime[i] == 0) for(int j = 2 * i; j <= 1e5; j += i) prime[j] = 1;
	}
	cin >> n;
	FOR(i, 1, n) cin >> a[i], dp[a[i]]++, mx = max(a[i], mx);
	REP(i, n, 1)
	{
		if(a[i] == 1) continue;
		for(int j = 2; j + a[i] <= mx; j++)
			for(int k = j; k + a[i] <= mx && prime[j] == 0; k += j)
				if(gcd(a[i], a[i] + k) > 1) dp[a[i]] = max(1 + dp[k + a[i]], dp[a[i]]);
	}
	FOR(i, 1, mx) ans = max(ans, dp[i]);
	cout << ans << endl;
	return 0;
}


#include "bits/stdc++.h"
#define endl '\n'
#define mod 1000000007
#define pb push_back
#define mp make_pair
#define FOR(i, s, e) for(int i = int(s); i <= int(e); i++)
#define REP(i, e, s) for(int i = int(e); i >= int(s); i--)
const int MAX = 1e5 + 5;
typedef long long ll;
using namespace std;
int check[MAX], a[MAX], dp[MAX], n, mx = -1, ans = -1; bool prime[MAX];
int main()
{
	ios_base::sync_with_stdio(false); cin.tie(0);
	cin >> n;
	prime[1] = 1;
	FOR(i, 1, n) cin >> a[i], check[a[i]]++, mx = max(a[i], mx);
	FOR(i, 2, 1e5)
	{
		if(prime[i] == 0) for(int j = 2 * i; j <= 1e5; j += i) prime[j] = 1;
	}
	REP(i, mx, 2)
	{
		dp[i] = check[i];
		if(prime[i] == 0)
		{
			for(int j = 2 * i; j <= mx; j += i)
				dp[i] = max(check[i] + dp[j], dp[i]);
			continue;
		}
		for(int j = 2; j + i <= mx; j++)
		{
			for(int k = j + i; k <= mx && prime[j] == 0 && i % j == 0; k += j)
				dp[i] = max(check[i] + dp[k], dp[i]);
		}
	}
	dp[1] = check[1];
	FOR(i, 1, mx) ans = max(ans, dp[i]);
	cout << ans << endl;
	return 0;
}


#include "bits/stdc++.h"
#define endl '\n'
#define mod 1000000007
#define pb push_back
#define mp make_pair
#define FOR(i, s, e) for(int i = int(s); i <= int(e); i++)
#define REP(i, e, s) for(int i = int(e); i >= int(s); i--)
const int MAX = 1e5 + 5;
typedef long long ll;
using namespace std;
int a[MAX], dp[MAX], n, mx = -1, ans = -1; bool prime[MAX];
int main()
{
	prime[1] = 1;
	FOR(i, 2, 1e5)
	{
		if(prime[i] == 0) for(int j = 2 * i; j <= 1e5; j += i) prime[j] = 1;
	}
	scanf("%d",&n);
	FOR(i, 1, n) scanf("%d",&a[i]), dp[a[i]]++, mx = max(a[i], mx);
	FOR(i, 1, n)
	{
		if(a[i] == 1) continue;
		for(int j = 2; j + a[i] <= mx; j++)
			for(int k = j; k + a[i] <= mx && prime[j] == 0 && a[i] % j == 0; k += j)
				dp[k + a[i]] = max(1 + dp[a[i]], dp[k + a[i]]);
	}
	FOR(i, 1, n) ans = max(ans, dp[a[i]]);
	printf("%d\n",ans);
	return 0;
}


#include "bits/stdc++.h"
#define endl '\n'
#define mod 1000000007
#define pb push_back
#define mp make_pair
#define FOR(i, s, e) for(int i = int(s); i <= int(e); i++)
#define REP(i, e, s) for(int i = int(e); i >= int(s); i--)
const int MAX = 1e5 + 5;
typedef long long ll;
using namespace std;
int check[MAX], a[MAX], dp[MAX], largest[MAX], n, mx = -1, ans = -1; bool prime[MAX];
int main()
{
	ios_base::sync_with_stdio(false); cin.tie(0);
	cin >> n;
	prime[1] = 1;
	FOR(i, 1, n) cin >> a[i], check[a[i]]++, mx = max(a[i], mx);
	FOR(i, 2, 1e5)
	{
		if(prime[i] == 0) for(int j = 2 * i; j <= 1e5; j += i) prime[j] = 1;
	}
	REP(i, mx, 2)
	{
		dp[i] = check[i];
		for(int j = 2; j + i <= mx; j++)
		{
			for(int k = j + i; k <= mx && prime[j] == 0 && i % j == 0; k += j)
				dp[i] = max(check[i] + dp[k], dp[i]);
		}
	}
	dp[1] = check[1];
	FOR(i, 1, mx) ans = max(ans, dp[i]);
	cout << ans << endl;
	return 0;
}


#include "bits/stdc++.h"
#define endl '\n'
#define mod 1000000007
#define pb push_back
#define mp make_pair
#define FOR(i, s, e) for(int i = int(s); i <= int(e); i++)
#define REP(i, e, s) for(int i = int(e); i >= int(s); i--)
const int MAX = 1e5 + 5;
typedef long long ll;
using namespace std;
int check[MAX], a[MAX], dp[MAX], largest[MAX], n, mx = -1, ans = -1; bool prime[MAX];
int main()
{
	ios_base::sync_with_stdio(false); cin.tie(0);
	cin >> n;
	prime[1] = 1;
	FOR(i, 1, n) cin >> a[i], check[a[i]]++, mx = max(a[i], mx);
	FOR(i, 2, mx)
		if(prime[i] == 0)
			for(int j = 2 * i; j <= mx; j += i)
				prime[j] = 1;
	REP(i, mx, 2)
	{
		dp[i] = check[i];
		for(int j = 2; j + i <= mx; j++)
		{
			for(int k = j + i; k <= mx && prime[j] == 0 && i % j == 0; k += j)
				dp[i] = max(check[i] + dp[k], dp[i]);
		}
	}
	dp[1] = check[1];
	FOR(i, 1, mx) ans = max(ans, dp[i]);
	cout << ans << endl;
	return 0;
}


#include "bits/stdc++.h"
#define endl '\n'
#define mod 1000000007
#define pb push_back
#define mp make_pair
#define FOR(i, s, e) for(int i = int(s); i <= int(e); i++)
#define REP(i, e, s) for(int i = int(e); i >= int(s); i--)
const int MAX = 1e5 + 5;
typedef long long ll;
using namespace std;
int a[MAX], dp[MAX], n, mx = -1, ans = -1; bool prime[MAX];
int main()
{
	ios_base::sync_with_stdio(false); cin.tie(0);
	prime[1] = 1;
	FOR(i, 2, 1e5)
	{
		if(prime[i] == 0) for(int j = 2 * i; j <= 1e5; j += i) prime[j] = 1;
	}
	cin >> n;
	FOR(i, 1, n) cin >> a[i], dp[a[i]]++, mx = max(a[i], mx);
	FOR(i, 1, n)
	{
		if(a[i] == 1) continue;
		for(int j = 2; j + a[i] <= mx; j++)
			for(int k = j; k + a[i] <= mx && prime[j] == 0 && a[i] % j == 0; k += j)
				dp[k + a[i]] = max(1 + dp[a[i]], dp[k + a[i]]);
	}
	FOR(i, 1, n) ans = max(ans, dp[a[i]]);
	cout << ans << endl;
	return 0;
}


#include "bits/stdc++.h"
#define endl '\n'
#define mod 1000000007
#define pb push_back
#define mp make_pair
#define FOR(i, s, e) for(int i = int(s); i <= int(e); i++)
#define REP(i, e, s) for(int i = int(e); i >= int(s); i--)
const int MAX = 1e5 + 5;
typedef long long ll;
using namespace std;
int a[MAX], dp[MAX], check[MAX], n, mx = -1, ans = -1; bool prime[MAX];
int main()
{
	prime[1] = 1;
	FOR(i, 2, 1e5)
	{
		if(prime[i] == 0) for(int j = 2 * i; j <= 1e5; j += i) prime[j] = 1;
	}
	scanf("%d",&n);
	FOR(i, 1, n) scanf("%d",&a[i]), check[a[i]]++, mx = max(a[i], mx);
	REP(i, mx, 2)
	{
		dp[i] = check[i];
		for(int j = 2; j + i <= mx; j++)
			for(int k = j; k + i <= mx && prime[j] == 0 && i % j == 0; k += j)
				dp[i] = max(check[i] + dp[k + i], dp[i]);
	}
	dp[1] = 1;
	FOR(i, 1, mx) ans = max(ans, dp[i]);
	printf("%d\n", ans);
	return 0;
}


#include "bits/stdc++.h"
#define endl '\n'
#define mod 1000000007
#define pb push_back
#define mp make_pair
#define FOR(i, s, e) for(int i = int(s); i <= int(e); i++)
#define REP(i, e, s) for(int i = int(e); i >= int(s); i--)
const int MAX = 1e5 + 5;
typedef long long ll;
using namespace std;
int a[MAX], dp[MAX], n, ans = -1; bool prime[MAX];
vector <int> divisors;
int main()
{
	prime[1] = 1; dp[1] = 1;
	FOR(i, 2, 1e5)
	{
		if(prime[i] == 0) for(int j = 2 * i; j <= 1e5; j += i) prime[j] = 1;
	}
	scanf("%d",&n);
	FOR(i, 1, n) scanf("%d",&a[i]);
	FOR(i, 1, n)
	{
		if(a[i] == 1) continue;
		if(!prime[a[i]]) divisors.pb(a[i]);
		for(int j = 2; j * j <= a[i]; j++)
		{
			if(!prime[a[i]/j] && j * j != a[i] && a[i] % j == 0) divisors.pb(a[i]/j);
			if(!prime[j] && a[i] % j == 0) divisors.pb(j);
		}
		int cur = 0;
		FOR(j, 0, divisors.size() - 1) cur = max(cur, dp[divisors[j]]);
		FOR(j, 0, divisors.size() - 1) dp[divisors[j]] = cur + 1;
		divisors.clear();
	}
	FOR(i, 1, MAX - 1) ans = max(ans, dp[i]);
	printf("%d\n",ans);
	return 0;
}


#include "bits/stdc++.h"
#define endl '\n'
#define mod 1000000007
#define pb push_back
#define mp make_pair
#define FOR(i, s, e) for(int i = int(s); i <= int(e); i++)
#define REP(i, e, s) for(int i = int(e); i >= int(s); i--)
const int MAX = 1e5 + 5;
typedef long long ll;
using namespace std;
int a[MAX], dp[MAX], n, ans = -1; bool prime[MAX];
vector <int> divisors;
int main()
{
	prime[1] = 1; dp[1] = 1;
	FOR(i, 2, 1e5)
	{
		if(prime[i] == 0) for(int j = 2 * i; j <= 1e5; j += i) prime[j] = 1;
	}
	scanf("%d",&n);
	FOR(i, 1, n) scanf("%d",&a[i]);
	FOR(i, 1, n)
	{
		if(a[i] == 1) continue;
		if(!prime[a[i]]) dp[a[i]] = 1;
		if(!prime[a[i]]) continue;
		FOR(j, 2, a[i]/2)
			if(!prime[j] && a[i] % j == 0) divisors.pb(j);
		int cur = 0;
		FOR(j, 0, divisors.size() - 1) cur = max(cur, dp[divisors[j]]);
		FOR(j, 0, divisors.size() - 1) dp[divisors[j]] = cur + 1;
		divisors.clear();
	}
	FOR(i, 1, n) ans = max(ans, dp[i]);
	printf("%d\n",ans);
	return 0;
}


#include <bits/stdc++.h>
#define loop(n) for(ll  i= 0 ; i< (n) ; i++)
#define ll long long
#define vi vector<ll>
#define ii pair<ll,ll>
#define inf 1000000000000000
#define MAXNODE 250009
#define all(x) x.begin(),x.end()
#define pii pair<ll,ll>
#define vii vector<pii>
#define OO (0x7fffffffffffffff)
#define md ((ll)1e9+9)
#define pi (3.141592653589793)
#define tRed(x) (x)*(pi)/(180.0)
#define tDeg(x) (x)*(180.0)/(pi)
#define LCM(a,b) ( (a*b)/__gcd(a,b) )
#define lp(i,n) for(int i = 0 ; i <(n) ; i++)
#define prV(v) cout << "(v) : " ; loop(v.size()){cout << v[i] << " " ; } cout << '\n' ;

using namespace std;

int prime(int n ){
    for(ll i = 2 ; i*i <=n  ;i++)if(n%i==0)return 0 ;
    return 1 ;
}

int main(){

    vi sp(100009) ;

    for(int i = 2 ; i<=100000 ; i++){
        if(sp[i])continue ;
        for(int j = i ; j<=100000 ; j+=i){
            sp[j] = i ;
        }
    }

    //freopen("DataSet.txt" , "r" , stdin) ;
    //freopen("1.txt" , "w" , stdout) ;

    cin.tie(0);
    cin.sync_with_stdio(0);

    int n ; cin >> n ;
    vi fr(100009) ;
    loop(n){
        int x ; cin >> x ; fr[x] = 1;
    }
    int a = 0  ;
    vi ans(100001) ;
    loop(100001){
        if(i>1 && fr[i]){
            ans[i]++ ;
            //if(i<20)cout << i << " : " << ans[i] << '\n' ;
            a = max(a , (int)ans[i]) ;

            int I = i ;
            int II = i ;
            while(I>1 && sp[I]!=I){
                int p = sp[I] ;
                //cout << "p : " << p << '\n' ;
                while(I%p==0)I/=p  ;

                for(int j = II+p ; j<=100000 ; j+=p ){
                    ans[j] = max(ans[j] , ans[i]) ;
                }

            }
            //cout << "after : "<< I << '\n' ;
            if(I!=1){
                for(int j=II+I ; j<=100000 ; j+=I){
                    ans[j] = max(ans[j] , ans[i]) ;
                }
            }
        }
    }
    cout << max(a, 1);
    return 0;
}


#include <bits/stdc++.h>
#define loop(n) for(ll  i= 0 ; i< (n) ; i++)
#define ll long long
#define vi vector<ll>
#define ii pair<ll,ll>
#define inf 1000000000000000
#define MAXNODE 250009
#define all(x) x.begin(),x.end()
#define pii pair<ll,ll>
#define vii vector<pii>
#define OO (0x7fffffffffffffff)
#define md ((ll)1e9+9)
#define pi (3.141592653589793)
#define tRed(x) (x)*(pi)/(180.0)
#define tDeg(x) (x)*(180.0)/(pi)
#define LCM(a,b) ( (a*b)/__gcd(a,b) )
#define lp(i,n) for(int i = 0 ; i <(n) ; i++)
#define prV(v) cout << "(v) : " ; loop(v.size()){cout << v[i] << " " ; } cout << '\n' ;

using namespace std;

int prime(int n ){
    for(ll i = 2 ; i*i <=n  ;i++)if(n%i==0)return 0 ;
    return 1 ;
}

int main(){

    //freopen("DataSet.txt" , "r" , stdin) ;
    //freopen("1.txt" , "w" , stdout) ;

    cin.tie(0);
    cin.sync_with_stdio(0);

    int n ; cin >> n ;
    vi fr(100009) ;
    loop(n){
        int x ; cin >> x ; fr[x] = 1;
    }
    int a = 0  ;
    vi ans(100001) ;
    loop(100001){
        if(i>1 && fr[i]){
            ans[i]++ ;
            //if(i<20)cout << i << " : " << ans[i] << '\n' ;
            a = max(a , (int)ans[i]) ;
            int I = i ;
            ll aa= ans[I] ;
            for(ll i = 2 ; i*i<=I ; i++){
                if(I%i==0){
                    while(I%i==0)I/=i ;
                    for(int j = i+i ; j<=100000 ; j+=i){
                        ans[j] = max(ans[j] , aa) ;
                        //if(j<20)cout << j << " jj : " << ans[j] << '\n' ;
                    }
                }
            }
            if(I!=1){
                for(int j = I+I ; j<=100000 ; j+=I){
                    ans[j] = max(ans[j] , aa) ;
                    //if(j<20)cout << j << " jj : " << ans[j] << '\n' ;
                }
            }
        }
    }
    cout << max(a, 1);
    return 0;
}


#include <bits/stdc++.h>
#define loop(n) for(ll  i= 0 ; i< (n) ; i++)
#define ll long long
#define vi vector<ll>
#define ii pair<ll,ll>
#define inf 1000000000000000
#define MAXNODE 250009
#define all(x) x.begin(),x.end()
#define pii pair<ll,ll>
#define vii vector<pii>
#define OO (0x7fffffffffffffff)
#define md ((ll)1e9+9)
#define pi (3.141592653589793)
#define tRed(x) (x)*(pi)/(180.0)
#define tDeg(x) (x)*(180.0)/(pi)
#define LCM(a,b) ( (a*b)/__gcd(a,b) )
#define lp(i,n) for(int i = 0 ; i <(n) ; i++)
#define prV(v) cout << "(v) : " ; loop(v.size()){cout << v[i] << " " ; } cout << '\n' ;

using namespace std;

int prime(int n ){
    for(ll i = 2 ; i*i <=n  ;i++)if(n%i==0)return 0 ;
    return 1 ;
}

int main(){

    //freopen("DataSet.txt" , "r" , stdin) ;
    //freopen("1.txt" , "w" , stdout) ;

    cin.tie(0);
    cin.sync_with_stdio(0);

    int n ; cin >> n ;
    vi fr(100009) ;
    loop(n){
        int x ; cin >> x ; fr[x] = 1;
    }
    int a = 0  ;
    vi ans(100001) ;
    loop(100001){
        if(i>1 && fr[i]){
            ans[i]++ ;
            //if(i<20)cout << i << " : " << ans[i] << '\n' ;
            a = max(a , (int)ans[i]) ;
            int I = i ;
            int II = i ;
            ll aa= ans[I] ;
            for(ll i = 2 ; i*i<=I ; i++){
                if(I%i==0){
                    while(I%i==0)I/=i ;
                    for(int j = I+i ; j<=100000 ; j+=i){
                        ans[j] = max(ans[j] , aa) ;
                        //if(j<20)cout << j << " jj : " << ans[j] << '\n' ;
                    }
                }
            }
            if(I!=1){
                for(int j = I+I ; j<=100000 ; j+=I){
                    ans[j] = max(ans[j] , aa) ;
                    //if(j<20)cout << j << " jj : " << ans[j] << '\n' ;
                }
            }
        }
    }
    cout << max(a, 1);
    return 0;
}


#include <bits/stdc++.h>
#define loop(n) for(ll  i= 0 ; i< (n) ; i++)
#define ll long long
#define vi vector<ll>
#define ii pair<ll,ll>
#define inf 1000000000000000
#define MAXNODE 250009
#define all(x) x.begin(),x.end()
#define pii pair<ll,ll>
#define vii vector<pii>
#define OO (0x7fffffffffffffff)
#define md ((ll)1e9+9)
#define pi (3.141592653589793)
#define tRed(x) (x)*(pi)/(180.0)
#define tDeg(x) (x)*(180.0)/(pi)
#define LCM(a,b) ( (a*b)/__gcd(a,b) )
#define lp(i,n) for(int i = 0 ; i <(n) ; i++)
#define prV(v) cout << "(v) : " ; loop(v.size()){cout << v[i] << " " ; } cout << '\n' ;

using namespace std;

int prime(int n ){
    for(ll i = 2 ; i*i <=n  ;i++)if(n%i==0)return 0 ;
    return 1 ;
}

int main(){

    vi sp(1000009) ;

    for(int i = 2 ; i<=1000000 ; i++){
        if(sp[i])continue ;
        for(int j = i ; j<=1000000 ; j+=i){
            sp[j] = i ;
        }
    }

    //freopen("DataSet.txt" , "r" , stdin) ;
    //freopen("1.txt" , "w" , stdout) ;

    cin.tie(0);
    cin.sync_with_stdio(0);

    int n ; cin >> n ;
    vi fr(100009) ;
    loop(n){
        int x ; cin >> x ; fr[x] = 1;
    }
    int a = 0  ;
    vi ans(100001) ;
    loop(100001){
        if(i>1 && fr[i]){
            ans[i]++ ;
            //if(i<20)cout << i << " : " << ans[i] << '\n' ;
            a = max(a , (int)ans[i]) ;

            int I = i ;
            int II = i ;
            while(I>1 && sp[I]!=I){
                int p = sp[I] ;
                //cout << "p : " << p << '\n' ;
                while(I%p==0)I/=p  ;

                for(int j = II+p ; j<=100000 ; j+=p ){
                    ans[j] = max(ans[j] , ans[i]) ;
                }

            }
            //cout << "after : "<< I << '\n' ;
            if(I!=1){
                for(int j  = II+I ; j<=100000 ; j+=I){
                    ans[j] = max(ans[j] , ans[i]) ;
                }
            }
        }
    }
    cout << max(a, 1);
    return 0;
}


#include <bits/stdc++.h>
#define loop(n) for(ll  i= 0 ; i< (n) ; i++)
#define ll long long
#define vi vector<ll>
#define ii pair<ll,ll>
#define inf 1000000000000000
#define MAXNODE 250009
#define all(x) x.begin(),x.end()
#define pii pair<ll,ll>
#define vii vector<pii>
#define OO (0x7fffffffffffffff)
#define md ((ll)1e9+9)
#define pi (3.141592653589793)
#define tRed(x) (x)*(pi)/(180.0)
#define tDeg(x) (x)*(180.0)/(pi)
#define LCM(a,b) ( (a*b)/__gcd(a,b) )
#define lp(i,n) for(int i = 0 ; i <(n) ; i++)
#define prV(v) cout << "(v) : " ; loop(v.size()){cout << v[i] << " " ; } cout << '\n' ;

using namespace std;

int prime(int n ){
    for(ll i = 2 ; i*i <=n  ;i++)if(n%i==0)return 0 ;
    return 1 ;
}

int main(){

    vi sp(1000009) ;

    for(int i = 2 ; i<=1000000 ; i++){
        if(sp[i])continue ;
        for(int j = i ; j<=1000000 ; j+=i){
            sp[j] = i ;
        }
    }

    //freopen("DataSet.txt" , "r" , stdin) ;
    //freopen("1.txt" , "w" , stdout) ;

    //cin.tie(0);
    //cin.sync_with_stdio(0);

    int n ; cin >> n ;
    vi fr(100009) ;
    loop(n){
        int x ; cin >> x ; fr[x] = 1;
    }
    int a = 0  ;
    vi ans(100001) ;
    loop(100001){
        if(i>1 && fr[i]){
            ans[i]++ ;
            //if(i<20)cout << i << " : " << ans[i] << '\n' ;
            a = max(a , (int)ans[i]) ;

            int I = i ;
            int II = i ;
            while(I>1 && sp[I]!=I){
                int p = sp[I] ;
                //cout << "p : " << p << '\n' ;
                while(I%p==0)I/=p  ;

                for(int j = II+p ; j<=100000 ; j+=p ){
                    ans[j] = max(ans[j] , ans[i]) ;
                }

            }
            //cout << "after : "<< I << '\n' ;
            if(I!=1){
                for(int j  = II+I ; j<=100000 ; j+=I){
                    ans[j] = max(ans[j] , ans[i]) ;
                }
            }
        }
    }
    cout << max(a, 1);
    return 0;
}


#include <bits/stdc++.h>
#define loop(n) for(ll  i= 0 ; i< (n) ; i++)
#define ll long long
#define vi vector<ll>
#define ii pair<ll,ll>
#define inf 1000000000000000
#define MAXNODE 250009
#define all(x) x.begin(),x.end()
#define pii pair<ll,ll>
#define vii vector<pii>
#define OO (0x7fffffffffffffff)
#define md ((ll)1e9+9)
#define pi (3.141592653589793)
#define tRed(x) (x)*(pi)/(180.0)
#define tDeg(x) (x)*(180.0)/(pi)
#define LCM(a,b) ( (a*b)/__gcd(a,b) )
#define lp(i,n) for(int i = 0 ; i <(n) ; i++)
#define prV(v) cout << "(v) : " ; loop(v.size()){cout << v[i] << " " ; } cout << '\n' ;

using namespace std;

int prime(int n ){
    for(ll i = 2 ; i*i <=n  ;i++)if(n%i==0)return 0 ;
    return 1 ;
}

int main(){

    //freopen("DataSet.txt" , "r" , stdin) ;
    //freopen("1.txt" , "w" , stdout) ;

    cin.tie(0);
    cin.sync_with_stdio(0);

    int n ; cin >> n ;
    vi fr(100009) ;
    loop(n){
        int x ; cin >> x ; fr[x] = 1;
    }
    int a = 0  ;
    vi ans(100001) ;
    loop(100001){
        if(i>1 && fr[i]){
            ans[i]++ ;
            //if(i<20)cout << i << " : " << ans[i] << '\n' ;
            a = max(a , (int)ans[i]) ;
            int I = i ;
            int II = i ;
            ll aa= ans[I] ;
            for(ll i = 2 ; i*i<=I ; i++){
                if(I%i==0){
                    while(I%i==0)I/=i ;
                    for(int j = II+i ; j<=100000 ; j+=i){
                        ans[j] = max(ans[j] , aa) ;
                        //if(j<20)cout << j << " jj : " << ans[j] << '\n' ;
                    }
                }
            }
            if(I!=1){
                for(int j = II+I ; j<=100000 ; j+=I){
                    ans[j] = max(ans[j] , aa) ;
                    //if(j<20)cout << j << " jj : " << ans[j] << '\n' ;
                }
            }
        }
    }
    cout << max(a, 1);
    return 0;
}


#include <bits/stdc++.h>
#define loop(n) for(ll  i= 0 ; i< (n) ; i++)
#define ll long long
#define vi vector<ll>
#define ii pair<ll,ll>
#define inf 1000000000000000
#define MAXNODE 250009
#define all(x) x.begin(),x.end()
#define pii pair<ll,ll>
#define vii vector<pii>
#define OO (0x7fffffffffffffff)
#define md ((ll)1e9+9)
#define pi (3.141592653589793)
#define tRed(x) (x)*(pi)/(180.0)
#define tDeg(x) (x)*(180.0)/(pi)
#define LCM(a,b) ( (a*b)/__gcd(a,b) )
#define lp(i,n) for(int i = 0 ; i <(n) ; i++)
#define prV(v) cout << "(v) : " ; loop(v.size()){cout << v[i] << " " ; } cout << '\n' ;

using namespace std;

vi sp(100009) ;

int prime(int n ){
    for(ll i = 2 ; i*i <=n  ;i++)if(n%i==0)return 0 ;
    return 1 ;
}

vi pf(int n ){

    vi v ;

    while(n>1){

        int p = sp[n] ;
        v.push_back(p) ;
        while(n%p==0)n/=p ;

    }

    return v;
}

int main(){

    for(int i = 2 ; i<=100000 ; i++){
        if(sp[i])continue ;
        for(int j = i ; j<=100000 ; j+=i){
            sp[j] = i ;
        }
    }

    //freopen("DataSet.txt" , "r" , stdin) ;
    //freopen("1.txt" , "w" , stdout) ;

    //cin.tie(0);
    //cin.sync_with_stdio(0);

    int n ; cin >> n ;
    vi fr(100009) ;

    loop(n){
        int x ; cin >> x ; fr[x] = 1;
    }

    vi ans(1000001) ;
    int a=  0 ;
    for(int i = 2;  i<= 100000 ; i++ ){

        vi v = pf(i) ;

        if(!fr[i])continue ;

        int cnt = 0 ;

        for(int x : v){
            cnt = max(cnt ,(int) ans[x] ) ;
        }

        cnt++ ;
        a= max(a, cnt) ;
        for(int x :v){
            ans[x] = max((int)ans[x] , cnt) ;
        }
        //if(i<20)cout << i<< '\n' ;

    }

    cout << max(1 , a) ;
    return 0;
}


#include <bits/stdc++.h>
#define loop(n) for(ll  i= 0 ; i< (n) ; i++)
#define ll long long
#define vi vector<ll>
#define ii pair<ll,ll>
#define inf 1000000000000000
#define MAXNODE 250009
#define all(x) x.begin(),x.end()
#define pii pair<ll,ll>
#define vii vector<pii>
#define OO (0x7fffffffffffffff)
#define md ((ll)1e9+9)
#define pi (3.141592653589793)
#define tRed(x) (x)*(pi)/(180.0)
#define tDeg(x) (x)*(180.0)/(pi)
#define LCM(a,b) ( (a*b)/__gcd(a,b) )
#define lp(i,n) for(int i = 0 ; i <(n) ; i++)
#define prV(v) cout << "(v) : " ; loop(v.size()){cout << v[i] << " " ; } cout << '\n' ;

using namespace std;

int prime(int n ){
    for(ll i = 2 ; i*i <=n  ;i++)if(n%i==0)return 0 ;
    return 1 ;
}

int main(){

    //freopen("DataSet.txt" , "r" , stdin) ;
    //freopen("1.txt" , "w" , stdout) ;

    cin.tie(0);
    cin.sync_with_stdio(0);

    int n ; cin >> n ;
    vi fr(100009) ;
    loop(n){
        int x ; cin >> x ; fr[x] = 1;
    }
    int a = 0  ;
    vi ans(100001) ;
    loop(100001){
        if(i>1 && fr[i]){
            ans[i]++ ;
            //if(i<20)cout << i << " : " << ans[i] << '\n' ;
            a = max(a , (int)ans[i]) ;
            int I = i ;
            ll aa= ans[I] ;
            for(ll i = 2 ; i*i<=I ; i++){
                if(I%i==0){
                    while(I%i==0)I/=i ;
                    for(int j = i+i ; j<=100000 ; j+=i){
                        ans[j] = max(ans[j] , aa) ;
                        //if(j<20)cout << j << " jj : " << ans[j] << '\n' ;
                    }
                }
            }
            if(I!=1){
                for(int j = I+I ; j<=100000 ; j+=I){
                    ans[j] = max(ans[j] , aa) ;
                    //if(j<20)cout << j << " jj : " << ans[j] << '\n' ;
                }
            }
        }
    }
    cout << a;
    return 0;
}


#include <bits/stdc++.h>
#define loop(n) for(ll  i= 0 ; i< (n) ; i++)
#define ll long long
#define vi vector<ll>
#define ii pair<ll,ll>
#define inf 1000000000000000
#define MAXNODE 250009
#define all(x) x.begin(),x.end()
#define pii pair<ll,ll>
#define vii vector<pii>
#define OO (0x7fffffffffffffff)
#define md ((ll)1e9+9)
#define pi (3.141592653589793)
#define tRed(x) (x)*(pi)/(180.0)
#define tDeg(x) (x)*(180.0)/(pi)
#define LCM(a,b) ( (a*b)/__gcd(a,b) )
#define lp(i,n) for(int i = 0 ; i <(n) ; i++)
#define prV(v) cout << "(v) : " ; loop(v.size()){cout << v[i] << " " ; } cout << '\n' ;

using namespace std;

int prime(int n ){
    for(ll i = 2 ; i*i <=n  ;i++)if(n%i==0)return 0 ;
    return 1 ;
}

int main(){

    vi sp(1000009) ;

    for(int i = 2 ; i<=100000 ; i++){
        if(sp[i])continue ;
        for(int j = i ; j<=100000 ; j+=i){
            sp[j] = i ;
        }
    }

    //freopen("DataSet.txt" , "r" , stdin) ;
    //freopen("1.txt" , "w" , stdout) ;

    cin.tie(0);
    cin.sync_with_stdio(0);

    int n ; cin >> n ;
    vi fr(100009) ;
    loop(n){
        int x ; cin >> x ; fr[x] = 1;
    }
    int a = 0  ;
    vi ans(100001) ;
    loop(100001){
        if(i>1 && fr[i]){
            ans[i]++ ;
            //if(i<20)cout << i << " : " << ans[i] << '\n' ;
            a = max(a , (int)ans[i]) ;

            int I = i ;
            int II = i ;
            while(I>1 && sp[I]!=I){
                int p = sp[I] ;
                //cout << "p : " << p << '\n' ;
                while(I%p==0)I/=p  ;

                for(int j = II+p ; j<=100000 ; j+=p ){
                    ans[j] = max(ans[j] , ans[i]) ;
                }

            }
            //cout << "after : "<< I << '\n' ;
            if(I!=1){
                for(int j=II+I ; j<=100000 ; j+=I){
                    ans[j] = max(ans[j] , ans[i]) ;
                }
            }
        }
    }
    cout << max(a, 1);
    return 0;
}