Problem:
Score : 1000 points

Problem Statement

Ringo has a string S.

He can perform the following N kinds of operations any number of times in any order.

Operation i: For each of the characters from the L_i-th through the R_i-th characters in S, replace it with its succeeding letter in the English alphabet. (That is, replace a with b, replace b with c and so on.) For z, we assume that its succeeding letter is a.

Ringo loves palindromes and wants to turn S into a palindrome.
Determine whether this is possible.

Constraints

1 \leq |S| \leq 10^5

S consists of lowercase English letters.

1 \leq N \leq 10^5

1 \leq L_i \leq R_i \leq |S|

Input

Input is given from Standard Input in the following format:

S
N
L_1 R_1
L_2 R_2
:
L_N R_N

Output

Print YES if it is possible to turn S into a palindrome; print NO if it is impossible.

Sample Input 1

bixzja
2
2 3
3 6

Sample Output 1

YES

For example, if we perform Operation 1, 2 and 1 in this order, S changes as bixzja → bjyzja → bjzakb → bkaakb and becomes a palindrome.

Sample Input 2

abc
1
2 2

Sample Output 2

NO

Sample Input 3

cassert
4
1 2
3 4
1 1
2 2

Sample Output 3

YES

Solution in C++ (GCC 9.2.1) (judge verdict: Accepted)

#include <bits/stdc++.h>
#pragma GCC optimize ("O2,unroll-loops")
//#pragma GCC optimize("no-stack-protector,fast-math")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<pii, int> piii;
typedef pair<ll, ll> pll;
#define debug(x) cerr<<#x<<'='<<(x)<<endl;
#define debugp(x) cerr<<#x<<"= {"<<(x.first)<<", "<<(x.second)<<"}"<<endl;
#define debug2(x, y) cerr<<"{"<<#x<<", "<<#y<<"} = {"<<(x)<<", "<<(y)<<"}"<<endl;
#define debugv(v) {cerr<<#v<<" : ";for (auto x:v) cerr<<x<<' ';cerr<<endl;}
#define all(x) x.begin(), x.end()
#define pb push_back
#define kill(x) return cout<<x<<'\n', 0;

const int inf=1000000010;
const ll INF=10000000000000010LL;
const int mod=1000000007;
const int MAXN=100010, LOG=20;

int n, m, k, u, v, x, y, t, a, b, ans;
int A[MAXN], sum[MAXN];
bool mark[MAXN];
string S, T;
vector<int> G[MAXN];

void add(int l, int r){
	G[l].pb(r+1);
	G[r+1].pb(l);
}

int dfs(int node){
	mark[node]=1;
	for (int v:G[node]) if (!mark[v]) sum[node]+=dfs(v);
//	debug2(node, sum[node])
	return sum[node];
}

int main(){
	ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	cin>>S>>m;
	int len=S.size();
	n=len/2;
	for (int i=0; i<n; i++) T+=S.back(), S.pop_back();
	if (len&1) S.pop_back();
	debug(S)
	debug(T)
	
	for (int i=1; i<=n; i++) A[i]=S[n-i]-T[n-i];
	for (int i=1; i<=n+1; i++) sum[i]=A[i]-A[i-1];
	while (m--){
		cin>>x>>y;
		if (len%2){
			if (x==n+1 && y==n+1) continue ;
			if (x==n+1) x++;
			if (y==n+1) y--;
			if (x>n) x--;
			if (y>n) y--;
		}
		if (x<=n && y<=n) x=n-x+1, y=n-y+1, swap(x, y);
		else if (x>n && y>n) x-=n, y-=n;
		else{
			x=n-x+1;
			y-=n;
			if (x>y) swap(x, y);
			x++;
		}
		add(x, y);
	}
	debug(len)
	for (int i=1; i<=n+1; i++) if (!mark[i] && dfs(i)%26) kill("NO")
	kill("YES")
	
	return 0;
}