Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //==================================================================//
- // Name : flash7even //
- // Author : Tarango Khan //
- // Codeforces : flash_7 //
- // Topcoder : flash_7 //
- // Hackerrank : flash_7 //
- // Email : [email protected] //
- // Facebook : flash7even //
- //==================================================================//
- //==================================================================//
- #include <bits/stdc++.h> //
- using namespace std; //
- #define read(nm) freopen(nm, "r", stdin) //
- #define write(nm) freopen(nm, "w", stdout) //
- #define pb push_back //
- #define MP make_pair //
- #define ff first //
- #define ss second //
- #define FABS(x) ((x)+eps<0?-(x):(x)) //
- #define POPCOUNT __builtin_popcountll //
- #define RIGHTMOST __builtin_ctzll //
- #define LEFTMOST(x) (63-__builtin_clzll((x))) //
- #define NUMDIGIT(x,y) (((int)(log10((x))/log10((y))))+1) //
- #define SQ(x) ((x)*(x)) //
- #define pf printf //
- #define sf scanf //
- #define phl printf("hello\n") //
- #define SZ(x) ((int)(x).size()) //
- #define mems(x,v) memset(x,v,sizeof(x)) //
- #define CLR(x,y) memset(x,y,sizeof(x)) //
- #define ALL(x) (x).begin(),(x).end() //
- #define NORM(x) if(x>=mod)x-=mod; //
- #define MOD(x,y) (((x)*(y))%mod) //
- #define fills(v,n) fill(v.begin(), v.end(), n) //
- #define LL long long //
- #define LLU long long unsigned int //
- #define vlong long long //
- #define uvlong unsigned long long //
- #define debug1(v1) cout<<"1@ Debug Val 1 = "<<v1<<endl; //
- #define debug2(v2) cout<<" 2@ Debug Num 2 = "<<v2<<endl; //
- #define debug3(v3) cout<<" 3@ Debug Res 3 = "<<v3<<endl; //
- #define UB(v,a) upper_bound(v.begin(),v.end(),a)-v.begin() //
- #define LB(v,a) lower_bound(v.begin(),v.end(),a)-v.begin() //
- #define fast_cin ios_base::sync_with_stdio(false);cin.tie(NULL) //
- //==================================================================//
- //==================================================================//
- void make_unique(vector<int> &a){ sort(a.begin(), a.end()); //
- a.erase(unique(a.begin(), a.end()), a.end()); } //
- void printDouble(double f,int p){ cout << fixed; //
- cout << setprecision(p) << f <<endl; } //
- int Set(int N,int cur){ return N = N | (1<<cur); } //
- int Reset(int N,int cur){ return N = N & ~(1<<cur); } //
- bool Check(int N,int cur){ return (bool)(N & (1<<cur)); } //
- LL GCD(LL a,LL b){ if(b == 0) return a; return GCD(b,a%b);} //
- LL LCM(LL a,LL b){ return a*b/GCD(a,b);} //
- LL POW(LL a,LL p){ LL res = 1,x = a;while(p){if(p&1) //
- res = (res*x); x = (x*x);p >>= 1;} return res;} //
- //==================================================================//
- //==================================================================//
- //int knightDir[8][2] = {{-2,1},{-1,2},{1,2},{2,1}, //
- // {2,-1},{-1,-2},{1,-2},{-2,-1}}; //
- //int dir8[8][2] = {{-1,0},{0,1},{1,0},{0,-1}, //
- // {-1,-1},{1,1},{1,-1},{-1,1}}; //
- //int dir4[4][2] = {{-1,0},{0,1},{1,0},{0,-1}}; //
- //==================================================================//
- #ifdef forthright48
- #include <ctime>
- clock_t tStart = clock();
- #define debug(args...) {dbg,args; cerr<<endl;}
- #define timeStamp printf("Exc Time: %.2fs\n",(double)(clock()-tStart)/CLOCKS_PER_SEC)
- #else
- #define debug(args...)
- #define timeStamp
- #endif
- struct debugger{
- template<typename T> debugger& operator , (const T& v){
- cerr << v << " ";
- return *this;
- }
- }dbg;
- typedef pair <LL,LL> pll;
- typedef vector<pll> vll;
- typedef vector<LL> vl;
- const LL inf = 2147383647;
- const LL MOD = 1000000007;
- const double pi = 2*acos(0.0);
- const double eps = 1e-9;
- #define Size 100005
- //=======// Done With The Shortcut Stuffs! Now Let's Code! //=======//
- int N;
- int A[1000005];
- int maxOccur(){
- if(N == 1) return 1;
- int res = 1,cnt = 1,i = 1;
- while(i<N){
- if(A[i] == A[i-1]){
- cnt++;
- }else{
- res = max(res,cnt);
- cnt = 1;
- }
- i++;
- }
- res = max(res,cnt);
- if(A[0] == A[N-1]){
- cnt = 2;
- i = 1;
- while(i<N){
- if(A[i] != A[i-1]) break;
- i++;
- cnt++;
- }
- i = N-2;
- while(i>=0){
- if(A[i] != A[i+1]) break;
- i--;
- cnt++;
- }
- res = max(res,cnt);
- }
- return res;
- }
- int main() {
- sf("%d",&N);
- for(int i = 0;i<N;i++){
- sf("%d",&A[i]);
- }
- int mxc = maxOccur();
- int res = mxc + (N-mxc)*2;
- cout << res << endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment