#include "permgame.h"
#include <vector>
#include <utility>
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define F(i,L,R) for (int i = L; i < R; i++)
#define FE(i,L,R) for (int i = L; i <= R; i++)
#define FF(i,L,R) for (int i = L; i > R; i--)
#define FFE(i,L,R) for (int i = L; i >= R; i--)
#define ms(a,x) memset(a,x,sizeof(a))
#define ALL(c) (c).begin(),(c).end()
#define SZ(a) sizeof(a)
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> ii;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<char> vc;
typedef vector<vc> vvc;
int Alice(int m, int e, std::vector<int> u, std::vector<int> v, int n, std::vector<int> p) {
vi t(m);
vb vis(n, 0);
int cnt = 0;
for(int i = 0; i < n; i++){
if(p[i] == i) cnt++;
}
for(int i = 0; i < n; i++){
if(p[i] != i && !vis[i]){
int cur = i, cycle = 0;
do{
vis[cur] = 1;
cur = p[cur];
cycle++;
}while(cur != i);
t[0] = i;
while(cycle % 2){
t[1] = p[t[0]], t[2] = p[t[1]];
int j = Bob(t);
if(cycle == 3){
cnt++;
break;
}
if(abs(u[j] - v[j]) == 1){
cnt++;
cycle--;
}else{
swap(p[t[0]], p[t[2]]);
cycle -= 2;
}
}
}
}
return cnt;
}