| # | Time | Username | Problem | Language | Result | Execution time | Memory | 
|---|---|---|---|---|---|---|---|
| 1169851 | monkey133 | Circle Passing (EGOI24_circlepassing) | C++20 | 0 ms | 0 KiB | 
#include <bits/stdc++.h>
using namespace std;
#define int long long
int n, m, q;
int sp(int a,  int b)
{
  return min(abs(b-a), 2*n - abs(a-b));
}
int32_t main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	std::cin >> n >> m >> q;
	std::vector <int> arr;
	for(int i=0; i<m; i++){
		int x;
		std::cin >> x;
		arr.push_back(x);
		arr.push_back(x+n);
	}
	sort(arr.begin(), arr.end());
	
	for(int i=0; i<q; i++){
		int a, b;
		std::cin >> a >> b;
		int ans= sp(a, b);
		
		//else if theres like smth between both of these that can +n then try it ig
		auto mid=lower_bound(arr.begin(), arr.end(), a);//check if <b ltr
		ll tele = (mid==arr.end()) ? arr[0] : *mid;
	  ans=min(ans, sp(a, tele) + sp((tele + n)%(2*n), b) + 1);
		auto aft=upper_bound(arr.begin(), arr.end(), a);
		if (aft==arr.begin()) aft = prev(arr.end());
		else aft--;
		tele=*aft;
		ans=min(ans, sp(a, tele) + sp((tele +n)%(2*n), b) + 1);
		std::cout << ans << "\n";
	}
}
