#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>
#include<algorithm>
#include<set>
#include<map>
#include<utility>
#include<vector>
#include<string>
#include<stack>
#include<queue>
using namespace std;
int ad[20006][11];
int sent[20006][11], recv[11];
int main()
{
    int N,M,K,n,m,cnt,i;
    while (scanf("%d %d %d", &N, &M, &K) != EOF)
    {
        for (n=1; n<=N; ++n)
        {
            for (m=1; m<=M; ++m) scanf("%d", &ad[n][m]);
        }
        memset(sent, 0, sizeof(sent));
        memset(recv, 0, sizeof(recv));
        while (K--)
        {
            scanf("%d %d", &n, &m);
            ++sent[n][m];
            ++recv[m];
        }
        for (n=1; n<=N; ++n)
        {
            cnt = 0;
            for (m=1; m<=M; ++m)
            {
                if (ad[n][m] == 0) continue;
                cnt += recv[m] - sent[n][m];
            }
            if (n > 1) putchar(' ');
            printf("%d", cnt);
        }
        puts("");
    }
    return 0;
}


#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#pragma comment(linker, "/STACK:16777216")

#include <cstdlib>
#include <cstdio>
#include <cstring>
#include <string>
#include <vector>
#include <iostream>
#include <map>
#include <stack>
#include <set>
#include <queue>
#include <numeric>
#include <algorithm>
#include <utility>
#include <bitset>
#include <cmath>
#include <sstream>

#define all(a) (a).begin(),(a).end()
#define sz(a) (int)(a).size()

using namespace std;

typedef long long int64;
typedef vector<int> vi;
typedef vector< vi > vvi;
typedef vector<double> vd;
typedef vector< vd > vvd;
typedef vector< string > vs;
typedef pair< int, int > pii;
typedef vector< pii > vpii;

int main()
{
#ifndef ONLINE_JUDGE
    freopen("input.txt", "rt", stdin);
    freopen("output.txt", "wt", stdout);
#endif
    int a = 0;
    cin >> a;
    switch(a)
    {
        case 1:
            while(true);
            break;
        case 2:
            cout << 3;
            break;
        case 3:
            cout << 1; // TRUE;
            break;
        case 4:
            malloc(512000000);
            break;
        case 5:
            cout << 2;
            break;
    }
    return 0;
}


#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define pb push_back
#define ff first
#define ss second
#define mp make_pair
#define ins insert
#define sb substr
#define con continue
#define ub upper_bound
#define lb lower_bound
#define pll pair<ll,ll>
#define pld pair<ld,ld>
using namespace std;
ll power(ll x, ll y);
bool isPrime(ll n);
vector<ll> X[200001], Y[200001];
ll A[200001], B[200001];
int main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ll a,b,c,d,n,m,i,j,k,l,p,q,x,y,z,cnt=0, flag=0;
  string s1, s2, s3;
  vector<ll> V, W;
  vector<ll> :: iterator itrv;
  map<ll, ll> M;
  set<ll> S;
  set<ll> :: iterator itrs;
  cin>>n>>m;
  if(((n+m)%2)==0)cout<<pow(2, n+m)%998244353;
  else cout<<pow(2, n+m-1)%998244353;
  return 0;
}

ll power(ll x, ll y){
    ll res = 1;
    while (y > 0){
        if (y & 1) res = res*x;
        y = y>>1;
        x = x*x;
    }
    return res;
}
bool isPrime(ll n){
    if (n <= 1)  return false;
    if (n <= 3)  return true;
    if (n%2 == 0 || n%3 == 0) return false;
    ll p=sqrt(n);
    for(int i=5;i<=p;i=i+6)
        if (n%i == 0 || n%(i+2) == 0)
            return false;
    return true;
}


#include <cstdlib>
#include <iostream>
#include <string>

using namespace std;

int mas[1000];

int main(int argc, char *argv[])
{int N,i;
 cin>>N;
 for(i=0;i<N;i++)
 cin>>mas[i];
 sort(mas,mas+N);
 cout<<mas[N-1];
 for(i=1;i<N-1;i++)
 cout<<' '<<mas[i];
 cout<<mas[0];

    return EXIT_SUCCESS;
}


#include <cassert>
#undef assert

#include <algorithm>
#include <set>
#include <array>
#include <bitset>
#include <iostream>
#include <tuple>
#include <utility>
#include <vector>

#define STRING_IMPL(...) #__VA_ARGS__
#define STRING(...) STRING_IMPL(__VA_ARGS__)

#ifdef DEBUG
#include <execinfo.h>

#define debug(...) debug_impl("[" __FILE__ ":" STRING(__LINE__) "] " #__VA_ARGS__ " = ", __VA_ARGS__)
#define optimize(...) do { assert(__VA_ARGS__); } while (0)
#define assert(...) void(static_cast<bool>(__VA_ARGS__) ? void() : assert_failed(__FILE__, __LINE__, #__VA_ARGS__))

void print_backtrace() {
	void *array[50];

	auto const size = backtrace(array, 50);
	auto messages = backtrace_symbols(array, size);

	for (int i = 1; i < size && messages != NULL; ++i)
		std::cerr << "[bt]: (" << i << ") " << messages[i] << '\n';

	free(messages);
}

void assert_failed(char const file[], size_t line, char const cond[]) {
	std::cerr << file << ':' << line << ": assert(" << cond << ") failed.\n";
	print_backtrace();
	exit(EXIT_FAILURE);
}
#else
#define debug(...) void()
#define optimize(...) do { if (!(__VA_ARGS__)) __builtin_unreachable(); } while (0)
#define assert(...) void()
#endif

template <class... T>
void debug_impl(char const s[], T&&... vals) {
	std::cerr << s;
	std::size_t n{0};
	((std::cerr << std::forward<T>(vals) << (++n != sizeof...(vals) ? ", " : "")), ...);
	std::cerr << '\n';
}

template <typename... Ts>
std::ostream& operator<<(std::ostream &os, std::tuple<Ts...> const &theTuple) {
	os << '(';
	std::apply([&os](Ts const&... tupleArgs) {
			std::size_t n{0};
			((os << tupleArgs << (++n != sizeof...(Ts) ? ", " : "")), ...);
		}, theTuple);
	return os << ')';
}

template <class T>
void print_iters(std::ostream &os, T begin, T end) {
	if (begin != end)
		for (;;) {
			os << *begin;
			if (++begin == end) break;
			os << ", ";
		}
}

template <class T, class A>
auto& operator<<(std::ostream &os, std::vector<T, A> const &c) {
	os << '[';
	print_iters(os, begin(c), end(c));
	return os << ']';
}

template <class T, size_t N>
auto& operator<<(std::ostream &os, std::array<T, N> const &c) {
	os << '[';
	print_iters(os, begin(c), end(c));
	return os << ']';
}

template <class T, class C, class A>
auto& operator<<(std::ostream &os, std::set<T, C, A> const &c) {
	os << '{';
	print_iters(os, begin(c), end(c));
	return os << '}';
}

template <class T, class U>
auto& operator<<(std::ostream &os, std::pair<T, U> const &p) {
	return os << '(' << p.first << ", " << p.second << ')';
}

auto& operator<<(std::ostream &os, uint8_t i) { return os << unsigned(i); }
auto& operator<<(std::ostream &os,  int8_t i) { return os << int(i);      }

template <class T, class A>
auto& operator>>(std::istream &is, std::vector<T, A> &v) {
	for (auto &x : v) is >> x;
	return is;
}

template <class T, size_t N>
auto& operator>>(std::istream &is, std::array<T, N> &a) {
	for (auto &x : a) is >> x;
	return is;
}

template <class T, class U>
auto& operator>>(std::istream &is, std::pair<T, U> &p) {
	return is >> p.first >> p.second;
}

template <class T, class... Args>
T read(Args&&... args) {
	T val(std::forward<Args>(args)...);
	std::cin >> val;
	assert(std::cin.good());
	return val;
}

/* * * * * * * * * * * * * * * *\
 * Solution by Casarin Filippo *
 * Date: 24-07-2020            *
\* * * * * * * * * * * * * * * */

constexpr size_t S = 20;

int32_t solve(std::string const &A, std::string const &B) {
	std::array<std::bitset<S>, S> pair_original {};
	std::vector<size_t> L;

	for (size_t i = 0; i < size(A); ++i)
		if (A[i] != B[i]) {
			L.push_back(A[i] - 'a');
			L.push_back(B[i] - 'a');
			pair_original[A[i] - 'a'].set(B[i] - 'a');
		}

	uint32_t sol = S * S;
	sort(begin(L), end(L));
	L.erase(unique(begin(L), end(L)), end(L));

	debug(L);

	do {
		uint32_t cnt = 0;
		auto pair = pair_original;

		for (size_t i = 0; i+1 < size(L); ++i) {
			pair[L[i]].reset(L[i]);
			cnt += pair[L[i]].any();
			pair[L[i+1]] |= pair[L[i]];
		}

		pair[L.back()].reset(L.back());
		cnt += pair[L.back()].count();

		sol = std::min(sol, cnt);
	} while (next_permutation(begin(L), end(L)));

	return sol;
}

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

	auto T = read<uint32_t>();
	while (T--) {
		auto const N = read<size_t>();
		auto const A = read<std::string>();
		auto const B = read<std::string>();
		assert(size(A) == N && size(B) == N);
		std::cout << solve(A, B) << '\n';
	}
}


#include <cstdio>
#include <vector>
#include <algorithm>
#include <ctype.h>
const int bufSize = 1e6;
#define DEBUG
using namespace std;
inline char nc()
{
    #ifdef DEBUG
    return getchar();
    #endif
    static char buf[bufSize], *p1 = buf, *p2 = buf;
    return p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, bufSize, stdin), p1 == p2) ? EOF : *p1++;
}
inline void read(char *s)
{
    static char c;
    for (; !isalpha(c); c = nc());
    for (; isalpha(c); c = nc()) *s++ = c;
    *s = '\0';
}
template<typename T>
inline T read(T &r)
{
    static char c;
    static int flag;
    flag = 1, r = 0;
    for (c = nc(); !isdigit(c); c = nc()) if (c == '-') flag = -1;
    for (; isdigit(c); c = nc()) r = r * 10 + c - 48;
    return r *= flag;
}
const int maxn = 1e5 + 100;
const int maxm = 21;
int T,n;
char A[maxn],B[maxn];
int G[maxm][maxn];
int G2[maxm];
vector<int> s[maxm];
int fa[maxm];
int find(const int &x){return fa[x] == x ? x : fa[x] = find(fa[x]);}
inline void merge(int x,int y)
{
    x = find(x),y = find(y);
    if(x == y) return;
    if(s[x].size() < s[y].size()) swap(x,y);
    fa[y] = x;
    for(vector<int>::iterator it = s[y].begin();it!=s[y].end();++it) s[x].push_back(*it);
    s[y].clear();
}
int f[1<<21],num[1<<21];
int main()
{
    for (int i = 0;i<(1<<20);++i) for (int x = i;x;x>>=1) num[i] += (x&1);
    read(T);
    while (T--)
    {
        read(n);
        read(A + 1),read(B + 1);
        for(int i = 1;i<=20;++i) fa[i] = i,s[i].clear(),s[i].push_back(i);
        for(int i = 1;i<=20;++i) for(int j = 1;j<=20;++j) G[i][j] = 0;
        for(int i = 1;i<=n;++i)
        {
            if(A[i] == B[i]) continue;
            G[A[i] - 'a' + 1][B[i] - 'a' + 1] = 1;
            merge(A[i] - 'a' + 1,B[i] - 'a' + 1);
        }
        int ans = 0;
        for(int i = 1;i<=20;++i)
        {
            if(find(i) != i) continue;
//            printf("%d: ",i);
//            for(vector<int>::iterator it = s[i].begin();it!=s[i].end();++it) printf("%d ",*it);
//            putchar('\n');
            for(unsigned int j = 0;j<s[i].size();++j) G2[j] = 0;
            for(unsigned int j = 0;j<s[i].size();++j) for(unsigned int k = 0;k<s[i].size();++k)
                if(G[s[i][j]][s[i][k]]) G2[j] |= (1<<k);
            int maxx = (1<<(int)s[i].size());
            for(int status = 0;status < maxx;++status) f[i] = 0;
            f[0] = 1;
            int res = 0;
            for(int status = 0;status < maxx;++status)
            {
                if(!f[status]) continue;
                res = max(res,num[status]);
                for(unsigned int j = 0;j<s[i].size();++j) if(!(status & (1<<j)) && !(G2[j] & status)) f[status | (1<<j)] = 1;
            }
//            printf("res:%d\n",res);
            ans += 2 * s[i].size() - res - 1;
        }
        printf("%d\n",ans);
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
const int N=4003,P=1e9+9;
int n,w,b,jc[N<<1];
inline void in(Re &x){
    int f=0;x=0;char c=getchar();
    while(c<'0'||c>'9')f|=c=='-',c=getchar();
    while(c>='0'&&c<='9')x=(x<<1)+(x<<3)+(c^48),c=getchar();
    x=f?-x:x;
}
inline int mi(Re x,Re k){
    Re s=1;
    while(k){
        if(k&1)s=(LL)s*x%P;
        x=(LL)x*x%P,k>>=1;
    }
    return s;
}
inline int inv(Re x){return x==0?1:mi(x,P-2);}
inline int C(Re m,Re n){return (LL)jc[n]*inv(jc[n-m])%P*inv(jc[m])%P;}
int main(){
    in(n),in(w),in(b),jc[0]=1;
    for(Re i=1;i<=w+b;++i)jc[i]=(LL)jc[i-1]*i%P;
    printf("%d\n",(LL)C(n-3,w+b-3)*(w-1)%P*jc[w]%P*jc[b]%P);
}


#include<iostream>
#include<vector>
using namespace std;
int main()
{

int n,m;
cin>>n>>m;

vector<int>x(m);
for(int i=0;i<m;++i)
cin>>x[i];

int t=n,c=1,b=0;
for(int i=0;i<m;++i)
{
int y=t-x[i];
if(x[i]>b)
++y;
int r=y;
while(y--)
{
	cout<<c<<" ";
}
c+=r;
t=x[i];
b=x[i];
}

	return 0;
}


#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include <string.h>
#include <limits.h>
#include <time.h>
#include <map>
#include <set>
#include <vector>
#include <functional>
#include <algorithm>
#include <stack>
#include <list>
#include <cassert>
#include <queue>
#include <bitset>
// #include <iostream>
// #include <iomanip>
// #include <sstream>
using namespace std;
// const int dx[] = {-1, -1, -1, 0, 0, 1, 1, 1};
// const int dy[] = {-1, 0, 1, -1, 1, -1, 0, 1};
// const int dx[] = {2, 2, -2, -2, 1, 1, -1, -1};
// const int dy[] = {-1, 1, 1, -1, 2, -2, 2, -2};
#define all(cont) cont.begin(), cont.end()
#define rall(cont) cont.end(), cont.begin()
#define pb push_back
#define mp make_pair
#define fs first
#define sc second
#define pf printf
#define sf scanf
#define test_ fr(_iii_, 0, 66)pf(">");puts("in")
#define deb(x) fr(_iii_, 0, 66)cerr<<'>';cerr<<#x"="<<x<<"\n"
#define fr(i, a, b) for(int i = a ; i < (int)b ; i++)
#define frr(i, a, b) for(int i = a ; i >= (int)b ; i--)
#define tr(it, var) for(__typeof(var.begin()) it = var.begin(); it != var.end(); it++)
#define trr(rit, var) for(__typeof(var.rbegin()) rit = var.rbegin(); rit != var.rend(); rit++)
#define its(x) static_cast< ostringstream & >( ( ostringstream() << dec << x ) ).str()
#define boost ios_base::sync_with_stdio(false)
#define boost2 cin.tie(NULL)
#define ln puts("")
#define mems(a) memset(a, 0, sizeof(a))
#define has(cont, x) ((cont).find((x)) != (cont).end())
#define sz(x) ((int)(x).size())
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<bool> vb;
typedef vector<ll> vll;
int on_bit(int x, int pos) {x |= (1 << pos); return x;}
int off_bit(int x, int pos) {x &= ~(1 << pos); return x;}
bool is_on_bit(int x, int pos) {return ((x & (1 << pos)) != 0);}
int flip_bit(int x, int pos) {x ^= (1 << pos); return x;}
int lsb(int x) {return x & (-x);}
int on_bit_all(int x, int pos) {x = (1 << pos)-1; return x;}
const double EPS = 1e-9;
const double PI = 2*acos(0.0);
const int INF = 0x3f3f3f3f;
const int MOD = 1 << 30;
int add(ll a, ll b){return ((a%MOD)+(b%MOD))%MOD;}
int sub(ll a, ll b){return ((a%MOD)-(b%MOD))%MOD;}
int mult(ll a, ll b){return ((a%MOD)*(b%MOD))%MOD;}
ll gcd(ll a, ll b) {return b?gcd(b,a%b):a;}

const int N = 12345;
bool sq[N];
int from[N];

int main() {
	mems(sq);
	int u = 1;
	while(u*u<=N){
		sq[u*u]=true;
		from[u*u]=u;
		u++;
	}
	int n;
	sf("%d",&n);
	int res=0;
	fr(i,1,n+1){
		fr(j,i,n+1){
			int mult = i*i+j*j;
			if(mult<N)res+=(sq[mult]&&from[mult]<=n);
		}
	}
	pf("%d\n",res);
  return 0;
}


#include<iostream>
using namespace std;
int main(){
	int s[4];
	cin>>s[0];
	cin>>s[1];
	cin>>s[2];
	cin>>s[3];

    int c=0;
    for(int i=0;i<=3;i++){
    	for(int j=i+1;j<=4;j++){

    		if(s[i]==s[j])
    		c++;

		}
	}
cout<<c;

}


#include <stdio.h>
#include <string.h>
#define MOD 1000000007
void ADD(int &a,int b){
    a+=b;
    a%=MOD;
}
int C[110][110],f[110][2][110][110];
int main(){
    int i,j,k,t,need,cnt,N,M,K,tak,now,then,ans;
    memset(C,0,sizeof(C));
    for (i=0;i<=100;i++)
        for (j=0;j<=i;j++)
        if (j==0||j==i) C[i][j] = 1;
        else C[i][j] = (C[i-1][j-1]+C[i-1][j])%MOD;

    while(scanf("%d%d%d",&N,&M,&K)!=EOF){
        ans = 0;
        for (i=0;i<=N;i++)
            for (j=0;j<=1;j++)
                for (k=0;k<=K;k++)
                    for (t=0;t<=N;t++)
                        f[i][j][k][t] = 0;

        for (j=0;j<=M;j++){
            now = j%2, then = 1-now;
            f[0][now][1][1] = 1;
            for (i=1;i<=N;i++)
                for (cnt=1;cnt<=K;cnt++)
                    ADD(ans,f[i][now][cnt][0]);
            for (i=0;i<=N;i++)
                for (cnt=1;cnt<=K;cnt++){
                    for (need=1;need<=i+1;need++)
                    if (f[i][now][cnt][need]!=0){
                        //printf("%d %d %d %d : %d\n",i,j,cnt,need,f[i][now][cnt][need]);
                        for (tak = need;tak+i<=N;tak++){
                            int add = C[tak-1][need-1];
                            if (cnt*add<=K){
                                //printf("%d %d\n",tak,add);
                                ADD(f[i+tak][then][cnt*add][i==0?tak-need+1:tak-need],
                                    f[i][now][cnt][need]);
                                }
                        }
                        f[i][now][cnt][need] = 0;
                    }
                    f[i][now][cnt][0] = 0;
                }
        }

        printf("%d\n",ans);
    }
}


#include <vector>
#include <iostream>
using namespace std;
typedef long long LL;

void SpezzaCifre(LL N, vector<int>& vecN) {
    while (N != 0) {
        vecN.push_back(N%10);
        N /= 10;
    }
}

vector<int> vecL, vecR;
int cc = 0;

vector<int> nines(20, 9);
vector<int> zeroes(20, 0);

bool Doable(int m, const vector<int>& a, const vector<int>& b, array<int, 10>& is) {
    if (m == 0) return true;

    m--;
    int ca = a[m], cb = b[m];
    for (int c = ca + 1; c < cb; c++) {
        if (is[c] > 0) return true;
    }

    if (ca == cb) {
        if (is[ca] == 0) return false;
        is[ca]--;
        bool possible = Doable(m, a, b, is);
        is[ca]++;
        return possible;
    }

    if (is[ca] > 0) {
        is[ca]--;
        if (Doable(m, a, nines, is)) return true;
        is[ca]++;
    }

    if (is[cb] > 0) {
        is[cb]--;
        if (Doable(m, zeroes, b, is)) return true;
        is[cb]++;
    }
    return false;
}

void CreateIncreasingSubseq(int c, int s, array<int, 10>& is) {
    if (c == 9) {
        is[c] = s;
        auto at_is = is;
        if (Doable(vecL.size(), vecL, vecR, at_is)) cc++;
        return;
    }
    for (int i = 0; i <= s; i++) {
        is[c] = i;
        CreateIncreasingSubseq(c + 1, s - i, is);
    }
}

int main() {
    ios::sync_with_stdio(false);

    LL L, R;
    cin >> L >> R;
    SpezzaCifre(L, vecL);
    SpezzaCifre(R, vecR);
    while (vecL.size() < vecR.size()) vecL.push_back(0);

    array<int, 10> is = {};
    CreateIncreasingSubseq(0, vecR.size(), is);

    cout << cc << "\n";
}


#include <bits/stdc++.h>

using namespace std;

bool att(const string &a, const string &b, const string &c) {
    if(a[0] == c[0]) {
        if(b[0] != c[0]) {
            return true;
        }
        if(a[1] < c[1] && (b[1] <= a[1] || c[1] <= b[1])) {
            return true;
        }
        if(a[1] > c[1] && (b[1] >= a[1] || c[1] >= b[1])) {
            return true;
        }
    }
    if(a[1] == c[1]) {
        if(b[1] != c[1]) {
            return true;
        }
        if(a[0] < c[0] && (b[0] <= a[0] || c[0] <= b[0])) {
            return true;
        }
        if(a[0] > c[0] && (b[0] >= a[0] || c[0] >= b[0])) {
            return true;
        }
    }
}

bool check(const string &kb, const string &r0, const string &r1, const string &kw) {
    if(kb[0] < 'a' || kb[0] > 'h') { return false; }
    if(kb[1] < '1' || kb[1] > '8') { return false; }

    if(kb != r0) {
        if(att(kb, r1, r0) && att(kb, kw, r0)) { return false; }
    }
    if(kb != r1) {
        if(att(kb, r0, r1) && att(kb, kw, r1)) { return false; }
    }
    if(kb != kw) {
        if(kw[0]-1 <= kb[0] && kb[0] <= kw[0]+1 && kw[1]-1 <= kb[1] && kb[1] <= kw[1]+1) {
            return false;
        }
    }
    return true;
}


#include <bits/stdc++.h>
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define rep(i,n) for (int i=0;i<(int)(n);i++)
#define codefor int test;scanf("%d",&test);while(test--)
#define INT(...) int __VA_ARGS__;in(__VA_ARGS__)
#define LL(...) ll __VA_ARGS__;in(__VA_ARGS__)
#define yes(ans) if(ans)printf("yes\n");else printf("no\n")
#define Yes(ans) if(ans)printf("Yes\n");else printf("No\n")
#define YES(ans) if(ans)printf("YES\n");else printf("NO\n")
#define vector1d(type,name,...) vector<type>name(__VA_ARGS__)
#define vector2d(type,name,h,...) vector<vector<type>>name(h,vector<type>(__VA_ARGS__))
#define umap unordered_map
#define uset unordered_set
using namespace std;
using ll = long long;
const int MOD=1000000007;
const int MOD2=998244353;
const int INF=1<<30;
const ll INF2=(ll)1<<60;
//入力系
void scan(int& a){scanf("%d",&a);}
void scan(long long& a){scanf("%lld",&a);}
template<class T,class L>void scan(pair<T, L>& p){scan(p.first);scan(p.second);}
template<class T> void scan(T& a){cin>>a;}
template<class T> void scan(vector<T>& vec){for(auto&& it:vec)scan(it);}
void in(){}
template <class Head, class... Tail> void in(Head& head, Tail&... tail){scan(head);in(tail...);}
//出力系
void print(const int& a){printf("%d",a);}
void print(const long long& a){printf("%lld",a);}
void print(const double& a){printf("%.15lf",a);}
template<class T,class L>void print(const pair<T, L>& p){print(p.first);putchar(' ');print(p.second);}
template<class T> void print(const T& a){cout<<a;}
template<class T> void print(const vector<T>& vec){if(vec.empty())return;print(vec[0]);for(auto it=vec.begin();++it!= vec.end();){putchar(' ');print(*it);}}
void out(){putchar('\n');}
template<class T> void out(const T& t){print(t);putchar('\n');}
template <class Head, class... Tail> void out(const Head& head,const Tail&... tail){print(head);putchar(' ');out(tail...);}
//デバッグ系
template<class T> void dprint(const T& a){cerr<<a;}
template<class T> void dprint(const vector<T>& vec){if(vec.empty())return;cerr<<vec[0];for(auto it=vec.begin();++it!= vec.end();){cerr<<" "<<*it;}}
void debug(){cerr<<endl;}
template<class T> void debug(const T& t){dprint(t);cerr<<endl;}
template <class Head, class... Tail> void debug(const Head& head, const Tail&... tail){dprint(head);cerr<<" ";debug(tail...);}
ll intpow(ll a, ll b){ ll ans = 1; while(b){ if(b & 1) ans *= a; a *= a; b /= 2; } return ans; }
ll modpow(ll a, ll b, ll p){ ll ans = 1; while(b){ if(b & 1) (ans *= a) %= p; (a *= a) %= p; b /= 2; } return ans; }
ll updivide(ll a,ll b){if(a%b==0) return a/b;else return (a/b)+1;}

int main(){
    INT(n);
    vector<ll> a(3),b(3);
    in(a,b);
    ll win2=min(a[0],b[1])+min(a[1],b[2])+min(a[2],b[0]),win1;
    if(b[0]>=b[1]&&b[0]>=b[2]){
        win1=max(b[0]-a[0]-a[1],0);
        if(win1==0){
            if(a[1]>b[0]){
                win1=max(a[1]-b[0]-b[1],0);
            }
        }
    }else if(b[1]>=b[0]&&b[1]>=b[2]){
        win1=max(b[1]-a[1]-a[2],0);
        if(win1==0){
            if(a[2]>b[1]){
                win1=max(a[2]-b[1]-b[2],0);
            }
        }
    }else if(b[2]>=b[0]&&b[2]>=b[1]){
        win1=max(b[2]-a[2]-a[0],0);
        if(win1==0){
            if(a[0]>b[2]){
                win1=max(a[0]-b[0]-b[2],0);
            }
        }
    }
    out(win1,win2);
}


#include <bits/stdc++.h>
using namespace std;
#define MOD 998244353
#define ff first
#define ss second
typedef long long ll;
ll power(ll a, ll b){//a^b
    ll res=1;
    a=a%MOD;
    while(b>0){
        if(b&1){res=(res*a)%MOD;b--;}
        a=(a*a)%MOD;
        b>>=1;
    }
    return res;
}
ll fermat_inv(ll y){return power(y,MOD-2);}
ll gcd(ll a, ll b){return (b==0)?a:gcd(b,a%b);}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll t=1;
    //cin>>t;
    while(t--){
        ll n;
        cin>>n;
        ll a1,a2,a3;
        ll b1,b2,b3;
        cin>>a1>>a2>>a3>>b1>>b2>>b3;
        ll m2=min(a1,b2)+min(a2,b3)+min(a3,b1);
        ll m1=max(a1+b2,max(a2+b3,a3+b1))-n;
        m1=max(m1,0);
        cout<<m1<<" "<<m2<<"\n";
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main(){
	string str;
	cin>>str;
	int len=str.length();
	int count1=0;
	int count2=0;
	int i=0;
	while(count1+count2<len && i<len){
		if(str[i]>=65 && str[i]<=90){
			count1++;
			i++;
		}
		if(str[i]>97 && str[i]<=122 ){
			count2++;
			i++;
		}

	}
	int j=0;
	while(j<len){
		if(count1==count2){
			if(str[j]>=65 && str[j]<=90){
			str[j]=str[j]+32;
			j++;
		}
		}
		if(count1>count2){
			if(str[j]>=65 && str[j]<=90){
			str[j]=str[j]+32;
			j++;
		}
	}
		if(count1<count2){
			if( str[j]>=97 && str[j]<=122){
			str[j]=str[j]-32;
			j++;
		}
	}
	}
	cout<<str;
}


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

#define ll long long
#define pb push_back
#define sz(x) (int)(x).size()
#define mp make_pair
#define f first
#define s second
#define all(x) x.begin(), x.end()
#define D(x) cerr << #x << " is " << (x) << "\n";

using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
template<class T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>; ///find_by_order(),order_of_key()
template<class T1, class T2> ostream& operator<<(ostream& os, const pair<T1,T2>& a) { os << '{' << a.f << ", " << a.s << '}'; return os; }
template<class T> ostream& operator<<(ostream& os, const vector<T>& a){os << '{';for(int i=0;i<sz(a);i++){if(i>0&&i<sz(a))os << ", ";os << a[i];}os<<'}';return os;}
template<class T> ostream& operator<<(ostream& os, const set<T>& a) {os << '{';int i=0;for(auto p:a){if(i>0&&i<sz(a))os << ", ";os << p;i++;}os << '}';return os;}
template<class T> ostream& operator<<(ostream& os, const multiset<T>& a) {os << '{';int i=0;for(auto p:a){if(i>0&&i<sz(a))os << ", ";os << p;i++;}os << '}';return os;}
template<class T1,class T2> ostream& operator<<(ostream& os, const map<T1,T2>& a) {os << '{';int i=0;for(auto p:a){if(i>0&&i<sz(a))os << ", ";os << p;i++;}os << '}';return os;}

const int mod=1e9+7;
int n,T;
const int N=51;
vector<int> songs[3];
int add(int a,int b)
{
    a+=b;
    if(a>=mod)
        a-=mod;
    return a;
}
int mul(int a,int b)
{
    return (ll)a*b%mod;
}
int dp[N][N][N*N][3];
int calc(int tr,int koliko,int t,int d)
{
    if(t<0)
        return 0;
    if(t==0||koliko==0)
    {
        if(t==0&&koliko==0)
            return 1;
        return 0;
    }
    if(tr>=(int)songs[d].size())
        return 0;
    if(dp[tr][koliko][t][d]!=-1)
        return dp[tr][koliko][t][d];
    dp[tr][koliko][t][d]=add(calc(tr+1,koliko,t,d),calc(tr+1,koliko-1,t-songs[d][tr],d));
    return dp[tr][koliko][t][d];
}
int powmod(int x,int k)
{
    int ans=1;
    for(;k;k>>=1,x=mul(x,x))
        if(k&1)
            ans=mul(ans,x);
    return ans;
}
int ways[N][N][N][4];
int calcways(int a,int b,int c,int d)
{
    if(a==0&&b==0&&c==0)
        return 1;
    if(ways[a][b][c][d]!=-1)
        return ways[a][b][c][d];
    ways[a][b][c][d]=0;
    if(d!=0&&a)
        ways[a][b][c][d]=add(ways[a][b][c][d],calcways(a-1,b,c,0));
    if(d!=1&&b)
        ways[a][b][c][d]=add(ways[a][b][c][d],calcways(a,b-1,c,1));
    if(d!=2&&c)
        ways[a][b][c][d]=add(ways[a][b][c][d],calcways(a,b,c-1,2));
    return ways[a][b][c][d];
}
vector<int> fact;
int main()
{
    fact.pb(1);
    for(int i=1;i<N;i++)
        fact.pb(mul(fact.back(),i));
    memset(ways,-1,sizeof(ways));
    memset(dp,-1,sizeof(dp));
    for(int i=0;i<N;i++)
        for(int j=0;j<N;j++)
            for(int k=0;k<N;k++)
                for(int o=0;o<4;o++)
                    ways[i][j][k][0]=calcways(i,j,k,o);
    //printf("%i\n",calcways(1,1,1,4));
	scanf("%i %i",&n,&T);
	for(int i=0;i<n;i++)
    {
        int a,b;
        scanf("%i %i",&a,&b);
        songs[b-1].pb(a);
    }
    for(int i=0;i<N;i++)
        for(int j=0;j<N;j++)
            for(int k=0;k<N*N;k++)
                for(int o=0;o<3;o++)
                    dp[i][j][k][o]=calc(i,j,k,o);
    int ans=0;
    for(int i=0;i<=(int)songs[0].size();i++)
    {
        for(int Ki=0;Ki<=T;Ki++)
        {
            int sol=dp[0][i][Ki][0];
            if(sol==0)
                continue;
            for(int j=0;j<=(int)songs[1].size();j++)
            {
                for(int k=0;k<=(int)songs[2].size();k++)
                {
                    int total=i+j+k;
                    int anss=calcways(i,j,k,3);
                    anss=mul(anss,mul(fact[i],mul(fact[j],fact[k])));
                    if(anss==0)
                        continue;
                    for(int Kj=0;Kj<=T-Ki;Kj++)
                    {
                        int sol2=dp[0][j][Kj][1];
                        if(sol2==0)
                            continue;
                        int Kk=T-Ki-Kj;
                        int sol3=dp[0][k][Kk][2];
                        int dodajem=mul(mul(mul(sol,sol2),sol3),anss);
                        ans=add(ans,dodajem);
                    }
                }
            }
        }
    }
    printf("%i\n",ans);
    return 0;
}


#include<bits/stdc++.h>

using namespace std;

int main(){
    int numero;
    while(true){
        cin>>numero;
        switch(numero){
            case 0:
                cout<<"zero";
                break;
            case 1:
                cout<<"one";
                break;
            case 2:
                cout<<"two";
                break;
            case 3:
                cout<<"three";
                break;
            case 4:
                cout<<"four";
                break;
            case 5:
                cout<<"five";
                break;
            case 6:
                cout<<"six";
                break;
            case 7:
                cout<<"seven";
                break;
            case 8:
                cout<<"eight";
                break;
            case 9:
                cout<<"nine";
                break;
            case 10:
                cout<<"ten";
                break;
            case 11:
                cout<<"eleven";
                break;
            case 12:
                cout<<"twelve";
                break;
            case 13:
                cout<<"thirteen";
                break;
            case 14:
                cout<<"fourteen";
                break;
            case 15:
                cout<<"fifth-teen";
                break;
            case 16:
                cout<<"six-teen";
                break;
            case 17:
                cout<<"seven-teen";
                break;
            case 18:
                cout<<"eighth-teen";
                break;
            case 19:
                cout<<"nine-teen";
                break;
            case 20:
                cout<<"twenty";
                break;
            case 21:
                cout<<"twenty-one";
                break;
            case 22:
                cout<<"twenty-two";
                break;
            case 23:
                cout<<"twenty-three";
                break;
            case 24:
                cout<<"twenty-four";
                break;
            case 25:
                cout<<"twenty.five";
                break;
            case 26:
                cout<<"twenty.six";
                break;
            case 27:
                cout<<"twenty-seven";
                break;
            case 28:
                cout<<"twenty-eighth";
                break;
            case 29:
                cout<<"twenty-nine";
                break;
            case 30:
                cout<<"thirty";
                break;
            case 31:
                cout<<"thirty-one";
                break;
            case 32:
                cout<<"thirty-two";
                break;
            case 33:
                cout<<"thirty-three";
                break;
            case 34:
                cout<<"thirty-four";
                break;
            case 35:
                cout<<"thirty-five";
                break;
            case 36:
                cout<<"thirty-six";
                break;
            case 37:
                cout<<"thirty-seven";
                break;
            case 38:
                cout<<"thirty-eighth";
                break;
            case 39:
                cout<<"thirty-nine";
                break;
            case  40:
                cout<<"forty";
                break;
            case 41:
                cout<<"forty-one";
                break;
            case 42:
                cout<<"forty-two";
                break;
            case 43:
                cout<<"forty-three";
                break;
            case 44:
                cout<<"forty-four";
                break;
            case 45:
                cout<<"forty-five";
                break;
            case 46:
                cout<<"forty-six";
                break;
            case 47:
                cout<<"forty-seven";
                break;
            case 48:
                cout<<"forty-eighth";
                break;
            case 49:
                cout<<"forty-nine";
                break;
            case 50 :
                cout<<"fifty";
                break;
            case 51:
                cout<<"fifty-one";
                break;
            case 52:
                cout<<"fifty-two";
                break;
            case 53:
                cout<<"fifty-three";
                break;
            case 54:
                cout<<"fifty-four";
                break;
            case 55:
                cout<<"fifty-five";
                break;
            case 56:
                cout<<"fifty-six";
                break;
            case 57:
                cout<<"fifty-seven";
                break;
            case 58:
                cout<<"fifty-eighth";
                break;
            case 59:
                cout<<"fifty-nine";
                break;
            case  60:
                cout<<"sixty";
                break;
            case 61:
                cout<<"sixty-one";
                break;
            case 62:
                cout<<"sixty-two";
                break;
            case 63:
                cout<<"sixty-three";
                break;
            case 64:
                cout<<"sixty-four";
                break;
            case 65:
                cout<<"sixty-five";
                break;
            case 66:
                cout<<"sixty-six";
                break;
            case 67:
                cout<<"sixty-seven";
                break;
            case 68:
                cout<<"sixty-eighth";
                break;
            case 69:
                cout<<"sixty-nine";
                break;
            case  70:
                cout<<"seventy";
                break;
            case 71:
                cout<<"seventy-one";
                break;
            case 72:
                cout<<"seventy-two";
                break;
            case 73:
                cout<<"seventy-three";
                break;
            case 74:
                cout<<"seventy-four";
                break;
            case 75:
                cout<<"seventy-five";
                break;
            case 76:
                cout<<"seventy-six";
                break;
            case 77:
                cout<<"seventy-seven";
                break;
            case 78:
                cout<<"seventy-eighth";
                break;
            case 79:
                cout<<"seventy-nine";
                break;
            case  80:
                cout<<"eighty";
                break;
            case 81:
                cout<<"eighty-one";
                break;
            case 82:
                cout<<"eighty-two";
                break;
            case 83:
                cout<<"eighty-three";
                break;
            case 84:
                cout<<"eighty-four";
                break;
            case 85:
                cout<<"eighty-five";
                break;
            case 86:
                cout<<"eighty-six";
                break;
            case 87:
                cout<<"eighty-seven";
                break;
            case 88:
                cout<<"eighty-eighth";
                break;
            case 89:
                cout<<"eighty-nine";
                break;
            case  90:
                cout<<"ninety";
                break;
            case 91:
                cout<<"ninety-one";
                break;
            case 92:
                cout<<"ninety-two";
                break;
            case 93:
                cout<<"ninety-three";
                break;
            case 94:
                cout<<"ninety-four";
                break;
            case 95:
                cout<<"ninety-five";
                break;
            case 96:
                cout<<"ninety-six";
                break;
            case 97:
                cout<<"ninety-seven";
                break;
            case 98:
                cout<<"ninety-eighth";
                break;
            case 99:
                cout<<"ninety-nine";
                break;

        }
        cout<<"\n";
    }

return 0;
}


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

int main(){
	int a,c;
	cin>>a>>c;

	vector<int> av;
	while(a>1){
		av.push_back(a%3);
		a=a/3;
	}
	av.push_back(a);

	vector<int> cv;
	while(c>1){
		cv.push_back(c%3);
		c=c/3;
	}
	cv.push_back(c);

	for(int i=0;i<cv.size()-av.size();i++){
		av.push_back(0);
	}

	vector<int> bv;
	for(int i=0;i<cv.size();i++){
		int diff=cv[i]-av[i];
		if(diff<0){
			diff=diff+3;
		}
		bv.push_back(diff);
	}

	int b=0;
	for(int i=0;i<bv.size();i++){
		b+=bv[i]*pow(3,i);
	}
	cout<<b<<endl;
}


#include<bits/stdc++.h>
#include <stdio.h>
#include <algorithm>

#define LL long long
#define pb push_back
#define MP make_pair
#define F first
#define S second
#define vecprint(vec) for (int i=0;i<vec.size();i++)printf("%d ",vec[i]);
#define queprint(q) while(q.size()){printf("%d ",q.front());q.pop();}
#define all(x) x.begin(),x.end()
#define sc(x) scanf("%d",&x)
#define scl(x) scanf("%lld",&x)
#define pr(x) printf("%d",x)
#define prl(x) printf("%lld",x)
#define sz(x) ((int)x.size())
#define MEM(v,x) memset(v,x,sizeof v)
#define rep(v,i) for(int i=0;i<v.size();i++)

const double eps=1e-7,PI=3.1415926;
const int N=1e6;

using namespace std;

LL q,n,m,k,sum,mx=-1,mn=1e9;
vector <int> a,b,c;
vector <int> vec;
map <char,LL> M;

int main()
{
    scl(n);scl(m);
    while(m!=0)
    {
        c.pb(m%3);
        m/=3;
    }
    while (n!=0)
    {
        a.pb(n%3);
        n/=3;
    }
    q=c.size();
    while(q!=a.size())
    {
        a.pb(0);
        m--;
    }
    for(int i=0;i<c.size();i++)
    {
        if(c[i]<a[i])
        {
            c[i]+=3;
        }
        b.pb(c[i]-a[i]);
    }
    reverse(all(b));
    for(int i=0;i<b.size();i++)
    {
        sum*=3;
        sum+=b[i];
    }
    cout<<sum;

}


#include <iostream>
#include<cmath>

using namespace std;

int main()
{
    long A,B;
    long x,y,z;
    cin>>A>>B;
    cin>>x>>y>>z;

    long sum=0,sum1=0,sum2=0;
    while((x+y+z)!=0){
        if(x>0){
            x--;
            sum1+=2;
        }
        if(y>0 && x==0 &&z==0){
            y--;
            sum1++;
            sum2++;
        }
        if(z>0){
            z--;
            sum2+=3;
        }
    }
    if((A+B-sum1-sum2)>=0)
        cout<<0;
    else
        cout<<abs(A+B-sum1-sum2);

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define FOR(i,o,n) for (int i = o; i <= n; i++)
#define mod 1000000007
#define pb push_back
#define ff first
#define ss second
#define pp pair<ll,ll>
#define vl vector<ll>
#define vpp vector<pp>
#define INF 1000000000
#define endl '\n'
typedef std::complex<double> Complex;
typedef std::valarray<Complex> CArray;
#define fast ios::sync_with_stdio(0);cin.tie(0)
//freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);
#define all(x) x.begin(),x.end()
#define ms(a,v) memset(a,v,sizeof a)
#define II ({int a; scanf("%d", &a); a;})
#define LL ({Long a; scanf("%lld", &a); a;})
#define DD ({double a; scanf("%lf", &a); a;})
#define mp make_pair
#define gc getchar
#define EPS 1e-10
#define pi 3.1415926535897932384626433832795
#define FI freopen ("in.txt", "r", stdin)
#define FO freopen ("out.txt", "w", stdout)
typedef unsigned long long ull;
typedef set<int> si;
typedef pair<string,ll>psl;
typedef pair<double,double>pdd;

#define forab(i, a, b)	for (__typeof (b) i = (a) ; i <= b ; ++i)
#define rep(i, n)		forab (i, 0, (n) - 1)
#define For(i, n)		forab (i, 1, n)
#define rofba(i, a, b)	for (__typeof (b)i = (b) ; i >= a ; --i)
#define per(i, n)		rofba (i, 0, (n) - 1)
#define rof(i, n)		rofba (i, 1, n)
#define forstl(i, s)	for (__typeof ((s).end ()) i = (s).begin (); i != (s).end (); ++i)

#ifdef LOCAL
#define __(args...) {dbg,args; cerr<<endl;}
struct debugger{template<typename T> debugger& operator , (const T& v){cerr<<v<<"\t"; return *this; }}dbg;
#define __1D(a,n) rep(i,n) { if(i) printf(" ") ; cout << a[i] ; }
#define __2D(a,r,c,f) forab(i,f,r-!f){forab(j,f,c-!f){if(j!=f)printf(" ");cout<<a[i][j];}cout<<endl;}
#endif
template<class A, class B> ostream &operator<<(ostream& o, const pair<A,B>& p){ return o<<"("<<p.ff<<", "<<p.ss<<")";} //Pair print
template<class T> ostream& operator<<(ostream& o, const vector<T>& v){ o<<"[";forstl(it,v)o<<*it<<", ";return o<<"]";} //Vector print
template<class T> ostream& operator<<(ostream& o, const set<T>& v){ o<<"[";forstl(it,v)o<<*it<<", ";return o<<"]";} //Set print
template<class T> inline void MAX(T &a , T b){ if (a < b ) a = b;}
template<class T> inline void MIN(T &a , T b){ if (a > b ) a = b;}

//Fast Reader
template<class T>inline bool read(T &x){int c=gc();int sgn=1;while(~c&&c<'0'||c>'9'){if(c=='-')sgn=-1;c=gc();}for(x=0;~c&&'0'<=c&&c<='9';c=gc())x=x*10+c-'0';x*=sgn;return ~c;}

//int dx[]={1,0,-1,0};int dy[]={0,1,0,-1}; //4 Direction
//int dx[]={1,1,0,-1,-1,-1,0,1};int dy[]={0,1,1,1,0,-1,-1,-1};//8 direction
//int dx[]={2,1,-1,-2,-2,-1,1,2};int dy[]={1,2,2,1,-1,-2,-2,-1};//Knight Direction
//int dx[]={2,1,-1,-2,-1,1};int dy[]={0,1,1,0,-1,-1}; //Hexagonal Direction

int main()
{
	ll red,blue,green;
	cin>>red>>green>>blue;
	ll cnt=0;
	ll n=min(green,min(blue,red));
	if(n==0)
	{
		cout<<green/3+blue/3+red/3;
	}
	cnt=n;
	red=red-n;
	green=green-n;
	blue=blue-n;
	cnt+=green/3+blue/3+red/3;
	if(green%3+blue%3+red%3==4)
	{
		cnt++;
	}
	cout<<cnt;
}


#include<stdio.h>
int main()
{
    int n,r,ans;
    scanf("%d",&n);
    r=n%4;
    if(n==0){
        ans=1;
    }
    else if (r==0)
        ans=6;
    else if (r==1)
        ans=8;
    else if (r==2) ans=4;
    else if (r==3) ans=2;
    printf("%d\n\n",ans)
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int fact(int n)
{
    int res = 1;
    for (int i = 2; i <= n; i++)
        res = res * i;
    return res;
}
int nCr(int n)
{
    return fact(n) / (fact(2) * fact(n - 2));
}

// Returns factorial of n
int main(){
	int n,m;
	cin>>n>>m;
	int max = 0;
	int min = 0;
	if(n!=1 and m!=0){
	for(int i=2;i<n;i++){
	    if(nCr(i)>=m){
	        max = n - i;
	        break;
	    }
	}
	if(max == 0){
	    min = 0;
	}
	else{
	    float answer = float(n)/(2*m);
	    if(answer <=1){
	        min = 0;
	    }
	    else{
	        min = int(answer);
	    }

	}
	cout<<min<<" "<<max<<endl;
}
else{
    if(m==0){
        int min = n;
        int max = n;
        cout<<min<<" "<<max<<endl;
    }
    else{
        if(n==1){
            int min = n;
            int max = n;
            cout<<min<<" "<<max<<endl;
        }
    }
}
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int a,b,c,n;
    scanf("%d%d%d%d",&a,&b,&c,n);
    int ans=n-(a+b-c);
    (ans>0&&a<n&&b<n&&c<n&&n-ans>=a&&n-ans>=b&&n-ans>=c&&c<=a&&c<=b&&ans<=n)?cout<<ans<<endl:cout<<-1<<endl;
    return 0;
}


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

bool checkk(string a , string b,int n)
{
    int countm(0),countl(0)
    bool vis1[n];
    bool vis2[n];
    for(int i=0;i<n;i++)
    {

        for(int j=0;j<n;j++)
        {
            if(vis2[j]) break;
            if(a[i] - '0'< b[j]-'0') {
                vis1[i] = true;
                vis2[j] = true;
                break;
                countl++;
            } else{ countm++;}
        }
    }
    if(countm==0 || countl ==0) return false;
    else return true;
}
int main()
{
    int n; cin>>n;
    string s; cin>>s;
    string first = s.substr(0,n);
    string second = s.substr(n+1,2n);
    int s1(0),s2(0);
    for(int i=0;i<n;i++)
    {
        s1+= first[i] -'0';
        s2+= second[i] - '0';
    }
    if(s1==s2) { cout<<'"NO"<<endl;
        return 0;
    }
    if(!checkk(first,second,n)) cout<<"NO"<<endl;
    else cout<<"YES"<<endl;
    return 0;

}


#include <bits/stdc++.h>
#define int long long
#define db long double
#define x first
#define y second
#define mp make_pair
#define pb push_back
#define all(a) a.begin(), a.end()

using namespace std;

const int K = 5007;

int cnt[K], rcnt[K];
int cl[K];

int get(int l, int r){
	if (l > r) return 0;
	return cnt[r] - cnt[l-1];
}

int pref[K];

vector<pair<int, int> > min_remainder[K];

pair<int, int> get_opt(pair<int, int> a, pair<int, int> b){
	if (a.first > b.first) return {a.first, max(a.second, b.first)};
	return {b.first, max(b.second, a.first)};

const int INF = -1;

main(){
#ifdef LOCAL
	freopen("C_input.txt", "r", stdin);
	//freopen("C_output.txt", "w", stdout);
#endif
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n;
	cin >> n;
	vector<int> v(n);
	for (int i=0;i<K;++i){
		 cl[i] = INF;
	}
	for (int i=0; i < n; ++i) cin >> v[i];
	sort(v.begin(), v.end());
	int u = 0;
	for (int i=0;i<n;++i){
		cnt[v[i]]++;
		rcnt[v[i]]++;
		cl[v[i]] = v[i];
	}
	for (int i=2; i < K; ++i){
		if (cl[i] == i) continue;
		cl[i] = cl[i-1];
	}
	for (int i=2; i < K; ++i){
		vector<pair<int, int> > min_here;
		vector<int> starts;
		for (int j=i; j < K; j += i){
			starts.push_back(j);
		}
		starts.push_back(K);
		for (int j=starts.size()-2; j >= 0; j--){
			int nxt = starts[j+1];
			int el = starts[j];
			int A = cl[nxt-1];
			if (A < el) A = INF;
			int B = INF;
			if (A!=INF) {
				if (rcnt[A] > 1) B = A;
				else{
					B = cl[A-1];
					if (B < el) B = -1;
				}
			}
			if (A!=INF) A = A%i;
			if (B!=INF) B = B%i;
			//if (i==2005) cout << A << " " << B << endl;
			if (!min_here.size()) min_here.push_back({A, B});
			else min_here.push_back(get_opt(min_here.back(), {A, B}));
		}
		reverse(min_here.begin(), min_here.end());
		min_remainder[i] = min_here;
	}

	for (int i=1; i < K; ++i) cnt[i] += cnt[i-1];
	for (int i=2; i < K; ++i){
		int ss = 0;
		for (int j=i; j < K; j += i){
			int L = j, R = min(K-1, j+i-1);
			ss += get(L, R) * (j/i);
		}
		pref[i] = ss;
	}
	int ans = 0;
	for (int take=2; take < K; ++take){
		int tut = 0;
		int L = 1, R = K;
		while (R-L>1){
			int M = (L+R)/2;
			int how = pref[M];

			int closest = ((take+M-1)/M)*M;

			if (2*take < K){
				int closest = ((2*take+M-1)/M)*M;
				int A;
				if (closest >= K){
					closest = K-1;
					A = cl[closest-1];
					if (A < 2*take) A = INF;

					if (A < M) A = INF;
				}
				else{
					A = cl[closest-1];
					if (A < 2*take) A = INF;

					if (A < M) A = INF;

					if (A!=INF) A = A%M;
					pair<int, int> Q = min_remainder[M][closest/M-1];

					A = max(Q.first, A);
				}
				if (A!=INF){
					int spend = max(0ll, (2*take-A+M-1)/M);

					int e = how-spend;

					if (e >= take) L = M;
				}
			}

			int A, B;
			pair<int, int> Q;

			if (closest >= K){
				closest = K-1;
				A = cl[closest-1];
				if (A < take) A = INF;
				B = INF;
				if (A!=INF){
					if (rcnt[A] > 1) B = A;
					else{
						B = cl[A-1];
						if (B < take) B = INF;
					}
				}

				if (A!=INF) A = A%M;
				if (B!=INF) B = B%M;
				Q={A, B};
			}

			else{

				A = cl[closest-1];
				if (A < take) A = INF;
				B = INF;
				if (A!=INF){
					if (rcnt[A] > 1) B = A;
					else{
						B = cl[A-1];
						if (B < take) B = INF;
					}
				}

				if (A!=INF) A = A%M;
				if (B!=INF) B = B%M;

				Q = min_remainder[M][closest/M-1];
				Q = get_opt(Q, {A, B});
			}

			//if (take==2) cout << M << " " << A << " " << B << " " << Q.first << " " << Q.second << " " << how << endl;

			if (Q.second == INF){
				R = M;
				continue;
			}

			A = Q.first, B = Q.second;

			int spend = max(0LL, (take-A+M-1)/M) + max(0LL, (take-B+M-1)/M);

			//if (take==2) cout << spend << endl;

			how -= spend;

			if (how >= take) L = M;
			else R = M;
		}
		if (L > 1) ans = max(ans, L*take);

	}
	cout << ans;

}


#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <stack>
using namespace std;
#define ll long long

const int maxn = 3e5;
ll n;
int mod = 993244853;
ll gao(ll num){
	ll res = 1;
	for(int i = 2;i<=num;i++)
	{
		res*=i;
		res%=mod;
	}
	return res;
}

int main()
{
	scanf("%lld%lld",&n,&mod);
	ll res = 0;
	for(int i = 1;i<=n;i++)
	{
		ll tmp = gao(i);
		tmp%=mod;
		tmp*=gao(n-i+1);
		tmp%=mod;
		tmp*=n-i+1;
		tmp%=mod;
		res+=tmp;
		res%=mod;
	}
	printf("%lld\n",res);

	return 0;
}


#include <stdio.h>

#define MAX_N 5001
#define MAX_M 5001

typedef struct
{
	int newcolor;
	int color;
	int count;
} loc;

loc chessboard[MAX_N][MAX_M];

int main()
{
	int N, M;
	long int X;
	scanf("%d %d %ld", &N, &M, &X);
	for(int a = 0; a < N; a++)
		for(int b = 0; b < M; b++)
		{
			chessboard[a][b].color = -1;
			chessboard[a][b].newcolor = -1;
			chessboard[a][b].count = 0;
			if(a % 2 == b % 2)
			{
				chessboard[a][b].color = 0;
				chessboard[a][b].count = 1;
				chessboard[a][b].newcolor = 0;
			}
		}

	for(int i = 1; ; i++)
	{
		bool changed = false;
		for(int a = 1; a < N-1; a++)
			for(int b = 1; b < M-1; b++)
			{
				if(a % 2 == b % 2 && chessboard[a-1][b+1].color == i-1 && chessboard[a-1][b-1].color == i-1 && chessboard[a+1][b-1].color == i-1 && chessboard[a+1][b+1].color == i-1)
				{
					changed = true;
					chessboard[a][b].newcolor = i;
					chessboard[a][b].count++;
				}
			}
		for(int a = 1; a < N-1; a++)
			for(int b = 1; b < M-1; b++)
			{
					chessboard[a][b].color = chessboard[a][b].newcolor;
			}
		if(!changed)
			break;
	}

	long int squares = 0;
	for(int a = 0; a < N; a++)
		for(int b = 0; b < M; b++)
		{
			if(chessboard[a][b].count == X)
				squares++;
		}
/*
	for(int a = 0; a < N; a++)
	{
		for(int b = 0; b < M; b++)
		{
//			if(chessboard[a][b].color == 0)
				printf("%d", chessboard[a][b].count);
	//		else
//				printf("w");
		}
		printf("\n");
	}*/
	printf("%ld", squares);
	return 0;
}


#include <iostream>
#include <string>
#include <cmath>
#include <algorithm>
#include <vector>

using namespace std;

int main() {
	int n;
	string s;
	cin >> n >> s;
	vector <char> ans;
	int mem;
	if (s.size() < 3) {
		cout << s;
		return 0;
	}
	for (int i = 0; i < n - 2; i++) {
		while (s.substr(i, 3) != "ogo") {
			ans.push_back(s[i]);
			i++;
		}
		ans.push_back('*');
		ans.push_back('*');
		ans.push_back('*');
		i += 3;
		bool b = 0;
		while (s.substr(i, 2) == "go") {
			i += 2;
			b = 1;
		}
		i--;
		mem = i;
	}
	for (int i = mem + 1; i < n; i++)
		ans.push_back(s[i]);
	for (int i = 0; i < ans.size(); i++)
		cout << ans[i];
	return 0;
}


#include<iostream>
#include<math.h>
using namespace std;
int main ()
{while (1)
	{short int N=0,i=0,S=0,a=0,sum=0,index=0;
	cin>>N>>S;
	short int arry[101]={0};
	for(i=0;i<N;i++)
	cin>>arry[i];

	 for(i=0;i<N;i++)
	{short int maxx=arry[i];
	if (maxx<=arry[i+1])
	{
		maxx=arry[i+1];
		index=i+1;

	}
	}
	arry[index]=0;

	for(i=0;i<N;i++)
	sum+=arry[i];
	for(i=0;i<N;i++)
	cout<<arry[i]<<" ";
	cout<<endl;
		if(sum>S)
	cout<<"NO"<<endl;

	if(sum<=S)
	cout<<"YES"<<endl;
}}


#include<bits/stdc++.h>
using namespace std;
int main(){
    int k,a,b,v;cin>>k>>a>>b>>v;
    int ans=0;
    while(a){
        int z=min(k-1,b);
        b-=z;
        z++;
        a-=v*z;
        ans++;
    }
    cout<<ans<<"\n";
    return 0;
}


/*________________________Bismillahir Rahmanir Rahim___________________
|                                                                      |
|                    /\     |     | |\    |     /\     |-------        |
|                   /  \    |     | | \   |    /  \    |               |
|                  /----\   |-----| |  \  |   /----\   |-----          |
|                 /      \  |     | |   \ |  /      \  |               |
|                /        \ |     | |    \| /        \ |               |
|                     14th batch CSE , ID : 12008029                   |
|                     Comilla University                               |
|                     Email : sheikhahnafshifat@gmail.com              |
|______________________________________________________________________*/
#include<bits/stdc++.h>
#include<string>
#include<iostream>
using namespace std;
#define ll                      long long
#define MAX                     1000007
#define pb(x)                   push_back(x)
#define mp(x,y)                 make_pair(x,y)
#define vii                     vector<int>
#define vll                     vector<long long>
#define vp                      vector<pair<ll, ll> >
#define v_min(a)                *min_element(a.begin(),a.end())
#define v_max(a)                *max_element(a.begin(),a.end())
#define v_sum(a)                accumulate(a.begin(),a.end(),0)
#define un(a)                   a.erase(unique(a.begin(),a.end()),a.end())
#define SORT(a)                 sort(a.begin(),a.end())
#define AHNAF                   ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define gcd(a,b)                __gcd(a,b)
#define lcm(a,b)                ((a)*(b))/gcd(a,b)
#define YES                     cout<<"YES"<<endl
#define NO                      cout<<"NO"<<endl
#define testcase(t)             int t;cin>>t;while(t--)
#define reverse(a)              reverse(a.begin(),a.end())
#define ff                      first
#define ss                      second
#define print(a)                for(auto it: a) cout<<it<<" "
#define all(a)                  a.begin(),a.end()
#define sf(v)                   for(auto &it: v) cin>>it
///--------------Graph Moves--------------------------------------
///const int fx[] = {+1,-1,+0,+0};
///const int fy[] = {+0,+0,+1,-1};
///const int fx[] = {+0,+0,+1,-1,-1,+1,-1,+1}; ///King's move
///const int fy[] = {-1,+1,+0,+0,+1,+1,-1,-1}; ///king's Move
///const int fx[] = {-2,-2,-1,-1,+1,+1,+2,+2}; ///knight's move
///const int fy[] = {-1,+1,-2,+2,-2,+2,-1,+1}; ///knight's move
///---------------------------------------------------------------

int main()
{
    AHNAF;
    int a,b,c;
    cin>>a>>b>>c;
    for(int i=1; i<=500; i++)
    {
        vector<bool> v(MAX,0);
        for(int j=0; j<=50; j++)
        {
            v[i+(j*a)]=1;
        }
        for(int j=1; j<=500; j++)
        {
            vector<bool> vv(MAX,0);
            for(int k=0; k<=50; k++)
            {
                vv[j+(k*b)]=1;
            }
            bool cc=true;
            for(int k=1; k<=500; k++)
            {
                for(int l=0; l<=5; l++)
                {
                    if(v[k+(l*c)]==0 && vv[k+(l*c)]==0) {
                        cc=false;
                        break;
                    }
                }
                if(cc) {
                    YES;
                    return 0;
                }
            }
        }
    }
    NO;
}


//==========================================================================
//
//                   Bismillahir-Rahmanir-Rahim
//
// ==========================================================================
#include <bits/stdc++.h>
#define        ll                              long long
#define        f(x,y,z)                        for(int x=y;x<z;x++)
#define        pii                             pair<int,int>
#define        pll                             pair<ll,ll>
#define        CLR(a)                          memset(a,0,sizeof(a))
#define        SET(a)                          memset(a,-1,sizeof(a))
#define        N                               1000010
#define        M                               1000000007
#define        pi                              acos(-1.0)
#define        ff                              first
#define        ss                              second
#define        pb                              push_back
#define        inf                             (int)1e9
using namespace std;
int dx[]={0,0,1,-1,-1,-1,1,1};
int dy[]={1,-1,0,0,-1,1,1,-1};
template < class T> inline T biton(T n,T pos){return n |((T)1<<pos);}
template < class T> inline T bitoff(T n,T pos){return n & ~((T)1<<pos);}
template < class T> inline T on(T n,T pos){return (bool)(n & ((T)1<<pos));}
template < class T> inline T gcd(T a, T b){while(b){a%=b;swap(a,b);}return a;}
template <typename T> string NumberToString ( T Number ) { ostringstream ss; ss << Number; return ss.str(); }
inline int nxt(){int aaa;scanf("%d",&aaa);return aaa;}
inline ll lxt(){ll aaa;scanf("%lld",&aaa);return aaa;}
template <class T> inline T bigmod(T p,T e,T m){T ret = 1;
for(; e > 0; e >>= 1){
    if(e & 1) ret = (ret * p) % m;p = (p * p) % m;
} return (T)ret;}
#define sayed
#ifdef sayed
     #define debug(args...) {cerr<<"Debug: "; dbg,args; cerr<<endl;}
#else
    #define debug(args...)  // Just strip off all debug tokens
#endif
struct debugger{
    template<typename T> debugger& operator , (const T& v){
        cerr<<v<<" ";
        return *this;
    }
}dbg;
///******************************************START******************************************
bool leap(ll a){
     if(a%400==0) return true;
     if(a%4==0&&a%100!=0) return true;
     return false;
 }
int main(){
     // freopen("out.txt","w",stdout);
  ll n;
  cin>>n;
  if(leap(n)) cout<<n+28<<endl;
  else {
      int c=0;
    for(int i=n; i;i++){
            if(c==7){
                cout<<i<<endl;
                break;
            }
        if(leap(i)) c+=2;
        else c+=1;
    }
  }
return 0;
}


//http://codeforces.com/problemset/problem/353/A

#include <iostream>
#include <string>
#include <cmath>
#include <vector>
#include <algorithm>
#include <iterator>
#include <cstdlib>
#include <cstdio>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <list>

using namespace std;

int size_n;
int upper = 0, lower = 0;

vector <pair <int, int > > el(0);

int main()
{
	int ii;

	cin >> size_n;

	el.resize(size_n);

	for (ii = 0; ii < size_n; ii++)
	{
		cin >> el[ii].first >> el[ii].second;

		upper += el[ii].first;
		lower += el[ii].first;
	}

	if ((((upper % 2) == (lower % 2))) && ((upper % 2) == 0))
		cout << "0";
	else if ((upper % 2) == (lower % 2))
		cout << "-1";
	else
	{
		for (ii = 0; ii < size_n; ii++)
		{
			if ((el[ii].first % 2) != (el[ii].second % 2))
				break;
		}

		if ((el[ii].first % 2) != (el[ii].second % 2))
			cout << "1";
		else
			cout << "-1";
	}

	return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
using ll = long long;
const int MOD = 998244353;

class SegTree {
	private:
		struct El {
			int p[2][2]; // Probability that leftmost is L/R and rightmost is L/R
			El() {
				p[0][0] = 0;
				p[0][1] = 0;
				p[1][0] = 0;
				p[1][1] = 0;
			}
			static El id() {
				El res;
				res.p[0][0] = 1;
				res.p[1][1] = 1;
				return res;
			}
		};
		static El combine(const El& le, const El& ri) {
			El res;
			for (int a = 0; a < 2; ++a) {
				for (int b = 0; b < 2; ++b) {
					for (int i = 0; i < 2; ++i) {
						res.p[a][b] = (res.p[a][b] + (ll)le.p[a][i] * ri.p[i][b]) % MOD;
					}
				}
			}
			return res;
		}
		void update(int i) {
			for (i >>= 1; i > 0; i >>= 1) seg[i] = combine(seg[2*i], seg[2*i+1]);
		}

		vector<El> seg;
		int h = 1;
	public:
		SegTree(int n) {
			while(h < n) h *= 2;
			seg.resize(2*h, El::id());
		}

		int prob(int i, int a, int b) {
			i += h;
			El backup = seg[i];
			for (int x = 0; x < 2; ++x) {
				for (int y = 0; y < 2; ++y) {
					if (x != a || y != b) seg[i].p[x][y] = 0;
				}
			}
			update(i);

			ll res = (seg[1].p[0][0] + seg[1].p[0][1]) % MOD;

			seg[i] = backup;
			update(i);
			return res;
		}
		void setv(int i, int a, int b, int c, int d) {
			i += h;
			seg[i].p[0][0] = a;
			seg[i].p[0][1] = b;
			seg[i].p[1][0] = c;
			seg[i].p[1][1] = d;
			update(i);
		}
		void zero(int i, int a, int b) {
			i += h;
			seg[i].p[a][b] = 0;
			update(i);
		}
};

ll modPow(ll a, ll b) {
	if (b & 1) return a * modPow(a, b-1) % MOD;
	if (b > 0) return modPow(a*a % MOD, b / 2);
	return 1;
}

struct Atom {
	int xi, vi, pi;
};

struct Rat {
	ll a, b;

	// a / b < rhs.a / rhs.b?
	bool operator<(const Rat& rhs) const {
		return a * rhs.b < b * rhs.a;
	}
	ll modv() const { return a * modPow(b, MOD-2) % MOD; }
};

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

	int n;
	cin >> n;

	SegTree seg(n);

	vector<Atom> atoms(n);
	for (auto& v : atoms) cin >> v.xi >> v.vi >> v.pi;

	const ll HI = modPow(100, MOD - 2);
	for (int i = 0; i < n; ++i) {
		int prob0 = (100 - atoms[i].pi) * HI % MOD;
		int prob1 = atoms[i].pi * HI % MOD;
		seg.setv(i, prob0, prob1, prob0, prob1);
	}

	vector<pair<Rat, pair<int, pair<int, int>>>> que;
	for (int i = 0; i+1 < n; ++i) {
		ll dist = atoms[i+1].xi - atoms[i].xi;
		for (int a = 0; a < 2; ++a) {
			for (int b = 0; b < 2; ++b) {
				ll vel = (a ? 1 : -1) * atoms[i].vi + (b ? -1 : 1) * atoms[i+1].vi;
				Rat r = {dist, vel};
				if (vel > 0) que.push_back({r, {i, {a, b}}}); // Collision eventually happens
			}
		}
	}
	sort(que.begin(), que.end());

	ll res = 0;
	for (auto pr : que) {
		ll t = pr.first.modv();
		int i = pr.second.first;
		int a = pr.second.second.first;
		int b = pr.second.second.second;

		ll prob = seg.prob(i+1, a, b);
		res = (res + prob * t) % MOD;
		seg.zero(i+1, a, b);

		// cerr << "event " << i << ' ' << a << ' ' << b << ": " << t << ' ' << prob << '\n';
	}


#include<bits/stdc++.h>
#define ls ch[x][0]
#define rs ch[x][1]
#define ll long long
#define int ll
using namespace std;

inline ll read(){
	ll num=0,neg=1;char c=getchar();
	while(!isdigit(c)){if(c=='-')neg=-1;c=getchar();}
	while(isdigit(c)){num=(num<<3)+(num<<1)+c-'0';c=getchar();}
	return num*neg;
}

const ll mod=998244353;
struct mat{
	int a[2][2];
	mat(){memset(a,0,sizeof(a));}
}tree[100010<<2];

const ll INF=0x7f7f7f7f7f7f7f;
struct node{
	int pos,p1,p2,val;
	double t;
}side[400010];int cnt;
ll ans,x[100010],v[100010],p[100010],n;

bool cmp1(node x,node y){return x.t<y.t;}

inline ll qpow(ll x,ll k){
	ll res=1;
	while(k){
		if(k&1)res=res*x%mod;
		x=x*x%mod;k>>=1;
	}return res;
}
inline mat mul(mat x,mat y){
	mat res;
	for(int i=0;i<=1;i++)
	for(int j=0;j<=1;j++)
	for(int k=0;k<=1;k++)
		res.a[i][j]=(res.a[i][j]+x.a[i][k]*y.a[k][j]%mod)%mod;
	return res;
}
inline void insert(int pos,int p1,int p2){
	side[++cnt].pos=pos;
	side[cnt].p1=p1,side[cnt].p2=p2;
	if(p1==0&&p2==0){
		int tmp=v[pos]-v[pos-1];
		if(tmp>0) side[cnt].val=(x[pos]-x[pos-1])*qpow(tmp,mod-2)%mod,side[cnt].t=(x[pos]-x[pos-1])*1.0/tmp;
		else side[cnt].val=INF,side[cnt].t=1e20;
	}
	if(p1==0&&p2==1) side[cnt].val=INF,side[cnt].t=1e20;
	if(p1==1&&p2==0) side[cnt].val=(x[pos]-x[pos-1])%mod*qpow((v[pos]+v[pos-1])%mod,mod-2)%mod,side[cnt].t=(x[pos]-x[pos-1])*1.0/(v[pos-1]+v[pos]);
	if(p1==1&&p2==1){
		int tmp=v[pos-1]-v[pos];
		if(tmp>0) side[cnt].val=(x[pos]-x[pos-1])*qpow(tmp,mod-2)%mod,side[cnt].t=(x[pos]-x[pos-1])*1.0/tmp;
		else side[cnt].val=INF,side[cnt].t=1e20;
	}
}
inline void push_up(int x){tree[x]=mul(tree[x<<1],tree[x<<1|1]);}
inline void build(int l,int r,int x){
	if(l==r){
		tree[x].a[0][0]=tree[x].a[1][0]=(1-p[l]+mod)%mod;
		tree[x].a[0][1]=tree[x].a[1][1]=p[l];
		return;
	}int mid=l+r>>1;
	build(l,mid,x<<1),build(mid+1,r,x<<1|1);
	push_up(x);return;
}
inline void update(int u,int p1,int p2,int l,int r,int x){
	if(l==r){tree[x].a[p1][p2]=0;return;}
	int mid=l+r>>1;
	if(u<=mid) update(u,p1,p2,l,mid,x<<1);
	else update(u,p1,p2,mid+1,r,x<<1|1);
	push_up(x);return;
}
inline mat query(int ql,int qr,int l,int r,int x){
	if(ql>qr){
		mat res;res.a[0][0]=res.a[1][1]=1;
		return res;
	}
	if(ql<=l&&qr>=r) return tree[x];
	int mid=l+r>>1;mat res;res.a[0][0]=res.a[1][1]=1;
	if(ql<=mid) res=mul(res,query(ql,qr,l,mid,x<<1));
	if(qr>mid) res=mul(res,query(ql,qr,mid+1,r,x<<1|1));
	return res;
}

signed main(){
	n=read();
	for(int i=1;i<=n;i++) x[i]=read(),v[i]=read(),p[i]=read()*qpow(100ll,mod-2)%mod;
	build(1,n,1);
	for(int i=2;i<=n;i++) for(int j=0;j<=1;j++) for(int k=0;k<=1;k++) insert(i,j,k);
	sort(side+1,side+cnt+1,cmp1);

	for(int i=1;i<=cnt;i++){
		if(side[i].val==INF) break;
		mat trans;
		trans.a[side[i].p1][side[i].p2]=(side[i].p2?p[side[i].pos]:(1-p[side[i].pos]+mod)%mod);
		trans=mul(query(1,side[i].pos-1,1,n,1),trans);
		trans=mul(trans,query(side[i].pos+1,n,1,n,1));
		ans+=(trans.a[0][0]+trans.a[0][1])%mod*side[i].val%mod;ans%=mod;
		update(side[i].pos,side[i].p1,side[i].p2,1,n,1);
	}printf("%lld\n",ans);return 0;
}


#include <iostream>
#include <string>
using namespace std;
int main()
{
    string ch;
    int i;
    string st2=".";
    cin>>ch; //deleting vowels
    for(i=0;i<ch.length();i++)
    {
        if(ch.at(i)=='a'||ch.at(i)=='e'||ch.at(i)=='i'||ch.at(i)=='o'||ch.at(i)=='u'||ch.at(i)=='A'||ch.at(i)=='E'||ch.at(i)=='I'||ch.at(i)=='U'||ch.at(i)=='O')
        {
            ch.erase(i);
        }
    }
    //inversing case of letters
    for(i=0;i<ch.length();i++)
    {
        if(ch.at(i)<=90)
        {
            ch[i]=ch[i]+32;
        }
    }

    //inserting . before consonants
    for(i=0;i<ch.length();i+=1)
    {
        ch.insert(i,st2);
    }
    cout<<ch;

}


#include<iostream>
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<string>
#include<math.h>

using namespace std;

int main()
{
  long long n, m, x, y, a, b, x1, y1, x2, y2 ;
  long long s, e, mid;
  long long i, j, k;
  bool found;

  cin >> n >> m >> x >> y >> a >> b;

  if (b > a)
  {
    j = b;
    i = a;
  }
  else
  {
    j = a;
    i = b;
  }

  while (j % i != 0)
  {
    k = j % i;
    j = i;
    i = k;
 //   cout << i << " " << j << endl;
  }

  //cout << i << endl;
  a = a / i;
  b = b / i;*/

  if (a == b)
    {
      a = 1;
      b = 1;
    }

  s = 1;
  e = n;

  while (s < e-1)
  {
    mid = (s+e) / 2;
    if ((mid * a <= n) && (mid * b <= m)) // ������ ��
      s = mid;
    else
      e = mid;

  }

  a = a*s;
  b = b*s;

  if (a%2 == 0)
    x1 = x - (a/2);
  else
    x1 = x - (a/2) - 1;

  x2 = x1 + a ;

  if (b%2 == 0)
    y1 = y - (b/2);
  else
    y1 = y - (b/2) - 1;

  y2 = y1 + b;

  if (x1 < 0)
  {
    x1 = 0;
    x2 = a;
  }

  if (x2 > n)
  {
    x1 = n - a;
    x2 = n;
  }

  if (y1 < 0)
  {
    y1 = 0;
    y2 = b;
  }

  if (y2 > n)
  {
    y1 = m - b;
    y2 = m;
  }

  cout << x1 << " " << y1 << " " << x2 << " " << y2 << endl;
  return 0;

}


#include "stdio.h"

void main(void )
{
  printf("HelloWorld!");

}


#include<iostream>
using namespace std;
int main()
{
    int n;
    int counter=0;
    cin>>n;
    for(int i=0;i<n;i++ )
    {
        int temp=n-i;
        if(temp%i==0)
        {
            counter++;
        }

    }

    cout<<counter;
}


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

typedef long long ll;

bool found = false;
vector<ll> jawab;

void dfs(ll u,ll maks,bool *visited)
{
    if ((u<=maks)&&(!found)&&(!(*(visited+u))))
    {
        *(visited+u) = true;
        jawab.push_back(u);
        if (u==maks) found = true;
        else
        {
            dfs(2*u,maks,visited);
            if (!found) dfs(10*u+1,maks,visited);
            if (!found) jawab.pop_back();
        }
    }
}

int main()
{
    ll a,b;
    cin >> a >> b;
    bool visited[b+1];
    for (ll i=a;i<=b;++i) visited[i] = false;
    dfs(a,b,visited);
    if (found)
    {
        cout << "YES" << endl << jawab.size() << endl << jawab[0];
        for (ll i=1;i<jawab.size();++i) cout << ' ' << jawab[i];
        cout << endl;
    }
    else cout << "NO" << endl;
    return 0;
}


#include<cstdio>
#include<algorithm>
#include<iostream>

using namespace std;

typedef long long LL;

int inf = 1000000009;

int findB(int x, int y, int a){

    LL low = -inf;
    LL high = inf;
    LL val, mid;

    while(low < high){
        mid = (low + high)/2;

        val = x - y - 2*a*mid;
        if( val < 0){
            high = mid;
        }
        else low = mid+1;
    }

    return low;
}

int findA(int x, int y, int a){

    LL low = -inf;
    LL high = inf;
    LL val, mid;

    while(low < high){
        mid =  low + (high-low)/2;

        val = x + y - 2*a*mid;
        if( val < 0){
            high = mid;
        }
        else low = mid+1;
    }

    return low;
}
int main(){

    int a, b, x1, y1, x2, y2;
    int a1, a2, b1, b2, ret;

    cin>> a >> b >> x1>> y1 >> x2 >> y2;

    a1 = findA(x1, y1, a);
    //cout<< a1<<endl;
    a2 = findA(x2, y2, a);

    b1 = findB(x1, y1, b);
    b2 = findB(x2, y2, b);

    ret = max( abs(a1-a2), abs(b1-b2));

    cout<< ret;

    return 0;
}


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

const int OO = 0x3f3f3f3f,N = 1e2+5,mod = 1e9+7 ;
#define read(FILE)  freopen(FILE, "r", stdin);
#define write(FILE) freopen(FILE, "w", stdout);
#define BeatMeIFUCAN ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);

int t1 ,t2 ,x1 ,x2 ,t0 ,a ,b ;
long long temprt(long long y1,long long y2){
    return(y1*t1+y2*t2)/(y1+y2);
}
bool can(int y1,int y2){
    long long c1=(0ll+a+b)*(1ll*y1*t1+1ll*y2*t2) ;
    long long c2=(0ll+y1+y2)*(1ll*a*t1+1ll*b*t2) ;
    if(c1<c2)return 1;
    if(c1>c2)return 0;
    return (y1+y2)>(a+b);
}
int main(){
    cin>>t1>>t2>>x1>>x2>>t0;
    a=0 ,b=x2;
    for(int y1=1;y1<=x1;++y1){
        long long y2= 1ll*y1*(t0-t1) / (t2-t0) ;
        y2+=((!y1)&&(!y2));
        while(y2<x2&&temprt(y1,y2)<t0)++y2;
        if(y2<=x2&&temprt(y1,y2)>=t0&&can(y1,y2))a=y1 ,b=y2;
    }
    cout<<a<<" "<<b;
    return 0;
}


#include <iostream>
#include <bits/stdc++.h>
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define REP(i,n) for(long long i=1; i<=n; i++)
#define rep(i,a,b) for(long long i=a; i<b; i++)
#define REPV(v) for(auto i = v.begin(); i != v.end(); ++i)
#define REPVI(v,a) for(auto i=a; i!=v.end(); ++i)
#define sort(arr) sort(arr.begin(),arr.end())
#define lb(v,n) lower_bound(v.begin(),v.end(),n)
#define ub(v,n) upper_bound(v.begin(),v.end(),n)
using namespace std;

typedef long long ll;
typedef vector<ll> vll;
typedef pair<ll, ll> pll;
typedef unsigned long int uli;
typedef vector<vector<ll>> matrix;

const ll MOD = 1000000007;

vector<ll> PrimeNumbers(ll n){
	vector<ll> primes;
	vector<ll> isPrime(n+1,1);
	for(ll i=2;i*i<=n;i++){
		if(isPrime[i]){
			for(ll j=i*i; j<=n ; j+=i){
				isPrime[j]=0;
			}
		}
	}
	rep(i,2,n){
		if(isPrime[i])primes.pb(i);
	}
	return primes;
}

vector<ll> segmentedSeive(ll l, ll r){
	vector<ll> primes;
	vll primeNos = PrimeNumbers(floor(sqrt(r)));
	vll isPrime(r-l+1,1);
	REPV(primeNos){
		ll x = (*i);
		ll rem = l%x;
		ll start = l;
		if(rem)start = (l/x+1)*x;
		for(ll j = start; j<=r; j+=x){
			if(j!=x){
				ll pos = j - l;
				if(isPrime[pos]){
					isPrime[pos]=0;
				}
			}
		}
	}

	rep(i,0,r-l+1){
		if(isPrime[i])primes.pb(l+i);
	}

	return primes;
}

ll findAnySolution(ll a, ll b, ll &x, ll &y){
	if(b==0){
		x = 1;
		y = 0;
		return a;
	}
	ll x1, y1;
	ll d = findAnySolution(b, a%b, x1, y1);
	x = y1;
	y = x1 - y1*(a/b);
	return d;
}

ll gcd(ll x, ll m) {
	if (m == 0) return x;
	else return gcd(m , x % m);
}

ll findAllSolutions(ll a, ll b, ll c,ll lx, ll rx, ll ly, ll ry){
	ll d = gcd(a,b);
	if(c%d){return 0;}
	c/=d;
	a/=d;
	b/=d;
	ll k =ceil((double) ((lx - c%b)*(a%b))/b);
	lx = abs(k);
	cout<<lx<<endl;
	k =floor((double) ((rx - c%b)*(a%b))/b);
	rx = abs(k);
	cout<<rx<<endl;
	k = ceil((double) (c-ly*b-(c%b)*a)/(a*b));
	ly =abs(k);
	cout<<ly<<endl;
	k = floor((double) (c-ry*b-(c%b)*a)/(a*b));
	ry =abs(k);
	cout<<ry<<endl;
	lx = max(lx,ly);
	ry = min(rx,ry);
	return (ry-lx)>0?ry-lx:0;
}

void solve() {
	ll n=1,a=1,k=1,minVal=LLONG_MAX,maxVal=LLONG_MIN,ans=LLONG_MAX,b=1,c=1;
	ll x,y,lx,rx,ly,ry;
	cin>>a>>b>>c;
	lx = 0,ly=0,rx=INT_MAX,ry=INT_MAX;
	ll d = findAnySolution(a,b,x,y);
	a/=d;
	b/=d;
	if(c%d==0 && (c%b)%(a%b)==0 && (c%b)/(a%b)<b)cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
	return;

}

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

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


#include <iostream>

using namespace std;

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

    int ans = 0;
    for(int i = 0; i < s.size(); i++) {
        if(s[i] == 'a' || s[i] == 'e' || s[i] == 'i' || s[i] == 'o'
           || s[i] == 'u' || (int)s[i] % 2 == 0) {
            ans++;
        }
    }

    cout << ans;

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    string s;cin>>s;
    string a="aeiou02468";
    int k=0;
    for(int i=0;i<s.length();i++)
    {
        if(find(a.begin(),a.end(),s[i])!=a.end())k++;
    }
    cout<<k<<endl;
}


#include <iostream>
#include <string.h>
#include <algorithm>
#include <stdio.h>
#include <set>
#include <map>
using namespace std;
map<long long,int>m;

void fun(long long n,long long l,long long r){
	if(n==1)
		return;
	if(n%2==1)
		m[(l+r)/2]=1;
	else
		m[(l+r)/2]=0;
	fun(n/2,l,(l+r)/2-1);
	fun(n/2,(l+r)/2+1,r);
}

int main(){

	long long n;
	int l,r;
	while(~scanf("%I64d",&n)){
		scanf("%d %d",&l,&r);
		m.clear();
		int cnt=0;
		long long k=1;
		long long t=n;
		while(t!=1){
			t/=2;
			k=2*k+1;
		}
		fun(n,1,k);
		long long ans=0;
		for(long long i=l;i<=r;i++){
			if(i%2==0)
				ans+=m[i];
			else
				ans++;
		}
		printf("%I64d\n",ans);
	}
	return 0;
}


//#pragma comment (linker, "/STACK:64000000")
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include <typeinfo>
#include <set>
#include <cctype>
#include <locale>
#include <utility>
#include <map>
#include <iterator>
#include <valarray>
#include <complex>
#include <sstream>
#include <bitset>
#include <ctime>
#include <list>
#include <numeric>
#include <cstring>
/*
#include <unordered_map>
#include <unordered_set>
#include <regex>
*/
#define all(c) c.begin(),c.end()
#define rall(c) c.rbegin(),c.rend()
#define ifo(n,v) for(int i=v;i<n;++i)
#define Fi for(int i=0;i<n;++i)
#define Vi vector <int>
#define pb push_back
#define sz size()
using namespace std;

int in() {
    int a;
    scanf("%d", &a);
    return a;
}

double din() {
    double a;
    scanf("%lf", &a);
    return a;
}

int gcd(int a, int b) {
    while(b){
        a%=b;
        swap(a,b);
    }
    return a;
    //return b ? gcd(b, a % b) : a;
}

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

const double eps = 1e-6;
const double pi = 3.14159265358979323;
const int INF = 999999999;

int qq(int a,int b){
    int c=a+b;
    int res=0;
    while(c%10==0){
        ++res;
        c/=10;
    }
    return res;
}
bool isa(char a){
    if(a=='a'||a=='e'||a=='i'||a=='o'||a=='u') return true;
    else return false;
}
bool isprime(int a){
    for(int i=2;i*i<=a;++i){
        if(a%i==0) return false;
    }
    return true;
}
struct Node{
    Node *l, *r,*p;
    int x,y;

    vector <Node*> a;
    vector <char> u;
    Node* use(){
        if(u.empty()) u.assign(a.size(),0);
        for(int i=0;i<u.size();++i){
            if(!u[i]){
                u[i]=1;
                return a[i];
            }
        }
        return NULL;
    }
    Node(){

    }

    Node(int xx,int yy){
        x=xx;
        y=yy;
        l=NULL;
        r=NULL;
        p=NULL;
    }
    Node(int xx,int yy,Node *pp){
        x=xx;
        y=yy;
        p=pp;
        l=NULL;
        r=NULL;
    }
    void setp(Node *pp){
        p=pp;
    }
};

class Treap{
private:
    Node *root,*l;
    void insert(Node *&r,Node *a){
        if(r==NULL){
            r=a;
            return;
        }
        // cout<<r->y<<' '<<a->y<<endl;
        if(a->y < r->y){
            split(r,a->x,a->l,a->r);
            r=a;
        }else{
            if(a->x < r->x) insert(r->l,a);
            else insert(r->r,a);
        }
    }
    void split(Node *a,int X,Node *&l,Node *&r){
        if(a==NULL){
            l=r=NULL;
            return;
        }
        if(a->x > X){
            split(a->l,X,l,a->l);
            r=a;
        }else{
            split(a->r,X,a->r,r);
            l=a;
        }

    }
    void built(Node *r,Node *t){
        while(r->y > t->y && r->p!=NULL){
            r=r->p;
        }
        if(r->p==NULL && t->y < r->y){
            r->p=t;
            t->l=r;
            root=t;
            root->p=NULL;
            l=t;
            return;
        }
        t->l=r->r;
        r->r=t;
        t->p=r;
        t->l->p=t;
        l=t;
    }

public:
    Treap(){
        root=NULL;
        l=NULL;
    }
    void built(pair<int,int> a){
        Node *n=new Node(a.first,a.second);
        if(root==NULL){
            root=n;
            l=n;
            return;
        }
        //cout<<root->y<<endl;
        if(l->y < n->y){
            l->r=n;
            n->p=l;
            l=n;
            return;
        }
        built(l,n);
    }

    void insert(pair<int,int> a){
        Node *node=new Node(a.first,a.second);
        insert(root,node);
    }
    Node* getRoot(){
        return root;
    }
};
/*int n=in();
vector<int>a,res,p;
for(;a.size()<n;a.push_back(in()));
vector<int>dp(a.size()+1,INF);
dp[0]=-INF;
for(int i=0;i<n;++i){
    int j=distance(dp.begin(),upper_bound(all(dp),a[i]));
    if(dp[j-1]<a[i] && a[i]<dp[j])
        dp[j]=a[i];
}
for(int i=1;i<=n;++i) cout<<dp[i]<<' ';*/
struct nod{
    nod *l,*r;
    long long sum;
};
int min(int x,int y){
    return y ^ ((x ^ y) & -(x < y));
}
int max(int x,int y){
    return x ^ ((x ^ y) & -(x < y));
}
int aa(int a){
    return log10(a);
}

string tos(int a){
    string r="";
    while(a>0){
        r+=a%10+'0';
        a/=10;
        // cout<<a;
    }
    reverse(all(r));
    return r;
}

string ma(string a){
    string r="";
    for(int i=0;i<a.size();++i){
        if(a[i]=='4' ||a[i]=='7') r+=a[i];
    }
    return r;
}
struct state {
    int len, link;
    map<char,int> next;
};

bool com(pair<double,int> a,pair<double,int> b){
    if (fabs(a.first-b.first)<=eps) return a.second<b.second;
    else return a.first>b.first;
}
long double nextApproximation(long double x){
    return x-(3*x+cos(x)+1)/(3-sin(x));
}
bool exit(){
    exit(0);
}
double dist(int x1,int y1,int x2,int y2){
    return sqrt((x2-x1)*(x2-x1)+(y2-y1)*(y2-y1));
}
vector<vector<long long> > g;
vector<vector<long long> > f;
vector <long long> ptr;
vector<long long> d;
bool bfs(int t,int s,int n){
    d.assign(n,0);
    queue<long long> q;
    q.push(s);
    d[s]=1;
    while(!q.empty()){
        long long v=q.front();
        q.pop();
        for(long long i=0;i<n;++i){
            if(d[i]==0 &&  g[v][i]-f[v][i]>0 ){
                q.push(i);
                d[i]=d[v]+1;
            }
        }
    }

}

long long dfs(int v,long long flow,int t,int n){
    // cout<<v<<' ';
    if(v==t || flow<=0) return flow;
    for(long long &i=ptr[v];i<n;++i){
        if(d[i]==d[v]+1 && g[v][i]>f[v][i]){
            long long push=dfs(i,min(flow,g[v][i]-f[v][i]),t,n);
            if(push>0){
                f[v][i]+=push;
                f[i][v]-=push;
                return push;
            }

        }
    }
    return 0;
}

int main(){
    //freopen("input.txt","r",stdin);
    // freopen("output.txt","w",stdout);
    int vp=in(),vd=in(),t=in(),f=in(),c=in();
    double p=t*vp,d=0;
    int res=0;
    while(fabs(p-c)>eps){
       double t2=(double)(p-d)/vd;
      // cout<<t2<<' ';
       if(((c-p)/(double)vp)>t2){
           res++;
           p+=vp*((2.*p)/vd);
           p+=f*vp;
       }else{
           d+=vd;
           p+=vp;
       }
    }
    cout<<res;

    return 0;
}
// vector <state> st;
/*  int n=in(),m=in();
g.assign (n,vector<long long>(n,0));
f.assign (n,vector<long long>(n,0));
for(int i=0;i<m;++i){
    int a,b,c;
    scanf("%d%d%d",&a,&b,&c);
    g[a-1][b-1]=c;
   // g[b][a]+=c;
}
int s=0,t=n-1;
long long inf=(long long)10000000000000;
long long flow=0;
while(bfs(t,s,n)){
   // for(int i=0;i<n;++i) cout<<d[i]<<' ';
  //  cout<<endl;
    ptr.assign(n,0);
    while(long long push=dfs(s,inf,t,n)) flow+=push;
}
cout<<flow<<endl;*/


#include<bits/stdc++.h>
using namespace std;
typedef int64_t lld;
typedef pair<int,int> pii;
#define int __int128
#define ff first
#define ss second
#define pb push_back
#define all(x) (x).begin(),(x).end()
//#define endl '\n'
#define jizz cin.tie(0);cout.tie(0);ios::sync_with_stdio(0);
template<typename Iter>
ostream& _out(ostream &s, Iter b, Iter e) {
    s<<"[";
    for ( auto it=b; it!=e; it++ ) s<<(it==b?"":" ")<<*it;
    s<<"]";
    return s;
}
template<class T1,class T2>
ostream& operator<<(ostream& out, pair<T1,T2> p) {
    return out << '(' << p.first << ", " << p.second << ')';
}
template<class T1,class T2>
istream& operator>>(istream& in, pair<T1,T2>& p) {
    return in >> p.ff >> p.ss;
}
template<typename T>
ostream& operator <<( ostream &s, const vector<T> &c ) {
     return _out(s,c.begin(),c.end());
}
int invmod(int a, int b, int s0 = 0, int s1 = 1){
    return b?invmod(b, a%b, s1-a/b*s0, s0):s1;
}
int gcd(int a, int b){
    return b?gcd(b, a%b):a;
}
signed main(){//jizz; //freopen("test.in", "r", stdin);
    signed _a1, _b1, _a2, _b2, _L, _R; //a1 k + b1 = a2 l + b2 => a1 k - a2 l = b2 - b1;
    cin >> _a1 >> _b1 >> _a2 >> _b2 >> _L >> _R;
    int a1 = _a1, b1 = _b1, a2 = _a2, b2 = _b2, L = _L, R = _R;
    if(b2 < b1)swap(a1, a2), swap(b1, b2);
    int t1 = (invmod(a1, a2)%a2+a2)%a2, g = gcd(a1, a2), t2 = (t1*a1-g)/a2; // t1*a1 - t2*a2 = g
    //cout << (lld)t1 << " " << (lld)t2 << endl;
    assert(t1*a1-t2*a2 == g);
    if((b2-b1)%g)return cout << 0 << endl, 0;
    //cout << (lld)t1 << " " << (lld)t2 << endl;
    t1*=(b2-b1)/g, t2*=(b2-b1)/g;
    //cout << (lld)t1 << " " << (lld)t2 << endl;
    t1 = (t1%(a2/g)+a2/g)%(a2/g); t2%=(t2%(a1/g)+a1/g)%(a1/g);
    //cout << (lld)t1 << " " << (lld)t2 << endl;
    //assert(t1 >= 0 && t2 >= 0);
    int posa = max(t1*a1+b1, t2*a2+b2), add = a1*a2/g;
    //assert((posa-b1)%a1 == 0);
    //assert((posa-b2)%a2 == 0);
    L-=posa, R-=posa;L--;
    //cout << (lld)L << " " << (lld)R << endl;
    if(R < 0)return cout << 0 << endl, 0;
    if(L < 0)return cout << (lld)(R/add+1) << endl, 0;
    cout << (lld)(R/add-L/add) << endl;

}


/* be name khoda */

// #define stream_enable
#define long_enable
#include <iostream>
#include <algorithm>
#include <cstring>
#include <numeric>
#include <iomanip>
#include <sstream>
#include <vector>
#include <queue>
#include <set>
#include <map>
using namespace std;

#ifdef stream_enable
#define cin sss
#endif
#ifdef long_enable
typedef long long int ll;
#else
typedef int ll;
#endif

typedef pair<ll, ll> pii;
typedef pair<pii, ll> ppi;
typedef pair<ll, pii> pip;
typedef vector<ll> vi;
typedef vector<pii> vpii;

const ll MOD = 1000000007;
const long long BIG = 1446803456761533460;
const int Big = 336860180;

#define F first
#define S second
#define pb push_back
#define eb emplace_back
#define all(x) (x).begin(), (x).end()

#define debug(x) cout << #x << " -> " << (x) << endl;
#define debug2(x, y) cout << #x << ' ' << #y << " -> " << (x) << ' ' << (y) << endl;
#define debug3(x, y, z) cout << #x << ' ' << #y << ' ' << #z << " -> " << (x) << ' ' << (y) << ' ' << (z) << endl;
#define debug4(x, y, z, t) cout << #x << ' ' << #y << ' ' << #z << ' ' << #t << " -> " << (x) << ' ' << (y) << ' ' << (z) << ' ' << (t) << endl;
#define debugp(x) cout << #x << " -> " << "(" << (x).F << ", " << (x).S << ")" << endl;
#define debuga(x, n) cout << #x << " -> "; fori (i1_da, n) { cout << (x)[i1_da] << ' '; } cout << endl
#define debugap(x, n) cout << #x << " ->\n"; fori (i1_dap, n) { cout << "(" << (x)[i1_dap].F << ", " << (x)[i1_dap].S << ")\n"; } cout << endl
#define debugaa(x, n, m) cout << #x << " ->\n"; fori (i1_daa, n) { fori (i2_daa, m) { cout << (x)[i1_daa][i2_daa] << ' '; } cout << '\n'; } cout << endl
#define debugav(x, n) cout << #x << " ->\n"; fori (i1_dav, n) { fori (i2_dav, (x)[i1_dav].size()) { cout << (x)[i1_dav][i2_dav] << ' '; } cout << '\n'; } cout << endl
#define debugia(x, n) cout << #x << " ->\n"; fori (i1_dia, n) { cout << i1_dia << " : " << (x)[i1_dia] << '\n'; } cout << endl

#define forifrom(i, s, n) for(ll i = (s); i < (n); ++i)
#define forirto(i, n, e) for(ll i = (n) - 1; i >= (e); --i)
#define fori(i, n) forifrom (i, 0, n)
#define forir(i, n) forirto (i, n, 0)

#define smin(a, b) a = min(a, (b))
#define smax(a, b) a = max(a, (b))

#define Add(a, b) a = (a + (b)) % MOD
#define Mul(a, b) a = (a * (b)) % MOD

stringstream sss;

// -----------------------------------------------------------------------

const ll maxd = 18;
const ll maxd2 = 1 << maxd;
const ll maxm = 100;

string n;
ll m;
ll dp[maxd2][maxm];
ll fact[maxd];

void MAIN() {

    cin >> n >> m;
    ll s = n.size();
    ll s2 = 1 << s;
    dp[0][0] = 1;
    fori (i, s2) {
        fori (j, s) {
            if (i >> j & 1) {
                if ((i ^ (1 << j)) == 0 && n[j] == '0') continue;
                fori (k, m) {
                    dp[i][(k * 10 + n[j] - '0') % m] += dp[i ^ (1 << j)][k];
                }
            }
        }
    }
    fact[0] = 1;
    fori (i, 10) fact[i + 1] = fact[i] * (i + 1);
    ll ans = dp[s2 - 1][0];
    fori (i, 10) {
        ans /= fact[count(all(n), '0' + i)];
    }
    cout << ans << '\n';

}

// -----------------------------------------------------------------------

int main() {
    ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
    cout << fixed << setprecision(10);
    sss << R"(
7067678 8
    )";
    MAIN();
    return 0;
}


#include <bits/stdc++.h>
#define ll          long long int
#define uu          first
#define vv          second
#define pii         pair<int,int>
#define pll         pair<ll,ll>
#define tp          tuple<int,int,int>
#define fastio      ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
using namespace std;
const int INF = 1e9;
const ll MOD = 1e9 + 7;

const int N = 1e6 + 6;

int main() {
    int n , m , k;
    cin>>n>>m>>k;

    string one = "Timur" , two = "Marsel";
    if(n%2 ==0) {
        cout<<two<<'\n';
        return 0;
    }

    int div = 0;
    for(ll i = 2 ; i*i <= m ; i++) {
        if(m % i) continue;
        int div1 = i;
        int div2 = m/i;
        if(div1 >=k || div2 >= k) div = 1;
    }

    if(k ==1 && m > 1) div = 1;

    if(k == 1 || div) cout<<one<<'\n';
    else cout<<two<<'\n';
    return 0;

}


/***************************************************************
	File name: A.cpp
	Author: ljfcnyali
	Create time: 2019年10月20日 星期日 17时03分35秒
***************************************************************/
#include<bits/stdc++.h>

using namespace std;

#define REP(i, a, b) for ( int i = (a), _end_ = (b); i <= _end_; ++ i )
#define mem(a) memset ( (a), 0, sizeof ( a ) )
#define str(a) strlen ( a )
#define pii pair<int, int>
#define int long long
typedef long long LL;

const int Mod = 1e9 + 7;

int f[100010], n, m;

signed main()
{
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    cin >> n >> m;
    f[1] = 1; f[2] = 2;
    REP(i, 3, n + m) f[i] = (f[i - 1] + f[i - 2]) % Mod;
    cout << (2 * (f[n] + f[m] - 1)) % Mod << endl;
    return 0;
}


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

int main()
{

	#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
    #endif
	int a[10]={6,2,5,5,4,5,6,3,7,6};
	int x,y,cnt=0,i;
	ll ans=0;
	cin>>x>>y;
	for(i=x;i<=y;++i)
	{
		while(i)
		{
			ans+=a[i%10];
			i/=10;
		}

	}
	cout<<ans;
}


#include<iostream>
using namespace std;
int main(void)
{
	int n,s,sum = 0,max = 0;
	cin >> n >> s;
	for(int i = 0 ; i , n ; i ++)
	{
		int x;
		cin >> x;
		if(x > max) max = x;
		sum += x;
	}
	if(sum - max <= s)  cout << "NO" << endl;
	else 			    cout << "YES" << endl;
	return 0;
}


#include <cstdio>
#include <iostream>

#define Max 1000001
#define MOD 1000000007
typedef long long LL;
const LL INF = 1e15 + 7LL;
using namespace std;
#define MAXN 105
int flag;
int n, k;
int a[4][4];
int main() {
	for (int i = 0; i < 4; i++) {
		for (int j = 0; j < 4; j++) {
			scanf("%d", &a[i][j]);
		}
	}
	int flag = 0;
	for (int i = 0; i < 4; i++) {
		if (a[i][3] == 1) {
			int t = (i + 1) % 4;
			int duimian = (i + 2) % 4;
			int shangmian = (i + 3) % 4;
			if(a[i][1]==1)
				flag=1;
			if (a[shangmian][2] == 1)
				flag = 1;
			if (a[duimian][1] == 1)
				flag = 1;
			if (a[t][0] == 1)
				flag = 1;
		}
	}
	if (flag == 1) {
		cout << "YES" << endl;
	} else {
		cout << "NO" << endl;
	}
	return 0;
}


//......by LFEY......//
#include <iostream>
#include <string>
#include <cstdlib>
#include <cstdio>
#include <set>
#include <map>
#include <vector>
#include <queue>
#include <algorithm>
#include <cmath>
#include <stack>
#include <deque>
#include <iomanip>

#define ll long long
#define pb push_back
#define mpr make_pair
#define F first
#define S second
#define pii pair <int, int>

using namespace std;

const int MX = 1e9 + 1;
const int Imp = -1;
const int INF = 1e7 + 100;
const int N = 1e6 + 5;
const int M = 1e5 + 5;

int X[] = {1, -1, 0, 0};
int Y[] = {0, 0, 1, -1};

map<char,int>mp;

ll mx = -1,ans;

ll ok , ok1;

vector<ll>v;

main(){
//	freopen(".in","r",stdin);
//	freopen(".out","w",stdout);
	ll n;
	cin >> n;
	string s;
	cin >> s;
	for(int i = 0 ; i < s.size(); ++i){
		ll g;
		while(1){
			if(s[i] == 'o' && s[i+1]=='g' && s[i+2] == 'o'){
				s[i] = '*';
				s[i+1] = '*';
				i += 2;
			 	g = i;
			}
			else
			{
				break;
			}
		}
		s[(g < s.size() ? g:i-1)] = '*';
	}
	cout<<s;
}


#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<cmath>
#include<vector>
#include<set>
#include<map>
using namespace std;
typedef long long ll;

#define inf int(0x3f3f3f3f)
#define mod int(1e9+7)
#define pi acos(-1.0)

int n,m;

int dx,dy;
int x,y;

char s[100005];

map<int,int> a[100010];

int main()
{
    cin>>n>>m;
    cin>>x>>y;
    scanf("%s",s+1);
    ll sum=0;
    if(s[1]=='U')
        dx=-1;
    else
        dx=1;
    if(s[2]=='L')
        dy=-1;
    else
        dy=1;
    int cnt=n+m-2;
    if(x==1||x==n||y==1||y==m)
    {
        a[x][y]=1;
        cnt--;
    }
    ll ji=0;
    while(1)
    {
        ji++;
        if(ji>=1e8)
        {
            cout<<-1<<endl;
            return 0;
        }
        int dis=inf;
        if(dx==1)
            dis=min(dis,n-x);
        else
            dis=min(dis,x-1);
        if(dy==1) dis=min(dis,m-y);
        else
            dis=min(dis,y-1);
        x+=dx*dis;
        y+=dy*dis;
        sum+=dis;
        if(x==1)
            dx=1;
        else if(x==n)
            dx=-1;
        if(y==1)
            dy=1;
        else if(y==m)
            dy=-1;
        if(a[x][y]==0)
        {
            cnt--;
            a[x][y]=1;
        }
        if(!cnt)
        {
            cout<<sum+1<<endl;
            return 0;
        }
    }
}


#include <bits/stdc++.h>

using namespace std;
int n;
int len;
long long power[60];
int maxPow = 0;
string k;
long long dp[65][65];

long long solve(int ind,int po) {
    if(ind == -1)
        return 0;
    if(po >= maxPow)
        return 1E18;

    if(dp[ind][po] != -1)
        return dp[ind][po];
    string s = "";
    long long ans = 1E18+1;
    for(int i = ind;i>=0;i--) {
        s = k[i] + s;
        long long num;
        stringstream convert(s);
        convert>>num;
        if(s.length() > 1 && s[0] == '0')
            continue;
        if(num >= n || num * power[po] < 0 || LONG_LONG_MAX / power[i] < num) {
            break;
        } else {
            ans = min(ans,solve(i-1,po+1) + num * power[po]);
        }
    }
    return dp[ind][po] = ans;
}

int main()
{
    cin>>n>>k;
    len = k.length();
    power[0] = 1;
    memset(dp,-1,sizeof dp);
    for(int i = 1;i<n;i++) {
        power[i] = power[i-1] * n;
        if(power[i] < power[i-1])
            break;
        else
            maxPow = i;
    }
    cout<<solve(len-1,0);
    return 0;
}


#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<cstdio>
#include<iostream>
using namespace std;

typedef long long ll;
int n,m;
int L;
/*
int main()
{
	scanf("%d%d",&n,&m);L=n+1;
	ll ans=0;
	for (int a=m+1;a<=n-m;a++){
        int lef=m+1,rig=min(2*a-1,n-m),mid;
        while(lef<=rig){
                        mid=lef+rig>>1;
                        ll t=L-(1ll*(L-a)*(-mid+2*a)-1)/(mid+a);
                        if(t<=m+1)lef=mid+1;
                        else rig=mid-1;
        }
        ans+=1ll*(n-2*m)*(lef-m-1);
        //printf("%d %d %d\n",a,lef,lef-m-1);
		//for (int b=min(2*a-1,n-m);b>m;b--){
         for (int b=lef;b<=2*a-1 && b<=n-m;b++){
			ll t=L-(1ll*(L-a)*(-b+2*a)-1)/(b+a);
		//	printf("%lld\n",t);
			if(t<=n-m){
                      ans+=n-m-t+1;
                     //  else {ans+=1ll*(n-2*m)*(n-m-b+1);break;}
			}else break;
		}
    }
	cout<<ans*3<<endl;
	return 0;
}*/
int main()
{
	scanf("%d%d",&n,&m);L=n+1;
	ll ans=0;
	for (int a=m+1;a<=n-m;a++){
        int lef=m+1,rig=min(2*a-1,n-m),mid;
        while(lef<=rig){
                        mid=lef+rig>>1;
                        ll t=L-(1ll*(L-a)*(-mid+2*a)-1)/(mid+a);
                        if(t<=m+1)lef=mid+1;
                        else rig=mid-1;
        }
        ans+=1ll*(n-2*m)*(lef-m-1);
         for (int b=lef,t=L-(1ll*(L-a)*(-lef+2*a)-1)/(lef+a);b<=2*a-1 && b<=n-m;b++){
		     while(t<=n-m && 1ll*(L-t)*(a+b)>=1ll*(L-a)*(2*a-b))t++;
			if(t<=n-m){
                      /* if(t>m+1)*/ans+=n-m-t+1;
                     //  else {ans+=1ll*(n-2*m)*(n-m-b+1);break;}
			}else break;
		}
    }
	cout<<ans*3<<endl;
	return 0;
}


#include <iostream>

using namespace std;

int main (){
    int n;
    cin >> n;
    int vet[6];
    int aux;
    for(int i = 0 ; i < 6 ; i++){
        cin >> vet[i];
    }
    for(int i = 0 ; i < 6 ; i++){
        for(int k = i+1 ; k < 6 ;k++)
            if(vet[i]>vet[k]){
                aux = vet[i];
                vet[i] = vet[k];
                vet[k] = aux;
            }
    }

    for(int i = 0 ; i < 6 ; i++)
        if((vet[i]+vet[i+1]+vet[i+2])==n && i+2 < 6){
            cout<<vet[i]<<" "<<vet[i+1]<<" "<<vet[i+2]<<"\n";
            break;
        }
    return 0;
}


#include <iostream>
#include <algorithm>
#include <cmath>
#include <iterator>
#include <cstddef>
#include <vector>
#include <tuple>
#include <unordered_map>
#include <stack>
#include <functional>
#include <cassert>
#include <set>
#include <map>
#include <utility>

using namespace std;

namespace
{
    // (x+t) \bmod a == 0
    // t = a-x + k_1 a
    // (y+t) \bmod b == 0
    // t = b-y + k_2 b
    // k_2 = \frac{a-b - x+y + k_1 a}{b}
    // x' = x + t
    // y' = y + t
    using lint = long long int;
    int gcd(int a, int b)
    {
        if(a < b)
            return gcd(b, a);
        while(b != 0)
        {
            const auto t = b;
            b = a%b;
            a = t;
        }
        return a;
    }
    int inverse(int val, int mod)
    {
        if(val == 0 || gcd(val, mod) != 1)
            return 0;
        lint res = 1;
        const auto ival = val;
        while(val != 1)
        {
            const auto mult = mod/val+1;
            res *= mult;
            res %= mod;
            const auto nxt = val*mult%mod;
            if(nxt != val)
            {
                val = nxt;
            }
            else
            {
                val = nxt+ival;
                res += 1;
                res %= mod;
            }
        }
        return res%mod;
    }
    pair<tuple<int, int>, bool> billiard(const tuple<int, int> &sz,
        const tuple<int, int> &pos, const tuple<int, int> &vel)
    {
        if(get<0>(sz) > get<1>(sz))
        {
            const auto res = billiard(make_tuple(get<1>(sz), get<0>(sz)),
                make_tuple(get<1>(pos), get<0>(pos)),
                make_tuple(get<1>(vel), get<0>(vel)));
            return make_pair(make_tuple(get<1>(res.first), get<0>(res.first)),
                res.second);
        }
        const auto x = (get<0>(sz)+get<0>(pos)*get<0>(vel))%get<0>(sz);
        const auto y = (get<1>(sz)+get<1>(pos)*get<1>(vel))%get<1>(sz);
        if(get<0>(vel) == 0)
        {
            if(get<0>(pos)%get<0>(sz) == 0)
            {
                return make_pair(make_tuple(
                        get<0>(pos),
                        get<1>(vel)>0?get<1>(sz):0), true);
            }
            else
            {
                return make_pair(make_tuple(0, 0), false);
            }
        }
        if(get<1>(vel) == 0)
        {
            if(get<1>(pos)%get<1>(sz) == 0)
            {
                return make_pair(make_tuple(
                        get<0>(vel)>0?get<0>(sz):0,
                        get<1>(pos)), true);
            }
            else
            {
                return make_pair(make_tuple(0, 0), false);
            }
        }
        const auto c = (get<1>(sz) - get<0>(sz)+get<1>(sz) + x - y)%get<1>(sz);
        const auto g = gcd(c, gcd(get<0>(sz), get<1>(sz)));
        lint cdash = c;
        lint sz1dash = get<0>(sz);
        lint sz2dash = get<1>(sz);
        if(g != 0)
        {
            cdash /= g;
            sz1dash /= g;
            sz2dash /= g;
        }
        const auto v = inverse(sz1dash%sz2dash, sz2dash);
        if((v*cdash%sz2dash*sz1dash%sz2dash + sz2dash - cdash)%sz2dash != 0)
            return make_pair(make_tuple(0, 0), false);
        const lint k1 = cdash*v%sz2dash;
        const lint t = (get<0>(sz) - x + k1*get<0>(sz));
        return make_pair(
            make_tuple(
                abs(get<0>(pos) + t*get<0>(vel))%(get<0>(sz)*2),
                abs(get<1>(pos) + t*get<1>(vel))%(get<1>(sz)*2)
                ), true);
    }
}

int main()
{
    tuple<int, int> sz;
    tuple<int, int> pos;
    tuple<int, int> vel;
    cin>>get<0>(sz)>>get<1>(sz);
    cin>>get<0>(pos)>>get<1>(pos);
    cin>>get<0>(vel)>>get<1>(vel);
    const auto res = billiard(sz, pos, vel);
    if(res.second)
    {
        cout<<get<0>(res.first)<<' '<<get<1>(res.first)<<endl;
    }
    else
    {
        cout<<-1<<endl;
    }
    return 0;
}


  #include<iostream>
  using namespace std;
  int main()
  {
  	int a,b,c,min;
  	cin>>a>>b>>c;
  	min=a;
  	if(b<min)
  	min=b;
  	if(c<min)
  	min=c;
  	if(min==a)
  	cout<<a*3+3;
  	if(min==b)
  	cout<<b*3;
  	if(min==c)
  	cout<<c*3-3;
  	return 0;

  }