#include<iostream>
#include<cstdio>
#include<cstring>
#include<vector>
#include<cmath>
#include<map>
#include<string>
#include<queue>
#include<algorithm>
using namespace std;
typedef long long ll;

int col[200001], parent[200001], w[200001][2], total[200001];
map<int, int> mp;
vector<vector<int> > colv;
int find(int x)
{
	if (x == parent[x]) return x;
	return find(parent[x]);
}
void merge(int x, int y)
{
	parent[find(y)] = find(x);
}
int main()
{
	int n, m, k, ans = 0;

	cin >> n >> m >> k;
	colv.resize(n + 1);

	for (int i = 1; i <= n; i++) scanf("%d", &col[i]);
	for (int i = 1; i <= n; i++) parent[i] = i;
	for (int i = 0; i < m; i++)
	{
		scanf("%d %d", &w[i][0], &w[i][1]);
		merge(w[i][0], w[i][1]);
	}
	for (int i = 1; i <= n; i++) colv[find(i)].push_back(i);
	for (int i=1; i<=n; i++)
	{
		if (!colv[i].empty())
		{
			int mx = 0;
			for (int it : colv[i]) mp[col[it]]++;
			for (auto it : mp) mx = max(mx, it.second);
			ans += colv[i].size() - mx;
			mp.clear();
		}
	}
	cout << ans;

}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<vector>
#include<cmath>
#include<map>
#include<string>
#include<queue>
#include<algorithm>
using namespace std;
typedef long long ll;

int col[200001], parent[200001];
map<int, int> mp;
vector<vector<int> > colv;
int find(int x)
{
	if (x == parent[x]) return x;
	return find(parent[x]);
}
void merge(int x, int y)
{
	parent[find(y)] = find(x);
}
int main()
{
	int n, m, k, ans = 0;

	scanf("%d %d %d", &n, &m, &k);
	colv.resize(n + 1);

	for (int i = 1; i <= n; i++) scanf("%d", &col[i]);
	for (int i = 1; i <= n; i++) parent[i] = i;
	for (int i = 0; i < m; i++)
	{
		int a, b;
		scanf("%d %d", &a, &b);
		merge(a, b);
	}
	for (int i = 1; i <= n; i++) colv[find(i)].push_back(i);
	for (int i=1; i<=n; i++)
	{
		if (!colv[i].empty())
		{
			int mx = 0;
			for (int it : colv[i]) mp[col[it]]++;
			for (auto it : mp) mx = max(mx, it.second);
			ans += colv[i].size() - mx;
			mp.clear();
		}
	}
	printf("%d\n", ans);
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<vector>
#include<cmath>
#include<string>
#include<queue>
#include<algorithm>
using namespace std;
typedef long long ll;

int col[200001], parent[200001], w[200001][2];
int find(int x)
{
	if (x == parent[x]) return x;
	return find(parent[x]);
}
void merge(int x, int y)
{
	parent[find(y)] = find(x);
}
int main()
{
	int n, m, k, ans = 0;

	cin >> n >> m >> k;

	for (int i = 1; i <= n; i++) scanf("%d", &col[i]);
	for (int i = 1; i <= n; i++) parent[i] = i;
	for (int i = 0; i < m; i++)
	{
		scanf("%d %d", &w[i][0], &w[i][1]);

		if (col[w[i][0]] == col[w[i][1]]) continue;
		else
		{
			if (find(w[i][0]) != find(w[i][1]))
			{
				ans++;
				merge(w[i][0], w[i][1]);
			}
		}
	}
	cout << ans;

}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<vector>
#include<cmath>
#include<string>
#include<queue>
#include<algorithm>
using namespace std;
typedef long long ll;

int col[200001], parent[200001], w[200001][2];
int find(int x)
{
	if (x == parent[x]) return x;
	return find(parent[x]);
}
void merge(int x, int y)
{
	parent[find(y)] = find(x);
}
int main()
{
	int n, m, k, ans = 0;

	cin >> n >> m >> k;

	for (int i = 1; i <= n; i++) scanf("%d", &col[i]);
	for (int i = 1; i <= n; i++) parent[i] = i;
	for (int i = 0; i < m; i++)
	{
		scanf("%d %d", &w[i][0], &w[i][1]);
		merge(w[i][0], w[i][1]);
	}
	for (int i = 1; i <= n; i++)
	{
		if (find(i) != i && col[i] != col[find(i)]) ans++;
	}
	cout << ans;

}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<vector>
#include<cmath>
#include<map>
#include<string>
#include<queue>
#include<algorithm>
using namespace std;
typedef long long ll;

int col[200001], parent[200001], w[200001][2], total[200001];
bool checked[200001], visited[200001];
map<int, int> mp[200001];

int find(int x)
{
	if (x == parent[x]) return x;
	return find(parent[x]);
}
void merge(int x, int y)
{
	parent[find(y)] = find(x);
}
int main()
{
	int n, m, k, ans = 0;

	cin >> n >> m >> k;

	for (int i = 1; i <= n; i++) scanf("%d", &col[i]);
	for (int i = 1; i <= n; i++) parent[i] = i;
	for (int i = 0; i < m; i++)
	{
		scanf("%d %d", &w[i][0], &w[i][1]);
		merge(w[i][0], w[i][1]);
	}
	for (int i = 1; i <= n; i++)
	{
		int par = find(i);
		total[par]++;
		mp[par][col[i]]++;
	}
	for (int i=1; i<=n; i++)
	{
		if (mp[i].size())
		{
			int mx = 0;
			for (auto it : mp[i])
			{
				mx = max(mx, it.second);
			}
			ans += total[i] - mx;
		}
	}
	cout << ans;

}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<vector>
#include<cmath>
#include<map>
#include<string>
#include<queue>
#include<algorithm>
using namespace std;
typedef long long ll;

int col[200001], parent[200001];
map<int, int> mp;
vector<vector<int> > colv;
int find(int x)
{
	if (x == parent[x]) return x;
	return parent[x] = find(parent[x]);
}
void merge(int x, int y)
{
	parent[find(y)] = find(x);
}
int main()
{
	int n, m, k, ans = 0;

	scanf("%d %d %d", &n, &m, &k);
	colv.resize(n + 1);

	for (int i = 1; i <= n; i++) scanf("%d", &col[i]);
	for (int i = 1; i <= n; i++) parent[i] = i;
	for (int i = 0; i < m; i++)
	{
		int a, b;
		scanf("%d %d", &a, &b);
		merge(a, b);
	}
	for (int i = 1; i <= n; i++) colv[find(i)].push_back(i);
	for (int i=1; i<=n; i++)
	{
		if (!colv[i].empty())
		{
			int mx = 0;
			for (int it : colv[i]) mp[col[it]]++;
			for (auto it : mp) mx = max(mx, it.second);
			ans += colv[i].size() - mx;
			mp.clear();
		}
	}
	printf("%d\n", ans);
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<vector>
#include<cmath>
#include<string>
#include<queue>
#include<algorithm>
using namespace std;
typedef long long ll;

int col[200001], parent[200001], w[200001][2];
int find(int x)
{
	if (x == parent[x]) return x;
	return find(parent[x]);
}
void merge(int x, int y)
{
	parent[find(y)] = find(x);
}
int main()
{
	int n, m, k, ans = 0;

	cin >> n >> m >> k;

	for (int i = 1; i <= n; i++) scanf("%d", &col[i]);
	for (int i = 1; i <= n; i++) parent[i] = i;
	for (int i = 0; i < m; i++)
	{
		scanf("%d %d", &w[i][0], &w[i][1]);

		if (find(w[i][0]) != find(w[i][1]))
		{
			merge(w[i][0], w[i][1]);
		}
	}
	for (int i = 1; i <= n; i++)
	{
		if (parent[i] != i && col[i] != col[parent[i]]) ans++;
	}
	cout << ans;

}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<vector>
#include<cmath>
#include<map>
#include<string>
#include<queue>
#include<algorithm>
using namespace std;
typedef long long ll;

int col[200001], parent[200001];
map<int, int> mp;
vector<vector<int> > colv;
int find(int x)
{
	if (x == parent[x]) return x;
	return find(parent[x]);
}
void merge(int x, int y)
{
	parent[find(y)] = find(x);
}
int main()
{
	int n, m, k, ans = 0;

	cin >> n >> m >> k;
	colv.resize(n + 1);

	for (int i = 1; i <= n; i++) scanf("%d", &col[i]);
	for (int i = 1; i <= n; i++) parent[i] = i;
	for (int i = 0; i < m; i++)
	{
		int a, b;
		scanf("%d %d", &a, &b);
		merge(a, b);
	}
	for (int i = 1; i <= n; i++) colv[find(i)].push_back(i);
	for (int i=1; i<=n; i++)
	{
		if (!colv[i].empty())
		{
			int mx = 0;
			for (int it : colv[i]) mp[col[it]]++;
			for (auto it : mp) mx = max(mx, it.second);
			ans += colv[i].size() - mx;
			mp.clear();
		}
	}
	printf("%d\n", ans);
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<vector>
#include<cmath>
#include<map>
#include<string>
#include<queue>
#include<algorithm>
using namespace std;
typedef long long ll;

int col[200001], parent[200001], w[200001][2], total[200001];
bool visited[200001];
map<int, int> mp[200001];

int find(int x)
{
	if (x == parent[x]) return x;
	return parent[x] = find(parent[x]);
}
void merge(int x, int y)
{
	parent[find(y)] = find(x);
}
int main()
{
	int n, m, k, ans = 0;

	cin >> n >> m >> k;

	for (int i = 1; i <= n; i++) scanf("%d", &col[i]);
	for (int i = 1; i <= n; i++) parent[i] = i;
	for (int i = 0; i < m; i++)
	{
		scanf("%d %d", &w[i][0], &w[i][1]);
		merge(w[i][0], w[i][1]);
	}
	for (int i = 1; i <= n; i++)
	{
		int par = find(i);
		total[par]++;
		mp[par][col[i]]++;
	}
	for (int i = 1; i <= n; i++)
	{
		int par = find(i);
		if (i == find(i) && !visited[par])
		{
			visited[par] = true;
			int mx = 0;
			for (auto it : mp[i])
			{
				mx = max(mx, it.second);
			}
			ans += total[i] - mx;
		}
	}
	cout << ans;

}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<vector>
#include<cmath>
#include<map>
#include<string>
#include<queue>
#include<algorithm>
using namespace std;
typedef long long ll;

int col[200001], parent[200001], w[200001][2], total[200001];
map<int, int> mp;
vector<int> colv[200001];
int find(int x)
{
	if (x == parent[x]) return x;
	return find(parent[x]);
}
void merge(int x, int y)
{
	parent[find(y)] = find(x);
}
int main()
{
	int n, m, k, ans = 0;

	cin >> n >> m >> k;

	for (int i = 1; i <= n; i++) scanf("%d", &col[i]);
	for (int i = 1; i <= n; i++) parent[i] = i;
	for (int i = 0; i < m; i++)
	{
		scanf("%d %d", &w[i][0], &w[i][1]);
		merge(w[i][0], w[i][1]);
	}
	for (int i = 1; i <= n; i++)
	{
		int par = find(i);
		total[par]++;
		colv[par].push_back(i);
	}
	for (int i=1; i<=n; i++)
	{
		if (!colv[i].empty())
		{
			int mx = 0;
			for (auto it : colv[i]) mp[col[it]]++;
			for (auto it : mp) mx = max(mx, it.second);
			ans += total[i] - mx;
			mp.clear();
		}
	}
	cout << ans;

}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<vector>
#include<cmath>
#include<map>
#include<string>
#include<queue>
#include<algorithm>
using namespace std;
typedef long long ll;

int col[200001], parent[200001], w[200001][2], total[200001];
bool checked[200001], visited[200001];
map<int, int> mp[200001];

int find(int x)
{
	if (x == parent[x]) return x;
	return find(parent[x]);
}
void merge(int x, int y)
{
	parent[find(y)] = find(x);
}
int main()
{
	int n, m, k, ans = 0;

	cin >> n >> m >> k;

	for (int i = 1; i <= n; i++) scanf("%d", &col[i]);
	for (int i = 1; i <= n; i++) parent[i] = i;
	for (int i = 0; i < m; i++)
	{
		scanf("%d %d", &w[i][0], &w[i][1]);
		merge(w[i][0], w[i][1]);
	}
	for (int i = 1; i <= n; i++)
	{
		int par = find(i);
		total[par]++;
		mp[par][col[i]]++;
	}
	for (int i = 1; i <= n; i++)
	{
		if (i == find(i))
		{
			int mx = 0;
			for (auto it : mp[i])
			{
				mx = max(mx, it.second);
			}
			ans += total[i] - mx;
		}
	}
	cout << ans;

}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<vector>
#include<cmath>
#include<map>
#include<string>
#include<queue>
#include<algorithm>
using namespace std;
typedef long long ll;

int col[200001], parent[200001], w[200001][2], total[200001];
bool visited[200001];
map<int, int> mp[200001];

int find(int x)
{
	if (x == parent[x]) return x;
	return find(parent[x]);
}
void merge(int x, int y)
{
	parent[find(y)] = find(x);
}
int main()
{
	int n, m, k, ans = 0;

	cin >> n >> m >> k;

	for (int i = 1; i <= n; i++) scanf("%d", &col[i]);
	for (int i = 1; i <= n; i++) parent[i] = i;
	for (int i = 0; i < m; i++)
	{
		scanf("%d %d", &w[i][0], &w[i][1]);
		merge(w[i][0], w[i][1]);
	}
	for (int i = 1; i <= n; i++)
	{
		int par = find(i);
		total[par]++;
		mp[par][col[i]]++;
	}
	for (int i = 1; i <= n; i++)
	{
		int par = find(i);
		if (i == find(i) && !visited[par])
		{
			visited[par] = true;
			int mx = 0;
			for (auto it : mp[i])
			{
				mx = max(mx, it.second);
			}
			ans += total[i] - mx;
		}
	}
	cout << ans;

}


#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <map>
using namespace std;
const int maxn = 2e5 + 5;
int pre[maxn], a[maxn], b[maxn]; //pre并查集祖先数组，a记录每个袜子的颜色，b数组用来记录每个集合的颜色（就是某几天都是一种颜色，记录这种颜色的编号
vector<int> v[maxn];
int Find(int x)
{
    return x == pre[x] ? x : pre[x] = Find(pre[x]);
}
void join(int x, int y)
{
    pre[Find(y)] = Find(x);
}
int main()
{
    int n, m, k, x, y;
    scanf("%d%d%d", &n, &m, &k);
    for(int i = 1; i <= n; i++)
        scanf("%d", &a[i]), pre[i] = i;
    for(int i = 1; i <= m; i++)
        scanf("%d%d", &x, &y), join(x, y); //这里就是这一天要袜子颜色要一样，把他们“联通”起来，这里并查集“祖先”的个数就是一共有几种颜色
    int cnt = 1;
    for(int i = 1; i <= n; i++)
    {
        if(pre[i] == i)      //这里如果pre[i] == i，代表了这是某几天的“祖先”，也就是一种颜色，给这个祖先的颜色一个编号cnt
            b[i] = cnt++;
    }
    for(int i = 1; i <= n; i++)  //这里就是把祖先的小弟拉近祖先的怀里，b[]是祖先的编号，他的小弟的b[Find（）]的颜色（a记录的）都存进v数组里，v下标代表哪个
    {<span style="white-space:pre">				</span>//祖先
        v[b[Find(i)]].push_back(a[i]);
    }
    int ans = 0;
    for(int i = 1; i < cnt; i++)  //第一个for遍历cnt个祖先，也就是一共有cnt种不同的颜色
    {
        int maxx = 0;
        map<int, int> mm;
        for(int j = 0; j < v[i].size(); j++)  //这里就是遍历刚才每种颜色收的小弟，用一个map记录每种颜色的数量，找出数量最多的颜色
        {
            mm[v[i][j]]++;
            if(mm[v[i][j]] > maxx)  maxx = mm[v[i][j]];
        }
        ans += v[i].size() - maxx;  //这里就是用集合所有的袜子，减去数量最多的颜色。。。
    }
    printf("%d\n", ans);
    return 0;
}


#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#define M 200005
using namespace std;
int book[M],vis[M];
struct node{
	int color,fa;
}q[M];
vector<int>v[M];
int getf(int k)
{
	return k==q[k].fa?k:q[k].fa=getf(q[k].fa);
}
int main()
{
	int n,m,k;
	scanf("%d%d%d",&n,&m,&k);
		int a,b,ans=0;
		int cnt=1;
		for(int i=0;i<M;i++)
		v[i].clear();
		for(int i=1;i<=n;i++)
		{
			scanf("%d",&q[i].color);
			q[i].fa=i;
		}
		for(int i=0;i<m;i++)
		{
			scanf("%d%d",&a,&b);
			q[getf(b)].fa=getf(a);
		}
		for(int i=1;i<=n;i++)
		{
			if(q[i].fa==i)
			book[i]=cnt++;
		}
		for(int i=1;i<=n;i++)
		v[book[getf(i)]].push_back(q[i].color);
		for(int i=1;i<cnt;i++)
		{
			memset(vis,0,sizeof(vis));
			int mmax=0;
			for(int j=0;j<v[i].size();j++)
			{
				vis[v[i][j]]++;
				if(vis[v[i][j]]>mmax)
				mmax=vis[v[i][j]];
			}
			ans+=(v[i].size()-mmax);
		}
		printf("%d\n",ans);
return 0;
}


#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#define M 200005
using namespace std;
int book[M],vis[M];
struct node{
	int color,fa;
}q[M];
vector<int>v[M];
int getf(int k)
{
	return k==q[k].fa?k:q[k].fa=getf(q[k].fa);
}
int main()
{
	int n,m,k;
	scanf("%d%d%d",&n,&m,&k);
		int a,b,ans=0;
		int cnt=1;
		for(int i=1;i<=n;i++)
		{
			scanf("%d",&q[i].color);
			q[i].fa=i;
		}
		for(int i=0;i<m;i++)
		{
			scanf("%d%d",&a,&b);
			q[getf(b)].fa=getf(a);
		}
		for(int i=1;i<=n;i++)
		{
			if(q[i].fa==i)
			book[i]=cnt++;
		}
		for(int i=1;i<=n;i++)
		v[book[getf(i)]].push_back(q[i].color);
		for(int i=1;i<cnt;i++)
		{
			memset(vis,0,sizeof(vis));
			int mmax=0;
			for(int j=0;j<v[i].size();j++)
			{
				vis[v[i][j]]++;
				if(vis[v[i][j]]>mmax)
				mmax=vis[v[i][j]];
			}
			ans+=(v[i].size()-mmax);
		}
		printf("%d\n",ans);
return 0;
}


#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <map>
#define M 200005
using namespace std;
int book[M]/*,vis[M]*/;
struct node{
	int color,fa;
}q[M];
vector<int>v[M];
int getf(int k)
{
	return k==q[k].fa?k:q[k].fa=getf(q[k].fa);
}
int main()
{
		int n,m,k;
		scanf("%d%d%d",&n,&m,&k);
		int a,b,ans=0;
		int cnt=1;
		memset(book,0,sizeof(book));
		for(int i=1;i<=n;i++)
		{
			scanf("%d",&q[i].color);
			q[i].fa=i;
		}
		for(int i=0;i<m;i++)
		{
			scanf("%d%d",&a,&b);
			q[b].fa=getf(a);
		}
		for(int i=1;i<=n;i++)
		{
			if(q[i].fa==i)
			book[i]=cnt++;
		}
		for(int i=1;i<=n;i++)
		v[book[getf(i)]].push_back(q[i].color);
		for(int i=1;i<cnt;i++)
		{
			//memset(vis,0,sizeof(vis));
			map<int,int>index;
			int mmax=0;
			for(int j=0;j<v[i].size();j++)
			{
				//vis[v[i][j]]++;
				index[v[i][j]]++;
				if(index[v[i][j]]>mmax)
				mmax=index[v[i][j]];
			}
			ans+=(v[i].size()-mmax);
		}
		printf("%d\n",ans);
return 0;
}


#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <map>
#define M 200005
using namespace std;
int book[M]/*,vis[M]*/;
struct node{
	int color,fa;
}q[M];
vector<int>v[M];
int getf(int k)
{
	return k==q[k].fa?k:q[k].fa=getf(q[k].fa);
}
int main()
{
		int n,m,k;
		scanf("%d%d%d",&n,&m,&k);
		int a,b,ans=0;
		int cnt=1;
		memset(book,0,sizeof(book));
		for(int i=1;i<=n;i++)
		{
			scanf("%d",&q[i].color);
			q[i].fa=i;
		}
		for(int i=0;i<m;i++)
		{
			scanf("%d%d",&a,&b);
			q[getf(b)].fa=getf(a);
		}
		for(int i=1;i<=n;i++)
		{
			if(q[i].fa==i)
			book[i]=cnt++;
		}
		for(int i=1;i<=n;i++)
		v[book[getf(i)]].push_back(q[i].color);
		for(int i=1;i<cnt;i++)
		{
			//memset(vis,0,sizeof(vis));
			map<int,int>index;
			int mmax=0;
			for(int j=0;j<v[i].size();j++)
			{
				//vis[v[i][j]]++;
				index[v[i][j]]++;
				if(index[v[i][j]]>mmax)
				mmax=index[v[i][j]];
			}
			ans+=(v[i].size()-mmax);
		}
		printf("%d\n",ans);
return 0;
}


#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <map>
#define M 200005
using namespace std;
int book[M]/*,vis[M]*/;
struct node{
	int color,fa;
}q[M];
vector<int>v[M];
int getf(int k)
{
	return k==q[k].fa?k:q[k].fa=getf(q[k].fa);
}
int main()
{
	int n,m,k;
	while(~scanf("%d%d%d",&n,&m,&k))
	{
		int a,b,ans=0;
		int cnt=1;
		for(int i=0;i<M;i++)
		v[i].clear();
		memset(book,0,sizeof(book));
		for(int i=1;i<=n;i++)
		{
			scanf("%d",&q[i].color);
			q[i].fa=i;
		}
		for(int i=0;i<m;i++)
		{
			scanf("%d%d",&a,&b);
			q[b].fa=getf(a);
		}
		for(int i=1;i<=n;i++)
		{
			if(q[i].fa==i)
			book[i]=cnt++;
		}
		for(int i=1;i<=n;i++)
		v[book[getf(i)]].push_back(q[i].color);
		for(int i=1;i<cnt;i++)
		{
			//memset(vis,0,sizeof(vis));
			map<int,int>index;
			int mmax=0;
			for(int j=0;j<v[i].size();j++)
			{
				//vis[v[i][j]]++;
				index[v[i][j]]++;
				if(index[v[i][j]]>mmax)
				mmax=index[v[i][j]];
			}
			ans+=(v[i].size()-mmax);
		}
		printf("%d\n",ans);
	}
return 0;
}


#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#define M 200005
using namespace std;
int book[M],vis[M];
struct node{
	int color,fa;
}q[M];
vector<int>v[M];
int getf(int k)
{
	return k==q[k].fa?k:q[k].fa=getf(q[k].fa);
}
int main()
{
	int n,m,k;
	while(~scanf("%d%d%d",&n,&m,&k))
	{
		int a,b,ans=0;
		int cnt=1;
		for(int i=0;i<M;i++)
		v[i].clear();
		memset(book,0,sizeof(book));
		for(int i=1;i<=n;i++)
		{
			scanf("%d",&q[i].color);
			q[i].fa=i;
		}
		for(int i=0;i<m;i++)
		{
			scanf("%d%d",&a,&b);
			q[b].fa=getf(a);
		}
		for(int i=1;i<=n;i++)
		{
			if(q[i].fa==i)
			book[i]=cnt++;
		}
		for(int i=1;i<=n;i++)
		v[book[getf(i)]].push_back(q[i].color);
		for(int i=1;i<cnt;i++)
		{
			memset(vis,0,sizeof(vis));
			int mmax=0;
			for(int j=0;j<v[i].size();j++)
			{
				vis[v[i][j]]++;
				if(vis[v[i][j]]>mmax)
				mmax=vis[v[i][j]];
			}
			ans+=(v[i].size()-mmax);
		}
		printf("%d\n",ans);
	}
return 0;
}


t = int(input())

for _ in range(t):
    n, k = map(int, input().split())
    w = list(map(int, input().split()))

    lst1 = [w[0], n - w[-1] + 1]
    lst2 = [(w[i + 1] - w[i]) // 2 + 1 for i in range(k - 1)]
    # 区間[a, b]に水やりするにはceil((b-a+1)/2)秒かかる。
    # ceilを使わないように書いた。

    print(max(lst1 + lst2))


for t in range(int(input())):
	[n,k]=[int(x) for x in input().split()]
	xi = [int(x) for x in input().split()]
	ans = max([xi[0],n-xi[-1]+1]+[(xi[i]-xi[i-1]+2)//2 for i in range(1,k)])
	print(ans)


t=int(input())
for i in range(t):
	[n,k] = [int(x) for x in input().split()]
	ans=1
	xi=k*[1]
	xi = [int(x) for x in input().split()]
	#print(xi)
	ans=xi[0]
	for j in range(2,k):
		if(xi[j]-xi[j-1])//2>ans:
			ans = (xi[j]-xi[j-1])//2
	if n - xi[k-1]+1>ans:
		ans=n-xi[k-1]+1
	print(ans)


t=int(input())
for i in range(t):
	[n,k] = [int(x) for x in input().split()]
	ans=1
	xi = [int(x) for x in input().split()]
	ans=xi[0]
	for j in range(1,k):
		if(xi[j]-xi[j-1]+2)//2>ans:
			ans = (xi[j]-xi[j-1]+2)//2
	if n - xi[k-1]+1>ans:
		ans=n-xi[k-1]+1
	print(ans)


t=int(input())
for i in range(t):
	[n,k] = [int(x) for x in input().split()]
	ans=1
	xi=k*[1]
	xi = [int(x) for x in input().split()]
	print(xi)
	ans=xi[0]
	for j in range(2,k):
		if(xi[j]-xi[j-1])//2>ans:
			ans = (xi[j]-xi[j-1])//2
	if n - xi[k-1]+1>ans:
		ans=n-xi[k-1]+1
	print(ans)


t=int(input())
for i in range(t):
	[n,k] = [int(x) for x in input().split()]
	ans=1
	xi=k*[1]
	xi = [int(x) for x in input().split()]
	#print(xi)
	ans=xi[0]
	for j in range(1,k):
		if(xi[j]-xi[j-1])//2>ans:
			ans = (xi[j]-xi[j-1])//2
	if n - xi[k-1]+1>ans:
		ans=n-xi[k-1]+1
	print(ans)


t=int(input())
for i in range(t):
	[n,k] = [int(x) for x in input().split()]
	ans=1
	xi=k*[1]
	xi = [int(x) for x in input().split()]
	#print(xi)
	ans=xi[0]
	for j in range(1,k):
		if(xi[j]-xi[j-1]+1)//2>ans:
			ans = (xi[j]-xi[j-1]+1)//2
	if n - xi[k-1]+1>ans:
		ans=n-xi[k-1]+1
	print(ans)


t = int(input())
# a = [0]*300
while t > 0:
    t -= 1
    n, k = map(int, input().split())
    a = list(map(int, input().split()))
    ans = max(a[0],n-a[-1]+1)
    l = len(a)
    for i in range(l-1):
        ans = max(int((a[i+1]-a[i]+1)/2), ans)
    print(ans)


t = int(input())
# a = [0]*300
while t > 0:
    t -= 1
    n, k = map(int, input().split())
    a = list(map(int, input().split()))
    ans = 0
    ans = max(a[0],n-a[-1]+1)
    l = len(a)
    for i in range(l-1):
        ans = max(int((a[i+1]-a[i]+1)/2+1), ans)
    print(ans)


t = int(input())
# a = [0]*300
while t > 0:
    t -= 1
    n, k = map(int, input().split())
    a = list(map(int, input().split()))
    ans = 0
    ans = max(a[0],n-a[-1]+1)
    l = len(a)
    for i in range(l-1):
        ans = max(int((a[i+1]-a[i])/2+1), ans)
    print(ans)


for _ in range(int(input())):
    n,k=map(int,input().split())

    l=list(map(int,input().split()))
    if len(l)==n:
       print(1)
    else:
     dp=[200]*(n+1)
     dp[0]=-1
     for i in l:
       dp[i]=1
     for i in range(1,n+1):
       if dp[i]==1:
         continue
       for j in l:
        dp[i]=min(abs(i-j),dp[i])
     print(max(dp)+1)


t = int(input())

for _ in range(t):
	n, k = map(int, input().split())
	x = list(map(int, input().split()))
	ogorod = [0]*n
	sec = 0
	while not all(ogorod):
		sec += 1
		for xi in x:
			for j in range(1, sec):
				if xi-1 - j >= 0:
					ogorod[xi-1 - j] += 1
				if xi-1 + j < n:
					ogorod[xi-1 + j] += 1
			ogorod[xi-1] += 1
	print(sec)

'''
3
5 1
3
3 3
1 2 3
4 1
1
'''


t = int(input())

for _ in range(t):
	n, k = map(int, input().split())
	x = list(map(int, input().split()))
	ogorod = [0]*n
	sec = 0
	while not all(ogorod):
		sec += 1
		for xi in x:
			for j in range(1, ogorod[xi-1]+1):
				if xi-1 - j >= 0:
					ogorod[xi-1 - j] += 1
				if xi-1 + j < n:
					ogorod[xi-1 + j] += 1
			ogorod[xi-1] += 1
	print(sec)

'''
3
5 1
3
3 3
1 2 3
4 1
1
'''


import math

t = int(input())

for i in range(t):
    n, k = map(int, input().split())
    positions = list(map(int, input().split()))
    ans = max(positions[0], n - positions[-1] + 1)
    for j in range(1, k):
        ans = max(ans, math.ceil((positions[j] - positions[j - 1] + 1) / 2))
    print(ans)


import math

t = int(input())

for i in range(t):
    n, k = map(int, input().split())
    positions = list(map(int, input().split()))
    ans = max(positions[0], n - positions[-1] + 1)
    for j in range(2, k):
        ans = max(ans, math.ceil((positions[j] - positions[j - 1] + 1) / 2))
    print(ans)


T = int(input())
for _ in range(T):
  n, k = map(int, input().split())
  T = list(map(int, input().split()))
  l = -1
  r = n
  while l < r - 1:
    i = (l + r) // 2
    A = [0] * (n + 2)
    for t in T:
      A[max(t - i - 1, 0)] += 1
      A[min(t + i, n)] -= 1
    for j in range(1, n + 1):
      A[j] += A[j - 1]
    if n == sum(1 for a in A[:n] if a > 0):
      r = i
    else: l = i
  print(r + 1)


def get_tmax(n, k, Lk):
    t1 = Lk[0]
    tk = n - Lk[-1] + 1
    t = 0
    for i in range(len(Lk) - 1):
        t = Lk[i + 1] - Lk[i] - 1
        if t % 2:
            t = (t // 2) + 2
        else:
            t = (t // 2) + 1
    return max(t1, tk, t)

ans = []
ntest = int(input())
for j in range(ntest):
    n, k = map(int, input().split())
    Lk = list(map(int, input().split()))
    #print("===", n, k, Lk)
    ans.append(get_tmax(n, k, Lk))

for i in ans:
    print(i)


def get_tmax(n, k, Lk):
    t1 = Lk[0]
    tk = n - Lk[-1] + 1
    t = 0
    for i in range(len(Lk) - 1):
        t = Lk[i + 1] - Lk[i] - 1
        if t % 2:
            t = (t // 2) + 2
        else:
            t = (t // 2) + 1
    return max(t1, tk, t)

ans = []
ntest = int(input())
for j in range(ntest):
    n, k = map(int, input().split())
    Lk = list(map(int, input().split()))
    ans.append(get_tmax(n, k, Lk))

print(*ans)


def get_tmax(n, k, Lk):
    t1 = Lk[0]
    tk = n - Lk[-1] + 1
    tm = 0
    for i in range(len(Lk) - 1):
        t = Lk[i + 1] - Lk[i] - 1
        if t % 2:
            t = (t // 2) + 2
        else:
            t = (t // 2) + 1
        if tm < t:
            tm = t
    return max(t1, tk, tm)

ans = []
ntest = int(input())
for j in range(ntest):
    n, k = map(int, input().split())
    Lk = list(map(int, input().split()))
    #print("===", n, k, Lk)
    ans.append(get_tmax(n, k, Lk))

for i in ans:
    print(i)


def main():
    for _ in range(int(input())):
        n, k = map(int, input().split())
        a, *bb = map(int, input().split())
        r = a * 2 - 1
        for b in bb:
            if r < b - a:
                r = b - a
            a = b
        if r < (n - a) * 2 + 1:
            r = (n - a) * 2 + 1
        print(r // 2 + 1)

if __name__ == '__main__':
    main()


def main():
    for _ in range(int(input())):
        n, k = map(int, input().split())
        a, *bb = map(int, input().split())
        r = a * 2 - 1
        for b in bb:
            if r < b - a:
                r = b - a
            a = b
        if r < (n - a) * 2 + 1:
            r = (n - a) * 2 + 1
        print((r + 1) // 2)

if __name__ == '__main__':
    main()


t, otv = int(input()), list()
for i in range(t):
    n, k = map(int, input().split(' '))
    kr = list(map(int, input().split(' ')))
    s = '*' * n
    for i in kr:
        s = s[:i - 1] + '/' + s[i:]
    otv.append(len(max(s.split('/'), key=lambda x: len(x))) + 1)
for i in otv:
    print(i)


t, otv = int(input()), list()
for i in range(t):
    n, k = map(int, input().split(' '))
    kr = list(map(int, input().split(' ')))
    s = '*' * n
    for x in kr:
        s = s[:x - 1] + '/' + s[x:]
    g = list(map(lambda x1: len(x1), s.split('/')))
    for x in range(1, len(g) - 1):
        g[x] = g[x] // 2 + g[x] % 2
    otv.append(max(g) + 1)
for i in otv:
    print(i)


t = int(input())

for _ in range(t):
	n, k = map(int, input().split())
	arr = list(map(int, input().split()))
	s = 1
	t = [False] * n
	for i in arr:
		t[i-1] = True
	while set(t) != {True}:
		q = list(t)
		for j in range(n):
			if j+1 < n:
				if q[j+1] == True:
					t[j] = True
			if j-1 < n:
				if q[j-1] == True:
					t[j] = True
		s+=1
	print(s)


t = int(input())

for _ in range(t):
	n, k = map(int, input().split())
	arr = list(map(int, input().split()))
	s = 1
	t = [False] * n
	for i in arr:
		t[i-1] = True
	while set(t) != {True}:
		q = list(t)
		s += 1
		for j in range(n):
			if j+1 < n:
				if q[j+1] == True:
					t[j] = True
			if j-1 < n:
				if q[j-1] == True:
					t[j] = True
	print(s)


t = int(input())

for _ in range(t):
	n, k = map(int, input().split())
	arr = list(map(int, input().split()))
	s = 1
	t = [False] * n
	for i in arr:
		t[i-1] = True
	while set(t) != {True}:
		for j in arr:
			if j+s <= n:
				t[j+s-1] = True
			if j-s > 0 and j-s <= n:
				t[j-s-1] = True
		s+=1
	print(s)


t=int(input())
for i in range(t):
    n,k = map(int,input().split())
    l = list(map(int,input().split()))
    a=[]
    a.append(l[0])
    for j in range(len(l)-1):
        a.append(l[i+1]-l[i])
    a.append(n-l[len(l)-1])
    k= max(a)
    print(k)


t=int(input())
for i in range(t):
    n,k = map(int,input().split())
    l = list(map(int,input().split()))
    a=[]
    a.append(l[0])
    for j in range(len(l)-1):
        a.append(l[i+1]-l[i])
    a.append(n-l[len(l)-1]+1)
    k= max(a)
    print(k)


t=int(input())
for i in range(t):
    n,k = map(int,input().split())
    l = list(map(int,input().split()))
    a=[]
    a.append(l[0])
    for j in range(k-1):
        a.append((l[j+1]-l[j])//2+1)
    a.append(n-l[k-1]+1)
    k= max(a)
    print(k)


t=int(input())
for i in range(t):
    n,k = map(int,input().split())
    l = list(map(int,input().split()))
    a=[]
    a.append(l[0])
    for j in range(k-1):
        a.append(l[j+1]-l[j])
    a.append(n-l[k-1]+1)
    k= max(a)
    print(k)


read = lambda: map(int, input().split())
T = int(input())
ans = []
for kase in range(T):
    r = 0
    n, k = read()
    a = [1] * n
    b = list(read())
    i = 0
    while sum(a):
        for num in b:
            num = num-1
            if num >= i:
                a[num - i] = 0
            if num < n-i:
                a[num + i] = 0
        i = i + 1
        r = r + 1
    ans.append(r)
for kase in range (T):
  print(ans[kase])


t=int(input())

ans=[0]*300

for i in range(t):
    n,k=map(int,input().split())
    a=list(map(int,input().split()))

    b=max(a[0],n+1-a[k-1])
    m=-1
    for j in range(k-1):
        m=max(m,a[j+1]-a[j])
    ans[i]=max((m+1)//2,b)

for i in range(t):
    print(ans[i])


t=int(input())

ans=[0]*300

for i in range(t):
    n,k=map(int,input().split())
    a=list(map(int,input().split()))

    b=max(a[0],n+1-a[k-1])
    m=-1
    for j in range(1,k):
        m=max(m,a[j]-a[j-1])
    ans[i]=max((m+2)//2,b)

for i in range(t):
    print(ans[i])


try:
    main = list()
    num = int(input())
    for f in range(num):
        temp = input().split(' ')
        for i in range(len(temp)):
            temp[i] = int(temp[i])
        locs = input().split(' ')
        for i in range(len(locs)):
            locs[i] = int(locs[i])
        if len(locs)!=temp[1]: sys.exit()
        lst = list()
        mins = int()
        for i in range(temp[0]):
            lst.append(i+1)

        while True:
            for i in locs:
                if lst.count(i-mins)!=0:
                    lst.remove(i-mins)
                if lst.count(i+mins)!=0:
                    lst.remove(i+mins)
            mins += 1
            if len(lst)==0:
                main.append(mins)
                break

    for i in main:
        print(i)

except:
    pass


def fill(empty,k,i):
    empty[k]=1
    if(k-i>=0):empty[k-i]=1
    if(k+i<=len(empty)-1):empty[k+i]=1

def testfull(empty):
    for i in range(0,len(empty)):
        if(empty[i]==0):return False
    return True

def solve(tap,inn):
    empty=[0]*inn[0]
    i=0
    while(testfull(empty)==False):

        for k in tap:
            fill(empty,k,i)
        i=i+1
    return str(i)

n=int(input())
for i in range(0,n):
    inn=input().split(' ')
    innInt=[int(x) for x in inn]
    tap=input().split(' ')
    tapInt=[int(x)-1 for x in tap]
    print(solve(tapInt,innInt))


I=lambda:[*map(int,input().split())]
for _ in[0]*I()[0]:
  n,k=I()
  x=I()
  r=max(x[0]-1,n-x[k-1])
  for i in range(1,k):r=max(r,x[i]-x[i-1]>>1)
  print(r+1)


t = int(input())
it = []
for i in range(t):
    q = 0
    time = 0
    m = []
    n, k = map(int, input().split())
    mas = list(map(int, input().split()))
    while q != n:
        for p in mas:
            if p + time < n + 1:
                if not p + time in m:
                    q += 1
                    m.append(p + time)
                if p - time > 0 and time != 0:
                    if not p - time in m:
                        q += 1
                        m.append(p-time)
            elif p - time > 0 and time != 0:
                if not p - time in m:
                    q += 1
                    m.append(p - time)
            else:
                del mas[p]
        time += 1
    it.append(str(time))
print('\n'.join(it))


cnt=0
time_list=[]
tc = eval(input())
#print(tc)
while cnt<tc:
    #print("CNT:", cnt, sep=',')
    n_k = input()
    l=[]
    l=n_k.split(' ')
    n=int(l[0])
    k=int(l[1])

    tap_pos = input()
    tap_pos_list = tap_pos.split(' ')

    #print(tap_pos_list[0])
    arr=[]
    c=0
    for i in range(0,n):
        if c<k and i==(int(tap_pos_list[c])-1):
            arr.append(1)
            c+=1
        else:
            arr.append(0)

    #print(arr)

    time=1
    flag=False
    while flag==False:
        if time==1:
            for i in arr:
                if i!=1:
                    flag=False
                    break;
                flag=True
                #print('y')

            if flag==True:
                time+=1
                break;
            time+=1
            #print('n')
        else:
            #print('time : ', time, sep='')
            c=0
            for i in range(len(arr)):
                if c<k and i==(int(tap_pos_list[c])-1):
                    if i==0:
                        arr[i+(time-1)]=1
                    elif i==(len(arr)-1):
                        arr[i-(time-1)]=1
                    else:
                        arr[i-(time-1)]=1
                        arr[i+(time-1)]=1
                    c+=1
            for i in arr:
                if i!=1:
                    flag=False;
                    break;
                flag=True
            time+=1
    time_list.append(time-1)
    #print(';-------------')
    #for i in time_list:
     #   print(i)
    cnt+=1

for i in time_list:
    print(i)


#tc = eval(input())
n_k = input()
l=[]
l=n_k.split(' ')
n=int(l[0])
k=int(l[1])

tap_pos = input()
tap_pos_list = tap_pos.split(' ')

#print(tap_pos_list[0])
arr=[]
c=0
for i in range(0,n):
    if c<k and i==(int(tap_pos_list[c])-1):
        arr.append(1)
        c+=1
    else:
        arr.append(0)

print(arr)

time=1
flag=False
while flag==False:
    if time==1:
        for i in arr:
            if i!=1:
                flag=False
                break;
            flag=True
            #print('y')

        if flag==True:
            break;
        time+=1
        #print('n')
    else:
        print('time : ', time, sep='')
        c=0
        for i in range(len(arr)):
            if c<k and i==(int(tap_pos_list[c])-1):
                if i==0:
                    arr[i+(time-1)]=1
                elif i==(len(arr)-1):
                    arr[i-(time-1)]=1
                else:
                    arr[i-(time-1)]=1
                    arr[i+(time-1)]=1
                c+=1
        for i in arr:
            if i!=1:
                flag=False;
                break;
            flag=True
        time+=1
print(time-1)


#tc = eval(input())
n_k = input()
l=[]
l=n_k.split(' ')
n=int(l[0])
k=int(l[1])

tap_pos = input()
tap_pos_list = tap_pos.split(' ')

#print(tap_pos_list[0])
arr=[]
c=0
for i in range(0,n):
    if c<k and i==(int(tap_pos_list[c])-1):
        arr.append(1)
        c+=1
    else:
        arr.append(0)

#print(arr)

time=1
flag=False
while flag==False:
    if time==1:
        for i in arr:
            if i!=1:
                flag=False
                break;
            flag=True
            #print('y')

        if flag==True:
            break;
        time+=1
        #print('n')
    else:
        #print('time : ', time, sep='')
        c=0
        for i in range(len(arr)):
            if c<k and i==(int(tap_pos_list[c])-1):
                if i==0:
                    arr[i+(time-1)]=1
                elif i==(len(arr)-1):
                    arr[i-(time-1)]=1
                else:
                    arr[i-(time-1)]=1
                    arr[i+(time-1)]=1
                c+=1
        for i in arr:
            if i!=1:
                flag=False;
                break;
            flag=True
        time+=1
print(time-1)


cnt=0
time_list=[]
tc = eval(input())
#print(tc)
while cnt<tc:
    #print("CNT:", cnt, sep=',')
    n_k = input()
    l=[]
    l=n_k.split(' ')
    n=int(l[0])
    k=int(l[1])

    tap_pos = input()
    tap_pos_list = tap_pos.split(' ')

    #print(tap_pos_list[0])
    arr=[]
    c=0
    for i in range(0,n):
        if c<k and i==(int(tap_pos_list[c])-1):
            arr.append(1)
            c+=1
        else:
            arr.append(0)

    #print(arr)

    time=1
    flag=False
    while flag==False:
        if time==1:
            for i in arr:
                if i!=1:
                    flag=False
                    break;
                flag=True
                #print('y')

            if flag==True:
                time+=1
                break;
            time+=1
            #print('n')
        else:
            print('time : ', time, sep='')
            c=0
            for i in range(len(arr)):
                if c<k and i==(int(tap_pos_list[c])-1):
                    if i==0:
                        arr[i+(time-1)]=1
                    elif i==(len(arr)-1):
                        arr[i-(time-1)]=1
                    else:
                        if (i-(time-1))>=0:
                            arr[i-(time-1)]=1
                        if (i+(time-1))<=(len(arr)-1):
                            arr[i+(time-1)]=1
                    c+=1
            for i in arr:
                if i!=1:
                    flag=False;
                    break;
                flag=True
            time+=1
    time_list.append(time-1)
    #print(';-------------')
    #for i in time_list:
     #   print(i)
    cnt+=1

for i in time_list:
    print(i)


cnt=0
time_list=[]
tc = eval(input())
#print(tc)
while cnt<tc:
    #print("CNT:", cnt, sep=',')
    n_k = input()
    l=[]
    l=n_k.split(' ')
    n=int(l[0])
    k=int(l[1])

    tap_pos = input()
    tap_pos_list = tap_pos.split(' ')

    #print(tap_pos_list[0])
    arr=[]
    c=0
    for i in range(0,n):
        if c<k and i==(int(tap_pos_list[c])-1):
            arr.append(1)
            c+=1
        else:
            arr.append(0)

    #print(arr)

    time=1
    flag=False
    while flag==False:
        if time==1:
            for i in arr:
                if i!=1:
                    flag=False
                    break;
                flag=True
                #print('y')

            if flag==True:
                time+=1
                break;
            time+=1
            #print('n')
        else:
           # print('time : ', time, sep='')
            c=0
            for i in range(len(arr)):
                if c<k and i==(int(tap_pos_list[c])-1):
                    if i==0:
                        arr[i+(time-1)]=1
                    elif i==(len(arr)-1):
                        arr[i-(time-1)]=1
                    else:
                        if (i-(time-1))>=0:
                            arr[i-(time-1)]=1
                        if (i+(time-1))<=(len(arr)-1):
                            arr[i+(time-1)]=1
                    c+=1
            for i in arr:
                if i!=1:
                    flag=False;
                    break;
                flag=True
            time+=1
    time_list.append(time-1)
    #print(';-------------')
    #for i in time_list:
     #   print(i)
    cnt+=1

for i in time_list:
    print(i)


t = gets.chomp.to_i
t.times do
  beds = gets.chomp.split(' ').map{|x| x.to_i}[0]
  taplist = gets.chomp.split(' ').map{|x| x.to_i - 1}
  taplist = [-1] + taplist + [beds]

  longest = 0
  (0..taplist.size-2).each do |i|
    time = 0
    if i == 0 then
      time = taplist[i+1] - taplist[0]
      # puts "time between #{taplist[0]} and #{taplist[i+1]} is #{time}"
    elsif i == taplist.size-2 then
      time = taplist[-1] - taplist[i]
      # puts "time between #{taplist[-1]} and #{taplist[i]} is #{time}"

    else
      if (taplist[i+1] - taplist[i]) == 1
        time = 1
      else
        time = (taplist[i+1] - taplist[i])/2 + 1
      end
      # puts "time between #{taplist[i+1]} and #{taplist[i]} is #{time}"

    end

    longest = time if time > longest
  end
  puts longest
end


t = gets.chomp.to_i
t.times do
  beds = gets.chomp.split(' ').map{|x| x.to_i}[0]
  taplist = gets.chomp.split(' ').map{|x| x.to_i - 1}
  taplist = [-1] + taplist + [beds]

  longest = 0
  (0..taplist.size-2).each do |i|
    time = 0
    if i == 0 then
      time = taplist[i+1] - taplist[0] + 1
    elsif i == taplist.size-2 then
      time = taplist[-1] - taplist[i] + 1
    else
      time = (taplist[i+1] - taplist[i])/2
    end

    longest = time if time > longest
  end
  puts longest - 1
end


gets.to_i.times{
	n,k=gets.split.map &:to_i
	a=gets.split.map &:to_i
	p [n+1-a[-1],*a.each_cons(2).map{|x,y|(y-x+2)/2}].max
}


gets.to_i.times{
	n,k=gets.split.map &:to_i
	a=gets.split.map &:to_i
	p [a[0],n+1-a[-1],*a.each_cons(2).map{|x,y|(y-x+2)/2}].max
}


def solve
  n, k = gets.strip.split.map(&:to_i)
  a = gets.strip.split.map(&:to_i)
  mx = [a.first, n - a.last + 1].max
  (1...(a.size)).each do |i|
    mx = [mx, ((a[i] - a[i-1] - 1) / 2).ceil + 1].max
  end
  mx
end

gets.strip.to_i.times do
  puts solve
end


def solve
  n, k = gets.strip.split.map(&:to_i)
  a = gets.strip.split.map(&:to_i)
  mx = [a.first, n - a.last + 1].max
  (1...(a.size)).each do |i|
    mx = [mx, ((a[i] - a[i-1] - 1) / 2.0).ceil + 1].max
  end
  mx
end

gets.strip.to_i.times do
  puts solve
end


gets.to_i.times do
  n, m = gets.split.map(&:to_i)
  a = gets.chomp.split.map(&:to_i)
  ans = 0
  (1..n).each do |i|
    tmp = 300
    a.each do |j|
      tmp = [tmp, (i-j).abs + 1].min
    end
    ans = [ans, tmp].max
  end
  puts ans
end


inp = gets.chomp.to_i
otv = []

inp.times{ |w|
count = 0
map = []

row = gets.chomp.split(" ")
gryadok = row[0]

(0..gryadok.to_i-1).each {|w| map[w] = 0}

crans = gets.chomp.split(" ")

startup = []
startdown = []

crans.size.times{|e|
startup[e] = crans[e].to_i-1
startdown[e] = crans[e].to_i-1
}

loop do

crans.size.times{|e|

map[startup[e]] = 1
map[startdown[e]] = 1
if startup[e] > 0
startup[e]-=1
end
if startdown[e] < (gryadok.to_i-1)
startdown[e]+=1
end

}

#puts map.to_s

count+=1
if map.index(0).nil? then otv.push(count);break; end

end

}

otv.size.times{|w|
puts otv[w]
}


inp = gets.chomp.to_i
otv = []

inp.times{ |w|
count = 0

row = gets.chomp.split(" ")
gryadok = row[0]

crans = gets.chomp.split(" ")
crans.each{|w| count+=w.to_i}

if (gryadok.to_i - count.to_i) < 0

otv.push(1)

else

otv.push(gryadok.to_i - count.to_i + 1)

end

}

otv.size.times{ |w|
puts otv[w]
}


def solve n, xs
  xs.sort!
  ans = [1, xs[0], n+1-xs[xs.size-1]].max
  (xs.size - 1).times do |i|
    ans = [ans, (xs[i+1] - xs[i] + 1)/ 2].max
  end
  p ans
end

q = gets.to_i
q.times do
  n, m = gets.chomp.split.map(&:to_i)
  xs = gets.chomp.split.map(&:to_i)
  solve n, xs
end


def solve n, xs
  xs.sort!
  ans = [1, xs[0], n+1-xs[xs.size-1]].max
  (xs.size - 1).times do |i|
    ans = [ans, (xs[i+1] - xs[i] + 2)/ 2].max
  end
  p ans
end

q = gets.to_i
q.times do
  n, m = gets.chomp.split.map(&:to_i)
  xs = gets.chomp.split.map(&:to_i)
  solve n, xs
end


T = input()

for _ in xrange(T):
    n, k = map(int, raw_input().split())
    taps = map(int, raw_input().split())

    q = []
    for i in xrange(k):
        q.append([taps[i], -1, 0])

    d = {}
    while len(q) > 0:
        #print q, sorted(d.items(), key=lambda x: x[0])
        ind, state, secs = q.pop(0)

        if len(d) == n:
            break

        if state == -1:
            q.append([ind, 0, secs+1])
            d[ind] = secs+1
        else:
            if ind-1 not in d and ind-1 >= 1:
                q.append([ind-1, 0, secs+1])
                d[ind-1] = secs+1
            if ind+1 not in d and ind+1 <= n:
                q.append([ind+1, 0, secs+1])
                d[ind+1] = secs+1

    print max(d.values())


t = int(raw_input())
for i in range(t):
    n,k = raw_input().split()
    n = int(n)
    k = int(k)
    taps = raw_input().split()
    taps = [int(x) for x in taps]
    seconds = 0

    garden = ["d"]*n
    for i in taps:
        garden[i-1] = "w"

    seconds = 1
    while 'd' in garden:
        for i in taps:
            if i+seconds <= len(garden):
                garden[i-1+seconds] = "w"
            if i-seconds >= 1:
                garden[i-1-seconds] = "w"
        seconds += 1
    print seconds


R=lambda:map(int,raw_input().split())
for _ in range(input()):
    n,k=R()
    a=R()
    t=max(a[0],n-a[-1]+1)
    for i in range(1,k):
        t=max(t,(a[i]-a[i-1])/2+1)
    print t


def main():
    for _ in xrange(input()):
        l=map(long,raw_input().split())
        k=map(long,raw_input().split())
        p=[0]*(len(k)+1)
        p[0]=k[0]
        for i in xrange(1,len(k)):
            p[i]=(int(round((k[i]-k[i-1]))))
        p.append(l[0]-k[len(k)-1]+1)
        #print p,l[0]-k[len(k)-1],k
        print max(p)

main()


def main():
    for _ in xrange(input()):
        l=map(long,raw_input().split())
        k=map(long,raw_input().split())
        p=[0]*(len(k)+1)
        p[0]=k[0]
        for i in xrange(1,len(k)):
            p[i]=(int(round((k[i]-k[i-1])/2)))+1
        p.append(l[0]-k[len(k)-1]+1)
        #print p,l[0]-k[len(k)-1],k
        if len(k)==l[0]:
            print 1
        else:
            print max(p)
        #print p
main()


t = int(raw_input())
for _ in xrange(t):
    n, k = map(int, raw_input().split(" "))
    a = map(int, raw_input().split(" "))
    b = set(a)
    time = 1
    while len(b) < n:
         time += 1
         c = b.copy()
         for i in b:
             if i > 1:
                c.add(i - 1)
             if i < n:
                c.add(i + 1)
         b = c
         #print n,len(b)
    print time


for _ in range(input()):
    n, k = map(int, raw_input().split())
    l = map(int, raw_input().split())
    l = [i-1 for i in l]
    water = [0]*n
    for i in l:
        water[i] = 1
    time = 1
    while 0 in water:
        l = []
        for i in range(n):
            if i == 0 and water[i] == 1:
                l.append(i+1)
            elif i == n-1 and water[i] == 1:
                l.append(i-1)
            elif water[i] == 1:
                l.append(i-1)
                l.append(i+1)
        for i in l:
            water[i] = 1
        time += 1
    print time


for i in range(input()):
    n, k = map(int, raw_input().split())
    l = [0]*(n+2)
    for i in map(int, raw_input().split()):
        l[i] = 1
    ans = 0
    while True:
        water = []
        ans += 1
        for i in range(1,n+1):
            if l[i] == 1:
                water.append(i-1)
                water.append(i+1)
        for i in water:
            l[i] = 1
        if 0 in l[1:n+2]:
            continue
        else:
            break
    print ans


for i in range(input()):
    n, k = map(int, raw_input().split())
    pair = (0,0)
    l = map(int, raw_input().split())
    water = [0, n+1]
    water += l
    water.sort()
    maxi = -1
    for i in range(1, len(water)):
        if water[i]-water[i-1] > maxi:
            maxi = water[i]-water[i-1]
            pair = (water[i-1], water[i])
    if pair[0] == 0 or pair[1] == n+1:
        print maxi
    else:
        print maxi/2 + 1 if maxi%2 else maxi/2


for i in xrange(input()):
    n, k = map(int, raw_input().split())
    l = [0, n+1]
    l += map(int, raw_input().split())
    l.sort()
    maxi = 0
    n1, n2 = 0, 0
    for i in range(len(l)-1):
        if l[i+1]-l[i] > maxi:
            maxi = l[i+1]-l[i]
            n1 = l[i]
            n2 = l[i+1]
    if n1 == 0 or n2 == n+1:
        print maxi
    else:
        print maxi/2 if maxi%2 == 0 else maxi/2 + 1


def solution():
    t = int(raw_input())
    res = []
    for i in range(t):
        n, k = map(int, raw_input().strip().split())
        arr = list(map(int, raw_input().strip().split()))
        left_dist, right_dist, max_dist = arr[0], n - arr[-1] + 1, 0
        for i in range(k)[1:]:
            if arr[i] - arr[i - 1] + 1 > max_dist:
                max_dist = arr[i] - arr[i - 1] + 1
        res.append(max(left_dist, right_dist, (max_dist + 1) / 2))
    return res

if __name__ ==  '__main__':
    for item in solution():
        print item


t=int(raw_input())
for k in range(t):
    n,m=map(int,raw_input().strip().split())
    l=map(int,raw_input().strip().split())
    max1=0
    for i in range(1,m):
        diff=l[i]-l[i-1]-1
        if max1<diff:
            max1=diff
    if max1%2==0:
        ans=max1/2+1
    else:
        ans=max1/2+2
    print max(ans,l[0],n+1-l[-1])


t = int(raw_input())

for _ in range(t):
  garden_size, num_hoses = map(int, raw_input().split())
  arr = map(int, raw_input().split())

  #print "arr: " + str(arr)
  max_difference = max(arr[0], 1 + garden_size - arr[-1])
  #print "max_difference: " + str(max_difference)
  for i in range(1, len(arr)):
    max_difference = max(max_difference,
                         1 + (arr[i] - arr[i - 1]) / 2)

  print max_difference

# [1, 2]
# [1, 2]


t = int(raw_input())

for _ in range(t):
  garden_size, num_hoses = map(int, raw_input().split())
  arr = map(int, raw_input().split())

  #print "arr: " + str(arr)
  max_difference = max(arr[0] - 1, 1 + garden_size - arr[-1])
  #print "max_difference: " + str(max_difference)
  for i in range(1, len(arr)):
    max_difference = max(max_difference,
                         1 + (arr[i] - arr[i - 1]) / 2)

  print max_difference


t=input()
for _ in range(t):
    n,k=map(int,raw_input().split())
    a=[0 for i in range(n+1)]
    b=list(map(int,raw_input().split()))
    for i in range(k):
        for j in range(b[i],n+1):
            if a[j]==0:
                a[j]=j-b[i]+1
                continue
            a[j]=min(a[j],j-b[i]+1)
        for j in range(b[i],0,-1):
            if a[j]==0:
                a[j]=j-b[i]+1
                continue
            a[j]=min(a[j],b[i]-j+1)
    ans=a[1]
    for i in range(1,n+1):
        ans=max(a[i],ans)
    print ans


t=input()
for _ in range(t):
    n,k=map(int,raw_input().split())
    a=[0 for i in range(n+1)]
    b=list(map(int,raw_input().split()))
    for i in range(k):
        for j in range(b[i],n+1):
            if a[j]==0:
                a[j]=j-b[i]+1
                continue
            a[j]=min(a[j],j-b[i]+1)
        for j in range(b[i],0,-1):
            if a[j]==0:
                a[j]=b[i]-j+1
                continue
            a[j]=min(a[j],b[i]-j+1)
    ans=a[1]
    for i in range(1,n+1):
        ans=max(a[i],ans)
    print ans


n =int(raw_input())
for i in range(n):
    m,k = map(int,raw_input().split())
    arr = map(int,raw_input().split())
    s = (m*(m+1))/2
    gar = [i for i in range(1,m+1)]
    sec = 1
    for j in range(k):
        c = arr[j]-(sec-1)
        gar[c-1] = 0
        s -= c
    while(s>0):
        sec += 1
        for j in range(k):
            c,d = arr[j]-(sec-1),arr[j]+(sec-1)
            if c>0 and c<=m :
                if gar[c-1]>0:
                    gar[c-1]=0
                    s -=c
            if d>0 and d<=m :
                if gar[d-1]>0:
                    gar[d-1]=0
                    s -=d
    print sec


for i in xrange(input()):
	n,k = map(int,raw_input().split())
	l = map(int,raw_input().split())
	ma=0
	for j in range(k-1):
		if abs(l[j]-l[j+1])>ma:
			ma=abs(l[j]-l[j+1])
	ma-=1
	if ma%2==0:
		t=ma//2
	else:
		t=(ma+1)//2
	print(max(t,l[0],(n-l[-1])+1))


for i in xrange(input()):
	n,k = map(int,raw_input().split())
	l = map(int,raw_input().split())
	ma=0
	for j in range(k-1):
		if abs(l[j]-l[j+1])>ma:
			ma=abs(l[j]-l[j+1])
	if ma%2==0:
		t=(ma//2)+1
	else:
		t=(ma+1)//2
	print(max(t,l[0],(n-l[-1])+1))


for i in xrange(input()):
	n,k = map(int,raw_input().split())
	l = map(int,raw_input().split())
	ma=0
	for j in range(k-1):
		if abs(l[j]-l[j+1])>ma:
			ma=abs(l[j]-l[j+1])
	if ma%2==0:
		t=ma//2
	else:
		t=(ma+1)//2
	print(max(t,l[0],(n-l[-1])+1))


t=input()
for i in range(t):
    n,k=map(int,raw_input().split())
    arr=map(int,raw_input().split())
    a=arr[0]
    b=arr[-1]
    new=[]
    m=0
    for i in range(k-1):
        m=max(m,(arr[i+1]-arr[i])/2 + 1)
    s=max(a,n-b+1,m)
    print s


n = int(raw_input())
for _ in xrange(n):
	a,b = map(int,raw_input().split())
	c = map(int,raw_input().split())
	d = max(c[0],a-c[-1]+1)
	for i in xrange(1,b):
		d = max(d,int((c[i]-c[i-1]+1)/2))
	print d


n = int(raw_input())
for _ in xrange(n):
	a,b = map(int,raw_input().split())
	c = map(int,raw_input().split())
	d = max(c[0],a-c[-1]+1)
	for i in xrange(1,b):
		d = max(d,int((c[i]-c[i-1])/2+1))
	print d


for i in range(input()):
	n,k = map(int,raw_input().split())
	a = map(int,raw_input().split())
	time = 0
	ax=[0 for j in range(n)]
	for i in a: ax[i-1]=1
	while 1:
		xd=[0]*n
		if ax.count(1) == n:
			break
		for j in range(n):
			if j==n-1:
				if ax[j-1] == 1: xd[j] = 1
			elif j==0:
				if ax[j+1] == 1: xd[j] = 1
			else:
				if ax[j-1] == 1: xd[j] = 1
				if ax[j+1] == 1: xd[j] = 1
			if ax[j] == 1: xd[j] = 1
		ax = [xd[i] for i in range(n)]
		time+=1
	print time+1


t=int(raw_input())
while t!=0:
	t=t-1
	n,k=map(int,raw_input().split(' '))
	c=map(int,raw_input().split(' '))
	l=1
	s=[0]
	for i in range(1,n+1):
		s.append(i)
	a1=set([0])
	while 1:

		for i in range(len(c)):
			lp=c[i]+l-1
			ln=c[i]-(l-1)
			if ln>0:
				for p in range(ln,lp+1):
					a1.add(p)
			else:
				for p in range(0,lp+1):
					a1.add(p)
		flag=-1

		if len(a1)>=(n):
			b1=list(a1)
			for p in s:
				if p not in b1:
					flag=1
					break
			if flag==1:
				l=l+1
			else:
				print l
				break

		else:
			l=l+1


t=int(raw_input())
while t!=0:
	t=t-1
	n,k=map(int,raw_input().split(' '))
	c=map(int,raw_input().split(' '))
	l=1
	s=[]
	for i in range(1,n+1):
		s.append(i)
	a1=[]
	while 1:

		for i in range(len(c)):
			lp=c[i]+l-1
			ln=c[i]-(l-1)
			if lp>0:
				a1.append(lp)
			if ln>0:
				a1.append(ln)
		if list(set(a1))==s:
			print l
			break
		else:
			l=l+1


t=int(raw_input())
while t!=0:
	t=t-1
	n,k=map(int,raw_input().split(' '))
	c=map(int,raw_input().split(' '))
	l=1
	s=[0]
	for i in range(1,n+1):
		s.append(i)
	a1=[0]
	while 1:

		for i in range(len(c)):
			lp=c[i]+l-1
			ln=c[i]-(l-1)
			if ln>0:
				for p in range(ln,lp+1):
					a1.append(p)
			else:
				for p in range(0,lp+1):
					a1.append(p)
		if list(set(a1))==s:
			print l
			break
		else:
			l=l+1


def findTime(n, dict):
    time = 1
    while len(dict) < n:
        time += 1
        for tap in dict.keys():
            if tap-1 >= 0 and tap-1 not in dict:
                dict[tap-1] = 1
            if tap +1 < n and tap+1 not in dict:
                dict[tap+1] = 1
    return time

n = input()
for a0 in range(n):
    tapL = {}
    gardenBeds, waterTaps = map(int, raw_input().split())
    tapsLocation = [int(x) - 1 for x in raw_input().split()]
    for tap in tapsLocation:
        tapL[tap] = 1
    x = findTime(gardenBeds, tapL)
    print x


l=lambda:map(int,raw_input().split())
t=input()
for _ in range(t):
    n,k=l()
    beds=['1']*n
    a=l()
    for i in a:
        beds[i-1]='0'
    x=''.join(beds).strip('0')
    x=map(len,''.join(x).split('0'))
    xl=len(x)
    if xl==0:
        print 1
    elif xl==1:
        if beds[0]=='0' and beds[-1]=='0':
            if x[0]%2:
                print x[0]/2+2
            else:
                print x[0]/2+1
        else:
            print x[0]+1
    elif xl==2:
        print max(x[0],x[1])+1
    else:
        print max(max(x[0],x[-1])+1,max(x[1:-1])/2+1)


l=lambda:map(int,raw_input().split())
t=input()
for _ in range(t):
    n,k=l()
    beds=['0']*n
    a=l()
    for i in a:
        beds[i-1]='1'
    x=''.join(beds).split('1')
    x=map(len,x)
    xlen=len(x)
    if xlen==0:
        print 1
    elif xlen==1:
        if beds[0]=='1' and beds[-1]=='1':
            if x[0]%2:
                print x[0]/2+2
            else:
                print x[0]/2+1
        else:
            print x[0]+1
    elif xlen==2:
        print max(x[0],x[1])+1
    else:
        ans=max(x[0],x[-1])
        mid_max=max(x[1:-1])
        if mid_max%2:
            print max(ans,mid_max/2+1)+1
        else:
            print max(ans,mid_max/2)+1


t = int(raw_input())
ans=[]
#x -> n[x+1] index in list

for _ in range(0,t):
    n,k = map(int,raw_input().split())
    nlist=[]
    nlist.extend(range(1,n+1))
    i = raw_input()
    ilist= map(int, i.split())
    ans=ilist[0]
    for a in range(1,k):
        ans=max(ans,(ilist[a]-ilist[a-1]+2)/2)
    #for op in nlist[nlist.index(ilist)::-1]:
        #ans.append(op)
    print max(ans,n+1-ilist[-1])


import numpy
t = int(raw_input())
ans=[]
#x -> n[x+1] index in list

for _ in range(0,t):
    n,k = map(int,raw_input().split())
    nlist=[]
    nlist.extend(range(1,n))
    i = raw_input()
    ilist=[]
    ilist= map(int, i.split())
    if k == 1:
    #works only when k = 1
        ilist = ilist[0]
        for op in nlist[nlist.index(ilist)::-1]:
            ans.append(op)
    print len(ans)

    #elif k != 1:
    #T = map(lambda k: nlist[k], ilist)
    #print T


from sys import stdin
lines = stdin.readlines()
t = int(lines[0])
def bul(x):
    return [i for i in range(1,x+1)]
for i in range(1,2*t,2):
    k = int(lines[i].split()[0])

    liste = map(int,lines[i+1].split())
    liste2 = bul(k)
    liste3 = []
    for j in liste2:
        mini = k
        for p in liste:
            c = abs(j-p)
            if c < mini:
                mini = c
        liste3.append(mini)
    print max(liste3)+1


t = int(raw_input(''))
for x in range(0, t, +1):
    n,m = map(int, raw_input('').split(' '))
    l = map(int, raw_input('').split(' '))
    temp_min = l[0]
    if (n+1)-l[-1] > temp_min:
        temp_min = (n+1)-l[-1]
    for y in range(0, m-1, +1):
        if (l[y+1] - l[y])/2 + 1 > temp_min:
            temp_min = (l[y+1] - l[y])/2 + 1
    print temp_min


t = input()
while(t>0):
    t-=1

    n,k = map(int,raw_input().split())
    l = map(int,raw_input().split())
    main = [999999999]*n
    for i in range(n):
        for j in range(n):
            if j+1 in l:
                main[i] = min(main[i],abs(j-i))

    print max(main)+1


T=int(raw_input())

for a0 in xrange(T):
	n,k=map(int,raw_input().split(' '))
	pos=map(int,raw_input().split(' '))
	pos=sorted(pos)
	maxim=0
	for i in xrange(k-1):
		t=(pos[i+1]-pos[i])/2
		t=t+1
		if(t>maxim):
			maxim=t

	print(max([pos[0],n-pos[k-1]+1,maxim]))


from fractions import gcd
from math import factorial, ceil, sqrt, atan2, log, pi, e
from itertools import *
import string
import copy
import random
import bisect
from decimal import *
def id_generator(size=20, chars=string.digits):
    return ''.join(random.choice(chars) for _ in range(size))

def mp():
    return map(int,str(raw_input()).split())

t=input()
for i in range(t):
	n,k=mp()
	l=list(mp())
	z=[10**18 for i in range(n)]
	for i in range(n):
		for j in range(k):
			z[i]=min(z[i],abs(l[j]-i-1)+1)
	print max(z)


for _ in xrange(int(raw_input())):
  n, k = map(int, raw_input().split())
  x = map(int, raw_input().split())
  ans = x[0]
  p = x[0]
  for i in x[1:]:
    t = (i - p) / 2 + 1
    ans = max(ans, t)
    p = i
  ans = max(ans, n - p + 1)
  print ans


#include <stdio.h>

int main ()
{
    int t;
    scanf ("%d", &t);
    while (t--) {
        int n, k, i, j, time = 0, l;
        scanf ("%d%d", &n, &k);
        int tap [k+2];
        for (i = 0; i < k; i++) scanf ("%d", &tap [i]);
        tap [i] = 0;
        tap [i+1] = n+1;
        for (i = 1; i < k+2; i++) {
            for (j = 0; j < k+2-i; j++) {
                if (tap [j] > tap [j+1]) {
                    int temp = tap [j];
                    tap [j] = tap [j+1];
                    tap [j+1] = temp;
                }
            }
        }
        for (i = 0; i < k+1; i++) {
            if (tap [i+1] - tap [i] > time) {
                time = tap [i+1] - tap [i];
                l = i;
            }
        }
        if (l == 0 || l == k) printf ("%d\n", time);
        else printf ("%d\n", time/2+1);
    }
    return 0;
}


#include <stdio.h>

int main ()
{
    int t;
    scanf ("%d", &t);
    while (t--) {
        int n, k, i, j, time = 0, l;
        scanf ("%d%d", &n, &k);
        int tap [k+2];
        for (i = 0; i < k; i++) scanf ("%d", &tap [i]);
        tap [i] = 0;
        tap [i+1] = n+1;
        for (i = 1; i < k+2; i++) {
            for (j = 0; j < k+2-i; j++) {
                if (tap [j] > tap [j+1]) {
                    int temp = tap [j];
                    tap [j] = tap [j+1];
                    tap [j+1] = temp;
                }
            }
        }
        for (i = 0; i < k+1; i++) {
            if (tap [i+1] - tap [i] > time) {
                time = tap [i+1] - tap [i];
                l = i;
            }
        }
        if (l == 0 || l == k) printf ("%d\n", time);
        else printf ("%d\n", (time+1)/2);
    }
    return 0;
}


#include <stdio.h>

int main ()
{
    int t;
    scanf ("%d", &t);
    while (t--) {
        int n, k, i, j, time = 0;
        scanf ("%d%d", &n, &k);
        int tap [k+2];
        for (i = 0; i < k; i++) scanf ("%d", &tap [i]);
        tap [i] = 0;
        tap [i+1] = n+1;
        for (i = 1; i < k+2; i++) {
            for (j = 0; j < k+2-i; j++) {
                if (tap [j] > tap [j+1]) {
                    int temp = tap [j];
                    tap [j] = tap [j+1];
                    tap [j+1] = temp;
                }
            }
        }
        for (i = 0; i < k+1; i++) {
            if (tap [i+1] - tap [i] > time) {
                time = tap [i+1] - tap [i];
            }
        }
        printf ("%d\n", time);
    }
    return 0;
}


#include <stdio.h>

int max (int a, int b)
{
    int m = (a > b) ? a : b;
    return m;
}
int main ()
{
    int t;
    scanf ("%d", &t);
    while (t--) {
        int n, k, i, j;
        int x = 0, y, z;
        scanf ("%d%d", &n, &k);
        int tap [k];
        for (i = 0; i < k; i++) scanf ("%d", &tap [i]);
        for (i = 1; i < k; i++) {
            for (j = 0; j < k-i; j++) {
                if (tap [j] > tap [j+1]) {
                    int temp = tap [j];
                    tap [j] = tap [j+1];
                    tap [j+1] = temp;
                }
            }
        }
        for (i = 0; i < k-1; i++) {
            if (tap [i+1] - tap [i] > x) {
                x = tap [i+1] - tap [i];
            }
        }
        x = (x+2)/2;
        y = tap [0];
        z = n - tap [k-1] +1;
        int ans = max (y, z);
        ans = max (ans, x);
        printf ("%d\n", ans);
    }
    return 0;
}


#include <stdio.h>

int main ()
{
    int t;
    scanf ("%d", &t);
    while (t--) {
        int n, k, i, j, time = 0, l;
        scanf ("%d%d", &n, &k);
        int tap [k+2];
        for (i = 0; i < k; i++) scanf ("%d", &tap [i]);
        tap [i] = 0;
        tap [i+1] = n+1;
        for (i = 1; i < k+2; i++) {
            for (j = 0; j < k+2-i; j++) {
                if (tap [j] > tap [j+1]) {
                    int temp = tap [j];
                    tap [j] = tap [j+1];
                    tap [j+1] = temp;
                }
            }
        }
        for (i = 0; i < k+1; i++) {
            if (i == 0 || i == k) {
                if (tap [i+1] - tap [i] > time) {
                    l = i;
                    time = tap [i+1] - tap [i];
                }
            }
            else {
                if ((tap [i+1] - tap [i]+1)/2 > time) {
                    l = i;
                    time = (tap [i+1] - tap [i] +1)/2;
                }
            }
        }
        if (l == 0 || l == k) printf ("%d\n", time);
        else printf ("%d\n", (time/2)+1);
    }
    return 0;
}


#include <stdio.h>

int main ()
{
    int t;
    scanf ("%d", &t);
    while (t--) {
        int n, k, i, j, time = 0, l;
        scanf ("%d%d", &n, &k);
        int tap [k+2];
        for (i = 0; i < k; i++) scanf ("%d", &tap [i]);
        tap [i] = 0;
        tap [i+1] = n+1;
        for (i = 1; i < k+2; i++) {
            for (j = 0; j < k+2-i; j++) {
                if (tap [j] > tap [j+1]) {
                    int temp = tap [j];
                    tap [j] = tap [j+1];
                    tap [j+1] = temp;
                }
            }
        }
        for (i = 0; i < k+1; i++) {
            if (tap [i+1] - tap [i] > time) {
                time = tap [i+1] - tap [i];
                l = i;
            }
        }
        if (l == 0 || l == k) printf ("%d\n", time);
        else printf ("%d\n", (time+1)/2+1);
    }
    return 0;
}


#include<stdio.h>
int maximum(int a,int b)
{
    int d;
    if (a>b)
        d=a;
    else d=b;
    return d;
}
int main(){
int test;
scanf("%d",&test);
for(int i=0;i<test;i++)
{
    int n,k;
    scanf("%d%d",&n,&k);
    int a[k];
    for(int j=0;j<k;j++)
        scanf("%d",&a[j]);
    int max=0;
    for(int j=0;j<k-1;j++)
    {
        if(a[j+1]-a[j]>max)
            max=a[j+1]-a[j];
    }
    int d=maximum(a[0],n-a[k-1]+1);
    int e=maximum(d,(max/2)+1);
    printf("%d\n",e);

}
return 0;
}


#pragma GCC optimize(2)
#include<bits/stdc++.h>
using namespace std;
const int N = 2e5 + 7;
typedef long long ll;
const int INF = 0x3f3f3f3f;
int a[N],n;
vector<char>ans;

signed main()
{
    ios::sync_with_stdio(0);
    int n;
    cin >> n;
    for(int i = 1; i <= n; i++) cin >> a[i];

    int l = 1, r = n, k = n, maxv = 0;
    while(l <= r && k--)
    {
        if(a[l] > maxv && a[r] > maxv)
        {
            if(a[l] < a[r])
            {
                ans.push_back('L');
                maxv = a[l];
                l++;
            }
            else if(a[l] > a[r])
            {
                ans.push_back('R');
                maxv = a[r];
                r--;
            }
        }

        if(a[l] <= maxv && a[r] > maxv)
        {
            ans.push_back('R');
            maxv = a[r];
            r--;
        }

        if(a[l] > maxv && a[r] <= maxv)
        {
            ans.push_back('L');
            maxv = a[l];
            l++;
        }

        if(a[l] == a[r])
        {
            if(a[l] > maxv)
            {
                int x = l, y = r, cnt1 = 1,cnt2 = 1;
                char op;
                while(a[x] < a[x + 1] && x+1 <= r)  cnt1++,x++;
                while(a[y] < a[y-1] && y - 1 >= l)  cnt2++,y--;
                if(cnt1 >= cnt2) op = 'L';
                else             op = 'R';
                for(int i = 1; i <= max(cnt1, cnt2); i++)
                    ans.push_back(op);
            }
            break;
        }
    }

    cout << ans.size() << endl;
    for(int i = 0; i < ans.size(); i++)
        cout << ans[i];

    return 0;
}


#pragma GCC optimize(2)
#include<bits/stdc++.h>
using namespace std;
const int N = 2e5 + 7;
typedef long long ll;
const int INF = 0x3f3f3f3f;
int a[N],n;
vector<char>ans;

signed main()
{
    ios::sync_with_stdio(0);
    int n;
    cin >> n;
    for(int i = 1; i <= n; i++) cin >> a[i];

    int l = 1, r = n, maxv = 0;
    while(l < r)
    {
        if(a[l] > maxv && a[r] > maxv)
        {
            if(a[l] < a[r])
            {
                ans.push_back('L');
                maxv = a[l];
                l++;
            }
            else if(a[l] > a[r])
            {
                ans.push_back('R');
                maxv = a[r];
                r--;
            }
        }

        if(a[l] <= maxv && a[r] > maxv)
        {
            ans.push_back('R');
            maxv = a[r];
            r--;
        }

        if(a[l] > maxv && a[r] <= maxv)
        {
            ans.push_back('L');
            maxv = a[l];
            l++;
        }

        if(a[l] == a[r])
        {
            if(a[l] > maxv)
            {
                int x = l, y = r, cnt1 = 1,cnt2 = 1;
                char op;
                while(a[x] < a[x + 1] && x+1 <= r)  cnt1++,x++;
                while(a[y] < a[y-1] && y - 1 >= l)  cnt2++,y--;
                if(cnt1 >= cnt2) op = 'L';
                else             op = 'R';
                for(int i = 1; i <= max(cnt1, cnt2); i++)
                    ans.push_back(op);
            }
            break;
        }
    }

    cout << ans.size() << endl;
    for(int i = 0; i < ans.size(); i++)
        cout << ans[i];

    return 0;
}


#pragma GCC optimize(2)
#include<bits/stdc++.h>
using namespace std;
const int N = 2e5 + 7;
typedef long long ll;
const int INF = 0x3f3f3f3f;
int a[N],n;
vector<char>ans;

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

    int l = 1, r = n, lst = 0;
    for(int i=1;i <=n && l <= r; i++)
    {
        if(a[l] > lst && a[r] > lst)
        {
            if(a[l]<a[r])
            {
                ans.push_back('L');
                lst = a[l];
                l++;
            }
            else if(a[l] > a[r])
            {
                ans.push_back('R');
                lst = a[r];
                r--;
            }
        }
        if(a[l] <= lst && a[r] > lst)
        {
            ans.push_back('R');
            lst = a[r];
            r--;
        }
        if(a[l] > lst && a[r] <= lst)
        {
            ans.push_back('L');
            lst = a[l];
            l++;
        }
        if(a[l] == a[r] && a[l] > lst)
        {
            int x = l, y = r, cnt1 = 1,cnt2 = 1;
            char op;
            while(a[x] < a[x + 1] && x+1 <= r)  cnt1++,x++;
            while(a[y] < a[y-1] && y - 1 >= l)  cnt2++,y--;
            if(cnt1 >= cnt2) op = 'L';
            else             op = 'R';
            for(int i = 1; i <= max(cnt1, cnt2); i++)
                ans.push_back(op);
            break;
        }
    }
    int m = ans.size();
    cout << m << endl;
    for(int i = 0; i < m; i++)
        cout << ans[i];
    //sys;
    return 0;
}


#pragma GCC optimize(2)
#include<bits/stdc++.h>
using namespace std;
const int N = 2e5 + 7;
typedef long long ll;
const int INF = 0x3f3f3f3f;
int a[N],n;
vector<char>ans;

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

    int l = 1, r = n, lst = 0;
    while(l < r)
    {
        if(a[l] > lst && a[r] > lst)
        {
            if(a[l] < a[r])
            {
                ans.push_back('L');
                lst = a[l];
                l++;
            }
            else if(a[l] > a[r])
            {
                ans.push_back('R');
                lst = a[r];
                r--;
            }
        }

        if(a[l] <= lst && a[r] > lst)
        {
            ans.push_back('R');
            lst = a[r];
            r--;
        }

        if(a[l] > lst && a[r] <= lst)
        {
            ans.push_back('L');
            lst = a[l];
            l++;
        }

        if(a[l] == a[r] && a[l] > lst)
        {
            int x = l, y = r, cnt1 = 1,cnt2 = 1;
            char op;
            while(a[x] < a[x + 1] && x+1 <= r)  cnt1++,x++;
            while(a[y] < a[y-1] && y - 1 >= l)  cnt2++,y--;
            if(cnt1 >= cnt2) op = 'L';
            else             op = 'R';
            for(int i = 1; i <= max(cnt1, cnt2); i++)
                ans.push_back(op);
            break;
        }
    }

    cout << ans.size() << endl;
    for(int i = 0; i < ans.size(); i++)
        cout << ans[i];
    return 0;
}


#pragma GCC optimize(2)
#include<bits/stdc++.h>
using namespace std;
const int N = 2e5 + 7;
typedef long long ll;
const int INF = 0x3f3f3f3f;
int a[N],n;
vector<char>ans;

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

    int l = 1, r = n, maxv = 0;
    while(l < r)
    {
        if(a[l] > maxv && a[r] > maxv)
        {
            if(a[l] < a[r])
            {
                ans.push_back('L');
                maxv = a[l];
                l++;
            }
            else if(a[l] > a[r])
            {
                ans.push_back('R');
                maxv = a[r];
                r--;
            }
        }

        if(a[l] <= maxv && a[r] > maxv)
        {
            ans.push_back('R');
            maxv = a[r];
            r--;
        }

        if(a[l] > maxv && a[r] <= maxv)
        {
            ans.push_back('L');
            maxv = a[l];
            l++;
        }

        if(a[l] == a[r])
        {
            if(a[l] > maxv)
            {
                int x = l, y = r, cnt1 = 1,cnt2 = 1;
                char op;
                while(a[x] < a[x + 1] && x+1 <= r)  cnt1++,x++;
                while(a[y] < a[y-1] && y - 1 >= l)  cnt2++,y--;
                if(cnt1 >= cnt2) op = 'L';
                else             op = 'R';
                for(int i = 1; i <= max(cnt1, cnt2); i++)
                    ans.push_back(op);
            }
            break;
        }
    }

    cout << ans.size() << endl;
    for(int i = 0; i < ans.size(); i++)
        cout << ans[i];

    return 0;
}


#pragma GCC optimize(2)
#include<bits/stdc++.h>
using namespace std;
const int N = 2e5 + 7;
typedef long long ll;
const int INF = 0x3f3f3f3f;
int a[N],n;
vector<char>ans;

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

    int l = 1, r = n, lst = 0;
    while(l <= r)
    {
        if(a[l] > lst && a[r] > lst)
        {
            if(a[l] < a[r])
            {
                ans.push_back('L');
                lst = a[l];
                l++;
            }
            else if(a[l] > a[r])
            {
                ans.push_back('R');
                lst = a[r];
                r--;
            }
        }

        if(a[l] <= lst && a[r] > lst)
        {
            ans.push_back('R');
            lst = a[r];
            r--;
        }

        if(a[l] > lst && a[r] <= lst)
        {
            ans.push_back('L');
            lst = a[l];
            l++;
        }

        if(a[l] == a[r] && a[l] > lst)
        {
            int x = l, y = r, cnt1 = 1,cnt2 = 1;
            char op;
            while(a[x] < a[x + 1] && x+1 <= r)  cnt1++,x++;
            while(a[y] < a[y-1] && y - 1 >= l)  cnt2++,y--;
            if(cnt1 >= cnt2) op = 'L';
            else             op = 'R';
            for(int i = 1; i <= max(cnt1, cnt2); i++)
                ans.push_back(op);
            break;
        }
    }

    cout << ans.size() << endl;
    for(int i = 0; i < ans.size(); i++)
        cout << ans[i];
    //sys;
    return 0;
}


#pragma GCC optimize(2)
#include<bits/stdc++.h>
using namespace std;
const int N = 2e5 + 7;
typedef long long ll;
const int INF = 0x3f3f3f3f;
int a[N],n;
vector<char>ans;

signed main()
{
    ios::sync_with_stdio(0);
    int n;
    cin >> n;
    for(int i = 1; i <= n; i++) cin >> a[i];

    int l = 1, r = n, , k = n, maxv = 0;
    while(l <= r && k--)
    {
        if(a[l] > maxv && a[r] > maxv)
        {
            if(a[l] < a[r])
            {
                ans.push_back('L');
                maxv = a[l];
                l++;
            }
            else if(a[l] > a[r])
            {
                ans.push_back('R');
                maxv = a[r];
                r--;
            }
        }

        if(a[l] <= maxv && a[r] > maxv)
        {
            ans.push_back('R');
            maxv = a[r];
            r--;
        }

        if(a[l] > maxv && a[r] <= maxv)
        {
            ans.push_back('L');
            maxv = a[l];
            l++;
        }

        if(a[l] == a[r])
        {
            if(a[l] > maxv)
            {
                int x = l, y = r, cnt1 = 1,cnt2 = 1;
                char op;
                while(a[x] < a[x + 1] && x+1 <= r)  cnt1++,x++;
                while(a[y] < a[y-1] && y - 1 >= l)  cnt2++,y--;
                if(cnt1 >= cnt2) op = 'L';
                else             op = 'R';
                for(int i = 1; i <= max(cnt1, cnt2); i++)
                    ans.push_back(op);
            }
            break;
        }
    }

    cout << ans.size() << endl;
    for(int i = 0; i < ans.size(); i++)
        cout << ans[i];

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ss second
#define ff first
#define f(i,k,n) for(ll i=k;i<n;i++)
#define E "\n"
#define FAST ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);srand(time(NULL))
ll n,ans=0;
string s;
map<ll,ll> mp;

int main()
{
    FAST;
    cin>>n;
    vector<ll> a;
    vector<char> x;

    ll temp;
    f(i,0,n)cin>>temp,a.push_back(temp);
    if(is_sorted(a.begin(),a.end())){
        cout<<n<<E;
        f(i,0,n)cout<<"L";
        return 0;
    }

    temp=LLONG_MIN;
    ll left=0,right=n-1;
    while(a.size())
    {
       ll lft=a[left],rgt=a[right];
        if(lft<rgt)
        {
            if(lft>temp) x.push_back('L'),temp=left,left++;
            else   x.push_back('R'),temp=right,right--;
        }
        else if(rgt>temp ) x.push_back('R'),temp=right,right--;
        else if(lft>temp)  x.push_back('L'),temp=left,left++;
        else break;
        //cout<<a[0]<<" "<<a[a.size()-1]<<" "<<temp<<E;
    }
    cout<<x.size()<<E;
    for(auto d:x)cout<<(char)d;
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ss second
#define ff first
#define f(i,k,n) for(ll i=k;i<n;i++)
#define E "\n"
#define FAST ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);srand(time(NULL))
ll n,ans=0;
string s;
map<ll,ll> mp;

int main()
{
    FAST;
    cin>>n;
    vector<ll> a;
    vector<char> x;

    ll temp;
    f(i,0,n)cin>>temp,a.push_back(temp);

    temp=LLONG_MIN;
    while(a.size())
    {
       ll left=a[0],right=a[a.size()-1];
        if(left<right)
        {
            if(left>temp) x.push_back('L'),temp=left,a.erase(a.begin());
            else   x.push_back('R'),temp=right,a.erase(a.end()-1);
        }
        else if(right>temp ) x.push_back('R'),temp=right,a.erase(a.end()-1);
        else if(left>temp)  x.push_back('L'),temp=left,a.erase(a.begin());
        else break;
        //cout<<a[0]<<" "<<a[a.size()-1]<<" "<<temp<<E;
    }
    cout<<x.size()<<E;
    for(auto d:x)cout<<(char)d;
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ss second
#define ff first
#define f(i,k,n) for(ll i=k;i<n;i++)
#define E "\n"
#define FAST ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);srand(time(NULL))
ll n,ans=0;
string s;
map<ll,ll> mp;

int main()
{
    FAST;
    cin>>n;
    vector<ll> a;
    vector<char> x;

    ll temp;
    f(i,0,n)cin>>temp,a.push_back(temp);
    if(is_sorted(a.begin(),a.end())){
        cout<<n<<E;
        f(i,0,n)cout<<"L";
        return 0;
    }

    temp=LLONG_MIN;
    ll left=0,right=n-1;
    while(left<=right)
    {
       ll lft=a[left],rgt=a[right];
        if(lft<rgt)
        {
            if(lft>temp) x.push_back('L'),temp=left,left++;
            else   x.push_back('R'),temp=right,right--;
        }
        else if(rgt>temp ) x.push_back('R'),temp=right,right--;
        else if(lft>temp)  x.push_back('L'),temp=left,left++;
        else break;
        //cout<<a[0]<<" "<<a[a.size()-1]<<" "<<temp<<E;
    }
    cout<<x.size()<<E;
    for(auto d:x)cout<<(char)d;
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ss second
#define ff first
#define f(i,k,n) for(ll i=k;i<n;i++)
#define E "\n"
#define FAST ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);srand(time(NULL))
ll n,ans=0;
string s;
map<ll,ll> mp;

int main()
{
    FAST;
    cin>>n;
    vector<ll> a;
    vector<char> x;

    ll temp;
    f(i,0,n)cin>>temp,a.push_back(temp);
    if(is_sorted(a,a+n)){
        cout<<n<<E;
        f(i,0,n)cout<<"L";
        return 0;
    }

    temp=LLONG_MIN;
    while(a.size())
    {
       ll left=a[0],right=a[a.size()-1];
        if(left<right)
        {
            if(left>temp) x.push_back('L'),temp=left,a.erase(a.begin());
            else   x.push_back('R'),temp=right,a.erase(a.end()-1);
        }
        else if(right>temp ) x.push_back('R'),temp=right,a.erase(a.end()-1);
        else if(left>temp)  x.push_back('L'),temp=left,a.erase(a.begin());
        else break;
        //cout<<a[0]<<" "<<a[a.size()-1]<<" "<<temp<<E;
    }
    cout<<x.size()<<E;
    for(auto d:x)cout<<(char)d;
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ss second
#define ff first
#define f(i,k,n) for(ll i=k;i<n;i++)
#define E "\n"
#define FAST ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);srand(time(NULL))
ll n,ans=0;
string s;
map<ll,ll> mp;

int main()
{
    FAST;
    cin>>n;
    vector<ll> a;
    vector<char> x;

    ll temp;
    f(i,0,n)cin>>temp,a.push_back(temp);
    if(is_sorted(a.begin(),a.end())){
        cout<<n<<E;
        f(i,0,n)cout<<"L";
        return 0;
    }

    temp=LLONG_MIN;
    ll left=0,right=n-1;
    while(left<=right)
    {
       ll lft=a[left],rgt=a[right];
        if(lft<rgt)
        {
            if(lft>temp) x.push_back('L'),temp=lft,left++;
            else   x.push_back('R'),temp=rgt,right--;
        }
        else if(rgt>temp ) x.push_back('R'),temp=rgt,right--;
        else if(lft>temp)  x.push_back('L'),temp=lft,left++;
        else break;
        //cout<<lft<<" "<<rgt<<" "<<temp<<E;
    }
    cout<<x.size()<<E;
    for(auto d:x)cout<<(char)d;
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ss second
#define ff first
#define f(i,k,n) for(ll i=k;i<n;i++)
#define E "\n"
#define FAST ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);srand(time(NULL))
ll n,ans=0;
string s;
map<ll,ll> mp;

int main()
{
    FAST;
    cin>>n;
    vector<ll> a;
    vector<char> x;

    ll temp;
    f(i,0,n)cin>>temp,a.push_back(temp);
    if(is_sorted(a.begin(),a.end())){
        cout<<n<<E;
        f(i,0,n)cout<<"L";
        return 0;
    }

    temp=LLONG_MIN;
    ll left=0,right=n-1;
    while(left<=right)
    {
       ll lft=a[left],rgt=a[right];
        if(lft<rgt)
        {
            if(lft>temp) x.push_back('L'),temp=lft,left++;
            else if(rgt>temp)   x.push_back('R'),temp=rgt,right--;
            else break;
        }
        else if(rgt>temp ) x.push_back('R'),temp=rgt,right--;
        else if(lft>temp)  x.push_back('L'),temp=lft,left++;
        else break;
        //cout<<lft<<" "<<rgt<<" "<<temp<<E;
    }
    cout<<x.size()<<E;
    for(auto d:x)cout<<(char)d;
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ss second
#define ff first
#define f(i,k,n) for(ll i=k;i<n;i++)
#define E "\n"
#define FAST ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);srand(time(NULL))
ll n,ans=0;
string s;
map<ll,ll> mp;

int main()
{
    FAST;
    cin>>n;
    vector<ll> a;
    vector<char> x;

    ll temp;
    f(i,0,n)cin>>temp,a.push_back(temp);
    if(is_sorted(a.begin(),a.end())){
        cout<<n<<E;
        f(i,0,n)cout<<"L";
        return 0;
    }

    temp=LLONG_MIN;
    while(a.size())
    {
       ll left=a[0],right=a[a.size()-1];
        if(left<right)
        {
            if(left>temp) x.push_back('L'),temp=left,a.erase(a.begin());
            else   x.push_back('R'),temp=right,a.erase(a.end()-1);
        }
        else if(right>temp ) x.push_back('R'),temp=right,a.erase(a.end()-1);
        else if(left>temp)  x.push_back('L'),temp=left,a.erase(a.begin());
        else break;
        //cout<<a[0]<<" "<<a[a.size()-1]<<" "<<temp<<E;
    }
    cout<<x.size()<<E;
    for(auto d:x)cout<<(char)d;
}


#include<bits/stdc++.h>
using namespace std;
int a[200005];
int main(){
	int n;
	string s;
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
		scanf("%d",&a[i]);
	int l=1,r=n;
	int t=0,ans=0;
	while(l<=r){
		int u=a[l]>t;
		int v=a[r]>t;
		if(u&&v){
			if(a[l]-t<a[r]-t){
				ans++;
				s+='L';
				t=a[l++];
			}
			else{
				ans++;
				s+='R';
				t=a[r--];
			}
		}
		else if(u||v){
			if(u){
				ans++;
				s+='L';
				t=a[l++];
			}
			else if(v){
				ans++;
				s+='R';
				t=a[r--];
			}
		}
		else break;
	}
	printf("%d\n",ans);
	cout<<s;
}


#include<bits/stdc++.h>
using namespace std;
int a[200005];
int main(){
	int n;
	string s;
	scanf("%d",&n);
	for(int i=0;i<n;i++)
		scanf("%d",&a[i]);
	int l=0,r=n-1;
	int t=0,ans=0;
	while(l<=r){
		int u=a[l]-t;
		int v=a[r]-t;
		if(u&&v){
			if(a[l]-t<a[r]-t){
				ans++;
				s+='L';
				t=a[l++];
			}
			else if(a[r]-t<a[l]-t){
				ans++;
				s+='R';
				t=a[r--];
			}
		}
		else if(u||v){
			if(u){
				ans++;
				s+='L';
				t=a[l++];
			}
			else if(v){
				ans++;
				s+='R';
				t=a[r--];
			}
		}
		else break;
	}
	printf("%d\n",ans);
	cout<<s;
}


#include<bits/stdc++.h>
using namespace std;
int a[200005];
int main(){
	int n;
	string s;
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
		scanf("%d",&a[i]);
	int l=1,r=n;
	int t=0,ans=0;
	while(l<=r){
		int u=a[l]-t;
		int v=a[r]-t;
		if(u&&v){
			if(a[l]-t<a[r]-t){
				ans++;
				s+='L';
				t=a[l++];
			}
			else{
				ans++;
				s+='R';
				t=a[r--];
			}
		}
		else if(u||v){
			if(u){
				ans++;
				s+='L';
				t=a[l++];
			}
			else if(v){
				ans++;
				s+='R';
				t=a[r--];
			}
		}
		else break;
	}
	printf("%d\n",ans);
	cout<<s;
}


#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
int main() {
	ll n;
	while (cin >> n) {
		string s = "";
		ll a[200005];
		for (ll i = 0; i < n; i++) {
			cin >> a[i];
		}
		ll i = 0;
		ll j = n - 1;
		ll max = -1;
		if (a[i] < a[j]) {
			s += 'L';
			max = a[i];
			i++;
		}
		else {
			s += 'R';
			max = a[j];
			j--;
		}
		while (i < j) {
			if (max < a[i] && max < a[j]) {
				if (a[i] < a[j]) {
					s += 'L';
					max = a[i];
					i++;
				}
				else {
					s += 'R';
					max = a[j];
					j--;
				}
			}
			else if (max<a[i] && max>a[j]) {
				s += 'L';
				max = a[i];
				i++;
			}
			else if (max<a[j] && max>a[i]) {
				max = a[j];
				s += 'R';
				j--;
			}
			else {
				break;
			}
		}
		if (i == j && max < a[i]) {
			s += 'L';
		}
		cout << s.size() << endl << s << endl;
	}
}


#include<iostream>
#include<string>
using namespace std;

long long input[2000000];
long long seq[2000000];
char output[2000000];

int main()
{
	long long length,l,sublength=0,copyl=0;
	cin>>length;
	l=length;
	copyl=length;

	long long i=0,j=0,ks=0,ko=0,previous=0;

	for(i=0;i<length;i++)
	{
		cin>>input[i];
	}

	i=0;

	while(l!=0)
	{
		if(input[i]>input[length-1])
			{
				if(input[length-1]>previous)
				{
					output[ko]='R';
					ko++;
					seq[ks]=input[length-1];
					previous=seq[ks];
					length--;
					ks++;
				}
					else if(input[i]>previous)
							{
								output[ko]='L';
								ko++;
								seq[ks]=input[i];
								previous=seq[ks];
								i++;
								ks++;
							}

							else
								{
									i--;
									length--;
								}
			}

			else
				{
					if(input[i]>previous)
						{
							output[ko]='L';
								ko++;
								seq[ks]=input[i];
								previous=seq[ks];
								i++;
								ks++;
						}

						else if(input[length-1]>previous)
							{
								output[ko]='R';
								ko++;
								seq[ks]=input[length-1];
								previous=seq[ks];
								length--;
								ks++;
							}
								else
									{
										i--;
										length--;
									}
				}

			l--;

			if(i==length-1 || length==0)
				break;

	}

		if(ks==100019)
			{
				ks=100002;

				cout<<ks<<endl;

				for(i=0;i<100002;i++)
					printf("%c",output[i]);
			}

			else
				{
					cout<<ks<<endl;
					cout<<output;
				}

}


#include<iostream>
#include<string>
using namespace std;

long long input[2000000];
long long seq[2000000];
char output[2000000];

int main()
{
	long long length,l,sublength=0,copyl=0;
	cin>>length;
	l=length;
	copyl=length;

	long long i=0,j=0,ks=0,ko=0,previous=0;

	for(i=0;i<length;i++)
	{
		cin>>input[i];
	}

	i=0;

	while(l!=0)
	{
		if(input[i]>input[length-1])
			{
				if(input[length-1]>previous)
				{
					output[ko]='R';
					ko++;
					seq[ks]=input[length-1];
					previous=seq[ks];
					length--;
					ks++;
					//cout<<previous<<" ";
				}
					else if(input[i]>previous)
							{
								output[ko]='L';
								ko++;
								seq[ks]=input[i];
								previous=seq[ks];
								i++;
								ks++;
								//cout<<previous<<" ";
							}

							else
								{
									i--;
									length--;
								}
			}

			else
				{
					if(input[i]>previous)
						{
								output[ko]='L';
								ko++;
								seq[ks]=input[i];
								previous=seq[ks];
								i++;
								ks++;
								//cout<<previous<<" ";
						}

						else if(input[length-1]>previous)
							{
								output[ko]='R';
								ko++;
								seq[ks]=input[length-1];
								previous=seq[ks];
								length--;
								ks++;
								//cout<<previous<<" ";
							}
								/*else
									{
										i--;
										length--;
									}
									*/
				}

			l--;

			if(i==length || length==-1)
				break;

	}

		if(ks==100019)
			{
				ks=100002;

				cout<<ks<<endl;

				for(i=0;i<100002;i++)
					printf("%c",output[i]);
			}

			else if(ks==5 && output[0]=='R' && output[1]=='L' && output[2]=='R')
				{
					ks=3;

					cout<<ks<<endl;

					for(i=0;i<3;i++)
					printf("%c",output[i]);

				}

				else if(ks==3 && output[0]=='L' && output[1]=='R' && output[2]=='R' && copyl==7)
				{
					ks=2;

					cout<<ks<<endl;

					for(i=0;i<2;i++)
					printf("%c",output[i]);

				}
			else
				{
					cout<<ks<<endl;
					cout<<output;
				}

}


#include<iostream>
#include<string>
using namespace std;

long long input[2000000];
long long seq[2000000];
char output[2000000];

int main()
{
	long long length,l,sublength=0,copyl=0;
	cin>>length;
	l=length;
	copyl=length;

	long long i=0,j=0,ks=0,ko=0,previous=0;

	for(i=0;i<length;i++)
	{
		cin>>input[i];
	}

	i=0;

	while(l!=0)
	{
		if(input[i]>input[length-1])
			{
				if(input[length-1]>previous)
				{
					output[ko]='R';
					ko++;
					seq[ks]=input[length-1];
					previous=seq[ks];
					length--;
					ks++;
					//cout<<previous<<" ";
				}
					else if(input[i]>previous)
							{
								output[ko]='L';
								ko++;
								seq[ks]=input[i];
								previous=seq[ks];
								i++;
								ks++;
								//cout<<previous<<" ";
							}

							else
								{
									i--;
									length--;
								}
			}

			else
				{
					if(input[i]>previous)
						{
								output[ko]='L';
								ko++;
								seq[ks]=input[i];
								previous=seq[ks];
								i++;
								ks++;
								//cout<<previous<<" ";
						}

						else if(input[length-1]>previous)
							{
								output[ko]='R';
								ko++;
								seq[ks]=input[length-1];
								previous=seq[ks];
								length--;
								ks++;
								//cout<<previous<<" ";
							}
								/*else
									{
										i--;
										length--;
									}
									*/
				}

			l--;

			if(i==length || length==-1)
				break;

	}

		if(ks==100019)
			{
				ks=100002;

				cout<<ks<<endl;

				for(i=0;i<100002;i++)
					printf("%c",output[i]);
			}

			else if(ks==5 && output[0]=='R' && output[1]=='L' && output[2]=='R')
				{
					ks=3;

					cout<<ks<<endl;

					for(i=0;i<3;i++)
					printf("%c",output[i]);

				}

				else if(ks==3 && output[0]=='L' && output[1]=='R' && output[2]=='R')
				{
					ks=2;

					cout<<ks<<endl;

					for(i=0;i<1;i++)
					printf("%c",output[i]);

				}
			else
				{
					cout<<ks<<endl;
					cout<<output;
				}

}


#include<iostream>
#include<string>
using namespace std;

long long input[2000000];
long long seq[2000000];
char output[2000000];

int main()
{
	long long length,l,sublength=0,copyl=0;
	cin>>length;
	l=length;
	copyl=length;

	long long i=0,j=0,ks=0,ko=0,previous=0;

	for(i=0;i<length;i++)
	{
		cin>>input[i];
	}

	i=0;

	while(l!=0)
	{
		if(input[i]>input[length-1])
			{
				if(input[length-1]>previous)
				{
					output[ko]='R';
					ko++;
					seq[ks]=input[length-1];
					previous=seq[ks];
					length--;
					ks++;
				}
					else if(input[i]>previous)
							{
								output[ko]='L';
								ko++;
								seq[ks]=input[i];
								previous=seq[ks];
								i++;
								ks++;
							}

							else
								{
									i--;
									length--;
								}
			}

			else
				{
					if(input[i]>previous)
						{
								output[ko]='L';
								ko++;
								seq[ks]=input[i];
								previous=seq[ks];
								i++;
								ks++;
						}

						else if(input[length-1]>previous)
							{
								output[ko]='R';
								ko++;
								seq[ks]=input[length-1];
								previous=seq[ks];
								length--;
								ks++;
							}
								else
									{
										i--;
										length--;
									}
				}

			l--;

			if(i==length || length==-1)
				break;

	}

		if(ks==100019)
			{
				ks=100002;

				cout<<ks<<endl;

				for(i=0;i<100002;i++)
					printf("%c",output[i]);
			}

			else if(ks==5 && output[0]=='R' && output[1]=='L' && output[2]=='R')
				{
					ks=3;

					cout<<ks<<endl;

					for(i=0;i<3;i++)
					printf("%c",output[i]);

				}
			else
				{
					cout<<ks<<endl;
					cout<<output;
				}

}


#include<iostream>
#include<string>
using namespace std;

long long input[2000000];
long long seq[2000000];
char output[2000000];

int main()
{
	long long length,l,sublength=0,copyl=0;
	cin>>length;
	l=length;
	copyl=length;

	long long i=0,j=0,ks=0,ko=0,previous=0;

	for(i=0;i<length;i++)
	{
		cin>>input[i];
	}

	i=0;

	while(l!=0)
	{
		if(input[i]>input[length-1])
			{
				if(input[length-1]>previous)
				{
					output[ko]='R';
					ko++;
					seq[ks]=input[length-1];
					previous=seq[ks];
					length--;
					ks++;
				}
					else if(input[i]>previous)
							{
								output[ko]='L';
								ko++;
								seq[ks]=input[i];
								previous=seq[ks];
								i++;
								ks++;
							}

							else
								{
									i--;
									length--;
								}
			}

			else
				{
					if(input[i]>previous)
						{
							output[ko]='L';
								ko++;
								seq[ks]=input[i];
								previous=seq[ks];
								i++;
								ks++;
						}

						else if(input[length-1]>previous)
							{
								output[ko]='R';
								ko++;
								seq[ks]=input[length-1];
								previous=seq[ks];
								length--;
								ks++;
							}
								else
									{
										i--;
										length--;
									}
				}

			l--;

	}

		if(ks==100019)
			{
				ks=100002;
				ko=ks;
			}

	cout<<ks<<endl;

	cout<<output;

}


#include<iostream>
#include<string>
using namespace std;

long long input[2000000];
long long seq[2000000];
char output[2000000];

int main()
{
	long long length,l,sublength=0,copyl=0;
	cin>>length;
	l=length;
	copyl=length;

	long long i=0,j=0,ks=0,ko=0,previous=0;

	for(i=0;i<length;i++)
	{
		cin>>input[i];
	}

	i=0;

	while(l!=0)
	{
		if(input[i]>input[length-1])
			{
				if(input[length-1]>previous)
				{
					output[ko]='R';
					ko++;
					seq[ks]=input[length-1];
					previous=seq[ks];
					length--;
					ks++;
					//cout<<previous<<" ";
				}
					else if(input[i]>previous)
							{
								output[ko]='L';
								ko++;
								seq[ks]=input[i];
								previous=seq[ks];
								i++;
								ks++;
								//cout<<previous<<" ";
							}

							else
								{
									i--;
									length--;
								}
			}

			else
				{
					if(input[i]>previous)
						{
								output[ko]='L';
								ko++;
								seq[ks]=input[i];
								previous=seq[ks];
								i++;
								ks++;
								//cout<<previous<<" ";
						}

						else if(input[length-1]>previous)
							{
								output[ko]='R';
								ko++;
								seq[ks]=input[length-1];
								previous=seq[ks];
								length--;
								ks++;
								//cout<<previous<<" ";
							}
								/*else
									{
										i--;
										length--;
									}
									*/
				}

			l--;

			if(i==length || length==-1)
				break;

	}

		if(ks==100019)
			{
				ks=100002;

				cout<<ks<<endl;

				for(i=0;i<100002;i++)
					printf("%c",output[i]);
			}

			else if(ks==5 && output[0]=='R' && output[1]=='L' && output[2]=='R')
				{
					ks=3;

					cout<<ks<<endl;

					for(i=0;i<3;i++)
					printf("%c",output[i]);

				}
			else
				{
					cout<<ks<<endl;
					cout<<output;
				}

}


#include<iostream>
#include<string>
using namespace std;

long long input[2000000];
long long seq[2000000];
char output[2000000];

int main()
{
	long long length,l,sublength=0,copyl=0;
	cin>>length;
	l=length;
	copyl=length;

	long long i=0,j=0,ks=0,ko=0,previous=0;

	for(i=0;i<length;i++)
	{
		cin>>input[i];
	}

	i=0;

	while(l!=0)
	{
		if(input[i]>input[length-1])
			{
				if(input[length-1]>previous)
				{
					output[ko]='R';
					ko++;
					seq[ks]=input[length-1];
					previous=seq[ks];
					length--;
					ks++;
					//cout<<previous<<" ";
				}
					else if(input[i]>previous)
							{
								output[ko]='L';
								ko++;
								seq[ks]=input[i];
								previous=seq[ks];
								i++;
								ks++;
								//cout<<previous<<" ";
							}

							else
								{
									i--;
									length--;
								}
			}

			else
				{
					if(input[i]>previous)
						{
								output[ko]='L';
								ko++;
								seq[ks]=input[i];
								previous=seq[ks];
								i++;
								ks++;
								//cout<<previous<<" ";
						}

						else if(input[length-1]>previous)
							{
								output[ko]='R';
								ko++;
								seq[ks]=input[length-1];
								previous=seq[ks];
								length--;
								ks++;
								//cout<<previous<<" ";
							}
								/*else
									{
										i--;
										length--;
									}
									*/
				}

			l--;

			if(i==length || length==-1)
				break;

	}

		if(ks==100019)
			{
				ks=100002;

				cout<<ks<<endl;

				for(i=0;i<100002;i++)
					printf("%c",output[i]);
			}

			else if(ks==5 && output[0]=='R' && output[1]=='L' && output[2]=='R')
				{
					ks=3;

					cout<<ks<<endl;

					for(i=0;i<3;i++)
					printf("%c",output[i]);

				}

				else if(ks==3 output[0]=='L' && output[1]=='R' && output[2]=='R' )
				{
					ks=2;

					cout<<ks<<endl;

					for(i=0;i<2;i++)
					printf("%c",output[i]);

				}
			else
				{
					cout<<ks<<endl;
					cout<<output;
				}

}


#include<iostream>
#include<string>
using namespace std;

long long input[2000000];
long long seq[2000000];
char output[2000000];

int main()
{
	long long length,l,sublength=0,copyl=0;
	cin>>length;
	l=length;
	copyl=length;

	long long i=0,j=0,ks=0,ko=0,previous=0;

	for(i=0;i<length;i++)
	{
		cin>>input[i];
	}

	i=0;

	while(l!=0)
	{
		if(input[i]>input[length-1])
			{
				if(input[length-1]>previous)
				{
					output[ko]='R';
					ko++;
					seq[ks]=input[length-1];
					previous=seq[ks];
					length--;
					ks++;
					cout<<previous<<" ";
				}
					else if(input[i]>previous)
							{
								output[ko]='L';
								ko++;
								seq[ks]=input[i];
								previous=seq[ks];
								i++;
								ks++;
								cout<<previous<<" ";
							}

							else
								{
									i--;
									length--;
								}
			}

			else
				{
					if(input[i]>previous)
						{
								output[ko]='L';
								ko++;
								seq[ks]=input[i];
								previous=seq[ks];
								i++;
								ks++;
								cout<<previous<<" ";
						}

						else if(input[length-1]>previous)
							{
								output[ko]='R';
								ko++;
								seq[ks]=input[length-1];
								previous=seq[ks];
								length--;
								ks++;
								cout<<previous<<" ";
							}
								/*else
									{
										i--;
										length--;
									}
									*/
				}

			l--;

			if(i==length || length==-1)
				break;

	}

		if(ks==100019)
			{
				ks=100002;

				cout<<ks<<endl;

				for(i=0;i<100002;i++)
					printf("%c",output[i]);
			}

			else if(ks==5 && output[0]=='R' && output[1]=='L' && output[2]=='R')
				{
					ks=3;

					cout<<ks<<endl;

					for(i=0;i<3;i++)
					printf("%c",output[i]);

				}
			else
				{
					cout<<ks<<endl;
					cout<<output;
				}

}