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

void solveOne()
{
    vector<string> strings(3);
    for(int i = 0; i < 3; i++)
        cin >> strings[i];

    set<char> letters;

    for(int i = 0; i < 3; i++)
    {
        for(int j = 0; j < strings[i].length(); j++)
        {
            letters.insert(strings[i][j]);
        }
    }

    if(letters.size() > 10)
    {
        cout << "UNSOLVABLE\n";
        return;
    }

    // translate to first 10 digits in alphabet
    char nc = '0';
    for(char c : letters)
    {
        for(int i = 0; i < 3; i++)
        {
            replace(strings[i].begin(), strings[i].end(), c, nc);
        }
        nc++;
    }

    int n = letters.size();
    vector<int> values(n);

    vector<int> numbers(10);
    for(int i = 0; i < 10; i++)
        numbers[i] = i;

    vector<string> resultstrings(3);
    for(int i = 0; i < 3; i++)
        resultstrings[i] = strings[i];

    do
    {
        for(int i = 0; i < n; i++)
        {
            values[i] = numbers[i];
        }

        for(int i = 0; i < 3; i++)
        {
            for(int j = 0; j < strings[i].size(); j++)
            {
                resultstrings[i][j] = '0' + values[strings[i][j] - '0'];
            }
        }

        bool flag = true;
        for(int i = 0; i < 3; i++)
        {
            if(resultstrings[i][0] == '0')
                flag = false;
        }

        if(!flag)
            continue;

        if(stoll(resultstrings[0]) + stoll(resultstrings[1]) == stoll(resultstrings[2]))
        {
            cout << resultstrings[0] << '\n';
            cout << resultstrings[1] << '\n';
            cout << resultstrings[2] << '\n';
            return;
        }

    } while(next_permutation(numbers.begin(), numbers.end()));

    cout << "UNSOLVABLE\n";
}

void setupIo()
{
    std::ios::sync_with_stdio(false);
    cin.tie(0);

    #ifndef ONLINE_JUDGE

    // For getting input from input.txt file
    freopen("input.txt", "r", stdin);

    // Printing the Output to output.txt file
    freopen("output.txt", "w", stdout);

    #endif
}

int main()
{
    setupIo();

    int tc;
    //cin >> tc;
    tc = 1;
    while(tc--)
        solveOne();

    return 0;
}

/*
  Author     : MatsuTaku
  Date         : 03/21/21
  Certificate:
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAAAgQDF9T447OEo8XSQ6O1AznN5tKC8mzvYc4Zs3+oOKfMqgLXfOwQnpfcoxKs4MAP1eICBD13PkcIezJ9IlV6nKQZKs1BQmvjSXJ+zKK8YCKvAueNPuNO0Bim43IBaNHNFWcMvcmUvHgRb6hUSO0V8I7OsjiFo20KDBj3gAznu9tir0Q== CompetitiveProgrammingCertification:tkm.matsumoto@gmail.com
*/

#include <bits/stdc++.h>
using namespace std;
#include <x86intrin.h>
#define REP(i, f, n)      for (auto i = (f), i##_len = (n); i < i##_len; i++)
#define rep(i, n)         REP(i, (int) 0, n)
#define RREP(i, f, n)     for (auto i = (n)-1, i##_left = (f); i >= i##_left; i--)
#define rrep(i, n)        RREP(i, (int) 0, n)
using lint = long long int;
using ulint = unsigned long long int;
template<typename T>
using vvec = vector<vector<T>>;
template<typename T>
vvec<T> make_vvec(int n, int m, T v) { return vvec<T>(n, vector<T>(m, v)); }
template<typename T>
T& chmax(T& dst, T x) { return dst = max(dst, x); }
template<typename T>
T& chmin(T& dst, T x) { return dst = min(dst, x); }

class Solver {
 public:
  Solver();
  void solve();
};

Solver::Solver() {}

struct Mex {
  unordered_set<int> s;
  int mex = 1;
  void insert(int x) {
    s.insert(x);
    if (mex == x) {
      ++mex;
      while (s.count(mex))
        ++mex;
    }
  }
};

void Solver::solve() {
  int n; cin>>n;
  vector<int> A(n);
  vector<Mex> M(n);
  REP(m, 2, n+1) {
    A[m-1] = M[m-1].mex;
    for (int j = m*2; j-1 < n; j += m) {
      M[j-1].insert(A[m-1]);
    }
  }
  A[0] = *max_element(A.begin(), A.end()) + 1;
  for (auto a:A)
    cout<<a<<' ';
  cout<<endl;
}

int main() {
  cin.tie(nullptr); ios::sync_with_stdio(false);
  cout<<fixed<<setprecision(10);
  Solver solver;
  int t = 1;
//  cin>>t;
  while (t--) {
    solver.solve();
  }
  return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define pb push_back
#define mp make_pair
#define sz(x) ((int)x.size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define manytests int TT;cin >> TT; while (TT--)

#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define FORd(i,a,b) for (int i = (a); i >= (b); --i)

int dx[8] = {-1, 1, 0, 0, 1, 1, -1, -1}, dy[8] = {0, 0, 1, -1, 1, 1, -1, -1};

#define ll long long
#define ld long double
#define fi first
#define se second
#define rev reverse

#define vi vector<int>
#define vl vector<ll>
#define vc vector<char>
#define vd vector<double>
#define vs vector<string>
#define vld vector<ld>
#define vb vector<bool>
#define vvi vector<vi>
#define pii pair<int, int>
#define pl pair<ll, ll>
#define pld pair<ld, ld>
#define vpi vector<pii>
#define vpl vector<pl>
#define vpld vector<pld>

void ckmin(ll &a, ll b) { if (a > b) a = b; }
void ckmax(ll &a, ll b) { if (a < b) a = b; }

const int mxn = 1e5+5;
int c[mxn];
int vis[mxn];
vi ans;
vvi g;

void dfs(int v, int p = -1) {
    if (!vis[c[v]]) ans.pb(v);
    vis[c[v]]++;
    for (int u : g[v]) if (u != p) dfs(u, v);
    vis[c[v]]--;
}

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

    int n;
    cin >> n;
    FOR(i,0,n) cin >> c[i];
    g.resize(n);
    FOR(i,0,n-1) {
        int x, y;
        cin >> x >> y;
        --x, --y;
        g[x].pb(y);
        g[y].pb(x);
    }
    dfs(0);
    sort(all(ans));
    for (auto x : ans) cout << x + 1 << "\n";

    return 0;
}

#include <bits/stdc++.h>
#define No return puts("-1"), 0
using namespace std;

typedef long long i64;
const int N = 2e5+10;
int n, m, a[N], b[N], c[N], to[N], bt[N];
vector<int> da[N], db[N];
void add(int x, int v=1) { for(; x <= n; x += x&-x) bt[x] += v; }
int ask(int x) { int y = 0; for(; x; x -= x&-x) y += bt[x]; return y; }

signed main() {
	cin >> n;
	for(int i = 1; i <= n; i ++) scanf("%d", &a[i]), a[i] += i, c[i] = a[i];
	for(int i = 1; i <= n; i ++) scanf("%d", &b[i]), b[i] += i;
	sort(c+1, c+1+n); m = unique(c+1, c+1+n) - c-1;
	for(int i = 1; i <= n; i ++) {
		a[i] = lower_bound(c+1, c+1+m, a[i]) - c;
		int p = lower_bound(c+1, c+1+m, b[i]) - c;
		if(c[p] != b[i]) No;
		da[a[i]].push_back(i), db[p].push_back(i);
	}
	for(int i = 1; i <= m; i ++) {
		if(da[i].size() != db[i].size()) No;
		for(int j = 0; j < da[i].size(); j ++)
			to[da[i][j]] = db[i][j];
	}
	i64 ans = 0;
	for(int i = n; i; i --) {
		ans += ask(to[i]);
		add(to[i]);
	}
	cout << ans << endl;
	return 0;
}


#include <bits/stdc++.h>
#define LL long long
#define PII pair<int,int>
#define PIL pair<int,LL>
#define PLI pair<LL,int>
#define PIII pair<int,PII>
#define PLL pair<LL,LL>
#define PLII pair<LL,PII>
#define VI vector<int>
#define VVI vector<VI>
#define VL vector<LL>
#define VVL vector<VL>
#define VPII vector<PII>
#define FF first
#define SS second
#define MP make_pair
#define PB push_back
#define all(x) x.begin(),x.end()
#define watch(x) cout<<(#x)<<" = "<<(x)<<'\n'
#define mset(a,v) memset(a,v,sizeof(a))
#define setp(x) cout<<fixed<<setprecision(x)
#define EPS 0.00000000001
#define PI acos(-1)
#define loop(i,b,n) for(int i=b;i<n;++i)
#define rev_loop(i,b,n) for(int i=b;i>=n;--i)
using namespace std;

const int MOD = 1e9 + 7;
const LL MX = 1e9;
const LL INF = 1e9;

int main()
{
    //ofstream out("output.txt");
    //ifstream in("input.txt");
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

    int n;
    cin>>n;
    int a[n], mx = 0;
    loop(i,0,n)
    {
        cin>>a[i];
        mx = max(mx,a[i]);
    }

    int mxc = 0, c, ans;
    loop(i,2,mx+1)
    {
        c = 0;
        loop(j,0,n)
        {
            if(a[j] % i == 0) ++c;
        }

        if(c > mxc) {mxc = c; ans = i;}
    }

    cout<<ans<<'\n';

    return 0;
}

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define repp(i, st, en) for (ll i = (ll)st; i < (ll)(en); i++)
#define repm(i, st, en) for (ll i = (ll)st; i >= (ll)(en); i--)
#define all(v) v.begin(), v.end()
void chmax(ll &x, ll y) {x = max(x,y);}
void chmin(ll &x, ll y) {x = min(x,y);}
void Yes() {cout << "Yes" << endl; exit(0);}
void No() {cout << "No" << endl; exit(0);}
template<class in_Cout> void Cout(in_Cout x) {cout << x << endl; exit(0);}
template<class in_vec_cout>
void vec_cout(vector<in_vec_cout> vec) {
    for (in_vec_cout res : vec) {cout << res << " ";}
    cout << endl;
}

const ll inf = 1e18;
const ll mod = 1e9 + 7;
const ll d = 16;

ll dp[220000][2][17];

ll to_num(char c) {
    ll x = c - '0';
    if (0<=x && x<10) return x;
    ll y = c - 'A';
    return 10 + y;
}

ll bitcnt(ll bit) {
    ll res = 0;
    rep(i,d) if ((bit>>i)&1) res++;
    return res;
}

void addmodp(ll &x, ll y) {x = (x + y) % mod;}

int main() {
    string str; cin >> str;
    ll N = str.size();
    ll K; cin >> K;
    vector<ll> S(N);
    rep(i,N) S[i] = to_num(str[i]);

    ll bit = 1<<S[0];
    dp[0][0][1] = 1LL;
    dp[0][1][1] = S[0] - 1;
    for (ll i=1; i<N; i++) {
        ll from = bitcnt(bit);
        bit |= 1<<S[i];
        ll now = bitcnt(bit);
        dp[i][0][now] = 1;
        for (ll j=1; j<=d; j++) {
            addmodp(dp[i][1][j], dp[i-1][1][j] * j % mod);
            addmodp(dp[i][1][j], dp[i-1][1][j-1] * (d-j+1) % mod);
        }
        rep(j,S[i]) {
            if ((bit>>j)&1) addmodp(dp[i][1][from],1LL);
            else addmodp(dp[i][1][from+1],1LL);
        }
        addmodp(dp[i][1][1],15);
    }

    ll ans = 0LL;
    rep(i,2) addmodp(ans,dp[N-1][i][K]);
    Cout(ans);
}


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

int n,a,ans;

int main() {
	cin>>n;
	while(n--) {
		cin>>a;
		ans+=max(0,a-10);
	}
	printf("%d\n",ans);
	return 0;
}

#pragma GCC optimize("Ofast")
#define _USE_MATH_DEFINES
#include "bits/stdc++.h"
using namespace std;

#define max(a, b) (a < b? b : a)
#define min(a, b) ((a>b)?b:a)

#define MOD 1000000007

#define FOR(a,c)   for ( ll (a)=0; (a)<(c); (a)++)
#define FORL(a,b,c)  for ( ll (a)=(b); (a)<(c); (a)++)
#define FORR(a,b,c)  for (  ll (a)=(b); (a)>=(c); (a)--)

#define INF 9223372036854775807
//18446744073709551615
#define abs llabs
#define by_AYUSH ios::sync_with_stdio(false);  cin.tie(NULL); cout.tie(NULL);

#define no cout<<"NO\n";
#define yes cout<<"YES\n";

#define Clear( a, b ) memset( a, b, sizeof( a ) )
#define run if(1)cout<<__LINE__<<endl;

#define pr3(a,b,c) cerr<<#a<<"="<<a<<"\t"<<#b<<"="<<b<<"\t"<<#c<<"="<<c<<"\n";
#define pr2(a,b) cerr<<#a<<"="<<a<<"\t"<<#b<<"="<<b<<"\n";
#define pr1(a) cerr<<#a<<"="<<a<<"\n";
#define debug(x)       cerr<< #x <<" : "<< x << endl;
#define debuga(A,N)    cerr<< #A <<" : [";for(int i = 0; i<N;i++) cerr<<A[i]<<" "; cerr<<"]\n";
#define debuga2(A,N,M) cerr<< #A << " : \n"; for(int i=0;i<N;i++){cerr<<"[";for(int j=0;j<M;++j) cerr<<A[i][j]<<" ";cerr<<"]\n";}
#define debugp(p)      cerr<< #p <<" : "<<"("<<(p).first<<","<<(p).second<<")\n";
#define debugv(v)      cerr<< #v <<" : "<<"[";for(int i = 0; i< (v).size(); i++) cerr<<v[i]<<" "; cerr<<"]\n";
#define debugv2(v)     cerr<< #v << " : \n"; for(int i=0;i<v.size();i++){cerr<<"[";for(int j=0;j<(v[0].size());++j) cerr<<v[i][j]<<" ";cerr<<"]\n";}
#define debugs(m)      cerr<< #m <<" : [ "; for(auto itr = m.begin(); itr!=m.end();itr++) cerr<<*itr<<" "; cerr<<"]\n";
#define debugm(m)      cerr<< #m <<" : [ "; for(auto itr = m.begin();itr!=m.end(); itr++) cerr<<"("<<itr->first<<","<<itr->second<<") ";cerr<<"]\n";
typedef unsigned long long ull;
typedef long long int ll;
typedef vector<ll> vi;
typedef pair<ll,ll> pi;
inline long long  max3(long long  a, long long  b,long long  c){return (a)>(b)?((a)>(c)?(a):(c)):((b)>(c)?(b):(c));}
inline long long  min3(long long  a, long long b,long long c){return (a)<(b)?((a)<(c)?(a):(c)):((b)<(c)?(b):(c));}
#define F first
#define S second
#define PB push_back
#define POB pop_back
#define MP make_pair
void solve()
{
  int n;cin>>n;
  int s=0;
  int a[n];
  for(int i=0;i<n;i++)
  {
    cin>>a[i];
    if(a[i]>=10)
      s+=a[i]-10;
}
  cout<<s;
}
int main()
{
    //int t;cin>>t;
   // while(t--)
   // {
    solve();
     //  }
   return 0;
}

//                               █████╗ ██╗   ██╗██╗   ██╗███████╗██╗  ██╗
//                              ██╔══██╗╚██╗ ██╔╝██║   ██║██╔════╝██║  ██║
//                              ███████║ ╚████╔╝ ██║   ██║███████╗███████║
//                              ██╔══██║  ╚██╔╝  ██║   ██║╚════██║██╔══██║
//                              ██║  ██║   ██║   ╚██████╔╝███████║██║  ██║
//                              ╚═╝  ╚═╝   ╚═╝    ╚═════╝ ╚══════╝╚═╝  ╚═╝

//
//
//
//
//


#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define all(v) v.begin(), v.end()
#define allr(v) v.rbegin(), v.rend()
#define V vector
#define pb push_back
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound
#define mp make_pair
#define sz(x) int(x.size())
#define pcnt __builtin_popcountll
template <typename T> bool chmin(T &a, const T &b) {if(a > b){a = b; return true;} return false;}
template <typename T> bool chmax(T &a, const T &b) {if(a < b){a = b; return true;} return false;}
template <typename T> void print(T a) {cout << a << ' ';}
template <typename T> void printe(T a) {cout << a << endl;}
template <typename T> void printv(T a) {rep(i, sz(a))print(a[i]); cout<<endl;}
template <typename T> void printp(pair<T, T> a) {print(a.first); cout<<a.second<<endl;}
template <typename A, size_t N, typename T> void Fill (A (&array)[N], const T & val) {fill ((T*)array, (T*)(array+N), val);}
template <typename T> using vc = vector<T>;
template <typename T> using vv = vc<vc<T>>;
template <typename T> using vvv = vc<vv<T>>;
using ll = long long;
using P = pair<int, int>;
using Pl = pair<ll, ll>;
using vi = vc<int>;
using vvi = vv<int>;
using vl = vc<ll>;
using vvl = vv<ll>;
vi di = {-1, 1,  0, 0, -1, -1,  1, 1};
vi dj = { 0, 0, -1, 1, -1,  1, -1, 1};

int main () {
    vc<string> s(3);
    rep(i, 3) cin >> s[i];
    map<char, ll> Mp; // その文字に割り当てられたものを何倍するか
    rep(i, 3) {
        ll scale = 1;
        for (int j = sz(s[i])-1; j >= 0; j--) {
            if (i == 2) {
                Mp[s[i][j]] -= scale;
            }
            else {
                Mp[s[i][j]] += scale;
            }
            scale *= 10;
        }
    }
    if (sz(Mp) > 10) {
        cout << "UNSOLVABLE" << endl;
        return 0;
    }

    map<char, int> Mp2; // 各文字に何の文字入れるか
    auto restore = [&] (string t) {
        ll res = 0;
        rep(i, sz(t)) {
            res *= 10;
            res += Mp2[t[i]];
        }
        return res;
    };
    vi p(10);
    rep(i, 10) p[i] = i;
    do {
        int now = 0; // 今何番目の要素か
        ll sum = 0;
        for (auto x : Mp) {
            sum += p[now] * x.second;
            Mp2[x.first] = p[now];
            now++;
        }
        if (sum == 0) {
            vl n(3);
            bool flag = true;
            rep(i, 3) {
                n[i] = restore(s[i]);
                if (n[i] <= 0 || sz(to_string(n[i])) < sz(s[i])) flag = false;
            }
            if (flag) {
                rep(i, 3) cout << n[i] << endl;
                return 0;
            }
            else {
                continue;
            }
        }
        Mp2.clear();
    } while (next_permutation(all(p)));

    cout << "UNSOLVABLE" << endl;

    return 0;
}

/*                             हरे कृष्ण हरे कृष्ण कृष्ण कृष्ण हरे हरे
                                  हरे राम हरे राम राम राम हरे हरे                                     */
#include<bits/stdc++.h>
using namespace std;
#define pb emplace_back
#define pob pop_back
typedef long long int lli;
#define test lli t; cin>>t; while(t--)
#define ff first
#define ss second
#define F(n) for(lli i=0;i<n;i++)
#define pf pop_front
#define lb lower_bound
#define ub upper_bound
#define setbits(x)  __builtin_popcountll(x)
#define zerobits(x)  __builtin_ctzll(x)
#define bs binary_search
#define all(x) x.begin(),x.end()
#define nl "\n"
#define loop(i,s,n) for(lli i=s;i<n;i++)
#define pp(a)  for(auto x : a)  cout<<x<<" ";  cout<<nl;
#define mem(arr,x) memset(arr,x,sizeof(arr))
#define mod 1000000007
#define inf 1e18
#define tt(n) cin>>n; lli a[n]; loop(i,0,n) cin>>a[i];
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define ps(x,y) fixed<<setprecision(y)<<x

int main()
{
    fast;
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
     lli n,i;
    string s1,s2,s3;
    cin>>s1>>s2>>s3;
    set<char> s;
    loop(i,0,s1.length()) s.insert(s1[i]);
    loop(i,0,s2.length()) s.insert(s2[i]);
    loop(i,0,s3.length()) s.insert(s3[i]);
    if(s.size()>10) cout<<"UNSOLVABLE";
    else
    {
        std::vector<char> a;
        n=s.size();
        for(auto x: s) a.pb(x);
        lli b[10]={0,1,2,3,4,5,6,7,8,9},f=0;
        //for(auto x: a) cout<<x<<" ";
        //set<lli> sm;
        do
        {
            map<char,lli> m;
            lli k=0;
            loop(i,0,n) m[a[i]]=b[k++];
            //for(auto x: m) cout<<x.ff<<" "<<x.ss<<nl;
              //  break;
            //sm.insert(m['s']);
            lli c1=0,c2=0,c3=0;
            if(m[s1[0]]==0 || m[s2[0]]==0 || m[s3[0]]==0) ;
            else
            {
                loop(i,0,s1.length())
                {
                    c1=(c1*10)+m[s1[i]];
                }
                loop(i,0,s2.length())
                {
                    c2=(c2*10)+m[s2[i]];
                }
                loop(i,0,s3.length())
                {
                    c3=(c3*10)+m[s3[i]];
                }
                if(c1+c2==c3 && c1>0 && c2>0 && c3>0)
                {
                    f=1;
                    loop(i,0,s1.length()) cout<<m[s1[i]];
                    cout<<nl;
                    loop(i,0,s2.length()) cout<<m[s2[i]];
                    cout<<nl;
                    loop(i,0,s3.length()) cout<<m[s3[i]];
                    break;
                }
            }
        }while(next_permutation(b,b+10));
        //for(auto x: sm) cout<<x<<" ";
        if(f==0) cout<<"UNSOLVABLE";
    }
return 0;
}


#include <bits/stdc++.h>
#define fo(a,b,c) for (a=b; a<=c; a++)
#define fd(a,b,c) for (a=b; a>=c; a--)
#define ll long long
//#define file
using namespace std;

int n,i,j,k,l,m,sum;
ll s[2];
char st[21];

int main()
{
	#ifdef file
	freopen("a.in","r",stdin);
	#endif

	scanf("%d%d",&n,&m);
	fo(i,1,n)
	{
		scanf("%s",st+1),sum=0;
		fo(j,1,m) sum+=st[j]=='1';
		++s[sum&1];
	}
	printf("%lld\n",s[0]*s[1]);

	fclose(stdin);
	fclose(stdout);
	return 0;
}


#pragma region Region_1

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
#define srep(i, s, t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(), a.end()
#define rrng(a) a.rbegin(), a.rend()
using ll = long long;
using P = pair<int, int>;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<ll>;
using VP = vector<P>;
#define MOD 1000000007
const int INF = 1e9 + 10;

template <class T, class C>
void chmax(T& a, C b) {
    if (a <= b) a = b;
}
template <class T, class C>
void chmin(T& a, C b) {
    if (a >= b) a = b;
}

template <class T>
T sum(const vector<T>& v) {
    T res = 0;
    for (size_t i = 0; i < v.size(); ++i) res += v[i];
    return res;
}

/////////////////////////////////////////////////////////
// print like python
// https://qiita.com/Lily0727K/items/06cb1d6da8a436369eed
/////////////////////////////////////////////////////////
void print() { cout << endl; }

template <class Head, class... Tail>
void print(Head&& head, Tail&&... tail) {
    cout << head;
    if (sizeof...(tail) != 0) cout << " ";
    print(forward<Tail>(tail)...);
}

template <class T>
void print(vector<T>& vec) {
    for (auto& a : vec) {
        cout << a;
        if (&a != &vec.back()) cout << " ";
    }
    cout << endl;
}

template <class T>
void print(vector<vector<T>>& df) {
    for (auto& vec : df) {
        print(vec);
    }
}

#pragma endregion Region_1
/////////////////////////////////////////////////////////

/**
 * 3角形の面積
 */
ll triangle_area(ll x1, ll y1, ll x2, ll y2, ll x3, ll y3) {
    x2 -= x1;
    x3 -= x1;
    y2 -= y1;
    y3 -= y1;
    return abs(x2 * y3 - y2 * x3);
}
int main() {
    //入力の高速化用のコード
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    std::cout << std::setprecision(15);
    //////////////////////////////////////////
    int n;
    cin >> n;
    VI x(n);
    VI y(n);
    rep(i, n) {
        cin >> x[i] >> y[i];
    }

    rep(i, n) srep(j, i + 1, n) srep(k, j + 1, n) {
        if (triangle_area(x[i], y[i], x[j], y[j], x[k], y[k])==0) {
            print("Yes");
            return 0;
        }
    }
    print("No");

    return 0;
}

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

using ll = long long;
using Vi = std::vector<int>;
using Vl = std::vector<ll>;
using Pii = std::pair<int, int>;
using Pll = std::pair<ll, ll>;

constexpr int I_INF = std::numeric_limits<int>::max();
constexpr ll L_INF = std::numeric_limits<ll>::max();

template <typename T1, typename T2>
inline bool chmin(T1& a, const T2& b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template <typename T1, typename T2>
inline bool chmax(T1& a, const T2& b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

class Prints {
private:
    class __Prints {
    public:
        __Prints(const char* sep, const char* term) : sep(sep), term(term) {}
        template <class... Args>
        auto operator()(const Args&... args) const -> decltype((std::cout << ... << std::declval<Args>()), void()) { print(args...); }
        template <typename T>
        auto pvec(const T& vec, size_t sz) const -> decltype(std::cout << std::declval<decltype(std::declval<T>()[0])>(), void()) {
            for (size_t i = 0; i < sz; i++)
                std::cout << vec[i] << (i == sz - 1 ? term : sep);
        }
        template <typename T>
        auto pmat(const T& mat, size_t h, size_t w) -> decltype(std::cout << std::declval<decltype(std::declval<T>()[0][0])>(), void()) {
            for (size_t i = 0; i < h; i++)
                for (size_t j = 0; j < w; j++)
                    std::cout << mat[i][j] << (j == w - 1 ? term : sep);
        }

    private:
        const char *sep, *term;
        void print() const { std::cout << term; }
        void print_rest() const { std::cout << term; }
        template <class T, class... Tail>
        void print(const T& head, const Tail&... tail) const { std::cout << head, print_rest(tail...); }
        template <class T, class... Tail>
        void print_rest(const T& head, const Tail&... tail) const { std::cout << sep << head, print_rest(tail...); }
    };

public:
    Prints() {}
    __Prints operator()(const char* sep = " ", const char* term = "\n") const { return __Prints(sep, term); }
};

Prints prints;

//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

void solve() {
    int N;
    cin >> N;
    using Pos = array<ll, 2>;
    vector<Pos> ps(N);
    for (ll i = 0; i < N; i++) {
        int a, b;
        cin >> a >> b;
        ps[i] = {a, b};
    }

    for (ll i = 0; i < N; i++) {
        for (ll j = i + 1; j < N; j++) {
            for (ll k = j + 1; k < N; k++) {
                Pos b1, b2;
                b1[0] = ps[j][0] - ps[i][0];
                b1[1] = ps[j][1] - ps[i][1];
                b2[0] = ps[k][0] - ps[i][0];
                b2[1] = ps[k][1] - ps[i][1];
                if (b1[0] * b2[1] - b1[1] * b2[0] == 0) {
                    prints()("Yes");
                    return;
                }
            }
        }
    }

    prints()("No");
}

//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

int main() {
#ifdef FASTIO
    std::cin.tie(nullptr), std::cout.tie(nullptr);
    std::ios::sync_with_stdio(false);
#endif
#ifdef FILEINPUT
    std::ifstream ifs("./in_out/input.txt");
    std::cin.rdbuf(ifs.rdbuf());
#endif
#ifdef FILEOUTPUT
    std::ofstream ofs("./in_out/output.txt");
    std::cout.rdbuf(ofs.rdbuf());
#endif
    std::cout << std::setprecision(18) << std::fixed;
    solve();
    std::cout << std::flush;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define All(a) (a).begin(),(a).end()
#define INF numeric_limits<ll>::max()

int main(){
	ll n,i,ans;
	cin >>n;
	n++;
	for(i=(ll)sqrt(2*n);i*(i+1)>2*n;i--){
	}

	cout << n-i << endl;
	return 0;

}

#include<bits/stdc++.h>
#define ll long long int
using namespace std;
int main()
{   ios_base::sync_with_stdio(false); cin.tie(0);

    long long n, min, max;
    cin>>n;
    min = 0;
    max = n+1;
    while(max > min){
        min++;
        max-=min;
    }
    cout<<n-min+1<<endl;
}


#include <bits/stdc++.h>
using namespace std;
#define repd(i,a,b) for (ll i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
#define all(x) (x).begin(),(x).end()
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; }
typedef long long ll;
typedef pair<ll,ll> P;
typedef vector<ll> vec;
using Graph = vector<vector<ll>>;
const long long INF = 1LL<<60;
const long long MOD = 1000000007;

// Sieve of Eratosthenes
// https://youtu.be/UTVg7wzMWQc?t=2774
struct Sieve {
  int n;
  vector<ll> f, primes;
  Sieve(int n=1):n(n), f(n+1) {
    f[0] = f[1] = -1;
    for (ll i = 2; i <= n; ++i) {
      if (f[i]) continue;
      primes.push_back(i);
      f[i] = i;
      for (ll j = i*i; j <= n; j += i) {
        if (!f[j]) f[j] = i;
      }
    }
  }
  bool isPrime(int x) { return f[x] == x;}
  vector<int> factorList(int x) {
    vector<int> res;
    while (x != 1) {
      res.push_back(f[x]);
      x /= f[x];
    }
    return res;
  }
  vector<P> factor(int x) {
    vector<int> fl = factorList(x);
    if (fl.size() == 0) return {};
    vector<P> res(1, P(fl[0], 0));
    for (int p : fl) {
      if (res.back().first == p) {
        res.back().second++;
      } else {
        res.emplace_back(p, 1);
      }
    }
    return res;
  }
  vector<pair<ll,int>> factor(ll x) {
    vector<pair<ll,int>> res;
    for (int p : primes) {
      int y = 0;
      while (x%p == 0) x /= p, ++y;
      if (y != 0) res.emplace_back(p,y);
    }
    if (x != 1) res.emplace_back(x,1);
    return res;
  }
};

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll n;cin>>n;
    vec a(n),t(n);
    rep(i,n)cin>>a[i]>>t[i];
    ll q;cin>>q;
    multiset<ll> x;
    map<ll,ll> mp;
    rep(i,q){
      ll X;cin>>X;
      x.insert(X);
      mp[i]=X;
    }
    vec ans(q);
    vec it(q,-1);
    ll tot=0;
    map<ll,ll> M;
    rep(i,n){
      if(t[i]==1)tot+=a[i];
      else if(t[i]==2){
        auto itr=x.lower_bound(a[i]-tot+1);
        if(itr==x.begin())continue;
        itr--;
        while(1){
          if(itr==x.begin()){M[*itr]=a[i]-tot;x.erase(itr);break;}
          else{
            M[*itr]=a[i]-tot;
            x.erase(itr--);
          }
        }
        x.insert(a[i]-tot);
        M[a[i]-tot]=a[i]-tot;
      }
      else{
        auto itr=x.lower_bound(a[i]-tot);
        if(itr==x.end())continue;
        while(itr!=x.end()){
          M[*itr]=a[i]-tot;
          x.erase(itr++);
        }
        x.insert(a[i]-tot);
        M[a[i]-tot]=a[i]-tot;
      }
    }
    rep(i,q){
      ll ans=mp[i];
      vec memo;
      while(1){
        if(M.count(ans)){
          if(M[ans]!=ans){
            memo.push_back(ans);
            ans=M[ans];
            }
          else break;
        }
        else break;
      }
      rep(j,memo.size())M[memo[j]]=ans;
      cout<<ans+tot<<endl;
    }
    return 0;
}

//#define _CRT_SECURE_NO_WARNINGS
#include "bits/stdc++.h"

#define rep(i,n) for(ll (i)=0;(i)<(ll)(n);(i)++)
#define all(x) (x).begin(),(x).end()
#define MOD 1000000007LL
#define INF (1LL<<60LL)
#define int long long
typedef long long ll;

using namespace std;

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n, k, m; cin >> n >> k >> m;
	int ans = n * m;
	rep(i, n - 1) {
		int a; cin >> a;
		ans -= a;
	}
	if (ans < 0) ans = 0;
	else if (ans > k) ans = -1;
	cout << ans << endl;
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define ff first
#define ss second
#define pii pair <int,int>
#define pll pair <ll,ll>
#define testcase() int t; cin>>t; while(t--)
#define forn(i,n) for(int i=0;i<n;i++)
#define forn1(i,n) for(int i=1;i<=n;i++)
#define vll vector <ll>
#define vi vector <int>
#define all(v) v.begin(),v.end()

ll M = 1e9 + 7;
double pi = acos(-1.0);
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
ll powerm(ll x,ll y){ ll res=1; while(y){ if(y&1) res=(res*x)%M; y=y>>1; x=(x*x)%M;} return res%M; }
ll power(ll x,ll y){ ll res=1; while(y){ if(y&1) res=(res*x); y=y>>1; x=(x*x);} return res; }
ll gcd(ll a,ll b){if(b>a)return gcd(b,a); if(b==0)return a; return gcd(b,a%b);}

////////////////////////////////////////////////////

// Function to return the sum of arr[0..index]
// This function assumes that the array is preprocessed
// and partial sums of array elements are stored in BITree[]
int getSum(int BITree[], int index)
{
    int sum = 0; // Initialize result

    // Traverse ancestors of BITree[index]
    while (index > 0) {
        // Add current element of BITree to sum
        sum += BITree[index];

        // Move index to parent node in getSum View
        index -= index & (-index);
    }
    return sum;
}

// Updates a node in Binary Index Tree (BITree) at given index
// in BITree. The given value 'val' is added to BITree[i] and
// all of its ancestors in tree.
void updateBIT(int BITree[], int n, int index, int val)
{
    // Traverse all ancestors and add 'val'
    while (index <= n) {

        // Add 'val' to current node of BI Tree
        BITree[index] += val;

        // Update index to that of parent in update View
        index += index & (-index);
    }
}

///////////////////////////////////////////////////

int main() {

	//ifstream cin("input.txt");
	//ofstream cout("output.txt");
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);

	int n; cin>>n;
    vi a(n);
    forn(i,n) cin>>a[i];
    // vi s;
    int BIT[n + 1];
    for (int i = 1; i <= n; i++)
        BIT[i] = 0;

    vi suff(n,0);
    // s.pb(a[n-1]);
    ll ans = 0;

    for (int i = n - 1; i >= 0; i--) {

        // Get count of elements smaller than arr[i]
        suff[i] = getSum(BIT, a[i]);
        ans += suff[i];
        // Add current element to BIT
        updateBIT(BIT, n, a[i]+1, 1);
    }

    // for(int i=n-2;i>=0;i--)
    // {
    //     auto it = lower_bound(all(s),a[i]);
    //     int h = it - s.begin();
    //     suff[i] = h;
    //     // it--;
    //     ans += h;
    //     s.insert(it,a[i]);
    //     // for(auto it:s) cout<<it<<':'; cout<<endl;
    // }
    // forn(i,n) cout<<suff[i]<<' ';
    cout<<ans<<'\n';
    int sz = 0;
    forn(i,n-1)
    {
        // auto it = lower_bound(all(s),a[i]);
        int h = a[i] - suff[i];
        ans += (n-1-i-2*suff[i]);
        ans -= h;
        ans += (sz-h);
        // s.insert(it,a[i]);
        sz++;
        // for(auto it:s) cout<<it<<':'; cout<<endl;
        cout<<ans<<'\n';
    }

	return 0;
}

#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <queue>
#include <map>
#include <set>
#include <cmath>
// #include <atcoder/all>
using namespace std;
using ll = long long int;
using vi = vector<int>;
using vll = vector<ll>;
using ss = string;
using db = double;
template<class T> using minpq = priority_queue <T,vector<T>,greater<T>>;
const int dx[4] = {1,0,-1,0};
const int dy[4] = {0,1,0,-1};
#define V vector
#define pii pair<int,int>
#define pll pair<ll,ll>
#define rep(i,s,n) for(int i=(s);i<(int)(n);i++)
#define reciv(v,n) vi (v)((n)); rep(i,0,(n))cin>>v[i]
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define ci(x) cin >> x
#define pb push_back
#define eb emplace_back
#define rz resize
#define sz(x) int(x.size())
#define yn cout<<"Yes"<<endl;else cout<<"No"<<endl
#define YN cout<<"YES"<<endl;else cout<<"NO"<<endl
template<class T>void chmax(T &x,T y){x=max(x,y);}
template<class T>void chmin(T &x,T y){x=min(x,y);}
template<class T>void allv(V<T> v){for(T NUM:v)printf("%d ",NUM);printf("\n");}

int main(){
    ll  a, b ;	cin>> a >> b ;
    ll  c, d ;	cin>> c >> d ;

    ll cdb=c*d-b;
    ll ans=1001001001;
    if(cdb<=0)ans=-1;

    else ans=(a+cdb-1)/cdb;

    cout<< ans <<endl;

}


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

#define asll unsigned long long
#define ll long long
#define ld long double
#define imt int
#define pii pair<int,int>
#define st first
#define nd second
#define psbk(x) push_back(x);
#define For(x,a,b) for(int x=(a);x!=(b+((b-a)/abs(b-a)));x+=(b-a)/abs(b-a))
#define FOR(x,n) for(int x=0;x<(n);x++)
#define m_p make_pair

#define kj <<" "<<
#define kjb <<" ";
#define dg <<","<<
#define ml <<endl;
#define co cout<<
#define ter cout<<endl;
#define sibi cout<<"TES"<<endl;
#define tes(x) cout<<"TES"<<x<<endl;
#define kpr(x) cout<<"("<<x.st dg x.nd <<")" ml
#define kkor(p) cout<<"("<<p.x dg p.y <<")" ml
#define kera(x,m) for( int i = 0;i < m ; i++ ){ cout<<"x["<< i <<"] =" kj x[i] ml}

asll M=1e9+7;
int n,m,k,tc;
int p,q,r;
int js,js1,js2,js3,js4,js5;
int lj1,lj2;
int la,la1,la2;
string s;
stack<char> st;
string cek="   ";

int main()
{
	cin>>p;
	cin.ignore();
	getline(cin,s);
	FOR(i,s.size()){
		st.push(s[i]);
		if(st.size()>=3){
			FOR(j,3){
				cek[j]=st.top();
				st.pop();
			}
			if(cek!="xof"){
				For(j,2,0){
					st.push(cek[j]);
				}
			}
		}
	}
	co st.size() ml

}

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const ll MOD = 1e9+7;
const ll INF = 1e18;
#define rep(i,m,n) for(ll i = (m); i <= (n); i++)
#define zep(i,m,n) for(ll i = (m); i < (n); i++)
#define rrep(i,m,n) for(ll i = (m); i >= (n); i--)
#define print(x) cout << (x) << endl;
#define printa(x,m,n) for(int i = (m); i <= n; i++){cout << (x[i]) << " ";} cout<<endl;

template<typename T> class segtree {
private:
    int n,sz,h;
    vector<T> node, lazy;
    void eval(int k) {
        if(lazy[k]){
            node[k] += lazy[k];
            if(k < n) {
                lazy[k*2] += lazy[k] / 2, lazy[k*2+1] += lazy[k] / 2;
            }
            lazy[k] = 0;
        }
    }

public:
    segtree(const vector<T>& v) : n(1), sz((int)v.size()), h(0) {
        while(n < sz) n *= 2, h++;
        node.resize(2*n, 0), lazy.resize(2*n, 0);
        for(int i = 0; i < sz; i++) node[i+n] = v[i];
        for(int i = n-1; i >= 1; i--) node[i] = node[2*i] + node[2*i+1];
    }
    void range(int a, int b, T x, int k=1, int l=0, int r=-1){
        if(r < 0) r = n;
        eval(k);
        if(b <= l || r <= a){
            return;
        }
        if(a <= l && r <= b){
            lazy[k] += (r-l)*x;
            eval(k);
        }else{
            range(a, b, x, 2*k, l, (l+r)/2);
            range(a, b, x, 2*k+1, (l+r)/2, r);
            node[k] = node[2*k] + node[2*k+1];
        }
    }
    T query(int a, int b) {
        a += n, b += n - 1;
        for(int i = h; i > 0; i--) eval(a >> i), eval(b >> i);
        b++;
        T res1 = 0, res2 = 0;
        while(a < b) {
            if(a & 1) eval(a), res1 += node[a++];
            if(b & 1) eval(--b), res2 += node[b];
            a >>= 1, b >>= 1;
        }
        return res1 + res2;
    }
    void _print(){for(int i = 0; i < sz; i++) cout<<query(i,i+1)<< " ";cout<<endl;}
};

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

    ll n; cin >> n;
    ll a[n]; zep(i, 0, n)cin >> a[i];

    vector<ll> v(n, 0);
    segtree<ll> s(v);

    ll ans = 0;
    ll cnt[n]; memset(cnt, 0, sizeof(cnt));
    zep(i, 0, n){
        ans += s.query(a[i], n);
        cnt[a[i]] = a[i] - s.query(0, a[i]);
        s.range(a[i], a[i] + 1, 1);
    }
    //printa(cnt, 0, n - 1)
    vector<ll> u(n, 0);
    segtree<ll> t(u);

    print(ans)
    zep(i, 0, n - 1){
        ans += n - i - 1 - 2 * cnt[a[i]];
        //print(ans)
        ans += t.query(a[i], n) - t.query(0, a[i]);
        print(ans)
        t.range(a[i], a[i] + 1, 1);
    }

    return 0;
}


#include <iostream>
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <set>
#include <queue>
#include <map>

using namespace std;
typedef long long int ll;
typedef pair <int,int> pii;
typedef pair<ll,ll> pll;

/*bool compare_function(const pair<int, int> a, const pair<int, int> b)
{
    return a.first < b.first;
}*/
// use case
//sort(V.begin(), V.end(), compare_function);

/*struct compare
{
    bool operator ()(const pair<int, int> &a, const pair<int, int> &b) {
    if (a.second-a.first==b.second-b.first)
    {
        return a.first>b.first;
    }
    return a.second-a.first < b.second-b.first;}
};
priority_queue <pair<int,int>, vector <pair<int,int>>, compare> Q;*/

void print(vector <ll> X)
{
    for (int i=0; i<X.size(); i++)
    {
        cout<<X[i]<<" ";
    }
    cout<<endl;
    return;
}

ll keisk(char x) {
	if (x=='B') {return 0LL;}
	if (x=='R') {return 1LL;}
	return 2LL;
	}

ll kiek(ll a) {
	//cout<<a<<endl;
	ll k=0;
	while (a>0) {
		k+=a/3;
		a=a/3;
		}
	//cout<<a<<" "<<k<<endl;
	return k;
	}

ll find(int n, int k, vector <ll> &F, vector <ll> &K) {
	if (K[n]>K[k]+K[n-k]) {return 0LL;}
	if (k==0 || k==n) {return 1LL;}
	return (F[n]*F[k]*F[n-k])%3;
	}

char keisk2(ll ats) {
	if (ats==0) {return 'B';}
	if (ats==1) {return 'R';}
	return 'W';
	}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin>>n;
    vector <ll> A(n);
    vector <ll> F(n,1);
    vector <ll> K(n,0);
	for (int i=0;i<n;i++) {
		K[i]=kiek(i);
		}
    for (int i=1;i<n;i++) {
		int j=i;
		while (j%3==0) {j=j/3;}
		F[i]=(F[i-1]*j)%3;
		}
	//print(K);
	//print(F);
    for (int i=0;i<n;i++) {
		char x;
		cin>>x;
		A[i]=keisk(x);
		}
	ll ats=0;
	vector <ll> X(n);
	for (int i=0;i<n;i++) {
		X[i]=find(n-1,i,F,K);
		ats+=X[i]*A[i];
		ats=ats%3;
		}
	//cout<<ats<<endl;
	//print(X);
	if (n%2==0 && ats!=0) {ats=3-ats;}
	char z=keisk2(ats);
	//cout<<ats<<endl;
	cout<<z<<endl;
    return 0;
}

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

//template
#define rep(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define ALL(v) (v).begin(),(v).end()
using ll=long long int;
const int inf = 0x3fffffff; const ll INF = 0x1fffffffffffffff; const double eps=1e-12;
template<typename T>inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<typename T>inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
//end

int C[5][5];
int nCr(int n,int r){
   if(C[0][0]==0){
      rep(i,0,5){
         C[i][0]=C[i][i]=1;
         rep(j,1,i){
            C[i][j]=(C[i-1][j-1]+C[i-1][j])%3;
         }
      }
   }
   int res=1;
   rep(_,0,30){
      res*=C[n%3][r%3];
      n/=3,r/=3;
   }
   return res;
}

int main(){
   int n;
   cin>>n;
   string s;
   cin>>s;

   int res=0;
   rep(i,0,n){
      if(s[i]=='R')continue;
      if(s[i]=='W')res=(res+nCr(n-1,i))%3;
      if(s[i]=='B')res=(res+nCr(n-1,i)*2)%3;
   }
   if(!(n&1))res=(3-res)%3;
   if(res==0)puts("R");
   if(res==1)puts("W");
   if(res==2)puts("B");
   return 0;
}


#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const int INF = 1001001001;
const int dx[4] = {1,0,-1,0};
const int dy[4] = {0,1,0,-1};
std::string to_string(long long);
using std::stol;

int main() {
ll n;
cin >> n;
vector<double> x(n);
vector<double> y(n);
ll ans = 0;
rep(i,n) {
    cin >> x[i] >> y[i];

}
for(ll i = 0;i < n;i++) {
    double cnt;
    for(ll j = i+1;j < n;j++) {
        double cnt = (y[i]-y[j]) /(x[i]-x[j]);
        if (cnt >= -1 && cnt <= 1) ans++;
    }
}
cout << ans << endl;

return 0;
}

#include<iostream>
#include<vector>
using namespace std;

float findslope(vector<long> point1, vector<long> point2)
{
  double x1 = point1[0];
  double y1 = point1[1];
  double x2 = point2[0];
  double y2 = point2[1];
  return ((y2-y1)/(x2-x1));
}

int main(){
  long N;
  cin >> N;
  vector<vector<long>> coordinates;
  coordinates.resize(N);
  long x,y;
  for(int i=0;i<N;++i)
  {
    cin >> x >> y;
    coordinates[i].push_back(x);
    coordinates[i].push_back(y);
  }

  int count=0;
  float slope;

  for(int i=0;i<N;++i)
  {
    for(int j=0;j<N;++j)
    {
      if(i==j) continue;
      slope = findslope(coordinates[i], coordinates[j]);
      if(slope >= -1 && slope <= 1)
      {
        ++count;
      }
    }
  }

  cout << count/2;
}


#include                        <bits/stdc++.h>
#include                        <ext/pb_ds/assoc_container.hpp>
#define lb                      lower_bound
#define ub                      upper_bound
#define fe(x)                   (*(x.begin()))
#define le(x)                   (*(x.rbegin()))
#define pb                      push_back
#define load(node,n)            bool operator < (const node &n) const
#define fbo(x,id)               (*(x.find_by_order(id)))
#define ook(y)                  order_of_key(y)
#define all(x)                  (x).begin(),(x).end()
#define si(a)                   scanf("%d",&a)
#define sii(a,b)                scanf("%d %d",&a,&b)
#define siii(a,b,c)             scanf("%d %d %d",&a,&b,&c)
#define sl(a)                   scanf("%lld",&a)
#define sll(a,b)                scanf("%lld %lld",&a,&b)
#define slll(a,b,c)             scanf("%lld %lld %lld",&a,&b,&c)
#define rep(i,a,b)              for(ll i = a; i<=b;  i++)
#define un(x)                   x.erase(unique(all(x)), x.end())
#define TT                      long long TC;  scanf("%lld",&TC);  while(TC--)
#define read                    freopen("input.txt","r",stdin)
#define write                   freopen("output.txt","w",stdout)
#define set(x)                  tree<x,null_type,less<x>,rb_tree_tag,tree_order_statistics_node_update>
#define assign(v,n,x)           v.clear(); for(int I = 0; I<n; I++)    v.pb(x);
#define SZ(x)                   (int)x.size()
#define ff                      first
#define ss                      second
using                           namespace __gnu_pbds;
using                           namespace std;
typedef                         long long ll;
typedef                         pair<ll,ll> pll;
typedef                         pair<int,int> pii;

#define mx 23

ll ar[mx];
ll MX = 1e12,n;

ll ans = MX;

void fn(ll pos,ll w = 0,ll Or = 0){
    if(pos==n){
        w^=Or;
        ans = min(ans,w);
        return;
    }
    ll p = Or|ar[pos];
    fn(pos+1,w^p,0);
    fn(pos+1,w,p);
}

main(){
//read;

sl(n);

for(ll i = 0; i<n; i++){
    sl(ar[i]);
}

fn(0);

cout<<ans;

return 0;
}

// Problem: C - ORXOR
// Contest: AtCoder - AtCoder Beginner Contest 197（Sponsored by Panasonic）
// URL: https://atcoder.jp/contests/abc197/tasks/abc197_c
// Memory Limit: 1024 MB
// Time Limit: 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include<bits/stdc++.h>
typedef long long int ll;
#define pb push_back
#define pi  3.141592653589793238462643383279
#define int long long
#define lld long double
#define ff first
#define ss second
#define endl '\n'
#define all(x) (x).begin(), (x).end()
#define rep(i,x,y) for(int i=(int)x; i<y; i++)
#define VI vector <int>
#define VVI vector <VI>
#define pii pair<int, int>
#define ppi pair<pii, int>
#define mii map<int, int>
#define mci map<char, int>
#define miv map<int, VI>
#define mis map<int, set<int>>
#define high_functioning_sociopath  ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;
const unsigned int M = 998244353;
/*_____________________________THE GAME IS ON_____________________________*/
void solve()
{
      int n;
      cin >> n;
      int res = 1e17;
      vector<int>arr(n);
      for(int i=0;i<n;i++) cin >> arr[i];
      for(int mask=0;mask<(1<<(n-1));mask++)
      {
      	   int x = 0;
      	   int o = 0;
      	   for(int i=0;i<n;i++)
      	   {
      	   	   if(!(mask&(1<<i)))
      	   	   {
      	   	   	   o|=arr[i];
      	   	   }
      	   	   else
      	   	   {
      	   	   	   o|=arr[i];
      	   	   	   x^=o;
      	   	   	   o=0;
      	   	   }
      	   }
      	   x^=o;
      	   res = min(x,res);
      }
      cout << res;
}
int32_t main()
{
   high_functioning_sociopath
   //pre();
   int t=1;
   //cin>>t;
   while(t--)
   {
      solve();
   }
}


#include<bits/stdc++.h>
#define int long long
#define endl "\n"
using namespace std;

const int max_n = 2010;
const int Mod = 1e9+7;
const int inf = 1e18;
const int lim = 3e3+20;

char a[max_n][max_n];
int dist[max_n][max_n],visited[max_n][max_n];
int v_char[26];
vector<pair<int,int> > adj[26];

pair<int,int> dir[4] = {{-1,0},{1,0},{0,1},{0,-1}};

signed main(){
    ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
	int n,m;cin>>n>>m;
	char a[n][m];

	pair<int,int> s,e;

	for(int i=0;i<n;i++){
		for(int j=0;j<m;j++){
			cin>>a[i][j];
			if(a[i][j]=='S') s={i,j};
			if(a[i][j]=='G') e={i,j};

			if(a[i][j]>='a' && a[i][j]<='z'){
				adj[a[i][j]-'a'].push_back({i,j});
			}
		}
	}

	queue<pair<int,int> > q;
	q.push(s);

	while(q.size()>0){
		pair<int,int> c = q.front();
		q.pop();

		for(int i=0;i<4;i++){
			pair<int,int> t(c.first+dir[i].first,c.second+dir[i].second);

			if(t.first>=0 && t.first<n && t.second>=0 && t.second<m){
				if(!visited[t.first][t.second] && a[t.first][t.second]!='#'){
					q.push(t);
					dist[t.first][t.second]=dist[c.first][c.second]+1;
					visited[t.first][t.second]=1;
				}
			}
		}

		char X = a[c.first][c.second];
		if(X>='a' && X<='z'){
			if(!v_char[X-'a']){
				v_char[X-'a']=1;
				for(pair<int,int> t:adj[X-'a']){
					if(!visited[t.first][t.second] && a[t.first][t.second]!='#'){
						q.push(t);
						dist[t.first][t.second]=dist[c.first][c.second]+1;
						visited[t.first][t.second]=1;
					}
				}
			}
		}
	}

	if(dist[e.first][e.second]==0){
		cout<<-1<<endl;
	}else{
		cout<<dist[e.first][e.second]<<endl;
	}
}


#pragma GCC optimize("O3")
#include<bits/stdc++.h>
using namespace std;
#define SET0(a) memset(a,0,sizeof(a))
#define FOR(i,a,b) for(int i=(a);i<=(b);i++)
#define DWN(i,a,b) for(int i=(a);i>=(b);i--)

typedef long long ll;

const ll INF=LLONG_MAX;
typedef pair<ll,ll> PII;

const int N=1e5+5;
ll d[N];
struct node{
    ll to,next,w,k;
}e[N<<1];
int head[N],tot;
void add(ll u,ll v,ll w,ll k){e[tot].to=v;e[tot].w=w;e[tot].k=k;e[tot].next=head[u];head[u]=tot++;}
bool vis[N];
int n,m;
int s,t;

ll dijk(){
    for(int i=1;i<=n;i++) d[i]=INF;

    priority_queue<PII,vector<PII>,greater<PII> > pque;
    pque.push({0,s});
    d[s]=0;

    while(pque.size()){
        auto hd=pque.top(); pque.pop();
        int ver=hd.second;

        if(vis[ver]) continue;
        vis[ver]=true;

        for(int i=head[ver];~i;i=e[i].next){
            int go=e[i].to;
            int w=e[i].k-(d[ver]%e[i].k==0?e[i].k:d[ver]%e[i].k)+e[i].w;
            if(d[go]>d[ver]+w){
                d[go]=d[ver]+w;
                pque.push({d[go],go});
            }
        }
    }

    if(d[t]==INF) return -1;
    else return d[t];
}

int main(){
    memset(head,-1,sizeof head);
    cin>>n>>m>>s>>t;
    while(m--){
        ll u,v,w,k;
        cin>>u>>v>>w>>k;
        add(u,v,w,k);
        add(v,u,w,k);
    }

    cout<<dijk()<<endl;
    return 0;
}

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

using ll = long long;
using ld = long double;

using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vld = vector<ld>;
using vvld = vector<vld>;

#define fi first
#define se second
#define pb push_back
#define all(a) a.begin(),a.end()
#define rep(i,start,end) for(ll i=start;i<(ll)(end);i++)

using T = tuple<int,ll,ll>;
using P = pair<ll,int>;

int main(){
  int n,m,x,y;
  cin>>n>>m>>x>>y;
  x--;y--;

  vector<vector<T>> graph(n);
  rep(i,0,m){
    int a,b;
    ll t,k;
    cin>>a>>b>>t>>k;
    a--;b--;
    graph[a].pb({b,t,k});
    graph[b].pb({a,t,k});
  }

  vll dist(n,1e18);
  dist[x]=0;

  priority_queue<P,vector<P>,greater<P>> que;
  que.push({0,x});

  while(!que.empty()){
    auto [time,now] = que.top();
    que.pop();

    if(dist[now]<time){
      continue;
    }

    for(auto [next,time2,k]:graph[now]){
      ll start=time+(k-time%k)%k;
      if(dist[next]>start+time2){
        que.push({start+time2,next});
        dist[next]=start+time2;
      }
    }
  }

  if(dist[y]>=1e17){
    cout<<-1<<endl;
  }
  else{
    cout<<dist[y]<<endl;
  }
}


#include <bits/stdc++.h>
#define fi first
#define se second

//#define ivorysi
#define enter putchar('\n')
#define space putchar(' ')
#define pii pair<int,int>
#define MOD 998244353
#define MAXN 100005
typedef long long int64;
using namespace std;

template<class T>
void read(T &res) {
	res = 0;T f = 1;char c = getchar();
	while(c < '0' || c > '9') {
		if(c == '-') f = -1;
		c = getchar();
	}
	while(c >= '0' && c <= '9') {
		res = res * 10 + c - '0';
		c = getchar();
	}
	res *= f;
}
template<class T>
void out(T x) {
	if(x < 0) {x = -x;putchar('-');}
	if(x >= 10) out(x / 10);
	putchar('0' + x % 10);
}

int T,N,a[MAXN];
string nm[2] = {"First","Second"};
void Solve() {
	read(N);
	for(int i = 1 ; i <= N ; ++i) {
		read(a[i]);
	}
	sort(a + 1,a + N + 1);
	int t = 0;t ^= (N & 1);
	if(N % 2 == 0) {
		bool f = 1;
		for(int i = N ; i >= 1 ; i -= 2) {
			if(a[i] != a[i - 1]) {f = 0;break;}
		}
		t ^= f;
	}
	cout << nm[t] << endl;
}
int main() {
#ifdef ivorysi
	freopen("f1.in","r",stdin);
#endif
	read(T);
	while(T--) {
		Solve();
	}
	return 0;
}

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

void solve(){
    ll n;
    cin>>n;
    vector<ll>v;
    for(ll i=2; i*i<=n; i++){
      for(int j=2; j<=50;j++){
        ll x = pow(i,j);
        if(x>n){
          break;
        }
        else{
          v.push_back(pow(i,j));
        }
      }
    }
    sort(v.begin(),v.end());
    v.erase(unique(v.begin(),v.end()),v.end());
    cout<<n-v.size()<<endl;
    return;
}

int main(){
  #ifndef ONLINE_JUDGE
  freopen("/home/shubham/Desktop/codes/input.txt", "r", stdin);
  freopen("/home/shubham/Desktop/codes/output.txt", "w", stdout);
  #endif
  ll t;
  // cin>>t;
  t = 1;
  while(t--){
    solve();
  }
  return 0;
}


#include <iostream>
using namespace std;

int main() {
    int a,b;cin>>a>>b;
    cout<<(a+b)/2<<" "<<(a-b)/2<<endl;
	return 0;
}

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

double pi = 3.141592653589793238;
const ll LL_INF_BIG = 1e18 + 7;
const ll LL_INF = 1e9 + 7;
const int INF = 1e9 + 7;

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

template <class T> void chmin(T& a, T b) {
    if (a > b) a = b;
    return;
}

template <class T> void chmax(T& a, T b) {
    if (a < b) a = b;
    return;
}

vector<pair<ll, ll>> prime_factorize(ll N) {
    vector<pair<ll, ll>> res;
    for (ll i = 2; i * i <= N; i++) {
        if (N % i != 0) continue;
        ll exp = 0;
        while (N % i == 0) {
            exp++;
            N /= i;
        }
        res.push_back({i, exp});
    }
    if (N != 1) res.push_back({N, 1});
    return res;
}

ll mod_pow(ll a, ll n, ll mod) {
    ll res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

ll modinv(ll a, ll m) {
    ll b = m;
    ll u = 1;
    ll v = 0;
    while (b) {
        ll t = a / b;
        a -= t * b;
        swap(a, b);
        u -= t * v;
        swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}

const int MAX_COM = 10000000;
const int MOD = 1000000007;

ll fac[MAX_COM], finv[MAX_COM], inv[MAX_COM];

void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX_COM; i++) {
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

ll COM(int n, int k) {
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

struct UnionFind {
    vector<int> parents, siz;

    UnionFind(int N) : parents(N, -1), siz(N, 1) {}

    int root(int x) {
        if (parents.at(x) == -1) return x;
        return parents.at(x) = root(parents.at(x));
    }

    bool unite(int x, int y) {
        int rx = root(x);
        int ry = root(y);
        if (rx == ry) return false;
        if (siz.at(rx) > siz.at(ry)) swap(rx, ry);
        parents.at(rx) = ry;
        // Update the size only at root.
        siz.at(ry) += siz.at(rx);
        return true;
    }

    bool same(int x, int y) {
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }

    // If the size is needed, we need to see it at root.
    int size(int x) { return siz.at(root(x)); }
};

struct Edge {
    ll to;
    ll weight;
    Edge(ll t, ll w) : to(t), weight(w) {}
};

// using Edge = pair<int, pair<int, int>>; // w, u, v

using Graph = vector<vector<Edge>>;

Graph G;

vector<Edge> edge;

ll N,K;
vector<ll> A,CNT;

ll answer;
vector<ll> answers;

void input() {
    cin >> N >> K;
    A.resize(N);
    CNT.resize(N);
    for (int i = 0; i < N; i++) cin >> A[i];
}

void solve() {
    for (int i = 0; i < N; i++) CNT[A[i]]++;

    for (int i = 0; i < N; i++) {
        if(CNT[i] < K) {
            ll dif = K - CNT[i];
            answer += i * (dif);
            K -= dif;
            if (K == 0) break;
        }
    }
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    // ifstream in("input.txt");
    // cin.rdbuf(in.rdbuf());
    input();
    solve();
    // cout << fixed << setprecision(15);
    cout << answer << "\n";
    // for (auto answer : answers) cout << answer << "\n";
    return 0;
}


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

double amount(ll v,ll p)
{
return (v*p);
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);

ll n;  cin>>n;
double x ; cin>>x;
pair <int,int> pr[n];
for(ll i=0;i<n;i++)
{
ll v,p;  cin>>v>>p;
pr[i]={v,p};
}
double sum=0;
ll i;
for( i=0;i<n;i++)
{
sum+=amount(pr[i].first,pr[i].second);
if(sum>(x*100))
{
	cout<<i+1;
	break;
}
}
if(sum<=x*100)
cout<<-1;
}

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

#define rep(i, a, b) for (int i = (a), i##end = (b); i < i##end; ++i)
#define per(i, a, b) for (int i = (a) - 1, i##end = (b); i >= i##end; --i)
#define REP(i, a) rep(i, 0, a)
#define PER(i, a) per(i, a, 0)

namespace IO {
	const int MAXIOSIZE = 1 << 24 | 1;
	unsigned char buf[MAXIOSIZE], *p1, *p2;
	#define gc (p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1 << 24, stdin), p1 == p2) ? EOF : *p1++)
	template <typename T> void read(T& x) {
		x = 0; char ch = gc; bool flg = false;
		for (; ch < '0' || '9' < ch; ch = gc) if (ch == '-') flg |= true;
		for (; '0' <= ch && ch <= '9'; ch = gc) x = x * 10 + ch - '0';
		flg ? x = -x : 0;
	}
	template <typename T> void out(const T& x) { if (x > 9) out(x / 10); putchar(x % 10 + '0'); }
	template <typename T> inline void write(const T& x, const char& ed = ' ') { if (x < 0) putchar('-'), out(-x); else out(x); putchar(ed); }
}

typedef long long ll;

const int MAXVAL = 50 + 10;
const int Prime[] = { 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47 };

int n;
ll fans = LONG_LONG_MAX;
bool tag[MAXVAL];
vector<int> frac[MAXVAL];

int main() {
	#ifdef LOCAL
		freopen("in.txt", "r", stdin);
	#endif
	IO::read(n);

	REP(i, n) {
		ll x; IO::read(x);
		for (ll p = 2; p <= x; ++p) if ((x % p) == 0) {
			frac[i].push_back(p);
			while ((x % p) == 0) x /= p;
		}
	}

	REP(S, 1 << 15) {
		ll ans = 1; int curtag[MAXVAL];
		memset(curtag, 0, sizeof curtag);
		REP(i, 15) if ((S >> i) & 1) ans *= Prime[i], curtag[Prime[i]] = true;
		if (ans > fans) continue;
		bool OK = true;
		REP(i, n) {
			bool ok = false;
			for (int f : frac[i]) if (curtag[f]) {
				ok = true;
				break;
			}
			if (!ok) {
				OK = false;
				break;
			}
		}
		if (OK) fans = ans;
	}
	IO::write(fans);
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef string str;
typedef long long ll;
typedef double db;
typedef pair<int,int> pi;
#define fi first
#define se second
#define int ll
#define all(x) begin(x), end(x)
typedef vector<int> vi;
typedef vector<str> vs;
#define pb push_back
#define rall(x) rbegin(x), rend(x)
#define pf push_front
#define lb lower_bound
#define ub upper_bound
#define mp make_pair
#define sz(x) (int)x.size()
#define endl "\n"
#define boost ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define ROF(i,a,b) for (int i = (b)-1; i >= (a); --i)
void IO(){
#ifndef ONLINE_JUDGE
    freopen("D:///docs///coding///c++///codes///input.txt", "r", stdin);
    freopen("D:///docs///coding///c++///codes///output.txt", "w", stdout);
#endif
}
int32_t main(){
// IO();
boost;
	int n,s,d; cin>>n>>s>>d;
	FOR(i,0,n)
	{
		int a,b; cin>>a>>b;
		if(a<s && b>d)
		{
			cout<<"Yes"<<endl;
			return 0;
		}
	}
	cout<<"No"<<endl;
return 0;
}
//  check data type
//  return function at recursions

#include <iostream>

using namespace std;

int main()
{
    int n, s, d;
    cin >> n >> s >> d;
    bool ans = false;

    for (int i = 0; i < n; i++)
    {
        int x, y;
        cin >> x >> y;
        if (x < s && y > d)
        {
            ans = true;
        }
    }

    if (ans)
    {
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }
    return 0;
}


#include <bits/stdc++.h>
#define LL long long
using namespace std;
template <typename T> void read(T &x){
	x = 0; int f = 1; char ch = getchar();
	while (!isdigit(ch)) {if (ch == '-') f = -1; ch = getchar();}
	while (isdigit(ch)) {x = x * 10 + ch - '0'; ch = getchar();}
	x *= f;
}
inline void write(int x){if (x > 9) write(x/10); putchar(x%10+'0'); }

const int N = 505;

inline void gg(){
	cout << "No\n",exit(0);
}

int n;
LL c[N][N];
LL a[N],b[N];

int main(){
	int i,j;
	cin >> n;
	for (i = 1; i <= n; ++i) for (j = 1; j <= n; ++j) cin >> c[i][j];

	LL mn = c[1][1];
	for (i = 1; i <= n; ++i) a[i] = c[i][1],mn = min(mn,a[i]);
	for (i = 1; i <= n; ++i) a[i] -= mn;
	for (i = 1; i <= n; ++i) b[i] = c[1][i] - a[1];

	for (i = 1; i <= n; ++i) for (j = 1; j <= n; ++j) if (a[i] + b[j] != c[i][j]) gg();
	for (i = 1; i <= n; ++i) if (a[i] < 0 || b[i] < 0) gg();

	cout << "Yes\n";
	for (i = 1; i <= n; ++i) cout << a[i] << (i<n?' ':'\n');
	for (i = 1; i <= n; ++i) cout << b[i] << (i<n?' ':'\n');
	return 0;
}

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

typedef long long ll;
typedef long double ld;
#define FOR(i, a, b) for (int i = a; i < (b); i++)
#define range(a) a.begin(), a.end()
#define endl "\n"
#define Yes() cout << "Yes" << endl
#define No() cout << "No" << endl
#define MP make_pair
using P = pair<int, int>;
const unsigned long long mod = 1e9 + 7;
const long long INF = 1LL<<60;
void chmin(long long &a, long long b) { if (a > b) a = b; }
void chmax(long long &a, long long b) { if (a < b) a = b; }

// @param m `1 <= m`
// @return x mod m
constexpr ll safe_mod(ll x, ll m) {
    x %= m;
    if (x < 0) x += m;
    return x;
}

constexpr pair<ll, ll> inv_gcd(ll a, ll b) {
    a = safe_mod(a, b);
    if (a == 0) return {b, 0};

    // Contracts:
    // [1] s - m0 * a = 0 (mod b)
    // [2] t - m1 * a = 0 (mod b)
    // [3] s * |m1| + t * |m0| <= b
    ll s = b, t = a;
    ll m0 = 0, m1 = 1;

    while (t) {
        ll u = s / t;
        s -= t * u;
        m0 -= m1 * u;  // |m1 * u| <= |m1| * s <= b

        // [3]:
        // (s - t * u) * |m1| + t * |m0 - m1 * u|
        // <= s * |m1| - t * u * |m1| + t * (|m0| + |m1| * u)
        // = s * |m1| + t * |m0| <= b

        auto tmp = s;
        s = t;
        t = tmp;
        tmp = m0;
        m0 = m1;
        m1 = tmp;
    }
    // by [3]: |m0| <= b/g
    // by g != b: |m0| < b/g
    if (m0 < 0) m0 += b / s;
    return {s, m0};
}

// (rem, mod)
pair<ll, ll> crt(const vector<ll>& r,
                                    const vector<ll>& m) {
    assert(r.size() == m.size());
    int n = int(r.size());
    // Contracts: 0 <= r0 < m0
    ll r0 = 0, m0 = 1;
    for (int i = 0; i < n; i++) {
        assert(1 <= m[i]);
        ll r1 = safe_mod(r[i], m[i]), m1 = m[i];
        if (m0 < m1) {
            swap(r0, r1);
            swap(m0, m1);
        }
        if (m0 % m1 == 0) {
            if (r0 % m1 != r1) return {0, 0};
            continue;
        }
        // assume: m0 > m1, lcm(m0, m1) >= 2 * max(m0, m1)

        // (r0, m0), (r1, m1) -> (r2, m2 = lcm(m0, m1));
        // r2 % m0 = r0
        // r2 % m1 = r1
        // -> (r0 + x*m0) % m1 = r1
        // -> x*u0*g % (u1*g) = (r1 - r0) (u0*g = m0, u1*g = m1)
        // -> x = (r1 - r0) / g * inv(u0) (mod u1)

        // im = inv(u0) (mod u1) (0 <= im < u1)
        ll g, im;
        tie(g, im) = inv_gcd(m0, m1);

        ll u1 = (m1 / g);
        // |r1 - r0| < (m0 + m1) <= lcm(m0, m1)
        if ((r1 - r0) % g) return {0, 0};

        // u1 * u1 <= m1 * m1 / g / g <= m0 * m1 / g = lcm(m0, m1)
        ll x = (r1 - r0) / g % u1 * im % u1;

        // |r0| + |m0 * x|
        // < m0 + m0 * (u1 - 1)
        // = m0 + m0 * m1 / g - m0
        // = lcm(m0, m1)
        r0 += x * m0;
        m0 *= u1;  // -> lcm(m0, m1)
        if (r0 < 0) r0 += m0;
    }
    return {r0, m0};
}

void solve(){
	ll x, y, p, q;
	cin >> x >> y >> p >> q;
	ll ans = INF;
	FOR(i,x,x+y){
		FOR(j,p,p+q){
			auto re =  crt({i, j}, {2 * (x + y), (p + q)});
			if(re.first == 0 && re.second == 0){
				continue;
			}
			ans = min(ans, re.first);
		}
	}
	if(ans==INF){
		cout << "infinity" << endl;
	}else{
		cout << ans << endl;
	}
}

int main(void){
	ios::sync_with_stdio(0);
	cin.tie(0);
	int T;
	cin >> T;
	while(T--){
		solve();
	}

	return 0;
}


#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define per(i,a,b) for(int i=(a);i>=(b);i--)
#define REP(i,n) for(int i=0;i<(n);i++)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define SZ(x) ((int)(x).size())
#define ALL(x) (x).begin(),(x).end()
using namespace std;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef long long ll;

template<class T> void read(T &x){
	int f=0; x=0; char ch=getchar();
	for(;!isdigit(ch);ch=getchar()) f|=(ch=='-');
	for(;isdigit(ch);ch=getchar()) x=x*10+ch-'0';
	if(f) x=-x;
}

int n;

int main(){
	read(n);
	REP(i,n){
		int A=i*2%n;
		int B=(i*2+1)%n;
		printf("%d %d\n",A+1,B+1);
	}

	return 0;
}

#include <bits/stdc++.h>

int n;

inline int highbit(int a){
	for(int i = 10; ~i; --i)
		if(a & (1 << i))
			return 1 << i;
	return 0;
}

int main(){
	std::scanf("%d", &n);
	for(int i = 1; i <= n; ++i){
		int a = i * 2, b = i * 2 + 1;
		while(a > n) a -= highbit(a);
		while(b > n) b -= highbit(b);
		if(!a) a = 1;
		if(!b) b = 1;
		std::printf("%d %d\n", a, b);
	}
}


#include<bits/stdc++.h>

using namespace std;

#define endl "\n"
#define lln long long int
#define ld long double
#define all(x) (x).begin(),(x).end()
#define IOS ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
const int MOD = 1e9 + 7;

int main(){
    IOS;

    double a, b;
    cin >> a >> b;
    cout << ((a - b) * 100) / a << endl;
    return 0;
}

// g++ -std=c++11 a.cpp
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<unordered_map>
#include<utility>
#include<cmath>
#include<random>
#include<cstring>
#include<queue>
#include<stack>
#include<bitset>
#include<cstdio>
#include<sstream>
#include<random>
#include<iomanip>
#include<assert.h>
#include<typeinfo>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
#define FOR(i,a) for(auto i:a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
#define show1d(v) {rep(_,v.size())cout<<" "<<v[_];cout<<endl;}
#define show2d(v) {rep(__,v.size())show1d(v[__]);}
using namespace std;
//kaewasuretyuui
typedef long long ll;
#define int ll
typedef int Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
#define mt make_tuple
typedef tuple<int,int,int> tp;
typedef vector<tp> vt;
typedef vector<vt>vvt;
template<typename A,typename B>bool cmin(A &a,const B &b){return a>b?(a=b,true):false;}
template<typename A,typename B>bool cmax(A &a,const B &b){return a<b?(a=b,true):false;}
const double PI=acos(-1);
const long double EPS=1e-9;
Def inf = sizeof(Def) == sizeof(long long) ? 2e18 : 1e9+10;
int dx[]={-1,0,1,0};
int dy[]={0,1,0,-1};
#define yes cout<<"Yes\n"
#define no cout<<"No\n"

int dp[200200][17][2];
signed main(){
	ios::sync_with_stdio(false);
	cin.tie(0);

	double a,b;
	cin>>a>>b;
	cout<<shosu(9)<<100-100*b/a<<endl;
}


#include <iostream>
#include <iomanip>
#include <cmath>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <tuple>
#include <string>
#include <list>
#include <map>
#include <unordered_map>
using namespace std;

long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

// a^{-1} mod を計算する
long long modinv(long long a, long long mod) {
    return modpow(a, mod - 2, mod);
}

void f(vector<vector<int>>& a,vector<vector<int>>& b,int N,int K){
    for(int i=0;i<N-1;i++){
        for(int j=i+1;j<N;j++){
            int l=0;
            for(int k=0;k<N;k++){
                if(a[k][i]+a[k][j]>K){
                    break;
                }
                l+=1;
            }
            if(l==N){
                b[i][j]=1;
                b[j][i]=1;
            }
        }
    }
}

void g(vector<vector<int>>& a,vector<vector<int>>& c,int N,int K){
    for(int i=0;i<N-1;i++){
        for(int j=i+1;j<N;j++){
            int l=0;
            for(int k=0;k<N;k++){
                if(a[i][k]+a[j][k]>K){
                    break;
                }
                l+=1;
            }
            if(l==N){
                c[i][j]=1;
                c[j][i]=1;
            }
        }
    }
}

int h(vector<vector<int>>& b,vector<int>& x,int N){
    int M=1;
    vector<int> a(N);
    for(int i=0;i<N;i++){
        a[i]=0;
    }
    stack<int> d;
    for(int i=0;i<N;i++){
        int j=0;
        if(a[i]==0){
            d.push(i);
            a[i]=1;
        }
        while(!d.empty()){
            int k=d.top();
            d.pop();
            j+=1;
            for(int l=0;l<N;l++){
                if(b[k][l]==1 && a[l]==0){
                    d.push(l);
                    a[l]=1;
                }
            }
        }
        if(j>1){
            x.push_back(j);
            M=max(M,j);
        }
    }
    return M;
}

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

/*
    sort(b.begin(),b.end(),[](const vector<int> &alpha,const vector<int> &beta){return alpha[0] < beta[0];});
    第一成分で昇順
    sort(r.begin(),r.end(),[](const vector<int> &alpha,const vector<int> &beta){return alpha[1] > beta[1];});
    第二成分で降順
*/

long long int gcd(long long int a, long long int b)
{
    if (a < b) {
        a ^= b;
        b ^= a;
        a ^= b;
    }

    return b ? gcd(b, a % b) : a;
}

long long int lcm(long long int a, long long int b)
{
    return a * b / gcd(a, b);
}

int main(){
    long long int N,W;
    cin>>N>>W;
    cout<<N/W<<endl;
    return 0;
}

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

#define fo(i,n) for(i = 0 ; i < n ; i++)
#define deb(x) cout << #x << "=" << x << endl
#define deb2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << endl
#define all(x) x.begin(), x.end()
#define sortall(x) sort(all(x))
#define tr(it, a) for(auto it = a.begin(); it != a.end(); it++)
#define nl "\n"
#define mod 1000000007
#define pb push_back
#define ff first
#define ss second
#define PI 3.141592653589793238

typedef long long int lli;
typedef unsigned long long int ulli;
typedef long double ld;
typedef pair<lli, lli> plli;
typedef priority_queue<lli> pqb;
typedef priority_queue<lli, vector<lli>, greater<lli>> pqs;

struct custom_hash {
	static uint64_t splitmix64(uint64_t x) {
		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);
	}
};

void GO_GO_GO() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
}

void BYE_BYE() {cerr << "Time elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";}

bool primeArr[1000001] = {false};

lli fact[1000001];

lli lazy[1000001] = {0};

vector<lli> primes;

/****************************************************************************************/
int main() {
	GO_GO_GO();

	lli t = 1;
	// cin >> t;
	while (t--) {
		lli i = 0;
		string n;
		lli k;
		cin >> n >> k;
		while (k--) {
			string t1 = n;
			sortall(t1);
			string t2 = t1;
			reverse(all(t1));
			n = to_string(stoi(t1) - stoi(t2));
		}
		cout << n << nl;
	}
	BYE_BYE();
	return 0;
}


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

#define INF ((1<<30)-1)
#define LLINF (1LL<<60)
#define EPS (1e-10)

const ll mod = 1e9 + 7;

ll f1(ll n) {
    if (n < 0) return 0;
    ll res = n * (n + 1) / 2;
    return res % mod;
}

ll f2(ll n) {
    if (n < 0) return 0;
    ll res = f1(n);
    res %= mod;
    res *= res;
    res %= mod;
    return res;
}

void solve() {
    int n, a, b;
    cin >> n >> a >> b;
    ll x = ((f1(n - a - b + 1) * (n - b + 1) % mod) * (n - a + 1)) % mod;
    ll y = f2(n - a - b + 1) % mod;
    ll ans = (x*4) % mod - (y*4) % mod;
    cout << (ans + mod) % mod << endl;
}

int main() {
    int T;
    cin >> T;
    rep(t, T) {
        solve();
    }
}

#include <iostream>
#include <algorithm>

using namespace std;

const long long waru = 1000000007;

int main()
{
	long long t;
	cin >> t;

	long long ans[100000];

	for (long long q = 0; q < t; q++) {
		long long n, a, b;
		cin >> n >> a >> b;

		if (a < b) swap(a, b);

		long long answer = 0;
		long long m_answer = 0;

		if (n < a + b) {
			ans[q] = 0;
			continue;
		}

		answer = ((n - a + 1) * (n - b + 1) * 4) % waru;
		long long pk = ((n - a - b + 1) * (n - a - b + 2) / 2) % waru;
		answer = (answer * pk) % waru;

		long long f = ((n - a - b + 1) * (n - a - b + 2) / 2) % waru;
		m_answer = (f * f * 4) % waru;

		answer = (answer - m_answer + waru) % waru;

		ans[q] = answer;
	}

	for (long long i = 0; i < t; i++) {
		cout << ans[i] << endl;
	}

}


//#include <atcoder/mincostflow>
#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
using namespace std;
typedef pair<long long,long long> ii;
typedef long long lint;

signed main(){
	//freopen("i.txt","r",stdin);
	ios_base::sync_with_stdio(false); cin.tie(0);

	vector<int> v(4);
	for(int i = 0;i < 4;i++) cin >> v[i];

	sort(all(v));

	do{
		if(v[0] + v[1] == v[2] + v[3]){
			cout << "Yes\n";
			return 0;
		}
		if(v[0] == v[1] + v[2] + v[3]){
			cout << "Yes\n";
			return 0;
		}
	} while(next_permutation(all(v)));

	cout << "No\n";
}

#include<bits/stdc++.h>
#define ll long long
#define mp make_pair
#define f(i,n) for(int i=0;i<n;i++)
#define F first
#define S second
#define pb push_back

using namespace std;

void test(){
	string s;
	cin>>s;
	int a[3]={0};
	int n = s.length();
	int sum = 0;
	f(i,n){
		int x = s[i]-'0';
		a[x%3]++;
		sum = sum + x;
	}
	sum = sum%3;
	if(sum==0)
		cout<<"0\n";
	else if(n==1)
		cout<<"-1\n";
	else if(sum==1){
		if(a[1]>0){
			cout<<"1\n";
		}else{
			if(a[0]>0 or a[2]>2){
				cout<<"2\n";
			}else
				cout<<"-1\n";
		}
	}else{
		if(a[2]>0){
			cout<<"1\n";
		}else {
			if(a[0]>0 or a[1]>2){
				cout<<"2\n";
			}else
				cout<<"-1\n";
		}
	}

}

int main(){
	std::ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int tests=1;
	// cin>>tests;
	while(tests--){
		test();
	}
}


#include <bits/stdc++.h>
using namespace std;
//ofstream cout("output.out");

#define fast() {ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);}
#define pb push_back
#define vi vector<int>
#define vl vector<ll>
#define vii vector<vector<int>>
#define mii map<int, int>
#define pii pair<int, int>
#define qii priority_que<int, vector<int>, greater<int>>
#define For(i, n) for(int i = 0; i < n; ++i)
#define For1(i, n) for(int i = 1; i <= n; ++i)
#define Forlr(i, l, r) for(int i = l; i <= r; ++i)
#define Forrl(i, r, l) for(int i = r; i >= l; --i)
#define o(a) { cout << #a << ":" << (a) <<" ";}
#define ov(a) {For(i, a.size()) cout << a[i] <<" ";}
#define ovv(a) {For(i, a.size()) {For(j, a[i].size()) cout << a[i][j] <<" ";cout <<"\n";}}
using ll = long long;
int n, m, k, q;
const ll INF = 1e18 + 5;
const int nax = 1e5 + 5;
const ll mod = 1e9 + 7;
void solve(){
	cin >> n;
	vl a(n);
	For(i, n) cin >> a[i];
	sort(a.begin(), a.end());
	auto it  = unique(a.begin(), a.end());
	a.resize(distance(a.begin(), it));
	//For(i, a.size()) cout << a[i] <<" ";
	ll rs = 1ll;
	ll pr = 0;
	For(i, a.size()){
		rs = rs * (a[i] - pr + 1ll) % mod;
		pr = a[i];
	}
	//rs = rs * 2 ;
	cout << rs <<"\n";
}
int main ()
{
	fast();
	int t = 1;
	//cin >> t;
	while(t--){
		solve();
	}
  	return 0;
}
/* stuff you should look for
	* int overflow, array bounds
	* special cases (n=1?)
	* do smth instead of nothing and stay organized
	* WRITE STUFF DOWN
	* DON'T GET STUCK ON ONE APPROACH
*/

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

const int N=1e6+5,mod=1e9+7;
int n,a[N];
int main() {
    cin>>n;
    for(int i=1;i<=n;i++) scanf("%d",&a[i]);
    sort(a+1,a+1+n);
    long long ans=1;
    for(int i=n-1;~i;i--) ans*=(a[i+1]-a[i]+1),ans%=(mod);
    cout<<ans;
}


#include<bits/stdc++.h>

struct em {
    using type = std::pair<unsigned long, unsigned long>;
    static type id(){ return {}; }
    static type op(const type& a, const type& b){return {a.first + b.first, a.second + b.second};}
};

// from https://kazuma8128.hatenablog.com/entry/2018/11/29/093827

template <typename M> // Mは 型type, 単位元id(), 演算op() を持つモノイド
class dynamic_segment_tree {
    using T = typename M::type;
    struct node {
        int pos;
        T val, all;
        node *l, *r;
        node(int p, T v)
                : pos(p), val(v), all(v), l(nullptr), r(nullptr) {}
    };
private:
    const int n;
    node *root;
public:
    dynamic_segment_tree(int n_) :
            n(1 << (int)ceil(log2(n_))), root(nullptr) {}
    void update(int p, T val) {
        root = change(root, p, val, 0, n);
    }
    T find(int l, int r) {
        return get(l, r, root, 0, n);
    }
private:
    T value(node *t) {
        return t ? t->all : M::id();
    }
    T get(int l, int r, node* t, int lb, int ub) {
        if (!t || ub <= l || r <= lb) return M::id();
        if (l <= lb && ub <= r) return t->all;
        int c = (lb + ub) / 2;
        T res = get(l, r, t->l, lb, c);
        if (l <= t->pos && t->pos < r) res = M::op(res, t->val);
        return M::op(res, get(l, r, t->r, c, ub));
    }
    node *change(node* t, int p, T val, int lb, int ub) {
        if (!t) return new node(p, val);
        if (t->pos == p) {
            t->val = val;
            t->all = M::op(value(t->l), M::op(t->val, value(t->r)));
            return t;
        }
        int c = (lb + ub) / 2;
        if (p < c) {
            if (p > t->pos) std::swap(p, t->pos), std::swap(val, t->val);
            t->l = change(t->l, p, val, lb, c);
        }
        else {
            if (p < t->pos) std::swap(p, t->pos), std::swap(val, t->val);
            t->r = change(t->r, p, val, c, ub);
        }
        t->all = M::op(value(t->l), M::op(t->val, value(t->r)));
        return t;
    }
};

int main(){
    using namespace std;
    unsigned long N, M, Q;
    cin >> N >> M >> Q;
    vector<unsigned long> A(N), B(M);
    dynamic_segment_tree<em> a(200000000), b(200000000);
    a.update(0, {0, N});
    b.update(0, {0, M});
    const auto dec{[](const auto a, unsigned long x) -> pair<unsigned long, unsigned long> {
        return {a.first - x, a.second - 1};
    }};
    const auto enc{[](const auto a, unsigned long x) -> pair<unsigned long, unsigned long> {
        return {a.first + x, a.second + 1};
    }};
    const auto diff{[](auto& sgt, unsigned long X){
        const auto [sum, cnt]{sgt.find(0, X)};
        return cnt * X - sum;
    }};
    unsigned long ans{0};
    for(unsigned long i{0}, t, x, y; i < Q; ++i){
        cin >> t >> x >> y;
        auto& v{t == 1 ? A[x - 1] : B[x - 1]};
        auto& now{t == 1 ? a : b}, oppo{t == 1 ? b : a};
        ans -= diff(oppo, v);
        now.update(v, dec(now.find(v, v + 1), v));
        swap(v, y);
        now.update(v, enc(now.find(v, v + 1), v));
        ans += diff(oppo, v);
        cout << ans << endl;
    }
    return 0;
}

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

#define int long long
#define mod 1000000007
#define mod2 998244353
#define pi 3.1415926535897932384626
#define endl '\n'
#define all(x) x.begin(), x.end()
#define deb(x) cout << #x << " : " << x << endl;
#define deb2(x, y) cout << #x << " : " << x << ", " << #y << " : " << y << endl;
#define lmax LLONG_MAX
#define lmin LLONG_MIN

/**************  segment tree code starts  ***************/

const int N = 2e5 + 100;
int tree[4 * N];

void build(int i, int s, int e, vector<int>& a) {
    if(s == e) {
        tree[i] = a[s];
        return;
    }

    int mid = (s + e) / 2;
    build(2 * i, s, mid, a);
    build(2 * i + 1, mid + 1, e, a);

    tree[i] = tree[2 * i] + tree[2 * i + 1];
}

void update(int i, int s, int e, int ind, int val, vector<int>& a) {
    if(s == e) {
        a[ind] = val;
        tree[i] = val;
        return;
    }

    int mid = (s + e) / 2;
    if(ind <= mid)
        update(2 * i, s, mid, ind, val, a);
    else
        update(2 * i + 1, mid + 1, e, ind, val, a);

    tree[i] = tree[2 * i] + tree[2 * i + 1];
}

int query(int i, int s, int e, int l, int r) {
    if(s > r or e < l) return 0;
    if(s >= l and e <= r) return tree[i];

    int mid = (s + e) / 2;
    int left = query(2 * i, s, mid, l, r);
    int right = query(2 * i + 1, mid + 1, e, l, r);

    return left + right;
}

/**************  segment tree code ends  ***************/

void testcase() {
    int r, c, x;
    cin >> r >> c >> x;
    if(x == 0) {
        cout << r * c << endl;
        return;
    }
    vector<int> a(r, c), b(c, r);
    vector<vector<int>> p(x, vector<int>(2));

    for(int i = 0; i < x; i++) {
        int d, e;
        cin >> d >> e;
        d--, e--;
        a[d] = min(a[d], e);
        b[e] = min(b[e], d);
        p[i][0] = e, p[i][1] = d;
    }
    sort(p.begin(), p.end());
    vector<int> g(r + 2);
    build(1, 0, r - 1, g);
    set<int> s;
    int ans = 0, row = 0;

    for(int i = 0; i < r; i++) {
        if(a[i] == 0) break;
        ans += a[i];
        row = i;
    }

    row++;
    int j = 0;
    for(int i = 0; i < c; i++) {
        if(b[i] == 0) break;
        while(j < x and p[j][0] == i) {
            if(s.count(p[j][1]) == 0 and p[j][1] < row) {
                update(1, 0, r - 1, p[j][1], 1, g);
                s.insert(p[j][1]);
            }
            j++;
        }
        int val = query(1, 0, r - 1, 0, b[i] - 1);
        ans += b[i];
        ans -= (min(row, b[i]) - val);
    }

    cout << ans;
}

signed main() {
#ifdef SP
    freopen("in.txt", "r", stdin);
    // freopen("out.txt", "w", stdout);
#endif
    ios::sync_with_stdio(false), cin.tie(NULL);
    srand(chrono::high_resolution_clock::now().time_since_epoch().count());
    int t = 1;
    // cin >> t;
    for(int i = 1; i <= t; i++) {
        // cout << "Case #" << i << ": ";
        testcase();
        cout << endl;
    }
}


#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
#define rep(i,a,b)  for(ll i=a;i<b;i++)
#define nl cout<<endl

#define pii pair<ll,ll>
#define vi  vector<ll>
#define vii vector<pii>
#define mi  map<ll,ll>
#define all(a)  (a).begin(),(a).end()

#define pb push_back
#define ff first
#define ss second
#define hell 1000000007

#define test4(x,y,z,a) cout<<"x is "<<x<<"		y is "<<y<<"		z is "<<z<<"		a is "<<a<<endl;
#define test3(x,y,z) cout<<"x is "<<x<<"		y is "<<y<<"		z is "<<z<<endl;
#define test2(x,y) cout<<"x is "<<x<<"		y is "<<y<<endl;
#define test1(x) cout<<"x is "<<x<<endl;
#define N 300009

ll power(ll a,ll b,ll m)
{
	ll ans=1;
	while(b)
	{
		if(b&1)
			ans=(ans*a)%m;
		b/=2;
		a=(a*a)%m;
	}
	return ans;
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);

	ll n,m;cin>>n>>m;

	if(n==1 and m==0) {
		cout << "1 2"<<endl;
		return 0;
	}
	if(m >= (n-1) ) {
		cout<< -1<<endl;
		return 0;
	}

	if(m == 0) {
		ll curr=1;
		rep(i,1,n+1) {
			cout<<curr<<" "<<curr+1<<endl;
			curr+=2;
		}
	}
	else if(m > 0 ) {
		cout << 1<< " "<< 1000000000<<endl;
		ll diff = m + 1;

		ll curr = 2;
		rep(i,0,diff-1) {
			cout<< curr <<" "<< curr+1<<endl;
			curr += 2;
		}
		ll curr2 = 1e8;

		ll more = 1 + diff - 1;
		more = n- more;
		rep(i,0,more) {
			cout<< curr <<" "<<curr2<<endl;
			curr++,curr2++;
		}
	}
	else
		cout<< -1 << endl;
}

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define mk make_pair
int main(){
    int n,m;
    scanf("%d%d",&n,&m);
    if(n==1&&m==0){
        printf("%d %d\n",1,2);
        return 0;
    }
    if(m<0||m==n||m==n-1){
        printf("-1\n");
    }
    else if(m==0){
         for (int i = 1; i <= n; ++i)
            printf("%d %d\n", i, i + n);
    }
    else{
        printf("%d %d\n",1,1000000);
        int idx=2;
        for(int i=1;i<=m+1;i++){
            printf("%d %d\n",idx,idx+1);
            idx+=2;
        }
        idx=1000010;
        for(int i=m+2;i<n;i++){
            printf("%d %d\n",idx,idx+1);
            idx+=2;
        }
    }
}


#include <algorithm>
#include <numeric>
#include <iomanip>
#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <numeric>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#define DEBUG(x) std::cout << '>' << #x << ':' << x << '\n';
#define PRINTVEC(x) for (int i = 0; i < (int)x.size(); i++) std::cout << x[i] << ' '; std::cout << '\n';
#define PRINTPAIR(x) for (int i = 0; i < (int)x.size(); i++) std::cout << x[i].first << ' ' << x[i].second << '\n'; std::cout << '\n';
#define PRINTSET(x) for (auto it = x.begin(); it != x.end(); it++) { std::cout << *it << ' '; } std::cout << '\n';
#define io std::ios_base::sync_with_stdio(false);std::cin.tie(NULL);
const int INF = 1<<29;
const double PI = acos(-1.0);
typedef long long ll;
const std::vector<int> GRID = {0,1,0,-1,0}; // for(k < 4) r=x+GRID[k],c=y+GRID[k+1]; if(0<=r&&r<m&&0<=c&&c<n) do smthg;
using namespace std;

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

    ll s,p; cin >> s >> p;
    for (int i = 0; i <= sqrt(p); i++) {
        if (i*(s-i) == p) {
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;

    #ifndef ONLINE_JUDGE
    std::cout << '\n' << "Time elapsed : " << 1.0 * clock() / CLOCKS_PER_SEC << " sec \n";
    #endif
    return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i=0; i<(n); i++)
#define rep2(i,n) for (int i=1; i<(n); i++)
using ll = long long;
using P = pair<int,int>;
int main() {
  ll s,p; cin >> s >> p;
  rep2(i,1000100) {
    if(i*(s-i) == p) {
      cout << "Yes" << endl;
      return 0;
    }
  }
  cout << "No" << endl;
}


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

int main(){
    long n;

    cin >> n;
    string s;
    long seven = 0;
    stringstream ss;
    std::string o;

    for(int i = 1; i <= n; i++){
        ss.str("");
        ss << std::dec << i;
        s = ss.str();
        ss.str("");
        ss << std::oct << i;
        o = ss.str();
        for(int j = 0; j < 6; j++){
            if(s[j] == '7' || o[j] == '7'){
                seven++;
                break;
            }
        }
    }

    cout << n - seven << endl;

}

#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/tag_and_trait.hpp>
#include <ext/pb_ds/trie_policy.hpp>
#include <ext/pb_ds/priority_queue.hpp>
#include <ext/rope>
//#include <boost/multiprecision/cpp_int.hpp>

using namespace std;
//using namespace boost::multiprecision;

#define rep(i,n) for(int i=0;i<(n);++i)
#define reps(i,n) for(int i=1;i<=(n);++i)
#define all(x) begin(x),end(x)
#define Fixed fixed << setprecision(12)
//#define int int_fast64_t
using pii = pair<int,int>;
constexpr int32_t INF  = 0x3f3f3f3f;
constexpr int_fast64_t LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr int mod1 = 1e9+7;
constexpr int mod2 = 998244353;

template <class Func>
class FixPoint : Func {
public:
    explicit constexpr FixPoint(Func&& f) noexcept : Func(forward<Func>(f)) {}

    template <class... Args>
    constexpr decltype(auto) operator()(Args&&... args) const {
        return Func::operator()(*this, std::forward<Args>(args)...);
    }
};

template <class Func>
static inline constexpr decltype(auto) makeFixPoint(Func&& f) noexcept {
    return FixPoint<Func>{forward<Func>(f)};
}

template <class A, class B> inline bool chmax(A &a, const B &b) { return b > a && (a = b, true); }
template <class A, class B> inline bool chmin(A &a, const B &b) { return b < a && (a = b, true); }

template <class T> using max_heap = priority_queue<T>;
template <class T> using min_heap = priority_queue<T,vector<T>,greater<T> >;
template <class A, class B> using umap = unordered_map<A,B>;

template <class T> using Max_Heap = __gnu_pbds::priority_queue<T, less<T>, __gnu_pbds::rc_binomial_heap_tag>;
template <class T> using Min_Heap = __gnu_pbds::priority_queue<T, greater<T>, __gnu_pbds::rc_binomial_heap_tag>;
template <class T> using Set = __gnu_pbds::tree<T, __gnu_pbds::null_type, less<T>, __gnu_pbds::rb_tree_tag, __gnu_pbds::tree_order_statistics_node_update>;
template <class K, class V> using Umap = __gnu_pbds::gp_hash_table<K, V>;
template <class T> using Rope = __gnu_cxx::rope<T>;
using Trie = __gnu_pbds::trie<string, __gnu_pbds::null_type, __gnu_pbds::trie_string_access_traits<>, __gnu_pbds::pat_trie_tag, __gnu_pbds::trie_prefix_search_node_update>;

inline int square(int a){ return a * a;}
inline int updiv(int a,int b){ return (a + b - 1) / b; }

constexpr int dx[] = {1,0,-1,0,1,1,-1,-1};
constexpr int dy[] = {0,-1,0,1,1,-1,-1,1};

signed main(){
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout.setf(ios_base::fixed);
    cout.precision(12);

    int n;
    cin >> n;

    int res = 0;
    for(int i = 1; i <= n; ++i){
        int tmp = i;
        while(tmp){
            if(tmp % 10 == 7){
                goto ng;
            }
            tmp /= 10;
        }
        tmp = i;
        while(tmp){
            if(tmp % 8 == 7){
                goto ng;
            }
            tmp /= 8;
        }
        ++res;
        ng:;
    }

    cout << res << '\n';

    return 0;
}


#include <bits/stdc++.h>
#define REP(i, s, n) for (int i = s; i < (int)(n); i++)
#define ALL(a) a.begin(), a.end()
#define MOD 998244353
using namespace std;
using ll = long long;

template<int M>
class ModInt {
   public:
    ll value;
    constexpr ModInt(ll v = 0) { value = v % M; if (value < 0) value += M; }
    constexpr ModInt pow(ll n) const { if (!n) return 1; ModInt a = pow(n >> 1); a *= a; if (n & 1) a *= *this; return a; }
    constexpr ModInt inv() const { return this->pow(M - 2); }
    constexpr ModInt operator + (const ModInt &rhs) const { return ModInt(*this) += rhs; };
    constexpr ModInt operator - (const ModInt &rhs) const { return ModInt(*this) -= rhs; };
    constexpr ModInt operator * (const ModInt &rhs) const { return ModInt(*this) *= rhs; };
    constexpr ModInt operator / (const ModInt &rhs) const { return ModInt(*this) /= rhs; };
    constexpr ModInt &operator += (const ModInt &rhs) { value += rhs.value; if (value >= M) value -= M; return *this; };
    constexpr ModInt &operator -= (const ModInt &rhs) { value -= rhs.value; if (value <  0) value += M; return *this; };
    constexpr ModInt &operator *= (const ModInt &rhs) { value = value * rhs.value % M; return *this; };
    constexpr ModInt &operator /= (const ModInt &rhs) { return (*this) *= rhs.inv(); };
    constexpr bool operator == (const ModInt &rhs) { return value == rhs.value; }
    constexpr bool operator != (const ModInt &rhs) { return value != rhs.value; }
    friend ostream &operator << (ostream &os, const ModInt &rhs) { os << rhs.value; return os; }
};

using mint = ModInt<MOD>;

int main() {
    int H, W; cin >> H >> W;
    vector<string> S(H);
    REP(i, 0, H) cin >> S[i];

    auto diag = [&](int h, int w) -> int {
        int c = 0;
        while (h < H && w >= 0) {
            int nc = 0;
            if (S[h][w] == 'R') nc = 1;
            else if (S[h][w] == 'B') nc = 2;

            if (c && nc && c != nc) return -1;
            if (!c) c = nc;
            h++; w--;
        }
        return c;
    };

    int cnt = 0;
    REP(i, 0, W) {
        int c = diag(0, i);
        if (c == -1) {
            cout << 0 << endl;
            return 0;
        } else if (c == 0) {
            cnt++;
        }
    }
    REP(i, 1, H) {
        int c = diag(i, W - 1);
        if (c == -1) {
            cout << 0 << endl;
            return 0;
        } else if (c == 0) {
            cnt++;
        }
    }

    cout << mint(2).pow(cnt) << endl;

    return 0;
}

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define BE(x) x.begin(), x.end()

int main() {
    int h, w;
    cin >> h >> w;
    vector<string> s(h);
    for (auto &x : s) cin >> x;

    vector<bitset<2>> cnt;
    for (int j = 0; j < w; j++) {
        bitset<2> bs;
        int jj = j;
        for (int i = 0; jj >= 0 && i < h; i++, jj--) {
            if (s[i][jj] == 'R') bs[0] = true;
            else if (s[i][jj] == 'B') bs[1] = true;
        }
        cnt.push_back(bs);
    }
    for (int i = 1; i < h; i++) {
        bitset<2> bs;
        int ii = i;
        for (int j = w-1; ii < h && j >= 0; ii++, j--) {
            if (s[ii][j] == 'R') bs[0] = true;
            else if (s[ii][j] == 'B') bs[1] = true;
        }
        cnt.push_back(bs);
    }

    ll ans = 1;
    for (auto &x : cnt) {
        if (x[0] && x[1]) {
            cout << 0 << endl;
            return 0;
        }
        else if (!(x[0] || x[1])) {
            ans = ans * 2LL % 998244353LL;
        }
    }
    cout << ans << endl;
}


#include <bits/stdc++.h>
#define FOR(i, a, n) for(ll i = (ll)a; i < (ll)n; i++)
#define FORR(i, n) for(ll i = (ll)n - 1LL; i >= 0LL; i--)
#define rep(i, n) FOR(i, 0, n)
#define ALL(x) begin(x), end(x)
using namespace std;
using ll = long long;
constexpr ll Mod = 998244353;
constexpr ll mod = 1e9 + 7;
constexpr ll inf = 1LL << 60;
const double PI = acos(-1);
template <typename T1, typename T2>
inline bool chmax(T1 &a, T2 b) {
    return a < b && (a = b, true);
}
template <typename T1, typename T2>
inline bool chmin(T1 &a, T2 b) {
    return a > b && (a = b, true);
}
/*-------------------------------------------*/

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

    string s;
    cin >> s;
    cout << (s[0] == s[1] && s[0] == s[2] ? "Won\n" : "Lost\n");

    return 0;
}

using namespace std;
#include<string>
#include<cmath>
#include<list>
#include <map>
#include <unordered_map>
#include <set>
#define ll long long
#define ld long double
#define ull unsigned long long
#define ml map<ll,ll>
#define pb push_back
#define mp make_pair
#define ppl pair<ll,ll>
#define F first
#define S second
#define fio ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL)

#define fr(i,a,b) for(ll i=a;i<b;i++)
#define ffr(i,a,b) for(ll i=a;i>=b;i--)
#include<bits/stdc++.h>
#include<vector>
#define vl vector<ll>
#define PI 3.141592654
const ll N = 1e9 + 7;
#include<iterator>
#define EPSILON numeric_limits<double>::epsilon()

// vl b;
// vector<vl> v;
// ll n, m;
// vl link, val;
// vector<char>a;
// vector<bool> visited;

// void dfs(ll pnt, ll lin) {
// 	link[pnt] = lin;
// 	visited[pnt] = true;
// 	fr(i, 0, v[pnt].size()) {
// 		if (!visited[v[pnt][i]])dfs(v[pnt][i], lin);
// 	}
// }

// vl pr(N, 0);

// void precompute() {
// 	fr(i, 2, N + 1) {
// 		if (pr[i] == 0)
// 			for (ll j = i * i; j <= N; j += i)pr[j] = 1;
// 	}
// }

// void prime() {
// 	pr[1] = 1;
// 	fr(i, 2, N + 1)pr[i] = i;
// 	fr(i, 4, N + 1) {pr[i] = 2; i++;}
// 	fr(i, 3, N + 1) {
// 		if (pr[i] == i) {
// 			for (ll j = i * i; j <= N; j += i) {if (pr[j] == j)pr[j] = i;}
// 		}
// 	}
// }

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

// ll fact(ll n) {
// 	ll res = 1;
// 	fr (i, 2, n + 1) res = (res * i) % N;
// 	return res;
// }

// ll nCr(ll n, ll r) {
// 	return fact(n) / (fact(r) * fact(n - r));
// }

void solve() {
	char a, b, c; cin >> a >> b >> c;
	if (a == b && a == c)cout << "Won";
	else cout << "Lost";
}

int main() {
	fio;
#ifndef ONLINE_JUDGE
	// for getting input
	freopen("input.txt", "r", stdin);
	//for writing output
	freopen("jout.txt", "w", stdout);
#endif
	// prime();
	// precompute();
	ll t;
	if (1)
		t = 1;
	else
		cin >> t;
	while (t--) {
		//cout << "Case #" << h << ": ";
		solve();
		//h++;
		cout << '\n';
	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
int main() {
  int a,b;
  cin >> a >> b;
  cout << (a+b)/2 << endl;
  cout << (a-b)/2 << endl;
  return 0;
}

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

#define rep(i,a,b) for(ll i=a;i<b;++i)
#define rrep(i,a,b) for(ll i=a;i>b;--i)
#define FOR(i,n)  for(ll i=0;i<n;i++)
#define vi vector<int>
#define vl vector<ll>
#define ld long double
#define vld vector<ld>
#define vvi vector<vector<int>>
#define vvl vector<vector<long long>>
#define vvld vector<vector<ld>>
#define pii pair<int,int>
#define pll pair<long,long>
#define vpii vector<pii>
#define vpll vector<pll>
#define ff first
#define ss second
#define pb push_back
#define pf push_front
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define bs binary_search
#define d1(x) cout<<(x)<<endl
#define d2(x,y) cout<<(x)<<" "<<(y)<<endl
#define d3(x,y,z) cout<<(x)<<" "<<(y)<<" "<<(z)<<endl
#define d4(a,b,c,d) cout<<(a)<<" "<<(b)<<" "<<(c)<<" "<<(d)<<endl
ll inf = 1e18;
ll mod = 1e9+7;

ll power(ll x, ll y, ll p)
{
    ll res = 1;
    x = x % p;
    while (y > 0)
    {
        if (y & 1)
            res = (res * x) % p;
        y = y >> 1;
        x = (x * x) % p;
    }
    return res;
}
ll pwr(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;
}
ll modInverse(ll n, ll p)
{
    return power(n, p - 2, p);
}
ll gcd(ll a, ll b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);

}
int main()
{
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll t = 1;
    while(t-->0)
    {
        int a, b;
        cin>>a>>b;
        d2((a+b)/2,(a-b)/2);

    }
}


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

typedef long long ll;
typedef unsigned long long ull;
const double pi = acos(-1);
const double eps = 1e-8;
const ll mod = 1e9 + 7;
const ull base = 131;
const ull mod1 = 1e9 + 9;
const ull mod2 = 1610612741;

const int maxn = 2e5 + 10;
int n, m, k;
bool vis[maxn];
double dp[maxn][2], now[2];

int main()
{
    scanf("%d%d%d", &n, &m, &k);
    while (k--)
    {
        int x;
        scanf("%d", &x);
        vis[x] = 1;
    }
    dp[n][0] = dp[n][1] = 0;
    int l, r;
    l = r = n;
    while (l >= 1)
    {
        int i = l - 1;
        if (vis[i]) dp[i][0] = 1, dp[i][1] = 0;
        else dp[i][0] = now[0] / m, dp[i][1] = now[1] / m + 1;
        now[0] += dp[i][0];
        now[1] += dp[i][1];
        l = i;
        if (r - l + 1 > m) now[0] -= dp[r][0], now[1] -= dp[r][1], --r;
    }
    if (fabs(dp[0][0] - 1) < 1e-8) printf("-1\n");
    else printf("%.4f\n", dp[0][1] / (1 - dp[0][0]));
    return 0;
}

#pragma GCC optimize("O3")   //
#include <bits/stdc++.h>
using namespace std;

#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define per(i, b, a) for(int i = b - 1; i >= a; i--)
#define trav(a, x) for(auto& a : x)
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef long double ld;
typedef unsigned long long ull;

unsigned seed = chrono::system_clock::now().time_since_epoch().count();
mt19937 eng(seed);

ll random2(){
    return (1ll << 31ll)*eng()+eng();
}

ll n,m,k,q,T;

const ll big = 1000000007;
const ll big2 = 1000000009;
const ll mod =  998244353;

const int MAXN = 300001;
const ll TOT = 10000000000;

ll upp(ll i, ll j){
    if(j == 0)return 1;
    ll h = upp(i,j/2);
    if(j%2 == 0)return (h*h)%big;
    return (i*((h*h)%big))%big;
}

ll FAC[2001] = {0};
vl A;

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

    //freopen("fhc.txt","r",stdin);
    //freopen("autput.txt","w",stdout);

    ll a,b,c,d;

    cin >> n >> m;

    ll sa = 0;
    rep(c1,0,n){
        cin >> a;
        A.push_back(a);
        sa += a;
    }

    a = n+m;
    b = sa+n;

    ll t = 1;
    ll tt = 1;

    for(ll c1 = 0; c1 < b; c1++){
        t *= c1+1;
        t %= big;
        tt *= a-c1;
        tt %= big;
    }
    ll ans = tt*upp(t,big-2);

    cout << ans%big << "\n";

    return 0;
}


#include <iostream>
#include <iomanip>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <string>
#include <algorithm>
#include <bitset>
#include <queue>

using namespace std;

#define ll long long
#define MOD 1000000007
#define rep(i, n) for( int i = 0; i < (n); i++ )

int main(){
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i, n) cin >> a.at(i);

    bool ans = true;

    sort( a.begin(), a.end () );
    rep(i, n){
        if( a.at(i) != i + 1 ){
            ans = false;
        }
    }

    if( ans ){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }

    return 0;
}

#include <bits/stdc++.h>
using namespace std;
int main(void){

    int N;
    cin >> N;
    vector<int> A(N), B(N);
    for(int i = 0; i < N; i++)cin >> A[i];
    for(int i = 0; i < N; i++)cin >> B[i];

    int  Bmin = 10000, Amax = 0;

    for(int i = 0; i < N; i++){
        Bmin = min(B[i], Bmin);

        //cout << Bmin << endl;
    }

    for(int i = 0; i < N; i++){
        Amax = max(A[i],Amax);
    }

    int Ans = Bmin-Amax;

    //cout << Amax << Bmin;

    if(Ans < 0){
        cout << 0 << endl;
    }
    else{
        cout << Ans+1 << endl;
    }

}