#include<bits/stdc++.h>
using namespace std;
#define int long long
typedef long long ll;
long long t,n,m,k,ccnt,pos=0,sum=0,minn2=INT_MAX,sum2,cnt=0,cnt1=0,cnt2=0,cnt3=0,cnt4=0,cnt5=0,cnt6=0,cnt7=0,a[2000005],x1,y7,x2,y2,x3,y3,aaa,bbb;
long long vis1[1005][1005],vis2[1005][1005],b[1000005],c[1000005],c3[2005][2005],c4[1000005],kk[1000005],x,y,z,d=0,l2,r2;
long long pos1=0,pos2=0,tem,tem2,l,r,ans=0,ans2,mod=998244353,tw[100005],th[100005],dd,ee,out[1000005],te[100005];
long long minn=LONG_LONG_MAX,maxx=-LONG_LONG_MAX,maxx2;
string s1,s2,s;
char cc[2005][2005],ch;
pair<int,int> p[200005];
vector<int> v[200005];
long long fpow(long long aa,long long bb)
{
    if(bb==0)
    {
        return 1;
    }
    else if(bb<0)
    {
        return 0;
    }
    long long kk1=aa;
    long long kk2=1;
    while(bb>1)
    {
        if(bb%2)
        {
            kk2*=kk1;
            kk2%=mod;
        }
        kk1*=kk1;
        kk1%=mod;
        bb=bb/2;
    }
    return (kk1*kk2)%mod;
}
long long co(long long x,long long y)
{
    long long ans=1;
    long long ans2=1;
    if(x==y||y==0)
    {
        return 1;
    }
    else
    {
        for(int i=x-y+1;i<=x;i++)
        {
            ans=ans*i;
            ans=ans%mod;
        }
        for(int i=1;i<=y;i++)
        {
            ans2=ans2*i;
            ans2=ans2%mod;
        }
        ans2=fpow(ans2,mod-2);
        ans2=(ans2*ans)%mod;
        return ans2;
    }
}
signed main()
{
    cin.tie(0);
    cout.tie(0);
    ios_base::sync_with_stdio(0);
    cin>>s;
    d=1;
    for(int i=0;i<s.size();i++)
    {
        if(i%2==0)
        {
            if(s[i]-'a'<0)
            {
                d=0;
                break;
            }
        }
        else
        {
            if(s[i]-'A'>=26)
            {
                d=0;
                break;
            }
        }
    }
    if(d)
    {
        cout<<"Yes";
    }
    else
    {
        cout<<"No";
    }

}

#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef pair<ll, ll> p_ll;

template<class T>
void debug(T itr1, T itr2) { auto now = itr1; while(now<itr2) { cout << *now << " "; now++; } cout << endl; }
#define repr(i,from,to) for (ll i=(ll)from; i<(ll)to; i++)
#define all(vec) vec.begin(), vec.end()
#define rep(i,N) repr(i,0,N)
#define per(i,N) for (ll i=(ll)N-1; i>=0; i--)

const ll MOD = pow(10,9)+7;
const ll LLINF = pow(2,61)-1;
const ll INF = pow(2,30)-1;

vector<ll> fac;
void c_fac(ll x=pow(10,6)+10) { fac.resize(x,true); rep(i,x) fac[i] = i ? (fac[i-1]*i)%MOD : 1; }
ll inv(ll a, ll m=MOD) { ll b = m, x = 1, y = 0; while (b!=0) { ll d = a/b; a -= b*d; swap(a,b); x -= y*d; swap(x,y); } return (x+m)%m; }
ll nck(ll n, ll k) { return fac[n]*inv(fac[k]*fac[n-k]%MOD)%MOD; }
ll modpow(ll x, ll p) { ll result = 1, now = 1, pm = x; while (now<=p) { if (p&now) { result = result * pm % MOD; } now*=2; pm = pm*pm % MOD; } return result; }
ll gcd(ll a, ll b) { if (a<b) swap(a,b); return b==0 ? a : gcd(b, a%b); }
ll lcm(ll a, ll b) { return a/gcd(a,b)*b; }

int main() {
  ll T; cin >> T;
  rep(_,T) {
    ll N, A, B; cin >> N >> A >> B;
    if (A+B>N) { cout << 0 << endl; continue; }
    ll t1 = (N-A-B+1) * (N-A-B+2) / 2 % MOD;
    ll x1 = t1 * t1 % MOD, x2 = t1 * ((N-A+1)*(N-B+1)%MOD) % MOD;
    ll result = (x2-x1+MOD) * 4 % MOD;
    cout << result << endl;
  }
  return 0;
}


#include <iostream>
#include<cmath>
#include<iomanip>
using namespace std;
typedef long long int LL;
LL x[100000];
int main(void){
    cout<<setprecision(16);
    LL n,i,j;
    LL ans;
    long double dans;
    cin>>n;
    for(i=0;i<n;i++)cin>>x[i];

    ans=0;
    for(i=0;i<n;i++)ans+=abs(x[i]);
    cout<<ans<<endl;

    dans=0.0;
    for(i=0;i<n;i++)dans+=(double)(x[i]*x[i]);
    cout<<sqrt(dans)<<endl;

    ans=0;
    for(i=0;i<n;i++)if(ans<abs(x[i]))ans=abs(x[i]);
    cout<<ans<<endl;
}

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

//debug用出力関数 dout("n",n);
void dout(string s, int n) {
	cout << s << ":" << n << endl;
	return;
}

int main() {

	int n,ans = 100000;
	cin >> n;
	vector<int> a(n);
	vector<int> b(n);
	vector<int> c(n);

	rep(i,n){
		cin >> a.at(i) >> b.at(i);
	}

	for (int i = 0; i < n; i++){
		for (int j = 0; j < n; j++){
			if(i == j){
				ans = min(ans,a.at(i) + b.at(j));
			} else {
				ans = min(ans,max(a.at(i),b.at(j)));
			}
		}
	}

	cout << ans << endl;
}


#include "bits/stdc++.h"
#define FI first.first
#define SE first.second
#define TH second
#define fi first
#define se second
#define th second

using namespace std;

template<typename T>
string to_string(const vector<T>& vc, int w) {
	if(vc.empty()) return "";
	if(w + 1 == vc.size()) return to_string(vc[w]);
	return to_string(vc[w]) + "," + to_string(vc, w + 1);
}

template<typename T>
string to_string(const vector<T>& vc) {
	return "{" + to_string(vc, 0) + "}";
}

void debug_out() { cerr << endl; }

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

#ifdef DEBUG
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

class DebugStream {}LOG;
template <typename T>DebugStream &operator<<(DebugStream &s, const T&) { return s; }
#ifdef DEBUG
#define LOG clog
#endif

typedef long long ll;
typedef pair<ll, ll> ii;
typedef long double ld;
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());

const int maxN = 1e5 + 9, maxV = 1e6 + 9, MOD = 1e9 + 7, SQ = 335, lg = 20, bs = 29;

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

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	#ifdef DEBUG
	freopen("input.txt", "r", stdin);
	#endif

	int t;
	cin >> t;
	while(t--) {
		ll n, s, k, x, y;
		cin >> n >> s >> k;
		k %= n;
		ll gg = gcd(n, k, x, y);
		ll nm = n - s;
		if(y < 0) y = (n - abs(y) % n) % n;
		else y %= n;

		if(nm % gg) {
			cout << "-1\n"; continue;
		}
		nm /= gg;
		n /= gg;

		ll ans = nm * y % n;
		cout << ans << '\n';
	}

}

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
pair <ll,ll> extgcd(ll a,ll b)
{
	if (b==0) return {1,0};
	pair<ll,ll> u=extgcd(b,a%b);
	return {u.second,u.first-a/b*u.second};

}
ll gcd(ll x,ll y)
{
	if(y==0) return x;
	return gcd(y,x%y);
}
void solve ()
{
	ll n,s,k;
	cin>>n>>s>>k;
	if (s%gcd(n,k)!=0) cout<<-1<<endl;
	else
	{
		ll e=gcd(n,k);
		n=n/e;
		s=s/e;
		k=k/e;
		pair<ll,ll> v=extgcd(k,n);
		cout<<((-v.first*s)%n+n)%n<<endl;
	}
}
int main()
{
	int t;
	cin>>t ;
	while (t--)
	{
		solve ();
	}
	return 0;
 }


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

int main(){
    long n, q;
    cin >> n >> q;
    long a[n], k[q];
    long b[n];
    vector <pair <long, long>> v;
    vector <long> ans(q);
    for(int i = 0; i < n; i++){
        cin >> a[i];
        if(i == 0) b[i] = a[i] - 1;
        else b[i] = b[i - 1] + a[i] - a[i - 1] - 1;
    }

    for(int i = 0; i < q; i++){
        cin >> k[i];
        v.push_back(make_pair(k[i], i));
    }

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

    long x, y, z, P, W;

    W = 0;

    for(int i = 0; i < q; i++){
        P = 0;
        for(int j = W; j < n; j++){
            if(v[i].first <= b[j]){
                x = a[j];
                y = b[j] - v[i].first;
                z = x - y - 1;

                P = 1;
                W = j;
                break;
            }
        }
        if(P == 1) ans[v[i].second] = z;
        else{
            ans[v[i].second] =  n + v[i].first;
            W = n;
        }
    }

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

}

#include<ctime>
#include<cstdio>
#include<cctype>
#include<algorithm>
using namespace std;
const int N=50+5;
int read() {
	char c;
	int x=0,f=1;
	while(!isdigit(c=getchar()))
		f-=2*(c=='-');
	while (isdigit(c)){
		x=x*10+(c-48)*f;
		c=getchar();
	}
	return x;
}
struct bag{
	int w,v;
	bag(int a=0,int b=0){
		w=a;
		v=b;
	}
	bool operator <(bag b){
		return v>b.v;
	}
};
bag a[N];
int n,m,q,l,r,x[N],vis[N];
int main() {
	#ifndef ONLINE_JUDGE
	freopen("D.in","r",stdin);
	freopen("D.out","w",stdout);
	#endif
	clock_t t1=clock();
	//--------
	n=read();
	m=read();
	q=read();
	for(int i=1;i<=n;++i){
		int w=read();
		int v=read();
		a[i]=bag(w,v);
	}
	sort(a+1,a+n+1);
	for(int i=1;i<=m;++i)
		x[i]=read();
	for(int i=1;i<=q;++i){
		l=read();
		r=read();
		int cnt=0;
		int res=0;
		int sz=m-(r-l+1);
		for(int j=1;j<=m;++j)
			vis[j]=0;
		for(int j=1;j<=n;++j){
			if(cnt==sz)
				break;
			int pos=0;
			for(int k=1;k<l;++k){
				if(x[k]<a[j].w)
					continue;
				if(vis[k])
					continue;
				if(!pos||x[k]<x[pos])
					pos=k;
			}
			for(int k=m;k>r;--k){
				if(x[k]<a[j].w)
					continue;
				if(vis[k])
					continue;
				if(!pos||x[k]<x[pos])
					pos=k;
			}
			if(pos){
				++cnt;
				vis[pos]=1;
				res+=a[j].v;
			}
		}
		printf("%d\n",res);
	}
	//--------
	clock_t t2=clock();
	fprintf(stderr,"time:%0.3lfs",1.0*(t2-t1)/CLOCKS_PER_SEC);
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
    ll n,s,d,x,y;
   cin>>n>>s>>d;
    int f=0;
    while(n--){
        scanf("%lld%lld",&x,&y);
        if(x<s&&y>d)
        f++;
    }
    if(!f)
        printf("No\n");
    else printf("Yes\n");
}

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

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

int main() {
	int x, y, z;
	cin >> x >> y >> z;
	int ans = 1000*1000;
	while (ans * x >= z * y) ans--;
	cout << ans << endl;
}


#include <bits/stdc++.h>
#define ll long long
using namespace std;
const ll mod = 1e9 + 7;

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n,m;
    cin >> n >> m;
    vector<int> a(n);
    vector<int> b(m);
    for(int &x:a) cin >> x;
    for(int &x:b) cin >> x;
    int h1, h2;
    h1 = h2 = 0;
    vector<int> res;
    while(h1 < n && h2 < m){
        if (a[h1] == b[h2]) {
            h1++;
            h2++;
        } else
        if (a[h1] < b[h2]){
            res.push_back(a[h1]);
            h1++;
        } else {
            res.push_back(b[h2]);
            h2++;
        }
    }
    while (h1 < n) res.push_back(a[h1++]);
    while (h2 < m) res.push_back(b[h2++]);
    for(int x:res) cout << x << ' ';
}

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

const int inf = 1e8;
const ll llinf = 1e18;
const double PI = acos(-1);
#define yes "Yes"
#define no "No"
#define all(n) n.begin(), n.end()

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

struct UnionFind {
  vector<int> par, siz;
  UnionFind(int n) : par(n, -1), siz(n, 1) {}
  int root(int x) {
    if (par[x] == -1) return x;
    return par[x] = root(par[x]);
  }
  bool isSame(int x, int y) { return root(x) == root(y); }
  bool unite(int x, int y) {
    x = root(x), y = root(y);
    if (x == y) return false;
    if (siz[x] < siz[y]) swap(x, y);
    par[y] = x;
    siz[x] += siz[y];
    return true;
  }
  int size(int x) { return siz[root(x)]; }
};

using Graph = vector<vector<int>>;
vector<int> visited(false);

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

void dfs(const Graph &G, int v) {
  visited[v] = true;
  for (auto next : G[v]) {
    if (visited[next]) continue;
    dfs(G, next);
  }
}

bool isPrime(ll n) {
  if (n < 2) return false;
  for (ll i = 2; i * i <= n; ++i)
    if (n % i == 0) return false;
  return true;
}

// 最大公約数
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }

// 最小公倍数
ll lcm(ll a, ll b) { return abs(a) / gcd(a, b) * abs(b); }

ll gcd2(const vector<ll> &v) {
  ll val = v[0];
  for (ll i = 1; i < v.size(); ++i) val = gcd(val, v[i]);
  return val;
}

ll lcm2(const vector<ll> &v) {
  ll val = v[0];
  for (ll i = 1; i < v.size(); ++i) val = lcm(val, v[i]);
  return val;
}

vector<ll> divisors(ll n) {
  vector<ll> a;
  for (ll i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      a.push_back(i);
      if (n / i != i) a.push_back(n / i);
    }
  }
  sort(a.begin(), a.end());
  return a;
}

// pairを要素に持つvectorをsecondを基準にソートする比較関数
bool comp(pair<ll, ll> a, pair<ll, ll> b) { return a.second < b.second; }

vector<int> eratosthenes(int n) {
  vector<bool> is_prime(n + 1, true);
  vector<int> p;
  for (int i = 2; i <= n; ++i) {
    if (is_prime[i]) {
      for (int j = i * 2; j <= n; j += i) {
        is_prime[j] = false;
      }
      p.push_back(i);
    }
  }
  return p;
}

int main() {
  int n, m;
  cin >> n >> m;
  vector<bool> a(1010, false), b(1010, false);
  rep(i, n) {
    int v;
    cin >> v;
    a[v] = true;
  }
  rep(i, m) {
    int v;
    cin >> v;
    b[v] = true;
  }

  for (int i = 1; i < 1010; ++i) {
    if ((a[i] && !b[i]) || (!a[i] && b[i])) cout << i << " ";
  }
  // cout << fixed << setprecision(9) << ans << endl;
}


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

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

    ll ans = 0;
    vector<int> v(26, 0);
    int len = s.length();
    v[s[len-1]-'a']++;
    v[s[len-2]-'a']++;
    char prev = '0';
    int x = len;
    for (int i = len-3; i >= 0; i--) {
        if (s[i] == s[i+1] && s[i+1] != s[i+2]) {
            if (s[i] == prev) ans += x - (i+2) - (v[s[i]-'a']-1);
            else ans += len - (i+2) - (v[s[i]-'a']-1);
            for (auto &x : v) x = 0;
            prev = s[i];
            x = i;
        }
        else v[s[i]-'a']++;
    }
    cout << ans << endl;
}

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

int main(){
    int N;
    cin >> N;
    vector<int> prime_number;
    vector<int> used(N+1);
    for (int i=2; i<=N; i++){
        if (used.at(i)==0){
            prime_number.push_back(i);
            int num = 2*i;
            while (num<=N){
                used.at(num)=1;
                num += i;
            }
        }
    }
    vector<int> ans(N+1);
    ans.at(1)=1;
    for (int i=1; i<=N; i++){
        int num = i;
        int index = 0;
        while(index<=(int)prime_number.size()-1&&num<=N){
            num = i*prime_number.at(index);
            if (num<=N) ans.at(num) = ans.at(i)+1;
            index++;

        }
    }
    for (int i=1; i<=N; i++){
        cout << ans.at(i) << " ";
    }
    cout << endl;
}


#include<bits/stdc++.h>
using namespace std;
template <typename T>
void read(T &x)
{
	T f = 1; x = 0;
	char ch = getchar();
	for (; !isdigit(ch); ch = getchar()) if (ch == '-') f = -1;
	for (; isdigit(ch); ch = getchar()) x = x * 10 + ch - '0';
	x *= f;
}
template <typename T>
void write(T x)
{
	if (x < 0)
	{
		putchar('-');
		x = -x;
	}
	if (x > 9) write(x / 10);
	putchar(char(x % 10 + 48));
}
template <typename T>
void writeln(T x, char ch = '\n')
{
	write(x);
	putchar(ch);
}
int n, m, k;
int main()
{
	read(n); read(m); read(k);
	cout << (n - m + k) << endl;
	return 0;
}

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

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

  for(int i=0;i<K;i++){
    S=to_string(N);
    sort(S.begin(), S.end());

    A=stoi(S);

    reverse(S.begin(), S.end());

    N=stoi(S)-A;
  }
  cout << N << endl;
}


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

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

int main() {
    vec<string> s(3); cin >> s;

    set<char> st;
    rep(i, 3) {
        for(auto &c : s[i]) st.insert(c);
    }

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

    vector<char> ch;
    for(auto &c : st) ch.push_back(c);
    while(ch.size() < 10) ch.push_back('0');
    sort(ch.begin(), ch.end());

    vec<int> num(26, -1);

    auto tol = [&](string str) -> ll {
        ll res = 0, x = 1;
        for(int i = str.size() - 1; i >= 0; --i) {
            res += x * num[str[i] - '0'];
            x *= 10;
        }
        return res;
    };

    do {
        rep(i, 10) {
            if(ch[i] == '0') continue;
            num[ch[i] - '0'] = i;
        }
        ll a = tol(s[0]);
        ll b = tol(s[1]);
        ll c = tol(s[2]);
        if(!a || !b || !c) continue;;
        if(to_string(a).size() != s[0].size()) continue;
        if(to_string(b).size() != s[1].size()) continue;
        if(to_string(c).size() != s[2].size()) continue;
        if(a + b == c) {
            cout << a << '\n';
            cout << b << '\n';
            cout << c << '\n';
            return 0;
        }

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

    cout << "UNSOLVABLE" << '\n';
    return 0;
}

//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
//#include <atcoder/all>
//using namespace atcoder;
using namespace std;
#define all(v) v.begin(), v.end()
using in = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
#define YES cout<<"YES"<<endl
#define NO cout<<"NO"<<endl
const in MOD = 1000000007;
const in INF=(in)1e18+7;
const int inf=max(int(1e18)+7,int(1e9)+7);
using P=pair<int,int>;
using T=tuple<int,int,int>;
vector<int> dx={0,1,-1,0};
vector<int> dy={1,0,0,-1};
template <typename Typ>
bool chmin(Typ &a, const Typ& b) {if (a > b) {a = b; return true;} return false;}
template <typename Typ>
bool chmax(Typ &a, const Typ& b) {if (a < b) {a = b; return true;} return false;}
template <typename Typ>
Typ ceil(Typ x, Typ y){return (x+y-1)/y;}
#ifdef  _DEBUG
    #define debug(x) cout<<"debug:"<<x<<endl
    #define vdebug(x) cout<<"debug:";\
                      for(auto asdf:x) cout<<asdf<<" ";\
                      cout<<endl
#else
    #define debug(x)
    #define vdebug(x)
#endif

int main(){
ios::sync_with_stdio(false);cin.tie(nullptr);
//cout << fixed << setprecision(12);
    int n,m;  cin>>n>>m;
    vector<int> a(m),b(m);
        rep(i,m) cin>>a[i]>>b[i];
    int k;  cin>>k;
    vector<int> c(k),d(k);
        rep(i,k) cin>>c[i]>>d[i];
    int ans=0;
    for(int tmp = 0;tmp< (1<<k); tmp++){
        bitset<16> bt(tmp);
        vector<bool> num(n,false);
        rep(i,k){
            if(bt.test(i)) num[d[i]-1]=true;
            else num[c[i]-1]=true;
        }
        int cnt=0;
        rep(i,m){
            if(num[a[i]-1] and num[b[i]-1]) cnt ++;
        }
        chmax(ans,cnt);
    }
    cout<<ans<<"\n";

}/*
./problem.exe
*/


#include <bits/stdc++.h>
using namespace std;
// clang-format off
using ll = int64_t;
template <class T>
istream& operator>>(istream& is, vector<T>& v) {
    for (auto& a : v) cin >> a;
    return is;
}
template <class T>
istream& operator>>(istream& is, vector<pair<T, T>>& v) {
    for (auto& a : v) cin >> a.first >> a.second;
    return is;
}
template <class T>
istream& operator>>(istream& is, vector<tuple<T, T, T>>& v) {
    for (auto& a : v) {
        T a1, a2, a3;
        cin >> a1 >> a2 >> a3;
        a = {a1, a2, a3};
    }
    return is;
}
template <class T>
ostream& operator<<(ostream& os, vector<T>& v) {
    for (auto& a : v) os << a << " ";
    os << endl;
    return os;
}
template<class T>
bool chmin(T &a, T b) {
    if (a > b) { a = b; return true; }
    return false;
}
template<class T>
bool chmax(T &a, T b) {
    if (a < b) { a = b; return true; }
    return false;
}
#define all(v) begin(v), end(v)
#define TRC1(a) cout << #a ":" << a
#define TRC2(a, b) TRC1(a); cout << " "; TRC1(b)
#define TRC3(a, b, c) TRC2(a, b); cout << " "; TRC1(c)
#define TRC4(a, b, c, d) TRC3(a, b, c); cout << " "; TRC1(d)
using veci = vector<int>;
using vecll = vector<ll>;
using Pi = pair<int, int>;
using Ti = tuple<int, int, int>;
#define rep(i, n) for (int i = 0; i < n; i++)
#define fore(x, v) for (auto x : v)
const int IINF = INT32_MAX;
const ll LINF = INT64_MAX;
// cout << fixed << setprecision(15);
void solve();
int main() { cout << fixed << setprecision(15); solve(); return 0; }
// clang-format on

void solve() {
    double R, X, Y;
    cin >> R >> X >> Y;
    double d = sqrt(X * X + Y * Y);
    if (d == R) {
        cout << 1 << endl;
        return;
    }
    if (d <= 2 * R) {
        cout << 2 << endl;
        return;
    }

    ll ans = ceil(d / R);
    cout << ans << endl;
}

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

int main() {
 ll R,X,Y;
  cin>>R>>X>>Y;
 ll count=0;
 ll r=0;

 while(r<X*X+Y*Y){
   if(R*R>X*X+Y*Y){
   	count=2;
     break;
   }
 	count++;
   r=(count*R)*(count*R);

 }
  cout<<count<<endl;
}


#include <bits/stdc++.h>
using namespace std;
using namespace std::chrono;
#define idfc ios_base::sync_with_stdio(false),cin.tie(nullptr)
//:/
#define pb push_back
#define mp make_pair
#define nt _ll128
#define ld long double
long double PI =3.14159265;
using ll = long long;

const ll modo=998244353;
const ll ms=2e5+5;
const ll inf=1e17;

ll ar[ms][2];
ll op[ms][2];
ll ans[ms][2];
vector<pair<ll,ll>> vv[ms];

int main()
{
    idfc;

    ll n;
    cin>>n;
    ll i;
    ll x,y;
    ll a,b;

    for(i=1;i<=n;i++)
    {
        cin>>ar[i][0]>>ar[i][1];
    }
    ll m;
    cin>>m;

    for(i=1;i<=m;i++)
    {
        cin>>op[i][0];
        if(op[i][0]>2)cin>>op[i][1];
    }

    ll q;
    cin>>q;

    for(i=1;i<=q;i++)
    {
        cin>>x>>y;
        vv[x].pb({y,i});
    }

    for(auto ii:vv[0])
    {
        ans[ii.second][0]=ar[ii.first][0];
        ans[ii.second][1]=ar[ii.first][1];
    }
    ll t;
    ll p;
    ll tot=0;

    x=0;
    y=0;
    a=0;
    b=0;
    ll tmp;
    ll t2=0;
    ll t3=0;

    for(i=1;i<=m;i++)
    {
        t=op[i][0];
        p=op[i][1];
        if(t==1)
        {
            tot=(tot+1)%2;
            if(tot)
            {
                x=-x;
                t2=(t2+1)%2;
            }
            else{
                y=-y;
                t3=(t3+1)%2;
            }
        }
        else if(t==2)
        {
            tot=(tot+1)%2;
            if(tot)
            {
                y=-y;
                t3=(t3+1)%2;
            }
            else{
                x=-x;
                t2=(t2+1)%2;
            }
        }
        else if(t==3)
        {
            if(!tot)
            {
                x=p-x;
                t2=(t2+1)%2;
            }
            else{
                y=p-y;
                t3=(t3+1)%2;
            }
        }
        else if(t==4)
        {
            if(!tot)
            {
                y=p-y;
                t3=(t3+1)%2;
            }
            else{
                x=p-x;
                t2=(t2+1)%2;
            }
        }

        for(auto it:vv[i])
        {
            ll nx,ny;
            if(t2)
            {
                nx=x+x-ar[it.first][0];
            }
            else{
                nx=x+x+ar[it.first][0];
            }
            if(t3)
            {
                ny=y+y-ar[it.first][1];
            }
            else{
                ny=y+y+ar[it.first][1];
            }
            if(tot)
            {
                ans[it.second][0]=ny;
                ans[it.second][1]=nx;
            }
            else{
                ans[it.second][0]=nx;
                ans[it.second][1]=ny;
            }
        }
    }

    for(i=1;i<=q;i++)cout<<ans[i][0]<<" "<<ans[i][1]<<"\n";

    return 0;
}

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = int64_t;
using P = pair<ll, ll>;
template <class T>
using V = vector<T>;

template <class T>
class Matrix {
 public:
  int h, w;
  V<V<T>> data;
  Matrix(int h_, int w_ = 0, T v = 0) {
    h = h_;
    w = (w != 0) ? w_ : h;
    data.resize(h);
    rep(i, h) data[i].resize(w, v);
  }
  Matrix(const V<V<T>>& data_)
      : h(data_.size()), w(data_[0].size), data(data_) {}
  Matrix(initializer_list<initializer_list<T>> list) {
    data.resize(list.size());
    int cnt = 0;
    for (auto row : list) data[cnt++] = V<T>(row);
    h = data.size(), w = data[0].size();
  }
  Matrix(const Matrix& a) : h(a.h), w(a.w), data(a.data) {}
  Matrix& operator=(const Matrix& a) {
    h = a.h, w = a.w, data = a.data;
    return *this;
  }
  V<T>& operator[](int n) { return data[n]; }
  Matrix& operator*=(Matrix& a) {
    V<V<T>> res(w, V<T>(a.w));
    rep(i, w) rep(j, a.w) {
      rep(k, w) res[i][j] += data[i][k] * a[k][j];
    }
    swap(data, res);
    h = w, w = a.w;
    return *this;
  }
  Matrix operator*(Matrix& a) { return Matrix(*this) *= a; }
  Matrix& operator+=(Matrix& a) {
    rep(i, h) rep(j, w) data[i][j] += a[i][j];
    return *this;
  }
  string str() {
    ostringstream oss;
    rep(i, h) {
      rep(j, w) oss << data[i][j] << " ";
      if (i != h - 1) oss << "\n";
    }
    return oss.str();
  }
};

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

  V<P> xy(n);
  rep(i, n) cin >> xy[i].first >> xy[i].second;

  V<Matrix<ll>> ops;
  Matrix<ll> now = {{1, 0, 0}, {0, 1, 0}, {0, 0, 1}};
  ops.push_back(now);
  Matrix<ll> clk = {{0, 1, 0}, {-1, 0, 0}, {0, 0, 1}};
  Matrix<ll> clw = {{0, -1, 0}, {1, 0, 0}, {0, 0, 1}};
  Matrix<ll> f3 = {{-1, 0, 2}, {0, 1, 0}, {0, 0, 1}};
  Matrix<ll> f4 = {{1, 0, 0}, {0, -1, 2}, {0, 0, 1}};

  cin >> m;
  rep(i, m) {
    int op;
    ll p;
    cin >> op;
    if (op > 2) cin >> p;

    if (op == 1) {
      now = clk * now;
    } else if (op == 2) {
      now = clw * now;
    } else if (op == 3) {
      f3[0][2] = 2 * p;
      now = f3 * now;
    } else if (op == 4) {
      f4[1][2] = 2 * p;
      now = f4 * now;
    }
    ops.emplace_back(now);
  }

  int Q;
  cin >> Q;
  rep(i, Q) {
    int a, b;
    cin >> a >> b;
    b--;
    Matrix<ll> pos = {{xy[b].first}, {xy[b].second}, {1}};
    auto ans = ops[a] * pos;
    ll x = ans[0][0], y = ans[1][0];
    printf("%ld %ld\n", x, y);
  }
}


#include <iostream>

using namespace std;

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

  cin >> a >> b >> c;

  int c_mod = c % 4;
  if(c_mod == 0)  c_mod = 4;
  int b_mod = b % 4;
  if(b_mod == 0) b_mod = 4;
  int a_down = a % 10;

  int b_res = 1;
  int a_res = 1;

  for(int i = 0; i < c_mod; i++){
    b_res *= b_mod;
  }

  b_mod = b_res % 4;
  if(b_mod == 0) b_mod = 4;

  for(int i = 0; i < b_mod; i++){
    a_res *= a_down;
  }

  int a_mod = a_res % 10;

  cout << a_mod << endl;
}

#include <iostream>
#include <sstream>
#include <string>
#include <list>
#include <vector>
#include <queue>
#include <algorithm>
#include <climits>
#include <cstring>
#include <cmath>
#include <stack>
#include <iomanip>
#include <tuple>
#include <functional>
#include <cfloat>
#include <map>
#include <set>
#include <array>
#include <stdio.h>
#include <string.h>
#include <random>
#include <cassert>
using ll = long long;
using ull = unsigned long long;
using uint = unsigned int;
using namespace std;
#define int long long
#define CONTAINS_VEC(v,n) (find((v).begin(), (v).end(), (n)) != (v).end())
#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
#define ARY_SORT(a, size) sort((a), (a)+(size))
#define REMOVE(v,a) (v.erase(remove((v).begin(), (v).end(), (a)), (v).end()))
#define REVERSE(v) (reverse((v).begin(), (v).end()))
#define ARY_REVERSE(v,a) (reverse((v), (v)+(a)))
#define REP(i, n) for (int (i)=0; (i) < (n); (i)++)
#define REPE(i, n) for (int (i)=0; (i) <= (n); (i)++)
#define CONTAINS_MAP(m, a) ((m).find((a)) != m.end())
#define CONTAINS_SET(m, a) ((m).find((a)) != m.end())
void YesNo(bool b) { cout << (b ? "Yes" : "No") << endl; exit(0); }
void Yes() { cout << "Yes" << endl; exit(0); }
void No() { cout << "No" << endl; exit(0); }

//---------- (a^n)%m -----------
ll pom(ll a, ll n, int m)
{
	ll x = 1;
	for (a %= m; n; n /= 2)
		n & 1 ? x = x * a % m : 0, a = a * a % m;
	return x;
}

signed main()
{
	int A, B, C;
	cin >> A >> B >> C;

	int bc = pom(B, C, 4);

	if (bc == 0) bc = 4;

	int a = pom(A, bc, 10);

	cout << a << endl;

}


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

typedef long long ll;

ll pow (ll a, ll n) {
	if (n==0)
		return 1;
	if (n==1)
		return a;

	ll tmp = pow (a, n/2);
	ll tmp2 = tmp*tmp;
	if (n%2)
		return tmp2*a;
	return tmp2;
}

int main () {
	ll N;
	cin >> N;
	ll tmp = 1;
	ll keta = 0;
	for (int i=0; i<12; i++) {
		if (N / tmp > 0) {
			keta ++;
		}
		tmp *= 10;
	}
	ll ans = 0;
	tmp = 1;
	for (int i=3; i<=keta; i+=2) {
		ans += 9*tmp;
		tmp *= 10;
	}
	if (keta%2 == 0) {
		ll hketa = keta / 2;
		ll d = pow(10, hketa);
		ll Nh = N / d;
		ll Nl = N % d;
		ans += Nh - d/10;
		if (Nl >= Nh)
			ans ++;
	}
	cout << ans << endl;
	return 0;
}

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

int main(){
  string n;cin>>n;
  ll X = (ll)n.size();
  string S;
  ll Q = stoll(n);
  if(Q<10){
      cout<<0<<endl;
      return 0;
  }
  if(X%2==1){
      n="";
      for(ll i=0;i<X-1;i++){
          n+='9';
      }
  }
  ll Y = (ll)n.size();
  string B;
  string C;
  for(ll i=0;i<Y/2;i++){
      B+=n[i];
  }
  for(ll i=Y/2;i<Y;i++){
      C+=n[i];
  }
  //cout<<B<<endl;
  ll b = stoll(B);
  ll c = stoll(C);
  if(b>c){
      cout<<b-1<<endl;
  }else{
      cout<<b<<endl;
  }
}


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

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

#define MAX_H 10000
#define MAX_W 10000

int n;
int x[200],y[200],r[200];
int a[200],b[200],c[200],d[200];

std::mt19937 mt;
std::random_device rnd;

struct Del {
  int i;
  char dir;// U D L R
};

void init(){
  REP(i,n){
    a[i]=x[i];
    c[i]=x[i]+1;
    b[i]=y[i];
    d[i]=y[i]+1;
  }
}

void flush(){
  REP(i,n)cout<<a[i]<<" "<<b[i]<<" "<<c[i]<<" "<<d[i]<<endl;
}

LL score(){
  double ret = 0.0;
  REP(i,n){
    LL s = (c[i]-a[i])*(d[i]-b[i]);
    double rat = (double)min(s,(LL)r[i])/(double)max(s,(LL)r[i]);
    ret+=1-(1-rat)*(1-rat);
  }
  return (LL)(ret*1e9/n);
}

/* control functions finish */

/* util functions start */

bool is_collide_two_interval(int a_,int b_,int c_, int d_){
  return (a_<=c_ && c_<b_) || (c_<=a_ && a_<d_);
}

bool is_collide_two_ad(int i,int j){
  if(i==j)return true;
  return is_collide_two_interval(a[i],c[i],a[j],c[j]) && is_collide_two_interval(b[i],d[i],b[j],d[j]);
}

bool is_collide_any_ad(int i){
  bool ret = false;
  REP(j,n){
    if(i==j)continue;
    ret = ret || is_collide_two_ad(i,j);
  }
  return ret;
}

int area(int a_,int b_,int c_, int d_){
  return (c_-a_)*(d_-b_);
}

bool is_over_area(int i){
  return area(a[i],b[i],c[i],d[i]) > r[i];
}

Del generate_del(){
  int i = mt()%n;
  int dir_i=mt()%4;
  switch(dir_i){
    case 0:
      return Del{i,'U'};
    case 1:
      return Del{i,'D'};
    case 2:
      return Del{i,'L'};
    case 3:
      return Del{i,'R'};
  }
}

bool redo_del(Del del){
  int i = del.i;
  switch(del.dir){
    case 'U':
      if(b[i]==0)return false;
      b[i]--;
      return true;
    case 'D':
      if(d[i]==MAX_H)return false;
      d[i]++;
      return true;
    case 'L':
      if(a[i]==0)return false;
      a[i]--;
      return true;
    case 'R':
      if(c[i]==MAX_W)return false;
      c[i]++;
      return true;
  }
}

void undo_del(Del del){
  int i = del.i;
  switch(del.dir){
    case 'U':
      b[i]++;
      return;
    case 'D':
      d[i]--;
      return;
    case 'L':
      a[i]++;
      return;
    case 'R':
      c[i]--;
      return;
  }
}

/* util functions finish */

int main(){
  mt.seed(42);

  cin>>n;
  REP(i,n)cin>>x[i]>>y[i]>>r[i];
  init();

  REP(i,3000000){
    auto del = generate_del();
    auto suc = redo_del(del);
    if(!suc){continue;}
    if(is_over_area(del.i) || is_collide_any_ad(del.i))undo_del(del);
  }

  flush();
  //cerr<<score()<<endl;
  return 0;
}

#include <bits/stdc++.h>
//#include <atcoder/all>
#define rep(i, n) for (int i = 0; i < (n); i++)
using ll = long long;
using namespace std;
//using namespace atcoder;
const int mod = 1000000007;
const int INF =1e9+1;
int main(){
    int n;cin>>n;
    vector<int> p(n);
    rep(i,n)cin>>p[i];
    int maxP=0;
    vector<bool> boo(200005,0);
    rep(i,n){
        boo[p[i]]=1;
        if(maxP==p[i]){
            for(int i=maxP+1;i<200005;i++){
                if(boo[i]==0){
                    maxP=i;
                    break;
                }
            }
        }

        cout<<maxP<<endl;
    }
}


#include <iostream>
#include <random>
#include <cmath>
#include <queue>
#include <utility>
#include <vector>
#include <algorithm>
#include <stack>
#include <cassert>

using namespace std;

const int SIZE = 30;
const int INF = 99999999;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const char dc[4] = {'D', 'R', 'U', 'L'};
struct Point {
  int i, j;
  Point() {}
  Point(int i, int j) : i(i), j(j) {}
  bool is_valid() {
    return (i >= 0) && (i < SIZE) && (j >= 0) && (j < SIZE);
  }
};

struct Edge {
  Point to;
  int n_passed = 0;
  double length = -1.0;
};

Edge graph[SIZE][SIZE][4];

deque<char> calculate_path(Point start, Point terminal) {
  bool visited[SIZE][SIZE];
  fill((bool*)visited, (bool*)visited+(SIZE*SIZE), false);
  //for (int i = 0; i < SIZE; ++i) {
  //  for (int j = 0; j < SIZE; ++j) {
  //    visited[i][j] = false;
  //  }
  //}
  int dist[SIZE][SIZE];
  fill((int*)dist, (int*)dist+(SIZE*SIZE), INF);
  int direction[SIZE][SIZE];
  fill((int*)direction, (int*)direction+(SIZE*SIZE), -1);

  stack<Point> s;
  visited[start.i][start.j] = true;
  dist[start.i][start.j] = 0;
  s.push(start);
  while (!s.empty()) {
    Point p = s.top(); s.pop();

    for (int dir = 0; dir < 4; ++dir) {
      Point np = p;
      np.i += dx[dir];
      np.j += dy[dir];

      if (np.is_valid() && !visited[np.i][np.j]) {
        visited[np.i][np.j] = true;
        dist[np.i][np.j] = dist[np.i][np.j] + graph[p.i][p.j][dir].length;
        direction[np.i][np.j] = dir;
        s.push(np);
      }
    }
  }

  deque<char> path;
  Point p = terminal;
  while (p.i != start.i || p.j != start.j) {
    int dir = direction[p.i][p.j];
    assert(dir >= 0 && dir < 4);
    path.push_front(dc[dir]);
    p.i -= dx[dir];
    p.j -= dy[dir];
  }

  return path;
}

void print_path(deque<char> path) {
  for (char c : path) {
    cout << c;
  }
  cout << endl << flush;
}

int main() {

  for (int i = 0; i < 1000; ++i) {
    // input start and terminal;
    Point s, t;
    cin >> s.i >> s.j >> t.i >> t.j;

    // calculate path
    deque<char> path = calculate_path(s, t);

    // output path
    print_path(path);

    // input path length
    int b;
    cin >> b;

    // update edge length
  }

}

#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 drep(i,j,n) for(int i=0;i<(int)(n-1);i++)for(int j=i+1;j<(int)(n);j++)
#define trep(i,j,k,n) for(int i=0;i<(int)(n-2);i++)for(int j=i+1;j<(int)(n-1);j++)for(int k=j+1;k<(int)(n);k++)
#define codefor int test;scanf("%d",&test);while(test--)
#define INT(...) int __VA_ARGS__;in(__VA_ARGS__)
#define LL(...) ll __VA_ARGS__;in(__VA_ARGS__)
#define yes(ans) if(ans)printf("yes\n");else printf("no\n")
#define Yes(ans) if(ans)printf("Yes\n");else printf("No\n")
#define YES(ans) if(ans)printf("YES\n");else printf("NO\n")
#define popcount(v) __builtin_popcount(v)
#define vector2d(type,name,h,...) vector<vector<type>>name(h,vector<type>(__VA_ARGS__))
#define vector3d(type,name,h,w,...) vector<vector<vector<type>>>name(h,vector<vector<type>>(w,vector<type>(__VA_ARGS__)))
#define umap unordered_map
#define uset unordered_set
using namespace std;
using ll = long long;
const int MOD=1000000007;
const int MOD2=998244353;
const int INF=1<<30;
const ll INF2=1LL<<60;
//入力系
void scan(int& a){scanf("%d",&a);}
void scan(long long& a){scanf("%lld",&a);}
template<class T,class L>void scan(pair<T, L>& p){scan(p.first);scan(p.second);}
template<class T,class U,class V>void scan(tuple<T,U,V>& p){scan(get<0>(p));scan(get<1>(p));scan(get<2>(p));}
template<class T> void scan(T& a){cin>>a;}
template<class T> void scan(vector<T>& vec){for(auto&& it:vec)scan(it);}
void in(){}
template <class Head, class... Tail> void in(Head& head, Tail&... tail){scan(head);in(tail...);}
//出力系
void print(const int& a){printf("%d",a);}
void print(const long long& a){printf("%lld",a);}
void print(const double& a){printf("%.15lf",a);}
template<class T,class L>void print(const pair<T, L>& p){print(p.first);putchar(' ');print(p.second);}
template<class T> void print(const T& a){cout<<a;}
template<class T> void print(const vector<T>& vec){if(vec.empty())return;print(vec[0]);for(auto it=vec.begin();++it!= vec.end();){putchar(' ');print(*it);}}
void out(){putchar('\n');}
template<class T> void out(const T& t){print(t);putchar('\n');}
template <class Head, class... Tail> void out(const Head& head,const Tail&... tail){print(head);putchar(' ');out(tail...);}
//デバッグ系
template<class T> void dprint(const T& a){cerr<<a;}
template<class T> void dprint(const vector<T>& vec){if(vec.empty())return;cerr<<vec[0];for(auto it=vec.begin();++it!= vec.end();){cerr<<" "<<*it;}}
void debug(){cerr<<endl;}
template<class T> void debug(const T& t){dprint(t);cerr<<endl;}
template <class Head, class... Tail> void debug(const Head& head, const Tail&... tail){dprint(head);cerr<<" ";debug(tail...);}
ll intpow(ll a, ll b){ ll ans = 1; while(b){ if(b & 1) ans *= a; a *= a; b /= 2; } return ans; }
ll modpow(ll a, ll b, ll p){ ll ans = 1; while(b){ if(b & 1) (ans *= a) %= p; (a *= a) %= p; b /= 2; } return ans; }
ll modinv(ll a, ll m) {ll b = m, u = 1, v = 0;while (b) {ll t = a / b;a -= t * b; swap(a, b);u -= t * v; swap(u, v);}u %= m;if (u < 0) u += m;return u;}
ll updivide(ll a,ll b){if(a%b==0) return a/b;else return (a/b)+1;}
template<class T> void chmax(T &a,const T b){if(b>a)a=b;}
template<class T> void chmin(T &a,const T b){if(b<a)a=b;}

/*string dijkstra(int sy,int sx,int gy,int gx){

}*/

int main(){
    int test=1000,sy,sx,gy,gx;
    int score;
    double d2;
    while(test--){
        cin>>sy>>sx>>gy>>gx;
        string s,t;
        if(gy>sy)s.resize(gy-sy,'D');
        else s.resize(sy-gy,'U');
        if(gx>sx)t.resize(gx-sx,'R');
        else t.resize(sx-gx,'L');
        cout<<s<<t<<endl;
        cin>>score;
    }
}


// https://atcoder.jp/contests/abc182/tasks/abc182_f

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

#define REP(i,n)   for(int i=0; i<(int)(n); i++)
#define FOR(i,b,e) for(int i=(b); i<=(int)(e); i++)
#define DEBUG 1
#if DEBUG
  #define _GLIBCXX_DEBUG
  #define DUMP(a) REP(_i, a.size()) cout << a[_i] << (_i + 1 == a.size() ? "\n" : " ")
  #define DUMP2D(b) REP(_j, b.size()) DUMP(b[_j]); cout << endl
#else
  #define DUMP(a)
  #define DUMP2D(b)
#endif

const int N_MAX = 50;
const ll A_N_MAX = 1e15;
const ll X_MAX = 1e15;
const ll INF = 2e15;

int N;
ll X;
vector<ll> A;

vector<ll> C, Y;
vector<vector<ll>> dp;

int main() {
  cin >> N >> X;
  A = vector<ll>(N);
  REP(i, N) cin >> A[i];

  C = vector<ll>(N);
  Y = vector<ll>(N);
  ll tmp = X;
  REP(i, N - 1) {
    C[i] = A[i + 1] / A[i];
    Y[i] = tmp % C[i];
    tmp /= C[i];
  }
  C[N - 1] = INF;
  Y[N - 1] = tmp;

  // DUMP(C);
  // DUMP(Y);

  dp = vector<vector<ll>>(N + 1, vector<ll>(2));
  dp[0][0] = 1; dp[0][1] = 0;
  REP(i, N) {
    dp[i + 1][0] += dp[i][0];
    if (Y[i] < C[i] - 1) dp[i + 1][0] += dp[i][1];
    if (i + 1 < N) {
      dp[i + 1][1] += dp[i][1];
      if (Y[i] > 0) dp[i + 1][1] += dp[i][0];
    }
  }

  // DUMP2D(dp);

  ll ans = dp[N][0];
  cout << ans << endl;
}

#include<bits/stdc++.h>
#include<iostream>
#include<algorithm>
#include<unordered_map>
#include<vector>
#include<unordered_set>
#include<set>
#include<map>
#include<queue>
#include<stack>
#include<string>
//Required Headers
using namespace std;

#define PI 3.1415926535897932384626
#define sp(x,y)                     fixed<<setprecision(y)<<x
#define mk(arr,n,type)              type *arr=new type[n]; // dynamic allocation of memory
#define del(arr)                    delete []arr;           // deletion of allocated memory
const int mod = 1'000'000'007;
const int inf = 1e9 + 5;

//for loops

#define fo(i, n) for(i=0; i<n; i++)
#define Fo(i,k,n) for(i=k;k<n?i<n:i>n;k<n?i+=1:i-=1)
#define fo2(i, n,t) for(i=0; i<n; i+=t)

//essentials

#define tc(t)               ll t;ll i; cin>>t; fo(i,t)
#define ll long long

//STL

#define pb push_back
#define mp make_pair
#define F first
#define S second
#define vbe(x) x.begin(), x.end()
#define sortvbe(x) sort(vbe(x))
#define setit(it, a) for(auto it = a.begin(); it != a.end(); it++)
typedef map<int,int>    mii;
typedef map<ll,ll>      mll;
typedef pair<int, int>  pii;
typedef pair<ll, ll>  pl;
typedef vector<int>   vi;
typedef vector<ll>    vl;
typedef vector<pii>   vpii;
typedef vector<pl>    vpl;
typedef vector<vi>    vvi;
typedef vector<vl>    vvl;
typedef set<int>        si;
typedef set<ll>         sl;

//inputs

#define ci(x)     cin>>x;
#define ci2(x,y)    cin>>x>>y;

//template<typename... T>
//void read(T&... args) {
//  ((cin >> args), ...);
//}

//outputs

#define pi(x)     cout<<x;
#define pinl(x)     cout<<x<<endl;

//template<typename... T>
//void write(T&&... args) { //rvalue reference is new to C++
//  ((cout << args << " "), ...);
//}
ll m=1000000007;
//some imp func

inline int gcd(int a,int b) {if (a==0) return b; else return gcd(b%a,a);}
inline void take_input(int A[],int n){for(int i=0;i<n;i++){ cin>>A[i];}}
inline void show(int *A,int n){for(int i=0;i<n;i++){cout<<A[i]<<" ";}cout<<endl;}
inline bool sortbysec(const pair<int,int> &a, const pair<int,int> &b) { return (a.second < b.second); }
inline bool sortbysecdesc(const pair<int,int> &a, const pair<int,int> &b) { return (a.second > b.second); }
inline void swap(int &a,int &b){int temp=a;a=b;b=temp;}
inline void initialise(int A[],int n,int k){for(int i=0;i<n;i++){A[i]=k;}}
inline void vect_input(vector<int>&v,int n){for(int i=0;i<n;i++){int input;cin>>input;v.pb(input);}}
inline int modulo(int a,int b){return (b+(a%b))%b;}
inline int getascii(char ch){return (int)ch;}
inline ll expo(ll e,ll p){if(p==0)return (1);ll ans=expo(e,p/2);ans=((ans%m)*(ans%m))%m;if(p%2!=0)ans=((e%m)*(ans%m))%m;return ans%m;}
inline ll com_wd_m(ll n,ll r,ll m){ll p=1,d=1;if(r==0 or r==n )return(1);if(r==1 )return (n%m);r=min(r,n-r);for(ll i=0;i<r;i++){p=((p%m)*((n%m)-(i%m))%m)%m;p=((p%m)*(expo((i+1),m-2)%m))%m;}return (p%m);}

template<typename T>
void show_vect(vector<T> v){for(int i=0;i<v.size();i++){cout<<v[i]<<" ";}cout<<endl;}
template<typename T>
void vect_input(vector<T>&v,T n){for(int i=0;i<n;i++){cin>>v[i];}}
int fact(int n) { return (n==1 || n==0) ? 1: n * fact(n - 1);  }

//debugging

#define deb(x) cout << #x << " = " << x << endl; //to check the values
#define deb2(x, y) cout << #x << " = " << x << "," << #y << " = " << y << endl;

void A_A()
{
    ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
    #ifndef ONLINE_JUDGE
    freopen("input.in", "r", stdin);
    freopen("output.in", "w", stdout);
    freopen("error.in","w",stderr);
    #endif
}
ll num;

void solve(){
  ll i,n,j;
  cin>>n;
  vl a(n);
  ll s=0,mx=0;
  long double s2=0;
  fo(i,n){
    cin>>a[i];
    s+=abs(a[i]);
    s2+=a[i]*a[i];
    mx=max(abs(a[i]),mx);
  }
  ll x=15;
  long double ans=sqrt(s2);
  cout<<s<<endl;
  cout << fixed;
  cout<<setprecision(15)<<ans<<endl;
  cout<<mx<<endl;

}
int main(){
   A_A();
  // tc(t){
    solve();
  // }
  return 0;
}
/*

*/


#include <iostream>
#include <queue>
#include <utility>
using namespace std;

int main() {
  int N; cin >> N;
  int P[N];
  for (int i = 0; i < N; i++) cin >> P[i];

  bool flag = true;
  bool flag_[N - 1];
  for (int i = 0; i < N - 1; i++) flag_[i] = false;
  int now = 0;
  queue<int> Que;

  for (int i = 0; i < N; i++){
    if (i == P[i] - 1) flag = false;
    if (i > P[i] - 1){
      for (int j = i - 1; j >= now; j--){
        if (P[j + 1] < P[j] && flag_[j] == false){
          flag_[j] = true;
          Que.push(j);
          swap(P[j], P[j + 1]);
        }
      }
      now = i;
    }
  }

  for (int i = 0; i < N - 1; i++){
    if (flag_[i] == false) flag = false;
  }
  for (int i = 0; i < N; i++){
    if (i != P[i] - 1) flag = false;
  }

  if (flag == true) {
    for (int i = 0; i < N - 1; i++){
      cout << Que.front() + 1 << endl;
      Que.pop();
    }
  }
  else cout << -1 << endl;
}

#include<vector>
#include<cstdio>
using namespace std;
int n,per[200010],ori[200010],mn=1e9;
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;++i)	scanf("%d",&per[i]),ori[per[i]]=i;
	vector<int> ans;
	for(int i=n;i;--i)
	{
		if((ori[i]^i)&&mn>ori[i])
		{
			mn=ori[i];
			for(int j=ori[i];j<i;++j)	ans.push_back(j),(per[j]^=per[j+1]^=per[j]^=per[j+1]);
		}
	}
	if(ans.size()^int(n-1))	printf("-1\n");
	else
	{
		for(int i=1;i<=n;++i)	if(per[i]^i)	return printf("-1\n"),0;
		for(int now : ans)	printf("%d\n",now);
	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define all(v) v.begin(), v.end()
#define chmax(x, y) (x = max(x, y))
#define chmin(x, y) (x = min(x, y))

using ll = long long;
using PAIR = pair<int, int>;
using PAIRLL = pair<ll, ll>;
using vi = vector<int>;
using vvi = vector<vi>;
using vc = vector<char>;
using vvc = vector<vc>;
using vb = vector<bool>;
using vvb = vector<vb>;
using vll = vector<ll>;
using vvll = vector<vll>;
using Graph = vector<vector<int>>;

int main()
{
  ll B, C, ans = 0;
  cin >> B >> C;
  if (B > 0)
  {
    if(C==1)
    {
      cout << 2 << endl;
      return 0;
    }
    if (B - C / 2 > 0)
    {
      if (C % 2)
        ans += 2 * (C / 2);
      else
      {
        ans += 2 * (C / 2) - 1;
      }
    }
    else
    {
      ans += 2 * B - 1;
    }

    if (C % 2)
    {
      ans += 2 * ((C-1) / 2) + 1;
    }
    else
    {
      ans += 2 * ((C-1) / 2+1);
    }
  }
  else if (B == 0)
  {
    if(C==1)
    {
      cout << 1 << endl;
      return 0;
    }
    if (C % 2)
    {
      cout << 2 * (C / 2) + 1 << endl;
      return 0;
    }
    else
    {
      cout << 2 * (C / 2) << endl;
      return 0;
    }
  }
  else
  {
    if(C==1)
    {
      cout << 2 << endl;
      return 0;
    }
    if (C % 2)
    {
      ans += 2 * (C / 2+1);
    }
    else
    {
      ans += 2 * (C / 2+1) - 1;
    }
    C--;
    B *= -1;
    if (B - C / 2 > 0)
    {
      if(C==1)
      {
        cout << 4 << endl;
        return 0;
      }
      if (C % 2)
        ans += 2 * (C / 2);
      else
      {
        ans += 2 * (C / 2+1) + 1;
      }
    }
    else
    {
      ans += 2 * B - 1;
    }
  }
  cout << ans << endl;
}

#include<bits/stdc++.h>
#define LL long long
#define DB double
#define pb push_back
#define mkp make_pair
#define LB lower_bound
#define UB upper_bound
#define rint register int
#define MS(x,y) memset(x,y,sizeof(x))
#define rep(i,a,b) for(rint i=a,i##end=b;i<=i##end;++i)
#define drep(i,a,b) for(rint i=a,i##end=b;i>=i##end;--i)
#define cms printf("%.2lf\n",(&o2-&o1)/1024.0/1024)
using namespace std;bool o1;
char IO;
inline int Rd(){
	int _s_=0;
	bool _f_=0;
	while(!isdigit(IO=getchar()))
		IO=='-'&&(_f_=1);
	do _s_=(_s_<<1)+(_s_<<3)+(IO^48);
	while(isdigit(IO=getchar()));
	return _f_?-_s_:_s_;
}
const int M=400005;
int n,m,p,t,A[M],B[M],b[M],c[M],f[M],g[M],T,ans;
vector<int>v[M];
bool o2;int main(){
	n=Rd(),m=Rd();
	rep(i,1,m)
		c[++p]=A[i]=Rd(),b[i]=B[++t]=Rd();
	b[++t]=n;
	sort(b+1,b+1+t);
	sort(c+1,c+1+p);
	t=unique(b+1,b+1+t)-b-1;
	p=unique(c+1,c+1+p)-c-1;
	rep(i,1,m){
		A[i]=LB(c+1,c+1+p,A[i])-c;
		B[i]=LB(b+1,b+1+t,B[i])-b;
		v[A[i]].push_back(B[i]);
	}
	f[LB(b+1,b+1+t,n)-b]=1;
	rep(i,1,p){
		rep(j,0,(int)v[i].size()-1){
			int x=v[i][j];
			g[x]=0;
			if(b[x-1]==b[x]-1)
				g[x]|=f[x-1];
			if(b[x+1]==b[x]+1)
				g[x]|=f[x+1];
		}
		rep(j,0,(int)v[i].size()-1){
			int x=v[i][j];
			f[x]=g[x];
		}
	}
	rep(i,1,t)
		ans+=f[i];
	cout<<ans;
	return 0;
}


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

using namespace std;

int main()
	{
	int N;
	cin >> N;
	N*=2;

	vector<pair<long long, int>> dogs;
	vector<int> color = vector<int>(3);
	color[0] = color[1] = color[2] = 0;
	int odd1=-1, odd2=-1;

	for(int i=0; i < N; i++)
		{
		long long x;
		cin >> x;

		char c;
		cin >> c;
		while(c==' ')
			cin >> c;

		switch(c)
			{
			case 'R':
				dogs.push_back(make_pair(x, 0));
				color[0]++;
				break;

			case 'G':
				dogs.push_back(make_pair(x, 1));
				color[1]++;
				break;

			case 'B':
				dogs.push_back(make_pair(x, 2));
				color[2]++;
				break;
			}
		}

	for(int i=0; i < 3; i++)
		{
		if(color[i]%2==1)
			{
			if(odd1==-1)	odd1=i;
			else			odd2=i;
			}
		}

	if(odd1==-1)
		cout << 0 << endl;
	else
		{
		const long long INF = 1e16;
		long long diff[3][3] = {{INF, INF, INF}, {INF, INF, INF},  {INF, INF, INF}};
		sort(dogs.begin(), dogs.end());

		vector<long long> last = vector<long long>(3, -1);
		last[dogs[0].second] = dogs[0].first;
		for(int i=1; i < N; i++)
			{
			int tmp = dogs[i].second;
			last[tmp] = dogs[i].first;
			for(int j=0; j < 3; j++)
				if(last[j]!=-1)
					diff[j][tmp] = diff[tmp][j] = min(diff[j][tmp], dogs[i].first-last[j]);
			}

		int odd3 = 3-odd1-odd2;
		cout << min(diff[odd1][odd2], diff[odd1][odd3]+diff[odd3][odd2]) << endl;
		}

	return 0;
	}

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

typedef long long ll;
typedef long double ldb;
typedef double db;
using namespace std;

#define ff first
#define ss second
#define pb push_back
#define pf push_front
#define ins insert
#define mp make_pair
#define len(s) s.length()
#define forp(i, a, b) for (ll i = a; i <= b; i++)
#define rep(i, n) for (ll i = 0; i < n; i++)
#define ren(i, n) for (ll i = n - 1; i >= 0; i--)
#define forn(i, a, b) for (ll i = a; i >= b; i--)
#define on cout << endl
#define o2(a, b) cout << a << " " << b
#define os cout << " "
#define all(v) v.begin(), v.end()
#define mem(n, m) memset(n, m, sizeof(n))
#define vi vector<int>
#define vl vector<ll>
#define ld long double
#define vld vector<ld>
#define vvi vector<vector<int>>
#define vvl vector<vector<long long>>
#define vvld vector<vector<ld>>
#define pii pair<int, int>
#define pll pair<ll, ll>
#define vpii vector<pii>
#define vpll vector<pll>
#define mll map<ll, ll>
#define lb lower_bound
#define ub upper_bound
#define ret return 0
#define present(s, x) (s.find(x) != s.end())
#define cpresent(s, x) (find(all(s), x) != s.end())
#define ford(container, it) for (__typeof(container.begin()) it = container.begin(); it != container.end(); it++)
#define fors(container, it, a, b) for (__typeof(container.begin()) it = a; it != b; it++)
#define d1(x) cout << (x) << endl
#define d2(x, y) cout << (x) << " " << (y) << endl
#define d3(x, y, z) cout << (x) << " " << (y) << " " << (z) << endl
#define d4(a, b, c, d) cout << (a) << " " << (b) << " " << (c) << " " << (d) << endl
#define max3(a, b, c) max(max(a, b), c)
#define min3(a, b, c) min(min(a, b), c)
#define itoa(x) to_string(x);
#define atoi(x) stoll(x);

#define boost ios_base::sync_with_stdio(0)
#define MOD 1000000007
#define EPSILON 1e-9
#define PI 3.14159265358979323846
#define inf 999999999999999999
#define siz 100001
#define SIZ 1000001
#define SIZE 200001

#define pqb priority_queue<int>
#define pqs priority_queue<int, vi, greater<int>>
#define setbits(x) __builtin_popcountll(x)
#define zrobits(x) __builtin_ctzll(x)
#define w(x)  \
    int x;    \
    cin >> x; \
    while (x--)

ll power(ll x, ll y, ll p)
{
    ll res = 1;
    x = x % p;
    while (y > 0)
    {
        if (y & 1)
            res = (res * x) % p;
        y = y >> 1;
        x = (x * x) % p;
    }
    return res;
}
ll pwr(ll x, ll y)
{
    ll res = 1;
    x = x;
    while (y > 0)
    {
        if (y & 1)
            res = (res * x);
        y = y >> 1;
        x = (x * x);
    }
    return res;
}
ll modInverse(ll n, ll p)
{
    return power(n, p - 2, p);
}
ll gcd(ll a, ll b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);
}
ll lcm(ll a, ll b)
{
    return (b * a) / gcd(a, b);
}
ll fact(ll n)
{
    if (n <= 1)
        return 1;
    return n * fact(n - 1);
}
ll nPr(ll n, ll r)
{
    return fact(n) / fact(n - r);
}
ll cd(ll n)
{
    ll c=0;
    while(n>0)
    {
        n/=10;
        c++;
    }
    return c;
}
ll getIndex(vl v, ll K)
{
    auto it = find(v.begin(), v.end(), K);

    // If element was found
    if (it != v.end())
    {

        // calculating the index
        // of K
        ll index = it - v.begin();
        return index;
    }
    else {
        // If the element is not
        // present in the vector
        return -1;
    }
}
void c_p_c()
{
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
}
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    c_p_c();
    ll t;
    t = 1;
    // cin >> t;
    while (t-- > 0)
    {
        ll a, b;
        cin>>a>>b;
        ll d = b-a, j=d;
        for(j; j>(d+1)/2; j--)
        {
            if((j-a%j)%j<d-j+1)
                goto out;
        }
        out:
        d1(j);
    }
    return 0;
}


//#define _GLIBCXX_DEBUG

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

//*
#include<vector>
#include<iostream>
#include<queue>
#include<algorithm>
#include<math.h>
#include<iomanip>
#include <numeric>
//*/
using namespace std;
#define ll long long
#define yes {cout<<"Yes"<<endl;return 0;}
#define no {cout<<"No"<<endl;return 0;}
#define YES {cout<<"YES"<<endl;return 0;}
#define NO {cout<<"NO"<<endl;return 0;}
#define cyes {cout<<"Yes"<<endl;continue;}
#define cno {cout<<"No"<<endl;continue;}

#define MOD 1000000007
#define MOD2 1000000009
#define MOD3 998244353
#define INF 2147483647
constexpr double PI = 3.14159265358979;
#define LINF 9223372036854775807

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

#define PF push_front
#define PB push_back
#define POF pop_front
#define POB pop_back

#define MP make_pair
#define MT make_tuple

#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define SZ(a) (int)((a).size())

#define NEXP(a) next_permutation((a).begin(),(a).end())
#define FI first
#define SE second

#define SORT(c) sort((c).begin(),(c).end())
#define SORTR(c) sort((c).rbegin(), (c).rend())
#define REVERSE(c) reverse((c).begin(),(c).end())

typedef long long LL;
typedef long long LL;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;
typedef vector<bool> VB;
typedef vector<VB> VVB;
typedef vector<double> VD;
typedef vector<VD> VVD;
typedef vector<string> VS;
typedef vector<VS> VVS;
typedef vector<char> VC;
typedef vector<VC> VVC;
typedef vector<PII> VPII;
typedef vector<PLL> VPLL;

void solve(vector<pair<PII, PII>> &s,vector<pair<PII,PII>> &a)
{
    int n=s.size();
    SORT(s);
    //map<int,int>ymax;
    //ymax[0]=10000;
    rep(i,n)
    {
        int now,pre;
        now=s[i].SE.SE;
        int xmax,ymax;
        if(i==0)
        {
            a[now].FI.FI=0;
            a[now].FI.SE=0;
            a[now].SE.FI=s[i].FI.FI+1;
            a[now].SE.SE=s[i].FI.SE+1;
            //ymax[-s[i].FI.FI]=s[i].FI.SE;
            xmax=s[i].FI.FI;
            ymax=s[i].FI.SE;
        }
        else
        {
            if(s[i].FI.FI==xmax)
            {
                a[now].FI.FI=a[pre].FI.FI;
                a[now].FI.SE=a[pre].SE.SE;
                a[now].SE.FI=s[i].FI.FI+1;
                a[now].SE.SE=s[i].FI.SE+1;
                xmax=s[i].FI.FI;ymax=s[i].FI.SE;
                if(i==n-1)
                {
                      a[now].SE.SE=10000;
                }
                     if(s[n-1].FI.FI==s[i].FI.FI)
                {
                    a[now].SE.FI=10000;

                }
            }
            else
            {

                a[now].FI.FI=a[pre].SE.FI;
                a[now].FI.SE=0;
                a[now].SE.FI=s[i].FI.FI+1;
                a[now].SE.SE=s[i].FI.SE+1;
                if(i==n-1)
                {
                      a[now].SE.SE=10000;
                }

                if(s[n-1].FI.FI==s[i].FI.FI)
                {
                    a[now].SE.FI=10000;

                }
                xmax=s[i].FI.FI;
                ymax=s[i].FI.SE;
                a[pre].SE.SE=10000;
            }

        }
        pre=now;

    }

}

int main(void)
{
	int n;
	cin >> n;
    vector<pair<PII, PII>> s(n);
    vector<pair<PII,PII>> ans(n);
	rep(i, n)
	{
	    cin >> s[i].first.first>> s[i].first.second >> s[i].second.FI;
	    s[i].SE.SE=i;
	}

	solve(s,ans);

	rep(i,n)cout<<ans[i].FI.FI<<" "<<ans[i].FI.SE<<" "<<ans[i].SE.FI<<" "<<ans[i].SE.SE<<endl;
}

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

int n;
struct xyr {
  int x;
  int y;
  int r;
};
struct sq {
  int x1;
  int y1;
  int x2;
  int y2;
  int s;
};

vector<xyr> ad;
vector<sq> ans;
vector<bool> okArea;
clock_t start;
vector<vector<int>> area(10001, vector<int>(10001, -1));

void input () {
  cin >> n;
  ad.resize(n);
	rep(i, n) cin >> ad[i].x >> ad[i].y >> ad[i].r;
}
void init() {
  ans.resize(n);
  okArea.resize(n);
  rep(i, n) {
    ans[i].x1 = ad[i].x;
    ans[i].y1 = ad[i].y;
    ans[i].x2 = ad[i].x+1;
    ans[i].y2 = ad[i].y+1;
    ans[i].s = 1;
    area[ad[i].y][ad[i].x] = i;
    okArea[i] = false;
  }
}

void moveLeft(int i) {
  bool ok = true;
  for (int j=ans[i].y1; j<=ans[i].y2; j++) {
    if (!(ans[i].x1-1 >= 0 && area[j][ans[i].x1-1] == -1)) {
      ok = false;
      break;
    }
  }
  if (!ok) return;
  ans[i].x1--;
  for (int j=ans[i].y1; j<=ans[i].y2; j++) {
    area[j][ans[i].x1] = i;
    ans[i].s++;
  }
}
void moveRight(int i) {
  bool ok = true;
  for (int j=ans[i].y1; j<=ans[i].y2; j++) {
    if (!(ans[i].x2+1 <= 10000 && area[j][ans[i].x2+1] == -1)) {
      ok = false;
      break;
    }
  }
  if (!ok) return;
  ans[i].x2++;
  for (int j=ans[i].y1; j<=ans[i].y2; j++) {
    area[j][ans[i].x2] = i;
    ans[i].s++;
  }
}
void moveUp(int i) {
  bool ok = true;
  for (int j=ans[i].x1; j<=ans[i].x2; j++) {
    if (!(ans[i].y1-1 >= 0 && area[ans[i].y1-1][j] == -1)) {
      ok = false;
      break;
    }
  }
  if (!ok) return;
  ans[i].y1--;
  for (int j=ans[i].x1; j<=ans[i].x2; j++) {
    area[ans[i].y1][j] = i;
    ans[i].s++;
  }
}
void moveDown(int i) {
  bool ok = true;
  for (int j=ans[i].x1; j<=ans[i].x2; j++) {
    if (!(ans[i].y2+1 <= 10000 && area[ans[i].y2+1][j] == -1)) {
      ok = false;
      break;
    }
  }
  if (!ok) return;
  ans[i].y2++;
  for (int j=ans[i].x1; j<=ans[i].x2; j++) {
    area[ans[i].y2][j] = i;
    ans[i].s++;
  }
}

void calcArea(int i) {
  if (ans[i].s >= ad[i].r*0.9) okArea[i] = true;
}

bool isTimeLimit(clock_t start) {
  clock_t end = clock();
  const double time = static_cast<double>(end - start) / CLOCKS_PER_SEC * 1000.0;
  if (time >= 4500) return true;
  else return false;
}

void output() {
  rep(i, n) {
    cout << ans[i].x1 << " " << ans[i].y1 << " " << ans[i].x2 << " " << ans[i].y2 << endl;
  }
}

int main() {
	// 入力
	input();
  init();
  int cnt = 0;
	while (1) {
    rep(i, n) {
      if (okArea[i]) continue;
      moveLeft(i);
      moveRight(i);
      moveUp(i);
      moveDown(i);
      calcArea(i);
    }
    if (cnt%1000 == 0) {
      if (isTimeLimit(start)) break;
    }
    cnt++;
	}
  output();

	return 0;
}


#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <unordered_map>
#include <unordered_set>
using namespace std;
#define x first
#define y second
#define all(v) v.begin(), v.end()
#define compress(v) (sort(all(v)), v.erase(unique(all(v)), v.end()))
#define setio ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)
//cout << fixed << setprecision(15);
typedef long long ll;
typedef pair<ll, int> p;

int N, M;
vector<int> adj[2004];
int adj2[2004][2004];
ll dist[2004];

void dijk(int s) {
	int i;
	for (i = 1; i <= N; i++) dist[i] = -1;
	dist[s] = 0;
	priority_queue<p> pq;
	pq.push({ 0,s });
	while (!pq.empty()) {
		int u = pq.top().y; ll cost = -pq.top().x;
		pq.pop();
		if (dist[u] < cost) continue;
		for (auto& v : adj[u]) {
			int c = adj2[u][v];
			if (dist[v] == -1 || dist[v] > dist[u] + c) {
				dist[v] = dist[u] + c;
				pq.push({ -dist[v],v });
			}
		}
	}
}
int main() {
	setio;
	int i, j; cin >> N >> M;
	for (i = 1; i <= N; i++) for (j = 1; j <= N; j++) adj2[i][j] = -1;

	for (i = 1; i <= M; i++) {
		int a, b, c; cin >> a >> b >> c;
		if (adj2[a][b] == -1 || adj2[a][b] > c) adj2[a][b] = c;
	}
	for (i = 1; i <= N; i++) for (j = 1; j <= N; j++) {
		if (adj2[i][j] != -1) adj[i].push_back(j);
	}
	for (i = 1; i <= N; i++) {
		dijk(i);
		ll mn;
		if (adj2[i][i] != -1) mn = adj2[i][i];
		else mn = (ll)1e10;
		for (j = 1; j <= N; j++) {
			if (i == j) continue;
			if (dist[j] == -1 || adj2[j][i] == -1) continue;
			mn = min(mn, dist[j] + adj2[j][i]);
		}
		if (mn == (ll)1e10) cout << -1 << '\n';
		else cout << mn << '\n';
	}
}

#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <functional>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <bitset>
#include <math.h>
#include <random>
#include <chrono>
#include <assert.h>
using namespace std ;
using ll = long long ;
using ld = long double ;
template<class T> using V = vector<T> ;
template<class T> using VV = V<V<T>> ;
using pll = pair<ll,ll> ;
#define all(v) v.begin(),v.end()
ll mod = 1000000007 ;
long double pie = acos(-1) ;
ll INF = 1e18 ;

void yorn(bool a){if(a) cout << "Yes" << endl ; else cout << "No" << endl ;}
//void YorN(bool a){if(a) cout << "YES" << endl ; else cout << "NO" << endl ;}
ll gcd(long long a,long long b){if(b==0) return a ; return gcd(b,a%b) ;}
ll lcm(long long a,long long b){return a/gcd(a,b)*b ;}
ll extGCD(ll a,ll b,ll &x,ll &y){
    if(b==0){
        x = 1 ;
        y = 0 ;
        return a ;
    }
    ll d = extGCD(b,a%b,y,x) ;
    y -= a/b*x ;
    return d ;
}
void fix_cout(){cout << fixed << setprecision(20) ;}
template<class T> void chmax(T &a,T b){if(a<b) a = b ;}
template<class T> void chmin(T &a,T b){if(a>b) a = b ;}

int main(){
    int n,m ;
    cin >> n >> m ;
    VV<pair<int,pair<ll,ll>>> g(n) ;
    for(int i=0;i<m;i++){
        ll a,b,c,d ;
        cin >> a >> b >> c >> d ;
        a-- ; b-- ;
        g[a].emplace_back(b,make_pair(c,d)) ;
        g[b].emplace_back(a,make_pair(c,d)) ;
    }
    using T = pair<ll,int> ;
    priority_queue<T,V<T>,greater<T>> pq ;
    V<ll> dis(n,INF) ;
    pq.emplace(0,0) ;
    while(!pq.empty()){
        int cur = pq.top().second ;
        ll cost = pq.top().first ;
        pq.pop() ;
        if(dis[cur]<cost) continue ;
        dis[cur] = cost ;
        for(auto p:g[cur]){
            int nx = p.first ;
            ll c = p.second.first ;
            ll d = p.second.second ;
            if(dis[nx]!=INF) continue ;
            ll f = sqrt(d)-1 ;
            ll mn = INF ;
            if(cost<=f){
               chmin(mn,(f+c+d/(f+1)));
            }
            if(cost<=f+1){
                chmin(mn,f+1+c+d/(f+2)) ;
            }
            if(cost<=f+1){
                chmin(mn,(f+1+c+d/(f+2))) ;
            }
            chmin(mn,cost+c+d/(cost+1)) ;
            pq.emplace(mn,nx) ;
        }
    }
    if(dis[n-1]==INF) dis[n-1] = -1 ;
    cout << dis[n-1] << endl ;
}


#include<bits/stdc++.h>
using namespace std;
const int maxn = 100005;
#define inf 1e9

int N, M, w[maxn];
int dis[10][10], ans = inf;
struct Data{
    int l, v;
    Data(){}
    Data(int l, int v){ this -> l = l, this -> v = v; }
}d[maxn];
struct segment_tree{
    static const int maxn = 100005;
    int rt, np, lc[maxn << 1], rc[maxn << 1], mx[maxn << 1];

    int newnode(){
        np++; lc[np] = rc[np] = mx[np] = 0;
        return np;
    }
    void pushup(int now){
        mx[now] = max(mx[lc[now]], mx[rc[now]]);
    }
    void build(int &now, int L, int R, Data *a){
        now = newnode();
        if(L == R){ mx[now] = a[L].l; return; }
        int m = L + R >> 1;
        build(lc[now], L, m, a);
        build(rc[now], m + 1, R, a);
        pushup(now);
    }
    int query(int now, int L, int R, int A, int B){
        if(A <= L && R <= B) return mx[now];
        int m = L + R >> 1, re = 0;
        if(A <= m) re = max(re, query(lc[now], L, m, A, B));
        if(B > m) re = max(re, query(rc[now], m + 1, R, A, B));
        return re;
    }
}st;

bool cmp(Data a, Data b){ return a.v < b.v; }
bool Fail(){
    int mn = inf, mx = 0;
    for(int i = 1; i <= N; i++) mx = max(mx, w[i]);
    for(int i = 1; i <= M; i++) mn = min(mn, d[i].v);
    return mx > mn;
}
void floyd(){
    for(int k = 1; k <= N; k++)
        for(int i = 1; i <= N; i++)
            for(int j = 1; j <= N; j++)
                dis[i][j] = max(dis[i][j], dis[i][k] + dis[k][j]);
}
bool vis[10]; int seq[10], sum[10];
void run(int i){
    if(i > N){
        for(int i = 1; i <= N; i++)
            for(int j = 1; j <= N; j++) dis[i][j] = -inf;
        for(int i = 1; i < N; i++) dis[i][i + 1] = 0;

        sum[0] = 0;
        for(int i = 1; i <= N; i++) sum[i] = sum[i - 1] + w[seq[i]];

        Data tmp;
        for(int lef = 1; lef < N; lef++)
            for(int rig = lef + 1; rig <= N; rig++){
                tmp.v = sum[rig] - sum[lef - 1];
                int r = lower_bound(d + 1, d + M + 1, tmp, cmp) - d - 1;
                tmp.v = max(sum[rig - 1] - sum[lef - 1], sum[rig] - sum[lef]);
                int l = lower_bound(d + 1, d + M + 1, tmp, cmp) - d;
                if(l <= r) dis[lef][rig] = max(dis[lef][rig], st.query(st.rt, 1, M, l, r));
            }

        floyd();
        ans = min(ans, dis[1][N]);

        return;
    }
    for(int j = 1; j <= N; j++){
        if(vis[j]) continue;
        vis[j] = 1, seq[i] = j;
        run(i + 1);
        vis[j] = 0;
    }
}
int main()
{

    scanf("%d%d", &N, &M);
    for(int i = 1; i <= N; i++) scanf("%d", &w[i]);
    for(int i = 1; i <= M; i++) scanf("%d%d", &d[i].l, &d[i].v);

    if(Fail()){
        printf("-1\n");
    }
    else{
        sort(d + 1, d + M + 1, cmp);
        st.build(st.rt, 1, M, d);
        run(1);
        printf("%d\n", ans);
    }

    return 0;
}

#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cmath>
#include <array>
#include <numeric>
//#include <atcoder/all>
using namespace std;
//using namespace atcoder;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, int> pdi;
typedef tuple<ll, ll, ll> tl3;

//typedef modint998244353 mint;

const int BIG_NUM = 1e9;
const ll INF = 1000000000000000000;
const ll MOD = 1e9 + 7;
//const ll MOD = 998244353;
const double EPS = 1e-7;
const int MAX = 1e5 + 5;

int main() {
	int n, m;
	cin >> n >> m;
	vector<int> w(n);
	for (int i = 0; i < n; i++) {
		cin >> w[i];
	}

	sort(w.begin(), w.end());
	vector<int> l(m);
	vector<int> v(m);

	for (int i = 0; i < m; i++) {
		cin >> l[i] >> v[i];
	}

	vector<pii> b(m);
	for (int i = 0; i < m; i++) {
		b[i].first = v[i];
		b[i].second = l[i];
	}

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

	sort(v.begin(), v.end());
	if (w[n - 1] > v[0]) {
		cout << -1 << endl;
		return 0;
	}

	vector<int> lim(m + 1);
	for (int i = 0; i < m; i++) {
		lim[i + 1] = max(lim[i], b[i].second);
	}

	vector<int> p(n);
	iota(p.begin(), p.end(), 0);
	ll ans = INF;
	do {

		vector<vector<ll>> g(n, vector<ll>(n));
		for (int i = 0; i < n; i++) {
			ll sum = w[p[i]];
			for (int j = i + 1; j < n; j++) {
				sum += w[p[j]];
				auto it = lower_bound(v.begin(), v.end(), sum);

				int k = (it - v.begin());
				//cout << k << endl;
				g[i][j] = lim[k];
				//cout << lim[k] << endl;
			}
		}
		/*
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < n; j++) {
				cout << g[i][j] << " ";
			}
			cout << endl;
		}
		*/

		vector<ll> d(n);

		for (int i = 0; i < n; i++) {
			for (int j = i + 1; j < n; j++) {
				d[j] = max(d[j], d[i] + g[i][j]);
			}
		}

		ans = min(ans, d[n - 1]);

	} while (std::next_permutation(p.begin(), p.end()));
	cout << ans << endl;
}


#include <iostream>
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double db;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;

template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template <typename T>
using ordered_multiset = tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;
#define pll pair<ll,ll>
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define ub(v,val) upper_bound(v.begin(),v.end(),val)
#define np(str) next_permutation(str.begin(),str.end())
#define lb(v,val) lower_bound(v.begin(),v.end(),val)
#define sortv(vec) sort(vec.begin(),vec.end())
#define rev(p) reverse(p.begin(),p.end());
#define v vector
#define pi 3.14159265358979323846264338327950288419716939937510
#define len length()
#define repc(i,s,e) for(ll i=s;i<e;i++)
#define fi first
#define se second
#define mset(a,val) memset(a,val,sizeof(a));
#define mt make_tuple
#define repr(i,n) for(i=n-1;i>=0;i--)
#define rep(i,n) for(i=0;i<n;i++)
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define at(s,pos) *(s.find_by_order(pos))
#define set_ind(s,val) s.order_of_key(val)
long long int M = 1e9 + 7 ;
long long int inf = 9 * 1e18;
//CLOCK
ll begtime = clock();
#define time() cout << "\n\nTime elapsed: " << (clock() - begtime)*1000/CLOCKS_PER_SEC << " ms\n\n";
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
//CLOCK ENDED
ll n, m;
// modular exponentiation
ll binpow(ll val, ll deg)
{
	if (deg < 0)
		return 0;
	if (!deg)
		return 1 % M;
	if (deg & 1)
		return binpow(val, deg - 1) * val % M;
	ll res = binpow(val, deg >> 1);
	return (res * res) % M;
}
//binomial
ll modinv(ll n) {
	return binpow(n, M - 2);
}
ll a, b;

int main() {
	// your code goes here
	IOS;
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	ll i, j, t, k, x, y, z,  N;

	cin >> n >> m;
	cin >> a >> b;
	ll nways = 0;

	x = n * m;
	ll p1[1ll << x] = {0}, p2[1ll << x] = {0};
	rep(i, 1ll << x) {
		ll flg = 0;
		ll row = 0;
		ll mat[n][m];
		mset(mat, 0);
		rep(j, x) {
			if ((i >> j) & 1) {
				mat[row][j % m] = 1ll;
			}
			if ((j + 1ll) % m == 0)row++;
		}
		ll cnt = 0;
		rep(j, n) {
			ll par = 0;
			rep(k, m) {
				// cout << mat[j][k] << ' ';
				if (mat[j][k]) {
					if (par == 0) {
						par = 1ll;
					}
					else if (par == 1ll) {
						if (mat[j][k - 1ll]) {
							par = 0;
							cnt++;
						}
						else {
							flg = 1ll;
						}
					}
				}
			}
			// cout << '\n';
			if (par) flg = 1ll;
		}
		if (flg == 0) {
			p1[i] = cnt;

		}
		// cout << '\n';
		flg = 0;
		cnt = 0;
		rep(k, m) {
			ll par = 0;
			rep(j, n) {
				if (mat[j][k]) {
					if (par == 0) {
						par = 1ll;
					}
					else if (par == 1ll) {
						if (mat[j - 1ll][k]) {
							par = 0;
							cnt++;
						}
						else {
							flg = 1ll;
						}
					}
				}
			}
			if (par) flg = 1ll;
		}
		if (flg == 0) {
			p2[i] = cnt;
		}
	}
	for (i = 0; i < (1ll << x); i++) {
		if (p1[i]) {
			if (p1[i] < a) {
				y = ((1ll << x) - 1ll)^i;
				for (j = y; j > 0; j = y & (j - 1ll)) {
					if (p2[j]) {
						if (p2[j] == a - p1[i])
							nways++;
					}
				}
			}
		}
	}
	rep(i, 1ll << x) {
		if (p1[i] == a) nways++;
		if (p2[i] == a) nways++;
	}
	if (a == 0) {
		cout << 1;
	}
	else
		cout << nways;

	return 0;

}


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

using namespace std;
#define all(a)a.begin(),a.end()
using ll=long long;
const int INF = 1<<30;
const ll INFll =1LL<<62;
//const int mod= int(1e9)+7;
const int mod=998244353;
using P = pair<int,int>;
using Pl= pair<ll,ll>;
using ld=long double;
using V=vector<int>;
using Vl=vector<ll>;
using VV=vector<vector<int>>;
using VVl=vector<vector<ll>>;

// modint: mod 計算を int を扱うように扱える構造体
template<int MOD> struct Fp {
    long long val;
    constexpr Fp(long long v = 0) noexcept : val(v % MOD) {
        if (val < 0) val += MOD;
    }
    constexpr int getmod() { return MOD; }
    constexpr Fp operator - () const noexcept {
        return val ? MOD - val : 0;
    }
    constexpr Fp operator + (const Fp& r) const noexcept { return Fp(*this) += r; }
    constexpr Fp operator - (const Fp& r) const noexcept { return Fp(*this) -= r; }
    constexpr Fp operator * (const Fp& r) const noexcept { return Fp(*this) *= r; }
    constexpr Fp operator / (const Fp& r) const noexcept { return Fp(*this) /= r; }
    constexpr Fp& operator += (const Fp& r) noexcept {
        val += r.val;
        if (val >= MOD) val -= MOD;
        return *this;
    }
    constexpr Fp& operator -= (const Fp& r) noexcept {
        val -= r.val;
        if (val < 0) val += MOD;
        return *this;
    }
    constexpr Fp& operator *= (const Fp& r) noexcept {
        val = val * r.val % MOD;
        return *this;
    }
    constexpr Fp& operator /= (const Fp& r) noexcept {
        long long a = r.val, b = MOD, u = 1, v = 0;
        while (b) {
            long long t = a / b;
            a -= t * b; swap(a, b);
            u -= t * v; swap(u, v);
        }
        val = val * u % MOD;
        if (val < 0) val += MOD;
        return *this;
    }
    constexpr bool operator == (const Fp& r) const noexcept {
        return this->val == r.val;
    }
    constexpr bool operator != (const Fp& r) const noexcept {
        return this->val != r.val;
    }
    friend constexpr ostream& operator << (ostream &os, const Fp<MOD>& x) noexcept {
        return os << x.val;
    }
    friend constexpr Fp<MOD> modpow(const Fp<MOD> &a, long long n) noexcept {
        if (n == 0) return 1;
        auto t = modpow(a, n / 2);
        t = t * t;
        if (n & 1) t = t * a;
        return t;
    }
};
using mint = Fp<mod>;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n,k;cin >>n>>k;
    vector<vector<mint>>dp(n+1,vector<mint>(n+1,0));
    dp[0][0]=1;
    for (int i = 1; i <=n; ++i) {
        for(int j=n;j>=1;j--){
            if(i<j)continue;
            mint cost=(2*j<=n)?dp[i][2*j]:0;
            dp[i][j]=dp[i-1][j-1]+cost;
        }
    }
    cout <<dp[n][k]<<"\n";
    return 0;
}

#include<bits/stdc++.h>
using namespace std;
using ll = long long;
ll n, m, dp[2010][2010];
char s[2011][2011];
void solve() {
	scanf("%lld%lld", &n, &m);
	for (int i = 1; i <= n; i++)
		scanf("%s", s[i] + 1);
	memset(dp, 63, sizeof(dp));
	dp[n][m] = 0;
	for (int i = n; i > 0; i--)
		for (int j = m; j > 0; j--) {
			if (i == n && j == m)
				continue;
			dp[i][j] = max((s[i + 1][j] == '+' ? 1 : -1) - dp[i + 1][j],
			               (s[i][j + 1] == '+' ? 1 : -1) - dp[i][j + 1]);
		}
	if (dp[1][1] > 0)cout << "Takahashi\n";
	else if (dp[1][1] == 0)cout << "Draw\n";
	else cout << "Aoki\n";
}
int main() {
	// ios::sync_with_stdio(false), cin.tie(nullptr);
	solve();
	return 0;
}


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

ll n,x,a[N],dp[N][N][N];
ll k,ned;

ll cal(int i,int c,int mod){
    if(i==n){
        if(c==k && mod==ned)return 0;
        return -1e9;
    }
    if(dp[i][c][mod]!=-1)return dp[i][c][mod];
    ll sol=cal(i+1,c,mod);
    if(c+1<=k) sol=max(sol,cal(i+1,c+1,(mod+a[i])%k)+a[i]);
    return dp[i][c][mod]=sol;
}

int main()
{
#ifndef ONLINE_JUDGE
    freopen("in.txt", "r", stdin);
#endif
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cin>>n>>x;
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    ll ans=1e18;
    for(int i=1;i<=n;i++){
        memset(dp,-1,sizeof dp);
        k=i;
        ned=x%i;
        ll res=cal(0,0,0);
        if(res<=0)continue;
        ll rem=x-res;
        ans=min(ans,rem/i);
    }
    cout<<ans<<'\n';
}


#include <bits/stdc++.h>

#define fi first
#define se second

using namespace std;

const int N=2*1e5+5;

typedef pair<long long, long long> ii;

long long n, m, a=1, b;

ii pw(long long n)
{
    if (!n) return {0, 1};

    ii p=pw(n/2);

    p.fi=p.fi*p.fi*m+2*p.fi*p.se+p.se*p.se/m;p.fi%=m;
    p.se=p.se*p.se%m;

    if (n&1)
    {
        p.fi=p.fi*10+p.se*10/m;p.fi%=m;
        p.se=p.se*10%m;
    }

    return p;
}

void solve()
{
    cin>>n>>m;
    if (m==1) cout<<0;
    else cout<<pw(n).fi;
}

int main()
{
//	freopen(".inp","r",stdin);
//	freopen(".out","w",stdout);

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

	solve();

	return 0;
}

/*
 © 2021-05-01 07:01:01 Franco1010 All Rights Reserved
*/

// #pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math")
// #pragma GCC target("avx,avx2,fma")
#include <bits/stdc++.h>
#define f first
#define s second
#define fore(i,a,b) for(int i = (a), ThxMK = (b); i < ThxMK; ++i)
#define pb push_back
#define all(s) begin(s), end(s)
#define _ ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define sz(s) int(s.size())
#define ENDL '\n'
using namespace std;
typedef long double ld;
typedef long long lli;
typedef pair<lli,lli> ii;
typedef vector<lli> vi;
#define deb(x) cout << #x": " << (x) << endl;
const lli N = 5e2 + 5;
int a[N][N], b[N][N];
int dp[N][N];
bool vis[N][N];
lli n, m;
using Node = array<int,3>;
void dijkstra(){
  priority_queue<Node, vector<Node>, greater<Node>> pq;
  pq.push({0, 0, 0});
  dp[0][0] = 0;
  vis[0][0] = true;
  while(!pq.empty()){
    auto u = pq.top(); pq.pop();
    if(u[0] != dp[u[1]][u[2]]) continue;
    // (x, y + 1)
    int cost = u[0] + a[u[1]][u[2]];
    if(u[2] + 1 < m and (!vis[u[1]][u[2] + 1] or cost < dp[u[1]][u[2] + 1])){
      dp[u[1]][u[2] + 1] = cost;
      vis[u[1]][u[2] + 1] = true;
      pq.push({cost, u[1], u[2] + 1});
    }
    // (x, y - 1)
    if(u[2] > 0){
      cost = u[0] + a[u[1]][u[2] - 1];
      if(!vis[u[1]][u[2] - 1] or cost < dp[u[1]][u[2] - 1]){
        dp[u[1]][u[2] - 1] = cost;
        vis[u[1]][u[2] - 1] = true;
        pq.push({cost, u[1], u[2] - 1});
      }
    }
    // (x + 1, y)
    cost = u[0] + b[u[1]][u[2]];
    if(u[1] + 1 < n and (!vis[u[1] + 1][u[2]] or cost < dp[u[1] + 1][u[2]])){
      dp[u[1] + 1][u[2]] = cost;
      vis[u[1] + 1][u[2]] = true;
      pq.push({cost, u[1] + 1, u[2]});
    }
    // else
    fore(i, 1, u[1] + 1){
      cost = u[0] + lli(i) + 1ll;
      if(!vis[u[1] - i][u[2]] or cost < dp[u[1] - i][u[2]]){
        dp[u[1] - i][u[2]] = cost;
        vis[u[1] - i][u[2]] = true;
        pq.push({cost, u[1] - i, u[2]});
      }
    }
  }
  cout << dp[n - 1][m - 1] << ENDL;
}
int main(){ _
  // freopen("file.in","r",stdin);
  // freopen("file.out","w",stdout);
  cin >> n >> m;
  fore(i, 0, n) fore(j, 0, m - 1) cin >> a[i][j];
  fore(i, 0, n - 1) fore(j, 0, m) cin >> b[i][j];
  dijkstra();
  return 0;
}


#include <cstdio>
#define ll long long
using namespace std;
int n,m;ll p[5010],g[5010][5010],ans;
const ll mod=998244353;
int main()
{
	scanf("%d %d",&n,&m);
	p[0]=1;
	for(int i=1;i<=n;i++)
		p[i]=p[i-1]*m%mod;
	for(int i=0;i<=m;i++)
	{
		g[i][0]=1;
		for(int j=1;j<=n;j++)
			g[i][j]=g[i][j-1]*i%mod;
	}
	ans=p[n]*n%mod;
	for(int x=1;x<=m;x++)
		for(int j=1;j<n;j++)
			ans=(ans-(n-j)*g[m-x][j-1]%mod*p[n-j-1]%mod+mod)%mod;
	printf("%lld",ans);
}

#pragma region head
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vll = vector<ll>;
using pi = pair<int, int>;
using pll = pair<ll, ll>;
template <class T>
using vv = vector<vector<T>>;
#define _roverload(_a1, _a2, _a3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for (int i = int(a); i < int(b); ++i)
#define rep(...) _roverload(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define _rrep(i, n) rrepi(i, 0, n)
#define rrepi(i, a, b) for (int i = (int)(b)-1; i >= (int)(a); --i)
#define rrep(...) _roverload(__VA_ARGS__, rrepi, _rrep, )(__VA_ARGS__)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define bit(n) (1LL << (n))
template <class T>
inline bool chmax(T& a, const T& b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
inline bool chmin(T& a, const T& b) {
    if (a > b) {
        a = b;
        return 1;
    }
    return 0;
}
void print() { cout << '\n'; }
template <class T>
void print(const vector<T>& v) {
    bool f = false;
    for (const auto& e : v) {
        if (f) cout << ' ';
        cout << e;
        f = true;
    }
    cout << '\n';
}
template <class... T>
void print(const T&... args) {
    bool f = false;
    for (const auto& e : {args...}) {
        if (f) cout << ' ';
        cout << e;
        f = true;
    }
    cout << '\n';
}
const int INF = 1002003004;
const ll LINF = 1002003004005006007ll;
struct preprocess {
    preprocess() {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(20);
    }
} ____;
#pragma endregion head

#pragma region library
const int MOD = 998244353;
struct mint {
    ll x;  // typedef long long ll;
    mint(ll x = 0) : x((x % MOD + MOD) % MOD) {}
    mint operator-() const { return mint(-x); }
    mint& operator+=(const mint a) {
        if ((x += a.x) >= MOD) x -= MOD;
        return *this;
    }
    mint& operator-=(const mint a) {
        if ((x += MOD - a.x) >= MOD) x -= MOD;
        return *this;
    }
    mint& operator*=(const mint a) {
        (x *= a.x) %= MOD;
        return *this;
    }
    mint operator+(const mint a) const {
        mint res(*this);
        return res += a;
    }
    mint operator-(const mint a) const {
        mint res(*this);
        return res -= a;
    }
    mint operator*(const mint a) const {
        mint res(*this);
        return res *= a;
    }
    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t >> 1);
        a *= a;
        if (t & 1) a *= *this;
        return a;
    }
    // for prime MOD
    mint inv() const {
        return pow(MOD - 2);
    }
    mint& operator/=(const mint a) {
        return (*this) *= a.inv();
    }
    mint operator/(const mint a) const {
        mint res(*this);
        return res /= a;
    }
    bool operator==(const mint a) const {
        return x == a.x;
    }
    bool operator!=(const mint a) const {
        return x != a.x;
    }
    friend ostream& operator<<(ostream& os, const mint& value) {
        os << value.x;
        return os;
    }
    friend istream& operator>>(istream& is, mint& value) {
        ll t;
        is >> t;
        value = mint(t);
        return is;
    }
};

#pragma endregion library

int main() {
    int n, m;
    cin >> n >> m;
    mint mm = m;
    mint ans = mm.pow(n) * n;
    vector<mint> mpow(n + 1);
    mpow[0] = 1;
    rep(i, n) {
        mpow[i + 1] = mpow[i] * m;
    }
    rep(v, 1, m + 1) {
        vll vs(n);
        vs[0] = 1;
        mint now = 1;
        mint mv = 1;
        rep(i, 1, n) {
            ans -= now * mpow[n - i - 1];
            now *= m;
            mv *= m - v;
            now += mv;
        }
    }
    print(ans);
}


#include <bits/stdc++.h>
using namespace std;
#define int long long
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define pb push_back
#define IOS ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define Test int T;cin>>T;while(T--)
#define ls lower_bound
#define up upper_bound
#define bs binary_search
#define S second
#define F first
#define vi vector<int>
#define pii pair<int,int>
#define vpii vector<pii>
#define vvi vector<vi>
#define gcd(a,b) __gcd((a),(b))
#define lcm(a,b) ((a)*(b))/gcd((a),(b))
#define m_n(v) *min_element(all(v))
#define m_x(v) *max_element(all(v))
#define _(a) for(auto &i:a)
#define nl cout<<"\n";
#define momo(k) memset(k,0,sizeof(k))
#define momi(k) memset(k,-1,sizeof(k))
// #include <ext/pb_ds/assoc_container.hpp> using namespace __gnu_pbds;
// typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>indexed_set;

// const int mod = 1e9+7;
// int power(int x, int y,int mod){
//     int res = 1;
//     while (y){
//         if (y & 1)
//         res = (res*x)%mod;
//         y = y>>1;
//         x = (x*x)%mod;
//     }
//     return res;
// }
// modInv = power(a,m-2,m)

// int fac[10009];

// void factorial(int n){
// 	fac[0]=1;
// 	for(int i=1;i<=n;i++)fac[i]=(i*fac[i-1])%mod;
// }
// //
// int ncr(int n,int r){
// 	return (fac[n]*((power(fac[r],mod-2,mod)*power(fac[n-r],mod-2,mod))%mod))%mod;
// }
// vector<int> prime;
// void sieve(){
//     bool arr[200000]={0};
//     prime.pb(2);
//     for(int i=3;i<200000;i+=2){
//         if(arr[i])continue;
//         for(int j=i*i;j<200000;j+=i) arr[j]=1;
//         prime.pb(i);
//     }
// }
// const int N=1e18+2;
const int N = 2e5+9;
const int mod = 1e9+7;
void doper(){
	#ifndef ONLINE_JUDGE
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
	freopen("error.txt","w",stderr);
	#endif
}

int32_t main(){
    // doper();
    IOS;
	int a,b;
	cin>>a>>b;
	if(a > b){
		int s = 0;
		for(int i=1;i<=a;i++) {
			cout<<i<<" ";
			s += i;
		}
		for(int i=1;i<b;i++){
			cout<<-1*i<<" ";
			s -= i;
		}
		cout<<-1*s;
	}
	else if(a == b){
		for(int i=1;i<=a;i++) cout<<i<<" ";
		for(int j=1;j<=b;j++) cout<<-1*j<<" ";
	}
	else{
		int s = 0;
		for(int i=1;i<=b;i++) {
			cout<<-1*i<<" ";
			s -= i;
		}
		for(int i=1;i<a;i++){
			cout<<i<<" ";
			s += i;
		}
		cout<<-1*s;
	}
    return 0;
}

#include <iostream>
#include <stdio.h>
#include <vector>

//martin02

using namespace std;

int main() {
	int a, b;
	scanf("%d %d", &a, &b);
	vector<int> v(a + b, 0);
	for (int i = 0; i < a; i++) {
		v.at(i) = i + 1;
	}

	for (int i = a; i < a + b; i++) {
		v.at(i) = -1 * (i - a + 1);
	}

	if (a * (a + 1) / 2 - b * (b + 1) / 2 > 0) {
		v.at(a + b - 1) -= a * (a + 1) / 2 - b * (b + 1) / 2;
	}
	else {
		v.at(a - 1) -= a * (a + 1) / 2 - b * (b + 1) / 2;;
	}

	for (int i = 0; i < a + b; i++) {
		printf("%d ", v.at(i));
	}
	printf("\n");

	return 0;
}


// Template begins
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <stdio.h>
#include <math.h>
#include <iomanip>
#include <queue>
#include <string.h>
#include <string>
using namespace std;
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define ll long long
#define endl "\n"
#define lb lower_bound
#define ub upper_bound
#define fo(i,a,b) for(i=a;i<=b;i++)
#define all(v) (v).begin(),(v).end()
#define sort0(v) sort(all(v))
#define lbb(a,b,arr,x) lower_bound(arr+a,arr+b+1,x)-arr
#define ubb(a,b,arr,x) upper_bound(arr+a,arr+b+1,x)-arr
#define freq(a,b,arr,x) upper_bound(arr+a,arr+b+1,x)-lower_bound(arr+a,arr+b+1,x)
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define d0(x) cout<<(x)<<" "
#define d1(x) cout<<(x)<<endl
#define d2(x,y) cout<<(x)<<" "<<(y)<<endl
#define d3(x,y,z) cout<<(x)<<" "<<(y)<<" "<<(z)<<endl
#define d4(a,b,c,d) cout<<(a)<<" "<<(b)<<" "<<(c)<<" "<<(d)<<endl
#define d5(a,b,c,d,e) cout<<(a)<<" "<<(b)<<" "<<(c)<<" "<<(d)<<" "<<(e)<<endl
#define d6(a,b,c,d,e,f) cout<<(a)<<" "<<(b)<<" "<<(c)<<" "<<(d)<<" "<<(e)<<" "<<(f)<<endl
#define max3(a,b,c) max(max((a),(b)),(c))
#define max4(a,b,c,d) max(max((a),(b)),max((c),(d)))
#define ss second
#define ff first
#define pb push_back
#define mp make_pair
#define printp(x) cout << x.ff << " " << x.ss << endl

const ll mod=998244353;
#define inf 9999999999999
#define MAXN   100001

// stores smallest prime factor for every number

ll inv(ll i){if(i==1) return 1;return (mod-((mod/i)*inv(mod%i))%mod)%mod;}

ll gcd(ll a,ll b){if(a==0) return b;return gcd(b,b%a);}
inline void fastio(){ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);}
// Template ends
const int MN = 2e5+7;
ll val(ll a){
    return ((a*(a+1))/2)%mod;
}
void solve(){
    ll a,b,c; cin>>a>>b>>c;
    a%=mod; b%=mod; c%=mod;
    ll ans=val(a); ans%=mod;
    ans= (ans*val(b))%mod;
    ans=(ans*val(c))%mod;
    cout<<ans<<endl;

}
int main(){
    fastio();
    //write code
    int t; t=1;
    while(t--){
        solve();
    }
    return 0;
}

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

//Cの計算 C[i][j]でiCjを得る
void combination(vector<vector <long long> > &v){
    for(int i = 0;i <v.size(); i++){
        v[i][0]=1;
        v[i][i]=1;
    }
    for(int k = 1;k <v.size();k++){
        for(int j = 1;j<k;j++){
          //modの法は問題により変更
          v[k][j]=(v[k-1][j-1]+v[k-1][j])%998244353;
        }
    }
}

ll ptn(ll k,ll N,vector<vector<ll>> &C,vector<ll> &f){
    ll a = 0;
    if(f[k]!=-1) return f[k];
    if(k==0) return 1LL;
    if(k==2) return C[N][2];
    for(ll i=0;i<=k;i += 2){
        if((k-i)%4!=0) continue;
        a += (C[N][i]*ptn((k-i)/2,N,C,f))%998244353; a%= 998244353;
    }
    f[k] = a; return a;
}

int main(){
    //main関数内に以下をペースト Kは計算が必要な最大の大きさ
    vector<vector<long long>> C(5001,vector<long long int>(5001,0));
    combination(C);
    ll N,M; cin >> N >> M;
    vector<ll> f;
    rep(i,M+1){
        f.push_back(-1);
    }
    ll ans = ptn(M,N,C,f);
    cout << ans  << endl;
}


#include <bits/stdc++.h>

using namespace std;

namespace ftr {

vector<int> prime;

void run_sieve(int n) {
  assert((int) prime.size() == 0);
  prime = vector<int>(n, 1);
  prime[0] = prime[1] = 0;
  for (int i = 2; i < n; i++) {
    if (prime[i]) {
      for (int j = i + i; j < n; j += i) {
        prime[j] = 0;
      }
    }
  }
}

template <typename T>
vector<pair<T, int>> factorize(T x) {
  if (x <= 1) {
    return {};
  }
  vector<pair<T, int>> ret;
  for (T i = 2; i * i <= x; i++) {
    T t = x / i;
    if (i > t) break;
    if (x == t * i) {
      int cnt = 0;
      while (x % i == 0) {
        x /= i;
        cnt++;
      }
      ret.emplace_back(i, cnt);
    }
  }
  if (x > 1) {
    ret.emplace_back(x, 1);
  }
  return ret;
}

} // namespace ftr

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  ftr::run_sieve(100);
  vector<int> primes;
  int val = 2;
  while ((int) primes.size() < 20) {
    if (ftr::prime[val]) {
      primes.push_back(val);
    }
    ++val;
  }
  long long A, B;
  cin >> A >> B;
  const int N = (int) primes.size();
  vector<long long> dp(1 << N);
  dp[0] = 1;
  for (long long val = A; val <= B; val++) {
    int bit = 0;
    for (int i = 0; i < N; i++) {
      if (val % primes[i] == 0) {
        bit |= (1 << i);
      }
    }
    for (int t = 0; t < (1 << N); t++) {
      if ((bit & t) == 0) {
        dp[bit ^ t] += dp[t];

      }
    }
  }
  long long ans = 0;
  for (int i = 0; i < (1 << N); i++) {
    ans += dp[i];
  }
  cout << ans << '\n';
  return 0;
}

#include <bits/stdc++.h>

using namespace std;

//begin of def

#define fastio ios_base::sync_with_stdio(false);cin.tie(0)
#define endl '\n'

using lli = long long int;
using ulli = unsigned long long int;
using Ld = long double;
using pii = pair<int, int>;
using pll = pair<lli, lli>;
using pld = pair<Ld, Ld>;
#define X first
#define Y second

#define rep(I, S, E) for(int I = (S); I < (E); I++)
#define repq(I, S, E) for(int I = (S); I <= (E); I++)

#define pb push_back
#define epb emplace_back

#define ALL(X) X.begin(), X.end()

//end of def

int main(){
    fastio;
    int n;
    cin >> n;
    string a, b;
    cin >> a >> b;
    int az = 0, bz = 0;
    int ct = 0;
    rep(i, 0, n){
        if(b[i] == '0'){
            bz++;
        }
        if(a[i] == '0'){
            az++;
            ct += (az != bz || a[i] != b[i]);
        }
    }
    if(az != bz)
        cout << -1;
    else
        cout << ct;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using VI = vector<int>;
using VL = vector<ll>;
using VS = vector<string>;
template<class T> using PQ = priority_queue<T, vector<T>, greater<T>>;
#define FOR(i,a,n) for(int i=(a);i<(n);++i)
#define eFOR(i,a,n) for(int i=(a);i<=(n);++i)
#define rFOR(i,a,n) for(int i=(n)-1;i>=(a);--i)
#define erFOR(i,a,n) for(int i=(n);i>=(a);--i)
#define SORT(a) sort(a.begin(),a.end())
#define rSORT(a) sort(a.rbegin(),a.rend())
#define fSORT(a,f) sort(a.begin(),a.end(),f)
#define all(a) a.begin(),a.end()
#define out(y,x) ((y)<0||h<=(y)||(x)<0||w<=(x))
#define tp(a,i) get<i>(a)
#ifdef _DEBUG
#define line cout << "-----------------------------\n"
#define stop system("pause")
#define debug(x) print(x)
#endif
constexpr ll INF = 1000000000;
constexpr ll LLINF = 1LL << 60;
constexpr ll mod = 1000000007;
constexpr ll MOD = 998244353;
constexpr ld eps = 1e-10;
constexpr ld pi = 3.1415926535897932;
template<class T>inline bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; }return false; }
template<class T>inline bool chmin(T& a, const T& b) { if (a > b) { a = b; return true; }return false; }
inline void init() { cin.tie(nullptr); cout.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); }
template<class T>inline istream& operator>>(istream& is, vector<T>& v) { for (auto& a : v)is >> a; return is; }
template<class T, class U>inline istream& operator>>(istream& is, pair<T, U>& p) { is >> p.first >> p.second; return is; }
template<class T>inline vector<T> vec(size_t a) { return vector<T>(a); }
template<class T>inline vector<T> defvec(T def, size_t a) { return vector<T>(a, def); }
template<class T, class... Ts>inline auto vec(size_t a, Ts... ts) { return vector<decltype(vec<T>(ts...))>(a, vec<T>(ts...)); }
template<class T, class... Ts>inline auto defvec(T def, size_t a, Ts... ts) { return vector<decltype(defvec<T>(def, ts...))>(a, defvec<T>(def, ts...)); }
template<class T>inline void print(const T& a) { cout << a << "\n"; }
template<class T, class... Ts>inline void print(const T& a, const Ts&... ts) { cout << a << " "; print(ts...); }
template<class T>inline void print(const vector<T>& v) { for (int i = 0; i < v.size(); ++i)cout << v[i] << (i == v.size() - 1 ? "\n" : " "); }
template<class T>inline void print(const vector<vector<T>>& v) { for (auto& a : v)print(a); }
inline string reversed(const string& s) { string t = s; reverse(all(t)); return t; }
template<class T>inline T sum(const vector<T>& a, int l, int r) { return a[r] - (l == 0 ? 0 : a[l - 1]); }
template<class T>inline void END(T s) { print(s); exit(0); }
void END() { exit(0); }

int main() {
    init();

    int n; cin >> n;
    VI a(n), b(n), p(n); cin >> a >> b >> p;

    set<pair<int, int>> s; // {持てる重さ、index}
    FOR(i, 0, n) {
        --p[i];
        if (a[i] <= b[p[i]] && p[i] != i)END(-1);
        if (i != p[i]) {
            s.emplace(a[i], i);
        }
    }

    vector<pair<int, int>> ans;
    while (!s.empty()) {
        int cur = s.rbegin()->second;
        int to = p[cur];
        ans.emplace_back(cur, to);
        if (p[to] == cur) {
            s.erase(pair<int, int>(a[cur], cur));
            s.erase(pair<int, int>(a[to], to));
        }
        else {
            s.erase(pair<int, int>(a[to], to));
            p[cur] = p[to];
        }
    }

    print(ans.size());
    for (auto [x, y] : ans)print(x + 1, y + 1);

    return 0;
}

#include<bits/stdc++.h>
using namespace std;
#define int long long
int dp[60][2];
int two_power(int x)
{
    int mul=1;
    for(int i=0;i<x;i++) mul*=2;
    return mul;
}
int32_t main()
{
    ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
    dp[0][1]=1,dp[0][0]=0;
    int n;cin>>n;
    vector <string> s(n+1);
    for(int i=1;i<=n;i++) cin>>s[i];
    for(int i=1;i<=n;i++)
    {
        for(int j=0;j<2;j++)
        {
            if(s[i]=="AND" and j==1) dp[i][j]=dp[i-1][0]+dp[i-1][1];
            else if(s[i]=="AND" and j==0) dp[i][j]=0;
            else if(s[i]=="OR" and j==1) dp[i][j]=two_power(i);
            else if(s[i]=="OR" and j==0) dp[i][j]=dp[i-1][0]+dp[i-1][1];
        }
    }
    cout<<dp[n][1]+dp[n][0]<<endl;
    return 0;
}
/*

*/


#include <bits/stdc++.h>
// #include <atcoder/all>
// using namespace atcoder;
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) x.begin(),x.end()
#define SZ(x) ((int)(x).size())
#define PB push_back
#define MP make_pair
#define V vector
#define P pair<int,int>
#define F first
#define S second
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; }
using ll = long long;
using ld = long double;
using namespace std;
const int INF =1001001001;
const int MAX = 2e6+1;

ll in(){
    double x;
    cin>>x;
    x*=10000;
    return round(x);
}

int main() {
    ll x=in();
    ll y=in();
    ll r=in();
    x%=10000;
    y%=10000;
    ll ans=0;
    ll rr=r*r;
    ll y1=(y/10000)*10000;
    ll y2=y1+10000;
    ll right=0,left=0;

    while((x-right)*(x-right)+(y-y1)*(y-y1)<=rr){
        right+=10000;
    }
    while((x-left)*(x-left)+(y-y1)*(y-y1)<=rr){
        left-=10000;
    }
    while(y1>=y-r){
        while((x-right)*(x-right)+(y-y1)*(y-y1)>rr){
            right-=10000;
        }
        while((x-left)*(x-left)+(y-y1)*(y-y1)>rr){
            left+=10000;
        }
        if(right>=left)
        ans+=(right-left+10000)/10000;
        y1-=10000;
    }

    right=0;left=0;
    while((x-right)*(x-right)+(y-y2)*(y-y2)<=rr){
        right+=10000;
    }
    while((x-left)*(x-left)+(y-y2)*(y-y2)<=rr){
        left-=10000;
    }
    while(y2<=y+r){
        while((x-right)*(x-right)+(y-y2)*(y-y2)>rr){
            right-=10000;
        }
        while((x-left)*(x-left)+(y-y2)*(y-y2)>rr){
            left+=10000;
        }
        if(right>=left)
        ans+=(right-left+10000)/10000;
        y2+=10000;
    }

    cout<<ans<<endl;
}

#include <bits/stdc++.h>

template <typename T> inline void rd(T& x) {
	int si = 1; char c = getchar(); x = 0;
	while(!isdigit(c)) si = c == '-' ? -1 : si, c = getchar();
	while(isdigit(c)) x = x * 10 + c - 48, c = getchar();
	x *= si;
}
template <typename T, typename... Args>
inline void rd(T& x, Args&... args) { rd(x); rd(args...); }
#define fi first
#define se second
#define mkp std::make_pair
typedef long long ll;
typedef double ff;
typedef std::pair <int, int> pii;
const int N = 1e5 + 5, B = 14, Inf = 0x3f3f3f3f, Mod = 998244353;
const ll InfLL = 0x3f3f3f3f3f3f3f3fLL;

int QPow(int a, int b) {
	int ret = 1, bas = a;
	for(; b; b >>= 1, bas = 1LL * bas * bas % Mod)
		if(b & 1) ret = 1LL * ret * bas % Mod;
	return ret;
}

int n, m, f[B][N], fac[N], fac_inv[N];
void Init() {
	fac[0] = 1;
	for(int i = 1; i <= n; ++i) fac[i] = 1LL * fac[i - 1] * i % Mod;
	fac_inv[n] = QPow(fac[n], Mod - 2);
	for(int i = n - 1; ~i; --i) fac_inv[i] = 1LL * fac_inv[i + 1] * (i + 1) % Mod;
}
int C(int x, int y) {
	return 1LL * fac[x] * fac_inv[x - y] % Mod * fac_inv[y] % Mod;
}
void Calc() {
	f[0][0] = 1;
	for(int i = 1; i < B; ++i) {
		for(int j = 0; j <= m; ++j) {
			for(int k = 0; k * (1 << (i - 1)) <= j && k <= n; k += 2)
				f[i][j] = (1LL * f[i - 1][j - k * (1 << (i - 1))] * C(n, k) + f[i][j]) % Mod;
		}
	}
}

int main() {
#ifndef ONLINE_JUDGE
	freopen("a.in", "r", stdin);
	freopen("a.out", "w", stdout);
#endif
	int test_case_cnt = 1; //rd(test_case_cnt);
	while(test_case_cnt--) {
		rd(n, m); Init(); Calc();
		printf("%d\n", f[B - 1][m]);
	} return 0;
}