///Bismillahir Rahmanir Rahim
#include "bits/stdc++.h"

#define                           ll                          long long
#define                           int                         ll
#define                           fi                          first
#define                           si                          second
#define                           mp                          make_pair
#define                           pb                          push_back
#define                           pi                          pair<ll,ll>
#define                           clr(x)                      memset(x,0,sizeof(x));
#define                           f(i,l,r)                    for(int i=l;i<=r;i++)
#define                           rf(i,r,l)                   for(int i=r;i>=l;i--)
#define                           done(i)                     cout<<"done = "<<i<<endl;
#define                           show(x,y)                   cout<<x<<" : ";for(auto z:y)cout<<z<<" ";cout<<endl;
#define                           fast                        ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);

using namespace std;

const ll inf=1e18;
const int mod=1e9+7;
const int M=100005;
int h,w;
int a[505][505];
vector<pi>vec;
vector<pair<pi,pi> >ses;
vector<pi>yo;
int flag=0;
void dfs(int x,int y,int ex,int ey,int turn)
{
    if(flag)return ;
    if(x==ex && y==ey)
    {
        flag=1;
        return ;
    }
    if(y>w)
    {
        y=w;
        x++;
        turn=1-turn;
        dfs(x,y,ex,ey,turn);
        return ;
    }
    if(y<1)
    {
        y=1;
        x++;
        turn=1-turn;
        dfs(x,y,ex,ey,turn);
        return ;
    }
    yo.pb(mp(x,y));
    if(turn==0)
    {
        dfs(x,y+1,ex,ey,turn);
    }
    else if(turn==1)
    {
        dfs(x,y-1,ex,ey,turn);
    }

}
void work(pi u,pi v)
{
    int x1=u.fi;
    int y1=u.si;
    int x2=v.fi;
    int y2=v.si;
    int turn=0;
    if(x1%2==0)turn=1;
    flag=0;
    yo.clear();
    dfs(x1,y1,x2,y2,turn);
    yo.pb(mp(x2,y2));
    int sz=yo.size();
//    for(auto x:yo)
//    {
//        cout<<x.fi<<" "<<x.si<<endl;
//    }
//    cout<<"......"<<endl;
    for(int i=0;i<sz-1;i++)
    {
       ses.pb(mp(yo[i],yo[i+1]));
    }
}
 main()

{
    fast
    cin>>h>>w;
    f(i,1,h)
    {
        vector<pi>nw;
        f(j,1,w)
        {
            cin>>a[i][j];
            if(a[i][j]%2==1)nw.pb(mp(i,j));
        }
        if(i%2==0)reverse(nw.begin(),nw.end());
        for(auto x:nw)vec.pb(x);
    }
    if(vec.size()==0)
    {
        cout<<"0"<<endl;
        return 0;
    }
    if(vec.size()%2==1)vec.pop_back();
    int sz=vec.size();
    if(sz==0)
    {
        cout<<"0"<<endl;return 0;
    }
    for(int i=0;i<sz;i=i+2)
    {
        pi x=vec[i];
        pi y=vec[i+1];
        //cout<<x.fi<<" "<<x.si<<" "<<y.fi<<" "<<y.si<<endl;
        work(x,y);
    }
   cout<<ses.size()<<"\n";
    for(auto x:ses)
    {
        pi u=x.fi;
        pi v=x.si;
        cout<<u.fi<<" "<<u.si<<" "<<v.fi<<" "<<v.si<<"\n";
    }
    return 0;

}

#include <bits/stdc++.h>
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
using ll = long long;
using P = pair<int, int>;
ll GCD(ll a, ll b) { return b?GCD(b, a%b):a; }
ll LCM(ll a, ll b) { return a/GCD(a, b)*b; }

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

int h, w;
struct xydata {
    int px; int py; int nex; int ney;
};

int main() {
    cin >> h >> w;
    vector< vector<int> > amap(h, vector<int>(w, 0));
    for(int i = 0; i < h; ++i) {
        for(int j = 0; j < w; ++j) {
            cin >> amap.at(i).at(j);
        }
    }

    int n = 0;
    vector<xydata> xyvec;
    for(int i = 0; i < h; ++i) {
        for(int j = 0; j < w; ++j) {
            if(amap.at(i).at(j)%2 != 0) {
                // そのマスが奇数ならまずは周囲を確認する
                bool flg = false;
                for(int k = 0; k < 4; ++k) {
                    int nx = j+dx[k]; int ny = i+dy[k];
                    if(nx >= 0 && nx < w && ny >= 0 && ny < h) {
                        if(amap.at(ny).at(nx)%2 != 0) {
                            flg = true;
                            n++;
                            xydata indata;
                            indata.px = j; indata.py = i;
                            indata.nex = nx; indata.ney = ny;
                            xyvec.emplace_back(indata);
                            amap.at(i).at(j)--;
                            amap.at(ny).at(nx)++;
                            break;
                        }
                    }
                }
                if(!flg) {
                    for(int k = 2; k < 4; ++k) {
                        int nx = j+dx[k]; int ny = i+dy[k];
                        if(nx >= 0 && nx < w && ny >= 0 && ny < h) {
                            n++;
                            xydata ndata;
                            ndata.px = j; ndata.py = i;
                            ndata.nex = nx; ndata.ney = ny;
                            xyvec.emplace_back(ndata);
                            amap.at(i).at(j)--;
                            amap.at(ny).at(nx)++;
                            break;
                        }
                    }
                }
            }
        }
    }

    cout << n << endl;
    for(int i = 0; i < n; ++i) {
        xydata ans = xyvec.at(i);
        cout << ans.py+1 << " " << ans.px+1 << " " << ans.ney+1 << " " << ans.nex+1 << endl;
    }
}


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

ll dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
ll counterb=0,counterw=0;
void dfs(ll x,ll y,ll H, ll W,vector<vector<bool>> &field,vector<vector<bool>> &check){
    check[x][y]=1;
    if(field[x][y]==1){counterb++;}
    if(field[x][y]==0){counterw++;}
    bool meter=(x+y+field[x][y])%2;
    for(int i=0;i<4;i++){if(x+dx[i]>=0&&x+dx[i]<H&&y+dy[i]>=0&&y+dy[i]<W){
        if(check[x+dx[i]][y+dy[i]]==0&&(x+y+dx[i]+dy[i]+field[x+dx[i]][y+dy[i]])%2==meter){
            dfs(x+dx[i],y+dy[i],H,W,field,check);
        };}
    ;}

}

int main(){
ll H;
cin >> H;
ll W;
cin >> W;
vector<vector<bool>> field(H, vector<bool>(W, 0));
vector<vector<bool>> check(H, vector<bool>(W, 0));
for(int i=0;i<H;i++){
 for(int j=0;j<W;j++){
     char k;
     cin>>k;
     if(k=='#'){field[i][j]=1;}
 ;}
;}
    ll ans=0;
for(ll i=0;i<H;i++){
 for(ll j=0;j<W;j++){

     if(check[i][j]==0){
         dfs(i,j,H,W,field,check);ans+=counterb*counterw;
         counterb=0;counterw=0;
     }

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

}

#include <bits/stdc++.h>

using namespace std;

int dy[4] = {-1,0,1,0};
int dx[4] = {0,1,0,-1};
char board[401][401];
int h,w;
int visited[401][401];
long long int arr[160005][2];

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

	cin >> h >> w;

	for(int i=0;i<h;i++)
	{
		for(int j=0;j<w;j++)
		{
			cin >> board[i][j];
		}
	}

	memset(visited,-1,sizeof(visited));

	int cnt = 0;

	for(int i=0;i<h;i++)
	{
		for(int j=0;j<w;j++)
		{
			if(visited[i][j]==-1 && board[i][j]=='#')
			{
				queue <pair<int,int>> que;
				que.push(make_pair(i,j));
				visited[i][j] = cnt;
				while(!que.empty())
				{
					int y = que.front().first;
					int x = que.front().second;
					que.pop();

					for(int k=0;k<4;k++)
					{
						int ny = y + dy[k];
						int nx = x + dx[k];
						if(ny < 0 || ny >= h || nx < 0 || nx >= w)
						{
							continue;
						}
						if(visited[ny][nx]==-1 && board[ny][nx]!=board[y][x])
						{
							visited[ny][nx] = cnt;
							que.push(make_pair(ny,nx));
						}
					}
				}
				cnt++;
			}
		}
	}

	long long int res = 0;
	for(int i=0;i<h;i++)
	{
		for(int j=0;j<w;j++)
		{
			if(visited[i][j]==-1)
			{
				continue;
			}
			if(board[i][j]=='#')
			{
				arr[visited[i][j]][0]++;
			}
			else
			{
				arr[visited[i][j]][1]++;
			}
		}
	}

	for(int i=0;i<cnt;i++)
	{
		res += (arr[i][0]*arr[i][1]);
	}

	cout << res << '\n';

    return 0;
}


#include <iostream>
#include <algorithm>
typedef long long ll;
using namespace std;

ll mod=998244353;
const int SIZE=2010000;
ll fac[SIZE], finv[SIZE], inv[SIZE], sum[260000];
void COMinit(ll m){
    fac[0]=fac[1]=1;
    finv[0]=finv[1]=1;
    inv[1]=1;
    for(int i=2; i<SIZE; ++i){
        fac[i]=(fac[i-1]*i)%m;
        inv[i]=m-(inv[m%i]*(m/i))%m;
        finv[i]=(finv[i-1]*inv[i])%m;
    }
}
ll COM(int n, int k, ll m){
    if(n<k) return 0;
    if(n<0 || k<0) return 0;
    return (fac[n]*((finv[k]*finv[n-k])%m))%m;
}

int main(void){
    int N, M;
    cin >> N >> M;
    COMinit(mod);
    ll ans=0;
    sum[0]=0;
    for(int i=0; i*2<=M; ++i){
        sum[i+1]=(sum[i]+COM(N-2+i, i, mod))%mod;
    }
    for(int i=M%2; i<=min(N, M); i += 2){
        ll num=COM((3*M-i)/2+N-1, N-1, mod);
        (num += mod-(sum[max((3*M-i)/2-M, 0)]*(N-i))%mod) %= mod;
        (num += mod-(sum[max((3*M-i)/2-M+1, 0)]*i)%mod) %= mod;
        (num *= COM(N, i, mod)) %= mod;
        (ans += num) %= mod;
    }
    cout << ans << endl;
    return 0;
}

#include <cstdio>
#include <algorithm>
#define mod 998244353
#define maxn 200010
#define LL long long
using namespace std;
LL fact[maxn],inv[maxn],ans,t[maxn],p;
int n,m,k,nm;
LL quick_pow(LL a,LL b){//a^b
	LL ans=1;
	while(b){
		if(b&1)ans=ans*a%mod;
		a=a*a%mod;
		b>>=1;
	}
	return ans%mod;
}
void init(){
	int i;
	scanf("%d%d%d",&n,&m,&k);
	nm=n,nm=max(nm,m),fact[0]=1;
	for(i=1;i<=nm;i++)fact[i]=fact[i-1]*i%mod;//fact[i]代表i!
	inv[nm]=quick_pow(fact[nm],mod-2);
	for(i=nm-1;i>=0;i--)inv[i]=inv[i+1]*(i+1)%mod;//inv[i]代表i!的乘法逆元
}
LL C(LL a,LL b){//组合数计算
	return fact[a]*inv[a-b]%mod*inv[b]%mod;
}
int main(){
	int i;
	init();
	ans=0,p=quick_pow(m-1,n-k-1);
	for(i=n-k;i<=n;i++){
		ans=(ans+m*p%mod*C(n-1,i-1)%mod)%mod;//C(n-1,i-1)隔板法
		p=p*(m-1)%mod;
	}
	printf("%lld\n",ans);
	return 0;
}


#include <cstdio>
#include <algorithm>
#include <set>

using namespace std;

int n,m;
int map[501][501];

main(){
  fill((int*)map, (int*)(map+sizeof(map)/sizeof(*map)), 0);

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

  if(n==0 && m == 0) return 0;

  int a,b;
  while(m--){
    scanf("%d%d", &a, &b);
    map[a][b] = 1;
    map[b][a] = 1;
  }

  set<int> s;
  for(int i=0;i<501;i++){
    if(map[1][i]){
      s.insert(i);
      for(int j=0;j<501;j++){
	if(map[i][j]){
	  s.insert(j);
	}
      }
    }
  }

  if(s.size())  printf("%d\n", (int)s.size()-1);
  else puts("0");

  main();
}

#include<iostream>
#include<queue>
using namespace std;
#define MAX 500
#define rep(i, n) for ( int i = 0; i < n; i++)

bool G[MAX][MAX];
int n, m;

int bfs(){
  queue<int> q;
  int d[MAX];
  rep(i, n) d[i] = (1<<21);

  q.push(0);
  d[0] = 0;

  int u;
  while(!q.empty()){
    u = q.front(); q.pop();

    rep(v, n){
      if ( d[v] == (1<<21) && G[u][v] ){
	d[v] = d[u] + 1;
	q.push(v);
      }
    }
  }

  int cnt = 0;
  rep(i, n) if ( d[i] == 1 || d[i] == 2 ) cnt++;
  return cnt;
}

main(){
  int s, t;
  while(1){
    cin >> n >> m;
    if ( n == 0 && m == 0 ) break;
    rep(i, n) rep(j, n) G[i][j] = false;

    rep(i, m){
      cin >> s >> t;
      s--; t--;
      G[s][t] = G[t][s] = true;
    }

    cout << bfs() << endl;
  }
}


#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define ll long long
#define rep(i,n) for(ll i=0;i<(n);i++)
#define pll pair<ll,ll>
#define pii pair<int,int>
#define pq priority_queue
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define endl '\n'
#define ios ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define lb(c,x) distance(c.begin(),lower_bound(all(c),x))
#define ub(c,x) distance(c.begin(),upper_bound(all(c),x))

using namespace std;

inline int topbit(unsigned long long x){
	return x?63-__builtin_clzll(x):-1;
}

inline int popcount(unsigned long long x){
	return __builtin_popcountll(x);
}

inline int parity(unsigned long long x){//popcount%2
	return __builtin_parity(x);
}

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

const ll INF=1e15;

const ll mod=1e9+7;

int main(){
    ll n;
    cin >> n;
    vector<vector<ll>> a(n,vector<ll>(n-1));
    rep(i,n)rep(j,n-1){
        cin >> a[i][j];
        a[i][j]--;
    }
    rep(i,n){
        reverse(a[i].begin(),a[i].end());
    }
    vector<pii> q;
    auto check=[&](ll i){
        if(a[i].size()==0){
            return ;
        }
        ll j=a[i].back();
        if(a[j].back()!=i){
            return ;
        }
        if(i>j) swap(i,j);
        pii P=make_pair(i,j);
        q.push_back(P);
    };
    rep(i,n){
        check(i);
    }
    ll day=0;
    while(q.size()){
        day++;
        sort(q.begin(),q.end());
        q.erase(unique(q.begin(),q.end()),q.end());
        vector<pii> preQ;
        swap(preQ,q);
        for(pii x:preQ){
            ll i=x.first;
            ll j=x.second;
            a[i].pop_back();
            a[j].pop_back();
        }
        for(pii x:preQ){
            ll i=x.first;
            ll j=x.second;
            check(i);
            check(j);
        }
    }
    rep(i,n){
        if(a[i].size()){
            cout << -1 << endl;
            return 0;
        }
    }
    cout << day << endl;
    return 0;
}

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

typedef long long              ll;
typedef long double            ld;
typedef pair<int, int>         pi;
typedef vector<int>            vi;
typedef vector<pair<int, int>> vpi;

#define pb       push_back
#define all(x)   begin(x), end(x)
#define sz(x)    (int)(x).size()
#define ff       first
#define ss       second
#define mp       make_pair
#define lb       lower_bound
#define ub       upper_bound
#define tcase()  int t; cin >> t; while(t--)

const int MOD = 1e9 + 7; // 998244353;
const int MX  = 2e5 + 5;
const ll  INF = 1e18;
const ld  PI  = acos((ld) -1);

void setIO(string name = "") {
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    if(sz(name)){
        freopen((name+".in").c_str(), "r", stdin);
        freopen((name+".out").c_str(), "w", stdout);
    }
}

int main(){

    setIO();

    int n, m;
    cin >> n >> m;

    bool ok = true;

    int mpp[n + 1] = {0};

    for(int i = 0; i < m; i++){
        int x, y;
        cin >> x >> y;

        if(x > n){
            ok = false;
        }

        if(mpp[x] != 0 && mpp[x] != y){
            ok = false;
        }

        if(x == 1 && y == 0) ok = false;

        else mpp[x] = y;
    }

    if(n == 1 && mpp[1] == 0){
        cout << 0;
        return 0;
    }

    if(m == 0 && n == 1){
        cout << 0;
        return 0;
    }

    if(m == 0 && n > 1){
        if(n == 2) cout << "10";
        else cout << "100";
        return 0;
    }

    if(!ok){
        cout << -1;
        return 0;
    }

    if(mpp[1] == 0){
        mpp[1] = 1;
    }

    for(int i = 1; i <= n; i++) cout << mpp[i];
}


#include <stdio.h>
#include <vector>
#include <queue>
using namespace std;
struct side{
    int n;
    int m;
    int l;
};
side sides[100000];
void mergesort(int l,int r){
    if(l==r)return;
    side temp;
    if(l==r-1){
        if(sides[l].l>sides[r].l){
            temp=sides[l];
            sides[l]=sides[r];
            sides[r]=temp;
        }
        return;
    }
    int mid=(l+r)/2,now=0;
    side b[r-l+1];
    mergesort(l,mid-1);
    mergesort(mid,r);
    for(int i=0;i<=r-l;i++){
        if(sides[i+l-now].l<sides[mid+now].l){
            b[i]=sides[i+l-now];
            if(i+l-now==mid-1){
                for(i++;i<=r-l;i++){
                    b[i]=sides[mid+now];
                    now++;
                }
            }
        }
        else{
            b[i]=sides[mid+now];
            now++;
            if(mid+now>r){
                for(i++;i<=r-l;i++)
                    b[i]=sides[i+l-now];
            }
        }
    }
    for(int i=0;i<=r-l;i++)
        sides[i+l]=b[i];
}
int main(){
    int n,m,a,ans=0,c=1;
    bool tree[10000];
    scanf("%d%d",&n,&m);
    if(m==0){
        printf("0\n");
        return 0;
    }
    tree[0]=true;
    for(int i=1;i<n;i++){
        tree[i]=false;
    }
    for(int i=0;i<m;i++){
        scanf("%d%d%d",&sides[i].n,&sides[i].m,&sides[i].l);
    }
    mergesort(0,m-1);
    while(c<n){
        a=0;
        while(tree[sides[a].n]==tree[sides[a].m])a++;
        ans+=sides[a].l;
        tree[sides[a].n]=tree[sides[a].m]=true;
        c++;
    }
    printf("%d\n",ans);
}

#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <climits>
#include <ctime>
using namespace std;

#define rep(i,a,n) for(int i=a; i<n; i++)
#define repr(i,a,n) for(int i=a; i>=n; i--)
#define pb(a) push_back(a)
#define fr first
#define sc second
#define INF INT_MAX

#define X real()
#define Y imag()
#define EPS (1e-10)
#define EQ(a,b) (abs((a) - (b)) < EPS)
#define EQV(a,b) ( EQ((a).X, (b).X) && EQ((a).Y, (b).Y) )
#define LE(n, m) ((n) < (m) + EPS)
#define GE(n, m) ((n) + EPS > (m))

typedef vector<int> VI;
typedef vector<VI> MAT;
typedef pair<int, int> pii;
typedef long long int ll;

typedef complex<double> P;
typedef pair<P, P> L;
typedef pair<P, double> C;

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

// ????????¨???????????????????¨???????????§???????
struct Edge {
    int from, to, cost;
    Edge(int f, int s, int d) : from(f), to(s), cost(d) {}
};

// 1??????????????????????????????????????±????????????????????????????????? vector
// Edges????????????????????????????????????????????°??????????????????
typedef vector<Edge> Edges;

// ???????????±??????????????? vector
// Graph??????????????????????????°?????????????????§??? V ??§?????????
typedef vector<Edges> Graph;

// union-find??¨
int uf[100010];
int rank[100010];

// ?????????
void init(int n) {
    rep(i,0,n) {
        uf[i] = i;
        rank[i] = 0;
    }
}

// find (??¨??????????±???????)
int find(int x) {
    if(uf[x] == x) return x;
    else return uf[x] = find(uf[x]);
}

// x ??¨ y ????±??????????????????????
void unite(int x, int y) {
    x = find(x);
    y = find(y);
    if(x == y) return;

    if(rank[x] < rank[y]) uf[x] = y;

    else {
        uf[y] = x;
        if(rank[x] == rank[y]) rank[x]++;
    }
}

// x ??¨ y ???????????????????±???????????????????
bool same(int x, int y) {
    return find(x) == find(y);
}

bool comp(const Edge &e1, const Edge &e2) {
    return e1.cost < e2.cost;
}

int kruskal(Graph &G) {
    int V = G.size();
    vector<Edge> es;
    rep(i,0,V) rep(j,0,G[i].size()) es.push_back(G[i][j]);
    int E = es.size();
    sort(es.begin(), es.end(), comp);
    init(V); int res = 0;
    for(int i=0; i<E; i++) {
        Edge e = es[i];
        if(!same(e.from, e.to)) {
            unite(e.from, e.to);
            res += e.cost;
        }
    }
    return res;
}

namespace std {
    bool operator<(const P a, const P b) {
        return a.X != b.X ? a.X < b.X : a.Y < b.Y;
    }
}

int main() {
    int V, E;
    cin >> V >> E;
    Graph G(V);
    int s, t, d;
    rep(i,0,E) {
        cin >> s >> t >> d;
        G[s].push_back(Edge(s,t,d));
        G[t].push_back(Edge(t,s,d)); // ????????°??????????????§
    }

    int ans = kruskal(G);
    cout << ans << endl;
    return 0;
}


#include <cstdio>
#include <cstring>
#include <cctype>
#include <algorithm>

using namespace std;

int getint()
{
    char ch=getchar();
    int f=1,x=0;
    while(!isdigit(ch)){if(ch=='-') f=-1; ch=getchar();}
    while(isdigit(ch)){x=x*10+ch-'0'; ch=getchar();}
    return f*x;
}

const int N=16;

int n,m;
int map[N][N];
int f[1<<15][N];
int slf[1<<15],ot[1<<15][N];
int tot;

void init()
{
    n=getint(),m=getint();
    for(int i=1; i<=m; i++){
        int u=getint(),v=getint(),w=getint();
        map[u][v]=map[v][u]=w;
        tot+=w;
    }
    for(int s=1; s<(1<<n); s++){
        for(int j=1; j<=n; j++){
            if(s&(1<<(j-1))){
                for(int k=j+1; k<=n; k++){
                    if(!(s&(1<<(k-1)))) continue;
                    slf[s]+=map[j][k];
                }
            }else{
                for(int k=1; k<=n; k++){
                    if(!(s&(1<<(k-1)))) continue;
                    ot[s][j]+=map[j][k];
                }
            }
        }
    }
}

int main()
{
    init();
    memset(f,128,sizeof(f));
    f[1][1]=0;
    for(int s=1; s<(1<<n); s+=2){
        for(int i=1; i<=n; i++){
            if(!(s&(1<<(i-1)))) continue;
            for(int t=s&(s-1); t; t=s&(t-1)){
                if(!(t&1)) continue;
                f[s][i]=max(f[s][i],f[t][i]+slf[s^t]+ot[s^t][i]);
            }
            for(int j=1; j<=n; j++){
                if(i==j || !(s&(1<<(j-1)))) continue;
                if(map[i][j]==0) continue;
                f[s][i]=max(f[s][i],f[s^(1<<(i-1))][j]+map[i][j]);
            }
        }
    }
    printf("%d\n",tot-f[(1<<n)-1][n]);
    return 0;
}

#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
#define REP(i,n) for (int i = 1; i < (int)(n); i++)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define debug(var) do{cout << #var << " : "; view(var);}while(0)
template<class T> bool chmin(T &a, T b) {if(a>b) {a=b;return 1;}return 0;}
template<class T> bool chmax(T &a, T b) {if(a<b) {a=b;return 1;}return 0;}
using namespace std;
template<class T> void view(T e) {cout << e << endl;}
template<class T> void view(const vector<T> &v) {for(const auto &e : v){cout << e << " ";} cout << endl;}
template<class T> void view(const vector<vector<T>> &vv) {for(const auto &v : vv){view(v);}}
using vint = vector<int>;
using vvint = vector<vector<int>>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<int,int>;
const int inf = 1e9;
const ll inf_l = 1e18;
const int MAX = 1e5;

const double eps = 1e-1;

int main() {
    int n; cin >> n;
    vll x;
    rep(i,n) {
        double f; cin >> f;
        f *= inf;
        ll l = ll(f+eps);
        x.push_back(l);
    }
    vvint data(50,vint(50,0));
    vector<P> ct;
    rep(i,n) {
        int ct_2 = 0, ct_5 = 0;
        while (x[i] % 2 == 0) {
            ct_2++;
            x[i] /= 2;
        }
        while (x[i] % 5 == 0) {
            ct_5++;
            x[i] /= 5;
        }
        data[ct_2][ct_5]++;
        ct.push_back(P(ct_2,ct_5));
    }
    rep(i,50)rep(j,50) {
        if (i != 0) data[i][j] += data[i-1][j];
        if (j != 0) data[i][j] += data[i][j-1];
        if (i != 0 && j != 0) data[i][j] -= data[i-1][j-1];
    }
    ll ans = 0;
    rep(i,n) {
        int ct_2 = max(0,18 - ct[i].first);
        int ct_5 = max(0,18 - ct[i].second);
        int tmp = data[49][49];
        if (ct_5 != 0) tmp -= data[49][ct_5-1];
        if (ct_2 != 0) tmp -= data[ct_2-1][49];
        if (ct_5 != 0 && ct_2 != 0) tmp += data[ct_2-1][ct_5-1];
        if (ct_2 <= ct[i].first && ct_5 <= ct[i].second) tmp--;
        ans += tmp;
    }
    ans /= 2;
    cout << ans << endl;
}


#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("unroll-loops")
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define int long long
#define fr(i,a,b) for(int i = a ; i <= b ; ++i)
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define all(x) begin(x), end(x)
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x).size()
#define pb push_back
#define fst first
#define snd second
using namespace __gnu_pbds;
using ordered_set =
 tree<int, null_type,less<int>,
 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 pair<int, int> pii;
typedef vector<int> vi;typedef long double ld;
template<class T>
using min_heap = priority_queue<T,vector<T>,greater<T>>;
template<typename T> T gcd(T a, T b){return(b?__gcd(a,b):a);}
template<typename T> T lcm(T a, T b){return(a*(b/gcd(a,b)));}
template<class T> void re(T& x) { cin >> x; }
template<typename T>
void remdup(vector<T>& v) {
	sort(all(v)); v.erase(unique(all(v)), v.end());
}
template<typename T> void re(vector<T> &v) {trav(i,v) cin >> i;}
template<class H, class... T> void re(H& h, T&... t) { re(h); re(t...); }
void unsyncIO() { ios_base::sync_with_stdio(0); cin.tie(0); }
#ifdef np
#include "/home/o_o/MyCodes/pr.h"
#else
#define trace(...)
#endif

#define MOD 1000000007

void solve(){
	int cnt = 1 ;
	int n , x , t ;
	re(n,x,t);
	while(cnt*x<n) cnt++;
	cout << cnt * t << endl;
}

signed main() {
	unsyncIO();
	int tt =1 ;
	// cin >> tt;
	rep(i,0,tt) solve();

#ifdef np
	cout <<endl<<endl<< "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
	return 0;
}

 #include<bits/stdc++.h>
 // #include <ext/pb_ds/tree_policy.hpp>
 // #include <ext/pb_ds/assoc_container.hpp>
 #include<chrono>
  using namespace std;
   using namespace std::chrono;
  // using namespace __gnu_pbds;
 #define fastio     ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
 #define fi         first
 #define se         second
 #define int         long long
 #define pb         push_back
 #define emp        emplace_back
 #define vv(x)      vector<x>
 #define mp(x,y)    map<x,y>
 #define dq(x)      deque<x>
 #define pql(x)     priority_queue<x>
 #define pqs(x)     priority_queue<x,vv(x),greater<x> >
 //#define M          1000000007
 #define forf(i,a,b) for(int i=a;i<b;i++)
 #define it(x)      x::iterator
 #define ll         long long
 #define debug(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)
 #define time__(d)  for(long blockTime = 0; (blockTime == 0 ? (blockTime=clock()) != 0 : false); debug("%s time : %.4fs", d, (double)(clock() - blockTime) / CLOCKS_PER_SEC))
 #define vii        vector<int>
 #define big        1e12
 #define sm         -2e18
 #define mkr        make_pair
 #define vpi        vector<pair<int,int> >
 #define pii        pair<int,int>
 #define rng        500005
 #define sz(x)      (int)x.size()
 #define rv(x)      reverse(x.begin(),x.end())
 #define out(x)     cout<<x.fi<<" "<<x.se<<endl;
#define MEM(x,val) memset(x,val,sizeof(x))

 // typedef tree<pii, null_type, less<pii>, rb_tree_tag,
 //            tree_order_statistics_node_update>  odst;

void pr_init()
{

    #ifndef ONLINE_JUDGE
    freopen("gin.txt", "r", stdin);
   // freopen("output.txt", "w", stdout);

    #endif
}

void solve()
{
  int n,x,t;
  cin >> n >> x >> t;

  int an = ceil((double)n/(double)x)*t ;
  cout<<an;

}

int32_t main()
{
  pr_init();
  fastio;
  auto start = high_resolution_clock::now();
  solve();
  auto stop = high_resolution_clock::now();
  auto duration = duration_cast<microseconds>(stop - start);

    // cout << "Time taken by function: "
    //      << duration.count() << " microseconds" << endl;

  return 0;
}


/*{{{*/
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<string>
#include<iostream>
#include<sstream>
#include<set>
#include<map>
#include<queue>
#include<bitset>
#include<vector>
#include<limits.h>
#include<assert.h>
#define SZ(X) ((int)(X).size())
#define ALL(X) (X).begin(), (X).end()
#define REP(I, N) for (int I = 0; I < (N); ++I)
#define REPP(I, A, B) for (int I = (A); I < (B); ++I)
#define FOR(I, A, B) for (int I = (A); I <= (B); ++I)
#define FORS(I, S) for (int I = 0; S[I]; ++I)
#define RS(X) scanf("%s", (X))
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define CASET int ___T; scanf("%d", &___T); for(int cs=1;cs<=___T;cs++)
#define MP make_pair
#define PB push_back
#define MS0(X) memset((X), 0, sizeof((X)))
#define MS1(X) memset((X), -1, sizeof((X)))
#define LEN(X) strlen(X)
#define F first
#define S second
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef long double LD;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<PII> VPII;
typedef pair<LL,LL> PLL;
typedef vector<PLL> VPLL;
template<class T> void _R(T &x) { cin >> x; }
void _R(int &x) { scanf("%d", &x); }
void _R(LL &x) { scanf("%lld", &x); }
void _R(double &x) { scanf("%lf", &x); }
void _R(char &x) { scanf(" %c", &x); }
void _R(char *x) { scanf("%s", x); }
void R() {}
template<class T, class... U> void R(T &head, U &... tail) { _R(head); R(tail...); }
template<class T> void _W(const T &x) { cout << x; }
void _W(const int &x) { printf("%d", x); }
void _W(const LL &x) { printf("%lld", x); }
void _W(const double &x) { printf("%.16f", x); }
void _W(const char &x) { putchar(x); }
void _W(const char *x) { printf("%s", x); }
template<class T,class U> void _W(const pair<T,U> &x) {_W(x.F); putchar(' '); _W(x.S);}
template<class T> void _W(const vector<T> &x) { for (auto i = x.begin(); i != x.end(); _W(*i++)) if (i != x.cbegin()) putchar(' '); }
void W() {}
template<class T, class... U> void W(const T &head, const U &... tail) { _W(head); putchar(sizeof...(tail) ? ' ' : '\n'); W(tail...); }
#ifdef HOME
 #define DEBUG(...) {printf("# ");printf(__VA_ARGS__);puts("");}
#else
 #define DEBUG(...)
#endif
int MOD = 1e9+7;
void ADD(LL& x,LL v){x=(x+v)%MOD;if(x<0)x+=MOD;}
/*}}}*/
const int SIZE = 1e6+10;
int N,X;
LL b[SIZE],l[SIZE],u[SIZE];
bool used[SIZE];
int main(){
    R(N,X);
    LL need=0;
    priority_queue<PLL>h0,h1,h2;
    REP(i,N){
        R(b[i],l[i],u[i]);
        need+=b[i]*l[i];
        h0.push({l[i]*b[i]+u[i]*(X-b[i]),i});
    }
    LL an=0;
    while(need>=h0.top().F){
        an+=X;
        used[h0.top().S]=1;
        need-=h0.top().F;
        h0.pop();
    }
    if(need<=0){
        W(an);
        return 0;
    }
    int add_id=h0.top().S;
    LL add_v=l[add_id]*b[add_id]+u[add_id]*(X-b[add_id]);
    LL mi=1e18;
    REP(i,N){
        if(used[i]){
            LL need2=need-add_v+l[i]*b[i]+u[i]*(X-b[i]);

            if(l[i]*b[i]>=need2){
                mi=min(mi,(need2+l[i]-1)/l[i]);
            }
            else{
                mi=min(mi,(need2-l[i]*b[i]+u[i]-1)/u[i]+b[i]);
            }
        }
        else{
            if(l[i]*b[i]+u[i]*(X-b[i])<need)continue;
            if(l[i]*b[i]>=need){
                mi=min(mi,(need+l[i]-1)/l[i]);
            }
            else{
                mi=min(mi,(need-l[i]*b[i]+u[i]-1)/u[i]+b[i]);
            }
        }
    }
    an+=mi;
    W(an);
    return 0;
}

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=100005;
struct sj{
	int a,l,r;ll x;
	inline sj(){}
	inline sj(int a,int l,int r,ll x):a(a),l(l),r(r),x(x){}
	inline bool operator<(const sj &t)const{return x>t.x;}
}d[N];
inline void cmax(ll &a,ll b){if(a<b)a=b;}
inline ll Y(int i,ll k){
	ll a=d[i].a;
	if(k<=a)return k*d[i].l;
	else    return k*d[i].r+a*(d[i].l-d[i].r);
}
int main(){
	int n,i,a,l,r,x;
	ll L=0ll,R,M,S,g=0ll,t1,t2;
	scanf("%d%d",&n,&x);R=(S=(t1=((ll)x))*n)-1ll;
	for(i=1;i<=n;++i){
		scanf("%d%d%d",&a,&l,&r);t2=a;
		d[i]=sj(a,l,r,t1*r+t2*(l-r));
		g+=l*t2;
	}
	sort(d+1,d+n+1);
	while(L<=R){
		M=(L+R)>>1;
		l=M/x;
		r=M%x;
//		printf("M=%lld l=%d r=%d",M,l,r);
//		for(i=1;i<=n;++i)printf(" (%d,%d)",d[i].x,Y(i,r));
//		printf("\n");
		t1=-1000000000000ll;t2=0ll;
		for(i=1;i<=l;++i){
			t2+=d[i].x;
			cmax(t1,Y(i,r)-d[i].x);
		}
		t1+=d[i].x;
		for(   ;i<=n;++i)cmax(t1,Y(i,r));
		if(t1+t2>=g)R=(S=M)-1ll;else L=M+1ll;
	}
	printf("%lld",S);
	return 0;
}


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

long long N;
void input()
{
    cin >> N;
}

void solve()
{
    long long num = 0;
    long long t26[13]; long long n26 = 1;
    for (int i = 0; i < 13; ++i) { t26[i] = n26; n26 *= 26; }
    long long tborder[13]; tborder[0] = 0;
    for (int i = 1; i < 13; ++i) tborder[i] = tborder[i-1] + t26[i];

    for (int i = 0; i < 13; ++i){
        // cout << tborder[i] << " ";
        if (tborder[i] < N) continue;
        N -= tborder[i-1] + 1;
        stack<char> stk;
        while (i != 0){
            stk.push('a' + N % 26);
            N /= 26;
            --i;
        }
        while (!stk.empty()){
            cout << stk.top();
            stk.pop();
        }
        cout << endl;
        break;
    }
}

int main()
{
    cin.tie();
    ios::sync_with_stdio(false);
    // int ti = clock();
    input();
    solve();
    // printf("Execution Time: %.4lf sec\n", 1.0 * (clock() - ti) / CLOCKS_PER_SEC);
    return 0;
}

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

int main(){
    long long N,a;
    int Z=26; //26^nで次のアルファベットの桁に移る
    string ans ="";
    cin >> N ;
    while(N>0){
        N--;
        a=N%Z;
        N/=Z;
        ans+='a'+a; //aから割ったあまりの分文字コードを移動する
    }
    reverse(ans.begin(),ans.end());
    cout << ans << endl;
}


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

int main(){
  int n, l;
  cin >> n >> l;
  int ans = 0;
  for(int i=l; i<l+n; ++i){
    if(l+n-1 < 0 && i == l+n-1) continue;
    if(l > 0 && i == l) continue;
    ans += i;
  }
  cout << ans << endl;
}

// Author : Harshdeep Sharma , IIT Indore
#pragma GCC optimize("O2")
#include <bits/stdc++.h>
using namespace std;
// #define MOD  998244353
#define ll long long
const double PI = atan(1.0) * 4;
// const ll INF = (int)1e9 ;
const int di[4] = { -1, 0, 1, 0} ;
const int dj[4] = {0, -1, 0, 1} ;
const ll INF = (ll)2e18 + 50;
const int maximum  = numeric_limits<int>::min();
const int minimum  = numeric_limits<int>::max();

// function to calculate any numbered power of some number without modulo
ll power(ll a , ll e) {
	ll res = 1LL ;
	while (e > 0) {
		if (e % 2 == 1) res = res * a;
		a =  a * a  ;
		e /= 2 ;
	}
	return res ;
}
// function to check whether a bracketed sequence is balanced or not
bool isBalanced(const string &exp) {
	// Initialising Variables
	bool flag = true;
	int count = 0;

	// Traversing the Expression
	for (int i = 0; i < exp.length(); i++) {

		if (exp[i] == '(') {
			count++;
		}
		else {
			count--;
		}
		if (count < 0) {
			flag = false;
			break;
		}
	}
	if (count != 0) {
		flag = false;
	}

	return flag;
}
// function to sort by second in a set of pairs
bool sortbysec(const pair<pair<int, int>, int> &a,
               const pair<pair<int, int>, int> &b) {
	return (a.second < b.second);
}

void uniformly_distribute_k_numbers_in_a_square_grid(int n , int k ) {
	int p = 0 , q = 0 ;
	vector<vector<int>> a(n, vector<int>(n)) ;
	for (int i = 1 ; i <= k ; ++i ) {
		a[p][q] = 1 ;
		p = p + 1 ;
		q = (q + 1) % n ;
		if (p == n) {
			p = 0  ;
			q = (q + 1) % n ;

		}
	}
}

ll f(ll n) {
	ll res ;
	if (n % 2 != 0) {
		ll pairs = (n + 1) / 2 ;
		if (pairs % 2 == 0) {
			res = 0  ;
		} else {
			res = 1 ;
		}
	} else {
		// cout << "i\n";
		ll pairs = n / 2 ;
		if (pairs % 2 == 0) {
			res = 0  ;
		} else {
			res = 1 ;
		}
		res ^= n ;
	}
	return res ;
}

// main funtion
int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	// int t ;
	// cin >> t ;
	// while (t--) {

	int n  , l ;
	cin >> n >> l ;
	int total = 0 ;
	int mn = 500 ;
	for (int i = 0 ; i < n ; i++) {
		total += (l + i) ;
		mn = min(mn , abs(l + i)) ;
	}
	// cout << total << " " << mn << "\n";
	if (total > 0) cout << total - mn << "\n";
	else cout << total + mn << "\n";

	// }

	return 0 ;
}


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

#define DIV 1000000007
#define TE 2e5
using namespace std;
using ll = long long;
using ldb = long double;

int main() {
	int N, M; cin >> N >> M;
	vector<vector<int>> A(N, vector<int>(M));
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < M; j++) {
			cin >> A[i][j];
			A[i][j]--;
		}
	}

	vector<bool> sp(M, true);
	int ans = 1e8;
	for (int k = 0; k < M - 1; k++) {
		vector<int> num(M);
		int temp = 0, id = 0;
		for (int i = 0; i < N; i++) {
			for (int j = 0; j < M; j++) {
				int a = A[i][j];
				if (sp[a]) {
					num[a]++;
					if (temp < num[a])
						temp = num[a], id = a;
					break;
				}
			}
		}
		//cout << "temp=" << temp << endl;
		sp[id] = false;
		if (temp == 0)continue;
		ans = min(ans, temp);
	}
	cout << (M == 1 ? N : ans) << endl;
}

#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<cctype>
#include<string.h>
#include <stdlib.h>

#define PI 3.1415926
void swap(int* x, int* y) {
	int a = *x;
	int b = *y;
	*x = b;
	*y = a;
}
int factorial(int n);
int sum(int n, int*);
int ave(int n, int*);
int min(int n, int*), min(int n, int m);
int max(int n, int*), max(int n, int m);

int main() {
	int N, M, A[2000], B[2000];
	int V[2000] = { 0 };
	int max = 0;
	int ans;
	scanf("%d %d", &N, &M);
	for (int i = 1; i <= N; i++) {
		scanf("%d", &A[i]);
	}
	for (int i = 1; i <= M; i++) {
		scanf("%d", &B[i]);
	}
	for (int i = 1; i <= M; i++) {
		for (int j = 1; i <= N; j++) {
			if (A[j] <= B[i]) {
				V[j]++;
				break;
			}
		}
	}
	for (int i = 1; i <= N; i++) {
		//printf("%d\n", V[i]);
		if (max < V[i]) {
			max = V[i];
			ans = i;
		}
	}
	printf("%d\n", ans);
	return 0;
}

int factorial(int n) {
	if (n > 0) {
		return n * factorial(n - 1);
	}
	else {
		return 1;
	}
}
int sum(int n, int *all) {
	int total = 0;
	for (int i = 0; i < n; ++i) {
		total += all[i];
	}
	return total;
}
int ave(int n, int *all) {
	int total = 0;
	for (int i = 0; i<n; ++i) {
		total += all[i];
	}
	return total / n;
}
int min(int n, int *all) {

	int min = all[0];
	for (int i = 1; i < n; ++i) {
		if (all[0] > all[i]) {
			min = all[i];
		}
	}
	return min;
}
int max(int n, int *all) {
	int max = all[0];
	for (int i = 1; i<n; ++i) {
		if (all[0]<all[i]) {
			max = all[i];
		}
	}
	return max;
}
int max(int n, int m) {
	if (n >= m) {
		return n;
	}
	else {
		return m;
	}
}
int min(int n, int m) {
	if (n >= m) {
		return m;
	}
	else {
		return n;
	}
}


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

#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long int n,a,i,k,x;
    cin >> n;
    k=0;x=n;
    for(i=0;i<n;i++)
    {
        cin >> a;
    if(a<=x)
    {
        k++;
        x=a;
    }
    }

    cout << k << endl;

}


#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;
using ll = long long;
int main(void){
    int N,K;
    cin>>N>>K;
    int ans=0;
    if(N%K!=0){
        ans=1;
    }

    cout<<ans<<endl;

}

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

int main()
{
    int N,K;
    cin >> N >> K;
    if(N < K){
        cout << 1 << endl;
        return 0;
    }
    if(N%K == 0){
        cout << 0 << endl;
        return 0;
    }
    cout << N%K+1 - N%K << endl;
}


// God put a smile upon your face <3

#include <bits/stdc++.h>

#define slld(longvalue) scanf("%lld", &longvalue)

#define ll long long
#define ull unsigned long long
#define pll pair < long long, long long >

#define fastio ios_base:: sync_with_stdio(false); cin.tie(0); cout.tie(0)

#define pb push_back

#define bug printf("BUG\n")

#define mxlld LLONG_MAX
#define mnlld -LLONG_MAX

#define mxd 2e8
#define mnd -2e8

#define pi 3.14159265359

using namespace std;

bool check(ll n, ll pos)
{
	return n & (1LL << pos);
}

ll Set(ll n, ll pos)
{
	return n = n | (1LL << pos);
}

int main()
{
    ll i, j, k, l, m, n, o, r, q;
    ll testcase;
    ll input, flag, tag, ans;

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

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

    double rad;

    while(cin >> rad)
    {
		cout << setprecision(10) << fixed << 2.0 * acos(-1.0) * rad << "\n";
    }

}

#include<bits/stdc++.h>

typedef  long long ll;
//forループ
//引数は、(ループ内変数,動く範囲)か(ループ内変数,始めの数,終わりの数)、のどちらか
//Dがついてないものはループ変数は1ずつインクリメントされ、Dがついてるものはループ変数は1ずつデクリメントされる
#define REP(i,n) for(ll i=0;i<ll(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=ll(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=ll(b);i--)
//
//
#define int long long

using namespace std;

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

 ll  a,b,c,s,t,i,j,k,x,y,z;
 ll A,B,C,S,T,X,Y,Z;
 ll count;

 long double pi=3.14159;

signed main(){

	cin>>a;

	cout<<2*a*pi;

 return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define rg register
#define rep(i,a,b) for (rg int i=(a);i<=(b);i++)
#define per(i,a,b) for (rg int i=(b);i>=(a);i--)
#define pb push_back
#define lowbit(x) (x&(-x))
#define replow(i,a,b) for(rg int i = (a);i<=(b);i+=lowbit(i))
#define perlow(i,a,b) for(rg int i = (b);i>=(a);i-=lowbit(i))
#define mk make_pair
#define VI vector<int>
#define pii pair<int,int>
#define pLL pair<long long,long long>
#define fi first
#define se second
#define il inline
#define ll long long
#define ull unsigned long long
#define db double
#define ld long double
#define inf 0x3f3f3f3f
#define getc() (p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<15,stdin),p1==p2)?EOF:*p1++)
char buf[1<<15],*p1 = buf,*p2 = buf;
inline ll read(){
    #define num ch-'0'
    char ch;bool flag=0;ll res;
    while(!isdigit(ch=getc()))
    (ch=='-')&&(flag=true);
    for(res=num;isdigit(ch=getc());res=res*10ll+num);
    (flag)&&(res=-res);
    #undef num
    return res;
}
inline void write(ll x){
	if (x < 0) x = ~x + 1ll, putchar('-');
	if (x > 9) write(x / 10ll);
	putchar(x % 10ll + '0');
}
#define mid ((l + r)>>1)
#define ls (x<<1)
#define rs ((x<<1)|1)
#undef mid
#undef ls
#undef rs
multiset<int> s;
void solve()
{
	int n = read();
	int mn = 1e9 + 10;
	int cnt = 0;
	rep(i,1,n)
	{
		int x = read();
		if(s.empty())
		{
			s.insert(x);
		}
		else
		{
			auto it = s.lower_bound(x);
			if(it == s.begin())
			{
				s.insert(x);
			}
			else
			{
				it--;
				s.erase(it);
				s.insert(x);
			}
		}
	}
	printf("%d",s.size());
}
int main()
{
	#ifndef ONLINE_JUDGE
	freopen("data.txt","r",stdin);
	#endif
//	int T = read();
//	while(T--)
	solve();
}

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

int main() {
    int sx, sy, tx, ty;
    cin >> sx >> sy >> tx >> ty;
    int x = tx-sx, y = ty-sy;
    rep(i,x) cout << 'R';
    rep(i,y) cout << 'U';
    rep(i,x) cout << 'L';
    rep(i,y) cout << 'D';
    cout << 'D';
    rep(i,x+1) cout << 'R';
    rep(i,y+1) cout << 'U';
    cout << 'L';
    cout << 'U';
    rep(i,x+1) cout << 'L';
    rep(i,y+1) cout << 'D';
    cout << 'R';
    return 0;
}


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

#define DEBUG 0

#if DEBUG
  #define DLOG(...) fprintf(stderr, __VA_ARGS__)
#else
  #define DLOG(...)
#endif

void debug(auto f) {
#if DEBUG
  f();
#endif
}

ll mPrime = int(1e9) + 7;
ll bN, bX;
vector<ll> bS;
vector<ll> facts;
vector<ll> invFacts;
vector<int> tbl;
vector<int> low;  // low[y] == #{ i | s[i] <= y }

ll mAdd(ll x, ll y) {
  ll z = x + y;
  if (z < mPrime)  return z;
  else             return (z - mPrime);
}

ll mSub(ll x, ll y) {
  ll z = x - y;
  if (z >= 0)  return z;
  else         return (z + mPrime);
}

ll mMul(ll x, ll y) {
  return (x * y) % mPrime;
}

ll eGCD(ll a, ll b, ll& s, ll& t) {
  if (a == 0) {
    s = 0;
    t = 1;
    return b;
  }
  ll u;
  ll g = eGCD(b % a, a, t, u);
  s = u - (b / a) * t;
  return g;
}

ll mInv(ll x) {
  ll s, t;
  eGCD(x, mPrime, s, t);
  return s < 0 ? s + mPrime : s;
}

ll tight(ll);

ll loose(ll y, ll len) {
  ll result = mMul(tight(y), mMul(facts.at(len), invFacts.at(low.at(y))));
  DLOG("loose(%lld, %lld) = %lld\n", y, len, result);
  return result;
}

ll tight(ll y) {
  if (tbl.at(y) >= 0)  return tbl.at(y);
  ll len = low.at(y);
  if (len == 0)  return y;
  ll result = 0;
  for (ll i = 0; i < len; i++) {
    ll z = y % bS.at(i);
    result = mAdd(result, loose(z, len-1));
  }
  tbl.at(y) = result;
  DLOG("tight(%lld) = %lld\n", y, result);
  return result;
}

int main() {
  cin >> bN >> bX;
  bS.resize(bN);
  for (ll i = 0; i < bN; i++) {
    cin >> bS.at(i);
  }
  facts.resize(bN+1);
  invFacts.resize(bN+1);
  facts.at(0) = invFacts.at(0) = 1;
  for (ll i = 1; i <= bN; i++) {
    facts.at(i) = mMul(i, facts.at(i-1));
    invFacts.at(i) = mInv(facts.at(i));
  }
  sort(bS.begin(), bS.end());

  low.resize(bX+1);
  ll idx = 0;
  for (ll i = 0; i < bX+1; i++) {
    if (idx < (ll) bS.size() && bS.at(idx) == i)  idx++;
    low.at(i) = idx;
  }

  tbl.resize(bX+1, -1);
  ll ans = loose(bX, bS.size());
  cout << ans << endl;

  return 0;
}

#include<cstdio>
#include<iostream>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<functional>
#include<set>
#include<map>
using namespace std;
#define rep(i,l,r) for(register int i=(l);i<=(r);++i)
#define repdo(i,l,r) for(register int i=(l);i>=(r);--i)
#define il inline
typedef double db;
typedef long long ll;

//---------------------------------------
namespace ubospica{

const int nsz=205,vsz=1e5+50;
const ll nmod=1e9+7;
int n;
ll x,li[nsz];
ll ans,dp[vsz];
ll inv[vsz]{0,1};
void init(int bnd){rep(i,2,bnd)inv[i]=inv[nmod%i]*((ll)nmod-nmod/i)%nmod;}//be aware of overflow!

void add(ll &a,ll b){a=(a+b)%nmod;}
void mul(ll &a,ll b){a=a*b%nmod;}
int main(){
	ios::sync_with_stdio(0),cin.tie(0);
	cin>>n>>x;
	rep(i,1,n)cin>>li[i];
	sort(li+1,li+n+1,greater<int>());
	init(1e5+5);
	ll tmp;
	dp[x]=1;
	rep(i,1,n){
		rep(j,0,x){
			tmp=dp[j],dp[j]=0;
			add(dp[j%li[i]],tmp*inv[n-i+1]);
			add(dp[j],tmp*(n-i)%nmod*inv[n-i+1]);
		}
	}
	ans=0;
	rep(i,0,x)
		add(ans,i*dp[i]);
	rep(i,1,n)mul(ans,i);
	cout<<ans<<'\n';
	return 0;
}

}

int main(){return ubospica::main();}

//	freopen(".in","r",stdin);
//	freopen(".out","w",stdout);


#include <iostream>
#include <cstring>
using namespace std;
int main()
{
	int n, i, j, k, c, x;
	char s[1001], r[1001], t[8] = "Hoshino";
	cin >> n;
	cin.ignore(1024, '\n');
	for (i = 0; i < n; i++)
	{
		cin.getline(s, sizeof(s));
		c = 0;
		for (j = 0; j < strlen(s); j++)
		{
			r[c] = s[j];
			c++;
			if (s[j] == 'H')
			{
				for (k = j+1, x = 0; k < j+7; k++, c++)
				{
					if (s[k] == t[k-j])
					{
						if (k == j+6)
							r[c] = 'a';
						else
							r[c] = t[k-j];
						x++;
					}
					else
					{
						r[c] = s[k];
						break;
					}
				}
				j+=x;
			}
		}
		r[strlen(s)] = '\0';
		cout << r << endl;
	}
}

#include <iostream>
#include <cstring>
#include <string>

using namespace std;

int main(){
    string s;
    int n;
    int c_pos;
    cin>>n;
    cin.ignore();
    while(n--){
        getline(cin,s);
        while((c_pos=s.find("Hoshino"))!=string::npos){
            s.replace(c_pos,7,"Hoshina");
        }
        cout<<s<<endl;
    }
}


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

int main(){
    int N, X, T;
    cin >> N >> X >> T;

    int minute = 0;

    while(N > 0){
        minute += T;
        N -= X;
    }

    cout << minute << endl;
}

#include <bits/stdc++.h>

using i16 = std::int16_t;
using i32 = std::int32_t;
using i64 = std::int64_t;
using usize = std::size_t;
template<typename T>
using Vector = std::vector<T>;
using String = std::string;
template<typename T>
using UniquePointer = std::unique_ptr<T>;
using namespace std;

#define rep(i, max) for(usize i = 0; i < max; ++i)
#define loop while(true)

UniquePointer<String> readLine() {
    UniquePointer<String> line(new String());
    getline(cin, *line);
    return line;
}

template<typename T>
UniquePointer<Vector<T>> readVector(usize num) {
    UniquePointer<Vector<T>> list(new Vector<T>(num));
    rep(i, num) {
        cin >> (*list)[i];
    }
    return list;
}

template<typename T>
void writeLine(T arg) {
    cout << arg << endl;
}

template<typename T>
void write(T arg) {
    cout << arg << std::flush;
}

void program();

int main()
{
    ios::sync_with_stdio(false);
    program();
}

void program() {
    i32 n, x, t;
    cin >> n;
    cin >> x;
    cin >> t;
    readLine();
    writeLine((i32)(ceil((double)n / x) * t));
}


#include<bits/stdc++.h>
#define fi first
#define se second
#define lc (x<<1)
#define rc (x<<1|1)
#define gc getchar()//(p1==p2&&(p2=(p1=buf)+fread(buf,1,size,stdin),p1==p2)?EOF:*p1++)
#define mk make_pair
#define pi pair<int,int>
#define pb push_back
#define IT iterator
#define SZ(a) ((int)a.size())
#define all(a) a.begin(),a.end()
using namespace std;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
const int N=4e5+10,size=1<<20,mod=998244353;
const ll inf=1e18;

template<class o> void qr(o &x) {
	char c=gc; x=0; int f=1;
	while(!isdigit(c)){if(c=='-')f=-1; c=gc;}
	while(isdigit(c)) x=x*10+c-'0',c=gc;
	x*=f;
}
template<class o> void qw(o x) {
	if(x/10) qw(x/10);
	putchar(x%10+'0');
}
template<class o> void pr1(o x) {
	if(x<0)x=-x,putchar('-');
	qw(x); putchar(' ');
}
template<class o> void pr2(o x) {
	if(x<0)x=-x,putchar('-');
	qw(x); puts("");
}

int n,dic[150],f[N*2][2],g[N*2][2];
ll ans=inf;
vector<pi> x[N],y[N];

int main() {
	qr(n);
	dic['U']=0;
	dic['D']=1;
	dic['R']=2;
	dic['L']=3;
	for(int i=1;i<=n;i++) {
		int a,b,c;qr(a); qr(b);
		char str[6]; scanf("%s",str);
		a++; b++; c=dic[str[0]];
		x[a].pb(mk(b,c));
		y[b].pb(mk(a,c));
	}
	for(int i=1;i<N;i++) {
		sort(all(x[i]));
		sort(all(y[i]));
		ll a,b;
		a=b=inf;
		for(auto j:x[i]) {
			if(j.se==0) a=j.fi;
			else if(j.se==1) b=j.fi;
			if(a<b) ans=min(ans,(b-a)*5);
		}
		a=b=inf;
		for(auto j:y[i]) {
			if(j.se==2) a=j.fi;
			else if(j.se==3) b=j.fi;
			if(a<b) ans=min(ans,(b-a)*5);
		}
	}
	for(int i=1;i<N;i++)
		for(auto j:x[i]) {
			int t=j.fi;
			if(j.se==2) {
				f[j.fi-i+N][0]=i;
				f[j.fi+i][1]=i;
			}
			else if(j.se==3) {
				int k=g[j.fi+i][1];
				if(k) ans=min(ans,(i-k)*10LL);
				k=g[j.fi-i+N][0];
				if(k) ans=min(ans,(i-k)*10LL);
			}
			else if(j.se==1) {
				int k=f[j.fi-i+N][0];
				if(k) ans=min(ans,(i-k)*10LL);
				g[j.fi+i][1]=i;
			}
			else if(j.se==0) {
				int k=f[j.fi+i][1];
				if(k) ans=min(ans,(i-k)*10LL);
				g[j.fi-i+N][0]=i;
			}
		}
	if(ans>inf/2) puts("SAFE");
	else pr2(ans);
	return 0;
}

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

#define rep(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

#ifdef LOCAL
    #define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
    #define eprintf(...) 42
#endif

ll n, m;

struct numinfo {
	int digit;
	int match;
	int min_match;
	int n;
};

vector<numinfo> nums;

bool dfs( int i, int remain_match, int remain_keta ){
	if ( i == SZ(nums) ){
		eprintf( "remain=%d %d   ", remain_match, remain_keta );
		rep(k,SZ(nums)){
			eprintf( "%d ", (int)nums[k].n );
		}
		eprintf( "\n" );
		if ( remain_match == 0 && remain_keta <= 0 )
			return true;
		return false;
	}
	for ( int k = remain_match/nums[i].match; k >= 0; k-- ){
		nums[i].n = k;
		int creatable_keta = (remain_match-k*nums[i].match)/nums[i].min_match;
		if ( remain_keta-k-creatable_keta > 0 )
			continue;
		if ( dfs( i+1, remain_match-k*nums[i].match, remain_keta-k ) )
			return true;
	}
	return false;
}

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

	vector<int> a(m);
	rep(i,m){
		cin >> a[i];
	}
	sort(a.rbegin(),a.rend());

	int digit_to_match[] = { 0, 2, 5, 5, 4, 5, 6, 3, 7, 6 };
	set<int> s;
	rep(i,m){
		int match = digit_to_match[a[i]];
		if ( s.count(match) == 0 )
			nums.push_back({a[i],match,100,0});
		s.insert(match);
	}
	m = nums.size();

	int min_match = 100;
	for ( int i = nums.size()-1; i >= 0; i-- ){
		nums[i].min_match = min_match;
		chmin(min_match, nums[i].match);
		eprintf( "digit,=%d match=%d min_match=%d\n", nums[i].digit, nums[i].match, nums[i].min_match );
	}

	for ( int keta = n / min_match; keta > 0; keta-- ){
		eprintf( "\n\nketa=%d\n", keta );
		if ( dfs( 0, n, keta ) ){
			sort(nums.begin(), nums.end(), [](numinfo &l, numinfo &r){
				return l.digit>r.digit;
			});
			rep(i,m){
				rep(j,nums[i].n){
					cout << nums[i].digit;
				}
			}
			cout << endl;
			return 0;
		}
	}

	return 0;
}


#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll mod = 1000000007;
const ll INF = (ll)1000000007 * 1000000007;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef long double ld;
typedef complex<ld> Point;
const ld eps = 1e-11;
const ld pi = acos(-1.0);
typedef pair<ll, ll> LP;
typedef pair<ld, ld> LDP;
struct rect { ll hei; int pos; };
ll getmaxrect(int size, ll buffer[]) {
	stack<rect> s;
	ll res = 0;
	buffer[size] = 0;
	for (int i = 0; i <= size; i++) {
		rect rec;
		rec.hei = buffer[i];
		rec.pos = i;
		if (s.empty()) {
			s.push(rec);
		}
		else {
			if (s.top().hei < rec.hei) {
				s.push(rec);
			}
			else if (s.top().hei > rec.hei) {
				int tag = i;
				while (!s.empty() && s.top().hei >= rec.hei) {
					rect pre = s.top(); s.pop();
					ll area = (pre.hei+1)*(i - pre.pos+1);
					res = max(res, area);
					tag = pre.pos;
				}
				rec.pos = tag;
				s.push(rec);
			}
		}
	}
	return res;
}
int p[2000][2000];
char t[2000][2000];
ll hi[2000][2000];
int main() {
	ll buffer[2001];
	int h, w; cin >> h >> w;
	rep(i, h) {
		string s; cin >> s;
		rep(j, w) {
			t[i][j] = s[j];
		}
	}
	rep(i, h - 1) {
		rep(j, w - 1) {
			int cnt = 0;
			rep(k, 2) {
				rep(l, 2) {
					if (t[i + k][j + l] == '#')cnt++;
				}
			}
			if (cnt % 2)p[i][j] = 1;
		}
	}
	rep(j, w - 1) {
		hi[0][j] = 1;
		if (p[0][j])hi[0][j] = 0;
		rep1(i, h - 2) {
			if (p[i][j])hi[i][j] = 0;
			else hi[i][j] = hi[i - 1][j] + 1;
		}
	}
	ll out = max(h,w);
	rep(i, h - 1) {
		rep(j, w - 1) {
			buffer[j] = hi[i][j];
		}
		out = max(out, getmaxrect(w - 1, buffer));
	}
	cout << out << endl;
	return 0;
}

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

using namespace std;

typedef long long ll;

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

	int n;
	cin >> n;

	string s;
	cin >> s;

	int q;
	cin >> q;

	vector<int> v(q);
	rep(i, q) cin >> v[i];

	vector<int> dsum(n+1, 0);
	rep(i, n) dsum[i+1] += dsum[i] + (s[i] == 'D' ? 1 : 0);

	for(int k : v){
		ll ans = 0;
		deque<int> q;

		ll t = 0;
		for(int i = 0; i < n; i++){
			if(i-k >= 0 && s[i-k] == 'D'){
				t -= q.size();
			}

			if(q.size() > 0 && q.back() < i - (k - 2)){
				q.pop_back();
			}

			if(s[i] == 'M'){
				q.push_front(i);
				t += dsum[i] - dsum[max(i-(k-1), 0)];
			}

			if(s[i] == 'C') ans += t;
		}

		cout << ans << endl;
	}
}


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

vector<int> to[600];//[]の中の人がどこに行けるか
bool res[600] = {};

void bfs()
{
	queue<int> q;

	for(int i=0;i<to[1].size();++i){
		q.push(to[1][i]);
	}
	for(int i=0;i<2;++i)
	{
		int size = q.size();
		for(int i=0;i<size;++i)
		{
			int now = q.front();q.pop();
			if(res[now]) continue;
			res[now] = true;
			for(int i=0;i<to[now].size();++i){
				q.push(to[now][i]);
			}
		}
	}
}

int main(void)
{
	while(1)
	{
		for(int i=0;i<501;++i){
			to[i].clear();
			res[i] = false;
		}
		int n;
		int m;
		cin >> n >> m;
		if(n == 0 || m == 0) return 0;
		for(int i=0;i<m;++i){
			int a,b;
			cin >> a >> b;
			to[a].push_back(b);
			to[b].push_back(a);
		}
		bfs();
		int count = 0;
		for(int i=2;i<501;++i){
			if(res[i])
				++count;
		}
		cout << count << endl;
	}
	return 0;
}

#include <iostream>
#include <vector>
#include <set>
#include <cstring>	// require memset
//#include <fstream>	// require freopen

using namespace std;

const int N = 501;
bool t[N][N];

int main()
{
//	cut here before submit
//	freopen ("testcase.party", "r", stdin );
	int n, m;

	while (cin >> n >> m && n && m ){
		int i,j;

		memset (t, false, sizeof (t ) );

		for (i = 0; i < m; ++i){
			int from, to;
			cin >> from >> to;
			t[from][to] = true;
			t[to][from] = true;
		} // end for
		set <int> res;

		for (i = 2; i <= n; ++i ){
			if (t[1][i] ){
				res.insert (i );
				for (j = 2; j <= n; ++j ){
					if (t[i][j]){
						res.insert (j );
					} // end if
				} // end for
			} // end if
		} // end for
		if (!res.empty() ){
			cout << res.size() << endl;
		}else{
			cout << '0' << endl;
		} // end if
	} // end loop

	return 0;
}


#include <bits/stdc++.h>
using ll = long long;
using namespace std;
#define rep(i, n) for (int i = 0, i##_len = (int)(n); i < i##_len; i++)
#define reps(i, n) for (int i = 1, i##_len = (int)(n); i <= i##_len; i++)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rreps(i, n) for (int i = ((int)(n)); i > 0; i--)
#define repi(i, x) \
	for (auto i = (x).begin(), i##_fin = (x).end(); i != i##_fin; i++)
#define all(x) (x).begin(), (x).end()
#define F first
#define S second
#define mp make_pair
#define pb push_back
#define solve(a) ((a) ? "Yes" : "No")
typedef vector<int> Vi;
typedef vector<Vi> VVi;
typedef pair<int, int> Pi;
typedef vector<Pi> VPi;
typedef vector<long long> V;
typedef vector<V> VV;
typedef pair<long long, long long> P;
typedef vector<P> VP;
template <class T>
inline bool chmax(T& a, T b) {
	if (a < b) {
		a = b;
		return 1;
	}
	return 0;
}
template <class T>
inline bool chmin(T& a, T b) {
	if (a > b) {
		a = b;
		return 1;
	}
	return 0;
}
const long long INFLL = 1LL << 60;
const int INF         = 1 << 30;
const double PI       = acos(-1);
int main() {
	int n;
	int ans = 0;
	cin >> n;
	int v;
	pair<Pi, Pi> as = mp(mp(0, 0), mp(0, 0));
	pair<Pi, Pi> bs = mp(mp(0, 0), mp(0, 0));
	pair<map<int, int>, map<int, int>> dis;
	rep(i, n) {
		cin >> v;
		if (i % 2) {
			dis.F[v]++;
		} else {
			dis.S[v]++;
		}
	}
	repi(itr, dis.F) {
		if (itr->S > as.F.S) {
			as.S = as.F;
			as.F = *itr;
		} else if (itr->S > as.S.S) {
			as.S = *itr;
		}
	}
	repi(itr, dis.S) {
		if (itr->S > bs.F.S) {
			bs.S = bs.F;
			bs.F = *itr;
		} else if (itr->S > bs.S.S) {
			bs.S = *itr;
		}
	}
	if (as.F.F != bs.F.F) {
		ans = n - as.F.S - bs.F.S;
	} else {
		ans = n - max(as.F.S + bs.S.S, as.S.S + bs.F.S);
	}

	cout << ans << endl;
}

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define Would
#define you
#define please

int D;
ll kotae = 0;
void keisan(ll A, int B, int C, vector<int> V) {
	if (B < C / 2) {
		ll k1 = 1, k2 = 1;
		rep(i, C - B - 1) k1 *= 10;
		rep(i, B) k2 *= 10;
		ll k = k1 - k2;
		if (A >= 0) {
			if (abs(A / k) < 10) {
				V.pb(A / k);
				keisan(A % k, B + 1, C, V);
				V.pop_back();
			}
			if (abs(A / k + 1) < 10) {
				V.pb(A / k + 1);
				keisan(A % k - k, B + 1, C, V);
			}
		}
		else {
			if (abs(A / k) < 10) {
				V.pb(A / k);
				keisan(A % k, B + 1, C, V);
				V.pop_back();
			}
			if (abs(A / k - 1) < 10) {
				V.pb(A / k - 1);
				keisan(A % k + k, B + 1, C, V);
			}
		}
	}
	else {
		if (A == 0) {
			ll kari = 1;
			rep(j, V.size()) {
				int kari2 = 0;
				if (j == 0) {
					rep1(k, 9) {
						if (k + V[j] < 10) kari2++;
					}
				}
				else {
					rep(k, 10) {
						if (k + V[j] >= 0 && k + V[j] < 10) kari2++;
					}
				}
				kari *= kari2;
			}
			if (C % 2) kari *= 10;
			kotae += kari;
		}
	}
}

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

	cin >> D;

	for (int i = 19; i >= 2; i--) {
		vector<int> V;
		keisan(D, 0, i, V);
	}

	co(kotae);

	Would you please return 0;
}


#include<bits/stdc++.h>

using namespace std;

int main(){

  int n;

  while(cin>>n,n){

	vector<int> k(n);
	string s;

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

	cin>>s;

	int key=0;

	for(int i=0;i!=s.size();++i){
	  for(int j=0;j<k[key];++j){
		if(s[i]=='a')
		  s[i]='Z';
		else  if(s[i]=='A')
		  s[i]='z';
		else
		  s[i]--;
	  }
	  if(key==n-1)
		key=0;
	  else
		key++;
	}

	cout<<s<<endl;

  }

}

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

int main() {
	int n,p;//~50
	int stone,player[50]={};
	int winner;
	int i;

	scanf("%d%d",&n,&p);
	while(1){
	for(i=0;i<50;i++){
		player[i]=0;
	}
	stone=p;
	for(i=0;;i++){
		if(stone==0){
			stone=player[i%n];
			player[i%n]=0;
		}
		else{
			stone-=1;
			player[i%n]+=1;
		}
		if((stone==0)&&(player[i%n]==p)){
			winner=i%n;
			break;
		}
	}
	printf("%d\n",winner);
	scanf("%d%d",&n,&p);
	if((n==0)&&(p==0)){break;}
	}
	return 0;
}


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

int main() {
    int k;
    vector<int> ab{0, 0};
    cin >> ab[0] >> ab[1] >> k;

    int i = 0;
    while (k--) {
        if (ab[i] & 1) {
            ab[i]--;
        }
        ab[i] >>= 1;
        ab[i ^ 1] += ab[i];
        i ^= 1;
    }
    cout << ab[0] << " " << ab[1] << endl;
}


#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <math.h>
using namespace std;

const int MAXN = 1e5 + 10;
int N, M;
int A[MAXN];
int cnt;

int main() {
	register int i, j = 0, k = 0;
	scanf("%d%d", &N, &M);
	for(i = 1; i <= M; ++i)
		scanf("%d", A + i),
		A[i] & 1 ? (++cnt, !j ? j = i : k = i) : 0;
	if(cnt > 2) return puts("Impossible"), 0;
	if(M == 1) {
		printf("%d\n", A[1]);
		printf("%d\n", A[1] == 1 ? 1 : 2);
		A[1] == 1 ? printf("%d\n", A[1]) : printf("1 %d\n", A[1] - 1);
		return 0;
	}
	if(j) swap(A[1], A[j]); if(k) swap(A[k], A[M]);
	for(i = 1; i <= M; ++i)
		printf("%d%c", A[i], " \n"[i == M]);
	++A[1], --A[M];
	if(A[M] == 0) --M;
	printf("%d\n", M);
	for(i = 1; i <= M; ++i)
		printf("%d%c", A[i], " \n"[i == M]);
	return 0;
}


#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <algorithm>
#include <cstdlib>
#include <ctime>
#include <cstdio>
#include <functional>
#include <set>
#include <sstream>
#include <map>
#include <queue>

using namespace std;

const double eps=1e-10;

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

class rect{
public:
	int h,w,d2;
	rect(int _h,int _w){h=_h; w=_w; d2=h*h+w*w;}
	bool operator<(const rect& r) const{
		return d2<r.d2 || d2==r.d2 && h<r.h;
	}

};

int main()
{

	vector< rect > vr;
	for(int h=1;h<=150;h++){
		for(int w=h+1;w<=150;w++) vr.push_back(rect(h,w));
	}
	sort(vr.begin(),vr.end());

	int h,w;
	while(cin>>h>>w,h){

		rect r(h,w);
		for(int i=0;i<vr.size();i++){
			if(r<vr[i]){
				cout<<vr[i].h<<" "<<vr[i].w<<endl;
				break;
			}
		}

	}

	return 0;
}

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

#define PI 4*atan(1)
#define INF 1e8

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

int main(){
  int m, n_min, n_max;
  while(cin >> m >> n_min >> n_max, m||n_min||n_max){
    vector<int> P(m);
    for(int i = 0; i < m; i++){
      cin >> P[i];
    }
    int diff = 0, ans;
    for(int i = n_min; i <= n_max; i++){
      if(diff <= P[i-1] - P[i]){
        diff = P[i-1] - P[i];
        ans = i;
      }
    }
    cout << ans << endl;
  }
}


#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cstdio>
#include <cmath>

using namespace std;

int main()
{
	int i = 0;
	char a[20];

	scanf("%s", a);

	while (1) {
		i++;
		if (a[i] == '\0') break;
	}
	i--;
	while (i != -1) {
		printf("%c", a[i]);
		i--;
	}
	printf("\n");

		return (0);

}

#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("unroll-loops")
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define int long long
#define fr(i,a,b) for(int i = a ; i <= b ; ++i)
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define all(x) begin(x), end(x)
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x).size()
#define pb push_back
#define fst first
#define snd second
using namespace __gnu_pbds;
using ordered_set =
 tree<int, null_type,less<int>,
 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 pair<int, int> pii;
typedef vector<int> vi;typedef long double ld;
template<class T>
using min_heap = priority_queue<T,vector<T>,greater<T>>;
template<typename T> T gcd(T a, T b){return(b?__gcd(a,b):a);}
template<typename T> T lcm(T a, T b){return(a*(b/gcd(a,b)));}
template<class T> void re(T& x) { cin >> x; }
template<typename T>
void remdup(vector<T>& v) {
	sort(all(v)); v.erase(unique(all(v)), v.end());
}
template<typename T> void re(vector<T> &v) {trav(i,v) cin >> i;}
template<class H, class... T> void re(H& h, T&... t) { re(h); re(t...); }
void unsyncIO() { ios_base::sync_with_stdio(0); cin.tie(0); }
#ifdef np
#include "C:\Users\navodit\Desktop\mycodes\pr.h"
#else
#define trace(...)
#endif

#define MOD 1000000007

void solve(){
	int n , r ;
	cin >> n >> r ;
	if(n<=10){
		cout << r + (100*(10-n)) << endl;
	}
	else cout << r << endl;
}

signed main() {
	unsyncIO();
	int tt =1 ;
	// cin >> tt;
	rep(i,0,tt) solve();

#ifdef np
	cout <<endl<<endl<< "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
	return 0;
}


#include <iostream>
#include <stdlib.h>
#define inf 99999

using namespace std;

bool check(int *label, int n)
{
	for(int i = 1; i <= n; i++){
		if(label[i] == 0){
			return true;
		}
	}

	return false;
}

void dij(int **a, int n, int s, int t)
{
	int *label, current=s, num=1, next, *cost, min;

	cost = (int *)calloc(n+1, sizeof(int));
	label = (int *)calloc(n+1, sizeof(int));

	for(int i = 1; i <= n; i++){
		cost[i] = a[current][i];
	}
	label[current] = num++;

	while(check(label, n)){
		min = inf;
		for(int i = 1; i <= n; i++){
			if(min >= cost[i] && label[i] == 0){
				min = cost[i];
				next = i;
			}
		}
		label[next] = num++;
		for(int i = 1; i <= n; i++){
			if(label[i] == 0 && cost[i] > (a[next][i]+cost[next])){
				cost[i] = a[next][i] + cost[next];
			}
		}
		current = next;
	}
	cout << cost[t] << endl;

	free(cost);
	free(label);

	return ;
}

int main(int argc, char **argv)
{
	int **t, **c, n, m, a, b, p, q;

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

		t = (int **)calloc(m+1, sizeof(int));
		c = (int **)calloc(m+1, sizeof(int));
		for(int i = 0; i <= m; i++){
			t[i] = (int *)calloc(m+1, sizeof(int));
			c[i] = (int *)calloc(m+1, sizeof(int));
		}

		for(int i = 0; i < n; i++){
			cin >> a >> b >> p >> q;
			c[a][b] = c[b][a] = p;
			t[a][b] = t[b][a] = q;
		}
		for(int i = 1; i <= m; i++){
			for(int j = 1; j <= m; j++){
				if(i != j && c[i][j] == 0){
					c[i][j] = inf;
				}
				if(i != j && t[i][j] == 0){
					t[i][j] = inf;
				}
			}
		}
		cin >> n;
		for(int i = 0; i < n; i++){
			cin >> a >> b >> p;
			if(p == 0){
				dij(c, m, a, b);
			} else {
				dij(t, m, a, b);
			}
		}

		for(int i = 0; i <= m; i++){
			free(t[i]);
			free(c[i]);
		}
		free(t);
		free(c);
	}

	return 0;
}

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

#define iota(i,n,b,s) for(int i=int(b);i!=int((b)+(s)*(n));i+=(s))
#define range(i,n,m) iota(i,(((n)>(m))?((n)-(m)+1):((m)-(n)+1)),(n),((n)>(m)?-1:1))
#define rep(i,n) iota(i,(n),0,1)

#define INF (1e9)
#define EPS (1e-9)
#define cons(a,b) (make_pair(a,b))
#define car(a) (a.first)
#define cdr(a) (a.second)
#define cadr(a) (car(cdr(a)))
#define cddr(a) (cdr(cdr(a)))
#define all(a) a.begin(), a.end()
#define trace(var) cerr<<">>> "<<#var<<" = "<<var<<endl;

typedef long long INTEGER;
typedef double FLOAT;

template<class S, class T>
ostream& operator<<(ostream& os, pair<S,T> p) {
  os << '(' << car(p) << ", " << cdr(p) << ')';
  return os;
}

template<class T>
ostream& operator<<(ostream& os, vector<T> v) {
  os << v[0];
  for (int i=1, len=v.size(); i<len; ++i) os << ' ' << v[i];
  return os;
}

const int MM = 100;
int cost[MM][MM];
int toki[MM][MM];

int main() {

entry:;
  int n, m; cin >> m >> n;
  if (n + m == 0) return 0;

  rep (i, n) {
    rep (j, n) {
      cost[i][j] = INF;
      toki[i][j] = INF;
    }
    cost[i][i] = 0;
    toki[i][i] = 0;
  }

  rep (i, m) {
    int a, b, c, t;
    cin >> a >> b >> c >> t;
    --a; --b;
    cost[a][b] = cost[b][a] = c;
    toki[a][b] = toki[b][a] = t;
  }

  rep (k, n) {
    rep (i, n) {
      rep (j, n) {
        cost[i][j] = min(cost[i][j], cost[i][k] + cost[k][j]);
        toki[i][j] = min(toki[i][j], toki[i][k] + toki[k][j]);
      }
    }
  }

  //rep (i,n) { rep(j,n) { cout << cost[i][j] << ' '; } cout << endl; }

  int k; cin >> k;
  rep (i, k) {
    int a, b, t;
    cin >> a >> b >> t;
    --a; --b;
    if (t) {
      cout << toki[a][b] << endl;
    } else {
      cout << cost[a][b] << endl;
    }
  }

  goto entry;

  return 0;
}


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

//snukeさんのコードをほぼ写した

int N;

vector<int> G[100010];

vector<int> dist;

void dfs(int v, int d=0, int p=-1) {
    dist[v] = d;
    for (int u : G[v]) {
        if (u == p) continue;
        dfs(u,d+1,v);
    }
}

vector<int> calcDist(int s) {
    dist.resize(N);
    dfs(s);
    return dist;
}

int main(){
    int u, v, ans = 0;
    cin >> N >> u >> v;
    u--;
    v--;

    rep(i,N-1) {
        int a, b;
        cin >> a >> b;
        a--;
        b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }

    vector<int> distU = calcDist(u);
    vector<int> distV = calcDist(v);

    rep(i,N) {
        if (distU[i] < distV[i]) {
            ans = max(ans, distV[i]);
        }
    }

    ans--;
    cout << ans << endl;
}

#include <bits/stdc++.h>
#include <ext/rope>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//#define int long long
#define pb push_back
#define x first
#define y second
#define mk(a,b) make_pair(a,b)
#define rr return 0
#define sqr(a) ((a)*(a))
#define all(a) (a).begin(), (a).end()
#define sz(a) (int)(a).size()

using namespace std;
using namespace __gnu_cxx;
using namespace __gnu_pbds;

using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

template<class value, class cmp = less<value> >
using ordered_set = tree<value, null_type, cmp, rb_tree_tag, tree_order_statistics_node_update>;
template<class value, class cmp = less_equal<value> >
using ordered_multiset = tree<value, null_type, cmp, rb_tree_tag, tree_order_statistics_node_update>;
template<class key, class value, class cmp = less<key> >
using ordered_map = tree<key, value, cmp, rb_tree_tag, tree_order_statistics_node_update>;

/// find_by_order()
/// order_of_key()
mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
inline int randll(int l = INT_MIN, int r = INT_MAX) {
    return uniform_int_distribution<int>(l, r)(rng);
}
const int INF = 1e9, MOD = 1e9 + 7; /// think
const ll LINF = 1e18;

const int dx[] = {0, 0, 1, -1}, dy[] = {1, -1, 0, 0};
inline bool inside (int x, int y, int n, int m) {
    return 0 <= x && 0 <= y && x < n && y < m;
}

template<class T> bool umin (T &a, T b) {return a > b ? (a = b, true) : false; }
template<class T> bool umax (T &a, T b) {return a < b ? (a = b, true) : false; }

vector <vector <int> > edge;
int n;
vector <int> get_v (int v, int x) {
    vector <int> d(n, INF), ans;
    d[v] = 0;
    queue <int> q;
    q.push(v);
    while (!q.empty()) {
        v = q.front();
        q.pop();
        for (int to : edge[v]) {
            if (d[to] == INF) {
                d[to] = d[v] + 1;
                q.push(to);
            }
        }
    }
    for (int i = 0; i < n; i++) {
        if (d[i] <= x) ans.pb(i);
    }
    return ans;
}
main()
{
    ios::sync_with_stdio(0);
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int a, b;
    cin >> n >> a >> b;
    --a, --b;
    edge.resize(n);
    for (int i = 1, u, v; i < n; i++) {
        cin >> u >> v;
        --u, --v;
        edge[u].pb(v);
        edge[v].pb(u);
    }
    int l = 0, r = n;
    while (l < r) {
        int mid = (l + r) >> 1;
        vector <int> A = get_v(a, mid), B = get_v(b, mid);
        vector <int> used(n);
        for (auto &i : B) used[i] = 1;
        bool ok = true;
        for (auto &i : A) {
            if (!used[i]) {
                ok = false;
                break;
            }
        }
        if (ok) r = mid;
        else l = mid + 1;
    }
    cout << r - 1 << '\n';
}


/*
 _ _ _   _    _   _    _   _ _ _   _    _   _ __ _   __       __
|  _ _| | |  | | | |  | | |  _  | | |  | | |  __  | |   \   /   |
| |_ _  | |__| | | |  | | | |_| | | |__| | | |__| | | |\ \_/ /| |
|_ _  | |  __  | | |  | | |  _ <  |  __  | |  __  | | | \   / | |
 _ _| | | |  | | | |__| | | |_| | | |  | | | |  | | | |  \_/  | |  _   _   _
|_ _ _| |_|  |_| |_ __ _| |_ _ _| |_|  |_| |_|  |_| |_|       |_| |_| |_| |_|

*/

#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define fi first
#define se second
#define pb push_back
#define all(a) (a).begin(), (a).end()
#define debug(a) cout << #a << " = " << a << " ";
#define endl "\n"
const int MOD=1e9 + 7;
const int N=1000100;
template<typename T> istream &operator>>(istream &is, vector<T> &vec){
                                                        for (auto &v : vec) is >> v; return is; }
#define dbg(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ") " << __FILE__ << endl;

void solve(){
    long n,k;
    cin>>n>>k;
    long double v[n];
    for(int i=0;i<n;i++){
        cin>>v[i];
        v[i]=(v[i]+1.00)/2.00;
    }
    long double pre[n+1];
    pre[0]=0.0;
    for(int i=0;i<n;i++){
        pre[i+1]=pre[i]+v[i];
    }
    long double ans=0.0;
    for(int i=k;i<=n;i++){
        ans=max(ans,pre[i]-pre[i-k]);
    }
    cout<<setprecision(16)<<ans<<endl;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    long int t = 1;
    // cin>>t;
    for (long int tt = 1; tt <= t; tt++) {
        solve();
    }
    return 0;
}

#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;
const ll INF = 1LL << 60;
ll dp[200][100001];
int S[200];
int main() {
	int N, X;
	cin >> N >> X;
	for (int i = 0; i < N; i++) {
		cin >> S[i];
	}
	sort(S, S + N);
	for (int i = 0; i <= X; i++) {
		dp[0][i] = i % S[0];
	}
	for (int i = 1; i < N; i++) {
		for (int j = 0; j <= X; j++) {
			(dp[i][j] += dp[i - 1][j%S[i]]) %= MOD;
			(dp[i][j] += (i*dp[i - 1][j]) % MOD) %= MOD;
		}
	}
	cout << dp[N - 1][X] << endl;
}


#include <cstdio>
#include <iostream>
#include <vector>
#define mod 1000000007
#define MN 1050000

std::vector<int> v[MN];

int n, a[MN];
int b[MN], c[MN];

int main()
{
	scanf("%d", &n);
	for(int i = 1; i <= n; i++)
	{
		scanf("%d", &a[i]);
		b[i] = b[i - 1] ^ a[i];
		c[i] = c[i - 1] + (b[i] == 0 ? 1 : 0);
		v[b[i]].push_back(i);
	}
	int ans = 0;
	for(int j = 1; j < (1 << 20); j++)
	{
		int Sumj = 0, Sum0 = 1;
		int S = v[j].size();
		for(int k = 0; k < S; k++)
		{
			if(k) Sum0 = (Sum0 + 1ll * Sumj * (c[v[j][k]] - c[v[j][k - 1]])) % mod;
			Sumj = (Sum0 + Sumj) % mod;
		}
		if(b[n] == j) ans = (ans + Sum0) % mod;
		if(b[n] == 0) ans = (ans + Sumj) % mod;
	}
	if(b[n] == 0)
	{
		int k = 1;
		for(int j = 1; j <= c[n] - 1; j++) k = k * 2 % mod;
		ans = (ans + k) % mod;
	}
	printf("%d\n", ans);
}

#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <string>
#include <queue>
#include <map>

using namespace std;
const int INF = 1e8;

//0:up, 1:right, 2:down, 3:left
vector<pair<int, int>> direction(4);

//距離を計算する
int f( vector<pair<int, int>> vec){
    sort(vec.begin(), vec.end());
    int dist = INF;
    for(int i=0; i<vec.size()-1; ++i){
        if(vec[i].second == 0 && vec[i+1].second != 0){
            int tmp = vec[i+1].first - vec[i].first;
            dist = min(dist, tmp);
        }
    }
    return dist;
}

int main(){
    int N; cin >> N ;
    vector<int> x(N), y(N), dir(N);

    for(int i=0; i<N; ++i){
        int X, Y;
        char U;
        cin  >> x[i] >> y[i];
        cin  >> U;

        if( U == 'U') dir[i] = 0;
        if( U == 'R') dir[i] = 1;
        if( U == 'D') dir[i] = 2;
        if( U == 'L') dir[i] = 3;
    }

    int ans = INF;

    //四回分ですべてをカバー
    for(int i=0; i<4; ++i){

        //すべてのx座標を独立に考える
        // x座標: [{y座標1, 方向1}, {y座標2, 方向2}]　みたいな感じ
        {
            map<int, vector<pair<int, int>>> mp;
            //180度パターン、上と下でぶつかる場合を考える
            for(int i=0; i<N; ++i){
                if (dir[i] != 0 && dir[i] !=2) continue;
                mp[x[i]].emplace_back( y[i], dir[i] );
            }

            for(auto y_dir : mp){
                int res = f(y_dir.second);
                if(res == INF)continue;
                ans = min(ans, res*5);
            }
        }
        //90度パターン、直角にぶつかる。ここではUとRでぶつかるを想定
        {
            map<int, vector<pair<int, int>>> mp;
            //この場合x+y座標の和が一致する
            for(int i=0; i<N; ++i){
                if (dir[i] != 0 && dir[i] !=1) continue;
                mp[ x[i] + y[i] ].emplace_back(y[i], dir[i]);
            }
            for(auto y_dir : mp){
                int res = f(y_dir.second);
                if(res == INF)continue;
                ans = min(ans, res*10);
            }
        }

        //時計回りに回転
        for(int i=0; i<N; ++i){
            int px = y[i];
            int py = -x[i];
            x[i] = px;
            y[i] = py;
            dir[i] = (dir[i] + 1)%4;
        }
    }

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

}


#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vint;
typedef vector<double> vd;
typedef vector<ll> vll;
typedef vector<string> vstr;
typedef vector<vector<int>> vvint;
typedef vector<pair<int, int>> vpii;
typedef vector<pair<ll, ll>> vpll;
typedef priority_queue<int, vector<int>, greater<int>> spqint; //小さい順に取り出し
typedef priority_queue<ll, vector<ll>, greater<ll>> spqll;     //小さい順に取り出し
typedef priority_queue<int, vector<int>, less<int>> bpqint;    //大きい順に取り出し
typedef priority_queue<ll, vector<ll>, less<ll>> bpqll;        //大きい順に取り出し

#define REP(i, n) for (ll i = 0; i < (ll)(n); i++)
#define FOR(i, a, b) for (ll i = (ll)a; i < (ll)b; i++)
#define IREP(i, v) for (auto i = (v).begin(); i != (v).end(); i++)
#define FI first
#define SE second
#define MP make_pair
#define MT make_tuple
#define PB push_back
#define PF push_front
#define TS to_string
#define BS binary_search
#define LB lower_bound
#define UB upper_bound
#define NP next_permutation
#define ALL(v) (v).begin(), (v).end()
#define SZ(x) (ll) x.size()
#define SP(x) setprecision((ll)x)

int INF = 1e9;
int NIL = -1;
ll MOD = 1000000007;
ll LINF = 1e18;
double EPS = 1e-9;
double PI = M_PI;
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; } //最大公約数
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }     //最小公倍数

void yes(){ cout << "Yes" << endl;}
void no(){ cout << "No" << endl;}
//-----------------------------------------

//-----------------------------------------
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    std::chrono::system_clock::time_point start,end;
    start = std::chrono::system_clock::now();

    ll n, k ;
    cin >> n >> k ;
    vll pa ;
    vll ma ;
    pa.PB(0) ;
    ma.PB(0) ;
    REP(i,n){
        ll a ;
        cin >> a ;
        if(a==0){
            k-- ;
        }
        else if(a>0){
            pa.PB(a) ;
        }
        else{
            ma.PB(-a) ;
        }
    }
    sort(ALL(ma)) ;
    sort(ALL(pa)) ;
    ll sp = SZ(pa) ;
    ll sm = SZ(ma) ;

    ll ans = LINF ;

    for(ll i=0;i<=k;i++){
        ll tmp ;
        if(k-i<sm && i<sp){
            tmp = 2*min(pa[i],ma[k-i]) + max(pa[i],ma[k-i]) ;
            ans = min(ans,tmp) ;
        }
    }

    cout << ans <<endl;

    end = std::chrono::system_clock::now();
    auto elapsed = std::chrono::duration_cast< std::chrono::milliseconds >(end - start).count();
    //std::cout << elapsed <<"ms"<< std::endl;

    return 0;
}

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

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

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

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

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

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

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

	uint64_t prod = a * b;

	return (prod / b != a);
}

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

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

// 円周率
// M_PI

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

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

ll pCount(int x){
  if(x==0) return 1;
  return pCount(x-1)*2 + 1;
}

ll allCount(int x){
  if(x==0) return 1;
  return allCount(x-1)*2 + 3;
}

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

  int minDist = 1000000000;
  for(int i=0;i<n-k;i++){
    if((pos[i]<=0 && pos[i+k]<=0)
      ||(pos[i]>=0 && pos[i+k]>=0)){
      minDist = min(minDist, (abs(pos[i])>abs(pos[i+k]))?abs(pos[i]):abs(pos[i+k]));
    }
    else if(pos[i]<=0 && pos[i+k]>=0){
      if(abs(pos[i]) < pos[i+k]){
        minDist = min(minDist, abs(pos[i])*2+pos[i+k]);
      }
      else{
        minDist = min(minDist, pos[i+k]*2+abs(pos[i]));
      }
    }
  }

  cout << minDist << endl;

  return 0;
}


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

signed main() {
 int n;
 cin>>n;
 priority_queue<int> que;
 int ala=0,a,k=0,t,s;
 for(int i=0;i<n;i++){
   cin>>a;
   que.push(a);
   ala^=a;
 }
 for(int i=59;i>=0;i--){
   if(que.empty())break;
    if(ala&(1LL<<i)){
     while(!que.empty()&&(que.top()&(1LL<<i))){
       que.push(que.top()^(1LL<<i));
       que.pop();
      // cerr<<que.top()<<' ';
     }
     continue;
   }
   if(!(que.top()&(1LL<<i)))continue;
    if(!(k&(1LL<<i)))k^=que.top();
    t=que.top();que.pop();
    while(!que.empty()&&(que.top()&(1LL<<i))){
      que.push((t^que.top()));
      que.pop();
    //  cerr<<que.top()<<' ';
    }

 }
 cerr<<ala<<' '<<k<<endl;
 cout<<(ala^k)+k;
return 0;
}

/*{{{*/
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<string>
#include<iostream>
#include<sstream>
#include<set>
#include<map>
#include<queue>
#include<bitset>
#include<vector>
#include<limits.h>
#include<assert.h>
#define SZ(X) ((int)(X).size())
#define ALL(X) (X).begin(), (X).end()
#define REP(I, N) for (int I = 0; I < (N); ++I)
#define REPP(I, A, B) for (int I = (A); I < (B); ++I)
#define FOR(I, A, B) for (int I = (A); I <= (B); ++I)
#define FORS(I, S) for (int I = 0; S[I]; ++I)
#define RS(X) scanf("%s", (X))
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define CASET int ___T; scanf("%d", &___T); for(int cs=1;cs<=___T;cs++)
#define MP make_pair
#define PB push_back
#define MS0(X) memset((X), 0, sizeof((X)))
#define MS1(X) memset((X), -1, sizeof((X)))
#define LEN(X) strlen(X)
#define F first
#define S second
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef long double LD;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<PII> VPII;
typedef pair<LL,LL> PLL;
typedef vector<PLL> VPLL;
template<class T> void _R(T &x) { cin >> x; }
void _R(int &x) { scanf("%d", &x); }
void _R(LL &x) { scanf("%lld", &x); }
void _R(double &x) { scanf("%lf", &x); }
void _R(char &x) { scanf(" %c", &x); }
void _R(char *x) { scanf("%s", x); }
void R() {}
template<class T, class... U> void R(T &head, U &... tail) { _R(head); R(tail...); }
template<class T> void _W(const T &x) { cout << x; }
void _W(const int &x) { printf("%d", x); }
void _W(const LL &x) { printf("%lld", x); }
void _W(const double &x) { printf("%.16f", x); }
void _W(const char &x) { putchar(x); }
void _W(const char *x) { printf("%s", x); }
template<class T,class U> void _W(const pair<T,U> &x) {_W(x.F); putchar(' '); _W(x.S);}
template<class T> void _W(const vector<T> &x) { for (auto i = x.begin(); i != x.end(); _W(*i++)) if (i != x.cbegin()) putchar(' '); }
void W() {}
template<class T, class... U> void W(const T &head, const U &... tail) { _W(head); putchar(sizeof...(tail) ? ' ' : '\n'); W(tail...); }
#ifdef HOME
 #define DEBUG(...) {printf("# ");printf(__VA_ARGS__);puts("");}
#else
 #define DEBUG(...)
#endif
int MOD = 1e9+7;
void ADD(LL& x,LL v){x=(x+v)%MOD;if(x<0)x+=MOD;}
/*}}}*/
const int SIZE = 1e6+10;
LL A[SIZE];
int get_bit(LL x,int v){return (x>>v)&1;}
int main(){
    int N; R(N);
    LL s=0;
    REP(i,N){
        R(A[i]);
        s^=A[i];
    }
    LL an=0;
    VI d;
    for(int i=59;i>=0;i--){
        if(get_bit(s,i))an+=1LL<<i;
        else{
            d.PB(i);
        }
    }
    LL now=0;
    int it=0;
    REP(i,SZ(d)){
        REPP(j,it,N){
            if(get_bit(A[j],d[i])){
                if(j!=it){
                    swap(A[j],A[it]);
                    break;
                }
            }
        }
        if(get_bit(A[it],d[i])){
            REPP(j,it+1,N){
                if(get_bit(A[j],d[i]))A[j]^=A[it];
            }
            if(get_bit(now,d[i])==0)now^=A[it];
            it++;
        }
        if(get_bit(now,d[i]))an+=2LL<<d[i];
    }
    W(an);
    return 0;
}


#include<bits/stdc++.h>
#define rep(i,N) for(ll (i)=0;(i)<(N);(i)++)
#define chmax(x,y) x=max(x,y)
#define chmin(x,y) x=min(x,y)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
const int mod = 1000000007;

int main() {
  string s;
  int w;
  cin >> s >> w;
  string ans = "";
  for(int i = 0; ; ++i) {
    if(i * w >= s.length()) break;
    ans += s.substr(i * w, 1);
  }
  cout << ans << endl;
}

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

int main(){
  string S;
  int w;
  cin >> S >> w;
  for(int i=0;i<S.size();i++){
    if(i%w==0){
      cout << S.at(i);
    }
  }
  cout << endl;
  return 0;
}


// Author: 23forever
#include <bits/stdc++.h>
//#define debug
const int MAXN = 40;
const int N = 5 + 7 + 5;
const int P = 1e9 + 7;
using namespace std;

inline void read(int &x) {
  x = 0; char c = getchar();
  while (!isdigit(c)) c = getchar();
  while (isdigit(c)) {
    x = (x << 1) + (x << 3) + (c ^ 48);
    c = getchar();
  }
}

int n, x, y, z;
int dp[MAXN + 5][1 << N];
int banned, S;

void print(int x) {
  bitset < 20 > tmp(x);
  cout << tmp << endl;
}

void init() {
  read(n), read(x), read(y), read(z);
  //cout << (1 << 5 - 1) << endl;
  banned = (1 << x + y + z - 1) | (1 << y + z - 1) | (1 << z - 1);
  S = (1 << x + y + z) - 1;
  //print(S);
}

int main() {
#ifdef forever23
  freopen("test.in", "r", stdin);
  freopen("test.out", "w", stdout);
#endif
  init();

  int ans = 1; dp[0][0] = 1;
  for (int i = 1; i <= n; ++i) {
    for (int s = 0; s <= S; ++s) {
      for (int j = 1; j <= 10; ++j) {
        int nxt_state = ((1 << j - 1) | (s << j)) & S;
        /*print(s); printf("%d\n", j);
        print(nxt_state);
        puts("");*/
        if ((nxt_state & banned) != banned) {
          dp[i][nxt_state] = (dp[i][nxt_state] + dp[i - 1][s]) % P;
        }
      }
    }
    ans = 1LL * ans * 10 % P;
  }

  for (int s = 0; s <= S; ++s) {
    ans = (ans - dp[n][s] + P) % P;
  }
  printf("%d\n", ans);
  return 0;
}

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

LL n,s,x[100009],p[100009],ans[100009];

void call(int l,int r)
{
    if(l==r)
    {
        ans[l]=fabs(x[l]);
        return;
    }
    if(x[l]>0)
    {
        call(l,r-1);
        ans[r]=ans[r-1]+x[r]-x[r-1];
        return;
    }
    if(x[r]<0)
    {
        call(l+1,r);
        ans[l]=ans[l+1]+x[l+1]-x[l];
        return;
    }
    if(p[l]>=p[r])
    {
        p[l]+=p[r];
        call(l,r-1);
        ans[r]=ans[l]+x[r]-x[l];
        return;
    }
    p[r]+=p[l];
    call(l+1,r);
    ans[l]=ans[r]+x[r]-x[l];
    return;
}

int main()
{
    scanf("%lld %lld",&n,&s);
    for(int i=1;i<=n;i++)
    {
        scanf("%lld %lld",&x[i],&p[i]);
        x[i]-=s;
    }
    call(1,n);
    LL foo=max(ans[1],ans[n]);
    cout<<foo<<endl;
    return 0;
}


// LOVED IT

#include<bits/stdc++.h>
using namespace std;
#define FastRead ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define int long long int
#define ll int
#define bits_count __builtin_popcountll
#define endl '\n'
#define double long double
#define ld double
#define FOR(i,a,n) for (ll i=(a);i<=(n);++i)
#define RFOR(i,a,n) for (ll i=(n);i>=(a);--i)
#define ZERO(a) memset((a),0,sizeof((a)))
#define MINUS(a) memset((a),-1,sizeof((a)))
#define f first
#define s second
#define pb push_back
#define mk make_pair
#define all(g) g.begin(),g.end()
#define sz(x) (ll)x.size()
#define pr pair<int,int>
int fastMax(int x, int y) { return (((y-x)>>(32-1))&(x^y))^y; }
int fastMin(int x, int y) { return (((y-x)>>(32-1))&(x^y))^x; }

// #include <ext/pb_ds/assoc_container.hpp> // Common file
// #include <ext/pb_ds/tree_policy.hpp>     // Including tree_order_statistics_node_updat
// using namespace __gnu_pbds;
// typedef tree<ll, null_type, less_equal<ll>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
// const int RANDOM = chrono::high_resolution_clock::now().time_since_epoch().count();
// struct chash { int operator()(int x) const { return x ^ RANDOM; }};
// cc_hash_table<int, int, hash<int>> cnt;

const int MAXN = 305;
int dp[MAXN][MAXN][MAXN];
const int MOD = 998244353;
string s; int k,n,m;
vector<int> one_cnt;

int rec(int idx,int carry,int step){
    if(step < 0) return 0;

    if(idx == -1) return (carry == 0);

    int &ans = dp[idx][carry][step];
    if(ans != -1) return ans;
    ans = 0;

    int total_ones_here = one_cnt[idx] + carry;

    FOR(how_many_here,0,total_ones_here){
        int to_go_head = total_ones_here - how_many_here;
        int steps_here = max(0LL,to_go_head - carry);
        ans = (ans + rec(idx-1,to_go_head,step-steps_here))%MOD;
    }
    return ans;
}

void solve(){
    MINUS(dp);
    cin>>s>>k; n = sz(s); k = min(k,n);

    int cnt = 0;
    for(char c:s){
        if(c == '0'){
            one_cnt.push_back(cnt);
            cnt = 0;
        }else cnt++;
    }
    if(cnt) one_cnt.push_back(cnt);
    m = sz(one_cnt);

    cout<<rec(m-1,0,k)<<endl;
}

signed main(){

    FastRead;

    int t = 1;
    // cin>>t;
    FOR(i,1,t){
        // cout<<"Case #"<<i<<": ";
        solve();
    }
}

#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0; i<n; i++)
#define rep1(i, n) for(int i=1; i<=n; i++)
#define repr(i, n) for(int i=n-1; i>=0; i--)
#define repr1(i, n) for(int i=n; i>=1; i--)
#define all(v) v.begin(),v.end()
using ll = long long;
using pii = pair<int, int>;
using pil = pair<int, ll>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
const int INF = 1e9;
const ll LLINF = 1e18;
const ll MOD = 1e9+7;
const double EPS = 1e-10;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

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

    vector<string> s(100, string(100, '#'));
    rep(i, 50) rep(j, 100) s[i][j] = '.';

    int cnt = 0;
    for (int i = 0; i < 50; i += 2) {
        if (cnt == b - 1) break;
        for (int j = 0; j < 100; j += 2) {
            if (cnt == b - 1) break;
            s[i][j] = '#';
            cnt++;
        }
    }

    cnt = 0;
    for (int i = 51; i < 100; i += 2) {
        if (cnt == a - 1) break;
        for (int j = 0; j < 100; j += 2) {
            if (cnt == a - 1) break;
            s[i][j] = '.';
            cnt++;
        }
    }

    printf("100 100\n");
    for (auto &line: s) cout << line << endl;

}


#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <iostream>
using namespace std;
int main()
{
    int n,k=0;
    long long sum=0;
    scanf("%d",&n);
    int num[100005];
    for(int i=0;i<n;i++)
    {
        scanf("%d",&num[i]);
        if(num[i]<0)
        {
            num[i]=-num[i];
            k++;
        }
        sum+=num[i];
    }
    sort(num,num+n);
    if(k%2!=0)
       sum=sum-num[0]*2;
    printf("%lld",sum);
    return 0;
}

#include <bits/stdc++.h>
#define int long long
#define gcd            __gcd
#define setbits(x)     __builtin_popcountll(x)
#define zrobits(x)     __builtin_ctzll(x)
#define mod            1000000007
#define mod2           998244353
#define maxe           *max_element
#define mine           *min_element
#define inf            1e18
#define deci(x,y)      fixed<<setprecision(y)<<x
#define w(t)           int t; cin>>t; while(t--)
#define nitin          ios_base::sync_with_stdio(false); cin.tie(NULL)
#define PI             3.141592653589793238
using namespace std;

int power(int x, int y, int p)
{
    int res = 1;
    x = x % p;
    while (y > 0)
    {
        if (y & 1)
            res = (res * x) % p;
        y = y >> 1;
        x = (x * x) % p;
    }
    return res;
}
int modi(int a, int m)
{
    return power(a, m - 2, m);
}
string find_ans(int n,vector<int>& v,string s)
{
    if(n==1)
    {
        if(v[0]%2==0)
        {
            return s;
        }
        else{
            if(s=="First")
            return "Second";
            else
                return "First";
        }
    }
    int e=0;
    int o=0;
    for(auto c:v)
    {
        if(c%2==0)
            e++;
        else
            o++;
    }
    if(e==1 || e%2!=0)
    {
        return s;
    }
    else if(e%2==0 && o>1){
        if(s=="First")
            return "Second";
        else
            return "First";
    }
    else{
        int g=v[0];
        for(auto &c:v)
        {
            if(c&1)
                c-=1;
        }
        for(auto c:v)
        {
            g=gcd(g,c);
        }
        for(auto &c:v)
        {
            c=c/g;
        }
        if(s=="First")
            s="Second";
        else
            s="First";
        return find_ans(n,v,s);
    }
}
int32_t main()
{
    nitin;
    int n;
    cin>>n;
    vector<int>v(n);
    for(int i=0;i<n;i++){
        cin>>v[i];
    }
    cout<<find_ans(n,v,"First")<<endl;
    return 0;
}


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

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)
#define ALL(a)     (a).begin(),(a).end()
#define RALL(a)     (a).rbegin(),(a).rend()
#define PRINT(a)   cout << (a) << endl

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define Fi first
#define Se second

#define debug(x) cerr << x << " " << "(L:" << __LINE__ << ")" << '\n';

using ll = long long int;
using P = pair<int,int>;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using pii = pair<int, int>;

template <typename T> using PQ = priority_queue<T>;
template <typename T> using minPQ = priority_queue<T, vector<T>, greater<T>>;

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

const int INF = 1001001001;
const ll LINF = 1001001001001001001ll;
const int MOD = 1e9 + 7;

int main(){
  int score[] = {300000, 200000, 100000};
  int x,y;
  cin >> x >> y;
  x--;y--;
  int ans = 0;
  if(x<3)ans+=score[x];
  if(y<3)ans+=score[y];
  cout << (ans==600000 ? ans + 400000 : ans) << endl;
}

#include <iostream>

int main(){
  int A, B;
  std::cin >> A >> B;
  if (A <= 8 && B <= 8) {
    std::cout << "Yay!" << std::endl;
  }
  else {
    std::cout << ":(" << std::endl;
  }
}


#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
int main()
{
	int a[10],ans=0;
	for(int iii=1;iii<=2;iii++){
		ans=0;
	for(int i=0;i<10;i++){
		scanf("%d",&a[i]);
	}
	sort(a,a+10);
	ans+=a[7]+a[8]+a[9];
	if(iii==1)printf("%d ",ans);
	else printf("%d\n",ans);

	}
	return 0;
}

#include<iostream>
#include<cstdio>
#include <algorithm>
#include <functional>
#include <vector>

using namespace std;

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

	int a[10], b[10];

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

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

	sort(a,a+10);
	sort(b,b+10);

	cout << a[9] + a[8] + a[7] << " ";
	cout << b[9] + b[8] + b[7] << "\n";

	return 0;
}