#include <bits/stdc++.h>
#define FOR(v, a, b) for(int v = (a); v < (b); ++v)
#define FORE(v, a, b) for(int v = (a); v <= (b); ++v)
#define REP(v, n) FOR(v, 0, n)
#define REPE(v, n) FORE(v, 0, n)
#define REV(v, a, b) for(int v = (a); v >= (b); --v)
#define ALL(x) (x).begin(), (x).end()
#define ITR(it, c) for(auto it = (c).begin(); it != (c).end(); ++it)
#define RITR(it, c) for(auto it = (c).rbegin(); it != (c).rend(); ++it)
#define EXIST(c,x) ((c).find(x) != (c).end())
#define LLI long long int
#define fst first
#define snd second
#ifndef M_PI
#define M_PI 3.14159265358979323846
#endif
#ifndef M_E
#define M_E 2.71828182845904523536
#endif

#ifdef DEBUG
#include <misc/C++/Debug.cpp>
#else
#define dump(x)
#endif

#define pln(x) cout << (x) << endl
#define gcd __gcd

using namespace std;
template <class T> constexpr T lcm(T m, T n){return m/gcd(m,n)*n;}

template <typename T> using V = vector<T>;
template <typename T, typename U> using P = pair<T,U>;
template <typename I> void join(ostream &ost, I s, I t, string d=" "){for(auto i=s; i!=t; ++i){if(i!=s)ost<<d; ost<<*i;}ost<<endl;}
template <typename T> istream& operator>>(istream &is, vector<T> &v){for(auto &a : v) is >> a; return is;}
template <typename T, typename U> istream& operator>>(istream &is, pair<T,U> &p){is >> p.first >> p.second; return is;}

template <typename T, typename U> T& chmin(T &a, const U &b){return a = (a<=b?a:b);}
template <typename T, typename U> T& chmax(T &a, const U &b){return a = (a>=b?a:b);}
template <typename T, size_t N, typename U> void fill_array(T (&a)[N], const U &v){fill((U*)a, (U*)(a+N), v);}

template <typename T> T power(T n, LLI p, const T &e, const function<T(T,T)> &f){
  T ret = e;
  while(p>0){
    if(p&1) ret = f(ret, n);
    n = f(n, n);
    p /= 2;
  }
  return ret;
}

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

  int N;
  while(cin >> N){
    vector<double> x(N); cin >> x;

    int M; cin >> M;
    LLI K; cin >> K;

    vector<int> a(M); cin >> a;
    for(auto &i : a) --i;

    vector<int> b(N-1);
    REP(i,N-1) b[i] = i;

    for(auto i : a){
      swap(b[i-1], b[i]);
    }

    dump(b);

    auto f = [N](const vector<int> &a, const vector<int> &b){
	       vector<int> ret(N-1);
	       REP(i,N-1){
		 ret[i] = a[b[i]];
	       }
	       return ret;
	     };

    vector<int> e(N-1);
    REP(i,N-1) e[i] = i;

    auto c = power<vector<int>>(b, K, e, f);

    dump(c);

    vector<double> diff(N-1);
    REP(i,N-1) diff[i] = x[i+1] - x[i];

    vector<double> diff2(N-1);
    REP(i,N-1) diff2[i] = diff[c[i]];

    vector<double> ans(N);
    ans[0] = x[0];
    REP(i,N-1) ans[i+1] = ans[i] + diff2[i];

    for(auto i : ans) cout << setprecision(15) << i << endl;
  }

  return 0;
}

// Crt. 2019-12-12  20:27:16
#include <algorithm>
#include <iostream>
#include <cstdio>
#define N 200005
using namespace std;
typedef long long ll;

int n, m, now[N], ans[N], tmp[N];
ll x[N], y[N], z[N], K;

int main() {
#ifdef LOCAL_JUDGE
    freopen("work.in", "r", stdin);
    freopen("work.out", "w", stdout);
#endif

    cin >> n;
    for (int i = 1; i <= n; ++i)
        scanf("%lld", x + i), y[i] = x[i] - x[i - 1], now[i] = ans[i] = i;
    cin >> m >> K;

    for (int i = 1, t; i <= m; ++i)
        scanf("%d", &t), swap(now[t], now[t + 1]);

    while (K) {
        if (K & 1) {
            for (int i = 1; i <= n; ++i) tmp[i] = ans[now[i]];
            for (int i = 1; i <= n; ++i) ans[i] = tmp[i];
        }
        for (int i = 1; i <= n; ++i) tmp[i] = now[now[i]];
        for (int i = 1; i <= n; ++i) now[i] = tmp[i];
        K >>= 1;
    }

    for (int i = 1; i <= n; ++i)
        z[i] = y[ans[i]];

    for (int i = 1; i <= n; ++i)
        z[i] += z[i - 1], printf("%lld.0\n", z[i]);

    return 0;
}


#define _USE_MATH_DEFINES
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<cmath>
#include<list>
#include<stack>
#include<queue>
#include<iomanip>
#include<functional>
using namespace std;
typedef long long llong;
int main() {
	int p, q, r;
	string x = "this the that";
	//cout << x.find("the") << endl << x.find("that") << endl << x.find("this") << endl;
	string a = "abcde";
	//cout << (int)a.find("the") << endl << (int)a.find("that") << endl << (int)a.find("this") << endl;
	string s;
	while (getline(cin, s)) {
		//cout << (int)s.find("the") << endl << (int)s.find("that") << endl << (int)s.find("this") << endl;
		for (int j = 0;; j++) {
			p = (int)s.find("the");
			q = (int)s.find("that");
			r = (int)s.find("this");
			//cout << p << q << r << endl;
			if (p >= 0 || q >= 0 || r >= 0) {
				cout << s << endl;
				break;
			}
			for (int i = 0; i < s.size(); i++) {
				if (isalpha(s[i])) {
					if (s[i] == 'z')s[i] = 'a';
					else s[i]++;

				}
			}
		}
	}
	return 0;
}

#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <vector>
#include <queue>
#include <numeric>
#include <string>
#include <string.h>
#include <map>
#include <set>
#include <functional>
#include <complex>

using namespace std;

const int INF = (1<<30) - 1;

string table = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";

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

    int n;
    while(cin >> n, n){
        vector<int> key(n);
        for(int i=0; i<n; i++)
            cin >> key[i];
        string s;
        cin >> s;
        for(int i=0; i<s.size(); i++){
            char &c = s[i];
            c = table[(table.find_first_of(c)-key[i%n]+52)%52];
        }
        cout << s << endl;
    }

    return 0;
}


#include <bits/stdc++.h>

using namespace std;

typedef long long int ll;

#define mod (int) (1e9+7)

// vector<ll>primes;

// void swap(ll &a, ll &b){
// 	ll c=a;
// 	a=b;
// 	b=c;
// }

// bool is_prime(int a){
// 	//bool f=true;
// 	for(int i=2; i*i<=a; i++){

// 		if(a%i==0){
// 			return false;
// 		}

// 	}

// 	return true;
// }

ll gcd(ll a, ll b){

	if(b==0){
		return a;
	}

	return gcd(b, a%b);

}

 ll ncr(ll x, ll y){
 	ll ans=1;

 	y=(y > x-y? x-y: y);

 	for(ll i=0; i<y; i++){
 		ans=ans*(x-i);
 		ans=ans/(i+1);
 		ans=ans%mod;
 	}

 	return ans;
 }

ll power(ll x, ll y){
    ll ans=1;
    while(y){
        if(y&1){
            ans=ans*x;
            ans=ans%mod;
        }

        x=x*x;
        x=x%mod;
        y=y>>1;
    }

    return ans;

}

void solve(){

	ll a,res=0; cin>>a;

    res+=a+(a*a)+(a*a*a);

    cout<<res<<"\n";

   return ;

}

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

    cin.tie(0);

    int t=1;//cin>>t;

    // clock_t begin, end;

    // double time_spent;

    // begin = clock(); // Time taken till now.

    while(t--){

	  solve();

    }

   //end= clock(); // Total  Time taken till now.

   //time_spent= (end- begin) / CLOCKS_PER_SEC;

   //cout<<time_spent<<"\n";

	return 0;
}

#include<bits/stdc++.h>
using namespace std;
int main(void){
    int a;
    cin>>a;
    cout<<(a+a*a+a*a*a)<<endl;
    return 0;
}


#include <cstdio>
#include <cstring>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#define INF 100000000000000000LL
using namespace std;

int main()
{
	int n, m;
	int a, b;
	scanf("%d %d", &n, &m);
	vector<int> v[100000];
	for(int i=0; i<m; i++){
		scanf("%d %d", &a, &b);
		a--;
		b--;
		v[a].push_back(b);
		v[b].push_back(a);
	}
	int c=0;
	vector<int> conn[100000];
	int d[100000], e[100000]={};
	fill(d, d+n, -1);
	set<int> st;
	for(int i=0; i<n; i++){
		st.insert(i);
	}
	vector<int> w;
	while(!st.empty()){
		auto begin=st.begin();
		w.push_back(*begin);
		conn[c].push_back(*begin);
		d[*begin]=0;
        if(v[*begin].empty()) e[c]=2;
		st.erase(begin);
		while(!w.empty()){
			int x=w.back();
			w.pop_back();
			for(int i=0; i<v[x].size(); i++){
				if(d[v[x][i]]==-1){
					d[v[x][i]]=(d[x]+1)%2;
				}else if(d[v[x][i]]==d[x]){
					e[c]=1;
				}
				if(st.find(v[x][i])==st.end()) continue;
				w.push_back(v[x][i]);
				conn[c].push_back(v[x][i]);
				st.erase(v[x][i]);
			}
		}
		c++;
	}
	long long int cn2=0, cn0=0, cn1=0, ans=0;
	for(int i=0; i<c; i++){
		if(e[i]==2){
			cn2++;
		}else if(e[i]==1){
			cn1++;
		}else{
			cn0++;
		}
	}
	for(int i=0; i<c; i++){
		if(e[i]==2){
          ans=ans+n;
		}else if(e[i]==1){
		  ans=ans+cn2*conn[i].size()+cn0+cn1;
		}else{
          ans=ans+cn2*conn[i].size()+2*cn0+cn1;
		}
	}
	long long int N=(long long int)n;
	printf("%lld\n", ans);
	return 0;
}

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(x) (x).begin(),(x).end()
const int mod=1000000007,MAX=100001,INF=1<<30;
vector<int> S[MAX],color(MAX,0),odd,even;

void DFS(int u){
    int cnt=1;
    bool ok=true;
    stack<int> ST;
    color[u]=1;
    ST.push(u);

    while(!ST.empty()){
        int a=ST.top();
        ST.pop();
        for(int i=0;i<S[a].size();i++){
            int b=S[a][i];
            if(color[b]==0){
                if(color[a]==1){
                    color[b]=2;
                    ST.push(b);
                    cnt++;
                }else{
                    color[b]=1;
                    ST.push(b);
                    cnt++;
                }
            }else if(color[a]==color[b]){
                ok=false;
            }
        }
    }

    if(ok) even.push_back(cnt);
    else odd.push_back(cnt);

    return;
}

int main(){

    int N,M;cin>>N>>M;
    for(int i=0;i<M;i++){
        int a,b;cin>>a>>b;
        a--;b--;
        S[a].push_back(b);
        S[b].push_back(a);
    }

    for(int i=0;i<N;i++){
        if(S[i].size()==0||color[i]) continue;
        DFS(i);
    }

    int rem=N;

    ll ans=0;

    for(int i=0;i<odd.size();i++){
        rem-=odd[i];
    }

    for(int i=0;i<even.size();i++){
        rem-=even[i];
    }

    ans+=odd.size()+even.size()*2;
    ans+=ll(N)*ll(N)-ll((N-rem))*ll((N-rem));

    ans+=ll(4)*ll(even.size())*ll((even.size()-1))/2;
    ans+=ll(2)*ll(even.size())*ll(odd.size());
    ans+=ll(2)*ll(odd.size())*ll((odd.size()-1))/2;

    cout<<ans<<endl;
    //cout<<rem<<" "<<odd.size()<<" "<<even.size()<<endl;

}


#include <bits/stdc++.h>
using namespace std;
int main()
{
  int x;
  int ans=0;
  cin>>x;
  ans=x*x;
  ans*=x;
  cout<<ans<<'\n';
  return 0;
}

#include<bits/stdc++.h>
using namespace std;
using ll=long long;
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define All(a) a.begin(),a.end()
#define INF 1000000007
const int MOD = 1000000007;
//accumulate(vec.begin(), vec.end(), 0)
//std::sort(v.begin(), v.end(), std::greater<Type>());
//set_intersection(x, x+7, y, y+6, back_inserter(v));
//set_union(x, x+7, y, y+6, back_inserter(v));
//set_difference(x, x+7, y, y+6, back_inserter(v));

int gcd(int x,int y){
  if(x%y==0) return y;
  else return gcd(y,x%y);
}

bool isPrime(int n){
  if(n < 2) return false;
  else if(n == 2) return true;
  else if(n%2==0) return false;

  for(int i=3;i<=sqrt(n);i++){
    if(n%i==0) return false;
  }
  return true;
}

int main(){
  int r;
  cin >> r;
  if(r<1200)cout<< "ABC" <<endl;
  else if(r<2800) cout<< "ARC" <<endl;
  else cout<< "AGC" <<endl;
}


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

const int64_t MOD = 1000000007;
typedef int64_t ll;
typedef uint64_t ull;

#define INF LLONG_MAX

#define FOR(i, start, end) for(uint64_t i=start; i<end; i++)
#define REP(i, n) FOR(i, 0, n)

// 最大公約数gcd
// 最小公倍数lcm=m*n/gcd
uint64_t gcd(uint64_t m, uint64_t n) {
  uint64_t temp;
  while (m % n != 0){
    temp = n;
    n = m % n;
    m = temp;
  }
  return n;
}

uint64_t lcm(uint64_t m, uint64_t n) {
  return (m*n)/gcd(m,n);
}

// vector<vector<uint64_t> > v(n+1, vector<uint64_t>(n+1, 0))
// v[n][k]に組み合わせ数が入る。
void comb(vector<vector <uint64_t> > &v){
  for(uint64_t i = 0;i <v.size(); i++){
    v[i][0]=1;
    v[i][i]=1;
  }
  for(uint64_t k = 1;k <v.size();k++){
    for(uint64_t j = 1;j<k;j++){
      v[k][j]=(v[k-1][j-1]+v[k-1][j]);
    }
  }
}

// 掛け算オーバーフロー判定
bool is_product_overflow(uint64_t a, uint64_t b) {

	uint64_t prod = a * b;

	return (prod / b != a);
}

//素因数分解
void primeFactorization(uint64_t a, list<uint64_t> &factors){ //素因数分解を出力するプログラム
  long i,sq;
  if(a%2==0){ //偶数の場合
    factors.push_back(2);
    primeFactorization(a/2,factors); //2で割った値で再帰
    return;
  }
  sq = sqrt(a);
  for(i=3;i<=sq;i+=2){ //3以上√a以下の奇数の場合
	if(a%i==0){
	  factors.push_back(i);
      primeFactorization(a/i,factors); //割れた値で再帰
      return;
	}
  }
  //偶数でも3以上√a以下の奇数の場合でも割り切れない場合
  if(a!=1){ //aが1でないなら、a自身は素数
    factors.push_back(a);
  }
}

// フェルマーの小定理
// mod. m での a の逆元 a^{-1} を計算する
// (a/b)%m = a*movinv(b,m)%m
int64_t modinv(int64_t a, int64_t m) {
    int64_t b = m, u = 1, v = 0;
    while (b) {
        int64_t t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}

// 円周率
// M_PI

// #include <iomanip> // setprecisionを使用するのに必要
// cout << std::fixed << std::setprecision(15) << y << endl;

// 昇順
// priority_queue<int, vector<int>, greater<int> > queue;

signed main() {
  int h,w;
  cin >> h >> w;

  vector<string> grid(h, "");
  int whiteCount = 0;
  for(int i=0;i<h;i++){
    cin >> grid[i];
    for(auto c:grid[i]){
      if(c=='.')whiteCount++;
    }
  }

  queue<tuple<int,int,int>> q;
  q.emplace(0,0,0);
  grid[0][0] = 'x';
  while(!q.empty()){
    auto pos = q.front();q.pop();
    if(get<0>(pos)==h-1&&get<1>(pos)==w-1){
      cout << whiteCount-1-get<2>(pos) << endl;
      return 0;
    }
    if(get<0>(pos)>0 && grid[get<0>(pos)-1][get<1>(pos)]=='.'){
      q.emplace(get<0>(pos)-1,get<1>(pos),get<2>(pos)+1);
      grid[get<0>(pos)-1][get<1>(pos)] = 'x';
    }
    if(get<0>(pos)<h-1 && grid[get<0>(pos)+1][get<1>(pos)]=='.'){
      q.emplace(get<0>(pos)+1,get<1>(pos),get<2>(pos)+1);
      grid[get<0>(pos)+1][get<1>(pos)] = 'x';
    }
    if(get<1>(pos)>0 && grid[get<0>(pos)][get<1>(pos)-1]=='.'){
      q.emplace(get<0>(pos),get<1>(pos)-1,get<2>(pos)+1);
      grid[get<0>(pos)][get<1>(pos)-1] = 'x';
    }
    if(get<1>(pos)<w-1 && grid[get<0>(pos)][get<1>(pos)+1]=='.'){
      q.emplace(get<0>(pos),get<1>(pos)+1,get<2>(pos)+1);
      grid[get<0>(pos)][get<1>(pos)+1] = 'x';
    }
  }
  cout << "-1" << endl;
  return 0;
}

#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cstdlib>
#include<queue>
#include<set>
#include<cstdio>

using namespace std;

#define ll long long
#define rep(i, n) for(int i = 0; i < n; i++)
#define P pair<int, int>

typedef vector<int> vec;
typedef vector<vec> mat;

const ll mod = 1000000007;

mat mul(mat &A, mat &B){
    mat C(A.size(), vec(B[0].size()));
    for (int i = 0; i < A.size(); i++){
        for (int k = 0; k < B.size(); k++){
            for (int j = 0; j < B[0].size(); j++){
                C[i][j] = (C[i][j] + A[i][k] * B[k][j]) % mod;
            }
        }
    }
    return C;
}

mat pow(mat A, ll n){
    mat B(A.size(), vec(A.size()));
    for (int i = 0; i < A.size(); i++){
        B[i][i] = 1;
    }
    while(n > 0){
        if(n & 1) B = mul(B, A);
        A = mul(A, A);
        n >>= 1;
    }
    return B;
}

int main(){
    int n, l;
    cin >> n >> l;
    int sm = 0;
    int ans = 1000000;
    rep(i, n){
        sm += l + i;
    }
    // cout << sm << endl;
    rep(i, n){
        int sm_ = 0;
        rep(j, n){
            if(i == j) continue;
            sm_ += l + j;
        }
        if(abs(ans - sm) > abs(sm_ - sm)) ans = sm_;
    }
    cout << ans << endl;
}


//
//  main.cpp

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

int main(){
	int n,m;
	int A[1001]={},B[1001]={};
	vector<pair<int,int> > vec;

	cin >> n >> m;
	for(int i=0;i<n;i++){
		cin >> A[i];
//		vec.push_back(make_pair(A[i],i));
	}
	for(int i=0;i<m;i++){
		cin >> B[i];
	}

//	sort(vec.begin(),vec.end(),greater<pair<int,int> >());
	int answer[1001]={};

	for(int j=0;j<m;j++){
		for(int i=0;i<n;i++){
			if(A[i] <= B[j]){
				answer[i] ++;
				break;
			}
		}
	}
	int Max = -1;
	for(int i=0;i<n;i++){
		Max = max(Max,answer[i]);
	}
	for(int i=0;i<n;i++){
		if(Max == answer[i]){
			cout << i+1 << endl;
			break;
		}
	}

	return 0;
}

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

int n, m;
int a[1020], b[1020];
int vote[1020];

int main()
{
    while(cin >> n>> m)
    {
        memset(vote, 0, sizeof vote);
        for(int i=1;i<=n;i++) scanf("%d",&a[i]);
        for(int i=1;i<=m;i++) scanf("%d",&b[i]);

        for(int i=1;i<=m;i++)
        {
            int j = 1;
            while(a[j] > b[i]) j++;
            vote[j]++;
        }
        printf("%d\n",max_element(vote+1,vote+n+1)-vote);
    }
    return 0;
}


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

using namespace std;
typedef long long ll;

int main(){
  ll N;
  cin >> N;
  ll P[N];
  for(ll i=0;i<N;i++){
    cin >> P[i];
  }
  ll ans = 1;
  ll now = P[0];
  for(ll i=1;i<N;i++){
    if(P[i]<now){
      ans++;
      now = P[i];
    }
  }
  cout << ans << endl;
}


/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author rahdirigs
 */

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

template <typename T> void add(T& a, T b, int mod) {
	a += b;
	if (a >= mod)
		a -= mod;
}

template <typename T> void sub(T& a, T b, int mod) {
	a -= b;
	if (a < 0)
		a += mod;
}

const int mxN = 10005, mxD = 110, mod = 1e9 + 7;
ll dp[mxN][mxD][2];

class TaskS {
public:
	string K;
	int D, n;
	vector<int> digits;

	void solve(std::istream& in, std::ostream& out) {
		in >> K >> D;
		for (char it : K) digits.push_back(it - '0');
		n = (int) digits.size();
		memset(dp, -1, sizeof(dp));
		ll ans = rec(0, 0, 1);
		sub(ans, 1ll, mod);
		out << ans;
	}

	ll rec(int pos, int sum, int flag) {
		if (pos == n) {
			if (sum % D == 0) return 1;
			return 0;
		}
		if (dp[pos][sum][flag] != -1) return dp[pos][sum][flag];
		int limit = 9;
		ll tot = 0;
		if (flag == 1) limit = digits[pos];
		for (int i = 0; i <= limit; i++) {
			if (i == digits[pos]) {
				add(tot, rec(pos + 1, (sum + i) % D, flag), mod);
			} else {
				add(tot, rec(pos + 1, (sum + i) % D, 0), mod);
			}
		}
		return dp[pos][sum][flag] = tot;
	}
};

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	TaskS solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}

#include<bits/stdc++.h>

using namespace std;

#define int long long

int dp[10010][110];
int mod = 1e9 + 7;

int32_t main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	string s;
	cin >> s;
	int d;
	cin >> d;
	int n = s.size();
	dp[0][0] = 1;
	for (int i = 0; i < n; i++) {
        for (int j = 0; j < d; j++) {
            for (int k = 0; k < 10; k++) {
                dp[i + 1][(j + k) % d] += dp[i][j];
                dp[i + 1][(j + k) % d] %= mod;
            }
        }
	}
	int sum = 0;
	int ans = 0;
	for (int i = 0; i < n; i++) {
        for (int j = 0; j < s[i] - '0'; j++) {
            ans += dp[n - i - 1][(d - (sum + j) % d) % d];
            ans %= mod;
        }
        sum += s[i] - '0';
	}
	if (sum % d == 0) {
        ans++;
	}
	ans += mod - 1;
	ans %= mod;
	cout << ans << endl;
	return 0;
}


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

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

  if (N == 1){
    cout << 1 << endl;
    return 0;
  }

  vector<int>A(N);
  vector<vector<vector<int>>> data(N, vector<vector<int>>(N, vector<int>(2)));

  for (int i = 0; i < N; i++) {
    cin >> A.at(i);
    for (int j = 0; j < A.at(i); j++) {
      for (int k = 0; k < 2; k++) {
        cin >> data.at(i).at(j).at(k);
      }
    }
  }

  int Max = 0;

  // すべての選び方を試して、総和がKになるものがあるかを調べる
  for (int tmp = 0; tmp < (1 << 15); tmp++) {
    bitset<15> s(tmp);  // 最大20個なので20ビットのビット列として扱う

    if (N < 15 && s.test(N)) {
      break;
    }
    // ビット列の1のビットに対応する整数を選んだとみなして総和を求める
    int count = 0;
    int honest = 0;

    for (int i = 0; i < N; i++) {
      if (s.test(i)) {
        honest++;
        for (int j = 0; j < A.at(i); j++) {
          int B = data.at(i).at(j).at(0) - 1;
          if (s.test(B)){
            if (data.at(i).at(j).at(1) == 0){
              count++;
            }
          }
          else {
            if (data.at(i).at(j).at(1) == 1){
              count++;
            }
          }
        }
      }
    }
    if (count == 0){
      if (honest > Max){
        Max = honest;
      }
    }
  }

  cout << Max << endl;
}

#include<bits/stdc++.h>
using namespace std;
#define lint long long
#define inf 1000000007
#define mod 1000000007
#define MAX 100005
#define pb push_back
#define mp make_pair
#define vit vector<int>::iterator
typedef pair<int,int> pii;
vector<pii> V[MAX];
int pos[MAX],flg,visited[MAX];
void dfs(int u){
    visited[u]=1;
    for(auto v:V[u]){
        if(v.second){
            if(!pos[v.first]){
                pos[v.first]=1;
                dfs(v.first);
            }
            else if(pos[v.first]==1){
                if(!visited[v.first])
                    dfs(v.first);
            }
            else flg=1;
        }
        else{
            if(!pos[v.first]) pos[v.first]=2;
            else if(pos[v.first]==1) flg=1;
        }
    }
}
int possible(int k,int n){
    vector<int>vec;
    for(int i=0;i<(n-k);i++) vec.pb(0);
    for(int i=0;i<k;i++) vec.pb(1);
    do{
        flg=0;
        for(int i=1;i<=n;i++){
            visited[i]=0;
            pos[i]=vec[i-1];
        }
        for(int i=1;i<=n;i++){
            if(!visited[i] && vec[i-1]){
                dfs(i);
            }
        }
        if(!flg)
            return 1;

    }while(next_permutation(vec.begin(),vec.end()));
    return 0;
}
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n;
    cin>>n;

    for(int i=0;i<n;i++){
        int a;
        cin>>a;
        for(int j=0;j<a;j++){
            int x,y;
            cin>>x>>y;
            V[i+1].pb(mp(x,y));
        }
    }
    int lo,hi,mid;
    lo=0;
    hi=n;
    while(hi>lo){
        mid=(lo+hi+1)/2;
        if(possible(mid,n)) lo=mid;
        else hi=mid-1;
    }
    cout<<lo;
}


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

int main() {
    int n, k;
    cin >> n >> k;
    vector<bool> v(10, true);
    rep(i, k) {
        int a;
        cin >> a;
        v[a] = false;
    }
    while(1) {
        int ans = n;
        while(ans > 0) {
            if (!v[ans % 10]) {
                break;
            }
            ans /= 10;
        }
        if (ans == 0) break;
        n++;
    }
    cout << n << "\n";
}

#include<cstdio>
#include<iostream>
#include<vector>
#include<string>
#include<map>
#include<stack>

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++)

vector<int> card[10];
map<stack<int> ,int> check;
int visit[10];

stack<int> ub;
int cont;

void saiki(int dep,int k,int n){
	if(dep==k){
		if(check[ub]==0){
			check[ub]=1;
			cont++;
		}
		return;
	}

	rep(i,n){
		if(visit[i]==0){
			visit[i]=1;
			rep(j,card[i].size()){
				ub.push(card[i][j]);
			}

			saiki(dep+1,k,n);

			rep(j,card[i].size()){
				ub.pop();
			}
			visit[i]=0;
		}
	}
}

int main(){
	while(1){
		int n;
		int k;

		scanf("%d%d",&n,&k);
		if(n==0)break;

		rep(i,10){
			card[i].clear();
			visit[i]=0;
		}

		check.clear();
		cont=0;

		rep(i,n){
			int a;
			scanf("%d",&a);

			if(a<10){
				card[i].push_back(a);
			}else{
				card[i].push_back(a/10);
				card[i].push_back(a%10);
			}
		}

		saiki(0,k,n);

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


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

class Dice{
public:
	int dice[6];
	int buff1, buff2, buff3;
	void north(){
		buff1 = dice[0];
		buff2 = dice[1];
		buff3 = dice[5];
		dice[5] = dice[4];	// 5 <- 1'
		dice[0] = buff2;	// 0 <- 4
		dice[4] = buff1;	// 4 <- 5'
		dice[1] = buff3;	// 1 <- 0'
	}
	void south(){
		buff1 = dice[0];
		buff2 = dice[1];
		buff3 = dice[5];
		dice[0] = dice[4];	// 0 <- 1'
		dice[1] = buff1;	// 1 <- 5'
		dice[5] = buff2;	// 5 <- 4
		dice[4] = buff3;	// 4 <- 0'
	}
	void west(){
		buff1 = dice[0];
		buff2 = dice[2];
		buff3 = dice[5];
		dice[0] = buff2;	// 0 <- 2'
		dice[2] = buff3;	// 2 <- 5'
		dice[5] = dice[3];	// 5 <- 3
		dice[3] = buff1;	// 3 <- 0'
	}
	void east(){
		buff1 = dice[0];
		buff2 = dice[2];
		buff3 = dice[5];
		dice[2] = buff1;	// 2 <- 0'
		dice[5] = buff2;	// 5 <- 2'
		dice[0] = dice[3];	// 0 <- 3
		dice[3] = buff3;	// 3 <- 5'
	}
};

int main()
{
	Dice d;
	for(int n = 0; n < 6; n++)
		cin >> d.dice[n];

	string command;
	string::iterator itr;
	char direction;
	cin >> command;
	for(itr = command.begin(); itr != command.end(); itr++){
		direction = *itr;
		if(direction == 'N')
			d.north();
		if(direction == 'S')
			d.south();
		if(direction == 'E')
			d.east();
		if(direction == 'W')
			d.west();
	}
	cout << d.dice[0] << endl;
}

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

#define fastio 			ios::sync_with_stdio(0);	cin.tie(0); cout.tie(0);  cout<<fixed;  cout<<setprecision(12);
#define randomINT 		mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
#define	newl 			cout<<"\n"
#define DISP(as)		for(auto it : as) cout<<it<<" ";newl;
#define DISP1(as)		for(auto it : as) cout<<it.f<<" "<<it.s<<") ";newl;
#define all(x)         	(x).begin(),(x).end()
#define mset(x,val)    	memset(x,val,sizeof(x))
#define newl           	cout<<"\n"
#define pb             	push_back
#define mp             	make_pair
#define f 				first
#define s 				second
#define dline          cerr<<"///REACHED///\n";
#define deb1(x)        cerr<<#x<<" = "<<x<<'\n';
#define deb2(x,y)      cerr<<'['<<#x<<','<<#y<<"] = "<<'['<<x<<','<<y<<']'<<'\n';
#define deb3(x,y,z)    cerr<<'['<<#x<<','<<#y<<','<<#z<<"] = "<<'['<<x<<','<<y<<','<<z<<']'<<'\n';

typedef long long 				ll;
typedef long double 			ld;
typedef vector<ll> 				vll;
typedef pair<ll , ll> 			pll;
typedef pair<ld, ld> 			pld;
typedef unordered_map<ll, ll> 	um;
typedef vector<pll> 			vpll;

const ll 	MAX5 	= 	2e+5 + 99;
const ll 	MAX7 	= 	1e+7 + 7;
const ll 	MAXN 	= 	MAX7;
const ll   	INF   	=  	0x7f7f7f7f7f7f7f7f;
const int  	INFi 	=  	0x7f7f7f7f;
const ll 	MOD		=  	1e+9 + 7;

// <------------- Declare Variables Here ------------> //

ll T = 1;
ll n, k, l, q, x, y;
string s, t;
ll prime[2000000];

// < ----------- func eh ---------------- ? //

// <------------- Start of main() -------------------> //

void MAIN() {
	ll h, m1, m2;
	cin >> h >> m1; m1 += 60 * h;
	cin >> h >> m2; m2 += 60 * h;

	cin>>k;
	m2-=k;

	cout<<max(0ll,m2-m1);newl;
}

int main() {
	fastio; randomINT;
	//cin >> T;
	while (T--) {
		MAIN();
	}
	return 0;
}


#include <iostream>
using namespace std;

int data[100];
int count=0;
void BubbleSort(int[],int);

int main(){

	int i,n;

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

	BubbleSort(data,n);

	for(i=0; i<n; i++){
		cout<<data[i];
		if(i==n-1)cout<<endl;
		else cout<<" ";
	}

	cout<<count<<endl;

return 0;

}

void BubbleSort(int data[],int n){

	int i,j,suspend;

	for(i=0; i<n; i++){
		for(j=n-1; j>=i+1; j--){
			if(data[j]<data[j-1]){
				suspend=data[j];
				data[j]=data[j-1];
				data[j-1]=suspend;
				count++;
			}
		}
	}
}

#define DIN freopen("input.txt","r",stdin);
#define DOUT freopen("output.txt","w",stdout);
#include <bits/stdc++.h>
#include <cstdio>
#define mem(a,b) memset(a,b,sizeof(a))
#define REP(i,a,b) for(int i=(a);i<=(int)(b);i++)
#define REP_(i,a,b) for(int i=(a);i>=(b);i--)
#define pb push_back
using namespace std;
typedef long long LL;
typedef std::vector<int> VI;
typedef std::pair<int,int> P;
int read()
{
    int x=0,flag=1; char c=getchar();
    while((c>'9' || c<'0') && c!='-') c=getchar();
    if(c=='-') flag=0,c=getchar();
    while(c<='9' && c>='0') {x=(x<<3)+(x<<1)+c-'0';c=getchar();}
    return flag?x:-x;
}

int main()
{
    int a[105],n;
    n=read();
    REP(i,1,n) a[i]=read();
    sort(a+1,a+n+1);
    int ans=0;
    for(int i=1;i<n;i++)
        for(int j=i+1;j<n;j++)
            for(int k=j+1;k<=n;k++)
                if(a[i]+a[j]>a[k] && a[i]!=a[j] && a[j]!=a[k])
                    ans++;
    cout<<ans;

    return 0;
}


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

int main(){
    priority_queue<int>q1,q2;
    int a,b;
    for(int i=0;i<4;i++){
        cin>>a;
        q1.push(a);
    }
    for(int i=0;i<2;i++){
        cin>>a;
        q2.push(a);
    }
    for(int i=0;i<3;i++){
        b+=q1.top();
        q1.pop();
    }
    cout<<b+q2.top()<<endl;
}

#include<iostream>
using namespace std;
int main(){
	int a[3],e,f,x,y,z,i;
	cin>>a[0]>>a[1]>>a[2]>>a[3]>>e>>f;
	x=100;
	y=0;
	for(i=0;i<4;i++){
		y=y+a[i];
		if(x>a[i]){
			x=a[i];
		}
	}
	z=y-x;
	if(e>f){
		z=z+e;
	}else{
		z=z+f;
	}
	cout<<z<<endl;
	return 0;
}


#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
#define MOD 1000000007LL
using namespace std;
typedef int_fast64_t ll;

template<int N, typename T, T M>
struct ModFact {
    T fact[N+1];
    constexpr ModFact() : fact() {
        fact[0] = 1;
        for (int i=0; i<N; ++i)
            fact[i+1] = (fact[i]*(i+1))%M;
    }
};

ModFact<100000, ll, MOD> fact;

ll ans;
int N, M, cnt = 0;
constexpr ll th = 1LL<<45;
char S[200000];

int main() {
    scanf("%d%s", &N, S);
    M = N << 1;
    ans = fact.fact[N];
    char *E = S + M, *C = S;
    while(C < E) {
		if((*C++^cnt)&1) {
            ans = ans * cnt % MOD;
            if(--cnt < 0) break;
        } else ++cnt;
	}
    printf("%lld\n", cnt == 0 ? ans : 0);
    return 0;
}

#include<iostream>
#include<vector>
#include<string>
using namespace std;
#define MOD 1000000007
int main(){
  int n; cin >> n;
  string s; cin >> s;
  vector<long long int> l,r;
  int parity = 0;
  for(int i=0;i< 2*n;i++){
    if(parity < 0){cout << 0 << endl; return 0;}
    if(parity==0 && s[i]=='W'){cout << 0 << endl; return 0;}
    if((parity%2==1) == (s[i]=='W')) {parity++; l.push_back(i);}
    else {parity--; r.push_back(i);}
  }
  if(parity != 0 || (r.size() != n) || (l.size()!=n) ){cout << 0 << endl; return 0;}
  long long int ans = 1;
  for(int i=n-1; i>=0; i--){
  	int num = n - (n-1-i) - (lower_bound(r.begin(), r.end(), l[i]) - r.begin());
    ans = (ans * num) % MOD;
  }
  for(int i=1;i<=n;i++){
    ans = (ans * i) % MOD;
  }
  cout << ans << endl;
  return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
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;
}

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
const ll mod = 1000000007;
ll X[3];
int N;
set<vector<int>> states;

void initialize(vector<int> v, int nowsum, int index) {
    states.insert(v);
    if(index == 3) return;
    for(int now = 1; now < X[index] - nowsum; now++) {
        v.push_back(now);
        initialize(v, nowsum + now, index);
        v.pop_back();
    }
    v.push_back(X[index] - nowsum);
    initialize(v, 0, index + 1);
}

void print(vector<int> v) {
    for(int i = 0; i < v.size(); i++) cerr << v[i] << " ";
    cerr << endl;
}
map<vector<int>, int> mp;
vector<int> vecs[50000];
int NEXT[50000][12];
bool checker(vector<int> v) {
    int index = 0;
    int nowsum = 0;
    for(int i = 0; i < v.size(); i++) {
        nowsum += v[i];
        if(index == 3 || nowsum > X[index]) {
            return false;
        }
        if(nowsum == X[index]) {
            nowsum = 0;
            index++;
        }
    }
    return index == 3;
}

void validate(vector<int> &v) {
    int index = 0;
    int nowsum = 0;
    for(int i = 0; i < v.size(); i++) {
        nowsum += v[i];
        if(index == 3 || nowsum > X[index]) {
            v.erase(v.begin());
            validate(v);
            return;
        }
        if(nowsum == X[index]) {
            nowsum = 0;
            index++;
        }
    }
    return;
}

ll dpnext[50000];
ll dpprev[50000];

int main() {
    //cout.precision(10);
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> N >> X[0] >> X[1] >> X[2];
    initialize({}, 0, 0);
    int num = 0;
    for(auto itr = states.begin(); itr != states.end(); itr++) {
        num++;
        mp[*itr] = num;
        vecs[num] = *itr;
        //print(*itr);
    }
    for(int i = 1; i <= num; i++) {
        for(int val = 1; val <= 10; val++) {
            vector<int> v = vecs[i];
            v.push_back(val);
            validate(v);
            NEXT[i][val] = mp[v];
            if(checker(vecs[i])) NEXT[i][val] = i;
            /*
            cerr << "----" << endl;
            print(vecs[i]);
            cerr << val << endl;
            print(v);
            */
        }
    }
    //cerr << states.size() << endl;
    dpprev[1] = 1;
    while(N--) {
        for(int index = 0; index <= num; index++) dpnext[index] = 0;
        for(int before = 1; before <= num; before++) {
            for(int val = 1; val <= 10; val++) {
                dpnext[NEXT[before][val]] += dpprev[before];
                dpnext[NEXT[before][val]] %= mod;
            }
        }
        swap(dpnext, dpprev);
    }
    ll ans = 0;
    for(int index = 1; index <= num; index++) {
        if(checker(vecs[index])) {
            ans = (ans + dpprev[index]) % mod;
            /*
            if(dpprev[index] == 0) continue;
            print(vecs[index]);
            cerr << dpprev[index] << endl;
            */
        }
    }
    cout << ans << endl;
    return 0;
}


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

const int mxD = 110, mxN = 1e4 + 5, mod = 1e9 + 7;
string K;
int D, n;
vector<int> digits;
ll dp[mxN][mxD][2];

ll rec(int idx, int sum, int flag) {
	if (idx == n) {
		if (sum % D == 0) {
			return 1;
		}
		return 0;
	}
	if (dp[idx][sum][flag] != -1) {
		return dp[idx][sum][flag];
	}
	int limit = (flag == 1)? digits[idx] : 9;
	ll ans = 0;
	for (int i = 0; i <= limit; i++) {
		if (i == digits[idx]) {
			ans = (ans + rec(idx + 1, (sum + i) % D, flag)) % mod;
		} else {
			ans = (ans + rec(idx + 1, (sum + i) % D, 0)) % mod;
		}
	}
	return dp[idx][sum][flag] = ans;
}

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

	cin >> K >> D;
	n = (int) K.length();
	for (char it : K) {
		digits.push_back(it - '0');
	}
	memset(dp, -1, sizeof(dp));
	ll ans = rec(0, 0, 1);
	ans = (ans - 1 + mod) % mod;
	cout << ans;

	return 0;
}

#include<bits/stdc++.h>

#define X first
#define Y second
#define ll long long
#define MP make_pair
#define PB push_back

using namespace std;

const int MAXN=1e5;
ll MOD=1e9+7;

string s;
ll d;
ll dp[105];
ll novidp[105];
ll rj,n;
ll br;

void update(){
	for(int i=0; i<103; i++){
		dp[i]=novidp[i];
		novidp[i]=0;
	}
}

void cist(){
	memset(novidp,0,sizeof(novidp));
}

int main () {

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

	cin>>s>>d;
	n=s.size();
	for(int i=0; i<n-1; i++){
		br+=s[i]-'0';
	}
	for(int i='0'; i<=s[n-1]; i++){
		if((br+i-'0')%d==0){
			rj++;
		}
	}
	for(int i=0; i<=9; i++){
		dp[i%d]++;
	}
	for(int i=n-2; i>=0; i--){
		br-=s[i]-'0';
		for(int j=0; j<s[i]-'0'; j++){
			rj+=dp[(d*1000000000000-br-j)%d];
			rj%=MOD;
		}
		cist();
		for(int j=0; j<d; j++){
			for(int i=0; i<10; i++){
				novidp[(j+i)%d]+=dp[j];
				novidp[(j+i)%d]%=MOD;
			}
		}
		update();
	}
	rj--;
	if(rj==-1){
		rj=1e9+6;
	}
	cout<<rj;

	return 0;
}


#include<cmath>
#include<iostream>

int main(){
    double r; std::cin >> r;
    std::cout << 2*M_PI*r << std::endl;
    return 0;
}

#include <iostream>
#include <cmath>
#include <vector>
#include <map>
#include <iomanip>
#include <algorithm>
#include <sstream>
#include <string>
#include <math.h>
#include <set>
#include <deque>
#include <queue>
using namespace std;
typedef long long ll;
const int mod = 1000000007;

int main() {
    ios::sync_with_stdio(false);
    string s;
    cin >> s;
    cout << 2018;
    for (int i = 4 ; i < s.length() ; i++) cout << s[i];
}


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

int gcd(int x, int y);

const int INF = 1001001001;

/*struct mint {
    ll x; // typedef long long ll;
    mint(ll x = 0) :x((x% mod + mod) % mod) {}
    mint operator-() const { return mint(-x); }
    mint& operator+=(const mint a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator-=(const mint a) {
        if ((x += mod - a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this; }
    mint operator+(const mint a) const { return mint(*this) += a; }
    mint operator-(const mint a) const { return mint(*this) -= a; }
    mint operator*(const mint a) const { return mint(*this) *= a; }
    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t >> 1);
        a *= a;
        if (t & 1) a *= *this;
        return a;
    }

    // for prime mod
    mint inv() const { return pow(mod - 2); }
    mint& operator/=(const mint a) { return *this *= a.inv(); }
    mint operator/(const mint a) const { return mint(*this) /= a; }
};
istream& operator>>(istream & is, const mint & a) { return is >> a.x; }
ostream& operator<<(ostream & os, const mint & a) { return os << a.x; }*/

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

    if (r < 1200)
        cout << "ABC" << endl;
    else if (r < 2800)
        cout << "ARC" << endl;
    else
        cout << "AGC" << endl;

    return 0;
}

/*���C�u�����ő����*/
//���[�O���b�h�̌ݏ��@
int gcd(int x, int y) {
    int num[3];
    num[0] = (x > y) ? x : y;
    num[1] = (x <= y) ? x : y;
    num[2] = num[0] % num[1];

    while (num[2]) {
        num[0] = num[1];
        num[1] = num[2];
        num[2] = num[0] % num[1];
    }

    return num[1];
}

/**
 * auther: moririn_cocoa
 */
// #pragma GCC target("avx")  // CPU 処理並列化
// #pragma GCC optimize("O3")  // CPU 処理並列化
// #pragma GCC optimize("unroll-loops")  // 条件処理の呼び出しを減らす
// #define BEGIN_STACK_EXTEND(size) void * stack_extend_memory_ = malloc(size);void * stack_extend_origin_memory_;char * stack_extend_dummy_memory_ = (char*)alloca((1+(int)(((long long)stack_extend_memory_)&127))*16);*stack_extend_dummy_memory_ = 0;asm volatile("mov %%rsp, %%rbx\nmov %%rax, %%rsp":"=b"(stack_extend_origin_memory_):"a"((char*)stack_extend_memory_+(size)-1024));
// #define END_STACK_EXTEND asm volatile("mov %%rax, %%rsp"::"a"(stack_extend_origin_memory_));free(stack_extend_memory_)

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <bitset>
#include <stdio.h>
#include <stdlib.h>
using namespace std;

#define rep(i,n) for(int i=0;i<(n);i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define all(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define fi first
#define se second

int main(int argc, char* argv[]) {

  int R;

  cin >> R;

  if ( R < 1200 ) {

    cout << "ABC" << endl;
  }

  else if ( R >= 1200 && R < 2800 ) {

    cout << "ARC" << endl;
  }

  else {

    cout << "AGC" << endl;
  }

  return 0;
}


#include <iostream>
#include <vector>
#include <cstring>
#include <queue>
#include <utility>
#include <algorithm>
#define INF 700000000

using namespace std;

vector<pair<int, int>> adj[110];

int solve (int x, int d)
{
    int dst[110];
    bool done[110];
    priority_queue<pair<int, int>> que;
    for (int i=0; i<110; i++) dst[i]=INF;
    memset(done, false, sizeof(done));
    dst[x]=0;
    que.push({0,x});
    while (!que.empty())
    {
        int a=que.top().second;
        que.pop();
        if (done[a]) continue;
        done[a]=true;
        for (auto u : adj[a])
        {
            int b=u.first, w=u.second;
            if (dst[a]+w<dst[b])
            {
                dst[b]=dst[a]+w;
                que.push({-dst[b], b});
            }
        }
    }
    if (dst[d]==INF) return -1;
    else return dst[d];
}

int main()
{
    while (1)
    {
        for (int i=0; i<110; i++) adj[i].clear();
        int n, k, a, b, c, d;
        bool ok;
        cin>>n>>k;
        if (n==0 && k==0) break;
        for (int i=0; i<k; i++)
        {
            cin>>a>>b>>c;
            if (a==0)
            {
                cout<<solve(b,c)<<'\n';
            }
            else
            {
                cin>>d;
                ok=true;
                for (auto itr=adj[b].begin(); itr!=adj[b].end(); itr++)
                {
                    if (itr->first==c)
                    {
                        itr->second=min(itr->second, d);
                        ok=false;
                    }
                }
                if (ok) adj[b].push_back({c,d});
                ok=true;
                for (auto itr=adj[c].begin(); itr!=adj[c].end(); itr++)
                {
                    if (itr->first==b)
                    {
                        itr->second=min(itr->second, d);
                        ok=false;
                    }
                }
                if (ok) adj[c].push_back({b,d});
            }
        }
    }
    return 0;
}

#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define rep(i,s,e) for(int (i) = (s);(i) <= (e);(i)++)
#define all(x) x.begin(),x.end()

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

    long long INF = 1e10;
    vector<vector<long long>> dist(n, vector<long long>(n, INF));
    for(int i = 0;i < n;i++) dist[i][i] = 0;

    for(int q = 0;q < k;q++) {
      int Q;
      cin >> Q;
      if(Q == 0) {
        int a, b;
        cin >> a >> b;
        a--;
        b--;
        if(dist[a][b] < INF) {
          cout << dist[a][b] << endl;
        }
        else {
          cout << -1 << endl;
        }
      }
      else {
        long long c,d,e;
        cin >> c >> d >> e;
        c--;
        d--;
        dist[c][d] = min(dist[c][d], e);
        dist[d][c] = min(dist[d][c], e);

        for(int i = 0;i < n;i++) for(int j = 0;j < n;j++) {
          dist[i][j] = min(dist[i][j], dist[i][c] + dist[c][d] + dist[d][j]);
        }

        for(int i = 0;i < n;i++) for(int j = 0;j < n;j++) {
          dist[i][j] = min(dist[i][j], dist[i][d] + dist[d][c] + dist[c][j]);
        }
      }
    }
  }
}


#include<iostream>
using namespace std;
int main(){
    string str,str2;
    cin >> str;
    int n = str.size();
    for(int i = 0;i < n;i++){
        str2.push_back(str[n-i-1]);
    }
    cout << str2 << endl;
    return 0;
}

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

string s;

int main() {
  cin >> s;
  for (int i = 1; i < s.size(); ++i)
    if (s[i - 1] == 'A' && s[i] == 'C') {
      cout << "Yes" << endl;
      return 0;
    }
  cout << "No" << endl;
  return 0;
}


#include <stdio.h>
#include <string.h>
int main(){
    char arry[20];
    scanf("%s",&arry);
    int ln=strlen(arry),i;
    for(i=ln-1;i>=0;i--)
    {
        printf("%c",arry[i]);
    }
    printf("\n");
    return 0;
}

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

int main(){
  string s;
  cin>>s;
  for(string::reverse_iterator r = s.rbegin();r!=s.rend();r++) cout<<*r;
  cout<<endl;
  return 0;
}


#include <bits/stdc++.h>
#define ADD(a, b) a = (a + ll(b)) % mod
#define MUL(a, b) a = (a * ll(b)) % mod
#define MAX(a, b) a = max(a, b)
#define MIN(a, b) a = min(a, b)
#define rep(i, a, b) for(int i = int(a); i < int(b); i++)
#define rer(i, a, b) for(int i = int(a) - 1; i >= int(b); i--)
#define all(a) (a).begin(), (a).end()
#define sz(v) (int)(v).size()
#define pb push_back
#define sec second
#define fst first
#define debug(fmt, ...) Debug(__LINE__, ":", fmt, ##__VA_ARGS__)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef pair<int, pi> ppi;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vl> mat;
typedef complex<double> comp;
void Debug() {cout << '\n'; }
template<class FIRST, class... REST>void Debug(FIRST arg, REST... rest){
	cout<<arg<<" ";Debug(rest...);}
template<class T>ostream& operator<<(ostream& out,const vector<T>& v) {
	out<<"[";if(!v.empty()){rep(i,0,sz(v)-1)out<<v[i]<<", ";out<<v.back();}out<<"]";return out;}
template<class S, class T>ostream& operator<<(ostream& out,const pair<S, T>& v){
	out<<"("<<v.first<<", "<<v.second<<")";return out;}
const int MAX_N = 200010;
const int MAX_V = 100010;
const double eps = 1e-6;
const ll mod = 1000000007;
const int inf = 1 << 29;
const ll linf = 1LL << 60;
const double PI = 3.14159265358979323846;
///////////////////////////////////////////////////////////////////////////////////////////////////

int N, K;
int dp[310][310][310];
bool used[26];
string str;

int loop(int a, int b, int k) {
	if(k < 0) return -inf;
	else if(a > b + 1) return 1;
	else if(a == b + 1) return 0;
	else if(a == b) return 1;
	else if(dp[a][b][k] != -1) return dp[a][b][k];
	else {
		int res = 1;
		if(str[a] == str[b]) {
			MAX(res, loop(a + 1, b - 1, k) + 2);
		}
		else {
			MAX(res, loop(a + 1, b, k));
			MAX(res, loop(a, b - 1, k));
			MAX(res, loop(a + 1, b - 1, k - 1) + 2);
			for(int i = a; i < b; i++) {
				if(str[i] == str[b]) {
					MAX(res, loop(i + 1, b - 2, k - 1) + 2);
					break;
				}
			}
			for(int i = b; i > a; i--) {
				if(str[i] == str[a]) {
					MAX(res, loop(a + 2, i - 1, k - 1) + 2);
					break;
				}
			}
		}
		return dp[a][b][k] = res;
	}
}

void solve() {
	memset(dp, -1, sizeof(dp));
	cin >> str >> K;
	N = sz(str);
	cout << loop(0, N - 1, K) << "\n";
}

int main() {
#ifndef LOCAL
	ios::sync_with_stdio(false);
    cin.tie(0);
#endif
    cout << fixed;
	cout.precision(20);
	srand((unsigned int)time(NULL));
#ifdef LOCAL
	//freopen("in.txt", "wt", stdout); //for tester
    freopen("in.txt", "rt", stdin);
#endif
	solve();
#ifdef LOCAL
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
	return 0;
}

#include <algorithm>
#include <cctype>
#include <cstring>
#include <cstdio>
using namespace std;
inline int read(int f = 1, int x = 0, char ch = ' ')
{
    while(!isdigit(ch = getchar())) if(ch == '-') f = -1;
    while(isdigit(ch)) x = x*10+ch-'0', ch = getchar();
    return f*x;
}
const int N = 3e2+5;
int n, m, f[N][N][N], ans; char s[N];
int main()
{
    scanf("%s", s+1), n = strlen(s+1), m = read();
    for(int i = 1; i <= n; ++i) f[0][i][i] = 1;
    for(int k = 0; k <= m; ++k)
        for(int l = 2; l <= n; ++l)
            for(int i = 1, j = l; j <= n; ++i, ++j)
            {
                f[k][i][j] = max(f[k][i+1][j], f[k][i][j-1]);
                if(s[i] == s[j]) f[k][i][j] = max(f[k][i][j], f[k][i+1][j-1]+2);
                if(k) f[k][i][j] = max(f[k][i][j], f[k-1][i+1][j-1]+2);
            }
    for(int i = 0; i <= m; ++i) ans = max(ans, f[i][1][n]);
    printf("%d\n", ans);
    return 0;
}


#include <cstdio>
using namespace std;

using int64 = long long;

int64 merge(int a[], int left, int mid, int right)
{
  int64 count = 0;
  int n1 = mid - left;
  int n2 = right - mid;
  int l[n1 + 1], r[n2 + 1];
  for (int i = 0; i < n1; i++)
    l[i] = a[left + i];
  for (int i = 0; i < n2; i++)
    r[i] = a[mid + i];
  l[n1] = 1000000001;
  r[n2] = 1000000001;

  int i = 0, j = 0;
  for (int k = left; k < right; k++)
  {
    if (l[i] <= r[j])
    {
      a[k] = l[i];
      i++;
    }
    else
    {
      a[k] = r[j];
      count += n1 - i;
      j++;
    }
  }

  return count;
}

int64 mergeSort(int a[], int left, int right)
{
  if (left + 1 < right)
  {
    int mid = (left + right) / 2;
    int64 v1 = mergeSort(a, left, mid);
    int64 v2 = mergeSort(a, mid, right);
    int64 v3 = merge(a, left, mid, right);
    return v1 + v2 + v3;
  }
  return 0;
}

int main()
{
  int n;
  scanf("%d", &n);

  int a[n];
  for (int i = 0; i < n; i++)
    scanf("%d", &a[i]);

  printf("%lld\n", mergeSort(a, 0, n));
  return 0;
}

#include <bits/stdc++.h>

using namespace std;

#define IO ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define ll long long int
#define ull unsigned long long int

const int INF = 1e9 + 7;
const int N = 1e5+5;

int main() {

	IO;

	int n;
	cin >> n;

	vector<int> a(n);

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

	int mn = a[0];
	int cnt = 1;

	for (int i = 1; i < n; ++i) {
		if (a[i] < mn) {
			++cnt;
			mn = a[i];
		}
	}

	cout << cnt;
}


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

int main(){
    int n, k;
    cin >> n >> k;
    vector<int> v(n);
    rep(i,n) cin >> v[i];
    int ans = 0;
    rep(i,n+1) for(int j = 0; j+i <= n; j++){
        if(i+j > k) continue;
        priority_queue<int,vector<int>,greater<int>> pq;
        if(i+j == 0) continue;
        rep(l,i) pq.push(v[l]);
        rep(l,j) pq.push(v[n-1-l]);
        rep(l,k-i-j) if(!pq.empty() && pq.top() < 0) pq.pop();
        int tmp = 0;
        while(!pq.empty()){
            tmp += pq.top();
            pq.pop();
        }
        ans = max(ans, tmp);
    }
    cout << ans << endl;
}

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

long long ara[57],dp[52][52][101];

long long solve(long long fr,long long sc,long long cap)
{

    if(sc<fr || cap==0)return 0;
    else if(dp[fr][sc][cap]!=-1)return dp[fr][sc][cap];
    else
    {

        long long p=-99999999999999;

        if(cap-1>=0)
        {
            p=max(p,ara[fr]+solve(fr+1,sc,cap-1));
            p=max(p,ara[sc]+solve(fr,sc-1,cap-1));
        }

        if(cap-2>=0)
        {

            p=max(p,solve(fr+1,sc,cap-2));
            p=max(p,solve(fr,sc-1,cap-2));
        }

        dp[fr][sc][cap]=p;  return dp[fr][sc][cap];

    }

}

int main()
{

        long long n,m,a,b,c,d,e,f,g,h,p,q,r,tr,sz,tz,i,j,k,mx=LLONG_MIN,mn=LLONG_MAX;
        long long x=0,y=0,cnt=0,res=0,ttl=0,ans=0,sum=0; long long flg=0,flag=1,na=0,as=1;
        vector<long long>u,v,w; vector< pair<long long,long long> >vct; vector<string>vst;
        set<long long>st,nt,tt; map<long long,long long>mp,nq,qr; string str,ttr,ntr;

        scanf("%lld %lld",&n,&k);

        for(i=1;i<=n;i++)
        {
            scanf("%lld",&a); ara[i]=a;

        }

        memset(dp,-1,sizeof dp);

        for(i=0;i<=k;i++)
        {
            ans=max(ans,solve(1,n,i));

        }

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

    return 0;
}


#include <iostream>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <map>
#include <unordered_map>
#include <set>
#include <deque>

int people[100005][4];
int sum[100005];

int main(){
  int N;
  scanf("%d", &N);
  std::vector<int > A(N);
  for (int i=0; i<N; i++){
    scanf("%d", &A[i]);
  }
  int prev=0;
  long long ans=0;
  if (A[0]!=0){
    std::cout << "-1" << std::endl;
    return 0;
  }
  for (int i=1; i<N; i++){
    if (A[i]>prev+1) {
      std::cout << "-1" << std::endl;
      return 0;
    } else if (A[i]==prev+1){
      ans++;
    } else {
      ans+=A[i];
    }
    prev = A[i];
  }
  std::cout << ans <<std::endl;
  return 0;
}

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

typedef long long ll;
typedef pair<ll, ll> P;

#define rep(i,n) for(ll (i)=0; (i)<(ll)(n); (i)++)
#define frep(i,m,n) for(ll (i)=(m); (i)<=(ll)(n); (i)++)
#define rrep(i,n) for(ll (i)=(n)-1; (i)>-1; (i)--)
#define frrep(i,m,n) for(ll (i)=(n); (i)>(ll)(m); (i)--)
#define ALL(x) (x).begin(), (x).end()

const ll INF = 100100100100100100;
const ll MOD = 1000000007;

// get abs
ll my_abs(ll a);
// a^n
ll a_n(ll a, ll n);
// get gcd
ll my_gcd(ll a, ll b);
// a^(-1) % MOD
ll inv(ll a);
// (a+b+c)%MOD
ll madd(ll a, ll b, ll c);
// (a-b)%MOD
ll msub(ll a, ll b);
// (a*b*c)%MOD
ll mtime(ll a, ll b, ll c);

int main() {
    ll n, ans = 0; cin >> n;
    vector<ll> a(n), b(n, 0);
    rep(i, n) cin >> a[i];
    if(a[0] != 0) {
        cout << -1 << endl;
        return 0;
    }
    else {
        rep(i, n-1) {
            if(a[i]+1 < a[i+1]) {
                cout << -1 << endl;
                return 0;
            }
        }
        rep(i, n) {
            b[i-a[i]]++;
        }
        ll index = 0;
        rep(i, n) {
            rep(j, b[i]) {
                a[index] = i;
                index++;
            }
        }
        set<ll> s;
        rep(i, n) {
            if(!s.count(a[n-1-i])) {
                s.insert(a[n-1-i]);
                ans += (n-1-i) - a[n-1-i];
            }
        }
        cout << ans << endl;
    }
    return 0;
}

ll my_abs(ll a) {
    if(a >= 0) return a;
    else return -1 *a;
}

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

    ll ret = a, count = 1;
    while(count * 2 < n) {
        ret *= ret;
        count *= 2;
    }
    if(count == n) return ret;
    else return (ret * a_n(a, n-count));
}

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

ll inv(ll a) {
    return a_n(a, MOD-2);
}

ll madd(ll a, ll b, ll c) {
    ll ret = (a+b) % MOD;
    return (ret+c) % MOD;
}

ll msub(ll a, ll b) {
    if(a < b) return (a-b+MOD) % MOD;
    else return (a-b) % MOD;
}

ll mtime(ll a, ll b, ll c) {
    ll ret = (a*b) % MOD;
    return (ret*c) % MOD;
}


#include<iostream>
#include<algorithm>
#include<functional>
#include<cmath>
#include<string>
#include<vector>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<deque>
using namespace std;
#define ll long long
const int mod = 1000000007;
const ll INF = 1000000000000000000;

bool isPrime[100010];
void set_prime() {
	for (int i = 1; i <= 100000; i++) {
		isPrime[i] = true;
	}
	isPrime[0] = false; isPrime[1] = false;
	for (int i = 2; i * i <= 100000; i++) {
		int j = 2;
		while (i * j <= 100000) {
			isPrime[i * j] = false;
			j++;
		}
	}
}

int main()
{
	int N;
	cin >> N;
	set_prime();
	int j = 2;
	for (int i = 0; i < N; i++) {
		while (true) {
			if (isPrime[j] && j % 5 == 1) {
				cout << j++ << " ";
				break;
			}
			j++;
		}
	}
	cout << endl;
}

#include <bits/stdc++.h>

using namespace std;

#define vt          vector
#define sz(x)       int((x).size())
#define all(x)      (x).begin(), (x).end()
#define rall(x)     (x).rbegin(), (x).rend()
#define fi          first
#define se          second

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

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

void solve() {
    int n;
    cin >> n;

    int num = 11;
    while (n--) {
        while (!is_prime(num)) num += 5;
        cout << num << ' ';
        num += 5;
    }
}

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

    int tcs = 1;
    for (int tc = 1; tc <= tcs; tc++) {
        // cout << "Case " << tc << ": ";
        solve();
    }
}


#include <iostream>
#include <math.h>

using namespace std;

int main() {
  double H, W, N;

  cin >> H >> W >> N;

  if (H > W) cout << ceil(N/H);
  else cout << ceil(N/W);

  return 0;
}

#include<stdio.h>
#include<iostream>
#include<vector>
#include<math.h>
#include<queue>
#include<map>
#include<algorithm>
#include<string.h>
#include<functional>
#include<limits.h>
#include<stdlib.h>
#include<string>
#include<unordered_map>
#include<set>
using namespace std;

#define intmax INT_MAX
#define lmax LONG_MAX
#define uintmax UINT_MAX
#define ulmax ULONG_MAX
#define llmax LLONG_MAX
#define ll long long
#define rep(i,a,N) for((i)=(a);(i)<(N);(i)++)
#define rrp(i,N,a) for((i)=(N)-1;(i)>=(a);(i)--)
#define llfor ll i,j,k
#define sc(a) cin>>a
#define pr(a) cout<<a<<endl
#define pY puts("YES")
#define pN puts("NO")
#define py puts("Yes")
#define pn puts("No")
#define pnn printf("\n")
#define sort(a) sort(a.begin(),a.end())
#define push(a,b) (a).push_back(b)
#define llvec vector<vector<ll>>
#define charvec vector<vector<char>>
#define sizeoof(a,b) (a,vector<ll>(b))
#define llpvec vector<pair<ll,ll>>
/*繰り上げ除算*/ll cei(ll x,ll y){ll ans=x/y;if(x%y!=0)ans++;return ans;}
/*最大公約数*/ll gcd(ll x,ll y){return y?gcd(y,x%y):x;}
/*最小公倍数*/ll lcm(ll x,ll y){return x/gcd(x,y)*y;}
/*n乗*/ll llpow(ll x,ll n){ll i,ans=1;rep(i,0,n)ans*=x;return ans;}
/*階乗*/ll fact(ll x){ll i,ans=1;rep(i,0,x)ans*=(x-i);return ans;}
/*nCr*/ll ncr(ll n,ll r){return fact(n)/fact(r)/fact(n-r);}
/*nPr*/ll npr(ll n,ll r){return fact(n)/fact(n-r);}
/*primejudge*/bool prime(ll a){if(a<=1)return false;ll i;for(i=2;i*i<=a;i++){if(a%i==0)return false;}return true;}
llfor;///////////////////////////////////////////////////////////
int main(){
 ll h,w,n;
 sc(h);sc(w);sc(n);
 ll a=max(h,w);
 a=cei(n,a);
 pr(a);
return 0;}


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

using namespace std;

int partition(int *A,int p,int r)
{
	int x,j,temp;

	x = A[r];
	j = p-1;

	for(int i = p; i < r; i++)
	{
		if (A[i] <= x)
		{
			j++;
			temp = A[j];
			A[j] = A[i];
			A[i] = temp;
		}
	}

	temp = A[j+1];
	A[j+1] = A[r];
	A[r] = temp;

	return j+1;
}

int main()
{
	int n,a[100000] = {0};
	int q;

	scanf("%d", &n);

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

	q = partition(a,0,n-1);

	for(int i = 0; i < n; i++)
	{
		if (i == q)
		{
			printf("[%d] ", a[i]);
		}else if (i == n-1)
		{
			printf("%d\n", a[i]);
		}else
		{
			printf("%d ", a[i]);
		}
	}

	return 0;
}

#include <bits/stdc++.h>

using namespace std;
using ll = long long;
using ld = long double;
using Vec = vector<int>;

int mod=1000000007;

bool IsPrime(int num)
{
    if (num < 2) return false;
    else if (num == 2) return true;
    else if (num % 2 == 0) return false;
    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            // 素数ではない
            return false;
        }
    }

    // 素数である
    return true;
}

int main(){

int n;
ll sum=0;
cin>>n;
Vec vec(n);
for(int i=0;i<n;i++){
    cin>>vec[i];
}
for(int i=0;i<n-1;i++){
  if(vec[i]>vec[i+1]){
      sum+=vec[i]-vec[i+1];
      vec[i+1]=vec[i];
  }

}
cout<<sum<<endl;

}


#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define str to_string
#define endl "\n"
#define PI 3.141592653589
using namespace std;
using lint = long long;
template <class T>ostream &operator<<(ostream &o,const vector<T>&v)
{o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}

//AC(*'ω'*)AC(*'ω'*)AC(*'ω'*)AC(*'ω'*)AC(*'ω'*)AC(*'ω'*)AC
int main(){
    string ans="",s;cin>>s;
    for(int i=0;i<s.size()-8;i++){
        ans+=s[i];
    }
    cout<<ans<<endl;
}

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

using namespace std;

typedef long long ll;

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

	string s;
	cin >> s;

	int n = s.size();
	cout << s.substr(0, n - 8) << endl;
}


#include<iostream>
using namespace std;

int main(){
  int a, ans;
  cin >> a;

  ans = a * (1 + a + a * a);
  cout << ans << endl;

  return 0;
}

//q1.cpp

#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>

#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>

#include <functional>
#include <cassert>

typedef long long ll;
using namespace std;

#define debug(x) cerr << #x << " = " << x << endl;

#define mod 1000000007 //1e9+7
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define SIZE 10000

int main(){

    int t[6];
    int ans = 0;

    for(int i=0;i<6;i++){
        scanf("%d",&t[i]);
        ans += t[i];
    }

    printf("%d\n",ans-min(min(t[0],t[1]),min(t[2],t[3]))-min(t[4],t[5]));

    return 0;
}


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

#define dump(...) cout<<"# "<<#__VA_ARGS__<<'='<<(__VA_ARGS__)<<endl
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define peri(i,a,b) for(int i=int(b);i-->int(a);)
#define rep(i,n) repi(i,0,n)
#define per(i,n) peri(i,0,n)
#define all(c) begin(c),end(c)
#define mp make_pair
#define mt make_tuple

using uint=unsigned;
using ll=long long;
using ull=unsigned long long;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using vd=vector<double>;
using vvd=vector<vd>;
using vs=vector<string>;

template<typename T1,typename T2>
ostream& operator<<(ostream& os,const pair<T1,T2>& p){
	return os<<'('<<p.first<<','<<p.second<<')';
}

template<typename Tuple>
void print_tuple(ostream&,const Tuple&){}
template<typename Car,typename... Cdr,typename Tuple>
void print_tuple(ostream& os,const Tuple& t){
	print_tuple<Cdr...>(os,t);
	os<<(sizeof...(Cdr)?",":"")<<get<sizeof...(Cdr)>(t);
}
template<typename... Args>
ostream& operator<<(ostream& os,const tuple<Args...>& t){
	print_tuple<Args...>(os<<'(',t);
	return os<<')';
}

template<typename Ch,typename Tr,typename C>
basic_ostream<Ch,Tr>& operator<<(basic_ostream<Ch,Tr>& os,const C& c){
	os<<'[';
	for(auto i=begin(c);i!=end(c);++i)
		os<<(i==begin(c)?"":" ")<<*i;
	return os<<']';
}

constexpr int INF=1e9;
constexpr int MOD=1e9+7;
constexpr double EPS=1e-9;

int getsum(const vvi& sums,int t,int b,int l,int r)
{
	if(l>=r || t>=b) return 0;
	return sums[b][r]-sums[t][r]-sums[b][l]+sums[t][l];
}

void chmax(int& a,int b)
{
	a=max(a,b);
}

int main()
{
	for(int h,w;cin>>h>>w && h|w;){
		vs grid(h);
		rep(i,h) cin>>grid[i];

		int ci=-1,cj=-1;
		rep(i,h) rep(j,w) if(grid[i][j]=='E') ci=i,cj=j;

		vvi sums(h+1,vi(w+1));
		rep(i,h) rep(j,w)
			sums[i+1][j+1]=(grid[i][j]=='o')+sums[i+1][j]+sums[i][j+1]-sums[i][j];

		int T=h-1-ci,B=ci,L=w-1-cj,R=cj;

		int dp[T+1][B+1][L+1][R+1]={};
		rep(t,T+1) rep(b,B+1) rep(l,L+1) rep(r,R+1){
			if(t!=T && ci+t+1<h-b)
				chmax(dp[t+1][b][l][r],dp[t][b][l][r]+getsum(sums,ci+(t+1),ci+(t+1)+1,max(cj-r,l),min(cj+l+1,w-r)));
			if(b!=B && t<=ci-(b+1))
				chmax(dp[t][b+1][l][r],dp[t][b][l][r]+getsum(sums,ci-(b+1),ci-(b+1)+1,max(cj-r,l),min(cj+l+1,w-r)));
			if(l!=L && cj+l+1<w-r)
				chmax(dp[t][b][l+1][r],dp[t][b][l][r]+getsum(sums,max(ci-b,t),min(ci+t+1,h-b),cj+(l+1),cj+(l+1)+1));
			if(r!=R && l<=cj-(r+1))
				chmax(dp[t][b][l][r+1],dp[t][b][l][r]+getsum(sums,max(ci-b,t),min(ci+t+1,h-b),cj-(r+1),cj-(r+1)+1));
		}

		int res=0;
		rep(t,T+1) rep(b,B+1) rep(l,L+1) rep(r,R+1) chmax(res,dp[t][b][l][r]);
		cout<<res<<endl;
	}
}

#include <iostream>
#include <algorithm>
#include <string>
#include <sstream>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstring>
#include <cmath>
#include <cstdio>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

typedef unsigned long long ull;

using namespace std;

int main() {
	int n, m;
	int ps[1000];
	for (;;) {
		cin >> n >> m;
		if (!(n | m))
			break;
		int ans = 0;
		REP(i,n) {
			cin >> ps[i];
			ans += ps[i];
		}
		if (n < m) {
			cout << ans << endl;
			continue;
		}
		sort(ps, ps + n, greater<int>());
		for (int i = m - 1; i < n; i += m) {
			ans -= ps[i];
		}
		cout << ans << endl;
	}
	return 0;
}


    #include<bits/stdc++.h>
    using namespace std;
    #define MAXN 400005
    #define MOD 998244353
    #define LL long long int
    LL ans,res,C[MAXN],fac[MAXN],revfac[MAXN];
    int n,m,k;
    LL qpow(LL a,int b)
    {
        LL tmp=1;
        while(b)
        {
            if(b&1)
            tmp=tmp*a%MOD;
            a=a*a%MOD;
            b>>=1;
        }
        return tmp;
    }
    void facrev()
    {
        C[0]=1;
        C[1]=(n-1);
        fac[1]=1;
        for(int i=2;i<=n;i++)
        {
            fac[i]=fac[i-1]*i%MOD;
            C[i]=C[i-1]*(n-i)%MOD;
        }
        revfac[n]=qpow(fac[n],MOD-2);
        for(int i=n-1;i>=1;i--)
        revfac[i]=revfac[i+1]*(i+1)%MOD,C[i]=C[i]*revfac[i]%MOD;
    }
    int main()
    {
        scanf("%d%d%d",&n,&m,&k);
        facrev();
        int p=n-k;
        res=m;
        for(int i=1;i<=p-1;i++)
        {
            res=res*(m-1)%MOD;
        }
        ans=res*C[p-1]%MOD;
        for(int j=p+1;j<=n;j++)
        {
            res=res*(m-1)%MOD;
            ans=(ans+res*C[j-1]%MOD)%MOD;
        }
        printf("%lld\n",ans);
        return 0;
    }

#include<bits/stdc++.h>
#define ll long long
#define re register
#define ull unsigned ll
using namespace std;
inline int read(){
	int s=0,t=1;
	char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')t=-1;ch=getchar();}
	while(ch>='0'&&ch<='9')s=(s<<3)+(s<<1)+(ch^48),ch=getchar();
	return s*t;
}
const int N=3e5+5;
const int P=1e9+7;
char s[N];
int n,Ans,f[N][3][3];
int Mod(int x){return x>=P?x-P:x;}
void Mod(int &x,int y){(x+=y)>=P?x-=P:0;}
int main(){
//	freopen(".in","r",stdin);
//	freopen(".out","w",stdout);
	scanf("%s",s+1),n=strlen(s+1);
	f[0][0][0]=1;
	for(int i=1,tp=0;i<=n;i++){
		for(int x=0;x<=2;x++)
		for(int y=0;y<=2;y++)
		if((tp=f[i-1][x][y])){
			if(s[i]!='0'){//1
				if(y==0)Mod(f[i][min(2,x+1)][0],tp);
				else Mod(f[i][x][y-1],tp);
			}
			if(s[i]!='1'){//0
				if(y==2)Mod(f[i][x][1],tp);
				else Mod(f[i][x][y+1],tp);
			}
		}
	}
	for(int x=0;x<=2;x++)
	for(int y=0;y<=2;y++)if(x>=y)Mod(Ans,f[n][x][y]);
	printf("%d",Ans);
	return 0;
}


#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define rrep2(ri,x,n) for(int ri = (int)(n-1); ri >= (int)(x); ri--)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(x) x.begin(), x.end()
using ll = long long;
using namespace std;

int main(){
  int n, x;
  cin >> n >> x;
  vector<int> a(n);
  rep(i, n) cin >> a.at(i);
  sort(ALL(a));
  int ans = 0;
  rep(i, n){
    if(i != n - 1){
      if(x > 0 && x - a.at(i) >= 0){
        ans++;
        x -= a.at(i);
      }else break;
    }else{
      if(x == a.at(i)) ans++;
    }
  }
  cout << ans << endl;
  return 0;
}

//Author:xht37
#include <bits/stdc++.h>

#define ui unsigned int
#define ll long long
#define ul unsigned ll
#define ld long double

#define pi pair <int, int>
#define fi first
#define se second
#define mp make_pair

#define ls (p << 1)
#define rs (ls | 1)
#define md ((t[p].l + t[p].r) >> 1)

#define vi vector <int>
#define pb push_back
#define pq priority_queue

#define dbg(x) cerr << #x" = " << x << endl
#define debug(...) fprintf(stderr, __VA_ARGS__)

#define fl(x) freopen(x".in", "r", stdin), freopen(x".out", "w", stdout)

using namespace std;

namespace io {
	const int SI = 1 << 21 | 1;
	char IB[SI], *IS, *IT, OB[SI], *OS = OB, *OT = OS + SI - 1, c, ch[100];
	int f, t;
	#define gc() (IS == IT ? (IT = (IS = IB) + fread(IB, 1, SI, stdin), IS == IT ? EOF : *IS++) : *IS++)
	inline void flush() {
		fwrite(OB, 1, OS - OB, stdout), OS = OB;
	}
	inline void pc(char x) {
		*OS++ = x;
		if (OS == OT) flush();
	}

	template <class I>
	inline void rd(I &x) {
		for (f = 1, c = gc(); c < '0' || c > '9'; c = gc()) if (c == '-') f = -1;
		for (x = 0; c >= '0' && c <= '9'; x = (x << 3) + (x << 1) + (c & 15), c = gc());
		x *= f;
	}
	template <class I>
	inline void rd(I &x, I &y) {
		rd(x), rd(y);
	}
	template <class I>
	inline void rd(I &x, I &y, I &z) {
		rd(x), rd(y), rd(z);
	}
	template <class I>
	inline void rda(I *a, int n) {
		for (int i = 1; i <= n; i++) rd(a[i]);
	}
	inline void rdc(char &c) {
		for (c = gc(); c < 33 || c > 126; c = gc());
	}
	inline void rds(char *s, int &n) {
		for (c = gc(); c < 33 || c > 126; c = gc());
		for (n = 0; c >= 33 && c <= 126; s[++n] = c, c = gc());
		s[n+1] = '\0';
	}
	inline void rds(string &s) {
		for (c = gc(); c < 33 || c > 126; c = gc());
		for (s.clear(); c >= 33 && c <= 126; s.pb(c), c = gc());
	}

	template <class I>
	inline void print(I x, char k = '\n') {
		if (!x) pc('0');
		if (x < 0) pc('-'), x = -x;
		while (x) ch[++t] = x % 10 + '0', x /= 10;
		while (t) pc(ch[t--]);
		pc(k);
	}
	template <class I>
	inline void print(I x, I y) {
		print(x, ' '), print(y);
	}
	template <class I>
	inline void print(I x, I y, I z) {
		print(x, ' '), print(y, ' '), print(z);
	}
	template <class I>
	inline void printa(I *a, int n) {
		for (int i = 1; i <= n; i++) print(a[i], " \n"[i==n]);
	}
	inline void printc(char c) {
		pc(c);
	}
	inline void prints(char *s, int n) {
		for (int i = 1; i <= n; i++) pc(s[i]);
		pc('\n');
	}
	inline void prints(string s) {
		int n = s.length();
		while (t < n) pc(s[t++]);
		pc('\n'), t = 0;
	}
	struct Flush {
		~Flush() {
			flush();
		}
	} flusher;
}
using io::rd;
using io::rda;
using io::rdc;
using io::rds;
using io::print;
using io::printa;
using io::printc;
using io::prints;

const int N = 107;
int n, x, a[N], s;

int main() {
	rd(n, x), rda(a, n);
	sort(a + 1, a + n + 1);
	for (int i = 1; i <= n; s += a[i++])
		if (s + a[i] > x) return print(i - 1), 0;
	print(n - (s != x));
	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;
#define rep(i,a,b) for(ll i=a ; i<b ; i++)
const int max_n = 1e5;
const ll mod = 1e9+7;
const ll INF = 1LL<<60;
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; }
int dx[4] = {0,0,1,-1};
int dy[4] = {1,-1,0,0};
ll gcd(ll a, ll b) { return a ? gcd(b%a, a) : b; }
bool betemp(string sleft, string sright, int left, int right){
  if(sleft==sright){
    return (right-left)%2 == 1;
  }else{
    return (right-left)%2 == 0;
  }
}
void solve(int N){
  string vct = "Vacant";
  string sleft, sright, str;
  int left=0, right=N/2;
  cout << left << endl;
  cin >> sleft;
  if(sleft==vct) return ;
  cout << right << endl;
  cin >> sright;
  if(sright==vct) return ;
  if(!betemp(sleft, sright, left, right)){
    swap(sleft, sright), left = right, right = N;
  }
  while(left+1<right){
    int mid = (left+right)/2;
    cout << mid << endl;
    cin >> str;
    if(str==vct) return;
    if(betemp(sleft, str, left, mid)){
      sright = str, right = mid;
    }else{
      left = mid, sleft = str;
    }
  }
}
int main(){
  int N;
  while(cin>>N) solve(N);
  return 0;
}

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

int dp[31];

int main() {
    dp[0] = 1;
    for (int i=1; i<31; ++i) {
        int sum = 0;
        for (int j=i-1; j>=i-3 && j>=0; --j) {
            sum += dp[j];
        }
        dp[i] = sum;
    }
    int n;
    while (cin >> n, n) {
        if (dp[n] % 3650 == 0) {
            cout << dp[n] / 3650 << endl;
        } else {
            cout << dp[n] / 3650 + 1 << endl;
        }
    }
    return 0;
}


#include<bits/stdc++.h>
#define MOD 1000000007
#define mp make_pair
#define ll long long
#define pb push_back
#define faster ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define debug cout<<"Debugging.."<<endl
using namespace std;
int main()
{
	faster;

		ll int n;
		cin>>n;

		int a=pow(n,2);
		int b=pow(n,3);
		cout<<a+b+n;

}

#include <iostream>

int main() {
  int a; std::cin >> a;
  int sum = a;
  sum += a*a + a*a*a;
  std::cout << sum << std::endl;

  return 0;
}


#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define _USE_MATH_DEFINES
#include <math.h>
#define NIL = -1;
#define all(x) x.begin(),x.end()
const ll INF = 1e9;
const ll INFL = 1e18;
const ll mod = 1e9 + 7;

int digit(ll x) {
    int digits = 0;

    while(x > 0){
        x /= 10;
        digits++;
    }

    return digits;
}

ll gcd(long long a,long long b) {
    if (a < b) swap(a,b);
    if (b == 0) return a;

    return gcd(b,a%b);
}

bool is_prime(long long N){
    if (N == 1) return false;
    for (long long i = 2;i * i <= N;i++){
        if (N % i == 0) return false;
    }
    return true;
}

ll lcm(ll a,ll b){
    return ((a * b == 0)) ? 0 : (a / gcd(a,b) * b);
}

double DegreeToRadian(double degree){
    return degree * M_PI / 180.0;
}

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

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

int main(){
    long long n;
    cin >> n;
    int ans = digit(n);
    for (long long i = 1LL;i * i <= n;i++){
        if (n % i != 0) continue;
        long long b = n / i;

        int res = max(digit(i), digit(b));

        if (ans > res){
            ans = res;
        }
    }

    cout << ans << endl;
}

#include <bits/stdc++.h>
#define pb push_back
#define cmin(a,b) (a>b?a=b:a)
#define cmax(a,b) (a<b?a=b:a)
#define lop(i,s,t) for(int i=s;i<(t);++i)
#define rep(i,s,t) for(int i=s;i<=(t);++i)
#define dec(i,s,t) for(int i=s;i>=(t);--i)
#define fore(i,v) for(int i=g[v],d=es[i].d;i;i=es[i].nxt,d=es[i].d)
using namespace std;

#define Pr(f,...) //fprintf(stderr,f,##__VA_ARGS__),fflush(stderr)

const int N=5e5+50;

void read(int &x){
	x=0;
	char c=getchar();
	for(;!isdigit(c);c=getchar());
	for(;isdigit(c);c=getchar())x=x*10+c-'0';
}

int n,a[N],odd,even,exist;

int gcd(int a,int b){ return !b?a:gcd(b,a%b); }

void maintain(){
	int g=a[1];
	rep(i,2,n)g=gcd(g,a[i]);
	rep(i,1,n)a[i]/=g;
	odd=even=exist=0;
	rep(i,1,n){
		odd+=a[i]%2==1;
		even+=a[i]%2==0;
		exist|=a[i]==1;
	}
}

int main(int argc,char *argv[]){
#ifdef CURIOUSCAT
	//freopen("dat.in","r",stdin);
	//freopen("my.out","w",stdout);
#endif
	read(n);
	rep(i,1,n)read(a[i]);
	int cur=1,win;
	do{
		maintain();
		rep(i,1,n)Pr("%d ",a[i]);Pr("\n");
		if(even%2==1){
			win=cur;
			break;
		}else if(odd>1){
			win=!cur;
			break;
		}else{
			if(exist){
				win=!cur;
				break;
			}
			rep(i,1,n)a[i]/=2;
		}
		cur=!cur;
	}while(true);
	puts(win==1?"First":"Second");
}


#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define PI 3.1415926535897932
#define MOD 1000000007;
using namespace std;
long long GCD(long long A,long long B){
  if(B==0){
    return A;
  }
  else{
    return GCD(B,A%B);
  }
}
long long LCM(long long A,long long B){
  long long g=GCD(A,B);
  return A/g*B;
}
long long num_order(long long X){
  long long ans=0;
  while(true){
    if(X==0){
      break;
    }
    else{
      X/=10;
      ans++;
    }
  }
  return ans;
}
int main() {

  int A,B,C;
  cin>>A>>B>>C;

  if((A<C&&C<B)||(B<C&&C<A)){
    cout<<"Yes"<<endl;
  }
  else{
    cout<<"No"<<endl;
  }
}

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int gcd(int a, int b) {
  return b != 0 ? gcd(b, a % b) : a;
}//MAX
int lcm(int a, int b) {
   return a * b / gcd(a, b);
   }
//MIN

 main() {
int n,h,w;
cin >> n >> h >> w;
cout << (n-w+1)*(n-h+1)<<endl;
 }


#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define perl(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define pb push_back
#define ins insert
#define pqueue(x) priority_queue<x,vector<x>,greater<x>>
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
#define vtpl(x,y,z) vector<tuple<x,y,z>>
#define rev(x) reverse(x);
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
using vpl=vector<pl>;
using vvpl=vector<vpl>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9+10;
const ll INF=4e18;
const ll dy[8]={1,0,-1,0,1,1,-1,-1};
const ll dx[8]={0,-1,0,1,1,-1,1,-1};
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
int main(){
    ll n,q;cin >> n >>q;
    vector<pair<ll,pl>> w(n);
    rep(i,n){
        cin >> w[i].se.fi>>w[i].se.se>>w[i].fi;
        w[i].se.fi-=w[i].fi;
        w[i].se.se-=w[i].fi+1;
    }
    sort(all(w));
    vector<ll> que(q),ans(q);
    rep(i,q)cin >> que[i];
    set<ll> st;rep(i,q)st.ins(que[i]);
    rep(i,n){
        auto p=st.lower_bound(w[i].se.fi);
        if(p==st.end())continue;
        while(*p<=w[i].se.se){
            ll id=lower_bound(all(que),*p)-que.begin();
            ans[id]=w[i].fi;p=st.erase(p);
            if(p==st.end())break;
        }
    }
    rep(i,q){
        if(ans[i])cout << ans[i] <<endl;
        else cout << -1 <<endl;
    }
}

#include<bits/stdc++.h>
using namespace std;
int main(){
  int N, Q;
  cin >> N >> Q;
  vector<vector<int>> vec(N,vector<int>(3));
  for(int i=0; i<N; i++){
    for(int j=0; j<3; j++){
      cin >> vec.at(i).at(j);
    }
  }
  vector<int> query(Q+2,-1e9);
  for(int i=1; i<=Q; i++){
    cin >> query.at(i);
  }
  query.at(Q+1) = 1e9+10;
  vector<vector<int>> in(Q+2,vector<int>(0));
  vector<vector<int>> out(Q+2,vector<int>(0));

  vector<int>::iterator pos;
  int idx;
  for(int i=0; i<N; i++){
    int s = vec.at(i).at(0);
    int e = vec.at(i).at(1);
    int p = vec.at(i).at(2);
    pos = lower_bound(query.begin(),query.end(),s-p);
    idx = distance(query.begin(),pos);
    in.at(idx).push_back(p);
    pos = lower_bound(query.begin(),query.end(),e-p);
    idx = distance(query.begin(),pos);
    out.at(idx).push_back(p);
  }

  map<int,int> mp;
  mp[1e9+10] = 1;
  for(int i=0; i<Q+1; i++){
    for(int j=0; j<in.at(i).size(); j++){
      if(mp.count(in.at(i).at(j))){
        mp[in.at(i).at(j)]++;
      }
      else{
        mp[in.at(i).at(j)] = 1;
      }
    }
    for(int j=0; j<out.at(i).size(); j++){
      mp[out.at(i).at(j)]--;
      if(mp[out.at(i).at(j)] == 0){
        mp.erase(out.at(i).at(j));
      }
    }
    if(i != 0){
      int x = mp.begin()->first;
      if(x == 1e9+10){
        cout << -1 << endl;
      }
      else{
        cout << x << endl;
      }
    }
  }
}


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

int f(int x){
  if(x < 0){x *= (-1);}
  return x;
}

int main(){
  int n; cin >> n;
  vector<int> v(n+10, 0);
  int time = 0;
  for(int i = 1; i <= n; i++){
    cin >> v[i];
    time += f(v[i] - v[i-1]);
  }
  time += f(v[n]);

  for(int i = 1; i <= n; i++){
    int res = time;
    if(v[i+1] >= v[i] && v[i] >= v[i-1]){cout << res << endl; continue;}
    else if(v[i+1] <= v[i] && v[i] <= v[i-1]){cout << res << endl; continue;}
    else if((v[i] - v[i-1]) * (v[i+1] - v[i-1]) <= 0){
      res -= f(v[i-1] - v[i]) * 2; cout << res << endl; continue;
      }
    else{res -= f(v[i+1] - v[i]) * 2; cout << res << endl; continue;}
  }
}

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i, n) for (ll i = 0; i < n; i++)
#define rep_r(i, n) for (ll i = n - 1; i >= 0; i--)
#define all(x) x.begin(),x.end()
#define resize(x, n) x.resize(n)
using pll = pair<ll, ll>;
using vl = vector<ll>;
using vvl = vector<vl>;
const ll INF = 1000000000000000000;
const ll mod = 1000000007;
const ll MAX = 100000;
struct edge {
    ll from, to, weight;
    edge(ll f, ll t, ll w) : from(f), to(t), weight(w) { }
};
vector<vector<edge>> edges;
vector<vector<ll>> graph;
vector<bool> visited;
int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
ll n, sum;
vl a;

ll cost(ll i) {
    return sum - abs(a[i-1]-a[i]) - abs(a[i]-a[i+1]) + abs(a[i-1]-a[i+1]);
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> n;
    resize(a, n+2);
    rep(i, n+2) {
        if (i == 0 || i == n+1) a[i] = 0;
        else cin >> a[i];
        if (i > 0) sum += abs(a[i-1]-a[i]);
    }
    rep(i, n+1) {
        if (i == 0) continue;
        printf("%ld\n", cost(i));
    }
}


#include<bits//stdc++.h>
using namespace std;
int main(){
	int m,minn,maxn;
	while(cin>>m>>minn>>maxn&&m!=0){
		int a[200];
		for(int i=0;i<m;i++){
			cin>>a[i];
		}
		sort(a,a+m);
		reverse(a,a+m);
		int go=-1;
		int n=0;
		for(int i=minn;i<=maxn;i++){
			if(go<a[i-1]-a[i]){
				go=a[i-1]-a[i];
				n=i;
			}
			else if(go==a[i-1]-a[i]){
				n=i;
			}
		}
		cout<<n<<endl;
	}
}

#include<iostream>
using namespace std;
int main(){
	int n,a,b,c=0,max=0,x;
	cin >> n;
	if(n==2)cin >> a >> b ;
	else if(n==3)cin >> a >> b >> c ;
	if(n==2){
		if(a<b){
			x=a;a=b;b=x;
		}
	}
	if(n==3){
		if(a<b){
			x=a;a=b;b=x;
		}
		if(b<c){
			x=b;b=c;c=x;
		}
		if(a<b){
			x=a;a=b;b=x;
		}
	}
	for(int i=0;i<a;i++){
		if(a%(i+1)==0&&b%(i+1)==0&&c%(i+1)==0){
			cout << i+1 <<endl;
		}

	}
	return 0;
}


//#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <stack>
#include <set>
#include <queue>
#include <algorithm>
#include <cmath>
#include <string>
#include <map>
using namespace std;
typedef long long ll;
#define free  freopen ("input.txt", "r", stdin);freopen ("output.txt", "w", stdout);
#define Fast  ios::sync_with_stdio(false); cin.tie(0);
#define pb push_back
#define mp make_pair
#define F first
#define S second

bool vowel(char che)
{
    if (che == 'A' || che == 'E' || che == 'I' || che == 'O' || che == 'U' || che == 'Y')
        return true;
    else
        return false;
}

const int N = 1e6+5;
const int mod = 1e9+7;
ll a[N], b[N], c[N], d, dp[N], dis;
//pair <ll, ll> p[N], p1[N];
char o;
bool mark[N], h;
string s;
//stack <int> st;
//set <ll> st1, st2;
//deque <int> dq;
//vector <ll> vm, vp, vt[N];
//int a1[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};

int main()
{
    Fast
    ll t, n, m, k = 0, f = 0, sum = 0, ans = 0;
    cin >> n >> m >> k;
    f = (n+k-1)/k;
    if (m >= f)
        cout << "Yes\n";
    else
        cout << "No\n";
}

#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
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;}

int main(){
  double d,t,s;
  cin >> d >> t >> s;
  if ((double)d / s <= t) cout << "Yes" << endl;
  else cout << "No" << endl;
}


#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <iostream>
#include <algorithm>
#define MOD 998244353
using namespace std;
typedef long long ll;

template <typename Tp> inline void getint(Tp &num){
	register int ch, neg = 0;
	while(!isdigit(ch = getchar())) if(ch == '-') neg = 1;
	num = ch & 15;
	while(isdigit(ch = getchar())) num = num * 10 + (ch & 15);
	if(neg) num = -num;
}

inline int fastpow(int bas, int ex){
	register int res = 1;
	for(; ex; ex >>= 1, bas = bas * (ll)bas % MOD) if(ex & 1) res = res * (ll)bas % MOD;
	return res;
}

inline int kazu(int a, const int &b) {return (a += b) >= MOD ? a - MOD : a;}
inline int hiku(int a, const int &b) {return (a -= b) < 0 ? a + MOD : a;}

int N, sum = 0, f[90005], g[90005];

int main(){
	getint(N), f[0] = g[0] = 1;
	for(register int i = 1, a; i <= N; i++){
		getint(a), sum += a;
		for(register int j = sum; j >= 0; j--){
			f[j] = f[j] * 2LL % MOD;
			if(j >= a) f[j] = kazu(f[j], f[j - a]), g[j] = kazu(g[j], g[j - a]);
		}
	}
	int ans = fastpow(3, N);
	for(register int i = sum + 1 >> 1; i <= sum; i++) ans = hiku(ans, f[i] * 3LL % MOD);
	if(!(sum & 1)) ans = kazu(ans, g[sum >> 1] * 3LL % MOD);
	return printf("%d\n", ans), 0;
}


#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> P;
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; }

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll n, mod = 1;
	cin >> n;
	if(n == 0){
		cout << 0 << endl;
		return 0;
	}
	string ans = "";
	while(n != 0){
		ll nex = mod * (-2);
		ll hoge = (n % nex != 0);
		ans += to_string(hoge);
		n -= hoge * mod;
		mod = nex;
	}
	reverse(ans.begin(), ans.end());
	cout << ans << endl;
	return 0;
}

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

int main() {
    vector<bool> a(26,false);
    string s; cin >> s;
    if(s.size()<26){
        for(int i = 0; i < s.size(); i++) {
            a[(int)s[i]-97]=true;
        }
        for(int i = 0; i < 26; i++) {
            if(a[i]==false){
                s += (char)(97+i);
                cout << s << endl;
                return 0;
            }
        }
    }
    else{
        if(s=="zyxwvutsrqponmlkjihgfedcba"){
            cout << -1 << endl;
            return 0;
        }
        string t=s;
        string ans;
        next_permutation(t.begin(),t.end());
        for(int i = 0; i < 26; i++) {
            ans += t[i];
            if(s[i]!=t[i]) break;
        }
        cout << ans << endl;

    }

    return 0;
}


#include<bits/stdc++.h>

#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define int long long
#define rep(i,a,b)    for(int i=a;i<b;i++)
#define repn(i,a,b)   for(int i=a;i>=b;i--)
#define F first
#define S second
#define pii pair<int,int>
#define vi vector<int>
#define vii vector<pii>
#define pb push_back
#define mp  make_pair
#define all(v) (v).begin(), (v).end()
#define mod 998244353
#define inf 1e18

using namespace std;
int gcd(int a, int b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);

}
signed main()
{
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output1.txt", "w", stdout);
    #endif

    IOS;
    int n,i,j,k;
    cin>>n;
    string s;
    cin>>s;
    vi r,g,b;
    for(i=0;i<n;i++)
    {
        if(s[i]=='R') r.pb(i);
        else if(s[i]=='G') g.pb(i);
        else b.pb(i);
    }
    int ans=0;
    for(i=0;i<n;i++)
    {
        for(j=i+1;j<n;j++)
        {
            if(s[i]==s[j]) continue;
            int x=0,y=0,z=0;
            if(s[i]=='R'||s[j]=='R') x++;
            if(s[i]=='G'||s[j]=='G') y++;
            if(s[i]=='B'||s[j]=='B') z++;
            // cout<<x<<" "<<y<<" "<<z<<endl;
            if(x==0)
            {
                auto it=upper_bound(r.begin(),r.end(),j);
                ans+=r.end()-it;
                int num=j+j-i;
                auto it1=lower_bound(r.begin(),r.end(),num);
                if(it1!=r.end()&&*it1==num) ans--;
            }
            else if(y==0)
            {
                auto it=upper_bound(g.begin(),g.end(),j);
                ans+=g.end()-it;
                int num=j+j-i;
                auto it1=lower_bound(g.begin(),g.end(),num);
                if(it1!=g.end()&&*it1==num) ans--;
            }
            else
            {
                auto it=upper_bound(b.begin(),b.end(),j);
                ans+=b.end()-it;
                int num=j+j-i;
                auto it1=lower_bound(b.begin(),b.end(),num);
                if(it1!=b.end()&&*it1==num) ans--;
            }
        }
    }
    cout<<ans;
}

#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <functional>
#include <queue>
#include <set>
#include <map>
#include <numeric>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cctype>

#define rep(i, a) REP(i, 0, a)
#define REP(i, a, b) for(int i = a; i < b; ++i)

typedef long long ll;
typedef unsigned long long ull;
typedef std::pair<int, int> P;
typedef std::pair<P, int> PP;
const double PI = 3.14159265358979323846;
const double esp = 1e-9;
const int infi = (int)1e+9 + 10;
const ll infll = (ll)1e+17 + 10;

int n;
int a[101];

int calc(){
	int ret = 0;
	rep(i, n - 1){
		rep(j, n - 1){
			if (a[j] > a[j + 1])++ret, std::swap(a[j], a[j + 1]);
		}
	}
	return ret;
}

int main(){
	std::cin >> n;
	rep(i, n)std::cin >> a[i];
	int ans = calc();
	std::cout << a[0];
	REP(i, 1, n)std::cout << " " << a[i];
	std::cout << std::endl;
	std::cout << ans << std::endl;
	return 0;
}


#include <iostream>
#include <algorithm>
#include <complex>
#include <utility>
#include <vector>
#include <string>
#include <queue>
#include <tuple>
#include <cmath>
#include <bitset>
#include <cctype>
#include <set>
#include <numeric>
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(ll i=ll(a);i<ll(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define PRINT(V) cout << V << "\n"
#define SORT(V) sort((V).begin(),(V).end())
#define RSORT(V) sort((V).rbegin(), (V).rend())
using namespace std;
using ll = long long;
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; }
inline bool Yes(bool condition){ if(condition) PRINT("Yes"); else PRINT("No"); }
template<class itr> void cins(itr first,itr last){
    for (auto i = first;i != last;i++){
        cin >> (*i);
    }
}
template<class itr> void array_output(itr start,itr goal){
    string ans = "";
    for (auto i = start;i != goal;i++) ans += to_string(*i)+" ";
    if (!ans.empty()) ans.pop_back();
    PRINT(ans);
}
ll gcd(ll a, ll b) {
    return a ? gcd(b%a,a) : b;
}
const ll INF = 1e17;
const ll MOD = 1000000007;
typedef pair<ll,ll> P;
const ll MAX = 200005;
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n,q;
    cin >> n >> q;
    set<ll> num;
    vector<vector<ll>> event;
    ll s,t,x;
    rep(i,n){
        cin >> s >> t >> x;
        vector<ll> a1{s-x,1,x},a2{t-x,-1,x};
        event.push_back(a1);
        event.push_back(a2);
    }
    SORT(event);
    vector<ll> d(q);
    ll index = 0;
    cins(all(d));
    rep(i,2*n){
        while(d[index] < event[i][0] && index < q){
            if (num.empty()) PRINT(-1);
            else PRINT(*num.begin());
            index++;
        }
        if (index == q) break;
        if (event[i][1] == 1) num.insert(event[i][2]);
        if (event[i][1] == -1) num.erase(event[i][2]);
    }
    rep(_,index,q) PRINT(-1);
    return 0;
}

#include <bits/stdc++.h>

using namespace std;

#ifndef ONLINE_JUDGE
	#define W(x, y) cerr << "\033[31m" << #x << " = " << x << "\033[0m" << y;
#else
	#define W(x, y)
#endif

using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vii = vector<pii>;
using vl = vector<ll>;
using vll = vector<pll>;
using ld = long double;
#define ff first
#define ss second
const ld pi = acosl(-1);
const ll prime = 1000000000 + 7;
const ll INF = 1000000000;

struct UnionFind{
    vl pai;
    vl rank;
    vl sum;
    UnionFind(ll n): pai(n), rank(n), sum(n){
        iota(pai.begin(), pai.end(), 0);
        fill(rank.begin(), rank.end(), 1);
        fill(sum.begin(), sum.end(), 1);
    }
    ll Find(ll x){
        if(x == pai[x]){
            return x;
        }
        return pai[x] = Find(pai[x]);
    }
    void Union(ll a, ll b){
        a = Find(a);
        b = Find(b);
        if(a == b){
            return;
        }
        if(rank[a] == rank[b]){
            rank[a]++;
        }
        if(rank[a] < rank[b]){
            sum[b] += sum[a];
            pai[a] = b;
        } else{
            sum[a] += sum[b];
            pai[b] = a;
        }
    }
};

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

    ll n, q;
    while(cin >> n >> q){
        vector<tuple<ll, ll, ll>> vet(n);
        map<ll, ll> conj;
        vl res(q, -1);
        for(int i = 0; i < n; ++i){
            ll s, t, x;
            cin >> s >> t >> x;
            vet[i] = make_tuple(x, s, t);
        }
        sort(vet.begin(), vet.end(), [](tuple<ll, ll, ll>a, tuple<ll, ll, ll>b){
            ll as, at, ax;
            tie(ax, as, at) = a;
            ll bs, bt, bx;
            tie(bx, bs, bt) = b;
            if(ax == bx){
                return as < bs;
            }
            return ax < bx;
        });
        for(int i = 0; i < q; ++i){
            ll d;
            cin >> d;
            conj[d] = i;
        }
        vector<ll> aux;
        for(int i = 0; i < n; ++i){
            ll s, t, x;
            tie(x, s, t) = vet[i];
            auto it1 = conj.lower_bound(s-x);
            if(it1 != conj.end()){

            }
            auto it2 = conj.lower_bound(t-x);
            if(it2 != conj.begin()){
                it2;
            }
            for(; it1 != it2; ++it1){
                res[it1->ss] = x;
                aux.push_back(it1->ff);
            }
            while(aux.size()){
                conj.erase(aux.back());
                aux.pop_back();
            }
        }

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

    return 0;
}


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

using namespace std;

struct data_t {
	string name;
	double eff;

	bool operator<(const data_t& right) const {
		if (eff == right.eff) {
			return (name < right.name);
		}
		else {
			return (eff > right.eff);
		}
	}
};

int main(void) {
	int N;
	while (cin >> N, N) {
		vector<data_t> data(N);
		int p,temp,d,e,f,m,s;
		for (int i = 0; i < N; ++i) {
			cin >> data[i].name;
			cin >> p;
			int time = 0;
			for (int i = 'A'; i <= 'C'; ++i) {
				cin >> temp;
				time += temp;
			}
			cin >> d >> e >> f >> s >> m;
			time += m * (d + e);
			data[i].eff = (double)((f * m * s) - p)/(double)time;
		}

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

		for (int i = 0; i < N; ++i) {
			cout << data[i].name << endl;
		}
		cout << "#" << endl;
	}
	return 0;
}

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

typedef ostringstream OSS; typedef istringstream ISS;
typedef long long LL;
typedef pair<int, int> PII;  typedef pair<LL, LL> PLL;
typedef vector<int>    VI;   typedef vector<VI>   VVI;   typedef vector<VVI>   VVVI;
typedef vector<LL>     VLL;  typedef vector<VLL>  VVLL;  typedef vector<VVLL>  VVVLL;
typedef vector<double> VD;   typedef vector<VD>   VVD;   typedef vector<VVD>   VVVD;
typedef vector<string> VS;   typedef vector<VS>   VVS;   typedef vector<VVS>   VVVS;
typedef vector<bool>   VB;   typedef vector<VB>   VVB;   typedef vector<VVB>   VVVB;
typedef vector<PII>    VPII; typedef vector<VPII> VVPII; typedef vector<VVPII> VVVPII;
typedef vector<PLL>    VPLL; typedef vector<VPLL> VVPLL; typedef vector<VVPLL> VVVPLL;

typedef unsigned int  UI;
typedef vector<UI>    VUI;
typedef vector<VUI>   VVUI;

#define fst first
#define snd second
// #define Y first
// #define X second
#define MP make_pair
#define PB push_back
#define EB emplace_back
#define ALL(x)  (x).begin(),(x).end()
#define RALL(x) (x).rbegin(),(x).rend()
#define RANGEBOX(x,y,maxX,maxY) (0 <= (x) && 0 <= (y) && (x) < (maxX) && (y) < (maxY))
#define RANGE(x, l, r) ((l) <= (x) && (x) <= (r))
#define rep(i, N)  for (int i = 0; i < (int)(N); i++)
#define rrep(i, N) for (int i = N - 1; i >= 0; i--)
#define REP(i, init, N)  for (int i = (init); i < (int)(N); i++)
#define RREP(i, N, last) for (int i = (init - 1); i >= last; i--)
#define MAXUD(orig, target) orig = max(orig, target)
#define MINUD(orig, target) orig = min(orig, target)
#define DUMP( x ) cerr << #x << " = " << ( x ) << endl

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

template<typename T=int> inline void dump(vector<T> vs, bool ent=false) { rep(i, vs.size()) cout << vs[i] << (i+1==vs.size() ? '\n' : ' '); if (ent) cout << endl; }
template<typename T = int> inline void dump(vector<vector<T>> vs, bool ent = false) { rep(i, vs.size()) dump<T>(vs[i]); if (ent) cout << endl; }

const int    INF  = 0x3f3f3f3f;
const LL     INFL = 0x3f3f3f3f3f3f3f3fLL;
const double DINF = 0x3f3f3f3f;
const int    DX[] = {1,  0, -1, 0};
const int    DY[] = {0, -1,  0, 1};
const double EPS  = 1e-12;
// const double PI   = acos(-1.0);
// lambda: [](T1 x)->T2{return y;}
// simple lambda: [](T x){return x;}

void solve(int n) {
    VS names(n);
    VI ps(n);
    VI ts1(n);
    VI ts2(n);
    VI fs(n);
    VI ss(n);
    VI ms(n);

    rep(i, n) {
        cin >> names[i] >> ps[i];
        VI as(5);
        rep(j, 5) cin >> as[j];
        ts1[i] = accumulate(ALL(as), 0);
        ts2[i] = as[3] + as[4];
        cin >> fs[i] >> ss[i] >> ms[i];
    }

    VD scores(n);
    rep(i, n) {
        scores[i] = 1. * (fs[i] * ms[i] * ss[i] - ps[i]) / (ts1[i] + (ms[i] - 1) * ts2[i]);
    }

    vector<pair<double, string>> xs(n);
    rep(i, n) xs[i] = MP(scores[i], names[i]);
    sort(ALL(xs), [](pair<double, string> a, pair<double, string> b){
            if (abs(a.fst - b.fst) > EPS) return a.fst > b.fst;
            return a.snd < b.snd;
    });

    for (auto x : xs) cout << x.snd << endl;
    cout << "#" << endl;

}

int main(void) {
    int n;
    while (cin >> n, n) solve(n);

    return 0;
}


#include <iostream>
#include <cstring>
#include <map>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <set>
#include <vector>
#include <queue>
#include <list>
#include <numeric>
#include <stdio.h>
#include <string>
#include <cstdlib>
#include <math.h>
#include <stack>
#include <climits>
#include <bitset>
#include <utility>

using namespace std;
typedef long long ll;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
// const ll INF = 1LL <<60;
const int INF = 10000;

//最大公約数
ll gcd(ll x, ll y) {
  ll tmp = 0;
  if (x < y){
    tmp=x;
    x=y;
    y=tmp;
  }
  while (y > 0) {
    ll r = x % y;
    x = y;
    y = r;
  }
  return x;
}

//最大公倍数
ll lcm(ll x,ll y){
  return x/gcd(x,y)*y;
}

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

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

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

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

//階乗
ll kaijo(ll k){
    ll sum = 1;
    for (ll i = 1; i <= k; ++i)
    {
        sum *= i;
        sum%=1000000000+7;
    }
    return sum;
}

//for(int i = ; i < ; i++){}

ll lmax(ll s,ll t){
  if(s>t){
    return s;
  }
  else{
    return t;
  }
}

ll lmin(ll s,ll t){
  if(s<t){
    return s;
  }
  else{
    return t;
  }
}
// ここから開始

int main(){
 int n,k;
 cin>>n>>k;
 cout<<n-k+1<<endl;
  return 0;
}

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

vector<ll> prime(ll n){
    vector<ll> rt;
    for(ll i=2;i*i<n;i++){
        ll tmp=0;
        while(n%i==0){
            tmp++;
            n/=i;
        }
        if(n%i!=0&&tmp!=0) rt.push_back(tmp);
    }
    if(n!=1) rt.push_back(1);
    return rt;
}

int main(){
    ll a,b;
    cin>>a>>b;
    if(a>b) swap(a,b);
    ll g=gcd(a,b);
    vector<ll> com=prime(g);
    // ll ans=1;
    // for(ll x:com){
    //     //cout<<x<<endl;
    //     ans*=(x+1);
    // }
    cout<<com.size()+1<<endl;
}