#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
#define FOR(i, n) for(int (i)=0; (i)<(n); (i)++)
#define FOR1(i, n) for(int (i)=1; (i)<=(n); (i)++)
#define FORI(i, n) for(int (i)=n-1; (i)>=0; (i)--)
template<class T, class U> void umin(T& x, const U& y){ x = min(x, (T)y);}
template<class T, class U> void umax(T& x, const U& y){ x = max(x, (T)y);}
template<class T, class U> void init(vector<T> &v, U x, size_t n) { v=vector<T>(n, (T)x); }
template<class T, class U, typename... W> void init(vector<T> &v, U x, size_t n, W... m) { v=vector<T>(n);  for(auto& a : v) init(a, x, m...); }
const ll MOD = 1e9+7;
vector<vector<char>> v(2, vector<char>(2));
vector<int> H(5000, -1);
int solve(int n, int a, int b){
    if (n <= 1) return 1;
    int key = n * 4 + a * 2 + b;
    if (H[key]!=-1) return H[key];

    int ret = 0;
    int c = v[a][b] - 'A';
    for(int i=0; i<=n-1; i++){
        ret += (ll) solve(i, a, c) * solve(n-1-i, c, b) % MOD;
        ret -= MOD * (ret >= MOD);
    }
    return H[key] = ret;
}

int mp(char c){
    if (c == 'A') return 0;
    return 1;
}

set<string> S;
void bf(string s, int n){
    if (n == 0) {
        S.insert(s);
        return;
    }

    FOR(i, s.length()-1){
        string s2 = s.substr(0, i+1) + v[mp(s[i])][mp(s[i+1])] + s.substr(i+1);
        bf(s2, n-1);
    }
}

int main(int argc, char** argv) {
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cout << setprecision(15);
    if (argc == 2 && atoi(argv[1]) == 123456789) freopen("d:\\code\\cpp\\contests\\stdin", "r", stdin);

    int n;
    cin >> n;
    FOR(i, 2) FOR(j, 2) cin >> v[i][j];
    int sol = 1;
    if (n>=3)
    {
        if (v[0][1] == 'B') {
            if (v[1][1] == 'B')
                sol = 1;
            else {
                if (v[1][0] == 'A') {
                    FOR(i, n - 3) {
                        sol = 2 * sol % MOD;
                    }
                } else {
                    int x = 1, y = 1, z;
                    FOR(i, n - 3) {
                        z = x + y;
                        z %= MOD;
                        x = y;
                        y = z;
                    }
                    sol = z;
                }
            }
        } else {
            if (v[0][0] == 'A')
                sol = 1;
            else {
                if (v[1][0] == 'B') {
                    FOR(i, n - 3) {
                        sol = 2 * sol % MOD;
                    }
                } else {
                    int x = 1, y = 1, z;
                    FOR(i, n - 3) {
                        z = x + y;
                        z %= MOD;
                        x = y;
                        y = z;
                    }
                    sol = z;
                }
            }
        }
    }
    cout << sol << endl;
//    bf("AB", n-2);
//    cout << S.size() << endl;

    if (argc == 2 && atoi(argv[1]) == 123456789) cout << clock()*1.0/CLOCKS_PER_SEC << " sec\n";
    return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <cmath>
#include <set>
#include <map>
#define ll long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define P pair<int, int>
using namespace std;

int main(){
  ll r1, c1, r2, c2; cin >> r1 >> c1 >> r2 >> c2;
  ll ans = 1e9;
  for(int i = -3; i <= 3; i++){
    for(int j = -3; j <= 3; j++){
      if(abs(i) + abs(j) > 3) continue;
      ll x = r2 + i, y = c2 + j;
      if((abs(r1 - x) + abs(c1 - y)) % 2 != 0) continue;
      ll cnt;
      if(i == 0 && j == 0) cnt = 0;
      else cnt = 1;
      if(x == r1 && y == c1){

      }
      else if(abs(r1 - x) + abs(c1 - y) <= 3){
        cnt++;
      }
      else if(r1 + c1 == x + y || r1 - c1 == x - y) cnt++;
      else cnt += 2;

      ans = min(ans, cnt);
    }
  }
  cout << ans << endl;
  return 0;
}
