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

/**
 *
 * @author epiZend
 */
public class Correct {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String num = sc.next();
        String ans = sc.next();
        if(num.equals("0") && ans.equals("0")){
            System.out.println("OK");
            return;
        }
        if (ans.startsWith("0")) {
            System.out.println("WRONG_ANSWER");
            return;
        }
        int zeroes = 0;
        for (int i = 0; i < num.length(); i++) {
            if (num.charAt(i) == '0') {
                zeroes++;
            }
        }
        num = num.replace("0", "");
        char[] chars = num.toCharArray();
        Arrays.sort(chars);
        String real = "";
        int last = -1;
        for (int i = 0; i < chars.length; i++) {
            real += chars[i];
            if (i == 0) {
                for (int j = 0; j < zeroes; j++) {
                    real += "0";
                }
                last = -2;
            }
        }
        System.out.println(real.equals(ans) ? "OK" : "WRONG_ANSWER");
    }
}

def sort(s):
    return sorted(sorted(s), key=str.upper)
s=input()
s1=input()
l=sort(s)
c=l.count('0')
res=""
if(len(l)>c):
    res=res+l[c]
for i in range(c):
    res=res+l[i]
for i in range(c+1,len(s)):
    res=res+l[i]
if(s1==res):
    print("OK")
else:
    print("WRONG_ANSWER")


import java.util.Scanner;

public class C1157 {

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int N = in.nextInt();
        int[] A = new int[N];
        for (int n=0; n<N; n++) {
            A[n] = in.nextInt();
        }
        StringBuilder output = new StringBuilder();
        int downIdx = 0;
        int upIdx = N-1;
        int last = 0;
        while (downIdx <= upIdx) {
            int down = A[downIdx];
            int up = A[upIdx];
            if (down > last) {
                if (up > last) {
                    if (down < up) {
                        last = down;
                        downIdx++;
                        output.append('L');
                    } else if (down > up) {
                        last = up;
                        upIdx--;
                        output.append('R');
                    } else if (downIdx == upIdx) {
                        output.append('L');
                        break;
                    } else {
                        int downLength = 1;
                        while (A[downIdx+1] > A[downIdx]) {
                            downLength++;
                            downIdx++;
                        }
                        int upLength = 1;
                        while (A[upIdx-1] > A[upIdx]) {
                            upLength++;
                            upIdx--;
                        }
                        int length;
                        char c;
                        if (downLength > upLength) {
                            length = downLength;
                            c = 'L';
                        } else {
                            length = upLength;
                            c = 'R';
                        }
                        for (int i=0; i<length; i++) {
                            output.append(c);
                        }
                        break;
                    }
                } else {
                    last = down;
                    downIdx++;
                    output.append('L');
                }
            } else {
                if (up > last) {
                    last = up;
                    upIdx--;
                    output.append('R');
                } else {
                    break; // both smaller
                }
            }
        }
        System.out.println(output.length());
        System.out.println(output);
    }

}

#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int i, c = 0, n, T, cs = 0, k, x, j;
  T = 1;
  string s = "";
  while (T--) {
    cin >> n;
    long long int a[n];
    for (i = 0; i < n; i++) cin >> a[i];
    i = n - 1;
    j = 0;
    c = 0;
    while (i >= j) {
      if (a[i] == a[j] && i != j) {
        k = j, cs = c;
        string p = "", q = "";
        while (j < i && a[j] > c) p += 'L', c = a[j], j++;
        c = cs;
        while (i > k && a[i] > c) q += 'R', c = a[i], i--;
        if (p.size() > q.size())
          s += p;
        else
          s += q;
        break;
      } else if (a[i] > a[j] && a[j] > c)
        s += 'L', c = a[j], j++;
      else if (a[i] > c)
        s += 'R', c = a[i], i--;
      else if (a[j] > c)
        s += 'L', c = a[j], j++;
      else
        break;
    }
    cout << s.size() << "\n" << s;
  }
  return 0;
}


import java.util.Arrays;
import java.util.TreeMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Scanner;
import java.util.Set;

public class practice {
	public static void main (String[] args)
	{
		Scanner sc=new Scanner(System.in);
		int n=sc.nextInt();
		String[] old=new String[n];
		String[] current =new String[n];
		int[] state=new int[n];
		int flag=0;
		int count=0;

		for(int i=0;i<n;i++)
		{
			state[i]=0;
		}

		for(int i=0;i<n;i++)
		{
			old[i]=sc.next();
		}
		for(int i=0;i<n;i++)
		{
			current[i]=sc.next();
		}

		for(int i=0;i<n;i++)
		{
			flag=0;
			for(int j=0;j<n;j++)
			{
				if(current[i].equals(old[j])&&state[j]==0)
				{
					flag=1;
					state[j]=1;
					break;
				}
			}
			if(flag==0)
				count++;
		}
		System.out.println(count);
}
}

8
XL
XS
S
XXXL
XXXL
XL
XXXL
S
XS
XXXS
XL
L
XXXS
M
XS
XXXL

6
XXL
XXS
XXXS
L
XXXS
XXXL
XXL
L
XXS
XXXS
XXXL
XXXL

#include <bits/stdc++.h>
using namespace std;
const int dr[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
const int dc[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const double PI = acos(-1);
const double EPS = 10e-9;
const int e4 = 1e4 + 5;
const int e5 = 1e5 + 5;
const int e6 = 1e6 + 5;
map<string, int> m;
int main() {
  int n, ans = 0;
  scanf("%d", &n);
  string str;
  for (int i = 0; i < n; i++) {
    cin >> str;
    m[str]++;
  }
  for (int i = 0; i < n; i++) {
    cin >> str;
    if (m[str] != 0) {
      m[str]--;
    } else {
      ans++;
    }
  }
  printf("%d\n", ans);
  return 0;
}


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

public class B {
    private void solve() throws IOException {
        int n = nextInt();
        int[] a = new int[n];
        for (int i = 0; i < n; i++) {
            a[i] = nextInt();
        }
        int[] r = a.clone();
        int res = 0;
        boolean enter = false;
        int i1 = -1;
        int j1 = -1;

        for (int i = 0; i < a.length; i++) {
            for (int j = 0; j < a.length; j++) {
                if (i == j)
                    continue;
                if (Math.abs(a[i] - a[j]) > 0) {
                    res = Math.abs(a[i] - a[j]) / 2;
                    if (a[i] < a[j]) {
                        a[i] += res;
                        a[j] -= res;
                        i1 = i;
                        j1 = j;
                    } else {
                        i1 = j;
                        j1 = i;
                        a[i] -= res;
                        a[j] += res;
                    }
                    enter = true;
                    Set<Integer> s = new HashSet<Integer>();
                    for (int L = 0; L < a.length; L++) {
                        s.add(a[L]);
                    }
                    if (s.size() == 1 && i1 != -1 &&  j1 != -1) {
                        System.out.printf("%d ml. from cup #%d to cup #%d.\n",
                                res, i1+1, j1+1);
                        return;
                    }
                    i1 = -1;
                    j1 = -1;
                    reset(a , r);
                }
            }
        }

        if (!enter) {
            System.out.println("Exemplary pages.");
            return;
        }
        System.out.println("Unrecoverable configuration.");
    }

    private void reset(int[] a , int [] r) {
        for (int i = 0; i < r.length; i++) {
            a[i] = r[i];
        }
    }

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

    BufferedReader reader;
    StringTokenizer tokenizer;
    PrintWriter writer;

    public void run() {
        try {
            reader = new BufferedReader(new InputStreamReader(System.in));
            tokenizer = null;
            writer = new PrintWriter(System.out);
            solve();
            reader.close();
            writer.close();
        } catch (Exception e) {
            e.printStackTrace();
            System.exit(1);
        }
    }

    int[] readIntArray(int size) throws IOException {
        int[] res = new int[size];
        for (int i = 0; i < size; i++) {
            res[i] = nextInt();
        }
        return res;
    }

    long[] readLongArray(int size) throws IOException {
        long[] res = new long[size];
        for (int i = 0; i < size; i++) {
            res[i] = nextLong();
        }
        return res;
    }

    double[] readDoubleArray(int size) throws IOException {
        double[] res = new double[size];
        for (int i = 0; i < size; i++) {
            res[i] = nextDouble();
        }
        return res;
    }

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

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

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

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

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

Unrecoverable configuration.
Unrecoverable configuration.
Unrecoverable configuration.
20 ml. from cup #4 to cup #1.
Exemplary pages.
Unrecoverable configuration.
Unrecoverable configuration.
Unrecoverable configuration.

n = int(input())
arr = [int(input()) for _ in range(n)]
if len(set(arr)) == 1:
    print('Exemplary pages.')
elif len(set(arr)) > 3:
    print('Unrecoverable configuration.')
else:
    kek = set(arr)
    kek = list(kek)
    kek.sort()
    val = kek[-1] - kek[0]
    if val % 2 == 1:
        print('Unrecoverable configuration.')
    else:
        val //= 2
        if len(kek) > 2 and (kek[1] - val != kek[0] or kek[1] + val != kek[-1]):
            print('Unrecoverable configuration.')
        else:
            x = kek[-1]
            y = kek[0]
            cnt1 = cnt2 = 0
            for x1 in arr:
                if x1 == x:
                    cnt1 += 1
                if x1 == y:
                    cnt2 += 1
            if cnt1 > 1 or cnt2 > 1:
                print('Unrecoverable configuration.')
            else:
                ind1, ind2 = 0, 0
                for i in range(n):
                    if arr[i] == x:
                        ind1 = i + 1
                    if arr[i] == y:
                        ind2 = i + 1
                print(str(val) + ' ml. from cup #' + str(ind2) + ' to cup #' + str(ind1) + '.')


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

public class Main {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(new BufferedInputStream(System.in));
        //int nCase = scanner.nextInt();
        //for (int iCase = 0; iCase < nCase; iCase++) {
        int n = scanner.nextInt();
        Point[] orig = new Point[n];
        for (int i = 0; i < n; i++) {
            orig[i] = new Point();
        }
        for (Point p : orig) {
            //p = new Point();
            p.x = scanner.nextInt();
            p.y = scanner.nextInt();
        }
        Arrays.sort(orig);
        superSet = new HashSet<Point>();
        divideAndMerge(orig, 0, orig.length - 1);
        superSet.addAll(Arrays.asList(orig));
        System.out.println(superSet.size());
        for (Point p : superSet) {
            System.out.println(p.x + " " + p.y);
        }
        //}
    }

    private static void divideAndMerge(Point[] orig, int left, int right) {
        int mid = (orig[left].x + orig[right].x) / 2;
        for (int i = left; i <= right; i++) {
            superSet.add(new Point(mid, orig[i].y));
        }
        int index = Arrays.binarySearch(orig, left, right + 1, new Point(mid, 0));
        if (index < 0) {
            index = -1 - index;
            divideAndMerge(orig, left, index - 1);
            divideAndMerge(orig, index, right);
        } else {
            if (left < index - 1) {
                divideAndMerge(orig, left, index - 1);
            }
            if (right > index + 1) {
                divideAndMerge(orig, index + 1, right);
            }
        }
    }

    private static class Point implements Comparable {

        int x, y;

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

        private Point() {
        }

        @Override
        public int hashCode() {
            int hash = 5;
            hash = 79 * hash + this.x;
            return hash;
        }

        @Override
        public boolean equals(Object o) {
            return x == ((Point) o).x && y == ((Point) o).y;
        }

        @Override
        public int compareTo(Object o) {
            return x - ((Point) o).x;
        }
    }
    private static HashSet<Point> superSet;
}

#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
const int INF = INT_MAX;
const long long LINF = LLONG_MAX;
const int N = 1e4 + 20;
pair<int, int> a[N];
set<pair<int, int> > s;
int n;
void solve(int l, int r) {
  if (r - l < 2) return;
  int mid = (l + r) / 2;
  solve(l, mid);
  solve(mid, r);
  int x = a[mid].first;
  for (int i = l; i < r; i++) s.insert(make_pair(x, a[i].second));
}
int main() {
  ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i].first >> a[i].second;
    s.insert(a[i]);
  }
  sort(a, a + n);
  solve(0, n);
  cout << s.size() << endl;
  for (auto x : s) cout << x.first << ' ' << x.second << endl;
}


import java.util.*;
public class cfCheeseboard {

    static int f1(int n){
        if(n==1){
            return 1;
        }
        int x= (n%2==0) ? (n-1) : n;
        return f1(n-1)+x;
    }

    public static void main(String[] args) {
        Scanner sc= new Scanner(System.in);
        int n = sc.nextInt();
        int b=0,w=0;
        for(int i=0;i<n;i++){
            String s=sc.next();
            String im=sc.next();
            if(im.charAt(0)=='s'){
                w++;
            }
            if(im.charAt(0)=='h'){
                b++;
            }

        }
        int c= Math.max(w,b);
        int arr[]=new int[100];
        for(int i=1;i<n+1;i++) {
            int xx=f1(i);

            if(c<=xx){
                if(w==b &&( n%2==1 || n==2)){
                    System.out.println(i+1);
                    break;
                }
            System.out.println(i);
            break;
        }}
    }
}

6
parmesan hard
emmental hard
edam hard
colby hard
gruyere hard
asiago hard

27
dbilglfh hard
iecrbay hard
cpunhmf hard
szvvz soft
qsbg hard
vdzexx hard
aiuvj soft
fuccez hard
dvscmzd hard
gps soft
dev hard
nwlfdh soft
nrlglw soft
ypff hard
wig hard
jvgtfo hard
zyp soft
cpgbws soft
xjsyjgi hard
izizf hard
izrwozx hard
wau hard
gzq hard
ffqa hard
najmkxn soft
vqtw hard
mymaoi hard

9
gorgonzola soft
cambozola soft
mascarpone soft
ricotta soft
mozzarella soft
bryndza soft
jarlsberg soft
havarti soft
stilton soft

17
gewvfeq soft
oaximz hard
xkfscel soft
nbxdbggw soft
gxgsscq hard
mqbu hard
btpzl soft
psv soft
iov soft
hliudz soft
bmiu soft
qqegoe hard
ufq soft
mgx soft
awjthx hard
onjmhee soft
xoarup soft

9
brie soft
camembert soft
feta soft
goat soft
muenster soft
asiago hard
cheddar hard
gouda hard
swiss hard

17
qojmshqd soft
cwbg hard
xomz soft
ymxfk soft
usledpbg hard
haaw hard
imwjce soft
aioff soft
sumpqbzx soft
zffbvrq hard
qosengs soft
kbori soft
kxsnrkc soft
wzsxh hard
isibmmg soft
hrfnj soft
hdaavekw soft

31
pevkjopz soft
smqei hard
xhfmuqua soft
gtmbnvn hard
kdvztv soft
cziuxm hard
gdswd hard
nawkigiz soft
eehdplwt hard
izhivjj soft
tvnkqkc hard
wefwgi hard
uxczrz hard
jdqudhgp soft
hmyzqb soft
wwlc soft
dsax soft
slefe soft
ahfitc hard
lztbmai soft
zcatg soft
hwlubzmy soft
jkbl soft
bfdfh soft
zshdiuce hard
eobyco soft
ckg hard
ahcwzw soft
vtaujlke soft
iwfdcik hard
itb soft

a, b = 0, 0
n = int(input())
for i in range(n):
    x, y = input().split()
    if y == 'soft':
        a += 1
    else:
        b += 1

for i in range(1, 1000):
    n = i*i
    y = n // 2
    x = n - y
    if (a <= x and b <= y) or (a <= y and b <= x):
        print(i)
        break


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

public class MainC {
	static final StdIn in = new StdIn();
	static final PrintWriter out = new PrintWriter(System.out);

	public static void main(String[] args) {
		int n=in.nextInt();
		int[] m = in.readIntArray(n, 0), nd = new int[n];
		nd[n-1]=m[n-1];
		for(int i=n-2; i>=0; --i)
			nd[i]=Math.max(m[i], nd[i+1]-1);
		for(int i=1; i<n; ++i)
			nd[i]=Math.max(nd[i-1], nd[i]);
		long ans=0;
		for(int i=0; i<n; ++i)
			ans+=nd[i]-m[i];
		out.println(ans);
		out.close();
	}

	static class StdIn {
		final private int BUFFER_SIZE = 1 << 16;
		private DataInputStream din;
		private byte[] buffer;
		private int bufferPointer, bytesRead;
		public StdIn() {
			din = new DataInputStream(System.in);
			buffer = new byte[BUFFER_SIZE];
			bufferPointer = bytesRead = 0;
		}
		public StdIn(InputStream in) {
			try{
				din = new DataInputStream(in);
			} catch(Exception e) {
				throw new RuntimeException();
			}
			buffer = new byte[BUFFER_SIZE];
			bufferPointer = bytesRead = 0;
		}
		public String next() {
			int c;
			while((c=read())!=-1&&(c==' '||c=='\n'||c=='\r'));
			StringBuilder s = new StringBuilder();
			while (c != -1)
			{
				if (c == ' ' || c == '\n'||c=='\r')
					break;
				s.append((char)c);
				c=read();
			}
			return s.toString();
		}
		public String nextLine() {
			int c;
			while((c=read())!=-1&&(c==' '||c=='\n'||c=='\r'));
			StringBuilder s = new StringBuilder();
			while (c != -1)
			{
				if (c == '\n'||c=='\r')
					break;
				s.append((char)c);
				c = read();
			}
			return s.toString();
		}
		public int nextInt() {
			int ret = 0;
			byte c = read();
			while (c <= ' ')
				c = read();
			boolean neg = (c == '-');
			if (neg)
				c = read();
			do
				ret = ret * 10 + c - '0';
			while ((c = read()) >= '0' && c <= '9');

			if (neg)
				return -ret;
			return ret;
		}
		public int[] readIntArray(int n, int os) {
			int[] ar = new int[n];
			for(int i=0; i<n; ++i)
				ar[i]=nextInt()+os;
			return ar;
		}
		public long nextLong() {
			long ret = 0;
			byte c = read();
			while (c <= ' ')
				c = read();
			boolean neg = (c == '-');
			if (neg)
				c = read();
			do
				ret = ret * 10 + c - '0';
			while ((c = read()) >= '0' && c <= '9');
			if (neg)
				return -ret;
			return ret;
		}
		public long[] readLongArray(int n, long os) {
			long[] ar = new long[n];
			for(int i=0; i<n; ++i)
				ar[i]=nextLong()+os;
			return ar;
		}
		public double nextDouble() {
			double ret = 0, div = 1;
			byte c = read();
			while (c <= ' ')
				c = read();
			boolean neg = (c == '-');
			if (neg)
				c = read();
			do
				ret = ret * 10 + c - '0';
			while ((c = read()) >= '0' && c <= '9');
			if (c == '.')
				while ((c = read()) >= '0' && c <= '9')
					ret += (c - '0') / (div *= 10);
			if (neg)
				return -ret;
			return ret;
		}
		private void fillBuffer() throws IOException {
			bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE);
			if (bytesRead == -1)
				buffer[0] = -1;
		}
		private byte read() {
			try{
				if (bufferPointer == bytesRead)
					fillBuffer();
				return buffer[bufferPointer++];
			} catch(IOException e) {
				throw new RuntimeException();
			}
		}
		public void close() throws IOException {
			if (din == null)
				return;
			din.close();
		}
	}
}

N = int(input())
above = list(map(int, input().split()))

if N == 1:
    print(0)
    quit()

required_mark = [0] * N
required_mark[N-2] = above[N-1]
for i in reversed(range(N-2)):
    required_mark[i] = max(above[i+1], required_mark[i+1] - 1)

d = 0
mark = 1
for i in range(1, N):
    if mark == above[i]:
        mark += 1
    elif mark >= required_mark[i]:
        d += mark - above[i] - 1
    else:
        d += mark - above[i]
        mark += 1

print(d)


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.StringTokenizer;

/**
 * Created by nischal.k on 02/10/16.
 */
public class Main {
    public static void main(String[] args) throws java.lang.Exception {
        Reader.init(System.in);
//        int t = Reader.nextInt();
//        while ((t--)>=0) {
//            String org = Reader.next();
//            String transform = Reader.next();
//            int dp[][] = new int[org.length()][transform.length()];
//            for (int i = 0; i < org.length(); i++) {
//                for (int j = 0; j < transform.length(); j++) {
//                    if (org.charAt(i) == transform.charAt(j)) {
//                        if (i >= 1 && j >= 1) {
//                            dp[i][j] = dp[i - 1][j - 1] + 1;
//                        } else {
//                            dp[i][j]=1;
//                        }
//                    } else {
//                        dp[i][j] = maxxer(dp, i, j);
//                    }
//                }
//            }
//            System.out.println(dp[org.length() - 1][transform.length() - 1]);
//        }
        int n,m;
        n = Reader.nextInt();
        m = Reader.nextInt();
        int[] ar= new int[105];
        List<Pair> data = new ArrayList<>();
        for (int i = 0; i < n; i++) {
            int a = Reader.nextInt();
            int b = Reader.nextInt();
            data.add(new Pair(a,b));
        }
//        Comparator<Pair> comparator = (Comparator<Pair>) (pair, t1) -> {
//            if(pair.getFirst() ==t1.getFirst()) {
//                return pair.getSecond() - t1.getSecond();
//            }
//            return pair.getFirst() - t1.getFirst();
//        };
//        data.sort(comparator);
        boolean flag = true;

        for (int i = 0; i < data.size(); i++) {
            for (int j = data.get(i).getFirst(); j < data.get(i).getSecond(); j++) {
                ar[j]=1;
            }
            if(ar[data.get(i).getSecond()]==0) {
                ar[data.get(i).getSecond()]=99;
            }
        }
        for (int i = 0; i < m; i++) {
            if(ar[i]==0 || ar[i]==99) {
                flag= false;
                break;
            }
        }
        if(ar[m]<1) {
            flag=false;
        }
//        int i = 0,j=0,k=0;
//        while (data.get(0).getFirst()==0 && true) {
//            k=data.get(i).getSecond();
//            if(k>=m) {
//                flag= true;
//                break;
//            }
//            int max = i;
//            for (int l = 0; l < data.size(); l++) {
//                if(data.get(l).getFirst()<=k && max < data.get(l).getSecond()) {
//                    max = l;
//                }
//            }
//            if(i==max) {
//                break;
//            }
//            i=max;
//        }

        if(flag) {
            System.out.println("YES");
        }else {
            System.out.println("NO");

        }
    }
//        int n = Reader.nextInt();
//        int m = Reader.nextInt();

    static int maxxer(int[][] dp, int i, int j) {
        int min = -1;
        if(i-1>=0) {
            min = Math.max(min, dp[i-1][j]);
        }
        if(j-1>=0) {
            min = Math.max(min, dp[i][j-1]);
        }
        return min;
    }

}
class Pair {
    int first;
    int second;

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

    public int getFirst() {
        return first;
    }

    public int getSecond() {
        return second;
    }
}
class Node {
    int start;
    int end;
}
class Reader {
    static BufferedReader reader;
    static StringTokenizer tokenizer;

    /**
     * call this method to initialize reader for InputStream
     */
    static void init(InputStream input) {
        reader = new BufferedReader(
                new InputStreamReader(input));
        tokenizer = new StringTokenizer("");

    }

    /**
     * get next word
     */
    static String next() throws IOException {
        while (!tokenizer.hasMoreTokens()) {
//            TODO add check for eof if necessary
            tokenizer = new StringTokenizer(
                    reader.readLine());
        }
        return tokenizer.nextToken();
    }

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

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

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

n, m = list( map( int, input().split() ) )

A = []
B = []
CanReach = []

start_idx = 0
end_idx = 0

for i in range( n ):
    a, b = list( map( int, input().split() ) )
    A.append( a )
    B.append( b )

memo = {}

def best( i ):

    if A[i] <= m <= B[i]:
        return ( True )

    if i in memo:
        return memo[i]

    Best = False
    for j in range( i+1, n ):
        if A[j] <= B[i] <= B[j]:
            Best |= best( j )

    if i not in memo:
        memo[i] = Best

    return ( Best )

for i in range( n ):
    if A[i] == 0:
        if best( i ):
            print( "YES" )
            exit(0)

print( "NO" )


import java.util.Scanner;

public class Fraction{

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

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

  double max = 0.0;
  int numerator = 1;

  for (int i = 1; i <= n / 2; ++i)
  {
	int a = i;
	int b = n - i;

	if (gcd(a, b) == 1)
	{
	  if (a > b * max)
	  {
		max = a / b;
		numerator = i;
	  }
	}
  }

  System.out.print(numerator);
  System.out.print(" ");
  System.out.print(n - numerator);
  System.out.print("\n");
 }
}

import math
n=int(input())
d=n//2
c=n-d
while math.gcd(c,d)!=1:
    c+=1
    d-=1
print(d,c)


#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(0);
  int n, m;
  cin >> n >> m;
  vector<int> val(n);
  for (auto &i : val) cin >> i;
  int a, b;
  long long res = 0;
  for (int i = 0; i < m; ++i) {
    cin >> a >> b;
    long long t = 0;
    for (int j = a - 1; j < b; ++j) t += val[j];
    if (t > 0) res += t;
  }
  cout << res << endl;
  return 0;
}

I=lambda:map(int,input().split())
R=range
ans=0
n,m=I()
a=list(I())
for _ in R(m):l,r=I();ans+=max(0,sum(a[i]for i in R(l-1,r)))
print(ans)


#include <bits/stdc++.h>
using namespace std;
const int mod = 1000000007;
const int inf = 1001001001;
long long n, a, b, c, ans;
int main() {
  ios_base::sync_with_stdio(0);
  cin >> n >> a >> b >> c;
  if (n < min(a, b)) {
    cout << 0;
    return 0;
  }
  if (a > b - c && n - b >= 0) {
    ans = (n - b) / (b - c) + 1 + ((n - b) % (b - c) + c) / a;
  } else {
    ans = n / a;
  }
  cout << ans;
  return 0;
}

import java.io.*;

import java.util.*;

public class Main {
	//public static Node node[];

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

InputStreamReader isr=new InputStreamReader(System.in);

 BufferedReader br=new BufferedReader(isr);

	 //StringTokenizer st=new StringTokenizer(br.readLine());
long a=Long.parseLong(br.readLine());
long b=Long.parseLong(br.readLine());
long c=Long.parseLong(br.readLine());
long d=Long.parseLong(br.readLine());

long ans=a/b;

if(c <= a)
{
	long x=1 ;
	a=a-c;
	long y=a/(c-d);
	a=a-y*(c-d);
	a=a+d;
	System.out.println(Math.max(ans, x+y+a/b));

}
else System.out.println(ans);

	}}


#include <bits/stdc++.h>
using namespace std;
bool roads[405][405];
int bfs(int n, bool road_type) {
  queue<int> towns;
  towns.push(1);
  bool visited[405];
  int road_length[405];
  for (int i = 1; i <= n; i++) {
    visited[i] = false;
    road_length[i] = -1;
  }
  road_length[1] = 0;
  visited[1] = true;
  while (!towns.empty()) {
    int current = towns.front();
    towns.pop();
    for (int town = 1; town <= n; town++) {
      if (roads[current][town] == road_type && !visited[town]) {
        visited[town] = true;
        towns.push(town);
        road_length[town] = road_length[current] + 1;
      }
    }
  }
  return road_length[n];
}
int main() {
  int n, m;
  cin >> n >> m;
  int x, y;
  while (m--) {
    cin >> x >> y;
    roads[x][y] = true;
    roads[y][x] = true;
  }
  int ans1 = bfs(n, false);
  int ans2 = bfs(n, true);
  if (ans1 == -1 || ans2 == -1) {
    cout << "-1" << endl;
  } else {
    cout << max(ans1, ans2) << endl;
  }
  return 0;
}

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

public class Rail {

	public static Integer[] parse(String st) {
		String[] a = st.split(" ");
		Integer[] ar = new Integer[a.length];
		for (int i = 0; i < a.length; i++)
			ar[i] = Integer.parseInt(a[i]);
		return ar;
	}

	public static int solve(boolean[][] rail) {
		int best = Integer.MAX_VALUE;
		LinkedList<Integer[]> todo = new LinkedList<>();
		todo.add(new Integer[] {1, 0});
		while (!todo.isEmpty()) {
			Integer[] cur = todo.remove();
			int x = cur[0];
			if (x == rail.length - 1) {
				if (cur[1] < best) best = cur[1];
			} else {
				for (int i = 1; i < rail.length; i++) {
					if (rail[x][i]) {
						rail[x][i] = false;
						todo.add(new Integer[] {i, cur[1] + 1});
					}
				}
			}
		}
		if (best == Integer.MAX_VALUE) return -1;
		return best;
	}

	public static boolean[][] adjMat(ArrayList<Integer[]> edges, int verts) {
		boolean[][] out = new boolean[verts + 1][verts + 1];
		for (Integer[] edge : edges) {
			int x = edge[0]; int y = edge[1];
			out[x][y] = true;
			out[y][x] = true;
		}
		return out;
	}

	public static boolean[][] complement(boolean[][] adjMat) {
		for (int i = 1; i < adjMat.length; i++) {
			for (int j = 1; j < adjMat[0].length; j++) {
				adjMat[i][j] = !adjMat[i][j];
			}
		}
		return adjMat;
	}

	public static void print(boolean[][] a) {
		for (boolean[] ar : a) System.out.println(Arrays.toString(ar));
	}

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

			Integer[] p = parse(br.readLine());
			ArrayList<Integer[]> edges = new ArrayList<>();
			for (int i = 0; i < p[1]; i++) edges.add(parse(br.readLine()));
			boolean[][] am = adjMat(edges, p[0]);
			boolean[][] amp = new boolean[am.length][am.length];
			for (int i = 0; i < amp.length; i++)
				amp[i] = Arrays.copyOfRange(am[i], 0, am[i].length);
			amp = complement(amp);

			int s1 = solve(am);
			int s2 = solve(amp);

			if (s1 == -1 || s2 == -1) {
				System.out.println(-1);
			} else {
				System.out.println(Math.max(s1, s2));
			}
		} catch (Exception e) {e.printStackTrace();}
	}

}


def main():
    n, m = map(int, input().split())
    n += 1
    cluster, dest, ab = list(range(n)), [0] * n, [[] for _ in range(n)]

    def root(x):
        if x != cluster[x]:
            cluster[x] = x = root(cluster[x])
        return x

    for _ in range(m):
        a, b = map(int, input().split())
        ab[a].append(b)
        dest[b] += 1
        cluster[root(a)] = root(b)
    pool = [a for a, f in enumerate(dest) if not f]
    for a in pool:
        for b in ab[a]:
            dest[b] -= 1
            if not dest[b]:
                pool.append(b)
    ab = [True] * n
    for a, f in enumerate(dest):
        if f:
            ab[root(a)] = False
    print(n - sum(f and a == c for a, c, f in zip(range(n), cluster, ab)))

if __name__ == '__main__':
    from sys import setrecursionlimit

    setrecursionlimit(100500)
    main()

#include <bits/stdc++.h>
using namespace std;
const int N = 100005;
vector<int> v[N];
int n, m, f[N], deg[N], fa[N];
int getf(int v) { return f[v] == v ? v : f[v] = getf(f[v]); }
inline void merge(int x, int y) {
  x = getf(x);
  y = getf(y);
  if (x != y) f[x] = y;
}
bool vis[N];
int main() {
  ios::sync_with_stdio(false);
  cin >> n >> m;
  for (int i = 1; i <= n; i++) f[i] = i;
  for (int i = 1; i <= m; i++) {
    int t1, t2;
    cin >> t1 >> t2;
    v[t1].push_back(t2);
    merge(t1, t2);
    ++deg[t2];
  }
  int ans = n;
  for (int i = 1; i <= n; i++) {
    fa[i] = getf(i);
    if (!vis[fa[i]]) --ans, vis[fa[i]] = 1;
  }
  queue<int> q;
  for (int i = 1; i <= n; i++)
    if (!deg[i]) q.push(i);
  while (!q.empty()) {
    int nd = q.front();
    q.pop();
    for (auto &i : v[nd])
      if (!--deg[i]) q.push(i);
  }
  for (int i = 1; i <= n; i++)
    if (deg[i]) ans += vis[fa[i]], vis[fa[i]] = 0;
  cout << ans << endl;
  return 0;
}


#include <bits/stdc++.h>
using namespace std;
char a[100], b[100];
int main() {
  int a[10];
  int b[10];
  a[0] = 1;
  a[1] = 1;
  a[2] = 2;
  a[3] = 7;
  a[4] = 4;
  int x;
  int cnt = 100000000;
  for (int i = 0; i < 5; i++) {
    scanf("%d", &x);
    cnt = min(cnt, x / a[i]);
  }
  cout << cnt << endl;
  return 0;
}

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

import static java.lang.Math.min;

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

    public static void main(String[] args) throws IOException {
        int a = nextInt();
        int b = nextInt();
        int c = nextInt();
        int d = nextInt();
        int e = nextInt();
        System.out.println(min(a, min(b, min(c / 2, min(d / 7, e / 4)))));
    }

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


#include <bits/stdc++.h>
using namespace std;
bool b;
long long ans, cnt, sum2;
string num_to_string(int num) {
  stringstream ss;
  ss << num;
  return ss.str();
}
void O_o() {
  ios::sync_with_stdio(0);
  ios_base::sync_with_stdio(0);
  cin.tie(0), cout.tie(0);
}
int main() {
  O_o();
  int n, k;
  string s;
  cin >> n >> k;
  for (int i = 0; i < n; i++) {
    cin >> s;
    set<int> ss;
    b = 0;
    for (int j = 0; j < ((int)(s.size())); j++) ss.insert(s[j] - '0');
    int x = 0;
    for (auto j : ss) {
      if (j != x) b = 1;
      if (x == k) break;
      x++;
    }
    if (((int)(ss.size())) < k + 1 || x != k) b = 1;
    if (!b) cnt++;
  }
  cout << cnt << endl;
  return 0;
}

import sys
x=input().split()
n=int(x[0])
k=int(x[1])
list=[]
for i in range(0,n):
    y=input()
    list.append(y)
l=0
for j in list:
    flag=1
    for z in range(0,k+1):
        if str(z) not in j:
            flag=0
            break
    if flag==1:
        l=l+1

print(l)


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintStream;
import java.io.IOException;
import java.io.UncheckedIOException;
import java.io.Closeable;
import java.io.Writer;
import java.io.OutputStreamWriter;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) throws Exception {
        Thread thread = new Thread(null, new TaskAdapter(), "", 1 << 29);
        thread.start();
        thread.join();
    }

    static class TaskAdapter implements Runnable {
        @Override
        public void run() {
            InputStream inputStream = System.in;
            OutputStream outputStream = System.out;
            FastInput in = new FastInput(inputStream);
            FastOutput out = new FastOutput(outputStream);
            DGameWithPowers solver = new DGameWithPowers();
            solver.solve(1, in, out);
            out.close();
        }
    }

    static class DGameWithPowers {
        int[] bitMask = new int[32];
        int[] sg = new int[]{0, 1, 2, 1, 4, 3, 2, 1, 5, 6, 2, 1, 8, 7, 5, 9, 8, 7, 3, 4, 7, 4, 2, 1, 10, 9, 3, 6, 11, 12, 14};
        Debug debug = new Debug(true);

        {
            for (int i = 1; i < 32; i++) {
                for (int j = i; j < 32; j += i) {
                    bitMask[i] |= 1 << j;
                }
                bitMask[i] = ~bitMask[i];
            }
        }

        public void solve(int testNumber, FastInput in, FastOutput out) {
            int n = in.ri();
            MultiplicativeFunctionSieve sieve = new MultiplicativeFunctionSieve((int) 1e5);
            int[] factors = sieve.getSmallestPrimeFactor();
            int bit = 2;
            int total = 1;
            for (int i = 2; i * i <= n; i++) {
                int g = 0;
                int cur = i;
                while (cur > 1) {
                    int sum = 0;
                    int f = factors[cur];
                    while (cur % f == 0) {
                        cur /= f;
                        sum++;
                    }
                    g = GCDs.gcd(g, sum);
                }
                if (g == 1) {
                    int len = 1;
                    long x = i;
                    while (x * i <= n) {
                        len++;
                        x *= i;
                    }
                    bit ^= 1 << len;
                    total += len;
                }
            }
            int miss = n - total;
            bit ^= (miss & 1) << 1;

            debug.debug("bit", bit);
            int sg = 0;
            for (int i = 1; i < 31; i++) {
                if (Bits.get(bit, i) == 0) {
                    continue;
                }
                sg ^= this.sg[i];
            }
            out.println(sg == 0 ? "Petya" : "Vasya");
        }

    }

    static class FastOutput implements AutoCloseable, Closeable, Appendable {
        private static final int THRESHOLD = 32 << 10;
        private final Writer os;
        private StringBuilder cache = new StringBuilder(THRESHOLD * 2);

        public FastOutput append(CharSequence csq) {
            cache.append(csq);
            return this;
        }

        public FastOutput append(CharSequence csq, int start, int end) {
            cache.append(csq, start, end);
            return this;
        }

        private void afterWrite() {
            if (cache.length() < THRESHOLD) {
                return;
            }
            flush();
        }

        public FastOutput(Writer os) {
            this.os = os;
        }

        public FastOutput(OutputStream os) {
            this(new OutputStreamWriter(os));
        }

        public FastOutput append(char c) {
            cache.append(c);
            afterWrite();
            return this;
        }

        public FastOutput append(String c) {
            cache.append(c);
            afterWrite();
            return this;
        }

        public FastOutput println(String c) {
            return append(c).println();
        }

        public FastOutput println() {
            return append('\n');
        }

        public FastOutput flush() {
            try {
//            boolean success = false;
//            if (stringBuilderValueField != null) {
//                try {
//                    char[] value = (char[]) stringBuilderValueField.get(cache);
//                    os.write(value, 0, cache.length());
//                    success = true;
//                } catch (Exception e) {
//                }
//            }
//            if (!success) {
                os.append(cache);
//            }
                os.flush();
                cache.setLength(0);
            } catch (IOException e) {
                throw new UncheckedIOException(e);
            }
            return this;
        }

        public void close() {
            flush();
            try {
                os.close();
            } catch (IOException e) {
                throw new UncheckedIOException(e);
            }
        }

        public String toString() {
            return cache.toString();
        }

    }

    static class FastInput {
        private final InputStream is;
        private byte[] buf = new byte[1 << 13];
        private int bufLen;
        private int bufOffset;
        private int next;

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

        private int read() {
            while (bufLen == bufOffset) {
                bufOffset = 0;
                try {
                    bufLen = is.read(buf);
                } catch (IOException e) {
                    bufLen = -1;
                }
                if (bufLen == -1) {
                    return -1;
                }
            }
            return buf[bufOffset++];
        }

        public void skipBlank() {
            while (next >= 0 && next <= 32) {
                next = read();
            }
        }

        public int ri() {
            return readInt();
        }

        public int readInt() {
            boolean rev = false;

            skipBlank();
            if (next == '+' || next == '-') {
                rev = next == '-';
                next = read();
            }

            int val = 0;
            while (next >= '0' && next <= '9') {
                val = val * 10 - next + '0';
                next = read();
            }

            return rev ? val : -val;
        }

    }

    static class GCDs {
        private GCDs() {
        }

        public static int gcd(int a, int b) {
            return a >= b ? gcd0(a, b) : gcd0(b, a);
        }

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

    }

    static class Bits {
        private Bits() {
        }

        public static int get(int x, int i) {
            return (x >>> i) & 1;
        }

    }

    static class Debug {
        private boolean offline;
        private PrintStream out = System.err;

        public Debug(boolean enable) {
            offline = enable && System.getSecurityManager() == null;
        }

        public Debug debug(String name, int x) {
            if (offline) {
                debug(name, "" + x);
            }
            return this;
        }

        public Debug debug(String name, String x) {
            if (offline) {
                out.printf("%s=%s", name, x);
                out.println();
            }
            return this;
        }

    }

    static class MultiplicativeFunctionSieve {
        public int[] primes;
        public boolean[] isComp;
        public int primeLength;
        public int[] smallestPrimeFactor;
        public int[] expOfSmallestPrimeFactor;
        int limit;

        public int[] getSmallestPrimeFactor() {
            return smallestPrimeFactor;
        }

        public MultiplicativeFunctionSieve(int limit) {
            this.limit = limit;
            isComp = new boolean[limit + 1];
            primes = new int[limit + 1];
            expOfSmallestPrimeFactor = new int[limit + 1];
            smallestPrimeFactor = new int[limit + 1];
            primeLength = 0;
            for (int i = 2; i <= limit; i++) {
                if (!isComp[i]) {
                    primes[primeLength++] = i;
                    expOfSmallestPrimeFactor[i] = smallestPrimeFactor[i] = i;
                }
                for (int j = 0, until = limit / i; j < primeLength && primes[j] <= until; j++) {
                    int pi = primes[j] * i;
                    smallestPrimeFactor[pi] = primes[j];
                    expOfSmallestPrimeFactor[pi] = smallestPrimeFactor[i] == primes[j]
                            ? (expOfSmallestPrimeFactor[i] * expOfSmallestPrimeFactor[primes[j]])
                            : expOfSmallestPrimeFactor[primes[j]];
                    isComp[pi] = true;
                    if (i % primes[j] == 0) {
                        break;
                    }
                }
            }
        }

    }
}

Vasya Vasya Petya Vasya Vasya Vasya Vasya Vasya Vasya Vasya Vasya Vasya Vasya Vasya Vasya Vasya Vasya Vasya Vasya Vasya Vasya Vasya Vasya Vasya Vasya Vasya Vasya Vasya Vasya Petya Petya Vasya Vasya Vasya Vasya Vasya Vasya Petya Vasya Petya Vasya Vasya Vasya Vasya Vasya Vasya Vasya Vasya Petya Petya Petya Vasya Vasya Petya Vasya Vasya Vasya Vasya Petya Petya Vasya Vasya Petya Vasya Petya Vasya Petya Vasya Vasya Vasya Vasya Vasya Vasya Petya Vasya Vasya Petya Vasya Vasya Vasya Vasya Vasya Vasya Vasya Vasya Vasya Vasya Vasya Vasya Petya Vasya Vasya Vasya Vasya Vasya Vasya Vasya Petya Vasya Vasya Petya Vasya Petya Vasya Petya Vasya Vasya Vasya Petya

#include <bits/stdc++.h>
using namespace std;
const int sq = 40 * 1000;
bool used[sq + 1];
const int G[30] = {0, 1, 2, 1, 4, 3, 2, 1, 5, 6,  2, 1, 8, 7,  5,
                   9, 8, 7, 3, 4, 7, 4, 2, 1, 10, 9, 3, 6, 11, 12};
int main() {
  int n;
  cin >> n;
  int res = 0;
  int after_sq = 0;
  for (int i = 1; i <= sq; ++i) {
    if (used[i]) {
      continue;
    }
    int cnt = i == 1;
    for (long long j = i; i != 1 && j <= n; j *= i) {
      if (j <= sq) {
        used[j] = true;
      } else {
        ++after_sq;
      }
      ++cnt;
    }
    res ^= G[cnt];
  }
  res ^= (n > sq ? (n - sq - after_sq) : 0) & 1;
  if (res) {
    cout << "Vasya\n";
  } else {
    cout << "Petya\n";
  }
  return 0;
}


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

    import java.util.*;
    public class Main{
        public static void main(String args[]){
            Scanner sc=new Scanner(System.in);
            int n=sc.nextInt();
            int a[]=new int[n];
            for(int i=0;i<n;i++){
                a[i]=sc.nextInt();

            }
            int m=sc.nextInt();
            for(int i=0;i<m;i++){
                int x=sc.nextInt();
                int y=sc.nextInt();
                x=x-1;
                if(n==1){a[x]=0;}
                else if(x==0){a[x+1]=a[x+1]+a[x]-y;a[x]=0;}
                else if(x==n-1){a[x-1]=a[x-1]+y-1;a[x]=0;}
                else{a[x-1]=a[x-1]+y-1;a[x+1]=a[x+1]+a[x]-y;a[x]=0;}
            }
        for(int i:a){
            System.out.println(i);
        }
    }}


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

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

    static class B269 {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.nextInt();
            int m = in.nextInt();
            int[] a = new int[n];
            for (int i = 0; i < n; ++i) {
                a[i] = in.nextInt();
                in.next();
            }
            int[] dp = new int[n];
            int max = 1;
            for (int i = 0; i < n; ++i) {
                dp[i] = 1;
                for (int j = 0; j < i; ++j) {
                    if (a[i] >= a[j]) {
                        dp[i] = Math.max(dp[i], dp[j] + 1);
                        max = Math.max(max, dp[i]);
                    }
                }
            }
            out.println(n - max);
        }

    }

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

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

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

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

    }
}

#include <bits/stdc++.h>
using namespace std;
int xx[5002][5002];
int lon_com_sub(int *ar, int *br, int n) {
  int i, j;
  for (i = 0; i <= n; i++) {
    for (j = 0; j <= n; j++) {
      if (i == 0 || j == 0)
        xx[i][j] = 0;
      else if (ar[i - 1] == br[j - 1])
        xx[i][j] = xx[i - 1][j - 1] + 1;
      else {
        if (xx[i - 1][j] > xx[i][j - 1])
          xx[i][j] = xx[i - 1][j];
        else
          xx[i][j] = xx[i][j - 1];
      }
    }
  }
  return xx[n][n];
}
int main() {
  int n, m, i, x;
  int ar[5002];
  double arr[5002];
  int br[5002];
  scanf("%d %d", &n, &m);
  for (i = 0; i < n; i++) {
    scanf("%d %lf", &ar[i], &arr[i]);
    br[i] = ar[i];
  }
  sort(br, br + n);
  x = lon_com_sub(ar, br, n);
  printf("%d\n", n - x);
  return 0;
}


#include <bits/stdc++.h>
using namespace std;
int const MAX = 1000 * 1000 * 1000;
int main() {
  long long a, b, m, i;
  cin >> a >> b >> m;
  if (m <= b + 1 || MAX % m == 0) {
    cout << 2;
    return 0;
  }
  for (i = 1; i <= min(m - 1, a); ++i) {
    int k = MAX * i % m;
    if (0 < k && k < m - b) {
      printf("1\n%09I64d", i);
      return 0;
    }
  }
  cout << 2;
  return 0;
}

41 0 193
```

Note that the length of each sample input is less than or equal to 40 tokens, and each sample input conforms to the input data format described in the problem statement.

import java.io.PrintWriter;
import java.util.Scanner;

public class TaskB {
    /**
     * @param args
     */
    public static void main(String[] args) {
        TaskB task = new TaskB();
        task.read();
        task.write();
    }

    long a,b;
    long mod;

    public void read() {
        Scanner in = new Scanner(System.in);
        // init
        a = in.nextLong();
        b = in.nextLong();
        mod = in.nextLong();
        in.close();
    }

    public void write() {
        PrintWriter out = new PrintWriter(System.out);
        long mul = 1000000000 % mod;
        for (long i = 1; i <= Math.min(a, mod); i++){
            if (((i * mul) % mod) != 0 && mod  - ((i * mul) % mod) > b){
                out.printf("1 %09d\n", i);
                out.close();
                return;
            }
        }
        out.println("2");
        out.close();
    }
}


#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  while (cin >> n) {
    for (int i = 0; i < n; i++) cout << (char)('a' + i % 4);
    cout << endl;
  }
}

import java.util.Scanner;

public class LuckyString {
    public static void main(String asd[])throws Exception
    {
        Scanner in=new Scanner(System.in);
        int n=in.nextInt();
        char ch[]=new char[n];
            for(int i=0;i<n;i+=4)
                ch[i]='a';
            char c='b';
            int m=n%4-1,k=n/4;
           //System.out.println(m+""+k);
            for(int i=0;i<4*k;i+=4)
            {
                c='b';
                for(int j=1;j<=3;j++)
                {
                    ch[i+j]=c;
                    c++;
                }
            }
           c='b';
           for(int i=1;i<=m;i++)
           {
               ch[4*k+i]=c;
               c++;
           }
           for(int i=0;i<n;i++)
               System.out.print(ch[i]);

    }
}


/*
 * UMANG PANCHAL
 * DAIICT
 */

import java.util.*;
import java.io.*;
import java.math.*;
import java.util.Comparator;
public class Main
{

	private static final Comparator<? super Integer> Comparator = null;
	static LinkedList<Integer> adj[];
	static ArrayList<Integer> adj1[];
	static int[] color,visited1;
	static boolean b[],visited[],possible;
	static int level[];
	static Map<Integer,HashSet<Integer>> s;
	static int totalnodes,colored;
	static int count[];
	static long sum[];
	static int nodes;
	static long ans=0;
	static long[] as=new long[10001];
	static long c1=0,c2=0;
	static int[] a,d,k;
	static int max=100000000;
	static long MOD = 1000000007,sm=0,m=Long.MIN_VALUE;
	static boolean[] prime=new boolean[1000005];
	static int[] levl;
    static int[] eat;
    static int price[];
    static int res[],par[],co[];
    static int result=0;
    static int[] root,size,du,dv;
    static long p=Long.MAX_VALUE;
    static int start,end,r=0;
    static boolean[] vis1,vis2;
    static long n;

	// --------------------My Code Starts Here----------------------

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

	       int n=ni(),k=ni();
	       long d=nl();
	       long[] a=new long[n];
	       for(int i=0;i<n;i++)
	    	   a[i]=nl();
	       shuffle(a,n);
	       Arrays.sort(a);
	       int[] dp=new int[n];
	       int pos=-1;
	       for(int i=k-1;i<n;i++)
	       {
	    	   if(i!=k-1 && dp[i-k]==1)
	    		   pos=i-k;
	    	   if(a[i]-a[pos+1]<=d)
	    		   dp[i]=1;
	       }
	    if(dp[n-1]==1)
	    	w.print("YES");
	    else
	    	w.print("NO");

   w.close();
   }

	// --------------------My Code Ends Here------------------------

	/*
	 *  PriorityQueue<Integer> pq = new PriorityQueue<Integer>(new Comparator<Integer>()
  			{
  				public int compare(Integer o1, Integer o2)
  				{
  					return Intege
  					r.compare(o2,o1);
  				}
  			});
	 *
	 *
	 */
	public static void shuffle(long[] a,int n)
	{
		Random r=new Random();
		for(int i=n-1;i>0;i--)
		{
			int j=r.nextInt(i);
			long t=a[j];
			a[j]=a[i];
			a[i]=t;
		}
	}
	public static void bfs1(int u)
	{
	    Queue<Integer> q=new LinkedList();
	    q.add(u);
	    visited[u]=true;
	    while(!q.isEmpty())
	    {
	    	//w.print(1);
	    	int p=q.poll();
	      for(int i=0;i<adj[p].size();i++)
	     {
	    	  if(!visited[adj[p].get(i)])
	    	  {
	    	q.add(adj[p].get(i));
	    	visited[adj[p].get(i)]=true;
	    	  }
	    	  levl[adj[p].get(i)]=levl[p]+1;
	    	  }
	    }

	}
	public static void bfs2(int u)
	{
	    Queue<Integer> q=new LinkedList();
	    q.add(u);
	    vis2[u]=true;
	    while(!q.isEmpty())
	    {
	    	int p=q.poll();
	      for(int i=0;i<adj[p].size();i++)
	     {
	    	  if(!vis2[adj[p].get(i)])
	    	  {
	    	dv[adj[p].get(i)]=dv[p]+1;
	    	q.add(adj[p].get(i));

	    	vis2[adj[p].get(i)]=true;
	    	  }
	    	  }
	    }

	}
	 public static void buildgraph(int n)
	 {
         adj=new LinkedList[n+1];
         visited=new boolean[n];
         level=new int[n];
         par=new int[n];
         for(int i=0;i<=n;i++)
         	{
        	 adj[i]=new LinkedList<Integer>();

         	}

	 }

	/*public static long kruskal(Pair[] p)
	{
		long ans=0;
		int w=0,x=0,y=0;
		for(int i=0;i<p.length;i++)
		{
			w=p[i].w;
			x=p[i].x;
			y=p[i].y;
			if(root(x)!=root(y))
			{
				ans+=w;
				union(x,y);
			}
		}
		return ans;
	}*/

	 static class Pair implements Comparable<Pair>
	 {
		 Long x,w;
		 Integer ind;
	        Pair(long x,long w,int ind)
	        {
	            this.x=x;
	            this.w=w;
	            this.ind=ind;
	        }
	        public int compareTo(Pair p)
	        {
	            return Long.compare(this.w,p.w);
	        }

	}
	 static  class npair implements Comparable<npair>
	 {
	     int a,b;

		npair(int a,int b)
		{
			this.a=a;
			this.b=b;
			//this.index=index;
		}

		public int compareTo(npair o) {
			// TODO Auto-generated method stub
			return Integer.compare(this.a,o.a);
		}

	}
	public static int root(int i)
	{
		while(root[i]!=i)
		{
			root[i]=root[root[i]];
			i=root[i];
		}
		return i;
	}

	public static void init(int n)
	{
		root=new int[n+1];
		for(int i=1;i<=n;i++)
			root[i]=i;
	}
	public static void union(int a,int b)
	{
	    int root_a=root(a);
	    int root_b=root(b);
	    root[root_a]=root_b;
	   // size[root_b]+=size[root_a];
	}

	public static boolean isPrime(long n)
	{
	    // Corner cases
	    if (n <= 1)  return false;
	    if (n <= 3)  return true;

	    // This is checked so that we can skip
	    // middle five numbers in below loop
	    if (n%2 == 0 || n%3 == 0)
	    	return false;

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

	    return true;
	}

	public static String ns()
	{
		return in.nextLine();
	}
	public static int ni()
	{
		return in.nextInt();
	}
	public static long nl()
	{
		return in.nextLong();
	}
	public static int[] na(int n)
	{
		int[] a=new int[n];
		for(int i=0;i<n;i++)
		a[i]=ni();
		return a;
	}
	public static long[] nla(int n)
	{
		long[] a=new long[n];
		for(int i=0;i<n;i++)
		a[i]=nl();
		return a;
	}
	public static void sieve()
	    {
	       int n=prime.length;
	        for(int i=0;i<n;i++)
	            prime[i] = true;

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

  public static String rev(String s)
	{
		StringBuilder sb=new StringBuilder(s);
		sb.reverse();
		return sb.toString();
	}
	static long lcm(long a, long b)
	{
	    return a * (b / gcd(a, b));
	}
	static long gcd(long a, long b)
	{
	    while (b > 0)
	    {
	        long temp = b;
	        b = a % b; // % is remainder
	        a = temp;
	    }
	    return a;
	}
	static InputReader in;
	static PrintWriter w;
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 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);
}
}

}

n, k, d = list(map(int, input().split()))
a = sorted(list(map(int, input().split())))
b = [0] * n
i = j = 0
for i in range(n):
    while a[i] - a[j] > d:
        j += 1
    b[i] = j
c = [0] * n
for i in range(k - 1, n):
    c[i] = c[i - 1] + int(i - b[i] + 1 >= k and (b[i] == 0 or c[i - k] > c[b[i] - 2] or (b[i] == 1 and c[i-k]> c[0])))
print('YES' if n < 2 or c[n - 1] > c[n - 2] else 'NO')


n, m = [int(x) for x in input().split()]
lr = []
lc = []
lst = []
for i in range(n):
    l = list(input())
    lr.append(l)
for i in range(m):
    l = []
    for j in range(n):
        s = lr[j][i]
        l.append(s)
    lc.append(l)
for i in range(n):
    for j in range(m):
        s = lr[i][j]
        if lr[i].count(s) == 1 and lc[j].count(s) == 1:
            lst.append(s)
print("".join(lst))

7 6
eklgxi
xmpzgf
xvwcmr
rqssed
ouiqpt
dueiok
bbuorv

100 2
hd
gx
mz
bq
of
st
zc
dg
th
ba
ew
bw
oc
ow
vh
qp
in
eh
pj
at
nn
br
ij
co
lv
sa
tb
bl
sr
xa
bz
rp
sz
oi
ec
pw
hf
jm
wu
hq
ra
pv
tc
gv
ik
ux
tz
bf
ty
dk
wo
or
za
kv
qt
fa
jy
bk
uv
gk
cz
ds
ie
oq
mf
xn
ql
xs
fb
iv
cj
kn
ns
lg
ji
ha
aj
dg
fj
ut
sg
ju
oc
ov
he
nw
bl
lp
bx
nm
yq
cw
ov
xk
pg
oh
pl
uo
gf
ul

abcd fg xyzabcdef bcda abcd xyzabcdef xyzabcdef xyzabcdef abcd bcda abcd abcd xyzabcdef bcda xeerwb abcd abcd bcda xyzabcdef eklgximpzgfvwcmrrqedoiqptdeiokuorv abcd abcd codeforces bcda abcd abcd abcd bcda bcdacca dvy abcd xyzabcdef xyzabcdef bcda abcd zxxz bcda bcda bcda abcd acaba abcd xyzabcdef xyzabcdef abcd xyzabcdef abcd abcd abcd elwtabvyokgmplabqbxlt

#include <bits/stdc++.h>
using namespace std;
int main() {
  char a[150][150];
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  int s[150][150];
  memset(s, 0, sizeof(s));
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      char c = a[i][j];
      for (int b = 0; b < m; b++) {
        if (b != j) {
          if (c == a[i][b]) {
            s[i][b] = 1;
          }
        }
      }
      for (int b = 0; b < n; b++) {
        if (b != i) {
          if (c == a[b][j]) {
            s[b][j] = 1;
          }
        }
      }
    }
  }
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++) {
      if (s[i][j] != 1) {
        cout << a[i][j];
      }
    }
  cout << endl;
  return 0;
}


#include <bits/stdc++.h>
using namespace std;
int N;
long double W, B, P;
pair<long double, long double> bus[10001];
bool win = true;
long double ans;
int main() {
  ios_base::sync_with_stdio(false);
  if (fopen("cf703c.in", "r")) {
    freopen("cf703c.in", "r", stdin);
    freopen("cf703c.out", "w", stdout);
  }
  cin >> N >> W >> B >> P;
  for (int i = 0; i < N; i++) {
    int a, b;
    cin >> a >> b;
    bus[i].first = a * 1.0;
    bus[i].second = b * 1.0;
    if (bus[i].first * P < bus[i].second * B) {
      win = false;
    }
    ans = max(ans, max(bus[i].first / B, bus[i].second / P) +
                       (W - bus[i].second) / P);
  }
  if (win) {
    cout << fixed << setprecision(20) << W / P << '\n';
    return 0;
  } else {
    cout << fixed << setprecision(20) << ans << '\n';
    return 0;
  }
}

n, w, v, u = map(int, input().split())
maxwait = 0
curr = True
for i in range(n):
    x, y = map(int, input().split())
    maxwait = max(maxwait, x / v - y / u)
    if x / v < y / u:
        curr = False
if curr:
    maxwait = 0
print(w / u + maxwait)


/**
 *
 * @author sarthak
 */

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

public class rnd356_D {

    static class FastScanner {
        BufferedReader br;
        StringTokenizer st;

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

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

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

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

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

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

        private long boxes, vol;

        public P(long x, long y) {
            this.boxes = x;
            this.vol = y;
        }

    }
    static long mb=0;
    static long mv=0;

    public static void rec(long m,long b,long v){
        if(m<0)return;
        if(m==0){
            if(b>mb){
                mb=b;
                mv=v;
            }
            else if(b==mb)mv=Math.max(mv,v);
            return;
        }
        long i=1;
        while((i+1)*(i+1)*(1+i)<=m)i++;
        rec(m-(i*i*i),(1+b),v+(i*i*i));
        if(i-1>=0)
            rec(((i*i*i)-1-((i-1)*(i-1)*(i-1))),(b+1),v+((i-1)*(i-1)*(i-1)));

    }

    public static void main(String[] args){

    FastScanner s = new FastScanner(System.in);
    StringBuilder op=new StringBuilder();

    long m=s.nextLong();
    rec(m,0,0);
    System.out.println(mb+" "+mv);

    }

}

#!/usr/bin/env python3

import sys

# 1 8 27 64 125 216 343 512 729 1000
# 1-7: blocks of size 1
# 8-15: 1 block of size 2, blocks of size 1
# 16-23: 2 blocks of size 2, blocks of size 1
# 24-26: 3 blocks of size 2, blocks of size 1
# 27-34: 1 block of size 3, blocks of size 1

# Maximum will always be when you have the max number of size 1 blocks

def cube_root(x):
    v = max(int(x ** (1.0 / 3.0)) - 1, 0)
    while (v + 1) ** 3 <= x:
        v += 1
    return v

def solution(x):
    # returns (n_blocks, volume)
    #print("solution {}".format(x))
    if x <= 7:
        return (x, x)

    next_smaller = cube_root(x) ** 3
    candidate = solution(x - next_smaller)
    candidate = (candidate[0] + 1, candidate[1] + next_smaller)

    prenext_smaller = cube_root(next_smaller - 1) ** 3
    if next_smaller - prenext_smaller > x - next_smaller:
        candidate2 = solution(next_smaller - 1)
    else:
        candidate2 = candidate

    if candidate >= candidate2:
        return candidate
    else:
        return candidate2

n = int(input())
s = solution(n)
print(s[0], s[1])


import java.util.Scanner;

public class codeforces {
    public static void main(String[] args) {
        TaskE Solver = new TaskE();
        Solver.Solve();
    }
    public static class TaskE {
        public void Solve() {
            Scanner in = new Scanner(System.in);
            long x1 = in.nextInt();
            long y1 = in.nextInt();
            long x2 = in.nextInt();
            long y2 = in.nextInt();
            long c = 0;
            if ((y2 - y1) % 2 == 0) {
                c += ((x2 - x1) / 2 + 1) * ((y2 - y1) / 2 + 1);
                c += ((x2 - x1) / 2 + 0) * ((y2 - y1) / 2 + 0);
            }
            else {
                c += ((x2 - x1) + 1) * ((y2 - y1) / 2 + 1);
            }
            System.out.println(c);
        }
    }
}


import java.util.*;
public class GFG {
	public static void main (String[] args) {
		Scanner sc=new Scanner(System.in);
		int n=sc.nextInt();
		ArrayList<Integer> arr=new ArrayList<Integer>();
	    while (n>0)
	    {
	        int n1=n,a=0,b=1;
	        while(n1>0)
	        {
	            if(n1%10!=0)a+=b;
	            b*=10;n1/=10;
	        }
	        n-=a;arr.add(a);
	    }
	    System.out.println(arr.size());
	    Collections.sort(arr);
	    for(int i:arr)
	    System.out.print(i+" ");
	}
}

import math
a = input()
d = int(max(a))
print(d)
dec = math.ceil(math.log10(int(a)))
c = [0]*d
if int(a) != 10**dec:
    for i in a:
        for j in range(int(i)):
            c[j] = c[j]+10**(dec-1)
        dec = dec - 1
d=''
for i in c:
    d += str(i)+' '
if int(a) == 10**dec:
    print(a)
else:
    print(d.strip())


import java.util.*;
import java.lang.reflect.Array;
import java.math.*;
import java.io.*;
import java.awt.*;
import java.awt.geom.Line2D;

import javax.naming.BinaryRefAddr;

public class Main{
    static FastReader in = new FastReader(new BufferedReader(new InputStreamReader(System.in)));
    static PrintWriter out = new PrintWriter(System.out);
    static final int maxn = (int)3e3 + 11;
    static int inf = (1<<30) - 1;
    static int n;
    static int a[] = new int[maxn];

    public static void solve() throws Exception {
        int n1 = in.nextInt();
        int n2 = in.nextInt();
        int k1 = in.nextInt();
        int k2 = in.nextInt();

        if (n1<=n2) {
            out.println("Second");
        } else {
            out.println("First");
        }

    }

    public static void main (String args[]) throws Exception {
        solve();
        out.close();
    }

}

class Pair implements Comparable<Pair> {
    int x,y;
    public Pair (int x, int y) {
        this.x = x;
        this.y = y;

    }

    @Override
    public int compareTo(Pair p) {
        if (this.x>p.x) {
            return -1;
        } else if (this.x == p.x) {
            return 0;
        } else {
            return 1;
        }
    }
}

class FastReader {

    BufferedReader bf;
    StringTokenizer tk = null;
    String DELIM = " ";

    public FastReader(BufferedReader bf) {
        this.bf = bf;
    }

    public String nextToken() throws Exception {

        if(tk==null || !tk.hasMoreTokens()) {
            tk = new StringTokenizer(bf.readLine(),DELIM);
        }
        return tk.nextToken();
    }

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

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

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

Second Second Second Second First Second First Second First First Second Second Second First Second Second Second First First Second First First Second Second Second First Second Second Second First Second Second First Second First First Second Second Second First First First Second First First Second Second First Second First First Second

n1 , n2 , k1 , k2 = map(int , (input().split(" ")))
if n1 <= n2:
    print('Second')
else:
    print('First')


n = int(input())
b = list(map(int, input().split()))
m = int(input())
g = list(map(int, input().split()))

b.sort()
g.sort()

res = 0
i = 0
j = 0
while i < n and j < m:
    if abs(b[i]-g[j]) <= 1:
        res += 1
        i += 1
        j += 1

    elif b[i] > g[j]:
        j += 1

    else:
        i += 1

print(res)

#include <bits/stdc++.h>
using namespace std;
int b[102];
int g[102];
int main() {
  int n, m;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> b[i];
  }
  cin >> m;
  for (int i = 0; i < m; i++) {
    cin >> g[i];
  }
  sort(b, b + n);
  sort(g, g + m);
  int itb, itg;
  itb = itg = 0;
  int cnt = 0;
  while (itb < n && itg < m) {
    if (abs(b[itb] - g[itg]) <= 1) {
      cnt++, itb++, itg++;
      continue;
    }
    if (b[itb] < g[itg])
      itb++;
    else
      itg++;
  }
  cout << cnt;
  return 0;
}


#include <bits/stdc++.h>
using namespace std;
int p, n;
bool build(string& in, int i) {
  bool gg = 0;
  for (char v = in[i] + 1; v <= p; ++v) {
    if ((i - 1 < 0 || in[i - 1] != v) && (i - 2 < 0 || in[i - 2] != v)) {
      gg = true;
      in[i] = v;
      break;
    }
  }
  if (gg) {
    bool can = true;
    for (int j = i + 1; j < n; ++j) {
      can = false;
      for (char v = 'a'; v <= p; ++v) {
        if ((j - 1 < 0 || in[j - 1] != v) && (j - 2 < 0 || in[j - 2] != v)) {
          can = true;
          in[j] = v;
          break;
        }
      }
      if (!can) {
        break;
      }
      if (j + 1 == n) {
        cout << in << endl;
        return 0;
      }
    }
    if (can) {
      cout << in << endl;
      return 0;
    }
  }
  return 1;
}
int main() {
  std::ios_base::sync_with_stdio(false);
  cin >> n >> p;
  p += 'a' - 1;
  string in;
  cin >> in;
  for (int i = n; i-- > 0;) {
    if (!build(in, i)) {
      return 0;
    }
  }
  cout << "NO" << endl;
}

import sys

def main():
    # fin = open("input.txt", "r")
    fin = sys.stdin
    fout = sys.stdout

    L = list("abcdefghijklmnopqrstuvwxyz")

    n, p = map(int, fin.readline().split())
    A = list(fin.readline())

    for i in range(n - 1, 1, -1):
        pr = ord(A[i - 1]) - ord("a")
        pp = ord(A[i - 2]) - ord("a")
        cur = ord(A[i]) - ord("a") + 1
        # print pr, pp, cur
        while cur < p and (cur == pr or cur == pp):
            cur += 1
        if cur < p:
            A[i] = chr(cur + ord("a"))
            print("".join(A[:i]), end="")
            print(chr(cur + ord("a")), end="")
            for j in range(i + 1, n):
                pr = ord(A[j - 1]) - ord("a")
                pp = ord(A[j - 2]) - ord("a")
                cur = 0
                while cur < p and (cur == pr or cur == pp):
                    cur += 1
                print(chr(cur + ord("a")), end="")
                A[j] = chr(cur + ord("a"))
            return

    if n >= 2:
        i = 1
        pr = ord(A[i - 1]) - ord("a")
        pp = -1
        cur = ord(A[i]) - ord("a") + 1
        # print pr, pp, cur
        while cur < p and (cur == pr or cur == pp):
            cur += 1
        if cur < p:
            A[i] = chr(cur + ord("a"))
            print("".join(A[:i]), end="")
            print(chr(cur + ord("a")), end="")
            for j in range(i + 1, n):
                pr = ord(A[j - 1]) - ord("a")
                pp = ord(A[j - 2]) - ord("a")
                cur = 0
                while cur < p and (cur == pr or cur == pp):
                    cur += 1
                print(chr(cur + ord("a")), end="")
                A[j] = chr(cur + ord("a"))
            return

    i = 0
    pr = pp = -1
    cur = ord(A[i]) - ord("a") + 1
    # print pr, pp, cur
    while cur < p and (cur == pr or cur == pp):
        cur += 1
    if cur < p:
        A[i] = chr(cur + ord("a"))
        # print("".join(A[:i]), end="")
        print(chr(cur + ord("a")), end="")
        if n == 1:
            return
        j = 1
        pr = ord(A[j - 1]) - ord("a")
        pp = -1
        cur = 0
        while cur < p and (cur == pr or cur == pp):
            cur += 1
        print(chr(cur + ord("a")), end="")
        A[j] = chr(cur + ord("a"))
        for j in range(i + 2, n):
            pr = ord(A[j - 1]) - ord("a")
            pp = ord(A[j - 2]) - ord("a")
            cur = 0
            while cur < p and (cur == pr or cur == pp):
                cur += 1
            print(chr(cur + ord("a")), end="")
            A[j] = chr(cur + ord("a"))
        return

    print("NO")

    fin.close()
    fout.close()

main()


n = int(input())
a = list(map(int, input().split()))
i = 0
ans = 0
while i < n:
    ans += 1
    i1 = i
    while i1 < n and a[i1] == -1:
        i1 += 1
    if i1 == n:
        break
    i2 = i1 + 1
    while i2 < n and a[i2] == -1:
        i2 += 1
    if i2 == n:
        break
    dist = i2 - i1
    step = (a[i2] - a[i1]) // dist
    if (a[i2] - a[i1]) % dist != 0 or (step > 0 and a[i1] - (i1 - i) * step <= 0):
        i = i2
        continue
    i3 = i2 + 1
    while i3 < n:
        nxt = a[i2] + step * (i3 - i2)
        if nxt <= 0 or (a[i3] != -1 and a[i3] != nxt):
            break
        i3 += 1

    i = i3
print(ans)

#include <bits/stdc++.h>
using namespace std;
int n, m, ans;
long long a[200005], d;
int main() {
  cin >> n;
  int i, j;
  for (i = 1; i <= n; i++) cin >> a[i];
  int k = 1;
  while (k <= n) {
    ans++;
    for (i = k; a[i] == -1; i++)
      ;
    for (j = i + 1; a[j] == -1; j++)
      ;
    if (j > n) break;
    d = (a[j] - a[i]) / (j - i);
    if ((a[j] - a[i]) % (j - i) || a[j] - d * (j - k) <= 0) {
      k = j;
      continue;
    }
    k = j + 1;
    while (k <= n && (long long)a[j] + d * (k - j) > 0 &&
           (a[k] == -1 || a[k] == a[j] + d * (k - j))) {
      k++;
    }
  }
  cout << ans;
}


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

public class A {

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

		int n = sc.nextInt();
		int ans = n + 1;
		long n2 = sq(n);
		for(int x = 1, y = n; x <= n; ++x)
		{
			int ny = y;
			while(sq(x) + sq(ny) > n2)
				--ny;
			if(y > ny)
				ans += y - ny - 1;
			y = ny;
		}
		if(n != 0)
			ans = ans * 4 - 4;
		out.println(ans);
		out.flush();
		out.close();
	}

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

	static class Scanner
	{
		StringTokenizer st;
		BufferedReader br;

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

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

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

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

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

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

from math import sqrt

n = int(input())
if n == 0:
    print(1)
else:
    print(4 * int(n * sqrt(2)))


# Made By Mostafa_Khaled
bot = True
import math,sys

n=int(input());k=n

a=sorted([int(x) for x in sys.stdin.read().strip().split('\n')])

p1=math.floor((n-1)/2);p2=n-1

while p1>=0:

    if 2*a[p1]<=a[p2]:

        k-=1;a[p2]=0;p2-=1

    p1-=1

k=max(math.ceil(n/2),k)

sys.stdout.write(str(k))

# Made By Mostafa_Khaled

#include <bits/stdc++.h>
using namespace std;
vector<int> v;
int main() {
  int n, c = 0;
  cin >> n;
  int x;
  for (int i = 0; i < n; i++) {
    cin >> x;
    v.push_back(x);
  }
  sort(v.begin(), v.end());
  int r = n - 1;
  for (int i = n / 2 - 1; i >= 0; i--) {
    if (2 * v[i] <= v[r]) {
      c++;
      r--;
    }
  }
  cout << n - c;
  return 0;
}


import java.util.Scanner;
import java.util.ArrayList;
public class Problem023_300A_Array {
    public static void main(String args[])
    {
        Scanner sc = new Scanner(System.in);
        int n=sc.nextInt();
        int zeros=0;
        ArrayList<Integer> positive = new ArrayList<Integer>();
        ArrayList<Integer> negative = new ArrayList<Integer>();
        boolean hasPositive=false;
        int temp;
        boolean moveNegativeToZero=false;
        int valueOfMoveNegativeToZero=0;
        for(int i=0;i<n;i++)
        {
            temp=sc.nextInt();
            if(temp==0)
                zeros++;
            else if(temp>0)
            {
                hasPositive=true;
                positive.add(temp);
            }
            else
                negative.add(temp);
        }
        //PRINT NEGATIVE
        if(negative.size()%2==0&&(hasPositive||(!hasPositive&&negative.size()!=2)))
        {
            moveNegativeToZero=true;
            valueOfMoveNegativeToZero=negative.get(negative.size()-1);
            negative.remove(negative.size()-1);
        }
        if(hasPositive)
        {
            System.out.print(negative.size()+" ");
            for(int i=0;i<negative.size()&&i<2;i++)
                System.out.print(negative.get(i)+" ");
        }
        else
            System.out.print(negative.size()-2+" ");
        for(int i=2;i<negative.size();i++)
            System.out.print(negative.get(i)+" ");
        System.out.println();
        //PRINT POSITIVE

        if(!hasPositive)
        {
            System.out.print("2 ");
            for(int i=0;i<negative.size()&&i<2;i++)
                System.out.print(negative.get(i)+" ");
        }
        else
        {
            System.out.print(positive.size()+" ");
            for(int i=0;i<positive.size();i++)
                System.out.print(positive.get(i)+" ");
        }
        System.out.println();
        //Print ZEROS

        System.out.print(((moveNegativeToZero)?(zeros+1):zeros)+" ");
        for(int i=0;i<zeros;i++)
            System.out.print("0 ");
        if(moveNegativeToZero)
            System.out.print(valueOfMoveNegativeToZero);
        System.out.println();
    }
}

n=int(input())
a=list(map(int,input().split()))
b=[]
k=0
k1=0
for i in range(0,n):
    if(a[i]==0):
        b.append(a[i])
    elif(a[i]>0):
        if(k==0):
            k=a[i]
        else:
            b.append(a[i])
    elif(a[i]<0):
        if(k1==0):
            k1=a[i]
        else:
            b.append(a[i])
print(1,k1)
f=0
if(k==0):
    c=[]
    for i in range(0,n):
        if(b[i]<0):
            c.append(b[i])
            b[i]='@'
            f=f+1
        if(len(c)==2):
            break
    print(2)
    for i in range(0,2):
        print(c[i])
else:
    print(1,k)
print(len(b)-f)
for i in range(0,len(b)):
    if(b[i]!='@'):
        print(b[i])


from itertools import *
alphabet="abcdefghijklmnopqrstuvwxyz";

def isValid(s, names):
    for name in names:
        if name.find(s)!=-1:
            return  False
    return True

def newProblem(names):
    for i in range(1,3):
        for s in product(alphabet, repeat=i):
            st=""
            for c in s:
                st+=c
            if isValid(st, names):
                return st

n=int(input())
names=[]
for i in range(0,n):
    name= input()
    names.append(name)
print(newProblem(names))

30
b
u
p
n
f
m
t
i
j
k
p
h
a
c
w
z
z
p
t
d
o
w
u
q
l
y
i
o
a
u

3
rjnflsbpxqivrcdjptj
vpojopbwbwbswdu
rydkiwnugwddcgcrng

5
threehorses
goodsubstrings
secret
primematrix
beautifulyear

5
zzxpfk
abcdefghijklmnopqrst
uvwxz
srgkjaskldfkln
vgnsdfdgfh

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

public class Solver {

	public static void main(String[] Args) throws NumberFormatException,
			IOException {
		new Solver().Run();
	}

	PrintWriter pw;
	StringTokenizer Stok;
	BufferedReader br;

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

	public int nextInt() throws NumberFormatException, IOException {
		return Integer.parseInt(nextToken());
	}

	public double nextDouble() throws NumberFormatException, IOException {
		return Double.parseDouble(nextToken());
	}

	public long nextLong() throws NumberFormatException, IOException {
		return Long.parseLong(nextToken());
	}

	int n;
	String curStr;
	int[] usedChars;
	int[][] usedPairs;
	String result;
	final int offset=(int)'a';

	public void Run() throws NumberFormatException, IOException {
		//br = new BufferedReader(new FileReader("input.txt")); pw = new PrintWriter("output.txt");
		br=new BufferedReader(new InputStreamReader(System.in));  pw=new PrintWriter(new OutputStreamWriter(System.out));
		usedChars=new int[26];
		usedPairs=new int[26][26];
		int n=nextInt();
		for (int i=0; i<n; i++){
			curStr=br.readLine();
			int len=curStr.length();
			for (int j=0; j<len; j++){
				usedChars[curStr.charAt(j)-offset]++;
			}
			for (int j=0; j<len-1; j++){
				usedPairs[curStr.charAt(j)-offset][curStr.charAt(j+1)-offset]++;
			}
		}

		for (int i=0; i<26; i++){
			if (usedChars[i]==0){
				pw.println((char)(i+offset));
				pw.flush();
				pw.close();
				return;
			}
		}

		for (int i=0; i<26; i++){
			for (int j=0; j<26; j++){
				if (usedPairs[i][j]==0){
					pw.print((char)(i+offset));
					pw.println((char)(j+offset));
					pw.flush();
					pw.close();
					return;
				}
			}
		}

		pw.flush();
		pw.close();
	}

}


#include <bits/stdc++.h>
const int maxn = 1000100;
long long result, n, m;
long long deg[maxn + 1];
int main() {
  long long i, j, k, x, y;
  scanf("%I64d%I64d", &n, &m);
  for (i = 1; i <= n; ++i) deg[i] = 0;
  for (i = 1; i <= m; ++i) {
    scanf("%I64d%I64d", &x, &y);
    ++deg[x];
    ++deg[y];
  }
  result = 0;
  for (i = 1; i <= n; ++i) {
    result += deg[i] * (n - 1 - deg[i]);
  }
  result = n * (n - 1) * (n - 2) / 6 - result / 2;
  printf("%I64d\n", result);
  return 0;
}

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

public class Solution{

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

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

    	int tt = 1;
    	while(tt-->0) {

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

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

    		for(int i=0;i<m;i++) {
    			int u = fs.nextInt(), v = fs.nextInt();
    			d[u]++; d[v]++;
    		}

    		long num = 0;
    		for(int i=1;i<=n;i++) {
    			num += (long)d[i]*(n-d[i]-1);
    		}
    		num /= 2;

    		long ans = (long)n*(n-1)*(n-2)/6 - num;
    		out.println(ans);

    	}

    	out.close();

    }

    static final Random random=new Random();

    static void ruffleSort(int[] a) {
    	int n=a.length;//shuffle, then sort
    	for (int i=0; i<n; i++) {
    		int oi=random.nextInt(n); int temp=a[oi];
    		a[oi]=a[i]; a[i]=temp;
    	}
    	Arrays.sort(a);
    }

    static void ruffleSort(long[] a) {
    	int n=a.length;//shuffle, then sort
    	for (int i=0; i<n; i++) {
    		int oi=random.nextInt(n); long temp=a[oi];
    		a[oi]=a[i]; a[i]=temp;
    	}
    	Arrays.sort(a);
    }

    static void reverse(int[] arr, int l, int r) {
    	for(int i=l;i<l+(r-l)/2;i++){
    		int temp = arr[i]; arr[i] = arr[r-i+l-1]; arr[r-i+l-1] = temp;
    	}
    }

    static void reverse(long[] arr, int l, int r) {
    	for(int i=l;i<l+(r-l)/2;i++){
    		long temp = arr[i]; arr[i] = arr[r-i+l-1]; arr[r-i+l-1] = temp;
    	}
    }

    static <T> void reverse(T[] arr, int l, int r) {
    	for(int i=l;i<l+(r-l)/2;i++) {
    		T temp = arr[i]; arr[i] = arr[r-i+l-1]; arr[r-i+l-1] = temp;
    	}
    }

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

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

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

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

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

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

    	public char nextChar() {
    		return next().toCharArray()[0];
    	}
    }

}


#include <bits/stdc++.h>
using namespace std;
struct diem {
  int x, y;
};
int n, ans = 0;
diem a[3005];
bool cmp(diem a, diem b) {
  if (a.x == b.x) return a.y <= b.y;
  return a.x <= b.x;
}
int binary_search(int l, int r, diem value) {
  if (l > r) return 0;
  if (l == r) return l;
  int mid = (l + r) / 2;
  if (cmp(value, a[mid]))
    return binary_search(l, mid, value);
  else
    return binary_search(mid + 1, r, value);
}
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> a[i].x >> a[i].y;
  sort(a + 1, a + n + 1, cmp);
  for (int i = 1; i <= n - 2; i++)
    for (int j = i + 2; j <= n; j++)
      if (abs(a[j].x - a[i].x) % 2 == 0 && abs(a[j].y - a[i].y) % 2 == 0) {
        diem temp;
        temp.x = (a[j].x + a[i].x) / 2;
        temp.y = (a[j].y + a[i].y) / 2;
        int vt = binary_search(i, j, temp);
        if (a[vt].x == temp.x && a[vt].y == temp.y) ans++;
      }
  cout << ans;
}

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

public class Number_of_Triplets {
    static boolean [][]mapa = new boolean[2001][2001];
    static BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
    static int coordenadas[];
    public static void main(String[] args) {
        try {
            int nPontos = 0;
            String linha = reader.readLine();
            int  n = Integer.parseInt(linha.split("\\s+")[0]);
            coordenadas = new int[n];
            for (int i = 0; i < n; i++) {
                linha = reader.readLine();
                int x = Integer.parseInt(linha.split("\\s+")[0]) + 1000; // correção para fazer de 0 a 2000
                int y = Integer.parseInt(linha.split("\\s+")[1]) + 1000; // correção para fazer de 0 a 2000
                mapa[x][y] = true;
                coordenadas[nPontos++] = x * 2001 + y;
            }

            int contador = 0;
            for (int i = 0; i < n; i++) {
                for (int j = i+1; j < n; j++) {
                    int x1 = coordenadas[i] / 2001;
                    int y1 = coordenadas[i] % 2001;
                    int x2 = coordenadas[j] / 2001;
                    int y2 = coordenadas[j] % 2001;
                    if ((x1+x2) % 2 == 0 && (y1+y2) % 2 == 0) {
                        if (mapa[(x1+x2)/2][(y1+y2)/2])
                            contador++;
                    }
                }
            }
            System.out.println(contador);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}


res = []
n = int(input())
print('?', 1, flush=True)
arr = list(map(int, input().split()))
for v,d in enumerate(arr):
    if d==1:
        res.append([0,v])
one = [v for v,d in enumerate(arr) if d&1]
two = [v for v,d in enumerate(arr) if v and not (d&1)]
if len(one)>len(two):
    one, two = two, one
for u in one:
    print('?', u+1, flush=True)
    arr = list(map(int, input().split()))
    for v,d in enumerate(arr):
        if d==1 and v:
            res.append([u,v])

print('!')
for u, v in res:
    print(u+1, v+1)

#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define mex 400005
#define pi pair<int,int>
#define minmax(a,b) {min(a,b),max(a,b)}
int main() {
	// your code goes here
	int n;
	cin>>n;
	cout<<"? 1\n";
	cout.flush();
	int a[n];
	map<int,vector<int> > h;
	for(int i=0;i<n;i++) cin>>a[i],h[a[i]].push_back(i);
	set<pi> ed;
	int oc=0,ec=0;
	for(int i=0;i<n;i++)  if(i&1) oc += h[i].size();else ec += h[i].size();
	int in =2;
	if(ec > oc) in--;
	for(int x: h[1]) ed.insert({0,x});
	for(int i=in;i<n;i+=2)
	{
	    if(ed.size() == n-1) break;
	    for(int x:h[i])
	    {
	        cout<<"? "<<x+1<<'\n';
	        cout.flush();
	        for(int i=0;i<n;i++) {
	            cin>>a[i];
	            if(a[i] == 1) ed.insert(minmax(x,i));
	        }
	    }
	}
	cout<<"!\n";
	auto it = ed.begin();
	while(it != ed.end())
	{
	    cout<<(*it).first + 1 << ' ' << (*it).second+1<<'\n';
	    it++;
	}
	return 0;
}


def untor(a, c):
    res = ''
    while a or c:
        a, ma = divmod(a, 3)
        c, mc = divmod(c, 3)
        x = 0
        while (ma + x)%3 != mc:
            x += 1
        res = str(x) + res
    try:
        return int(res, 3)
    except Exception as e:
        return 0

a, c = map(int, input().split())
print(untor(a, c))

import java.util.Scanner;

public class B136 {

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int A = in.nextInt();
        int C = in.nextInt();
        int B = 0;
        int power = 1;
        while (A != 0 || C != 0) {
            int b = (3 + C%3 - A%3)%3;
            B += b*power;
            power *= 3;
            A /= 3;
            C /= 3;
        }
        System.out.println(B);
    }

}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.math.MathContext;
import java.math.RoundingMode;
import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.Scanner;
import java.util.StringTokenizer;
import java.util.TreeMap;
import java.util.stream.IntStream;

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

        new d().solve(in, out);

        out.close();
    }

    void solve(FS in, PrintWriter out) {
        int n = in.nextInt();
        int[] a = new int[n];
        int m = 0;
        for(int i = 0; i < n; i++) m += a[i] = in.nextInt();
        long invM = pow(m, MOD-2), invN1 = pow(n-1, MOD-2);
        long[] ans = new long[m+5];
        for(int i = m; i >= 0; i--) {
            long k1 = ((i*invM)%MOD*invN1)%MOD, k2 = ((m-i)*invM)%MOD;
            ans[i] = (((k2*ans[i+1]+1)%MOD)*pow(k1, MOD-2))%MOD;
        }

        for(int i = 1; i <= m; i++) ans[i] = (ans[i]+ans[i-1])%MOD;
        long res = 0;
        for(int i = 1; i <= n; i++) res = (res+ans[m-a[i-1]])%MOD;
        res = (res+MOD-(ans[m]*(n-1))%MOD)%MOD;
        out.println((res*pow(n, MOD-2))%MOD);
    }

    long MOD = 998244353;

    long pow(long a, long b) {
        long ret = 1;
        for(; b > 0; b >>= 1, a = (a*a)%MOD) if((b&1) == 1) ret = (ret*a)%MOD;
        return ret;
    }

    static class FS {

        BufferedReader in;
        StringTokenizer token;

        public FS(InputStream str) {
            in = new BufferedReader(new InputStreamReader(str));
        }

        public String next() {
            if (token == null || !token.hasMoreElements()) {
                try {
                    token = new StringTokenizer(in.readLine());
                } catch (IOException ex) {
                }
                return next();
            }
            return token.nextToken();
        }

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

#include <bits/stdc++.h>
using namespace std;
namespace FGF {
int n, m, ans;
const int N = 3e5 + 5, mo = 998244353;
int a[N], f[N], inv[N];
void work() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]), m += a[i];
  inv[1] = 1;
  for (int i = 2; i <= m; i++) inv[i] = 1ll * inv[mo % i] * (mo - mo / i) % mo;
  for (long long i = 1, y; i < m; i++)
    y = i * (n - 1) % mo * inv[m - i] % mo,
    f[i + 1] =
        (((y + 1) % mo * f[i] % mo - y * (f[i - 1] + 1) % mo) % mo + mo) % mo;
  for (int i = 1; i <= n; i++) ans = (ans + f[a[i]]) % mo;
  printf("%d\n", (ans - f[m] + mo) % mo);
}
}  // namespace FGF
int main() {
  FGF::work();
  return 0;
}


#include <bits/stdc++.h>
using namespace std;
long long n, a[1000005], add[1000005];
long long k;
bool used[1000005];
int main() {
  scanf("%lld%lld", &n, &k);
  long long sum = n * (n + 1) / 2;
  if (sum > k) {
    cout << -1 << endl;
    return 0;
  }
  for (int i = 1; i <= n; i++) a[i] = i;
  for (int i = 1; i <= n / 2; i++) {
    long long ch = n - 2 * i + 1;
    if (sum + ch <= k) {
      sum += ch;
      swap(a[i], a[n - i + 1]);
    } else {
      swap(a[i], a[k - sum + i]);
      sum = k;
      break;
    }
  }
  cout << sum << endl;
  for (int i = 1; i <= n; i++) cout << i << ' ';
  cout << endl;
  for (int i = 1; i <= n; i++) cout << a[i] << ' ';
  cout << endl;
  return 0;
}

/**
 * ******* Created on 14/10/19 3:04 PM*******
 */

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

public class G1244 implements Runnable {

    public static final int MAX = (int) (1e6+5);

    int[] a = new int[MAX];
    int[] b = new int[MAX];
    private void solve() throws IOException {
        long n = reader.nextLong();
        long k = reader.nextLong();

        if( k < (n*(n+1)/2)){
            writer.println("-1");
            return;
        }

        k-= (n*(n+1))/2;
        long ans = (n*(n+1))/2;
        for(int i=1;i<=n;i++)a[i]=i;
        for(int i=1;i<=n;i++)b[i]=i;
        for(int i=1;i<=n/2;i++){
            if(k==0)break;
            if(n-i+1-i <=k){
                k-= n-i+1-i;
                ans +=(n-i+1-i);
                swap(i, (int) (n-i+1));
            }else{
                for(int j=i;j<=n-i;j++){
                    if(n-i+1-j==k){
                        ans += (n-i+1-j);
                        swap(j, (int) (n-i+1));
                        k=0;
                        break;
                    }
                }
            }
        }

        writer.println(ans);
        for(int i=1;i<=n;i++) writer.print(a[i]+" ");
        writer.println();
        for(int i=1;i<=n;i++) writer.print(b[i]+" ");
        writer.println();

    }

    private void swap(int a, int b1) {
        int tmp =b[a];
        b[a] = b[b1];
        b[b1]= tmp;
    }

    public static void main(String[] args) throws IOException {
        try (Input reader = new StandardInput(); PrintWriter writer = new PrintWriter(System.out)) {
            new G1244().run();
        }
    }

    StandardInput reader;
    PrintWriter writer;

    @Override
    public void run() {
        try {
            reader = new StandardInput();
            writer = new PrintWriter(System.out);
            solve();
            reader.close();
            writer.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    interface Input extends Closeable {
        String next() throws IOException;

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

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

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

        default int[] readIntArray() throws IOException {
            return readIntArray(nextInt());
        }

        default int[] readIntArray(int size) throws IOException {
            int[] array = new int[size];
            for (int i = 0; i < array.length; i++) {
                array[i] = nextInt();
            }
            return array;
        }

        default long[] readLongArray(int size) throws IOException {
            long[] array = new long[size];
            for (int i = 0; i < array.length; i++) {
                array[i] = nextLong();
            }
            return array;
        }
    }

    private static class StandardInput implements Input {
        private final BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));

        private StringTokenizer stringTokenizer;

        @Override
        public void close() throws IOException {
            reader.close();
        }

        @Override
        public String next() throws IOException {
            if (stringTokenizer == null || !stringTokenizer.hasMoreTokens()) {
                stringTokenizer = new StringTokenizer(reader.readLine());
            }
            return stringTokenizer.nextToken();
        }
    }
}