#include "bits/stdc++.h"

using namespace std;

const int N = 2e5 + 5;

char s[N], x[N];
int dp[N][7];

int n;

int solve (int pos, int rem) {
  if (pos == n) {
    return rem == 0;
  }
  int &ret = dp[pos][rem];
  if (ret != -1) {
    return ret;
  }
  ret = 1;
  int dig = s[pos] - '0';
  int hi = solve(pos + 1, (10 * rem + dig) % 7);
  int bi = solve(pos + 1, (10 * rem) % 7);
  if (x[pos] == 'A') {
    ret = 1;
    if (hi == 0 || bi == 0) {
      ret = 0;
    }
  } else {
    ret = 0;
    if (hi == 1 || bi == 1) {
      ret = 1;
    }
  }
  return ret;
}

int main() {
  scanf("%d", &n);
  scanf("%s", s);
  scanf("%s", x);
  memset(dp, -1, sizeof dp);
  int lol = solve(0, 0);
  lol ? puts("Takahashi") : puts("Aoki");
  return 0;
}

#include <iostream>
using namespace std;

int main()
{
    int n;
    cin >> n;
    string s, x;
    cin >> s >> x;
    bool b[7]{0};
    b[0] = true;
    for(int i = n - 1; i > 0; i--){
        bool c[7];
        if(x[i] == 'T'){
            for(int j = 0; j < 7; j++){
                c[j] = false;
                for(int k = 0; k < 7; k++){
                    if(!b[k]) continue;
                    if((j * 10 + s[i] - '0' - k) % 7 == 0) c[j] = true;
                    if((j * 10 - k) % 7 == 0) c[j] = true;
                }
            }
        }
        else{
            for(int j = 0; j < 7; j++){
                c[j] = true;
                for(int k = 0; k < 7; k++){
                    if(b[k]) continue;
                    if((j * 10 + s[i] - '0' - k) % 7 == 0) c[j] = false;
                    if((j * 10 - k) % 7 == 0) c[j] = false;
                }
            }
        }
        swap(b, c);
    }
    if(x[0] == 'T'){
        if(b[0] || b[s[0] - '0']) cout << "Takahashi" << endl;
        else cout << "Aoki" << endl;
    }
    else{
        if(!b[0] || !b[s[0] - '0']) cout << "Aoki" << endl;
        else cout << "Takahashi" << endl;
    }
}


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

int32_t main() {

    int n; cin >> n;
    vector<vector<int>> dp(n + 1, vector<int> (13, 0));

    dp[0][0] = 1;
    for(int j = 1; j <= n; j ++) {
        for(int i = 1; i <= 12; i ++) {

            if(i > j)
                continue;
            else if(i == j)
                dp[i][j] = 1;
            else {

                for(int k = 1; k <= j; k ++)
                    dp[j][i] += dp[j - k][i - 1];
            }
        }
    }

    // for(int i = 1; i <= n; i ++) {
    //     for(int j = 1; j <= 12; j ++)
    //         cout << dp[i][j] << ' ';
    //     cout << endl;
    // }

    cout << dp[n][12] << endl;
}

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define uint unsigned int
#define pb push_back
#define str string
#define mp make_pair
#define fi first
#define se second
#define sz(a) (int)(a.size())
#define REP(i, n) for(int i = 0; i < (int)n; ++i)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
const ll MOD = 1e9 + 7;
const ll INF = 1e18;
const double PI = acos(-1.0);
const int MAXN = (int)3e5 + 7;

void solve(){
    str s; cin >> s;
    cout << s.substr(1) << s[0];
}

int main(){
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr); cout.tie(nullptr);
    solve();
    return 0;
}


// Problem: A - kcal
// Contest: AtCoder - AtCoder Beginner Contest 205
// URL: https://atcoder.jp/contests/abc205/tasks/abc205_a
// Memory Limit: 1024 MB
// Time Limit: 2000 ms
//
// Powered by CP Editor (https://cpeditor.org)

#include<bits/stdc++.h>
using namespace std;
#define Jai_shri_Ram ios_base::sync_with_stdio(false), cin.tie(NULL);
//#define int long long int
#define rep(x,a,b) for(int x=a;x<b;x++)
#define deb(x) cout<< #x <<" = "<<x<<endl;

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

	double ans = 0.0 ;
	ans = (1.0 * a * b) / 100 ;
	cout << ans << endl ;
}

signed main(){
  Jai_shri_Ram
	solve();
}

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

int main() {
    double A = 0, B = 0;
    cin >> A >> B;
    if (A==0 || B==0) {
        cout << 0 << endl;
        return 0;
    }
    cout << (B / 100) * A << endl;
}


#include<bits/stdc++.h>
#define ff              first
#define ss              second
#define ld              long double
#define ll              long long int
#define mod             1000000007
#define vll             vector<ll>
#define pll             pair<ll, ll>
#define uom             unordered_map
#define uos             unordered_set
#define mxh             priority_queue<ll>
#define ull             unsigned long long
#define INF             9223372036854775807
#define mnh             priority_queue<ll, vector<ll>, greater<ll>>
#define endl            "\n"
#define w(t)            ll tests;    cin>>tests;        while(tests--)
#define pb(x)           push_back(x)
#define ppb()           pop_back()
#define all(x)          x.begin(), x.end()
#define mp(a, b)        make_pair(a, b)
#define setp(x, y)      fixed << setprecision(x) << y
#define f(i, a, b)      for(ll i = a ; i < b ; i++)
#define fo(j, a, b)     for(ll j = a ; j >= b ; j--)
#define fill(a, n, x)   f(i, 0, n)     a[i]=x;
using namespace std;

void init() {
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
}

int main() {

    init();
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

    ll a, b;
    cin >> a >> b;

    ld c = b * 1.0 / 100;
    cout << a*c;

    return 0;
}

#include "bits/stdc++.h"
using namespace std;
int main(){
  cout << fixed << setprecision(15);
  double a,b;cin >> a >> b;
  double ans = a/100.0*b;
  cout << ans << endl;
}


#include <iostream>
#include <iomanip>
#include <vector>
#include <set>
#include <string>
#include <queue>
#include <algorithm>
#include <map>
#include <cmath>
#include <numeric>
#include <list>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <tuple>
#include <deque>
#include <complex>
#include <bitset>

using namespace std;

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;
typedef vector<pii> vpii;

typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<long long, long long> pll;
typedef vector<pll> vpll;

typedef long double ld;
typedef vector<ld> vld;

typedef vector<bool> vb;

#define rep(i, n) for (ll i = 0; i < (n); i++)
#define reps(i, n) for (ll i = 1; i <= (n); i++)
#define rrep(i, n) for (ll i = (n) - 1; i >= 0; i--)
#define rreps(i, n) for (ll i = (n); i >= 1; i--)
#define all(v) (v).begin(), (v).end()

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

constexpr int INF = 1 << 30;
constexpr ll INFL = 1LL << 60;
constexpr ll MOD = 1000000007;
constexpr ld EPS = 1e-12;
ld PI = acos(-1.0);

void solve() {
    vll a(4);
    rep(i, 4) cin >> a[i];
    ll ans = 1000;
    rep(i, 4) chmin(ans, a[i]);
    cout << ans << endl;
    return;
}

int main() {
    std::cin.tie(nullptr);
    std::ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    solve();
}

#include<bits/stdc++.h>
using namespace std;
#define endl "\n";
typedef long long ll;
int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);cout.tie(0);
	ll n,s=0,ma=0;
	cin>>n;
	double a[n],sum=0;
	for(int i=0;i<n;i++){
		cin>>a[i];
		ll k=abs(a[i]);
		ma=max(ma,k);
		s+=abs(a[i]);
		sum+=a[i]*a[i];
	}
	printf("%lld\n",s);
	printf("%0.16f\n",sqrt(sum));
	printf("%lld\n",ma);
}


/**
 *    Author  : Tanbin_Hasan
 *    Created : 15.11.2020
**/
#include <bits/stdc++.h>
using namespace std ;
typedef int_fast64_t ll ;
typedef uint_fast64_t ull ;
double pi = acos(-1.0) ;
double eps = 1e-9 ;
ll L = 31250001 ;
const ll md = 1e9 + 7 ;
#define pb push_back
#define SP(x) cout << fixed << setprecision(x)
vector <ll> check ;
#define on(x) (check[x >> 6] & (1LL << (x & 63)))
#define set1(x) check[x >> 6] |= (1LL << (x & 63))
int main(void)
{
    ios_base::sync_with_stdio(false) ; cin.tie(nullptr) ; cout.tie(nullptr) ;
    #ifdef FILE_IO
    #define FILE_IO
    freopen("input.txt" , "r" , stdin) ; freopen("output.txt" , "w" , stdout) ;
    #endif
    ll n ; cin >> n ;
    cout << ((n < 0) ? 0 : n) << '\n' ;
    return 0 ;
}

/**
 * author : madhav
 * handle : madhav10
**/
#include <bits/stdc++.h>
using namespace std;

#define For(start,end,inc) for( int i=(start);i<(end);i+=inc)
#define pb push_back
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define mp make_pair

bool isPalindrome(string s){
	int n=s.length();
	for(int i=0;i<n/2;i++){
		if(s[i]!=s[n-i-1]){
			return false;
		}
	}
	return true;
}
template <typename T ,typename U>
T max_self(T a,U b){
    if(b>a){
        a=b;
    }
    return a;
}
template <typename T ,typename U>
T min_self(T a,U b){
    if(b<a){
        a=b;
    }
    return a;
}

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vli;
typedef pair<int,int> ii;
typedef pair<ll, ll> lii;

void solve(){
	string s;
	cin>>s;
	int n=s.length();
	int i=0,j=n-1;
	while(i<n && s[i]=='0'){
		i++;
	}
	while(j>=0 && s[j]=='0'){
		j--;
	}
	if(i>j){
		cout<<"Yes\n";
		return;
	}
	int range=j-i+1;
	bool ok=true;
	for(int k=0;k<range/2;k++){
		//cout<<k+i<<" "<<i+range-k<<"\n";
		if(s[k+i]!=s[i+range-k-1]){
			ok=false;
		}
	}
	cout<<(ok?"Yes":"No")<<"\n";

}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int tt=1;
	//cin>>tt;
	while(tt--){
		solve();
	}
    return 0;
}


#include <bits/stdc++.h>
#define int ll
#define double long double
#define rbtree __gnu_pbds::tree<int,__gnu_pbds::null_type,less<int>,__gnu_pbds::rb_tree_tag,__gnu_pbds::tree_order_statistics_node_update>
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);
#define pb push_back
#define ALL(X) X.begin(),X.end()
#define F(i,n)  FF(i,0,n)
#define F1(i,n)  FF(i,1,n+1)
#define FF(i,n,m) for(int i=(int)n;i<(int)m;++i)
#ifndef LOCAL
//#pragma GCC optimize("Ofast,unroll-loops,no-stack-protector")
#else
#endif // LOCOL
//#define mp make_pair
using namespace std;
//using namespace __gnu_pbds;
template<typename T> bool remax(T& a, const T& b) {return b>a?a=b,1:0;}
template<typename T> bool remin(T& a, const T& b) {return b<a?a=b,1:0;}
inline ostream& operator << (ostream& os,__int128_t a){if(a==0) {return (os<<'0');}bool flag=0;if(a<0) {a=-a,flag=1;}string s;while(a){s+=a%10+'0';a/=10;}s+=flag?"-":"";reverse(ALL(s));return os<<s;}
inline istream& operator >>(istream& is,__int128_t& a){string s;cin>>s;a=0;for(auto c:s) a=a*__int128_t(10)+__int128_t(c-'0');return is;}
template<typename T,typename P> inline ostream& operator << (ostream& os,pair<T,P> a){os<<a.first<<" "<<a.second; return os;}
template<typename T,typename P> inline istream& operator >> (istream& is,pair<T,P> &a){is>>a.first>>a.second; return is;}
using ll=long long;
using ull=unsigned long long;
using int128= __int128_t;
using uint128= __uint128_t;
using pii =pair<int,int>;
const double pi=acos(-1);
const int N=5000+5;
const ll M=1000000000;
const ll INF_64=0x3f3f3f3f3f3f3f3f;
const int INF_32=0x3f3f3f3f;
const int16_t INF_16=0x3f3f;
const int klog=20;
const int mod=998244353;//1E9+7
const double eps=1E-8;

void gen(){

}

void sol(){
    int a[3];
    cin>>a[0]>>a[1]>>a[2];
    sort(a,a+3);
    if(a[0]==a[1])
        cout<<a[2]<<"\n";
    else if(a[1]==a[2])
        cout<<a[0]<<"\n";
    else cout<<"0\n";

}
int32_t main(){
    #ifdef LOCAL
    //freopen(".in","r",stdin);
    //freopen(".out","w",stdout);
    #endif // LOCAL
    IOS;
    int t=1;
    gen();
    //cin>>t;
    FF(i,1,t+1){
        //cout<<"Case #"<<i<<": ";
        sol();
    }
}

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

using namespace std;
//using namespace atcoder;

#define REP(i, n) for (int i=0; i<(n); ++i)
#define RREP(i, n) for (int i=(int)(n)-1; i>=0; --i)
#define FOR(i, a, n) for (int i=(a); i<(n); ++i)
#define RFOR(i, a, n) for (int i=(int)(n)-1; i>=(a); --i)

#define SZ(x) ((int)(x).size())
#define ALL(x) (x).begin(),(x).end()

#define DUMP(x) cerr<<#x<<" = "<<(x)<<endl
#define DEBUG(x) cerr<<#x<<" = "<<(x)<<" (L"<<__LINE__<<")"<<endl;

template<class T>
ostream &operator<<(ostream &os, const vector<T> &v) {
    os << "[";
    REP(i, SZ(v)) {
        if (i) os << ", ";
        os << v[i];
    }
    return os << "]";
}

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

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

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

using ll = long long;
using ull = unsigned long long;
using ld = long double;
using P = pair<int, int>;
using vi = vector<int>;
using vll = vector<ll>;
using vvi = vector<vi>;
using vvll = vector<vll>;

const ll MOD = 1e9 + 7;
const int INF = INT_MAX / 2;
const ll LINF = LLONG_MAX / 2;
const ld eps = 1e-9;

// edit

template<int m>
struct mint {
    int x;

    mint(ll x = 0) : x(((x % m) + m) % m) {}

    mint operator-() const { return x ? m - x : 0; }

    mint &operator+=(mint r) {
        if ((x += r.x) >= m) x -= m;
        return *this;
    }

    mint &operator-=(mint r) {
        if ((x -= r.x) < 0) x += m;
        return *this;
    }

    mint &operator*=(mint r) {
        x = ((ll) x * r.x) % m;
        return *this;
    }

    mint inv() const { return pow(m - 2); }

    mint &operator/=(mint r) { return *this *= r.inv(); }

    friend mint operator+(mint l, mint r) { return l += r; }

    friend mint operator-(mint l, mint r) { return l -= r; }

    friend mint operator*(mint l, mint r) { return l *= r; }

    friend mint operator/(mint l, mint r) { return l /= r; }

    mint pow(ll n) const {
        mint ret = 1, tmp = *this;
        while (n) {
            if (n & 1) ret *= tmp;
            tmp *= tmp, n >>= 1;
        }
        return ret;
    }

    friend bool operator==(mint l, mint r) { return l.x == r.x; }

    friend bool operator!=(mint l, mint r) { return l.x != r.x; }

    friend ostream &operator<<(ostream &os, mint a) {
        return os << a.x;
    }

    friend istream &operator>>(istream &is, mint &a) {
        ll x;
        is >> x;
        a = x;
        return is;
    }
};

using Mint = mint<998244353>;

void solve() {
    ll A, B, C;
    cin >> A >> B >> C;

    Mint a = Mint(A);
    Mint b = Mint(B);
    Mint c = Mint(C);

    Mint ans = 0;
    ans += a * (a + 1) * b * (b + 1) * c * (c + 1) / 8;
    cout << ans << endl;

}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
//    std::ifstream in("input.txt");
//    std::cin.rdbuf(in.rdbuf());

    solve();

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long int lld;
typedef pair<int,int> pi;
typedef pair<lld,lld> pl;
typedef pair<int,lld> pil;
typedef pair<lld,int> pli;
typedef vector<int> vit;
typedef vector<vit> vitt;
typedef vector<lld> vlt;
typedef vector<vlt> vltt;
typedef vector<pi> vpit;
typedef vector<vpit> vpitt;
typedef long double ld;
#define x first
#define y second
#define pb push_back
#define all(v) v.begin(), v.end()
#define sz(x) (int)x.size()
#define mk(a,b) make_pair(a,b)
bool isrange(int y,int x,int n,int m){
	 if(0<=y&&y<n&&0<=x&&x<m) return true;
	 return false;
}
int dy[4] = {1,0,-1,0},dx[4]={0,1,0,-1},ddy[8] = {1,0,-1,0,1,1,-1,-1},ddx[8] = {0,1,0,-1,1,-1,1,-1};

const int MAX = 555;
int arr[MAX];
vector<int> v;
void f(int x){
	v.push_back(x);
	swap(arr[x],arr[x+1]);
}
void solve(int tc){
	v.clear();
	int n;
	cin >> n;
	for(int e=1;e<=n;e++) cin >> arr[e];
	int cnt = 1,flag = 0;
	for(int e=1;e<=n;e++){
		while(arr[e]!=e){
			int pos = -1;
			for(int p=e+1;p<=n;p++) if(arr[p]==e) pos = p;
			if((pos-1)%2==(cnt%2)){
				f(pos-1);
				cnt++;
			}else{
				if(pos-2<e){
					f(pos-2);
					f(pos-1);
					f(pos-2);
					f(pos-1);
					f(pos-2);
					cnt += 5;
				}else{
					f(pos-2);
					f(pos-1);
					cnt += 2;
				}
			}
		}
	}
	cout << sz(v) << "\n";
	for(int e=0;e<sz(v);e++) cout << v[e] << " ";
	cout << "\n";
}

int main(void){

	ios_base :: sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);

	int tc = 1;

		cin >> tc;

	for(int test_number=1;test_number<=tc;test_number++){
		solve(test_number);
	}
	return 0;
}

#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL_
void debug_out() {cerr << endl;}
template<typename Head,typename... Tail> void debug_out(Head H,Tail... T){cerr << ' ' << H; debug_out(T...);}
#define debug(...) cerr << 'L' << __LINE__ << " [" << #__VA_ARGS__ << "]:",debug_out(__VA_ARGS__)
#define dump(x) cerr << 'L' << __LINE__ << " " << #x << " = " << (x) << endl;
#else
#define debug(...) (void(0))
#define dump(x) (void(0))
#endif
#define rep(i,n) for (int i = 0; i < (int)(n); i ++)
#define irep(i,n) for (int i = (int)(n) - 1;i >= 0;--i)
using ll = long long;
using PL = pair<ll,ll>;
using P = pair<int,int>;
constexpr int INF = 1000000000;
constexpr long long HINF = 1000000000000000;
constexpr long long MOD = 1000000007;// = 998244353;
constexpr double EPS = 1e-4;
constexpr double PI = 3.14159265358979;

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

    int T; cin >> T;
    string atcoder = "atcoder";
    rep(i,T) {
        string s; cin >> s;
        if (s > atcoder) {
            cout << 0 << '\n';
            continue;
        }
        int ans = -1;
        rep(i,s.size()) {
            if (s[i] != 'a') {
                if (s[i] > 't') ans = i - 1;
                else ans = i;
                break;
            }
        }
        cout << ans << '\n';
    }
    return 0;
}


#include <iostream>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <tuple>
#include <cmath>
#include <numeric>
#include <functional>
#include <cassert>

#define debug_value(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << #x << "=" << x << endl;
#define debug(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << x << endl;

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

using namespace std;
typedef long long ll;
using P = pair<int, string>;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << setprecision(10) << fixed;
    int n; cin >> n;
    vector<P> v;
    for(int i = 0; i < n; i++){
        string s; int t; cin >> s >> t;
        v.push_back(P(t, s));
    }
    sort(v.begin(), v.end(), greater<P>());
    cout << v[1].second << endl;
}

#include<iostream>
using namespace std;
using ll = long long;

int main() {
  int T,i;
  cin>>T;
  for (i=0;i<T;i++) {
    ll L,R,ans = 0;
    cin>>L>>R;
    if (L*2<=R) {
      ans = (R-L*2+2)*(R-L*2+1)/2;
    }
    cout<<ans<<endl;
  }
  return 0;
}


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

#define ll long long
#define mp make_pair
#define pb push_back
#define pii pair <int, int>
#define vi vector<int>

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

#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define sz size

const int MOD = 1000000007;
long double PI = 4*atan(1);
/*std::cout << std::fixed;
std::cout << std::setprecision(2);*/

int n,s,t,w,p;
ll dp[200005];

int main()
{
    ios::sync_with_stdio(0), cin.tie(0);
    cin >> n >> w;
    F0R(i,n) {
    	cin >> s >> t >> p;
    	dp[s] += p;
    	dp[t] -= p;
    }
    F0R(i,200005) {
    	dp[i] += dp[i-1];
    	if (dp[i] > w) {
    		cout << "No";
    		return 0;
    	}
    }
    cout << "Yes\n";
    return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(), A.end()
#define RALL(A) A.rbegin(), A.rend()
typedef long long ll;
typedef pair<ll, ll> P;
const ll mod = 1000000007;
const ll LINF = 1LL << 60;
const int INF = 1 << 30;

bool solve(ll x, set<ll> &s)
{
    // cout << 'x' << x << endl;
    ll ans = 0;
    for (auto e : s)
    {
        for (auto e2 : s)
        {
            for (auto e3 : s)
            {
                // cout << e << e2 << e3 << endl;
                ans = (e | e2 | e3);
                // cout << "ans: " << ans << endl;
                if (ans == ((1LL << 5) - 1LL))
                {
                    return true;
                }
            }
        }
    }
    return false;
}

int main()
{
    int n;
    cin >> n;
    vector<vector<ll>> A(n, vector<ll>(5));
    for (int i = 0; i < n; i++)
    {
        for (int j = 0; j < 5; j++)
        {
            cin >> A[i][j];
        }
    }

    ll ok = 0;
    ll ng = 1001001001;

    while (abs(ok - ng) > 1)
    {
        ll mid = (ok + ng) / 2LL;
        set<ll> s;
        for (ll i = 0; i < n; i++)
        {
            ll bit = 0;
            for (ll j = 0; j < 5; j++)
            {
                if (A[i][j] >= mid)
                {
                    bit |= (1LL << j);
                }
            }
            s.insert(bit);
        }

        if (solve(mid, s))
        {
            ok = mid;
        }
        else
        {
            ng = mid;
        }
    }
    cout << ok << endl;

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
// --------------------------------------------------------
template<class T> bool chmax(T& a, const T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> bool chmin(T& a, const T b) { if (b < a) { a = b; return 1; } return 0; }
#define FOR(i,l,r) for (ll i = (l); i < (r); ++i)
#define RFOR(i,l,r) for (ll i = (r)-1; (l) <= i; --i)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(c) (c).begin(), (c).end()
#define RALL(c) (c).rbegin(), (c).rend()
#define SORT(c) sort(ALL(c))
#define RSORT(c) sort(RALL(c))
#define MIN(c) *min_element(ALL(c))
#define MAX(c) *max_element(ALL(c))
#define SUMLL(c) accumulate(ALL(c), 0LL)
#define COUNT(c,v) count(ALL(c),(v))
#define SZ(c) ((ll)(c).size())
#define BIT(b,i) (((b)>>(i)) & 1)
#define PCNT(b) __builtin_popcountll(b)
#define CIN(c) cin >> (c)
#define COUT(c) cout << (c) << '\n'
#define debug(x) cerr << "l." << __LINE__ << " : " << #x << " = " << (x) << '\n'
ll llceil(ll a, ll b) { return (a + b - 1) / b; }
ll bitlen(ll b) { if (b <= 0) { return 0; } return (64LL - __builtin_clzll(b)); }
string toupper(const string& S) { string T(S); REP(i,SZ(T)) T[i] = toupper(T[i]); return T; }
string tolower(const string& S) { string T(S); REP(i,SZ(T)) T[i] = tolower(T[i]); return T; }
using P = pair<ll,ll>;
using VP = vector<P>;
using VVP = vector<VP>;
using VS = vector<string>;
using VVS = vector<VS>;
using VLL = vector<ll>;
using VVLL = vector<VLL>;
using VVVLL = vector<VVLL>;
using VB = vector<bool>;
using VVB = vector<VB>;
using VVVB = vector<VVB>;
using VD = vector<double>;
using VVD = vector<VD>;
using VVVD = vector<VVD>;
using VLD = vector<ld>;
using VVLD = vector<VLD>;
using VVVLD = vector<VVLD>;
static const double EPS = 1e-10;
static const double PI  = acos(-1.0);
static const ll MOD = 1000000007;
// static const ll MOD = 998244353;
static const ll INF = (1LL << 62) - 1;  // 4611686018427387904 - 1
// --------------------------------------------------------
// #include <atcoder/all>
// using namespace atcoder;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(15);

    ll N; cin >> N;
    VVLL A(N,VLL(5)); REP(i,N) REP(j,5) cin >> A[i][j];

    auto is_ok = [&](ll X) -> bool {
        ll res = false;
        VLL C(5);
        auto rec = [&](auto self, ll n) -> void {
            if (n == 5) {
                bool ok1 = false;
                bool ok2 = false;
                bool ok3 = false;
                REP(i,N) {
                    bool b1 = true;
                    bool b2 = true;
                    bool b3 = true;
                    REP(j,5) {
                        if (C[j] == 0) { if (A[i][j] < X) b1 = false; }
                        if (C[j] == 1) { if (A[i][j] < X) b2 = false; }
                        if (C[j] == 2) { if (A[i][j] < X) b3 = false; }
                    }
                    if (b1) ok1 = true;
                    if (b2) ok2 = true;
                    if (b3) ok3 = true;
                }
                if (ok1 && ok2 && ok3) res = true;
                return;
            }
            REP(i,3) {
                C[n] = i;
                self(self, n+1);
            }
            return;
        };
        rec(rec, 0);
        return res;
    };

    ll ok = 0;
    ll ng = 1e10;
    while (ng - ok > 1) {
        ll m = (ok + ng) / 2;
        (is_ok(m) ? ok : ng) = m;
    }
    ll ans = ok;
    COUT(ans);

    return 0;
}

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;

int a[3005][5];

int n;

string tostr(int x){
    string str = "";
    while(x){
        str += x%3 + '0';
        x /= 3;
    }
    while(str.size() <= 5) str += '0';
    return str;
}

bool check(int k){
    for(int j=0; j<3*3*3*3*3; j++){
        int x = j;
        string s = tostr(j);
        vector <int> prvi;
        vector <int> drugi;
        vector <int> treci;
        for(int i=0; i<5; i++){
            if(s[i] == '0') prvi.push_back(i);
            else if(s[i] == '1') drugi.push_back(i);
            else treci.push_back(i);
        }
        int ch = 0;
        for(int r=1; r<=n; r++){
            bool ovaj = 1;
            for(auto c : prvi){
                if(a[r][c] < k) ovaj = 0;
            }
            if(ovaj){
                ch++;
                break;
            }
        }
        for(int r=1; r<=n; r++){
            bool ovaj = 1;
            for(auto c : drugi){
                if(a[r][c] < k) ovaj = 0;
            }
            if(ovaj){
                ch++;
                break;
            }
        }
        for(int r=1; r<=n; r++){
            bool ovaj = 1;
            for(auto c : treci){
                if(a[r][c] < k) ovaj = 0;
            }
            if(ovaj){
                ch++;
                break;
            }
        }
        if(ch == 3) return 1;
    }
    return 0;
}

int main(){
    ios_base::sync_with_stdio(false);
	cout.precision(10);
	cout << fixed;

    cin >> n;
    for(int i=1; i<=n; i++){
        cin >> a[i][0] >> a[i][1] >> a[i][2] >> a[i][3] >> a[i][4];
    }
    int l=1, r=1000000000, res = 1;
    while(l <= r){
        int mid = (l+r)/2;
        if(check(mid)){
            res = mid;
            l = mid+1;
        }
        else r = mid-1;
    }
    cout << res;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
// #include <atcoder/all>
// using namespace atcoder;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define drep(i,n) for(int i = (n-1); i >= 0; i--)
#define all(v) (v).begin(),(v).end()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
template <class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template <class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; }
template <class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
template <class T> T lcm(T a, T b) { return a/gcd(a,b)*b; }
typedef pair<int, int> P;
typedef long long ll;
const int INF = 1001001001;
const ll LINF = 1001002003004005006ll;
const ll MOD = 1e9+7;

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
	int x;
	cin >> x;
    int ans = 100 - x%100;
    cout << ans << "\n";
	return 0;
}

/*
 *
 *
 * Copyright 2020 Tanishk <tanishktonk>
 * ........ ;)
 *
 *
 */

#include <bits/stdc++.h>
#define ll long long int
#define fr(i,n) for(i=0;i<n;i++)
#define rng(i,a,b) for(i=a;i<b;i++)
#define T long long int T;cin>>T;while(T--)
#define ain(a,n) for(int zzz=0;zzz<n;zzz++){cin>>a[zzz];}
#define aout(a,n) for(int zzz=0;zzz<n;zzz++){cout<<a[zzz]<<' ';}cout<<"\n";
#define All(v) v.begin(),v.end()
#define dbg(v) cerr<<">-- "<<#v<<" = "<<v<<"\n";
#define PB push_back
#define MP make_pair
#define N "\n"
const int inf = ((int)1e9+3);
const int M97 = ((int)1e9+7);
using namespace std;

typedef vector<int> Vi;
typedef pair<int,int> Pii;
typedef pair<int,Pii> Piii;

ll i,j,k;

void solve()
{
	int n;
	cin >> n;
	cout << 100-n%100 << N;
}

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

	solve();

    return 0;
}


#include <iostream>
#include <unordered_set>
using namespace std;
using ll = int64_t;

int main(){
    ll N;
    cin >> N;
    unordered_set<ll> s;
    for(ll a = 2; a * a <= N; a++){
        ll x = a * a;
        while(x <= N){
            s.insert(x);
            x *= a;
        }
    }
    cout << N - s.size() << endl;
}

#include <iostream>
#include <iomanip>
#include <sstream>
#include <vector>
#include <string>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include <functional>
#include <iterator>
#include <limits>
#include <numeric>
#include <utility>
#include <type_traits>
#include <cmath>
#include <cassert>
#include <cstdio>

using namespace std;
using namespace placeholders;

using LL = long long;
using ULL = unsigned long long;
using VI = vector< int >;
using VVI = vector< vector< int > >;
using VS = vector< string >;
using ISS = istringstream;
using OSS = ostringstream;
using PII = pair< int, int >;
using VPII = vector< pair< int, int > >;
template < typename T = int > using VT = vector< T >;
template < typename T = int > using VVT = vector< vector< T > >;
template < typename T = int > using LIM = numeric_limits< T >;
template < typename T = int > using OSI = ostream_iterator< T >;

template < typename T > inline istream& operator>>( istream &s, vector< T > &v ){ for ( T &t : v ) { s >> t; } return s; }
template < typename T > inline ostream& operator<<( ostream &s, const vector< T > &v ){ for ( int i = 0; i < int( v.size() ); ++i ){ s << ( " " + !i ) << v[i]; } return s; }

void in_impl(){};
template < typename T, typename... TS > void in_impl( T &head, TS &... tail ){ cin >> head; in_impl( tail ... ); }
#define IN( T, ... ) T __VA_ARGS__; in_impl( __VA_ARGS__ );

template < typename T > inline T fromString( const string &s ) { T res; istringstream iss( s ); iss >> res; return res; }
template < typename T > inline string toString( const T &a ) { ostringstream oss; oss << a; return oss.str(); }

#define NUMBERED( name, number ) NUMBERED2( name, number )
#define NUMBERED2( name, number ) name ## _ ## number
#define REP1( n ) REP2( NUMBERED( REP_COUNTER, __LINE__ ), n )
#define REP2( i, n ) REP3( i, 0, n )
#define REP3( i, m, n ) for ( int i = ( int )( m ); i < ( int )( n ); ++i )
#define GET_REP( a, b, c, F, ... ) F
#define REP( ... ) GET_REP( __VA_ARGS__, REP3, REP2, REP1 )( __VA_ARGS__ )
#define FOR( e, c ) for ( auto &&e : c )
#define ALL( c ) begin( c ), end( c )
#define AALL( a ) ( remove_all_extents< decltype( a ) >::type * )a, ( remove_all_extents< decltype( a ) >::type * )a + sizeof( a ) / sizeof( remove_all_extents< decltype( a ) >::type )

#define SZ( v ) ( (int)( v ).size() )
#define EXISTS( c, e ) ( ( c ).find( e ) != ( c ).end() )

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

#define PB push_back
#define EM emplace
#define EB emplace_back
#define BI back_inserter

#define MP make_pair
#define fst first
#define snd second

#define DUMP( x ) cerr << #x << " = " << ( x ) << endl

//     Λ   Λ＿_
//  ／(*ﾟーﾟ)／＼
// ／| ￣U U￣|＼／
//   |      |／

int main()
{
	cin.tie( nullptr );
	ios::sync_with_stdio( false );
	cout << setprecision( 12 ) << fixed;

	IN( int, N );
	VT< LL > A( N );
	cin >> A;

	sort( ALL( A ) );

	VT< LL > psum( 1 );
	partial_sum( ALL( A ), BI( psum ) );

	LL res = 0;
	REP( j, N )
	{
		res += j * A[j];
	}
	res -= accumulate( begin( psum ), end( psum ) - 1, 0LL );
	cout << res << endl;

	return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef double db;
typedef long long LL;
#define fi first
#define se second
#define pb push_back
#define mkp make_pair
#define sz(v) (int)(v).size()
#define rep(i, x, y) for(int i = x, i##end = y; i <= i##end; ++i)
#define per(i, x, y) for(int i = x, i##end = y; i >= i##end; --i)
template<class T> inline bool ckmax(T &x, T y) { return x < y ? x = y, 1 : 0; }
template<class T> inline bool ckmin(T &x, T y) { return x > y ? x = y, 1 : 0; }
inline int read() {
    int x = 0, f = 1; char ch = getchar();
    while(!isdigit(ch)) { if(ch == '-') f = 0; ch = getchar(); }
    while(isdigit(ch)) x = x * 10 + ch - '0', ch = getchar();
    return f ? x : -x;
}

const int N = 200005;
LL ans;
int n, a[N], b[N], lsh[N], rag, it[N], tr[N];
vector<int> va[N], vb[N];
inline void add(int x, int d) {
	for(int i = x; i <= n; i += i & -i) tr[i] += d;
}
inline int ask(int x) {
	int res = 0;
	for(int i = x; i > 0; i -= i & -i) res += tr[i];
	return res;
}
signed main() {
	n = read();
	rep(i, 1, n) a[i] = read() + i, lsh[++rag] = a[i];
	rep(i, 1, n) b[i] = read() + i;
	sort(lsh + 1, lsh + rag + 1), rag = unique(lsh + 1, lsh + rag + 1) - lsh - 1;
	rep(i, 1, n) a[i] = lower_bound(lsh + 1, lsh + rag + 1, a[i]) - lsh, va[a[i]].pb(i);
	rep(i, 1, n) {
		int tmp = b[i];
		b[i] = lower_bound(lsh + 1, lsh + rag + 1, b[i]) - lsh;
		if(lsh[b[i]] != tmp) return puts("-1"), 0;
		vb[b[i]].pb(i);
	}
	rep(i, 1, rag) if(sz(va[i]) != sz(vb[i])) return puts("-1"), 0;
	rep(i, 1, n) {
		int tmp = va[b[i]][it[b[i]]++];
		add(tmp, 1);
		tmp += i - ask(tmp);
		ans += tmp - i;
	}
	cout << ans << '\n';
}

#include<iostream>
#include<list>
#include<map>
#include<vector>
using namespace std;
typedef long long li;
#define rep(i,n) for(int i=0;i<(n);i++)
#define df 0
template<class T> void print(const T& t){ cout << t << "\n"; }
template<class T, class... Ts> void print(const T& t, const Ts&... ts) { cout << t; if (sizeof...(ts)) cout << " "; print(ts...); }
// Container コンテナ型, map以外
template< template<class ...> class Ctn,class T>
std::ostream& operator<<(std::ostream& os,const Ctn<T>& v){
  auto itr=v.begin();
  while(itr!=v.end()){
    if(itr!=v.begin())cout << " ";
    cout << *(itr++);
  }
  return os;
};

// pair 型
template<class S,class T>
std::ostream& operator<<(std::ostream& os, const pair<T,S>& p){
  cout << "(" << p.first << "," << p.second << ")";
  return os;
}

// map 型
template<class S,class T>
std::ostream& operator<<(std::ostream& os, const map<S,T>& mp){
  for(const pair<S,T>& x: mp){
    cout << "[" << x.first << "]=" << x.second << " ";
  }
  return os;
}

struct segtree{
  int n;
  vector<int> vec;

  segtree(int nn){
    n=nn;
    vec.resize(2*n,0);
  }

  int get(int i){ return vec[i+n]; };
  void set(li a,int i){
    i+=n;
    vec[i]=a;
    while(i>1){
      i/=2;
      vec[i]=vec[i*2]+vec[i*2+1];
    }

  };
  int sum(int i,int j){
    // [i,j)
    if(df)print(i,j);
    int s=0;
    i=i+n; j=j+n;

    while(i<j){
      if(i%2){ if(df) print(i); s+=vec[i]; i++; }
      if(j%2){ j--; s+=vec[j]; if(df) print(j); }
      i/=2; j/=2;
    }
    return s;
  }

};

std::ostream& operator<<(std::ostream& os, const segtree& s){
  rep(i,2*s.n) printf("%ld ",s.vec[i]);
  return os;
}

int judge(map<li,int>& mpa,map<li,int>& mpb){
  int f=1;
  int t=0;
  for(auto& x:mpa){
    if(mpb[x.first]!=x.second) f=0;
    if(df)print(x,mpb[x.first],"->",f);
  }
  return f;
}

int main(){
  int n; cin >>n;
  vector<li> a(n);
  map<li,int> mpa;
  rep(i,n){
    li c; cin >>c;
    a[i]=c+i;
    mpa[a[i]]++;
  }
  if(df)print(mpa);
  vector<li> b(n);
  map<li,int> mpb;
  rep(i,n){
    li c; cin >>c;
    b[i]=c+i;
    mpb[b[i]]++;
  }
  if(df)print(mpb);

  if(!judge(mpa,mpb)){
    print(-1);
    return 0;
  }
  map<li,list<int>> mp;
  rep(i,n){
    mp[b[i]].push_back(i);
  }
  if(df)print(mp);
  rep(i,n){
    int t=mp[a[i]].front();
    mp[a[i]].pop_front();
    a[i]=t;
  }
  if(df)print(a);

  segtree sgt(n);
  li ans=0;
  rep(i,n){
    ans+=sgt.sum(a[i],n);
    sgt.set(1,a[i]);
    if(df)print(sgt, sgt.sum(a[i],n));
  }
  print(ans);

}


#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define mp make_pair
#define all(a) a.begin(),a.end()
#define sz(a) (int)(a.size())
#define lb lower_bound
#define ub upper_bound
#define owo ios_base::sync_with_stdio(0);cin.tie(0);
#define MOD (ll)(1e9+7)
#define INF (ll)(1e18)
#define debug(...) fprintf(stderr, __VA_ARGS__),fflush(stderr)
#define time__(d) for(long blockTime = 0; (blockTime == 0 ? (blockTime=clock()) != 0 : false);\
debug("%s time : %.4fs\n", d, (double)(clock() - blockTime) / CLOCKS_PER_SEC))
typedef long long int ll;
typedef long double ld;
typedef pair<ll,ll> PII;
typedef pair<int,int> pii;
typedef vector<vector<int>> vii;
typedef vector<vector<ll>> VII;
ll gcd(ll A,ll B) {if(!B)return A;return gcd(B,A%B);}
int main()
{
   ll a[5];
  bool ok = 0;
  cin>>a[0]>>a[1]>>a[2]>>a[3];
  a[4] = 0;
  ll sum = a[0]+a[1]+a[2]+a[3];
  for(int i=0;i<5;i++){
	  for(int j=0;j<5;j++){
		  if(i == j)continue;
		  for(int k=0;k<5;k++){
			  if(j == k || i == k)continue;
			  if(sum-a[i]-a[j]-a[k] == a[i]+a[j]+a[k])ok = 1;

		  }
	  }
	  }
	  if(ok)cout<<"Yes";
	  else cout<<"No";
}

#include <bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define ll long long
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;

// #define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update>

int32_t main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll t = 1;
    // cin >> t;
    while(t--)
    {
        ll a, b, c, d;
        cin >> a >> b >> c >> d;
        cout << b-c;
    }
    return 0;
}


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

#define pb push_back
#define mp make_pair
#define f1 first
#define s2 second

#define fastio ios :: sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define debug(x) cerr << "[" << #x << "]: " << x << "\n";

using ll = long long;
using ld = long double;
using ii = pair<int, int>;
using pl = pair<ll, ll>;

ld const PI = 4*atan((ld)1);

template<int MOD = 1'000'000'007>
struct Mint
{
	int val;

	Mint() : val(0) {}
	Mint(ll _val) : val((int)(_val % MOD)) { if (val < 0) val += MOD; }

	Mint& operator+= (const Mint &rhs) { val += rhs.val; if (val >= MOD) val -= MOD; return *this; }
	Mint& operator-= (const Mint &rhs) { val -= rhs.val; if (val < 0) val += MOD; return *this; }
	Mint& operator*= (const Mint &rhs) { val = (int)((ll) val * rhs.val % MOD); return *this; }

	friend Mint fpow(Mint x, ll y)
	{
		Mint res = 1;
		for (; y > 0; y >>= 1, x *= x)
		{
			if (y & 1)
				res *= x;
		}
		return res;
	}
	friend Mint inverse(Mint x) { return fpow(x, MOD-2); }
	Mint& operator/= (const Mint &rhs) { return *this *= inverse(rhs); }

	friend Mint operator+ (Mint a, const Mint &b) { return a += b; }
	friend Mint operator- (Mint a, const Mint &b) { return a -= b; }
	friend Mint operator- (Mint a) { return 0 - a; }
	friend Mint operator* (Mint a, const Mint &b) { return a *= b; }
	friend Mint operator/ (Mint a, const Mint &b) { return a /= b; }
	friend ostream& operator<< (ostream &os, const Mint &a) { return os << a.val; }
	friend bool operator== (const Mint &a, const Mint &b) { return a.val == b.val; }
	friend bool operator!= (const Mint &a, const Mint &b) { return a.val != b.val; }
};

const int MAX = 3069;

int n;
ll ar[MAX], pfx[MAX];
Mint<> dp[MAX][MAX] = {};
Mint<> sum[MAX][MAX] = {};

int main()
{
	fastio;

	cin >> n;
	for (int i = 1; i <= n; ++i)
		cin >> ar[i], pfx[i] = pfx[i-1] + ar[i];

	dp[0][0] = 1;
	sum[1][0] = 1;
	for (int i = 1; i <= n; ++i)
	{
		for (int j = i; j >= 1; --j)
		{
			dp[i][j] = sum[j][pfx[i] % j];
			sum[j+1][pfx[i] % (j+1)] += dp[i][j];
			// for (int x : v[j][pfx[i] % j])
			// {
			// 	if (x == i)
			// 		break;
			// 	dp[i][j] += dp[x][j-1];
			// }

			// for (int k = 0; k < i; ++k)
			// {
			// 	if (pfx[i] % j == pfx[k] % j)
			// 		dp[i][j] += dp[k][j-1];
			// }
		}
	}

	// for (int i = 1; i <= n; ++i)
	// {
	// 	for (int j = 1; j <= i; ++j)
	// 		cerr << dp[i][j] << ", ";
	// 	cerr << '\n';
	// }

	Mint<> res = 0;
	for (int i = 1; i <= n; ++i)
		res += dp[n][i];
	cout << res << '\n';

	return 0;
}

#include <iostream>
#include <cstring>
#include <cstdio>
#define N 3005
#define ll long long
#define mod 1000000007
using namespace std;
ll a[N],sum[N];
int f[N],f2[N],g[N];
int main()
{
	int i,k,n,ans=0;
	scanf("%d",&n);
	for(i=1;i<=n;++i)
		scanf("%lld",&a[i]);
	f[0]=1;
	for(k=1;k<=n;++k)
	{
		memcpy(f2,f,sizeof(f2));
		memset(f,0,sizeof(f));
		memset(g,0,sizeof(g));
		for(i=1;i<=n;++i)sum[i]=(sum[i-1]+a[i])%k;
		g[0]=f2[0];
		for(i=1;i<=n;++i)
		{
			f[i]=g[sum[i]];
			(g[sum[i]]+=f2[i])%=mod;
		}
		(ans+=f[n])%=mod;
	}
	printf("%d\n",ans);
	return 0;
}


#include<iostream>
#include<string>
#include<cmath>
#include<algorithm> //max,min
#include<iomanip> //setprecision,tuple
#include<vector>  //vector
#include<numeric> //iota
#include<map> //map
#include<set> //set
#include<sstream> //stringstream(hex 16,dec 10,oct 8,bilset 2)
#include<list> //list
using namespace std;
using lint = long long;
#define INF 2147483647
#define PI acos(-1)
#define rep(i, n) for(int i = 0; i < (int)(n); i++)

int main(){
    int a,b,c;cin>>a>>b>>c;
    int ans=21-(a+b+c);
    cout<<ans<<endl;
    return 0;
}

#include <bits/stdc++.h>
#define all(V) V.begin(),V.end()
#define pi 3.1415926535897932384626
#define fi fixed<<setprecision(13)
#define ll long long
#define rep(i, n) for (int i = 0; i < (ll)(n); i++)
#define Rep(i, n) for (ll i = 1; i <=(ll)(n); i++)
#define reps(i,k,n) for (ll i = (ll)k; i < (ll)(n); i++)
using namespace std;
using V = vector<vector<int>>;
using Vc = vector<vector<char>>;
using Vb = vector<vector<bool>>;
using P = pair<int,int>;
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
template<class T> void chmin(T& a,T b){ if(a > b) a=b; }
template<class T> void chmax(T& a,T b){ if(a < b) a=b; }
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){ fill( (T*)array, (T*)(array+N), val );}
const ll infll=1LL<<62;
const ll inf=1<<30;
const int dx[4] = {0, 0, -1, 1};
const int dy[4] = {1, -1, 0, 0};
struct Edge{
  int to;
  ll w;
  Edge(int to,ll w) : to(to),w(w){}
};
using Graph = vector<vector<Edge>>;
int main(){
  ios::sync_with_stdio(false);
  std::cin.tie(nullptr);
  /*----------------------------------------------------*/
  int a,b,c;
  cin >> a >> b >> c;
  cout << 21 - a - b - c <<"\n";
}
/*制約を確認しろllじゃなくて大丈夫か？*/
/* sample 保存

*/


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

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

const int CM = 1 << 17, CL = 12;
char cn[CM + CL], * ci = cn + CM + CL, * owa = cn + CM, ct;
const ll ma0 = 1157442765409226768;
const ll ma1 = 1085102592571150095;
const ll ma2 = 71777214294589695;
const ll ma3 = 281470681808895;
const ll ma4 = 4294967295;
inline int getint() {
	if (ci - owa > 0) {
		memcpy(cn, owa, CL);
		ci -= CM;
		fread(cn + CL, 1, CM, stdin);
	}
	ll tmp = *(ll*)ci;
	int dig = 68 - __builtin_ctzll((tmp & ma0) ^ ma0);
	tmp = tmp << dig & ma1;
	tmp = tmp * 10 + (tmp >> 8) & ma2;
	tmp = tmp * 100 + (tmp >> 16) & ma3;
	tmp = tmp * 10000 + (tmp >> 32) & ma4;
	ci += 72 - dig >> 3;
	return tmp;
}
const int MAX = 1000;
class shuturyoku_unko {
public:
	char C[MAX * 4];
	constexpr shuturyoku_unko() : C() {
		rep(i, MAX) {
			int X = i;
			rep(j, 3) {
				C[i * 4 + 2 - j] = '0' + X % 10;
				X /= 10;
			}
			C[i * 4 + 3] = ' ';
		}
	}
};
constexpr shuturyoku_unko f;
const int dm = 1 << 17;
char* dn = cn, * di = dn, * owad = dn + dm - 20;
void putint(int A) {
	if (owad < di) {
		fwrite(dn, 1, di - dn, stdout);
		di = dn;
	}
	if (A >= 1000) {
		int dig = 1;
		if (A >= 100000) dig = 3;
		else if (A >= 10000) dig = 2;
		memcpy(di, f.C + A / 1000 * 4 + 3 - dig, dig);
		memcpy(di + dig, f.C + A % 1000 * 4, 4);
		di += dig + 4;
	}
	else {
		int dig = 1;
		if (A >= 100) dig = 3;
		else if (A >= 10) dig = 2;
		memcpy(di, f.C + A * 4 + 3 - dig, dig + 1);
		di += dig + 1;
	}
}

int N;
int to[400001], ne[400001], he[200001];
int Q[200001], vis[200001], p, q;
ll are[200001];

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

	N = getint();
	rep1(i, N * 2 - 2) {
		int a = getint(), b = getint();
		to[i] = b;
		ne[i] = he[a];
		he[a] = i++;
		to[i] = a;
		ne[i] = he[b];
		he[b] = i;
	}

	Q[q++] = 1;
	while (p < q) {
		int u = Q[p++];
		vis[u] = -1;
		for (int i = he[u]; i; i = ne[i]) {
			if (vis[to[i]] == 0) {
				Q[q++] = to[i];
			}
		}
	}
	int tmp = Q[N - 1];
	p = 0;
	q = 0;
	Q[q++] = tmp;
	vis[tmp] = 0;
	while (p < q) {
		int u = Q[p++];
		int mae = 0;
		for (int i = he[u]; i; i = ne[i]) {
			if (vis[to[i]] < 0) {
				vis[to[i]] = u;
				Q[q++] = to[i];
				mae = i;
			}
			else {
				if (mae) ne[mae] = ne[i];
				else he[u] = ne[i];
			}
		}
	}
	ll m = (1ll << 20) - 1, m0 = ~m, m1 = 1ll << 20;
	for (int i = N - 1; i >= 0; i--) {
		int u = Q[i];
		ll kari = (are[u] & m0) + m1 + u;
		if (are[vis[u]] < kari) are[vis[u]] = kari;
	}

	int k = 0;
	q = 0;
	Q[q++] = tmp;
	while (q) {
		k++;
		int u = Q[q - 1];
		if (u < 0) q--;
		else {
			vis[u] = -k;
			Q[q - 1] = -u;
			int nanika = are[u] & m;
			if (nanika) Q[q++] = nanika;
			for (int i = he[u]; i; i = ne[i]) {
				int v = to[i];
				if (v != nanika) {
					Q[q++] = v;
				}
			}
		}
	}

	rep1(i, N) putint(-vis[i]);
	fwrite(dn, 1, di - dn, stdout);

	Would you please return 0;
}

#include<bits/stdc++.h>

using namespace std;

//一の位の数の2倍と十の位以上の数の差が7の倍数であれば、その数は7で割り切れる。
//ある自然数を一の位から3ケタごとに区切り、それらを交互に加算する。そして、それらの和の差が7の倍数のとき、その自然数は7の倍数である。

int main(){
    int N;
    string S,T;
    cin>>N;
    cin>>S>>T;

    vector<int> Tv;
    int ten=1;

    for(int i=S.size()-1;i>=0;i--){
        int a=(S[i]-'0')*ten%7;
        ten=ten*10%7;
        Tv.push_back(a);
    }
    reverse(Tv.begin(),Tv.end());

    for(int i=0;i<Tv.size();i++){
       // cout<<Tv[i];
    }
   // cout<<endl;

   int win[7]={0};
   win[0]=1;
   for(int i=S.size()-1;i>=0;i--){
       int nxwin[7]={0};
       if(T[i]=='T'){
           for(int j=0;j<7;j++){
                int nx1=(j+Tv[i])%7;
                while(nx1<0) nx1+=7;
                int nx2=j%7;
                while(nx2<0) nx2+=7;
                if(win[nx1]==1) nxwin[j]=1;
                if(win[nx2]==1) nxwin[j]=1;
           }
       }
       else{
           for(int j=0;j<7;j++){
                int nx1=(j+Tv[i])%7;
                while(nx1<0) nx1+=7;
                int nx2=j%7;
                while(nx2<0) nx2+=7;
                if(win[nx1]==1&&win[nx2]==1) nxwin[j]=1;
           }
       }
       for(int j=0;j<7;j++){
           //cout<<nxwin[j]<<" ";
           win[j]=nxwin[j];
       }
       //cout<<endl;
   }

   if(win[0]==1) cout<<"Takahashi"<<endl;
   else cout<<"Aoki"<<endl;
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define P pair
#define fi first
#define se second
#define rep(i,n) for(int i=0;i<n;i++)
#define all(v) v.begin(),v.end()
#define pb push_back
#define eb emplace_back
template<class T>void chmax(T &a,T b){if(a<b)a=b;}
template<class T>void chmin(T &a,T b){if(a>b)a=b;}
constexpr int INF=1000000000;
constexpr ll llINF=1000000000000000000;
constexpr int mod=1000000007;
constexpr double eps=1e-8;
const double pi=acos(-1);
int dx[]={0,1,0,-1},dy[]={1,0,-1,0};
int Random(int mi,int ma){
    random_device rnd;
    mt19937 mt(rnd());//32bit
    //[mi,ma]
    uniform_int_distribution<int>engine(mi,ma);
    return engine(mt);
}
ll gcd(ll a,ll b){
    if(b==0)return a;
    return gcd(b,a%b);
}
ll lcm(ll a,ll b){
    return a/gcd(a,b)*b;
}
bool prime(int a){
    if(a==1)return false;
    for(int i=2;i*i<=a;i++){
        if(a%i==0)return false;
    }
    return true;
}
ll modpow(ll a,ll b){
    if(b==0)return 1;
    if(b%2)return modpow(a,b-1)*a%mod;
    ll memo=modpow(a,b/2);
    return memo*memo%mod;
}
vector<ll>kaijo,invkaijo;
void init_fact(int n){
    kaijo.resize(n+1);
    invkaijo.resize(n+1);
    kaijo[0]=1;
    for(ll i=1;i<=n;i++){
        kaijo[i]=kaijo[i-1]*i;
        kaijo[i]%=mod;
    }
    rep(i,n+1)invkaijo[i]=modpow(kaijo[i],mod-2);
}
/*
vector<vector<ll>>C,sC;
void init_comb(int n,int m){
    C.resize(n+1,vector<ll>(m+1,0));
    sC.resize(n+1,vector<ll>(m+1,0));
    C[0][0]=1;
    for(int i=1;i<=n;i++){
        C[i][0]=1;
        for(int j=1;j<=m;j++){
            C[i][j]=(C[i-1][j-1]+C[i-1][j])%mod;
        }
    }
    rep(i,n+1){
        rep(j,m){
            sC[i][j+1]=(sC[i][j]+C[i][j])%mod;
        }
    }
}*/
ll comb(int a,int b){
    if(a<b)return 0;
    if(a<0)return 0;
    return kaijo[a]*invkaijo[a-b]%mod*invkaijo[b]%mod;
}
ll inv(ll x){
    x=modpow(x,mod-2);
    return x;
}
void solve(){

}
int main(){
    int n,m,t,a[1010],b[1010];
    cin>>n>>m>>t;
    int x=n;
    rep(i,m)cin>>a[i]>>b[i];
    rep(i,m){
        x-=(i==0?a[i]:a[i]-b[i-1]);
        if(x<=0){
            cout<<"No"<<endl;
            return 0;
        }
        x+=b[i]-a[i];
        chmin(x,n);
    }
    x-=(t-b[m-1]);
    if(x<=0){
        cout<<"No"<<endl;
        return 0;
    }
    cout<<"Yes"<<endl;
    return 0;
}

#include<bits/stdc++.h>
#include<string>

using namespace std;

#define ll long long int
#define ld long double
#define pb push_back
#define all(v) v.begin(),v.end()
#define sz(x) ((int)(x).size())
#define fi first
#define se second
#define deb(x) cout<< #x << '=' << x <<endl
#define MOD 1000000007

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

    ll n , m , t;
    cin>>n>>m>>t;
    ll cur = n , prev = 0;
    bool flag = 0;
    ll a[m] , b[m];
    for(int i = 0; i < m; i++){
        cin>>a[i]>>b[i];
        cur -= max(0LL , a[i] - prev);
        if(cur <= 0){
            flag = 1;
        }
        cur += b[i] - a[i];
        cur = min(n , cur);
        prev = b[i];
    }
    cur -= (t - b[m - 1]);
    if(cur <= 0){
        flag = 1;
    }
    if(flag){
        cout<<"No\n";
    }else{
        cout<<"Yes\n";
    }
    return 0;
}


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

#define rep(i,x,y) for(ll i=(x);i<(y);i++)
#define rrep(i,x,y) for(ll i=(ll)(y)-1;i>=(x);i--)
#define all(x) (x).begin(),(x).end()
#define itrout(x) for(int i=0;i<x.size();i++) {cout << x[i] << (i==x.size()-1 ? "\n" : " ");}
#ifdef LOCAL
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl
#define debugbit(x, n) cerr << #x << " = " << bitset<n>(x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl
#define itrdebug(x) cerr << #x << " "; for (auto & el : (x)) {cerr << (el) << " ";} cerr << endl
#define dassert(...) assert(__VA_ARGS__)
#else
#define debug(x)
#define debugbit(x, n)
#define itrdebug(x)
#define dassert(...)
#endif
//#define int long long
//using mint = atcoder::modint;

typedef long long ll;
const ll MOD = 1e9 + 7;
const long double EPS = 1e-8;

ll merge_cnt(vector<ll> &a) {
    int n = a.size();
    if (n <= 1) { return 0; }

    ll cnt = 0;
    vector<ll> b(a.begin(), a.begin()+n/2);
    vector<ll> c(a.begin()+n/2, a.end());

    cnt += merge_cnt(b);
    cnt += merge_cnt(c);

    int ai = 0, bi = 0, ci = 0;
    // merge の処理
    while (ai < n) {
        if ( bi < b.size() && (ci == c.size() || b[bi] <= c[ci]) ) {
            a[ai++] = b[bi++];
        } else {
            cnt += n / 2 - bi;
            a[ai++] = c[ci++];
        }
    }
    return cnt;
}

void solve(long long N, std::vector<long long> a){
    auto A = a;
    ll current = merge_cnt(A);
    rep(i,0,N) {
        cout << current << endl;
        current -= a[i];
        current += N - a[i] - 1;
    }
}

signed main(){
    // ios_base::sync_with_stdio(false);
    // cin.tie(NULL);
    long long N;
    scanf("%lld",&N);
    std::vector<long long> a(N-1-0+1);
    for(int i = 0 ; i < N-1-0+1 ; i++){
        scanf("%lld",&a[i]);
    }
    solve(N, std::move(a));
    return 0;
}

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

#define pll              pair <long long,long long>
#define pb               push_back
#define ll               long long
#define ff               first
#define ss               second
#define D(x)             cerr<<#x " = "<<(x)<<endl
#define vll              vector <ll>
#define IOS              ios_base::sync_with_stdio(0); cin.tie(NULL);
#define endl             '\n'
using namespace std;

using namespace __gnu_pbds;
typedef tree<ll,null_type,less_equal<ll>,rb_tree_tag,tree_order_statistics_node_update> ost;
ost st;

void remove(ll x)
{
	st.erase(st.lower_bound(x-1));
	return;
}

ll lt(ll x)
{
	return st.order_of_key(x);
}

ll gt(ll x)
{
	return st.size() - lt(x) - 1;
}

int main()
{
    IOS
 	// freopen("input.txt","r",stdin);
 	// freopen("output.txt","w",stdout);
 	// freopen("error.txt","w",stderr);
	ll n;
	cin>>n;
	vector<ll>a(n);
	ll total=0;
	for(ll i=0;i<n;i++)
	{
		cin>>a[i];
		st.insert(a[i]);
		total+=gt(a[i]);
	}
	cout<<total<<endl;
	for(ll i=0;i<n-1;i++)
	{
		ll ls = lt(a[i]);
		total-=ls;
		ll grt = gt(a[i]);
		total+=grt;
		cout<<total<<endl;
	}
    return 0;
}


#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define forn(i,x,n) for(int i = x;i <= n;++i)
#define Angel_Dust ios::sync_with_stdio(0);cin.tie(0)

const int N = 3e5+7;
ll sum[N],ssum[N],a[N];

int main()
{
	Angel_Dust;
	int n;cin >> n;
	forn(i,1,n)	cin >> a[i];
	forn(i,1,n)	sum[i] = sum[i - 1] + a[i],ssum[i] = ssum[i - 1] + a[i] * a[i];

	ll res = 0;
	forn(i,2,n)
	{
		res += (i - 1) * (a[i] * a[i]);
		res += ssum[i - 1];
		res -= 2 * a[i] * sum[i - 1];
	}
	printf("%lld\n",res);
	return 0;
}

#include <bits/stdc++.h>

#define fi first
#define se second
#define mp make_pair
#define lowbit(x) ((x) & -(x))

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

constexpr double eps = 1e-8;
constexpr int NINF = 0xc0c0c0c0;
constexpr int INF = 0x3f3f3f3f;
constexpr ll mod = 1e9 + 7;
constexpr ll N = 1e6 + 5;

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

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

    int H, W;
    cin >> H >> W;
    vector<string> s(H);
    for (int i = 0; i < H; i++) cin >> s[i];
    int ans = 0;
    for (int i = 0; i + 1 < H; i++) {
        for (int j = 0; j + 1 < W; j++) {
            int cnt = 0;
            for (int k = 0; k < 4; k++) {
                cnt += s[i + dx[k]][j + dy[k]] == '#';
            }
            ans += cnt & 1;
        }
    }
    cout << ans << '\n';

    return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define eb emplace_back
#define ii pair<int, int>
#define OK (cerr << "OK" << endl)
#define debug(x) cerr << #x " = " << (x) << endl
#define ff first
#define ss second
#define int long long
#define tt tuple<int, int, int>
#define all(x) x.begin(), x.end()
#define vi vector<int>
#define vii vector<pair<int, int>>
#define vvi vector<vector<int>>
#define vvii vector<vector<pair<int, int>>>
#define Mat(n, m, v) vector<vector<int>>(n, vector<int>(m, v))
#define endl '\n'

constexpr int INF = (sizeof(int) == 4 ? 1e9 : 2e18) + 1e5;
constexpr int MOD = 1e9 + 7;
constexpr int MAXN = 200 + 3;

int dp[MAXN][MAXN];

//

int n;
int f(int idx, int cut) {
  if (idx >= n)
    return (idx == n && cut == 11);

  int &ret = dp[idx][cut];
  if (~ret)
    return ret;
  ret = f(n, cut);
  for (int j = idx; j <= n; ++j) {
    ret += f(j + 1, cut + 1);
  }
  return ret;
}

// #define MULTIPLE_TEST_CASES
void solve() {
  memset(dp, -1, sizeof dp);
  cin >> n;
  --n;

  cout << f(0, 0) << endl;
}

signed main() {
  // const string FILE_NAME = "";
  // freopen((FILE_NAME + string(".in")).c_str(), "r", stdin);
  // freopen((FILE_NAME + string(".out")).c_str(), "w", stdout);
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr), cout.tie(nullptr);

  int t = 1;
#ifdef MULTIPLE_TEST_CASES
  cin >> t;
#endif
  while (t--)
    solve();
}

#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
#include<stdio.h>
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<string.h>

#ifdef LOCAL
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
#define NDEBUG
#define eprintf(...) do {} while (0)
#endif
#include<cassert>

using namespace std;

typedef long long LL;
typedef vector<int> VI;

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define EACH(i,c) for(__typeof((c).begin()) i=(c).begin(),i##_end=(c).end();i!=i##_end;++i)

template<class T> inline void amin(T &x, const T &y) { if (y<x) x=y; }
template<class T> inline void amax(T &x, const T &y) { if (x<y) x=y; }
template<class Iter> void rprintf(const char *fmt, Iter begin, Iter end) {
    for (bool sp=0; begin!=end; ++begin) { if (sp) putchar(' '); else sp = true; printf(fmt, *begin); }
    putchar('\n');
}

int N;
int A[100011];

void MAIN() {
    scanf("%d", &N);
    REP (i, N) scanf("%d", A+i);

    bool first;
    if (N % 2 == 1) {
	first = false;
    } else {
	sort(A, A+N);
	first = false;
	for (int i=0; i<N; i+=2) {
	    if (A[i] != A[i+1]) first = true;
	}
    }

    puts(first? "First": "Second");
}

int main() {
    int TC = 1;
    scanf("%d", &TC);
    REP (tc, TC) MAIN();
    return 0;
}


#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <string>
#include <sstream>
#include <cstring>
#include <cctype>
#include <cmath>
#include <vector>
#include <set>
#include <bitset>
#include <map>
#include <stack>
#include <queue>
#include <ctime>
#define _for(i,a,b) for(int i=(a);i<(b);++i)
#define _rep(i,a,b) for(int i=(a);i<=(b);++i)
#define mem(a,b) memset(a,b,sizeof(a))
using namespace std;
typedef long long LL;
inline int read_int(){
	int t=0;bool sign=false;char c=getchar();
	while(!isdigit(c)){sign|=c=='-';c=getchar();}
	while(isdigit(c)){t=(t<<1)+(t<<3)+(c&15);c=getchar();}
	return sign?-t:t;
}
inline LL read_LL(){
	LL t=0;bool sign=false;char c=getchar();
	while(!isdigit(c)){sign|=c=='-';c=getchar();}
	while(isdigit(c)){t=(t<<1)+(t<<3)+(c&15);c=getchar();}
	return sign?-t:t;
}
inline char get_char(){
	char c=getchar();
	while(c==' '||c=='\n'||c=='\r')c=getchar();
	return c;
}
inline void write(LL x){
	char c[21],len=0;
	if(!x)return putchar('0'),void();
	if(x<0)x=-x,putchar('-');
	while(x)c[++len]=x%10,x/=10;
	while(len)putchar(c[len--]+48);
}
inline void space(LL x){write(x),putchar(' ');}
inline void enter(LL x){write(x),putchar('\n');}
const int MAXN=2e5+5;
int p[MAXN],a[MAXN],b[MAXN];
LL s[MAXN];
int Find(int x){
	return p[x]==x?x:p[x]=Find(p[x]);
}
int main()
{
//	freopen("test.in","r",stdin);
//	freopen("test.out","w",stdout);
	int n=read_int(),m=read_int();
	if(n==1&&m==0)
	printf("%d %d\n",1,2);
	else if(m<0||m>=n-1)puts("-1");
	else if((n-m)%2==1){
		m++;
		int pos=1,d=(n-m)/2;
		_for(i,1,d){
			printf("%d %d\n%d %d\n",pos,pos+3,pos+1,pos+2);
			pos+=4;
		}
		d=n-2*(d-1)-1;
		printf("%d %d\n",pos,pos+1+2*d);
		pos++;
		_rep(i,1,d-2)
		printf("%d %d\n",pos,pos+1),pos+=2;
		printf("%d %d\n%d %d\n",pos,pos+3,pos+1,pos+2);
	}
	else{
		int pos=1,d=(n-m)/2;
		_for(i,1,d){
			printf("%d %d\n%d %d\n",pos,pos+3,pos+1,pos+2);
			pos+=4;
		}
		d=n-2*(d-1)-1;
		printf("%d %d\n",pos,pos+1+2*d);
		pos++;
		_rep(i,1,d)
		printf("%d %d\n",pos,pos+1),pos+=2;
	}
	return 0;
}

#include<cmath>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
#define ch() getchar()
#define pc(x) putchar(x)
template<typename T>inline void read(T&x){
	int f;char c;
	for(f=1,c=ch();c<'0'||c>'9';c=ch())if(c=='-')f=-f;
	for(x=0;c<='9'&&c>='0';c=ch())x=x*10+(c&15);x*=f;
}
template<typename T>inline void write(T x){
	static char q[64];int cnt=0;
	if(!x)pc('0');if(x<0)pc('-'),x=-x;
	while(x)q[cnt++]=x%10+'0',x/=10;
	while(cnt--)pc(q[cnt]);
}
int main(){
	int n,m;read(n),read(m);
	if(n==1&&m==0)puts("1 2");
	else if(m>n-2||m<0)puts("-1");
	else if(m==0){
		for(int i=1;i<=n;++i)
			write(i),pc(' '),write(i+n),pc('\n');
	}
	else{
		const int Base=300000;
		for(int i=1;i<=m+1;++i)
			write(i*2-1+Base),pc(' '),write(i*2+Base),pc('\n');
		int l=0,r=(m+1)*2+1;
		for(int i=m+2;i<=n;++i)
			write((l--)+Base),pc(' '),write((r++)+Base),pc('\n');
	}
	return 0;
}


/*
口台 口台
令人咍咍。
*/
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 2e5 + 10;
int n, dep[N], is[N], son[N], res[N], tim, p, q;
int e, to[N << 1], nxt[N << 1], hd[N];
void add(int u, int v){ to[++e] = v; nxt[e] = hd[u]; hd[u] = e; }
void dfs(int u, int fa){
	if(dep[u] > dep[p]) p = u;
	for(int i = hd[u]; i; i = nxt[i]){
		int v = to[i]; if(v == fa) continue;
		dep[v] = dep[u] + 1; dfs(v, u);
	}
	return;
}
void dfs2(int u, int fa){
	is[u] = (u == q); //printf("%d ", u); printf("%d\n", is[u]);
	for(int i = hd[u]; i; i = nxt[i]){
		int v = to[i]; if(v == fa) continue;
		dfs2(v, u); if(is[v]) is[u] = 1, son[u] = v;
	}

	return;
}
void dfs3(int u, int fa){
	res[u] = ++tim;
	for(int i = hd[u]; i; i = nxt[i]){
		int v = to[i]; if(v == fa || v == son[u]) continue;
		dfs3(v, u);
	}
	if(son[u]) dfs3(son[u], u);
	++tim;
	return;
}
int main() {
	//freopen("ex.in", "r", stdin);
	//freopen("ex.out", "w", stdout);
	scanf("%d", &n);
	for(int i = 1, u, v; i < n; i++)
		scanf("%d%d", &u, &v), add(u, v), add(v, u);
	p = 1; dep[1] = 0; dfs(1, 0);
	q = p; dep[q] = 0; dfs(q, 0);
	//cout<<p<<" "<<q<<endl;
	dfs2(p, 0); dfs3(p, 0);
	//printf("%d\n", 2 * (n - 1) + 1 - dep[p]);
	for(int i = 1; i <= n; i++)
		printf("%d ", res[i]);
	return 0;
}

#include "bits/stdc++.h"
//#include "atcoder/all"
using namespace std;
//using namespace atcoder;
//using mint = modint1000000007;
//const int mod = 1000000007;
//using mint = modint998244353;
//const int mod = 998244353;
//const int INF = 1e9;
//const long long LINF = 1e18;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep2(i,l,r)for(int i=(l);i<(r);++i)
#define rrep(i, n) for (int i = (n-1); i >= 0; --i)
#define rrep2(i,l,r)for(int i=(r-1);i>=(l);--i)
#define all(x) (x).begin(),(x).end()
#define allR(x) (x).rbegin(),(x).rend()
#define endl "\n"
int N;
vector<int>to[200005];
int deep = -1;
int dmax = -1;
void dfs(int v, int d = 0, int p = -1) {
	if (d > dmax) {
		deep = v;
		dmax = d;
	}
	for (int e : to[v]) {
		if (p == e) { continue; }
		dfs(e, d + 1, v);
	}
}
int pre[200005];
int deep2 = -1;
int dmax2 = -1;
void dfs0(int v, int d = 0, int p = -1) {
	pre[v] = p;
	if (d > dmax2) {
		deep2 = v;
		dmax2 = d;
	}
	for (int e : to[v]) {
		if (p == e) { continue; }
		dfs0(e, d + 1, v);
	}
}
set<int>st;
int now = 0;
int a[200005];
void dfs2(int v, int d = 0, int p = -1) {
	now++;
	if (0 == a[v]) {
		a[v] = now;
	}
	int last = -1;
	for (int e : to[v]) {
		if (p == e) { continue; }
		if (st.count(e)) {
			last = e;
			continue;
		}
		dfs2(e, d + 1, v);
		now++;
	}
	if (-1 != last) {
		dfs2(last, d + 1, v);
		now++;
	}
}
int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cin >> N;
	rep(i, N - 1) {
		int a, b;
		cin >> a >> b;
		a--;
		b--;
		to[a].push_back(b);
		to[b].push_back(a);
	}
	dfs(0);
	dfs0(deep);
	int now = deep2;
	while (-1 != deep2) {
		st.insert(deep2);
		deep2 = pre[deep2];
	}
	//cout << deep << endl;
	//cout << deep2 << endl;
	dfs2(deep);
	rep(i, N) {
		cout << a[i] << " ";
	}
	return 0;
}


#include <stdint.h>
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>

using namespace std;

#define FOR_N(i, n) for (int64_t i = 0; i < (int64_t)(n); i++)
#define FOR_R(i, b, e) for (int64_t i = int64_t(b); i < (int64_t)(e); i++)

int main() {
    int64_t H, W;
    cin >> H >> W;

    int64_t A[100][100];
    int64_t min_A = 9999999999;

    FOR_N(i, H) {
        FOR_N(j, W) {
            cin >> A[i][j];
            min_A = min(min_A, A[i][j]);
        }
    }

    int64_t diff = 0;

    FOR_N(i, H) {
        FOR_N(j, W) {
            diff += A[i][j] - min_A;
        }
    }
    cout << diff << endl;

    return 0;
}

#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
typedef long long ll;
#define FOR(i, a, b) for(int i=(a); i<(b);i++)
#define REP(i, n) for(int i=0; i<(n);i++)
#define ROF(i, a, b) for(int i=(b-1); i>=(a);i--)
#define PER(i, n) for(int i=n-1; i>=0;i--)
using namespace std;

int main() {

  ll h, w;
  ll sum, min;
  sum = 0;
  min = 100;
  cin >> h >> w;
  REP(i, h) {
    REP(j, w) {
      ll a;
      cin >> a;
      sum += a;
      min = min > a ? a : min;
    }
  }
  cout << sum - min * h * w;

  return 0;
}


using namespace std;
#include<bits/stdc++.h>
#define int long long
#define all(x) x.begin(), x.end()
#define IOS ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)

const int N = 2e5+3;

int digits(int value)
{
    int cnt = 0;

    while( value )
        ++cnt, value/=10;

    return cnt;
}

int power (int base, int exp)
{
    int res = 1;

    while(exp)
    {
        if (exp & 1)
        {
            res*=base;
        }
        exp>>=1;
        base*=base;

    }
    return res;
}

signed main()
{
    IOS;
    int n; cin >> n;

    int tot = digits(n);
    int ans = 0;

    if ( tot < 4 )
    {
        cout << 0 << endl;
        return 0;
    }

    for ( int i = 4; i < tot; ++i )
        ans += power(10,i-1)*9LL*((i - 1)/3);

    ans += (n - power(10, tot - 1) + 1)*(( tot - 1 )/3);

    cout << ans << endl;
}

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

int main()
{
   long long n  ;
cin>>n ;
long long x[n] , y=0;
for(int i=0 ;i<n;i++)
{
cin>>x[i] ;
}
for(int i=0 ;i<n ;i++)
{
y+=abs(x[i]) ;
}
cout<<y<<endl ;
 long long t=0 ;
for(int i=0;i<n;i++)
{
 t+=(abs(x[i])*abs(x[i]) ) ;
}
cout<<fixed<<showpoint<<setprecision(15)<<sqrt(t)<<endl ;
int r= abs(x[0]);
for(int i=0 ;i<n;i++)
{
if(r<abs(x[i]))
r=(abs(x[i])) ;
}
cout<<r<<endl ;

    return 0;
 }


#include<bits/stdc++.h>
using namespace std;
long long n,x,i,a[1000000],cnt;
int main(){
	ios::sync_with_stdio(false);
	cin>>n;
	for(i=1;i<=sqrt(n);i++){
		if(n%i==0){
			cout<<i<<endl;
			x=n/i;
			if(i!=x)a[++cnt]=x;
		}
	}
	for(i=cnt;i>=1;i--)cout<<a[i]<<endl;
	return 0;
}

//#define _GLIBCXX_DEBUG

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

#define endl '\n'
#define lfs cout<<fixed<<setprecision(10)
#define ALL(a)  (a).begin(),(a).end()
#define ALLR(a)  (a).rbegin(),(a).rend()
#define spa << " " <<
#define fi first
#define se second
#define MP make_pair
#define MT make_tuple
#define PB push_back
#define EB emplace_back
#define rep(i,n,m) for(ll i = (n); i < (ll)(m); i++)
#define rrep(i,n,m) for(ll i = (ll)(m) - 1; i >= (ll)(n); i--)
using ll = long long;
using ld = long double;
const ll MOD1 = 1e9+7;
const ll MOD9 = 998244353;
const ll INF = 1e18;
using P = pair<ll, ll>;
template<typename T1, typename T2>bool chmin(T1 &a,T2 b){if(a>b){a=b;return true;}else return false;}
template<typename T1, typename T2>bool chmax(T1 &a,T2 b){if(a<b){a=b;return true;}else return false;}
ll median(ll a,ll b, ll c){return a+b+c-max({a,b,c})-min({a,b,c});}
void ans1(bool x){if(x) cout<<"Yes"<<endl;else cout<<"No"<<endl;}
void ans2(bool x){if(x) cout<<"YES"<<endl;else cout<<"NO"<<endl;}
void ans3(bool x){if(x) cout<<"Yay!"<<endl;else cout<<":("<<endl;}
template<typename T1,typename T2>void ans(bool x,T1 y,T2 z){if(x)cout<<y<<endl;else cout<<z<<endl;}
template<typename T>void debug(vector<vector<T>>&v,ll h,ll w){for(ll i=0;i<h;i++){cout<<v[i][0];for(ll j=1;j<w;j++)cout spa v[i][j];cout<<endl;}};
void debug(vector<string>&v,ll h,ll w){for(ll i=0;i<h;i++){for(ll j=0;j<w;j++)cout<<v[i][j];cout<<endl;}};
template<typename T>void debug(vector<T>&v,ll n){if(n!=0)cout<<v[0];for(ll i=1;i<n;i++)cout spa v[i];cout<<endl;};
template<typename T>vector<vector<T>>vec(ll x, ll y, T w){vector<vector<T>>v(x,vector<T>(y,w));return v;}
ll gcd(ll x,ll y){ll r;while(y!=0&&(r=x%y)!=0){x=y;y=r;}return y==0?x:y;}
vector<ll>dx={1,-1,0,0,1,1,-1,-1};vector<ll>dy={0,0,1,-1,1,-1,1,-1};
template<typename T>vector<T> make_v(size_t a,T b){return vector<T>(a,b);}
template<typename... Ts>auto make_v(size_t a,Ts... ts){return vector<decltype(make_v(ts...))>(a,make_v(ts...));}
template<typename T1, typename T2>ostream &operator<<(ostream &os, const pair<T1, T2>&p){return os << p.first << " " << p.second;}
template<typename T>ostream &operator<<(ostream &os, const vector<T> &v){for(auto &z:v)os << z << " ";cout<<"|"; return os;}
//mt19937 mt(chrono::steady_clock::now().time_since_epoch().count());
int popcount(ll x){return __builtin_popcountll(x);};
int poplow(ll x){return __builtin_ctzll(x);};
int pophigh(ll x){return 63 - __builtin_clzll(x);};
vector<ll>divisor_enum(ll n){
  vector<ll>ret;
  for(ll i=1;i*i<=n;i++){
    if(n%i==0){
      if(i*i==n)ret.PB(i);
      else{
        ret.PB(i);
        ret.PB(n/i);
      }
    }
  }
  return ret;
}
int main(){
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  ll res=0,buf=0;
  bool judge = true;
  ll n;cin>>n;
  auto d=divisor_enum(n);
  sort(ALL(d));
  for(auto z:d)cout<<z<<endl;
  return 0;
}


# include <bits/stdc++.h>
# ifndef ngng628_library
# define ngng628_library
# define int long long
# define float long double
# define fi first
# define se second
# define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
# define reps(i,n) for(int i=1, i##_len=(n); i<=i##_len; ++i)
# define rrep(i,n) for(int i=((int)(n)-1); i>=0; --i)
# define rreps(i,n) for(int i=((int)(n)); i>0; --i)
# define repr(i,b,e) for(int i=(b), i##_len=(e); i<i##_len; ++i)
# define reprs(i,b,e) for(int i=(b), i##_len=(e); i<=i##_len; ++i)
# define all(x) std::begin(x), std::end(x)
# define rall(x) std::rbegin(x), std::rend(x)
# define pb push_back
# define eb emplace_back
# define len(x) ((int)(x).size())
using namespace std;
template<class T> using vec = vector<T>;
using pii = pair<int, int>;
using vi = vec<int>;
using vvi = vec<vi>;
using db = deque<bool>;
using ddb = deque<db>;
using vs = vec<string>;
constexpr int INF = (1LL<<62)-(1LL<<31);
constexpr float EPS = 1e-10;
template<class T> istream& operator>>(istream& is, vec<T>& v) { for (auto& x : v) is >> x; return is; }
template<class T, class U> istream& operator>>(istream& is, pair<T, U>& p) { return is >> p.fi >> p.se; }
template<class T> string join(const vec<T> &v){ stringstream s; rep (i, len(v)) s<<' '<<v[i]; return s.str().substr(1); }
template<class T> ostream& operator<<(ostream& os, const vec<T>& v){ if (len(v)) os << join(v); return os; }
template<class T> ostream& operator<<(ostream& os, const vec<vec<T>>& v){ rep (i, len(v)) if (len(v[i])) os << join(v[i]) << (i-len(v)+1 ? "\n" : ""); return os; }
template<class T, class U> ostream& operator<<(ostream& os, const pair<T, U>& p){ return os << p.fi << " " << p.se; }
template<class T, class U, class V> ostream& operator<<(ostream& os, const tuple<T, U, V>& t){ return os << get<0>(t) << " " << get<1>(t) << " " << get<2>(t); }
void print(){ cout << "\n"; }
template<class T, class... A>void print(const T& v, const A&...args){ cout << v; if(sizeof...(args))cout << " "; print(args...); }
void eprint() { cerr << "\n"; }
template<class T, class... A>void eprint(const T& v, const A&...args){ cerr << v; if(sizeof...(args))cerr << " "; eprint(args...); }
void drop(){ cout << "\n"; exit(0); }
template<class T, class... A>void drop(const T& v, const A&...args){ cout << v; if(sizeof...(args))cout << " "; drop(args...); }
template<class T> constexpr bool chmax(T &a, const T& b) { return a < b && (a = b, true); }
template<class T> constexpr bool chmin(T &a, const T& b) { return a > b && (a = b, true); }
constexpr int ctoi(const char c) { return ('0' <= c and c <= '9') ? (c - '0') : -1; }
# endif  // ngng628_library

int32_t main() {
   int h, w, a, b;
   cin >> h >> w >> a >> b;

   set<vvi> st;
   auto rec = [&st,h,w](auto&& self, vvi now, int a, int b, int r) -> void {
      if (r == 0) {
         st.insert(now);
         return;
      }
      if (a == 0 and b == 0) return;

      if (r >= 2) {
         // 縦
         rep (y, h-1) rep (x, w) {
            if (now[y][x] == -1 and now[y+1][x] == -1 and a > 0) {
               now[y][x] = now[y+1][x] = 1;
               self(self, now, a-1, b, r - 2);
               now[y][x] = now[y+1][x] = -1;
               goto A;
            }
         }
         A:;
         // 横
         rep (y, h) rep (x, w-1) {
            if (now[y][x] == -1 and now[y][x+1] == -1 and a > 0) {
               now[y][x] = now[y][x+1] = 2;
               self(self, now, a-1, b, r - 2);
               now[y][x] = now[y][x+1] = -1;
               goto B;
            }
         }
         B:;
      }
      // 1 枚
      rep (y, h) rep (x, w) {
         if (now[y][x] == -1 and b > 0) {
            now[y][x] = 0;
            self(self, now, a, b-1, r - 1);
            now[y][x] = -1;
            goto C;
         }
      }
      C:;
   };
   vvi init(h, vi(w, -1));
   rec(rec, init, a, b, h*w);

   print(len(st));
}

#pragma region Region_1

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
#define srep(i, s, t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(), a.end()
#define rrng(a) a.rbegin(), a.rend()
using ll = long long;
using P = pair<ll, ll>;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<ll>;
using VVL = vector<VL>;
using VP = vector<P>;
using VS = vector<string>;
using VC = vector<char>;
using VVC = vector<vector<char>>;
#define MOD 1000000007
const int INF = (int)1e9 + 10;         // int max > 2*10^9
const long long INFL = (ll)2e18 + 10;  // ll max > 9*10^18

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

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

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

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

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

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

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

int main() {
    std::cout << std::setprecision(15);
    //////////////////////////////////////////
    VI a(3);
    rep(i,3)cin >> a[i];
    sort(rng(a));
    if(a[2]-a[1] == a[1]-a[0])print("Yes");
    else print("No");

    return 0;
}


#include "bits/stdc++.h"

#define REP(i, n, N) for(ll i=(n); i<(N); i++)
#define RREP(i, n, N) for(ll i=(N-1); i>=(n); i--)
#define LREP(lst,itr) for(auto itr = lst.begin(); itr != lst.end(); ++itr)
#define CK(n, a, b) ((a)<=(n)&&(n)<(b))
#define ALL(v) (v).begin(),(v).end()
#define MCP(a, b) memcpy(b,a,sizeof(b))
#define P(s) cout<<(s)<<endl
#define P2(a, b) cout<<(a)<<" "<<(b)<<endl
#define P3(a, b, c) cout<<(a)<<" "<<(b)<<" "<<(c)<<endl
#define V2(T) vector<vector<T>>
typedef long long ll;
using namespace std;
const ll MOD = 1e9 + 7;
const ll INF = 1e18;

int main(){
    int N, A, B;
    cin >> N >> A >> B;
    P(N+(B-A));
}

#include <bits/stdc++.h>

using namespace std;

int main (void) {
    int N, A, B;
    cin >> N >> A >> B;

    cout << N - A + B << endl;
    return 0;
}


#include<bits/stdc++.h>
// #define int long long
// #define maxn
// #define mod
using namespace std;
// template<class T>T ABS(T x) {return x<0?-x:x;}
//int ksm(int x,int y) {int r=1;while(y) y&1?r=1ll*r*x%mod:0,x=1ll*x*x%mod,y>>=1;return r;}
int read()
{
	int s=0,w=1;
	char ch=getchar();
	while(ch<'0'||ch>'9') {if(ch=='-')w=-1;ch=getchar();}
	while(ch>='0'&&ch<='9') s=(s<<3)+(s<<1)+(ch^48),ch=getchar();
	return s*w;
}
// struct Edge{int to,next;}a[maxn];
// int h[maxn],cnt;
// void add(int x,int y) {a[++cnt]=(Edge){y,h[x]},h[x]=cnt,a[++cnt]=(Edge){x,h[y]},h[y]=cnt;}
signed main()
{
	int A=read(),B=read(),W=read()*1000;
	int ta=W/A,tb=(W+B-1)/B;
	if(tb>ta) cout<<"UNSATISFIABLE\n";
	else cout<<tb<<' '<<ta<<'\n';
	return 0;
}

#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <functional>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <deque>
#include <string>
#include <cassert>

using namespace std;

typedef long long llint;

const int INF = 0x3f3f3f3f;
const llint INFLL = 0x3f3f3f3f3f3f3f3fLL;

void print() { cout << "\n"; }

template <typename...T, typename X>
void print(X&& x, T... args) { cout << x << " "; print(args...); }

int input() { return 0; }

template <typename...T, typename X>
int input(X& x, T&... args) {
    if (!(cin >> x)) return 0;
    return input(args...) + 1;
}

const int ALPHA = 256;
const string UNSOLVABLE = "UNSOLVABLE";
string a, b, c;
int mp[ALPHA];

llint string_to_int(const string& s) {
    int n = s.size();
    llint res = 0;
    if (mp[s[0]] == 0) {
        return -1;
    }

    for (int i = 0; i < n; i++) {
        res = res * 10 + mp[s[i]];
    }

    return res;
}

bool check() {
    llint aa = string_to_int(a);
    if (aa == -1) {
        return false;
    }
    llint bb = string_to_int(b);
    if (bb == -1) {
        return false;
    }
    llint cc = string_to_int(c);
    if (cc == -1) {
        return false;
    }
    return aa + bb == cc;
}

int main() {
    input(a, b, c);

    string charset = a + b + c;
    sort(charset.begin(), charset.end());

    charset.erase(std::unique(charset.begin(), charset.end()), charset.end());

    if (charset.size() > 10) {
        puts(UNSOLVABLE.c_str());
        return 0;
    }

    vector<int> ns;
    for (int i = 0; i < 10; i++) {
        ns.push_back(i);
    }

    bool flag = false;
    do {
        memset(mp, -1, sizeof(mp));
        for (int i = 0; i < charset.size(); i++) {
            mp[charset[i]] = ns[i];
        }

        if (check()) {
            flag = true;
            break;
        }
    } while (next_permutation(ns.begin(), ns.end()));

    if (flag) {
        llint aa = string_to_int(a);
        llint bb = string_to_int(b);
        llint cc = string_to_int(c);

        printf("%lld\n", aa);
        printf("%lld\n", bb);
        printf("%lld\n", cc);
    } else {
        puts(UNSOLVABLE.c_str());
    }

    return 0;
}

/*

^^^TEST^^^
a
b
c
-----
1
2
3
$$$TEST$$$

^^^TEST^^^
x
x
y
----
1
1
2
$$$TEST$$$

^^^TEST^^^
p
q
p
---
UNSOLVABLE
$$$TEST$$$

^^^TEST^^^
abcd
efgh
ijkl
---
UNSOLVABLE
$$$TEST$$$

^^^TEST^^^
send
more
money
----
9567
1085
10652
$$$TEST$$$

*/


#include<bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef long double ld;

const ll maxn=100005;
const ll mod=1e9+7;
const ll m2=1e9+7;
const ll INF64 = ll(1e18);
const ll max2=1e3+10;
const ll N = 1000001;
const ll MAXN=2e5+10;
const ll ALPHABET_SIZE = 2;

int main()
{
#ifndef ONLINE_JUDGE
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
//long long tt = clock();
#endif
ios_base::sync_with_stdio(NULL);  cin.tie(0); cout.tie(0);
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
ll n,i,j;
cin>>n;
vector<ll> v(n);
for(i=0;i<n;++i)
cin>>v[i];

ll val[n+1][n];
memset(val,0,sizeof(val));
ll dp[n+1][n+1];
memset(dp,0,sizeof(dp));
dp[0][0]=1;
val[1][0]=1;
ll mod1[n+1];
memset(mod1,0,sizeof(mod1));
for(i=1;i<=n;++i)
{
	for(j=1;j<=n;++j)
	{
		mod1[j]+=v[i-1]%j;
		mod1[j]%=j;
		dp[i][j]+=val[j][mod1[j]];
		dp[i][j]%=mod;

	}
	for(j=1;j<=n;++j)
	{
		val[j][mod1[j]]+=dp[i][j-1];
		val[j][mod1[j]]%=mod;
	}
}
ll val1=0;
for(i=1;i<=n;++i)
{val1+=dp[n][i];
	val1%=mod;
}
cout<<val1;

return(0);
}

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

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

ll dp[18];
char S[200200];
int suuji(char c) {
	if (c < 'A') return c - '0';
	else return c - ('A' - 10);
}

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

	fread(S, 1, 200200, stdin);
	int K = 0;
	int N = 200200 - 1;
	while (S[N] != ' ') N--;
	int tmp = N + 1;
	while (S[tmp] >= '0') K = K * 10 + S[tmp++] - '0';

	const int mod = 1e9 + 7;
	int k = suuji(S[0]);
	dp[1] = k - 1;
	int kazu = 1 << 15 - k;

	rep1(i, N - 1) {
		if (!(i & 7)) for (int j = 2; j <= 16; j++) dp[j] %= mod;
		for (int j = 16; j >= 1; j--) {
			dp[j + 1] += (16 - j) * dp[j];
			dp[j] = j * dp[j];
		}
		dp[1] += 15;
		int k = suuji(S[i]);
		int k1 = __builtin_popcount(kazu >> 16 - k);
		int kazu0 = __builtin_popcount(kazu);
		dp[kazu0] += k1;
		dp[kazu0 + 1] += k - k1;
		kazu |= 1 << 15 - k;
	}

	ll kotae = dp[K];
	kotae += (__builtin_popcount(kazu) == K);
	printf("%lld", kotae % mod);

	Would you please return 0;
}


#include <bits/stdc++.h>

using namespace std;
const double PI=acos(-1);
const double eps=1e-5;
int main(){
	int n,a,b,c,d;
	scanf("%d",&n);
	scanf("%d%d%d%d",&a,&b,&c,&d);
	double x=1.0*(a+c)/2.0,y=1.0*(b+d)/2.0;
	double len=sqrt(1.0*(a-c)*(a-c)+1.0*(b-d)*(b-d))/2;
	double al=atan2(1.0*(d-b),1.0*(c-a));//用atan()会WA,
	double bl=2.0*PI/n;
	double cl=al+bl;
	double ax=x-len*cos(cl),ay=y-len*sin(cl);
	if(fabs(ay)<eps) ay=0;//-0的情况
	if(fabs(ax)<eps) ax=0;
	printf("%.5f %.5f\n",ax,ay);
	return 0;
}

#include <bits/stdc++.h>

using namespace std;

int main() {
  int N;
  cin >> N;

  complex<long double> p0, pN2;
  {
    double x, y;
    cin >> x >> y;
    p0 = x + y * 1i;
    cin >> x >> y;
    pN2 = x + y * 1i;
  }

  complex<long double> g = (p0 + pN2) * (long double)0.5;
  complex<long double> rot = polar(1.0, M_PI * 2 / N);

  complex<long double> p1 = (p0 - g) * rot + g;

  cout << fixed << setprecision(10) << p1.real() << ' ' << p1.imag() << endl;

  return 0;
}


#include <bits/stdc++.h>
using namespace std;
using std::cout;
using std::cin;
using std::endl;
using ll=long long;
using ld=long double;
ll I=1167167167167167167;
ll Q=1e9+7;
#define rep(i,a) for (ll i=0;i<a;i++)
template<class T> using _pq = priority_queue<T, vector<T>, greater<T>>;
template<class T> ll LB(vector<T> &v,T a){return lower_bound(v.begin(),v.end(),a)-v.begin();}
template<class T> ll UB(vector<T> &v,T a){return upper_bound(v.begin(),v.end(),a)-v.begin();}
template<class T> bool chmin(T &a,const T &b){if(a>b){a=b;return 1;}else return 0;}
template<class T> bool chmax(T &a,const T &b){if(a<b){a=b;return 1;}else return 0;}
template<class T> void So(vector<T> &v) {sort(v.begin(),v.end());}
template<class T> void Sore(vector<T> &v) {sort(v.begin(),v.end());reverse(v.begin(),v.end());}
template<class T> void print_tate(vector<T> &v) {rep(i,v.size()) cout<<v[i]<<"\n";}
void yneos(bool a){if(a) cout<<"Yes"<<"\n"; else cout<<"No"<<"\n";}

//Cとかで出てみたい
int main() {
	ll R,X,Y;
	cin>>R>>X>>Y;
	R*=R,X*=X,Y*=Y;
	ll K=(X+Y+R-1)/R;
	//cout<<K<<endl;
	ll l=0,r=1e9;
	while(r-l>1){
		ll D=(l+r)/2;
		if(D*D>=K) r=D;
		else l=D;
	}
	if(X+Y<R) cout<<"2"<<endl;
	else cout<<r<<endl;
}

#include <cstdio>
#include <iostream>
using namespace std;
#define int __int128
int T, X, Y, P, Q;

void read( int &x ) {
	x = 0; char s = getchar();
	while( s < '0' || s > '9' ) s = getchar();
	while( '0' <= s && s <= '9' ) {
		x = ( x << 1 ) + ( x << 3 ) + ( s ^ 48 );
		s = getchar();
	}
}

void exgcd( int a, int b, int &d, int &x, int &y ) {
	if( ! b ) d = a, x = 1, y = 0;
	else {
		exgcd( b, a % b, d, y, x );
		y -= x * ( a / b );
	}
}

void print( int x ) {
	if( x > 9 ) print( x / 10 );
	putchar( ( x % 10 ) + '0' );
}

signed main() {
	read( T );
	while( T -- ) {
		read( X ), read( Y ), read( P ), read( Q );
		int d, x, y, ans = 1e32;
		exgcd( X * 2 + Y * 2, P + Q, d, x, y );
		for( int i = 0;i < Y;i ++ )
			for( int j = 0;j < Q;j ++ ) {
				int c = P + j - X - i;
				if( c % d ) continue;
				int k1 = c / d * x;
				int k2 = c / d * ( - y );
				int mod1 = ( P + Q ) / d, mod2 = ( X * 2 + Y * 2 ) / d;
				if( k1 < 0 ) {
					int t = ( - k1 + mod1 - 1 ) / mod1;
					k1 += mod1 * t, k2 += mod2 * t;
				}
				if( k2 < 0 ) {
					int t = ( - k2 + mod2 - 1 ) / mod2;
					k1 += mod1 * t, k2 += mod2 * t;
				}
				k1 %= mod1;
				ans = min( ans, k1 * ( X * 2 + Y * 2 ) + X + i );
			}
		if( ans == 1e32 ) printf( "infinity\n" );
		else print( ans ), putchar( '\n' );
	}
	return 0;
}


#include <bits/stdc++.h>
//#include <chrono>
//#pragma GCC optimize("O3")
using namespace std;
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define Rreps(i,n,e) for(int i = n - 1; i >= e; --i)
#define Rrep(i,n) Rreps(i,n,0)
#define ALL(a) a.begin(), a.end()
#define fi first
#define se second

using ll = long long;
using vec = vector<ll>;
using mat = vector<vec>;

ll N,M,H,W,Q,K,A,B;
string S;
using P = pair<ll, ll>;
const ll INF = (1LL<<60);

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

template <unsigned long long mod > class modint{
public:
    ll x;
    constexpr modint(){x = 0;}
    constexpr modint(ll _x) : x((_x < 0 ? ((_x += (LLONG_MAX / mod) * mod) < 0 ? _x + (LLONG_MAX / mod) * mod : _x) : _x)%mod){}
    constexpr modint set_raw(ll _x){
        //_x in [0, mod)
        x = _x;
        return *this;
    }
    constexpr modint operator-(){
        return x == 0 ? 0 : mod - x;
    }
    constexpr modint& operator+=(const modint& a){
        if((x += a.x) >= mod) x -= mod;
        return *this;
    }
    constexpr modint operator+(const modint& a) const{
        return modint(*this) += a;
    }
    constexpr modint& operator-=(const modint& a){
        if((x -= a.x) < 0) x += mod;
        return *this;
    }
    constexpr modint operator-(const modint& a) const{
        return modint(*this) -= a;
    }
    constexpr modint& operator*=(const modint& a){
        (x *= a.x)%=mod;
        return *this;
    }
    constexpr modint operator*(const modint& a) const{
        return modint(*this) *= a;
    }
    constexpr modint pow(unsigned long long pw) const{
        modint res(1), comp(*this);
        while(pw){
            if(pw&1) res *= comp;
            comp *= comp;
            pw >>= 1;
        }
        return res;
    }
    //以下、modが素数のときのみ
    constexpr modint inv() const{
        if(x == 2) return (mod + 1) >> 1;
        return modint(*this).pow(mod - 2);
    }
    constexpr modint& operator/=(const modint &a){
        (x *= a.inv().x)%=mod;
        return *this;
    }
    constexpr modint operator/(const modint &a) const{
        return modint(*this) /= a;
    }
};
#define mod2 1000000007
using mint = modint<mod2>;

ostream& operator<<(ostream& os, const mint& a){
    os << a.x;
    return os;
}
using vm = vector<mint>;

mint fibo(int n, bool debug = false){
    vector<vm> dp(2, vm(2, 0));
    dp[0][0] = 1;
    rep(i, n - 1){
        dp[1][0] = dp[0][1];
        dp[1][1] = dp[0][0] + dp[0][1];
        swap(dp[0], dp[1]);
        if(debug){
            cout<<dp[0][0]<<' '<<dp[0][1]<<endl;
        }
    }
    return dp[0][1];
}

int main(){
    //fibo(6, true);
    cin>>N;
    char aa, ab, ba, bb;
    cin>>aa>>ab>>ba>>bb;
    if(N <= 3){
        cout<<1<<endl;
    }else{
        if(ab == 'A'){
            if(aa == 'A'){
                cout<<1<<endl;
            }else if(ba == 'A'){
                cout<<fibo(N)<<endl;
            }else{
                cout<<mint(2).pow(N - 3)<<endl;
            }
        }else{
            if(bb == 'B'){
                cout<<1<<endl;
            }else if(ba == 'A'){
                cout<<mint(2).pow(N - 3)<<endl;
            }else{
                cout<<fibo(N)<<endl;
            }
        }
    }
}

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

int main() {
  ll N; cin>>N;
  vector<ll> A(N),B,C;
  bool isOK=false;
  for(ll i=0; i<N; ++i) {
    cin>>A[i];
    A[i]%=200;
  }
  // N<=8なら全て
  // N>8なら先頭8個のみを全探索
  vector<vector<ll>> group(200);
  for(ll i=1; i<1ll<<min(8ll,N); ++i) {
    bitset<8> bs=i;
    ll val=0;
    for(ll j=0; j<bs.size(); ++j) {
      if(bs.test(j)) val=(val+A[j])%200;
    }
    group[val].push_back(i);
    if(group[val].size()>=2) {
      isOK=true;
      bitset<8> x=group[val][0], y=group[val][1];
      for(ll j=0; j<8; ++j) {
        if(x.test(j)) B.push_back(j+1);
        if(y.test(j)) C.push_back(j+1);
      }
      break;
    }
  }
  if(isOK) {
    cout<<"Yes"<<endl;
    cout<<B.size()<<" ";
    for(auto& e:B) cout<<e<<" ";
    cout<<endl;
    cout<<C.size()<<" ";
    for(auto& e:C) cout<<e<<" ";
    cout<<endl;
  } else cout<<"No"<<endl;
}


#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
#include <cstring>
#include <utility>
#include <numeric>

using namespace std;

int main(){

    string s;
    cin >> s;
    if(s[0] == s[1] && s[1] == s[2]){
        cout << "Won" << endl;
    }
    else{
        cout << "Lost" << endl;
    }

    return 0;
}

// @iamnifer
#include <iostream>
#include <set>
#include <vector>
#include <string>
#include <algorithm>
#include <map>
#include <stack>
#include <deque>
#include <queue>
#include <iomanip>
#include <ext/pb_ds/detail/standard_policies.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#include <bits/stdc++.h>

#define ll long long
#define ld long double
#define ull unsigned long long
#define uint unsigned int
#define elif else if
#define pb push_back
#define add insert
#define fastio cout.tie(nullptr); cin.tie(nullptr); ios_base::sync_with_stdio(false)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define str to_string

using namespace std;
using namespace __gnu_pbds;

typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ld, ld> pld;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
typedef tree<pii, null_type, less<pii>, rb_tree_tag, tree_order_statistics_node_update> ordered_multiset;

template<typename A, typename B>
inline bool umin(A &a, B b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}

template<typename A, typename B>
inline bool umax(A &a, B b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

template<typename T>
T binpow(T b, T e, T m) {
    T r = 1;
    while(e > 0) {
        if(e & 1) r = r * b % m;
        b = b * b % m;
        e >>= 1;
    }
    return r;
}

inline void precision(int x) {
    cout << fixed << setprecision(x);
}

template<typename T>
inline T gcd(T a, T b) {
    return __gcd(a, b);
}

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

template<typename T>
inline int len(T x) {
    return int(x.size());
}

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

inline ll rand(ll l, ll r) {
    return uniform_int_distribution<ll>(l, r)(rng);
}

string str(string &s) {
    return "\"" + s + "\"";
}

template<typename A, typename B>
string str(pair<A, B> v) {
    return str(v.first) + " " + str(v.second);
}

template<typename T>
string str(set<T>& v) {
    string r, e;
    for(auto &i: v) r += e + str(i), e = " ";
    return r;
}

template<typename T>
string str(vector<T>& v) {
    string r, e;
    for(auto &i: v) r += e + str(i), e = " ";
    return r;
}

void debug() {
    cerr << "\n";
}

template<typename Head, typename...Tail>
void debug(Head H, Tail...T) {
    cerr << " " << str(H);
    debug(T...);
}

#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug(__VA_ARGS__)
#else
#define debug(...) 0
#endif

// #pragma GCC optimize("Ofast,unroll-loops")
// #pragma GCC target("avx,avx2,fma,sse4")
// #pragma comment(linker,"/STACK:128777216")

// #pragma GCC optimize("O3")

const ld pi = 3.14159265358979323846264338327950288419716939937510;
const ld eps = 1e-8;
const int inf = 1e9 + 9;
const ll MOD = 1e9 + 7;  // 998244353
const int maxN = 2e5 + 9;

int main() {
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    fastio;
    char a, b, c;
    string s; cin >> s;

    a = s[0]; b = s[1]; c = s[2];
    if(a == b && b == c) {
        cout << "Won\n";
    }
    else cout << "Lost\n";

}


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

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

char S[1000000], *i = S + 500000, *ato = i, *mae = ato, c;

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

	fread(i, 1, 500000, stdin);

	int r = 0;
	while ((c = *i++) >= 'R') {
		if (c == 'R') r ^= 1;
		else {
			if (r) {
				if (mae == ato || *mae != c) *--mae = c;
				else mae++;
			}
			else {
				if (mae == ato || *(ato - 1) != c) *ato++ = c;
				else ato--;
			}
		}
	}

	if (r) reverse(mae, ato);
	fwrite(mae, 1, ato - mae, stdout);

	Would you please return 0;
}

/* #pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") */
// only when really needed

#include <bits/stdc++.h>

#define for1(i,a,b) for (int i = a; i <= b; i++)
#define for2(i,a,b) for (int i = a; i >= b; i--)
#define int long long
#define sz(a) (int)a.size()

#define PI 3.1415926535897932384626433832795
#define INF 8000000000000000000
#define MOD 1000000007

using namespace std;

signed main() {

    int n,x;
    string s;
    cin >> n >> x;
    cin >> s;
    for1(i,0,n-1) {
        if (s[i]=='o') x++;
        else if (x>0) x--;
    }
    cout << x;

}


/* SHUBHAM KESHARWANI */
#include<bits/stdc++.h>
#define ll  long long int
#define mod 1000000007
#define fr(a,b) for(ll i=a;i<b;i++)
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL);
#define test ll t; cin>>t; while(t--)
#define pb push_back
#define all(x) (x).begin(),(x).end()
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
using namespace std;
int main()
{
fast;
//test
{
ll n,i,x,p=1,prev=0;
cin>>n;
set<ll>s;
for(i=0;i<n;i++)
{
	cin>>x;
	s.insert(x);
}
for(auto i:s)
{
	p*=(i-prev+1);
	p%=mod;
	prev=i;
}
cout<<p;
cout<<'\n';
}
    return 0;
}

#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;

#define ll long long int
#define fast ios_base::sync_with_stdio(false)
#define fast_input cin.tie(NULL)
#define fast_output cout.tie(NULL)
#define vi vector<long long int>
#define vp vector<pair<long long int ,long long int>>
#define pb push_back
#define mp make_pair
#define pp pop_back
#define iter vector<int>::iterator
#define pa pair<long long int ,long long int>
#define f(a,b) for(int a=0;a<b;a++)
#define mod 1000000007
#define F first
#define S second
#define sett set<long long int>
#define um unordered_map<ll,ll>
#define ordered_set tree<pa, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
// ll mul(ll a,ll b)
// {
// 	return (a%mod*b%mod)%mod;
// }
// ll add(ll a,ll b)
// {
// 	ll res=a+b;
// 	if(res>=mod)
// 	{
//       res-=mod;
// 	}
// 	return res;
// }
// ll sub(ll a,ll b)
// {
// 	ll res=a-b;
// 	if(res<0)
// 	 res+=mod;
// 	return res;
// }
// ll powmod(ll a, ll b)
// {
//     ll res = 1;
//     while (b) {
//         if (b&1) {
//             res =mul(res,a);
//         }
//         b >>= 1;
//         a=mul(a,a);
//     }

//     return res;
// }

// ll modinv(ll a)
// {
//     return powmod(a, mod - 2);
// }
//  unordered_map<ll,ll>facti;
//  ll fact(ll n)
//  {
// 	if(n==0)return 1;
// 	if(n<=1)return 1;
// 	if(facti[n]!=0)return facti[n];
// 	return facti[n]=mul(n,fact(n-1));
//  }
//   ll ncr(ll n,ll r)
//   {
//         ll h=fact(n);
// 	ll v=fact(r);
// 	ll j=fact(n-r);
// 	v=mul(v,j);
// 	v=powmod(v,mod-2);
// 	return mul(h,v);
//  }
// int fastread(){
//     int x=0;
//     int c = getchar_unlocked();
//     while(c<48)
//         c = getchar_unlocked();
//     while(c>=48){
//         x = x*10 + (c - 48);
//         c = getchar_unlocked();
//     }
//     return x;
// }
// bool comp(pa a,pa b)
// {
//     if(a.F==b.F)
//     {
//         return v[a.S]<v[b.S];
//     }
//     returna.S<b.S;
// }
vector<pa>g[1000001];
ll dp[1000001];
void dfs(ll v,ll par=-1)
{
        for(pa d:g[v])
        {
                if(d.first-par)
                {
                      dp[d.first]=dp[v]^d.second;
                      dfs(d.first,v);
                }
        }
}
void solve()
{
        ll n;
        cin>>n;
        f(i,n-1)
        {
             ll x,y,w;
             cin>>x>>y>>w;
             x--,y--;
             g[x].pb({y,w});
             g[y].pb({x,w});
        }
        dfs(0);
        ll ans=0;
        f(j,60)
        {
                ll ones,zeros;
                ones=zeros=0;
                f(i,n)
                {
                        if(dp[i]&(1ll<<j))
                        {
                                ones++;
                        }
                        else
                        {
                                zeros++;
                        }
                }
                zeros*=ones;
                zeros%=mod;
                ans+=((1ll<<j)%mod*zeros%mod);
                ans%=mod;
        }
        cout<<ans<<endl;
}
int main() {
	fast;
	fast_input;
	fast_output;
	// ll t;
	// cin>>t;
	// while(t--)
	// {
	  solve();
	// }
	return 0;
}