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

public class CodeForces {
    /*****************************************WRITING CODE STARTS HERE******************************************/
    public static void solve(int t)throws IOException {
        int n = sc.nextInt();
        int m = sc.nextInt();
        char[][] str = new char[n][];
        for(int i=0;i<n;i++)str[i] = sc.next().toCharArray();
        boolean [] remover = new boolean[m];
        for(int j=0;j<m;j++){
            for(int i=0;i<n-1;i++){
                StringBuilder curr = new StringBuilder();
                StringBuilder next = new StringBuilder();
                for(int k=0;k<=j;k++)
                    if(!remover[k]){
                        curr.append(str[i][k]);
                        next.append(str[i+1][k]);
                    }
                if(curr.compareTo(next)>0)remover[j] = true;
            }
        }
        int removeCount = 0;
        for(boolean ele : remover)if(ele)removeCount++;
        out.println(removeCount);
    }

    /*****************************************WRITING CODE ENDS HERE******************************************/

    public static void main(String[] args) throws IOException{
        int testCase = 1;
//        testCase = sc.nextInt();
        for (int i = 1; i <= testCase; i++) solve(i);
        closeIO();

    }
    static FastestReader sc = new FastestReader();              // FASTEST INPUT
    static PrintWriter out = new PrintWriter(System.out);                // FAST OUTPUT

    /**************************************HELPER FUNCTION STARTS HERE ************************************/

    public static int mod = (int) 1e9 + 7;
    public static final int inf_int = (int) 1e9;
    public static final long inf_long = (long) 1e12;

    public static final String YES = "Yes";
    public static final String NO = "No";

    public static void sort(int[] a, boolean isAscending) {
        ArrayList<Integer> temp = new ArrayList<>();
        for (int j : a) temp.add(j);
        sort(temp, isAscending);
        for (int i = 0; i < a.length; i++) a[i] = temp.get(i);
    }

    public static void sort(long[] a, boolean isAscending) {
        ArrayList<Long> temp = new ArrayList<>();
        for (long ele : a) temp.add(ele);
        sort(temp, isAscending);
        for (int i = 0; i < a.length; i++) a[i] = temp.get(i);
    }
    @SuppressWarnings({"rawtypes","unchecked"})
    public static void sort(List list, boolean isAscending) {
        if (isAscending) Collections.sort(list);
        else list.sort(Collections.reverseOrder());
    }

    // count the length of a number, time O(1)
    public static int countDigitBase10(long n) {
        if (n == 0) return 0;
        return (int) (1 + Math.log10(n));
    }

    // euclidean algorithm
    public static long gcd(long a, long b) {
        // time O(max (loga ,logb))
        long x = Math.min(a, b);
        long y = Math.max(a, b);
        if (y % x == 0) return x;
        return gcd(y % x, x);
    }

    public static long lcm(long a, long b) {
        // lcm(a,b) * gcd(a,b) = a * b
        return (a / gcd(a, b)) * b;
    }
    // binary exponentiation
    public static long power(long x, long n) {
        // time O(logn)
        long ans = 1;
        while (n > 0) {
            if ((n & 1) == 1) {
                ans *= x;
                ans %= mod;
                n--;
            } else {
                x *= x;
                x %= mod;
                n >>= 1;
            }
        }
        return ans;
    }

    public static long firstDivisor(long n) {
        if (n == 1 || n == 0) return n;
        for (long i = 2; i * i <= n; i++)
            if (n % i == 0) return i;
        return -1;
    }

    public static long max3(long a, long b, long c) {
        return max2(max2(a, b), c);
    }

    public static long max2(long a, long b) {
        return Math.max(a, b);
    }

    public static long min3(long a, long b, long c) {
        return min2(min2(a, b), c);
    }

    public static long min2(long a, long b) {
        return Math.min(a, b);
    }

    public static int max3(int a, int b, int c) {
        return max2(max2(a, b), c);
    }

    public static int max2(int a, int b) {
        return Math.max(a, b);
    }

    public static int min3(int a, int b, int c) {
        return min2(min2(a, b), c);
    }

    public static int min2(int a, int b) {
        return Math.min(a, b);
    }

    /**************************************HELPER FUNCTION ENDS HERE ************************************/

    /*****************************************FAST INPUT STARTS HERE *************************************/

    public static void closeIO() throws IOException{
            out.flush();
            out.close();
            sc.close();
    }
    private static class FastestReader {
        private static final int BUFFER_SIZE = 1 << 16;
        private final DataInputStream din;
        private final byte[] buffer;
        private int bufferPointer, bytesRead;

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

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

        private static boolean isSpaceChar(int c) { return !(c >= 33 && c <= 126); }

        private int skip() throws IOException {
            int b;
            //noinspection StatementWithEmptyBody
            while ((b = read()) != -1 && isSpaceChar(b)) {}
            return b;
        }

        public String next() throws IOException {
            int b = skip();
            final StringBuilder sb = new StringBuilder();
            while (!isSpaceChar(b)) { // when nextLine, (isSpaceChar(b) && b != ' ')
                sb.appendCodePoint(b);
                b = read();
            }
            return sb.toString();
        }

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

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

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

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

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

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

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

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

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

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

    }
    /*****************************************FAST INPUT ENDS HERE *************************************/
}

9 7
ygqartj
lgwxlqv
ancjjpr
wnnhkpx
cnnhvty
xsfrbqp
xsolyne
bsoojiq
xstetjb

import sys,heapq,math
from collections import defaultdict,deque
input=sys.stdin.readline

r,c=map(int,input().split())
grid=[]
for i in range(r):
    grid.append(input().strip())
equal=[0 for _ in range(c)]
less=[0 for _ in range(c)]
for i in range(c):
    for row in range(1,r):
        if(grid[row-1][i]==grid[row][i]):
            equal[i]=1
        elif(grid[row-1][i]>grid[row][i]):
            equal[i]=0
            break
    less[i]=1
    for row in range(1,r):
        if(equal[i]==1):
            less[i]=0
            break
        elif(grid[row-1][i]>grid[row][i]):
            less[i]=0
            break
ans=0
for i in range(c):
    if(less[i]==1):
        ans=max(ans,c-i)
        break
    elif(equal[i]==1):
        cnt=1
        l=[]
        for row in range(1,r):
            if(grid[row-1][i]==grid[row][i]):
                start=row-1
                while(row<r and grid[row-1]==grid[row][i]):
                    row+=1
                end=row
                l.append([start,end])

        for col in range(i+1,c):
            f=0
            ptr=0
            while(ptr<len(l)):
                start,end=l[ptr]
                ptr+=1
                for row in range(start+1,end+1):
                    if(grid[row-1][col]>grid[row][col]):
                        f=1
                        break
                if(f==1):
                    break
            if(f==0):
                cnt+=1
                ptr=0
                nl=[]
                while(ptr<len(l)):
                    start,end=l[ptr]
                    ptr+=1
                    for row in range(start+1,end+1):
                        if(grid[row-1][col]==grid[row][col]):
                            s1=row-1
                            while(row<end+1 and grid[row-1]==grid[row][col]):
                                row+=1
                            e1=row
                            nl.append([s1,e1])
                l=nl
        ans=max(ans,cnt)

print(c-ans)


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

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

    public static void main(String[] args) throws IOException {
        BufferedReader input = new BufferedReader(new InputStreamReader(System.in));
        //int testcases = Integer.parseInt(input.readLine());
        StringTokenizer line = new StringTokenizer(input.readLine());
        int n = Integer.parseInt(line.nextToken());
        int k = Integer.parseInt(line.nextToken());
        int per[]= new int[n];
        line = new StringTokenizer(input.readLine());
        for (int i = 0; i < n; i++) {
            per[i]= Integer.parseInt(line.nextToken());
        }
        Arrays.sort(per);
        long count = 0;
        for (int i = per.length-1; i >= 0; i-=k) {
            count+=(per[i]-1)*2;
        }
        System.out.println(count);
    }
}

n, k = map(int, input().split())
arr = list(map(int, input().split()))
arr.sort()
ans = 0
p = 1
i = 0
while n != 0:
    tp = arr[i]
    ans += 2 * (tp - p) * (round(n / k + 0.49999999999999))
    while n != 0 and arr[i] == tp:
        n -= 1
        i += 1
    p = tp
print(ans)


import math
n,k=map(int,input().split())
l=list(map(int,input().split()))
for i in range(n):
    l[i]=math.ceil(l[i]/k)
f=max(l)
for i in range(n-1,-1,-1):
    if f==l[i]:
        print(i+1)
        break

#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m, a[100], temp = -1, max = -1, li = -1;
  scanf("%d %d", &n, &m);
  for (int i = 0; i < n; i++) {
    scanf("%d", &a[i]);
    temp = ceil((float)a[i] / m);
    if (temp >= max && i > li) {
      max = temp;
      li = i;
    }
  }
  printf("%d", li + 1);
  return 0;
}


#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  set<int> positions;
  for (int i = 0; i < n; i++) {
    string row;
    cin >> row;
    int s_pos = -1;
    int g_pos = -1;
    for (int j = 0; j < m; j++) {
      if (row[j] == 'G') {
        g_pos = j;
      } else if (row[j] == 'S') {
        s_pos = j;
      }
      if (g_pos != -1 && s_pos != -1) {
        break;
      }
    }
    int diff = s_pos - g_pos;
    if (diff < 0) {
      cout << -1;
      return 0;
    }
    positions.insert(diff);
  }
  cout << positions.size();
  return 0;
}

n, m = (int(x) for x in input().split())
st = set()
for i in range(n):
	s = input()
	g = s.index('G')
	s = s.index('S')
	if g > s:
		print(-1)
		exit(0)
	st.add(s - g)
print(len(st))


import java.util.*;

public class x79B {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        StringBuilder SB = new StringBuilder("YES\n");
        int N = sc.nextInt();
        Stack<StringBuilder> x = new Stack<StringBuilder>();
        Stack<StringBuilder> y = new Stack<StringBuilder>();
        int[] nums = new int[N];
        int[] sorted = new int[N];
        //int[][] insort = new int[N][2];
        for (int a = 0; a < N; a++) {
            nums[a] = sc.nextInt();
            sorted[a] = nums[a];
        //  insort[a][0]=nums[a];
    //      insort[a][1]=a;
    //      System.out.print(insort[a][0]+" ");
        //  System.out.println(insort[a][1]);
        }
        Arrays.sort(sorted);
    //  Arrays.sort(insort);
        //for (int a = 0; a < N; a++) {
        //  System.out.print(insort[a][0]+" ");
            //System.out.println(insort[a][1]);
        //}

        int largest = sorted[N - 1];
        String[] master = new String[N];
        int done = 0;
        StringBuilder zero = new StringBuilder("0");
        StringBuilder one = new StringBuilder("1");
        x.add(one);
        x.add(zero);
        for (int a = 1; a <= largest; a++) {
            int q = x.size();
            if (x.size()<N-done&&a != 1) {

                for (int c = 0; c < q; c++) {
                    StringBuilder temp =  x.pop();
                    StringBuilder temp2 =  new StringBuilder(temp.toString());
                    y.add(temp2.append("1"));
                    y.add(temp.append("0"));

                }
                q = y.size();
                for (int c = 0; c < q; c++) {
                    x.add(y.pop());
                }
            }
            int z = 0;
                while (sorted[done] == a) {
                    if(x.isEmpty()){
                        System.out.print("NO");
                        System.exit(0);
                    }
                    for(int e=0;e<N;e++){
                        if(nums[e]==a){
                            z=e;
                            break;
                        }
                    }
                    StringBuilder temp = x.pop();
                    for(int t=temp.length();t<a;t++){
                        temp.append("0");
                    }
                    master[z] = temp.toString();
                    nums[z] = -1;
                    done++;
                    if(done==N)break;
                }

        }
        for (int b = 0; b < N; b++) {
            SB.append(master[b] + "\n");
        }
        System.out.print(SB.toString());

        System.exit(0);
    }
}

#!/usr/bin/python3

counts = [0]*1024
for x in range(len(counts)): counts[x] = []
N = int(input())
x = [int(t) for t in input().strip().split()]
for i,t in enumerate(x): counts[t].append(i)

curr = 0
ans = [0]*N
for i in range(1,1024):
	while len(counts[i]) > 0:
		x = bin(curr)[2:]
		if len(x) > i:
			print("NO")
			exit(0)
		else: x = "0"*(i-len(x)) + x
		ans[counts[i].pop()] = x
		curr += 1
	curr = 2*curr
print("YES")
print("\n".join(ans))


#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, k;
  cin >> n >> k;
  long long ct = (n * (n - 1)) / 2;
  if (k >= ct)
    cout << "no solution\n";
  else {
    long long x = 0, y = 0;
    long long incr = 1;
    for (int e = 0; e < n; e++) {
      cout << x << " " << y << endl;
      y++;
    }
  }
  return 0;
}

import java.util.*;
public class cf311a {
  public static void main(String[] args) {
    Scanner in = new Scanner(System.in);
    int n = in.nextInt();
    int k = in.nextInt();
    int max = (n*n-n)/2;
    if(max <= k)
      System.out.println("no solution");
    else for(int i=0; i<n; i++)
      System.out.println(0+" "+i);
  }
}


import java.util.Comparator;
import java.io.BufferedReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.Collection;
import java.util.List;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.ArrayList;
import java.util.StringTokenizer;
import java.math.BigInteger;
import java.util.Collections;
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);
		TaskA solver = new TaskA();
		solver.solve(1, in, out);
		out.close();
	}
}

class TaskA {
    public void solve(int testNumber, InputReader in, PrintWriter out) {
        int n = in.nextInt();
        if (n == 1) {
            out.println(1);
            return;
        }
        if (n % 4 == 3 || n % 4 == 2) {
            out.println(-1);
            return;
        }
        int[] p = new int[n];
        rec(p, 0, p.length-1, 1, p.length);
        out.println(ArrayUtils.toString(p));
    }

    private void rec(int[] p, int le, int ri, int low, int high) {
        if (le == ri) {
            p[le] = low;
            return;
        }
        if (le > ri) {
            return;
        }
        p[le] = low + 1;
        p[le + 1] = high;
        p[ri] = high-1;
        p[ri-1] = low;
        rec(p, le + 2, ri - 2, low + 2, high - 2);
    }
}

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

}

class ArrayUtils {

    public static String toString(int[] a) {
        StringBuilder result = new StringBuilder("");
        for (int x : a) result.append(x).append(' ');
        return result.substring(0, result.length()-1);
    }

}

n=int(input())
if(n%4>1):
    print(-1)
else:
    ans=[0]*(n+1)
    i,j,a,b=1,n,1,n
    while(i<j and a<=n and b>=1):
        ans[i],ans[j]=a+1,b-1
        ans[i+1],ans[j-1]=b,a
        i+=2
        j-=2
        a+=2
        b-=2
    if(i==j):
        ans[i]=a
    for i in range(1,n+1):
        print(ans[i],end=' ')


#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:102400000,102400000")
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  int ret = 0;
  while (n--) {
    char str[1009];
    int cnt = 0;
    scanf("%s", str);
    int flag = 1;
    for (int i = 0; str[i]; i++) {
      if (str[i] == '4' || str[i] == '7') {
        cnt++;
        if (cnt > m) {
          flag = 0;
          break;
        }
      }
    }
    if (flag == 1) {
      ret++;
    }
  }
  cout << ret << endl;
  return 0;
}

import java.util.Scanner;

/**
 *
 * @author takhi
 */
public class numbers_262A {
    public static void main(String args[]){
        Scanner sc=new Scanner(System.in);
        int n=sc.nextInt();
        int k=sc.nextInt();
        int count=0;
        int lucky=0;
        int rem=0;
        while(n-->0){
            int x=sc.nextInt();
            int num=x;
            while(num>0){
                rem=num%10;
                if(rem==4||rem==7){
                    count++;
                }
                num=num/10;
            }
            if(count<=k){
                lucky++;
            }
            count=0;
        }
        System.out.println(lucky);

    }
}


#include <bits/stdc++.h>
using namespace std;
const int M = 1e6 + 5;
int a, b, k, t, p[M], mark[M], sum[M];
void init() {
  int N = 1e6;
  for (int i = 2; i <= N; i++) {
    if (mark[i] == 0) p[++t] = i;
    for (int j = 1; p[j] * i <= N; j++) {
      mark[p[j] * i] = 1;
      if (i % p[j] == 0) break;
    }
  }
  for (int i = 2; i <= N; i++) {
    sum[i] = sum[i - 1];
    if (mark[i] == 0) sum[i]++;
  }
}
int judge(int x) {
  for (int i = a; i <= b - x + 1; i++) {
    int j = i + x - 1;
    if (sum[j] - sum[i - 1] < k) return 0;
  }
  return 1;
}
int main() {
  init();
  scanf("%d%d%d", &a, &b, &k);
  int le = 1, ri = b - a + 1, ans = -1;
  while (le <= ri) {
    int mid = le + ri >> 1;
    if (judge(mid)) {
      ans = mid;
      ri = mid - 1;
    } else
      le = mid + 1;
  }
  printf("%d", ans);
  return 0;
}


#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  long long a, d, b, c, i, j, k, l, m, t, x, y, n, z;
  string s;
  cin >> n;
  long long a1[n], a2[n], a3[n];
  for (i = 0; i < n; i++) cin >> a1[i];
  a2[0] = a1[0];
  a3[n - 1] = a1[n - 1];
  for (i = 1; i < n; i++) a2[i] = a2[i - 1] + a1[i];
  for (i = n - 2; i >= 0; i--) a3[i] = a3[i + 1] + a1[i];
  d = 0;
  for (i = 0; i < n - 1; i++) {
    if (a2[i] == a3[i + 1]) d++;
  }
  cout << d << endl;
  return 0;
}

n=int(input())
l=list(map(int,input().split()))
s=[0]*n
for i in range(n):
    if i==0:
        s[i]=l[i]
    else:
        s[i]=l[i]+s[i-1]
ans=0
for i in range(1,n):
    if s[i-1]==s[-1]-s[i-1]:
        ans=ans+1
print(ans)


#include <bits/stdc++.h>
using namespace std;
const int MAXN = 2e5 + 5;
int n;
int cnt[2];
vector<int> Adj[MAXN];
void DFS(int node, int p, int c) {
  cnt[c]++;
  for (auto x : Adj[node]) {
    if (x == p) {
      continue;
    }
    DFS(x, node, 1 - c);
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  for (int i = 1; i < n; i++) {
    int u, v;
    cin >> u >> v;
    Adj[u].push_back(v);
    Adj[v].push_back(u);
  }
  DFS(1, -1, 0);
  cout << min(cnt[0], cnt[1]) - 1;
}

import sys
input = sys.stdin.readline
n=int(input())
graph=[[] for _ in range(n)]
for j in range(n-1):
    x,y=map(int,input().split())
    x-=1
    y-=1
    graph[x].append(y)
    graph[y].append(x)

color=[-1]*n
tem=[0]
visit=[0]*n
color[0]=0

while(tem!=[]):
    x=tem.pop()
    for i in graph[x]:
        if(color[i]==-1):
            visit[i]=1
            color[i]=1-color[x]
            tem.append(i)
k=color.count(1)

print(min(k,n-k)-1)


n = int(input())
c = 0
while n>0:
    c += 1/n
    n -= 1
print(c)

import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
import java.io.Writer;
import java.io.OutputStreamWriter;
import java.io.BufferedReader;
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);
        TaskB solver = new TaskB();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskB {
        public void solve(int testNumber, InputReader in, OutputWriter out) {
            int N = in.nextInt();
            double ans = 0;
            for (int i = 1; i <= N; i++) {
                ans += 1.0 / i;
            }
            out.printLine(ans);
        }

    }

    static class OutputWriter {
        PrintWriter writer;

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

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

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

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

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

    }

    static class InputReader {
        BufferedReader in;
        StringTokenizer tokenizer = null;

        public InputReader(InputStream inputStream) {
            in = new BufferedReader(new InputStreamReader(inputStream));
        }

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

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

    }
}


#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC optimize("no-stack-protector")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("fast-math")
#pragma GCC target("sse,sse2,sse3,ssse3,popcnt,abm,mmx,tune=native")
using namespace std;
template <typename T>
void uin(T &a, T b) {
  if (b < a) {
    a = b;
  }
}
template <typename T>
void uax(T &a, T b) {
  if (b > a) {
    a = b;
  }
}
const long long N = 100 * 1000 + 228;
long long p[N];
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  long long n, m, k;
  cin >> n >> m >> k;
  for (long long i = 1; i <= m; ++i) cin >> p[i];
  long long mod = 0;
  long long i = 1;
  long long moves = 0;
  while (i <= m) {
    long long page = (p[i] - mod + k - 1) / k;
    long long cnt = 0;
    while (i <= n && (p[i] - mod + k - 1) / k == page) {
      ++i;
      ++cnt;
    }
    mod += cnt;
    ++moves;
  }
  cout << moves << '\n';
  return 0;
}

import java.util.Scanner;

public class A1190 {

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        long N = in.nextLong();
        int M = in.nextInt();
        long K = in.nextLong();
        long[] P = new long[M];
        for (int m=0; m<M; m++) {
            P[m] = in.nextLong();
        }
        long answer = 0;
        int pIdx = 0;
        long pStart = 1;
        while (pIdx < M) {
            long p = P[pIdx];
            pStart += K*((p-pStart)/K);
            int shift = 0;
            while (pIdx < M && P[pIdx] < pStart + K) {
                pIdx++;
                shift++;
            }
            answer++;
            pStart += shift;
        }
        System.out.println(answer);
    }

}


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

public class Solution
{

	public static int findMinRec(int arr[], int i,
            int sumCalculated,
             int sumTotal)
{
if (i == 0)
return Math.abs((sumTotal-sumCalculated) -
               sumCalculated);

return Math.min(findMinRec(arr, i - 1, sumCalculated
               + arr[i-1], sumTotal),
             findMinRec(arr, i-1,
              sumCalculated, sumTotal));
}

public static int findMin(int arr[], int n)
{

int sumTotal = 0;
for (int i = 0; i < n; i++)
sumTotal += arr[i];

return findMinRec(arr, n, 0, sumTotal);
}

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

		int arr[]=new int[n];

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

		Arrays.sort(arr);

		int d=y-x;
		if(d<0)
			{
			pw.println(n);
			pw.flush();
			pw.close();

			}
		else
		{
		int count=0;
		ArrayList<Integer>al=new ArrayList<>();
		for(int i=0;i<n;i++)
		{
			if(arr[i]<=x)
				count++;
		}
		if(count%2==1)
			count=(count/2)+1;
		else
			count/=2;
		pw.println(count);
		pw.flush();
		pw.close();}
	}

	static class InputReader
	{

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

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

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

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

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

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

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

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

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

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

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

	public static long mod = 1000000007;
	public static int d;
	public static int p;
	public static int q;

	public static int[] suffle(int[] a,Random gen)
	{
		int n = a.length;
		for(int i=0;i<n;i++)
		{
			int ind = gen.nextInt(n-i)+i;
			int temp = a[ind];
			a[ind] = a[i];
			a[i] = temp;
		}
		return a;
	}

	public static void swap(int a, int b){
		int temp = a;
		a = b;
		b = temp;
	}

	public static HashSet<Integer> primeFactorization(int n)
	{
		HashSet<Integer> a =new HashSet<Integer>();
		for(int i=2;i*i<=n;i++)
		{
			while(n%i==0)
			{
				a.add(i);
				n/=i;
			}
		}
		if(n!=1)
			a.add(n);
		return a;
	}

	public static void sieve(boolean[] isPrime,int n)
	{
		for(int i=1;i<n;i++)
			isPrime[i] = true;

		isPrime[0] = false;
		isPrime[1] = false;

		for(int i=2;i*i<n;i++)
		{
			if(isPrime[i] == true)
			{
				for(int j=(2*i);j<n;j+=i)
					isPrime[j] = false;
			}
		}
	}

	public static int GCD(int a,int b)
	{
		if(b==0)
			return a;
		else
			return GCD(b,a%b);
	}

	public static long GCD(long a,long b)
	{
		if(b==0)
			return a;
		else
			return GCD(b,a%b);
	}

	public static void extendedEuclid(int A,int B)
	{
		if(B==0)
		{
			d = A;
			p = 1 ;
			q = 0;
		}
		else
		{
			extendedEuclid(B, A%B);
			int temp = p;
			p = q;
			q = temp - (A/B)*q;
		}
	}

	public static long LCM(long a,long b)
	{
		return (a*b)/GCD(a,b);
	}

	public static int LCM(int a,int b)
	{
		return (a*b)/GCD(a,b);
	}

	public static int binaryExponentiation(int x,int n)
	{
	    int result=1;
	    while(n>0)
	    {
	        if(n % 2 ==1)
	            result=result * x;
	        x=x*x;
	        n=n/2;
	    }
	    return result;
	}

	public static long binaryExponentiation(long x,long n)
	{
	    long result=1;
	    while(n>0)
	    {
	        if(n % 2 ==1)
	            result=result * x;
	        x=x*x;
	        n=n/2;
	    }
	    return result;
	}

	public static int modularExponentiation(int x,int n,int M)
	{
	    int result=1;
	    while(n>0)
	    {
	        if(n % 2 ==1)
	            result=(result * x)%M;
	        x=(x*x)%M;
	        n=n/2;
	    }
	    return result;
	}

	public static long modularExponentiation(long x,long n,long M)
	{
	    long result=1;
	    while(n>0)
	    {
	        if(n % 2 ==1)
	            result=(result * x)%M;
	        x=(x*x)%M;
	        n=n/2;
	    }
	    return result;
	}

	public static int modInverse(int A,int M)
	{
	    return modularExponentiation(A,M-2,M);
	}

	public static long modInverse(long A,long M)
	{
	    return modularExponentiation(A,M-2,M);
	}

	public static boolean isPrime(int n)
	{

	    if (n <= 1)  return false;
	    if (n <= 3)  return true;

	    if (n%2 == 0 || n%3 == 0)
	    	return false;

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

	    return true;
	}

	static class pair implements Comparable<pair>
	{
		Integer x, y;
		pair(int x,int y)
		{
			this.x=x;
			this.y=y;
		}

		public int compareTo(pair o) {
			int result = x.compareTo(o.x);
			if(result==0)
				result = y.compareTo(o.y);

			return result;
		}

		public String toString()
		{
			return x+" "+y;
		}

		public boolean equals(Object o)
		{
			if (o instanceof pair)
		    {
				pair p = (pair)o;
				return (Math.abs(p.x-x)==0 && Math.abs(p.y-y)==0);
			}
			return false;
		}

		public int hashCode()
		{
			return new Long(x).hashCode()*31 + new Long(y).hashCode();
		}
	}
}

#include <bits/stdc++.h>
using namespace std;
int n, x, y;
int a[105];
int main() {
  cin >> n >> x >> y;
  for (int i = 0; i < n; i++) scanf("%d", &a[i]);
  if (y < x) {
    printf("%d", n);
    return 0;
  }
  if (x <= y) {
    int cnt = 0;
    for (int i = 0; i < n; i++)
      if (a[i] <= x) cnt++;
    printf("%d", (cnt + 1) / 2);
  }
  return 0;
}


#include <bits/stdc++.h>
using namespace std;
int a[100005];
int main() {
  int i, n, k, m, v, t, mx = 0;
  long long s = 0, x, cnt = 0, y;
  scanf("%d %d", &n, &m);
  for (i = 0; i < n; i++) {
    scanf("%d", &a[i]);
    s += a[i];
    mx = max(mx, a[i]);
  }
  x = s - n;
  sort(a, a + n);
  int pos = 0;
  for (i = 0; i < n; i++) {
    cnt++;
    if (a[i] > pos) pos++;
  }
  cnt += (mx - pos);
  cout << s - cnt;
}

n,m=map(int,input().split(' '))
a=list(map(int,input().split(' ')))
a.sort()
count=0
prev=0
for i in range(n):
    count+=1
    if a[i]>prev:
        prev+=1
count+=a[n-1]-prev
print(sum(a)-count)


#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  string a, b, result;
  int nb = 0;
  cin >> t >> a >> b;
  for (int i = b.size() - 1; i >= 0; i--) {
    int j = 0;
    for (; j <= i && b[i] != a[j]; j++)
      ;
    if (j == i + 1) {
      nb = -1;
      break;
    }
    for (; j < i; j++) {
      nb++;
      result += to_string(j + 1) + " ";
      char temp = a[j];
      a[j] = a[j + 1];
      a[j + 1] = temp;
    }
  }
  if (nb != -1)
    cout << nb << endl << result << endl;
  else
    cout << nb << endl;
  return 0;
}

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.*;
public class C {
    static class FastScanner {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st = new StringTokenizer("");

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

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

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

        long nextLong() {
            return Long.parseLong(next());
        }
    }
    static class FastWriter extends PrintWriter {
        FastWriter() {
            super(System.out);
        }

        void println(int[] array) {
            for (int i = 0; i < array.length; i++) {
                print(array[i] + " ");
            }
            println();
        }

        void println(long[] array) {
            long ans[]=new long[10];
            for (int i = 0; i < array.length; i++) {
                print(array[i] + " ");
            }
            println();
        }
    }
    public static void main(String[] args) {
        // Yo bitch !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
        FastScanner in = new FastScanner();
        FastWriter out = new FastWriter();
        int n=in.nextInt();
        char[] s1=in.next().toCharArray();
        char[] s2=in.next().toCharArray();
        boolean flag=true;
        ArrayList<Integer> list=new ArrayList<>();
        for (int i = 0; i < n; i++) {
            if(s1[i]!=s2[i]){
                int ind=-1;
                for(int j=i+1;j<n;j++){
                    if(s1[j]==s2[i]){
                        ind=j;
                        break;
                    }
                }
                if(ind==-1){
                    System.out.println("-1");
                    return;
                }
                for (int j = ind-1; j >=i ; j--) {
                    list.add(j+1);
                    char ch=s1[j];
                    s1[j]=s1[j+1];
                    s1[j+1]=ch;
                }
            }
        }
        out.println(list.size());
        for (int i = 0; i < list.size(); i++) {
            out.print(list.get(i)+" ");
        }
        out.println();
        out.close();
    }
}


#include <bits/stdc++.h>
using namespace std;
int a[22 + 1], sortat[22 + 1];
int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
    sortat[i] = a[i];
  }
  sort(sortat, sortat + n);
  for (int i = 0; i < n; ++i) {
    int k = 0;
    while (sortat[k] < a[i]) ++k;
    k = (k + 1) % n;
    cout << sortat[k] << " ";
  }
  cout << "\n";
  return 0;
}

import sys
input()
a = list(map(int, input().split()))
b = sorted(a)
for i in a:
	sys.stdout.write(str(b[b.index(i)-1]))
	sys.stdout.write(" ")
sys.stdout.write("\n")


/*
 * PDPM IIITDM Jabalpur
 * Asutosh Rana
 */

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

public class Main
{
    static long MOD = 1000000007;
    public static void main (String[] args) throws java.lang.Exception
	{
		InputReader in=new InputReader(System.in);
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        PrintWriter out=new PrintWriter(System.out);

        int t = 1;

        while(t-->0){
        	char[] S = in.readCharA();
        	int started = 0;
        	for(int i=0;i<S.length;i++){
        		if(S[i]!='a'){
        			started = 1;
        			S[i]--;
        		}
        		else if(started==1){
        			break;
        		}
        	}
        	if(started==0)
        		S[S.length-1]='z';
        	out.println(String.valueOf(S));
		}
		out.flush();
        out.close();
	}

    static class Point{
    	long x,y,z;
    	public Point(long x,long y,long z){
    		this.x=x;this.y=y;this.z=z;
    	}
    }

    static Point gen(long[][] A, Point P){
    	long a = A[0][0]*P.x+A[0][1]*P.y+A[0][2]*P.z;
    	long b = A[1][0]*P.x+A[1][1]*P.y+A[1][2]*P.z;
    	long c = A[2][0]*P.x+A[2][1]*P.y+A[2][2]*P.z;
    	return new Point(a,b,c);
    }
}

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

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

	public 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 void readInt(int[] A){
		for(int i=0;i<A.length;i++)
			A[i] = readInt();
	}

	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 void readLong(long[] A){
		for(int i=0;i<A.length;i++)
			A[i] = readLong();
	}

	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 == 'e' || c == 'E')
				return res * Math.pow(10, readInt());
			if (c < '0' || c > '9')
				throw new InputMismatchException();
			res *= 10;
			res += c - '0';
			c = read();
        }
		if (c == '.') {
			c = read();
			double m = 1;
			while (!isSpaceChar(c)) {
				if (c == 'e' || c == 'E')
					return res * Math.pow(10, readInt());
				if (c < '0' || c > '9')
					throw new InputMismatchException();
				m /= 10;
				res += (c - '0') * m;
				c = read();
            }
        }
		return res * sgn;
    }

	public char[] readCharA(){
		return readString().toCharArray();
	}

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

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

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

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

}

import sys
n=input()
i=0
n=n+'a'
m=""
while n[i]=='a' and len(n)>i+1:
    i+=1
    m=m+'a'
if i+1==len(n):
    w=m[0:len(m)-1]+'z'
    print(w)
    sys.exit()
while n[i]!='a' and len(n)>i:
    m=m+chr(ord(n[i])-1)
    i+=1
m=m+n[i:len(n)-1]

print(m)


#include <bits/stdc++.h>
using namespace std;
int main() {
  double l, q, p, t1;
  cin >> l >> p >> q;
  t1 = l / (q + p);
  cout << 3 * l / (q + p) * p - 2 * t1 * p << "\n";
  return 0;
}

l=int(input())
p=int(input())
q=int(input())
v=p+q
t=l/v
d=p*t
print(d)


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

public class C
{
	String line;
	StringTokenizer inputParser;
	BufferedReader is;
	FileInputStream fstream;
	DataInputStream in;

	void openInput(String file)
	{

		if(file==null)is = new BufferedReader(new InputStreamReader(System.in));//stdin
		else
		{
			try{

			fstream = new FileInputStream(file);
			in = new DataInputStream(fstream);
			is = new BufferedReader(new InputStreamReader(in));
			}catch(Exception e)
			{
				System.err.println(e);
			}
		}

	}

	void readNextLine()
	{
		try {
			line = is.readLine();
			inputParser = new StringTokenizer(line, " ");
			//System.err.println("Input: " + line);
		} catch (IOException e) {
			System.err.println("Unexpected IO ERROR: " + e);
		}

	}

	int NextInt()
	{
		String n = inputParser.nextToken();
		int val = Integer.parseInt(n);

		//System.out.println("I read this number: " + val);
		return val;
	}

	String NextString()
	{
		String n = inputParser.nextToken();
		return n;
	}

	void closeInput()
	{
		try {
			is.close();
		} catch (IOException e) {
			System.err.println("Unexpected IO ERROR: " + e);
		}

	}

	public static void main(String [] argv)
	{
		String filePath=null;
		if(argv.length>0)filePath=argv[0];
		C c = new C(filePath);
	}
	long [] f = new long[70];

	public C(String inputFile)
	{
		long ret=0;
		openInput(inputFile);

		readNextLine();
		int N=line.length();
		ArrayList <Worker> list = new ArrayList <Worker>();

		f[0]=1;
		for(int i=1; i<70; i++)f[i]=i*f[i-1];
		//System.out.println(f[69]);

		String n="";
		Worker up=null;
		String el=":.,";
		for(int i=0; i<N; i++)
		{
			if(el.indexOf(line.charAt(i))>-1)
			{
				if(n.length()>0)
				{
					Worker w=new Worker (n, up);

					list.add(w);
					up=w;
					n="";
				}

				switch(line.charAt(i))
				{
					case ':':
						break;
					case '.':
						up=up.up;
						break;
					case ',':
						break;
				}

			}
			else n+=line.charAt(i);

		}

		for(int i=0; i<list.size(); i++)
		{
			//long nn=list.get(i).getNum(list.get(i).name);
			//System.out.println(list.get(i).name+" "+nn);
			ret+=list.get(i).getNum(list.get(i).name);
		}
		//ret/=2;

		System.out.println(ret);

        closeInput();
	}

	class Worker
	{
		Worker up;
		ArrayList <Worker> down;
		String name;
		long myNum=-1;

		Worker(String n, Worker chef)
		{
			up=chef;
			name=n;
			down = new ArrayList<Worker>();
			if(chef!=null)chef.addSub(this);
		}

		void addSub(Worker w)
		{
			down.add(w);
		}

		long getNum(String s)
		{
			//if(myNum>-1)return myNum;
			long ret=0;
			for(int i=0; i<down.size(); i++)
			{
				if(down.get(i).name.compareTo(s)==0)
				{
					ret++;

				}
				ret+=down.get(i).getNum(s);
			}
			myNum=ret;
			return ret;
		}
	}

}

#!/usr/bin/env python3

tree = input().strip()

def get_answer(tree, start_index = 0, prev = []):
  colon_index = tree.find(':', start_index)
  period_index = tree.find('.', start_index)
  name_end_index = colon_index if ((colon_index != -1) and (colon_index < period_index)) else period_index
  name = tree[start_index:name_end_index]
  answer = prev.count(name)
  if ((colon_index == -1) or (period_index < colon_index)):
    return (answer, period_index+1)
  else:
    # Recurse
    prev_names = prev + [name]
    next_start = colon_index
    while tree[next_start] != '.':
      (sub_answer, next_start) = get_answer(tree, next_start+1, prev_names)
      answer += sub_answer
    return (answer, next_start+1)

print(get_answer(tree)[0])


#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  char s[16];
  string two = "2";
  string three = "3";
  string four = "322";
  string five = "5";
  string six = "53";
  string seven = "7";
  string eight = "7222";
  string nine = "7332";
  cin >> n;
  cin >> s;
  string ans;
  int r;
  for (int i = 0; i < strlen(s); i++) {
    r = s[i] - 48;
    switch (r) {
      case 2:
        ans = ans + two;
        break;
      case 3:
        ans = ans + three;
        break;
      case 4:
        ans = ans + four;
        break;
      case 5:
        ans = ans + five;
        break;
      case 6:
        ans = ans + six;
        break;
      case 7:
        ans = ans + seven;
        break;
      case 8:
        ans = ans + eight;
        break;
      case 9:
        ans = ans + nine;
        break;
      default:
        break;
    }
  }
  sort(ans.begin(), ans.end());
  reverse(ans.begin(), ans.end());
  cout << ans;
}

import java.util.*;

public class C_292 {

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

        String s = inp.nextLine();
        s = inp.nextLine();
        Operation ops = new Operation();

        char output[];
        try
        {
        output = ops.output(s);
        }
        catch(Exception e)
        {
            e.printStackTrace();
            return;
        }

        for(int i=0;i<output.length;i++)
        System.out.print(output[i]);

        System.out.println();
    }

}

class Operation
{
    public char[] output(String s)
    {
        String ou ="";

        for(int i=0;i<s.length();i++)
        {
            int t= s.charAt(i)-'0';

            if(t==0 ||t ==1)
                continue;
            else if(t==2||t==3||t==5||t==7)
                ou = ou+ t;
            else if(t==4)
            {
                ou = ou+"322";
            }
            else if(t==6)
            {
                ou = ou+"53";
            }
            else if(t==8)
                ou = ou+"7222";
            else if(t==9)
                ou = ou+"7332";

        }

        char []out = ou.toCharArray();
        //System.out.println(out.length);

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

        char pa[] = new char[out.length];
        for(int i=0;i<pa.length;i++)
        {
            pa[i]=out[i];
        }

        return pa;

    }
    }


n,l=map(int,input().split())
a=list(map(int,input().split()))
a.sort()
max=0
for i in range(len(a)-1):
    if a[i+1]-a[i]>max:
        max=a[i+1]-a[i]
if a[0]>=max/2 and a[0]>=l-a[len(a)-1]:
    print("%.10f"%(a[0]))
elif l-a[len(a)-1]>=max/2 and l-a[len(a)-1]>=a[0]:
    print("%.10f"%(l-a[len(a)-1]))
elif max/2>=l-a[len(a)-1] and max/2>=a[0]:
    print("%.10f"%(max/2))

import java.util.Scanner;
public class Test {

	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		int n=sc.nextInt();
		int l=sc.nextInt();
		double[]arr=new double[n+2];
		arr[0]=0;
		arr[n+1]=l;
		for(int i=1;i<n+1;i++){
			arr[i]=sc.nextInt();
		}
		for(int i=0;i<n+2;i++){
			for(int j=0;j<n+1-i;j++){
				if(arr[j]>arr[j+1]){
					double temp=arr[j];
					arr[j]=arr[j+1];
					arr[j+1]=temp;
				}
			}
		}
		double maxdiff=0;
		for(int i=1;i<n;i++){
			if((arr[i+1]-arr[i])>maxdiff) maxdiff=arr[i+1]-arr[i];
		}
		double a=maxdiff/2;
		if(arr[1]==0&&arr[n]==l) a=maxdiff/2;
		else if(arr[1]==0&&arr[n+1]-arr[n]>a) a=arr[n+1]-arr[n];
		else if(arr[n]==l&&arr[1]-arr[0]>a) a=arr[1];
		else if(arr[1]!=0&&arr[n]!=l&&arr[1]-arr[0]>a&&arr[n+1]-arr[n]<arr[1]-arr[0]) a=arr[1];
		else if(arr[1]!=0&&arr[n]!=l&&arr[n+1]-arr[n]>a) a=arr[n+1]-arr[n];
		System.out.println(a);
	}

}


n, p, k = map(int, input().split())
x = 0
close_symbol = True
pages = ""
if((p-k) > 1):
    pages += "<< "

if(k<=p):
    for x in range (k):
        if(p-k+x == 0):
            continue #means that p == k and need to ommit first navigation number
        pages += str(p-k+x) + " "

else:
    for x in range(1,p):
        pages += str(x) + " "
    if x == 0:
        x = k-p # we want to start in 2 for second part
    else:
        x = k-1#x = x+p

pages += "(" + str(p) + ") "

while(x >=0):
    if(p+k-x <= n):
        pages += str(p+k-x) + " "
    if(p+k-x >= n):
        close_symbol = False #no >> required
    x -= 1;

if(close_symbol):
    pages += ">>"
print(pages)


#!/usr/bin/python3

def gcd(a, b):
    while a:
        a, b = b % a, a
    return b

n, m, x, y, a, b = tuple(map(int, input().strip().split()))
g = gcd(a, b)
a //= g
b //= g
k = min(n // a, m // b)
w = k * a
h = k * b
ans = [x - w + w // 2, y - h + h // 2, x + w // 2, y + h // 2]
if ans[0] < 0:
    ans[2] -= ans[0]
    ans[0] = 0;
if ans[1] < 0:
    ans[3] -= ans[1]
    ans[1] = 0
if ans[2] > n:
    ans[0] -= ans[2] - n
    ans[2] = n
if ans[3] > m:
    ans[1] -= ans[3] - m
    ans[3] = m
print('%d %d %d %d' % tuple(ans))

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

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

class TaskB {
    public void solve(int testNumber, InputReader in, PrintWriter out) {
        long maxx = in.nextInt();
        long maxy = in.nextInt();
        long x = in.nextInt();
        long y = in.nextInt();
        long a = in.nextInt();
        long b = in.nextInt();
        long g = BigInteger.valueOf(a).gcd(BigInteger.valueOf(b)).intValue();
        a /= g;
        b /= g;
        long bdist = Long.MAX_VALUE;
        long x1 = -1;
        long y1 = -1;
        long x2 = -1;
        long y2 = -1;
        long mult = Math.min(maxx / a, maxy / b);
        {
            long sx = a * mult;
            long sy = b * mult;
            long xl = Math.max(0, Math.min(maxx - sx, x - sx / 2));
            for (long dx = 0; dx < 2 && xl >= 0; ++dx, --xl) {
                long yl = Math.max(0, Math.min(maxy - sy, y - sy / 2));
                for (long dy = 0; dy < 2 && yl >= 0; ++dy, --yl) {
                    long xr = xl + sx;
                    long yr = yl + sy;
                    long distx = (xl + xr - 2 * x);
                    long disty = (yl + yr - 2 * y);
                    long dist = distx * distx + disty * disty;
                    boolean ok;
                    if (dist < bdist) {
                        ok = true;
                    } else if (dist > bdist) {
                        ok = false;
                    } else if (xl < x1) {
                        ok = true;
                    } else if (xl > x1) {
                        ok = false;
                    } else if (yl < y1) {
                        ok = true;
                    } else if (yl > y1) {
                        ok = false;
                    } else if (xr < x2) {
                        ok = true;
                    } else if (xr > x2) {
                        ok = false;
                    } else if (yr < y2) {
                        ok = true;
                    } else {
                        ok = false;
                    }
                    if (ok) {
                        bdist = dist;
                        x1 = xl;
                        y1 = yl;
                        x2 = xr;
                        y2 = yr;
                    }
                }
            }
        }
        out.println(x1 + " " + y1 + " " + x2 + " " + y2);
    }
}

class InputReader {
    public BufferedReader reader;
    public StringTokenizer tokenizer;

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

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

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

    }


#include <bits/stdc++.h>
using namespace std;
int p[111], n;
int main() {
  cin >> n;
  if (n == 1 || n % 2 == 1) {
    cout << -1;
    return 0;
  }
  for (int i = 1; i <= n; i++) p[i] = i;
  for (int i = 2; i <= n; i++) swap(p[i - 1], p[i]), i++;
  for (int i = 1; i <= n; i++) cout << p[i] << " ";
  cin.get(), cin.get();
  return 0;
}

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

public class Main {

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

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

        if(n%2==1)
            System.out.print(-1);
        else
        {
            for(int i = 1; i <= n; i += 2)
                System.out.print((i==1?"":" ")+(i+1)+" "+i);
            System.out.println();
        }
    }

}


a = input()
b = input()

n = list(a) + list(b)
n = sorted(n)

p = sorted(list(input()))

if n == p:
    print("YES")
else:
    print("NO")

import java.util.HashMap;
import java.util.Scanner;
import java.util.StringTokenizer;

public class CodeA {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		HashMap <Character,Integer>map = new HashMap<Character,Integer>();

		String one =in.nextLine();
		int i;

		for(i=0; i < one.length(); i++) {
			if(map.containsKey(one.charAt(i)))
				map.put(one.charAt(i), map.get(one.charAt(i))+1);
			else
				map.put(one.charAt(i), 1);
		}

		String two = in.nextLine();

		for(i=0; i < two.length(); i++) {
			if(map.containsKey(two.charAt(i)))
				map.put(two.charAt(i), map.get(two.charAt(i))+1);
			else
				map.put(two.charAt(i), 1);
		}

		String fin= in.nextLine();

		boolean flag=true;

		for(i=0; i < fin.length(); i++) {
			if(map.containsKey(fin.charAt(i)))
				map.put(fin.charAt(i), map.get(fin.charAt(i))-1);
			else{
				flag=false;
				break;
			}
		}

		for(char j: map.keySet()) if(map.get(j)!=0) {flag=false;}

		System.out.println((flag)?"YES":"NO");

	}

}


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

public class MostUnstableArray {

	// https://codeforces.com/contest/1353/problem/A

	public static void main(String[] args) throws IOException, FileNotFoundException {
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		//BufferedReader in = new BufferedReader(new FileReader("MostUnstableArray"));

		int t = Integer.parseInt(in.readLine());
		for (int j=0; j<t; j++) {
			StringTokenizer st = new StringTokenizer(in.readLine());
			int n = Integer.parseInt(st.nextToken());
			int m = Integer.parseInt(st.nextToken());
			if (n == 1) System.out.println(0);
			else if (n == 2) System.out.println(m);
			else System.out.println(2 * m);
		}
		//StringTokenizer st = new StringTokenizer(in.readLine());
		//int n = Integer.parseInt(st.nextToken());

	}

}

#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int t;
  cin >> t;
  while (t--) {
    int n, m;
    cin >> n >> m;
    if (n == 1)
      cout << 0 << "\n";
    else if (n == 2)
      cout << m << "\n";
    else
      cout << 2 * m << "\n";
  }
}


n=int(input())
g={}
for i in list(map(int,input().split())):g[i]=g.get(i,0)+2
mx=max(g)
for i in sorted(g)[:-1]:
	if i+1 not in g:exit(print('NO'))
	g[i+1]-=g[i]
	if g[i+1]<0:exit(print('NO'))
print('YES'if g[mx]==0 and list(g.values()).count(0)==1else'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 NO NO NO NO NO NO NO NO NO NO NO NO YES NO NO NO NO NO NO NO NO YES 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 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

#include <bits/stdc++.h>
using namespace std;
bool possible(map<int, int> &M) {
  map<int, int>::iterator it = M.begin(), jt = M.begin();
  jt++;
  if (M.size() == 2) {
    return (jt->first == 1 + it->first) and (it->second == jt->second);
  }
  if (jt->second < 2) return false;
  it->second--;
  if (it->second == 0) M.erase(it);
  jt->second--;
  return possible(M);
}
int main() {
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  if (n % 2 == 1) {
    cout << "NO" << endl;
    return 0;
  }
  map<int, int> M;
  int a;
  for (int i = 0; i < n; i++) {
    cin >> a;
    M[a]++;
  }
  if (possible(M)) {
    cout << "YES" << endl;
  } else {
    cout << "NO" << endl;
  }
  return 0;
}


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

public class A
{
    static int n;
    static int[] sz;
    static long[] dp;
    static long ans;
    static List<Integer> adj[];
    public static void main(String[] args) throws IOException
    {
        Flash f = new Flash();
        n = f.ni();
        adj = new ArrayList[n];
        for(int i = 0; i < n; i++) adj[i] = new ArrayList<>();
        for(int i = 1; i <= n-1; i++){
            int u = f.ni()-1, v = f.ni()-1;
            adj[u].add(v);
            adj[v].add(u);
        }

        sop(fn());
    }

    //Problems related to ReRooting technique
    //https://codeforces.com/blog/entry/68142
    static long fn()
    {
        sz = new int[n];
        dp = new long[n];
        ans = 0;
        calcSize(0, -1);
        dfs(0, -1);
        dfs2(0, -1);
        return ans;
    }

    static void calcSize(int u, int p){
        sz[u] = 1;
        for(int v : adj[u]){
            if(v == p) continue;
            calcSize(v, u);
            sz[u] += sz[v];
        }
    }

    static void dfs(int u, int p){
        dp[u] = sz[u];
        for(int v : adj[u]){
            if(v == p) continue;
            dfs(v, u);
            dp[u] += dp[v];
        }
    }

    static void dfs2(int u, int p){
        ans = Math.max(ans, dp[u]);

        for(int v : adj[u]){
            if(v == p) continue;

            sz[u] -= sz[v];
            dp[u] -= sz[v];
            dp[u] -= dp[v];
            dp[v] -= sz[v];
            sz[v] += sz[u];
            dp[v] += dp[u];
            dp[v] += sz[v];

            dfs2(v, u);

            dp[v] -= sz[v];
            dp[v] -= dp[u];
            sz[v] -= sz[u];
            dp[v] += sz[v];
            dp[u] += dp[v];
            dp[u] += sz[v];
            sz[u] += sz[v];
        }
    }

    static void sort(int[] a){
        List<Integer> A = new ArrayList<>();
        for(int i : a) A.add(i);
        Collections.sort(A);
        for(int i = 0; i < A.size(); i++) a[i] = A.get(i);
    }

    static int swap(int itself, int dummy){
        return itself;
    }

    static void sop(Object o){ System.out.println(o); }

    static void print(int[] a){
        StringBuilder sb = new StringBuilder();
        for(int i = 0; i < a.length; i++) sb.append(a[i] + " ");
        System.out.println(sb);
    }

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

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

            return st.nextToken();
        }

        String ns(){
            String s = new String();
            try{
                s = br.readLine().trim();
            }catch(IOException e){
                e.printStackTrace();
            }

            return s;
        }

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

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

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

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

import sys

input = sys.stdin.readline

n = int(input())
G = [[] for _ in range(n)]

for _ in range(n-1):
    a,b = map(int,input().split())
    G[a-1].append(b-1)
    G[b-1].append(a-1)

F = [0]*n
stk = [0]
visited = [0]*n

while stk:
    x = stk[-1]
    if not visited[x]:
        visited[x] = 1
        for y in G[x]:
            if not visited[y]:
                stk.append(y)
    else:
        x = stk.pop()
        F[x] = 1
        for y in G[x]:
            F[x] += F[y]

DP = [0]*n
stk = [0]
visited = [0]*n

while stk:
    x = stk[-1]
    if not visited[x]:
        visited[x] = 1
        for y in G[x]:
            if not visited[y]:
                stk.append(y)
    else:
        x = stk.pop()
        DP[x] = F[x]
        for y in G[x]:
            DP[x] += DP[y]

ans = [0]*n
ans[0] = DP[0]
stk = [0]
Z = DP[0]

while stk:
    x = stk.pop()
    for y in G[x]:
        if not ans[y]:
            ay = ans[x] + n - 2 * F[y]
            ans[y] = ay
            Z = max(Z,ay)
            stk.append(y)

print(Z)


a,b,c=map(int,input().split())
dif=abs(a-b)
if dif <=1:
    print(a+b+c*2)
else:
    print(min(a,b)*2+1+c*2)

#include <bits/stdc++.h>
using namespace std;
const long long INF = 0xacacaca;
inline long long read() {
  long long x = 0, f = 0;
  char ch = 0;
  while (!isdigit(ch)) f |= (ch == '-'), ch = getchar();
  while (isdigit(ch)) (x *= 10) += (ch ^ 48), ch = getchar();
  return f ? -x : x;
}
long long a, b, c, ans;
signed main() {
  a = read();
  b = read();
  c = read();
  ans += c << 1;
  ans += min(a, b) * 2;
  ans += a == b ? 0 : 1;
  printf("%lld\n", ans);
  return 0;
}


import java.util.*;
public class main
{
    public static void main(String args[])
    {
       Scanner sc=new Scanner(System.in);
       int n,k;
       double r,g,b;
       n=sc.nextInt();
       k=sc.nextInt();
       r=1.0*n*2/k;
       g=1.0*n*5/k;
       b=1.0*n*8/k;
       System.out.print((int)(Math.ceil(r)+Math.ceil(g)+Math.ceil(b)));
    }
}

data=[int(i) for i in input().split()]
n=data.pop(0)
k=data.pop(0)
red=n*2
green=n*5
blue=n*8
answer=0
if red%k==0:
      answer+=red//k
else:
      answer+=red//k+1
if blue%k==0:
      answer+=blue//k
else:
      answer+=blue//k+1
if green%k==0:
      answer+=green//k
else:
      answer+=green//k+1
print(int(answer))


#include <bits/stdc++.h>
using namespace std;
long long int index_sum[5001];
long long int n, varr[5001];
long long int summ(int i) {
  if (i < 0) return 0;
  return index_sum[i];
}
int main() {
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> varr[i];
    index_sum[i] = varr[i] + summ(i - 1);
  }
  long long int ans = 0;
  for (int i = 0; i < n; i++) {
    for (int j = i; j < n; j++) {
      if (summ(j) - summ(i - 1) > 100 * (j + 1 - i)) {
        if (ans <= j + 1 - i) ans = j + 1 - i;
      }
    }
  }
  cout << ans << endl;
  return 0;
}

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

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

    static class Solver {
        private void solve(InputReader inp, PrintWriter out) {
            int n = inp.nextInt(), max = 0;
            int[] r = new int[n];
            for (int i = 0; i < n; i++) r[i] = inp.nextInt();
            for (int i = 0; i < n; i++) {
                int sum = 0;
                for (int j = i; j < n; j++) {
                    sum += r[j];
                    if (sum >  (j - i + 1) * 100) {
                        max = Math.max(max, j - i + 1);
                    }
                }
            }
            out.print(max);
        }
    }

    static class InputReader {
        BufferedReader reader;
        StringTokenizer tokenizer;

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

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

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

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


#include <bits/stdc++.h>
using namespace std;
int l, r, x, y;
vector<int> k, n, m;
int power(int a, int b) {
  int res = 1;
  for (int i = 0; i < b; i++) res *= a;
  return res;
}
int calc(int i, int x, int y) {
  if (i == k.size()) return (l <= x && x <= r && l <= y && y <= r);
  int res = calc(i + 1, x * power(k[i], n[i]), y * power(k[i], m[i]));
  if (n[i] > m[i])
    res += calc(i + 1, x * power(k[i], m[i]), y * power(k[i], n[i]));
  return res;
}
int main() {
  cin >> l >> r >> x >> y;
  if (x == y) {
    cout << (l <= x && x <= r);
    return 0;
  }
  if (y % x) {
    cout << 0;
    return 0;
  }
  for (int i = 2; i * i <= y; i++)
    if (y % i == 0) {
      k.push_back(i);
      int cnt = 0;
      for (cnt; y % i == 0; y /= i, cnt++)
        ;
      n.push_back(cnt);
    }
  if (y > 1) k.push_back(y), n.push_back(1);
  for (int i = 0; i < k.size(); i++) {
    int cnt = 0;
    for (cnt; x % k[i] == 0; x /= k[i], cnt++)
      ;
    m.push_back(cnt);
  }
  cout << calc(0, 1, 1);
}

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.util.ArrayList;
import java.io.InputStream;

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

    static class TaskB {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            long l = in.NextInt();
            long r = in.NextInt();
            long x = in.NextInt();
            long y = in.NextInt();
            ArrayList<Long> dividers = MathExtentions.getAllDividers(y);
            int res = 0;
            for (long a : dividers)
                if (l <= a && a <= r)
                    for (long b : dividers)
                        if (l <= b && b <= r)
                            if (MathExtentions.gcd(a, b) == x && MathExtentions.lcm(a, b) == y)
                                res++;
            out.println(res);

        }

    }

    static class InputReader {
        BufferedReader reader;
        StringTokenizer tokenizer;

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

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

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

    }

    static class MathExtentions {
        public static long gcd(final long a, final long b) {
            if (a == 0)
                return b;
            return gcd(b % a, a);
        }

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

        public static ArrayList<Long> getAllDividers(long y) {
            //not complete! can use factors
            ArrayList<Long> res = new ArrayList<>();
            long i = 1;
            for (; i * i < y; i++) {
                if (y % i == 0) {
                    res.add(i);
                    res.add(y / i);
                }
            }
            if (i * i == y) res.add(i);
            return res;
        }

    }
}


import java.util.*;
import java.text.*;

import javax.swing.plaf.basic.BasicScrollPaneUI.HSBChangeListener;

import java.io.*;
import java.math.*;
public class code5 {
	InputStream is;
	PrintWriter out;
	static long mod=pow(10,9)+7;
	static int dx[]={1,-1,-1,1,0,0,1,-1},dy[]={1,-1,1,-1,1,-1,0,0};
	void solve() throws Exception
	{
		long t=nl();
		int l=ni();
		int r=ni();
		prime(r);
		long dp[]=new long[r+1];
		for(int i=2;i<=r;i++)
		{
			if(small[i]==0)
				dp[i]=((((i*1L)*(i-1)))/2L)%mod;
			else
				dp[i]=(((i/small[i])*dp[small[i]])%mod+dp[i/small[i]])%mod;
		}
		long ans=0,temp=1;
		for(int i=l;i<=r;i++)
		{
			ans+=(temp*dp[i])%mod;
			ans%=mod;
			temp*=t;
			temp%=mod;
		}
		out.print(ans);
	}
	int small[];
	void prime(int n)
	{
		small=new int[n+1];
		for(int i=2;i*i<=n;i++)
		{
			for(int j=i;j*i<=n;j++)
			{
				if(small[j*i]==0)
					small[j*i]=i;
			}
		}
	}
	public static int count(int x)
	{
		int num=0;
		while(x!=0)
		{
			x=x&(x-1);
			num++;
		}
		return num;
	}
	static long d, x, y;
	void extendedEuclid(long A, long B) {
	    if(B == 0) {
	        d = A;
	        x = 1;
	        y = 0;
	    }
	    else {
	        extendedEuclid(B, A%B);
	        long temp = x;
	        x = y;
	        y = temp - (A/B)*y;
	    }
	}
	long modInverse(long A,long M) //A and M are coprime
	{
	    extendedEuclid(A,M);
	    return (x%M+M)%M;    //x may be negative
	}
	public static void mergeSort(int[] arr, int l ,int r){
		if((r-l)>=1){
			int mid = (l+r)/2;
			mergeSort(arr,l,mid);
			mergeSort(arr,mid+1,r);
			merge(arr,l,r,mid);
		}
	}
	public static void merge(int arr[], int l, int r, int mid){
		int n1 = (mid-l+1), n2 = (r-mid);
		int left[] = new int[n1];
		int right[] = new int[n2];
		for(int i =0 ;i<n1;i++) left[i] = arr[l+i];
		for(int i =0 ;i<n2;i++) right[i] = arr[mid+1+i];
		int i =0, j =0, k = l;
		while(i<n1 && j<n2){
			if(left[i]>right[j]){
				arr[k++] = right[j++];
			}
			else{
				arr[k++] = left[i++];
			}
		}
		while(i<n1) arr[k++] = left[i++];
		while(j<n2) arr[k++] = right[j++];
	}
	public static void mergeSort(long[] arr, int l ,int r){
		if((r-l)>=1){
			int mid = (l+r)/2;
			mergeSort(arr,l,mid);
			mergeSort(arr,mid+1,r);
			merge(arr,l,r,mid);
		}
	}
	public static void merge(long arr[], int l, int r, int mid){
		int n1 = (mid-l+1), n2 = (r-mid);
		long left[] = new long[n1];
		long right[] = new long[n2];
		for(int i =0 ;i<n1;i++) left[i] = arr[l+i];
		for(int i =0 ;i<n2;i++) right[i] = arr[mid+1+i];
		int i =0, j =0, k = l;
		while(i<n1 && j<n2){
			if(left[i]>right[j]){
				arr[k++] = right[j++];
			}
			else{
				arr[k++] = left[i++];
			}
		}
		while(i<n1) arr[k++] = left[i++];
		while(j<n2) arr[k++] = right[j++];
	}
	 static class Pair implements Comparable<Pair>{

	       int x,y,k;
	       int i;
	       long cost;
		Pair (int x,int y){
			this.x=x;
			this.y=y;
		}
		public int compareTo(Pair o) {
			return this.k-o.k;
		}

		public String toString(){
			return x+" "+y+" "+k+" "+i;}
		public boolean equals(Object o) {
			if (o instanceof Pair) {
				Pair p = (Pair)o;
				return p.x == x && p.y == y ;
			}
			return false;
		}
		public int hashCode() {
			return new Long(x).hashCode()*31 + new Long(y).hashCode();
		}
	}

	    public static boolean isPal(String s){
	        for(int i=0, j=s.length()-1;i<=j;i++,j--){
	                if(s.charAt(i)!=s.charAt(j)) return false;
	        }
	        return true;
	    }
	    public static String rev(String s){
			StringBuilder sb=new StringBuilder(s);
			sb.reverse();
			return sb.toString();
	    }

	    public static long gcd(long x,long y){
		if(x%y==0)
			return y;
		else
			return gcd(y,x%y);
	    }

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

	    public static long gcdExtended(long a,long b,long[] x){

	        if(a==0){
	            x[0]=0;
	            x[1]=1;
	            return b;
	        }
	        long[] y=new long[2];
	        long gcd=gcdExtended(b%a, a, y);

	        x[0]=y[1]-(b/a)*y[0];
	        x[1]=y[0];

	        return gcd;
	    }

	    public static int abs(int a,int b){
		return (int)Math.abs(a-b);
	    }

	    public static long abs(long a,long b){
		return (long)Math.abs(a-b);
	    }

	    public static int max(int a,int b){
		if(a>b)
			return a;
		else
			return b;
	    }

	    public static int min(int a,int b){
		if(a>b)
			return b;
		else
			return a;
	    }

	    public static long max(long a,long b){
		if(a>b)
			return a;
		else
			return b;
	    }

	    public static long min(long a,long b){
		if(a>b)
			return b;
		else
			return a;
	    }

	    public static long pow(long n,long p,long m){
		 long  result = 1;
		  if(p==0)
		    return 1;
		if (p==1)
		    return n;
		while(p!=0)
		{
		    if(p%2==1)
		        result *= n;
		    if(result>=m)
		    result%=m;
		    p >>=1;
		    n*=n;
		    if(n>=m)
		    n%=m;
		}
		return result;
	    }

	    public static long pow(long n,long p){
		long  result = 1;
		  if(p==0)
		    return 1;
		if (p==1)
		    return n;
		while(p!=0)
		{
		    if(p%2==1)
		        result *= n;
		    p >>=1;
		    n*=n;
		}
		return result;
	    }
	    public static void debug(Object... o) {
			System.out.println(Arrays.deepToString(o));
		}
	    void run() throws Exception {
			is = System.in;
			out = new PrintWriter(System.out);
			solve();
			out.flush();
		}

	    public static void main(String[] args) throws Exception {
			new Thread(null, new Runnable() {
				public void run() {
					try {
						new code5().run();
					} catch (Exception e) {
						e.printStackTrace();
					}
				}
			}, "1", 1 << 26).start();

	    	//new code5().run();
		}
	    private byte[] inbuf = new byte[1024];
		public int lenbuf = 0, ptrbuf = 0;

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

		private boolean isSpaceChar(int c) {
			return !(c >= 33 && c <= 126);
		}

		private int skip() {
			int b;
			while ((b = readByte()) != -1 && isSpaceChar(b));
			return b;
		}

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

		private char nc() {
			return (char) skip();
		}

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

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

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

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

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

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

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

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

}

#include <bits/stdc++.h>
using namespace std;
const int N = 6005000;
long long d[N];
int main() {
  srand(time(NULL));
  long long t;
  int l, r;
  cin >> t >> l >> r;
  for (int i = 1; i <= r; i++) d[i] = 1e18;
  d[1] = 0;
  for (int i = 1; i <= r; i++) {
    for (int j = i + i; j <= r; j += i) {
      d[j] = min(d[j], d[i] + (j * 1LL * ((j / i) - 1)) / 2LL);
    }
  }
  long long nw = 1;
  long long ans = 0;
  for (int i = l; i <= r; i++) {
    ans += (nw * (d[i] % 1000000007)) % 1000000007;
    ans %= 1000000007;
    nw *= t;
    nw %= 1000000007;
  }
  cout << ans;
  return 0;
}


def cut_to_lexicographic(word_bigger, word_smaller):
    for l in range(len(word_bigger)):
        if word_bigger[l] != word_smaller[l]:
            return word_bigger[:l]
    return word_bigger

n = int(input())
array = [str(input()) for c in range(n)]
b = n - 2
while b > -1:
    if array[b + 1] >= array[b]:
        b = b - 1
    else:
        if len(array[b]) > len(array[b + 1]):
            array[b] = array[b][:len(array[b + 1])]
        array[b] = cut_to_lexicographic(array[b], array[b+1])
print("\n".join(array))

#include <bits/stdc++.h>
using namespace std;
int n;
vector<string> h;
void solve() {
  cin >> n;
  h.resize(n);
  for (int i = 0; i < n; ++i) {
    cin >> h[i];
    h[i].erase(h[i].begin());
  }
  for (int i = n - 2; i >= 0; --i) {
    if (h[i] > h[i + 1]) {
      for (int j = 0; j < h[i].size(); ++j) {
        if (h[i][j] > h[i + 1][j]) {
          h[i].resize(j);
        }
      }
    }
  }
  for (int i = 0; i < n; ++i) {
    cout << '#' << h[i] << endl;
  }
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  solve();
  return 0;
}


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

public class B {
	public static void main(String[]args) throws IOException {
		BufferedReader x = new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st = new StringTokenizer(x.readLine());
		int n = Integer.parseInt(st.nextToken());
		int k = Integer.parseInt(st.nextToken());
		int[]arr = new int[n];
		st = new StringTokenizer(x.readLine());
		for (int i = 0; i < n; i++) {
			arr[i] = Integer.parseInt(st.nextToken());
		}
		int cur = 0;
		int ans = 0;
		for (int i = 1; i < n; i++) {
			int temp = k - (arr[i] + arr[i-1]);
			temp = Math.max(temp, 0);
			arr[i] += temp;
			ans += temp;
		}
		System.out.println(ans);
		for (int i = 0; i < n; i++) {
			System.out.print(arr[i]+" ");
		}
		System.out.println();
	}
}

import math
n,k=map(int,input().split())
l2=[]
a=list(map(int,input().split()))
for i in a:
    l2.append(i)
i=1
l=[a[0]]
while i<=n-1:
    if a[i]+a[i-1]<k:
        a[i]=k-a[i-1]
        l.append(k-a[i-1])
    else:
        l.append(a[i])
    i=i+1
print(sum(l)-sum(l2))
print(*l)


#include <bits/stdc++.h>
using namespace std;
int main() {
  int a, ta, b, tb;
  cin >> a >> ta >> b >> tb;
  string st;
  cin >> st;
  int min = (stoi(st.substr(0, 2)) * 60 + stoi(st.substr(3, 5)));
  vector<int> arr;
  for (int i = 300; i < (24 * 60); i += b) arr.push_back(i);
  int s = upper_bound(arr.begin(), arr.end(), min - tb) - arr.begin();
  int e = lower_bound(arr.begin(), arr.end(), min + ta - 1) - arr.begin();
  if (!binary_search(arr.begin(), arr.end(), min + ta - 1)) e--;
  cout << (e - s + 1);
}

def solve(a, t1, t2):
    l1 = t1 - (t1 - 300) % a + a
    if (l1 < 300):
        l1 = 300
    l2 = t2 - (t2 - 300) % a
    if (l2 > 1439):
        l2 = 1439
    if (l2 < l1):
        return 0
    return (l2-l1) // a + 1 - (l2 == t2)

def trans(h, m):
    return 60 * h + m

data1 = [int(x) for x in input().split()]
data2 = [int(x) for x in input().split()]
data3 = input()
h0 = int(data3[0:2])
m0 = int(data3[-2:])
t0 = trans(h0, m0)
sol = solve(data2[0], t0 - data2[1], t0 + data1[1])
print(sol)


#include <bits/stdc++.h>
#pragma GCC optimization("unroll-loops")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4")
using namespace std;
int main() {
  int n;
  scanf("%d", &n);
  vector<int> x(n);
  for (int i = 0; i < n; ++i) {
    scanf("%d", &x[i]);
  }
  sort(x.begin(), x.end());
  int ans = INT_MAX;
  for (int i = 0; i < n / 2; ++i) {
    ans = min(ans, x[i + n / 2] - x[i]);
  }
  cout << ans << '\n';
  return 0;
}

#!/usr/bin/env python3

n = int(input())
n_2 = n // 2
x = sorted([int(tok) for tok in input().split()])
res = min((x[j] - x[j-n_2] for j in range(n_2, n)))
print(res)


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

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner scanner = new Scanner(System.in);

		int n = scanner.nextInt();
		String a = scanner.next().toLowerCase();

		HashSet<String> w = new HashSet<>();

		for (int i = 0; i < n; i++) {
			String ai = a.substring(i, i + 1);
			w.add(ai);
		}

		if (w.size() == 26) {
			System.out.println("YES");
		} else {
			System.out.println("NO");
		}

		scanner.close();
	}
}

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

#include <bits/stdc++.h>
using namespace std;
void spic(string &s, int n) {
  for (int i = 0; i < n; i++) {
    s[i] = (char)tolower(s[i]);
  }
}
int main() {
  int p = 0, b;
  cin >> b;
  string s;
  cin >> s;
  if (b < 26)
    cout << "NO"
         << "\n";
  else {
    int t = 0;
    spic(s, b);
    sort(s.begin(), s.end());
    for (int j = 0; j < b; j++) {
      if (s[j] == 'a' + t) {
        p++;
        t++;
      }
    }
    if (p == 26)
      cout << "YES"
           << "\n";
    else
      cout << "NO"
           << "\n";
  }
}


n = int(input())
linea = list(map(int, input().split()))
lineb = list(map(int, input().split()))
lines = linea + lineb
c1 = lines.count(1)
c2 = lines.count(2)
c3 = lines.count(3)
c4 = lines.count(4)
c5 = lines.count(5)
cc1 = linea.count(1)
cc2 = linea.count(2)
cc3 = linea.count(3)
cc4 = linea.count(4)
cc5 = linea.count(5)
if (c1 % 2 == 1 or c2 % 2 == 1 or c3 % 2 == 1 or c4 % 2 == 1 or c5 % 2 == 1):
    print(-1)
else:
    print(int(abs(c1 / 2 - cc1) + abs(c2 / 2 - cc2) + abs(c3 / 2 - cc3) + abs(c4 / 2 - cc4) + abs(c5 / 2 - cc5)) // 2)

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

public class TestClass {
    public static void main(String args[] ) throws IOException {
        BufferedReader obj = new BufferedReader(new InputStreamReader(System.in));
        PrintWriter pout = new PrintWriter(System.out);
        int n = Integer.parseInt(obj.readLine());
        int [][] hash = new int[5][2];
        String [] s1 = obj.readLine().split(" ");
        String [] s2 = obj.readLine().split(" ");
        for (int i = 0; i < n; i++) {
            int a = Integer.parseInt(s1[i]);
            int b = Integer.parseInt(s2[i]);
            a -= 1;
            b -= 1;
            hash[a][0] += 1;
            hash[b][1] += 1;
        }
        /*for (int i = 0; i < 5; i++) {
            System.out.println(hash[i][0]+" "+hash[i][1]);
        }*/
        int flag = 0;
        for (int i = 0; i < 5; i++) {
            int sum = hash[i][0] + hash[i][1];
            if (sum % 2 != 0) {
                flag = 1;
                break;
            }
        }
        if (flag == 1) {
            pout.println("-1");
        }
        else {
            int swap = 0;
            for (int i = 0; i < 5; i++) {
                if (hash[i][0] == hash[i][1]) {
                    continue;
                }
                int avg = (hash[i][0] + hash[i][1]) / 2;
                int d = Math.abs(hash[i][0] - avg);
                swap += d;
            }
            swap /= 2;
            pout.println(swap);
        }
        pout.flush();
    }
}


#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int n;
  cin >> n;
  cout << (n + 1) / 2 << "\n";
  return 0;
}

import java.util.Scanner;

public class CollectiveMindsets {
	public static void main(String args[])
	{
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		System.out.println((n+1)/2);
	}
}


s = input()

blocks = []

evenA = [0]
oddA = [0]
evenB = [0]
oddB = [0]

even = True

for x in s:
    evenA.append(evenA[-1])
    oddA.append(oddA[-1])
    evenB.append(evenB[-1])
    oddB.append(oddB[-1])
    if x == 'a':
        if even:
            evenA[-1] += 1
        else:
            oddA[-1] += 1
    else:
        if even:
            evenB[-1] += 1
        else:
            oddB[-1] += 1

    even = not even

even = True
totalE = 0
totalO = 0

for x in range(len(s)):
    if s[x] == 'a':
        if x%2 == 0:
            totalE += evenA[-1] - evenA[x]
            totalO += oddA[-1] - oddA[x]
        else:
            totalE += oddA[-1] - oddA[x]
            totalO += evenA[-1] - evenA[x]
    else:
        if x%2 == 0:
            totalE += evenB[-1] - evenB[x]
            totalO += oddB[-1] - oddB[x]
        else:
            totalE += oddB[-1] - oddB[x]
            totalO += evenB[-1] - evenB[x]

print(totalO,totalE)

bababa
```

Note that each sample input is a string of length 40 or less consisting only of the characters 'a' and 'b'.

#include <bits/stdc++.h>
const long long INF = 1e18;
const int MOD = 1e9 + 7;
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  string s;
  cin >> s;
  int n = s.size();
  long long b_odd = 0, b_even = 0;
  long long a_odd = 0, a_even = 0;
  long long res = 0, reso = 0;
  for (int i = 0; i < n; ++i) {
    if (i % 2) {
      if (s[i] == 'a')
        a_odd++, res += a_even, reso += a_odd;
      else
        b_odd++, res += b_even, reso += b_odd;
    } else {
      if (s[i] == 'a')
        a_even++, res += a_odd, reso += a_even;
      else
        b_even++, res += b_odd, reso += b_even;
    }
  }
  cout << res << ' ' << reso << '\n';
}


n,v=map(int,input().split())
a=[int(i) for i in input().split()]
b=[int(i) for i in input().split()]
mini=10**9
for i in range(n):
    mini=min(mini,b[i]/a[i])
sm=0
for i in range(n):
    sm=sm+mini*a[i]
print(min(sm,v))

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

public class Main implements Runnable {

    public void solve() throws IOException {
        int n = nextInt(), V = nextInt();
        int[ ] a = new int[n];
        for(int i = 0; i < n; ++i) {
            a[i] = nextInt();
        }
        int[] b = new int[n];
        for(int i = 0; i < n; ++i) {
            b[i] = nextInt();
        }
        double left = 0, right = 1000000;
        while (right - left > 1e-9) {
            double c = (left + right) / 2;
            double q = 0;
            boolean can = true;
            for(int i = 0; i < n;++i) {
                can &= b[i] >= (a[i] * c);
                q += a[i] * c;
            }
            can &= q < V;
            if (!can)
                right = c;
            else if (q > V)
                right = c;
            else
                left = c;
        }
        double ans = 0;
        for(int i = 0; i < n; ++i)
            ans += a[i] * right;
        pw.printf(Locale.US, "%1.8f", ans);
    }

    static final String filename = "A";
    static final boolean fromConsole = true;

    public void run() {
        try {
            if (!fromConsole) {
                in = new BufferedReader(new FileReader(filename + ".in"));
                pw = new PrintWriter(filename + ".out");
            } else {
                in = new BufferedReader(new InputStreamReader(System.in));
                pw = new PrintWriter(System.out);
            }
            st = new StringTokenizer("");
            long st = System.currentTimeMillis();
            solve();
            //pw.printf("\nWorking time: %d ms\n", System.currentTimeMillis() - st);
            pw.close();
        } catch (Exception e) {
            e.printStackTrace();
            System.exit(-1);
        }
    }

    private StringTokenizer st;
    private BufferedReader in;
    private PrintWriter pw;

    boolean hasNext() throws IOException {
        while (!st.hasMoreTokens()) {
            String line = in.readLine();
            if (line == null) {
                return false;
            }
            st = new StringTokenizer(line);
        }
        return st.hasMoreTokens();
    }

    String next() throws IOException {
        return hasNext() ? st.nextToken() : null;
    }

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

    BigInteger nextBigInteger() throws IOException {
        return new BigInteger(next());
    }

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

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

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


import java.io.IOException;
import java.util.Scanner;
public class SerejaAndDima {

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

		short n = s.nextShort();
		short card[] = new short[n];
		short i, j;
		for (i=0; i<n; i++) {
			card[i] = s.nextShort();
		}

		int S=0, D=0;
		i = 0;
		j = (short) (n-1);
		while(n>0) {
			if (card[i]>card[j]) {
				S+=card[i];
				card[i] = 0;
				i++;
			}
			else {
				S+=card[j];
				card[j] = 0;
				j--;
			}
			n--;
			if (n==0) break;
			if (card[i]>card[j]) {
				D+=card[i];
				card[i] = 0;
				i++;
			}
			else {
				D+=card[j];
				card[j] = 0;
				j--;
			}
			n--;
		}
		System.out.println(S+" "+D);

	}

}

#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, s = 0, d = 0, beg = 0, end = 0;
  cin >> n;
  int a[n];
  end = n - 1;
  for (int i = 0; i < n; i++) cin >> a[i];
  for (int i = 0; i < n; i++) {
    if (i % 2 == 0) {
      if (a[beg] < a[end]) {
        s += a[end];
        end--;
      } else {
        s += a[beg];
        beg++;
      }
    } else {
      if (a[beg] < a[end]) {
        d += a[end];
        end--;
      } else {
        d += a[beg];
        beg++;
      }
    }
  }
  cout << s << " " << d;
}


import static java.lang.Math.*;
import static java.lang.System.currentTimeMillis;
import static java.lang.System.exit;
import static java.lang.System.arraycopy;
import static java.util.Arrays.sort;
import static java.util.Arrays.binarySearch;
import static java.util.Arrays.fill;
import java.util.*;
import java.io.*;

public class Main {

    public static void main(String[] args) throws IOException {
        try {
            if (new File("input.txt").exists())
                System.setIn(new FileInputStream("input.txt"));
        } catch (SecurityException e) {
        }
        new Main().run();
    }

    BufferedReader in;
    PrintWriter out;
    StringTokenizer st = new StringTokenizer("");

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

    final int MAXN = 100001;
    char[] sms;
    String[]word = new String[MAXN];
    int n;

    int shift__3(int i){
        boolean ok1 = false, ok2 = false;
        while(i < sms.length && sms[i] != '<')
            i++;
        if(i < sms.length && sms[i] == '<')
            ok1 = true;
        while(i < sms.length && sms[i] != '3')
            i++;
        if(i < sms.length && sms[i] == '3')
            ok2 = true;
        if(ok1 && ok2)
            return i+1;
        return -1;
    }
    int shiftChar(int i, char ch){
        boolean ok = false;
        while(i < sms.length && sms[i] != ch)
            i++;
        if(i < sms.length && sms[i] == ch)
            return i+1;
        return -1;
    }

    private void solve() throws IOException {
        n = nextInt();
        for(int i = 0; i < n; i++)
            word[i] = nextToken();
        sms = nextToken().toCharArray();
        int len = sms.length;
        int i = 0;
        boolean bad = false;
        for(int w = 0; w < n; w++){
            i = shift__3(i);
            if(i == -1 || i == sms.length){
                bad = true;
                break;
            }
            char[] t = word[w].toCharArray();
            for(int k = 0; k < t.length; k++){
                i = shiftChar(i,t[k]);
                if(i == -1 || i == sms.length){
                    bad = true;
                    break;
                }
            }
            if(bad)
                break;
        }
        if(bad){
            out.println("no");
        } else {
            i = shift__3(i);
            if(i == -1)
                out.println("no");
            else
                out.println("yes");
        }
    }

    void chk(boolean b) {
        if (b)
            return;
        System.out.println(new Error().getStackTrace()[1]);
        exit(999);
    }
    void deb(String fmt, Object... args) {
        System.out.printf(Locale.US, fmt + "%n", args);
    }
    String nextToken() throws IOException {
        while (!st.hasMoreTokens())
            st = new StringTokenizer(in.readLine());
        return st.nextToken();
    }
    int nextInt() throws IOException {
        return Integer.parseInt(nextToken());
    }
    long nextLong() throws IOException {
        return Long.parseLong(nextToken());
    }
    double nextDouble() throws IOException {
        return Double.parseDouble(nextToken());
    }
    String nextLine() throws IOException {
        st = new StringTokenizer("");
        return in.readLine();
    }
    boolean EOF() throws IOException {
        while (!st.hasMoreTokens()) {
            String s = in.readLine();
            if (s == null)
                return true;
            st = new StringTokenizer(s);
        }
        return false;
    }
}

7
i
am
not
main
in
the
family
<3i<>3am<3the<3<main<3in<3the<3><3family<3

def werify_message(words, message):
    true_message = ''.join(['<3', '<3'.join(words), '<3'])

    # index in true_message
    i = 0
    for litera in message:
        if len(true_message) != i:
            if litera == true_message[i]:
                i += 1
        else:
            # Дошли до конца исходного сообщения и не нашли вставок
            return 'yes'

    if i == len(true_message):
        return 'yes'
    else:
        return 'no'

n = int(input())
words = list()
for i in range(n):
    word = input()
    words.append(word)

message = input()
print(werify_message(words, message))