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

bool judge(int x, vector<int> d){
    bool ans = true;
    while (x > 0){
        rep(i, d.size()){
            if (x % 10 == d[i]) ans = false;
        }
        x /= 10;
    }
    return ans;
}

int main(){
    int n, k;
    cin >> n >> k;
    vector<int> d(k);
    rep(i, k) cin >> d[i];
    for(int i = n; i < 1000000; i++){
        if (judge(i, d)){
            cout << i << endl;
            return 0;
        }
    }
}

#include<bits/stdc++.h>
#define ll long long int
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
static const ll MAX = 1000000000000000;
static const int NIL = -1;
using namespace std;
const long double EPS = 0.0000000001;
const long double PI = (acos(-1));
const ll MOD = 1e9 + 7;

#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")

vector<ll> m;
vector<bool> num(10,true);

int N,K;

void rec(int n){
    if(n > N) return;

    rep(i,10){
        if(num[i]){
            if(n*10 + i == 0) continue;
            m.emplace_back(n*10 + i);
            rec(n*10 + i);
        }
    }
}

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

    rep(i,K){
        cin >> a;
        num[a] = false;
    }

    rec(0);

    sort(m.begin(),m.end());

    rep(i,m.size()){
        if(m[i] >= N){
            cout << m[i];
            return 0;
        }
    }
}


#include <bits/stdc++.h>

using namespace std;

long long n,i;

int main()
{
    cin >> n;
    for(i=111; i<=999; i+=111)
        if(i>=n) {
            cout<<i<<endl;
            break;
        }

    return 0;
}

#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define ll long long
#define rep(i,n) for(ll i=0;i<(n);i++)
#define pll pair<ll,ll>
#define pq priority_queue
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define ios ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define lb(c,x) distance(c.begin(),lower_bound(all(c),x))
#define ub(c,x) distance(c.begin(),upper_bound(all(c),x))

using namespace std;

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

const ll INF=1e9+7;

int main()
{
    ll n;
    cin >> n;
    ll digit1=n/100;
    if(n<=digit1*111){
        cout << digit1*111 << endl;
    }
    else{
        cout << (digit1+1)*111 << endl;
    }
    return 0;
}


#include "bits/stdc++.h"

using namespace std;

void solve()
{
    string s;
    cin >> s;
    int k = s.size();
    while (s[k - 1] != 'F')
        k--;
    cout << s.substr(0, k - 1) << endl;
}

int main()
{
    solve();
    return 0;
}

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
const ll INF = 1LL<<60;

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

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; }

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

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

  string S;
  cin >> S;

  string ans;
  ans = "";
  for(int i = 0; i + 8 < S.length(); i++){
    ans += S[i];
  }

  cout << ans << endl;

  return 0;
}


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

struct Node{
    int key;
    Node *parent, *left, *right;
};

Node *root, *NIL;

void insert(int k){
    Node *y = NIL;
    Node *x = root;
    Node *z;

    z = (Node *)malloc(sizeof(Node));
    z->key = k;
    z->left = NIL;
    z->right = NIL;

    while(x != NIL){
        y = x;
        if(z->key < x->key) x = x->left;
        else x = x->right;
    }

    z->parent = y;

    if(y == NIL){
        root = z;
    }else{
        if(z->key < y->key) y->left = z;
        else y-> right = z;
    }

}

Node* treeMinimum(Node *x){
    while(x->left != NIL){
        x = x->left;
    }
    return x;
}

Node* find(int k){
    Node *x = root;
    while(x != NIL && x->key != k){
        if(k < x->key) x = x->left;
        else x = x->right;
    }
    return x;
}

Node* treeSuccessor(Node *x){
    if(x->right != NIL) return treeMinimum(x->right);
    Node *y = x->parent;
    while(y != NIL && x == y->right){
        x = y;
        y = y->parent;
    }
    return y;
}

void deleteNode(Node *z){
    Node *y; //削除する対象
    Node *x; //yの子

    //削除する接点を決める
    if(z->left == NIL || z->right == NIL) y = z;
    else y = treeSuccessor(z);

    //yの子xを決める
    if(y->left != NIL){
        x = y->left;
    }else{
        x = y->right;
    }

    if(x != NIL){
        x->parent = y->parent;
    }

    if(y->parent == NIL){
        root = x;
    }else{
        if(y == y->parent->left){
            y->parent->left = x;
        }else{
            y->parent->right = x;
        }
    }

    if(y != z){
        z->key = y->key;
    }

    free(y);

}

void inorder(Node *u){
    if(u == NIL) return;
    inorder(u->left);
    printf(" %d", u->key);
    inorder(u->right);
}

void preorder(Node *u){
    if(u == NIL) return;
    printf(" %d", u->key);
    preorder(u->left);
    preorder(u->right);
}

void print(Node *u){
    inorder(u);
    printf("\n");
    preorder(u);
    printf("\n");
}

int main(){
    int m;
    cin >> m;
    char com[10];
    int k;

    rep(i,m){
        scanf("%s", com);
        if(com[0] == 'i'){
            scanf("%d", &k);
            insert(k);
        }else if(com[0] == 'f'){
            scanf("%d", &k);
            Node *x = find(k);
            if(x == NIL) cout << "no" << endl;
            else cout << "yes" << endl;
        }else if(com[0] == 'd'){
            scanf("%d", &k);
            Node *x = find(k);
            if(x != NIL){
                deleteNode(x);
            }
        }else{
            print(root);
        }
    }

    return 0;
}

#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 yn(ans) if(ans)printf("Yes\n");else printf("No\n")
#define YN(ans) if(ans)printf("YES\n");else printf("NO\n")
#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...);}

int main(){
    struct dice{int u,e,w,n,s,d;
    void rotate(char c){
        int temp=u;
        if(c=='E'){u=w;w=d;d=e;e=temp;}
        else if(c=='W'){u=e;e=d;d=w;w=temp;}
        else if(c=='N'){u=s;s=d;d=n;n=temp;}
        else if(c=='S'){u=n;n=d;d=s;s=temp;}
    }
    bool hikaku(dice q){
        int counter=0;
        if(u==q.u)counter++;
        if(s==q.s)counter++;
        if(e==q.e)counter++;
        if(w==q.w)counter++;
        if(n==q.n)counter++;
        if(d==q.d)counter++;
        if(counter==6)return true;else return false;
    }
    };
    int n;
    in(n);
    vector<dice> vec(n);
    rep(i,n){
        in(vec[i].u,vec[i].s,vec[i].e,vec[i].w,vec[i].n,vec[i].d);
    }
    string s="NNNNENNNN";
    for(int j=0;j<n-1;j++){
        for(int k=j+1;k<n;k++){
            dice a=vec[j];
            dice b=vec[k];
        rep(i,9){
            if(a.s==b.s)break;
            b.rotate(s[i]);
        }
        int counter=0;
        while(!a.hikaku(b)){
            b.rotate('E');
            counter++;
            if(counter>=5){
                goto skip;
            }
        }
        out("No");
        return 0;
        skip: ;
        }
    }
    out("Yes");
}


/*                                  /   \                                                                   (Hello)//JSM//*/
/*                                 /*****\                                                                              */
/*     Jai Shree Mataji           /       \ |\| |_| $ |-| K                                                            */
#include<vector>
#include<iostream>
#include<algorithm>
#include<string.h>
#include<bits/stdc++.h>
#include<cstring>
#include<map>
#include<cmath>
#include<set>
using namespace std;
#define ll long long int
#define ld long double
#define MOD 1000000007
#define PI 3.1415926535897932384626433832795
#define YY cout<<"YES"
#define NN cout<<"NO"
#define EE cout<<"\n"
#define ee cout<<"\n"
#define ne cout<<"-1"
#define pb push_back
#define fi first
#define se second
#define mkp make_pair
#define mkt make_tuple
#define sall(v ) sort(v.begin(), v.end())
#define all(v )  v.begin(), v.end()
#define fo(i , n) for(ll i = 0 ; i < n ; i++)
#define vl vector<ll>
#define vc vector<char>
#define vll vector< pair<ll,ll> >
#define mps map<string ,ll>
#define mpc map<char ,ll>
#define mpl map<ll, ll>
#define pr pair<ll,ll>
#define tpl tuple<ll,ll,ll>
ll containsDigit(ll number, ll digit){while (number != 0){int curr_digit = number % 10;if (curr_digit == digit) return 1;number /= 10;}return 0;}
ll soltn(ll x, ll n) {if(x>=0) return x%n;    else return n+x%n;}
ll pd(ll x,ll y){if(x%y==0) return x/y;else return x/y+1;}
ll coda(ll n,ll d){ll count=0;while(n!=0){if(n%10==d)count++;n/=10;}return count;}
ll mdls(ll x){return max(x,-x);}
ll pow1(ll n,ll p){if(p==0)return 1;ll x=pow1(n, p/2);x=(x%MOD*x%MOD)%MOD;if(p%2==0) return x;else return (x*n)%MOD;}
ll isSubstr(string s1, string s2) {   ll M = s1.length();    ll N = s2.length();  for (ll i = 0; i <= N - M; i++) { ll j; for (j = 0; j < M; j++) if (s2[i + j] != s1[j])  break;         if (j == M) return i;   } return -1; }
//s2>s1;if(not) rtrn -1;

ll maxSubArraySum(ll a[], ll size)
{
   ll max_so_far = a[0];
   ll curr_max = a[0];

   for (ll i = 1; i < size; i++)
   {
        curr_max = max(a[i], curr_max+a[i]);
        max_so_far = max(max_so_far, curr_max);
   }
   return max_so_far;
}

int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
	  ll tt=1;

//	   cin>>tt;
	      while(tt--)
{

/*
3 2 3*/
ll n,j,i;
ll a[3];
fo(i,3)
cin>>a[i];
sort(a,a+3);
cout<<a[0]+a[1];
ee;

}
return 0;
}

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

    /*
    int a, b;
    cin >> a >> b ;
    //*/

    //*
    vector<int> vec(3);
    cin >> vec.at(0) >> vec.at(1) >> vec.at(2) ;

    sort(vec.begin(), vec.end());
    //*/

    /*
    if( a < 6 ){
        cout << 0 << endl;
    } else if (a < 13){
        cout << b / 2 << endl;
    } else {
        cout << b << endl;
    }
    //*/

    cout << vec.at(0) + vec.at(1) << endl;

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
long long sum[200005];
int main()
{
    long long mod=1000000007;
    long long n;cin>>n;long long a[n];long long sum=0;
    for(long long i=0;i<n;i++)
    {
        cin>>a[i];
        sum+=a[i];
        sum=sum%mod;

    }

    long long pum=sum;long long rum=0;
    for(long long i=0;i<n-1;i++)
    {
        //cout<<sum[n-1]<<" "<<sum[i]<<" "<<a[i]<<endl;

       pum=pum-a[i];
       if(pum<0)
        pum+=mod;
       rum+=(a[i]*pum);
       rum=rum%mod;

    }
    cout<<rum;

}

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

#define pb push_back
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define debug(x) cerr << #x << " : " << x << '\n'

using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef long double ld;
typedef string str;
typedef pair<ll, ll> pll;
typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

const ll Mod = 1e9 + 7;
const ll Inf = 2242545357980376863LL;
const ll Log = 20;
const ll N = 1ll << Log;
const int Maxn = 5e2 + 10;
const int Base = 101;

ll c1[30], c2[30];

int main(){
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	memset(c2, 31 , sizeof c2);
	ll n, m;
	cin >> n >> m;
	ll s1 = 0, s2 = 0;
	ll sm = 0, v;
	for(int i = 0; i < n; i++){
		cin >> v;
		s1 += ((v * i) - sm);
		sm += v;
	}
	sm = 0;
	for(int i = 0; i < m; i++){
		cin >> v;
		s2 += ((v * i) - sm);
		sm += v;
	}
	cout << (s1 % Mod)*(s2 % Mod) % Mod;
	return 0;
}


#include <bits/stdc++.h>
#define loop2(i, s, n, a) for (int i = int(s); i < int(n); i += a)
#define loop(i, s, n) loop2(i, s, n, 1)
#define rep(i, n) loop(i, 0, n)

#define pb push_back
#define all(in) in.begin(),in.end()

using ll = long long;
using ull = unsigned long long;
using namespace std;

int main(){
    int n; cin >> n;
    vector<int> data(n); rep(i,n) cin >> data[i];

    vector<int> ans(1,-data[0]);

    for(int i = 1; i < n; i++){
        int k = upper_bound(all(ans),-data[i]) - ans.begin();
        if(k == ans.size()) ans.push_back(-data[i]);
        else ans[k] = -data[i];
    }
    cout << ans.size() << endl;
}

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

int main(){
  int n,t;
  cin>>n>>t;
  int sum=0;
  int cur=0;
  rep(i,0,n){
    int a;
    cin>>a;
    if(cur<=a){
      sum+=t;
    }
    else{
      sum+=a+t-cur;
    }
    cur=a+t;
  }
  cout<<sum<<endl;
}


#include<bits/stdc++.h>

#include <ext/pb_ds/assoc_container.hpp> //required
#include <ext/pb_ds/tree_policy.hpp> //required

using namespace __gnu_pbds;
using namespace std;

template <typename T> using ordered_set =  tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
// find_by_order(k)  returns iterator to kth element starting from 0;
// order_of_key(k) returns count of elements strictly smaller than k;
typedef long long  ll;
typedef vector<ll> VL;
typedef vector<int> VI;
typedef pair<ll,ll> PLL;
typedef pair<int,int> PII;
#define pb push_back

#define F first
#define S second
#define SZ(a) int((a).size())
#define ALL(a) a.begin(),a.end()
#define fr(i,x,y) for(int i=x;i<y;i++)
#define frr(i,x,y) for(int i=x-1;i>=y;i--)
#define inf 1e18+1
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
const int mod=1000000007;
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
ll power(ll a,ll b){ll ans=1;while(b!=0){if(b&1){ans*=a;}a=a*a;b>>=1;}return ans;}
ll powerm(ll a,ll b){ll ans=1;while(b!=0){if(b&1){ans*=a;ans%=mod;}a=a*a;a%=mod;b>>=1;}return ans%mod;}
// string to integer stoi()
// string to long long stoll()
// string.substr(position,length);
// integer to string to_string();

void solve()
{
    ll n,x;
    cin>>n>>x;
    ll ct=0;
    VL arr(n);
    fr(i,0,n)
        cin>>arr[i];
    fr(i,1,n)
    {
        if((arr[i]+arr[i-1])>x)
        {
            ll rem=(arr[i]+arr[i-1])-x;
            ll f=min(rem,arr[i]);
            rem-=f;
            arr[i]-=f;
            ct+=f;
            if((arr[i]+arr[i-1])>x)
            {
                ct+=rem;
            }
        }
    }
    cout<<ct<<endl;
    return;
}
int main()
{
    IOS;
    ll t=1;
    //cin>>t;
    while(t--)
    {
        //cout<<"Case #"<<pp-t<<":\n";
        solve();
    }
    return 0;
}
/* stuff you should look for
        * int overflow, array bounds
        * special cases (n=1?)
        * do smth instead of nothing and stay organized
        * WRITE STUFF DOWN
*/
/*
recursion - matrix exponential

*/
// BITMASK:
// 1)When some constrall is of the order of 15-20, think of bitmask DP.
// 2)When some constrall is around 40, try out meet in the middle
// 3) See Strings,palindromes,prefix,suffix etc -> KMP,Z algorithm

#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<cmath>
#include<cstdio>
#include<queue>
#include<deque>
#include<map>
#include<stack>
#include<set>
#include<utility>
using namespace std;
typedef pair<int,int> ii;
typedef long long ll;
typedef pair<ll,ll> p;
typedef unsigned long long int ull;
const ll MOD=998244353;
int dy[]={1,0,-1,0};
int dx[]={0,1,0,-1};
const int MAXN=100000;
const int MAXE=100000;
const int MAXV=10000;
const ll INF=2e9;

ll N,M,V,P;
ll A[100000];

bool C(int x){
    if(x<P) return true;
    if(A[x]+M<A[P-1]) return false;
    ll sum=0;
    sum+=M*P;
    sum+=M*(N-1-x);
    for(int i=P-1;i<x;i++){
        sum+=min(M,A[x]+M-A[i]);
    }
    return sum>=M*V;
}

int main(){
    cin>>N>>M>>V>>P;
    for(int i=0;i<N;i++) cin>>A[i];
    sort(A,A+N,greater<ll>());
    int l=0,r=N;
    while(r-l>1){
        int m=(l+r)/2;
        if(C(m)) l=m;
        else r=m;
    }
    cout<<l+1<<endl;
    return 0;
}


#include<iostream>
#include<vector>
using namespace std;
typedef unsigned long long int ull;
vector<ull> allPrimes;

void sieve(int n)
{
    vector<bool> prime(n+1, true);
    for (int p=2; p*p<=n; p++) {
        if (prime[p] == true) {
            for (int i=p*2; i<=n; i += p)
                prime[i] = false;
        }
    }
    for (int p=2; p<=n; p++)
        if (prime[p])
            allPrimes.push_back(p);
}
ull factorialDivisors(ull n)
{
    sieve(n);
    ull result = 1;
    for (int  i=0; i < allPrimes.size(); i++)
    {
        ull p = allPrimes[i];
        ull exp = 0;
        while (p <= n)
        {
            exp = exp + (n/p);
            p = p*allPrimes[i];
        }
        result = (result*(exp+1))%1000000007;
    }
    return result;
}

int main()
{
    int n; cin>>n;
    cout << factorialDivisors(n);
    return 0;
}

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
 int H, W;
 int seen[10000][10000];
  char S[10000][10000];
vector<pair<ll, ll>> prime_factorize(ll n) { //素因数分解と各素数の個数
    vector<pair<ll, ll>> res;

    for (ll i = 2; i * i <= n; i++)
    {
        if (n % i != 0)
        {
            continue;
        }
        int num = 0;

        while (n % i == 0)
        {
            ++num;
            n /= i;
        }
        res.push_back(make_pair(i, num));

    }
     if (n != 1)
        {
            res.push_back(make_pair(n, 1));
        }
        return res;

}
long long GCD(long long a, long long b) {
    if (b == 0) return a;
    else return GCD(b, a % b);
}
ll lcm(ll x, ll y) {
    return x / GCD(x, y) * y;//先に割り算をして掛けられる数を小さくして掛け算を行う
}
const int MAX = 510000;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

void dfs(int st, int fi) {
  //  cout << st << " " << fi <<  endl;
    if (st < 0 || fi < 0 || st >= H || fi >= W)
    {
        return ;
    }
    if (S[st][fi] == '#')
    {
        return ;
    }

    if (seen[st][fi] == 1)
    {
        return ;
    }

    if (S[st][fi] == '.')
    {
        seen[st][fi] = 1;
    }

    dfs(st + 1, fi);
    dfs(st, fi + 1);
    dfs(st, fi - 1);
    dfs(st - 1, fi);

}
int main() {
    int N;
    cin >> N;
    vector<int> p(N + 1);
    p[1] = 0;
    for(int i = 2; i <= N; i++) {
        int n = i;
        vector<pair<int, int>> b;
       for(int j = 2; j * j <= n; j++) {
           if(n % j != 0) continue;
           int ex = 0;

           while(n % j == 0) {
               ex++;
               n /= j;
           }

           b.push_back({j, ex});
       }
       if(n != 1) b.push_back({n, 1});

       for(auto v : b) {
           p[v.first] += v.second;
       }
    }

    /*for(int i = 1; i <= N; i++)
        cout << p[i] << endl;*/

    ll ans = 1;

    for(int i = 2; i <= N; i++) {
        ans *= (p[i] + 1);
        ans %= 1000000007;
    }

    cout << ans << endl;
 return 0;
}


#include <iostream>
#include <stdio.h>
#include <string.h>
#include <vector>
#include <map>
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

const ll inf = -1e16;

int main(){
    int N;
    cin >> N;
    vector<int> v(N);
    ll dp[3];
    rep(i,N) cin >> v[i];

    dp[0] = v[0];
    dp[1] = max(v[0],v[1]);
    if(N>2){
        dp[0] += v[2];
        dp[2] = max(dp[1],(ll)v[2]);
    }
    for(int i=3; i<N; ++i){
        ll tmp1,tmp2;
        tmp1 = dp[0];
        tmp2 = dp[1];
        if((i+1)%2){ // odd
            dp[0] += v[i];
            dp[1] = tmp1> tmp2? tmp1:tmp2 ;
            dp[2] += v[i];
            dp[2] = dp[1]>dp[2]? dp[1]:dp[2];
        }
        else{
            dp[1] += v[i];
            dp[2] = tmp2> dp[2]? tmp2:dp[2] ;
        }
    }

    if(N%2){
        cout << dp[2] << endl;
    }else{
        cout << dp[1] << endl;
    }

    return 0;
}

#include <bits/stdc++.h>
#define Int int64_t

using namespace std;

int main() {
	constexpr Int INF = 1e18;
	int N;
	cin >> N;
	vector<Int> a(N);
	for (int i = 0; i < N; ++i) { cin >> a[i]; }

	int skip = 1 + N % 2;
	vector<vector<Int>> dp(N + 2, vector<Int>(skip + 1, -INF));
	dp[0][0] = 0;
	for (int i = 0; i <= N; ++i) {
		for (int j = 0; j <= skip; ++j) {
			if (j < skip) {
				dp[i + 1][j + 1] = max(dp[i + 1][j + 1], dp[i][j]);
			}
			if (i < N) {
				dp[i + 2][j] = max(dp[i + 2][j], dp[i][j] + a[i]);
			}
		}
	}
	cout << dp[N + 1][skip] << endl;

	return 0;
}


#include <bits/stdc++.h>
using namespace std;
int main(){
  long long N,M;
  cin>>N>>M;
  vector<long long> l(M);
  vector<long long> r(M);
  for(long long i=0;i<M;i++)
    cin>>l.at(i)>>r.at(i);
  sort(l.begin(),l.end());
  sort(r.begin(),r.end());
  long long a=r.at(0)-l.at(M-1)+1;
  if(a>0)
  cout<<a<<endl;
  else
    cout<<0<<endl;
}

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

int main() {
  int n,m; cin >> n >> m;
  int l,u; l = 0; u = (int)1e6;
  rep(i, m){
    int p, q; cin >> p >> q;
    if(l < p) l = p;
    if(q < u) u = q;
  }

  cout << max(u - l + 1, 0) << endl;
}


#include <bits/stdc++.h>

using namespace std;

#define INF 1001000100010001000
#define MOD 1000000007
#define EPS 1e-10
#define int long long
#define rep(i, N) for (int i = 0; i < N; i++)
#define Rep(i, N) for (int i = 1; i < N; i++)
#define For(i, a, b) for (int i = (a); i < (b); i++)
#define pb push_back
#define eb emplece_back
#define mp make_pair
#define i_i pair<int, int>
#define vi vector<int>
#define vvi vector<vi >
#define vb vector<bool>
#define vvb vector<vb >
#define vp vector< i_i >
#define all(a) (a).begin(), (a).end()
#define Int(x) int x; scanf("%lld", &x);
#define int2(x, y) int x, y; scanf("%lld %lld", &x, &y);
#define fir first
#define sec second
#define ffir first.first
#define fsec first.second
#define sfir second.first
#define ssec second.second

//int dxy[5] = {0, 1, 0, -1, 0};
// assign

#define Edge pair< i_i, int>
#define Graph vector< vp >

//???????§????????????????(???????????????)
//Dijkstra O((E+V)logV)
//dist: ?§????????????????????????§??????????????¢
//?????????: ??????????????¨????????????(??????-1)
vector<int> dijkstra(Graph &g, int s, vi &dist)
{
    int n = g.size();
    vi visited(n, 0); visited[s] = 1;
    vi prev(n, -1);
    dist.assign(n, INF); dist[s] = 0;
    priority_queue< Edge, vector< Edge >, greater< Edge > > pq;
    pq.push(Edge(i_i((int)0, s), (int)-1)); // ????????? ??? ???
    while (pq.size()) {
        int d = pq.top().ffir, v = pq.top().fsec, u = pq.top().second;
        pq.pop();
        if (dist[v] < d) continue; //?????§???????????§???????????°??????
        visited[v] = 2; prev[v] = u;
        for (i_i &e : g[v]) {
            if (visited[e.fir] == 2) continue;
            if (dist[e.fir] > dist[v] + e.sec) {
                dist[e.fir] = dist[v] + e.sec;
                pq.push(Edge(i_i(dist[e.fir], e.fir), v));
                visited[e.fir] = 1;
            }
        }
    }
    return prev;
}

signed main()
{
    int2(n, m);
    Int(st);
    Graph g(n, vp());
    vi ans(n);

    rep(i, m) {
        int2(s, t);
        Int(d);
        g[s].pb(i_i(t, d));
    }
    dijkstra(g, st, ans);
    rep(i, n) {
        if (ans[i] == INF) {
            cout << "INF" << endl;
        } else {
            cout << ans[i] << endl;
        }
    }

    return 0;
}

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

//#define int long long
#define DBG 1
#define dump(o) if(DBG){cerr<<#o<<" "<<o<<endl;}
#define dumpc(o) if(DBG){cerr<<#o; for(auto &e:(o))cerr<<" "<<e;cerr<<endl;}
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define each(it,c) for(auto it=(c).begin();it!=(c).end();it++)
#define all(c) c.begin(),c.end()
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9 + 7);
int n, m, r; const int W(1), B(0);
vector<vector<pair<int, int>>>adj; // dist, cost
void dijkstra() {
	vector<int>d(n, INF), color(n, W);
	d[r] = 0;
	priority_queue<pair<int, int>>pq; // d[v], v
	pq.push(make_pair(0, r));
	while (!pq.empty()) {
		pair<int, int>f(pq.top()); pq.pop();
		color[f.second] = B;
		if (d[f.second] < (-1)*f.first)continue;
		rep(i, 0, adj[f.second].size()) {
			pair<int, int>u(adj[f.second][i]);
			if (color[u.first] != B&&d[f.second] + u.second < d[u.first]) {
				d[u.first] = d[f.second] + u.second;
				pq.push(make_pair((-1)*d[u.first], u.first));
			}
		}
	}
	rep(i, 0, n) {
		if (d[i] == INF)cout << "INF" << endl;
		else cout << d[i] << endl;
	}
}
signed main() {
	cin >> n >> m >> r; adj = vector<vector<pair<int, int>>>(n, vector<pair<int,int>>());
	rep(i, 0, m) {
		int s, t, d; cin >> s >> t >> d;
		adj[s].push_back(make_pair(t, d));
	}
	dijkstra();
	return 0;
}


//kruskal tree
#include <cstdio>
#include <algorithm>
using namespace std;
#define M 100000
int parent[M],a[M],b[M];
pair<int,int>node[M];
int root(int a){return parent[a]==a?a:parent[a]=root(parent[a]);}
int unite(int a,int b){
	int x=root(a),y=root(b);
	if(x==y)return 0;
	parent[x]=y;
	return 1;
}
int main(){
	int i,s,n,m;
	for(;scanf("%d%d",&n,&m)>1;printf("%d\n",s)){
		for(i=0;i<m;i++)scanf("%d%d%d",a+i,b+i,&node[i].first),node[i].second=i;
		sort(node,node+m);
		for(i=0;i<n;i++)parent[i]=i;
		for(s=i=0;i<m;i++)if(unite(a[node[i].second],b[node[i].second]))s+=node[i].first;
	}
}

#include<vector>
#include<iostream>
#include<algorithm>
using namespace std;
#define MAX_V 10000
#define MAX_E 10000

int par[MAX_V];
int rank_[MAX_V];

void init(int V) {
	for (int i = 0; i < V; i++) {
		par[i] = i;
		rank_[i] = 0;
	}
}

int root(int x) {
	if (par[x] == x) {
		return x;
	}
	return par[x] = root(par[x]);
}

void unite(int x, int y) {
	x = root(x);
	y = root(y);
	if (x == y) {
		return;
	}
	if (rank_[x] < rank_[y]) {
		par[x] = y;
	}
	else if (rank_[x]==rank_[y]){
		par[y] = x;
		rank_[x]++;

	}
	else if (rank_[y] < rank_[x]) {
		par[y] = x;
	}
}

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

struct edge {
	int from, to, cost;
	bool operator<(const edge& other)const {
		return cost < other.cost;
	}
};

using edges = vector<edge>;

int kruskal(edges&  es,int V) {

	sort(es.begin(), es.end());
	int E = es.size();
	init(V);
	int res = 0;
	for (int i = 0; i < E; i++) {
		if (!same(es[i].from, es[i].to)) {
			unite(es[i].from, es[i].to);
			res += es[i].cost;
		}
	}
	return res;
}

int main() {
	int V, E;
	cin >> V >> E;
	edges es(E);
	for(int i=0;i<E;i++){
		cin >> es[i].from >> es[i].to >> es[i].cost;

	}
	cout << kruskal(es, V) << endl;
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i< (n); i++)
using ll = long long;
using P = pair<int, int>;
int main()
{
    int n;
    cin >> n;
    string m = to_string(n);
    int cnt = 0;
    rep(i,m.size()){
        cnt += m.at(i) - '0';
    }
    if(n % cnt == 0)cout << "Yes" << endl;
    else cout << "No" << endl;
return 0;
}


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

int main() {
    int n;
    cin>>n;
    long long int ar=0;

    int temp[64];
    for(int i=0;i<64;i++){
        temp[i]=0;
    }
    for(int i=0;i<n;i++){
        cin>>ar;
        int j=0;
        while(ar>0){
            temp[j]+=ar%2;
            ar/=2;
            j++;
        }
    }
    long long int sum=0,tempsum=0,temp2;

    for(int i=0;i<63;i++){
        int k1=temp[i],k2=n-temp[i];
        // cout <<k1 << " " << k2 << endl;
        tempsum=k1;tempsum*=k2;
        if(tempsum>1000000007)    tempsum=tempsum%1000000007;
        temp2=(pow(2,i));
        // cout << temp2 <<endl;
        // cout << tempsum<< endl;
        if(temp2>1000000007)    temp2=temp2%1000000007;
        tempsum*=temp2;
        sum+=tempsum;
        if(sum>1000000007)    sum=sum%1000000007;

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

}

#include <bits/stdc++.h>
using namespace std;
#include <math.h>
#include <iomanip>
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

const int mod=1000000007;
const int INF=1001001001;

vector<pair<int64_t,int64_t>>prime_factorize(int64_t x){
  vector<pair<int64_t,int64_t>>p;
  for(int64_t i=2;i*i<=x;i++){
    int cnt=0;
    if(x%i==0){
    while(x%i==0){cnt++;x/=i;}
    p.push_back(make_pair(i,cnt));
    }
  }
  if(x!=1){p.push_back(make_pair(x,1));}
  return p;
}

int main() {
  string s;
  cin>>s;
  int n=s.size();
  stack<char>k;
  for(int i=0;i<n;i++){
    if(k.empty()){k.push(s[i]);}
    else if(s[i]=='T'&&k.top()=='S'){k.pop();}
    else{k.push(s[i]);}
  }
  cout<<k.size()<<endl;
  return 0;
}


#include<iostream>
main(){
  std::string s;
  std::cin>>s;
  int n=s.size();
  std::cout<<s.substr(0,n-8)<<std::endl;
}

#include <bits/stdc++.h>
using namespace std;
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
typedef long long ll;
typedef long double lb;
#define int long long
#define double long double
typedef pair<int,int> P;
const int MOD = 1000000007;
const ll INF = 1e16;
const double EPS = 1e-10;
const double PI = 3.141592653589793;
template<class T> inline bool chmin(T& a, T b){if(a>b){a = b;return 1;}return 0;}
template<class T> inline bool chmax(T& a, T b){if(a<b){a = b;return 1;}return 0;}
const pair<int,int> fd[] = {make_pair(1,0),make_pair(-1,0),make_pair(0,1),make_pair(0,-1)};

////////////////////////////////////////////////////////////////////
template<typename T>
struct edge {
  int to, from;T cost;
  edge(int to) : from(-1), to(to), cost(-1) {}
  edge(int to, T cost) : from(-1), to(to), cost(cost) {}
  edge(int from, int to, T cost) : from(from), to(to), cost(cost) {}
};
template<typename T>
using edges = vector<edge<T>>;
template<typename T>
using graph = vector<edges<T>>;
template<typename T>
using matrix = vector<vector<T>>;

template<typename T>
bool compByCost(const edge<T>& left, const edge<T>& right){
  return left.cost < right.cost;
}

template<typename T>
vector<vector<T>> warshall(matrix<T> &g){
  vector<vector<T>> dist(g.size());
  rep(i,g.size()){
    dist[i].resize(g.size());
    rep(j,g.size())dist[i][j] = (i == j ? 0 : g[i][j]);
  }
  rep(k,g.size()){
    rep(i,g.size()){
      rep(j,g.size()){
        if(dist[i][k] == INF || dist[k][j] == INF)continue;
        dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
      }
    }
  }
  return dist;
}

#define warshall warshall<int>// matの初期化でINFを詰めておく

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

signed main(){
  string s,t;cin>>s;
  rep(i,s.length()-8)t += s[i];
  cout << t << endl;
}


#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
ll d;
map < ll, ll > mp[20];
ll pw10[20];
ll coef[20];
ll gc[20];
int LEN = 0;
int val[25];
int val0[25];
ll solve(int where, ll need) {
    //cout << where << " " << need << endl;
    if (where == LEN) {
        return (need == 0);
    }
    if (gc[where] != 0 && need % gc[where] != 0) return 0;
    //if (need % gc[where] != 0) return 0;
    if (coef[where] == 0) {
        if (need == 0) return 10;
        else return 0;
    }
    if (mp[where].find(need) != mp[where].end()) {
        return mp[where][need];
    }
    ll tot = 0;
    for (int i = -9; i <= 9; i++) {
        if (where) tot += solve(where + 1, need - i * coef[where]) * val[i + 9];
        else {
            tot += solve(where + 1, need - i * coef[where]) * val0[i + 9];
        }
    }
    return mp[where][need] = tot;
}
ll solve(int len) {
    LEN = (len + 1) / 2;
    for (int i = 0; i <= LEN; i++) mp[i].clear();
    for (int i = 0; i < (len + 1) / 2; i++) {
         coef[i] = pw10[len - 1 - i] - pw10[i];
         coef[i] /= 9;
    }
    gc[LEN] = 0;
    for (int i = LEN - 1; i >= 0; i--) gc[i] = __gcd(coef[i], gc[i + 1]);
    return solve(0, d);
}
int main() {
    ios_base::sync_with_stdio(false);
    //freopen("input.txt", "r", stdin);
    for (int i = 0; i <= 9; i++) {
        for (int j = 0; j <= 9; j++) {
            val[i - j + 9]++;
            if (j) val0[i - j + 9]++;
        }
    }
    pw10[0] = 1;
    for (int i = 1; i <= 18; i++) pw10[i] = 10 * pw10[i - 1];
    cin >> d;
    if (d % 9 != 0) {
        cout << 0;
        return 0;
    }
    d /= 9;
    ll f = 0;
    for (int len = 2; len <= 18; len++) {
        f += solve(len);
    }
    cout << f << endl;

    return 0;
}

#include<cstdio>
#include<cmath>
typedef long long LL;
int D;
LL ans=0;
LL solve(int len){
	LL now=0,ans=1;
	for(int l=0,r=len-1;l<r;++l,--r){
		LL dw=(LL)pow(10,l),qaq=((LL)pow(10,r)-dw)/9;
		if(now<D){
			int wg=(D-now)/dw%10;
			now+=qaq*wg;
			ans=ans*(10-wg-(l==0));
		}else{
			int wg=(now-D)/dw%10;
			now-=qaq*wg;
			ans=ans*(10-wg-(l==0));
		}
	}
	if(len&1)ans*=10;
	if(now==D)return ans;
	return 0;
}
int main(){
	scanf("%d",&D);
	if(D%9)return puts("0"),0;
	D/=9;
	for(int i=1;i<=18;++i)
	if(pow(10,i)>D)ans+=solve(i);
	printf("%lld\n",ans);
	return 0;
}


#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
inline int gi()
{
	char c;int num=0,flg=1;
	while((c=getchar())<'0'||c>'9')if(c=='-')flg=-1;
	while(c>='0'&&c<='9'){num=num*10+c-48;c=getchar();}
	return num*flg;
}
#define N 200005
#define LL long long
#define lc i<<1
#define rc i<<1|1
const LL INF=0x3f3f3f3f3f3f3f3fll;
int pos[N],A,B,n,Q;
struct node{
	int l,r;
	LL mi1,mi2,la;
}a[N<<2];
void cal(int i,LL k){a[i].mi1+=k;a[i].mi2+=k;a[i].la+=k;}
void pushdown(int i)
{
	if(a[i].la&&a[i].l<a[i].r){
		cal(lc,a[i].la);cal(rc,a[i].la);
		a[i].la=0;
	}
}
void pushup(int i)
{
	a[i].mi1=min(a[lc].mi1,a[rc].mi1);
	a[i].mi2=min(a[lc].mi2,a[rc].mi2);
}
void build(int i,int l,int r)
{
	a[i].l=l;a[i].r=r;
	if(l==r){
		a[i].mi1=INF;a[i].mi2=INF;
		return;
	}
	int mid=(l+r)>>1;
	build(lc,l,mid);build(rc,mid+1,r);
	pushup(i);
}
void insert(int i,int l,int r,LL k)
{
	if(a[i].l>r||a[i].r<l)return;
	pushdown(i);
	if(l<=a[i].l&&a[i].r<=r){cal(i,k);return;}
	insert(lc,l,r,k);insert(rc,l,r,k);
	pushup(i);
}
void modify(int i,int x,LL k)
{
	if(a[i].l>x||a[i].r<x)return;
	pushdown(i);
	if(x==a[i].l&&a[i].r==x){a[i].mi1=min(a[i].mi1,k-x);a[i].mi2=min(a[i].mi2,k+x);return;}
	modify(lc,x,k);modify(rc,x,k);
	pushup(i);
}
LL query1(int i,int l,int r)
{
	if(a[i].l>r||a[i].r<l)return INF;
	pushdown(i);
	if(l<=a[i].l&&a[i].r<=r)return a[i].mi1;
	return min(query1(lc,l,r),query1(rc,l,r));
}
LL query2(int i,int l,int r)
{
	if(a[i].l>r||a[i].r<l)return INF;
	pushdown(i);
	if(l<=a[i].l&&a[i].r<=r)return a[i].mi2;
	return min(query2(lc,l,r),query2(rc,l,r));
}
LL query(int i)
{
	if(a[i].l==a[i].r)return a[i].mi1+a[i].l;
	pushdown(i);
	return min(query(lc),query(rc));
}
int ab(int x){return x<0?-x:x;}
int main()
{
	int i;LL f;
	n=gi();Q=gi();A=gi();B=gi();
	build(1,1,n);
	pos[0]=A;modify(1,B,0);
	for(i=1;i<=Q;i++){
		pos[i]=gi();
		f=min(query1(1,1,pos[i])+pos[i],query2(1,pos[i]+1,n)-pos[i]);
		insert(1,1,n,ab(pos[i]-pos[i-1]));
		modify(1,pos[i-1],f);
	}
	printf("%lld\n",query(1));
}

#include <bits/stdc++.h>

using namespace std;
int u,v,kq,x[100005],y[100005],deg[100005],n,m,slx;
vector<int> a[100005],ng[100005];
queue<int> q;
void sxtp()
{
    for (int i=1;i<=n;++i) if (deg[i]==0) q.push(i);

    while (!q.empty())
    {

        int u=q.front();q.pop();
        x[++slx]=u;y[u]=slx;
        for (int i=0;i<a[u].size();++i)
        {
            int v=a[u][i];
            deg[v]--;
            if (deg[v]==0) q.push(v);
        }
    }
}
int main()
{

    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    cin>>n>>m;
    for (int i=1;i<=n+m-1;++i)
    {
        cin>>u>>v;
        a[u].push_back(v);deg[v]++;
        ng[v].push_back(u);
    }
    sxtp();
    for (int u=1;u<=n;++u)
    {
        kq=0;
        for (int j=0;j<ng[u].size();++j)
        {
            v=ng[u][j];
           // if (u==1) cout<<v<<endl;
            if (y[v]>y[kq]) kq=v;
        }
        cout<<kq<<'\n';
    }
   // cout<<x[1]<<' '<<y[6]<<endl;

    return 0;
}


#include <bits/stdc++.h>
#define err(args...) {}
#ifdef DEBUG
#include "_debug.cpp"
#endif
using namespace std;
using ll = long long;
using ld = long double;
template <typename T> using lim = numeric_limits<T>;
template <typename T> istream& operator>>(istream& is, vector<T>& a) { for(T& x : a) { is >> x; } return is; }
const int N = 50;
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    ll k;
    cin >> k;
    cout << N << endl;
    for(int i = 0; i < N; i++) {
        if(i < N - 1 - (k - 1) % N) {
            cout << (k - 1) / N + i << " ";
        } else if(i == N - 1) {
            cout << (k - 1) / N + N << " ";
        } else {
            cout << (k - 1) / N + N - 1 << " ";
        }
    }
    cout << endl;
    return 0;
}

#include<iostream>
#include<iomanip>
#include<cmath>
#include<string>
#include<cstring>
#include<vector>
#include<list>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define mp make_pair
#define rep(i, n) for(int i=0;i<n;++i)
#define rrep(i, n) for(int i=n;i>=0;--i)
const int inf=1e9+7;
const ll mod=1e9+7;
const ll big=1e18;
const double PI=2*asin(1);

ll mod1 = 998244353;

ll mypow(ll a, ll b) {
  ll h = b;
  ll two;
  ll ans = 1;
  ll tmp;
  while(h>0) {
    two = 1;
    tmp = a;
    while(2*two<h) {
      two *= 2;
      tmp *= tmp;
      tmp %= mod1;
    }
    h -= two;
    ans *= tmp;
    ans %= mod1;
  }
  return ans;
}

int main() {
  int N;
  cin>>N;
  int D[N];
  map<int, int> amap;
  for(int i=0;i<N;++i) {
    cin>>D[i];
    amap[D[i]]++;
  }
  if(D[0]>0 || amap[0]>1) {
    cout<<0<<endl;
    return 0;
  }
  ll ans = 1;
  ll num = 1;
  int maxnum=0;
  bool can = true;
  bool owari = false;
  for(int i=0;i<N;++i) {
    if(amap[i]>0) {
      if(owari) can = false;
      maxnum = i;
    }
    else {
      owari = true;
    }
  }
  if(!can) {
    cout<<0<<endl;
    return 0;
  }
  for(int i=1;i<=maxnum;++i) {
    ans *= mypow(num, amap[i]);
    ans %= mod1;
    num = amap[i];
  }
  cout<<ans<<endl;
}


#include <stdio.h>

int main(void){
  int n,i,j,k;
  scanf("%d",&n);
  int retsu[n];
  for (i = 1; i <= n; i++){
    k = n - i;
    scanf("%d",&retsu[k]);
  }
  for (j = 0; j < n; j++){
    if( j ) printf(" ");
    printf("%d",retsu[j]);
    }
    printf("\n");
 return 0;
}

#include<stdio.h>
int main()
{
	int a,b;
	while(scanf("%d",&a)!=EOF&&a)
	{
		int b[10000]={0};
		int i,j;
		for(i=0;i<a;i++)
		{
			scanf("%d",&b[i]);
		}
		printf("%d",b[i-1]);
		for(j=i-2;j>=0;j--)
		{
			printf(" %d",b[j]);
		}
		printf("\n");
	}
	return 0;
 }


#include <cstdio>
#include <vector>
#include <algorithm>
#include <queue>
#include <utility>

using namespace std;

template <class T>
using lp_queue=priority_queue<T, deque<T>, greater<T>>;

using Weight=long long;
static const Weight INF=1LL<<57;

struct Edge {
    size_t src, dst;
    Weight weight;
    Edge() {}
    Edge(size_t src, size_t dst, Weight weight=1):
        src(src), dst(dst), weight(weight)
    {}
};

bool operator<(const Edge &e, const Edge &f) {
    if (e.weight != f.weight) {
        return e.weight > f.weight;
    } else {
        return e.src!=f.src? e.src<f.src : e.dst<f.dst;
    }
}

using Edges=vector<Edge>;
using Vertex=vector<Edge>;
using Graph=vector<Vertex>;

void join(Graph &g, size_t s, size_t d, Weight w=1) {
    // non-directed
    g[s].push_back(Edge(s, d, w));
    g[d].push_back(Edge(d, s, w));
}

void connect(Graph &g, size_t s, size_t d, Weight w=1) {
    // directed
    g[s].push_back(Edge(s, d, w));
}

vector<vector<Weight>> shortest_distance(Graph &g) {
    /* Johnson */
    size_t V=g.size();
    vector<Weight> h(V);
    for (size_t k=0; k<V; ++k)
        for (size_t i=0; i<V; ++i)
            for (const Edge &e: g[i])
                if (h[e.dst] > h[e.src] + e.weight) {
                    h[e.dst] = h[e.src] + e.weight;
                    if (k == V-1)
                        return vector<vector<Weight>>();
                }

    for (size_t i=0; i<V; ++i)
        for (Edge &e: g[i])
            e.weight += h[e.src] - h[e.dst];

    vector<vector<Weight>> d(V, vector<Weight>(V, INF));
    for (size_t s=0; s<V; ++s) {
        d[s][s] = 0;
        lp_queue<pair<Weight, size_t>> q; q.push(make_pair(0, s));
        while (!q.empty()) {
            pair<Weight, size_t> p=q.top(); q.pop();
            size_t v=p.second;
            if (d[s][v] < p.first) continue;

            for (const Edge &e: g[v])
                if (d[s][e.dst] > d[s][v] + e.weight) {
                    d[s][e.dst] = d[s][v] + e.weight;
                    q.push(make_pair(d[s][e.dst], e.dst));
                }
        }

        for (size_t u=0; u<V; ++u)
            if (d[s][u] < INF)
                d[s][u] += h[u] - h[s];
    }

    for (size_t v=0; v<V; ++v)
        for (Edge &e: g[v])
            e.weight += h[e.dst] - h[e.src];

    return d;
}

int main() {
    size_t V, E;
    scanf("%zu %zu", &V, &E);

    Graph g(V);
    for (size_t i=0; i<E; ++i) {
        size_t s, t;
        Weight d;
        scanf("%zu %zu %lld", &s, &t, &d);

        connect(g, s, t, d);
    }

    vector<vector<Weight>> d=shortest_distance(g);
    if (d.empty())
        return !printf("NEGATIVE CYCLE\n");

    for (vector<Weight> w: d)
        for (size_t i=0; i<V; ++i)
            if (w[i] < INF) {
                printf("%lld%c", w[i], i<V-1? ' ':'\n');
            } else {
                printf("INF%c", i<V-1? ' ':'\n');
            }

    return 0;
}


#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,b,a) for(int i=b;i>=a;i--)
#define fori(a) for(auto i : a )
#define all(a) begin(a), end(a)
#define set(a,b) memset(a,b,sizeof(a))
#define sz(a) a.size()
#define pi 3.14159
#define ll long long
#define ull unsigned long long
#define pb push_back
#define PF push_front //deque
#define mp make_pair
#define pq priority_queue
#define mod 1000000007
#define f first
#define s second
#define pii pair< int, int >
#define vi vector<int>
#define vpii vector<pii>
#define debug(v) for(auto i:v) cout<<i<<" ";
#define tc int t; cin >> t; while(t--)

using namespace std;
string repeat(string s, int n) {
    string s1 = "";
    for (int i=0; i<n;i++)
        s1+=s;
    return s1;
}
string getString(char x) {
    string s(1, x);
    return s;
}

void optimizeIO(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
}
int gcd(int a, int b){
    if (a == 0)  return b;
    return gcd(b % a, a);
}
const int N=55556;
vector<int> isprime(N,1);
vector<int> prime;
void  solve(){
	rep(i,2,N){
		for(int j=2*i;j<N;j+=i) isprime[j]=0;
	}
	rep(i,2,N) if(isprime[i]) prime.pb(i);
	int n,i=0;
	cin>>n;
	while(n>0 && i<prime.size()){
		if(prime[i]%5==4) cout<<prime[i]<<" ",n--;
		i++;
	}
	cout<<endl;
}
int main(){
    optimizeIO();
    // tc
    { solve();
    }
}

#include<bits/stdc++.h>
#define del(a,i) memset(a,i,sizeof(a))
#define ll long long
#define inl inline
#define il inl void
#define it inl int
#define ill inl ll
#define re register
#define ri re int
#define rl re ll
#define mid ((l+r)>>1)
#define lowbit(x) (x&(-x))
#define INF 0x3f3f3f3f
using namespace std;
template<class T>il read(T &x){
	int f=1;char k=getchar();x=0;
	for(;k>'9'||k<'0';k=getchar()) if(k=='-') f=-1;
	for(;k>='0'&&k<='9';k=getchar()) x=x*10+k-'0';
	x*=f;
}
template<class T>il _print(T x){
	if(x>=10) _print(x/10);
	putchar(x%10+'0');
}
template<class T>il print(T x){
	if(x<0) putchar('-'),x=-x;
	_print(x);
}
ll mul(ll a,ll b,ll mod){long double c=1.;return (a*b-(ll)(c*a*b/mod)*mod)%mod;}
it qpow(int x,int k,int mod){
	int res=1,bas=x;
	while(k){
		if(k&1) res=1ll*res*bas%mod;
		bas=1ll*bas*bas%mod,k>>=1;
	}
	return res;
}
const int N = 2e5+5,mod = 1e9+7;
it add(int x,int y){return x+y>=mod?x+y-mod:x+y;}
it mul(int x,int y){return 1ll*x*y%mod;}
il inc(int &x,int y){x=add(x,y);}
int n,m,k,ans,fac[N],ifac[N];
it C(int n,int m){return mul(mul(ifac[n-m],ifac[m]),fac[n]);}
int main(){
//	freopen(".in","r",stdin);
//	freopen(".out","w",stdout);
	read(n),read(m),read(k),fac[0]=1;
	for(ri i=1;i<=n*m;++i) fac[i]=mul(fac[i-1],i);
	ifac[n*m]=qpow(fac[n*m],mod-2,mod);
	for(ri i=n*m-1;i>=0;--i) ifac[i]=mul(ifac[i+1],i+1);
	for(ri i=1;i<=n-1;++i) inc(ans,mul(mul(mul(m,m),n-i),i));
	for(ri i=1;i<=m-1;++i) inc(ans,mul(mul(mul(n,n),m-i),i));
	print(mul(ans,C(n*m-2,k-2)));
	return 0;
}


#include <bits/stdc++.h>
#define err(args...) {}
#ifdef DEBUG
#include "_debug.cpp"
#endif
using namespace std;
using ll = long long;
using ld = long double;
template <typename T> using lim = numeric_limits<T>;
template <typename T> istream& operator>>(istream& is, vector<T>& a) { for(T& x : a) { is >> x; } return is; }
const int M = 1'000'000'007;
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int n, m;
    cin >> n >> m;
    vector<ll> x(n), y(m);
    cin >> x >> y;
    adjacent_difference(x.begin(), x.end(), x.begin());
    adjacent_difference(y.begin(), y.end(), y.begin());
    ll ysum = 0;
    for(int j = 1; j < m; j++) {
        ysum += y[j] * (m - j) % M * j % M;
        ysum %= M;
    }
    ll xsum = 0;
    for(int i = 1; i < n; i++) {
        xsum += x[i] * (n - i) % M * i % M;
        xsum %= M;
    }
    cout << xsum * ysum % M << endl;
    return 0;
}

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

# define REP(i,n) for (int i=0;i<(n);++i)
# define rep(i,a,b) for(int i=a;i<(b);++i)
# define p(s) std::cout << s ;
# define pl(s)  std::cout << s << endl;
# define printIf(j,s1,s2) cout << (j ? s1 : s2) << endl;
# define YES(j) cout << (j ? "YES" : "NO") << endl;
# define Yes(j) std::cout << (j ? "Yes" : "No") << endl;
# define yes(j) std::cout << (j ? "yes" : "no") << endl;
# define all(v) v.begin(),v.end()
# define showVector(v) REP(i,v.size()){p(v[i]);p(" ")} pl("")
template<class T> inline bool chmin(T &a, T b){ if(a > b) { a = b; return true;} return false;}
template<class T> inline bool chmax(T &a, T b){ if(a < b) { a = b; return true;} return false;}
typedef long long int ll;
typedef pair<ll,ll> P_ii;
typedef pair<double,double> P_dd;

template<class T>
vector<T> make_vec(size_t a){
    return vector<T>(a);
}

template<class T, class... Ts>
auto make_vec(size_t a, Ts... ts){
  return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}

template<typename T,typename V>
typename enable_if<is_class<T>::value==0>::type
fill_v(T &t,const V &v){t=v;}

template<typename T,typename V>
typename enable_if<is_class<T>::value!=0>::type
fill_v(T &t,const V &v){
  for(auto &e:t) fill_v(e,v);
}

const int MOD = 1000000007;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;

void addM(long long &a, long long b) {
    a += b;
    if (a >= MOD) a -= MOD;
}

void mulM(long long &a, long long b) {
    a = ((a%MOD)*(b%MOD))%MOD ;
}

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

    vector<ll> x(n),y(m);
    ll xsum = 0, ysum = 0;

    REP(i, n) cin >> x[i];
    sort(all(x));
    REP(i, n - 1) addM(xsum, (x[i+1] - x[i])*(i + 1)*(n - i - 1));

    REP(i, m) cin >> y[i];
    sort(all(y));
    REP(i, m - 1) addM(ysum, (y[i+1] - y[i])*(i + 1)*(m - i - 1));

    mulM(xsum,ysum);

    cout << xsum << endl;

    return 0;
}


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

#define ll long long
//~ #define endl '\n'

void solve(){
	int a[3];
	cin>>a[0]>>a[1]>>a[2];
	for(int i = 0; i<3; i++){
		if(a[i] == a[(i + 1)%3] && a[i] != a[(i + 2)%3]){
			cout<<"Yes"<<endl;
			return;
		}
	}
	cout<<"No"<<endl;
}

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

#include <bits/stdc++.h>
#define rep(i, a, b) for (int i = (int)(a); i < (int)(b); ++i)
using namespace std;

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

    if (n % k == 0)
    {
        std::cout << 0 << endl;
        return 0;
    }
    std::cout << 1 << endl;

    return 0;
}


#include"bits/stdc++.h"

using namespace std;

#define rep(i,n) for(int i=0;i<(int)(n);i++)

const long long INF10=1e10+1,ID_MAX=20;
const long mod=(1e9)+7;
const long long INF18=1e18+1;

struct edge{
    int to;
    long cost;
};

void sort2array(double *a,long *b,long n){
    for(int i=0;i<n;i++){
        b[i]=i;
    }
    sort(b,b+n,[a](long i,long j)->bool {return a[i]<a[j];} );
}
//bを何回足せばaを超えるか(O(a/b))
int wtover(int a,int b){
    if(a%b>0)return (a/b)+1;
    else return a/b;
}
int bi_e[ID_MAX]={0};
//2進数表示したときの最高桁(O(log n))
int bi_max(long n){
    int m=0;
    for(m;(1<<m)<=n;m++);m=m-1;
    return m;
}
//bi_eに二進数表示したやつを代入(O(log^2 n))
void bi_exs(long n){
    memset(bi_e,0,sizeof(bi_e));
    if(n<(1<<ID_MAX)){
        for(int i=0;n>0;n=(n>>1),i++)bi_e[i]=n&1;
    }
}
//x^n mod m (nが負の時は０)(O(log n))
long myPow(long x, long n, long m){
  if(n<0)return 0;
  if(n == 0)
    return 1;
  if(n % 2 == 0)
    return myPow(x * x % m, n / 2, m);
  else
    return x * myPow(x, n - 1, m) % m;
}
//m以下のn以下の分割数のmodの表生成(O(nm))d[i][j]=jのi分割
long long d[10001][10001];
void divNum(int n,int m,long long md=mod){
    rep(j,n+1){
        d[j][0]=1;
    }
    rep(j,m){
        d[0][j+1]=0;
    }
    for(int j=1;j<=n;j++){
        for(int k=1;k<=m;k++){
            if(j>k)d[j][k]=d[j-1][k];
            else d[j][k]=(d[j-1][k]+d[j][k-j])%md;
        }
    }
}
const int N_MAX=1e5+1,M_MAX=1e9+1;
int n,m;
vector<int> a;
long long div_res[N_MAX][100];
void divide(int s,int t){
    div_res[0][0]=1;
    rep(i,s){
        rep(j,t+1){
            rep(k,t-j+1){
                div_res[i+1][j+k]=(div_res[i+1][j+k]+div_res[i][j])%mod;
            }
        }
    }
}

int main(){
    int i=0,maxa=0;
    //入力
    cin>>n>>m;
    int mm=m,x=2,r;
    for(int j=2;j<=ceil(sqrt(m));j++){
        r=0;
        while(mm%j==0){
            mm=mm/j;
            r++;
        }
        if(r!=0){
            if(maxa<r)maxa=r;
            a.push_back(r);
        }
    }
    if(mm!=1)a.push_back(1);
    //処理
    long long res=1;
    divide(n,maxa);
    rep(i,a.size()){
        res=(res*div_res[n][a.at(i)])%mod;
    }
    //出力
    cout<<res<<endl;
}

#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef long int li;
typedef long double lb;
#define rep(i,j,n) for (ll i = j; i < (n); i++)
#define repr(i,j,n) for(ll i = j; i >= (n); i--)
#define all(x) (x).begin(),(x).end()
#define CLR(mat,f) memset(mat, f, sizeof(mat))
#define IN(a, b, x) (a<=x&&x<b)
#define out(ans) cout << ans << endl
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
typedef pair<ll,ll>P;
const ll mod=1e9+7;
const ll INF = 1LL<<60;
const ll m=1LL<<32;

const int MAX = 510000;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main(){

  ll n,m;cin>>n>>m;
  COMinit();

  map<ll,ll>mp;
  for(ll i=2;i*i<=m;i++){
    while(m%i==0){
      mp[i]++;
      m/=i;
    }
  }
  if(m!=1)mp[m]++;

  ll ans=1;
  for(auto p:mp){
    // out(p.first<<":"<<p.second<<" "<<COM(p.second+n-1,p.second));
    ans*=COM(p.second+n-1,p.second);
    ans%=mod;
  }
  //因数別にそれぞれ配分していく組み合わせを掛けていく
  out(ans);

  return 0;
}


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

#define MAX_STATIONS 100+1
#define INF 1<<15

#define reep(i,n,m) for(int i=n;i<m;i++)
#define rep(i,n) reep(i,0,n)

using namespace std;

class Stations{
private:
    int time[MAX_STATIONS][MAX_STATIONS];
    int cost[MAX_STATIONS][MAX_STATIONS];
public:
    void solve(int a[MAX_STATIONS][MAX_STATIONS], int r){
        //wayは文系をあらわす
        rep(way,MAX_STATIONS){
            rep(to,MAX_STATIONS){
                rep(from,MAX_STATIONS){
                    a[from][to] = min(a[from][to], a[from][way] + a[way][to]);
                    a[to][from] = a[from][to];
                }
            }
        }
        if(r==1){
            rep(i,MAX_STATIONS){
                rep(k,MAX_STATIONS){
                    time[k][i] = a[k][i];
                }
            }
        }
        else{
            rep(i,MAX_STATIONS){
                rep(k,MAX_STATIONS){
                    cost[k][i] = a[k][i];
                }
            }
        }
    }

    int getTime(int from, int to){
        return time[from][to];
    }

    int getCost(int from, int to){
        return cost[from][to];
    }
};

int main(void){
    int n,m;
    int t[MAX_STATIONS][MAX_STATIONS], c[MAX_STATIONS][MAX_STATIONS];
    while(cin >> n >> m,n+m){
        rep(i,MAX_STATIONS){
            rep(k,MAX_STATIONS){
                t[i][k] = INF;
                c[i][k] = INF;
            }
        }

        rep(i,n){
            int from,to,cost,time;
            cin >> from >> to >> cost >> time;
            t[from][to] = t[to][from] = time;
            c[from][to] = c[to][from] = cost;
        }

        Stations station;
        station.solve(c,0);
        station.solve(t,1);

        int q;
        cin >> q;

        rep(i,q){
            int from,to,r;
            cin >> from >> to >> r;
            if(r==1){
                cout << station.getTime(from,to) << endl;
            }else{
                cout << station.getCost(from,to) << endl;
            }
        }
    }
    return 0;
}

#include <bits/stdc++.h>
#include "atcoder/all"

using namespace std;

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

#define FOR(i, n, m) for(ll (i)=(m);(i)<(n);++(i))
#define REP(i, n) FOR(i,n,0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll) 1e15;

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

    ll N, Q;
    cin >> N >> Q;
    atcoder::fenwick_tree<ll> bit(N);
    REP(i, N) {
        ll a;
        cin >> a;
        bit.add(i, a);
    }

    REP(_, Q) {
        ll t, a, b;
        cin >> t >> a >> b;
        if (t == 0) {
            bit.add(a, b);
        }
        else {
            cout << bit.sum(a, b) << endl;
        }
    }
    return 0;
}


#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <ctime>
#include <cassert>
#include <iostream>
#include <cctype>
#include <sstream>
#include <string>
#include <list>
#include <vector>
#include <queue>
#include <set>
#include <stack>
#include <map>
#include <utility>
#include <numeric>
#include <algorithm>
#include <iterator>
#include <bitset>
#include <complex>
#include <fstream>
#include <iomanip>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef pair<int, int> pint;
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
template<class T> T RoundOff(T a){ return int(a+.5-(a<0)); }
template<class T, class C> void chmax(T& a, C b){ if(a < b) a = b; }
template<class T, class C> void chmin(T& a, C b){ if(b < a) a = b; }
template<class T, class C> pair<T, C> mp(T a, C b){ return make_pair(a, b); }

int main()
{
	int n, m;
	while(cin >> n >> m && n)
	{
		vint p(n);
		rep(i, n)
			cin >> p[i];

		sort(ALL(p));

		int res = accumulate(ALL(p), 0);
		rep(i, n)
			res -= ((i + 1) % m== 0) * p[n - i - 1];

		cout << res << endl;
	}
}

#include <iostream>
#include <queue>

int main(){
	std::priority_queue<int> p;

	int n, m;
	int price;
	while(std::cin >> n >> m){
		int sum_price = 0;
		if(n == 0 && m == 0) break;
		//input
		for(int i = 0; i < n; ++i){
			std::cin >> price;
			p.push(price);
		}
		//袋詰め
		while(!p.empty()){
			for(int i = 1; i <= m && !p.empty(); ++i){
				if(i != m){
					sum_price += p.top();
					p.pop();
				}
				else{
					p.pop();
				}
			}
		}
		std::cout << sum_price << std::endl;
	}
}


#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <tuple>
#include <vector>
using namespace std;
typedef long long ll;
ll const INF = 1LL << 60;

int main() {
  ll A, B, C, D;
  cin >> A >> B >> C >> D;
  if (A + B < C + D) {
    cout << "Right" << endl;
  } else if (A + B > C + D) {
    cout << "Left" << endl;
  } else {
    cout << "Balanced" << endl;
  }
  return 0;
}

#include <iostream>
#include <string>

int main () {
  int a, b, c, d;
  std::string ans = "";
  std::cin >> a >> b >> c >> d;
  int x = a + b - c - d;
  if(x > 0) ans = "Left";
  else if(x == 0) ans = "Balanced";
  else ans = "Right";
  std::cout << ans << std::endl;
}


#include <bits/stdc++.h>
using namespace std;
#include <math.h>
#include <iomanip>
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

const int mod=1e9+7;
const int INF=1001001001;

int dp[105][10];
int main() {
  int H,W,K;
  cin>>H>>W>>K;

  dp[0][0]=1;
  for(int i=0;i<H;i++){
    for(int j=0;j<W;j++){
      if(dp[i][j]==0){continue;}
      for(int s=0;s<(1<<W-1);s++){
        vector<int>t(W-1);
        for(int k=0;k<W-1;k++){
          if((s>>k)&1){t[k]=1;}
        }
        bool ok=true;
        for(int k=0;k<W-2;k++){
          if(t[k]==1&&t[k+1]==1){ok=false;}
        }
        if(ok){
          if(j<W-1&&t[j]){(dp[i+1][j+1]+=dp[i][j])%=mod;}
          else if(j>0&&t[j-1]){(dp[i+1][j-1]+=dp[i][j])%=mod;}
          else{(dp[i+1][j]+=dp[i][j])%=mod;}
        }
      }
    }
  }

  cout<<dp[H][K-1]<<endl;
  return 0;
}

#include "bits/stdc++.h"

#define MOD 1000000007
#define rep(i, n) for(ll i=0; i < (n); i++)
#define rrep(i, n) for(ll i=(n)-1; i >=0; i--)
#define ALL(v) v.begin(),v.end()
#define rALL(v) v.rbegin(),v.rend()
#define FOR(i, j, k) for(ll i=j;i<k;i++)
#define DUMP(i, v)for(ll i=0;i<v.size();i++)cerr<<v[i]<<" "

using namespace std;
typedef long long int ll;
typedef vector<ll> llvec;
typedef vector<double> dvec;
typedef pair<ll, ll> P;
typedef long double ld;
struct edge{ll x, c;};

ll mod(ll a, ll mod){
  ll res = a%mod;
  while(res<0)res=res + mod;
  return res;
}

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

ll modinv(ll a, ll mod){
  return modpow(a, mod-2, mod);
}

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

bool is_prime(ll n){
  ll i = 2;
  if(n==1)return false;
  if(n==2)return true;
  bool res = true;
  while(i*i <n){
    if(n%i==0){
      res = false;
    }
    i = i+1;
  }

  //if(i==1)res = false;
  if(n%i==0)res=false;
  return res;
}

struct UnionFind{
  ll N;
  llvec p;
  llvec cnt;
  UnionFind(ll n){
    N = n;
    p=llvec(N);
    cnt=llvec(N, 0);
    rep(i, N){
      p[i] = i;
      cnt[i] = 1;
    }
  }

  void con(ll a, ll b){
    P at = root(a);
    P bt = root(b);
    if(at.second!=bt.second){
      if(at.first>bt.first){
        swap(at, bt);
        swap(a, b);
      }
      p[at.second] = bt.second;
      cnt[bt.second]+=cnt[at.second];
      p[a]=bt.second;
    }
  }

  P root(ll a){
    ll atmp = a;
    ll c=0;
    while(atmp!=p[atmp]){
      atmp = p[atmp];
      c++;
    }
    p[a] = atmp;
    return {c, atmp};
  }

  bool is_con(ll a, ll b){
    P at=root(a);
    P bt=root(b);
    return at.second == bt.second;
  }

};

struct dijkstra{
  ll N;
  llvec d;
  vector<vector<edge>> e;
  dijkstra(ll n){
    N = n;
    //d = llvec(N, 1e18);
    e = vector<vector<edge>>(N);
  }

  void add_edge(ll from, ll to, ll cost){
    e[from].push_back({to, cost});
  }

  void run(ll start){
    priority_queue<P, vector<P>, greater<P>> que;
    que.push({0, start});
    d = llvec(N, 1e18);
    d[start]=0;
    while(!que.empty()){
      P q = que.top();que.pop();
      ll dc = q.first;
      ll x = q.second;
      if(dc>d[x]){
        continue;
      }else{
        for(auto ip: e[x]){
          if(d[ip.x]<=d[x]+ip.c){
            continue;
          }else{
            d[ip.x]= d[x]+ip.c;
            que.push({d[ip.x], ip.x});
          }
        }
      }
    }
  }
};

ll fact[500000];
ll ifact[500000];

void gen(){
  fact[0]=ifact[0]=1;
  rep(i, 200100){
    fact[i+1]=mod(fact[i]*(i+1), MOD);
    ifact[i+1]=modinv(fact[i+1], MOD);
  }
}

ll comb(ll n, ll k){
  return mod(mod(fact[n]*ifact[n-k], MOD)*ifact[k], MOD);
}

/**************************************
** A main function starts from here  **
***************************************/
int main(){
  ll N, M, K;
  cin >> N >> M >> K;
  ll ans = 0;
  gen();
  rep(i, N*M){
    ll x = i/N+1;
    ll y = i/M+1;
    ans =mod(ans+ (M-x)*(M-x+1)/2*N, MOD);
    ans =mod(ans+ (N-y)*(N-y+1)/2*M, MOD);
  }
  cout << mod(ans*comb(N*M-2, K-2),MOD)<<endl;
  return 0;
}


#include <stdio.h>

int main(){

int menit;
int angkaangka[5];
for(int i=0;i<5; i++){
    scanf("%d", &angkaangka[i]);
}
//for(int i=0;i<5; i++){
//   printf("%d ", angkaangka[i]);
//}
int jam=angkaangka[2]-angkaangka[0];
//printf("total jam: %d\n", jam);
if(angkaangka[3]>angkaangka[1]){
    menit=angkaangka[3]-angkaangka[1];
}
else if(angkaangka[1]>angkaangka[3]){
    menit=60-(angkaangka[1]-angkaangka[3]);
    jam--;
}
else{
    menit=0;
}
//printf("total menit=%d\n", menit);
//printf("total k= %d\n", angkaangka[4]);
printf("%d\n", jam*60+menit-angkaangka[4]);

    return 0;
}

#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;
#define REP(i,n) for (int i=0; i<(n); i++)
#define SORT(c) sort((c).begin(),(c).end())
typedef vector<int> vi;
int main() {
	vi W(10),K(10);
	REP(i,10) scanf("%d",&W[i]);
	REP(i,10) scanf("%d",&K[i]);
	SORT(W); SORT(K);
	int w=0,k=0;
	REP(i,3) w+=W[9-i];
	REP(i,3) k+=K[9-i];
	printf("%d %d\n",w,k);
}


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

int main() {
  string a, b, c;
  cin >> a >> b >> c;
  bool flag = true;
  if(a[a.size()-1] != b[0]) flag = false;
  if(b[b.size()-1] != c[0]) flag = false;
  if(flag) cout << "YES" << endl;
  else cout << "NO" << endl;
}

    #include <bits/stdc++.h>

    using namespace std;

    #define pb push_back
    #define pi 3.14159265358979323846
    #define ll long long
    #define mp make_pair
    #define pf push_front
    #define MOD 1000000007
    #define MAX 100000000
    #define MIN -1000000000
    #define LLINF 0x3f3f3f3f3f3f
    #define INF 0x3f3f3f3f
    #define ld long double
    #define MAXN 1010
    #define MAXM 1010

    int main()
    {
        ios_base::sync_with_stdio(false);
        cin.tie(NULL);
        cout.tie(NULL);
        int d, t, s;
        cin >> d >> t  >> s;
        if(s*t >= d){
        	cout << "Yes" << endl;
        }else{
        	cout << "No" << endl;
        }
        return 0;
    }


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

#define INF 1e18
long long DP[5001][5001];

struct Constraint {
	long long H, P;

	Constraint(long long H = 0, long long P = 0):H(H), P(P){}

	bool operator<(const Constraint& r)const {
		return P+H < r.P+r.H;
	}
};

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

	int N; cin >> N;
	vector<Constraint>C(N);
	for (int i = 0; i < N; i++) {
		int P, H; cin >> H >> P;
		C[i] = Constraint(H, P);
	}
	sort(C.begin(), C.end());

	for (int i = 0; i <= N; i++)for (int j = 0; j <= N; j++)DP[i][j] = INF;
	DP[0][0] = 0;
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < i + 1; j++) {
			if (DP[i][j] == INF)continue;

			if (DP[i][j] <= C[i].H) {
				DP[i + 1][j + 1] = min(DP[i + 1][j + 1], DP[i][j] + C[i].P);
			}
			DP[i + 1][j] = min(DP[i + 1][j], DP[i][j]);
		}
	}

	int ans = 0;
	for (int i = 1; i <= N; i++) {
		for (int j = 1; j <= N; j++) {
			if (DP[i][j]==0 || DP[i][j] == INF)continue;
			ans = max(ans, j);
		}
	}

	cout << ans << endl;

	return 0;
}

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

const int M = 1e9 + 7;

int main()
{

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

    int n;
    cin >> n;

    vector<pair<ll, ll>> A(n);
    for (int i = 0; i < n; ++i) {
        cin >> A[i].first >> A[i].second;
    }

    auto comp = [&](pair<ll, ll>& a, pair<ll, ll>& b) {
        return a.first + a.second < b.first + b.second;
    };

    sort(A.begin(), A.end(), comp);

    vector<vector<ll>> dp(2, vector<ll>(n + 1, 1e14));

    dp[0][0] = 0;

    for (int i = 1; i <= n; ++i) {
        for (int j = 1; j <= n; ++j) {

            dp[i%2][j] = dp[(i - 1)%2][j];

            if (A[i - 1].first >= dp[(i - 1)%2][j - 1]) {
                dp[i%2][j] = min(dp[i%2][j], A[i - 1].second + dp[(i - 1)%2][j - 1]);
            }
        }
    }

    // cout <<"dp array :: "<< "\n";

    // for(int i = 1 ; i <= n ;++i){
    //     for(int j = 1 ; j <= n ;++j){
    //         cout << dp[i][j] << " ";
    //     }
    //     cout << "\n";
    // }
    for (int j = n; j >= 0; --j) {
        if (dp[n%2][j] != 1e14) {
            cout << j << "\n";
            break;
        }
    }

    return 0;
}


#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
int main() {
  string S;
  cin >> S;
  int N = S.size();
  int sum = 0;
  vector<int> vec(N);
  rep(i, N) {
    if(S.at(i) == '0') {
      vec.at(i) = 0;
    }
    if(S.at(i) == '1') {
      vec.at(i) = 1;
    }
    if(S.at(i) == '2') {
      vec.at(i) = 2;
    }
    if(S.at(i) == '3') {
      vec.at(i) = 3;
    }
    if(S.at(i) == '4') {
      vec.at(i) = 4;
    }
    if(S.at(i) == '5') {
      vec.at(i) = 5;
    }
    if(S.at(i) == '6') {
      vec.at(i) = 6;
    }
    if(S.at(i) == '7') {
      vec.at(i) = 7;
    }
    if(S.at(i) == '8') {
      vec.at(i) = 8;
    }
    if(S.at(i) == '9') {
      vec.at(i) = 9;
    }
  }
  reverse(vec.begin(), vec.end());
  vector<int> vec10(N);
  rep(i, N) {
    if(i == 0) {
      vec10.at(i) = 1;
    }
    else {
      vec10.at(i) = vec10.at(i-1)*10;
    }
  }
  int sum2 = 0;
  rep(i, N) {
    sum += vec.at(i) * vec10.at(i);
    sum2 += vec.at(i);
  }
  if(sum%sum2 == 0) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
}

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rrep(i, n) for(int i = n-1; i >= 0; i--)
#define  all(x) (x).begin(),(x).end()     // 昇順ソート
#define  rall(v) (v).rbegin(), (v).rend() // 降順ソート
#define  FastIO ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
typedef long long ll;
using P = pair<int,int>;
using VI = vector<int>;
using VVI = vector<vector<int>>;
using VL = vector<ll>;
using VVL = vector<vector<ll>>;
using VP = vector<P>;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return true; } return false; }

int main(){
    int n;
    cin >> n;
    int sum = 0;
    int x = n;
    while(n){
        sum += n % 10;
        n /= 10;
    }
    if (x % sum == 0) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}


#include "bits/stdc++.h"

using namespace std;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<VVI> VVVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef vector<PII> VPII;
typedef long long LL;
typedef priority_queue<int> PQ_DESC;
typedef priority_queue<int, vector<int>, greater<int>> PQ_ASC;
typedef priority_queue<PII> PQ_DESC_PII;
typedef priority_queue<PII, vector<PII>, greater<PII>> PQ_ASC_PII;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;
typedef vector<VVLL> VVVLL;

#define SORT_ASC(c) sort((c).begin(), (c).end())
#define SORT_DESC(c) sort((c).begin(), (c).end(), greater<typeof((c).begin())>())

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define FORL(i,a,b) for(LL i=(a);i<(b);++i)
#define REPL(i,n)  FORL(i,0,n)
#define SIZE(a) int((a).size())
#define ALL(a) (a).begin(),(a).end()

const double EPS = 1e-10;
const double PI  = acos(-1.0);
const int INT_LARGE = 1000000100;

//debug func
template<typename T>
void vecprint(vector<T> v) {
    for(auto x : v) {
        cerr << x << " ";
    }
    cerr << endl;
}

template<typename T>
void vecvecprint(vector<vector<T>> vv) {
    REP(i, SIZE(vv)) {
        REP(j, SIZE(vv[i])) {
            cerr << vv[i][j] << " ";
        }
        cerr << endl;
    }
}

template<typename T>
void pqprint(priority_queue<T> q) {
    while(!q.empty()) {
        cerr << q.top() << " ";
        q.pop();
    }
    cerr << endl;
}

template<typename T>
void qprint(queue<T> q) {
    while(!q.empty()) {
        cerr << q.front() << " ";
        q.pop();
    }
    cerr << endl;
}

template<typename T>
void vecqprint(vector<queue<T>> v) {
    for(int i = 0; i < v.size(); i++) {
        qprint(v[i]);
    }
}

template <typename Iterator>
inline bool next_combination(const Iterator first, Iterator k, const Iterator last)
{
   /* Credits: Thomas Draper */
   if ((first == last) || (first == k) || (last == k))
      return false;
   Iterator itr1 = first;
   Iterator itr2 = last;
   ++itr1;
   if (last == itr1)
      return false;
   itr1 = last;
   --itr1;
   itr1 = k;
   --itr2;
   while (first != itr1)
   {
      if (*--itr1 < *itr2)
      {
         Iterator j = k;
         while (!(*itr1 < *j)) ++j;
         iter_swap(itr1,j);
         ++itr1;
         ++j;
         itr2 = k;
         rotate(itr1,j,last);
         while (last != j)
         {
            ++j;
            ++itr2;
         }
         rotate(k,itr2,last);
         return true;
      }
   }
   rotate(first,k,last);
   return false;
}

inline double get_time_sec(void){
    return static_cast<double>(chrono::duration_cast<chrono::nanoseconds>(chrono::steady_clock::now().time_since_epoch()).count())/1000000000;
}

template<typename T>
T gcd(T a, T b) {
    if(a > b) swap(a, b);
    if(a == 0) return b;
    else return gcd(b%a, a);
}

template<typename T>
map<T, T> prime_list(T n) {
    map<T, T> ret;
    for(T i = 2; i*i <= n; i++) {
        if(n % i == 0) {
            ret[i] = 0;
            while(n % i == 0) {
                n /= i;
                ret[i]++;
            }
        }
    }
    if(n != 1) ret[n]++;
    return ret;
}

int main(void) {
    int n;
    cin >> n;
    VI a(n+2, 0);
    REP(i, n) cin >> a[i+1];
    VI b(n+1);
    REP(i, n+1) b[i] = abs(a[i+1] - a[i]);
    int sum = 0;
    REP(i, n+1) sum += b[i];
    REP(i, n) {
        cout << sum - b[i] - b[i+1] + abs(a[i] - a[i+2]) << endl;
    }
}

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

int main(void) {
    int N,sum;
    cin >> N;
    vector<int> A(N+2,0);
    vector<bool> bs(N+1,false);

    // 経由地点が間にあるかどうかを判定する
    sum = 0;
    for(int i=0;i<N;i++) {
        cin >> A[i+1];
        if(i) {
            // 2個前と1個前と現在を見て1個前を確定
            if(((A[i+1] >= A[i]) && (A[i] >= A[i-1]))
                || ((A[i+1] <= A[i]) && (A[i] <= A[i-1]))) {
                bs[i] = true;
            }
        }
        sum += abs(A[i+1] - A[i]);
    }

    // 最後を確定
    if(((A[N+1] >= A[N]) && (A[N] >= A[N-1]))
                || ((A[N+1] <= A[N]) && (A[N] <= A[N-1]))) {
        bs[N] = true;
    }
    sum += abs(A[N+1] - A[N]);

    for(int i=1;i<=N;i++){
        if(bs[i]) {
            cout << sum << endl;
        } else {
            cout << sum - abs(A[i]-A[i-1]) - abs(A[i+1]-A[i]) + abs(A[i+1]-A[i-1]) << endl;
        }
    }
    return 0;
}


#include<bits/stdc++.h>
#define pb(a) push_back(a)
#define ms(x,y) memset(x,y,sizeof(x))
#define sci(a) scanf("%d",&a)
#define scl(a) scanf("%lld",&a)
#define scd(a) scanf("%lf",&a)
#define ll long long
using namespace std;
/* --------------- fast io --------------- */ // begin
namespace Fread{
const int SIZE=1<<20;
char buf[SIZE],*S,*T;
inline char getchar(){
	if(S==T){
		T=(S=buf)+fread(buf,1,SIZE,stdin);
		if(S==T)return EOF;
	}
	return *S++;
}
}//namespace Fread
namespace Fwrite{
const int SIZE=1<<20;
char buf[SIZE],*S=buf,*T=buf+SIZE;
inline void flush(){
	fwrite(buf,1,S-buf,stdout);
	S=buf;
}
inline void putchar(char c){
	*S++=c;
	if(S==T)flush();
}
struct _{
	~_(){flush();}
}__;
}//namespace Fwrite

#ifdef ONLINE_JUDGE
	#define getchar Fread::getchar
	#define putchar Fwrite::putchar
#endif

template<typename T>inline void read(T& x){
	x=0;int f=1;
	char c=getchar();
	while(!isdigit(c)){if(c=='-')f=-1;c=getchar();}
	while(isdigit(c))x=x*10+(c-'0'),c=getchar();
	x*=f;
}
template<typename T>inline void write(T x,bool _enter=0,bool _space=0){
	if (!x)putchar('0');else{
		if(x<0)putchar('-'),x=-x;
		static char dig[41];
		int top=0;
		while(x)dig[++top]=(x%10)+'0',x/=10;
		while(top)putchar(dig[top--]);
	}
	if(_enter)putchar('\n');
	if(_space)putchar(' ');
}

namespace Fastio{
struct reader{
	template<typename T>reader& operator>>(T& x){::read(x);return *this;}
	reader& operator>>(char& c){
		c=getchar();
		while(c=='\n'||c==' ')c=getchar();
		return *this;
	}
	reader& operator>>(char* str){
		int len=0;
		char c=getchar();
		while(c=='\n'||c==' ')c=getchar();
		while(c!='\n'&&c!=' ')str[len++]=c,c=getchar();
		str[len]='\0';
		return *this;
	}
}cin;
const char endl='\n';
struct writer{
	template<typename T>writer& operator<<(T x){::write(x,0,0);return *this;}
	writer& operator<<(char c){putchar(c);return *this;}
	writer& operator<<(const char* str){
		int cur=0;
		while(str[cur])putchar(str[cur++]);
		return *this;
	}
}cout;
}//namespace Fastio
#define cin Fastio::cin
#define cout Fastio::cout
#define endl Fastio::endl
/* --------------- fast io --------------- */ // end

const int maxn=100005;
int main(){
		//#define int ll
		int d,t,s;
	while(scanf("%d %d %d",&d,&t,&s)!=EOF){

		if(t*s>=d)
			puts("Yes");
		else
			puts("No");
	 }
	return 0;
}

#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 yn(ans) if(ans)printf("Yes\n");else printf("No\n")
#define YN(ans) if(ans)printf("YES\n");else printf("NO\n")
#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...);}

int main(){
    string s;
    cin>>s;
    if(s=="zyxwvutsrqponmlkjihgfedcba"){
        out(-1);
        return 0;
    }
    if(s.length()<26){
    cout<<s;
    char c='a';
    rep(i,26){
        if(count(all(s),c)==0){
            cout<<c<<endl;
            return 0;
        }
        c++;
    }
    }else if(s.length()==26){
        int n=25,d=0;
        while(1){
            s[n]++;
            if(s[n]>'z'){
                s[n-1]++;
                s.erase(s.begin()+n);
                n--;
            }
            if(s[n]>='a'&&s[n]<='z'&&count(all(s),s[n])==1)break;
        }
        cout<<s<<endl;
    }
}


#include <bits/stdc++.h>

using namespace std;
int arr[4];
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    int d;
    cin>>d;

    if(d==1)
        cout<<"Hello World";
    else
    {
        int a,b;
        cin>>a>>b;

        cout<<a+b;
    }

    return 0;
}

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,a) for(int i=0;i<(a);i++)
const ll MOD=1000000007;
//const ll MOD=998244353;

int main(){
  int M; cin>>M;
  ll sum=0,sumC=0;
  rep(i,M){
    ll d,c; cin>>d>>c;
    sum+=d*c;
    sumC+=c;
  }
  cout<<sumC-1+(sum-1)/9<<endl;
  return 0;
}


#include <iostream>

using namespace std;

class Dice {
private:
	int number[6];
	int state[6];
public:
	Dice();
	~Dice();
	void initialize();
	void setNumber(int index, int num);
	void roll(char d);
	void move(string d);
	int getNumber(int idx);
	int getTop();
	int getSide(int t, int f);
	bool cmp(Dice dice1);
};

Dice::Dice() {
	initialize();
}

Dice::~Dice() {
}

void Dice::initialize() {
	for (int i = 0; i < 6; i++)
		state[i] = i+1;
}

void Dice::setNumber(int index, int num) {
	number[index] = num;
}

void Dice::roll(char d) {
	int nextIndex[4][6] = {
		{1, 5, 2, 3, 0, 4},
		{3, 1, 0, 5, 4, 2},
		{2, 1, 5, 0, 4, 3},
		{4, 0, 2, 3, 5, 1},
	};
	int *idx, nextState[6];
	switch (d) {
		case 'N': idx = nextIndex[0]; break;
		case 'E': idx = nextIndex[1]; break;
		case 'W': idx = nextIndex[2]; break;
		case 'S': idx = nextIndex[3]; break;
		default: return;
	}
	for (int i = 0; i < 6; i++)
		nextState[i] = state[idx[i]];
	for (int i = 0; i < 6; i++)
		state[i] = nextState[i];
}

void Dice::move(string d) {
	int oldIndex[4][6] = {
		{1, 5, 2, 3, 0, 4},
		{3, 1, 0, 5, 4, 2},
		{2, 1, 5, 0, 4, 3},
		{4, 0, 2, 3, 5, 1},
	};
	for (int i = 0; i < d.size(); i++) {
		int newNumber[6] = {0};
		int *idx;
		char c = d[i];
		switch (c) {
			case 'N': idx = oldIndex[0]; break;
			case 'E': idx = oldIndex[1]; break;
			case 'W': idx = oldIndex[2]; break;
			case 'S': idx = oldIndex[3]; break;
			default: return;
		}
		for (int i = 0; i < 6; i++)
			newNumber[i] = number[idx[i]];
		for (int i = 0; i < 6; i++)
			number[i] = newNumber[i];
	}
}

int Dice::getNumber(int idx) {
	return number[state[idx]-1];
}

int Dice::getTop() {
	return getNumber(0);
}

int Dice::getSide(int t, int f) {
	string s = "NNNNENNNN";
	for (int i = 0; i < s.size(); i++) {
		if (number[state[1]-1] == f) {
			break;
		}
		char c = s[i];
		roll(c);
	}
	s = "EEEEE";
	for (int i = 0; i < s.size(); i++) {
		if (number[state[0]-1] == t)
			break;
		char c = s[i];
		roll(c);
	}
	return getNumber(2);
}

bool Dice::cmp(Dice op) {
	string s = "SWWWWNEEEEENEEEENNEEEESEEEEESEEEE";
	for (int i = 0; i < s.size(); i++) {
		char c = s[i];
		op.roll(c);
		int flag = 0;
		for (int i = 0; i < 6; i++)
			if (op.getNumber(i) != number[i]) {
				flag = 1;
				break;
			}
		if (flag == 0)
			return true;
	}
	return false;
}

int main() {
	Dice *dice;
	int n, m;
	cin >> n;
	dice = new Dice[n];
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < 6; j++) {
			cin >> m;
			dice[i].setNumber(j, m);
		}
	}
	for (int i = 0; i < n; i++) {
		for (int j = i + 1; j < n; j++) {
			if (dice[i].cmp(dice[j]) == true) {
				cout << "No" << endl;
				return 0;
			}
		}
	}
	cout << "Yes" << endl;
	return 0;
}

#include <bits/stdc++.h>
using namespace std;
//#include <atcoder/all>
//using namespace atcoder;
template <typename T> bool chmax(T &u, const T z) { if (u < z) {u = z; return true;} else return false; }
template <typename T> bool chmin(T &u, const T z) { if (u > z) {u = z; return true;} else return false; }
#define rep(i, n) for (long long i = 0; i < (long long)(n); i++)
#define ll long long
typedef pair<ll, ll> P;
const ll INF = 1LL << 60;
//const int MOD = 1000000007;
const ll MOD=998244353;
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }

int main(){
  string s;
  cin>>s;
  int n=s.size();
  rep(i,n-1){
    string t=s.substr(i,2);
    if(t=="AC"){
      cout<<"Yes"<<endl;
      return 0;
    }
  }
  cout<<"No"<<endl;
  return 0;
}


#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
using namespace std;
static const double EPS = 1e-5;
typedef long long ll;

int main(){

	int N,Q,M,Date[101],i,l,k;

	while(0<=scanf("%d%d",&N,&Q)){
		for(i=0;i<101;i++){
			Date[i]=0;
		}

		if((N==0) && (Q==0)){
			break;
		}

		for(k=0;k<N;k++){
			scanf("%d",&M);
			if(M==0){
				continue;
			}else{
				for(i=0;i<M;i++){
					scanf("%d",&l);
					++Date[l];
				}
			}
		}
		l=0;
		i=0;
		for(k=0;k<100;k++){
			if(i<Date[k] && Date[k]>=Q){
				i=Date[k];
				l=k;
			}
		}

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

	return 0;
}

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

int main()
{
    for(;;){
        int n, q;
        cin >> n >> q;
        if(n == 0)
            return 0;

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

        int ret = 0;
        for(int i=1; i<=100; ++i){
            if(num[i] >= q && num[i] > num[ret])
                ret = i;
        }
        cout << ret << endl;
    }
}


#include<iostream>
#include<algorithm>
#include<vector>
#include<numeric>
#include<string>
#include<cmath>
#include<set>
#include<queue>
#include<deque>
#include<bitset>
#include<iomanip>
#include<cctype>
#include<map>
#include<cstring>
#include<bitset>
#include<cassert>

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

using namespace std;
using ll = long long int;

const int inf = 1001001000;
const long long int Inf = 1001001001001001000;

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

void print(vector<vector<long long int>> a){
	for (int i=0;i<a.size();i++){
		for (int j=0;j<a[i].size();j++){
			cout << a[i][j] << " ";
		}
		cout << endl;
	}
}

void print(vector<int> a){
    int n = a.size();
    for (int j=0;j<n;j++) {
        if (j != n-1) cout << a[j] << " ";
        else cout << a[j] << endl;
    }
}

void print(vector<long long int> a){
    int n = a.size();
    for (int j=0;j<n;j++) {
        if (j != n-1) cout << a[j] << " ";
        else cout << a[j] << endl;
    }
}

void print(set<int> a){
	for (auto x:a)
		cout << x << " ";
	cout << endl;
}

//nの約数を返す関数.sortされてない.
vector<long long int> divisors(long long int n){
	vector<long long int> res;
	for (long long int i = 1; i * i <= n;i++){
		if (n % i == 0){
			res.push_back(i);
			if(i * i != n){
				res.push_back(n / i);
			}
		}
	}
	return res;
}

int main()
{
	ll n;
	cin >> n;
	vector<ll> d = divisors(n);
	int ans = inf;
	for (auto x : d)
	{
		ans = min(max(int(to_string(x).size()), int(to_string(n/x).size())),ans);
	}
	cout << ans << endl;

	return 0;
}

#include<iostream>
#include<cmath>
using namespace std;
int main()
{
  int r;
  cin>>r;
  double pi=3.147;
  double ans=pi*2*r;
  cout<<ans<<endl;
return 0;
}


#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <cmath>
#include <iomanip>
#include <set>
#include <sstream>
#include <queue>
using namespace std;
typedef long long ll;

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

  vector<int> west_sum(n);
  vector<int> east_sum(n);

  for (int i = 1; i < n; i++) {
    if (s[i-1] == 'W') {
      west_sum[i] = west_sum[i-1] + 1;
    } else {
      west_sum[i] = west_sum[i-1];
    }
  }

  for (int i = n-2; i >= 0; i--) {
    if (s[i+1] == 'E') {
      east_sum[i] = east_sum[i+1] + 1;
    } else {
      east_sum[i] = east_sum[i+1];
    }
  }

  int ans = 1e9;
  for (int i = 0; i < n; i++) {
    if (i == 0) {
      ans = min(ans, east_sum[i]);
    } else if (i == n-1) {
      ans = min(ans, west_sum[i]);
    } else {
      ans = min(ans, west_sum[i] + east_sum[i]);
    }
  }

  cout << ans << endl;

  return 0;
}

#include<iostream>
#include<string.h>
#include<string>
#include<stdio.h>
#include<algorithm>
#include<vector>
#include<bitset>
#include<math.h>
#include<stack>
#include<queue>
#include<set>
#include<map>
using namespace std;
typedef long long ll;
typedef long double db;
typedef pair<int,int> pii;
const int N=100000;
const db pi=acos(-1.0);
#define lowbit(x) (x)&(-x)
#define sqr(x) (x)*(x)
#define rep(i,a,b) for (register int i=a;i<=b;i++)
#define per(i,a,b) for (register int i=a;i>=b;i--)
#define go(u,i) for (register int i=head[u];i;i=sq[i].nxt)
#define fir first
#define sec second
#define mp make_pair
#define pb push_back
#define maxd 1000000007
#define eps 1e-8
inline int read()
{
    int x=0,f=1;char ch=getchar();
    while ((ch<'0') || (ch>'9')) {if (ch=='-') f=-1;ch=getchar();}
    while ((ch>='0') && (ch<='9')) {x=x*10+(ch-'0');ch=getchar();}
    return x*f;
}

namespace My_Math{
	#define N 100000

	int fac[N+100],invfac[N+100];

	int add(int x,int y) {return x+y>=maxd?x+y-maxd:x+y;}
	int dec(int x,int y) {return x<y?x-y+maxd:x-y;}
	int mul(int x,int y) {return 1ll*x*y%maxd;}
	ll qpow(ll x,int y)
	{
		ll ans=1;
		while (y)
		{
			if (y&1) ans=mul(ans,x);
			x=mul(x,x);y>>=1;
		}
		return ans;
	}
	int inv(int x) {return qpow(x,maxd-2);}

	int c(int n,int m)
	{
		if ((n<m) || (n<0) || (m<0)) return 0;
		return mul(mul(fac[n],invfac[m]),invfac[n-m]);
	}

	int math_init()
	{
		fac[0]=invfac[0]=1;
		rep(i,1,N) fac[i]=mul(fac[i-1],i);
		invfac[N]=inv(fac[N]);
		per(i,N-1,1) invfac[i]=mul(invfac[i+1],i+1);
	}
	#undef N
}
using namespace My_Math;
int n,A,B,C,D,f[1010][1010];

int main()
{
	n=read();A=read();B=read();C=read();D=read();
	math_init();
	f[0][0]=1;
	rep(i,1,B-A+1)
	{
		int t=i+A-1;
		rep(j,0,n)
		{
			f[i][j]=f[i-1][j];
			rep(k,C,D)
			{
				if (k*t>j) continue;
				int tmp=mul(f[i-1][j-k*t],c(n-j+k*t,k*t));
				tmp=mul(mul(tmp,invfac[k]),mul(qpow(invfac[t],k),fac[k*t]));
				f[i][j]=add(f[i][j],tmp);
			}
		}
	}
	printf("%d",f[B-A+1][n]);
	return 0;
}


#include <bits/stdc++.h>

#define pb push_back
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define debug(x) cerr << #x << " : " << x << '\n'

using namespace std;

typedef long long ll;
typedef long double ld;
typedef string str;
typedef pair<ll, ll> pll;

const ll Mod = 998244353;
const int N = 4e3 + 10;
const ll Inf = 2242545357980376863LL;
const ll Log = 30;

ll mul(ll a, ll b){
	return (a*b) % Mod;
}
ll p2[N], C[N][N];

ll Solve(ll n, ll s){
	if(n == 0 && s == 0) return 1;
	if(s < 0) return 0;
	if(n <= 0) return 0;
	return C[s + n - 1][s];
}

int main(){
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	p2[0] = 1;
	for(int i = 1; i < N; i++) p2[i] = (p2[i - 1] << 1) % Mod;
	for(int i = 0; i < N; i++){
		for(int j = 0; j <= i; j++) C[i][j] = (j ? C[i - 1][j] + C[i - 1][j - 1] : 1) % Mod;
	}
	ll n, k;
	cin >> k >> n;
	for(int i = 2; i <= k+k; i++){
		ll res = 0;
		if(i & 1){
			ll t = (i <= k + 1 ? i / 2 : (k + k + 2 - i) / 2);
			for(int y = 0; y <= t; y++){
				res += mul(mul(p2[y], C[t][y]), Solve(k - t - t + y, n - y));
			}
		} else {
			ll t = (i <= k + 1 ? i / 2 : (k + k + 2 - i) / 2) - 1;
			for(int y = 0; y <= t; y++){
				res += mul(mul(p2[y], C[t][y]), Solve(k - t - t - 1 + y, n - y - 1));
				res += mul(mul(p2[y], C[t][y]), Solve(k - t - t - 1 + y, n - y));
			}
		}
		cout << res%Mod << '\n';
	}
	return 0;
}

/*
[arc102] E - Stop. Otherwise...
*/

#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long int ll;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;

const int MAX_Z = 2000 * 2 + 2;
const ll MOD = 998244353;

int K, N;
int fact[MAX_Z + 1];
int ifac[MAX_Z + 1];
int pow2[MAX_Z + 1];

void prepare() {
    int inv[MAX_Z + 1];
    fact[1] = fact[0] = 1;
    ifac[1] = ifac[0] = 1;
    inv[1] = 1;
    for (int i = 2; i <= MAX_Z; i++) {
        fact[i] = 1LL * i * fact[i - 1] % MOD;
        inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
        ifac[i] = 1LL * ifac[i - 1] * inv[i] % MOD;
    }

    pow2[0] = 1;
    for (int i = 1; i <= MAX_Z; i++) {
        pow2[i] = (2LL * pow2[i - 1]) % MOD;
    }
}

int comb(int n, int r) {
    if (n < 0 || r < 0 || n < r) {
        return 0;
    }
    return (1LL * fact[n] * ifac[n - r]) % MOD * ifac[r] % MOD;
}
int hcomb(int n, int r) {
    if (n == 0 && r == 0) {
        return 1;
    }
    return comb(n + r - 1, r);
}

ll solve(int t) {
    ll ans = 0;

    int p = 0;
    for (int j = 1; j <= K; j++) {
        if (j < t - j && t - j <= K) p++;
    }

    for (int q = 0; q <= min(N, p); q++) {
        ll c = (1LL * pow2[q] * comb(p, q)) % MOD;
        if (t % 2 == 0) {
            (c *= ((hcomb(K - 2 * p + q - 1, N - q) +
                    hcomb(K - 2 * p + q - 1, N - q - 1)) %
                   MOD)) %= MOD;
        } else {
            (c *= hcomb(K - 2 * p + q, N - q)) %= MOD;
        }
        (ans += c) %= MOD;
    }

    return ans;
}

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

    prepare();

    for (int t = 2; t <= 2 * K; t++) {
        cout << solve(t) << endl;
    }

    return 0;
}


#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstring>
#include <map>
#include <queue>
#include <stack>
#include <set>
#include <functional>
#include <sstream>
#include <complex>
#include <climits>
using namespace std;

#define REP(i,a,n) for(int i=(a);i<(int)(n);i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define mp make_pair
#define all(x) x.begin(),x.end()
#define EPS 1e-8

int main(){
	int m,d;
	const int day[] = {31,29,31,30,31,30,31,31,30,31,30,31};
	const char *youbi[] = {
		"Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"
	};
	while(scanf("%d",&m),m){
		scanf("%d",&d);
		int sum = 0;
		rep(i,m-1)sum+=day[i];
		sum += d;
		puts(youbi[(sum+2)%7]);
	}
	return 0;
}

#include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <stack>
#include <set>
#include <cmath>
#include <algorithm>
using namespace std;

int zeller(int y , int m , int d){
	if(m==1 || m==2) {m+=12; y-=1;}
	return(y + y/4 - y/100 + y/400 + ((13*m+8)/5) + d )%7;
}

int main(){
	int m , d , w=4 , fw;
	while (cin >> m >> d, m){
		switch(zeller(2004,m,d)){
			case 0:
			cout << "Sunday" << endl;
			break;
			case 1:
			cout << "Monday" << endl;
			break;
			case 2:
			cout << "Tuesday" << endl;
			break;
			case 3:
			cout << "Wednesday" << endl;
			break;
			case 4:
			cout << "Thursday" << endl;
			break;
			case 5:
			cout << "Friday" << endl;
			break;
			case 6:
			cout << "Saturday" << endl;
		}
	}
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

class Dice{

public:
    unique_ptr<vector<int>> nums;

    Dice(int n){
        nums.reset(new vector<int>(6));
    }

    void rotate(char dir){
        int a, b, c, d;
        switch(dir){
        case 'N':
            a = nums->at(0), b = nums->at(1), c = nums->at(5), d = nums->at(4);
            nums->at(0) = b;
            nums->at(1) = c;
            nums->at(5) = d;
            nums->at(4) = a;
            break;
        case 'E':
            a = nums->at(0), b = nums->at(2), c = nums->at(5), d = nums->at(3);
            nums->at(0) = d;
            nums->at(2) = a;
            nums->at(5) = b;
            nums->at(3) = c;
            break;
        case 'W':
            a = nums->at(0), b = nums->at(2), c = nums->at(5), d = nums->at(3);
            nums->at(0) = b;
            nums->at(2) = c;
            nums->at(5) = d;
            nums->at(3) = a;
            break;
        case 'S':
            a = nums->at(0), b = nums->at(1), c = nums->at(5), d = nums->at(4);
            nums->at(0) = d;
            nums->at(1) = a;
            nums->at(5) = b;
            nums->at(4) = c;
            break;
        }
    }

};

int main()
{

    Dice d(6);
    for(int i = 0; i < 6; i++){
        cin >> d.nums->at(i);
    }
    string s;
    cin >> s;
    for(char c: s){
        d.rotate(c);
    }
    cout << d.nums->at(0) << endl;
}

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

class Dice {
public:
    static int rollingface[][4];
    int face[6];
    Dice(string &face_data);
    // ~Dice();
    void roll(const char &op);
    int top();
    void print_faces();
};

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

Dice::Dice(string &face_data) {
    istringstream bstrm;
    bstrm.str(face_data);
    for (int i = 0; i < 6; i++) {
        bstrm >> 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;
    }
}

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;
}

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

int main() {
    string buf, op_seq;
    int i;
    Dice *dice;

    getline(cin, buf);
    dice = new Dice(buf);
    getline(cin, op_seq);
    for (i = 0; i < op_seq.size(); i++) {
        dice->roll(op_seq[i]);
        // dice->print_faces();
    }
    cout << dice->top() << endl;

    return 0;
}