#include <bits/stdc++.h>

using namespace std;

typedef long long int ll;

void testcase(){
	int l, r;
	cin>>l>>r;

	int flag = 0;
	ll count = 0;
	ll inc = 2;
	if(r-2*l+1>=1){
		ll times = r-2*l+1;
		count = (times*(times+1))/2;
	}
	cout<<count<<endl;
}

int main(){
	ios_base::sync_with_stdio();
	cin.tie(NULL);

	int test;
	cin>>test;
	while(test-->0){
		testcase();
	}
}

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using Pll = pair<long long,long long>;
using vec = vector<int>;
using vecll = vector<long long>;
using mat = vector<vector<int>>;
using matll = vector<vector<long long>>;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define endl "\n"
#define _GLIBCXX_DEBUG

constexpr int MOD = 1000000007;
const int INF = 1 << 30;

template<typename T> T gcd(T a, T b) { return b ? gcd(b, a%b) : a; }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }

int main(){
 int n;

  int  max1=-1,max2=-1;

  cin >> n;

  vector<vector<int>> a,b;

  rep(i,n){
    int x1,y1;
    cin>>x1>>y1;
    a.push_back({x1,y1,i+1});
    b.push_back({y1,x1,i+1});
  }
  sort(all(a));
  sort(all(b));

  set<int> num;
	vec x,y;
    rep(i,2){
      if(!num.count(a[i][2])){
        x.push_back(a[i][0]);
        y.push_back(a[i][1]);
        num.insert(a[i][2]);
      }
      if(!num.count(a[n-1-i][2])){
        x.push_back(a[n-1-i][0]);
        y.push_back(a[n-1-i][1]);
        num.insert(a[n-1-i][2]);
      }
         }
             rep(i,2){
      if(!num.count(b[i][2])){
        y.push_back(b[i][0]);
        x.push_back(b[i][1]);
        num.insert(b[i][2]);
      }
      if(!num.count(b[n-1-i][2])){
        y.push_back(b[n-1-i][0]);
        x.push_back(b[n-1-i][1]);
        num.insert(b[n-1-i][2]);
      }
         }
	n = x.size();
  rep(i,n-1){
      for ( int j = i+1; j<n;j++){
        int dis = max(abs(x[j]-x[i]),abs(y[j]-y[i]));
      	if(dis > max1 ){
          max2 =max1;
          max1 = dis;
        }
        else if(dis > max2) max2 = dis;

      }
    }
  cout<<max2<<endl;

}


// Problem: A - Two Sequences 2
// Contest: AtCoder - KEYENCE Programming Contest 2021
// URL: https://atcoder.jp/contests/keyence2021/tasks/keyence2021_a
// Memory Limit: 1024 MB
// Time Limit: 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include <bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define int long long
#define F(i, n) for (int i = 0; i < n; i++)
#define all(x)(x).begin(), (x).end()
#define show(A) for (auto i: A) cout << i << " "; cout << '\n';
#define show_(A, n) F(i, n) { show(A[i]) }

using namespace std;
using ld = long double;
using vi = vector < int > ;
using mi = map < int, int > ;
using pi = pair < int, int > ;

const int N = 100005;
const int MOD = 1e9 + 7;
const int inf = 1e18 + 1;
/***************************code begins here*****************************/

void solve() {
    int n, ans = 0;
    cin >> n;
    vi a(n);
    F(i, n) cin >> a[i];

    show(a);
    cout << ans << '\n';
}
int32_t main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n; cin>>n;
    vi x(n),y(n);
    F(i,n) cin>>x[i];
    F(i,n) cin>>y[i];
    set<int> a,b; int ans=-1;
    for(int i=0;i<n;i++){
    	a.insert(-x[i]);
    	ans = max(ans ,(-y[i]) * (*a.begin()) );
    	cout<< ans  <<'\n' ;
    }

    return 0;
}

#include <bits/stdc++.h>
#include <vector>
#include <iostream>
#include<algorithm>
#include<string>
#include <map>
#include <queue>
#include <stack>
#include<set>

//#define DIV 1000000007
#define TE 2e5
using namespace std;
using ll = long long;
using ldb = long double;

int main() {
    int N; cin >> N;
    vector<ll> a(N), b(N);
    for (int i = 0; i < N; i++) {
        cin >> a[i];
    }

    for (int i = 0; i < N; i++) {
        cin >> b[i];
    }

    ll ma = a[0], mb = b[0];
    vector<ll> c(N);
    c[0] = a[0] * b[0];
    for (int i = 1; i < N; i++) {
        ma = max(ma, a[i]);
        //c[i] = max(c[i - 1], max(ma * b[i], mb * a[i]));
        c[i] = max(c[i - 1], ma * b[i]);
        mb = max(mb, b[i]);
    }

    for (int i = 0; i < N; i++) {
        cout << c[i] << endl;
    }

}


#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,s,n) for (int i = (s); i < (n); ++i)
#define rrep(i,n,g) for (int i = (n)-1; i >= (g); --i)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define len(x) (int)(x).size()
#define dup(x,y) (((x)+(y)-1)/(y))
#define pb push_back
#define eb emplace_back
#define Field(T) vector<vector<T>>
#define pq(T) priority_queue<T,vector<T>,greater<T>>
using namespace std;
using ll = long long;
using P = pair<int,int>;

ll gcd(ll a, ll b) {
  if (a%b == 0) {
    return (b);
  } else {
    return(gcd(b, a%b));
  }
}

int main() {
  int n;
  cin >> n;
  unordered_map<int, int> m;
  int x = 1000000000;
  rep(i,0,n) {
    int a;
    cin >> a;
    x = min(x, a);
    for (int i = 1; i*i <= a; ++i) {
      if (a % i != 0) continue;
      if (!m.count(i)) {
        m[i] = a;
      } else {
        m[i] = gcd(m[i], a);
      }
      if (a/i == i) continue;
      if (!m.count(a/i)) {
        m[a/i] = a;
      } else {
        m[a/i] = gcd(m[a/i], a);
      }
    }
  }
  int ans = 0;
  for (auto itr = m.begin(); itr != m.end(); ++itr) {
    if (itr->fi == itr->se && itr->fi <= x) {
      ++ans;
    }
  }
  cout << ans << endl;
  return 0;
}

#include<bits/stdc++.h>
using namespace std;
using lli = long long int;
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
const int MOD = 1000000007;
const int MOD1 = 998244353;
const int maxn = 100010;
const int lim = (int)1e9;
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int n = 0;
	cin >> n;
	vector<int> a(n);
	for (auto &i : a)
		cin >> i;
	int mi = *min_element(a.begin(), a.end());
	unordered_map<int, int> mp;
	for (auto &i : a)
	{
		for (int j = 1; j * j <= i && j < mi; ++j)
		{
			if (i % j == 0)
			{
				mp[j] = __gcd(i, mp[j]);
				if (i / j < mi)
					mp[i / j] = __gcd(i, mp[i / j]);
			}
		}
	}
	int res = 1;
	for (auto &i : mp)
		if (i.fi == i.se)
			++res;
	cout << res;
}


#include <bits/stdc++.h>

using i32 = std::int32_t;
using u32 = std::uint32_t;
using i64 = std::int64_t;
using u64 = std::uint64_t;
using i128 = __int128_t;
using u128 = __uint128_t;
using isize = std::ptrdiff_t;
using usize = std::size_t;

class rep {
    struct Iter {
        usize itr;
        constexpr Iter(const usize pos) noexcept: itr(pos) { }
        constexpr void operator ++ () noexcept { ++itr; }
        constexpr bool operator != (const Iter& other) const noexcept { return itr != other.itr; }
        constexpr usize operator * () const noexcept { return itr; }
    };
    const Iter first, last;
public:
    explicit constexpr rep(const usize first, const usize last) noexcept: first(first), last(std::max(first, last)) { }
    constexpr Iter begin() const noexcept { return first; }
    constexpr Iter end() const noexcept { return last; }
};

template <class T>
using Vec = std::vector<T>;

void B_main() {
    usize N;
    std::cin >> N;
    Vec<Vec<i32>> C(N, Vec<i32>(N));
    for (auto &v: C) {
        for (auto &x: v) {
            std::cin >> x;
        }
    }
    Vec<i32> Adif(N), Bdif(N);
    for (auto i: rep(1, N)) {
        Adif[i] = C[i][0] - C[0][0];
        for (auto j: rep(1, N)) {
            if (C[i][j] - C[0][j] != Adif[i]) {
                std::cout << "No\n";
                return;
            }
        }
    }
    for (auto j: rep(1, N)) {
        Bdif[j] = C[0][j] - C[0][0];
        for (auto i: rep(1, N)) {
            if (C[i][j] - C[i][0] != Bdif[j]) {
                std::cout << "No\n";
                return;
            }
        }
    }
    const auto Amin = -*std::min_element(Adif.begin(), Adif.end());
    const auto Bmin = -*std::min_element(Bdif.begin(), Bdif.end());
    if (C[0][0] < Amin + Bmin) {
        std::cout << "No\n";
        return;
    }
    Vec<i32> A(N), B(N);
    A[0] = Amin;
    B[0] = C[0][0] - Amin;
    for (auto i: rep(1, N)) {
        A[i] = A[0] + Adif[i];
        B[i] = B[0] + Bdif[i];
    }
    std::cout << "Yes\n";
    for (auto i: rep(0, N)) {
        std::cout << A[i] << " \n"[i + 1 == N];
    }
    for (auto i: rep(0, N)) {
        std::cout << B[i] << " \n"[i + 1 == N];
    }
    return;
}

int main() {
    std::ios_base::sync_with_stdio(false);
    std::cin.tie(nullptr);
    B_main();
    return 0;
}

#include<iostream>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<bitset>
#include<cmath>
#include<ctime>
#include<queue>
#include<map>
#include<set>

#define int long long
#define lowbit(x) (x&(-x))
#define mp(x,y) make_pair(x,y)
#define lc (x<<1)
#define rc (x<<1|1)
#define fi first
#define se second
#define mid ((l+r)>>1)
#define fan(x) (((x-1)^1)+1)
#define max Max
#define min Min
#define abs Abs

using namespace std;

inline int read()
{
	int ans=0,f=1;
	char c=getchar();
	while(c>'9'||c<'0'){if(c=='-')f=-1;c=getchar();}
	while(c>='0'&&c<='9'){ans=(ans<<1)+(ans<<3)+c-'0';c=getchar();}
	return ans*f;
}

inline void write(int x)
{
	if(x<0) putchar('-'),x=-x;
	if(x/10) write(x/10);
	putchar((char)(x%10)+'0');
}

template<typename T>inline T Abs(T a){return a>0?a:-a;};
template<typename T,typename TT>inline T Min(T a,TT b){return a>b?b:a;}
template<typename T,typename TT> inline T Max(T a,TT b){return a>b?a:b;}

const int N=505;
int n,a[N],b[N],c[N][N],fl=1;

signed main()
{
	n=read();
	for(int i=1;i<=n;++i)
		for(int j=1;j<=n;++j)
			c[i][j]=read();
	for(int i=2;i<=n;++i)
		for(int j=2;j<=n;++j)
			if(c[i][j]-c[i][j-1]!=c[i-1][j]-c[i-1][j-1])
				fl=0;
	for(int j=2;j<=n;++j)
		for(int i=2;i<=n;++i)
			if(c[i][j]-c[i-1][j]!=c[i][j-1]-c[i-1][j-1])
				fl=0;
	if(!fl)
	{
		printf("No\n");
		return 0;
	}
	int mn=1e18;
	for(int j=1;j<=n;++j)
		mn=min(mn,c[1][j]);
	for(int j=1;j<=n;++j)
		b[j]=c[1][j]-mn;
	for(int i=1;i<=n;++i)
		a[i]=c[i][1]-b[1];
	for(int i=1;i<=n;++i)
	{
		if(a[i]<0) fl=0;
		if(b[i]<0) fl=0;
	}
	if(!fl)
	{
		printf("No\n");
		return 0;
	}
	printf("Yes\n");
	for(int i=1;i<=n;++i)
		printf("%lld ",a[i]);
	printf("\n");
	for(int i=1;i<=n;++i)
		printf("%lld ",b[i]);
	return 0;
}


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

// mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());

#define MAXN 200007

int n , k ;
vector < int > v[ MAXN ] ;

int depth[ MAXN ] ;
int lst[ MAXN ] ;
bool used[ MAXN ] ;
int root ;
vector < int > ord ;

void dfs ( int vertex , int prv ) {
    for ( auto x : v[ vertex ] ) {
        if ( x == prv ) { continue ; }
        depth[ x ] = depth[ vertex ] + 1 ;
        lst[ x ] = vertex ;
        dfs ( x , vertex ) ;
    }
}

void mark ( int vertex , int prv , int lft ) {
    used[ vertex ] = true ;
    if ( lft == 0 ) { return ; }
    for ( auto x : v[ vertex ] ) {
        if ( x == prv ) { continue ; }
        mark ( x , vertex , lft - 1 ) ;
    }
}

bool f ( int sr ) {
    for ( int i = 1 ; i <= n ; ++ i ) {
        used[ i ] = false ;
    }
    int cnt = 0 ;
    for ( auto x : ord ) {
        if ( used[ x ] == true ) { continue ; }
        ++ cnt ;
        if ( cnt > k ) { return false ; }
        int h = x ;
        for ( int i = 0 ; i < sr ; ++ i ) { h = lst[ h ] ; }
        mark ( h , -1 , sr ) ;
    }
    return true ;
}

void input ( ) {
    scanf ( "%d%d" , &n , &k ) ;
    for ( int i = 1 ; i < n ; ++ i ) {
        int x , y ; scanf ( "%d%d" , &x , &y ) ;
        v[ x ].push_back ( y ) ;
        v[ y ].push_back ( x ) ;
    }
}

vector < pair < int , int > > srt ;

void solve ( ) {
    dfs ( 1 , -1 ) ;
    int mx = 0 ;
    for ( int i = 1 ; i <= n ; ++ i ) {
        if ( mx < depth[ i ] ) {
            root = i ;
            mx = depth[ i ] ;
        }
    }
    depth[ root ] = 0 ;
    lst[ root ] = root ;
    dfs ( root , -1 ) ;
    for ( int i = 1 ; i <= n ; ++ i ) {
        srt.push_back ( { -depth[ i ] , i } ) ;
    }
    sort ( srt.begin ( ) , srt.end ( ) ) ;
    for ( auto [ val , wh ] : srt ) {
        ord.push_back ( wh ) ;
    }
    int l , r , mid ;
    l = 0 ;
    r = n ;
    while ( r - l > 3 ) {
        mid = ( l + r ) / 2 ;
        if ( f ( mid ) == true ) { r = mid ; }
        else { l = mid ; }
    }
    while ( f ( l ) == false ) { ++ l ; }
    printf ( "%d\n" , l ) ;
}

int main ( ) {
    ios_base :: sync_with_stdio ( false ) ;
    cin.tie ( NULL ) ;
    int t ;
    // cin >> t ;
    t = 1 ;
    // scanf ( "%d" , &t ) ;
    while ( t -- ) {
        input ( ) ;
        solve ( ) ;
    }
    return 0 ;
}

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

#define fastio                  ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define input_output            freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);

template <typename Arg1>
void prn(Arg1&& arg1) { cout<<arg1<<"\n";}
template <typename Arg1, typename... Args>
void prn(Arg1&& arg1, Args&&... args) { cout<<arg1<<" "; prn(args...); }

template <typename Arg1>
void prs(Arg1&& arg1) { cout<<arg1<<" ";}
template <typename Arg1, typename... Args>
void prs(Arg1&& arg1, Args&&... args) { cout<<arg1<<" "; prs(args...); }

template <typename Arg1>
void read(Arg1&& arg1) { cin>>arg1; }
template <typename Arg1, typename... Args>
void read(Arg1&& arg1, Args&&... args) { cin>>arg1; read(args...); }

#define int                     long long
#define all(ds)                 ds.begin(), ds.end()
#define uniq(v)                 (v).erase(unique(all(v)),(v).end())
#define gcd(x,y)                __gcd(x,y)
#define rep(i,a,b)              for(int i=a;i<b;i++)
#define precise(x)              cout<<fixed<<setprecision(x)
#define endl                    "\n"

const long long INF = 1e18;
const int32_t MOD = 1e9+7;
const int N = 2e5+5;

int n, m, k, q, r, l, x, y, z;
int a[N], b[N], c[N];
string s, t;
int ans ;

unordered_map<int, int>dp;

int recur(int y){

    if(dp.find(y) != dp.end())return dp[y];
    dp[y] = INF;
    int &ans = dp[y];
    ans = abs(y-x);
    if(y == 1){
        return ans;
    }
    if(y%2 == 0){
        ans = min(ans, 1 + recur(y/2));
    }
    else{
        ans = min(ans, 1 + min(recur(y-1), recur(y+1)));
    }
    return ans;

}
void solve(){
    read(x,y);
    // ans = abs(x-y);
    prn(recur(y));
}

signed main()
{
#ifndef ONLINE_JUDGE
    input_output
#else
    fastio
#endif

#ifdef SIEVE
    sieve();
#endif

#ifdef NCR
    init();
#endif

    int t = 1;
    // cin>>t;
    while(t--){
        solve();
    }

    return 0;
}


//QwQcOrZ yyds!!!
#ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#endif
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#if __cplusplus >= 201103L
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdalign>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#endif

// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif
#define ll __int128
#define F(i,a,b) for (int i=(a);i<=(b);i++)
#define R(i,a,b) for (int i=(a);i<(b);i++)
#define D(i,a,b) for (int i=(a);i>=(b);i--)
#define go(i,x) for (int i=head[x];i;i=e[i].nx)
#define mp make_pair
#define pb push_back
#define pa pair < int,int >
#define fi first
#define se second
#define re register
#define be begin()
#define en end()
#define sqr(x) ((x)*(x))
#define ret return puts("-1"),0;
#define put putchar('\n')
#define inf 1000000005
#define mod 998244353
#define int ll
#define N 1000005
using namespace std;
inline char gc(){static char buf[100000],*p1=buf,*p2=buf;return p1==p2&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++;}
#define gc getchar
inline ll read(){char c=gc();ll su=0,f=1;for (;c<'0'||c>'9';c=gc()) if (c=='-') f=-1;for (;c>='0'&&c<='9';c=gc()) su=su*10+c-'0';return su*f;}
inline void write(ll x){if (x<0){putchar('-');write(-x);return;}if (x>=10) write(x/10);putchar(x%10+'0');}
inline void writesp(ll x){write(x),putchar(' ');}
inline void writeln(ll x){write(x);putchar('\n');}
int n,f[N],t,a[N],ans;
signed main()
{
	n=read();
	if (n==1)
	{
		puts("1\n1");
		return 0;
	}
	f[1]=1,f[2]=1;
	for (int i=3;i;i++)
	{
		f[i]=f[i-1]+f[i-2];
	 	if (f[i]>n)
	 	{
	 		t=i;
	 		break;
	 	}
	}
	t-=1;
	for (int i=t;i>=1;i--)
	{
		a[i]+=(n/f[i]);
		n%=f[i];
	}
	t=max(t,t^1);
	for (int i=1;i<=t;i++)
	{
		ans+=a[i]+1;
	}
	writeln(ans);
	for (int i=1;i<=t-i+1;i++)
	{
		swap(a[i],a[t-i+1]);
	}
	for (int i=1;i<=t;i++)
	{
		if (i%2) for (int j=1;j<=a[i];j++) writeln(1);
		else for (int j=1;j<=a[i];j++) writeln(2);

		if (i%2) writeln(3);
		else writeln(4);
	}

}
/*
1 0
1 0
1 1
2 1
3 4
7 0
*/

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

#define nl "\n"
#define nf endl
#define ll long long
#define pb push_back
#define _ << ' ' <<

#define INF (ll)1e18
#define mod 998244353
#define maxn 110
#define phi ((1 + sqrt(5)) / 2)

ll i, i1, j, k, k1, t, n, m, res, flag[10], a, b;
vector<ll> rs;

void solve(ll a, ll b) {
    ll i;
    if (rs.size() == 131) return;

    if (a == 0) {
        for (i = 1; i <= b; i++) rs.pb(2);
        return;
    }
    if (b == 0) {
        for (i = 1; i <= a; i++) rs.pb(1);
        return;
    }

    if (a > b) {
        rs.pb(3); solve(a - b, b);
    } else {
        rs.pb(4); solve(a, b - a);
    }
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);

    #if !ONLINE_JUDGE && !EVAL
        ifstream cin("input.txt");
        ofstream cout("output.txt");
    #endif

    cin >> n;
    k = round(n / phi);

    for (i = max(-k, (ll)-100);; i++) {
        rs.clear();
        solve(n, k + i);
        if (rs.size() <= 130) break;
    }

    reverse(rs.begin(), rs.end());

    cout << rs.size() << nl;
    for (auto u : rs) cout << u << nl;

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep1(i, n) for(int i = 1;i < n+1; i++)
#define all(A) A.begin(),A.end()
typedef long long ll;

int main(){
  int n,m;
  cin >> n >> m;
  vector<ll> a(n+1);
  priority_queue<pair<ll,int>> p;
  rep1(i,n){
    cin >> a[i];
    p.push(make_pair(-a[i],i));
  }
  vector<vector<int>> to(n+1);
  rep(i,m){
    int x,y;
    cin >> x >> y;
    to[x].push_back(y);
  }
  vector<ll> dp(n+1,1e18);
  vector<bool> seen(n+1,0);
  while(p.size()>0){
    int start = p.top().second;
    p.pop();
    queue<int> q;
    q.push(start);
    while(q.size()>0){
      int now = q.front();
      q.pop();
      if(seen[now]) continue;
      seen[now] = 1;
      for(int next : to[now]){
        dp[next] = min(dp[next],dp[now]);
        dp[next] = min(dp[next],a[now]);
        q.push(next);
      }//next
    }//q
  }//p
  ll ans = -1e18;
  rep1(i,n){
    ans = max(ans,a[i]-dp[i]);
  }
  cout << ans << endl;
}

#include <bits/stdc++.h>

using namespace std;

int _____asdfwqerqwdcasdfasd = 0;
#define debug cout << "debug output " << "number: " << ++_____asdfwqerqwdcasdfasd << endl;
#define int long long
#define inf 2e18

int32_t main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    int n, x;
    cin >> n >> x;
    vector<int> a(n);
    for (int& x : a) {
        cin >> x;
    }

    int ans = x;
    for (int k = 1; k <= n; k++) {
        vector<vector<int>> dp(k + 1, vector<int>(k, -1));
        dp[0][0] = 0;

        for (int x : a) {
            for (int c = k - 1; c >= 0; c--) {
                for (int r = 0; r < k; r++) {
                    if (dp[c][r] == -1) {
                        continue;
                    }
                    int nx = dp[c][r] + x;
                    dp[c + 1][nx % k] = max(dp[c + 1][nx % k], nx);
                }
            }
        }

        int st = dp[k][x % k];
        if (st == -1) {
            continue;
        }
        ans = min(ans, (x - st) / k);
    }

    cout << ans << "\n";
    return 0;
}


/////home/mohammed/.config/sublime-text-3/Packages/User

/*input

*/
#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <numeric>
#include <math.h>
#include <sstream>
#include <iterator>
#include <cstdlib>
#include <unordered_map>
#include <map>
#include <list>
#include <set>

using namespace std;
using bin = std::bitset<8>;

#define endl ("\n")
#define pi (3.141592653589)
#define mod 1000000007
#define int int64_t
#define float double
#define ll long long
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define all(c) c.begin(), c.end()
#define min3(a, b, c) min({a,b,c})
#define max3(a, b, c) max({a,b,c})
#define min4(a, b, c, d) min({a,b,c,d})
#define max4(a, b, c, d) max({a,b,c,d})
#define rrep(i, n) for(int i=n-1;i>=0;i--)
#define rep(i,n) for(int i=0;i<n;i++)
#define fast ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr)
#define ld long double
#define scanArray(a,n) for(int i = 0; i < n; i++){cin >> a[i];}
#define coutArray(a,n) for(int i = 0; i < n; i++){cout << a[i] << " ";};cout << endl;
#define input(type, n) type n; cin>>n;

struct debugger
{
	template<typename T> debugger& operator , (const T& v)
	{
		cerr << v << " ";
		return *this;
	}
} dbg;

bool check_key(map<int, int> m, int key)
{
	if (m.find(key) == m.end())
		return false;

	return true;
}

vector<int> SieveOfEratosthenes(int n)
{
	bool prime[n + 1];
	memset(prime, true, sizeof(prime));

	vector<int> res;
	for (int p = 2; p * p <= n; p++)
	{
		if (prime[p] == true)
		{
			for (int i = p * p; i <= n; i += p)
				prime[i] = false;
		}
	}

	for (int p = 2; p <= n; p++)
		if (prime[p])
			res.push_back(p);
	//cout << p << " ";
	return res;
}

// function to convert decimal to binary
bin decToBinary(int n)
{
	// array to store binary number
	int binaryNum[32];

	// counter for binary array
	int i = 0;
	while (n > 0) {

		// storing remainder in binary array
		binaryNum[i] = n % 2;
		n = n / 2;
		i++;
	}
	string x = "";
	// printing binary array in reverse order
	for (int j = i - 1; j >= 0; j--) {
		x += to_string(binaryNum[j]);
	}
	bin result{x};
	return result;
}
// for example:
// bin result = decToBinary(2);
// bin result2 = decToBinary(10);
// bin z = result xor result2;
// cout << z;
// return 0;
int convertBinaryToDecimal(long long n)
{
	int decimalNumber = 0, i = 0, remainder;
	while (n != 0)
	{
		remainder = n % 10;
		n /= 10;
		decimalNumber += remainder * pow(2, i);
		++i;
	}
	return decimalNumber;
}
int factorial(int n) {

	long long res = 1;
	for (int i = 1; i <= n; i++) {
		res = ((res * i) % mod + mod) % mod ;
	}
	return res;
}

int32_t main()
{
	fast;
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

	input(int, num1); input(int, num2);
	if (num2 % num1 == 0) {
		cout <<	"Yes";
	} else {
		cout << "No";
	}

}

#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast,unroll-loops,no-stack-protector,fast-math,inline")
#pragma GCC target("sse4")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

template<typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define mod         1000000007
#define pi          3.1415926535898
#define eps         1e-9

#define fast       ios::sync_with_stdio(0); cin.tie(0);cout.tie(0)
#define vt vector
#define ar array
#define fs          first
#define sc          second
#define pb         push_back
#define sp          printf(" ")
#define nl          '\n'
#define all(a) a.begin(),a.end()
#define unique(c) (c).resize(unique(all(c)) - (c).begin())
#define sz(x) (int)(x).size()
#define revsort(x) sort(all(x));reverse(all(x))

#define REP(i,start,end) for (int i = start; i <=end; i++)
#define RREP(i,end,start) for (int i=end; i>=start ;i--)
#define EACH(x, a) for (auto& x: a)

typedef long long LL;
typedef long double LD;
typedef unsigned long long ULL;
typedef pair<int, int> pii;
typedef pair<LL, LL> pll;
typedef pair<double, double> pdd;
typedef vector<int> vi;
typedef vector<LL> vll;
typedef vector<double> vd;
typedef vector<vector<LL> > matrix;
typedef vector<vector<int> > graph;

template<class A> void read(vt<A>& v);
template<class A, size_t S> void read(ar<A, S>& a);
template<class T> void read(T& x) {
    cin >> x;
}
void read(double& d) {
    string t;
    read(t);
    d=stod(t);
}
void read(long double& d) {
    string t;
    read(t);
    d=stold(t);
}
template<class H, class... T> void read(H& h, T&... t) {
    read(h);
    read(t...);
}
template<class A> void read(vt<A>& x) {
    EACH(a, x)
        read(a);
}
template<class A, size_t S> void read(array<A, S>& x) {
    EACH(a, x)
        read(a);
}

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

int getRand(int l, int r)
{
    uniform_int_distribution<int> uid(l, r);
    return uid(rng);
}

struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        // http://xorshift.di.unimi.it/splitmix64.c
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};

int add (LL var1, LL var2) {
    return ( (var1 % mod) + (var2 % mod) + mod) % mod;
}

int mul (LL var1, LL var2) {
    return (var1*var2) % mod;
}

int powm (LL x, LL y) {
    int ans = 1;
    while (y) {
        if (y & 1) {
            ans = mul(ans, x);
        }
        x = mul(x, x);
        y /= 2;
    }
    return ans;
}

int inv(LL x) {
    return powm(x, mod-2);
}

LL INF=1e9;

void solve() {
    int n;
    read(n);
    vi a(n);
    read(a);
    int x = *min_element(all(a));

    map <int, int> mp;

    REP (i, 0, n-1) {
        for (LL j = 1; j*j <= a[i]; j++) {
            if (a[i]%j) continue;
            mp[j] = __gcd(a[i], mp[j]);
            mp[a[i]/j] = __gcd(a[i], mp[a[i]/j]);
        }
    }
    int ans = 0;
    for (auto px : mp) {
        if (px.fs > x) break;
        if (px.fs == px.sc) ans++;
    }
    cout << ans << nl;
}

int main() {
    fast;
        solve();
}


#include <bits/stdc++.h>

#define mid(l,r) ((l + r) >> 1)
#define lsb(x) (x & (-x))
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define FOR(X,L,R) for(int X=L;X<R;++X)
#define endl '\n'
#define int long long
#define MOD ((int)1e9 + 7)
#define INF (0x3f3f3f3f)
#define LLINF (0x3f3f3f3f3f3f3f3fLL)

using namespace std;

template<typename T>
inline void input(vector<T>& v)
{
    for(T& x: v)
        cin >> x;
}

void solve()
{
    int a, b, c; cin >> a >> b >> c;

    cout << 21 - (a + b + c) << endl;
}

signed main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);

    #if defined(CODEFORCES) || defined(CF)
        int t; cin >> t;
        while(t--) solve();
    #else
        solve();
    #endif

    return 0;
}

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD=1000000007;
#define INF 1LL<<30
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()

int main(){
    ll N;
    cin>>N;
    for(ll i=1;;i++){
        if(stoll(to_string(i)+to_string(i))>N){
            cout<<i-1<<endl;
            return 0;
        }
    }
}


// Problem : D - AB
// Contest : AtCoder - AtCoder Regular Contest 108
// URL : https://atcoder.jp/contests/arc108/tasks/arc108_d
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update

using namespace std;
using namespace __gnu_pbds;

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>
ordered_set;

struct splitmix64_hash {
	static uint64_t splitmix64(uint64_t x) {
		// http://xorshift.di.unimi.it/splitmix64.c
		x += 0x9e3779b97f4a7c15;
		x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
		x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
		return x ^ (x >> 31);
	}

	size_t operator()(uint64_t x) const {
		static const uint64_t FIXED_RANDOM = std::chrono::steady_clock::now().time_since_epoch().count();
		return splitmix64(x + FIXED_RANDOM);
	}
};

template <typename K, typename V, typename Hash = splitmix64_hash>
using hash_map = __gnu_pbds::gp_hash_table<K, V, Hash>;

template <typename K, typename Hash = splitmix64_hash>
using hash_set = hash_map<K, __gnu_pbds::null_type, Hash>;

#define FOR(i,a,b) for(int i = (a); i <= (b); ++i)
#define FORD(i,a,b) for(int i = (a); i >= (b); --i)
#define RI(i,n) FOR(i,1,(n))
#define REP(i,n) FOR(i,0,(n)-1)
#define mini(a,b) a=min(a,b)
#define maxi(a,b) a=max(a,b)
#define pb push_back
#define st first
#define nd second
#define sz(w) (int) w.size()
typedef vector<int> vi;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<pii, int> para;
const ll inf = 1e18 + 7;
const ll maxN = 1e6 + 5;
const ll MOD = 1e9 + 7;
int n;
char caa, cab, cba, cbb;
ll dp1[maxN], dp2[maxN][2];

ll solve1(int left) {
	if (left == 0) return 1;
	if (left == 1) return 0;
	if (dp1[left] != -1) return dp1[left];
	ll ans = 0;
	FOR(i, 2, left) {
		ans = (ans + solve1(left - i)) % MOD;
	}
	dp1[left] = ans;
	return ans;
}

ll solve2(int left, int which) {
	if (left == 0) {
		return 1 - which;
	}
	if (dp2[left][which] != -1) return dp2[left][which];
	ll ans = 0;
	FOR(i, 1, left) {
		ans = (ans + solve2(left - i, 1 ^ which)) % MOD;
	}
	dp2[left][which] = ans;
	return ans;
}

// sprawdz MODULO!
int main() {
    mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
	ios_base::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	cin >> n;
	cin >> caa >> cab >> cba >> cbb;
	RI(i, n) {
		dp1[i] = -1;
		dp2[i][0] = dp2[i][1] = -1;
	}
	// if (n == 2) {
		// cout << 1 << "\n";
	// }
	// if(n == 3) {
		// cout << 1 << "\n";
		// return 0;
	// }
	if (cab == 'B') {
		if (cbb == 'B') {
			cout << 1 << "\n";
		} else {
			if (cba == 'B') {
				cout << solve1(n) << "\n";
			} else {
				cout << solve2(n - 1, 1) << "\n";
			}
		}
	} else {
		if (caa == 'A') {
			cout << 1 << "\n";
		} else {
			if (cba == 'A') {
				cout << solve1(n) << "\n";
			} else {
				cout << solve2(n - 1, 1) << "\n";
			}
		}
	}
	return 0;
}


#include<cstdio>
#include<cmath>
using namespace std;

#define ll long long
ll a,b,c,d;
int main()
{
	scanf("%lld%lld%lld%lld",&a,&b,&c,&d);
	if (c*d<=b) printf("-1\n");
	else printf("%d",(int)ceil(a*1.0/(c*d-b)));
	return 0;
}

#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double lld;

#define mod 1000000007;
#define INF 1e18
#define pb push_back

#define F first
#define S second
#define pll pair<ll,ll>
#define plll pair<ll,pair<ll,ll>>
// pb,mp,F,S,MOD,INF should not be used as variable names for any instances...

#ifndef ONLINE_JUDGE
#define debug(x) cerr << #x <<" "; _print(x); cerr << endl;
#else
#define debug(x)
#endif

void _print(ll t) {cerr << t;}
void _print(int t) {cerr << t;}
void _print(string t) {cerr << t;}
void _print(char t) {cerr << t;}
void _print(lld t) {cerr << t;}
void _print(double t) {cerr << t;}
void google(int t) {cout << "Case #" << t << ": ";}

template <class T, class V> void _print(pair <T, V> p);
template <class T> void _print(vector <T> v);
template <class T> void _print(set <T> v);
template <class T, class V> void _print(map <T, V> v);
template <class T> void _print(multiset <T> v);
template <class T, class V> void _print(pair <T, V> p) {cerr << "{"; _print(p.ff); cerr << ","; _print(p.ss); cerr << "}";}
template <class T> void _print(vector <T> v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";}
template <class T> void _print(set <T> v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";}
template <class T> void _print(multiset <T> v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";}
template <class T, class V> void _print(map <T, V> v) {cerr << "[ "; for (auto i : v) {_print(i); cerr << " ";} cerr << "]";}

ll gcd(ll a,ll b)
{
    if(b==0)
    {
        return a;
    }
    return gcd(b,a%b);
}
ll lcm(ll a,ll b)
{
    return a*b/__gcd(a,b);
}
bool isprime(ll x){
    if(x <= 1){
        return false;
    }
    if(x % 2 == 0 && x != 2){
        return false;
    }
    for(ll i=3;i<=sqrt(x);i+=2){
        if(x%i == 0){
            return false;
        }
    }
    return true;
}
ll power(ll x,ll y)
{
    if (y == 0)
     {  return 1;}

    if (y%2==0)
    {
        return (power(x,y/2)*power(x,y/2))%mod;
    }
    if(y%2!=0)
    {
        return (x*power(x,y/2)*power(x,y/2))%mod;
    }
}
#define ma 200001
vector<ll>edges[ma];
vector<ll>cat(ma);
ll up[ma][20];
// vector<pair<ll,ll>>downpath(ma);
// vector<ll>diameter(ma,0);
// vector<ll>vis(ma,0);
// int dfs(int src)
// {
//     vis[src]=1;
//     for(auto i:v[src])
//     {
//         if(vis[i]==0)
//         {
//             dfs(i);
//             downpath[src].S+=1+downpath[i].S;
//             downpath[src].F+=downpath[i].F+downpath[i].S+1;
//         }
//     }
// }
void binarylift(int src,int par)
{
    up[src][0]=par;
    for(int i=1;i<20;i++)
    {
        if(up[src][i-1]!=-1)
        {
            up[src][i]=up[up[src][i-1]][i-1];
        }
        else
        {
            up[src][i]=-1;
        }
    }
    for(auto i:edges[src])
    {
        if(i!=par)
        {
            binarylift(i,src);
        }
    }
}
ll ans=0;
void solve(int r_sum,int edge,int node,int find,int c_sum)
{  // cout<<"fyj"<<endl;
    if(c_sum>r_sum)
    {
        return;
    }
    if(c_sum==r_sum)
    {   //cout<<find<<endl;
        if(find!=0)
        {
            ans=(ans+1)%mod;
        }
        return;
    }
    for(int i=1;i<=edge;i++)
    {
        if(i>=node)
        {
            solve(r_sum,edge,node,find+1,c_sum+i);
        }
        else
        {
            solve(r_sum,edge,node,find,c_sum+i);
        }
    }
}
int main()
{
      #ifndef ONLINE_JUDGE
        freopen("input.txt","r",stdin);
        freopen("output.txt","w",stdout);
        freopen("Error.txt", "w", stderr);
      #endif
      ll t,n,j,h,r,x,y,k,w,l,m,i,d,A,B,p,q;
      t=1;
      while(t--)
      {
        ll a,b,c;
        cin>>a>>b>>c>>d;
        if(b>=c*d)
        {
           cout<<-1<<endl;continue;
        }
        k=0;l=0;
        while(k*d<a)
        {
            k+=c;
            a+=b;
            l++;
        }
        cout<<l<<endl;
       }
    return 0;
}


#include <bits/stdc++.h>
#define rep(i,n) for (int i=0;i<(n);i++)
#define rep1(i,n) for (int i=1;i<(n);i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main() {
  int n;
  cin >> n;
  map<int,int> circle;
  vector<int> f(n);
  rep(i,n){
    cin >> f[i];
  }
  int cnt = 0;
  rep(i,n){
    map<int,int> m;
    int x = f[i] - 1;
    while(1){
      if(m[x] > 0){
        cnt++;
        break;
      }
      if(circle[x] > 0){
        break;
      }

      // if(m[x] > 0){
      //   cnt++;
      //   while(1){
      //     if(circle[x]>0){
      //       break;
      //     }
      //     circle[x]++;
      //     x = f[x] - 1;
      //   }
      //   break;
      // }
      m[x]++;
      circle[x]++;
      x = f[x] - 1;
    }
  }
  ll ans = 1;

  rep(i,cnt){
    ans *= 2;
    ans %= 998244353;
  }

  cout << (ans - 1) % 998244353 << endl;
  return 0;
}

#include <bits/stdc++.h>
using namespace std;
const int P=998244353;
vector<int> e[200050];
int n,ans=1;
bool v[200050];

void dfs(int u) {
	v[u]=1;
	for (int i=0; i<e[u].size(); ++i)
		if (!v[e[u][i]]) dfs(e[u][i]);
}

int main() {
	scanf("%d",&n);
	for (int i=1,u; i<=n; ++i) {
		scanf("%d",&u);
		e[u].push_back(i);
		e[i].push_back(u);
	}
	for (int i=1; i<=n; ++i)
		if (!v[i]) dfs(i),ans=ans*2%P;
	cout<<(ans+P-1)%P;
}


#include<iostream>
#include<vector>
#include<algorithm>
#include<cstdio>
#include<string>
#include<stdio.h>
#include<stdlib.h>
#include<float.h>
#include<tuple>
#include<string.h>
#include<iomanip>
#include<stack>
#include<queue>
#include<map>
#include<deque>
#include<math.h>

using namespace std;
#define ll long long
#define rep(i,n) for(ll i=0;i<n;i++)
#define REP(i,n) for(ll i=1;i<=n;i++)
#define ALLOF(c) (c).begin(), (c).end()
#define Pa pair<ll,ll>
const ll mod=1000000007;
const ll modq=998244353;
const ll INF=1e12;
const ll inf=-1;
ll ABS(ll a){return max(a,-a);}

int main(void){
    ll N;
    string S,X;
    cin>>N>>S>>X;
    reverse(ALLOF(S));
    reverse(ALLOF(X));
    vector<vector<bool>> TW(N+1,vector<bool>(7,false));

    TW.at(0).at(0)=true;
    ll ima=1;
    rep(i,N){
        ll num=S.at(i)-'0';
        if(X.at(i)=='A'){
            rep(j,7) TW.at(i+1).at((j+ima*num)%7)=(TW.at(i).at(j) && TW.at(i).at((j+ima*num)%7));
        }
        else{
            rep(j,7) TW.at(i+1).at((j+ima*num)%7)=(TW.at(i).at(j) || TW.at(i).at((j+ima*num)%7));
        }
        ima=(ima*10)%7;
    }
    if(TW.at(N).at(0)) cout<<"Takahashi"<<endl;
    else cout<<"Aoki"<<endl;
    return 0;
}

#include<bits/stdc++.h>
using namespace std;
template<typename A, typename B> ostream& operator<<(ostream &os, const pair<A, B> &p) { return os << '(' << p.first << ", " << p.second << ')';}
template<typename T_container, typename T = typename enable_if<!is_same<T_container, string>::value, typename T_container::value_type>::type> ostream& operator<<(ostream &os, const T_container &v) {os << '{'; string sep; for (const T &x : v) os << sep << x, sep = ", "; return os << '}'; }
void dbg_out() { cerr << endl; }
template<typename Head, typename... Tail> void dbg_out(Head H, Tail... T) { cerr << ' ' << H; dbg_out(T...); }
template<typename T> void dbg_a(T *a,int l,int r){cerr<<" {";for(int i = l;i<r;i++) cerr<<a[i]<<", ";cerr<<a[r]<<"}"<<endl;}
typedef long long ll;
//#define int ll
inline int read(){
	int f(1),r(0);char c(getchar());
	while(c<'0'||c>'9'){if(c == '-') f = -1; c = getchar();}
	while(c>='0'&&c<='9'){ r = (r<<1) + (r<<3) + c - '0';c = getchar();}
	return f*r;
}
typedef pair<int,int> PII;
#define fi first
#define se second
#define mst(a,b) memset(a,b,sizeof(a))
#define For(i,a,b) for(int i = a;i<=b;i++)
#define For_(i,a,b) for(int i = a;i>=b;i--)
#define _for(i,a) for(int i = 0;i<a;i++)
#define _sum(a,l,r) accumulate(a + l,a + 1 + r,0)
#define All(x) x.begin(),x.end()
//    For(i,1,n) For(j,1,m) printf("f[%lld][%lld] = %lld\n",i,j,f[i][j]);
//const ll INF = 0x3f3f3f3f3f3f3f3f;
const int INF = 0x3f3f3f3f;
const int N = 2e5 + 10,M = N*2 + 10;
const int mod = 998244353;
int h[N],ne[M],e[M],idx;
void add(int a,int b){
	e[++idx] = b,ne[idx] = h[a],h[a] = idx;
}
bool dp[N][10];
void solve(){
	int n = read();
	string s,x;
	cin>>s>>x;
	dp[n][0] = 1;
	For_(i,n-1,0){
		For(j,0,6){
			int q = dp[i+1][10*j%7],p = dp[i+1][(10*j + s[i] - '0')%7];
			if(x[i] == 'T') dp[i][j] = q|p;
			else dp[i][j] = q&p;
		}
	}
	if(dp[0][0]) cout<<"Takahashi\n";
	else cout<<"Aoki\n";
}
signed main(){
	int T = 1;
	//T = read();
	while(T--) solve();
	system("pause");
	return 0;
}


#pragma GCC optimize ("O2")
#pragma GCC target ("avx2")
#include<bits/stdc++.h>
//#include<atcoder/all>
//using namespace atcoder;

using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);

	int N;
	cin >> N;
	N--;
	string S;
	cin >> S;

	while (N > 0) {
		int K = 1;
		int tmp = N;
		while (tmp > 0) {
			K *= 3;
			tmp /= 3;
		}
		K /= 3;

		string T;
		rep(i, N - K + 1) {
			char a = S[i], b = S[i + K];
			if (a > b) swap(a, b);
			if (a == b) T.pb(a);
			else if (a == 'B' && b == 'R') T.pb('W');
			else if (a == 'B' && b == 'W') T.pb('R');
			else T.pb('B');
		}
		S = T;
		N -= K;
	}
	co(S[0]);

	Would you please return 0;
}

#include <bits/stdc++.h>
#define REP(i,n) for (int i = 0; i < (n); ++i)
template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}
using namespace std;
using ll = long long;
using P = pair<int,int>;
using Pl = pair<long long,long long>;
using veci = vector<int>;
using vecl = vector<long long>;
using vecveci = vector<vector<int>>;
using vecvecl = vector<vector<long long>>;
const int MOD = 1000000007;
const double pi = acos(-1);
ll gcd(ll a, ll b) {if(b == 0) return a; else return gcd(b,a%b);}
ll lcm(ll a, ll b) {return a*b/gcd(a,b);}

template<int MOD> struct Fp {
    long long val;
    constexpr Fp(long long v = 0) noexcept : val(v % MOD) {
        if (val < 0) val += MOD;
    }
    constexpr int getmod() { return MOD; }
    constexpr Fp operator - () const noexcept {
        return val ? MOD - val : 0;
    }
    constexpr Fp operator + (const Fp& r) const noexcept { return Fp(*this) += r; }
    constexpr Fp operator - (const Fp& r) const noexcept { return Fp(*this) -= r; }
    constexpr Fp operator * (const Fp& r) const noexcept { return Fp(*this) *= r; }
    constexpr Fp operator / (const Fp& r) const noexcept { return Fp(*this) /= r; }
    constexpr Fp& operator += (const Fp& r) noexcept {
        val += r.val;
        if (val >= MOD) val -= MOD;
        return *this;
    }
    constexpr Fp& operator -= (const Fp& r) noexcept {
        val -= r.val;
        if (val < 0) val += MOD;
        return *this;
    }
    constexpr Fp& operator *= (const Fp& r) noexcept {
        val = val * r.val % MOD;
        return *this;
    }
    constexpr Fp& operator /= (const Fp& r) noexcept {
        long long a = r.val, b = MOD, u = 1, v = 0;
        while (b) {
            long long t = a / b;
            a -= t * b; swap(a, b);
            u -= t * v; swap(u, v);
        }
        val = val * u % MOD;
        if (val < 0) val += MOD;
        return *this;
    }
    constexpr bool operator == (const Fp& r) const noexcept {
        return this->val == r.val;
    }
    constexpr bool operator != (const Fp& r) const noexcept {
        return this->val != r.val;
    }
    friend constexpr ostream& operator << (ostream &os, const Fp<MOD>& x) noexcept {
        return os << x.val;
    }
    friend constexpr Fp<MOD> modpow(const Fp<MOD> &a, long long n) noexcept {
        if (n == 0) return 1;
        auto t = modpow(a, n / 2);
        t = t * t;
        if (n & 1) t = t * a;
        return t;
    }
};

using mint = Fp<MOD>;

long long extGCD(long long a, long long b, long long &x, long long &y) {
    if (b == 0) {
        x = 1;
        y = 0;
        return a;
    }
    long long d = extGCD(b, a%b, y, x);
    y -= a/b * x;
    return d;
}

ll f(ll a, ll b, ll m) {
    ll k,l;
    extGCD(a,m,k,l);
    if(k < 0) k = m+k;
    return (m+b*k)%m;
}

void solve(ll a, ll b, ll m) {
    ll g = gcd(a,m);
    if(g == 1) {
        cout << f(a,b,m) << endl;
    } else if(b%g == 0) {
        cout << f(a/g,b/g,m/g) << endl;
    } else {
        cout << -1 << endl;
    }
}

int main() {
    int T; cin >> T;
    while(T--) {
        ll N,S,K;
        cin >> N >> S >> K;
        solve(K,N-S,N);
    }
}


#include <bits/stdc++.h>
using namespace std;
typedef signed long long ll;

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define FORR2(x,y,arr) for(auto& [x,y]:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

ll N;
set<ll> A;
void solve() {
	int i,j,k,l,r,x,y; string s;

	cin>>N;
	for(i=1;1LL*i*i<=N;i++) if(N%i==0) A.insert(i),A.insert(N/i);
	FORR(a,A) cout<<a<<endl;
}

int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}

#include<bits/stdc++.h>
using namespace std;
#define ll  long long int
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL)
#define br cout<<endl;
#define pb push_back
#define left(x) x.begin(), x.end()
#define right(x) x.begin(), x.end(), greater<ll>()
#define mp make_pair
#define M -1000000005
void solve(){
    ll n;
    cin>>n;
    set<ll>a;
    for(ll i = 1; i <= sqrt(n); ++i){
        if(n % i == 0){
            a.insert(i);
            a.insert(n/i);
        }
    }
    for(auto i:a){cout<<i;br}
}
int main(){
    fast;
    ll q=1;
    while(q--){
        solve();br;
    }
}


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

char RPS(char a, char b) {
  if(a=='R' && b=='S') return a;
  if(a=='P' && b=='R') return a;
  if(a=='S' && b=='P') return a;
  if(a=='R' && b=='P') return b;
  if(a=='P' && b=='S') return b;
  if(a=='S' && b=='R') return b;
  return a;
}

int main() {
  ll n,k; cin>>n>>k;
  string s; cin>>s;
  for(int i=0; i<k; ++i) {
    // 2つを比べたときの勝者
    string winner;
    for(int j=0; j<(int)s.length(); ++j) {
      if(j==(int)s.length()-1) winner+=RPS(s[j],s[0]);
      else winner+=RPS(s[j],s[j+1]);
    }
    string s2;
    if(s.length()%2==0) {
      for(int j=0; j<(int)s.length(); j+=2) s2+=winner[j];
    } else {
      for(int j=0; j<(int)s.length(); j+=2) s2+=winner[j];
      for(int j=1; j<(int)s.length(); j+=2) s2+=winner[j];
    }
    s = s2;
  }
  cout << s[0] << endl;
}

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

int main() {
	// your code goes here
	string a;
	int n;
	cin>>n;
	cin>>a;
	vector<int> C(n), A(n);
	for(int i=0;i<n;i++)
	{
			if(a[i]=='A')
			A[i]++;
			else if( a[i]=='C')
			C[i]++;
			else if(a[i]=='G')
			C[i]--;
			else
			A[i]--;

		if(i==0) continue ;

		A[i]+=A[i-1];
		C[i]+=C[i-1];

	}
	int cnt=0;
	for(int i=1;i<n;i++)
	{
		for(int j=0;j+i<n;j++)
		{
			if(j==0)
			{
				if(A[j+i]==0 && C[j+i]==0)
				cnt++;
			}
			else
			{
				if(A[j+i]-A[j-1]==0 && C[j+i]-C[j-1]==0)
				cnt++;
			}

		}
	}
	cout<<cnt;
	return 0;
}


/**
 *   @FileName	a.cpp
 *   @Author	kanpurin
 *   @Created	2021.05.31 03:48:48
**/

#include "bits/stdc++.h"
using namespace std;
typedef long long ll;

int main() {
    int n,m;cin >> n >> m;
    vector<bool> dp(min(n,m)*2+1);
    vector<pair<int,int>> a(m);
    for (int i = 0; i < m; i++) {
        cin >> a[i].first >> a[i].second;
        a[i].second-=max(n-m,0);
    }
    dp[dp.size()/2] = 1;
    sort(a.begin(), a.end());
    for (int i = 0; i < m; i++) {
        int h = a[i].first;
        vector<int> v1,v2;
        while(i < m && h == a[i].first) {
            if (a[i].second < 0 || a[i].second >= dp.size()) {i++; continue;}
            v1.push_back(a[i].second);
            if ((a[i].second>=1 && dp[a[i].second-1]) || (a[i].second+1<dp.size() && dp[a[i].second+1])) {
                v2.push_back(a[i].second);
            }
            i++;
        }
        i--;
        for(int v:v1) dp[v]=false;
        for(int v:v2) dp[v]=true;
    }
    cout << accumulate(dp.begin(), dp.end(), 0) << endl;
    return 0;
}

#include <bits/stdc++.h>

using namespace std;

#define int long long

template <typename T>
void print_vec(const vector<T>& v, bool newline = true) {
    for (int i = 0; i < v.size(); ++i) {
        cout << v[i] << " ";
    }
    if (newline) {
        cout << "\n";
    }
}

mt19937 rng((uint32_t)chrono::steady_clock::now().time_since_epoch().count());

const int maxn = (int)2e5 + 105;
const int mod = (int)998244353;

#define sz(x) ((int)(x.size()))

#define pb push_back
#define rep(i,a,b) for (int i = (a); i <= (b); i++)
#define repr(i,a,b) for (int i = (a); i >= (b); i--)

int fact_setup=0; int * fact;

int ex (int a, int b){
    if(b==0)return 1; int e = ex(a,b/2); e=(1ll*e*e)%mod; if(b&1)e=(1ll*e*a)%mod; return e;
}
int inv (int a){
    return ex(a, mod - 2);
}
int choose (int a, int b){
    if(!fact_setup){
        fact_setup=1;
        fact = new int [maxn];
        fact[0]=1; rep (i,1,maxn-1) fact[i]=(i*fact[i-1])%mod;
    }
    if(a<b)return 0;
    int num = fact[a];
    int denom = (fact[b] * fact[a - b]) % mod;
    return (num * inv(denom)) % mod;
}

#define pii pair <int, int>
#define pvi pair <vector <int>, int>

#define pai array <int,2>
#define pdi array <double, 2>
#define pdt array <double, 3>

#define pti array <int,3>
#define pfi array <int,4>

#define all(v) v.begin(), v.end()

main(){
    cin.tie(0); ios_base::sync_with_stdio(0);
    int n, m; cin >> n >> m;
    map<int,vector<int> >coord;
    rep (i,1,m){
        int a,b;cin>>a>>b;
        coord[a].pb(b);
    }
    map<int,int>vis;vis[n]=1;
    for (auto i = coord.begin(); i!=coord.end(); i++){
        vector<int> v = i->second;
        vector<pai>on;
        for (int j : v){
            if(vis[j-1]||vis[j+1]) on.pb({j,1});
            else if(vis[j])on.pb({j,0});
        }
        for (auto j : on) vis[j[0]]=j[1];

    }
    int ans=0;
    for (auto i = vis.begin();i!=vis.end(); i++){
        if (i->second)ans++;
    }
    cout<<ans;
    return 0;
}


#include<bits/stdc++.h>
#define ll long long int
using namespace std;
#define fio ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL)
#define mp make_pair
#define fi first
#define se second
#define pb push_back
#define endl "\n"
#define maxpq priority_queue<ll>
#define minpq priority_queue<ll, vector<ll>, greater<ll> >
#define vi vector<ll>
#define pii pair<ll, ll>
#define vii vector<pii>
#define for0(i, n) for (int i = 0; i < n; i++)
#define for1(i, n) for (int i = 1; i <= n; i++)
#define loop(i,a,b) for (int i = a; i < b; i++)
#define bloop(i,a,b) for (int i = a ; i>=b;i--)
#define MOD 1000000007
#define INT_MAXI 9000000000000000000
#define INT_MINI -9000000000000000000

ll max(ll a, ll b) {if (a > b) return a; else return b;}
ll min(ll a, ll b) {if (a < b) return a; else return b;}

const int dx[4] = { -1, 1, 0, 0};
const int dy[4] = {0, 0, -1, 1};
int XX[] = { -1, -1, -1, 0, 0, 1, 1, 1 };
int YY[] = { -1, 0, 1, -1, 1, -1, 0, 1 };

ll n,m,x,y,z,county,c2=0;
//vector<ll>vec[25];
ll ans=0;
ll arr[20];
ll dp[20][300005];

vector<pii>vec[20];

bool check(ll mask,ll ind)
{
	ll ind2=0,count=0;
	for(auto itr:vec[ind])
	{
		y=itr.fi,z=itr.se;
		while(ind2<y)
		{
			ind2++;
			ll z=arr[ind2]&mask;
			if(z!=0)
			count++;

		}
		if(count>z)
		return 0;

	}
	return 1;

}

ll func(ll ind,ll mask)
{
  //  cout<<ind<<" "<<mask<<endl;
	if(ind==n+1)
	return 1;

	if(dp[ind][mask]!=-1)
	return dp[ind][mask];

	ll count=0;
	for(int i=1;i<=n;i++)
	{
		ll z=mask&arr[i];
		if(z==0)
		{
			ll temp=mask+arr[i];
			if(check(temp,ind))
			{
			 //   cout<<ind<<" "<<temp<<i<<" "<<arr[i]<<endl;
				count+=func(ind+1,temp);
			}

		}

	}

	return dp[ind][mask]= count;

}
map<ll,pii>mpp;

int main()
{
    memset(dp,-1,sizeof(dp));
	fio;
	ll t,i,j,a,b,c,mini=INT_MAXI,maxi=INT_MINI,q,flag=0;
	cin>>n>>m;
	arr[0]=1;
	for(i=1;i<=20;i++)
	arr[i]=2*arr[i-1];
	for(i=0;i<m;i++)
	{
		cin>>x>>y>>z;
		vec[x].pb(mp(y,z));

	}
	for(i=1;i<=n;i++)
	sort(vec[i].begin(),vec[i].end());
	ll ans=func(1,0);
	cout<<ans;

}

#include <bits/stdc++.h>

#define endl '\n'
#define fi first
#define se second
#define MOD(n,k) ( ( ((n) % (k)) + (k) ) % (k))
#define forn(i,n) for (int i = 0; i < int(n); i++)
#define forr(i,a,b) for (int i = a; i <= b; i++)
#define all(v) v.begin(), v.end()
#define pb push_back

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> ii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ii> vii;

const int MX = 300005;
ll n, k, a[MX], cn[MX], res, acu;

int main () {
	ios_base::sync_with_stdio(0); cin.tie(0);

	cin >> n >> k;
	forn (i, n) {
		cin >> a[i];
		cn[a[i]]++;
	}

	acu = k;
	forn (i, n + 1) {
		acu = min(acu, cn[i]);
		res += acu;
	}

	cout << res << endl;

	return 0;
}


#include<bits/stdc++.h>
#define ll long long
#define fr(i,j,k) for(int i=j;i<k;i++)
#define f(n) fr(i,0,n)
#define f1(n) fr(i,1,n+1)
#define pb push_back
#define F first
#define S second
#define all(x) x.begin(), x.end()
const int mod = 1e9+7;
using namespace std;
int d[1005][1005];
vector<int>g[1005][26];
void solve() {
    int n, m;
    cin >> n >> m;
    vector<pair<int,int>>e;
    f(m) {
        int a, b;
        char c;
        cin >> a >> b >> c;
        e.pb({a, b});
        g[a][c-'a'].pb(b);
        g[b][c-'a'].pb(a);
    }
    queue<pair<int,int>>q;
    q.push({1, n});

    memset(d, -1, sizeof(d));
    d[1][n] = 0;
    while (q.size()) {
        auto now = q.front();
        q.pop();
        for (int i = 0 ; i < 26 ; i++) {
            for (auto &j : g[now.F][i]) {
                for (auto &k : g[now.S][i]) {
                    if (d[j][k] == -1) {
                        d[j][k] = d[now.F][now.S] + 2;
                        q.push({j,k});
                    }
                }
            }
        }
    }
    int mn = 1e9;
    f1(n) {
        if (~d[i][i])
            mn = min(mn, d[i][i]);
    }
    for (auto &i : e) {
        if (~d[i.F][i.S]) mn = min(mn, d[i.F][i.S] + 1);
        if (~d[i.S][i.F]) mn = min(mn, d[i.S][i.F] + 1);
    }
    if (mn >1e6) {
        mn = -1;
    }
    cout << mn << '\n';
}
int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int t = 1;
    //cin >> t;
    while (t--) {
        solve();
    }
}

#include <iostream>
#include <algorithm>
#include <numeric>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <iomanip>
#include <functional>
#include <bitset>
#include <limits>
#include <cstdio>
#include <cmath>
#include <cassert>
#include <random>

#ifdef DEBUG
#include "library/Utility/debug.cpp"
#else
#define debug(...)
#endif

#define rep(i,n) for(int i=0;i<(n);++i)
#define EL '\n'
#define print(i) std::cout << (i) << '\n'
#define all(v) (v).begin(), (v).end()
using lnt = long long;
struct FIO{FIO(){std::cin.tie(0);std::ios_base::sync_with_stdio(0);std::cout<<std::fixed<<std::setprecision(15);}}fIO;
template<typename T> using V = std::vector<T>;
template<typename T> void fill(V<T>&v) { for(T&e:v) std::cin >> e; }
/*-*/

int main() {
	lnt n,t;
	std::cin >> n >> t;
	V<lnt> a(n);
	fill(a);
	V<lnt> x;
	x.reserve((int)2e6);
	lnt m=n/2;
	x.emplace_back(0);
	rep(s,1<<m) {
		lnt sum=0;
		rep(i,m) {
			if(s>>i&1) sum+=a[i];
		}
		if(sum<=t) x.emplace_back(-sum);
	}
	std::set<lnt> set1(all(x));
	lnt max=-*set1.lower_bound(-t);
	rep(s,1<<(n-m)) {
		lnt sum=0;
		rep(i,(n-m)) {
			if(s>>i&1) sum+=a[m+i];
		}
		if(sum<=t) {
			auto lb=set1.lower_bound(-t+sum);
			max=std::max(max,sum-*lb);
		}
	}
	print(max);
}


#include<iostream>
#include<vector>
#include<map>
#include<stack>
#include<set>
#include<queue>
#include<stdlib.h>
#include<math.h>
#include<string>
#include<string.h>
#include<algorithm>
#include<iomanip>
#include<sstream>
#define endl "\n"
#define Doura() ios_base::sync_with_stdio(false),cin.tie(NULL), cout.tie(NULL)
#define ll long long
using namespace std;
const long long MXX=1e7;
bool isPalindrome(string s)
{
     string s1=s;
     reverse(s.begin(),s.end());
     return s1==s;
}
void kajelag()
{
     string s;
     cin>>s;
     if(isPalindrome(s))
     {
          cout<<"Yes"<<endl;
          return;
     }
     int leading0=0,last0=0;
     for(int i=0;i<s.size();i++)
     {
          if(s[i]!='0')
               break;
          else leading0++;
     }
     for(int i=s.size()-1;i>=0;i--)
     {
          if(s[i]!='0')
               break;
          else last0++;
     }
     if(last0>leading0)
     {
          int dif=last0-leading0;
          string s1="";
          for(int i=0;i<dif;i++)
               s1+='0';
          s1+=s;
          if(isPalindrome(s1))
          {
               cout<<"Yes"<<endl;
               return;
          }
          cout<<"No"<<endl;
     }
     else cout<<"No"<<endl;
}
int main()
{
      Doura();
     #ifndef ONLINE_JUDGE
             freopen("input.txt","r",stdin);
             freopen("output.txt","w",stdout);
     #endif // ONLINE_JUDGE

     int t;
    // cin>>t;
    // while(t--)
     {
          kajelag();
     }
     return 0;
}

#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define f first
#define s second
#define FSD ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;
const int mod=998244353;
const int maxN=1e6+1;
const ll inf=1e18+1;
int main(){
    int n;
    cin>>n;
    int nt = 1.08 * n;
    if(nt < 206){
        cout<<"Yay!\n";
    }
    else if(nt == 206){
        cout<<"so-so\n";
    }
    else{
        cout<<":(\n";
    }
}


#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
using namespace std;
#define ll long long
#define endl "\n"
#define f first
#define s second
#define ar array
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define sz(X) ((int)(X).size())
#define pcnt __builtin_popcount
#define sort_unique(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define get_pos(c, x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define all(X) (X).begin(), (X).end()
#define rall(X) (X).rbegin(), (X).rend()
#define ms(c, x)  memset(c,x,sizeof c)
#define  No(x) cout<<(x?"NO":"No")<<endl;
#define  Yes(x) cout<<(x?"YES":"Yes")<<endl;
#define  nl cout<<endl;
#define forn(i, n) for(int i = 0; i < int(n); i++)
#define fore(i, l, r) for(int i = l; i <=r; i++)
#define ford(i, n) for (int i = n - 1; i >= 0; --i)
using ld = long double;
using db = double;
using str = string;
using pi = pair<int, int>;
using pl = pair<ll, ll>;
using pd = pair<db, db>;

using vi = vector<int>;
using vb = vector<bool>;
using vl = vector<ll>;
using vd = vector<db>;
using vs = vector<str>;
using vpi = vector<pi>;
using vpl = vector<pl>;
using vpd = vector<pd>;

template<typename T>
using osl = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template<typename T>
using osg = tree<T, null_type, greater<T>, rb_tree_tag, tree_order_statistics_node_update>;

// for greater use greater<T>
template<typename T>
ostream &operator+(ostream &out, const vector<T> &vec) {
    for (const auto &x : vec) {
        out << x << " ";
    }
    out << "\n";
    return out;
}

template<typename T>
ostream &operator*(ostream &out, const vector<T> &vec) {
    for (const auto &x : vec) {
        out + x;
    }
    return out;
}

template<typename T>
istream &operator>>(istream &in, vector<T> &vec) {
    for (auto &x : vec) {
        in >> x;
    }
    return in;
}

template<class T>
bool ckmin(T &a, const T &b) { return b < a ? a = b, 1 : 0; }

template<class T>
bool ckmax(T &a, const T &b) { return a < b ? a = b, 1 : 0; }

#ifdef LOCAL

void debug() { cerr << endl; }

template<class T, class... Args>
void debug(const T &t, const Args &... args) {
    cerr << t << " ";
    debug(args...);
}

#define dbg(...) {cerr<<__LINE__<<" [[DEBUG]] ";debug(__VA_ARGS__);};
#else
#define dbg(...) void(0)
#endif
const ll mod = 1e9 + 7;
//const int mod = 998244353;
const ll INF = 1e17 + 6;

inline ll power(ll x, ll y) {
    ll res = 1;
    x = x;
    while (y > 0) {
        if (y & 1)
            res = (res * x);
        y = y >> 1;
        x = (x * x);
    }
    return res;
}

int dx[4] = {0, 1, 0, -1};
int dy[4] = {1, 0, -1, 0};
const int MXN=3e6+5;

void solve() {
   int n,m;
   cin>>n>>m;
   vl h(n);
   cin>>h;
   vl w(m);
   cin>>w;
   vi pref((n+1)/2+2);
   vi suff((n+1)/2+2);
   sort(all(h));
   for(int i=0;i<n-1;i+=2) {
       pref[i / 2+1] += pref[i / 2] + h[i + 1] - h[i];
   }
   for(int i=n-2;i>0;i-=2) {
       suff[i / 2] += suff[i / 2+1] + h[i+1] - h[i];
   }
   ll ans=INF;
   for(auto i:w){
       int pos=get_pos(h,i);
       if(pos&1){
           pos--;
       }
       ans=min(pref[pos/2]+suff[pos/2]+abs(i-h[pos]),ans);
   }
   cout<<ans<<endl;
}

int main() {

    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cout << fixed << setprecision(10);
#ifdef LOCAL
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    int t = 1, tc = 1;
//    cin >> t;
    while (t--) {
        // cout<<"Case #"<<tc<<": " ;
        solve();
        tc++;
    }
#ifdef LOCAL
    cerr << endl << "Time elapsed : " << clock() * 1000.0 / CLOCKS_PER_SEC << " ms" << '\n';
#endif
    return 0;
}
//look if it requires ll

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

#define REP(i,n) for(ll i=0;i<(ll)n;i++)
#define dump(x)  cerr << "Line " << __LINE__ << ": " <<  #x << " = " << (x) << "\n";
#define spa << " " <<
#define fi first
#define se second
#define ALL(a)  (a).begin(),(a).end()
#define ALLR(a)  (a).rbegin(),(a).rend()

using ld = long double;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pdd = pair<ld, ld>;

template<typename T> using V = vector<T>;
template<typename T> using P = pair<T, T>;
template<typename T> vector<T> make_vec(size_t n, T a) { return vector<T>(n, a); }
template<typename... Ts> auto make_vec(size_t n, Ts... ts) { return vector<decltype(make_vec(ts...))>(n, make_vec(ts...)); }
template<class S, class T> ostream& operator << (ostream& os, const pair<S, T> v){os << "(" << v.first << ", " << v.second << ")"; return os;}
template<typename T> ostream& operator<<(ostream &os, const vector<T> &v) { for (auto &e : v) os << e << ' '; return os; }
template<class T> ostream& operator<<(ostream& os, const vector<vector<T>> &v){ for(auto &e : v){os << e << "\n";} return os;}
struct fast_ios { fast_ios(){ cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;

template <class T> void UNIQUE(vector<T> &x) {sort(ALL(x));x.erase(unique(ALL(x)), x.end());}
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
void fail() { cout << -1 << '\n'; exit(0); }
inline int popcount(const int x) { return __builtin_popcount(x); }
inline int popcount(const ll x) { return __builtin_popcountll(x); }
template<typename T> void debug(vector<vector<T>>&v,ll h,ll w){for(ll i=0;i<h;i++)
{cerr<<v[i][0];for(ll j=1;j<w;j++)cerr spa v[i][j];cerr<<"\n";}};
template<typename T> void debug(vector<T>&v,ll n){if(n!=0)cerr<<v[0];
for(ll i=1;i<n;i++)cerr spa v[i];
cerr<<"\n";};

const ll INF = (1ll<<62);
// const ld EPS   = 1e-10;
// const ld PI    = acos(-1.0);
const ll mod = (int)1e9 + 7;
//const ll mod = 998244353;

int main(){

    V<string> S(3);
    REP(i, 3) cin >> S[i];

    V<char> C;
    REP(i, 3){
        REP(j, S[i].size()){
            C.push_back(S[i][j]);
        }
    }

    UNIQUE(C);
    // dump(C)

    if((ll)C.size() > 10){
        cout << "UNSOLVABLE" << endl;
        return 0;
    }
    ll sz = C.size();
    V<ll> c2num(26, -1);
    REP(i, sz) c2num[C[i] - 'a'] = i;

    // dump(sz)

    V<ll> used(10, -1);
    V<ll> vals(sz);
    ll cnt = 0;
    auto dfs = [&](auto self, ll now) -> void{
        if(now == sz){
            cnt++;
            // dump(vals)

            if(vals[c2num[S[0][0]-'a']] != 0 and vals[c2num[S[1][0]-'a']] != 0 and vals[c2num[S[2][0]-'a']] != 0){
                V<ll> X(3, 0);
                REP(i, 3){
                    REP(j, S[i].size()){
                        X[i] *= 10;
                        ll v = vals[c2num[S[i][j]-'a']];
                        X[i] += v;
                    }
                }

                if(X[0] + X[1] == X[2]){
                    REP(i, 3){
                        cout << X[i] << endl;
                    }
                    exit(0);
                }
            }

        }else{
            REP(i, 10){
                if(used[i] == -1){
                    used[i] = 1;
                    vals[now] = i;
                    self(self, now+1);
                    used[i] = -1;
                    vals[now] = -1;
                }
            }
        }
        return;
    };

    dfs(dfs, 0);

    dump(cnt)

    cout << "UNSOLVABLE" << endl;

    return 0;
}


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

void solve(){
    int a,b;
    cin>>a>>b;
    cout<<(a/b);
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    int T=1;
  //  cin>>T;
    while(T--){
        solve();
    }
}

// Sky's the limit :)
#include <bits/stdc++.h>
using namespace std;
#define int long long

/*
    w / a
*/

void run_case() {
    int a, b;
    cin >> a >> b;

    vector<int> primes = {
        2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71
    };

    int n = b - a + 1;
    vector<int> bit(n, 0);
    for (int i = a; i <= b; i++) {
        for (int j = 0; j < primes.size(); j++) {
            if (i % primes[j] == 0) {
                bit[i - a] |= (1LL << j);
            }
        }
    }

    int N = (1 << 20);
    vector<vector<int>> dp(n + 1, vector<int>(N, 0));
    dp[0][0] = 1;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < N; j++) {
            dp[i + 1][j] += dp[i][j];
            if ((j & bit[i]) == 0) {
                dp[i + 1][j | bit[i]] += dp[i][j];
            }
        }
    }

    int res = 0;
    for (int j = 0; j < N; j++) {
        res += dp[n][j];
    }
    cout << res << '\n';
}

signed main() {
    ios_base::sync_with_stdio(false); cin.tie(nullptr);

    int T = 1;
    // cin >> T;
    for (int t = 1; t <= T; t++) {
        // cout << "Case #" << t << ": ";
        run_case();
    }

    return 0;
}


#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) (x).begin(), (x).end()
#define ll long long

using namespace std;
int main() {
  int n, x;
  cin >> n >> x;

  int a[n];
  REP(i, n) cin >> a[i];

  vector<int> ans;
  REP(i, n) {
    if (a[i] == x) {
      continue;
    } else {
      ans.push_back(a[i]);
    }
  }

  REP(i, ans.size()) {
    if (ans.size() == i) {
      cout << ans[i] << endl;
    } else {
      cout << ans[i];
      cout << " ";
    }
  }
}

#include <bits/stdc++.h>
//#include <atcoder/all>
#define rep(i, n) for (int i = 0; i < (n); i++)
using ll = long long;
using namespace std;
//using namespace atcoder;
const int mod = 1000000007;
int main() {
    int a,b;cin>>a>>b;
    int X=(a+b)/2;
    int Y=(a-b)/2;
    cout<<X<<" "<<Y<<endl;
}


#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <iomanip>
#include <stack>
#include <queue>
#include <numeric>
#include <map>
#include <unordered_map>
#include <set>
#include <fstream>
#include <chrono>
#include <random>
#include <bitset>
//#include <atcoder/all>
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define sz(x) ((int)(x).size())
#define pb push_back
using ll = long long;
using namespace std;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
ll gcd(ll a, ll b) {return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) {return a/gcd(a,b)*b;}

int main(){
  int N; cin >> N;
  ll X; cin >> X;
  vector<ll> A(N); rep(i,N) cin >> A[i];
  reverse(all(A));
  //rep(i,N) cout << A[i] << " ";
  //cout << endl;
  vector<map<ll,ll>> dp(N+1);
  dp[0][X]=1;
  for(int i=1;i<=N;i++){
    for(auto m:dp[i-1]){
      ll x = m.first;
      //cout << i <<" " << x << " " << m.second << endl;
      if(x>=0){
        ll t = (x)/A[i-1];
        //cout << t << endl;
        if(!(i>1&&t>=A[i-2]/A[i-1])){
          if(abs(x-A[i-1]*t)<A[i-1]){
            dp[i][x-A[i-1]*t]+=m.second;
          }
        }
        if(!(i>1&&t+1>=A[i-2]/A[i-1])){
          if(abs(x-A[i-1]*(t+1))<A[i-1]){
            dp[i][x-A[i-1]*(t+1)]+=m.second;
          }
        }
      }
      else{
        ll t=(-x)/A[i-1];
        //cout << t << endl;
        if(!(i>1&&t>=A[i-2]/A[i-1])){
          if(abs(x+A[i-1]*t)<A[i-1]){
            dp[i][x+A[i-1]*t]+=m.second;
          }
        }

        if(!(i>1&&t+1>=A[i-2]/A[i-1])){
          if(abs(x+A[i-1]*(t+1))<A[i-1]){
            dp[i][x+A[i-1]*(t+1)]+=m.second;
          }
        }
      }
    }
  }
  cout << dp[N][0] << endl;;
  return 0;
}

#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
using ll = long long;
using p = pair<int,int>;
using Graph = vector<vector<int>>;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
int main(int argc, const char * argv[]) {
    ios::sync_with_stdio(false);

    int n;
    cin>>n;
    vector<ll>a(n);
    rep(i,n)cin>>a[i];
    ll ans=0;
    ll sum=0;
    vector<ll>b(n+1);
    b[0]=0;
    for(int i=1;i<n+1;i++){
        b[i]=b[i-1]+a[i-1];
    }
    int max_point=0;
    for(int i=0;i<n;i++){
        chmax(ans,sum+b[max_point]);
        if(sum+b[max_point]<sum+b[i+1]){
            max_point=i+1;
        }
        sum+=b[i+1];
    }
    chmax(ans,sum);
    cout<<ans<<endl;

    return 0;
}


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

using ll = long long;
using ld = long double;
const ld eps = 1e-8;
#define len(x) ((int)x.size())
#define rep(i,n) for (int i = -1; ++ i < n; )
#define rep1(i,n) for (int i = 0; i ++ < n; )
#define be(a) (a).begin(), (a).end()
// #define constexpr(...) (__VA_ARGS__)
// DEBUGING TEMPLETE ////////////////////////////////////////////////////////////////////////{{{
#define db(val) "["#val" = "<<(val)<<"] "
#define CONCAT_(x, y) x##y
#define CONCAT(x, y) CONCAT_(x, y)
#ifdef LOCAL_DEBUG
#   define clog cerr << flush << string(__db_level * 2, ' ')
#   define DB() debug_block CONCAT(dbbl, __LINE__)
    int __db_level = 0;
    struct debug_block {
        debug_block() { clog << "{" << endl; ++__db_level; }
        ~debug_block() { --__db_level; clog << "}" << endl; }
    };
#else
#   define clog if (0) cerr
#   define DB(...)
#endif

template<class U, class V> ostream& operator<<(ostream& out, const pair<U, V>& p) {
    return out << "(" << p.first << ", " << p.second << ")";
}

template<size_t i, class T> ostream& print_tuple_utils(ostream& out, const T& tup) {
    if constexpr(i == tuple_size<T>::value) return out << ")";
    else return print_tuple_utils<i + 1, T>(out << (i ? ", " : "(") << get<i>(tup), tup);
}

template<class ...U> ostream& operator<<(ostream& out, const tuple<U...>& tup) {
    return print_tuple_utils<0, tuple<U...>>(out, tup);
}

template<class Con, class = decltype(begin(declval<Con>()))>
typename enable_if<!is_same<Con, string>::value, ostream&>::type
operator<<(ostream& out, const Con& container) {
    out << "{";
    for (auto it = container.begin(); it != container.end(); ++it)
        out << (it == container.begin() ? "" : ", ") << *it;
    return out << "}";
}
// ACTUAL SOLUTION START HERE ////////////////////////////////////////////////////////////////}}}

int main() {
#ifdef LOCAL
    freopen("main.inp", "r", stdin);
    freopen("main.out", "w", stdout);
    freopen(".log", "w", stderr);
#endif
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    ll m, h; cin >> m >> h;
    if (h % m == 0) cout << "Yes";
    else cout << "No";

    return 0;
}

// vim: foldmethod=marker

#include <iostream>

int main()
{
    int m, h;
    std::cin >> m >> h;
    if (h % m == 0) {
        std::cout << "Yes" << std::endl;
    } else {
        std::cout << "No" << std::endl;
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pii pair<int, int>
#define ull unsigned ll
#define f first
#define s second
#define ALL(x) x.begin(),x.end()
#define SZ(x) (int)x.size()
#define SQ(x) (x)*(x)
#define MN(a,b) a = min(a,(__typeof__(a))(b))
#define MX(a,b) a = max(a,(__typeof__(a))(b))
#define pb push_back
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#ifdef BALBIT
#define IOS()
#define bug(...) fprintf(stderr,"#%d (%s) = ",__LINE__,#__VA_ARGS__),_do(__VA_ARGS__);
template<typename T> void _do(T &&x){cerr<<x<<endl;}
template<typename T, typename ...S> void _do(T &&x, S &&...y){cerr<<x<<", ";_do(y...);}
#else
#define IOS() ios_base::sync_with_stdio(0);cin.tie(0);
#define endl '\n'
#define bug(...)
#endif

const int iinf = 1e9+10;
const ll inf = 1ll<<60;
const ll mod = 998244353;

void GG(){cout<<"0\n"; exit(0);}

ll mpow(ll a, ll n, ll mo = mod){ // a^n % mod
    ll re=1;
    while (n>0){
        if (n&1) re = re*a %mo;
        a = a*a %mo;
        n>>=1;
    }
    return re;
}

ll inv (ll b, ll mo = mod){
    if (b==1) return b;
    return (mo-mo/b) * inv(mo%b,mo) % mo;
}

const int maxn = 1e6+5;

ll dp[3003][6003];
ll sig[6006];

signed main(){
    IOS();

    int N,K; cin>>N>>K;
    dp[0][0] = 1;
    sig[0] += 1;
    for (int n = 1; n<=N; ++n) {
        for (int k = n; k>=0; --k) {
//            for (int j = 0; j<=k; ++j) {
//                dp[n][k] += dp[n-j][2*(k-j)];
//                if (dp[n][k] >= mod) dp[n][k] -= mod;
//            }
            dp[n][k] = sig[2*n - 2*k];
            if (2*n>=k) {
                sig[2*n-k] += dp[n][k];
                if (sig[2*n-k]>=mod) sig[2*n-k] -= mod;
            }
        }
    }
//    for (int j = 0; j<100; ++j) {
//        bug(sig[K-j]);
//    }
    bug(sig[2*N - 2*K]);
    bug(2*N-2*K);
    cout<<dp[N][K]<<endl;

}

/*
	Normie's Template v2.0
*/

// Standard library in one include.
#include <bits/stdc++.h>
using namespace std;

// ordered_set library.
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_set(el) tree<el,null_type,less<el>,rb_tree_tag,tree_order_statistics_node_update>

// AtCoder library. (Comment out these two lines if you're not submitting in AtCoder.) (Or if you want to use it in other judges, run expander.py first.)
//#include <atcoder/all>
//using namespace atcoder;

//Pragmas (Comment out these three lines if you're submitting in szkopul.)
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

//File I/O.
#define FILE_IN "cseq.inp"
#define FILE_OUT "cseq.out"
#define ofile freopen(FILE_IN,"r",stdin);freopen(FILE_OUT,"w",stdout)

//Fast I/O.
#define fio ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define nfio cin.tie(0);cout.tie(0)
#define endl "\n"

//Order checking.
#define ord(a,b,c) ((a>=b)and(b>=c))

//min/max redefines, so i dont have to resolve annoying compile errors.
#define min(a,b) (((a)<(b))?(a):(b))
#define max(a,b) (((a)>(b))?(a):(b))

//Constants.
#define MOD (ll(998244353))
#define MAX 300001
#define mag 320

//Pairs and 3-pairs.
#define p1 first
#define p2 second.first
#define p3 second.second
#define fi first
#define se second
#define pii(element_type) pair<element_type,element_type>
#define piii(element_type) pair<element_type,pii(element_type)>

//Quick power of 2.
#define pow2(x) (ll(1)<<x)

//Short for-loops.
#define ff(i,__,___) for(int i=__;i<=___;i++)
#define rr(i,__,___) for(int i=__;i>=___;i--)

//Typedefs.
#define bi BigInt
typedef long long ll;
typedef long double ld;
typedef short sh;
//---------END-------//
ll dp[3001][3001];
ll n,m,i,j,k,t,t1,u,v,a,b;
int main()
{
	cin>>n>>m;
	dp[0][0]=1;
	for (i=1;i<=n;i++) for (j=1;j<=i;j++)
	{
		k=j;
		while(true)
		{
			dp[i][j]+=dp[i-1][k-1];
			dp[i][j]%=MOD;
			k*=2;
			if (k>i) break;
		}
	}
	cout<<dp[n][m];
}


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

template<typename T, typename U>
using vp = vector<pair<T,U>>;
template<typename T>
using pque = priority_queue<T>;
template<typename T>
using lpque = priority_queue<T,vector<T>,greater<T>>;

using ll = long long;
using pint = pair<int,int>;
using pll = pair<ll,ll>;
using pil = pair<int,ll>;
using pli = pair<ll,int>;
using vint = vector<int>;
using vll = vector<ll>;
using qint = queue<int>;
using pqint = pque<int>;
using qll = queue<ll>;
using pqll = pque<ll>;

constexpr double PI = 3.141592653589793;
constexpr int INTINF = (1<<30)-1;
constexpr ll LLINF = (1LL<<62)-1;
constexpr int MPRIME = 1000000007;
constexpr int MPRIME9 = 998244353;
constexpr ll MMPRIME = (1LL<<61)-1;
constexpr char newl = '\n';

#define len length()
#define pushb push_back
#define fi first
#define se second

#define all(name) name.begin(),name.end()
#define rall(name) name.rbegin(),name.rend()
#define gsort(vbeg,vend) sort(vbeg,vend,greater<>())

template<typename T>
struct matrix{
private:
	vector<vector<T>> mat;

public:
	matrix() : matrix(0,0) {}
	matrix(int h, int w) { resize(h,w); }
	matrix(int h, int w, T init) { resize(h,w,init); }

	void resize(int h, int w) {
		mat=vector<vector<T>>(h,vector<T>(w));
	}
	void resize(int h, int w, T init) {
		mat=vector<vector<T>>(h,vector<T>(w,init));
	};

	void in() {
		for(int i=0; i<mat.size(); i++) for(int j=0; j<mat[i].size(); j++) {
			cin>>mat[i][j];
		}
	}

	void out() {
		for(int i=0; i<mat.size(); i++) {
			int wm=mat[i].size();
			for(int j=0; j<wm; j++) {
				cout<<mat[i][j]<<(wm==j+1 ? '\n' : ' ');
			}
		}
		cout<<flush;
	}

	inline vector<T> &operator[](int idx) {
		assert(0<=idx && idx<mat.size());
		return mat[idx];
	}
};

template<class T>
inline bool chmin(T& a, T b) {
	if (a > b) {
		a = b;
		return true;
	}
	return false;
}

template<class T>
inline bool chmax(T& a, T b) {
	if (a < b) {
		a = b;
		return true;
	}
	return false;
}

template<class T>
inline void init(T& v) {
	for(auto &a: v) cin>>a;
}
template<class T, class U>
inline void init(vector<pair<T,U>>& v) {
	for(auto &a: v) cin>>a.first>>a.second;
}
template<class T, class N>
inline void init(T& v, N n) {
	v.resize(n);
	for(auto &a: v) cin>>a;
}
template<class T, class U, class N>
inline void init(vector<pair<T,U>>& v, N n) {
	v.resize(n);
	for(auto &a: v) cin>>a.first>>a.second;
}

template<class T>
inline void out(T a) {
	cout<<a<<endl;
}
template<class T, class... U>
inline void out(T a, U... alist) {
	cout<<a<<" ";
	out(forward<U>(alist)...);
}

template<class N>
void resiz(N n) {
	//empty
}
template<class N, class T, class... U>
void resiz(N n, T&& hd, U&&... tl) {
	hd.resize(n);
	resiz(n,forward<U>(tl)...);
}

long long binpow(long long a, long long ex, long long p=MMPRIME) {
	long long res = 1;
	while(ex > 0) {
		if(ex & 1) (res*=a) %= p;
		ex>>=1;
		(a*=a) %= p;
	}
	return res;
}

ll r1,c1,r2,c2;

void input() {
	cin>>r1>>c1>>r2>>c2;
}

void solve() {
	if(r1==r2 && c1==c2) {
		cout<<0<<newl;
		return;
	}
	if(r1+c1==r2+c2 || r1-c1==r2-c2 || abs(r1-r2)+abs(c1-c2)<=3) {
		cout<<1<<newl;
		return;
	}
	if((r1+c1)%2==(r2+c2)%2 || abs(r1-r2)+abs(c1-c2)<=6 || abs(r1+c1-r2-c2)<=3 || abs(r1-c1-r2+c2)<=3) {
		cout<<2<<newl;
		return;
	}
	cout<<3<<newl;
}

int main() {
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout<<fixed<<setprecision(15);
	int t=1;
	while(t--) {
		input();
		solve();
	}
}

#include <bits/stdc++.h>
//#define int ll
using namespace std;
typedef long long ll;
const int maxn=1e6+5;
const int mod=998244353;

void solve() {
    int a,b,c,d;
    int sum=0;
    cin>>a>>b>>c>>d;
    int x=abs(c-a);
    int y=abs(d-b);
    if(x==0&&y==0) {
        cout<<"0\n";
        return;
    }
    if(x==y||x+y<=3) {
        cout<<"1\n";
        return;
    }
    if(abs(x+y)%2==0||x+y<=6||abs(x-y)<=3) {
        cout<<"2\n";
        return;
    }
    cout<<"3\n";
}

signed main() {
    //ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
//    freopen("1.in","r",stdin);
    int _ = 1;
    //cin >> _;
    //init();
    while (_--) {
        solve();
    }
    return 0;
}


//
//  header_useful.h
//  c++_acm
//
//  Created by 李弘辰 on 2019/7/23.
//  Copyright  2019 李弘辰. All rights reserved.
//

#include <stdio.h>
#include <stdarg.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <time.h>
#include <limits.h>
#include <vector>
#include <list>
#include <set>
#include <utility> // pair
#include <map>
#include <iostream>
#include <sstream>
#include <algorithm> // sort
#include <functional>
#include <string>
#include <stack>
#include <queue>
#include <fstream>
#include <bitset>

//#include <unordered_map>
//#include <unordered_set>

using namespace std;

#define ll long long
#define lll __int128
#define uchar unsigned char
#define ushort unsigned short
#define uint unsigned int
#define ulong unsigned long
#define ull unsigned long long

#define INT_INF 0x7fffffff

#define pi acos(-1)

#define mem(a,b) memset(a,b,sizeof(a))
#define memn(a,b,c,n) memset(a,b,sizeof(c)*(n))
#define fre(a) freopen(a,"r",stdin)

#define cio ios::sync_with_stdio(false); // Do not use it with "scanf" and other c input!
#define pb push_back
#define mpair make_pair
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define pre(i,a,b) for(int i=a;i>=b;i--)
#define REP(i,a,b) for(int i=a;i<b;i++)

#define repl(i,a,b) for(ll i=a;i<=b;i++)
#define prel(i,a,b) for(ll i=a;i>=b;i--)

#define reada(a,s,n) rep(i,s,n)scanf("%d",a + i);
#define READa(a,s,n) REP(i,s,n)scanf("%d",a + i);

#define readall(a,s,n) rep(i,s,n)scanf("%lld",a + i);
#define READall(a,s,n) REP(i,s,n)scanf("%lld",a + i);

//template <typename _Tp> inline void read(_Tp&x) {
//    char ch;bool flag=0;x=0;
//    ch=getchar();
//    while(!isdigit(ch)){if(ch=='-')flag=1;ch=getchar();}
//    while(isdigit(ch))x=x*10+ch-'0',ch=getchar();
//    if(flag)x=-x;
//}
//inline void print_lll(lll x) {
//    if(x<0) {x=-x;putchar('-');}
//    if(x>9) print_lll(x/10);
//    putchar(x%10+'0');
//}

//#define _T_(T) int T;scanf("%d",&T);while(T--)
//#define __T _T_(TTESTCASES)
//#define _E_(T) while(~T)
#define __T int TT;scanf("%d",&TT);for (int T = 1;T <= TT;T ++)

#define _C(a) cout << a << endl;

#define dsci(a) int a;scanf("%d",&a)
#define dscii(a,b) int a,b;scanf("%d%d",&a,&b)
#define dsciii(a,b,c) int a,b,c;scanf("%d%d%d",&a,&b,&c)
#define dscl(a) ll a;scanf("%lld",&a)
#define dscll(a,b) ll a,b;scanf("%lld%lld",&a,&b)
#define dsclll(a,b,c) ll a,b,c;scanf("%lld%lld%lld",&a,&b,&c)
#define dscd(a) double a;scanf("%lf",&a)
#define dscdd(a,b) double a,b;scanf("%lf%lf",&a,&b)
#define dscddd(a,b,c) double a,b,c;scanf("%lf%lf%lf",&a,&b,&c)

#define sci(a) scanf("%d",&a)
#define scii(a,b) scanf("%d%d",&a,&b)
#define sciii(a,b,c) scanf("%d%d%d",&a,&b,&c)
#define scl(a) scanf("%lld",&a)
#define scll(a,b) scanf("%lld%lld",&a,&b)
#define sclll(a,b,c) scanf("%lld%lld%lld",&a,&b,&c)
#define scd(a) scanf("%lf",&a)
#define scdd(a,b) scanf("%lf%lf",&a,&b)
#define scddd(a,b,c) scanf("%lf%lf%lf",&a,&b,&c)

#define lowbit(x) ((x)&(-(x)))

#define Tprint(a,s,e) REP(i,s,e){if(i!=s)printf(" ");printf("%lld",a[i]);}

#define endl '\n'

#define itn int
#define iny int
#define nit int
#define inr int
#define mian main
#define iman main
#define mina main
#define mian main
#define ednl endl
#define fro for
#define fir for
#define reutrn return
#define retunr return
#define reutnr return
#define re0 return 0
#define re1 return 1

/* header_useful_h */

void solve(){
    string a; cin >> a;
    int len = a.length();
    if(len == 1){
        cout << 0 << endl;
        return;
    }
    int l = stoi(a.substr(0, len / 2));
    int r = stoi(a.substr(len / 2));
    if(l == r) cout << l << endl;
    else if(len & 1){
        for(int i = 0; i < len / 2; i ++) cout << 9; cout << endl;
    }else{
        if(l < r) cout << l << endl;
        else cout << l - 1 << endl;
    }
}
int main()
{
    solve();
}

#include <bits/stdc++.h>
using namespace std;
// #include <atcoder/all>
// using namespace atcoder;
#define rep(i,n) for (int i = 0; i < (n); ++i)
using ll = long long;
using vl = vector<ll>;
using vvl = vector<vl>;
using P = pair<ll,ll>;
#define pb push_back

int main(){
  vvl tate(29, vl(30,5000));
  vvl yoko(30, vl(29,5000));
  rep(_,1000){
    int a, b, ato, bto;
    cin >> a >> b >> ato >> bto;
    int ma = a;
    int mb = b;
    string ans;
    while(a != ato || b != bto){
      if (a == ato){
        if (b < bto){
          b++;
          ans.pb('R'); continue; // continueの貼り付けを忘れると
        } else { // バグる ato btoが連続するからです
          b--; // 全てに張り付けておく必要があるので
          ans.pb('L'); continue;
        }
      }
      if (b == bto){
        if (a < ato){
          a++;
          ans.pb('D'); continue;
        } else {
          a--;
          ans.pb('U'); continue;
        }
      }
      if (a < ato && b < bto){
        // 下 右
        if (tate[a][b] < yoko[a][b]){
          a++; // 縦移動優先
          ans.pb('D'); continue;
        } else {
          b++;
          ans.pb('R'); continue;
        }
      }
      if (a < ato && b > bto){
        // 下 左
        if (tate[a][b] < yoko[a][b-1]){
          a++; // 縦移動優先
          ans.pb('D'); continue;
        } else {
          b--;
          ans.pb('L'); continue;
        }
      }
      if (a > ato && b < bto){
        // 上 右
        if (tate[a-1][b] < yoko[a][b]){
          a--; // 縦移動優先
          ans.pb('U'); continue;
        } else {
          b++;
          ans.pb('R'); continue;
        }
      }
      if (a > ato && b > bto){
        // 上 左 ここから続き
        if (tate[a-1][b] < yoko[a][b-1]){
          a--; // 縦移動優先
          ans.pb('U'); continue;
        } else {
          b--;
          ans.pb('L'); continue;
        }
      }
    }
    cout << ans << endl; // flushを炊く
    ll score;
    cin >> score;
    score /= ans.size(); // 通った数で割り一歩当たりのコスト計算
    ll change = (5000 - score) / ans.size();
    rep(i,ans.size()){
      if (ans[i] == 'U'){
        tate[ma-1][mb] += change;
        ma--;
      }
      if (ans[i] == 'D'){
        tate[ma][mb] += change;
        ma++;
      }
      if (ans[i] == 'L'){
        yoko[ma][mb-1] += change;
        mb--;
      }
      if (ans[i] == 'R'){
        yoko[ma][mb] += change;
        mb++;
      }
    }
    // for(auto x : tate){ // コスト計算debug
    //   for(auto y : x){
    //     cout << y << " ";
    //   } cout << endl;
    // }
    // for(auto x : yoko){
    //   for(auto y : x){
    //     cout << y << " ";
    //   } cout << endl;
    // }
  }
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define rep2(i, s, n) for (ll i = (s); i < (ll)(n); i++)
const ll MAX = 1001001;
const ll MOD = 998244353;
const double pi = 2.0 * asin(1.0);
ll dx[4] = {1, 0, -1, 0};
ll dy[4] = {0, 1, 0, -1};
ll modpow(ll a, ll n, ll mod)
{
    ll res = 1;
    while (n > 0)
    {
        if (n & 1)
            res = res * a % mod;
        a = a % mod * (a % mod) % mod;
        n >>= 1;
    }
    return res;
}
int main()
{
    ll n, m;
    cin >> n >> m;
    vector<string> s(n);
    rep(i, n)
    {
        cin >> s[i];
    }
    vector<ll> d(n + m);
    vector<ll> d2(n + m);
    vector<ll> d3(n + m);
    rep(i, n)
    {
        rep(j, m)
        {
            if (s[i][j] == 'R')
            {
                d[i + j]++;
            }
            else if (s[i][j] == 'B')
            {
                d2[i + j]++;
            }
            else
            {
                d3[i + j]++;
            }
        }
    }
    ll co = 0;
    rep(i, n + m)
    {
        if (d[i] > 0 && d2[i] > 0)
        {
            cout << 0 << endl;
            return 0;
        }
        if (d3[i] > 0 && d[i] == 0 && d2[i] == 0)
        {
            co++;
        }
    }
    ll ans = modpow(2, co, MOD);
    cout << ans << endl;
}


#include <bits/stdc++.h>
using namespace std;
using ll = long long;
constexpr long long MOD = 1000000007;
constexpr long long MOD2 = 998244353;
constexpr long long INF = 1LL << 60;
const long double PI = acosl(-1.0);
constexpr long double EPS = 1e-11;
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
void factorization(long long n,map<long long ,long long>& mp){
    for(long long i=2;i*i<=n;i++){
        while(n%i==0){
            mp[i]++;
            n /= i;
        }
     }
     if(!(n == 1)) mp[n]++;
}
void divisor(ll n, map<ll,ll>& ret) {
    for (ll i = 1; i * i <= n; i++) {
        if (n % i == 0) {
            ret[i]++;
            if (i * i != n) ret[n / i]++;
        }
    }
}
int main(){
ll n;
cin >> n;
map<ll, ll> mp;
ll ans = 0;
divisor(2 * n, mp);
for(auto i:mp){
    ll x = i.first;
    ll y = 2 * n / i.first;
    if (x < y) swap(x, y);
    if ((x - y - 1) % 2 == 0 and (x + y - 1) % 2 == 0) ans++;
}
cout << ans << endl;
}

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

long long f[110],n;

int main(){
	scanf("%lld",&n);
	f[0]=1;f[1]=1;
	int t=1;
	while(f[t-1]+f[t]<=n) t++,f[t]=f[t-1]+f[t-2];
	long long tmp=n;
	int ans=t;
	for(int i=t;i>=1;i--) if(tmp>=f[i]) tmp-=f[i],ans++;
	printf("%d\n",ans);
	for(int i=t;i>=1;i--){
		if(n>=f[i]) printf("%d\n",(i&1)+1),n-=f[i];
		printf("%d\n",((i-1)&1)+3);
	}
}


#include   <bits/stdc++.h>
#include   <ext/pb_ds/assoc_container.hpp>
#include   <stdio.h>
#include   <stdlib.h>
#include   <iomanip>
#define    FAST       ios::sync_with_stdio(0);cin.tie(0);
#define    pb         push_back
#define    mp         make_pair
#define    ff         first
#define    ss         second
#define    el         "\n"
#define    ll         long long
#define    ld         long double
#define    pii        pair<ii,ii>
#define    pll        pair<ll,ll>
#define    vcii       vector<ii>
#define    vcll       vector<ll>
#define    vcd        vector<double>
#define    vcs        vector<string>
#define    vpii       vector<pii>
#define    vpll       vector<pll>
#define    stl_sort(v)   sort(v.begin(),v.end())
#define    stl_rev(v)    reverse(v.begin(),v.end())
#define    rep(i,x,y) for(ll i=x;i<y;i++)
#define    scll(x)    scanf("%lld",&x)
#define    pfll(x)    printf("%lld",x)
#define    scd(x)     scanf("%llf",&x)
#define    pfd(x)     prinf("%0.5llf\n",x)
using namespace std;

ll bigmod(ll a,ll b,ll m)
{
	if(b==0)return 1%m;
	ll x=bigmod(a,b/2,m);
	x=(x*x)%m;
	if(b%2==1)x=(x*a)%m;

	return x;
}

int main()
{
    /* freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout); */

  //FAST

    ll a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z,sum1,sum2;
    ld A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z,SUM1,SUM2;

      cin>>n>>m;
		cout<<((bigmod(10,n,m*m)-bigmod(10,n,m))/m)%m<<el;
    return 0;
}

#include <bits/stdc++.h>

using namespace std;

template<typename S, typename T>
ostream& operator<<(ostream& out, const pair<S, T> p) {
    out << "(" << p.first << "," << p.second << ")";
    return out;
}

template<typename T>
ostream& operator<<(ostream& out, const vector<T>& v) {
    for (auto a: v)
        out << a << " ";
    return out;
}

template<typename T>
ostream& operator<<(ostream& out, const set<T>& S) {
    for (auto a: S)
        cout << a << " ";
    return out;
}

template<typename T>
ostream& operator<<(ostream& out, const multiset<T>& S) {
    for (auto a: S)
        cout << a << " ";
    return out;
}

template<typename S, typename T>
ostream& operator<<(ostream& out, const map<S, T>& M) {
    for (auto m: M)
        cout << "(" << m.first << "->" << m.second << ") ";
    return out;
}

template<typename S, typename T>
pair<S, T> operator+(pair<S, T> a, pair<S, T> b) {
    return make_pair(a.first + b.first, a.second + b.second);
}

template<typename S, typename T>
pair<S, T> operator-(pair<S, T> a, pair<S, T> b) {
    return make_pair(a.first - b.first, a.second - b.second);
}

long long get_value(vector<long long>& A, long long x) {
    long long ans = x;
    auto first = A.begin();
    auto last = upper_bound(A.begin(), A.end(), x);
    x -= (last - first);
    return x;
}

long long solve(vector<long long>& A, long long kth) {
    long long left = 1;
    long long right = 1;
    if (get_value(A, left) >= kth) {
        return left;
    }
    while (get_value(A, right) < kth) {
        right <<= 1;
    }
    while (right - left > 1) {
        long long mid = (left  + right) / 2;
        if (get_value(A, mid) >= kth) {
            right = mid;
        } else {
            left = mid;
        }
    }
    return right;
}

int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    int n, q;
    vector<long long> A;
    cin >> n >> q;
    A.resize(n);
    for (int i = 0; i < n; i++) {
        cin >> A[i];
    }
    sort(A.begin(), A.end());
    while (q--) {
        long long k;
        cin >> k;
        cout <<  solve(A, k) << endl;
    }
    return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <stack>
#include <numeric>
#include <bitset>
#include <math.h>
#include <iomanip>
#include <sstream>
#include <cstdlib>
#include <stdio.h>

using namespace std;
typedef long long ll;

//マクロ
//forループ関係
//引数は、(ループ内変数,動く範囲)か(ループ内変数,始めの数,終わりの数)、のどちらか
//Dがついてないものはループ変数は1ずつインクリメントされ、Dがついてるものはループ変数は1ずつデクリメントされる
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
//xにはvectorなどのコンテナ
#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x)) //最大値を求める
#define MIN(x) *min_element(ALL(x)) //最小値を求める
//定数
#define INF 1000000000000 //10^12:極めて大きい値,∞
#define MOD 1000000007 //10^9+7:合同式の法
#define MAXR 100000 //10^5:配列の最大のrange(素数列挙などで使用)
#define PI 3.14159265359 //πの値
//略記
#define PB push_back //vectorヘの挿入
#define MP make_pair //pairのコンストラクタ
#define F first //pairの一つ目の要素
#define S second //pairの二つ目の要素
#define C(x) cout << x << endl //テスト出力

//DP処理用
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

//関数
//nCkの計算の関数(呼び出しは[cbn])
ll cbn(ll n, ll k) {
    ll r = 1;
    for (ll d = 1; d <= k; ++d) {
        r *= n--;
        r /= d;
    }
    return r;
}
// a^n mod を計算する
ll powmod(ll a, ll n) {
    ll res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % MOD;
        a = a * a % MOD;
        n >>= 1;
    }
    return res;
}
//２つの最大公約数
int gcb(int a, int b){
    if(a < b){
        int x = a;
        a = b;
        b = x;
    }
    int amari = a % b;
    if(amari == 0) return b;

    return gcb(b, amari);
}
//３つの最大公約数
int gcb_3(int a, int b, int c){
    return gcb(gcb(a, b), c);
}

/*map<Keyの型, Valueの型> 変数名;
queue<型> 変数名;
priority_queue<型> 変数名;
priority_queue<型, vector<型>, greater<型>> 変数名;
vector<vector<要素の型>> 変数名(要素数1, vector<要素の型>(要素数2, 初期値))
sort(変数名.begin(), 変数名.end());*/

/*-----------------------------ここから-----------------------------*/

int main() {
cin.tie(0);
ios::sync_with_stdio(false);
  ll a,b,c;
  cin>>a>>b>>c;
  cout<<a-b+c;
}

#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>

#define ordered_set tree<int, null_type, less<int >,rb_tree_tag, tree_order_statistics_node_update>
using namespace __gnu_pbds;
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#define ll long long
#define ld long double
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define vii vector<int>
#define pii pair<ll,ll>
#define vll vector<ll>
#define clr(v, d) memset(v,d,sizeof(v))
using namespace std;
const int N = 2e5 + 500, mod = 1e9 + 7;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);

    int x[3];
    cin>>x[0]>>x[1]>>x[2];
    sort(x,x+3);
    cout<<x[2]+x[1]<<"\n";

    return 0;
}