# !DO NOT READ!... this solution is way too easy

#1
``````#include<bits/stdc++.h>
#define rep(i,a,b)       for(long long int i=a;i<b;i++)
#define input(a,n)       for(long long int i=0;i<n;i++)cin>>a[i];
#define set(a,n, x)      for(long long int i=0;i<n;i++)a[i]=x;
#define dikhao(a,n)      for(long long int i=0;i<n;i++)cout<<a[i]<<" ";cout<<endl;
#define ll              long long int
#define mp              make_pair
#define pb              push_back
#define all(a) a.begin(),a.end()
#define mx(a) *max_element(all(a))
#define mn(a) *min_element(all(a))
using namespace std;
int maxsize = 200001;
double power(float x, int y)
{
float temp;
if(y == 0)
return 1;
temp = power(x, y / 2);
if (y % 2 == 0)
return temp * temp;
else
{
if(y > 0)
return x * temp * temp;
else
return (temp * temp) / x;
}
}

bool valid(int i,int j,int A,int B){
if(i>=1 && i<=A && j>=1 && j<=B)return true;
return false;
}

int mins[501][501];
int solve(int A, int B, int C, int D, int E, int F) {
for(int i= 0; i<=A; i++){
for(int j=0; j<=B; j++){
mins[i][j] = INT_MAX;
}
}
mins[C][D] = 0;
int movesx[] = {1,2,-1,2,-1,-2,1,-2};
int movesy[] = {2,1,2,-1,-2,-1,-2,1};
queue<pair<int, int> > q;
q.push(make_pair(C, D));
pair<int, int> cur ;
while(!q.empty()){
cur = q.front();
q.pop();
int x, y;
for(int i =0; i<8; i++){
x = cur.first+ movesx[i];
y = cur.second+ movesy[i];
if(valid(x, y, A, B) && mins[x][y] == INT_MAX){
// cout<<x<<' '<<y<<endl;
mins[x][y] = min( mins[x][y], 1+ mins[cur.first][cur.second]);
q.push(make_pair(x, y));
}
}
}
// for(int i= 1    ; i<=A; i++){
//     for(int j=1; j<=B; j++){
//         cout<<mins[i][j]<<" ";
//     }
//     cout<<endl;
// }
return mins[E][F];
}

int main(){
cout<<solve(4,4,1,1,4,4)<<endl;
return 0;
}``````