#pragma GCC optimize("Ofast")
#pragma GCC target("avx2,tune=native")
#pragma GCC optimize("unroll-loops")
//#pragma GCC optimize("trapv")
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//using namespace __gnu_pbds;
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define pb push_back
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using pi = pair<ll, ll>;
const int mod = 1000000007;
const ll inf = 1e18;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
using ld = double;
using vec = complex<ld>;
#define x real()
#define y imag()
ld dot(vec a, vec b) {
	return (conj(a)*b).x;
}
ld cross(vec a, vec b) {
	return (conj(a)*b).y;
}
istream& operator>>(istream& in, vec &v) {
	ld a, b;
	in >> a >> b;
	v = vec(a, b);
	return in;
}
bool cw(vector<pair<vec, int>> &hull, vec &v) {
	int n = hull.size();
	if(n < 2) return true;
	return cross(hull[n-1].first-hull[n-2].first, v-hull[n-1].first)<=0;
}
ld ans[100100];
int main() { //DINIC ORZ
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int n;
	cin >> n;
	vector<pair<vec, int>> v;
	v.resize(n);
	int _T = 0;
	for(auto &i : v) {
		cin >> i.first;
		i.second = ++_T;
	}
	for(auto &i : v) {
		if(i.first.x < v.back().first.x || (i.first.x == v.back().first.x&&i.first.y<v.back().first.y))
			swap(v.back(), i);
	}
	vector<pair<vec, int>> hull {v.back()};
	v.pop_back();
	sort(all(v), [&](const pair<vec, int> &a, const pair<vec, int> &b) {
		if(fabs(cross(a.first-hull[0].first, b.first-hull[0].first))<1e-9)
			return abs(a.first-hull[0].first) < abs(b.first-hull[0].first);
		return cross(a.first-hull[0].first, b.first-hull[0].first) < 0;
	});
	for(auto i : v) {
		while(!cw(hull, i.first)) hull.pop_back();
		hull.pb(i);
	}
	for(int i = 0; i < hull.size(); i++) {
		vec l = (i?hull[i-1]:hull.back()).first;
		vec r = (i+1<hull.size()?hull[i+1]:hull[0]).first;
//		cout << hull[i].first << "\n";
//		cout << hull[i].first << " " << l << " " << r << "\n";
		l-=hull[i].first,	r-=hull[i].first;
		ld angle = M_PI - acos(((dot(l, r)/abs(l))/abs(r)));
//		cout << hull[i].first << " " << l << " " << r << "\n";
//		cout << dot(l, r) << "\n";
		ans[hull[i].second] = angle/(2*M_PI);
	}
	cout << fixed << setprecision(15);
	for(int i = 1; i <=n; i++) cout << ans[i] << "\n";
}

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

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

  ll n;
  cin >> n;
  string s;
  vector<pair<ll,ll> > p;

  for(ll i=0; i<n; i++) {
    cin >> s;
    ll x=0, d=0;
    for(ll j=0; j<(ll)s.size(); j++) {
      if (s[j]=='(') x++;
      if (s[j]==')') {
        x--;
        d = min(d, x);
      }
    }
    if(x<0) d-=x;
    p.push_back(make_pair(-d,x));
  }

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

  ll h=0;
  for(ll i=0; i<n; i++) {
    if(p[i].second>=0) {
      if(h-p[i].first<0) {
        cout << "No" << '\n';
        return 0;
      }
      h += p[i].second;
    }
  }
  for(ll i=n-1; i>=0; i--) {
    if(p[i].second<0) {
      if(h-p[i].first+p[i].second<0) {
        cout << "No" << '\n';
        return 0;
      }
      h += p[i].second;
    }
  }
  if(h!=0) {
    cout << "No" << '\n';
    return 0;
  }

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


#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

//マクロ
//forループ関係
//引数は、(ループ内変数,動く範囲)か(ループ内変数,始めの数,終わりの数)、のどちらか
//Dがついてないものはループ変数は1ずつインクリメントされ、Dがついてるものはループ変数は1ずつデクリメントされる
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
//xにはvectorなどのコンテナ
#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x)) //最大値を求める
#define MIN(x) *min_element(ALL(x)) //最小値を求める
//定数
#define INF 1000000000000 //10^12:極めて大きい値,∞
#define MOD 1000000007 //10^9+7:合同式の法
#define MAXR 100000 //10^5:配列の最大のrange(素数列挙などで使用)
#define PI 3.14159265359 //πの値
//略記
#define PB push_back //vectorヘの挿入
#define MP make_pair //pairのコンストラクタ
#define F first //pairの一つ目の要素
#define S second //pairの二つ目の要素

int main() {
cin.tie(0);
ios::sync_with_stdio(false);
string A, B; cin >> A >> B;
cout << B << A;
}

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

#define M 1000000007
#define pb push_back
#define mp make_pair
#define s second
#define f first
#define mod 998244353
#define sz(v) (int)(v).size()

#define pii pair<int, int>
#define vi vector<int>
#define ll long long
#define fastio ios_base::sync_with_stdio(false);cin.tie(0)

ll add(ll a,ll b)
{
	a%=M;
	b%=M;
	ll p = (a+b)%M;
	return (p+M)%M;
}

ll mul(ll a,ll b)
{
	a%=M;
	b%=M;
	ll p = (a*b)%M;
	return (p+M)%M;
}

int main()
{
	fastio;
	ll i,j,n,ans=0;
	cin>>n;
	string str;
	cin>>str;
	ll c1=0,c2=0,c3=0;
	for(i=0;i<n;i++)
	{
		if(str[i]=='R')
			c1++;
		else if(str[i]=='G')
			c2++;
		else
			c3++;
	}
	ans = c1*c2*c3;
	for(i=0;i<n;i++)
	{
		for(j=1;(j<=i)&&(i+j<n);j++)
		{
			if((str[i]!=str[i-j])&&(str[i]!=str[i+j])&&(str[i-j]!=str[i+j]))
				ans--;
		}
	}
	cout<<ans<<endl;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
template<typename T1,typename T2> bool chmin(T1 &a,T2 b){if(a<=b)return 0; a=b; return 1;}
template<typename T1,typename T2> bool chmax(T1 &a,T2 b){if(a>=b)return 0; a=b; return 1;}

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

    int n;
    cin>>n;
    int ans = -1;
    int l=1,r=n-1;
    cout << 0 << endl;
    string s;
    cin>>s;
    string fi = s;
    if(s == "Vacant") return 0;

    cout << n-1 << endl;
    cin>>s;
    string la = s;
    if(s=="Vacant")return 0;

    while(true){
        int mid = (l+r)/2;
        cout << mid << endl;
        cin >> s;
        if(s == "Vacant")return 0;
        if(mid%2 == 0){
            if(s == fi) l = mid;
            else r = mid;
        }
        else{
            if(s == la) l = mid;
            else r = mid;
        }
    }

}

/* 実行時間1s制限の場合10^6 1,000,000 : 余裕をもって間に合う10^7
  10,000,000 : おそらく間に合う10^8 100,000,000 : 非常にシンプルな処理
  でないと厳しい
 */
#define rep(i, n) for(int i = 0; i < (int)n; i++)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#include <bits/stdc++.h>
#define M_PI 3.14159265358979323846
using namespace std;

typedef long long ll; // long longはデータモデル(LLP64, LP64, ...)によらず64bit.
ll gcd(ll a, ll b) {return b ? gcd(b, a%b) : a;}  // Greatest Common Divisor ユークリッドの互除法（aが長辺）
vector<pair<ll,int>> factorize(ll n) {            // a,bの公約数 = GCD(a, b)の約数
    vector<pair<ll,int>> res;
    for (ll i = 2; i*i <= n; i++) { // √nまで探せばよい
        if (n%i) continue;
        res.emplace_back(i, 0);     // 割り切れたら
        while (n%i == 0) {
            n /= i;
            res.back().second++;
        }
    }
    if (n != 1) res.emplace_back(n, 1); // この時点で1でなかったら、残りは素数.
    return res;
}
ll lcm(ll a, ll b) {return a/gcd(a,b)*b;}         // Least Commont Multiple オーバーフローしないように先に割る
ll ceil(ll a, ll b) {return (a+b-1)/b;}

const ll INF = LONG_MAX;
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(int argc, char* argv[])
{
#ifdef LOCAL
    // 以降 cin の入力元が 'xxx.txt' になる
    // std::ifstream in(argv[1]);
    //std::cin.rdbuf(in.rdbuf());
    //std::ifstream in(string(argv[0]) + ".txt");
    std::ifstream in("in.txt");
    std::cin.rdbuf(in.rdbuf());
#endif

    int n;
    cin >> n;
    int tmp = sqrt(n);
//    cout << tmp << endl;
    ll ans = 0;
    for (int i = tmp; ; tmp++) {
        ll a = tmp * tmp;
        if (a > n) break;
        ans = a;
    }

    cout << ans;

    return 0;
}

/*
  - 1e9 : 10^9
  - container一般
    - 合計
      accumulate(a.begin(), a.end(), 0LL)  0LLはオーバーフロー用
  - vector
    vector<int> A(N, 0); // 0で初期化(省略可)
    vector<vector<int>> vec(n_rows, vector<int>(n_cols, value));  // 2次元配列初期化
    - loop
      for  (int i = 0; i < A.size(); i++) {}
      for  (int elem : A) {}
    - sort
      std::sort(v.begin(), v.end());  // 昇順
      std::sort(v.begin(), v.end(), std::greater<int>()); //降順
      - vector<vector<int>> cnt(h, vector<int>(w))
    - sort(struct)
        struct st_t {
            string name;
            int p;
            bool operator<(const st_t& another) const {
                if (name == another.name)
                {
                    return p > another.p;
                }
                return name < another.name;
            }
        };
        vector<st_t> st(n);
        sort(st.begin(), st.end());
  - pair
    - pairのソートの定義 : firstが優先的に比較。同じだったらsecond。
    - pair<pair<string,int>,int> p[110];
      std::sort(p,p+a);
        こうすると、first.first -> first.second -> secondの順にソートされる
    - sort
      - sort(a.begin(), cb.end(), greater<pair<int, int>>());
  - map
    - for (auto x : map) {}  // x.first:key  x.second:value.
  - priority_queue<int> q;
    - q.top()に最大値が入っている
  - string
    - loop
      for (char& c : s) {}
 */


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

int main(){
	ll n; cin>>n;
	vector<ll> v(5);
	rep(i,5) cin>>v[i];
	sort(all(v));
	cout<<(n+v[0]-1)/v[0]+4<<endl;
}

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

int main() {
  int64_t N;
  cin >> N;
  int64_t minimum;
  for(int i = 0; i < 5; i++) {
    if(i == 0) {
      cin >> minimum;
    }
    else {
      int64_t a;
      cin >> a;
      minimum = min(minimum, a);
    }
  }
  cout << (N - 1) / minimum + 5 << endl;
}


#include <iostream>
#include <algorithm>
#include <iomanip>

double avg(int n) {
	return (n+1)/2.0;
}

int main() {
	int n, k, p[2000010];
	std::cin >> n >> k;

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

	double sum = 0;
	for (int i = 0; i < k; ++i) {
		sum += avg(p[i]);
	}

	double ans = sum;
	for (int i = k; i < n; ++i) {
		sum -= avg(p[i-k]);
		sum += avg(p[i]);

		ans = std::max(ans, sum);
	}

	std::cout << std::setprecision(10) << std::fixed << ans;
}

#include <bits/stdc++.h>
using namespace std;
int main(){
  int N,K; cin>>N>>K;
  vector<int>A(N);
  vector<long double>sum(N+K);
  for(int i=0;i<N;i++){
    cin>>A[i];
    sum[i]+=A[i]+1;
    sum[i+K]-=A[i]+1;
  }
  for(int i=1;i<N+K;i++)sum[i]+=sum[i-1];
  sort(sum.begin(),sum.end());
  cout<<fixed<<setprecision(10)<<sum[N+K-1]/2<<endl;
}


#include <stdio.h>
#include <string.h>
#include <string>
#include <iostream>
#include <vector>
#include <sstream>
#include <memory>
#include <iomanip>

std::vector<int> parse_line(std::string const& line) {
    using namespace std;
    vector<int> result;
    istringstream s(line);
    string element;
    while (getline(s, element, ' ')) {
        stringstream buf;
        int value = 0;
        buf << element;
        buf >> value;
        result.push_back(value);
    }
    return std::move(result);
}
int main(int argc, char* argv[])
{
    using namespace std;
    while (true) {
        string line;
        getline(std::cin, line);
        auto elements = parse_line(line);
        auto length = elements[0];
        if (length == 0) break;
        vector<int> total(length + 1);
        size_t width = length + 1;
        for (size_t i = 0; i < length; ++i) {
            getline(cin, line);
            elements = parse_line(line);
            int sum = 0;
            for (size_t n = 0; n < length; ++n) {
                int val = elements[n];
                sum += val;
                total[n] += val;
                cout << setw(5) << val;
            }
            cout << setw(5) << sum << endl;
            total[length] += sum;
        }
        for (size_t i = 0; i < width; ++i) {
            cout << setw(5) << total[i];
        }
        cout << endl;
    }

    return 0;
}

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

using namespace std;

int main()
{
    int data[10][10];
    int n;

    while (cin >> n, n) {
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                cin >> data[i][j];
            }
        }
        int ans;
        for (int i = 0; i < n; i++) {
            ans = 0;
            for (int j = 0; j < n; j++) {
                printf("%5d", data[i][j]);
                ans += data[i][j];
            }
            printf("%5d\n", ans);
        }
        int s = 0;
        for (int i = 0; i < n; i++) {
            int sum = 0;
            for (int j = 0; j < n; j++) {
                sum += data[j][i];
            }
            printf("%5d", sum);
            s += sum;
        }
        printf("%5d\n", s);
    }
    return 0;
}


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

int main(){
int n,m,mx=0,mn=999999;
  cin>>n>>m;
vector<pair<int,int>> v(m);
  for(int i=0;i<m;i++){
  cin>>v[i].first>>v[i].second;
  mx=max(v[i].first,mx);
  mn=min(v[i].second,mn);
  }
  cout<<max(mn-mx+1,0);
  return 0;
}


#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
const ll N=1e5+5;
ll n;
vector< pair<ll,ll> > adj[N];
vector< pair< pair<ll,ll> , ll > >wt;
bool cmp( pair< pair<ll,ll> , ll > a,pair< pair<ll,ll> ,ll >b){
    return a.second<b.second;
}
ll par[N],sz[N];
void init(){
    for(ll i=0;i<N;i++)par[i]=i,sz[i]=1;
}
ll dsu_parent(ll node){
    if(node==par[node])return node;
    return par[node]=dsu_parent(par[node]);
}
void dsu_union(ll a,ll b){
    a=dsu_parent(a);
    b=dsu_parent(b);
    if(a==b)return;
    if(sz[a]<sz[b])swap(a,b);
    sz[a]+=sz[b];
    par[b]=a;
}
ll func(){
    ll ans = 0;
    for(ll i=1;i<=n;i++)for(auto &ele:adj[i])wt.push_back( { {i,ele.second} , ele.first} );
    sort(wt.begin(),wt.end(),cmp);
    init();
    for(auto &edges:wt){
       // cout<<edges.first.first<<" "<<edges.first.second<<" "<<edges.second<<endl;
        ll u=edges.first.first,v=edges.first.second,w=edges.second;
        if(dsu_parent(u)==dsu_parent(v))continue;
        ans+=w;
        dsu_union(u,v);
    }
    return ans;
}
int main(){
    cin.tie(NULL); cout.tie(NULL);
    ios_base:: sync_with_stdio(false);
    cin>>n;
    pair<ll,ll> x[n],y[n];
    for(ll i=0;i<n;i++)cin>>x[i].first>>y[i].first,x[i].second=y[i].second=i+1;
    sort(x,x+n);
    sort(y,y+n);
    for(ll i=1;i<n;i++){
        adj[x[i].second].push_back({x[i].first-x[i-1].first , x[i-1].second});
        adj[x[i-1].second].push_back({x[i].first-x[i-1].first , x[i].second});

        adj[y[i].second].push_back({y[i].first-y[i-1].first , y[i-1].second});
        adj[y[i-1].second].push_back({y[i].first-y[i-1].first , y[i].second});
    }
    cout<<func();
}

#include <bits/stdc++.h>

using namespace std;

mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
typedef long long ll;
typedef long double ld;

const int N = (int) 1e6 + 7;
int n, sumtop;

struct T {
  int top;
  int mn;
};

bool cmp1(T a, T b) {
  return a.mn > b.mn;
}

bool cmp2(T a, T b) {
  return min(a.mn, a.top + b.mn) > min(b.mn, b.top + a.mn);
 ///return a.top - a.mn > b.top - b.mn;
}

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  vector<T> a, b;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    string s;
    cin >> s;
    int top = 0, mn = 0;
    for (auto &ch : s) {
      if (ch == '(') {
        top++;
      } else {
        top--;
      }
      mn = min(mn, top);
    }
    if (top >= 0) {
      a.push_back({top, mn});
    } else {
      b.push_back({top, mn});
    }
    sumtop += top;
  }
  if (sumtop != 0) {
    cout << "No\n";
    return 0;
  }
  sort(a.begin(), a.end(), cmp1);
  sort(b.begin(), b.end(), cmp2);
  int cur = 0;
  for (auto &it : a) {
    if (cur + it.mn < 0) {
      cout << "No\n";
      return 0;
    }
    cur += it.top;
  }
  for (auto &it : b) {
    if (cur + it.mn < 0) {
      cout << "No\n";
      return 0;
    }
    cur += it.top;
  }
  cout << "Yes\n";
  return 0;
}


#include<cstdio>
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
int main(){
    int m,n;
    while(cin>>n>>m,n){
        int plz[1050]={0},total=0,cnt=1;
        for(int i=0;i<n;i++){
            cin>>plz[i];
        }
        sort(plz,plz+n);
        reverse(plz,plz+n);
        for(int i=0;i<n;i++){
            if(cnt!=m){
                total+=plz[i];
                cnt++;
            }
            else if(cnt==m){
                    cnt=1;
            }
        }
        cout<<total<<endl;
    }
    return 0;
}

#include <iostream>
using namespace std;
int sum,h,w,a,b;
int main(){
	while(1){
		cin >> h>>w;
		if(!(h||w))break;
		sum=h*h+w*w;
		a=h+1;
		while(1){
			while(a*a<sum){
				b=a+1;
				while(a*a+b*b<=sum){
					if(a*a+b*b==sum)goto END;
					b++;
				}
				a++;
			}
			sum++;
			a=1;
		}
		END:;
		cout <<a <<" " <<b <<endl;
	}
}


#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;

int main()
{
  int N; cin >> N;
  ll ans = 0;
  int k;
  ll r = 0, g = 0, b = 0;
  vector<char> S(N+1);
  FOR(i,1,N+1){
    cin >> S[i];
    if(S[i] == 'R') r++;
    if(S[i] == 'G') g++;
    if(S[i] == 'B') b++;
  }
  ans = r * g * b;
  FOR(i,1,N-1){
    FOR(j,i+1,N){
      k = 2 * j - i;
      if(k > N) break;
      if(S[i] != S[j] && S[i] != S[k] && S[k] != S[j])
        ans--;
    }
  }
  cout << ans << endl;
}

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

typedef long long int ll;
typedef pair<ll, ll> p_ll;
typedef vector<pair<ll, ll>> vec_p; //vector<pair<ll, ll>> pairs(n) ,pairs.at(i) = make_pair(i*i, i)

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

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

    int N;
    string S;
    cin >> N >> S;

    vector<int> G;
    vector<int> R;
    vector<int> B;

    for (int i = 0; i < N; i++)
    {
        if (S.at(i) == 'R')
        {
            R.push_back(i + 1);
        }
        else if (S.at(i) == 'G')
        {
            G.push_back(i + 1);
        }
        else if (S.at(i) == 'B')
        {
            B.push_back(i + 1);
        }
    }

    int tmp1, tmp2, tmp3;
    ll ans = 0;
    for (ll i = 0; i < N; i++)
    {
        for (ll j = 1; i + 2 * j < N; j++)
        {
            if(i+2*j<N){
                if(S.at(i)=='R'){
                    tmp1 = 1;
                }
                else if(S.at(i)=='G'){
                    tmp1 = 2;
                }
                else if(S.at(i)=='B'){
                    tmp1 = 4;
                }
                if (S.at(i+j) == 'R')
                {
                    tmp2 = 1;
                }
                else if (S.at(i+j) == 'G')
                {
                    tmp2 = 2;
                }
                else if (S.at(i+j) == 'B')
                {
                    tmp2 = 4;
                }
                if (S.at(i + 2*j) == 'R')
                {
                    tmp3 = 1;
                }
                else if (S.at(i + 2*j) == 'G')
                {
                    tmp3 = 2;
                }
                else if (S.at(i + 2*j) == 'B')
                {
                    tmp3 = 4;
                }
                if(tmp1+tmp2+tmp3==7){
                    ans++;
                }
            }
        }
    }

    cout << R.size()*G.size()*B.size()-ans << endl;
}


#include<bits/stdc++.h>
using namespace std;
int main(){
  int y,z;
  cin>>y>>z;
  if(y%z==0) cout<<0<<endl;
  else cout<<1<<endl;
}

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

#define MOD (int)1e9+7
#define rep(i,a,b) for(int i=a;i<b;++i)
#define rrep(i,a,b) for(int i=a;i>b;--i)
#define vi vector<int>
#define vl vector<ll>
#define ld long double
#define vvi vector<vector<int>>
#define vvl vector<vector<long long>>
#define pii pair<int,int>
#define pll pair<long,long>
#define vpii vector<pii>
#define vpll vector<pll>
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define PI 3.1415926535897932384626433832795
#define fix(f,n) fixed<<setprecision(n)<<f
#define all(x) x.begin(),x.end()

ll powM(ll a,ll b,ll m )
{
  a%=m;
  ll ans=1;
  while(b>0)
  {
    if(b&1)ans=ans*a%m;
    a=a*a%m;
    b>>=1;
  }

return ans;
}

ll c(ll a,ll b)
{
  if(a==0)return b==0?1:0;

if(b>a)return 0;

  ll val=1;
ll fac=1;
for(int i=1;i<=b;i++)fac*=i;
for(int i=a;i>=a-b+1;i--)val*=i;

  return val/fac;

}

ll f(ll n)
{
  ll ans=1LL;
  while(ans<=n)ans<<=1;

return ans;
}

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

ll n,k;
cin>>n>>k;
ll ans=0;
if(n%k)ans=1;

cout<<ans<<"\n";

return 0;

}


#include<bits/stdc++.h>
using namespace std;
int main(){
int A,B,C,D,a;
  cin>>A>>B>>C>>D;
  a=min(min(min(A+C,A+D),B+C),B+D);
cout<<a<<endl;
}

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

#define INF 1001001001
#define LINF 1001001001001001001
#define MOD 1000000007
#define MOD2 998244353

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

#define rep(i,n) for(int i=0,_i=(n);i<_i;++i)
#define rep1(i,a,b) for(int a_=(a),b_=(b),i=a_;i<b_;++i)
#define repr(i,n) for(int _i=(n),i=_i;i>0;--i)

#define db(x) cerr<<#x<<" = "<<x<<" ";
#define db2(x,y) cerr<<"("<<#x<<", "<<#y<<") = ("<<x<<", "<<y<<") ";
#define db3(x,y,z) cerr<<"("<<#x<<", "<<#y<<", "<<#z<<") = ("<<x<<", "<<y<<", "<<z<<") ";
#define ln cout<<endl;

#define all(a)  (a).begin(),(a).end()
#define dig(n)  to_string(n).length()

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define se second
#define fi first

typedef long long ll;

typedef pair<int,int> P;
typedef pair<int,P> iP;
typedef pair<P,P> PP;

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

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

int main(){

    bool flag=false;
    long double ans=0,d,n,m;
    cin>>n>>m>>d;

    if(d == 0){
        ans = (m-1)/n;
    }else{
        ans = (m-1)*(((n-d)*2)/(n*n));
    }

    cout <<fixed<<setprecision(16)<<ans << endl;
    //if(flag)cout << "Yes" <<endl;
    //else cout << "No" <<endl;
    return 0;
}


#include <iostream>
#include <cstring>
#include <string>
#include <cstdlib>
#include <queue>
#include <set>
#include <algorithm>
using namespace std;
const int MAXN = 100005;
const int MAXE = 200005;
const int NIL = -1;
typedef long long ll;
const ll INF = 0x3f3f3f3f3f3f3f3f;

bool vis[MAXN];
struct Edge {
	int to, next, w;
	Edge() { next = -1; }
} edge[MAXE];

int N;
int prenum[MAXN], parent[MAXN], lowest[MAXN], head[MAXE], timer, cnt;

void dfs(int cur, int pre)
{
	prenum[cur] = lowest[cur] = timer++;
	vis[cur] = true;

	int next;

	for (int i = head[cur]; i != NIL; i = edge[i].next)
	{
		next = edge[i].to;
		if (!vis[next])
		{
			parent[next] = cur;
			dfs(next, cur);
			lowest[cur] = min(lowest[cur], lowest[next]);
		}
		else if (next != pre)
		{
			lowest[cur] = min(lowest[cur], prenum[next]);
		}
	}
}

void art_points()
{
	for (int i = 0; i < N; ++i)
		vis[i] = false;
	timer = 1;
	dfs(0, NIL);

	set<int> ans;
	int flag = 0;	//?????????

	for (int i = 1; i < N; ++i)
	{
		int p = parent[i];
		if (p == 0)
			++flag;
		else if (prenum[p] <= lowest[i])
			ans.insert(p);
	}

	if (flag > 1)
		ans.insert(0);

	for (set<int>::iterator it = ans.begin(); it != ans.end(); ++it)
		cout << *it << endl;

}

void add(int u, int v, int w)
{
	edge[cnt].to = v;
	edge[cnt].w = w;
	edge[cnt].next = head[u];
	head[u] = cnt++;
}

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

	int m, s, t;
	cin >> N >> m;
	memset(head, NIL, sizeof(int) * 2 * (m + 1));
	cnt = 0;
	for (int i = 0; i < m; ++i)
	{
		cin >> s >> t;
		add(s, t, 0);
		add(t, s, 0);
	}
	art_points();
	return 0;
}

// https://atcoder.jp/contests/abc106/tasks/abc106_d
#include <bits/stdc++.h>
using namespace std;
// #define int long long
#define REP(i, n) FOR(i, 0, n)
#define REPR(i, n) for (int i = n - 1; i >= 0; i--)
#define FOR(i, s, n) for (int i = (s), i##_len = (n); i < i##_len; ++i)
#define ALL(obj) (obj).begin(), (obj).end()
#define ALLR(obj) (obj).rbegin(), (obj).rend()
#define CEIL(a, b) ((a - 1) / b + 1)

// https://github.com/drken1215/algorithm/blob/master/DataStructure/binary_indexed_tree_2D.cpp
template <class Abel> struct BIT2D {
    const Abel UNITY_SUM = 0; // to be set
    vector<vector<Abel>> dat;

    BIT2D(int n = 1, int m = 1) : dat(n + 1, vector<Abel>(m + 1, UNITY_SUM)) {}
    void init(int n, int m) {
        dat.assign(n + 1, vector<Abel>(m + 1, UNITY_SUM));
    }

    /* add x on the point (a, b) */
    inline void add(int a, int b, Abel x) {
        for (int i = a; i < (int)dat.size(); i += i & -i)
            for (int j = b; j < (int)dat[0].size(); j += j & -j)
                dat[i][j] = dat[i][j] + x;
    }

    inline Abel sum(int p, int q) {
        Abel res = UNITY_SUM;
        for (int i = p; i > 0; i -= i & -i)
            for (int j = q; j > 0; j -= j & -j)
                res = res + dat[i][j];
        return res;
    }

    /* a1 <= x < b1, a2 <= y < b2, 1-indexd */
    inline Abel sum(int a1, int a2, int b1, int b2) {
        return sum(b1 - 1, b2 - 1) - sum(a1 - 1, b2 - 1) - sum(b1 - 1, a2 - 1) +
               sum(a1 - 1, a2 - 1);
    }

    /* debug */
    void print() {
        for (int i = 1; i < (int)dat.size(); ++i) {
            for (int j = 1; j < (int)dat[0].size(); ++j)
                cout << sum(i, j, i + 1, j + 1) << ",";
            cout << endl;
        }
    }
};
signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int N, M, Q;
    cin >> N >> M >> Q;
    BIT2D<int> ft(N, N);
    REP(i, M) {
        int l, r;
        cin >> l >> r;
        ft.add(l, r, 1);
    }
    while (Q--) {
        int l, r;
        cin >> l >> r;
        // [l, r)の半開区間なので右側は+1する
        cout << ft.sum(l, l, r + 1, r + 1) << "\n";
    }

    return 0;
}


#include <iostream>
#include <stdlib.h>
#include <string.h>
using namespace std;
int main() {
    string x;
    cin >> x;
    for (int j = 97; j <= 122; j++) {
        bool a = 0;
        for (int i = 0; i < x.size(); i++) {
            if (char(j) == x[i]) {
                a = 1;
                continue;
            }
        }
        if (a == 0) {
            cout << char(j);
            return 0;
        }
    }
    cout << "None";
    return 0;
}

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

string in;
vector<string> V;

string change(string in){
  for(int i = 0; i < in.length(); i++){
    if(in[i] != 'a') in[i]--;
    else in[i] = 'z';
  }
  return in;
}
string solve(){
  int status = 0;
  while(1){
    for(int i = 0; i < V.size(); i++){
      string str = V[i];
      if(str != "." && str != " ") V[i] = change(str);
      if(V[i] == "the" || V[i] == "this" || V[i] == "that") status = 1;
    }
    if(status)break;
  }
  string out;
  for(int i = 0; i < V.size(); i++){
    out += V[i];
  }
  return out;
}
int main(){
  while(getline(cin,in)){
    V.clear();
    in += "\n";
    string str;
    for(int i = 0; i < in.length(); i++){
      if(in[i] < 'a' || in[i] > 'z'){
	V.push_back(str);
	str = "";
	if(in[i] == '.') V.push_back(".");
	if(in[i] == ' ') V.push_back(" ");
      }else str += in[i];
    }
    cout << solve() << endl;
  }
  return 0;
}


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

#define int long long
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define rep(i, n) for (int i = 0; i < n; ++i)
#define REP(i, n) for (int i = 0; i < n; ++i)
#define range(i,a,b) ((a)<=(i) && (i)<(b))
#define debug(x) cout << #x << " = " << (x) << endl;
#define fs first
#define sc second
#define pb push_back
#define eb emplace_back
#define SP << " " <<

typedef long long ll;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> T;
typedef vector<ll> vec;
typedef vector<P> pvec;
typedef vector<vector<ll>> vvec;
typedef vector<vector<P>> pvvec;
typedef priority_queue<ll> PQI;
typedef priority_queue<P> PQP;
typedef priority_queue<ll,vector<ll>,greater<ll>> PQIG;
typedef priority_queue<P,vector<P>,greater<P>> PQPG;

const vector<int> dx = {0, -1, 0, 1, 1, 1, -1, -1};
const vector<int> dy = {1, 0, -1, 0, 1, -1, 1, -1};
constexpr int MOD = (1000000007);
// const int MOD = (998244353);
// const int INF = (1 << 30); // 1073741824
const int INF = (1LL << 60); // 1152921504606846976
const double EPS = (1 >> 30);

template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return 1;} return 0;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return 1;} return 0;}
template<class T> inline T ceil(T a, T b) {return T((a + b - 1) / b);}
template<class T> inline T round(T a, T b) {return T(a / b);}
template< typename T1, typename T2 > istream &operator>>(istream &is, pair< T1, T2 > &p) { is >> p.first >> p.second; return is; }
template <class T> inline void out(T &a) { bool flag=true; for(auto&x:a){if(flag) {flag=false;} else{ cout << ' '; } cout<<x; } cout << endl; }

//----------------------------------------------------------------
int nmax=200000; // 2*(10^5)
vvec g(nmax);

void solve4ts()
{

    int N; cin >> N;
	cout << 0 << endl;
	string first; cin >> first;

	int l = 0, r = N;
	if(first!="Vacant")while (1) {
		int m = (l + r) / 2;
		cout << m << endl;

		string s; cin >> s;
		if (s == "Vacant")break;

		if (m % 2 && s != first || m % 2 == 0 && s == first)l = m + 1;
		else r = m;
	}
}
//-----------------------------------------------------------------

signed main(){ ios::sync_with_stdio(false); cin.tie(0); cout << fixed << setprecision(15);
    int repeat = 1;
    // cin >> repeat;
    while(repeat--) solve4ts();
}

#include <bits/stdc++.h>
#define int long long
#define x first
#define y second
#define getbit(x, i) (((x) >> (i)) & 1)
using namespace std;
typedef pair<int, int> pii;
#define hashset unordered_set
#define hashmap unordered_map
#define newline fast_writechar('\n')
#define unify(arr) arr.resize(unique(arr.begin(), arr.end()) - arr.begin())
#define getbit(x, i) (((x) >> (i)) & 1)

template <typename T>
vector<T> readvector(size_t sz) {
    vector<T> res(sz);
    for (size_t i = 0; i < sz; ++i) {
        cin >> res[i];
    }
    return res;
}
template <typename T>
std::ostream &operator<<(std::ostream &out, const std::vector<T> &v) {
    std::copy(v.begin(), v.end(), std::ostream_iterator<T>(out, " "));
    return out;
}

int mylog(int n) {
    return 63 - __builtin_clzll(n);
}

inline int binPow(int x, int deg, int mod) {
    int ans = 1;
    for (int i = sizeof(deg) * CHAR_BIT - 1; i >= 0; i--) {
        ans *= ans;
        ans %= mod;
        if (getbit(deg, i)) ans *= x;
        ans %= mod;
    }
    return ans;
}

/** Interface */

inline int readInt();
inline int readUInt();
inline void readWord(char *s);
inline int fast_readchar();  // you may use readchar() instead of it

inline void writeInt(int x);
inline void fast_writechar(int x);  // you may use putchar() instead of it
inline void writeWord(const char *s);
inline void fast_flush();

// ====================== END ======================
const int MAXN = 2e6 + 10;
const int MOD = 1e9 + 7;
const int INF = 1e18;

void solve() {
    int n, k;
    cin >> n >> k;
    auto arr =readvector<int>(n);
    arr.insert(arr.begin(), 0);
    for (int i = 1; i <= n; i++) arr[i] += arr[i - 1];
    int ans = 0;
    for (int i = 0; i + k <= n; i++) {
        ans = max(ans, arr[i + k] - arr[i] + k);
    }
    cout << fixed << setprecision(1) << ans / 2. << endl;
}

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int t = 1;
    // t = readInt();
    // cin >> t;
    for (int i = 1; i <= t; ++i) {
        // cout << "Case #" << i << ": ";
        solve();
    }
    // fast_flush();
    return 0;
}

/** Read */

static const int buf_size = 4096;

inline int fast_readchar() {
    static char buf[buf_size];
    static int len = 0, pos = 0;
    if (pos == len) pos = 0, len = fread(buf, 1, buf_size, stdin);
    if (pos == len) return -1;
    return buf[pos++];
}

inline int readUInt() {
    int c = fast_readchar(), x = 0;
    while (c <= 32) c = fast_readchar();
    while ('0' <= c && c <= '9') x = x * 10 + c - '0', c = fast_readchar();
    return x;
}

inline int readInt() {
    int s = 1, c = fast_readchar();
    int x = 0;
    while (c <= 32) c = fast_readchar();
    if (c == '-') s = -1, c = fast_readchar();
    while ('0' <= c && c <= '9') x = x * 10 + c - '0', c = fast_readchar();
    return x * s;
}

inline void readWord(char *s) {
    int c = fast_readchar();
    while (c <= 32) c = fast_readchar();
    while (c > 32) *s++ = c, c = fast_readchar();
    *s = 0;
}

/** Write */

static int write_pos = 0;
static char write_buf[buf_size];

inline void fast_writechar(int x) {
    if (write_pos == buf_size) fwrite(write_buf, 1, buf_size, stdout), write_pos = 0;
    write_buf[write_pos++] = x;
}

inline void fast_flush() {
    if (write_pos) fwrite(write_buf, 1, write_pos, stdout), write_pos = 0;
}

inline void writeInt(int x) {
    if (x < 0) fast_writechar('-'), x = -x;

    char s[24];
    int n = 0;
    while (x || !n) s[n++] = '0' + x % 10, x /= 10;
    while (n--) fast_writechar(s[n]);
}

inline void writeWord(const char *s) {
    while (*s) fast_writechar(*s++);
}


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

//#define int long long
typedef long long ll;

typedef unsigned long long ul;
typedef unsigned int ui;
const ll mod = 1000000007;
const ll INF = mod * mod;
const int INF_N = 1e+9;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
#define all(v) (v).begin(),(v).end()
typedef pair<ll, ll> LP;
typedef long double ld;
typedef pair<ld, ld> LDP;
const ld eps = 1e-12;
const ld pi = acos(-1.0);
//typedef vector<vector<ll>> mat;
typedef vector<int> vec;

//繰り返し二乗法
ll mod_pow(ll a, ll n, ll m) {
	ll res = 1;
	while (n) {
		if (n & 1)res = res * a%m;
		a = a * a%m; n >>= 1;
	}
	return res;
}

struct modint {
	ll n;
	modint() :n(0) { ; }
	modint(ll m) :n(m) {
		if (n >= mod)n %= mod;
		else if (n < 0)n = (n%mod + mod) % mod;
	}
	operator int() { return n; }
};
bool operator==(modint a, modint b) { return a.n == b.n; }
modint operator+=(modint &a, modint b) { a.n += b.n; if (a.n >= mod)a.n -= mod; return a; }
modint operator-=(modint &a, modint b) { a.n -= b.n; if (a.n < 0)a.n += mod; return a; }
modint operator*=(modint &a, modint b) { a.n = ((ll)a.n*b.n) % mod; return a; }
modint operator+(modint a, modint b) { return a += b; }
modint operator-(modint a, modint b) { return a -= b; }
modint operator*(modint a, modint b) { return a *= b; }
modint operator^(modint a, int n) {
	if (n == 0)return modint(1);
	modint res = (a*a) ^ (n / 2);
	if (n % 2)res = res * a;
	return res;
}

//逆元(Eucledean algorithm)
ll inv(ll a, ll p) {
	return (a == 1 ? 1 : (1 - p * inv(p%a, a)) / a + p);
}
modint operator/(modint a, modint b) { return a * modint(inv(b, mod)); }

const int max_n = 1 << 18;
modint fact[max_n], factinv[max_n];
void init_f() {
	fact[0] = modint(1);
	for (int i = 0; i < max_n - 1; i++) {
		fact[i + 1] = fact[i] * modint(i + 1);
	}
	factinv[max_n - 1] = modint(1) / fact[max_n - 1];
	for (int i = max_n - 2; i >= 0; i--) {
		factinv[i] = factinv[i + 1] * modint(i + 1);
	}
}
modint comb(int a, int b) {
	if (a < 0 || b < 0 || a < b)return 0;
	return fact[a] * factinv[b] * factinv[a - b];
}
using mP = pair<modint, modint>;

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

vec memo(1005);
queue<int> v[1005];

void solve() {
    int N; cin >> N;
    auto tmemo = memo;
    rep1(i, N){
        rep(j, N-1){
            int a; cin >> a;
            v[i].push(a);
        }
    }
    int res = 0;
    while(1){
        bool f = false;
        memo = tmemo;
        rep1(i, N){
            if(v[i].empty()) continue;
            int tmp = v[i].front();
            if(memo[i] || memo[tmp]) continue;
            if(v[tmp].front() == i){
                f = true;
                v[i].pop(); v[tmp].pop();
                memo[i] = memo[tmp] = 1;
            }
        }
        if(!f) break;
        res++;
    }
    rep1(i, N){
        if(!v[i].empty()){
            cout << -1 << endl;
            return;
        }
    }
    cout << res << endl;
}

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

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define rep(i, n) FOR(i, 0, n)
#define whole(x) (x).begin(),(x).end()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
using P = pair<int, int>;
#define debug(var) cerr << "[" << #var << "] " << var << endl
const ll mod = 1000000007;

vector<int> to[500000];
int tab[1005][1005];

int toID(int i, int j) {
    if (i>j) swap(i, j);
    return tab[i][j];
}

int dp[500000];
bool used[500000];
bool calculated[500000];

int dfs(int x) {
    if (used[x]) {
        if (!calculated[x]) return -1;
        return dp[x];
    }
    used[x] = true;
    int now = 1;
    for (int e: to[x]) {
        int res = dfs(e);
        if (res<0) return -1;
        now = max(res+1, now);
    }
    dp[x] = now;
    calculated[x] = true;
    return dp[x];
}

int main(){
    int n;
    cin >> n;
    vector<vector<int>> a(n, vector<int>(n-1));
    rep(i, n) rep(j, n-1) {
        cin >> a[i][j];
        a[i][j]--;
    }
    int id = 0;
    rep(i, n) rep(j, n) {
        if (i<j) tab[i][j] = id++;
    }
    rep(i, n) {
        rep(j, n-1) {
            a[i][j] = toID(i, a[i][j]);
        }
        rep(j, n-2) {
            to[a[i][j]].push_back(a[i][j+1]);
        }
    }

    int ans = 0;
    rep(i, id) {
        int res = dfs(i);
        ans = max(ans, res);
        if (res==-1) {
            cout << "-1" << endl;
            return 0;
        }
    }

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


#include <bits/stdc++.h>

using namespace std;
#define ll long long
#define rep(i, n) for (int i = 0; i < (n); ++i)
double const PI = 3.1415926535897932384626433;

int main() {
    int a, b, c, d, e, k;
    cin >> a >> b >> c >> d >> e >> k;
    if (e - a <= k) {
        cout << "Yay!" << endl;
    } else {
        cout << ":(" << endl;
    }
    return 0;
}

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

int main() {

  vector<int> A(5);
  for(int i=0; i<5; i++) cin >> A.at(i);
  int k, ans=0;
  cin >> k;

  for(int i=0; i<5; i++) {
    for(int j=i+1; j<5; j++) {
      if(A.at(j) - A.at(i) > k) ans = 1;
    }
  }

  if(ans == 0) cout << "Yay!" << endl;
  else cout << ":(" << endl;

}


#include <iostream>
#include <algorithm>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <bitset>
#include <complex>
#include <functional>

// output
#define SPBR(w, n) std::cout<<(w + 1 == n ? '\n' : ' ');
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
// utility
#define ALL(i) (i).begin(), (i).end()
#define FOR(i, a, n) for(int i=(a);i<(n);++i)
#define RFOR(i, a, n) for(int i=(n)-1;i>=(a);--i)
#define REP(i, n) for(int i=0;i<int(n);++i)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define IN(a, x, b) (a<=x && x<b)
#define OUT(a, x, b) (x<a || b<=x)
template<class T> inline T chmax(T & a, const T b) { return a = (a < b) ? b : a; }
template<class T> inline T chmin(T& a, const T b) { return a = (a > b) ? b : a; }

// type/const
#define int ll
using ll = long long;
using ull = unsigned long long;
using ld = long double;
const int MOD = 1000000007;
/* const int MOD = 1000000007; */
const int INF = 1e18;
const double PI = acos(-1);

using namespace std;

signed main() {
  int N, M;
  cin >> N >> M;

  vector<vector<int>> A(N, vector<int>(M));
  REP(i, N) REP(j, M){
    cin >> A[i][j];
    A[i][j]--;
  }

  int ans = N;
  vector<int> cnt(N, 0);
  vector<int> ng;

  while((int)ng.size() < M-1){
    vector<int> num(M, 0);
    REP(i, N){
      num[A[i][cnt[i]]]++;
    }

    int ret = 0;
    REP(i, M) if(num[i] != 0) chmax(ret, num[i]);
    chmin(ans, ret);

    pair<int, int> p(0, 0);
    REP(i, M){
      if(p.first < num[i]){
        p.first = num[i];
        p.second = i;
      }
    }
    ng.emplace_back(p.second);

    REP(i, N){
      REP(j, ng.size()){
        if(A[i][cnt[i]] == ng[j]){
          cnt[i]++;
          j = -1;
        }
      }
    }
  }

  cout << ans << endl;

  return 0;
}

#pragma GCC optimize ("O3")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse4")
#include"bits/stdc++.h"
using namespace std;
typedef long long ll;
#define int ll
#define sz(x) (int)(x).size();
#define all(x) x.begin(), x.end()
#define trav(i,a) for(auto &i:a)
inline int in(){int x;scanf("%lld",&x);return x;}
int32_t main()
{
	int n=in();
	map<int,int> f;
	int x;
	vector<int> a;
	for(int i=0;i<n;i++){x=in();f[x]++;}
	for(auto i:f)
	{
		int t=i.second;
		t/=2;
		for(int _=0;_<t;_++)a.push_back(i.first);
	}
	sort(a.rbegin(),a.rend());
	if(a.size()<=1)cout<<0;
	else cout<<a[0]*a[1];

}


#include <bits/stdc++.h>
#define fi first
#define se second
#define pii pair<int,int>
#define space putchar(' ')
#define enter putchar('\n')
#define mp make_pair
#define pb push_back
//#define ivorysi
#define MAXN 300005
using namespace std;
typedef long long int64;
typedef double db;
template<class T>
void read(T &res) {
    res = 0;char c = getchar();T f = 1;
    while(c < '0' || c > '9') {
    	if(c == '-') f = -1;
    	c = getchar();
    }
    while(c >= '0' && c <= '9') {
    	res = res * 10 + c - '0';
    	c = getchar();
    }
    res *= f;
}
template<class T>
void out(T x) {
    if(x < 0) {x = -x;putchar('-');}
    if(x >= 10) {
    	out(x / 10);
    }
    putchar('0' + x % 10);
}
const int MOD = 1000000007;
int dp[MAXN][3][2][2],sum[MAXN],ans,N;
char s[MAXN];
int inc(int a,int b) {
    return a + b >= MOD ? a + b - MOD : a + b;
}
int mul(int a,int b) {
    return 1LL * a * b % MOD;
}
void update(int &x,int y) {
    x = inc(x,y);
}
int fpow(int x,int c) {
    int res = 1,t = x;
    while(c) {
        if(c & 1) res = mul(res,t);
        t = mul(t,t);
        c >>= 1;
    }
    return res;
}
void Solve() {
    scanf("%s",s + 1);
    N = strlen(s + 1);
    for(int i = N ; i >= 1 ; --i) {
        sum[i] = sum[i + 1] + (s[i] == '?');
    }
    dp[0][0][0][0] = 1;
    for(int i = 1 ; i <= N ; ++i) {
        int t = 0;

        for(int j = 0 ; j <= 2 ; ++j) {
            for(int h = 0 ; h <= 1 ; ++h) {
                for(int k = 0 ; k <= 1 ; ++k) {
                    if(!dp[i - 1][j][h][k]) continue;
                    if(s[i] == '0' || s[i] == '?') {
                        if(k) update(dp[i][1][h][0],dp[i - 1][j][h][k]);
                        else {
                            if(j == 1) update(dp[i][2][h][0],dp[i - 1][j][h][k]);
                            else update(dp[i][1][h][0],dp[i - 1][j][h][k]);
                        }
                    }
                    if(s[i] == '1' || s[i] == '?') {
                        if(k) {
                            if(h) update(t,dp[i - 1][j][h][k]);
                            else update(dp[i][0][h + 1][0],dp[i - 1][j][h][k]);
                        }
                        else {
                            if(j == 1) update(dp[i][0][h][1],dp[i - 1][j][h][k]);
                            if(j == 2) update(dp[i][1][h][0],dp[i - 1][j][h][k]);
                            if(j == 0) {
                                if(h) update(t,dp[i - 1][j][h][k]);
                                else update(dp[i][0][h + 1][0],dp[i - 1][j][h][k]);
                            }
                        }
                    }
                }
            }
        }
        update(ans,mul(t,fpow(2,sum[i + 1])));
    }
    update(ans,inc(dp[N][0][1][1],dp[N][0][1][0]));
    out(ans);enter;
}
int main() {
#ifdef ivorysi
    freopen("f1.in","r",stdin);
#endif
    Solve();
    return 0;
}

#ifndef VS
#include<bits/stdc++.h>
#endif

using namespace std;
typedef long long LL;

#ifdef BTK
#define DEBUG if(1)
#else
#define CIN_ONLY if(1)
struct cww {cww() {CIN_ONLY{ios::sync_with_stdio(false); cin.tie(0);}}
}star;
#define DEBUG if(0)
#endif

#define ALL(v) (v).begin(),(v).end()
#define REC(ret, ...) std::function<ret (__VA_ARGS__)>
template <typename T>inline bool chmin(T &l, T r){bool a = l>r; if (a)l = r; return a;}
template <typename T>inline bool chmax(T &l, T r){bool a = l<r; if (a)l = r; return a;}
template <typename T>istream& operator>>(istream &is, vector<T> &v){for (auto &it : v)is >> it;return is;}

class range {private: struct I { int x; int operator*() { return x; }bool operator!=(I& lhs) { return x<lhs.x; }void operator++() { ++x; } }; I i, n;public:range(int n) :i({ 0 }), n({ n }) {}range(int i, int n) :i({ i }), n({ n }) {}I& begin() { return i; }I& end() { return n; }};

const int mod = 1e9 + 7;
typedef vector<LL> V;
typedef vector<V> VV;
int main() {
	string s;
	while (cin >> s) {
		VV dp(4, V(3, 0));
		dp[0][0] = 1;
		for (auto c : s) {
			VV nxt(4, V(3, 0));
			if (c == '0' || c == '?') {
				for (int i : range(4)) {
					nxt[i][1] += dp[i][0];
					nxt[i][2] += dp[i][1];
					nxt[i][1] += dp[i][2];
				}
			}
			if (c == '1' || c == '?') {
				for (int i : range(4)) {
					nxt[min(i + 1, 3)][0] += dp[i][0];
					nxt[i][0] += dp[i][1];
					nxt[i][1] += dp[i][2];
				}
			}
			for (auto &a : nxt)for (auto &b : a)b %= mod;
			swap(dp, nxt);
		}
		cout << (dp[3][0] + dp[3][1] + dp[3][2] + dp[2][0] + dp[2][1] + dp[1][0]) % mod << endl;
	}
	return 0;
}


using namespace std;
#include <iostream>
#include <vector>
int A,B,C;

int main() {
  cin >> A >> B >> C;
  string ans = (A < C) ^ (B < C)?"Yes":"No";
  cout << ans << endl;
  return 0;
}

#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
#include<stdio.h>
#include<queue>
#include <climits>
#include <map>
#include <set>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
const int mod = 1e9 + 7;
const long long INF = 1LL << 60;

int main()
{
    int n; cin >> n;
    if(n==2){
        int a,b;
        cin >> a >> b;
        for(int i = 1; i <= min(a,b); i++){
            if(a % i == 0 && b % i == 0){
                cout << i << endl;
            }
        }
    }else{
        int a,b,c;
        cin >> a >> b >> c;
        for(int i = 1; i <= min({a,b,c}); i++){
            if(a % i == 0 && b % i == 0 && c % i == 0){
                cout << i << endl;
            }
        }
    }
}


#include<iostream>
#include<cstdio>
using namespace std;
char s[20][20];
int ans,dx[]={0,0,1,-1},dy[]={1,-1,0,0};
void func(int y,int x){
	s[y][x]='0';
	int q,p;
	for(int i=0;i<4;i++){
		q=x+dx[i];
		p=y+dy[i];
		if(q>=0&&q<12&&p>=0&&p<12){
			if(s[p][q]=='1')
			func(p,q);
		}
	}
}
int main(){

	while(cin>>s[0]){
		ans=0;
		for(int i=1;i<12;i++)
		cin>>s[i];
		for(int i=0;i<12;i++)
		for(int j=0;j<12;j++)
		if(s[i][j]=='1'){
			ans++;
			func(i,j);
		}
		cout<<ans<<endl;
	}
	return 0;
}

#include <iostream>
#include <utility>
static int bsort(int *a, int n) {
    bool f = true;
    int c = 0;
    while (f) {
        f = false;
        for (int i = n - 1; i > 0; --i) {
            if (a[i] < a[i - 1]) {
                std::swap(a[i], a[i - 1]);
                f = true;
                ++c;
            }
        }
    }
    return c;
}
int main() {
    int n, a[100];
    std::cin >> n;
    for (int i = 0; i < n; ++i) {
        std::cin >> a[i];
    }
    int c = bsort(a, n);
    for (int i = 0; i < n; ++i) {
        std::cout << ((i == 0) ? "" : " ") << a[i];
    }
    std::cout << std::endl << c << std::endl;
}


// 解き直し.
// https://img.atcoder.jp/cf17-final/editorial.pdf
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
using P = pair<LL, LL>;
#define pb push_back
#define a first
#define b second
#define repx(i, a, b) for(int i = a; i < b; i++)
#define rep(i, n) repx(i, 0, n)
#define repr(i, a, b) for(int i = a; i >= b; i--)
const LL INF = 2020202020;
const int MAX = 5050;
LL dp[MAX][MAX];

int main(){

    // 1. 入力情報.
    int N;
    scanf("%d", &N);
    vector<P> v;
    LL h, p;
    v.pb({0, 0});
    rep(i, N){
        scanf("%lld %lld", &h, &p);
        v.pb({h, p});
    }
    rep(i, MAX) rep(j, MAX) dp[i][j] = INF;

    // 2. h + p を 小さい順に, sort.
    // ex.
    // 6
    // 1 6
    // 2 5
    // 3 4
    // 4 3
    // 5 2
    // 6 1
    //
    // -> 以下のようにsortする必要があるはず.
    // h=0 p=0
    // h=6 p=1
    // h=5 p=2
    // h=4 p=3
    // h=3 p=4
    // h=2 p=5
    // h=1 p=6
    // -> この場合, 3人(sort後 の 1番目, 2番目, 3番目, もしくは, sort前 の 6番目, 5番目, 4番目)が座布団を積める.
    sort(v.begin(), v.end(), [](const P &x, const P &y){
        if(x.a + x.b < y.a + y.b)                    return true;
        else if(x.a + x.b == y.a + y.b && x.b < y.b) return true;
        else                                         return false;
    });
    // for(auto &p : v) printf("h=%lld p=%lld\n", p.a, p.b);

    // 3. dp更新.
    dp[1][1] = v[1].b;
    repx(i, 2, N + 1){
        repx(j, 1, i + 1){
            if(dp[i - 1][j - 1] > v[i].a) dp[i][j] = dp[i - 1][j];
            else                          dp[i][j] = min(dp[i - 1][j], dp[i - 1][j - 1] + v[i].b);
        }
    }
    // rep(i, N + 1){
    //     rep(j, N + 1){
    //         printf("%lld ", dp[i][j]);
    //     }
    //     printf("\n");
    // }

    // 4. 出力.
    int ans = 0;
    rep(i, N + 1) if(dp[N][i] != INF) ans++;
    printf("%d\n", ans);
    return 0;

}

/**
 *    author:  tourist
 *    created: 22.01.2020 00:01:26
**/
#include <bits/stdc++.h>

using namespace std;

class dsu {
 public:
  vector<int> p;
  int n;

  dsu(int _n) : n(_n) {
    p.resize(n);
    iota(p.begin(), p.end(), 0);
  }

  inline int get(int x) {
    return (x == p[x] ? x : (p[x] = get(p[x])));
  }

  inline bool unite(int x, int y) {
    x = get(x);
    y = get(y);
    if (x != y) {
      p[x] = y;
      return true;
    }
    return false;
  }
};

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, m;
  cin >> n >> m;
  dsu d(2 * n);
  for (int i = 0; i < m; i++) {
    int x, y;
    cin >> x >> y;
    --x; --y;
    d.unite(x, y + n);
    d.unite(x + n, y);
  }
  vector<int> cnt(n, 0);
  for (int i = 0; i < n; i++) {
    cnt[d.get(i) % n] += 1;
  }
  long long iso = 0;
  long long bip = 0;
  long long non = 0;
  for (int i = 0; i < n; i++) {
    if (cnt[i] == 1) {
      iso += 1;
    }
    if (cnt[i] > 1) {
      if (d.get(i) == d.get(i + n)) {
        non += 1;
      } else {
        bip += 1;
      }
    }
  }
  long long ans = iso * iso + iso * (n - iso) + (n - iso) * iso;
  ans += (non + bip) * (non + bip);
  ans += bip * bip;
  cout << ans << '\n';
  return 0;
}


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

const int MAXN = 110;
int n, m, ex, ey;
int dp[2][MAXN][MAXN][MAXN];
int C[MAXN][MAXN], R[MAXN][MAXN];
char s[MAXN][MAXN];

inline int QR(int p, int l, int r) {
	if(l >= r) return 0;
	return R[p][r]-R[p][l];
}

inline int QC(int p, int l, int r) {
	if(l >= r) return 0;
	return C[p][r]-C[p][l];
}

inline void chkmax(int &cur, int val) {
	if(cur < val) cur = val;
}

int main() {
	scanf("%d%d", &n, &m);
	for(int i = 1; i <= n; i++) scanf("%s", s[i]+1);
	for(int i = 1; i <= n; i++) {
		C[i][0] = 0;
		for(int j = 1; j <= m; j++) {
			C[i][j] = C[i][j-1]+(s[i][j]=='o');
			if(s[i][j] == 'E') ex = i, ey = j;
		}
	}
	for(int i = 1; i <= m; i++) {
		R[i][0] = 0;
		for(int j = 1; j <= n; j++)
			R[i][j] = R[i][j-1]+(s[j][i]=='o');
	}

	for(int l = 0; l < ex; l++) {
		for(int d = 0; d < ey; d++)
			for(int r = 0; r <= n-ex; r++)
				for(int u = 0; u <= m-ey; u++) {
					int val = dp[l&1][d][r][u];
					if(l != ex-1) {
						if(ex-l-1 <= r) chkmax(dp[l&1^1][d][r][u], val);
						else {
							int lef = max(ey-d, u+1), rig = min(ey+u, m-d);
							chkmax(dp[l&1^1][d][r][u], val+QC(ex-l-1, lef-1, rig));
						}
					}
					if(d != ey-1) {
						if(ey-d-1 <= u) chkmax(dp[l&1][d+1][r][u], val);
						else {
							int lef = max(ex-l, r+1), rig = min(ex+r, n-l);
							//if(d == 0 && r == 1 && u == 1) printf("!\n");
							chkmax(dp[l&1][d+1][r][u], val+QR(ey-d-1, lef-1, rig));
						}
					}
					if(r != n-ex) {
						if(ex+r+1 > n-l) chkmax(dp[l&1][d][r+1][u], val);
						else {
							int lef = max(ey-d, u+1), rig = min(ey+u, m-d);
							//if(d == 1 && r == 0 && u == 1) printf("!!\n");
							chkmax(dp[l&1][d][r+1][u], val+QC(ex+r+1, lef-1, rig));
						}
					}
					if(u != m-ey) {
						if(ey+u+1 > m-d) chkmax(dp[l&1][d][r][u+1], val);
						else {
							int lef = max(ex-l, r+1), rig = min(ex+r, n-l);
							//if(d == 1 && r == 1 && u == 0) printf("!!!\n");
							chkmax(dp[l&1][d][r][u+1], val+QR(ey+u+1, lef-1, rig));
						}
					}
				}
		if(l == ex-1) break;
		for(int d = 0; d < ey; d++)
			for(int r = 0; r <= n-ex; r++)
				for(int u = 0; u <= m-ey; u++)
					dp[l&1][d][r][u] = 0;
	}
	printf("%d\n", dp[(ex-1)&1][ey-1][n-ex][m-ey]);
	return 0;
}

#include <iostream>
#include <vector>
#include <deque>
#include <algorithm>
#include <numeric>
#include <string>
#include <cstring>
#include <list>
#include <unordered_set>
#include <tuple>
#include <cmath>
#include <limits>
#include <type_traits>
#include <iomanip>
#include <map>
#include <unordered_map>
#include <queue>
#include <stack>
#include <set>
#include <bitset>
#include <regex>
#include <random>
#include<bits/stdc++.h>

using namespace std;

typedef long long ll;
#define rep(i,n)for(ll i=0;i<n;++i)
#define exout(x) printf("%.10f\n", x)
const double pi = acos(-1.0);
const ll MOD = 1000000007;
const ll INF = 1e18;
const ll MAX_N = 201010;

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

ll lcm(ll x, ll y) {
	if (x == 0 || y == 0)return 0;
	return (x / gcd(x, y) * y);
}

ll dx[4] = { 0,0,-1,1 };
ll dy[4] = { -1,1,0,0 };
ll ans[110][110];
bool flag[2][110];

//long longしか使わない
//素数は1より大きい
//lower_boundは指定したkey以上の要素の一番左のイテレータをかえす
//upper_boundは指定したkeyより大きい要素の一番左のイテレータをかえす
int main() {
	ll n, k;
	cin >> n >> k;
	vector<ll>a(n);
	bool flag = false;
	rep(i, n) {
		cin >> a[i];
		if (a[i] >= k)flag = true;
	}
	ll res = a[0];
	rep(i, n - 1) {
		res = gcd(res, a[i + 1]);
	}
	sort(a.begin(), a.end());
	if (flag == false) {
		puts("IMPOSSIBLE");
		return 0;
	}
	else {
		if (k % res) {
			puts("IMPOSSIBLE");
		}
		else {
			puts("POSSIBLE");
		}
	}
	return 0;
}


#include <bits/stdc++.h>
#define ri register
#define int long long
#define E (n+1)
using namespace std; const int N=200010;
inline int read()
{
    int s=0, w=1; ri char ch=getchar();
    while(ch<'0'||ch>'9') { if(ch=='-') w=-1; ch=getchar(); }
    while(ch>='0'&&ch<='9') s=(s<<3)+(s<<1)+(ch^48), ch=getchar();
    return s*w;
}
signed main()
{
    int n=read();
    printf("%lld\n",n/3);
    return 0;
}

#include<iostream>
using namespace std;
int main()
{
  int n;
  cin >> n;
  if(n / 3. >= 1)
    cout << n / 3;
  else cout << 0;
  return 0;
}


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

int main(){
    string str;
    cin>>str;
    for(int i=0;i<str.length();i++)
        cout<<str[str.length()-i-1];
    cout<<endl;
}

#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef vector<ll> vl;
typedef vector<string> vs;
typedef vector<char> vc;
typedef queue<ll> ql;
typedef deque<ll> dql;
typedef priority_queue<ll, vl/*, greater<ll>*/> pql; //降順(/*昇順*/)
typedef set<ll> sl;
typedef pair<ll, ll> pl;
typedef vector<vl> vvl;
typedef vector<pl> vpl;
#define rep(i, n) for(ll i = 0; i < ll(n); i++)
#define rep2(i, n) for(ll i = 1; i <= ll(n); i++)
//#define rep(i, k, n) for(ll i = k-1; i < ll(n); i++)
//#define rep2(i, k, n) for(ll i = k; i <= ll(n); i++)
#define all(v) (v).begin(), (v).end()
bool chmin(ll &a, ll b) {if(b < a) {a = b; return 1;} return 0;}
bool chmax(ll &a, ll b) {if(b > a) {a = b; return 1;} return 0;}
const ll INF = 1LL << 60;
const ll MOD = 1e9 + 7;
//const ll MOD = 998244353;
const ll MAX = 1e9;
const char newl = '\n';

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

  ll a, b;
  cin >> a >> b;
  cout << max(a+b, max(a-b, a*b)) << newl;
  return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
using namespace std;
#define ENDL "\n"
typedef long long int llint;
int intinput()
{
  int x;
  scanf("%d", &x);
  return x;
}

llint dp[300][300 * 300 + 1];

void code()
{
  llint MOD = 998244353;
  int N = intinput();
  vector<int> a(N);
  for (int i = 0; i < N; i++)
  {
    a[i] = intinput();
  }
  llint S = 0;
  for (int i = 0; i < N; i++)
  {
    S += a[i];
  }
  // すべての配置パターン
  llint ans = 1;
  for (int i = 0; i < N; i++)
  {
    ans *= 3;
    ans %= MOD;
  }
  // R, G, Bの長さがS/2を超えるパターンを除外
  // dp[i個目まで使う][Rの長さ] = パターン数
  dp[0][0] = 2; //Gに使うかBに使うか
  dp[0][a[0]] = 1;
  for (int i = 1; i < N; i++)
  {
    for (int s = 0; s <= S; s++)
    {
      dp[i][s] = 2 * dp[i - 1][s] + (s - a[i] >= 0 ? dp[i - 1][s - a[i]] : 0);
      dp[i][s] %= MOD;
    }
  }
  for (int s = (S + 1) / 2; s <= S; s++)
  {
    ans -= dp[N - 1][s] * 3;
    while (ans < 0)
    {
      ans += MOD;
    }
  }
  // R==G==S/2の場合が引かれすぎている
  // dp[i個目まで使う][Rの長さ] = パターン数　・・・今度はRとGのみに使い、R==G==S/2のパターン数を計算する
  if((S&1)==0){ //合計が偶数でないと起こり得ない
    for (int s = 0; s <= S/2; s++){
      dp[0][s] = 0; //リセット
    }
    //
    dp[0][0] = 1; //Gに使う(Bには使えないので1)
    dp[0][a[0]] = 1;  //Rに使う
    for (int i = 1; i < N; i++)
    {
      for (int s = 0; s <= S/2; s++){
        dp[i][s] = dp[i-1][s] + (s-a[i] >= 0 ? dp[i-1][s-a[i]] : 0);
        dp[i][s] %= MOD;
      }
    }
    ans += dp[N-1][S/2] * 3;
    ans %= MOD;
  }
  //
  ans %= MOD;
  cout << ans << ENDL;
}

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

#include <bits/stdc++.h>

using namespace std;

const int N = 305;
const int S = N * N;
const int mod = 998244353;

void add(int &x,int y) {
  x += y;
  if (x >= mod) x -= mod;
}

void sub(int &x,int y) {
  x -= y;
  if (x < 0) x += mod;
}

int mul(int x,int y) {
  return (long long) x * y % mod;
}

int a[N];
int f[S], g[S];
int nf[S], ng[S];

int main() {
  int n;
  scanf("%d", &n);
  f[0] = 1;
  g[0] = 1;
  int sum = 0;
  for (int i = 1; i <= n; ++i) {
    int x;
    scanf("%d", &x);
    for (int j = 0; j <= sum; ++j) {
      add(nf[j], f[j]);
      add(nf[j + x], f[j]);
      add(ng[j], mul(g[j], 2));
      add(ng[j + x], g[j]);
    }
    sum += x;
    for (int j = 0; j <= sum; ++j) {
      f[j] = nf[j], nf[j] = 0;
      g[j] = ng[j], ng[j] = 0;
    }
  }
  int ans = 1;
  for (int i = 1; i <= n; ++i) ans = mul(ans, 3);
  for (int i = 0; i <= sum; ++i) if (i + i >= sum) {
    sub(ans, mul(g[i], 3));
  }
  if (sum % 2 == 0) add(ans, mul(f[sum / 2], 3));
  printf("%d\n", ans);
  return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main(){
       string s;
       cin>>s;
       reverse  (s.begin(),s.end());
       cout<<s<<endl;

    return 0;
}

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

int main(){
  char str[21];
  scanf("%s", str);
  for(int i=0; i<strlen(str); i++){
    printf("%c", str[strlen(str)-i-1]);
  }
  puts("");
  return 0;
}


#include<cstdio>
#include<cstdlib>
#include<iostream>
#include<vector>
#include<queue>
#include<bitset>
#include<string>
#include<stack>
#include<set>
#include<unordered_set>
#include<map>
#include<unordered_map>
#include<cstring>
#include<complex>
#include<cmath>
#include<iomanip>
#include<numeric>
#include<algorithm>
#include<list>
#include<functional>
#include<cassert>
#define mp make_pair
#define pb push_back
#define X first
#define Y second
#define y0 y12
#define y1 y22
#define INF 987654321
#define PI 3.141592653589793238462643383279502884
#define fup(i,a,b,c) for(int (i)=(a);(i)<=(b);(i)+=(c))
#define fdn(i,a,b,c) for(int (i)=(a);(i)>=(b);(i)-=(c))
#define MEM0(a) memset((a),0,sizeof(a));
#define MEM_1(a) memset((a),-1,sizeof(a));
#define ALL(a) a.begin(),a.end()
#define SYNC ios_base::sync_with_stdio(false);cin.tie(0)
using namespace std;
typedef long long ll;
typedef long double ld;
typedef double db;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int, int> Pi;
typedef pair<ll, ll> Pll;
typedef pair<ld, ld> Pd;
typedef vector<int> Vi;
typedef vector<ll> Vll;
typedef vector<double> Vd;
typedef vector<Pi> VPi;
typedef vector<Pll> VPll;
typedef vector<Pd> VPd;
typedef tuple<int, int, int> iii;
typedef tuple<int,int,int,int> iiii;
typedef tuple<ll, ll, ll> LLL;
typedef vector<iii> Viii;
typedef vector<LLL> VLLL;
typedef complex<double> base;
const int MOD = 998244353;
ll POW(ll a, ll b, ll MMM = MOD) {ll ret=1; for(;b;b>>=1,a=(a*a)%MMM)if(b&1)ret=(ret*a)% MMM; return ret; }
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
ll lcm(ll a, ll b) { if (a == 0 || b == 0)return a + b; return a*(b / gcd(a, b)); }
int dx[] = { 0,1,0,-1,1,1,-1,-1 }, dy[] = { 1,0,-1,0,1,-1,1,-1 };
int ddx[]={2,2,-2,-2,1,1,-1,-1},ddy[]={1,-1,1,-1,2,-2,2,-2};

int k,d[305][305][305];
char s[305];
int go(int l,int r,int K)
{
	if(K<0)return -INF;
	if(l==r)return 1;
	if(l>r)return 0;
	int &ret=d[l][r][K];
	if(~ret)return ret;
	ret=max({go(l+1,r-1,K-(s[l]!=s[r]))+2,go(l+1,r,K),go(l,r-1,K)});
	return ret;
}
int main(){
	MEM_1(d);
	scanf("%s%d",s,&k);
	printf("%d",go(0,strlen(s)-1,k));
}

#include <bits/stdc++.h>
#define ll long long
#define maxn 100005 /*rem*/
#define mod 998244353
#define db double
#define vi vector<int>
#define pb push_back
#define mp make_pair
#define pi pair<int, int>
#define fi first
#define se second
using namespace std;
int a[maxn];
int n, m;
int f[maxn], cnt = 0;
bool cmp(int a, int b) {
	return (a % 2) > (b % 2);
}
int pl;
void push(int a) {
	if (pl + a - 1 >= n) a = n + 1 - pl;
	f[cnt++] = a, pl += a;
}
int main() {
	cin >> n >> m;
	for (int i = 0; i < m; i++)
		cin >> a[i];
	sort(a, a + m, cmp);
	int ans = 0;
	for (int i = 0; i < m; i++)
		ans += a[i] % 2;
	if (n % 2 == 0 && ans > 2) cout << "Impossible" << endl;
	else if (n % 2 == 1 && ans > 1) cout << "Impossible" << endl;
	else {
		pl = 1;
		if (a[1] % 2) swap(a[1], a[m - 1]);
		for (int i = 0; i < m; i++) {
			if (a[i] % 2) {
				if (i == 0)
					for (int j = 0; j < a[i] / 2 + 1; j++)
						push(2);
				else for (int j = 0; j < a[i] / 2; j++)
					push(2);
			}
			else {
				if (i == 0) push(1);
				push(a[i]);
			}
		}
		for (int i = 0; i < m; i++)
			cout << a[i] << ' ';
		cout << endl;
		cout << cnt << endl;
		for (int i = 0; i < cnt; i++)
			printf("%d ", f[i]);
		printf("\n");
	}
	return 0;
}


#include<iostream>
#include<cmath>
#include <iomanip>
using namespace std;

int main() {
  long double n,m,x,y,w,z;
  cin >> x>>y>>w>>z;
  n = x-w;
  m = y-z;

  cout << setprecision(10) <<sqrt(n*n+m*m) << endl;
    return 0;
}

#include<cstdio>
#include<cctype>
#include<cstdlib>
#include<algorithm>
typedef signed long long int int64;
inline unsigned getint() {
	register char ch;
	while(!isdigit(ch=getchar()));
	register unsigned x=ch^'0';
	while(isdigit(ch=getchar())) x=(((x<<2)+x)<<1)+(ch^'0');
	return x;
}
inline int64 min(const int64 &a,const int64 &b) {
	return a<b?a:b;
}
const int64 inf=0x7ffffffffffffff;
const int N=200001;
int n;
class FenwickTree {
	private:
		int64 val[N];
		int lowbit(const int &x) const {
			return x&-x;
		}
	public:
		FenwickTree() {
			std::fill(&val[0],&val[N],inf);
		}
		void modify(int p,const int64 &x) {
			while(p<=n) {
				if(x<val[p]) {
					val[p]=x;
				} else
				p+=lowbit(p);
			}
		}
		int64 query(int p) const {
			int64 ret=inf;
			while(p) {
				ret=min(ret,val[p]);
				p-=lowbit(p);
			}
			return ret;
		}
};
FenwickTree ta;
class RevFenwickTree {
	private:
		int64 val[N];
		int lowbit(const int &x) const {
			return x&-x;
		}
	public:
		RevFenwickTree() {
			std::fill(&val[0],&val[N],inf);
		}
		void modify(int p,const int64 &x) {
			while(p) {
				if(x<val[p]) {
					val[p]=x;
				}
				p-=lowbit(p);
			}
		}
		int64 query(int p) const {
			int64 ret=inf;
			while(p<=n) {
				ret=min(ret,val[p]);
				p+=lowbit(p);
			}
			return ret;
		}
};
RevFenwickTree tb;
int64 f[N];
inline void modify(const int &p,const int64 x) {
	if(1) {
		f[p]=x;
		ta.modify(p,x-p);
		tb.modify(p,x+p);
	}
}
int main() {
	n=getint();
	int q=getint(),a=getint(),b=getint();
	std::fill(&f[0],&f[N],inf);
	modify(a,0);
	int64 sum=0;
	while(q--) {
		a=b;
		b=getint();
		sum+=abs(a-b);
		int64 t1=ta.query(b)+b,t2=tb.query(b)-b;
		modify(a,min(t1,t2)-abs(a-b));
	}
	int64 tmp=inf;
	for(register int i=1;i<=n;i++) {
		tmp=min(tmp,f[i]);
	}
	printf("%lld\n",tmp+sum);
	return 0;
}


#include <iostream>
#include <limits>

using namespace std;

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n, a;
	long long int mina, maxa, suma;
	cin>>n>>a;
	mina=maxa=suma=a;
	for(int i=1; i<n; i++) {
		cin>>a;
		if(mina>a) mina=a;
		if(maxa<a) maxa=a;
		suma+=a;
	}
	cout<<mina<<' '<<maxa<<' '<<suma<<'\n';
	return 0;
}

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

#define faster      ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define pi          acos(-1.0)
#define nl          '\n'

///Library
#define mem(a,b)    memset(a,b,sizeof(a))
#define all(a)      a.begin(),a.end()
#define Sort(x)     sort(x.begin(),x.end())
#define Reverse(x)  reverse(x.begin(),x.end())
#define SortA(ar,s) sort(ar,ar+s)
#define SortD(ar,s) sort(ar,ar+s,greater<int>())
#define gcd(a,b)    __gcd(a,b)
#define lcm(a,b)    (a*(b/gcd(a,b)))
#define sq(x)       (x)*(x)

#define min3(a,b,c)        min(a,min(b,c))
#define min4(a,b,c,d)      min(a,min(b,min(c,d)))
#define max3(a,b,c)        max(a,max(b,c))
#define max4(a,b,c,d)      max(a,max(b,max(c,d)))
#define ABS(x)             ((x)<0?-(x):(x))
#define pb                 push_back
#define mod                1000000007
#define end                printf("\n")
#define yes                printf("YES\n")
#define no                 printf("NO\n")

///data type
typedef long long int ll;
typedef unsigned long long int  llu;

int main()
{
    faster
    ll n,sum=0;
    cin>>n;
    int A[n+n];
    for(int i=0; i<(n+n); i++)
        cin>>A[i];

    sort(A,A+n+n);
    for(int i=0; i<n+n; i=i+2)
    {
        sum+=A[i];
    }
    cout<<sum<<nl;
    return 0;
}


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

using namespace std;

int main(void){

	string roman;
	string fig("IVXLCDM");
	int ure[]={1,5,10,50,100,500,1000};
	int sum;
	while(cin>>roman){
		sum=0;
		for(int i=1;i<roman.length();i++){
			if(ure[fig.find(roman[i])]>ure[fig.find(roman[i-1])]) sum+=-1*ure[fig.find(roman[i-1])];
			else sum+=ure[fig.find(roman[i-1])];
		}
		sum+=ure[fig.find(roman[roman.length()-1])];
		cout<<sum<<endl;
	}

	return 0;
}

#include <iostream>
using namespace std;
int gcd(int a, int b){
    if(a < b) swap(a,b);
    if(b == 0) return a;
    else return gcd(b, a%b);
}
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int N; cin >> N;
    if(N == 2){
        int a, b;
        cin >> a >> b;
        for(int i = 1; i < max(a,b) + 1; ++i){
            if(a%i == 0 && b%i == 0) cout << i << endl;
        }
    }
    else {
        int a, b , c;
        cin >> a >> b >> c;
        for(int i = 1; i < max(a,max(b,c)) + 1; ++i){
            if(a%i == 0 && b%i == 0 && c%i == 0) cout << i << endl;
        }
    }
    return 0;
}


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

typedef long long ll;
typedef long double ld;
typedef vector<vector<int>> Graph;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
#define pi 3.14159265359
#define inf 2147483647
#define INF 9223372036854775807
#define mod 1000000007
#define mod2 998244353

int main() {
	int N, K; cin >> N >> K;
	set<char> D;
	for(int i = 0; i < K; i++) {
		char d; cin >> d;
		D.insert(d);
	}
	int ans = N;
	while(true) {
		string n = to_string(ans);
		bool flag = true;
		for(int i = 0; i < n.size(); i++) {
			if(D.count(n[i])) {
				flag = false;
				break;
			}
		}
		if(flag) {
			cout << ans << endl;
			return 0;
		}
		ans++;
	}
}

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, x, n) for(int i = x; i <= n; i++)
#define rep3(i, x, n) for(int i = x; i >= n; i--)
#define elif else if
#define sp(x) fixed << setprecision(x)
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(), x.end()
#define sz(x) (int)x.size()
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pil = pair<int, ll>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
const int inf = (1<<30)-1;
const ll INF = (1LL<<60)-1;
const ld EPS = 1e-10;
template<typename T> bool chmax(T &x, const T &y) {return (x < y)? (x = y, true) : false;};
template<typename T> bool chmin(T &x, const T &y) {return (x > y)? (x = y, true) : false;};

int main(){
    int H, W, A, B;
    cin >> H >> W >> A >> B;
    char s[H][W];
    rep(i, H){
        rep(j, W){
            if((i < B && j < A) || (i >= B && j >= A)) s[i][j] = '1';
            else s[i][j] = '0';
        }
    }
    rep(i, H){
        rep(j, W) cout << s[i][j]; cout << endl;
    }
}


#include <bits/stdc++.h>

#define CHOOSE(a) CHOOSE2 a
#define CHOOSE2(a0, a1, a2, a3, a4, x, ...) x
#define dump_1(x1) cerr << #x1 << ": " << x1 << endl
#define dump_2(x1, x2) \
  cerr << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << endl
#define dump_3(x1, x2, x3)                                                \
  cerr << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << ", " #x3 << ": " \
       << x3 << endl
#define dump_4(x1, x2, x3, x4)                                            \
  cerr << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << ", " #x3 << ": " \
       << x3 << ", " #x4 << ": " << x4 << endl
#define dump_5(x1, x2, x3, x4, x5)                                        \
  cerr << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << ", " #x3 << ": " \
       << x3 << ", " #x4 << ": " << x4 << ", " #x5 << ": " << x5 << endl
#define dump(...) \
  CHOOSE((__VA_ARGS__, dump_5, dump_4, dump_3, dump_2, dump_1, ~))(__VA_ARGS__)
#define check(s) cerr << s << endl

#define rep(i, n) for (int i = 0; i < n; i++)
#define repr(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define unique(v) v.erase(unique(v.begin(), v.end()), v.end());
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)

using namespace std;

using ll = long long;

vector<int> dx = {0, 1, 0, -1};
vector<int> dy = {1, 0, -1, 0};

const ll LINF = 2e18;
const int INF = 1e9;

// Binary Indexed Tree (Fenwick Tree)
// https://youtu.be/lyHk98daDJo?t=7960
template <typename T>
struct BIT {
  int n;
  vector<T> d;
  BIT(int n = 0) : n(n), d(n + 1) {}
  void add(int i, T x = 1) {
    for (i++; i <= n; i += i & -i) {
      d[i] += x;
    }
  }
  T sum(int i) {
    T x = 0;
    for (i++; i; i -= i & -i) {
      x += d[i];
    }
    return x;
  }
  T sum(int l, int r) { return sum(r - 1) - sum(l - 1); }
};

void solve(ll N, ll Q, std::vector<ll> c, std::vector<ll> l,
           std::vector<ll> r) {
  vector<int> pi(N + 1, -1);
  vector<vector<int>> ps(N);
  rep(i, N) {
    int l = pi.at(c.at(i));
    if (l != -1) ps.at(l).push_back(i);
    pi.at(c.at(i)) = i;
  }

  vector<vector<pair<int, int>>> qs(N);
  rep(i, Q) { qs.at(l.at(i)).emplace_back(r.at(i), i); }

  BIT<int> d(N);
  vector<int> ans(Q);

  for (int x = N - 1; x >= 0; --x) {
    for (int y : ps.at(x)) d.add(y, 1);
    for (auto query : qs.at(x)) {
      int r = query.first, i = query.second;
      ans.at(i) = (r - x + 1) - d.sum(r);
    }
  }

  rep(i, Q) { cout << ans.at(i) << endl; }

  return;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(15);
  ll N;
  scanf("%lld", &N);
  ll Q;
  scanf("%lld", &Q);
  std::vector<ll> c(N);
  for (int i = 0; i < N; i++) {
    scanf("%lld", &c[i]);
  }
  std::vector<ll> l(Q);
  std::vector<ll> r(Q);
  for (int i = 0; i < Q; i++) {
    scanf("%lld", &l[i]);
    scanf("%lld", &r[i]);
    l[i]--;  // 0-indexed
    r[i]--;  // 0-indexed
  }
  solve(N, Q, std::move(c), std::move(l), std::move(r));
  return 0;
}


#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<set>
#define lol(i,n) for(ll i=0;i<n;i++)
#define mod 1000000007
typedef long long ll;

using namespace std;
#define X 610
ll n;
class Con{
  public:
  vector<pair<ll,ll> > g[X][X];
  ll s[X][X];
  void dfs(ll x,ll y,ll c){
    if(~s[x][y])return;
    s[x][y]=c;
    for(auto t:g[x][y]){
      dfs(t.first,t.second,1^c);
    }
  }
  void main(ll d){
    vector<ll> x,y;
    for(int i=-X;i<X;i++)for(int j=-X;j<X;j++){
      if(i*i+j*j==d){
	x.push_back(i); y.push_back(j);
      }
    }
    lol(i,n)lol(j,n){
      for(int k=0;k<x.size();k++){
	ll xx=i+x[k],yy=j+y[k];
	if(xx<0||yy<0||xx>=n||yy>=n)continue;
	g[i][j].push_back(make_pair(xx,yy));
      }
    }
    lol(i,n)lol(j,n)s[i][j]=-1;
    lol(i,n)lol(j,n)dfs(i,j,0);
  }
};Con co[2];
int main(){
    cin>>n;n*=2;
    lol(i,2){
      ll d;
      cin>>d;
      co[i].main(d);
    }
    vector<pair<ll,ll> >v[2][2];
    lol(i,n)lol(j,n){
      v[co[0].s[i][j]][co[1].s[i][j]].push_back(make_pair(i,j));
    }
    lol(i,2)lol(j,2)if(v[i][j].size()>=n*n/4){
      for(int k=0;k<n*n/4;k++){
	cout<<v[i][j][k].first<<" "<<v[i][j][k].second<<endl;
      }
      return 0;
    }
    return 0;
}

#include <bits/stdc++.h>
int read(){
	int x=0,f=1;
	char ch=getchar();
	while (ch<'0' || ch>'9'){
		if (ch=='-') f=-1;
		ch=getchar();
	}
	while (ch>='0' && ch<='9'){
		x=x*10+ch-'0';ch=getchar();
	}
	return x*f;
}
const int N=600;
int n,d1,d2,col[2][N*N];
std::vector< std::pair<int,int> > v[2];
inline int id(const int &x,const int &y) {
    return x*N+y;
}
inline bool check(const int &x) {
    return 0<=x && x<n*2;
}
void dfs(const int &x,const int &t) {
    const int i=x/N,j=x%N;
    for (auto &d:v[t]) {
        const int nx=i+d.first,ny=j+d.second;
        if (!check(nx)||!check(ny)) continue;
        const int y=id(i+d.first,j+d.second);
        if (!col[t][y]) {
            col[t][y]=col[t][x]==1?2:1;
            dfs(y,t);
        }
    }
}
int main() {
    n=read(),d1=read(),d2=read();
    for (register int i=0;i<=d1;i++) {
        const int j=sqrt(d1-i*i);
        if (i*i+j*j!=d1) continue;
        v[0].emplace_back(std::make_pair(i,j));
        v[0].emplace_back(std::make_pair(-i,j));
        v[0].emplace_back(std::make_pair(i,-j));
        v[0].emplace_back(std::make_pair(-i,-j));
    }
    for (register int i=0;i<=d2;i++) {
        const int j=sqrt(d2-i*i);
        if (i*i+j*j!=d2) continue;
        v[1].emplace_back(std::make_pair(i,j));
        v[1].emplace_back(std::make_pair(-i,j));
        v[1].emplace_back(std::make_pair(i,-j));
        v[1].emplace_back(std::make_pair(-i,-j));
    }
    for (register int i=0;i<n*2;i++) {
        for (register int j=0;j<n*2;j++) {
            if (!col[0][id(i,j)]) {
                col[0][id(i,j)]=1;
                dfs(id(i,j),0);
            }
            if (!col[1][id(i,j)]) {
                col[1][id(i,j)]=1;
                dfs(id(i,j),1);
            }
        }
    }
    for (register int i=0,cnt=0;i<n*2;i++){
        for (register int j=0;j<n*2;j++) {
            if (col[0][id(i,j)]==1 && col[1][id(i,j)]==1) {
                printf("%d %d\n",i,j);
                if (++cnt==n*n) return 0;
            }
        }
    }
}


#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <numeric>
#include <string>
#include <cstdio>
#include <cstring>
#include <queue>
#include <stack>
#include <set>
#include <cmath>
#include <bitset>
#include <iomanip>

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

#define FALSE printf("false\n");
#define TRUE printf("true\n");
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i = 0;(i) < ((int)(n));++(i))
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() )
#define test(a) cout<<"line:"<<__LINE__<<"["<<(#a)<<": "<<(a)<<"]"<<endl

const int INF = 1e9+7;
const ll INFL = 9*1e18;

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

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

ll inline digit(ll num){int tmp = 0;while(num){tmp++;num/=10;}return tmp;} // 桁数
template<typename T>inline void print(T&& x){cout<<x<<endl;}// 改行付き出力
template<typename T>inline T SUM(vector<T> vec){return accumulate(all(vec),(T)0);} // vectorの中身を全部足す
template<typename T>inline T digitSum(T num){T sum = 0;while(num){sum+=num%10;num/=10;}return sum;} // 各桁の和
template<typename T>inline T gcd(T a,T b){if(b == 0)return a;return gcd(b,a%b);} // 最大公約数
template<typename T>inline T lcm(T a, T b){T g = gcd(a,b);return a/g*b;} // 最小公倍数
template<typename T>inline T power(T a,T b){T tmp=1;rep(i,b){tmp*=a;}return tmp;} // 累乗
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 ctoi(char c){return c-'0';}

vector<long long> primes(long long N) {
    vector<long long> res;
    for (long long i = 1; i * i <= N; ++i) {
        if (N % i == 0) {
            res.push_back(i);
            if (N/i != i) res.push_back(N/i);
        }
    }
    sort(res.begin(), res.end());
    return res;
}

// TODO: write
int main() {
  int n;cin>>n;
  vector<int> a(n+1);rep(i,n)cin>>a[i+1];
  vector<int> b(n+1,0);

  vector<int> ans;
  for(int i = n;i > 0;--i){
    if(b[i]%2 == a[i])continue;
    auto p = primes(i);
    ans.pb(i);
    for(auto&& one: p){
      b[one]++;
    }
  }

  print(ans.size());
  for(auto&& one: ans){
    cout<<one<<" ";
  }
  cout<<endl;

  return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define M 1000000007
long long int power(int a,int b)
{
    if(b==0)
        return 1;
    long long int k=power(a,b/2);
    if(b%2==0)
        return ((k%M)*(k%M))%M;
    else
        return ((k%M)*(k%M)*(a%M))%M;
}
long long int fact(long long int n)
{
    if(n==1 || n==0)
        return 1;
    else
        return ((n%M)*(fact(n-1)%M))%M;

}
int div(int n)
{  int c=0;
    for(int i=1;i<sqrt(n);i++)
    {
        if(n%i==0)
        {
          c++;
        }
    }
    c=c*2;
    if(pow(sqrt(n),2)==(sqrt(n)*sqrt(n)))
        c++;
    return  c;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
     #ifndef ONLINE_JUDGE

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

   #endif
   int n;
   cin>>n;
   int cmin=32;
   for(int i=0;i<n;i++)
   {
    int h;
    cin>>h;
    int j;
    for(j=0;j<32;j++)
    {
         if(h&(1<<j))
            break;
    }
      cmin=min(cmin,j);
   }
   cout<<cmin;

 return 0;
}


#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vll = vector<ll>;
#define all(x) (x).begin(), (x).end()
#define fsp(x) fixed << setprecision(x)
const ll inf = LLONG_MAX;
const long double pi = acos(-1);
void Yes() {cout << "Yes" << endl;}
void No() {cout << "No" << endl;}
void YES() {cout << "YES" << endl;}
void NO() {cout << "NO" << endl;}

int main() {
	//ios::sync_with_stdio(false);
	//cin.tie(nullptr);
	const ll p = 1e9 + 7;
	//const ll p = 998244353;

	ll n, a, b;
	cin >> n >> a >> b;
	vll x(n);
	for (ll i = 0; i < n; i++) cin >> x[i];

	ll ans = 0;
	for (ll i = 0; i < n - 1; i++) ans += min(a * (x[i + 1] - x[i]), b);
	cout << ans << endl;
}

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

main() {
	int n;
	cin>>n;
	int arr[2*n];
	for(int i=0; i<2*n; i++){
		cin>>arr[i];
	}
	sort(arr, arr+2*n);
	int sum=0;
	for(int i=0; i<2*n; i=i+2){
		sum+=arr[i];
	}
	cout<<sum;
	return 0;
}


#include <cassert>
#include <cmath>
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <limits.h>
#include <map>
#include <queue>
#include <set>
#include <string.h>
#include <vector>

using namespace std;
typedef long long ll;

int N, K;
vector<int> A;

void simulate() {
  int RUI[N + 1];
  memset(RUI, 0, sizeof(RUI));

  for (int i = 0; i < N; ++i) {
    int a = A[i];

    int left = max(0, i - a);
    int right = min(N - 1, i + a);

    RUI[left]++;
    RUI[right + 1]--;
  }

  int sum = 0;
  for (int i = 0; i < N; ++i) {
    sum += RUI[i];
    A[i] = sum;
  }
}

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

  int a;
  for (int i = 0; i < N; ++i) {
    cin >> a;
    A.push_back(a);
  }

  for (int i = 0; i < min(100, K); ++i) {
    simulate();
  }

  for (int i = 0; i < N; ++i) {
    cout << A[i];

    if (i != N - 1) {
      cout << " ";
    }
  }

  cout << endl;

  return 0;
}

#include <bits/stdc++.h>

#define ll long long
#define str string
#define pii pair<int, int>
#define pll pair<ll, ll>
#define fi first
#define se second

#define vc vector<char>
#define vvc vector<vc>
#define vi vector<int>
#define vll vector<ll>
#define vvi vector<vi>
#define vvll vector<vll>
#define vvvll vector<vvll>
#define vs vector<str>
#define vvs vector<vs>
#define vpii vector<pii>
#define vvpii vector<vpii>
#define vpll vector<pll>
#define vvpll vector<vpll>
#define vb vector<bool>
#define vvb vector<vb>
#define rep(i, a, b) for (int i = (a); i < int(b); i++)
#define repi(i, a, b) for (int i = (a); i <= int(b); i++)

using namespace std;
ll INF = LONG_LONG_MAX;
ll mod = 1000000000 + 7;

template <typename T, typename L>
void readVector(vector<T> & _data, L & _size, bool _shift) {
    _data.resize(_size + (ll)_shift);
    for (ll i = (ll)_shift; i < _size + (ll)_shift; i++)
        cin >> _data[i];
}

template <typename T, typename L>
void readMatrix(vector<vector<T>> & _data, L & _rows, L & _cols, bool _shiftRows, bool _shiftCols) {
    _data.resize(_rows + (ll)_shiftRows);
    for (ll i = 0; i < _rows + (ll)_shiftRows; i++)
        _data[i].resize(_cols + (ll)_shiftCols);
    for (ll i = (ll)_shiftRows; i < _rows + (ll)_shiftRows; i++)
        for (ll j = (ll)_shiftCols; j < _cols + (ll)_shiftCols; j++)
            cin >> _data[i][j];
}

//TODO: SOLUTION

ll n;
vll a, pre, f, g;

void computeG() {
    ll j = n - 2;
    g[n - 1] = n;

    while (j >= 1) {
        int k = g[j + 1];
        while (abs(pre[n] - (2*pre[k - 1]) + pre[j - 1]) > abs(pre[n] - (2*pre[k - 2]) + pre[j - 1]))
            k--;
        g[j] = k;
        j--;
    }
}

void computeF() {
    ll j = 3;
    f[2] = 1;

    while (j <= n) {
        int k = f[j - 1];
        while (abs(pre[j] - (2*pre[k])) > abs(pre[j] - (2*pre[k + 1])))
            k++;
        f[j] = k;
        j++;
    }
}

void solve() {
    cin >> n;
    readVector(a, n, 1);
    pre.resize(n + 1, 0);

    repi(i, 1, n) {
        pre[i] = pre[i - 1] + a[i];
    }

    f.resize(n + 1);
    g.resize(n + 1);

    computeF();
    computeG();

    ll ans = INF;
    repi(i, 2, n - 2) {
        ans = min(ans, max(max(max(pre[f[i]], pre[i] - pre[f[i]]), pre[n] - pre[g[i + 1] - 1]), pre[g[i + 1] - 1] - pre[i])
                      -min(min(min(pre[f[i]], pre[i] - pre[f[i]]), pre[n] - pre[g[i + 1] - 1]), pre[g[i + 1] - 1] - pre[i]));
    }

    cout << ans << endl;
}

int main() {

    // TODO: Set value of this variable manually
    bool _multipleTestCases = false;

    if (_multipleTestCases) {
        ll t; cin >> t;
        while (t--)
            solve();
    }
    else {
        solve();
    }

    return 0;
}


#include<iostream>
#include<vector>
using namespace std;
const int MOD=1000000007;
void add(long long &a,long long b){a+=b;if(a>=MOD)a-=MOD;}

int H,W,K;
long long solve(){
    --K;
    vector<vector<long long> > dp(H+1,vector<long long>(W,0));
    dp[0][0]=1;
    for(int i=0;i<H;i++){
        for(int j=0;j<W;j++){
            for(int bit=0;bit<1<<(W-1);bit++){
                bool ok=true;
                for(int k=0;k<W-2;k++){
                    if((bit&(1<<k))&&(bit&(1<<(k+1)))) ok=false;
                }
                if(!ok)continue;
                int nj=j;
                if(bit&(1<<j))nj=j+1;
                else if(j>0&&(bit&(1<<(j-1))))nj=j-1;
                add(dp[i+1][nj],dp[i][j]);
            }
        }
    }
    return dp[H][K];
}

int main(){
    while(cin>>H>>W>>K)cout<<solve()<<endl;
}


#include<bits/stdc++.h>
using namespace std;
#define mp make_pair
#define se second
#define fi first
const int N=2000005;
int n,m,tot,l,x,y,z,f[N],dis[N],to[N],ne[N],fi[N],zz[N],g[N];
vector<pair<int ,int> > G[N];
vector<int> v;
void jb(int x,int y){
	ne[++tot]=fi[x];
	fi[x]=tot;
	zz[tot]=y;
}
int find(int x){
	if (x==f[x])return x;
	return f[x]=find(f[x]);
}
void up(int x){
	if (x==1)return;
	if (dis[f[x]]<dis[f[x/2]]){
		swap(f[x],f[x/2]);
		swap(g[f[x]],g[f[x/2]]);
		up(x/2);
	}
}
void down(int x){
	int i=x;
	if (x*2<=l&&dis[f[x*2]]<dis[f[x]])i=x*2;
	if (x*2<l&&dis[f[x*2+1]]<dis[f[i]])i=x*2+1;
	if (i!=x){
		swap(f[x],f[i]);
		swap(g[f[x]],g[f[i]]);
		down(i);
	}
}
int main(){
	scanf("%d%d",&n,&m);
	while (m--){
		scanf("%d%d%d",&x,&y,&z);
		G[z].push_back(mp(x,y));
	}
	for (int i=1;i<=n;i++)f[i]=i;
	int cnt=n;
	for (int i=1;i<=1000000;i++){
		v.clear();
		for (int j=0;j<G[i].size();j++)f[find(G[i][j].fi)]=find(G[i][j].se);
		for (int j=0;j<G[i].size();j++)v.push_back(G[i][j].fi),v.push_back(G[i][j].se);
		for (int j=0;j<v.size();j++)
			if (find(v[j])==v[j])to[v[j]]=++cnt;
		for (int j=0;j<v.size();j++)jb(to[find(v[j])],v[j]),jb(v[j],to[find(v[j])]);
		for (int j=0;j<v.size();j++)f[v[j]]=v[j];
	}
	dis[1]=0;
	for (int i=2;i<=cnt;i++)dis[i]=1e9;
	for (int i=1;i<=cnt;i++)f[i]=g[i]=i;
	l=cnt;
	for (int i=cnt;i;i--)down(i);
	for (int i=1;i<=cnt;i++){
		int k=f[1];
		f[1]=f[l--];
		g[f[1]]=1;
		down(1);
		for (int j=fi[k];j;j=ne[j])
			if (dis[zz[j]]>dis[k]+1){
				dis[zz[j]]=dis[k]+1;
				up(g[zz[j]]);
			}
	}
	if (dis[n]==1e9)puts("-1");
	else printf("%d\n",dis[n]/2);
	return 0;
}

#include <bits/stdc++.h>
#define enter putchar('\n')
#define space putchar(' ')
#define pb push_back
#define mp make_pair
#define fi first
#define se second
using namespace std;
typedef pair<int, int> pii;
map<pii, int> M;
vector<pii> E[500005];
set<pii> s;
int n, m, ncnt, d[500005];
template <class T> int read(T &x) {
	x = 0; int f = 1; char c = getchar();
	while (c > -1 && c < '0' || c > '9') { if (c == '-') f = -1; c = getchar(); }
	if (c == -1) return 0;
	while (c >= '0' && c <= '9') { x = x * 10 + c - 48; c = getchar(); }
	return x *= f, 1;
}
template <class T> void write(T x) {
	if (x < 0) x = -x, putchar('-');
	if (x > 9) write(x / 10);
	putchar(x % 10 + 48);
}
int main() {
	while (read(n), read(m)) {
		M.clear();
		ncnt = n;
		for (int i = 1; i <= n; ++i)
			E[i].clear();
		for (int i = 1; i <= m; ++i) {
			int u, v, c;
			read(u), read(v), read(c);
			if (!M[mp(u, c)]) {
				M[mp(u, c)] = ++ncnt;
				E[ncnt].clear();
				E[ncnt].pb(mp(u, 1));
				E[u].pb(mp(ncnt, 1));
			}
			if (!M[mp(v, c)]) {
				M[mp(v, c)] = ++ncnt;
				E[ncnt].clear();
				E[ncnt].pb(mp(v, 1));
				E[v].pb(mp(ncnt, 1));
			}
			E[M[mp(u, c)]].pb(mp(M[mp(v, c)], 0));
			E[M[mp(v, c)]].pb(mp(M[mp(u, c)], 0));
		}
		fill(d, d + ncnt + 1, -1);
		d[1] = 0;
		s.insert(mp(d[1], 1));
		while (!s.empty()) {
			int u = s.begin() -> se;
			s.erase(s.begin());
			for (int i = 0; i < E[u].size(); ++i) {
				int v = E[u][i].fi;
				if (d[v] > d[u] + E[u][i].se || d[v] == -1) {
					s.erase(mp(d[v], v));
					d[v] = d[u] + E[u][i].se;
					s.insert(mp(d[v], v));
				}
			}
		}
		write(d[n] >> 1), enter;
	}
	return 0;
}


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

typedef long long i64;

int D, len = 0;
i64 pw[20], result = 0;

void work(int x, int L, i64 rest, i64 way) {
  if (x == L / 2) {
    if (rest == 0) result += way * ((L & 1) ? 10 : 1);

    return;
  }

  if ((L & 1) && x == L / 2) {
    work(x + 1, L, rest, way * 9);
  } else {
    if (pw[L - x - 1] - pw[x] > 0) {
      for (int i = -9; i <= 10; ++i) {
	if ((pw[L - x - 1] - pw[x]) * i > rest) {
	  if (i != 10) work(x + 1, L, rest - (pw[L - x - 1] - pw[x]) * i, way * (9 - abs(i) + (x != 0)));
	  if (i > -9) work(x + 1, L, rest - (pw[L - x - 1] - pw[x]) * (i - 1), way * (9 - abs(i - 1) + (x != 0)));
	  break;
	}
      }
    } else {
      for (int i = 9; i >= -10; --i) {
	if ((pw[L - x - 1] - pw[x]) * i > rest) {
	  if (i != -10) work(x + 1, L, rest - (pw[L - x - 1] - pw[x]) * i, way * (9 - abs(i) + (x != 0)));
	  if (i < 9) work(x + 1, L, rest - (pw[L - x - 1] - pw[x]) * (i + 1), way * (9 - abs(i + 1) + (x != 0)));
	  break;
	}
      }
    }
  }

}

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

  pw[0] = 1;

  for (int i = 1; i < 20; ++i) pw[i] = pw[i - 1] * 10;

  for (int i = 18; i; --i)
    work(0, i, D, 1);

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

#include<bits/stdc++.h>
#define fo(i,a,b) for(i=a;i<=b;i++)
#define fd(i,a,b) for(i=a;i>=b;i--)
#define min(a,b) (a<b?a:b)
#define max(a,b) (a>b?a:b)
typedef long long ll;
using namespace std;
int d,k,L,i,j,ten[15],a[25];
int s[25],mx,f[25];ll ans,an;
void dfs(int x,ll now){
	if (L-x>=k-1&&abs(now)>=10) return;
	if (now<0) return;
	int i;
	if (x>mx){
		an=a[s[1]+9]-(s[1]<=0);
		if (L&1) an*=10-(L==1);
		s[L]=-s[1];
		fo(i,2,mx) an*=a[s[i]+9],s[L-i+1]=-s[i];
		ll p=0;
		fd(i,L,1){
			p=p*10+s[i];
			if (p>d) return;
		}if (p==d) ans+=an;
		return;
	}
	fo(i,-9,9) s[x]=i,dfs(x+1,now*10-i);
}
int main(){
	ten[0]=1;
	fo(i,1,9) ten[i]=ten[i-1]*10;
	scanf("%d",&d);
	fo(i,1,9) if (d<ten[i]) break;
	k=i+1;
	fo(i,0,9)
	fo(j,0,9) a[i-j+9]++;
	fo(L,2,k<<1){
		mx=L>>1;
		memset(s,0,sizeof(s));
		dfs(1,0);
	}
	printf("%lld\n",ans);
}


#include <bits/stdc++.h>
using namespace std;
#define all(n) begin(n), end(n)
const long long INF = numeric_limits<long long>::max();
typedef long long ll;
typedef vector<int> vint;
typedef vector<vector<int>> vvint;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef unsigned long long ull;
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;
}
template <typename T>
vector<T> make_v(size_t a) { return vector<T>(a); }

template <typename T, typename... Ts>
auto make_v(size_t a, Ts... ts)
{
    return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}
template <typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type
fill_v(T &t, const V &v) { t = v; }

template <typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type
fill_v(T &t, const V &v)
{
    for (auto &e : t)
        fill_v(e, v);
}
int main()
{
    int N,K;
    cin>>N>>K;
    vector<long double> p(N),psum(N);
    for (size_t i = 0; i < N; i++)
    {
        long double q;
        cin>>q;
        p[i]=(q+(long double)1)/(long double)2;
    }
    partial_sum(all(p),psum.begin());
    long double ans = psum[K-1];
    for (size_t i = 0; i+K < N; i++)
    {
        chmax(ans,psum[i+K]-psum[i]);
    }
    cout<<setprecision(30)<<ans<<endl;
    return 0;
}

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

int main(){
  //in
  int n, k;
  cin >> n >> k;
  vector<int> p(n);
  REP(i,n) cin >> p[i];

  //

  int ex = 0;
  //前処理
  REP(i,k){
    int px = p[i]+1;
    ex += px;
  }
  int exmax = ex;

  REP2(i,k,n){
    ex -= p[i-k];
    ex += p[i];
    exmax = max(ex,exmax);
  }

  double ans = (double)exmax/2;

  cout << fixed << setprecision(10) << ans << endl;

  return 0;
}


#include <algorithm>
#include <cmath>
#include <climits>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <cassert>
#include <functional>

using namespace std;

#define LOG(...) printf(__VA_ARGS__)
//#define LOG(...)
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define RSORT(c) sort((c).rbegin(),(c).rend())
#define CLR(a) memset((a), 0 ,sizeof(a))

typedef long long ll;
typedef unsigned long long ull;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vb> vvb;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

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

int main() {
	int length[10];
	int v1;
	int v2;
	char comma;
	while (cin>>length[0]>>comma>> length[1]>>comma>> length[2]>>comma>> length[3]>>comma>> length[4]>>comma>> length[5]>>comma>> length[6]>>comma>> length[7]>>comma>> length[8]>>comma>>length[9]>>comma>>v1>>comma>>v2){
	double sum=0;
	REP(i,10)
		sum += length[i];
	double time = sum / (double)(v1+v2);
	double go=time*(double)v1;
	REP(i,10){
		if (go <= (double)length[i] + 1e-10){
		cout<<(i+1)<<endl;
		break;
		}else
			go -= (double)length[i];
	}
	}
	return 0;
}

#include <iostream>
using namespace std;

int main(){
	double t[10], a, b;
	char c;
	while(cin >> t[0] >> c){
		for(int i = 1;i< 10;i++){cin >> t[i] >> c;t[i] += t[i-1];}
		cin >> a >> c >> b;
		double tmp = t[9]/(a+b)*a;
		int ans = 1;
		while(tmp > t[ans-1])ans++;
		cout << ans << endl;
	}
	return 0;
}


// C++ 14
#include <bits/stdc++.h>
using namespace std;
template <typename T>  ostream& operator<<(ostream& os, const vector<T>& v)  {  os << "[";  for (int i = 0; i < v.size(); ++i) {  os << v[i];  if (i != v.size() - 1)  os << ", ";  }  os << "]";  return os;  }
template <typename T> void print(T v, string s = "\n") { cout << v << s; }
template <typename T> void in(T &v) { cin >> v; }
#define ll long long
#define loop(__x, __start, __end) for(int __x = __start; __x < __end; __x++)

int main() {
  int n, m; in(n),in(m);
  vector<bool> ac(n+1, false);
  vector<int> wa(n+1, 0);
  int p; string s;
  loop(i,0,m) {
    in(p),in(s);
    if (ac[p]) continue;
    if (s == "WA") wa[p]++;
    else ac[p] = true;
  }
  loop(p,1,n+1) if (!ac[p]) wa[p] = 0;

  int ans1 = 0;
  for (auto&&b: ac) ans1+=b;
  int ans2 = 0;
  for (auto&&w: wa) ans2+=w;
  print(ans1, " ");
  print(ans2);
  return 0;
}

#include"bits/stdc++.h"
using namespace std;
const int N=5e3+100;
typedef long long LL;
struct node{
	LL h,p;
}a[N];
LL dp[N];
bool cmp(node a,node b){
	if(a.h+a.p==b.h+b.p)return a.h<b.h;
	return a.h+a.p<b.h+b.p;
}

int main()
{
	int n;
	scanf("%d",&n);
	for(int i=0;i<=5050;i++)dp[i]=0x3f3f3f3f3f3f3f3f;
	for(int i=1;i<=n;i++)
		scanf("%d %d",&a[i].h,&a[i].p);
	sort(a+1,a+n+1,cmp);
	dp[0]=0;
	for(int i=1;i<=n;i++){
		for(int j=i-1;j>=0;j--){
			if(a[i].h>=dp[j]){
				dp[j+1]=min(dp[j+1],dp[j]+a[i].p);
			}
		}
	}
	int ans=1;
	for(int i=2;i<=n;i++)
		if(dp[i]!=0x3f3f3f3f3f3f3f3f)ans=i;
	printf("%d\n",ans);
}


#include <iostream>
using namespace std;

int fld[100][100];//[横][縦]
int Dx[4]={0,-1,0,1};
int Dy[4]={1,0,-1,0};

bool ans[1000];
int counter=0;

bool flag=true;

void dfs(int x,int y,int w,int h,int c){//スタート地点と色を与える
	fld[x][y]=-1;
	for(int i=0;i<4;i++){
		int nx=x+Dx[i],ny=y+Dy[i];//範囲内にある必要あり
		if(nx>=0 && nx<w && ny>=0 && ny<h){
		if(fld[nx][ny]==c)//同色についてのみ継続
			dfs(nx,ny,w,h,c);
		}
	}
}//色の塗り替え

void solve(){
	int w,h,xs,ys,xg,yg,n;
	cin >> w>>h;

	if(w==0) {flag=false;counter--; return;}

	cin >>xs>>ys>>xg>>yg>>n;//start,goal座標は-1する
	xs--;ys--;xg--;yg--;

	for(int i=0;i<w;i++){//fieldの初期化0~w-1
		for(int j=0;j<h;j++){//0~h-1
			fld[i][j]=0;//0は何も無い
		}
	}

	for(int i=0;i<n;i++){
		int color,drc,x,y;
		cin >>color>>drc>>x>>y;
		x--;y--;
		if(drc==0){
			for(int dx=0;dx<4;dx++){
				for(int dy=0;dy<2;dy++){
					fld[x+dx][y+dy]=color;
				}
			}
		}
		if(drc==1){
			for(int dy=0;dy<4;dy++){
				for(int dx=0;dx<2;dx++){
					fld[x+dx][y+dy]=color;
				}
			}
		}
	}//fieldの色塗り

	if(fld[xs][ys]!=fld[xg][yg]) {
		ans[counter]=false;
		return;
	}
	if(fld[xs][ys]==0){
		ans[counter]=false;
		return;
	}

	dfs(xs,ys,w,h,fld[xs][ys]);//塗り替え

	if(fld[xg][yg]==-1) ans[counter]=true;
	else ans[counter]=false;

	return;
}

int main(){
	while(flag){
		solve();
		counter++;
	}
	for(int i=0;i<counter;i++){
		if(ans[i]) cout << "OK"<<endl;
		else cout << "NG" << endl;
	}

}

#include<iostream>
#include<vector>
#include<queue>
#include<map>
using namespace std;
int n,m;
map<int,vector<pair<int,int> > >G[1<<17];
map<int,int>d[1<<17];
main()
{
	cin>>n>>m;
	for(int i=0;i<m;i++)
	{
		int a,b,c;cin>>a>>b>>c;
		G[a][c].push_back(make_pair(b,c));
		G[b][c].push_back(make_pair(a,c));
		G[a][c].push_back(make_pair(a,0));
		G[b][c].push_back(make_pair(b,0));
		G[a][0].push_back(make_pair(b,c));
		G[b][0].push_back(make_pair(a,c));
	}
	priority_queue<pair<int,pair<int,int> > >P;
	d[1][0]=0;
	P.push(make_pair(0,make_pair(1,0)));
	while(!P.empty())
	{
		int dis=-P.top().first;
		int u=P.top().second.first;
		int c=P.top().second.second;
		P.pop();
		if(u==n&&c==0)
		{
			cout<<dis<<endl;
			return 0;
		}
		if(d[u][c]<dis)continue;
		for(pair<int,int>&p:G[u][c])
		{
			int v=p.first;
			int cost=dis+!c;
			int col=p.second;
			if(d[v].find(col)==d[v].end()||d[v][col]>cost)
			{
				d[v][col]=cost;
				P.push(make_pair(-cost,make_pair(v,col)));
			}
		}
	}
	cout<<-1<<endl;
}


#include<iostream>
using namespace std;

int main() {
	int n;
	cin >> n;
	int p[100] = {};

	for (int i = 0;i < n*(n - 1) / 2;i++) {
		int a, b, c, d;
		cin >> a >> b >> c >> d;
		if (c > d)p[a - 1] += 3;
		else if (c < d)p[b - 1] += 3;
		else {
			p[a - 1]++;
			p[b - 1]++;
		}
	}
	int ans[100];
	for (int i = 0;i < n;i++) {
		int a = 0;
		for (int j = 0;j < n;j++) {
			if (p[i] < p[j])a++;
		}
		ans[i] = a + 1;
	}
	for (int i = 0;i < n;i++)cout << ans[i] << endl;
	return 0;
}

#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <sstream>
#include <functional>
#include <numeric>
#include <cmath>
#include <cstring>
#include <queue>

using namespace std;
int n;

const int INF = 1 << 29;

typedef pair<int,int> P;
vector<P> teams;
bool sortSecond(const P& p1, const P& p2)
{
	if(p1.second != p2.second) return p1.second < p2.second;
	if(p1.first != p2.first) return p1.first < p2.first;
	return false;
}

int main(void)
{
	while(cin >> n && n)
	{
		teams.resize(n);
		for (int i = 0; i < n; i++)
		{
			teams[i] = P(0, i);
		}
		for (int i = 0, leags = n * (n - 1) / 2; i < leags; i++)
		{
			int a, b, c, d;
			cin >> a >> b >> c >> d;
			if(c == d)
			{
				teams[a - 1].first++;
				teams[b - 1].first++;
			}
			else if(c > d) teams[a - 1].first += 3;
			else teams[b - 1].first += 3;
		}
		sort(teams.begin(), teams.end(), greater<P>());
		int hikiwake = 0;
		for (int i = 0; i < n; i++)
		{
			int tmp = teams[i].first;
			teams[i].first = i + 1 - hikiwake;
			if(i + 1 < n && tmp == teams[i + 1].first)
			{
				hikiwake++;
			}
			else hikiwake = 0;
		}
		sort(teams.begin(), teams.end(), sortSecond);
		for (int i = 0; i < n; i++)
		{
			cout << teams[i].first << endl;
		}
	}
	return 0;
}