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

using namespace std;

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

//組み合わせの余りを求める
ll fac[MAX_N], finv[MAX_N], inv[MAX_N];
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX_N; i++) {
		fac[i] = fac[i - 1] * i % MOD;
		inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
		finv[i] = finv[i - 1] * inv[i] % MOD;
	}
}

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

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

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

ll dx[8] = { 1,-1,0,0,1,1,-1,-1 };
ll dy[8] = { 0,0,1,-1,1,-1,1,-1 };
ll d[110][2];

//long longしか使わない
//素数は1より大きい
//lower_boundは指定したkey以上の要素の一番左のイテレータをかえす
//upper_boundは指定したkeyより大きい要素の一番左のイテレータをかえす
int main() {
	ll n, q;
	cin >> n >> q;
	string s;
	cin >> s;
	vector<ll>res(n);
	rep(i, n - 1) {
		res[i + 1] = res[i];
		if (s[i] == 'A' && s[i + 1] == 'C')res[i + 1]++;
	}
	rep(i, q) {
		ll l, r;
		cin >> l >> r;
		l--, r--;
		cout << res[r] - res[l] << endl;
	}
	return 0;
}

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<vector>
#include<utility>
#include<cmath>
#include<string>
#include<cstring>
#include<map>
#include<queue>
#include<set>
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define prin(arg) std::cout<<arg<<"\n"
#define prin2(arg1,arg2) std::cout<<arg1<<" "<<arg2<<"\n"
#define fill(arg,n) std::memset(arg,n,sizeof(arg))
#define mp std::make_pair
#define pb push_back
using std::cin;
typedef long long ll;
typedef std::pair<int,int> pi;
typedef std::pair<int,pi> pipi;
typedef std::vector<int> vi;
typedef std::set<int> si;
typedef std::string str;
const int INF=1e+9;
const ll INFLL=1e+17;
const ll MOD=1e+9+7;
const int NMAX=200010;
int N,K,L;
int p[100010],q[100010],r[100010],s[100010];
//UnionFindTreeのクラス。
/***************************/
class uft{
public:
  int par[NMAX];//親
  int rank[NMAX];//木の深さ
  int size[NMAX];//木の大きさ
  uft(int n);//コンストラクタ
  int find(int x);
  void unite(int x,int y);
  bool same(int x,int y);
  int usize(int x);
};
uft::uft(int n){//コンストラクタ uft uf(N)でサイズNのunionfindtreeを宣言
  for(int i=0;i<n;i++){
    par[i]=i;
    rank[i]=0;
    size[i]=1;
  }
}
int uft::find(int x){//xの根を返す
  if(par[x]==x) return x;//根の親は自分自身
  else return par[x]=find(par[x]);//再起で親を辿る
}
void uft::unite(int x,int y){//x,yを併合
  x=find(x);
  y=find(y);
  if(x==y) return ;//根が同じなら併合する必要なし

  if(rank[x]<rank[y]){//木の深い方に浅い方をつける
    par[x]=y;
    size[y]+=size[x];
  }
  else{
    par[y]=x;
    size[x]+=size[y];
    if(rank[x]==rank[y]) rank[x]++;//同じ深さなら深さを増やす
  }
}
bool uft::same(int x,int y){//x,yが同じグループにいるかどうかを返す
  return find(x)==find(y);//根が同じかどうかを判断する
}
int uft::usize(int x){//xの属する木のサイズを返す
  return size[find(x)];
}

int main(){
  cin>>N>>K>>L;
  rep(i,K){
    cin>>p[i]>>q[i];
    p[i]--;q[i]--;
  }
  rep(i,L){
    cin>>r[i]>>s[i];
    r[i]--;s[i]--;
  }
  uft ur(N),ut(N);
  rep(i,K){
    ur.unite(p[i],q[i]);
  }
  rep(i,L){
    ut.unite(r[i],s[i]);
  }
  pipi p[200010];
  rep(i,N){
    p[i]=mp(ur.find(i),mp(ut.find(i),i));
  }
  std::sort(p,p+N);
  int res[200010];
  int cnt=1;
  rep(i,N-1){
    if(p[i].first==p[i+1].first&&p[i].second.first==p[i+1].second.first) cnt++;
    else{
      rep(j,cnt){
	res[p[i-j].second.second]=cnt;
      }
      cnt=1;
    }
  }
  rep(j,cnt){
    res[p[N-1-j].second.second]=cnt;
  }
  rep(i,N){
    std::cout<<res[i]<<" ";
  }
  std::cout<<"\n";

  return 0;
}


#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <ctime>
#include <cstring>
#include <functional>
#include <iostream>
#include <iomanip>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <regex>
#include <vector>

#define fix(n)          cout<<fixed<<setprecision(n)
#define rep(i,n)        for (int i = 0; i < (n); ++i)
#define sort(a)         sort((a).begin(), (a).end())
#define uniq(a)         SORT(a);(a).erase(unique((a).begin(), (a).end()), (a).end())
#define reverse(a)      reverse((a).begin(), (a).end())
#define ctos(c)         string(1, (c))
#define out(d)          cout << (d)
#define outl(d)         std::cout<<(d)<<"\n"
#define YES(n)          cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n)          cout << ((n) ? "Yes" : "No"  ) << endl
#define ceil(x, y)      ((x + y - 1) / (y))
#define debug(x)        cerr << #x << ": " << (x) << '\n'
#define debug2(x, y)    cerr << #x << ": " << (x) << ", " << #y << ": " << (y) << '\n'
#define debug3(x, y, z) cerr << #x << ": " << (x) << ", " << #y << ": " << (y) << ", " << #z << ": " << (z) << '\n'
#define dbg(v)          for (size_t _ = 0; _ < v.size(); ++_){ cerr << #v << "[" << _ << "] : " << v[_] << '\n'; }

using namespace std;
using ll = long long;
using P = pair<ll,ll>;

const ll MOD = 1000000007; // 10^9 + 7

void solve() {
  int n; cin >> n;
  string a, b, c; cin >> a >> b >> c;
  int ans = 0;
  rep(i, n) {
    set<char> s;
    s.insert(a[i]);s.insert(b[i]);s.insert(c[i]);
    if (s.size() == 3) ans += 2;
    else if (s.size() == 2) ans += 1;
  }
  outl(ans);
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  srand((unsigned)time(NULL));
  fix(12);

  solve();
}

#include<bits/stdc++.h>
#define all(v) v.begin(),v.end()
using namespace std;
int main(){
	cin.tie(0);
    ios::sync_with_stdio(false);
	int a[5];
	char ans[5];
	string b;
	cin>>b;
	for(int i=0;i<4;i++){
		a[i]=b[i]-'0';
		ans[i]='+';
	}
	for(int i=0;i<4;i++){
		for(int j=0;j<4;j++){
			int sum=0;
			for(int k=0;k<4;k++){
				if(k==i  && k!=0 || k==j && k!=0){
					sum-=a[k];
				}
				else{
					sum+=a[k];
				}
			}
			if(sum==7){
				ans[i]='-';
				ans[j]='-';
				cout<<a[0]<<ans[1]<<a[1]<<ans[2]<<a[2]<<ans[3]<<a[3]<<"="<<"7"<<endl;
				return(0);
			}
		}
	}

    return(0);
}


#include <bits/stdc++.h>
using namespace std;
int main(void){
    int sx,sy,tx,ty;
    cin>>sx>>sy>>tx>>ty;
    std::map<pair<int,int>, int> seen;
    int x=sx,y=sy;
    for (int i=0;i<2;i++) {
    seen[pair(tx,ty)]=0;
    seen[pair(x,y)]++;
    while (1) {
        if (x<tx&&seen[pair(x+1,y)]==0) {
            cout<<"R";
            seen[pair(x+1,y)]++;
            x++;
        } else if (y<=ty&&seen[pair(x,y+1)]==0) {
            cout<<"U";
            seen[pair(x,y+1)]++;
            y++;
        } else if (seen[pair(x-1,y)]==0) {
            cout<<"L";
            seen[pair(x-1,y)]++;
            x--;
        } else if (seen[pair(x,y-1)]==0) {
            cout<<"D";
            seen[pair(x,y-1)]++;
            y--;
        }
        if (x==tx&&y==ty) {
            break;
        }
    }
    seen[pair(sx,sy)]=0;
    //cout<<endl;
    while (1) {
        if (x>sx&&seen[pair(x-1,y)]==0) {
            cout<<"L";
            seen[pair(x-1,y)]++;
            x--;
        } else if (y>=sy&&seen[pair(x,y-1)]==0) {
            cout<<"D";
            seen[pair(x,y-1)]++;
            y--;
        } else if (seen[pair(x+1,y)]==0) {
            cout<<"R";
            seen[pair(x+1,y)]++;
            x++;
        } else if (seen[pair(x,y+1)]==0) {
            cout<<"U";
            seen[pair(x,y+1)]++;
            y++;
        }
        if (x==sx&&y==sy) {
            break;
        }
    }
    //cout<<endl;
    }
    cout<<endl;
}

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=5500+5,M=1500,inf=0x3f3f3f3f,mod=1e9+7;
#define mst(a,b) memset(a,b,sizeof a)
#define lx x<<1
#define rx x<<1|1
#define reg register
#define PII pair<int,int>
#define fi first
#define se second
#define pb push_back
#define il inline
int sx,sy,ex,ey;
int main(){
	cin>>sx>>sy>>ex>>ey;
	for(int i=0;i<ey-sy;i++)	putchar('U');
	for(int i=0;i<ex-sx;i++) putchar('R');
	for(int i=0;i<ey-sy;i++)	putchar('D');
	for(int i=0;i<ex-sx;i++) putchar('L');
	putchar('L');
	for(int i=0;i<=ey-sy;i++)	putchar('U');
	for(int i=0;i<=ex-sx;i++) putchar('R');
	putchar('D');
	putchar('R');
	for(int i=0;i<=ey-sy;i++)	putchar('D');
	for(int i=0;i<=ex-sx;i++) putchar('L');
	putchar('U');
	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)
/*
5の数
2の数
mapでいれとく
{2,5,小数の数｝

7.5=0,3,1
2.4=3,0,1
3-2=1>0だからOK
全部9桁として
9+4=13桁として扱う
2と5が18桁あればOK

10.000
20.000

10*10の組み合わせもとっちゃう。
2
200000*400はぎりぎりせーふ。50msくらい。
200000*1になりそう
*/
int main(){
  cin.tie(0);
  ios::sync_with_stdio(0);
  ll N; cin>>N;
  vector<vector<ll>> DP(20, vector<ll>(20,0));
  vector<pair<ll,ll>> Z(N,{0,0});
  rep(i,N){
    string S; cin>>S;
    ll n=0, j=0, d=100;
    while (S[j] && d-->0){
      if (S[j] == '.'){
        d=9;
        j++;
        continue;
      }
      n = n * 10 + (S[j++] - '0');
    }

    d = min(d, 9LL);
    ll two=d, five=d;
    while (n%2==0){
      two++;
      n/=2;
    }
    while (n%5==0){
      five++;
      n/=5;
    }
    two = min(two,18LL);
    five = min(five,18LL);
    DP[two][five]++;
    Z[i] = {two,five};
  }
//DPつくる
  for(ll j=18; j>=0; j--) for(ll k=18; k>=0; k--)
    DP[j][k] += DP[j][k+1];
  for(ll j=18; j>=0; j--) for(ll k=18; k>=0; k--)
    DP[k][j] += DP[k+1][j];

  ll ans=0;
  rep(i, N){
    ll t=Z[i].first;
    ll f=Z[i].second;
    ans += DP[18-t][18-f];
    if (t>=9 && f>=9)
      ans--;
  }
  ans /= 2;
  cout<<ans<<endl;
}

#include <bits/stdc++.h>

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

struct fastio {
    fastio() {
        ios::sync_with_stdio(false);
        cout << setprecision(10) << fixed;
        cin.tie(0);
    }
};

fastio _fast_io;

const int N = 2e5 + 5;
int n;
int a[N];
int cnt[N];
int res;

int main() {
    cin >> n;
    for (int i = 1; i <= n; ++i) {
        cin >> a[i];
    }
    for (int i = n; i >= 1; --i) {
        int Cnt = 0;
        for (int j = i + i; j <= n; j += i) {
            Cnt += cnt[j];
        }
        Cnt %= 2;
        if (a[i] != Cnt) {
            ++res;
            cnt[i] = 1;
        }
    }
    cout << res << endl;
    for (int i = 1; i <= n; ++i) {
        if (cnt[i]) {
            cout << i << ' ';
        }
    }
    if (res)
        cout << endl;
    return 0;
}


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

int main (){
    int n = 0, m = 0;
    while(true){
        int ans = 0; //for answer
        std::cin >> n >> m;
        //exit when n = m = 0
        if(n == 0 && m == 0){
            break;
        }
        std::vector<int> price(n); //each vegetable price
        //put price to vector
        for(int i = 0; i < n; ++i){
            std::cin >> price[i];
        }
        //descending sort
        std::sort(price.begin(), price.end(), std::greater<int>());
        //m'th vegetable don't add
        for(int i = 0; i < n; ++i){
            if((i+1) % m != 0){
                ans += price[i];
            }
        }
        std::cout << ans << std::endl;
    }
    return 0;
}

#include <cstdio>
#include <set>
#include <vector>

using namespace std;

inline int abs(int x) { return (x >= 0) ? x : - x; }

int main()
{
    int n;
    long d;
    scanf("%d%ld", &n, &d);
    vector<long> a(n);
    for (int i = 0; i < n; i++)
        scanf("%ld", &a[i]);

    vector<long> b(n);
    for (int i = 0; i < n; i++)
        b[i] = a[i] + i * d;

    set<pair<long, int>> pairs;
    for (int i = 1; i < n; i++)
        pairs.insert(make_pair(b[i], i));

    long cost = 0;
    int j = 0;
    int k = 0;
    while (!pairs.empty()) {
        const int i = pairs.begin()->second;
        cost += abs(i - j) * d + a[i] + a[j];
        pairs.erase(pairs.begin());
        for (k++; k < i; k++) {
            cost += min(abs(i - k) * d + a[i] + a[k], abs(j - k) * d + a[j] + a[k]);
            pairs.erase(make_pair(b[k], k));
        }
        if (a[i] < a[j] + abs(i - j) * d)
            j = i;
    }

    printf("%ld\n", cost);

    return 0;
}


#include <iostream>
#include <vector>
#include <tuple>

using namespace std;
using int64 = long long;
using TP = tuple<int64,int,int>;
int main() {
  int n;
  cin >> n;
  vector<TP> ab;
  for (int i=0; i<n; i++) {
    int a, b;
    cin >> a >> b;
    ab.emplace_back(a+b, a, b);
  }
  sort(ab.rbegin(), ab.rend());

  int64 a = 0;
  int64 b = 0;
  for (int i=0; i<n; i++) {
    if (i%2) b += get<2>(ab[i]);
    else a += get<1>(ab[i]);
  }

  cout << (a-b) << endl;
}

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

vector<vector<int>> way;
int64_t N, M;
vector<int> color;

bool dfs(int x, int col) {
  color.at(x) = col;
  for(int i = 0; i < way.at(x).size(); i++) {
    if(color.at(way.at(x).at(i)) == col) {
      return false;
    }
    if(color.at(way.at(x).at(i)) == -1) {
      if(!dfs(way.at(x).at(i), 1 - col)) {
        return false;
      }
    }
  }
  return true;
}

int main() {
  cin >> N >> M;
  way.assign(N, {});
  color.assign(N, -1);
  for(int64_t i = 0; i < M; i++) {
    int a, b;
    cin >> a >> b;
    way.at(a - 1).push_back(b - 1);
    way.at(b - 1).push_back(a - 1);
  }
  if(!dfs(0, 0)) {
    cout << N * (N - 1) / 2 - M << endl;
  }
  else {
    int64_t total = 0;
    for(int i = 0; i < N; i++) {
      if(color.at(i) == 0) {
        total++;
      }
    }
    cout << total * (N - total) - M << endl;
  }
}


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

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

// time-limit: 2000
// 23
#include <bits/stdc++.h>
using namespace std;
#define coutc "\033[48;5;196m\033[38;5;15m"
#define endc "\033[0m"
#define endl '\n'
#define M(_1, _2, _3, _4, NAME, ...) NAME
#define rep(...) \
  M(__VA_ARGS__, rep4, rep3, rep2, rep1)(__VA_ARGS__)
#define rep4(_, x, n, s) \
  for (int _ = x; (s < 0) ? _ > n : _ < n; _ += s)
#define rep3(_, x, n) rep4(_, x, n, (x < n ? 1 : -1))
#define rep2(_, n) rep3(_, 0, n)
#define rep1(n) rep2(i, n)
#define fi first
#define se second
#define pb push_back
#define pii pair<int, int>
#define all(x) x.begin(), x.end()
#define len(x) int(x.size())
#define lli __int128_t
#define li long long int
#define ld long double
#ifdef DEBUG
// 3
ostream &operator<<(ostream &o, pair<auto, auto> p) {
  return o << "(" << p.fi << ", " << p.se << ")";
}
// 4
ostream &operator<<(ostream &o, vector<auto> v) {
  rep(i, len(v)) o << setw(7) << right << v[i];
  return o << endc << endl << coutc;
}
// 4
ostream &operator<<(ostream &o, map<auto, auto> m) {
  for (auto &kv : m) o << kv;
  return o;
}
// 7
void debug(const auto &e, const auto &... r) {
  cout << coutc << e;
  ((cout << " " << r), ..., (cout << endc << endl));
}
#else
#define debug(...)
#endif

int sign(li x) { return x < 0 ? -1 : x > 0; }

//         a / b
li ceil(li a, li b) {
  if (sign(a) == sign(b) && a % b) return a / b + 1;
  else return a / b;
}

void _main(int tc) {
    int a, b;
    cin >> a >> b;

    // b = a + (a - 1) * X
    // X = (b - a) / (a - 1)
    // is ceiling because we need to assure that with X pipes we complete "b - a" lines.
    // we add one because after fullfilling "b - a" we still need to complete with "a" lines.
    cout << ceil(b - a, a - 1) + 1 << endl;
}
// 7
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0);
  _main(0), exit(0);
  int tc;
  cin >> tc;
  rep(i, tc) _main(i + 1);
}


#include <algorithm>
#include <cstdio>
#include <iostream>
#include <numeric>
#include <utility>
#include <vector>
using namespace std;

vector<int> ant;

int main() {
#ifdef HOME
	freopen("agc01d.in", "r", stdin);
	freopen("agc01d.out", "w", stdout);
#endif
	ios::sync_with_stdio(false);
	cin.tie(0), cout.tie(0);
	int n, m, odd(0);

	vector<int> v;
	cin >> n >> m;
	v.resize(m);
	for (auto &i: v) {
		cin >> i;
		if (i % 2)
			odd+= 1; }

	if (odd > 2) {
		cout << "Impossible\n";
		return 0; }

	ant.reserve(n);

	partition(begin(v), end(v), [&](const int &x) { return x % 2; });
	partition(begin(v) + 1, end(v), [&](const int &x) { return 1 - x % 2; });

	ant.push_back(v[0] - 1);
	n-= v[0] - 1;
	for (int i = 1; i < m; ++i) {
		ant.push_back(v[i]);
		n-= v[i]; }

	if (n > 0) {
		if (v.back() == 1 || m != 1)
			ant.back()+= n;
		else
			ant.push_back(n); }

	ant.erase(remove(begin(ant), end(ant), 0), end(ant));

	for  (auto i: v)
		cout << i << ' ';
	cout << '\n' << ant.size() << '\n';
	for (auto i: ant)
		cout << i << ' ';
	cout << endl;

	return 0; }

#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
using namespace std;
using ll = long long ;
using P = pair<int,int> ;
using pll = pair<long long,long long>;
constexpr int INF = 1e9;
constexpr long long LINF = 1e17;
constexpr int MOD = 1000000007;
constexpr double PI = 3.14159265358979323846;

int main(){
    int n;
    ll x;
    cin >> n >> x;
    vector<ll> a(n);
    rep(i,n) cin >> a[i];
    sort(a.begin(),a.end());
    ll now = 0;
    int ans = n;
    rep(i,n){
        now += a[i];
        if(now > x){
            ans = i;
            break;
        }
    }

    if(ans==n&&now!=x) cout << (n-1) << endl;
    else cout << ans << endl;
    return 0;
}


#include<cstdio>
#include<iostream>
#include<map>
#include<set>
#include<vector>
#include<cstring>
#include<cassert>
#include<sstream>
#include<cmath>
#include<algorithm>
#include<queue>
#include<limits>
#include<ctime>
#include<stack>
#include<bits/stdc++.h>
#include<string>
#include<stdlib.h>
#include<stdio.h>

typedef long long ll;
using namespace std;
const ll x=1000000007;
int mod(ll a){
	return a%x;
}
int main(){
	ll n;
	cin>>n;
	ll a[n],ans=0,mins=n+1;
	for(int i=0;i<n;i++){
		cin>>a[i];
		if(a[i]<mins){
			ans+=mins-a[i]-1;
			mins=a[i];
		}
	}
	cout<<n-ans;
}

/*
   Push yourself, because no one else is going to do it for you.
*/
#include <bits/stdc++.h>
#define fast_io ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define set_zero(a) memset(a,0,sizeof(a));
#define ll long long int
#define PI 2 * acos(0.0)
#define MAX 10000000000000000
#define in(a) scanf("%d",&a);
#define out(a) printf("%d",a);
#define INF 1000000
#define M 1000000007
using namespace std;
int main(){
   fast_io
   ll n;
   cin>>n;
   ll a[n];
   for(ll i = 0;i<n;i++) cin>>a[i];
   ll ans = a[0];
   ll sum = 1;
   for(ll i = 1;i<n;i++){
       if(ans > a[i]){
            sum++;
       }
       ans = min(a[i],ans);
   }
   cout<<sum<<endl;
   return 0;
}


const int LG = 21;
const int FN = 400005;
const long long MOD = 1e9 + 7;
const long long INF = 1e9;
const long long INFLL = 1e18;

#include <bits/stdc++.h>

using namespace std;
#define int long long
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;

#define forn(i, n) for (int (i) = 0; (i) != (n); (i)++)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define popcount(x) __builtin_popcount(x)
#define popcountll(x) __builtin_popcountll(x)
#define fi first
#define se second
#define re return
#define pb push_back
#define uniq(x) sort(all(x)); (x).resize(unique(all(x)) - (x).begin())

#ifdef LOCAL
#define dbg(x) cerr << __LINE__ << " " << #x << " " << x << endl
#define ln cerr << __LINE__ << endl
#else
#define dbg(x) void(0)
#define ln void(0)
#endif // LOCAL

int cx[4] = {-1, 0, 1, 0};
int cy[4] = {0, -1, 0, 1};
string Yes[2] = {"No", "Yes"};
string YES[2] = {"NO", "YES"};

ll inq(ll x, ll y)
{
    if (!y) re 1 % MOD;
    ll l = inq(x, y / 2);
    if (y % 2) re l * l % MOD * x % MOD;
    re l * l % MOD;
}

ll rev(ll x)
{
    return inq(x, MOD - 2);
}

bool __precomputed_combinatorics = 0;
vector<ll> __fact, __ufact, __rev;

void __precompute_combinatorics()
{
    __precomputed_combinatorics = 1;
    __fact.resize(FN);
    __ufact.resize(FN);
    __rev.resize(FN);
    __rev[1] = 1;
    for (int i = 2; i < FN; i++) __rev[i] = MOD - __rev[MOD % i] * (MOD / i) % MOD;
    __fact[0] = 1, __ufact[0] = 1;
    for (int i = 1; i < FN; i++) __fact[i] = __fact[i - 1] * i % MOD, __ufact[i] = __ufact[i - 1] * __rev[i] % MOD;
}

ll fact(int x)
{
    if (!__precomputed_combinatorics) __precompute_combinatorics();
    return __fact[x];
}

ll cnk(int n, int k)
{
    if (k < 0 || k > n) return 0;
    if (!__precomputed_combinatorics) __precompute_combinatorics();
    return __fact[n] * __ufact[n - k] % MOD * __ufact[k] % MOD;
}

int Root(int x, vector<int> &root)
{
    if (x == root[x]) return x;
    return root[x] = Root(root[x], root);
}

void Merge(int v, int u, vector<int> &root, vector<int> &sz)
{
    v = Root(v, root), u = Root(u, root);
    if (v == u) return;
    if (sz[v] < sz[u])
    {
        sz[u] += sz[v];
        root[v] = u;
    }
    else
    {
        sz[v] += sz[u];
        root[u] = v;
    }
}

int ok(int x, int n)
{
    return 0 <= x && x < n;
}

void bfs(int v, vi &dist, vector<vi> &graph)
{
    fill(all(dist), -1);
    dist[v] = 0;
    vi q = {v};
    for (int i = 0; i < q.size(); i++)
    {
        for (auto u : graph[q[i]])
        {
            if (dist[u] == -1)
            {
                dist[u] = dist[q[i]] + 1;
                q.push_back(u);
            }
        }
    }
}

signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int k, n;
    cin >> k >> n;
    vi a(n);
    forn(i, n) cin >> a[i];
    int x = *max_element(all(a));
    for (int bd = 0; bd <= 30000; bd++)
    {
        int nx = x - bd;
        int ny = k - bd;
        if (nx <= (ny + 1) / 2) cout << bd, exit(0);
    }
}

/* Note:
Check constants at the beginning of the code.
    N is set to 4e5 but be careful in problems with large constant factor.
    Setting N in every problem is more effective.
Check corner cases.
    N = 1
No def int long long for now.
Add something here.
*/

#include <iostream>
#include <vector>

using namespace std;

int main(int argc, char* argv[]) {
  int K, T;
  cin >> K >> T;

  vector<int> a(T);
  int maximum = 0;
  for (int i = 0; i < T; ++i) {
    cin >> a[i];
    maximum = max(maximum, a[i]);
  }

  cout << max(maximum - (K - maximum) - 1, 0) << endl;

  return 0;
}


#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <map>
#include <algorithm>
#include <iomanip>
#include <math.h>
#include <string.h>
#include <cstdio>
#include <tuple>
#include <numeric>
using namespace std; using ll = long long; using ld = long double;  using pll = pair<ll, ll>;
using vl = vector<ll>; using vll = vector<vl>; using vpll = vector<pll>;
using vs = vector<string>; using tll = tuple<ll, ll, ll>; using vtll = vector<tll>;
const ld PI = 3.1415926535897932;
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define co(i) cout << i << endl;
#define co2(i,j) cout << i << " " << j << endl;
#define co3(i) cout << i << " ";
#define po(i) cout << i.first << " " << i.second << endl;
void in() {}
void debug_out() { cerr << endl; }
template<typename Head, typename... Tail>
void debug_out(Head h, Tail... t) {
	cerr << " " << h;
	if (sizeof...(t) > 0) cerr << " :";
	debug_out(t...);
}
template <typename T>
ostream& operator<<(ostream& os, vector<T> vec) {
	for (size_t i = 0; i < vec.size(); i++)os << vec[i] << (i + 1 == vec.size() ? "" : " ");
	return os;
}
ll ctoi(char c) {
	switch (c) {
	case '0': return 0; case '1': return 1; case '2': return 2;
	case '3': return 3; case '4': return 4; case '5': return 5;
	case '6': return 6; case '7': return 7; case '8': return 8;
	case '9': return 9;  default: return 0;
	}
}
bool pairCompare(const pll firstElof, pll secondElof)
{
	return firstElof.first > secondElof.first;
}
//**Snippetリスト**//
//rep, vin, all, iteLoop, bitSearch, bitList, nod, digitDP, treeDP//
//gcdlcm, isPrime, eratos, primeFactorize, Npow, combination, divisor, modinv, doubling//
//dfs, bfs, dijkstra, WarshallFloyd, BellmanFord, UnionFind, Kruskal, RMQ, LCA//
ll i, j, k, l; ll N, M, K, H, W, L, X, Y, Z, R, Q;
ll MOD = 1000000007, INF = 1LL << 60, ans = 0, z = 0, o = 1;
vll flag, D; vll path;
//***********//
class UnionFind {
public:
	vl rank, par, siz;
	UnionFind() {}
	UnionFind(ll N) {
		rank.resize(N, 0);
		par.resize(N, 0);
		siz.resize(N, 1);
		init(N);
	}
	void init(ll N) {
		for (ll i = 0; i < N; i++) {
			par[i] = i;
			rank[i] = 0;
		}
	}
	ll find(ll x) {
		if (par[x] == x) {
			return x;
		}
		else {
			return par[x] = find(par[x]);
		}
	}
	void unite(ll x, ll y) {
		x = find(x);
		y = find(y);
		if (x != y) {
			if (rank[x] < rank[y]) {
				par[x] = y;
				siz[y] += siz[x];
			}
			else {
				par[y] = x;
				siz[x] += siz[y];
				if (rank[x] == rank[y]) rank[x]++;
			}
		}
	}
	bool issame(ll x, ll y) {
		return find(x) == find(y);
	}
	ll size(ll x) {
		return siz[find(x)];
	}
};
int main() {
	cin >> H >> W;
	vs S(H);
	for (i = 0; i < H; i++) cin >> S[i];
	UnionFind UF(H * W);
	for (i = 0; i < H; i++) {
		for (j = 0; j < W-1; j++) if (S[i][j] != S[i][j + 1]) UF.unite(i * W + j, i * W + j + 1);
	}
	for (j = 0; j < W; j++) {
		for (i = 0; i < H - 1; i++) if (S[i][j] != S[i+1][j]) UF.unite(i * W + j, i * W + j + W);
	}
	map<ll, pll> P;
	for (i = 0; i < H; i++) {
		for (j = 0; j < W; j++) {
			if (S[i][j] == '.') P[UF.find(i * W + j)].first++;
			else P[UF.find(i * W + j)].second++;
		}
	}
	for (auto x : P) ans += x.second.first * x.second.second;
	co(ans);
}

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

char fi[410][410];
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
int h,w;
int vis[410][410];

int main() {

    cin>>h>>w;

    rep(i,h){
        rep(j,w){
            cin>>fi[i][j];
        }
    }

    ll ans=0;
    rep(i,h){
        rep(j,w){
            if(vis[i][j]) continue;
            vis[i][j]=true;
            vector<ll> num(2,0);
            queue<pair<int,int>> que;
            que.push({i,j});

            while (!que.empty())
            {
                auto p=que.front();
                que.pop();
                int x=p.first,y=p.second;
                num[fi[x][y]=='#']++;

                rep(k,4){
                    int nx=x+dx[k];
                    int ny=y+dy[k];
                    if(nx>=0 && nx<h && ny>=0 && ny<w && !vis[nx][ny] && fi[nx][ny]!=fi[x][y]){
                        que.push({nx,ny});
                        vis[nx][ny]=true;
                    }
                }
            }
            ans+=num[0]*num[1];
        }
    }

    cout<<ans<<endl;
}


//#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define trav(x,a) for (const auto& x: a)
#define sz(x) (int)(x).size()
#define mem(a,v) memset((a), (v), sizeof (a))
#define enl printf("\n")
#define case(t) printf("Case #%d: ", (t))
#define ni(n) scanf("%d", &(n))
#define nl(n) scanf("%lld", &(n))
#define nai(a, n) for (int _i = 0; _i < (n); _i++) ni(a[_i])
#define nal(a, n) for (int _i = 0; _i < (n); _i++) nl(a[_i])
#define pri(n) printf("%d\n", (n))
#define prl(n) printf("%lld\n", (n))
#define pii pair<int, int>
#define pll pair<long long, long long>
#define vii vector<pii>
#define vll vector<pll>
#define vi vector<int>
#define vl vector<long long>
#define pb push_back
#define mp make_pair
#define st first
#define nd second
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef cc_hash_table<int,int,hash<int>> ht;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> oset;
const double pi = acos(-1);
const int mod = 1e9 + 7;
const int inf = 1e9 + 7;
const int N = 1e6 + 5;
const double eps = 1e-9;
vi adj[N];
int dp[N], par[N];

int main() {
  int n, m; scanf("%d %d", &n, &m);
  for (int i = 1; i <= m; i++) {
    int u, v; scanf("%d %d", &u, &v);
    adj[u].pb(v);
  }
  int len = inf, idx = -1;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++)
      dp[j] = inf;
    deque<int> pq; pq.pb(i);
    dp[i] = 0;
    int mn = inf;
    while (sz(pq)) {
      int u = pq.front(); pq.pop_front();
      trav(v, adj[u]) {
        if (v == i)
          mn = min(mn, dp[u]+1);
        if (dp[v] > dp[u] + 1) {
          dp[v] = dp[u] + 1;
          pq.pb(v);
        }
      }
    }
    if (mn < len) {
      len = mn, idx = i;
    }
  }
  if (idx < 0)
    return !printf("-1\n");
  for (int j = 1; j <= n; j++)
    dp[j] = inf;
  deque<int> pq; pq.pb(idx);
  dp[idx] = 0;
  int c = 0;
  while (sz(pq)) {
    int u = pq.front(); pq.pop_front();
    c++;
    int d = dp[u];
    if (c == 1)
      dp[u] = inf;
    trav(v, adj[u]) {
      if (dp[v] > d + 1) {
        dp[v] = d + 1;
        par[v] = u;
        pq.pb(v);
      }
    }
  }
  vi ans;
  int u = idx;
  do {
    ans.pb(u);
    u = par[u];
  } while (u != idx);
  printf("%d\n", sz(ans));
  trav(v, ans) printf("%d\n", v);
  return 0;
}

#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
using namespace std;
typedef long long ll;
#define chmin(a,b) a=min(a,b)
#define chmax(a,b) a=max(a,b)
#define all(x) x.begin(),x.end()
#define rep(i,n) for(int i=0;i<n;i++)
#define mod 1000000007
#define mad(a,b) a=(a+b)%mod
#define N 100010
vector<ll> g[N];
ll col[N];
ll cnt;
bool nibu;
void dfs(ll x,ll c){
	if(~col[x]){
		if(c!=col[x])nibu=0;
		return;
	}
	cnt++;
	col[x]=c;
	for(auto y:g[x])dfs(y,c^1);
}
ll n,m;
int main(){
	cin>>n>>m;
	rep(i,m){
		ll a,b; cin>>a>>b;
		a--,b--;
		g[a].push_back(b);
		g[b].push_back(a);
	}
	rep(i,n)col[i]=-1;
	ll nonone=0;
	ll sei=0,nisei=0;
	rep(i,n)if(col[i]==-1){
		cnt=0;
		nibu=1;
		dfs(i,0);
		if(cnt>1){
			nonone+=cnt;
			sei++;
			if(nibu)nisei++;
		}
	}
	ll ans=n*n-nonone*nonone;
	ans+=sei*sei+nisei*nisei;
	cout<<ans<<endl;
}


#include <bits/stdc++.h>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<cstdlib>
#include<string.h>
using namespace std;
#define pb push_back
#define all(v) v. begin(),v. end()
#define  rep(i,n,v) for(i=n;i<v;i++)
#define per(i,n,v) for(i=n;i>v;i--)
#define ff first
#define ss second
#define pp pair<ll,ll>
#define eps 1e-6
#define ll  long long
#define endl '\n'
void solve()
{
  ll n, a,m=0,b=1, k=0, i, j,l=2e9+7;
  string s, r, y;
  cin>>n>>a>>b;
  k=min(n+a,min(n+b,a+b));
  cout<<k;
  /*if(n<a) cout<<0;
  else cout<<10;*/
}
int main()
{
 ios_base::sync_with_stdio(false);
  cin. tie(0);cout. tie(0);
    ll t=1;
 //  cin>>t;
    while(t--)
    {
      solve();
    }
    return 0;
}

#include<iostream>
using namespace std;
int main()
{
    // 整数の入力
    int N, X, T;
    cin >> N >> X >> T;
    // スペース区切りの整数の入力
    int x = N / X * T;
    if ( N % X > 0 ){
      x += T;
    }
    cout << x << endl;

}


#include<bits/stdc++.h>
typedef long double ld;
using namespace std;
int main(void){
  int n; cin>>n;
  vector<pair<ld,ld>> ab(n);
  for(auto& i:ab) cin>>i.first>>i.second;
  ld res=0;
  for(int i=0; i<n; ++i) for(int j=i+1; j<n; ++j){
    ld x=ab[i].first-ab[j].first;
    ld y=ab[i].second-ab[j].second;
    res+=sqrtl(x*x+y*y)*2;
  }
  printf("%.10llf",res/n);
  return 0;
}

#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi=vector<int>;
double dist(int x1,int y1, int x2, int y2){
    return sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));
}
int main() {
    int N; cin>>N;
    vi x(N),y(N);
    for (int i = 0; i < N; i++){
        cin>>x[i]>>y[i];
    }
    vi perm(N);
    for (int i = 0; i < N; i++){
        perm[i]=i;
    }
    double sum=0;
    do{
        for (int i = 0; i < N-1; i++){
            sum+=dist(x[perm[i]],y[perm[i]],x[perm[i+1]],y[perm[i+1]]);
        }
    }while(next_permutation(perm.begin(),perm.end()));
    int fact=1;
    for (int i = 1; i <= N; i++){
        fact*=i;
    }
    printf("%.7f\n",sum/(double)fact);
}


#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin>>n;
  vector<int> a(n);
  vector<int> b(n);
  vector<int> x(n);
  int64_t sb=0;
  for(int i=0;i<n;i++){
    cin>>a.at(i)>>b.at(i);
    x.at(i)=a.at(i)+b.at(i);
    sb+=b.at(i);
  }
  sort(x.begin(),x.end(),greater<int>());
  int64_t sx=0;
  for(int i=0;i<n;i+=2)
    sx+=x.at(i);
  cout<<sx-sb<<endl;
}

#include <stdio.h>
#include <string.h>
#include <limits.h>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <stack>
#include <queue>

typedef unsigned long long ULLONG;
typedef long long LLONG;
static const LLONG MOD_NUM = 1000000007;

template<class _T> static void getint(_T& a) {
	std::cin >> a;
}
template<class _T> static void getint(_T& a, _T& b) {
	std::cin >> a >> b;
}
template<class _T> static void getint(_T& a, _T& b, _T& c) {
	std::cin >> a >> b >> c;
}
template <class _T> static _T tp_abs(_T a) {
	if (a < (_T)0) {
		a *= (_T)-1;
	}
	return a;
}

static void exec();

int main()
{
	exec();
	fflush(stdout);
	return 0;
}

static void exec()
{
	int N;
	getint(N);

	std::vector<std::pair<LLONG, LLONG>> plates(N);
	for (int i = 0; i < N; i++) {
		getint(plates[i].first, plates[i].second);
	}

	std::sort(plates.begin(), plates.end(),
		[](const std::pair<LLONG, LLONG>& a, const std::pair<LLONG, LLONG>& b) {
		return (a.first + a.second) > (b.first + b.second);
	});

	bool tkhs = true;
	std::vector<std::pair<LLONG, LLONG>> tk, ao;
	for (int i = 0; i < N; i++) {
		if (tkhs) {
			tk.push_back(plates[i]);
			tkhs = false;
		}
		else {
			ao.push_back(plates[i]);
			tkhs = true;
		}
	}

	LLONG tkSum = 0;
	for (auto it = tk.begin(); it != tk.end(); it++) {
		tkSum += it->first;
	}
	LLONG aoSum = 0;
	for (auto it = ao.begin(); it != ao.end(); it++) {
		aoSum += it->second;
	}

	printf("%lld\n", tkSum - aoSum);
}


#include<bits/stdc++.h>
#define endl '\n'
#define INF (1 << 21)
const int MOD = 1000000009;
using namespace std;
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n;
  int ice[10];
  int c;

  cin >> n;
  while(n != 0){
    memset(ice, 0, sizeof(ice));
    for(int i = 0;i < n;i++){
      cin >> c;
      ice[c]++;
    }

    for(int i = 0;i <= 9;i++){
      if(ice[i] == 0){
	cout << "-" << endl;
      }else{
	for(int j = 0;j < ice[i];j++){
	  cout << "*";
	}
	cout << endl;
      }
    }

    cin >> n;
  }
  return 0;
}


#include <bits/stdc++.h>
const int INF = 1e9;
const int MOD = 1e9+7;
const long long LINF = 1e18;
#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define rep(i,n) for(ll i=0;i<(n);++i)
#define REPR(i,n) for(ll i=n;i>=0;i--)
#define FOREACH(x,a) for(auto& (x) : (a) )
typedef long long ll;
using namespace std;
typedef pair<ll, ll> P;

template<typename T>
void print(const vector<T> &x) {
    int n = x.size();
    rep(i,n) {
        cout << x[i];
        if (i!=n-1) cout<<" ";
        else cout << endl;
    }
}

template<typename T>
void print(const vector<vector<T>> &x) {
    int n = x.size();
    rep(i,n) {
        rep(j,x[i].size()) {
            cout << x[i][j] << " ";
        }
        cout << endl;
    }
}

template<typename T>
void print(const vector<T> &x, int n) {
    rep(i,n) {
        cout << x[i];
        if (i!=n-1) cout<<" ";
        else cout << endl;
    }
}

template<typename T>
void print(const vector<vector<T>> &x, int n, int m) {
    rep(i,n) {
        rep(j,m) {
            cout << x[i][j] << " ";
        }
        cout << endl;
    }
}

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

void input_init() {
    cin.tie(0); ios::sync_with_stdio(false);
}

int main(int argc, char const *argv[]) {
    int n; cin>>n;
    vector<P> a(n);
    rep(i,n) {
        string s; cin>>s;
        int sum = 0;
        int mini = INF;
        for (auto &&e: s) {
            if (e == '(') sum++;
            else sum--;
            chmin(mini, sum);
        }
        a[i].first = mini;
        a[i].second = sum;
    }

    auto print = [&]() {
        for (auto &&e: a) cout << e.first << ", " << e.second << '\n';
    };

    vector<P> ans;
    sort(a.begin(), a.end(), greater<>());
    for (auto &&e: a) {
        if (e.second >= 0) {
            ans.push_back(e);
        }
    }

    sort(a.begin(), a.end(), [](const P &l, const P &r) {
        return l.second-l.first > r.second-r.first;
    });

    for (auto&&e: a) {
        if (e.second < 0) {
            ans.push_back(e);
        }
    }

    P c;
    bool ok = true;
    for (auto &&e: ans) {
       if (c.second+e.first < 0) ok = false;
       c.second += e.second;
    }

    if (c.second != 0) ok = false;

    if (ok) {
        cout << "Yes" << '\n';
    }
    else {
        cout << "No" << '\n';
    }
    return 0;
}

#include <iostream>
#include <complex>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <numeric>
#include <cstring>
#include <ctime>
#include <cstdlib>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <cmath>
#include <bitset>
#include <cassert>
#include <queue>
#include <stack>
#include <deque>
#include <random>
#include <iomanip>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef pair<ll,ll> P;
const ll MOD=1000000007;
const ll MAX_N=500010;
const ll INF=999999999999;

int main(){
    int n;
    cin>>n;
    vector<int> a(n);
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    vector<int> b(n,0);
    int ans=0;
    for(int i=n-1;i>=0;i--){
        int now=i+1;
        int widt=now;
        int num=0;
        for(;now<=n;now+=widt){
            num+=b[now-1];
        }
        if(num%2==a[i]){
            b[i]=0;
        }else{
            b[i]=1;
            ans++;
        }
    }
    cout<<ans<<endl;
    for(int i=0;i<b.size();i++){
        if(b[i]) cout<<i+1<<" ";
    }
    cout<<endl;

}


#include <bits/stdc++.h>

using namespace std;

int main()
{
	int D, G;
	cin >> D >> G;
	vector < int >p(D), c(D);
	for (int i = 0; i < D; i++) {
		cin >> p[i] >> c[i];
	}

	int ans = INT_MAX;
	for (int bits = 0; bits < (1 << D); bits++) {
		int score = 0;
		int num = 0;
		int resultMax = -1;
		for (int i = 0; i < D; i++) {
			if (bits >> i & 1) {
				score += 100 * (1 + i) * p[i] + c[i];
				num += p[i];
			} else {
				resultMax = i;
			}
		}

		if (score < G) {
			int s1 = 100 * (resultMax + 1);
			int need = (G - score + s1 - 1) / s1;
			if (need >= p[resultMax]) {
				continue;
			}
			num += need;
		}
		ans = min(ans, num);
	}

	cout << ans << endl;

	return 0;
}

#include<bits/stdc++.h>
using namespace std;
template<class T> void chmax(T& x, T y){if(x < y) x = y;}
template<class T> void chmin(T& x, T y){if(x > y) x = y;}
int N, M;
int A[310][310];
int cnt[310];
bool hold[310];
int idx[310];

int solve(){
    bool flag = false;
    for(int i = 1; i <= M; i++){
        if(hold[i]) flag = true;
    }
    if(!flag) return 1 << 30;

    for(int i = 1; i <= N; i++){
        if(hold[A[i][idx[i]]]) continue;
        for(int& j = idx[i]; j <= M; j++){
            if(hold[A[i][j]]){
                cnt[A[i][j]]++;
                break;
            }
        }
    }

    int mx = 0;
    for(int i = 1; i <= M; i++){
        chmax(mx, cnt[i]);
    }
    set<int> h;
    for(int i = 1; i <= M; i++){
        if(cnt[i] == mx){
            h.insert(i);
            hold[i] = false;
            cnt[i] = 0;
        }
    }
    return min(solve(), mx);
}

int main(){
    cin >> N >> M;
    for(int i = 1; i <= N; i++){
        for(int j = 1; j <= M; j++){
            cin >> A[i][j];
        }
    }
    for(int i = 1; i <= M; i++){
        hold[i] = true;
    }
    cout << solve() << endl;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
constexpr int Inf = 1000000001;
constexpr ll INF= 1e18;
constexpr ll MOD = 1000000007;
const double PI = 3.1415926535897;
typedef pair<int,int> P;

int main() {
    int N;
    cin >> N;
    string A,B,C;
    cin >> A >> B >> C;
    int ret = 0;
    for(int i = 0;i < N;i++) {
        if(A.at(i) == B.at(i) && B.at(i) == C.at(i)) {
            ret = ret;
        }
        else if(A.at(i) == B.at(i)) {
            ret++;
        }
        else if(B.at(i) == C.at(i)) {
            ret++;
        }
        else if(A.at(i) == C.at(i)) {
            ret++;
        }
        else {
            ret += 2;
        }
    }
    cout << ret << endl;
}

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

int main() {
  ll n;
  cin >> n;
  vector<string> s(3);
  for(ll i=0;i<3;i++) {
    cin >> s[i];
  }
  ll ans=0;
  for(ll i=0;i<n;i++) {
    set<char> ss;
    for(ll j=0;j<3;j++) {
      ss.insert(s[j][i]);
    }
    ans+=ss.size()-1;
  }
  cout << ans << endl;
}


#include <iostream>
#include <vector>

using namespace std;

typedef pair<int, bool> Link;
typedef vector<vector<Link> > Graph;

int main () {
    int V, E;
    cin >> V >> E;
    Graph g(V, vector<Link>(V));

    // Set identity to 0
    for(int i=0; i<V; i++)
        g[i][i] = make_pair(0, true);

    // Set known edges
    for(int i=0; i<E; i++) {
        int s, t, d;
        cin >> s >> t >> d;
        g[s][t] = make_pair(d, true);
    }

    // Run Floyd-Warshall algorithm
    for(int k=0; k<V; k++)
        for(int i=0; i<V; i++)
            for(int j=0; j<V; j++)
                if (
                        (g[i][k].second && g[k][j].second) &&
                        (!g[i][j].second || g[i][j].first > g[i][k].first + g[k][j].first))
                    g[i][j] = make_pair(g[i][k].first + g[k][j].first, true);

    // Check if any cycle
    for(int i=0; i<V; i++)
        if (g[i][i].first < 0) {
            cout << "NEGATIVE CYCLE" << endl;
            return 0;
        }

    // Print output
    for(int i=0; i<V; i++) {
        for(int j=0; j<V; j++)
            if (g[i][j].second)
                cout << (j ? " " : "") <<  g[i][j].first;
            else
                cout << (j ? " " : "") << "INF";
        cout << endl;
    }
}

#include<bits/stdc++.h>
using namespace std;
int N,M;

int main()
{
	while(true){
		scanf("%d%d",&N,&M);
		if(N==0&&M==0)return 0;
		int cost[200][200];
		int time[200][200];
		int minc[200][200];
		int mint[200][200];
		for(int i=0;i<M;i++){
			for(int j=0;j<M;j++){
				cost[i][j]=1<<25;
				time[i][j]=1<<25;
				minc[i][j]=1<<25;
				mint[i][j]=1<<25;
				if(i==j){
					cost[i][j]=0;
					time[i][j]=0;
					minc[i][j]=0;
					mint[i][j]=0;
				}
			}
		}
		int A,B,co,ti;
		for(int i=0;i<N;i++){
			scanf("%d%d%d%d",&A,&B,&co,&ti);A--;B--;
			cost[A][B]=co;cost[B][A]=co;
			time[A][B]=ti;time[B][A]=ti;
		}
		for(int i=0;i<M;i++){
			for(int j=0;j<M;j++){
				for(int k=0;k<M;k++){
					cost[j][k]=min(cost[j][k],cost[j][i]+cost[i][k]);
					time[j][k]=min(time[j][k],time[j][i]+time[i][k]);
				}
			}
		}

		int K;
		scanf("%d",&K);
		for(int i=0;i<K;i++){
			int P,Q,R;
			scanf("%d%d%d",&P,&Q,&R);P--;Q--;
			if(R==0)printf("%d\n",cost[P][Q]);
			else printf("%d\n",time[P][Q]);
		}
	}
}


#include<iostream>
#include<string>
#include<vector>
#include<cstdio>
#include<sstream>
#include<algorithm>
#include<cmath>
#include<map>
using namespace std;
int main(){
int n, dp[50];
while(cin>>n,n!=0){
fill(dp,dp+50,0);
dp[0]=0,dp[1]=1,dp[2]=1,dp[3]=2;
for(int i=3;i<=n+1;i++)dp[i]=dp[i-1]+dp[i-2]+dp[i-3];
int ans=dp[n+1];
ans/=3650;
if(dp[n]%3650!=0)ans++;
cout<<ans<<endl;
}
return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define mp make_pair
#define pb push_back
#define x first
#define y second
typedef pair<int,int> pii;
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ldb;
template <typename T> void chkmax(T &x,T y){x<y?x=y:T();}
template <typename T> void chkmin(T &x,T y){x>y?x=y:T();}
template <typename T> bool readint(T &x)
{
	x=0;int f=1;char c;
	for(c=getchar();!isdigit(c);c=getchar())if(c=='-')f=-1;
	for(;isdigit(c);c=getchar())x=x*10+c-'0';
	x*=f;
	return c=='.';
}
const int MAXN=200005;

int n;
ll a[MAXN];
pii b[MAXN];
int cnt[100][100];

int main()
{
	#ifdef LOCAL
	freopen("code.in","r",stdin);
//	freopen("code.out","w",stdout);
	#endif
	readint(n);
	int s=0;
	for(int i=1;i<=n;++i)
	{
		ldb d;
		scanf("%Lf",&d);
		a[i]=d*1000000000+0.5;
		while(a[i]%2==0)a[i]>>=1,++b[i].x;
		while(a[i]%5==0)a[i]/=5,++b[i].y;
		++cnt[b[i].x][b[i].y];
		if(b[i].x>=9 && b[i].y>=9)++s;
	}
	sort(b+1,b+n+1);
	ll ans=0;
	for(int i=0;i<=55;++i)
		for(int j=0;j<=55;++j)
			for(int x=0;x<=55;++x)
				for(int y=0;y<=55;++y)
					if(i+x>=18 && j+y>=18)
						ans+=1ll*cnt[i][j]*cnt[x][y];
	printf("%lld\n",(ans-s)/2);
	return 0;
}


#include<iostream>
#include<algorithm>
using namespace std;
int main(){
	int a,b,l=100,s=0;
	for(int i=0;i<4;i++){
		cin>>a;
		s+=a;
		l=min(a,l);
	}
	cin>>a>>b;
	cout<<s-l+max(a,b)<<endl;
	return 0;
}

#include <bits/stdc++.h>

using namespace std;

vector<int> SubjectsInfo;

int main() {
	int score;

	for (int i = 0; i < 6; ++i) {
		cin >> score;
		SubjectsInfo.push_back(score);
	}
	sort(SubjectsInfo.begin(), SubjectsInfo.begin() + 4);
	cout << SubjectsInfo[1] + SubjectsInfo[2] + SubjectsInfo[3] + max(SubjectsInfo[4], SubjectsInfo[5]) << endl;

	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main(){
  string S; cin>>S;
  if(S.size()==2)
    cout<<S<<endl;
  else
    cout<<S.at(2)<<S.at(1)<<S.at(0)<<endl;
}

const int LG = 21;
const int FN = 400005;
const long long MOD = 1e9 + 7;
const long long INF = 1e9;
const long long INFLL = 1e18;

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vector<int> > G;

#define forn(i, n) for (int (i) = 0; (i) != (n); (i)++)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define popcount(x) __builtin_popcount(x)
#define popcountll(x) __builtin_popcountll(x)
#define fi first
#define se second
#define re return
#define pb push_back
#define uniq(x) sort(all(x)); (x).resize(unique(all(x)) - (x).begin())

#ifdef LOCAL
#define dbg(x) cerr << __LINE__ << " " << #x << " " << x << endl
#define ln cerr << __LINE__ << endl
#else
#define dbg(x) void(0)
#define ln void(0)
#endif // LOCAL

int cx[4] = {-1, 0, 1, 0};
int cy[4] = {0, -1, 0, 1};
string Ans[2] = {"No", "Yes"};
string ANS[2] = {"NO", "YES"};

ll inq(ll x, ll y)
{
    if (!y) re 1 % MOD;
    ll l = inq(x, y / 2);
    if (y % 2) re l * l % MOD * x % MOD;
    re l * l % MOD;
}

ll rev(ll x)
{
    return inq(x, MOD - 2);
}

bool __precomputed_combinatorics = 0;
vector<ll> __fact, __ufact, __rev;

void __precompute_combinatorics()
{
    __precomputed_combinatorics = 1;
    __fact.resize(FN);
    __ufact.resize(FN);
    __rev.resize(FN);
    __rev[1] = 1;
    for (int i = 2; i < FN; i++) __rev[i] = MOD - __rev[MOD % i] * (MOD / i) % MOD;
    __fact[0] = 1, __ufact[0] = 1;
    for (int i = 1; i < FN; i++) __fact[i] = __fact[i - 1] * i % MOD, __ufact[i] = __ufact[i - 1] * __rev[i] % MOD;
}

ll fact(int x)
{
    if (!__precomputed_combinatorics) __precompute_combinatorics();
    return __fact[x];
}

ll cnk(int n, int k)
{
    if (k < 0 || k > n) return 0;
    if (!__precomputed_combinatorics) __precompute_combinatorics();
    return __fact[n] * __ufact[n - k] % MOD * __ufact[k] % MOD;
}

int Root(int x, vector<int> &root)
{
    if (x == root[x]) return x;
    return root[x] = Root(root[x], root);
}

void Merge(int v, int u, vector<int> &root, vector<int> &sz)
{
    v = Root(v, root), u = Root(u, root);
    if (v == u) return;
    if (sz[v] < sz[u])
    {
        sz[u] += sz[v];
        root[v] = u;
    }
    else
    {
        sz[v] += sz[u];
        root[u] = v;
    }
}

int ok(int x, int n)
{
    return 0 <= x && x < n;
}

void bfs(int v, vi &dist, vector<vi> &graph)
{
    fill(all(dist), -1);
    dist[v] = 0;
    vi q = {v};
    for (int i = 0; i < q.size(); i++)
    {
        for (auto u : graph[q[i]])
        {
            if (dist[u] == -1)
            {
                dist[u] = dist[q[i]] + 1;
                q.push_back(u);
            }
        }
    }
}

int t;

void dfs(int v, int p, G &graph, vi &in, vi &up)
{
    up[v] = in[v] = t;
    t++;
    for (auto u : graph[v])
    {
        if (u == p) continue;
        if (in[u] == 0)
        {
            dfs(u, v, graph, in, up);
        }
        up[v] = min(up[v], up[u]);
    }
}

signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    string s;
    cin >> s;
    if (s.size() == 3) reverse(all(s));
    cout << s;
}

/* Note:
Check constants at the beginning of the code.
    N is set to 4e5 but be careful in problems with large constant factor.
    Setting N in every problem is more effective.
Check corner cases.
    N = 1
No def int long long for now.
Add something here.
*/


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

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    string S; cin >> S;
    int ok=0;
    for (int i=0;i+1<S.size();++i)
        if (S[i]=='A'&&S[i+1]=='C') ok=1;
    cout << (ok?"Yes":"No") << '\n';
}

#include<iostream>
using namespace std;
int main(){
    int x;
    cin>>x;
    int temp=x;
    int sum=0;
    while(temp!=0)
    {
        sum+=temp%10;
        temp/=10;
    }
    if(x%sum==0)
    {
        cout<<"Yes";
    }
    else
    cout<<"No";
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define mp make_pair
#define all(z) (z).begin(),(z).end()
#define MOD 1000000007
#define FAST ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
ll isprime(ll n)
{
	for(int i=2;i<n;i++)
		if(n%i==0)
		return 0;

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

}

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

using ll = long long;

int main() {
    int d, t, s;
    cin >> d >> t >> s;
    string ans = "Yes";
    if (s * t < d) ans = "No";
    cout << ans << endl;
}


#include<iostream>
#include<math.h>
using namespace std;
class Xcubic{
public:
  int cal(int x){
    int res=(int)pow(x,3);
    return res;
  }
};
int main(){
  int x;
  cin>>x;
  Xcubic xcubic;
  cout<<xcubic.cal(x)<<endl;
  return 0;
}

#include<iostream>
#include<iomanip>
using namespace std;
int main(void){
      int x;
       cin >> x;
       cout << x*x*x <<"\n";
    return 0;
}


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

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

  if(S == "SSS") cout << "0" << endl;
  else if(S == "RRR") cout << "3" << endl;
  else if(S == "SRR" || S == "RRS") cout << "2" << endl;
  else cout << "1" << endl;
}

#include<iostream>
#include<cstring>

using namespace std;

char str[1010];

int main(){
    scanf("%s",str);
    int len=strlen(str);
    int res=0;
    for(int i=0;i<len;++i){
        int cnt=0;
        while(i<len&&str[i]=='R'){
            cnt++;
            i++;
        }
        res=max(cnt,res);
    }
    cout<<res<<endl;
    return 0;
}


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

int main() {
	while (1) {
		int a;
		cin >> a;
		if (a == 0)break;
		for (int b = 0; b < a; b++) {
			int  c, d, e;
			cin >> c >> d >> e;
			if (c == 100 || d == 100 || e == 100)cout << "A" << endl;
			else if (c+d>179)cout << "A" << endl;
			else if(c+d+e>239)cout << "A" << endl;
			else if(c+d+e>209)cout << "B" << endl;
			else if((c+d+e>149)&&(c>79||d>79))cout << "B" << endl;
			else cout << "C" << endl;
		}
   }
}

#include <iostream>
#include <algorithm>
using namespace std;
int mp[101][101];
bool flg[101] ={};
int n,q;
int dis[101];

int sssp(int s,int g) {
  for(int i=1;i<=n;i++) dis[i] = 1000000000,flg[i] = 0;
  //flg[s] = 1;
  dis[s] = 0;
  int ima;

  while(1) {
    int mindis = 1000000000;

    for(int i=1;i<=n;i++)
      if(mindis > dis[i] && flg[i] == 0) {
	ima = i;
	mindis = dis[i];
      }

    if(mindis == 1000000000) return -1;
    flg[ima] = 1;
    if(ima == g) return dis[ima];

    for(int i=1;i<=n;i++)
      if(dis[i] >dis[ima] + mp[ima][i] && mp[ima][i] != -1)
	dis[i] = dis[ima]+mp[ima][i];

  }

  return dis[g];
}

int main() {

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

  for(int i=0;i<=n;i++){
    //    dis[i] = 1000000000;
    //flg[i] = 0;
    for(int j=0;j<=n;j++)
      mp[i][j] = -1;
  }

  bool sta;
  int s,g,c;
  for(int i=0;i<q;i++) {
    cin >> sta;
    if(sta == 0) {
      cin  >> s >> g;
      //for(int i=1;i<=n;i++) if(mp[s][i] !=-1)dis[i] = mp[s][i];
      int ans = sssp(s,g);
      cout << ans<< endl;
    }
    else {
      cin >> s >> g >> c;
      if(mp[s][g] != -1) {
	mp[s][g] = min(c ,mp[s][g]);
	mp[g][s] = min( mp[g][s] ,c);
      }
      else {
	mp[s][g] = c;
	mp[g][s] = c;
      }

    }
  }
  }

  return 0;

  }


#include <bits/stdc++.h>

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

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

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

int A, B, C, D, E, K;
vector<int> a;

int main() {
    cin >> A >> B >> C >> D >> E >> K;
    a.push_back(A); a.push_back(B); a.push_back(C); a.push_back(D); a.push_back(E);
    bool istrue = true;
    for (int i=0; i<a.size(); i++) {
        for (int j=i+1; j<a.size(); j++) {
            if (abs(a[i] - a[j]) > K) { istrue = false; break; }
        }
    }
    istrue ? cout << "Yay!\n" : cout << ":(\n";
    return 0;
}


#include <iostream>
#include <string>
using namespace std;
class Dice{
public:
    int n1,n2,n3,n4,n5,n6;

    void East(){
        int t = n1;
        n1 = n4;
        n4 = n6;
        n6 = n3;
        n3 = t;
    }
    void West(){
        int t = n1;
        n1 = n3;
        n3 = n6;
        n6 = n4;
        n4 = t;
    }
    void South(){
        int t=n1;
        n1 = n5;
        n5 = n6;
        n6 = n2;
        n2 = t;
    }
    void North(){
        int t=n1;
        n1 = n2;
        n2 = n6;
        n6 = n5;
        n5 = t;
    }
};

int main() {
    Dice dice;
    int n1, n2, n3, n4, n5, n6;
    char ch;
    cin >> n1 >> n2 >> n3 >> n4 >> n5 >> n6;
    dice.n1 = n1;
    dice.n2 = n2;
    dice.n3 = n3;
    dice.n4 = n4;
    dice.n5 = n5;
    dice.n6 = n6;
    while(cin >> ch){
        if(ch=='E'){
            dice.East();
        }
        else if(ch=='W'){
            dice.West();
        }
        else if(ch=='S'){
            dice.South();
        }
        else if(ch=='N'){
            dice.North();
        }
    }
    cout << dice.n1 << endl;
    return 0;
}

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

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

string str;
int ans;

class dice{
public:
	int n[6];
	void E(){
		int t = n[0];
		n[0] = n[3];
		n[3] = n[5];
		n[5] = n[2];
		n[2] = t;
	}
	void W(){
		int t = n[0];
		n[0] = n[2];
		n[2] = n[5];
		n[5] = n[3];
		n[3] = t;
	}
	void S(){
		int t = n[0];
		n[0] = n[4];
		n[4] = n[5];
		n[5] = n[1];
		n[1] = t;
	}
	void N(){
		int t = n[0];
		n[0] = n[1];
		n[1] = n[5];
		n[5] = n[4];
		n[4] = t;
	}
};

int main(){
	dice d;
	rep(i, 6) cin >> d.n[i];
	cin >> str;
	ans = d.n[0];
	rep(i, str.length()){
		switch (str[i])
		{
		case 'E':
			d.E();
			break;
		case 'W':
			d.W();
			break;
		case 'S':
			d.S();
			break;
		case 'N':
			d.N();
			break;
		default:
			break;
		}
	}
	cout << d.n[0] << endl;
	return 0;
}


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

signed main()
{
  double x1, x2, y1, y2;

  cin >> x1 >> y1 >> x2 >> y2;
  cout << fixed << setprecision(10) << sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2)) << endl;

  return (0);
}

#include<stdio.h>

int main()
{
	int x,y,z;
	scanf("%d %d %d",&x,&y,&z);
	if (x>9 || x<1 || y>9 || y<1 || z>9 || z<1)
	{
		printf("Error!");
	}
	else if( x == y && y == z && x == z){
		printf("No");
	}
	else if (x == z || x == y || y == z){
		printf("Yes");
	}
	else if (x>y || z>x || y>z){
		printf("No");
	}
}


#include<iostream>
using namespace std;

const int INF = 2000000;

struct LineTable{
  int cost;
  int times;
  LineTable(){
    cost = INF;
    times = INF;
  }
};

int main(){

    int n,m;
    while(1){
      cin >> n >> m;
      if(n==0&&m==0){
        break;
      }
      LineTable table[m][m];

      for(int i=0;i<m;i++){
        table[i][i].cost = 0;
        table[i][i].times = 0;
      }

      for(int i=0;i<n;i++){
        int a,b,cost,times;
        cin >> a >> b >> cost >> times;
        table[a-1][b-1].cost = cost;
        table[a-1][b-1].times = times;
        table[b-1][a-1].cost = cost;
        table[b-1][a-1].times = times;
      }

      for(int k=0;k<m;k++){
        for(int i=0;i<m;i++){
          for(int j=0;j<m;j++){
            if(table[i][j].cost > table[i][k].cost + table[k][j].cost){
              table[i][j].cost = table[i][k].cost + table[k][j].cost;
            }
          }
        }
      }

      for(int k=0;k<m;k++){
        for(int i=0;i<m;i++){
          for(int j=0;j<m;j++){
            if(table[i][j].times > table[i][k].times + table[k][j].times){
              table[i][j].times = table[i][k].times + table[k][j].times;
            }
          }
        }
      }

/*      for(int k=m-1;k>=0;k--){
        for(int i=m-1;i>=0;i--){
          for(int j=m-1;j>=0;j--){
            if(table[i][j].cost > table[i][k].cost + table[k][j].cost){
              table[i][j].cost = table[i][k].cost + table[k][j].cost;
            }
          }
        }
      }

      for(int k=m-1;k>=0;k--){
        for(int i=m-1;i>=0;i--){
          for(int j=m-1;j>=0;j--){
            if(table[i][j].times > table[i][k].times + table[k][j].times){
              table[i][j].times = table[i][k].times + table[k][j].times;
            }
          }
        }
      }*/

      int k,p,q,r;
      cin >> k;
      /*cin >> p >> q >> r;
      if(r==0){
        cout << table[p-1][q-1].cost;
      }
      else{
        cout << table[p-1][q-1].times;
      }
      for(int i=1;i<k;i++){
        cin >> p >> q >> r;
        if(r==0){
          cout << ' ' <<table[p-1][q-1].cost;
        }
        else{
          cout << ' ' <<table[p-1][q-1].times;
        }
      }
      cout << endl;*/

      for(int i=0;i<k;i++){
        cin >> p >> q >> r;
        if(r==0){
          cout << table[p-1][q-1].cost << endl;;
        }
        else{
          cout << table[p-1][q-1].times << endl;
        }
      }
    }
    return 0;
}

#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
struct Graph{
  Graph(int n):E(n),d(n){}
  vector<vector<tuple<int,int,int>>>E;
  vector<int>d;
  void add_edge(int a,int b,int c,int d){
    E[a].push_back(make_tuple(b,c,d));
  }
  void dijkstra(int s,int f){
    priority_queue<P,vector<P>,greater<P>>q;
    fill(d.begin(),d.end(),1e9);
    q.push({d[s]=0,s});
    while(q.size()){
      auto p=q.top();q.pop();
      if(p.first>d[p.second])continue;
      for(auto& a:E[p.second]){
        int x=get<0>(a),y=get<1>(a)+p.first;
        if(f)y=get<2>(a)+p.first;
        if(y<d[x])d[x]=y,q.push({y,x});
      }
    }
  }
};
main(){
  int n,m,a,b,c,d,k;
  while(cin>>n>>m,n){
    Graph E(m);
    for(int i=0;i++<n;E.add_edge(--a,--b,c,d),E.add_edge(b,a,c,d))cin>>a>>b>>c>>d;
    cin>>k;
    for(int i=0;i++<k;cout<<E.d[--b]<<endl){
      cin>>a>>b>>c;
      E.dijkstra(--a,c);
    }
  }
}


#include <bits/stdc++.h>
#define ll long long int
using namespace std;
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	ll a;
	ll b;
	ll c;
	cin>>a;
	cin>>b;
	cin>>c;
	if((a==b)&&(b==c))
	{
		cout<<"No"<<"\n";
	}
	else if((a!=b)&&(b!=c)&&(c!=a))
	{
		cout<<"No"<<"\n";
	}
	else
	{
		cout<<"Yes"<<"\n";
	}
	return 0;
}

#include <bits/stdc++.h>
#include <iostream>
#include <algorithm>
#include <ctype.h>
#include <math.h>
#include <stack>
#include <string>
#include <string.h>
using namespace std;
double PI = 3.1415926535897932;
long mod = 1000000007;

const long INF = 1e9 + 1;

int main() {
  int a[3];
  cin >> a[0] >> a[1] >> a[2];
  sort(a,a+3);
  if(a[0] == a[1] & a[1] == a[2]) cout << "No" << endl;
  else if(a[0] != a[1] & a[1] != a[2]) cout << "No" << endl;
  else if(a[0] == a[1] & a[1] != a[2]) cout << "Yes" << endl;
  else if(a[0] != a[1] & a[1] == a[2]) cout << "Yes" << endl;
}


#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(), (x).end()
#define SZ(X) ((int)(X).size())
#define endl "\n";
int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
    int n,a[9]={111,222,333,444,555,666,777,888,999};
    cin>>n;
    for(int i=0;i<9;i++){
    	if(n<=a[i]) {
	cout<<a[i]<<endl;
	return 0;
	}

    }

   return 0;
}

#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = a; i < n; i++)
#define repr(i, a, n) for (int i = n - 1; i >= a; i--)
using namespace std;
using ll = long long;
using P = pair<int, int>;
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chmax(T &a, T b) { a = max(a, b); }

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

  int n;
  cin >> n;
  cout << ((n + 110) / 111) * 111 << endl;
}


#include <bits/stdc++.h>

using namespace std;

const int INF=INT_MAX;

struct lst
{
    private:
        int n;
        vector<int> node;
        vector<int> lazy;
        vector<bool> lflg;
    public:
        lst(int sz)
        {
            n=1; while(n<sz) n*=2;
            node.resize(2*n-1, INF);
            lazy.resize(2*n-1, 0);
            lflg.resize(2*n-1, false);
        }
    void lazy2node(int k, int l, int r)
    {
        if(lflg[k])
        {
            node[k]=lazy[k];
            lflg[k]=false;
            prop(k, l, r);
        }
    }
    void prop(int k, int l, int r)
    {
        if (r-l>0)
        {
            lazy[2*k+1]=lazy[2*k+2]=node[k];
            lflg[2*k+1]=lflg[2*k+2]=true;
        }
    }

    void update(int qa, int qb, int v, int k=0, int l=0, int r=-1)
    {
        if(r<0) r=n-1;
        lazy2node(k, l, r);
        if(qb<l || r<qa) return;
        if(qa<=l && r<=qb)
        {
            node[k] = v;
            prop(k, l, r);
        }
        else
        {
            int m=(l+r)/2;
            update(qa, qb, v, 2*k+1, l, m);
            update(qa, qb, v, 2*k+2, m+1, r);
        }
    }

    int get(int qa, int qb, int k=0, int l=0, int r=-1)
    {
        if(r<0) r=n-1;
        lazy2node(k, l, r);
        if(qb<l || r<qa) return INF;
        if(qa<=l && r<=qb) return node[k];
        else
        {
            int m=(l+r)/2;
            int lv = get(qa, qb, 2*k+1, l, m);
            int lr = get(qa, qb, 2*k+2, m+1, r);
            return min(lv, lr);
        }
    }
};

int main()
{
    int n, q;
    scanf("%d %d", &n, &q);
    lst tree = lst(n);
    for(int i=0; i<q; i++)
    {
        int t;
        scanf("%d", &t);
        if(t)
        {
            int s;
            scanf("%d", &s);
            printf("%d\n", tree.get(s,s));
        }
        else
        {
            int s, t, v;
            scanf("%d %d %d", &s, &t, &v);
            tree.update(s, t, v);
        }
    }
    return 0;
}


#include <iostream>
#include <iomanip>
#include <algorithm>
#include <bitset>
#include <string>
#include <cmath>
#include <complex>
#include <numeric>
#include <cassert>

#include <vector>
#include <array>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <utility>

#define int64 long long
#define uint64 unsigned long long
using namespace std;

int main()
{
	int64 nn, mm, dd;
	long double ans = 0.0;
	cin >> nn >> mm >> dd;
	if(dd == 0)
	{
		ans += (long double)(mm - 1) / (long double)nn;
	}
	else
	{
		ans += (long double)(mm - 1) * 2.0 * (long double)(nn - dd) / (long double)(nn * nn);
	}
    cout << fixed << setprecision(20);
	cout << ans << endl;
	return 0;
}

#include<bits/stdc++.h>
using namespace std;
#define FOR(i,l,r) for(long long i=(l);i<(r);++i)
#define REP(i,n) FOR(i,0,n)
#define REPS(i,n) FOR(i,1,n+1)
#define RFOR(i,l,r) for(long long i=(l);i>=(r);--i)
#define RREP(i,n) RFOR(i,n-1,0)
#define RREPS(i,n) RFOR(i,n,1)
#define int long long
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define SZ(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
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; }
const int INF = 1e18;

signed main(){
    double n, m, d; cin >> n >> m >> d;
    double ans = max(n-d,0.0)*(d !=0 ? 2 : 1) / (n*n) * (m-1);
    cout << fixed << setprecision(20.20) << ans << endl;
}


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

#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()

typedef long long ll;
typedef array<int, 3> tri;
typedef long double ld;

template <class T> istream& operator>>(istream& I, vector<T>& v) {for (T &e: v) I >> e; return I;}
template <class T> ostream& operator<<(ostream &O, const vector<T>& v) {for (const T &e: v) O << e << ' '; return O;}

void _main() {
        int n; cin >> n;
        map<int, int> freq;
        while (n--) {
                int a; cin >> a;
                freq[a]++;
        }

        vector<int> candidates;
        for (const auto it: freq) {
                if (it.second >= 2) candidates.emplace_back(it.first);
                if (it.second >= 4) candidates.emplace_back(it.first);
        }

        sort(all(candidates), greater<>());
        if (candidates.size() < 2) cout << 0;
        else cout << (ll) candidates[0] * candidates[1];
}

signed main() {
        ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
//        freopen("input.txt", "r", stdin);
        int _t = 1;
//        cin >> _t;
        while (_t--) _main();
        return 0;
}

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

#define print cout <<
#define printl(s) cout << s << endl;
#define rep(i,n) for (int i = 0; i < (n); ++i)
using ll = long long;

const ll modseed = pow(10,9) + 7;

template <typename T>
vector<T> getValues(int num){
    vector<T> values(num);
    for(int i=0;i<num;i++){
        cin >> values.at(i);
    }
    return values;
}

int calcDigit(ll N){
  int digit = 0;
  while(N>0){
    N/= 10;
    digit++;
  }
  return digit;
}

int main(){
  ll N;
  cin >> N;
  int ans = calcDigit(N);
  for(ll A=1;A*A<=N;A++){
    if(N%A!=0){
      continue;
    }
    ll B = N /A;
    int tmp = max(calcDigit(A),calcDigit(B));
    if(ans > tmp){
      ans = tmp;
    }
  }
  printl(ans);
}


#include<iostream>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<utility>
#include<vector>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<time.h>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
#define rp(a) while(a--)
#define pb push_back
#define mp make_pair
#define all(in) in.begin(),in.end()
const double PI=acos(-1);
const double EPS=1e-10;
using namespace std;
typedef long long ll;
typedef vector<int> vi;
int main(){
	int n;
	cin>>n;
	string s;
	getline(cin,s);
	while(n--){
		getline(cin,s);
		if(s.size()>6)rep(i,s.size()-6)if(s.substr(i,7)=="Hoshino")s[i+6]='a';
		cout<<s<<endl;
	}
}

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

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


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

using std::cin;
using std::cout;
using std::endl;

char encode(char c, int n) {
	char ret = c;
	for (int i = 0; i < n; i++) {

		if (ret == 'a') {
			ret = 'Z';
		}
		else if (ret == 'A') {
			ret = 'z';
		}
		else {
			ret -= 1;
		}
	}
	return ret;
}

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

	while (n != 0) {
		std::vector<int> k(n);
		std::string str;
		for (int i = 0; i < n; i++) {
			cin >> k[i];
		}

		cin >> str;

		for (int i = 0; i < str.length(); i++) {
			cout << encode(str[i], k[i%n]);
		}
		cout << endl;

		cin >> n;
	}

	return 0;
}

#include<iostream>
using namespace std;
#define MAX 100
#define BLANK 0
#define LONG 4
#define SHORT 2
#define HORIZONTAL 0
#define VERTICAL 1
#define VISITED 9

int field[MAX+2][MAX+2];
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
void rec(int x,int y,int c)
{
  int i;
  if(field[x][y]!=c)return;
  field[x][y]=VISITED;
  for(i=0;i<4;i++)rec(x+dx[i],y+dy[i],c);
  return;
}

int main()
{
  int w,h,xs,ys,xg,yg,n,c,d,x,y;
  int i,j;
  while(cin>>w>>h>>xs>>ys>>xg>>yg>>n,w|h){
    for(j=1-1;j<=h+1;j++)for(i=1-1;i<=w+1;i++)field[i][j]=BLANK;
    while(n-->0){
      cin>>c>>d>>x>>y;
      if(d==HORIZONTAL)
	for(i=0;i<LONG;i++)for(j=0;j<SHORT;j++)field[x+i][y+j]=c;
      else
	for(i=0;i<SHORT;i++)for(j=0;j<LONG;j++)field[x+i][y+j]=c;
    }
    if(field[xs][ys]!=BLANK)rec(xs,ys,field[xs][ys]);
    puts(field[xg][yg]==VISITED?"OK":"NG");
  }
}


#include<bits/stdc++.h>

using namespace std;
using ll = long long;

/***********debug tools***********/
template<class T> inline ostream& operator<<(ostream& os,vector<T> arr) {os << "["; for(int i = 0; i < (int)arr.size(); i++)os << arr[i] << (i == (int)arr.size() - 1 ? "]" : ",");os << endl;return os;}
template<typename A, typename B> ostream& operator<<(ostream& os, const pair<A,B>& p){os << "{" << p.first << "," << p.second << "}";return os; }
#define prvec(v) cerr<<#v<<": [";for(int __i = 0;__i < (int)(v).size(); __i++)cerr<<((v)[__i])<<(__i+1==(int)(v).size()?"]\n":",");
#define print(x) cerr<<#x<<": "<<(x)<<endl
/*********************************/

const int D = 30;
const int MAX_N = 100000;

int n, l;
vector<int> x;
vector<vector<int>> tor, tol;

void ftor() {
    for(int i = 0; i < n; i++) {

        int L = i + 1, R = n; //ooooxxx
        while(R - L > 1) {
            int mid = (L + R) / 2;
            (x[mid] - x[i] <= l ? L : R) = mid;
        }
        tor[0][i] = L;
    }
    tor[0][n - 1] = n - 1;

    for(int i = 0; i < D - 1; i++) {
        for(int j = 0; j < n; j++) {
            tor[i + 1][j] = tor[i][tor[i][j]];
        }
    }

}

void ftol() {
    for(int i = 1; i < n; i++) {
        int L = -1, R = i - 1;//xxxxxoooo
        while(R - L > 1) {
            int mid = (L + R) / 2;
            (x[i] - x[mid] <= l ? R : L) = mid;
        }
        tol[0][i] = R;
    }
    tol[0][0] = 0;
    for(int i = 0; i < D - 1; i++) {
        for(int j = 0; j < n; j++) {
            tol[i + 1][j] = tol[i][tol[i][j]];
        }
    }

}

int main()
{
    cin >> n;
    x.resize(n), tor.resize(D, vector<int>(n));
    tol = tor;
    for(int i = 0; i < n; i++)cin >> x[i];
    cin >> l;
    ftor();
    ftol();

    int Q; cin >> Q;
    while(Q--) {
        int a, b;
        cin >> a >> b;
        a--,b--;
        if(a > b) {

            int l = 0, r = 2 * n;//xxxxxxoooo
            while(r - l > 1) {
                int mid = (l + r) / 2;
                int pos = a;
                for(int i = 0; i < D; i++) {
                    if(mid & (1<<i))pos = tol[i][pos];
                }
                (pos <= b ? r : l) = mid;
            }
            cout << r << endl;

        } else {
            int l = 0, r = 2 * n;//xxxxxxoooo
            while(r - l > 1) {
                int mid = (l + r) / 2;
                int pos = a;
                for(int i = 0; i < D; i++) {
                    if(mid & (1<<i))pos = tor[i][pos];
                }
                (pos >= b ? r : l) = mid;
            }
            cout << r << endl;
        }

    }

}

#include "bits/stdc++.h"
using namespace std;
///////////////////////////////////////////
const long long int INF = 1LL<<60;
const long long int Mod = 1000000007;
using ll = long long int; using ci = const int;
using vi = vector<int>;  using Vi = vector<long long int>;
using P = pair<int, int>;  using PLL = pair<ll, ll>;
using matrix = vector<vector<ll>>;
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define all(x) (x).begin(),(x).end()
#define rep(i,N) for(ll i = 0; i < (ll)N; i++)
#define repi(i,a,b) for(ll i = ll(a); i < ll(b); ++i)
template<class T>bool chmax(T &former, const T &b) { if (former<b) { former=b; return true; } return false; }
template<class T>bool chmin(T &former, const T &b) { if (b<former) { former=b; return true; } return false; }
template<class T>T sqar(T x){ return x*x; }//sqrt(x)は平方根;
#define Sort(v) std::sort(v.begin(), v.end(), std::greater<decltype(v[0])>()) //降順でVをソート
#define p_queue(v) priority_queue<v, vector<v>, greater<v> >
template<class T> inline void princ(T x){cout<<x<<" ";};
template<class T> inline void print(T x){cout<<x<<"\n";};
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
///////////////////////////////////////////////////////////////////////////////////

ll m;
map<ll,ll> ma;
Vi d,c;

bool ck(){
	ll sum = 0;
	rep(i,10){
		sum += ma[i];
		if(sum>=2)return true;
	}
	return false;
}

int main(){
	cin.tie(0);ios::sync_with_stdio(false);
	std::cout<<std::fixed<<std::setprecision(30);
	cin>>m;
	d.resize(m);
	c.resize(m);
	rep(i,m){
		cin>>d[i]>>c[i];
		ma[d[i]] += c[i];
	}
	ll ans = 0;
	while(ck()){
		rep(i,10){
			ll sum = 0;
			if(i==0){
				if(ma[i]<2)continue;
				ans += ma[i]-1;
				ma[i] = 1;
			}else{
				while(ma[i]>1){
				if(ma[i]*i<10){
					sum = ma[i]*i;
					ans += ma[i]-1;
					ma[i] = 0;
					ma[sum]++;
				}else{
					ll tmp = 10/i;
					if(10%i==0){
						tmp--;
					}
					tmp++;
					ll ret = ma[i]/tmp;
					ma[i]%=tmp;
					sum = tmp*i;
					sum = sum%10 + sum/10;
					ans += tmp*ret;
					ma[sum]+=ret;
				}
				}
			}
		}
		rep(i,10){
			if(ma[i]==0)continue;
			repi(j,i+1,10){
				if(ma[i]==0)continue;
				if(ma[j]==0)continue;
				ll sum = i+j;
				ans++;
				if(sum>=10)ans++;
				sum = sum/10 + sum%10;
				ma[i]--;
				ma[j]--;
				ma[sum]++;
			}
		}
	}
	print(ans);
	return 0;
}


#include<iostream>
using namespace std;
#include<string>
#include<strstream>
#include<sstream>
#include<algorithm>
#include<math.h>
#include<iomanip>
#include<set>
long long mod = 10e18;
long long is(int n)
{
	if (n == 0)
		return 2;
	if (n == 1)
		return 1;
	return (is(n - 1) + is(n - 2));
}
int main()
{
	int n, k; cin >> n >> k; int j = 1;
	j += j;
	for (int i = 2; i <= n; ++i)
	{
		if (j < k)
		{
			j += j;
		}
		else
			j += k;
	}
	cout << j;

}

#include<iostream>
#include<cstdio>
#include<map>
using namespace std;
#define int long long
map<char, int> m={
        {'I',1},
        {'V',5},
        {'X',10},
        {'L',50},
        {'C',100},
        {'D',500},
        {'M',1000},
};
signed main(){
        char buf[256];
        while( scanf("%s", buf) != EOF ){
                int ans = 0;
                for(int i=0; i<256 && buf[i]!=0;i++){
                        if(buf[i+1]==0){
                                ans+=m[buf[i]];
                        }else{
                                if(m[buf[i]]<m[buf[i+1]]) ans-=m[buf[i]];
                                else ans+=m[buf[i]];
                        }
                }
                cout << ans<< endl;
        }
        return 0;
}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define ll long long
#define FASTIO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define inf 1e18
#define ff first
#define ss second
#define lb lower_bound
#define ub upper_bound
#define bs binary_search
#define mod 1000000007
#define pb push_back
#define all(s) s.begin(),s.end()
#define pie 3.14159265358979323846
#define fr(i,a,b)  for(ll i=a;i<b;i++)
#define frr(i,a,b) for(ll i=b-1;i>=a;i--)
#define gcd __gcd
#define con continue
#define pii pair<ll,ll>
signed main(){
    FASTIO;
    ll tt=1;
    //cin>>tt;
    while(tt--){
         ll n,ans=0,x,mx=0;cin>>n;
         for(ll i=0;i<n;i++){
            cin>>x;
            if(mx>x)ans+=mx-x;
            mx=max(mx,x);
         }
         cout<<ans<<"\n";
    }
}

#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < (n); i++)
#define REP1(i, n) for(int i = 1; i <= (n); i++)
#define REPD(i,a,b) for (int i=(a);i<(b);i++)
#define ALL(v) (v).begin(), (v).end()
using namespace std;
typedef long long ll;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef set<int> si;
typedef vector<si> vsi;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<int, int> pi;
typedef queue<int> qi;
typedef queue<pi> qpi;
typedef pair<ll, ll> pll;
typedef queue<pll> qpll;
typedef vector<pi> vpi;
typedef vector<pll> vpll;
const int mod = 1000000007;
const int INF = 1001001001;
// 小数点　<< fixed << setprecision(0) <<
// sort降順　sort(ALL(),greater<int>());
// 円周率　M_PI
// 文字判定　isupper islower
// 文字変換
// 順列　do {} while(next_permutation(ALL(X)));
// 最大値　LLONG_MAX
// a内でx以上　auto iter = lower_bound(ALL(a), x);
// a内でxより大きい　auto iter = upper_bound(ALL(a), x);
int dx[8] = {1, 0, -1, 0, 1, 1, -1, -1};
int dy[8] = {0, 1, 0, -1, 1, -1, 1, -1};
struct edge {
    int from; //出発点
    int to;   //到達点
    int cost; //移動コスト
};
typedef struct edge se;
typedef vector<edge> ve;
unsigned Euclidean_gcd(unsigned a, unsigned b) {
  if(a < b) return Euclidean_gcd(b, a);
  unsigned r;
  while ((r=a%b)) {
    a = b;
    b = r;
  }
  return b;
}

vpll PrimeFactorization(ll n) {
  vpll res;
  for (ll i=2; i*i<=n; i++) {
    if(n%i!=0) continue;
    ll ex=0;
    while(n%i==0) {
      ex++;
      n/=i;
    }
    res.push_back(pll(i,ex));
  }
  if(n!=1) res.push_back(pll(n,1));
  return res;
}

int main() {
  int k;
  vi a(3);
  cin >> a[0] >> a[1] >> a[2] >> k;
  sort(ALL(a));
  int ans=a[0]+a[1]+a[2]*pow(2,k);
  cout << ans << endl;
  return 0;
}


#include <iostream>
using namespace std;

int main() {
    int n;

    while(1){
    cin >> n;
    if(n == 0) break;
    int num[10000][2] = {};
    int score[2] = {};

    for (int i = 0; i < n; ++i)
    {
        for (int j = 0; j < 2; ++j){
            cin >> num[i][j];
        }
        if (num[i][0] > num[i][1])
        {
            score[0] += num[i][0] + num[i][1];
        } else if (num[i][0] == num[i][1])
        {
            score[0] += num[i][0];
            score[1] += num[i][1];
        } else{
            score[1] += num[i][0] + num[i][1];
        }
    }

    cout << score[0] << " " << score[1] << endl;
    }

    return 0;
}

#include <iostream>
using namespace std;
int result[200] = { 0 };
int main(){
		int num;
		int tmp1, tmp2, sc1 = 0, sc2= 0;
		while (cin >> num){
			sc1 = sc2 = 0;
			if (num == 0)break;
			for (int i = 0; i < num; i++){
				cin >> tmp1 >> tmp2;
				if (tmp1 == tmp2){
					sc1 += tmp1;
					sc2 += tmp2;
				}
				else if (tmp1 > tmp2)
					sc1 += tmp1 + tmp2;
				else if (tmp1 < tmp2)
					sc2 += tmp1 + tmp2;
			}
			cout << sc1 << " " << sc2 << endl;
		}
}


#include <iostream>
#include <vector>
#include <cassert>
#include <cmath>

using ll = long long;
#define MIN(a, b) (((a) < (b)) ? (a) : (b))
#define MAX(a, b) (((a) < (b)) ? (b) : (a))

int const nmax = 200;
ll v[1 + nmax];

class IndependentSet{
private:
  std::vector<std::pair<ll,int>> v;
public:
  ll reduce(ll number) {
    for(int i = 0; i < v.size(); i++)
      if(0 < ((1LL<<v[i].second) & number))
        number ^= v[i].first;
    return number;
  }
  void _insert(ll number) {
    number = reduce(number);
    if(0 < number)
      v.push_back({number, __builtin_ctzll(number)});
  }
};

int solve() {
  int n;
  std::cin >> n;
  for(int i = 1; i <= n; i++)
    std::cin >> v[i];
  std::string s;
  std::cin >> s;
  s = "#" + s;
  IndependentSet myset;
  for(int i = n; 1 <= i; i--) {
    if(s[i] == '0')
      myset._insert(v[i]);
    else {
      if(0 < myset.reduce(v[i]))
        return 1;
    }
  }
  return 0;
}

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

  int t;
  std::cin >> t;
  for(int testcase = 1; testcase <= t; testcase++)
    std::cout << solve() << '\n';
  return 0;
}

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

// a^n mod を計算する
// O(logn)
ll modpow(ll a, ll n, ll mod=998244353) {
    ll res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

ll cnt[100010];

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

    vector<ll> d(n);
    rep(i,n){
        cin>>d[i];
        cnt[d[i]]++;
    }

    if(d[0]!=0 || cnt[0]!=1){
        cout<<0<<endl;
        return 0;
    }

    ll ans=1;

    for(int i=1;i<100010;i++){
        ll tmp=modpow(cnt[i],cnt[i+1]);
        ans=(ans*tmp)%998244353;
    }

    cout<<ans<<endl;
}


#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define REP(a,b) for(int a=0;a<(b);++a)
#define REP1(i,n) for(int i=1;i<=(n);++i)
#define debug(x) cerr<<#x<<": "<<x<<'\n'
#define all(x) (x).begin(),(x).end()
#define YES() printf("YES\n")
#define NO() printf("NO\n")
#define isYES(x) printf("%s\n",(x) ? "YES" : "NO")
#define Yes() printf("Yes\n")
#define No() printf("No\n")
#define isYes(x) printf("%s\n",(x) ? "Yes" : "No")
#define isPossible(x) printf("%s\n",(x) ? "Possible" : "Impossible")
#define SZ(x) ((int)(x).size())
#define pb push_back
#define mp make_pair
// #define INF (1<<29)

const long long INF = 1LL<<60;

#define Sp(p) cout<<setprecision(25)<< fixed<<p<<endl
#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
#define pll pair<ll,ll>
#define pie 3.14159265358979323846
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;
template<class T=int>
T in(){T x;cin>>x;return (x);}
template<class T>
void print(T& x){cout<<x<<'\n';}

const int MOD =(int)1e9+7;
// const int mod =(int)998244353;
const int mod =(int)1e9+7;

const int MAX =510000;
ll fac[MAX],finv[MAX],inv[MAX];
void COMint(){
    fac[0]=fac[1]=1;
    finv[0]=finv[1]=1;
    inv[1]=1;
    for(int i=2;i<MAX;i++){
        fac[i]=fac[i-1]*i%MOD;
        inv[i]=MOD-inv[MOD%i]*(MOD/i)%MOD;
        finv[i]=finv[i-1]*inv[i]%MOD;
    }
}
ll COM(int n,int k){
    if(n<k) return 0;
    if(n<0||k<0)return 0;
    return fac[n]*(finv[k]*finv[n-k]%MOD)%MOD;
}
ll gcd(ll a,ll b){
    if(a<0)a=-a;
    if(b<0)b=-b;
    if(b==0)return a;
    if(a>b){
        swap(a,b);
    }
    return gcd(a,b%a);
}
ll lcm(ll a,ll b){
  if(a<0)a=-a;
  if(b<0)b=-b;
    ll g;g=gcd(a,b);
    return b/g*a;
}
bool compare_by_b(pair<int, int> a, pair<int, int> b) {
    if(a.second != b.second){
        return a.second < b.second;
    }else{
        return a.first < b.first;
    }
}
bool compare_by_a(pair<int, int> a, pair<int, int> b) {
    if(a.first != b.first){
        return a.first < b.first;
    }else{
        return a.second < b.second;
    }
}
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
ll RS(ll N,ll P,ll m){
    if(P==0){
        return 1;
    }else{
        if(P%2==0){
            ll t=RS(N,P/2,m);
            return t*t%m;
        }else{
            return N*RS(N,P-1,m)%m;
        }
    }
}
bool greater_pair(pair<ll,ll> a,pair<ll,ll> b){
    if(a.first!=b.first){
        return a.first>b.first;
    }else{
        return a.second>b.second;
    }
}
int N;
vector<vector<int>> to(100100);
vector<int> parent(100100,-1);
vector<int> depth(100100,-1);
vector<int> level(100100,-1);
vector<int>checked(100100,0);

int f(int i){
    checked[i]=1;
    int res=0;
    REP(ni,to[i].size()){
        if(checked[to[i][ni]]!=0)continue;
        parent[to[i][ni]]=i;
        level[to[i][ni]]=level[i]+1;
        res=max(res,1+f(to[i][ni]));
    }
    return depth[i]=res;
}
int main() {
    ios::sync_with_stdio(false);
    cin>>N;
    int v,u;cin>>u>>v;--v,--u;
    REP(i,N-1){
        int a,b;cin>>a>>b;--a;--b;
        to[a].pb(b);
        to[b].pb(a);
    }
    parent[v]=-1;
    level[v]=0;
    int d=f(v);
    int ans=0;
    if(level[u]%2==0)ans++;
    int temp=(level[u]-1)/2;
    REP(i,temp){
       u=parent[u];
       ans++;
    }
    ans+=depth[u];
    cout<<ans<<endl;
    return 0;
}

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

vector<int>adj[100003],leaf;
int par[100003],depth[100005],sparse[100005][20],root=0,lz=0;

int lca(int p,int q)
{

    int a,b,c,d,lp,i,j;

    if(depth[p]<depth[q])
    {
        c=p; p=q; q=c;
    }

    for(j=19;j>=0;j--)
    {
         if((depth[p]-(1 << j))>=depth[q])
         {
             p=sparse[p][j];  if(depth[p]==depth[q])break;
         }
    }

    if(p==q){ return p; }
    else
    {
         for(j=19;j>=0;j--)
         {
             if(sparse[p][j]!=0 && sparse[p][j]!=sparse[q][j])
             {

                 p=sparse[p][j]; q=sparse[q][j];

                 if(par[p]==par[q])break;
             }

         }

         return par[p];
    }

}

void dfs(int src)
{
    int sz=adj[src].size();

    if(sz==1 && src!=root){   leaf.push_back(src);  lz++;   }

    for(int lp=0;lp<sz;lp++)
    {
        int u=adj[src][lp];

        if(u!=root && par[u]==0)
        {
            par[u]=src; sparse[u][0]=src; depth[u]=depth[src]+1;
            dfs(u);

        }

    }

}

int main()
{

    int n,m,a,b,i,j,u,v,ans,z,x,y,fr,sc,tr,w;
    scanf("%d %d %d",&n,&u,&v);

    for(i=1;i<=n-1;i++)
    {
        scanf("%d %d",&a,&b);
        adj[a].push_back(b); if(root==0){  if(adj[a].size()==2)root=a;  }
        adj[b].push_back(a); if(root==0){  if(adj[b].size()==2)root=b;  }

    }

    if(n==2)printf("0\n");
    else
    {
       dfs(root);

       for(j=1;j<=19;j++)
       {
           for(i=1;i<=n;i++)
           {
               if(sparse[i][j-1]!=0)
               {
                   sparse[i][j]=sparse[sparse[i][j-1]][j-1];
               }
           }
       }

       m=lca(u,v);

       ans=(depth[v]-depth[m])+(depth[u]-depth[m]); ans=ans-1;

       for(i=0;i<lz;i++)
       {
           y=leaf[i]; m=lca(u,y); w=lca(v,y);

           fr=(depth[u]-depth[m])+(depth[y]-depth[m]);
           sc=(depth[v]-depth[w])+(depth[y]-depth[w]);

           if(fr<sc)
           {
               if(sc-1>ans)ans=sc-1;
           }

       }

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

    }

    return 0;
}


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

int main(){
  long long N;
  cin>>N;
  long long A[N];
  long long O[65];
  for(long long i=0;i<65;i++){
    O[i]=0;
  }

  for(long long i=0;i<N;i++){
    cin>>A[i];
    int count=0;
    long long temp=A[i];
    while(temp!=0){
      O[count]+= temp%2;
      temp/=2;
      count++;
    }
    //cout<<i<<" "<<A[i]<<" "<<count<<" "<<O[count]<<endl;
  }
  long long ans=0;
  long long t=1;
  for(long long i=0;i<63;i++){
    ans=(ans+((t*O[i])%1000000007)*(N-O[i]))%1000000007;
    t=(t*2)%1000000007;
    //cout<<i<<" "<<O[i]<<" "<<ans<<endl;
  }

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

#include<bits/stdc++.h>

#include <ext/pb_ds/assoc_container.hpp> //required
#include <ext/pb_ds/tree_policy.hpp> //required

using namespace __gnu_pbds;
using namespace std;

template <typename T> using ordered_set =  tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
// find_by_order(k)  returns iterator to kth element starting from 0;
// order_of_key(k) returns count of elements strictly smaller than k;
typedef long long  ll;
typedef vector<ll> VL;
typedef vector<int> VI;
typedef pair<ll,ll> PLL;
typedef pair<int,int> PII;
#define pb push_back

#define F first
#define S second
#define SZ(a) int((a).size())
#define ALL(a) a.begin(),a.end()
#define fr(i,x,y) for(int i=x;i<y;i++)
#define frr(i,x,y) for(int i=x-1;i>=y;i--)
#define inf 1e18+1
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
const int mod=1000000007;
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
ll power(ll a,ll b){ll ans=1;while(b!=0){if(b&1){ans*=a;}a=a*a;b>>=1;}return ans;}
ll powerm(ll a,ll b){ll ans=1;while(b!=0){if(b&1){ans*=a;ans%=mod;}a=a*a;a%=mod;b>>=1;}return ans%mod;}
// string to integer stoi()
// string to long long stoll()
// string.substr(position,length);
// integer to string to_string();

void solve()
{
    ll n;
    cin>>n;
    vector<VL> pref(n+2,VL(60,0));
    VL arr(n);
    fr(i,0,n)
    {
        cin>>arr[i];
        ll x=arr[i];
        fr(j,0,60)
        {
            if(x&(1LL<<j))
            {
                pref[i+1][j]=1;
            }
        }
    }
    fr(j,0,60)
    {
        frr(i,n+1,1)
        {
            pref[i][j]+=pref[i+1][j];
        }
    }
    ll ans=0;

    fr(i,0,n-1)
    {
        //cin>>arr[i];
        ll x=arr[i];
        ll rem=n-(i+1);
        fr(j,0,60)
        {
            if(x&(1LL<<j))
            {
                ans+=(powerm(2,j)*(rem-pref[i+2][j])%mod);
                //scout<<x<<' '<<j<<endl;
            }
            else
            {
                ans+=(powerm(2,j)*(pref[i+2][j])%mod);
            }
            ans%=mod;
        }
    }
    cout<<ans<<endl;
    return;
}
int main()
{
    IOS;
    ll t=1;
    //cin>>t;
    while(t--)
    {
        //cout<<"Case #"<<pp-t<<":\n";
        solve();
    }
    return 0;
}
/* stuff you should look for
        * int overflow, array bounds
        * special cases (n=1?)
        * do smth instead of nothing and stay organized
        * WRITE STUFF DOWN
*/
/*
recursion - matrix exponential

*/
// BITMASK:
// 1)When some constrall is of the order of 15-20, think of bitmask DP.
// 2)When some constrall is around 40, try out meet in the middle
// 3) See Strings,palindromes,prefix,suffix etc -> KMP,Z algorithm


#include <stdio.h>
#include <algorithm>
int n, t, x;
int a[100000];
int main() {
	scanf("%d", &n);
	for (int i = 0; i < n; i++) {
		scanf("%d", a + i);
	}
	std::sort(a, a + n);
	t = 1;
	for (int i = 0; i < n; i++) {
		if (i == n - 1 || a[i] != a[i + 1]) {
			if (t % 2)x++;
			t = 1;
		}
		else t++;
	}
	printf("%d\n", x);
}

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

string data[22];

int solve(int x, int y){

  if(x < 0 || y < 0 || x == 12 || y == 12 || data[y][x] == '0') return 0;

  data[y][x] = '0';

  int dx[] = {0, 0, 1, -1};
  int dy[] = {1, -1, 0, 0};
  for(int i=0;i<4;i++) solve(x+dx[i], y+dy[i]);

  return 1;
}

int main(){

  while(cin >> data[0]){
    for(int i=1;i<12;i++) cin >> data[i];

    int ans = 0;
    for(int i=0;i<12;i++) for(int j=0;j<12;j++) ans += solve(i, j);

    cout << ans << endl;
  }

}


#include <bits/stdc++.h>

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

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

using namespace std;

using ll = long long;

const long long MOD = 1000000007;

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

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

void solve(std::string K, ll D) {
  ll N = K.size();
  vector<vector<vector<ll>>> dp(N + 1,
                                vector<vector<ll>>(2, vector<ll>(D + 1)));
  dp[0][0][0] = 1;
  FOR(i, 0, N) {
    ll k = K.at(i) - '0';
    FOR(j, 0, D) {
      FOR(dig, 0, 10) { (dp[i + 1][1][(j + dig) % D] += dp[i][1][j]) %= MOD; }
      FOR(dig, 0, k) { (dp[i + 1][1][(j + dig) % D] += dp[i][0][j]) %= MOD; }
      (dp[i + 1][0][(j + k) % D] += dp[i][0][j]) %= MOD;
    }
  }
  ll ans = (dp[N][0][0] + dp[N][1][0] - 1 + MOD) % MOD;
  cout << ans << endl;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(15);
  std::string K;
  std::cin >> K;
  ll D;
  cin >> D;
  solve(K, D);
  return 0;
}

#include <algorithm>  // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <bitset>     // bitset
#include <cctype>     // isupper, islower, isdigit, toupper, tolower
#include <cstdint>    // int64_t, int*_t
#include <cstdio>     // printf
#include <deque>      // deque
#include <iomanip>    // fixed, setprecision
#include <iostream>   // cout, endl, cin
#include <map>        // map
#include <queue>      // queue, priority_queue
#include <set>        // set
#include <stack>      // stack
#include <string>     // string, to_string, stoi
#include <tuple>      // tuple, make_tuple
#include <unordered_map>  // unordered_map
#include <unordered_set>  // unordered_set
#include <utility>        // pair, make_pair
#include <vector>         // vector
using namespace std;

int main() {
  int N, L, t, s = 0, mdiff = 20000, mt;
  cin >> N >> L;
  for (int i = 0; i < N; i++) {
    t = L + i;
    if (abs(t) < mdiff) {
      mdiff = abs(t);
      mt = t;
    }
    s += t;
  }
  cout << s - mt << endl;
}


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

int main() {
  string s; cin >> s;
  for(int i = s.size()-1; i >= 0; i--) printf("%c", s[i]);
  cout << endl;
}

#include<bits/stdc++.h>
using namespace std;
signed main(void){
	ios::sync_with_stdio(false);
	int d,ans;
	while(cin>>d){
		ans=0;
		for(int i=0;i<600;i+=d)
			ans+=i*i*d;
		cout<<ans<<endl;
	}
}


/*
 * sto Qingyu orz
 * 感谢真神sqy无私的教诲。膜时队者处处阿克，只因大师sqy在他背后。不膜大师者违背了真神的旨意，真神必将降下天谴,
 * 使其天天爆零
 * 我不由自主地膜拜真神sqy。
 * Author: RainAir
 * Time: 2019-10-16 10:11:35
 */
#include <algorithm>
#include <iostream>
#include <cstring>
#include <climits>
#include <cstdlib>
#include <cstdio>
#include <bitset>
#include <vector>
#include <cmath>
#include <ctime>
#include <queue>
#include <stack>
#include <map>
#include <set>

#define fi first
#define se second
#define U unsigned
#define P std::pair
#define LL long long
#define pb push_back
#define MP std::make_pair
#define all(x) x.begin(),x.end()
#define CLR(i,a) memset(i,a,sizeof(i))
#define FOR(i,a,b) for(int i = a;i <= b;++i)
#define ROF(i,a,b) for(int i = a;i >= b;--i)
#define DEBUG(x) std::cerr << #x << '=' << x << std::endl

const int MAXN = 5000+5;
const int ha = 998244353;
int cnt[MAXN];
int n,k,fac[MAXN],inv[MAXN];

inline int qpow(int a,int n=ha-2){
    int res = 1;
    while(n){
        if(n & 1) res = 1ll*res*a%ha;
        a = 1ll*a*a%ha;
        n >>= 1;
    }
    return res;
}

inline void prework(){
    fac[0] = 1;
    FOR(i,1,MAXN-1) fac[i] = 1ll*fac[i-1]*i%ha;
    inv[MAXN-1] = qpow(fac[MAXN-1]);
    ROF(i,MAXN-2,0) inv[i] = 1ll*inv[i+1]*(i+1)%ha;
}

inline int C(int n,int m){
    if(n < m) return 0;
    return 1ll*fac[n]*inv[m]%ha*inv[n-m]%ha;
}

int main(){
    scanf("%d%d",&k,&n);
    prework();
    FOR(i,1,k) cnt[i+1]++,cnt[i+k+1]--;
    FOR(i,1,2*k) cnt[i] += cnt[i-1],cnt[i-1] = (cnt[i-1]+1)/2;
//    FOR(i,1,2*k) DEBUG(cnt[i]);
    FOR(i,2,k*2){
        int ans = 0;
        FOR(j,0,std::min(cnt[i],n/2)){
            (ans += 1ll*((j&1)?ha-1:1)*C(cnt[i],j)%ha*C(n-2*j+k-1,k-1)%ha)%=ha;
        }
        printf("%d\n",ans);
    }
    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;
  ll m = 0;
  cin >> n >> m;
  vector<ll> a(n);
  vector<ll> b(m);
  map<ll,ll> ac;
  map<ll,ll> bc;
  for(int i = 0;i < n;i++)cin >> a[i],ac[a[i]]++;
  for(int i = 0;i < m;i++)cin >> b[i],bc[b[i]]++;
  if((ll)ac.size() != n || (ll)bc.size() != m){
    cout << 0 << endl;
    return 0;
  }
  vector<ll> awa(n*m);
  vector<ll> bwa(n*m);
  for(int i = n*m - 1;i >= 0;i--){
    if(ac[i + 1] == 1)awa[i] = 1;
    if(i != n*m - 1)awa[i] += awa[i + 1];
  }
  for(int i = n*m - 1;i >= 0;i--){
    if(bc[i + 1] == 1)bwa[i] = 1;
    if(i != n*m - 1)bwa[i] += bwa[i + 1];
  }
  ll res = 1;
  ll mod = pow(10,9) + 7;
  for(int i = n*m - 1;i >= 0;i--){
    if(ac[i + 1] == 1 && bc[i + 1] == 0)res *= max((ll)0,bwa[i + 1]);
    if(ac[i + 1] == 0 && bc[i + 1] == 1)res *= max((ll)0,awa[i + 1]);
    if(ac[i + 1] == 0 && bc[i + 1] == 0)res *= max((ll)0,awa[i + 1] * bwa[i + 1] - (n*m - i - 1));
    res %= mod;
  }
  cout << res << endl;
}


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

int main(){
  int g;
  cin >>g;
  int a,b;
  cin >>a >>b;
  if(g==1){cout << "Hello World" << endl;}else{cout << a+b << endl;}
}

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

int main(void) {
    int n,a,b;
    cin >> n;
    if(n==2) {
        cin >> a >> b;
        cout << a + b << endl;
    } else {
        cout << "Hello World\n" << endl;
    }

    return 0;
}


#include <bitset>
#include <cmath>
#include <iostream>

using namespace std;

int a(int i) {
  int ret{};
  for (int j = 0; j != i; ++j) {
    ret += lround(pow(2, 2 * j + 1));
  }
  return ret;
}

int main() {
  long long N;
  cin >> N;
  bitset<64> ans;

  for (int i = 0; i != 16; ++i) {
    auto x = ((N + a(i)) >> 2*i) % 4;
    ans.set(2 * i + 1, x & 0x2);
    ans.set(2 * i, x & 0x1);
  }

  bool flag{false};
  for (int i = 31; i >= 0; --i) {
    if (flag |= ans.test(i), !flag) continue;
    cout << ans.test(i);
  }
  if (!flag) cout << 0;
  cout << endl;
}

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

int main(){
  ll N;
  cin >> N;
  if (N == 0){
    cout << '0' << endl;
    exit(0);
  }

  vector<ll> bin(0);
  while (N != 1){
    ll amari = N % -2;
    if (amari >= 0){
      bin.push_back(amari);
      N /= -2;
    }
    else{
      bin.push_back(1);
      N /= -2;
      N += 1;
    }
  }
  bin.push_back(1);

  for (ll i = bin.size() - 1; i >= 0; i--){
    ll a = bin.at(i);
    cout << a;
  }
  cout << endl;

  /*ll a = N % -2;
  ll b = N / -2;
  cout << a << ' ' << b << endl;*/
}