import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class cf2 {
	static final double EPS = 1e-9;

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

	 //rec
	 int xr1=sc.nextInt(), yr1=sc.nextInt(), xr2=sc.nextInt(),yr2=sc.nextInt();
	 int xr3=sc.nextInt(), yr3=sc.nextInt(), xr4=sc.nextInt(),yr4=sc.nextInt();

	 Point pr1 = new Point(xr1, yr1);
	 Point pr2 = new Point(xr2, yr2);
	 Point pr3 = new Point(xr3, yr3);
	 Point pr4 = new Point(xr4, yr4);

	 LineSegment lr1 = new LineSegment(pr1, pr2);
	 LineSegment lr2 = new LineSegment(pr2, pr3);
	 LineSegment lr3 = new LineSegment(pr3, pr4);
	 LineSegment lr4 = new LineSegment(pr4, pr1);

	 //diamond
	 int xd1=sc.nextInt(), yd1=sc.nextInt(), xd2=sc.nextInt(),yd2=sc.nextInt();
	 int xd3=sc.nextInt(), yd3=sc.nextInt(), xd4=sc.nextInt(),yd4=sc.nextInt();

	 Point p1 = new Point(xd1, yd1);
	 Point p2 = new Point(xd2, yd2);
	 Point p3 = new Point(xd3, yd3);
	 Point p4 = new Point(xd4, yd4);

	 Point [] pt = new Point [5];
	 pt[0]=p1;  pt[1]=p2;  pt[2]=p3;  pt[3]=p4;  pt[4]=p1;
	 Polygon pg = new Polygon(pt);

	 if(pg.inside(pr1)||pg.inside(pr2)||pg.inside(pr3)||pg.inside(pr4)) {
		 System.out.println("YES");
		 return;
	 }

	 LineSegment ld1 = new LineSegment(p1, p2);
	 LineSegment ld2 = new LineSegment(p2, p3);
	 LineSegment ld3 = new LineSegment(p3, p4);
	 LineSegment ld4 = new LineSegment(p4, p1);

	 Rectangle rec = new Rectangle(new Point(Math.min(Math.min(xr3,xr4),Math.min(xr1,xr2)), Math.min(Math.min(yr3,yr4),Math.min(yr1,yr2))),
			 new Point(Math.max(Math.max(xr3,xr4),Math.max(xr1,xr2)), Math.max(Math.max(yr3,yr4),Math.max(yr1,yr2))) );

	 if(rec.contains(p1)||rec.contains(p2)||rec.contains(p3)||rec.contains(p4)) {
		 System.out.println("YES");
	     return;
	 }

	 if(ld1.intersect(lr1)||ld1.intersect(lr3)||ld1.intersect(lr3)||ld1.intersect(lr4)) {
		 System.out.println("YES");
	     return;
	 }

	 if(ld2.intersect(lr1)||ld2.intersect(lr3)||ld2.intersect(lr3)||ld2.intersect(lr4)) {
		 System.out.println("YES");
	     return;
	 }

	 if(ld3.intersect(lr1)||ld3.intersect(lr3)||ld3.intersect(lr3)||ld3.intersect(lr4)) {
		 System.out.println("YES");
	     return;
	 }

	 if(ld4.intersect(lr1)||ld4.intersect(lr3)||ld4.intersect(lr3)||ld4.intersect(lr4)) {
		 System.out.println("YES");
	     return;
	 }

	 System.out.println("NO");

}

  public static class Polygon {
		// Cases to handle: collinear points, polygons with n < 3

		static final double EPS = 1e-9;

		Point[] g; 			//first point = last point, counter-clockwise representation

		Polygon(Point[] o) { g = o; }

		double perimeter()
		{
			double sum = 0.0;
			for(int i = 0; i < g.length - 1; ++i)
				sum += g[i].dist(g[i+1]);
			return sum;
		}

		double area() 		//clockwise/anti-clockwise check, for convex/concave polygons
		{
			double area = 0.0;
			for(int i = 0; i < g.length - 1; ++i)
				area += g[i].x * g[i+1].y - g[i].y * g[i+1].x;
			return Math.abs(area) / 2.0;			//negative value in case of clockwise
		}

		boolean inside(Point p)	//for convex/concave polygons - winding number algorithm
		{
			double sum = 0.0;
			for(int i = 0; i < g.length - 1; ++i)
			{
				double angle = Point.angle(g[i], p, g[i+1]);
				if((Math.abs(angle) < EPS || Math.abs(angle - Math.PI) < EPS) && p.between(g[i], g[i+1]))
					return true;
				if(Point.ccw(p, g[i], g[i+1]))
					sum += angle;
				else
					sum -= angle;
			}

			return Math.abs(2 * Math.PI - Math.abs(sum)) < EPS;		//abs makes it work for clockwise
		}
		/*
		 * Another way if the polygon is convex
		 * 1. Triangulate the poylgon through p
		 * 2. Check if sum areas == poygon area
		 * 3. Handle empty polygon
		 */

		Point centroid()		//center of mass
		{
			double cx = 0.0, cy = 0.0;
			for(int i = 0; i < g.length - 1; i++)
			{
				double x1 = g[i].x, y1 = g[i].y;
				double x2 = g[i+1].x, y2 = g[i+1].y;

				double f = x1 * y2 - x2 * y1;
				cx += (x1 + x2) * f;
				cy += (y1 + y2) * f;
			}
			double area = area();		//remove abs
			cx /= 6.0 * area;
			cy /= 6.0 * area;
			return new Point(cx, cy);
		}
	}

   static class LineSegment {

		Point p, q;

		LineSegment(Point a, Point b) { p = a; q = b; }

		boolean intersect(LineSegment ls)
		{
			Line l1 = new Line(p, q), l2 = new Line(ls.p, ls.q);
			if(l1.parallel(l2))
			{
				if(l1.same(l2))
					return p.between(ls.p, ls.q) || q.between(ls.p, ls.q) || ls.p.between(p, q) || ls.q.between(p, q);
				return false;
			}
			Point c = l1.intersect(l2);
			return c.between(p, q) && c.between(ls.p, ls.q);
		}

	}

   static class Rectangle {

		static final double EPS = 1e-9;

		Point ll, ur;

		Rectangle(Point a, Point b) { ll = a; ur = b; }

		double area() { return (ur.x - ll.x) * (ur.y - ll.y); }

		boolean contains(Point p)
		{
			return p.x <= ur.x + EPS && p.x + EPS >= ll.x && p.y <= ur.y + EPS && p.y + EPS >= ll.y;
		}

		Rectangle intersect(Rectangle r)
		{
			Point ll = new Point(Math.max(this.ll.x, r.ll.x), Math.max(this.ll.y, r.ll.y));
			Point ur = new Point(Math.min(this.ur.x, r.ur.x), Math.min(this.ur.y, r.ur.y));
			if(Math.abs(ur.x - ll.x) > EPS && Math.abs(ur.y - ll.y) > EPS && this.contains(ll) && this.contains(ur) && r.contains(ll) && r.contains(ur))
				return new Rectangle(ll, ur);
			return null;
		}

	}
   static class Line {

		static final double INF = 1e9, EPS = 1e-9;

		double a, b, c;

		Line(Point p, Point q)
		{
			if(Math.abs(p.x - q.x) < EPS) {	a = 1; b = 0; c = -p.x;	}
			else
			{
				a = (p.y - q.y) / (q.x - p.x);
				b = 1.0;
				c = -(a * p.x + p.y);
			}

		}

		Line(Point p, double m) { a = -m; b = 1; c =  -(a * p.x + p.y); }

		boolean parallel(Line l) { return Math.abs(a - l.a) < EPS && Math.abs(b - l.b) < EPS; }

		boolean same(Line l) { return parallel(l) && Math.abs(c - l.c) < EPS; }

		Point intersect(Line l)
		{
			if(parallel(l))
				return null;
			double x = (b * l.c - c * l.b) / (a * l.b - b * l.a);
			double y;
			if(Math.abs(b) < EPS)
				 y = -l.a * x - l.c;
			else
				y = -a * x - c;

			return new Point(x, y);
		}

		Point closestPoint(Point p)
		{
			if(Math.abs(b) < EPS) return new Point(-c, p.y);
			if(Math.abs(a) < EPS) return new Point(p.x, -c);
			return intersect(new Line(p, 1 / a));
		}

	}

   public static class Vector {

		double x, y;

		Vector(double a, double b) { x = a; y = b; }

		Vector(Point a, Point b) { this(b.x - a.x, b.y - a.y); }

		Vector scale(double s) { return new Vector(x * s, y * s); }              //s is a non-negative value

		double dot(Vector v) { return (x * v.x + y * v.y); }

		double cross(Vector v) { return x * v.y - y * v.x; }

		double norm2() { return x * x + y * y; }

		Vector reverse() { return new Vector(-x, -y); }

		Vector normalize()
		{
			double d = Math.sqrt(norm2());
			return scale(1 / d);
		}
	}

   static class Point implements Comparable<Point>{

		static final double EPS = 1e-9;

		double x, y;

		Point(double a, double b) { x = a; y = b; }

		public int compareTo(Point p)
		{
			if(Math.abs(x - p.x) > EPS) return x > p.x ? 1 : -1;
			if(Math.abs(y - p.y) > EPS) return y > p.y ? 1 : -1;
			return 0;
		}
		static double angle(Point a, Point o, Point b)  // angle AOB
		{
			Vector oa = new Vector(o, a), ob = new Vector(o, b);
			return Math.acos(oa.dot(ob) / Math.sqrt(oa.norm2() * ob.norm2()));
		}
		static boolean ccw(Point p, Point q, Point r)
		{
			return new Vector(p, q).cross(new Vector(p, r)) > 0;
		}

		public double dist(Point p) { return Math.sqrt(sq(x - p.x) + sq(y - p.y)); }

		static double sq(double x) { return x * x; }

		Point rotate(double angle)
		{
			double c = Math.cos(angle), s = Math.sin(angle);
			return new Point(x * c - y * s, x * s + y * c);
		}
		// for integer points and rotation by 90 (counterclockwise) : swap x and y, negate x

		boolean between(Point p, Point q)
		{
			return x < Math.max(p.x, q.x) + EPS && x + EPS > Math.min(p.x, q.x)
					&& y < Math.max(p.y, q.y) + EPS && y + EPS > Math.min(p.y, q.y);
		}

		//returns true if it is on the line defined by a and b

		//returns true if it is on the ray whose start point is a and passes through b
		// Another way: find closest point and calculate the distance between it and p
	}

	static class Scanner {
		StringTokenizer st;
		BufferedReader br;

		public Scanner(InputStream s) {
			br = new BufferedReader(new InputStreamReader(s));
		}

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

		public Scanner(String file) throws FileNotFoundException {
			br = new BufferedReader(new FileReader(file));
		}

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

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

		public String nextLine() throws IOException {
			return br.readLine();
		}

		public long nextlong() throws IOException {
			String x = next();
			StringBuilder sb = new StringBuilder("0");
			long res = 0, f = 1;
			boolean dec = false, neg = false;
			int start = 0;
			if (x.charAt(0) == '-') {
				neg = true;
				start++;
			}
			for (int i = start; i < x.length(); i++)
				if (x.charAt(i) == '.') {
					res = Long.parseLong(sb.toString());
					sb = new StringBuilder("0");
					dec = true;
				} else {
					sb.append(x.charAt(i));
					if (dec)
						f *= 10;
				}
			res += Long.parseLong(sb.toString()) / f;
			return res * (neg ? -1 : 1);
		}

		public boolean ready() throws IOException {
			return br.ready();
		}

	}
}


//q4

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

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

        int query = in.nextInt();

        while (query -- > 0) {
            int n = in.nextInt();
            int k = in.nextInt();

            char[] arr = new char[n];
            //slot all n into char array
            String code = in.next();
            for (int i = 0; i < n; i++) {
                arr[i] = code.charAt(i);

            }

            //R, G, B cycle
            int r = 0;
            int g = 0;
            int b = 0;

            for (int i = 0; i < k; i++) {
                if (i % 3 == 0) {
                    if (arr[i] == 'R') {g++; b++;}
                    else if (arr[i] == 'G') {r++; b++;}
                    else {r++; g++;} //if is 'B'
                } else if (i % 3 == 1) {
                    if (arr[i] == 'G') {g++; b++;}
                    else if (arr[i] == 'B') {r++; b++;}
                    else {r++; g++;} //if is 'R'
                } else { //if mod 3 is 2
                    if (arr[i] == 'B') {g++; b++;}
                    else if (arr[i] == 'R') {r++; b++;}
                    else {r++; g++;} //if is 'G'
                }
            }

            //starting from kth position, if different then add 1, and check (j-k)th position
            int rMin = r;
            int gMin = g;
            int bMin = b;
            for (int j = k; j < n; j++) {
                //R cycle
                if ((j % 3 == 0 && arr[j] != 'R') ||
                    (j % 3 == 1 && arr[j] != 'G') ||
                    (j % 3 == 2 && arr[j] != 'B')) {
                    r++;
                }
                //R cycle
                if (((j - k) % 3 == 0 && arr[j - k] != 'R') ||
                    ((j - k) % 3 == 1 && arr[j - k] != 'G') ||
                    ((j - k) % 3 == 2 && arr[j - k] != 'B')) {
                    r--;
                }
                rMin = Math.min(r, rMin);
                //G cycle
                if ((j % 3 == 0 && arr[j] != 'G') ||
                    (j % 3 == 1 && arr[j] != 'B') ||
                    (j % 3 == 2 && arr[j] != 'R')) {
                    g++;
                }
                if (((j - k) % 3 == 0 && arr[j - k] != 'G') ||
                    ((j - k) % 3 == 1 && arr[j - k] != 'B') ||
                    ((j - k) % 3 == 2 && arr[j - k] != 'R')) {
                    g--;
                }
                gMin = Math.min(gMin, g);
                //B cycle
                if ((j % 3 == 0 && arr[j] != 'B') ||
                    (j % 3 == 1 && arr[j] != 'R') ||
                    (j % 3 == 2 && arr[j] != 'G')) {
                    b++;
                }
                if (((j - k) % 3 == 0 && arr[j - k] != 'B') ||
                    ((j - k) % 3 == 1 && arr[j - k] != 'R') ||
                    ((j - k) % 3 == 2 && arr[j - k] != 'G')) {
                    b--;
                }
                bMin = Math.min(bMin, b);

            }

            System.out.println(Math.min(Math.min(rMin, gMin), bMin));

        }

    }

}


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.io.OutputStream;
import java.util.List;
import java.util.Arrays;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;

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

    static class TaskB {
        public void solve(int testNumber, FastReader in, PrintWriter out) {
            Debug debug = new Debug();
            int n = in.nextInt();
            int K = in.nextInt();

            List<Integer>[] g = GraphUtils.nextU(in, n, n - 1, true);
            int[] center = GraphUtils.getCenter(g);
            if (center.length == 2) {
                out.println("No");
                return;
            }

            int[][] pars = GraphUtils.parents3(g, center[0]);
            int[] par = pars[0], ord = pars[1], depth = pars[2];
            int[] deg = new int[n];
            for (int i = 0; i < n; ++i) deg[i] = g[i].size();

            if (deg[center[0]] < 3) {
                out.println("No");
                return;
            }

            // all leaves depth = K
            for (int i = 0; i < n; ++i) {
                if (deg[i] == 1) {
                    if (depth[i] != K) {
                        out.println("No");
                        return;
                    }
                } else if (i != center[0]) {
                    if (deg[i] < 4) {
                        out.println("No");
                        return;
                    }
                }
            }
            out.println("Yes");
        }

    }

    static class GraphUtils {
        public static List<Integer>[] nextU(FastReader in, int n, int m, boolean oneIndexed) {
            int diff = oneIndexed ? 1 : 0;
            List<Integer>[] g = new List[n];
            for (int i = 0; i < n; ++i) g[i] = new ArrayList<>();
            for (int i = 0; i < m; ++i) {
                int u = in.nextInt() - diff;
                int v = in.nextInt() - diff;
                g[u].add(v);
                g[v].add(u);
            }
            return g;
        }

        public static int[][] parents3(List<Integer>[] g, int root) {
            int n = g.length;
            int[] par = new int[n];
            ArrayUtils.fill(par, -1);

            int[] depth = new int[n];
            depth[0] = 0;

            int[] q = new int[n];
            q[0] = root;
            for (int p = 0, r = 1; p < r; p++) {
                int cur = q[p];
                for (int nex : g[cur]) {
                    if (par[cur] != nex) {
                        q[r++] = nex;
                        par[nex] = cur;
                        depth[nex] = depth[cur] + 1;
                    }
                }
            }
            return new int[][]{par, q, depth};
        }

        public static int[] getCenter(List<Integer>[] g) {
            int n = g.length;
            int[] q = new int[n];
            int[] deg = new int[n];
            int p = 0;
            for (int i = 0; i < n; i++) {
                deg[i] = g[i].size();
                if (g[i].size() <= 1) { // < for n=1
                    q[p++] = i;
                }
            }
            int bound = p == n ? 0 : p;
            for (int z = 0; z < p; z++) {
                if (bound == z && p < n) bound = p;
                int cur = q[z];
                deg[cur]--;
                for (int e : g[cur]) {
                    if (--deg[e] == 1) q[p++] = e;
                }
            }
            assert p == n;
            assert bound >= n - 2 && bound < n;
            if (bound == n - 2) {
                return new int[]{q[n - 2], q[n - 1]};
            } else {
                return new int[]{q[n - 1]};
            }
        }

    }

    static class FastReader {
        private InputStream stream;
        private byte[] buf = new byte[8192];
        private int curChar;
        private int pnumChars;

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

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

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

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

    }

    static class ArrayUtils {
        public static void fill(int[] array, int value) {
            Arrays.fill(array, value);
        }

    }

    static class Debug {
        PrintWriter out;
        boolean oj;
        boolean system;
        long timeBegin;
        Runtime runtime;

        public Debug(PrintWriter out) {
            oj = System.getProperty("ONLINE_JUDGE") != null;
            this.out = out;
            this.timeBegin = System.currentTimeMillis();
            this.runtime = Runtime.getRuntime();
        }

        public Debug() {
            system = true;
            oj = System.getProperty("ONLINE_JUDGE") != null;
            OutputStream outputStream = System.out;
            this.out = new PrintWriter(outputStream);
            this.timeBegin = System.currentTimeMillis();
            this.runtime = Runtime.getRuntime();
        }

    }
}


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

public class AAA {
	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st = new StringTokenizer(br.readLine());
		int n=Integer.parseInt(st.nextToken());
		int m=Integer.parseInt(st.nextToken());
		String a="";
		String b="";
		for(int i=0;i<1129;i++) {
			a+="1";
			b+="8";
		}
		a+="9";
		b+="1";

		System.out.println(a);
		System.out.println(b);
	}

}


    import java.util.*;
    import java.io.*;
    import java.lang.*;
    import java.math.*;
    public class B {
        public static void main(String[] args) throws Exception {
            BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
            PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out));
            int n = Integer.parseInt(bf.readLine());
            StringTokenizer st = new StringTokenizer(bf.readLine());
            Integer[] a = new Integer[n]; for(int i=0; i<n; i++) a[i] = Integer.parseInt(st.nextToken());
            Arrays.sort(a);
            int[] b = new int[n];
            for(int i=0; i<n; i++) b[i] = a[i].intValue();
            boolean diff = false;
            boolean diff2 = false;
            Set<Integer> vals = new HashSet<Integer>();
            vals.add(b[0]);
            int valval = 0;
            for(int i=1; i<n; i++) {
                vals.add(b[i]);
                if(b[i] == b[i-1]) {
                    if(!diff) {
                        diff = true;
                        valval = b[i];
                    }
                    else diff2 = true;
                }
            }
            long sum = 0;
            for(int i : b) sum += i;
            sum -= 1L*n*(n-1)/2;

            if(diff && !diff2) {
                if(!vals.contains((valval-1)) && (valval > 0)) {
                    if(sum%2 == 0) out.println("cslnb"); else out.println("sjfnb");
                }
                else out.println("cslnb");
            }
            else if(diff2) out.println("cslnb");
            else if(sum%2 == 0) out.println("cslnb"); else out.println("sjfnb");
            // int n = Integer.parseInt(st.nextToken());

            out.close(); System.exit(0);
        }
    }


//package ContestEd69;

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

public class mainD {
    public static PrintWriter out = new PrintWriter(System.out);
    public static FastScanner enter = new FastScanner(System.in);
    public static long[] arr;
    public static void main(String[] args) throws IOException {
        int n=enter.nextInt();
        int m=enter.nextInt();
        long k=enter.nextLong();
        arr=new long[n+1];
        for (int i = 1; i <n+1 ; i++) {
            arr[i]=enter.nextLong();
        }
        long[] summ=new long[n+1];
        for (int i = 1; i <n+1 ; i++) {
            summ[i]+=arr[i]+summ[i-1];
        }

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

        for (int i = 1; i <n+1 ; i++) {
            best[i]=Math.max(0, ((i-m>=0) ? best[i-m]+summ[i]-summ[i-m]-k:0));
        }
        long ans=best[1];

        for (int i = 1; i <n+1 ; i++) {
            ans=Math.max(ans,best[i]);
            for (int j = 1; j <m ; j++) {
                ans=Math.max(ans, ((i-j>=0) ? best[i-j] -k +summ[i]-summ[i-j]:0));
            }
        }
        System.out.println(ans);
    }

    static class FastScanner {
        BufferedReader br;
        StringTokenizer stok;

        FastScanner(InputStream is) {
            br = new BufferedReader(new InputStreamReader(is));
        }

        String next() throws IOException {
            while (stok == null || !stok.hasMoreTokens()) {
                String s = br.readLine();
                if (s == null) {
                    return null;
                }
                stok = new StringTokenizer(s);
            }
            return stok.nextToken();
        }

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

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

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

        char nextChar() throws IOException {
            return (char) (br.read());
        }

        String nextLine() throws IOException {
            return br.readLine();
        }
    }
}


import java.util.*;
import java.lang.*;
public class Main {
    static long m = 1000000007;
    static long powmod(long x, long y, long p)
    {
        // Initialize result
        long res = 1;

        // Update x if it is more
        // than or equal to p
        x = x % p;

        while (y > 0)
        {
            // If y is odd, multiply x
            // with result
            if((y & 1)==1)
                res = (res * x) % p;

            // y must be even now
            // y = y / 2
            y = y >> 1;
            x = (x * x) % p;
        }
        return res;
    }

    static long mulmod(long a, long b, long mod){
        long res=0;
        a = a % mod;
        while (b > 0)
        {
            // If b is odd, add 'a' to result
            if (b % 2 == 1)
                res = (res + a) % mod;

            // Multiply 'a' with 2
            a = (a * 2) % mod;

            // Divide b by 2
            b /= 2;
        }

        // Return result
        return res % mod;
    }

    public static void main(String args[] ) throws Exception {
        Scanner sc = new Scanner(System.in);
        long x = sc.nextLong();
        long k = sc.nextLong();
        if(x>0) {
            long d= powmod(2,k,m);
            long ans= mulmod(d,2,m)%m;
            ans= mulmod(ans,x,m)%m;
            ans++;
            ans%=m;
            ans= (ans-d+m)%m;
            System.out.println(ans);
        }
        else
            System.out.println(0);
    }
}


import java.util.*;
import java.io.*;
import java.lang.*;
import java.math.*;
import java.util.Map.*;
public class codeforces {
     static int count =0;
     static boolean f=false;
     static int [] arr;
	static 	PrintWriter pw=new PrintWriter(System.out);
	static void solve(int index , int mask) {
		if(index==arr.length) {
			int sum1=0; int sum2=0;
			for(int i=0;i<arr.length;i++) {
				if((mask & 1<<i)!=0) sum1+=arr[i];

			}
			return;
		}
		solve(index+1, mask | 1<<index);
		solve(index+1, mask);
	}
	public static void main(String [] args) throws IOException, InterruptedException {
		Scanner sc=new Scanner(System.in);
		int x=sc.nextInt();
		int y=sc.nextInt();
		pair [] arr=new pair[x];
		for(int i=0;i<x;i++) arr[i]=new pair(i, sc.nextInt(),0);
		for(int i=0;i<x;i++) arr[i].y=sc.nextInt();
		Arrays.sort(arr);
		PriorityQueue<Integer> qq=new PriorityQueue<>();
		//pw.println(Arrays.toString(arr));
		Long [] list=new Long [x];
		long sum=0;
		for(int i=0;i<x;i++) {
			pair w=arr[i];
			if(qq.size()<y) {
				qq.add(w.y);
				sum+=w.y;
				list[w.i]=sum;

			}else if(!qq.isEmpty()) {
				sum+=w.y;
				list[w.i]=sum;
				int first=qq.poll();
				if(w.y>first) {
					sum-=first;
					qq.add(w.y);
				}else {
					qq.add(first);
					sum-=w.y;
				}
			} else list[w.i]=(long) w.y;
			//pw.println(qq);
		}
		for(Long w:list) pw.print(w+" ");
		pw.flush();
		pw.close();
	}

	static class pair implements Comparable<pair>{
		String  name; int x,y,i ;
		public pair(String name , int x) {
			this.name=name; this.x=x;
		}

		public pair (int i,int x,int y) {
			this.i=i; this.x=x; this.y=y;
		}
		public int compareTo(pair o) {
			return x-o.x;
		}
		public int compareTo1(pair o) {
			if(!name.equals(o.name))
				return name.compareTo(o.name);
			return x-o.x;
		}
		public String toString() {
			return i+" "+x+" "+y;
		}
	}

   static class Scanner {
		StringTokenizer st;
		BufferedReader br;

		public Scanner(InputStream system) {
			br = new BufferedReader(new InputStreamReader(system));
		}

		public Scanner(String file) throws Exception {
			br = new BufferedReader(new FileReader(file));
		}

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

		public String nextLine() throws IOException {
			return br.readLine();
		}

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

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

		public char nextChar() throws IOException {
			return next().charAt(0);
		}

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

		public boolean ready() throws IOException {
			return br.ready();
		}

		public void waitForInput() throws InterruptedException {
			Thread.sleep(3000);
		}
	}
	}


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

public class Codeforces913F {
	public static void main(String[] args) throws IOException {
		Scanner input = new Scanner(System.in);
		int n = input.nextInt();
		int a = input.nextInt();
		int b = input.nextInt();
		input.close();
		final int mod = 998244353;

		int frac = multiply(a, inverse(b, mod), mod);
		int reverse = (mod+1-frac)%mod;

		int[] fracpower = new int[n+1];
		int[] reversepower = new int[n+1];
		fracpower[0] = 1;
		reversepower[0] = 1;
		for (int i = 1; i <= n; i++) {
			fracpower[i] = multiply(fracpower[i-1], frac, mod);
			reversepower[i] = multiply(reversepower[i-1], reverse, mod);
		}

		int[][] dp1 = new int[n+1][n+1];
		dp1[2][1] = 1;
		for (int i = 3; i <= n; i++) {
			for (int j = 1; j < i; j++) {
				if (j == 1) {
					dp1[i][j] = fracpower[i-1];
				}
				else {
					dp1[i][j] = multiply(dp1[i-1][j-1], fracpower[i-j], mod);
				}
				if (j == i-1) {
					dp1[i][j] += reversepower[i-1];
					dp1[i][j] %= mod;
				}
				else {
					dp1[i][j] += multiply(dp1[i-1][j], reversepower[j], mod);
					dp1[i][j] %= mod;
				}
			}
		}

		int[][] dp2 = new int[n+1][n+1];
		dp2[1][1] = 1;
		dp2[2][1] = 1;
		dp2[2][2] = 0;
		for (int i = 3; i <= n; i++) {
			int val = 0;
			for (int j = 1; j < i; j++) {
				dp2[i][j] = multiply(dp2[j][j], dp1[i][j], mod);
				val += dp2[i][j];
				val %= mod;
			}
			dp2[i][i] = (mod+1-val)%mod;
		}

		/*for (int i = 2; i <= n; i++) {
			for (int j = 1; j <= i; j++) {
				System.out.print(dp2[i][j] + " ");
			}
			System.out.println();
		}*/

		int[] EV = new int[n+1];
		EV[1] = 0;
		EV[2] = 1;
		for (int i = 3; i <= n; i++) {
			int val = 0;
			for (int j = 1; j < i; j++) {
				int r = j*(i-j) + (j*(j-1))/2 + EV[i-j] + EV[j];
				r %= mod;
				val += multiply(dp2[i][j], r, mod);
				val %= mod;
			}
			val += multiply((i*(i-1))/2, dp2[i][i], mod);
			val %= mod;

			int s = (mod+1-dp2[i][i])%mod;
			EV[i] = multiply(val, inverse(s, mod), mod);
		}

		System.out.println(EV[n]);
	}

	public static int multiply(int a, int b, int mod) {
		long x = (long)a*(long)b;
		return (int) (x%mod);
	}

	public static int inverse (int a, int n) {
		int m = n;
		int r1 = 1;
		int r2 = 0;
		int r3 = 0;
		int r4 = 1;
		while ((a > 0) && (n > 0)) {
			if (n >= a) {
				r3 -= r1*(n/a);
				r4 -= r2*(n/a);
				n = n%a;
			}
			else {
				int tmp = a;
				a = n;
				n = tmp;
				tmp = r1;
				r1 = r3;
				r3 = tmp;
				tmp = r2;
				r2 = r4;
				r4 = tmp;
			}
		}
		if (a == 0) {
			if (r3 >= 0)
				return (r3%m);
			else
				return (m+(r3%m));
		}
		else {
			if (r1 >= 0)
				return (r1%m);
			else
				return (m+(r1%m));
		}

	}
}


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

public class Main {

    public static void main(String[] args) throws Exception {

        new Main().go();
    }

    PrintWriter out;
    Reader in;
    BufferedReader br;

    Main() throws IOException {

        try {

            //br = new BufferedReader( new FileReader("input.txt") );
            //in = new Reader("input.txt");
            in = new Reader("input.txt");
            out = new PrintWriter( new BufferedWriter(new FileWriter("output.txt")) );
        }
        catch (Exception e) {

            //br = new BufferedReader( new InputStreamReader( System.in ) );
            in = new Reader();
            out = new PrintWriter( new BufferedWriter(new OutputStreamWriter(System.out)) );
        }
    }

    void go() throws Exception {

        //int t = in.nextInt();
        int t = 1;
        while (t > 0) {
            solve();
            t--;
        }

        out.flush();
        out.close();
    }

    int inf = 2000000000;
    int mod = 1000000007;
    double eps = 0.000000001;

    int n;
    int m;

    ArrayList<Pair>[] g;
    String s;
    int[][] a;
    void solve() throws IOException {
        int n = in.nextInt();
        int m = in.nextInt();
        a = new int[n][m];
        for (int i = 0; i < n; i++) {
            String s = in.nextLine();
            for (int j = 0; j < m; j++) {
                a[i][j] = s.charAt(j);
            }
        }

        int[][] f = new int[n][m];
        for (int i = 0; i < n; i++)
            for (int j = 0; j < m; j++)
                f[i][j] = inf;

        for (int i = 0; i < n; i++) {
            int cnt = 0;
            for (int j = 0; j < m; j++) {
                if (a[i][j] == '*') {
                    f[i][j] = Math.min(f[i][j], cnt);
                    cnt++;
                } else {
                    cnt = 0;
                }
            }
        }

        for (int i = 0; i < n; i++) {
            int cnt = 0;
            for (int j = m - 1; j >= 0; j--) {
                if (a[i][j] == '*') {
                    f[i][j] = Math.min(f[i][j], cnt);
                    cnt++;
                } else {
                    cnt = 0;
                }
            }
        }

        for (int j = 0; j < m; j++) {
            int cnt = 0;
            for (int i = 0; i < n; i++) {
                if (a[i][j] == '*') {
                    f[i][j] = Math.min(f[i][j], cnt);
                    cnt++;
                } else {
                    cnt = 0;
                }
            }
        }

        for (int j = 0; j < m; j++) {
            int cnt = 0;
            for (int i = n - 1; i >= 0; i--) {
                if (a[i][j] == '*') {
                    f[i][j] = Math.min(f[i][j], cnt);
                    cnt++;
                } else {
                    cnt = 0;
                }
            }
        }

        ArrayList<Item> ans = new ArrayList<>();
        for (int i = 0; i < n; i++)
            for (int j = 0; j < m; j++) {
                if (a[i][j] == '*' && f[i][j] > 0)
                    ans.add(new Item(i + 1, j + 1, f[i][j]));
            }
        boolean[][] used = new boolean[n][m];
        for (int i = 0; i < n; i++) {
            int cnt = 0;
            for (int j = 0; j < m; j++) {
                if (a[i][j] == '*' && f[i][j] > 0) {
                    cnt = Math.max(cnt, f[i][j] + 1);
                }
                if (cnt > 0) used[i][j] = true;
                cnt--;
            }
            cnt = 0;
            for (int j = m - 1; j >= 0; j--) {
                if (a[i][j] == '*' && f[i][j] > 0) {
                    cnt = Math.max(cnt, f[i][j] + 1);
                }
                if (cnt > 0) used[i][j] = true;
                cnt--;
            }
        }

        for (int j = 0; j < m; j++) {
            int cnt = 0;
            for (int i = 0; i < n; i++) {
                if (a[i][j] == '*' && f[i][j] > 0) {
                    cnt = Math.max(cnt, f[i][j] + 1);
                }
                if (cnt > 0) used[i][j] = true;
                cnt--;
            }
            cnt = 0;
            for (int i = n - 1; i >= 0; i--) {
                if (a[i][j] == '*' && f[i][j] > 0) {
                    cnt = Math.max(cnt, f[i][j] + 1);
                }
                if (cnt > 0) used[i][j] = true;
                cnt--;
            }
        }

        for (int i = 0; i < n; i++)
            for (int j = 0; j < m; j++)
                if (a[i][j] == '*' && !used[i][j]) {
                    out.println(-1);
                    return;
                }

        out.println(ans.size());
        for (Item i : ans)
            out.println(i.a + " " + i.b + " " + i.c);
    }

    class Pair implements Comparable<Pair>{

        int a;
        int b;

        Pair(int a, int b) {

            this.a = a;
            this.b = b;
        }

        public int compareTo(Pair p) {
            if (a != p.a)
                return Integer.compare(a, p.a);
            else
                return Integer.compare(b, p.b);
        }
    }

    class Item {

        int a;
        int b;
        int c;

        Item(int a, int b, int c) {
            this.a = a;
            this.b = b;
            this.c = c;
        }

    }

    class Reader {

        BufferedReader  br;
        StringTokenizer tok;

        Reader(String file) throws IOException {
            br = new BufferedReader( new FileReader(file) );
        }

        Reader() throws IOException {
            br = new BufferedReader( new InputStreamReader(System.in) );
        }

        String next() throws IOException {

            while (tok == null || !tok.hasMoreElements())
                tok = new StringTokenizer(br.readLine());
            return tok.nextToken();
        }

        int nextInt() throws NumberFormatException, IOException {
            return Integer.valueOf(next());
        }

        long nextLong() throws NumberFormatException, IOException {
            return Long.valueOf(next());
        }

        double nextDouble() throws NumberFormatException, IOException {
            return Double.valueOf(next());
        }

        String nextLine() throws IOException {
            return br.readLine();
        }

    }

    static class InputReader
    {
        final private int BUFFER_SIZE = 1 << 16;
        private DataInputStream din;
        private byte[] buffer;
        private int bufferPointer, bytesRead;

        public InputReader()
        {
            din = new DataInputStream(System.in);
            buffer = new byte[BUFFER_SIZE];
            bufferPointer = bytesRead = 0;
        }

        public InputReader(String file_name) throws IOException
        {
            din = new DataInputStream(new FileInputStream(file_name));
            buffer = new byte[BUFFER_SIZE];
            bufferPointer = bytesRead = 0;
        }

        public String readLine() throws IOException
        {
            byte[] buf = new byte[64]; // line length
            int cnt = 0, c;
            while ((c = read()) != -1)
            {
                if (c == '\n')
                    break;
                buf[cnt++] = (byte) c;
            }
            return new String(buf, 0, cnt);
        }

        public int nextInt() throws IOException
        {
            int ret = 0;
            byte c = read();
            while (c <= ' ')
                c = read();
            boolean neg = (c == '-');
            if (neg)
                c = read();
            do
            {
                ret = ret * 10 + c - '0';
            }  while ((c = read()) >= '0' && c <= '9');

            if (neg)
                return -ret;
            return ret;
        }

        public long nextLong() throws IOException
        {
            long ret = 0;
            byte c = read();
            while (c <= ' ')
                c = read();
            boolean neg = (c == '-');
            if (neg)
                c = read();
            do {
                ret = ret * 10 + c - '0';
            }
            while ((c = read()) >= '0' && c <= '9');
            if (neg)
                return -ret;
            return ret;
        }

        public double nextDouble() throws IOException
        {
            double ret = 0, div = 1;
            byte c = read();
            while (c <= ' ')
                c = read();
            boolean neg = (c == '-');
            if (neg)
                c = read();

            do {
                ret = ret * 10 + c - '0';
            }
            while ((c = read()) >= '0' && c <= '9');

            if (c == '.')
            {
                while ((c = read()) >= '0' && c <= '9')
                {
                    ret += (c - '0') / (div *= 10);
                }
            }

            if (neg)
                return -ret;
            return ret;
        }

        private void fillBuffer() throws IOException
        {
            bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE);
            if (bytesRead == -1)
                buffer[0] = -1;
        }

        private byte read() throws IOException
        {
            if (bufferPointer == bytesRead)
                fillBuffer();
            return buffer[bufferPointer++];
        }

        public void close() throws IOException
        {
            if (din == null)
                return;
            din.close();
        }
    }

}


import java.util.*;
import java.io.*;
import java.math.*;
public class Solution{
    public static void main(String[] args)throws IOException{
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int n = Integer.parseInt(br.readLine());
        StringTokenizer st = new StringTokenizer(br.readLine());
        int[] a = new int[n];
        for(int i=0;i<n;i++) a[i] = Integer.parseInt(st.nextToken());
        int ind = 0;
        for(int i=0;i<n;i++){
            if(a[i]==n){
                ind = i;
                break;
            }
        }
        boolean ok = true;
        for(int i=ind+1;i<n;i++) if(a[i]>a[i-1]) ok = false;
        for(int i=ind-1;i>=0;i--) if(a[i]>a[i+1]) ok = false;
        if(ok) 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 Solve4 {

    public static void main(String[] args) throws IOException {
      FastReader sc = new FastReader();
      int x= sc.nextInt();
      int y= sc.nextInt();
      int z= sc.nextInt();
      int t1= sc.nextInt();
      int t2= sc.nextInt();
      int t3= sc.nextInt();
      if(Math.abs(x-y)*t1 < (Math.abs(x-z)+Math.abs(x-y))*t2+3*t3 ) System.out.println("NO");
      else System.out.println("YES");
    }

    static class FastReader {

        BufferedReader br;
        StringTokenizer st;

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

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

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

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

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

        public String nextLine() {
            String s = "";
            try {
                s = br.readLine();
            } catch (IOException ex) {
            }
            return s;
        }
    }

}


import java.util.Scanner;

public class codef8 {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);
		int num = sc.nextInt();
		int beacon[] = new int[1000001];
		int pos[] = new int[num];
		for (int i = 0; i < num; i++) {
			int position = sc.nextInt();
			beacon[position] = sc.nextInt();
			pos[i] = position;
		}
		int dp[] = new int[1000001];
		int max = 0;
		if (beacon[0] != 0)
			dp[0] = 1;

		for (int i = 1; i <= 1000000; i++) {
			if (beacon[i] == 0) {
				dp[i] = dp[i-1];
			}
			else {
				int j = i - beacon[i] - 1;
				if (j < 0) {
					dp[i] = 1;
				}
				else {
					dp[i] = dp[j] + 1;
				}
			}
			max = Math.max(max, dp[i]);
		}
		System.out.println(num-max);
	}

}


import java.io.*;
public class coins
{
 public static void main(String args[])throws IOException
 {
  InputStreamReader read=new InputStreamReader(System.in);
  BufferedReader in=new BufferedReader(read);
  int i,k,n,v;
  String a;
  a=in.readLine();
  for(i=0;i<a.length();i++)
  {
   if(a.charAt(i)==' ')
   break;
  }
  n=Integer.parseInt(a.substring(0,i));
  v=Integer.parseInt(a.substring(i+1));
  k=v%n;
  v=v/n;
  if(k>0)
  v++;
  System.out.println(v);
 }
}


import java.io.*;

public class First {
    StreamTokenizer in;
    PrintWriter out;

    int nextInt() throws IOException {
        in.nextToken();
        return (int)in.nval;
    }

    long nextLong() throws IOException {
        in.nextToken();
        return (long) in.nval;
    }

    String nextString() throws IOException {
        in.nextToken();
        return in.sval;
    }

    void run() throws IOException {
        in = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));
        out = new PrintWriter(System.out);
        solve();
        out.flush();
    }

    void solve() throws IOException {
        int n = nextInt(), k = nextInt(), sum = 0, count = 0;
        String str = nextString();
        char[] arr = str.toCharArray();
        boolean[] bool = new boolean[26];
        for(char ch: arr){
            bool[((int)ch)-97] = true;
        }
        for(int i = 0; i < 26; i++){
            if(bool[i]){
                sum += i+1;
                count++;
                i += 1;
            }
            if(count == k) break;
        }
        if(count == k) out.println(sum);
        else out.println(-1);
    }

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


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

public class p7{

	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 sc = new FastReader();
        //PrintWriter out = new PrintWriter(System.out);
        int n = sc.nextInt();
		int k = sc.nextInt();
		long one = (long)Math.pow(2, k) - 1;

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

		arr[0] = 0;
		for(int i=1;i<=n;i++){
			arr[i] = sc.nextLong();
			arr[i] ^= arr[i-1];
		}

		Map<Long, Long> count = new HashMap<>();

		for(int i=0;i<=n;i++){
			Long key = Math.min(arr[i], (arr[i]^one));
			Long val = count.get(key);
			if(val==null) val = 0L;
			count.put(key, val+1);
		}

		long num = n;
		long ans = num*(num+1)/2;

		for(Map.Entry<Long, Long> ent: count.entrySet()){

			Long cnt = ent.getValue();

			long num1 = cnt/2;
			long num2 = (cnt+1)/2;

			ans -= ( (num1*(num1-1))/2 );
			ans -= ( (num2*(num2-1))/2 );
		}

		System.out.println(ans);
	}
}


import java.util.Scanner;
import java.util.Vector;

public class Main {

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        int a[] = new int[n];
        int b[] = new int[n];
        for (int i = 0; i < n; i++) a[i] = sc.nextInt();
        for (int i = 0; i < n; i++) b[i] = sc.nextInt();
        int c[] = new int[2 * n];
        c[0] = a[0];
        for (int i = 1; i < n; i++) {
            c[i * 2] = a[i];
            c[i * 2 - 1] = b[i];
            if (a[i] == 1 || b[i] == 1) {
                System.out.print(-1);
                System.exit(0);
            }
        }
        c[2 * n - 1] = b[0];
        if (a[0] == 1 || b[0] == 1) {
            System.out.print(-1);
            System.exit(0);
        }
        System.out.println(bin_search(c, m));
    }

    private static double bin_search(int[] c, int m) {
        double start = 0;
        double end = Integer.MAX_VALUE;
        double mid;
        while (start + 0.0000001 < end) {
            mid = (start + end) / 2;
            if (test(mid, m, c)) end = mid;
            else start = mid;
        }
        return end;
    }

    private static boolean test(double fuel, int m, int[] c) {
        for (int i = 0; i < c.length; i++) {
            fuel -= (m + fuel) / c[i];
            if (fuel < 0) {
                return false;
            }
        }
        return true;
    }
}


import java.util.Scanner;

public class FUck {

		public static void main(String args[])
		{
			Scanner scan=new Scanner(System.in);
			int n=scan.nextInt();
			int k=scan.nextInt();
			String t=scan.next();
			int mx=0;
			for(int i=1;i<n;i++)
			{
				int gd=1;
				for(int j=0;j<i;j++)
				{

					if(t.charAt(j)!=t.charAt((n-i)+j))
					{

						gd=0;
						// i think i can break here
					}
					}
				if(gd==1){
					mx=i;

				}
			}
			System.out.print(t);
			for(int i=2;i<=k;i++)
			{
				for(int j=mx;j<n;j++)
				{
					System.out.print(t.charAt(j));
				}
			}
		}
}


import java.util.*;
import java.io.*;
public class A
{
      public static void main(String ar[]) throws Exception
      {
            BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
            String s1[]=br.readLine().split(" ");
            String s2[]=br.readLine().split(" ");
            int n=Integer.parseInt(s1[0]);
            int m=Integer.parseInt(s1[1]);
            int a[]=new int[n];
            int b[]=new int[n];
            int c[]=new int[n];
            int d[]=new int[n];
            HashSet<Integer> hs=new HashSet<Integer>();
            hs.add(0);
            hs.add(m);
            int max=0;
            for(int i=0;i<n;i++)
            {
                  a[i]=Integer.parseInt(s2[i]);
                  if(i%2==0)
                   b[i]=1;
                  hs.add(a[i]);
            }

            c[0]=a[0];
            for(int i=1;i<n;i++)
            {
                  if(b[i]==0)
                   c[i]=c[i-1];
                  else
                   c[i]=c[i-1]+a[i]-a[i-1];
            }

            if(b[n-1]==0)
             d[n-1]=m-a[n-1];
            for(int i=n-2;i>=0;i--)
            {
                  if(b[i]==1)
                   d[i]=d[i+1];
                  else
                   d[i]=d[i+1]+a[i+1]-a[i];
            }

            max=c[n-1];
            if(b[n-1]==0)
             max+=m-a[n-1];
            //System.out.println(max);
            for(int i=n-1;i>=0;i--)
            {
                  int u=a[i]-1;
                  int v=a[i]+1;
                  if(!hs.contains(u))
                  {
                        if(b[i]==0)
                        {
                             int r=1+m-a[i]-d[i]+c[i-1];
                             max=Math.max(max,r);
                        }
                        else
                        {
                              int l=0;
                              if(i>0)
                               l=a[i-1];
                              int r=c[i]-1+m-a[i]-d[i];
                              max=Math.max(max,r);
                        }
                  }

                  if(!hs.contains(v))
                  {
                        if(b[i]==0)
                        {
                           if(i==n-1)
                           {
                              int r=c[i]+1;
                              max=Math.max(max,r);
                           }
                           else
                           {
                               int r=c[i]+1+m-a[i+1]-d[i+1];
                               max=Math.max(max,r);
                           }
                        }
                        else
                        {
                                if(i==n-1)
                                {
                                   int r=c[i]+m-a[i]-1;
                                   max=Math.max(max,r);
                                }
                                else
                                {
                                    int r=c[i]+m-a[i+1]-d[i+1]+a[i+1]-1-a[i];
                                    max=Math.max(max,r);
                                }
                        }
                  }
            }

            System.out.println(max);
      }
}


import java.util.*;
public class Main {
	public static void main(String[] args) {
		Scanner in =new Scanner(System.in);
		int n = in.nextInt();
		int k = in.nextInt();
		int[] arr = new int[n];
		for(int i = 0; i < n; i++)
			arr[i] = in.nextInt();
		for(int i = n-1; i > 0; i--)
			arr[i] -= arr[i-1];
		arr[0] = 0;
		Arrays.sort(arr);
		long sum = 0;
		for(int i = n-k; i >= 0; i--)
			sum += arr[i];
		System.out.println(sum);
	}
}


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

/* spar5h */

public class cf1 implements Runnable{

	public void run() {

		InputReader s = new InputReader(System.in);
		PrintWriter w = new PrintWriter(System.out);

		int t = 1;

		while(t-- > 0) {

			int n = s.nextInt(), m = s.nextInt();

			int[] a = new int[n + 1];

			for(int i = 1; i <= n; i++)
				a[i] = s.nextInt();

			int[] b = new int[n + 1];

			for(int i = 1; i <= n; i++)
				b[i] = s.nextInt();

			ArrayList<Integer> list = new ArrayList<Integer>();

			list.add(a[1]);

			for(int i = 2; i <= n; i++) {
				list.add(b[i]); list.add(a[i]);
			}

			list.add(b[1]);

			double wt = m;
			boolean check = true;

			for(int i = list.size() - 1; i >= 0; i--) {

				if(list.get(i) <= 1) {
					check = false; break;
				}

				double x = wt / (list.get(i) - 1);

				wt += x;
			}

			if(check)
				w.println(wt - m);
			else
				w.println(-1);
		}

		w.close();
	}

	static class InputReader {

		private InputStream stream;
		private byte[] buf = new byte[1024];
		private int curChar;
		private int numChars;
		private 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 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);
		}
	}

	public static void main(String args[]) throws Exception
	{
		new Thread(null, new cf1(),"cf1",1<<26).start();
	}
}


import java.io.*;
import java.util.Arrays;
import java.util.Comparator;
import java.util.StringTokenizer;
import java.util.stream.IntStream;

public class B {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));

        Solver solver = new Solver();
        solver.solve(in, out);
        out.close();
    }

    static class Solver {
        int n;
        int n2;
        InputReader in;
        PrintWriter out;

        public void solve(InputReader in, PrintWriter out) {
            this.in = in;
            this.out = out;
            n = in.readInt();
            n2 = n/2;

            int res = find();
            out.print("! ");
            out.println(res);
        }

        public int find() {
            if (n%4 != 0) return -1;
            int c = compare(0);
            if (c == 0) return 1;
            int s = 1;
            int f = n2-1;
            if (c > 0) {
                s = n2+1;
                f = n-1;
            }
            while (s <= f) {
                int m = (s+f)/2;
                int v = compare(m);
                if (v == 0) return m+1;
                else if (v < 0) s = m+1;
                else f = m-1;
            }
            return -1;
        }

        public int compare(int z) {
            out.print("? ");
            out.println(z+1);
            out.flush();
            int r1 = in.readInt();
            out.print("? ");
            out.println((z+n2)%n+1);
            out.flush();
            int r2 = in.readInt();
            return r1-r2;
        }

    }

    static class InputReader {
        private BufferedReader reader;
        private StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            this.reader = new BufferedReader(new InputStreamReader(stream));
        }

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

        public int readInt() {
            return Integer.parseInt(read());
        }

        public long readLong() {
            return Long.parseLong(read());
        }

        public void readIntArrays(int[]... arrays) {
            for (int i = 0; i < arrays[0].length; i++) {
                for (int j = 0; j < arrays.length; j++) {
                    arrays[j][i] = readInt();
                }
            }
        }
    }

}


import java.util.*;
import java.math.*;
public class Solution{
    private long [] sums;
    private void solve(){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        int k = sc.nextInt();
        int [] arr = new int[n];
        this.sums = new long[n];
        for(int i = 0; i < n; i++){
            arr[i] = sc.nextInt();
            sums[i] = arr[i] + (i == 0 ? 0 : sums[i - 1]);
        }
        long ans = 0;
        for(int i = 1; i <= n && i <= m; i++){
            ans = Math.max(ans, sum(0, i - 1) - k);
        }
        long [] dp = new long[n];
        for(int i = 0; i < n; i++){
            if(i + 1 >= m){
                long cur = sum(i - m + 1, i) - k;
                if(i - m >= 0){
                    cur += dp[i - m];
                }
                dp[i] = Math.max(dp[i], cur);
            }
            for(int j = 0; j <= m && i + j < n; j++){
                ans = Math.max(ans, dp[i] + sum(i + 1, i + j) - k * (j > 0 ? 1 : 0));
            }
        }
        System.out.println(ans);
    }
    private long sum(int l, int r){
        if(l <= 0){
            return sums[r];
        }else{
            return sums[r] - sums[l - 1];
        }
    }
    public static void main(String [] args){
        new Solution().solve();
    }
}


import java.util.*;

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

        int n = sc.nextInt();
        int m = sc.nextInt();

        long totalBlocks = 0;
        long a[] = new long[n];
        for(int i = 0; i < n; ++i) {
            a[i] = sc.nextLong();
            totalBlocks += a[i];
        }

        Arrays.sort(a);

        long selected = 0;
        for(int i = 0; i < n; ++i) {
            if(a[i] > selected)
                selected++;
        }

        long leftCols = a[n - 1] - selected;
        long remBlocks = totalBlocks - leftCols - n;

        System.out.print(remBlocks);
    }
}


/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

import java.util.ArrayList;
import java.util.Scanner;

/**
 *
 * @author Ahmed
 */

public class Watermelon {

   static class Passengers {

     public int floor ;
     public int time;

     public Passengers( int floor  , int time){
         this.floor =floor;
         this.time =time;
     }

}

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        // TODO code application logic here

        Scanner in = new Scanner(System.in);

        int x = in.nextInt() , y = in.nextInt();

        ArrayList<Passengers> list = new ArrayList<>();

        for(int i = 1 ; i <= x ; ++i){
            list.add(new Passengers(in.nextInt(), in.nextInt()));
        }

        int sum = 0 ;
       for(int i = list.size() - 1 ; i >= 0 ; --i)
       {
          int s = y -  list.get(i).floor;
          sum = sum + s ;

          if(sum < list.get(i).time)
          {
              sum = sum + ( list.get(i).time - sum);
          }

          y = list.get(i).floor;
       }

       if( list.get(list.size() - 1).floor != 0){
           sum = sum  + (list.get(0).floor);
       }
        System.out.println(sum);
    }

}


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

public class MinimumDiameterTree{
    public static void main(String[] args) {
	InputReader in = new InputReader (System.in);
	PrintWriter out = new PrintWriter (System.out);

	int n = in.nextInt();
	int s = in.nextInt();
	int deg[] = new int [n];

	for (int i = 1; i < n; ++i) {
	    deg[in.nextInt() - 1] ++;
	    deg[in.nextInt() - 1] ++;
	}

	int l = 0;
	for (int i = 0; i < n; ++i)
	    if (deg[i] == 1) l ++;

	out.println((double) 2 * s / l);
	out.close();
    }

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

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

	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 int nextInt() {
	    return Integer.parseInt(next());
	}

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


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

/**
 *
 * @author Antonio "Teo" Alurralde
 */
public class Main {
  public static void main(String[] args) throws IOException {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    int n = Integer.parseInt(br.readLine());
    StringTokenizer tok = new StringTokenizer(br.readLine());
    int ax = Integer.parseInt(tok.nextToken());
    int ay = Integer.parseInt(tok.nextToken());
    tok = new StringTokenizer(br.readLine());
    int bx = Integer.parseInt(tok.nextToken());
    int by = Integer.parseInt(tok.nextToken());
    tok = new StringTokenizer(br.readLine());
    int cx = Integer.parseInt(tok.nextToken());
    int cy = Integer.parseInt(tok.nextToken());
    boolean ans = (bx < ax && cx < ax && by < ay && cy < ay) ||
    (bx < ax && cx < ax && by > ay && cy > ay) ||
    (bx > ax && cx > ax && by < ay && cy < ay) ||
    (bx > ax && cx > ax && by > ay && cy > ay);
    System.out.print(ans?"YES":"NO");
  }
}


/**
 * Created by Aminul on 3/14/2019.
 */

import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.InputMismatchException;

import static java.lang.Math.max;

public class E_2 {
    public static void main(String[] args) throws Exception {
        FastReader in = new FastReader(System.in);
        PrintWriter pw = new PrintWriter(System.out);
        int n = in.nextInt(), k = in.nextInt(), N = (int) 5e6 + 1;
        int left = 0, right = 0;
        int a[] = new int[n + 1];
        for (int i = 1; i <= n; i++) {
            a[i] = in.nextInt();
            if (a[i] == k) left++;
        }
        int f[] = new int[N + 1];
        int ans = 0;
        for (int i = n; i >= 1; i--) {
            if (a[i] == k) left--;
            f[a[i]]++;
            f[a[i]] = max(f[a[i]], 1 + right);
            ans = max(ans, f[a[i]] + left);
            if (a[i] == k) right++;
        }
        pw.println(ans);
        pw.close();
    }

    static void debug(Object... obj) {
        System.err.println(Arrays.deepToString(obj));
    }

    static class FastReader {
        InputStream is;
        private byte[] inbuf = new byte[1024];
        private int lenbuf = 0, ptrbuf = 0;

        public FastReader(InputStream is) {
            this.is = is;
        }

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

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


import java.util.Scanner;

public class TreasureHunt {

	public static String Solve() {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		sc.nextLine();
		String kuro = sc.nextLine(), shiro = sc.nextLine(), katie = sc.nextLine();
		sc.close();
		String[] output = {"Kuro", "Shiro", "Katie", "Draw"};
		if(n >= kuro.length())
			return output[3];
		int[] maxArr = new int[3];
		int[][] freq = new int[3][58];
		for(int i = 0; i < kuro.length(); i++) {
			maxArr[0] = ++freq[0][kuro.charAt(i) - 65] > maxArr[0]? freq[0][kuro.charAt(i) - 65] : maxArr[0];
			maxArr[1] = ++freq[1][shiro.charAt(i) - 65] > maxArr[1]? freq[1][shiro.charAt(i) - 65] : maxArr[1];
			maxArr[2] = ++freq[2][katie.charAt(i) - 65] > maxArr[2]? freq[2][katie.charAt(i) - 65] : maxArr[2];
		}
		int winner = 0, max = 0;
		for(int i = 0; i < 3; i++) {
			if(kuro.length() - maxArr[i] >= n)
				maxArr[i] += n;
			else
				maxArr[i] = n == 1? kuro.length() - 1: kuro.length();
			if(max < maxArr[i]) {
				winner = i;
				max = maxArr[i];
			} else if(max == maxArr[i])
				winner = 3;
		}

		return output[winner];
	}
	public static void main(String[] args) {
		System.out.println(Solve());
	}
}


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

public class CF1197B {
    public static void main(String[] args) {
        FastReader input = new FastReader();
        int n = input.nextInt();
        int[] arr = new int[n];
        int max = 0;
        int maxIndex = 0;
        for(int i = 0;i < n;i++){
            arr[i] = input.nextInt();
            if(arr[i] > max){
                max = arr[i];
                maxIndex = i;
            }
        }
        int j = maxIndex - 1;
        int k = maxIndex + 1;
        while (j >= 0 && k < n){
            if(arr[j] > arr[k]){
                if(arr[j] < max){
                    max = arr[j];
                    j--;
                }
                else {
                    System.out.println("NO");
                    return;
                }
            }
            else{
                if(arr[k] < max){
                    max = arr[k];
                    k++;
                }
                else{
                    System.out.println("NO");
                    return;
                }
            }
        }
        if(j >= 0){
            while (j >= 0){
                if(arr[j] < max){
                    max = arr[j];
                    j--;
                }
                else{
                    System.out.println("NO");
                    return;
                }
            }
        }
        if(k < n){
            while (k < n){
                if(arr[k] < max){
                    max = arr[k];
                    k++;
                }
                else{
                    System.out.println("NO");
                    return;
                }
            }
        }
        if(j == -1 && k == n){
            System.out.println("YES");
        }
    }
    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;
        }
    }
}


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

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

    static class TaskC {
        BigInteger mod = new BigInteger("1000000007");

        public void solve(int testNumber, InputReader in, PrintWriter out) {
            BigInteger x = new BigInteger(in.next());
            BigInteger k = new BigInteger(in.next());
            if (x.longValue() == 0) {
                out.print(x);
                return;
            }
            BigInteger pow = powerWithMod(new BigInteger("2"), k);
            BigInteger current = x.mod(mod).multiply(pow).mod(mod);
            BigInteger result = current.multiply(new BigInteger("2")).mod(mod)
                    .subtract(pow.subtract(new BigInteger("1")).mod(mod))
                    .mod(mod);
            out.print(result);
        }

        BigInteger powerWithMod(BigInteger base, BigInteger exponent) {
            if (exponent.longValue() == 0) {
                return new BigInteger("1");
            }
            BigInteger temp = powerWithMod(base, exponent.divide(new BigInteger("2")));
            BigInteger term = temp.mod(mod);
            if (exponent.mod(new BigInteger("2")).intValue() == 0) {
                return term.multiply(term.mod(mod)).mod(mod);
            } else {
                return term.multiply(term.mod(mod)).multiply(base.mod(mod)).mod(mod);
            }
        }

    }

    static class InputReader {
        private BufferedReader reader;
        private StringTokenizer tokenizer;

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

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

    }
}


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

// author @mdazmat9
public  class codeforces{
    public static void main(String[] args) throws IOException {
        Scanner sc = new Scanner(System.in);
        PrintWriter out = new PrintWriter(System.out);
        int test = 1;
        for (int ind = 0; ind < test; ind++) {
          int [] a=new int[3];
          a[0]=sc.nextInt();
          a[1]=sc.nextInt();
          a[2]=sc.nextInt();
          Arrays.sort(a);
          int k1=a[0];
          int k2=a[1];
          int k3=a[2];
          if(k1==1 || k2==1 || k3==1){
              out.println("YES");
          }
          else if((k1==2 && k2==2)||(k2==2 && k3==2)){
              out.println("YES");
            }
            else if(k1==3 && k2==3 && k3==3){
              out.println("YES");
          }
          else if(k1==2 && k2==4 && k3==4){
              out.println("YES");
          }
          else
              out.println("NO");

        }
        out.flush();
    }

    static   void shuffle(int[] a) {
        int n = a.length;
        for(int i = 0; i < n; i++) {
            int r = i + (int) (Math.random() * (n - i));
            int tmp = a[i];
            a[i] = a[r];
            a[r] = tmp;
        }
    }
    static long gcd(long a , long b)
    {
        if(b == 0)
            return a;
        return gcd(b , a % b);
    }

}
class Scanner {
    public BufferedReader reader;
    public StringTokenizer st;

    public Scanner(InputStream stream) {
        reader = new BufferedReader(new InputStreamReader(stream));
        st = null;
    }

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

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

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

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

class OutputWriter {
    BufferedWriter writer;

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

    public void print(int i) throws IOException {
        writer.write(i);
    }

    public void print(String s) throws IOException {
        writer.write(s);
    }

    public void print(char[] c) throws IOException {
        writer.write(c);
    }

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

}


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

public class Main {

	static InputReader in = new InputReader(System.in);
	static PrintWriter out = new PrintWriter(System.out);

	static long oo = 1000000000000L;

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

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

		ArrayDeque<Integer> dq = new ArrayDeque<>();
		int max = -1;
		for(int i = 0; i < n; ++i) {
			int x = in.nextInt();
			dq.add(x);
			max = Math.max(max, x);
		}
		ArrayList<Pair> ans = new ArrayList<>();
		while(dq.peekFirst() != max) {
			int a = dq.pollFirst();
			int b = dq.pollFirst();
			ans.add(new Pair(a, b));
			if(a > b) {
				dq.addFirst(a);
				dq.addLast(b);
			}
			else {
				dq.addFirst(b);
				dq.addLast(a);
			}
		}
		ArrayList<Integer> a = new ArrayList<>();
		dq.pollFirst();
		for(int x : dq)
			a.add(x);
		while(q --> 0) {
			long m = in.nextLong() - 1;
			if(m < ans.size()) {
				System.out.println(ans.get((int)m).first + " " + ans.get((int)m).second);
			}
			else {
				int idx = (int)((m - ans.size()) % a.size());
				System.out.println(max + " " + a.get(idx));
			}
		}

		out.close();
	}

	static long lcm(long a, long b) {
		return a * b / gcd(a, b);
	}

	static boolean nextPermutation(int[] a) {
		for(int i = a.length - 2; i >= 0; --i) {
			if(a[i] < a[i+1]) {
				for(int j = a.length - 1; ; --j) {
					if(a[i] < a[j]) {
						int t = a[i];
						a[i] = a[j];
						a[j] = t;
						for(i++, j = a.length - 1; i < j; ++i, --j) {
							t = a[i];
							a[i] = a[j];
							a[j] = t;
						}
						return true;
					}
				}
			}
		}
		return false;
	}

	static void shuffle(int[] a) {
		Random r = new Random();
		for(int i = a.length - 1; i > 0; --i) {
			int si = r.nextInt(i);
			int t = a[si];
			a[si] = a[i];
			a[i] = t;
		}
	}

	static void shuffle(long[] a) {
		Random r = new Random();
		for(int i = a.length - 1; i > 0; --i) {
			int si = r.nextInt(i);
			long t = a[si];
			a[si] = a[i];
			a[i] = t;
		}
	}

	static int lower_bound(int[] a, int n, int k) {
		int s = 0;
		int e = n;
		int m;
		while (e - s > 0) {
			m = (s + e) / 2;
			if (a[m] < k)
				s = m + 1;
			else
				e = m;
		}
		return e;
	}
	static int lower_bound(long[] a, int n, long k) {
		int s = 0;
		int e = n;
		int m;
		while (e - s > 0) {
			m = (s + e) / 2;
			if (a[m] < k)
				s = m + 1;
			else
				e = m;
		}
		return e;
	}

	static int gcd(int a, int b) {
		return b == 0 ? a : gcd(b, a % b);
	}
	static long gcd(long a, long b) {
		return b == 0 ? a : gcd(b, a % b);
	}

	static class Pair implements Comparable<Pair> {
		int first, second;

		public Pair(int first, int second) {
			super();
			this.first = first;
			this.second = second;
		}

		@Override
		public int compareTo(Pair o) {
			return this.first != o.first ? this.first - o.first : this.second - o.second;
		}

		@Override
		public int hashCode() {
			final int prime = 31;
			int result = 1;
			result = prime * result + first;
			result = prime * result + second;
			return result;
		}

		@Override
		public boolean equals(Object obj) {
			if (this == obj)
				return true;
			if (obj == null)
				return false;
			if (getClass() != obj.getClass())
				return false;
			Pair other = (Pair) obj;
			if (first != other.first)
				return false;
			if (second != other.second)
				return false;
			return true;
		}
	}

}

class InputReader {

	private final InputStream stream;
	private final byte[] buf = new byte[8192];
	private int curChar, snumChars;

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

	public int read() {
		if (snumChars == -1)
			throw new InputMismatchException();
		if (curChar >= snumChars) {
			curChar = 0;
			try {
				snumChars = stream.read(buf);
			} catch (IOException e) {
				throw new InputMismatchException();
			}
			if (snumChars <= 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 {
			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 {
			res *= 10;
			res += c - '0';
			c = read();
		} while (!isSpaceChar(c));
		return res * sgn;
	}

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

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

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

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

}


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

public class AAA {
	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st = new StringTokenizer(br.readLine());
		int n=Integer.parseInt(st.nextToken());
		int m=Integer.parseInt(st.nextToken());
		String a="";
		String b="";
		for(int i=0;i<1129;i++) {
			a+="1";
			b+="8";
		}
		a+="9";
		b+="1";

		System.out.println(a);
		System.out.println(b);
	}

}


import java.io.BufferedOutputStream;
import java.io.PrintWriter;
import java.util.*;

public class E1180D {

    public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);
        PrintWriter pw = new PrintWriter(new BufferedOutputStream(System.out));
        int n = sc.nextInt();
        int m = sc.nextInt();

        // Move from both ends, Time limit exceeded on test 6
        for (int i= 1; i<= m/2; i++) {
            // String s = "";
            int i2 = m -i + 1; // the other end of i
            // i is left row, i2 is right row
            for (int j = 1; j <= n ; j++) {
                int j2 = n - j + 1;
                // start with (i,j), then go thru all the cell with (,i) and (,i2)
                pw.println(j + " " + i);
                pw.println(j2+ " " + i2);
                // s += j + " " + i + "\n" + j2+ " " + i2 + "\n";
            }
            // out.print(s);
        }

        // if n is odd, there is one line in the middle
        if (m % 2 == 1) {
            int i2 = m /2 + 1; // this is the middle column
            for (int j = 1; j <= n/2 ; j++) {
                int j2 = n - j + 1;
                // start with (i,j), then go thru all the cell with (,i) and (,i2)
                pw.println(j + " " + i2);
                pw.println(j2+ " " + i2);
            }
            if (n %2 == 1) {
                int j = n /2 + 1;
                pw.println(j + " " + i2);
            }
        }
        pw.flush();
        pw.close();
    }
}


import java.util.*;
import java.io.*;
import java.lang.*;
import java.math.*;
public class C {
    public static void main(String[] args) throws Exception {
        BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
        // Scanner scan = new Scanner(System.in);
        PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out));
        int n = Integer.parseInt(bf.readLine());
        int counter = 0;
        for(int i=0; i<2*n/3; i++) System.out.println("0 " + i);
        for(int i=0; i<n-2*n/3; i++) System.out.println("3 " + (2*i+1));

    }
}


import java.util.Scanner;

public class codef8 {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);
		int num = sc.nextInt();
		int beacon[] = new int[1000001];
		int pos[] = new int[num];
		for (int i = 0; i < num; i++) {
			int position = sc.nextInt();
			beacon[position] = sc.nextInt();
			pos[i] = position;
		}
		int dp[] = new int[1000001];
		int max = 1;
		if (beacon[0] != 0)
			dp[0] = 1;

		for (int i = 1; i <= 1000000; i++) {
			if (beacon[i] == 0) {
				dp[i] = dp[i-1];
			}
			else {
				int j = i - beacon[i] - 1;
				if (j < 0) {
					dp[i] = 1;
				}
				else {
					dp[i] = dp[j] + 1;
				}
			}
			max = Math.max(max, dp[i]);
		}
		System.out.println(num-max);
	}

}


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

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

    static class TaskD {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.nextInt();
            int[] a = new int[n];
            for (int i = 0; i < n; i++) {
                a[i] = in.nextInt();
            }
            int inv = 0;
            for (int i = 0; i < n; i++) {
                for (int j = 0; j < i; j++) {
                    if (a[j] > a[i]) {
                        inv++;
                    }
                }
            }
            int m = in.nextInt();
            for (int i = 0; i < m; i++) {
                int l = in.nextInt();
                int r = in.nextInt();
                int s = (r - l + 1) * (r - l) / 2;
                inv = (inv + s) % 2;
                out.println(inv % 2 == 0 ? "even" : "odd");
            }
        }

    }

    static class InputReader {
        private BufferedReader reader;
        private StringTokenizer stt;

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

        public String nextLine() {
            try {
                return reader.readLine();
            } catch (IOException e) {
                return null;
            }
        }

        public String next() {
            while (stt == null || !stt.hasMoreTokens()) {
                stt = new StringTokenizer(nextLine());
            }
            return stt.nextToken();
        }

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

    }
}


import com.sun.org.apache.xpath.internal.operations.Bool;

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

public class Main {

    public static void main(String[] args) throws Exception {
        MyScanner scan = new MyScanner();
        out = new PrintWriter(new BufferedOutputStream(System.out));

        int n = scan.nextInt();
        int[] vals = new int[n];
        for (int i = 0; i < n; i++) {
            vals[i] = scan.nextInt();
        }

        for (int i = 0; i < n; i++) {
            if (solve(i, vals)) {
                out.print('A');
            } else {
                out.print('B');
            }
        }

        out.close();
    }

    static HashMap<Integer, Boolean> dpResult = new HashMap<>();

    private static boolean solve(int pos, int[] vals) {
        if (dpResult.containsKey(pos)) return dpResult.get(pos);
        int val = vals[pos];
        boolean hasLose = false;
        for (int i = pos; i < vals.length; i += val) {
            if (i == pos) continue;
            if (vals[i] <= vals[pos]) continue;
            if (hasLose) break;
            if (!solve(i, vals)) {
                hasLose = true;
            }
        }
        for (int i = pos; i >= 0; i -= val) {
            if (i == pos) continue;
            if (vals[i] <= vals[pos]) continue;
            if (hasLose) break;
            if (!solve(i, vals)) {
                hasLose = true;
            }
        }
        dpResult.put(pos, hasLose);
        return hasLose;
    }

    //-----------PrintWriter for faster output---------------------------------
    public static PrintWriter out;

    //-----------MyScanner class for faster input----------
    public static class MyScanner {
        BufferedReader br;
        StringTokenizer st;

        public MyScanner() {
            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;
        }

    }
    //--------------------------------------------------------

}


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

public class Main {
    public void solve() {
        int n = ni();
        int a = ni();
        int b = ni();

        long ans = 0;
        HashMap<Long, Long> m = new HashMap<>();
        HashMap<String, Long> s = new HashMap<>();

        for (int i = 0; i < n; i++) {
            ni();
            long vx = ni();
            long vy = ni();
            long v = (long) a * vx - vy;
            String k = vx + "|" + vy;
            long cs = s.getOrDefault(k, 0L);
            long c = m.getOrDefault(v, 0L);
            ans += c - cs;
            m.put(v, c + 1);
            s.put(k, cs + 1);
        }
        write (ans * 2 + "\n");
    }

    public static void main(String[] args) {
        Main m = new Main();
        m.solve();
        try {
            m.out.close();
        } catch (IOException e) {}
    }

    BufferedReader in;
    BufferedWriter out;
    StringTokenizer tokenizer;
    public Main() {
        in = new BufferedReader(new InputStreamReader(System.in));
        out = new BufferedWriter(new OutputStreamWriter(System.out));
    }
    public String n() {
        if (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                tokenizer = new StringTokenizer(in.readLine());
            } catch (IOException e) {}
        }
        return tokenizer.nextToken();
    }
    public int ni() {
        return Integer.parseInt(n());
    }
    public long nl() {
        return Long.parseLong(n());
    }
    public void write(String s) {
        try {
            out.write(s);
        } catch (IOException e) {}
    }
}


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

public class pr1073B {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        PrintWriter out = new PrintWriter(System.out);

        int n = Integer.parseInt(br.readLine());

        int[] a = new int[n];
        int[] b = new int[n];

        StringTokenizer st = new StringTokenizer(br.readLine());

        for (int i = 0; i < n; i++) {
            a[i] = Integer.parseInt(st.nextToken());
        }
        st = new StringTokenizer(br.readLine());
        for (int i = 0; i < n; i++) {
            b[i] = Integer.parseInt(st.nextToken());
        }

        solve(n, a, b, out);
        out.flush();
        out.close();
    }

    private static void solve(int n, int[] a, int[] b, PrintWriter out) {
        boolean[] book = new boolean[n+1];
        boolean f;
        int j1 = 0, j2 = 0;
        for (int i = 0; i < n; i++) {
            f = false;
            int num = b[i];
            if(!book[num]) {
                f = true;
                j1 = j2;
                for (;j2 < n; j2++) {
                    book[a[j2]] = true;
                    if (a[j2] == num) {
                        j2++;
                        break;
                    }
                }
            }
            out.print(f ? j2-j1 + " ": 0 + " ");
        }
    }
}


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

public class LectureSleep {

    static class InputReader {
        BufferedReader reader;
        StringTokenizer tokenizer;

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

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

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

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

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

        public float nextFloat() {
            return Float.parseFloat(next());
        }

    }

    static InputReader r = new InputReader(System.in);
    static PrintWriter pw = new PrintWriter(System.out);

    public static void main(String[] args) {
        int n = r.nextInt(); // duration of lecture
        int k = r.nextInt(); // number of minutes keep mishka awake
        int[] theorems = new int[n+1];
        for(int i = 1; i <= n; i++){
            theorems[i] = r.nextInt();
        }
        int[] mishka = new int[n+1];
        for(int i = 1; i <= n; i++){
            mishka[i] = r.nextInt();
        }
        int[] sums = new int[n+1];
        for(int i = 1; i <= n; i++){
            if(mishka[i] == 0){
                sums[i] = sums[i-1] + theorems[i];
            } else{
                sums[i] = sums[i-1];
            }
        }
        int max = 0;
        for(int i = 1; i <= n-k+1; i++){
            int sum = sums[i+k-1] - sums[i-1];
            max = Math.max(max, sum);
        }
        int totalSum = 0;
        for(int i = 1; i <= n; i++){
            if(mishka[i] == 1){
                totalSum += theorems[i];
            }
        }

        pw.println(totalSum + max);

        pw.close();
    }
}


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

public class C {

	public static int mod = 1000000000 + 7;

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

		String n = br.readLine();
		int k = Integer.parseInt(br.readLine());
		int l = n.length();

		if(k == 0) {
			System.out.println(1);
		}else {
			int max = 1000;
			if (l <= 10) {
				max = Integer.min(1000, Integer.parseInt(n, 2));
			}

			int[] steps = new int[max + 1];

			for (int i = 2; i <= max; i++) {
				int ones = numberOfOnes(i);
				steps[i] = 1 + steps[ones];
			}

			if (l <= 10) {
				int ans = 0;
				for (int i = 1; i <= max; i++) {
					if (steps[i] == k) {
						ans++;
					}
				}
				System.out.println(ans);
			} else {
				int[][] C = binomial(max);

				int ans = 0;
				int count = 0;

				for (int i = 0; i < l; i++) {
					if (n.charAt(i) == '1') {
						for (int j = count; j < max; j++) {
							if (steps[j] == k - 1) {
								ans = (ans + C[l - i - 1][j - count]) % mod;
								if (i == 0 && k == 1) {
									ans = (ans + mod - 1) % mod;
								}
							}
						}
						count++;
					}
				}

				int ones = 0;
				for (int i = 0; i < l; i++) {
					if (n.charAt(i) == '1') {
						ones++;
					}
				}
				if (steps[ones] == k-1) {
					ans = (ans + 1) % mod;
				}

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

	public static int numberOfOnes(int x) {
		char[] s = Integer.toBinaryString(x).toCharArray();
		int count = 0;
		for (char c : s) {
			if (c == '1') {
				count++;
			}
		}
		return count;
	}

	public static int[][] binomial(int n) {
		int[][] C = new int[n + 1][n + 1];

		for (int i = 0; i <= n; i++) {
			C[i][0] = 1;
			for (int j = 1; j <= i; j++) {
				C[i][j] = ((C[i - 1][j - 1] % mod) + (C[i - 1][j] % mod)) % mod;
			}
		}

		return C;
	}

}

914_C. Travelling Salesman and Special Numbers


import java.io.BufferedReader;
import java.io.PrintWriter;

import java.io.InputStreamReader;

import java.io.IOException;

import java.util.StringTokenizer;

import java.util.Arrays;

public class Main {

    static Scanner in = new Scanner();
    static PrintWriter out = new PrintWriter(System.out);

    public static void main(String[] args) throws IOException {
        long n = in.nextLong(), m = in.nextLong();
        out.print(m / n + (m % n == 0 ? 0 : 1));
        out.close();
    }

    static class Scanner {
        BufferedReader br;
        StringTokenizer st;

        public Scanner() {
            br = new BufferedReader(new InputStreamReader(System.in));
            st = new StringTokenizer("");
        }

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

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

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