#include<bits/stdc++.h>

using namespace std;
typedef long long ll;

#define FAST ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define mp make_pair
#define pb push_back
#define lp(i,s,f) for(ll i = s; i < ll(f); i++)
#define inF freopen("input.in", "r", stdin);
#define outF freopen("output.in", "w", stdout);
#define endl '\n'
#define MOD 1000000007
#define mm(arr) memset(arr, 0, sizeof(arr))

int main(){
    FAST
    int arr[3];
    for(int i = 0; i < 3; i++){
        cin >> arr[i];
    }
    sort(arr, arr + 3);
    cout << arr[0] + arr[1];
    return 0;
}

#include <iostream>
#include <algorithm>

int main()
{
    int n;
    int64_t a, b;
    std::cin >> n >> a >> b;
    int x;
    std::cin >> x;

    int64_t sum = 0;
    for (int i = 1; i < n; ++i)
    {
        int y;
        std::cin >> y;
        sum += std::min((y - x) * a, b);

        x = y;
    }

    std::cout << sum << std::endl;
    return 0;
}


#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
#define chmax(x,y) x = max(x,y);
#define chmin(x,y) x = min(x,y);
const int di[] = {-1, 0, 1, 0};
const int dj[] = {0, -1, 0, 1};
const int INF = 1001001001;

int main() {
    int n;
    cin >> n;
    vector<int> a(n+1);
    rep(i,n) cin >> a[i+1];
    vector<int> ans(n+1);
    for (int i = n; i >= 1; i--) {
        int cnt = 0;
        for (int j = i; j <= n; j += i) {
            cnt += ans[j];
        }
        ans[i] = a[i]^(cnt%2);
    }
    int b = 0;
    for (int i = 1; i <= n; i++) {
        if (ans[i]) b++;
    }
    cout << b << endl;
    for (int i = 1; i <= n; i++) {
        if (ans[i]) cout << i << endl;
    }
    return 0;
}

#include<bits/stdc++.h>

using namespace std;
typedef long long ll;

int main() {
    int n, m;
    scanf("%d%d", &n, &m);
    int l = 1, r = (n - 1) / 2;
    int ll = r + 1, rr = ll + r;
    int cnt = 0;
    for (int i = 0; i < 2; i++) {
        while (l < r && cnt < m) {
            printf("%d %d\n", l, r);
            cnt++;
            l++, r--;
        }
        l = ll, r = rr;
    }
}


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

#define ll long long
#define ld long double
#define ar array

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;

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

#define vt vector
#define pb push_back
#define all(c) (c).begin(), (c).end()
#define sz(x) (int)(x).size()

#define F_OR(i, a, b, s) for (int i=(a); (s)>0?i<(b):i>(b); i+=(s))
#define F_OR1(e) F_OR(i, 0, e, 1)
#define F_OR2(i, e) F_OR(i, 0, e, 1)
#define F_OR3(i, b, e) F_OR(i, b, e, 1)
#define F_OR4(i, b, e, s) F_OR(i, b, e, s)
#define GET5(a, b, c, d, e, ...) e
#define F_ORC(...) GET5(__VA_ARGS__, F_OR4, F_OR3, F_OR2, F_OR1)
#define FOR(...) F_ORC(__VA_ARGS__)(__VA_ARGS__)
#define EACH(x, a) for (auto& x: a)

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

string to_string(char c) {
	return string(1, c);
}
string to_string(bool b) {
	return b?"true":"false";
}
string to_string(const char* s) {
	return string(s);
}
string to_string(string s) {
	return s;
}
string to_string(vt<bool> v) {
	string res;
	FOR(sz(v))
		res+=char('0'+v[i]);
	return res;
}

template<size_t S> string to_string(bitset<S> b) {
	string res;
	FOR(S)
		res+=char('0'+b[i]);
	return res;
}
template<class T> string to_string(T v) {
    bool f=1;
    string res;
    EACH(x, v) {
		if(!f)
			res+=' ';
		f=0;
		res+=to_string(x);
	}
    return res;
}

template<class A> void write(A x) {
	cout << to_string(x);
}
template<class H, class... T> void write(const H& h, const T&... t) {
	write(h);
	write(t...);
}
void print() {
	write("\n");
}
template<class H, class... T> void print(const H& h, const T&... t) {
	write(h);
	if(sizeof...(t))
		write(' ');
	print(t...);
}

void DBG() {
	cerr << "]" << endl;
}
template<class H, class... T> void DBG(H h, T... t) {
	cerr << to_string(h);
	if(sizeof...(t))
		cerr << ", ";
	DBG(t...);
}
#ifdef _DEBUG
#define dbg(...) cerr << "LINE(" << __LINE__ << ") -> [" << #__VA_ARGS__ << "]: [", DBG(__VA_ARGS__)
#else
#define dbg(...) 0
#endif

template<class T> void offset(ll o, T& x) {
	x+=o;
}
template<class T> void offset(ll o, vt<T>& x) {
	EACH(a, x)
		offset(o, a);
}
template<class T, size_t S> void offset(ll o, ar<T, S>& x) {
	EACH(a, x)
		offset(o, a);
}

mt19937 mt_rng(chrono::steady_clock::now().time_since_epoch().count());
ll randint(ll a, ll b) {
	return uniform_int_distribution<ll>(a, b)(mt_rng);
}
const int d4i[4]={-1, 0, 1, 0}, d4j[4]={0, 1, 0, -1};
const int d8i[8]={-1, -1, 0, 1, 1, 1, 0, -1}, d8j[8]={0, 1, 1, 1, 0, -1, -1, -1};
ll mod=1e9+7;
const int N=1e6+5;
const ld PI=2*acos(0.0);

ll modpow(ll a, ll b){
ll res=1; a%=mod;
while(b){
if(b&1){ res=(res*a)%mod;}
a=(a*a)%mod;
b>>=1;
}
return res;
}

#define lcm(a,b) ((a)*(b))/(__gcd(a,b))

bool compare(array<int,2> a,array<int,2> b){
return a[0]<b[0];
}
void solve() {
int n,t; read(n,t);
vt<array<int,2> > td(n+1);
FOR(i,1,n+1) read(td[i][0],td[i][1]);
sort(++td.begin(),td.end(),compare);
int siz=(*--td.end())[0]+t+5;
vt<int> dp(siz,0);
vt<int> pre(siz,0);
FOR(i,1,n+1){
FOR(j,1,siz){
if(j-td[i][0]<0||j-td[i][0]>=t) { dp[j]=pre[j];}
else{ dp[j]=max(pre[j],pre[j-td[i][0]]+td[i][1]);}
}
FOR(j,1,siz){ pre[j]=dp[j]; dp[j]=0; }
//dbg(i,pre);
}
print(*max_element(all(pre)));
}

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

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

using ll = long long;
#define rep(i, n) for (long long i = 0; i < (n); ++i)
#define repr(i, a, b) for (auto i = (a); i < (b); ++i)
#define itr(x) for (auto&& v : (x))
#define updatemax(t, v) ((t) = std::max((t), (v)))
#define updatemin(t, v) ((t) = std::min((t), (v)))

ll dp[3010][3010];
pair<ll, ll> a[3010];
int main() {
  ll n, t;
  cin >> n >> t;
  rep(i, n) cin >> a[i].first >> a[i].second;
  sort(a, a + n);
  rep(i, n) {
    rep(j, t) {
      updatemax(dp[i + 1][j], dp[i][j]);
      updatemax(dp[i + 1][min(j + a[i].first, t)], dp[i][j] + a[i].second);
    }
    updatemax(dp[i + 1][t], dp[i][t]);
  }
  cout << dp[n][t] << endl;
}


#include <bits/stdc++.h>
using namespace std;
using ll = long long;
constexpr ll MOD = 1000000007;
#define REP(i, n) for (ll i = 0; i < (n); i++)
#define REP2(i, x, n) for (ll i = x; i < (n); i++)
const long long INF = numeric_limits<long long>::max();
template <class T>
inline bool chmin(T &a, T b)
{
    if (a > b)
    {
        a = b;
        return true;
    }
    return false;
}
template <class T>
inline bool chmax(T &a, T b)
{
    if (a < b)
    {
        a = b;
        return true;
    }
    return false;
}

string func(ll N, ll Y)
{

    for (ll i = 0; i <= N; ++i)
    {
        ll iAmount = 10000 * i;
        for (ll j = 0; j <= (N-i); ++j)
        {
            ll jAmount = 5000 * j;
            ll k = N - (i + j);
            if ( k < 0 )    continue;
            if (iAmount + jAmount + 1000 * k == Y)
            {

#ifdef SOURCE_TEST
                cout << N << " " << Y << endl;
                cout << i + j + k << endl;
                cout << i * 10000 + j * 5000 + k * 1000 << endl;
#endif
                return to_string(i) + " " + to_string(j) + " " + to_string(k);
            }
        }
    }

    return "-1 -1 -1";
}
int main()
{
    ll N, Y;
    cin >> N >> Y;

    cout << func(N, Y) << endl;

    return 0;
}

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

// syntax sugar: `for (int i = 0; i < N; ++i)`
#define rep(i, N) for (int i = 0; i < (int)(N); ++i)
#define rep2(i, startValue, N) for (int i = (int)(startValue); i < (int)(N); ++i)
// syntax sugar: `for (int i = 0; i < N; ++i)`
#define REP(type, name, beginValue, endCondValue) \
  for (type name = beginValue; name < endCondValue; ++name)
// syntax sugar: 多次元vector
#define VECTOR_DIM3(T, name, d1, d2, d3, initValue) \
    std::vector<std::vector<std::vector<T>>> name(d1, std::vector<std::vector<T>>(d2, std::vector<int>(d3, initValue)));
#define VECTOR_DIM2(T, name, d1, d2, initValue) \
    std::vector<std::vector<T>> name(d1, std::vector<T>(d2, initValue));
#define VECTOR_DIM1(T, name, d1, initValue) \
    std::vector<T> name(d1, initValue);
#define ll long long
#define ld long double

// ABC085C - Otoshidama
int main(){
  int n, y; // 1 <= n <= 2000
  cin >> n >> y;

  for (int a = 0; a <= n; ++a) {
    const int total = a * 10000;
    if (y < total) {
      break;
    }
    for (int b = 0; b <= n-a; ++b) {
      const int total2 = total + b * 5000;
      if (y < total2) {
        break;
      }
      const int c = (n-a-b);
      if (total2 + c * 1000 == y) {
        cout << a << " " << b << " " << c << endl;
        return 0;
      }
    }
  }
  cout << "-1 -1 -1" << endl;
  return 0;
}


const int LG = 21;
const int FN = 400005;
const long long MOD = 1e9 + 7;
const long long INF = 1e9;
const long long INFLL = 1e18;

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;

#define forn(i, n) for (int (i) = 0; (i) != (n); (i)++)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define popcount(x) __builtin_popcount(x)
#define popcountll(x) __builtin_popcountll(x)
#define fi first
#define se second
#define re return
#define pb push_back
#define uniq(x) sort(all(x)); (x).resize(unique(all(x)) - (x).begin())

#ifdef LOCAL
#define dbg(x) cerr << __LINE__ << " " << #x << " " << x << endl
#define ln cerr << __LINE__ << endl
#else
#define dbg(x) void(0)
#define ln void(0)
#endif // LOCAL

int cx[4] = {-1, 0, 1, 0};
int cy[4] = {0, -1, 0, 1};
string Ans[2] = {"No", "Yes"};
string ANS[2] = {"NO", "YES"};

ll inq(ll x, ll y)
{
    if (!y) re 1 % MOD;
    ll l = inq(x, y / 2);
    if (y % 2) re l * l % MOD * x % MOD;
    re l * l % MOD;
}

ll rev(ll x)
{
    return inq(x, MOD - 2);
}

bool __precomputed_combinatorics = 0;
vector<ll> __fact, __ufact, __rev;

void __precompute_combinatorics()
{
    __precomputed_combinatorics = 1;
    __fact.resize(FN);
    __ufact.resize(FN);
    __rev.resize(FN);
    __rev[1] = 1;
    for (int i = 2; i < FN; i++) __rev[i] = MOD - __rev[MOD % i] * (MOD / i) % MOD;
    __fact[0] = 1, __ufact[0] = 1;
    for (int i = 1; i < FN; i++) __fact[i] = __fact[i - 1] * i % MOD, __ufact[i] = __ufact[i - 1] * __rev[i] % MOD;
}

ll fact(int x)
{
    if (!__precomputed_combinatorics) __precompute_combinatorics();
    return __fact[x];
}

ll cnk(int n, int k)
{
    if (k < 0 || k > n) return 0;
    if (!__precomputed_combinatorics) __precompute_combinatorics();
    return __fact[n] * __ufact[n - k] % MOD * __ufact[k] % MOD;
}

int Root(int x, vector<int> &root)
{
    if (x == root[x]) return x;
    return root[x] = Root(root[x], root);
}

void Merge(int v, int u, vector<int> &root, vector<int> &sz)
{
    v = Root(v, root), u = Root(u, root);
    if (v == u) return;
    if (sz[v] < sz[u])
    {
        sz[u] += sz[v];
        root[v] = u;
    }
    else
    {
        sz[v] += sz[u];
        root[u] = v;
    }
}

int ok(int x, int n)
{
    return 0 <= x && x < n;
}

void bfs(int v, vi &dist, vector<vi> &graph)
{
    fill(all(dist), -1);
    dist[v] = 0;
    vi q = {v};
    for (int i = 0; i < q.size(); i++)
    {
        for (auto u : graph[q[i]])
        {
            if (dist[u] == -1)
            {
                dist[u] = dist[q[i]] + 1;
                q.push_back(u);
            }
        }
    }
}

int A[505][505];

signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n, m, q;
    cin >> n >> m >> q;
    forn(i, m)
    {
        int l, r;
        cin >> l >> r;
        for (int k = r; k <= n; k++) A[l][k]++;
    }
    while (q--)
    {
        int a, b;
        cin >> a >> b;
        int ans = 0;
        for (int i = a; i <= b; i++) ans += A[i][b];
        cout << ans << "\n";
    }
}

/* Note:
Check constants at the beginning of the code.
    N is set to 4e5 but be careful in problems with large constant factor.
    Setting N in every problem is more effective.
Check corner cases.
    N = 1
No def int long long for now.
Add something here.
*/

#include <bits/stdc++.h>

// #undef DEBUG  // Uncomment this line to forcefully disable debug print.
#if DEBUG
template <typename T>
void debug(T value) {
  std::cerr << value;
}
template <typename T, typename... Ts>
void debug(T value, Ts... args) {
  std::cerr << value << ", ";
  debug(args...);
}
#define dbg(...)                              \
  do {                                        \
    cerr << #__VA_ARGS__ << ": ";             \
    debug(__VA_ARGS__);                       \
    cerr << " (L" << __LINE__ << ")" << endl; \
  } while (0)
#else
#define dbg(...)
#endif

void read_from_cin() {}
template <typename T, typename... Ts>
void read_from_cin(T& value, Ts&... args) {
  std::cin >> value;
  read_from_cin(args...);
}
#define in(type, ...) \
  type __VA_ARGS__;   \
  read_from_cin(__VA_ARGS__);

template <typename T>
void write_to_cout(const T& value) {
  std::cout << value << std::endl;
}
template <typename T, typename... Ts>
void write_to_cout(const T& value, const Ts&... args) {
  std::cout << value << ' ';
  write_to_cout(args...);
}
#define out(...) write_to_cout(__VA_ARGS__);

#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)

using ll = long long;

using namespace std;

int main() {
  in(int, N, M, Q);
  vector<int> l(N + 2), r(N + 2);
  vector<vector<int>> train(N + 1);
  while (M--) {
    in(int, L, R);
    ++l[L];
    ++r[R];
    train[L].push_back(R);
  }
  vector<int> ls(N + 2), rs(N + 2);
  rep(i, N) {
    ls[i + 1] = ls[i] + l[i + 1];
    rs[i + 1] = rs[i] + r[i + 1];
    // rs[N - i] = rs[N - i + 1] + r[N - i];
  }

  vector outside(N + 1, vector(N + 1, 0));
  priority_queue<int> que;
  for (int i = 1; i <= N; ++i) {
    for (int t : train[i - 1]) {
      que.push(-t);
    }
    while (!que.empty() && -que.top() <= i) {
      que.pop();
    }
    priority_queue<int> que2 = que;
    for (int j = i; j <= N; ++j) {
      while (!que2.empty() && -que2.top() <= j) {
        que2.pop();
      }
      outside[i][j] = que2.size();
    }
  }
  while (Q--) {
    in(int, p, q);
    out(rs[q] - ls[p - 1] + outside[p][q]);
    // out(M - (ls[p - 1] + rs[q + 1]));
  }
}


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

int n;
void dijkstra(vector<vector<pair<ll,ll>>>& graph,vector<long long> &distance,int start){
    priority_queue<pair<ll,ll>> PQ;
    vector<bool> checked(n,false);
    distance[start]=0;
    PQ.push(make_pair(0,start));
    int u;
    while(1){
        u=-1;
        while(!PQ.empty()){
            if(!checked[PQ.top().second]){
                u=PQ.top().second;
                distance[u]=-PQ.top().first;
                PQ.pop();
                break;
            }
            PQ.pop();
        }
        if(u==-1)break;
        checked[u]=true;
        for(int i=0;i<graph[u].size();i++){
            PQ.push(make_pair(-(distance[u]+graph[u][i].second),graph[u][i].first));
        }
    }
}

int main(){
    in(n);
    vector<vector<pair<ll,ll>>> graph(n);
    vector<ll> distance(n,1000000000000000000);
    int u,k,v,c,q;
    rep(i,n-1){
        in(u,v,c);
        graph[u-1].push_back(make_pair(v-1,c));
        graph[v-1].push_back(make_pair(u-1,c));
    }
    in(q,k);
    dijkstra(graph,distance,k-1);
    rep(i,q){
        in(u,v);
        out(distance[u-1]+distance[v-1]);
    }
}

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

signed main(){
    // cout << fixed << setprecision(10) << flush;

    int n;
    cin >> n;
    vector<int> a(n), b(n), c(n);
    vector<vector<int>> edge(n, vector<int>());
    vector<vector<int>> weight(n, vector<int>());
    for(int i=0; i<n-1; i++){
        cin >> a[i] >> b[i] >> c[i];
        a[i]--; b[i]--; c[i];
        edge[a[i]].push_back(b[i]);
        edge[b[i]].push_back(a[i]);
        weight[a[i]].push_back(c[i]);
        weight[b[i]].push_back(c[i]);
    }

    int q, k;
    cin >> q >> k;
    k--;

    vector<int> dis(n, -1);
    #if 0
    priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>> pq;
    pq.push(make_pair(0, k));
    while(!pq.empty()){
        int d = pq.top().first;
        int p = pq.top().second;
        pq.pop();
        if(dis[p] != -1) continue;
        dis[p] = d;
        for(int i=0; i<edge[p].size(); i++){
            int next = edge[p][i];
            if(dis[next] == -1){
                pq.push(make_pair(d + weight[p][i], next));
            }
        }
    }
    #else
    stack<int> s;
    s.push(k);
    dis[k] = 0;
    while(!s.empty()){
        int p = s.top();
        s.pop();
        for(int i=0; i<edge[p].size(); i++){
            int next = edge[p][i];
            if(dis[next] == -1){
                s.push(next);
                dis[next] = dis[p] + weight[p][i];
            }
        }
    }
    #endif

    for(int i=0; i<q; i++){
        int x, y;
        cin >> x >> y;
        x--; y--;
        cout << dis[x] + dis[y] << endl;
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

using ll = long long;

int main(void) {
    ll N, M;
    cin >> N >> M;
    ll even_max_len = M % 2 == 0 ? M : M - 1;
    ll odd_max_len = M % 2 == 1 ? M : M - 1;
    for (ll i = M; i > 0; i--) {
        if (i % 2 == 0) {
            ll j = (even_max_len - i) / 2;
            printf("%lld %lld\n", 1 + j, 1 + j + i);
        } else {
            ll base = even_max_len + 2;
            ll j = (odd_max_len - i) / 2;
            printf("%lld %lld\n", base + j, base + j + i);
        }
    }
}

// practice with Dukkha
#include <algorithm>
#include <iostream>

using namespace std;

int main() {
	int n, m; cin >> n >> m;
	for (int i = 1, j = m + 1; i < j; i++, j--)
		cout << i << ' ' << j << '\n';
	for (int i = m + 2, j = m + m + 1; i < j; i++, j--)
		cout << i << ' ' << j << '\n';
	return 0;
}


#include <string>
#include <vector>
#include <iostream>
using namespace std;
vector<int> x[100]; int n, t;
bool same(vector<int> a, vector<int> b) {
	for(int i = 0; i < 4; i++) {
		for(int j = 0; j < 4; j++) {
			for(int k = 0; k < 4; k++) {
				for(int l = 0; l < 4; l++) {
					string s;
					for(int m = 0; m < i; m++) s += 'N';
					for(int m = 0; m < j; m++) s += 'E';
					for(int m = 0; m < k; m++) s += 'S';
					for(int m = 0; m < l; m++) s += 'W';
					for(int i = 0; i < s.size(); i++) {
        				t = a[0];
        				switch(s[i]) {
        				case 'N':
            				a[0] = a[1];
            				a[1] = a[5];
        					a[5] = a[4];
        				    a[4] = t;
        				    break;
        				case 'E':
        				    a[0] = a[3];
        				    a[3] = a[5];
        				    a[5] = a[2];
        				    a[2] = t;
        				    break;
        				case 'S':
        				    a[0] = a[4];
        				    a[4] = a[5];
        				    a[5] = a[1];
        				    a[1] = t;
        				    break;
        				case 'W':
        				    a[0] = a[2];
        				    a[2] = a[5];
        				    a[5] = a[3];
    					    a[3] = t;
    					   	break;
	    				}
					}
					if(a == b) return true;
				}
			}
		}
	}
	return false;
}
int main() {
	scanf("%d", &n);
	for(int i = 0; i < n; i++) {
		x[i].resize(6);
		for(int j = 0; j < 6; j++) scanf("%d", &x[i][j]);
	}
	for(int i = 0; i < n; i++) {
		for(int j = i + 1; j < n; j++) {
			if(same(x[i], x[j])) {
				printf("No\n"); return 0;
			}
		}
	}
	printf("Yes\n");
	return 0;
}

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

class Dice {
public:
    static int rollingface[][4];
    static int sideface[][4];
    int face[6];

    Dice(string &face_data);
    // ~Dice();
    void roll(const char &op);
    int top();
    int front_face(int top, int right);
    void print_faces();
    bool operator==(const Dice& other);
};

int Dice::rollingface[][4] = {
    {0, 2, 5, 3},
    {0, 4, 5, 1},
    {0, 1, 5, 4},
    {0, 3, 5, 2},
};

int Dice::sideface[][4] = {
    {1, 3, 4, 2},
    {0, 2, 5, 3},
    {0, 4, 5, 1},
    {0, 1, 5, 4},
    {0, 3, 5, 2},
    {1, 2, 4, 3},
};

Dice::Dice(string &face_data) {
    istringstream strm;
    strm.str(face_data);
    for (int i = 0; i < 6; i++) {
        strm >> face[i];
    }
}

void Dice::roll(const char &op) {
    int *fseq;
    switch (op) {
        case 'E': fseq = Dice::rollingface[0]; break;
        case 'N': fseq = Dice::rollingface[1]; break;
        case 'S': fseq = Dice::rollingface[2]; break;
        case 'W': fseq = Dice::rollingface[3]; break;
        default: break;
    }
    int t, p = face[fseq[3]];
    for (int i = 0; i < 4; i++) {
        t = face[fseq[i]];
        face[fseq[i]] = p;
        p = t;
    }
}

int Dice::front_face(int top, int right) {
    int i;
    for (i = 0; i < 6; i++) {
        if (face[i] == top) break;
    }
    int *fseq = Dice::sideface[i];
    for (i = 0; i < 4; i++) {
        if (face[fseq[i]] == right) return face[fseq[(i-1+4)%4]];
    }
    return -1;
}

void Dice::print_faces() {
    cout << "face:" << endl;
    cout << "   " << face[4] << endl;
    cout << face[3] << " " << face[0] << " " << face[2] << endl;
    cout << "   " << face[1] << endl;
    cout << "   " << face[5] << endl;
    cout << endl;
}

bool Dice::operator==(const Dice& other) {
    int i;
    for (i = 0; i < 6; i++) {
        if (other.face[i] == face[0]) {
            if (other.face[5-i] != face[5]) continue;
            int *f = Dice::sideface[0], *of = Dice::sideface[i];
            for (int j = 0; j < 4; j++) {
                if (face[f[0]] == other.face[of[j]]) {
                    for (int k = 1; k < 4; k++) {
                        if (face[f[k]] != other.face[of[(j+k)%4]]) goto NOT_MATCH;
                    }
                    return true;
                }
            }
            NOT_MATCH:;
        }
    }
    return false;
}

int Dice::top() {
    return face[0];
}

int main() {
    int n, i;
    string buf;
    istringstream strm;
    Dice *dice[100];

    getline(cin, buf);
    strm.str(buf);
    strm >> n;
    for (i = 0; i < n; i++) {
        getline(cin, buf);
        dice[i] = new Dice(buf);
    }

    for (i = 0; i < n-1; i++) {
        Dice *s = dice[i];
        for (int j = i + 1; j < n; j++) {
            if (*s == *dice[j]) {
                cout << "No" << endl;
                return 0;
            }
        }
    }
    cout << "Yes" << endl;

    return 0;
}


#pragma GCC optimize ("O3")
#pragma GCC target ("avx")
//#include<bits/stdc++.h>
#include<cstdio>
#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

const int dm = 1 << 16;
char dn[dm], * di = dn;
inline void putint(int X) {
	int keta = 0;
	char C[10];
	while (X) {
		*(C + keta) = '0' + X % 10;
		X /= 10;
		keta++;
	}
	for (int i = keta - 1; i >= 0; i--)* di++ = (*(C + i));
	*di++ = '\n';
}

const ll mod = 998244353;
ll modpow(ll A, ll B) {
	ll kotae = 1;
	while (B > 0) {
		if (B & 1) kotae = kotae * A % mod;
		A = A * A % mod;
		B >>= 1;
	}
	return kotae;
}

const int IMAX = 4000;
int fac[IMAX + 1], ifac[IMAX + 1];
inline ll comb(int A, int B) {
	return fac[A] * ifac[B] % mod * ifac[A - B] % mod;
}

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

	int K, N;
	scanf("%d", &K);
	scanf("%d", &N);

	if (K == 1) {
		printf("0");
		return 0;
	}

	fac[0] = 1;
	rep1(i, IMAX) fac[i] = (ll)fac[i - 1] * i % mod;
	ifac[IMAX] = modpow(fac[IMAX], mod - 2);
	for (int i = IMAX; i > 0; i--) ifac[i - 1] = (ll)ifac[i] * i % mod;
	int H[1001];
	rep(i, 1001) {
		if (N >= 2 * i) {
			if (i & 1) H[i] = (ll)-fac[N + K - 1 - 2 * i] * ifac[N - 2 * i] % mod;
			else H[i] = (ll)fac[N + K - 1 - 2 * i] * ifac[N - 2 * i] % mod;
		}
	}

	int kotae[1001];
	rep1(i, (K + 1) / 2) {
		ll tmp = 0;
		for (int j = 0; j <= i && N >= j * 2; j++) {
			tmp += (ll)ifac[j] * ifac[i - j] % mod * H[j] % mod;
		}
		kotae[i] = (tmp % mod * ifac[K - 1] % mod * fac[i] % mod + mod) % mod;
	}

	rep1(i, (K + 1) / 2 - 1) {
		putint(kotae[i]);
		putint(kotae[i]);
	}
	putint(kotae[(K + 1) / 2]);
	if (!(K & 1)) {
		putint(kotae[(K + 1) / 2]);
		putint(kotae[(K + 1) / 2]);
	}
	for (int i = (K + 1) / 2 - 1; i >= 1; i--) {
		putint(kotae[i]);
		putint(kotae[i]);
	}

	fwrite(dn, 1, di - dn, stdout);

	Would you please return 0;
}

#include<iostream>
#include<algorithm>

using namespace std;
typedef long long ll;

int N, K;
const ll MOD = 998244353;
ll F[4002], F_inv[4002];

ll modpow(ll a, ll b) {
	ll rtn = 1, kakeru = a;
	while (b > 0) {
		if (b & 1)rtn *= kakeru;
		kakeru *= kakeru;
		kakeru %= MOD;
		rtn %= MOD;
		b >>= 1;
	}
	return rtn;
}

void calc_fac() {
	F[0] = 1, F[1] = 1;
	for (int i = 2; i <= 4001; i++) {
		F[i] = F[i - 1] * i;
		F[i] %= MOD;
	}

	F_inv[4001] = modpow(F[4001], MOD - 2);
	for (int j = 4000; j >= 0; j--) {
		F_inv[j] = F_inv[j + 1] * (j + 1);
		F_inv[j] %= MOD;
	}

}

ll comb(ll a, ll b) {
	if (a < 0)return 0;
	if (b < 0)return 0;
	if (b > a)return 0;
	ll ans = (F[a] * F_inv[b])%MOD * F_inv[a - b];
	return ans % MOD;
}

ll hcomb(ll a, ll b) {
	return comb(a + b - 1, b);
}

int main() {

	calc_fac();

	cin >> K >> N;

	for (int i = 2; i <= 2 * K; i++) {
		if (i % 2 == 1) {
			ll cnt = 0;
			int A = min((i - 1) / 2, (2 * (K + 1) - i) / 2);
			for (int j = 0; j <= A; j++) {
				ll tmp = 1;
				tmp *= (modpow(2, j) * comb(A, j)) % MOD;
				tmp *= hcomb(K - 2 * A + j, N - j);
				tmp %= MOD;
				cnt += tmp;
				cnt %= MOD;
			}
			cout << cnt << endl;
		}
		else {
			ll cnt = 0;
			int A = min((i) / 2, (2 * (K + 1) - i) / 2) - 1;
			for (int j = 0; j <= A; j++) {
				ll tmp = 1;
				tmp *= (modpow(2, j) * comb(A, j)) % MOD;
				ll a = hcomb(K - 2 * A + j - 1, N - j) + hcomb(K - 2 * A + j - 1, N - j - 1);
				a %= MOD;
				tmp *= a;
				tmp %= MOD;
				cnt += tmp;
				cnt %= MOD;
			}
			cout << cnt << endl;
		}
	}

	return 0;
}


#include<bits/stdc++.h>
#include<algorithm>
#include<vector>
#include<queue>
using namespace std;
typedef long long ll;
typedef pair<char,int> P;

int main(){
	char s[1000005];
	scanf("%s",s);
	vector<P> d;//(?¨????,??°)
	int count=1; char before=s[0];
	for(int i=1;s[i]!=0;i++){
		if(s[i]!=before){
			d.push_back(P(before,count));
			before=s[i];
			count=1;
		}else count++;
	}
	d.push_back(P(before,count));
	int res=0;
	if(d.size()==1||d.size()==2) printf("0\n");
	else{
		for(int i=0;i<d.size()-2;i++)
			if(d[i].first=='J'&&d[i+1].first=='O'&&d[i+2].first=='I')
				if(d[i].second>=d[i+1].second&&d[i+1].second<=d[i+2].second) res=max(res,d[i+1].second);
		printf("%d\n",res);
	}
}

#include <iostream>
#include <string>

using namespace std;

int main(void)
{
    string s;
    cin >> s;
    if (s.length() % 2 == 1)
    {
        cout << "No" << endl;
    }
    else
    {
        for (int i = 0; i < (int)s.length(); i += 2)
        {
            if (s[i] != 'h' || s[i + 1] != 'i')
            {
                cout << "No" << endl;
                return 0;
            }
        }
        cout << "Yes" << endl;
    }
    return 0;
}


//
//  main.c
//  ITP1_4_D
//
//  Created by ??±??°?????? on 2015/09/29.
//  Copyright ?? 2015??´ HamadaShogo. All rights reserved.
//

#include <stdio.h>
#include <stdlib.h>

long long intSum(int *num, int size);
int intMax(int *num, int size);
int intMin(int *num, int size);

int main(int argc, const char * argv[]) {
    int *num;
    int size;
    long long sum;
    int max;
    int min;
    int i;

    scanf("%d", &size);
    num = (int *)malloc(sizeof(int) * size);
    if (num == NULL) {
        printf("?????¢???????¢??????§????????????\n");
        exit(1);
    }

    for (i=0; i<size; i++) {
        scanf("%d", &num[i]);
    }

    sum = intSum(num, size);
    max = intMax(num, size);
    min = intMin(num, size);

    printf("%d %d %lld\n", min, max, sum);

    free(num);

    return 0;
}

long long intSum(int *num, int size){
    int i;
    long long sum = 0;

    for(i=0; i<size; i++){
        sum += num[i];
    }

    return sum;
}

int intMax(int *num, int size){
    int i;
    int max = num[0];

    for (i=0; i<size; i++) {
        if (max < num[i]) {
            max = num[i];
        }
    }

    return max;
}

int intMin(int *num, int size){
    int i;
    int min = num[0];

    for (i=0; i<size; i++) {
        if (num[i] < min) {
            min = num[i];
        }
    }

    return min;
}

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

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

    vector<int> a(n);
    for(int i=0; i<n; i++){ cin >> a[i]; }

    int min=0, max=0;
    long long sum=0;
    min = *min_element(a.begin(), a.end());
    max = *max_element(a.begin(), a.end());
    for(int i=0; i<a.size(); i++){ sum += a[i]; }

    cout << min << " " << max << " " << sum << endl;
    return 0;
}


#include<cstring>
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<vector>
#include<cmath>
#include<map>
#include<set>
#define l(x) (x<<1)
#define r(x) ((x<<1)|1)
#define IL inline
#define reg register
#define LL long long
#define N 200010
#define INF 0x3f3f3f3f
using namespace std;

int n,i,j;
int ans=INF;
set <int> S[N*4];

struct Data{
	int x,y;
	char c;
}a[N];

IL int Abs(int x){return (x<0)?-x:x;}
IL void Swap(int &a,int &b){a^=b^=a^=b;}
IL int Min(int a,int b){return (a<b)?a:b;}
IL int Max(int a,int b){return (a>b)?a:b;}

IL int read(){
	int p=0,f=1;	char	c=getchar();
	while (c<48||c>57)	{if (c=='-')	f=-1;	c=getchar();}
	while (c>=48&&c<=57)	p=(p<<1)+(p<<3)+c-48,c=getchar();
	return p*f;
}

int main(){
	#ifdef __Marvolo
	freopen("zht.in","r",stdin);
	freopen("zht.out","w",stdout);
	#endif
	n=read();
	for (i=1;i<=n;i++){
		a[i].x=read();	a[i].y=read();	a[i].c=getchar();
	}
	if (n==1){
		puts("SAFE");
		return 0;
	}

	for (i=1;i<=n;i++)
		if (a[i].c=='U')	S[a[i].x+a[i].y].insert(a[i].x);

	for (i=1;i<=n;i++){
		if (a[i].c=='R'){
			if (!S[a[i].x+a[i].y].size())	continue;
			j=*(--S[a[i].x+a[i].y].end());
			if (j<a[i].x)	continue;
			j=*S[a[i].x+a[i].y].upper_bound(a[i].x);
			ans=Min(ans,j-a[i].x);
		}
	}
	for (i=0;i<4*N;i++)	S[i].clear();
	//U--R

	for (i=1;i<=n;i++)
		if (a[i].c=='D')	S[a[i].x+a[i].y].insert(a[i].x);

	for (i=1;i<=n;i++){
		if (a[i].c=='L'){
			if (!S[a[i].x+a[i].y].size())	continue;
			j=*S[a[i].x+a[i].y].begin();
			if (j>a[i].x)	continue;
			j=*(--S[a[i].x+a[i].y].upper_bound(a[i].x));
			ans=Min(ans,a[i].x-j);
		}
	}
	for (i=0;i<4*N;i++)	S[i].clear();
	//D--L

	for (i=1;i<=n;i++)
		if (a[i].c=='R')	S[a[i].y-a[i].x+N].insert(a[i].x);

	for (i=1;i<=n;i++){
		if (a[i].c=='D'){
			if (!S[a[i].y-a[i].x+N].size())	continue;
			j=*S[a[i].y-a[i].x+N].begin();
			if (j>a[i].x)	continue;
			j=*(--S[a[i].y-a[i].x+N].upper_bound(a[i].x));
			ans=Min(ans,a[i].x-j);
		}
	}
	for (i=0;i<4*N;i++)	S[i].clear();
	//D--R

	for (i=1;i<=n;i++)
		if (a[i].c=='L')	S[a[i].y-a[i].x+N].insert(a[i].x);

	for (i=1;i<=n;i++){
		if (a[i].c=='U'){
			if (!S[a[i].y-a[i].x+N].size())	continue;
			j=*(--S[a[i].y-a[i].x+N].end());
			if (j<a[i].x)	continue;
			j=*S[a[i].y-a[i].x+N].upper_bound(a[i].x);
			ans=Min(ans,j-a[i].x);
		}
	}
	for (i=0;i<4*N;i++)	S[i].clear();
	//D--R
	if (ans!=INF)	ans*=2;

	for (i=1;i<=n;i++)
		if (a[i].c=='R')	S[a[i].y].insert(a[i].x);

	for (i=1;i<=n;i++){
		if (a[i].c=='L'){
			if (!S[a[i].y].size())	continue;
			j=*S[a[i].y].begin();
			if (j>a[i].x)	continue;
			j=*(--S[a[i].y].upper_bound(a[i].x));
			ans=Min(ans,a[i].x-j);
		}
	}
	for (i=0;i<4*N;i++)	S[i].clear();
	//L--R

	for (i=1;i<=n;i++)
		if (a[i].c=='U')	S[a[i].x].insert(a[i].y);

	for (i=1;i<=n;i++){
		if (a[i].c=='D'){
			if (!S[a[i].x].size())	continue;
			j=*S[a[i].x].begin();
			if (j>a[i].y)	continue;
			j=*(--S[a[i].x].upper_bound(a[i].y));
			ans=Min(ans,a[i].y-j);
		}
	}
	for (i=0;i<4*N;i++)	S[i].clear();
	//U--D

	if (ans==INF)	puts("SAFE");
	else cout<<ans*5<<endl;
	return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; ++i)
#define rep2(i, x, n) for(ll i = x, i##_len = (n); i < i##_len; ++i)
#define all(n) begin(n), end(n)
using ll = long long;
using P = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vs = vector<string>;
using vc = vector<char>;
using vb = vector<bool>;
using vd = vector<double>;
vi dir = {-1, 0, 1, 0, -1, -1, 1, 1, -1};

int main() {
  ll n;
  cin >> n;
  map<char, vector<P>> mp;
  rep(i, n) {
    ll x, y;
    char c;
    cin >> x >> y >> c;
    mp[c].push_back({x, y});
  }
  ll ans = 1e18;
  map<ll, set<ll>> ds, ls;
  for(auto p : mp['D']) ds[p.first].insert(p.second);
  for(auto p : mp['U']) {
    ll x = p.first;
    ll y = p.second;
    auto in = ds[x].lower_bound(y);
    if(in == end(ds[x])) continue;
    ll now = (*in - y) * 5;
    ans = min(ans, now);
  }
  for(auto p : mp['L']) ls[p.second].insert(p.first);
  for(auto p : mp['R']) {
    ll x = p.first;
    ll y = p.second;
    auto in = ls[y].lower_bound(x);
    if(in == end(ls[y])) continue;
    ll now = (*in - x) * 5;
    ans = min(ans, now);
  }

  map<ll, set<ll>> u, d;
  for(auto p : mp['U']) u[p.first + p.second].insert(p.first);
  for(auto p : mp['D']) d[p.first - p.second].insert(p.first);
  for(auto p : mp['R']) {
    ll x = p.first;
    ll y = p.second;
    auto in = u[x + y].lower_bound(x);
    ll now;
    if(in != end(u[x + y])) {
      now = (*in - x) * 10;
      ans = min(ans, now);
    }
    in = d[x - y].lower_bound(x);
    if(in != end(d[x - y])) {
      now = (*in - x) * 10;
      ans = min(ans, now);
    }
  }

  u.clear();
  d.clear();
  for(auto p : mp['U']) u[p.first - p.second].insert(p.first);
  for(auto p : mp['D']) d[p.first + p.second].insert(p.first);
  for(auto p : mp['L']) {
    ll x = p.first;
    ll y = p.second;
    auto in = u[x - y].upper_bound(x);
    ll now;
    if(in != begin(u[x - y])) {
      in--;
      now = (x - *in) * 10;
      ans = min(ans, now);
    }
    in = d[x + y].upper_bound(x);
    if(in != begin(d[x + y])) {
      in--;
      now = (x - *in) * 10;
      ans = min(ans, now);
    }
  }

  if(ans == 1e18)
    cout << "SAFE" << endl;
  else
    cout << ans << endl;
}


#include <cstdio>
#include <cstdlib>
#include <iostream>

using namespace std;

struct Dice {
  string input;
  size_t pos;
  int values[6];

  int top;
  int bottom;
  int front;
  int back;
  int left;
  int right;

  void Init() {
    pos = 0;
    top = 1;
    bottom = 6;
    front = 2;
    back = 5;
    left = 4;
    right = 3;
  }

  int Value() const {
    return values[top - 1];
  }

  bool Done() const {
    return pos == input.size();
  }

  void Next() {
    const char d = input[pos];
    int temp = 0;
    switch (d) {
      case 'S':
        temp = front;
        front = top;
        top = back;
        back = bottom;
        bottom = temp;
        break;
      case 'N':
        temp = back;
        back = top;
        top = front;
        front = bottom;
        bottom = temp;
        break;
      case 'E':
        temp = right;
        right = top;
        top = left;
        left = bottom;
        bottom = temp;
        break;
      case 'W':
        temp = left;
        left = top;
        top = right;
        right = bottom;
        bottom = temp;
        break;
    }
    ++pos;
  }
};

int main() {
  Dice dice;
  dice.Init();
  for (int i = 0; i < 6; ++i) {
    cin >> dice.values[i];
  }
  cin >> dice.input;

  for (;;) {
    if (dice.Done()) {
      break;
    }
    dice.Next();
  }
  cout << dice.Value() << endl;
  return 0;
}

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

class Dice {
    public:
        int a, b, c, d, z, f;
        Dice(int a, int b, int c, int d, int z, int f) {
            this->a = a;
            this->b = b;
            this->c = c;
            this->d = d;
            this->z = z;
            this->f = f;
        }

        void s() {
            int tmp = this->b;
            this->b = this->a;
            this->a = this->z;
            this->z = this->f;
            this->f = tmp;
        }

        void e() {
            int tmp = this->c;
            this->c = this->a;
            this->a = this->d;
            this->d = this->f;
            this->f = tmp;
        }

        void n() {
            int tmp = this->b;
            this->b = this->f;
            this->f = this->z;
            this->z = this->a;
            this->a = tmp;
        }

        void w() {
            int tmp = this->c;
            this->c = this->f;
            this->f = this->d;
            this->d = this->a;
            this->a = tmp;
        }

        void printTop() {
            cout << this->a << endl;
        }
};

int main () {
        int a,  b,  c,  d,  z,  f;
        cin >> a >>  b >>  c >>  d >>  z >>  f;
        Dice dd(a, b, c, d, z, f);
        char orders[100];
        scanf("%s", orders);
        for(int i=0; i<strlen(orders); i++) {
            if (orders[i] == 'S') {
                dd.s();
            }
            else if (orders[i] == 'E') {
                dd.e();
            }
            else if (orders[i] == 'W') {
                dd.w();
            }
            else if (orders[i] == 'N') {
                dd.n();
            }
        }
        dd.printTop();
        return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int limN = 105;

int xs[limN], ys[limN];
ll dp[limN][limN];
bool usd[limN][limN];

ll memo(int l, int r) {
    if(l>=r)
        return 0;
    if(usd[l][r])
        return dp[l][r];
    usd[l][r] = true;
    ll &ans = dp[l][r];
    ans = (1LL<<62);
    for(int i=l; i<r; i++) {
        // printf("%d %d %d\n", xs[l], ys[i], ys[i+1]);
        // printf("considerando %d %d %d => %d %lld %lld\n", l, i, r, xs[l]*ys[i]*ys[r], memo(l, i), memo(i+1, r));
        ans = min(ans, xs[l]*ys[i]*ys[r] + memo(l, i) + memo(i+1, r));
    }
    return ans;
}

int main() {
    int N ;
    scanf("%d", &N);
    for(int i=0; i<N; i++) {
        scanf("%d%d", &xs[i], &ys[i]);
    }
    printf("%lld\n", memo(0, N-1));
}


#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<functional>
#include<math.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<(n);i++)
#define pf(n) printf("%d\n",n)
#define pff(a,b) printf("%d  %d\n",a,b);
typedef long long ll;
typedef pair<ll, ll> p;
const int INF = 1001001001;
const double PI = acos(-1);

int main() {
	ll l, r;
	cin >> l >> r;

	ll ans = 1001001;
	if (r - l >= 2019) {
		ans = 0;
	}
	else {
		for (ll i = l; i < r; i++) {
			for (ll j = i + 1; j <= r; j++) {
				ans = min(ans, (i*j) % 2019);
			}
		}
	}
	cout << ans << endl;

	return 0;
}


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

const int64_t MOD = 1e9+7;
void add(int64_t& a, int64_t b){
    a = (a+b) % MOD;
}
void mul(int64_t& a, int64_t b){
    a = a*b % MOD;
}

int nth_bit(int64_t num, int n){
    return (num >> n) & 1;
}

int main(){
    int N, X, Y, Z;
    cin >> N >> X >> Y >> Z;

    int XYZ = (1<<Z) + (1<<(Y+Z)) + (1<<(X+Y+Z));
    const int M = 1<<18;
    const int B = M-1;
    static int64_t dp[41][M][2];
    dp[0][1][0] = 1;
    for(int i=0; i<N; i++) for(int j=0; j<M; j++) for(int k=0; k<2; k++) for(int l=1; l<=10; l++){
        int j2 = ((j<<l) + 1) & B;
        int k2 = k | (XYZ == (XYZ&j2));
        add(dp[i+1][j2][k2], dp[i][j][k]);
    }
    int64_t ans = 0;
    for(int j=0; j<M; j++) add(ans, dp[N][j][1]);
    cout << ans << endl;
}

#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) REP(i,0,n)
#define REP(i,s,e) for(int i=(s); i<(int)(e); i++)
#define repr(i, n) REPR(i, n, 0)
#define REPR(i, s, e) for(int i=(int)(s-1); i>=(int)(e); i--)
#define pb push_back
#define all(r) r.begin(),r.end()
#define rall(r) r.rbegin(),r.rend()
#define fi first
#define se second

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

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

template<typename T> T chmax(T& a, const T& b){return a = (a > b ? a : b);}
template<typename T> T chmin(T& a, const T& b){return a = (a < b ? a : b);}

ll modPow(ll x, ll n) {
    ll ret = 1;
    while(n) {
        if(n&1LL) (ret *= x) %= MOD;
        n >>= 1;
        (x *= x) %= MOD;
    }
    return ret;
}

ll dp[41][(1<<17)+10];

int main(){
    int n;
    vi v(3);
    cin >> n;
    rep(i, 3) cin >> v[i];
    int sum_v = v[0] + v[1] + v[2];
    dp[0][0] = 1;
    auto check = [&](int mask) {
        bool f = true;
        f &= (mask >>=(v[2]-1)) & 1;
        f &= (mask >>=v[1]) & 1;
        f &= (mask >>=v[0]) & 1;
        return f;
    };
    auto pop_mask = [&](int mask) {
        if(mask == 0) return 0;
        bool f = true;
        repr(i, sum_v) {
            if(mask & (1<<i)) {
                if(f) {
                    mask -= (1<<i);
                    f = false;
                    break;
                }
            }
        }
        return mask;
    };
    auto getSize = [&](int mask) {
        if(mask == 0) return 0;
        repr(i, sum_v) {
            if(mask&(1<<i)) {
                return i+1;
            }
        }
        return 0;
    };
    auto push_mask = [&](int mask, int add) {
        if(add > sum_v) return 0;
        while(getSize(mask)+add > sum_v) {
            mask = pop_mask(mask);
        }
        mask <<= add;
        mask |= 1<<(add-1);
        return mask;
    };
    rep(i, n) rep(mask, 1<<sum_v) {
        REP(k, 1, 11) {
            int nxt = push_mask(mask, k);
            if(check(mask) || check(nxt)) continue;
            (dp[i+1][nxt] += dp[i][mask]) %= MOD;
        }
    }
    ll sum = 0LL;
    rep(mask, 1<<sum_v) (sum += dp[n][mask]) %= MOD;
    ll ans = modPow(10, n);
    (ans += MOD - sum) %= MOD;
    cout << ans << endl;
    return 0;
}


#include "bits/stdc++.h"
#include <unordered_set>

#define _CRT_SECURE_NO_WARNINGS

#define REP(i, n) for(decltype(n) i = 0; i < (n); i++)
#define REP2(i, x, n) for(decltype(x) i = (x); i < (n); i++)
#define REP3(i, x, n) for(decltype(x) i = (x); i <= (n); i++)
#define RREP(i, n) for (decltype(n) i = (n) - 1; i >= 0; i--)

#define ALL(a) (a).begin(),(a).end()
#define SORT(c) sort((c).begin(),(c).end())
#define DESCSORT(c) sort(c.begin(), c.end(), greater<int>())

using namespace std;

// N, E, S, W
const int dx[4] = { 1, 0, -1, 0};
const int dy[4] = { 0, 1, 0, -1};

using LL = long long int;
using LD = long double;

const int INF = (1 << 30) - 1;
const LL INF64 = ((LL)1 << 62) - 1;
const double PI = 3.1415926535897932384626433832795;

using pii = pair<int, int>;
using pll = pair<LL, LL>;
using pdd = pair<double, double>;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vl = vector<LL>;
using vvl = vector<vl>;
using vvvl = vector<vvl>;
using vd = vector<double>;
using vs = vector<string>;
using vb = vector<bool>;

//==============================================
int n, e;
vvl M;

void warshallFloyd() {
	REP(k, n) {
		REP(i, n) {
			if (M[i][k] == INF64) continue;
			REP(j, n) {
				if (M[k][j] == INF64) continue;
				M[i][j] = min(M[i][j], M[i][k] + M[k][j]);
			}
		}
	}
}

void print() {
	REP(i, n) {
		if (M[i][i] < 0) {
			cout << "NEGATIVE CYCLE" << "\n";
			return;
		}
	}

	REP(i, n) {
		REP(j, n) {
			if (j) cout << " ";
			if (M[i][j] == INF64) cout << "INF";
			else cout << M[i][j];
		}
		cout << "\n";
	}

}

void solve() {
	warshallFloyd();
	print();
}

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

	cin >> n >> e;

	M.resize(n, vl(n, INF64));
	REP(i, n) M[i][i] = 0;

	LL s, t, d;
	REP(i, e) {
		cin >> s >> t >> d;
		M[s][t] = d;
	}

	solve();
	return 0;
}

#include <iostream>
#include <list>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <algorithm>
#include <cmath>
#include <string>
using namespace std;
typedef long long lli;
typedef vector<lli> vll;
typedef vector<bool> vbl;
typedef vector<vector<lli> > mat;
typedef vector<vector<bool> > matb;
typedef vector<string> vst;
typedef pair<lli,lli> pll;
typedef pair<double,double> pdd;

vll par;
vll rnk;
void init(lli n){
    par = vll(n);
    rnk = vll(n);
    for(lli i = 0;i < n;i++) par[i] = i;
}
lli find(lli x){
    if(par[x] == x) return x;
    else return par[x] = find(par[x]);
}
void unite(lli x,lli y){
    x = find(x);y = find(y);
    if(x == y) return;
    if(rnk[x] < rnk[y]) par[x] = y;
    else {
        par[y] = x;
        if(rnk[x] == rnk[y]) rnk[x]++;
    }
}
bool same(lli x,lli y){
    return find(x) == find(y);
}

lli n;
vll c,r,l;
vll p;
mat g;
lli ans = 0;

int main(){
    cin >> n;
    g = mat(n,vll(n));
    for(lli i = 0;i < n;i++){
        for(lli j = 0;j < n;j++){
            cin >> g[i][j];
        }
    }
    for(lli i = 0;i < n;i++){
        for(lli j = i+1;j < n;j++){
            if(g[i][j] >= 0) c.push_back(g[i][j]),r.push_back(i),l.push_back(j);
        }
    }
    p = vll(c.size());
    for(lli i = 0;i < p.size();i++) p[i] = i;
    sort(p.begin(),p.end(),[](lli a,lli b){
        return c[a] < c[b];
    });
    init(n);
    for(lli i = 0;i < p.size();i++){
        if(!same(r[p[i]],l[p[i]])) unite(r[p[i]],l[p[i]]),ans += c[p[i]];
    }
    cout << ans << endl;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
const int M=1e9+7,N=1<<20;
int n,i,ans,x,f[N],g[N],now,la[N];
inline char gc(){
	static char buf[100000],*p1=buf,*p2=buf;
	return p1==p2&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++;
}
inline int rd(){
	int x=0,fl=1;char ch=gc();
	for(;ch<48||ch>57;ch=gc())if(ch=='-')fl=-1;
	for(;48<=ch&&ch<=57;ch=gc())x=(x<<3)+(x<<1)+(ch^48);
	return x*fl;
}
void inc(int &x,int y){x+=y;if(x>=M)x-=M;}
int main(){
    //freopen("inp","r",stdin);
	n=rd();
	for (i=1;i<N;i++) f[i]=1;
	for (i=ans=1;i<=n;i++){
		x^=rd();
		if (x) inc(f[x],1ll*(now-la[x])*g[x]%M),inc(g[x],f[x]),la[x]=now;
		else inc(ans,ans),now++;
	}
	if (x) return printf("%d",f[x]),0;
	ans=1ll*ans*(M+1>>1)%M;
	for (i=1;i<N;i++) inc(ans,g[i]);
	printf("%d",ans);
}

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<pii,int> ppii;
typedef pair<int,pii> pipi;
typedef pair<ll,ll> pll;
typedef pair<ll,pll> plpl;
typedef tuple<ll,ll,ll> tl;
ll mod=1000000007;
ll inf=1000000000000000000;
#define rep(i,m,n) for(int i=m;i<n;i++)
#define rrep(i,n,m) for(int i=n;i>=m;i--)
ll lmax(ll a,ll b){
    if(a<b)return b;
    else return a;
}
ll lmin(ll a,ll b){
    if(a<b)return a;
    else return b;
}
ll gya[200010];
ll kai[200010];
ll beki(ll n,ll k){
    ll ret=1;
    ll now=n;
    while(k>0){
        if(k%2==1){
            ret*=now;
            ret%=mod;
        }
        now*=now;
        now%=mod;
        k/=2;
    }
    return ret;
}
ll gyaku(ll n){
    return beki(n,mod-2);
}
void nckinit(ll n){
    gya[0]=1;
    gya[1]=1;
    for(int i=2;i<=n;i++){
        gya[i]=gya[i-1]*gyaku(i);
        gya[i]%=mod;
    }
    kai[0]=1;
    kai[1]=1;
    for(int i=2;i<=n;i++){
        kai[i]=kai[i-1]*i;
        kai[i]%=mod;
    }
}
ll nck(ll n,ll k){
    if(k<0)return 0;
    if(k==0||n==k)return 1;
    ll ret=kai[n];
    ret*=gya[n-k];
    ret%=mod;
    ret*=gya[k];
    ret%=mod;
    return ret;
}
ll npk(ll n,ll k){
    if(k<0)return 0;
    if(k==0)return 1;
    ll ret=kai[n];
    ret*=gya[n-k];
    ret%=mod;
    return ret;
}
int main(){

    ll n;cin>>n;
    ll a[n];rep(i,0,n)cin>>a[i];
    ll b[n];
    b[0]=a[0];
    rep(i,1,n)b[i]=b[i-1]^a[i];
    vector<ll> w;
    rep(i,0,n)w.push_back(b[i]);
    sort(w.begin(),w.end());
    w.erase(unique(w.begin(),w.end()),w.end());
    unordered_map<ll,ll> mp;
    rep(i,0,w.size()){
        if(w[i]==0)mp[w[i]]=0;
        else mp[w[i]]=i+1;
    }
    rep(i,0,n)b[i]=mp[b[i]];
    ll m=w.size();
    vector<ll> v[m+2];
    rep(i,0,n){

        v[b[i]].push_back(i);
    }
    //rep(i,0,n)cout<<b[i]<<" ";
    bool used[m+2];
    ll ans=0;
    fill(used,used+m+2,false);
    rep(i,0,n-1){
        //cout<<ans<<" ";
        if(used[b[i]])continue;
        if(b[i]==0&&b[n-1]==0){
            ll y=beki(2,v[0].size()-1);
            y--;
            y=(y+mod)%mod;
            ans+=y;
            ans%=mod;
            used[0]=true;
            continue;
        }
        if(b[n-1]!=0&&b[i]!=b[n-1])continue;
        used[b[i]]=true;
            ll jou=1,ka=1;
            ll now=lower_bound(v[0].begin(),v[0].end(),i)-v[0].begin();
        //cout<<now<<endl;
            rep(j,1,v[b[i]].size()){
                ll ne=v[b[i]][j];
                ll r=lower_bound(v[0].begin(),v[0].end(),ne)-v[0].begin();
                jou+=ka*(r-now);
                jou%=mod;
                ka+=jou;
                ka%=mod;
                now=r;
            }
        if(b[n-1]==b[i]){
            ans=(ans+jou-1+mod)%mod;
            continue;
        }
        if(v[b[i]].size()==1){
            ans=(ans+1)%mod;
            continue;
        }
        ans=(ans+ka)%mod;

    }
    ans=(ans+1)%mod;
    cout<<ans<<endl;
}


#include <stdio.h>
#include <math.h>
#define MAXINPUT 100

int main(void){
	int h[MAXINPUT],w[MAXINPUT];
	int ansh[MAXINPUT]={},answ[MAXINPUT]={};
	int i=0,j=0;
	int ans=0;
	int num=0;
	int k;
	while(i<MAXINPUT){
		scanf("%d %d",&h[i],&w[i]);
		if(h[i]==0 && w[i]==0)break;
		i++;
		num++;
	}

	for(i=0;i<num;i++,ans=0){
		ans=h[i]*h[i]+w[i]*w[i];
		for(;(ansh[i]==0||answ[i]==0);){
			for(j=1;k==0;j++){
				double temp=ans-(j*j);
				double tempa=0;
				if(temp<=0){
					k=1;
					break;
				}
				temp=sqrt(temp);
				temp=modf(temp,&tempa);
				if(temp==0 && tempa<=150 && j<tempa){
					if(tempa*tempa+j*j==h[i]*h[i]+w[i]*w[i] && j<=h[i]){
						continue;
					}
					ansh[i]=j;
					answ[i]=(int)tempa;
					printf("%d %d\n",ansh[i],answ[i]);
					break;
				}
			}
		ans++;
		k=0;
		}
	}

	return 0;
}

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

#define REP(i,s,n) for(int i=s;i<n;++i)
#define rep(i,n) REP(i,0,n)
#define SORT(c) sort((c).begin(),(c).end())
#define IINF INT_MAX
#define LLINF LLONG_MAX
#define DEBUG false

typedef long long ll;
typedef pair<int, int> ii;

#define MAXI 1000000

struct NODE{
	int h, w;
	NODE(){h = w = 0;}
	NODE(int h, int w): h(h), w(w){}

	bool operator<(const NODE r){
		if(h * h + w * w != r.h * r.h + r.w * r.w) return h * h + w * w < r.h * r.h + r.w * r.w;
		return h < r.h;
	}

};

int main() {

	vector<NODE> vec;
	REP(i, 1, 151){
		REP(j, i+1, 151){
			vec.push_back(NODE(i, j));
		}
	}

	SORT(vec);

	int h, w;
	while(cin >> h >> w, h, w){
		int num = 0;
		while(vec[num].h != h || vec[num].w != w) num++;
		cout << vec[num+1].h << " " << vec[num+1].w << endl;
	}

	return 0;
}


#include <bits/stdc++.h>
using namespace std;
int main() {
    long long n, x;
    cin >> n >> x;
    long long a[n], c = 0;
    for (long long i = 0; i < n; i++)
    {
        cin >> a[i];
        if (a[i] > x)
        {
            c += a[i] - x;
            a[i] = x;
        }
    }
    for (long long i = 1; i < n; i++)
    {
        if (a[i] + a[i - 1] > x)
        {
            c += a[i] + a[i - 1] - x;
            a[i] = x - a[i - 1];
        }
    }
    cout << c;
}

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

int main(){
  int n;
  cin >> n;
  string s;
  cin >> s;
  int w = 0, e = 0;
  int ans[n];
  rep(i,n)ans[i] = 0;
  rep(i,n){
    ans[i] = w;
    if(s[i]=='W')w++;
  }
  rep(i,n){
    ans[n-1-i] += e;
    if(s[n-1-i]=='E')e++;
  }
  int minans = INF;
  rep(i,n)if(minans > ans[i]) minans = ans[i];
  cout << minans << endl;
  return 0;
}


#include <bits/stdc++.h>
#define fi first
#define se second
#define pii pair<int,int>
#define mp make_pair
#define pb push_back
#define space putchar(' ')
#define enter putchar('\n')
#define eps 1e-10
#define MAXN 200005
//#define ivorysi
using namespace std;
typedef long long int64;
typedef unsigned int u32;
typedef double db;
template<class T>
void read(T &res) {
    res = 0;T f = 1;char c = getchar();
    while(c < '0' || c > '9') {
	if(c == '-') f = -1;
	c = getchar();
    }
    while(c >= '0' && c <= '9') {
	res = res * 10 +c - '0';
	c = getchar();
    }
    res *= f;
}
template<class T>
void out(T x) {
    if(x < 0) {x = -x;putchar('-');}
    if(x >= 10) {
	out(x / 10);
    }
    putchar('0' + x % 10);
}
map<pii,int> zz;
int N,K,L;
int fa[MAXN],col[MAXN][2],tot;
int getfa(int x) {
    return fa[x] == x ? x : fa[x] = getfa(fa[x]);
}
void Solve() {
    read(N);read(K);read(L);
    for(int i = 1 ; i <= N ; ++i) fa[i] = i;
    int a,b;
    for(int i = 1 ; i <= K ; ++i) {
	read(a);read(b);
	fa[getfa(a)] = getfa(b);
    }
    tot = 0;
    for(int i = 1 ; i <= N ; ++i) {
	if(getfa(i) == i) col[i][0] = ++tot;
    }
    for(int i = 1 ; i <= N ; ++i) col[i][0] = col[getfa(i)][0];
    for(int i = 1 ; i <= N ; ++i) fa[i] = i;
    for(int i = 1 ; i <= L ; ++i) {
	read(a);read(b);
	fa[getfa(a)] = getfa(b);
    }
    tot = 0;
    for(int i = 1 ; i <= N ; ++i) {
	if(getfa(i) == i) col[i][1] = ++tot;
    }
    for(int i = 1 ; i <= N ; ++i) col[i][1] = col[getfa(i)][1];
    for(int i = 1 ; i <= N ; ++i) {
	zz[mp(col[i][0],col[i][1])]++;
    }
    for(int i = 1 ; i <= N ; ++i) {
	out(zz[mp(col[i][0],col[i][1])]);space;
    }
    enter;
}
int main() {
#ifdef ivorysi
    freopen("f1.in","r",stdin);
#endif
    Solve();
    return 0;
}

#define NguyenDangQuan the_author

#include <bits/stdc++.h>
#define all(x) x.begin(),x.end()
#define mset(x, i) memset(x,i,sizeof(x))
#define elif else if
#define heap priority_queue
#define fi first
#define se second
#define pb push_back
#define ld long double
#define ll long long
#define ull unsigned long long
#define task "codejam"
using namespace std;

int typetest;
template<class T>
void read(T &x){
    register int c;
    T neg = 1;
    x = (T)0;
    while ((c = getchar()) <= 47 || c >= 58)
		if(c == '-') neg = -1;
    for (; (c > 47 && c < 58); c = getchar()){
        x = (x << 3) + (x << 1) + (T)(c - 48);
    }
	x *= neg;
}
inline void fastIOfileinput(){
	ios:: sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
//	freopen(task".INP", "r", stdin);
//	freopen(task".OUT", "w", stdout);
//	freopen(task".in", "r", stdin);
//	freopen(task".out", "w", stdout);
	typetest = 0;
}

const int N = 2e5 + 2;
int m, n, k;
vector<int> ker[N], kel[N];
int ltr[N], ltl[N];

void Enter(){
	read(n); read(m); read(k);
	while(m--){
		int a, b;
		read(a); read(b);
		ker[a].pb(b);
		ker[b].pb(a);
	}
	while(k--){
		int a, b;
		read(a); read(b);
		kel[a].pb(b);
		kel[b].pb(a);
	}
}

void BFS(int i, int lt[], vector<int> ke[]){
	++m;
	lt[i] = m;
	queue<int> open;
	open.push(i);
	while(open.size()){
		int c = open.front();
		open.pop();
		for(auto i : ke[c]){
			if((!lt[i]))
				open.push(i), lt[i] = m;
		}
	}
}

void solve(){
	m = 0;
	for(int i = 1; i <= n; ++i)
		if(ltr[i] == 0)
			BFS(i, ltr, ker);
	m = 0;
	for(int i = 1; i <= n; ++i)
		if(ltl[i] == 0)
			BFS(i, ltl, kel);
	map<int, map<int, int> > s;
	for(int i = 1; i <= n; ++i){
		++s[ltr[i]][ltl[i]];
//		cerr << ltr[i] << " " << ltl[i] << "\n";
	}
	for(int i = 1; i <= n; ++i){
		int& v = s[ltr[i]][ltl[i]];
		cout << v << " ";
	}
}

signed main(){
	fastIOfileinput();
	if(typetest){
		int t;
		cin >> t;
		int v = t;
		while(t--){
			Enter();
			cout << "Case #" << v - t << ": ";
			solve();
		}
	}
	else{
		Enter();
		solve();
	}
}


#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdio>
#define N 45
#define mod 1000000007
using namespace std;

int n, x, y, z, f[N][(1 << 17) + 5], ans;

template < typename T >
inline T read()
{
	T x = 0, w = 1; char c = getchar();
	while(c < '0' || c > '9') { if(c == '-') w = -1; c = getchar(); }
	while(c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
	return x * w;
}

int main()
{
	n = read <int> (), x = read <int> (), y = read <int> (), z = read <int> ();
	ans = 1;
	for(int i = 1; i <= n; i++)
		ans = 1ll * ans * 10 % mod;
	int sz = (1 << (x + y + z)) - 1, ck = (1 << (x + y + z - 1)) | (1 << (y + z - 1)) | (1 << (z - 1));
	f[0][0] = 1;
	for(int i = 1; i <= n; i++)
		for(int j = 0; j <= sz; j++)
			if(f[i - 1][j])
			{
				for(int k = 1; k <= 10; k++)
				{
					int tmp = (j << k) | (1 << (k - 1));
					tmp &= sz;
					if((tmp & ck) != ck) f[i][tmp] = (1ll * f[i][tmp] + f[i - 1][j]) % mod;
				}
			}
	for(int j = 0; j <= sz; j++)
		ans = ((1ll * ans - f[n][j]) % mod + mod) % mod;
	printf("%d\n", ans);
	return 0;
}


#include <stdio.h>
#define MAX 200000

using namespace std;
int temp[MAX];

long long merge(int A[], int lo, int mid, int hi) {
    for(int i = lo; i <= hi; i++) temp[i] = A[i];
    long long cnt = 0;
    int i = lo, j = mid + 1;
    for(int k = lo; k <= hi; k++) {
        if(i > mid) A[k] = temp[j++];
        else if(j > hi) A[k] = temp[i++];
        else if(temp[i] <= temp[j]) A[k] = temp[i++];
        else {
            A[k] = temp[j++];
            cnt = cnt + mid+1 - i;
        }
    }
    return cnt;
}

long long mergeSort(int A[], int lo, int hi) {
    if(lo >= hi) return 0;
    long long v1, v2, v3;
    int mid = (lo + hi) / 2;
    v1 = mergeSort(A, lo, mid);
    v2 = mergeSort(A, mid+1, hi);
    v3 = merge(A, lo, mid, hi);
    return v1 + v2 + v3;
}

int main()
{
    int n, A[MAX];
    scanf("%d", &n);
    for(int i = 0; i < n; i++) {
        scanf("%d", &A[i]);
    }
    long long res = mergeSort(A, 0, n-1);
    printf("%lld\n", res);

    return 0;
}


#include<cstdio>
#include<algorithm>
using namespace std;
long long Mod = 998244353, F[10100], InvF[10100], po[10100];
long long Pow(long long a, long long b) {
	long long r = 1;
	while (b) {
		if (b & 1)r = r*a%Mod;
		a = a*a%Mod; b >>= 1;
	}
	return r;
}
long long Comb(int a, int b) {
	if (a >= b&&b >= 0)return F[a] * InvF[b] % Mod*InvF[a - b] % Mod;
	return 0;
}
long long Get(int a, int b) {
	return Comb(a + b - 1, b);
}
long long Go(int n, int p, int c) {
	if (n == 0)return 1;
	int i;
	long long r = 0;
	for (i = 0; i <= p; i++) {
		if (n < i)continue;
		r = (r + Get(i + c, n - i) * Comb(p,i)%Mod * po[i]) % Mod;
	}
	return r;
}
int main() {
	int i, n, K;
	scanf("%d%d", &K,&n);
	F[0] = InvF[0] =po[0] = 1;
	for (i = 1; i <= 10000; i++) {
		F[i] = F[i - 1] * i%Mod;
		InvF[i] = Pow(F[i], Mod - 2);
		po[i] = po[i - 1] * 2 % Mod;
	}
	for (i = 2; i <= K + K; i++) {
		if (i % 2 == 0) {
			long long t = min(i - 1, K + K + 1 - i);
			printf("%lld\n",(Go(n, t / 2, K - t) + Go(n - 1, t / 2, K - t)) % Mod);
		}
		else {
			long long t = min(i - 1, K + K + 1 - i);
			printf("%lld\n",Go(n, t / 2, K - t));
		}
	}

}

#include <bits/stdc++.h>

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

using namespace std;

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

const int MX = 5005, mod = 998244353;
ll fac[MX], inv[MX];
int n, k;

ll pot (ll b, int p) {
	ll res = 1;
	while (p) {
		if (p & 1) (res *= b) %= mod;
		(b *= b) %= mod;
		p >>= 1;
	}
	return res;
}

ll comb (int n, int k) {
	if (n < 0 || k < 0 || n < k) return 0;
	return fac[n] * inv[k] % mod * inv[n-k] % mod;
}

// n espacios, k numeros
ll f (int n, int k) {
	if (!n) return 1;
	return comb(n + k - 1, n);
}

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

	fac[0] = inv[0] = 1;
	for (ll i = 1; i < MX; i++) {
		fac[i] = i * fac[i-1] % mod;
		inv[i] = pot(fac[i], mod - 2);
	}

	cin >> k >> n;
	for (int i = 2; i <= 2 * k; i++) {
		ll res = 0;
		int a = 0, b = 0, mit = 0;

		for (int j = 1; j <= k; j++) {
			if (2 * j == i) mit = 1;
			else if (1 <= i - j && i - j <= k) a++;
			else b++;
		}

		a /= 2;

		for (int j = 0; j <= a; j++) {
			res += comb(a, j) * pot(2, j) % mod *
				(f(n - j, j + b) + mit * f(n - j - 1, j + b)) % mod;
			res %= mod;
		}

		cout << res << endl;
	}

	return 0;
}


#include <bits/stdc++.h>
using namespace std;
///////////////////////////////////////////
const long long int INF = 1LL<<60;
const long long int Mod = 1000000007;
using ll = long long int; using ci = const int;
using vi = vector<int>;  using Vi = vector<long long int>;
using P = pair<int, int>;  using PLL = pair<ll, ll>;
using matrix = vector<vector<ll>>;
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define all(x) (x).begin(),(x).end()
#define rp(i,N) for(ll i = 0; i < (ll)N; i++)
#define repi(i,a,b) for(ll i = ll(a); i < ll(b); ++i)
template<class T>bool chmax(T &former, const T &b) { if (former<b) { former=b; return true; } return false; }
template<class T>bool chmin(T &former, const T &b) { if (b<former) { former=b; return true; } return false; }
template<class T>T sqar(T x){ return x*x; }//sqrt(x)は平方根;
#define Sort(v) std::sort(v.begin(), v.end(), std::greater<decltype(v[0])>()) //降順でVをソート
#define p_queue(v) priority_queue<v, vector<v>, greater<v> >
template<class T> inline void princ(T x){cout<<x<<" ";};
template<class T> inline void print(T x){cout<<x<<"\n";};
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
///////////////////////////////////////////////////////////////////////////////////

void solve(){
    ll n;
    cin >> n;
    Vi a(n);
    rp(i,n){
        string s;
        cin >> s;
        int si=s.size();
        bool point=false;
        int num=0;
        rp(j,si){
            if(s[j]=='.') {
                point=true;
                num=si-j-1;
                continue;
            }
            if(point){
                s[j-1]=s[j];
            }
        }
        if(point) s[si-1]='0';
        ll aa=stoll(s);
        if(!point) aa*=1000000000;
        else{
            rp(j,9-num-1)aa*=10;
            if(num==9) aa/=10;
        }
        a[i]=aa;
    }
    matrix mat(19,Vi(19,0)),summat(19,Vi(19,0));
    rp(i,n){
        ll t=0,f=0;
        ll as=a[i];
        while(as%2==0){
            as/=2;
            t++;
        }
        while(as%5==0){
            as/=5;
            f++;
        }
        if(t>18)t=18;
        if(f>18)f=18;
        mat[t][f]++;
    }
    for(ll i=18; i>=0; i--){
        for(ll j=18; j>=0; j--){
            if(i==18&&j==18){
                summat[i][j]=mat[i][j];
                continue;
            }
            if(i==18){
                summat[i][j]=summat[i][j+1]+mat[i][j];
                continue;
            }
            if(j==18){
                summat[i][j]=summat[i+1][j]+mat[i][j];
                continue;
            }
            summat[i][j]=summat[i+1][j]+summat[i][j+1]-summat[i+1][j+1]+mat[i][j];
        }
    }
    ll ans=0;
    rp(i,19){
        rp(j,19){
            if(i>=9&&j>=9){
                ans+=mat[i][j]*(summat[18-i][18-j]-1);
                continue;
            }
            ans+=mat[i][j]*summat[18-i][18-j];
        }
    }
    ans/=2;
    print(ans);
    return;
}
int main(){
    cin.tie(0);ios::sync_with_stdio(false);
    std::cout<<std::fixed<<std::setprecision(30);
    solve();
    return 0;
}

#pragma GCC optimize(2)
#include<bits/stdc++.h>
#define ll long long
#define maxn 2000005
#define inf 1e9
#define pb push_back
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define per(i,a,b) for(int i=a;i>=b;i--)
using namespace std;

ll n,a[maxn],b[maxn],c[maxn];

inline ll read()
{
	ll x=0,w=1,x2=0,base=1e9; char c=getchar();
	while(c<'0'||c>'9') c=getchar();
	while(c<='9'&&c>='0') {x=(x<<1)+(x<<3)+c-'0'; c=getchar();}
	if(c=='.')
	{
		while(c<'0'||c>'9') c=getchar();
		while(c<='9'&&c>='0') {x2=(x2<<1)+(x2<<3)+c-'0'; base/=10; c=getchar();}
		return x*1e9+x2*base;
	}
	else return x*1e9;
}

ll dp[55][55];

int main()
{
	ll n,ans=0; cin>>n; rep(i,1,n) a[i]=read();
	rep(i,1,n)
	{
		int c1=0,c2=0;
		while(a[i]%2==0) a[i]/=2,c1++; c1=min(18,c1);
		while(a[i]%5==0) a[i]/=5,c2++; c2=min(18,c2);
		rep(j,18-c1,50) rep(k,18-c2,50) ans+=dp[j][k];
		dp[c1][c2]++;
	}
	cout<<ans<<endl;
	return 0;
}


#include<iostream>
#include<string>

using namespace std;

typedef long long ll;

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

	int q;
	cin >> q;
	while (q--) {
		int k;
		cin >> k;

		ll ans = 0;
		ll cm = 0, cc = 0;
		int left = 0, right = 0;
		ll plus = 0;
		for (; left < n; left++) {
			while (right < n && right - left < k) {
				if (s[right] == 'M')cm++;
				if (s[right] == 'C')plus += cm, cc++;
				right++;
			}

			if (s[left] == 'D')ans += plus;

			if (s[left] == 'M')plus -= cc, cm--;
			if (s[left] == 'C')cc--;
		}
		cout << ans << endl;
	}

	return 0;
}

#include<iostream>
#include<algorithm>
using namespace std;
/*
void swap(int &a,int &b){
	int tmp=a;
	a=b;
	b=tmp;
}*/

int partition(int A[],int p,int r){

	int x=A[r-1];
	int i=p-1;

	for(int j=p;j<r;j++){
		if(A[j]<=x){
			i++;
		if(i>=0&&j>=0)
		swap(A[i],A[j]);
		}
		//swap(A[i],A[r-1]);
	}

	//swap(A[i],A[r-1]);
	return i;

}

int main(){
	int tmp[1000000];
	int n;
	cin>>n;

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

	int q;

	q=partition(tmp,0,n);

	for(int i=0;i<n;i++){

		if(i==q){
			cout<<"["<<tmp[i]<<"]";
		}

		else cout<<tmp[i];

		if(i==n-1)cout<<endl;
		else cout<<" ";
	}

	return 0;
}


#include<stdio.h>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<vector>
#include<map>
#include<set>
#include<cmath>
#include<iostream>
#include<queue>
#include<string>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef long double ld;
typedef unsigned long long ull;
typedef pair<long long,long long> pll;
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define rep(i,j,k)  for(register int i=(int)(j);i<=(int)(k);i++)
#define rrep(i,j,k) for(register int i=(int)(j);i>=(int)(k);i--)

ll read(){
	ll x=0,f=1;char c=getchar();
	while(c<'0' || c>'9'){if(c=='-')f=-1;c=getchar();}
	while(c>='0' && c<='9'){x=x*10+c-'0';c=getchar();}
	return x*f;
}

const int maxn=200;
int n,m;
int a[maxn];

int main(){
#ifdef LZT
//	freopen("in","r",stdin);
#endif
	int num=0;
	n=read();m=read();
	rep(i,1,m){
		a[i]=read();
		if(a[i]&1) num++;
	}
	if(num>2){
		puts("Impossible");
		return 0;
	}
	for(int i=1;i<=m;i++)
		if(a[i]&1){
			if(a[1]&1) swap(a[i],a[m]);
			else swap(a[i],a[1]);
		}
	rep(i,1,m) cout<<a[i]<<' ';
	cout<<endl;
	a[1]++;a[m]--;
	if(a[m]==0) m--;
	if(m>=2){
		cout<<m<<endl;
		rep(i,1,m) cout<<a[i]<<' ';
		cout<<endl;
	}
	else{
		if(n<=2){
			cout<<1<<endl;
			cout<<n<<endl;
		}
		else{
			cout<<2<<endl;
			cout<<n-1<<' '<<1<<endl;
		}
	}
	return 0;
}


// lcmとか__builtin_popcountとかはg++ -std=c++17 default.cppみたいなかんじで

#include <bits/stdc++.h>
#define mod 1000000007
#define INF LLONG_MAX
#define ll long long
#define ln cout<<endl
#define Yes cout<<"Yes"<<endl
#define NO cout<<"NO"<<endl
#define YES cout<<"YES"<<endl
#define No cout<<"No"<<endl
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
using namespace std;
ll dx[4]={1,0,-1,0};
ll dy[4]={0,1,0,-1};

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

    ll  a,b,c,d,e,n,k,maxi=0,f=0,mini=INF,sum=0,q;
	string str,stra,straa;
    ll x,y,w,z;
    char ca,cb,cc;
    cin>>a>>b;
    cout<<max(a+b,max(a-b,a*b))<<endl;
    return 0;
}

#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define reps(i,s,n) for(int i=(s); i<(n); i++)
#define all(v) v.begin(),v.end()
#define outve(v) for(auto i : v) cout << i << " ";cout << endl
#define outmat(v) for(auto i : v){for(auto j : i) cout << j << " ";cout << endl;}
#define in(n,v) for(int i=0; i<(n); i++){cin >> v[i];}
#define out(n) cout << (n) << endl
#define fi first
#define se second
#define pb push_back
#define mod 1000000007
#define infi 1900000000
#define infl 1100000000000000000
#define cyes cout << "Yes" << endl
#define cno cout << "No" << endl
#define csp << " " <<
#define outset(n) cout << fixed << setprecision(n);
using namespace std;
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
template<typename T> using ve = vector<T>;
template<typename T> using pq2 = priority_queue<T>;
template<typename T> using pq1 = priority_queue<T,vector<T>,greater<T>>;

int main()
{
    int N;
    cin >> N;
    cout << 180*((N-3)+1) << endl;

    return 0;
}


// lcmとかはg++ -std=c++17 default.cppみたいなかんじで
#include <bits/stdc++.h>
#define mod 1000000007
#define INF 1001001001
#define ll long long
#define ln cout<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl
//#define double long double
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
#define rep1(i,n) REP(i,1,n+1)
using namespace std;

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

    ll a,b,c,n,maxi=0,f=0,mini=INF;
    ll sum=0;
    string str,sub;
    ll h,w;
    ll m;
    cin>>n>>m;
    if(m==0){
        if(n==1){
            cout<<0<<endl;
        }else if(n==2){
            cout<<10<<endl;
        }else{
            cout<<100<<endl;
        }
        return 0;
    }
    vector<pair<ll,ll>> s(m);

    rep(i,m){
        cin>>a>>b;
        s[i]=make_pair(a,b);
    }
    f=0;
    sort(s.begin(),s.end());
    sum=0;
            if(s[0].first==1) {
                //sum-=100;
                if(s[0].second==0&&n!=1) f=1;

                sum+=100*s[0].second;
            }
            if(s[0].first==2){
                //if(s[0].second==0&&n==2) f=1;

                sum+=10*s[0].second;
               // sum-=10;
            }
            if(s[0].first==3){
                //sum-=1;
                sum+=1*s[0].second;
            }
    for(ll i=1;i<m;i++){
        if(s[i-1].first==s[i].first&&s[i-1].second!=s[i].second) f=1;
        else if(s[i-1].first==s[i].first&&s[i-1].second==s[i].second) continue;
        else{
            if(s[i].first==1) {
               // sum-=100;
               if(s[i].second==0&&n!=1) f=1;
                sum+=100*s[i].second;
            }
            if(s[i].first==2) {
               // sum-=10;
                sum+=10*s[i].second;
            }
            if(s[i].first==3) {
              //  sum--;
                sum+=1*s[i].second;
            }
        }
    }
    if(n==1&&sum!=0) sum/=100;
    if(n==2&&sum!=0) sum/=10;
    if(n==3&&sum!=0&&sum<100) sum+=100;
    if(n==2&&sum<10) sum+=10;
    if(f!=1&&sum==0&&n==1){
        cout<<0<<endl;
        return 0;
    }

    if(f==1){
        cout<<"-1"<<endl;
    }else{
        cout<<sum<<endl;
    }
    return 0;
}

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

int main() {
  int n,m;cin>>n>>m;
  vector<pair<int,int>> pr(m);
  rep(i,m){
    int s,c;cin>>s>>c;
    s--;
    pr[i]=make_pair(s,c);
  }
  rep(i,1000){
    string s=to_string(i);
    if(s.size()==n){
      bool ans=true;
      rep(j,m){
        if((s[pr[j].first]-'0')!=pr[j].second)ans=false;
      }
      if(ans){
        cout<<i<<endl;
        return 0;
      }
    }
  }
  cout<<-1<<endl;
}


#include <stdio.h>
#include <string.h>

void shift(char *str, int len, int n){
	char t[] = "abcdefghijklmnopqrstuvwxyz";
	char c;
	for(int i=0; i<len; ++i){
		c = *(str + i);
		if(c >= 'a' && c <= 'z'){
			str[i] = t[(c-'a'+n)%26];
		}
	}
}

int main(void){
	char input[81];
	char copy[81];
	char *token;
	int len = 0;
	int n = 0;

	while(fgets(input, 80, stdin) != NULL){
		n = -1;
		strcpy(copy, input);

		token = strtok(copy, " .\n");
		while(token != NULL && n == -1){
			len = strlen(token);
			if(len == 4){
				for(int i=0;i<26; ++i){
					shift(token, 4, 1);
					if(strcmp(token, "this")==0 ||
						strcmp(token, "that")==0){
						n = i + 1;
						break;
					}
				}
			}else if(len ==3){
				for(int i=0;i<26; ++i){
					shift(token, 3, 1);
					if(strcmp(token, "the")==0){
						n = i + 1;
						break;
					}
				}
			}
			token = strtok(NULL, " .\n");
		}
		shift(input, strlen(input), n);
		printf(input);
	}
	return 0;
}

#include <bits/stdc++.h>

using namespace std;

int main() {
  string str;
  while (getline(cin, str)) {
    for (int i = 0; i < 26; ++i) {
      for (char& c : str) {
        if (isalpha(c)) {
          if (c != 'z') ++c;
          else c = 'a';
        }
      }
      if (str.find("that") != string::npos || str.find("this") != string::npos || str.find("the") != string::npos) {
        cout << str << endl;
      }
    }
  }
}


#include<cstdio>
void swap(int &x,int &y)
{
	int t=x;
	x=y;
	y=t;
	return ;
}
int main()
{
	int a,b,c;
	while(~scanf("%d %d %d",&a,&b,&c))
	{
		int t;
		swap(a,b);
		swap(a,c);
		printf("%d %d %d\n",a,b,c);
	}
	return 0;
}

#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
#include <queue>
#include <set>
#include <map>
#include <iomanip>
#include <fstream>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int mod = 1000000007;

vector<string> a;

bool cmp(string s, string t) {
    if (s.length() != t.length()) return s.length() < t.length();
    return s < t;
}

void sol(string s) {
    a.push_back(s);
    if (s.length() == 10) return;
    if (s.back() != '0') {
        s += (s.back() - 1);
        sol(s);
        s.pop_back();
    }
    s += (s.back());
    sol(s);
    s.pop_back();
    if (s.back() != '9') {
        s += (s.back() + 1);
        sol(s);
        s.pop_back();
    }
}

int main() {
    ios::sync_with_stdio(false);
    int a, b, c;
    cin >> a >> b >> c;
    cout << c << ' ' << a << ' ' << b;
}


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

int main() {
  int n, k;
  cin >> n >> k;
  if (n % k == 0)
    cout << 0 << endl;
  else
    cout << 1 << endl;
}

#pragma GCC optimize(3,"Ofast","inline")
#pragma GCC target("avx")
#include <bits/stdc++.h>
using namespace std;
#ifdef ONLINE_JUDGE
#define getchar gc
inline char gc(){
	static char buf[1<<16],*p1=buf,*p2=buf;
	if(p1==p2){
		p2=(p1=buf)+fread(buf,1,1<<16,stdin);
		if(p2==p1) return EOF;
	}
	return *p1++;
}
#endif
template<class t> inline t read(t &x){
    char c=getchar();bool f=0;x=0;
    while(!isdigit(c)) f|=c=='-',c=getchar();
    while(isdigit(c)) x=(x<<1)+(x<<3)+(c^48),c=getchar();
    if(f) x=-x;return x;
}
template<class t> inline void write(t x){
    if(x<0) putchar('-'),write(-x);
    else{if(x>9) write(x/10);putchar('0'+x%10);}
}

int n,k;

signed main(){
	read(n);read(k);
	for(int i=1,l=1,r=k+1;i<=k;i++){
		if(l>=r) l=k+2,r=k<<1|1;
		printf("%d %d\n",l++,r--);
	}
}


#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_poizcy.hpp>
typedef long long  ll;
#define pb                push_back
#define mp                make_pair
#define all(a)            (a).begin(), (a).end()
#define clr(a,h)          memset(a, (h), sizeof(a))
#define mem(a,h)          memset(a, (h), sizeof(a))
#define fi first
#define se second
#define por(a,b) (((a%MOD) * (b%MOD))%MOD)
#define forg(i, b, e, c)    for (ll i = (ll)b; i < (ll)e; i+=c)
#define forr(i, b, e)    for (ll i = b; i < e; i++)

using namespace std;
//using namespace __gnu_pbds;
typedef double lldb;
typedef pair<ll, ll>  ii;
typedef pair<double, double>  iidb;
typedef pair<ii, ll>  iii;
typedef vector<ll>     vi;
typedef vector<vi>     vvi;
typedef vector<ii>      vii;
typedef vector<ll>      vll;
//typedef tree<ii,null_type,less<ii>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
const ll INF = 1e18+7;
const double PI = acos(-1);
const ll MOD= 1e9+7;
#define initseg ll new_nodo=(nodo*2),mid=(iz+der)/2;

//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define tam 210000
#define offset 200
#define ptr nodo*

map<ll,vector<iii> > chocarx,chocary,flechader,flechaiz,flechader2,flechaiz2;
vector<pair<ii,string> >lst,lst2;
ll ANSWER;
void update(ii par1, ii par2)
{
	if (par1.fi==INF|| par2.fi==INF)return;
	ll dist=abs(par1.fi-par2.fi)+abs(par1.se-par2.se);
	ANSWER=min(ANSWER,dist*5);
}
void resolver1(map<ll,vector<iii> > & mapa)
{
	//<<"mira \n";
	for(auto ite:mapa)
	{
		sort(all(ite.se));
		ii actant={INF,INF};
		//<<ite.fi<<":\n";
		for(iii par:ite.second)
		{
			//<<par.fi.fi<<","<<par.fi.se<<" "<<par.se<<" - ";
			if (par.se==1)
			{
				actant=par.fi;
			}
			else
			{
				update(par.fi,actant);
			}
		}
		//<<endl;

	}
}
void resolver2(map<ll,vector<iii> > & mapa)
{
	for(auto ite:mapa)
	{
		sort(all(ite.se));
		ii actant={INF,INF};
		for(iii par:ite.second)
		{
			if (par.se==1)
			{
				actant=par.fi;
			}
			else
			{
				update(par.fi,actant);
			}
		}
	}
}
void solve(vector<pair<ii,string> >este)
{
	ll x,y;
	string tipo;
	chocarx.clear(),chocary.clear(),flechaiz.clear(),flechader.clear();
	flechaiz2.clear(),flechader2.clear();
	for(auto par:este)
	{
		x=par.fi.fi;
		y=par.fi.se;
		tipo=par.se;
		if (tipo=="U" || tipo=="D")
		chocarx[x].pb({{y,x},tipo=="U"});
		else
		chocary[y].pb({{y,x},tipo=="R"});

		if (tipo=="D"|| tipo=="U")
		{
			if (tipo=="U"){
				flechader[x-y].pb({{y,x},tipo=="U"});
				flechaiz[x+y].pb({{y,x},tipo=="U"});
			}
			else
			{
				flechader2[x-y].pb({{y,x},0});
				flechaiz2[x+y].pb({{y,x},0});
			}
		}
		else
		{
			if (tipo=="L")
			{
				flechader[x-y].pb({{y,x},tipo=="U"});
				flechaiz2[x+y].pb({{y,x},1});
			}
			else
			{
				flechaiz[x+y].pb({{y,x},tipo=="U"});
				flechader2[x-y].pb({{y,x},1});
			}
		}
	}

	resolver1(chocarx);
	resolver1(chocary);

	resolver1(flechaiz);
	resolver1(flechader);

	resolver1(flechaiz2);
	resolver1(flechader2);
}
int main()
{
	ANSWER=INF;
	ll n;
	cin>>n;
	ll x,y;
	string tipo;
	map<string,string> inv;
	inv["L"]="R";inv["R"]="L";inv["U"]="D";inv["D"]="U";
	forr(i,0,n)
	{
		cin>>x>>y>>tipo;
		lst.pb({{x,y},tipo});
		lst2.pb({{x,y},inv[tipo]});
	}
	solve(lst);
	//solve(lst2);
	if (ANSWER==INF)
		cout<<"SAFE\n";
	else
		cout<<ANSWER<<endl;
}

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

using namespace std;

#define dump(n) cout<<"# "<<#n<<"="<<(n)<<endl
#define debug(n) cout<<__FILE__<<","<<__LINE__<<": #"<<#n<<"="<<(n)<<endl
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,n) repi(i,0,n)
#define iter(c) __typeof((c).begin())
#define tr(c,i) for(iter(c) i=(c).begin();i!=(c).end();i++)
#define allof(c) (c).begin(),(c).end()
#define mp make_pair

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int,int> pii;

string replace(string s,char table[])
{
	rep(i,s.size())
		if(islower(s[i]))
			s[i]=table[s[i]-'a'];
	return s;
}

int main()
{
	for(string s;getline(cin,s);){
		char table[]="abcdefghijklmnopqrstuvwxyz";
		rep(i,26){
			string s2=" "+s+" ";
			rep(i,s2.size())
				if(s2[i]=='.' || s2[i]=='\n')
					s2[i]=' ';
			s2=replace(s2,table);
			if(s2.find(" the ")!=string::npos || s2.find(" this ")!=string::npos ||s2.find(" that ")!=string::npos){
				cout<<replace(s,table)<<endl;
				break;
			}
			rotate(table,table+1,table+26);
		}
	}

	return 0;
}


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

int main() {
  string S;
  cin >> S;
  vector<int> v(4);
  for(int i = 0; i < 4; i++){
    v.at(i) = (int)S.at(i) - (int)'0';
  }

  bool finish = false;

  for (int tmp = 0; tmp < (1 << 3); tmp++){
    if(finish) break;
    bitset<3> s(tmp);
    int test = v.at(0);
    int sign = 1;
    string op = "+++";
    for(int i = 0; i < 3; i++){
      if(s.test(i)){
        sign = -1;
        op.at(i)='-';
      }else{
        sign = 1;
      }
      test += sign * v.at(i+1);
    }
    if(test == 7){
      for(int i=0; i<3;i++){
        cout << v.at(i) << op.at(i);
      }
      cout << v.at(3) << "=7" << endl;
      finish = true;
    }
  }

}

#include<bits/stdc++.h>

typedef long long ll;
typedef long double ld;

#define n1		      "\n"
#define B                     begin()
#define E                     end()
#define F                     first
#define S                     second
#define pb                    push_back
#define pf                    push_front
#define popb                  pop_back()
#define popf                  pop_front()

const int BIG=1e5+55;
const int BIGG=1e9+7;
const ll BIGGE=1e12+55;
const double SML=(1e-7);

using namespace std;

    int a[5];
    bool go = 0;

void dp(int i, int sum, string s) {
    if (go || i > 3)
        return;
    if (sum == 7 && i == 3) {
        go = 1;
        cout <<s <<'=' <<7;
        return;
    }
    string ans = s , an = s;
    ans += '-';
    ans += (a[i+1] + '0');
    if (i != -1)
        an  += '+';
    an  += (a[i+1] + '0');
    if (i != -1)
        dp(i+1 , sum-a[i+1] ,ans);
    dp(i+1 , sum+a[i+1] ,an);
}

int main()
{
    ios::sync_with_stdio(false); cin.tie(NULL);
    cout.tie(NULL);
    for (int i=0; i<4; i++) {
        char c;
        cin >>c;
        a[i] = c - '0';
    }
    dp(-1,0,"");

    return 0;
}


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

int main() {

  string S;
  cin >> S;
  //S の先頭から 3 文字目と末尾から 2 文字目の間（両端含む）に大文字の C がちょうど 1 個含まれる。
  int count = 0;
  int index;

  for (int i = 2; i < S.size() - 1; i++) {
    if(S[i] == 'C'){
      count++;
      index = i;
    }
  }

  int up_count = 0;

  for (int i = 1; i < S.size(); i++) {
    if(i != index){
      if(S[i] >= 'A' && S[i] <= 'Z'){
		up_count++;
      }
    }
  }

  if(S[0] == 'A' && count == 1 && up_count == 0){
   cout << "AC" << endl;
  }else{
   cout << "WA" << endl;
  }

}

#include<iostream>
#include<iomanip>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<string>
#include<utility>
#include<numeric>
#include<algorithm>
#include<cmath>
#include<climits>
using namespace std;

using ll = long long;

class Stream{
public:
    Stream(){

    }
    //配列以外の入力を受け取る
    void read(){

    }
    template<typename First, typename... Rest>
    void read(First& first, Rest&... rest){
        cin >> first;
        read(rest...);
    }
    //配列を区切って出力する
    template<typename T>
    void write_vec(vector<T>& v, char divider){
        for(size_t i = 0; i < v.size(); i++){
            cout << v[i] << divider;
        }
    }
};

int main(){
    Stream io;

    string S;
    io.read(S);
    string ans = "AC";
    if(S[0] != 'A') ans = "WA";
    int c = 0;
    for(int i = 1; i < S.size(); i++){
        if(!(S[i] <= 'z' && S[i] >= 'a')){
            if(i <= S.size() - 2 && i >= 2){
                c++;
            }
            else ans = "WA";
        }
    }
    if(c != 1) ans = "WA";
    cout << ans;
    return 0;
}


#include<iostream>
#include<iomanip>
#include<algorithm>
#include<string>
#include<map>
#include<cmath>
#include<queue>

using namespace std;

namespace MyLib {
#define ALL(a) a.begin(),a.end()
#define REP(i,n) for(int i=0;i<n;i++)
#define RREP(i,n) for(int i=n-1;i>=0;i--)
#define debug(x) if(1)cout<<#x<<":"<<x<<endl;
#define DEBUG(x) if(1)cout<<#x<<":"<<x<<endl;
#define ll long long
}

using namespace MyLib;
bool ju[21][21];
int rx[30], ry[30];

int main() {
	int m;
	int l[30];
	char buf;

	int x, y;
	int n;
	while (cin >> n, n) {
		REP(i, 21)
			REP(j, 21)
			ju[i][j] = 0;
		REP(i, n)
			cin >> x >> y, ju[y][x] = 1;
		cin >> m;
		REP(i, m) {
			cin >> buf >> l[i];
			if (buf == 'E') {
				rx[i] = 1;
				ry[i] = 0;
			}
			else if (buf == 'W') {
				rx[i] = -1;
				ry[i] = 0;
			}
			else if (buf == 'N') {
				rx[i]= 0;
				ry[i] = 1;
			}
			else if (buf == 'S') {
				rx[i] = 0;
				ry[i] = -1;
			}

		}
		x = 10, y = 10;
		int count = 0;
		REP(i,m)
			REP(j, l[i]) {
				x += rx[i];
				y += ry[i];
				if (ju[y][x]) {
					ju[y][x] = 0;
					count++;
				}
		}
		if (count == n)
			cout << "Yes" << endl;
		else
			cout << "No" << endl;
	}

	return 0;

}

#include<iostream>
using namespace std;

int main(){
    int L;
    int l[10];
    int v1, v2;
    int st, la;
    double pass;
    double time;
    char comma;
    while(cin >> l[0]){
        for(int i=1;i<10;i++){
            cin >> comma >> L;
            l[i] = L + l[i-1];
        }
        cin >> comma >> v1 >> comma >> v2;
        time = l[9] / (double)(v1+v2);
        pass = time * v1;
        for(int i=0;i<10;i++){
            if(pass <= l[i]){
                cout << i+1 << endl;
                break;
            }
        }
    }
}


#include <iostream>
#include <vector>
#include <string>
#define rep(i,N) for(int i=0;i<(N);i++)
using namespace std;

int main(){
	long long N,i=0;
	cin>>N;
	vector<long long> p;

	while(N!=0){
		N=N-1;
		p.push_back(N % 26);
		N = N / 26;
		i++;
	}
	string res = "";
	for(int i = p.size() -1 ; i >= 0 ; i-- )res += (char)('a' +p[i]);
	cout<<res<<endl;
}

#include <stdio.h>

int main(){
	int t;
	scanf("%d", &t);
	long long int sum=0;
	long long int min =0;
	for (int i=1; i<= t; i++){
		if (i%3==0 || i%5==0){
			min += i;
		}
		sum+=i;
	}
	printf("%lld", sum-min);
	return 0;
}


#include <cstdio>
#include <vector>
#include <algorithm>
#include <set>
#include <cstring>
#include <map>
using namespace std;
const int MAXN = 1000005;
char S[MAXN], T[MAXN];
int n, q[MAXN], head = 1, tail;
signed main () {
	scanf("%d%s%s", &n, S+1, T+1);
	if(strcmp(S+1, T+1) == 0) { puts("0"); return 0; }
	int ans = 0;
	for(int i = n, j = n; i >= 1; --i) {
		if(T[i] == T[i-1]) continue;
		j = min(j, i);
		for(; j && S[j] != T[i]; --j);
		if(!j) { puts("-1"); return 0; }
		while(head <= tail && q[head] - (tail-head+1) + 1 > i) ++head;
		q[++tail] = j;
		if(i != j) ans = max(ans, tail-head+1);
	}
	printf("%d\n", ans+1);
}

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define mod 998244353
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
char a[1000005],b[1000005];
vector<int>from;
vector<int>to;
vector<int>pos[26];
int main(){
    int n;
	scanf("%d%s%s",&n,&a,&b);
	for(int i=0;i<n;i++) if(a[i] != b[i]) goto nxt;
	puts("0"); return 0; nxt:;
	for(int i=0;i<n;i++) pos[a[i]-'a'].pb(i);
	bool dif = 0;
	int pre = INF;
	for(int i=n-1;i>=0;i--){
		if(i == 0 || (i > 0 && b[i-1] != b[i])){
			int id = b[i]-'a';
			int x = POSU(pos[id],min(pre-1,i));
			if(x == 0){
				puts("-1");
				return 0;
			}
			from.pb(pos[id][x-1]);
			to.pb(i);
			if(pos[id][x-1] != i) dif = 1;
			pre = pos[id][x-1];
		}
	}
	int ret = 0;
	for(int i=0;i<to.size();i++){
		//(lb,ub]
		int lb = -1,ub = i+1;
		while(ub-lb > 1){
			int mid = (lb+ub)/2;
			int x = from[i-mid]-mid;
			if(x >= to[i]) ub = mid;
			else lb = mid;
		}
		ret = max(ret,ub+1);
	}
	cout<<ret<<endl;
}


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

// DAG
vector<bool> visited;
vector<int> dp;

int DFS(const vector<vector<int>> &graph, int v){
    if(visited[v] == true) return dp[v];

    visited[v] = true;
    for(auto next_v : graph[v]){
        if(DFS(graph, next_v) == -1) return -1;

        dp[v] = max(dp[v], DFS(graph, next_v) + 1);
    }
    return dp[v] = max(0, dp[v]);// if no next_v (i.e. source) dp[v] = 0
}

int main(){
    int n;
    cin >> n;
    int V = n * (n-1) / 2;
    visited.assign(V,false);
    dp.assign(V,-1);

    vector<vector<int>> a(n, vector<int>(n-1));
    for(int i=0; i<n; i++){
        for(int j=0; j<n-1; j++){
            cin >> a[i][j];
            a[i][j] -= 1;
        }
    }

    vector<vector<int>> matchID(n, vector<int>(n));
    int id = 0;
    for(int i=0; i<n; i++){
        for(int j=i+1; j<n; j++){
            matchID[i][j] = id;
            matchID[j][i] = id;
            id += 1;
        }
    }

    vector<vector<int>> graph(V);
    for(int i=0; i<n; i++){
        for(int j=1; j<n-1; j++){
            int s = matchID[i][a[i][j-1]];
            int t = matchID[i][a[i][j]];
            //cout << s << " " << t << endl;
            graph[t].push_back(s);// arrow inversed
        }
    }

    int ans = 0;
    for(int i=0; i<V; i++){
        int depth = DFS(graph, i);
        if(depth == -1){
            cout << -1 << endl;
            return 0;
        }
        ans = max(ans, depth);
    }
    cout << ans + 1 << endl;
    return 0;
}

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

int main(){
	int n;
  	cin >> n;
  	vector<vector<int>> a(n, vector<int>(n-1));
  	rep(i, n){
    	rep(j, n-1){
          	cin >> a[i][j];
      		a[i][j]--;
        }
      	reverse(a[i].begin(), a[i].end());
    }
  	vector<P> q;

  	auto check = [&](int i){
      	if(a[i].size() == 0) return;
      	int j = a[i].back();
      	if(a[j].size() == 0) return;
      	if(a[j].back() == i){
          	P p(i, j);
          	if(p.second < p.first) swap(p.first, p.second);
        	q.push_back(p);
        }
    };

  	rep(i, n){
      	check(i);
    }

  	int day = 0;
  	while(q.size() > 0){
  		day++;
      	sort(q.begin(), q.end());
      	q.erase(unique(q.begin(), q.end()), q.end());
      	vector<P> prevQ;
      	swap(prevQ, q);
      	for(P p : prevQ){
        	int i = p.first, j = p.second;
          	a[i].pop_back();
          	a[j].pop_back();
        }
        for(P p : prevQ){
        	int i = p.first, j = p.second;
          	check(i);
          	check(j);
        }
    }

  	rep(i, n){
    	if(a[i].size() != 0){
        	puts("-1");
          	return 0;
        }
    }

  	cout << day << endl;
}


#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

#define F first
#define S second
#define int long long
//#define ll long long
//#define int  unsigned long long
#define pb push_back
#define double long double

using namespace std;
using namespace __gnu_pbds;
typedef  tree< int , null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
const int N = 3000000;
int mod = 1e9 + 7;
int s[N], dp[N][2], b[N];
map < int, int > m;
main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    //freopen("input.txt", "r", stdin);
    int n;
    cin >> n;
    s[0] = 0;
    set < int > t;
    for (int i = 1; i <= n; i++){
        int x;
        cin >> x;
        s[i] = (s[i - 1] ^ x);
        t.insert(s[i]);
    }
    t.insert(0);
    int cnt = 0;
    for (auto i: t){
        m[i] = cnt;
        cnt++;
    }
    for (int i = 1; i <= cnt; i++) dp[i][0] = 1;
    int g = 0;
    for (int i = 1; i <= n; i++){
        if (s[i] == 0){
            g++;
        } else{
            int p = m[s[i]];
            if (b[p] < g){
                dp[p][0] = (dp[p][0] + (g - b[p]) * dp[p][1]) % mod;
                b[p] = g;
            }
            dp[p][1] = (dp[p][1] + dp[p][0]) % mod;
        }
    }
    if (s[n] == 0){
        int c = 1;
        for (int i = 1; i < n; i++) if (s[i] == 0) c = (c + c) % mod;
        for (int i = 1; i <= cnt; i++){
            c = (c + dp[i][1]) % mod;
        }
        cout << c << endl;
    }
    else {
        int p = m[s[n]];
        if (b[p] < g)  dp[p][0] = (dp[p][0] + (g - b[p]) * dp[p][1]) % mod;
        cout << dp[p][0];

    };
}

#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define __ ios_base::sync_with_stdio(0);cin.tie(0);
#define fi first
#define se second
#define pb push_back
#define all(x) x.begin(),x.end()
#define forn(i,a,n) for(int i=a; i < n; i++)
typedef long long int lli;
typedef long double Double;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
#define MAXN (1<<16)
lli val[MAXN];
lli dp[MAXN];
int used[MAXN];
int a[17][17];
int n;

lli solve(int msk){
	if(msk == (1<<n)-1){
		return 0ll;
	}

	if(used[msk]) return dp[msk];
	used[msk] = 1;
	lli ans = -1ll;
	int ini = msk ^ ((1<<n)-1);
	for(int i=ini; i >=1; i--){
		int andi = msk & i;
		if(andi == 0){
			ans = max(ans, solve(msk | i) + val[i]);
		}
	}
	return dp[msk] = ans;
}

int main(){__
	cin >> n;
	for(int i=0; i < n; i++){
		for(int j=0; j < n; j++){
			cin >> a[i][j];
		}
	}

	for(int i=1; i < (1<<n);i++){
		int msk = i;
		lli res = 0ll;
		for(int j =0; j < n; j++){
			if(msk & (1<<j)){
				for(int k =j; k < n; k++){
					if(msk & (1<<k)){
						res+= a[j][k];
					}
				}
			}
		}
		val[i] = res;
	}
	cout << solve(0) << endl;
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
using int64 = long long;
#define int int64
#define rep(i, n) for(int i=0; i<n; i++)
#define FOR(i, a, b) for(int i=a; i<b; i++)
#define SORT(x) sort(x.begin(), x.end())
#define GSORT(x) sort(x.begin(), x.end(), greater<int>())
#define mk make_pair
#define fi first
#define se second
#define pb push_back
#define ALL(x) x.begin(), x.end()
#define V(T) vector<T>
typedef pair<int, int> P;
typedef pair<P, P> PP;
typedef vector<int> vi;
typedef vector<vi> vvi;
int max(int a, int b) {if(b>a) return b; else return a;}
int min(int a, int b) {if(b<a) return b; else return a;}
const int INF = 1e18;

int N, M;
vvi A(305, vi(305));

int dfs(int n, V(bool) D) {
    if(n==0) return 0;
    //int res = INF;
    int t = 0;
    vi cnt(M, 0);
    rep(i, N) {
        rep(j, M) {
            if(D[A[i][j]]) {
                cnt[A[i][j]]++;
                break;
            }
        }
    }
    int mi = 0;
    rep(i, M) {
        if(cnt[i]>cnt[mi]) mi = i;
    }
    int res = cnt[mi];
    D[mi] = false;
    int nx = dfs(n-1, D);
    if(nx) res = min(res, nx);
    return res;
}

signed main() {
    cin >> N >> M;
    rep(i, N) rep(j, M) {
        cin >> A[i][j];
        A[i][j]--;
    }

    V(bool) D(M, true);

    cout << dfs(M, D) << endl;

    return 0;
}

#include<bits/stdc++.h>

#define ll long long
#define rep(A,B,C) for(A=B;A<C;++A)
#define repd(A,B,C) for(A=(ll)C-1;A>=B;++A)
#define pii pair<int,int>
#define pll pair<ll,ll>
template<typename T>
void mxin(T& a,T b){if(a<b)a = b;}
template<typename T>
void mnin(T& a,T b){if(a>b)a = b;}
using namespace std;

/////////////////////////////////////////////////////
#define MOD 998244353
#define MXN 333

char S[333];
ll N,K;
ll dp[MXN][MXN], odp[MXN][MXN];
ll i, j, k, l;

int main(){
    scanf("%s%lld", S, &K);
    N = strlen(S);
    K = min(N, K);

    dp[0][0] = 1;
    ll pi = N;
    for (i = N - 1; i >= 0;--i)
    {
        if(S[i]=='1')
            continue;
        rep(j,0,MXN){
            rep(k,0,MXN){
                odp[j][k] = dp[j][k];
                dp[j][k] = 0;
            }
        }
        ll a = pi - i;
        pi = i;
        rep(j,0,K+1){
            ll b = 0;
            for(k = j; k >= 0;--k){
                (b += odp[j][k]) %= MOD;
                (dp[j][k] += b) %= MOD;
                if(odp[j][k]==0)
                    continue;
                rep(l,1,a){
                    (dp[j + l][k + l] += odp[j][k]) %= MOD;
                }
            }
        }
        //printf("\n%lld:\n", i);
        /*
        rep(j,0,N+1){
            rep(k,0,j+1){
                printf("%lld ", dp[j][k]);
            }
            printf("\n");
        }*/
    }
    ll ans = 0;
    rep(i,0,K+1){
        rep(j,0,i+1){
            (ans += dp[i][j]) %= MOD;
        }
    }
    printf("%lld\n", ans);
    return 0;
}


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

int main() {
    int N, T; cin >> N >> T;
    vector<int> t(N);
    rep(i, N){
        cin >> t[i];
    }

    int ans = t[N-1] + T;
    for (int i = 1; i < N; i++){
        int d = t[i] - t[i-1];
        if(d > T){
            ans -= d-T;
        }
    }

    cout << ans << endl;

    return 0;
}

#include <bits/stdc++.h>
using namespace std;
int main(){
  int N;cin>>N;
  vector<int>A(N);
  vector<int>B(N);
  vector<int>C(N);
  vector<long long>D(N);
  for(int i=0;i<N;i++)cin>>A[i];
  for(int i=0;i<N;i++)cin>>B[i];
  for(int i=0;i<N;i++)cin>>C[i];
  sort(A.begin(),A.end());
  sort(C.begin(),C.end());
  long long ans=0;
  for(int i=0;i<N;i++){
    ans+=(N-(A.end()-lower_bound(A.begin(),A.end(),B[i])))*(C.end()-upper_bound(C.begin(),C.end(),B[i]));
  }
  cout<<ans<<endl;
}