using
System;
using
System.Linq;
using
System.Collections.Generic;
class
MainClass {
static
SortedSet<
int
> st =
new
SortedSet<
int
>();
static
int
LIPS(
int
[] arr,
int
N) {
if
(N == 0)
return
0;
int
[,] dp =
new
int
[N + 1, 2];
int
max_subsequence = 0;
for
(
int
i = 0; i < N; i++) {
dp[i, 0] = (arr[i] >= 2) ? 1 : 0;
dp[i, 1] = 1;
for
(
int
j = 0; j < i; j++) {
var
option1 = st.GetViewBetween(arr[j],
int
.MaxValue).FirstOrDefault();
var
option2 = st.GetViewBetween(arr[j],
int
.MaxValue).Skip(1).FirstOrDefault();
if
(option1 < st.GetViewBetween(arr[i],
int
.MaxValue).First())
dp[i, 0] = Math.Max(dp[i, 0], dp[j, 0] + 1);
if
(option2 < st.GetViewBetween(arr[i],
int
.MaxValue).First())
dp[i, 0] = Math.Max(dp[i, 0], dp[j, 1] + 1);
if
(option1 < st.GetViewBetween(arr[i],
int
.MaxValue).Skip(1).First())
dp[i, 1] = Math.Max(dp[i, 1], dp[j, 0] + 1);
if
(option2 < st.GetViewBetween(arr[i],
int
.MaxValue).Skip(1).First())
dp[i, 1] = Math.Max(dp[i, 1], dp[j, 1] + 1);
}
max_subsequence = Math.Max(max_subsequence, dp[i, 0]);
max_subsequence = Math.Max(max_subsequence, dp[i, 1]);
}
return
max_subsequence ;
}
static
void
prime_sieve() {
bool
[] primes =
new
bool
[1000000 + 5 + 1];
for
(
int
i = 0; i <= 1000000 + 5; i++)
primes[i] =
true
;
primes[0] = primes[1] =
false
;
for
(
int
i = 4; i <= 1000000; i += 2)
primes[i] =
false
;
for
(
int
i = 3; i <= 1000000; i += 2) {
if
(primes[i]) {
for
(
int
j = 2 * i; j <= 1000000; j += i)
primes[j] =
false
;
}
}
st.Add(2);
for
(
int
i = 3; i <= 1000000; i += 2)
if
(primes[i])
st.Add(i);
}
public
static
void
Main(
string
[] args) {
int
N = 6;
int
[] arr = { 6, 7, 8, 9, 10, 11 };
prime_sieve();
Console.WriteLine(LIPS(arr, N));
}
}