Little girl Susie went shopping with her mom and she wondered how to improve service quality. There are n people in the queue. For each person we know time ti needed to serve him. A person will be disappointed if the time he waits is more than the time needed to serve him. The time a person waits is the total time when all the people who stand in the queue in front of him are served. Susie thought that if we swap some people in the queue, then we can decrease the number of people who are disappointed. Help Susie find out what is the maximum number of not disappointed people can be achieved by swapping people in the queue.

The first line contains integer n (1 ≤ n ≤ 105). The next line contains n integers ti (1 ≤ ti ≤ 109), separated by spaces.

Print a single number — the maximum number of not disappointed people in the queue.

NoteValue 4 is achieved at such an arrangement, for example: 1, 2, 3, 5, 15. Thus, you can make everything feel not disappointed except for the person with time 5.

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);

// 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);

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);
})

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);


Recently, you found a bot to play "Rock paper scissors" with. Unfortunately, the bot uses quite a simple algorithm to play: he has a string $$$s = s_1 s_2 \dots s_{n}$$$ of length $$$n$$$ where each letter is either R, S or P.While initializing, the bot is choosing a starting index $$$pos$$$ ($$$1 \le pos \le n$$$), and then it can play any number of rounds. In the first round, he chooses "Rock", "Scissors" or "Paper" based on the value of $$$s_{pos}$$$:   if $$$s_{pos}$$$ is equal to R the bot chooses "Rock";  if $$$s_{pos}$$$ is equal to S the bot chooses "Scissors";  if $$$s_{pos}$$$ is equal to P the bot chooses "Paper"; In the second round, the bot's choice is based on the value of $$$s_{pos + 1}$$$. In the third round — on $$$s_{pos + 2}$$$ and so on. After $$$s_n$$$ the bot returns to $$$s_1$$$ and continues his game.You plan to play $$$n$$$ rounds and you've already figured out the string $$$s$$$ but still don't know what is the starting index $$$pos$$$. But since the bot's tactic is so boring, you've decided to find $$$n$$$ choices to each round to maximize the average number of wins.In other words, let's suggest your choices are $$$c_1 c_2 \dots c_n$$$ and if the bot starts from index $$$pos$$$ then you'll win in $$$win(pos)$$$ rounds. Find $$$c_1 c_2 \dots c_n$$$ such that $$$\frac{win(1) + win(2) + \dots + win(n)}{n}$$$ is maximum possible.

The first line contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of test cases. Next $$$t$$$ lines contain test cases — one per line. The first and only line of each test case contains string $$$s = s_1 s_2 \dots s_{n}$$$ ($$$1 \le n \le 2 \cdot 10^5$$$; $$$s_i \in \{\text{R}, \text{S}, \text{P}\}$$$) — the string of the bot. It's guaranteed that the total length of all strings in one test doesn't exceed $$$2 \cdot 10^5$$$.

For each test case, print $$$n$$$ choices $$$c_1 c_2 \dots c_n$$$ to maximize the average number of wins. Print them in the same manner as the string $$$s$$$. If there are multiple optimal answers, print any of them.

NoteIn the first test case, the bot (wherever it starts) will always choose "Rock", so we can always choose "Paper". So, in any case, we will win all $$$n = 4$$$ rounds, so the average is also equal to $$$4$$$.In the second test case:   if bot will start from $$$pos = 1$$$, then $$$(s_1, c_1)$$$ is draw, $$$(s_2, c_2)$$$ is draw and $$$(s_3, c_3)$$$ is draw, so $$$win(1) = 0$$$;  if bot will start from $$$pos = 2$$$, then $$$(s_2, c_1)$$$ is win, $$$(s_3, c_2)$$$ is win and $$$(s_1, c_3)$$$ is win, so $$$win(2) = 3$$$;  if bot will start from $$$pos = 3$$$, then $$$(s_3, c_1)$$$ is lose, $$$(s_1, c_2)$$$ is lose and $$$(s_2, c_3)$$$ is lose, so $$$win(3) = 0$$$;  The average is equal to $$$\frac{0 + 3 + 0}{3} = 1$$$ and it can be proven that it's the maximum possible average.A picture from Wikipedia explaining "Rock paper scissors" game:

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();
}


When Xellos was doing a practice course in university, he once had to measure the intensity of an effect that slowly approached equilibrium. A good way to determine the equilibrium intensity would be choosing a sufficiently large number of consecutive data points that seems as constant as possible and taking their average. Of course, with the usual sizes of data, it's nothing challenging — but why not make a similar programming contest problem while we're at it?You're given a sequence of n data points a1, ..., an. There aren't any big jumps between consecutive data points — for each 1 ≤ i < n, it's guaranteed that |ai + 1 - ai| ≤ 1.A range [l, r] of data points is said to be almost constant if the difference between the largest and the smallest value in that range is at most 1. Formally, let M be the maximum and m the minimum value of ai for l ≤ i ≤ r; the range [l, r] is almost constant if M - m ≤ 1.Find the length of the longest almost constant range.

The first line of the input contains a single integer n (2 ≤ n ≤ 100 000) — the number of data points. The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 100 000).

Print a single number — the maximum length of an almost constant range of the given sequence.

NoteIn the first sample, the longest almost constant range is [2, 5]; its length (the number of data points in it) is 4.In the second sample, there are three almost constant ranges of length 4: [1, 4], [6, 9] and [7, 10]; the only almost constant range of the maximum length 5 is [6, 10].

// 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));
}

'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.
   */

  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));
}