#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<functional>
#include<vector>
using namespace std;

int main(){
	int N,M;
	while(cin>>N>>M,N||M){
		int latte[1001],ans=0;
		vector<int> comb;
		latte[0]=0;
		for(int i=1;i<=N;i++){
			cin>>latte[i];
		}
		for(int i=0;i<N;i++){
			for(int j=0;j<N;j++){
				comb.push_back(latte[i]+latte[j]);
			}
		}
		sort(comb.begin(),comb.end());
		//for(int i=0;i<comb.size();i++) printf("%d ",comb[i]); puts("");
		for(int i=0;i<=N;i++){
			for(int j=0;j<=N;j++){
				vector<int>::iterator itr;
				itr = upper_bound(comb.begin(),comb.end(),M-latte[i]-latte[j]);
				if(itr!=comb.begin()) ans = max(ans,latte[i]+latte[j]+*(itr-1));
			}
		}
		printf("%d\n",ans);
	}
	return 0;
}

#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define INF (1<<30)
#define INFLL (1ll<<60)
typedef pair<int, int> P;
typedef pair<ll, P> E;
#define MOD (1000000007ll)
#define l_ength size
#define PI 3.14159265358979

void mul_mod(ll& a, ll b){
	a *= b;
	a %= MOD;
}

void add_mod(ll& a, ll b){
	b += MOD;
	a += b;
	a %= MOD;
}

int n,s;
ll m,p[1234567];

ll search(ll x){
	int l,r,mid;
	if(x>m){
		return 0ll;
	}
	l = 0; r = s;
	while((r-l)>1){
		mid = (l+r)/2;
		if(x+p[mid]>m){
			r = mid;
		}else{
			l = mid;
		}
	}
	return ((x+p[r]>m)?(x+p[l]):(x+p[r]));
}

int main(void){
	int i,j;
	ll ans;
	cin >> n >> m;
	while(!(n==0&&m==0ll)){
		ans = 0ll; s = n*n+n+1;
		for(i=0; i<n; ++i){
			cin >> p[i];
		}
		for(i=0; i<n; ++i){
			for(j=0; j<n; ++j){
				p[n+i*n+j] = p[i]+p[j];
			}
		}
		p[s-1] = 0ll;
		sort(p,p+s);
		for(i=0; i<s; ++i){
			ans = max(ans,search(p[i]));
		}
		cout << ans << endl;
		cin >> n >> m;
	}
	return 0;
}


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

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

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

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

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

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

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

using namespace std;

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

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

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

const int N = 1e5 + 7;
int n;
ll s, x[N], p[N];

ll f(int l, int r, int o) {
	if (s < x[l] || x[r] < s) return abs(s - x[o]);
	if (p[l] >= p[r]) return p[l] += p[r], f(l, r - 1, l) + abs(x[l] - x[o]);
	return p[r] += p[l], f(l + 1, r, r) + abs(x[r] - x[o]);
}

int main() {
	rd(n), rd(s);
	for (int i = 1; i <= n; i++) rd(x[i], p[i]);
	print(f(1, n, s < x[1] ? n : x[n] < s ? 1 : p[1] >= p[n] ? n : 1));
	return 0;
}

#include <bits/stdc++.h>

#define For(i, j, k) for (int i = j; i <= k; i++)

using namespace std;

typedef long long LL;

const int N = 1e5 + 10;

int x[N];
LL w[N];
int S, n;

int main() {

	scanf("%d%d", &n, &S);
	For(i, 1, n) scanf("%d%lld", &x[i], &w[i]);

	int l = 1, r = n, nxt = 0;
	LL ans = 0;
	while (x[l] < S && x[r] > S) {
		if (w[l] >= w[r]) {
			w[l] += w[r];
			if (nxt != l) ans += x[r] - x[l];
			--r, nxt = l;
		} else {
			w[r] += w[l];
			if (nxt != r) ans += x[r] - x[l];
			++l, nxt = r;
		}
	}

	if (x[l] < S) ans += S - x[l];
	else ans += x[r] - S;
	printf("%lld\n", ans);

	return 0;
}


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

int main() {
  int n;
  cin >> n;
  cout << n * n * n << endl;
}

#include<iostream>
using namespace std;

int main(){
    int x, y=1, i;

    cin >> x;

    for(i = 0; i < 3; i++){
        y = y * x;
    }

    cout << y << endl;
    return 0;
}


#include <iostream>
#define ll long long
using namespace std;
bool mx[1003][1003], flag[10004];
ll a[1003], b[1003], ans[1003][1003];
ll prime[10004];
ll gcd(ll x, ll y){
	if (y == 0)
		return x;
	return gcd(y, x % y);
}
ll lcm(ll x, ll y){
	if (x == 0 || y == 0)
		return x + y;
	return x / gcd(x, y) * y;
}
int main(){
	int prime_cnt = 0;
	for (int i = 2; i <= 10000; ++ i){
		if (! flag[i])
			prime[++ prime_cnt] = i;
		for (int j = 2; i * j <= 10000; ++ j){
			flag[i * j] = true;
			if (i % j == 0)
				break;
		}
	}
	int n;
	cin >> n;
	if (n == 2){
		cout << "4 7" << endl << "23 10" << endl;
		return 0;
	}
	for (int i = 1; i <= n; ++ i)
		for (int j = 1; j <= n; ++ j)
			if (i % 2 == j % 2)
				mx[i][j] = true;
	int cnt = 0;
	for (int i = 1; i <= n; ++ i)
		for (int j = 1; j <= n; ++ j)
			if (! mx[i][j]){
				//if (! a[i + j])
					//a[i + j] = prime[++ cnt];
				//if (! b[i - j + n])
					//b[i - j + n] = prime[++ cnt];
				//ans[i][j] = a[i + j] * b[i - j + n];
				ans[i][j] = prime[(i + j) / 2] * prime[(i + n + 1 - j) / 2 + n];
			}
	for (int i = 1; i <= n; ++ i)
		for (int j = 1; j <= n; ++ j)
			if (mx[i][j])
				ans[i][j] = lcm(lcm(ans[i - 1][j], ans[i + 1][j]), lcm(ans[i][j - 1], ans[i][j + 1])) + 1;
	for (int i = 1; i <= n; ++ i){
		for (int j = 1; j <= n; ++ j)
			cout << ans[i][j] << " ";
		cout << endl;
	}
}

#define _USE_MATH_DEFINES
#include<iostream>
#include<string>
#include<queue>
#include<cmath>
#include<map>
#include<set>
#include<list>
#include<iomanip>
#include<vector>
#include<random>
#include<functional>
#include<algorithm>
#include<stack>
#include<cstdio>
#include<bitset>
#include<unordered_map>
#include<climits>
#include<fstream>
using namespace std;
typedef long long ll;
typedef long double ld;
#define all(a) (a).begin(),(a).end()
#define EPS (1e-5)
#define bit(n,k) ((n>>k)&1)
const ll Mod = 1000000007;
const ll mod = 998244353;
struct H {
	ld x, y;
	bool operator<(const H& b) const {
		if (x != b.x) return x < b.x;
		return y < b.y;
	}
	bool operator>(const H& b) const {
		if (x != b.x) return x > b.x;
		return y > b.y;
	}
	bool operator==(const H& b) const { return x == b.x && y == b.y; }
	bool operator!=(const H& b) const { return (*this) != b; }
};
struct P {
	ll pos, cost;
	bool operator<(const P& b) const { return cost < b.cost; }
	bool operator>(const P& b) const { return cost > b.cost; }
};
struct B {
	ll to, cost;
};
struct E {
	ll from, to, cost;
	bool operator<(const E& b) const { return cost < b.cost; }
	bool operator>(const E& b) const { return cost > b.cost; }
};
template<typename T, typename U>
void chmin(T& a, U b) {
	if (a > b) a = b;
}
template<typename T, typename U>
void chmax(T& a, U b) {
	if (a < b) a = b;
}
template<typename T>
T max_0(T a) {
	if (a < 0) return 0;
	return a;
}
template<typename T>
T min_0(T a) {
	if (a > 0) return 0;
	return a;
}
ll read() {
	ll u;
	ll k = scanf("%lld", &u);
	return u;
}
ll gcd(ll i, ll j) {
	if (i > j) swap(i, j);
	if (i == 0) return j;
	return gcd(j % i, i);
}
ll mod_pow(ll x, ll n, ll p) {
	ll res = 1;
	while (n > 0) {
		if (n & 1) res = res * x % p;
		x = x * x % p;
		n >>= 1;
	}
	return res;
}//x^n%p
const ll Inf = 3023372036854775807;
const int inf = 1500000000;
#define int long long
//----------------------------------------------------
int n;
struct A { ld x, y; int t; } a[200000];
bool operator<(A a, A b) { if (a.x != b.x) return a.x > b.x; return a.y > b.y; }

ld sgarea(A a, A b, A c) {
	return ((b.x - a.x) * (c.y - a.y) - (c.x - a.x) * (b.y - a.y)) / 2;
}
H b[400000];
ld d[2000];
signed main() {
	cin >> n;
	H sum = { 0,0 };
	for (int i = 0; i < n; i++) {
		cin >> a[i].x >> a[i].y;
		sum.x += a[i].x, sum.y += a[i].y;
		a[i].t = i;
	}
	sum.x /= n, sum.y /= n; sum.x += 0.01, sum.y -= 0.01;
	sort(a, a + n);
	for (int i = 0; i < n; i++) {
		b[i] = H{ atan2(a[i].y - sum.y, a[i].x - sum.x) ,(ld)i };
		if (b[i].x < 0) b[i].x += 2 * M_PI;
	}
	sort(b, b + n);
	for (int i = 1; i < 3; i++)for (int j = 0; j < n; j++) b[i * n + j] = b[j];
	vector<int>v;
	int s = 0;
	for (int i = 0; i < n; i++) if (b[i].y == 0) s = i;
	v.push_back(b[s].y); v.push_back(b[s + 1].y);
	for (int i = 2; i <= n; i++) {
		do {
			if (sgarea(a[v[v.size() - 2]], a[v[v.size() - 1]], a[(int)b[i + s].y]) < 0) {
				v.pop_back();
			}
			else break;
		} while (v.size() > 1);
		v.push_back(b[i + s].y);
	}
	v.pop_back();
	vector<A>u;
	for (int i = 0; i < v.size(); i++) {
		u.push_back(A{ a[v[i]].x,a[v[i]].y, a[v[i]].t });
	}
	int U = u.size();
	ld res = 0;
	for (int j = 0; j < 2; j++) for (int i = 0; i < U; i++) u.push_back(u[i]);
	for (int i =U; i < 2 * U; i++) {
		ld u1 = atan2(u[i - 1].y - u[i].y, u[i - 1].x - u[i].x), u2 = atan2(u[i + 1].y - u[i].y, u[i + 1].x - u[i].x);
		if (u1 < 0) u1 += 2 * M_PI;
		if (u2 < 0) u2 += 2 * M_PI;
		ld x = abs(u1 - u2);
		if (x > M_PI) x = 2 * M_PI - x;
		d[u[i].t] = M_PI - x;
		res += d[u[i].t];
	}
	for (int i = 0; i < n; i++) {
		printf("%.12LF\n", d[i] / M_PI / 2);
	}
}


#include "bits/stdc++.h"

using namespace std;
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);

#define ll long long
#define li long int
#define ld long double
#define lld long long double

#define pb push_back
#define mk make_pair
#define F first
#define S second

#define all(v) (v).begin(),(v).end()
#define fill(a) memset(a, 0, sizeof(a))

const int MX = 1e6;
const int MI = -1e6;
const int MOD = 1e9 + 7;
const string ALPHA = "abcdefghijklmnopqrstuvwxyz";
const double PI = 3.1415926535;

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

const int mod=1e9+7;
inline int add(int x,int y){
  x+=y;
  if (x>=mod) return x-mod;
  return x;
}
inline int sub(int x,int y){
  x-=y;
  if (x<0) return x+mod;
  return x;
}
inline int mul(int x,int y){
  return (x*1ll*y)%mod;
}
inline int power(int x,int y){
  int ans=1;
  while(y){
    if (y&1) ans=mul(ans,x);
    x=mul(x,x);
    y>>=1;
  }
  return ans;
}
inline int inv(int x){
  return power(x,mod-2);
}

int main()
{
  IOS;
  int a, b, c;
  cin >> a >> b >> c;
  cout << c << " " << a << " " << b << endl;

  return 0;
}

#include <iostream>
using namespace std;

#include <cmath>
int main(){
    int n,x,t; cin >> n >> x >> t;
    cout << (long long)ceil((double)n/x)*t << endl;
}


#include<bits/stdc++.h>
using namespace std;
string s;
int main()
{
	getline(cin,s);
	int len=s.size()-8;
	for(int i=0;i<len;i++)cout<<s[i];

	return 0;
}

#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
const ll mod=1000000007;
const int MAX_N = 1000;         // n の最大値

// nCk を取得
double nCk(int n, int k) {
double res=1.0;
for(int i=0; i<n; i++){
res*=0.5;}
for(int i=0; i<k; i++){
res*=(double)(n-i);
res/=(double)(k-i);
}
return res;}

int main() {
string n;
cin>>n;
string ca = n.substr(0,n.size()-8);
cout <<ca<< endl;
return 0;}


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

#define INF 1e9
#define LLINF 1e18
#define pi 3.14159265358979323
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;

int gcd(int a, int b) {
    if(a % b == 0) {
        return b;
    }
    else {
        return(gcd(b, a % b));
    }
}

int main() {
    int a, b, m;
    cin >> a >> b >> m;
    vector<int> veca(a);
    vector<int> vecb(b);
    int minia = INF;
    int minib = INF;
    rep(i, a) {
        cin >> veca.at(i);
        minia = min(minia, veca.at(i));
    }
    rep(i, b) {
        cin >> vecb.at(i);
        minib = min(minib, vecb.at(i));
    }
    int mini = minia + minib;
    int dismini = INF;
    vector<vector<int> > dis(m, vector<int> (3));
    rep(i, m) {
        rep(j, 3) {
            cin >> dis.at(i).at(j);
        }
        dismini = min(dismini, veca.at(dis.at(i).at(0) - 1) + vecb.at(dis.at(i).at(1) - 1) - dis.at(i).at(2));
    }
    cout << min(dismini, mini) << endl;
}

#include<bits/stdc++.h>
using namespace std;
#define ll long long
void read(int &x)
{
    int f=1;
    x=0;
    char s=getchar();
    while(s<'0'||s>'9')
    {
        if(s=='-')
            f=-1;
        s=getchar();
    }
    while(s>='0'&&s<='9')
    {
        x=x*10+s-'0';
        s=getchar();
    }
    x*=f;
}
#define N 100005
int n,m,t;
int a[N],b[N];
int main(){
    cin>>n>>m>>t;
    for (int i = 1; i <= n; i++)
    {
        cin>>a[i];
    }
    for (int i = 1; i <= m; i++)
    {
        cin>>b[i];
    }
    int ans=1e9;
    for (int i = 0; i < t; i++)
    {
        int x,y,c;
        cin>>x>>y>>c;
        ans= min(a[x]+b[y]-c,ans);
    }
    sort(a+1,a+n+1);
    sort(b+1,b+m+1);
    cout<<min(ans,a[1]+b[1]);

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef vector<ll> vl;
typedef pair<ll, ll> PP;
#define rep(i, n) for(ll i = 0; i < ll(n); i++)
#define all(v) v.begin(), v.end()
#define inputv(v, n)                                                           \
    vl v;                                                                      \
    rep(i, n) {                                                                \
        ll x;                                                                  \
        cin >> x;                                                              \
        v.push_back(x);                                                        \
    }
bool chmin(ll& a, ll  b) { if (b < a) { a = b; return 1; } return 0; }
bool chmax(ll& a, ll b) { if (b > a) { a = b; return 1; } return 0; }
const ll INF = 999999999999999;
const ll MOD = 1000000007;
const ll MAX_N = 500010;
ll a, b, c, d, e, f, p, t, x, y, z, q, m, n, r, h, k, w, l, ans;
struct Gragh {
    ll N;
    vector<vl> G;
    vl visited;

    Gragh(ll n) {
        N = n;
        G.resize(N);
        resetv();
    }

    void add(ll a, ll b) { G[a].push_back(b); }

    void resetv(void) { visited = vl(N, 0); }

    //重さ無し
    void dfs(ll x) {
        visited[x] = 1;
        for (ll i : G[x]) {
            if (visited[i] == 0) {
                dfs(i);
            }
        }
    }
};
int main() {
    cin >> n >> m;
    Gragh G(2 * n);
    rep(i, m) {
        cin >> a >> b;
        a--;
        b--;
        G.add(a * 2, b * 2 + 1);
        G.add(b * 2, a * 2 + 1);
        G.add(a * 2+1, b * 2);
        G.add(b * 2+1, a * 2);
    }

    G.dfs(0);
    vl dp(2, 0);
    rep(i, n * 2) {
        if (G.visited[i] == 1)dp[i % 2]++;
    }

    x=dp[0];
    y=dp[1];
    k=x+y-n;
    ans=k*(n-k)+k*(k-1)/2+(x-k)*(y-k)-m;

    cout << ans << endl;
}

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const double pi=3.141592653589793;
typedef unsigned long long ull;
typedef long double ldouble;
const ll INF=1e18;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(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; }

const int MAX_V = 100005;

vector<int> G[MAX_V];
vector<int> color(MAX_V);

// 辺に属性がある場合
/*
struct edge {int to,cost;};
vector<edge> G[MAX_V];
*/

// 2部グラフの場合: b*w - m 2部グラフでない場合: n(n-1)/2 - m
bool dfs(int v, int c){
    color[v] = c;
    rep(i, G[v].size()){
        if(color[G[v][i]] == c) return false;
        if(color[G[v][i]] == 0 && !dfs(G[v][i], -c)) return false;
    }
    return true;
}

int main(){
    ll N, M;
    cin >> N >> M;
    rep(i, M){
        int s, t;
        cin >> s >> t;
        s--; t--;
        G[s].push_back(t);
        // 無向グラフの場合
        G[t].push_back(s);
    }

    // グラフの操作
    ll B = 0, W = 0;
    if(dfs(0, 1)){
        rep(i, N){
            if(color[i] == 1){
                B++;
            }
            else if(color[i] == -1){
                W++;
            }
        }
        cout << B*W - M << endl;
    }
    else {
        cout << ((N * (N-1)) / 2) - M << endl;
    }
}


#include <iostream>
#include <bitset>
#include <vector>
#include <sstream>
#include <algorithm>

int main(){

    int purchase_num;
    int max_cap;

    while(std::cin >> purchase_num >> max_cap){
        if(purchase_num == 0 && max_cap == 0) break;
        std::vector<int> price;
        std::string str;
        int input_data;
        int min_price = 0;
        std::cin.ignore();
        std::getline(std::cin, str);
        std::istringstream iss(str);
        while(!iss.eof()){
            iss >> input_data;
            price.push_back(input_data);
        }
        std::sort(price.begin(),price.end(),std::greater<int>());
        for(int i = 0; i < price.size(); ++i){
            if((i+1)%max_cap != 0){
                min_price += price[i];
            }
        }
        std::cout << min_price << std::endl;
    }
    return 0;
}

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

int p[1000];
int main() {
	int n, m;
	while (cin >> n >> m, n) {
		int sum = 0;
		rep(i, n) {
			scanf("%d", &p[i]);
			sum += p[i];
		}
		sort(p, p + n, greater<>());
		for (int i = m - 1; i < n; i += m) {
			sum -= p[i];
		}
		cout << sum << endl;
	}
}


#pragma GCC optimize("Ofast")
#define _USE_MATH_DEFINES
#include "bits/stdc++.h"

using namespace std;

using u8 = uint8_t;
using u16 = uint16_t;
using u32 = uint32_t;
using u64 = uint64_t;
using i8 = int8_t;
using i16 = int16_t;
using i32 = int32_t;
using i64 = int64_t;

using vi = vector<int>;

constexpr char newl = '\n';
constexpr double eps = 1e-10;

#define FOR(i,a,b) for (int i = (a); i < (b); i++)
#define F0R(i,b) FOR(i,0,b)
#define RFO(i,a,b) for (int i = ((b)-1); i >=(a); i--)
#define RF0(i,b) RFO(i,0,b)
#define fi first
#define se second
#define show(x) cout << #x << " = " << x << '\n';
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define sz(x) (int)(x).size()
#define YesNo {cout<<"Yes";}else{cout<<"No";}
#define YESNO {cout<<"YES";}else{cout<<"NO";}
#define v(T) vector<T>

template<typename T1, typename T2> inline void chmin(T1& a, T2 b) { if (a > b) a = b; }
template<typename T1, typename T2> inline void chmax(T1& a, T2 b) { if (a < b) a = b; }
template<class T> bool lcmp(const pair<T, T>& l, const pair<T, T>& r) {
  return l.first < r.first;
}
template<class T> istream& operator>>(istream& i, v(T)& v) {
  F0R(j, sz(v)) i >> v[j];
  return i;
}
template<class A, class B> istream& operator>>(istream& i, pair<A, B>& p) {
  return i >> p.first >> p.second;
}
template<class A, class B, class C> istream& operator>>(istream& i, tuple<A, B, C>& t) {
  return i >> get<0>(t) >> get<1>(t) >> get<2>(t);
}
template<class T> ostream& operator<<(ostream& o, const vector<T>& v) {
  F0R(i, v.size()) {
    o << v[i] << ' ';
  }
  o << newl;
  return o;
}
template<class T1, class T2> ostream& operator<<(ostream& o, const map<T1, T2>& m) {
  for (auto& p : m) {
    o << p.first << ": " << p.second << newl;
  }
  o << newl;
  return o;
}

#if 1

// INSERT ABOVE HERE
signed main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);

  int N, M;
  cin >> N >> M;
  vector<int> a(N + 1), b(M + 1);
  cin >> a[0] >> b[0];
  F0R(i, N) cin >> a[i + 1];
  F0R(i, M) cin >> b[i + 1];
  sort(rng(a));
  sort(rng(b));
  cout << (a.back() < b[0] ? "No War" : "War");
}
#endif

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

int main(){
  string N,m;
  cin >> N;
  int x,y = 0;
  for(int i = 0; i < int(N.size()); i++){
    istringstream n;
    m = N[i];
  	n = istringstream(m);
  	n >> x;
    y += x;
  }
  if (stoi(N) % y == 0){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
}


#include <iostream>
#include <cmath>
#include <cstdlib>

using namespace std;

int main(int argc, char* argv[])
{
    int n = 0, n2 = 0;
    cin >> n;
    //n = atoi(argv[1]);
    if(n < 1 || n > 100) {
        return 1;
    }
    n2 = pow(n, 3.0);
    cout << n2 << endl;
}

#include<iostream>
#include<cstdio>

int main() {
    int n;
    std::cin >> n;
    printf("%d\n", n * n * n);
    return 0;
}


#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <cmath>
#include <climits>
#include <iomanip>
#include <set>
#include <map>
using namespace std;
typedef long long ll;
int main(){
  ll n = 0;
  cin >> n;
  vector<ll> a(n);
  for(int i = 0;i < n;i++)cin >> a[i];
  vector<ll> c;
  c.push_back(a[0]);
  for(int i = 1;i < n;i++){
    //if(i == 5)cout << c.size()<< " " << c[0] << " " << c[1] << " " << c[2] << endl;

    ll pushnum = 0;
    ll popit = lower_bound(c.begin(),c.end(),a[i]) - c.begin();
    if(popit == 0)pushnum = a[i];
    else{
      pushnum = a[i];
      c.erase(c.begin() + popit - 1);
    }

    ll pushit = lower_bound(c.begin(),c.end(),pushnum) - c.begin();
    c.insert(c.begin() + pushit,pushnum);
  }
  //cout << c[0] << " " << c[1] << " " << c[2] << endl;
  cout << c.size() << endl;
}

#include<bits/stdc++.h>
#include<vector>
#include<string>
#include<stack>
#include<iostream>
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ll long long
#define MOD 1000000007
#define vec(a) vector<int>a
using namespace std;

bool isPrime(ll n)
{
	if(n==1||n==2||n==3||n==5||n==7)
		return 1;
	else
	{
		ll i,j,k,l,m;
		for(i=2;i<=sqrt(n);i++)
		{
			if(n%i==0)
				return 0;
		}
		return 1;
	}
}

int main()
{
#ifndef ONLINE_JUDGE
	freopen("output.txt", "w", stdout);
	freopen("input.txt", "r", stdin);
#endif
	ll arr[3];
	cin>>arr[0]>>arr[1]>>arr[2];
	sort(arr,arr+3);
	cout<<arr[0]+arr[1];
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define dup(x,y) (((x)+(y)-1)/(y))
#define ALL(x) (x).begin(), (x).end()
typedef long long ll;
typedef pair<int, int> pii;
const double EPS = 1e-10;
const int INF = 1e9;
const ll LINF = 1e18;
const int MOD = 1000000007;
const double PI = acos(-1);
int dx[4] = {0,1,0,-1};
int dy[4] = {1,0,-1,0};

int main() {
	int n, k;
	cin >> n >> k;
	int c = 0;
	int t = 1;
	while (t < k) {
		t -= 1;
		t += n;
		c++;
	}
	cout << c << endl;
}

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

int main() {
  int a, b;
  cin >> a >> b;
  int cnt = 1;
  while (1) {
    if ((a-1) * (cnt-1) + a >= b) break;
    cnt++;
  }
  if (b == 1) cout << 0 << endl;
  else cout << cnt << endl;
  return 0;
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef tuple<int, int> duo;
const int dx[] = {0, 0, 1, -1, 1, 1, -1, -1};
const int dy[] = {1, -1, 0, 0, 1, -1, 1, -1};
const int Mod = 1000000000 + 0;
//{{{ templates
#define TT_ template<typename T>inline
#define TTF_ template<typename T,typename F>inline
TT_ T sq(T x){return x*x;}
TT_ T In(){T x;cin>>x;return x;}
TT_ void Out(T&x){cout<<x;}
TT_ void sort(T&v){sort(begin(v),end(v));}
TT_ void revs(T&v){reverse(begin(v),end(v));}
TT_ void uniq(T&v){sort(v);v.erase(unique(begin(v),end(v)),end(v));}
TT_ int ubnd(T&v,typename T::value_type x){return upper_bound(begin(v),end(v),x)-begin(v);}
TT_ int lbnd(T&v,typename T::value_type x){return lower_bound(begin(v),end(v),x)-begin(v);}
TTF_ void inpt(T&v,int n,F f){for(v.reserve(n);n--;v.emplace_back(f()));}
TTF_ void show(T&v,F f,string d=" ",string e="\n"){int i=0;for(auto&x:v)i++&&(cout<<d),f(x);cout<<e;}
TT_ typename T::iterator minel(T&v){return min_element(begin(v),end(v));}
TT_ typename T::iterator maxel(T&v){return max_element(begin(v),end(v));}

inline void fast_io(){ios_base::sync_with_stdio(0);cin.tie(0);}
inline int in(){int x;scanf("%d",&x);return x;}
inline ll pow_mod(ll a,ll k,ll m){ll r=1;for(;k>0;a=a*a%m,k>>=1)if(k&1)r=r*a%m;return r;}
inline ll mod_inv(ll a,ll p){return pow_mod(a,p-2,p);}
//}}} priority_queue queue deque front stringstream max_element min_element insert count make_tuple

int main()
{
  int N, Q;
  while (N = in(), Q = in(), N || Q){
    int bkt[128] = {};
    for (int i = 0; i < N; i++){
      for (int x = in(); x--;){
        bkt[in()]++;
      }
    }
    int maxi = 0;
    for (int i = 1; i < 128; i++){
      if (bkt[i] >= Q && bkt[maxi] < bkt[i]){
        maxi = i;
      }
    }
    cout << maxi << endl;
  }
  return 0;
}

#include <iostream>
using namespace std;
int main(){
  int N,Q,i,I,M,data,max,result;
  int box[100]={};
  while(1){
  cin>>N>>Q;
  if(N==0||Q==0) break;
  for(i=1;i<=N;i++){
    cin>>M;
    for(I=1;I<=M;I++){
      cin>>data;
      box[data]++;
    }
  }
  max=-1;
  for(i=0;i<100;i++){
    if(max<box[i]){
      max=box[i];
      result=i;
    }
  }
  if(box[result]<Q) cout<<"0"<<endl;
  else cout<<result<<endl;
  for(i=0;i<100;i++){
    box[i]=0;
  }
  }
  return 0;
}


#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define rep(i,n) for (ll i=0; i<n; ++i)
#define all(c) begin(c),end(c)
#define PI acos(-1)
#define oo LLONG_MAX
template<typename T1, typename T2>
bool chmax(T1 &a,T2 b){if(a<b){a=b;return true;}else return false;}
template<typename T1, typename T2>
bool chmin(T1 &a,T2 b){if(a>b){a=b;return true;}else return false;}
/*

*/
//BIT
#define M 500010
ll dat[M];
void init(){
  rep(i, M) dat[i] = 0;
}
void add(ll i, ll x){
  for(; i<M; i += i&-i) dat[i] += x;
}
ll sum(ll i){
  ll res = 0;
  for(; i>0; i -= i&-i) res += dat[i];
  return res;
}
ll rangesum(ll L, ll R){
  return sum(R) - sum(L-1);
}

ll A[M] = {};
vector<ll> QL[M], QID[M];
ll ans[M];

ll N, Q, C[M];

int main(){
  cin.tie(0);
  ios::sync_with_stdio(0);
  cin >> N >> Q;
  for(ll i = 1; i <= N; i++) cin >> C[i];
  rep(i, Q){
    ll L, R;
    cin >> L >> R;
    QL[R].push_back(L);
    QID[R].push_back(i);//後続、sortしないで順番に出せる
  }
  init();
  for(ll i = 1; i <= N; i++){
    if (A[C[i]] > 0) add(A[C[i]], -1);
    add(i, +1);
//rep(i, Q+10) cout<<dat[i]; cout<<endl;
    A[C[i]] = i;
    rep(j, QL[i].size())
      ans[QID[i][j]] = rangesum(QL[i][j], i);
  }

  rep(i, Q) cout << ans[i]<< endl;
}

#define NguyenDangQuan the_author

#include <bits/stdc++.h>
#define all(x) x.begin(),x.end()
#define mset(x, i) memset(x,i,sizeof(x))
#define elif else if
#define heap priority_queue
#define fi first
#define se second
#define pb push_back
#define ld long double
#define ll long long
#define ull unsigned long long
#define task "codejam"
using namespace std;

int typetest;
template<class T>
void read(T &x){
    register int c;
    T neg = 1;
    x = (T)0;
    while ((c = getchar()) <= 47 || c >= 58)
		if(c == '-') neg = -1;
    for (; (c > 47 && c < 58); c = getchar()){
        x = (x << 3) + (x << 1) + (T)(c - 48);
    }
	x *= neg;
}
inline void fastIOfileinput(){
	ios:: sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
//	freopen(task".INP", "r", stdin);
//	freopen(task".OUT", "w", stdout);
//	freopen(task".in", "r", stdin);
//	freopen(task".out", "w", stdout);
	typetest = 0;
}

const int N = 2e5 + 2;
int m, n, k;
vector<int> ker[N], kel[N];
int ltr[N], ltl[N];

void Enter(){
	read(n); read(m); read(k);
	while(m--){
		int a, b;
		read(a); read(b);
		ker[a].pb(b);
		ker[b].pb(a);
	}
	while(k--){
		int a, b;
		read(a); read(b);
		kel[a].pb(b);
		kel[b].pb(a);
	}
}

void BFS(int i, int lt[], vector<int> ke[]){
	++m;
	lt[i] = m;
	queue<int> open;
	open.push(i);
	while(open.size()){
		int c = open.front();
		open.pop();
		for(auto i : ke[c]){
			if((!lt[i]))
				open.push(i), lt[i] = m;
		}
	}
}

void solve(){
	m = 0;
	for(int i = 1; i <= n; ++i)
		if(ltr[i] == 0)
			BFS(i, ltr, ker);
	m = 0;
	for(int i = 1; i <= n; ++i)
		if(ltl[i] == 0)
			BFS(i, ltl, kel);
	map<int, map<int, int> > s;
	for(int i = 1; i <= n; ++i){
		++s[ltr[i]][ltl[i]];
//		cerr << ltr[i] << " " << ltl[i] << "\n";
	}
	for(int i = 1; i <= n; ++i){
		int& v = s[ltr[i]][ltl[i]];
		cout << v << " ";
	}
}

signed main(){
	fastIOfileinput();
	if(typetest){
		int t;
		cin >> t;
		int v = t;
		while(t--){
			Enter();
			cout << "Case #" << v - t << ": ";
			solve();
		}
	}
	else{
		Enter();
		solve();
	}
}


#include<iostream>
#include<iomanip>
#include<cmath>
#include<string>
#include<cstring>
#include<vector>
#include<list>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define mp make_pair
#define mt make_tuple
#define pqueue priority_queue
const int inf=1e9+7;
const ll mod=1e9+7;
const ll mod1=998244353;
const ll big=1e18;
const double PI=2*asin(1);

int main() {
  int D, T, S;
  cin>>D>>T>>S;
  if(S*T>=D) cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}

#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <map>
#include <unordered_set>
#include <queue>
#include <set>
#include <iomanip>
#include <stack>
#define int long long
#define ld long double
#define dbg(x) cout <<#x<<":"<<x<<'\n';
#define dbg2(x,y) cout<<#x<<":"<<x<<' '<<#y<<":"<<y<<'\n';
#define endl '\n'
#define inf 1000000010
#define eps 1e-8l
using namespace std;

const int N=2e5+5;
std::vector<int> g[N],c(N),gd(N),p(N),r(N);
vector<bool> vis(N);
int power(int x,int y){int res = 1;while(y>0){if(y&1)res = (res*x);x = (x*x);y = y>>1;}return res;}

//int n,m;
int n,a,b,da,db,md,nd,m;

int const dpn=2e5+5;
int dp[dpn];

bool comp(pair<int,int> l,pair<int,int> r){
	if(l.first!=r.first)
		return (l.first<r.first);
	return l.second>r.second;
}

int find(int i){
	if(p[i]!=i)
		return p[i]=find(p[i]);
	return i;
}

void join(int x,int y){
	int px=find(x);
	int py=find(y);
	if(r[px]>r[py])
		p[py]=px;
	else if(r[px]<r[py])
		p[px]=py;
	else
		p[py]=px,r[px]++;
}

int32_t main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	int t=1;
	//cin>>t;
	while(t--){
		//int n;
		//int n;
		int d,t,s;
		cin>>d>>t>>s;
		if((double)d/(double)s<=(double)t)
			cout<<"Yes\n";
		else
			cout<<"No\n";

	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std ;
int main()
{
    int w = 0 , k = 0 ;
    int score[2][10] = {0} ;
    for ( int i = 0 ; i < 2 ; i++ )
    {
        for ( int j = 0 ; j < 10 ; j++ )
        {
            cin >> score[i][j] ;
        }
        sort( score[i],score[i]+10 ) ;
        reverse( score[i],score[i]+10 ) ;
    }
    w = score[0][0] + score[0][1] + score[0][2] ;
    k = score[1][0] + score[1][1] + score[1][2] ;
    printf("%d %d\n",w ,k ) ;

    return 0 ;
}

#include <iostream>
#include <algorithm>
#include <bitset>
#include <cmath>
#include <deque>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>

#define Rep(i, b, e) for(int (i) = (b); (i) < (e); ++(i))
#define Repr(i, b, e) for(int (i) = (b) - 1; (i) >= (e); --(i))
#define Print(x) cout << (x) << endl
#define Min2(a, b) ((a) < (b)) ? (a) : (b)
#define Max2(a, b) ((a) > (b)) ? (a) : (b)

typedef long long ll;

using namespace std;

int N, K;
string C[10];
set<string> bt;

void dfs(string str, int k, int state){
    if(k == 0){
        bt.insert(str);
        return;
    }
    Rep(i, 0, N){
        if((1 << i) & state) continue;
        dfs(str + C[i], k - 1, state | (1 << i));
    }
}

int main(){
    while(true){
        cin >> N >> K;
        if(N == 0 && K == 0) break;
        Rep(i, 0, N) cin >> C[i];
        dfs("", K, 0);
        Print(bt.size());
        bt.clear();
    }
    return 0;
}


#include <bits/stdc++.h>

#define REP(i, n) for(int i=0;i<(int)(n);i++)
#define ALL(x) (x).begin(),(x).end()
const int INF = 1e9;

using namespace std;
int n;
int res = 0;
struct node {
    int id;
    int parent;
};

node v[100];
vector<tuple<int, int, int>> cost;
vector<int> path;

int find(node x){
    if(x.parent == -1){
        REP(i, path.size())
            v[path[i]].parent = x.id;
        path.clear();
        return x.id;
    }
    else{
        path.push_back(x.id);
        return find(v[x.parent]);
    }
}

void marge(node x, node y){
    int x_id = find(x);
    int y_id = find(y);
    if(x_id == y_id)
        return;
    else
        v[y_id].parent = x_id;
    return;
}

bool judge(node x, node y){
    vector<int> xpath, ypath;
    return find(x) == find(y);
}

int main() {
    cin >> n;
    REP(i, n) REP(j, n) {
        int tmp;
        cin >> tmp;
        if(tmp != -1)
            cost.push_back(make_tuple(tmp, i, j));
    }
    REP(i, n){
        v[i].id = i;
        v[i].parent = -1;
    }
    sort(ALL(cost));
    REP(i, cost.size()){
        node from = v[get<1>(cost[i])];
        node to = v[get<2>(cost[i])];
        if(judge(from, to)){
            continue;
        }
        res += get<0>(cost[i]);
        marge(from, to);
    }

    cout << res << endl;
    return 0;
}


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

#define REP(i, a, b) for(int i = (a); i <= (b); i++)
#define PER(i, a, b) for(int i = (a); i >= (b); i--)
#define rep(i, a, b) for(int i = (a); i < (b); i++)
#define all(S) (S).begin(), (S).end()
#define pb push_back
#define mk make_pair
#define S second
#define F first
typedef long long ll;
typedef long double lf;
typedef pair<int, int> ii;
const int MAX = 1e5+5;
char s[MAX];

int main(int argc, char ** argv) {
	scanf(" %s", s);
	int sz = strlen(s);
	rep(i, 0, sz) {
	    if(i >= 1 && s[i] == s[i-1]) printf("%d %d\n", i, i+1), exit(0);
	    if(i >= 2 && s[i] == s[i-2]) printf("%d %d\n", i-1, i+1), exit(0);
	}
	puts("-1 -1");
	return 0;
}

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

typedef long long ll;

int main(){
	ll n,a,b,c,d,e;
	cin >> n >> a >> b >> c >> d >> e;
	cout << (n-1)/min({a,b,c,d,e})+5 << endl;

	return 0;
}


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

using namespace std;

int main(){

    vector<int> W(10),K(10);

    for(int i=0;i<10;i++) scanf("%d",&W[i]);
    for(int i=0;i<10;i++) scanf("%d",&K[i]);

    sort(W.begin(),W.end());
    sort(K.begin(),K.end());

    printf("%d %d\n",W[7]+W[8]+W[9],K[7]+K[8]+K[9]);

    return 0;
}

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

int main() {
	int sum[2] = {0}, num[10] = { 0 }, i, j;
	for (j = 0; j < 2; j++) {
		for (i = 0; i < 10; i++) {
			cin >> num[i];
		}
		sort(num, num + 10);
		sum[j] = num[7] + num[8] + num[9];
	}
	cout << sum[0] << " " << sum[1] << endl;
	return 0;
}


// clang-format off
#include <bits/stdc++.h>
#define int long long
#define main signed main()
#define loop(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) loop(i, 0, n)
#define forever for (;;)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define prec(n) fixed << setprecision(n)
template<typename A> using V = std::vector<A>;
template<typename A> using F = std::function<A>;
template<typename A, typename B> using P = std::pair<A, B>;
using pii = P<int, int>;
using vi = V<int>;
using vd = V<double>;
using vs = V<std::string>;
using vpii = V<pii>;
using vvi = V<vi>;
using vvpii = V<vpii>;
constexpr int INF = sizeof(int) == sizeof(long long) ? 1000000000000000000LL : 1000000000;
constexpr int MOD = 1000000007;
constexpr double PI = 3.14159265358979;
template<typename A, typename B> bool cmin(A &a, const B &b) { return a > b ? (a = b, true) : false; }
template<typename A, typename B> bool cmax(A &a, const B &b) { return a < b ? (a = b, true) : false; }
constexpr bool odd(const int n) { return n & 1; }
constexpr bool even(const int n) { return ~n & 1; }
template<typename T> std::istream &operator>>(std::istream &is, std::vector<T> &v) { for (T &x : v) is >> x; return is; }
template<typename A, typename B> std::istream &operator>>(std::istream &is, std::pair<A, B> &p) { is >> p.first; is >> p.second; return is; }
using namespace std;
// clang-format on

main {
  vi v(5);
  char gomi;
  while (cin >> v[0] >> gomi >> v[1] >> gomi >> v[2] >> gomi >> v[3] >> gomi >> v[4]) {
    sort(all(v));
    if (v[0] == v[3] || v[1] == v[4]) {
      cout << "four card" << endl;
      continue;
    }
    if ((v[0] == v[1] && v[2] == v[4]) || (v[0] == v[2] && v[3] == v[4])) {
      cout << "full house" << endl;
      continue;
    }
    if (v[4] - v[0] == 4 || (v[0] == 1 && v[1] == 10 && v[4] - v[1] == 3)) {
      cout << "straight" << endl;
      continue;
    }
    if (v[0] == v[2] || v[1] == v[3] || v[2] == v[4]) {
      cout << "three card" << endl;
      continue;
    }
    if ((v[0] == v[1] && (v[2] == v[3] || v[3] == v[4])) || (v[1] == v[2] && v[3] == v[4])) {
      cout << "two pair" << endl;
      continue;
    }
    if (v[0] == v[1] || v[1] == v[2] || v[2] == v[3] || v[3] == v[4]) {
      cout << "one pair" << endl;
      continue;
    }
    cout << "null" << endl;
  }
}

#include <iostream>
using namespace std;
char judge(int, int, int);

int main() {
	int n, pm, pe, pj;
	while (true) {
		cin >> n;
		if (n == 0) break;

		for (int i = 0;i < n;i++) {
			cin >> pm >> pe >> pj;
			cout << judge(pm, pe, pj) << endl;
		}
	}
}

char judge(int math, int eng, int jap) {
	float twoave = (math + eng) / 2;
	float ave = (math + eng + jap) / 3;
	if (math == 100 || eng == 100 || jap == 100) {
		return 'A';
	} else if (twoave >= 90) {
		return 'A';
	} else if (ave >= 80) {
		return 'A';
	} else if (ave >= 70) {
		return 'B';
	} else if (ave >= 50 && (math >= 80 || eng >= 80)) {
		return 'B';
	} else {
		return 'C';
	}
}


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

int main()
{
	int N;
	long long Y;
	cin >> N >> Y;
	int a, b , c;
	a = 0;
	while (a <= Y / 10000)
	{
		b = 0;
		while (10000*a + 5000 * b <= Y)
		{
			c = N - a - b;
			if (10000*a + 5000*b + 1000*c == Y)
			{	cout << a << " " << b << " " << c << endl;
				return 0;
			}
			b++;
		}
		a++;
	}
	cout << "-1 -1 -1" << endl;
	return 0;
}

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

int main() {
  ll n;
  cin >> n;
  vector<ll> a(5);
  ll minimum=1e18;
  rep(i,5){
    cin >> a[i];
    minimum = min(minimum,a[i]);
  }

  if(n <= minimum){
    cout << 5 << endl;
  }else{
    ll times = ceil((n-minimum)*1.0/minimum);
    cout << times + 5 << endl;
  }

  return(0);
}


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

using ll = long long;
using Vi = vector<int>;
using Vl = vector<ll>;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

constexpr int I_INF = numeric_limits<int>::max();
constexpr ll L_INF = numeric_limits<ll>::max();

//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

void solve() {
    ll N;
    cin >> N;

    cout << 0 << endl;

    string r0;
    cin >> r0;

    if (r0 == "Vacant") {
        return;
    }

    string r;
    int left = -1, right = N;
    while (right - left > 1) {
        int mid = (left + right) >> 1;
        cout << mid << endl;
        cin >> r;
        if (r == "Vacant") {
            return;
        }

        if (mid & 1) {
            if (r == r0) {
                right = mid;
            }
            else {
                left = mid;
            }
        }
        else {
            if (r == r0) {
                left = mid;
            }
            else {
                right = mid;
            }
        }
    }

    int cur = left + 1;
    while (true) {
        cout << cur << endl;
        cin >> r;
        if (r == "Vacant") break;
        ++cur;
    }
}

//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

int main() {
#ifdef FASTIO
    cin.tie(0), cout.tie(0);
    ios::sync_with_stdio(false);
#endif
#ifdef FILEINPUT
    ifstream ifs("./in_out/input.txt");
    cin.rdbuf(ifs.rdbuf());
#endif
#ifdef FILEOUTPUT
    ofstream ofs("./in_out/output.txt");
    cout.rdbuf(ofs.rdbuf());
#endif
    solve();
    cout << flush;
    return 0;
}


#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 repr(i, a, b) for (int i = a; i < b; i++)
#define each(i, mp)   for (auto &i : mp)

const int INF = 1001001001;

int main()
{
  int a;
  cin >> a;
  ll ans = 0;

  rep(i, 3) ans += pow(a, i + 1);
  cout << ans << endl;

  return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define ALL(a) (a).begin(),(a).end()
#define rALL(a) (a).rbegin(),(a).rend()
typedef pair<int, int> Pint;
typedef pair<int64_t, int64_t> Pll;

int main() {
    int N;
    cin >> N;
    cout << (N - 2) * 180 << endl;
}


#include<iostream>
using namespace std;

int main(){
	int m, d, ans, month, i, total = 0;
	while(1){
		cin >> m >> d;
		if (m == 0) break;
		for(i = 1; i < m; i ++){
			if(i==1||i==3||i==5||i==7||i==8||i==10||i==12){
				total += 31;
			}
			else if(i == 2){
				total += 29;
			}
			else{
				total += 30;
			}
		}
		total += d;

		ans = total % 7;

		switch (ans){
		case 1:cout << "Thursday" << endl;
			break;
		case 2:cout << "Friday" << endl;
			break;
		case 3:cout << "Saturday" << endl;
			break;
		case 4:cout << "Sunday" << endl;
			break;
		case 5:cout << "Monday" << endl;
			break;
		case 6:cout << "Tuesday" << endl;
			break;
		case 0:cout << "Wednesday" << endl;
			break;
		}

		ans = 0, total = 0;
	}

	return 0;
}

// clang-format off
#include <bits/stdc++.h>
#define int long long
#define main signed main()
// #define main int main()
#define loop(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) loop(i, 0, n)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define prec(n) fixed << setprecision(n)
#define stlice(from, to) substr(from, (to) - (from) + 1)
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
using namespace std;
using pii = pair<int, int>;
using vi = vector<int>;
using vd = vector<double>;
using vc = vector<char>;
using vb = vector<bool>;
using vs = vector<string>;
using vpii = vector<pii>;
using vvi = vector<vi>;
using vvb = vector<vb>;
using vvpii = vector<vpii>;
template<typename A> using fn = function<A>;
constexpr int INF = sizeof(int) == sizeof(long long) ? 1000000000000000000LL : 1000000000;
constexpr int MOD = 1000000007;
constexpr double PI = acos(-1);
template<typename A, typename B> bool cmin(A &a, const B &b) { return a > b ? (a = b, true) : false; }
template<typename A, typename B> bool cmax(A &a, const B &b) { return a < b ? (a = b, true) : false; }
constexpr bool odd(const int &n) { return n & 1; }
constexpr bool even(const int &n) { return !odd(n); }
template<typename V> constexpr typename V::value_type sum(const V &v) { return accumulate(all(v), 0); }
void solve();
main { solve(); return 0; }
// clang-format on

constexpr int zeller(int y, int m, const int &d) {
  if (m == 1 || m == 2) y--, m += 12;
  int k = y % 100, j = y / 100;
  return (d + 13 * (m + 1) / 5 + k + k / 4 + j / 4 + 5 * j + 6) % 7;
}

void solve() {
  int m, d;
  string t[] = {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"};
  while (cin >> m >> d, m) cout << t[zeller(2004, m, d)] << endl;
}


#include <bits/stdc++.h>
#define rep(i, n) for(ll i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
const double PI=acos(-1);

template<typename T>
istream& operator>> (istream& is, vector<T> &vec){
    for(T& x: vec) is >> x;
    return is;
}

vector<vector<pair<ll,ll>>> a(15);
vector<ll> l(15, -1);

ll count(ll x, ll n){
    for(auto j : a[x]){
        if(l[j.first-1] != -1 && l[j.first-1] != j.second){
            //cout << "hoge";
            return -1;
        }
        l[j.first-1] = j.second;
    }
    ll ans = 0;
    rep(i, n) if(l[i] == 1) ans++;
    return ans;
}

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

    rep(i, n){
        ll b; cin >> b;
        rep(j, b){
            ll x, y; cin >> x >> y;
            a[i].emplace_back(x, y);
        }
    }
    ll ans = 0;
    for(ll i = 0; i < pow(2, n); ++i){
        ll tmp = 0;
        l.assign(15, -1);
        //cout << i << " " << ans << ": ";
        rep(j, n) l[j] = (i & (1 << j)) ? 1 : 0;
        rep(j, n){
            if(!(i & (1 << j))) continue;
            tmp = count(j, n);
            if(tmp == -1) break;
        }
        ans = max(ans, tmp);
        //cout << endl;
        //for(auto x : l) cout << x << " "; cout << endl;
    }
    cout << ans << endl;
    return 0;
}

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

int mypow(int x, int y);
vector<int> my_bit(int n, int keta);

int main(){
    map<int, vector<pair<int, int>>> shogen;
    int N, A, x, y, n, sum_;
    int ans = 0;
    pair<int, int> p;

    //インプット
    std::cin >> N;
    vector<int> pattern(N);

    for(int i = 0; i < N; i++){
        //この時点で人名は-1されていく
        std::cin >> A;
        shogen[i] = {};

        for(int j = 0; j < A; j++){
            std::cin >> x >> y;
            p = std::make_pair(x - 1, y);

            if(shogen.count(i)){
                shogen[i].push_back(p);
            }
        }
    }
    //インプット終了

    // std::cout << N;

    std::map<int, vector<pair<int, int>>>::iterator iter;
    // std::cout << shogen.size() << "\n";
    // for(int i = 0 ; shogen.size(); i++){
    //     std::cout << iter->first << "\n";
    //     for(int j = 0; j < iter->second.size(); j++){
    //         std::cout << iter->second[j].first << " " << iter->second[j].first << "\n";
    //     }
    //     iter++;
    // }

    for(int i = 0; i < mypow(2, N); i++){
        pattern = my_bit(i, N);
        iter = shogen.begin();
        for(int j = 0; j < N; j++){
            //全員の証言を見ていく
            n = iter->second.size();
            for(int k = 0; k < n; k++){
                //証言を順番に見ていく
                if(iter->second[k].second != pattern[iter->second[k].first]){
                    //ここに入ると嘘つき
                    if(pattern[j] == 1){
                        //なのにいい人だとおかしいのでそのパターンはなし。
                        goto ptn_end;
                    }
                }
            }
            iter++;
        }
        //やり終えたら次のパタンに行く前に集計、いい人が保持値より多ければ答えを更新
        sum_ = std::accumulate(pattern.begin(), pattern.end(),0);
        if(sum_ > ans){
            ans = sum_;
        }

        ptn_end:
        ;
    }
    std::cout << ans;

}

vector<int> my_bit(int n, int keta){
    int n_loop = 0;//桁数
    int bit_buff;
    double d_n = (double)n;
    //最大桁を算出
    while(d_n >= 1.0){
        n_loop++;
        d_n = d_n/2.0;
    }

    vector<int> ans(n_loop);

    //割ってこう
    for(int i =0; i < n_loop; i++){
        bit_buff = mypow(2, (n_loop - 1 -i));
        if(n >= bit_buff){
            ans[i] = 1;
            n = n - bit_buff;
        }
    }

    ans.insert(ans.begin(), keta - ans.size(), 0);
    return ans;
}

int mypow(int x, int y){
    int ans = 1;
    for(int i = 0; i < y; i++){
        ans = ans * x;
    }
    return ans;
}


#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define per(i,a,b) for(int i=(a);i>=(b);i--)
#define REP(i,n) for(int i=0;i<(n);i++)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
using namespace std;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef long long ll;

template<class T> void read(T &x){
	int f=0; x=0; char ch=getchar();
	for(;!isdigit(ch);ch=getchar()) f|=(ch=='-');
	for(;isdigit(ch);ch=getchar()) x=x*10+ch-'0';
	if(f) x=-x;
}

const int N=305,mod=998244353;
int f[N][N][N<<1],g[N][N<<1],h[N][N<<1];
int a[N],b[N],n,m=1,K;
char s[N];

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

int main(){
	scanf("%s",s+1),read(K);
	n=strlen(s+1),K=min(K,n);
	for(int i=1;i<=n+1;i++,m++){
		for(;i<=n&&s[i]!='0';i++,a[m]++);
		b[m]=b[m-1]+a[m];
	}
	m--;
	f[0][0][0]=1;
	rep(i,1,m){
		memset(g,0,sizeof g);
		memset(h,0,sizeof h);
		rep(j,b[i-1],b[m]){
			rep(k,0,K*2){
				if(f[i-1][j][k]){
					if(j+a[i]<=b[m]){
						add(g[j+a[i]][k],f[i-1][j][k]);
					}
					if(a[i]){
						int t=max(0,j+a[i]-1-b[m]);
						add(h[j+a[i]-1-t][k+1+t],f[i-1][j][k]);
						if(j) add(h[j-1][k+a[i]+1],mod-f[i-1][j][k]);
					}
				}
			}
		}
		rep(j,b[i-1],b[m]-1){
			rep(k,0,K*2){
				add(g[j+1][k+1],g[j][k]);
			}
		}
		per(j,b[m],b[i-1]+1){
			rep(k,0,K*2){
				add(h[j-1][k+1],h[j][k]);
			}
		}
		rep(j,b[i],b[m]){
			rep(k,0,K*2){
				add(f[i][j][k],g[j][k]);
				add(f[i][j][k],h[j][k]);
			}
		}
	}
	int ans=0;
	rep(i,0,K*2){
		add(ans,f[m][b[m]][i]);
	}
	cout<<ans<<endl;
	return 0;
}

#include<iostream>
#define LL long long
#define  INF 0x7fffffff;
using namespace std;
const int maxn=500010;
int a[maxn];
int L[maxn/2+2],R[maxn/2+2];
int n;
LL merge(int left,int mid ,int right){
	int n1=mid-left;
	int n2=right-mid;
	for(int i=0;i<n1;i++)L[i]=a[left+i];
	for(int i=0;i<n2;i++)R[i]=a[mid+i];
	int i=0,j=0;
	L[n1]=R[n2]=INF;
	LL s=0;
	for(int k=left;k<right;k++){
		if(L[i]<=R[j])
			a[k]=L[i++];
		else{
			a[k]=R[j++];
			s+=n1-i;
		}
	}
	return s;
}
LL mergesort(int left,int right ){//[left,right)
	LL c1,c2,c3;
	if(left+1<right){//避免死循?
		int mid=(left+right)/2;
		c1=mergesort(left,mid);
		c2=mergesort(mid,right);
		c3=merge(left,mid,right);
		return c1+c2+c3;
	}
	else
		return 0;
}
int main(){
	cin>>n;
	for(int i=0;i<n;i++)cin>>a[i];
	cout<<mergesort(0,n)<<endl;
	return 0;
}


#include <bits/stdc++.h>

#define N_MAX 200002
#define Q_MAX 200002

#define ll long long

using namespace std;

const ll INF = 1000000000000000;

int n, q, a, b;

int pos[Q_MAX];

struct SGTNode
{
    ll mindp;
    ll min1, min2;
    ll lazy;
};

SGTNode dp[N_MAX * 3];

void split (int node)
{
    int lson = (node << 1), rson = (lson | 1);
    dp[lson].mindp += dp[node].lazy;
    dp[lson].min1 += dp[node].lazy;
    dp[lson].min2 += dp[node].lazy;
    dp[lson].lazy += dp[node].lazy;
    dp[rson].mindp += dp[node].lazy;
    dp[rson].min1 += dp[node].lazy;
    dp[rson].min2 += dp[node].lazy;
    dp[rson].lazy += dp[node].lazy;
    dp[node].lazy = 0;
}

SGTNode join (SGTNode a, SGTNode b)
{
    SGTNode ans;
    ans.mindp = min(a.mindp, b.mindp);
    ans.min1 = min(a.min1, b.min1);
    ans.min2 = min(a.min2, b.min2);
    ans.lazy = 0;
    return ans;
}

void update (int node, int l, int r, int ul, int ur, ll val)
{
    if(ul <= l && r <= ur)
    {
        dp[node].mindp += val;
        dp[node].min1 += val;
        dp[node].min2 += val;
        dp[node].lazy += val;
        return;
    }
    int mid = (l + r) / 2, lson = (node << 1), rson = (lson | 1);
    split(node);
    if(ul <= mid)
        update(lson, l, mid, ul, ur, val);
    if(mid + 1 <= ur)
        update(rson, mid + 1, r, ul, ur, val);
    dp[node] = join(dp[lson], dp[rson]);
}

void update1 (int node, int l, int r, int pos, ll val)
{
    if(l == r)
    {
        dp[node].mindp = val;
        dp[node].min1 = val - pos;
        dp[node].min2 = val + pos;
        return;
    }
    int mid = (l + r) / 2, lson = (node << 1), rson = (lson | 1);
    split(node);
    if(pos <= mid)
        update1(lson, l, mid, pos, val);
    if(mid + 1 <= pos)
        update1(rson, mid + 1, r, pos, val);
    dp[node] = join(dp[lson], dp[rson]);
}

SGTNode query (int node, int l, int r, int ql, int qr)
{
    if(ql <= l && r <= qr)
        return dp[node];
    int mid = (l + r) / 2, lson = (node << 1), rson = (lson | 1);
    split(node);
    if(ql <= mid && mid + 1 <= qr)
        return join(query(lson, l, mid, ql, qr), query(rson, mid + 1, r, ql, qr));
    else if(ql <= mid)
        return query(lson, l, mid, ql, qr);
    else
        return query(rson, mid + 1, r, ql, qr);
}

int main()
{
    cin >> n >> q >> a >> b;
    for(int i = 1; i <= q; i++)
        cin >> pos[i];
    pos[0] = a;
    for(int i = 1; i < N_MAX * 3; i++)
        dp[i].min1 = dp[i].min2 = dp[i].mindp = INF;
    update1(1, 1, n, b, 0);
    for(int i = 1; i <= q; i++)
    {
        ll diff = abs(pos[i] - pos[i - 1]);
        ll mi = min(query(1, 1, n, pos[i], pos[i]).mindp + diff, min(query(1, 1, n, 1, pos[i]).min1 + pos[i], query(1, 1, n, pos[i], n).min2 - pos[i]));
        if(pos[i - 1] - 1 >= 1)
            update(1, 1, n, 1, pos[i - 1] - 1, diff);
        if(pos[i - 1] + 1 <= n)
            update(1, 1, n, pos[i - 1] + 1, n, diff);
        update1(1, 1, n, pos[i - 1], mi);
        update1(1, 1, n, pos[i], INF);
    }
    cout << dp[1].mindp << "\n";
    return 0;
}

#include <bits/stdc++.h>
#define de(x) cout << #x << '=' << x << ", "
#define dd cout << '\n';
#define XinAi ios::sync_with_stdio(0), cin.tie(0);
#define rep(i,j,k) for (int i=j; i<=k; i++)
#define S second
#define F first
#define int long long
using namespace std;
typedef pair<int,int> pii;
const int N = 2e5+10;
/*
dp[i][j] = dp[i-1][j] + |x[i]-x[i-1]|
dp[i][x[i-1]] = min(dp[i][x[i-1]], min(dp[i-1][k] + |k-x[i]|, k=1~n))

owo = dp[i-1][k] + |k-x[i]|, k=1~n
k=1~x[i]: owo = dp[i-1][k] + x[i] - k;
k=x[i]~n: owo = dp[i-1][k] + k - x[i];

sta[j], dp[i][j]-j
stb[j], dp[i][j]+j

dp[b]=0
*/
int n, q, x[N], b;
struct ST
{
	int st[N<<2], lz[N<<2]; //lz: not cover to subnodes, st: merge subnode + lazy
	inline void init()
	{
		memset(st,0x3f,sizeof(st));
	}
	inline void setto (int u, int l, int r, int p, int v)
	{
		if (r<p || p<l) return;
		else if (l==p && p==r) st[u]=v;
		else
		{
			int m = (l+r)/2;
			setto(u<<1,l,m,p,v-lz[u]);
			setto(u<<1|1,m+1,r,p,v-lz[u]);
			st[u] = min(st[u<<1], st[u<<1|1])+lz[u];
		}
	}
	inline void add (int u, int l, int r, int ql, int qr, int v)
	{
		if (r<ql || qr<l) return;
		else if (ql<=l && r<=qr) st[u]+=v,lz[u]+=v;
		else
		{
			int m = (l+r)/2;
			add(u<<1,l,m,ql,qr,v);
			add(u<<1|1,m+1,r,ql,qr,v);
			st[u] = min(st[u<<1], st[u<<1|1])+lz[u];
		}
	}
	inline int query (int u, int l, int r, int ql, int qr)
	{
		if (r<ql || qr<l) return 1e18;
		else if (ql<=l && r<=qr) return st[u];
		else
		{
			int m = (l+r)/2;
			return min(query(u<<1,l,m,ql,qr), query(u<<1|1,m+1,r,ql,qr)) + lz[u];
		}
	}
} sta, stb;

void test ()
{
	int n, t, l, r, a;
	cin >> n;
	while (cin >> t >> l >> r)
	{
		if (t==0) sta.setto(1,1,n,l,r);
		if (t==1) cin >> a, sta.add(1,1,n,l,r,a);
		if (t==2) cout << sta.query(1,1,n,l,r) << '\n';
	}
}
void print ()
{
	int dp, dp_min_i, dp_add_i;
	rep(i,1,n)
	{
		dp = sta.query(1,1,n,i,i)+i;
		dp_min_i = sta.query(1,1,n,i,i);
		dp_add_i = stb.query(1,1,n,i,i);
		de(i), de(dp), de(dp_min_i), de(dp_add_i), dd;
	}
	dd
}

signed main()
{
	XinAi
	cin >> n >> q >> x[0] >> b;
	rep(i,1,q) cin >> x[i];
	sta.init(), stb.init();
	sta.setto(1,1,n,b,-b), stb.setto(1,1,n,b,b);

	//print();

	rep(i,1,q)
	{
		int owo = min(sta.query(1,1,n,1,x[i])+x[i], stb.query(1,1,n,x[i],n)-x[i]);
		sta.add(1,1,n,1,n,abs(x[i]-x[i-1]));
		stb.add(1,1,n,1,n,abs(x[i]-x[i-1]));
		int qwq = sta.query(1,1,n,x[i-1],x[i-1])+x[i-1];
		if (owo < qwq)
		{
			sta.setto(1,1,n,x[i-1],owo-x[i-1]);
			stb.setto(1,1,n,x[i-1],owo+x[i-1]);
		}
		//de(i), de(owo), de(qwq), de(owo-x[i-1]), de(owo+x[i-1]), dd print();
	}
	int res=9e18;
	rep(i,1,n) res = min(res, sta.query(1,1,n,i,i)+i);
	cout << res << '\n';
}


#include <iostream>

using namespace std;

int hi[101];

int main() {
	int a, b;
	cin >> a >> b;
	while (a != 0 || b != 0) {
	    int no = 0, yes = 0;
	    for (int i = 1; i <= 101; i++) hi[i] = 0;
	    for (int i = 0; i < a; i++) {
	        int x; cin >> x;
	        for (int o = 0; o < x; o++) {
	            int yay; cin >> yay;
	            hi[yay]++;
	        }
	    }
	    for (int i = 101; i > 0; i--) {
	        if (yes <= hi[i] && hi[i] >= b) {
	            no = i;
	            yes = hi[i];
	        }
	    }
	    cout << no << endl;
	    cin >> a >> b;
	}
}

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

ll solve() {
    ll N, Q, t, a;
    cin >> N >> Q;
    atcoder::fenwick_tree<ll> ft(N);
    for ( int i = 0; i < N; i++ ) {
        cin >> a;
        ft.add(i, a);
    }
    vector<ll> ans;
    for ( int q = 0; q < Q; q++ ) {
        cin >> t;
        if ( t == 0 ) {
            ll p, x;
            cin >> p >> x;
            ft.add(p,x);
        } else {
            ll l, r;
            cin >> l >> r;
            ans.push_back(ft.sum(l,r));
        }
    }
    for ( auto a : ans ) {
        cout << a << "\n";
    }
    return 0;
}

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


#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
#define chmax(x,y) x = max(x,y);
#define chmin(x,y) x = min(x,y);
const int di[] = {-1, 0, 1, 0};
const int dj[] = {0, -1, 0, 1};
const int INF = 1001001001;

int main() {
    int n;
    cin >> n;
    vector<ll> a(n);
    rep(i,n) cin >> a[i];
    int c = 0;
    rep(i,n) {
        if (a[i] < 0) c ^= 1;
    }
    ll ans = 0;
    rep(i,n) ans += abs(a[i]);
    if (c) {
        ll mn = 1e10;
        rep(i,n) {
            mn = min(mn, abs(a[i]));
        }
        ans -= mn*2;
    }
    cout << ans << endl;
    return 0;
}

#include <algorithm>
#include <iostream>
#include <vector>
#include <math.h>
#include <set>
#include <map>
#include <string>
#include <stack>
#include <queue>
#include <iomanip>
#include <numeric>
#include <tuple>
#include <bitset>
#include <complex>
#include <unistd.h>
#include <cassert>
#include <cctype>
#include <random>
#include <time.h>
#define _USE_MATH_DEFINES
#define _GLIBCXX_DEBUG
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> plglg;
typedef pair<double, ll> pdlg;
typedef tuple<int, int, int> tiii;
typedef tuple<ll, ll, ll> tlglglg;
typedef tuple<double, double, double> tddd;
typedef complex<double> xy_t;
typedef vector<ll> vll;
typedef vector< vector<ll> > matrix;
#define REP(i, x, y) for(ll i = (ll)x; i < (ll)y; i++)
#define DREP(i, x, y, d) for(ll i = (ll)x; i < (ll)y; i += (ll)d)
#define PER(i, x, y) for(ll i = (ll)x; i > (ll)y; i--)
#define DPER(i, x, y, d) for(ll i = (ll)x; i > (ll)y; i -= (ll)d)
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
double pi = 3.141592653589793;
ll mod = 998244353;
int intmax = 2147483647;
int intmin = -2147483648;
ll llmax = 9223372036854775807;
ll llmin = -9223372036854775807;
int iinf = intmax / 8;
ll inf = llmax / 8;
double eps = 1e-12;

ll modadd(ll x, ll y) {
    return ((x + y) % mod + mod) % mod;
}

ll modminus(ll x, ll y) {
    return (x - y + mod) % mod;
}

ll multiply(ll x, ll y) {
    return (x % mod) * (y % mod) % mod;
}

ll modpower(ll x, ll y) {
    if (y == 0) {
        return 1;
    } else if (y == 1) {
        return x % mod;
    } else if (y % 2 == 0) {
        ll p = modpower(x, y / 2);
        return p * p % mod;
    } else {
        ll p = modpower (x, y / 2);
        return (p * p) % mod * (x % mod) % mod;
    }
}

ll dp[310][90010];
ll dpb[310][90010];

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N;
    cin >> N;
    ll a[N];
    ll sum = 0;
    REP(i, 0, N) {
        cin >> a[i];
        sum += a[i];
    }
    dp[0][0] = 1;
    dpb[0][0] = 1;
    REP(i, 0, N) {
        REP(j, 0, 90000) {
            dp[i + 1][j] = modadd(dp[i + 1][j], multiply(dp[i][j], 2));
            dpb[i + 1][j] = modadd(dpb[i + 1][j], dpb[i][j]);
            if (j + a[i] <= 90000) {
                dp[i + 1][j + a[i]] = modadd(dp[i + 1][j + a[i]], dp[i][j]);
                dpb[i + 1][j + a[i]] = modadd(dpb[i + 1][j + a[i]], dpb[i][j]);
            }
        }
    }
    ll dis = 0;
    ll disa = 0;
    REP(i, (sum + 1) / 2, sum) {
        dis = modadd(dis, dp[N][i]);
    }
    dis = multiply(dis, 3);
    if (sum % 2 == 0) {
        disa = dpb[N][sum / 2];
    }
    disa = multiply(disa, 3);
    ll base = modadd(modpower(3, N), -3);
    ll ans = modadd(base, - modadd(dis, - disa));
    cout << ans << endl;
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair
#define pl pair<ll, ll>
#define vl vector<ll>
#define fastIO ios_base::sync_with_stdio(false);cin.tie(NULL);

int main()
{
    ll n;cin>>n;
    ll a[n];
    for(ll i=0;i<n;i++)
    cin>>a[i];
    map<ll,ll>m;ll cnt=0;
    for(ll i=0;i<n;i++)
    {
        if(m[a[i]]==0)
        {
            cnt+=1;m[a[i]]+=1;
        }
        else if(m[a[i]]>0)
        {
            cnt-=1;m[a[i]]-=1;
        }
    }
    cout<<cnt<<"\n";
}

#include <iostream>
#include <math.h>
#include <algorithm>
#include <string>
#include <map>
#include <vector>
#include <cmath>

using namespace std;

void c_write_and_erase(void) {
	int n;
	cin >> n;
	map<long long, int>a;
	long long ain;
	for (int i = 0; i < n; i++) {
		cin >> ain;
		if (a.count(ain)) {
			a[ain]++;
		}
		else {
			a.insert(make_pair(ain, 1));
		}
	}

	int cnt = 0;
	map<long long, int>::iterator aptr = a.begin();
	for (aptr; aptr!=a.end(); aptr++) {
		if ((aptr->second) % 2 == 1) cnt++;
	}

	cout << cnt << endl;
}

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


#include <bits/stdc++.h>
// iostream is too mainstream
#include <cstdio>
// bitch please
#include <iostream>
#include <algorithm>
#include <cstdlib>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <cmath>
#include <iomanip>
#include <time.h>
#define dibs reserve
#define OVER9000 1234567890
#define ALL_THE(CAKE,LIE) for(auto LIE =CAKE.begin(); LIE != CAKE.end(); LIE++)
#define tisic 47
#define soclose 1e-8
#define chocolate win
// so much chocolate
#define patkan 9
#define ff first
#define ss second
#define abs(x) (((x) < 0)?-(x):(x))
#define uint unsigned int
#define dbl long double
#define pi 3.14159265358979323846
using namespace std;
// mylittledoge

using cat = long long;

#ifdef DONLINE_JUDGE
	// palindromic tree is better than splay tree!
	#define lld I64d
#endif

cat gcd(cat x, cat y) {
	if(x > y) swap(x, y);
	return (x == 0) ? y : gcd(y%x, x);
}

cat lcm(cat x, cat y) {
	return x / gcd(x, y) * y;
}

int main() {
	cin.sync_with_stdio(0);
	cin.tie(0);
	cout << fixed << setprecision(10);
	int N;
	cin >> N;
	vector< vector<cat> > A(N, vector<cat>(N, 1));
	vector<int> P;
	for(int p = 4; ; p++) {
		bool is_prime = true;
		for(int i = 2; i*i <= p; i++) is_prime &= (p%i != 0);
		if(!is_prime) continue;
		P.push_back(p);
		if((int)P.size() == N+10) break;
	}
	for(int i = 0; i < N; i += 2) for(int j = 0; j < N; j += 2) A[i][j] = P[i/2] * P[N/2+1+j/2];
	for(int i = 1; i < N; i += 2) for(int j = 1; j < N; j += 2) A[i][j] = 3 * A[i-1][j-1];
	for(int i = 0; i < N; i++) for(int j = 1-(i&1); j < N; j += 2) {
		if(i > 0) A[i][j] = lcm(A[i][j], A[i-1][j]);
		if(j > 0) A[i][j] = lcm(A[i][j], A[i][j-1]);
		if(i+1 < N) A[i][j] = lcm(A[i][j], A[i+1][j]);
		if(j+1 < N) A[i][j] = lcm(A[i][j], A[i][j+1]);
		if(j&1) A[i][j] *= 2;
		A[i][j]++;
	}
	for(int i = 0; i < N; i++) for(int j = 0; j < N; j++) cout << A[i][j] << ((j == N-1) ? "\n" : " ");
	return 0;
}

// look at my code
// my code is amazing

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
using vint = vector<int>;
using vvint = vector<vint>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vchar = vector<char>;
using vvchar = vector<vchar>;
using vp = vector<P>;
using vpp = vector<pair<P, P>>;
using vvp = vector<vp>;

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

P bounds = P(0, 0);
void rot(vp *up, vp *down, vp *left, vp *right)
{
    vector<vp *> vecs = {up, down, left, right};
    rep(i, 4)
    {
        vp *a = vecs[i];
        rep(j, (*a).size())
        {
            P now = (*a)[j];
            (*a)[j] = P(now.second, -now.first + bounds.first);
        }
    }
    swap(bounds.first, bounds.second);
    swap(*down, *left);
    swap(*down, *up);
    swap(*down, *right);
}

bool comp(P l, P r)
{
    return (l.first + l.second) < (r.first + r.second);
}

const ll INF = 1e10 + 5;

int main()
{
    int n;
    cin >> n;
    vp up, down, left, right;
    rep(i, n)
    {
        int x, y;
        char u;
        cin >> x >> y >> u;
        P p = P(x, y);
        if (p.first > bounds.first)
        {
            bounds = P(p.first, bounds.second);
        }
        if (p.second > bounds.second)
        {
            bounds = P(bounds.first, p.second);
        }
        if (u == 'U')
        {
            up.emplace_back(p);
        }
        else if (u == 'D')
        {
            down.emplace_back(p);
        }
        else if (u == 'R')
        {
            right.emplace_back(p);
        }
        else if (u == 'L')
        {
            left.emplace_back(p);
        }
    }

    ll ans = INF;
    rep(i, 4)
    {

        map<int, vp> m;
        for (P p : up)
        {
            int sum = p.first + p.second;
            m[sum].emplace_back(P(p.second, 0));
        }
        for (P p : right)
        {
            int sum = p.first + p.second;
            m[sum].emplace_back(P(p.second, 1));
        }
        for (auto x : m)
        {
            vp b = x.second;
            sort(b.begin(), b.end());
            rep(j, b.size() - 1)
            {
                if (!b[j].second && b[j + 1].second)
                {
                    // collision between up and right
                    // not b[j].second && !b[j].second because we sorted by Y coords
                    ll now = b[j + 1].first - b[j].first;
                    now *= 10;
                    ans = min(ans, now);
                    break;
                }
            }
        }

        map<int, vp> q;
        for (P p : up)
        {
            q[p.first].emplace_back(P(p.second, 0));
        }
        for (P p : down)
        {
            q[p.first].emplace_back(P(p.second, 1));
        }
        for (auto x : q)
        {
            vp b = x.second;
            sort(b.begin(), b.end());
            rep(j, b.size() - 1)
            {
                if (!b[j].second && b[j + 1].second)
                {
                    ll now = b[j + 1].first - b[j].first;
                    now *= 5;
                    ans = min(ans, now);
                    break;
                }
            }
        }

        rot(&up, &down, &left, &right);
    }

    if (ans == INF)
    {
        cout << "SAFE" << endl;
    }
    else
    {
        cout << ans << endl;
    }

    return 0;
}


#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <cmath>
#include <climits>
#include <iomanip>
#include <set>
#include <map>
using namespace std;
typedef long long ll;
int main(){
  ll n;
  cin >> n;
  string s = to_string(n);
  ll wa = 0;
  for(int i = 0;i < (int)s.size();i++){
    wa += s[i] - '0';
  }
  if(n % wa == 0)cout << "Yes" << endl;
  else cout << "No" << endl;
}

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

int main() {
  int N;
  cin >> N;
  int S = 0;
  int a = 1;

  for (int i =0; i < 9; i++) {
    int x;
    a *= 10;
    x = (N % a - N % (a/10)) / (a/10);
    S += x;
  }

  if (N % S == 0){
  	cout << "Yes";
  }
  else {
  	cout << "No";
  }

}


#include <cmath>
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <vector>
#include <map>
#include<cstdio>
#include<functional>
#include <bitset>
#include <iomanip>
#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 repr(i, n) for(int i = n; i >= 0; i--)
#define ll long long
using namespace std;
template <typename T> bool chmin(T &a, const T &b) { if (a > b) { a = b; return true; } return false; }
template <typename T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
const ll INF = 1000000000000000000;
const ll MOD = 1e9 + 7;

int gcd(int a, int b)
{
	if (a%b == 0)
	{
		return(b);
	}
	else
	{
		return(gcd(b, a%b));
	}
}

int lcm(int a, int b)
{
	return a * b / gcd(a, b);
}

int main()
{
	int n;
	cin >> n;
	vector<int> wl(n);
	vector<int> el(n);
	string s;
	cin >> s;
	rep(i, n) {
		if (i - 1 >= 0) {
			wl[i] = wl[i - 1];
			el[i] = el[i - 1];
		}
		if (s[i] == 'W') {
			wl[i]++;
		}
		else{
			el[i]++;
		}
	}
	int ans = 1000000000;
	rep(i, n) {
		int ec = 0;
		int wc = 0;
		if (i - 1 > 0) {
			wc = wl[i - 1];
		}
		ec = el[el.size() - 1] - el[i];
		ans = min(ans, ec + wc);
	}
	cout << ans << endl;
	//cout << fixed << setprecision(10) << ans << endl;
	system("pause");
}

#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()
{
    int n;
    cin >> n;
    string s;
    cin >> s;
    int east[n], west[n];
    rep(i, n) west[i] = 0;
    if (s[0] == 'W')
        west[0] = 1;
    else
        west[0] = 0;
    for (int i = 1; i < n; ++i)
    {
        if (s[i] == 'W')
            west[i] = west[i - 1] + 1;
        else
            west[i] = west[i - 1];
    }
    if (s[n - 1] == 'E')
        east[n - 1] = 1;
    else
        east[n - 1] = 0;
    for (int i = n - 2; i >= 0; --i)
    {
        if (s[i] == 'E')
            east[i] = east[i + 1] + 1;
        else
            east[i] = east[i + 1];
    }
    int cnt = n;
    rep(i, n)
    {
        if (east[i] + west[i] < cnt)
        {
            cnt = east[i] + west[i];
        }
    }
    cout << cnt - 1 << endl;
    return 0;
}


#include <iostream>
#include <algorithm>
#include <vector>
#include <stack>
#include <string>
#include <queue>
#include <cmath>
#include <numeric>
#include <list>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <climits>
#include <set>
#include <memory.h>
#include <memory>
#include <cstdio>
#include <cstdlib>
#include <cctype>
#include <map>
#include <cassert>
#define _USE_MATH_DEFINES
using namespace std;

typedef long long ll;
typedef pair<int, int> P;
typedef pair<int, P> PP;
typedef vector<int> vec;
typedef vector<vec> mat;
const int INF = 1 << 30;
const double EPS = 1e-9;

int nums[200];

int main(){
	int n, q;
	while(cin >> n >> q && (n || q)){
		fill(nums, nums + 200, 0);
		for(int i = 0; i < n; i++){
			int num, date;
			cin >> num;
			for(int j = 0; j < num; j++){
				cin >> date;
				nums[date]++;
			}
		}
		int t = -1;
		int id = 0;
		vector<int> res;
		for(int i = 0; i < 200; i++){
			if(nums[i] >= q){
				if(nums[i] > t){
					t = nums[i];
					id = i;
				}
			}
		}
		if(t == -1){
			cout << 0 << endl;
		}else{
			cout << id << endl;
		}
	}
	return 0;
}

#include <stdio.h>
#include <math.h>
#include <stdlib.h>

int main(){

	int N,Q,M,Date[101],i,l,k;

	while(0<=scanf("%d%d",&N,&Q)){
		for(i=0;i<101;i++){
			Date[i]=0;
		}

		if((N==0) && (Q==0)){
			break;
		}

		for(k=0;k<N;k++){
			scanf("%d",&M);
			if(M==0){
				continue;
			}else{
				for(i=0;i<M;i++){
					scanf("%d",&l);
					++Date[l];
				}
			}
		}
		l=0;
		i=0;
		for(k=0;k<100;k++){
			if(i<Date[k] && Date[k]>=Q){
				i=Date[k];
				l=k;
			}
		}

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

	return 0;
}


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

int main(){
  ll S;
  cin>>S;
  ll digit=0;
  ll d=S;
  while(d!=0){
    digit++;
    d/=10;
  }
  vector<ll> s(digit);
  rep(i,digit){
    s[i]=S%10;
    S/=10;
  }
  reverse(s.begin(),s.end());
  ll ans;
  ll cnt;
  ll cnt2;
  rep(i,digit-2){
    cnt=0;
    cnt2=0;
    cnt=s[i]*100+s[i+1]*10+s[i+2];
    cnt2=abs(753-cnt);
    if(i==0){
      ans=cnt2;
    }
    if(i>0){
      if(cnt2<ans){
        ans=cnt2;
      }
    }
  }
  cout<<ans<<endl;
}

#include <cstdio>
#include <algorithm>
#include <vector>
#include <utility>

using namespace std;

template <class RandomIt>
RandomIt partition_(RandomIt first, RandomIt last) {
    using T=typename RandomIt::value_type;
    T x=last[-1];
    RandomIt it=first-1;
    for (RandomIt it2=first; it2<last-1; ++it2)
        if (*it2 <= x) {
            ++it;
            swap(*it, *it2);
        }

    swap(*++it, last[-1]);
    return it;
}

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

    vector<int> A(n);
    for (size_t i=0; i<n; ++i)
        scanf("%d", &A[i]);

    vector<int>::iterator pivot=partition_(A.begin(), A.end());
    for (vector<int>::iterator it=A.begin(); it<pivot; ++it)
        printf("%d ", *it);

    printf("[%d] ", *pivot);

    for (vector<int>::iterator it=pivot+1; it<A.end(); ++it)
        printf("%d%c", *it, it<A.end()-1? ' ':'\n');

    return 0;
}


#include <iostream>
#include <vector>

using namespace std;

class Dice
{
  public:
    vector<int> diceNum;
    Dice(vector<int>& inputs);
    void toW();
    void toS();
    void ParallelRotation();
};

Dice::Dice(vector<int>& inputs)
{
  diceNum=inputs;
}

void Dice::toW()
{
  swap(diceNum[0],diceNum[3]);
  swap(diceNum[0],diceNum[5]);
  swap(diceNum[0],diceNum[2]);
}

void Dice::toS()
{
  swap(diceNum[0],diceNum[1]);
  swap(diceNum[0],diceNum[5]);
  swap(diceNum[0],diceNum[4]);
}

void Dice::ParallelRotation()
{
  swap(diceNum[1],diceNum[2]);
  swap(diceNum[2],diceNum[4]);
  swap(diceNum[4],diceNum[3]);
}

bool Judge(Dice& dice1,Dice& dice2)
{
  int count=0;
  for(int i=0;i<6;i++)
  {
    if(dice1.diceNum[i]==dice2.diceNum[i]) count++;
  }
  if(count==6)return true;
  else return false;

}

bool preJudge(Dice& dice1,Dice& dice2)
{
  int count=0;
  bool flag=false;
  while(1)
  {
    dice2.toS();
    for(int j=0;j<4;j++)
    {
      dice2.ParallelRotation();
      flag=Judge(dice1,dice2);
      if(flag==true) break;
    }
    if(flag==true) break;
    dice2.toW();
    for(int j=0;j<4;j++)
    {
      dice2.ParallelRotation();
      flag=Judge(dice1,dice2);
      if(flag==true) break;
    }
    count++;
    if(flag==true) break;
    if(count==3)break;
  }
  return flag;
}

int main(int argc,char* argv[])
{
  vector<int> inputs(6);
  int number;
  int count =0;
  cin >> number;
  bool flag=false;

  vector<Dice> Dices;
  for(int i=0;i<number;i++)
  {
    for(int j=0;j<6;j++)
    {
      cin >> inputs[j];
    }
    Dices.push_back(Dice(inputs));
  }
  for(int i=0;i<number-1;i++)
  {
    for(int j=i+1;j<number;j++)
    {
      flag = preJudge(Dices[i],Dices[j]);
      if(flag==true) break;
    }
    if(flag==true) break;
  }
  if(flag==true) cout << "No" << endl;
  else if(flag==false) cout << "Yes" << endl;
}


#include <iostream>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <cmath>
#include <string>
#include <cstring>
#include <sstream>
#include <iomanip>//小数精度 	cout << fixed << setprecision(5) << tmp << endl;
using namespace std;

#define ll long long
#define vvi vector< vector<int> >
#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(X)      (X).begin(),(X).end()
const ll int INF =1000000001;
int v,e,r;

struct edge {ll int from,to,cost; };

vector<edge> es(e);
vector<ll int> d(v);

bool find_negative_loop(){
	//memset(d,0,sizeof(d));
	fill(All(d),0);
	REP(i,v){
		REP(j,e){
			edge e = es[j];
			if(d[e.to] > d[e.from] + e.cost){
				d[e.to] = d[e.from] + e.cost;
				if(i==v-1) return true;
			}
		}
	}
	return false;
}

void SearchMinCost(int s){
	REP(i,v) d[i] = INF;
	d[s] = 0;
	while(true){
		bool update = false;
		REP(i,e){
			edge e = es[i];
			if(d[e.from]!=INF && d[e.to] > d[e.from] + e.cost ){
				d[e.to] = d[e.from] + e.cost;
				update = true;
			}
		}
		if(!update) break;
	}
}
int main(){
	cin >> v >> e >> r;
	es.resize(e);
	REP(i,e) {
		cin >> es[i].from >> es[i].to >> es[i].cost;
	}
	d.resize(v);
	SearchMinCost(r);

	//if(find_negative_loop()){
	//	cout <<"NEGATIVE CYCLE"<<endl;
	//}else{
		SearchMinCost(r);
		REP(i,v) {
			if(d[i]>=INF) cout << "INF" <<endl;
			else cout << d[i] <<endl;
		}
	//}
	return 0;
}

#include <bits/stdc++.h>
using namespace std;using ll=int_fast64_t;using ld=long double;using pll=pair<ll,ll>;using pld=pair<ld,ld>;
const ll INF=1LL<<60;void solve();int main(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(10);solve();}
#define foreach(i,a) for(auto &i:a)
#define SELECTOR(_1,_2,_3,_4,SELECT,...) SELECT
#define rep(...) SELECTOR(__VA_ARGS__,_rep2,_rep1,_rep0)(__VA_ARGS__)
#define _rep0(i,n) for(ll i=0;i<n;++i)
#define _rep1(i,k,n) for(ll i=k;i<n;++i)
#define _rep2(i,k,n,d) for(ll i=k;d!=0&&d>0?i<n:i>n;i+=d)
template<class T> vector<T> make_v(size_t a,T b){return vector<T>(a,b);}
template<class... Ts> auto make_v(size_t a,Ts... ts){return vector<decltype(make_v(ts...))>(a,make_v(ts...));}
template<class T> inline bool chmax(T &a,const T &b){if(a<b){a=b; return 1;} return 0;}
template<class T> inline bool chmin(T &a,const T &b){if(a>b){a=b; return 1;} return 0;}

void solve(){
  ll n; cin>>n;
  string S; cin>>S;
  ll q; cin>>q;
  rep(_,q){
    ll k; cin>>k;
    vector<ll> DMC(3);
    ll cnt=0;
    ll ans=0;
    queue<char> Q;
    foreach(s,S){
      // push
      if(s=='D'){
        DMC[0]++;
      }else if(s=='M'){
        DMC[1]++;
        cnt+=DMC[0];
      }else if(s=='C'){
        DMC[2]++;
        ans+=cnt;
      }
      Q.push(s);

      // pop
      if(Q.size()<k) continue;
      char t=Q.front(); Q.pop();
      if(t=='D'){
        DMC[0]--;
        cnt-=DMC[1];
      }else if(t=='M'){
        DMC[1]--;
      }else if(t=='C'){
        DMC[2]--;
      }
    }
    cout<<ans<<"\n";
  }
}


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

int main() {
    int N, x, res = 0;
    cin >> N >> x;

    int a[N];

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

    sort(a, a+N);

    for (int j = 0; j < N; j++) {
        if (j == N -1) {
            if (x == a[j]) {
                res++;
            }
            break;
        }
        if (x - a[j] >= 0) {
            x -= a[j];
            res++;
        }
    }

    cout << res << endl;
}

#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  FOR(i,0,n)
#define req(i,n) for(int i = 1;i <=n;i++)
#define pai 3.14159265358979323846
const int INF = 1001001001;
typedef long long ll;
int A[3][3], N;
bool punched[3][3];
bool ok[3][3];
using Graph = vector<vector<int>>;
vector<vector<int>> field;
vector<bool> seen;

const int MOD = 1000000007;
typedef pair<int,int> P;

//最大公約数
int gcd(int a,int b){
	if (a%b == 0){
		return b;
	}
	else{
		return gcd(b,a%b);
	}

}

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

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

// 素因数分解
vector<pair<long long, long long> > prime_factorize(long long n) {
    vector<pair<long long, long long> > res;
    for (long long p = 2; p * p <= n; ++p) {
        if (n % p != 0) continue;
        int num = 0;
        while (n % p == 0) { ++num; n /= p; }
        res.push_back(make_pair(p, num));
    }
    if (n != 1) res.push_back(make_pair(n, 1));
    return res;
}

// 10進数から2進数
int binary(int bina){
    int ans = 0;
    for (int i = 0; bina>0 ; i++)
    {
        ans = ans+(bina%2)*pow(10,i);
        bina = bina/2;
    }
    return ans;
}

int main() {
  int n;
  cin >> n;
  ll x,a[n+1];
  cin >> x;
  rep (i,n){
    cin >> a[i];
  }
  int res = 0;
  sort (a,a+n);
  rep (i,n){
    if (x >= a[i]) {
      res ++;
      x -= a[i];
    }
    else break;
  }
  if (res == n && x) --res;
  cout << res << endl;
}


#include<bits/stdc++.h>
using namespace std;
int main(){
    int n,k;
    cin >> n >> k;
    cout << (n+k-1)/k - n/k << endl;
}

#pragma GCC optimize ("O3")

#include <bits/stdc++.h>

using namespace std;

#ifdef LOCAL
#include <prettyprint.hpp>
#define debug(...)  cerr << "[" << #__VA_ARGS__ << "]: ", d_err(__VA_ARGS__);
#else
#define debug(...) 83;
#endif

void d_err() {
    cerr << endl;
}

template <typename H, typename... T>
void d_err(H h, T... t) {
    cerr << h << " ";
    d_err(t...);
}

template <typename T>
void print(T x) {
    cout << x << endl;
}

#define ALL(x) (x).begin(), (x).end()
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define REP(i, n) FOR(i, 0, n)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define bcnt __builtin_popcountll

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<ll,ll> Pll;
typedef pair<int,int> Pin;

ll INF = 1e16;
int inf = 1e9;
ll MOD = 1e9+7;

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

    int N, K;
    cin >> N >> K;

    if (N % K == 0) print(0);
    else print(1);

}


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

int main() {
	int n;
	cin >> n;
	multiset<int> st;
	for (int i = 0; i < n; i++) {
		int a;
		cin >> a;
		auto itr = st.lower_bound(a);
		if (itr == st.begin()) {
			st.insert(a);
		} else {
			itr--;
			st.erase(itr);
			st.insert(a);
		}

	}
	int ans = st.size();
	cout << ans << endl;
	return 0;
}

// Made by Luis Miguel Baez
// es.luismiguelbaez@gmail.com

#include <bits/stdc++.h>

using namespace std;

#define endl '\n'
#define precise(n,k) fixed << setprecision(k) << n
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

#define uint  unsigned int
#define ll    long long
#define ull   unsigned long long
#define ld    long double

#define pii   pair<int, int>
#define piii  pair<int, pair<int, int>>
#define pll   pair<ll, ll>

#define F  first
#define S  second
#define PB push_back
#define MP make_pair

#define debug(...) "[" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

string to_string(string s) {
    return '"' + s + '"';
}

string to_string(bool b) {
    return (b ? "true" : "false");
}

template <typename A, typename B>
string to_string(pair<A, B> p) {
    return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}

template <typename T>
string to_string(const vector<T> &v) {
    bool first = true;
    string res = "{";
    for (const T &x : v) {
        if (!first) {
            res += ", ";
        }
        first = false;
        res += to_string((T)x);
    }
    res += "}";
    return res;
}

// add templates here

template<class T>
void println(const T &data) {
    cout << to_string((T)data) << endl;
}

template <typename T>
void write(vector<T> &v, bool size=true) {
    if(size) cout << v.size() << endl;
    string res = "";
    for(const T &x: v) {
        res += to_string((T)x) + " ";
    }
    cout << res << endl;
}

template <typename T>
void read(vector<T> &v) {

    for(const T &x: v) {
        cin >> x;
    }
}

const int MOD = int(1e9+7);
const int oo  = int(1e9 + 20);
const ll lloo  = (ll)(1e18 + 10);

#define NEUTRAL_MIN -oo
// Limite de la longitud del Array
const int N = 100000 + 20;

int n; // Tamaño del Arreglo

// Maximo Tamaño del Arbol
int tree[2 * N];

// Funcion que Construye el Arbol
void build( vector<int> arr) {

    for (int i=0; i<n; i++){
        tree[n+i] = arr[i];
    }

    // construye el árbol calculando a los padres
    for (int i = n - 1; i > 0; --i) {
        tree[i] = max(tree[i<<1], tree[i<<1 | 1]);
    }
}

// Función para actualizar un nodo de árbol
void updateTreeNode(int index, int value) {
    // Establecer el valor en la posición p
    tree[index+n] = value;
    index = index + n;

    // Moverse hacia arriba y actualizar a los padres
    for (int i = index; i > 1; i >>= 1){
        tree[i>>1] = max(tree[i], tree[i^1]);
    }
}

// función para obtener la suma en el intervalo [l, r)

int query(int l, int r) {
    int ans = NEUTRAL_MIN;

    // bucle para encontrar la suma en el rango
    for (l += n, r += n; l < r; l >>= 1, r >>= 1) {
        if (l&1) {
            ans = max(ans, tree[l++]);
        }

        if (r&1) {
            ans = max(ans, tree[--r]);
        }
    }

    return ans;
}

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

    cin >> n;
    n++;
    vector<int> val(n);
    for(int i = 1; i < n; ++i) {
        cin >> val[i];
    }
    build(val);

    vector<bool> visited(n, false);
    int colors = 0;
    int last;
    for(int i = 1; i < n; ++i) {
        if(!visited[i]) {
            colors++;
            last = val[i];
            visited[i] = true;
            updateTreeNode(i, -oo);

            if(query(i+1, n) <= last) continue;

            for(int j = i + 1; j < n; ++j) {
                if(!visited[j] && last < val[j]) {
                    last = val[j];
                    visited[j] = true;
                    updateTreeNode(j, -oo);
                    if(query(j+1, n) <= last) break;
                }
            }
        }
    }
    cout << colors << endl;

    return 0;
}


#include<iostream>
using namespace std;

int cnt;

void insertionSort(int* a, int n, int g){

    int i, j, v;

    for(i = g; i < n; i++){
        v = a[i];
        j = i - g;
        while((j >= 0) && (a[j] > v)){
            a[j + g] = a[j];
            j = j - g;
			cnt++;
        };
        a[j + g] = v;
    }
}

void shellsort(int* a, int n)
{
	cnt = 0;
	int i, p;
	int m;
	int G[15];

	p = 1;
	for(i = 1; i < 20; i++){
		p = p * 3;
		if(p - 1 > 2 * n) break;
	}
	if(i > 1) i = i - 1;
	m = i;

	p = 1;
	for(i = 0; i < m; i++){
		p = p * 3;
		G[m - 1 - i] = (p - 1) / 2;
	}
	cout << m << endl;
	for(i = 0; i < m - 1; i++) cout << G[i] << " ";
	cout << G[m - 1] << endl;

	for(int i = 0; i < m; i++){
		insertionSort(a, n, G[i]);
	}
}

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

	shellsort(A, n);
	cout << cnt << endl;
    for(i = 0; i < n; i++) cout << A[i] << endl;

    return 0;
}

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

int main() {
  using LL = long long;

  int N;
  cin >> N;
  vector<LL> A(N);
  for(auto& i: A) cin >> i;

  const LL NG = -1e18;
  vector<map<int, LL>> memo(N);
  function<LL(int,int)> dfs = [&](int i, int n) {
    if(n == 0) return 0ll;
    if(N <= i) return NG;
    if(N < i+2*n-1) return NG;
    if(memo[i][n]) return memo[i][n];
    return memo[i][n] = max(dfs(i+1, n), A[i]+dfs(i+2, n-1));
  };

  cout << dfs(0, N/2) << endl;
}


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

#define FOR(i,a,b) for(int i=(a);i<(int)(b);i++)
#define rep(i,n) FOR(i,0,n)
#define ZERO(a) memset(a,0,sizeof(a))
#define pb push_back

int rank[1020];

int main() {
    int n, m;
    ZERO(rank);
    cin >> n >> m;
    vector<int> v;
    rep(i,n) {
        int cost; scanf("%d",&cost);
        v.pb(cost);
    }

    rep(i,m) {
        int c; scanf("%d",&c);
        rep(j,n) if(c >= v[j]) {
            rank[j+1]++; break;
        }
    }

    int ans = 0, ma = 0;
    rep(i,1001) if(ma < rank[i]) {
        ma = rank[i];
        ans = i;
    }
    cout << ans << "\n";

    return 0;
}


#include<bits/stdc++.h>
#define REP(i,n) for(long long i=0;i<n;++i)
#define FOR(i,a,b) for(long long i=a;i<b;++i)
using namespace std;
using point = pair< int,int >;
using ll = long long;

int main(){
    int n;
    int c;
    int graph[11];
    while (~scanf("%d", &n)) {
        if (!n) break;
        fill(graph, graph + 11, 0);
        REP(i, n) {
            scanf("%d", &c);
            graph[c]++;
        }
        FOR(i, 0, 10) {
            if (!graph[i]) printf("-\n");
            else {
                REP(j, graph[i]) printf("*");
                puts("");
            }
        }
    }
    return 0;
}

#include <bits/stdc++.h>
using namespace std;
const int M = 1e6;
set<int> adj[M];
int nd, indeg[M];
bool vis[M];
int main() {
	ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
	int n;
	cin >> n;
	map<pair<int, int>, int > mp;
	int mat[n][n - 1];
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n - 1; j++) {
			cin >> mat[i][j];
			mat[i][j]--;
		}
	}
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n - 2; j++) {
			pair<int, int> p1 = {i, mat[i][j]}, p2 = {i, mat[i][j + 1]};
			if (p1.first > p1.second)
				swap(p1.first, p1.second);
			if (p2.first > p2.second)
				swap(p2.first, p2.second);
			if (mp.find(p1) == mp.end())
				mp[p1] = nd++;
			if (mp.find(p2) == mp.end())
				mp[p2] = nd++;
			if (adj[mp[p1]].find(mp[p2]) == adj[mp[p1]].end()) {
				adj[mp[p1]].insert(mp[p2]);
				indeg[mp[p2]]++;
			}
		}
	}
	queue<pair<int, int> > q;
	for (int i = 0; i < nd; i++) {
		if (indeg[i] == 0) {
			vis[i] = true;
			q.push({i, 1});
		}
	}
	int ans = -1;
	while (!q.empty()) {
		int v = q.front().first, d = q.front().second;
		q.pop();
		for (auto nbr : adj[v])
			indeg[nbr]--;
		ans = d;
		for (auto nbr : adj[v]) {
			if (!vis[nbr] && indeg[nbr] == 0) {
				vis[nbr] = true;
				q.push({nbr, d + 1});
			}
		}
	}
	for (int i = 0; i < n; i++) {
		if (!vis[i])
			ans = -1;
	}
	cout << ans;
	return 0;
}


#include<bits/stdc++.h>
using ll=long long;
using namespace std;
#define rep(i, n) for(ll i=0; i<n; i++)
#define Rep(i, j, n) for(ll i=j; i<n; i++)
#define all(vec) vec.begin(), vec.end()
template<class T> inline bool chmin(T& a, T b) {if(a > b) {a = b; return true;} return false;}
template<class T> inline bool chmax(T& a, T b) {if(a < b) {a = b; return true;} return false;}
int dh[4] = {-1, 0, 0, 1};
int dw[4] = {0, -1, 1, 0};
using P = pair<int, int>;
const double pi = acos(-1.0);

int main(){
  string s;
  cin>>s;
  vector<bool>ch(26);
  string ans="abcdefghijklmnopqrstuvwxyz";
  rep(i,s.size()){
    ch[s[i]-'a']=true;
  }
  rep(i,26){
    if(!ch[i]){cout<<ans[i]<<endl;return 0;}
  }

  cout<<"None"<<endl;

  return 0;
}

#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pi 3.141592653589793238
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define mod 1000000007
int main(){
	fast;
	string s;
	cin>>s;
	int fre[26]={0};
	for(int i=0;i<s.length();i++)
		fre[s[i]-97]++;
	for(int i=0;i<26;i++)
	{
		if(fre[i]==0)
		{
			cout<<(char)(i+97);
			return 0;
		}
	}
	cout<<"None";
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef pair<int, int> pi;
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<pi> vpi;
typedef vector<vi> vii;
typedef map<int, int> mp;
typedef multiset<int> mset;
typedef long int int32;
typedef unsigned long int uint32;
typedef long long int int64;
typedef unsigned long long int  uint64;
typedef vector<int64> vi64;
#define fast ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL)
#define form(i,j,k,l) for(int i=j;i<int(k);i+=l)
#define rform(i,j,k,l) for(int i=int(j);i>int(l);i-=l)
#define rep(i, j) for(int i=0;i<int(j);i++)
#define rrep(i, j) for(int i=int(j);i>=0;i--)
#define all(cont) cont.begin(), cont.end()
#define rall(cont) cont.end(), cont.begin()
#define forc(it, l) for (auto it = l.begin(); it != l.end(); it++)
#define IN(A, B, C) assert( B <= A && A <= C)
#define mp(x,y) make_pair(x,y)
#define pb(x) push_back(x)
#define INF (int)1e9
#define INF64 (int64)1e18
#define EPS 1e-9
#define PI 3.1415926535897932384626433832795
#define MOD 1000000007
#define read(type) readInt<type>()
#define F first
#define S  second
const double pie = acos(-1.0);
template <typename T>
T Max(T x, T y)
{
  return (x > y) ? x : y;
}
template <typename T>
T Min(T x, T y)
{
  return (x > y) ? y : x;
}
int gcd(int n1, int n2)
{
  if (n2 != 0) return gcd(n2, n1 % n2);
  else return n1;
}
#define TRACE

#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
  cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
  const char* comma = strchr(names + 1, ','); cerr.write(names, comma - names) << " : " << arg1 << " | "; __f(comma + 1, args...);
}
#else
#define trace(...)
#endif
clock_t time_p = clock();
void rtime() { time_p = clock() - time_p; cerr << "Time Taken : " << (float)1000 * (time_p) / CLOCKS_PER_SEC << "\n";}
int main()
{ fast;
  int64 n;
  cin >> n;
  int64 r = (int64)sqrt((double)n);
  for (int64 i = r; i >= 1; i--)
  { if (n % i == 0)
    { int k = n / i;
      int l = 0;
      while (k > 0)
      { k = k / 10;
        l++;
      }
      cout << l;
      return 0;
    }

  }
}

#include<bits/stdc++.h>

#define fast ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define int long long
#define endl '\n'

using namespace std;

const int N = 2e5 + 77;
int A[N];
int F(int a,int b){
    string x = to_string(a);
    string y = to_string(b);
    return max(x.length(),y.length());
}
int32_t main(){
    fast;
    int n , ans = 1e12; cin >> n ;
    for(int i = 1 ; i*i <= n ; ++i){
        if(n%i==0){
            int a = i ,b = n/i;
            ans = min(ans,F(a,b));
        }
    }
    cout << ans << endl;
    return 0;
}


#include<iostream>
using namespace std;

 int InsertionSort(int* a, int n, int g)
{
	int tmp, j, count = 0;
	for (int i = g; i < n; i++)
	{
		tmp = a[i];
		for (j = i - g; j >= 0 && a[j] > tmp; j -= g)
		{
			a[j + g] = a[j];
			count++;
		}
		a[j + g] = tmp;
	}
	return count;
}

int ShellSort(int* a, int n)
{
	int m, g[100],count = 0;
	for (m = 1; m * m * m <= n; m++)
		continue;
	m--;
	cout << m << endl;
	for (int i = 0; i < m; i++)
	{
	    g[i] = (m - i) * (m - i);
		if (i)
			cout << " ";
		cout << g[i];
	}
	for (int i = 0; i < m; i++)
		count += InsertionSort(a, n, g[i]);

	return count;
}

int main()
{
	int n, a[1000000], count;
	cin >> n;
	for (int i = 0; i < n; i++)
		cin >> a[i];
	count = ShellSort(a, n);
	cout << endl << count << endl;
	for (int i = 0; i < n; i++)
		cout << a[i] << endl;

	return 0;
}

#define dbg(...) fprintf(stderr,__VA_ARGS__)
#define dpr(x) cerr<<#x<<": "<<x<<endl;
#define dprc(c) do{cerr<<#c<<":";for(auto&_i:(c)){cerr<<" "<<_i;}cerr<<endl;}while(0)
#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
int INF = 1e9+7;
#define all(c) begin(c), end(c)
#define tr(i,c) for(auto i=begin(c);i!=end(c);i++)
#define rtr(i,c) for(auto i=(c).rbegin();i!=(c).rend();i++)
#define rep(i,b) for(auto i=0;i<(b);i++)
#define pb push_back
#define sz(c) int((c).size())

int cnt, m;
vi G;

void insertionSort(vi& A, int n, int g) {
  for (int i = g; i < n; i++) {
    int v = A[i];
    int j = i - g;
    while (j >= 0 && A[j] > v) {
      A[j+g] = A[j];
      j = j - g;
      cnt++;
    }
    A[j+g] = v;
  }
}

void shellSort(vi& A, int n) {
  cnt = 0;
  G = vi(0);
  int g = 1;
  do {
    G.pb(g);
    g = g*3 + 1;
  } while (g <= n);
  reverse(all(G));
  m = sz(G);
  for (auto& g:G) {
    insertionSort(A, n, g);
  }
}

void dump(vi& A, const string& sep) {
  string sp = "";
  for (auto& a:A) {
    cout << sp << a;
    sp = sep;
  }
  cout << endl;
}

int main(int argc, char **argv)
{
  vi A;
  int n;
  cin >> n;
  A = vi(n);
  for (int i = 0; i < n; i++) {
    cin >> A[i];
  }
  shellSort(A, n);

  cout << m << endl;
  dump(G, " ");
  cout << cnt << endl;
  dump(A, "\n");
  return 0;
}


#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <iomanip>
#include <cassert>
#include <random>
#include <tuple>

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

using namespace std;
typedef long long ll;
typedef pair<int, int> P;

const int MAX_V = 10010;
int V;
int cmp[MAX_V]; // components of each vertex
bool used[MAX_V];
vector<int> g[MAX_V], rg[MAX_V], ng[MAX_V], vs;

void add_edge(int from, int to) {
    g[from].push_back(to);
    rg[to].push_back(from);
}

void dfs(int v) {
    used[v] = true;
    for (int nv: g[v]) {
        if (!used[nv]) dfs(nv);
    }
    vs.push_back(v);
}

void rdfs(int v, int k) {
    used[v] = true;
    cmp[v] = k;
    for (int nv: rg[v]) {
        if (!used[nv]) rdfs(nv, k);
    }
}

// return number of components
int scc() {
    memset(used, false, sizeof(used));
    vs.clear();
    for (int v = 0; v < V; v++) {
        if (!used[v]) dfs(v);
    }
    memset(used, false, sizeof(used));
    int k = 0;
    for (int i = vs.size()-1; i >= 0; i--) {
        if (!used[vs[i]]) rdfs(vs[i], k++);
    }
    return k;
}

void new_graph(int k) {
    for (int v = 0; v < V; v++) {
        for (int nv: g[v]) {
            int x = cmp[v];
            int y = cmp[nv];
            if (x == y) continue;
            ng[x].push_back(y);
        }
    }
}

int main() {
    int e; cin >> V >> e;
    rep(i, e) {
        int s, t; cin >> s >> t;
        add_edge(s, t);
    }

    scc();

    int q; cin >> q;
    rep(i, q) {
        int u, v; cin >> u >> v;
        cout << (cmp[u] == cmp[v] ? 1 : 0) << endl;
    }

    return 0;
}

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

int N;
int dubling[22][100005];
int X[100005];
int L;
int main()
{
        cin >> N;

        for ( int i = 0; i < N; i++ ) cin >> X[i];
        cin >> L;
        for ( int i = 0; i < N; i++ ) {
                dubling[0][i] = upper_bound(X, X + N, X[i] + L) - X - 1;
                //cout << dubling[0][i] << " ";
        }
        //cout << endl;

        for ( int p = 1; p < 22; p++ ) {
                for ( int i = 0; i < N; i++ ) {
                        dubling[p][i] = dubling[p - 1][dubling[p - 1][i]];
                        //cout << p << " " << i << " " << dubling[p][i] << endl;
                }
        }

        int Q;
        cin >> Q;
        while ( Q-- ) {
                int a, b;
                cin >> a >> b; --a, --b;
                if ( a > b ) swap(a, b);
                int bit = 0;
                int node = a;
                for ( int p = 21; p >= 0; p-- ) {
                        if ( dubling[p][node] < b ) {
                                node = dubling[p][node];
                                bit |= (1 << p);
                        }
                }
                cout << bit + 1 << endl;
        }

        return ( 0 );
}


#include <bits/stdc++.h>
#include <stdio.h>
#include <math.h>
using namespace std;
using vi = vector<int>;
using vll = vector<long long int>;
using vb = vector<bool>;
using vvi = vector<vector<int>>;
using vvll = vector<vector<long long int>>;
using ll = long long int;

int main(){
    ll N; string A, B, C; cin >> N >> A >> B >> C;
    ll c = 0;
    for(int i=0; i<N; i++){
        if(A[i] == B[i]&&B[i] ==C[i]){}
        else if(A[i] == B[i]&&B[i] !=C[i]){c++;}
        else if(A[i] != B[i]&&B[i] ==C[i]){c++;}
        else if(A[i] == C[i]&&B[i] !=C[i]){c++;}
        else{c += 2;}
    }
    cout << c;
}

#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#include<bits/stdc++.h>
using namespace std;
#define IO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define int long long
#define endl "\n"
#define all(x) (x).begin(),(x).end()
const int MOD = 1e9+7;
const int mxN = 2e5+3;

void solve(){
	int n, x, t;
	cin >> n >> x >> t;
	int r = n/x;
	if(n % x != 0)r++;
	int ans = r * t;
	cout << ans << endl;
}

int32_t main(){
	IO;

	int nT = 1;
	//cin >> nT;
	for(int i = 1; i <= nT; ++i)
		solve();
	return 0;
}


#include<iostream>
#include<iomanip>
#include<cmath>

using namespace std;

int main()
{
	double x1,x2,y1,y2,p;
	cin>>x1>>y1>>x2>>y2;

	x1=x2-x1;
	y1=y2-y1;

	x1=sqrt(x1*x1+y1*y1);

	cout<<setprecision(10)<<x1<<endl;

	return 0;
}