import java.util.*;

public class E {

    final int N = 100_000;
    final int W = 7;
    final int MOD = 1_000_000_007;

    int[] w;
    int[][] mem;
    int[][][] memG;
    int ans;

    void read() {
        Scanner scanner = new Scanner(System.in);

        int[] t = new int[W];
        int s = 0;

        for (int i = 0; i < t.length; i++) {
            t[i] = scanner.nextInt();
            s += t[i];
        }

        w = new int[s];

        for (int i = 0, j = 0; i < t.length; i++) {
            for (int k = 0; k < t[i]; k++) {
                w[j++] = i + 1;
            }
        }

        scanner.close();
    }

    int calcRealMask(int mask, int pos) {
        int prev = pos == 0 ? 0 : w[pos - 1];
        return mask | (((1 << prev) - 1) ^ ((1 << w[pos]) - 1));
    }

    boolean good(int w, int a, int b, int c) {
        c = (((1 << (w - 1)) | c) << 1) | 1;
        for (int i = 0; i < w; i++) {
            if ((a & (1 << i)) > 0 && (b & (1 << i)) > 0 && (c & (1 << i)) > 0 && (c & (2 << i)) > 0) {
                return false;
            }
        }
        return true;
    }

    int g(int w, int a, int b) {
        if (memG[w][a][b] == 0) {
            int res = 0;

            int n = 1 << (w - 1);
            for (int i = 0; i < n; i++) {
                if (good(w, a, b, i)) {
                    res++;
                }
            }

            memG[w][a][b] = res + 1;
        }
        return memG[w][a][b] - 1;
    }

    long f(int mask, int pos) {
        if (mem[mask][pos] == 0) {
            int realMask = calcRealMask(mask, pos);
            long res = 0;
            int lastMask = 1 << w[pos];

            if (pos == w.length - 1) {
                res = g(w[pos], realMask, lastMask - 1);
            } else {
                for (int i = 0; i < lastMask; i++) {
                    res = (res + g(w[pos], realMask, i) * f(i, pos + 1)) % MOD;
                }
            }

            mem[mask][pos] = (int) res + 1;
        }
        return mem[mask][pos] - 1;
    }

    void solve() {
        mem = new int[1 << w[w.length - 1]][w.length];
        memG = new int[W + 1][1 << W][1 << W];
        ans = f(0, 0);
    }

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

    public static void main(String[] args) {
        E e = new E();
        e.read();
        e.solve();
        e.write();
    }

}


import java.util.*;

public class E {

    final int N = 100_000;
    final int W = 7;
    final int MOD = 1_000_000_007;

    int[][] mem;
    long[][][] memG;
    int[] w;
    int ans;
    boolean memGood[][][][];
    boolean memGood1[][][][];

    void read() {
        Scanner scanner = new Scanner(System.in);

        w = new int[W];

        for (int i = 0; i < w.length; i++) {
            w[i] = scanner.nextInt();
        }

        scanner.close();
    }

    boolean good(int w, int a, int b, int c) {
        if (w < 0) {
            return true;
        }
        if (!memGood1[w][a][b][c]) {
            memGood1[w][a][b][c] = true;
            int x = 1 << w;
            memGood[w][a][b][c] = !((a & x) > 0 && (b & x) > 0 && (c & x) > 0 && (c & (x << 1)) > 0) && good(w - 1, a, b, c);
        }
        return memGood[w][a][b][c];
    }

    long[][] mul(long [][] a, long[][] b) {
        long[][] t = new long[a.length][a.length];

        for (int i = 0; i < a.length; i++) {
            for (int j = 0; j < a.length; j++) {
                for (int k = 0; k < a.length; k++) {
                    t[i][j] = (t[i][j] + a[i][k] * b[k][j]) % MOD;
                }
            }
        }

        return t;
    }

    long[][] pow(long[][] base, int p) {
        long[][] ans = new long[base.length][base.length];
        for (int i = 0; i < ans.length; i++) {
            ans[i][i] = 1;
        }
        for (; p > 0; p >>= 1) {
            if ((p & 1) > 0) {
                ans = mul(ans, base);
            }
            base = mul(base, base);
        }
        return ans;
    }

    long f(int mask, int pos) {
        if (mem[pos][mask] == 0) {
            int realMask = 1 << pos | mask;
            long res = 0;
            int lastMask = 1 << (pos + 1);

            if (pos == w.length - 1) {
                res = memG[pos][realMask][lastMask - 1];
            } else {
                for (int i = 0; i < lastMask; i++) {
                    res = (res + memG[pos][realMask][i] * f(i, pos + 1)) % MOD;
                }
            }

            mem[pos][mask] = (int) res + 1;
        }
        return mem[pos][mask] - 1;
    }

    void solve() {
        mem = new int[W][1 << W];
        memG = new long[W][][];
        memGood = new boolean[W][1 << W + 1][1 << W + 1][1 << W + 2];
        memGood1 = new boolean[W][1 << W + 1][1 << W + 1][1 << W + 2];

        for (int w = 0; w < W; w++) {
            int m = 1 << w + 1;
            long[][] t = new long[m][m];

            for (int i = 0; i < m; i++) {
                for (int j = 0; j < m; j++) {
                    int res = 0;
                    int n = 1 << w;
                    for (int k = 0; k < n; k++) {
                        if (good(w, i, j, ((n | k) << 1) | 1)) {
                            res++;
                        }
                    }
                    t[i][j] = res;
                }
            }

            memG[w] = pow(t, this.w[w]);
        }

        ans = (int) f(0, 0);
    }

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

    public static void main(String[] args) {
        //long time = System.currentTimeMillis();
        E e = new E();
        e.read();
        e.solve();
        e.write();
        //System.out.println(System.currentTimeMillis() - time);
    }

}


package codeforces;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.util.Locale;
import java.util.StringTokenizer;

public class Codeforces_Round_164_b {
	static PrintWriter pw;
	static BufferedReader br;
	static StringTokenizer st;

	static class sort implements Comparable<sort> {
		int x, y;

		public sort(int x, int y) {
			this.x = x;
			this.y = y;
		}

		public int compareTo(sort arg0) {
			if (this.x == arg0.x)
				return (this.y - arg0.y);
			return (this.x - arg0.x);
		}
	}

	public static void main(String[] args) throws IOException {
		Locale.setDefault(Locale.US);
		Doston();
		// Dostonf();
		int n=nextInt();
		long ans=n;
		for (int i = 1; i <=n; i++) {
			ans+=(n-i)*i;
		}
		pw.print(ans);
		pw.close();
	}

	private static void Dostonf() throws IOException {
		br = new BufferedReader(new FileReader(new File("input.txt")));
		pw = new PrintWriter(new BufferedWriter(new FileWriter("output.txt")));
	}

	private static void Doston() throws IOException {
		br = new BufferedReader(new InputStreamReader(System.in));
		pw = new PrintWriter(new BufferedWriter(new OutputStreamWriter(
				System.out)));
	}

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

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

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

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


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

import static java.lang.Math.*;

public class Main implements Runnable
{
	static class InputReader
	{
		private InputStream stream;
		private byte[] buf = new byte[1024];
		private int curChar;
		private int numChars;
		private SpaceCharFilter filter;
		private BufferedReader br=new BufferedReader(new InputStreamReader(System.in));

		public InputReader(InputStream stream)
		{
			this.stream = stream;
		}

		public int read()
		{
			if (numChars==-1)
				throw new InputMismatchException();

			if (curChar >= numChars)
			{
				curChar = 0;
				try
				{
					numChars = stream.read(buf);
				}
				catch (IOException e)
				{
					throw new InputMismatchException();
				}

				if(numChars <= 0)
					return -1;
			}
			return buf[curChar++];
		}

		public String nextLine()
		{
			String str = "";
            try
            {
                str = br.readLine();
            }
            catch (IOException e)
            {
                e.printStackTrace();
            }
            return str;
		}
		public int nextInt()
		{
			int c = read();

			while(isSpaceChar(c))
				c = read();

			int sgn = 1;

			if (c == '-')
			{
				sgn = -1;
				c = read();
			}

			int res = 0;
			do
			{
				if(c<'0'||c>'9')
					throw new InputMismatchException();
				res *= 10;
				res += c - '0';
				c = read();
			}
			while (!isSpaceChar(c));

			return res * sgn;
		}

		public long nextLong()
		{
			int c = read();
			while (isSpaceChar(c))
				c = read();
			int sgn = 1;
			if (c == '-')
			{
				sgn = -1;
				c = read();
			}
			long res = 0;

			do
			{
				if (c < '0' || c > '9')
					throw new InputMismatchException();
				res *= 10;
				res += c - '0';
				c = read();
			}
			while (!isSpaceChar(c));
				return res * sgn;
		}

		public double nextDouble()
		{
			int c = read();
			while (isSpaceChar(c))
				c = read();
			int sgn = 1;
			if (c == '-')
			{
				sgn = -1;
				c = read();
			}
			double res = 0;
			while (!isSpaceChar(c) && c != '.')
			{
				if (c == 'e' || c == 'E')
					return res * Math.pow(10, nextInt());
				if (c < '0' || c > '9')
					throw new InputMismatchException();
				res *= 10;
				res += c - '0';
				c = read();
			}
			if (c == '.')
			{
				c = read();
				double m = 1;
				while (!isSpaceChar(c))
				{
					if (c == 'e' || c == 'E')
						return res * Math.pow(10, nextInt());
					if (c < '0' || c > '9')
						throw new InputMismatchException();
					m /= 10;
					res += (c - '0') * m;
					c = read();
				}
			}
			return res * sgn;
		}

		public String readString()
		{
			int c = read();
			while (isSpaceChar(c))
				c = read();
			StringBuilder res = new StringBuilder();
			do
			{
				res.appendCodePoint(c);
				c = read();
			}
			while (!isSpaceChar(c));

			return res.toString();
		}

		public boolean isSpaceChar(int c)
		{
			if (filter != null)
				return filter.isSpaceChar(c);
			return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
		}

		public String next()
		{
			return readString();
		}

		public interface SpaceCharFilter
		{
			public boolean isSpaceChar(int ch);
		}
	}

	public static void main(String args[]) throws Exception
	{
		new Thread(null, new Main(),"Main",1<<26).start();
	}
	public void run()
	{
		InputReader sc = new InputReader(System.in);
		PrintWriter w = new PrintWriter(System.out);

		StringBuffer s = new StringBuffer("What are you doing at the end of the world? Are you busy? Will you save us?");

        int q = sc.nextInt();
        Queries query[] = new Queries[q];

        for(int i = 0; i < q; ++i)
            query[i] = new Queries(i, sc.nextInt(), sc.nextLong());

        Arrays.sort(query, new Comparator<Queries>() {
            public int compare(Queries q1, Queries q2) {
                if(q1.n > q2.n)
                    return 1;
                if(q1.n < q2.n)
                    return -1;
                return 0;
            }
        });
        int curq = 0;
        char ans[] = new char[q];
        for(int i = 0; i <= 100000; ++i) {
            while(curq < q && query[curq].n == i) {
                if(query[curq].k >= s.length())
                    ans[query[curq].ind] = '.';
                else
                    ans[query[curq].ind] = s.charAt((int)query[curq].k);
                curq++;
            }
            if(curq == q)
                break;
            s = new StringBuffer("What are you doing while sending \"" + s + "\"? Are you busy? Will you send \"" + s + "\"?");
        }

        w.print(ans);

		w.close();
	}
}
class Queries {
    int ind;
    int n;
    long k;
    Queries(int c, int a, long b) {
        ind = c;
        n = a;
        k = b - 1;
    }
}


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

public class C {

    private static final int oo = Integer.MAX_VALUE / 4;

    private void work() {
        Scanner sc = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        n = sc.nextInt();
        int s = sc.nextInt() - 1;
        k = sc.nextInt();

        r = new int[n];
        for (int i = 0; i < n; i++) r[i] = sc.nextInt();
        char[] c = sc.next().toCharArray();
        sc.close();

        deg = new int[n];
        g = new int[n][n];

        for (int i = 0; i < n; i++) {
            for (int j = i + 1; j < n; j++) {
                if (c[i] != c[j]) {
                    if (r[i] < r[j]) g[i][deg[i]++] = j;
                    if (r[i] > r[j]) g[j][deg[j]++] = i;
                }
            }
        }

        memo = new int[n][k];
        for(int i = 0; i < n; i++){
            Arrays.fill(memo[i], - 1);
        }

        for(int i = 0; i < n; i++){
            go(i, r[i]);
        }

        int res = oo;
        for(int i = 0; i < n; i++){
            int t = Math.abs(i - s) + memo[i][r[i]];
            if(t < res) res = t;
        }

        System.out.println(res == oo ? -1 : res);
    }

    private int n, k;
    private int[] r, deg;
    private int[][] g, memo;

    private int go(int u, int candies){
        if(candies >= k){
            return 0;
        }
        if(memo[u][candies] >= 0) return memo[u][candies];

        int ret = oo;
        for(int i = 0; i < deg[u]; i++){
            int v = g[u][i];
            int t = Math.abs(u - v) + go(v, candies + r[v]);
            if(t < ret) ret = t;
        }

        return memo[u][candies] = ret;
    }

    public static void main(String[] args) {
        new C().work();
    }
}


import static java.lang.Math.pow;
import java.util.Scanner;

public class JavaApplication19 {

    public static void main(String[] args) {
   Scanner sc= new Scanner(System.in);
   int  n = sc.nextInt();
    int k = sc.nextInt();
    int x = n+1;
    int x2=1;
        if (k > n)
            System.out.println(k);
        else{
  while(x % k!=0){
      x ++;

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


import java.util.Scanner;

public class ACarrotCakes {

    public static void main(String[] args) {

    Scanner input = new Scanner(System.in);
    int n = input.nextInt();//number of carrots to complete the task
    int t = input.nextInt();//minutes to bake by one oven
    int k = input.nextInt();//num of carrots cake
    int d = input.nextInt();//minutes to build another oven
        int q=0;
            int w=0;
    if(n<=k)
    {
         System.out.println("NO");
    }
    else if(t==d)
    {
         System.out.println("NO");

    }
    else if(n>k)
    {
        while(true)
        {
             q+=t;
             w+=k;
            if(w==n){break;}
        }
        if(t+d<q){System.out.println("YES");}
        else{System.out.println("NO");}
    }

    }

}


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;
import java.util.HashMap;
import java.util.Collections;
import java.util.ArrayList;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author Nurlan Sofiyev
 */
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);
        TaskC solver = new TaskC();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskC {
        public HashMap<String, Team> hm;
        public ArrayList<Team> teams;

        public void add(String name, int goal, int missed) {

            if (hm.containsKey(name)) {
                hm.get(name).update(goal, missed);
            } else {
                hm.put(name, new Team(name, goal, missed));
            }
        }

        public void solve(int testNumber, Scanner in, PrintWriter out) {

            hm = new HashMap<>();

            for (int i = 0; i < 5; ++i) {
                String A, B;
                int a, b;
                A = in.next();
                B = in.next();
                String[] temp = in.next().split(":");
                a = Integer.parseInt(temp[0]);
                b = Integer.parseInt(temp[1]);
                add(A, a, b);
                add(B, b, a);

            }
            teams = new ArrayList<>(hm.values());
            Collections.sort(teams);
            int current = 3;
            Team berland = teams.get(3);
            Team other = teams.get(3);
            String s_other;
            for (int i = 0; i < 3; ++i) {
                if (teams.get(i).name.equals("BERLAND")) {
                    current = i;
                    berland = teams.get(i);
                } else if (teams.get(i).played == 2) {
                    other = teams.get(i);
                }
            }

            s_other = other.name;

            if (berland.point + 3 < teams.get(1).point) {
                out.println("IMPOSSIBLE");
                return;
            }

            for (int diff = 1; diff <= 20; ++diff) {
                for (int goals = diff; goals <= 20; ++goals) {
                    int mis = goals - diff;
                    berland.update(goals, mis);
                    other.update(mis, goals);
                    Collections.sort(teams);
                    for (int i = 0; i < 2; ++i) {
                        if (teams.get(i).name.equals("BERLAND")) {
                            out.println(goals + ":" + mis);
                            return;
                        }

                    }
                    berland.backup();
                    other.backup();
                }
            }

            out.println("IMPOSSIBLE");

        }

        class Team implements Comparable<Team> {
            public String name;
            public int played;
            public int point;
            public int goals;
            public int missed;
            public int t_point;
            public int t_goals;
            public int t_missed;

            public void backup() {
                goals -= t_goals;
                missed -= t_missed;
                point -= t_point;
            }

            public String toString() {
                return (name + "   " + point + "   " + goals + "   " + missed);
            }

            public void update(int goals, int missed) {
                if (goals > missed) {
                    point += 3;
                    t_point = 3;
                } else if (goals == missed) {
                    point += 1;
                    t_point = 1;
                } else {
                    t_point = 0;
                }
                this.goals += goals;
                this.missed += missed;
                t_goals = goals;
                t_missed = missed;
                ++played;

            }

            public Team(String name, int goals, int missed) {
                this.name = name;
                update(goals, missed);
            }

            public Team() {

            }

            public int hashCode() {
                return name.hashCode();
            }

            public boolean equals(Object obj) {
                return name.equals(obj);
            }

            public int compareTo(Team o) {
                int temp = o.point - point;
                if (temp != 0) {
                    return temp;
                }
                temp = (o.goals - o.missed) - (goals - missed);
                if (temp != 0) {
                    return temp;
                }
                temp = (o.goals - goals);
                if (temp != 0) {
                    return temp;
                }

                return name.compareTo(o.name);

            }

        }

    }

    static
    @Documented
    @Retention(RetentionPolicy.CLASS)
    @Target({ElementType.METHOD, ElementType.FIELD, ElementType.PARAMETER, ElementType.LOCAL_VARIABLE})
    interface NotNull {
    }
}


// Author @ BlackRise :) //
// Birla Institute of Technology, Mesra//
import java.io.*;
import java.util.*;

public class maths {

    static void Blackrise() {                                                //The name Blackrise is my pen name... you can change the name according to your wish

        long n=ni();

        tsc();                                                               //calculates the starting time of execution

        int c=0,increment=0,minimizable=1;
        while(minimizable==1)
        {
            for(int i=1;i<=n;i++)
            {
                double sqrt=Math.sqrt(n*i);
                double sqrt1=(long)sqrt;
                //pl(sqrt+" "+sqrt1);
                if(sqrt==sqrt1)
                {
                    //pl(i);
                    if(i==n)
                    {
                        minimizable=0;
                        break;
                    }
                    if(i>1)
                    {
                        increment=1;
                    }
                    n=(long)Math.sqrt(n*i);c++;break;
                }
            }
        }
        if(increment==1)c++;
        pl(n+" "+c);

        tec();                  //calculates the ending time of execution
        /pwt();                //prints the time taken to execute the program
    }

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

    static Calendar ts, te;                                                  //For time calculation
    static int mod9 = (int) 1e9 + 7;
    static Lelo input = new Lelo(System.in);
    static PrintWriter pw = new PrintWriter(System.out, true);

    public static void main(String[] args) {                                 //threading has been used to increase the stack size.

        new Thread(null, null, "BlackRise", 1<<25)  //the last parameter is stack size which is desired,
        {
            public void run() {

                try {
                    Blackrise();
                } catch (Exception e) {
                    e.printStackTrace();
                    System.exit(1);
                }
            }
        }.start();
    }

    static class Lelo {                                              //Lelo class for fast input
        private InputStream ayega;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;
        private SpaceCharFilter filter;

        public Lelo(InputStream ayega) {
            this.ayega = ayega;
        }

        public int read() {
            if (numChars == -1)
                throw new InputMismatchException();

            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = ayega.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }

                if (numChars <= 0)
                    return -1;
            }
            return buf[curChar++];
        }

        public String nextLine() {
            BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }

        public int nextInt() {
            int c = read();

            while (isSpaceChar(c))
                c = read();

            int sgn = 1;

            if (c == '-') {
                sgn = -1;
                c = read();
            }

            int res = 0;
            do {
                if (c < '0' || c > '9')
                    throw new InputMismatchException();
                res *= 10;
                res += c - '0';
                c = read();
            }
            while (!isSpaceChar(c));

            return res * sgn;
        }

        public long nextLong() {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            long res = 0;

            do {
                if (c < '0' || c > '9')
                    throw new InputMismatchException();
                res *= 10;
                res += c - '0';
                c = read();
            }
            while (!isSpaceChar(c));
            return res * sgn;
        }

        public double nextDouble() {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            double res = 0;
            while (!isSpaceChar(c) && c != '.') {
                if (c == 'e' || c == 'E')
                    return res * Math.pow(10, nextInt());
                if (c < '0' || c > '9')
                    throw new InputMismatchException();
                res *= 10;
                res += c - '0';
                c = read();
            }
            if (c == '.') {
                c = read();
                double m = 1;
                while (!isSpaceChar(c)) {
                    if (c == 'e' || c == 'E')
                        return res * Math.pow(10, nextInt());
                    if (c < '0' || c > '9')
                        throw new InputMismatchException();
                    m /= 10;
                    res += (c - '0') * m;
                    c = read();
                }
            }
            return res * sgn;
        }

        public String readString() {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            StringBuilder res = new StringBuilder();
            do {
                res.appendCodePoint(c);
                c = read();
            }
            while (!isSpaceChar(c));

            return res.toString();
        }

        public boolean isSpaceChar(int c) {
            if (filter != null)
                return filter.isSpaceChar(c);
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        public String next() {
            return readString();
        }

        public interface SpaceCharFilter {
            public boolean isSpaceChar(int ch);
        }
    }

    // functions to take input//
    static int ni() {
        return input.nextInt();
    }

    static long nl() {
        return input.nextLong();
    }

    static double nd() {
        return input.nextDouble();
    }

    static String ns() {
        return input.readString();
    }

    //functions to give output
    static void pl() {
        pw.println();
    }

    static void p(Object o) {
        pw.print(o + " ");
    }

    static void pws(Object o){
        pw.print(o+"");
    }

    static void pl(Object o) {
        pw.println(o);
    }

    static void tsc()                                          //calculates the starting time of execution
    {
        ts = Calendar.getInstance();
        ts.setTime(new Date());
    }

    static void tec()                                          //calculates the ending time of execution
    {
        te = Calendar.getInstance();
        te.setTime(new Date());
    }

    static void pwt()                                          //prints the time taken for execution
    {
        pw.printf("\nExecution time was :- %f s\n", (te.getTimeInMillis() - ts.getTimeInMillis()) / 1000.00);
    }
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
public class D
{
    public static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    public static StringTokenizer inp;
    public static void main(String[] args)  throws IOException
    {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

        int ln[] = new int[1026];
        ln[0] = 0 ; ln[1023] = 2000000000;
        int ind = 1;
        for(int i = 2 ; i < 1024 ; i++)
        {
            char s[] = Integer.toBinaryString(i).toCharArray();
            for(int j = 1 ; j < s.length ; j++) s[j] = (s[j]=='0'?'4':'7');
            ln[ind++] = Integer.parseInt(String.valueOf(s).substring(1));
        }
        inp = new StringTokenizer(br.readLine());
        int pl = nextInt(),pr = nextInt() , vl=nextInt() , vr = nextInt() , k = nextInt();
        long ans = 0;
        int l = 1, r = k;
        for(; r <= 1022 ; r++,l++)
        {
            if(vl>ln[l])continue;
            if(ln[r] > pr || ln[l-1] > vr)break;
            ans+=(long)Math.max(0, (Math.min(ln[l], vr)- Math.max(vl, ln[l-1]+1) + 1))*Math.max(0, (Math.min(pr, ln[r+1]-1)- Math.max(ln[r], pl) + 1));
        }
        l=1;r=k;
        for(; r <= 1022 ; r++,l++)
        {
            if(pl>ln[l])continue;
            if(ln[r] > vr || ln[l-1] > pr)break;
            ans+=(long)Math.max(0, (Math.min(ln[l], pr)- Math.max(pl, ln[l-1]+1) + 1))*Math.max(0, (Math.min(vr, ln[r+1]-1)- Math.max(ln[r], vl) + 1));
        }
        double res = (double)(ans)/((long)(pr-pl+1)*(vr-vl+1));
        System.out.printf("%.12f\n",Math.min(res, 1.0));
    }

    public static int nextInt(){return Integer.parseInt(inp.nextToken());}
    public static long nextLong(){return Long.parseLong(inp.nextToken());}
    public static double nextDouble(){return Double.parseDouble(inp.nextToken());}

}


// Working program with FastReader
import java.io.*;
import java.util.*;
import java.text.*;
import java.math.*;

public class Main1
{
	static class FastReader
	{
		BufferedReader br;
		StringTokenizer st;

		public FastReader()
		{
			br = new BufferedReader(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 nextLine()
		{
			String str = "";
			try
			{
				str = br.readLine();
			}
			catch (IOException e)
			{
				e.printStackTrace();
			}
			return str;
		}
	}

	public static void main(String[] args)
	{
		FastReader s=new FastReader();
		int n1=s.nextInt();
		String n=s.nextLine();
		long c=0;
		for(int i=0;i<n1;i++)
		{
		    if(n.charAt(i)==n.charAt(i+1))
		    c++;
		}

		if(c==n1)
		System.out.println(c-1);
		else
		System.out.println(c);

	}
}


		import java.io.*;
		import java.util.*;
		public class Sample {
		    static int MAX = (int)2e5+1;
		    static int MOD=(int)1e9+7;
		    static int countt = 0;
			public static void main(String[] args) throws Exception{
				// TODO Auto-generated method stub
				//BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
				Scanner input  = new Scanner(System.in);
				int n = input.nextInt();
				int aSize = input.nextInt();
				int a[] = new int[aSize];
				ArrayList<Integer> tempA = new ArrayList<>();
				ArrayList<Integer> tempB = new ArrayList<>();
				for(int i =0;i<aSize;i++) {a[i] = input.nextInt();tempA.add(a[i]);}
				int bSize = input.nextInt();
				int b[] = new int[bSize];
				for(int i =0;i<bSize;i++) {b[i] = input.nextInt();tempB.add(b[i]);}
				int count =0;

				boolean ok = false;
				int winner = 1;
				while(true) {
					if(tempA.size() == 0 || tempB.size() == 0) {
						winner = tempA.size() == 0?2:1;
						ok = true;
						break;
					}
					if(check(tempA,tempB,a,b) && count != 0)break;

					int t1 = tempA.remove(0);
					int t2 = tempB.remove(0);

					if(t2>t1) {
						tempB.add(t1);
						tempB.add(t2);
					}else {

						tempA.add(t2);
						tempA.add(t1);

					}

					count++;

				}
				if(ok) {
					System.out.println(count+" "+winner);
				}else System.out.println(-1);
			}
			public static boolean check(ArrayList<Integer>lista,ArrayList<Integer>listb,int a[],int b[]) {
				for(int i =0;i<lista.size();i++) {
					if(a[i] != lista.get(i))return false;
				}
				for(int i =0;i<listb.size();i++) {
					if(b[i] != listb.get(i))return false;
				}
				return true;
			}
			public static boolean check(long val) {
				long v = 1;
				countt = 0;
				while(true) {
					if(v>=val)break;
					v*=2;
					countt++;
				}
				return v == val;
			}
			public static void sort(long arr[]) {
				ArrayList<Long>list = new ArrayList<>();
				for(long it:arr)list.add(it);
				Collections.sort(list);
				for(int i =0;i<arr.length;i++)arr[i] = list.get(i);
			}
			public static boolean check(int arr[],int curr) {

				for(int i =0;i<arr.length;i++) {
					if(arr[i] != curr)return false;
				}
				return true;
			}

		}


   			/*
    		     * Author- Priyam Vora
    		     * BTech 2nd Year DAIICT
    		     */

    		    import java.io.*;
    		    import java.math.*;
    		    import java.util.*;
import java.util.concurrent.ConcurrentHashMap;

import javax.print.attribute.SetOfIntegerSyntax;

    		    public class Practice{
    		    	private static InputStream stream;
    		    	private static byte[] buf = new byte[1024];
    		    	private static int curChar;
    		    	private static int numChars;
    		    	private static SpaceCharFilter filter;
    		    	private static PrintWriter pw;
    		    	private static long count = 0,mod=1000000007;
    		    //	private static TreeSet<Integer> ts=new TreeSet[200000];

    		        public static void main(String[] args) {
    		        	InputReader(System.in);
    		    		pw = new PrintWriter(System.out);
    		            new Thread(null ,new Runnable(){
    		               public void run(){
    		                   try{
    		                       soln2();
    		                       pw.close();
    		                   } catch(Exception e){
    		                       e.printStackTrace();
    		                   }
    		               }
    		           },"1",1<<26).start();
    		       }

    		    	public static long gcd(long x, long y) {
    		    		if (x == 0)
    		    			return y;
    		    		else
    		    			return gcd( y % x,x);
    		    	}
    		    	public static String reverseString(String s) {
    		    		StringBuilder sb = new StringBuilder(s);
    		    		sb.reverse();
    		    		return (sb.toString());
    		    	}

    		    	public static long pow(long n, long p) {
    		    		if(p==0)
    		    			return 1;
    		    		if(p==1)
    		    			return n%10;
    		    		if(p%2==0){
    		    			long temp=pow(n, p/2);
    		    		return (temp*temp)%10;
    		    		}else{
    		    			 	long temp=pow(n,p/2);
    		    			 	temp=(temp*temp)%10;
    		    			 	return(temp*n)%10;

    		    		}
    		    	}

    		    	public static boolean isPrime(int n) {
    		    		// Corner cases
    		    		if (n <= 1)
    		    			return false;
    		    		if (n <= 3)
    		    			return true;

    		    		// This is checked so that we can skip
    		    		// middle five numbers in below loop
    		    		if (n % 2 == 0 || n % 3 == 0)
    		    			return false;

    		    		for (int i = 5; i * i <= n; i = i + 6)
    		    			if (n % i == 0 || n % (i + 2) == 0)
    		    				return false;

    		    		return true;
    		    	}

    		    	// To Get Input
    		    	// Some Buffer Methods

    		    	public static void InputReader(InputStream stream1) {
    		    		stream = stream1;
    		    	}

    		    	private static boolean isWhitespace(int c) {
    		    		return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
    		    	}

    		    	private static boolean isEndOfLine(int c) {
    		    		return c == '\n' || c == '\r' || c == -1;
    		    	}

    		    	private static int read() {
    		    		if (numChars == -1)
    		    			throw new InputMismatchException();
    		    		if (curChar >= numChars) {
    		    			curChar = 0;
    		    			try {
    		    				numChars = stream.read(buf);
    		    			} catch (IOException e) {
    		    				throw new InputMismatchException();
    		    			}
    		    			if (numChars <= 0)
    		    				return -1;
    		    		}
    		    		return buf[curChar++];
    		    	}

    		    	private static int nextInt() {
    		    		int c = read();
    		    		while (isSpaceChar(c))
    		    			c = read();
    		    		int sgn = 1;
    		    		if (c == '-') {
    		    			sgn = -1;
    		    			c = read();
    		    		}
    		    		int res = 0;
    		    		do {
    		    			if (c < '0' || c > '9')
    		    				throw new InputMismatchException();
    		    			res *= 10;
    		    			res += c - '0';
    		    			c = read();
    		    		} while (!isSpaceChar(c));
    		    		return res * sgn;
    		    	}

    		    	private static long nextLong() {
    		    		int c = read();
    		    		while (isSpaceChar(c))
    		    			c = read();
    		    		int sgn = 1;
    		    		if (c == '-') {
    		    			sgn = -1;
    		    			c = read();
    		    		}
    		    		long res = 0;
    		    		do {
    		    			if (c < '0' || c > '9')
    		    				throw new InputMismatchException();
    		    			res *= 10;
    		    			res += c - '0';
    		    			c = read();
    		    		} while (!isSpaceChar(c));
    		    		return res * sgn;
    		    	}

    		    	private static String nextToken() {
    		    		int c = read();
    		    		while (isSpaceChar(c))
    		    			c = read();
    		    		StringBuilder res = new StringBuilder();
    		    		do {
    		    			res.appendCodePoint(c);
    		    			c = read();
    		    		} while (!isSpaceChar(c));
    		    		return res.toString();
    		    	}

    		    	private static String nextLine() {
    		    		int c = read();
    		    		while (isSpaceChar(c))
    		    			c = read();
    		    		StringBuilder res = new StringBuilder();
    		    		do {
    		    			res.appendCodePoint(c);
    		    			c = read();
    		    		} while (!isEndOfLine(c));
    		    		return res.toString();
    		    	}

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

    		    	private static int[][] next2dArray(int n, int m) {
    		    		int[][] arr = new int[n][m];
    		    		for (int i = 0; i < n; i++) {
    		    			for (int j = 0; j < m; j++) {
    		    				arr[i][j] = nextInt();
    		    			}
    		    		}
    		    		return arr;
    		    	}
    		    	private static char[][] nextCharArray(int n,int m){
    		    		char [][]c=new char[n][m];
    		    		for(int i=0;i<n;i++){
    		    			String s=nextLine();
    		    			for(int j=0;j<s.length();j++){
    		    				c[i][j]=s.charAt(j);
    		    			}
    		    		}
    		    		return c;
    		    	}

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

    		    	private static void pArray(int[] arr) {
    		    		for (int i = 0; i < arr.length; i++) {
    		    			pw.print(arr[i] + " ");
    		    		}
    		    		pw.println();
    		    		return;
    		    	}

    		    	private static void pArray(long[] arr) {
    		    		for (int i = 0; i < arr.length; i++) {
    		    			pw.print(arr[i] + " ");
    		    		}
    		    		pw.println();
    		    		return;
    		    	}

    		    	private static void pArray(boolean[] arr) {
    		    		for (int i = 0; i < arr.length; i++) {
    		    			pw.print(arr[i] + " ");
    		    		}
    		    		pw.println();
    		    		return;
    		    	}

    		    	private static boolean isSpaceChar(int c) {
    		    		if (filter != null)
    		    			return filter.isSpaceChar(c);
    		    		return isWhitespace(c);
    		    	}

    		    	private interface SpaceCharFilter {
    		    		public boolean isSpaceChar(int ch);
    		    	}

     		       static boolean Visited[][];
     		       static int level[][];
     		       private static void soln2(){

     		    	   int n=nextInt();
     		    	   int m=nextInt();
     		    	   int i=nextInt();
     		    	   int j=nextInt();
     		    	   int a=nextInt();
     		    	   int b=nextInt();
     		    	   Visited= new boolean[n][m];
     		    	   level=new int[n][m];
     		    	   BFS(i-1,j-1,a,b,n,m);
     		       }
     		       private static void BFS(int s,int e,int a,int b,int n,int m){
     		    	   Queue<Pair> q=new LinkedList<Pair>();
     		    	   q.add(new Pair(s,e));
     		    	   while(!q.isEmpty()){
     		    		   Pair temp=q.poll();
     		    		   int x=temp.start;
     		    		   int y=temp.end;
     		    		   Visited[x][y]=true;
     		    		   if(x==0 && y==0){
     		    			   pw.println(level[x][y]);
     		    			   return;
     		    		   }
     		    		   if(x==0 && y==m-1){
     		    			   pw.println(level[x][y]);
     		    			   return;

     		    		   }
     		    		   if(x==n-1 && y==0){
     		    			   pw.println(level[x][y]);
     		    			   return;

     		    		   }
     		    		   if(x==n-1 && y==m-1){
     		    			   pw.println(level[x][y]);
     		    			   return;

     		    		   }
     		    		   if(check(x-a,y-b,n,m) && !Visited[x-a][y-b]){
     		    			   q.add(new Pair(x-a,y-b));
     		    			   level[x-a][y-b]=level[x][y]+1;
     		    			   Visited[x-a][y-b]=true;
     		    		   }
     		    		  if(check(x+a,y-b,n,m) && !Visited[x+a][y-b]){
    		    			   q.add(new Pair(x+a,y-b));
    		    			   level[x+a][y-b]=level[x][y]+1;
    		    			   Visited[x+a][y-b]=true;
     		    		  }
     		    		 if(check(x-a,y+b,n,m) && !Visited[x-a][y+b]){
   		    			   q.add(new Pair(x-a,y+b));
   		    			   level[x-a][y+b]=level[x][y]+1;
   		    			  Visited[x-a][y+b]=true;
     		    		 }
     		    		if(check(x+a,y+b,n,m) && !Visited[x+a][y+b]){
  		    			   q.add(new Pair(x+a,y+b));
  		    			   level[x+a][y+b]=level[x][y]+1;
  		    			  Visited[x+a][y+b]=true;
     		    		}

     		    	   }
     		    	   pw.println("Poor Inna and pony!");
     		       }
     		       private static boolean check(int x,int y,int n,int m){
     		    	   if(x>=0 && x<n && y>=0 && y<m){
     		    		   return true;
     		    	   }
     		    	   return false;
     		       }

    		    }
    		    class Node{
    		    	int val;
    		    	int ind;

    		    	Node(int val,int ind){
    		    		this.val=val;
    		    		this.ind=ind;
    		    	}

    		    }

    		    class Pair implements Comparable<Pair>{

        				int start,end;
        				Pair(int start,int end){
        				this.start=start;
        				this.end=end;
        				}
    					@Override
    					public int compareTo(Pair o) {

    					return 0;
    					}

    			/*	public int hashCode() {
					//	return 0;
    	    			int hu = (int) (row ^ (row >>> 32));
    	    			int hv = (int) (col ^ (col >>> 32));
    	    			return 31 * hu + hv;
    	    		}
    				public boolean equals(Object o) {
    	    			Pair other = (Pair) o;
    	    		return row == other.row && col == other.col;
    	    		}
    		*/
    		    	}
    		        class Graph{
    		        	private static int V,level[][],count=-1,lev_dfs[],degree=0,no_vert_conn_comp=0;
    		        	private Stack <Integer>st=new Stack();
    		        	private static LinkedList<Integer > adj[];
    		        	private boolean[][] Visite;
    		        	private static boolean [] Visited;
    		        	private static HashSet<Integer> Vis=new HashSet();
    		        	private static Stack<Integer> topo_sort=new Stack<>();
    		        	private static HashMap<String,Integer> hm=new HashMap<>();
    		  private static HashSet<String> hs=new HashSet();
    		private static HashSet<String > exist=new HashSet();
    		private static int a[];

    		    Graph(int V){
    		    V++;
    		    this.V=(V);
    		    adj=new LinkedList[V];
    		    Visite=new boolean[100][100];

    	 	    Visited=new boolean[V];
    		    level=new int[100][100];
    		    lev_dfs=new int[V];
    		   for(int i=0;i<V;i++)
    			   adj[i]=new LinkedList<Integer>();
    		a=new int[V+1];
    		    }

    		    void setup(int d[]){

    		    	a=Arrays.copyOf(d, d.length);

    		    }
    		    void ans(){
    		    	StringBuilder sb=new StringBuilder();
    		    	for(int i=1;i<a.length;i++){
    		    		sb.append(a[i]+" ");
    		    	}
    		    	System.out.println(sb);
    		    }
    		   void addEdge(int v,int w){

    		    	if(adj[v]==null){
    		    		adj[v]=new LinkedList();
    		    	}
    		    	adj[v].add(w);

    		    }

    		    public static int BFS2(int startVert){
    		    	Visited=new boolean[V];
    		    	for(int i=1;i<V;i++){
    		    		lev_dfs[i]=-1;
    		    	}
    		    //	System.out.println(startVert);
    		    	Queue<Integer> q=new LinkedList<Integer>();
    		    	q.add(startVert);

    		    	lev_dfs[startVert]=0;
    		    	while(!q.isEmpty()){
    		    		int top=q.poll();

    		    		Iterator<Integer> i= adj[top].listIterator();
    		    		while(i.hasNext()){
    		    			int n=i.next();
    		    	//		System.out.println(top+" "+n);
    		    			if(!Visited[n]){
    		    				q.add(n);
    		    				Visited[n]=true;
    		    				lev_dfs[n]=lev_dfs[top]+1;

    		    			}
    		    		}
    		    	}

    		    //	q.clear();
    		    	return -1;
    		    }
    		    public static int getAn(){
    		    	if(ans==Long.MAX_VALUE)
    		    		ans=-1;
    		    	return 0;
    		    }
    		    public int getEd(){
    		    	return degree/2;
    		    }
    		    public void get(int from,int to){
    		    	int h=lev_dfs[from]-lev_dfs[to];
    		    	if(h<=0){
    		    		System.out.println(-1);
    		    	}else{
    		    		System.out.println(h-1);
    		    	}
    		    }
    		    private static boolean check(int x,int y,char c[][]){

    				if((x>=0 && y>=0) && (x<c.length && y<c[0].length) && c[x][y]!='#'){

    					return true;
    				}
    				return false;
    			}
    		    public int BFS(int x,int y,int k,char[][] c)
    		    {
    		    	 LinkedList<Pair> queue = new LinkedList<Pair>();
    		        //Visited[s]=true;
    		   //     queue.add(new Pair(x,y));
    		       int count=0;
    		   level[x][y]=-1;
    		   c[x][y]='M';
    		        while (!queue.isEmpty())
    		        {
    		            Pair temp = queue.poll();

    		        }
    		        return V;
    		    }
    		    static long ans=Long.MAX_VALUE;

    		   public static void dfs2(int startVert,int endVert,long need){
    			Visited[startVert]=true;
    			//System.out.println(startVert+" "+need);
    			   for(int x:adj[startVert]){
    				if(x==endVert ){
    					String to="";
    					to+=startVert+" "+x;

    					if(hs.contains(to) && startVert!=x)
    					ans=Math.min(need+1, ans);
    					else
    						ans=Math.min(need, ans);
    				}
    				else{
    					String to="";
    					to+=startVert+" "+x;
    					boolean tmp=false;
    					if(hs.contains(to) )
    						tmp=true;
    					if(!Visited[x])
    					{
    					if(tmp)
    						dfs2(x, endVert, need+1);
    					else{
    						dfs2(x, endVert, need);
    					}
    					}
    					}
    			}

    		   }
    		     public long dfs(int startVertex){
    		    //	 getAns(startVertex);
    		    	 if(!Visited[startVertex])  {

    		   return dfsUtil(startVertex);

    		    	//return getAns();
    		    	}

    		    return 0;
    		    	}
    		 private long dfsUtil(int startVertex) {//0-Blue 1-Pink
    			 int c=1;
    		TreeSet<Integer> index=new TreeSet();
    		TreeSet<Integer> ele=new TreeSet(Collections.reverseOrder());
    			 long cout=0;
    		      degree=0;
    		    	Visited[startVertex]=true;
    		    	lev_dfs[startVertex]=0;
    		      st.push(startVertex);
    		      int temp=-1;
    		    	    while(!st.isEmpty()){

    		    	int top=st.pop();
    		    //	ts.add(top);
    		    	Iterator<Integer> i=adj[top].listIterator();

      		      index.add(top);
      		      ele.add(a[top]);
    		    while(i.hasNext()){
    		    //	System.out.println(top);
    		    	int n=i.next();
    		     if( !Visited[n]){
    		    				Visited[n]=true;
    		    				st.push(n);
    		    c++;
    		     }
    		         }
    		 }
    		    	   for(int x:index){
    		    		   a[x]=ele.first();
    		    		   ele.remove(ele.first());
    		    	  }

    		 //   System.out.println(temp);
    		    return 0;
    		    }

    		        }

    		    class Dsu{
    		    	private int rank[], parent[] ,n;
    		    	private static int[] parent1;
    		    	Dsu(int size){
    		    		this.n=size+1;
    		    		rank=new int[n];
    		    		//parent=new int[n];
    		    		parent=new int[n];
    		    	makeSet();

    		    	}

    		    	void makeSet(){
    		    		for(int i=0;i<n;i++){
    		    			parent[i]=i;
    		    		}
    		    	}

    		    	int find(int x){
    		    		if(parent[x]!=x){

    		    			parent[x]=find(parent[x]);
    		    		}
    		    		return parent[x];
    		    	}

    		    	void union(int x,int y){
    		    		int xRoot=find(x);
    		    		int yRoot=find(y);

    		    		if(xRoot==yRoot)
    		    			return;
    		    		if(rank[xRoot]<rank[yRoot]){
    		    		parent[xRoot]=yRoot;
    		    		}else if(rank[yRoot]<rank[xRoot]){
    		    			parent[yRoot]=xRoot;
    		    		}else{
    		    			parent[yRoot]=xRoot;
    		    			rank[xRoot]++;
    		    		}

    		    	}

    		    }


import java.util.*;
import java.io.*;
import java.math.*;
import java.math.BigInteger;
import java.text.DecimalFormat;
 public class Tester {
	static long sum=0,sum1=Long.MAX_VALUE;
	//DecimalFormat df = new DecimalFormat("#.#####");
	public static final int MOD = (int) (1e9 + 7);
	public static void main(String args[])
	{
		InputReader in = new InputReader(System.in);
		OutputStream outputStream = System.out;
		PrintWriter out = new PrintWriter(outputStream);
		int x=in.nextInt();
		int y=in.nextInt();
		int a=in.nextInt();
		int b=in.nextInt();
		int count=0;
		while(true)
		{
		if(x!=a&&y!=b)
		{
			if(x<a)
			{
				x++;
			}
			else
			{
				x--;
			}
			if(y<b)
			{
				y++;
			}
			else
			{
				y--;
			}
			count++;
		}
		else if(x!=a)
		{
			if(x<a)
			{
				x++;
			}
			else
			{
				x--;
			}
			count++;
		}
		else if(y!=b)
		{
			if(y<b)
			{
				y++;
			}
			else
			{
				y--;
			}
			count++;
		}
		else if(x==a&&y==b)
		{
			out.println(count);
			break;
		}
		}
		out.close();
	}
	private static long[] nextIntArray(InputReader in,int n)
	{
		long[] a=new long[n];
		for(int i=0;i<n;i++)
			a[i]=in.nextLong();
		return a;
	}
	public static double dis(double x1,double x2,double y1)
	{
		return Math.sqrt(((x1-x2)*(x1-x2))+(y1*y1));
	}
	private static String[] nextStringArray(InputReader in,int n)
	{
		String[] a=new String[n];
		for(int i=0;i<n;i++)
			a[i]=in.next();
		return a;
	}
	private static void show(int[] a)
	{
		for(int i=0;i<a.length;i++)
			System.out.print(a[i]+" ");
		System.out.println();
	}
	private static void show2DArray(char[][] a)
	{
		for(int i=0;i<a.length;i++)
		{
			for(int j=0;j<a[0].length;j++)
				System.out.print(a[i][j]);
			System.out.println();
		}
	}
 static long fact(long x)
 {
	 long i=x,mul=1;
	 while(i>0)
	 {
		 mul=(mul%1000000007)*(i%1000000007)%1000000007;
		 i--;
	 }
	 return mul;
 }
 static long output(ArrayList<Integer> h[],int j,boolean[] v)
 {
	 int k;
	 v[j]=true;
	 sum++;
	 for(k=0;k<h[j].size();k++)
	 {
		 if(v[h[j].get(k)]==false)
		 {
			 output(h,h[j].get(k),v);
		 }
	 }
	 return sum;
 }
 static long func(boolean v[],int j,ArrayList<Integer> h[],long ban[])
 {
	 	v[j]=true;
	 	 int k;
	 	long sum=0;
	    sum=sum+ban[j];
	 	//System.out.println(h[j].size());
	 	for(k=0;k<h[j].size();k++)
	 	{
	 		if(v[h[j].get(k)]==false)
	 		{
	 			v[h[j].get(k)]=true;
	 			sum+=func(v,h[j].get(k),h,ban);
	 		}
	 	}
	 	return sum;
 }
/*static class Graph {

    	private static Deque<Integer> stack = new ArrayDeque<Integer>();
 		private int least,count,v;

		Set<Integer>[] cities;
    	private int[] risk;

    	Graph(int n,String[] risk){

    		cities = new HashSet[n];
    		this.risk = new int[n];
    		for(int i =0;i<n;i++){
    			cities[i] = new HashSet<>();
    		}
    		for(int i =0;i<n;i++){
    			this.risk[i] = Integer.parseInt(risk[i]);
    		}
    		visited = new boolean[n];
    	}

    	public void add(int x,int y){
    		cities[x].add(y);
    		cities[y].add(x);
    	}
}*/
	static int root(int arr[],int i)
	{
		while(arr[i]!=i)
		{
			i=arr[i];
		}
		return i;
	}
	static boolean find(int arr[],int a,int b)
	{
		if(root(arr,a)==root(arr,b))
		{
			return true;
		}
		else
			return false;
	}
	static void weighted_union(int arr[],int size[],int a,int b)
	{
		int root_a=root(arr,a);
		int root_b=root(arr,b);
		if(root_a!=root_b)
		{
			if(size[root_a]<size[root_b])
			{
				arr[root_a]=arr[root_b];
				size[root_b]+=size[root_a];
			}
			else
			{
				arr[root_b]=arr[root_a];
				size[root_a]+=size[root_b];
			}
		//	count--;
		}
	}
	static class Pair implements Comparable<Pair>
	{
		private long first;
		private long index;
		//private long second;;

		public Pair(long i, long j)
		{
			this.first = i;
			this.index = j;
		}
		public long getFirst() { return first; }
		//public long getSecond() { return second; }
		public long getIndex() { return index ;}
		public void setFirst(long k) { this.first=k ; }
		public void setIndex(long k) { this.index=k ;}
		//public void setSecond(long k) { this.second=k ;}
		@Override
		public int compareTo(Pair o)
		{
			return Long.compare(this.first, o.first);
		}
	}
	static class InputReader {
		public BufferedReader reader;
		public StringTokenizer tokenizer;

		public InputReader(InputStream inputstream) {
			reader = new BufferedReader(new InputStreamReader(inputstream));
			tokenizer = null;
		}

		public String nextLine(){
			String fullLine=null;
			while (tokenizer == null || !tokenizer.hasMoreTokens()) {
				try {
					fullLine=reader.readLine();
				} catch (IOException e) {
					throw new RuntimeException(e);
				}
				return fullLine;
			}
			return fullLine;
		}
		public String next() {
			while (tokenizer == null || !tokenizer.hasMoreTokens()) {
				try {
					tokenizer = new StringTokenizer(reader.readLine());
				} catch (IOException e) {
					throw new RuntimeException(e);
				}
			}
			return tokenizer.nextToken();
		}
		public long nextLong() {
			return Long.parseLong(next());
		}
		public int nextInt() {
			return Integer.parseInt(next());
		}
	}
}


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

public class Main {
  public static IO in;
  public static PrintWriter out;

  static void init_io(String filename) throws Exception {
    if (filename.equals("")) {
      in = new IO(System.in);
      out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)), true);
    } else {
      in = new IO(new FileInputStream(filename + ".in"));
      out = new PrintWriter(new BufferedWriter(new FileWriter(filename + ".out")), true);
    }
  }

  final static long mod = 1_000_000_007;

  public static void main(String[] _u_n_u_s_e_d_) throws Exception {
    init_io("");

    String s = in.nstr();
    int n = s.length();

    TreeSet<String> ts = new TreeSet<String>();

    for (int l = 0; l <= n; i++) {
        String a = "", b = "";
        if (l > 0) a = s.substring(0, l - 1);
        if (l < n) b = s.substring(l, n - 1);
        for (char c = 'a'; c <= 'z'; c++) {
            ts.add(a + "" + c + b);
        }
    }

    out.println(ts.size());
  }

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

  static void qsort(long[] arr) {
    Long[] oarr = new Long[arr.length];
    for (int i = 0; i < arr.length; i++) {
      oarr[i] = arr[i];
    }

    ArrayList<Long> alist = new ArrayList<Long>(Arrays.asList(oarr));
    Collections.sort(alist);

    for (int i = 0; i < arr.length; i++) {
      arr[i] = alist.get(i);
    }
  }

  static void reverse(long[] arr) {
    for (int i = 0; i < arr.length / 2; i++) {
      long temp = arr[i];
      arr[i] = arr[arr.length - 1 - i];
      arr[arr.length - 1 - i] = temp;
    }
  }

  static String atos(long[] arr) {
    String s = Arrays.toString(arr);
    s = s.substring(1, s.length() - 1);
    return s.replace(",", "");
  }

  static class IO {
    public BufferedReader in;
    public StringTokenizer tokens;

    public IO(InputStream x) throws Exception {
      in = new BufferedReader(new InputStreamReader(x));
      tokens = new StringTokenizer(in.readLine());
    }

    int nint() throws Exception {
      return Integer.parseInt(nstr());
    }

    long nlong() throws Exception {
      return Long.parseLong(nstr());
    }

    double ndouble() throws Exception {
      return Double.parseDouble(nstr());
    }

    String nstr() throws Exception {
      if (!tokens.hasMoreTokens()) tokens = new StringTokenizer(in.readLine());
      return tokens.nextToken();
    }

    long[] nla(int n) throws Exception {
      long[] arr = new long[n];
      for (int i = 0; i < n; i++) {
        arr[i] = nlong();
      }
      return arr;
    }
  }

  static class Pair<A extends Comparable<A>, B extends Comparable<B>> implements Comparable<Pair<A, B>> {
    public A f;
    public B s;

    public Pair(A a, B b) {
      f = a;
      s = b;
    }

    public int compareTo(Pair<A, B> other) {
      int v = f.compareTo(other.f);
      if (v != 0) return v;
      return s.compareTo(other.s);
    }

    public String toString() {
      return "(" + f.toString() + ", " + s.toString() + ")";
    }
  }
}


import java.io.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class EducationalRound86E {

	public static long mod = 998244353;
	public static int max = (int)4e5+10;
	public static long[] fact;
	public static long[] infact;

	public static void PreCompute() {
		fact = new long[max];
		infact = new long[max];
		fact[0] = fact[1] = infact[0] = infact[1] = 1;
		for(int i = 2; i < max; i++) {
			fact[i] = (fact[i - 1] * (long)i)%mod;
			infact[i] = (infact[i - 1] * (long)ModInverse(i, mod))%mod;
		}
	}

	public static long nCr(int n, int r) {
		long ans = fact[n] * infact[r];
		ans %= mod;
		ans *= infact[n - r];
		ans %= mod;
		return ans;
	}

	public static long fast(long a, long n) {
		if(n == 0) return 1L;
		long ans = fast(a, n/2L);
		ans = ans * ans;
		ans %= mod;
		if(n%2 == 1) {
			ans = ans * a;
			ans %= mod;
		}
		return ans;
	}

	public static void solve() {
		PreCompute();
		int n = s.nextInt();
		int k = s.nextInt();
		if(k == 0) {
			out.println(fact[n]);
			return;
		}
		if(n <= k) {
			out.println(0);
			return;
		}
		long ans = nCr(n, k);
		int cols = n - k;
		long sum = 0;
		for(int i = 0; i <= cols; i ++) {
			long tempans = nCr(cols, i);
			tempans *= fast(cols - i, n);
			tempans %= mod;
			if((i&1)==1) {
				sum -= tempans;
				if(sum < 0) sum += mod;
			}else {
				sum+=tempans;
				if(sum >= mod) sum -= mod;
			}
		}
		out.println((2 * ((ans * sum)%mod))%mod);
	}

	public static void main(String[] args) {
		out = new PrintWriter(new BufferedOutputStream(System.out));
		s = new FastReader();
		solve();
		out.close();
	}

	public static class Triplet {
		long gcd;
		long x;
		long y;

		Triplet(long gcd, long x, long y) {
			this.gcd = gcd;
			this.x = x;
			this.y = y;
		}
	}

	public static Triplet ExtendedEuclideanAlgo(long a, long b) {
		if (a == 0) {
			return new Triplet(b, 0, 1);
		}
		Triplet ans = ExtendedEuclideanAlgo(b % a, a);
		long x = ans.y - (b / a) * ans.x;
		long y = ans.x;
		return new Triplet(ans.gcd, x, y);
	}

	public static long ModInverse(long a, long m) {
		Triplet ans = ExtendedEuclideanAlgo(a, m);
		if (ans.gcd != 1) {
			//System.out.println("Multiplicative inverse doesnot exist");
			return -1;
		} else {
			//m is added to handle negative x
			long result = (ans.x % m + m) % m;
			return result;
		}
	}

	public static FastReader s;
	public static PrintWriter out;

	public static class FastReader {
		BufferedReader br;
		StringTokenizer st;

		public FastReader() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}

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

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

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

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

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

}


import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class e_e86 {

	static int MOD = 998244353;
	static long fact [];

	public static void main(String[] args) throws Exception {
		// TODO Auto-generated method stub

		FastScanner in = new FastScanner(System.in);
		OutputStream outputStream = System.out;
		PrintWriter out = new PrintWriter(outputStream);

		int N = in.nextInt();
		long pk = in.nextLong();
		if(pk > N-1) {
			out.println(0);
		}else {
			int k = (int) pk;
			fact = new long [N];

			fact[0] = 1;
			for(int i = 1; i <= N+4; i++) {
				fact[i] = (i*fact[i-1])%MOD;
			}

			long ans = 0;
			int dir = 1;
			int c = N-k;
			for(int i = c; i >= 0; i--) {
				long dif = (choose(c, i)*power(i, N))%MOD;
				dif = dir*dif;
				ans = (ans + dif + MOD)%MOD;

		//		out.println(dir*(((choose(c, i))*power(i, N) + MOD)%MOD + MOD)%MOD +" " + choose(c, i) + " " + power(i, N));
				dir = -dir;
			}

			ans = (ans*choose(N, c))%MOD;
			if(k > 0) {
				ans = (2*ans)%MOD;
			}

			out.println(ans);
		}

		out.close();

	}

	static long choose(int a, int b) {
		long res = (fact[a] * inv((fact[b] * fact[a-b])%MOD))%MOD;
		return res;
	}

	static long power (long x, int y) {
		long res = 1;
		while(y > 0) {
			if(y%2 == 1) res = (res*x)%MOD;
			x = (x*x)%MOD;
			y /= 2;
		}
		return (res%MOD);
	}

	static long inv (long a) {
		return power(a, MOD-2);
	}

	static class FastScanner {
		BufferedReader br;
		StringTokenizer st;

		public FastScanner(InputStream stream) {
			br = new BufferedReader(new InputStreamReader(stream));
			st = new StringTokenizer("");
		}

		public FastScanner(String fileName) throws Exception {
			br = new BufferedReader(new FileReader(new File(fileName)));
			st = new StringTokenizer("");
		}

		public String next() throws Exception {
			while (!st.hasMoreTokens()) {
				st = new StringTokenizer(br.readLine());
			}
			return st.nextToken();
		}

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

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

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

		public String nextLine() throws Exception {
			if (st.hasMoreTokens()) {
				StringBuilder str = new StringBuilder();
				boolean first = true;
				while (st.hasMoreTokens()) {
					if (first) {
						first = false;
					} else {
						str.append(" ");
					}
					str.append(st.nextToken());
				}
				return str.toString();
			} else {
				return br.readLine();
			}
		}
	}

}


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

public class E {
	FastScanner in;
	PrintWriter out;

	int[] p;
	double[][] dpEqLess;
	double[][] dpEqLessMul;
	int maxK = 150;

	public void solve() throws IOException {
		int q = in.nextInt();
		dpEqLess = new double[maxK][q];
		for (int i = 0; i < maxK; i++) {
			dpEqLess[i][0] = 1;
		}
		p = new int[q];
		p[0] = -1;
		int cntV = 0;
		for (int i = 0; i < q; i++) {
			int type = in.nextInt();
			int v = in.nextInt() - 1;
			if (type == 1) {
				int u = ++cntV;
				p[u] = v;
				for (int j = 0; j < maxK; j++) {
					dpEqLess[j][u] = 1;
				}
				double prev = 1;
				for (int j = 0; j < maxK; j++) {
					double val = dpEqLess[j][v];
					val /= prev;
					prev = dpEqLess[j][v]*0.5 + 0.5;
					val *= (0.5 + 0.5*(j - 1 >= 0 ? dpEqLess[j - 1][u] : 0));
					dpEqLess[j][v] = val;

					v = p[v];
					u = p[u];
					if (v == -1) {
						break;
					}
				}
			} else {
				double res = 0;
				for (int j = 1; j < maxK; j++) {
					res += j * (dpEqLess[j][v] - dpEqLess[j - 1][v]);
				}
				out.println(res);
			}
		}
	}

	public void run() {
		try {
			in = new FastScanner();
			out = new PrintWriter(System.out);

			solve();

			out.close();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

	class FastScanner {
		BufferedReader br;
		StringTokenizer st;

		FastScanner() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}

		String next() {
			while (st == null || !st.hasMoreTokens()) {
				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());
		}
	}

	public static void main(String[] arg) {
		new E().run();
	}
}


public class Tanya {

  public static void main(String[] args) {
    System.out.println(alg(Integer.parseInt(args[0]), Integer.parseInt(args[1])));
  }

  public static int alg(int n, int k) {
    for(int a = 0; a < k; a++) {
      if(n % 10 != 0) {
        n -= 1;
      }
      else {
        n /= 10;
      }
    }
    return n;
  }

}


import java.util.Scanner;

/**
 * Created by jfy on 7/7/16.
 */
public class MikeAndCellphone {

    static boolean check(String s) {
        boolean ans = true;
        int n = s.length();

        while (ans) {
            for (int i = 0; i < n; i++) {
                if (s.charAt(i) == '0') {
                    while (ans) {
                        for (int j = 0; j < n; j++) {
                            if (s.charAt(j) == '1' || s.charAt(j) == '2' || s.charAt(j) == '3')
                                ans = false;
                        }
                    }
                }
            }
        }

        while(ans) {
            for (int i = 0; i < n; i++) {
                if (s.charAt(i) == '1') {
                    while (ans) {
                        for (int j = 0; j < n; j++) {
                            if (s.charAt(j) == '9')
                                ans = false;
                        }
                    }
                }
            }
        }

        while (ans) {
            for (int i = 0; i < n; i++) {
                if (s.charAt(i) == '3') {
                    while (ans) {
                        for (int j = 0; j < n; j++) {
                            if (s.charAt(j) == '7')
                                ans = false;
                        }
                    }
                }
            }
        }

        return ans;
    }

    public static void main(String arg[]) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        String s = sc.next();
        if (check(s)) {
            System.out.println("NO");
        }
        else System.out.println("YES");
    }
}


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

public class CF224_E {
    static int mod = 1_000_000_007;

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);// Scanner :')
        int n = in.nextInt();
        int k = in.nextInt();

        long[][] f = new long[n + 1][n + 1];// root matched, can't be unmatched
                                            // and keep the matching maximum
        long[][] g = new long[n + 1][n + 1];// root not matched in maximum
                                            // matching

        long[][] c = new long[n + 1][n + 1];

        c[0][0] = 1;
        for (int i = 1; i <= n; c[i][0] = 1, i++)
            for (int j = 1; j <= n; j++)
                c[i][j] = (c[i - 1][j] + c[i - 1][j - 1]) % mod;

        f[1][0] = 0;
        f[0][0] = 1;
        g[1][0] = g[0][0] = 1;

        for (int i = 2; i <= n; i++) {
            for (int j = 0; j <= n; j++) {
                // calculate f[i][j], g[i][j]
                for (int left = 1; left <= i - 1; left++) {
                    long mul = c[i - 2][left - 1] * (left)
                            * max(1, (i - 1 - left)) % mod;
                    for (int kleft = 0; kleft <= j - 1; kleft++) {

                        long addA = g[left][kleft]
                                * (i - 1 - left > 0 ? g[i - 1 - left][j - 1
                                        - kleft]
                                        + f[i - 1 - left][j - 1 - kleft] : j
                                        - 1 - kleft == 0 ? 1 : 0) % mod;
                        long addB = ((i - 1 - left) > 0 ? g[i - 1 - left][j - 1
                                - kleft]
                                * f[left][kleft] : 0)
                                % mod;
                        f[i][j] = (f[i][j] + mul * (addA + addB) % mod) % mod;
                    }
                    for (int kleft = 0; kleft <= j; kleft++)
                        g[i][j] = (g[i][j] + mul * f[left][kleft] % mod
                                * f[i - 1 - left][j - kleft])
                                % mod;
                }
            }
        }

        System.out.println((f[n][k] + g[n][k]) % mod);
    }
}


import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.io.BufferedReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.InputStream;

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

class TaskE {
    private static final int MOD = 1000000007;
    private static final long[][] choose;
    static {
        choose = new long[55][55];
        for (int i = 0; i <= 51; ++i) {
            choose[i][0] = choose[i][i] = 1;
            for (int j = 1; j < i; ++j) {
                choose[i][j] = (choose[i - 1][j] + choose[i - 1][j - 1]) % MOD;
            }
        }
    }
    public void solve(int testNumber, InputReader in, PrintWriter out) {
        int n = in.nextInt(), k = in.nextInt();

        int[][][] dp = new int[n + 1][2][n + 1];
        dp[1][0][0] = 1;
        dp[0][1][0] = 1;
        for (int i = 2; i <= n; ++i) {
            for (int j = 0; j < 2; ++j) {
                for (int match = 0; match <= i; ++match) {
                    for (int left = 0; left < 2; ++left) {
                        for (int right = 0; right < 2; ++right) {
                            if ((left == 0 || right == 0) && j == 0) continue;
                            if (left == 1 && right == 1 && j == 1) continue;
                            int rem = match - j;
                            if (rem < 0) continue;
                            for (int leftSize = 0; leftSize < i; ++leftSize) {
                                for (int leftMatch = 0; leftMatch <= leftSize && leftMatch <= rem; ++leftMatch) {
                                    int rightSize = i - 1 - leftSize;
                                    int rightMatch = rem - leftMatch;
                                    if (rightMatch > rightSize) continue;
                                    if (leftSize < rightSize || leftSize == rightSize && leftMatch < rightMatch) {
                                        dp[i][j][match] = (int) ((dp[i][j][match] + dp[leftSize][left][leftMatch]
                                                * (long) dp[rightSize][right][rightMatch] % MOD * (i == n ? 1 : i) % MOD * choose[i - 1][leftSize] % MOD) % MOD);
                                    } else if (leftSize == rightSize && leftMatch == rightMatch) {
                                        dp[i][j][match] = (int) ((dp[i][j][match] + dp[leftSize][left][leftMatch]
                                                * (long) (dp[rightSize][right][rightMatch] - 1) % MOD * NumberUtils.powMod(2, MOD - 2, MOD) % MOD * (i == n ? 1 : i) % MOD * choose[i - 1][leftSize] % MOD) % MOD);
                                        dp[i][j][match] = (int) ((dp[i][j][match] + dp[leftSize][left][leftMatch] * (long) (i == n ? 1 : i) % MOD * choose[i - 1][leftSize] % MOD * NumberUtils.powMod(2, MOD - 2, MOD) % MOD) % MOD);
                                    }
//                                    if (i == 3 && j == 1 && match == 1) {
//                                        out.println("left = " + left + " right = " + right + " ls = " + leftSize + " lm = " + leftMatch + " rs = " + rightSize + " rm = " + rightMatch + " i = " + i + " j = " + j + " match = " + match + " res = " + dp[i][j][match]);
//                                    }
                                 }
                            }
                        }
                    }
//                    out.println("i = " + i + " j = " + j + " match = " + match + " res = " + dp[i][j][match]);
                }
            }
        }

        out.println((((dp[n][0][k] + dp[n][1][k]) % MOD) + MOD) % MOD);
    }
}

class InputReader {
    BufferedReader reader;
    StringTokenizer tokenizer;

    public InputReader(InputStream stream) {
        reader = new BufferedReader(new InputStreamReader(stream));
        tokenizer = null;
    }

    public String next() {
        while (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                tokenizer = new StringTokenizer(reader.readLine());
            } catch (Exception e) {
                throw new UnknownError();
            }
        }
        return tokenizer.nextToken();
    }

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

    }

class NumberUtils {

    public static long powMod(long x, long y, long mod) {
        long res = 1;
        for (; y != 0; y >>= 1L) {
            if (y % 2 == 1) res = res * x % mod;
            x = x * x % mod;
        }
        return res;
    }

    }


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

import java.lang.Math;
public class Solution
{

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

        int min = 0;
        int max = 0;
        if (k < n) {
            min = 1;
        } else {
            min = 0;
            max = 0;
            System.out.println(min + " " + max);
            return;
        }

        if (k == 0) {
            min = 0;
            max = 0;
            System.out.println(min + " " + max);
            return;
        }

        if (n == 1) {
            max = 0;
            min = 0;
            System.out.println(min + " " + max);
            return;

        }

        if (n == 2) {
            if (k == 1) {
                max = 1;
            } else if (k == 2) {
                max = 0;
            }
            System.out.println(min + " " + max);
            return;
        }

        if (n == 3) {
            if (k == 1) {
                max = 2;
            } else if (k == 2) {
                max = 1;
            } else {
                max = 0;
            }
            System.out.println(min + " " + max);
            return;
        }

        int arr[] = new int[n];
        for (int i = 0; i < n; ++i) {
            if (i % 3 == 1) {
                arr[i] = 1;
            } else {
                arr[i] = 0;
            }
        }

        if (1 + 3 * (k - 1) < n) {
            for (int i = 1 + 3 * (k - 1) + 1; i < n; ++i) {
                arr[i] = 0;
            }
        } else {
            // k < (n-1)/3 + 1
            int idealK = (n-1)/3 + 1;
            if ((n-1) % 3 == 0) {
                --idealK;
            }

            int diffK = k - idealK;
            for (int i = n-1; i >= 0; --i) {
                if (diffK == 0) {
                    break;
                }
                if (arr[i] != 1) {
                    arr[i] = 1;
                    --diffK;
                }
            }
        }

        for (int i = 0; i < n; ++i) {
            if (arr[i] == 1) {
                if (arr[i - 1] == 0) {
                    ++max;
                }
                if (i + 2 < n) {
                    if (arr[i + 1] == 0 && arr[i + 2] == 0) {
                        ++max;
                    }
                } else if (i + 1 < n && i + 2 >= n) {
                    if (arr[i + 1] == 0) {
                        ++max;
                    }
                }
            }
        }

        System.out.println(min + " " + max);

    }
}


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.BufferedWriter;
import java.io.Writer;
import java.io.OutputStreamWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.InputStream;

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

    static class TaskB {
        public void solve(int testNumber, InputReader in, OutputWriter out) {
            int n = in.nextInt();
            int k = in.nextInt();
            int a[] = new int[n + 3];
            int min = 0, max = 0;
            if (n % 2 == 0) {
                if (k >= n / 2) {
                    max = (n / 2) - (k - n / 2);
                } else if (k != 0) {
                    int rem = k;
                    for (int i = 2; i <= n; i += 3) {
                        a[i] = 1;
                        --rem;
                        if (rem == 0) break;

                    }
                    for (int i = 1; i <= n; i++) {
                        if (a[i] == 0 && a[i + 1] == 1 || a[i - 1] == 1)
                            ++max;
                    }
                }
                if (k != n && k != 0)
                    min = 1;
            } else {
                ++n;
                if (k >= n / 2)
                    max = n / 2 - (k - n / 2) - 1;
                else if (k != 0) {
                    int rem = k;
                    for (int i = 2; i < n; i += 3) {
                        a[i] = 1;
                        --rem;
                        if (rem == 0) break;
                    }
                    for (int i = 1; i < n; i++) {
                        if (a[i] == 0 && a[i + 1] == 1 || a[i - 1] == 1)
                            ++max;
                    }
                }
                if (k != n - 1 && k != 0)
                    min = 1;
            }
            out.println(min + " " + max);

        }

    }

    static class OutputWriter {
        private final PrintWriter writer;

        public OutputWriter(OutputStream outputStream) {
            writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
        }

        public OutputWriter(Writer writer) {
            this.writer = new PrintWriter(writer);
        }

        public void print(Object... objects) {
            for (int i = 0; i < objects.length; i++) {
                if (i != 0) {
                    writer.print(' ');
                }
                writer.print(objects[i]);
            }
        }

        public void println(Object... objects) {
            print(objects);
            writer.println();
        }

        public void close() {
            writer.close();
        }

    }

    static class InputReader {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;
        private InputReader.SpaceCharFilter filter;

        public InputReader(InputStream stream) {
            this.stream = stream;
        }

        public int read() {
            if (numChars == -1) {
                throw new InputMismatchException();
            }
            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (numChars <= 0) {
                    return -1;
                }
            }
            return buf[curChar++];
        }

        public int nextInt() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            int res = 0;
            do {
                if (c < '0' || c > '9') {
                    throw new InputMismatchException();
                }
                res *= 10;
                res += c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public boolean isSpaceChar(int c) {
            if (filter != null) {
                return filter.isSpaceChar(c);
            }
            return isWhitespace(c);
        }

        public static boolean isWhitespace(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        public interface SpaceCharFilter {
            public boolean isSpaceChar(int ch);

        }

    }
}


import java.util.Scanner;

public class MaximApartment {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int k = sc.nextInt();

		int min = (n - k > 0 && k > 0) ? 1 : 0;

		int max = 0;

		int[] map = new int[n];
		int placed = 0;
		for(int i = 1; i < n && placed < k; ) {
			map[i] = 1;
			placed++;
			i += 3;
		}

		for(int i = 0; i < n; ++i) {
			if(map[i] == 0 && ((i > 0 && map[i - 1] == 1) || (i < n-1 && map[i + 1] == 1) ))
			 	++max;
		}

		if(placed < k)
			max -= (k - placed);

		if(max < min)
			max = min;

		System.out.println(min + " " + max);
	}
}


import java.util.Arrays;
import java.util.Scanner;

public class Apartments {

	public static void main(String[] args) {
		Scanner scn = new Scanner(System.in);
		int n = scn.nextInt();
		int k = scn.nextInt();
		int[] arr = new int[n];
		Arrays.fill(arr, 0);

		int max = 0;
		if(k > 0) {
			int temp = k;
			for(int i = 1; i < n; i+=2) {
				if(temp == 0)break;
				arr[i] = 1;
				temp--;
			}
			int i = 0;
			while(temp > 0 || i >= n) {
				if(arr[i] == 1) {
					i++;
					continue;
				}
				arr[i] = 1;
				i++;
				temp--;
			}
			for(int j = 0;j < n; j++) {
				if(j+1 < n && arr[j+1] == 1 && arr[j] == 0)max++;
				else if(j-1 >= 0 && arr[j-1] == 1 && arr[j] == 0)max++;
			}
		}
		int min = 0;
		if(n > k && k > 0) min = 1;
		System.out.println(min + " "+ max);
	}

}


import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int a=scanner.nextInt();
        int b=scanner.nextInt();
        if( Math.abs(a-b)<=1){
            System.out.println("YES");
        }else{
            System.out.println("NO");
        }

    }
}


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

public class walruses {
public static void main(String[] args) throws IOException{
BufferedReader in=new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st=new StringTokenizer(in.readLine());
int n=Integer.parseInt(st.nextToken());
int k=Integer.parseInt(st.nextToken());
boolean cont=true;
while(cont){
for (int i = 1; i <=k; i++) {
	if(i>k){
		cont=false;
		break;
	}	k-=i;
}}

System.out.println(k);
}
}


import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        long a = in.nextLong(), b = in.nextLong();
        int res = 1;
        while (a <= b) {
            a *= a * a;
            b *= b;
            res++;
        }
        System.out.println(res);
    }
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Scanner;
import java.util.StringTokenizer;

public class Main {

	static BufferedReader brscan = new BufferedReader(new InputStreamReader(
			System.in));
	static PrintWriter pw = new PrintWriter(System.out);
	static Scanner scan = new Scanner(System.in);

	public static void main(String[] args) throws IOException {
		StringTokenizer stoken;

		int a = scan.nextInt();
		int b = scan.nextInt();
		int r = scan.nextInt();

		if (Math.min(a, b)<2*r) {
			System.out.println("First");
		} else {
			System.out.println("Second");
		}

	}
}

class Node {

	int id;
	ArrayList<Node> edge;
	final int DEFAULT_SZ = 26;
	int chromatic_num = 0;

	public Node(int id) {
		this.id = id;
		edge = new ArrayList<Node>(DEFAULT_SZ);
	}

	public void addEdge(Node another) {
		edge.add(another);
	}

	public Node getEdge(int index) {
		return edge.get(index);
	}

	public String toString() {
		String edgeName = "";

		for (int n = 0; n < edge.size(); n++) {
			edgeName += " " + edge.get(n).id;
		}

		return "[" + this.id + "] - " + edgeName;
	}
}


import java.util.Scanner;

public class A {
    public static void main(String args[]){
            Scanner in = new Scanner(System.in);
            int a[] = new int[6];
            for(int i = 0 ; i < 6 ; i++)
                a[i] = in.nextInt();
            while(a[0]!=a[2]){
                int temp = a[0];
                for(int i = 0 ; i + 1 < 6 ; i++)
                    a[i] = a[i+1];
                a[5] = temp;
            }
            int n = 0 , count = 0;
            for(int i = a[1];i<a[1]+a[2];i++,count++)
                n+=i;
            for(int i = a[4];i<a[4]+a[5];i++,count++)
                n+=i;
            System.out.println((2*n+count));
    }
}


package trying;

import java.util.Scanner;

public class C {
    public static void main(String[] args) {
        Scanner myScanner = new Scanner(System.in);
        long t1 = myScanner.nextInt(), t2 = myScanner.nextInt(), x1 = myScanner
                .nextInt(), x2 = myScanner.nextInt(), t0 = myScanner.nextInt(), y1 = -1, y2 = -1, j, max = -1;

        double currT, dif, minDif = Integer.MAX_VALUE;

        if (t1 > t2) {
            long tmp = x1;
            x1 = x2;
            x2 = tmp;
            tmp = t1;
            t1 = t2;
            t2 = tmp;
        }

        for (int i = 0; i <= x1; i++) {
            j = BS(i, x2, t1, t2, t0);
            currT = ((i * t1) + (j * t2)) * 1.0 / (i + j) * 1.0;
            dif = currT - t0;
            if (((dif > -1e-9) && dif < minDif)) {
                max = i + j;
                y1 = i;
                y2 = j;
                minDif = dif;
            } else if (dif - minDif > -1e-9 && dif - minDif < 1e-9)
                if (i + j > max) {
                    max = i + j;
                    y1 = i;
                    y2 = j;
                    minDif = dif;
                }
        }
        System.out.println(y1 + " " + y2);
    }

    private static long BS(int y1, long x2, long t1, long t2, long t0) {
        long low = 0, high = x2, mid = (low + high) / 2;
        int cnt = 0;
        double currT = 0;
        double a, b;
        if (y1 == 0) {
            double dif, minDif = 1e10;
            long res = x2;
            for (long i = x2; i >= 0; i--) {
                a = ((t1 * y1) + (t2 * mid));
                b = (y1 + mid);
                dif = a / b - t0;
                if (dif > -1e-7 && dif < minDif) {
                    minDif = dif;
                    res = i;
                }
            }
            return res;
        }
        while (low < high - 1) {
            a = ((t1 * y1) + (t2 * mid));
            b = (y1 + mid);
            if (b > 0 && a > -1)
                currT = a * 1.0 / b * 1.0;
            if (currT < t0)
                low = mid;
            else if (currT == t0) {
                a = ((t1 * y1) + (t2 * high));
                b = (y1 + high);
                currT = a * 1.0 / b * 1.0;
                return currT == t0 ? high : mid;
            } else
                high = mid;
            cnt++;
            mid = (low + high) / 2;
        }
        a = ((t1 * y1) + (t2 * mid));
        b = (y1 + mid);
        if (b > 0)
            currT = a / b;
        if (currT < t0)
            low = mid;
        else
            high = mid;
        cnt++;
        double dif1 = ((((t1 * y1) + (t2 * low)) * 1.0 / (y1 + low) * 1.0))
                - t0, dif2 = ((((t1 * y1) + (t2 * high)) * 1.0 / (y1 + high) * 1.0))
                - t0;
        if (dif1 < 0)
            return high;
        if (dif2 < 0)
            return low;
        return dif1 < dif2 ? low : high;
    }
}


import java.io.*;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

public class Task317AA {

    public static void main(String... args) throws NumberFormatException,
            IOException {
        Solution.main(System.in, System.out);
    }

    static class Scanner {

        private final BufferedReader br;
        private String[] cache;
        private int cacheIndex;

        Scanner(InputStream is) {
            br = new BufferedReader(new InputStreamReader(is));
            cache = new String[0];
            cacheIndex = 0;
        }

        int nextInt() throws IOException {
            if (cacheIndex >= cache.length) {
                cache = br.readLine().split(" ");
                cacheIndex = 0;
            }
            return Integer.parseInt(cache[cacheIndex++]);
        }

        long nextLong() throws IOException {
            if (cacheIndex >= cache.length) {
                cache = br.readLine().split(" ");
                cacheIndex = 0;
            }
            return Long.parseLong(cache[cacheIndex++]);
        }

        String next() throws IOException {
            if (cacheIndex >= cache.length) {
                cache = br.readLine().split(" ");
                cacheIndex = 0;
            }
            return cache[cacheIndex++];
        }

        void close() throws IOException {
            br.close();
        }

    }

    static class Solution {

        public static void main(InputStream is, OutputStream os)
                throws NumberFormatException, IOException {
            PrintWriter pw = new PrintWriter(os);
            Scanner sc = new Scanner(is);

            long x = sc.nextLong();
            long y = sc.nextLong();
            long m = sc.nextLong();

            int retVal = 0;

            while(x < m && y < m){
                if(x < y){
                    if(y <= 0){
                        pw.println(-1);
                        pw.flush();
                        sc.close();
                        return;
                    }
                    x += y;
                    retVal++;
                } else {
                    if(x <= 0){
                        pw.println(-1);
                        pw.flush();
                        sc.close();
                        return;
                    }
                    y += x;
                    retVal++;
                }
            }

            pw.println(retVal);
            pw.flush();
            sc.close();
        }
    }

}


import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Scanner;

public class InterestingGame
{
	static ArrayList<Pair>[] arr;
	static int dp[];
	static int[] ans;
	public static void main(String[] args)
	{

		dp = new int[100001];
		ans = new int[100001];
		Arrays.fill(dp, -1);
//		for (int i = 0; i < 100001; i++)
//			System.out.println(i + " " + G(i));
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		if(G(n) == 0)
			System.out.println(-1);
		else
			System.out.println(ans[n]);
	}

	private static int G(int n)
	{
		if(dp[n] != -1)
			return dp[n];
		HashSet<Integer> set = new HashSet<Integer>();
		ans[n] = 1000000;
		for (int k = 2;(n - sumto(k-1)) / k > 0; k++)
		{
			if((n - sumto(k-1)) % k == 0)
			{
				int st = (int)((n - sumto(k-1)) / k);
				int xor = 0;
				for (int i = 0; i < k; i++)
					xor ^= G(st++);
				if(xor == 0)
					ans[n] = Math.min(ans[n], k);
				set.add(xor);
			}
		}
		return dp[n] = mex(set);
	}

	static int mex(HashSet<Integer> set)
	{
		int ret = 0;
		while(set.contains(ret))
			ret++;
		return ret;
	}

	static long sumto(int n)
	{
		long n1 = n;
		long n2 = n+1;
		if(n1 % 2 == 0)
			n1 /= 2;
		else
			n2/=2;
		return 1l*n1*n2;
	}
}


import java.util.Arrays;
import java.util.Scanner;
//http://codeforces.com/contest/914/problem/0
public class PerfectSquares {
	public static void main(String[] args) {
		Scanner s = new Scanner(System.in);
		s.nextLine();
		int[] a = Arrays.stream(s.nextLine().split(" ")).mapToInt(x -> Integer.parseInt(x)).toArray();
		int max = Integer.MIN_VALUE;
		for (int i = 0; i < a.length; i++) {
			if(are(int a) {
		for (int i = 0; i*i <= a ; i++) {
			if(i*i == a) {
				return true;
			}
		}
		return false;
	}
}


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

public class Hack{

    public static void main(String args[]){
        Scanner in = new Scanner(System.in);

            int n = in.nextInt();
            BigInteger x = new BigInteger("8");
            BigInteger y = new BigInteger("8");
            BigInteger div = new BigInteger("10");
            x = x.pow(n/2);
            y = y.pow((n/2)+(n%2));
            System.out.println(((x.remainder(div)).multiply(y.remainder(div))).remainder(div));

    }
}


import java.util.Scanner;

public class TaskB {
	public static Scanner in = new Scanner(System.in);

	public static void main(String[] args){
		int n = in.nextInt();
		int m = in.nextInt();
		int k = in.nextInt();
		int a = in.nextInt();
		int b = in.nextInt();
		int time = 0;
		int n1 , n2;
		int m1, m2;
		n1 = a/(m*k) + 1;
		n2 = b/(m*k)+1  ;
		if(a %(m*k) == 0 ) n1--;
		if(b%(m*k) == 0) n2--;
		m1 = (a - (n1-1)* m* k)/k + 1 ;
		m2 = (b - (n2-1)*m*k)/k + 1;
		if((a - (n1-1)* m* k)%k == 0 ) m1--;
		if((b - (n2-1)*m*k)%k == 0) m2--;
		if(n1 != n2){
			if(Math.abs((n1 - n2)) < n -n1 + n2 )
			time += Math.abs((n1 - n2)*15);
			else
				time +=(n -n1 + n2)*15;
			if(m1 > 3) time+= (10 + m1-1);
			else time += (5 * (m1-1));
			if(m2 > 3) time+= (10 + m2-1);
			else time += (5 * (m2-1));
		}else {

			if(Math.abs(m1- m2) > 2) time+= (10 + Math.abs(m1- m2));
			else time += (5 * Math.abs(m1- m2));
		}
		System.out.println(time);

	}

}


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

public class A_RegularBracketSequence {
    private static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    private static BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));

    public static void main(String[] args)throws IOException {
        long ct1 = Long.parseLong(br.readLine());
        long ct2 = Long.parseLong(br.readLine());
        long ct3 = Long.parseLong(br.readLine());
        long ct4 = Long.parseLong(br.readLine());

        Stack<Integer> stack = new Stack<>();
        for(int i=0;i<ct1;i++){
            stack.push(1);
            stack.push(1);
        }
        for(int i=0;i<ct2;i++){
            stack.push(1);
            stack.pop();
        }
        int flag=0;
        for(int i=0;i<ct3;i++){
            if(stack.empty()){
                flag=1;
                break;
            }
        }
        for(int i=0;i<2*ct4&& flag==0;i++){
            if(stack.empty()){
                flag=1;
                break;
            }
            stack.pop();
        }

        if(flag==1)
            bw.write(0+"\n");
        else
            bw.write(1+"\n");

        bw.flush();
    }
}