Untitled

mail@pastecode.io avatar
unknown
plain_text
7 months ago
861 B
0
Indexable
Never
#include <iostream>
#include <vector>
int main()
{
	int n = 0;
	int cur = 0;
	int prev = 0;
	int maxChangeLen = 0;
	int curChangeLen = 1;
	int resChangeLen = 0;
	int prevChangeLen = 0;

	std::cin >> n;

	for (int i = 0; i < n; i++) {
		std::cin >> cur;
		
		if (cur == prev) {
			curChangeLen++;
		}
		else {
			if (prevChangeLen == 0) {
				prevChangeLen = curChangeLen;
				curChangeLen = 1;
			}
			else {
				resChangeLen = std::min(prevChangeLen, curChangeLen);
				prevChangeLen = curChangeLen;
				curChangeLen = 0;
			}
			/*resChangeLen = std::max(prevChangeLen, curChangeLen);*/
			if (resChangeLen > maxChangeLen) {
				maxChangeLen = resChangeLen;
			}
			/*prevChangeLen = curChangeLen;
			curChangeLen = 1;*/
		}
		prev = cur;
	}
	std::cout << maxChangeLen * 2;
}
//Шульга Егор Андреевич
Leave a Comment