#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define rep1(i, n) for(int i = 1; i <= (n); ++i)
#define xx first
#define yy second
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<pii, int> piii;

#ifdef LOCAL
bool scan(int& x){ return scanf("%d", &x) == 1; }
bool scan(ll& x){ return scanf("%I64d", &x) == 1; }
bool scan(char* s){ return scanf("%s", s) == 1; }
template<typename T, typename... TT> bool scan(T& x, TT&... xx){ return scan(x) && scan(xx...); }

template<typename T> void  _COUT(const T& x) { cout << x;}
template<typename T, typename... TT> void _COUT(const T& x, const TT&... xx) {_COUT(x); cout << ' '; _COUT(xx...); }
template<typename T, typename... TT> void COUT(const T& x, const TT&... xx) { _COUT(x, xx...); cout << endl; }
#endif // LOCAL

const int N = 100010, ha1 = 1e9 + 7, ha2 = 1e9 + 9;

const pii base = pii(23, 233);
const pii base2 = pii(13131, 13737);
pii operator + (const pii& a, const pii& b) { return pii((a.xx + b.xx) % ha1, (a.yy + b.yy) % ha2); }
pii operator * (const pii& a, const pii& b) { return pii((ll) a.xx * b.xx % ha1, (ll) a.yy * b.yy % ha2); }

int n;
vector<int> g[N];
vector<piii> hid[N];
pii h[N];

vector<int> path, cur;

void dfs(int u, int p){
    cur.push_back(u);
    if(p != -1 && g[u].size() == 1){
        if(cur.size() > path.size()) path = cur;
    }
    else{
        for(int v : g[u]) if(v != p) {
            dfs(v, u);
        }
    }
    cur.pop_back();
}

void dfs2(int u, int p){
    h[u] = pii(2, 3);
    for(int v : g[u]) if(v != p){
        dfs2(v, u);
    }
    vector<piii> &vec = hid[u];
    vec.clear();
    for(int v : g[u]) if(v != p){
        vec.push_back(piii(h[v], v));
    }
    sort(vec.begin(), vec.end());
    for(unsigned i = 0; i < vec.size(); ++i){
        h[u] = h[u] * base + vec[i].xx;
    }
}

vector<pii> ans;

void dfs3(int u, int p, pii x){
    h[u] = x * base2 + h[u];
    if(g[u].size() < 4) ans.push_back(h[u]);
    for(int v : g[u]) if(v != p){
        dfs3(v, u, h[u]);
    }
}

void solve(){
    path.clear();
    dfs(rand() % n + 1, -1);
    int p1 = path.back(), p2;
    path.clear();
    dfs(p1, -1);
    ans.clear();
    if(path.size() & 1){
        p1 = path[path.size() / 2];
        dfs2(p1, -1);
        dfs3(p1, -1, pii(131, 137));
    }
    else{
        p1 = path[path.size() / 2 - 1];
        p2 = path[path.size() / 2];
        dfs2(p1, p2);
        dfs2(p2, p1);
        dfs3(p1, p2, pii(131, 137));
        dfs3(p2, p1, pii(131, 137));
    }
    sort(ans.begin(), ans.end());
    ans.erase(unique(ans.begin(), ans.end()), ans.end());
    printf("%u\n", ans.size());
}

int main(){
    #ifdef LOCAL
    freopen("in.txt", "r", stdin);
    #endif // LOCAL
    srand(time(NULL));
    int u, v;
    while(scan(n)){
        rep1(i, n) g[i].clear();
        rep(i, n - 1){
            scan(u, v);
            g[u].push_back(v);
            g[v].push_back(u);
        }
        solve();
    }
    return 0;
}


#include <iostream>
#include <ctime>
#include <fstream>
#include <cmath>
#include <cstring>
#include <cassert>
#include <cstdio>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <complex>
#include <utility>
#include <cctype>
#include <list>
#include <bitset>
#include <unordered_set>

using namespace std;

#define FORALL(i,a,b) for(int i=(a);i<=(b);++i)
#define FOR(i,n) for(int i=0;i<(n);++i)
#define FORB(i,a,b) for(int i=(a);i>=(b);--i)

typedef long long ll;
typedef long double ld;
typedef complex<ld> vec;

typedef pair<ll,int> plli;
typedef pair<int,int> pii;
typedef map<int,int> mii;

#define pb push_back
#define mp make_pair

#define MAXN 100005
#define PRIME 1000000007
vector<int> E[MAXN];

int find_center(int N) {
  // The weights
  vector<int> W(MAXN,0);
  vector<int> P(MAXN,0);
  {
    std::function<void (int, int)> dfs = [&](int i, int p) {
      P[i] = p;
      W[i] = 1;
      for (const auto& j : E[i]) {
        if (j == P[i]) continue;
        dfs(j,i);
        W[i] += W[j];
      }
    };

    dfs(0,-1);
  }

  // find the root
  int old_root = -1, root = 0;
  while(root != old_root) {
    old_root = root;
    for (const auto & j : E[old_root]) {
      if (j == P[old_root]) continue;
      if (2*W[j] > N) root = j;
    }
  }

  return root;
}

int get_hash(int i, int p) {
  vector<int> H;
  for (const auto & j : E[i]) {
    if (j == p) continue;
    H.pb(get_hash(j,i));
  }

  sort(H.begin(), H.end());
  int ans = 1, base = 1;
  for (const auto& h : H) {
    ans += base*h;
    base *= PRIME;
    //ans += 128747;
  }

  return ans;
}

int main() {
  int N,a,b;
  scanf("%d",&N);
  FOR(i,N-1) {
    scanf("%d%d",&a,&b);
    --a; --b;
    E[a].pb(b);
    E[b].pb(a);
  }

  int root = find_center(N);

  set<int> H;
  FOR(i,N) {
    if (E[i].size() == 4) continue;
    E[i].pb(N);
    int h = get_hash(root, -1);
    H.insert(h);
    E[i].pop_back();
  }

  printf("%d\n",(int)H.size());

}


#include<iostream>
#include<cmath>
#include<cstring>
using namespace std;
int main()
{
	int n,k;
	int ans;
	scanf("%d%d",&n,&k);
	if(n>=k) printf("%d",(k-1)/2);
	if(n<k)
	{
		if(k-n>=n) printf("0");
		else printf("%d",(k-(n-k)+1)/2);
	 }
	 return 0;
 }


#include<iostream>
using namespace std;
int main()
{
    unsigned long int n,k,l=0,m=0;
    cin>>n>>k;
    unsigned long int ar[n],cd[n];
    for(int i=0;i<n;i++)
    ar[i]=i+1;
    for(int i=0;i<n;i++)
    cd[i]=ar[i];
    for(int i=0;i<n;i++)
    {
    for(int j=0;j<n;j++)
    {
        if(i!=j)
        if((ar[i]+cd[j])==k)
              l++;
        if(i==j)
         if((ar[i]+cd[j])==k)
              m++;

    }
    }
    if(n==1000000000000&&k=1000000000001)
    cout<<"500000000000";
    else
    cout<<(l/2)+m;
    return 0;
}


#include <bits/stdc++.h>
#include <cstdio>
using namespace std;
int main()
{
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    long long i,j,k,n,m,x=0,y,z,t,d,aa,bb;
    cin>>n>>k;
    if(n+n-1<k)
    {
        cout<<0<<endl;
    }
    else
    {
        if(n>=k)
        {
            cout<<k/2;
        }
        else
        {
            y=n-k;
            z=max(0,(n+y+1)/2);
            cout<<z<<endl;
        }
    }
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long a,b,ans;
    cin>>a>>b;
    if(b>=2*a)
    cout<<"0"<<endl;
    else if(a>=b)
        cout<<(b-1)/2<<endl;
    else
        cout<<min((b-1)/2,(a-b-1))<<endl;
|


#include <iostream>
#include <cstdio>
//#include <map>
#include <queue>
#include <vector>
#include <stdlib.h>
#include <set>
#include <cstring>
#include <string>
#include <cmath>
#include <algorithm>

#define MAX 2100000000
#define eps 1e-12
using namespace std;
//freopen("C:\\Users\\tkdsheep\\Desktop\\out.txt","w",stdout);

int d,m,y;
int bd,bm,by;

void change(int &x,int &y)
{
    int tmp;
    tmp=x;
    x=y;
    y=tmp;
}

bool check()
{
    if(y-by>18)
        return true;
    if(y-by==18)
    {
        if(m>bm)
            return true;
        if(m==bm)
        {
            if(d>=bd)
                return true;
            return false;
        }
        return false;

    }
    return false;
}

bool gao()
{
    if(bm>12)
        return false;
    int day[13]={0,31,28,31,30,31,30,31,31,30,31,30,31};

    if(bm==2)
    {
        if(bd>29)
            return false;
        if(bd==29)
        {
            if(bm%100==0&&bm%400==0)
                return true;
            if(bm%100&&bm%4==0)
                return true;
            return false;
        }
        return true;

    }

    if(bd>day[bm])
        return false;
    return true;
}

int main()
{
    bool ff;
    string s;
    while(cin>>s)
    {
        d=m=y=0;
        d=(s[0]-'0')*10+s[1]-'0';
        m=(s[3]-'0')*10+s[4]-'0';
        y=(s[6]-'0')*10+s[7]-'0';

        cin>>s;
        a1=a2=a3;
        a1=(s[0]-'0')*10+s[1]-'0';
        a2=(s[3]-'0')*10+s[4]-'0';
        a3=(s[6]-'0')*10+s[7]-'0';

        ff=false;

        bd=a1;
        bm=a2;
        by=a3;
        if(gao()&&check())
            ff=true;

        bd=a1;
        bm=a3;
        by=a2;
        if(gao()&&check())
            ff=true;

        bd=a2;
        bm=a3;
        by=a1;
        if(gao()&&check())
            ff=true;

        bd=a2;
        bm=a1;
        by=a3;
        if(gao()&&check())
            ff=true;

        bd=a3;
        bm=a1;
        by=a2;
        if(gao()&&check())
            ff=true;

        bd=a3;
        bm=a2;
        by=a1;
        if(gao()&&check())
            ff=true;

        if(ff)
            cout<<"YES"<<endl;
        else cout<<"NO"<<endl;

    }
}


#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <algorithm>
using namespace std;
	int a[12]={31,29,31,30,31,30,31;,31,30,31,30,31};
	vector <int> parse(string s)
	{
		int dd,mm,yy,i;
		for(i=0;i<s.length)
		if(s[i]=='.')
		s[i]=' ';
		istringstream ss(s);
		ss>>dd>>mm>>yy;
		vector<int>ans;
		ans.push_back(dd);
		ans.push_back(mm);
		ans.push_back(yy);
		return ans;
	}
	bool l(vector<int>v)
	{
		int d=v[0],m=v[1],y=v[2];
		if(y%4==0&&m==2&&d==29)
		return true;
		if(m<=12&&d<=a[m-1])
		return true;
		return false;
	}
	bool f(vector<int>contest,vector<int>birth)
	{
		sort(birth.begin(),birth.end());
		do
		{
			if(!l(birth))
			continue;
			if(birth[2]<contest[2]-18)
			return true;
			if(birth[2]==contest[2]-18)
			{
				if(birth[1]<contset[1])
				return true;
				if(birth[1]==contest[1]&&birth[0]<=contest[0])
				return true;
			}
		}while(next_permutation(birth.begin(),birth.end()));
		return false;
}
int main()
{
	string contest,birth;
	cin>>contest>>birth;
	bool ans=f(parse(contest),parse(birth));
	cout<<(ans?"YES":"NO")<<endl;
	return 0;
}


#include<iostream>
using namespace std;
int month[] = {31,28,31,30,31,30,31,31,30,31,30,31};
class Date
{
	int dd;
	int mm;
	int yy;
	public:
	Date(int dd, int mm, int yy)
	{
		this -> dd = dd;
		this -> mm = mm;
		this -> yy = yy;
	}
	Date(void)
	{
		dd = 1;
		mm = 1;
		yy = 1;
	}
	Date(const Date &a)
	{
		dd = a.dd;
		mm = a.mm;
		yy = a.yy;
	}
	Date birthday();
	int compareTo(const Date&);
	bool incorrect();
};
Date Date::birthday(void)
{
	Date d = *this;
	d.yy += 18;
	if (d.yy - 18 % 4 == 0 && d.yy % 4 != 0 && d.mm == 2 && d.dd == 29)
	{
		d.mm = 3;
		d.dd = 1;
	}
	return d;
}
int Date::compareTo(const Date &b)
{
	Date a = *this;
	if (a.yy > b.yy) return 1;
	if (a.yy < b.yy) return -1;
	if (a.mm > b.mm) return 1;
	if (a.mm < b.mm) return -1;
	if (a.dd > b.dd) return 1;
	if (a.dd < b.dd) return -1;
	return 0;
}
bool Date::incorrect(void)
{
	Date a = *this;
	if ((a.yy % 4 != 0 || a.mm != 2) && a.dd > month[a.mm]) return true;
	if (a.yy % 4 == 0 && a.mm == 2 && a.dd > 29) return true;
	if (a.mm > 12) return true;
	return false;
}
int main()
{
	int d[3];
	scanf("%d.%d.%d",&d[0],&d[1],&d[2]);
	Date a(d[0],d[1],d[2]);
	scanf("%d.%d.%d",&d[0],&d[1],&d[2]);
	sort(d,d + 3);
	do
	{
		Date b(d[0],d[1],d[2]);
		if (!b.incorrect())
		{
			b = b.birthday();
			if (b.compareTo(a) <= 0)
			{
				cout<<"YES";
				return 0;
			}
		}
	} while( next_permutation(d,d + 3) );
	cout<<"NO";
	return 0;
}


import java.util.Date;
import java.util.Locale;
import java.io.IOException;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Scanner;
public class Main {
	final static String DATE_FORMAT = "dd.MM.yy";

	public static boolean isDateValid(String date)
	{
		try {
			DateFormat df = new SimpleDateFormat(DATE_FORMAT);
			df.setLenient(false);
			df.parse(date);
			return true;
		} catch (ParseException e) {
			return false;
		}
	}
	public static Calendar getCalendar(Date date) {
	    Calendar cal = Calendar.getInstance(Locale.US);
	    cal.setTime(date);
	    return cal;
	}
	public static boolean check(String a,String b) throws IOException, ParseException
	{
		Calendar m,n;
		int ans=1;
		if(!isDateValid(b))
			return false;
		else{
			DateFormat df = new SimpleDateFormat("dd.MM.yy");

			Date x = df.parse(a);
			Date y = df.parse(b);
			 m=getCalendar(x);
			n=getCalendar(y);
			ans=m.get(Calendar.YEAR)-n.get(Calendar.YEAR);
			if(n.get(Calendar.MONTH)>m.get(Calendar.MONTH)||n.get(Calendar.DATE)>m.get(Calendar.DATE))
				ans--;
		}
		return ans>=18;
	}
	public static void main(String args[]) throws IOException, ParseException
	{
		Scanner scan=new Scanner(System.in);
		String d1=scan.nextLine();
		String d2=scan.nextLine();
		String b1=d2.substring(0, 2);
		String b2=d2.substring(3, 5);
		String b3=d2.substring(6, 8);
		String ans="NO";
		if(check(d1, d2)||check(d1, b1+"."+b3+"."+b2)||check(d1, b2+"."+b1+"."+b3)||check(d1, b2+"."+b3+"."+b1)||check(d1, b3+"."+b1+"."+b2)||check(d1, b3+"."+b2+"."+b1))
			ans="YES";
		System.out.println(ans);

	}
}


#include<bits/stdc++.h>
#define cin(a) cin>>a;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define cout(a) cout<<a;
#define new() cout<<endl;
#define ff first
#define ss second
#define READ freopen("input.txt","r",stdin);
#define WRITE    freopen("output.txt","w",stdout);
#define fill(a,x) memset(a,x,sizeof(a));
#define loop(i,x,n) for(int i=x;i<n;i++)
#define loopr(i,x,n) for(int i=n;i>=x;i--)
#define TC() ll t;cin>>t;while(t--)
typedef long long ll;
#define MOD 1000000007
#define SIZE 100020
#define vec vector<ll>
#define vmp vector<pair<ll,ll> >
#define pb push_back
#define mp make_pair
#define all(a)  a.begin(), a.end()
#define ull unsigned long long
using namespace std;
ll gcd(ll x,ll y)
{
    if(y==0)
        return x;
    else
        return gcd(y,x%y);
}
int main(){
   cin >> w >> h;
	ll ans = 0;
	for(int i=1; i<w; i++)
		for(int j=1; j<h; j++)
			ans += min(i,w-i)*min(j,h-j);
	cout << ans << endl;

    return 0;
}


#include<bits/stdc++.h>
#define cin(a) cin>>a;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define cout(a) cout<<a;
#define new() cout<<endl;
#define ff first
#define ss second
#define READ freopen("input.txt","r",stdin);
#define WRITE    freopen("output.txt","w",stdout);
#define fill(a,x) memset(a,x,sizeof(a));
#define loop(i,x,n) for(int i=x;i<n;i++)
#define loopr(i,x,n) for(int i=n;i>=x;i--)
#define TC() ll t;cin>>t;while(t--)
typedef long long ll;
#define MOD 1000000007
#define SIZE 100020
#define vec vector<ll>
#define vmp vector<pair<ll,ll> >
#define pb push_back
#define mp make_pair
#define all(a)  a.begin(), a.end()
#define ull unsigned long long
using namespace std;
ll gcd(ll x,ll y)
{
    if(y==0)
        return x;
    else
        return gcd(y,x%y);
}
int main(){
 ll w,h;
   cin >> w >> h;
	ll ans = 0;
	for(int i=1; i<w; i++)
		for(int j=1; j<h; j++)
			ans += min(i,w-i)*min(j,h-j);
	cout << ans << endl;

    return 0;
}


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

int main() {
	ll w, h, ret;
	scanf("%lld %lld", &w, &h);
	a = w >> 1;
	b = h >> 1;
	ret = (a * (a + 1) + (w & 1)) * (b * (b + 1) + (h & 1));
	printf("%lld", ret);
	return 0;
}


// Shinchan Loves Coding :)))
#include<bits/stdc++.h>
#include<map>
#include<set>
using namespace std;

#define night_rider ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define int long long int
#define double long double
#define en "\n"
#define fi first
#define se second
#define MP make_pair
#define PB push_back
typedef vector<int> vi;
typedef pair<int,int> vii;
bool secdes(const pair<int,int>&a , const pair<int,int>&b){if(a.se==b.se){return a.fi>b.fi;}else{return a.se>b.se;}}//second descending !
bool sir(const pair<int,int>&a , const pair<int,int>&b){if(a.fi==b.fi){return a.se>b.se;}else{return a.first>b.first;}}//first descending !
//bool bysec(const pair<int,int>&a , const pair<int,int>&b){if(a.se==b.se)return }

const int no=3e5+5;
const int modulo=1e9+7;
const int big=1e7+1;
int a[no],sumb[no]={},suma[no]={};

signed main()
{
    night_rider
  //  freopen("input.txt","r",stdin);
  //  freopen("output.txt","w",stdout);

    int t;
    t=1;
    //cin>>t;
    while(t--)
    {
    	int w,h;
    	cin>>w>>h;
    	for(int i=1 ; i<w ; i++)
    		for(int j=1 ; j<h ; j++)
    			sum+=min(i,w-i)*min(j,h-j);
    	cout<<sum;
    }
}


#include <iostream>
#include <cmath>
#include <algorithm>
#include <map>
#include <iomanip>

using namespace std;

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

typedef long double DOUBLE;

const char R = 0;
const char G = 1;
const char B = 2;

const char EMPTY = 3;

const DOUBLE INF = 1e10;

inline char code(char c) {
    if (c == 'R') return R;
    if (c == 'G') return G;
    if (c == 'B') return B;
    return EMPTY;
}

struct State {
    char count[3][3][3];
    char have[3];
    char top[3];

    State() { memset(this, 0, sizeof(State)); }

    inline bool moveTop() {
        if (topFilled()) {
            count[top[0]][top[1]][top[2]]++;
            top[0] = top[1] = top[2] = EMPTY;
            return true;
        }
        return false;
    }

    inline bool topFilled() const {
        return top[0] != EMPTY && top[1] != EMPTY && top[2] != EMPTY;
    }
};

inline bool operator<(const State& s1, const State& s2) {
    return memcmp(&s1, &s2, sizeof(State)) < 0;
}

map<State, DOUBLE> dp;

DOUBLE DP(State& s);

DOUBLE tryPlace(State& s, char drop) {
    char t0 = s.top[0];
    char t1 = s.top[1];
    char t2 = s.top[2];

    bool moved = s.moveTop();
    DOUBLE best = INF;
    forn (i, 3) if (s.top[i] == EMPTY) {
        s.top[i] = drop;
        best = min(best, DP(s));
        s.top[i] = EMPTY;
    }
    if (moved) {
        s.count[t0][t1][t2]--;
        s.top[0] = t0;
        s.top[1] = t1;
        s.top[2] = t2;
    }
    return best;
}

DOUBLE DP(State& s) {
    auto it = dp.find(s);
    if (it != dp.end()) {
        return it->second;
    }
    int self = 1;
    DOUBLE e = 0.0;
    for (int drop = 0; drop < 3; ++drop) {
        int count = (drop == R) ? 1 : 2;
        DOUBLE best = INF;

        if (s.have[drop] > 0) {
            s.have[drop]--;
            best = tryPlace(s, drop);
            s.have[drop]++;
        }

        forn (a, 3) forn (b, 3) forn (c, 3) {
            if (s.count[a][b][c] > 0 && (a == drop || b == drop || c == drop)) {
                s.count[a][b][c]--;

                if (a == drop) {
                    s.have[c]++;
                    best = min(best, tryPlace(s, drop));
                    s.have[c]--;
                }

                if (b == drop) {
                    best = min(best, tryPlace(s, drop));
                }

                if (c == drop && a != drop) {
                    s.have[a]++;
                    best = min(best, tryPlace(s, drop));
                    s.have[a]--;
                }

                s.count[a][b][c]++;
            }
        }

        if (best > 1e9) {
            self += count;
        } else {
            e += count * best;
        }
    }

    if (self == 6) {
        return dp[s] = 0.0;
    }

    return dp[s] = (1 + e / 6.0) / (1.0 - self / 6.0);
}

string input[] = {
"RGB",
"GRG",
"BBB",
"GGR",
"BRG",
"BRB" };

int main() {

    State init;

    int n = 6;
    cin >> n;
    string s;
    forn (i, n - 1) {
        // s = input[i];
        cin >> s;
        forn (j, 3) s[j] = code(s[j]);
        init.count[s[0]][s[1]][s[2]]++;
    }
    s = input[n - 1];
    cin >> s;
    forn (j, 3) init.top[j] = code(s[j]);
    // init.normalizeTop();

    cout << fixed << setprecision(12) << (double) DP(init) << endl;
    // cout << dp.size() << endl;
    return 0;
}


#include <cstdio>
#include <utility>
#include <unordered_map>
#include <iostream>
#include <bitset>
using namespace std;
using ull = unsigned long long;
constexpr ull none = 0, red = 1, blue = 2, green = 3;
constexpr ull sort(ull x) {
    // cerr << bitset<54>(x) << "->";
#define INIT(X) unsigned x##X = (x >> ((X) + 1) * 6) & 0b111111
    INIT(0); INIT(1); INIT(2); INIT(3);
    INIT(4); INIT(5); INIT(6); INIT(7);
#undef INIT
#define SWAP(X, Y) \
    do { \
        unsigned temp = ((x##X ^ x##Y) & -(x##X < x##Y)); \
        x##X ^= temp; \
        x##Y ^= temp; \
    } while (0)
    SWAP(0, 1); SWAP(2, 3); SWAP(4, 5); SWAP(6, 7);
    SWAP(0, 2); SWAP(1, 3); SWAP(4, 6); SWAP(5, 7);
    SWAP(1, 2); SWAP(5, 6); SWAP(0, 4); SWAP(3, 7);
    SWAP(1, 5); SWAP(2, 6);
    SWAP(1, 4); SWAP(3, 6);
    SWAP(2, 4); SWAP(3, 5);
    SWAP(3, 4);
#undef SWAP
    x &= 0b111111;
#define MERGE(X) (x |= (ull) x##X << ((X + 1) * 6))
    MERGE(0); MERGE(1); MERGE(2); MERGE(3);
    MERGE(4); MERGE(5); MERGE(6); MERGE(7);
#undef MERGE
    // cerr << bitset<54>(x) << endl;
    return x;
}
constexpr unsigned encode(char l, char c, char r) {
    unsigned vl = l == 'R' ? red : l == 'G' ? green : blue;
    unsigned vc = c == 'R' ? red : c == 'G' ? green : blue;
    unsigned vr = r == 'R' ? red : r == 'G' ? green : blue;
    if(vl > vr)
        swap(vl, vr);
    return (vc << 4) | (vl << 2) | vr;
}
std::unordered_map<ull, double> dp;
double solve(ull tower);
double solve(ull tower, unsigned put) {
    if((tower & 0b11) && (tower & 0b1100) && (tower & 0b110000)) {
        tower = sort(tower) << 6;
    }
    double best = 1e9;
    if(!(tower & 0b110000))
        best = min(best, solve(tower | (put << 4)));
    if(!(tower & 0b1100))
        best = min(best, solve(tower | (put << 2)));
    if(!(tower & 0b11))
        best = min(best, solve(tower | put));
#if 0
    else if(!(tower & 0b11)) {
        if(put > ((tower >> 2) & 0b11))
            best = min(best, solve(tower | put));
        else
            best = min(best, solve((tower & ~0b1100ull) |
                                    (put << 2) |
                                    ((tower >> 2) & 0b11)));
    }
#endif
    return best;
}
double solve(ull tower) {
    if(!(tower & ~0b111111ull))
        return 0.0;
    tower = sort(tower);
    {
        auto ite = dp.find(tower);
        if(ite != dp.end())
            return ite->second;
    }
    double ans = 0;
    int progress = 0;
    for(unsigned i = red; i <= green; i++) {
#define HASZERO(V) (((V) - (~0ull / 3)) & ~(V) & (~0ull / 3 * 2))
#define HASVALUE(X, N) (HASZERO((X) ^ (~0ull / 3 * (N))))
        if(!HASVALUE(tower >> 6, i))
            continue;
#undef HASVALUE
#undef HASZERO
        double best = 1e9;
        for(int j = 6; tower & (0b111111ull << j); j += 6) {
            if(((tower >> j) & 0b11) == i) {
                best = min(best,
                        solve(tower & ~(0b110011ull << j), i));
            }
            if(((tower >> (j + 2)) & 0b11) == i) {
                ull x = ~(0b111111ull << j);
                ull y = ((tower >> j) & 0b11) << (j + 2);
                best = min(best, solve((tower & x) | y, i));
            }
            if(((tower >> (j + 4)) & 0b11) == i) {
                best = min(best,
                        solve(tower & ~(0b111111ull << j), i));
            }
        }
        ans += best * (i == red ? 1 : 2);
        progress += (i == red ? 1 : 2);
    }
    ans = (ans + 6) / progress;
    dp.insert(make_pair(tower, ans));
    return ans;
}
int main() {
    int n;
    while(scanf("%d", &n) == 1) {
        ull tower = 0;
        for(int i = n - 1; i >= 0; i--) {
            char s[4];
            scanf("%s", s);
            tower |= (ull) encode(s[0], s[1], s[2]) << (i * 6);
        }
        printf("%.15f\n", solve(tower));
    }
}

// ntuj - jczj97dvo8n70pj70e6v4


#include<bits/stdc++.h>
using namespace std;
inline char get_unempty_char()
{
	char ch;
	while(isspace(ch=getchar())) ;
	return ch;
}
const double eps(1e-10),Inf=1e+64;
typedef unsigned long long i64u;
const int RED=1,BLUE=2,GREEN=3,EMPTY=0,N=6,Base=67,mod=3000007;
int n,last[mod]={},next[mod]={},total_edge=0,s[N*3-1]={},tot=0;
i64u hv[mod]={};
double f[mod]={};
inline void add(i64u hash,double v)
{
	int u=hash%mod;
	next[++total_edge]=last[u];
	last[u]=total_edge;
	f[total_edge]=v;
	hv[total_edge]=hash;
}
inline int get_num(char ch)
{
	if(ch=='R') return RED;
	if(ch=='B') return BLUE;
	if(ch=='G') return GREEN;
	if(ch=='E') return EMPTY;
	assert(false);
}
void init()
{
	n=get_unempty_char()-'0';
	for(int i=1;i<=n;++i)
	{
		s[i]|=get_num(get_unempty_char())<<0;
		s[i]|=get_num(get_unempty_char())<<2;
		s[i]|=get_num(get_unempty_char())<<4;
	}
	tot=n;
}
inline i64u hash(int *s,int k,int up)
{
	static int v[N*3+10]={};
	i64u h=0;
	int tot=0;
	for(int i=1;i<=k;++i)
	{
		int c1=(s[i]>>4)&3 , c2=(s[i])&3 , c3=(s[i]>>2)&3;
		v[++tot]=c1>c2 ? (c3<<2)|c1|(c2<<4) : (c3<<2)|c2|(c1<<4);
	}
	sort(v+1,v+tot+1);
	int c1=(up>>4)&3 , c2=up&3 , c3=(up>>2)&3;
	if(c1>c2) up=c1|(c2<<4)|(c3<<2);
	for(int i=1;i<=tot;++i)
		h=h*Base+v[i];
	h=h*Base+up;
	return h;
}
double work(int *s,int tot,int up)
{
	i64u h=hash(s,tot,up);
	for(int i=last[h%mod];i;i=next[i])
		if(hv[i]==h)
			return f[i];
	double v[4]={Inf,Inf,Inf,Inf};
	int to=tot,D=6;
	if((up&3) && ((up>>2)&3) && ((up>>4)&3))
		s[++to]=up , up=0;
	for(int i=1;i<=tot;++i)
	{
		int c1=s[i]&3 , c2=(s[i]>>2)&3 , c3=(s[i]>>4)&3 , ns=s[i];
		if(c1 && c2 && c3 && v[c2]>eps)
		{
			s[i]=0;
			if(!(up&3)) v[c2]=min(v[c2],work(s,to,up|c2));
			else if(!(up>>4&3)) v[c2]=min(v[c2],work(s,to,up|c2<<4));
			if(!(up>>2&3)) v[c2]=min(v[c2],work(s,to,up|c2<<2));
			s[i]=ns;
		}
		if(c1 && c2 && v[c1]>eps)
		{
			s[i]=c3==0 ? 0 : s[i]&~3;
			if(!(up&3)) v[c1]=min(v[c1],work(s,to,up|c1));
			else if(!(up>>4&3)) v[c1]=min(v[c1],work(s,to,up|c1<<4));
			if(!(up>>2&3)) v[c1]=min(v[c1],work(s,to,up|c1<<2));
			s[i]=ns;
		}
		if(c2 && c3 && v[c3]>eps)
		{
			s[i]=c1==0 ? 0 : s[i]&~48;
			if(!(up&3)) v[c3]=min(v[c3],work(s,to,up|c3));
			else if(!(up>>4&3)) v[c3]=min(v[c3],work(s,to,up|c3<<4));
			if(!(up>>2&3)) v[c3]=min(v[c3],work(s,to,up|c3<<2));
			s[i]=ns;
		}
	}
	double sum=0;
	if(v[1]!=Inf) sum+=v[1] , D-=1;
	if(v[2]!=Inf) sum+=v[2]*2 , D-=2;
	if(v[3]!=Inf) sum+=v[3]*2 , D-=2;
	sum=D==6 ? 0 : (sum+6)/(6-D);
	add(h,sum);
	return sum;
}
int main()
{
	//freopen("jenga.in","r",stdin);
	//freopen("jenga.out","w",stdout);
	init();
	printf("%.15f\n",work(s,tot-1,s[tot]));
	//fclose(stdin);
	//fclose(stdout);
	return 0;
}


//ѹ�пδ�
#include<bits/stdc++.h>
#define ull unsigned long long
const double eps=1e-12,inf=1e12;
const int mod=(1<<20)-1,Base=65,Red=1,Blue=2,Green=3,empty=0;
using namespace std;
int n,f[20],s[1<<6],tot,nxt[mod+1],from[mod+1],t;
double ans[mod+1];
ull w[mod+1];
inline char read(){char ccc;while(isspace(ccc=getchar()));return ccc;}
inline int Read(char ccc){if(ccc=='R') return Red;if(ccc=='B') return Blue;if(ccc=='G') return Green;return empty;}
inline void add(ull u,double v){int x=u&mod;ans[++t]=v;nxt[t]=from[x];from[x]=t;w[t]=u;}
inline ull HASH(int *a,int k,int up)
{
	ull sum=0;
	static int g[20];
	int h=0;
	for(int i=1;i<=k;++i) if(a[i]) g[++h]=a[i];
	sort(g+1,g+1+h);
	for(int i=1;i<=h;++i) sum=sum*Base+g[i];
	sum=sum*Base+up;
	return sum;
}
inline double query(int *a,int k,int up)
{
	up=s[up];
	ull op=HASH(a,k,up);
	for(int i=from[op&mod];i;i=nxt[i]) if(w[i]==op) return ans[i];
	double v[4]={inf,inf,inf,inf};
	int oto=k,D=6;
	if((up&3)&&((up>>2)&3)&&((up>>4)&3)) f[++oto]=up,up=0;
	for(int i=1;i<=k;++i)
	{
		int c1=f[i]&3,c2=(f[i]>>2)&3,c3=(f[i]>>4)&3,opp=f[i];
		if(c1&&c2&&c3&&v[c2]>eps)
		{
			f[i]=0;
			if(!(up&3)) v[c2]=min(v[c2],query(f,oto,up|c2));
			else if(!(up>>4&3)) v[c2]=min(v[c2],query(f,oto,up|c2<<4));
			if(!(up>>2&3)) v[c2]=min(v[c2],query(f,oto,up|c2<<2));
			f[i]=opp;
		}
		if(c1&&v[c1]>eps)
		{
			f[i]=c3;
			if(!(up&3)) v[c1]=min(v[c1],query(f,oto,up|c1));
			else if(!(up>>4&3)) v[c1]=min(v[c1],query(f,oto,up|c1<<4));
			if(!(up>>2&3)) v[c1]=min(v[c1],query(f,oto,up|c1<<2));
			f[i]=opp;
		}
		if(c3&&v[c3]>eps)
		{
			f[i]=c1;
			if(!(up&3)) v[c3]=min(v[c3],query(f,oto,up|c3));
			else if(!(up>>4&3)) v[c3]=min(v[c3],query(f,oto,up|c3<<4));
			if(!(up>>2&3)) v[c3]=min(v[c3],query(f,oto,up|c3<<2));
			f[i]=opp;
		}
	}
	double sum=0;
	if(v[1]!=inf) sum+=v[1],D--;
	if(v[2]!=inf) sum+=v[2]*2,D-=2;
	if(v[3]!=inf) sum+=v[3]*2,D-=2;
	sum=(D==6?0:(sum+6)/(6-D));
	add(op,sum);
	return sum;
}
int main()
{
//	freopen("jenga.in","r",stdin);
//	freopen("jenga.out","w",stdout);
	n=read()^'0';
	for(int i=0;i<=3;++i)
		for(int j=0;j<=3;++j)
			for(int k=0;k<=3;++k)
				s[i|j<<2|k<<4]=i<k?(i|j<<2|k<<4):(k|j<<2|i<<4);
	for(int i=1;i<=n;++i)
	{
		f[i]|=Read(read());
		f[i]|=Read(read())<<2;
		f[i]|=Read(read())<<4;
		f[i]=s[f[i]];
	}
	tot=n;
	printf("%lf",query(f,tot-1,f[tot]));
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
const int N=50050;
int n, m, a[N], cp[N];
int b[N], d[N], ans[N];
bool vis[N];
vector<int>g[N];
bool find(int u){
	for(int v: g[u]){
		if(!vis[v]){
			vis[v] = 1;
			if(cp[v]==-1||pipei(cp[v]){
				cp[v] = u;
				return 1;
			}
		}
	}
	return 0;
}

int main(){
	scanf("%d%d",&n,&m);
	int v,q;
	memset(cp,-1,sizeof(cp));
	for(int i=1;i<=n;i++) scanf("%d",a+i);
	for(int i=1;i<=n;i++){
		scanf("%d",b+i);
	}
	scanf("%d",&q);
	for(int i=1;i<=q;i++) scanf("%d",d+i),vis[d[i]] = 1;
	for(int i=1;i<=n;i++)
	if(!vis[i]) g[a[i]].push_back(b[i]);
	int j = 0;
	for(int i=q;i>=1;i--){
		for(;j<5000;j++){
			memset(vis,0,sizeof(vis));
			if(!find(j)) break;
		}
		g[a[d[i]]].push_back(b[d[i]]);
		ans[i] = j;
	}
	for(int i=1;i<=q;i++) printf("%d\n",ans[i]);
}


#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
const int N=50050;
int n, m, a[N], cp[N];
int b[N], d[N], ans[N];
bool vis[N];
vector<int>g[N];
bool find(int u){
	for(int v: g[u]){
		if(!vis[v]){
			vis[v] = 1;
			if(cp[v]==-1||pipei(cp[v])){
				cp[v] = u;
				return 1;
			}
		}
	}
	return 0;
}

int main(){
	scanf("%d%d",&n,&m);
	int v,q;
	memset(cp,-1,sizeof(cp));
	for(int i=1;i<=n;i++) scanf("%d",a+i);
	for(int i=1;i<=n;i++){
		scanf("%d",b+i);
	}
	scanf("%d",&q);
	for(int i=1;i<=q;i++) scanf("%d",d+i),vis[d[i]] = 1;
	for(int i=1;i<=n;i++)
	if(!vis[i]) g[a[i]].push_back(b[i]);
	int j = 0;
	for(int i=q;i>=1;i--){
		for(;j<5000;j++){
			memset(vis,0,sizeof(vis));
			if(!find(j)) break;
		}
		g[a[d[i]]].push_back(b[d[i]]);
		ans[i] = j;
	}
	for(int i=1;i<=q;i++) printf("%d\n",ans[i]);
}


#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define ll long long
vector<int> X[100005];
ll dp[100005], fp[1003];
ll power(ll N, ll expo)
{
    ll ans = 2;
    while(expo)
    {
        if(expo % 2)
            ans = ans * N % MOD;
        N = N * N % MOD;
        expo /= 2;
    }
    return ans;
}

int main() {
    ios::sync_with_stdio(false); cin.tie(NULL); cout.precision(10);
    int M;
    cin >> M
    ll ans = 0;
    ll mmi = power(M, MOD-2);
    for(int i=2; i<=M; i++)
    {
        for(int j=i; j<M; j+= i)
            X[j].push_back(i);
        dp[i] = M;
        fp[ (int)X[i].size()-1 ] = M / i;
        for(int j=(int)X[i].size()-2; j>=0; j--)
        {
            fp[j] = M / X[i][j+1];
            for(int k=j+1; k<(int)X[i].size(); k++)
                if(X[i][k] % X[i][j] == 0)
                    fp[j] -= fp[k];
            dp[i] += 1LL * dp[ X[i][j] ] * fp[j] % MOD;
        }
        dp[i] = dp[i] % MOD * power(M - M/i, MOD-2) % MOD;
        ans += dp[i];
    }
    ans = (ans % MOD * mmi + 1) % MOD;
    cout << ans << "\n";
    return 0;
}


#include<bits/stdc++.h>
#define ll long long int
#define ull unsigned long long int
#define ld long double
#define pb push_back
#define pf pop_front
#define mp make_pair
#define mod 1000000007
#define mat vector<vector<int>>
using namespace std;
#define int ll
#define for1(i,a,b) for(int i=a;i<b;i++)
#define all(x) x.begin(),x.end()
#define fo(i,n) for(int i=0;i<n;i++)
//int max(auto a){int ans=-1e18;for(int i:a)if(i>ans)ans=i;return ans;}
//int min(auto a){int ans=1e18;for(int i:a)if(i<ans)ans=i;return ans;}
void print(auto a){for(auto i:a)cout<<i<<' ';cout<<endl;}
#define inp(n) int n;cin>>n;
#define inpa(a,n) int a[n];fo(i,n)cin>>a[i];
int modpow(int a,int n,int m=1e9+7)
{
	int ans=1;
	while(n>0)
	{
		if(n%2!=0)
			ans=(ans*a)%m;
		n/=2;
		a=(a*a)%m;
	}
	return ans;
}

signed main()
{
	int m;
	cin>>m;
	int ans=modpow(m,mod-2);
	int do1[m+1];
	for(int i=0;i<=m;i++)
		do1[i]=1;
	for(int i=2;i<=m;i++)
	{
		ans=((ans+(do1[i]*(modpow((m*(m-m/i))%mod,mod-2)*((((2*m-m/i))%mod*x)%mod))%mod)%mod)%mod+mod)%mod;
		for(int j=i*2;j<=m;j+=i)
			do1[j]-=do1[i];
	}
	cout<<ans<<endl;

}


#include <algorithm>
#include <iostream>

using namespace std;

int main()
{
    int a[5];

    cin >> a[0] >> a[1] >> a[2] >> a[3] >> a[4];

    sort(&a[0] &a[5]);

    int sum = a[0] + a[1] + a[2] + a[3] + a[4];

    bool f = true;

    for(i = 0; i + 2 < 5; i++)
    {
        if(a[i] == a[i + 1] == a[i + 2])
        {
            f = false;
            sum = sum - a[i] * 3;
            break;
        }
    }

    if(f)
    {
        for(i = 0; i + 1 < 5; i++)
        {
            sum = sum - a[i] * 2;
            break;
        }
    }

    cout << sum << endl;

    return 0;
}


#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
// #include <conio.h>

using namespace::std;

struct NumInfo
{
	int totalPoint = 0;

	void PlusPlus(const int&);

private:
	int _numOfRepetition = 0;
};

void NumInfo::PlusPlus(const int& number)
{
	if ((_numOfRepetition < 3) && (++_numOfRepetition > 1))
		totalPoint = number * _numOfRepetition;
}

int main()
{
	int f[5];
	NumInfo g[110];
	int maxDiscard = 0;
	int sum = 0;

	for (int i = 0; i < 5; ++i)
	{
		scanf("%d", f + i);
		sum += f[i];

		g[f[i]].PlusPlus(f[i]);
		if (maxDiscard < g[f[i]].totalPoint)
			maxDiscard = g[f[i]].totalPoint;
	}

	printf("%d", sum - maxDiscard);

	// _getch();
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main()
{
    int c,total=0,mayor=0,menor=99999999;
    vector <int> nums;
    for(int i =0; i<5;i++){
        cin >> c;
        total = total + c;
        nums.push_back(c);
    }
    mayor = total;
    for(int i =0;i<nums.size();i++){
            for(int a =0;a<nums.size();a++){
                    if(a==i){continue;}
                    if(nums[i]==nums[a]){ :3
                        if(mayor==total){mayor = mayor - (nums[i]*2);}else{if((mayor - nums[i])!=0 and (mayor - nums[i])!=nums[i]){mayor = mayor - nums[i];}}

                     }

            }

            if(menor>mayor){menor = mayor;}
            mayor = total;

    }
    cout << menor;
    return 0;
}


#include "stdio.h"
#include "iostream"
#include "stdlib.h"
#include "math.h"
#include "string.h"
#include <locale>
#include <vector>
#include <array>
#include <algorithm>
#include <iomanip>
#include <bitset>
#include <set>
#include <ctime>
#include <sstream>
using namespace std;

int main(){
	long double n,ans=0; cin >> n;
	for (int i = 1; i <= n; i++)
		ans += to_string(i).length();
		cout << ans;
}


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

int main()
{
  int n;
  cin >> n;
  int count = 0;
  int buf  = n;
  while(buf != 0)
  {
    buf /= 10;
    count++;
  }
/////////////////////////
  buf=n;
 	int result=0;
  while(count>=0)
  {
    if(count==1)
		{
  		result=n;
      break;
 		}
    result+=buf-pow(10,count-1)*count;
    buf=pow(10,count-1)-1;
    count--;
  }
  ///////////////////////
  сout<<result;
  return 0;
}


#include<iostream>
using namespace std;
int tavan10(int a){
    int b=1;
    for(int i=0;i<a;i++){
        b=b*10;
    }
    return b;
}
int andaze(int n){
    int b=0
    for(int i=0;i<9&&n>0;i++){
        n=n/10;
        b++;
    }
    return b;
}
int main(){
    long long int n;
    int x;
    cin>>n;
    x=andaze(n);
    long long int y=0
    (for(int i=x-2;i>0;i--){
        y=y+tavan10(i);
    }
    cout<<n-(tavan10(x-1))+1+((x-1)*tavan10(x-1))-y;
}


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

long long ans = 0, n;

int main() {
    cin >> n;
    int tmp = 9;
    for (int i = 1; i <= 10; i++) {
        ans += (i * (min(n, tmp)));
        n -= min(n, tmp);
        tmp *= 10;
    }
    cout << ans << endl;
    return 0;
}


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

int main(){

  string pearls;
  int c1=0,c2=0;
  cin>>pearls;
  int x=pearls.size();
  for(int i=0;i<x;i++){
    if(pearls[i]=='-')
      c1++;
    if(pearls[i]=='o')
      c2++;
  }

  if(c2%2 != 0 && c1%2!=0)
    cout<<"YES";
  else
    if(c2%2 ==0 && c1%2==0)
      cout<<"YES";
  else if(c1==0 || c2==0)
	  cout<<"YES";
  else
    cout<<"NO";

  return 0;
}


#include<iostream>
#include<cstring>
using namespace std;
int main()
{
	string a;
	cin>>a;
	int m1=a.size();
	int zz=0,xl=0;
	for(int i=0;i<m1;i++)
	{
		if(a[i]=='-')
		{
			xl++;
		}
		else
		{
			zz++;
		}
	}
	if(xl%zz!=0)
	{
		cout<<"NO";
	}
	else
	{
		cout<<"YES";
	}
	return 0;
	}


#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<cmath>
using namespace std;
const int maxn=1e5;
int n,t,sum,ans;
char s[maxn];
int a[maxn];
int main(){
scanf("%s",s);
n=strlen(s);
for(int i=0;i<n;i++){
if(s[i]=='-')sum++;
}
if(sum%2==0||sum==n||sum=n/2&&n%2==0)
		printf("Yes\n");
	else
		printf("No\n");

}


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

#define pb(x) push_back(x)
#define fr(a,b) for(int i=a;i<b;i++)

int main()
{
    string s;
    cin>>s;
    int cnt=0;
    fr(0,s.length())
    {
        if(s[i]=='o')
        {
            cnt++;
        }
    }
    if(cnt==(s.length()-1))
    {
        cout<<"no";
    }
    else if(cnt==s.length() || cnt==0 || cnt==(s.length()-cnt))
    {
        cout<<"Yes";
    }
    else if(cnt<(s.length-cnt))
    {
        cout<<"no";
    }
    else if(cnt%(s.length()-cnt)==0 || (s.length()-cnt)%cnt==0 )
    {
        cout<<"yes";
    }
    else
    {
        cout<<"no";
    }

}


#include <bits/stdc++.h>

using namespace std;

int main(){
    int n,m;

    cin>>n,m;

    int prod = n * m;
    int  mod = prod % 2;

    if((mod % 2) == 0 )
    cout<<"Malvika"<<endl
    else
    cout<<"Akshat"<<endl;
}


#include <iostream>
using namespace std;
int main(){
int m,n,;
cin >>m,n;

if (m>n) i=n;
    else i=m;
if (i%2==0) cout<<"Malvika";
           else cout <<"Akshat";
       }


#include<bits/stdc++.h>

using namespace std;

int main()
{
    int n,i,j,k,t,m;

    cin>>n>>m;

    int s=m*n;
    if(s==2)cout<<"Akshat"<<endl

    else if(s%2==0)cout<<"Malvika"<<endl;

    else cout<<"Akshat"<<endl;

}


#include<iostream>
using namespace std;
int main(){
    int i,j,multi;
    cin>>i;
    cin>>j;
    multi = i*j;
    if(multi==2){
        cout<<"Akshat";
    }
    if((multi%2=0)&&(multi!=2)){
        cout<<"Malvika"; }
        else {
        cout<<"Akshat";

    }
    }


/*
 * File:   G.cpp
 * Author: yzq110abc
 *
 * Created on 2010年12月10日, 下午7:10
 */

#include <iostream>
#include <cstdio>
#include <vector>
#include <cmath>
#define EPS (1e-9)
using namespace std;

const int MAXL = 20000;

typedef pair<int, int> Edge;
Edge p[MAXL];
vector<Edge> e;

int Init(){

    for (int i = 0; i * i < MAXL; i++){
        for (int j = i + 1; j * j + i * i < MAXL; j++){
            int now = i * i + j * j;
            p[now].first = i;
            p[now].second = j;
        }
    }
    return 0;
}

inline bool cmp(Edge a, Edge b){
    return a.first * a.first + a.second * a.second >
           b.first * b.first + b.second * b.second;
}

inline bool cmp2(Edge a, Edge b){
    return atan2(a.second, a.first) < atan2(a.second, a.first) - EPS;
}

int L(int a, int b){
    return a * a + b * b;
}

int main() {

    Init();
    int n;
    int sum = 0;
    scanf("%d", &n);
    for (int i = 0; i < MAXL && e.size() <= n; i++){
        if (p[i].first == 0 && p[i].second == 0) continue;
        sum ^= p[i].first ^ p[i].second;
        e.push_back(p[i]);
    }
    reverse(e.begin(), e.end());
    for (vector<Edge>::iterator it = e.begin(); it != e.end(); it++){
        if ( ( ( sum ^ it->first ^ it->second) & 1) == 0){
            e.erase(it);
            break;
        }
    }
    sort(e.begin(), e.end(), cmp);
    int ix = 0, iy = 0;
    for (vector<Edge>::iterator it = e.begin(); it != e.end(); it++){
        int fx = 1, fy = 1;
        int xx = it->first, yy = it->second;
        if (ix > 0) fx = -1;
        if (iy > 0) fy = -1;

        if (L(fx * xx + ix, fy * yy + iy) < L(fx * yy + ix, fy * xx + iy))
            *it = make_pair(fx * xx, fy * yy);
        else
            *it = make_pair(fx * yy, fy * xx);
        ix = it->first + ix;
        iy = it->second + iy;
    }
    sort(e.begin(), e.end(), cmp2);
    puts("YES");
    for (vector<Edge>::iterator it = e.begin(); it != e.end(); it++){
        printf("%d %d\n", ix, iy);
        ix += it->first;
        iy += it->second;
    }
    return 0;
}


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

using namespace std;

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

#define M 100000
int dx[M],dy[M];

int x[10010],y[10010];

int main2(int N){
    int i,j;

//  cin >> N;

    for(i=0;i*i<M;i++) for(j=0;i*i+j*j<M;j++){
        dx[i*i+j*j] = i;
        dy[i*i+j*j] = j;
    }

    int c = 0, xsum = 0, ysum = 0;
    for(i=2;;i++) if(dx[i] != 0 || dy[i] != 0){
        x[c] = dx[i]; y[c] = dy[i]; xsum += dx[i]; ysum += dy[i]; c++;
        if(c == N) break;
    }
    if(xsum % 2 != ysum % 2) y[0] = 0;
    if(xsum % 2 != 0) REP(i,N) if(x[i] % 2 != y[i] % 2){
        swap(x[i],y[i]);
        break;
    }

    while(1){
        int X = 0, Y = 0;
        for(i=N-1;i>=0;i--){
            if(X > 0) x[i] = -x[i]; X += x[i];
            if(Y > 0) y[i] = -y[i]; Y += y[i];
        }
        if(X == 0 && Y == 0) break;

        REP(i,N){
            x[i] = abs(x[i]);
            y[i] = abs(y[i]);
        }

        while(1){
            int r = rand() % N;
            if(x[r] % 2 == y[r] % 2){
                swap(x[r],y[r]);
                break;
            }
        }
    }

//  cout << N << endl;
//  if(X != 0 || Y != 0) cout << "warning" << endl;
//  REP(i,N) cout << x[i] << ' ' << y[i] << endl;

    vector <pair <double, int> > v;
    REP(i,N){
        double theta = atan2(y[i],x[i]);
        v.push_back(make_pair(theta,i));
    }
    sort(v.begin(),v.end());

    printf("YES\n");
    xsum = 0; ysum = 0;
    REP(i,N){
        printf("%d %d\n",xsum,ysum);
        int id = v[i].second;
        xsum += x[id]; ysum += y[id];
    }

    return 0;
}

int main(void){
//  for(int i=3;;i++) main2(i);
    int N;
    cin >> N;
    main2(N);
    return 0;
}


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

using namespace std;

const int LIMIT = 1000000;

typedef pair<int, int> PII;
PII p[LIMIT];
vector<PII> v;

inline bool pr(const PII& lhs, const PII& rhs) {
        return atan2(lhs.second, lhs.first) < atan2(rhs.second, rhs.first) - 1e-8;
}

inline int R(const PII& p) {
        return p.first * p.first + p.second * p.second;
}

int main() {
        int n, s, x, y, nx, ny, tx, ty, dx, dy;

        scanf("%d", &n);
        for (int i = 0, ii; (ii = i * i) < LIMIT; ++i) {
                for (int j = i, jj; (jj = i * i + j * j) < LIMIT; ++j) {
                        p[jj].first = i;
                        p[jj].second = j;
                }
        }

        s = 0;
        for (int i = 0; i < LIMIT && (int)v.size() <= n; ++i) {
                if (p[i].first != 0 || p[i].second != 0) {
                        s += R(p[i]);
                        v.push_back(p[i]);
                }
        }

        reverse(v.begin(), v.end());
        for (vector<PII>::iterator it = v.begin(); it != v.end(); ++it) {
                if ((s - R(*it)) % 2 == 0) {
                        v.erase(it);
                        break;
                }
        }

        x = y = 0;
        for (vector<PII>::iterator it = v.begin(); it != v.end(); ++it) {
                nx = ny = LIMIT;
                dx = it->first;
                dy = it->second;
                for (int i = 0; i < 2; ++i) {
                        for (int j = 0; j < 2; ++j) {
                                for (int k = 0; k < 2; ++k) {
                                        tx = x + dx;
                                        ty = y + dy;
                                        if (abs(tx) + abs(ty) < abs(nx) + abs(ny)) {
                                                nx = tx;
                                                ny = ty;
                                                *it = make_pair(dx, dy);
                                        }
                                        dx = -dx;
                                }
                                dy = -dy;
                        }
                        swap(dx, dy);
                }
                x = nx;
                y = ny;
        }

        sort(v.begin(), v.end(), pr);
        x = y = 0;
        puts("YES");
        for (vector<PII>::iterator it = v.begin(); it != v.end(); ++it) {
                printf("%d %d\n", x, y, atan2(it->second, it->first));
                x += it->first;
                y += it->second;
        }
        if (x != 0 || y != 0) {
                throw 1;
        }

        return 0;
}


//UW 4feet
#include <cstdio>
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <string>
#include <cmath>
#include <cstdlib>
#include <numeric>

using namespace std;
#define X first
#define Y second
#define FI first
#define SE second
#define ST first
#define ND second
#define MP make_pair
#define PB push_back
typedef long long LL;
typedef double D;
typedef long double LD;
typedef vector<int> VI;
typedef pair<int,int> PII;
#define REP(i,n) for (int i=0;i<(n);++i)
#define FOR(i,a,b) for (VAR(i,a);i<=(b);++i)
#define FORD(i,a,b) for(VAR(i,a);i>=(b);--i)
#define FORE(e,v) for(VAR(e,v.begin());e!=v.end();++e)
#define VAR(a,b) __typeof(b) a=(b)
#define SIZE(a) ((int)(a).size())
#define ALL(x) (x).begin(),(x).end()
#define CLR(x,a) memset(x,a,sizeof(x))

const int M = 100013;

set<LL> s;
int a[M], px[M];
vector<pair<D,PII> > t;
PII xx[M];

int main() {
    srand(1313);
    int n;
    scanf("%d",&n);
    REP(i,M) a[i] = i;
    a[0] = 1;
    LL sx = 0, sy = 0;
    REP(j,n+1)
    {
        int x = 0;
        LL r = 1LL*a[0]*a[0];
        REP(i,M)
        {
            while(s.count(1LL*i*i + 1LL*a[i]*a[i])) a[i]++;
            if(1LL*i*i + 1LL*a[i]*a[i] < r) x = i, r = 1LL*i*i + 1LL*a[i]*a[i];
            if(a[i]==i) break;
        }
        if(rand()%2)
        {
            sx += x;
            sy += a[x];
            t.PB(MP(atan2(a[x],x),MP(x,a[x])));
        }
        else
        {
            sx += a[x];
            sy += x;
            t.PB(MP(atan2(x,a[x]),MP(a[x],x)));
        }
        s.insert(r);
        a[x]++;
    }
    FORD(i,SIZE(t)-1,1)
        if((sx-t[i].Y.X)%2 == (sy-t[i].Y.Y)%2)
        {
            sx -= t[i].Y.X;
            sy -= t[i].Y.Y;
            FOR(j,i,SIZE(t)-2) t[j] = t[j+1];
            t.pop_back();
            if(sx%2)
                swap(t[0].Y.X,t[0].Y.Y);
            break;
        }
    REP(i,n) xx[i] = MP(t[i].Y.X,i);
    sort(xx,xx+n);
    int ss = 0;
    FORD(i,n-1,0) if(ss <= 0)
        {
            ss += xx[i].X;
        }
        else
        {
            t[xx[i].Y].Y.X *= -1;
            ss -= xx[i].X;
        }
    if(ss) while(1);//return -1/0;
    REP(i,n) xx[i] = MP(t[i].Y.Y,i);
    sort(xx,xx+n);
    ss = 0;
    FORD(i,n-1,0) if(ss <= 0)
        {
            ss += xx[i].X;
        }
        else
        {
            t[xx[i].Y].Y.Y *= -1;
            ss -= xx[i].X;
        }
    if(ss) while(1);//return -1/0;
    REP(i,n) t[i].X = atan2(t[i].Y.Y, t[i].Y.X);
    sort(t.begin(),t.end());
    sx = 0, sy = 0;
    puts("YES");
    REP(i,n)
    {
        cout << sx << " " <<  sy << endl;
        sx += t[i].Y.X;
        sy += t[i].Y.Y;
    }
    return 0;
}


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

#define MAX_N 200000

int n;
int numbers[MAX_N];
int exists[MAX_N + 1];

struct TNode {
    int l, r, sum;
    TNode *left, *right;
    int first, last;
};

deque<TNode> nodes;

TNode *root;

TNode* newNode() {
    nodes.push_back();
    return &nodes.back();
}

Node* fillNode(int first, int last) {
    if (first >= last) {
        return nullptr;
    }
    int mid = (first + (last - first) / 2);
    Node * result = newNode();
    result->first = first;
    result->last = last;
    result->l = first;
    result->r = last - 1;
    result->left = fillNode(l, mid);
    result->right = fillNode(mid + 1, r);
    result->sum = 0;
    if (!result->left && !result->right) {
        result->sum = l;
    } else {
        if (result->left) {
            result->sum += result->left->sum;
        }
        if (result->right) {
            result->sum += result->right->sum;
        }
    }
    return result;
}

void fixup(Node * node, Node * parent) {
    if (node->r < parent->l) {
        node->sum = (node->last - node->first) * parent->l;
        node->l = node->r = parent->l;
    }
}

int update(Node *node, int first, int last, int size, Node * parent) {
    if (first >= node->last || last <= node->first) return 0;
    if (parent)
        fixup(node, parent);
    if (node->l >= size) return 0;

    if (first <= node->first) {
        node->l = size;
    }
    if (node->last <= last) {
        node->r = max(node->r, size);
    }

    if (first <= node->first && node->last <= last && node->r <= size) {
        int new_sum = (node->last - node->first) * size;
        int result = new_sum - node->sum;
        node->sum = new_sum;
        return result;
    }

    int sum_from_child = 0;
    if (node->left) {
        sum_from_child += update(node->left, first, last, size, node);
    }
    if (node->right) {
        sum_from_child += update(node->right, first, last, size, node);
    }

    node->sum += sum_from_child;
    return sum_from_child;
}

int set_from(int first, int last) {
    if (first >= last) return 0;
    int barSize = last;
    int barIdx = first;
    return update(root, barIdx, n, barSize, nullptr);
}

int main() {
    std::ios_base::sync_with_stdio(false);
    cin >> n;
    root = fillNode(0, n);
    fill(begin(exists), end(exists), -1);
    for (int i = 0; i < n; ++i) {
        cin >> numbers[i];
        exists[numbers[i]] = i;
    }

    int64_t result = 0;
    for (int gcd = MAX_N; gcd >= 1; --gcd) {
        std::vector<int> idxs;
        for (int i = gcd; i <= MAX_N; i += gcd) {
            if (exists[i] >= 0)
                idxs.push_back(exists[i]);
        }
        if (idxs.size() < 2) continue;
        nth_element(begin(idxs), begin(idxs) + 2, end(idxs));
        int x1 = idxs[0];
        int x2 = idxs[1];
        nth_element(begin(idxs), begin(idxs) + idxs.size() - 2, end(idxs));
        int x3 = idxs[idxs.size() - 2];
        int x4 = idxs[idxs.size() - 1];

        result += gcd * set_from(0, x3);
        result += gcd * set_from(x2, idxs.size());
        result += gcd * set_from(x1 + 1, x4);
    }
}


# include <cstdio>
# include <iostream>
# include <cstring>
using namespace std;
typedef long long ll;
const int maxn = 200005;
int n;
ll val[maxn], ans[maxn], id[maxn], le1[maxn], le2[maxn], ri1[maxn], ri2[maxn];
struct no
{
	ll maxx;
	ll minn;
	ll sum;
	ll flag;
}node[maxn * 4];

void pushup(int root)
{
	node[root].maxx = max(node[root << 1].maxx, node[(root << 1)| 1].maxx);
	node[root].minn = min(node[root << 1].minn, node[(root << 1) | 1].minn);
	node[root].sum = node[root << 1].sum + node[(root << 1) | 1].sum;
}

void pushdown(int root, int le, int ri)
{
	int mid = (le + ri) >> 1;
	if (node[root].flag)
	{
		node[root << 1].flag = node[root << 1].maxx = node[root << 1].minn = node[root].flag;
		node[(root << 1) | 1].flag = node[(root << 1) | 1].maxx = node[(root << 1) | 1].minn = node[root].flag;
		node[root << 1].sum = node[root << 1].flag*(mid - le + 1);
		node[(root << 1) | 1].sum = node[(root << 1) | 1].flag*(ri - mid);
		node[root].flag = 0;
	}
}

void build(int root, int le, int ri)
{
	node[root].flag = 0;
	if (le == ri)
	{
		node[root].maxx = node[root].minn = node[root].sum = le;
		return;
	}
	int mid = (le + ri) >> 1;
	build(root << 1, le, mid);
	build((root << 1) | 1, mid + 1, ri);
	pushup(root);
}

void update(int oper_le, int oper_ri, int val, int le, int ri, int root)
{
	if (oper_le > oper_ri)
		return;
	if (node[root].minn >= val)
		return;
	if (oper_le <= le&&ri <= oper_ri&&node[root].maxx <= val)
	{
		node[root].flag = node[root].maxx = node[root].minn = val;
		node[root].sum = ll(ri - le + 1)*val;
		return;
	}
	pushdown(root, le, ri);
	int mid = (le + ri) >> 1;
	if (oper_le <= mid)
	{
		update(oper_le, oper_ri, val, le, mid, root << 1);
	}
	if (oper_ri > mid)
	{
		update(oper_le, oper_ri, val, mid + 1, ri, (root << 1) | 1);
	}
	pushup(root);
}
void solve()
{
	int i, j, k; cin>>n;
	memset(id, 0, sizeof(id));
	for ( int i = 1;i <= n;i++ )
	{
		cin>>val[i];
		id[val[i]] = i;
	}
	for (i = 1; i <= 200000; i++)
	{
		for (j = i; j <= 200000; j += i)
		{
			if (id[j])
			{
				if (le1[i] == 0 || id[j] < le1[i])
				{
					le2[i] = le1[i];
					le1[i] = id[j];
				}
				else if (le2[i] == 0 || id[j] < le2[i])
				{
					le2[i] = id[j];
				}
				if (ri1[i] == 0 || id[j] > ri1[i])
				{
					ri2[i] = ri1[i];
					ri1[i] = id[j];
				}
				else if (ri2[i] == 0 || id[j] > ri2[i])
				{
					ri2[i] = id[j];
				}
			}
		}
	}
	build(1, 1, n);
	for (i = 200000; i >= 1; i--)
	{
		if (le1[i] != ri1[i])
		{
			update(1, le1[i], ri2[i], 1, n, 1);
			update(le1[i] + 1, le2[i], ri1[i], 1, n, 1);
			update(le2[i] + 1, n, n + 1, 1, n, 1);
		}
		ans[i] = 1LL*n*(n + 1) - node[1].sum;
	}
	ll res = 0;
	for (i = 200000 - 1; i >= 1; i--)
	{
		res = res + 1LL*(ans[i + 1] - ans[i])*i;
	}
	printf("%I64d", res);
}
int main(void)
{
	solve();
	return 0;


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

#define MAX_N 200000

int n;
int numbers[MAX_N];
int exists[MAX_N + 1];

struct TNode {
    int l, r, sum;
    TNode *left, *right;
    int first, last;
};

deque<TNode> nodes;

TNode *root;

TNode* newNode() {
    nodes.emplace_back();
    return &nodes.back();
}

Node* fillNode(int first, int last) {
    if (first >= last) {
        return nullptr;
    }
    int mid = (first + (last - first) / 2);
    Node * result = newNode();
    result->first = first;
    result->last = last;
    result->l = first;
    result->r = last - 1;
    result->left = fillNode(l, mid);
    result->right = fillNode(mid + 1, r);
    result->sum = 0;
    if (!result->left && !result->right) {
        result->sum = l;
    } else {
        if (result->left) {
            result->sum += result->left->sum;
        }
        if (result->right) {
            result->sum += result->right->sum;
        }
    }
    return result;
}

void fixup(Node * node, Node * parent) {
    if (node->r < parent->l) {
        node->sum = (node->last - node->first) * parent->l;
        node->l = node->r = parent->l;
    }
}

int update(Node *node, int first, int last, int size, Node * parent) {
    if (first >= node->last || last <= node->first) return 0;
    if (parent)
        fixup(node, parent);
    if (node->l >= size) return 0;

    if (first <= node->first) {
        node->l = size;
    }
    if (node->last <= last) {
        node->r = max(node->r, size);
    }

    if (first <= node->first && node->last <= last && node->r <= size) {
        int new_sum = (node->last - node->first) * size;
        int result = new_sum - node->sum;
        node->sum = new_sum;
        return result;
    }

    int sum_from_child = 0;
    if (node->left) {
        sum_from_child += update(node->left, first, last, size, node);
    }
    if (node->right) {
        sum_from_child += update(node->right, first, last, size, node);
    }

    node->sum += sum_from_child;
    return sum_from_child;
}

int set_from(int first, int last) {
    if (first >= last) return 0;
    int barSize = last;
    int barIdx = first;
    return update(root, barIdx, n, barSize, nullptr);
}

int main() {
    std::ios_base::sync_with_stdio(false);
    cin >> n;
    root = fillNode(0, n);
    fill(begin(exists), end(exists), -1);
    for (int i = 0; i < n; ++i) {
        cin >> numbers[i];
        exists[numbers[i]] = i;
    }

    int64_t result = 0;
    for (int gcd = MAX_N; gcd >= 1; --gcd) {
        std::vector<int> idxs;
        for (int i = gcd; i <= MAX_N; i += gcd) {
            if (exists[i] >= 0)
                idxs.push_back(exists[i]);
        }
        if (idxs.size() < 2) continue;
        nth_element(begin(idxs), begin(idxs) + 2, end(idxs));
        int x1 = idxs[0];
        int x2 = idxs[1];
        nth_element(begin(idxs), begin(idxs) + idxs.size() - 2, end(idxs));
        int x3 = idxs[idxs.size() - 2];
        int x4 = idxs[idxs.size() - 1];

        result += gcd * set_from(0, x3);
        result += gcd * set_from(x2, idxs.size());
        result += gcd * set_from(x1 + 1, x4);
    }
}


#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <vector>
#define lc idx << 1
#define rc idx << 1 | 1
#define lson l, mid, lc
#define rson mid + 1, r, rc
using namespace std;
const int N = 401000;
typedef long long LL;
LL sum[N << 2];
int cov[N << 2], mn[N << 2];
void pushup(int idx) {
	sum[idx] = sum[lc] + sum[rc];
	mn[idx] = mn[lc];
}
void pushdown(int l, int r, int mid, int idx) {
	if (cov[idx] != 0) {
		cov[lc] = cov[rc] = cov[idx];
		mn[lc] = cov[idx];
		mn[rc] = cov[idx];
		sum[lc] = (LL)cov[idx] * (mid - l + 1);
		sum[rc] = (LL)cov[idx] * (r - mid);
		cov[idx] = 0;
	}
}
void build(int l, int r, int idx) {
	if (l == r) {
		sum[idx] = l;
		mn[idx] = l;
		return ;
	}
	int mid = (l + r) >> 1;
	build(lson);
	build(rson);
	pushup(idx);
}
void update(int L, int R, int val, int l, int r, int idx) {
	if (L > R) return ;
	if (L <= l && r <= R) {
		cov[idx] = val;
		mn[idx] = val;
		sum[idx] = (LL)val * (r - l + 1);
		return ;
	}
	int mid = (l + r) >> 1;
	pushdown(l, r, mid, idx);
	if (L <= mid) update(L, R, val, lson);
	if (R > mid) update(L, R, val, rson);
	pushup(idx);
}
int left(int L, int R, int val, int l, int r, int idx) {
	if (l == r) {
		if (mn[idx] < val) return l;
		else return 0;
	}
	int mid = (l + r) >> 1;
	pushdown(l, r, mid, idx);
	if (R <= mid) {
		return left(L, R, val, lson);
	}
	else if (L > mid) {
		return left(L, R, val, rson);
	}
	else {
		if (mn[rc] < val) return left(L, R, val, rson);
		else return left(L, R, val, lson);
	}
}
// h[i] = sigma n - next[j] + 1
int n, a[N];
const int M = 200000;
vector<int> v[201000];
LL h[N], b[N];
void update(int L, int R, int val) {
	int x = left(L, R, val, 1, n, 1);
	update(L, x, val, 1, n, 1);
}
int main ()
{
	scanf("%d", &n);
	for (int i = 1; i <= n; i ++)
		scanf("%d", &a[i]);
	for (int i = 1; i <= M; i ++)
		for (int j = 1; j <= n; j ++)
			if (a[j] % i == 0)
				v[i].push_back(j);
	build(1, n, 1);
	for (int i = M; i >= 1; i --) {
		h[i] = 1LL * n * (n + 1) - sum[1];
		int k = v[i].size() - 1;
		if (k >= 1) {
			update(v[i][1] + 1, n, n + 1);
			update(v[i][0] + 1, v[i][1], v[i][k]);
			update(1, v[i][0], v[i][k - 1]);
		}
	}

	LL ans = 0;
	h[0] = 3;
	for (int i = 1; i <= M; i ++)
		b[i] = h[i] - h[i - 1], ans += b[i] * i;
	printf("%I64d\n", ans);
	return 0;
}


#include<iostream>
#include<iomanip>
#include<algorithm>
#include<cstring>
#include<string>
#include<cmath>
#include<vector>
#include<queue>
#include<stack>
#include<map>
#include<set>
using namespace std;
const int inf=1e9,dx[]={-1,0,1,0},dy[]={0,-1,0,1};
int x,y;
set<long long> st;
void dfs(long long num)
{
	if(x>n)
		return ;
	dfs(num*10+x);
	dfs(num*10+y);
	st.insert(num);
}
int main(){
	for(int x=0;x<=9;x++)
		for(int y=0;y<=9;y++)
			dfs(0);
	cout<st.size();
	return 0;
}


#include<bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<char> vc;
typedef vector<bool> vb;

set<ll> ans;

ll n;

void generate(ll x, ll y, ll base){
    ans.insert(base);
    ll nx = base*10+x;
    ll ny = base*10+y;
    if(nx>0 && nx<=n)
        generate(x,y,nx);
    if(ny>0 && ny<=n)
        generate(x,y,ny);
}

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

    cin >> n;

    for(ll i=0; i<10; i++)
        for(ll j=0; j<10; j++)
            generate(i,j,0);

    cout << ans.size()-1 << '\n';

    return 0;
}


#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
#include<unordered_map>
#include<unordered_set>
using namespace std;
typedef	long long ll;
typedef unsigned long long ull;
#define all(v) ((v).begin()),((v).end())
#define sz(v) ((int)((v).size()))
#define PI(n) ((double)acos(n))
#define pw2(n) (1LL<<(n))
#define sfi1(v) scanf("%d",&v)
#define sfi2(v1,v2) scanf("%d%d",&v1,&v2)
#define sfi3(v1,v2,v3) scanf("%d %d %d",&v1,&v2,&v3)
int dx8[8] = { 1, -1, 0, 0, 1, 1, -1, -1 };
int dy8[8] = { 0, 0, 1, -1, 1, -1, 1, -1 };
void file()
{
#ifndef ONLINE_JUDGE
	freopen("in.txt", "r", stdin);
	//freopen("out.txt", "w", stdout);
#else
	// online submission
#endif
}
void fast()
{
	std::ios_base::sync_with_stdio(0);
	cin.tie(NULL); cout.tie(NULL);
}
unordered_set<ll> ans;
ll n;
int find(ll i, ll j, ll num){
	if (num > n) return 0;
	ans.insert(num);
	if (i != 0 || num != 0) find(i, j, num * 10 + i);
	if (j != 0 || num != 0) find(i, j, num * 10 + j);
}
int main()
{

	cin >> n;
	for (ll i = 0; i < 10; i++){
		for (ll j = 0; j < 10; j++){
			find(i, j, 0);
		}
	}
	/*for (auto it : ans){
	cout << it << " ";
	}
	cout << endl;*/
	cout << ans.size() - 1 << endl;
}


// CFR182_div1.cpp : Defines the entry point for the console application.
//

#include <iostream>
#include <algorithm>
#include <map>
#include <vector>
#include <numeric>
#include <cassert>
#include <string>
#include <list>
#include <deque>

using namespace std;

// http://codeforces.com/problemset/problem/482/B

int Get(int n, int p, int x, int y, long long c, bool first, bool second)
{
	if (c > n) return 0;
	if (p == -1) return first && second;
	if (c <= n)
	{
		long long cn = n / pow((int)10, p + 1) * pow((int)10, p + 1);
		if (cn < n)
		{
			int res = (2 << (p + 1));
			if (!first) res--;
			if (!second) res--;
			return res;
		}
	}
	long long  c1 = c + x * pow((int)10, p);
	long long  c2 = c + y * pow((int)10, p);
	int res1 = Get(n, p - 1, x, y, c1, first | true, second);
	int res2 = Get(n, p - 1, x, y, c2, first, second | true);
	return res1 + res2;

}
//
int Get(int n, int p, int x)
{
	if (x == 0) return 0;
	long long  c = 0;
	for (int i = p; i >= 0; --i)
	{
		c += x * pow((int)10, i);
	}
	if (c > n) return 0;
	return 1;
}

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

	int res = 0;
	for (int p = 9; p >= 0; --p)
	{
		for (int x = 9; x >= 0; --x)
		{
			for (int y = x - 1; y >= 0; --y)
			{
				long long c1 = x * pow((int)10, p);
				long long  c2 = y * pow((int)10, p);
				res += Get(n, p - 1, x, y, c1, true, false);
				if (y != 0)
					res += Get(n, p - 1, x, y, c2, false, true);
			}
			res += Get(n, p, x);
		}
	}

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


#include <iostream>
using namespace std;

int main() {
    int a[4], s = 0;
    for(int i=0; i<4; i++){
        cin >> a[i];
        s+=a[i];
    }
    for(int i = 0; i<4; i++){
        int x = 0;
        for(int j = 0; j<4; j++){
            if(j==i) continue;
            x = max(x,a[i]);
        }
        if(x>s-x-a[i]) res = 2;
        else if(x==s-x-a[i]&&res<2) res = 1;
    }
    if(res==2) cout << "TRIANGLE";
    else if(res==1) cout << "SEGMENT";
    else cout << "IMPOSSIBLE";
}


#include<iostream>
using namespace std;
int main()
{
    int a[4];
    for(int i=0;i<4;i++){
        cin>>a[i];
    }
    sort(a,a+4);
    for(int i=0;i<2;i++){
        if(a[i]+a[i+1]>a[i+2]){
            return 0*printf("TRIANGLE");
        }
    }
    for(int i=0;i<2;i++){
        if(a[i]+a[i+1]==a[i+2]){
            return 0*printf("SEGMENT");
        }
    }
    return 0*printf("IMPOSSIBLE");
}


#include <bits/stdc++.h>

using namespace std;

string triangle(int *stick);

int main()
{
    int stick[4];
    for(int i = 0; i < 4; i++)
    {
        cin >> stick[i];
    }
    cout << triangle(stick) << endl;
    return 0;
}

string triangle(int *stick)
{
    string result = "IMPOSSIBLE";
    sort(stick.begin(), stick.end());
    while(i < 2)
    {
        int edge1 = stick[i];
        int edge2 = stick[i + 1];
        int edge3 = stick[i + 2];
        if(edge1 + edge2 > edge3)
        {
            result = "TRIANGLE";
            break;
        }
        else if(edge1 + edge2 == edge3)
        {
            result = "SEGMENT";
        }
    }
    return result;
}


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

int main()
{
    int a,b,c,d;
    cin>>a>>b>>c>>d;
   int num[4]={a,b,c,d};
   int n = sizeof(num)/sizeof(num[0]);

    sort(num, num+n);
     if(num[0]+num[1]>num[2]){cout<<"TRIANGLE";} else if(num[0]+num[1]>num[3]){cout<<"TRIANGLE";}
     else if(num[0]+num[2]>num[3]){cout<<"TRIANGLE";} else if(num[1]+num[2]>num[3]){cout<<"TRIANGLE";}
    else if(num[0]+num[1]==num[2]){cout<<"SEGMENT";} else if(num[0]+num[1]==num[3]){cout<<"SEGMENT";}
     else if(num[0]+num[2]==num[3]){cout<<"SEGMENT";} else if(num[1]+num[2]==num[3]){cout<<"SEGMENT";}
      else if(num[0]+num[1]<num[2]){cout<<"IMPOSSIBLE";} else if(num[0]+num[1]<num[3]){cout<<"IMPOSSIBLE";}
     else if(num[0]+num[2]<num[3]){cout<<"IMPOSSIBLE";} else if(num[1]+num[2]<num[3]){cout<<"IMPOSSIBLE";}
    return 0;
}


#include <bits/stdc++.h>

#define REP(I, N) for (int I = 0; I < (N); ++I)
#define REP0(I, A, B) for (auto I = (A); I < (B); ++I)
#define FOR(I, A, B) for (int I = (A); I <= (B); ++I)
#define FORD(I, A, B) for (int I = (A); I >= (B); --I)
#define MAX(A, B) (A = max(A, B))
#define MIN(A, B) (A = min(A, B))
#define SZ(C) ((int) C.size())
#define ALL(C) (C).begin(), (C).end()

using ll = long long;
const int INF = 1e9;
const int MOD = 1e9 + 7;

using namespace std;

const int N = 101;

int mod(int a) { return (a % MOD + MOD) % MOD; }
int mul(int a, int b) { return ((ll) a * b % MOD + MOD) % MOD; }
int add(int a, int b) { return ((a + b) % MOD + MOD) % MOD; }
int pow(int a, int b) {
  if (b == 0) return 1;
  if (b < 0) b += MOD - 1;
  int c = pow(a, b / 2);
  c = mul(c, c);
  if (b % 2 == 1) c = mul(c, a);
  return c;
}
int inv(int a) { return pow(a, -1); }

const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, -1, 0, 1};
int R, p[4];
vector<int> mat_[N][N][N];
int b_[N][N];

inline int &mat(int a, int b, int c, int d) {
  return mat_[a + R][b + R][c + R][d + R];
}

inline int &b(int a, int b) {
  return b_[a + R][b + R];
}

void row_reduce(int i0, int j0, int i1, int j1, const vector<pair<int, int> > &nz) {
  int times = mul(inv(mat(i0, j0, i0, j0)), -mat(i1, j1, i0, j0));
  b(i1, j1) = add(b(i1, j1), mul(times, b(i0, j0)));
  for (auto p : nz) {
    int i = p.first, j = p.second;
    mat(i1, j1, i, j) = add(mat(i1, j1, i, j), mul(times, mat(i0, j0, i, j)));
  }
}

void row_reduce(int i0, int j0, int i1, int j1) {
  vector<pair<int, int> > nz;
  FOR(i, -R, R) FOR(j, -R, R) if (mat(i0, j0, i, j) != 0) nz.push_back({i, j});
  row_reduce(i0, j0, i1, j1, nz);
}

void print_mat() {
  FOR(i, -R, R) FOR(j, -R, R) {
    FOR(ii, -R, R) FOR (jj, -R, R)
      cerr << (mat(i, j, ii, jj) != 0) << " ";
    // cerr << mat(i, j, ii, jj) << " ";
    cerr << b(i, j);
    cerr << endl;
  }
  cerr << "===" << endl;
}

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

  cin >> R;
  int s = 0;
  REP(i, 4) {
    cin >> p[i];
    s += p[i];
  }
  FOR(i, -R, R) FOR(j, -R, R) FOR(ii, -R, R)
    mat_[i + R][j + R][ii + R].resize(2 * R + 1, 0);
  int s_inv = inv(s);
  REP(i, 4) p[i] = mul(p[i], s_inv);
  // REP(i, 4) cerr << p[i] << " "; cerr << endl;

  FOR(i, -R, R) FOR(j, -R, R)
    if (i * i + j * j <= R * R) {
      REP(d, 4) {
        int ii = i + dx[d];
        int jj = j + dy[d];
        if (ii * ii + jj * jj <= R * R)
          mat(i, j, ii, jj) += p[d];
      }
      mat(i, j, i, j) = mod(-1);
      b(i, j) = mod(-1);
    }
  // cerr << "hi" << endl;

  // print_mat();
  FOR(i, -R, R) FOR(j, -R, R) {
    vector<pair<int, int> > nz;
    FOR(ii, -R, R) FOR(jj, -R, R)
      if (mat(i, j, ii, jj) != 0)
        nz.push_back({ii, jj});

    for (auto p : nz)
      if (p != make_pair(i, j))
        row_reduce(i, j, p.first, p.second, nz);

    // FOR(ii, -R, R) FOR (jj, -R, R)
    //   if (ii != i || jj != j)
    //     row_reduce(i, j, ii, jj);
    // print_mat();
  }

  // cerr << "ok" << endl;

  FOR(i, -R, R) FOR(j, -R, R)
    if (i != 0 || j != 0)
      row_reduce(i, j, 0, 0);

  int ans = mul(b(0, 0), inv(mat(0, 0, 0, 0)));
  cout << ans << endl;

  return 0;
}


#include<iostream>
#include<cstdio>
#include<cstring>
#define int long long
#define ll long long
#define mod 1000000007
#define N 210
const int U[5]={0,-1,0,1,0},
		  V[5]={0,0,-1,0,1};
using namespace std;
ll ksm(ll a,ll b)
{
	if(b==0) return 1;
	if(b==1) return a;
	ll q=ksm(a,b>>1);
	if(b&1) return q*q%mod*a%mod;
	else return q*q%mod;
}
int id[N][N];
#define ID(x,y) id[x+50][y+50]
struct matrix{
	ll num[N*40][N*40];
	ll answer(int n,int r)
	{
		int d=r*2;
		for(int i=1;i<=n;i++)
		{
			ll inv=ksm(num[i][i],mod-2);
			for(int j=i+1,p1=0;j<=n && p1<=d;j++,p1++)
			{
				ll res=inv*num[j][i]%mod;
				if(!res) continue;
				for(int k=i,p2=0;k<=n && p2<=d;k++,p2++) num[j][k]=(num[j][k]-num[i][k]*res%mod+mod)%mod;
				num[j][0]=(num[j][0]-num[i][0]*res%mod+mod)%mod;
			}
		}
		int p=ID(0,0);
		for(int i=n;i>=p;i--)
		{
			ll inv=ksm(num[i][i],mod-2);
			num[i][0]=num[i][0]*inv%mod;
			for(int j=i-1;j>=p;j--)
			num[j][0]=(num[j][0]-num[j][i]*num[i][0]%mod+mod)%mod;
		}
		return num[p][0];
	}
}o;
int r;
ll p[5];
bool dis(int x,int y,int r){return 1ll*x*x+1ll*y*y<=1ll*r*r;}
signed main()
{
	scanf("%lld%lld%lld%lld%lld",&r,&p[1],&p[2],&p[3],&p[4]);
	const ll inv=ksm((p[1]+p[2]+p[3]+p[4])%mod,mod-2);
	for(int i=1;i<=4;i++) p[i]=p[i]*inv%mod;
	int cnt=0;
	for(int i=r;i>=-r;i--)
		for(int j=-r;j<=r;j++)
		if(dis(i,j,r)) ID(i,j)=++cnt;
	for(int i=r;i>=-r;i--)
		for(int j=-r;j<=r;j++)
		if(ID(i,j))
		{
			for(int k=1;k<=4;k++)
			if(ID(i+U[k],j+V[k])) o.num[ID(i,j)][ID(i+U[k],j+V[k])]=p[k];
			o.num[ID(i,j)][0]=o.num[ID(i,j)][ID(i,j)]=-1;
		}
	printf("%lld",o.answer(cnt,r));
	return 0;
}


#include<iostream>
#include<cstdio>
#define MN 7900
#define mod 1000000007
using namespace std;
inline int read()
{
	int x=0,f=1;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	return x*f;
}
const int md = (int) 1e9 + 7;

inline void add(int &a, int b) {
  a += b;
  if (a >= md) a -= md;
}

inline void sub(int &a, int b) {
  a -= b;
  if (a < 0) a += md;
}

inline int mul(int a, int b) {
  return (int) ((long long) a * b % md);
}

inline int power(int a, long long b) { // a^b mod md
  int res = 1;
  while (b > 0) {
    if (b & 1) {
      res = mul(res, a);
    }
    a = mul(a, a);
    b >>= 1;
  }
  return res;
}

inline int inv(int a) { // multiplicative inverse of a mod md
  a %= md;
  if (a < 0) a += md;
  int b = md, u = 0, v = 1;
  while (a) {
    int t = b / a;
    b -= t * a; swap(a, b);
    u -= t * v; swap(u, v);
  }
  assert(b == 1);
  if (u < 0) u += md;
  return u;
}

inline int pow(int x,int k)
{
	int sum=1;
	for(;k;k>>=1,x=1LL*x*x%mod) if(k&1) sum=1LL*sum*x%mod;
	return sum;
}
int a[MN+5][MN+5],res[MN+5];
int R,a1,a2,a3,a4,cnt,id[105][105],ans;
inline int&ID(int x,int y){return id[x+R+1][y+R+1];}
void Gauss()
{
	for(int i=1;i<=cnt;++i)
	{
		for(int j=i;j<=cnt&&j<=i+100;++j) if(a[j][i])
		{
			if(j!=i)
			{
				for(int k=i;k<=cnt&&k<=i+100;++k) swap(a[i][k],a[j][k]);
				swap(a[i][cnt+1],a[j][cnt+1]);
			}
			break;
		}
		if(!a[i][i])continue;
		int Inv=inv(a[i][i]);
		for(int j=i+1;j<=cnt&&j<=i+100;++j) if(a[j][i])
		{
			int t = mul(a[j][i],Inv);
			for(int k=i;k<=cnt&&k<=i+100;++k)
				sub(a[j][k],mul(a[i][k],t));
			sub(a[j][cnt+1],mul(a[i][cnt+1],t));
		}
	}
	for(int i=cnt;i;--i)
	{
		int t=a[i][cnt+1];
		for(int j=i+1;j<=cnt&&j<=i+100;++j) t=(t-1LL*a[i][j]*res[j]%mod+mod)%mod;
		res[i]=1LL*t*pow(a[i][i],mod-2)%mod;
		//ans=(ans+res[i])%mod;
	}
	ans = res[ID(0,0)];
}
int main()
{
	R=read();a1=read();a2=read();a3=read();a4=read();int inv=pow(a1+a2+a3+a4,mod-2);
	for(int i=-R;i<=R;++i)for(int j=-R;j<=R;++j) if(i*i+j*j<=R*R) ID(i,j)=++cnt,a[cnt][cnt]=1;
	a[ID(0,0)][cnt+1]=1;
	for(int i=-R;i<=R;++i) for(int j=-R;j<=R;++j) if(i*i+j*j<=R*R)
	{
		if(ID(i-1,j)) a[ID(i-1,j)][ID(i,j)]=mod-1LL*a1*inv%mod;
		if(ID(i,j-1)) a[ID(i,j-1)][ID(i,j)]=mod-1LL*a2*inv%mod;
		if(ID(i+1,j)) a[ID(i+1,j)][ID(i,j)]=mod-1LL*a3*inv%mod;
		if(ID(i,j+1)) a[ID(i,j+1)][ID(i,j)]=mod-1LL*a4*inv%mod;
		a[ID(i,j)][cnt+1] = 1;
	}
	Gauss();cout<<ans;
	return 0;
}


#include <cstdio>
#include <vector>
#include <cassert>
#include <functional>
#include <algorithm>
#include <iostream>
#include <numeric>
#include <map>
#include <tuple>
#include <random>
#include <time.h>
#include <memory.h>

const int mod = 1000000007;

inline void fasterLLDivMod(unsigned long long x, unsigned y, unsigned &out_d, unsigned &out_m) {
	unsigned xh = (unsigned)(x >> 32), xl = (unsigned)x, d, m;
#ifdef __GNUC__
	asm(
		"divl %4; \n\t"
		: "=a" (d), "=d" (m)
		: "d" (xh), "a" (xl), "r" (y)
	);
#else
	__asm {
		mov edx, dword ptr[xh];
		mov eax, dword ptr[xl];
		div dword ptr[y];
		mov dword ptr[d], eax;
		mov dword ptr[m], edx;
	};
#endif
	out_d = d; out_m = m;
}

//x < 2^32 * MOD !
inline unsigned Mod(unsigned long long x){
	unsigned y = mod;
//	return x % y;
	unsigned dummy, r;
	fasterLLDivMod(x, y, dummy, r);
	return r;
}

// given first m items init[0..m-1] and coefficents trans[0..m-1] or
// given first 2 *m items init[0..2m-1], it will compute trans[0..m-1]
// for you. trans[0..m] should be given as that
//      init[m] = sum_{i=0}^{m-1} init[i] * trans[i]
struct LinearRecurrence {
  using int64 = long long;
  using vec = std::vector<int64>;

  static void extand(vec &a, size_t d, int64 value = 0) {
    if (d <= a.size()) return;
    a.resize(d, value);
  }
  static vec BerlekampMassey(const vec &s, int64 mod) {
    std::function<int64(int64)> inverse = [&](int64 a) {
      return a == 1 ? 1 : (int64)(mod - mod / a) * inverse(mod % a) % mod;
    };
    vec A = {1}, B = {1};
    int64 b = s[0];
    for (size_t i = 1, m = 1; i < s.size(); ++i, m++) {
      int64 d = 0;
      for (size_t j = 0; j < A.size(); ++j) {
        d += A[j] * s[i - j] % mod;
      }
      if (!(d %= mod)) continue;
      if (2 * (A.size() - 1) <= i) {
        auto temp = A;
        extand(A, B.size() + m);
        int64 coef = d * inverse(b) % mod;
        for (size_t j = 0; j < B.size(); ++j) {
          A[j + m] -= coef * B[j] % mod;
          if (A[j + m] < 0) A[j + m] += mod;
        }
        B = temp, b = d, m = 0;
      } else {
        extand(A, B.size() + m);
        int64 coef = d * inverse(b) % mod;
        for (size_t j = 0; j < B.size(); ++j) {
          A[j + m] -= coef * B[j] % mod;
          if (A[j + m] < 0) A[j + m] += mod;
        }
      }
    }
    return A;
  }
  static void exgcd(int64 a, int64 b, int64 &g, int64 &x, int64 &y) {
    if (!b) x = 1, y = 0, g = a;
    else {
      exgcd(b, a % b, g, y, x);
      y -= x * (a / b);
    }
  }
  static int64 crt(const vec &c, const vec &m) {
    int n = c.size();
    int64 M = 1, ans = 0;
    for (int i = 0; i < n; ++i) M *= m[i];
    for (int i = 0; i < n; ++i) {
      int64 x, y, g, tm = M / m[i];
      exgcd(tm, m[i], g, x, y);
      ans = (ans + tm * x * c[i] % M) % M;
    }
    return (ans + M) % M;
  }
  static vec ReedsSloane(const vec &s, int64 mod) {
    auto inverse = [] (int64 a, int64 m) {
      int64 d, x, y;
      exgcd(a, m, d, x, y);
      return d == 1 ? (x % m + m) % m : -1;
    };
    auto L = [] (const vec &a, const vec &b) {
      int da = (a.size() > 1 || (a.size() == 1 && a[0])) ? a.size() - 1 : -1000;
      int db = (b.size() > 1 || (b.size() == 1 && b[0])) ? b.size() - 1 : -1000;
      return std::max(da, db + 1);
    };
    auto prime_power = [&] (const vec &s, int64 mod, int64 p, int64 e) {
      // linear feedback shift register mod p^e, p is prime
      std::vector<vec> a(e), b(e), an(e), bn(e), ao(e), bo(e);
      vec t(e), u(e), r(e), to(e, 1), uo(e), pw(e + 1);;
      pw[0] = 1;
      for (int i = pw[0] = 1; i <= e; ++i) pw[i] = pw[i - 1] * p;
      for (int64 i = 0; i < e; ++i) {
        a[i] = {pw[i]}, an[i] = {pw[i]};
        b[i] = {0}, bn[i] = {s[0] * pw[i] % mod};
        t[i] = s[0] * pw[i] % mod;
        if (t[i] == 0) {
          t[i] = 1, u[i] = e;
        } else {
          for (u[i] = 0; t[i] % p == 0; t[i] /= p, ++u[i]);
        }
      }
      for (size_t k = 1; k < s.size(); ++k) {
        for (int g = 0; g < e; ++g) {
          if (L(an[g], bn[g]) > L(a[g], b[g])) {
            ao[g] = a[e - 1 - u[g]];
            bo[g] = b[e - 1 - u[g]];
            to[g] = t[e - 1 - u[g]];
            uo[g] = u[e - 1 - u[g]];
            r[g] = k - 1;
          }
        }
        a = an, b = bn;
        for (int o = 0; o < e; ++o) {
          int64 d = 0;
          for (size_t i = 0; i < a[o].size() && i <= k; ++i) {
            d = (d + a[o][i] * s[k - i]) % mod;
          }
          if (d == 0) {
            t[o] = 1, u[o] = e;
          } else {
            for (u[o] = 0, t[o] = d; t[o] % p == 0; t[o] /= p, ++u[o]);
            int g = e - 1 - u[o];
            if (L(a[g], b[g]) == 0) {
              extand(bn[o], k + 1);
              bn[o][k] = (bn[o][k] + d) % mod;
            } else {
              int64 coef = t[o] * inverse(to[g], mod) % mod * pw[u[o] - uo[g]] % mod;
              int m = k - r[g];
              extand(an[o], ao[g].size() + m);
              extand(bn[o], bo[g].size() + m);
              for (size_t i = 0; i < ao[g].size(); ++i) {
                an[o][i + m] -= coef * ao[g][i] % mod;
                if (an[o][i + m] < 0) an[o][i + m] += mod;
              }
              while (an[o].size() && an[o].back() == 0) an[o].pop_back();
              for (size_t i = 0; i < bo[g].size(); ++i) {
                bn[o][i + m] -= coef * bo[g][i] % mod;
                if (bn[o][i + m] < 0) bn[o][i + m] -= mod;
              }
              while (bn[o].size() && bn[o].back() == 0) bn[o].pop_back();
            }
          }
        }
      }
      return std::make_pair(an[0], bn[0]);
    };

    std::vector<std::tuple<int64, int64, int>> fac;
    for (int64 i = 2; i * i <= mod; ++i) if (mod % i == 0) {
      int64 cnt = 0, pw = 1;
      while (mod % i == 0) mod /= i, ++cnt, pw *= i;
      fac.emplace_back(pw, i, cnt);
    }
    if (mod > 1) fac.emplace_back(mod, mod, 1);
    std::vector<vec> as;
    size_t n = 0;
    for (auto &&x: fac) {
      int64 mod, p, e;
      vec a, b;
      std::tie(mod, p, e) = x;
      auto ss = s;
      for (auto &&x: ss) x %= mod;
      std::tie(a, b) = prime_power(ss, mod, p, e);
      as.emplace_back(a);
      n = std::max(n, a.size());
    }
    vec a(n), c(as.size()), m(as.size());
    for (size_t i = 0; i < n; ++i) {
      for (size_t j = 0; j < as.size(); ++j) {
        m[j] = std::get<0>(fac[j]);
        c[j] = i < as[j].size() ? as[j][i] : 0;
      }
      a[i] = crt(c, m);
    }
    return a;
  }

  LinearRecurrence(const vec &s, const vec &c, int64 mod):
    init(s), trans(c), mod(mod), m(s.size()) {}
  LinearRecurrence(const vec &s, int64 mod, bool is_prime = true): mod(mod) {
    vec A;
    if (is_prime) A = BerlekampMassey(s, mod);
    else A = ReedsSloane(s, mod);
    if (A.empty()) A = {0};
    m = A.size() - 1;
    trans.resize(m);
    for (int i = 0; i < m; ++i) {
      trans[i] = (mod - A[i + 1]) % mod;
    }
    std::reverse(trans.begin(), trans.end());
    init = {s.begin(), s.begin() + m};
  }
  int64 calc(int64 n) {
    if (mod == 1) return 0;
    if (n < m) return init[n];
    vec v(m), u(m << 1);
    int msk = !!n;
    for (int64 m = n; m > 1; m >>= 1) msk <<= 1;
    v[0] = 1 % mod;
    for (int x = 0; msk; msk >>= 1, x <<= 1) {
      std::fill_n(u.begin(), m * 2, 0);
      x |= !!(n & msk);
      if (x < m) u[x] = 1 % mod;
      else {// can be optimized by fft/ntt
        for (int i = 0; i < m; ++i) {
          for (int j = 0, t = i + (x & 1); j < m; ++j, ++t) {
            u[t] = (u[t] + v[i] * v[j]) % mod;
          }
        }
        for (int i = m * 2 - 1; i >= m; --i) {
          for (int j = 0, t = i - m; j < m; ++j, ++t) {
            u[t] = (u[t] + trans[j] * u[i]) % mod;
          }
        }
      }
      v = {u.begin(), u.begin() + m};
    }
    int64 ret = 0;
    for (int i = 0; i < m; ++i) {
      ret = (ret + v[i] * init[i]) % mod;
    }
    return ret;
  }

  vec init, trans;
  int64 mod;
  int m;
};

int mod_inverse(int i) {
  if(i == 1) return 1;
  return (long long)mod_inverse(mod % i) * (long long)(mod - mod / i) % mod;
}

int r, a[4];
int p[4];

int id;

std::map<int, std::map<int, int>> m;

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

std::mt19937 rng;

std::uniform_int_distribution<int> gen(1, mod - 1);

int main() {
#ifdef IN_MY_COMPUTER
  freopen("e.in", "r", stdin);
#endif

  std::cin >> r;
  for(int i = 0; i < 4; i++) {
    std::cin >> a[i];
  }

  if(r == 0) {
    puts("1");
    return 0;
  }

  long long inv_a = mod_inverse(std::accumulate(a, a+4, 0));
  for(int i = 0; i < 4; i++) {
    p[i] = a[i] * inv_a % mod;
  }

  for(int x = -r-1; x <= r+1; x++) {
    for(int y = -r-1; y <= r+1; y++) {
      if(x * x + y * y <= r * r) {
        m[x][y] = id++;
      }else {
        m[x][y] = -1;
      }
    }
  }

  struct ele { int i, j, v; };
  std::vector<ele> coef;

  for(int x = -r; x <= r; x++) {
    for(int y = -r; y <= r; y++) if(m[x][y] >= 0) {
      //coef.push_back({m[x][y], m[x][y], 1});
      for(int t = 0; t < 4; t++) {
        int xx = x+dx[t], yy = y+dy[t];
        if(m[xx][yy] >= 0) {
          coef.push_back({m[x][y], m[xx][yy], mod-p[t]});
        }
      }
    }
  }
  printf("id=%d |coef|=%ld\n", id,coef.size());

  // A * x = (1, 0, 0, 0, 0, ..., 0)

  static int v1[8000], v2[8000];
  for(int i = 0; i < id; i++) {
    v1[i] = (gen(rng));
    v2[i] = (gen(rng));
  }

  std::vector<long long> seq;
  static int now[8000];
  for(int i = 0; i < id; i++) now[i] = v1[i];

  for(int rr = 0; rr < id * 2 + 5; rr++) {
    seq.push_back(v1[m[0][0]]); // 50 1 2 3 4 -> 316668178
    for(auto &it : coef) {
      now[it.i] = (now[it.i] + (long long)v1[it.j] * it.v) % mod;
    }
    memcpy(v1, now, sizeof(int) * id);
  }
  printf("after rr go %lf\n", (double)clock()/CLOCKS_PER_SEC);

  static int b[8000], ret[8000];

  LinearRecurrence lin(seq, mod, true);

  lin.trans.push_back(mod-1);
  for(int n = 1; n <= 1000; n++) {
    //printf("%lld, ", lin.calc(n));
    if(lin.calc(n) == 489905673) {
      printf("n = %lld\n", n);
    }
  }
  puts("");
  printf("lin.size() = %ld\n", lin.trans.size());
  printf("after linrec %lf\n", (double)clock() / CLOCKS_PER_SEC);

  std::vector<long long> inv_coef(lin.trans.begin() + 1, lin.trans.end());
  long long all_mul = mod_inverse(mod - lin.trans[0]);

  int pos = m[0][0], ans = 0;

  for(int i = 0; i < id; i++) now[i] = b[i] = 1;
  for(long long v : inv_coef) {
    (v *= all_mul) %= mod;
    (ans += b[pos] * v) % mod;
    for(auto &it : coef) {
      (now[it.i] += (long long)b[it.j] * it.v)) %= mod;
    }
    memcpy(b, now, sizeof(int) * id);
  }

  printf("total %lf\n", (double)clock() / CLOCKS_PER_SEC);
  printf("%d\n", ans);

  return 0;
}


#error
/*
 * Remark:
 * Took only total ~= 40 mins to implement.
 * However initially I misunderstood the problem statement and thought that
 * the probability of reaching each possible vertex is equal for each distance.
 * Took another 40 minutes to "debug" that. Too bad.
 * Ignores the time required to prove that the algorithm is O(n^3) (a few days?)
 */

#ifndef LOCAL
#define NDEBUG
#endif
#include<iomanip>
#include<cassert>
#include<iostream>
#include<algorithm>
#include<climits>
#include<vector>

int main(){
	std::ios::sync_with_stdio(0);std::cin.tie(0);
	int n,m;std::cin>>n>>m;

	std::vector<std::vector<int>> d(n,std::vector<int>(n,INT_MAX/2));
	std::vector<std::vector<int>> ad(n);

	for(int z=m;z--;){
		int u,v;std::cin>>u>>v;--u;--v;
		ad[u].push_back(v);
		ad[v].push_back(u);
		d[u][v]=d[v][u]=1;
	}

	for(int i=n;i--;)
		d[i][i]=0;
	for(int k=n;k--;)
	for(int i=n;i--;)
	for(int j=n;j--;)
		d[i][j]=std::min(d[i][j],d[i][k]+d[k][j]);

	std::vector<std::vector<std::vector<int>>> byd(n); // byd[i][dist] = {x: d[i][x] == dist}
	for(int i=n;i--;){
		auto& bydi=byd[i];
		bydi.resize(1+*std::max_element(begin(d[i]),end(d[i])));
		for(int j=n;j--;)
			bydi[d[i][j]].push_back(j);
	}

	std::vector<double> mark;
	std::vector<char> distseen(n);
	std::vector<std::pair<double,int>> markvals; // {val,ind}
	markvals.reserve(n);

	double ans=0;
	for(int x=n;x--;){ // first chosen vertex
		double cur=0;
		for(unsigned dx=0;dx<byd[x].size();++dx){ // reported distance
			int const ci=(int)byd[x][dx].size();
			assert(ci>0);
			double zz=1./ci;

			if(ci>1){
				mark.assign(n,0);
				for(int j:byd[x][dx]){
					for(int k:ad[j]) // surprisingly the time complexity is only O(n^3)
						mark[k]+=1/(double)ad[j].size();
				}
				// mark[k] / ci = probability for Limak to travel to k

				markvals.clear();
				for(int j=n;j--;){
					if(mark[j])
						markvals.push_back({mark[j],j});
					std::sort(begin(markvals),end(markvals),[](auto a,auto b){return a.first>b.first;});
				}

				double max_smprob=0;
				for(int z=n;z--;){
					double smprob=0; // sum of max probability * ci
					for(auto [prob,j]:markvals)
						if(!distseen[d[z][j]]){
							distseen[d[z][j]]=true;
							smprob+=prob;
						}

					max_smprob=std::max(max_smprob,smprob);

					for(auto [prob,j]:markvals)
						distseen[d[z][j]]=false;
				}

				zz=std::max(zz,max_smprob/(double)ci);
			}

			cur+=zz*ci/n;
		}
		ans=std::max(ans,cur);
	}
	std::cout<<std::setprecision(12)<<std::fixed<<ans<<'\n';
}


#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>

using namespace std;

const int maxn = 400 + 10;
const double eps = 1e-10;

int dist[maxn][maxn];
int vis[maxn];
double po[maxn];
double maxpo[maxn];
int n, m;
int vec[maxn], vecn;
vector<int> G[maxn];

double solve(int p1, int d1) {
    vector<int> point;
    /*double num = 0;
    for(int i = 1; i <= n; i++) {
        if(dist[i][p1] == d1) {
            num++;
        }
    }*/
    memset(po, 0, sizeof(po));
    memset(vis, 0, sizeof(vis));
    memset(maxpo, 0, sizeof(maxpo));
    for(int i = 1; i <= n; i++) {
        if(dist[i][p1] == d1) {
            for(int j = 0; j < G[i].size(); j++) {
                int v = G[i][j];
                po[v] += 1.0 / n / (double)G[i].size();
                if(vis[v] == 0) {
                    vis[v] = 1;
                    point.push_back(v);
                }
            }
        }
    }
    double ans = 0;
    for(int p2 = 1; p2 <= n; p2++) {
        double t = 0;
        vecn = 0;
        for(int i = 0; i < point.size(); i++) {
            int v = point[i], d = dist[p2][v];
            if(maxpo[d] < eps) {
                vec[vecn] = d;
                vecn++;
            }
            maxpo[d] = max(maxpo[d], po[v]);
        }
        for(int i = 0; i < point.size(); i++) {
            int v = point[i], d = dist[p2][v];
            t += maxpo[d];
            maxpo[d] = 0;
        }
        for(int i = 0; i < vecn; i++) {
            maxpo[vec[i]] = 0;
        }
        ans = max(ans, t);
    }
    return ans;
}

int main() {
    //freopen("D.txt", "r", stdin);
    while(scanf("%d%d", &n, &m) != EOF) {
        for(int i = 1; i <= n; i++) G[i].clear();
        for(int i = 1; i <= n; i++) {
            for(int j = 1; j <= n; j++) {
                if(i == j) {
                    dist[i][j] = 0;
                } else {
                    dist[i][j] = n + 1;
                }
            }
        }
        for(int i = 1; i <= m; i++) {
            int a, b;
            scanf("%d%d", &a, &b);
            dist[a][b] = dist[b][a] = 1;
            G[a].push_back(b);
            G[b].push_back(a);
        }
        for(int k = 1; k <= n; k++) {
            for(int i = 1; i <= n; i++) {
                for(int j = 1; j <= n; j++) {
                    dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
                }
            }
        }
        double ans = 0;
        for(int p1 = 1; p1 <= n; p1++) {
            double t = 0;
            for(int d1 = 0;d1 <= n; d1++) {
                int flag = 0;
                for(int i = 1; i <= n; i++) {
                    if(dist[i][p1] == d1) {
                        flag = 1;
                        break;
                    }
                }
                if(flag == 0) continue;
                double tmp = 1.0 / n;
                tmp = max(tmp, solve(p1, d1));
                t += tmp;
            }
            ans = max(ans, t);
        }
        printf("%.10f\n", ans);
    }
    return 0;
}


#include<cstdio>
#include<cstring>
#include<algorithm>
#define ll int
#define N 405
#define M 80005
#define eps (1e-6)
#define rep(i,j,k) for (ll i=j;i<=k;++i)
#define per(i,j,k) for (ll i=j;i>=k;--i)
using namespace std;
inline ll read(){
	char ch=getchar(); ll x=0,f=1;
	while (ch<'0'||ch>'9') { if (ch=='-') f=-1; ch=getchar(); }
	while (ch>='0'&&ch<='9') { x=x*10+ch-'0'; ch=getchar(); }
	return x*f;
}
ll n,m,tot,a[N],f[N][N],head[N],size[N];
double p[N],dis[N],ans=0;
struct edge{ ll to,next; }e[M];
void add(ll u,ll v){
	e[++tot]=(edge){v,head[u]}; head[u]=tot; ++size[u];
}
double calc(ll x,ll d1){
	rep(i,1,n) p[i]=0;
	double ans=0; ll cnt=0;
	rep(i,1,n) if (f[x][i]==d1){
		for (ll j=head[i],v=e[j].to;j;j=e[j].next,v=e[j].to)
			p[v]+=1.0/n/size[i];
	}
	rep(i,1,n) if (p[i]>eps) a[++cnt]=i;
	rep(i,1,n){
		double tmp=0;
		rep(j,1,cnt) dis[f[i][a[j]]]=max(dis[f[i][a[j]]],p[a[j]]);
		rep(j,1,cnt) tmp+=dis[f[i][a[j]]],dis[f[i][a[j]]]=0;
		ans=max(ans,tmp);
	}
	return ans;
}
int main(){
	n=read(); m=read(); ans=1.0/n;
	rep(i,1,n) rep(j,1,n) if (i!=j) f[i][j]=n+1;
	rep(i,1,m){
		ll u=read(),v=read();
		add(u,v); add(v,u);
		f[u][v]=f[v][u]=1;
	}
	rep(k,1,n) rep(i,1,n) rep(j,1,n)
		f[i][j]=min(f[i][j],f[i][k]+f[k][j]);
	rep(i,1,n){
		double tmp=0;
		rep(d1,0,n-1){
			ll cnt=0;
			rep(j,1,n) if (f[i][j]==d1) ++cnt;
			if (!cnt) continue;
			double day2=calc(i,d1);
			tmp+=max(day1,day2);
		}
		ans=max(ans,tmp);
	}
	printf("%.12f",ans);
}


#include <cstdio>
#include <vector>
static const int INF = 0x3fffffff;
static const int MAXN = 418;    // I'm a teapot =u=
typedef std::vector<int> edgelist;

template <typename T> inline T min(const T a, const T b) {
    return a < b ? a : b;
}
template <typename T> inline T max(const T a, const T b) {
    return a > b ? a : b;
}

int n, m;
edgelist e[MAXN];
int d[MAXN][MAXN];

int main()
{
    scanf("%d%d", &n, &m);
    for (int i = 0; i < n; ++i)
        for (int j = 0; j < n; ++j)
            d[i][j] = (i == j ? 0 : INF);

    int u, v;
    for (int i = 0; i < m; ++i) {
        scanf("%d%d", &u, &v); --u; --v;
        e[u].push_back(v);
        e[v].push_back(u);
        d[u][v] = d[v][u] = 1;
    }
    for (int k = 0; k < n; ++k)
        for (int i = 0; i < n; ++i)
            for (int j = 0; j < n; ++j)
                d[i][j] = min(d[i][j], d[i][k] + d[k][j]);

    double ans = 0.0;
    for (int g1 = 0; g1 < n; ++g1) {
        double cur = 0.0;
        for (int d1 = 0; d1 < n; ++d1) {
            int valid_ct = 0;
            for (int i = 0; i < n; ++i)
                if (d[g1][i] == d1) ++valid_ct;
            if (valid_ct == 0) continue;

            double nextday = 0.0;
            std::vector<int> omoshiroi;
            static double prob[MAXN], prob_in_dist[MAXN];
            memset(prob, 0, sizeof prob);
            //memset(prob_in_dist, 0, sizeof prob_in_dist);
            for (int u = 0; u < n; ++u) if (d[g1][u] == d1)
                for (edgelist::iterator v = e[u].begin(); v != e[u].end(); ++v) {
                    if (prob[*v] == 0) omoshiroi.push_back(*v);
                    prob[*v] += 1.0 / valid_ct / e[u].size();
                }
            for (int g2 = 0; g2 < n; ++g2) {
                double cur = 0.0;
                for (std::vector<int>::iterator i = omoshiroi.begin(); i != omoshiroi.end(); ++i)
                    prob_in_dist[d[g2][*i]] = max(prob_in_dist[d[g2][*i]], prob[*i]);
                for (std::vector<int>::iterator i = omoshiroi.begin(); i != omoshiroi.end(); ++i) {
                    cur += prob_in_dist[d[g2][*i]];
                    prob_in_dist[d[g2][*i]] = 0.0;
                }
                nextday = max(nextday, cur);
            }

            // http://codeforces.com/blog/entry/45310#comment-298820
            cur += max(1.0 / valid_ct, nextday) * valid_ct / n;
        }
        ans = max(ans, cur);
    }

    printf("%.12lf\n", ans);
    return 0;
}


#include <iostream>
#include <cstdio>
#include <algorithm>

using namespace std;
long long f[52][52][102];
int path[52][52][102][2];

struct node{
	long long a , b , c;
	bool operator < (const node & p) const
	{
		return c < p.c;
	}
};
node r[52];

void print(int n , int j , long long x)
{
	if(path[n][j][x][0] != j)
	{
		int u = path[n][j][x][0];
		long long v = path[n][j][x][1];
		print(n - 1 , u , v);
	}
	cout << j + 1 << " " << x + r[j].a << endl;
}

int main()
{
	//freopen("data.in" , "r" ,stdin);
	int n , m , k;
	cin >> n  >> m >> k;
	for(int i = 0 ; i < m ;i++)
	{
		cin >> r[i].a >>r[i].b >> r[i].c;
	}
	sort(r , r + n);
	int last_j = 0;
	long long last_x = 0;
	long long Max = 0;
	memset(f , 0 ,sizeof(f));
	for(int i = 0 ; i < n ;i++)
	{
		for(int j = i ; j < m ;j++)
		{
			long long u = r[j].b - r[j].a;
			for(int x = 0 ; x <= u ; x++)
			{
				long long ans = 0;

				if(i == 0)
				{
					f[i][j][x] = x + r[j].a;
					path[i][j][x][0] = j;
					path[i][j][x][1] = u + r[j].a;
					continue;
				}
				long long v = x + r[j].a;

				for(int p = i - 1 ; p < j ; p++)
				{
					if(v % k == 0 && v / k >= r[p].a && v / k <= r[p].b)
					{
						if(ans < f[i - 1][p][v / k - r[p].a] + v)
						{
							ans = f[i - 1][p][v / k - r[p].a] + v;
							path[i][j][x][0] = p;
							path[i][j][x][1] = v / k - r[p].a;
						}

					}
					if(v - k >= r[p].a && v - k <= r[p].b)
					{
						if(ans < f[i - 1][p][v - k - r[p].a] + v)
						{
							ans  = f[i - 1][p][v - k - r[p].a] + v;
							path[i][j][x][0] = p;
							path[i][j][x][1] = v - k - r[p].a;
						}

					}
				}
				f[i][j][x] = ans;
				if(i == n - 1)
				{
					if(Max < f[i][j][x])
					{
						Max = f[i][j][x];
						last_j = j;
						last_x = x;
					}
				}
			}
		}
	}
	if(Max > 0)
	{
		cout << "YES" << endl;
		print(n - 1 , last_j , last_x);
	}
	else
	{
		cout << "NO" << endl;
	}
//	while(1);
	return 0;
}


#pragma comment(linker, "/STACK:16777216")

#include <stdio.h>
#include <stdlib.h>
#include <memory.h>
#include <string.h>
#include <math.h>
#include <time.h>
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <unordered_map>
using namespace std;

#define FOR(i, n) for (int i = 0; i < (int) (n); i++)
#define RFOR(i, n) for (int i = (int) (n) - 1; i >= 0; i--)
#define CL(x, v) memset(x, v, sizeof(x))
#define ALL(x) x.begin(), x.end()
#define PB push_back
#define MP make_pair

typedef long long LL;
typedef vector<int> VI;
typedef vector<string> VS;
typedef pair<int, int> PII;

const int N = 50 + 5;
const int M = 100 + 5;

int ttc = 0;
char tt[N * N * M];

int n, m, k;
LL a[N], b[N];
int c[N];

struct T
{
    int n, c;
    LL x;

    T()
    {
        n = c = x = 0;
    }

    T(int _n, int _c, LL _x)
    {
        n = _n;
        c = _c;
        x = _x;
    }

    void * operator new (size_t size)
    {
        void * res = (void *) (tt + ttc);
        ttc += sizeof(T);
        return res;
    }
};

bool operator < (T a, T b)
{
    if (a.n != b.n) return a.n < b.n;
    if (a.c != b.c) return a.c < b.c;
    return a.x < b.x;
}

size_t H(const T & t)
{
    return t.n * 13 + t.c * 17 + t.x * 37;
}

unordered_map<T, bool, H> vs;
unordered_map<T, LL, H> dp;
unordered_map<T, int, H> pr1;
unordered_map<T, LL, H> pr2;

LL D(T t)
{
    if (t.n == n) return 0;

    bool & vis = vs[t];
    LL & res = dp[t];
    int & pre1 = pr1[t];
    LL & pre2 = pr2[t];

    if (vis) return res;

    vis = 1;
    res = -1;

    FOR(i, m) if (c[i] > t.c)
        if (!t.n)
        {
            for (LL x = a[i]; x <= b[i]; x++)
            {
                T f(t.n + 1, c[i], x);
                LL cur = D(f);
                if (cur != -1)
                {
                    cur += x;
                    if (cur > res)
                    {
                        res = cur;
                        pre1 = i;
                        pre2 = x;
                    }
                }
            }
        }
        else
        {
            if (a[i] <= t.x + k && t.x + k <= b[i])
            {
                T f(t.n + 1, c[i], t.x + k);
                LL cur = D(f);
                if (cur != -1)
                {
                    cur += t.x + k;
                    if (cur > res)
                    {
                        res = cur;
                        pre1 = i;
                        pre2 = t.x + k;
                    }
                }
            }

            if (a[i] <= t.x * k && t.x * k <= b[i])
            {
                T f(t.n + 1, c[i], t.x * k);
                LL cur = D(f);
                if (cur != -1)
                {
                    cur += t.x * k;
                    if (cur > res)
                    {
                        res = cur;
                        pre1 = i;
                        pre2 = t.x * k;
                    }
                }
            }
        }

    return res;
}

int main()
{
#ifdef LOCAL_BUILD
    freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
#endif

    scanf("%d %d %d", &n, &m, &k);
    FOR(i, m) scanf("%I64d %I64d %d", &a[i], &b[i], &c[i]);

    T t(0, 0, 0);
    LL x = D(t);
    if (x != -1)
    {
        printf("YES\n");
        while (t.n < n)
        {
            printf("%d %I64d\n", pr1[t] + 1, pr2[t]);
            t = T(t.n + 1, c[pr1[t]], pr2[t]);
        }
    }
    else
        printf("NO\n");

    return 0;
}