#include <algorithm>
#include <bitset>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <cctype>
#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <limits>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using namespace std;
using ll = long long;
using ld = long double;
#define endl "\n"
//#define int long long
#define ALL(x) begin(x),end(x)
#define RALL(a) (a).rbegin(), (a).rend()
#define _CRT_SECURE_NO_WARNINGS
#define rep(i, n) for (int i = 0; i < n; i++)
const int MOD = 1e9 + 7;
const ll INF = 1LL << 60;
const int inf = 1 << 25;
constexpr long double pi = 3.141592653589793238462643383279;
int dx[] = { 1,0,-1,0 };
int dy[] = { 0,1,0,-1 };
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
ll fact(ll i) {
    if (i == 0) return 1;
    return ((fact(i - 1)) * i) % MOD;
}
ll gcd(ll a, ll b) {
    if (b == 0) return a;
    return gcd(b, a % b);
}
ll lcm(ll a, ll b) {
    return a * b / gcd(a, b);
}
ll keta(ll n) {
    if (n == 0) return 1;
    ll count = 0;
    while (n != 0) {
        n /= 10;
        count++;
    }
    return count;
}
ll ketasum(ll n) {
    ll sum = 0;
    while (n != 0) {
        sum += n % 10;
        n /= 10;
    }
    return sum;
}
ll mch(ll n) {
    if (n == 1) return 1;
    else return n * mch(n - 1);
}
ll modpow(ll a, ll n, ll mod) {
    ll hi = 1;
    while (n > 0) {
        if (n & 1) hi = hi * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return hi;
}
bool is_prime(const unsigned n) {
    switch (n) {
    case 0: // fall-through
    case 1: return false;
    case 2: // fall-through
    case 3: return true;
    } // n > 3 が保証された
    if (n % 2 == 0 || n % 3 == 0) return false;
    for (unsigned i = 5; i * i <= n; i += 6) {
        if (n % i == 0) return false; // (6の倍数)-1
        if (n % (i + 2) == 0) return false; // (6の倍数)+1
    }
    return true;
}
/*signed*/int main(void) {
    int n, m;
    cin >> n >> m;
    vector<pair<int, int>> p(m);
    rep(i, m) {
        int s, c;
        cin >> s >> c;
        s--;
        p[i] = make_pair(s, c);
    }
    rep(i, 1000) {
        string s = to_string(i);
        if (s.size() == n) {
            bool ans = true;
            rep(j, m) {
                if ((s[p[j].first] - '0') != p[j].second)ans = false;
            }
            if (ans) {
                cout << i << endl;
                return 0;
            }
        }
    }
    cout << -1 << endl;
    return 0;
}

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

int main() {
    int n, m, s, c;
    int ans = 0;
    vector<int> a(5, -1);

    cin >> n >> m;
    for (int i = 0; i < m; i++) {
        cin >> s >> c;

        if (s == 1 && c == 0 && n != 1) ans = -1;

        if (a[s] == -1 || a[s] == c) a[s] = c;
        else ans = -1;
    }

    if (ans == -1) cout << ans << endl;
    else {
        if (a[1] == -1 && n != 1) a[1] = 1;
        for(int i = 1; i <= n; i++) {
            if (a[i] == -1) a[i] = 0;
            cout << a[i];
        }
        cout << endl;
    }
}


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

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

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

void solve() {
    string s, t;
    cin >> t >> s;
    cout << s + t;
}

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

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

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
using P = pair<ll, ll>;
using V = vector<ll>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep1(i, n) for(ll i=1;i<=(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
#define ALL(obj) (obj).begin(), (obj).end()
#define RALL(obj) (obj).rbegin(), (obj).rend()
#define MOD 1000000007
#define INF 1000000000
#define LLINF 1e18

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

void solve_abc_a() {
	ll n, m;
	ll x, y;
	ll a, b, d;
	ll c;
	//char c;
	ll h, w;
	ll k;
	string s, t;
	//ll s, t;
	ll l_ans = 0;
	string s_ans = "NG";

	V val(3, 0);
	cin >> val[0] >> val[1] >> val[2] >> k;
	sort(ALL(val));

	val[2] = val[2] * pow(2, k);

	l_ans = val[0] + val[1] + val[2];

	cout << l_ans << "\n";

	return;
}

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

	solve_abc_a();

	return 0;
}


// 2016-12-03
#include <iostream>
#include <cmath>
using namespace std;

int main() {
	int m, min, max, n;
	int p[200];
	while (cin >> m >> min >> max, m) {
		for (int i = 0; i < m; i++) {
			cin >> p[i];
		}
		n = min - 1;
		for (int i = min; i < max; i++) {
			if (p[i] - p[i + 1] >= p[n] - p[n + 1]) {
				n = i;
			}
		}
		cout << n + 1 << endl;
	}
	return 0;
}

#include <iostream>
#include <stdio.h>
#include <string.h>
#include <string>
#include <functional>
#include <algorithm>
#include <string>
#include <vector>
#include <algorithm>
#include <time.h>
#include <stdlib.h>
#include <math.h>

using namespace std;

int main (void)
{
	long m,min,max,p[10000],g[10000],kkk,rrr;

	for (long o = 0; o < 10000; o++)
	{
	cin >> m >> min >> max;

	if (m == 0 && min == 0)
	{
		if (max == 0)
		{
			break;
		}
	}

	kkk = 0;

	for (long i = 1; i < m + 1; i++)
	{
		cin >> p[i];
	}

	for (long j = min; j < max + 1; j++)
	{
		g[j] = p[j] - p[j + 1];

		if (kkk <= g[j])
		{
			kkk = 0;
			kkk = g[j];
			rrr = 0;
			rrr = j;
		}
	}

		cout << rrr << endl;
	}
}


#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;
#define rep(i, begin, n) for (int i = begin; i < n; i++)
#define repe(i, begin, n) for (int i = begin; i <= n; i++)
#define repr(i, begin, n) for (int i = begin; i > begin - n; i--)
#define repre(i, begin, end) for (int i = begin; i >= end; i--)

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

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

const int inf = INT_MAX;
const int MOD = 1000000007;
const long long INF = LLONG_MAX;

// -------------------------------------------------------

ll x;

int main() {
  cin >> x;
  ll q = x / 11;
  ll r = x % 11;
  if (r == 0) {
    cout << q * 2;
    return 0;
  }

  if (1 <= r && r <= 6) {
    cout << q * 2 + 1;
    return 0;
  }

  cout << q * 2 + 2;
}

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

long long int gcd(long long int a,long long int b){
    if(a%b==0){
        return b;
    }
    else{
        return gcd(b,a%b);
    }
}
long long int fac(long long int n){
    if(n==0){
        return 1;
    }
    else{
        return n*(fac(n-1))%1000000007;
    }
}

int main(){
    long long int n,k,ans=0;
    cin>>n;
    ans+=2*((n-1)/11);
    if(n%11<7&&n%11>0){
        ans++;
    }
    else{
        ans++;
        ans++;
    }
    cout<<ans<<endl;
    return 0;
}


#include<iostream>
#include<vector>
#include<string>
#include<sstream>
int main()
{
	std::vector<std::string>result;
	for (std::string s; std::getline(std::cin, s);)
	{
		int delta = 0;
		std::stringstream ss;
		ss << s;
		while (!ss.eof())
		{
			std::string temp;
			ss >> temp;
			if (temp.length() == 3 && temp[0] != '.' && temp[1] != '.' && temp[2] != '.')
			{
				int d1 = temp[0] - 't';
				int d2 = temp[1] - 'h';
				int d3 = temp[2] - 'e';
				for (auto i : { &d1,&d2,&d3 })
				{
					if (*i < 0)
					{
						*i += 26;
					}
				}
				if (d1 == d2 && d2 == d3)
				{
					delta = temp[0] - 't';
					break;
				}
			}
			else if (temp.length() == 4 && temp[0] != '.' && temp[1] != '.' && temp[2] != '.' && temp[3] != '.')
			{
				int d1 = temp[0] - 't';
				int d2 = temp[1] - 'h';
				int d3 = temp[2] - 'i';
				int d4 = temp[3] - 's';
				for (auto i : { &d1,&d2,&d3,&d4 })
				{
					if (*i < 0)
					{
						*i += 26;
					}
				}
				if (d1 == d2 && d2 == d3 && d3 == d4)
				{
					delta = temp[0] - 't';
					break;
				}
				d1 = temp[0] - 't';
				d2 = temp[1] - 'h';
				d3 = temp[2] - 'a';
				d4 = temp[3] - 't';
				for (auto i : { &d1,&d2,&d3,&d4 })
				{
					if (*i < 0)
					{
						*i += 26;
					}
				}
				if (d1 == d2 && d2 == d3 && d3 == d4)
				{
					delta = temp[0] - 't';
					break;
				}
			}
		}
		result.push_back(std::string(s.length(), 'a'));
		for (int i = 0; i < s.length(); i++)
		{
			result.back()[i] = 'a' <= s[i] && s[i] <= 'z' ? (s[i] - delta - 'a') % 26 + 'a' : s[i];
		}
	}
	for (auto i : result)
	{
		std::cout << i << std::endl;
	}
	return 0;
}

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

#define MAX 100
//#define NIL -1

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

Node *root, *NIL;
int n;

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

    z->key = val;
    z->left = NIL;
    z->right = NIL;

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

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

Node * find(Node *x, int val) {
    while ( x != NIL) {
        if (x->key == val) break;
        if (x->key > val) {
            x = x->left;
        } else {
            x = x->right;
        }
    }
    return x;
}

Node * getSuccessor(Node *u) {
    while (u->left != NIL) {
        u = u->left;
    }
    return u;
}

void delete_node(Node *u) {
    Node *y;
    Node *x;
    if (u->left != NIL && u->right != NIL) {
        y = getSuccessor(u->right);
    } else {
        y = u;
    }

    // search child
    if (y->left != NIL) {
        x = y->left;
    } else {
        x = y->right;
    }

    // set the parent to the child if it exists
    if (x != NIL) {
        x->parent = y->parent;
    }

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

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

    delete y;
}

void preorder(Node *u) {
    if (u == NIL) return;

    printf(" %d", u->key);
    preorder(u->left);
    preorder(u->right);
}

void inorder(Node *u) {
    if (u == NIL) return;

    inorder(u->left);
    printf(" %d", u->key);
    inorder(u->right);
}

void print() {
    inorder(root);
    printf("\n");
    preorder(root);
    printf("\n");
}

int main() {
    int val;
    char moji[10];

    scanf("%d", &n);
    for (int i = 0; i < n; i++) {
        scanf("%s", moji);
        if (moji[0] == 'i') {
            scanf("%d", &val);
            insert(val);
        } else if (moji[0] == 'f') {
            scanf("%d", &val);
            Node *t = find(root, val);
            if ( t != NIL ) printf("yes\n");
            else printf("no\n");
        } else if (moji[0] == 'd') {
            scanf("%d", &val);
            Node *t = find(root, val);
            delete_node(t);
        } else {
            print();
        }
    }

    return 0;
}


#include <cstdio>
#include <cstring>

int main() {
	char str[110];
	scanf("%s", str);
	str[strlen(str) - 8] = 0;
	puts(str);
	return 0;
}

#include "bits/stdc++.h"
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000

int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int R; cin >> R;
    if( R < 1200) cout << "ABC" << endl;
    else if (R < 2800) cout << "ARC" << endl;
    else cout << "AGC" << endl;

    return 0;
}


#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>

// Acknowledgement: Special thanks to kyomukyomupurin, who developed this
// template.
template <class T, class U>
std::ostream& operator<<(std::ostream& os, const std::pair<T, U>& p) {
  return os << '(' << p.first << ", " << p.second << ')';
}

template <class T>
std::ostream& operator<<(std::ostream& os, const std::vector<T>& vec) {
  int n = 0;
  for (auto e : vec) os << (n++ ? ", " : "{") << e;
  return os << (n ? "}" : "{}");
}

template <class T>
std::ostream& operator<<(std::ostream& os, const std::set<T>& st) {
  int n = 0;
  for (auto e : st) os << (n++ ? ", " : "{") << e;
  return os << (n ? "}" : "{}");
}

template <class T, class U>
std::ostream& operator<<(std::ostream& os, const std::map<T, U>& mp) {
  int n = 0;
  for (auto e : mp) os << (n++ ? ", " : "{") << e;
  return os << (n ? "}" : "{}");
}

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

#ifdef LOCAL
#define debug(...) \
  std::cerr << "[" << #__VA_ARGS__ << "]: ", debug_out(__VA_ARGS__)
#else
#define debug(...)
#endif

void debug_out() { std::cerr << '\n'; }

template <class Head, class... Tail>
void debug_out(Head&& head, Tail&&... tail) {
  std::cerr << head;
  if (sizeof...(Tail) != 0) std::cerr << ", ";
  debug_out(std::forward<Tail>(tail)...);
}
using namespace std;
using int64 = long long;

int main() {
  string X;
  cin >> X;
  int X_size = X.size();
  int delete_num = 0;
  int S_left_num = 0;
  for (int i = 0; i < X_size; i++) {
    if (X[i] == 'S')
      S_left_num++;
    else {
      if (S_left_num) {
        S_left_num--;
        delete_num += 2;
      }
    }
  }
  cout << X_size - delete_num << endl;
  return 0;
}

#include<iostream>
#include<cstdio>
#include<string>
using namespace std;
int main()
{
	string a;
	cin>>a;
	int tmp=a.find("ST");
	while(a.length()>0&&tmp>=0)
	{
		a.erase(tmp,2);
		int x=max(tmp-1,0);
		tmp=a.find("ST",x);
		if(tmp==string::npos&&(a[tmp]!='S'||a[tmp+1]!='T'))
			tmp=-1;
	}
	cout<<a.length()<<endl;
	return 0;
}


#include<bits/stdc++.h>

int main(){
    using namespace std;
    unsigned long N;
    cin >> N;
    unsigned long ans{~0UL};
    for(unsigned long i{0}, pa{~0UL}, a; i < N; ++i){
        cin >> a;
        if(pa + 1 < a)return 0 & puts("-1");
        if(pa + 1 == a)++ans;
        else ans += a;
        pa = a;
    }
    cout << ans << endl;
    return 0;
}

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

// boost
#include <boost/multiprecision/cpp_int.hpp>
using boost::multiprecision::cpp_int;

using ll = long long;
using ld = long double;

using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vb = vector<bool>;
using vs = vector<string>;
using vld = vector<ld>;
using vvld = vector<vld>;

typedef pair<ll, ll> P;

#define bit(n) (1LL << (n))

//#define int long long

#define all(v) v.begin(), v.end()

#define rep(i, n) for (ll i = 0; i < n; i++)
#define REP(i, n) for (ll i = 1; i < n; i++)

#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define FORm(i, m) for (auto i = m.begin(); i != m.end(); i++)

template <class T>
inline void chmax(T& a, T b) {
  a = std::max(a, b);
}
template <class T>
inline void chmin(T& a, T b) {
  a = std::min(a, b);
}

#define mod (ll)(1e9 + 7)
// #define mod (998244353ll)

const long long INF = 1LL << 60;

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

  ll n;
  cin >> n;
  vll a(n);
  rep(i, n) cin >> a[i];

  if (a[0] != 0) {
    cout << -1 << endl;
    return 0;
  }

  REP(i, n) {
    if (a[i] >= a[i - 1] + 2) {
      cout << -1 << endl;
      return 0;
    }
  }

  ll ans = a[n - 1];
  for (int i = n - 2; i > 0; i--) {
    if (a[i] != a[i + 1] - 1) {
      ans += a[i];
    }
  }

  cout << ans << endl;

  return 0;
}


#include <iostream>
#include <algorithm>
#include <fstream>
using namespace std;

int N = 0, M = 0;
int points[1001];
int scores[1002001];

bool check(int a, int c){
    if(a >= (N + 2) * (N + 1) / 2 - 1){
        return true;
    }
    return (scores[a] <= c && scores[a + 1] > c);
}

int search2(int a, int b, int c){
    int pib = a + b - b / 2;
    if(check(pib, c)){
        return pib;
    }else if(scores[pib] < c){
        return search2(pib, b / 2, c);
    }else{
        return search2(a, b / 2, c);
    }
}

int main(){
    for(;;){
        for(int i = 0; i < 1001; i++){
            points[i] = 0;
        }
        for(int i = 0; i < 1002001; i++){
            scores[i] = 0;
        }
        if(cin >> N){
            if(N == 0){
                break;
            }
            cin >> M;
            for(int i = 1; i <= N; i++){
                cin >> points[i];
            }
            for(int i = 0; i <= N; i++){
                for(int j = i; j <= N; j++){
                    scores[(2 * N - i + 1) * i / 2 + j] = points[i] + points[j];
                }
            }
            int mxsco = 0;
            sort(scores, scores + ((N + 2) * (N + 1)) / 2);
            for(int i = 0; i < (N + 2) * (N + 1) / 2; i++){
                if(scores[i] > M){
                    break;
                }
                int nosco = scores[i] + scores[search2(0, (N + 2) * (N + 1) / 2, M - scores[i])];
                if(nosco >= mxsco &&  nosco <= M){
                    mxsco = nosco;
                }
            }
            cout << mxsco << endl;
        }else{
            break;
        }
    }
    return 0;
}

#include <iostream>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <algorithm>
#include <cstdio>
#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 FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
#define INF 999999999
using namespace std;
typedef pair<int, int> P;

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

int n;
llong m;

int main(){
	while(1){
		scanf("%d%lld", &n, &m);
		if(n==0 && m==0) return 0;
		n++;
		vector<llong> p(n);
		p[0]=0;
		FOR(i, 1, n) scanf("%lld", &p[i]);
		VSORT(p);
		int size=0;
		vector<llong> v;
		REP(i, n){
			REP(j, n){
				v.push_back(p[i]+p[j]);
			}
		}
		VSORT(v);
		llong ans=0;
		REP(i, v.size()){
			int rem=m-v[i];
			if(rem < 0) continue;
			int l=0, r=v.size();

			while(l<r){
				int mid=(l+r)/2;
				if(rem>v[mid]){
					l=mid+1;
				}
				else if(rem<v[mid]){
					r=mid;
				}
				else {
					break;
				}
			}

			ans = max(ans, v[i]+v[r-1]);
		}

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


#include<iostream>
#include<vector>

using namespace std;
long long cnt=0;
void insertionSort(int numbers[],int n,int g)
{
    for(int i=g;i<n;i++)
    {
        int v=numbers[i];
        int j=i-g;
        while(j>=0&&numbers[j]>v)
        {
            numbers[j+g]=numbers[j];
            j=j-g;
            cnt++;
        }
        numbers[j+g]=v;
    }
}
void shellSort(int numbers[],int n)
{
   // int m=2;
   //生成数列G int G[2]={4,1}
   vector<int> G;
   for(int i=1;i<=n;)
   {
       G.push_back(i);
       i=i*3+1;
   }
    for(int i=G.size()-1;i>=0;i--)
    {

        insertionSort(numbers,n,G[i]);
    }
    cout<<G.size()<<endl;
   for(int i=G.size()-1;i>0;i--)
   {
       cout<<G[i]<<" ";
   }
   cout<<G[0];
   cout<<endl;
}
int main()
{
    int n;
    cin>>n;
    int numbers[1000000];

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

    shellSort(numbers,n);
    cout<<cnt<<endl;
    for(int i=0;i<n;i++)
    {
        cout<<numbers[i]<<endl;
    }
}

#include <iostream>
#include <vector>
#include <algorithm>
#include <cstdio>
#include <math.h>

using namespace std;

typedef long long ll;

int main() {
	int v[100];
	int n; cin >> n;
	for (int i = 0; i < n; ++i) {
		cin >> v[i];
	}
	for (int i = n-1; i >= 0; --i) {
		if (i != n-1) cout << " ";
		cout << v[i];
	}
	cout << endl;
}


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

const int MAX_V = 100;
const long long INF = (1LL << 32);

long D[MAX_V][MAX_V];
int V;

void wf() {
  for (int k = 0; k < V; k++) {
    for (int i = 0; i < V; i++) {
      if (D[i][k] == INF) continue;
      for (int j = 0; j < V; j++) {
        if (D[k][j] == INF) continue;
        D[i][j] = min(D[i][j], D[i][k] + D[k][j]);
      }
    }
  }
}

int main() {
  int e;
  cin >> V >> e;

  for (int i = 0; i < V; i++) {
    for (int j = 0; j < V; j++) {
      D[i][j] = ((i == j) ? 0 : INF);
    }
  }

  for (int i = 0; i < e; i++) {
    int s, t; cin >> s >> t;
    long d; cin >> d;

    D[s][t] = d;
  }

  wf();

  bool negative = false;

  for (int i = 0; i < V; i++) {
    if (D[i][i] < 0) negative = true;
  }

  if (negative) {
    cout << "NEGATIVE CYCLE" << endl;
    return 0;
  }

  for (int i = 0; i < V; i++) {
    for (int j = 0; j < V; j++) {
      if (j) cout << ' ';
      if (D[i][j] == INF) cout << "INF";
      else cout << D[i][j];
    }
    cout << endl;
  }

  return 0;
}

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

struct Edge {
    ll to, cost;
    Edge(ll to, ll cost):to(to),cost(cost) {}
};

struct Data {
    ll v, x;  // いまいる頂点v, 進んだ距離x
    Data(ll v, ll x):v(v),x(x) {}
    bool operator<(const Data& hoge) const {
        return x > hoge.x;
    }
};

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

    vector<vector<Edge>> G(n);
    rep(i, n-1) {
        ll a, b, c;
        cin >> a >> b >> c;
        a--;  b--;
        G[a].emplace_back(b, c);
        G[b].emplace_back(a, c);
    }

    ll q, sv;
    cin >> q >> sv;
    sv--;

    vl dp(n, INF);
    priority_queue<Data> Q;
    auto push = [&](ll v, ll x) {
        if(dp[v] <= x) {
            return;
        }
        dp[v] = x;
        Q.emplace(v, x);
    };

    // ダイクストラ法。計算量はO((V+E)*log(V))
    push(sv, 0);
    while(!Q.empty()) {
        Data hoge = Q.top();  Q.pop();
        ll v = hoge.v, x = hoge.x;
        if(dp[v] != x) {
            continue;
        }
        for(Edge e : G[v]) {
            push(e.to, x + e.cost);
        }
    }

    rep(i, q) {
        ll x, y;
        cin >> x >> y;
        x--;  y--;
        out(dp[x] + dp[y]);
    }

    re0;
}


#include <iostream>

using namespace std ;

long long int arr[60] ;

int main()
{
    long long int k ;

    cin >> k ;

    // vorodi
    if (k == 0) {
        cout << 2 << endl;
        cout << 1 << " " << 1;
        return 0;
    }

    for(int i = 0 ; i < 50 ; i++)
        arr[i] = i ;

    for(int i = 0 ; i < 50 ; i++)
        arr[i] += (k) / 50 ;

    if (k % 50 != 0) {
        for(int i = 0 ; i < k % 50 ; i++)
        {
            arr[i] += 50 ;

            for(int j = 0 ; j < 50 ; j++)
                if(j != i)
                    arr[j]-- ;
        }
    }

    cout << 50 << endl ;
    for(int i = 0 ; i < 50 ; i++)
        cout << arr[i] << " " ;

    cout << endl ;
	return 0 ;
}


#include <bits/stdc++.h>

using namespace std;
#define int long long
int MOD = 1000000007;

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

    int ans = 0;
    for(int i=0;i<N;i++){
        if(A[i]==B[i] && B[i]==C[i]) ans += 0;
        else if(A[i]==B[i]||B[i]==C[i]||A[i]==C[i]) ans++;
        else ans += 2;

    }

    cout << ans << endl;

    return 0;
}

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

//type
#define ll long long
typedef pair<int, int> P;
//定数
#define INF 1000000000000 //10^12:∞
#define MOD 1000000007    //10^9+7:合同式の法
#define MAXR 100000       //10^5:配列の最大のrange
//略記
#define PB push_back //挿入
#define MP make_pair //pairのコンストラクタ
#define F first      //pairの一つ目の要素
#define S second     //pairの二つ目の要素
#define Z class
// OTHER
// xの二乗を返す (関数テンプレート版)
template <typename T>
T square(T x) { return x * x; }
#define chmax(x, y) (x = max(x, y))
#define chmin(x, y) (x = min(x, y))
// loop
#define rep(i, n) for (int i = 0; i < (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--)
#define FORA(i, I) for (const auto &i : I)

// vector
#define ALL(x) x.begin(), x.end()

// output
#define YES() printf("YES\n")
#define NO() printf("NO\n")
#define isYES(x) printf("%s\n", (x) ? "YES" : "NO")
#define Yes() printf("Yes\n")
#define No() printf("No\n")
#define ln cout << '\n'
template <Z A>
void pr(A a)
{
  cout << a;
  ln;
}
template <Z A, Z B>
void pr(A a, B b)
{
  cout << a << ' ';
  pr(b);
}

int ans = 0;
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *

int main()
{
  int a, b, c;
  cin >> a >> b >> c;
  pr((a + b + c) - max(a, max(b, c)));

  return 0;
}


#include <iostream>

int main(int argc, char const *argv[]) {
  int x, result;
  std::cin >> x;
  result = x*x*x;
  std::cout << result << "\n";

  return 0;
}

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

int main() {
	// your code goes here
	int x;
	cin>>x;
	x=(int)(pow(x,3));
	cout<<x<<endl;
	return 0;
}


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

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

#define p_ary(ary,a,b) do { cout << "["; for (int count = (a);count < (b);++count) cout << ary[count] << ((b)-1 == count ? "" : ", "); cout << "]\n"; } while(0)
#define p_map(map,it) do {cout << "{";for (auto (it) = map.begin();;++(it)) {if ((it) == map.end()) {cout << "}\n";break;}else cout << "" << (it)->first << "=>" << (it)->second << ", ";}}while(0)

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

const char newl = '\n';

int main() {
    int n,m;
    cin >> n >> m;
    int l = n-1,r = 0;
    vector<P> ans;
    vector<bool> a(n+1,false);
    for (int i = 0;i < n/2;++i) {
        ans.push_back(make_pair(l,r));
        a[l-r] = a[n-(l-r)] = true;
        l--;r++;
        if (a[l-r] || a[n-(l-r)] || l-r == n-l+r) {
            l--;
            while (l > r) {
                ans.push_back(make_pair(l,r));
                l--;r++;
            }
            break;
        }
    }
    for (int i = 0;i < m;++i) cout << ans[i].first+1 << " " << ans[i].second+1 << newl;
}


#include <string>
#include <vector>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <map>
#include <list>
#include <set>
#include <numeric>
#include <queue>
#include <stack>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <climits>
#include <cfloat>
#include <ctime>
#include <complex>
#include <cassert>
#include <iomanip>
#include <tuple>
using namespace std;
typedef long long LL;
typedef pair<int,int> P;

void exec()
{
	int edge[100][100]={0};
	int n,k;
	cin >> n >> k;
	if(n==0&&k==0)exit(0);
	for(int i=0;i<k;i++){
		int a,b,c;
		cin >> a >> b >> c;
		b--;
		c--;
		if(a==0){
			priority_queue<P, vector<P>, greater<P> > q;
			q.push(P(0,b));
			int dist[100];
			fill(dist,dist+n,INT_MAX);
			dist[b]=0;
			while(q.size()){
				int f=q.top().second;
				int d=q.top().first;
				q.pop();
				if(f==c)break;
				if(dist[f]<d)continue;
				for(int j=0;j<n;j++){
					if(edge[f][j]&&d+edge[f][j]<dist[j]){
						dist[j]=d+edge[f][j];
						q.push(P(dist[j],j));
					}
				}
			}
			if(dist[c]!=INT_MAX){
				cout << dist[c] << endl;
			}
			else
			{
				cout << -1 << endl;
			}
		}
		else
		{
			int d;
			cin >> d;
			if(edge[b][c]==0||d<edge[b][c]){
				edge[b][c]=d;
				edge[c][b]=d;
			}
		}
	}
}
int main() {
	while(1)exec();
}

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

using namespace std;

#define rep(i,n) for(int i=0;i<int(n);i++)
#define reps(i,n) for(int i=1;i<=int(n);i++)
#define sint(i) scanf("%d",&i);
#define sintt(i,j) scanf("%d%d",&i,&j);
#define sinttt(i,j,k) scanf("%d%d%d",&i,&j,&k);
#define sintttt(i,j,k,m) scanf("%d%d%d%d",&i,&j,&k,&m);

#define INF 1010000000
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};

class S{
	public:
	int p,n;
	S(int p,int n):p(p),n(n){}

	bool operator<(const S& a)const{
		return n>a.n;
	}
};

////////////djk//////////////////////////////////////////
int main(){
	while(1){
		int n,m;
		sintt(n,m);
		if(n==0)break;
		vector<pair<int,int> > load[101];

		rep(o,m){
			int a;
			sint(a);
			if(a==1){
				int b,c,d;
				sinttt(b,c,d);
				load[b].push_back(make_pair(c,d));
				load[c].push_back(make_pair(b,d));
			}else{
				int s,g;
				sintt(s,g);

				priority_queue<S> que;
				que.push(S(s,0));

				int visit[101];
				rep(i,101)visit[i]=0;

				int ans=-1;

				while(1){
					if(que.empty()==1){
						break;
					}

					S u=que.top();
					que.pop();

					if(visit[u.p]==1){
						continue;
					}
					visit[u.p]=1;

					if(u.p==g){
						ans=u.n;
						break;
					}

					rep(i,load[u.p].size()){
						que.push( S( load[u.p][i].first,  u.n+load[u.p][i].second));
					}
				}
				printf("%d\n",ans);
			}
		}
	}
}


#include <bits/stdc++.h>
using namespace std;
int main(){
int N;
int counter = 0;
cin >>  N;
for(int i = 0;i < N/3 + 1;i++){
if((N - 3*(i + 1) >= 0)){
counter ++;}
else  cout << counter << endl;}
}

//#include<bits/stdc++.h>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<set>
#include<map>

/*
#include<boost/multiprecision/cpp_int.hpp>
#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/rational.hpp>
namespace mp = boost::multiprecision;
using Real = mp::number<mp::cpp_dec_float<1024>>;
using Bint = mp::cpp_int;
*/

using namespace std;

#define int long long
#define REP(i,s,e) for((i)=(s);(i)<(e);(i)++)
#define RREP(i,s,e) for((i)=((s)-1);(i)>=(e);(i)--)
#define FOR(i,n) for((i)=(0);(i)<(n);(i)++)
#define RFOR(i,n) for((i)=((n)-1);(i)>=(0);(i)--)
#define MOD 1000000007

signed main(){
    double R;
    cin>>R;
    printf("%.12f\n",2*R*acos(-1));
}


#include <bits/stdc++.h>
using namespace std;
struct edge {
    int to;     // 辺の行き先
    int weight; // 辺の重み
    edge(int t, int w) : to(t), weight(w) { }
};
using Graph = vector<vector<int>>;
using dou =long double;
string yes="yes";
string Yes="Yes";
string YES="YES";
string no="no";
string No="No";
string NO="NO";

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
#define rep(i, n)         for(int i = 0; i < (int)(n); i++)
#define brep(n)           for(int bit=0;bit<(1<<n);bit++)
#define erep(i,container) for (auto i : container)
#define irep(i, n)        for(int i = n-1; i >= (int)0; i--)
#define rrep(i,m,n) for(ll i = m; i < (ll)(n); i++)
#define reprep(i,j,h,w) rep(i,h)rep(j,w)
#define all(x) (x).begin(),(x).end()
#define VEC(type,name,n) std::vector<type> name(n);rep(i,n)std::cin >> name[i];
#define pb push_back
#define pf push_front
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define itn int
#define mp make_pair
#define sum(a) accumulate(all(a),0ll)
#define keta fixed<<setprecision
#define vvector(name,typ,m,n,a)vector<vector<typ> > name(m,vector<typ> (n,a))
#define vvvector(name,t,l,m,n,a) vector<vector<vector<t> > > name(l, vector<vector<t> >(m, vector<t>(n,a)));
#define vvvvector(name,t,k,l,m,n,a) vector<vector<vector<vector<t> > > > name(k,vector<vector<vector<t> > >(l, vector<vector<t> >(m, vector<t>(n,a)) ));
#define case std::cout <<"Case #" <<qqq+1<<": "
#define res resize
#define as assign
#define ffor for(;;)
#define ppri(a,b) std::cout << a<<" "<<b << std::endl
#define pppri(a,b,c) std::cout << a<<" "<<b <<" "<< c<<std::endl
#define aall(x,n) (x).begin(),(x).begin()+(n)

typedef long long ll;
typedef pair<int,int> P;
//typedef long long T;
const int INF = 2000000000;
const ll INF64 = 922337203685477580ll;
const ll MOD = 1000000007ll;
const dou pi=3.141592653589793;
int main(){
    string s;
    std::cin >> s;
    int n;
    std::cin >> n;
    string ans;
    rep(i,s.size()){
        if(i%n==0){
            ans.pb(s[i]);
        }
    }
    std::cout << ans << std::endl;
}


#include <iostream>
#include <vector>

using namespace std;

int game(int num, int stone)
{
        int i = 0, in_the_box = stone;
        vector<int> mayor(num, 0);
        while(1){
                if(in_the_box != 0){
                        mayor[i] += 1;
                        in_the_box -= 1;
                        if(mayor[i] == stone){
                                break;
                        }
                }else if(mayor[i] != 0){
                        in_the_box = mayor[i];
                        mayor[i] = 0;
                }

                i = (i + 1) % num;
        }
        return i;
}

int main(void)
{
        int i, n, p, next_mayor;

        while(1){
                cin >> n >> p;
                if(n == 0 && p == 0)
                        break;

                next_mayor = game(n, p);
                cout << next_mayor << endl;
        }
        return 0;
}

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

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

using namespace std;

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

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

template<class T> inline void amin(T &x, const T &y) { if (y<x) x=y; }
template<class T> inline void amax(T &x, const T &y) { if (x<y) x=y; }
template<class Iter> void rprintf(const char *fmt, Iter begin, Iter end) {
    for (bool sp=0; begin!=end; ++begin) { if (sp) putchar(' '); else sp = true; printf(fmt, *begin); }
    putchar('\n');
}
/*
6
abcdef
aabbdd

abcdef
abbddd
aabbdd

6
abcdef
aabcde

abcdef
abcdee
abcdde
abccde
abbcde
aabcde
*/

int N;
char S[1000111];
char T[1000111];
int C[1000111];
int off = 0, add = 0;

void MAIN() {
    scanf("%d%s%s", &N, S, T);
    while (N > 0 && S[N-1] == T[N-1]) N--;

    memset(C, 0xc0, sizeof C);
    int pos = N-1;
    int ans = 0;
    for (int i=N-1; i>=0; ) {
	int j=i;
	while (j > 0 && T[j-1] == T[i]) j--;

	// T[j .. i];
	int nxt = min(pos, j);
	while (nxt >= 0 && S[nxt] != T[i]) nxt--;
	if (nxt == -1) {
	    puts("-1");
	    return;
	}

	off++;
	add++;
	for (int k=nxt; k<=pos; k++) C[k+off] = 1 - add;
	for (int k=j; k<=i; k++) amax(ans, C[k+off] + add);

//	REP (z, N) eprintf("%d ", C[z+off] + add);
//	eprintf("\n");

	pos = nxt - 1;
	i = j-1;
    }
    printf("%d\n", ans);
}

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


#include <stdio.h>
int main(void){
int A,B;
scanf ("%d %d",&A,&B);
if (B+2<=A) printf ("%d",A+(A-1));
if (A+2<=B) printf ("%d",B+(B-1));
else {
    if (A==B+1||B==A+1||A==B) printf ("%d",A+B);
}
}

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

int main() {
    int a,b,ans;
    cin >> a >> b;
    ans = (a==b ? 2*a : 2*max(a,b)-1);
    cout << ans << endl;
}


#include <stdio.h>
int main()
{
int x,t;
scanf("%d",&x);
for(int i=2;i<=x;i++)
{
	if(i%3==0)printf(" %d",i);
	else {
		t=i;
		while(1){
		if(t%10==3){printf(" %d",i);break;}
		t=t/10;
		if(t==0)break;
		}
	}

}
printf("\n");
return 0;
}

#include <bits/stdc++.h>

using namespace std;

vector<string> p[8] = {
	{},

	{},

	{},

	{"aa.",
  	"..a",
  	"..a"},

 	{"aabc",
  	"ddbc",
  	"bcaa",
  	"bcdd"},

 	{"aabba",
  	"bcc.a",
  	"b..cb",
  	"a..cb",
  	"abbaa"},

 	{"aabc..",
  	"ddbc..",
  	"..aabc",
  	"..ddbc",
  	"bc..aa",
  	"bc..dd"},

 	{"aabbcc.",
  	"dd.dd.a",
  	"..d..da",
  	"..d..db",
  	"dd.dd.b",
  	"..d..dc",
  	"..d..dc"}
};

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

	if(n <= 2) {
		cout << -1 << '\n';
		return 0;
	}

	vector<string> s(n, string(n, '.'));

	function<void(int, int, int)> draw = [&] (int x, int y, int w) {
		for(int i = 0; i < w; ++i) {
			for(int j = 0; j < w; ++j) {
				s[i + x][j + y] = p[w][i][j];
			}
		}
	};

	while(n >= 8) {
		draw(n - 4, n - 4, 4);
		n -= 4;
	}

	draw(0, 0, n);

	for(int i = 0; i < s.size(); ++i) {
		cout << s[i] << '\n';
	}

	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define finish(x) return cout << x << endl, 0
#define ll long long

const int N = 100001;

int n, m, col[N];
vector <int> v[N];

int dfs(int node, int pnode){
    for(auto &i : v[node]){
        if(col[i] != -1){
            if(col[i] != (col[node] ^ 1)) return 1;
        }
        else{
            col[i] = col[node] ^ 1;
            int f = dfs(i, node);
            if(f == 1) return 1;
        }
    }
    return 0;
}
int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    memset(col, -1, sizeof col);
    cin >> n >> m;
    for(int i = 0 ; i < m ; i++){
        int x, y;
        cin >> x >> y;
        v[x].push_back(y);
        v[y].push_back(x);
    }
    col[1] = 0;
    if(dfs(1, 0)) finish(1LL * n * (n - 1) / 2 - m);
    int r = 0, b = 0;
    for(int i = 1 ; i <= n ; i++){
        if(col[i] == 0) r++;
        else b++;
    }
    cout << 1LL * r * b - m << endl;
}

#include <bits/stdc++.h>
#define N 1000010
#define F first
#define S second
using namespace std;
int n,m,book[N],nd;
vector<pair<int,int> > ed[N];
vector<int> col[N],ng[N];
int main(){
	int x,y,c,i,j,k;
	//memset(book,-1,sizeof(book));
	cin>>n>>m;
	nd=n;
	for(i=0;i<m;i++)
	{
		cin>>x>>y>>c;
		x--;
		y--;
		ed[x].push_back(make_pair(c,y));
		ed[y].push_back(make_pair(c,x));
		col[c].push_back(x);
		col[c].push_back(y);
	}
	for(i=0;i<n;i++)
	{
		sort(ed[i].begin(),ed[i].end());
	}
	for(i=0;i<N;i++)
	{
		for(j=0;j<col[i].size();j++)
		{
			y=col[i][j];
			if(book[y]==i)
			{
				continue;
			}
			queue<int> q;
			q.push(y);
			book[y]=i;
			while(q.size())
			{
				x=q.front();
				q.pop();
				ng[x].push_back(nd);
				ng[nd].push_back(x);
				for(k=lower_bound(ed[x].begin(),ed[x].end(),make_pair(i,0))-ed[x].begin();k<ed[x].size();k++)
				{
					if(ed[x][k].F!=i)
					{
						break;
					}
					if(book[ed[x][k].S]!=i)
					{
						book[ed[x][k].S]=i;
						q.push(ed[x][k].S);
					}
				}
			}
			nd++;
		}
	}
	/*for(i=0;i<n;i++)
	{
		for(j=0;j<ng[i].size();j++)
		{
			cout<<i<<"->"<<ng[i][j]<<endl;
		}
	}*/
	queue<int> q,st;
	q.push(0);
	st.push(0);
	book[0]=-2;
	while(q.size())
	{
		x=q.front();
		y=st.front();
		q.pop();
		st.pop();
		if(x==n-1)
		{
			cout<<y/2<<endl;
			return 0;
		}
		for(i=0;i<ng[x].size();i++)
		{
			c=ng[x][i];
			if(book[c]==-2)
			{
				continue;
			}
			book[c]=-2;
			q.push(c);
			st.push(y+1);
		}
	}
	cout<<-1<<endl;
	return 0;
}


#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <sstream>
#include <cmath>
#include <queue>

using namespace std;

int main(){

	int n, m;

	while(true){

		cin >> n >> m;

		if(n == 0 && m == 0){
			break;
		}

		int p[200000];

		long long int sum = 0;

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

		sort(p, p + n);

		for(int i = n - m; i >= 0; i -= m){
			sum -= p[i];
		}

		cout << sum << endl;

	}

	return 0;
}

#include <bits/stdc++.h>
#define REP(i, s, n) for (int i = s; i < (int)(n); i++)
#define ALL(a) a.begin(), a.end()
#define MOD 1000000007
using namespace std;
using ll = long long;

int main() {
    int N, M; cin >> N >> M;
    vector<int> A(N);
    REP(i, 0, N) cin >> A[i];

    int modsum = 0; unordered_map<int, int> m;
    REP(i, 0, N) {
        modsum = (modsum + A[i]) % M;
        m[modsum]++;
    }

    ll ans = 0; modsum = 0;
    REP(i, 0, N) {
        ans += m[modsum];
        modsum = (modsum + A[i]) % M;
        m[modsum]--;
    }
    cout << ans << endl;

    return 0;
}


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

int main(){
  double x1, x2, y1, y2, dis;

  cin >> x1 >> y1 >> x2 >> y2;
  dis = sqrt(pow(x2 - x1,2.0) + pow(y2 - y1,2.0));
  cout << fixed << dis <<endl;
  return 0;
}

#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <cmath>
#include <numeric>
#include <iomanip>
#include <stack>
#include <complex>
#include <functional>
#include <tuple>

using namespace std;

#define Rep(i,a,b) for(ll i = a; i < b; ++i)
#define rep(i,b) Rep(i,0,b)
#define allof(a) (a).begin(), (a).end()

#define Yes(q) ((q) ? "Yes" : "No")
#define YES(q) ((q) ? "YES" : "NO")
#define Possible(q) ((q) ? "Possible" : "Impossible")
#define POSSIBLE(q) ((q) ? "POSSIBLE" : "IMPOSSIBLE")

using ll = long long;

constexpr int inf = 1e9 + 7;
constexpr ll infll = 1ll << 60ll;
constexpr ll mod = 998244353;
// 0~3までは右下左上 4~7までは斜め
constexpr int dx[] = { 1, 0, -1, 0, 1, 1, -1, -1 };
constexpr int dy[] = { 0, 1, 0, -1, -1, 1, 1, -1 };

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

    void Cout(long long x, const char* end = "\n") { std::cout << x << end; }
    template <typename T> void Cout(const T& x, const char* end = "\n") { std::cout << x << end; }
    template <typename T> void Cout(const std::vector<T>& x, const char* sep = " ", const char* end = "\n") { for (std::size_t i = 0, sz = x.size(); i < sz; ++i) { std::cout << x[i] << (i == sz - 1 ? end : sep); } }

    // 標準入出力
    struct inp {
        std::size_t szi, szj;
        inp(std::size_t _szi = 1, std::size_t _szj = 1) : szi(_szi), szj(_szj) {}
        template <typename T> operator T () const { T a; std::cin >> a; return a; }
        template <typename T> operator std::vector<T>() const { std::vector<T> a(szi); for (std::size_t i = 0; i < szi; ++i) std::cin >> a[i]; return a; }
        template <typename T> operator std::vector<std::vector<T>>() const {
            std::vector<std::vector<T>> a(szi, std::vector<T>(szj));
            for (std::size_t i = 0; i < szi; ++i) for (std::size_t j = 0; j < szj; ++j) cin >> a[i][j]; return a;
        }
    };
    inp inp1;
}

int main() {

    string s = inp1;
    s = '0' + s;
    int n = s.size();

    vector<vector<int>> dp(n + 1, vector<int>(2, inf));
    dp[0][0] = 0;

    rep(i, n) {
        int num = s[i] - '0';
        // ピッタリ払う
        chmin(dp[i + 1][0], dp[i][0] + num);
        chmin(dp[i + 1][0], dp[i][1] + 10 - num);

        // 余分に払う
        chmin(dp[i + 1][1], dp[i][0] + num + 1);
        chmin(dp[i + 1][1], dp[i][1] + 10 - num - 1);
    }

    Cout(dp[n][0]);

    return 0;
}


#include <iostream>
#include <string>

using namespace std;

int main(){
	string str;
	//string reverse="";
	cin>>str;
	for (int i=str.length()-1; i>-1; i--){
		cout<<str.at(i);
	}
	cout<<endl;
	//cout<<reverse<<endl;
	return 0;
}

#include <bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp>
//namespace mp = boost::multiprecision;

using namespace std;

const double PI = 3.14159265358979323846;
typedef long long ll;
const double EPS = 1e-9;
#define rep(i, n) for (int i = 0; i < (n); ++i)
//#define rep(i, n) for (ll i = 0; i < (n); ++i)
typedef pair<ll, ll> P;
const ll INF = 10e17;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)
#define ret() return 0;

double equal(double a, double b) {
    return fabs(a - b) < DBL_EPSILON;
}

std::istream &operator>>(std::istream &in, set<int> &o) {
    int a;
    in >> a;
    o.insert(a);
    return in;
}

std::istream &operator>>(std::istream &in, queue<int> &o) {
    ll a;
    in >> a;
    o.push(a);
    return in;
}

bool contain(set<int> &s, int a) { return s.find(a) != s.end(); }

//ofstream outfile("log.txt");
//outfile << setw(6) << setfill('0') << prefecture << setw(6) << setfill('0') << rank << endl;
// std::cout << std::bitset<8>(9);
//const ll mod = 1e10;

typedef priority_queue<ll, vector<ll>, greater<ll> > PQ_ASK;

// 借りました。
// https://kenkoooo.hatenablog.com/entry/2019/12/29/110321

const vector<vector<char>> s3 = vector<vector<char>>{
        {'a', 'a', '.',},
        {'.', '.', 'a',},
        {'.', '.', 'a',},
};

const vector<vector<char>> s4 = vector<vector<char>>{
        {'a', 'b', 'e', 'e'},
        {'a', 'b', 'f', 'f'},
        {'g', 'g', 'c', 'd'},
        {'h', 'h', 'c', 'd'},
};

const vector<vector<char>> s5 = {
        {'a', 'c', 'd', '.', '.'},
        {'a', 'c', 'd', '.', '.'},
        {'b', 'f', 'f', 'g', 'g'},
        {'b', '.', 'e', 'h', 'h'},
        {'i', 'i', 'e', 'j', 'j'},
};

const vector<vector<char>> s6 = {
        {'a', 'd', 'g', 'g', '.', '.'},
        {'a', 'd', 'h', 'h', '.', '.'},
        {'b', 'e', 'i', 'i', '.', '.'},
        {'b', 'e', '.', '.', 'j', 'j'},
        {'c', 'f', '.', '.', 'k', 'k'},
        {'c', 'f', '.', '.', 'l', 'l'},
};

const vector<vector<char>> s7 = {
        {'a', 'd', 'f', '.', '.', '.', '.'},
        {'a', 'd', 'f', '.', '.', '.', '.'},
        {'b', 'e', 'g', '.', '.', '.', '.'},
        {'b', 'e', 'g', '.', '.', '.', '.'},
        {'c', '.', '.', 'h', 'h', 'i', 'i'},
        {'c', '.', '.', 'j', 'j', 'k', 'k'},
        {'.', 'l', 'l', 'm', 'm', 'n', 'n'},
};

P solve(int n) {
    rep(i, 1000) {
        int x = i;
        int y = n - (4 * x);

        if (y == 5) {
            return {x, y};
        }

        if (y == 6) {
            return {x, y};
        }

        if (y == 7) {
            return {x, y};
        }

        if (y == 0) {
            return {x, y};
        }
    }

    __throw_runtime_error("konaide");
}

void copy_print(vector<vector<char>> &ans, int n, const vector<vector<char>> &from, int sy, int sx) {
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            ans[sy + i][sx + j] = from[i][j];
        }
    }
}

void print(const vector<vector<char>> &ans) {
    for (auto &line: ans) {
        for (char e : line) cout << e;
        cout << endl;
    }
}

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

    if (n == 2) {
        cout << -1 << endl;
        ret();
    }

    if (n == 3) {
        print(s3);
        ret();
    }

    P p = solve(n);

    vector<vector<char>> ans(n, vector<char>(n, '.'));

    rep(i, p.first) {
        int sy = 4 * i;
        int sx = 4 * i;

        copy_print(ans, 4, s4, sy, sx);
    }

    if (p.second == 5) {
        int sy = p.first * 4;
        int sx = p.first * 4;
        copy_print(ans, 5, s5, sy, sx);
    }

    if (p.second == 6) {
        int sy = p.first * 4;
        int sx = p.first * 4;
        copy_print(ans, 6, s6, sy, sx);
    }

    if (p.second == 7) {
        int sy = p.first * 4;
        int sx = p.first * 4;
        copy_print(ans, 7, s7, sy, sx);
    }

    print(ans);

}


#include <bits/stdc++.h>

using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define MIN(a,b) ((a)>(b)? (b): (a))
#define MAX(a,b) ((a)<(b)? (b): (a))

const long long INF = 1LL << 60;
typedef unsigned long long ll;
const long long MOD = 1000000000 + 7;

int main(){
    ll n;
    cin >> n;
    vector<ll> sq;
    ll cnt = 1;
    while (cnt * cnt <= n)
    {
        sq.push_back(cnt*cnt);
        cnt++;
    }
    sort(sq.begin(), sq.end());
    cout << sq[sq.size() - 1] << endl;
    return 0;
}

#include<iostream>
using namespace std;
int main(){
  int a;cin>>a;
  if(a<112)cout<<111<<endl;
  else if(a<223)cout<<222<<endl;
  else if(a<334)cout<<333<<endl;
  else if(a<445)cout<<444<<endl;
  else if(a<556)cout<<555<<endl;
  else if(a<667)cout<<666<<endl;
  else if(a<778)cout<<777<<endl;
  else if(a<889)cout<<888<<endl;
  else cout<<999<<endl;
}


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

const int mod = 998244353;

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

    if(d0 != 0) {
        cout << 0 << endl;
        return 0;
    }

    vector<int> d(100005);
    d.at(0) = 1;
    int max_d = 0;
    for(int i = 1; i < n; ++i) {
        int di;
        cin >> di;
        max_d = max(max_d, di);
        d.at(di)++;
    }

    if(d.at(0) != 1) {
        cout << 0 << endl;
        return 0;
    }

    ll ans = 1;
    int i = 1;
    while(i < n) {
        if(d.at(i) == 0) break;
        rep(j, d.at(i)) {
            ans *= d.at(i-1);
            ans %= mod;
        }
        ++i;
    }
    if(i < max_d) cout << 0 << endl;
    else cout << ans << endl;

    return 0;
}

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

const long long mod = 998244353;

int main() {
  int n;
  cin >> n;
  map<int, long long> d;
  for(int i = 0; i < n; i++){
    int a;
    cin >> a;
    if(i == 0 && a != 0){
      cout << 0 << endl;
      return 0;
    }
    d[a]++;
  }

  long long sum = 0, ans = 1, last = 1;
  bool ok = false;
  for(int i = 0; i < n; i++){
    if(sum == n){
      ok = true;
      break;
    }
    else if(!d.count(i)) break;
    if(d.at(0) > 1) break;
    long long now = d.at(i);
    sum += now;
    long long mul = 1;
    for(int i = 0; i < now; i++){
      mul *= last;
      mul %= mod;
    }
    ans *= mul;
    ans %= mod;
    last = now;
    if(sum == n) ok = true;
  }

  if(!ok) ans = 0;
  cout << ans << endl;
}


#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0,i##_max=(N);i<i##_max;++i)
#define repp(i,l,r) for(int i=(l),i##_max=(r);i<i##_max;++i)
#define per(i,N) for(int i=(N)-1;i>=0;--i)
#define perr(i,l,r) for(int i=r-1,i##_min(l);i>=i##_min;--i)
#define all(arr) (arr).begin(), (arr).end()
#define SP << " " <<
#define SPF << " "
#define SPEEDUP cin.tie(0);ios::sync_with_stdio(false);
#define MAX_I INT_MAX //1e9
#define MIN_I INT_MIN //-1e9
#define MAX_UI UINT_MAX //1e9
#define MAX_LL LLONG_MAX //1e18
#define MIN_LL LLONG_MIN //-1e18
#define MAX_ULL ULLONG_MAX //1e19
  typedef long long ll;
  typedef pair<int,int> PII;
  typedef pair<char,char> PCC;
  typedef pair<ll,ll> PLL;
  typedef pair<char,int> PCI;
  typedef pair<int,char> PIC;
  typedef pair<ll,int> PLI;
  typedef pair<int,ll> PIL;
  typedef pair<ll,char> PLC;
  typedef pair<char,ll> PCL;

inline void YesNo(bool b){ cout << (b?"Yes" : "No") << endl;}
inline void YESNO(bool b){ cout << (b?"YES" : "NO") << endl;}
inline void Yay(bool b){ cout << (b?"Yay!" : ":(") << endl;}

int main(void){
  SPEEDUP
  cout << setprecision(15);
  int N;cin >> N;
  string s;cin >> s;
  map<pair<string,string>,int> mp;
  rep(n,1<<N){
    string t,u;
    rep(i,N){
      if((n>>i)&1) t.push_back(s[i]);
      else u.push_back(s[i]);
    }
    ++mp[make_pair(t,u)];
  }

  reverse(all(s));
  ll ans = 0;
  rep(n,1<<N){
    string t,u;
    rep(i,N){
      if((n>>i)&1) t.push_back(s[i]);
      else u.push_back(s[i]);
    }
    if(mp.count(make_pair(t,u))) ans += mp[make_pair(t,u)];
  }
  cout << ans << endl;
  return 0;
}

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

int main() {
  const ll M = 998244353;
  ll N, ans = 1;
  cin >> N;
  vector<ll> d;
  vector<ll> cnt(N, 0);
  for (ll i = 0; i < N; i++) {
    ll x;
    cin >> x;
    if (i == 0) {
      if (x != 0) ans = 0;
    } else {
      d.push_back(x);
    }
    cnt[x]++;
  }
  for (auto x : d) {
    if (x > 0) ans *= cnt[x-1];
    else ans = 0;
    ans %= M;
  }
  cout << ans << endl;
  return 0;
}


# define _CRT_SECUREj_NO_WARNINGS 1
# define _USE_MATH_DEFINES
# include <iostream>
# include <numeric>
# include <string>
# include <bitset>
# include <vector>
# include <algorithm>
# include <cstdlib>
# include <cstdio>
# include <cstring>
# include <cstdlib>
# include <iomanip>
# include <queue>
# include <sstream>
# include <climits>
# include <cmath>
# include <list>
# include <functional>
# include <string>
# include <ctime>
# include <set>
# include <forward_list>
# include <map>
# include <stack>
using namespace std;
# define INF ((int)(1<<25))
# define REP(i,n) for(int i=0;i<(int)n;i++)
# define FOR(i,n) REP(i,n)
# define FORI(i,k,n) for(int i=k;i<(int)n;i++)
# define TORAD 2.0*M_PI/360.0
# define INT(x) int x;cin>>x;
# define ALL(x) (x).begin(),(x).end()
# define RALL(x) (x).rbegin(),(x).rend()
# define DEBUG(x) cout<<#x<<":"<<x<<endl;
# define EPS 1e-12
#ifdef _MSC_VER
#include <intrin.h>
#define __builtin_popcount __popcnt
#endif
#define int long long
typedef long long lint;
typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef pair<int, pii> piii;
const int dx[4] = { 0,1,0,-1 }, dy[4] = { -1,0,1,0 };
template<class T> void debug(T a) { for (auto i : a)cout << i << endl; }

const int M = 110;
int f[M][M];
int v, e, r;

signed main()
{
	cin >> v >> e;
	FOR(i, M)FOR(j, M)f[i][j] = INT_MAX;
	FOR(i, M)f[i][i] = 0;
	FOR(i, e)
	{
		int s, t, d;
		cin >> s >> t >> d;
		f[s][t] = d;
	}

	FOR(k, M)
	{
		FOR(i, M)
		{
			FOR(j, M)
			{
				if (f[i][k] == INT_MAX || f[k][j] == INT_MAX)continue;
				f[i][j] = min(f[i][j], f[i][k] + f[k][j]);
			}
		}
	}
	FOR(i, M)if (f[i][i] < 0) { cout << "NEGATIVE CYCLE" << endl; return 0; }

	FOR(i, v)
	{
		FOR(j, v)
		{
			if (j)cout << " ";
			if (f[i][j] == INT_MAX)cout << "INF";
			else cout << f[i][j];
		}
		cout << endl;
	}
}


#include <iostream>
#include <vector>

using namespace std;
typedef long long ll;

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

    int l = s.length();

    if (s.find("AC") != string::npos) {
        cout << "Yes" << endl;
    } else {

        cout << "No" << endl;
    }
}

#include <iostream>
#include <numeric>
#include <math.h>
#include <algorithm>
#include <float.h>
#include <limits>
#include <vector>
#include <string.h>
#include <iomanip>

#define rep(i,a,n) for(ll int (i) = (a);(i) < (n);(i)++)
#define urep(i,a,n) for(ll int (i) = (a);(i) > (n);(i)--)
#define MOD 1000000007
#define INF 2147483647
#define ll long long
#define asort(a) sort(a.begin(),a.end());//昇順ソート
#define usort(a) sort(a.rbegin(),a.rend());//降順ソート

using namespace::std;

int jo(ll int a, ll int b){//累乗
    ll int num=1;
    rep(i,0,b) num=num*a;
    return num;
}
char tobig(char s){//char大文字化
  return (s-0x20);
}
char tolow(char s){//char小文字化
  return (s+0x20);
}
int ctoi(char a){//char->int
  if('0'<=a&&a<='9') return (a-'0');
  return -1;
}

int gcd(ll int a,ll int b) {//最大公約数
  if(a<b) return gcd(b,a);
  int c;
  while ((c=a%b)) {
    a=b;
    b=c;
  }
  return b;
}
int lcm(ll int a,ll int b){//最小公倍数
 return (a*b)/gcd(a,b);
}

int main(){
  string S;cin>>S;
  int AC=0;
  rep(i,0,S.length()-1){
    if(S[i]=='A'&&S[i+1]=='C') AC++;
  }
  cout<<(AC?"Yes":"No");
}

// vector<vector<int>> 変数名(左の個数, vector<int>(右の個数));

//cout<<fixed<<setprecision(n);  //小数点n桁まで表示

//  vector<pair<int,int>> data(N);  //2つのデータを格納、.first/.secondで参照
// pairのソートはfirst優先の昇順


#include <bits/stdc++.h>
#define rep(i, z, n) for(int i = z; i < n; i++)
#define all(v) v.begin(), v.end()
typedef long long ll;
//const int INF = 1<<29;
//const int MODINF = 1000000007;
using namespace std;

int main(){
    int N;
    cin >> N;
    vector<int> A(N + 2, 0);
    int sum = 0;
    rep(i, 1, N + 1) cin >> A.at(i);
    rep(i, 0, N + 1) sum += abs(A.at(i + 1) - A.at(i));
    rep(i, 1, N + 1){
        int x = A.at(i - 1);
        int y = A.at(i);
        int z = A.at(i + 1);
        if ((x - y)*(y - z) >= 0){
            cout << sum << endl;
        }
        else{
            cout << sum - 2 * min(abs(x - y), abs(y - z)) << endl;
        }
    }
}

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

int main()
{
  ll n;
  cin >> n;
  vector<int> a(n, 0);
  vector<ll> ans(n, 0);
  ll fee = 0;
  for (ll i = 0; i < n; i++)
  {
    cin >> a[i];
  }

  ll tmp = 0;
  for (ll i = 0; i < n + 1; i++)
  {
    if (i == n)
    {
      fee += abs(tmp - 0);
      break;
    }

    fee += abs(tmp - a[i]);
    tmp = a[i];
  }

  for (ll i = 0; i < n; i++)
  {
    ans[i] = fee - (abs(a[i] - a[i - 1]) + abs(a[i + 1] - a[i])) + (abs(a[i + 1] - a[i - 1]));
  }

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


#include<stdio.h>
#include<string.h>
#include<iostream>
#include <fstream>
#include<iostream>
#include <sstream>
#include<string>
#include <list>

using namespace std;
const int M = 1003;
const int INIT = (M*M + 1);
int C[M][M];// = { 0 };

int countmatchstring(const char* p1, const char*p2, int length1, int length2,int x, int y, int i, int j,int cost)
{
	int w = (i - 1 > j - 1) ? i - 1 : j - 1;
	if (p1[x + i] == p2[y + j])
	{
		x = x + i;
		y = y + j;
		if (x == length1 - 1 && y == length2 - 1)
		{
			C[x][y] = 0;
			return w;
		}
		if (x == length1 - 1 || y == length2 - 1)
		{
			while (1);
		}
		C[x][y] = countmatchstring(p1, p2, length1, length2, x, y, 1, 1, w + cost);
		return w + C[x][y];

	}
	if (C[x + i][y + j] == INIT)
	{
		int c1 = INIT, c2 = INIT,c3 = INIT;
		if (x + i + 1 < length1)
		{
			for (int p = 1; x + i + p < length1; ++p)
			{
				if (p1[x + i + p] == p2[y + j])
				{
					c1 = countmatchstring(p1, p2, length1, length2, x, y, i + p, j, cost);
					break;
				}
			}
		}
		if (y + j + 1 < length2)
		{
			for (int q = 1; y + j + q < length2; ++q)
			{
				if (p1[x + i] == p2[y + j + q])
				{
					c2 = countmatchstring(p1, p2, length1, length2, x, y, i, j + q, cost);
					break;
				}
			}
		}
		if ((x + i + 1 < length1) && (y + j + 1 < length2))
		{
			c3 = countmatchstring(p1, p2, length1, length2, x, y, i + 1, j + 1, cost);
		}
		int c = (c1 < c2 ? c1 : c2);
		c = (c < c3 ? c : c3);
		C[x + i][y + j] = c;
	}
	return C[x + i][y + j];
}

int main(){
	std::istream & c_in = cin;
	for (int i = 0; i < M; ++i){
		for (int j = 0; j < M; ++j){
			C[i][j] = INIT;
		}
	}
	string s1, s2;
	getline(c_in, s1);
	getline(c_in, s2);
	s1 = "A" + s1 + "B";
	s2 = "A" + s2 + "B";
	const char* p1 = s1.c_str();
	const char* p2 = s2.c_str();
	countmatchstring(p1, p2, s1.length(), s2.length(),0, 0, 1,1,0);
	printf("%d\n", C[1][1]);
	return 0;
}

#include<iostream>
#include<iomanip>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
using namespace std;
typedef long long ll;
#define INF (1 << 30)
#define MOD 1000000007

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

class Combination
{
	vector<ll> fact, finv;
public:Combination(int n) {
	fact.resize(n + 1, 1);
	finv.resize(n + 1, 1);
	vector<ll> inv(n + 1, 1);
	for (int i = 2; i <= n; ++i) {
		fact[i] = fact[i - 1] * i % MOD;
		inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
		finv[i] = finv[i - 1] * inv[i] % MOD;
	}
}
public:ll comb(int n, int k) {
	return fact[n] * (finv[n - k] * finv[k] % MOD) % MOD;
}
};
map<int, int> factorize(int x)
{
	map<int, int> m;
	for (int i = 2; i * i <= x; ++i) {
		while (x % i == 0) {
			x = x / i;
			++m[i];
		}
	}
	if (x != 1) {
		++m[x];
	}
	return m;
}
int main()
{
	int N, M; cin >> N >> M;
	auto m = factorize(M);
	auto C = Combination(N + 100);
	ll ans = 1;
	for (auto i : m) {
		ans *= C.comb(N + i.second - 1, i.second);
		ans = ans % MOD;
	}
	cout << ans << endl;
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define BIG 1000000010
#define repi(i,x,n) for(int i=x;i<n;i++)
#define rep(i,n) repi(i,0,n)
#define repn(i,n) for(int i=n;i>=0;i--)
typedef long long int ll;

int main(){
  int n;
  int k[100];
  int num;
  string s;
  string ans;
  int alp[52];
  rep(i,52){
    if(i<26) alp[i]=i+65;
    else alp[i]=i+71;
  }
  while(1){
    cin>>n;
    if(n==0) break;
    rep(i,n){
      cin>>k[i];
    }
    cin>>s;
    ans="0";
    rep(i,s.size() ){
      rep(j,52){
	if(alp[j]==s[i]) num=j;
      }
      int a=(num-k[i%n]+520)%52;
      //cout<<a<<endl;
      ans+=alp[a];
      //cout<<ans<<endl;
    }
    repi(i,1,ans.size()){
      cout<<ans[i];
    }
    cout<<endl;
  }

  return 0;
}

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

int main(){
    int N,Q;
    while( cin >> N >> Q, N||Q ){
        vector<int> date(100, 0);
        for(int i = 0; i < N; i++){
            int m;
            cin >> m;
            for(int j = 0; j < m; j++){
                int a;
                cin >> a;
                date[a] += 1;
            }
        }
        int most_conv, max_v = 0;
        for(int i = 0; i < 100; i++){
            if( date[i] > max_v ){
                most_conv = i;
                max_v = date[i];
            }
        }
        if( max_v >= Q ) cout << most_conv << endl;
        else cout << 0 << endl;
    }
    return 0;
}


#include <stdio.h>
#include <string.h>

int main(void)
{
	int i, j;
	int n;
	int len;
	char str[1024];

	scanf("%d\n", &n);

	for (j = 0; j < n; j++){
		fgets(str, 1024, stdin);

		len = strlen(str);
		for (i = 0; i < len; i++){
			if (strncmp(&str[i], "Hoshino", 7) == 0){
				strncpy(&str[i], "Hoshina", 7);
			}
		}
		printf("%s", str);
	}

	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 n;
	string sn;
	getline(cin, sn);
	n = atoi(sn.c_str());
	REP(i, n){
		string s;
		getline(cin, s);
		while (s.find("Hoshino") != string::npos){
			s[s.find("Hoshino") + 6] = 'a';
		}
		cout << s << endl;
	}
}


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

int main()
{
	int n,m,A,B;
	scanf("%d %d %d %d",&n,&m,&A,&B);
	for(int i=0;i<B;i++)
	{
		for(int j=0;j<m;j++) printf("%c",j<A?'0':'1');
		puts("");
		for(int j=0;j<m;j++) printf("%c",j<A?'1':'0');
		puts("");
	}
	for(int i=0;i<n-2*B;i++)
	{
		for(int j=0;j<m;j++) printf("%c",j<A?'0':'1');
		puts("");
	}
}

#include <bits/stdc++.h>
using namespace std;
int main() {
  int a,b,c,k,m,mk; cin>>a>>b>>c>>k;
  m=max({a,b,c}); mk=m;
  for(int i=0; i<k; i++) mk*=2;
  cout<<a+b+c-m+mk;
}


#include<iostream>
#include<vector>
#include<string.h>
#include<queue>
using namespace std;
const int N = 1e5 + 7;
string x[3] = { "RGB","GBR","BRG" };
int y[3][N];
int main() {
	int n, k;
	while (cin >> n >> k) {
		cout << n - k + 1 << '\n';
	}
	return 0;
}

#include <iostream>
using namespace std;

int main() {
    char input[1000];
    while (cin >> input) {
        char pre = '0';
        int output = 0;
        for (int i = 0; input[i] != '\0'; i++) {
            switch (input[i]) {
            case 'M':
                output += (pre == 'C') ? 800 : 1000;
                break;
            case 'D':
                output += (pre == 'C') ? 300 : 500;
                break;
            case 'C':
                output += (pre == 'X') ? 80 : 100;
                break;
            case 'L':
                output += (pre == 'X') ? 30 : 50;
                break;
            case 'X':
                output += (pre == 'I') ? 8 : 10;
                break;
            case 'V':
                output += (pre == 'I') ? 3 : 5;
                break;
            case 'I':
                output++;
                break;
            }
            pre = input[i];
        }
        cout << output << endl;
    }
}


#include <algorithm>
#include <cmath>
#include <vector>
#include <functional>
#include <cstdlib>
#include <map>
#include <set>
#include <iostream>
#include <string>
#include <ctype.h>
#include <climits>
#include <queue>
#include <iomanip>
using namespace std;
typedef long long ll;
#define REP(i, n) for(ll i = 0; i < (ll)(n); ++i)
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(){
	ll n;
	cin >> n;
	vector<ll> a(n), b(n), c(n);
	REP(i,n) cin >> a[i];
	REP(i,n) cin >> b[i];
	REP(i,n) cin >> c[i];
	sort(a.begin(),a.end());
	sort(b.begin(),b.end());
	sort(c.begin(),c.end());

	vector<ll> B(n),SB(n+1);
	REP(i,n){
		if(b[i] >= c[n-1]){
			B[i] = 0;
			continue;
		}
		int ok,ng,mid;
		ok = 1;
		ng = n+1;
		while(abs(ok-ng)>1){
			mid = (ok+ng)/2;
			if(b[i]<c[n-mid]){
				ok = mid;
			}else{
				ng = mid;
			}
		}
		B[i] = ok;
	}

	SB[n]=0;
	for(int i=n-1; i>=0; i--) SB[i] = SB[i+1]+B[i];

	vector<ll> A(n);
	REP(i,n){
		if(a[i] >= b[n-1]){
			A[i] = 0;
			continue;
		}
		int ok,ng,mid;
		ok = 1;
		ng = n+1;
		while(abs(ok-ng)>1){
			mid = (ok+ng)/2;
			if(a[i]<b[n-mid]){
				ok = mid;
			}else{
				ng = mid;
			}
		}
		A[i] = SB[n-ok];
	}

	ll ans = 0;
	REP(i,n) ans += A[i];
	cout << ans << endl;

	return 0;
}

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

int N;
int A[3][100001];
LL dp[3][100001] = {};

int main() {
    scanf("%d", &N);
    rep(j, 3) { rep(i, N) scanf("%d", &A[j][i]); A[j][N] = 1000000001; }
    rep(j, 3) sort(A[j], A[j] + N);
    rep(i, N + 1) dp[0][i] = i;
    rep(j, 2) {
        int p = 0;
        rep(i, N) {
            while (A[j][p] < A[j + 1][i]) p++;
            dp[j + 1][i + 1] += dp[j + 1][i] + dp[j][p];
        }
    }
    printf("%lld\n", dp[2][N]);
    return 0;
}


#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i=0;i<(n);++i)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define all(x) (x).begin(), (x).end()
#define PI 3.14159265358979323846264338327950L
using namespace std;
typedef long long ll;
typedef long double ld;
int main() {
    int n,k;
    cin>>n>>k;
    vector<int> l(n);
    rep(i,n) cin>>l[i];
    sort(all(l));
    int ans=0;
    rep(i,k) ans+=l[n-1-i];
    cout<<ans;
}

#include <iostream>
#include <algorithm>
#include <iomanip>
#include <string>
#include <vector>
#include <math.h>
#include <queue>
#include <deque>
#include <stack>
#include <map>
const int MOD = 1e9+7;
#define PI 3.14159265359
typedef long long ll;
using namespace std;

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

	ll ans = 0;
	for (int all = 0; all <= min(k, n); all++){
		for (int i = 0; i <= all; i++){
			int l = i, r = all - i;
			int rem = k - all;
			priority_queue<int, vector<int>, greater<int> > que;
			for (int j = 0; j < l; j++){
				que.push(v[j]);
			}
			for (int j = 0; j < r; j++){
				que.push(v[n-j-1]);
			}
			ll tmp = 0;
			while (!que.empty()){
				if (que.top() < 0 && rem > 0){
					rem--;
					que.pop();
				}else{
					tmp += que.top();
					que.pop();
				}
			}
			ans = max(ans, tmp);
		}
	}
	cout << ans << endl;
	return 0;
}


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

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

	else return u(b,a%b);

}

//素数判別じゃなかったです
//ll s( ll n){
//	bool k[n+1]={};
//	ll ans=0;
//	for(ll i=2; i<n; i++){
//		if(!k[i]){
//			ll d=i;
//			if(n%i==0){
//				ans++;
//				cout<<i<<endl;
//			}
//			//cout<<i<<" "<<ans<<endl;
//			while(d<=n){
//				k[d]=true;
//				d+=i;
//			}
//		}
//		///cout<<ans<<endl;
//	}
//	//cout<<ans<<endl;
//	return ans;
//}

int main(){
	ll n,a,b;
	cin>>a>>b;
	n=u( max(a,b),min(a,b));
	//cout<<n<<endl;
	ll ans=1;
	ll k=2;
	//ans+=s(n);
	//ルートn以上の素因数は１コまで
	while(n>=k*k){
		if(n%k==0) ans++;

		while(n%k==0){
			n/=k;
		}
		//cout<<n<<endl;
		k++;
	}
	if(n>1){
		ans++;
	}
	//cout<<n<<endl;
	cout<< ans <<endl;
}

#include<bits/stdc++.h>
#define rep(i,f,n) for(ll i=(f); (i) < (n); i++)
#define repe(i,f,n) for(ll i=(f); (i) <= (n); i++)
using namespace std;
using ll = long long;
#define MOD (ll)1000000007
#define PI 3.14159265359
#define debug(x) cout<<#x<<" :: "<<x<<"\n";
#define debug2(x,y) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\n";
#define debug3(x,y,z) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\t"<<#z<<" :: "<<z<<"\n";
//#define P pair<ll, ll>
//printf("%.10f\n")
//cout << fixed << setprecision(10);
template<class T> inline bool chmax(T& a, T b){if (a < b) { a = b; return true; } return false;}
template<class T> inline bool chmin(T& a, T b){if (a > b) { a = b; return true; } return false;}
ll INF = 1e+18;
int iINF = 1e9;

int
main()
{

  int N, M; cin >> N >> M;
  if(M % N == 0){
    cout << M / N << endl;
    return 0;
  }
  int maxi = 1;
  rep(i, 1, M/N){
    int d = i;
    if((M - (d * (N - 1))) % d == 0) maxi = i;
  }

  cout << maxi << endl;

}


/*
Loading:{
        https://codeforces.com/problemset/problem/1234/F
}
*/
#include <bits/stdc++.h>

using namespace std;

#define ll int // optimize with int
#define endl '\n'
const int N = 1e6 + 5;
ll a[305];
ll dp[305][305][305]; // id, used to donate, used to receive;
ll mod = 998244353; // fucking mod 1e9 + 7
ll n, k, cnt = 0;
ll add(ll x, ll y){ // optimize with add func
        ll res = x + y;
        if (res >= mod) res -= mod;
        return res;
}
int main(){
        ios_base::sync_with_stdio(false);
        cin.tie(0);
        if (fopen("GUARDS.INP", "r")){
                freopen("GUARDS.INP", "r", stdin);
                freopen("GUARDS.OUT", "w", stdout);
        }
        string s;
        cin >> s;
        n = s.length();
        cin >> k;
        ll cur = 0;
        ll cnt1 = 0;
        for (int i = s.length() - 1; i >= 0; i--){
                if (s[i] == '1') {
                        cur++;
                        cnt1++;
                }
                else {
                        cnt++;
                        a[cnt] = cur;
                        cur = 0;
                }
        }
        cnt++;
        a[cnt] = cur;
        //memset(dp, -1, sizeof(dp));
        k = min(k, cnt1);
        for (int i = a[1]; i >= max(0, a[1] - k); i--){
                dp[1][a[1] - i][0] = 1;
        }
        ll sum = a[1];
        for (int i = 1; i < cnt; i++){
                for (int j = 0; j <= sum; j++){
                        for (int t = 0; t <= j; t++){
                                dp[i + 1][j][t] = add(dp[i + 1][j][t], dp[i][j][t]);
                                for (int x = a[i + 1] - 1; x >= max(0, (a[i + 1] - (k - j))); x--){
                                        dp[i + 1][j + a[i + 1] - x][t] = add(dp[i + 1][j + a[i + 1] - x][t], dp[i][j][t]);
                                }
                                for (int x = a[i + 1] + 1; x <= a[i + 1] + (j - t); x++){
                                        dp[i + 1][j][t + x - a[i + 1]] = add(dp[i + 1][j][t + x - a[i + 1]], dp[i][j][t]);
                                }
                        }
                }
                sum += a[i + 1];
        }
        ll ans = 0;
        for (int i = 0; i <= k; i++) {
                ans = add(ans, dp[cnt][i][i]);
                //cout << dp[cnt][i][i] << " ";
        }
        cout << ans;
}


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

#define int ll
#define REP(i,n) for (int i = 0; i < (n); ++i)
#define FORE(i, s, n) for (int i = (s); i <= (int)(n); i++)

#define ALL(vec) (vec).begin(), (vec).end()
#define REVALL(vec) (vec).rbegin(), (vec).rend()

#define debug(x) cerr << #x << ": " << x << '\n'
#define hyphen() cerr << "--\n"

#define fst first
#define pb push_back

const int MOD = (int)1e9 + 7;

int bigger(int a, int b) {
    return a >= b ? a : b;
}

int smaller(int a, int b) {
    return a >= b ? b : a;
}

signed main() {
    int N;

    cin >> N;

    vector<int> As(N);
    vector<int> Bs(N);
    REP(i, N) {
        cin >> As.at(i) >> Bs.at(i);
    }

    // (priority, score, ind)
    vector<tuple<int, int, int>> sorted_for_a(N);
    vector<tuple<int, int, int>> sorted_for_b(N);
    REP(i, N) {
        int a = As.at(i);
        int b = Bs.at(i);
        int priority = a + b;
        tuple<int, int, int> ta = make_tuple(priority, a, i);
        tuple<int, int, int> tb = make_tuple(priority, b, i);

        sorted_for_a.pb(ta);
        sorted_for_b.pb(tb);
    }

    sort(REVALL(sorted_for_a));
    sort(REVALL(sorted_for_b));

    queue<tuple<int, int, int>> a_queue;
    for (auto a : sorted_for_a) {
        a_queue.push(a);
    }

    queue<tuple<int, int, int>> b_queue;
    for (auto b : sorted_for_b) {
        b_queue.push(b);
    }

    // それが食べられたことを表す配列
    vector<bool> eaten(N, false);

    // ここから作業開始
    int score_a = 0;
    int score_b = 0;

    tuple<int,int,int> ta;
    tuple<int,int,int> tb;

    while(!a_queue.empty() || !b_queue.empty()) {
        // Aのターン

        // 食べられていない料理が見つかるまで捨てる
        while(true) {
            if (a_queue.empty()) {
                break;
            }

            ta = a_queue.front();
            a_queue.pop();

            int& ind = get<2>(ta);
            if (!eaten.at(ind)) {
                break;
            }
        }

        if (a_queue.empty()) {
            break;
        }

        // Aが食べる処理
        int& a = get<1>(ta);
        int& ind_a = get<2>(ta);
        debug(a);
        debug(ind_a);

        score_a += a;
        debug(ind_a);
        eaten.at(ind_a) = true;

        // 食べられていない料理が見つかるまで捨てる
        while(true) {
            if (b_queue.empty()) {
                break;
            }

            tb = b_queue.front();
            b_queue.pop();

            int& ind = get<2>(tb);
            if (!eaten.at(ind)) {
                break;
            }
        }

        // Bが食べる処理
        // 後攻はもう食べるものが無い可能性がある
        if (b_queue.empty()) {
            break;
        }

        int& b = get<1>(tb);
        int& ind_b = get<2>(tb);
        debug(b);
        debug(ind_b);

        score_b += b;
        debug(ind_b);
        eaten.at(ind_b) = true;
    }

    cout << score_a - score_b << endl;
}

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

//#define int long long
#define ll long long
#define all(v) (v).begin(), (v).end()
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<n;++i)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define EPS (1e-7)
#define gearup ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
typedef pair<ll, ll> P;
typedef vector<ll> vl;
typedef vector<vector<ll> > vvl;
typedef vector<vector<vector<ll> > > vvvl;
ll MOD = 1000000007;
const long long L_INF = 1LL << 60;
const int INF = 2147483647; // 2^31-1
const double PI = acos(-1);
//cout<<fixed<<setprecision(10);

template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}
template<class T> void debug(T v){rep(i,v.size()) cout<<v[i]<<" ";cout<<endl;}
const ll dx[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll dy[8] = {0, 1, 1, 1, 0, -1, -1, -1};

signed main()
{
    gearup;
    int n;cin >> n;
    vl a(n),b(n),c(n);
    rep(i,n){
        cin >> a[i] >> b[i];
        c[i] = a[i] + b[i];
    }
    sort(all(c),greater<ll>()); //降順そーと
    ll res = 0,res1=0;
    rep(i,n){
        if(i%2==0)res+=c[i];
        else res1+=c[i];
    }
    cout << res - accumulate(all(b),0LL) << endl;
}


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

int main(){

int score[20]={};

for(int i=0;i<10;i++){
  cin >> score[i];
 }
 sort(score, score+10);

 int score2[20]={};

for(int i=0;i<10;i++){
  cin >> score2[i];
 }
 sort(score2,score2+10);

int  sum1=score[9]+score[8]+score[7];
int  sum2=score2[9]+score2[8]+score2[7];

 cout << sum1 << ' '<< sum2 << endl;

}

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

#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

template<typename H> bool chmin(H& v1, const H v2) { if (v1 > v2) { v1 = v2; return true; } return false; }
template<typename H> bool chmax(H& v1, const H v2) { if (v1 < v2) { v1 = v2; return true; } return false; }
template<typename H> void read(H& head) { cin >> head; }
template<typename H, typename ...T> void read(H& head, T& ...tail) { cin >> head; read(tail...); }
template<typename H> void write(H head) { cout << head << '\n'; }
template<typename H, typename ...T> void write(H head, T ...tail) { cout << head << " "; write(tail...); }
template<typename ...T> void die(T ...tok) { write(tok...); exit(0); }

int main() {
	cin.tie(0)->sync_with_stdio(0);
	cin.exceptions(cin.failbit);

	int n, k; read(n, k);
	vector<int> v(n);

	rep(i, 0, n) read(v[i]);

	ll ans = 0;
	rep(i, 0, min(n, k) + 1) {
		int p = k - i; // put back
		rep(j, 0, i + 1) {
			int left = j, right = i - j;
			multiset<int> m;
			rep(k, 0, left) m.insert(v[k]);
			rep(k, 0, right) m.insert(v[n - 1 - k]);
			rep(k, 0, p) if (m.size() && *m.begin() < 0) m.erase(m.begin());
			ll lans = 0;
			for (int h : m) lans += h;
			chmax(ans, lans);
		}
	}
	die(ans);
}


#include <bits/stdc++.h>

#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 reps(i, n) for (int i = 1; i <= int(n); i++)
#define rreps(i, n) for (int i = int(n); i >= 1; i--)
#define repc(i, n) for (int i = 0; i <= int(n); i++)
#define rrepc(i, n) for (int i = int(n); i >= 0; i--)
#define repi(i, a, b) for (int i = int(a); i < int(b); i++)
#define repic(i, a, b) for (int i = int(a); i <= int(b); i++)
#define all(a) (a).begin(), (a).end()
#define bit32(x) (1 << (x))
#define bit64(x) (1ll << (x))
#define sz(v) ((int) v.size())

using namespace std;

using i64 = long long;
using f80 = long double;
using vi32 = vector<int>;
using vi64 = vector<i64>;
using vf80 = vector<f80>;
using vstr = vector<string>;

void yes() { cout << "Yes" << endl; exit(0); }
void no() { cout << "No" << endl; exit(0); }
template <typename T> class pqasc : public priority_queue<T, vector<T>, greater<T>> {};
template <typename T> class pqdesc : public priority_queue<T, vector<T>, less<T>> {};
template <typename T> void amax(T &x, T y) { x = max(x, y); }
template <typename T> void amin(T &x, T y) { x = min(x, y); }
template <typename T> T exp(T x, i64 n, T e = 1) { T r = e; while (n > 0) { if (n & 1) r *= x; x *= x; n >>= 1; } return r; }
template <typename T> istream& operator>>(istream &is, vector<T> &v) { for (auto &x : v) is >> x; return is; }
template <typename T> ostream& operator<<(ostream &os, vector<T> &v) { rep(i, v.size()) { if (i) os << ' '; os << v[i]; } return os; }
void solve(); int main() { ios::sync_with_stdio(0); cin.tie(0); cout << fixed << setprecision(16); solve(); return 0; }

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

void solve() {
  int n, k;
  cin >> n >> k;
  vi32 a(n);
  cin >> a;
  while (k--) {
    auto p = a;
    a.assign(n, 0);
    rep(i, n) {
      int l = max(0, i - p[i]);
      int r = min(n, i + p[i] + 1);
      a[l] += 1;
      if (r < n) a[r] -= 1;
    }
    rep(i, n - 1) a[i + 1] += a[i];
    if (a == p) {
      break;
    }
  }
  cout << a << endl;
}

#include <cstdio>
#include <iostream>
#include <cassert>
#include <string>
#include <algorithm>
#include <cstring>
#include <utility>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <cmath>
#include <deque>
#include <unordered_map>
#define IOS ios_base::sync_with_stdio(0); cin.tie(0)

using namespace std;
typedef long long LL;
typedef pair<int, int> pii;
typedef pair<LL, LL> pll;

const int MAXN = 234567;
int A[MAXN];
int sum[MAXN];

int main() {
    int N, K;
    scanf("%d %d", &N, &K);
    for (int i = 0; i < N; i++)
        scanf("%d", &A[i]);
    while (K--) {
        for (int i = 0; i < N; i++) {
            int l = max(0, i - A[i]);
            int r = min(N, i + A[i]) + 1;
            sum[l]++;
            sum[r]--;
        }
        int cur = 0;
        for (int i = 0; i < N; i++) {
            cur += sum[i];
            A[i] = cur;
            sum[i] = 0;
        }
        bool OK = false;
        for (int i = 0; i < N; i++) {
            if (A[i] != N)
                OK = true;
        }
        if (!OK) break;
    }
    for (int i = 0; i < N; i++)
        printf("%d ", A[i]);

    return 0;
}
/* stuff you should look for
	* int overflow, array bounds
	* special cases (n=1?)
	* do smth instead of nothing and stay organized
	* WRITE STUFF DOWN
by Benq;
*/


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

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

int main() {

    int h, w;

    cin >> h >> w;

    vector<vector<bool>> tile(h + 2, vector<bool>(w + 2, false));

    for(int i = 1; i <= h; ++i) {
        for(int j = 1; j <= w; ++j) {
            char ch;
            cin >> ch;

            if(ch == '.')
                tile[i][j] = true;

        }
    }

    bool isTrue = false;

    vector<vector<bool>> visited(h + 2, vector<bool>(w + 2, false));

    struct node {
        vector<pair<int, int>> walked;
        int i, j;
        void AddWalked(int i, int j) {
            walked.emplace_back(make_pair(i, j));
        }

        node(int i = 1, int j = 1) : walked(vector<pair<int, int>>()), i(i), j(j) {}

    };

    queue<node> q;
    q.push(node(1, 1));

    node ansNode;

    while(!q.empty()) {

        auto nowNode = q.front(); q.pop();
        int ni = nowNode.i, nj = nowNode.j;

        if(!tile[ni][nj] || visited[ni][nj])
            continue;

        visited[ni][nj] = true;

        if(ni == h && nj == w) {
            isTrue = true;
            ansNode = nowNode;
            break;
        }

        for(int i = 0; i < 4; ++i) {
            if(tile[dx[i] + ni][dy[i] + nj]) {
                node newNode(dx[i] + ni, dy[i] + nj);
                newNode.walked = nowNode.walked;
                newNode.AddWalked(dx[i] + ni, dy[i] + nj);
                q.push(newNode);
            }
        }

    }

    int answerCount = 0;

    if(isTrue) {
        tile[1][1] = false;
        for(int i = 0; i < ansNode.walked.size(); ++i) {
            int ai = ansNode.walked[i].first, aj = ansNode.walked[i].second;
            tile[ai][aj] = false;
        }

        for(int i = 1; i <= h; ++i)
            for(int j = 1; j <= w; ++j)
                if(tile[i][j])
                    answerCount++;

    }

    if(isTrue)
        cout << answerCount << endl;
    else
        cout << -1 << endl;

}

#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <stack>

using namespace std;

struct Info{
	Info(){
		rank = cost = point = 0;
	}
	int cost,point,rank;
};

int main(){

	int num_sport,num_member,cost_limit,maximum,max_index;

	Info info[1000];

	scanf("%d %d",&num_sport,&num_member);

	for(int i = 0; i < num_sport; i++){
		scanf("%d",&info[i].cost);
		info[i].rank = i+1;
	}

	for(int i = 1; i <= num_sport-1; i++){
		for(int k = num_sport-1; k >= i; k--){
			if(info[k].cost < info[k-1].cost)swap(info[k],info[k-1]);
		}
	}

	for(int i = 0; i < num_member; i++){
		scanf("%d",&cost_limit);
		maximum = 1000000000;
		for(int k = 0; k < num_sport; k++){
			if(info[k].cost > cost_limit)break;
			if(info[k].rank < maximum){
				maximum = info[k].rank;
				max_index = k;
			}
		}
		info[max_index].point++;
	}

	maximum = -1;

	for(int i = 0; i < num_sport; i++){
		if(info[i].point > maximum){
			maximum = info[i].point;
			max_index = i;
		}
	}

	printf("%d\n",info[max_index].rank);
	return 0;
}


#include <bits/stdc++.h>
#define pb push_back
#define ll long long
#define f first
#define s second
using namespace std;

int main(){
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    #ifdef debug
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
    vector<int> vec; vec.pb(111); vec.pb(222); vec.pb(333);
    vec.pb(444); vec.pb(555); vec.pb(666); vec.pb(777); vec.pb(888); vec.pb(999);
    int n; cin >> n;
    int t = *lower_bound(vec.begin(), vec.end(), n);
    cout << t << endl;
    return 0;
}

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

int main() {
  string s;
  cin >> s;
  vector<bool> app(26);
  rep(i, s.size()) app[s[i] - 'a'] = true;
  rep(i, 26) if(!app[i]) {
    cout << string(1, i + 'a') << "\n";
    return 0;
  }

  cout << "None" << "\n";
  return 0;
}


#include "bits/stdc++.h"

using namespace std;

long long dfs(long long K, long long A, long long B, long long C) {
    if (K == 0) {
        return A + B + C;
    }

    long long a = dfs(K - 1, 2 * A, B, C);
    long long b = dfs(K - 1, A, 2 * B, C);
    long long c = dfs(K - 1, A, B, 2 * C);
    return max(max(a, b), c);
}

void Main() {
    long long A, B, C;
    cin >> A >> B >> C;
    long long K;
    cin >> K;

    long long ans = dfs(K, A, B, C);
    cout << ans << endl;
}

int main() {
    std::cout << std::fixed << std::setprecision(15);
    Main();
    return 0;
}

#include<iostream>
#include<string>
#include<map>
#include<algorithm>
using namespace std;
typedef long long ll;
const int Max = 1e3 + 7;
int ls1[Max], ls2[Max];
int n;

int main()
{
	int a, b;
	string str;
	cin >> a >> b;
	cin >> str;
	int f = 0;
	for (int i = 0; i <= str.size() - 1; i++)
	{
		if (i == a)
		{
			if (str[i] != '-')
			{
				f = 1;
				break;
			}
		}
		else
		{
			if (!(str[i] <= '9' && str[i] >= '0'))
			{
				f = 1;
				break;
			}
		}
	}
	if (f)cout << "No";
	else cout << "Yes";
}


#include <bits/stdc++.h>

#define fi first
#define se second

const int N = 1000100;

using namespace std;

int n;
char a[N];
char b[N];
int last[N][26];

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

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

        cin >> n;
        for(int i = 1; i <= n; i++){
                cin >> a[i];
                for(int j = 0; j < 26; j++){
                        last[i][j] = last[i - 1][j];
                }
                last[i][a[i] - 'a'] = i;
        }
        bool good = true;
        for(int i = 1; i <= n; i++){
                cin >> b[i];
                if(a[i] != b[i]){
                        good = false;
                }
        }
        if(good){
                cout << 0 << "\n";
                return 0;
        }

        queue < int > v;
        int res = 0, gg = n;
        for(int i = n; i >= 1; i--){
                if(gg > i){
                        gg = i;
                }
                if(a[gg] == b[i]){
                        continue;
                }

                int h = last[gg][b[i] - 'a'];
                if(h == 0){
                        cout << -1 << "\n";
                        return 0;
                }
                gg = h;
                while(!v.empty() && v.front() - v.size() >= i){
                        v.pop();
                }
                v.push(h);
                res = max(res, (int)v.size());
        }
        cout << res << "\n";
}

#include<bits/stdc++.h>
using namespace std;
const int N=1e6+5;
char s[N],t[N];
int n,ans,l=1,r,last,q[N];
int main(){
	scanf("%d%s%s",&n,s+1,t+1),last=n;
	for(int i=n;i;){
		while(last&&(i<last||s[last]!=t[i])) --last;
		if(!last)	{puts("-1");return 0;}
		while(l<=r&&q[l]-r+l-1>=i)	++l;
		q[++r]=last;
		if(i!=last) ans=max(ans,r-l+1);
		while(t[i]==s[last]&&i>=last)	--i;
	}
	printf("%d\n",ans);
	return 0;
}


/*
 * File:   main.cpp
 * Author: freebsd
 *
 * Created on 2014/08/28, 10:07
 */

#include <cstdio>

using namespace std;

int main() {
    while (true) {
        int n = 0;
        int ice[10] = {0}, icetemp = 0;

        scanf("%d", &n);

        if(n == 0) break;

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

        for (int i = 0; i < 10; i++) {
            if(ice[i] > 0) {
                for(int j = 0; j < ice[i]; j++){
                    printf("*");
                }
            }else {
                printf("-");
            }
            printf("\n");
        }

    }

    return 0;
}

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

#define int           long long // change here
#define sfi(x)        scanf("%lld", &x) // change here

#define sfi2(x, y)    sfi(x) , sfi(y)
#define sfi3(x, y, z) sfi(x) , sfi(y) , sfi(z)
#define sfc(x)        scanf(" %c", &x)
#define sfs(x)        scanf(" %s", x)
#define sfsn(x)       scanf(" %[^\n]s", x)

#define pfi(x)        printf("%lld", (intl)x)
#define pfis(x)       printf("%lld", (intl)x), printf(" ")
#define pfin(x)       printf("%lld", (intl)x), printf("\n")
#define pfs(x)        printf("%s", x)
#define pfnl          printf("\n")
#define pfsp          printf(" ")
#define endl          '\n'
#define sp            ' '

#define watch(x)      cout<<"::debug::   "<< #x <<" : "<<x<<endl
#define watchi(i, x)  cout<<"::debug::   "<< #x <<"-> ["<<i<<"]"<<" : "<<x<<endl

#define FOR(i, begin, end)  for(__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define repit(it, x)        for(__typeof((x).begin()) it = (x).begin(); it != (x).end(); ++it)
#define perit(it, x)        for(__typeof((x).rbegin()) it = (x).rbegin(); it != (x).rend(); ++it)
#define rep(i, begin, end)  for(int i = (begin), ed = (end); i < (ed); ++i)
#define per(i, end, begin)  for(int i = (end)-1, bg = (begin); i >= (bg); --i)

#define setvalue(a, v)  for(int i = 0, sz = (sizeof(a)/sizeof(*a)); i<sz; i++){ a[i] = v; }
#define ZERO(a)       memset(a, 0, sizeof(a))
#define MINUS(a)      memset(a, 0xff, sizeof(a))

#define all(a)        a.begin(), a.end()
#define min3(x, y, z) min(x,min(y,z))
#define max3(x, y, z) max(x,max(y,z))
#define PI            2*acos(0)
#define INF           1000000007
#define debug         if( 1 )

const int mxn = 100010;

void solve(int tc)
{
    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 tot = 0;
    for(int i=0; i<2*n; i+=2) tot += arr[i];

    cout << tot << endl;
}

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

    solve(1);
    //int tc; cin>>tc; for(int t=1; t<=tc; t++) solve(t);

    return 0;
}


#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <cstring>

namespace IO {
    template <typename _T>
    inline bool read (_T& x) {
        x = 0;
        _T y = 1;
        char c = getchar();
        while ((c < '0' || '9' < c) && c != EOF) {
            if (c == '-') y = -1;
            c = getchar();
        }
        if (c == EOF) return false;
        while ('0' <= c && c <= '9') x = x * 10 + c - '0', c = getchar();
        x *= y;
        return true;
    }

    template <typename _T>
    inline _T input () {
        _T x = 0, y = 1;
        char c = getchar();
        while ((c < '0' || '9' < c) && c != EOF) {
            if (c == '-') y = -1;
            c = getchar();
        }
        if (c == EOF) return 0;
        while ('0' <= c && c <= '9') x = x * 10 + c - '0', c = getchar();
        x *= y;
        return x;
    }
};
using namespace IO;

namespace modular {
    const int MOD = 1000000007;

    inline int add (int x, int y) { return (x += y) >= MOD ? x -= MOD : x; }

    inline void inc (int &x, int y) { (x += y) >= MOD ? x -= MOD : 0; }

    inline int mul (int x, int y) { return 1LL * x * y % MOD; }

    inline int qpow (int x, int y) {
        int ans = 1;
        for (; y; y >>= 1, x = mul(x, x)) if (y & 1) ans = mul(ans, x);
        return ans;
    }
};
using namespace modular;

#define reg register
#define MAX_N 200007
#define FIN(s) freopen(s, "r", stdin)
#define FOUT(s) freopen(s, "w", stdout)
#define debug(...) fprintf(stderr, __VA_ARGS__)
#define rep(i, l, r) for(int i = l; i <= r; ++i)
#define lep(i, l, r) for(int i = l; i < r; ++i)
#define irep(i, r, l) for(int i = r; i >= l; --i)
#define ilep(i, r, l) for(int i = r; i > l; --i)
typedef long long ll;

int N, M, A, B;
int fac[MAX_N], ifac[MAX_N];

inline int C (int x, int y) {
    if (x < y || y < 0) return 0;
    return mul(fac[x], mul(ifac[y], ifac[x - y]));
}

inline void init () {
    int MX = 200000;
    fac[0] = ifac[0] = 1;
    rep (i, 1, MX) fac[i] = mul(fac[i - 1], i);
    ifac[MX] = qpow(fac[MX], MOD - 2);
    irep (i, MX, 2) ifac[i - 1] = mul(ifac[i], i);
}

int main () {
#ifdef LOCAL
    FIN("in");
#endif
    init();
    read(N), read(M), read(A), read(B);
    int res = 0;
    rep (i, 1, B) inc(res, mul(C(N - A - 1 + i - 1, i - 1), C(A - 1 + M - i, M - i)));
    res = add(C(N + M - 2, N - 1), MOD - res);
    printf("%d\n", res);
    return 0;
}

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

#define MOD 1000000007

int64_t expotent(int64_t n,int64_t m){
  if (m == 1) return n;
  else if (m % 2 == 0) return expotent(n * n % MOD, m/2);
  else return expotent(n * n % MOD, m/2) * n % MOD;
}

int64_t nCr(int64_t n, int64_t r){
  int Ans = 1;
  if (r > n / 2) r = n - r;
  for (int i = 1; i <= r; i++)
    Ans = Ans * (n + 1 - i) % MOD * expotent(i, MOD-2) %MOD;

  return Ans;
}

int main(){
  int64_t H, W, A, B;
  int64_t currentways = 1;
  int64_t ways = 0;

  cin >> H >> W >> A >> B;

  currentways = nCr(H+W-B-2, W-B-1);
  ways += currentways;
  for (int i = 1; i < H-A; i++){
    //ways += nCr(i+B-2, B-1) * nCr(H+W-i-B-1, W-B-1);
    currentways = currentways * (i+B-1) % MOD * expotent(i, MOD-2) % MOD * (H-i) % MOD * expotent(H+W-i-B-1, MOD-2) %MOD;
    ways =(ways + currentways) % MOD;
  }

  cout << ways;
}


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

int main() {
  vector<string> s(3);
  vector<int> vec(3),cnt(3);
  int n=0;
  rep(i,3){
    cin>>s[i];
    n+=s[i].size();
    cnt[i]=s[i].size();
  }
  int x=0;
  rep(i,n){
    if(cnt[x]==vec[x]){
      cout<<(char)(x+'A')<<endl;
      return 0;
    }
    x=s[x][vec[x]++]-'a';
  }
}

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

int main() {

  string SA, SB, SC;
  cin >> SA >> SB >> SC;

  int ind_A = 1, ind_B = 0, ind_C = 0;

  char cur = SA[0];

  while(true) {

    // 文字を見る
    if (cur == 'a') {

      // 終了条件のチェック
      if (ind_A == SA.size()) {
        cout << "A" << endl;
        return 0;
      } else { // 終了しない場合の cur の更新
        cur = SA[ind_A];
        ind_A++;
      }
    } else if (cur ==  'b') {

      // Bのカードを見る

      // 終了条件のチェック
      if (ind_B == SB.size()) {
        cout << "B" << endl;
        return 0;
      } else { // 終了しない場合の cur の更新
        cur = SB[ind_B];
        ind_B++;
      }
    } else {

      // 終了条件のチェック
      if (ind_C == SC.size()) {
        cout << "C" << endl;
        return 0;
      } else { // 終了しない場合の cur の更新
        cur = SC[ind_C];
        ind_C++;
      }
    }
  }

}


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

#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define endl "\n"
const double EPS = 1e-7;
const int INF = 1 << 30;
const ll LLINF = 1LL << 60;
const double PI = acos(-1);
const int MOD = 1000000007;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

//-------------------------------------

vector<string> three = {
    "add",
    "a.c",
    "bbc",
};

vector<string> four = {
    "afgg",
    "afhh",
    "bbde",
    "ccde",
};

vector<string> five = {
    "ahhii", "ag..j", "bg..j", "b.ffe", "ccdde",
};

vector<string> six = {
    "aa.bbc", "de...c", "deff..", "..gghi", "j...hi", "jkk.ll",
};

vector<string> seven = {
    "a.jj.kk", "ai..ll.", ".i.mm.o", "b.h...o", "b.h..g.", ".ff..ge", "cc.dd.e",
};

int n;

// 4,5,6,7
void solve(int a, int b, int c, int d) {
    vector<string> ans(n, string(n, '.'));
    int id = 0;
    for(int i = 0; i < a; i++) {
        for(int y = id; y < id + 4; y++) {
            for(int x = id; x < id + 4; x++) {
                ans[y][x] = four[y - id][x - id];
            }
        }
        id += 4;
    }
    for(int i = 0; i < b; i++) {
        for(int y = id; y < id + 5; y++) {
            for(int x = id; x < id + 5; x++) {
                ans[y][x] = five[y - id][x - id];
            }
        }
        id += 5;
    }
    for(int i = 0; i < c; i++) {
        for(int y = id; y < id + 6; y++) {
            for(int x = id; x < id + 6; x++) {
                ans[y][x] = six[y - id][x - id];
            }
        }
        id += 6;
    }
    for(int i = 0; i < d; i++) {
        for(int y = id; y < id + 7; y++) {
            for(int x = id; x < id + 7; x++) {
                ans[y][x] = seven[y - id][x - id];
            }
        }
        id += 7;
    }
    for(int i = 0; i < n; i++) {
        cout << ans[i] << endl;
    }
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> n;
    if(n <= 2) {
        cout << -1 << endl;
        return 0;
    }
    if(n == 3) {
        for(int i = 0; i < three.size(); i++) {
            cout << three[i] << endl;
        }
        return 0;
    }
    for(int i = 0; i * 7 <= n; i++) {
        for(int j = 0; j * 6 <= n; j++) {
            for(int k = 0; k * 5 <= n; k++) {
                int sum = i * 7 + j * 6 + k * 5;
                if(sum <= n && (n - sum) % 4 == 0) {
                    int l = (n - sum) / 4;
                    solve(l, k, j, i);
                    return 0;
                }
            }
        }
    }
    cout << -1 << endl;
}