#include <bits/stdc++.h>
#define fi first
#define se second
using namespace std;

long long n, cur, ans, le, l, r, mid, cnt[300005], mx[300005], mn = 0x3f3f3f3f3f3f3f3f, me = 0x3f3f3f3f;
pair <long long, long long> a[300005];

int main() {
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> a[i].fi >> a[i].se;
		me = min(me, (long long) a[i].fi);
		le = max(le, (long long) a[i].se);
	}
	sort(a, a + n);
	fill(mx, mx + n + 1, 0x3f3f3f3f3f3f3f3f);
	for (int i = n - 1; i >= 0; i--) {
//		cout << a[i].fi << ' ' << a[i].se << endl;
		if (a[i].fi > le) mx[i] = 0, cnt[i] = 1;
		if (mx[i] > mx[i + 1] + a[i + 1].fi - a[i].fi){
			mx[i] = mx[i + 1] + a[i + 1].fi - a[i].fi;
			cnt[i] = cnt[i + 1];
		}
//		else if (mx[i] == mx[i + 1] + a[i + 1].fi - a[i].fi) cnt[i] += cnt[i + 1];
		l = 0, r = i - 1;
		while (l < r) {
			mid = (l + r + 1) / 2;
			if (a[i].se < a[mid].fi) r = mid - 1;
			else l = mid;
		}
//		cout << l << endl;
		if (a[i].se >= a[l].fi) {
			if (mx[l] > mx[i] + a[i].se - a[l].fi) {
				mx[l] = mx[i] + a[i].se - a[l].fi;
				cnt[l] = cnt[i];
			}
			else if (mx[l] == mx[i] + a[i].se - a[l].fi) cnt[l] += cnt[i];
		}
		if (a[i].se < me) {
			if (mx[i] + a[i].se < mn) {
				mn = mx[i] + a[i].se;
				ans = cnt[i];
			}
			else if (mx[i] + a[i].se == mn) ans += cnt[i];
		}
//		cout << mx[i] << ' ' << cnt[i] << endl;
	}
	cout << ans << endl;
}


#include <bits/stdc++.h>
#define fi first
#define se second
using namespace std;

long long n, cur, ans, le, l, r, mid, cnt[300005], mx[300005], mn = 0x3f3f3f3f3f3f3f3f, me = 0x3f3f3f3f;
pair <int, int> a[300005];

int main() {
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> a[i].fi >> a[i].se;
		me = min(me, (long long) a[i].fi);
		le = max(le, (long long) a[i].se);
	}
	sort(a, a + n);
	fill(mx, mx + n + 1, 0x3f3f3f3f3f3f3f3f);
	for (int i = n - 1; i >= 0; i--) {
//		cout << a[i].fi << ' ' << a[i].se << endl;
		if (a[i].fi > le) mx[i] = 0, cnt[i] = 1;
		if (mx[i] > mx[i + 1] + a[i + 1].fi - a[i].fi){
			mx[i] = mx[i + 1] + a[i + 1].fi - a[i].fi;
			cnt[i] = cnt[i + 1];
		}
//		else if (mx[i] == mx[i + 1] + a[i + 1].fi - a[i].fi) cnt[i] += cnt[i + 1];
		l = 0, r = i - 1;
		while (l < r) {
			mid = (l + r + 1) / 2;
			if (a[i].se < a[mid].fi) r = mid - 1;
			else l = mid;
		}
//		cout << l << endl;
		if (a[i].se >= a[l].fi) {
			if (mx[l] > mx[i] + a[i].se - a[l].fi) {
				mx[l] = mx[i] + a[i].se - a[l].fi;
				cnt[l] = cnt[i];
			}
			else if (mx[l] == mx[i] + a[i].se - a[l].fi) cnt[l] += cnt[i];
		}
		if (a[i].se < me) {
			if (mx[i] + a[i].se < mn) {
				mn = mx[i] + a[i].se;
				ans = cnt[i];
			}
			else if (mx[i] + a[i].se == mn) ans += cnt[i];
		}
//		cout << mx[i] << ' ' << cnt[i] << endl;
	}
	cout << ans << endl;
}


#include <bits/stdc++.h>
#define fi first
#define se second
using namespace std;

const long long MOD = 1e9 + 7;
long long n, mxe, cur, ans, le, l, r, mid, mx[300005], cnt[300005], mn = 0x3f3f3f3f3f3f3f3f, me = 0x3f3f3f3f;
pair <long long, long long> a[300005];

int main() {
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> a[i].fi >> a[i].se;
		mxe = max(mxe, (long long) a[i].fi);
		me = min(me, (long long) a[i].fi);
		le = max(le, (long long) a[i].se);
	}
	sort(a, a + n);
	fill(mx, mx + n + 1, 0x3f3f3f3f3f3f3f3f);
	for (int i = n - 1; i >= 0; i--) {
//		cout << a[i].fi << ' ' << a[i].se << endl;
		if (a[i].fi > le) mx[i] = 0, cnt[i] = 1;
		if (mx[i] > mx[i + 1] + a[i + 1].fi - a[i].fi){
			mx[i] = mx[i + 1] + a[i + 1].fi - a[i].fi;
			cnt[i] = cnt[i + 1];
		}
		else if (mx[i] == mx[i + 1] + a[i + 1].fi - a[i].fi && a[i].fi != mxe) cnt[i] += cnt[i + 1];
		l = 0, r = i - 1;
		while (l < r) {
			mid = (l + r + 1) / 2;
			if (a[i].se < a[mid].fi) r = mid - 1;
			else l = mid;
		}
//		cout << l << endl;
		if (a[i].se >= a[l].fi) {
			if (mx[l] > mx[i] + a[i].se - a[l].fi) {
				mx[l] = mx[i] + a[i].se - a[l].fi;
				cnt[l] = cnt[i];
			}
			else if (mx[l] == mx[i] + a[i].se - a[l].fi) cnt[l] = (cnt[l] + cnt[i]) % MOD;
		}
		if (a[i].se < me) {
			if (mx[i] + a[i].se < mn) {
				mn = mx[i] + a[i].se;
				ans = cnt[i];
			}
			else if (mx[i] + a[i].se == mn) ans = (ans + cnt[i]) % MOD;
		}
//		cout << mx[i] << ' ' << cnt[i] << endl;
	}
	cout << ans << endl;
}


#include <bits/stdc++.h>
#define fi first
#define se second
using namespace std;

int n, cur, ans, le, cnt[300005], mx[300005], mn = 0x3f3f3f3f, me = 0x3f3f3f3f;
pair <int, int> a[300005];
bool nested;

int main() {
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> a[i].fi >> a[i].se;
		me = min(me, a[i].fi);
		le = max(le, a[i].se);
	}
	sort(a, a + n);
	fill(mx, mx + n, 0x3f3f3f3f);
	fill(cnt, cnt + n, 1);
	for (int i = n - 1; i >= 0; i--) {
		if (a[i].fi > le) mx[i] = 0;
		for (int j = i - 1; j >= 0; j--) {
			if (a[i].se >= a[j].fi) {
				if (mx[j] + a[j].fi > mx[i] + a[i].se) {
					mx[j] = mx[i] + a[i].se - a[j].fi;
					cnt[j] = cnt[i];
				}
				else if (mx[j] + a[j].fi == mx[i] + a[i].se) cnt[j] += cnt[i];
			}
		}
		if (a[i].se < me) {
			if (mx[i] + cur < mn) {
				mn = mx[i] + cur;
				ans = cnt[i];
			}
			else if (mx[i] + cur == mn) ans += cnt[i];
		}
	}
	cout << ans << endl;
}


#include <bits/stdc++.h>
#define fi first
#define se second
using namespace std;

int n, cur, ans, le, cnt[300005], mx[300005], mn = 0x3f3f3f3f;
pair <int, int> a[300005];
bool nested;

int main() {
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> a[i].fi >> a[i].se;
		le = max(le, a[i].se);
	}
	sort(a, a + n);
	fill(mx, mx + n, 0x3f3f3f3f);
	fill(cnt, cnt + n, 1);
	for (int i = n - 1; i >= 0; i--) {
		cur = a[i].se, nested = 1;
		if (a[i].fi > le) mx[i] = 0;
		for (int j = i - 1; j >= 0; j--) {
			if (cur >= a[j].fi) {
				if (mx[j] > mx[i] + cur - a[j].fi) {
					mx[j] = mx[i] + cur - a[j].fi;
					cnt[j] = cnt[i];
				}
				else if (mx[j] == mx[i] + cur - a[j].fi) cnt[j] += cnt[i];
				nested = 0;
			}
		}
		if (nested) {
			if (mx[i] + cur < mn) {
				mn = mx[i] + cur;
				ans = cnt[i];
			}
			else if (mx[i] + cur == mn) ans += cnt[i];
		}
	}
	cout << ans << endl;
}


#include <bits/stdc++.h>
#define fi first
#define se second
using namespace std;

const long long MOD = 1e9 + 7;
long long n, cur, ans, le, l, r, mid, mx[300005], cnt[300005], mn = 0x3f3f3f3f3f3f3f3f, me = 0x3f3f3f3f;
pair <long long, long long> a[300005];

int main() {
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> a[i].fi >> a[i].se;
		me = min(me, (long long) a[i].fi);
		le = max(le, (long long) a[i].se);
	}
	sort(a, a + n);
	fill(mx, mx + n + 1, 0x3f3f3f3f3f3f3f3f);
	for (int i = n - 1; i >= 0; i--) {
//		cout << a[i].fi << ' ' << a[i].se << endl;
		if (a[i].fi > le) mx[i] = 0, cnt[i] = 1;
		if (mx[i] > mx[i + 1] + a[i + 1].fi - a[i].fi){
			mx[i] = mx[i + 1] + a[i + 1].fi - a[i].fi;
			cnt[i] = cnt[i + 1];
		}
//		else if (mx[i] == mx[i + 1] + a[i + 1].fi - a[i].fi) cnt[i] += cnt[i + 1];
		l = 0, r = i - 1;
		while (l < r) {
			mid = (l + r + 1) / 2;
			if (a[i].se < a[mid].fi) r = mid - 1;
			else l = mid;
		}
//		cout << l << endl;
		if (a[i].se >= a[l].fi) {
			if (mx[l] > mx[i] + a[i].se - a[l].fi) {
				mx[l] = mx[i] + a[i].se - a[l].fi;
				cnt[l] = cnt[i];
			}
			else if (mx[l] == mx[i] + a[i].se - a[l].fi) cnt[l] = (cnt[l] + cnt[i]) % MOD;
		}
		if (a[i].se < me) {
			if (mx[i] + a[i].se < mn) {
				mn = mx[i] + a[i].se;
				ans = cnt[i];
			}
			else if (mx[i] + a[i].se == mn) ans = (ans + cnt[i]) % MOD;
		}
//		cout << mx[i] << ' ' << cnt[i] << endl;
	}
	cout << ans << endl;
}


#include <bits/stdc++.h>
#define fi first
#define se second
using namespace std;

int n, cur, ans, le, l, r, mid, cnt[300005], mx[300005], mn = 0x3f3f3f3f, me = 0x3f3f3f3f;
pair <int, int> a[300005];
bool nested;

int main() {
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> a[i].fi >> a[i].se;
		me = min(me, a[i].fi);
		le = max(le, a[i].se);
	}
	sort(a, a + n);
	fill(mx, mx + n + 1, 0x3f3f3f3f);
	for (int i = n - 1; i >= 0; i--) {
//		cout << a[i].fi << ' ' << a[i].se << endl;
		if (a[i].fi > le) mx[i] = 0, cnt[i] = 1;
		if (mx[i] > mx[i + 1] + a[i + 1].fi - a[i].fi){
			mx[i] = mx[i + 1] + a[i + 1].fi - a[i].fi;
			cnt[i] = cnt[i + 1];
		}
//		else if (mx[i] == mx[i + 1] + a[i + 1].fi - a[i].fi) cnt[i] += cnt[i + 1];
		l = 0, r = i - 1;
		while (l < r) {
			mid = (l + r + 1) / 2;
			if (a[i].se < a[mid].fi) r = mid - 1;
			else l = mid;
		}
//		cout << l << endl;
		if (a[i].se >= a[l].fi) {
			if (mx[l] > mx[i] + a[i].se - a[l].fi) {
				mx[l] = mx[i] + a[i].se - a[l].fi;
				cnt[l] = cnt[i];
			}
			else if (mx[l] == mx[i] + a[i].se - a[l].fi) cnt[l] += cnt[i];
		}
		if (a[i].se < me) {
			if (mx[i] + a[i].se < mn) {
				mn = mx[i] + a[i].se;
				ans = cnt[i];
			}
			else if (mx[i] + a[i].se == mn) ans += cnt[i];
		}
//		cout << mx[i] << ' ' << cnt[i] << endl;
	}
	cout << ans << endl;
}


#include <bits/stdc++.h>
#define fi first
#define se second
using namespace std;

long long n, cur, ans, le, l, r, mid, mx[300005], mn = 0x3f3f3f3f3f3f3f3f, me = 0x3f3f3f3f;
unsigned long long cnt[300005];
pair <long long, long long> a[300005];

int main() {
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> a[i].fi >> a[i].se;
		me = min(me, (long long) a[i].fi);
		le = max(le, (long long) a[i].se);
	}
	sort(a, a + n);
	fill(mx, mx + n + 1, 0x3f3f3f3f3f3f3f3f);
	for (int i = n - 1; i >= 0; i--) {
//		cout << a[i].fi << ' ' << a[i].se << endl;
		if (a[i].fi > le) mx[i] = 0, cnt[i] = 1;
		if (mx[i] > mx[i + 1] + a[i + 1].fi - a[i].fi){
			mx[i] = mx[i + 1] + a[i + 1].fi - a[i].fi;
			cnt[i] = cnt[i + 1];
		}
//		else if (mx[i] == mx[i + 1] + a[i + 1].fi - a[i].fi) cnt[i] += cnt[i + 1];
		l = 0, r = i - 1;
		while (l < r) {
			mid = (l + r + 1) / 2;
			if (a[i].se < a[mid].fi) r = mid - 1;
			else l = mid;
		}
//		cout << l << endl;
		if (a[i].se >= a[l].fi) {
			if (mx[l] > mx[i] + a[i].se - a[l].fi) {
				mx[l] = mx[i] + a[i].se - a[l].fi;
				cnt[l] = cnt[i];
			}
			else if (mx[l] == mx[i] + a[i].se - a[l].fi) cnt[l] += cnt[i];
		}
		if (a[i].se < me) {
			if (mx[i] + a[i].se < mn) {
				mn = mx[i] + a[i].se;
				ans = cnt[i];
			}
			else if (mx[i] + a[i].se == mn) ans += cnt[i];
		}
//		cout << mx[i] << ' ' << cnt[i] << endl;
	}
	cout << ans << endl;
}


#include <bits/stdc++.h>
#define fi first
#define se second
using namespace std;

long long n, cur, ans, le, l, r, mid, cnt[300005], mx[300005], mn = 0x3f3f3f3f3f3f3f3f, me = 0x3f3f3f3f;
pair <int, int> a[300005];

int main() {
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> a[i].fi >> a[i].se;
		me = min(me, (long long) a[i].fi);
		le = max(le, (long long) a[i].se);
	}
	sort(a, a + n);
	fill(mx, mx + n + 1, 0x3f3f3f3f);
	for (int i = n - 1; i >= 0; i--) {
//		cout << a[i].fi << ' ' << a[i].se << endl;
		if (a[i].fi > le) mx[i] = 0, cnt[i] = 1;
		if (mx[i] > mx[i + 1] + a[i + 1].fi - a[i].fi){
			mx[i] = mx[i + 1] + a[i + 1].fi - a[i].fi;
			cnt[i] = cnt[i + 1];
		}
//		else if (mx[i] == mx[i + 1] + a[i + 1].fi - a[i].fi) cnt[i] += cnt[i + 1];
		l = 0, r = i - 1;
		while (l < r) {
			mid = (l + r + 1) / 2;
			if (a[i].se < a[mid].fi) r = mid - 1;
			else l = mid;
		}
//		cout << l << endl;
		if (a[i].se >= a[l].fi) {
			if (mx[l] > mx[i] + a[i].se - a[l].fi) {
				mx[l] = mx[i] + a[i].se - a[l].fi;
				cnt[l] = cnt[i];
			}
			else if (mx[l] == mx[i] + a[i].se - a[l].fi) cnt[l] += cnt[i];
		}
		if (a[i].se < me) {
			if (mx[i] + a[i].se < mn) {
				mn = mx[i] + a[i].se;
				ans = cnt[i];
			}
			else if (mx[i] + a[i].se == mn) ans += cnt[i];
		}
//		cout << mx[i] << ' ' << cnt[i] << endl;
	}
	cout << ans << endl;
}


#include <bits/stdc++.h>
#define fi first
#define se second
using namespace std;

const long long MOD = 1e9 + 7;
long long n, mxe, cur, ans, le, l, r, mid, mx[300005], cnt[300005], mn = 0x3f3f3f3f3f3f3f3f, me = 0x3f3f3f3f;
pair <long long, long long> a[300005];

int main() {
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> a[i].fi >> a[i].se;
		mxe = max(mxe, (long long) a[i].fi);
		me = min(me, (long long) a[i].fi);
		le = max(le, (long long) a[i].se);
	}
	sort(a, a + n);
	fill(mx, mx + n + 1, 0x3f3f3f3f3f3f3f3f);
	for (int i = n - 1; i >= 0; i--) {
//		cout << a[i].fi << ' ' << a[i].se << endl;
		if (a[i].fi > le) mx[i] = 0;
		if (mx[i] > mx[i + 1] + a[i + 1].fi - a[i].fi){
			mx[i] = mx[i + 1] + a[i + 1].fi - a[i].fi;
			cnt[i] = cnt[i + 1];
		}
		else if (mx[i] == mx[i + 1] + a[i + 1].fi - a[i].fi && cnt[i] != 0) cnt[i] = (cnt[i] + cnt[i + 1]) % MOD;
		if (a[i].fi > le) cnt[i] = 1;
		l = 0, r = i - 1;
		while (l < r) {
			mid = (l + r + 1) / 2;
			if (a[i].se < a[mid].fi) r = mid - 1;
			else l = mid;
		}
//		cout << l << endl;
		if (a[i].se >= a[l].fi) {
			if (mx[l] > mx[i] + a[i].se - a[l].fi) {
				mx[l] = mx[i] + a[i].se - a[l].fi;
				cnt[l] = cnt[i];
			}
			else if (mx[l] == mx[i] + a[i].se - a[l].fi) cnt[l] = (cnt[l] + cnt[i]) % MOD;
		}
		if (a[i].se < me) {
			if (mx[i] + a[i].se < mn) {
				mn = mx[i] + a[i].se;
				ans = cnt[i];
			}
			else if (mx[i] + a[i].se == mn) ans = (ans + cnt[i]) % MOD;
		}
//		cout << mx[i] << ' ' << cnt[i] << endl;
	}
	cout << ans << endl;
}


#include <bits/stdc++.h>
#define fi first
#define se second
using namespace std;

long long n, cur, ans, le, l, r, mid, cnt[300005], mx[300005], mn = 0x3f3f3f3f, me = 0x3f3f3f3f;
pair <int, int> a[300005];

int main() {
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> a[i].fi >> a[i].se;
		me = min(me, (long long) a[i].fi);
		le = max(le, (long long) a[i].se);
	}
	sort(a, a + n);
	fill(mx, mx + n + 1, 0x3f3f3f3f);
	for (int i = n - 1; i >= 0; i--) {
//		cout << a[i].fi << ' ' << a[i].se << endl;
		if (a[i].fi > le) mx[i] = 0, cnt[i] = 1;
		if (mx[i] > mx[i + 1] + a[i + 1].fi - a[i].fi){
			mx[i] = mx[i + 1] + a[i + 1].fi - a[i].fi;
			cnt[i] = cnt[i + 1];
		}
//		else if (mx[i] == mx[i + 1] + a[i + 1].fi - a[i].fi) cnt[i] += cnt[i + 1];
		l = 0, r = i - 1;
		while (l < r) {
			mid = (l + r + 1) / 2;
			if (a[i].se < a[mid].fi) r = mid - 1;
			else l = mid;
		}
//		cout << l << endl;
		if (a[i].se >= a[l].fi) {
			if (mx[l] > mx[i] + a[i].se - a[l].fi) {
				mx[l] = mx[i] + a[i].se - a[l].fi;
				cnt[l] = cnt[i];
			}
			else if (mx[l] == mx[i] + a[i].se - a[l].fi) cnt[l] += cnt[i];
		}
		if (a[i].se < me) {
			if (mx[i] + a[i].se < mn) {
				mn = mx[i] + a[i].se;
				ans = cnt[i];
			}
			else if (mx[i] + a[i].se == mn) ans += cnt[i];
		}
//		cout << mx[i] << ' ' << cnt[i] << endl;
	}
	cout << ans << endl;
}


#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdio>
#include <map>
#include <set>
#define mp make_pair
#define fi first
#define se second
using namespace std;
const int maxn = 1000006;
const int P = 1000000007;
const int INF = 1000000000;
pair <int, int> a[maxn];
int f[maxn][2], s[maxn][2];
int read(){
    int c = 0, f = 1; char ch = getchar();
    while ((ch < '0' || '9' < ch) && ch != '-') ch = getchar();
    if (ch == '-') f = -1, ch = getchar();
    while ('0' <= ch && ch <= '9') c = c * 10 + ch - '0', ch = getchar();
    return c * f;
}
int main(){
    int n = read();
    for (int i = 1; i <= n; ++ i)
        a[i].fi = read(), a[i].se = read();
    sort(a + 1, a + 1 + n);
    int mx = 0;
    s[0][1] = 1;
    for (int i = 1; i <= n; ++ i){
        int t = upper_bound(a + 1, a + i, mp(a[i].se, INF)) - a - 1;
        mx = max(mx, t);
        f[i][0] = s[t][0] + a[i].se;
        f[i][1] = s[t][1];
        if (s[i - 1][0] > f[i][0] - a[i].fi)
            s[i][0] = f[i][0] - a[i].fi, s[i][1] = f[i][1];
        else if (s[i - 1][0] == f[i][0] - a[i].fi)
            s[i][0] = s[i - 1][0], s[i][1] = (s[i - 1][1] + f[i][1]) % P;
    }
    int x = INF, y = 0;
    for (int i = mx + 1; i <= n; ++ i)
        if (f[i][0] < x)
            x = f[i][0], y = f[i][1];
        else if (f[i][0] == x)
            y = (y + f[i][1]) % P;
    cout << y << endl;
}


#include <bits/stdc++.h>

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
// typedef complex<double> point;
ll mod = 1e9 + 7;
#define EPS 1e-1
#define PI 3.141592653589
#define point complex<ld>
#define dot(a, b) (conj(a) * b).real()
#define cross(a, b) (conj(a) * b).imag()
#define line tuple<ll, ll, ll>
#define X real()
#define Y imag()

// int dx[] = { 0, 0, 1, -1 };
// int dy[] = { 1, -1, 0, 0 };

#define iofile                                                                 \
  freopen("input.txt", "r", stdin);                                            \
  freopen("output.txt", "w", stdout);
#define fastio ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
using namespace std;

void primeFactors(ll n, vector<ll> &vec) {

  while (n % 2 == 0) {
    vec.push_back(2);
    n = n / 2;
  }
  for (ll i = 3; i <= sqrt(n); i = i + 2) {
    while (n % i == 0) {
      vec.push_back(i);
      n = n / i;
    }
  }

  if (n > 2) {
    vec.push_back(n);
  }
}

ll gcd(ll a, ll b) {
  if (b == 0) {
    return a;
  } else {
    return gcd(b, a % b);
  }
}

ll Lcm(ll a, ll b) { return ((a * b) / gcd(a, b)); }

line getL(point p1, point p2) {
  ll a, b, c;
  a = p2.Y - p1.Y;
  b = p1.X - p2.X;
  c = -a * p1.X - b * p1.Y;
  ll gcdres = abs(gcd(a, gcd(b, c)));
  if (a < 0 || a == 0 && b < 0) {
    gcdres *= -1;
  }
  a /= gcdres;
  b /= gcdres;
  c /= gcdres;
  return line(a, b, c);
}

ll fastpow(ll base, ll pow) {
  if (!base)
    return 0;
  if (!pow)
    return 1;
  if (pow == 1)
    return base;
  ll x = fastpow(base, pow / 2) % mod;
  x *= x;
  x %= mod;
  if (pow % 2)
    x *= base;
  return x % mod;
}

ll inverse(ll x) { return fastpow(x, mod - 2) % mod; }

ld disty(pair<double, double> a, pair<double, double> b) {
  return sqrt(pow(b.second - a.second, 2.0) + pow(b.first - a.first, 2.0));
}

/*ll fact[(int)1e6 + 5], inv[(int)1e6 + 5];
void init()
{
    fact[0] = inv[0] = 1;
    for (int i = 1; i <= 1e6; i++)
    {
        fact[i] = (i * fact[i - 1]) % mod;
        inv[i] = inverse(fact[i]);
    }
}*/

void factorize(ll x, set<ll> &ss) {
  while (x % 2 == 0)
    ss.insert(2), x /= 2;
  for (int i = 3; i <= sqrt(x); i += 2)
    while (x % i == 0)
      ss.insert(i), x /= i;
  if (x > 2)
    ss.insert(x);
}

/*ll ncr(ll n, ll r)
{
    return ((fact[n] * inv[r]) % mod * inv[n - r]) % mod;
}*/

void SieveOfEratosthenes(ll n, bool prime[]) {

  for (int p = 2; p * p <= n; p++) {

    if (prime[p] == true) {
      for (int i = p * p; i <= n; i += p)
        prime[i] = false;
    }
  }
}
void divisors(ll n, vector<ll> &vec) {
  for (ll i = 2; i <= sqrt(n); ++i) {
    if (n % i == 0 && i != sqrt(n)) {
      vec.push_back(i);
      vec.push_back(n / i);
    } else if (n % i == 0) {
      vec.push_back(i);
    }
  }
}

bool isprime(ll n) {
  if (n == 1) {
    return false;
  }
  for (int i = 2; i <= sqrt(n); ++i) {
    if (n % i == 0) {
      return false;
    }
  }
  return true;
}

point rot(point p, ld angle) { return (p * polar((ld)1.0, angle)); }

point rotA(point p, point A, ld angle) {
  return (((p - A) * polar((ld)1, angle)) + A);
}

ld distance(point a, point b) {
  ld x1 = a.X, y1 = a.Y, x2 = b.X, y2 = b.Y;
  return pow(y2 - y1, 2) + pow(x2 - x1, 2);
}

int distSq(pair<ll, ll> p, pair<ll, ll> q) {
  return (p.first - q.first) * (p.first - q.first) +
         (p.second - q.second) * (p.second - q.second);
}

bool isSquare(pair<ll, ll> p1, pair<ll, ll> p2, pair<ll, ll> p3,
              pair<ll, ll> p4) {
  ll d2 = distSq(p1, p2);
  ll d3 = distSq(p1, p3);
  ll d4 = distSq(p1, p4);
  if (d2 == d3 && 2 * d2 == d4 && 2 * d2 == distSq(p2, p3)) {
    int d = distSq(p2, p4);
    return (d == distSq(p3, p4) && d == d2);
  }

  // The below two cases are similar to above case
  if (d3 == d4 && 2 * d3 == d2 && 2 * d3 == distSq(p3, p4)) {
    int d = distSq(p2, p3);
    return (d == distSq(p2, p4) && d == d3);
  }
  if (d2 == d4 && 2 * d2 == d3 && 2 * d2 == distSq(p2, p4)) {
    int d = distSq(p2, p3);
    return (d == distSq(p3, p4) && d == d2);
  }

  return false;
}

ll FP(ll base, ll power, ll m) {

  if (power == 0) {
    return 1;
  } else if (power % 2 == 0) {
    ll res = FP(base, power / 2, m);
    return (res % m * res % m) % m;
  } else {
    ll res = FP(base, power / 2, m);
    return ((((base % m * (res % m)) % m) * (res % m) % m) % m);
  }
}
ll EGCD(ll a, ll b, ll &x, ll &y) {

  if (b == 0) {
    x = 0;
    y = 1;
    return a;
  } else {
    ll ans = EGCD(b, a % b, x, y);
    ll tmp = x;
    x = y - (a / b) * x;
    y = tmp;
    return ans;
  }
}
// ll f[(int)1e7+7],in[(int)1e7+7];
/*void prec(ull n){
f[0]=1;
in[0]=1;
for(int i=1;i<=n;++i){
    f[i]=(f[i-1]*i)%mod;
    in[i]=FP(f[i],mod-2,mod);
}
}
ll npr(ll n,ll r){
    return (f[n]*in[n-r])%mod;
}
ll NCR(ll n,ll r){
return (((f[n]*in[n-r])%mod)*in[r])%mod;
}*/
ll factorial(ll n) {
  if (n == 0) {
    return 1;
  } else
    return n * factorial(n - 1);
}

int main() {
  // fastio
  ll freq[100005]={};
  ll n;
  cin>>n;
  ll arr[n];
  ll maxi=-1;
  for(int i=0;i<n;++i){
    cin>>arr[i];
  }
  for(int i=0;i<n;++i){
        freq[arr[i]]=1;
    for(int j=i-1;j>=0;--j){
        if(gcd(arr[i],arr[j])>1){freq[arr[i]]=1+freq[arr[j]];break;}
    }
    maxi=max(maxi,freq[arr[i]]);
  }
  cout<<maxi<<"\n";
  return 0;
}


#include <bits/stdc++.h>

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
// typedef complex<double> point;
ll mod = 1e9 + 7;
#define EPS 1e-1
#define PI 3.141592653589
#define point complex<ld>
#define dot(a, b) (conj(a) * b).real()
#define cross(a, b) (conj(a) * b).imag()
#define line tuple<ll, ll, ll>
#define X real()
#define Y imag()

// int dx[] = { 0, 0, 1, -1 };
// int dy[] = { 1, -1, 0, 0 };

#define iofile                                                                 \
  freopen("input.txt", "r", stdin);                                            \
  freopen("output.txt", "w", stdout);
#define fastio ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
using namespace std;

void primeFactors(ll n, vector<ll> &vec) {

  while (n % 2 == 0) {
    vec.push_back(2);
    n = n / 2;
  }
  for (ll i = 3; i <= sqrt(n); i = i + 2) {
    while (n % i == 0) {
      vec.push_back(i);
      n = n / i;
    }
  }

  if (n > 2) {
    vec.push_back(n);
  }
}

ll gcd(ll a, ll b) {
  if (b == 0) {
    return a;
  } else {
    return gcd(b, a % b);
  }
}

ll Lcm(ll a, ll b) { return ((a * b) / gcd(a, b)); }

line getL(point p1, point p2) {
  ll a, b, c;
  a = p2.Y - p1.Y;
  b = p1.X - p2.X;
  c = -a * p1.X - b * p1.Y;
  ll gcdres = abs(gcd(a, gcd(b, c)));
  if (a < 0 || a == 0 && b < 0) {
    gcdres *= -1;
  }
  a /= gcdres;
  b /= gcdres;
  c /= gcdres;
  return line(a, b, c);
}

ll fastpow(ll base, ll pow) {
  if (!base)
    return 0;
  if (!pow)
    return 1;
  if (pow == 1)
    return base;
  ll x = fastpow(base, pow / 2) % mod;
  x *= x;
  x %= mod;
  if (pow % 2)
    x *= base;
  return x % mod;
}

ll inverse(ll x) { return fastpow(x, mod - 2) % mod; }

ld disty(pair<double, double> a, pair<double, double> b) {
  return sqrt(pow(b.second - a.second, 2.0) + pow(b.first - a.first, 2.0));
}

/*ll fact[(int)1e6 + 5], inv[(int)1e6 + 5];
void init()
{
    fact[0] = inv[0] = 1;
    for (int i = 1; i <= 1e6; i++)
    {
        fact[i] = (i * fact[i - 1]) % mod;
        inv[i] = inverse(fact[i]);
    }
}*/

void factorize(ll x, set<ll> &ss) {
  while (x % 2 == 0)
    ss.insert(2), x /= 2;
  for (int i = 3; i <= sqrt(x); i += 2)
    while (x % i == 0)
      ss.insert(i), x /= i;
  if (x > 2)
    ss.insert(x);
}

/*ll ncr(ll n, ll r)
{
    return ((fact[n] * inv[r]) % mod * inv[n - r]) % mod;
}*/

void SieveOfEratosthenes(ll n, bool prime[]) {

  for (int p = 2; p * p <= n; p++) {

    if (prime[p] == true) {
      for (int i = p * p; i <= n; i += p)
        prime[i] = false;
    }
  }
}
void divisors(ll n, vector<ll> &vec) {
  for (ll i = 2; i <= sqrt(n); ++i) {
    if (n % i == 0 && i != sqrt(n)) {
      vec.push_back(i);
      vec.push_back(n / i);
    } else if (n % i == 0) {
      vec.push_back(i);
    }
  }
}

bool isprime(ll n) {
  if (n == 1) {
    return false;
  }
  for (int i = 2; i <= sqrt(n); ++i) {
    if (n % i == 0) {
      return false;
    }
  }
  return true;
}

point rot(point p, ld angle) { return (p * polar((ld)1.0, angle)); }

point rotA(point p, point A, ld angle) {
  return (((p - A) * polar((ld)1, angle)) + A);
}

ld distance(point a, point b) {
  ld x1 = a.X, y1 = a.Y, x2 = b.X, y2 = b.Y;
  return pow(y2 - y1, 2) + pow(x2 - x1, 2);
}

int distSq(pair<ll, ll> p, pair<ll, ll> q) {
  return (p.first - q.first) * (p.first - q.first) +
         (p.second - q.second) * (p.second - q.second);
}

bool isSquare(pair<ll, ll> p1, pair<ll, ll> p2, pair<ll, ll> p3,
              pair<ll, ll> p4) {
  ll d2 = distSq(p1, p2);
  ll d3 = distSq(p1, p3);
  ll d4 = distSq(p1, p4);
  if (d2 == d3 && 2 * d2 == d4 && 2 * d2 == distSq(p2, p3)) {
    int d = distSq(p2, p4);
    return (d == distSq(p3, p4) && d == d2);
  }

  // The below two cases are similar to above case
  if (d3 == d4 && 2 * d3 == d2 && 2 * d3 == distSq(p3, p4)) {
    int d = distSq(p2, p3);
    return (d == distSq(p2, p4) && d == d3);
  }
  if (d2 == d4 && 2 * d2 == d3 && 2 * d2 == distSq(p2, p4)) {
    int d = distSq(p2, p3);
    return (d == distSq(p3, p4) && d == d2);
  }

  return false;
}

ll FP(ll base, ll power, ll m) {

  if (power == 0) {
    return 1;
  } else if (power % 2 == 0) {
    ll res = FP(base, power / 2, m);
    return (res % m * res % m) % m;
  } else {
    ll res = FP(base, power / 2, m);
    return ((((base % m * (res % m)) % m) * (res % m) % m) % m);
  }
}
ll EGCD(ll a, ll b, ll &x, ll &y) {

  if (b == 0) {
    x = 0;
    y = 1;
    return a;
  } else {
    ll ans = EGCD(b, a % b, x, y);
    ll tmp = x;
    x = y - (a / b) * x;
    y = tmp;
    return ans;
  }
}
// ll f[(int)1e7+7],in[(int)1e7+7];
/*void prec(ull n){
f[0]=1;
in[0]=1;
for(int i=1;i<=n;++i){
    f[i]=(f[i-1]*i)%mod;
    in[i]=FP(f[i],mod-2,mod);
}
}
ll npr(ll n,ll r){
    return (f[n]*in[n-r])%mod;
}
ll NCR(ll n,ll r){
return (((f[n]*in[n-r])%mod)*in[r])%mod;
}*/
ll factorial(ll n) {
  if (n == 0) {
    return 1;
  } else
    return n * factorial(n - 1);
}

int main() {
  // fastio
  ll freq[100005]={};
  ll in[100005]={};
  ll n;
  cin>>n;
  ll arr[n];
  ll maxi=-1;
  for(int i=0;i<n;++i){
    cin>>arr[i];
    in[arr[i]]+=1;
  }
  for(int i=0;i<n;++i){
        vector<ll>vec;
        divisors(arr[i],vec);
        for(int j=0;j<vec.size();++j){
            for(int k=1;k*vec[j]<arr[i];++k){
                ll num=vec[j]*k;
                if(in[num])freq[arr[i]]=max(freq[arr[i]],1+freq[num]);
            }
        }if(freq[arr[i]]==0){freq[arr[i]]=1;}
        maxi=max(maxi,freq[arr[i]]);
  }
  cout<<maxi<<"\n";
  return 0;
}


#include <bits/stdc++.h>

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
// typedef complex<double> point;
ll mod = 1e9 + 7;
#define EPS 1e-1
#define PI 3.141592653589
#define point complex<ld>
#define dot(a, b) (conj(a) * b).real()
#define cross(a, b) (conj(a) * b).imag()
#define line tuple<ll, ll, ll>
#define X real()
#define Y imag()

// int dx[] = { 0, 0, 1, -1 };
// int dy[] = { 1, -1, 0, 0 };

#define iofile                                                                 \
  freopen("input.txt", "r", stdin);                                            \
  freopen("output.txt", "w", stdout);
#define fastio ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
using namespace std;

void primeFactors(ll n, vector<ll> &vec) {

  while (n % 2 == 0) {
    vec.push_back(2);
    n = n / 2;
  }
  for (ll i = 3; i <= sqrt(n); i = i + 2) {
    while (n % i == 0) {
      vec.push_back(i);
      n = n / i;
    }
  }

  if (n > 2) {
    vec.push_back(n);
  }
}

ll gcd(ll a, ll b) {
  if (b == 0) {
    return a;
  } else {
    return gcd(b, a % b);
  }
}

ll Lcm(ll a, ll b) { return ((a * b) / gcd(a, b)); }

line getL(point p1, point p2) {
  ll a, b, c;
  a = p2.Y - p1.Y;
  b = p1.X - p2.X;
  c = -a * p1.X - b * p1.Y;
  ll gcdres = abs(gcd(a, gcd(b, c)));
  if (a < 0 || a == 0 && b < 0) {
    gcdres *= -1;
  }
  a /= gcdres;
  b /= gcdres;
  c /= gcdres;
  return line(a, b, c);
}

ll fastpow(ll base, ll pow) {
  if (!base)
    return 0;
  if (!pow)
    return 1;
  if (pow == 1)
    return base;
  ll x = fastpow(base, pow / 2) % mod;
  x *= x;
  x %= mod;
  if (pow % 2)
    x *= base;
  return x % mod;
}

ll inverse(ll x) { return fastpow(x, mod - 2) % mod; }

ld disty(pair<double, double> a, pair<double, double> b) {
  return sqrt(pow(b.second - a.second, 2.0) + pow(b.first - a.first, 2.0));
}

/*ll fact[(int)1e6 + 5], inv[(int)1e6 + 5];
void init()
{
    fact[0] = inv[0] = 1;
    for (int i = 1; i <= 1e6; i++)
    {
        fact[i] = (i * fact[i - 1]) % mod;
        inv[i] = inverse(fact[i]);
    }
}*/

void factorize(ll x, set<ll> &ss) {
  while (x % 2 == 0)
    ss.insert(2), x /= 2;
  for (int i = 3; i <= sqrt(x); i += 2)
    while (x % i == 0)
      ss.insert(i), x /= i;
  if (x > 2)
    ss.insert(x);
}

/*ll ncr(ll n, ll r)
{
    return ((fact[n] * inv[r]) % mod * inv[n - r]) % mod;
}*/

void SieveOfEratosthenes(ll n, bool prime[]) {

  for (int p = 2; p * p <= n; p++) {

    if (prime[p] == true) {
      for (int i = p * p; i <= n; i += p)
        prime[i] = false;
    }
  }
}
void divisors(ll n, vector<ll> &vec) {
  for (ll i = 2; i <= sqrt(n); ++i) {
    if (n % i == 0 && i != sqrt(n)) {
      vec.push_back(i);
      vec.push_back(n / i);
    } else if (n % i == 0) {
      vec.push_back(i);
    }
  }
}

bool isprime(ll n) {
  if (n == 1) {
    return false;
  }
  for (int i = 2; i <= sqrt(n); ++i) {
    if (n % i == 0) {
      return false;
    }
  }
  return true;
}

point rot(point p, ld angle) { return (p * polar((ld)1.0, angle)); }

point rotA(point p, point A, ld angle) {
  return (((p - A) * polar((ld)1, angle)) + A);
}

ld distance(point a, point b) {
  ld x1 = a.X, y1 = a.Y, x2 = b.X, y2 = b.Y;
  return pow(y2 - y1, 2) + pow(x2 - x1, 2);
}

int distSq(pair<ll, ll> p, pair<ll, ll> q) {
  return (p.first - q.first) * (p.first - q.first) +
         (p.second - q.second) * (p.second - q.second);
}

bool isSquare(pair<ll, ll> p1, pair<ll, ll> p2, pair<ll, ll> p3,
              pair<ll, ll> p4) {
  ll d2 = distSq(p1, p2);
  ll d3 = distSq(p1, p3);
  ll d4 = distSq(p1, p4);
  if (d2 == d3 && 2 * d2 == d4 && 2 * d2 == distSq(p2, p3)) {
    int d = distSq(p2, p4);
    return (d == distSq(p3, p4) && d == d2);
  }

  // The below two cases are similar to above case
  if (d3 == d4 && 2 * d3 == d2 && 2 * d3 == distSq(p3, p4)) {
    int d = distSq(p2, p3);
    return (d == distSq(p2, p4) && d == d3);
  }
  if (d2 == d4 && 2 * d2 == d3 && 2 * d2 == distSq(p2, p4)) {
    int d = distSq(p2, p3);
    return (d == distSq(p3, p4) && d == d2);
  }

  return false;
}

ll FP(ll base, ll power, ll m) {

  if (power == 0) {
    return 1;
  } else if (power % 2 == 0) {
    ll res = FP(base, power / 2, m);
    return (res % m * res % m) % m;
  } else {
    ll res = FP(base, power / 2, m);
    return ((((base % m * (res % m)) % m) * (res % m) % m) % m);
  }
}
ll EGCD(ll a, ll b, ll &x, ll &y) {

  if (b == 0) {
    x = 0;
    y = 1;
    return a;
  } else {
    ll ans = EGCD(b, a % b, x, y);
    ll tmp = x;
    x = y - (a / b) * x;
    y = tmp;
    return ans;
  }
}
// ll f[(int)1e7+7],in[(int)1e7+7];
/*void prec(ull n){
f[0]=1;
in[0]=1;
for(int i=1;i<=n;++i){
    f[i]=(f[i-1]*i)%mod;
    in[i]=FP(f[i],mod-2,mod);
}
}
ll npr(ll n,ll r){
    return (f[n]*in[n-r])%mod;
}
ll NCR(ll n,ll r){
return (((f[n]*in[n-r])%mod)*in[r])%mod;
}*/
ll factorial(ll n) {
  if (n == 0) {
    return 1;
  } else
    return n * factorial(n - 1);
}

int main() {
  // fastio
  ll freq[100005]={};
  ll n;
  cin>>n;
  ll arr[n];
  ll maxi=-1;
  set<ll>in;
  for(int i=0;i<n;++i){
    cin>>arr[i];
    in.insert(arr[i]);
    //freq[num]+=1;
  }
  for(int i=0;i<n;++i){
    ll curr=arr[i];
    if(arr[i]==1){freq[1]=1;continue;}
    while(curr<=100005){
         if(curr-arr[i]>=0 && in.count(curr)!=0){freq[curr]=max(freq[curr],1+freq[curr-arr[i]]);}
         else if(curr-arr[i]>=0 && in.count(curr)==0){freq[curr]=max(freq[curr],freq[curr-arr[i]]);}
         else{freq[curr]=1;}
         curr+=arr[i];
    }
    maxi=max(maxi,freq[arr[i]]);
  }
  cout<<maxi<<"\n";
  return 0;
}


#include <bits/stdc++.h>

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
// typedef complex<double> point;
ll mod = 1e9 + 7;
#define EPS 1e-1
#define PI 3.141592653589
#define point complex<ld>
#define dot(a, b) (conj(a) * b).real()
#define cross(a, b) (conj(a) * b).imag()
#define line tuple<ll, ll, ll>
#define X real()
#define Y imag()
#define MAXN 100001
int spf[MAXN];

// int dx[] = { 0, 0, 1, -1 };
// int dy[] = { 1, -1, 0, 0 };

#define iofile                                                                 \
  freopen("input.txt", "r", stdin);                                            \
  freopen("output.txt", "w", stdout);
#define fastio ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
using namespace std;

void primeFactors(ll n, vector<ll> &vec) {

  while (n % 2 == 0) {
    vec.push_back(2);
    n = n / 2;
  }
  for (ll i = 3; i <= sqrt(n); i = i + 2) {
    while (n % i == 0) {
      vec.push_back(i);
      n = n / i;
    }
  }

  if (n > 2) {
    vec.push_back(n);
  }
}

ll gcd(ll a, ll b) {
  if (b == 0) {
    return a;
  } else {
    return gcd(b, a % b);
  }
}

ll Lcm(ll a, ll b) { return ((a * b) / gcd(a, b)); }

line getL(point p1, point p2) {
  ll a, b, c;
  a = p2.Y - p1.Y;
  b = p1.X - p2.X;
  c = -a * p1.X - b * p1.Y;
  ll gcdres = abs(gcd(a, gcd(b, c)));
  if (a < 0 || a == 0 && b < 0) {
    gcdres *= -1;
  }
  a /= gcdres;
  b /= gcdres;
  c /= gcdres;
  return line(a, b, c);
}

ll fastpow(ll base, ll pow) {
  if (!base)
    return 0;
  if (!pow)
    return 1;
  if (pow == 1)
    return base;
  ll x = fastpow(base, pow / 2) % mod;
  x *= x;
  x %= mod;
  if (pow % 2)
    x *= base;
  return x % mod;
}

ll inverse(ll x) { return fastpow(x, mod - 2) % mod; }

ld disty(pair<double, double> a, pair<double, double> b) {
  return sqrt(pow(b.second - a.second, 2.0) + pow(b.first - a.first, 2.0));
}

/*ll fact[(int)1e6 + 5], inv[(int)1e6 + 5];
void init()
{
    fact[0] = inv[0] = 1;
    for (int i = 1; i <= 1e6; i++)
    {
        fact[i] = (i * fact[i - 1]) % mod;
        inv[i] = inverse(fact[i]);
    }
}*/

void factorize(ll x, set<ll> &ss) {
  while (x % 2 == 0)
    ss.insert(2), x /= 2;
  for (int i = 3; i <= sqrt(x); i += 2)
    while (x % i == 0)
      ss.insert(i), x /= i;
  if (x > 2)
    ss.insert(x);
}

/*ll ncr(ll n, ll r)
{
    return ((fact[n] * inv[r]) % mod * inv[n - r]) % mod;
}*/

void SieveOfEratosthenes(ll n, bool prime[]) {

  for (int p = 2; p * p <= n; p++) {

    if (prime[p] == true) {
      for (int i = p * p; i <= n; i += p)
        prime[i] = false;
    }
  }
}
void divisors(ll n, vector<ll> &vec) {
  for (ll i = 2; i <= sqrt(n); ++i) {
    if (n % i == 0 && i != sqrt(n)) {
      vec.push_back(i);
      vec.push_back(n / i);
    } else if (n % i == 0) {
      vec.push_back(i);
    }
  }
}

bool isprime(ll n) {
  if (n == 1) {
    return false;
  }
  for (int i = 2; i <= sqrt(n); ++i) {
    if (n % i == 0) {
      return false;
    }
  }
  return true;
}

point rot(point p, ld angle) { return (p * polar((ld)1.0, angle)); }

point rotA(point p, point A, ld angle) {
  return (((p - A) * polar((ld)1, angle)) + A);
}

ld distance(point a, point b) {
  ld x1 = a.X, y1 = a.Y, x2 = b.X, y2 = b.Y;
  return pow(y2 - y1, 2) + pow(x2 - x1, 2);
}

int distSq(pair<ll, ll> p, pair<ll, ll> q) {
  return (p.first - q.first) * (p.first - q.first) +
         (p.second - q.second) * (p.second - q.second);
}

bool isSquare(pair<ll, ll> p1, pair<ll, ll> p2, pair<ll, ll> p3,
              pair<ll, ll> p4) {
  ll d2 = distSq(p1, p2);
  ll d3 = distSq(p1, p3);
  ll d4 = distSq(p1, p4);
  if (d2 == d3 && 2 * d2 == d4 && 2 * d2 == distSq(p2, p3)) {
    int d = distSq(p2, p4);
    return (d == distSq(p3, p4) && d == d2);
  }

  // The below two cases are similar to above case
  if (d3 == d4 && 2 * d3 == d2 && 2 * d3 == distSq(p3, p4)) {
    int d = distSq(p2, p3);
    return (d == distSq(p2, p4) && d == d3);
  }
  if (d2 == d4 && 2 * d2 == d3 && 2 * d2 == distSq(p2, p4)) {
    int d = distSq(p2, p3);
    return (d == distSq(p3, p4) && d == d2);
  }

  return false;
}

ll FP(ll base, ll power, ll m) {

  if (power == 0) {
    return 1;
  } else if (power % 2 == 0) {
    ll res = FP(base, power / 2, m);
    return (res % m * res % m) % m;
  } else {
    ll res = FP(base, power / 2, m);
    return ((((base % m * (res % m)) % m) * (res % m) % m) % m);
  }
}
ll EGCD(ll a, ll b, ll &x, ll &y) {

  if (b == 0) {
    x = 0;
    y = 1;
    return a;
  } else {
    ll ans = EGCD(b, a % b, x, y);
    ll tmp = x;
    x = y - (a / b) * x;
    y = tmp;
    return ans;
  }
}
// ll f[(int)1e7+7],in[(int)1e7+7];
/*void prec(ull n){
f[0]=1;
in[0]=1;
for(int i=1;i<=n;++i){
    f[i]=(f[i-1]*i)%mod;
    in[i]=FP(f[i],mod-2,mod);
}
}
ll npr(ll n,ll r){
    return (f[n]*in[n-r])%mod;
}
ll NCR(ll n,ll r){
return (((f[n]*in[n-r])%mod)*in[r])%mod;
}*/
void sieve()
{
    spf[1] = 1;
    for (int i=2; i<MAXN; i++)

        spf[i] = i;

    for (int i=4; i<MAXN; i+=2)
        spf[i] = 2;

    for (int i=3; i*i<MAXN; i++)
    {

        if (spf[i] == i)
        {

            for (int j=i*i; j<MAXN; j+=i)

                if (spf[j]==j)
                    spf[j] = i;
        }
    }
}

set<int> getFactorization(int x)
{
    set<int> ret;
    while (x != 1)
    {
        ret.insert(spf[x]);
        x = x / spf[x];
    }
    return ret;
}

int main() {
  // fastio
  int freq[100001]={};
  sieve();
  ll n;
  cin>>n;
  ll arr[n];
  for(int i=0;i<n;++i){
    cin>>arr[i];
  }
  map<int,vector<int> >mp;
  set<int>::iterator it;
  set<int>numbers;
  int maxi=-1;
  for(int i=0;i<n;++i){
    numbers=getFactorization(arr[i]);
    int m=-1;
    if(arr[i]==1){freq[1]=1;continue;}
    for(it=numbers.begin();it!=numbers.end();++it){
        if(mp.count(*it)==0){m=max(m,0);}
        else{
            m=max(m,freq[mp[*it].back()]);
        }
        mp[*it].push_back(arr[i]);
    }
    freq[arr[i]]=(m+1);
    maxi=max(freq[arr[i]],maxi);
    numbers.clear();
  }
  cout<<maxi<<"\n";
  return 0;
}


#include<bits/stdc++.h>
#define ll long long int
using namespace std;
vector <int> p;
bool *pr=new bool[100001];
void solve()
{   fill(pr+2,pr+100001,1);
    for(int i=2; i<100001; i++)
    {
        if(pr[i])
        {
            p.push_back(i);
            for(int j=i; j<100001; j+=i)
            pr[i]=0;
        }
    }
}
int main()
{
    solve();
    int n;
    cin>>n;
    int a[n];
    for(int i=0; i<n; i++)
    cin>>a[i];
    int dp[n];
    fill(dp,dp+n,0);
    int x=p.size();
    int f[100001];
    fill(f,f+100001,0);
    for(int i=0; i<n; i++)
    {
        int l=a[i],m=0;
        vector<int>factors;
        if(pr[l]==1)
            f[l]++;
        else
        {
            if(l%2==0)
            {  f[2]++;
                while(l%2==0)
                    l/=2;
              m=f[2];
              factors.push_back(2);
            }
            for(int j=1; p[j]*p[j]<=l && j<x; j++)
            {
                if(l%p[j]==0)
                {  f[p[j]]++;
                    while(l%p[j]==0)
                        l/=p[j];
                 m=max(m,f[p[j]]);
                 factors.push_back(p[j]);
                }
              if(pr[l]==1)
               {
                   f[l]++;
               m=max(m,f[l]);
               factors.push_back(l);
               }
            }
        }
        for(int j=0; j<factors.size(); j++)
            f[factors[j]]=m;
     dp[i]=m;
    }
    dp[0]=1;
    int ans=0;
    for(int i=0; i<n; i++)
        ans=max(ans,dp[i]);
    cout<<ans;
   return 0;
}


#include<bits/stdc++.h>
#define ll long long int
using namespace std;
vector <int> p;
bool *pr=new bool[100001];
void solve()
{   fill(pr+2,pr+100001,1);
    for(int i=2; i<100001; i++)
    {
        if(pr[i])
        {
            p.push_back(i);
            for(int j=2*i; j<100001; j+=i)
            pr[j]=0;
        }
    }
}
int main()
{
    solve();
    int n;
    cin>>n;
    int a[n];
    for(int i=0; i<n; i++)
    cin>>a[i];
    int dp[n];
    fill(dp,dp+n,0);
    int x=p.size();
    int f[100001];
    fill(f,f+100001,0);
    for(int i=0; i<n; i++)
    {
        int l=a[i],m=0;
        vector<int>factors;
        if(pr[l]==1)
            f[l]++;
        else
        {
            if(l%2==0)
            {  f[2]++;
                while(l%2==0)
                    l/=2;
              m=f[2];
              factors.push_back(2);
            }
            for(int j=1; p[j]*p[j]<=l && j<x; j++)
            {
                if(l%p[j]==0)
                {  f[p[j]]++;
                    while(l%p[j]==0)
                        l/=p[j];
                 m=max(m,f[p[j]]);
                 factors.push_back(p[j]);
                }
            }
            if(pr[l])
            {
              f[l]++;
              m=max(m,f[l]);
              factors.push_back(l);
            }
        }
        for(int j=0; j<factors.size(); j++)
            f[factors[j]]=m;
     dp[i]=m;
    }
    dp[0]=1;
    int ans=0;
    for(int i=0; i<n; i++)
        ans=max(ans,dp[i]);
    cout<<ans;
   return 0;
}


#include<bits/stdc++.h>
#define ll long long int
using namespace std;
vector <int> p;
bool *pr=new bool[100001];
void solve()
{   fill(pr+2,pr+100001,1);
    for(int i=2; i<100001; i++)
    {
        if(pr[i])
        {
            p.push_back(i);
            for(int j=2*i; j<100001; j+=i)
            pr[j]=0;
        }
    }
}
int main()
{
    solve();
    int n;
    cin>>n;
    int a[n];
    for(int i=0; i<n; i++)
    cin>>a[i];
    int dp[n];
    fill(dp,dp+n,0);
    int x=p.size();
    int f[100001];
    fill(f,f+100001,0);
    for(int i=0; i<n; i++)
    {
        int l=a[i],m=0;
        vector<int>factors;
        if(pr[l]==1)
            f[l]++;
        else
        {
            if(l%2==0)
            {  f[2]++;
                while(l%2==0)
                    l/=2;
              m=f[2];
              factors.push_back(2);
            }
            for(int j=1; p[j]*p[j]<=l && j<x; j++)
            {
                if(l%p[j]==0)
                {  f[p[j]]++;
                    while(l%p[j]==0)
                        l/=p[j];
                 m=max(m,f[p[j]]);
                 factors.push_back(p[j]);
                }
               if(pr[l])
                {
                   f[l]++;
                  m=max(m,f[l]);
                  factors.push_back(l);
                  break;
                }
            }
            if(pr[l])
            {
              f[l]++;
              m=max(m,f[l]);
              factors.push_back(l);
            }
        }
        for(int j=0; j<factors.size(); j++)
            f[factors[j]]=m;
     dp[i]=m;
    }
    dp[0]=1;
    int ans=0;
    for(int i=0; i<n; i++)
        ans=max(ans,dp[i]);
    cout<<ans;
   return 0;
}


#include<bits/stdc++.h>
#define ll long long int
using namespace std;
vector <int> p;
bool *pr=new bool[100001];
void solve()
{   fill(pr+2,pr+100001,1);
    for(int i=2; i<100001; i++)
    {
        if(pr[i])
        {
            p.push_back(i);
            for(int j=2*i; j<100001; j+=i)
            pr[j]=0;
        }
    }
}
int main()
{   ios_base::sync_with_stdio(0);
    cin.tie(0);
    solve();
    int n;
    cin>>n;
    int a[n];
    for(int i=0; i<n; i++)
    cin>>a[i];
    int dp[n];
    fill(dp,dp+n,0);
    int x=p.size();
    int f[100001];
    fill(f,f+100001,0);
    for(int i=0; i<n; i++)
    {
        int l=a[i],m=0;
        vector<int>factors;
        if(pr[l]==1)
            f[l]++;
        else
        {
            if(l%2==0)
            {  f[2]++;
                while(l%2==0)
                    l/=2;
              m=f[2];
              factors.push_back(2);
            }
            for(int j=1; p[j]*p[j]<=l && j<x; j++)
            {
                if(l%p[j]==0)
                {  f[p[j]]++;
                    while(l%p[j]==0)
                        l/=p[j];
                 m=max(m,f[p[j]]);
                 factors.push_back(p[j]);
                }
            }
            if(l>2)
            {
              f[l]++;
              m=max(m,f[l]);
              factors.push_back(l);
            }
        }
        for(int j=0; j<factors.size(); j++)
            f[factors[j]]=m;
     dp[i]=m;
    }
    dp[0]=1;
    int ans=0;
    for(int i=0; i<n; i++)
        ans=max(ans,dp[i]);
    cout<<ans;
   return 0;
}


#include<bits/stdc++.h>
#define ll long long int
using namespace std;
vector <int> p;
bool *pr=new bool[100001];
void solve()
{   fill(pr+2,pr+100001,1);
    for(int i=2; i<100001; i++)
    {
        if(pr[i])
        {
            p.push_back(i);
            for(int j=i; j<100001; j+=i)
            pr[i]=0;
        }
    }
}
int main()
{
    solve();
    int n;
    cin>>n;
    int a[n];
    for(int i=0; i<n; i++)
    cin>>a[i];
    int dp[n];
    fill(dp,dp+n,0);
    int x=p.size();
    int f[100001];
    fill(f,f+100001,0);
    for(int i=0; i<n; i++)
    {
        int l=a[i],m=0;
        vector<int>factors;
        if(pr[l]==1)
            f[l]++;
        else
        {
            if(l%2==0)
            {  f[2]++;
                while(l%2==0)
                    l/=2;
              m=f[2];
              factors.push_back(2);
            }
            for(int j=1; p[j]<=l && j<x; j++)
            {
                if(l%p[j]==0)
                {  f[p[j]]++;
                    while(l%p[j]==0)
                        l/=p[j];
                 m=max(m,f[p[j]]);
                 factors.push_back(p[j]);
                }
            }
        }
        for(int j=0; j<factors.size(); j++)
            f[factors[j]]=m;
     dp[i]=m;
    }
    dp[0]=1;
    int ans=0;
    for(int i=0; i<n; i++)
        ans=max(ans,dp[i]);
    cout<<ans;
   return 0;
}


#include<bits/stdc++.h>
#define ll long long int
using namespace std;
vector <int> p;
bool *pr=new bool[100001];
void solve()
{   fill(pr+2,pr+100001,1);
    for(int i=2; i<100001; i++)
    {
        if(pr[i])
        {
            p.push_back(i);
            for(int j=2*i; j<100001; j+=i)
            pr[j]=0;
        }
    }
}
int main()
{
    solve();
    int n;
    cin>>n;
    int a[n];
    for(int i=0; i<n; i++)
    cin>>a[i];
    int dp[n];
    fill(dp,dp+n,0);
    int x=p.size();
    int f[100001];
    fill(f,f+100001,0);
    for(int i=0; i<n; i++)
    {
        int l=a[i],m=0;
        vector<int>factors;
        if(pr[l]==1)
            f[l]++;
        else
        {
            if(l%2==0)
            {  f[2]++;
                while(l%2==0)
                    l/=2;
              m=f[2];
              factors.push_back(2);
            }
            for(int j=1; p[j]*p[j]<=l && j<x; j++)
            {
                if(l%p[j]==0)
                {  f[p[j]]++;
                    while(l%p[j]==0)
                        l/=p[j];
                 m=max(m,f[p[j]]);
                 factors.push_back(p[j]);
                }
            }
            if(l>2)
            {
              f[l]++;
              m=max(m,f[l]);
              factors.push_back(l);
            }
        }
        for(int j=0; j<factors.size(); j++)
            f[factors[j]]=m;
     dp[i]=m;
    }
    dp[0]=1;
    int ans=0;
    for(int i=0; i<n; i++)
        ans=max(ans,dp[i]);
    cout<<ans;
   return 0;
}


#include<bits/stdc++.h>
#define ll long long int
using namespace std;
vector <int> p;
bool *pr=new bool[100001];
void solve()
{   fill(pr+2,pr+100001,1);
    for(int i=2; i<100001; i++)
    {
        if(pr[i])
        {
            p.push_back(i);
            for(int j=2*i; j<100001; j+=i)
            pr[j]=0;
        }
    }
}
int main()
{   ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    solve();
    int n;
    cin>>n;
    int a[n];
    for(int i=0; i<n; i++)
    cin>>a[i];
    int dp[n];
    fill(dp,dp+n,0);
    int x=p.size();
    int f[100001];
    fill(f,f+100001,0);
    for(int i=0; i<n; i++)
    {
        int l=a[i],m=0;
        vector<int>factors;
        if(pr[l]==1)
            f[l]++;
        else
        {
            if(l%2==0)
            {  f[2]++;
                while(l%2==0)
                    l/=2;
              m=f[2];
              factors.push_back(2);
            }
            for(int j=1; p[j]*p[j]<=l && j<x; j++)
            {
                if(l%p[j]==0)
                {  f[p[j]]++;
                    while(l%p[j]==0)
                        l/=p[j];
                 m=max(m,f[p[j]]);
                 factors.push_back(p[j]);
                }
            }
            if(l>2)
            {
              f[l]++;
              m=max(m,f[l]);
              factors.push_back(l);
            }
        }
        for(int j=0; j<factors.size(); j++)
            f[factors[j]]=m;
     dp[i]=m;
    }
    dp[0]=1;
    int ans=0;
    for(int i=0; i<n; i++)
        ans=max(ans,dp[i]);
    cout<<ans;
   return 0;
}


#include<bits/stdc++.h>
#define ll long long int
using namespace std;
vector <int> p;
bool *pr=new bool[100001];
void solve()
{   fill(pr+2,pr+100001,1);
    for(int i=2; i<100001; i++)
    {
        if(pr[i])
        {
            p.push_back(i);
            for(int j=i; j<100001; j+=i)
            pr[i]=0;
        }
    }
}
int main()
{
    solve();
    int n;
    cin>>n;
    int a[n];
    for(int i=0; i<n; i++)
    cin>>a[i];
    int dp[n];
    fill(dp,dp+n,0);
    int x=p.size();
    int f[x];
    fill(f,f+x,0);
    for(int i=0; i<n; i++)
    {
        int l=a[i];
        vector <int> e;
          int m=0;
        if(l%2==0){
         f[0]++;
         e.push_back(0);
                 m=f[0];
        while(l%2==0)
            l/=2;}
        for(int in=1; p[in]<=l; in++)
        {
         if(l%p[in]==0 && l>0)
          {
              while(l%p[in]==0)
              l/=p[in];
              f[in]++;
              e.push_back(in);
              m=max(f[in],m);
          }
        }
       for(int j=0; j<e.size(); j++)
        f[e[j]]=m;
    dp[i]=m;
    }
    dp[0]=1;
    int ans=0;
    for(int i=0; i<n; i++)
        ans=max(ans,dp[i]);
    cout<<ans;
   return 0;
}


#include<bits/stdc++.h>
#define ll long long int
using namespace std;
vector <int> p;
bool *pr=new bool[100001];
void solve()
{   fill(pr+2,pr+100001,1);
    for(int i=2; i<100001; i++)
    {
        if(pr[i])
        {
            p.push_back(i);
            for(int j=i; j<100001; j+=i)
            pr[i]=0;
        }
    }
}
int main()
{
    solve();
    int n;
    cin>>n;
    int a[n];
    for(int i=0; i<n; i++)
    cin>>a[i];
    int dp[n];
    dp[0]=1;
    fill(dp+1,dp+n,0);
    int x=p.size();
    int f[x];
    fill(f,f+x,0);
    for(int i=0; i<n; i++)
    {
        int l=a[i],in=0;
        vector <int> e;
          int m=0;

        while(l>0 && in<=x-1)
        {
         if(l%p[in]==0)
          {
              while(l%p[in]==0)
              l/=p[in];
              f[in]++;
              e.push_back(in);
              m=max(f[in],m);
          }
          in++;
        }
       for(int j=0; j<e.size(); j++)
        f[e[j]]=m;
    dp[i]=m;
    }
    int ans=0;
    for(int i=0; i<n; i++)
        ans=max(ans,dp[i]);
    cout<<ans;
   return 0;
}


#include<bits/stdc++.h>
#define ll long long int
using namespace std;
vector <int> p;
bool *pr=new bool[100001];
void solve()
{   fill(pr+2,pr+100001,1);
    for(int i=2; i<100001; i++)
    {
        if(pr[i])
        {
            p.push_back(i);
            for(int j=i; j<100001; j+=i)
            pr[i]=0;
        }
    }
}
int main()
{
    solve();
    int n;
    cin>>n;
    int a[n];
    for(int i=0; i<n; i++)
    cin>>a[i];
    int dp[n];
    fill(dp,dp+n,0);
    int x=p.size();
    int f[x];
    fill(f,f+x,0);
    for(int i=0; i<n; i++)
    {
        int l=a[i],in=0;
        vector <int> e;
          int m=0;

        while(l>0 && in<=x-1)
        {
         if(l%p[in]==0)
          {
              while(l%p[in]==0)
              l/=p[in];
              f[in]++;
              e.push_back(in);
              m=max(f[in],m);
          }
          in++;
        }
       for(int j=0; j<e.size(); j++)
        f[e[j]]=m;
    dp[i]=m;
    }
    dp[0]=1;
    int ans=0;
    for(int i=0; i<n; i++)
        ans=max(ans,dp[i]);
    cout<<ans;
   return 0;
}


#include<bits/stdc++.h>
#define ll long long int
using namespace std;
vector <int> p;
bool *pr=new bool[100001];
void solve()
{   fill(pr+2,pr+100001,1);
    for(int i=2; i<100001; i++)
    {
        if(pr[i])
        {
            p.push_back(i);
            for(int j=i; j<100001; j+=i)
            pr[i]=0;
        }
    }
}
int main()
{
    solve();
    int n;
    cin>>n;
    int a[n];
    for(int i=0; i<n; i++)
    cin>>a[i];
    int dp[n];
    fill(dp,dp+n,0);
    int x=p.size();
    int f[100001];
    fill(f,f+100001,0);
    for(int i=0; i<n; i++)
    {
        int l=a[i],m=0;
        vector<int>factors;
        if(pr[l]==1)
            f[l]++;
        else
        {
            if(l%2==0)
            {  f[2]++;
                while(l%2==0)
                    l/=2;
              m=f[2];
              factors.push_back(2);
            }
            for(int j=1; p[j]*p[j]<=l && j<x; j++)
            {
                if(l%p[j]==0)
                {  f[p[j]]++;
                    while(l%p[j]==0)
                        l/=p[j];
                 m=max(m,f[p[j]]);
                 factors.push_back(p[j]);
                }
            }
           if(l>2)
           {
               f[l]++;
               m=max(m,f[l]);
               factors.push_back(l);
           }
        }
        for(int j=0; j<factors.size(); j++)
            f[factors[j]]=m;
     dp[i]=m;
    }
    dp[0]=1;
    int ans=0;
    for(int i=0; i<n; i++)
        ans=max(ans,dp[i]);
    cout<<ans;
   return 0;
}


 /*
What ?!?!
Ohhh....
Mmmmm....
Aaa yeee
It'll be easy for me.
By Daniyar Kuttymbek

*/
# include <bits/stdc++.h>

# define f first
# define s second
# define pb push_back
# define mp make_pair
# define int long long
# define sc(x) scanf("%I64d",&x)
# define pr(x) printf("%I64d\n",x)
# define For(x,y,z) for(int x = y;x <= z;x ++)
# define all(x) x.begin(),x.end()
# define sz(x) x.size()
# define forn(x,y,z) for(int x = y;x >= z; x--)
# define Sort(x,n) sort(x + 1,x + n + 1)
# define rev(x,n) reverse(x + 1,x + n + 1)
# define EZPZ return 0
# define pii pair <int,int>

using namespace std;

const int Inf = 1e9 + 7;
const int Imp = -1;
const int MaxN = 2e6 + 1;
int a[MaxN],dp[MaxN];
main ()
{
    int n;
    sc(n);
    For(i,1,n)
    sc(a[i]);
    For(i,1,n)
    {
        int mx = dp[a[i]];
        for(int j = 2;j * j <= a[i];j ++)
        {
            if(a[i] % j == 0)
            {
                int b = a[i] / j;
                mx = max(dp[b],dp[j]);

            }
        }
        for(int j = 2;j * j <= a[i];j ++)
        {
            if(a[i] % j == 0)
            {
                int b = a[i] / j;
                dp[b] = mx + 1;
                dp[j] = mx + 1;
            }
        }
        dp[a[i]] = mx + 1;
    }
    int ans = 1;
    For(i,2,1e5)
    ans = max(ans,dp[i]);
    pr(ans);
}


 /*
What ?!?!
Ohhh....
Mmmmm....
Aaa yeee
It'll be easy for me.
By Daniyar Kuttymbek

*/
# include <bits/stdc++.h>

# define f first
# define s second
# define pb push_back
# define mp make_pair
# define int long long
# define sc(x) scanf("%I64d",&x)
# define pr(x) printf("%I64d\n",x)
# define For(x,y,z) for(int x = y;x <= z;x ++)
# define all(x) x.begin(),x.end()
# define sz(x) x.size()
# define forn(x,y,z) for(int x = y;x >= z; x--)
# define Sort(x,n) sort(x + 1,x + n + 1)
# define rev(x,n) reverse(x + 1,x + n + 1)
# define EZPZ return 0
# define pii pair <int,int>

using namespace std;

const int Inf = 1e9 + 7;
const int Imp = -1;
const int MaxN = 2e6 + 1;
int a[MaxN],dp[MaxN];
main ()
{
    int n;
    sc(n);
    For(i,1,n)
    sc(a[i]);
    For(i,1,n)
    {
        int mx = 0;
        for(int j = 2;j * j <= a[i];j ++)
        {
            if(a[i] % j == 0)
            {
                int b = a[i] / j;
                mx = max(dp[b],dp[j]);
            }
        }
        for(int j = 2;j * j <= a[i];j ++)
        {
            if(a[i] % j == 0)
            {
                int b = a[i] / j;
                dp[b] = mx + 1;
                dp[j] = mx + 1;
            }
        }
        if(a[i] != 2)
        dp[a[i]] = mx + 1;
    }
    int ans = 0;
    For(i,2,1e5)
    ans = max(ans,dp[i]);
    pr(ans + 1);
}


 /*
What ?!?!
Ohhh....
Mmmmm....
Aaa yeee
It'll be easy for me.
By Daniyar Kuttymbek

*/
# include <bits/stdc++.h>

# define f first
# define s second
# define pb push_back
# define mp make_pair
# define int long long
# define sc(x) scanf("%I64d",&x)
# define pr(x) printf("%I64d\n",x)
# define For(x,y,z) for(int x = y;x <= z;x ++)
# define all(x) x.begin(),x.end()
# define sz(x) x.size()
# define forn(x,y,z) for(int x = y;x >= z; x--)
# define Sort(x,n) sort(x + 1,x + n + 1)
# define rev(x,n) reverse(x + 1,x + n + 1)
# define EZPZ return 0
# define pii pair <int,int>

using namespace std;

const int Inf = 1e9 + 7;
const int Imp = -1;
const int MaxN = 2e6 + 1;
int a[MaxN],dp[MaxN];
main ()
{
    int n;
    sc(n);
    For(i,1,n)
    sc(a[i]);
    For(i,1,n)
    {
        int mx = dp[a[i]];
        for(int j = 2;j * j <= a[i];j ++)
        {
            if(a[i] % j == 0)
            {
                int b = a[i] / j;
                mx = max(mx,dp[j]);
                mx = max(dp[b],mx);

            }
        }
        for(int j = 2;j * j <= a[i];j ++)
        {
            if(a[i] % j == 0)
            {
                int b = a[i] / j;
                dp[b] = mx + 1;
                dp[j] = mx + 1;
            }
        }
        dp[a[i]] = mx + 1;
    }
    int ans = 1;
    For(i,2,1e5)
    ans = max(ans,dp[i]);
    pr(ans);
}


 /*
What ?!?!
Ohhh....
Mmmmm....
Aaa yeee
It'll be easy for me.
By Daniyar Kuttymbek

*/
# include <bits/stdc++.h>

# define f first
# define s second
# define pb push_back
# define mp make_pair
# define int long long
# define sc(x) scanf("%I64d",&x)
# define pr(x) printf("%I64d\n",x)
# define For(x,y,z) for(int x = y;x <= z;x ++)
# define all(x) x.begin(),x.end()
# define sz(x) x.size()
# define forn(x,y,z) for(int x = y;x >= z; x--)
# define Sort(x,n) sort(x + 1,x + n + 1)
# define rev(x,n) reverse(x + 1,x + n + 1)
# define EZPZ return 0
# define pii pair <int,int>

using namespace std;

const int Inf = 1e9 + 7;
const int Imp = -1;
const int MaxN = 2e6 + 1;
int a[MaxN],dp[MaxN];
main ()
{
    int n;
    sc(n);
    For(i,1,n)
    sc(a[i]);
    For(i,1,n)
    {
        int mx = 0;
        for(int j = 2;j * j <= a[i];j ++)
        {
            if(a[i] % j == 0)
            {
                int b = a[i] / j;
                mx = max(dp[b],dp[j]);
            }
        }
        for(int j = 2;j * j <= a[i];j ++)
        {
            if(a[i] % j == 0)
            {
                int b = a[i] / j;
                dp[b] = mx + 1;
                dp[j] = mx + 1;
            }
        }
    }
    int ans = 0;
    For(i,1,1e5)
    ans = max(ans,dp[i]);
    pr(ans + 1);
}


 /*
What ?!?!
Ohhh....
Mmmmm....
Aaa yeee
It'll be easy for me.
By Daniyar Kuttymbek

*/
# include <bits/stdc++.h>

# define f first
# define s second
# define pb push_back
# define mp make_pair
# define int long long
# define sc(x) scanf("%I64d",&x)
# define pr(x) printf("%I64d\n",x)
# define For(x,y,z) for(int x = y;x <= z;x ++)
# define all(x) x.begin(),x.end()
# define sz(x) x.size()
# define forn(x,y,z) for(int x = y;x >= z; x--)
# define Sort(x,n) sort(x + 1,x + n + 1)
# define rev(x,n) reverse(x + 1,x + n + 1)
# define EZPZ return 0
# define pii pair <int,int>

using namespace std;

const int Inf = 1e9 + 7;
const int Imp = -1;
const int MaxN = 2e6 + 1;
int a[MaxN],dp[MaxN];
main ()
{
    int n;
    sc(n);
    For(i,1,n)
    sc(a[i]);
    For(i,1,n)
    {
        int mx = 0;
        for(int j = 2;j * j <= a[i];j ++)
        {
            if(a[i] % j == 0)
            {
                int b = a[i] / j;
                mx = max(dp[b],dp[j]);
            }
        }
        for(int j = 2;j * j <= a[i];j ++)
        {
            if(a[i] % j == 0)
            {
                int b = a[i] / j;
                dp[b] = mx + 1;
                dp[j] = mx + 1;
            }
        }
        dp[a[i]] = mx + 1;
    }
    int ans = 0;
    For(i,2,1e5)
    ans = max(ans,dp[i]);
    pr(ans + 1);
}


 /*
What ?!?!
Ohhh....
Mmmmm....
Aaa yeee
It'll be easy for me.
By Daniyar Kuttymbek

*/
# include <bits/stdc++.h>

# define f first
# define s second
# define pb push_back
# define mp make_pair
# define int long long
# define sc(x) scanf("%I64d",&x)
# define pr(x) printf("%I64d\n",x)
# define For(x,y,z) for(int x = y;x <= z;x ++)
# define all(x) x.begin(),x.end()
# define sz(x) x.size()
# define forn(x,y,z) for(int x = y;x >= z; x--)
# define Sort(x,n) sort(x + 1,x + n + 1)
# define rev(x,n) reverse(x + 1,x + n + 1)
# define EZPZ return 0
# define pii pair <int,int>

using namespace std;

const int Inf = 1e9 + 7;
const int Imp = -1;
const int MaxN = 2e6 + 1;
int a[MaxN],dp[MaxN];
main ()
{
    int n;
    sc(n);
    For(i,1,n)
    sc(a[i]);
    For(i,1,n)
    {
        int mx = dp[a[i]];
        for(int j = 2;j * j <= a[i];j ++)
        {
            if(a[i] % j == 0)
            {
                int b = a[i] / j;
                mx = max(dp[b],dp[j]);

            }
        }
        for(int j = 2;j * j <= a[i];j ++)
        {
            if(a[i] % j == 0)
            {
                int b = a[i] / j;
                dp[b] = mx + 1;
                dp[j] = mx + 1;
            }
        }
        dp[a[i]] = mx + 1;
    }
    int ans = 0;
    For(i,2,1e5)
    ans = max(ans,dp[i]);
    pr(ans);
}


 /*
What ?!?!
Ohhh....
Mmmmm....
Aaa yeee
It'll be easy for me.
By Daniyar Kuttymbek

*/
# include <bits/stdc++.h>

# define f first
# define s second
# define pb push_back
# define mp make_pair
# define int long long
# define sc(x) scanf("%I64d",&x)
# define pr(x) printf("%I64d\n",x)
# define For(x,y,z) for(int x = y;x <= z;x ++)
# define all(x) x.begin(),x.end()
# define sz(x) x.size()
# define forn(x,y,z) for(int x = y;x >= z; x--)
# define Sort(x,n) sort(x + 1,x + n + 1)
# define rev(x,n) reverse(x + 1,x + n + 1)
# define EZPZ return 0
# define pii pair <int,int>

using namespace std;

const int Inf = 1e9 + 7;
const int Imp = -1;
const int MaxN = 2e6 + 1;
int a[MaxN],dp[MaxN];
main ()
{
    int n;
    sc(n);
    For(i,1,n)
    sc(a[i]);
    For(i,1,n)
    {
        int mx = 0;
        for(int j = 2;j * j <= a[i];j ++)
        {
            if(a[i] % j == 0)
            {
                int b = a[i] / j;
                mx = max(dp[b],dp[j]);

            }
        }
        for(int j = 2;j * j <= a[i];j ++)
        {
            if(a[i] % j == 0)
            {
                int b = a[i] / j;
                dp[b] = mx + 1;
                dp[j] = mx + 1;
            }
        }
        if(a[i] != 2)
        dp[a[i]] = mx + 1;
    }
    int ans = 0;
    For(i,2,1e5)
    ans = max(ans,dp[i]);
    pr(ans);
}


 /*
What ?!?!
Ohhh....
Mmmmm....
Aaa yeee
It'll be easy for me.
By Daniyar Kuttymbek

*/
# include <bits/stdc++.h>

# define f first
# define s second
# define pb push_back
# define mp make_pair
# define int long long
# define sc(x) scanf("%I64d",&x)
# define pr(x) printf("%I64d\n",x)
# define For(x,y,z) for(int x = y;x <= z;x ++)
# define all(x) x.begin(),x.end()
# define sz(x) x.size()
# define forn(x,y,z) for(int x = y;x >= z; x--)
# define Sort(x,n) sort(x + 1,x + n + 1)
# define rev(x,n) reverse(x + 1,x + n + 1)
# define EZPZ return 0
# define pii pair <int,int>

using namespace std;

const int Inf = 1e9 + 7;
const int Imp = -1;
const int MaxN = 2e6 + 1;
int a[MaxN],dp[MaxN];
main ()
{
    int n;
    sc(n);
    For(i,1,n)
    sc(a[i]);
    For(i,1,n)
    {
        int mx = dp[a[i]];
        for(int j = 2;j * j <= a[i];j ++)
        {
            if(a[i] % j == 0)
            {
                int b = a[i] / j;
                mx = max(mx,dp[j]);
                mx = max(dp[b],dp[j]);

            }
        }
        for(int j = 2;j * j <= a[i];j ++)
        {
            if(a[i] % j == 0)
            {
                int b = a[i] / j;
                dp[b] = mx + 1;
                dp[j] = mx + 1;
            }
        }
        dp[a[i]] = mx + 1;
    }
    int ans = 1;
    For(i,2,1e5)
    ans = max(ans,dp[i]);
    pr(ans);
}


#include <bits/stdc++.h>

using namespace std;
int n,x;
vector<int>v;

int gcd(int a, int b) {
    return b == 0 ? a : gcd(b, a % b);
}

 int f(int i,int prec)
 {  if (i==n) return 0;

     if (gcd(v[i],v[prec])==1) {return f(i+1,prec);}
     else {  return max(1+f(i+1,i),f(i+1,prec));}
 }

int main()
{ cin>>n;
  if (n==1) {cout<<1; return 0;}
  for (int i=0;i<n;i++)
  {cin>>x; v.push_back(x);}
  if (v[0]==1) { v.erase(v.begin()); n--;}
   if (n==1) {cout<<1; return 0;}

   cout<<f(0,0);
}


#include <bits/stdc++.h>

using namespace std;
int n,x;
int dp[1005][1005];
vector<int>v;

int gcd(int a, int b) {
    return b == 0 ? a : gcd(b, a % b);
}

 int f(int i,int prec)
 {  if (i==n) return 0 ;
    if (dp[i][prec]!=-1) return dp[i][prec];

     if (gcd(v[i],v[prec])==1) {return dp[i][prec]=f(i+1,prec);}
     else {  return dp[i][prec]=max(1+f(i+1,i),f(i+1,prec));}
 }

int main()
{ cin>>n;
  memset(dp,-1,sizeof dp);
  if (n==1) {cout<<1; return 0;}
  for (int i=0;i<n;i++)
  {cin>>x; v.push_back(x);}
  if (v[0]==1) { v.erase(v.begin()); n--;}
   if (n==1) {cout<<1; return 0;}

   cout<<f(0,0);
}


#include <bits/stdc++.h>
using namespace std;
int dp[100000];
typedef long long ll;
vector<ll>sol;
vector<ll>v;
ll x;
ll Lis();
ll akber=1;
ll k,n;
int main()
{  memset(dp,0,sizeof dp);
   //memset(par,-1,sizeof par);

	cin>>n;

	for (int i=0;i<n;i++)
	{cin>>x;
   v.push_back(x);}

   ll a=Lis();

    printf("%d",a);

}

ll  Lis()
{dp[0]=1;
  for (int i=1;i<v.size();i++)
    {dp[i]++; // hethi 3ibara 3malna memset lel dp mel 1
    	for (int j=i-1;j>=0;j--)
      {if (__gcd(v[j],v[i])!=1) { if (dp[j]+1>dp[i]) {dp[i]=dp[j]+1;

                                             }

      	               if (akber<=dp[i]) {akber=dp[i];
      	                                 //k=i;
      	                                 }

      	                                          }}}

      return (akber);
      }


#include <bits/stdc++.h>

using namespace std;
int n,x;
map <pair<int,int>,int >dp;
vector<int>v;

int gcd(int a, int b) {
    return b == 0 ? a : gcd(b, a % b);
}

 int f(int i,int prec)
 {  if (i==n) return 0 ;
    if (dp.count({i,prec})) return dp[{i,prec}];

     if (gcd(v[i],v[prec])==1) {return dp[{i,prec}]=f(i+1,prec);}
     else {  return dp[{i,prec}]=max(1+f(i+1,i),f(i+1,prec));}
 }

int main()
{ cin>>n;
  if (n==1) {cout<<1; return 0;}
  for (int i=0;i<n;i++)
  {cin>>x; v.push_back(x);}
  if (v[0]==1) { v.erase(v.begin()); n--;}
   if (n==1) {cout<<1; return 0;}

   cout<<f(0,0);
}


#include <bits/stdc++.h>
using namespace std;
int dp[100000];
typedef long long ll;
vector<ll>sol;
vector<ll>v;
ll x;
ll Lis();
ll akber=1;
ll k,n;
int main()
{  memset(dp,0,sizeof dp);
   //memset(par,-1,sizeof par);

	cin>>n;

	for (int i=0;i<n;i++)
	{cin>>x;
   v.push_back(x);}

   ll a=Lis();

    printf("%d",a);

}

ll  Lis()
{dp[0]=1;
  for (int i=1;i<v.size();i++)
    {dp[i]++; // hethi 3ibara 3malna memset lel dp mel 1
    	for (int j=i-1;j>=0 && i-j<100 ;j--)
      {if (__gcd(v[j],v[i])!=1) { if (dp[j]+1>dp[i]) {dp[i]=dp[j]+1;

                                             }

      	               if (akber<=dp[i]) {akber=dp[i];
      	                                 //k=i;
      	                                 }

      	                                          }}}

      return (akber);
      }


#include <bits/stdc++.h>

using namespace std;
int n,x;
int dp[1005][1005];
vector<int>v;

int gcd(int a, int b) {
    return b == 0 ? a : gcd(b, a % b);
}

 int f(int i,int prec)
 {  if (i==n) return 0 ;
    if (dp[i][prec]!=-1) return dp[i][prec];

     if (__gcd(v[i],v[prec])==1) {return dp[i][prec]=f(i+1,prec);}
     else {  return dp[i][prec]=max(1+f(i+1,i),f(i+1,prec));}
 }

int main()
{ cin>>n;
  memset(dp,-1,sizeof dp);
  if (n==1) {cout<<1; return 0;}
  for (int i=0;i<n;i++)
  {cin>>x; v.push_back(x);}
  if (v[0]==1) { v.erase(v.begin()); n--;}
   if (n==1) {cout<<1; return 0;}

   cout<<f(0,0);
}


#include <bits/stdc++.h>
using namespace std;
int dp[100000];
typedef long long ll;
vector<ll>sol;
vector<ll>v;
ll x;
ll Lis();
ll akber=1;
ll k,n;
int main()
{  memset(dp,0,sizeof dp);
   //memset(par,-1,sizeof par);

	cin>>n;

	for (int i=0;i<n;i++)
	{cin>>x;
   v.push_back(x);}

   ll a=Lis();

    printf("%d",a);

}

ll  Lis()
{dp[0]=1;
  for (int i=1;i<v.size();i++)
    {dp[i]++; // hethi 3ibara 3malna memset lel dp mel 1
    	for (int j=i-1;j>=0 && i-j>100 ;j--)
      {if (__gcd(v[j],v[i])!=1) { if (dp[j]+1>dp[i]) {dp[i]=dp[j]+1;

                                             }

      	               if (akber<=dp[i]) {akber=dp[i];
      	                                 //k=i;
      	                                 }

      	                                          }}}

      return (akber);
      }


#include <bits/stdc++.h>
using namespace std;
int dp[100000];
typedef long long ll;
vector<ll>sol;
vector<ll>v;
ll x;
ll Lis();
ll akber=1;
ll k,n;
int main()
{  memset(dp,0,sizeof dp);
   //memset(par,-1,sizeof par);

	cin>>n;

	for (int i=0;i<n;i++)
	{cin>>x;
   v.push_back(x);}

   ll a=Lis();

    printf("%d",a);

}

ll  Lis()
{dp[0]=1;
  for (int i=1;i<v.size();i++)
    {dp[i]++; // hethi 3ibara 3malna memset lel dp mel 1
    	for (int j=i-1;j>=0 && i-j<50 ;j--)
      {if (__gcd(v[j],v[i])!=1) { if (dp[j]+1>dp[i]) {dp[i]=dp[j]+1;

                                             }

      	               if (akber<=dp[i]) {akber=dp[i];
      	                                 //k=i;
      	                                 }

      	                                          }}}

      return (akber);
      }


#include <bits/stdc++.h>
using namespace std;
int dp[100000];
typedef long long ll;
vector<ll>sol;
vector<ll>v;
ll x;
ll Lis();
ll akber=1;
ll k,n;
int main()
{  memset(dp,0,sizeof dp);
   //memset(par,-1,sizeof par);

	cin>>n;

	for (int i=0;i<n;i++)
	{cin>>x;
   v.push_back(x);}

   ll a=Lis();

    printf("%d",a);

}

ll  Lis()
{dp[0]=1;
  for (int i=1;i<v.size();i++)
    {dp[i]++; // hethi 3ibara 3malna memset lel dp mel 1
    	for (int j=i-1;j>=0 && i-j<10 ;j--)
      {if (__gcd(v[j],v[i])!=1) { if (dp[j]+1>dp[i]) {dp[i]=dp[j]+1;

                                             }

      	               if (akber<=dp[i]) {akber=dp[i];
      	                                 //k=i;
      	                                 }

      	                                          }}}

      return (akber);
      }


#include <bits/stdc++.h>

using namespace std;
int n,x;
int dp[100005];
vector<int>v;

int gcd(int a, int b) {
    return b == 0 ? a : gcd(b, a % b);
}

 int f(int i,int prec)
 {  if (i==n) return 0 ;
    if (dp[i]) return dp[i];

     if (gcd(v[i],v[prec])==1) {return dp[i]=f(i+1,prec);}
     else {  return dp[i]=max(1+f(i+1,i),f(i+1,prec));}
 }

int main()
{ cin>>n;
  if (n==1) {cout<<1; return 0;}
  for (int i=0;i<n;i++)
  {cin>>x; v.push_back(x);}
  if (v[0]==1) { v.erase(v.begin()); n--;}
   if (n==1) {cout<<1; return 0;}

   cout<<f(0,0);
}


#include<iostream>
#include<cmath>
using namespace std;

class problem
{
public:
	void idea()
	{
		input();
		build();
		output();
	}

private:
	int num;
	int *arr,*len;
	int result;

	void input()
	{
		cin>>num;
		arr=new int[num];
		for(int i=0;i<num;i++) cin>>arr[i];
	}

	void build()
	{
		len=new int[num];
		for(int i=0;i<num;i++) len[i]=1;
		for(int i=num-1;i>=0;i--) max_len(i);
	}

	void max_len(int x)
	{
		for(int i=x+1;i<num;i++)
			if((len[i]+1) > len[x])
				if(gcd(arr[x],arr[i])) len[x]=(len[i]+1);
	}

	int gcd(int x,int y)
	{
		if(y%x==0) return 1;
		for(int i=2;i<=(sqrt(x)+1);i++) if(x%i==0 && y%i==0) return 1;
		return 0;
	}

	void output()
	{
		result=0;
		if(arr[0]==1) len[0]=0;
		for(int i=0;i<num;i++) if(len[i]>result) result=len[i];
		cout<<result<<endl;
	}
};

int main()
{
	problem test;
	test.idea();

	//system("pause");
	return 0;
}


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

class problem
{
public:
	void idea()
	{
		repair();
		input();
		max_length();
		output();
	}

private:
	vector<vector<int>> div;
	int num,*arr;
	int len[5133];

	void repair()
	{
		ifstream x; x.open("promo");

		int my_size,my_prime;
		vector<int> temp; div.push_back(temp);

		for(int i=1;i<=100000;i++)
		{
			x>>my_size;
			for(int i=1;i<=my_size;i++)
			{
				x>>my_prime;
				temp.push_back(my_prime);
			}

			div.push_back(temp);
			temp.clear();
		}

		for(int i=0;i<5133;i++) len[i]=0;
		x.close();
	}

	void input()
	{
		cin>>num;
		arr=new int[num];
		for(int i=0;i<num;i++) cin>>arr[i];
	}

	void max_length()
	{
		for(int i=num-1;i>=0;i--)
		{
			int ans=0;
			for(unsigned int j=0;j<div[arr[i]].size();j++) if(len[div[arr[i]][j]]>ans) ans=len[div[arr[i]][j]];
			for(unsigned int j=0;j<div[arr[i]].size();j++) len[div[arr[i]][j]]=(ans+1);
		}
	}

	void output()
	{
		int result=1;
		for(int i=0;i<5133;i++) if(len[i]>result) result=len[i];
		cout<<result<<endl;
	}

};

int main()
{
	problem test;
	test.idea();

	//system("pause");
	return 0;
}


#include<iostream>
using namespace std;

class problem
{
public:
	void idea()
	{
		input();
		prepair();

		if(num<=40000) max_length(5133);
		else max_length(66);

		output();
	}

private:
	int num,*arr;
	int prime[5133],len[5133];

	void input()
	{
		cin>>num;
		arr=new int[num];
		for(int i=0;i<num;i++) cin>>arr[i];
	}

	void prepair()
	{
		int count=0,n=0;
		for(int i=2;i<=317;i++)
		{
			count=0;
			for(int j=2;j<i;j++) if(i%j==0) count++;
			if(count==0) prime[n++]=i;
		}

		if(num<=40000)
		{
			for(int i=prime[65];i<=100000;i++)
			{
				count=0;
				for(int j=0;j<66;j++) if(i%prime[j]==0) count++;
				if(count==0) prime[n++]=i;
			}
		}

		for(int i=0;i<5133;i++) len[i]=0;
	}

	void max_length(int z)
	{
		for(int i=num-1;i>=0;i--)
		{
			int ans=0;
			for(int j=0;j<z && arr[i]>=prime[j];j++) if(arr[i]%prime[j]==0 && len[j]>ans) ans=len[j];
			for(int j=0;j<z && arr[i]>=prime[j];j++) if(arr[i]%prime[j]==0) len[j]=(ans+1);
		}
	}

	void output()
	{
		int result=1;
		for(int i=0;i<5133;i++) if(len[i]>result) result=len[i];
		cout<<result<<endl;
	}

};

int main()
{
	problem test;
	test.idea();

	//system("pause");
	return 0;
}


#include<iostream>
using namespace std;

class problem
{
public:
	void idea()
	{
		input();
		promo();
		output();
	}

private:
	int num,*arr;
	int num_prime,prime[10000],len[10000];

	void input()
	{
		cin>>num;
		arr=new int[num];
		for(int i=0;i<num;i++) cin>>arr[i];
	}

	void promo()
	{
		num_prime=0;
		for(int i=2;i<=arr[num-1];i++)
		{
			int count=0;
			for(int j=2;j<i && j<317;j++) if(i%j==0) count++;
			if(count==0) {prime[num_prime]=i; len[num_prime++]=0;}
		}

		for(int i=num-1;i>=0;i--)
		{
			int temp=0;
			for(int j=0;j<num_prime;j++) if(arr[i]%prime[j]==0 && len[j]>temp) temp=len[j];
			for(int j=0;j<num_prime;j++) if(arr[i]%prime[j]==0) len[j]=(temp+1);
		}
	}

	void output()
	{
		int result=1;
		for(int i=0;i<num_prime;i++) if(len[i]>result) result=len[i];
		cout<<result<<endl;
	}

};

int main()
{
	problem test;
	test.idea();

	//system("pause");
	return 0;
}


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

class problem
{
public:
	void idea()
	{
		prepair();
		input();
		max_length();
		output();
	}

private:
	vector<vector<int>> div;
	int num,*arr;
	int len[5133];

	vector<int> temp;
	int prime1[65],prime2[5133];

	void prepair()
	{
		int count=0,n=0;
		for(int i=2;i<=316;i++)
		{
			count=0;
			for(int j=2;j<i;j++) if(i%j==0) count++;
			if(count==0) prime1[n++]=i;
		}

		count=0;n=0;
		for(int i=2;i<50000;i++)
		{
			count=0;
			for(int j=2;j<i && j<=316;j++) if(i%j==0) count++;
			if(count==0) prime2[n++]=i;
		}

		div.push_back(temp);
		my_prime1(1);
		/*for(int i=1;i<=100000;i++)
		{
			for(int j=0;j<5133;j++) if(i%prime2[j]==0) temp.push_back(prime2[j]);
			div.push_back(temp); temp.clear();
		}*/

		for(int i=0;i<5133;i++) len[i]=0;
	}

	void my_prime1(int number)
	{
		my_prime2(number);
		div.push_back(temp); temp.clear();
		if(number<(100000)) my_prime1(number+1);
	}

	void my_prime2(int number,int i=0)
	{
		if(number%prime2[i]==0) temp.push_back(prime2[i]);
		if(i<(5133-1) && number>prime2[i]) my_prime2(number,i+1);
	}

	void input()
	{
		cin>>num;
		arr=new int[num];
		for(int i=0;i<num;i++) cin>>arr[i];
	}

	void max_length()
	{
		for(int i=num-1;i>=0;i--)
		{
			int ans=0;
			for(unsigned int j=0;j<div[arr[i]].size();j++) if(len[div[arr[i]][j]]>ans) ans=len[div[arr[i]][j]];
			for(unsigned int j=0;j<div[arr[i]].size();j++) len[div[arr[i]][j]]=(ans+1);
		}
	}

	void output()
	{
		int result=1;
		for(int i=0;i<5133;i++) if(len[i]>result) result=len[i];
		cout<<result<<endl;
	}

};

int main()
{
	problem test;
	test.idea();

	//system("pause");
	return 0;
}


#include<iostream>
using namespace std;

class problem
{
public:
	void idea()
	{
		input();
		repair();
		max_length();
		output();
	}

private:
	int num,*arr;
	int *prime,*len;
	int result;

	void input()
	{
		cin>>num;
		arr=new int[num];
		for(int i=0;i<num;i++) cin>>arr[i];
	}

	void repair()
	{
		int number=0; // prime numbers 2->320
		prime=new int[9526];
		for(int i=2;i<=100000;i++)
		{
			int count=0;
			for(int j=2;j<=317;j++) if(i%j==0) count++;
			if(count==0) prime[number++]=i;
		}

		len=new int[9526]; // max_length for each divisors
		for(int i=0;i<9526;i++) len[i]=0;
	}

	void max_length()
	{
		for(int i=num-1;i>=0;i--)
		{
			int ans=0;
			for(int j=0;j<9526;j++) if((arr[i]%prime[j]==0) && (len[j]>ans)) ans=len[j]; // find max_length from my divisors
			for(int j=0;j<9526;j++) if(arr[i]%prime[j]==0) len[j]=(ans+1); // update max_length for each divisors
		}

		result=1;
		for(int i=0;i<9526;i++) if(len[i]>result) result=len[i]; // max_length for all
	}

	void output()
	{
		cout<<result<<endl;
	}

};

int main()
{
	problem test;
	test.idea();

	//system("pause");
	return 0;
}


#include<iostream>
#include<cmath>
using namespace std;

class problem
{
public:
	void idea()
	{
		input();
		build();
		output();
	}

private:
	int num;
	int *arr,*len;
	int result;

	void input()
	{
		cin>>num;
		arr=new int[num];
		for(int i=0;i<num;i++) cin>>arr[i];
	}

	void build()
	{
		len=new int[num];
		for(int i=0;i<num;i++) len[i]=1;
		for(int i=num-1;i>=0;i--) max_len(i);
	}

	void max_len(int x)
	{
		for(int i=x+1;i<num;i++)
			if((len[i]+1) > len[x])
				if(gcd(arr[x],arr[i])) len[x]=(len[i]+1);
	}

	int gcd(int x,int y)
	{
		if(y%x==0) return 1;
		for(int i=2;i<=(sqrt(x)+1);i++) if(x%i==0 && y%i==0) return 1;
		return 0;
	}

	void output()
	{
		result=1;
		if(arr[0]==1) len[0]=1;
		for(int i=0;i<num;i++) if(len[i]>result) result=len[i];
		cout<<result<<endl;
	}
};

int main()
{
	problem test;
	test.idea();

	//system("pause");
	return 0;
}


#include<iostream>
using namespace std;

class problem
{
public:
	void idea()
	{
		input();
		promo();
		output();
	}

private:
	int num,*arr;
	int num_prime,prime[5133],len[5133];

	void input()
	{
		cin>>num;
		arr=new int[num];
		for(int i=0;i<num;i++) cin>>arr[i];
	}

	void promo()
	{
		num_prime=0;
		for(int i=2;i<=arr[num-1];i++)
		{
			int count=0;
			for(int j=2;(j<i && j<317);j++) if(i%j==0) count++;
			if(count==0) {prime[num_prime]=i; len[num_prime++]=0;}
		}

		for(int i=num-1;i>=0;i--)
		{
			int temp=0;
			for(int j=0;j<num_prime;j++) if(arr[i]%prime[j]==0 && len[j]>temp) temp=len[j];
			for(int j=0;j<num_prime;j++) if(arr[i]%prime[j]==0) len[j]=(temp+1);
		}
	}

	void output()
	{
		int result=1;
		for(int i=0;i<num_prime;i++) if(len[i]>result) result=len[i];
		cout<<result<<endl;
	}

};

int main()
{
	problem test;
	test.idea();

	//system("pause");
	return 0;
}


#include<iostream>
using namespace std;

class problem
{
public:
	void idea()
	{
		prepair();
		input();

		max_length(0,66);
		//if(result<316) max_length(66,5133);

		output();
	}

private:
	int num,*arr;
	int prime[5133],len[5133];
	int result;

	void prepair()
	{
		int count=0,n=0;

		for(int i=2;i<=317;i++)
		{
			count=0;
			for(int j=2;j<i;j++) if(i%j==0) count++;
			if(count==0) prime[n++]=i;
		}
		/*
		for(int i=prime[65];i<=100000;i++)
		{
			count=0;
			for(int j=0;j<66;j++) if(i%prime[j]==0) count++;
			if(count==0) prime[n++]=i;
		}
		*/
		for(int i=0;i<5133;i++) len[i]=0;
	}

	void input()
	{
		cin>>num;
		arr=new int[num];
		for(int i=0;i<num;i++) cin>>arr[i];
		result=1;
	}

	void max_length(int a,int z)
	{
		for(int i=num-1;i>=0;i--)
		{
			int ans=0;
			for(int j=a;j<z && arr[i]>=prime[j];j++) if(arr[i]%prime[j]==0 && len[j]>ans) ans=len[j];
			for(int j=a;j<z && arr[i]>=prime[j];j++) if(arr[i]%prime[j]==0) len[j]=(ans+1);
		}
	}

	void output()
	{
		for(int i=0;i<66;i++) if(len[i]>result) result=len[i];
		cout<<result<<endl;
	}

};

int main()
{
	problem test;
	test.idea();

	//system("pause");
	return 0;
}


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

class problem
{
public:
	void idea()
	{
		prepair();
		input();
		max_length();
		output();
	}

private:
	vector<vector<int>> div;
	int num,*arr;
	int len[5133];

	vector<int> temp;
	int prime1[65],prime2[5133];

	void prepair()
	{
		int count=0,n=0;
		for(int i=2;i<=316;i++)
		{
			count=0;
			for(int j=2;j<i;j++) if(i%j==0) count++;
			if(count==0) prime1[n++]=i;
		}

		count=0;n=0;
		for(int i=2;i<50000;i++)
		{
			count=0;
			for(int j=2;j<i && j<=316;j++) if(i%j==0) count++;
			if(count==0) prime2[n++]=i;
		}

		div.push_back(temp);
		for(int i=1;i<=100000;i++)
		{
			for(int j=0;j<5133;j++) if(i%prime2[j]==0) temp.push_back(prime2[j]);
			div.push_back(temp); temp.clear();
		}

		for(int i=0;i<5133;i++) len[i]=0;
	}

	void input()
	{
		cin>>num;
		arr=new int[num];
		for(int i=0;i<num;i++) cin>>arr[i];
	}

	void max_length()
	{
		for(int i=num-1;i>=0;i--)
		{
			int ans=0;
			for(unsigned int j=0;j<div[arr[i]].size();j++) if(len[div[arr[i]][j]]>ans) ans=len[div[arr[i]][j]];
			for(unsigned int j=0;j<div[arr[i]].size();j++) len[div[arr[i]][j]]=(ans+1);
		}
	}

	void output()
	{
		int result=1;
		for(int i=0;i<5133;i++) if(len[i]>result) result=len[i];
		cout<<result<<endl;
	}

};

int main()
{
	problem test;
	test.idea();

	//system("pause");
	return 0;
}


#include<iostream>
using namespace std;

class problem
{
public:
	void idea()
	{
		input();
		prepair();

		if(num<40000) max_length(5133);
		else max_length(66);

		output();
	}

private:
	int num,*arr;
	int prime[5133],len[5133];

	void input()
	{
		cin>>num;
		arr=new int[num];
		for(int i=0;i<num;i++) cin>>arr[i];
	}

	void prepair()
	{
		int count=0,n=0;
		for(int i=2;i<=317;i++)
		{
			count=0;
			for(int j=2;j<i;j++) if(i%j==0) count++;
			if(count==0) prime[n++]=i;
		}

		if(num<40000)
		{
			for(int i=prime[65];i<=100000;i++)
			{
				count=0;
				for(int j=0;j<66;j++) if(i%prime[j]==0) count++;
				if(count==0) prime[n++]=i;
			}
		}

		for(int i=0;i<5133;i++) len[i]=0;
	}

	void max_length(int z)
	{
		for(int i=num-1;i>=0;i--)
		{
			int ans=0;
			for(int j=0;j<z && arr[i]>=prime[j];j++) if(arr[i]%prime[j]==0 && len[j]>ans) ans=len[j];
			for(int j=0;j<z && arr[i]>=prime[j];j++) if(arr[i]%prime[j]==0) len[j]=(ans+1);
		}
	}

	void output()
	{
		int result=1;
		for(int i=0;i<5133;i++) if(len[i]>result) result=len[i];
		cout<<result<<endl;
	}

};

int main()
{
	problem test;
	test.idea();

	//system("pause");
	return 0;
}


#include<iostream>
using namespace std;

class problem
{
public:
	void idea()
	{
		input();
		prepair();

		if(num<10000) max_length(5133);
		else max_length(66);

		output();
	}

private:
	int num,*arr;
	int prime[5133],len[5133];

	void input()
	{
		cin>>num;
		arr=new int[num];
		for(int i=0;i<num;i++) cin>>arr[i];
	}

	void prepair()
	{
		int count=0,n=0;
		for(int i=2;i<=317;i++)
		{
			count=0;
			for(int j=2;j<i;j++) if(i%j==0) count++;
			if(count==0) prime[n++]=i;
		}

		if(num<10000)
		{
			for(int i=prime[65];i<=100000;i++)
			{
				count=0;
				for(int j=0;j<66;j++) if(i%prime[j]==0) count++;
				if(count==0) prime[n++]=i;
			}
		}

		for(int i=0;i<5133;i++) len[i]=0;
	}

	void max_length(int z)
	{
		for(int i=num-1;i>=0;i--)
		{
			int ans=0;
			for(int j=0;j<z && arr[i]>=prime[j];j++) if(arr[i]%prime[j]==0 && len[j]>ans) ans=len[j];
			for(int j=0;j<z && arr[i]>=prime[j];j++) if(arr[i]%prime[j]==0) len[j]=(ans+1);
		}
	}

	void output()
	{
		int result=1;
		for(int i=0;i<5133;i++) if(len[i]>result) result=len[i];
		cout<<result<<endl;
	}

};

int main()
{
	problem test;
	test.idea();

	//system("pause");
	return 0;
}


#include<iostream>
using namespace std;

class problem
{
public:
	void idea()
	{
		prepair();
		input();

		max_length(0,200);
		if(result<12) max_length(200,5133);

		output();
	}

private:
	int num,*arr;
	int prime[5133],len[5133];
	int result;

	void prepair()
	{
		int count=0,n=0;

		for(int i=2;i<=317;i++)
		{
			count=0;
			for(int j=2;j<i;j++) if(i%j==0) count++;
			if(count==0) prime[n++]=i;
		}

		for(int i=prime[65];i<=100000;i++)
		{
			count=0;
			for(int j=0;j<66;j++) if(i%prime[j]==0) count++;
			if(count==0) prime[n++]=i;
		}

		for(int i=0;i<5133;i++) len[i]=0;
	}

	void input()
	{
		cin>>num;
		arr=new int[num];
		for(int i=0;i<num;i++) cin>>arr[i];
		result=1;
	}

	void max_length(int a,int z)
	{
		for(int i=num-1;i>=0;i--)
		{
			int ans=0;
			for(int j=a;j<z && arr[i]>=prime[j];j++) if(arr[i]%prime[j]==0 && len[j]>ans) ans=len[j];
			for(int j=a;j<z && arr[i]>=prime[j];j++) if(arr[i]%prime[j]==0) len[j]=(ans+1);
		}
	}

	void output()
	{
		for(int i=0;i<5133;i++) if(len[i]>result) result=len[i];
		cout<<result<<endl;
	}

};

int main()
{
	problem test;
	test.idea();

	//system("pause");
	return 0;
}


#include<iostream>
using namespace std;

class problem
{
public:
	void idea()
	{
		prepair();
		input();

		max_length(0,500);
		if(result<12) max_length(500,5133);

		output();
	}

private:
	int num,*arr;
	int prime[5133],len[5133];
	int result;

	void prepair()
	{
		int count=0,n=0;

		for(int i=2;i<=317;i++)
		{
			count=0;
			for(int j=2;j<i;j++) if(i%j==0) count++;
			if(count==0) prime[n++]=i;
		}

		for(int i=prime[65];i<=100000;i++)
		{
			count=0;
			for(int j=0;j<66;j++) if(i%prime[j]==0) count++;
			if(count==0) prime[n++]=i;
		}

		for(int i=0;i<5133;i++) len[i]=0;
	}

	void input()
	{
		cin>>num;
		arr=new int[num];
		for(int i=0;i<num;i++) cin>>arr[i];
		result=1;
	}

	void max_length(int a,int z)
	{
		for(int i=num-1;i>=0;i--)
		{
			int ans=0;
			for(int j=a;j<z && arr[i]>=prime[j];j++) if(arr[i]%prime[j]==0 && len[j]>ans) ans=len[j];
			for(int j=a;j<z && arr[i]>=prime[j];j++) if(arr[i]%prime[j]==0) len[j]=(ans+1);
		}
	}

	void output()
	{
		for(int i=0;i<5133;i++) if(len[i]>result) result=len[i];
		cout<<result<<endl;
	}

};

int main()
{
	problem test;
	test.idea();

	//system("pause");
	return 0;
}


#include<iostream>
using namespace std;

class problem
{
public:
	void idea()
	{
		prepair();
		input();

		max_length(0,1000);
		if(result<12) max_length(1000,5133);

		output();
	}

private:
	int num,*arr;
	int prime[5133],len[5133];
	int result;

	void prepair()
	{
		int count=0,n=0;

		for(int i=2;i<=317;i++)
		{
			count=0;
			for(int j=2;j<i;j++) if(i%j==0) count++;
			if(count==0) prime[n++]=i;
		}

		for(int i=prime[65];i<=100000;i++)
		{
			count=0;
			for(int j=0;j<66;j++) if(i%prime[j]==0) count++;
			if(count==0) prime[n++]=i;
		}

		for(int i=0;i<5133;i++) len[i]=0;
	}

	void input()
	{
		cin>>num;
		arr=new int[num];
		for(int i=0;i<num;i++) cin>>arr[i];
		result=1;
	}

	void max_length(int a,int z)
	{
		for(int i=num-1;i>=0;i--)
		{
			int ans=0;
			for(int j=a;j<z && arr[i]>=prime[j];j++) if(arr[i]%prime[j]==0 && len[j]>ans) ans=len[j];
			for(int j=a;j<z && arr[i]>=prime[j];j++) if(arr[i]%prime[j]==0) len[j]=(ans+1);
		}
	}

	void output()
	{
		for(int i=0;i<5133;i++) if(len[i]>result) result=len[i];
		cout<<result<<endl;
	}

};

int main()
{
	problem test;
	test.idea();

	//system("pause");
	return 0;
}


#include<iostream>
using namespace std;

class problem
{
public:
	void idea()
	{
		input();
		prepair();

		if(num<62000) max_length(5133);
		else max_length(66);

		output();
	}

private:
	int num,*arr;
	int prime[5133],len[5133];

	void input()
	{
		cin>>num;
		arr=new int[num];
		for(int i=0;i<num;i++) cin>>arr[i];
	}

	void prepair()
	{
		int count=0,n=0;
		for(int i=2;i<=317;i++)
		{
			count=0;
			for(int j=2;j<i;j++) if(i%j==0) count++;
			if(count==0) prime[n++]=i;
		}

		if(num<62000)
		{
			for(int i=prime[65];i<=100000;i++)
			{
				count=0;
				for(int j=0;j<66;j++) if(i%prime[j]==0) count++;
				if(count==0) prime[n++]=i;
			}
		}

		for(int i=0;i<5133;i++) len[i]=0;
	}

	void max_length(int z)
	{
		for(int i=num-1;i>=0;i--)
		{
			int ans=0;
			for(int j=0;j<z && arr[i]>=prime[j];j++) if(arr[i]%prime[j]==0 && len[j]>ans) ans=len[j];
			for(int j=0;j<z && arr[i]>=prime[j];j++) if(arr[i]%prime[j]==0) len[j]=(ans+1);
		}
	}

	void output()
	{
		int result=1;
		for(int i=0;i<5133;i++) if(len[i]>result) result=len[i];
		cout<<result<<endl;
	}

};

int main()
{
	problem test;
	test.idea();

	//system("pause");
	return 0;
}


#include<iostream>
using namespace std;

class problem
{
public:
	void idea()
	{
		input();
		prepair();

		if(num<50000) max_length(5133);
		else max_length(66);

		output();
	}

private:
	int num,*arr;
	int prime[5133],len[5133];

	void input()
	{
		cin>>num;
		arr=new int[num];
		for(int i=0;i<num;i++) cin>>arr[i];
	}

	void prepair()
	{
		int count=0,n=0;
		for(int i=2;i<=317;i++)
		{
			count=0;
			for(int j=2;j<i;j++) if(i%j==0) count++;
			if(count==0) prime[n++]=i;
		}

		if(num<50000)
		{
			for(int i=prime[65];i<=100000;i++)
			{
				count=0;
				for(int j=0;j<66;j++) if(i%prime[j]==0) count++;
				if(count==0) prime[n++]=i;
			}
		}

		for(int i=0;i<5133;i++) len[i]=0;
	}

	void max_length(int z)
	{
		for(int i=num-1;i>=0;i--)
		{
			int ans=0;
			for(int j=0;j<z && arr[i]>=prime[j];j++) if(arr[i]%prime[j]==0 && len[j]>ans) ans=len[j];
			for(int j=0;j<z && arr[i]>=prime[j];j++) if(arr[i]%prime[j]==0) len[j]=(ans+1);
		}
	}

	void output()
	{
		int result=1;
		for(int i=0;i<5133;i++) if(len[i]>result) result=len[i];
		cout<<result<<endl;
	}

};

int main()
{
	problem test;
	test.idea();

	//system("pause");
	return 0;
}


#include<iostream>
using namespace std;

class problem
{
public:
	void idea()
	{
		input();
		prepair();

		if(num<10000) max_length(5133);
		else max_length(66);

		output();
	}

private:
	int num,*arr;
	int prime[5133],len[5133];

	void input()
	{
		cin>>num;
		arr=new int[num];
		for(int i=0;i<num;i++) cin>>arr[i];
	}

	void prepair()
	{
		int count=0,n=0;
		for(int i=2;i<=317;i++)
		{
			count=0;
			for(int j=2;j<i;j++) if(i%j==0) count++;
			if(count==0) prime[n++]=i;
		}

		if(num<10000)
		{
			for(int i=prime[65];i<=100000;i++)
			{
				count=0;
				for(int j=0;j<66;j++) if(i%prime[j]==0) count++;
				if(count==0) prime[n++]=i;
			}
		}

		for(int i=0;i<5133;i++) len[i]=0;
	}

	void max_length(int z)
	{
		for(int i=num-1;i>=0;i--)
		{
			int ans=0;
			for(int j=0;j<z && arr[i]>=prime[j];j++) if(arr[i]%prime[j]==0 && len[j]>ans) ans=len[j];
			for(int j=0;j<z && arr[i]>=prime[j];j++) if(arr[i]%prime[j]==0) len[j]=(ans+1);
		}
	}

	void output()
	{
		int result=1;
		for(int i=0;i<66;i++) if(len[i]>result) result=len[i];
		cout<<result<<endl;
	}

};

int main()
{
	problem test;
	test.idea();

	//system("pause");
	return 0;
}


#include<iostream>
#include<cmath>
using namespace std;

class problem
{
public:
	void idea()
	{
		input();
		build();
		output();
	}

private:
	int num;
	int *arr,*len;
	int result;

	void input()
	{
		cin>>num;
		arr=new int[num];
		for(int i=0;i<num;i++) cin>>arr[i];
	}

	void build()
	{
		len=new int[num];
		for(int i=0;i<num;i++) len[i]=1;
		for(int i=num-1;i>=0;i--) max_len(i);
	}

	void max_len(int x)
	{
		for(int i=x+1;i<num;i++)
			if((len[i]+1) > len[x])
				if(gcd(arr[x],arr[i])) len[x]=(len[i]+1);
	}

	int gcd(int x,int y)
	{
		if(y%x==0) return 1;
		for(int i=2;i<=(sqrt(x)+1);i++) if(x%i==0 && y%i==0) return 1;
		return 0;
	}

	void output()
	{
		result=1;
		for(int i=0;i<num;i++) if(len[i]>result) result=len[i];
		if(arr[0]==1) result--;
		cout<<result<<endl;
	}
};

int main()
{
	problem test;
	test.idea();

	//system("pause");
	return 0;
}


#include<iostream>
using namespace std;

class problem
{
public:
	void idea()
	{
		prepair();
		input();

		max_length(0,66);
		if(result<316) max_length(66,5133);

		output();
	}

private:
	int num,*arr;
	int prime[5133],len[5133];
	int result;

	void prepair()
	{
		int count=0,n=0;

		for(int i=2;i<=317;i++)
		{
			count=0;
			for(int j=2;j<i;j++) if(i%j==0) count++;
			if(count==0) prime[n++]=i;
		}

		for(int i=prime[65];i<=100000;i++)
		{
			count=0;
			for(int j=0;j<66;j++) if(i%prime[j]==0) count++;
			if(count==0) prime[n++]=i;
		}

		for(int i=0;i<5133;i++) len[i]=0;
	}

	void input()
	{
		cin>>num;
		arr=new int[num];
		for(int i=0;i<num;i++) cin>>arr[i];
		result=1;
	}

	void max_length(int a,int z)
	{
		for(int i=num-1;i>=0;i--)
		{
			int ans=0;
			for(int j=a;j<z && arr[i]>=prime[j];j++) if(arr[i]%prime[j]==0 && len[j]>ans) ans=len[j];
			for(int j=a;j<z && arr[i]>=prime[j];j++) if(arr[i]%prime[j]==0) len[j]=(ans+1);
		}
	}

	void output()
	{
		for(int i=0;i<5133;i++) if(len[i]>result) result=len[i];
		cout<<result<<endl;
	}

};

int main()
{
	problem test;
	test.idea();

	//system("pause");
	return 0;
}


#include<iostream>
using namespace std;

class problem
{
public:
	void idea()
	{
		input();
		prepair();

		if(num<=40000) max_length(5133);
		else max_length(66);

		output();
	}

private:
	int num,*arr;
	int prime[5133],len[5133];

	void input()
	{
		cin>>num;
		arr=new int[num];
		for(int i=0;i<num;i++) cin>>arr[i];
	}

	void prepair()
	{
		int count=0,n=0;
		for(int i=2;i<=317;i++)
		{
			count=0;
			for(int j=2;j<i;j++) if(i%j==0) count++;
			if(count==0) prime[n++]=i;
		}

		if(num<=40000)
		{
			for(int i=prime[65];i<=100000;i++)
			{
				count=0;
				for(int j=0;j<66;j++) if(i%prime[j]==0) count++;
				if(count==0) prime[n++]=i;
			}
		}

		for(int i=0;i<5133;i++) len[i]=0;
	}

	void max_length(int z)
	{
		for(int i=num-1;i>=0;i--)
		{
			int ans=0;
			for(int j=0;j<z && arr[i]>=prime[j];j++) if(arr[i]%prime[j]==0 && len[j]>ans) ans=len[j];
			for(int j=0;j<z && arr[i]>=prime[j];j++) if(arr[i]%prime[j]==0) len[j]=(ans+1);
		}
	}

	void output()
	{
		int result=1;
		for(int i=0;i<5133;i++) if(len[i]>result) result=len[i];
		cout<<result<<endl;
	}

};

int main()
{
	problem test;
	test.idea();

	//system("pause");
	return 0;
}


#include<iostream>
using namespace std;

class problem
{
public:
	void idea()
	{
		input();
		repair();
		max_length();
		output();
	}

private:
	int num,*arr;
	int *prime,*len;
	int result;

	void input()
	{
		cin>>num;
		arr=new int[num];
		for(int i=0;i<num;i++) cin>>arr[i];
	}

	void repair()
	{
		int number=0; // prime numbers 2->320
		prime=new int[66];
		for(int i=2;i<=320;i++)
		{
			int count=0;
			for(int j=2;j<i;j++) if(i%j==0) count++;
			if(count==0) prime[number++]=i;
		}

		len=new int[66]; // max_length for each divisors
		for(int i=0;i<66;i++) len[i]=0;
	}

	void max_length()
	{
		for(int i=num-1;i>=0;i--)
		{
			int ans=0;
			for(int j=0;j<66;j++) if((arr[i]%prime[j]==0) && (len[j]>ans)) ans=len[j]; // find max_length from my divisors
			for(int j=0;j<66;j++) if(arr[i]%prime[j]==0) len[j]=(ans+1); // update max_length for each divisors
		}

		result=1;
		for(int i=0;i<66;i++) if(len[i]>result) result=len[i]; // max_length for all
	}

	void output()
	{
		cout<<result<<endl;
	}

};

int main()
{
	problem test;
	test.idea();

	//system("pause");
	return 0;
}


#include<iostream>
#include<cmath>
using namespace std;

class problem
{
public:
	void idea()
	{
		input();
		build();
		output();
	}

private:
	int num;
	int *arr,*len;
	int result;

	void input()
	{
		cin>>num;
		arr=new int[num];
		for(int i=0;i<num;i++) cin>>arr[i];
	}

	void build()
	{
		len=new int[num];
		for(int i=0;i<num;i++) len[i]=1;
		for(int i=num-1;i>=0;i--) max_len(i);
	}

	void max_len(int x)
	{
		for(int i=x+1;i<num;i++)
			if((len[i]+1) > len[x])
				if(gcd(arr[x],arr[i])) len[x]=(len[i]+1);
	}

	int gcd(int x,int y)
	{
		if(y%x==0) return 1;
		for(int i=2;i<=(sqrt(x)+1);i++) if(x%i==0 && y%i==0) return 1;
		return 0;
	}

	void output()
	{
		if(arr[0]==1) len[0]=0;
		for(int i=0;i<num;i++) if(len[i]>result) result=len[i];
		cout<<result<<endl;
	}
};

int main()
{
	problem test;
	test.idea();

	//system("pause");
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define all(x) x.begin(),x.end()

int const N = 100001;
int n, a[N], dp[N], spf[N], nxt[N];
vector<int> fc[N], ps[N];

void Pr(){
     for(int i = 1; i<=N; ++i)spf[i] = i;
     for(int i = 2; i<=N; i+=2)spf[i] = 2;
     for(int i = 3; i<=N; ++i)if(spf[i] == i){
	    for(int j = i*2; j<=N; j+=i)spf[j] = i;
	 }
}

void f(int x){
	int t = x;
      while(x & 1 ^ 1)x >>= 1;
      if(x != t)fc[t].push_back(2);
      while(x != 1)fc[t].push_back(spf[x]), x/=spf[x];
      if(x != 1)fc[t].push_back(x);
      sort(all(fc[t]));
      fc[t].resize(unique(all(fc[t]))-fc[t].begin());
}

int go(int cur){
    if(cur == n)return 0;
    int &ret = dp[cur];
    if(ret + 1)return ret;
    ret = go(cur+1);
    ret = max(ret, go(nxt[cur])+1);
    return ret;
}

int main(){
	scanf("%d", &n);
	Pr();
	for(int i = 0; i<n; ++i){
	    scanf("%d", a+i);
	    f(a[i]);
	    for(auto k: fc[a[i]])ps[k].push_back(i);
	}
	for(int i = 0; i<n; ++i){
		if(a[i] == 1){nxt[i] = n;continue;}
	    if (__gcd(a[i], a[i+1]) != 1)nxt[i] = i+1;
	    else {
		     int p = 1e9;
		     for(auto k: fc[a[i]]){
			     int j = upper_bound(all(ps[k]), i)-ps[k].begin();
			     if(j == (int)ps[k].size())continue;
			     p = min(p, ps[k][j]);
			 }
			 if(p == 1e9)nxt[i] = n;
			 else nxt[i] = p;
		}
	}
	memset(dp,-1,sizeof dp);
	int an = go(0);
	printf("%d\n",an);
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define all(x) x.begin(),x.end()

int const N = 100001;
int n, a[N], dp[N], spf[N], nxt[N];
vector<int> fc[N], ps[N];

void f(int x){
	int t = x;
	bool sp = false;
	while(x & 1 ^ 1)sp = true,x >>= 1;
	if(sp)fc[t].push_back(2);
	for(int i = 3; i<=sqrt(n); i+=2){
		sp = false;
	    while(x % i == 0){
		     x /= i;
		     sp = true;
		}
		if(sp)fc[t].push_back(i);
	}
	if(x > 2)fc[t].push_back(x);
}

int go(int cur){
    if(cur >= n)return 0;
    int &ret = dp[cur];
    if(ret + 1)return ret;
    ret = go(cur+1);
    ret = max(ret, go(nxt[cur])+1);
    return ret;
}

int main(){
	scanf("%d", &n);
	for(int i = 0; i<n; ++i){
	    scanf("%d", a+i);
	    f(a[i]);
	    for(auto k: fc[a[i]])ps[k].push_back(i);
	 }
	for(int i = 0; i<n; ++i){
	    if (__gcd(a[i], a[i+1]) != 1)nxt[i] = i+1;
	    else {
		     int p = 1e9;
		     for(auto k: fc[a[i]]){
			     int j = upper_bound(all(ps[k]), i)-ps[k].begin();
			     if(j == (int)ps[k].size())continue;
			     p = min(p, ps[k][j]);
			 }
			 if(p == 1e9)nxt[i] = n+1;
			 else nxt[i] = p;
		}
	}
	memset(dp,-1,sizeof dp);
	int an = go(a[0] == 1? 1: 0);
	printf("%d\n",max(1,an));
}