//import java.util.Scanner;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.PriorityQueue;

import java.util.StringTokenizer;
import java.util.TreeSet;

public class Main {

	public static void main(String[] args) throws IOException
	{
		Scanner sc = new Scanner(System.in);
	     int n=sc.nextInt();
	  int arr[] =new int[1001];
	  int arr2[]=new int[n];
	  int arr3[]=new int[n];
	  for(int i=0;i<n;i++) {
		  int x=sc.nextInt();
		  arr[x]++;
		  arr2[i]=x;
		  }
	  int count=0;
	  int j=0;
	  for(int i=0;i<n;i++)
	  {
		  if(arr[arr2[i]]>1)
			  arr[arr2[i]]--;
		  else if(arr[arr2[i]]==1) {
			  count++;
			  arr3[j]=arr2[i];
			  j++;
		  }
		  }
	  System.out.println(count);
	 for(int i=0;i<n;i++)
	  {
		     if(arr3[i]!=0)
			  System.out.print(arr3[i]+" ");
		  }
	  }}

	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()) {//lma ykon fe next token mesh hyd5ol fe while bs yrg3li l token elii wrah
				st = new StringTokenizer(br.readLine());
			//System.out.println(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 {
			String x = next();
			StringBuilder sb = new StringBuilder("0");
			double res = 0, f = 1;
			boolean dec = false, neg = false;
			int start = 0;
			if (x.charAt(0) == '-') {
				neg = true;
				start++;
			}
			for (int i = start; i < x.length(); i++)
				if (x.charAt(i) == '.') {
					res = Long.parseLong(sb.toString());
					sb = new StringBuilder("0");
					dec = true;
				} else {
					sb.append(x.charAt(i));
					if (dec)
						f *= 10;
				}
			res += Long.parseLong(sb.toString()) / f;
			return res * (neg ? -1 : 1);
		}

		public boolean ready() throws IOException {
			return br.ready() || st.hasMoreTokens();//an br ready y3ni fe line tany w st 3ndha tokens (y3ni rg3ly next token bs mtd5olesh fe while)

		}}

#include <bits/stdc++.h>
using namespace std;
using ll = long long int;
int main() {
  int n, tmp;
  cin >> n;
  vector<int> nums;
  for (int i = 0; i < n; i++) {
    cin >> tmp;
    nums.push_back(tmp);
  }
  deque<int> dedupe;
  for (int j = n - 1; j >= 0; j--) {
    deque<int>::iterator iter = find(dedupe.begin(), dedupe.end(), nums[j]);
    if (iter == dedupe.end()) {
      dedupe.push_front(nums[j]);
    }
  }
  cout << dedupe.size() << '\n';
  for (auto c : dedupe) {
    cout << c << ' ';
  }
  cout << '\n';
}


import java.util.Scanner;

public class C {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        int a = sc.nextInt();
        int b = sc.nextInt();
        int ra = (a-1)/m;
        int rb = (b-1)/m;
        int pa = (a-1)%m;
        int pb = (b-1)%m;
        int ans = 3;
        if(m==1)ans = 1;
        else if(ra==rb)ans = 1;
        else if(rb-ra==1){
            if(pa==0 && (pb==m-1||b==n))ans = 1;
            else ans = 2;
        }
        else{
            if(pa==0){
                if((pb==m-1||b==n))
                    ans = 1;
                else ans = 2;
            }
            else if(pb==m-1||b==n||pb==pa-1){
                ans = 2;
            }
            else {
                ans = 3;
            }

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

import math
n,m,a,b=map(int,input().split())

if (a-1)//m==(b-1)//m:
    print(1)
elif (a-1)%m==0 and b%m==0:
    print(1)
elif (a-1)%m==0 and b==n or m==1:
    print(1)
elif (a-1)%m==0 or b%m==0 or b==n:
    print(2)
elif abs((a-1)//m - (b-1)//m)==1 or m==2:
    print(2)
elif (a-1)%m==b%m:
    print(2)
else:
    print(3)


import math
n = int(input())
ans = 0
for a in range(1, n+1):
    for b in range(a, n+1):
        c= a^b
        if c < b or c > n:
            continue
        if a+b > c:
            ans += 1
print(ans)

42
```

Each of these inputs is a single integer between 1 and 42, inclusive, representing the order of the xorangle to be counted.

#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  int ans = 0;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++)
    for (int j = i; j <= n; j++) {
      int k = i ^ j;
      if (k <= n && k >= 1 && k >= j && i + j > k) ans++;
    }
  printf("%d", ans);
}


import sys
text = sys.stdin.read().strip()
n = int(text)
q = lambda x: sum([int(b) for b in str(x)])
e = []
for i in range(max(0, n-81), n):
    if i + q(i) == n:
        e.append(i)
print(len(e))
for z in e:
    print(z)

#include <bits/stdc++.h>
using namespace std;
long n;
vector<long> answer;
long decimal(long a) {
  int ans = a, q;
  for (int i = 0; i <= 9; i++) {
    q = pow(10, i);
    ans += (a / q) % 10;
  }
  return ans;
}
int main() {
  cin >> n;
  for (int i = n; i >= n - 100 && i >= 1; i--) {
    if (decimal(i) == n) {
      answer.push_back(i);
    }
  }
  cout << answer.size();
  sort(answer.begin(), answer.end());
  for (int i = 0; i < answer.size(); i++) {
    cout << endl << answer[i];
  }
  return 0;
}


n=int(input())
arr=list(map(int,input().split()))
s,t,p=0,0,0
for i in range(1,n) :
    if arr[i] < arr[i - 1]: s = 1
    elif arr[i]==arr[i-1] and s: t=1
    elif arr[i]==arr[i-1] and not s: p=1
    if arr[i]>arr[i-1] and (s or p):t=1

if t:   print("NO")
else :  print("YES")

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


#include <bits/stdc++.h>
using namespace std;
pair<int, int> ii;
long long a[11];
void init() {
  long long n = 9, ten = 10, nine = 8;
  for (int i = 1; i < 10; ++i) {
    a[i] = n;
    n = n * 10 + 9;
  }
}
int numdigit(long long n) {
  int res = 0;
  while (n) {
    ++res;
    n /= 10;
  }
  return res;
}
long long ans(long long n) {
  if (n <= 9) return n;
  long long num = numdigit(n);
  long long diff = n - a[num - 1];
  return diff * num + ans(a[num - 1]);
}
int main() {
  init();
  long long n;
  cin >> n;
  cout << ans(n);
  return 0;
}

//package vanyaAndBooks;

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

public class VanyaAndBooks {

	public static void main(String[] args) {

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

		int n = 0;
		try {
			n = Integer.parseInt(br.readLine());
		} catch (Exception e) {
			System.out.println(e.getMessage());
			return;
		}

		long numDigits = 0;

		int pow = 0;
		while (true) {
			//System.out.println(numDigits);
			pow++;
			long tekPow = (long)Math.pow(10, pow);

			if (tekPow <= n) {
				numDigits += 9 * Math.pow(10, pow - 1) * pow;
			} else {
				numDigits += (n - Math.pow(10, pow - 1) + 1) * pow;
				break;
			}
		}

		System.out.println(numDigits);
	}
}


#include <bits/stdc++.h>
using namespace std;
int main() {
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  int misha1 = a - (a / 250) * c;
  int vasiya1 = b - (b / 250) * d;
  int misha2 = (3 * a) / 10;
  int vasiya2 = (3 * b) / 10;
  int misha = max(misha1, misha2);
  int vasiya = max(vasiya1, vasiya2);
  if (vasiya > misha)
    printf("Vasya\n");
  else if (vasiya < misha)
    printf("Misha\n");
  else
    printf("Tie\n");
  return 0;
}

Tie Vasya Vasya Tie Misha Misha Vasya Vasya Misha Tie Tie Tie Vasya Misha Misha Misha Vasya Vasya Vasya Tie Tie Vasya Misha Tie Tie Misha Vasya Tie Misha Misha Misha Vasya Vasya Tie Misha Misha Misha Misha Tie Misha Misha Tie Vasya Vasya Misha Vasya Misha Misha Vasya Vasya

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

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

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

        int mScore = Math.max(3*a/10, a - c*a/250);
        int vScore = Math.max(3*b/10, b - d*b/250);

        if (mScore>vScore){
            out.print("Misha");
        } else if (mScore < vScore){
            out.print("Vasya");
        } else {
            out.print("Tie");
        }

    }
}


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

//package oak;

import java.math.BigInteger;
import java.util.Collections;
import java.util.Scanner;
import java.util.Vector;

public class Main {

    static void d(Object x) {  System.out.println(x);  }
    static Scanner in = new Scanner(System.in);

    public static void main(String[] args) {
        Vector<Integer> v = new Vector<Integer>();

        int a;
        int b;
        int c;
        while(in.hasNext()){
            a = in.nextInt();
            b = in.nextInt();
            c = in.nextInt();

            v.addElement(a+b+c);
            v.addElement(a+b*c);
            v.addElement(a*b+c);
            v.add(a*b*c);
            v.add((a+b)*c);
            v.add(a*(b+c));

            int C = Collections.max(v);
            d(C);

            v.clear();

        }

    }

}

#include <bits/stdc++.h>
using namespace std;
int main() {
  int a, b, c;
  cin >> a >> b >> c;
  int first = a + b * c, second = a * (b + c), third = a * b * c,
      fourth = (a + b) * c, fifth = a + b + c, sixth = (a * b) + c;
  cout << max(max(first, max(second, third)), max(fourth, max(fifth, sixth)))
       << endl;
  return 0;
}


#include <bits/stdc++.h>
using namespace std;
long long a[200000];
long long dp[200000][2];
int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    long long x;
    cin >> x;
    a[x]++;
  }
  long long ans = 0;
  for (long long i = 1; i <= 1e5; i++) {
    dp[i][1] = max(dp[i - 1][1], dp[i - 1][0] + i * a[i]);
    dp[i][0] = dp[i - 1][1];
    ans = max(max(dp[i][1], dp[i][0]), ans);
  }
  cout << ans;
}

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

public class Boredom implements Closeable {

    private InputReader in = new InputReader(System.in);
    private PrintWriter out = new PrintWriter(System.out);

    public void solve() {
        int n = in.ni();
        int max = 0;
        int[] x = new int[n];
        for (int i = 0; i < n; i++) {
            x[i] = in.ni();
            if (x[i] > max) max = x[i];
        }
        long[] cnt = new long[max + 1];
        for (int i = 0; i < n; i++) {
            cnt[x[i]]++;
        }
        long[] dp = new long[max + 1];
        dp[0] = 0; dp[1] = cnt[1];
        for (int i = 2; i <= max; i++) {
            dp[i] = Math.max(dp[i - 1], dp[i - 2] + i * cnt[i]);
        }
        out.println(dp[max]);
    }

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

    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 ni() {
            return Integer.parseInt(next());
        }

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

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

    public static void main(String[] args) throws IOException {
        try (Boredom instance = new Boredom()) {
            instance.solve();
        }
    }
}


import java.util.Scanner;
import java.util.Arrays;
import java.util.*;
import java.lang.*;

public class Code {

	public static void main(String[] args) {
		Scanner cin = new Scanner(System.in);
		int numBidders = cin.nextInt();
		int max = -9999999;
		int index = 0;
		int temp =0;

		int[] arr = new int[numBidders];

		for(int i=0;i<numBidders;i++) {
			arr[i] = cin.nextInt();
			if(max < arr[i]) {
				max = arr[i];
				index = i;

			}
		}

		Arrays.sort(arr);

		System.out.println(index+1 +" "+ arr[arr.length-2]);

		cin.close();
	}
}

a=int(input())
a=list(map(int,input().split()))
ind=a.index(max(a))
a.sort()
print(str(ind+1)+' '+str(a[-2]))


c=[]
n=int(input())
for uygf in range(n):
    s=list(input())
    l=len(s)
    i=0
    p=[]
    d=['u','o','k','h']
    while(i<l):
        if(s[i] not in d):
            p.append(s[i])
            i+=1
        elif(s[i]=='u'):
            p.append('o')
            p.append('o')
            i+=1
        elif(s[i]=='k'):
            y=i+1
            while(y<l and s[y]=='k'):
                y+=1
            if(y!=l):
                if(s[y]=='h'):

                    p.append('h')
                    i=y+1
                else:
                    for pp in range(i,y):
                        p.append('k')
                    i=y
            else:
                for pp in range(i,y):
                    p.append('k')
                i=y
        else:
            p.append(s[i])
            i+=1

    c.append(p)
d=[]
for i in range(n):
    if(i in d):
        continue
    for j in range(i+1,n):
        if(c[i]==c[j]):
            d.append(j)
print(n-len(d))

10
mihail
oolyana
kooooper
hoon
ulyana
koouper
mikhail
khun
kuooper
kkkhoon

100
uh
u
ou
hk
okh
uou
k
o
uhh
k
oku
k
ou
huh
koo
uo
kk
kok
hhu
uu
oou
k
k
oh
hk
k
u
o
uo
o
o
o
hoh
kuo
huh
khu
uu
k
oku
k
h
uu
uo
huo
oo
hu
ukk
ok
o
oh
uo
kko
ok
ouh
koh
hhu
ku
ko
hho
kho
kho
khk
ho
hk
uko
ukh
h
kh
kk
uku
kkk
o
uo
o
ouh
ou
uhk
ou
k
h
kko
uko
o
u
ho
u
ooo
uo
o
ko
oh
kh
uk
ohk
oko
uko
h
h
oo
o

9
hoon
khun
kkkhoon
khoon
hkon
khon
khoon
hkon
khon

40
oooo
hu
o
hoh
khk
uuh
hu
ou
uuoh
o
kouk
uouo
u
ok
uu
uuuo
hoh
uu
kuu
h
u
kkoh
khh
uoh
ouuk
kuo
k
u
uku
h
u
k
huho
ku
h
oo
uh
k
uo
ou

9
hariton
hkariton
buoi
kkkhariton
boooi
bui
khariton
boui
boi

10
mikhail
mihail
mihael
mihael
mihael
mikhail
mihail
mihael
mihael
mikhail

101
ukuu
h
ouuo
o
kkuo
ko
u
h
hku
h
h
huo
uhoh
kuu
hu
hkko
uhuk
koho
h
hukk
oohu
kk
kko
ou
oou
h
uuu
uh
khuk
okoo
ouou
uo
kk
oo
huok
o
u
hok
hu
hhuu
kuu
ooho
oku
huoh
hhkh
uuuh
ouo
hou
hhu
h
o
okou
uo
h
ukk
u
hook
h
oouk
okuo
kuuu
k
uuk
u
ukk
kk
u
uhk
h
k
okuu
uoho
khuk
hukk
hoo
ouko
u
uu
u
h
huo
h
ukk
hk
k
uoh
hk
ko
ou
ho
u
hhhk
kuo
huo
hkh
ku
hok
ho
kok
hk
ouuh

8
kooooper
koouper
kuooper
kupper
koooper
kuoper
kopper
kuper

7
oolyana
ulyana
ooliana
ulyana
ooliana
ulyana
ooliana

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

public class Main {

	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int n = scanner.nextInt();
		HashSet<String> set = new HashSet<String>();
		while(n-->0){
			String s = scanner.next();
			s = s.replace("u", "oo");
			s = s.replaceAll("k+h", "h");
			set.add(s);
		}
		System.out.println(set.size());
	}
}


#include <bits/stdc++.h>
using namespace std;
int a[100005], vis[100005];
int main() {
  int n;
  scanf("%d", &n);
  int t = n;
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
    vis[a[i]] = 1;
    for (; vis[t] == 1; t--) printf("%d ", t);
    printf("\n");
  }
  return 0;
}

n = int(input())
s = list(map(int, input().split()))
e1 = []
e2 = set()

f = '\n'
r = ''
for i in s:
    '''e1.append(i)
    while n in e1:
        print(n, end=' ')
        n -= 1
    print()'''

    e2.add(i)
    while n in e2:
        print(n, end=' ')
        n -= 1
    print()


import logging
import copy
import sys
import math

logging.basicConfig(stream=sys.stderr, level=logging.DEBUG)

#def solve(firstLine):
def solve(formatStr, timeStr):

    if int(timeStr[3]) > 5 :
        timeStr =  timeStr[:3] + "0" + timeStr[4:]

    if formatStr == 24:
        if int(timeStr[0]) > 2:
            timeStr = "0" + timeStr[1:]
        elif int(timeStr[0]) == 2 and int(timeStr[1]) >= 4:
            timeStr = timeStr[0] +  "0" + timeStr[2:]

    if formatStr == 12:
        if int(timeStr[0]) > 1:
            if int(timeStr[1]) == 0:
                timeStr = "1" + timeStr[1:]
            else:
                timeStr = "0" + timeStr[1:]
        elif int(timeStr[0]) == 1 and int(timeStr[1]) > 2:
            timeStr = "0" + timeStr[1:]
        elif int(timeStr[0]) == 0 and int(timeStr[1]) == 0:
            timeStr = "01" + timeStr[2:]

    return timeStr

def main():
    formatStr = int(input())

    print(solve(formatStr, input()))

def log(*message):
    logging.debug(message)

if __name__ == "__main__":
    main()


#include <bits/stdc++.h>
using namespace std;
int main() {
  int h1, h2, a, b;
  cin >> h1 >> h2;
  cin >> a >> b;
  h1 += 8 * a;
  if (h1 >= h2) {
    cout << 0;
    return 0;
  }
  if (b >= a) {
    cout << -1;
    return 0;
  }
  int ans = 0;
  while (1) {
    ans++;
    h1 -= 12 * b;
    h1 += 12 * a;
    if (h1 >= h2) {
      cout << ans;
      return 0;
    }
  }
  return 0;
}

import java.util.Scanner;

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

	public static void main(String[] args) {
		long h1 = sc.nextInt();
		long h2 = sc.nextInt();
		long a = sc.nextInt();
		long b = sc.nextInt();

		if(b>=a) {
			if(h2-h1 <= 8*a) {
				System.out.println(0);
			} else {
				System.out.println(-1);
			}
			return;
		}

		long days = -1;
		long h = h1-4*a;
		while(true) {
			days++;
			h += 12*a;

			if(h>=h2) {
				break;
			}

			h -= 12*b;
		}
		System.out.println(days);
	}

}


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

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

	static class TaskE {
		public void solve(int testNumber, InputReader in, OutputWriter out) {
			int n = in.readInt();
			int[][] p = IOUtils.readIntTable(in, n, n);
			double[] retain = new double[n];
			Arrays.fill(retain, 1);
			double[] answer = new double[n];
			double[] accumulated = new double[n];
			Arrays.fill(answer, Double.POSITIVE_INFINITY);
			answer[n - 1] = 0;
			boolean[] processed = new boolean[n];
			for (int i = 0; i < n; i++) {
				double best = Double.POSITIVE_INFINITY;
				int at = -1;
				for (int j = 0; j < n; j++) {
					if (!processed[j] && best > answer[j]) {
						best = answer[j];
						at = j;
					}
				}
				if (at == -1) {
					break;
				}
				processed[at] = true;
				for (int j = 0; j < n; j++) {
					if (processed[j] || p[j][at] == 0 || retain[j] == 0) {
						continue;
					}
					double nAccumulated = accumulated[j] + retain[j] * p[j][at] / 100d * (answer[at]);
					double nRetain = retain[j] * (1 - p[j][at] / 100d);
					double nAnswer = (1 + nAccumulated) / (1 - nRetain);
					if (nAnswer < answer[j]) {
						accumulated[j] = nAccumulated;
						retain[j] = nRetain;
						answer[j] = nAnswer;
					}
				}
			}
			out.printLine(answer[0]);
		}

	}

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

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

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

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

		public boolean isSpaceChar(int c) {
			if (filter != null)
				return filter.isSpaceChar(c);
			return isWhitespace(c);
		}

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

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

		}

	}

	static class IOUtils {
		public static int[] readIntArray(InputReader in, int size) {
			int[] array = new int[size];
			for (int i = 0; i < size; i++)
				array[i] = in.readInt();
			return array;
		}

		public static int[][] readIntTable(InputReader in, int rowCount, int columnCount) {
			int[][] table = new int[rowCount][];
			for (int i = 0; i < rowCount; i++)
				table[i] = readIntArray(in, columnCount);
			return table;
		}

	}

	static class OutputWriter {
		private final PrintWriter writer;

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

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

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

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

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

	}
}


from collections import defaultdict
_ =  input()

nums  = list(map(int, input().split()))

freqs = defaultdict(list)

_max =  -1
for i, k in enumerate(nums):
    freqs[k].append(i + 1)
    _max = max(_max, len(freqs[k]))

start = 1
end = len(nums)
length = end - start
for k, v in freqs.items():
    if len(v) == _max:
        if v[-1] - v[0] < length:
            start = v[0]
            end = v[-1]
            length  = end - start

print(start, end)

#include <bits/stdc++.h>
using namespace std;
int arr[100000];
int main() {
  int n;
  cin >> n;
  vector<int> vc;
  map<int, int> mp;
  map<int, int> fs;
  map<int, int> ls;
  int cnt = 0;
  for (int i = 0; i < n; i++) {
    cin >> arr[i];
    if (mp[arr[i]] == 0) {
      fs[arr[i]] = i;
      vc.push_back(arr[i]);
      cnt++;
    }
    mp[arr[i]]++;
    ls[arr[i]] = i;
  }
  if (cnt == n)
    cout << "1 1" << endl;
  else {
    int mx = 0;
    for (int i = 0; i < cnt; i++) {
      mx = max(mx, mp[vc[i]]);
    }
    vector<int> p;
    for (int i = 0; i < cnt; i++) {
      if (mp[vc[i]] == mx) p.push_back(vc[i]);
    }
    int l = 0;
    int r = n - 1;
    for (int i = 0; i < p.size(); i++) {
      int xx = p[i];
      int ll, rr;
      ll = fs[xx];
      rr = ls[xx];
      int d1, d2;
      d1 = rr - ll;
      d2 = r - l;
      if (d1 < d2) {
        l = ll;
        r = rr;
      }
    }
    l++;
    r++;
    cout << l << " " << r << endl;
  }
}


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

import java.util.Scanner;

public class CodeForces {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        switch (n) {
            case 1:
                System.out.println(1);
                break;
            case 2:
                System.out.println(2);
                break;
            case 3:
                System.out.println(6);
                break;
            case 4:
                System.out.println(20);
                break;
            case 5:
                System.out.println(70);
                break;
            case 6:
                System.out.println(252);
                break;
            case 7:
                System.out.println(924);
                break;
            case 8:
                System.out.println(3432);
                break;
            case 9:
                System.out.println(12870);
                break;
            case 10:
                System.out.println(48620);
                break;
            default:
                System.out.println(0);
        }
    }
}


(n,m) = input().split()
n=int(n)
m=int(m)
for i in range(0,10**5):
    n+=n%m
    if n%m == 0:
        break
if (n%m == 0): print("Yes")
else: print('No')

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

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

public  class Solution {

    public static void main(String[] args) throws Exception {
        Scanner in = new Scanner(System.in);
        Set <BigInteger> st = new HashSet<BigInteger>();
        BigInteger x = in.nextBigInteger();
        BigInteger m = in.nextBigInteger();
        BigInteger p;
        p = x.mod(m);
        while(!p.equals(BigInteger.ZERO))
        {
            if(!st.add(p))
            {
                System.out.print("No");
                break;
            }
            x = x.add(p);
            p = x.mod(m);
        }
        if(p.equals(BigInteger.ZERO))
            System.out.print("Yes");
    }
}


#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7, N_MAX = 1e5;
int n;
vector<int> gr[N_MAX + 2];
bool col[N_MAX + 2];
int dp[N_MAX + 2][2];
void dfs(int arg) {
  dp[arg][0] = !col[arg];
  dp[arg][1] = col[arg];
  for (auto it : gr[arg]) {
    dfs(it);
    int aux0 = dp[arg][0], aux1 = dp[arg][1];
    dp[arg][0] = (1LL * aux0 * dp[it][0] + 1LL * aux0 * dp[it][1]) % MOD;
    dp[arg][1] = (1LL * aux0 * dp[it][1] + 1LL * aux1 * dp[it][0] +
                  1LL * aux1 * dp[it][1]) %
                 MOD;
  }
}
int main() {
  cin >> n;
  for (int i = 1; i < n; i++) {
    int x;
    cin >> x;
    gr[x].push_back(i);
  }
  for (int i = 0; i < n; i++) cin >> col[i];
  dfs(0);
  cout << dp[0][1];
  return 0;
}

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.ArrayList;
import java.util.List;
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;
	final long del=(long) (1e9+7);
	List<List<Integer>> edges;
	int[] colour;
	boolean[] visited;
	long[] hasOne, hasZero;

	void processNode(int curNode){
		if (!visited[curNode]){
			visited[curNode]=true;
			hasOne[curNode]=0;
			hasZero[curNode]=1;
			for (Integer child : edges.get(curNode)){
				if (!visited[child]){
					processNode(child);
					long newOne=(hasZero[curNode]*hasOne[child]+hasOne[curNode]*hasZero[child])%del;
					long newZero=(hasZero[curNode]*hasZero[child])%del;
					hasOne[curNode]=newOne;
					hasZero[curNode]=newZero;
				}
			}
			if (colour[curNode]==1){
				hasOne[curNode]=hasZero[curNode];
			} else {
				hasZero[curNode]=(hasZero[curNode]+hasOne[curNode])%del;
			}
		}
	}

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

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

		colour = new int[n];
		visited = new boolean[n];
		for (int i=0; i<n-1; i++){
			int p = nextInt();
			edges.get(i+1).add(p);
			edges.get(p).add(i+1);
		}
		for (int i=0; i<n; i++){
			colour[i]=nextInt();
		}

		hasOne=new long[n];
		hasZero=new long[n];

		processNode(0);
		pw.println(hasOne[0]);
		pw.flush();
		pw.close();
	}

}


import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.PriorityQueue;
import java.util.StringTokenizer;

public class Main
{

	private static BufferedWriter out;

	public static void main(String[] args) throws IOException
	{
		// The input and output streams
		boolean file = false;
		BufferedReader in;
		if (file)
			in = new BufferedReader(new FileReader("input.txt"), 32768);
		else
			in = new BufferedReader(new InputStreamReader(System.in), 32768);
		out = new BufferedWriter(new OutputStreamWriter(System.out));
		StringTokenizer tok;

		// take input
		tok = new StringTokenizer(in.readLine());
		int n = Integer.parseInt(tok.nextToken());

		String pattern = in.readLine();
		int l = pattern.length();
		char chars[] = new char[l];
		for (int i = 0; i < l; i++)
			chars[i] = pattern.charAt(i);

		// take the rest
		for (int i = 0; i < n-1; i++)
		{
			pattern = in.readLine();
			for (int j = 0; j < l; j++)
			{
				char c = pattern.charAt(j);
				if (c != '?')
				{
					if (chars[j] == '?')
						chars[j] = c;
					else if (c != chars[j])
						chars[j] = '.';
				}
			}
		}

		// make the answers
		StringBuilder ans = new StringBuilder();
		for (int i = 0; i < l; i++)
		{
			if (chars[i] == '?')
				ans.append("x");
			else if (chars[i] == '.')
				ans.append('?');
			else
				ans.append(chars[i]);
		}

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

	}

}

n = int(input())
matrix = []
for _ in range(n):
    pattern = list(input())
    matrix.append(pattern)

m = len(matrix[0])
answer = []
for i in range(m):
    memo = set()
    question = False
    for j in range(n):
        if matrix[j][i].isalpha():
            memo.add(matrix[j][i])
        else:
            question = True
    memo = list(memo)

    if len(memo) == 0:
        answer.append('a')
    elif len(memo) == 1:
        answer.append(memo[0])
    else:
        answer.append('?')

result = "".join(answer)
print(result)


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

public class Arena {

    public static void main(String[] args) {
        MyScanner input = new MyScanner();
        PrintWriter output = new PrintWriter(new BufferedOutputStream(System.out));

        String number = input.nextLine();

        while (number.length() > 0) {
            if (number.startsWith("144")) {
                number = number.substring(3);
            } else if (number.startsWith("14")) {
                number = number.substring(2);
            } else if (number.startsWith("1")) {
                number = number.substring(1);
            } else {
                break;
            }
        }

        if (number.length() == 0) {
            output.println("YES");
        } else {
            output.println("NO");
        }

        output.close();
    }

    private static class MyScanner {
        BufferedReader br;
        StringTokenizer st;

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

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

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

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

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

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

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

a=input()
result=1
if a[0]!='1':
    print('NO')
    result=0
else:
    for i in range(len(a)):
        if a[i]!='1' and a[i]!='4':
            print('NO')
            result=0
            break
    if result==1:
        length=len(a)
        for i in range(length-2):
            if a[i]=='4' and a[i+1]=='4' and a[i+2]=='4':
                print('NO')
                result=0
                break
if result==1:
    print('YES')


var inp = readline().split(' ').map(function(cur,i,ar){return parseInt(cur.trim());});
var n = inp[0], k = inp[1];
var a = {}, len = new Array(n);
inp = readline().split(' ').map(function(cur,i,ar){return parseInt(cur.trim());});
inp.sort(function(a,b){return a - b;});

for(var i = 0; i < n; i++) {
    a[inp[i]] = i;
    if(inp[i] % k == 0 && a[inp[i] / k] != undefined){
        var t = a[inp[i] / k];
        len[i] = len[t] + 1;
        len[t] = 0;
    }
    else len[i] = 1;
}
var ans = 0;
for(var i = 0; i < n; i++)
    ans += Math.floor((len[i] + 1) / 2);
print((k == 1)? n : ans);

#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long int n, k;
  cin >> n >> k;
  if (k == 1) {
    cout << n;
    return 0;
  }
  if (n == 1) {
    cout << 1;
    return 0;
  }
  set<long long int> s;
  for (long long int i = 0; i < n; i++) {
    long long int x;
    cin >> x;
    s.insert(x);
  }
  for (auto it = s.begin(); it != s.end(); it++) {
    long long int t = *it;
    if (s.find(t * k) != s.end()) {
      s.erase(s.find(t * k));
    }
  }
  int ans = s.size();
  cout << ans;
}


#include <bits/stdc++.h>
using namespace std;
int s, k;
int f[1000005];
vector<int> vec;
int sum = 1, m = 0, t = 0;
void k_bonacci() {
  f[0] = 1;
  int sum = 1;
  for (int i = 1;; i++) {
    if (sum > s) break;
    f[i] = sum;
    sum += f[i];
    if (i + 1 > k) sum -= f[i - k];
    t++;
  }
}
void solve() {
  int j = t;
  while (s) {
    if (s >= f[j]) {
      s -= f[j];
      vec.push_back(f[j]);
    }
    j--;
  }
  if (vec.size() == 1)
    cout << 2 << endl << 0 << " " << *vec.begin() << endl;
  else {
    cout << vec.size() << endl;
    for (vector<int>::iterator i = vec.begin(); i != vec.end(); i++)
      cout << *i << " ";
    cout << endl;
  }
}
int main() {
  cin >> s >> k;
  k_bonacci();
  solve();
  return 0;
}

def s():
    [s,k] = list(map(int,input().split()))
    d = [0]
    d.append(1)
    t = 0
    r = []
    while t < s:
        t = sum(d[-min(k,len(d)):])
        d.append(t)
    for i in reversed(d):
        if i <= s:
            s -= i
            r.append(i)
            if i == 0:
                break
    print(len(r))
    print(*r)
s()


#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:256000000")
using namespace std;
int inf = 100000;
int main() {
  int n, k;
  cin >> n >> k;
  vector<pair<int, int> > t(n);
  for (int i = 0; i < n; i++) cin >> t[i].first >> t[i].second;
  n++;
  t.push_back(make_pair(86401, 1));
  int K = n - k;
  vector<int> d(K + 1, inf);
  d[0] = 1;
  int ans = 0;
  for (int i = 0; i < n; i++) {
    int p = max(i - k, 0);
    int m = inf;
    for (int j = p; j <= K; j++) m = min(m, d[j]);
    if (m <= t[i].first) ans = max(ans, t[i].first - m);
    for (int j = K; j > 0; j--) {
      int u;
      if (d[j - 1] > t[i].first)
        u = d[j - 1] + t[i].second;
      else
        u = t[i].first + t[i].second;
      d[j] = min(d[j], u);
    }
  }
  cout << ans << endl;
}

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

import static java.lang.Math.*;

public class Solution implements Runnable {

	int n, k;

	int t [], d [];

	public void solve() throws Exception {
		n = nextInt();
		k = nextInt();
		t = new int [n + 1];
		d = new int [n + 1];

		int dp [][] = new int [n + 2][k + 1];
		for (int i = 0; i < n + 2; i++)
			Arrays.fill(dp[i], Integer.MAX_VALUE / 2);

		for (int i = 0; i < n; i++) {
			t[i] = nextInt();
			d[i] = nextInt();
		}

		t [n] = 86401;
		d [n] = 1;

		int bestResult = 0;
		dp[0][0] = 0;
		for (int i = 0; i < n + 1; i++) {
			for (int j = 0; j <= k; j++) {
				if (dp[i][j] != Integer.MAX_VALUE / 2) {
					int stime = t[i];
					if (stime <= dp[i][j]) {
						stime = dp[i][j] + 1;
					}
					bestResult = max (bestResult, min (stime, 86401) - dp[i][j] - 1);
					if (i < n + 1) {
						// miss
						if (j < k)
							dp[i + 1][j + 1] = min (dp[i + 1][j + 1], dp[i][j]);
						// call
							dp[i + 1][j] = min (dp[i + 1][j], stime + d[i] - 1);
					}
				}
			}
		}
		out.println(bestResult);

	}

	/*******************************************************************************/

	public static void main(String[] args) throws Exception {
		new Thread(null, new Solution(), "", 1 << 26).start();
	}

	BufferedReader in;
	PrintWriter out;
	StringTokenizer st;

	private String next() throws Exception {
		if (st == null || !st.hasMoreElements())
			st = new StringTokenizer(in.readLine());
		return st.nextToken();
	}

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

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

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

	public void run() {
		try {
			in = new BufferedReader(new InputStreamReader(System.in));
			out = new PrintWriter(new OutputStreamWriter(System.out));
			solve();
		} catch (Exception ex) {
			throw new RuntimeException(ex);
		} finally {
			out.close();
		}
	}

}


import math
t=int(input())

while(t>0):
    l=(input().split())
    a=int(l[0])
    b=int(l[1])
    mov=math.ceil(math.fabs(b-a)/10)
    print(mov)
    t=t-1

import java.io.*;
import java.util.*;
public class j1to10 {
	public static void main(String args[]) {
		Scanner sc=new Scanner(System.in);
		long n=sc.nextLong();
		while(n-->0) {
				long a=sc.nextLong();
				long b=sc.nextLong();
				long d=Math.abs(a-b);
				System.out.println((d+9)/10);
		}
				sc.close();
	}
}


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

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

	A() {
		Scanner s = new Scanner(System.in);
		System.err.println("");

		int numAs = 300 - ask(s, build('a', 300));
		if(numAs == 300) return;
		int numBs = 300 - ask(s, build('b', 300));
		if(numBs == 300) return;
		int N = numAs+numBs;
		char[] res = new char[N];
		Arrays.fill(res, 'a');
		int initDist = numBs;

		int[] freq = new int[2];
		for(int i = 0; i < N-1; i++) {
			res[i] = 'b';
			int chk = ask(s, res);
			if(chk < initDist) {
				initDist = chk;
				freq[1]++;
			}
			else {
				res[i] = 'a';
				freq[0]++;
			}
			if(chk == 0) {
				return;
			}
		}
		if(freq[1] < numBs) res[N-1] = 'b';
		ask(s, res);
	}

	int ask(Scanner s, char[] str) {
		return ask(s, new String(str));
	}

	int ask(Scanner s, String str) {
		System.out.println(str);
		System.out.flush();
		int ret = s.nextInt();
		return ret;
	}

	String build(char a, int len) {
		String res = "";
		while(res.length() < len) res += a;
		return res;
	}

}

#include <bits/stdc++.h>
using namespace std;
int ask(string foo) {
  cout << foo << endl;
  fflush(stdout);
  int t;
  cin >> t;
  if (t == 0) exit(0);
  return t;
}
int main() {
  int n1 = 300 - ask(string(300, 'a'));
  int n2 = 300 - ask(string(300, 'b'));
  int n = n1 + n2;
  if (n1 == n) {
    ask(string(n, 'a'));
  }
  if (n2 == n) {
    ask(string(n, 'b'));
  }
  string s(n, 'a');
  int now = n2;
  for (int i = 0; i < n; i++) {
    s[i] = 'b';
    int cur = ask(s);
    if (cur > now) {
      s[i] = 'a';
    } else {
      now = cur;
    }
  }
  return 0;
}


#include <bits/stdc++.h>
using namespace std;
int ans(vector<vector<int> > &dp, int n, int v, int limit, int x) {
  if (dp[n][v] != x) {
    return dp[n][v];
  }
  if (n == 1) {
    return dp[n][v] = v;
  }
  int min_1 = INT_MAX;
  if (v + 1 <= limit) {
    min_1 = min(min_1, 0 + ans(dp, n - 1, v + 1, limit, x));
  }
  for (int i = v; i >= 0; i--) {
    min_1 = min(min_1, n * (v - i + 1) + ans(dp, n - 1, i, limit, x));
  }
  return dp[n][v] = min_1;
}
int main() {
  int n, v;
  cin >> n >> v;
  vector<vector<int> > dp(n + 1, vector<int>(v + 1, (n * v)));
  int min_1 = INT_MAX;
  for (int i = 0; i < v; i++) {
    min_1 = min(min_1, ans(dp, n, i, v, (n * v)));
  }
  cout << min_1 << endl;
  return 0;
}

import java.util.Scanner;

public class Main4 {

	public static void main(String args[]){

		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int total = sc.nextInt();
		int cnt = Math.min(n-1, total);
		int fuel = Math.min(n-1, total) - 1;
		//System.out.println("g " + cnt + "  " + fuel);
		for(int i=2;i<n;i++){
			if(n-i > fuel){
				cnt += Math.min(n-i-fuel, total-fuel)*i;
				fuel += Math.min(n-i-fuel, total-fuel);

				//System.out.println("g " + cnt + "  " + fuel + "  " + Math.min(n-i-fuel, total-fuel));
			}
			fuel--;
		}
		System.out.println(cnt);

	}
}


scalini = input()
conti_tania = input().split(" ")

numero_scale = 0
numero_scalini = []

n = 0
conta_scalini = ""
count = 1
x = 0
lista = []
conti_tania.append('0')

for n in range(int(len(conti_tania))-1):
    if int(conti_tania[n+1]) > int(conti_tania[n]):
        count += 1
        if int(conti_tania[n]) == 1:
            numero_scale += 1

    else: #conti_tania[n+1] < conti_tania[n]:
        lista.append(count)
        count = 1
        if conti_tania[n] == "1":
            numero_scale += 1

print(numero_scale)

listToStr = ' '.join([str(elem) for elem in lista])
print(listToStr)

import java.util.*;
public class TanyaAndStairways {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		int[] A = new int[n];
		scan.nextLine();
		for(int i = 0; i < n; i++) {
			A[i] = scan.nextInt();
		}
		int res = 0;
		ArrayList<Integer> list = new ArrayList<>();
		for(int i = 0; i < n; i++) {
			if(A[i] == 1) {
				res++;
			}
		}
		for(int i = 1; i < n; i++) {
			if(A[i] == 1) {
				list.add(A[i-1]);
			}
		}
		list.add(A[n-1]);
		System.out.println(res);
		for(int i = 0; i < list.size(); i++) {
			System.out.print(list.get(i) + " ");
		}
	}

}


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

public class test {
	/*
	 * array list
	 *
	 * ArrayList<Integer> al=new ArrayList<>(); creating BigIntegers
	 *
	 * BigInteger a=new BigInteger(); BigInteger b=new BigInteger();
	 *
	 * hash map
	 *
	 * HashMap<Integer,Integer> hm=new HashMap<Integer,Integer>(); for(int
	 * i=0;i<ar.length;i++) { Integer c=hm.get(ar[i]); if(hm.get(ar[i])==null) {
	 * hm.put(ar[i],1); } else { hm.put(ar[i],++c); } }
	 *
	 * while loop
	 *
	 * int t=sc.nextInt(); while(t>0) { t--; }
	 *
	 * array input
	 *
	 * int n = sc.nextInt(); int ar[] = new int[n]; for (int i = 0; i < ar.length;
	 * i++) { ar[i] = sc.nextInt(); }
	 */

	static class FastReader {
		BufferedReader br;
		StringTokenizer st;

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

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

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

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

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

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

	static class Pair {
		int first, second;

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

	}

	static class OutputWriter {
		private final PrintWriter writer;

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

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

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

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

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

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

	}

	private static final Scanner sc = new Scanner(System.in);
	private static final FastReader fs = new FastReader();
	private static final OutputWriter op = new OutputWriter(System.out);

	static int[] getintarray(int n) {
		int ar[] = new int[n];
		for (int i = 0; i < n; i++) {
			ar[i] = fs.nextInt();
		}
		return ar;
	}

	static long[] getlongarray(int n) {
		long ar[] = new long[n];
		for (int i = 0; i < n; i++) {
			ar[i] = fs.nextLong();
		}
		return ar;
	}

	static int[][] get2darray(int n, int m) {
		int ar[][] = new int[n][m];
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < m; j++) {
				ar[i][j] = fs.nextInt();
			}
		}
		return ar;
	}

	static Pair[] getpairarray(int n) {
		Pair ar[] = new Pair[n];
		for (int i = 0; i < n; i++) {
			ar[i] = new Pair(fs.nextInt(), fs.nextInt());
		}
		return ar;
	}

	static void printarray(int ar[]) {
		System.out.println(Arrays.toString(ar));
	}

	static boolean checkmyArray(int[] ar)

	{
		int temp = ar[0];
		for (int i = 1; i < ar.length; i++) {
			if (temp != ar[i])
				return false;
		}
		return true;
	}

	static int fact(int n) {
		int fact = 1;
		for (int i = 2; i <= n; i++) {
			fact *= i;
		}
		return fact;
	}

	public static void main(String[] args) {
//		int t = fs.nextInt();
		int t = 1;
		while (t > 0) {
			int n = fs.nextInt();
			if (n % 2 == 0)
				System.out.println("Mahmoud");
			else
				System.out.println("Ehab");

			t--;
		}
	}

}/*
	 * 1 5 -2 -3 -1 -4 -6till here
	 */

Ehab Ehab Mahmoud Mahmoud Ehab Mahmoud Mahmoud Mahmoud Ehab Mahmoud Ehab Ehab Mahmoud Mahmoud Mahmoud Ehab Ehab Mahmoud Mahmoud Ehab Ehab Ehab Mahmoud Mahmoud Ehab Ehab Ehab Mahmoud Mahmoud Ehab Ehab Mahmoud Mahmoud Mahmoud Ehab Ehab Ehab Mahmoud Mahmoud Ehab Ehab Ehab Mahmoud Mahmoud Ehab Mahmoud Ehab Ehab Ehab Mahmoud

import sys

def solve():
	n = int(input())
	if n%2 == 0:
		ans = "Mahmoud"
	else:
		ans = "Ehab"
	return ans
ans = solve()
print(ans)


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

if n % 2 == 0:
    print('0')
else:
    print(min(m // (n // 2 + 1) * k, min(a[::2])))

# Made By Mostafa_Khaled

#include <bits/stdc++.h>
using namespace std;
long long n, m, k, mn = 1e6, tmp;
int main() {
  cin >> n >> m >> k;
  for (int i = 0; i < n; i++) {
    scanf("%d", &tmp);
    if (i % 2 == 0) mn = min(mn, tmp);
  }
  if (n % 2 == 0) {
    cout << 0 << endl;
  } else {
    long long res = 0;
    for (int i = 0; i < min(k, mn); i++) {
      res += m / ((n + 1) / 2);
    }
    res = min(res, mn);
    cout << res << endl;
  }
  return 0;
}


n, k = eval(input().rstrip().replace(" ", ","))
k = min(k, 26)
letters = [chr(i) for i in range(97, 123)]
for i in range(n):
    print(letters[i%k], end="")

#include <bits/stdc++.h>
using namespace std;
long long i, j, n, k, l, m, r, x, y, K;
string s, t, s1;
int main() {
  cin >> n >> m;
  for (i = 0; i < n; i++) s.push_back('a' + i % m);
  cout << s << endl;
  return 0;
}


import sys
input = sys.stdin.readline
from heapq import heappop, heappush, heapify

n = int(input())
b, _ = map(int, input().split())
heap = []
heap2 = []
for _ in range(n-1):
    t, w = map(int, input().split())
    if t > b:
        heap.append(w + 1 - t)
    else:
        heap2.append((-t, -w))
heapify(heap)
heapify(heap2)
ans = len(heap) + 1
while heap:
    need = heap[0]
    if need > b:
        break
    b -= need
    heappop(heap)
    while heap2 and -heap2[0][0] > b:
        t, w = heappop(heap2)
        t, w = -t, -w
        heappush(heap, w + 1 - t)
    cur = len(heap) + 1
    ans = min(ans, cur)
print(ans)

#include <bits/stdc++.h>
using namespace std;
const int maxn = 3e5 + 10;
const int oo = 0x3f3f3f3f;
pair<long long, long long> a[maxn];
priority_queue<long long> q;
int main() {
  int n;
  while (~scanf("%d", &n)) {
    for (int i = 1; i <= n; i++) {
      scanf("%I64d %I64d", &a[i].first, &a[i].second);
    }
    sort(a + 2, a + 1 + n);
    reverse(a + 2, a + 1 + n);
    int r = 2;
    while (r <= n && a[r].first > a[1].first) {
      q.push(-(a[r].second - a[r].first + 1));
      ++r;
    }
    int ret = r - 1, f = 1;
    while (!q.empty()) {
      long long tmp = -q.top();
      q.pop();
      a[1].first -= tmp;
      if (a[1].first < 0) break;
      ++f;
      while (r <= n && a[r].first > a[1].first) {
        q.push(-(a[r].second - a[r].first + 1));
        ++r;
      }
      ret = min(ret, r - f);
    }
    printf("%d\n", ret);
  }
}


from math import factorial

def c(n, k):
    cur = factorial(n) // factorial(k)
    return cur // factorial(n - k)

n = int(input())
ans = c(n, 5) + c(n, 6) + c(n, 7)

print(ans)

#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<vector<long long> > C(n + 1, vector<long long>(n + 1));
  for (int i = 0; i < n + 1; i++) {
    C[i][0] = 1;
    C[i][i] = 1;
    for (int j = 1; j < i; j++) {
      C[i][j] = C[i - 1][j] + C[i - 1][j - 1];
    }
  }
  cout << C[n][5] + C[n][6] + C[n][7];
  return 0;
}


n, m = input().split(' ')

n = int(n)
m = int(m)

hints = {}

max_right = None
min_left = None

if m > 0:

    for i in range(m):
        do_nothing = False
        line = input().split(' ')
        hint_position = int(line[4])-1

        if line[2] == 'left':

            hint_box = hint_position - 1

            if min_left is None or hint_box < min_left:
                min_left = hint_box

            hint_pointer = -1

        else:

            hint_box = hint_position + 1

            if max_right is None or hint_box > max_right:
                max_right = hint_box

            hint_pointer = 1

        hints[hint_position] = hint_pointer

    value_1 = hints.get(max_right)

    if max_right is not None and min_left is not None:

        if max_right <= min_left:

            boxes = 0
            for i in range(max_right, min_left+1):
                value = hints.get(i)

                if value is None:
                    boxes +=1

            if boxes == 0:
                print(-1)
            else:
                print(boxes)

        else:
            print(-1)

    elif max_right is None:

        if min_left < 0:
            print(-1)
        else:
            print(min_left+1)

    else:
        if max_right > n-1:
            print(-1)
        else:
            print(n-max_right)

else:
    print(n)

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

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

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class Main implements Runnable {
    private void solve() throws IOException {
        int n = nextInt();
        int m = nextInt();
        int[] left = new int[m];
        int leftCount = 0;
        int[] right = new int[m];
        int rightCount = 0;

        for (int i = 0; i<m; i++){
            String s = nextToken();
            s = nextToken();
            s = nextToken();
            if (s.equals("left")){
                s = nextToken();
                left[leftCount] = nextInt();
                leftCount++;
            } else {
                s = nextToken();
                right[rightCount] = nextInt();
                rightCount++;
            }
        }
        int minLeft=n+1;
        int maxRight=0;
        for (int i = 0; i<leftCount; i++){
            if (i == 0)
                minLeft = left[i];
            if(left[i]<minLeft)
                minLeft = left[i];
        }

        for (int i = 0; i<rightCount; i++){
            if (i == 0)
                maxRight = right[i];
            if(right[i]>maxRight)
                maxRight = right[i];
        }

        if(minLeft - maxRight <=1){
            writer.println("-1");
        } else {

            int count = minLeft - (maxRight+1);
            writer.println(count);
        }

    }

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

//    static final String IN_FILE = "input.txt";
//    static final String OUT_FILE = "output.txt";

    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 nextInt() throws IOException {
        return Integer.parseInt(nextToken());
    }

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

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

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


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

public class B {

    final boolean ONLINE_JUDGE = System.getProperty("ONLINE_JUDGE") != null;
    BufferedReader in;
    PrintWriter out;
    StringTokenizer tok = new StringTokenizer("");

	void solve() throws IOException {
        int n = readInt();
        long m = readLong()-1;
        int[] res = new int[n];
        int l = 0;
        int right = n-1;
        for(int i = 0; i < n-1; i++) {
            int rev = n - i - 2;
            if((m & (1l << rev)) != 0) {
                res[right--] = i+1;
            } else {
                res[l++] = i+1;
            }
        }
        res[l] = n;
        for(int i = 0; i < n; i++) {
            out.print(res[i] + " ");
        }
	}

    void init() throws FileNotFoundException {
        if (ONLINE_JUDGE) {
            in = new BufferedReader(new InputStreamReader(System.in));
            out = new PrintWriter(System.out);
        } else {
            in = new BufferedReader(new FileReader("input.txt"));
            out = new PrintWriter("output.txt");
        }
    }

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

    int readInt() throws IOException {
        return Integer.parseInt(readString());
    }

    long readLong() throws IOException {
        return Long.parseLong(readString());
    }

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

    int[] readArr(int n) throws IOException {
        int[] res = new int[n];
        for (int i = 0; i < n; i++) {
            res[i] = readInt();
        }
        return res;
    }

    long[] readArrL(int n) throws IOException {
        long[] res = new long[n];
        for (int i = 0; i < n; i++) {
            res[i] = readLong();
        }
        return res;
    }

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

    public void run() {
        try {
            long t1 = System.currentTimeMillis();
            init();
            solve();
            out.close();
            long t2 = System.currentTimeMillis();
            System.err.println("Time = " + (t2 - t1));
        } catch (Exception e) {
            e.printStackTrace(System.err);
            System.exit(-1);
        }
    }
}

import sys
import math
import itertools

TESTING = False

def helper(length, knum):
    if length <= 1: return [1]
    possibilties = pow(2, length - 1);
    if knum <= possibilties / 2:
        temp = helper(length - 1, knum)
        for i in range(len(temp)): temp[i]+=1
        return [1]+temp;
    res = helper(length, possibilties - knum + 1);
    return res[::-1]

def solve():
    n , m = read()
    return helper(n, m)

def read(mode=2):
    inputs = input().strip()
    if mode == 0: return inputs  # String
    if mode == 1: return inputs.split()  # List of strings
    if mode == 2: return list(map(int, inputs.split()))  # List of integers

def write(s="\n"):
    if s is None: s = ""
    if isinstance(s, list): s = " ".join(map(str, s))
    if isinstance(s, tuple): s = " ".join(map(str, s))
    s = str(s)
    print(s, end="")

def run():
    if TESTING: sys.stdin = open("test.txt")
    res = solve()
    write(res)

run()


#include <bits/stdc++.h>
using namespace std;
const int N = 2e5;
int solve() {
  int m, s;
  cin >> m >> s;
  if (s == 0) {
    if (m != 1) {
      cout << "-1 -1" << endl;
    } else if (m == 1) {
      cout << "0 0" << endl;
    }
  } else {
    string mini = "", maxi = "";
    for (long long i = 0; i < m; i++) {
      int k = min(9, s);
      maxi.push_back('0' + k);
      s -= k;
    }
    if (s > 0) {
      cout << "-1 -1";
      return 0;
    }
    mini = maxi;
    reverse(mini.begin(), mini.end());
    int j = 0;
    while (mini[j] == '0') {
      j++;
    }
    mini[j]--;
    mini[0]++;
    cout << mini << " " << maxi;
  }
}
int main() { solve(); }

// CODE PRODUCED UNDER ACE PRODUCTIONS

import java.util.*;
public class Ace
{
    public static void main(String[] args)
    {
        Scanner sc=new Scanner(System.in);
       int m,s,i,j,k,d,p=0;
       m=sc.nextInt();
       s=sc.nextInt();
       int[] ar=new int[m];
       int[] br=new int[m];
       k=m*9;
    if(m==1&&s==0) System.out.print("0 0");
       else  if(s>0&&s<=k)
      {
          for(i=0;i<m;i++)
       {
         p=9;
         if(p<s)
         {
              ar[i]=p; br[i]=p;
             s=s-p;
         }
         else if(p>=s)
         {
             ar[i]=s; br[i]=s;
             s=0;
             break;
         }
       }

       if(br[m-1]==0)
       {
           for(i=m-1;i>=0;i--)
           {
               if(br[i]!=0)
               {br[m-1]++;
           br[i]--;
               break;
               }
           }
       }
       for(i=m-1;i>=0;i--)
          System.out.print(br[i]);
       System.out.print(" ");
       for(i=0;i<m;i++)
           System.out.print(+ar[i]);
      }
      else System.out.print("-1 -1");

    }
}


//package codeforces;

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

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

        long[][] t = new long[3][3];
        for (int i = 0; i < 3; i++)
            for (int j = 0; j < 3; j++)
                t[i][j] = in.nextLong();

        int n = in.nextInt();

        long[][] dp = new long[3][3];
        long[][] dp_prev = new long[3][3];

        for (int k = 0; k < n; k++) {
            copy(dp, dp_prev);

            for (int i = 0; i < 3; i++)
                for (int j = 0; j < 3; j++) {
                    if (i == j) continue;

                    int other = other(i, j);
                    long cost1 = dp_prev[i][other] + t[i][j] + dp_prev[other][j];
                    long cost2 = dp_prev[i][j] + t[i][other] + dp_prev[j][i] + t[other][j] + dp_prev[i][j];
                    dp[i][j] = Math.min(cost1, cost2);
                }
        }

        out.println(dp[0][2]);
        out.flush();
    }

    private static void copy(long[][] from, long[][] to) {
        for (int i = 0; i < 3; i++)
            System.arraycopy(from[i], 0, to[i], 0, 3);
    }

    private static int other(int i, int j) {
        if (0 != i && 0 != j) return 0;
        if (1 != i && 1 != j) return 1;
        return 2;
    }
}

#include <bits/stdc++.h>
using namespace std;
long long cost[200][200], dp[100][10][10], n, rem;
int main() {
  ios_base::sync_with_stdio(0);
  for (int i = 0; i < 3; i++)
    for (int j = 0; j < 3; j++) cin >> cost[i][j];
  cin >> n;
  for (int k = 1; k <= n; k++)
    for (int i = 0; i < 3; i++)
      for (int j = 0; j < 3; j++)
        if (i - j) {
          rem = (3 ^ i ^ j);
          dp[k][i][j] = min(dp[k - 1][i][rem] + cost[i][j] + dp[k - 1][rem][j],
                            dp[k - 1][i][j] + cost[i][rem] + dp[k - 1][j][i] +
                                cost[rem][j] + dp[k - 1][i][j]);
        }
  cout << dp[n][0][2] << endl;
  cin.get();
  cin.get();
  return 0;
}


#include <bits/stdc++.h>
using namespace std;
long long int x[1000007], y[1000007], z[1000007];
string s;
int main() {
  {
    long long int a = 0, b = 0, d, e, i, j, k, l, m, n, p = 1, q, r, t, u, val,
                  w, tc, mn = 2134567891, mx = 0, sum = 0, ans = 0;
    cin >> n;
    for (i = 0; i < n; i++) cin >> x[i];
    for (i = 0; i < n; i++) {
      if (x[i] == 25)
        a++;
      else if (x[i] == 50) {
        if (a)
          a--, b++;
        else {
          p = 0;
          break;
        }
      } else {
        if (a && b)
          a--, b--;
        else if (a >= 3)
          a -= 3;
        else {
          p = 0;
          break;
        }
      }
    }
    if (p)
      cout << "YES\n";
    else
      cout << "NO\n";
    memset(x, 0, sizeof(x));
  }
  return 0;
}

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

import java.util.Scanner;
public class test {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int x;
        int c25=0;
        int c50=0;
        boolean s=true;
        while(n--!=0){
            x=in.nextInt();
            if(s){
               if(x==25)
                  c25++;
               else if(x==50){
                   c25--;
                   c50++;
               }
               else {
                  if(c50>0){
                      c50--;
                      c25--;
                  }
                  else c25-=3;
                }
                  if(c25<0)s=false;
            }
        }
        if(s==true)System.out.println("YES");
        else System.out.println("NO");
    }
}


# METO Bot 0.9.9.1
n=int(input())
if n&1:
	print(-1)
else:
	D,R=[False]*(10**6),[0]*(10**6)
	i,j=0,0
	while True:
		D[j]=True
		R[i]=j
		i+=1
		if not D[(j+n)>>1]:
			j=(j+n)>>1
		elif not D[j>>1]:
			j=j>>1
		else:
			break
	print(" ".join(str(R[i]) for i in range(n,-1,-1)))

#include <bits/stdc++.h>
using namespace std;
const double eps = 1e-8;
const double pi = acos(-1.0);
const int N = 1e5 + 10;
vector<int> vec[N];
bool vis[N];
int dis[N], tt[N];
int n;
int spfa(int u) {
  if (vis[u]) return -1;
  vis[u] = 1;
  if (dis[u] != -1) return dis[u];
  if ((u * 2 + 1) % n == u) return dis[u] = spfa(u * 2 % n) + 1;
  int t1 = spfa((u * 2 + 1) % n), t2 = spfa((u * 2) % n);
  vis[u] = 0;
  return dis[u] = max(t1, t2) + 1;
}
int main() {
  int i;
  scanf("%d", &n);
  memset(dis, -1, sizeof(dis));
  dis[0] = 0;
  spfa(1);
  if (dis[1] != n - 1) {
    puts("-1");
    return 0;
  } else {
    for (i = 0; i < n; ++i) tt[dis[i]] = i;
  }
  printf("0 ");
  for (i = n - 1; i; --i) printf("%d ", tt[i]);
  printf("%d\n", tt[0]);
  puts("");
  return 0;
}


#include <bits/stdc++.h>
using namespace std;
int inds[5001];
int main() {
  ifstream in("input.txt");
  ofstream out("output.txt");
  int n;
  in >> n;
  int* ci = new int[n];
  for (int i = 0; i < n; i++) {
    in >> ci[i];
  }
  sort(ci, ci + n);
  memset(inds, -1, sizeof inds);
  for (int i = 0; i < n; i++) {
    inds[ci[i]] = i;
  }
  for (int i = 0; i < 5000; i++) {
    if (inds[i + 1] == -1) inds[i + 1] = inds[i];
  }
  int min = 90019001;
  for (int i = 0; i < n; i++) {
    int low = ci[i];
    int rem = i;
    if (low < 2500) {
      cout << "adding " << n - inds[low * 2] - 1 << endl;
      rem += n - inds[low * 2] - 1;
    }
    cout << rem << " for " << i << endl;
    if (min > rem) min = rem;
  }
  for (int i = 0; i < n; i++) cout << ci[i] << " ";
  cout << endl;
  for (int i = 0; i < 20; i++) cout << inds[i] << " ";
  cout << endl;
  out << min << endl;
  out.close();
  return 0;
}

yucky yucky yucky yucky yucky yucky yucky yucky yucky yucky yucky yucky yucky yucky yucky yucky yucky yucky yucky yucky yucky yucky yucky yucky yucky yucky yucky yucky yucky yucky yucky yucky yucky yucky yucky yucky yucky yucky yucky yucky yucky yucky

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.StringTokenizer;

public class PhysicsPractical {
    public static void main(String[] args) {
        int n;
        int[] arr;
        String str;
        try (BufferedReader br = new BufferedReader(new FileReader("input.txt"))) {
            PrintWriter pw = new PrintWriter(new BufferedWriter(new FileWriter("output.txt")));
            pw.flush();
            str = br.readLine();
            while (str != null) {
                arr = new int[5001];
                n = Integer.parseInt(str);
                str = br.readLine();
                StringTokenizer st = new StringTokenizer(str);
                for (int i = 0; i < n; i++) {
                    arr[Integer.parseInt(st.nextToken())]++;
                }
                int max = 0, cur;
                for (int i = 1; i <= arr.length / 2; i++) {
                    cur = 0;
                    for (int j = i; j <= 2*i; j++) {
                        cur += arr[j];
                    }
                    if (max <cur) {
                        max = cur;
                    }
                }
                pw.println(n-max);
                str = br.readLine();
            }
            pw.close();
        } catch (IOException e) {
            System.out.println("yucky");
        }
    }
}


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;
	int[] h;
	TSit[] sits;

	class TSit{

		int lastTow;
		int result;
	}

	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));
		n=nextInt();
		h=new int[n];
		for (int i=0; i<n; i++){
			h[i]=nextInt();
		}
		sits=new TSit[n+1];
		sits[0]=new TSit();
		sits[0].lastTow=0;
		sits[0].result=0;
		sits[1]=new TSit();
		sits[1].lastTow=h[0];
		sits[1].result=0;
		int curSum=h[0];
		int iback=0;
		for (int i=2; i<=n; i++){
			curSum=h[i-1];
			iback=i;
			while (curSum<sits[iback-1].lastTow){
				iback--;
				curSum+=h[iback-1];
			}
			/*while (iback<=i && curSum>=sits[iback-1].lastTow){
				curSum-=h[iback-1];
				iback++;
			}
			iback--;
			curSum+=h[iback-1];*/
			sits[i]=new TSit();
			sits[i].lastTow=curSum;
			sits[i].result=(i-iback);
			sits[i].result+=sits[iback-1].result;
		}
		pw.println(sits[n].result);
		pw.flush();
		pw.close();
	}

}


#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9;
const double EPS = 1e-9;
const int MaxN = 100000 + 5;
int N, A[MaxN];
int main(void) {
  scanf("%d", &N);
  for (int i = 0; i < N; i++) scanf("%d", &A[i]);
  sort(A, A + N);
  if (A[N - 1] != 1) {
    printf("%d", 1);
    for (int i = 1; i < N; i++) printf(" %d", A[i - 1]);
    printf("\n");
  } else {
    for (int i = 0; i < N - 1; i++) printf("%d ", A[i]);
    printf("%d\n", A[N - 1] + 1);
  }
  return 0;
}

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

public class Replacement {

	/**
	 * @param args
	 * @throws IOException
	 * @throws NumberFormatException
	 */
	public static void main(String[] args) throws NumberFormatException, IOException {
		BufferedReader reader=new BufferedReader(new InputStreamReader(System.in));
		int x=Integer.parseInt(reader.readLine());
		String st[]=reader.readLine().split(" ");
		int []f=new int[st.length];

		for(int i=0;i<st.length;i++)
			f[i]=Integer.parseInt(st[i]);
		Arrays.sort(f);
		if(f[f.length-1]!=1)
		{
			f[f.length-1]=1;
		}
		else
			f[f.length-1]+=1;
		Arrays.sort(f);
		StringBuilder ans=new StringBuilder("");
		for(int i=0;i<st.length;i++)
			ans.append(f[i]+" ");
		System.out.println(ans);

	}

}


import java.io.*;
import java.util.*;
public class MainClass{
    public static void task(InputReader in,PrintWriter out){
        //---------------------------------Solve here-------------------------------
        int n=in.nextInt();
        int m=in.nextInt();
        int a[]=new int[n];
        for(int i=0;i<n;i++)
        {
            a[i]=in.nextInt();
        }
        Arrays.sort(a);
        for(int i=0,j=n-1;i<=j;i++,j--)
        {
            int t=a[i];
            a[i]=a[j];
            a[j]=t;
        }
        boolean flag=false;
        for(int k=1;k<=n;k++)
        {
            int s=0;
            for(int i=0;i<n;i++)
            {
                s+=Math.max(0,a[i]-i/k);
            }
            if(s>=m)
            {
                out.println(k);
                flag=true;break;
            }
        }
        if(!flag)
        out.println("-1");
        //--------------------------------------------------------------------------
    }
    public static void main(String[] args)throws IOException {
        try{
            InputStream inputStream = System.in;
            OutputStream outputStream = System.out;
            InputReader in = new InputReader(inputStream);
            PrintWriter out = new PrintWriter(System.out);
            task(in, out);
            out.close();
        }
        catch(NumberFormatException e){
            System.out.println(e);
        }
    }
    public static class InputReader {
        /*
        String-nextString()
        int   -nextInt()
        double-nextDouble()
        long  -nextLong()
        char  -nextChar()
        line  -nextLine()
        */
		private InputStream stream;
		private byte[] buf = new byte[8192];
		private int curChar;
		private int numChars;
		private SpaceCharFilter filter;
		public InputReader(InputStream stream) {
			this.stream = stream;
		}
		public int read() {
			if (numChars == -1) {
				throw new InputMismatchException();
			}
			if (curChar >= numChars) {
				curChar = 0;
				try {
					numChars = stream.read(buf);
				} catch (IOException e) {
					throw new InputMismatchException();
				}
				if (numChars <= 0) {
					return -1;
				}
			}
			return buf[curChar++];
		}
		public int nextInt() {
			int c = read();
			while (isSpaceChar(c)) {
				c = read();
			}
			int sgn = 1;
			if (c == '-') {
				sgn = -1;
				c = read();
			}
			int res = 0;
			do {
				if (c < '0' || c > '9') {
					throw new InputMismatchException();
				}
				res *= 10;
				res += c - '0';
				c = read();
			} while (!isSpaceChar(c));
			return res * sgn;
		}
		public String nextString() {
			int c = read();
			while (isSpaceChar(c)) {
				c = read();
			}
			StringBuilder res = new StringBuilder();
			do {
				res.appendCodePoint(c);
				c = read();
			} while (!isSpaceChar(c));
			return res.toString();
		}
		public double nextDouble() {
			int c = read();
			while (isSpaceChar(c)) {
				c = read();
			}
			int sgn = 1;
			if (c == '-') {
				sgn = -1;
				c = read();
			}
			double res = 0;
			while (!isSpaceChar(c) && c != '.') {
				if (c == 'e' || c == 'E') {
					return res * Math.pow(10, nextInt());
				}
				if (c < '0' || c > '9') {
					throw new InputMismatchException();
				}
				res *= 10;
				res += c - '0';
				c = read();
			}
			if (c == '.') {
				c = read();
				double m = 1;
				while (!isSpaceChar(c)) {
					if (c == 'e' || c == 'E') {
						return res * Math.pow(10, nextInt());
					}
					if (c < '0' || c > '9') {
						throw new InputMismatchException();
					}
					m /= 10;
					res += (c - '0') * m;
					c = read();
				}
			}
			return res * sgn;
		}
		public long nextLong() {
			int c = read();
			while (isSpaceChar(c)) {
				c = read();
			}
			int sgn = 1;
			if (c == '-') {
				sgn = -1;
				c = read();
			}
			long res = 0;
			do {
				if (c < '0' || c > '9') {
					throw new InputMismatchException();
				}
				res *= 10;
				res += c - '0';
				c = read();
			} while (!isSpaceChar(c));
			return res * sgn;
		}
		public String nextLine() {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            StringBuilder res = new StringBuilder();
            do {
                res.appendCodePoint(c);
                c = read();
            } while (!isEndOfLine(c));
            return res.toString();
        }
        public char nextChar(){
            return nextString().charAt(0);
        }
		public boolean isSpaceChar(int c) {
			if (filter != null) {
				return filter.isSpaceChar(c);
			}
			return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
		}
		public String next() {
			return nextString();
		}
		public interface SpaceCharFilter {
			public boolean isSpaceChar(int ch);
		}
		private boolean isEndOfLine(int c) {
            return c == '\n' || c == '\r' || c == -1;
        }
	}
}

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using pint = pair<int, int>;
using pll = pair<ll, ll>;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll n, m;
  cin >> n >> m;
  vector<ll> a(n);
  for (ll i = 0; i < (ll)n; i++) cin >> a[i];
  sort(a.begin(), a.end());
  reverse(a.begin(), a.end());
  ll sum = 0;
  for (ll i = 0; i < (ll)n; i++) sum += a[i];
  if (sum < m) {
    cout << -1 << endl;
    return 0;
  }
  ll l = 0, r = n;
  while (r - l > 1) {
    ll mid = (l + r) / 2;
    ll power = 0;
    ll cnt = 0, cost = 0;
    for (ll i = 0; i < (ll)n; i++) {
      if (a[i] < cost) break;
      power += a[i] - cost;
      cnt++;
      if (cnt == mid) {
        cnt = 0;
        cost++;
      }
    }
    if (power >= m)
      r = mid;
    else
      l = mid;
  }
  cout << r << endl;
  return 0;
}


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

public class C {

	public static void main(String[] ar) throws IOException {
		BufferedReader in=new BufferedReader(new InputStreamReader(System.in));
		int n=Integer.parseInt(in.readLine());
		int closedCount[]=new int[500005];
		int openCount[]=new int[500005];
		for(int i=0;i<n;i++) {
			char[] c=in.readLine().toCharArray();
			char stack[]=new char[c.length];
			int pos=-1;
			for(int j=0;j<c.length;j++) {
				if(pos==-1) {
					pos++;
					stack[pos]=c[j];
				}else {
					if(c[j]==')' && stack[pos]=='(') {
						pos--;
					}else {
						pos++;
						stack[pos]=c[j];
					}
				}
			}
			int close=0,open=0;
			while(pos>=0) {
				if(stack[pos--]=='(') {
					open++;
				}else {
					close++;
				}
			}

			if(close>0 && open==0) {
				closedCount[close]++;
			}else if(open>0 && close==0) {
				openCount[open]++;
			}else if(open==0 && close==0) {
				openCount[0]++;
				closedCount[0]++;
			}
		}
		int ans=openCount[0]/2;
		for(int i=1;i<openCount.length;i++) {
			ans=ans+Math.min(openCount[i],closedCount[i]);
		}
		System.out.println(ans);
	}
}

n = int(input())
a = dict()
b = dict()
for i in range(n):
    s = input()
    k = 0
    max_k = 0
    op = True
    for j in s:
        if j == '(':
            k += 1
        else:
            k -= 1
            if k < max_k:
                max_k = k
        if k < 0:
            op = False
    if op == False and max_k < k:
        continue
    if op == True:
        if k in a.keys():
            a[k] += 1
        else:
            a[k] = 1
    else:
        if k in b.keys():
            b[k] += 1
        else:
            b[k] = 1
ss = 0
for i in a.keys():
    if i == 0:
        ss += int(a[i]/2)
    elif -i in b.keys():
        ss += min(a[i], b[-i])
print(ss)


'''
the max element would have 0 0 i both l,r
'''
from  collections  import defaultdict
def f(l,r):
    cnts=defaultdict(list)
    lmax=[0]*len(l)
    rmax=[0]*len(l)
    for i in range(len(l)):
        cnts[l[i]+r[i]].append(i)
    mx=len(l)
    ans=[0]*(len(l))
    for i in sorted(cnts):
        # print(lmax,rmax)
        for ind in cnts[i]:
            if lmax[ind]==l[ind] and rmax[ind]==r[ind]:
                ans[ind]=mx
            else:
                return "NO"
        for ind in cnts[i]:
            for j in range(0,ind):
                rmax[j]+=1
            for j in range(len(l)-1,ind,-1):
                lmax[j]+=1
        mx-=1
    print("YES")
    print(*ans)
    return ''

n=input()
l=list(map(int,input().strip().split()))
r=list(map(int,input().strip().split()))
print(f(l,r))

#include <bits/stdc++.h>
using namespace std;
int L[1000], R[1000];
int ans[1000];
vector<int> v;
int n;
int check(int lo);
int main(void) {
  scanf("%d", &n);
  for (int i = 0; i < n; i++) scanf("%d", L + i);
  for (int i = 0; i < n; i++) scanf("%d", R + i);
  for (int i = 0; i < n; i++) v.push_back(L[i] + R[i]);
  sort(v.begin(), v.end());
  v.erase(unique(v.begin(), v.end()), v.end());
  for (int i = 0; i < n; i++)
    ans[i] = n - (lower_bound(v.begin(), v.end(), L[i] + R[i]) - v.begin());
  for (int i = 0; i < n; i++) {
    if (check(i) == 0 || ans[i] < 0) {
      printf("NO\n");
      return 0;
    }
  }
  printf("YES\n");
  for (int i = 0; i < n; i++) printf("%d ", ans[i]);
}
int check(int lo) {
  int ll = 0, rr = 0;
  for (int i = 0; i < lo; i++) ll += (ans[i] > ans[lo]);
  for (int i = lo + 1; i < n; i++) rr += (ans[i] > ans[lo]);
  return (ll == L[lo]) && (rr == R[lo]);
}


#include <bits/stdc++.h>
using namespace std;
void show(vector<long long int> &a) {
  cout << a.size() << endl;
  for (int i = 0; i < a.size(); i++) cout << a[i] << " ";
  cout << endl;
}
int main() {
  long long int a, b;
  cin >> a >> b;
  vector<long long int> v1, v2;
  long long int k = 0;
  for (; (k + 1) * (k + 2) / 2 <= a + b; k++)
    ;
  long long int sum = k * (k + 1) / 2;
  long long int k1;
  for (k1 = k; k1 > 0 && b >= k1; k1--) {
    b -= k1;
    v2.push_back(k1);
  }
  if (b && b <= k1) v2.push_back(b);
  for (long long int i = 1; i <= k1; i++)
    if (i != b) v1.push_back(i);
  show(v1);
  show(v2);
}

a = input()
(a,b) = a.split(" ")
a = int(a)
b = int(b)

def binary_search(val):
	(l,r,ans)=(1,val,-1)
	while l<=r:
		mid = (l+r)//2
		if mid*(mid+1) <= 2*val:
			ans = mid
			l = mid+1
		else:
			r = mid-1

	return ans

val = binary_search(a+b)

lista = []
listb = []
vis = [0]*(val+1)
t = val
while a>0 and t>0:
	if a>=t:
		vis[t]=1
		lista.append(t)
		a-=t
		t-=1
	else:
		vis[a]=1
		lista.append(a)
		a=0

t = 1
while b>0:
	if b<t:
		break
	elif vis[t]==1:
		t+=1
	else:
		b-=t
		listb.append(t)
		t+=1

print(len(lista))
for x in lista:
	print(x,end=" ")
print('\n')
print(len(listb))
for x in listb:
	print(x,end=" ")


import java.util.Scanner;

public class AAvito {

	@SuppressWarnings("resource")
	public static void main(String[] args) {
		Scanner input = new Scanner(System.in);
		String s = input.next();
		while (s.length() > 0 && pal(s)){
			s = s.substring(0, s.length() - 1);
		}
		System.out.println(s.length());
	}

	public static boolean pal(String s){
		for (int i = 0; i < s.length() / 2; i++){
			if (s.charAt(i) != s.charAt(s.length() - i - 1)){
				return false;
			}
		}
		return true;
	}

}

abba aaabcdaaa mmm rrr www ooo mew aaaa wuffuw a qqqqqqqq anna hhh aaadcba refer lll wuffuw level aa racecar wow ppp ddd solos ccc fff mew iii bbb vvv sss civic aaabaa aaa qqq abracadabra noon ybejrrlbcintahovgjddrqatv deified kkk nnn radar ababa ttt jjj uuu qqqqqqqq madam ggg eee

a=input()
b=a[::-1]
c=0
if a!=b:
    print(len(a))
while a==b:
    a=a[:0]+a[(0+1):]
    b=a[::-1]
    if a!=b:
        print(len(a))
    else:
        print(c)
        break


var arr = readline().split(" ").map(v => +v.trim());

var l = arr[0];
var u = arr[1];

var cur = 1;

while (true)
{
	if (cur * 3 > u)
	{
		break;
	}
	cur *= 3;
}

var res = 0;

while (cur >= 1)
{
	var cur2 = 1;
	while (true)
	{
		if (cur2 * cur >= l)
		{
			++res;
		}

		if (cur2 * 2 * cur > u)
		{
			break;
		}

		cur2 *= 2;
	}

	cur = Math.floor(cur / 3);
}

print(res);

import sys
from math import *
from fractions import gcd
readints=lambda:map(int, input().strip('\n').split())

l,r=readints()

maxn=2*(10**9)
twos=set()
i=2
while i<=maxn:
    twos.add(i)
    i*=2

threes=set()
i=3
while i<=maxn:
    threes.add(i)
    i*=3

nums=set()
nums.add(1)
for x in twos:
    for y in threes:
        if x*y>maxn: continue
        nums.add(x*y)
for x in twos:
    nums.add(x)
for y in threes:
    nums.add(y)

# nums=list(sorted(list(nums)))

ans=0
for x in nums:
    if l<=x and x<=r:
        ans+=1
print(ans)


import java.util.Scanner;

public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int t = sc.nextInt();
		double[][] glasses = new double[n][n];
		for(int i=0;i<t;i++){
			glasses[0][0] += 1;
			for(int j=0;j<n-1;j++){
				for(int k=0;k<=j;k++){
					if(glasses[j][k] > 1){
						double rem = glasses[j][k] - 1;
						glasses[j][k] = 1;
						glasses[j + 1][k] += rem/2;
						glasses[j + 1][k + 1] += rem/2;
					}
				}
			}
		}
		int count = 0;
		for(int i=0;i<n;i++){
			for(int j=0;j<n;j++){
				if(glasses[i][j] >= 1){
					count++;
				}
			}
		}
		System.out.println(count);
	}
}


if __name__ == "__main__":

    n = int( input().strip() )
    s = input().strip()

    segs = []

    start = 0
    i = 1
    while i <= n:
        if i == n or s[i] != s[start]:
            segs.append( i - start )
            start = i
            i = start + 1
        else:
            i += 1

    res = len(segs)

    segs.sort()
    if segs[-1] >= 3:
        res += 2
    elif len(segs) >= 2 and segs[-1] >= 2 and segs[-2] >= 2:
        res += 2
    elif segs[-1] >= 2:
        res += 1

    print( res )


import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.io.PrintStream;
import java.math.BigInteger;
import java.util.HashMap;
import java.util.Map;
import java.util.StringTokenizer;

/*
 public class _507D {

 }

 */

public class _507D {
  public void solve() throws FileNotFoundException {
    InputStream inputStream = System.in;

    InputHelper inputHelper = new InputHelper(inputStream);

    PrintStream out = System.out;

    // actual solution

    int n = inputHelper.readInteger();
    int k = inputHelper.readInteger();
    int m = inputHelper.readInteger();

    long[][] mod = new long[n][10];

    for (int i = 0; i < n; i++) {
      for (int j = 0; j < 10; j++) {
        long num = j % k;
        for (int l = 0; l < i; l++) {
          num *= 10;
          num %= k;
        }
        mod[i][j] = num;
      }
    }

    long[][][] dp = new long[n][k][2];

    for (int j = 1; j < 10; j++) {
      dp[0][j % k][1]++;
    }

    if (n == 1) {
      System.out.println(dp[0][0][1] % m);
      return;
    }

    long[] mul = new long[n];

    mul[n - 1] = 1;
    mul[n - 2] = 9;

    for (int i = n - 3; i >= 0; i--) {
      mul[i] = (mul[i + 1] * 10) % m;
    }

    long ans = 0;

    ans += (dp[0][0][1] * mul[0]) % m;
    ans %= m;

    dp[0][0][0]++;

    for (int i = 1; i < n; i++) {
      for (int j = 0; j < 10; j++) {
        for (int l = 1; l < k; l++) {
          dp[i][((int) mod[i][j] + l) % k][1] += dp[i - 1][l][1];
          dp[i][((int) mod[i][j] + l) % k][1] %= m;
        }
        for (int l = 1; l < k; l++) {
          dp[i][((int) mod[i][j] + l) % k][0] += dp[i - 1][l][0];
          dp[i][((int) mod[i][j] + l) % k][0] %= m;
        }
        if (j > 0)
          dp[i][(int) mod[i][j] % k][0]++;
      }
      ans += ((dp[i][0][1] + dp[i][0][0]) * mul[i]) % m;
      ans %= m;
      // for (int l = 1; l < k; l++) {
      // dp[i][l] += dp[i - 1][l];
      // dp[i][l] %= m;
      // }
      // dp[i][0]++;
    }

    System.out.println(ans);
    // BigInteger mb = new BigInteger(String.valueOf(m));
    //
    // String ns = "";
    //
    // long ans = 0;
    // for(int i = 1; i <= n; i++)
    // {
    // for(int j = 0; j < i; j++)
    // {
    // ns += "9";
    // }
    //
    // BigInteger nb = new BigInteger(ns);
    //
    // BigInteger nod = nb.divide(new BigInteger(String.valueOf(k)));
    //
    // ans += ((((9L * pow(10, n - i - 1, m)) % m) * nod.mod(mb).intValue()) % m);
    // }

    // System.out.println(ans);
    // end here
  }

  long help() {
    int ans = 0;
    for (int i = 10000; i <= 99999; i++) {
      if (isv(i))
        ans++;
    }

    return ans;
  }

  boolean isv(int num) {
    String nums = String.valueOf(num);

    for (int i = 0; i < nums.length(); i++) {
      String sub = nums.substring(i);

      Integer subn = Integer.valueOf(sub);

      if (subn % 3 == 0 && subn != 0) {
        return true;
      }
    }

    return false;
  }

  private long pow(int i, int j, int m) {

    if (j == 0)
      return 1;
    long ans = pow(i, j / 2, m);

    if (j % 2 == 1) {
      return (((ans * j) % m) * ans) % m;
    } else {
      return (ans * ans) % m;
    }
  }

  public static void main(String[] args) throws FileNotFoundException {
    (new _507D()).solve();
  }

  class InputHelper {
    StringTokenizer tokenizer = null;
    private BufferedReader bufferedReader;

    public InputHelper(InputStream inputStream) {
      InputStreamReader inputStreamReader = new InputStreamReader(inputStream);
      bufferedReader = new BufferedReader(inputStreamReader, 16384);
    }

    public String read() {
      while (tokenizer == null || !tokenizer.hasMoreTokens()) {
        try {
          String line = bufferedReader.readLine();
          if (line == null) {
            return null;
          }
          tokenizer = new StringTokenizer(line);
        } catch (IOException e) {
          e.printStackTrace();
        }
      }

      return tokenizer.nextToken();
    }

    public Integer readInteger() {
      return Integer.parseInt(read());
    }

    public Long readLong() {
      return Long.parseLong(read());
    }
  }
}


import math
nums=eval(input())
list=input().split()
max1=0
for i in list:
    if max1<list.count(i):
        max1=list.count(i)
if max1>math.ceil((len(list)/2)):
    print("NO")
else :print("YES")

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

#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  map<int, int> m;
  int mmax = 0;
  for (int i = 0; i < n; i++) {
    int a;
    cin >> a;
    m[a]++;
    if (m[a] > mmax) mmax = m[a];
  }
  if (mmax <= (n + 1) / 2)
    cout << "YES";
  else
    cout << "NO";
  return 0;
}


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

public class Main implements Runnable {
        class Point implements Comparable<Point>{
            int x, y;
            Point(int x, int y){
                this.x = x;
                this.y = y;
            }
            @Override
            public int compareTo(Point b){
                if(x != b.x) return x - b.x;
                else return y - b.y;
            }
        }
	public void solve() throws IOException {
		int N = nextInt();
                int[] a = new int[N];
                int[] b = new int[N];
                Point[] c = new Point[2 * N];
                for(int i = 0; i < N; i++){
                    int v = nextInt();
                    a[i] = v;
                    c[i] = new Point(v, i+1);
                }

                for(int i = 0; i < N; i++){
                    int v = nextInt();
                    b[i] = v;
                    c[N+i] = new Point(v, i + 1);
                }

                int MOD = nextInt();

                Arrays.sort(c);

                long answer = 1;
                int i = 0;
                while(i < c.length){
                    int j = i;
                    while(j < c.length && c[i].x == c[j].x) j++;
                    int two = 0;
                    for(int k = i; k + 1 < j; k++) if(c[k].y == c[k+1].y) two++;
                    long now = fact(j - i, two, MOD);
                    answer = (answer * now) % MOD;
                    i = j;
                }

                out.println(answer);
	}

	private long fact(int N, int two, int MOD){
            long result = 1;
            two = -two; //these are actually divided by 2 in the operation hence we will take them out as we do fact for the numerator

            for(int i = 1; i <= N; i++){
                int x = i;
                while(x % 2 == 0){
                    x = x/ 2;
                    two++;
                }
                result = (result * x) % MOD; //NOTE: x is multiplied after taking all its pow of 2 OUT
            }

            //in case if we have take more than needed twos out, put them back in
            for(int i = 0; i < two; i++) result = (result * 2) % MOD;
            return result;
        }

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

        public void debug(Object... arr){
            System.out.println(Arrays.deepToString(arr));
        }

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

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

	public void run() {
		try {
			in = new BufferedReader(new InputStreamReader(System.in));
                        out = new PrintWriter(System.out);
			tok = null;
			solve();
			in.close();
                        out.close();
		} catch (IOException e) {
			System.exit(0);
		}
	}

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

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

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

	public double nextDouble() throws IOException {
		return Double.parseDouble(nextToken());
	}
        PrintWriter out;
	BufferedReader in;
	StringTokenizer tok;
}

#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:16777216")
using namespace std;
const int maxn = 200005;
const int mod = 1000000007;
void task() {
  int n;
  cin >> n;
  std::vector<long long> a(n), b(n);
  std::map<long long, long long> cnt, same;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    cnt[a[i]]++;
  }
  for (int i = 0; i < n; i++) {
    cin >> b[i];
    cnt[b[i]]++;
    if (a[i] == b[i]) same[a[i]]++;
  }
  long long m;
  cin >> m;
  long long ans = 1;
  for (auto x : cnt) {
    long long now = 1;
    long long tot = same[x.first];
    long long N = x.second;
    for (long long i = 1; i <= N; i++) {
      long long p = i;
      while (p % 2 == 0 and tot > 0) {
        p /= 2;
        tot--;
      }
      now *= p;
      now %= m;
    }
    ans *= now;
    ans %= m;
  }
  cout << ans << "\n";
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int T = 1;
  for (int __ = 1; __ <= T; __++) {
    task();
  }
  return 0;
}


from math import hypot
y1, y2, yw, xb, yb, r = map(int, input().split())
yw -= r
y1, y2 = yw * 2 - y2, yw * 2 - y1

def xww(y):
	return (y - yw) * xb / (y - yb)

def dd(y):
	xw = xww(y)
	return (y - y1) / hypot(1, (yw - y) / xw)

def binary_search():
    a, b = y1 + r, 1e10
    for i in range(200):
    	m = (a + b) / 2
    	if dd(m) < r:
    		a = m
    	else:
    		b= m
    return (a + b) / 2

m = binary_search()
if m + r > y2:
	print("-1")
else:
	m = (m + y2 - r) / 2
	print(xww(m))

#include <bits/stdc++.h>
using namespace std;
double cross(complex<double> a, complex<double> b) {
  return a.real() * b.imag() - a.imag() * b.real();
}
double distanceLnPt(complex<double> a, complex<double> b, complex<double> c) {
  return abs(cross(c - a, b - a)) / abs(b - a);
}
complex<double> intersectionLn(complex<double> a1, complex<double> a2,
                               complex<double> b1, complex<double> b2) {
  complex<double> a = a2 - a1;
  complex<double> b = b2 - b1;
  return a1 + a * cross(b, b1 - a1) / cross(b, a);
}
int main() {
  int y1, y2, yw, xb, yb, r;
  cin >> y1 >> y2 >> yw >> xb >> yb >> r;
  yw -= r;
  complex<double> a(xb, yb);
  complex<double> b(0, 2 * yw - (y1 + r));
  complex<double> c(0, 2 * yw - y2);
  double d = distanceLnPt(a, b, c);
  complex<double> pw =
      intersectionLn(a, b, complex<double>(0, yw), complex<double>(1, yw));
  if (d + (1e-8) > r)
    printf("%.18lf", pw.real());
  else
    puts("-1");
  return 0;
}


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

public class P1325D {
    public static void main(String[] args) throws Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String[] input = br.readLine().split(" ");
        long u = Long.parseLong(input[0]);
        long v = Long.parseLong(input[1]);
        if((u%2) != (v%2) || (u > v)) {
            System.out.println(-1);
        } else if(u == v) {
            if(u == 0) {
                System.out.println(0);
            } else {
                System.out.println(1);
                System.out.println(u);
            }
        } else {
            long rem = v;
            long a = 0;
            long b = 0;
            for (int i = 60; i >= 0; i--) {
                long shift = ((long) 1) << i;
                if ((shift & u) > 0) {
                    rem -= shift;
                    a += shift;
                } else if (rem >= (shift << 1)) {
                    rem -= (shift << 1);
                    a += shift;
                    b += shift;
                }
            }
            if (rem == 0) {
                System.out.println(2);
                System.out.println(a + " " + b);
            } else {
                long o = (v - u) >> 1;
                System.out.println(3);
                System.out.println(u + " " + o + " " + o);
            }
        }
    }
}

#include <bits/stdc++.h>
using namespace std;
const double pi = 3.141592653589;
long long int mod = 1000000007;
int main() {
  int t = 1;
  while (t--) {
    long long int u, v, x;
    cin >> u >> v;
    x = (v - u) / 2;
    if (u + v == 0) {
      cout << 0;
    } else if (u == v) {
      cout << 1 << endl;
      cout << v << endl;
    } else if (u > v) {
      cout << -1;
    } else if ((v - u) % 2 == 1) {
      cout << -1;
    } else if (u == 0) {
      cout << 2 << endl;
      cout << v / 2 << " " << v / 2;
    } else if ((u & x) == 0) {
      cout << 2 << endl;
      cout << x << " " << u + x;
    } else {
      cout << 3 << endl;
      cout << (v - u) / 2 << " " << (v - u) / 2 << " " << u;
    }
  }
}