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

using namespace std;

template<typename T>
long long modpow(const T n,const T p,const T mod);
template<typename T>
long long modinv(const T n,const T mod);
template<typename T>
bool chmax(T &a,const T &b);
template<typename T>
bool chmin(T &a,const T &b);

long long inf=1000000007;

int main(){
    int a,b;
  cin>>a>>b;
  for(int i=-1000;i<=1000;i++){
    for(int j=-1000;j<=1000;j++){
    if(i+j==a && i-j==b){
      cout<<i<<" "<<j<<endl;
      return 0;
      }
  }
  }

    return 0;
}

template<typename T>
long long modpow(const T n,const T p,const T mod){
    if(p==0) return 1;
    if(p%2==0){
        long long a=modpow(n,p/2,mod);
        return a*a%mod;
    }
    if(p%2==1) return (modpow(n,p-1,mod)*n)%mod;
    cerr<<"ERROR"<<endl;
    return 1;
}

template<typename T>
long long modinv(const T n,const T mod){
    return modpow(n,mod-2,mod);
}

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

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

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

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

using namespace std;

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

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

template<class T> inline void amin(T &x, const T &y) { if (y<x) x=y; }
template<class T> inline void amax(T &x, const T &y) { if (x<y) x=y; }
#define rprintf(fmt, begin, end) do { const auto end_rp = (end); auto it_rp = (begin); for (bool sp_rp=0; it_rp!=end_rp; ++it_rp) { if (sp_rp) putchar(' '); else sp_rp = true; printf(fmt, *it_rp); } putchar('\n'); } while(0)

int N, M;
vector<pair<int, int> > G[2011];

LL D[2011];

void MAIN() {
    scanf("%d%d", &N, &M);
    REP (i, M) {
	int x, y, c;
	scanf("%d%d%d", &x, &y, &c);
	x--; y--;
	G[x].emplace_back(y, c);
    }

    REP (s, N) {
	memset(D, 0x3f, sizeof D);
	const int INF = D[0];
	D[s] = 0;
	priority_queue<pair<LL, int> > Q;
	Q.emplace(0, s);
	while (!Q.empty()) {
	    int v = Q.top().second;
	    LL cst = -Q.top().first;
	    Q.pop();
	    if (cst != D[v]) continue;

	    EACH (e, G[v]) {
		int w = e->first;
		LL tmp = cst + e->second;
		if (D[w] > tmp) {
		    D[w] = tmp;
		    Q.emplace(-tmp, w);
		}
	    }
	}

	LL ans = INF;
	REP (v, N) EACH (e, G[v]) {
	    int w = e->first;
	    int c = e->second;
	    if (w == s) amin(ans, D[v] + c);
	}

	if (ans == INF) puts("-1");
	else printf("%lld\n", ans);

    }

}

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


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

int main(void) {
	int n, k;
	cin >> n >> k;
	int ans = 0;
	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= k; j++) {
			ans += i * 100 + j;
		}
	}
	cout << ans << endl;
	return 0;
}

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

int main(){
    ll n,k;
    cin>>n>>k;
    cout<<100*k*(n*(n+1)/2)+n*k*(k+1)/2<<endl;

    return 0;
}


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

typedef long long ll;

// union by size + path having
class UnionFind {
public:
    vector <ll> par; // 各元の親を表す配列
    vector <ll> siz; // 素集合のサイズを表す配列(1 で初期化)

    // Constructor
    UnionFind(ll sz_): par(sz_), siz(sz_, 1LL) {
        for (ll i = 0; i < sz_; ++i) par[i] = i; // 初期では親は自分自身
    }
    void init(ll sz_) {
        par.resize(sz_);
        siz.assign(sz_, 1LL);  // resize だとなぜか初期化されなかった
        for (ll i = 0; i < sz_; ++i) par[i] = i; // 初期では親は自分自身
    }

    // Member Function
    // Find
    ll root(ll x) { // 根の検索
        while (par[x] != x) {
            x = par[x] = par[par[x]]; // x の親の親を x の親とする
        }
        return x;
    }

    // Union(Unite, Merge)
    bool merge(ll x, ll y) {
        x = root(x);
        y = root(y);
        if (x == y) return false;
        // merge technique（データ構造をマージするテク．小を大にくっつける）
        if (siz[x] < siz[y]) swap(x, y);
        siz[x] += siz[y];
        par[y] = x;
        return true;
    }

    bool issame(ll x, ll y) { // 連結判定
        return root(x) == root(y);
    }

    ll size(ll x) { // 素集合のサイズ
        return siz[root(x)];
    }
};

int main(){
  ios::sync_with_stdio(false);
  std::cin.tie(nullptr);
  cout << fixed << setprecision(10);
  /*--------------------------------*/

  int n;cin>>n;
//   n=10000000;
  vector<ll> p(n);
  for(int i=0;i<n;i++)cin>>p[i];
//   for(int i=0;i<n;i++)p[i]=i+1;
  vector<pair<ll,ll> >vec(n);
  for(int i=0;i<n;i++){
      vec[i].first=p[i];vec[i].second=i;
  }
  sort(vec.begin(),vec.end());
  reverse(vec.begin(),vec.end());
  UnionFind tree(n);
  vector<int> flag(n);
  ll ans=-1;
  ll ans_name=-1,ans_size=-1;
  for(int i=0;i<n;i++){
      ll name=vec[i].second,value=vec[i].first;
      flag[name]=1;
      if(name!=0 && flag[name-1]==1){
          tree.merge(name,name-1);
          if(ans<tree.size(name)*value){
              ans=tree.size(name)*value;
              ans_name=value;
              ans_size=tree.size(name);
          }
      }
      if(name!=n-1 && flag[name+1]==1){
          tree.merge(name,name+1);
          if(ans<tree.size(name)*value){
              ans=tree.size(name)*value;
              ans_name=value;
              ans_size=tree.size(name);
          }
      }
  }
  ll res=ans_size*ans_name;
//   cout<<ans_size<<" "<<ans_name<<endl;
  for(int i=0;i<n;i++){
      res=max(res,(ll)p[i]);
    //   cout<<p[i]<<endl;
  }
  cout<<res<<endl;
}

#include <bits/stdc++.h>
using namespace std;
#define rep(i, a, b) for (lli i = a; i < b; i++)
#define lli long long int
#define ld long double
#define all(v) v.begin(), v.end()
#define hell 1000000000000000
#define pb push_back
#define vi vector<lli>
#define vip vector<pair<lli, lli>>
#define F first
#define S second
#define mod 998244353
lli n = 10000000;
vector<bool> p(n + 1, true);
void sieve()
{
    for (long long int i = 2; i * i <= n; i++)
    {
        if (p[i])
        {
            for (long long int j = i + i; j <= n; j = j + i)
            {
                p[j] = false;
            }
        }
    }
}
lli Gcd(lli a, lli b)
{
    if (a % b == 0)
    {
        return b;
    }
    return Gcd(b, a % b);
}
lli power(lli a, lli n)
{
    lli res = 1;
    while (n > 0)
    {
        if (n & 1)
            res = ((res % mod) * (a % mod)) % mod, n--;
        else
            a = ((a % mod) * (a % mod)) % mod, n /= 2;
    }
    return res;
}
void solve()
{
    lli n,ans=0;
    cin>>n;
    lli a[n];
    rep(i,0,n)
    {
        cin>>a[i];
    }
    rep(l,0,n)
    {
        lli x=a[l];
        rep(r,l,n)
        {
           x=min(x,a[r]);
           ans=max(ans,x*(r-l+1));
        }
        // cout<<ans<<" ";
    }
    cout<<ans;
    cout<<endl;
    // cout << (double)clock()/CLOCKS_PER_SEC << endl;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    // sieve();
    lli t = 1;
    while (t--)
    {
        solve();
    }
}


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

#define ll long long
#define rep(i, n) for (ll i = 0; i < n; ++i)
#define rep_up(i, a, b) for (ll i = a; i < b; ++i)
#define rep_down(i, a, b) for (ll i = a; i > b; --i)
#define P pair<ll, ll>
#define Graph vector<vector<ll>>
#define fi first
#define se second
#define vvvll vector<vector<vector<ll>>>
#define vvll vector<vector<ll>>
#define vll vector<ll>

constexpr ll INF = (1ll << 60);
constexpr ll mod = 998244353;
constexpr double pi = 3.14159265358979323846;
template <typename T>
inline bool chmax(T &a, T b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <typename T>
inline bool chmin(T &a, T b) {
    if (a > b) {
        a = b;
        return 1;
    }
    return 0;
}

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

ll modinv(ll a, ll 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;
}

int gcd(int x, int y) { return (x % y)? gcd(y, x % y): y; }

int main(){
    ll h,w,k,a,b,p;
    char c;
    cin>>h>>w>>k;
    vector<vector<ll>> x(h+1, vector<ll>(w+1,0));
    vector<vector<char>> y(h+1, vector<char>(w+1,'N'));
    rep(i,k){
        cin>>a>>b>>c;
        y[a-1][b-1]=c;
    }
    x[0][0]=modpow(3,h*w-k,mod);
    rep(i,h){
        rep(j,w){
            x[i][j]%=mod;
            if(y[i][j]=='X'){
                x[i+1][j]+=x[i][j];
                x[i][j+1]+=x[i][j];
            }else if(y[i][j]=='R'){
                x[i][j+1]+=x[i][j];
            }else if(y[i][j]=='D'){
                x[i+1][j]+=x[i][j];
            }else{
                p=x[i][j]*2*modinv(3,mod)%mod;
                x[i+1][j]+=p;
                x[i][j+1]+=p;
            }
        }
    }
    cout<<x[h-1][w-1]<<endl;
}


#define LOCAL
#ifdef LOCAL
#define _GLIBCXX_DEBUG
#endif
#include <bits/stdc++.h>
using namespace std;

#define int long long
#define rep(i,s,n) for (int i = (ll)s; i < (ll)n; i++)
#define rrep(i,n,e) for (int i = (ll)n; i > (ll)e; i--)
#define ll long long
#define ld long double
#define pb push_back
#define eb emplace_back
#define All(x) x.begin(), x.end()
#define Range(x, i, j) x.begin() + i, x.begin() + j
// #define M_PI 3.14159265358979323846 // CF
#define deg2rad(deg) ((((double)deg)/((double)360)*2*M_PI))
#define rad2deg(rad) ((((double)rad)/(double)2/M_PI)*(double)360)
#define Find(set, element) set.find(element) != set.end()
#define Decimal(x) cout << fixed << setprecision(10) << x << endl; // print Decimal number 10 Rank
#define endl "\n"
#define Case(x) printf("Case #%d: ", x); // gcj

typedef pair<int, int> PI;
typedef pair<ll, ll> PLL;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<vector<vector<int>>> vvvi;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<vector<vector<ll>>> vvvl;
typedef vector<PI> vpi;
typedef vector<vector<PI>> vvpi;
typedef vector<PLL> vpl;
typedef vector<vector<PLL>> vvpl;
typedef vector<char> vch;
typedef vector<vector<char>> vvch;

constexpr ll INF = 1001002003004005006ll;
constexpr int n_max = 2e5+10;

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

template<class T, class U>
T POW(T x, U n) {T ret=1; while (n>0) {if (n&1) {ret*=x;} x*=x; n>>=1;} return ret;};

// debug
template <typename A, typename B>
string to_string(pair<A, B> p);
string to_string(const string &s) {return '"' + s + '"';};
string to_string(const char c) {return to_string((string) &c);};
string to_string(bool b) {return (b ? "true" : "false");};
template <size_t N>
string to_string(bitset<N> v){
  string res = "";
  for(size_t i = 0; i < N; i++) res += static_cast<char>('0' + v[i]);
  return res;
};
template <typename A>
string to_string(A v) {
  bool first = true;
  string res = "{";
  for(const auto &x : v) {
    if(!first) res += ", ";
    first = false; res += to_string(x);
  }
  res += "}";
  return res;
};
template <typename A, typename B>
string to_string(pair<A, B> p){return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";}

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

void LINE_OUT() {
  cout << "--------------" << endl;
};

#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#define LINE LINE_OUT();
#else
#define debug(...) 71
#define LINE 71;
#endif

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

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

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

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

  int N, M; cin >> N >> M;
  vi mem(1005);
  rep(i,0,N) {
    int a; cin >> a; mem[a]++;
  }
  rep(i,0,M) {
    int b; cin >> b; mem[b]--;
  }

  vi ans;
  rep(i,0,1005) {
    if (mem[i] != 0) ans.pb(i);
  }
  rep(i,0,ans.size()) {
    cout << ans[i];
    if (i < ans.size()-1) cout << " ";
  }
  cout << endl;

  return 0;
};

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

#define int long long
typedef long long ll;
typedef long double ld;
const int inf=1e9+7;
const ll INF=1LL<<60;
#define rep(i, n) for(int i = 0; i < n; ++ i)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
#define fr first
#define sc second
#define all(c) c.begin(),c.end()
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

template <class Abel> struct BIT {
private:
	vector<Abel> node; int n;
    Abel UNITY_SUM = 0; //to be set
public:
	BIT(int n_) {
		n = n_; node.resize(n, UNITY_SUM);
	}
	//0-indexed
	void add(int a, Abel w) {
		for (int i = a; i < n; i |= i + 1)node[i] += w;
	}
	//[0,a)
	Abel sum(int a) {
		Abel ret = UNITY_SUM;
		for (int i = a - 1; i >= 0; i = (i&(i + 1)) - 1)ret += node[i];
		return ret;
	}
	//[a,b)
	Abel sum(int a, int b) {
		return sum(b) - sum(a);
	}
	//k-th number (k is 0-indexed)
    int get(int k) {
        ++k;
        int res = 0;
        int n = 1; while(n < (int)node.size()) n *= 2;
        for(int i = n / 2; i > 0; i /= 2) {
            if(res + i <= (int)node.size() && node[res + i - 1] < k) {
                k -= node[res + i - 1];
                res += i;
            }
        }
        return res; //0-indexed
    }
    //debug
    void print() {
        for(int i = 0; i < n; ++i) cout << sum(i, i + 1) << ",";
        cout << endl;
    }
};

void solve() {
	int h, w, m; cin >> h >> w >> m;
    ll ans = h * w;
    vector<int> x(m), y(m);
    int a = w, b = h;
    rep(i, m) {
        cin >> x[i] >> y[i];
        -- x[i], -- y[i];
        if(x[i] == 0) chmin(a, y[i]);
        if(y[i] == 0) chmin(b, x[i]);
    }
    for(int i = b; i < h; ++ i) {
        x.push_back(i);
        y.push_back(0);
        ++ m;
    }
    for(int i = a; i < w; ++ i) {
        x.push_back(0);
        y.push_back(i);
        ++ m;
    }
    vector<int> ids(m);
    iota(all(ids), 0);
    sort(all(ids), [&](int i, int j){
        return (y[i] != y[j] ? y[i] < y[j] : x[i] > x[j]);});
    BIT<int> bit(h);
    vector<int> co(w, 0);
    int prev = -1;
    rep(i, m) {
        int id = ids[i];
        if(bit.sum(x[id], x[id] + 1) == 0) bit.add(x[id], 1);
        if(co[y[id]] == 0) ans -= bit.sum(x[id], h);
        else ans -= bit.sum(x[id], prev);
        prev = x[id];
        ++ co[y[id]];
    }
    cout << ans << "\n";
}

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	//cout << fixed << setprecision(20);
	//int t; cin >> t; rep(i, t)solve();
	solve();
    return 0;
}


/* Bismillahirrahmanirrahim */
/* Author : Jehian Norman Saviero (@Reiva5) */
#include <bits/stdc++.h>

// MACROS SAMPAH
#define Jehian using
#define Norman namespace
#define Saviero std

Jehian Norman Saviero;

// MACROS TYPE
typedef long l;
typedef long long ll;
typedef unsigned long ul;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int,int> pi;
typedef pair<l,l> pl;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<l> vl;
typedef vector<ll> vll;

// MACROS FOR PRINT
#define nl printf("\n")

// MACROS FOR ATTRIBUTE
#define fi first
#define se second

// MACROS FOR FUNCTION AND METHOD
#define eb emplace_back
#define mp make_pair
#define pb push_back
#define pf push_front
#define ppb pop_back
#define ppf pop_front
#define ALL(x) (x).begin(), (x).end()
#define ALLN(x,n) (x), (x)+(n)
#define CUBE(x) (SQR(x)*(x))
#define SET(x,y) for (int _qwe = sizeof(x)/sizeof(x[0]); _qwe; ) x[--_qwe] = (y)
#define SQR(x) ((x)*(x))
#define SSORT(x,sz) sort(ALLN(x,sz))
#define RESET(x) memset((x), 0, sizeof(x))
#define VSORT(x) sort(ALL(x))

// MACROS READ INPUT
#define sci(x) scanf("%d", &x)
#define scl(x) scanf("%ld", &x)
#define scll(x) scanf("%lld", &x)
#define scd(x) scanf("%lf", &x)
#define scld(x) scanf("%Lf", &x)
#define scul(x) scl(x)
#define scull(x) scll(x)

int main() {
	int N, K, M;
	sci(N), sci(K), sci(M);
	ll sum = 0;
	for (int i = 0; i < N-1; ++i) {
		int curr;
		sci(curr);
		sum += curr;
	}
	ll tot = M * N;
	ll diff = tot - sum;
	if (0 <= diff && diff <= K) {
		printf("%lld\n", diff);
	} else if (diff < 0) {
		printf("0\n");
	} else {
		printf("-1\n");
	}
	return 0;
}

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

int main() {
  int n, k, m;
  cin >> n >> k >> m;
  int s = 0;
  int A;
  for(int i = 0; i < n - 1; i++){
    cin >> A;
    s += A;
  }
  int B = n*m - s;
  if(B > k){
    cout << -1;
  }
  else if(B < 0){
    cout << 0;
  }
  else{
    cout << B;
  }
}


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

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

ll C[100][100];

int main()
{
	int a=read(),b=read();
	int n=a+b;
	ll k=read();
	for(int i=0;i<=n;i++) C[i][i]=C[i][0]=1;
	for(int i=1;i<=n;i++)
		for(int j=i+1;j<=n;j++)
			C[j][i]=C[j-1][i-1]+C[j-1][i];
	for(int i=1;i<=n;i++)
	{
//		cout<<a<<" "<<b<<" "<<k<<endl;
		if(a==0)
		{
			for(int j=1;j<=b;j++) putchar('b');
			break;
		}
		if(b==0)
		{
			for(int j=1;j<=a;j++) putchar('a');
			break;
		}
		ll res=C[a+b-1][a-1];
//		cout<<res<<endl;
		if(k>res)
		{
			putchar('b');
			k-=res;
			b--;
		}
		else
		{
			putchar('a');
			a--;
		}
	}
	return 0;
}

/* dont stick to an approach */

#include <iostream>
#include <iomanip>
#include <cmath>
#include <string>
#include <algorithm>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <unordered_map>
#include <vector>
#include <numeric>
#include <cstdlib>
#include <bitset>

using namespace std;

typedef long long ll;
typedef unsigned long long int ull;
typedef long double ldb;

#define PB push_back

#define For(i, n) for (ll i = 0; i < n; i++)

#define trav(a,x) for (auto& a : x)

#define PYES cout<<"YES\n"
#define PNO cout<<"NO\n"
#define PYes cout<<"Yes\n"
#define PNo cout<<"No\n"
#define endl '\n'

#define sq(x)           (x*x)

#define vll             vector<ll>
#define pll             pair<ll,ll>
#define ff              first
#define ss              second
#define rev(v)          reverse(v.begin(),v.end())
#define srt(v)          sort(v.begin(),v.end())
#define grtsrt(v)       sort(v.begin(),v.end(),greater<ll>())
#define mnv(v)          *min_element(v.begin(),v.end())
#define mxv(v)          *max_element(v.begin(),v.end())
#define all(v)          v.begin(),v.end()
#define ACC(v)          accumulate(v.begin(),v.end(),0ll)

#define Fas ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)

//--------------------------------------------functions-------------------------------------------------//

ll power(ll a,ll b){ll result=1;while(b>0){if(b%2 == 1){result *= a;} a *= a;b /= 2;}return result;}
ll gcd(ll x,ll y){ll r;while(y!=0&&(r=x%y)!=0){x=y;y=r;}return y==0?x:y;}
ll countSetBits(ll x){ll Count=0;while(x>0){if(x&1) Count++;x=x>>1;}return Count;}
bool isPerfectSquare(ll n){ll sr = sqrt(n);if (sr * sr == n)return true;else return false;}
ll mod(ll x,ll M){return ((x%M + M)%M);}
ll add(ll a, ll b,ll M){return mod(mod(a,M)+mod(b,M),M);}
ll mul(ll a, ll b,ll M){return mod(mod(a,M)*mod(b,M),M);}
ll powerM(ll a,ll b,ll M){
    ll res=1ll;
    while(b){
        if(b%2ll==1ll){
            res=mul(a,res,M);
        }
        a=mul(a,a,M);b/=2ll;
    }
    return res;
}
//------------------------------------sieve of erantothenes-----------------------------------------------//
//ll MAXN=1e7+150;
//vector<ll> fact(MAXN+1);
//void sieve_of_erantothenes()
//{
//    fact[1] = 1;
//    for (ll i = 2; i <= MAXN; i++)
//        fact[i] = i;
//    for (ll i = 4; i <= MAXN; i += 2)
//        fact[i] = 2;
//    for (ll i = 3; i * i <= MAXN; i++){
//        if (fact[i] == i){
//            for (ll j = i * i; j <= MAXN; j += i)
//                if (fact[j] == j)
//                    fact[j] = i;
//        }
//    }
//}
//----------------------------------------nCr mod------------------------------------------------------//
ll nCr(ll n, ll k){
    if(n<k) return 0;
    if(k==0) return 1;
    ll res = 1;
    if (k > n - k) k = n - k;
    for(ll i = 0; i < k; ++i){
        res *= (n - i);
        res /= (i + 1);
    }
    return res;
}

ll modInverse(ll n,ll M){
    return powerM(n,M-2,M);
}
ll nCrM(ll n,ll r,ll M){
    if(n<r) return 0;
    if(r==0) return 1;
    vector<ll> fact(n+1);
    fact[0]=1;
    for(ll i=1;i<=n;i++){
        fact[i]=mul(fact[i-1],i,M);
    }
    return mul(mul(fact[n],modInverse(fact[r],M),M),modInverse(fact[n-r],M),M);
}
//-----------------------------------------------solve-----------------------------------------------------//

void solve(){
    ll a,b,k;cin>>a>>b>>k;
    vll v(a+b);
    for(ll i=b-1;i>=0;i--){
        ll curr=i;
        for(ll j=i;j<=i+a;j++){
            if(nCr(j,i)<k){
                k-=nCr(j,i);
                curr++;
            }else{
                break;
            }
        }
        v[curr]=1;
    }
    rev(v);
    for(ll i=0;i<a+b;i++){
        if(v[i]==1) cout<<'b';
        else cout<<'a';
    }
    cout<<endl;
}

int main(){
    Fas;

//    freopen("input.txt","r",stdin);
//    freopen("output.txt","w",stdout);

//    ll t=0;
//    cin>>t;
//    while(t--)

        solve();

    return 0;
}


    #include <bits/stdc++.h>
    using namespace std;
    #include <math.h>
    #include <iomanip>
    #include <cstdint>
    #include <string>
    #include <sstream>
    template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
    template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
    #define rep(i,n) for (int i = 0; i < (n); ++i)
    typedef long long ll;
    using P = pair<ll,ll>;
    const int INF=1001001001;
    const int mod=1e9+7;

    ll dp[100][100];
    int main() {
      int N;
      cin>>N;
      vector<string>s(N);
      rep(i,N){cin>>s[i];}
      dp[0][0]=1;
      dp[0][1]=1;
      rep(i,N){
        if(s[i]=="AND"){
          dp[i+1][1]+=dp[i][1];
          dp[i+1][0]+=dp[i][1]+2*dp[i][0];
        }
        else{
          dp[i+1][1]+=2*dp[i][1]+dp[i][0];
          dp[i+1][0]+=dp[i][0];
        }
      }
      cout<<dp[N][1]<<endl;
      return 0;
    }

#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2")
#include <bits/stdc++.h>
using namespace std;
// #include <ext/pb_ds/assoc_container.hpp>
// using namespace __gnu_pbds;
// template <class c, class cmp = less<c> > using ordered_set = tree<c, null_type, cmp, rb_tree_tag, tree_order_statistics_node_update>;
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif
template<class T> ostream& operator<<(ostream &os, vector<T> V) {os << "[ "; for(auto v : V) os << v << " "; return os << "]";}
template<class L, class R> ostream& operator<<(ostream &os, pair<L,R> P) {return os << "(" << P.first << "," << P.second << ")";}
template <typename T,typename U>pair<T,U> operator+(const pair<T,U> & l,const std::pair<T,U> & r) { return {l.first+r.first,l.second+r.second};}
typedef long long int ll;
const ll mod = 1e9 + 7;
const ll maxn = 2e5 + 5;
#define endl '\n'
#define ld long double
#define int ll
#define all(x)  (x).begin(),(x).end()

int32_t main(){

  IOS

	int n;
	cin >> n;
	vector<int> a(n), pref(n + 1, 0);
	vector<vector<int> > dp(n + 1, vector<int>(n + 1, 0)), sum(n + 2, vector<int>(n + 2, 0));

	for(int i = 0; i < n;i++) cin >> a[i], pref[i + 1] = pref[i] + a[i];

	dp[0][0] = 1;
	sum[1][0] = 1;
	for(int i = 1;i <= n;i++){
		for(int k = 1;k<=i;k++){
			int x = pref[i]%k;
			dp[i][k] += sum[k][x];
			dp[i][k]%=mod;
		}

		for(int k = 1;k<=n + 1;k++){
			sum[k][pref[i]%(k)] += dp[i][k - 1];
			sum[k][pref[i]%k]%=mod;
		}
	}

	int ans = 0 ;
	for(int i = 1;i<=n;i++){
		ans += dp[n][i];
		ans%=mod;
	}

	cout << ans << endl;

}


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

void printmat(const vector<vector<long long>>& mat) {
    for (auto row : mat) {
        for (int elem : row)
            cout << elem << ", ";
        cout << endl;
    }
}
void printv(const vector<int>& v) {
    for (int elem : v)
        cout << elem << " ";
    cout << endl;
}
void printvp(const vector<pair<int, int>>& vp) {
    for (auto row : vp)
        cout << row.first << ", " << row.second << " ; ";
    cout << endl;
}

int main() {
    int T=1, caseIdx=0;
    //cin >> T;
    while (T--) {
        caseIdx++;
        int n;
        long long ans=0, second=0;
        cin >> n;
        vector<long long> a(n), s(n+1);
        for (int i=0; i<n; i++) {
            cin >> a[i];
            s[i+1] = s[i] + a[i];
            ans += (a[i]*a[i]);
        }
        ans *= (n-1LL);
        for (int i=0; i<n-1; i++) {
            second += (a[i] * (s[n]-s[i+1]));
            //cout << (s[n]-s[i+1]) << endl;
        }
        ans = ans - 2LL*second;

        cout << ans << endl;
        //cout << "Case #" << caseIdx << ": " << ans << endl;
    }
}

#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define srep(i,s,t) for(int i = s; i < t; ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
#define yn {puts("Yes");}else{puts("No");}
#define MAX_N 200005

int n;
vector<int> G[MAX_N];
int par[MAX_N];
int visit_[MAX_N];

priority_queue<int> que1[MAX_N], que2[MAX_N];

int dfs(int x){
    int res = 0;
    if(visit_[x] == 0){
        res++;
        visit_[x] = 1;
        res -= dfs(x);
        return res;
    }
    if(visit_[x] == 1){
        rep(i,G[x].size()){
            int tmp = -dfs(G[x][i]);
            if(tmp % 2 == 0) que2[x].push(tmp);
            else que1[x].push(tmp);
        }
        visit_[x] = 2;
    }
    while(!que2[x].empty() && que2[x].top()>=0){
        res += que2[x].top();
        que2[x].pop();
    }
    if(!que1[x].empty()){
        res += que1[x].top();
        que1[x].pop();
        res -= dfs(x);
    }
    while(!que2[x].empty()){
        res += que2[x].top();
        que2[x].pop();
    }
    return res;
}

int main() {
    par[0] = -1;
    cin >> n;
    srep(i,1,n){
        cin >> par[i];
        par[i]--;
        G[par[i]].push_back(i);
    }

    int tmp = dfs(0);
    int ans = (n-tmp) / 2 + tmp;
    cout << ans << endl;
    return 0;
}


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

using namespace std;

int main() {

	int A, B;

	cin >> A >> B;

	int* E;
	E = (int*)malloc((A + B) * sizeof(int));

	int sum = 0;
	int j = 1;
	if (A > B) {
		for (int i = 0; i < A; i++) {
			E[i] = i + 1;
			sum += E[i];
		}

		for (int i = A; i < A + B - 1; i++) {
			E[i] = -j;
			j++;
			sum += E[i];
		}
		E[A + B - 1] = -sum;

	}
	else {
		for (int i = 0; i < B; i++) {
			E[i] = -(i + 1);
			sum += E[i];
		}

		for (int i = B; i < A + B - 1; i++) {
			E[i] = j;
			j++;
			sum += E[i];
		}
		E[A + B - 1] = -sum;
	}

	for (int i = 0; i < A + B; i++) cout << E[i] << " ";

	free(E);

	return 0;
}

#include <bits/stdc++.h>

#include <cstdint>
using namespace std;

#define endl "\n"
#define pb push_back
#define fo(i, start, end) for (ll i = start; i < end; i++)
#define rep(i, start, end, step) for (ll i = start; i < end; i += step)
#define print(x) cout << #x << " is " << x << endl
#define all(arg) arg.begin(), arg.end()
#define sz(arg) (int)arg.size()

using ll = long long;
using vi = vector<int>;
using vll = vector<long long>;

void solve() {
    int a, b;
    cin >> a >> b;
    int ans;
    if (a + b >= 15 && b >= 8)
        ans = 1;
    else if (a + b >= 10 && b >= 3)
        ans = 2;
    else if (a + b >= 3)
        ans = 3;
    else
        ans = 4;
    cout << ans << endl;
}

int main() {
#ifndef DEBUG
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
#endif
    solve();
    return 0;
}


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

int main() {
  int n; cin>>n;
  ll C; cin>>C;
  vector<P> e;
  rep(i,n) {
    ll a,b,c; cin>>a>>b>>c;
    e.emplace_back(a-1,c);
    e.emplace_back(b,-c);
  }
  sort(e.begin(),e.end());
  ll ans=0,cost=0,now=0;
  for(auto [x,y]:e) {
    if(x!=now) {
      ans+=min(C,cost)*(x-now);
      now=x;
    }
    cost+=y;
  }
  cout<<ans;
}

#include <bits/stdc++.h>
using namespace std;
#define mp(a, b) make_pair(a, b)
typedef pair<int, int> pii;
typedef long long ll;
const int maxn = 2e5 + 10;
int a[maxn], b[maxn], c[maxn], d[maxn];
ll ans;
int n, l;
int main()
{
	scanf("%d%d", &n, &l);
	for(int i = 1; i <= n; ++i) scanf("%d", &a[i]);
	for(int i = 1; i <= n; ++i) scanf("%d", &b[i]);
	c[1] = a[1] - 1;
	for(int i = 2; i <= n; ++i) c[i] = a[i] - a[i - 1] - 1;
	c[n + 1] = l - a[n];
	d[1] = b[1] - 1;
	for(int i = 2; i <= n; ++i) d[i] = b[i] - b[i - 1] - 1;
	d[n + 1] = l - b[n];
	/*for(int i = 1; i <= n + 1; ++i) cout << c[i] << ' '; cout << endl;
	for(int i = 1; i <= n + 1; ++i) cout << d[i] << ' '; cout << endl; */
	int l = 1;
	for(int i = 1; i <= n + 1; ++i)
		if(d[i])
		{
			while(l <= n + 1 && !c[l]) ++l;
			int r = l;
			while(r <= n + 1 && d[i] > 0)
			{
				d[i] -= c[r];
				++r;
			}
			if(d[i] < 0)
			{
				puts("-1");
				return 0;
			}
			//cout << l << ' ' << r - 1 << endl;
			if(i < l) ans += r - 1 - i;
			else if(i >= r) ans += i - l;
			else ans += r - l - 1;
			l = r;
		}
	printf("%lld\n", ans);
	return 0;
}


#include <cstdio>

using namespace std;

int main() {
    int i, j;
    long long n, x = 3, y;

    scanf("%lld", &n);

    for (i = 1; x <= n; i++, x *= 3) {
        y = 5;

        for (j = 1; x + y <= n; j++, y *= 5) {
            if (x + y == n) {
                printf("%d %d\n", i, j);

                return 0;
            }
        }
    }

    puts("-1");

    return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define all(a) a.begin(), a.end()
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<ll,int> pli;
typedef pair<int,int> pii;
#define rep(i,a,b) for(ll i=a ; i<b ; i++)
#define qrep(que, ite) for(auto ite=begin(que) ; ite!=end(que) ; ite++)
const int max_n = 1e5;
const ll mod = 1e9+7;
const ll INF = 1e17;
const int inf = 1e5;
typedef long double ld;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
ll gcd(ll a, ll b) { return a ? gcd(b%a, a) : b; }
int dx[4] = {0,0,1,-1};
int dy[4] = {1,-1,0,0};
ll mo = 998244353;
struct UnionFind {
    vector<int> par;

    UnionFind(int n) : par(n, -1) { }
    void init(int n) { par.assign(n, -1); }

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

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

    bool merge(int x, int y) {
        x = root(x); y = root(y);
        if (x == y) return false;
        if (par[x] > par[y]) swap(x, y); // merge technique
        par[x] += par[y];
        par[y] = x;
        return true;
    }

    int size(int x) {
        return -par[root(x)];
    }
};
struct SegmentTree{
  int N;
  vector<int> node;
  public :
    void intit(vector<int>v){
      int sz = v.size();
      N=1;
      while(N<sz) N*=2;
      node.resize(N);
      for(int i=0 ; i<sz ; i++) node[i+N-1] = v[i];
      for(int i=N-2 ; i>=0 ; i--) node[i] = min(node[i*2+1], node[i*2+2]);
    }
    void update(int x, int val){
      x += N-1;
      node[x+N-1] = val;
      while(x>0){
        x = (x-1)/2;
        node[x] = min(node[x*2+1], node[x*2+2]);
      }
    }
    int getmin(int a, int b, int k, int l, int r){
      if(b<=l || r<=a) return inf;
      else if(a<=l && r<=b) return node[k];
      else{
        int vl = getmin(a, b, 2*k+1, l, (l+r)/2);
        int vr = getmin(a, b, 2*k+2, (l+r)/2, r);
        return min(vl, vr);
      }
    }
};
vector<ll> divisor(ll n){
  vector<ll> res;
  for(ll i=1; i*i<=n ; i++){
    while(n%i==0){
      ++res[i];
      n /= i;
    }
  }
  if(n!=1) res[n]=1;
  return res;
}

int main(){
  ll N; cin>>N;
  ll now = 1;
  ll jj = 1;
  rep(i,1,1000000){
    now *= 3;
    if(N-now<=0) break;
    if((N-now)%5==0){
      ll k = N-now;
      ll cnt = 0;
      int ok=1;
      while(k>1){
        cnt++;
        if(k%5!=0){
          ok=0;
          break;
        }
        k/=5;
      }
      if(!ok) continue;
      if(cnt==0)continue;
      cout<<i<<" "<<cnt<<endl;
      return 0;
    }
  }
  cout<<-1<<endl;
  return 0;
}


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

void fun()
{
    ll a[3];
    cin>>a[0]>>a[1]>>a[2];
    sort(a,a+3);
    cout<<a[2]+a[1];
}

int main() {
     ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	ll t=1;
// 	cin>>t;
	while(t--)
	fun();
	return 0;
}

#include<bits/stdc++.h>
using namespace std;
long long x,y,a,b,ans;
int main(){
	cin>>x>>y>>a>>b;
	bool flag=0;
	while(x<y/a&&x<(x+b)/a){
		x*=a;
		ans++;
	}
	ans+=(y-x-1)/b;
	printf("%lld\n",ans);
}


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

int main(){
  int64_t n,m,x,y;
  cin>>n>>m>>x>>y;
  x--,y--;
  vector<vector<vector<int64_t>>>trn(n);
  for(int64_t i=0,a,b,c,d;i<m;i++){
    cin>>a>>b>>c>>d;
    a--,b--;
    trn[a].push_back(vector<int64_t>{b,c,d});
    trn[b].push_back(vector<int64_t>{a,c,d});
  }
  priority_queue<pair<int64_t,int64_t>,vector<pair<int64_t,int64_t>>,greater<pair<int64_t,int64_t>>>dijk;
  vector<int64_t>dist(n,9e18);
  dist[x]=0;
  dijk.push({(int64_t)0,x});
  while(!dijk.empty()){
    auto i=dijk.top();
    dijk.pop();
    if(i.first>dist[i.second])continue;
    for(auto j:trn[i.second]){
      int64_t e=j[2];
      int64_t d=((dist[i.second]+e-1)/e+0)*e+j[1];
      if(dist[j[0]]>d){
        dist[j[0]]=d;
        dijk.push({d,j[0]});
      }
    }
  }
  cout<<(dist[y]==9e18?(int64_t)-1:dist[y])<<'\n';
}

#include <bits/stdc++.h>
#define REP(i,n) for (int i = 0; i <(n); ++i)
#define REP2(i,x,n) for (int i = x; i <(n); ++i)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
using namespace std;
using ll = long long;
using P = pair<int,int>;
static const double PI = acos(-1);
static const int INF = 1e9+7;
//debug
#ifdef _DEBUG
#define debug(var)  do{cout << #var << " :";view(var);}while(0)
#else
#define debug(...)
#endif
template<typename T> void view(T e){cout << e << endl;}
template<typename T> void view(const vector<T>& v){for(const auto& e : v){ cout << e << " "; } cout << endl;}
template<typename T> void view(const vector<vector<T> >& vv){ for(const auto& v : vv){ view(v); } }

int solve(){
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  int x = c - a;
  int y = d - b;
  //0
  if(x == 0 && y == 0) return 0;
  //1
  if( x - y == 0 || x + y == 0) return 1;
  if(abs(x)+abs(y) <= 3) return 1;
  //2
  //斜め移動 2
  if((x+y)%2 == 0) return 2;
  //斜め１，縦横1
  for(int i =  -3; i <= 3; i++){
    for(int j = -3; j <= 3; j++){
      if(abs(i)+abs(j) > 3) continue;
      if((x+i) - (y+j) == 0 || (x+i) + (y+j) == 0 ) return 2;
    }
  }
  //縦横2
  if(abs(x)+abs(y) <= 3*2) return 2;
  //3: 0,1,2以外なら3手
  return 3;
}

int main(){
  cout << solve() << endl;
  return 0;
}


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

const ll MOD = 1e9 + 7;

int mpow(int base, int exp);
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#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 deb(x) cout << #x << " = " << x << endl
#define deb2(x, y) cout << #x << " = " << x << ", " << #y << " = " << y << endl
#define deb3(x, y, z) cout << #x << " = " << x << ", " << #y << " = " << y << ", "<< #z << " = " << z << endl

ll randGen(ll lower, ll upper) { return (rand() % (upper - lower + 1)) + lower; }
ll dir[4][2] = {{1, 0}, {0, 1}, {-1, 0}, {0, -1}};
// cout << fixed;
// cout.precision(10);
//******************          Function here          *********************//

   void test_case(){
	int n, a, b;
     cin >> n >> a >> b;
     cout << n - a + b << endl;
   }

//*********************************************************************//

int main()
{
    #ifndef ONLINE_JUDGE
      string inputFile, outputFile;
      inputFile = "input.txt";
      outputFile = "output.txt";
      freopen(inputFile.c_str(), "r", stdin);
      freopen(outputFile.c_str(), "w", stdout);
    #endif
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t = 1;
    // cin >> t;
    while(t-- > 0){
      test_case();
    }
    return 0;
}

/**********************   Utility Functions  *****************************/
   int mpow(int base, int exp) {
     base %= MOD;
     int result = 1;
     while (exp > 0) {
       if (exp & 1) result = ((ll)result * base) % MOD;
       base = ((ll)base * base) % MOD;
       exp >>= 1;
     }
     return result;
   }
/***********************************************************************/

#include <bits/stdc++.h>
#define pb(x) push_back(x)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define F(w,x,y) for(ll w=x; w<y; w++)
#define endl "\n"
#define mod 1000000007
#define INF 1000000000
typedef long long ll;
typedef long double ld;
using namespace std;

void play()
{
    ll n,m;
    cin>>n>>m;
    string s;
    ll arr[2]={0,0};
    F(i,0,n)
    {
        cin>>s;
        ll sum=0;
        F(j,0,m)
        {
            sum+=s[j]-'0';
        }
        arr[sum%2]++;
    }
    cout<<arr[0]*arr[1]<<endl;
}

int main()
{
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll t;
    t=1;
    //cin>>t;
    F(i,1,t+1)
    {
        //cout<<"Case #"<<i<<": ";
        play();
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
string to_string(string s) { return '"' + s + '"'; }
string to_string(const char* s) { return to_string(string(s)); }
string to_string(bool b) { return to_string(int(b)); }
string to_string(vector<bool>::reference b) { return to_string(int(b)); }
string to_string(char b) { return "'" + string(1, b) + "'"; }
template <typename A, typename B>
string to_string(pair<A, B> p) { return "(" + to_string(p.first) + ", " + to_string(p.second) + ")"; }
template <typename A>
string to_string(A v) {
	string res = "{";
	for (const auto& x : v) res += (res == "{" ? "" : ", ") + to_string(x);
	return res + "}";
}
void debug() { cerr << endl; }
template <typename Head, typename... Tail>
void debug(Head H, Tail... T) {
	cerr << " " << to_string(H);
	debug(T...);
}
#define db(...) cerr << "[" << #__VA_ARGS__ << "]:", debug(__VA_ARGS__)
#else
#define db(...) 42
#endif
typedef long long ll;
typedef long double ld;
const int MOD = 1000000007;
struct Mint {
	int val;
	Mint() { val = 0; }
	Mint(const ll& x) {
		val = (-MOD <= x && x < MOD) ? x : x % MOD;
		if (val < 0) val += MOD;
	}
	template <typename U>
	explicit operator U() const { return (U)val; }
	friend bool operator==(const Mint& a, const Mint& b) { return a.val == b.val; }
	friend bool operator!=(const Mint& a, const Mint& b) { return !(a == b); }
	friend bool operator<(const Mint& a, const Mint& b) { return a.val < b.val; }
	Mint& operator+=(const Mint& m) { if ((val += m.val) >= MOD) val -= MOD; return *this; }
	Mint& operator-=(const Mint& m) { if ((val -= m.val) < 0) val += MOD; return *this; }
	Mint& operator*=(const Mint& m) { val = (ll)val * m.val % MOD; return *this; }
	friend Mint modex(Mint a, ll p) {
		assert(p >= 0);
		Mint ans = 1;
		for (; p; p >>= 1, a *= a) if (p & 1) ans *= a;
		return ans;
	}
	Mint& operator/=(const Mint& m) { return *this *= modex(m, MOD - 2); }
	Mint& operator++() { return *this += 1; }
	Mint& operator--() { return *this -= 1; }
	Mint operator++(int) { Mint result(*this); *this += 1; return result; }
	Mint operator--(int) { Mint result(*this); *this -= 1; return result; }
	Mint operator-() const { return Mint(-val); }
	friend Mint operator+(Mint a, const Mint& b) { return a += b; }
	friend Mint operator-(Mint a, const Mint& b) { return a -= b; }
	friend Mint operator*(Mint a, const Mint& b) { return a *= b; }
	friend Mint operator/(Mint a, const Mint& b) { return a /= b; }
	friend ostream& operator<<(ostream& os, const Mint& x) { return os << x.val; }
	friend string to_string(const Mint& b) { return to_string(b.val); }
};
int main() {
	int n;
	scanf("%d", &n);
	vector<string> C(2, string(2, '_'));
	for (int i = 0; i < 2; ++i)
		for (int j = 0; j < 2; ++j)
			scanf(" %c", &C[i][j]);
	if (C[0][1] == 'B') {
		auto D = C;
		int sum = (int)'A' + 'B';
		D[0][0] = sum - C[1][1];
		D[1][1] = sum - C[0][0];
		D[0][1] = sum - C[0][1];
		D[1][0] = sum - C[1][0];
		swap(D, C);
	}
	assert(C[0][1] == 'A');
	Mint ans = 0;
	if (n == 2) ans = 1;
	else if (C[0][0] == 'A') ans = 1;
	else if (C[1][0] == 'B') ans = modex(Mint(2), n - 3);
	else {
		Mint a = 1, b = 0;
		for (int i = 1; i + 1 < n; ++i) {
			Mint na = a + b;
			Mint nb = a;
			swap(na, a);
			swap(nb, b);
		}
		ans += a;
	}
	printf("%d\n", ans.val);
}


#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long
int main(){
  ll n;
  cin >> n;
  ll bit=1;
  rep(i,n){
    bit*=2;
  }
  vector<ll> a(bit),c(bit);
  rep(i,bit){
    cin >> a.at(i);
  }
  c=a;
  ll ans=0;
  for(int i=0;i<n;i++){
    vector<ll> b;
    for(ll j=0;j<bit;j+=2){
      ll p=max(a.at(j),a.at(j+1));
      b.push_back(p);
      if(i==n-1){
        ans=min(a.at(j),a.at(j+1));
      }
    }
    bit/=2;
    a=b;
  }
  ll ct=1;
  for(auto q: c){
    if(q==ans){
      cout << ct;
    }
    ct++;
  }
}

#ifdef _DEBUG
#include "../../../library/src/debug_template.cpp"
#define DMP(...) dump(#__VA_ARGS__, __VA_ARGS__)
#else
#define DMP(...) ((void)0)
#endif

#include <cassert>
#include <cstdio>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <queue>
#include <numeric>
#include <algorithm>
#include <bitset>
#include <functional>

using namespace std;
using lint = long long;
constexpr int MOD = 1000000007, INF = 1010101010;
constexpr lint LINF = 1LL << 60;

struct init {
    init() {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(10);
    }
} init_;

int main() {

    int N;
    cin >> N;
    N = 1 << N;

    vector<int> A(N);
    for (int i = 0; i < N; i++) cin >> A[i];

    auto l = max_element(A.begin(), A.begin() + N / 2);
    auto r = max_element(A.begin() + N / 2, A.end());

    cout << (*l < *r ? l : r) - A.begin() + 1 << '\n';

    return 0;
}


#include <numeric>
#include <bits/stdc++.h>
#include <utility>
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <math.h>
#include <string>
#define ll long long
#define ull unsigned long long
#define make(type,x) type x; cin>>x
#define make2(type,x,y) type x,y; cin>>x>>y
#define fr(x,y) for(long long x=0;x<y;x++)
#define makevec(x,y,n) vector <x> y(n); for(ll i=0;i<n;i++) cin>>y[i]
#define M (ll)1000000007
#define MM (ll) 1e8
#define INF (ll) 1e18

# define IOS ios_base::sync_with_stdio(false); cin.tie(NULL)

using namespace std;

template <typename T>
T modpow(T base, T exp, T modulus) {
  base %= modulus;
  T result = 1;
  while (exp > 0) {
    if (exp & 1) result = (result * base) % modulus;
    base = (base * base) % modulus;
    exp >>= 1;
  }
  return result;
}
bool sortbysec(const ll &a, const ll &b){
    return abs(a)>abs(b);
}

struct cmp {
	bool operator() (const pair<int, int> &a, const pair<int, int> &b) const {
		int lena = a.second - a.first + 1;
		int lenb = b.second - b.first + 1;
		if (lena == lenb) return a.first < b.first;
		return lena > lenb;
	}
};

struct c_h {
    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        x ^= FIXED_RANDOM;
        return x ^ (x >> 16);
    }
};

ll calcpow(ll x, ll y)
{
    ll temp;
    if(y == 0)
        return 1;
    temp = calcpow(x, y / 2);
    if (y % 2 == 0)
        return temp * temp;
    else
    {
        if(y > 0)
            return x * temp * temp;
        else
            return (temp * temp) / x;
    }
}
ll gcd(ll a, ll b){
    if(b==0) return a;
    return gcd(b,a%b);

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

bool isprime(ll a){
bool flag=1;
for(ll i=2;i*i<=a;i++){
    if(a%i==0) {flag=0; break;}
}
return flag;
}

ll dx8[8]={1,0,-1,0,1,-1,1,-1};
ll dy8[8]={0,1,0,-1,1,-1,-1,1};
ll dx4[4]={0,0,1,-1};
ll dy4[4]={1,-1,0,0};
const ll N=100;
double dp[N][N][N];
double solve(ll a, ll b, ll c){
    if(a==100 || b==100 || c==100) return 0;
    if(dp[a][b][c]!=-1) return dp[a][b][c];
    dp[a][b][c]=1+(1.0*a/(a+b+c))*solve(a+1,b,c) + (1.0*b/(a+b+c))*solve(a,b+1,c) + (1.0*c/(a+b+c))*solve(a,b,c+1);
    return dp[a][b][c];
}

int main(){
    IOS;
    fr(i,100) fr(j,100) fr(k,100) dp[i][j][k]=-1;
    make2(ll,a,b); make(ll,c);
    cout<<setprecision(10)<<solve(a,b,c)<<endl;

    return 0;
}

#include <bits/stdc++.h>
#define int long long
#define double long double
#define x first
#define y second
#define pb push_back
#define rt return
using namespace std;
double dp[110][110][110];
double solve(int a,int b,int c){
	if (a==100||b==100||c==100) return dp[a][b][c]=0.0;
	if (dp[a][b][c]!=-1.0) return dp[a][b][c];
	double m1=solve(a+1,b,c)+1.0,m2=solve(a,b+1,c)+1.0,m3=solve(a,b,c+1)+1.0;
	double s=0.0+a+b+c;
	return dp[a][b][c]=m1*a/s+m2*b/s+m3*c/s;
}
signed main(){
	for (int i=0; i<110; i++){
		for (int j=0; j<110; j++){
			for (int k=0; k<110; k++) dp[i][j][k]=-1.0;
		}
	}
	int a,b,c;
	cin>>a>>b>>c;
	cout<<fixed<<setprecision(8)<<solve(a,b,c);
}


/*

  AUTHOR:    nit1n
  CREATED:   21.03.2021 21:41:12

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

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

	int n ;
	cin >> n ;
	int l = 0 , h = 1e6 +10 ;
	while(l<h){
		int mid = (l+h)/2 ;
		string s = to_string(mid) + to_string(mid) ;
		int m = stoll(s) ;
		if( m >=n){
  			h = mid ;
		}else{
			l = mid + 1;
		}
	}
	string s = to_string(h) + to_string(h) ;
	int m = stoll(s) ;
	if(m > n){
		h-- ;
	}
	cout << h ;
}

#include<bits/stdc++.h>
#define int long long
#define rint regester int
const int maxn = 1e6 + 10;
const int INF = 1e9;
using std::ios;
using std::cin;
using std::cout;
using std::max;
using std::min;
using std::sort;
using std::unique;
using std::lower_bound;
using std::swap;
using std::abs;
using std::acos;
using std::queue;
using std::map;
using std::string;
int read(){int x = 0,f = 1; char ch = getchar(); while(ch < '0' || ch > '9'){if(ch == '-')f = -1; ch = getchar();}while(ch >= '0' && ch <= '9'){x = (x << 1) + (x << 3) + (ch ^ 48); ch = getchar();} return x * f;}
int n, a[maxn], q, k;//find i -->> a_i < k + i < a_{i+1}
signed main(){
	n = read(), q = read();
	for(int i = 1; i <= n; i++)a[i] = read();
	while(q--){
		k = read();
		int l = 0, r = n, mid, ans = 0;
		while(l <= r){
			mid = (l + r) >> 1;
			if(k + mid <= a[mid]){
				r = mid - 1;
			}else
			if(k + mid >= a[mid + 1]){
				l = mid + 1;
			}else
			{ans = mid; break;}
		}
		cout << mid + k << "\n";
	}
}


#include<bits/stdc++.h>
#define FAST ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
using namespace std;
#define int long long
//typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;

signed main() {
    FAST
    int n,q;
    cin>>n>>q;
    vi v(n+1);
    for (int i = 1; i <= n; ++i) cin>>v[i];
    while (q--) {
        int k; cin>>k;

        int lo = 1, hi = n, mid,ans=-1;
        while (lo <= hi) {
            mid = lo + (hi - lo) / 2;
            int x=v[mid]-mid;
            if(x<k) lo=mid+1;
            else {
                int y = v[mid - 1] - (mid - 1);
                int tmp = k - y;
                int z = v[mid] - v[mid - 1] - 1;
                if (tmp>=1 and tmp <= z) {
                    ans=v[mid-1]+tmp;
                    break;
                }
                hi=mid-1;
            }
        }
        if(~ans) cout<<ans<<endl;
        else {
            int yy=v[n]-n;
            k-=yy;
            cout<<v[n]+k<<endl;
        }
    }
}

#include <bits/stdc++.h>

using namespace std;

#define REP(i, n)   for(int i = 0; i < (n); i++)
#define REPS(i, n)  for(int i = 1; i <= (n); i++)
#define RREP(i, n)  for(int i = (n)-1; i >= 0; i--)
#define RREPS(i, n) for(int i = (n); i > 0; i--)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl

using ll  = long long;
using pi  = pair<int, int>;
using pl  = pair<ll, ll>;
using vi  = vector<int>;
using vl  = vector<ll>;
using vs  = vector<string>;
using vb  = vector<bool>;
using vvi = vector<vi>;
using vvl = vector<vl>;

const int MOD = 1e9 + 7;
//const int MOD = 998244353;
const ll INF = 1e9 + 7;
const ll  INFL = 1e18;
const double PI = 3.14159265359;

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

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

    ll N, Q; cin >> N >> Q;
    vl A(N); REP(i, N) cin >> A[i];
    vl K(Q); REP(i, Q) cin >> K[i];

    sort(ALL(A));
    vl s;
    vl t;
    t.pb(0);
    if(A[0] != 1)
    {
        s.pb(1);
        t.pb(A[0]-1);
    }
    REP(i, N-1)
    {
        if(A[i]+1 != A[i+1]) s.pb(A[i]+1), t.pb(A[i+1]-A[i]-1);
    }
    s.pb(A[N-1]+1);
    t.pb((ll)2e18);

    REP(i, (int)t.size()-1) t[i+1] += t[i];

    REP(i, Q)
    {
        int idx = lower_bound(ALL(t), K[i]) - t.begin() -1;
        cout << s[idx]+K[i]-1-t[idx] << endl;
    }
}


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

int main()
{
	int n, m; cin >> n >> m;
	vector<int> H(n), L((n+1)/2), R((n+1)/2);
	for (int i = 0; i < n; ++i)
		cin >> H[i];
	sort(H.begin(), H.end());
	for (int i = 0; i+1 < n; i+=2)
		L[i/2+1] = L[i/2] + H[i+1] - H[i];
	for (int i = n-2; i >= 0; i-=2)
		R[i/2] = R[i/2+1] + H[i+1] - H[i];
	int ans = INT_MAX;
	for (int i = 0; i < m; ++i)
	{
		int w; cin >> w;
		auto it = lower_bound(H.begin(), H.end(), w) - H.begin();
		if (it & 1) it ^= 1;
		ans = min(ans, L[it/2] + R[it/2] + abs(w - H[it]));
	}
	cout << ans << endl;
}

//#include <tourist>
#include <bits/stdc++.h>
//#include <atcoder/all>
using namespace std;
//using namespace atcoder;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<ll, ll> p;
const int INF = 1e9;
const ll LINF = ll(1e18);
const int MOD = 1000000007;
const int dx[4] = {0, 1, 0, -1}, dy[4] = {-1, 0, 1, 0};
const int Dx[8] = {0, 1, 1, 1, 0, -1, -1, -1}, Dy[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl
#define rep(i, n) for (int i = 0; i < n; i++)
#define ALL(v) v.begin(), v.end()
#define debug(v)          \
    cout << #v << ":";    \
    for (auto x : v)      \
    {                     \
        cout << x << ' '; \
    }                     \
    cout << endl;
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;
}
//cout<<fixed<<setprecision(15);有効数字15桁
//-std=c++14
//g++ yarudake.cpp -std=c++17 -I .
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n, m;
    cin >> n >> m;
    vector<ll> a(n), b(m);
    rep(i, n) cin >> a[i];
    rep(i, m) cin >> b[i];
    sort(ALL(a));
    sort(ALL(b));
    vector<ll> odd(n), even(n);
    ll sumo = 0;
    ll sume = 0;
    rep(i, n)
    {
        if (i % 2)
        {
            sumo += a[i];
        }
        else
        {
            sume += a[i];
        }
        odd[i] = sumo;
        even[i] = sume;
    }
    //debug(odd);
    //debug(even);
    ll ans = LINF;
    rep(i, n)
    {
        ll sum = 0;
        int x = upper_bound(ALL(b), a[i])-b.begin();
        if (x == 0)
        {
            sum += abs(b[x] - a[i]);
        }
        else if (x == b.size())
        {
            sum += abs(b[x - 1] - a[i]);
        }
        else
        {
            sum += min(abs(b[x] - a[i]), abs(b[x - 1] - a[i]));
        }
        ll plus = 0;
        ll minus = 0;
        if (i % 2)
        {
            minus += even[i - 1];
            minus += odd[n - 1] - odd[i];
            if (i >= 2)
                ;
            plus += odd[i - 2];
            plus += even[n - 1] - even[i - 1];
        }
        else
        {
            if (i >= 2)
                minus += even[i - 2];
            if (i >= 1)
                minus += odd[n - 1] - odd[i - 1];
            else
            {
                minus += odd[n - 1];
            }
            if (i >= 1)
                plus += odd[i - 1];
            plus += even[n - 1] - even[i];
        }
        sum += plus - minus;
        chmin(ans, sum);
    }
    cout << ans << "\n";
}


#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define ll long long
#define x1 first
#define y1 second
#define frb(i,a,b) for(ll (i)=(a);(i) <= (b); (i)+=(i)&-(i))
#define rfrb(i,a) for(ll (i)=(a);(i) > 0;(i)-=(i)&-(i))
#define fr(i,a,b) for(ll (i) = (a); (i) <= (b); (i)++)
#define rep(i,c) for(auto (i) : (c))
#define mini(a,b) ((a) < (b)) ? (a) : (b)
#define maxi(a,b) ((a) > (b)) ? (a) : (b)
#define par pair<ll,ll>
#define vp vector<par>
#define vi vector<ll>

const ll mod = 1e9+7;
ll n;
vi g;
map<ll,ll>ar;

int main() {
    ios_base::sync_with_stdio(0);cin.tie(0);
    cout.setf(ios::fixed);cout.precision(0);
    cin>>n;
    ll a;
    g.push_back(0);
    fr(i,1,n){
        cin>>a;
        ar[a]++;
        if(ar[a]==1)g.push_back(a);
    }
    sort(g.begin(),g.end());
    ll id = 0,sol=1;
    rep(v,g){
        sol = ((v-id+1)*(sol))%mod;
        sol%=mod;
        id = v;
    }
    cout<<sol;
    return 0;
}

/*
    Washief Hossain Mugdho
    12 April 2021
    AtCoder ARC_116 arc116_c
*/

#ifndef DEBUG
#pragma GCC optimize("O2")
#endif

#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define fr first
#define sc second
#define fastio ios_base::sync_with_stdio(0)
#define untie cin.tie(0)
#define rep(i, n) for (int i = 0; i < n; i++)
#define repe(i, n) for (int i = 1; i <= n; i++)
#define rrep(i, n) for (int i = n - 1; i >= 0; i--)
#define rrepe(i, n) for (int i = n; i > 0; i--)
#define ms(a, b) memset(a, b, sizeof a)
#define MOD 998244353
#define MAX 200005

typedef long long ll;
typedef unsigned long long ull;

using namespace std;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vb = vector<bool>;
using vi = vector<int>;
using vl = vector<ll>;
using vvb = vector<vector<bool>>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;
using vpii = vector<pair<int, int>>;
using mii = map<int, int>;
using umii = unordered_map<int, int>;
using seti = set<int>;
using useti = unordered_set<int>;

/***********IO Utility**************/
template <typename... ArgTypes>
void print(ArgTypes... args);
template <typename... ArgTypes>
void input(ArgTypes &...args);
template <>
void print() {}
template <>
void input() {}
template <typename T, typename... ArgTypes>
void print(T t, ArgTypes... args)
{
    cout << t;
    print(args...);
}
template <typename T, typename... ArgTypes>
void input(T &t, ArgTypes &...args)
{
    cin >> t;
    input(args...);
}

int modPow(int a, int b)
{
    int res = 1;
    while (b)
    {
        if (b & 1)
            res = 1LL * res * a % MOD;
        a = 1LL * a * a % MOD;
        b >>= 1;
    }
    return res;
}

int main()
{
    fastio;
#ifdef LOCAL_OUTPUT
    freopen(LOCAL_OUTPUT, "w", stdout);
#endif
#ifdef LOCAL_INPUT
    freopen(LOCAL_INPUT, "r", stdin);
#endif
    int n, m;
    cin >> n >> m;
    vi fact(n + 20), inv(n + 20);
    fact[0] = 1;
    repe(i, n + 19) fact[i] = 1LL * fact[i - 1] * i % MOD;
    inv[n + 19] = modPow(fact[n + 19], MOD - 2);
    rrep(i, n + 19) inv[i] = 1LL * inv[i + 1] * (i + 1) % MOD;
    vi spf(m + 1);
    repe(i, m)
        spf[i] = (i % 2 ? i : 2);

    for (int i = 3; i * i <= m; i += 2)
    {
        if (spf[i] != i)
            continue;
        for (int j = i * i; j <= m; j += (i << 1))
            spf[j] = min(spf[j], i);
    }
    int res = 0;
    repe(i, m)
    {
        umii facPow;
        int now = i;
        int ways = 1;
        while (now != 1)
        {
            facPow[spf[now]]++;
            now /= spf[now];
        }
        for (auto x : facPow)
        {
            ways = 1LL * ways * fact[n - 1 + x.sc] % MOD;
            ways = 1LL * ways * inv[n - 1] % MOD;
            ways = 1LL * ways * inv[x.sc] % MOD;
        }
        res = (res + ways) % MOD;
    }
    cout << res << endl;
}


#pragma GCC optimize("O3")
//#pragma GCC target("avx")
#include <bits/stdc++.h>
using namespace std;
#define re return
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define make_unique(x) sort(all(x)),x.resize(unique(all(x))-x.begin())
#define fi first
#define se second
#define ss second.second
#define sf second.first
#define ff first.first
#define fs first.second
#define sqrt(x) sqrt(abs(x))
#define mp make_pair
#define PI 3.14159265358979323846
#define E 2.71828182845904523536
#define er erase
#define in insert
#define fo(i,n) for((i)=0;(i)<(n);(i)++)
#define ro(i,n) for((i)=n-1;(i)>=0;(i)--)
#define fr(i,j,n) for((i)=(j);(i)<(n);(i)++)
#define rf(i,j,n) for((i)=((n)-1);(i)>=(j);(i)--)
typedef long double ld;
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int uint;
void eras(map<int,int> &m,int x)
{
    m[x]--;
    if (!m[x])
        m.erase(x);
}
const int N=(int)3e5+100;
const int M=(int)2e6+100;
const int inf=(int)1e9+100;
#define filename ""
    vector<int> prost;
    vector<int> v;
    bool was[73][(1<<20)];
    ll table[73][(1<<20)];
ll f(int x,int mask)
{
    if (x==v.size()) re 1;
    if (was[x][mask]) re table[x][mask];
    was[x][mask]=1;
    ll o=f(x+1,mask);
    if ((mask&v[x])==0) o+=f(x+1,mask|v[x]);
    re table[x][mask]=o;
}
int main()
{
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    //freopen(filename".in","r",stdin);
    //freopen(filename".out","w",stdout);
    //freopen("ans.txt","w",stdout);
    mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
    srand(time(0));
    ios_base::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
    ll a,b;
    int i,j;
    for(i=2;i<72;i++)
    {
        for(j=2;j<i;j++)
        {
            if (i%j==0) break;
        }
        if (j==i)
        {
            prost.pb(j);
        }
    }
    cin>>a>>b;
    while(a<=b)
    {
        int mask=0;
        fo(i,prost.size())
        {
            j=prost[i];
            if (a%j==0)
            {
                mask|=(1<<i);
            }
        }
        v.pb(mask);
        a++;
    }
    cout<<f(0,0);
}

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

int main(){
int n,k;
cin>>n>>k;
for(int i=0;i<k;i++){
string s = to_string(n);
sort(s.begin(),s.end());
string s1 = s;
sort(s.rbegin(),s.rend());
string s2 = s;
n = stoi(s2) - stoi(s1);
}
cout<<n;
}


#include <bits/stdc++.h>
#define f(a, n) for (int a = 0; a < n; a++)
#define F(a, n) for (int a = 1; a <= n; a++)

using namespace std;

/*
We declare an array of size 2^20. We will pretend N = 2^19. (sort of)
The i-th element is stored in A[N+i]. (0 indexed)
for i in [1, N-1], A[i] = A[2i] + A[2i+1].
When we update element i, let j = i + N, then we update A[j], A[j/2], A[j/4],...
When we query for the sum of [1, i], if the last bit is 1, we add A[j]. Either way, we set j = j / 2. Proceed until j == 0.
*/

int A[1<<20];
constexpr int N = 1 << 19;

int sumto(int i){ // sums to i - 1 inclusive
	int ret = 0;
	int j = i + N;
	while (i > 0){
		if (i & 1) ret ^= A[j - 1];
		i >>= 1;
		j >>= 1;
	}
	//i = 6 = 110, we want [0, 3] + [4, 5] = A[2] + A[6]
	//i = 7 = 111, we want A[2]+A[6]+A[14]
	//i = 5 = 101, we want A[2]+A[12]
	return ret;
}

int main(){
	int n, q;
	cin >> n >> q;
	f(i, n){
		cin>>A[i + N];
	}
	for (int i = N - 1; i > 0; i--){
		A[i] = A[2*i] ^ A[2*i+1];
	}
	f(i, q){
		int x, y, z;
		cin>>x>>y>>z;
		if (x == 1){
			int j = y-1 + N;
			while (j > 0){
				A[j] ^= z;
				j >>= 1;
			}
		}else{
			//cout<<sumto(z)<<" "<<sumto(y-1)<<"!"<<endl;
			cout << (sumto(z) ^ sumto(y-1)) << endl;
		}
	}
}

#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define ordered_set tree<ll, null_type , less<ll> , rb_tree_tag , tree_order_statistics_Node_update>
#define ll long long
#define ull unsigned long long
#define pb push_back
#define inf 3e18
#define mk make_pair
#define ld long double
#define mod 1000000007
#define fi first
#define se second
#define fastIO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define test ll t; cin>>t; while(t--)
#define setbits __builtin_popcount
#define endl '\n'
#define LOCAL
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i));}
sim, class b dor(pair < b, c > d) {
    ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
    *this << "[";
    for (auto it = d.b; it != d.e; ++it)
        *this << ", " + 2 * (it == d.b) << *it;
    ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
#define maxn 300001
vector<ll>a(maxn);
ll seg[4*maxn];
void build(ll v,ll l,ll r)
{
	if(l==r)
	{
		seg[v]=a[l];
		return;
	}
	ll mid=(l+r)/2;
	build(2*v,l,mid);
	build(2*v+1,mid+1,r);
	seg[v]=seg[2*v]^seg[2*v+1];
}
void update(ll v,ll l,ll r,ll pos,ll val)
{
	if(l==r)
	{
		seg[v]^=val;
		return;
	}
	ll mid=(l+r)/2;
	if(pos<=mid)
	{
		update(2*v,l,mid,pos,val);
	}
	else
	{
		update(2*v+1,mid+1,r,pos,val);
	}
	seg[v]=seg[2*v]^seg[2*v+1];
}
ll query(ll v,ll l,ll r,ll x,ll y)
{
	if(y<x)
	{
		return 0;
	}
	if(x<=l && r<=y)
	{
		return seg[v];
	}
	ll mid=(l+r)/2,val,val1;
	val=query(2*v,l,mid,x,min(y,mid));
	val1=query(2*v+1,mid+1,r,max(mid+1,x),y);
	return val^val1;
}
int main()
{
	fastIO;
	ll n,q;
	cin>>n>>q;
	for(int i=0;i<n;i++)
	{
		cin>>a[i];
	}
	build(1,0,n-1);
	ll x,y,z,val;
	while(q--)
	{
		cin>>x>>y>>z;
		if(x==1)
		{
			y--;
			update(1,0,n-1,y,z);
		}
		else
		{
			y--;
			z--;
			val=query(1,0,n-1,y,z);
			cout<<val<<endl;
		}
	}
}


#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
#define repr(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define invrepr(i,a,b) for(int i=b-1;i>=a;i--)
#define invrep(i,n) invrepr(i,0,n)
#define repitr(itr,a) for(auto itr=a.begin();itr!=a.end();++itr)
#define P pair<int,int>
const ll MOD=1e9+7;
const int INF=2e9;
const double PI=acos(-1);

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

    int n,m;
    cin >> n >> m;
    vector<vector<P>> r(n);
    rep(i,m) {
        int u,v,c;
        cin >> u >> v >> c;
        r[u-1].push_back({v-1,c});
        r[v-1].push_back({u-1,c});
    }
    queue<int> q;
    q.push(0);
    vector<int> ans(n),visited(n);
    ans[0]=1;
    visited[0]=1;
    while(!q.empty()) {
        int p=q.front();
        q.pop();
        int rs=r[p].size();
        rep(i,rs) {
            int np=r[p][i].first,c=r[p][i].second;
            if (visited[np]==0) {
                visited[np]=1;
                if (ans[p]==c) ans[np]=c%n+1;
                else ans[np]=c;
                q.push(np);
            }
        }
    }
    bool flag=1;
    rep(i,n) {
        if (visited[i]!=1) flag=0;
    }
    if (flag) {
        rep(i,n) cout << ans[i] << endl;
    } else cout << "No" << endl;

    return 0;
}

#include<bits/stdc++.h>
using namespace std;
const long long mod=1e9+7,INF=1e18;
#define ll long long
#define line cout<<"\n";
#define flush cout<<endl;
#define pll pair<ll,ll>
#define x first
#define y second
#define p_all(arr) for(auto i:arr){cout<<i<<" ";}cout<<"\n";
vector<ll> par,sze,val;
vector<vector<pll> > tree;
ll root(ll u)
{
    if(par[u]==u)
    return u;
    return par[u]=root(par[u]);
}
void union1(ll u,ll v)
{
    u=root(u),v=root(v);
    if(u==v)
    return ;
    if(sze[u]<sze[v])
    swap(u,v);
    sze[u]+=sze[v];
    par[v]=u;
}
void dfs(ll u,ll pa,ll value)
{
    for(auto v:tree[u])
    {
        if(v.x!=pa)
        {
            if(value!=v.y)
            {
                val[v.x]=v.y;
            }
            dfs(v.x,u,val[v.x]);
        }
    }
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);
    ll t=1;
    // cin>>t;
    for(ll test=1;test<=t;test++)
    {
        ll n,m;
        cin>>n>>m;
        par.resize(n);
        sze.resize(n,1);
        tree.resize(n);
        val.resize(n,-1);
        for(int i=0;i<n;i++)
        par[i]=i;
        vector<pair<pll,ll> > edges(m);
        for(int i=0;i<m;i++)
        {
            ll u,v,w;
            cin>>u>>v>>w;
            u--,v--;
            edges[i]={{u,v},w};
        }
        vector<vector<ll> > val1(n);
        for(int i=0;i<m;i++)
        {
            if(root(edges[i].x.x)!=root(edges[i].x.y))
            {
                union1(edges[i].x.x,edges[i].x.y);
                val1[edges[i].x.x].push_back(edges[i].y);
                val1[edges[i].x.y].push_back(edges[i].y);
                tree[edges[i].x.x].push_back({edges[i].x.y,edges[i].y});
                tree[edges[i].x.y].push_back({edges[i].x.x,edges[i].y});
            }
        }
        dfs(0,-1,-1);
        for(int i=0;i<n;i++)
        {
            if(val[i]==-1)
            {
                sort(val1[i].begin(),val1[i].end());
                for(int j=1;j<=n;j++)
                {
                    if(j>val1[i].size()||val1[i][j-1]!=j)
                    {
                        val[i]=j;
                        break;
                    }
                }
            }
        }
        for(int i=0;i<n;i++)
        {
            cout<<val[i]<<"\n";
        }
    }
    return 0;
}


// < Rahil Malhotra / ViciousCoder >
#include "bits/stdc++.h"
using namespace std;

template <typename T> void print(T t) { cout<<t<<endl; }
template<typename T, typename... Args> void print(T t, Args... args) { cout<<t<<" "; print(args...); }

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl '\n'
#define int long long
#define double long double

int32_t main()
{
    IOS;
    int n;
    cin>>n;
    int arr[n][2];
    for(int i=0;i<n;i++)
        cin>>arr[i][0]>>arr[i][1];
    int fl=0;
    for(int i=0;i<n;i++)
        for(int j=i+1;j<n;j++)
            for(int k=j+1;k<n;k++)
            {
                int a=arr[i][0]*(arr[j][1]-arr[k][1]);
                a+=arr[j][0]*(arr[k][1]-arr[i][1]);
                a+=arr[k][0]*(arr[i][1]-arr[j][1]);
                if(a==0)
                    fl=1;
            }
    if(fl)
        print("Yes");
    else
        print("No");
}

//always use
#include <bits/stdc++.h>
using namespace std;
#define forn(i, n) for(int i=0; i<n; i++)
#define mp make_pair
#define pb push_back
#define f first
#define s second
typedef long long ll;
#define MOD 1000000007
#define HASHMOD 1275341791
//2 147 483 647 (2^31-1) int max
//9 223 372 036 854 775 807 (2^63-1) ll max

//codeforces and USACO
void fast_io(){
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  cout.tie(NULL);}

//USACO
void file_io(string taskname){
  string fin = taskname + ".in";
  string fout = taskname + ".out";
  const char* FIN = fin.c_str();
  const char* FOUT = fout.c_str();
  freopen(FIN, "r", stdin);
  freopen(FOUT, "w", stdout);
  fast_io();}

//Printing pairs and vectors
template<typename A, typename B> ostream& operator<<(ostream &cout, pair<A, B> const &p) { return cout << "(" << p.f << ", " << p.s << ")"; }
template<typename A> ostream& operator<<(ostream &cout, vector<A> const &v) {
cout << "["; for(int i = 0; i < v.size(); i++) {if (i) cout << ", "; cout << v[i];} return cout << "]";}

//main code
int main(){
  fast_io();
  int n;
  cin >> n;
  vector<pair<int,int>>a(n);
  forn(i,n){
    int x,y;
    cin >> x >> y;
    a[i]=mp(x,y);
  }
  bool mybool=false;
  forn(i,n){
    forn(j,n){
      forn(k,n){
        if (i==j or i==k or j==k){
          continue;
        }
        vector<pair<int,int>>points;
        points.pb(a[i]);
        points.pb(a[j]);
        points.pb(a[k]);
        sort(points.begin(),points.end()); //sorting by increasing x
        if (((double)points[2].s-points[0].s)/(points[2].f-points[0].f)==((double)points[1].s-points[0].s)/(points[1].f-points[0].f)){
          mybool=true;
        }
      }
    }
  }
  if (mybool){
    cout << "Yes";
  }
  else{
    cout << "No";
  }
}


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

int main() {
  int a, b;
  cin >> a >> b;
  int x = (a + b) / 2;
  int y = a - x;
  cout << x << " " << y << endl;
}

#include<iostream>
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<set>
#include<string>
#include<map>
#include<string.h>
#include<complex>
#include<math.h>
#include<queue>
#include <functional>
#include<time.h>
#include <stack>
#include<iomanip>
#include<functional>
using namespace std;
#define rep(i,a,n) for(ll i=(a);i<(n);i++)
#define ll long long
#define llint long long int
#define reverse(v)  reverse(v.begin(), v.end());
#define Yes(ans) if(ans)cout<<"Yes"<<endl; else cout<<"No"<<endl;
#define YES(ans) if(ans)cout<<"YES"<<endl; else cout<<"NO"<<endl;
#define hei(a) vector<a>
#define whei(a) vector<vector<a>>
#define UF  UnionFind
#define Pint pair<int,int>
#define Pll pair<llint,llint>
#define keta(a)  fixed << setprecision(a)
const ll mod = 1000000007;
//辞書順はnext_permutation( begin( v ), end( v ) );やで！
const ll INF = 1000;

class UnionFind {
public:
	//親の番号を格納する
	vector<int> par;

	//最初は全てが根であるとして初期化
	UnionFind(int N) {
		par.resize(N);
		for (int i = 0; i < N; i++)par[i] = i;
	}

	//Aがどのグループに属しているか調べる
	int root(int A) {
		if (par[A] == A) return A;
		return par[A] = root(par[A]);
	}

	//AとBをくっ付ける
	bool unite(int A, int B) {
		//AとBを直接つなぐのではなく、root(A)にroot(B)をくっつける
		A = root(A);
		B = root(B);
		if (A == B) {
			//すでにくっついてるからくっ付けない
			return false;
		}

		//Bの親をAに変更する
		par[B] = A;

		return true;
	}
	bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
		int rx = root(x);
		int ry = root(y);
		return rx == ry;
	}
};

template<class T>
class SegTree {
public:
	T size;
	vector<T> seg; //配列
	T e; //単位元
	function <T(T, T)> f; //演算
	function<T(T, T)> updata; //更新
	SegTree(T n, T _e, function<T(T, T)> _f, function<T(T, T)> _updata) { //コンストラクタ(初期化)
		f = _f;
		e = _e;
		updata = _updata;
		size = 1;
		while (size < n)size *= 2;
		seg.resize(size * 2 - 1, e);
	}

	void change(T n, T k) { //一点更新
		n += size - 1;
		seg[n] = updata(seg[n],k);
		while (n > 0) {
			n = (n - 1) / 2;
			seg[n] = f(seg[n * 2 + 1], seg[n * 2 + 2]);
		}
	}
	T query(T a, T b, T l, T r, T k) {
		if (b <= l || r <= a)return e;
		if (a <= l && r <= b)return seg[k];
		T v1 = query(a, b, l, (l + r) / 2, k * 2 + 1);
		T v2 = query(a, b, (l + r) / 2, r, k * 2 + 2);
		return f(v1, v2);
	}

};

int main() {
	int a, b;
    cin >> a >> b;
	int ans = a + b;
	ans /= 2;
	int x = a - ans;
	cout << ans <<" "<<x<< endl;

	return 0;
}


#include <bits/stdc++.h>
using namespace std;
// type alias
typedef long long LL;
typedef pair<int,int> II;
typedef tuple<int,int,int> III;
typedef vector<int> VI;
typedef vector<string> VS;
typedef unordered_map<int,int> MAPII;
typedef unordered_set<int> SETI;
template<class T> using VV=vector<vector<T>>;
// minmax
template<class T> inline T SMIN(T& a, const T b) { return a=(a>b)?b:a; }
template<class T> inline T SMAX(T& a, const T b) { return a=(a<b)?b:a; }
// repetition
#define FORE(i,a,b) for(int i=(a);i<=(b);++i)
#define REPE(i,n)  for(int i=0;i<=(n);++i)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  for(int i=0;i<(n);++i)
#define FORR(x,arr) for(auto& x:arr)
#define SZ(a) int((a).size())
// collection
#define ALL(c) (c).begin(),(c).end()
// DP
#define MINUS(dp) memset(dp, -1, sizeof(dp))
#define ZERO(dp) memset(dp, 0, sizeof(dp))
// stdout
#define println(args...) fprintf(stdout, ##args),putchar('\n');
// debug cerr
template<class Iter> void __kumaerrc(Iter begin, Iter end) { for(; begin!=end; ++begin) { cerr<<*begin<<','; } cerr<<endl; }
void __kumaerr(istream_iterator<string> it) { (void)it; cerr<<endl; }
template<typename T, typename... Args> void __kumaerr(istream_iterator<string> it, T a, Args... args) { cerr<<*it<<"="<<a<<", ",__kumaerr(++it, args...); }
template<typename S, typename T> std::ostream& operator<<(std::ostream& _os, const std::pair<S,T>& _p) { return _os<<"{"<<_p.first<<','<<_p.second<<"}"; }
#define __KUMATRACE__ true
#ifdef __KUMATRACE__
#define dump(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); __kumaerr(_it, args); }
#define dumpc(ar) { cerr<<#ar<<": "; FORR(x,(ar)) { cerr << x << ','; } cerr << endl; }
#define dumpC(beg,end) { cerr<<"~"<<#end<<": "; __kumaerrc(beg,end); }
#else
#define dump(args...)
#define dumpc(ar)
#define dumpC(beg,end)
#endif

// $ cp-batch VariousDistances | diff VariousDistances.out -
// $ g++ -std=c++14 -Wall -O2 -D_GLIBCXX_DEBUG -fsanitize=address VariousDistances.cpp && ./a.out

/*

 10/17/2020

 4:01-4:04

 */

const int MAX_N=1e6+1;
LL X[MAX_N];
int N;

void solve() {
  LL a=0,b=0,c=0;
  REP(i,N) a+=abs(X[i]),b+=X[i]*X[i],SMAX(c, abs(X[i]));
  cout<<a<<endl;
  cout<<sqrt(b)<<endl;
  cout<<c<<endl;
}

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

  cin>>N;
  REP(i,N) cin>>X[i];
  solve();

  return 0;
}

// Problem : B - Various distances
// Contest : AtCoder - AtCoder Beginner Contest 180
// URL : https://atcoder.jp/contests/abc180/tasks/abc180_b
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

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

// Macros

template <typename T>
using ordered_set =
    tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#define ll long long
#define db long double
#define pb push_back
#define eb emplace_back
#define pii pair<int, int>
#define vi vector<int>
#define vii vector<pii>
#define mi map<int, int>
#define mii map<pii, int>
#define fi first
#define se second
#define all(a) (a).begin(), (a).end()
#define sz(x) (int) x.size()
#define mod 1000000007
#define EPS 1e-9
#define inf 1e10
#define PI acos(-1.0)
#define int long long
#define N 100005

// Solution

void solve() {
  int n;
  cin >> n;
  int m = 0, c = 0;
  db e = 0;
  for(int i=0;i<n;i++){
    int x;
    cin >> x;
    m += abs(x);
    c = max(c, abs(x));
    e += x*x;
  }
  e = sqrt(e);
  cout << fixed << setprecision(12);
  cout << m << '\n';
  cout << e << '\n';
  cout << c << '\n';
}

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

  int tests;
  tests = 1;
  // cin>>tests;

  for (int test = 1; test <= tests; test++) {
    // cout<<"Case #"<<test<<": ";
    solve();
  }

  return 0;
}


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

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define range(a) a.begin(), a.end()
#define endl "\n"
#define Yes() cout << "Yes" << endl
#define No() cout << "No" << endl
#define MP make_pair
const unsigned long long mod = 1e9 + 7;
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
void chmin(long long &a, long long b) { if (a > b) a = b; }
void chmax(long long &a, long long b) { if (a < b) a = b; }

struct Edge {
    long long to;
    long long cost;
};
using Graph = vector<vector<Edge>>;
using P = pair<long, int>;
const long long INF = 1LL << 60;

/* dijkstra(G,s,dis)
    入力：グラフ G, 開始点 s, 距離を格納する dis
    計算量：O(|E|log|V|)
    副作用：dis が書き換えられる
*/
ll dijkstra(const Graph &G, int s) {
	vector<long long> dis;
	int N = G.size();
	dis.resize(N, INF);
    priority_queue<P, vector<P>, greater<P>> pq;  // 「仮の最短距離, 頂点」が小さい順に並ぶ
    dis[s] = 0;
    pq.emplace(dis[s], s);
	bool f = true;
    while (!pq.empty()) {
        P p = pq.top();
        pq.pop();
        int v = p.second;
        if (dis[v] < p.first) {  // 最短距離で無ければ無視
            continue;
        }
        for (auto &e : G[v]) {
            if (dis[e.to] > dis[v] + e.cost) {  // 最短距離候補なら priority_queue に追加
                dis[e.to] = dis[v] + e.cost;
                pq.emplace(dis[e.to], e.to);
            }
        }
		if(f){
			dis[s] = INF;
			f = !f;
		}
	}
	return dis[s];
}

int main(){
	int N, M;
	cin >> N >> M;
	Graph G(N);
	vector<ll> self(N, INF);
	while(M--){
		ll a, b, c;
		cin >> a >> b >> c;
		--a;
		--b;
		if(a==b){
			self.at(a) = min(self.at(a), c);
			continue;
		}
		Edge e = {b, c};
		G.at(a).push_back(e);
	}

	FOR(i,0,N){
		ll g = dijkstra(G, i);
		if(g==INF&&self[i]==INF){
			cout << -1 << endl;
		}else{
			ll ans = min(g, self[i]);
			cout << ans << endl;
		}
	}

}

#pragma GCC optimize("Ofast,unroll-loops")
#pragma GCC target("avx,avx2,sse4,fma")

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

template <typename T>
using minpq = priority_queue<T, vector<T>, greater<T>>;

const int IN_SZ = 20<<20, OUT_SZ = 20<<20;
int _i0, _o0; char _, _i[IN_SZ], _o[OUT_SZ];
template <typename T> inline void re(T &x) {
	for(x=_i[_i0++]^48;(_=_i[_i0++])&16;x=x*10+(_^48)); }
template <typename T> inline void wr(T x) {
	char s[11];int i=0;do s[i++]='0'+x%10,x/=10; while(x);
	while (i--) _o[_o0++]=s[i]; _o[_o0++]='\n'; }
inline void wr(const string &s){for(char c:s)_o[_o0++]=c;}

const int maxn = 2'005;
vector<pii> adj[maxn];
int dis[maxn];

int main() {
	fread(_i,1,IN_SZ,stdin);

	int N, M; re(N), re(M);
	for (int i = 0; i < M; ++i) {
		int a,b,c; re(a),re(b),re(c);
		adj[--a].emplace_back(--b, c);
	}

	for (int st = 0; st < N; ++st) {
		minpq<pii> pq; pq.emplace(0, st);
		for (int i = 0; i < N; ++i) dis[i] = 2e9;

		bool is_loop = false;

		while (!pq.empty()) {
			const auto [d, c] = pq.top(); pq.pop();

			if (c == st && d > 0) {
				wr(d);
				is_loop = true;
				break;
			}

			if (dis[c] <= d) continue;
			dis[c] = d;

			for (const auto &[n, e]: adj[c]) {
				pq.emplace(d+e, n);
			}
		}

		if (!is_loop) {
			wr(string("-1\n"));
		}
	}

	fwrite(_o,1,_o0,stdout);
}


#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <tuple>
#include <numeric>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;

// a^n (mod.MOD)を求める。計算量はO(logn)
ll modpow(ll a, ll n, ll MOD = mod) {
    if(n == 0) {
        return 1;
    }
    if(n%2 == 1) {
        return (a * modpow(a, n-1, MOD)) % MOD;
    }
    return (modpow(a, n/2, MOD) * modpow(a, n/2, MOD)) % MOD;
}

// nCrをO(r)で求める。
ll Comb(ll n, ll r) {
    if(n < r) {
        return 0;
    }
    if(r > n-r) {
        return Comb(n, n-r);
    }
    ll Mul = 1, Div = 1;
    rep(i, r) {
        Mul *= (n-i);  Div *= (i+1);
        Mul %= mod;  Div %= mod;
    }
    return Mul * modpow(Div, mod - 2) % mod;
}

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

    ll s = 0;
    rep(i, n) {
        ll a;
        cin >> a;
        s += a;
    }

    out(Comb(n+m, n+s));
    re0;
}

#include <bits/stdc++.h>

using namespace std;

#define flush cout.flush

using ll = int;
using ull = unsigned long long;
using ld = long double;
using pl = pair<ll, ll>;
const ll INF = 1e9 + 7;
const ll mod = 1e9 + 7;
const ll mod2 = 998244353;
const ld eps = 1e-9;
const ld PI = acos(-1);
ll n, m;
vector<vector<char>> mx;
vector<char> used(26, 0);
vector<vector<pl>> to(26);
queue<pl> q;
vector<vector<ll>> d;

void go(pl a, pl b) {
    if (a.first < 0 || a.first >= n)return;
    if (a.second < 0 || a.second >= m)return;
    if (mx[a.first][a.second] == '#')return;
    if (d[a.first][a.second] != -1)return;
    d[a.first][a.second] = d[b.first][b.second] + 1;
    q.push(a);
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    cin >> n >> m;
    mx.assign(n, vector<char>(m));
    d.assign(n, vector<ll>(m, -1));
    pl st, en;
    for (ll i = 0; i < n; ++i) {
        for (ll j = 0; j < m; ++j) {
            cin >> mx[i][j];
            if (mx[i][j] == 'S') {
                st = {i, j};
            }
            if (mx[i][j] == 'G') {
                en = {i, j};
            }
            if (mx[i][j] >= 'a' && mx[i][j] <= 'z') {
                to[mx[i][j] - 'a'].push_back({i, j});
            }
        }
    }
    d[st.first][st.second] = 0;
    q.push(st);
    while (!q.empty()) {
        pl v = q.front();
        q.pop();
        if (mx[v.first][v.second] >= 'a' && mx[v.first][v.second] <= 'z' && !used[mx[v.first][v.second] - 'a']) {
            ll x = mx[v.first][v.second] - 'a';
            used[x] = 1;
            for (auto t : to[x]) {
                go(t, v);
            }
        }
        go({v.first - 1, v.second}, v);
        go({v.first + 1, v.second}, v);
        go({v.first, v.second - 1}, v);
        go({v.first, v.second + 1}, v);
    }
    cout << d[en.first][en.second] << "\n";
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define pb push_back
#define f(i,n) for(int i=0; i<n; ++i)
#define fi(i,st,n) for(int i=st; i<=n; ++i)
#define veci vector<int>
#define vecp vector<pair<int,int> >
#define vecl vector<ll>
int prime[100000+10];

ll lcm(ll a, ll b) {
	return a*b/__gcd(a,b);
}

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

ll sum(int arr[], int n) {
	ll res = 0;
	f(i,n) {
		res += arr[i];
	}
	return res;
}

void seive() {
	prime[1] = 0;
	for(int i=2; i<=100000; i++) {
		prime[i] = 1;
	}
	for(ll i=2; i<=100000; i++) {
		if(prime[i]) {
			for(ll j=i*i; j<=100000; j+=i) {
				prime[j] = 0;
			}
		}
	}
}

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int t = 1;
//	cin>>t;
	while(t--){
		ll n;
		cin>>n;
		ll arr[n];
		f(i,n) cin>>arr[i];
		ll count[200] = {0};
		f(i,n) {
			count[arr[i]%200]++;
		}
		ll ans = 0;
		for(int i=0; i<200; i++) {
			ans += count[i]*(count[i]-1)/2;
		}
		cout<<ans<<"\n";
	}
 	return 0;
}

#include <iostream>
#include <vector>
#include <algorithm>

int main(){
    long long n, ans = 0;
    std::cin >> n;
    std::vector <int> a(n);
    std::vector <std::vector<int> > list(200, std::vector<int>(0));

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

    for (int i = 0; i < n; ++i){
        int k;
        k = a[i] % 200;
        list[k].push_back(a[i]);
    }

    // std::sort(a.begin(), a.end());

    // for (int i = 0; i < n; ++i){
    //     for (int j = i+1; j < n; ++j){
    //         if ((a[j] - a[i]) % 200 == 0) ans++;
    //     }
    // }

    for (int i = 0; i < 200; ++i){
        long long k = list[i].size();
        if (k > 1){
            ans += ((k * (k - 1)) / 2);
        }
    }

    std::cout <<  ans  << std::endl;

    return 0;
}


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

using ll = long long int;

const int MAX = (int)(1e5 + 5);
const ll INF = (ll)(1e17 + 5);

const int MAX_N = (int)(2e5 + 5);

int n;

ll x[MAX_N];
int c[MAX_N];

ll dp[MAX_N][2];  // dp[i][0]: end color i at left, dp[i][1]: end color i at right

int main(void) {
  // Here your code !
  scanf("%d", &n);

  for (int i = 0; i < n; ++i) {
    scanf("%lld %d", &x[i], &c[i]);
  }

  set<int> col_set;

  for (int i = 0; i < n; ++i) {
    col_set.insert(c[i]);
  }

  int cnt = 0;

  unordered_map<int, int> dense;

  for (auto c : col_set) {
    cnt += 1;
    dense[c] = cnt;
  }

  int last_col = cnt;

  for (int i = 0; i < n; ++i) {
    c[i] = dense[c[i]];
  }

  ll most_left[MAX_N];
  ll most_right[MAX_N];
  fill(most_left, most_left + n + 5, INF);
  fill(most_right, most_right + n + 5, -INF);

  for (int i = 0; i < n; ++i) {
    most_left[c[i]] = min(most_left[c[i]], x[i]);
    most_right[c[i]] = max(most_right[c[i]], x[i]);
  }

  most_left[0] = 0;
  most_right[0] = 0;

  dp[0][0] = 0;
  dp[0][1] = 0;

  for (int col = 1; col <= last_col; ++col) {
    ll last_right = most_right[col - 1];
    ll last_left = most_left[col - 1];
    ll cur_right = most_right[col];
    ll cur_left = most_left[col];

    // last right to current left / right
    if (last_right < cur_left) {
      dp[col][0] = dp[col - 1][1] + (cur_right - last_right) + (cur_right - cur_left);
      dp[col][1] = dp[col - 1][1] + (cur_right - last_right);
    } else if (cur_left < last_right && last_right < cur_right) {
      dp[col][0] = dp[col - 1][1] + (cur_right - last_right) + (cur_right - cur_left);
      dp[col][1] = dp[col - 1][1] + (last_right - cur_left) + (cur_right - cur_left);
    } else if (cur_right < last_right) {
      dp[col][0] = dp[col - 1][1] + (last_right - cur_left);
      dp[col][1] = dp[col - 1][1] + (last_right - cur_left) + (cur_right - cur_left);
    }

    // last left to current left / right
    if (last_left < cur_left) {
      dp[col][0] = min(dp[col][0], dp[col - 1][0] + (cur_right - last_left) + (cur_right - cur_left));
      dp[col][1] = min(dp[col][1], dp[col - 1][0] + (cur_right - last_left));
    } else if (cur_left < last_left && last_left < cur_right) {
      dp[col][0] = min(dp[col][0], dp[col - 1][0] + (cur_right - last_left) + (cur_right - cur_left));
      dp[col][1] = min(dp[col][1], dp[col - 1][0] + (last_left - cur_left) + (cur_right - cur_left));
    } else if (cur_right < last_left) {
      dp[col][0] = min(dp[col][0], dp[col - 1][0] + (last_left - cur_left));
      dp[col][1] = min(dp[col][1], dp[col - 1][0] + (last_left - cur_left) + (cur_right - cur_left));
    }
  }

  ll cand_last_left = abs(most_left[last_col] - 0) + dp[last_col][0];
  ll cand_last_right = abs(most_right[last_col] - 0) + dp[last_col][1];

  ll ans = min(cand_last_left, cand_last_right);

  printf("%lld\n", ans);

  return 0;
}

#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

#define REP(i,n) for(ll i=0; i<ll(n); i++)
#define FOR(i,m,n) for(ll i=ll(m); i<ll(n); i++)
#define ALL(obj) (obj).begin(),(obj).end()
#define VI vector<int>
#define VP vector<pair<ll,ll>>
#define VPP vector<pair<int,pair<int,int>>>
#define VLL vector<long long>
#define VVI vector<vector<int>>
#define VVLL vector<vector<long long>>
#define VC vector<char>
#define VS vector<string>
#define VVC vector<vector<char>>
#define VB vector<bool>
#define VVB vector<vector<bool>>
#define fore(i,a) for(auto &i:a)
typedef pair <int, int> P;
template<typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
template<class T> bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; }

const int  INF = (1 << 30) - 1;
const ll INFL = 1LL << 61;
const ll mod =998244353;

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

	vector<pair<ll, ll>> p(200005, { INF,-INF });

	REP(i, n) {
		ll x, c;
		cin >> x >> c;
		chmin(p[c].first, x);
		chmax(p[c].second, x);
	}

	ll cura = 0;
	ll curb = 0;
	ll dista = 0;
	ll distb = 0;

	REP(i, 200005) {
		if(p[i].first == INF)continue;
		ll distaa = min(dista + abs(p[i].second - cura) + p[i].second - p[i].first,
			distb + abs(p[i].second - curb) + p[i].second - p[i].first);

		distb= min(distb + abs(p[i].first - curb) + p[i].second - p[i].first,
			dista + abs(p[i].first - cura) + p[i].second - p[i].first);
		cura = p[i].first;
		curb = p[i].second;
		dista = distaa;
		//if (i < 6)cerr << cura << ' ' << curb << ' ' << dista << ' ' << distb << endl;
	}
	ll res = 0;
	cout << min(abs(cura) + dista, abs(curb) + distb) << endl;

}


#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
#define int long long
using namespace std;
inline int read()
{
	int x=0;
	bool flag=1;
	char c=getchar();
	while(c<'0'||c>'9')
	{
		if(c=='-')
			flag=0;
		c=getchar();
	}
	while(c>='0'&&c<='9')
	{
		x=(x<<1)+(x<<3)+c-'0';
		c=getchar();
	}
	return (flag?x:~(x-1));
}
int n;
string s;
signed main()
{
	cin>>n;
	cin>>s;
	if(s[0]!=s[s.size()-1])
	{
		puts("1");
		return 0;
	}
	for(int i=1;i+2<s.size();i++)
	{
		if(s[0]!=s[i]&&s[i+1]!=s[s.size()-1])
		{
			puts("2");
			return 0;
		}
	}
	puts("-1");
	return 0;
}

#include <bits/stdc++.h>

using namespace std;

#define ar array
#define ll long long

const int MAX_N = 1e5 + 1;
const ll MOD = 1e9 + 7;
const ll INF = 1e9;

int findMaxGCD(int arr[], int n)
{
    // Calculating MAX in array
    int high = 0;
    for (int i = 0; i < n; i++)
        high = max(high, arr[i]);

    // Maintaining count array
    int count[high + 1] = {0};
    for (int i = 0; i < n; i++)
        count[arr[i]]++;

    // Variable to store the
    // multiples of a number
    int counter = 0;

    // Iterating from MAX to 1
    // GCD is always between
    // MAX and 1. The first
    // GCD found will be the
    // highest as we are
    // decrementing the potential
    // GCD
    for (int i = high; i >= 1; i--)
    {
        int j = i;
       counter = 0;

        // Iterating from current
        // potential GCD
        // till it is less than
        // MAX
        while (j <= high)
        {
            // A multiple found

            if(count[j] >=2)
               return j;

           else if (count[j] == 1)
                counter++;

            // Incrementing potential
            // GCD by itself
            // To check i, 2i, 3i....
            j += i;

            // 2 multiples found,
            // max GCD found
            if (counter == 2)
                return i;
        }
    }
}

void solve() {
    int a, b; cin >> a >> b;
    int n = b - a + 1;
    int arr[n];
    for (int i = a, j = 0; i <= b; i++, j++) arr[j] = i;
    cout << findMaxGCD(arr, n) << "\n";
}

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    int tc = 1;
    // cin >> tc;
    for (int t = 1; t <= tc; t++) {
        // cout << "Case #" << t << ": ";
        solve();
    }
}


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

const int MOD = 1e9 + 7;

int32_t main(){

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

	int n;
	cin>>n;

	set<int> s;
	for(int i=0;i<n;i++){
		int x;
		cin>>x;
		s.insert(x);
	}

	int prev = 0;
	int ans = 1;

	for(int i : s){
		int extra = i - prev + 1;
		ans = (ans*extra)%MOD;
		prev = i;
	}

	cout<<ans<<"\n";

	return 0;
}

#pragma GCC target("avx2")
#pragma GCC optimization("O3")
#pragma GCC optimization("unroll-loops")
// warning: pragmas don't work on USACO and just set to O0

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> //gp_hash_table<T, U, chash>;
#include <ext/pb_ds/tree_policy.hpp>     //tree<T, U, cmp, rb_tree_tag,tree_order_statistics_node_update>;
using namespace std; using namespace __gnu_pbds;
// shorter template (CF specialization, because compile time better)

inline int RAND(int l, int r) {
    mt19937 mt(chrono::steady_clock::now().time_since_epoch().count());
    uniform_int_distribution<int> unifd(l, r); return unifd(mt);
}

template <class T> using pq = priority_queue<T, vector<T>, greater<T>>;
using ll = long long; using db = double; using ld = long double; using pii = pair<int, int>; using pll = pair<ll, ll>; using vi = vector<int>;
using vll = vector<ll>; const int xd[4] = {0, 1, 0, -1}, yd[4] = {1, 0, -1, 0};

#define ff first
#define ss second
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
#define eb emplace_back
#define pb push_back
#define pf push_front

//#define TC
const ll INF = 1e18; const db EPS = 1e-8;
const int MOD = 1e9 + 7, // 998244353
    _ = 2e5 + 5;

void solve() {
    int n;
    cin>>n;
    vll a(n);
    for(int i=0;i<n;i++) {
        cin>>a[i];
    }
    sort(all(a));
    ll ans = 1;
    for(int i=1;i<n;i++) {
        ll res = (a[i]-a[i-1]+1);
        ans *= res;
        ans%=MOD;
    }

    ans *= (a[0]+1);
    ans%=MOD;
    cout<<ans;

}

int main() {
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
#endif
    cin.tie(0)->sync_with_stdio(0); //cout << setprecision(3) << fixed << showpoint;
    int t = 1;
    //cin >> t;
    while (t--) {
        solve();
    }
    return 0;
}