1 #include <bits/stdc++.h> 2 #define _for(i,a,b) for(int i = (a);i < b;i ++) 3 typedef long long ll; 4 using namespace std; 5 inline ll read() 6 { 7 ll ans = 0; 8 char ch = getchar(), last = ' '; 9 while(!isdigit(ch)) last = ch, ch = getchar(); 10 while(isdigit(ch)) ans = (ans << 1) + (ans << 3) + ch - '0', ch = getchar(); 11 if(last == '-') ans = -ans; 12 return ans; 13 } 14 inline void write(ll x) 15 { 16 if(x < 0) x = -x, putchar('-'); 17 if(x >= 10) write(x / 10); 18 putchar(x % 10 + '0'); 19 } 20 int N; 21 int a[103]; 22 23 int sv1(int k) 24 { 25 int dp1[103]; 26 int dp1ed = 1; 27 dp1[dp1ed] = a[0]; 28 _for(i,1,k+1) 29 if(a[i]>dp1[dp1ed]) 30 dp1[++dp1ed] = a[i]; 31 else 32 { 33 int t = lower_bound(dp1+1,dp1+dp1ed+1,a[i])-dp1; 34 dp1[t] = a[i]; 35 } 36 return k+1-dp1ed; 37 } 38 int sv2(int k) 39 { 40 int dp2[103]; 41 int dp2ed = 1; 42 dp2[dp2ed] = a[k]; 43 _for(i,k,N) 44 if(a[i]<dp2[dp2ed]) 45 dp2[++dp2ed] = a[i]; 46 else 47 { 48 int t = lower_bound(dp2+1,dp2+dp2ed+1,a[i],greater<int>())-dp2; 49 dp2[t] = a[i]; 50 } 51 return N-k-dp2ed; 52 } 53 int main() 54 { 55 N = read(); 56 _for(i,0,N) 57 a[i] = read(); 58 59 int rnt = 200; 60 _for(i,0,N) 61 { 62 int rt1 = sv1(i); 63 int rt2 = sv2(i); 64 rnt = min(rnt,rt1+rt2); 65 } 66 write(rnt); 67 return 0; 68 }