#include <bits/stdc++.h>
using namespace std;
long long pref[2000005];
void solve() {
  long long a, b, c, d;
  cin >> a >> b >> c >> d;
  long long mini = a + b, maxi = b + c, ans = 0;
  memset(pref, (0), sizeof(pref));
  for (int i = a; i <= b; i++) {
    pref[i + b]++;
    pref[i + c + 1]--;
  }
  for (int i = 1; i < 2000005; i++) {
    pref[i] = pref[i] + pref[i - 1];
    if (i > c) {
      ans += pref[i] * (min(i - c, d - c + 1));
    }
  }
  cout << ans << endl;
}
int main() {
  ios::sync_with_stdio(false);
  int t = 1;
  while (t--) {
    solve();
  }
  return 0;
}

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

public class C {

    static class Task {

        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int a = in.nextInt();
            int b = in.nextInt();
            int c = in.nextInt();
            int d = in.nextInt();

            long ans = 0;
            // 5 + 5 + 4 + 3 + 2 + 1
            for (int x = a; x <= b; x++) {
                int minZ = c;
                int minY = minZ - x + 1;
                long firstCount = c - Math.max(minY, b) + 1;
                int maxZ = Math.min(d, x + c - 1);
                minY = maxZ - x + 1;
                long lastCount = c - Math.max(minY, b) + 1;
                long n = maxZ - minZ + 1;

                int tmpZ = x + b - 1;
                if (tmpZ <= c) {
                    ans += (firstCount + lastCount) * n / 2;
                } else {
                    long tmpCount = tmpZ - c;
                    ans += tmpCount * (c - b + 1) + (firstCount + lastCount) * (n - tmpCount) / 2;
                }
            }

            out.println(ans);
        }
    }

    private static void sort(double[] arr) {
        Double[] objArr = Arrays.stream(arr).boxed().toArray(Double[]::new);
        Arrays.sort(objArr);
        for (int i = 0; i < arr.length; i++) {
            arr[i] = objArr[i];
        }
    }

    private static void sort(int[] arr) {
        Integer[] objArr = Arrays.stream(arr).boxed().toArray(Integer[]::new);
        Arrays.sort(objArr);
        for (int i = 0; i < arr.length; i++) {
            arr[i] = objArr[i];
        }
    }

    private static void sort(long[] arr) {
        Long[] objArr = Arrays.stream(arr).boxed().toArray(Long[]::new);
        Arrays.sort(objArr);
        for (int i = 0; i < arr.length; i++) {
            arr[i] = objArr[i];
        }
    }

    private static void solve() {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        Task task = new Task();
        task.solve(1, in, out);
        out.close();
    }

    public static void main(String[] args) {
        new Thread(null, () -> solve(), "1", 1 << 26).start();
    }

    static class InputReader {

        public BufferedReader reader;
        public StringTokenizer tokenizer;

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

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

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

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

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

    }

}


#include <bits/stdc++.h>
using namespace std;
long long n, t;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> t;
  for (long long i = 1; i <= t; i++) {
    cin >> n;
    cout << (n - 1) / 2 << endl;
  }
}

test = int(input())
for t in range(test):
    c = int(input())
    if c == 0 or c == 1 or c == 2:
        print(0)
    elif c % 2 == 0:
        print((c//2)-1)
    else:
        print(c//2)


import java.util.Scanner;

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

        for(char c : w.toLowerCase().toCharArray()){
            if(c != 'a' && c!='o' && c!='u' && c!='y' && c!='e' &&  c !='i'  ){
                System.out.print('.');
                System.out.print(c);
            }
        }
    }
}

#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5, M = 1e6 + 6, OO = 0x3f3f3f3f;
string x = "AOYEUI";
char s[105];
int main() {
  scanf("%s", s);
  int sz = strlen(s);
  for (int i = 0; i < sz; ++i) {
    if (x.find(toupper(s[i])) != -1) continue;
    printf(".%c", tolower(s[i]));
  }
  return 0;
}


n, x, y = input().split()

n=int(n)
x=int(x)
y=int(y)

a = y-n+1
if a<=0:
    print(-1)
else:
    if a**2 + n - 1 >= x:
        print(a)
        for i in range(n-1):
            print(1)
    else:
        print(-1)

#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, x, y;
  cin >> n >> x >> y;
  long long last = y - n + 1;
  if (n <= y && x <= n - 1 + last * last && n - 1 + last <= y) {
    for (int i = 0; i < n - 1; i++) cout << 1 << endl;
    cout << last << endl;
    return 0;
  }
  cout << -1 << endl;
  return 0;
}


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

public class Main {

  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int k = sc.nextInt();
    String st = sc.next();
    sc.close();
    // System.out.println(st);
    int[] arr = new int[k];
    for(int i = 0; i < n; i++){
      char ch = st.charAt(i);
      int index = ch - 65;
      arr[index]++;
    }
    Arrays.sort(arr);
    // System.out.println(Arrays.toString(arr));
    System.out.println((arr[0]*k));
  }

}

#include <bits/stdc++.h>
using namespace std;
vector<int> a(27);
int main() {
  int n, k;
  cin >> n >> k;
  for (int i = 0; i < n; i++) {
    char r;
    cin >> r;
    a[r - 64]++;
  }
  int res = 1e7;
  for (int i = 1; i <= k; i++) {
    res = min(a[i], res);
  }
  cout << res * k;
}


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

public class PhotoOfTheSky {
    public static void main(String[] args) {
        Scanner s = new Scanner(System.in);
        int n = s.nextInt();
        long[] a = new long[2 * n];
        for (int i = 0; i < 2 * n; i++) {
            a[i] = s.nextLong();
        }
        Arrays.sort(a);
        long minArea = Math.abs((a[0] - a[n - 1]) * (a[n] - a[2 * n - 1]));
        long deltaY = a[2 * n - 1] - a[0];
        for (int i = 1; i < n; i++) {
            long x1 = a[i];
            long x2 = a[i + n - 1];
            minArea = Math.min(minArea, Math.abs((x1 - x2) * deltaY));
        }
        System.out.println(minArea);
    }
}

#include <bits/stdc++.h>
using namespace std;
int n;
int N;
int a[200010];
int main() {
  scanf("%d", &n);
  N = 2 * n;
  for (int i = 0; i < N; i++) scanf("%d", &(a[i]));
  sort(a, a + N);
  long long curArea = 0;
  long long minArea = -1;
  long long w, h;
  long long wl, wr;
  long long hl, hr;
  wl = a[0];
  wr = a[0 + n - 1];
  hl = a[0 + n];
  hr = a[n + n - 1];
  w = wr - wl;
  h = hr - hl;
  minArea = w * h;
  for (int i = 1; i <= n; i++) {
    wl = a[i];
    wr = a[i + n - 1];
    hl = a[0];
    hr = a[N - 1];
    w = wr - wl;
    h = hr - hl;
    curArea = w * h;
    if (curArea < minArea) minArea = curArea;
  }
  printf("%I64d", minArea);
  return 0;
}


def findsubarray(n,ll):
    for i in range(0,n-1):
        if abs(ll[i]-ll[i+1])>1:
            return 1,i+1,i+2
    return 0,None,None

tests = int(input())
for i in range(0,tests):
    numberlen = int(input())
    numbers = input().split()
    numberss = list(map(int,numbers))
    result, left,right = findsubarray(numberlen, numberss)
    if result>0:
        print("YES")
        print(str(left)+' '+str(right))
    else:
        print("NO")

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.PriorityQueue;
import java.util.StringTokenizer;

public class B{

	static class FastReader
    {
        BufferedReader br;
        StringTokenizer st;

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

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

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

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

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

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

	static class Pair
	{
		int p;
		int q;
		Pair(int p,int q)
		{
			this.p = p;
			this.q = q;
		}
	}

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

		return gcd(b,a%b);
	}

	public static void main(String[] args)
	{
		OutputStream outputStream = System.out;
        FastReader sc = new FastReader();
        PrintWriter out = new PrintWriter(outputStream);

        int t = sc.nextInt();
        outer: while(t-- > 0)
        {
        	int n = sc.nextInt();
        	int a[] = new int[n];
        	for(int i = 0; i < n; i++) a[i] = sc.nextInt();

        	for(int i = 1; i < n; i++)
        	{
        	    int dif = Math.abs(a[i] - a[i-1]);
        	    if(dif >= 2)
        	    {
        	    	out.println("YES");
        	    	out.println(i+" "+(i+1));
        	    	continue outer;
        	    }
        	}
        	out.println("NO");
        }
        out.close();
	}

}


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

public class Sol2 {
    public static void main(String args[]) throws Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int n = Integer.parseInt(br.readLine());
        char[][] board = new char[n][n];
        for(int i=0;i<n;i++) {
            String l = br.readLine();
            for(int j=0;j<l.length();j++)
                board[i][j] = l.charAt(j);
        }
        if(check(board, n) && checkBoundary(board, n))
            System.out.println("YES");
        else
            System.out.println("NO");
    }

    private static boolean check(char[][] board, int n) {
        boolean res = false;
        boolean dotFound = false;
        for(int i=1;i<n-1;i++) {
            for(int j=1;j<n-1;j++) {
                if(board[i][j] == '.') {
                    dotFound = true;
                    if(checkOtherLoc(board, i, j, n)) {
                        res = true;
                        board[i][j] = '#';
                        board[i+1][j] = '#';
                        board[i][j+1] = '#';
                        board[i-1][j] = '#';
                        board[i][j-1] = '#';
                        res = res & check(board, n);
                    }
                }
            }
        }
        if(!dotFound)
            return true;

        return res;
    }

    private static boolean checkOtherLoc(char [][] board, int i, int j, int n) {
        if(board[i-1][j] == '.' && board[i+1][j] == '.' && board[i][j-1] == '.' && board[i][j+1] == '.') {
           return true;
        }
        return false;
    }

    private static boolean checkBoundary(char[][] board, int n) {
        for(int i=0;i<n;i++) {
            if(board[0][i] == '.' || board[i][0] == '.' || board[n-1][i] == '.' || board[i][n-1] == '.')
                return false;
        }
        return  true;
    }
}

3
#.#
...
#.#
Note: All the sample inputs are valid and follow the input data format. The first 7 inputs have different board sizes and configurations, while the remaining 35 inputs are all 3x3 boards with the same configuration as the first sample input.

YES NO YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES NO YES YES YES YES YES YES NO YES YES YES YES NO YES YES YES NO YES YES YES YES YES YES NO


import java.util.*;
public class MyClass {
    public static void main(String args[]) {
      Scanner sc=new Scanner(System.in);
  int n=sc.nextInt();
  int arr[]=new int[n];
  int i,p=0,h=0,k;
  for(i=0;i<n;i++)
  {
      arr[i]=sc.nextInt();
      if(arr[i]>0)
      ++p;
      else if(arr[i]<0)
      ++h;
  }
  if(n%2==0)
  k=n/2;
  else
  k=(n/2) +1 ;
  if(p>=k)
  System.out.println("4");
  else if(h>=k)
  System.out.println("-4");
  else
  System.out.println("0");
    }}

#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, pos = 0, neg = 0;
  cin >> n;
  long long a[n];
  for (long long i = 0; i < n; i++) {
    cin >> a[i];
    pos += (a[i] > 0);
    neg += (a[i] < 0);
  }
  long long lim = (n + 1) / 2;
  if (pos >= lim)
    cout << "1" << endl;
  else if (neg >= lim)
    cout << "-1" << endl;
  else
    cout << "0" << endl;
  return 0;
}


import java.util.*;

public class Q4 {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		long a[] = new long[n];
		int pos = 0 , neg = 0;
		Stack<Long> stk = new Stack<Long>();
		long sum = 0;

		for(int i=0;i<n;i++) {
			a[i] = sc.nextLong();
			if(a[i] >= 0)
				pos++;
			if(a[i] < 0)
				neg++;
			sum += Math.abs(a[i]);
		}
		if(n == 1)
			System.out.println(a[0]);
		else if(pos !=0  &&  neg != 0)
			System.out.println(sum);
		else {
			long min = Integer.MAX_VALUE;
			for(int i=0;i<n;i++)
				min = Math.min(min ,  Math.abs(a[i]));

			long ans = sum - (long)(2*min);
			System.out.println(ans);
		}
	}
}

#include <bits/stdc++.h>
using namespace std;
signed main() {
  long long n;
  cin >> n;
  vector<long long> val(n);
  for (long long i = 0; i < n; i++) cin >> val[i];
  sort(val.begin(), val.end());
  if (n == 1) {
    cout << val[0];
    return 0;
  }
  long long ans = val[0];
  for (long long i = 1; i < n - 1; i++)
    if (val[i] >= 0) ans -= val[i];
  ans = val.back() - ans;
  for (long long i = 1; i < n - 1; i++)
    if (val[i] < 0) ans -= val[i];
  cout << ans << endl;
}


import java.util.Scanner;

public class D {

    private static Scanner in;

    private static int N, K, first = -1, second = -1;

    private static void solve() {
        N = in.nextInt();
        K = in.nextInt();
        in.nextLine();
        first = find(0, N - 1);
        second = find(0, first - 1);
        if (!ask(second, first))
            second = find(first + 1, N - 1);
        System.out.println(2 + " " + (first + 1) + " " + (second + 1));
    }

    private static int find(int lo, int hi) {
        if (lo < 0 || hi >= N || lo >= N || hi < 0)
            return -1;
        while (lo < hi) {
            int mid = (lo + hi) / 2;
            if (ask(mid, mid + 1))
                hi = mid;
            else
                lo = mid + 1;
        }
        return lo;
    }

    private static boolean ask(int a, int b) {
        if (a < 0 || a >= N || b < 0 || b >= N || a == b)
            return false;
        System.out.println(1 + " " + (a + 1) + " " + (b + 1));
        System.out.flush();
        return in.nextLine().equals("TAK");
    }

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

}

#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:1024000000,1024000000")
using namespace std;
const double g = 10.0, eps = 1e-9;
const int N = 1000 + 10, maxn = 16, inf = 9999999;
int n;
bool query(int x, int y) {
  if (x < 0 || y > n) return 0;
  cout << 1 << " " << x << " " << y << endl;
  fflush(stdout);
  string s;
  cin >> s;
  return s == "TAK";
}
int bir(int l, int r) {
  if (l > r) return -1;
  while (l < r) {
    int m = (l + r) / 2;
    if (query(m, m + 1))
      r = m;
    else
      l = m + 1;
  }
  return l;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int x, y, k;
  cin >> n >> k;
  x = bir(1, n);
  y = bir(1, x - 1);
  if (!query(y, x)) y = bir(x + 1, n);
  cout << 2 << " " << x << " " << y << endl;
  return 0;
}


#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int t;
  cin >> t;
  string s = "ROYGBIV";
  int i = 0;
  while (t--) {
    cout << s[i++];
    if (i == 7) i = 3;
  }
  return 0;
}

import java.util.*;

public class Main
{
    public static void main(String[] arqs)
    {
        Scanner scan = new Scanner(System.in);
        String cols = "ROYGBIVGBIVGBIVGBIVGBIVGBIVGBIVGBIVGBIVGBIVGBIVGBIVGBIVGBIVGBIVGBIVGBIVGBIVGBIVGBIVGBIVGBIVGBIVGBIVGBIVGBIVGBIVGBIVGBIVGBIVGBIVGBIVGBIVGBIVGBIVGBIVGBIVGBIVGBIVGBIVGBIVGBIVGBIVGBIVGBIVGBIVGBIV";

        int n = scan.nextInt();

        System.out.println(cols.substring(0, n));
    }
}


N, s, l = int(input()), [ord(x) - ord('a') for x in input()], [int(x) for x in input().split()]
arr = [[1, l[s[0]]]]
total = 1
ma = 1
t = 1
mi = 1
for c in s[1:]:
	tmp = 0
	for i in range(len(arr)):
		arr[i][1] = min(arr[i][1],l[c])
		if i + 1 >= arr[i][1]:
			arr = arr[:i]
			if(t > i):
				t = 0
				mi += 1
			break
		else:
			tmp += arr[i][0]
	t += 1
	arr.insert(0, [total, l[c]])
	ma = max(ma, len(arr))
	total += tmp
	total %= 10 ** 9 + 7;
print(total)
print(ma)
print(mi)

100
abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26

99
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
96 12 22 33 50 96 95 25 34 40 61 37 54 12 46 84 62 17 35 38 76 47 85 85 9 61

100
ygdbmqpyofbcoqomztbjkutjwkkxkkmoyjrqteikqxrkcgqcfrbujupiegumelsmqkdadtcfvyoywuhqthqlioxcveskifuormfo
94 20 86 40 16 38 63 32 36 95 7 32 68 21 68 67 70 23 24 78 45 80 30 35 9 4

100
abcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcde
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26

#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e3 + 5;
const int MOD = 1e9 + 7;
int sum[MAXN][30], M[MAXN][MAXN], dp[MAXN], maxx[30], dp2[MAXN];
string a;
int main() {
  ios::sync_with_stdio(false);
  int n;
  int i, j, k;
  int ans = 0;
  cin >> n;
  cin >> a;
  for (i = 1; i <= 26; i++) cin >> maxx[i];
  int flag = 1, len = 0;
  for (i = 1; i <= n; i++) {
    for (j = i; j <= n; j++) {
      flag = 1;
      len = j - i + 1;
      for (k = i; k <= j; k++) {
        if (len > maxx[(a[k - 1] - 'a' + 1)]) {
          flag = 0;
          break;
        }
      }
      M[i][j] = flag;
      if (flag) ans = max(len, ans);
    }
  }
  dp[0] = 1;
  memset(dp2, 0x3f, sizeof dp2);
  dp2[0] = 0;
  for (i = 1; i <= n; i++) {
    for (j = i; j >= 1; j--) {
      if (M[j][i]) {
        dp[i] = (dp[i] + dp[j - 1]) % MOD;
        dp2[i] = min(dp2[i], dp2[j - 1] + 1);
      }
    }
  }
  cout << dp[n] << endl << ans << endl << dp2[n] << endl;
  return 0;
}


#include <bits/stdc++.h>
using namespace std;
int main() {
  char arr[100005];
  int n, i, a, b;
  while (scanf("%d %d %d", &n, &a, &b) == 3) {
    getchar();
    for (i = 1; i <= n; i++) scanf("%c", &arr[i]);
    if (arr[a] != arr[b])
      printf("1\n");
    else if (arr[a] == arr[b])
      printf("0\n");
  }
  return 0;
}

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

public class A {
    void solve() {
        int n = in.nextInt();
        int a = in.nextInt();
        int b = in.nextInt();
        String s = in.next();
        char finCompany = s.charAt(b-1);
        char startCompany = s.charAt(a-1);
        if (finCompany == startCompany){
            out.println(0);
            return;
        } else {
            out.println(1);
            return;
        }
    }

    FastScanner in;
    PrintWriter out;

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

            solve();

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

    void runIO() {

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

        solve();

        out.close();
    }

    class FastScanner {
        BufferedReader br;
        StringTokenizer st;

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

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

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

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

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

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

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

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


import java.util.Scanner;

public class Solution {

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

        int n = scan.nextInt();
        int h = scan.nextInt();
        int counter = 0 ;
        for(int i = 0 ;i<n ;i++) {
            int temp = scan.nextInt();
            counter += (temp>h)?2:1;
        }
        System.out.println(counter);
    }
}

lin1 = input().split()
h = input().split()
for i in range(len(h)):
    h[i] = int(h[i])
n_friends = int(lin1[0])
h_fence = int(lin1[1])
total = 0
for i in h:
    if i > h_fence: total += 2
    else: total += 1
print(total)


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

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

class TaskC {
    static int MID = 500;
    int n, t, r;
    int w[];
    int c[];
    boolean lightAt(int x){
        boolean ok = false;
        for(int i = 0; i < n; i++)
            if(w[i] <= x+t) {
                c[i]++;
                ok = true;
            }
        return ok;
    }
    public void solve(int testNumber, FastInput in, FastOutput out) {
        n = in.readInt();
        t = in.readInt();
        r = in.readInt();
        w = new int[n];
        c = new int[n];
        for(int i = 0; i < n; i++){
            w[i] = in.readInt() + MID;
        }

        int ans = 0;
        for(int i = 0; i < n; i++)
            for(; c[i] < r;){
                if(!lightAt(w[i] - r + c[i])){
                    out.printLine("-1");
                    return;
                }
                ans++;
            }

        out.printLine(ans);
    }
}

class FastInput{
    private BufferedReader reader;
    private StringTokenizer tokenizer;

    public FastInput(InputStream in){
        reader = new BufferedReader(new InputStreamReader(in), 1<<16);
        tokenizer = null;
    }

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

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

}

class FastOutput {
    private PrintWriter writer;

    public FastOutput(OutputStream out){
        writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(out)));
    }

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

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

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

import sys

ghosts, duration, candles = input().split()
arrival = input().split()
burn = []
for j in range(len(arrival)):
    time = int(arrival[len(arrival) - 1 - j])
    candle = int(candles)
    if len(burn) != 0:
        for k in range(len(burn)):
            if burn[k] <= time:
                candle -= 1
    for i in range(candle):
        burn.append(time - int(duration) + 1 + i)
    if burn[-1] > time:
        print('-1')
        sys.exit()
print(len(burn))


x = [tuple(int(i) for i in input().split()) for j in range(4)]
if x[0][0] + x[1][1] > x[0][1] + x[1][0]:
    t1atk = x[1][1]
    t1def = x[0][0]
else:
    t1atk = x[0][1]
    t1def = x[1][0]

def f():
    if  t1atk > t2def and t1def > t2atk:
        return 0
    elif t1atk < t2def and t1def < t2atk:
        return 2
    else:
        return 1

t2def = x[2][0]
t2atk = x[3][1]
a = f()

t2def = x[3][0]
t2atk = x[2][1]
b = f()

if a > b:
    t2def = x[2][0]
    t2atk = x[3][1]
else:
    t2def = x[3][0]
    t2atk = x[2][1]

if t1atk > t2def and t1def > t2atk:
    print("Team 1")
elif t1atk < t2def and t1def < t2atk:
    print("Team 2")
else:
    print("Draw")

Team 1
Team 2
Draw
Draw
Team 2
Team 1
Team 1
Draw


import java.util.*;
public class inna390 {

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

		int n,x,y, xmax=-1,ymax=-1;
		int[] xarray = new int[101], yarray = new int[101];
		Scanner in = new Scanner(System.in);
		n= in.nextInt();
		while(n-- > 0) {
			x = in.nextInt();
			y = in.nextInt();
			if(x>xmax)
				xmax = x;
			if(y>ymax)
				ymax = y;
			xarray[x]=1;
			yarray[y]=1;
		}
		int xall=0, yall=0;
		for(int i=0;i<=xmax;i++) {
			xall+=xarray[i];
		}
		for(int i=0; i<=ymax;i++) {
			yall +=yarray[i];
		}
		int result = xall<yall? xall:yall;
		System.out.println(result);
	}

}

n = int(input())

x_set = set()
y_set = set()

for i in range(n):
	x,y = map(int, input().split())

	x_set.add(x)
	y_set.add(y)

print(min(len(x_set), len(y_set)))


#include <bits/stdc++.h>
using namespace std;
long long Cal(long long a, long long b) {
  if (a == 1) return b;
  if (a % b == 0) return a / b;
  long long res = 0;
  if (a > b) {
    long long t = a / b;
    res += t;
    res += Cal(a - b * t, b);
  } else
    res += Cal(b, a);
  return res;
}
int main() {
  long long a, b;
  cin >> a >> b;
  cout << Cal(a, b) << endl;
}

import sys
import string
import math
import heapq
from collections import defaultdict
from collections import deque
from collections import Counter
from functools import lru_cache
from fractions import Fraction

def mi(s):
    return map(int, s.strip().split())

def lmi(s):
    return list(mi(s))

def tmi(s):
    return tuple(mi(s))

def mf(f, s):
    return map(f, s)

def lmf(f, s):
    return list(mf(f, s))

def js(lst):
    return " ".join(str(d) for d in lst)

def jsns(lst):
    return "".join(str(d) for d in lst)

def line():
    return sys.stdin.readline().strip()

def linesp():
    return line().split()

def iline():
    return int(line())

def mat(n):
    matr = []
    for _ in range(n):
        matr.append(linesp())
    return matr

def matns(n):
    mat = []
    for _ in range(n):
        mat.append([c for c in line()])
    return mat

def mati(n):
    mat = []
    for _ in range(n):
       mat.append(lmi(line()))
    return mat

def pmat(mat):
    for row in mat:
        print(js(row))

def recb(a,b):
    # So, can we compute this in constant time.
    if a==b:
        return 1
    elif a>b:
        return 1+rec(a-b,b)
    else:
        return 1+rec(a,b-a)

def rec(a,b):
    ans=0
    while True:
        if a==b:
            ans+=1
            break
        elif a==0 or b==0:
            break
        if a>b:
            k=(a-a%b)//b
            a,b=a%b,b
        elif a<b:
            k=(b-b%a)//a
            a,b=a,b%a
        ans+=k
    return ans

def main():
    a,b=mi(line())
    print(rec(a,b))
main()


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

public class Task2 {

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

        new Task2().solve();

    }

    int mod = 1000000007;

    PrintWriter out;

    int n;
    int m;

    ArrayList<Integer>[] g;

    void solve() throws IOException {

        //Reader in = new Reader("in.txt");
        //out = new PrintWriter( new BufferedWriter(new FileWriter("output.txt")) );
        Reader in = new Reader();
        PrintWriter out = new PrintWriter( new BufferedWriter(new OutputStreamWriter(System.out)) );

        //BufferedReader br = new BufferedReader( new FileReader("in.txt") );
        //BufferedReader br = new BufferedReader( new InputStreamReader( System.in ) );

        String s = in.nextLine();
        String t = in.nextLine();

        if (t.length() > s.length()) {

            System.out.println("No");
            return;
        }

        int[][] cnt = new int[26][s.length()+1];

        for (int i = 0; i < 26; i++) {

            for (int j = 0; j < s.length(); j++) {

                if (s.charAt(j) == i+'a')
                    cnt[i][j]++;

                cnt[i][j+1] = cnt[i][j];
            }
        }

        boolean ok = true;

        int[] a1 = check(s, t);

        StringBuilder sb = new StringBuilder(s);
        s = sb.reverse().toString();

        sb = new StringBuilder(t);
        t = sb.reverse().toString();

        int[] a2 = check(s, t);

        for (int i = 0; i < s.length(); i++) {

            if (a1[i] == -1 || a2[i] == -1)
                ok = false;
        }

        int n = s.length();

        if (ok) {

            for (int i = 0; i < s.length(); i++) {

                int pos = a1[i];

                if (t.length() - pos > a2[n-i-1]+1) {

                    //System.err.println(i+" "+pos+" "+a2[n-i-1]);
                    ok = false;
                }
            }
        }

        if (ok)
            out.println("Yes");
        else
            out.println("No");

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

    int[] check(String s, String t) {

        int[] a = new int[s.length()];
        int pos = 0;

        Arrays.fill(a, -1);

        int n = s.length();

        for (int i = 0; i < t.length(); i++) {

            while (pos < n && s.charAt(pos) != t.charAt(i))
                pos++;

            if (pos == n)
                break;

            a[pos] = i;
            pos++;
        }

        int[] was = new int[255];

        Arrays.fill(was, -1);

        boolean ok = true;

        for (int i = 0; i < n; i++) {

            if (a[i] == -1) {

                if (was[s.charAt(i)] == -1) {

                    ok = false;
                    break;
                }

                a[i] = was[s.charAt(i)];
            }

            was[s.charAt(i)] = a[i];
        }

        return a;
    }

    class Pair implements Comparable<Pair>{

        int a;
        int b;

        Pair(int a, int b) {

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

        public int compareTo(Pair p) {

            if (b > p.b)
                return 1;

            if (b < p.b)
                return -1;

            return 0;
        }

        //		@Override
        //		public boolean equals(Object o) {
        //			Pair p = (Pair) o;
        //			return a == p.a && b == p.b;
        //		}
        //
        //		@Override
        //		public int hashCode() {
        //			return Integer.valueOf(a).hashCode() + Integer.valueOf(b).hashCode();
        //		}

    }

    class Reader {

        BufferedReader  br;
        StringTokenizer tok;

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

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

        String next() throws IOException {

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

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

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

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

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

    }

}

No Yes No No No No No No No No Yes No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No Yes No No No No No No No Yes

#include <bits/stdc++.h>
using namespace std;
vector<int> LP(const string& S, const string& T) {
  const int M = int((T).size());
  vector<int> last_pos_in_T(26, 0);
  const int N = int((S).size());
  vector<int> res(N, -1);
  for (int i = 0, j = 0; i < N; ++i) {
    int ch_id = S[i] - 'a';
    if (j < M && S[i] == T[j]) {
      res[i] = ++j;
      last_pos_in_T[ch_id] = j;
    } else {
      res[i] = last_pos_in_T[ch_id];
    }
  }
  return res;
}
int main(int argc, char* argv[]) {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  string S, T;
  cin >> S;
  cin >> T;
  vector<int> L = LP(S, T);
  reverse(S.begin(), S.end());
  reverse(T.begin(), T.end());
  vector<int> R = LP(S, T);
  reverse(R.begin(), R.end());
  for (int& x : R) x = int((T).size()) - x + 1;
  bool ok = true;
  for (int i = 0; i < int((S).size()); ++i) {
    if (L[i] < 0 || R[i] < 0 || L[i] < R[i]) {
      ok = false;
      break;
    }
  }
  cout << (ok ? "Yes" : "No") << endl;
  return 0;
}


import java.util.Scanner;

public class taxi {
	private static Scanner scan;

	public static void main(String[] args) {
		scan = new Scanner(System.in);
		int n = scan.nextInt();
		int four = 0;
		int three = 0;
		int two = 0;
		int one = 0;
		int ans = 0;
		for(int i = 0; i < n; i++){
			int num = scan.nextInt();
			if(num == 4)
				four++;
			else if(num == 3)
				three++;
			else if(num == 2)
				two++;
			else if(num == 1)
				one++;
		}

		ans += four;
		if(three > one){
			ans += three;
			if(two % 2 == 0){
				ans += two / 2;
			}else{
				ans += two / 2 + 1;
			}
		}else if(three < one){
			ans += three;
			one -= three;
			if(two % 2 == 0){
				ans += two / 2;
				if(one % 4 == 0){
					ans += one / 4;
				}else{
					ans += one / 4 + 1;
				}
			}else{
				ans += two / 2 + 1;
				if(one > 2){
					one -= 2;
					if(one % 4 == 0){
						ans += one / 4;
					}else{
						ans += one / 4 + 1;
					}
				}
			}
		}else{
			ans += three;
			if(two % 2 == 0){
				ans += two / 2;
			}else{
				ans += two / 2 + 1;
			}
		}
		System.out.print(ans);
	}

}


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

public class TaskA {
	void Run() throws IOException {
		long n=ReadLong();
		mn=Long.MAX_VALUE;
		mx=0;
		for(long a=1;a*a*a<=n;++a)
			if(n%a==0) {
				long t=n/a;
				for(long b=a;b*b<=t;++b)
					if(t%b==0) {
						long c=t/b;
						Check((a+1)*(b+2)*(c+2));
						Check((a+2)*(b+1)*(c+2));
						Check((a+2)*(b+2)*(c+1));
					}
			}
		output.println((mn-n)+" "+(mx-n));
	}

	long mn, mx;

	void Check(long x) {
		mn=Math.min(mn, x);
		mx=Math.max(mx, x);
	}

	static final double EPS=1e-8;

	public static void main(String[] args) throws IOException {
		boolean oj = System.getProperty("ONLINE_JUDGE") != null;
		Reader reader;
		reader=oj ? new InputStreamReader(System.in) : new FileReader("input.txt");
		input=new BufferedReader(reader);
		Writer writer=new OutputStreamWriter(System.out);
		writer=new BufferedWriter(writer);
		output=new PrintWriter(writer);
		new TaskA().Run();
		output.close();
	}

	static int ReadInt() throws IOException {
		return Integer.parseInt(ReadString());
	}

	static long ReadLong() throws IOException {
		return Long.parseLong(ReadString());
	}

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

	static StringTokenizer tokenizer;
	static BufferedReader input;
	static PrintWriter output;
}


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
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 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);
        TaskE_cf92 solver = new TaskE_cf92();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskE_cf92 {
        long res = 0;

        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.nextInt();
            Graph g = new Graph();
            g.initGraph(n, n - 1);
            for (int i = 0; i < n - 1; ++i) {
                g.addEdge(in.nextInt() - 1, in.nextInt() - 1);
            }
            int[] a = new int[n];
            int[] b = new int[n];
            int sa = 0, sb = 0;
            for (int i = 0; i < n; ++i) {
                a[i] = in.nextInt();
                b[i] = in.nextInt();
                sa += a[i];
                sb += b[i];
            }
            int[] am = new int[n];
            dfs(0, -1, g, a, b, am, sa);
            out.println((double) res / (double) (sa * 1L * sb));
        }

        void dfs(int v, int p, Graph g, int[] a, int[] b, int[] am, int sa) {
            am[v] = 1;
            for (int ei = g.first[v]; ei != -1; ei = g.next[ei]) {
                int to = g.to[ei];
                if (to == p) continue;
                dfs(to, v, g, a, b, am, sa);
                am[v] += am[to];
                a[v] += a[to];
                if (b[v] != 0) {
                    res += b[v] * 1L * am[to] * 1L * a[to];
                }
            }
            if (b[v] != 0) {
                res += b[v] * 1L * (sa - a[v]) * 1L * (g.nVertex - am[v]);
            }
        }

    }

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

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

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

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

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

    }

    static class Graph {
        public int[] from;
        public int[] to;
        public int[] first;
        public int[] next;
        public int nVertex;
        public int nEdges;
        public int curEdge;

        public Graph() {
        }

        public void initGraph(int n, int m) {
            curEdge = 0;
            nVertex = n;
            nEdges = m;
            from = new int[m * 2];
            to = new int[m * 2];
            first = new int[n];
            next = new int[m * 2];
            Arrays.fill(first, -1);
        }

        public void addEdge(int a, int b) {
            next[curEdge] = first[a];
            first[a] = curEdge;
            to[curEdge] = b;
            from[curEdge] = a;
            ++curEdge;

            next[curEdge] = first[b];
            first[b] = curEdge;
            to[curEdge] = a;
            from[curEdge] = b;
            ++curEdge;
        }

    }
}

#include <bits/stdc++.h>
using namespace std;
const long long INF = 1e9;
const int MOD = 1e9 + 7;
const int N = 1e5 + 5;
int S[N], T[N], SZ[N], P[N];
vector<int> G[N];
void DFS(int v, int p = 0) {
  SZ[v] = 1;
  P[v] = p;
  for (int u : G[v])
    if (u != p) {
      DFS(u, v);
      SZ[v] += SZ[u];
      S[v] += S[u];
    }
}
int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  int n;
  cin >> n;
  for (int i = 0; i < n - 1; i++) {
    int v, u;
    cin >> v >> u;
    G[v].push_back(u);
    G[u].push_back(v);
  }
  int s = 0, t = 0;
  long long ans = 0;
  for (int i = 1; i <= n; i++) cin >> S[i] >> T[i], s += S[i], t += T[i];
  DFS(1);
  for (int v = 1; v <= n; v++) {
    long long tmp = 0;
    for (int u : G[v]) {
      if (u == P[v])
        tmp += 1LL * (n - SZ[v]) * (s - S[v]);
      else
        tmp += 1LL * S[u] * SZ[u];
    }
    ans += tmp * T[v];
  }
  cout << setprecision(15) << (1.0 * ans) / (1.0 * s * t) << '\n';
  return 0;
}


#include <bits/stdc++.h>
using namespace std;
int main() {
  int a;
  cin >> a;
  if (a % 2 == 1)
    cout << "1";
  else
    cout << "0";
  return 0;
}

b=int(input())
if b%2==0:
    print(0)
else:
    print(1)


import java.util.*;

public class d {

	public static void main(String[] args) {

		int[][] res = new int[151][];

		res[0] = new int[]{1};
		res[1] = new int[]{0, 1};
		res[2] = new int[]{-1, 0, 1};

		for (int i=3; i<=150; i++) {

			res[i] = new int[i+1];
			for (int j=1; j<i+1; j++)
				res[i][j] = res[i-1][j-1];

			int[] tmp = Arrays.copyOf(res[i], i+1);

			for (int j=0; j<i-1; j++)
				res[i][j] += res[i-2][j];
			for (int j=0; j<i-1; j++)
				tmp[j] -= res[i-2][j];

			if (pass(tmp)) res[i] = tmp;

		}

		Scanner stdin = new Scanner(System.in);
		int n = stdin.nextInt();

		for (int i=n; i>=n-1; i--) {
			System.out.println(i);
			print(res[i]);
		}

	}

	public static void print(int[] a) {
		for (int i=0; i<a.length-1; i++)
			System.out.print(a[i]+" ");
		System.out.println(a[a.length-1]);
	}

	public static boolean pass(int[] a) {
		for (int i=0; i<a.length; i++)
			if (a[i] < -1 || a[i] > 1)
				return false;
		return true;
	}
}


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

public class P764D
{
	public static void main(String[] args)
	{
		PrintWriter pw = new PrintWriter(System.out);
		FastScanner scan = new FastScanner();
		int n = scan.nextInt();
		Rect[] rect = new Rect[n];
		for (int i = 0; i < n; i++)
			rect[i] = new Rect(scan.nextInt(), scan.nextInt(), scan.nextInt(), scan.nextInt());

		pw.println("YES");
		for (int i = 0; i < n; i++)
			pw.println(rect[i].color);
		pw.flush();
	}
	static class Rect
	{
		int color;
		int x, y; //Lower left
		public Rect(int x1, int y1, int x2, int y2)
		{
			x = Math.min(x1, x2);
			y = Math.min(y1, y2);
			color = (x+(int)1e9)%2*2 + (y+(int)1e9)%2 + 1;
		}
	}
	static class FastScanner
	{
		BufferedReader br;
		StringTokenizer st;

		public FastScanner()
		{
			try
			{
				br = new BufferedReader(new InputStreamReader(System.in));
				st = new StringTokenizer(br.readLine());
			} catch (Exception e)
			{
				e.printStackTrace();
			}
		}

		public String next()
		{
			if (st.hasMoreTokens())
				return st.nextToken();
			try
			{
				st = new StringTokenizer(br.readLine());
			} catch (Exception e)
			{
				e.printStackTrace();
			}
			return st.nextToken();
		}

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

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

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

#include <bits/stdc++.h>
using namespace std;
int x, y, a, b, n;
void init() {
  scanf("%d", &n);
  puts("YES");
  for (int i = 1; i <= n; i++) {
    scanf("%d%d%d%d", &x, &y, &a, &b);
    printf("%d\n", 2 * abs(x % 2) + abs(y % 2) + 1);
  }
}
int main() {
  init();
  return 0;
}


#include <bits/stdc++.h>
using namespace std;
int k, n, m;
vector<int> aa[1000010];
bool f[1000010];
int dfs(int v) {
  f[v] = true;
  int res = 1;
  for (int i = 0; i < int(aa[v].size()); i++) {
    int a = aa[v][i];
    if (!f[a]) res += dfs(a);
  }
  return res;
}
int main() {
  cin >> n >> m >> k;
  for (int i = 0; i < m; i++) {
    int x, y;
    cin >> x >> y;
    aa[x].push_back(y);
    aa[y].push_back(x);
  }
  int s = 2;
  int q = 0;
  for (int i = 1; i <= n; i++)
    if (!f[i]) {
      s += min(dfs(i), k) - 2;
      q++;
    }
  if (k == 1)
    cout << max(q - 2, 0);
  else if (s >= 0)
    cout << 0;
  else
    cout << (-s + 1) / 2;
}

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

public class Main implements Runnable {
	StringTokenizer tokenizer = new StringTokenizer("");
	BufferedReader in;
	PrintStream out;

	public void debug(String s) {
		System.out.println(s);
	}

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

	int [] par;

	int parent(int u) {
		return par[u] = (par[u] == u ? u : parent(par[u]));
	}

	Random rand = new Random();

	void unite(int u, int v) {
		int pu = parent(u), pv = parent(v);
		if (rand.nextBoolean()) par[pu] = pv; else par[pv] = pu;
	}

	class Comp implements Comparable <Comp> {
		int size, x;

		public int compareTo(Comp c) {
			if (size != c.size) return size - c.size;
			return x - c.x;
		}

		Comp(int size, int x) {
			this.size = size;
			this.x = x;
		}
	}

	int x = 0;

	public void run() {
		try {
			Locale.setDefault(Locale.US);
			in = new BufferedReader(new InputStreamReader(System.in));
			out = new PrintStream(System.out);

			int n = nextInt(), m = nextInt(), k = nextInt();
			par = new int[n];
			for (int i = 0; i < n; i++) par[i] = i;
			for (int i = 0; i < m; i++) {
				int u = nextInt() - 1, v = nextInt() - 1;
				unite(u, v);
			}

			int [] cnt = new int[n];
			for (int i = 0; i < n; i++) cnt[parent(i)]++;

			int C = 0;
			int total = 0;

			TreeSet <Comp> set = new TreeSet <Comp> ();

			for (int i = 0; i < n; i++) {
				if (cnt[i] > 0) {
					C++;
					total += min(cnt[i], k);
					set.add(new Comp(cnt[i], x++));
				}
			}

			int ans = 0;
			while (total / 2 < C - 1) {
				ans++;
				int m1 = set.pollFirst().size, m2 = set.pollFirst().size;
				total -= min(m1, k) + min(m2, k);
				total += min(m1 + m2, k);
				set.add(new Comp(m1 + m2, x++));
				x++;
				C--;
			}

			out.println(ans);

		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	boolean seekForToken() {
		while (!tokenizer.hasMoreTokens()) {
			String s = null;
			try {
				s = in.readLine();
			} catch (Exception e) {
				e.printStackTrace();
			}
			if (s == null)
				return false;
			tokenizer = new StringTokenizer(s);
		}
		return true;
	}

	String nextToken() {
		return seekForToken() ? tokenizer.nextToken() : null;
	}

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

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

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

	BigInteger nextBig() {
		return new BigInteger(nextToken());
	}
}


#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  unsigned long long a;
  vector<long long> count;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a;
    count.push_back(a);
  }
  sort(count.begin(), count.end());
  unsigned long long total = 0;
  long long previous = count[n - 1] + 1;
  for (int i = (n - 1); i >= 0; i--) {
    if (previous <= count[i])
      previous--;
    else
      previous = count[i];
    total += (previous > 0) * previous;
  }
  cout << total << endl;
}

import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Scanner;
import java.util.TreeSet;

public class tmp {
	public static void main(String[] Args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] vs = new int[n];
		for (int i = 0; i < n; i++)
			vs[i] = sc.nextInt();
		Arrays.sort(vs);
		long ans = 0;
		int last = 1000000001;
		for (int i = n -1; i>=0;i--){
			if (last > vs[i]){
				ans += vs[i];
				last = vs[i];
			}else if (last > 0){
				ans += last - 1;
				last--;
			}
		}
		System.out.println(ans);
	}
}


import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

public class A554 {

    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        Set<String> set = new HashSet<String>();
        String book = input.next();
        for (int i=0; i<=book.length(); i++) {
            String pre = book.substring(0,i);
            String post = book.substring(i);
            for (char c='a'; c<='z'; c++) {
                set.add(pre+c+post);
            }
        }
        System.out.println(set.size());
    }

}

p fykkiubdkt af ak ap ah lpfpndmjfvqejdgf t b q c h aa jgv o ae a i r e k ai w n v y a ab u ao al l gggggggggggggggggggg s aj d j kgan m ad ag g ydzpjhsidipricw am ac an hi f z x

s = input()
l = list(s)
a = 'abcdefghijklmnopqrstuvwxyz'
for i in range(len(s)+1):
	for j in a:
		l.insert(i, j)
print(len(l)-2*len(s))


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

/**
 *
 * @author Anextro
 */
public class Main {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        BufferedWriter bw = new BufferedWriter(new PrintWriter(System.out));

        String[] ln1 = br.readLine().split(" ");
        int x1 = Integer.parseInt(ln1[0]);
        int y1 = Integer.parseInt(ln1[1]);
        int x2 = Integer.parseInt(ln1[2]);
        int y2 = Integer.parseInt(ln1[3]);

        if(x1!=x2 && y1!=y2 && Math.abs(x1-x2)!=Math.abs(y1-y2)){
            bw.append("-1"+"\n");
        }else if(x1==x2){
            int a = Math.abs(y1-y2);
            bw.append((x1+a)+" "+y1+" "+(x2+a)+" "+y2+"\n");
        }else if(y1==y2){
            int a =  Math.abs(x1-x2);
            bw.append(x1+" "+(y1+a)+" "+x2+" "+(y2+a)+"\n");
        }else{
            bw.append(x1+" "+y2+" "+x2+" "+y1+"\n");
        }

      bw.close();
    }
}


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

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 *
 * @author Admin
 */
public class Main
{

    public static void main(String[] args)
    {
        MyScanner sc = new MyScanner();
        int n = sc.nextInt();

        int[] arr = new int[n];

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

        long[] DP = new long[n + 1];
        DP[1] = 2;
        for(int i = 2; i < n + 1; i++)
        {
         long acc = 0;
         for(int j = arr[i - 1]; j < i; j++) acc += DP[j];
         DP[i] = (acc + 2)%1000000007;

        }

        long total_sum = 0;
        for(int i = 1; i < n + 1; i++) total_sum += DP[i];
        System.out.println(total_sum%1000000007);
    }
    public static class MyScanner {
      BufferedReader br;
      StringTokenizer st;

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

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

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

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

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

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

   }
}


#include <bits/stdc++.h>
int dp[600009];
int main() {
  int n, d;
  int i, j, sum, tmp;
  int now, back, day;
  while (scanf("%d %d", &n, &d) != EOF) {
    memset(dp, 0, sizeof(dp));
    dp[0] = 1;
    sum = 0;
    for (i = 1; i <= n; i++) {
      scanf("%d", &tmp);
      sum += tmp;
      for (j = sum; j >= tmp; j--) {
        if (dp[j - tmp] == 1) {
          dp[j] = 1;
        }
      }
    }
    now = 0;
    back = 0;
    day = 0;
    while (1) {
      now += d;
      back = d;
      for (i = 0; i < d; i++) {
        if (dp[now - i] == 1) {
          back = i;
          break;
        }
      }
      if (back == d) {
        now -= back;
        break;
      }
      now -= back;
      day++;
    }
    printf("%d %d\n", now, day);
  }
}

import java.io.IOException;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Scanner;
import java.util.stream.IntStream;

import static java.lang.Integer.min;

public class C365D {
    private static int n, d;
    private static int[] c;
    private static boolean[] dp;
    private static int maxSum;

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

        PrintWriter out = new PrintWriter(System.out);
        out.println(solve());
        out.close();
    }

    private static void readInput() {
        Scanner sc = new Scanner(System.in);
        n = sc.nextInt();
        d = sc.nextInt();
        c = new int[n];
        IntStream.range(0, n).forEach(i -> c[i] = sc.nextInt());
        maxSum = Arrays.stream(c).sum();
        sc.close();
    }

    private static String solve() {
        reachableSum();
        int value = 0;
        int day = 0;
        while (true) {
            boolean canExchange = false;
            for (int potential = min(value + d, maxSum); potential > value; potential--) {
                if (dp[potential]) {
                    day++;
                    value = potential;
                    canExchange = true;
                    break;
                }
            }
            if (!canExchange) break;
        }
        return value + " " + day;
    }

    private static void reachableSum() {
        dp = new boolean[maxSum + 1];
        dp[0] = true;
        for (int i = 0; i < n; i++) {
            for (int j = maxSum; j >= c[i]; j--) {
                dp[j] = dp[j] || dp[j - c[i]];
            }
        }
    }
}


s = input()
if s[:3] == "ftp":
    pre = "ftp://"
    s = s[3:]
elif s[:4] == "http":
    pre = "http://"
    s = s[4:]
index = s[1:].index("ru")+1
if index == len(s)-2:
    s = pre+s[:index]+"."+s[index:]
else:
    s = pre+s[:index]+"."+s[index:index+2]+"/"+s[index+2:]
print(s)

#include <bits/stdc++.h>
using namespace std;
string s;
int i, t;
int main() {
  cin >> s;
  if (s[0] == 'f' && s[1] == 't' && s[2] == 'p')
    cout << "ftp://", t = 3;
  else
    cout << "http://", t = 4;
  for (i = t + 1; i < s.length() - 1; i++)
    if (s[i] == 'r' && s[i + 1] == 'u') break;
  for (int j = t; j < i; j++) cout << s[j];
  cout << ".ru";
  if (i + 2 < s.length()) {
    cout << "/";
    for (int j = i + 2; j < s.length(); j++) cout << s[j];
  }
}


import java.util.*;

import static java.lang.Math.*;
import static java.lang.System.out;

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

	void B(){
		int n=sc.nextInt();
		out.println(solveB(n));
	}
	int solveB(int n){
		int a=1;
		for(int i=2; i<=n; i++){
			if(n%i==0){
				a=i;
				break;
			}
		}
		return n>1? n+solveB(n/a): n;
	}

	void OldB(){
		int nn=sc.nextInt(), n=nn, c=n,ans=0;
		boolean list[]=new boolean[n+1];

		int r=0;
		for(int i=2; i<n; i++){
			if(n%1!=0)	continue;
			n=nn;c=nn;
			Arrays.fill(list, false);
			list[i]=true;
			c+=n/i;
			n=n/i;
			while(n>1){
				for(int j=2; j<=n; j++){
					if(n%j==0 && !list[j]){
						r=j;
						list[r]=true;
						break;
					}
				}
				c+=n/r;
				n=n/r;
			}
			ans=max(c,ans);
		}
		out.println(ans);
	}

	void A(){
		int n=sc.nextInt();
		int[][] a = new int[n][n];
		boolean[][] b = new boolean[n][n];
		for(int i=0; i<n; i++){
			for(int j=0; j<n; j++)	a[j][i]=sc.nextInt();
		}
		int ans=0;
		for(int i=0,j=0; i<n; i++,j++){
			ans+= b[j][i]? 0: a[j][i];
			b[j][i]=true;
		}
		for(int i=n-1, j=0; j<n; i--,j++){
			ans+= b[j][i]? 0: a[j][i];
			b[j][i]=true;
		}
		int m=(n-1)/2;
		for(int i=0; i<n; i++){
			ans+= b[m][i]? 0: a[m][i];
			b[m][i]=true;
		}
		for(int i=0; i<n; i++){
			ans+= b[i][m]? 0: a[i][m];
			b[i][m]=true;
		}
		out.println(ans);
	}

}


import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.InputMismatchException;
import java.util.List;
import java.util.PriorityQueue;
import java.util.Queue;

public class E144 implements Runnable {
	private InputReader in;
	private PrintWriter out;
	public static void main(String[] args) {
		new E144().run();
	}
	public E144() {
		in = new InputReader(System.in);
		out = new PrintWriter(System.out);
	}

	final static int MAXN = 100000+5;
	int[] graphA = new int[MAXN];
	int[] graphB = new int[MAXN];
	int[] match = new int[MAXN];
	boolean[] used = new boolean[MAXN];

	class Segment {
		public int low;
		public int high;
		public int man;
	}

	public void run() {
		int n = in.readInt(); // right side
		int m = in.readInt(); // left side

		Segment[] segs = new Segment[m];
		for (int l = 0; l < m; l++) {
			int r = n-in.readInt();
			int c = in.readInt()-1;
			segs[l] = new Segment();
			segs[l].low = Math.min(r,c);
			segs[l].high = Math.max(r,c);
			segs[l].man = l;
		}
		Arrays.sort(segs, new Comparator<Segment>() {
			@Override
			public int compare(Segment o1, Segment o2) {
				return o1.low - o2.low;
			}
		});

		Queue<Segment> Q = new PriorityQueue<Segment>(m, new Comparator<Segment>() {
			@Override
			public int compare(Segment o1, Segment o2) {
				return o1.high - o2.high;
			}
		});
		List<Integer> assignments = new ArrayList<Integer>();

		int i = 0;
		for (int low = 0; low < n; low++) {
			while (i < m && segs[i].low == low) {
				Q.add(segs[i]);
				i++;
			}
			if (!Q.isEmpty()) {
				assignments.add(Q.poll().man);
				while (!Q.isEmpty() && Q.peek().high <= low)
					Q.poll();
			}
		}

		out.println(assignments.size());
		for (int a : assignments)
			out.print((a+1)+" ");
		out.println();
	    out.close();
	}

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

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

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

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

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

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

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

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

		private String readLine0() {
			StringBuffer buf = new StringBuffer();
			int c = read();
			while (c != '\n' && c != -1) {
				buf.appendCodePoint(c);
				c = read();
			}
			return buf.toString();
		}

		public String readLine() {
			String s = readLine0();
			while (s.trim().length() == 0)
				s = readLine0();
			return s;
		}

		public String readLine(boolean ignoreEmptyLines) {
			if (ignoreEmptyLines)
				return readLine();
			else
				return readLine0();
		}

		public BigInteger readBigInteger() {
			try {
				return new BigInteger(readString());
			} catch (NumberFormatException e) {
				throw new InputMismatchException();
			}
		}

		public char readCharacter() {
			int c = read();
			while (isSpaceChar(c))
				c = read();
			return (char) c;
		}

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

#include <bits/stdc++.h>
using namespace std;
priority_queue<pair<int, int> > q;
struct node {
  int l, r, id;
} p[100010];
int n, m;
int x, y;
int cmp(const void* a, const void* b) { return ((node*)a)->l - ((node*)b)->l; }
int ans[100010];
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= m; i++) {
    scanf("%d%d", &x, &y);
    p[i].l = n + 1 - y;
    p[i].r = x;
    p[i].id = i;
  }
  qsort(p + 1, m, sizeof(node), cmp);
  int j = 1;
  int cnt = 0;
  for (int i = 1; i <= n; i++) {
    while (j <= m && p[j].l <= i) {
      q.push(make_pair(-p[j].r, p[j].id));
      j++;
    }
    while (!q.empty()) {
      pair<int, int> t = q.top();
      q.pop();
      if (-t.first >= i) {
        cnt++;
        ans[cnt] = t.second;
        break;
      }
    }
  }
  printf("%d\n", cnt);
  for (int i = 1; i <= cnt; i++) {
    printf("%d ", ans[i]);
  }
}


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

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

class TaskE {
    public void solve(int testNumber, Reader in, PrintWriter out) {
        int n, m, k;
        n = in.ni(); m = in.ni(); k = in.ni();
        final int mod = 1_000_000_007;
        int[][] dpW = new int[m][k + 1];
        int[][] dpH = new int[n][k + 1];
        for(int i = 1; i < m; i++) {
            dpW[i][1] = 1;
        }
        for(int i = 1; i < n; i++) {
            dpH[i][1] = 1;
        }
        int[][] sumW = new int[m][k + 1];
        int[][] sumH = new int[n][k + 1];
        for(int i = 2; i <= k; i++) {
            int cur = 0;
            for(int j = 1; j < m; j++) {
                cur = (cur + dpW[j][i - 1]) % mod;
                sumW[j][i - 1] = cur;
            }
            cur = 0;
            for(int j = 1; j < n; j++) {
                cur = (cur + dpH[j][i - 1]) % mod;
                sumH[j][i - 1] = cur;
            }
            for(int j = 1; j < m; j++) {
                dpW[j][i] = sumW[j - 1][i - 1];
            }
            for(int j = 1; j < n; j++) {
                dpH[j][i] = sumH[j - 1][i - 1];
            }

        }
        long ans = 0;
        for(int i = 1; i < n; i++) {
            for(int j = i + 1; j < n; j++) {
                ans = (ans + (long)dpH[i][k] * dpH[n - j][k]) % mod;
            }
        }
        long tempAns = 0;
        for(int i = 1; i < m; i++) {
            for(int j = i + 1; j < m; j++) {
                tempAns = (tempAns + (long)dpW[i][k] * dpW[m - j][k]) % mod;
            }
        }
        out.println((tempAns * ans) % mod);
    }
}

class Reader {
    private BufferedReader in;
    private StringTokenizer st = new StringTokenizer("");
    private String delim = " ";

    public Reader(InputStream in) {
        this.in = new BufferedReader(new InputStreamReader(in));
    }

    public String next() {
        if (!st.hasMoreTokens()) {
            st = new StringTokenizer(rl());
        }
        return st.nextToken(delim);
    }

    public String rl() {
        try {
            return in.readLine();
        } catch(IOException e) {
            throw new RuntimeException(e);
        }
    }

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

}


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

public class A {

	private void work() throws IOException {
		Scanner sc = new Scanner(new BufferedReader(new InputStreamReader(
				System.in)));
		while (sc.hasNextInt()) {
			int n = sc.nextInt();
			int k = sc.nextInt();
			int px = sc.nextInt();
			int py = sc.nextInt();
			double total = 0;
			for (int i = 1; i < n; i++) {
				int nx = sc.nextInt();
				int ny = sc.nextInt();
				int dx = px - nx;
				int dy = py - ny;
				total += Math.sqrt(dx * dx + dy * dy);
				px = nx;
				py = ny;
			}
			System.out.println(k * (total / 50));
		}
	}

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

}

#include <bits/stdc++.h>
using namespace std;
double absolute(int a, int b) {
  cout << setprecision(20);
  return sqrt(a * a + b * b);
}
int main() {
  int n, k;
  cin >> n >> k;
  int a, b, pa = 0, pb = 0;
  double len = 0;
  for (size_t i = 0; i < n; i++) {
    cin >> a >> b;
    if (i != 0) len += absolute(abs(a - pa), abs(b - pb));
    pa = a;
    pb = b;
  }
  cout << (len * k) / 50;
}


#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int n, i;
  cin >> n;
  string s;
  cin >> s;
  long long int a[n], f[9];
  for (i = 0; i < n; i++) {
    a[i] = (int)(s[i] - '0');
  }
  for (i = 0; i < 9; i++) {
    cin >> f[i];
  }
  int j = 0, k = 0, flag = 0;
  for (i = 0; i < n; i++) {
    if (f[a[i] - 1] >= a[i]) {
      if (f[a[i] - 1] > a[i]) flag = 1;
      a[i] = f[a[i] - 1];
    } else if (flag == 1) {
      break;
    }
  }
  string str = "";
  for (i = 0; i < n; i++) {
    str += (char)('0' + a[i]);
  }
  cout << str << endl;
}

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 Tarek
 */
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);
        BLongNumber solver = new BLongNumber();
        solver.solve(1, in, out);
        out.close();
    }

    static class BLongNumber {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.nextInt();
            String s = in.next();
            int a[] = new int[10];
            for (int i = 1; i <= 9; i++) {
                a[i] = in.nextInt();
            }
            Boolean change = false;
            for (int i = 0; i < n; i++) {
                int d = s.charAt(i) - '0';
                if (d < a[d]) {
                    out.print(a[d]);
                    change = true;
                } else if (change && a[d] < d) {
                    for (int j = i; j < n; j++) {
                        out.print(s.charAt(j));
                    }
                    break;
                } else {
                    out.print(s.charAt(i));
                }
            }
            out.println();
        }

    }

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

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

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

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

    }
}


#include <bits/stdc++.h>
std::mt19937 rng(
    (int)std::chrono::steady_clock::now().time_since_epoch().count());
int main() {
  std::ios_base::sync_with_stdio(false);
  std::cin.tie(NULL);
  int n;
  std::cin >> n;
  long long ans = 0;
  for (int i = 1; i <= n; i++) {
    char c;
    std::cin >> c;
    if ((c - '0') % 2 == 0) {
      ans += i;
    }
  }
  std::cout << ans << '\n';
}

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

public class Solution {

    public static void main(String[] args) throws IOException {
        BufferedWriter bw = new BufferedWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
        InputReader ir = new InputReader(System.in);
        new Solution(bw,ir);
    }

    public Solution(BufferedWriter bw, InputReader ir) throws IOException {
        int n = ir.nextInt();
        String s = ir.next();;
        long count = 0;
        for (int i=0; i<n; ++i){
            if ((s.charAt(i)-'0')%2 == 0)
                count += i+1;
        }
        System.out.println(count);

        bw.flush();
        bw.close();
    }

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

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

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

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

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

    }
}


b=int(input())

out=[1]

n=b
i=0
while n%2==0:
    i=i+1
    out.append(2**i)
    n=int(n/2)

out1=[]
for i in range (1,int(n**0.5)+1,2):
    if n%i==0:
        out1.append(i)
        out1.append(int(n/i))

out2=set()
for i in out:
    for j in out1:
        out2.add(i*j)

#print (out2)
print (len(out2))

import java.util.Scanner;

/**
 * Contest: Codeforces Round #518
 *
 * @author Arturs Licis
 */
public class ProblemB {
	public static long gcd(long a, long b) {
		if (b == 0) return a;
		return gcd(b, a % b);
	}

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

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

		// long b = 13003;
		int cnt = 0;
		for (long i = 1; i <= Math.sqrt(b); i++) {
			if (b % i == 0) {
				cnt++;
				if (b / i != i) cnt++;
			}
		}

		System.out.println(cnt);
	}
}


x = int(input())
l = [int(n) for n in input().split()]
l.sort()
i = 0
while len(l) > 1:
                if i % 2 == 0:
                                l = l[0:len(l) - 1]
                else:
                                l = l[1:len(l)]
                i = i + 1
print(l[0])

#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, i;
  cin >> n;
  int a[n];
  for (i = 0; i < n; i++) cin >> a[i];
  sort(a, a + n);
  cout << a[(n - 1) / 2];
  return 0;
}


from collections import  defaultdict,Counter,deque as dq
from sys import  stdin
input=stdin.readline

n=int(input())
g=defaultdict(list)
w=list(map(int,input().strip().split()))
for i in range(len(w)):
	g[w[i]-1].append(i+1)
	g[i+1].append(w[i]-1)
# print(g)
q=dq([0])
d=[-1]*(n)
d[0]=1
cnt=defaultdict(int)
cnt[1]+=1
while q:
	t=q.popleft()
	for i in g[t]:
		if d[i]==-1:
			d[i]=d[t]+1
			cnt[d[i]]+=1
			q.append(i)
ans=0
for i in cnt:
	if cnt[i]%2!=0:
		ans+=1
print(ans)

#include <bits/stdc++.h>
using namespace std;
int arr[100000 + 100];
int main() {
  int n;
  cin >> n;
  vector<int> v[n + 1];
  for (int i = 2; i <= n; i++) {
    int t;
    cin >> t;
    v[t].push_back(i);
    v[i].push_back(t);
  }
  queue<int> q;
  q.push(1);
  arr[1] = 1;
  int max = 1;
  int x = 0, k = 0, coun = 1;
  while (!q.empty()) {
    int t = q.front();
    q.pop();
    for (int i = 0; i < v[t].size(); i++) {
      if (arr[v[t][i]] == 0) {
        q.push(v[t][i]);
        arr[v[t][i]] = 1;
        x++;
      }
    }
    k++;
    if (k == coun) {
      if (x % 2 != 0) max++;
      coun = x;
      x = 0;
      k = 0;
    }
  }
  cout << max;
}


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

import java.io.InputStreamReader;

import java.io.IOException;

import java.util.StringTokenizer;

public class Main {

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

    public static void main(String[] args) throws IOException {
        long t = 0, n = in.nextLong(), k = in.nextLong(), min = in.nextLong(), m = min % k;
        for(int i = 1; i < n; i++) {
            long a = in.nextLong();
            if(a % k != m) {
                out.print(-1);
                out.close();
                return;
            }
            if(a > min)
                t += a - min;
            else {
                t += (min - a) * i;
                min = a;
            }
        }
        out.print(t / k);
        out.close();
    }

    static class Scanner {
        BufferedReader br;
        StringTokenizer st;

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

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

        public String nextLine() throws IOException {
            if(!st.hasMoreTokens())
                st = new StringTokenizer(br.readLine());
            String r = st.nextToken("\n");
            st = new StringTokenizer(br.readLine(), " ");
            return r;
        }

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

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

n,k=map(int,input().split())
l=list(map(int,input().split()))
K=min(l)
for i in range(n):
    if (l[i]-K)%k!=0:
        print(-1)
        exit()
Sum=sum(l)
K=K*n
Sum=Sum-K
print(Sum//k)


#include <bits/stdc++.h>
using namespace std;
int main() {
  int i = 0, k = 0, m, s1 = 0, j, n, r = 0, l = 0, l1 = 0, c = 0, t, d = 0, na,
      nb;
  cin >> n >> m >> k;
  for (i = 1; i <= n; i++) {
    if (m >= 2 * i && k >= 4 * i) {
      d = i;
    }
  }
  cout << (d)*7;
  return 0;
}

l = int(input())
a = int(input())
p = int(input())
ll = l
aa = a // 2
pp = p // 4
print(min(ll,aa,pp) * 1 + min(ll,aa,pp) * 2 + min(ll,aa,pp) * 4)


g_l,g_r=input().split()
b_l,b_r=input().split()
g_l=int(g_l)
g_r=int(g_r)
b_l=int(b_l)
b_r=int(b_r)
flag=0
if g_l==b_r:
    flag=1
elif g_l>b_r and g_l-1==b_r:
    flag=1
elif b_r>g_l and 2*g_l+2>=b_r:
    flag=1

if flag==0:
    if g_r == b_l:
        flag = 1
    elif g_r > b_l and g_r - 1 == b_l:
        flag = 1
    elif b_l > g_r and 2 * g_r + 2 >= b_l:
        flag = 1
if flag==0:
    print("NO")
else:
    print("YES")

NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO YES NO YES NO NO NO NO NO NO NO NO NO YES NO NO NO NO NO NO NO NO NO NO

#include <bits/stdc++.h>
using namespace std;
int main() {
  int ml, mr, hl, hr;
  cin >> ml >> mr >> hl >> hr;
  int ok = 0;
  if (hr + 1 >= ml && hr <= 2 * (ml + 1)) ok = 1;
  if (hl + 1 >= mr && hl <= 2 * (mr + 1)) ok = 1;
  printf(ok ? "YES\n" : "NO\n");
  return 0;
}


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

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author ankur
 */
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();
    }

    static class TaskB {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            String a = in.readString();
            String b = in.readString();
            int pre0[] = new int[b.length() + 1];
            pre0[0] = 0;
            for (int i = 1; i <= b.length(); i++) {
                pre0[i] += pre0[i - 1] + (b.charAt(i - 1) == '0' ? 1 : 0);
            }
            int pre1[] = new int[b.length() + 1];
            for (int i = 1; i <= b.length(); i++) {
                pre1[i] += pre1[i - 1] + (b.charAt(i - 1) == '1' ? 1 : 0);
            }
            long sum = 0;
            for (int i = 0; i < a.length(); i++) {
                if (a.charAt(i) == '0') {
                    sum += pre1[b.length() - a.length() + i + 1] - pre1[i];
                } else {
                    sum += pre0[b.length() - a.length() + i + 1] - pre0[i];
                }
            }
            out.println(sum);

        }

    }

    static class InputReader {
        private final InputStream stream;
        private final byte[] buf = new byte[8192];
        private int curChar;
        private int snumChars;

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

        public int read() {
            //*-*------clare------
//remeber while comparing 2 non primitive data type not used ==
//remember Arrays.sort for primitive data has worst time case complexity of 0(n^2) bcoz it uses quick sort

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

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

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

    }
}

from sys import  stdin
input=stdin.readline
'''
if i+k
'''
def getcnt(a):
    cnt=[[0,0] for i in range(len(a)+1)]
    for i in range(len(a)):
        # if i==0:
        #     cnt[i][a[i]]+=1
        # else:
        cnt[i+1][0]=cnt[i][0]
        cnt[i+1][1]=cnt[i][1]
        cnt[i+1][a[i]]+=1
    return cnt
def f(a,b):
    ans=0
    a=list(map(int,list(a)))
    b=list(map(int,list(b)))
    lb=len(b)
    la=len(a)
    cnt=getcnt(a)
    ans=0
    for i in range(len(b)):
        lo=max(0,i-(lb-la))
        hi=min(i+1,la)
        # print(lo,hi)
        # if lo==0:
        #     lr=[0,0]
        # else:
        lr=cnt[lo]
        rr=cnt[hi]
        t=list(map(lambda x,y:x-y,rr,lr))
        ans+=t[b[i]^1]

    return ans

s=input().strip()
t=input().strip()
print(f(s,t))


import java.io.OutputStream;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.InputStream;

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

class TaskC {
    boolean works(long left, long right, long tbites, long sizem, long A, long B){
        long heightmin = (A + B * (left - 1)), heightmax = (A + B * (right - 1));
        if(heightmax > tbites) return false;
        long avgheight = heightmax + heightmin;
        long width = (right - left + 1);
        long heightall = (long) (Math.ceil(1.0 * width * avgheight / 2));
        if(heightall > tbites * sizem) return false;
        return true;
    }

    public void solve(int testNumber, InputReader in, OutputWriter out) {
        int A=-1,B=-1, nqueries=-1;
        if(in.peek()!=-1) {A = in.readInt();} else{throw new InputMismatchException();}
        if(in.peek()!=-1) {B = in.readInt();} else{throw new InputMismatchException();}
        if(in.peek()!=-1) {nqueries = in.readInt();} else{throw new InputMismatchException();}
        for(int query = 0; query < nqueries; query++) {
            int rmin = 0, rmax = (int) 1e9;
            int left=-1, tbites=-1,sizem=-1;
            if(in.peek()!=-1) {left = in.readInt();} else{throw new InputMismatchException();}
            if(in.peek()!=-1)  {tbites = in.readInt();} else{throw new InputMismatchException();}
            if(in.peek()!=-1) {sizem = in.readInt();} else{throw new InputMismatchException();}
            while(rmin < rmax){
                int middle = (rmin + rmax + 1) / 2;
                if(works(left, middle, tbites, sizem, A, B)) rmin = middle; else rmax = middle - 1;
            }
            out.printLine((rmin < left ? -1 : rmin));
        }
    }
}

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

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

    public int read() {
        if(this.numChars == -1) {
            throw new InputMismatchException();
        } else {
            if(this.curChar >= this.numChars) {
                this.curChar = 0;

                try {
                    this.numChars = this.stream.read(this.buf);
                } catch (IOException var2) {
                    throw new InputMismatchException();
                }

                if(this.numChars <= 0) {
                    return -1;
                }
            }

            return this.buf[this.curChar++];
        }
    }

    public int peek() {
        if(this.numChars == -1) {
            return -1;
        } else {
            if(this.curChar >= this.numChars) {
                this.curChar = 0;

                try {
                    this.numChars = this.stream.read(this.buf);
                } catch (IOException var2) {
                    return -1;
                }

                if(this.numChars <= 0) {
                    return -1;
                }
            }

            return this.buf[this.curChar];
        }
    }

    public int readInt() {
        int c;
        for(c = this.read(); isSpaceChar(c); c = this.read()) {
            ;
        }

        byte sgn = 1;
        if(c == 45) {
            sgn = -1;
            c = this.read();
        }

        int res = 0;

        while(c >= 48 && c <= 57) {
            res *= 10;
            res += c - 48;
            c = this.read();
            if(isSpaceChar(c)) {
                return res * sgn;
            }
        }

        throw new InputMismatchException();
    }

    public static boolean isSpaceChar(int c) {
        return c == 32 || c == 10 || c == 13 || c == 9 || c == -1;
    }

}

class OutputWriter {
    private final OutputStream out;

    public OutputWriter(OutputStream outputStream) {
        this.out = outputStream;
    }

    public void print(Object... objects) {
        try {
            for(int e = 0; e < objects.length; ++e) {
                if(e != 0) {
                    this.out.write(32);
                }

                this.out.write(objects[e].toString().getBytes("UTF-8"));
            }

        } catch (IOException var3) {
            throw new RuntimeException(var3);
        }
    }

    public void printLine(Object... objects) {
        this.print(objects);

        try {
            this.out.write(10);
        } catch (IOException var3) {
            throw new RuntimeException(var3);
        }
    }

    public void close() {
        try {
            this.out.close();
        } catch (IOException var2) {
            throw new RuntimeException(var2);
        }
    }

}

a,b,n=map(int,input().split())
for _ in range(n):
    l,t,m=map(int,input().split())
    lo=l
    hi=100000000
    while lo<hi:
        mid=(lo+hi)//2
        count=(mid-l)+1
        first=a+(l-1)*b
        last=a+(mid-1)*b
        if last<=t and (count*(first+last))//2<=m*t:
            lo=mid+1
        else:
            hi=mid
    if mid!=lo:
        print(mid)
    else:
        count=(mid-1-l)+1
        first=a+(l-1)*b
        last=a+(mid-1-1)*b
        if last<=t and (count*(first+last))//2<=m*t and mid-1>=l:
            print(mid-1)
        else:
            print(-1)


import sys
import math as mt
#input=sys.stdin.buffer.readline
#import bisect
mod=1000000007
#t=int(input())
#tot=0
t=1

for __ in range(t):
    #n=int(input())
    n,m,k=map(int,input().split())
    x,y=1,0
    d=0
    r=1
    ch=1
    cnt1=1
    for i in range(k-1):
        print(2,end=" ")
        for j in range(2):
            if y+1<=m and mt.ceil(cnt1/m)%2!=0 and ch==1:
                y+=1
                if y==m:
                    ch=0
                print(x,y,end=" ")
            elif ch==0:
                x+=1
                ch=1
                print(x,y,end=" ")
            else:
                y-=1
                if y==1:
                    ch=0
                print(x,y,end=" ")
            cnt1+=1

        print()

    if n*m-2*(k-1)>0:
        print(n*m-2*(k-1),end=" ")
        cnt=n*m-2*(k-1)
        while cnt>0:
            if y+1<=m and mt.ceil(cnt1/m)%2!=0 and ch==1:
                y+=1
                if y==m:
                    ch=0
                print(x,y,end=" ")
            elif  ch==0:
                ch=1
                x+=1
                print(x,y,end=" ")
            else:
                y-=1
                if y==1:

                    #print(x,y,ch)
                    ch=0
                print(x,y,end=" ")
            cnt-=1
            cnt1+=1


#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<bitset<102> > cards;
  vector<int> size;
  for (int i = 0; i < n; i++) {
    int m, x;
    cin >> m;
    size.push_back(m);
    bitset<102> aux;
    for (int j = 0; j < m; j++) {
      cin >> x;
      aux[x] = true;
    }
    cards.push_back(aux);
  }
  bool flag = false;
  for (int i = 0; i < n; i++) {
    flag = false;
    bitset<102> aux;
    for (int j = 0; j < n; j++) {
      if (i == j) continue;
      aux = cards[i] & cards[j];
      int lit = aux.count();
      if (lit > 0) {
        if (size[j] - lit == 0) {
          flag = true;
          cout << "NO" << endl;
          break;
        } else if (size[i] - lit == 0 && size[j] - lit == 0) {
          flag = true;
          cout << "NO" << endl;
          break;
        }
      }
    }
    if (!flag) {
      cout << "YES" << endl;
    }
  }
  return 0;
}

NO
NO
NO
YES
NO
NO
NO
NO
NO
NO
NO
YES
NO
NO
NO
NO
NO
NO
NO
NO
YES
YES
YES
YES
NO
YES
NO
NO
NO
YES
YES
NO
NO
NO
YES
NO
YES
NO
YES
YES

YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES

n = int(input())
cards = [None] + [[] for i in range(n)]
for i in range(1, n+1):
    cards[i] = list(map(int, input().split()))[1:]
ans = [None] + [True for i in range(n)]
#print(cards, ans)
for i in range(1, n + 1):
    for j in range( 1, n + 1):
        if i == j :
            continue;
        if  set(cards[i]) & set(cards[j]) == set(cards[j]):
            ans[i] = False
o = ''
for i in range(1, len(ans)):
    if ans[i] == True:
        o += 'YES\n'
    elif ans[i] == False:
        o += 'NO\n'
print(o)


#include <bits/stdc++.h>
using namespace std;
int a[110];
int main() {
  int n;
  int mini = 0;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    if (a[mini] > a[i]) mini = i;
  }
  swap(a[mini], a[n - 1]);
  int maxi = 0;
  for (int i = 0; i < n; i++)
    if (a[maxi] < a[i]) maxi = i;
  swap(a[0], a[maxi]);
  sort(a + 1, a + n - 1);
  for (int i = 0; i < n; i++) {
    cout << a[i] << " ";
  }
  cout << endl;
  return 0;
}

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

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

        for(int i=0 ; i<n ; i++){
        int x;
        x=input.nextInt();
        arr[i]=x;
        }

        Arrays.sort(arr);
        int temp;
        temp=arr[n-1];
        arr[n-1]=arr[0];
        arr[0]=temp;

        for(int E: arr){
           System.out.print(E+" ") ;
        }

    }
}


#include <bits/stdc++.h>
using namespace std;
const long long MAXN = 1e5 + 20;
long long n;
long long vec[MAXN];
long long p[MAXN];
long long ans[MAXN];
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> n;
  for (long long i = 0; i < n; i++) cin >> vec[i];
  sort(vec, vec + n, greater<long long>());
  for (long long i = n - 1; i >= 0; i--) p[i] = (p[i + 1] + vec[i]);
  for (long long i = 1; i < n; i++) {
    ans[i] = p[1];
    long long s = i;
    for (long long j = i + 1; j < n; s *= i, j += s) ans[i] += p[j];
  }
  long long q;
  cin >> q;
  while (q--) {
    long long k;
    cin >> k;
    k = min(k, n - 1);
    cout << ans[k] << " ";
  }
  cout << endl;
  return 0;
}

n = int(input())
stones = list(map(lambda t : int(t), input().split()))
q = int(input())
queries = list(map(lambda t : int(t), input().split()))

stones.sort()

added_stones = []
added_stones.append(stones[0])
for i in range(1, n, 1):
    added_stones.append(stones[i] + added_stones[i - 1])

computed_queries = {}

for qidx, qq in enumerate(queries):
    if qq in computed_queries:
        queries[qidx] = computed_queries[qq]
        continue

    i = n - 2
    multiplier = 1
    cost = 0
    while i >= 0:
        pp = pow(qq, multiplier)
        nexti = i - pp
        if nexti < 0:
            cost += added_stones[i] * multiplier
            break
        cost += (added_stones[i] - added_stones[nexti]) * multiplier
        multiplier += 1
        i = nexti
    queries[qidx] = cost
    computed_queries[qq] = cost

print(*queries, sep=' ')


import java.util.Scanner;

public class F {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		long[][] left = new long[n][2];
		long[][] right = new long[n][2];
		int[] get = new int[n-1];
		for(int i = 0; i < n-1; i++) get[i] = scan.nextInt();
		long max = 0;
		for(int i = 1; i < n; i++) {
			int a = get[i-1];
			if(a == 1) {
				left[i][1] = Math.max(left[i-1][0], left[i-1][1])+1;
			}
			else {
				left[i][0] = left[i-1][0] + (a-(a%2));
				left[i][1] = Math.max(left[i-1][0], left[i-1][1]) + (a-((a+1)%2));
			}
		}
		for(int i = n-2; i >= 0; i--) {
			int a = get[i];
			if(a == 1) {
				right[i][1] = Math.max(right[i+1][0], right[i+1][1])+1;
			}
			else {
				right[i][0] = right[i+1][0] + (a-(a%2));
				right[i][1] = Math.max(right[i+1][0], right[i+1][1]) + (a-((a+1)%2));
			}
		}
		for(int i = 0; i < n; i++) {
			if(i == 0) {
				max = Math.max(max, Math.max(right[i][0], right[i][1]));
			}
			else if(i == n-1) {
				max = Math.max(max, Math.max(left[i][0], left[i][1]));
			}
			else {
				long a = left[i][0] + Math.max(right[i][0], right[i][1]);
				long b = right[i][0] + Math.max(left[i][0], left[i][1]);
				long c = Math.max(left[i][0], left[i][1]);
				long d = Math.max(right[i][0], right[i][1]);
				if(left[i][0] != 0) max = Math.max(max, a);
				if(right[i][0] != 0) max = Math.max(max, b);
				max = Math.max(max, Math.max(c, d));
			}
			//System.out.println(i + " " + max);
		}
		System.out.println(max);
	}

}


number_of_testcases = 1 #int(input())

for _ in range(number_of_testcases):
    number_of_digits = int(input())
    ticket_number = input()
    ticket_number = list(ticket_number)
    first_half = ticket_number[:number_of_digits]
    second_half = ticket_number[number_of_digits:]
    #print(first_half)
    first_half.sort()
    second_half.sort()
    flag = 1
    if first_half[0] > second_half[0]:
        for i in range(number_of_digits):
            if first_half[i] <= second_half[i]:
                flag = 0
                #print("NO")

    else:
        for i in range(number_of_digits):
            if first_half[i] >= second_half[i]:
                flag = 0
                #print("NO")

    if flag==1:
        print("YES")

    else:
        print("NO")

YES YES NO YES YES NO YES NO NO YES NO YES YES NO YES NO

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

public class HelloWorld{

     public static void main(String []args){

       Scanner sc = new Scanner (System.in);
       int n = sc.nextInt();
       int []A = new int[n];
       int []B= new int[n];
       String s = sc.next();

       for(int i = 0; i < n; i++){
           A[i] = s.charAt(i)-'0';
       }
       int k = 0;
       for(int i = n; i < n*2; i++){
           B[k] = s.charAt(i)-'0';
           k++;
       }

       Arrays.sort(A);Arrays.sort(B);
       int count = 0;
       int count1 = 0;

       for(int i = 0; i < n; i++){
           if(A[i] > B[i])count++;
           if(B[i] > A[i])count1++;
           }

        if(count == n || count1 == n){
            System.out.println("YES");
        }else{
            System.out.println("NO");
        }
     }
}