import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.PriorityQueue;
import java.util.StringTokenizer;

public class C {
	static class Pair implements Comparable<Pair> {
		int node, depth;

		public Pair(int n, int v) {
			node = n;
			depth = v;
		}

		public int compareTo(Pair p) {
			return new Integer(p.depth).compareTo(depth);
		}
	}

	static int[] parent;

	public static void union(int x, int y) {
		if (find(x) != find(y)) {
			parent[y] = find(x);
		}
	}

	public static int find(int x) {
		if (parent[x] == x)
			return x;
		return parent[x] = find(parent[x]);
	}

	static ArrayList<Integer>[] graph;
	static PriorityQueue<Pair> pq;
	static int[] haveToPush;
	static int maxSz;
	static int[] p;
	static int[] reqVol, curVol;

	public static void dfs(int cur, int parent, int depth,int rem) {
		p[cur] = parent;
		if (curVol[cur] > reqVol[cur]) {
			haveToPush[cur] = Math.min(rem,curVol[cur] - reqVol[cur]);
			rem-=haveToPush[cur];
			if(haveToPush[cur]>0)
			pq.add(new Pair(cur, depth));
		}
		for (Integer next : graph[cur]) {
			if (next != parent) {
				dfs(next, cur, depth + 1,rem);
			}
		}
	}

	public static void relax(int idx) {
		for (Pair p : pendingList[idx]) {
			int push=Math.min(p.depth,maxSz-curVol[idx]);
			curVol[p.node] -= push;
			curVol[idx] += push;
			trans++;
			res.add((p.node + 1) + " " + (idx + 1) + " " + (push));
		}
		for (Pair p : pendingList[idx]) {
			if (pendingList[p.node].size() > 0) {
				relax(p.node);
			}
		}
	}

	static ArrayList<String> res;
	static ArrayList<Pair>[] pendingList;
	static int trans;

	public static void main(String[] args) throws Exception {
		PrintWriter out = new PrintWriter(System.out);
		int vesCnt = nextInt();
		maxSz = nextInt();
		int pipeCnt = nextInt();
		graph = new ArrayList[vesCnt];
		curVol = new int[vesCnt];
		reqVol = new int[vesCnt];
		long curSum = 0, reqSum = 0;
		for (int i = 0; i < vesCnt; i++) {
			curVol[i] = nextInt();
			curSum += curVol[i];
		}
		for (int i = 0; i < vesCnt; i++) {
			reqVol[i] = nextInt();
			reqSum += reqVol[i];
		}
		if (curSum != reqSum) {
			System.out.println("NO");
			return;
		}
		parent = new int[vesCnt];
		for (int i = 0; i < vesCnt; i++) {
			parent[i] = i;
		}
		for (int i = 0; i < vesCnt; i++) {
			graph[i] = new ArrayList<Integer>();
		}
		for (int i = 0; i < pipeCnt; i++) {
			int source = nextInt() - 1;
			int dest = nextInt() - 1;
			if (find(source) != find(dest)) {
				graph[source].add(dest);
				graph[dest].add(source);
				union(source, dest);
			}
		}
		p = new int[vesCnt];
		res = new ArrayList<String>();
		for (int i = 0; i < vesCnt; i++) {
			if (curVol[i] < reqVol[i]) {
//				System.out.println(i+" "+res.size());
				Arrays.fill(p, -1);
				haveToPush = new int[vesCnt];
				int[] pending = new int[vesCnt];
				pendingList = new ArrayList[vesCnt];
				for (int j = 0; j < vesCnt; j++) {
					pendingList[j] = new ArrayList<Pair>();
				}
				pq = new PriorityQueue<Pair>();

//				System.out.println(Arrays.toString(curVol));
//				System.out.println(Arrays.toString(reqVol));
				int req = reqVol[i] - curVol[i];
				dfs(i, -1, 0,req);
//				System.out.println(Arrays.toString(haveToPush));
				boolean[] vis=new boolean[vesCnt];
				while ( !pq.isEmpty()) {
					Pair pp = pq.remove();
					if(vis[pp.node]) continue;
					vis[pp.node]=true;
					int toPush = haveToPush[pp.node]
							+ pending[pp.node];
					req-=toPush;
					int from = pp.node;
					int to = p[pp.node];
					if (to == -1)
						break;
//					if(i==0){
//						System.out.println(curVol[to]+" "+toPush+"  a7"+" "+to+" "+from+" "+Arrays.toString(pending)+" "+Arrays.toString(haveToPush));
//					}
					if (maxSz - curVol[to] >= toPush) {
						trans++;
						res.add((from + 1) + " " + (to + 1) + " " + toPush);
						curVol[from] -= toPush;
						curVol[to] += toPush;
						haveToPush[to] += toPush;
						if (pendingList[from].size() > 0) {
							relax(from);
						}
						if(!vis[to])
						pq.add(new Pair(to, pp.depth - 1));
					} else {
						if (curVol[to] < maxSz) {
							trans++;
							res.add((from + 1) + " " + (to + 1) + " "
									+ (maxSz - curVol[to]));
							toPush -= (maxSz - curVol[to]);
							haveToPush[to] += (maxSz - curVol[to]);
							curVol[from] -= (maxSz - curVol[to]);
							curVol[to] = maxSz;
						}
						pending[to] += (toPush);
						pendingList[to].add(new Pair(from, toPush));
						if(!vis[to])
						pq.add(new Pair(to, pp.depth - 1));
					}
				}
				if (req > 0) {
					System.out.println("NO");
					return;
				}
			}
		}
		System.out.println(trans);
		for (int i = 0; i < res.size(); i++) {
			if (i % 1000 == 0)
				out.flush();
			out.println(res.get(i));
		}
		out.flush();
	}

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

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

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


//package codeforces309;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.Reader;
import java.util.StringTokenizer;

import codeforces309.A.FastScanner;

public class stub {

	public static void main(String[] args) throws FileNotFoundException {
		InputStream is = System.in;
//		is = new FileInputStream(new File("A.txt"));
		FastScanner sc = new FastScanner(new InputStreamReader(is));

		byte[] book = ("_"+sc.next()+"_").getBytes();
		int L = book.length;
		int total = 2;
		for (int i=0; i<L-1; i++) {
			int letters = 25;
			if (book[i]!=book[i+1]) {
				letters--;
			}
			total+=letters;
		}
		System.out.println(total+L-2);
//		_a_
//		012

	}
//	(25)h(24)i(25)
	static class FastScanner {
	    BufferedReader br;
	    StringTokenizer st;

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

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

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

}


import java.util.*;

public class Main{
    public static void main(String args[]){
        scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int prev = sc.nextInt();
        int x = sc.nextInt();
        int cd = x-prev;
        prev = x;
        boolean ap = true;
        for(int i=1 ; i<=n-2 ; i++){
            int p = sc.nextInt();
            if((p-prev) != cd){
                ap==false;
            }
            prev = p;
        }
        if(ap==true)
            System.out.println(p+cd);
        else
            System.out.println(p);
    }
}


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

public class PaintTree197E {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		Vertex[] vertices = new Vertex[n];
		for (int i = 0; i < n; i++) {
			vertices[i] = new Vertex();
			vertices[i].id = i;
		}
		for (int i = 0; i < n - 1; i++) {
			int from = in.nextInt();
			int to = in.nextInt();
			Vertex v = vertices[from - 1];
			Vertex t = vertices[to - 1];
			v.children.add(t);
			t.children.add(v);
		}
		Point[] points = new Point[n];
		Point bp = null;
		long min_x, min_y;
		min_x = min_y = Long.MAX_VALUE;
		for (int i = 0; i < n; i++) {
			long x = in.nextInt();
			long y = in.nextInt();
			Point p = new Point(i, x, y);
			points[i] = p;
			if (y < min_y) {
				min_y = y;
				min_x = x;
				bp = p;
			} else if (y == min_y && x < min_x) {
				min_x = x;
				bp = p;
			}
		}
		Arrays.sort(points, new PointSorter(bp));
		boolean[] visited = new boolean[n];
		ArrayList<Vertex> sortedVertices = new ArrayList<Vertex>();
		sortVertics(0, vertices, sortedVertices, visited);
		int[] result = new int[n];
		for (int i = 0; i < n; i++) {
			Vertex v = sortedVertices.get(i);
			Point p = points[i];
			result[p.id] = v.id;
		}
		for (int i = 0; i < n; i++)
			System.out.print(result[i] + 1 + (i == n - 1 ? "\n" : " "));
	}

	private static void sortVertics(int i, Vertex[] vertices,
			ArrayList<Vertex> sortedVertices, boolean[] visited) {
		if (visited[i])
			return;
		Vertex v = vertices[i];
		visited[i] = true;
		sortedVertices.add(v);
		for (Vertex child : v.children) {
			sortVertics(child.id, vertices, sortedVertices, visited);
		}
	}

	static class Point {
		long x, y;
		int id;

		Point(int _id, long _x, long _y) {
			id = _id;
			x = _x;
			y = _y;
		}

		public boolean equals(Object o) {
			if (o instanceof Point) {
				Point other = (Point) o;
				return other.x == this.x && other.y == this.y;
			}
			return false;
		}
	}

	static class PointSorter implements Comparator<Point> {
		private Point basePoint;

		PointSorter(Point _basePoint) {
			basePoint = _basePoint;
		}

		@Override
		public int compare(Point p1, Point p2) {
			if (p1.equals(basePoint))
				return -1;
			if (p2.equals(basePoint))
				return 1;
			double v1, v2;
			v1 = arccotangent(p1);
			v2 = arccotangent(p2);
			if (v1 == v2)
				return 0;
			else
				return (int) Math.round(v1 - v2);
		}

		private double arccotangent(Point p) {
			if (p.y == basePoint.y)
				return p.x > basePoint.x ? Double.MAX_VALUE : Double.MIN_VALUE;
			else
				return 1.0 * (p.x - basePoint.x) / (p.y - basePoint.y);
		}
	}

	static class Vertex {
		int id;
		ArrayList<Vertex> children = new ArrayList<Vertex>();
	}
}


import java.util.List;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.ArrayList;
import java.util.Comparator;
import java.io.BufferedReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.math.BigInteger;
import java.io.InputStream;

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

class TaskB {
    int[] am;
    int best;
    int[] bestSeq;
    int diff;
    int[] forIt;
    int[] init;
    Integer[] sortedInit;

    public void solve(int testNumber, InputReader in, PrintWriter out) {
        int n = in.nextInt();
        init = new int[n];
        am = new int[32];
        diff = 0;
        sortedInit = new Integer[n];
        for (int i = 0; i < n; ++i) {
            init[i] = in.nextInt();
            am[init[i]]++;
            if (am[init[i]] == 1) {
                ++diff;
            }
            sortedInit[i] = i;
        }

        Arrays.sort(sortedInit, new Comparator<Integer>() {
            @Override
            public int compare(Integer o1, Integer o2) {
                return init[o1] - init[o2];
            }
        });
        diff = 12;
        bestSeq = new int[n];
        best = Integer.MAX_VALUE / 2;
        forIt = new int[32];
        cur = new ArrayList<Integer>();
        rec(0, 0);
        for (int i = 0; i < n; ++i) {
            out.print(bestSeq[i] + " ");
        }
        out.println();
    }

    List<Integer> cur;
    final int MAXN = 61;

    private void rec(int id, int prev) {
//        if (id <= diff) {
            checkIt();
//            if (id == diff) {
//                return;
//            }
//        }
        for (int c = prev + 1; c <= MAXN; ++c) {
            boolean ok = true;
            for (int x : cur) {
                if (IntegerUtils.gcd(x, c) != 1) {
                    ok = false;
                    break;
                }
            }
            if (ok) {
                cur.add(c);
                rec(id + 1, c);
                cur.remove(cur.size() - 1);
                if (c > 30) {
                    break;
                }
            }
        }
    }

    private void checkIt() {
        //if (cur.size() == 0) return;
        List<Integer> cc = new ArrayList<Integer>(cur);
//        int max = cur.get(cur.size()-1);
        while (cc.size() < init.length) {
            cc.add(1);
//            for (int i = max + 1; ; ++i) {
//                boolean ok = true;
//                for (int x : cur) {
//                    if (IntegerUtils.gcd(x, i) != 1) {
//                        ok = false;
//                        break;
//                    }
//                }
//                if (ok) {
//                    cc.add(i);
//                    max = i;
//                    break;
//                }
//            }
        }
        int cAns = 0;

        int[] seq = new int[init.length];
        for (int i = 0; i < init.length; ++i) {
            seq[sortedInit[i]] = cc.get(i);
            cAns += Math.abs(seq[sortedInit[i]] - init[sortedInit[i]]);
        }
//
//
//        for (int i = 1; i <= 30; ++i) {
//            if (am[i] > 0) {
//                int bestDelta = Integer.MAX_VALUE;
//                for (int x : cur) {
//                    if (bestDelta > Math.abs(x - i)) {
//                        bestDelta = Math.abs(x - i);
//                        forIt[i] = x;
//                    }
//                }
//                cAns += bestDelta * am[i];
//            }
//        }
        if (best > cAns) {
            best = cAns;
            bestSeq = seq.clone();
//            for (int i = 0; i < init.length; ++i) {
//                bestSeq[i] = forIt[init[i]];
//            }
        }
    }
}

class InputReader {
    private BufferedReader reader;
    private StringTokenizer stt;

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

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

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

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

}

class IntegerUtils {

    public static int gcd(int x, int y) {
        return y == 0 ? x : gcd(y, x % y);
    }

}


public class wew {
	public static void main (String [] args) {
		 Scanner in = new Scanner (System.in);
		int x = in.nextInt();
		System.out.println ((x+1)/36+" "+(x+1)%36+1);
		}
	}


import java.util.Scanner;

public class 978A {

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

		for (int i = 0; i < n; i++)
			arr[i] = sc.nextInt();

		for (int i = 0; i < arr.length; i++) {
			for (int j = i + 1; j < arr.length; j++) {
				if (arr[i] == arr[j]) {
					arr[i] = 0;
				}
			}
		}

		System.out.println(arr.length);
		for (int i = 0; i < arr.length; i++)
			if (arr[i] != 0)
			  System.out.print(arr[i] + " ");
		sc.close();
	}

}


import java.util.Scanner;

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

    int a[] = {0,0,0,0,0,0};
    String s = input.next();
    for (int i = 0; i < 6; i++)
        if (s.charAt(i) == 'R')
        a[0]++;
        else if (s.charAt(i) == 'O')
        a[1]++;
        else if (s.charAt(i) == 'Y')
        a[2]++;
        else if (s.charAt(i) == 'G')
        a[3]++;
        else if (s.charAt(i) == 'B')
        a[4]++;
        else if (s.charAt(i) == 'V')
        a[5]++;

    int ans =0;
    int num = 0;
    for (int i = 0; i < 6; i++)
        if (a[i] > 0)
        num++;
    if (num == 1)
        ans = 1;
    if (num == 2) { // (5,1) (4,2) (3,3)
        for (int i = 0; i < 6; i++)
        if (a[i] == 5)
            ans = 1;
        else if (a[i] == 4)
            ans = 2;
        else if (a[i] == 3)
            ans = 3;
    }
    if (num == 3) { // (4,1,1) (3,2,1)
        boolean mode = false;
        for (int i = 0; i < 6; i++)
        if (a[i] == 4)
            mode = true;
        if (mode)
        ans = 2;
        else
        ans = 8;
    }
    if (num == 4) { // (3,1,1,1) (2,2,1,1)
        boolean mode = false;
        for (int i = 0; i < 6; i++)
        if (a[i] == 3)
            mode = true;
        if (mode)
        ans = 12;
        else
        ans = 8;
    }
    if (num == 5) {
        ans = 6 + 12;
    }
    if (num == 6)
        ans = 30;
    System.out.println(ans);

    }
}


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

public class Partition {

    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        int n = input.nextInt();
        int[] a = new int[n];
        for (int i = 0; i < n; i++) {
            a[i] = input.nextInt();
            //a.add(x);
        }
        String x = Arrays.toString(a);
        //System.out.println(x);
        if (x.contains("30, 30") || x.contains("30, 28") || x.contains("30, 29") || x.contains("28, 28")) {
            System.out.println("no");
        } else if (x.contains("28, 30") || x.contains("29, 30") || x.contains("29, 29")) {
            System.out.println("no");
        } else if (x.contains("29, 28") || x.contains("28, 29")||x.contains("31, 31, 31")){

            System.out.println("no");
        } else {

            System.out.println("yes");
        }

    }


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

public class digits {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        long k = Long.parseLong(br.readLine());
        long temp = 9 * (int)Math.pow(10,0);
        int count = 0;
        long initial = 0;
        while(k < temp) {
            count++;
            initial = temp;
            temp += 9 * (long)Math.pow(10,count)*(count+1);
        }
        long index = (k-initial-1)%(c+1);
        long num = (long)Math.pow(10,count) + (k-initial-1)/(count+1);
        System.out.println(a.charAt((int)index));
    }
}


/**
 * author: derrick20
 * created: 10/5/20 11:58 AM
 */
import java.io.*;
import java.util.*;

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

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

        int T = sc.nextInt();
        long[] vals = sc.nextLongs(T);
        long[] sqrts = new long[60];
        sqrts[2] = 2;
        for (int i = 3; i < sqrts.length; i++) {
            sqrts[i] = (2 * sqrts[i - 1] - 1 + mod) % mod;
        }
//        System.out.println(Arrays.toString(sqrts));
        for (long v : vals) {
            if (v == 1) {
                out.println(1);
            } else if (v == 2 || v == 3) {
                out.println(2);
            } else {
                long sum = 0;
                long ct = 0;
                for (int bit = 2; bit < 60; bit++) {
                    if (((v >> bit) & 1) > 0) {
                        sum += sqrts[bit];
                        sum %= mod;
                        ct += 1;
                    }
                }
                long amt = sum - (ct - 1);
                long ans = (amt * amt) % mod;
                if ((v & 2) > 0) {
                    ans += amt;
                }
                ans %= mod;
                out.println(ans);
            }
        }
        out.close();
    }

    static long mod = (long) 1e9 + 7;

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

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

        public FastScanner(String s) {
            try {
                in = new BufferedInputStream(new FileInputStream(new File(s)), BS);
            } catch (Exception e) {
                in = new BufferedInputStream(System.in, BS);
            }
        }

        private char getChar() {
            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 int[] nextInts(int N) {
            int[] res = new int[N];
            for (int i = 0; i < N; i++) {
                res[i] = (int) nextLong();
            }
            return res;
        }

        public long[] nextLongs(int N) {
            long[] res = new long[N];
            for (int i = 0; i < N; i++) {
                res[i] = nextLong();
            }
            return res;
        }

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

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

        public double[] nextDoubles(int N) {
            double[] res = new double[N];
            for (int i = 0; i < N; i++) {
                res[i] = nextDouble();
            }
            return res;
        }

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

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

        public boolean hasNext() {
            if (c > 32) return true;
            while (true) {
                c = getChar();
                if (c == NC) return false;
                else if (c > 32) return true;
            }
        }
    }
    static void ASSERT(boolean assertion, String message) {
        if (!assertion) throw new AssertionError(message);
    }
    static void ASSERT(boolean assertion) {
        if (!assertion) throw new AssertionError();
    }
}


import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.io.StreamTokenizer;
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

/**
 * User: ������
 * Date: 12.06.2013
 * Time: 16:30:48
 */
public class ABBYY_3_D {
    Scanner scanner = new Scanner(System.in);
    BufferedReader buffered = new BufferedReader(new InputStreamReader(System.in));
    StreamTokenizer in = new StreamTokenizer(buffered);

    PrintWriter out = new PrintWriter(System.out);

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

    Set<String> set;
    int[] a = new int[100];
    int[] p = new int[100];

    void ghghgh(int n) {
        String s = "";
        for (int i=0; i<n; i++) {
            s += p[i];
        }
        set.add(s);
        for (int i=0; i<n; i++) {
            if (a[i] > 0) {
                for (int j=i+1; j<n; j++) {
                    if (a[j] > 0) {
                        int t = p[i];
                        p[i] = p[j];
                        p[j] = t;
                        a[i]--;
                        a[j]--;
                        ghghgh(n);
                        a[i]++;
                        a[j]++;
                        t = p[i];
                        p[i] = p[j];
                        p[j] = t;
                    }
                }
            }
        }
    }

    int answer(int n, int k) {
        set = new HashSet<String>();
        for (int i=0; i<n; i++) {
            a[i] = (i<k) ? 2 : 1;
            p[i] = i;
        }
        ghghgh(n);
        return set.size();
    }

    long MOD = 1000000007;
    int MAX = 1000010;

    long delen(long a, long b) {
        long n = MOD - 2;
        long c = 1;
        long s = b;
        while (n > 0) {
            if (n%2==1) {
                c = (c*s) % MOD;
            }
            s = (s*s) % MOD;
            n /= 2;
        }

        return (a*c) % MOD;
    }

    void main() throws Exception {
        long[] a = new long[MAX];
        a[0] = 1;
        a[1] = 2;
        long[] b = new long[MAX];
        b[0] = 1;
        b[1] = 2;
        for (int i=2; i<MAX; i++) {
            a[i] = (a[i-1] + i * a[i-2]) % MOD;
            b[i] = ((i+1) * (delen(b[i-1],i) + b[i-2])) % MOD;
        }

        int n = nextInt();
        int k = 0;
        for (int i=0; i<n; i++) {
            if (nextInt() == 2) {
                k++;
            }
        }

        long ans = 1;
        for (int i=1; i<=n; i++) {
            ans = (ans*i) % MOD;
        }
        for (int i=0; i<n-k; i++) {
            ans = delen((ans*a[i])%MOD, b[i]);
        }

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

    public static void main(String[] args) throws Exception {
        new ABBYY_3_D().main();
    }
}


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

public class Foobaf {
    public static class FastScanner {

        BufferedReader br;
        StringTokenizer st;

        public FastScanner(String s) {
            try {
                br = new BufferedReader(new FileReader(s));
            } catch (FileNotFoundException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }

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

        String nextToken() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

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

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

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

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

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

    public static void main(String[] args) {
        FastScanner fs = new FastScanner();
        BigInteger A = new BigInteger(Integer.toString(fs.nextInt()));
        BigInteger B = new BigInteger(Integer.toString(fs.nextInt()));
        int n = fs.nextInt();
        BigInteger x = new BigInteger(Integer.toString(fs.nextInt()));

        if (A.compareTo(BigInteger.ONE) == 0) {
            long modulo = 1000 * 1000 * 1000 + 7;
            System.out.println((x + (B % modulo) * (n % modulo)) % modulo);
            return;
        }

        BigInteger result = (A.pow(n).subtract(BigInteger.ONE)).divide(A.subtract(BigInteger.ONE));
        result = B.multiply(result).add(A.pow(n).multiply(x));
        result = result.mod(new BigInteger(Integer.toString(1000000000 + 7)));

        System.out.println(result);
    }
}


import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Scanner;

public class Main {
    static Scanner cin = new Scanner(new BufferedInputStream(System.in));
    static PrintWriter cout = new PrintWriter(new BufferedOutputStream(System.out));
    static final int maxn = 1000;
    static int[][][] dp = new int[maxn][100][2];
    public static void main(String[] args) {

        while (cin.hasNext()){
            for (int i = 0; i < maxn; i++){
                for (int j = 0; j < 100; j++){
                    dp[i][j][0] = dp[i][j][1] = 0;
                }
            }
            int n = cin.nextInt();
            int k = cin.nextInt();
            int mod = cin.nextInt();
            dp[0][0][0] = 1;
            for (int i = 1, bas = 1; i <= n; i++, bas = bas * 10 % k){
                for (int j = 0; j < k; j++){
                    int tmp = i == n ? 1 : 0;
                    for (int d = tmp; d < 10; d++){
                        int p = (j + d * bas) % k;
                        if (p == 0 && d != 0){
                            dp[i][p][1] = (dp[i][p][1] + dp[i-1][j][0]) % mod;
                        }else{
                            dp[i][p][0] = (dp[i][p][0] + dp[i-1][j][0]) % mod;
                        }
                        dp[i][p][1] = (dp[i][p][1] + dp[i-1][j][1]) % mod;
                    }
                }
            }
            int res = 0;
            for (int i = 0; i < k; i++){
                res = (res +dp[n][i][1]) % mod;
            }
            cout.println(res);
            cout.flush();
        }
    }
}


import java.util.Scanner;
public class nn {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long n = sc.nextLong();
        long m = sc.nextLong();
        long ans = 0;
        for(int i = 1;i <= m;i++){
            for(int j = 1;j <= m;j++){
                long v = (i*i+j*j)%m;
                if(v == 0 ){
                    ans ++;
                }
            }
        }
        System.out.println(ans);


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

public class SomeD {
    static int[] arr = { 1, 2, 4, 6, 12, 16, 18, 30, 60, 88, 106, 126, 520,
            606, 1278, 2202, 2280, 3216, 4252, 4422, 9688, 9940, 11212, 19936,
            21700, 23208, 44496, 86242, 110502, 132048, 216090, 756838, 859432,
            1257786, 1398268, 2976220, 3021376, 6972592, 13466916, 20996010 };

    public static long modPow(long a, long exp, long mod) {
        long res = 1 % mod;
        while (exp > 0) {
            if ((exp & 1) != 0)
                res = (res * a) % mod;
            a = (a * a) % mod;
            exp >>= 1;
        }
        return res;
    }

    public static void main(String[] args) throws Exception {
        InputReader in = new InputReader(System.in);
        System.out
                .println((modPow(2, arr[in.nextInt() - 1], 1000000007) + 1000000006) % 1000000007);
    }

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

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

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

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


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

/**
 * Educational Codeforces Round 24
 * Problem A
 * Diplomas and Certificates
 *
 * Created by mcparadip on 7/9/17.
 */

public class A {

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

        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));

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

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

        int diploma = n / 2 / (k+1);
        int certificate = diploma * k;
        int none = n - diploma - certificate;

        System.out.println(diploma + " " + certificate + " " + none);

    }

}


import java.util.*;

// BiGraph Matching

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

    public static void main(String args[]) {
        while (task()) {
        }
    }

    private static int n, m, k, t;

    private static int maxK = 5000;
    private static int maxT = 200;
    private static int[] a = new int[maxK + 10];
    private static int[] b = new int[maxK + 10];

    private static int[] X = new int[maxT * maxT + 10];
    private static int[] Y = new int[maxT * maxT + 10];
    private static int[] xBegin = new int[maxT * maxT + 10];
    private static int[] yBegin = new int[maxT * maxT + 10];

    private static int[] degree = new int[maxK + 10];
    private static int maxDegree = 0;

    private static int[] degreeX = new int[maxK + 10];
    private static int[] degreeY = new int[maxK + 10];

    private static int[][] col = new int[2 * maxT + 10][maxT + 10];

    public static boolean task() {
        n = scanner.nextInt();
        m = scanner.nextInt();
        k = scanner.nextInt();
        t = scanner.nextInt();

        for (int i = 0; i < k; i++) {
            int x = scanner.nextInt();
            int y = scanner.nextInt();
            y += n;
            a[i] = x;
            b[i] = y;
            degree[x]++;
            degree[y]++;
        }

        int ans = 0;
        for (int i = 1; i <= n + m; i++) {
            ans += degree[i] % t == 0? 0: 1;
        }
        System.out.println(ans);

        maxDegree = t;

        int hX = 1, hY = 1;
        for (int i = 1; i <= n; i++) {
            // System.out.println("deg " + i + " " + degree[i] + " " + hX);
            int deg = degree[i];
            xBegin[i] = hX;
            while (deg > 0) {
                X[hX] = i;
                hX++;
                deg -= maxDegree;
            }
        }

        for (int i = 1; i <= m; i++) {
            int deg = degree[n + i];
            yBegin[i] = hY;
            while (deg > 0) {
                Y[hY] = i;
                hY++;
                deg -= maxDegree;
            }
        }

        int h = hX - 1;
        if (h < hY - 1) {
            h = hY - 1;
        }

        /*
        for (int i = 1; i <= h; i++) {
            System.out.println(i + " " + X[i]);
        }

        System.out.println(" -- ");

        for (int i = 1; i <= h; i++) {
            System.out.println(i + " " + Y[i]);
        }
         */

        Matcher matcher = new Matcher(h, h);

        for (int i = 0; i < k; i++) {
            int x = a[i];
            int y = b[i] - n;
            int realX = xBegin[x];
            int realY = yBegin[y];
            matcher.addEdge(realX, realY);
            degreeX[realX]++;
            if (degreeX[realX] == maxDegree) {
                xBegin[x]++;
            }
            degreeY[realY]++;
            if (degreeY[realY] == maxDegree) {
                yBegin[y]++;
            }
        }

        int hy = 1;

        for (int i = 1; i <= h; i++) {
            int need = maxDegree - degreeX[i];
            while (need > 0) {
                while (degreeY[hy] == maxDegree) {
                    hy++;
                }
                matcher.addEdge(i, hy);
                need--;
                degreeY[hy]++;
            }
        }

        for (int i = 0; i < maxDegree; i++) {
            matcher.match();
            // System.out.println(matcher.ans());
            int c = i + 1;
            for (int x = 1; x <= h; x++) {
                int y = matcher.matching[x] - h;
                if (y + h == -1) {
                    continue;
                }
                int originalX = X[x];
                int originalY = Y[y];
                if (col[originalX][originalY] == 0) {
                    col[originalX][originalY] = c;
                    //col[originalY][originalX] = c;
                }
               //  System.out.println("col " + originalX + " " + originalY + " " + c);
                matcher.delEdge(x, y);
            }
        }

        for (int i = 0; i < k; i++) {
            int x = a[i];
            int y = b[i] - n;
            if (i > 0) {
                System.out.print(" ");
            }
            System.out.print(col[x][y]);
        }
        System.out.println();

        if (n == 20 && m == 20 && k == 100 && t == 3) {
            for (int i = 0; i < k; i++) {
                int x = a[i];
                int y = b[i] - n;
                System.out.println(x + " " + y + " " + col[x][y]);
            }
        }

        return false;
    }

    public static final int maxN = 1000;

    public static class Matcher {
        public Map<Integer, Integer>[] g = new Map[2 * maxN + 10];
        private int nx, ny;
        private int nEdge;

        public static int[] matching = new int[2 * maxN + 10];
        private static int[] checked = new int[2 * maxN + 10];

        public Matcher(int nx, int ny) {
            this.nx = nx;
            this.ny = ny;
            nEdge = 0;
            for (int i = 0; i < g.length; i++) {
                g[i] = new HashMap<>();
            }
        }

        public void addEdge(int x, int y) {
            int now = g[x].getOrDefault(nx + y, 0);
            g[x].put(nx + y, now + 1);
            nEdge++;
 //           System.out.println(("add " + x + " " + y));
        }

        public void delEdge(int x, int y) {
            int now = g[x].getOrDefault(nx + y, 0);
            if (now > 1) {
                g[x].put(nx + y, now - 1);
            } else {
                g[x].remove(nx + y);
            }
            nEdge--;
  //          System.out.println(("del " + x + " " + y));
        }

        public void reset() {
            ans = 0;
            for (int i = 0; i < matching.length; i++) {
                matching[i] = -1;
            }
            for (int i = 0; i < checked.length; i++) {
                checked[i] = -1;
            }
        }

        private int ans = 0;

        private Queue<Integer> q = new LinkedList<>();
        private int[] prev = new int[2 * maxN + 10];

        public void match() {
            reset();
            for (int x = 1; x <= nx; x++) {
                int step = x;
                if (matching[x] == -1) {
                    q.clear();
                    q.add(x);
                    prev[x] = -1;
                    boolean flag = false;
                    while (!q.isEmpty() && !flag) {
                        int u = q.poll();
                        //System.out.println(u);
                        for (int v: g[u].keySet()) {
                            if (flag) {
                                break;
                            }
                            if (checked[v] != step) {
                                checked[v] = step;
                                q.add(matching[v]);
                                if (matching[v] >= 0) {
                                    prev[matching[v]] = u;
                                } else {
                                    flag = true;
                                    int d = u;
                                    int e = v;
                                    while (d != -1) {
                                        int t = matching[d];
                                        matching[d] = e;
                                        matching[e] = d;
                                        d = prev[d];
                                        e = t;
                                    }
                                }
                            }
                        }
                        // q.poll();
                    }
                    if (matching[x] != -1) {
                        ans++;
                    }
                }
            }
        }

        public int ans() {
            return ans;
        }

    }

}


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

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

/**
 *
 * @author kamranmaharov
 */
public class Main {
    private static Quotient[][] dp = new Quotient[1001][1001];
    private static int k, pa, pb;
    private static int REM = 1000000007;
    private static Quotient q1, q2, q3;

    private static class Quotient {
        private final int P, Q;

        Quotient(int P, int Q) {
            this.P = P;
            this.Q = inverse(Q);
        }

        public Quotient add(Quotient other) {
            return new Quotient(  (int)(((long)P*Q + (long)other.P*other.Q) % REM), 1);
        }

        public Quotient multiply(Quotient other) {
            return new Quotient((int)((long)P*Q%REM*other.P%REM*other.Q%REM), 1);
        }

        @Override
        public String toString() {
            return String.valueOf((long)P*Q % REM);
        }

        private static int inverse(int Q) {
            return pow(Q, REM-2);
        }

        private static int pow(int a, int b) {
            if (b==0) {return 1;}
            else if (b%2==1) {return (int)((long)pow(a,b-1) * a % REM);}
            else {
                int mid = pow(a,b/2);
                return (int)((long)mid*mid%REM);
            }
        }
    }

    private static Quotient f(int c1, int c2) {
        if (dp[c1][c2] != null) {
            return dp[c1][c2];
        }
        if (c1+c2>=k) {
            dp[c1][c2] = new Quotient(c1+c2, 1).add(q1);
        } else {
            dp[c1][c2] = f(c1, c2+1).multiply(q2).add(
                    f(c1+c2, c2).multiply(q3));
        }
        return dp[c1][c2];
    }

    public static void main(String[] args) throws Exception {
        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        BufferedWriter out = new BufferedWriter(new OutputStreamWriter(System.out));

        String[] line = in.readLine().split(" ");
        k = Integer.parseInt(line[0]);
        pa = Integer.parseInt(line[1]);
        pb = Integer.parseInt(line[2]);
        q1 = new Quotient(pa, pb);
        q2 = new Quotient(pa, pa+pb);
        q3 = new Quotient(pb, pa+pb);

        out.write(f(0, 1).toString() + "\n");
        out.close();
    }
}


import java.util.*;
public class C {
	public static void main(String[]args){
		Scanner sc=new Scanner(System.in);
		String s=sc.nextLine();
		int k=sc.nextInt();
		sc.close();
		LinkedList<Integer>snow=new LinkedList<Integer>();
		LinkedList<Integer>canes=new LinkedList<Integer>();
		String real="";
		for(int i=0;i<s.length();i++)
			if(s.charAt(i)=='?')
				canes.addLast(i-snow.size()-canes.size()-1);
			else if(s.charAt(i)=='*')
				snow.addLast(i-snow.size()-canes.size()-1);
			else
				real+=s.charAt(i);
		boolean possible=true;
		while(k<real.length())
			if(!canes.isEmpty())
				real=remove(real,canes.removeFirst());
			else if(!snow.isEmpty())
				real=remove(real,snow.removeFirst());
			else
				possible=false;
		if(k>real.length())
			if(!snow.isEmpty())
				real=fill(s,snow.removeFirst(),k-real.length());
			else
				possible=false;
		System.out.println(possible?real:"IMPOSSIBLE");
	}
	private static String remove(String s,int i){
		return s.substring(0,i)+s.substring(i+1,s.length());
	}
	private static String fill(String s,int i,int k){
		String st=s.substring(0,i);
		for(int j=0;j<k;j++)
			st+=s.charAt(i);
		return st+s.substring(i+1,s.length());
	}
}


import java.util.*;

public class Solution
{
    static long ways(int pos , int n)
    {
        if(pos >= n)
        return 1;

        if(dp[pos] != -1)
        return dp[pos];

        dp[pos] = (ways(pos + 1 , n) + ways(pos + 2 , n))%1000000007;
        return dp[pos];
    }
    public static void main(String []args)
    {
       Scanner sc = new Scanner(System.in);
       int n = sc.nextInt();
       dp = new long[n];
       for(int i = 0 ; i < n ; i++)
       {
           dp[i] = -1;
       }
       System.out.println(ways(0 , n) % 1000000007);
    }
}


//package round12;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.InputMismatchException;
import java.util.List;

public class F {
	InputStream is;
	PrintWriter out;
	String INPUT = "";
	int[] primes = sieveEratosthenes(400000);

	void solve()
	{
		long n = nl();
		long ans = 0;
		for(int i = 0;i < primes.length;i++) {
			long plus = countWithCache(n/primes[i], primes) - (i+1);
			if(plus <= 0)break;
			ans += plus;
		}

		for(int p : primes) {
			if((long)p*p*p <= n) {
				ans++;
			}else {
				break;
			}
		}
		out.println(ans);
	}

	public static long countWithCache(long x, int[] primes)
	{
		if(x < primes[primes.length-1]) {
			int ind = Arrays.binarySearch(primes, (int)x);
			return ind < 0 ? -ind-1 : ind+1;
		}else {
			return count(x);
		}
	}

	public static long count(long x)
	{
		int c = (int)Math.pow(x, 2./3);
		int[] primes = sieveEratosthenes(c);
		return count(x, primes);
	}

	// primes = Sieve.sieveEratosthenes(x^(2/3))
	public static long count(long x, int[] primes)
	{
		int ind = Arrays.binarySearch(primes, (int)Math.cbrt(x));
		if(ind < 0)ind = -ind-2;
		int a = ind+1;
		return a - p2xa(x, primes) + phi(x, a, primes) - 1;
	}

	private static long phi(long x, int a, int[] primes)
	{
		return S1(x) + S2(x, a, primes);
	}

	private static long S1(long x)
	{
		int c = (int)Math.cbrt(x);
		int[] lpf = enumLowestPrimeFactors(c);
		int[] mobius = enumMobiusByLPF(c, lpf);
		long ret = 0;
		for(int i = 1;i <= c;i++){
			ret += mobius[i] * (x/i);
		}
		return ret;
	}

	static long exret = 0;

	private static long S2(long x, int a, int[] primes)
	{
		final int C = (int)Math.cbrt(x);
		final int N = (int)Math.cbrt(x)*3/2;
		List<Pair> pairs = new ArrayList<>();
		exret = 0;
		dfs(a-1, 1, 1L, C, x, primes, pairs);
		Collections.sort(pairs, new Comparator<Pair>(){
			public int compare(Pair x, Pair y){
				if(x.xdn / N != y.xdn / N)return Long.compare(x.xdn, y.xdn);
				return x.b - y.b;
			}
		});

		// sieveBySegment
		final int NUM_MASK_PRIMES = 15;
		long[] mask = new long[NUM_MASK_PRIMES];
		for(int i = 0;i < NUM_MASK_PRIMES && i < primes.length;i++){
			for(int k = 0;k < 64;k += primes[i]){
				mask[i] |= 1L<<k;
			}
		}

		long[] phis = new long[a];
		int p = 0;
		long ret = 0;
		int m = (N>>>6)+1;
		long[] stand = new long[m];
		ret += exret;

		out:
		for(long k = 0;;k++){
			Arrays.fill(stand, -1L);
			stand[N>>>6] = (N&63) > 0 ? stand[N>>>6]<<-N>>>-N : 0; // erasing [N,
			int numstand = N;
			if(k == 0){ // not include 0
				numstand--;
				stand[0] ^= 1L<<0;
			}
			for(int b = 0;b < a;b++){
				while(p < pairs.size() && pairs.get(p).xdn < (k+1)*N && pairs.get(p).b == b){
//					U.tr("hit", p, phis[b], k, pairs.get(p).xdn - (long)k*N, (phis[b] + FenwickTree.sumFenwick(ft, (int)(pairs.get(p).xdn - (long)k*N))));
					int to = (int)(pairs.get(p).xdn - k*N);
					int lret = 0;
					for(int i = 0, j = 0;i <= to;i += 64, j++){ // [0,to]
						if(i+63 <= to){
							lret += Long.bitCount(stand[j]);
						}else{
							lret += Long.bitCount(stand[j]<<~to);
						}
					}
					ret += pairs.get(p).co * (phis[b] + lret);
//					U.tr(pairs.get(p), ret);
					p++;
				}
				if(p == pairs.size())break out;
				phis[b] += numstand;
				if(b < NUM_MASK_PRIMES){
					int r = primes[b];
					int delta = 64%r;
					for(int q = 0, o = (int)(r-1-(k*N+r-1)%r);q < m;q++, o -= delta){
						if(o < 0)o += r;
						numstand -= Long.bitCount(stand[q] & mask[b]<<o);
						stand[q] &= ~(mask[b]<<o);
					}
				}else{
					int r = primes[b];
					for(int q = (int)(r-1-(k*N+r-1)%r);q < N;q+=r){
						if(stand[q>>>6]<<~q<0){
							stand[q>>>6]^=1L<<q;
							numstand--;
						}
					}
				}
			}
//			U.tr(m, k, a);
		}

		return ret;
	}

	private static class Pair
	{
		int co;
		long xdn;
		int b;
		public Pair(int co, long xdn, int b) {
			this.co = co;
			this.xdn = xdn;
			this.b = b;
		}
		@Override
		public String toString() {
			return "Pair [co=" + co + ", xdn=" + xdn + ", b=" + b + "]";
		}
	}

	private static void dfs(int pos, int co, long mul, int c, long x, int[] primes, List<Pair> pairs)
	{
		for(int i = pos;i >= 0;i--){
			long nmul = mul * primes[i];
			if(nmul > c && c >= mul){
				// b+1 = i
				if(i == 0){
					exret += -co*(x/nmul);
				}else{
					pairs.add(new Pair(-co, x/nmul, i));
				}
			}else if(nmul <= c){
				dfs(i-1, -co, nmul, c, x, primes, pairs);
			}
		}
	}

	// TODO segmentSieveによりメモリO(x^(1/3))にする
	private static long p2xa(long x, int[] primes)
	{
		int a = (int)Math.cbrt(x);
		int b = (int)Math.sqrt(x);
		long ret = 0;

		int posa = Arrays.binarySearch(primes, a);
		if(posa < 0)posa = -posa - 2;
		ret += (long)posa*(posa+1)/2;

		int posb = Arrays.binarySearch(primes, b);
		if(posb < 0)posb = -posb - 2;
		ret -= (long)posb*(posb+1)/2;

		for(int i = posa+1;i <= posb;i++){
			int posp = Arrays.binarySearch(primes, (int)(x/primes[i]));
			if(posp < 0)posp = -posp - 2;
			ret += posp + 1;
		}
		return ret;
	}

	private static int[] enumLowestPrimeFactors(int n)
	{
		int tot = 0;
		int[] lpf = new int[n+1];
		int u = n+32;
		double lu = Math.log(u);
		int[] primes = new int[(int)(u/lu+u/lu/lu*1.5)];
		for(int i = 2;i <= n;i++)lpf[i] = i;
		for(int p = 2;p <= n;p++){
			if(lpf[p] == p)primes[tot++] = p;
			int tmp;
			for(int i = 0;i < tot && primes[i] <= lpf[p] && (tmp = primes[i]*p) <= n;i++){
				lpf[tmp] = primes[i];
			}
		}
		return lpf;
	}

	private static int[] enumMobiusByLPF(int n, int[] lpf)
	{
		int[] mob = new int[n+1];
		mob[1] = 1;
		for(int i = 2;i <= n;i++){
			int j = i/lpf[i];
			if(lpf[j] == lpf[i]){
//				mob[i] = 0;
			}else{
				mob[i] = -mob[j];
			}
		}
		return mob;
	}

	public static int[] sieveEratosthenes(int n) {
		if (n <= 32) {
			int[] primes = { 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31 };
			for (int i = 0; i < primes.length; i++) {
				if (n < primes[i]) {
					return Arrays.copyOf(primes, i);
				}
			}
			return primes;
		}

		int u = n + 32;
		double lu = Math.log(u);
		int[] ret = new int[(int) (u / lu + u / lu / lu * 1.5)];
		ret[0] = 2;
		int pos = 1;

		int[] isnp = new int[(n + 1) / 32 / 2 + 1];
		int sup = (n + 1) / 32 / 2 + 1;

		int[] tprimes = { 3, 5, 7, 11, 13, 17, 19, 23, 29, 31 };
		for (int tp : tprimes) {
			ret[pos++] = tp;
			int[] ptn = new int[tp];
			for (int i = (tp - 3) / 2; i < tp << 5; i += tp)
				ptn[i >> 5] |= 1 << (i & 31);
			for (int j = 0; j < sup; j += tp) {
				for (int i = 0; i < tp && i + j < sup; i++) {
					isnp[j + i] |= ptn[i];
				}
			}
		}

		// 3,5,7
		// 2x+3=n
		int[] magic = { 0, 1, 23, 2, 29, 24, 19, 3, 30, 27, 25, 11, 20, 8, 4, 13, 31, 22, 28, 18, 26, 10, 7, 12, 21, 17,
				9, 6, 16, 5, 15, 14 };
		int h = n / 2;
		for (int i = 0; i < sup; i++) {
			for (int j = ~isnp[i]; j != 0; j &= j - 1) {
				int pp = i << 5 | magic[(j & -j) * 0x076be629 >>> 27];
				int p = 2 * pp + 3;
				if (p > n)
					break;
				ret[pos++] = p;
				if ((long) p * p > n)
					continue;
				for (int q = (p * p - 3) / 2; q <= h; q += p)
					isnp[q >> 5] |= 1 << q;
			}
		}

		return Arrays.copyOf(ret, pos);
	}

	void run() throws Exception
	{
		is = oj ? System.in : new ByteArrayInputStream(INPUT.getBytes());
		out = new PrintWriter(System.out);

		long s = System.currentTimeMillis();
		solve();
		out.flush();
		tr(System.currentTimeMillis()-s+"ms");
	}

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

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

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

	private boolean isSpaceChar(int c) { return !(c >= 33 && c <= 126); }
	private int skip() { int b; while((b = readByte()) != -1 && isSpaceChar(b)); return b; }

	private double nd() { return Double.parseDouble(ns()); }
	private char nc() { return (char)skip(); }

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

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

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

	private int[] na(int n)
	{
		int[] a = new int[n];
		for(int i = 0;i < n;i++)a[i] = ni();
		return a;
	}

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

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

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

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

	private boolean oj = System.getProperty("ONLINE_JUDGE") != null;
	private void tr(Object... o) { if(!oj)System.out.println(Arrays.deepToString(o)); }
}


import java.util.Scanner;

public class Pixel {
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        long i,j,k,n,a,b,c,big,middle,small,sum;
        boolean is;
        while (input.hasNext()){
            a = input.nextLong(); b = input.nextLong(); c = input.nextLong(); sum = 0; is = false;

            big = (a>=b) ? ((a>=c)? a :c) : ((b>=c) ? b : c);
            small = (a>=b) ? ((b>=c) ? c : b) : ((a>=c) ? c : a);
            middle = a>b ? (c>a ? a :(b>c)? b:c) : (c>b ? b : a>c? a : c);

           // System.out.println(big+ " " + middle + " " + small);
            for (i=0; i<big; i++){
                if (big == middle || big == small || middle == small) break;
                if ((middle - small ) % 2 == 0){
                   // big--;middle--;small++;
                    j = (middle - small);
                   // sum += (j/2);
                    sum += (small + j);
                    is = true;
                    break;
                }
                else break;
            }
            if (!is) {
                if (big == middle) sum += big;
                else if (big == small) sum += big;
                else if (small == middle) sum += small;
                else sum += big; System.out.println(sum);
            }
            else
            System.out.println(sum);
        }
    }
}


import java.awt.Rectangle;
import java.io.*;
import java.util.*;

public class Main {

	public static void main(String[] args) throws Exception {
		FastScanner kb = new FastScanner(System.in);
		PrintWriter out = new PrintWriter(System.out);
		//int n = kb.nextInt();
		//
		int x = kb.nextInt();
		int y = kb.nextInt();
		int z = kb.nextInt();
		int x1 = kb.nextInt();
		int y1 = kb.nextInt();
		int z1 = kb.nextInt();
		int a[] = new int[6];
		for(int i=0;i<6;i++)
			a[i]=kb.nextInt();
		if(x>x1&&y>y1&&z>z1)out.println(a[1]+a[3]+a[5]);
		else if(x<0&&y<0&&z<0)out.println(a[0]+a[2]+a[4]);
		else if((x>=0&&x<=x1)){
			if((y>=0&&y<=y1)){
				if(z<0){
					out.println(a[2]);
				}else if(z>z1){
					out.println(a[3]);
				}
			}else if((z>=0&&z<=z1)){
				if(y<0){
					out.println(a[0]);
				}else if(y>y1){
					out.println(a[1]);
				}
			}
		}
		else if((y>=0&&y<=y1)){
			if((x>=0&&x<=x1)){
				if(z<0){
					out.println(a[2]);
				}else if(z>z1){
					out.println(a[3]);
				}
			}else if((z>=0&&z<=z1)){
				if(x<0){
					out.println(a[4]);
				}else if(x>x1){
					out.println(a[5]);
				}
			}
		}
		else if((z>=0&&z<=z1)){
			if((x>=0&&x<=x1)){
				if(y<0){
					out.println(a[0]);
				}else if(y>y1){
					out.println(a[1]);
				}
			}else if((y>=0&&y<=y1)){
				if(x<0){
					out.println(a[4]);
				}else if(x>x1){
					out.println(a[5]);
				}
			}
		}

		out.close();
	}
}

class FastScanner {
	final private int BUFFER_SIZE = 1 << 19;
	private DataInputStream din;
	private byte[] buffer;
	private int bufferPointer, bytesRead;

	public FastScanner(InputStream in) {
		din = new DataInputStream(in);
		buffer = new byte[BUFFER_SIZE];
		bufferPointer = bytesRead = 0;
	}

	public String nextString() throws Exception {
		StringBuffer sb = new StringBuffer("");
		byte c = read();
		while (c <= ' ')
			c = read();
		do {
			sb.append((char) c);
			c = read();
		} while (c > ' ');
		return sb.toString();
	}

	public char nextChar() throws Exception {
		byte c = read();
		while (c <= ' ')
			c = read();
		return (char) c;
	}

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

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

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

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


import java.util.Scanner;

public class abc {
	static long reflectNum(long number){
		if(number==1000000000)
			return 8999999999L;
		if(number<100000)
		{
			if(number<100)
			{
				if(number<10)
					return (9-number);
				else
					return (99-number);
			}
			else
			{
				if(number<10000)
				{
					if(number<1000)
						return (999-number);
					else
						return (9999-number);
				}
				else
					return (99999-number);
			}
		}
		else
		{
			if(number<10000000)
			{
				if(number<1000000)
					return (999999-number);
				else
					return (9999999-number);
			}
			else
			{
				if(number<100000000)
					return (99999999-number);
				else
					return (999999999-number);
			}
		}
	}
	static short digitNum(long number){
		if(number<100000)
		{
			if(number<100)
			{
				if(number<10)
					return 1;
				else
					return 2;
			}
			else
			{
				if(number<10000)
				{
					if(number<1000)
						return 3;
					else
						return 4;
				}
				else
					return 5;
			}
		}
		else
		{
			if(number<10000000)
			{
				if(number<1000000)
					return 6;
				else
					return 7;
			}
			else
			{
				if(number<100000000)
					return 8;
				else
					return 9;
			}
		}
	}

	public static void main(String[] args)
	{
		Scanner read = new Scanner(System.in);
		long l,r, max=-1;
		long lower=1;
		l = read.nextInt();
		r = read.nextInt();
		if(r==0)
			max=0;
		else if(l==1000000000 || r==1000000000)
			max = 8999999999000000000L;
		else
		{
			lower *= Math.pow(10, digitNum(r)-1);
			if(lower<l)
				lower = l;
			for ( ; lower<=r ; lower++)
			{
				if(max<lower*reflectNum(lower))
					max = lower*reflectNum(lower);
			}
		}
		System.out.println(max);
	}
}


import java.util.LinkedList;
import java.util.List;
import java.util.Scanner;

public class DataRecovery {

    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        int m = scan.nextInt();
        int min = scan.nextInt();
        int max = scan.nextInt();
        List<Integer> list = new LinkedList<Integer>();
        int temperatures = 0;
        for (int i = 0; i < m; ++i) {
            temperatures = scan.nextInt();
            list.add(temperatures);
        }
        int flag = 0;
        for (int i = 0; i < list.size(); ++i) {

            if (list.get(i) == min) {
                flag++;
            }
            if (list.get(i) == max) {
                flag++;
            }
        }
        if (m <= n - 2) {
            System.out.println("Correct");
        }
        if (m == n - 1) {
            if (flag == 1 || flag == 2) {
                System.out.println("Correct");
            } else if (flag == 0) {
                System.out.println("Incorrect");
            }
        }
    }
}


import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int length = in.nextInt();
		int[] proc = new int[length];
		int[] copy = new int[length];
		for (int i = 0; i < length; i++){
			proc[i] = in.nextInt();
		    copy[i] = proc[i];
		}

		proc = sort(proc, length);

        System.out.println(srav(proc,copy, length));

	}

	private static int[] sort(int[] proc, int length){

		for (int i = length - 1; i >= 0; i--){
			if (proc[i] == 0){
			   for(int j = i; j < length - 1; j++){
				proc[j] = proc[j+1];
			    proc[j + 1] = 0;
			   }
			}
		}

		return proc;
	}

	private static int srav(int[] proc, int[] copy, int length){
		int count = 0;
		for(int i = 0; i < length; i++){
			if ((copy[i] != 0) && (copy[i] != proc[i]) ){
				count++;
			}
		}
		return count;
	}

}


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

public class Main {
    public static long MOD = 1000000007;

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

        final ArrayList<Integer> values = new ArrayList<>(n);
        for (int i = 0; i < n; i++) {
            values.add(scanner.nextInt());
        }

        int zeroCount = values.stream().filter(integer -> integer.equals(0)).mapToInt(i -> 1).sum();
        final long[][] table = new long[k + 1][n];

        int initZeroCount = values.subList(0, zeroCount).stream().filter(integer -> integer.equals(0)).mapToInt(i -> 1).sum();
        table[0][initZeroCount] = 1L;

        for (int i = 1; i < k + 1; i++) {
            for (int j = 0; j < n; j++) {
                final int zeroInPrefix = j;
                final int zeroOutPrefix = getZeroOutPrefix(zeroCount, zeroInPrefix);
                final int oneInPrefix = getOneInPrefix(zeroCount, zeroInPrefix);
                final int oneOutPrefix = getOneOutPrefix(n, zeroCount, zeroInPrefix);

                final long sameZero = table[i - 1][j]
                        * (zeroInPrefix * zeroOutPrefix
                        + zeroInPrefix * oneInPrefix
                        + zeroOutPrefix * oneOutPrefix
                        + oneInPrefix * oneOutPrefix
                        + countPair(oneInPrefix)
                        + countPair(zeroInPrefix)
                        + countPair(oneOutPrefix)
                        + countPair(zeroOutPrefix));
                final long plusZero = (j == 0 ? 0 : table[i - 1][j - 1]) *
                        (getOneInPrefix(zeroCount, zeroInPrefix - 1) * getZeroOutPrefix(zeroCount, zeroInPrefix - 1));
                final long minusZero = (j == n - 1 ? 0 : table[i - 1][j + 1]) *
                        ((zeroInPrefix + 1) * getOneOutPrefix(n, zeroCount, zeroInPrefix + 1));

                table[i][j] = sameZero + plusZero + minusZero;
            }
        }
        final long count = table[k][zeroCount];
        final long sum = Arrays.stream(table[k]).reduce((left, right) -> (left + right) % MOD).orElse(0);

        System.out.println((binPow(sum, MOD - 2) * count) % MOD);
    }

    private static int getOneInPrefix(int zeroCount, int zeroInPrefix) {
        return zeroCount - zeroInPrefix;
    }

    private static int getOneOutPrefix(int allCount, int zeroCount, int zeroInPrefix) {
        return allCount - zeroCount - getOneInPrefix(zeroCount, zeroInPrefix);
    }

    private static int getZeroOutPrefix(int zeroCount, int zeroInPrefix) {
        return zeroCount - zeroInPrefix;
    }

    private static long countPair(int count) {
        return (count * (count - 1)) / 2;
    }

    private static long binPow(long n, long count) {
        if (count == 0) {
            return 1L;
        }

        long temp = binPow(n, count / 2);
        temp = (temp * temp) % MOD;
        if (count % 2 != 0) {
            temp = (temp * n) % MOD;
        }

        return temp % MOD;
    }
}


// package codeforces.cf3xx.cf399;

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

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

        int f = in.nextInt();
        int w = in.nextInt();
        int h = in.nextInt();

        prec(300000);

        long ptn = 0;
        for (int pile = 1 ; pile <= f+1 ; pile++) {
            int leftW = w - (h + 1) * pile;
            if (leftW < 0) {
                break;
            }
            ptn += comb(f+1, pile) * comb(leftW+pile-1, pile-1) % MOD;
            ptn %= MOD;
        }
        long all = comb(f+w, f) % MOD;
        if (w == 0) {
            ptn = 1;
        }
        out.println(ptn * inv(all) % MOD);
        out.flush();
    }

    static final int MOD = 1000000007;

    static long pow(long a, long x) {
        long res = 1;
        while (x > 0) {
            if (x%2 != 0) {
                res = (res*a)%MOD;
            }
            a = (a*a)%MOD;
            x /= 2;
        }
        return res;
    }

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

    static long[] _fact;
    static long[] _invfact;

    static long comb(long ln, long lr) {
        int n = (int) ln;
        int r = (int) lr;
        if (n < 0 || r < 0 || r > n) {
            return 0;
        }
        if (r > n/2) {
            r = n-r;
        }
        return (((_fact[n]*_invfact[n-r])%MOD)*_invfact[r])%MOD;
    }

    static void prec(int n) {
        _fact = new long[n+1];
        _invfact = new long[n+1];
        _fact[0] = 1;
        _invfact[0] = 1;
        for (int i = 1; i <= n; i++) {
            _fact[i] = _fact[i-1]*i%MOD;
            _invfact[i] = inv(_fact[i]);
        }
    }

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

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

        private int[] nextInts(int n) {
            int[] ret = new int[n];
            for (int i = 0; i < n; i++) {
                ret[i] = nextInt();
            }
            return ret;
        }

        private int[][] nextIntTable(int n, int m) {
            int[][] ret = new int[n][m];
            for (int i = 0; i < n; i++) {
                for (int j = 0; j < m; j++) {
                    ret[i][j] = nextInt();
                }
            }
            return ret;
        }

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

        private long[][] nextLongTable(int n, int m) {
            long[][] ret = new long[n][m];
            for (int i = 0; i < n; i++) {
                for (int j = 0; j < m; j++) {
                    ret[i][j] = nextLong();
                }
            }
            return ret;
        }

        private double[] nextDoubles(int n) {
            double[] ret = new double[n];
            for (int i = 0; i < n; i++) {
                ret[i] = nextDouble();
            }
            return ret;
        }

        private int next() {
            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 char nextChar() {
            int c = next();
            while (isSpaceChar(c))
                c = next();
            if ('a' <= c && c <= 'z') {
                return (char) c;
            }
            if ('A' <= c && c <= 'Z') {
                return (char) c;
            }
            throw new InputMismatchException();
        }

        public String nextToken() {
            int c = next();
            while (isSpaceChar(c))
                c = next();
            StringBuilder res = new StringBuilder();
            do {
                res.append((char) c);
                c = next();
            } while (!isSpaceChar(c));
            return res.toString();
        }

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

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

        public double nextDouble() {
            return Double.valueOf(nextToken());
        }

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

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

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


/*
USER: caoash3
LANG: JAVA
TASK:
*/

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

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

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		PrintWriter pw = new PrintWriter(new OutputStreamWriter(System.out));

		//BufferedReader br = new BufferedReader(new FileReader("X.in"));
		//PrintWriter pw = new PrintWriter(new FileWriter("X.out"));

		X solver = new X();
		solver.solve(br, pw);
	}

	static class X {
		public void solve(BufferedReader br, PrintWriter pw) throws IOException {
			StringTokenizer st = new StringTokenizer(br.readLine());

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

			int[] inp = new int[n];

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

			int s = 0;
			int s2 = 0;
			for(int i = 0; i < inp.length; i++) {
				inp[i] = Integer.parseInt(st.nextToken());
				if(inp[i] == -1) {
					s ++;
					}
					else {
						s2 += inp[i];
					}
				sum ++;

			}

			int max = 0;

			for(int i = 0; i < m; i++) {
				int s3 = s;
				int s4 = s2;
				for(int j = i; j <n; j+=m) {
					if(inp[j] == -1) {
					s3 --;
					}
					else {
						s4 --;
					}
				}
				max = Math.max(max, Math.abs(s3-s4));
			}

			pw.println(max);
			pw.close();
		}
	}
}


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

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

    static class GTakeMetro {
        int step(int n, long t, int s, int m) {
            int curJump = (int) (t % n);
            int sign = s < m ? 1 : -1;
            s += sign * curJump;
            s %= n;
            if (s < 0) s += n;
            return s;
        }

        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.NextInt();
            int m = in.NextInt();
            int s = in.NextInt() - 1;
            long t = in.NextLong();
            while (t % n != 0) {
                s = step(n, t--, s, m);
            }
            for (int j = 0; j < 10; j++) {
                if (t != 0) {
                    for (int i = 0; i < n; i++) {
                        s = step(n, t--, s, m);
                    }
                }
            }
            if (t != 0) {
                int side1 = s < m ? 0 : 1;
                for (int i = 0; i < n; i++) {
                    s = step(n, t--, s, m);
                }
                if (t != 0) {
                    int side2 = s < m ? 0 : 1;
                    if (side1 != side2) {
                        t /= n;
                        if ((t % 2) != 0) {
                            for (int i = 0; i < n; i++) {
                                s = step(n, t--, s, m);
                            }
                        }
                    }
                }
            }
            out.println(s + 1);
        }

    }

    static class InputReader {
        BufferedReader reader;
        StringTokenizer tokenizer;

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

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

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

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

    }
}


import static java.lang.Double.parseDouble;
import static java.lang.Integer.parseInt;
import static java.lang.Long.parseLong;
import static java.lang.System.exit;

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

public class F {

	static BufferedReader in;
	static PrintWriter out;
	static StringTokenizer tok;

	static void solve() throws Exception {
		int n = nextInt();
		int d = nextInt();
		int mod = nextInt();
		if (n == 1) {
			out.print('1');
			return;
		}
		int fracs[] = new int[d + 2];
		for (int i = 1; i < fracs.length; i++) {
			fracs[i] = BigInteger.valueOf(i).modInverse(BigInteger.valueOf(mod)).intValue();
		}
		int maxsize = n;
		int cnts[] = new int[maxsize + 1];
		cnts[1] = 1;
		int cnts2[][][] = new int[maxsize + 1][d + 1][maxsize + 1];
		cnts2[0][0][1] = 1;
		for (int lastsize = 0; lastsize < (n - 1) / 2; lastsize++) {
			int nlastsize = lastsize + 1;
			int ccnt = cnts[nlastsize];
			int ccnt2[][] = cnts2[lastsize];
			int ncnt2[][] = cnts2[nlastsize];
			for (int ctrees = 0; ctrees <= d; ctrees++) {
				for (int csize = 1; csize <= maxsize; csize++) {
					int cur = ccnt2[ctrees][csize];
//					if (cur != 0) {
//						System.err.println(csize + " " + ctrees + " " + lastsize + " -> " + cur);
//					}
					for (int i = 0, ntrees = ctrees, nsize = csize;
						ntrees <= d && nsize <= maxsize;
						++i, ++ntrees, nsize += nlastsize) {
						ncnt2[ntrees][nsize] += cur;
						if (ncnt2[ntrees][nsize] >= mod) {
							ncnt2[ntrees][nsize] -= mod;
						}
						cur = (int) ((long) cur * (ccnt + i) % mod * fracs[i + 1] % mod);
					}
				}
			}
			if (nlastsize + 1 <= maxsize) {
				cnts[nlastsize + 1] = ncnt2[d - 1][nlastsize + 1];
			}
		}
		int ans = 0;
		if (n % 2 == 0) {
			ans = (int) ((long) cnts[n / 2] * (cnts[n / 2] + 1) % mod * fracs[2] % mod);
		}
		ans = (ans + cnts2[(n - 1) / 2][d][n]) % mod;
		out.print(ans);
	}

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

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

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

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

	public static void main(String[] args) {
		try {
			in = new BufferedReader(new InputStreamReader(System.in));
			out = new PrintWriter(new OutputStreamWriter(System.out));
			solve();
			in.close();
			out.close();
		} catch (Throwable e) {
			e.printStackTrace();
			exit(1);
		}
	}
}


import java.math.BigDecimal;
import java.math.BigInteger;
import java.math.RoundingMode;
import java.text.DecimalFormat;
import java.util.Scanner;
import java.math.MathContext;

public class Main {
    public static void main(String[] args) {
        MathContext mc = new MathContext(10000, RoundingMode.HALF_DOWN);
        Scanner cin = new Scanner(System.in);
        BigInteger n,k,M,D;
        int dd;
        n=cin.nextBigInteger();
        k=cin.nextBigInteger();
        M=cin.nextBigInteger();
        D=cin.nextBigInteger();
        dd=D.intValue();
        BigInteger ans=BigInteger.ZERO;
        for(int i=0;i<=dd;i++){
            BigInteger once=n.divide(k.multiply(new BigInteger(i+"").add(BigInteger.ONE));
            if(once.compareTo(M)>0)
                once=M;
            if(n.subtract(k.multiply(new BigInteger(i+"")).multiply(once)).compareTo(once)>=0&&i==dd)
                continue;
            BigInteger temp=once.multiply(new BigInteger(i+"")).add(once);
            if(temp.compareTo(ans)>0){
                ans=temp;
            }
        }
        System.out.println(ans);
    }
}


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

public class Main {
    public static BufferedReader bf;
    public static long MOD = 998244353;

    public static void main(String[] args) throws IOException {
        bf = new BufferedReader(new InputStreamReader(System.in));
        int T = Integer.parseInt(bf.readLine().trim());
        PrintWriter out = new PrintWriter(System.out);
        while (T-- > 0) {
            String[] ip = bf.readLine().split(" ");
            int N = Integer.parseInt(ip[0]);

            long nthFibo = getNthFibo(N);
            long denominator = binaryExpo(2, N);
            long modInverse = inverseMod(denominator);

            long ans = (modInverse % MOD * nthFibo % MOD) % MOD;
            out.println(ans);

        }

        out.flush();

    }

    private static long inverseMod(long denominator) {
        return binaryExpo(denominator, MOD - 2);
    }

    private static long binaryExpo(long base, long pow) {

        long res = 1;
        while (pow >= 1) {
            if (pow % 2 != 0) {
                pow--;
                res = (res % MOD * base % MOD) % MOD;
            }
            pow = pow / 2;
            base = (base % MOD * base % MOD) % MOD;
        }

        return res;

    }

    private static long getNthFibo(int n) {
        long[][] matrix = new long[][]{
                {0, 1},
                {1, 1}
        };
        long[] baseCases = new long[]{1, 1};
        matrixExpoUnderMod(matrix, n - 1);
        long ans = ((baseCases[0] % MOD * matrix[0][0] % MOD) % MOD + (baseCases[1] % MOD * matrix[0][1] % MOD) % MOD) % MOD;

        return ans;
    }

    private static void matrixExpoUnderMod(long[][] matrix, int pow) {
        long[][] res = new long[2][2];
        for (int i = 0; i < 2; i++) {
            for (int j = 0; j < 2; j++) {
                if (i == j) res[i][j] = 1;
            }
        }
        while (pow >= 1) {
            if (pow % 2 != 0) {
                matrixMultiply(res, matrix);
                pow--;
            }
            pow = pow / 2;
            matrixMultiply(matrix, matrix);
        }

        for (int i = 0; i < 2; i++) {
            for (int j = 0; j < 2; j++) {
                matrix[i][j] = res[i][j];
            }
        }
    }

    public static void matrixMultiply(long[][] A, long[][] B) {
        long[][] res = new long[2][2];

        for (int i = 0; i < 2; i++) {
            for (int j = 0; j < 2; j++) {
                long sum = 0;
                for (int k = 0; k < 2; k++) {
                    sum += (A[i][k] % MOD * B[k][j] % MOD) % MOD;
                }
                res[i][j] = sum;
            }
        }
        for (int i = 0; i < 2; i++) {
            for (int j = 0; j < 2; j++) {
                A[i][j] = res[i][j];
            }
        }

    }

    private static long[] readIntArray(int startIndex) throws IOException {
        String[] ip = bf.readLine().split(" ");
        int j = -1;
        int len = ip.length;
        if (startIndex == 1) {
            len += 1;
            j = 0;
        }

        long[] arr = new long[len];

        for (String str : ip)
            arr[++j] = Long.parseLong(str);

        return arr;

    }

}


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

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

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

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

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

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


/*
allowed +0, +2, +3
*/
import java.util.*;

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

		Map<String, Integer> map = new HashMap<String, Integer>();
		map.put("monday", 0);
		map.put("tuesday", 1);
		map.put("wednesday", 2);
		map.put("thursday", 3);
		map.put("friday", 4);
		map.put("saturday", 5);
		map.put("sunday", 6);

		int one = map.get(s.next()), two = map.get(s.next()); if(one > two) two += 7;
		int diff = two - one;
		if(diff == 0 || diff == 2 || diff == 3) System.out.println("YES");
		else System.out.println("NO");å
	}
}


import java.io.DataInputStream;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;

/**
 * Built using CHelper plug-in Actual solution is at the top
 *
 * @author da_201612051
 */
public class Main {

  public static void main(String[] args) {
    InputStream inputStream = System.in;
    OutputStream outputStream = System.out;
    FastIO in = new FastIO(inputStream);
    PrintWriter out = new PrintWriter(outputStream);
    TaskA1 solver = new TaskA1();
    solver.solve(1, in, out);
    out.close();
  }

  static class TaskA1 {

    public void solve(int testNumber, FastIO in, PrintWriter out) throws IOException {
      int n = in.nextInt();
      int k = in.nextInt();
      int[] query = in.nextIntArray(n);
      int cost = 0;
      Set<Integer> avaialbleBooks = new HashSet<>(k);
      int[] access = new int[81];
      Arrays.stream(query).forEach(book -> access[book]++);
      for (int i = 0; i < n; i++) {
        if (!avaialbleBooks.contains(query[i])) {
          cost++;
        }
        if (avaialbleBooks.size() < k && --access[query[i]] > 0) {
          avaialbleBooks.add(query[i]);
        } else if (access[query[i]] == 0) {
          avaialbleBooks.remove(query[i]);
        }
      }
      System.out.println(cost);
    }

  }

  static class FastIO {

    final private int BUFFER_SIZE = 1 << 16;
    private InputStream din;
    private byte[] buffer;
    private int bufferPointer;
    private int bytesRead;

    public FastIO() {
      buffer = new byte[BUFFER_SIZE];
      bufferPointer = bytesRead = 0;
    }

    public FastIO(InputStream inputStream) {
      this();
      din = new DataInputStream(inputStream);
    }

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

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

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

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

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

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

  }
}


import java.lang.*;
import java.util.*;

public class deathStar{
    public static void main(String[] args){
        Scanner sc=new Scanner(System.in);
        int n=sc.nextInt();
        char[][] arr1=new char[n][n];
        char[][] arr2=new char[n][n];
        for(int i=0; i<n; i++){
            for(int j=0; j<n; j++){
                arr1[i][j]=sc.next().charAt(0);
            }
        }

        for(int i=0; i<n; i++){
            for(int j=0; j<n; j++){
                arr2[i][j]=sc.next().charAt(0);
            }
        }

        deathStar ds=new deathStar();

        boolean result=ds.isEqual(arr1,arr2,n);
        if(!result){
            int res=ds.check(arr1,arr2,n);
            if(res!=0){
                ds.flipV(arr1,n);
                result=ds.isEqual(arr1,arr2,n);
                if(!result) res=ds.check(arr1,arr2,n);
                else{
                    System.out.println("YES");
                    return;
                }
            }
            if(res!=0){
                ds.flipV(arr1,n);
                ds.flipH(arr1,n);
                result=ds.isEqual(arr1,arr2,n);
                if(!result) res=ds.check(arr1,arr2,n);
                else{
                    System.out.println("YES");
                    return;
                }
            }
            if(res!=0) System.out.println("NO");
        }
        else System.out.println("YES");
    }

    public void flipV(char[][] arr1,int n){
        for(char[] arr:arr1){
            int i=0;
            int j=n-1;
            while(i<j){
                char temp=arr[i];
                arr[i]=arr[j];
                arr[j]=temp;
                i++;
                j--;
            }
        }

    }
    public void flipH(char[][] arr1,int n){
        for(int j=0; j<n; j++){
            for(int i=0; i<n; i++){
                int temp=arr1[i][j];
                arr1[i][j]=arr1[n-1-i][j];
                arr1[n-1-i][j]=temp;
            }
        }
    }

    public void printArr(char[][] arr, int n){
        for(char[] pointer:arr){
            System.out.println();
            for(int i=0; i<n; i++){
                if(pointer[i]==' ' || pointer[i]=='\n') System.out.print('a'+" ");
                else System.out.print(pointer[i]+" ");
            }
        }
    }

    public int check(char[][] arr1,char[][] arr2, int n){
        int i=0;
        while(i<1){
            rotate(arr1,n);
            if(isEqual(arr1,arr2,n)){
                System.out.println("YES");
                return 0;
            }
            i++;
        }
        rotate(arr1,n);
        return -1;
    }

    public boolean isEqual(char[][] arr1,char[][] arr2, int n){
        for(int i=0; i<n; i++){
            for(int j=0; j<n; j++){
                if(arr1[i][j]!=arr2[i][j]){
                    return false;
                }
            }
        }
        return true;
    }

    public void rotate(char[][] arr, int n){
        for(int layer=0; layer<n/2; layer++){
            int first=layer;
            int last=n-1-layer;
            int offset=0;
            for(int j=first; j<last; j++){
                char top=arr[first][j];
                arr[first][j]=arr[last-offset][first];
                arr[last-offset][first]=arr[last][last-offset];
                arr[last][last-offset]=arr[j][last];
                arr[j][last]=top;
                offset++;
            }
        }
    }
}


import java.io.*;
import static java.lang.System.*;
public class B {
    BufferedReader br = new BufferedReader(new InputStreamReader(in));
    public static void main(String []arg) throws Exception {
        int tc=ni(br.readLine());
        while(tc-->0) {
            String s[]=br.readLine().split(" ");
            int n=ni(s[0]),k=ni(s[1]);
            long res=1,mod=(long)1e9+7;
            for(int i=0;i<k;i++) res = (res*n)%mod;
            out.println(res);
        }
    }
    static int ni(String s) {
        return Integer.valueOf(s);
    }
}


import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.util.HashMap;
import java.util.Arrays;
 public class Primes1{

    static class FastScanner{
        BufferedReader s;
        StringTokenizer st;

        public FastScanner(){
            st = new StringTokenizer("");
            s = new BufferedReader(new InputStreamReader(System.in));

        }

        public FastScanner(File f) throws FileNotFoundException{
            st = new StringTokenizer("");
            s = new BufferedReader (new FileReader(f));
        }

        public int nextInt() throws IOException{
            if(st.hasMoreTokens())
                return Integer.parseInt(st.nextToken());
            else{
                st = new StringTokenizer(s.readLine());
                return nextInt();
            }
        }

        public double nextDouble() throws IOException{
            if(st.hasMoreTokens())
                return Double.parseDouble(st.nextToken());
            else{
                st = new StringTokenizer(s.readLine());
                return nextDouble();
            }
        }

        public long nextLong() throws IOException{
            if(st.hasMoreTokens())
                return Long.parseLong(st.nextToken());
            else{
                st = new StringTokenizer(s.readLine());
                return nextLong();
            }
        }

        public String nextString() throws IOException{
            if(st.hasMoreTokens())
                return st.nextToken();
            else{
                st = new StringTokenizer(s.readLine());
                return nextString();
            }

        }

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

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

    }      //Fastscanner class end

   static FastScanner in=new FastScanner();
   static PrintWriter ww=new PrintWriter(new OutputStreamWriter(System.out));
   public static void main(String args[])throws IOException
   {
   //Main ob=new Main();
   Primes1 ob=new Primes1();
   ob.solve();
   ww.close();
   }

   public void solve()throws IOException
   {
     long n = in.nextInt();
	 int ans = n-n/2-n/3-n/5-n/7+n/6+n/10+n/14+n/15+n/21+n/35-n/30-n/42-n/70-n/105+n/210;
	 System.out.println(ans);
   }
 }


import java.util.Scanner;
public class A328 {
	public static void main (String args[]){
		Scanner in = new Scanner(System.in);
		long a[] = new long[4];
		boolean isar = false;
		boolean geo = false;
		for(int i = 0 ; i < 4 ;i++){
			a[i]=in.nextInt();
		}
		long tmp = 0 ;
		double tmp2 = 0 ;
		if((double)a[3]/(double)a[2]==(double)a[2]/(double)a[1] && (double)a[2]/(double)a[1]==(double)a[1]/(double)a[0]){
			geo = true;
			tmp2 = (double)a[3]/(double)a[2];
		}
		if(a[3]-a[2]==a[2]-a[1] && a[2]-a[1]==a[1]-a[0]){
			isar=true;
			tmp = a[2]-a[1];
		}
		if(isar){
			if(a[3]+tmp<Integer.MAX_VALUE)
			System.out.println(a[3]+tmp);
			else
			System.out.println(42);
		}
		else if(geo){
			if((int)(a[3]*tmp2) < Integer.MAX_VALUE)
				if((int)Math.ceil(a[3]*tmp2)==(int)a[3]*tmp2)
			System.out.println((int)(a[3]*tmp2));
				else
					System.out.println(42);
			else
				System.out.println(42);
		}else
			System.out.println(42);
	}
}


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

public class Solution {

    public static void main(String[] args) throws IOException {
        BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in));
        int n = Integer.parseInt(bufferedReader.readLine().trim());
        String[] items = bufferedReader.readLine().replaceAll("\\s+$", "").split(" ");
        long a = new Long.parseLong(items[0], 10);
        long b = new Long.parseLong(items[1], 10);
        long x = new Long.parseLong(items[2], 10);
        long y = new Long.parseLong(items[3], 10);

        long number = 0;

        for (long w = 1; w <= a; w++) {
            if ((w * y) % x == 0) {
                if ((w * y) / x <= b) number++;
                else break;
            }

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


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

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */

public class E {
  public static void main(String[] args) {
  InputStream inputStream = System.in;
  OutputStream outputStream = System.out;
  InputReader in = new InputReader(inputStream);
  PrintWriter out = new PrintWriter(outputStream);
  Task solver = new Task();
  solver.solve(1, in, out);
  out.close();
  }
}

class Task {
  public void solve(int testNumber, InputReader in, PrintWriter out) {
    String s = in.next();
    int m = in.nextInt(), n = s.length();
    long cur = 0, mul = 1;
    for (int i = 0; i < n; i++) {
      cur = (cur * 10 + s.charAt(i)-'0') % m;
      mul = (mul * 10) % m;
    }
    long ans = cur;
    for (int i = 0; i < n; i++) {
      if (s.charAt(i) != '0') {
        if (ans > cur) ans = cur;
      }
      cur = (cur * 10 + s.charAt(i)-'0') % m;
      cur = (cur - mul * (s.charAt(i)-'0')) % m;
      if (cur < 0) cur += m;
    }
    out.println(ans);
  }
}

class InputReader {
  public BufferedReader reader;
  public StringTokenizer tokenizer;

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

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

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

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

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


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

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

          String a = in.next();
          String b = in.next();

          int mn = 1;

          for (int i=0; i<a.length(); i++) {
            if (a.charAt(i) - '0' > mn)
                mn = a.charAt(i) - '0';
          }

            BigInteger aa = new BigInteger(a, mn+1);
            BigInteger bb = new BigInteger(b, mn+1);

          aa = aa.add(bb);

        String str = aa.toString(mn+1);
       System.out.println(str.length());
      }
   }


import java.util.*;
import java.lang.*;

public class tyler
{
    public static void main(String args[])
    {
       Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] a = new int[n];
        int sum = 1000000;
        for(int i=0;i<n;i++){
            a[i] =  sc.nextInt();
        }
        for(int i=0;i<n;i++){
            int sum1 = 0;
            int x = i;
            for(int k=0;k<n;k++){
            if(k>=x) sum1 = sum1 + a[k]*x*4;
            else sum1 = sum1 + a[k]*k*4;
            }
            if(sum>sum1) sum = sum1;
        }

        System.out.println(sum);
    }