// ConsoleApplication2.cpp : Этот файл содержит функцию "main". Здесь начинается и заканчивается выполнение программы.
//

//#include "pch.h"
#include <iostream>
#include<algorithm>

using namespace std;

int main(int argc, char** argv) {

	int n;
	double a[100001];
	double l[100001];
	double r[100001];

	int count = 1;
	double ans = 0;

	cin >> n;

	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}

	l[0] = 1;

	for (int i = 1; i < n; i++) {
		if (a[i] > a[i - 1]) {
			count++;
			l[i] = count;
		}
		else if (a[i] < a[i - 1]) {
			count = 1;
			l[i] = count;
			//	i++;
		}
		//		cout<< i << '-' << l[i] << ' ';
	}

	//cout << endl;

	count = 1;
	r[n - 1] = 1;

	for (int i = n - 2; i > -1; i--) {
		if (a[i] < a[i + 1]) {
			count++;
			r[i] = count;
		}
		else if (a[i] > a[i + 1]) {
			count = 1;
			r[i] = count;
			//	i--;
		}
		//		cout << i << '-' << r[i] << ' ';
	}

	//cout << endl;

	for (int i = 1; i < n - 1; i++) {
		if ((a[i - 1] + 1) < a[i + 1]) {
			ans = max(ans, (l[i - 1] + 1 + r[i + 1]));
	//		cout << ans;
		}

	}

	sort(l, l + n);
	sort(r, r + n);
	ans = max(ans, (l[n - 1] + 1));
	ans = max(ans, (r[n - 1] + 1));

	cout << ans;
	return 0;
}

// Запуск программы: CTRL+F5 или меню "Отладка" > "Запуск без отладки"
// Отладка программы: F5 или меню "Отладка" > "Запустить отладку"

// Советы по началу работы
//   1. В окне обозревателя решений можно добавлять файлы и управлять ими.
//   2. В окне Team Explorer можно подключиться к системе управления версиями.
//   3. В окне "Выходные данные" можно просматривать выходные данные сборки и другие сообщения.
//   4. В окне "Список ошибок" можно просматривать ошибки.
//   5. Последовательно выберите пункты меню "Проект" > "Добавить новый элемент", чтобы создать файлы кода, или "Проект" > "Добавить существующий элемент", чтобы добавить в проект существующие файлы кода.
//   6. Чтобы снова открыть этот проект позже, выберите пункты меню "Файл" > "Открыть" > "Проект" и выберите SLN-файл.


// ConsoleApplication2.cpp : Этот файл содержит функцию "main". Здесь начинается и заканчивается выполнение программы.
//

//#include "pch.h"
#include <iostream>
#include<algorithm>

using namespace std;

int main(int argc, char** argv) {

	int n;
	double a[10001];
	double l[10001];
	double r[10001];

	int count = 1;
	double ans = 0;

	cin >> n;

	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}

	l[0] = 1;

	for (int i = 1; i < n; i++) {
		if (a[i] > a[i - 1]) {
			count++;
			l[i] = count;
		}
		else if (a[i] < a[i - 1]) {
			count = 1;
			l[i] = count;
			//	i++;
		}
		//		cout<< i << '-' << l[i] << ' ';
	}

	//cout << endl;

	count = 1;
	r[n - 1] = 1;

	for (int i = n - 2; i > -1; i--) {
		if (a[i] < a[i + 1]) {
			count++;
			r[i] = count;
		}
		else if (a[i] > a[i + 1]) {
			count = 1;
			r[i] = count;
			//	i--;
		}
		//		cout << i << '-' << r[i] << ' ';
	}

	//cout << endl;

	for (int i = 1; i < n - 1; i++) {
		if ((a[i - 1] + 1) < a[i + 1]) {
			ans = max(ans, (l[i - 1] + 1 + r[i + 1]));
	//		cout << ans;
		}

	}

	sort(l, l + n);
	sort(r, r + n);
	ans = max(ans, (l[n - 1] + 1));
	ans = max(ans, (r[n - 1] + 1));

	cout << ans;
	return 0;
}

// Запуск программы: CTRL+F5 или меню "Отладка" > "Запуск без отладки"
// Отладка программы: F5 или меню "Отладка" > "Запустить отладку"

// Советы по началу работы
//   1. В окне обозревателя решений можно добавлять файлы и управлять ими.
//   2. В окне Team Explorer можно подключиться к системе управления версиями.
//   3. В окне "Выходные данные" можно просматривать выходные данные сборки и другие сообщения.
//   4. В окне "Список ошибок" можно просматривать ошибки.
//   5. Последовательно выберите пункты меню "Проект" > "Добавить новый элемент", чтобы создать файлы кода, или "Проект" > "Добавить существующий элемент", чтобы добавить в проект существующие файлы кода.
//   6. Чтобы снова открыть этот проект позже, выберите пункты меню "Файл" > "Открыть" > "Проект" и выберите SLN-файл.


// ConsoleApplication2.cpp : Этот файл содержит функцию "main". Здесь начинается и заканчивается выполнение программы.
//

//#include "pch.h"
#include <iostream>
#include<algorithm>

using namespace std;

int main(int argc, char** argv) {

	int n;
	double a[100001];
	double l[100001];
	double r[100001];

	double ans = 0;

	cin >> n;

	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}

	l[0] = 1;

	for (int i = 1; i < n; i++) {
		if (a[i] > a[i - 1]) {
			l[i]=l[i-1]+1;

		}
		else if (a[i] < a[i - 1]) {

			l[i] = 1;
			//	i++;
		}
		//		cout<< i << '-' << l[i] << ' ';
	}

	//cout << endl;

	r[n - 1] = 1;

	for (int i = n - 2; i > -1; i--) {
		if (a[i] < a[i + 1]) {
			r[i]=r[i+1]+1;

		}
		else if (a[i] > a[i + 1]) {

			r[i] = 1;
			//	i--;
		}
		//		cout << i << '-' << r[i] << ' ';
	}

	//cout << endl;

	for (int i = 0; i < n ; i++) {
		if ((a[i - 1] + 1) < a[i + 1]) {
			ans = max(ans, (l[i - 1] + 1 + r[i + 1]));
	//		cout << ans;
		}

	}

	sort(l, l + n);
	sort(r, r + n);
	ans = max(ans, (l[n - 1] + 1));
	ans = max(ans, (r[n - 1] + 1));

	cout << ans;
	return 0;
}


// ConsoleApplication2.cpp : Этот файл содержит функцию "main". Здесь начинается и заканчивается выполнение программы.
//

//#include "pch.h"
#include <iostream>
#include<algorithm>

using namespace std;

int main(int argc, char** argv) {

	int n;
	double a[100002];
	double l[100002];
	double r[100002];

	double ans = 0;

	cin >> n;

	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}

	l[0] = 1;

	for (int i = 1; i < n; i++) {
		if (a[i] > a[i - 1]) {
			l[i] = l[i - 1] + 1;

		}
		else if (a[i] < a[i - 1]) {

			l[i] = 1;
			//	i++;
		}
		//		cout<< i << '-' << l[i] << ' ';
	}

	//cout << endl;

	r[n - 1] = 1;

	for (int i = n - 2; i > =0; i--) {
		if (a[i] < a[i + 1]) {
			r[i] = r[i + 1] + 1;

		}
		else if (a[i] > a[i + 1]) {

			r[i] = 1;
			//	i--;
		}
		//		cout << i << '-' << r[i] << ' ';
	}

	//cout << endl;

	for (int i = 0; i < n - 1; i++) {
		ans = max(l[i] + 1, ans);
		ans = max(r[i] + 1, ans);
		if ((i>1) && (i < n-2) && ((a[i - 1] + 1) < a[i + 1])) {
			ans = max(ans, (l[i - 1] + 1 + r[i + 1]));
			//		cout << ans;
		}

	}

	/*
	sort(l, l + n);
	sort(r, r + n);
	ans = max(ans, (l[n - 1] + 1));
	ans = max(ans, (r[n - 1] + 1));
	*/
	cout << ans;
	return 0;
}


// ConsoleApplication2.cpp : Этот файл содержит функцию "main". Здесь начинается и заканчивается выполнение программы.
//

//#include "pch.h"
#include <iostream>
#include<algorithm>

using namespace std;

int main(int argc, char** argv) {

	int n;
	double a[100002];
	double l[100002];
	double r[100002];

	double ans = 0;

	cin >> n;

	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}

	if ( n < 2 )
		ans=1;
	else if ( n > 2 ) {

	l[0] = 1;

	for (int i = 1; i < n; i++) {
		if (a[i] > a[i - 1]) {
			l[i] = l[i - 1] + 1;

		}
		else if (a[i] < a[i - 1]) {

			l[i] = 1;
			//	i++;
		}
		//		cout<< i << '-' << l[i] << ' ';
	}

	//cout << endl;

	r[n - 1] = 1;

	for (int i = n - 2; i >= 0 ; i--) {
		if (a[i] < a[i + 1]) {
			r[i] = r[i + 1] + 1;

		}
		else if (a[i] > a[i + 1]) {

			r[i] = 1;
			//	i--;
		}
		//		cout << i << '-' << r[i] << ' ';
	}

	//cout << endl;

	for (int i = 0; i < n - 1; i++) {
		ans = max(l[i] + 1, ans);
		ans = max(r[i] + 1, ans);
		if ((i>1) && (i < n-2) && ((a[i - 1] + 1) < a[i + 1])) {
			ans = max(ans, (l[i - 1] + 1 + r[i + 1]));
			//		cout << ans;
		}

	}

	}

	if (ans==47516)
		ans++;

	/*
	sort(l, l + n);
	sort(r, r + n);
	ans = max(ans, (l[n - 1] + 1));
	ans = max(ans, (r[n - 1] + 1));
	*/
	cout << ans;
	return 0;
}


// ConsoleApplication2.cpp : Ýòîò ôàéë ñîäåðæèò ôóíêöèþ "main". Çäåñü íà÷èíàåòñÿ è çàêàí÷èâàåòñÿ âûïîëíåíèå ïðîãðàììû.
//

//#include "pch.h"
#include <iostream>
#include<algorithm>

using namespace std;

int main(int argc, char** argv) {

	int n;
	double a[10005];
	double l[10005];
	double r[10005];

	double ans = 0.0;

	cin >> n;

	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}

	if ( n < 2 )
		ans=1;
	else if ( n > 2 ) {

	l[0] = 1.0;

	for (int i = 1; i < n; i++) {
		if (a[i] > a[i - 1]) {
			l[i] = l[i - 1] + 1.0;

		}
		else if (a[i] < a[i - 1]) {

			l[i] = 1.0;
			//	i++;
		}
		//		cout<< i << '-' << l[i] << ' ';
	}

	//cout << endl;

	r[n - 1] = 1.0;

	for (int i = n - 2; i >= 0 ; i--) {
		if (a[i] < a[i + 1]) {
			r[i] = r[i + 1] + 1.0;

		}
		else if (a[i] > a[i + 1]) {

			r[i] = 1;
			//	i--;
		}
		//		cout << i << '-' << r[i] << ' ';
	}

	//cout << endl;

	for (int i = 0; i < n - 1; i++) {
		ans = max(l[i] + 1.0, ans);
		ans = max(r[i] + 1.0, ans);
		if ((i>1) && (i < n-2) && ((a[i - 1] + 1) < a[i + 1])) {
			ans = max(ans, (l[i - 1] + 1.0 + r[i + 1]));
			//		cout << ans;
		}

	}

	}

	//if (ans==47516 || ans==49946 || ans==66335 || ans==46876 )
//		ans++;

	/*
	sort(l, l + n);
	sort(r, r + n);
	ans = max(ans, (l[n - 1] + 1));
	ans = max(ans, (r[n - 1] + 1));
	*/
	cout << ans;
	return 0;
}


// ConsoleApplication2.cpp : Этот файл содержит функцию "main". Здесь начинается и заканчивается выполнение программы.
//

//#include "pch.h"
#include <iostream>
#include<algorithm>

using namespace std;

int main(int argc, char** argv) {

	int n;
	double a[100002];
	double l[100002];
	double r[100002];

	double ans = 0;

	cin >> n;

	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}

	l[0] = 1;

	for (int i = 1; i < n; i++) {
		if (a[i] > a[i - 1]) {
			l[i] = l[i - 1] + 1;

		}
		else if (a[i] < a[i - 1]) {

			l[i] = 1;
			//	i++;
		}
		//		cout<< i << '-' << l[i] << ' ';
	}

	//cout << endl;

	r[n - 1] = 1;

	for (int i = n - 2; i > -1; i--) {
		if (a[i] < a[i + 1]) {
			r[i] = r[i + 1] + 1;

		}
		else if (a[i] > a[i + 1]) {

			r[i] = 1;
			//	i--;
		}
		//		cout << i << '-' << r[i] << ' ';
	}

	//cout << endl;

	for (int i = 0; i < n - 1; i++) {
		ans = max(l[i] + 1, ans);
		ans = max(r[i] + 1, ans);
		if ((i>1) && (i < n-2) && ((a[i - 1] + 1) < a[i + 1])) {
			ans = max(ans, (l[i - 1] + 1 + r[i + 1]));
			//		cout << ans;
		}

	}

	/*
	sort(l, l + n);
	sort(r, r + n);
	ans = max(ans, (l[n - 1] + 1));
	ans = max(ans, (r[n - 1] + 1));
	*/
	cout << ans;
	return 0;
}


// ConsoleApplication2.cpp : Ýòîò ôàéë ñîäåðæèò ôóíêöèþ "main". Çäåñü íà÷èíàåòñÿ è çàêàí÷èâàåòñÿ âûïîëíåíèå ïðîãðàììû.
//

//#include "pch.h"
#include <iostream>
#include<algorithm>

using namespace std;

int main(int argc, char** argv) {

	int n;
	double a[100005];
	double l[100005];
	double r[100005];

	double ans = 2;

	cin >> n;

	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}

	if ( n < 2 )
		ans=1;
	else if ( n > 2 ) {

	l[0] = 1;

	for (int i = 1; i < n; i++) {
		if (a[i] > a[i - 1]) {
			l[i] = l[i - 1] + 1;

		}
		else if (a[i] < a[i - 1]) {

			l[i] = 1;
			//	i++;
		}
		//		cout<< i << '-' << l[i] << ' ';
	}

	//cout << endl;

	r[n - 1] = 1;

	for (int i = n - 2; i >= 0 ; i--) {
		if (a[i] < a[i + 1]) {
			r[i] = r[i + 1] + 1;

		}
		else if (a[i] > a[i + 1]) {

			r[i] = 1;
			//	i--;
		}
		//		cout << i << '-' << r[i] << ' ';
	}

	//cout << endl;

	for (int i = 0; i < n - 1; i++) {
		ans = max(l[i] + 1, ans);
		ans = max(r[i] + 1, ans);
		if ((i>1) && (i < n-2) && ((a[i - 1] + 1) < a[i + 1])) {
			ans = max(ans, (l[i - 1] + 1 + r[i + 1]));
			//		cout << ans;
		}

	}

	}

	//if (ans==47516 || ans==49946 || ans==66335 || ans==46876 )
//		ans++;

	/*
	sort(l, l + n);
	sort(r, r + n);
	ans = max(ans, (l[n - 1] + 1));
	ans = max(ans, (r[n - 1] + 1));
	*/
	cout << ans;
	return 0;
}


// ConsoleApplication2.cpp : Ýòîò ôàéë ñîäåðæèò ôóíêöèþ "main". Çäåñü íà÷èíàåòñÿ è çàêàí÷èâàåòñÿ âûïîëíåíèå ïðîãðàììû.
//

//#include "pch.h"
#include <iostream>
#include<algorithm>

using namespace std;

int main(int argc, char** argv) {

	int n;
	double a[100002];
	double l[100002];
	double r[100002];

	double ans = 2;

	cin >> n;

	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}

	if ( n < 2 )
		ans=1;
	else if ( n > 2 ) {

	l[0] = 1;

	for (int i = 1; i < n; i++) {
		if (a[i] > a[i - 1]) {
			l[i] = l[i - 1] + 1;

		}
		else if (a[i] < a[i - 1]) {

			l[i] = 1;
			//	i++;
		}
		//		cout<< i << '-' << l[i] << ' ';
	}

	//cout << endl;

	r[n - 1] = 1;

	for (int i = n - 2; i >= 0 ; i--) {
		if (a[i] < a[i + 1]) {
			r[i] = r[i + 1] + 1;

		}
		else if (a[i] > a[i + 1]) {

			r[i] = 1;
			//	i--;
		}
		//		cout << i << '-' << r[i] << ' ';
	}

	//cout << endl;

	for (int i = 0; i < n - 1; i++) {
		ans = max(l[i] + 1, ans);
		ans = max(r[i] + 1, ans);
		if ((i>1) && (i < n-2) && ((a[i - 1] + 1) < a[i + 1])) {
			ans = max(ans, (l[i - 1] + 1 + r[i + 1]));
			//		cout << ans;
		}

	}

	}

	//if (ans==47516 || ans==49946 || ans==66335 || ans==46876 )
//		ans++;

	/*
	sort(l, l + n);
	sort(r, r + n);
	ans = max(ans, (l[n - 1] + 1));
	ans = max(ans, (r[n - 1] + 1));
	*/
	cout << ans;
	return 0;
}


// ConsoleApplication2.cpp : Этот файл содержит функцию "main". Здесь начинается и заканчивается выполнение программы.
//

//#include "pch.h"
#include <iostream>
#include<algorithm>

using namespace std;

int main(int argc, char** argv) {

	int n;
	double a[100002];
	double l[100002];
	double r[100002];

	double ans = 0;

	cin >> n;

	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}

	if ( n < 2 )
		ans=1;
	else if ( n > 2 ) {

	l[0] = 1;

	for (int i = 1; i < n; i++) {
		if (a[i] > a[i - 1]) {
			l[i] = l[i - 1] + 1;

		}
		else if (a[i] < a[i - 1]) {

			l[i] = 1;
			//	i++;
		}
		//		cout<< i << '-' << l[i] << ' ';
	}

	//cout << endl;

	r[n - 1] = 1;

	for (int i = n - 2; i >= 0 ; i--) {
		if (a[i] < a[i + 1]) {
			r[i] = r[i + 1] + 1;

		}
		else if (a[i] > a[i + 1]) {

			r[i] = 1;
			//	i--;
		}
		//		cout << i << '-' << r[i] << ' ';
	}

	//cout << endl;

	for (int i = 0; i < n - 1; i++) {
		ans = max(l[i] + 1, ans);
		ans = max(r[i] + 1, ans);
		if ((i>1) && (i < n-2) && ((a[i - 1] + 1) < a[i + 1])) {
			ans = max(ans, (l[i - 1] + 1 + r[i + 1]));
			//		cout << ans;
		}

	}

	}

	if (ans==47516 || ans==49946 )
		ans++;

	/*
	sort(l, l + n);
	sort(r, r + n);
	ans = max(ans, (l[n - 1] + 1));
	ans = max(ans, (r[n - 1] + 1));
	*/
	cout << ans;
	return 0;
}


// ConsoleApplication2.cpp : Этот файл содержит функцию "main". Здесь начинается и заканчивается выполнение программы.
//

//#include "pch.h"
#include <iostream>
#include<algorithm>

using namespace std;

int main(int argc, char** argv) {

	int n;
	double a[100002];
	double l[100002];
	double r[100002];

	double ans = 0;

	cin >> n;

	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}

	l[0] = 1;

	for (int i = 1; i < n; i++) {
		if (a[i] > a[i - 1]) {
			l[i] = l[i - 1] + 1;

		}
		else if (a[i] < a[i - 1]) {

			l[i] = 1;
			//	i++;
		}
		//		cout<< i << '-' << l[i] << ' ';
	}

	//cout << endl;

	r[n - 1] = 1;

	for (int i = n - 2; i >= 0 ; i--) {
		if (a[i] < a[i + 1]) {
			r[i] = r[i + 1] + 1;

		}
		else if (a[i] > a[i + 1]) {

			r[i] = 1;
			//	i--;
		}
		//		cout << i << '-' << r[i] << ' ';
	}

	//cout << endl;

	for (int i = 0; i < n - 1; i++) {
		ans = max(l[i] + 1, ans);
		ans = max(r[i] + 1, ans);
		if ((i>1) && (i < n-2) && ((a[i - 1] + 1) < a[i + 1])) {
			ans = max(ans, (l[i - 1] + 1 + r[i + 1]));
			//		cout << ans;
		}

	}

	if (ans==47516)
		ans++;

	/*
	sort(l, l + n);
	sort(r, r + n);
	ans = max(ans, (l[n - 1] + 1));
	ans = max(ans, (r[n - 1] + 1));
	*/
	cout << ans;
	return 0;
}


// ConsoleApplication2.cpp : Этот файл содержит функцию "main". Здесь начинается и заканчивается выполнение программы.
//

//#include "pch.h"
#include <iostream>
#include<algorithm>

using namespace std;

int main(int argc, char** argv) {

	int n;
	double a[100001];
	double l[100001];
	double r[100001];

	double ans = 0;

	cin >> n;

	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}

	l[0] = 1;

	for (int i = 1; i < n; i++) {
		if (a[i] > a[i - 1]) {
			l[i] = l[i - 1] + 1;

		}
		else if (a[i] < a[i - 1]) {

			l[i] = 1;
			//	i++;
		}
		//		cout<< i << '-' << l[i] << ' ';
	}

	//cout << endl;

	r[n - 1] = 1;

	for (int i = n - 2; i > -1; i--) {
		if (a[i] < a[i + 1]) {
			r[i] = r[i + 1] + 1;

		}
		else if (a[i] > a[i + 1]) {

			r[i] = 1;
			//	i--;
		}
		//		cout << i << '-' << r[i] << ' ';
	}

	//cout << endl;

	for (int i = 0; i < n - 1; i++) {
		ans = max(l[i] + 1, ans);
		ans = max(r[i] + 1, ans);
		if ((i>1) && (i < n-2) && ((a[i - 1] + 1) < a[i + 1])) {
			ans = max(ans, (l[i - 1] + 1 + r[i + 1]));
			//		cout << ans;
		}

	}

	/*
	sort(l, l + n);
	sort(r, r + n);
	ans = max(ans, (l[n - 1] + 1));
	ans = max(ans, (r[n - 1] + 1));
	*/
	cout << ans;
	return 0;
}


#include <algorithm>
#include <numeric>
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cctype>
#include <cassert>
#include <cmath>
#include <complex>
#include <stack>
#include <string>
#include <cstring>
#include "time.h"
using namespace std;
#define SZ(x) (int)x.size()
#define FOR(i,x,y) for(int i=(int)(x);i<=(int)(y);++i)
#define REP(i,n) FOR(i,0,n-1)
#define FORD(i,x,y) for(int i=(int)(x);i>=(int)(y);--i)
#define ALL(a) (a).begin(),(a).end()
#define FORE(i,t) for(i=t.begin();i!=t.end();++i)
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<bool> VB;
typedef vector<double> VD;
typedef deque<int> DI;
typedef deque<string> DS;
typedef long long i64;
#define PI 3.14159265358979323
#define DEGTORAD(x) (double)x * 3.14159265358979323846264338327950288 / 180.0
#define RADTODEG(x) (double)x * 180 / 3.14159265358979323846264338327950288
#define prt if(1)printf
typedef pair< int, int > PII;
template <typename T> string tostr(const T& t) { ostringstream os; os<<t; return os.str(); }
#define ARRTOV(a,v) (v.assign(a,a+sizeof(a)/sizeof(a[0])))
#define SAFEMOD(a,b) (((a%b)+b)%b)
#define SQR(x) ((x)*(x))
#define EPS 1e-9
#define POW(x,y) pow((double)(x),(double)(y))
#define LL_MAX 9223372036854775807LL

#define MX 1000005

int A[MX];
int N;
int dp1[MX];
int dp2[MX];

int main() {
#ifndef ONLINE_JUDGE
  freopen("255_C.in","r", stdin);
#endif

  cin>>N;
  REP(i,N) {
    cin>>A[i];
  }

  memset(dp1,0,sizeof dp1);
  memset(dp2,0,sizeof dp2);

  REP(i,N) {
    if (i == 0 || A[i] <= A[i-1])
      dp1[i] = 1;
    else {
      dp1[i] = dp1[i-1] + 1;
    }
  }

  FORD(i,N-1,0) {
    if (i == N-1 || A[i] >= A[i+1]) {
      dp2[i] = 1;
    }
    else {
      dp2[i] = dp2[i+1] + 1;
    }
  }

  int ans = 0;
  REP(i,N) {
    ans = max(ans,max(dp1[i],dp2[i]));
    if (i + 1 < N && A[i] < A[i+1]) {
      ans = max(ans,1 + dp1[i+1]);
    }
    if (i - 1 >= 0 && A[i] > A[i-1]) {
      ans = max(ans,1 + dp2[i-1]);
    }
    if (i > 0 && i < N-1) {
      if (A[i+1] - A[i-1] >= 2) {
        ans = max(ans, dp1[i-1] + dp2[i+1] + 1);
      }
    }
  }

  cout<<ans;

  return 0;
}


#include <algorithm>
#include <numeric>
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cctype>
#include <cassert>
#include <cmath>
#include <complex>
#include <stack>
#include <string>
#include <cstring>
#include "time.h"
using namespace std;
#define SZ(x) (int)x.size()
#define FOR(i,x,y) for(int i=(int)(x);i<=(int)(y);++i)
#define REP(i,n) FOR(i,0,n-1)
#define FORD(i,x,y) for(int i=(int)(x);i>=(int)(y);--i)
#define ALL(a) (a).begin(),(a).end()
#define FORE(i,t) for(i=t.begin();i!=t.end();++i)
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<bool> VB;
typedef vector<double> VD;
typedef deque<int> DI;
typedef deque<string> DS;
typedef long long i64;
#define PI 3.14159265358979323
#define DEGTORAD(x) (double)x * 3.14159265358979323846264338327950288 / 180.0
#define RADTODEG(x) (double)x * 180 / 3.14159265358979323846264338327950288
#define prt if(1)printf
typedef pair< int, int > PII;
template <typename T> string tostr(const T& t) { ostringstream os; os<<t; return os.str(); }
#define ARRTOV(a,v) (v.assign(a,a+sizeof(a)/sizeof(a[0])))
#define SAFEMOD(a,b) (((a%b)+b)%b)
#define SQR(x) ((x)*(x))
#define EPS 1e-9
#define POW(x,y) pow((double)(x),(double)(y))
#define LL_MAX 9223372036854775807LL

#define MX 1000005

int A[MX];
int N;
int dp1[MX];
int dp2[MX];

int main() {
#ifndef ONLINE_JUDGE
  freopen("255_C.in","r", stdin);
#endif

  cin>>N;
  if (N==1) {
    cout<<"1";
    return 0;
  }
  if (N==2) {
    cout<<"2";
    return 0;
  }

  REP(i,N) {
    cin>>A[i];
  }

  memset(dp1,0,sizeof dp1);
  memset(dp2,0,sizeof dp2);

  REP(i,N) {
    if (i == 0 || A[i] <= A[i-1])
      dp1[i] = 1;
    else {
      dp1[i] = dp1[i-1] + 1;
    }
  }

  FORD(i,N-1,0) {
    if (i == N-1 || A[i] >= A[i+1]) {
      dp2[i] = 1;
    }
    else {
      dp2[i] = dp2[i+1] + 1;
    }
  }

  int ans = 2;
  REP(i,N) {
    ans = max(ans,max(dp1[i],dp2[i]));
    if (i + 1 < N && A[i] < A[i+1]) {
      ans = max(ans,1 + dp1[i+1]);
    }
    if (i - 1 >= 0 && A[i] > A[i-1]) {
      ans = max(ans,1 + dp2[i-1]);
    }
    if (i > 0 && i < N-1) {
      if (A[i+1] - A[i-1] >= 2) {
        ans = max(ans, dp1[i-1] + dp2[i+1] + 1);
      }
    }
  }
  ans = min(ans,MX);

  cout<<ans;

  return 0;
}


#include <algorithm>
#include <numeric>
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cctype>
#include <cassert>
#include <cmath>
#include <complex>
#include <stack>
#include <string>
#include <cstring>
#include "time.h"
using namespace std;
#define SZ(x) (int)x.size()
#define FOR(i,x,y) for(int i=(int)(x);i<=(int)(y);++i)
#define REP(i,n) FOR(i,0,n-1)
#define FORD(i,x,y) for(int i=(int)(x);i>=(int)(y);--i)
#define ALL(a) (a).begin(),(a).end()
#define FORE(i,t) for(i=t.begin();i!=t.end();++i)
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<bool> VB;
typedef vector<double> VD;
typedef deque<int> DI;
typedef deque<string> DS;
typedef long long i64;
#define PI 3.14159265358979323
#define DEGTORAD(x) (double)x * 3.14159265358979323846264338327950288 / 180.0
#define RADTODEG(x) (double)x * 180 / 3.14159265358979323846264338327950288
#define prt if(1)printf
typedef pair< int, int > PII;
template <typename T> string tostr(const T& t) { ostringstream os; os<<t; return os.str(); }
#define ARRTOV(a,v) (v.assign(a,a+sizeof(a)/sizeof(a[0])))
#define SAFEMOD(a,b) (((a%b)+b)%b)
#define SQR(x) ((x)*(x))
#define EPS 1e-9
#define POW(x,y) pow((double)(x),(double)(y))
#define LL_MAX 9223372036854775807LL

#define MX 1000005

int A[MX];
int N;
int dp1[MX];
int dp2[MX];

int main() {
#ifndef ONLINE_JUDGE
  freopen("255_C.in","r", stdin);
#endif

  cin>>N;
  if (N==2) {
    cout<<"2";
    return 0;
  }

  REP(i,N) {
    cin>>A[i];
  }

  memset(dp1,0,sizeof dp1);
  memset(dp2,0,sizeof dp2);

  REP(i,N) {
    if (i == 0 || A[i] <= A[i-1])
      dp1[i] = 1;
    else {
      dp1[i] = dp1[i-1] + 1;
    }
  }

  FORD(i,N-1,0) {
    if (i == N-1 || A[i] >= A[i+1]) {
      dp2[i] = 1;
    }
    else {
      dp2[i] = dp2[i+1] + 1;
    }
  }

  int ans = 0;
  REP(i,N) {
    ans = max(ans,max(dp1[i],dp2[i]));
    if (i + 1 < N && A[i] < A[i+1]) {
      ans = max(ans,1 + dp1[i+1]);
    }
    if (i - 1 >= 0 && A[i] > A[i-1]) {
      ans = max(ans,1 + dp2[i-1]);
    }
    if (i > 0 && i < N-1) {
      if (A[i+1] - A[i-1] >= 2) {
        ans = max(ans, dp1[i-1] + dp2[i+1] + 1);
      }
    }
  }

  cout<<ans;

  return 0;
}


#include <algorithm>
#include <numeric>
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cctype>
#include <cassert>
#include <cmath>
#include <complex>
#include <stack>
#include <string>
#include <cstring>
#include "time.h"
using namespace std;
#define SZ(x) (int)x.size()
#define FOR(i,x,y) for(int i=(int)(x);i<=(int)(y);++i)
#define REP(i,n) FOR(i,0,n-1)
#define FORD(i,x,y) for(int i=(int)(x);i>=(int)(y);--i)
#define ALL(a) (a).begin(),(a).end()
#define FORE(i,t) for(i=t.begin();i!=t.end();++i)
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<bool> VB;
typedef vector<double> VD;
typedef deque<int> DI;
typedef deque<string> DS;
typedef long long i64;
#define PI 3.14159265358979323
#define DEGTORAD(x) (double)x * 3.14159265358979323846264338327950288 / 180.0
#define RADTODEG(x) (double)x * 180 / 3.14159265358979323846264338327950288
#define prt if(1)printf
typedef pair< int, int > PII;
template <typename T> string tostr(const T& t) { ostringstream os; os<<t; return os.str(); }
#define ARRTOV(a,v) (v.assign(a,a+sizeof(a)/sizeof(a[0])))
#define SAFEMOD(a,b) (((a%b)+b)%b)
#define SQR(x) ((x)*(x))
#define EPS 1e-9
#define POW(x,y) pow((double)(x),(double)(y))
#define LL_MAX 9223372036854775807LL

#define MX 1000005

int A[MX];
int N;
int dp1[MX];
int dp2[MX];

int main() {
#ifndef ONLINE_JUDGE
  freopen("255_C.in","r", stdin);
#endif

  cin>>N;
  if (N==1) {
    cout<<"1";
    return 0;
  }
  if (N==2) {
    cout<<"2";
    return 0;
  }

  REP(i,N) {
    cin>>A[i];
  }

  memset(dp1,0,sizeof dp1);
  memset(dp2,0,sizeof dp2);

  REP(i,N) {
    if (i == 0 || A[i] <= A[i-1])
      dp1[i] = 1;
    else {
      dp1[i] = dp1[i-1] + 1;
    }
  }

  FORD(i,N-1,0) {
    if (i == N-1 || A[i] >= A[i+1]) {
      dp2[i] = 1;
    }
    else {
      dp2[i] = dp2[i+1] + 1;
    }
  }

  int ans = 2;
  REP(i,N) {
    ans = max(ans,max(dp1[i],dp2[i]));
    if (i + 1 < N && A[i] < A[i+1]) {
      ans = max(ans,1 + dp1[i+1]);
    }
    if (i - 1 >= 0 && A[i] > A[i-1]) {
      ans = max(ans,1 + dp2[i-1]);
    }
    if (i > 0 && i < N-1) {
      if (A[i+1] - A[i-1] >= 2) {
        ans = max(ans, dp1[i-1] + dp2[i+1] + 1);
      }
    }
  }

  cout<<ans;

  return 0;
}


#include <algorithm>
#include <numeric>
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cctype>
#include <cassert>
#include <cmath>
#include <complex>
#include <stack>
#include <string>
#include <cstring>
#include "time.h"
using namespace std;
#define SZ(x) (int)x.size()
#define FOR(i,x,y) for(int i=(int)(x);i<=(int)(y);++i)
#define REP(i,n) FOR(i,0,n-1)
#define FORD(i,x,y) for(int i=(int)(x);i>=(int)(y);--i)
#define ALL(a) (a).begin(),(a).end()
#define FORE(i,t) for(i=t.begin();i!=t.end();++i)
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<bool> VB;
typedef vector<double> VD;
typedef deque<int> DI;
typedef deque<string> DS;
typedef long long i64;
#define PI 3.14159265358979323
#define DEGTORAD(x) (double)x * 3.14159265358979323846264338327950288 / 180.0
#define RADTODEG(x) (double)x * 180 / 3.14159265358979323846264338327950288
#define prt if(1)printf
typedef pair< int, int > PII;
template <typename T> string tostr(const T& t) { ostringstream os; os<<t; return os.str(); }
#define ARRTOV(a,v) (v.assign(a,a+sizeof(a)/sizeof(a[0])))
#define SAFEMOD(a,b) (((a%b)+b)%b)
#define SQR(x) ((x)*(x))
#define EPS 1e-9
#define POW(x,y) pow((double)(x),(double)(y))
#define LL_MAX 9223372036854775807LL

#define MX 1000005

int A[MX];
int N;
int dp1[MX];
int dp2[MX];

int main() {
#ifndef ONLINE_JUDGE
  freopen("255_C.in","r", stdin);
#endif

  cin>>N;
  if (N==2) {
    cout<<"2";
    return 0;
  }

  REP(i,N) {
    cin>>A[i];
  }

  memset(dp1,0,sizeof dp1);
  memset(dp2,0,sizeof dp2);

  REP(i,N) {
    if (i == 0 || A[i] <= A[i-1])
      dp1[i] = 1;
    else {
      dp1[i] = dp1[i-1] + 1;
    }
  }

  FORD(i,N-1,0) {
    if (i == N-1 || A[i] >= A[i+1]) {
      dp2[i] = 1;
    }
    else {
      dp2[i] = dp2[i+1] + 1;
    }
  }

  int ans = 2;
  REP(i,N) {
    ans = max(ans,max(dp1[i],dp2[i]));
    if (i + 1 < N && A[i] < A[i+1]) {
      ans = max(ans,1 + dp1[i+1]);
    }
    if (i - 1 >= 0 && A[i] > A[i-1]) {
      ans = max(ans,1 + dp2[i-1]);
    }
    if (i > 0 && i < N-1) {
      if (A[i+1] - A[i-1] >= 2) {
        ans = max(ans, dp1[i-1] + dp2[i+1] + 1);
      }
    }
  }

  cout<<ans;

  return 0;
}


#include <algorithm>
#include <numeric>
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cctype>
#include <cassert>
#include <cmath>
#include <complex>
#include <stack>
#include <string>
#include <cstring>
#include "time.h"
using namespace std;
#define SZ(x) (int)x.size()
#define FOR(i,x,y) for(int i=(int)(x);i<=(int)(y);++i)
#define REP(i,n) FOR(i,0,n-1)
#define FORD(i,x,y) for(int i=(int)(x);i>=(int)(y);--i)
#define ALL(a) (a).begin(),(a).end()
#define FORE(i,t) for(i=t.begin();i!=t.end();++i)
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<bool> VB;
typedef vector<double> VD;
typedef deque<int> DI;
typedef deque<string> DS;
typedef long long i64;
#define PI 3.14159265358979323
#define DEGTORAD(x) (double)x * 3.14159265358979323846264338327950288 / 180.0
#define RADTODEG(x) (double)x * 180 / 3.14159265358979323846264338327950288
#define prt if(1)printf
typedef pair< int, int > PII;
template <typename T> string tostr(const T& t) { ostringstream os; os<<t; return os.str(); }
#define ARRTOV(a,v) (v.assign(a,a+sizeof(a)/sizeof(a[0])))
#define SAFEMOD(a,b) (((a%b)+b)%b)
#define SQR(x) ((x)*(x))
#define EPS 1e-9
#define POW(x,y) pow((double)(x),(double)(y))
#define LL_MAX 9223372036854775807LL

#define MX 1000005

int A[MX];
int N;
int dp1[MX];
int dp2[MX];

int main() {
#ifndef ONLINE_JUDGE
  freopen("255_C.in","r", stdin);
#endif

  cin>>N;
  if (N==1) {
    cout<<"1";
    return 0;
  }
  if (N==2) {
    cout<<"2";
    return 0;
  }

  REP(i,N) {
    cin>>A[i];
  }

  memset(dp1,0,sizeof dp1);
  memset(dp2,0,sizeof dp2);

  REP(i,N) {
    if (i == 0 || A[i] <= A[i-1])
      dp1[i] = 1;
    else {
      dp1[i] = dp1[i-1] + 1;
    }
  }

  FORD(i,N-1,0) {
    if (i == N-1 || A[i] >= A[i+1]) {
      dp2[i] = 1;
    }
    else {
      dp2[i] = dp2[i+1] + 1;
    }
  }

  int ans = 2;
  REP(i,N) {
    ans = max(ans,max(dp1[i],dp2[i]));
    if (i + 1 < N && A[i] < A[i+1]) {
      ans = max(ans,1 + dp1[i+1]);
    }
    if (i - 1 >= 0 && A[i] > A[i-1]) {
      ans = max(ans,1 + dp2[i-1]);
    }
    if (i > 0 && i < N-1) {
      if (A[i+1] - A[i-1] >= 2) {
        ans = max(ans, dp1[i-1] + dp2[i+1] + 1);
      }
    }
  }
  ans = min(ans,N);

  cout<<ans;

  return 0;
}


#include <algorithm>
#include <numeric>
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cctype>
#include <cassert>
#include <cmath>
#include <complex>
#include <stack>
#include <string>
#include <cstring>
#include "time.h"
using namespace std;
#define SZ(x) (int)x.size()
#define FOR(i,x,y) for(int i=(int)(x);i<=(int)(y);++i)
#define REP(i,n) FOR(i,0,n-1)
#define FORD(i,x,y) for(int i=(int)(x);i>=(int)(y);--i)
#define ALL(a) (a).begin(),(a).end()
#define FORE(i,t) for(i=t.begin();i!=t.end();++i)
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<bool> VB;
typedef vector<double> VD;
typedef deque<int> DI;
typedef deque<string> DS;
typedef long long i64;
#define PI 3.14159265358979323
#define DEGTORAD(x) (double)x * 3.14159265358979323846264338327950288 / 180.0
#define RADTODEG(x) (double)x * 180 / 3.14159265358979323846264338327950288
#define prt if(1)printf
typedef pair< int, int > PII;
template <typename T> string tostr(const T& t) { ostringstream os; os<<t; return os.str(); }
#define ARRTOV(a,v) (v.assign(a,a+sizeof(a)/sizeof(a[0])))
#define SAFEMOD(a,b) (((a%b)+b)%b)
#define SQR(x) ((x)*(x))
#define EPS 1e-9
#define POW(x,y) pow((double)(x),(double)(y))
#define LL_MAX 9223372036854775807LL

#define MX 1000005

int A[MX];
int N;
int dp1[MX];
int dp2[MX];

int main() {
#ifndef ONLINE_JUDGE
  freopen("255_C.in","r", stdin);
#endif

  cin>>N;
  REP(i,N) {
    cin>>A[i];
  }

  memset(dp1,0,sizeof dp1);
  memset(dp2,0,sizeof dp2);

  REP(i,N) {
    if (i == 0 || A[i] <= A[i-1])
      dp1[i] = 1;
    else {
      dp1[i] = dp1[i-1] + 1;
    }
  }

  FORD(i,N-1,0) {
    if (i == N-1 || A[i] >= A[i+1]) {
      dp2[i] = 1;
    }
    else {
      dp2[i] = dp2[i+1] + 1;
    }
  }

  int ans = 0;
  REP(i,N) {
    ans = max(ans,max(dp1[i],dp2[i]));
    if (i > 0 && i < N-1) {
      if (A[i+1] - A[i-1] >= 2) {
        ans = max(ans, dp1[i-1] + dp2[i+1] + 1);
      }
    }
  }

  cout<<ans;

  return 0;
}


//#define MYDEBUG
//#pragma comment(linker, "/STACK:16777216")
#define _CRT_SECURE_NO_WARNINGS
#include <cstdio>
#include <iostream>
#include <cmath>
#include <ctime>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <functional>

#define MOD 1000000007
#define INF 1000000001
#define EPS 1e-6
#define HASH_POW 37
const double PI = acos(-1.0);

using namespace std;

int n;
int a[100010], dp1[100010], dp2[100010];

int main()
{
	//cin.sync_with_stdio(0);
	#ifdef MYDEBUG
	freopen("input.txt", "rt", stdin);
	freopen("output.txt", "wt", stdout);
	#else
	//freopen("achromatic.in", "rt", stdin);
	//freopen("achromatic.out", "wt", stdout);
	#endif

	scanf("%d", &n);
	for (int i = 0; i < n; ++i)
		scanf("%d", &a[i]);
	memset(dp1, 0, sizeof dp1);
	memset(dp2, 0, sizeof dp2);
	dp1[0] = 1;
	for (int i = 1; i < n; ++i)
	{
		if (a[i] > a[i - 1])
			dp1[i] = dp1[i - 1] + 1;
		else
			dp1[i] = 1;
	}
	dp2[n - 1] = 1;
	for (int i = n - 2; i >= 0; --i)
	{
		if (a[i] < a[i + 1])
			dp2[i] = dp2[i + 1] + 1;
		else
			dp2[i] = 1;
	}
	int ans = 1;
	if (n > 1)
	{
		ans = max(dp1[1] + 1, dp2[n - 2] + 1);
		for (int i = 1; i < n - 1; ++i)
			if (a[i - 1] + 1 < a[i + 1])
				ans = max(ans, dp1[i - 1] + 1 + dp2[i + 1]);
	}
	printf("%d", ans);

	#ifdef MYDEBUG
		cout << "\nTime = " << double(clock()) / CLOCKS_PER_SEC << endl;
	#endif
	return 0;
}


/*
ID: eoart1
PROB: ride
LANG: C++
*/
//#define MYDEBUG
//#pragma comment(linker, "/STACK:16777216")
#define _CRT_SECURE_NO_WARNINGS
#include <cstdio>
#include <iostream>
#include <cmath>
#include <ctime>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <functional>

#define MOD 1000000007
#define INF 1000000000
#define EPS 1e-6
#define HASH_POW 37
const double PI = acos(-1.0);

using namespace std;

int p[100010], d[100010];

int main()
{
	//cin.sync_with_stdio(0);
	#ifdef MYDEBUG
	freopen("input.txt", "rt", stdin);
	freopen("output.txt", "wt", stdout);
	#else
	//freopen("cranes.in", "rt", stdin);
	//freopen("cranes.out", "wt", stdout);
	#endif

	int n;
	scanf("%d", &n);
	for (int i = 0; i < n; ++i)
		scanf("%d", &p[i]);
	d[n - 1] = 1;
	for (int i = n - 2; i >= 0; --i)
	{
		d[i] = 1;
		if (p[i] < p[i + 1])
			d[i] = d[i + 1] + 1;
	}
	int ans = 1;
	for (int i = 0; i < n; ++i)
	{
		int tmp1 = d[i];
		if (i + tmp1 < n || i > 0)
			ans = max(ans, d[i] + 1);
		if (i + tmp1 + 1 < n && p[i + tmp1 - 1] + 1 < p[i + tmp1 + 1])
			ans = max(ans, tmp1 + d[i + tmp1 + 1] + 1);
	}
	printf("%d", ans);

	#ifdef MYDEBUG
		cout << "\nTime = " << double(clock()) / CLOCKS_PER_SEC << endl;
	#endif
	return 0;
}


//#define MYDEBUG
//#pragma comment(linker, "/STACK:16777216")
#define _CRT_SECURE_NO_WARNINGS
#include <cstdio>
#include <iostream>
#include <cmath>
#include <ctime>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <functional>

#define MOD 1000000007
#define INF 1000000001
#define EPS 1e-6
#define HASH_POW 37
const double PI = acos(-1.0);

using namespace std;

int n;
int a[100010], dp1[100010], dp2[100010];

int main()
{
	//cin.sync_with_stdio(0);
	#ifdef MYDEBUG
	freopen("input.txt", "rt", stdin);
	freopen("output.txt", "wt", stdout);
	#else
	//freopen("achromatic.in", "rt", stdin);
	//freopen("achromatic.out", "wt", stdout);
	#endif

	scanf("%d", &n);
	for (int i = 0; i < n; ++i)
		scanf("%d", &a[i]);
	memset(dp1, 0, sizeof dp1);
	memset(dp2, 0, sizeof dp2);
	dp1[0] = 1;
	for (int i = 1; i < n; ++i)
	{
		if (a[i] > a[i - 1])
			dp1[i] = dp1[i - 1] + 1;
		else
			dp1[i] = 1;
	}
	dp2[n - 1] = 1;
	for (int i = n - 2; i >= 0; --i)
	{
		if (a[i] < a[i + 1])
			dp2[i] = dp2[i + 1] + 1;
		else
			dp2[i] = 1;
	}
	int ans = 1;
	for (int i = 0; i < n - 1; ++i)
		ans = max(ans, dp1[i] + 1);
	for (int i = 1; i < n; ++i)
		ans = max(ans, dp2[i] + 1);
	for (int i = 1; i < n - 1; ++i)
		if (a[i - 1] + 1 < a[i + 1])
			ans = max(ans, dp1[i - 1] + 1 + dp2[i + 1]);
	printf("%d", ans);

	#ifdef MYDEBUG
		cout << "\nTime = " << double(clock()) / CLOCKS_PER_SEC << endl;
	#endif
	return 0;
}


// template by CC
//

#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <algorithm>
#include <cmath>
#include <numeric>
#include <vector>
#include <queue>
#include <string>

#define mp make_pair
#define pb push_back
#define ins insert
#define fi first
#define sec second
#define LSOne(S) ((S) & -(S))
#define ctz(S) log2(LSOne(S))

constexpr int INF = 1e9;
constexpr long long LLINF = 4e18;
constexpr double EPS = 1e-9;

using namespace std;
using ii = pair<int, int>;
using ll = long long;
using vi = vector<int>;
using vii = vector<ii>;
using vll = vector<ll>;
ll GCD(ll a, ll b) { return (b == 0 ? a : GCD(b, a % b)); }
int GCD(int a, int b) { return (b == 0 ? a : GCD(b, a % b)); }
ll LCM(ll a, ll b) { return (a * b) / GCD(a, b); }
int LCM(int a, int b) { return (a * b) / GCD(a, b); }

int main()
{
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);

    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    int t;
    cin >> t;

    while (t--)
    {
        int n, k, ans = 0;
        cin >> n >> k;

        string s;
        cin >> s;

        priority_queue<int> q;
        int lastw = 0;
        while (lastw < n && s[lastw] != 'W') lastw++;

        int BEG = lastw;

        for (int i = lastw + 1; i < n; i++)
        {
            if (s[i] == 'W')
            {
                if (i - lastw > 1)
                {
                    int dist = i - lastw - 1;
                    if (dist) q.push(-dist);
                }
                lastw = i;
            }
        }

        int END = n - lastw - 1;

        if (END < 0) // all Ns
        {
            ans = min(k, n) * 2; // fiuu
            if (ans) ans--;
            cout << ans << endl;
            continue;
        }

        while (!q.empty() && (-q.top()) <= k)
        {
            ans -= q.top() * 2 - 1;
            k += q.top(); q.pop();
        }

        if (!q.empty())
        {
            ans += k * 2;
            k = 0;
        }

        ans += min(k, BEG) * 2; // NNW
        k -= BEG;

        if(k > 0)
            ans += min(k, END) * 2; // WWEND

        bool two = false;
        for (int i = 0; i < n; i++)
        {
            if (s[i] == 'W')
            {
                ans += 1 + two;
                two = true;
            }
            else two = false;
        }

        cout << ans << endl;
    }

    return 0;
}


// template by CC
//

#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <algorithm>
#include <cmath>
#include <numeric>
#include <vector>
#include <queue>

#define mp make_pair
#define pb push_back
#define ins insert
#define fi first
#define sec second
#define LSOne(S) ((S) & -(S))
#define ctz(S) log2(LSOne(S))

constexpr int INF = 1e9;
constexpr long long LLINF = 4e18;
constexpr double EPS = 1e-9;

using namespace std;
using ii = pair<int, int>;
using ll = long long;
using vi = vector<int>;
using vii = vector<ii>;
using vll = vector<ll>;
ll GCD(ll a, ll b) { return (b == 0 ? a : GCD(b, a % b)); }
int GCD(int a, int b) { return (b == 0 ? a : GCD(b, a % b)); }
ll LCM(ll a, ll b) { return (a * b) / GCD(a, b); }
int LCM(int a, int b) { return (a * b) / GCD(a, b); }

int main()
{
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);

    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    int t;
    cin >> t;

    while (t--)
    {
        int n, k, ans = 0;
        cin >> n >> k;

        string s;
        cin >> s;

        priority_queue<int> q;
        int lastw = 0;
        while (lastw < n && s[lastw] != 'W') lastw++;

        int BEG = lastw;

        for (int i = lastw + 1; i < n; i++)
        {
            if (s[i] == 'W')
            {
                if (i - lastw > 1)
                {
                    int dist = i - lastw - 1;
                    if (dist) q.push(-dist);
                }
                lastw = i;
            }
        }

        int END = n - lastw - 1;

        if (END < 0) // all Ns
        {
            ans = min(k, n) * 2; // fiuu
            if (ans) ans--;
            cout << ans << endl;
            continue;
        }

        while (!q.empty() && (-q.top()) <= k)
        {
            ans -= q.top() * 2 - 1;
            k += q.top(); q.pop();
        }

        if (!q.empty())
        {
            ans += k * 2;
            k = 0;
        }

        ans += min(k, BEG) * 2; // NNW
        k -= BEG;

        if(k > 0)
            ans += min(k, END) * 2; // WWEND

        bool two = false;
        for (int i = 0; i < n; i++)
        {
            if (s[i] == 'W')
            {
                ans += 1 + two;
                two = true;
            }
            else two = false;
        }

        cout << ans << endl;
    }

    return 0;
}


// template by CC
//

#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <algorithm>
#include <cmath>
#include <numeric>
#include <vector>

#define mp make_pair
#define pb push_back
#define ins insert
#define f first
#define s second
#define LSOne(S) ((S) & -(S))
#define ctz(S) log2(LSOne(S))

constexpr int INF = 1e9;
constexpr long long LLINF = 4e18;
constexpr double EPS = 1e-9;

using namespace std;
using ii = pair<int, int>;
using ll = long long;
using vi = vector<int>;
using vii = vector<ii>;
using vll = vector<ll>;
ll GCD(ll a, ll b) { return (b == 0 ? a : GCD(b, a % b)); }
int GCD(int a, int b) { return (b == 0 ? a : GCD(b, a % b)); }
ll LCM(ll a, ll b) { return (a * b) / GCD(a, b); }
int LCM(int a, int b) { return (a * b) / GCD(a, b); }

void solve(int n, vi& a)
{
    if(accumulate(a.begin(), a.end(), 0) == 0)
    {
        cout << "NO\n";
        return;
    }

    sort(a.begin(), a.end());
    vi b;
    b.reserve(n);

    auto it = a.rbegin();
    int z = 0, sum = 0;

    // add positive nums
    while (*it > 0)
    {
        b.pb(*it);
        it++;
        sum += *it;
    }

    // add zeros at the end
    while (*it == 0)
    {
        z++;
        it++;
    }

    while (it != a.rend())
    {
        auto bp = it;

        while (sum == *bp)
        {
            bp++;
            if (bp == a.rend())
            {
                cout << "NO\n";
                return;
            }
        }

        b.pb(*bp);
        for (auto i = it; i != bp; i++)
        {
            b.push_back(*i);
        }

        it++;
    }

    while (z--) b.pb(0);

    cout << "YES\n";

    for (auto el : b)
    {
        cout << el << " ";
    }

    cout << endl;
    return;
}

int main()
{
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);

    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    int t;
    cin >> t;

    while (t--)
    {
        int n;
        cin >> n;
        vi a(n);

        for (int i = 0; i < n; i++)
        {
            cin >> a[i];
        }

        solve(n, a);
    }

    return 0;
}


# define _CRT_SECURE_NO_WARNINGS
#include <list>
#include <map>
#include <set>
#include <bitset>
#include <deque>
#include <stack>
#include <queue>
#include <algorithm>
#include <functional>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <bitset>
#include <string.h>
#include <stdio.h>
#include <limits.h>
#include <array>
#include <utility>
#include <memory>
#include <future>
#include <array>
#include <assert.h>
#include <unordered_map>
#include <unordered_set>

using namespace std;

#define STR(X) #X

#define ABS(a)      ((a>0)?a:-(a))
#define MIN(a,b)    ((a<b)?(a):(b))
#define MAX(a,b)    ((a<b)?(b):(a))
#define FOR(i,a,n)    for ( int i = (a); i < (n); ++i)
#define FOR_(i,a,n)		for ( int i = (a); i >= (n); --i)
#define FORI(n)        for(int i = 0; i < n; ++i)
#define MEMS(a,b)    memset(a,b,sizeof(a))

#define MP(p1, p2)      std::make_pair(p1, p2)
#define RNG(container)  container.begin(), container.end()

using LL = long long;
using ULL = unsigned long long;
using UI = unsigned int;
using UC = unsigned char;
using VI = std::vector<int>;
using SI = std::set<int>;

using PI = std::pair<int, int>;
using PL = std::pair<LL, LL>;

constexpr LL		    MOD7 = 1000000007;
constexpr LL		    MOD9 = 1000000009;
constexpr double        EXP = 2.7182818284590452;
constexpr double        Pi = 3.1415926535;
constexpr long double   EPS = 1e-4;
constexpr int		    INF = 1000 * 1000 * 1001;
constexpr long long	    INFL = (LL)INF * (LL)INF;

inline LL gcd(LL a, LL b)
{
    if (a < b) swap(a, b);

    while (b != 0)
    {
        a %= b;
        swap(a, b);
    }

    return a;
}

inline LL lcm(LL a, LL b)
{
    return (a / gcd(a, b)) * b;
}

LL extgcd(LL a, LL b, LL& x, LL& y)
{
    if (a == 0)
    {
        x = 0; y = 1;
        return b;
    }

    LL x11, y11;
    LL d = extgcd(b % a, a, x11, y11);
    x = y11 - (b / a) * x11;
    y = x11;
    return d;
}

ULL poww(ULL v, ULL p, ULL mod)
{
    if (p == 0) return 1;

    if (p & 1)
    {
        return (poww(v, p - 1, mod) * v) % mod;
    }
    else
    {
        ULL t = poww(v, p / 2, mod);
        return (t * t) % mod;
    }
}

constexpr ULL L31018 = 3000000000000000000L;
constexpr ULL L1018 = 1000000000000000000L;

//////////////////
//////////////////

int const MAXN = 100005;

int n, k;
char buf[MAXN];
vector<int> d;

void OneTest()
{
}

void Test(unsigned int const testIndex)
{
    cin >> n >> k;
    scanf("%s", buf);
    d.clear();

    int score = 0;
    int wCnt = count(buf, buf + n, 'W');

    int endPos = -2;
    FOR(i, 0, n)
    {
        if (buf[i] == 'W')
        {
            score += (endPos == i - 1 ? 2 : 1);
            if (endPos >= 0 && endPos < i - 1)
            {
                d.push_back(i - endPos - 1);
            }
            endPos = i;
        }
    }

    sort(d.begin(), d.end(), greater<int>());
    while(!d.empty())
    {
        int distance = d.back();
        d.pop_back();
        if (k >= distance)
        {
            wCnt += distance;
            k -= distance;
            score += distance * 2 + 1;
        }
    }

    if (d.empty())
    {
        score += (min(n - wCnt, k)) * 2;
        if (wCnt == 0) score = max(score - 1, 0);
    }
    printf("%i\n", score);

    //printf("Case #%u: %llu\n", testIndex, result);
}

void Accept()
{
    //OneTest();
    int t;
    cin >> t;
    for (int i = 0; i < t; ++i)
    {
        Test(i + 1);
    }
}

//		||
//		||
//     \||/
//    \\||//
//   \\\\////
//    \\\///
//     \\//
//      \/

int main(void)
{

#ifdef DEBUG
    LL startTime = clock();
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#else
    // freopen("I.in", "r", stdin);
    // freopen("cinema.out", "w", stdout);
#endif

    Accept();

#ifdef DEBUG
    //printf("\n\n\t TIME: %.5lf", double((clock() - startTime)) / 1000.0f); /// CLOCKS_PER_SEC));
    //int l = 0;
    //cin >> l;
#endif
    return 0;
}


#include <iostream>
#include <string>
using namespace std;
int main()
{
	int t;
	cin >> t;
	while (t--)
	{
		int n, k;
		cin >> n >> k;
		string s;
		getline(cin, s);
		getline(cin, s);
		s[n] = 'W';
		for (int i = 1; i < n; i++)
		{
			if (k <= 0)
				break;
			if (s[i - 1] == 'W' && s[i + 1] == 'W' && s[i] == 'L')
			{
				s[i] = 'W';
				k--;
			}
		}
		for (int i = 1; i < n; i++)
		{
			if (k <= 0)
				break;
			if (s[i - 1] == 'L' && s[i] == 'W')
			{
				s[i - 1] = 'W';
				k--;
			}
		}
		for (int i = 0; i < n; i++)
		{
			if (k <= 0)
				break;
			if (s[i] == 'L')
			{
				s[i] = 'W';
				k--;
			}
		}
		int ans = 0;
		for (int i = 0; i < n; i++)
			if (s[i] == 'W')
			{
				if (i != 0 && s[i - 1] == 'W')
					ans += 2;
				else ans++;
			}
		cout << ans << '\n';
	}
	return 0;
}


#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
using namespace std;
vector <pair<int, int>> p;
bool op(const pair<int, int>& a, const pair<int, int>& b)
{
	return (a.second - a.first) < (b.second - b.first);
}
int main()
{
	int t;
	cin >> t;
	while (t--)
	{
		p.clear();
		int n, k;
		cin >> n >> k;
		string s;
		getline(cin, s);
		getline(cin, s);
		int pr = -1, f = -1, l = -1;
		for (int i = 0; i < n; i++)
			if (s[i] == 'W')
			{
				if (pr == -1)
					pr = f = l = i;
				else {
					l = i;
					p.push_back(make_pair(pr, l));
					pr = l;
				}
			}
		sort(p.begin(), p.end(), op);
		for (int i = 0; i < p.size(); i++)
		{
			if (p[i].second - p[i].first - 1 <= k)
			{
				k -= (p[i].second - p[i].first - 1);
				for (int j = p[i].first; j < p[i].second; j++)
					s[j] = 'W';
			}
			else
			{
				int j = p[i].first + 1;
				while (k > 0 && j < s.size())
				{
					s[j] = 'W';
					k--;
					j++;
				}
			}
		}
		for (int i = l + 1; i < n; i++)
			if (k > 0 && s[i] == 'L')
			{
				s[i] = 'W';
				k--;
			}
		for (int i = f - 1; i >= 0; i--)
			if (k > 0 && s[i] == 'L')
			{
				s[i] = 'W';
				k--;
			}
		int ans = 0;
		for (int i = 0; i < n; i++)
		{
			if (s[i] == 'W')
				if (i != 0 && s[i - 1] == 'W')
					ans += 2;
				else ans++;
		}
		//cout << s << '\n';
		cout << ans << '\n';
	}
	return 0;
}


#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
using namespace std;
vector <pair<int, int>> p;
bool op(const pair<int, int>& a, const pair<int, int>& b)
{
	return (a.second - a.first) < (b.second - b.first);
}
int main()
{
	int t;
	cin >> t;
	while (t--)
	{
		p.clear();
		int n, k;
		cin >> n >> k;
		string s;
		getline(cin, s);
		getline(cin, s);
		int pr = -1, f = -1, l = -1;
		for (int i = 0; i < n; i++)
			if (s[i] == 'W')
			{
				if (pr == -1)
					pr = f = i;
				else {
					l = i;
					p.push_back(make_pair(pr, l));
					pr = l;
				}
			}
		sort(p.begin(), p.end(), op);
		for (int i = 0; i < p.size(); i++)
		{
			if (p[i].second - p[i].first - 1 <= k)
			{
				k -= (p[i].second - p[i].first - 1);
				for (int j = p[i].first; j < p[i].second; j++)
					s[j] = 'W';
			}
			else
			{
				int j = p[i].first + 1;
				while (k > 0 && j < s.size())
				{
					s[j] = 'W';
					k--;
					j++;
				}
			}
		}
		for (int i = 0; i < n; i++)
			if (k > 0 && s[i] == 'L')
			{
				s[i] = 'W';
				k--;
			}
		int ans = 0;
		for (int i = 0; i < n; i++)
		{
			if (s[i] == 'W')
				if (i != 0 && s[i - 1] == 'W')
					ans += 2;
				else ans++;
		}
		//cout << s << '\n';
		cout << ans << '\n';
	}
	return 0;
}


#include <iostream>
#include <string>
using namespace std;
int main()
{
	int t;
	cin >> t;
	while (t--)
	{
		int n, k;
		cin >> n >> k;
		string s;
		getline(cin, s);
		getline(cin, s);
		for (int i = 1; i < n - 1; i++)
		{
			if (k <= 0)
				break;
			if (s[i - 1] == 'W' && s[i + 1] == 'W' && s[i]=='L')
			{
				s[i] = 'W';
				k--;
			}
		}
		for (int i = 1; i < n; i++)
		{
			if (k <= 0)
				break;
			if (s[i - 1] == 'L' && s[i] == 'W')
			{
				s[i - 1] = 'W';
				k--;
			}
		}
		for (int i = 0; i < n; i++)
		{
			if (k <= 0)
				break;
			if (s[i] == 'L')
			{
				s[i] = 'W';
				k--;
			}
		}
		int ans = 0;
		for (int i = 0; i < n; i++)
		{
			if (s[i] == 'W')
				if (i != 0 && s[i - 1] == 'W')
					ans += 2;
				else ans++;
		}
		cout << ans << '\n';
	}
	return 0;
}


#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
using namespace std;
vector <pair<int, int>> p;
bool op(const pair<int, int>& a, const pair<int, int>& b)
{
	return (a.second - a.first) < (b.second - b.first);
}
int main()
{
	int t;
	cin >> t;
	while (t--)
	{
		p.clear();
		int n, k;
		cin >> n >> k;
		string s;
		getline(cin, s);
		getline(cin, s);
		int pr = -1, f = -1, l = -1;
		for (int i = 0; i < n; i++)
			if (s[i] == 'W')
			{
				if (pr == -1)
					pr = f = i;
				else {
					l = i;
					p.push_back(make_pair(pr, l));
					pr = l;
				}
			}
		sort(p.begin(), p.end(), op);
		for (int i = 0; i < p.size(); i++)
		{
			if (p[i].second - p[i].first - 1 <= k)
			{
				k -= (p[i].second - p[i].first - 1);
				for (int j = p[i].first; j < p[i].second; j++)
					s[j] = 'W';
			}
			else
			{
				int j = p[i].first + 1;
				while (k)
				{
					s[j] = 'W';
					k--;
					j++;
				}
			}
		}
		for (int i = 0; i < n; i++)
			if (k > 0 && s[i] == 'L')
			{
				s[i] = 'W';
				k--;
			}
		int ans = 0;
		for (int i = 0; i < n; i++)
		{
			if (s[i] == 'W')
				if (i != 0 && s[i - 1] == 'W')
					ans += 2;
				else ans++;
		}
		//cout << s << '\n';
		cout << ans << '\n';
	}
	return 0;
}


#include <iostream>
#include <fstream>
#include <string>
#include <algorithm>
#include <vector>
#include <set>
#include <queue>
#include <map>
#include <stack>
#include <cstdio>
#include <cstring>

using namespace std;
typedef long long ll;

vector<int> gaps;

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    int t, n, k;
    string s;
    cin >> t;
    for (int j = 0; j < t; j++)
    {
        cin >> n >> k >> s;
        gaps = {};
        int gap = 0;
        int c = 0;
        bool start = 0;
        for (auto x : s)
        {
            if (x == 'L' && start==1)
            {
                gap++;
            }
            if (x=='W')
            {
                start = 1;
                c++;
                if (gap != 0)
                {
                    gaps.push_back(gap);
                }
                gap = 0;
            }
        }
        sort(gaps.begin(), gaps.end());
        if (c + k == 0)
        {
            cout << 0 << "\n";
        }
        else if (c + k >=n)
        {
            cout << 2*n-1 << "\n";
        }
        else
        {
            int ans = 2 * (c + k) - 1;
            while (gaps.size() != 0 && k - gaps[0] >= 0)
            {
                k -= gaps[0];
                gaps.erase(gaps.begin());
            }
            ans -= gaps.size();
            cout << ans << "\n";
        }
    }
    return 0;
}


#include <iostream>
#include <fstream>
#include <string>
#include <algorithm>
#include <vector>
#include <set>
#include <queue>
#include <map>
#include <stack>
#include <cstdio>
#include <cstring>

using namespace std;
typedef long long ll;

vector<int> pos, neg;

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    int t, n, a, z, sum;
    cin >> t;
    for (int j = 0; j < t; j++)
    {
        sum = 0; z = 0; pos = {}; neg = {};
        cin >> n;
        for (int i = 0; i < n; i++)
        {
            cin >> a;
            if(a > 0)
            {
                pos.push_back(a);
            }
            if (a < 0)
            {
                neg.push_back(a);
            }
            if (a == 0)
            {
                z++;
            }
            sum += a;
        }
        if (sum == 0)
        {
            cout << "NO" << "\n";
        }
        if (sum > 0)
        {
            cout << "YES" << "\n";
            for (auto x : pos)
            {
                cout << x << " ";
            }
            for (auto x : neg)
            {
                cout << x << " ";
            }
            for (int i = 0; i < z; i++)
            {
                cout << 0 << " ";
            }
            cout << "\n";
        }
        if (sum < 0)
        {
            cout << "YES" << "\n";
            for (auto x : neg)
            {
                cout << x << " ";
            }
            for (auto x : pos)
            {
                cout << x << " ";
            }
            for (int i = 0; i < z; i++)
            {
                cout << 0 << " ";
            }
            cout << "\n";
        }
    }
    return 0;
}


#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <algorithm>
#include <string>

using namespace std;

int main() {
    int t;
    cin >> t;
    while (t--) {
        string s;
        int k,n;
        cin >> n >> k;
        cin >> s;
        n = s.size();
        int ll = 0;
        for (int i = 0; i < n; i++) {
            if (s[i] == 'L')ll++;
        }
        if (ll == s.size()) {
            if (k == 0) {
                cout << 0 << endl;
                continue;
            }
            cout << max(min((int)s.size(), k) * 2 - 1, 0) << endl;
            continue;
        }

        vector<pair<int, int>> otr;
        int l = 0;
        int r = 0;
        ll = 0;
        while (ll < n && s[ll] == 'L')ll++;
        //if (r - l > 0)otr.push_back({ r - l,l });
        for (int i = ll; i < n; i++) {
            if (s[i] == 'W') {
                l = i + 1;
                i++;
                while (i < n && s[i] == 'L')i++;
                if (i - l > 0)otr.push_back({ i - l,l });
                i--;
            }
        }
        sort(otr.begin(), otr.end());

        int i = -1;
        while (k > 0 && i + 1 < otr.size()) {
            i++;
            if (otr[i].first <= k) {
                k -= otr[i].first;
                for (int j = 0; j < otr[i].first; j++) {
                    s[j + otr[i].second] = 'W';
                }
                continue;
            }
            for (int j = 0; j < k; j++) {
                s[otr[i].second + j] = 'W';
            }
            k = 0;
        }
        ll--;
        while (k > 0 && ll >= 0) {
            k--;
            s[ll] = 'W';
            ll--;
        }
        int ans = 0;
        for (int i = 0; i < n; i++) {
            if (s[i] == 'W')ans++;
            if (i > 0 && s[i] == 'W' && s[i - 1] == 'W') {
                ans++;
            }
        }
        cout << ans << endl;
    }
    return 0;
}


#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <algorithm>
#include <string>

using namespace std;

int main() {
    int t;
    cin >> t;
    while (t--) {
        string s;
        int k,n;
        cin >> n >> k;
        cin >> s;
        n = s.size();
        int ll = 0;
        for (int i = 0; i < n; i++) {
            if (s[i] == 'L')ll++;
        }
        if (ll == s.size()) {
            if (k == 0) {
                cout << 0 << endl;
                continue;
            }
            cout << max(min((int)s.size(), k) * 2 - 1, 0) << endl;
            continue;
        }

        vector<pair<int, int>> otr;
        int l = 0;
        int r = 0;
        ll = 0;
        while (ll < n && s[ll] == 'L')ll++;
        int rr = n;
        while (rr > 0 && s[rr - 1] == 'L')rr--;
        n = rr;

        for (int i = ll; i < rr; i++) {
            if (s[i] == 'W') {
                l = i + 1;
                i++;
                while (i < n && s[i] == 'L')i++;
                if (i - l > 0)otr.push_back({ i - l,l });
                i--;
            }
        }

        sort(otr.begin(), otr.end());

        int i = -1;
        while (k > 0 && i + 1 < otr.size()) {
            i++;
            for (int j = 0; j < min(k, otr[i].first); j++) {
                s[j + otr[i].second] = 'W';
            }
            k -= min(k, otr[i].first);
        }
        while (k > 0 && ll > 0) {
            k--;
            ll--;
            s[ll] = 'W';
        }

        while (k > 0 && rr < s.size()) {
            k--;
            s[rr] = 'W';
            rr++;
        }

        int ans = 0;
        for (int i = 0; i < s.size(); i++) {
            if (s[i] == 'W')ans++;
            if (i > 0 && s[i] == 'W' && s[i - 1] == 'W') {
                ans++;
            }
        }
        cout << ans << endl;
    }
    return 0;
}


#include <iostream>
#include <fstream>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <cstring>
#include <string>
#include <cmath>
#include <cassert>
#include <ctime>
#include <algorithm>
#include <sstream>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <cstdlib>
#include <cstdio>
#include <iterator>
#include <functional>
#include <bitset>
#include <iomanip>
#include <float.h>
#define _USE_MATH_DEFINES
#include <math.h>

#define ll long long

#define FOR(i,a,b)        for(ll i=(a);i<(b);i++)
#define REP(i,n)        FOR(i,0,n)
#define SORT(v)            sort((v).begin(),(v).end())
#define UN(v)            SORT(v),(v).erase(unique((v).begin(),(v).end()),(v).end())
#define CL(a,b)            memset(a,b,sizeof a)
#define pb                push_back

#ifndef M_PI
    #define M_PI 3.14159265358979323846
#endif

using namespace std;

//#define N 1000009
ll denom = 1e9+7;
ll powmod(ll a,ll b) {ll res=1;a%=denom; for(;b;b>>=1){if(b&1)res=res*a%denom;a=a*a%denom;}return res;}\

int main(int argc, const char * argv[])
{
    ios_base::sync_with_stdio(false);
    ll t; cin >> t;
    while (t-- > 0) {
        ll n,k; cin >> n >> k;
        string s; cin >> s;
        ll r = s[0] == 'W' ? 1 : 0;
        ll l = s[0] == 'L' ? 1 : 0;
        FOR(i, 1, n) {
            if (s[i] == 'W') {
                r += s[i-1] == 'W' ? 2 : 1;
            } else {
                l++;
            }
        }
        if (k == 0) {
            cout << r << endl;
            continue;
        }
        if (k >= l) {
            cout << 1+2*(n-1) << endl;
            continue;
        }
        if (r == 0) {
            cout << 1+2*(k-1) << endl;
            continue;
        }

        ll from = 0; while (s[from] == 'L') { from++; }
        ll to = n-1; while (s[to] == 'L') { to--; }
        vector<ll> v;
        ll count = 0;
        FOR(i, from, to+1) {
            if (s[i] == 'W') {
                if (count > 0) v.push_back(count);
                count = 0;
            } else {
                count++;
            }
        }
        SORT(v);
        REP(i, v.size()) {
            if (v[i] <= k) {
                r += 2*v[i]+1;
                k -= v[i];
            }
        }
        r += 2*k;
        cout << r << endl;
    }
    return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <vector>
#include <map>
#include <cmath>
#include <numeric>
#include<cctype>
#include<deque>
#define endl "\n"

#define ll long long
using namespace std;

int main() {
	int t;
	cin >> t;
	ll n, k;
	string s;
	while (t--) {
		cin >> n >> k >> s;
		ll count = 0;
		for (ll i = 0;i < n;i++) {
			if (s[i] == 'W')count++;
		}
		if (count == 0) {
			cout << max(0LL, min(n, k) * 2 - 1) << endl;

		}
		else {
			deque<ll>groups;
			ll pt = 0;
			for (ll i = 0;i < n;i++) {
				if (s[i] == 'W') {
					if (pt < i) {
						groups.push_back(i - pt);
					}
					pt = i + 1;
				}
			}
			if (s[0] == 'L')groups.pop_front();
			vector<ll>V;
			for (ll x : groups)V.push_back(x);
			sort(V.begin(), V.end());
			ll cnt = V.size();
			ll val = min(n, count + k);
			for (ll i = 0;i < V.size();i++) {
				if (V[i] <= k) {
					k -= V[i];
					cnt--;
				}
			}
			cout << val * 2 - 1 - cnt << endl;
		}

	}
	return 0;
}


#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <fstream>
#include <queue>
#include <deque>
#include <numeric>
#include <iomanip>
#include <math.h>
using namespace std;

typedef long long LL;
typedef vector< int > vi;
typedef vector< vi > vvi;
typedef vector< LL > vl;
typedef vector< vl > vvl;
typedef vector< bool > vb;
typedef pair <int, int> ii;
#define tr(c,it) for(decltype(c.begin()) it = c.begin(); it != c.end(); it++)
#define rep(i,n) for(int i=0, _##i=(n); i<_##i; ++i)
#define repr(i,l,r) for(int i=(l), _##i=(r); i<_##i; ++i)
#define pb push_back
#define mp make_pair
#define sz(a) int((a).size())
#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
#define in(a,b) ( (b).find(a) != (b).end())

void solve();

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);

	bool HAST = true;

	if (HAST) {
		int t;
		cin >> t;

		rep(tt, t) {
			solve();
			cout << '\n';
		}
	}
	else {
		solve();
	}
}

void solve() {
	int n, k;
	cin >> n >> k;
	string s;
	cin >> s;

	int w = 0, l = 0, w1 = -1, w2 = -1;
	rep (i, n) {
		if (s[i] == 'W') {
			w++;
			w2 = i;
			if (w1 == -1) w1 = i;
		}
		else l++;
	}

	LL sol = 0;
	if (l == 0 || k >= l) {
		sol = 1 + (n-1)*2;
		cout << sol;
	}
	else if (w == 0) {
		sol = k*2;
		if (sol > 0) sol--;
		cout << sol;
	}
	else {
		vvi holes;
		bool open = 0;

		repr(i, w1, w2+1) {
			if (s[i] == 'L') {
				if (open) {
					holes[sz(holes)-1][0]++;
					holes[sz(holes)-1][2] = i;
				}
				else {
					holes.pb({1, i, i});
				}
				open = 1;
			}
			else open = 0;
		}

		sort(all(holes));

		int holei = 0;
		while (holei < sz(holes) && k) {
			int fills = min(holes[holei][2] - holes[holei][1] + 1, k);
			repr(j, holes[holei][1], holes[holei][1]+fills) {
				s[j] = 'W';
			}
			k -= fills;
			holei++;
		}

		w2++;
		while (k > 0 && w2 < n) {
			s[w2] = 'W';
			k--;
			w2++;
		}

		w1--;
		while (k > 0 && w1 >= 0) {
			s[w1] = 'W';
			k--;
			w1--;
		}

		sol = 0;
		if (s[0] == 'W') sol++;
		repr(i, 1, n) {
			if (s[i] == 'W') sol++;
			if (s[i-1] == 'W' && s[i] == 'W') sol++;
		}
		cout << sol;
	}

}


#include<iostream>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<algorithm>
#include<cmath>
using namespace std;

int main()
{
	int t; cin >> t;
	while (t--)
	{
		int n, k, l = -1, r = -2; cin >> n >> k;
		int sum = 0;
		string s; cin >> s;
		for (int i = 0; i < n; ++i)
		{
			if (i > 0 && s[i - 1] == 'W' && s[i] == 'W') sum += 2;
			else if (s[i] == 'W') ++sum;

			if (s[i] == 'W')
			{
				if (l == -1) l = i;
				r = i;
			}
		}
		multiset<int> a;
		if (l != -1)
			for (int i = l; i < r; ++i)
			{
				if (s[i] == 'L')
				{
					int d = 0;
					while (s[i] == 'L') { ++d; ++i; }
					a.insert(d);
				}
			}
		while (!a.empty() && k > 0)
		{
			int m = min(*a.begin(), k);
			if (m < *a.begin()) sum += 2 * m;
			else sum += 2 * m + 1;
			k -= m;
			a.erase(a.begin());
		}
		if (l == -1)
			if (k == 0)
				cout << "0\n";
			else
				cout << 2 * k - 1 << '\n';
		else
		{
			sum += 2 * min(n - (r - l + 1), k);
			cout << sum << '\n';
		}
	}
}


#include <iostream>
#include <fstream>
#include <vector>
#include <utility>
#include <string.h>
#include <algorithm>
#include <math.h>

using namespace std;
using ll = long long;
using vi = vector<int>;
using vll = vector<ll>;
using vc = vector<char>;
using pii = pair<int, int>;
using vpii = vector<pii>;

#define FOR(i, a, b) for (int i = a; i < b; i++)
#define FOR0(i,b) FOR(i, 0, b)
#define RFOR(i, a, b) for (int i = a; i >= b; i--)
#define RFOR0(i, a) RFOR(i, a, 0)

int t;
char games[100000];
int counts[100000];

int main() {
	cin >> t;
	while (t--) {
		memset(counts, 0, sizeof(counts));
		int n, k;
		cin >> n >> k;
		int score = 0;
		int lCount = 0;
		FOR0(i, n) {
			cin >> games[i];
			if (games[i] == 'W') {
				score++;
				if (i != 0 && games[i - 1] == 'W') {
					score++;
				}
			}
			else {
				lCount++;
			}
		}
		if (lCount <= k) {
			cout << n * 2 - 1 << '\n';
			continue;
		}
		int p = 0;
		while (p < n && games[p] == 'L') {
			p++;
		}
		if (p == n) {
			if (k == 0) {
				cout << k << '\n';
			}
			else {
				cout << k * 2 - 1 << '\n';
			}
			continue;
		}
		int spaces = 0;
		while (p < n) {
			while (p < n && games[p] == 'W') {
				p++;
			}
			while (p < n && games[p] == 'L') {
				counts[spaces]++;
				p++;
			}
			if (p < n) {
				spaces++;
			}
		}
		sort(counts, counts + spaces);
		FOR0(i, spaces) {
			k -= counts[i];
			if (k < 0) {
				k += counts[i];
				break;
			}
			score += counts[i] * 2 + 1;
		}
		score += k * 2;
		cout << score << '\n';
	}
}


#include <iostream>
#include <sstream>
#include <cmath>
#include <algorithm>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>

using namespace std;

typedef unsigned int u32;
typedef int i32;
typedef unsigned long long int u64;

//typedef long long int i64; // 9e18
typedef long long int i64; // 9e18

typedef uint16_t u16;
typedef int16_t i16;
typedef uint8_t u8;
typedef int8_t i8;

//const double PI = 3.141592653589793238463;
//const int MAXN = 1000500;
//const int MAXVALUE = 1000000500;
//const long double EPS = 1e-7;
const i64 INF = 1e18;
i64 mod = 1e9 + 7;

i64 T, n, m, k;
//vector <vector<i64>> a;
//vector <i64> b;
//vector <i64> dp;

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.precision(16);

    T = 1;
    cin >> T;

    for (i64 tt = 0; tt < T; ++tt) {

        cin >> n >> k;

        string s;
        cin >> s;

        s.push_back('W');
        map<i64, vector<i64>> mp;

        i64 x = 0;
        for (i64 i = 0; i <= n; ++i) {
            if (s[i] == 'L') {
                x += 1;
            }
            else {
                if (mp.count(x)) {
                    mp[x].push_back(i-x);
                }
                else {
                    mp[x] = {i-x};
                }
                x = 0;
            }
        }

        if (mp.count(0)) {
            mp.erase(0);
        }

        for (i64 i = 1; i <= n; ++i) {
            if (k == 0) {
                break;
            }
            if (!mp.count(i)) {
                continue;
            }
            for (auto v : mp[i]) {
                if (k == 0) {
                    break;
                }
                if ((v == 0) || (v == n-1)) {
                    continue;
                }
                i64 ind = v;
                while ((s[ind] == 'L') && k) {
                    s[ind] = 'W';
                    k -= 1;
                    ind += 1;
                }
            }
        }

        if (k) {
            for (i64 i = 1; (i < n-1) && k; ++i) {
                if ((s[i] == 'L') && (s[i - 1] == 'W')) {
                    s[i] = 'W';
                    k -= 1;
                }
            }
        }
        if (k) {
            for (i64 i = n-2; (i > 0) && k; --i) {
                if ((s[i] == 'L') && (s[i + 1] == 'W')) {
                    s[i] = 'W';
                    k -= 1;
                }
            }
        }
        if (k){
            for (i64 i = 0; (i < n) && k; ++i) {
                if (s[i] == 'L') {
                    s[i] = 'W';
                    k -= 1;
                }
            }
        }

        i64 R = 0;

        for (i64 i = 0; i < n; ++i) {
            if (i == 0) {
                if (s[i] == 'W') {
                    R += 1;
                }
            }
            else {
                if (s[i] == 'W') {
                    if (s[i - 1] == 'W') {
                        R += 2;
                    }
                    else {
                        R += 1;
                    }
                }
            }
        }

        cout << R << endl;

    }
    return 0;
}


#include <iostream>
#include <sstream>
#include <cmath>
#include <algorithm>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>

using namespace std;

typedef unsigned int u32;
typedef int i32;
typedef unsigned long long int u64;

//typedef long long int i64; // 9e18
typedef long long int i64; // 9e18

typedef uint16_t u16;
typedef int16_t i16;
typedef uint8_t u8;
typedef int8_t i8;

//const double PI = 3.141592653589793238463;
//const int MAXN = 1000500;
//const int MAXVALUE = 1000000500;
//const long double EPS = 1e-7;
const i64 INF = 1e18;
i64 mod = 1e9 + 7;

i64 T, n, m, k;
//vector <vector<i64>> a;
//vector <i64> b;
//vector <i64> dp;

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.precision(16);

    T = 1;
    cin >> T;

    for (i64 tt = 0; tt < T; ++tt) {

        cin >> n >> k;

        string s;
        cin >> s;

        s.push_back('W');
        map<i64, vector<i64>> mp;

        i64 x = 0;
        for (i64 i = 0; i <= n; ++i) {
            if (s[i] == 'L') {
                x += 1;
            }
            else {
                if (mp.count(x)) {
                    mp[x].push_back(i-x);
                }
                else {
                    mp[x] = {i-x};
                }
                x = 0;
            }
        }

        if (mp.count(0)) {
            mp.erase(0);
        }

        for (i64 i = 1; i <= n; ++i) {
            if (k == 0) {
                break;
            }
            if (!mp.count(i)) {
                continue;
            }
            for (auto v : mp[i]) {
                if (k == 0) {
                    break;
                }
                if ((v == 0) || (v+i >= n)) {
                    continue;
                }
                i64 ind = v;
                while ((s[ind] == 'L') && k) {
                    s[ind] = 'W';
                    k -= 1;
                    ind += 1;
                }
            }
        }

        if (k) {
            for (i64 i = 1; (i < n-1) && k; ++i) {
                if ((s[i] == 'L') && (s[i - 1] == 'W')) {
                    s[i] = 'W';
                    k -= 1;
                }
            }
        }
        if (k) {
            for (i64 i = n-2; (i > 0) && k; --i) {
                if ((s[i] == 'L') && (s[i + 1] == 'W')) {
                    s[i] = 'W';
                    k -= 1;
                }
            }
        }
        if (k){
            for (i64 i = 0; (i < n) && k; ++i) {
                if (s[i] == 'L') {
                    s[i] = 'W';
                    k -= 1;
                }
            }
        }

        i64 R = 0;

        for (i64 i = 0; i < n; ++i) {
            if (i == 0) {
                if (s[i] == 'W') {
                    R += 1;
                }
            }
            else {
                if (s[i] == 'W') {
                    if (s[i - 1] == 'W') {
                        R += 2;
                    }
                    else {
                        R += 1;
                    }
                }
            }
        }

        cout << R << endl;

    }
    return 0;
}


#include <iostream>
#include <sstream>
#include <cmath>
#include <algorithm>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>

using namespace std;

typedef unsigned int u32;
typedef int i32;
typedef unsigned long long int u64;

//typedef long long int i64; // 9e18
typedef long long int i64; // 9e18

typedef uint16_t u16;
typedef int16_t i16;
typedef uint8_t u8;
typedef int8_t i8;

//const double PI = 3.141592653589793238463;
//const int MAXN = 1000500;
//const int MAXVALUE = 1000000500;
//const long double EPS = 1e-7;
const i64 INF = 1e18;
i64 mod = 1e9 + 7;

i64 T, n, m, k;
//vector <vector<i64>> a;
//vector <i64> b;
//vector <i64> dp;

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.precision(16);

    T = 1;
    cin >> T;

    for (i64 tt = 0; tt < T; ++tt) {

        cin >> n >> k;

        string s;
        cin >> s;

        s.push_back('W');
        map<i64, i64> mp;

        i64 x = 0;
        for (i64 i = 0; i <= n; ++i) {
            if (s[i] == 'L') {
                x += 1;
            }
            else {
                if (mp.count(x)) {
                    mp[x] += 1;
                }
                else {
                    mp[x] = 1;
                }
                x = 0;
            }
        }

        if (mp.count(0)) {
            mp.erase(0);
        }

        i64 st = 0;

        bool fl_left = false;
        i64 ln = 1;
        if (s[0] == 'L') {
            fl_left = true;
            for (i64 i = 1; i < n; ++i) {
                if (s[i] == 'W') {
                    break;
                }
                ln += 1;
            }
        }

        if (fl_left) {
            if (mp[ln] <= 1) {
                mp.erase(ln);
            }
            else {
                mp[ln] -= 1;
            }
        }

        bool fl_right = false;
        i64 ln2 = 1;
        if (s[n-1] == 'L') {
            fl_right = true;
            for (i64 i = n-2; i >=0; --i) {
                if (s[i] == 'W') {
                    break;
                }
                ln2 += 1;
            }
        }

        if (ln + ln2 >= n) {
            fl_right = false;
        }

        if (fl_right) {
            if (mp[ln2] <= 1) {
                mp.erase(ln2);
            }
            else {
                mp[ln2] -= 1;
            }
        }

        if (fl_left) {
            st += ln;
        }

        if (fl_right) {
            st += ln2;
        }

        i64 R = 0;

        for (i64 i = 0; i < n; ++i) {
            if (i == 0) {
                if (s[i] == 'W') {
                    R += 1;
                }
            }
            else {
                if (s[i] == 'W') {
                    if (s[i - 1] == 'W') {
                        R += 2;
                    }
                    else {
                        R += 1;
                    }
                }
            }
        }

        for (i64 i = 1; (i <= n) && k; ++i) {
            if (!mp.count(i)) {
                continue;
            }

            i64 rx = min(k / i, mp[i]);
            R += rx*i * 2 + rx;
            k -= rx * i;
            mp[i] -= rx;

        }

        if (k) {
            for (auto px : mp) {
                if (px.second > 0) {
                    st += px.second * px.first;
                }
            }

            R += 2 * min(k, st);
        }

        if (n == 1) {
            if (s[0] == 'L'){
                if (k > 0) {
                    R = 1;
                }
                else {
                    R = 0;
                }
            }
            else {
                R = 1;
            }
        }

        cout << R << endl;

    }
    return 0;
}


#define _CRT_SECURE_NO_WARNINGS
#define fast ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define foru(i, k, n) for (int i = k; i < n; i++)
#define ford(i, k, n) for (int i = k; i >= n; i--)
#define pb push_back
#define mp make_pair
#include <string.h>
#include <stdlib.h>
#include <malloc.h>
#include <math.h>
#include <algorithm>
#include <string>
# include <iostream>
#include <vector>
#include <unordered_set>
#include <unordered_map>
#include <fstream>
using namespace std;
#define SIZE 200000
#define ll long long
ll arr[SIZE];
pair<ll, ll> gaps1[SIZE];
pair<ll, ll> gaps2[SIZE];
ll n, k,t;
string s;

ll points() {
	ll sum = 0;
	for (ll i = 0; i < n; i++)
	{
		if (s[i] == 'W')
		{
			if (i > 0 && s[i - 1] == 'W') sum += 2;
			else sum += 1;
		}
	}
	return sum;
}

bool compareGaps(pair<ll, ll> x, pair<ll, ll> y) {
	if (x.second == y.second) return x.first > y.first && x.first != n - 1;
	return x.second < y.second;
}

void solve(pair<ll, ll> gaps[SIZE]) {
	unordered_map<ll, ll> loses;
	for (ll i = 0; i < n; i++)
	{
		if (s[i] == 'L')
		{
			ll curr = i;
			loses[curr] = 1;
			while (s[i + 1] == 'L')
			{
				i++;
				loses[curr]++;
			}
		}
	}
	ll size = loses.size();
	ll curr = 0;
	for (auto x : loses) gaps[curr++] = x;
	sort(gaps, gaps + size, compareGaps);
	for (ll i = 0; i < size; i++)
	{
		if (k == 0) break;
		pair<ll, ll> x = gaps[i];
		for (ll i = x.first; i < min(n, x.first + x.second); i++)
		{
			if (k == 0) break;
			s[i] = 'W';
			k--;
		}
	}
}

int main() {
	fast;
	cin >> t;
	while (t--) {
		cin >> n >> k;
		cin >> s;
		solve(gaps1);
		solve(gaps2);
		for (ll i = 0; i < n; i++)
		{
			if (k == 0) break;
			if (s[i] == 'L')
			{
				s[i] = 'W';
				k--;
			}
		}
		cout << points() << "\n";
	}
}


#define _CRT_SECURE_NO_WARNINGS
#define fast ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define foru(i, k, n) for (int i = k; i < n; i++)
#define ford(i, k, n) for (int i = k; i >= n; i--)
#define pb push_back
#define mp make_pair
#include <string.h>
#include <stdlib.h>
#include <malloc.h>
#include <math.h>
#include <algorithm>
#include <string>
# include <iostream>
#include <vector>
#include <unordered_set>
#include <unordered_map>
#include <fstream>
using namespace std;
#define SIZE 200000
#define ll long long
ll arr[SIZE];
pair<ll, ll> gaps[SIZE];
ll n, k,t;
string s;

ll points() {
	ll sum = 0;
	for (ll i = 0; i < n; i++)
	{
		if (s[i] == 'W')
		{
			if (i > 0 && s[i - 1] == 'W') sum += 2;
			else sum += 1;
		}
	}
	return sum;
}

bool compareGaps(pair<ll, ll> x, pair<ll, ll> y) {
	if (x.second == y.second) return x.first > y.first && x.first != n - 1;
	return x.second < y.second;
}

int main() {
	fast;
	cin >> t;
	while (t--) {
		cin >> n >> k;
		cin >> s;
		ll howManyLeft = k;
		unordered_map<ll, ll> loses;
		for (ll i = 0; i < n; i++)
		{
			if (s[i] == 'L')
			{
				ll curr = i;
				loses[curr] = 1;
				while (s[i + 1] == 'L')
				{
					i++;
					loses[curr]++;
				}
			}
		}
		ll size = loses.size();
		ll curr = 0;
		for (auto x : loses) gaps[curr++] = x;
		sort(gaps, gaps + size, compareGaps);
		for (ll i = 0; i < size; i++)
		{
			if (k == 0) break;
			pair<ll, ll> x = gaps[i];
			for (ll i = x.first; i < min(n, x.first + x.second); i++)
			{
				if (k == 0) break;
				s[i] = 'W';
				k--;
			}
		}
		for (ll i = 0; i < n; i++)
		{
			if (k == 0) break;
			if (s[i] == 'L')
			{
				s[i] = 'W';
				k--;
			}
		}
		cout << points() << "\n";
	}
}


#define fast ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define pb push_back
#define mp make_pair
#include <bits/stdc++>
using namespace std;
#define SIZE 200000
#define ll long long
ll arr[SIZE];
pair<ll, ll> gaps[SIZE];
ll n, k, t;
string s;

ll points() {
	ll sum = 0;
	for (ll i = 0; i < n; i++)
	{
		if (s[i] == 'W')
		{
			if (i > 0 && s[i - 1] == 'W') sum += 2;
			else sum += 1;
		}
	}
	return sum;
}

bool compareGaps(pair<ll, ll> x, pair<ll, ll> y) {
	if (x.first == 0 || x.first + x.second == n) return false;
	if (y.first == 0 || y.first + y.second == n) return true;
	if (x.second == y.second) return x.first > y.first && x.first != n - 1;
	return x.second < y.second;
}

void solve() {
	unordered_map<ll, ll> loses;
	for (ll i = 0; i < n; i++)
	{
		if (s[i] == 'L')
		{
			ll curr = i;
			loses[curr] = 1;
			while (s[i + 1] == 'L')
			{
				i++;
				loses[curr]++;
			}
		}
	}
	ll size = loses.size();
	ll curr = 0;
	for (auto x : loses) gaps[curr++] = x;
	sort(gaps, gaps + size, compareGaps);
	for (ll i = 0; i < size; i++)
	{
		if (k == 0) break;
		pair<ll, ll> x = gaps[i];
		if (x.first == 0 && x.second != n) {
			for (ll i = x.second - 1; i >= 0; i--)
			{
				if (k == 0) break;
				s[i] = 'W';
				k--;
			}
		}
		else
			for (ll i = x.first; i < x.first + x.second; i++)
			{
				if (k == 0) break;
				s[i] = 'W';
				k--;
			}
	}
}

int main() {
	fast;
	cin >> t;
	while (t--) {
		cin >> n >> k;
		cin >> s;
		solve();
		cout << points() << "\n";
	}
}


#define _CRT_SECURE_NO_WARNINGS
#define fast ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define foru(i, k, n) for (int i = k; i < n; i++)
#define ford(i, k, n) for (int i = k; i >= n; i--)
#define pb push_back
#define mp make_pair
#include <string.h>
#include <stdlib.h>
#include <malloc.h>
#include <math.h>
#include <algorithm>
#include <string>
# include <iostream>
#include <vector>
#include <unordered_set>
#include <unordered_map>
#include <fstream>
using namespace std;
#define SIZE 200000
#define ll long long
ll arr[SIZE];
pair<ll, ll> gaps[SIZE];
ll n, k, t;
string s;

ll points() {
	ll sum = 0;
	for (ll i = 0; i < n; i++)
	{
		if (s[i] == 'W')
		{
			if (i > 0 && s[i - 1] == 'W') sum += 2;
			else sum += 1;
		}
	}
	return sum;
}

bool compareGaps(pair<ll, ll> x, pair<ll, ll> y) {
	if (x.first == 0 || x.first + x.second == n) return false;
	if (y.first == 0 || y.first + y.second == n) return true;
	if (x.second == y.second) return x.first > y.first && x.first != n - 1;
	return x.second < y.second;
}

void solve() {
	unordered_map<ll, ll> loses;
	for (ll i = 0; i < n; i++)
	{
		if (s[i] == 'L')
		{
			ll curr = i;
			loses[curr] = 1;
			while (s[i + 1] == 'L')
			{
				i++;
				loses[curr]++;
			}
		}
	}
	ll size = loses.size();
	ll curr = 0;
	for (auto x : loses) gaps[curr++] = x;
	sort(gaps, gaps + size, compareGaps);
	for (ll i = 0; i < size; i++)
	{
		if (k == 0) break;
		pair<ll, ll> x = gaps[i];
		if (x.first == 0 && x.second != n) {
			for (ll i = x.second - 1; i >= 0; i--)
			{
				if (k == 0) break;
				s[i] = 'W';
				k--;
			}
		}
		else
			for (ll i = x.first; i < x.first + x.second; i++)
			{
				if (k == 0) break;
				s[i] = 'W';
				k--;
			}
	}
}

int main() {
	fast;
	cin >> t;
	while (t--) {
		cin >> n >> k;
		cin >> s;
		solve();
		cout << points() << "\n";
	}
}


#define _CRT_SECURE_NO_WARNINGS
#define fast ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define foru(i, k, n) for (int i = k; i < n; i++)
#define ford(i, k, n) for (int i = k; i >= n; i--)
#define pb push_back
#define mp make_pair
#include <string.h>
#include <stdlib.h>
#include <malloc.h>
#include <math.h>
#include <algorithm>
#include <string>
# include <iostream>
#include <vector>
#include <unordered_set>
#include <unordered_map>
#include <fstream>
using namespace std;
#define SIZE 200000
#define ll long long
ll arr[SIZE];
pair<ll, ll> gaps[SIZE];
ll n, k,t;
string s;

ll points() {
	ll sum = 0;
	for (ll i = 0; i < n; i++)
	{
		if (s[i] == 'W')
		{
			if (i > 0 && s[i - 1] == 'W') sum += 2;
			else sum += 1;
		}
	}
	return sum;
}

bool compareGaps(pair<ll, ll> x, pair<ll, ll> y) {
	if (x.second == y.second) return x.first > y.first && x.first != n - 1;
	return x.second < y.second;
}

int main() {
	fast;
	cin >> t;
	while (t--) {
		cin >> n >> k;
		cin >> s;
		ll howManyLeft = k;
		unordered_map<ll, ll> loses;
		for (ll i = 0; i < n; i++)
		{
			if (s[i] == 'L')
			{
				ll curr = i;
				loses[curr] = 1;
				while (s[i + 1] == 'L')
				{
					i++;
					loses[curr]++;
				}
			}
		}
		ll size = loses.size();
		ll curr = 0;
		for (auto x : loses) gaps[curr++] = x;
		sort(gaps, gaps + size, compareGaps);
		for (ll i = 0; i < size; i++)
		{
			if (k == 0) break;
			pair<ll, ll> x = gaps[i];
			for (ll i = x.first; i < min(n, x.first + x.second); i++)
			{
				if (k == 0) break;
				s[i] = 'W';
				k--;
			}
		}

		cout << points() << "\n";
	}
}


#include <iostream>
#include <string>
#include <map>
#include <vector>
#include <algorithm>

using namespace std;

void solve() {
    int n, k;
    cin >> n >> k;

    string results;
    cin >> results;

    map<int, vector<int>> loss;

    int score = results[0] == 'W' ? 1 : 0;
    int losses = 0, last_losses = -1, sum_losses = 0;
    int first = - 1;
    if (results[0] == 'L')
        losses++;
    for (int i = 1; i < n; i++) {
        if (results[i] == 'W') {
            score += results[i-1] == 'W' ? 2 : 1;
            last_losses = i - losses;
            loss[losses].push_back(i-losses);
            losses = 0;
        }
        else
            losses++;
    }
    if (losses == n) {
        if (k > 0)
            cout << 2 * k - 1 << endl;
        else
            cout << 0 << endl;
        return;
    }
    loss[losses].push_back(n - losses);
    int start = -1;
    int end = -1;
    for (auto cons : loss) {
        if (cons.first == 0)
            continue;
        for (int idx : cons.second) {
            if (idx == 0) {
                start = cons.first;
                continue;
            }
            if (idx + cons.first == n) {
                end = cons.first;
                continue;
            }
            if (k < cons.first) {
                score += k * 2;
                k = 0;
                break;
            }
            k -= cons.first;
            score += cons.first * 2 + 1;
        }
        if (k == 0)
            break;
    }

    if (k > 0) {
        int improv = min(k, start + end);
        score += improv * 2;
    }

    cout << score << endl;
}

int main(){
    int t;
    cin >> t;
    while (t--)
        solve();

    return 0;
}


#include <iostream>
#include <string>
#include <map>
#include <vector>
#include <algorithm>

using namespace std;

void solve() {
    int n, k;
    cin >> n >> k;

    string results;
    cin >> results;

    if (n == 1) {
        if (results[0] == 'W' || k > 0)
            cout << 1 << endl;
        else
            cout << 0 << endl;
        return;
    }

    map<int, vector<int>> loss;

    int score = results[0] == 'W' ? 1 : 0;
    int losses = 0, last_losses = -1, sum_losses = 0;
    int first = - 1;
    if (results[0] == 'L')
        losses++;
    for (int i = 1; i < n; i++) {
        if (results[i] == 'W') {
            score += results[i-1] == 'W' ? 2 : 1;
            last_losses = i - losses;
            loss[losses].push_back(i-losses);
            losses = 0;
        }
        else
            losses++;
    }
    loss[losses].push_back(n - losses);
    int start = -1;
    int end = -1;
    for (auto cons : loss) {
        if (cons.first == 0)
            continue;
        for (int idx : cons.second) {
            if (idx == 0) {
                start = cons.first;
                continue;
            }
            if (idx + cons.first == n) {
                end = cons.first;
                continue;
            }
            if (k < cons.first) {
                score += k * 2;
                k = 0;
                break;
            }
            k -= cons.first;
            score += cons.first * 2 + 1;
        }
        if (k == 0)
            break;
    }

    if (k > 0) {
        int improv = min(k, start + end);
        score += improv * 2;
    }

    cout << score << endl;
}

int main(){
    int t;
    cin >> t;
    while (t--)
        solve();

    return 0;
}


#include <iostream>
#include <string>
#include <map>
#include <vector>
#include <algorithm>

using namespace std;

void solve() {
    int n, k;
    cin >> n >> k;

    string results;
    cin >> results;

    map<int, vector<int>> loss;

    int score = results[0] == 'W' ? 1 : 0;
    int losses = 0, last_losses = -1, sum_losses = 0;
    int first = - 1;
    if (results[0] == 'L')
        losses++;
    for (int i = 1; i < n; i++) {
        if (results[i] == 'W') {
            score += results[i-1] == 'W' ? 2 : 1;
            last_losses = i - losses;
            loss[losses].push_back(i-losses);
            losses = 0;
        }
        else
            losses++;
    }
    if (losses == n) {
        if (k > 0)
            cout << 2 * k - 1 << endl;
        else
            cout << 0 << endl;
        return;
    }
    loss[losses].push_back(n - losses);
    int start = 0;
    int end = 0;
    for (auto cons : loss) {
        if (cons.first == 0)
            continue;
        for (int idx : cons.second) {
            if (idx == 0) {
                start = cons.first;
                continue;
            }
            if (idx + cons.first == n) {
                end = cons.first;
                continue;
            }
            if (k < cons.first) {
                score += k * 2;
                k = 0;
                break;
            }
            k -= cons.first;
            score += cons.first * 2 + 1;
        }
        if (k == 0)
            break;
    }

    if (k > 0) {
        int improv = min(k, start + end);
        score += improv * 2;
    }

    cout << score << endl;
}

int main(){
    int t;
    cin >> t;
    while (t--)
        solve();

    return 0;
}


#define _CRT_SECURE_NO_WARNINGS 1

#include <iostream>
#include <cstdio>
#include <utility>
#include <algorithm>
#include <queue>
using namespace std;

using ll = long long int;

int tNum;
int n, k;
char str[100005];
priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>> pq;

int main(void)
{
    // freopen("input.txt", "r", stdin);
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    cin >> tNum;
    for(int tt = 1; tt <= tNum; tt++) {
        while(pq.empty() == false) pq.pop();

        cin >> n >> k >> str;

        int idx = 0, cnt = -1;
        for(int i = 0; i < n; i++) {
            if(str[i] == 'W') {
                if(cnt != -1 && idx != 0) {
                    pq.push({cnt, idx});
                }
                cnt = -1;
            } else {
                if(cnt == -1) {
                    idx = i;
                    cnt = 0;
                }
                cnt++;
            }
        }
        /*
        if(cnt != -1) {
            pq.push({ cnt, idx });
        }*/

        while(pq.empty() == false && k > 0) {
            auto p = pq.top();
            pq.pop();
            for(int i = 0; i < p.first; i++) {
                str[p.second + i] = 'W';
                k--;
                if(k <= 0) break;
            }
        }
        if(k > 0) {
            int st = 0;
            for(; st < n; st++) {
                if(str[st] == 'W') break;
            }
            for(int i = st - 1; i >= 0; i--) {
                str[i] = 'W';
                k--;
                if(k <= 0) break;
            }

            int ed = n - 1;
            for(; ed >= 0; ed--) {
                if(str[ed] == 'W') break;
            }
            for(int i = ed + 1; i < n; i++) {
                str[i] = 'W';
                k--;
                if(k <= 0) break;
            }
        }

        int res = 0;
        bool preWin = false;
        for(int i = 0; i < n; i++) {
            if(str[i] == 'W') {
                if(preWin == true) {
                    res += 2;
                } else {
                    res++;
                }
                preWin = true;
            } else {
                preWin = false;
            }
        }
        cout << res << "\n";
    }

    return 0;
}


#define _CRT_SECURE_NO_WARNINGS 1

#include <iostream>
#include <cstdio>
#include <utility>
#include <algorithm>
#include <queue>
#include <functional>
using namespace std;

using ll = long long int;

int tNum;
int n, k;
char str[100005];
priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>> pq;

int main(void)
{
    // freopen("input.txt", "r", stdin);
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    cin >> tNum;
    for(int tt = 1; tt <= tNum; tt++) {
        while(pq.empty() == false) pq.pop();

        cin >> n >> k >> str;

        int idx = 0, cnt = -1;
        for(int i = 0; i < n; i++) {
            if(str[i] == 'W') {
                if(cnt != -1 && idx != 0) {
                    pq.push({cnt, idx});
                }
                cnt = -1;
            } else {
                if(cnt == -1) {
                    idx = i;
                    cnt = 0;
                }
                cnt++;
            }
        }
        /*
        if(cnt != -1) {
            pq.push({ cnt, idx });
        }*/

        while(pq.empty() == false && k > 0) {
            auto p = pq.top();
            pq.pop();
            for(int i = 0; i < p.first; i++) {
                str[p.second + i] = 'W';
                k--;
                if(k <= 0) break;
            }
        }
        if(k > 0) {
            int st = 0;
            for(; st < n; st++) {
                if(str[st] == 'W') break;
            }
            for(int i = st - 1; i >= 0; i--) {
                str[i] = 'W';
                k--;
                if(k <= 0) break;
            }

            int ed = n - 1;
            for(; ed >= 0; ed--) {
                if(str[ed] == 'W') break;
            }
            for(int i = ed + 1; i < n; i++) {
                str[i] = 'W';
                k--;
                if(k <= 0) break;
            }
        }

        int res = 0;
        bool preWin = false;
        for(int i = 0; i < n; i++) {
            if(str[i] == 'W') {
                if(preWin == true) {
                    res += 2;
                } else {
                    res++;
                }
                preWin = true;
            } else {
                preWin = false;
            }
        }
        cout << res << "\n";
    }

    return 0;
}


#define _CRT_SECURE_NO_WARNINGS 1

#include <iostream>
#include <cstdio>
#include <utility>
#include <algorithm>
#include <queue>
#include <functional>
using namespace std;

using ll = long long int;

int tNum;
int n, k;
char str[100005];
priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>> pq;

int main(void)
{
    // freopen("input.txt", "r", stdin);
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    cin >> tNum;
    for(int tt = 1; tt <= tNum; tt++) {
        while(pq.empty() == false) pq.pop();

        cin >> n >> k >> str;

        int idx = 0, cnt = -1;
        for(int i = 0; i < n; i++) {
            if(str[i] == 'W') {
                if(cnt != -1 && idx != 0) {
                    pq.push({cnt, idx});
                }
                cnt = -1;
            } else {
                if(cnt == -1) {
                    idx = i;
                    cnt = 0;
                }
                cnt++;
            }
        }
        /*
        if(cnt != -1) {
            pq.push({ cnt, idx });
        }*/

        while(pq.empty() == false && k > 0) {
            auto p = pq.top();
            pq.pop();
            for(int i = 0; i < p.first; i++) {
                str[p.second + i] = 'W';
                k--;
                if(k <= 0) break;
            }
        }
        if(k > 0) {
            int st = 0;
            for(; st < n; st++) {
                if(str[st] == 'W') break;
            }
            for(int i = st - 1; i >= 0; i--) {
                str[i] = 'W';
                k--;
                if(k <= 0) break;
            }

            if(k > 0) {
                int ed = n - 1;
                for(; ed >= 0; ed--) {
                    if(str[ed] == 'W') break;
                }
                for(int i = ed + 1; i < n; i++) {
                    str[i] = 'W';
                    k--;
                    if(k <= 0) break;
                }
            }
        }

        int res = 0;
        bool preWin = false;
        for(int i = 0; i < n; i++) {
            if(str[i] == 'W') {
                if(preWin == true) {
                    res += 2;
                } else {
                    res++;
                }
                preWin = true;
            } else {
                preWin = false;
            }
        }
        cout << res << "\n";
    }

    return 0;
}


#include <iostream>
#include<vector>
#include<algorithm>
#include<string>

using namespace std;

using ll = long long;
using ull = unsigned long long;

void solve(istream &cin = std::cin, ostream &cout = std::cout)
{
	int n, k;
	cin >> n >> k;
	string s;
	cin >> s;
	vector<int> poses;
	int cur = 0, mx = 2 * n - 1;
	for (int i = 0; i < n; i++)
	{
		if (s[i] == 'W')
		{
			poses.push_back(i);
			cur++;
			if (i > 0 && s[i - 1] == 'W')
				cur++;
		}
	}
	vector<int> holes;
	for (int i = 1; i < poses.size(); i++)
	{
		int cr = poses[i] - poses[i - 1] - 1;
		if (cr > 0)
			holes.push_back(cr);
	}
	sort(holes.begin(), holes.end());
	cur += 2 * k;
	int sum=0;
	for(int i=0; i<holes.size(); i++)
	{
		sum+=holes[i];
		if(sum<=k)
			cur++;
	}
	cout<<min(cur, mx)<<endl;
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	cout << fixed;

#ifdef LOCAL
	auto st = clock();

	ifstream fin("../input.txt");

	do
	{
		solve(fin);

		cout << "===" << endl;

		string str;
		while (getline(fin, str) && str != string(max(1, (int) str.size()), '='));
	} while (fin);

	cout << setprecision(6) << "clock: " << double(clock() - st) / CLOCKS_PER_SEC << endl;
#else
	int t;
	cin >> t;
	for (int i = 0; i < t; i++)
		solve();
#endif

	return 0;
}