1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#include <cstdio>
#include <algorithm>

using namespace std;

const int mxn = 1e6+7;

int t[mxn];
int pref1[mxn];
int pref2[mxn];
int suf1[mxn];
int suf2[mxn];

int main() {
	
	int n;
	scanf("%d", &n);
	for(int i=1; i<=n; ++i)
		scanf("%d", &t[i]);
	
	for(int i=1; i<=n; ++i){
		pref1[i] = pref1[i-1] + t[i];
		pref2[i] = pref2[i-1] + 1 - t[i];
	}
	
	for(int i=n; i>=1; --i){
		suf1[i] = suf1[i+1] + t[i];
		suf2[i] = suf2[i+1] + 1 - t[i];
	}
	
	int result = n+1;
	
	for(int i=1; i<=n; ++i){
		result = min(result, pref2[i-1] + suf1[i]);
	}
	
	printf("%d\n", result);
	
	return 0;
}