/**
 * Created with IntelliJ IDEA.
 * User: Zakhar_Voit
 * Date: 21.04.12
 * Time: 1:48
 */

import java.io.*;
import java.util.*;

import static java.lang.System.exit;

public class C {

    class Pair implements Comparable<Pair> {
        long u;
        long v;

        public Pair(long u, long v) {
            this.u = u;
            this.v = v;
        }

        public int hashCode() {
            int hu = (int) (u ^ (u >>> 32));
            int hv = (int) (v ^ (v >>> 32));
            return (int) (hu * 31 + hv);
        }

        public boolean equals(Object o) {
            Pair other = (Pair) o;
            return u == other.u && v == other.v;
        }

        public int compareTo(Pair other) {
            if (u != other.u)
                return u < other.u ? -1 : 1;

            return v < other.v ? -1 : v > other.v ? 1 : 0;
        }

        public String toString() {
            return "[u=" + u + ", v=" + v + "]";
        }

    }

    BufferedReader in;
    PrintWriter out;
    StringTokenizer st = new StringTokenizer("");

    public void openIO() throws IOException {
        if (new File("input.txt").exists()) {
            System.setIn(new FileInputStream("input.txt"));
            out = new PrintWriter(new BufferedWriter(new FileWriter("output.txt")));
        } else {
            out = new PrintWriter(System.out);
        }
        in = new BufferedReader(new InputStreamReader(System.in));
    }

    String nextToken() throws IOException {
        while (!st.hasMoreTokens())
            st = new StringTokenizer(in.readLine());
        return st.nextToken();
    }

    int nextInt() throws IOException {
        return Integer.parseInt(nextToken());
    }

    long nextLong() throws IOException {
        return Long.parseLong(nextToken());
    }

    double nextDouble() throws IOException {
        return Double.parseDouble(nextToken());
    }

    String nextLine() throws IOException {
        st = new StringTokenizer("");
        return in.readLine();
    }

    boolean EOF() throws IOException {
        while (!st.hasMoreTokens()) {
            String s = in.readLine();
            if (s == null)
                return true;
            st = new StringTokenizer(s);
        }
        return false;
    }

    int n, m, k, ans = 0;
    int[][] a, b, c, p;
    int number[][];

    static void swap(int[] a, int i, int j) {
        int t = a[j];
        a[j] = a[i];
        a[i] = t;
    }

    void init() {

    }

    void read() throws IOException {
        n = nextInt();
        m = nextInt();
        k = nextInt();
        a = new int[n][m];
        b = new int[n][m];
        c = new int[n][m];
        number = new int[n][m];
        p = new int[n][m];
        for (int i = 0; i < n; i++) {
            nextLine();
            for (int j = 0; j < m; j++) {
                a[i][j] = nextInt();
                b[i][j] = nextInt();
                c[i][j] = nextInt();
            }
        }
    }

    void solve() {
        for (int i = 0; i < n; i++) {
            for (int j = i + 1; j < n; j++) {
                int[] diff = new int[m], cnt = c[i];
                for (int k = 0; k < m; k++) {
                    diff[k] = b[j][k] - a[i][k];
                }
                for (int t = 0; t < m; t++) {
                    for (int c = 0; c + 1< m; c++) {
                        if (diff[c] < diff[c + 1]) {
                            swap(diff, c, c + 1);
                            swap(cnt, c, c + 1);
                        }
                    }
                }
                int cur = 0, profit = 0, idx = 0;
                while (cur < k && idx < m) {
                    int lastcur = cur;
                    cur += Math.min(k - lastcur, c[i][idx]);
                    profit += Math.min(k - lastcur, c[i][idx]) * diff[idx];
                    idx++;
                }
                p[j][i] = p[i][j] = Math.max(p[j][i], profit);
            }
        }
    }

    void write() {
        for (int i = 0; i < n; i++) {
            int mx = 0;
            for (int j = 0; j < n; j++) {
                mx = Math.max(mx, p[i][j]);
            }
            ans = Math.max(mx, ans);
        }
        out.println(ans);
    }

    public void run() throws IOException {
        openIO();
        init();
        read();
        solve();
        write();
        out.close();
    }

    static public void main(String[] args) throws IOException {
        new Thread(null, new Runnable() {
            public void run() {
                try {
                    new C().run();
                } catch (Throwable e) {
                    e.printStackTrace();
                    exit(999);
                }
            }
        }, "1", 1 << 23).start();
    }
}


/**
 * Created with IntelliJ IDEA.
 * User: Zakhar_Voit
 * Date: 21.04.12
 * Time: 1:48
 */

import java.io.*;
import java.util.*;

import static java.lang.System.exit;

public class C {

    class Pair implements Comparable<Pair> {
        long u;
        long v;

        public Pair(long u, long v) {
            this.u = u;
            this.v = v;
        }

        public int hashCode() {
            int hu = (int) (u ^ (u >>> 32));
            int hv = (int) (v ^ (v >>> 32));
            return (int) (hu * 31 + hv);
        }

        public boolean equals(Object o) {
            Pair other = (Pair) o;
            return u == other.u && v == other.v;
        }

        public int compareTo(Pair other) {
            if (u != other.u)
                return u < other.u ? -1 : 1;

            return v < other.v ? -1 : v > other.v ? 1 : 0;
        }

        public String toString() {
            return "[u=" + u + ", v=" + v + "]";
        }

    }

    BufferedReader in;
    PrintWriter out;
    StringTokenizer st = new StringTokenizer("");

    public void openIO() throws IOException {
        if (new File("input.txt").exists()) {
            System.setIn(new FileInputStream("input.txt"));
            out = new PrintWriter(new BufferedWriter(new FileWriter("output.txt")));
        } else {
            out = new PrintWriter(System.out);
        }
        in = new BufferedReader(new InputStreamReader(System.in));
    }

    String nextToken() throws IOException {
        while (!st.hasMoreTokens())
            st = new StringTokenizer(in.readLine());
        return st.nextToken();
    }

    int nextInt() throws IOException {
        return Integer.parseInt(nextToken());
    }

    long nextLong() throws IOException {
        return Long.parseLong(nextToken());
    }

    double nextDouble() throws IOException {
        return Double.parseDouble(nextToken());
    }

    String nextLine() throws IOException {
        st = new StringTokenizer("");
        return in.readLine();
    }

    boolean EOF() throws IOException {
        while (!st.hasMoreTokens()) {
            String s = in.readLine();
            if (s == null)
                return true;
            st = new StringTokenizer(s);
        }
        return false;
    }

    int n, m, k, ans = 0;
    int[][] a, b, c;

    static void swap(int[] a, int i, int j) {
        int t = a[j];
        a[j] = a[i];
        a[i] = t;
    }

    void init() {

    }

    void read() throws IOException {
        n = nextInt();
        m = nextInt();
        k = nextInt();
        a = new int[n][m];
        b = new int[n][m];
        c = new int[n][m];
        for (int i = 0; i < n; i++) {
            nextLine();
            for (int j = 0; j < m; j++) {
                a[i][j] = nextInt();
                b[i][j] = nextInt();
                c[i][j] = nextInt();
            }
        }
    }

    void solve() {
        for (int i = 0; i < n; i++) {
            for (int j = i + 1; j < n; j++) {
                int[] diff = new int[m], cnt = new int[m];
                for (int k = 0; k < m; k++) cnt[k] = c[i][k];
                for (int k = 0; k < m; k++) {
                    diff[k] = Math.max(0, b[j][k] - a[i][k]);
                }
                for (int t = 0; t < m; t++) {
                    for (int c = 0; c + 1< m; c++) {
                        if (diff[c] < diff[c + 1]) {
                            swap(diff, c, c + 1);
                            swap(cnt, c, c + 1);
                        }
                    }
                }
                int cur = 0, profit = 0, idx = 0;
                while (cur < k && idx < m) {
                    int lastcur = cur;
                    cur += Math.min(k - lastcur, cnt[idx]);
                    profit += Math.min(k - lastcur, cnt[idx]) * diff[idx];
                    idx++;
                }
                ans = Math.max(ans, profit);
            }
        }
    }

    void write() {
        out.println(ans);
    }

    public void run() throws IOException {
        openIO();
        init();
        read();
        solve();
        write();
        out.close();
    }

    static public void main(String[] args) throws IOException {
        new Thread(null, new Runnable() {
            public void run() {
                try {
                    new C().run();
                } catch (Throwable e) {
                    e.printStackTrace();
                    exit(999);
                }
            }
        }, "1", 1 << 23).start();
    }
}


import java.util.Scanner;
public class Ishu
{
    public static void main(String[] args)
    {
        Scanner scan=new Scanner(System.in);
        int a,b,lcm,d=0,m=0,i,hcf;
        a=scan.nextInt();
        b=scan.nextInt();
        lcm=a*b;
        for(i=a<b?a:b;i>0;--i)
            if(a%i==0&&b%i==0)
                {
                 hcf=i;
                 break;
                }
        lcm/=hcf;
        d=lcm/a;
        m=lcm/b;
        if(a<b)
            --d;
        else
            --m;
        if(m>d)
            System.out.println("Masha");
        else if(m<d)
            System.out.println("Dasha");
        else
            System.out.println("Equal");
    }
}


import java.util.Scanner;
public class Ishu
{
    public static void main(String[] args)
    {
        Scanner scan=new Scanner(System.in);
        int a,b,lcm,d=0,m=0,i,hcf;
        a=scan.nextInt();
        b=scan.nextInt();
        lcm=a*b;
        for(i=a<b?a:b;i>0;--i)
            if(a%i==0&&b%i==0)
                {
                 hcf=i;
                 break;
                }
        lcm/=hcf;
        for(i=1;i<lcm;++i)
            {
             if(i%a==0)
                ++d;
             else if(i%b==0)
                ++m;
            }
        if(a<b)
            ++m;
        else
            ++d;
        if(m>d)
            System.out.println("Masha");
        else if(m<d)
            System.out.println("Dasha");
        else
            System.out.println("Equal");
    }
}


import static java.lang.Math.*;
import java.util.*;
import java.io.*;

public class C {

    boolean showDebug = true;

    public void solve() throws Exception {

        int a=nextInt(), b=nextInt();
        long aa=a/gcd(a,b)l long bb=b/gcd(a,b);
        boolean rev=false;
        long max = lcm(a,b);

        if (a>b) {
            a^=b; b^=a; a^=b; rev=true;
        }

        long m = ((long)(a+1)*a)/2;
        if (m==max-m) {println("Equal"); return;}
        if (m>max-m)
            println(rev?"Dasha":"Masha");
        else
            println(rev?"Masha":"Dasha");

    }

    ////////////////////////////////////////////////////////////////////////////

    double EPS = 1e-7;
    int INF = Integer.MAX_VALUE;
    long INFL = Long.MAX_VALUE;
    double INFD = Double.MAX_VALUE;

    int[] dx = {0,1,0,-1};
    int[] dy = {-1,0,1,0};
    int[] dx8 = {0,1,1,1,0,-1,-1,-1};
    int[] dy8 = {-1,-1,0,1,1,1,0,-1};
    int[] knightMovesX = {1,2,2,1,-1,-2,-2,-1};
    int[] knightMovesY = {-2,-1,1,2,2,1,-1,-2};

    @SuppressWarnings("serial")
    class IncMap extends HashMap<Object, Integer> {
        boolean add(Object key, int amount) {
            Integer i = get(key);
            if (i!=null) {
                put(key, i+amount);
                return false;
            } else {
                put(key, amount);
                return true;
            }
        }
        boolean add(Object key) {
            return add(key, 1);
        }
    }

    int min(int... nums) {
        int r = INF;
        for (int i: nums)
            if (i<r) r=i;
        return r;
    }
    int max(int... nums) {
        int r = -INF;
        for (int i: nums)
            if (i>r) r=i;
        return r;
    }
    long minL(long... nums) {
        long r = INFL;
        for (long i: nums)
            if (i<r) r=i;
        return r;
    }
    long maxL(long... nums) {
        long r = -INFL;
        for (long i: nums)
            if (i>r) r=i;
        return r;
    }
    double minD(double... nums) {
        double r = INFD;
        for (double i: nums)
            if (i<r) r=i;
        return r;
    }
    double maxD(double... nums) {
        double r = -INFD;
        for (double i: nums)
            if (i>r) r=i;
        return r;
    }
    long sumArr(int[] arr) {
        long res = 0;
        for (int i: arr)
            res+=i;
        return res;
    }
    long sumArr(long[] arr) {
        long res = 0;
        for (long i: arr)
            res+=i;
        return res;
    }
    double sumArr(double[] arr) {
        double res = 0;
        for (double i: arr)
            res+=i;
        return res;
    }

    long partsFitCnt(long partSize, long wholeSize) {
        return (partSize+wholeSize-1)/partSize;
    }

    boolean odd(long i) {
        return (i&1)==1;
    }

    int digitSum(long i) {
        i = abs(i);
        int r = 0;
        while (i>0) {
            r+=i%10;
            i/=10;
        }
        return r;
    }
    long digitProd(long i) {
        if (i==0) return 0;
        i = abs(i);
        long r = 1;
        while (i>0) {
            r*=i%10;
            i/=10;
        }
        return r;
    }

    long gcd (long a, long b) {
        while (b>0) {
            a%=b;
            long tmp=a; a=b; b=tmp;
        }
        return a;
    }
    long lcm(long a, long b) {
        return (a*b)/gcd(a,b);
    }

    double log_2 = log(2);
    double log2(double i) {
        return log(i)/log_2;
    }
    long binpow(int x, int n) {
        long r = 1;
        while (n>0) {
            if ((n&1)!=0) r*=x;
            x*=x;
            n>>=1;
        }
        return r;
    }
    long fac(int i) {
        if (i>20) throw new IllegalArgumentException();
        return i<=1 ?  1:fac(i-1)*i;
    }

    double dist(double x, double y, double xx, double yy) {
        return sqrt((xx-x)*(xx-x)+(yy-y)*(yy-y));
    }

    boolean isPalindrome(String s) {
        for (int i=0; i<s.length()/2; i++)
            if (s.charAt(i)!=s.charAt(s.length()-1-i)) return false;
        return true;
    }
    int occurenciesCnt(String s, String pattern) {
        int res = 0;
        for (int i=0; i<s.length()-pattern.length()+1; i++)
            if (s.substring(i, i+pattern.length()).equals(pattern)) res++;
        return res;
    }
    int occurenciesCnt(String s, char pattern) {
        int res = 0;
        for (int i=0; i<s.length(); i++)
            if (s.charAt(i)==pattern) res++;
        return res;
    }

    int[] months = {0,31,28,31,30,31,30,31,31,30,31,30,31};
    boolean isLeapYear(int y) {
        return y%4==0 && (y%400==0 || y%100!=0);
    }
    boolean isValidDate(int d, int m, int y) {
        if (isLeapYear(y) && m==2 && d==29) return true;
        return m>0 && m<=12 && d>0 && d<=months[d];
    }
    int[] nextDay(int d, int m, int y) {
        if (d>=months[m])
            if (m==2 && d==28 && isLeapYear(y)) d++;
            else {d=1; m++;}
        else
            d++;
        if (m==13) {d=1; m=1; y++;}
        return new int[] {d,m,y};
    }

    String str(Object o) {
        return o.toString();
    }

    long timer = System.currentTimeMillis();
    void startTimer() {
        timer = System.currentTimeMillis();
    }
    void stopTimer() {
        System.err.println("time: "+(System.currentTimeMillis()-timer)/1000.0);
    }

    static BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    static BufferedWriter out = new BufferedWriter(new OutputStreamWriter(System.out));

    String nextLine() throws IOException {
        return in.readLine();
    }
    String nextWord() throws IOException {
        StringBuilder sb = new StringBuilder();
        int c = 0;
        while (c<=' ') c=in.read();
        while (c>' ') {
            sb.append((char)c);
            c = in.read();
        }
        return sb.toString();
    }
    int nextInt() throws NumberFormatException, IOException {
        return Integer.parseInt(nextWord());
    }
    long nextLong() throws NumberFormatException, IOException {
        return Long.parseLong(nextWord());
    }
    double nextDouble() throws NumberFormatException, IOException {
        return Double.parseDouble(nextWord());
    }
    int[] nextArr(int size) throws NumberFormatException, IOException {
        int[] arr = new int[size];
        for (int i=0; i<size; i++)
            arr[i] = nextInt();
        return arr;
    }
    long[] nextArrL(int size) throws NumberFormatException, IOException {
        long[] arr = new long[size];
        for (int i=0; i<size; i++)
            arr[i] = nextLong();
        return arr;
    }
    double[] nextArrD(int size) throws NumberFormatException, IOException {
        double[] arr = new double[size];
        for (int i=0; i<size; i++)
            arr[i] = nextDouble();
        return arr;
    }
    String[] nextArrS(int size) throws NumberFormatException, IOException {
        String[] arr = new String[size];
        for (int i=0; i<size; i++)
            arr[i] = nextWord();
        return arr;
    }

    void print(Object o) throws IOException {
        out.write(o.toString());
    }
    void println(Object o) throws IOException {
        out.write(o.toString());
        out.newLine();
    }
    void print(Object... o) throws IOException {
        for (int i=0; i<o.length; i++) {
            if (i!=0) out.write(' ');
            out.write(o[i].toString());
        }
    }
    void println(Object... o) throws IOException {
        print(o);
        out.newLine();
    }
    void printArr(int[] arr) throws IOException {
        for (int i=0; i<arr.length; i++) {
            if (i!=0) out.write(' ');
            out.write(Integer.toString(arr[i]));
        }
    }
    void printArr(long[] arr) throws IOException {
        for (int i=0; i<arr.length; i++) {
            if (i!=0) out.write(' ');
            out.write(Long.toString(arr[i]));
        }
    }
    void printArr(double[] arr) throws IOException {
        for (int i=0; i<arr.length; i++) {
            if (i!=0) out.write(' ');
            out.write(Double.toString(arr[i]));
        }
    }
    void printArr(String[] arr) throws IOException {
        for (int i=0; i<arr.length; i++) {
            if (i!=0) out.write(' ');
            out.write(arr[i]);
        }
    }
    void printlnArr(int[] arr) throws IOException {
        printArr(arr);
        out.newLine();
    }
    void printlnArr(long[] arr) throws IOException {
        printArr(arr);
        out.newLine();
    }
    void printlnArr(double[] arr) throws IOException {
        printArr(arr);
        out.newLine();
    }
    void printlnArr(String[] arr) throws IOException {
        printArr(arr);
        out.newLine();
    }

    void debug(Object... o) {
        if (showDebug) System.err.println(Arrays.deepToString(o));
    }

    public static void main(String[] args) throws Exception {
        Locale.setDefault(Locale.US);
        new C().solve();
        out.flush();
        out.close(); in.close();
    }
}


import java.util.Scanner;
public class Ishu
{
    public static void main(String[] args)
    {
        Scanner scan=new Scanner(System.in);
        long a,b,lcm,d=0,m=0,hcf=1;
        int i;
        a=scan.nextLong();
        b=scan.nextLong();
        lcm=a*b;
        for(i=a<b?a:b;i>0;--i)
            if(a%i==0&&b%i==0)
                {
                 hcf=i;
                 break;
                }
        lcm/=hcf;
        --lcm;
        d=lcm/a;
        m=lcm/b;
        if(a<b)
            ++m;
        else
            ++d;
        if(m>d)
            System.out.println("Masha");
        else if(m<d)
            System.out.println("Dasha");
        else
            System.out.println("Equal");
    }
}


package mysteriousStrings;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class MysteriousStrings {

	static int a = 1;
	static String[] president = {
			"Washington", "Adams", "Jefferson", "Madison", "Monroe", "Quincy Adams",
			"Jackson", "Van Buren", "Henry Harrison", "Tyler", "Polk", "Taylor", "Fillmore",
			"Pierce", "Buchanan", "Lincoln", "Johnson", "Grant", "Hayes", "Garfield", "Arthur",
			"Cleveland", "Harrison", "Cleveland", "McKinley", "Roosevelt", "Howard Taft",
			"Wilson", "Harding", "Coolidge", "Hoover", "Roosevelt", "Truman", "Eisenhower",
			"Kennedy", "Johnson", "Nixon", "Ford", "Carter", "Reagan"
	};
	public static void main(String[] args) throws NumberFormatException, IOException {
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		int a=Integer.parseInt(br.readLine());
		if(1 <= a){
			if(a<= 40){
				System.out.println(president[a-1]);
			}
			else{
				System.out.println("Invalid input!");
			}
		}
		else{
			System.out.println("Invalid input!");
		}
	}
}


import java.util.Scanner;
import java.io.OutputStream;
import java.io.IOException;
import java.io.PrintWriter;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskB solver = new TaskB();
        solver.solve(1, in, out);
        out.close();
    }
}

class TaskB {
    public void solve(int testNumber, Scanner in, PrintWriter out) {
        int a1=in.nextInt();
        int a2=in.nextInt();
        int ans=a1^a2;
        out.println(ans%2);

    }
}


package Round_FirstApril_2013;

import java.util.*;
import java.io.*;

import static java.lang.Math.*;

public class A {

    void solve () throws IOException {
        int a = in.nextInt();
        boolean ok = false;

        if (a == 2){
            out.println("Adams");
        } else if (a % 2 == 0){
            out.println("Van Buren");
        } else {
            out.println("Harding");
        }
    }

    String input = "";
    String output = "";

    FastScanner in;
    PrintWriter out;

    void run () {
        try {
            BufferedReader bf;
            if (input.length() == 0)
                bf = new BufferedReader(new InputStreamReader(
                        System.in));
            else
                bf = new BufferedReader(new FileReader(input));
            in = new FastScanner(bf);

            if (output.length() == 0)
                out = new PrintWriter(System.out);
            else
                out = new PrintWriter(new File(output));

            solve();

            out.close();
        } catch (Exception ex) {
            out.close();
            ex.printStackTrace();
        }
    }

    public static void main (String[] args) {
        new A().run();
    }

    class FastScanner {
        BufferedReader bf;
        StringTokenizer st;

        FastScanner(BufferedReader bf) {
            this.bf = bf;
        }

        String next () throws IOException {
            while (st == null || !st.hasMoreTokens())
                st = new StringTokenizer(bf.readLine());
            return st.nextToken();
        }

        int nextInt () throws IOException {
            return Integer.parseInt(next());
        }

        long nextLong () throws IOException {
            return Long.parseLong(next());
        }

        double nextDouble () throws IOException {
            return Double.parseDouble(next());
        }

        int[] readIntArray (int n) throws IOException {
            int a[] = new int[n];
            for (int i = 0; i < n; i++)
                a[i] = nextInt();
            return a;
        }

        long[] readLongArray (int n) throws IOException {
            long a[] = new long[n];
            for (int i = 0; i < n; i++)
                a[i] = nextLong();
            return a;
        }
    }
}


import java.io.*;
import java.util.*;

public class test{
public static void main(String[] args){
Scanner in = new Scanner(System.in);
PrintWriter out = new PrintWriter(System.out);
String[] s= {Washington,Adams,Jefferson,Madison,Monroe,Quincy Adams,Jackson,Van Buren,Henry Harrison, Tyler,K. Polk,Taylor,Fillmore,Pierce,Buchanan,Lincoln,Johnson,S. Grant,B. Hayes,A. Garfield,A. Arthur,Cleveland,Harrison,Cleveland,McKinley,Roosevelt,Howard Taft,Wilson,G. Harding,Coolidge,Hoover,Roosevelt,S. Truman,D. Eisenhower,F. Kennedy,B. Johnson,Nixon,Ford,Carter,Reagan,H. W. Bush,Clinton,W. Bush,Obama}
int p = in.nextInt();
out.println(s[p+1]);

}
}


mport java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

/**
 * Created by IntelliJ IDEA.
 * User: tiro
 * Date: 19/08/11
 * Time: 18:00
 * To change this template use File | Settings | File Templates.
 */

public class Durak extends Thread {
    private String doS(String input) {
        if (!Character.isDigit(input.charAt(0))) {
            input = input.replace('T', '4');
            input = input.replace('J', '5');
            input = input.replace('Q', '6');
            input = input.replace('K', '7');
            input = input.replace('A', '8');
        } else {
            Integer digit = Character.digit(input.charAt(0), 10);
            Character ch = digit.toString().charAt(0);
            digit -= 6;
            input = input.replace(ch, new Character(digit.toString().charAt(0)));
        }
        return input;
    }

    public void Run() {
        try {
            String superType = nextToken();
            String first = nextToken();
            String second = nextToken();
            first = doS(first);
            second = doS(second);
            if (first.charAt(1) == second.charAt(1) && Character.digit(first.charAt(0), 10) > Character.digit(second.charAt(0), 10)) {
                out.print("YES");
                return;
            } else if (first.charAt(1) == superType.charAt(0)) {
                out.print("YES");
                return;
            }
            out.print("NO");
        } catch (Exception ex) {
            ex.printStackTrace();
        } finally {
            out.flush();
            out.close();
        }
    }

    public static void main(String[] args) {
        new Durak().Run();
    }

    public Durak() {
        in = new BufferedReader(new InputStreamReader(System.in));
        out = new PrintWriter(System.out);
        setPriority(Thread.MAX_PRIORITY);
    }

    private BufferedReader in;
    private PrintWriter out;
    private StringTokenizer stringTokenizer;

    private int nextInt() throws IOException {
        return Integer.parseInt(nextToken());
    }

    private double nextDouble() throws IOException {
        return Double.parseDouble(nextToken());
    }

    private long nextLong() throws IOException {
        return Long.parseLong(nextToken());
    }

    private String nextToken() throws IOException {
        if (stringTokenizer == null || !stringTokenizer.hasMoreElements()) {
            stringTokenizer = new StringTokenizer(in.readLine(), "\t\n\r ");
        }
        return stringTokenizer.nextToken();
    }
}


import java.util.Scanner;

public class test {
public static void main(String[] args) {
	String win="SHDC";
	String rank="6789TJQKA";
	Scanner s=new Scanner(System.in);
	String tump=s.next();
	String s1=s.next();
	String s2=s.next();

	if(s1.contains(tump+"")&&(!s2.contains(tump+""))) System.out.println("YES");
	else if(s2.contains(tump+"")&&(!s1.contains(tump+""))) System.out.println("NO");
	else{
		System.out.println(rank.indexOf(a)!=rank.indexOf(b));
		if (rank.indexOf(a)==rank.indexOf(b)){
	    if(rank.indexOf(s1.charAt(0))>rank.indexOf(s2.charAt(0))) System.out.println("YES");
		else System.out.println("NO");
		}
	}

}
}


import java.util.*;
public class Main{
    public static void main(String args[]){
        Scanner sc=new Scanner(System.in);
        char c=sc.next().charAt(0);
        String st1=sc.next();
        String st2=sc.next();
        String str="6789TJQKA"
        if(st1.charAt(1)==c)System.out.println("YES");
        else if(st1.charAt(1)!=st2.charAt(1))System.out.println("NO");
        else{
            if(st1.indexOf(st1.charAt(0)+"")>st2.indexOg(st2.charAt(0)+""))
            System.out.println("YES");
            else System.out.println("NO");
        }
    }

}


import static java.lang.Math.*;
import static java.util.Arrays.*;
import static java.util.Collections.*;
import java.io.*;
import java.math.*;import static java.lang.Math.*;
import stimport static java.lang.Math.*;
import static java.util.Arrays.*;
import static java.util.Collections.*;
import java.io.*;
import java.math.*;
import java.util.*;

public class CardGame {

    public static void main(String[] args) throws Exception {
        String trump = next();
        String a = next(), b = next();
        String order = "6789TJQKA";
        if ((a.charAt(1) == b.charAt(1) && order.indexOf(a.charAt(0)) > order.indexOf(b.charAt(0))) || (a.charAt(1) == trump.charAt(0) && b.charAt(1) != trump.charAt(0))) {
            System.out.println("YES");
        } else {
            System.out.println("NO");
        }
    }

    static BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    static StringTokenizer st = new StringTokenizer("");

    static void initFileIO(boolean large) throws Exception {
        System.setIn(new FileInputStream("CardGame-" + (large ? "large" : "small") + ".in"));
        System.setOut(new PrintStream("output"));
    }

    static String next() throws Exception {
        while (!st.hasMoreTokens()) {
            String s = in.readLine();
            if (s == null)
                return null;
            st = new StringTokenizer(s);
        }
        return st.nextToken();
    }

    static int nextInt() throws Exception {
        return Integer.parseInt(next());
    }

    static long nextLong() throws Exception {
        return Long.parseLong(next());
    }

    static double nextDouble() throws Exception {
        return Double.parseDouble(next());
    }
}
atic java.util.Arrays.*;
import static java.util.Collections.*;
import java.io.*;
import java.math.*;
import java.util.*;

public class CardGame {

    public static void main(String[] args) throws Exception {
        String trump = next();
        String a = next(), b = next();
        String order = "6789TJQKA";
        if ((a.charAt(1) == b.charAt(1) && order.indexOf(a.charAt(0)) > order.indexOf(b.charAt(0))) || (a.charAt(1) == trump.charAt(0) && b.charAt(1) != trump.charAt(0))) {
            System.out.println("YES");
        } else {
            System.out.println("NO");
        }
    }

    static BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    static StringTokenizer st = new StringTokenizer("");

    static void initFileIO(boolean large) throws Exception {
        System.setIn(new FileInputStream("CardGame-" + (large ? "large" : "small") + ".in"));
        System.setOut(new PrintStream("output"));
    }

    static String next() throws Exception {
        while (!st.hasMoreTokens()) {
            String s = in.readLine();
            if (s == null)
                return null;
            st = new StringTokenizer(s);
        }
        return st.nextToken();
    }

    static int nextInt() throws Exception {
        return Integer.parseInt(next());
    }

    static long nextLong() throws Exception {
        return Long.parseLong(next());
    }

    static double nextDouble() throws Exception {
        return Double.parseDouble(next());
    }
}

import java.util.*;

public class CardGame {

    public static void main(String[] args) throws Exception {
        String trump = next();
        String a = next(), b = next();
        String order = "6789TJQKA";
        if (a.charAt(1) == b.charAt(1) || order.indexOf(a.charAt(0)) > order.indexOf(b.charAt(0)) || (a.charAt(1) == trump.charAt(0) && b.charAt(1) != trump.charAt(0))) {
            System.out.println("YES");
        } else {
            System.out.println("NO");
        }
    }

    static BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    static StringTokenizer st = new StringTokenizer("");

    static void initFileIO(boolean large) throws Exception {
        System.setIn(new FileInputStream("CardGame-" + (large ? "large" : "small") + ".in"));
        System.setOut(new PrintStream("output"));
    }

    static String next() throws Exception {
        while (!st.hasMoreTokens()) {
            String s = in.readLine();
            if (s == null)
                return null;
            st = new StringTokenizer(s);
        }
        return st.nextToken();
    }

    static int nextInt() throws Exception {
        return Integer.parseInt(next());
    }

    static long nextLong() throws Exception {
        return Long.parseLong(next());
    }

    static double nextDouble() throws Exception {
        return Double.parseDouble(next());
    }
}


import java.util.*;
public class bear
{
    public static void main(String args[])
    {
        Scanner sc=new Scanner(System.in);
        int c=0;
        int a=sc.nextInt();
        int b=sc.nexxtInt();
        while(a<b)
        {
            a=a*3;
            b=b*2;
            ++c;
        }
        System.out.println(c);
    }
}


import java.util.Scanner;
public class Solution{
    public static void main(String[] args){
        Scanner s = new Scanner(System.in);
        int a = s.nextInt();
        int b = s.nextInt();
        int i;
        if(a<=b){
            for(i = 0 ; ; i++){
                a *= 3;
                b *= 2;
            }
        }
        System.out.println(i);
    }
}


import java. util. Scanner;
public class main{
    static Scanner sc=new Scanner(System. in);
    static int i;
    public static int years(int a,int b){
        for(int i=1;i<=b;i++){
            if((a*3)>(b*2))
            return i;
            else
            a*=3;
            b*=2;

        }
        return i;
    }
    public static void main(String[]args){
        int a=sc. nextInt();
        int b=sc. nextInt();
        System. out. println(years(a, b);
    }
}


import java.util.*;

public class BearBrother {
	public static void main (String[] args) {
		String input = scanner.nextLine();
		String[] temp = input.split(" ");
		int[] weights = new int[temp.length];
		for (int i = 0; i < temp.length; i++) {
            weights[i] = Integer.parseInt(temp[i]);
        }

        int a = weights[0];
        int b = weights[1];

        //a <= b at start
        int year = 0;
        while(a <= b){
			year++;
			a *= 3;
			b *=2;
		}

		System.out.print(year);
	}
}


import java.io.*;
import java.util.Arrays;
import java.util.StringJoiner;
import java.util.StringTokenizer;
import java.util.function.IntBinaryOperator;

public class Main {

    static int N, M;

    public static void main(String[] args) {
        FastScanner sc = new FastScanner(System.in);
        N = sc.nextInt();
        M = sc.nextInt();

        System.out.println(solve());
    }

    static int MOD = 1_000_000_007;

    static int solve() {
        // 右側に 0* or 1 をくっつけていくDPを考える
        // M=3のケース
        // f4 = f1 + f3
        // f3 = f2
        // f2 = f1
        IntMat mat = new IntMat(M, M);
        mat.set(0, 0, 1);
        mat.set(0, M-1, 1);
        for (int i = 1; i < M; i++) {
            mat.set(i, i-1, 1);
        }

        IntBinaryOperator add = (a, b) -> {
            int c = a+b;
            if( c >= MOD ) {
                c %= MOD;
            }
            return c;
        };
        IntBinaryOperator mul = (a, b) -> {
            long c = (long)a*b;
            if( c >= MOD ) {
                c %= MOD;
            }
            return (int)c;
        };

        IntMat powed = IntMat.pow(mat, N, mul, add);
        IntMat in = new IntMat(M, 1);
        in.set(0, 0, 1);
        IntMat out = IntMat.dot(powed, in);
        return out.get(0, 0);
    }

    static class IntMat {

        final int[][] mat;

        IntMat(int r, int c) {
            mat = new int[r][c];
        }

        IntMat(int[][] mat) {
            this.mat = mat;
        }

        IntMat(int[] vec) {
            mat = new int[vec.length][1];
            for (int i = 0; i < vec.length; i++) {
                mat[i][0] = vec[i];
            }
        }

        static IntMat pow(IntMat m, long k, IntBinaryOperator mul, IntBinaryOperator add) {
            if( m.row() != m.col() ) throw new IllegalArgumentException("row != col : " + m.row() + " " + m.col());

            int n = m.row();
            IntMat ret = new IntMat(n, n);
            for (int i = 0; i < n; i++) {
                ret.set(i, i, 1);
            }
            if( k == 0 ) return ret; // どうだろ...

            while( k > 0 ) {
                if( (k & 1) == 1 ) {
                    ret = IntMat.dot(ret, m, mul, add);
                }

                m = IntMat.dot(m, m, mul, add);
                k = k >> 1L;
            }
            return ret;
        }

        static IntMat dot(IntMat a, IntMat b) {
            return dot(a, b, (i, j) -> i*j, (i, j) -> i+j);
        }

        static IntMat dot(IntMat a, IntMat b, IntBinaryOperator mul, IntBinaryOperator add) {
            int[][] ret = new int[a.row()][b.col()];

            for (int r = 0; r < a.row(); r++) {
                for (int c = 0; c < b.col(); c++) {
                    int sum = 0;
                    for (int i = 0; i < b.row(); i++) {
                        sum = add.applyAsInt(sum, mul.applyAsInt(a.get(r, i), b.get(i, c)));
                    }
                    ret[r][c] = sum;
                }
            }
            return new IntMat(ret);
        }

        void set(int r, int c, int n) {
            mat[r][c] = n;
        }

        int get(int r, int c) {
            try {
                return mat[r][c];
            } catch( ArrayIndexOutOfBoundsException e ) {
                throw new RuntimeException("wrong index : r=" + r + " c=" + c + " row=" + row() + " col=" + col());
            }
        }

        int row() {
            return mat.length;
        }

        int col() {
            return mat[0].length;
        }
    }

    @SuppressWarnings("unused")
    static class FastScanner {
        private BufferedReader reader;
        private StringTokenizer tokenizer;

        FastScanner(InputStream in) {
            reader = new BufferedReader(new InputStreamReader(in));
            tokenizer = null;
        }

        String next() {
            if (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        String nextLine() {
            if (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    return reader.readLine();
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken("\n");
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        int[] nextIntArray(int n) {
            int[] a = new int[n];
            for (int i = 0; i < n; i++) a[i] = nextInt();
            return a;
        }

        int[] nextIntArray(int n, int delta) {
            int[] a = new int[n];
            for (int i = 0; i < n; i++) a[i] = nextInt() + delta;
            return a;
        }

        long[] nextLongArray(int n) {
            long[] a = new long[n];
            for (int i = 0; i < n; i++) a[i] = nextLong();
            return a;
        }
    }

    static void writeLines(int[] as) {
        PrintWriter pw = new PrintWriter(System.out);
        for (int a : as) pw.println(a);
        pw.flush();
    }

    static void writeLines(long[] as) {
        PrintWriter pw = new PrintWriter(System.out);
        for (long a : as) pw.println(a);
        pw.flush();
    }

    static void writeSingleLine(int[] as) {
        PrintWriter pw = new PrintWriter(System.out);
        for (int i = 0; i < as.length; i++) {
            if (i != 0) pw.print(" ");
            pw.print(as[i]);
        }
        pw.println();
        pw.flush();
    }

    static int max(int... as) {
        int max = Integer.MIN_VALUE;
        for (int a : as) max = Math.max(a, max);
        return max;
    }

    static int min(int... as) {
        int min = Integer.MAX_VALUE;
        for (int a : as) min = Math.min(a, min);
        return min;
    }

    static void debug(Object... args) {
        StringJoiner j = new StringJoiner(" ");
        for (Object arg : args) {
            if (arg == null) j.add("null");
            else if (arg instanceof int[]) j.add(Arrays.toString((int[]) arg));
            else if (arg instanceof long[]) j.add(Arrays.toString((long[]) arg));
            else if (arg instanceof double[]) j.add(Arrays.toString((double[]) arg));
            else if (arg instanceof Object[]) j.add(Arrays.toString((Object[]) arg));
            else j.add(arg.toString());
        }
        System.err.println(j.toString());
    }

    static void printSingleLine(int[] array) {
        PrintWriter pw = new PrintWriter(System.out);
        for (int i = 0; i < array.length; i++) {
            if (i != 0) pw.print(" ");
            pw.print(array[i]);
        }
        pw.println();
        pw.flush();
    }

    static int lowerBound(int[] array, int value) {
        int lo = 0, hi = array.length, mid;
        while (lo < hi) {
            mid = (hi + lo) / 2;
            if (array[mid] < value) lo = mid + 1;
            else hi = mid;
        }
        return lo;
    }

    static int upperBound(int[] array, int value) {
        int lo = 0, hi = array.length, mid;
        while (lo < hi) {
            mid = (hi + lo) / 2;
            if (array[mid] <= value) lo = mid + 1;
            else hi = mid;
        }
        return lo;
    }
}


import java.util.*;

public class Dcode {

    static  int m;
    static  int mod = 1000000007;

    static  long[][] mul(long a[][],long n){
        if(n<=1){
            return a;
        }

        long base = (long)Math.floor(Math.log(n)/Math.log(2));

        n = n - (long)Math.pow(2,base);
        if(n==0){
            return pow(a,(long)Math.pow(2,base));
        }

        long x[][] = mul(a,n);
        long y[][] = pow(a,(long)Math.pow(2,base));
        long c[][] = new long[m][m];

        for(int i=0;i<m;i++){
            for(int j=0;j<m;j++){
                long sum = 0;
                for(int k=0;k<m;k++){
                    sum = (sum + x[i][k]*y[k][j])%mod;
                }

                c[i][j] = sum;
            }
        }

        return c;

    }

    static  long[][] pow(long a[][],long n){
         if(n==1){
             return a;
         }
        if(n==2){

            long c[][] = new long[m][m];

            for(int i=0;i<m;i++){
                for(int j=0;j<m;j++){
                    long sum = 0;
                    for(int k=0;k<m;k++){
                        sum = (sum + a[i][k]*a[k][j])%mod;
                    }

                    c[i][j] = sum;
                }
            }

            return c;
        }

        return pow(pow(a,n/2),2);
    }
    public static  void main(String args[]){

        Scanner s = new Scanner(System.in);
        int n = s.nextInt();
        m = s.nextInt();
        long a[][] = new long[m][m];

        a[0][0] = 1;
        a[0][m-1] = 1;
        for(int i=1;i<m;i++){
            a[i][i-1] = 1;
        }

        long ans  = 0;

        long h[][] = mul(a,n-m);

        ans = 2*h[0][0];

        for(int i=1;i<m;i++){
            ans = (ans + h[0][i])%mod;
        }

        System.out.println(ans);

    }
}


// package Practice.CF1117;

import java.io.*;
import java.math.BigInteger;
import java.util.*;

public class CF1117D {
    static FastReader s;
    static PrintWriter out;
    static String INPUT = "4 2\n";

    public static void main(String[] args) {
        long time = System.currentTimeMillis();
        boolean oj = System.getProperty("ONLINE_JUDGE") != null;
        out = new PrintWriter(System.out);
        s = new FastReader(oj);
        long n = s.nextLong();
        long m = s.nextLong();
        long k = n/m;
        long firstTerm = n - m + 1;
        BigInteger ans;
        if(k != 1) {
            BigInteger k2 = BigInteger.valueOf(k/2);
            BigInteger fi2 = BigInteger.TWO.multiply(BigInteger.valueOf(firstTerm));
            BigInteger km = BigInteger.valueOf(k).multiply(BigInteger.valueOf(m));
            BigInteger mB = BigInteger.valueOf(m);
            ans = k2.multiply(fi2.subtract(km).add(mB));
        } else {
            ans = BigInteger.valueOf(firstTerm);
        }
        out.println(ans.add(BigInteger.ONE).mod(BigInteger.valueOf(1000000007)));
        if (!oj) {
            System.out.println(Arrays.deepToString(new Object[]{System.currentTimeMillis() - time + " ms"}));
        }
        out.flush();
    }

    private static class Maths {
        static ArrayList<Long> printDivisors(long n) {
            // Note that this loop runs till square root
            ArrayList<Long> list = new ArrayList<>();
            for (long i = 1; i <= Math.sqrt(n); i++) {
                if (n % i == 0) {
                    if (n / i == i) {
                        list.add(i);
                    } else {
                        list.add(i);
                        list.add(n / i);
                    }
                }
            }
            return list;
        }

        //    GCD - Using Euclid theorem.
        private static long gcd(long a, long b) {
            if (b == 0) {
                return a;
            }

            return gcd(b, a % b);
        }

        //    Extended euclidean algorithm
//    Used to solve equations of the form ax + by = gcd(a,b)
//    return array [d, a, b] such that d = gcd(p, q), ap + bq = d
        static long[] extendedEuclidean(long p, long q) {
            if (q == 0)
                return new long[]{p, 1, 0};

            long[] vals = extendedEuclidean(q, p % q);
            long d = vals[0];
            long a = vals[2];
            long b = vals[1] - (p / q) * vals[2];
            return new long[]{d, a, b};
        }

        // X ^ y mod p
        static long power(long x, long y, long p) {
            long res = 1;
            x = x % p;

            while (y > 0) {
                if ((y & 1) == 1)
                    res = (res * x) % p;
                y = y >> 1;
                x = (x * x) % p;
            }
            return res;
        }

        // Returns modulo inverse of a
        // with respect to m using extended
        // Euclid Algorithm. Refer below post for details:
        // https://www.geeksforgeeks.org/multiplicative-inverse-under-modulo-m/
        static long inv(long a, long m) {
            long m0 = m, t, q;
            long x0 = 0, x1 = 1;

            if (m == 1)
                return 0;

            // Apply extended Euclid Algorithm
            while (a > 1) {
                q = a / m;
                t = m;
                m = a % m;
                a = t;
                t = x0;
                x0 = x1 - q * x0;
                x1 = t;
            }

            // Make x1 positive
            if (x1 < 0)
                x1 += m0;

            return x1;
        }

        // k is size of num[] and rem[].
        // Returns the smallest number
        // x such that:
        // x % num[0] = rem[0],
        // x % num[1] = rem[1],
        // ..................
        // x % num[k-2] = rem[k-1]
        // Assumption: Numbers in num[] are pairwise
        // coprime (gcd for every pair is 1)
        static long findMinX(long num[], long rem[], long k) {
            int prod = 1;
            for (int i = 0; i < k; i++)
                prod *= num[i];

            int result = 0;
            for (int i = 0; i < k; i++) {
                long pp = prod / num[i];
                result += rem[i] * inv(pp, num[i]) * pp;
            }

            return result % prod;
        }
    }

    private static class BS {
        //  Binary search
        private static int binarySearch(int[] arr, int ele) {
            int low = 0;
            int high = arr.length - 1;
            while (low <= high) {
                int mid = (low + high) / 2;
                if (arr[mid] == ele) {
                    return mid;
                } else if (ele < arr[mid]) {
                    high = mid - 1;
                } else {
                    low = mid + 1;
                }
            }
            return -1;
        }

        //    First occurence using binary search
        private static int binarySearchFirstOccurence(int[] arr, int ele) {
            int low = 0;
            int high = arr.length - 1;
            int ans = -1;
            while (low <= high) {
                int mid = (low + high) / 2;
                if (arr[mid] == ele) {
                    ans = mid;
                    high = mid - 1;
                } else if (ele < arr[mid]) {
                    high = mid - 1;
                } else {
                    low = mid + 1;
                }
            }
            return ans;
        }

        //    Last occurenece using binary search
        private static int binarySearchLastOccurence(int[] arr, int ele) {
            int low = 0;
            int high = arr.length - 1;
            int ans = -1;
            while (low <= high) {
                int mid = (low + high) / 2;
                if (arr[mid] == ele) {
                    ans = mid;
                    low = mid + 1;
                } else if (ele < arr[mid]) {
                    high = mid - 1;
                } else {
                    low = mid + 1;
                }
            }
            return ans;
        }
    }

    private static class arrays {
        // Merge sort
        static void merge(int arr[], int l, int m, int r) {
            int n1 = m - l + 1;
            int n2 = r - m;
            int L[] = new int[n1];
            int R[] = new int[n2];
            for (int i = 0; i < n1; ++i)
                L[i] = arr[l + i];
            for (int j = 0; j < n2; ++j)
                R[j] = arr[m + 1 + j];
            int i = 0, j = 0;
            int k = l;
            while (i < n1 && j < n2) {
                if (L[i] <= R[j]) {
                    arr[k] = L[i];
                    i++;
                } else {
                    arr[k] = R[j];
                    j++;
                }
                k++;
            }

            while (i < n1) {
                arr[k] = L[i];
                i++;
                k++;
            }

            while (j < n2) {
                arr[k] = R[j];
                j++;
                k++;
            }
        }

        static void sort(int arr[], int l, int r) {
            if (l < r) {
                int m = (l + r) / 2;
                sort(arr, l, m);
                sort(arr, m + 1, r);
                merge(arr, l, m, r);
            }
        }

        static void sort(int[] arr) {
            sort(arr, 0, arr.length - 1);
        }
    }

    private static class UnionFindDisjointSet {
        int[] parent;
        int[] size;
        int n;
        int size1;

        public UnionFindDisjointSet(int n) {
            this.n = n;
            this.parent = new int[n];
            this.size = new int[n];
            for (int i = 0; i < n; i++) {
                parent[i] = i;
            }

            for (int i = 0; i < n; i++) {
                size[i] = 1;
            }

            this.size1 = n;
        }

        private int numDisjointSets() {
            System.out.println(size1);
            return size1;
        }

        private boolean find(int a, int b) {
            int rootA = root(a);
            int rootB = root(b);
            if (rootA == rootB) {
                return true;
            }
            return false;
        }

        private int root(int b) {
            while (parent[b] != b) {
                parent[b] = parent[parent[b]];
                b = parent[b];
            }
            return b;
        }

        private void union(int a, int b) {
            int rootA = root(a);
            int rootB = root(b);
            if (rootA == rootB) {
                return;
            }

            if (size[rootA] < size[rootB]) {
                parent[rootA] = parent[rootB];
                size[rootB] += size[rootA];
            } else {
                parent[rootB] = parent[rootA];
                size[rootA] += size[rootB];
            }
            size1--;
            System.out.println(Arrays.toString(parent));
        }
    }

    private static class SegTree {
        int[] st;
        int[] arr;

        public SegTree(int[] arr) {
            this.arr = arr;
            int size = (int) Math.ceil(Math.log(arr.length) / Math.log(2));
            st = new int[(int) ((2 * Math.pow(2, size)) - 1)];
            buildSegmentTree(1, 0, arr.length - 1);
        }

        //**********JUST CALL THE CONSTRUCTOR, THIS FUNCTION WILL BE CALLED AUTOMATICALLY******
        private void buildSegmentTree(int index, int L, int R) {
            if (L == R) {
                st[index] = arr[L];
                return;
            }

            buildSegmentTree(index * 2, L, (L + R) / 2);
            buildSegmentTree(index * 2 + 1, (L + R) / 2 + 1, R);
//          Replace this line if you want to change the function of the Segment tree.
            st[index] = Math.min(st[index * 2], st[index * 2 + 1]);
        }

        //***********We have to use this function **************
        private int Query(int queL, int queR) {
            return Query1(1, 0, arr.length - 1, queL, queR);
        }

        //This is a helper function.
        //************* DO NOT USE THIS ****************
        private int Query1(int index, int segL, int segR, int queL, int queR) {
            if (queL > segR || queR < segL) {
                return -1;
            }

            if (queL <= segL && queR >= segR) {
                return st[index];
            }

            int ans1 = Query1(index * 2, segL, (segL + segR) / 2, queL, queR);
            int ans2 = Query1(index * 2 + 1, (segL + segR) / 2 + 1, segR, queL, queR);
            if (ans1 == -1) {
                return ans2;
            }

            if (ans2 == -1) {
                return ans1;
            }
//             Segment tree implemented for range minimum query. Change the below line to change the function.
            return Math.min(ans1, ans2);
        }

        private void update(int idx, int val) {
            update1(1, 0, arr.length - 1, idx, val);
        }

        private void update1(int node, int queL, int queR, int idx, int val) {
            // idx - index to be updated in the array
            // node - index to be updated in the seg tree
            if (queL == queR) {
                // Leaf node
                arr[idx] += val;
                st[node] += val;
            } else {
                int mid = (queL + queR) / 2;
                if (queL <= idx && idx <= mid) {
                    // If idx is in the left child, recurse on the left child
                    update1(2 * node, queL, mid, idx, val);
                } else {
                    // if idx is in the right child, recurse on the right child
                    update1(2 * node + 1, mid + 1, queR, idx, val);
                }
                // Internal node will have the min of both of its children
                st[node] = Math.min(st[2 * node], st[2 * node + 1]);
            }
        }

    }

    private static class FastReader {
        InputStream is;

        public FastReader(boolean onlineJudge) {
            is = onlineJudge ? System.in : new ByteArrayInputStream(INPUT.getBytes());
        }

        byte[] inbuf = new byte[1024];
        public int lenbuf = 0, ptrbuf = 0;

        int readByte() {
            if (lenbuf == -1)
                throw new InputMismatchException();
            if (ptrbuf >= lenbuf) {
                ptrbuf = 0;
                try {
                    lenbuf = is.read(inbuf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (lenbuf <= 0)
                    return -1;
            }
            return inbuf[ptrbuf++];
        }

        boolean isSpaceChar(int c) {
            return !(c >= 33 && c <= 126);
        }

        int skip() {
            int b;
            while ((b = readByte()) != -1 && isSpaceChar(b))
                ;
            return b;
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }

        char nextChar() {
            return (char) skip();
        }

        String next() {
            int b = skip();
            StringBuilder sb = new StringBuilder();
            while (!(isSpaceChar(b))) { // when nextLine, (isSpaceChar(b) && b != ' ')
                sb.appendCodePoint(b);
                b = readByte();
            }
            return sb.toString();
        }

        String nextLine() {
            int b = skip();
            StringBuilder sb = new StringBuilder();
            while ((!isSpaceChar(b) || b == ' ')) { // when nextLine, (isSpaceChar(b) && b != ' ')
                sb.appendCodePoint(b);
                b = readByte();
            }
            return sb.toString();
        }

        char[] next(int n) {
            char[] buf = new char[n];
            int b = skip(), p = 0;
            while (p < n && !(isSpaceChar(b))) {
                buf[p++] = (char) b;
                b = readByte();
            }
            return n == p ? buf : Arrays.copyOf(buf, p);
        }

        int nextInt() {
            int num = 0, b;
            boolean minus = false;
            while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'))
                ;
            if (b == '-') {
                minus = true;
                b = readByte();
            }

            while (true) {
                if (b >= '0' && b <= '9') {
                    num = num * 10 + (b - '0');
                } else {
                    return minus ? -num : num;
                }
                b = readByte();
            }
        }

        long nextLong() {
            long num = 0;
            int b;
            boolean minus = false;
            while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'))
                ;
            if (b == '-') {
                minus = true;
                b = readByte();
            }

            while (true) {
                if (b >= '0' && b <= '9') {
                    num = num * 10 + (b - '0');
                } else {
                    return minus ? -num : num;
                }
                b = readByte();
            }
        }

        char[][] nextMatrix(int n, int m) {
            char[][] map = new char[n][];
            for (int i = 0; i < n; i++)
                map[i] = next(m);
            return map;
        }

        int[] nextIntArray(int n) {
            int[] a = new int[n];
            for (int i = 0; i < n; i++)
                a[i] = nextInt();
            return a;
        }

        long[] nextLongArray(int n) {
            long[] a = new long[n];
            for (int i = 0; i < n; i++)
                a[i] = nextLong();
            return a;
        }

        int[][] next2DInt(int n, int m) {
            int[][] arr = new int[n][];
            for (int i = 0; i < n; i++) {
                arr[i] = nextIntArray(m);
            }
            return arr;
        }

        long[][] next2DLong(int n, int m) {
            long[][] arr = new long[n][];
            for (int i = 0; i < n; i++) {
                arr[i] = nextLongArray(m);
            }
            return arr;
        }

        int[] shuffle(int[] arr) {
            Random r = new Random();
            for (int i = 1, j; i < arr.length; i++) {
                j = r.nextInt(i);
                arr[i] = arr[i] ^ arr[j];
                arr[j] = arr[i] ^ arr[j];
                arr[i] = arr[i] ^ arr[j];
            }
            return arr;
        }

        int[] uniq(int[] arr) {
            Arrays.sort(arr);
            int[] rv = new int[arr.length];
            int pos = 0;
            rv[pos++] = arr[0];
            for (int i = 1; i < arr.length; i++) {
                if (arr[i] != arr[i - 1]) {
                    rv[pos++] = arr[i];
                }
            }
            return Arrays.copyOf(rv, pos);
        }
    }

}


import java.util.*;
import java.io.*;

public class MagicGems {
    public static final long MOD = 1000000007L;
    public static final long MODS = MOD*MOD;
    public static void main(String[] args) {
        FastScanner scanner = new FastScanner();
        PrintWriter out = new PrintWriter(System.out);
        long N = scanner.nextLong();
        int M = scanner.nextInt();
        long[][] matrix = new long[M][M];
        for(int i= 0; i  < M-1; i++) {
            matrix[i+1][i] = 1;
        }
        //base cases
        matrix[0][0] = 1;
        matrix[0][M-1] = 1;
        long[] ans = new long[M];
        ans[0] = 1;
        out.println(mPow(matrix, ans, N)[0]);
        out.flush();
    }

    public static long[] mPow (long[][] M,  long[] v, int pow) {
        for(int i= 0; i < v.length; i++) if(v[i] >= MOD) v[i]%=MOD;
        long[][] ret = M;
        //>>>= is an unsigned right shift by 1
        for(;pow> 0; pow >>>=1) {
            if ((pow&1)==1) v = mMul(ret, v);
            ret = mSquare(ret);
        }
        return v;
    }

    public static long[] mMul(long[][] M, long[] v) {
        int m = M.length;
        int n= v.length;
        long[] ret = new long[m];
        for(int i= 0; i < m; i++) {
            long sum = 0;
            for(int k = 0; k < n; k++) {
                sum += M[i][k] * v[k];
                if (sum >= MODS) sum-= MODS;
            }
            ret[i] = sum;
        }
        return ret;
    }

    //need to be a square matrix
    //should have efficiency based on lacking mod ops.
    public static long[][] mSquare(long[][] M) {
        int N = M.length;
        long[][] ret = new long[N][N];
        for(int i = 0; i < N; i++) {
            long[] temp = new long[N];
            for(int k = 0; k < N; k++) {
                for(int j = 0; j < N; j++) {
                    temp[j] += M[i][k] * M[k][j];
                    if (temp[j] >= MODS) temp[j]-=MODS;
                }
            }
            for(int k = 0; k < N; k++) {
                ret[i][k] = (temp[k] %MOD);
            }
        }
        return ret;
    }

    public static class FastScanner {
        BufferedReader br;
        StringTokenizer st;

        public FastScanner(Reader in) {
            br = new BufferedReader(in);
        }

        public FastScanner() {
            this(new InputStreamReader(System.in));
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }

        String readNextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }

        int[] readIntArray(int n) {
            int[] a = new int[n];
            for (int idx = 0; idx < n; idx++) {
                a[idx] = nextInt();
            }
            return a;
        }
    }
}


import java.io.*;
public class _402_A {
	boolean testOutput=true;
	public void runTestCases() throws Exception{
//		Case 0
		input=
		"3 10 3 3 ";
		runTest(input,
		"2 ");

//		Case 1
		input=
		"3 10 1 3 ";
		runTest(input,
		"3 ");

//		Case 2
		input=
		"100 100 1 1000 ";
		runTest(input,
		"1 ");

//		Case 1
		input=
		"3 20 1 3 ";
		runTest(input,
		"3 ");

	}

	public void compare(String rcAnswer, String realAnswer){
		realAnswer=realAnswer.trim();
		rcAnswer=rcAnswer.trim();
		if(realAnswer.equals(rcAnswer)){
			System.out.println("[Passed] Case "+nroCases);
		}else{
			failed=true;
			System.out.println("rChi "+rcAnswer);
			System.out.println("Expected "+realAnswer);
			System.out.println("[Failed] Case "+nroCases);
//			System.exit(0);
		}
		nroCases++;
	}

	public void runTest(String input, String output) throws Exception{
		r.in= new ByteArrayInputStream(input.getBytes());
		r.run();
		if(testOutput){
			compare(baos.toString(), output);
		}else{
			System.out.println(baos.toString());
		}
		baos.reset();
//		r.in.
	}
	_402_A_Nuts r;
	ByteArrayOutputStream baos = new ByteArrayOutputStream();
	private void init() throws Exception{
		r = new _402_A_Nuts();
		r.out = new PrintWriter(baos);
		runTestCases();
		if(testOutput && !failed){
			System.out.println("All test cases [Passed]");
		}
	}
	private String input;
	private int nroCases=1;
	private boolean failed=false;
	public static void main(String[] args) throws Exception {
		new _402_A().init();
	}

}


import java.util.Scanner;

public class CF236_1 {

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int k = in.nextInt();
        int a = in.nextInt();
        int b = in.nextInt();
        int v = in.nextInt();

        if (k > b) {
        int i;
        for (i = 0; a > 0; i++) {
            if (b > 0) {
            for (int j = 0; b >= 0; b--) {
                a = a - v;
            }
            }else {
                a = a - v;
            }
        }
        System.out.println(i);
        } else {
            int i;
            for (i = 0; a > 0; i++) {
                if(b > 0){
                    for (int j = 0; j < k  ; j++) {
                        if (b > 0) {
                            a = a - v;
                        }
                    }
                    b--;
                //  if( b == 0) break;
                } else {
                    a = a - v;
                }

            }

        System.out.println(i);

        }

    }


import java.util.Scanner;

public class Nuts {

	private static int k;
	private static int a;
	private static int b;
	private static int v;
	private static int boxesNumber;

	public static void main(String[] args) {

		boxesNumber = 0;

		Scanner scanner = new Scanner(System.in);
		String input = scanner.nextLine();
		String[] parts = input.split(" ");

		// максимальное количество отсеков в коробке
		k = Integer.parseInt(parts[0]);
		// количество орехов
		a = Integer.parseInt(parts[1]);
		// количество разделителей
		b = Integer.parseInt(parts[2]);
		// вместительность каждого отсека
		v = Integer.parseInt(parts[3]);

		/*---------------------------------*/

		while (a > 0) {
			// берем еще коробку
			boxesNumber++;
			if (b > 0) {
				a -= v*(Math.min(b, k-1) + 1);
				b -= Math.min(b, k-1);
			} else {
				a -= v;
			}
		}

		System.out.println(boxesNumber);
	}
}


import java.util.Scanner;

public class problemA {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int k, a, b, v, n;
        k = sc.nextInt(); // max кол-во отсеков в 1 коробке
        a = sc.nextInt(); // кол-во орехов
        b = sc.nextInt(); // кол-во разделителей
        v = sc.nextInt(); // max кол-во орехов в отсеке

        int nDiv = ((Double)Math.ceil((double)a / v)).intValue();
        int c = b + 1;

        if (nDiv <= c) {
            n = ((Double)Math.ceil((double)nDiv / k)).intValue();
        } else {
            n = ((Double)Math.ceil((double)c / k)).intValue() + (nDiv - c);
        }

        System.out.println(n);
    }
}


import java.io.*;
import java.util.*;

public class B {
    private static Scanner sc = new Scanner(new InputStreamReader(System.in));
    public static void main (String[] args) {
        String[] nums = sc.nextLine().split(" ");
        String ops = sc.nextLine();
        long[] ns = new long[4];
        for (int i = 0; i < 4; i++) ns[i] = Integer.parseInt(nums[i]);

        System.out.println(solve(ns, ops));
    }
    static long solve(long[] ns, String ops) {
        Arrays.sort(ns);
        if (ops.equals("+ + +")) return ns[0] + ns[1] + ns[2] + ns[3];
        if (ns[0] == 0) return 0;
        if (ops.equals("* * *")) return ns[0] * ns[1] * ns[2] * ns[3];
        long e = ns[0] * ns[1];
        if (ops.equals("+ * *") || ops.equals("* + *") || ops.equals("* * +")) {
            if (e <= ns[3]) return e * ns[2] + ns[3];
            else return e + ns[2] * ns[3];
        }
        return e + ns[2] + ns[3];
    }
}


import java.io.*;
import java.util.*;
import static java.lang.Math.*;

public class ProblemB_51 {

	final boolean ONLINE_JUDGE=System.getProperty("ONLINE_JUDGE")!=null;
	BufferedReader in;
	PrintWriter out;
	StringTokenizer tok=new StringTokenizer("");

	void init() throws FileNotFoundException{
		if (ONLINE_JUDGE){
			in=new BufferedReader(new InputStreamReader(System.in));
			out =new PrintWriter(System.out);
		}
		else{
			in = new BufferedReader(new FileReader("input.txt"));
			out = new PrintWriter("output.txt");
		}
	}

	String readString() throws IOException{
		while(!tok.hasMoreTokens()){
			tok=new StringTokenizer(in.readLine());
		}
		return tok.nextToken();
	}

	int readInt() throws IOException{
		return Integer.parseInt(readString());
	}

	public static void main(String[] args){
		new ProblemB_51().run();
	}

	public void run(){
		try{
			long t1=System.currentTimeMillis();
			init();
			solve();
			out.close();
			long t2=System.currentTimeMillis();
			System.err.println("Time = "+(t2-t1));
		}catch (Exception e){
			e.printStackTrace(System.err);
			System.exit(-1);
		}
	}

	void solve() throws IOException{
		long[] a=new long[6];
		for (int i=0; i<4; i++){
			a[i]=readInt();
		}
		a[5]=0;
		String[] c=new String[3];
		for (int i=0; i<3; i++){
			c[i]=readString();
		}
		HashSet<Integer> b=new HashSet<Integer>();
		long min=Long.MAX_VALUE;
		for (int i1=0; i1<4; i1++){
			b.clear();
			a[5]=0;
			a[4]=a[i1];
			b.add(i1);
			for (int i2=0; i2<4; i2++){
				if (!b.contains(i2)){
					b.add(i2);
					if (c[0].charAt(0)=='+'){
						a[4]+=a[i2];
					}else{
						a[4]*=a[i2];
					}
					for (int i3=0; i3<5; i3++){
						if (!b.contains(i3)){
							b.add(i3);
							a[5]=a[i3];
							for (int i4=0; i4<5; i4++){
								if (!b.contains(i4)){
									b.add(i4);
									if (c[1].charAt(0)=='+'){
										a[5]+=a[i4];
									}else{
										a[5]*=a[i4];
									}
									for (int i=0; i<5; i++){
										if(!b.contains(i)){
												if (c[2].charAt(0)=='+'){
													a[5]+=a[i];
												}else{
													a[5]*=a[i];
												}
												if (a[5]<min){
													min=a[5];
												}
												if (c[2].charAt(0)=='+'){
													a[5]-=a[i];
												}else{
													a[5]/=a[i];
												}
											}
										}
									b.remove(i4);
									a[5]=a[i3];
								}
							}
							b.remove(i3);
							a[5]=0;
						}
					}
					b.remove(i2);
					if (c[0].charAt(0)=='+'){
						a[4]-=a[i2];
					}else{
						a[4]/=a[i2];
					}
				}
			}
		}
		out.print(min);
	}
}


import java.util.*;
public class B55 {
    int add;
    static int multy;
    public static void main(String[]args){
        Scanner sc = new Scanner(System.in);

        long ar [] = new long [4];
        for (int i = 0; i<4; i++){
            ar[i] = sc.nextLong();
        }
        int[]act = new int[3];
        int add = 0;
        int multy = 0;
        for (int i = 0; i<3; i++){
            String S = sc.next();
            if (S.equals("+")){act[i]=1; add++;}
            if (S.equals("*")){act[i]=2; multy++;}
        }
        System.out.println( count(act, ar[0], ar[1], ar[2], ar[3], multy) );
    }

    public static long count(int[]act, long A, long B, long C, long D, int multy){
        ArrayList<Long>f = new ArrayList<Long>();
        f.add(A);
        f.add(B);
        f.add(C);
        f.add(D);

        if (multy<=1){
            for (int i = 0; i<3; i++){
                if (act[i]==1){f = mySort(f); f.set(0, f.remove(0) + f.get(0) );}
                if (act[i]==2){Collections.sort(f);  f.set(0, f.get(0) * f.remove(1) );}
            }
        }
        if (act[0]==2 && act[1]==2){

                if (act[0]==1){f = mySort(f); f.set(0, f.remove(0) + f.get(0) );}
                if (act[0]==2){
                    Collections.sort(f);
                    f.set(0, f.get(0) * f.remove(f.size()-1));
                    //System.out.println(f.get(0));
                }

                if (act[1]==1){f = mySort(f); f.set(0, f.remove(0) + f.get(0) );}
                if (act[1]==2){
                    Collections.sort(f);
                    f.set(0, f.remove(0) * f.get(0));
                }

                if (act[2]==1){f.set(0, f.get(0) + f.remove(1) );}
                if (act[2]==2){
                    Collections.sort(f);
                    f.set(0, f.get(0) * f.remove(1));
                }
        }

        if (act[0]==2 && act[2]==2){

            Collections.sort(f);
            f.set(1, f.get(1) * f.remove(2));

            if (act[1]==1){f = mySort(f); f.set(0, f.remove(0) + f.get(0) );}
            if (act[1]==2){
                Collections.sort(f);
                f.set(0, f.remove(0) * f.get(0));
            }
            Collections.sort(f);
            f.set(0, f.get(0) * f.remove(1));
        }
        return f.get(0);
    }
    public static ArrayList<Long> mySort(ArrayList<Long>A){
        ArrayList<Long> G = new ArrayList<Long>();
        Collections.sort(A);
        while (A.size()!=0){
            G.add( A.remove(A.size()-1) );
        }
//      for (int i = 0; i<G.size(); i++){
//          System.out.println(G.get(i));
//      }
        return G;
    }
}
// by Ronex)


**
 * Created by IntelliJ IDEA.
 * User: Taras_Brzezinsky
 * Date: 8/29/11
 * Time: 6:02 PM
 * To change this template use File | Settings | File Templates.
 */

import com.sun.corba.se.spi.activation._LocatorImplBase;
import sun.security.krb5.EncryptedData;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.io.IOException;
import java.util.*;

public class TaskB extends Thread {
    public TaskB() {
        this.input = new BufferedReader(new InputStreamReader(System.in));
        this.output = new PrintWriter(System.out);
        this.setPriority(Thread.MAX_PRIORITY);
    }

    static long go(long[] what, boolean []types, int where) {
        long result = Long.MAX_VALUE;
        if (where == 3) {
            for (long current : what) {
                if (current != -1) {
                    return current;
                }
            }
        }
        for (int i = 0; i < 4; ++i) {
            for (int j = i + 1; j < 4; ++j) {
                if (what[i] != -1 && what[j] != -1) {
                   long l = what[i], r = what[j];
                    if (types[where]) {
                        what[i] = l * r;
                    } else {
                        what[i] = l + r;
                    }
                    what[j] = -1;
                    result = Math.min(result, go(what, types, where + 1));
                    what[i] = l;
                    what[j] = r;
                }
            }
        }
        return result;
    }

    private void solve() throws Throwable {
        long[] numbers = new long[4];
        for (int i = 0; i < 4; ++i) {
            numbers[i] = nextLong();
        }
        boolean[] types = new boolean[3];
        for (int i = 0; i < 3; ++i) {
            types[i] =  nextToken().charAt(0) == '*';
        }
        output.println(go(numbers,types, 0));
    }

    public void run() {
        try {
            solve();
        } catch (Throwable e) {
            System.err.println(e.getMessage());
            e.printStackTrace();
            System.exit(666);
        } finally {
            output.flush();
            output.close();
        }
    }

    public static void main(String[] args) {
        new TaskB().start();
    }

    private int nextInt() throws IOException {
        return Integer.parseInt(nextToken());
    }

    private long nextLong() throws IOException {
        return Long.parseLong(nextToken());
    }

    private double nextDouble() throws IOException {
        return Double.parseDouble(nextToken());
    }

    private String nextToken() throws IOException {
        while (tokens == null || !tokens.hasMoreTokens()) {
            tokens = new StringTokenizer(input.readLine());
        }
        return tokens.nextToken();
    }

    Set<Integer> numbers = new TreeSet<Integer>();
    private BufferedReader input;
    private PrintWriter output;
    private StringTokenizer tokens = null;
}


        import java.util.*;
        import java.math.*;
        import java.io.*;
        import java.text.DecimalFormat;
        import java.math.BigInteger;
        public class Main{
            static int d=20,n;
            static int mod=1000000007 ;
            static HashMap<String,Integer> hm=new HashMap<>();
            public static void main(String[] args)  throws IOException {
                s.init(System.in);

                PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
                int n,x;
                n=s.ni();
                x=s.ni();
                int ans=0;
                double sub=1e-19;
                double[] glass=new double[(n*(n+1))/2];
                int id=0;

                glass[id]=x;
                for(int row=1;row<=n && x!=0.0;row++){
                    for(int col=1;col<=row;col++,id++){
                        x=glass[id];
                        glass[id]=(x>=1.0)?1.0:x;
                        x=(x>=(1.0-sub))?((x-1.0)):0.0;
                        if(row==n)
                            continue;
                        glass[id+row]+=x/2;
                        glass[id+row+1]+=x/2;
                    }
                }
                for(int i=0;i<(n*(n+1))/2;i++){
                    if(glass[i]>=(1.0-sub))
                        ans++;
                }
                out.println(ans);

                out.close();
            }

            static class party implements Comparable<party>{
                int size;
                int id;
                public party(int x,int y){
                    id=x;
                    size=y;
                }
                public  int compareTo(party o){
                    return o.size-size;
                }
            }

            public static class s {
                static BufferedReader reader;
                static StringTokenizer tokenizer;

                /** call this method to initialize reader for InputStream */
                static void init(InputStream input) {
                    reader = new BufferedReader(
                                new InputStreamReader(input) );
                    tokenizer = new StringTokenizer("");
                }

                /** get next word */
                static String ns() throws IOException {
                    while ( ! tokenizer.hasMoreTokens() ) {
                        //TODO add check for eof if necessary
                        tokenizer = new StringTokenizer(
                            reader.readLine() );
                    }
                    return tokenizer.nextToken();
                }

                static int ni() throws IOException {
                    return Integer.parseInt( ns() );
                }

                static double nd() throws IOException {
                    return Double.parseDouble( ns() );
                }
                static long nl() throws IOException {
                    return Long.parseLong( ns() );
                }

            }
        }


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class PyramidOfGlasses {

    class Node {
	int liquid;
	int level;
	Node Left, Right;
	boolean counted = false;
	boolean isInner;

	Node(int level, boolean inner){
		this.liquid = 0;
		this.level = level;
		this.Left = null;
		this.Right = null;
		this.isInner = inner;
	}

	boolean isFull(){
		if(level==1) return (liquid==1);
		return ((int)Math.pow(2,(level-1)))==liquid;
	}

	void pour(){
		if(!this.isFull()) liquid++;
		else {
			if(this.Left != null) this.Left.pour();
			if(this.Right != null) this.Right.pour();

		}

	}

	public String toString(){
		return "{ " + liquid + " , " + level + " , " + this.Left + " , " + this.Right + " } ";
	}

	int fullCups(){
		int ret = 0;
		if(this.counted) return ret;
		this.counted = true;

		if(this.Left != null) ret += this.Left.fullCups();
		if(this.Right != null) ret += this.Right.fullCups();
		if(this.isFull()){ ret++; }
		return ret;
	}
}

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st = new StringTokenizer(br.readLine());

		int n = Integer.parseInt(st.nextToken());
		int t = Integer.parseInt(st.nextToken());

		Node[][] pyramid = new Node[n+1][];
		for(int i=(n-1); i>=0; i--) {
			Node[] lvl = new Node[i+1];
			pyramid[i] = lvl;

			for(int j=0; j<lvl.length; j++) lvl[j] = new Node(i+1, ((j!=0)&&(j!=(lvl.length-1))));

			if(i==(n-1)) continue;

			Node[] nextLvl = pyramid[i+1];

			lvl[0].Left = nextLvl[0];
			lvl[lvl.length-1].Right = nextLvl[nextLvl.length-1];

			for(int k=0; k<lvl.length-1; k++) {
				lvl[k].Right = nextLvl[k+1];
				lvl[k+1].Left = nextLvl[k+1];
			}

		}

		for(int s=0; s<t; s++){
			pyramid[0][0].pour();
		}

		System.out.println(pyramid[0][0].fullCups());
		//System.out.println(pyramid[0][0]);
		//System.out.println(pyramid[1][0]);
		//System.out.println(pyramid[1][1]);

	}

}


import java.util.Scanner;
public class mao
{
	public static int pour(double liquid,double[][] glasses,int row,int col)
	{
		if(liquid == 0 || row == glasses.length) return 0;
		if(glasses[row][col] == 1)
		{
			return pour(liquid/2,glasses,row+1,col) + pour(liquid/2,glasses,row+1,col+1);
		}

		glasses[row][col] += liquid
		if(glasses[row][col] >= 1)
		{
			double overflow = glasses[row][col] - 1;
			glasses[row][col] = 1;
			return 1 + pour(overflow/2,glasses,row+1,col) + pour(overflow/2,glasses,row+1,col+1);
		}
		return 0;
	}

	public static void solve()
	{
		Scanner input = new Scanner(System.in);
		int n = input.nextInt();
		int t = input.nextInt();

		if(t >= Math.pow(2,n) - 1)
		{
			System.out.println((n*n + n)/2);
			return;
		}

		if(t <= 1)
		{
			System.out.println(t);
			return;
		}

		int retval = 0;
		double[][] glasses = new double[n][];
		for(int i = 0; i < n; i++) glasses[i] = new double[i+1];
		for(int time = t; time > 0; time--)
		{
			retval += pour(1.0,glasses,0,0);
		}
		System.out.println(retval);
	}

	public static void main(String[] args)
	{
		solve();
	}

}


3 5
import java.io.*;
import java.util.*;
import java.text.*;
import java.math.*;
import java.util.regex.*;

public class Solution {

    public static double[] a;
    public static int[] level;
    public static int n;
    public static int max = 55;

    public static void fill(int i, double cur)
    {
        if(level[i]>n)
            return;
        //System.out.println(i+" "+(cur-(100-a[i])));

        if((cur- (100-a[i]))<=0.1)
        {
            a[i] += cur;
            cur = 0;
            return;
        }
        else
        {
            cur -= (100-a[i]);
            a[i] = 100;
            int c1 = i + level[i];
            int c2 = c1+1;
            if(c1<=55)
            fill(c1, cur/2);
            if(c2<=55)
            fill(c2, cur/2);
        }

    }

 public static void main(String[] args) {

     Scanner in = new Scanner(System.in);
     //BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
     PrintWriter pw = new PrintWriter(System.out);

     n = in.nextInt();
     int t = in.nextInt();

     a = new double[100];
     level = new int[100];
     int tmp = 0;
     //int prev = 0;
     for(int i=1; i<=10; i++)
     {
         for(int j=0; j<i; j++)
             level[tmp++] = i;

     }
    // pw.println(tmp);
     // for(int j=0; j<20; j++)
       //      pw.print(level[j]+" ");

     for(int i=0; i<t; i++)
     {
         double cur = 100;
        fill(0, cur);
        /* for(int j=0; j<10; j++)
             pw.print(a[j]+" "+level[j]+"\t");
         pw.println();
         */

     }

     int count = 0;
     int ans = 0;
     for(int i=0; i<100; i++)
        if(level[i]<=n && a[i]==100)
            ans++;

     pw.print(ans);

     pw.flush();
     pw.close();
   }
}