import java.util.ArrayList; import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int[] a = new int[n]; for (int i = 0; i < n; i++) { a[i] = sc.nextInt(); } ArrayList list = new ArrayList<>(); int prev = a[0]; int count = 0; for (int i : a) { if (i == prev) { count++; } else { list.add(count); count = 1; prev = i; } } list.add(count); // for (int i = 0; i < list.size(); i++) { // System.out.print(list.get(i)+" "); // } // System.out.println(); long[][] dp = new long[list.size() + 10][2]; dp[0][0] = 0; dp[0][1] = 0; for (int i = 1; i <= list.size(); i++) { dp[i][0] = Math.max(dp[i - 1][0], dp[i - 1][1]); dp[i][1] = dp[i - 1][0] + list.get(i - 1); } System.out.println(Math.max(dp[list.size()][0], dp[list.size()][1])); } }