process.stdin.resume();
process.stdin.setEncoding("ascii");
let string = "";
process.stdin.on("data", data => string += data);
process.stdin.on("end", () => {
    const array = string.split("\n")[1].split(" ").map(Number);
    let accumulatedTime = 0;
    let satisfiedCustomerCount = 0;
    array
        .sort((a, b) => a - b)
        .forEach(serviceTime => {
            if (accumulatedTime <= serviceTime) {
                satisfiedCustomerCount++;
                accumulatedTime += serviceTime;
            }
        });
    console.log(satisfiedCustomerCount);
})

// Getting Problem Data from Codeforces.
var peopleCount  = parseInt(readline());
var servingTimes = readline().split(' ');
// Converting Array to Integers.
for(var j = 0;j<peopleCount;++j)
   servingTimes[j] = parseInt(servingTimes[j]);
// Sorting List.
servingTimes.sort(function(a,b){
    return a-b;
});
// Algorithm.
var notDissapointedCount = 0,sum = 0;
for (var i  = 0;i<peopleCount;++i){
   if(servingTimes[i]>=sum){
     notDissapointedCount++;
     sum+=servingTimes[i];
   }
}
// Solution.
print(notDissapointedCount);

function cmp(a, b)
{
    if (+a < +b)
        return -1;
    if (+a > +b)
        return 1;
    return 0;
}

function main(cin, cout)
{
    var n = +cin.next();
    var t = Array(n);
    for(var i = 0; i < n; ++i)
        t[i] = +cin.next();
    t.sort(cmp);
    var ans = 0;
    var time = 0;
    for(var i = 0; i < n; ++i)
    {
        if (t[i] >= time)
        {
            time += t[i];
            ++ans;
        }
    }
    cout.print(ans);
}

function Stack()
{
    this.array = [];
}

Stack.prototype.empty = function()
{
    return this.array.length == 0;
}

Stack.prototype.push = function(value)
{
    this.array.push(value);
}

Stack.prototype.pop = function()
{
    if (!this.empty())
        return this.array.pop();
    return undefined;
}

Stack.prototype.top = function()
{
    if (!this.empty())
        return this.array[this.array.length - 1];
    return undefined;
}

Stack.prototype.clear = function()
{
    this.array = [];
}

Stack.prototype.size = function()
{
    return this.array.length;
}

function Queue()
{
    this.leftStack = new Stack();
    this.rightStack = new Stack();
}

Queue.prototype.push = function(value)
{
    this.leftStack.push(value);
}

Queue.prototype.empty = function()
{
    return this.rightStack.empty() && this.leftStack.empty();
}

Queue.prototype.pop = function()
{
    if (this.rightStack.empty())
    {
        while(!this.leftStack.empty())
            this.rightStack.push(this.leftStack.pop());
    }
    if (!this.rightStack.empty())
        return this.rightStack.pop();
    return undefined;
}

Queue.prototype.front = function()
{
    if (this.rightStack.empty())
    {
        while(!this.leftStack.empty())
            this.rightStack.push(this.leftStack.pop());
    }
    if (!this.rightStack.empty())
        return this.rightStack.top();
    return undefined;
}

Queue.prototype.size = function()
{
    return leftStack.size() + rightStack.size();
}

Queue.prototype.clear = function()
{
    leftStack.clear();
    rightStack.clear();
}

function Reader()
{
    this.buffer = [];
    this.cur = 0;
}

Reader.prototype.next = function()
{
    if (this.cur == this.buffer.length)
    {
        this.cur = 0;
        this.buffer = readline().split(' ');
    }
    return this.buffer[this.cur++];
}

function Writer()
{
    this.buffer = "";
}

Writer.prototype.print = function(s)
{
    this.buffer += s;
}

Writer.prototype.println = function(s)
{
    this.buffer += s;
    print(this.buffer);
    this.buffer = "";
}

Writer.prototype.flush = function()
{
    if (this.buffer != "")
    print(this.buffer);
    this.buffer = "";
}

var cin = new Reader();
var cout = new Writer();

main(cin, cout);

cout.flush();

function Stack(){this.a=[]}function Queue(){this.l=new Stack,this.r=new Stack}function Reader(){this.b=[],this.c=0}function Writer(){this.l=[""],this.c=0}Array.prototype.back=function(){return this[this.length-1]},Math.gcd=function(t,i){return i?gcd(i,t%i):t},Math.lcm=function(t,i){return t/gcd(t,i)*i},Math.sign=function(t){return(t>0)-(0>t)},Math.cmp=function(t,i){return(+t>+i)-(+i>+t)},Math.icmp=function(t,i){return(+i>+t)-(+t>+i)},Stack.prototype.empty=function(){return 0==this.a.length},Stack.prototype.push=function(t){this.a.push(t)},Stack.prototype.pop=function(){return this.empty()?void 0:this.a.pop()},Stack.prototype.top=function(){return this.empty()?void 0:this.array[this.a.length-1]},Stack.prototype.clear=function(){this.a=[]},Stack.prototype.size=function(){return this.a.length},Queue.prototype.push=function(t){this.l.push(t)},Queue.prototype.empty=function(){return this.r.empty()&&this.l.empty()},Queue.prototype.pop=function(){if(this.r.empty())for(;!this.l.empty();)this.r.push(this.l.pop());return this.r.empty()?void 0:this.r.pop()},Queue.prototype.front=function(){if(this.r.empty())for(;!this.l.empty();)this.r.push(this.l.pop());return this.r.empty()?void 0:this.r.top()},Queue.prototype.size=function(){return l.size()+r.size()},Queue.prototype.clear=function(){l.clear(),r.clear()},Reader.prototype.next=function(){return this.c==this.b.length&&(this.c=0,this.b=readline().split(" ")),this.b[this.c++]},Writer.prototype.print=function(t){this.l[this.c]+=t},Writer.prototype.println=function(t){this.l[this.c]+=t,this.l.push(""),++this.c},Writer.prototype.flush=function(){print(this.l.join("\n")),this.l=[]};

function main(cin, cout)
{
    var n = +cin.next();
    var t = Array(n);
    for(var i = 0; i < n; ++i)
        t[i] = +cin.next();
    t.sort(Math.cmp);
    var ans = 0;
    var time = 0;
    for(var i = 0; i < n; ++i)
    {
        if (t[i] >= time)
        {
            time += t[i];
            ++ans;
        }
    }
    cout.print(ans);
}

var cin = new Reader();
var cout = new Writer();

main(cin, cout);

cout.flush();

var n = parseInt(readline());
var t = readline().split(" ").map(Number);
t.sort(function(a,b){return a-b;});
var tt=0, dd = 0;

for(var i=0; i<n; i++)
{
  if(t[i]>=tt)
  {
    tt+=t[i];
    dd++;
  }
}

print(dd);

function ProblemSolver() {
    this.HAS_TEST_CASES = false;
    this.INPUT_FILE_NAME = "test.in";
    this.OUTPUT_FILE_NAME = "out.txt";
    this.DO_OUTPUT_TO_FILE = false;
    this.CLEAR_ARRAY_PER_CASE = false;

    this.solveCase = function() {
        var res , i , a ;
        res = 0 ;
        a = 0 ;
        this.arr = this.arr.sort( function( left , right ) { return left - right ; } ) ;
        for( i = 0 ; i < this.n ; i++ ) {
        	if( i == 0 || this.arr[ i ] >= a ) {
        		a += this.arr[ i ] ;
        		res++ ;
        	}
        }
        print( res );
    };

    this.init = function() {
        this.lim1 = 100010;
        this.lim2 = 110;
        this.cc = 1;
        this.ind = 1;
        this.n = 0;
        this.cn = 0;
        this.declareAndFillArrays();
    };

    this.getInput = function( irObj ) {
        var hasMoreInput , i;
        hasMoreInput = true;
        try {
            this.n = irObj.nextInt();
            this.arr = [] ;
            for( i = 0 ; i < this.n ; i++ ) {
                this.arr.push( irObj.nextInt() ) ;
            }
        }
        catch( ex ) {
            hasMoreInput = false;
        }
        return hasMoreInput;
    };

    this.clearArraysPerCase = function() {
        var i;
        this.arr = new Array();
        this.adj_list = new Array();
        for( i = 0 ; i < this.lim1 ; i++ ) {
            this.arr.push( 0 );
            this.adj_list.push( new Array() );
        }
    };

    this.clearPerCase = function() {
        this.cn = 0;
        this.cc++;
        if( this.CLEAR_ARRAY_PER_CASE == true ) {
            this.clearArraysPerCase() ;
        }
    };

    this.declareAndFillArrays = function() {
        var i , j;
        this.srr = new Array();
        this.vis = new Array();
        this.arr = new Array();
        this.brr = new Array();
        this.memo = new Array();
        this.done = new Array();
        this.adj_list = new Array();
        for( i = 0 ; i < this.lim1 ; i++ ) {
            this.srr.push( "" );
            this.vis.push( 0 );
            this.arr.push( 0 );
            this.brr.push( 0 );
            this.adj_list.push( new Array() );
        }
        for( i = 0 ; i < this.lim2 ; i++ ) {
            this.memo.push( new Array() );
            this.done.push( new Array() );
            for( j = 0 ; j < this.lim2 ; j++ ) {
                this.memo[ i ].push( -1 );
                this.done[ i ].push( 0 );
            }
        }
    };

    this.init();
}

function InputReader() {
    var self = this ;
    this.allLines = new Array();
    this.currrentLineNumber = 0;
    this.currrentCharacterIndex = 0;
    this.callBackFunction = null ;
    this.parentContext = null ;

    this.readAllLines = function() {
        var singleLine;
        while( true ) {
            try {
                singleLine = readline();
                if( singleLine == null ) {
                    break;
                }
            }
            catch( ex ) {
                break;
            }
            this.allLines.push( singleLine );
        }
    };

    this.readAllLinesFromRhino = function() {
        var brObj , line ;
        importPackage( java.io ) ;
        importPackage( java.lang ) ;
        brObj = new BufferedReader( new InputStreamReader( System[ 'in' ] ) ) ;
        this.allLines = [] ;
        while( true ) {
            line = brObj.readLine() ;
            if( line == null ) {
                break;
            }
            this.allLines.push( line ) ;
        }
    };

    this.readSingleLinesFromNodeJsJudgeServer = function( chunk ) {
        self.chunkData += chunk ;
    };

    this.readEndFromNodeJsJudgeServer = function() {
        self.parseRawData( self.chunkData ) ;
        self.parentContext.runCases() ;
    };

    this.readAllLinesFromNodeJsJudgeServer = function( parentContext ) {
        this.parentContext = parentContext ;
        process.stdin.resume() ;
        process.stdin.setEncoding( 'utf8' ) ;
        this.chunkData = '' ;
        process.stdin.on( 'data' , this.readSingleLinesFromNodeJsJudgeServer ) ;
        process.stdin.on( 'end' , this.readEndFromNodeJsJudgeServer ) ;
    };

    this.parseRawData = function( data ) {
        var len , i , currentString;
        len = data.length;
        currentString = "";
        this.allLines = [] ;
        for( i = 0 ; i < len ; i++ ) {
            if( data[ i ] == '\r' ) {
            }
            else if( data[ i ] == '\n' ) {
                this.allLines.push( currentString );
                currentString = "";
            }
            else {
                currentString += data[ i ];
            }
        }
        if( currentString != "" ) {
            this.allLines.push( currentString );
        }
    };

    this.readAllLinesFromFile = function( inputFileName ) {
        var currentDirectory , fsObj , inputFilePath , rawData;
        fsObj = require( 'fs' );
        currentDirectory = __dirname;
        inputFilePath = currentDirectory + "\\" + inputFileName;
        rawData = fsObj.readFileSync( inputFilePath , "utf8" );
        this.parseRawData( rawData );
    };

    this.next = function( flag ) {
        var len , i , startIdx , res , endIdx;
        if( flag == 0 ) {
            if( this.currrentCharacterIndex != 0 ) {
                this.currrentLineNumber++;
                this.currrentCharacterIndex = 0;
            }
            res = "";
            len = this.allLines[ this.currrentLineNumber ].length;
            if( typeof( len ) == 'function' ) {
                len = this.allLines[ this.currrentLineNumber ].length() ;
            }
            for( i = this.currrentCharacterIndex ; i < len ; i++ ) {
                res += '' + this.allLines[ this.currrentLineNumber ].charAt( i ) ;
            }
            this.currrentLineNumber++;
            this.currrentCharacterIndex = 0;
            return res;
        }
        while( true ) {
            if( this.currrentLineNumber >= this.allLines.length ) {
                throw new Error( "No more tokens available!" );
            }
            startIdx = -1;
            len = this.allLines[ this.currrentLineNumber ].length;
            if( typeof( len ) == 'function' ) {
                len = this.allLines[ this.currrentLineNumber ].length() ;
            }
            for( i = this.currrentCharacterIndex ; i < len ; i++ ) {
                if( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) != ' '.charCodeAt( 0 ) ) {
                    startIdx = i;
                    break;
                }
            }
            if( startIdx == -1 ) {
                this.currrentLineNumber++;
                this.currrentCharacterIndex = 0;
                continue;
            }
            res = "";
            endIdx = len - 1 ;
            for( i = startIdx ; i < len ; i++ ) {
                if( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) == ' '.charCodeAt( 0 ) ) {
                    endIdx = i;
                    break;
                }
                if( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) >= 48 && this.allLines[ this.currrentLineNumber ].charCodeAt( i ) <= 57 ) {
                    res += '' + ( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) - 48 ) ;
                }
                else {
                    res += '' + this.allLines[ this.currrentLineNumber ].charAt( i );
                }
            }
            this.currrentCharacterIndex = endIdx;
            if( endIdx == len - 1 ) {
                this.currrentLineNumber++;
                this.currrentCharacterIndex = 0;
            }
            return res;
        }
    };

    this.nextInt = function() {
        return parseInt( this.next( 1 ) );
    };

    this.nextDouble = function() {
        return parseFloat( this.next( 1 ) );
    };

    this.nextString = function() {
        return this.next( 1 );
    };

    this.nextLine = function() {
        return this.next( 0 );
    };
}

function FileOutputHandler() {
    this.resultantStringArray = new Array();

    this.addNewLine = function( newString ) {
        this.resultantStringArray.push( newString );
    };

    this.clearPercase = function() {
        this.resultantStringArray = new Array();
    };

    this.flushOutOutputToFile = function( outputFileName ) {
        var i , sz , res , currentDirectory , fsObj , outputFilePath;
        res = "";
        sz = this.resultantStringArray.length;
        for( i = 0 ; i < sz ; i++ ) {
            if( i != 0 ) {
                res += "\n";
            }
            res += this.resultantStringArray[ i ];
        }
        fsObj = require( 'fs' );
        currentDirectory = __dirname;
        outputFilePath = currentDirectory + "\\" + outputFileName;
        fsObj.writeFileSync( outputFilePath , res );
        this.clearPercase();
    };
}

function CodeExecutioner() {
    this.irObj = new InputReader();
    this.psObj = new ProblemSolver();
    this.fohObj = new FileOutputHandler();

    this.runCases = function() {
        if( this.psObj.HAS_TEST_CASES == true ) {
            testCases = this.irObj.nextInt();
            for( i = 0 ; i < testCases ; i++ ) {
                this.psObj.clearPerCase();
                this.psObj.getInput( this.irObj );
                this.psObj.solveCase();
            }
        }
        else {
            while( true ) {
                this.psObj.clearPerCase();
                hasMoreTestCases = this.psObj.getInput( this.irObj );
                if( hasMoreTestCases == false ) {
                    break;
                }
                this.psObj.solveCase();
            }
        }
        if( this.psObj.DO_OUTPUT_TO_FILE == true ) {
            this.fohObj.flushOutOutputToFile( this.psObj.OUTPUT_FILE_NAME );
        }
    };

    this.detectEnvironmentType = function() {
        var environmentType = null ;
        try {
            if( importPackage != null ) {
                environmentType = 'rhino' ;
            }
        }
        catch( ex1 ) {
            try {
                //for nodejs local server check
                if( __dirname != null && readline != null && typeof( readline ) != 'function' ) {
                    environmentType = 'local-node-js' ;
                }
            }
            catch( ex2 ) {
                try {
                    if( readline == null || typeof( readline ) != 'function' ) {
                        environmentType = 'server-node-js' ;
                    }
                    else {
                        try {
                            if( Map != null ) {
                                environmentType = 'spider-monkey' ;
                            }
                            else {
                                environmentType = 'javascript-v8' ;
                            }
                        }
                        catch( ex3 ) {
                            environmentType = 'javascript-v8' ;
                        }
                    }
                }
                catch( ex3 ) {
                    environmentType = 'server-node-js' ;
                }
            }
        }
        return environmentType ;
    };

    this.configureStreamsAndReadInput = function() {
        var testCases , i , hasMoreTestCases , isLocal , localContext , isNodeJsJudgeServer , environmentType ;
        isNodeJsJudgeServer = false ;
        environmentType = this.detectEnvironmentType() ;
        if( environmentType == 'local-node-js' ) {
            try {
                if( print == null || typeof( print ) != 'function' ) {
                    print = console.log;
                }
            }
            catch( ex ) {
                print = console.log;
            }
            if( this.psObj.DO_OUTPUT_TO_FILE == true ) {
                localContext = this.fohObj;
                print = function() {
                    localContext.addNewLine.apply( localContext , arguments );
                }
            }
            this.irObj.readAllLinesFromFile( this.psObj.INPUT_FILE_NAME );
            this.runCases() ;
        }
        else if( environmentType == 'server-node-js' ) {
            try {
                if( print == null || typeof( print ) != 'function' ) {
                    print = console.log;
                }
            }
            catch( ex ) {
                print = console.log;
            }
            this.irObj.readAllLinesFromNodeJsJudgeServer( this ) ;
        }
        else if( environmentType == 'javascript-v8' ) {
            this.irObj.readAllLines();
            this.runCases() ;
        }
        else if( environmentType == 'rhino' ) {
            this.irObj.readAllLinesFromRhino();
            this.runCases() ;
        }
        else if( environmentType == 'spider-monkey' ) {
            this.irObj.readAllLines();
            this.runCases() ;
        }
    };

    this.configureStreamsAndReadInput();
}

new CodeExecutioner();

function toi(x){return parseInt(x);}
var n=+readline();
var t=readline().split(" ").map(toi);
var wT=0;
var res=0;
t.sort(function(a,b){return a-b;});
for(var i=0;i<n;i++){
    if(wT<=t[i]){
	wT+=t[i];
	res++;
    }
}
print(res);

var n = parseInt(readline(), 10);
var line = readline().split(' ');
var a = line.map(Number);
a.sort(function(x, y) {
	return x - y;
})

var sum = 0;
var ans = 0;

for (var i = 0; i < n; i++) {
	if (sum <= a[i]) {
		sum += a[i];
		ans ++;
	}
}

print(ans);

function QuickSort(A)
{
    if (A.length == 0) return [];
    var a = [], b = [], p = A[0];
    for (var i = 1; i < A.length; i++)
     { if (A[ i ] < p) a[a.length] = A[ i ];
       else b[b.length] = A[ i ];
     }
    return QuickSort(a).concat( p,QuickSort(b) );
}
// main

var n = parseInt(readline());
var t = readline().split(" ").map(Number);
var rrr = QuickSort(t);
var tt=0, dd = 0;

for(var i=0; i<n; i++);
{
  if(rrr[i]>=tt)
  {
    tt+=rrr[i];
    dd++;
  }
}

print(rrr);

function QuickSort(A)
{
    if (A.length == 0) return [];
    var a = [], b = [], p = A[0];
    for (var i = 1; i < A.length; i++)
     { if (A[ i ] < p) a[a.length] = A[ i ];
       else b[b.length] = A[ i ];
     }
    return QuickSort(a).concat( p,QuickSort(b) );
}
// main

var n = parseInt(readline());
var t = readline().split(" ").map(Number);
var rrr = QuickSort(t);
var tt=0, dd = 0;

for(var i=0; i<n; i++);
{
  if(rrr[i]>=tt)
  {
    tt+=rrr[i];
    dd++;
  }
}

print(dd);

var n = parseInt(readline(), 10);
var line = readline().split(' ');
var a = line.map(Number);
a.sort(function(x, y) {
	return x - y;
})

var sum = 0;
var ans = 0;

for (var i = 0; i < n; i++) {
	if (sum < a[i]) {
		sum += a[i];
		ans ++;
	}
}

print(ans);


function solve() {
   var s = read();
   var c = {
      P: 0,
      S: 0,
      R: 0
   }
   for (var i = 0; i < s.length; i++) {
      c[s[i]]++;
   }
   if (c.P > c.S) {
      if (c.P > c.R) {
         write('S'.repeat(s.length));
      } else {
         write('P'.repeat(s.length))
      }
   } else {
      if (c.S > c.R) {
         write('R'.repeat(s.length));
      } else {
         write('P'.repeat(s.length))
      }
   }
}

function init() {
   var T;
   T = 1;
   T = Number(read());
   for (var t = 0; t < T; t++) {
      solve();
   }
}

function readArray(mapF) {
   return read().split(' ').map(mapF);
}

function sortF(a, b) {
   if (a < b) {
      return -1;
   }
   if (a > b) {
      return 1;
   }
   return 0;
}

var isNode = typeof console !== 'undefined';
var MEMORY = [];
var MEMORY_INDEX = 0;
if (isNode) {
   var fs = require('fs');
   var path = require('path');

   var inTextName;
   var outTextName;
   if (process.argv.length === 5) {
      inTextName = process.argv[3];
      outTextName = process.argv[4];
   }

   if (inTextName) {
      fs.readFile(path.join(__dirname, inTextName), 'utf8', (err, data) => {
         MEMORY = data.split('\r\n');
         init();
      });
   } else {
      var RL = require('readline').createInterface({
         input : process.stdin,
         output : process.stdout
      });

      RL.on('line', (line) => {
         MEMORY.push(line);
      });

      RL.on('close', init);
   }
} else {
   init();
}

function write(value) {
   isNode ? console.log(value) : print(value);
}
function read() {
   return isNode ? MEMORY[MEMORY_INDEX++] : readline();
}

process.stdin.resume();
process.stdin.setEncoding('utf-8');

let inputString = '';
let currentLine = 0;

process.stdin.on('data', inputStdin => {
    inputString += inputStdin;
});

process.stdin.on('end', _ => {
    inputString = inputString.trim().split('\n').map(string => {
        return string.trim();
    });

    B();
});

function readline() {
    return inputString[currentLine++];
}

function pi(a) {
    return parseInt(a);
}

function ti(a){
    for(let i = 0; i < a.length; i++)
        a[i] = pi(a[i]);

    return a;
}

function A(){
    let t = pi(readline());
    while(t > 0){
        t--;
        let n = pi(readline());
        if(n % 2 === 0){
            console.log('YES');
        }else{
            console.log('NO');
        }
    }
}

function B(){
    let t = pi(readline());
    while(t > 0){
        t--;
        let s = readline().split('');
        let map = new Array(3);
        map.fill(0);
        for(let i = 0; i < s.length; i++){
            if(s[i] === 'R'){
                map[0] += 1;
            }else if(s[i] === 'S'){
                map[1] += 1;
            }else{
                map[2] += 1;
            }
        }

        let max = Math.max(map[0], map[1], map[2]);
        let c = max === map[0] ? 'P' : max === map[1] ? 'R' : 'S';
        let res = '';
        for(let i = 0; i < s.length; i++){
            res += c;
        }
        console.log(res);
    }
}

function solve() {
   var s = read();
   var c = {
      P: 0,
      S: 0,
      R: 0
   }
   for (var i = 0; i < s.length; i++) {
      c[s[i]]++;
   }
   if (c.P > c.S) {
      if (c.P > c.R) {
         write('S'.repeat(s.length));
      } else {
         write('PPP'.repeat(s.length))
      }
   } else {
      if (c.S > c.R) {
         write('R'.repeat(s.length));
      } else {
         write('P'.repeat(s.length))
      }
   }
}

function init() {
   var T;
   T = 1;
   T = Number(read());
   for (var t = 0; t < T; t++) {
      solve();
   }
}

function readArray(mapF) {
   return read().split(' ').map(mapF);
}

function sortF(a, b) {
   if (a < b) {
      return -1;
   }
   if (a > b) {
      return 1;
   }
   return 0;
}

var isNode = typeof console !== 'undefined';
var MEMORY = [];
var MEMORY_INDEX = 0;
if (isNode) {
   var fs = require('fs');
   var path = require('path');

   var inTextName;
   var outTextName;
   if (process.argv.length === 5) {
      inTextName = process.argv[3];
      outTextName = process.argv[4];
   }

   if (inTextName) {
      fs.readFile(path.join(__dirname, inTextName), 'utf8', (err, data) => {
         MEMORY = data.split('\r\n');
         init();
      });
   } else {
      var RL = require('readline').createInterface({
         input : process.stdin,
         output : process.stdout
      });

      RL.on('line', (line) => {
         MEMORY.push(line);
      });

      RL.on('close', init);
   }
} else {
   init();
}

function write(value) {
   isNode ? console.log(value) : print(value);
}
function read() {
   return isNode ? MEMORY[MEMORY_INDEX++] : readline();
}


'use strict';

process.stdin.resume();
process.stdin.setEncoding('utf-8');

let inputString = '';
let currentLine = 0;

process.stdin.on('data', (inputStdin) => {
  inputString += inputStdin;
});

process.stdin.on('end', (_) => {
  inputString = inputString
    .trim()
    .split('\n')
    .map((string) => {
      return string.trim();
    });

  main();
});

function readline() {
  return inputString[currentLine++];
}

function main() {
  const n = Number(readline());
  const a = readline().split(' ').map(Number);
  helper(n, a);
}

function helper(n, a) {
  let left = 0
  let right = 0
  let cnt = new Map()
  let max = 0

  while (right < n) {
    cnt.set(a[right], (cnt.get(a[right]) || 0) + 1)
    while (cnt.size > 2) {
      cnt.set(a[left], cnt.get(a[left]) - 1)
      if (cnt.get(a[left]) === 0) {
        cnt.delete(a[left])
      }
      left++
    }
    max = Math.max(right - left + 1, max)
    right++
  }

  console.log(max)
}

/*
thought: segment tree + devide and counque
*/
var maxn = 1000100;
var tmax = new Array([maxn*4]);
var tmin = new Array([maxn*4]);
var a = new Array([maxn]);
var n = parseInt(readline());
var x = readline().split(' ');
for(var i=0;i<n;i++) {
    a[i] = parseInt(x[i]);
}

function dfs(l, r, id) {
    if(l == r) {
        tmax[id] = a[l];
        tmin[id] = a[l];
        return;
    }
    var mid = ~~((l+r)/2);
    dfs(l, mid, id*2);
    dfs(mid+1, r, id*2+1);
    tmax[id] = Math.max(tmax[id*2] , tmax[id*2+1]);
    tmin[id] = Math.min(tmin[id*2] , tmin[id*2+1]);
    return;
}
dfs(0, n-1, 1);

function getMax(L, R, l, r, id) {
    if(L <= l && r <= R) return tmax[id];
    var mid = ~~((l+r)/2);
    var t1 = -1;
    var t2 = -1;
    if(mid >= L) t1 = getMax(L, R, l, mid, id*2);
    if(R > mid) t2 = getMax(L, R ,mid+1, r, id*2+1);
    if(t1 == -1) return t2;
    else if(t2 == -1) return t1;
    else return Math.max(t1, t2);
}

function getMin(L, R, l, r, id) {
    if(L <= l && r <= R) return tmin[id];
    var mid = ~~((l+r)/2);
    var t1 = -1;
    var t2 = -1;
    if(mid >= L) t1 = getMin(L, R, l, mid, id*2);
    if(R > mid) t2 = getMin(L, R ,mid+1, r, id*2+1);
    if(t1 == -1) return t2;
    else if(t2 == -1) return t1;
    else return Math.min(t1, t2);
}

// var test = getMax(0, 2, 0, n-1, 1);
// print(test);

function check(L, R) {
    var maxx = getMax(L, R, 0, n-1, 1);
    var minn = getMin(L, R, 0, n-1, 1);
    if(maxx - minn <= 1) return true;
    return false;
}

function get(start) {
    var l = start;
    var r = n-1;
    while(l <= r) {
        var mid = ~~((l+r)/2);
        if(check(start, mid) == true) l = mid+1;
        else r = mid - 1;
    }
    return l - start;
}

// for(var i = 0; i < n; i++) {
//     print(getMax(i,n-1, 0, n-1, 1), ",", getMin(i,n-1, 0, n-1, 1));
// }
// print(getMin(0, n-1, 0, n-1, 1));

var ans = 0;
for(var i = 0; i<n;i ++) {
    var t = get(i);
    if(t > ans) ans = t;
}
print(ans);

// const approximatingRange = (lengthArr, arr) => {
//   const currPoint = { value: arr[0], index: 0 };
//   const nextPoint = { value: arr[0], index: 0 };
//   const minPoint = { value: arr[0], index: 0 };
//   const maxPoint = { value: arr[0], index: 0 };
//   let maxRange = 0;

//   for (let i = 0; i < lengthArr; i++) {
//     if (arr[i] < minPoint.value) {
//       minPoint.value = arr[i];
//       minPoint.index = i;
//     }

//     if (arr[i] > maxPoint.value) {
//       maxPoint.value = arr[i];
//       maxPoint.index = i;
//     }

//     if ((maxPoint.value - minPoint.value) > 1) {
//       const range = i - currPoint.index;
//       if (range > maxRange) {
//         maxRange = range;
//       }
//       currPoint.index = nextPoint.index;
//       currPoint.value = nextPoint.value;

//       minPoint.index = nextPoint.index;
//       minPoint.value = nextPoint.value;

//       maxPoint.index = nextPoint.index;
//       maxPoint.value = nextPoint.value;

//       nextPoint.value = arr[i];
//       nextPoint.index = i;
//     } else if ((maxPoint.value - minPoint.value) === 1) {
//       nextPoint.value = arr[i];
//       nextPoint.index = i;
//     }

//     console.log('i=', i, 'maxRange:=', maxRange, 'currentPoint=', currPoint, 'nextPoint=', nextPoint);

//     if (lengthArr === i + 1) {
//       const range = i - currPoint.index + 1;
//       if (range > maxRange) {
//         maxRange = range;
//       }
//     }
//   }

//   return maxRange;
// }

// console.log(approximatingRange(11, [5, 4, 5, 5, 9, 7, 8, 8, 8, 7, 6]));
//console.log(approximatingRange(5, [1, 2, 3, 3, 2]));
//console.log(approximatingRange(4, [2, 2, 3, 4]));

// const lineReader = require('line-reader');
// lineReader.eachLine('', function(line) {
//   console.log(line);
// });
// var fs = require('fs');
// const readline = require('readline');
// const rl = readline.createInterface({
//   input: process.stdin,
//   output: process.stdout
// });

// rl.question('What do you think of Node.js? ', (answer) => {
//   // TODO: Log the answer in a database
//   console.log(`Thank you for your valuable feedback: ${answer}`);

//   rl.close();
// });

'use strict';

// const fs = require('fs');

process.stdin.resume();
process.stdin.setEncoding('utf-8');

let inputString = '';
let currentLine = 0;

process.stdin.on('data', inputStdin => {
  inputString += inputStdin;
});

process.stdin.on('end', _ => {
  inputString = inputString.trim().split('\n').map(string => {
      return string.trim();
  });

  main();
});

function readLine() {
  return inputString[currentLine++];
}

function approximatingRange(size, arr) {
  /*
   * Write your code here.
   */

  let currPoint = { value: arr[0], index: 0 };
  let nextPoint = { value: arr[0], index: 0 };
  let minPoint = { value: arr[0], index: 0 };
  let maxPoint = { value: arr[0], index: 0 };
  let maxRange = 0;

  for (let i = 0; i < size; i++) {
    // if (i !== 0 && (arr[i] !== arr[i - 1]) && (arr[i] === minPoint.value) && (arr[i] === minPoint.value)) {
    //   nextPoint = { value: arr[i], index: i }
    // }
    // if (arr[i] < minPoint.value) {
    //   minPoint = { value: arr[i], index: i };
    // }

    // if (arr[i] > maxPoint.value) {
    //   maxPoint = { value: arr[i], index: i };
    // }

    if (Math.abs(arr[i] - arr[i-1]) > 1) {
      const range = i - currPoint.index;
      maxRange = Math.max(maxRange, range);
      currPoint = { value: arr[i], index: i };
      nextPoint = { value: arr[i], index: i };
      minPoint = { value: arr[i], index: i };
      maxPoint = { value: arr[i], index: i };
    } else if (Math.abs(arr[i] - arr[i-1]) === 1) {
      if ((Math.abs(arr[i] - maxPoint.value) > 1) ||
        (Math.abs(arr[i] - minPoint.value) > 1)
      ) {
        const range = i - currPoint.index;
        maxRange = Math.max(maxRange, range);
        currPoint.value = nextPoint.value;
        currPoint.index = nextPoint.index;

        if (arr[i] > nextPoint.value) {
          minPoint = { value: nextPoint.value, index: nextPoint.index };
          maxPoint = { value: arr[i], index: i };
        }
        if (arr[i] < nextPoint.value) {
          maxPoint = { value: nextPoint.value, index: nextPoint.index };
          minPoint = { value: arr[i], index: i };
        }
        // nextPoint = { value: arr[i], index: i };
      }

      nextPoint = { value: arr[i], index: i }
    }

    // if ((Math.abs(arr[i] - arr[i-1]) > 1) || (maxPoint.value - minPoint.value) > 2) {
    //   const range = i - currPoint.index;
    //   if (range > maxRange) {
    //     maxRange = range;
    //   }
    //   currPoint.index = i;
    //   currPoint.value = arr[i];

    //   minPoint.index = i;
    //   minPoint.value = arr[i]

    //   maxPoint.index = i;
    //   maxPoint.value = arr[i]

    //   nextPoint.value = arr[i];
    //   nextPoint.index = i;
    // } else {
    //   if ((maxPoint.value - minPoint.value) > 1) {
    //     const range = i - currPoint.index;
    //     if (range > maxRange) {
    //       maxRange = range;
    //     }
    //     currPoint.index = nextPoint.index;
    //     currPoint.value = nextPoint.value;

    //     minPoint.index = nextPoint.index;
    //     minPoint.value = nextPoint.value;

    //     maxPoint.index = nextPoint.index;
    //     maxPoint.value = nextPoint.value;

    //     nextPoint.value = arr[i];
    //     nextPoint.index = i;
    //   } else {
    //     if (arr[i] !== arr[i - 1]) {
    //       nextPoint.value = arr[i];
    //       nextPoint.index = i;
    //     }
    //   }
    // }

    // console.log('i=', i, 'maxRange:=', maxRange, 'currentPoint=', currPoint, 'nextPoint=', nextPoint);

    if (size === i + 1) {
      const range = size - currPoint.index;
      if (range > maxRange) {
        maxRange = range;
      }
    }
  }

  return maxRange;

}

function main() {

  const size = parseInt(readLine(), 10);

  const arr = readLine().split(' ').map(bTemp => parseInt(bTemp, 10));

  console.log(approximatingRange(size, arr));
}

// const approximatingRange = (lengthArr, arr) => {
//   const currPoint = { value: arr[0], index: 0 };
//   const nextPoint = { value: arr[0], index: 0 };
//   const minPoint = { value: arr[0], index: 0 };
//   const maxPoint = { value: arr[0], index: 0 };
//   let maxRange = 0;

//   for (let i = 0; i < lengthArr; i++) {
//     if (arr[i] < minPoint.value) {
//       minPoint.value = arr[i];
//       minPoint.index = i;
//     }

//     if (arr[i] > maxPoint.value) {
//       maxPoint.value = arr[i];
//       maxPoint.index = i;
//     }

//     if ((maxPoint.value - minPoint.value) > 1) {
//       const range = i - currPoint.index;
//       if (range > maxRange) {
//         maxRange = range;
//       }
//       currPoint.index = nextPoint.index;
//       currPoint.value = nextPoint.value;

//       minPoint.index = nextPoint.index;
//       minPoint.value = nextPoint.value;

//       maxPoint.index = nextPoint.index;
//       maxPoint.value = nextPoint.value;

//       nextPoint.value = arr[i];
//       nextPoint.index = i;
//     } else if ((maxPoint.value - minPoint.value) === 1) {
//       nextPoint.value = arr[i];
//       nextPoint.index = i;
//     }

//     console.log('i=', i, 'maxRange:=', maxRange, 'currentPoint=', currPoint, 'nextPoint=', nextPoint);

//     if (lengthArr === i + 1) {
//       const range = i - currPoint.index + 1;
//       if (range > maxRange) {
//         maxRange = range;
//       }
//     }
//   }

//   return maxRange;
// }

// console.log(approximatingRange(11, [5, 4, 5, 5, 9, 7, 8, 8, 8, 7, 6]));
//console.log(approximatingRange(5, [1, 2, 3, 3, 2]));
//console.log(approximatingRange(4, [2, 2, 3, 4]));

// const lineReader = require('line-reader');
// lineReader.eachLine('', function(line) {
//   console.log(line);
// });
// var fs = require('fs');
// const readline = require('readline');
// const rl = readline.createInterface({
//   input: process.stdin,
//   output: process.stdout
// });

// rl.question('What do you think of Node.js? ', (answer) => {
//   // TODO: Log the answer in a database
//   console.log(`Thank you for your valuable feedback: ${answer}`);

//   rl.close();
// });

'use strict';

// const fs = require('fs');

process.stdin.resume();
process.stdin.setEncoding('utf-8');

let inputString = '';
let currentLine = 0;

process.stdin.on('data', inputStdin => {
  inputString += inputStdin;
});

process.stdin.on('end', _ => {
  inputString = inputString.trim().split('\n').map(string => {
      return string.trim();
  });

  main();
});

function readLine() {
  return inputString[currentLine++];
}

function approximatingRange(size, arr) {
  /*
   * Write your code here.
   */

  const currPoint = { value: arr[0], index: 0 };
  const nextPoint = { value: arr[0], index: 0 };
  const minPoint = { value: arr[0], index: 0 };
  const maxPoint = { value: arr[0], index: 0 };
  let maxRange = 0;

  for (let i = 0; i < size; i++) {
    if (arr[i] < minPoint.value) {
      minPoint.value = arr[i];
      minPoint.index = i;
    }

    if (arr[i] > maxPoint.value) {
      maxPoint.value = arr[i];
      maxPoint.index = i;
    }

    if ((Math.abs(arr[i] - arr[i-1]) > 1) || (maxPoint.value - minPoint.value) > 2) {
      const range = i - currPoint.index;
      if (range > maxRange) {
        maxRange = range;
      }
      currPoint.index = i;
      currPoint.value = arr[i];

      minPoint.index = i;
      minPoint.value = arr[i]

      maxPoint.index = i;
      maxPoint.value = arr[i]

      nextPoint.value = arr[i];
      nextPoint.index = i;
    } else {
      if ((maxPoint.value - minPoint.value) > 1) {
        const range = i - currPoint.index;
        if (range > maxRange) {
          maxRange = range;
        }
        currPoint.index = nextPoint.index;
        currPoint.value = nextPoint.value;

        minPoint.index = nextPoint.index;
        minPoint.value = nextPoint.value;

        maxPoint.index = nextPoint.index;
        maxPoint.value = nextPoint.value;

        nextPoint.value = arr[i];
        nextPoint.index = i;
      } else {
        if (arr[i] !== arr[i - 1]) {
          nextPoint.value = arr[i];
          nextPoint.index = i;
        }
      }
    }

    console.log('i=', i, 'maxRange:=', maxRange, 'currentPoint=', currPoint, 'nextPoint=', nextPoint);

    if (size === i + 1) {
      const range = size - currPoint.index;
      if (range > maxRange) {
        maxRange = range;
      }
    }
  }

  return maxRange;

}

function main() {

  const size = parseInt(readLine(), 10);

  const arr = readLine().split(' ').map(bTemp => parseInt(bTemp, 10));

  console.log(approximatingRange(size, arr));
}

// const approximatingRange = (lengthArr, arr) => {
//   const currPoint = { value: arr[0], index: 0 };
//   const nextPoint = { value: arr[0], index: 0 };
//   const minPoint = { value: arr[0], index: 0 };
//   const maxPoint = { value: arr[0], index: 0 };
//   let maxRange = 0;

//   for (let i = 0; i < lengthArr; i++) {
//     if (arr[i] < minPoint.value) {
//       minPoint.value = arr[i];
//       minPoint.index = i;
//     }

//     if (arr[i] > maxPoint.value) {
//       maxPoint.value = arr[i];
//       maxPoint.index = i;
//     }

//     if ((maxPoint.value - minPoint.value) > 1) {
//       const range = i - currPoint.index;
//       if (range > maxRange) {
//         maxRange = range;
//       }
//       currPoint.index = nextPoint.index;
//       currPoint.value = nextPoint.value;

//       minPoint.index = nextPoint.index;
//       minPoint.value = nextPoint.value;

//       maxPoint.index = nextPoint.index;
//       maxPoint.value = nextPoint.value;

//       nextPoint.value = arr[i];
//       nextPoint.index = i;
//     } else if ((maxPoint.value - minPoint.value) === 1) {
//       nextPoint.value = arr[i];
//       nextPoint.index = i;
//     }

//     console.log('i=', i, 'maxRange:=', maxRange, 'currentPoint=', currPoint, 'nextPoint=', nextPoint);

//     if (lengthArr === i + 1) {
//       const range = i - currPoint.index + 1;
//       if (range > maxRange) {
//         maxRange = range;
//       }
//     }
//   }

//   return maxRange;
// }

// console.log(approximatingRange(11, [5, 4, 5, 5, 9, 7, 8, 8, 8, 7, 6]));
//console.log(approximatingRange(5, [1, 2, 3, 3, 2]));
//console.log(approximatingRange(4, [2, 2, 3, 4]));

// const lineReader = require('line-reader');
// lineReader.eachLine('', function(line) {
//   console.log(line);
// });
// var fs = require('fs');
// const readline = require('readline');
// const rl = readline.createInterface({
//   input: process.stdin,
//   output: process.stdout
// });

// rl.question('What do you think of Node.js? ', (answer) => {
//   // TODO: Log the answer in a database
//   console.log(`Thank you for your valuable feedback: ${answer}`);

//   rl.close();
// });

'use strict';

// const fs = require('fs');

process.stdin.resume();
process.stdin.setEncoding('utf-8');

let inputString = '';
let currentLine = 0;

process.stdin.on('data', inputStdin => {
  inputString += inputStdin;
});

process.stdin.on('end', _ => {
  inputString = inputString.trim().split('\n').map(string => {
      return string.trim();
  });

  main();
});

function readLine() {
  return inputString[currentLine++];
}

function approximatingRange(size, arr) {
  /*
   * Write your code here.
   */

  const currPoint = { value: arr[0], index: 0 };
  const nextPoint = { value: arr[0], index: 0 };
  const minPoint = { value: arr[0], index: 0 };
  const maxPoint = { value: arr[0], index: 0 };
  let maxRange = 0;

  for (let i = 0; i < size; i++) {
    if (arr[i] < minPoint.value) {
      minPoint.value = arr[i];
      minPoint.index = i;
    }

    if (arr[i] > maxPoint.value) {
      maxPoint.value = arr[i];
      maxPoint.index = i;
    }

    if ((maxPoint.value - minPoint.value) > 2) {
      const range = i - currPoint.index;
      if (range > maxRange) {
        maxRange = range;
      }
      currPoint.index = i;
      currPoint.value = arr[i];

      minPoint.index = i;
      minPoint.value = arr[i];

      maxPoint.index = i;
      maxPoint.value = arr[i];

      nextPoint.value = arr[i];
      nextPoint.index = i;
    } else if ((maxPoint.value - minPoint.value) > 1) {
      const range = i - currPoint.index;
      if (range > maxRange) {
        maxRange = range;
      }
      currPoint.index = nextPoint.index;
      currPoint.value = nextPoint.value;

      minPoint.index = nextPoint.index;
      minPoint.value = nextPoint.value;

      maxPoint.index = nextPoint.index;
      maxPoint.value = nextPoint.value;

      nextPoint.value = arr[i];
      nextPoint.index = i;
    } else {
      if (arr[i] !== arr[i - 1]) {
        nextPoint.value = arr[i];
        nextPoint.index = i;
      }
    }

    // console.log('i=', i, 'maxRange:=', maxRange, 'currentPoint=', currPoint, 'nextPoint=', nextPoint);

    if (size === i + 1) {
      const range = i - currPoint.index + 1;
      if (range > maxRange) {
        maxRange = range;
      }
    }
  }

  return maxRange;

}

function main() {

  const size = parseInt(readLine(), 10);

  const arr = readLine().split(' ').map(bTemp => parseInt(bTemp, 10));

  console.log(approximatingRange(size, arr));
}

// const approximatingRange = (lengthArr, arr) => {
//   const currPoint = { value: arr[0], index: 0 };
//   const nextPoint = { value: arr[0], index: 0 };
//   const minPoint = { value: arr[0], index: 0 };
//   const maxPoint = { value: arr[0], index: 0 };
//   let maxRange = 0;

//   for (let i = 0; i < lengthArr; i++) {
//     if (arr[i] < minPoint.value) {
//       minPoint.value = arr[i];
//       minPoint.index = i;
//     }

//     if (arr[i] > maxPoint.value) {
//       maxPoint.value = arr[i];
//       maxPoint.index = i;
//     }

//     if ((maxPoint.value - minPoint.value) > 1) {
//       const range = i - currPoint.index;
//       if (range > maxRange) {
//         maxRange = range;
//       }
//       currPoint.index = nextPoint.index;
//       currPoint.value = nextPoint.value;

//       minPoint.index = nextPoint.index;
//       minPoint.value = nextPoint.value;

//       maxPoint.index = nextPoint.index;
//       maxPoint.value = nextPoint.value;

//       nextPoint.value = arr[i];
//       nextPoint.index = i;
//     } else if ((maxPoint.value - minPoint.value) === 1) {
//       nextPoint.value = arr[i];
//       nextPoint.index = i;
//     }

//     console.log('i=', i, 'maxRange:=', maxRange, 'currentPoint=', currPoint, 'nextPoint=', nextPoint);

//     if (lengthArr === i + 1) {
//       const range = i - currPoint.index + 1;
//       if (range > maxRange) {
//         maxRange = range;
//       }
//     }
//   }

//   return maxRange;
// }

// console.log(approximatingRange(11, [5, 4, 5, 5, 9, 7, 8, 8, 8, 7, 6]));
//console.log(approximatingRange(5, [1, 2, 3, 3, 2]));
//console.log(approximatingRange(4, [2, 2, 3, 4]));

// const lineReader = require('line-reader');
// lineReader.eachLine('', function(line) {
//   console.log(line);
// });
// var fs = require('fs');
// const readline = require('readline');
// const rl = readline.createInterface({
//   input: process.stdin,
//   output: process.stdout
// });

// rl.question('What do you think of Node.js? ', (answer) => {
//   // TODO: Log the answer in a database
//   console.log(`Thank you for your valuable feedback: ${answer}`);

//   rl.close();
// });

'use strict';

// const fs = require('fs');

process.stdin.resume();
process.stdin.setEncoding('utf-8');

let inputString = '';
let currentLine = 0;

process.stdin.on('data', inputStdin => {
  inputString += inputStdin;
});

process.stdin.on('end', _ => {
  inputString = inputString.trim().split('\n').map(string => {
      return string.trim();
  });

  main();
});

function readLine() {
  return inputString[currentLine++];
}

function approximatingRange(size, arr) {
  /*
   * Write your code here.
   */

  const currPoint = { value: arr[0], index: 0 };
  const nextPoint = { value: arr[0], index: 0 };
  const minPoint = { value: arr[0], index: 0 };
  const maxPoint = { value: arr[0], index: 0 };
  let maxRange = 0;

  for (let i = 0; i < size; i++) {
    if (arr[i] < minPoint.value) {
      minPoint.value = arr[i];
      minPoint.index = i;
    }

    if (arr[i] > maxPoint.value) {
      maxPoint.value = arr[i];
      maxPoint.index = i;
    }

    if ((maxPoint.value - minPoint.value) > 1) {
      const range = i - currPoint.index;
      if (range > maxRange) {
        maxRange = range;
      }
      currPoint.index = nextPoint.index;
      currPoint.value = nextPoint.value;

      minPoint.index = nextPoint.index;
      minPoint.value = nextPoint.value;

      maxPoint.index = nextPoint.index;
      maxPoint.value = nextPoint.value;

      nextPoint.value = arr[i];
      nextPoint.index = i;
    } else if (((maxPoint.value - minPoint.value)) === 1 && (arr[i] !== arr[i - 1])) {
      nextPoint.value = arr[i];
      nextPoint.index = i;
    }

    // console.log('i=', i, 'maxRange:=', maxRange, 'currentPoint=', currPoint, 'nextPoint=', nextPoint);

    if (size === i + 1) {
      const range = i - currPoint.index + 1;
      if (range > maxRange) {
        maxRange = range;
      }
    }
  }

  return maxRange;

}

function main() {

  const size = parseInt(readLine(), 10);

  const arr = readLine().split(' ').map(bTemp => parseInt(bTemp, 10));

  console.log(approximatingRange(size, arr));
}

// const approximatingRange = (lengthArr, arr) => {
//   const currPoint = { value: arr[0], index: 0 };
//   const nextPoint = { value: arr[0], index: 0 };
//   const minPoint = { value: arr[0], index: 0 };
//   const maxPoint = { value: arr[0], index: 0 };
//   let maxRange = 0;

//   for (let i = 0; i < lengthArr; i++) {
//     if (arr[i] < minPoint.value) {
//       minPoint.value = arr[i];
//       minPoint.index = i;
//     }

//     if (arr[i] > maxPoint.value) {
//       maxPoint.value = arr[i];
//       maxPoint.index = i;
//     }

//     if ((maxPoint.value - minPoint.value) > 1) {
//       const range = i - currPoint.index;
//       if (range > maxRange) {
//         maxRange = range;
//       }
//       currPoint.index = nextPoint.index;
//       currPoint.value = nextPoint.value;

//       minPoint.index = nextPoint.index;
//       minPoint.value = nextPoint.value;

//       maxPoint.index = nextPoint.index;
//       maxPoint.value = nextPoint.value;

//       nextPoint.value = arr[i];
//       nextPoint.index = i;
//     } else if ((maxPoint.value - minPoint.value) === 1) {
//       nextPoint.value = arr[i];
//       nextPoint.index = i;
//     }

//     console.log('i=', i, 'maxRange:=', maxRange, 'currentPoint=', currPoint, 'nextPoint=', nextPoint);

//     if (lengthArr === i + 1) {
//       const range = i - currPoint.index + 1;
//       if (range > maxRange) {
//         maxRange = range;
//       }
//     }
//   }

//   return maxRange;
// }

// console.log(approximatingRange(11, [5, 4, 5, 5, 9, 7, 8, 8, 8, 7, 6]));
//console.log(approximatingRange(5, [1, 2, 3, 3, 2]));
//console.log(approximatingRange(4, [2, 2, 3, 4]));

// const lineReader = require('line-reader');
// lineReader.eachLine('', function(line) {
//   console.log(line);
// });
// var fs = require('fs');
// const readline = require('readline');
// const rl = readline.createInterface({
//   input: process.stdin,
//   output: process.stdout
// });

// rl.question('What do you think of Node.js? ', (answer) => {
//   // TODO: Log the answer in a database
//   console.log(`Thank you for your valuable feedback: ${answer}`);

//   rl.close();
// });

'use strict';

// const fs = require('fs');

process.stdin.resume();
process.stdin.setEncoding('utf-8');

let inputString = '';
let currentLine = 0;

process.stdin.on('data', inputStdin => {
  inputString += inputStdin;
});

process.stdin.on('end', _ => {
  inputString = inputString.trim().split('\n').map(string => {
      return string.trim();
  });

  main();
});

function readLine() {
  return inputString[currentLine++];
}

function approximatingRange(size, arr) {
  /*
   * Write your code here.
   */

  const currPoint = { value: arr[0], index: 0 };
  const nextPoint = { value: arr[0], index: 0 };
  const minPoint = { value: arr[0], index: 0 };
  const maxPoint = { value: arr[0], index: 0 };
  let maxRange = 0;

  for (let i = 0; i < size; i++) {
    if (arr[i] < minPoint.value) {
      minPoint.value = arr[i];
      minPoint.index = i;
    }

    if (arr[i] > maxPoint.value) {
      maxPoint.value = arr[i];
      maxPoint.index = i;
    }

    if ((maxPoint.value - minPoint.value) > 1) {
      const range = i - currPoint.index;
      if (range > maxRange) {
        maxRange = range;
      }
      currPoint.index = nextPoint.index;
      currPoint.value = nextPoint.value;

      minPoint.index = nextPoint.index;
      minPoint.value = nextPoint.value;

      maxPoint.index = nextPoint.index;
      maxPoint.value = nextPoint.value;

      nextPoint.value = arr[i];
      nextPoint.index = i;
    } else if ((maxPoint.value - minPoint.value) === 1) {
      nextPoint.value = arr[i];
      nextPoint.index = i;
    }

    if (size === i + 1) {
      const range = i - currPoint.index + 1;
      if (range > maxRange) {
        maxRange = range;
      }
    }
  }

  return maxRange;

}

function main() {

  const size = parseInt(readLine(), 10);

  const arr = readLine().split(' ').map(bTemp => parseInt(bTemp, 10));

  console.log(approximatingRange(size, arr));
}

// const approximatingRange = (lengthArr, arr) => {
//   const currPoint = { value: arr[0], index: 0 };
//   const nextPoint = { value: arr[0], index: 0 };
//   const minPoint = { value: arr[0], index: 0 };
//   const maxPoint = { value: arr[0], index: 0 };
//   let maxRange = 0;

//   for (let i = 0; i < lengthArr; i++) {
//     if (arr[i] < minPoint.value) {
//       minPoint.value = arr[i];
//       minPoint.index = i;
//     }

//     if (arr[i] > maxPoint.value) {
//       maxPoint.value = arr[i];
//       maxPoint.index = i;
//     }

//     if ((maxPoint.value - minPoint.value) > 1) {
//       const range = i - currPoint.index;
//       if (range > maxRange) {
//         maxRange = range;
//       }
//       currPoint.index = nextPoint.index;
//       currPoint.value = nextPoint.value;

//       minPoint.index = nextPoint.index;
//       minPoint.value = nextPoint.value;

//       maxPoint.index = nextPoint.index;
//       maxPoint.value = nextPoint.value;

//       nextPoint.value = arr[i];
//       nextPoint.index = i;
//     } else if ((maxPoint.value - minPoint.value) === 1) {
//       nextPoint.value = arr[i];
//       nextPoint.index = i;
//     }

//     console.log('i=', i, 'maxRange:=', maxRange, 'currentPoint=', currPoint, 'nextPoint=', nextPoint);

//     if (lengthArr === i + 1) {
//       const range = i - currPoint.index + 1;
//       if (range > maxRange) {
//         maxRange = range;
//       }
//     }
//   }

//   return maxRange;
// }

// console.log(approximatingRange(11, [5, 4, 5, 5, 9, 7, 8, 8, 8, 7, 6]));
//console.log(approximatingRange(5, [1, 2, 3, 3, 2]));
//console.log(approximatingRange(4, [2, 2, 3, 4]));

// const lineReader = require('line-reader');
// lineReader.eachLine('', function(line) {
//   console.log(line);
// });
// var fs = require('fs');
// const readline = require('readline');
// const rl = readline.createInterface({
//   input: process.stdin,
//   output: process.stdout
// });

// rl.question('What do you think of Node.js? ', (answer) => {
//   // TODO: Log the answer in a database
//   console.log(`Thank you for your valuable feedback: ${answer}`);

//   rl.close();
// });

'use strict';

// const fs = require('fs');

process.stdin.resume();
process.stdin.setEncoding('utf-8');

let inputString = '';
let currentLine = 0;

process.stdin.on('data', inputStdin => {
  inputString += inputStdin;
});

process.stdin.on('end', _ => {
  inputString = inputString.trim().split('\n').map(string => {
      return string.trim();
  });

  main();
});

function readLine() {
  return inputString[currentLine++];
}

function approximatingRange(size, arr) {
  /*
   * Write your code here.
   */

  const currPoint = { value: arr[0], index: 0 };
  const nextPoint = { value: arr[0], index: 0 };
  const minPoint = { value: arr[0], index: 0 };
  const maxPoint = { value: arr[0], index: 0 };
  let maxRange = 0;

  for (let i = 0; i < size; i++) {
    if (arr[i] < minPoint.value) {
      minPoint.value = arr[i];
      minPoint.index = i;
    }

    if (arr[i] > maxPoint.value) {
      maxPoint.value = arr[i];
      maxPoint.index = i;
    }

    if ((maxPoint.value - minPoint.value) > 1) {
      const range = i - currPoint.index;
      if (range > maxRange) {
        maxRange = range;
      }
      currPoint.index = nextPoint.index;
      currPoint.value = nextPoint.value;

      minPoint.index = nextPoint.index;
      minPoint.value = nextPoint.value;

      maxPoint.index = nextPoint.index;
      maxPoint.value = nextPoint.value;

      nextPoint.value = arr[i];
      nextPoint.index = i;
    } else if (((maxPoint.value - minPoint.value)) === 1 && (arr[i] !== arr[i - 1])) {
      nextPoint.value = arr[i];
      nextPoint.index = i;
    }

    console.log('i=', i, 'maxRange:=', maxRange, 'currentPoint=', currPoint, 'nextPoint=', nextPoint);

    if (size === i + 1) {
      const range = i - currPoint.index + 1;
      if (range > maxRange) {
        maxRange = range;
      }
    }
  }

  return maxRange;

}

function main() {

  const size = parseInt(readLine(), 10);

  const arr = readLine().split(' ').map(bTemp => parseInt(bTemp, 10));

  console.log(approximatingRange(size, arr));
}

// const approximatingRange = (lengthArr, arr) => {
//   const currPoint = { value: arr[0], index: 0 };
//   const nextPoint = { value: arr[0], index: 0 };
//   const minPoint = { value: arr[0], index: 0 };
//   const maxPoint = { value: arr[0], index: 0 };
//   let maxRange = 0;

//   for (let i = 0; i < lengthArr; i++) {
//     if (arr[i] < minPoint.value) {
//       minPoint.value = arr[i];
//       minPoint.index = i;
//     }

//     if (arr[i] > maxPoint.value) {
//       maxPoint.value = arr[i];
//       maxPoint.index = i;
//     }

//     if ((maxPoint.value - minPoint.value) > 1) {
//       const range = i - currPoint.index;
//       if (range > maxRange) {
//         maxRange = range;
//       }
//       currPoint.index = nextPoint.index;
//       currPoint.value = nextPoint.value;

//       minPoint.index = nextPoint.index;
//       minPoint.value = nextPoint.value;

//       maxPoint.index = nextPoint.index;
//       maxPoint.value = nextPoint.value;

//       nextPoint.value = arr[i];
//       nextPoint.index = i;
//     } else if ((maxPoint.value - minPoint.value) === 1) {
//       nextPoint.value = arr[i];
//       nextPoint.index = i;
//     }

//     console.log('i=', i, 'maxRange:=', maxRange, 'currentPoint=', currPoint, 'nextPoint=', nextPoint);

//     if (lengthArr === i + 1) {
//       const range = i - currPoint.index + 1;
//       if (range > maxRange) {
//         maxRange = range;
//       }
//     }
//   }

//   return maxRange;
// }

// console.log(approximatingRange(11, [5, 4, 5, 5, 9, 7, 8, 8, 8, 7, 6]));
//console.log(approximatingRange(5, [1, 2, 3, 3, 2]));
//console.log(approximatingRange(4, [2, 2, 3, 4]));

// const lineReader = require('line-reader');
// lineReader.eachLine('', function(line) {
//   console.log(line);
// });
// var fs = require('fs');
// const readline = require('readline');
// const rl = readline.createInterface({
//   input: process.stdin,
//   output: process.stdout
// });

// rl.question('What do you think of Node.js? ', (answer) => {
//   // TODO: Log the answer in a database
//   console.log(`Thank you for your valuable feedback: ${answer}`);

//   rl.close();
// });

'use strict';

// const fs = require('fs');

process.stdin.resume();
process.stdin.setEncoding('utf-8');

let inputString = '';
let currentLine = 0;

process.stdin.on('data', inputStdin => {
  inputString += inputStdin;
});

process.stdin.on('end', _ => {
  inputString = inputString.trim().split('\n').map(string => {
      return string.trim();
  });

  main();
});

function readLine() {
  return inputString[currentLine++];
}

function approximatingRange(size, arr) {
  /*
   * Write your code here.
   */

  const currPoint = { value: arr[0], index: 0 };
  const nextPoint = { value: arr[0], index: 0 };
  const minPoint = { value: arr[0], index: 0 };
  const maxPoint = { value: arr[0], index: 0 };
  let maxRange = 0;

  for (let i = 0; i < size; i++) {
    if (arr[i] < minPoint.value) {
      minPoint.value = arr[i];
      minPoint.index = i;
    }

    if (arr[i] > maxPoint.value) {
      maxPoint.value = arr[i];
      maxPoint.index = i;
    }

    if ((maxPoint.value - minPoint.value) > 1) {
      const range = i - currPoint.index;
      if (range > maxRange) {
        maxRange = range;
      }
      currPoint.index = nextPoint.index;
      currPoint.value = nextPoint.value;

      minPoint.index = nextPoint.index;
      minPoint.value = nextPoint.value;

      maxPoint.index = nextPoint.index;
      maxPoint.value = nextPoint.value;

      nextPoint.value = arr[i];
      nextPoint.index = i;
    } else {
      if (arr[i] !== arr[i - 1]) {
        nextPoint.value = arr[i];
        nextPoint.index = i;
      }
    }

    // console.log('i=', i, 'maxRange:=', maxRange, 'currentPoint=', currPoint, 'nextPoint=', nextPoint);

    if (size === i + 1) {
      const range = i - currPoint.index + 1;
      if (range > maxRange) {
        maxRange = range;
      }
    }
  }

  return maxRange;

}

function main() {

  const size = parseInt(readLine(), 10);

  const arr = readLine().split(' ').map(bTemp => parseInt(bTemp, 10));

  console.log(approximatingRange(size, arr));
}

// const approximatingRange = (lengthArr, arr) => {
//   const currPoint = { value: arr[0], index: 0 };
//   const nextPoint = { value: arr[0], index: 0 };
//   const minPoint = { value: arr[0], index: 0 };
//   const maxPoint = { value: arr[0], index: 0 };
//   let maxRange = 0;

//   for (let i = 0; i < lengthArr; i++) {
//     if (arr[i] < minPoint.value) {
//       minPoint.value = arr[i];
//       minPoint.index = i;
//     }

//     if (arr[i] > maxPoint.value) {
//       maxPoint.value = arr[i];
//       maxPoint.index = i;
//     }

//     if ((maxPoint.value - minPoint.value) > 1) {
//       const range = i - currPoint.index;
//       if (range > maxRange) {
//         maxRange = range;
//       }
//       currPoint.index = nextPoint.index;
//       currPoint.value = nextPoint.value;

//       minPoint.index = nextPoint.index;
//       minPoint.value = nextPoint.value;

//       maxPoint.index = nextPoint.index;
//       maxPoint.value = nextPoint.value;

//       nextPoint.value = arr[i];
//       nextPoint.index = i;
//     } else if ((maxPoint.value - minPoint.value) === 1) {
//       nextPoint.value = arr[i];
//       nextPoint.index = i;
//     }

//     console.log('i=', i, 'maxRange:=', maxRange, 'currentPoint=', currPoint, 'nextPoint=', nextPoint);

//     if (lengthArr === i + 1) {
//       const range = i - currPoint.index + 1;
//       if (range > maxRange) {
//         maxRange = range;
//       }
//     }
//   }

//   return maxRange;
// }

// console.log(approximatingRange(11, [5, 4, 5, 5, 9, 7, 8, 8, 8, 7, 6]));
//console.log(approximatingRange(5, [1, 2, 3, 3, 2]));
//console.log(approximatingRange(4, [2, 2, 3, 4]));

// const lineReader = require('line-reader');
// lineReader.eachLine('', function(line) {
//   console.log(line);
// });
// var fs = require('fs');
// const readline = require('readline');
// const rl = readline.createInterface({
//   input: process.stdin,
//   output: process.stdout
// });

// rl.question('What do you think of Node.js? ', (answer) => {
//   // TODO: Log the answer in a database
//   console.log(`Thank you for your valuable feedback: ${answer}`);

//   rl.close();
// });

'use strict';

// const fs = require('fs');

process.stdin.resume();
process.stdin.setEncoding('utf-8');

let inputString = '';
let currentLine = 0;

process.stdin.on('data', inputStdin => {
  inputString += inputStdin;
});

process.stdin.on('end', _ => {
  inputString = inputString.trim().split('\n').map(string => {
      return string.trim();
  });

  main();
});

function readLine() {
  return inputString[currentLine++];
}

function approximatingRange(size, arr) {
  /*
   * Write your code here.
   */

  let currPoint = { value: arr[0], index: 0 };
  let nextPoint = { value: arr[0], index: 0 };
  let minPoint = { value: arr[0], index: 0 };
  let maxPoint = { value: arr[0], index: 0 };
  let maxRange = 0;

  for (let i = 0; i < size; i++) {
    // if (i !== 0 && (arr[i] !== arr[i - 1]) && (arr[i] === minPoint.value) && (arr[i] === minPoint.value)) {
    //   nextPoint = { value: arr[i], index: i }
    // }
    // if (arr[i] < minPoint.value) {
    //   minPoint = { value: arr[i], index: i };
    // }

    // if (arr[i] > maxPoint.value) {
    //   maxPoint = { value: arr[i], index: i };
    // }

    if (Math.abs(arr[i] - arr[i-1]) > 1) {
      const range = i - currPoint.index;
      maxRange = Math.max(maxRange, range);
      currPoint = { value: arr[i], index: i };
      nextPoint = { value: arr[i], index: i };
      minPoint = { value: arr[i], index: i };
      maxPoint = { value: arr[i], index: i };
    } else if (Math.abs(arr[i] - arr[i-1]) === 1) {
      if ((Math.abs(arr[i] - maxPoint.value) > 1) ||
        (Math.abs(arr[i] - minPoint.value) > 1)
      ) {
        const range = i - currPoint.index;
        maxRange = Math.max(maxRange, range);
        currPoint.value = nextPoint.value;
        currPoint.index = nextPoint.index;

        if (arr[i] > nextPoint.value) {
          minPoint = { value: nextPoint.value, index: nextPoint.index };
          maxPoint = { value: arr[i], index: i };
        }
        if (arr[i] < nextPoint.value) {
          maxPoint = { value: nextPoint.value, index: nextPoint.index };
          minPoint = { value: arr[i], index: i };
        }
        nextPoint = { value: arr[i], index: i };
      }

      nextPoint = { value: arr[i], index: i }
    }

    // if ((Math.abs(arr[i] - arr[i-1]) > 1) || (maxPoint.value - minPoint.value) > 2) {
    //   const range = i - currPoint.index;
    //   if (range > maxRange) {
    //     maxRange = range;
    //   }
    //   currPoint.index = i;
    //   currPoint.value = arr[i];

    //   minPoint.index = i;
    //   minPoint.value = arr[i]

    //   maxPoint.index = i;
    //   maxPoint.value = arr[i]

    //   nextPoint.value = arr[i];
    //   nextPoint.index = i;
    // } else {
    //   if ((maxPoint.value - minPoint.value) > 1) {
    //     const range = i - currPoint.index;
    //     if (range > maxRange) {
    //       maxRange = range;
    //     }
    //     currPoint.index = nextPoint.index;
    //     currPoint.value = nextPoint.value;

    //     minPoint.index = nextPoint.index;
    //     minPoint.value = nextPoint.value;

    //     maxPoint.index = nextPoint.index;
    //     maxPoint.value = nextPoint.value;

    //     nextPoint.value = arr[i];
    //     nextPoint.index = i;
    //   } else {
    //     if (arr[i] !== arr[i - 1]) {
    //       nextPoint.value = arr[i];
    //       nextPoint.index = i;
    //     }
    //   }
    // }

    console.log('i=', i, 'maxRange:=', maxRange, 'currentPoint=', currPoint, 'nextPoint=', nextPoint);

    if (size === i + 1) {
      const range = size - currPoint.index;
      if (range > maxRange) {
        maxRange = range;
      }
    }
  }

  return maxRange;

}

function main() {

  const size = parseInt(readLine(), 10);

  const arr = readLine().split(' ').map(bTemp => parseInt(bTemp, 10));

  console.log(approximatingRange(size, arr));
}

// const approximatingRange = (lengthArr, arr) => {
//   const currPoint = { value: arr[0], index: 0 };
//   const nextPoint = { value: arr[0], index: 0 };
//   const minPoint = { value: arr[0], index: 0 };
//   const maxPoint = { value: arr[0], index: 0 };
//   let maxRange = 0;

//   for (let i = 0; i < lengthArr; i++) {
//     if (arr[i] < minPoint.value) {
//       minPoint.value = arr[i];
//       minPoint.index = i;
//     }

//     if (arr[i] > maxPoint.value) {
//       maxPoint.value = arr[i];
//       maxPoint.index = i;
//     }

//     if ((maxPoint.value - minPoint.value) > 1) {
//       const range = i - currPoint.index;
//       if (range > maxRange) {
//         maxRange = range;
//       }
//       currPoint.index = nextPoint.index;
//       currPoint.value = nextPoint.value;

//       minPoint.index = nextPoint.index;
//       minPoint.value = nextPoint.value;

//       maxPoint.index = nextPoint.index;
//       maxPoint.value = nextPoint.value;

//       nextPoint.value = arr[i];
//       nextPoint.index = i;
//     } else if ((maxPoint.value - minPoint.value) === 1) {
//       nextPoint.value = arr[i];
//       nextPoint.index = i;
//     }

//     console.log('i=', i, 'maxRange:=', maxRange, 'currentPoint=', currPoint, 'nextPoint=', nextPoint);

//     if (lengthArr === i + 1) {
//       const range = i - currPoint.index + 1;
//       if (range > maxRange) {
//         maxRange = range;
//       }
//     }
//   }

//   return maxRange;
// }

// console.log(approximatingRange(11, [5, 4, 5, 5, 9, 7, 8, 8, 8, 7, 6]));
//console.log(approximatingRange(5, [1, 2, 3, 3, 2]));
//console.log(approximatingRange(4, [2, 2, 3, 4]));

// const lineReader = require('line-reader');
// lineReader.eachLine('', function(line) {
//   console.log(line);
// });
// var fs = require('fs');
// const readline = require('readline');
// const rl = readline.createInterface({
//   input: process.stdin,
//   output: process.stdout
// });

// rl.question('What do you think of Node.js? ', (answer) => {
//   // TODO: Log the answer in a database
//   console.log(`Thank you for your valuable feedback: ${answer}`);

//   rl.close();
// });

'use strict';

// const fs = require('fs');

process.stdin.resume();
process.stdin.setEncoding('utf-8');

let inputString = '';
let currentLine = 0;

process.stdin.on('data', inputStdin => {
  inputString += inputStdin;
});

process.stdin.on('end', _ => {
  inputString = inputString.trim().split('\n').map(string => {
      return string.trim();
  });

  main();
});

function readLine() {
  return inputString[currentLine++];
}

function approximatingRange(size, arr) {
  /*
   * Write your code here.
   */

  const currPoint = { value: arr[0], index: 0 };
  const nextPoint = { value: arr[0], index: 0 };
  const minPoint = { value: arr[0], index: 0 };
  const maxPoint = { value: arr[0], index: 0 };
  let maxRange = 0;

  for (let i = 0; i < size; i++) {
    if (arr[i] < minPoint.value) {
      minPoint.value = arr[i];
      minPoint.index = i;
    }

    if (arr[i] > maxPoint.value) {
      maxPoint.value = arr[i];
      maxPoint.index = i;
    }

    if ((Math.abs(arr[i] - arr[i-1]) > 1) || (maxPoint.value - minPoint.value) > 2) {
      const range = i - currPoint.index;
      if (range > maxRange) {
        maxRange = range;
      }
      currPoint.index = i;
      currPoint.value = arr[i];

      minPoint.index = i;
      minPoint.value = arr[i]

      maxPoint.index = i;
      maxPoint.value = arr[i]

      nextPoint.value = arr[i];
      nextPoint.index = i;
    } else {
      if ((maxPoint.value - minPoint.value) > 1) {
        const range = i - currPoint.index;
        if (range > maxRange) {
          maxRange = range;
        }
        currPoint.index = nextPoint.index;
        currPoint.value = nextPoint.value;

        minPoint.index = nextPoint.index;
        minPoint.value = nextPoint.value;

        maxPoint.index = nextPoint.index;
        maxPoint.value = nextPoint.value;

        nextPoint.value = arr[i];
        nextPoint.index = i;
      } else {
        if (arr[i] !== arr[i - 1]) {
          nextPoint.value = arr[i];
          nextPoint.index = i;
        }
      }
    }

    // console.log('i=', i, 'maxRange:=', maxRange, 'currentPoint=', currPoint, 'nextPoint=', nextPoint);

    if (size === i + 1) {
      const range = size - currPoint.index;
      if (range > maxRange) {
        maxRange = range;
      }
    }
  }

  return maxRange;

}

function main() {

  const size = parseInt(readLine(), 10);

  const arr = readLine().split(' ').map(bTemp => parseInt(bTemp, 10));

  console.log(approximatingRange(size, arr));
}


'use strict';

var fs = require('fs');

function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }

var fs__default = /*#__PURE__*/_interopDefaultLegacy(fs);

function solve(read) {
  const [rn, rb, rns, re, rbs] = convertInput(read);
  const n = rn(),
        s = read();
  let a = 0,
      b = 0;
  for (let ch of s) {
    if (ch === '0') a++;else b++;
  }
  if (a === 0) {
    return b ** 2;
  } else if (b === 0) {
    return a ** 2;
  }
  let res = a * b;
  for (let i = 0; i < n; i++) {
    for (let j = i; j < n; j++) {
      if (s[i] !== s[j]) break;
      res = Math.max(res, (j - i + 1) ** 2);
    }
  }
  return res;
}
function convertInput(read) {
  const rn = () => Number(read());
  const rb = () => BigInt(read());
  const rns = () => read().split(/\s+/).map(Number);
  const re = () => read().split(/\s+/).map(s => Number(s) - 1);
  const rbs = () => read().split(/\s+/).map(BigInt);
  return [rn, rb, rns, re, rbs];
}
function main(r) {
  try {
    let t = Number(r());
    let res = new Array(t);
    let limit = 0;
    for (let i = 0; i < t; i++) {
      let s = solve(r);
      if (s === undefined) s = '';
      if (t < limit) {
        process.stdout.write(s.toString());
        process.stdout.write('\n');
      } else {
        res[i] = s;
      }
    }
    if (t >= limit) {
      return res.join('\n');
    } else {
      return '';
    }
  } catch (error) {
    console.log(error);
  }
}

const inputs = fs__default["default"].readFileSync(0, 'utf-8').split(/\r?\n/);
void function () {
  const read = ((i = 0) => () => inputs[i++])();
  const output = main(read);
  process.stdout.write(output);
}();

function solve(input) {
    var maxX = 0;
    var maxY = 0;

    var curX = 0;
    var curY = 0;

    var totalX = 0;
    var totalY = 0;

    for (var i = 0; i < input.length; i++) {
        var char = input[i];
        if (i >= 1 && char !== input[i-1]) {
            curX = 0;
            curY = 0;
        }

        if (char === '0') {
            totalX++;
            curX++;
            maxX = Math.max(maxX, curX);
        } else {
            totalY++;
            curY++;
            maxY = Math.max(maxY, curY);
        }
    }

    const mult = totalX * totalY;

    var max = Math.max(mult, Math.pow(maxX, 2), Math.pow(maxY, 2));
    cl(max);
}

// ===========

var numOfCases = Number(readline());
for (var testCase = 0; testCase < numOfCases; testCase++) {
    var caseLength = rlsn();
    var input = rlarrstr()[0];

    var res = solve(input);
}
function cl(s) {print(s)}

function rlsn() {return Number(readline());}
function rlarrstr() {return readline().split(' ');}
function rlarrn() {return rlarrstr().map(Number);}

var numOfCases = Number(readline());

for (var testCase = 0; testCase < numOfCases; testCase++) {
    var caseLength = Number(readline());
    var input = readline();
    process(input);
}

function process(input) {
    var maxX = 0;
    var maxY = 0;

    var curX = 0;
    var curY = 0;

    var totalX = 0;
    var totalY = 0;

    for (var i = 0; i < input.length; i++) {
        var char = input[i];
        if (i >= 1 && char !== input[i-1]) {
            curX = 0;
            curY = 0;
        }

        if (char === '0') {
            totalX++;
            curX++;
            maxX = Math.max(maxX, curX);
        } else {
            totalY++;
            curY++;
            maxY = Math.max(maxY, curY);
        }
    }

    const mult = totalX * totalY;

    var max = Math.max(mult, Math.pow(maxX, 2), Math.pow(maxY, 2));
    print(max);
}

var t = readline();
t = parseInt(t);

while(t--){
    var x = 0;
    var y = 0;
    var counter = 1;
    var max_length = 1;

    var n = readline();
    var s = readline();

    for(var i=0; i<n; i++){
        if(s[i]=="0"){
            x++;
        }
        else{
            y++;
        }
    }
    var pre_bit = s[0];

    for(var i=1; i<s.length; i++){
        if(pre_bit == s[i]){
            counter++;
        }
        else{
            counter = 1;
        }
        if(counter>max_length){
            max_length = counter;
        }
        pre_bit =  s[i];
    }

    if(x*y > max_length*max_length){
        print(x*y);
    }
    else{
        print(max_length*max_length)
    }
}

const x = readline(); // first line

for(var i = 0 ; i < x ; i++) {
  var length = parseInt(readline()); // skip line
  var inp = readline();
  var ones = inp.split('').filter(s => s == 1).length;
  var zeros = length - ones;
  var number0 = inp.split('1').sort().pop().length;
  var number1 = inp.split('0').sort().pop().length;
  var onesPow = number1 * number1;
  var zerosPow = number0 * number0;
  var onesZeros = ones * zeros;

  print(Math.max(onesPow, zerosPow, onesZeros));
}

'use strict';

function solve([input]) {
    var maxX = 0;
    var maxY = 0;

    var curX = 0;
    var curY = 0;

    var totalX = 0;
    var totalY = 0;

    for (var i = 0; i < input.length; i++) {
        var char = input[i];
        if (i >= 1 && char !== input[i-1]) {
            curX = 0;
            curY = 0;
        }

        if (char === '0') {
            totalX++;
            curX++;
            maxX = Math.max(maxX, curX);
        } else {
            totalY++;
            curY++;
            maxY = Math.max(maxY, curY);
        }
    }

    const mult = totalX * totalY;

    return Math.max(mult, Math.pow(maxX, 2), Math.pow(maxY, 2));
}

function main() {
    const numOfCases = rlsn();

    for (let testCase = 0; testCase < numOfCases; testCase++) {
        const l1 = rlsn();
        const l2 = rlarrstr();

        const res = solve(l2);
        cl(res);
    }
}

process.stdin.resume();
process.stdin.setEncoding('utf-8');

let inStr = '';
let curLine = 0;
const cl = console.log;

process.stdin.on('data', function(inStdin) {inStr += inStdin;});
process.stdin.on('end', function() {inStr = inStr.split('\n');main();});

function readline() {return inStr[curLine++].replace(/\s+$/g, '');}
function rlsn() {return Number(readline());}
function rlarrstr() {return readline().split(' ');}
function rlarrn() {return rlarrstr().map(Number);}

'use strict';

process.stdin.resume();
process.stdin.setEncoding('utf-8');

let inputString = '';
let currentLine = 0;

process.stdin.on('data', function(inputStdin) {
    inputString += inputStdin;
});

process.stdin.on('end', function() {
    inputString = inputString.split('\n');

    main();
});

function readLine() {
    return inputString[currentLine++];
}

function sorted(arr)
{
    let second_index;
	for(let first_index = 0; first_index < arr.length; first_index++){
  	  second_index = first_index + 1;
      if(arr[second_index] - arr[first_index] < 0) return false;
    }
    return true;
}

function main() {

    let t = parseInt(readLine());

    loopwhile:
    while(t--)
    {
        let n = parseInt(readLine())

        let arr = readLine().trim().split("").map(x=>parseInt(x))

        //console.log("arr " + arr)

        let swap=false

        let cur=arr[0]
        let cur_streak=0

        let count_zer = 0
        let count_one = 0

        let max_sq = 0
        for(let i=0;i<n;i++)
        {
            if(cur!=arr[i])
                swap = true;

            //console.log("swap " + swap)
            if(arr[i]==0)
            {
                count_zer++
            }
            else
            {
                count_one++
            }
            if(!swap & (i==(n-1)))
            {
                //console.log("cur_streak" + cur_streak)
               max_sq=Math.max(max_sq,cur_streak+1)
            }
            if(swap)
                {
                    max_sq=Math.max(max_sq,cur_streak)
                    cur_streak=0
                    swap=false;
                }

            cur_streak++;
            cur=arr[i]
        }

        /*console.log("count_zer" +  count_zer)
        console.log("count_one" +  count_one)
        console.log("count_map " +  max_sq)*/

        let prod_val = count_zer * count_one
        let prod_sq = Math.pow(max_sq,2)

        console.log(Math.max(prod_val, prod_sq))
   }
}

// ------------------------
// Codeabschnitt, der für die Verarbeitung der Eingabe zuständig ist
'use strict';

process.stdin.resume();
process.stdin.setEncoding('utf-8');

let inputString = '';
let currentLine = 0;

process.stdin.on('data', inputStdin => {
    inputString += inputStdin;
});

process.stdin.on('end', _ => {
    inputString = inputString.trim().split('\n').map(string => {
        return string.trim();
    });

    main();
});

function readline() {
    return inputString[currentLine++];
}

const print = console.log

// ---------------------------

/**
 * Usage (Linux/Unix): cat input.txt | node index.js
 */

function main() {
    const testCases = +readline()

    for(let i = 0; i < testCases; i++) {
      let len = +readline();
      let inp = readline()

      let longestZeroSequence = 0;
      let longestOneSequence = 0;
      let latestSequence = 1;
      let lastChar = inp[0];
      for(let ii = 1; ii <= len; ii++){
        if(inp[ii] == lastChar && ii != len){
            latestSequence++
        } else {
            if(lastChar === '0'){
                if(latestSequence > longestZeroSequence){
                    longestZeroSequence = latestSequence;
                }
            } else {
                if(latestSequence > longestOneSequence){
                    longestOneSequence = latestSequence;
                }
            }
            latestSequence = 1;
            lastChar = inp[ii];
        }
      }

      let highestSequence = Math.max(longestZeroSequence, longestOneSequence);
      let costAll = (inp.match(/0/g) || []).length * (inp.match(/1/g) || []).length;

      if(costAll > highestSequence ** 2){
        print(costAll);
      } else {
        print(highestSequence ** 2);
      }

    }
}

function solve() {
    var n = Number(read());
    var s = read();
    var ans = 0;
    var zeroCount = 0;
    var oneCount = 0;
    var currentStartIndex = 0;
    for (var i = 0; i <= n; i++) {
        if (s[i] === '1') {
            oneCount++;
        }
        if (s[i] === '0') {
            zeroCount++;
        }
        if (s[i] === s[i - 1]) {
            continue;
        }
        var prevLenght = i - currentStartIndex;
        currentStartIndex = i;
        var value = prevLenght * prevLenght;
        if (value > ans) {
            ans = value;
        }
    }
    write(Math.max(ans, zeroCount * oneCount));
}

function start() {
    var T = 1;
    T = Number(read());
    for (var t = 0; t < T; t++) {
        solve();
    }
    writeAns();
}

function gcd(a, b) {
    if (b === 0) {
        return a;
    }
    return gcd(b, a % b)
}

var MEMORY;
var MEMORY_INDEX = 0;
var ANS = '';

try {
    initInput(start);
} catch (e) {
    console.log(e);
}
function readArray(f) {
    return read().split(' ').map(f);
}

function sortNumbers(a, b) {
    return a - b;
}
function sortNumbersDec(a, b) {
    return b - a;
}
var ANS;
// вывод через ANS быстрее, но ест кучу памяти.
// К тому же, максимальная длина строки - 2097151.
function write(value) {
    // console.log(value);
    ANS += value + '\n';
}
function writeAns() {
    if (ANS) {
        console.log(ANS);
    }
}
function read() {
    return MEMORY[MEMORY_INDEX++];
}
function initInput(callback) {
    var fs = require('fs');
    var isLocalStart = process.argv[2] === 'lorelvate';
    if (!isLocalStart) {
        MEMORY = fs.readFileSync(0, 'utf-8').split('\r\n');
        callback();
        return;
    }
    var path = require('path');
    fs.readFile(path.join(__dirname, 'input.txt'), 'utf8', (err, data) => {
        if (err) {
            write(err);
            return;
        }
        MEMORY = data.split('\r\n');
        callback();
    });
}