CCCPaste

Untitled

#include 
#include 
#include 
using namespace std;

int main() {
    ios_base::sync_with_stdio(false);
    int n;
    cin >> n;
    
    vector v(n);
    for(int i = 0; i < n; i++) {
        cin >> v[i];
    }
    int i = 0, j = 0;
    int cnt_3 = 0, res = 0;
    while(j < n) {
        if(cnt_3 <= 3) {
            if(v[j] == 3) {
                cnt_3++;
            }
            j++;
            
            if(cnt_3 == 3) {
                res = max(res, j - i);
            }
        }
        else {
            if(v[i] == 3) {
                cnt_3--;
            }
            i++;
            if(cnt_3 == 3) {
                res = max(res, j - i);
            }
        }
        
    }
    cout << res << endl;
    return 0;
}