import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Set;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.TreeSet;
import java.util.ArrayList;
import java.util.List;
import java.util.AbstractCollection;
import java.util.TreeMap;
import java.util.StringTokenizer;
import java.util.Map;
import java.io.BufferedReader;
import java.util.Collections;
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;
        FastScanner in = new FastScanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskC solver = new TaskC();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskC {
        final double eps = 1e-8;

        public void solve(int testNumber, FastScanner in, PrintWriter out) {
            int n = in.nextInt();
            Circle[] circles = new Circle[n];
            for (int i = 0; i < n; i++) {
                int x = in.nextInt();
                int y = in.nextInt();
                int r = in.nextInt();
                circles[i] = new Circle();
                circles[i].o = new Point(x, y);
                circles[i].r = r;
            }

            Set<Point> all = new TreeSet<>();
            for (int i = 0; i < n; i++) {
                for (int j = i + 1; j < n; j++) {
                    List<Point> inter = intersect(circles[i], circles[j]);
                    if (inter == null) {
                        continue;
                    }
                    all.addAll(inter);
                }
            }

            Map<Point, Integer> pointId = new TreeMap<>();
            List<Set<Integer>> adj = new ArrayList<>();
            for (int i = 0; i < n; i++) {
                List<Double> angles = new ArrayList<>();
                final int K = 100;
                for (int j = 0; j < K; j++) {
                    angles.add(Math.PI * 2 * j / K);
                }
                for (Point p : all) {
                    if (circles[i].contains(p)) {
                        double dx = p.x - circles[i].o.x;
                        double dy = p.y - circles[i].o.y;
                        double alpha = Math.atan2(dy, dx);
                        if (alpha < 0) {
                            alpha += 2 * Math.PI;
                        }
                        angles.add(alpha);
                    }
                }
                Collections.sort(angles);
                Point dir = new Point(1, 0).scale(circles[i].r);
                Double[] as = new TreeSet<>(angles).toArray(new Double[0]);
                for (int j = 0; j < as.length; j++) {
                    Point p = circles[i].o.add(dir.rotate(as[j]));
                    getId(p, pointId, adj);
                }
                for (int j = 0; j < as.length; j++) {
                    Point p = circles[i].o.add(dir.rotate(as[j]));
                    Point q = circles[i].o.add(dir.rotate(as[(j + 1) % as.length]));
                    int u = pointId.get(p);
                    int v = pointId.get(q);
                    if (u == v) {
                        continue;
                    }
                    adj.get(u).add(v);
                    adj.get(v).add(u);
                }
            }

            int v = adj.size();
            int e = 0;
            for (int i = 0; i < v; i++) {
                e += adj.get(i).size();
            }
            e /= 2;

            int comps = 0;
            boolean[] was = new boolean[v];
            for (int i = 0; i < v; i++) {
                if (!was[i]) {
                    ++comps;
                    dfs(i, was, adj);
                }
            }

            out.println(1 + comps + e - v);
        }

        private void dfs(int i, boolean[] was, List<Set<Integer>> adj) {
            was[i] = true;
            for (int j : adj.get(i)) {
                if (!was[j]) {
                    dfs(j, was, adj);
                }
            }
        }

        private void getId(Point p, Map<Point, Integer> pointId, List<Set<Integer>> adj) {
            if (!pointId.containsKey(p)) {
                int sz = pointId.size();
                pointId.put(p, sz);
                adj.add(new TreeSet<>());
            }
        }

        private List<Point> intersect(Circle c1, Circle c2) {
            double dx = c1.o.x - c2.o.x;
            double dy = c1.o.y - c2.o.y;
            double d = Math.sqrt(dx * dx + dy * dy);
            double cos = (c1.r * c1.r + d * d - c2.r * c2.r) / (2 * c1.r * d);
            if (cos < -1 - eps) {
                return null;
            }
            if (cos < -1) {
                cos = -1;
            }
            if (cos > 1 + eps) {
                return null;
            }
            if (cos > 1) {
                cos = 1;
            }
            List<Point> res = new ArrayList<>();
            double alpha = Math.acos(cos);
            Point dir = c2.o.sub(c1.o).norm();
            res.add(c1.o.add(dir.scale(c1.r).rotate(+alpha)));
            res.add(c1.o.add(dir.scale(c1.r).rotate(-alpha)));
            return res;
        }

        class Point implements Comparable<Point> {
            double x;
            double y;

            Point(double x, double y) {
                this.x = x;
                this.y = y;
            }

            Point add(Point o) {
                return new Point(x + o.x, y + o.y);
            }

            Point sub(Point o) {
                return new Point(x - o.x, y - o.y);
            }

            Point rotate(double alpha) {
                double c = Math.cos(alpha);
                double s = Math.sin(alpha);
                double nx = x * c - y * s;
                double ny = x * s + y * c;
                return new Point(nx, ny);
            }

            Point norm() {
                double len = length();
                return scale(1.0 / len);
            }

            Point scale(double f) {
                return new Point(f * x, f * y);
            }

            double length() {
                return Math.sqrt(x * x + y * y);
            }

            public String toString() {
                return String.format("%.6f %.6f", x, y);
            }

            public boolean equals(Object obj) {
                Point o = (Point) obj;
                return Math.abs(x - o.x) < eps && Math.abs(y - o.y) < eps;
            }

            public int compareTo(Point o) {
                if (Math.abs(x - o.x) > eps) {
                    return x < o.x ? -1 : 1;
                }
                if (Math.abs(y - o.y) > eps) {
                    return y < o.y ? -1 : 1;
                }
                return 0;
            }

        }

        class Circle {
            Point o;
            double r;

            boolean contains(Point p) {
                double dist = p.sub(o).length();
                return Math.abs(dist - r) < eps;
            }

        }

    }

    static class FastScanner {
        private BufferedReader in;
        private StringTokenizer st;

        public FastScanner(InputStream stream) {
            in = new BufferedReader(new InputStreamReader(stream));
        }

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

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

    }
}


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

public class  Main{
	static class base implements Comparable<base>{
		int d,g;
		base(int dd,int gg){
			d=dd;g=gg;
		}
		@Override
		public int compareTo(base o) {
			return d-o.d;
		}

	}
	static long inf=(long)1e15+7;
	static long[][]adj;

	static int V, s, t;
	static long res[][];			//input
	static ArrayList<Integer>[] adjList;	//input
	static int[] ptr, dist;

	static long dinic()						//O(V^2E)
	{
		long mf = 0;
		while(bfs())
		{
			ptr = new int[V];
			long f;
			while((f = dfs(s, inf)) != 0)
				mf += f;
		}
		return mf;
	}

	static boolean bfs()
	{
		dist = new int[V];
		Arrays.fill(dist, -1);
		dist[s] = 0;
		Queue<Integer> q = new LinkedList<Integer>();
		q.add(s);
		while(!q.isEmpty())
		{
			int u = q.remove();
			if(u == t)
				return true;
			for(int v: adjList[u])
				if(dist[v] == -1 && res[u][v] > 0)
				{
					dist[v] = dist[u] + 1;
					q.add(v);
				}
		}
		return false;
	}

	static long dfs(int u, long flow)
	{
		if(u == t)
			return flow;
		for(int i = ptr[u]; i < adjList[u].size(); i = ++ptr[u])
		{
			int v = adjList[u].get(i);
			if(dist[v] == dist[u] + 1 && res[u][v] > 0)
			{
				long f = dfs(v, Math.min(flow, res[u][v]));
				if(f > 0)
				{
					res[u][v] -= f;
					res[v][u] += f;
					return f;
				}
			}
		}
		return 0;

	}
	public static void main(String[] args) throws Exception{
		MScanner sc=new MScanner(System.in);
		PrintWriter pw=new PrintWriter(System.out);
		int n=sc.nextInt(),m=sc.nextInt();
		adj=new long[n][n];
		for(long []i:adj)Arrays.fill(i, inf);
		for(int i=0;i<m;i++) {
			int x=sc.nextInt()-1,y=sc.nextInt()-1;
			adj[x][y]=1;
			adj[y][x]=1;
		}
		for(int i=0;i<n;i++)adj[i][i]=0;
		for(int k=0;k<n;k++) {
			for(int i=0;i<n;i++) {
				for(int j=0;j<n;j++) {
					adj[i][j]=Math.min(adj[i][j], adj[i][k]+adj[k][j]);
				}
			}
		}
		int ss=sc.nextInt(),b=sc.nextInt(),k=sc.nextInt();
		int[][]spaceShips=new int[ss][5];
		for(int i=0;i<ss;i++) {
			for(int j=0;j<4;j++) {
				spaceShips[i][j]=sc.nextInt();
			}
			spaceShips[i][0]--;
			spaceShips[i][4]=i;
		}
		Arrays.sort(spaceShips,(x,y) -> x[1]-y[1]);

		TreeSet<base>[]planets=new TreeSet[n];
		for(int i=0;i<n;i++) {
			planets[i]=new TreeSet<base>();
		}
		for(int i=0;i<b;i++) {
			planets[sc.nextInt()-1].add(new base(sc.nextInt(), sc.nextInt()));
		}

		long[]maxProfit=new long[ss];
		long[]maxSoFar=new long[n];
		Arrays.fill(maxSoFar, -inf);
		for(int i=0;i<ss;i++) {
			int curAtt=spaceShips[i][1],curFuel=spaceShips[i][2],curPrice=spaceShips[i][3],curLoc=spaceShips[i][0];
			long profit=-inf;
			for(int p=0;p<n;p++) {
				long dist=adj[curLoc][p];
				if(dist>curFuel)continue;

				while(!planets[p].isEmpty() && curAtt>=planets[p].first().d) {
					maxSoFar[p]=Math.max(maxSoFar[p], planets[p].pollFirst().g);
				}
				profit=Math.max(profit, maxSoFar[p]);

			}
			maxProfit[spaceShips[i][4]]=Math.max(-inf, profit*1l-curPrice);
		}
		long ans=0;

		HashSet<Integer>dep=new HashSet<Integer>();
		int[][]depend=new int[k][2];
		for(int i=0;i<k;i++) {
			int x=sc.nextInt()-1,y=sc.nextInt()-1;
			dep.add(x);dep.add(y);
			depend[i][0]=x;depend[i][1]=y;
		}

		V=dep.size()+2;
		res=new long[V][V];
		adjList=new ArrayList[V];
		for(int i=0;i<V;i++)adjList[i]=new ArrayList<Integer>();

		t=V-1;
		HashMap<Integer, Integer>ids=new HashMap<Integer,Integer>();
		int id=1;

		for(int i=0;i<k;i++) {
			int x=depend[i][0],y=depend[i][1];
			int idx,idy;
			if(ids.containsKey(x)) {
				idx=ids.get(x);
			}
			else {
				idx=id++;
				ids.put(x, idx);
			}
			if(ids.containsKey(y)) {
				idy=ids.get(y);
			}
			else {
				idy=id++;
				ids.put(y, idy);
			}

			adjList[idx].add(idy);
			adjList[idy].add(idx);
			res[idx][idy]=inf;

		}

		for(int i=0;i<ss;i++) {
			if(dep.contains(i)) {
				int curID=ids.get(i);
				if(maxProfit[i]>=0) {
					adjList[s].add(curID);
					adjList[curID].add(s);
					res[s][curID]=maxProfit[i];
				}
				else {
					adjList[t].add(curID);
					adjList[curID].add(t);
					res[curID][t]=-maxProfit[i];
				}
			}
			ans+=Math.max(0, maxProfit[i]);
		}
		pw.println(ans-dinic());
		pw.flush();
	}
	static class MScanner {
		StringTokenizer st;
		BufferedReader br;
		public MScanner(InputStream system) {
			br = new BufferedReader(new InputStreamReader(system));
		}

		public MScanner(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 int[] intArr(int n) throws IOException {
	        int[]in=new int[n];for(int i=0;i<n;i++)in[i]=nextInt();
	        return in;
		}
		public long[] longArr(int n) throws IOException {
	        long[]in=new long[n];for(int i=0;i<n;i++)in[i]=nextLong();
	        return in;
		}
		public int[] intSortedArr(int n) throws IOException {
	        int[]in=new int[n];for(int i=0;i<n;i++)in[i]=nextInt();
	        shuffle(in);
	        Arrays.sort(in);
	        return in;
		}
		public long[] longSortedArr(int n) throws IOException {
	        long[]in=new long[n];for(int i=0;i<n;i++)in[i]=nextLong();
	        shuffle(in);
	        Arrays.sort(in);
	        return in;
		}
		static void shuffle(int[]in) {
			for(int i=0;i<in.length;i++) {
				int idx=(int)(Math.random()*in.length);
				int tmp=in[i];
				in[i]=in[idx];
				in[idx]=tmp;
			}
		}
		static void shuffle(long[]in) {
			for(int i=0;i<in.length;i++) {
				int idx=(int)(Math.random()*in.length);
				long tmp=in[i];
				in[i]=in[idx];
				in[idx]=tmp;
			}
		}
		public Integer[] IntegerArr(int n) throws IOException {
	        Integer[]in=new Integer[n];for(int i=0;i<n;i++)in[i]=nextInt();
	        return in;
		}
		public Long[] LongArr(int n) throws IOException {
	        Long[]in=new Long[n];for(int i=0;i<n;i++)in[i]=nextLong();
	        return in;
		}
		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);
		}
	}
	static void addX(int[]in,int x) {
		for(int i=0;i<in.length;i++)in[i]+=x;
	}
	static void addX(long[]in,int x) {
		for(int i=0;i<in.length;i++)in[i]+=x;
	}
}


import java.util.*;

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

		boolean blocked[][] = new boolean[300][300];
		int x = 150, y = 150, len = path.length();

		for (int i = 0; i < 300; i++) Arrays.fill(blocked[i], true);
		blocked[x][y] = false;

		for (int i = 0; i < len; i++) {
			char c = path.charAt(i);
			if (c == 'R') {
				x++;
				/*
				int temp = dx;
				dx = dy;
				dy = -temp;*/
			} else if (c == 'L') {
				x--;
				/*
				int temp = dy;
				dy = dx;
				dx = -temp;*/
			} else if (c == 'D') {
				y--;
				/*
				dx = -dx;
				dy = -dy;*/
			} else y++;
			blocked[x][y] = false;
			//System.out.println("Not blocked: " + x + " " + y);
		}

		int fx = x, fy = y;
		//System.out.println(fx + " " + fy);

		boolean visited[][] = new boolean[300][300];
		x = 150;
		y = 150;

		LinkedList<int[]> q = new LinkedList<int[]>(); /* x, y, dist */
		q.add(new int[]{x, y, 0});

		int dist = 1 << 25;
		while (q.size() != 0) {
			int[] pt = q.remove();
			int xp = pt[0], yp = pt[1], d = pt[2];

			visited[xp][yp] = true;

			/*
			if (xp == 148 && yp == 153) {
				System.out.println(blocked[149][153]);
				System.out.println(visited[149][153]);
			}*/

			if (xp == fx && yp == fy) {
				dist = d;
				break;
			}

			if (xp >= 1 && !visited[xp - 1][yp] && !blocked[xp - 1][yp]) q.add(new int[]{xp - 1, yp, d + 1});
			if (xp < 299 && !visited[xp + 1][yp] && !blocked[xp + 1][yp]) q.add(new int[]{xp + 1, yp, d + 1});
			if (yp >= 1 && !visited[xp][yp - 1] && !blocked[xp][yp - 1]) q.add(new int[]{xp, yp - 1, d + 1});
			if (yp < 299 && !visited[xp][yp + 1] && !blocked[xp][yp + 1]) q.add(new int[]{xp, yp + 1, d + 1});
		}

		//System.out.println(dist + " " + len);
		System.out.println((dist == len) ? "OK" : "BUG");
	}
}


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

public class Main {

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

	void run() {
		solve();
	}

	final long mod=998244353;

	long pow(long a, long n) {
		if (n==0) return 1;
		return pow(a*a%mod, n/2) * (n%2==1 ? a : 1) % mod;
	}

	long inv(long a) {
		return pow(a, mod-2);
	}

	int MAX=100000;
	long[] fac=new long[MAX];
	long[] ifac=new long[MAX];
	long[] inv=new long[MAX];
	{
		fac[0]=fac[1]=ifac[0]=ifac[1]=inv[0]=inv[1]=1;
		for (int i=2;i<MAX;++i) {
			fac[i]=i*fac[i-1]%mod;
			inv[i]=mod-(mod/i)*inv[(int)(mod%i)]%mod;
			ifac[i]=inv[i]*ifac[i-1]%mod;
		}
	}

	long c(int n, int k) {
		if (n<0||k<0||n-k<0) return 0;
		return fac[n]*ifac[n-k]%mod*ifac[k]%mod;
	}

	void solve() {
		FastScanner sc=new FastScanner();
		PrintWriter pw=new PrintWriter(System.out);

		int N=sc.nextInt();
		int K=sc.nextInt();

		long[] dp=new long[N];
		dp[0]=1;
		for (int i=0;i<K;++i) {
			long[] ndp=dp.clone();
			for (int n=0;n<N;++n) {
				for (int add=1;add+n<=N-1;++add) {
					int nn=n+add;
					ndp[nn]+=dp[n]*pow(K-i, n*add+add*(add-1)/2)%mod*c(N-1-n, add)%mod;
					ndp[nn]%=mod;
				}
			}
			dp=ndp;
		}
		System.out.println(dp[N-1]);
		pw.close();
	}

	static void tr(Object...objects) {
		System.out.println(Arrays.deepToString(objects));
	}

}

class FastScanner {
    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;
    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        }else{
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }
    private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
    private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
    private void skipUnprintable() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++;}
    public boolean hasNext() { skipUnprintable(); return hasNextByte();}
    public String next() {
        if (!hasNext()) throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while(isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }
    public long nextLong() {
        if (!hasNext()) throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while(true){
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            }else if(b == -1 || !isPrintableChar(b)){
                return minus ? -n : n;
            }else{
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }
    public int nextInt() {
    	return (int)nextLong();
    }
}


import java.util.Scanner;
import java.util.*;
public class project{
    public static void main(String[]args)
    {
	Scanner s = new Scanner(System.in);

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

          String str = s.next();
          str='Y'+str;
          str+='Y';
         char[] x = str.toCharArray();

          int cur =0 ,ans = 0;
          boolean t=false;
          for(int i=1;i<=n;i++)
          {
                    if(t && x[i]=='N')
                    {
                              cur++;
                    }
                    if(!t && x[i]=='N')
                    {
                              t=true;
                              cur++;
                    }
                    if(x[i]!='N')
                    {
                        if (ans < cur)
                        ans = cur;

                              t=false;
                              cur=0;
                    }
          }

          if (ans < cur) ans = cur;
          if(ans>k)
          {
                    System.out.println("NO");

          }
          else
          {
          boolean vyv = false;
          for(int i=1;i<=n-k+1;i++)
          {
                    if((x[i-1]=='Y' || x[i-1]=='?') && (x[i+k]=='Y' || x[i+k]=='?'))
                    {
                              t=true;
                              for(int j=i;j<k+i;j++)
                              {
                                        if(x[j]=='Y')
                                                  t=false;
                              }
                              if(t)
                              {
                                        System.out.println("YES");
                                      vyv = true;
                                      break;
                              }
                    }
          }
          if (!vyv)
          System.out.println("NO");
          }
    }
}


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

public class Solution {

	BufferedReader in;
	PrintWriter out;
	StringTokenizer st;

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

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

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

	Map<Long, Long> memo = new TreeMap<Long, Long>();

	int cd(long q) {
		int res = 0;
		for (; q > 0; q /= 10) {
			if (q % 10 == 4 || q % 10 == 7) res++;
		}
		return res;
	}

	long dp(int m, int d) {
		if (memo.containsKey((long)m * 10 + d)) return memo.get((long)m * 10 + d);
		if (m == 0) return (d == 0)? 1 : 0;
		long res = 0;
		if (d > 0) {
			res = dp(m / 10, d - 1) * 2;
			if (cd(m / 10) == d - 1) {
				if (m % 10 < 7) res--;
				if (m % 10 < 4) res--;
			}
		}
		res += dp(m / 10, d) * 8;
		if (cd(m / 10) == d) {
			res -= 8;
			if (m % 10 < 4) res += (m % 10 + 1); else
				if (m % 10 < 7) res += (m % 10); else
					res += (m % 10 - 1);
		}
		memo.put((long)m * 10 + d, res);
		return res;
	}

	long[] a = new long[10];
	int[] w = new int[10];
	long ans = 0;
	long modd = 1000000007;
	int g0 = -1, sumg = 0;

	void rek(int q, long cur) {
		if (q == 7) {
			if (g0 > sumg) {
				ans = (ans + cur) % modd;
			}
		} else {
			for (int i = 0; i < 10; i++) {
				if (w[i] < a[i]) {
					long cc = (cur * (a[i] - w[i])) % modd;
					w[i]++;
					if (q == 0) g0 = i; else sumg += i;
					rek(q + 1, cc);
					if (q == 0) g0 = -1; else sumg -= i;
					w[i]--;
				}
			}
		}
	}

	void solve() throws Exception {
		int m = nextInt();
		for (int i = 0; i <= 9; i++) a[i] = dp(m, i);
		a[0]--;
//		for (int i = 0; i < 10; i++) out.print(a[i] + " ");
		rek(0, 1);
		out.println(ans);
	}

	void run() {
		try {
			Locale.setDefault(Locale.US);
			in = new BufferedReader(new InputStreamReader(System.in));
			out = new PrintWriter(System.out);
			solve();
		} catch (Exception e) {
			e.printStackTrace();
			System.exit(1);
		} finally {
			out.close();
		}
	}

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

}


import java.util.Scanner;

/**
 *
 * @author RezaM
 */
public class B2 {

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

        int remind = x % m;

        for (int i = 0; i < m && remind!=0; i++) {
            remind = (remind * 2) % m;
        }
        if (remind==0) {
            System.out.println("Yes");
        } else {
            System.out.println("No");
        }
    }

}


import java.util.Scanner;

public class A_Accumulation_of_Dominoes {

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

	static long n, m;

	static void solve() {

		if(m == 1) {

			System.out.println(n - 1);
			return;

		}

		long ans = (m - 1) * n;

		System.out.println(ans);

	}

	public static void main(String [] amit) {

		n = in.nextLong();
		m = in.nextLong();

		solve();

	}

}


import java.awt.*;
import java.io.*;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.*;
import java.util.List;

import static java.lang.Math.max;
import static java.lang.Math.min;

public class C implements Runnable{

    // SOLUTION AT THE TOP OF CODE!!!
    // HACK ME PLEASE IF YOU CAN!!!
    // PLEASE!!!
    // PLEASE!!!
    // PLEASE!!!

    @SuppressWarnings("unused")
    private final static Random rnd = new Random();
    private final static String fileName = "";

    private final static long MODULO = 1000 * 1000 * 1000 + 7;

    // THERE SOLUTION STARTS!!!
    private void solve() {
        long la = readInt();
        long ra = readInt();
        long ta = readInt();

        long lb = readInt();
        long rb = readInt();
        long tb = readInt();

        if (ta > tb) {
            long tmp = la;
            la = lb;
            lb = tmp;

            tmp = ra;
            ra = rb;
            rb = tmp;

            tmp = ta;
            ta = tb;
            tb = tmp;
        }

        long gcd = gcd(ta, tb);

        long lDelta = lb - la;

        long reminder = lDelta % gcd;
        if (reminder < 0) reminder += gcd;

        long answer = 0;

        {
            long sa = (lb + gcd - reminder) % (3 * tb);
            long ea = (lb + (ra - la) + gcd - reminder) % (3 * tb);

            long start = max(sa, lb);
            long end = min(ea, rb);

            answer = max(answer, end - start + 1);

            sa = (lb - reminder + 3 * tb) % (3 * tb);
            ea = (lb + (ra - la) - reminder + 3 * tb) % (3 * tb);

            start = max(sa, lb);
            end = min(ea, rb);

            answer = max(answer, end - start + 1);
        }

        out.println(answer);
    }

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

    private final static boolean MULTIPLE_TESTS = true;
    private final boolean ONLINE_JUDGE = !new File("input.txt").exists();
//    private final boolean ONLINE_JUDGE = System.getProperty("ONLINE_JUDGE") != null;

    private final static int MAX_STACK_SIZE = 128;

    private final static boolean OPTIMIZE_READ_NUMBERS = false;

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

    @SuppressWarnings("unused")
    private static long inverse(long x) {
        return binpow(x, MODULO - 2);
    }

    private static long binpow(long base, long power) {
        if (power == 0) return 1;
        if ((power & 1) == 0) {
            long half = binpow(base, power >> 1);
            return mult(half, half);
        } else {
            long prev = binpow(base, power - 1);
            return mult(prev, base);
        }
    }

    private static long add(long a, long b) { return (a + b) % MODULO; }

    @SuppressWarnings("unused")
    private static long subtract(long a, long b) { return add(a, MODULO - b % MODULO); }

    private static long mult(long a, long b) { return (a * b) % MODULO; }

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

    @SuppressWarnings("unused")
    void yesNo(boolean yes) {
        out.println(yes ? "YES" : "NO");
    }

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

    public void run(){
        try{
            timeInit();
            Locale.setDefault(Locale.US);

            init();

            if (ONLINE_JUDGE) {
                solve();
            } else {
                do {
                    try {
                        timeInit();
                        solve();
                        time();

                        out.println();
                        out.flush();
                    } catch (NumberFormatException | EOFException e) {
                        break;
                    }
                } while (MULTIPLE_TESTS);
            }

            out.close();
            time();
        }catch (Exception e){
            e.printStackTrace(System.err);
            System.exit(-1);
        }
    }

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

    private BufferedReader in;
    private OutputWriter out;
    private StringTokenizer tok = new StringTokenizer("");

    public static void main(String[] args){
        new Thread(null, new C(), "", MAX_STACK_SIZE * (1L << 20)).start();
    }

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

    private void init() throws FileNotFoundException{
        Locale.setDefault(Locale.US);

        if (ONLINE_JUDGE){
            if (fileName.isEmpty()) {
                in = new BufferedReader(new InputStreamReader(System.in));
                out = new OutputWriter(System.out);
            } else {
                in = new BufferedReader(new FileReader(fileName + ".in"));
                out = new OutputWriter(fileName + ".out");
            }
        }else{
            in = new BufferedReader(new FileReader("input.txt"));
            out = new OutputWriter("output.txt");
        }
    }

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

    private long timeBegin;

    private void timeInit() {
        this.timeBegin = System.currentTimeMillis();
    }

    private void time(){
        long timeEnd = System.currentTimeMillis();
        System.err.println("Time = " + (timeEnd - timeBegin));
    }

    @SuppressWarnings("unused")
    private void debug(Object... objects){
        if (ONLINE_JUDGE){
            for (Object o: objects){
                System.err.println(o.toString());
            }
        }
    }

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

    private String delim = " ";

    private String readNullableLine() {
        try {
            return in.readLine();
        } catch (IOException e) {
            throw new RuntimeIOException(e);
        }
    }

    private String readLine() {
        String line = readNullableLine();
        if (null == line) throw new EOFException();
        return line;
    }

    private String readString() {
        while(!tok.hasMoreTokens()){
            tok = new StringTokenizer(readLine(), delim);
        }

        return tok.nextToken(delim);
    }

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

    private final char NOT_A_SYMBOL = '\0';

    @SuppressWarnings("unused")
    private char readChar() {
        try {
            int intValue = in.read();

            if (intValue == -1){
                return NOT_A_SYMBOL;
            }

            return (char) intValue;
        } catch (IOException e) {
            throw new RuntimeIOException(e);
        }
    }

    private char[] readCharArray() {
        return readLine().toCharArray();
    }

    @SuppressWarnings("unused")
    private char[][] readCharField(int rowsCount) {
        char[][] field = new char[rowsCount][];
        for (int row = 0; row < rowsCount; ++row) {
            field[row] = readCharArray();
        }

        return field;
    }

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

    private long optimizedReadLong() {
        int sign = 1;
        long result = 0;
        boolean started = false;
        while (true) {
            try {
                int j = in.read();
                if (-1 == j) {
                    if (started) return sign * result;
                    throw new NumberFormatException();
                }

                if (j == '-') {
                    if (started) throw new NumberFormatException();
                    sign = -sign;
                }

                if ('0' <= j && j <= '9') {
                    result = result * 10 + j - '0';
                    started = true;
                } else if (started) {
                    return sign * result;
                }
            } catch (IOException e) {
                throw new RuntimeIOException(e);
            }
        }
    }

    private int readInt() {

        if (!OPTIMIZE_READ_NUMBERS) {
            return Integer.parseInt(readString());
        } else {
            return (int) optimizedReadLong();
        }
    }

    private int[] readIntArray(int size) {
        int[] array = new int[size];

        for (int index = 0; index < size; ++index){
            array[index] = readInt();
        }

        return array;
    }

    @SuppressWarnings("unused")
    private int[] readSortedIntArray(int size) {
        Integer[] array = new Integer[size];

        for (int index = 0; index < size; ++index) {
            array[index] = readInt();
        }
        Arrays.sort(array);

        int[] sortedArray = new int[size];
        for (int index = 0; index < size; ++index) {
            sortedArray[index] = array[index];
        }

        return sortedArray;
    }

    private int[] readIntArrayWithDecrease(int size) {
        int[] array = readIntArray(size);

        for (int i = 0; i < size; ++i) {
            array[i]--;
        }

        return array;
    }

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

    @SuppressWarnings("unused")
    private int[][] readIntMatrix(int rowsCount, int columnsCount) {
        int[][] matrix = new int[rowsCount][];

        for (int rowIndex = 0; rowIndex < rowsCount; ++rowIndex) {
            matrix[rowIndex] = readIntArray(columnsCount);
        }

        return matrix;
    }

    @SuppressWarnings("unused")
    private int[][] readIntMatrixWithDecrease(int rowsCount, int columnsCount) {
        int[][] matrix = new int[rowsCount][];

        for (int rowIndex = 0; rowIndex < rowsCount; ++rowIndex) {
            matrix[rowIndex] = readIntArrayWithDecrease(columnsCount);
        }

        return matrix;
    }

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

    private long readLong() {
        if (!OPTIMIZE_READ_NUMBERS) {
            return Long.parseLong(readString());
        } else {
            return optimizedReadLong();
        }
    }

    @SuppressWarnings("unused")
    private long[] readLongArray(int size) {
        long[] array = new long[size];

        for (int index = 0; index < size; ++index){
            array[index] = readLong();
        }

        return array;
    }

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

    private double readDouble() {
        return Double.parseDouble(readString());
    }

    @SuppressWarnings("unused")
    private double[] readDoubleArray(int size) {
        double[] array = new double[size];

        for (int index = 0; index < size; ++index){
            array[index] = readDouble();
        }

        return array;
    }

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

    @SuppressWarnings("unused")
    private BigInteger readBigInteger() {
        return new BigInteger(readString());
    }

    @SuppressWarnings("unused")
    private BigDecimal readBigDecimal() {
        return new BigDecimal(readString());
    }

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

    private Point readPoint() {
        int x = readInt();
        int y = readInt();
        return new Point(x, y);
    }

    @SuppressWarnings("unused")
    private Point[] readPointArray(int size) {
        Point[] array = new Point[size];

        for (int index = 0; index < size; ++index){
            array[index] = readPoint();
        }

        return array;
    }

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

    @Deprecated
    @SuppressWarnings("unused")
    private List<Integer>[] readGraph(int vertexNumber, int edgeNumber) {
        @SuppressWarnings("unchecked")
        List<Integer>[] graph = new List[vertexNumber];

        for (int index = 0; index < vertexNumber; ++index){
            graph[index] = new ArrayList<>();
        }

        while (edgeNumber-- > 0){
            int from = readInt() - 1;
            int to = readInt() - 1;

            graph[from].add(to);
            graph[to].add(from);
        }

        return graph;
    }

    private static class GraphBuilder {

        final int size;
        final List<Integer>[] edges;

        static GraphBuilder createInstance(int size) {
            @SuppressWarnings("unchecked")
            List<Integer>[] edges = new List[size];
            for (int v = 0; v < size; ++v) {
                edges[v] = new ArrayList<>();
            }

            return new GraphBuilder(edges);
        }

        private GraphBuilder(List<Integer>[] edges) {
            this.size = edges.length;
            this.edges = edges;
        }

        public void addEdge(int from, int to) {
            addDirectedEdge(from, to);
            addDirectedEdge(to, from);
        }

        public void addDirectedEdge(int from, int to) {
            edges[from].add(to);
        }

        public int[][] build() {
            int[][] graph = new int[size][];
            for (int v = 0; v < size; ++v) {
                List<Integer> vEdges = edges[v];
                graph[v] = castInt(vEdges);
            }

            return graph;
        }
    }

    @SuppressWarnings("unused")
    private final static int ZERO_INDEXATION = 0, ONE_INDEXATION = 1;

    @SuppressWarnings("unused")
    private int[][] readUnweightedGraph(int vertexNumber, int edgesNumber) {
        return readUnweightedGraph(vertexNumber, edgesNumber, ONE_INDEXATION, false);
    }

    private int[][] readUnweightedGraph(int vertexNumber, int edgesNumber,
                                        int indexation, boolean directed
    ) {
        GraphBuilder graphBuilder = GraphBuilder.createInstance(vertexNumber);
        for (int i = 0; i < edgesNumber; ++i) {
            int from = readInt() - indexation;
            int to = readInt() - indexation;

            if (directed) graphBuilder.addDirectedEdge(from, to);
            else graphBuilder.addEdge(from, to);
        }

        return graphBuilder.build();
    }

    private static class Edge {
        int to;
        int w;

        Edge(int to, int w) {
            this.to = to;
            this.w = w;
        }
    }

    @SuppressWarnings("unused")
    private Edge[][] readWeightedGraph(int vertexNumber, int edgesNumber) {
        return readWeightedGraph(vertexNumber, edgesNumber, ONE_INDEXATION, false);
    }

    private Edge[][] readWeightedGraph(int vertexNumber, int edgesNumber,
                                       int indexation, boolean directed) {
        @SuppressWarnings("unchecked")
        List<Edge>[] graph = new List[vertexNumber];
        for (int v = 0; v < vertexNumber; ++v) {
            graph[v] = new ArrayList<>();
        }

        while (edgesNumber --> 0) {
            int from = readInt() - indexation;
            int to = readInt() - indexation;
            int w = readInt();

            graph[from].add(new Edge(to, w));
            if (!directed) graph[to].add(new Edge(from, w));
        }

        Edge[][] graphArrays = new Edge[vertexNumber][];
        for (int v = 0; v < vertexNumber; ++v) {
            graphArrays[v] = graph[v].toArray(new Edge[0]);
        }

        return graphArrays;
    }

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

    private static class IntIndexPair {

        @SuppressWarnings("unused")
        static Comparator<IntIndexPair> increaseComparator = new Comparator<C.IntIndexPair>() {
            @Override
            public int compare(C.IntIndexPair indexPair1, C.IntIndexPair indexPair2) {
                int value1 = indexPair1.value;
                int value2 = indexPair2.value;

                if (value1 != value2) return value1 - value2;

                int index1 = indexPair1.index;
                int index2 = indexPair2.index;

                return index1 - index2;
            }
        };

        @SuppressWarnings("unused")
        static Comparator<IntIndexPair> decreaseComparator = new Comparator<C.IntIndexPair>() {
            @Override
            public int compare(C.IntIndexPair indexPair1, C.IntIndexPair indexPair2) {
                int value1 = indexPair1.value;
                int value2 = indexPair2.value;

                if (value1 != value2) return -(value1 - value2);

                int index1 = indexPair1.index;
                int index2 = indexPair2.index;

                return index1 - index2;
            }
        };

        @SuppressWarnings("unused")
        static IntIndexPair[] from(int[] array) {
            IntIndexPair[] iip = new IntIndexPair[array.length];
            for (int i = 0; i < array.length; ++i) {
                iip[i] = new IntIndexPair(array[i], i);
            }

            return iip;
        }

        int value, index;

        IntIndexPair(int value, int index) {
            super();
            this.value = value;
            this.index = index;
        }

        @SuppressWarnings("unused")
        int getRealIndex() {
            return index + 1;
        }
    }

    @SuppressWarnings("unused")
    private IntIndexPair[] readIntIndexArray(int size) {
        IntIndexPair[] array = new IntIndexPair[size];

        for (int index = 0; index < size; ++index) {
            array[index] = new IntIndexPair(readInt(), index);
        }

        return array;
    }

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

    private static class OutputWriter extends PrintWriter {

        final int DEFAULT_PRECISION = 12;

        private int precision;
        private String format, formatWithSpace;

        {
            precision = DEFAULT_PRECISION;

            format = createFormat(precision);
            formatWithSpace = format + " ";
        }

        OutputWriter(OutputStream out) {
            super(out);
        }

        OutputWriter(String fileName) throws FileNotFoundException {
            super(fileName);
        }

        int getPrecision() {
            return precision;
        }

        void setPrecision(int precision) {
            precision = max(0, precision);
            this.precision = precision;

            format = createFormat(precision);
            formatWithSpace = format + " ";
        }

        String createFormat(int precision){
            return "%." + precision + "f";
        }

        @Override
        public void print(double d){
            printf(format, d);
        }

        @Override
        public void println(double d){
            print(d);
            println();
        }

        void printWithSpace(double d){
            printf(formatWithSpace, d);
        }

        void printAll(double...d){
            for (int i = 0; i < d.length - 1; ++i){
                printWithSpace(d[i]);
            }

            print(d[d.length - 1]);
        }

        @SuppressWarnings("unused")
        void printlnAll(double... d){
            printAll(d);
            println();
        }

        void printAll(int... array) {
        	for (int value : array) {
        		print(value + " ");
        	}
        }

        @SuppressWarnings("unused")
        void printlnAll(int... array) {
        	printAll(array);
        	println();
        }

        void printAll(long... array) {
        	for (long value : array) {
        		print(value + " ");
        	}
        }

        @SuppressWarnings("unused")
        void printlnAll(long... array) {
        	printAll(array);
        	println();
        }
    }

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

    private static class EOFException extends RuntimeException {

        EOFException() {
            super();
        }
    }

    private static class RuntimeIOException extends RuntimeException {

        /**
         *
         */
        private static final long serialVersionUID = -6463830523020118289L;

        RuntimeIOException(Throwable cause) {
            super(cause);
        }
    }

    /////////////////////////////////////////////////////////////////////
    //////////////// Some useful constants andTo functions ////////////////
    /////////////////////////////////////////////////////////////////////

    private static void swap(int[] array, int i, int j) {
        if (i != j) {
            int tmp = array[i];
            array[i] = array[j];
            array[j] = tmp;
        }
    }

    private static <T> void swap(T[] array, int i, int j) {
        if (i != j) {
            T tmp = array[i];
            array[i] = array[j];
            array[j] = tmp;
        }
    }

    private static final int[][] steps = {{-1, 0}, {1, 0}, {0, -1}, {0, 1}};
    private static final int[][] steps8 = {
            {-1, 0}, {1, 0}, {0, -1}, {0, 1},
            {-1, -1}, {1, 1}, {1, -1}, {-1, 1}
    };

    @SuppressWarnings("unused")
    private static boolean checkCell(int row, int rowsCount, int column, int columnsCount) {
        return checkIndex(row, rowsCount) && checkIndex(column, columnsCount);
    }

    private static boolean checkIndex(int index, int lim){
        return (0 <= index && index < lim);
    }

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

    private static int getBit(long mask, int bit) { return (int)((mask >> bit) & 1); }

    @SuppressWarnings("unused")
    private static boolean checkBit(long mask, int bit){
        return getBit(mask, bit) != 0;
    }

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

    @SuppressWarnings("unused")
    private static long getSum(int[] array) {
        long sum = 0;
        for (int value: array) {
            sum += value;
        }

        return sum;
    }

    @SuppressWarnings("unused")
    private static Point getMinMax(int[] array) {
        int min = array[0];
        int max = array[0];

        for (int index = 0, size = array.length; index < size; ++index, ++index) {
            int value = array[index];

            if (index == size - 1) {
                min = min(min, value);
                max = max(max, value);
            } else {
                int otherValue = array[index + 1];

                if (value <= otherValue) {
                    min = min(min, value);
                    max = max(max, otherValue);
                } else {
                    min = min(min, otherValue);
                    max = max(max, value);
                }
            }
        }

        return new Point(min, max);
    }

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

    @SuppressWarnings("unused")
    private static boolean isPrime(int x) {
        if (x < 2) return false;
        for (int d = 2; d * d <= x; ++d) {
            if (x % d == 0) return false;
        }

        return true;
    }

    @SuppressWarnings("unused")
    private static int[] getPrimes(int n) {
        boolean[] used = new boolean[n];
        used[0] = used[1] = true;

        int size = 0;
        for (int i = 2; i < n; ++i) {
            if (!used[i]) {
                ++size;
                for (int j = 2 * i; j < n; j += i) {
                    used[j] = true;
                }
            }
        }

        int[] primes = new int[size];
        for (int i = 0, cur = 0; i < n; ++i) {
            if (!used[i]) {
                primes[cur++] = i;
            }
        }

        return primes;
    }

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

    @SuppressWarnings("unused")
    int[] getDivisors(int value) {
        List<Integer> divisors = new ArrayList<>();
        for (int divisor = 1; divisor * divisor <= value; ++divisor) {
            if (value % divisor == 0) {
                divisors.add(divisor);
                if (divisor * divisor != value) {
                    divisors.add(value / divisor);
                }
            }
        }

        return castInt(divisors);
    }

    @SuppressWarnings("unused")
    long[] getDivisors(long value) {
        List<Long> divisors = new ArrayList<>();
        for (long divisor = 1; divisor * divisor <= value; ++divisor) {
            if (value % divisor == 0) {
                divisors.add(divisor);
                if (divisor * divisor != value) {
                    divisors.add(value / divisor);
                }
            }
        }

        return castLong(divisors);
    }

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

    @SuppressWarnings("unused")
    private static long lcm(long a, long b) {
        return a / gcd(a, b) * b;
    }

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

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

    private static int[] castInt(List<Integer> list) {
        int[] array = new int[list.size()];
        for (int i = 0; i < array.length; ++i) {
            array[i] = list.get(i);
        }

        return array;
    }

    @SuppressWarnings("unused")
    private static long[] castLong(List<Long> list) {
        long[] array = new long[list.size()];
        for (int i = 0; i < array.length; ++i) {
            array[i] = list.get(i);
        }

        return array;
    }

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

    /**
     * Generates list with keys 0..<n
     * @param n - exclusive limit of sequence
     */
    @SuppressWarnings("unused")
    private static List<Integer> order(int n) {
        List<Integer> sequence = new ArrayList<>();
        for (int i = 0; i < n; ++i) {
            sequence.add(i);
        }

        return sequence;
    }

    @SuppressWarnings("unused")
    private static List<Integer> shuffled(List<Integer> list) {
        Collections.shuffle(list, rnd);
        return list;
    }
}


import java.util.Scanner;

public class Coding {

 public static void main(String[] args) {
       Scanner in=new Scanner(System.in);
   long a = in.nextLong();
   long b= a%10 ;
   ;
       if(b==0) System.out.println(a);
   if(b<=5&&b!=0){

       System.out.println(a-b);
   }
   if(b>5){
     long  c=10-b ;
       System.out.println(a+c);
   }

    }
}


import java.io.*;
import java.lang.Math;
import java.lang.reflect.Array;
import java.util.*;
import javax.swing.text.DefaultStyledDocument.ElementSpec;

public final class Solution {

  static BufferedReader br = new BufferedReader(
    new InputStreamReader(System.in)
  );
  static BufferedWriter bw = new BufferedWriter(
    new OutputStreamWriter(System.out)
  );
  static StringTokenizer st;

  /*write your constructor and global variables here*/

  static class sortCond implements Comparator<Pair<Integer, Integer>> {

    @Override
    public int compare(Pair<Integer, Integer> p1, Pair<Integer, Integer> p2) {
      if (p1.a <= p2.a) {
        return -1;
      } else {
        return 1;
      }
    }
  }

  static class Rec {

    int a;
    int b;
    long c;

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

  static class Pair<f, s> {

    f a;
    s b;

    Pair(f a, s b) {
      this.a = a;
      this.b = b;
    }
  }

  interface modOperations {
    int mod(int a, int b, int mod);
  }

  static int findBinaryExponentian(int a, int pow, int mod) {
    if (pow == 1) {
      return a;
    } else if (pow == 0) {
      return 1;
    } else {
      int retVal = findBinaryExponentian(a, (int) pow / 2, mod);
      int val = (pow % 2 == 0) ? 1 : a;
      return modMul.mod(modMul.mod(retVal, retVal, mod), val, mod);
    }
  }

  static int findPow(int a, int b, int mod) {
    if (b == 1) {
      return a % mod;
    } else if (b == 0) {
      return 1;
    } else {
      int res = findPow(a, (int) b / 2, mod);
      return modMul.mod(res, modMul.mod(res, (b % 2 == 1 ? a : 1), mod), mod);
    }
  }

  static int bleft(long ele, ArrayList<Long> sortedArr) {
    int l = 0;
    int h = sortedArr.size() - 1;
    int ans = -1;
    while (l <= h) {
      int mid = l + (int) (h - l) / 2;
      if (sortedArr.get(mid) < ele) {
        l = mid + 1;
      } else if (sortedArr.get(mid) >= ele) {
        ans = mid;
        h = mid - 1;
      }
    }
    return ans;
  }

  static int gcd(int a, int b) {
    int div = b;
    int rem = a % b;
    while (rem != 0) {
      int temp = rem;
      rem = div % rem;
      div = temp;
    }
    return div;
  }

  static long[] log(long no, long n) {
    long i = 1;
    int cnt = 0;
    long sum = 0l;
    long arr[] = new long[2];
    while (i < no) {
      sum += i;
      cnt++;
      if (sum == n) {
        arr[0] = 1l * cnt;
        arr[1] = sum;
        break;
      }
      i *= 2l;
    }
    if (arr[0] == 0) {
      arr[0] = cnt;
      arr[1] = sum;
    }
    return arr;
  }

  static modOperations modAdd = (int a, int b, int mod) -> {
    return (a % mod + b % mod) % mod;
  };
  static modOperations modSub = (int a, int b, int mod) -> {
    return (int) ((1l * a % mod - 1l * b % mod + 1l * mod) % mod);
  };
  static modOperations modMul = (int a, int b, int mod) -> {
    return (int) ((1l * (a % mod) * 1l * (b % mod)) % (1l * mod));
  };
  static modOperations modDiv = (int a, int b, int mod) -> {
    return modMul.mod(a, findBinaryExponentian(b, mod - 1, mod), mod);
  };

  static HashSet<Integer> primeList(int MAXI) {
    int[] prime = new int[MAXI + 1];
    HashSet<Integer> obj = new HashSet<>();
    for (int i = 2; i <= (int) Math.sqrt(MAXI) + 1; i++) {
      if (prime[i] == 0) {
        obj.add(i);
        for (int j = i * i; j <= MAXI; j += i) {
          prime[j] = 1;
        }
      }
    }
    for (int i = (int) Math.sqrt(MAXI) + 1; i <= MAXI; i++) {
      if (prime[i] == 0) {
        obj.add(i);
      }
    }
    return obj;
  }

  static int[] factorialList(int MAXI, int mod) {
    int[] factorial = new int[MAXI + 1];
    factorial[2] = 1;
    for (int i = 3; i < MAXI + 1; i++) {
      factorial[i] = modMul.mod(factorial[i - 1], i, mod);
    }
    return factorial;
  }

  static void put(HashMap<Integer, Integer> cnt, int key) {
    if (cnt.containsKey(key)) {
      cnt.replace(key, cnt.get(key) + 1);
    } else {
      cnt.put(key, 1);
    }
  }

  static long arrSum(ArrayList<Long> arr) {
    long tot = 0;
    for (int i = 0; i < arr.size(); i++) {
      tot += arr.get(i);
    }
    return tot;
  }

  static int ord(char b) {
    return (int) b - (int) 'a';
  }

  static int optimSearch(int[] cnt, int lower_bound, int pow, int n) {
    int l = lower_bound + 1;
    int h = n;
    int ans = 0;
    while (l <= h) {
      int mid = l + (h - l) / 2;
      if (cnt[mid] - cnt[lower_bound] == pow) {
        return mid;
      } else if (cnt[mid] - cnt[lower_bound] < pow) {
        ans = mid;
        l = mid + 1;
      } else {
        h = mid - 1;
      }
    }
    return ans;
  }

  static Pair<Long, Integer> ret_ans(ArrayList<Integer> ans) {
    int size = ans.size();
    int mini = 1000000000 + 1;
    long tit = 0l;
    for (int i = 0; i < size; i++) {
      tit += 1l * ans.get(i);
      mini = Math.min(mini, ans.get(i));
    }
    return new Pair<>(tit - mini, mini);
  }

  static int factorList(
    HashMap<Integer, Integer> maps,
    int no,
    int maxK,
    int req
  ) {
    int i = 1;
    while (i * i <= no) {
      if (no % i == 0) {
        if (i != no / i) {
          put(maps, no / i);
        }
        put(maps, i);
        if (maps.get(i) == req) {
          maxK = Math.max(maxK, i);
        }
        if (maps.get(no / i) == req) {
          maxK = Math.max(maxK, no / i);
        }
      }
      i++;
    }
    return maxK;
  }

  static ArrayList<Integer> getKeys(HashMap<Integer, Integer> maps) {
    ArrayList<Integer> vals = new ArrayList<>();
    for (Map.Entry<Integer, Integer> map : maps.entrySet()) {
      vals.add(map.getKey());
    }
    return vals;
  }

  static ArrayList<Integer> getValues(HashMap<Integer, Integer> maps) {
    ArrayList<Integer> vals = new ArrayList<>();
    for (Map.Entry<Integer, Integer> map : maps.entrySet()) {
      vals.add(map.getValue());
    }
    return vals;
  }

  /*write your  methods here*/
  static int getMax(ArrayList<Integer> arr) {
    int max = arr.get(0);
    for (int i = 1; i < arr.size(); i++) {
      if (arr.get(i) > max) {
        max = arr.get(i);
      }
    }
    return max;
  }

  static int getMin(ArrayList<Integer> arr) {
    int max = arr.get(0);
    for (int i = 1; i < arr.size(); i++) {
      if (arr.get(i) < max) {
        max = arr.get(i);
      }
    }
    return max;
  }

  static int list[][] = { { -1, 0 }, { 0, 1 }, { 1, 0 }, { 0, -1 } };

  public static void main(String[] args) throws IOException {
    int h;
    h = Integer.parseInt(br.readLine());
    if (h == 1) {
      bw.write("6\n");
    } else {
      long tot = 16l;
      long mod = (long) Math.pow(10, 9) + 7;
      long las = 16l;
      for (int i = 3; i <= h; i++) {
        tot *= (las * las) % mod;
        las = (las * las) % mod;
        tot = tot % mod;
      }
      tot = (tot * 6) % mod;

      bw.write(Long.toString(tot) + "\n");
    }
    bw.flush();
  }
}


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

public class A {

    void solve() {
        long a = in.nextInt();
        long b = in.nextInt();
        long c = in.nextInt();
        long d = in.nextInt();
        if (d == b) {
            out.println(b);
            return;
        }
        long res = -1;
        HashSet<Long> was = new HashSet<>();
        was.add(b);
        was.add(d);
        for (int i = 0; i < (int)1e5; i++) {
            b += a;
            d += c;
            if (was.contains(b)) {
                res = b;
                break;
            }
            was.add(b);
            if (was.contains(d)){
                res = d;
                break;
            }
            was.add(d);
        }
        out.println(res);
    }

    FastScanner in;
    PrintWriter out;

    void run() {
        try {
            in = new FastScanner(new File("B.in"));
            out = new PrintWriter(new File("B.out"));

            solve();

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

    void runIO() {

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

        solve();

        out.close();
    }

    class FastScanner {
        BufferedReader br;
        StringTokenizer st;

        public FastScanner(File f) {
            try {
                br = new BufferedReader(new FileReader(f));
            } catch (FileNotFoundException e) {
                e.printStackTrace();
            }
        }

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

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

        boolean hasMoreTokens() {
            while (st == null || !st.hasMoreTokens()) {
                String s = null;
                try {
                    s = br.readLine();
                } catch (IOException e) {
                    e.printStackTrace();
                }
                if (s == null)
                    return false;
                st = new StringTokenizer(s);
            }
            return true;
        }

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

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

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

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


import java.io.BufferedWriter;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

public class Test {

  static PrintWriter writer =
      new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));

  public static void main(String[] args) {
    Test te = new Test();
    te.start();
    writer.flush();
  }

  int readInt() {
    int ans = 0;
    boolean neg = false;
    try {
      boolean start = false;
      for (int c = 0; (c = System.in.read()) != -1; ) {
        if (c == '-') {
          start = true;
          neg = true;
          continue;
        } else if (c >= '0' && c <= '9') {
          start = true;
          ans = ans * 10 + c - '0';
        } else if (start) break;
      }
    } catch (IOException e) {
    }
    return neg ? -ans : ans;
  }

  long readLong() {
    long ans = 0;
    boolean neg = false;
    try {
      boolean start = false;
      for (int c = 0; (c = System.in.read()) != -1; ) {
        if (c == '-') {
          start = true;
          neg = true;
          continue;
        } else if (c >= '0' && c <= '9') {
          start = true;
          ans = ans * 10 + c - '0';
        } else if (start) break;
      }
    } catch (IOException e) {
    }
    return neg ? -ans : ans;
  }

  String readLine() {
    StringBuilder b = new StringBuilder();
    try {
      for (int c = 0; (c = System.in.read()) != -1; ) {
        if (c == '\n') {
          break;
        } else {
          b.append((char) (c));
        }
      }
    } catch (IOException e) {
    }
    return b.toString().trim();
  }

  void start() {
    int n = readInt();
    long k = readLong();
    int[] a = new int[n];
    long sum = 0;
    for (int i = 0; i < n; sum += a[i], i++) a[i] = readInt();
    List<Long> seg = new ArrayList<>();
    for (int i = 0; i < n; i++) {
      for (int j = 1; j*j <= a[i]; j++) {
        seg.add((long)j);
        seg.add((long)(a[i] + j - 1)/j);
      }
    }
    seg.add(sum/n);
    Collections.sort(seg);
    long p = -1;
    for (int i = seg.size() - 1; i >= 0; i--) {
      long v = seg.get(i);
      if (v == p) continue;
      p = v;
      long c = 0;
      for (int j = 0; j < n; j++) c += (a[j] + v - 1) / v;
      if (c*v - sum > k) continue;
      long x = (sum + k) / c;
      writer.println(x);
      break;
    }
  }
}


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

public class F implements Runnable{
	public static void main (String[] args) {new Thread(null, new F(), "_cf", 1 << 28).start();}

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

		int oo = (int)2e9;
		int n = fs.nextInt();
		int k = fs.nextInt();
		int[] dp = new int[n + 1], tdp = new int[n + 1];
		Arrays.fill(dp, oo);
		dp[0] = 0;
		while(k-->0) {
			int l = fs.nextInt(), r = fs.nextInt(), len = r - l;
			for(int i = 0; i <= n; i++) tdp[i] = dp[i];
			ArrayDeque<Integer> minQueue = new ArrayDeque<>();
			for(int i = 0; i <= n; i++) {
				push(minQueue, i, dp);
				tdp[i] = Math.min(tdp[i], best(minQueue, dp) + 2);
				if(r - i >= 0 && r - i <= n) tdp[r - i] = Math.min(tdp[r - i], best(minQueue, dp) + 1);
				pop(minQueue, i - len);
			}
			for(int i = 0; i <= n; i++) dp[i] = tdp[i];
		}

		if(dp[n] >= oo) out.println("Hungry");
		else out.printf("Full\n%d\n", dp[n]);

		out.close();
	}

	void pop(ArrayDeque<Integer> minQueue, int idx) {
		if(!minQueue.isEmpty() && minQueue.peekFirst() == idx) minQueue.pollFirst();
	}

	int best(ArrayDeque<Integer> minQueue, int[] dp) {
		if(minQueue.isEmpty()) return (int)2e9;
		return dp[minQueue.peekFirst()];
	}

	void push(ArrayDeque<Integer> minQueue, int p, int[] dp) {
		while(!minQueue.isEmpty() && dp[minQueue.getLast()] >= dp[p]) minQueue.pollLast();
		minQueue.addLast(p);
	}

	/*
	 * dp[i][j] means the minimum number of moves to cook the cutlet on one side
	   for j seconds after processing i intervals (do iterative space saving)
	 * The length of the interval is known and so we'll build up time j with the
	   previous length values (including j) all from the previous state. It'll take
	   an extra 2 flips to so:
	   if we know the number of flips to get the cutlet to exactly t seconds and we
	   want to get it to j seconds in the current interval being processed, then we'll
	   need to flip it after it gets to t seconds in the other interval (to prevent overcooking)
	   and then flip it again when it needs to cook in our interval to get it to the desired j.
	 * There's also a case where we can just flip it once based off of the previous states.
	   The main idea for some time j, is we want the cutlet to get to its jth second of cooking
	   during our current interval (so we can do a flip if necessary). So what happens is we take
	   the min of the dp values that are allowed in our current range and use that value to calculate
	   (right - j)'s best value by taking that minimum and I guess not flipping it and instead letting
	   it cook. Still a bit hazy but it makes sense when doing the second sample by hand (especially
	   when we update times 10 and 8).
	 * Definitely had to study someone else's solution because the editorial is very obscure and
	   doesn't actually explain the important part of the problem (how to derive the +1 and +2 jumps).
	 */

	class FastScanner {
		BufferedReader br;
		StringTokenizer st;
		public FastScanner() {
			try	{
				br = new BufferedReader(new InputStreamReader(System.in));
				//                br = new BufferedReader(new FileReader("testdata.out"));
				st = new StringTokenizer("");
			} catch (Exception e){e.printStackTrace();}
		}
		public String next() {
			if (st.hasMoreTokens())	return st.nextToken();
			try {st = new StringTokenizer(br.readLine());}
			catch (Exception e) {e.printStackTrace();}
			return st.nextToken();
		}
		public int nextInt() {return Integer.parseInt(next());}
		public long nextLong() {return Long.parseLong(next());}
		public double nextDouble() {return Double.parseDouble(next());}

		public String nextLine() {
			String line = "";
			try {line = br.readLine();}
			catch (Exception e) {e.printStackTrace();}
			return line;
		}
		public Integer[] nextIntegerArray(int n) {
			Integer[] a = new Integer[n];
			for(int i = 0; i < n; i++) a[i] = nextInt();
			return a;
		}
		public int[] nextIntArray(int n) {
			int[] a = new int[n];
			for(int i = 0; i < n; i++) a[i] = nextInt();
			return a;
		}
		public char[] nextCharArray() {return nextLine().toCharArray();}
	}

}


import java.io.*;
import java.math.*;
import java.security.*;
import java.text.*;
import java.util.*;
import java.util.concurrent.*;
import java.util.regex.*;
import java.util.Arrays;
import java.util.ArrayList;
import java.lang.Math;

public class project
{
    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;
        }
    }

    static int binarySearch(long a[],long k,int l,int h){
        int min = Integer.MAX_VALUE;
        while(l<=h){
         int mid = (l+h)/2;
         if(a[mid]==k) return mid;
         else if(a[mid]>k) h=mid-1;
         else if(a[mid]<k) l =mid+1;
    }

        return min;
    }

    static String reverse(String input)
    {
        char[] a = input.toCharArray();
        int l, r = 0;
        r = a.length - 1;

        for (l = 0; l < r; l++, r--)
        {
            // Swap values of l and r
            char temp = a[l];
            a[l] = a[r];
            a[r] = temp;
        }
        return String.valueOf(a);
    }

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

        OutputStream outputStream = System.out;
        PrintWriter w = new PrintWriter(outputStream);
        FastReader sc = new FastReader();
        int i,j;
        String s1 = sc.nextLine();
        String a[] = {"00","01","02","03","04","05","10","11","12","13","14","15","20","21","22","23"};

        String  s = s1.substring(0,2);
        String  p = s1.substring(3);

        int l =0, r=15 , mid=-1;

        while(l<=r){

            mid = (l+r)/2;
            if(a[mid].compareTo(s)==0)      break;
            else if(a[mid].compareTo(s)>0)  r=mid-1;
            else                            l = mid+1;
        }
        String ans = "";
        String rev;
        if(s.compareTo(a[mid]) < 0){
            rev = reverse(a[mid]);
            ans += a[mid] +":"+ rev;
        }
        else{
        rev = reverse(a[mid]);
        if(p.compareTo(rev) < 0) ans += a[mid] +":"+ rev;
        else{
            rev = reverse(a[(mid+1)%16]);
            ans += a[(mid+1)%16] +":"+ rev;
        }
    }
        w.print(ans);

        w.close();
    }

}

// System.out.println();


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

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

		char[] x = br.readLine().toCharArray();
		char[] y = br.readLine().toCharArray();
		int n = x.length;
		boolean pos = true;
		for( int i = 0; i < n; i++){
			if(x[i] < y[i])pos = false;

		}
		if(!pos){
			System.out.println(-1);
			return;
		}
		System.out.println(y);

	}

}


import java.util.*;
import java.math.*;
import java.io.*;
import java.text.*;
import java.awt.Point;

import static java.util.Arrays.*;
import static java.lang.Integer.*;
import static java.lang.Double.*;
import static java.lang.Long.*;
import static java.lang.Short.*;
import static java.lang.Math.*;
import static java.math.BigInteger.*;
import static java.util.Collections.*;

public class Main {

	private Scanner in;
	private StringTokenizer st;
	private PrintWriter out;

	private DecimalFormat fmt = new DecimalFormat("0.0000000000");

	public void solve() throws Exception {
		long n = in.nextLong();
		long a = in.nextLong();
		long b = in.nextLong();

		long target = n * 6;
		if (a * b < target) {
			long small = min(a, b);
			long large = max(a, b);

			long best = Integer.MAX_VALUE;
			for(int i= (int) small; i<sqrt(target); i++) {
				long tmp = (long) ceil((double)target/i);

				if (best > abs(target - i * tmp) && tmp >= max(a, b) && i * tmp >= target) {
					small = i;
					large = tmp;
					best = abs(target - i * tmp);
				}
			}

			if (a < b) {
				a = small;
				b = large;
			} else {
				b = small;
				a = large;
			}
		}
		out.println(a * b);
		out.println(a + " " + b);
	}

	public Main() {
		this.in = new Scanner(System.in);
		this.out = new PrintWriter(System.out);
	}

	public void end() {
		try {
			this.out.flush();
			this.out.close();
			this.in.close();
		} catch (Exception e){
			//do nothing then :)
		}
	}

	public static void main(String[] args) throws Exception {
		Main solver = new Main();
		solver.solve();
		solver.end();
	}
}


import java.util.Scanner;

public class Pizza {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long n = sc.nextLong();
        n++;
        if(n==1){
            System.out.println("0");
        }else
        if(n%2==0)
            System.out.println(n/2);
        else
            System.out.println(n);
    }

}


//45G

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

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

		int n = Integer.parseInt(br.readLine());
		int s = n*(n+1)/2;

		if (n == 2) {
			System.out.println("1 1");
			return;
		}

		boolean[] sieve = new boolean[s+1];
		sieve[0] = sieve[1] = true;
		for (int j = 4; j < sieve.length; j += 2) {
			sieve[j] = true;
		}
		for (int i = 3; i < sieve.length; i += 2) {
			if (!sieve[i]) {
				for (int j = 3*i; j < sieve.length; j += i<<1) {
					sieve[j] = true;
				}
			}
		}
		int i;
		for (i = 2; i <= s/2; i++) {
			if (!sieve[i] && !sieve[s-i])
				break;
		}
		if (i > s/2) {
			for (i = 2; i <= (s-3)/2; i++) {
				if (!sieve[i] && !sieve[s-3-i])
					break;
			}
			int j;
			for (j = 0; i > n-j; j++) {
				i -= n-j;
			}
			switch (i) {
			case '1':
				System.out.print("2 1 3");
				for (int k = 3; k < n-j; k++) {
					System.out.print(" 1");
				}
				break;
			case '2':
				System.out.print("1 2 3");
				for (int k = 3; k < n-j; k++) {
					System.out.print(" 1");
				}
				break;
			case '3':
				System.out.print("2 2 3");
				for (int k = 3; k < n-j; k++) {
					System.out.print(" 1");
				}
				break;
			default:
				System.out.print("1 1 3 ");
				for (int k = 3; k < i-1; k++) {
					System.out.print("1 ");
				}
				System.out.print("2");
				for (int k = i; k < n-j; k++) {
					System.out.print(" 1");
				}
				break;
			}
			for (int k = n-j; k < n; k++) {
				System.out.print(" 2");
			}
			System.out.println();
		}
		else {
			int j;
			for (j = 0; i > n-j; j++) {
				i -= n-j;
			}
			for (int k = 0; k < i-1; k++) {
				System.out.print("1 ");
			}
			System.out.print("2");
			for (int k = i; k < n-j; k++) {
				System.out.print(" 1");
			}
			for (int k = n-j; k < n; k++) {
				System.out.print(" 2");
			}
			System.out.println();
		}
	}
}


import java.util.ArrayList;
import java.util.Collections;
import java.util.LinkedList;
import java.util.Scanner;

public class haha {

	public static void main(String[] args) {

		Scanner in = new Scanner(System.in) ;
		int n = in.nextInt() ;
		ArrayList<Integer> arr = new ArrayList<Integer>() ;
		for(int i = 0 ; i < n ; ++i) {
			arr.add(in.nextInt()) ;
		}
		Collections.sort(arr) ;
		System.out.println(arr.get(n/2)) ;
	}
}


import java.io.*;
import java.util.*;
import java.math.*;
public class incARG
{
    public static void main(String[] args) throws IOException
    {
        //Locale.setDefault (Locale.US);
        Reader in = new Reader();
        StringBuilder out = new StringBuilder();

        int n = in.nextInt();
        char[] bits = new char[n];
        String bitz = out.append(in.next().trim()).reverse().toString();
        for (int i = 0; i < bits.length; i++)
            bits[i]=bitz.charAt(i);

        BigInteger tn, bn = new BigInteger(bitz, 2);
        bn = bn.add(BigInteger.ONE);
        //System.out.println(bn+" "+bn.bitLength());

        String bites = bn.toString(2);
        if(bites.length() < bitz.length())
        {
            int c = bitz.length()-bites.length();
            bites = "";
            for (int u = 0; u < c; u++)
                bites += "0";
            bites += bn.toString(2);
        }
        //System.out.println(bites);
        //if(bn.bitLength() > n)
        int diff = 0;
            for (int i = 0, j = bites.length()-n; i < bitz.length(); i++, j++)
                if(bites.charAt(j)!=bitz.charAt(i))
                    diff++;

        /*for (int i = 0; i < bitz.length()-bn.bitLength(); i++)
            bites += "0";
        bites += bn.toString();
        int diff = 0;
        for (int i = 0; i < bites.length(); i++) {
            if(bites.charAt(i)!=bitz.charAt(i))
                diff++;
        }*/
        System.out.println(diff);
    }
    static class  Reader
    {
        BufferedReader br;
        StringTokenizer st;
        Reader() { // To read from the standard input
            br = new BufferedReader(new InputStreamReader(System.in));
        }
        Reader(int i) throws IOException { // To read from a file
            br = new BufferedReader(new FileReader("Sample Input.txt"));
        }
       String next() throws IOException {
          while (st == null || !st.hasMoreTokens())
             st = new StringTokenizer(br.readLine());
          return st.nextToken();
       }
       int nextInt() throws IOException { return Integer.parseInt(next()); }
       long nextLong() throws IOException { return Long.parseLong(next()); }
       double nextDouble() throws IOException { return Double.parseDouble(next()); }
       String nextLine() throws IOException { return br.readLine(); }
    }

}


		import java.io.*;
import java.util.*;
		public class TreeMapDemo {
		public static void main(String[] args) throws IOException {
		BufferedReader k=new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer str=new StringTokenizer(k.readLine(),":");
		String hour=str.nextToken();
		String mint=str.nextToken();
		boolean flag=true;
		int max=0;
		for (int i = 0; i < hour.length(); i++) {
			if (hour.charAt(i)>='A'&&hour.charAt(i)<='Z') {
				if (max<hour.charAt(i)-'A'+10) {
					max=hour.charAt(i)-'A'+10;
				}
			}
			else if (max<hour.charAt(i)-'0') {
				max=hour.charAt(i)-'0';
			}
		}
		for (int i = 0; i < mint.length(); i++) {
			if (mint.charAt(i)>='A'&&mint.charAt(i)<='Z') {
				if (max<mint.charAt(i)-'A'+10) {
					max=mint.charAt(i)-'A'+10;
				}
			}
			else if (max<mint.charAt(i)-'0') {
				max=mint.charAt(i)-'0';
			}
		}
		max++;
		if (max==1) {
			System.out.println(-1);
			return;
		}
		String base="";
		int count=0;
		while (max<61) {
			long x=0,y=0;
			if (max>=37) {
				 x=getvalue(hour, max);
				 y=getvalue(mint, max);
			}
			else{
			 x=Long.parseLong(hour,max);
			 y=Long.parseLong(mint,max);
			}
			if (x<24&&y<60) {
				base+=max+" ";
				max++;
				count++;
			}
			else {
				flag=false;
				break;
			}
		}

		if (flag) {
			System.out.println(-1);
		}
		else if (count==0) {
			System.out.println(0);
		}
		else {
			System.out.println(base);
		}

		}
		public static long getvalue(String num,int base){
			int counter=0;
			long x=0;
			for (int i = num.length()-1; i >= 0; i--) {
				if (num.charAt(i)>='A'&&num.charAt(i)<'Z') {
					x+=(num.charAt(i)-'A'+10)*Math.pow(base, counter);
				}
				else {
					x+=(num.charAt(i)-'0')*Math.pow(base, counter);
				}
				counter++;
			}
			return x;

		}
		}


import javax.print.DocFlavor;
import javax.swing.*;
import java.lang.reflect.Array;
import java.util.*;
import java.io.*;
public class Main {
    static int max;
    static int min;
    static int d;
    static void combinations(int[] arr,int index,ArrayList<ArrayList<Integer>> ans,ArrayList<Integer> al){
        if(al.size()>=2) {
            int sum = 0;
            for (int i = 0; i < al.size(); i++) {
                sum += al.get(i);
            }
            if (sum >= min && sum <= max &&  al.get(al.size() - 1)-al.get(0)>=d) {
                ans.add(new ArrayList<>(al));
            }
        }

        for(int i=index;i<arr.length;i++){
            al.add(arr[i]);
            combinations(arr,i+1,ans,al);
            al.remove(al.size()-1);
        }
    }
    public static void main(String[] args) throws IOException {
        //Code starts
        FastReader ip = new FastReader();
        OutputStream output = System.out;
        PrintWriter out = new PrintWriter(output);
        int n=ip.nextInt();
        min=ip.nextInt();
        max=ip.nextInt();
        d=ip.nextInt();
        int[] arr=new int[n];
        for(int i=0;i<n;i++){
            arr[i]=ip.nextInt();
        }
        Arrays.sort(arr);
        ArrayList<ArrayList<Integer>> ans=new ArrayList<>();
        ArrayList<Integer> al=new ArrayList<>();
        combinations(arr,0,ans,al);
        out.print(ans.size());
        out.close();
        //Code ends
    }

    static class FastReader {
        BufferedReader br;
        StringTokenizer st;
        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.*;
import java.util.*;

public class Test{
  public static void main(String args[]){

    Scanner sc = new Scanner(System.in);

    long l1 = sc.nextLong();
    long r1 = sc.nextLong();
    long l2 = sc.nextLong();
    long r2 = sc.nextLong();
    long k = sc.nextLong();

    long p = Math.max(l1,l2);//System.out.println(q);
    long q = Math.min(r1,r2);//System.out.println(p);

    long ans =0;
    if(k<=q && k>=p)
      ans=q-p;
    else
      ans = q-p+1;

    if(ans>0)
    System.out.println(ans);
    else System.out.println(0);

  }
}


import java.util.*;

public class TV1 {

	public static void main(String[] args) {

		Scanner sc  = new Scanner(System.in);

		int ans = 0;
		int a[] = new int[3];
		for(int i = 0 ;i<3;i++) {

			a[i] = sc.nextInt();
		}
		Arrays.sort(a);
		int d = sc.nextInt();
		int sum = 0;

		int p = a[2]-a[1];
		int q = a[1]-a[0];

		if(p<d) {

			ans = ans + d-p;
		}
		if(q<d) {

			ans = ans + d-q;
		}

		System.out.println(ans);
	}

}


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

public class Main {

    static StringBuilder data = new StringBuilder();
    final static FastReader in = new FastReader();

    public static void main(String[] args) {
       int n=in.nextInt();
       int []a = new int[1000*1000+1];
        for (int i = 2; i < a.length; i++) {
            for (int j = i+i; j < a.length; j+=i) {
                a[j]=1;
            }

        }
        for (int i = 1; i < a.length; i++) {
            if(a[n*i+1]==1){
                System.out.println(i);
                break;
            }
        }

    }

    static void fileOut(String s) {
        File out = new File("output.txt");
        try {
            FileWriter fw = new FileWriter(out);
            fw.write(s);
            fw.flush();
            fw.close();
        } catch (IOException e) {
            e.printStackTrace();
        }

    }

    static class FastReader {
        BufferedReader br;
        StringTokenizer st;

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

        public FastReader(String path) {
            try {
                br = new BufferedReader(new
                        InputStreamReader(new FileInputStream(path)));
            } catch (FileNotFoundException e) {
                e.printStackTrace();
            }
        }

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

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

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

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

}


import java.util.Scanner;

public class Draw
{

    public static void main (String[] args) throws java.lang.Exception
    {
        Scanner myScanner = new Scanner(System.in);

        int n = myScanner.nextInt();

        System.out.println(n*3/2);

        myScanner.close();
    }
}


import java.io.IOException;
import java.io.OutputStreamWriter;
import java.util.Arrays;
import java.io.BufferedWriter;
import java.util.InputMismatchException;
import java.util.Comparator;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.Writer;
import java.math.BigInteger;
import java.io.InputStream;

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

class TaskC {
	public void solve(int testNumber, InputReader in, OutputWriter out) {
		char[] s = in.readString().toCharArray();
		long[][] answer = new long[2][2];
		long[][] next = new long[2][2];
		answer[0][0] = answer[1][1] = 1;
		for (int i = 1; i <= s.length; i++) {
			int currentLetter = s[i - 1] - 'A';
			int nextLetter = s[i % s.length] - 'A';
			ArrayUtils.fill(next, 0);
			if (currentLetter == 0) {
				if (nextLetter == 0) {
					for (int j = 0; j < 2; j++) {
						next[j][0] = answer[j][1] + answer[j][0];
						next[j][1] = 0;
					}
				} else if (nextLetter == 1) {
					for (int j = 0; j < 2; j++) {
						next[j][0] = answer[j][1] + answer[j][0];
						next[j][1] = answer[j][1];
					}
				}
			} else {
				if (nextLetter == 0) {
					for (int j = 0; j < 2; j++) {
						next[j][0] = answer[j][1];
						next[j][1] = answer[j][0];
					}
				} else if (nextLetter == 1) {
					for (int j = 0; j < 2; j++) {
						next[j][0] = answer[j][1];
						next[j][1] = answer[j][1];
					}
				}
			}
			long[][] temp = next;
			next = answer;
			answer = temp;
		}
		long result = answer[0][0] + answer[1][1];
		out.printLine(result);
	}
}

class InputReader {

	private InputStream stream;
	private byte[] buf = new byte[1024];
	private int curChar;
	private int numChars;

	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 readString() {
		int c = read();
		while (isSpaceChar(c))
			c = read();
		StringBuffer res = new StringBuffer();
		do {
			res.appendCodePoint(c);
			c = read();
		} while (!isSpaceChar(c));
		return res.toString();
	}

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

	}

class OutputWriter {
	private final PrintWriter writer;

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

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

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

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

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

	}

class ArrayUtils {

	public static void fill(long[][] array, long value) {
		for (long[] row : array)
			Arrays.fill(row, value);
	}

	}


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

public class E implements Runnable {

	private void solve() throws IOException {
		int n = nextInt();
		String s = nextToken();
		int[] digits = new int[2 * n];
		for (int i = 0; i < 2 * n; i++) {
			digits[i] = s.charAt(2 * n - 1 - i) - '0';
		}
		long[] pows = new long[n];
		pows[0] = 1;
		for (int i = 1; i < n; i++) {
			pows[i] = pows[i - 1] * 10;
		}
		long[][] d = new long[n + 1][n + 1];
		d[0][0] = 0;
		for (int sum = 1; sum <= 2 * n; sum++) {
			for (int i = Math.max(sum - n, 0); i <= Math.min(sum, n); i++) {
				int j = sum - i;
				if (i > 0)
					d[i][j] = Math.max(d[i][j], d[i - 1][j] + digits[sum - 1]
							* pows[i - 1]);
				if (j > 0)
					d[i][j] = Math.max(d[i][j], d[i][j - 1] + digits[sum - 1]
							* pows[j - 1]);
			}
		}

		boolean[] res = new boolean[2 * n];
		int c1 = n, c2 = n;
		while (c1 + c2 > 0) {
			int sum = c1 + c2;
			if (c1 > 0
					&& d[c1][c2] == d[c1 - 1][c2] + digits[sum - 1]
							* pows[c1 - 1]) {
				res[sum - 1] = true;
				c1--;
				continue;
			}
			if (c2 > 0
					&& d[c1][c2] == d[c1][c2 - 1] + digits[sum - 1]
							* pows[c2 - 1]) {
				res[sum - 1] = false;
				c2--;
				continue;
			}
		}

		for (int i = 0; i < n; i++) {
			boolean t = res[i];
			res[i] = res[2 * n - 1 - i];
			res[2 * n - 1 - i] = t;
		}

		for (int i = 0; i < 2 * n; i++) {
			out.print(res[i] ? 'H' : 'M');
		}
	}

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

	BufferedReader br;
	StringTokenizer st;
	PrintWriter out;
	boolean eof = false;

	public void run() {
		Locale.setDefault(Locale.US);
		try {
			br = new BufferedReader(new InputStreamReader(System.in));
			out = new PrintWriter(System.out);
			solve();
			out.close();
		} catch (Throwable e) {
			e.printStackTrace();
			System.exit(239);
		}
	}

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

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

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

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


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

public class R554D
{

	static long mod = (long)(1e9)+7;
	static long[] fact = new long[3000];
	static int n;
	static long[][][] memo;

    public static void main (String[] args)
    {
        JS scan = new JS();
        n = scan.nextInt();
        memo = new long[2][n+1][n+1];
        for(int i = 0; i < 2; i++){
        	for(int j = 0; j <= n; j++){
        		Arrays.fill(memo[i][j], -1);
        	}
        }
        System.out.println(solve(0, 0, 0)); //DON'T SUBMIT BEFORE YOU MOD
    }

    static long solve(int cant, int i, int j){
    	if(memo[cant][i][j] != -1) return memo[cant][i][j];
    	long resNoTake = 0;
    	if(i < n) resNoTake += solve(0, i+1, j);
    	if(j < i) resNoTake += solve(0, i, j+1);
    	resNoTake %= mod;
    	if(cant == 1) return memo[cant][i][j] = resNoTake;

    	long resTake = 0;
    	long op1 = 0;
    	long op2 = 0;
    	if(i < n){
    		op1 = 1+solve(1, i+1, j);
    		if(j < i){
    			op1 += solve(0, i, j+1);
    		}
    		op1 %= mod;
    	}
    	if(j < i){
    		op2 = 1+solve(1, i, j+1);
    		if(i < n){
    			op2 += solve(0, i+1, j);
    		}
    		op2 %= mod;
    	}
    	resTake = Math.max(op1, op2);

    	return memo[cant][i][j] = Math.max(resTake, resNoTake);
    }

    static long power(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 % 2 == 1)
                res = (res * x) % p;

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

    // Returns n^(-1) mod p
    static long modInverse(long n, long p)
    {
        return power(n, p-2, p);
    }

	static void _printParenthesis(char str[], int pos, int n, int open, int close)
    {
        if(close == n)
        {
            // print the possible combinations
            for(int i=0;i<str.length;i++)
                System.out.print(str[i]);
            System.out.println();
            return;
        }
        else
        {
            if(open > close) {
                str[pos] = '}';
                _printParenthesis(str, pos+1, n, open, close+1);
            }
            if(open < n) {
                str[pos] = '{';
                _printParenthesis(str, pos+1, n, open+1, close);
            }
        }
    }

    // Wrapper over _printParenthesis()
    static void printParenthesis(char str[], int n)
    {
        if(n > 0)
        _printParenthesis(str, 0, n, 0, 0);
        return;
    }

	static class JS{
		public int BS = 1<<16;
		public char NC = (char)0;
		byte[] buf = new byte[BS];
		int bId = 0, size = 0;
		char c = NC;
		double num = 1;
		BufferedInputStream in;

		public JS() {
			in = new BufferedInputStream(System.in, BS);
		}

		public JS(String s) throws FileNotFoundException {
			in = new BufferedInputStream(new FileInputStream(new File(s)), BS);
		}

		public char nextChar(){
			while(bId==size) {
				try {
					size = in.read(buf);
				}catch(Exception e) {
					return NC;
				}
				if(size==-1)return NC;
				bId=0;
			}
			return (char)buf[bId++];
		}

		public int nextInt() {
			return (int)nextLong();
		}

		public long nextLong() {
			num=1;
			boolean neg = false;
			if(c==NC)c=nextChar();
			for(;(c<'0' || c>'9'); c = nextChar()) {
				if(c=='-')neg=true;
			}
			long res = 0;
			for(; c>='0' && c <='9'; c=nextChar()) {
				res = (res<<3)+(res<<1)+c-'0';
				num*=10;
			}
			return neg?-res:res;
		}

		public double nextDouble() {
			double cur = nextLong();
			return c!='.' ? cur:cur+nextLong()/num;
		}

		public String next() {
			StringBuilder res = new StringBuilder();
			while(c<=32)c=nextChar();
			while(c>32) {
				res.append(c);
				c=nextChar();
			}
			return res.toString();
		}

		public String nextLine() {
			StringBuilder res = new StringBuilder();
			while(c<=32)c=nextChar();
			while(c!='\n') {
				res.append(c);
				c=nextChar();
			}
			return res.toString();
		}

		public boolean hasNext() {
			if(c>32)return true;
			while(true) {
				c=nextChar();
				if(c==NC)return false;
				else if(c>32)return true;
			}
		}
	}
}


import java.io.*;
public class Lucky_Numbers {
public static void main(String ar[])throws IOException
{
	long n;
	long sum=0;
	BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
	n=Long.parseLong(br.readLine());
	System.out.println(((long)Math.pow(2,n)-1)*2);
}
}


import java.io.FileInputStream;
import java.io.IOException;
import java.util.Scanner;

public class Solution {

    public static void main(String[] args) throws IOException {
        Scanner sc = new Scanner(System.in);
//      Scanner sc = new Scanner(new FileInputStream("/home/camoroh13/temp/input.txt"));
        String n = sc.nextLine();
        String m = sc.nextLine();
        String ans="OK";

            String tm = "";
            int[] c = new int[10];
            c[0] = c[1] = c[2] = c[3] = c[4] = c[5] = c[6] = c[7] = c[8] = c[9] = 0;

            for (int i=0;i < 10; i++) {
                String str = i+"";
                int pos = n.indexOf(str);
                while (pos > -1) {
                    c[i]++;
                    pos = n.indexOf(str, pos+1) ;
                }
            }

            int k = 1;
            while (k <= 9 && c[k] == 0) {
                k++;
            }

            if (k < 10) {
                for (int j=0; j< c[k]; j++) {
                    tm += k+"";
                    c[k]--;
                    break;
                }
            }
                for (int j=1; j<= c[0]; j++) {
                    tm += "0";
                }
            for (int i=1;i < 10; i++) {
                String str = i+"";
                for (int j=1; j<= c[i]; j++) {
                    tm += str;
                }
            }

          if (!tm.equals(m)) {
                ans = "WRONG_ANSWER";
            }

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

}