import java.text.ParseException;
import java.util.*;
import java.io.*;
import java.math.BigInteger;

import static java.lang.Math.*;

    public class solver {

    final boolean ONLINE_JUDGE = System.getProperty("ONLINE_JUDGE")!=null;

    BufferedReader in;
    static PrintWriter out;
    StringTokenizer tok = new StringTokenizer("");

    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()){
            try{
                tok = new StringTokenizer(in.readLine());
            }catch (Exception e){
                return null;
            }
        }
        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());
    }

    public static void main(String[] args) throws IOException, ParseException{
        new solver().run();
    }

    long timeBegin, timeEnd;

    void time(){
        timeEnd = System.currentTimeMillis();
        System.err.println("Time = " + (timeEnd - timeBegin));
    }
    int[] iMas(int n) throws IOException{
        int[] a=new int[n];
        for (int i=0;i<n;i++){
            a[i]=readInt();
        }
        return a;
    }
    void oMas(int[] a){
        for (int i=0;i<a.length;i++){
            out.println(a[i]);
        }
    }

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

    class Pair implements Comparable<Pair>{
        int a;
        int b;

        Pair(int a,int b){
            this.a=a;
            this.b=b;
        }

        @Override
        public int compareTo(Pair o) {
            return a-o.a;
        }

    }

    long result(int i,long[] prefix){
        int ik=i+k-1;
        long pref=prefix[ik];
        if (i!=0) pref-=prefix[i-1];
        return pref;
    }

    int min(int i,int j){
        long resulti=result(i,prefix);
        long resultj=result(j,prefix);

        resulti-=(long)(i*2+k)*(result(i,p));
        resultj-=(long)(j*2+k)*(result(j,p));

        if (resulti<=resultj) return i;else return j;
    }

    int k;int n;
    long[] p,prefix;
    int[] l;

    void solve() throws IOException{
        n=readInt();
        Pair[] a=new Pair[n];
        for (int i=0;i<n;i++){
            a[i]=new Pair(readInt(),i+1);
        }

        Arrays.sort(a);

        k=readInt();
        p=new long[n];
        prefix=new long[n];
        l=new int[n];
        for (int i=0;i<n;i++){
            if (i!=0) {
                l[i]=l[i-1]+2;
                prefix[i]=prefix[i-1];
                p[i]=p[i-1];
            }else{
                l[i]=1;
            }
            p[i]+=a[i].a;
            prefix[i]+=(long)l[i]*a[i].a;
        }

        int ans=0;

        for (int i=1;i<=n-k;i++){
            ans=min(ans,i);
        }
        for (int i=ans;i<ans+k;i++){
            out.print(a[i].b+" ");
        }
    }

    public void run() throws IOException, ParseException{

        init();
        long h=System.currentTimeMillis();
        solve();
        System.err.println(System.currentTimeMillis()-h);
        out.close();
    }

}

#include <bits/stdc++.h>
using namespace std;
pair<long long, int> dist[400000];
long long sum[400000];
long long ans[400000];
int main() {
  int n, k;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    long long t;
    cin >> t;
    dist[i] = pair<long long, int>(t, i);
  }
  cin >> k;
  sort(dist + 1, dist + 1 + n);
  for (int i = 1; i <= n; i++) sum[i] = sum[i - 1] + dist[i].first;
  long long t = 0;
  for (int i = 1; i <= k; i++) t = t + (i - 1) * dist[i].first - sum[i - 1];
  long long ans = t;
  int s = 1;
  for (int i = k + 1; i <= n; i++) {
    t = t - 2 * (sum[i - 1] - sum[i - k + 1] + dist[i - k + 1].first) +
        (k - 1) * (dist[i].first + dist[i - k].first);
    if (t < ans) {
      s = i - k + 1;
      ans = t;
    }
  }
  for (int i = 0; i < k; i++) {
    cout << dist[s + i].second << " ";
  }
  return 0;
}


#include <bits/stdc++.h>
using namespace std;
const int maxint = -1u >> 1;
const int maxn = 100 + 10;
int n;
int d[maxn * 2];
int main() {
  while (scanf("%d", &n) == 1) {
    for (int i = 0; i < n; ++i) scanf("%d", &d[i]);
    for (int i = n; i < n + n; ++i) d[i] = d[i - n];
    int s, t;
    scanf("%d%d", &s, &t);
    if (s > t) swap(s, t);
    --s, --t;
    int t1 = 0, t2 = 0;
    for (int i = s; i < t; ++i) t1 += d[i];
    for (int i = t; i < s + n; ++i) t2 += d[i];
    int ans = min(t1, t2);
    printf("%d\n", ans);
  }
  return 0;
}

n = int(input())
a = list(map(int, input().split()))
s, t = sorted(map(int, input().split()))
print(min(sum(a[s-1:t-1]), sum(a[:s-1])+sum(a[t-1:])))


import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;

public class Question181A {
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        int n=sc.nextInt();
        int m=sc.nextInt();
        Character[][] arr=new Character[n][m];
        int count=0;
        List<Integer> listx=new ArrayList<>();
        List<Integer> listy=new ArrayList<>();
        for(int i=0;i<n;i++){
            String temp=sc.next();
            for(int j=0;j<temp.length();j++){
                arr[i][j]=temp.charAt(j);
                if(arr[i][j]=='*'){
                    listx.add(i);//1,1,2
                    listy.add(j); //1,3,1
                    //,11,3
                    //1,3,3
                }
            }
        }
        Collections.sort(listx);
        Collections.sort(listy);
        if(listx.get(0)==listx.get(1))
            System.out.print((listx.get(2)+1)+" ");
        else
            System.out.print((listx.get(0)+1)+" ");
        if(listy.get(0)==listy.get(1))
            System.out.print(listy.get(2)+1);
        else
            System.out.print(listy.get(0)+1);
//        int x=0;
//        for(int i=0;i<arr.length;i++){
//            for(int j=0;j<arr[0].length;j++){
//                if(arr[i][j]=='*'){
//                    count++;
//                }
//            }
//            if(count==1){
//                x=i;
//            }
//            count=0;
//        }
//        //System.out.println(x+1);
//        int y=0;
//        for(int i=0;i<arr[0].length;i++){
//            for(int j=0;j<arr.length;j++){
//                if(arr[j][i]=='*'){
//                    count++;
//                }
//            }
//            if(count==1){
//                y=i;
//            }
//            count=0;
//        }
//        System.out.println((x+1)+" "+(y+1));
//

    }
}


n = int(input())
arr = list(map(int, input().split()))
brr = arr[:]
t = 0
for i in range(n):
    t = arr[i] - 1
    brr[t] = i + 1
print(*brr)

#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, x;
  int a[100] = {};
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> x;
    a[x] = i;
  }
  for (int i = 1; i <= n; i++) {
    cout << a[i] << ' ';
  }
}


#include <bits/stdc++.h>
using namespace std;
namespace Primary {
int a, b;
long long ans = 0;
void main() {
  scanf("%d%d", &a, &b);
  for (int L = 1, R; L <= a + b; L = R + 1) {
    int p = (a + b) / L;
    R = (a + b) / p;
    if (a < p || b < p) continue;
    int l_a = (a - 1) / (p + 1) + 1, l_b = (b - 1) / (p + 1) + 1;
    int r_a = a / p, r_b = b / p;
    if (l_a <= r_a && l_b <= r_b)
      ans += max(0ll, 1ll * (min(R, r_a + r_b) - max(L, l_a + l_b) + 1));
  }
  printf("%I64d", ans);
}
}  // namespace Primary
int main() {
  Primary::main();
  return 0;
}

import math
a,b= map(int,input().split())
n=a+b
ans,l=0,1
while l<=n:
    g= n//l
    if a<g or b<g:
        l= (n//g) +1
        continue
    r= n//g
    a_low = (a+g)//(g+1)
    a_high = a//g
    b_low=(b+g)//(g+1)
    b_high = b//g
    if (a_low <= a_high and b_low <= b_high):
        ans += max(0,min(r,a_high+b_high)- max(l,a_low +b_low)+1)

    l=r+1
print(ans)


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

public class Main {

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

        new Main().go();
    }

    PrintWriter out;
    Reader in;
    BufferedReader br;

    Main() throws IOException {

        try {

            //br = new BufferedReader( new FileReader("input.txt") );
            //in = new Reader("input.txt");
            in = new Reader("input.txt");
            out = new PrintWriter( new BufferedWriter(new FileWriter("output.txt")) );
        }
        catch (Exception e) {

            //br = new BufferedReader( new InputStreamReader( System.in ) );
            in = new Reader();
            out = new PrintWriter( new BufferedWriter(new OutputStreamWriter(System.out)) );
        }
    }

    void go() throws Exception {

        //int t = in.nextInt();
        int t = 1;
        while (t > 0) {
            solve();
            t--;
        }

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

    int inf = 2000000000;
    int mod = 1000000007;
    double eps = 0.000000001;

    int n;
    int m;

    ArrayList<Pair>[] g;

    void solve() throws IOException {

        int k = in.nextInt();
        String s = in.nextLine();
        String t = in.nextLine();

        int[] ans = new int[k];
        int rem = 0;
        for (int i = k - 1; i >= 0; i--) {
            int x = s.charAt(i) - 'a';
            int y = t.charAt(i) - 'a';
            int sum = x + y + rem;
            int mod = sum % 26;
            ans[i] = mod;
            rem = sum / 26;
        }

        for (int i = 0; i < k; i++) {
            int sum = ans[i] + rem * 26;
            ans[i] = sum / 2;
            rem = sum % 2;
        }

        for (int i = 0; i < k; i++)
            out.print((char)(ans[i] + 'a'));

    }

    class Pair implements Comparable<Pair>{

        int a;
        int b;

        Pair(int a, int b) {

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

        public int compareTo(Pair p) {
            if (a != p.a)
                return Integer.compare(a, p.a);
            else
                return Integer.compare(b, p.b);
        }
    }

    class Item {

        int a;
        int b;
        int c;

        Item(int a, int b, int c) {
            this.a = a;
            this.b = b;
            this.c = c;
        }

    }

    class Reader {

        BufferedReader  br;
        StringTokenizer tok;

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

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

        String next() throws IOException {

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

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

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

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

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

    }

    static class InputReader
    {
        final private int BUFFER_SIZE = 1 << 16;
        private DataInputStream din;
        private byte[] buffer;
        private int bufferPointer, bytesRead;

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

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

        public String readLine() throws IOException
        {
            byte[] buf = new byte[64]; // line length
            int cnt = 0, c;
            while ((c = read()) != -1)
            {
                if (c == '\n')
                    break;
                buf[cnt++] = (byte) c;
            }
            return new String(buf, 0, cnt);
        }

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

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

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

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

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

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

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

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

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

        public void close() throws IOException
        {
            if (din == null)
                return;
            din.close();
        }
    }

}

u bc aak ao ay aaak ak as ah aaw m aam k aw nbqykcppkvzu aq aaah aaf s q ac aau qoztvz w alvuw y am aao g c aaq aaa c af aay zzzzzzzzzy i aaaf o q e a aaaa aa aah aas au aaac aac qquio

#include <bits/stdc++.h>
using namespace std;
const int MAXN = (int)2e5 + 5;
long long k, c[MAXN];
string s, t;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  while (cin >> k >> s >> t) {
    for (long long i = 0; i < k; ++i) c[i] = s[i] - 'a' + t[i] - 'a';
    for (long long i = k - 1; i > 0; --i)
      if (c[i] >= 26) c[i] -= 26, c[i - 1]++;
    for (long long i = 0; i < k; ++i)
      c[i + 1] += c[i] & 1 ? 26 : 0, cout << char(c[i] / 2 + 'a');
  }
}


#include <bits/stdc++.h>
using namespace std;
int sum[200006];
int main() {
  int ans = 0, n, x;
  cin >> n;
  sum[0] = 0;
  for (int i = 1; i <= n; i++) {
    cin >> x;
    if (i % 2 == 1)
      sum[i] = sum[i - 1] + x;
    else
      sum[i] = sum[i - 1] - x;
  }
  for (int i = 1; i <= n; i++) {
    if (-(sum[n] - sum[i]) + sum[i - 1] == 0) ans++;
  }
  cout << ans << "\n";
  return 0;
}

import java.util.*;
public class adi
{

	public static void main(String[] args) {
		long l=0;
		Scanner s=new Scanner(System.in);
		int n;
		n=s.nextInt();
		int a[]=new int[n];
		int sume=0,sumo=0;
		for(int i=0;i<n;i++)
		{
			a[i]=s.nextInt();
			}
      for(int i=0;i<n;i++)
      {
			if(i%2==0)
			{
				sume+=a[i];
			}
			else
			{
				sumo+=a[i];
			}

		}
		int se=0,so=0,c=0,x,y;

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

			if(i%2==0)
			{
				x=(sumo-so)+se;
				y=(sume-a[i]-se)+so;

				if(x==y)
					c++;

			}
			else
			{
				x=(sume-se)+so;
				y=(sumo-a[i]-so)+se;

				if(x==y)
					c++;
			}
			if(i%2==0)
			{
				se=se+a[i];
			}
			else
			{
				so=so+a[i];
			}

		}
		System.out.println(c);

	}
}


n = str(input())
alist = input().split(' ')

for i in alist:
    if i[0] == n[0]:
        print('YES')
        exit(0)
    elif i[-1] == n[-1]:
        print('YES')
        exit(0)
print('NO')

import java.util.Scanner;
public class CardGame {

    public static void main(String[] args) {
        Scanner s = new Scanner (System.in);
       boolean fl = false;
        String tc = s.nextLine();
        String [] hc = new String [5];
        for (int i=0;i<hc.length;i++)
            hc[i]=s.next();

        for (int i=0;i<5;i++)
        {
            if (tc.charAt(0)==hc[i].charAt(0))
            {
                fl=true;
                break;
            }
            else
                if (tc.charAt(1)==hc[i].charAt(1))
                {
                    fl = true;
                    break;
                }
        }
        if (fl)
            System.out.println("YES");
        else
            System.out.println("NO");

    }
}


#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int n, i;
  cin >> n;
  string s, temp;
  cin >> s;
  int flag = 0;
  for (i = 0; i < n - 1; i++) {
    if (s[i] > s[i + 1] && flag == 0) {
      flag = 1;
      continue;
    }
    temp += s[i];
  }
  temp += s[i];
  if (temp.size() == s.size()) temp.pop_back();
  cout << temp;
}

ab c aacc aa abca aaa llthisiscoolfreehackforya bbbb

import sys, threading

sys.setrecursionlimit(10 ** 6)

scan = lambda: map(int, input().split())
n = int(input())
string = input()
ans = string
for i in range(n-1):
    if string[i] > string[i+1]:
        print(string[0:i]+string[i+1:n])
        exit(0)
print(string[0:n-1])


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

public class Main {

	void solve (FastScanner in, PrintWriter out) {

		int start = in.nextInt(), goal = in.nextInt(), elev = in.nextInt();
		int stairTime = in.nextInt(), elevTime = in.nextInt(), doorTime = in.nextInt();

		int stair = Math.abs(start-goal) * stairTime;
		int elevator = Math.abs(start-elev)*elevTime + Math.abs(start-goal)*elevTime + 3*doorTime;

//		print(elevator, stair);

		out.println(elevator<=stair? "YES" : "NO");

	}

	public static void print (Object... ar) {
		System.out.println(Arrays.deepToString(ar));
	}

	public static void main(String[] args) {
		FastScanner in = new FastScanner(System.in);
		PrintWriter out = new PrintWriter(System.out);
		Main main = new Main();
		main.solve(in, out);
		in.close();
		out.close();
	}

	static class FastScanner {

		private InputStream in;
		private byte[] buffer = new byte[1024];
		private  int length = 0, p = 0;

		public FastScanner (InputStream stream) {
			in = stream;
		}
		public boolean hasNextByte () {
			if (p < length) return true;
			else {
				p = 0;
				try {length = in.read(buffer);}
				catch (Exception e) {e.printStackTrace();}
				if (length <= 0) return false;
			}
			return true;
		}
		public int readByte () {
			if (hasNextByte() == true) return buffer[p++];
			return -1;
		}
		public boolean isPrintable (int n) {return 33<=n&&n<=126;}
		public void skip () {
			while (hasNextByte() && !isPrintable(buffer[p])) p++;
		}
		public boolean hasNext () {skip(); return hasNextByte();}
		public String next () {
			if (!hasNext()) throw new NoSuchElementException();
			StringBuilder sb = new StringBuilder();
			int t = readByte();
			while (isPrintable(t)) {
				sb.appendCodePoint(t);
				t = readByte();
			}
			return sb.toString();
		}
		public String[] nextArray (int n) {
			String[] ar = new String[n];
			for (int i=0; i<n; i++) ar[i] = next();
			return ar;
		}
		public int nextInt () {return Math.toIntExact(nextLong());}
		public int[] nextIntArray (int n) {
			int[] ar = new int[n];
			for (int i=0; i<n; i++) ar[i] = nextInt();
			return ar;
		}
		public long nextLong () {
			if (!hasNext()) throw new NoSuchElementException();
			boolean minus = false;
			int temp = readByte();
			if (temp == '-') {
				minus = true;
				temp = readByte();
			}
			if (temp<'0' || '9'<temp) throw new NumberFormatException();
			long n = 0;
			while (isPrintable(temp)) {
				if ('0'<=temp && temp<='9') {
					n *= 10;
					n += temp - '0';
				}
				else throw new NumberFormatException();
				temp = readByte();
			}
			return minus? -n : n;
		}
		public double nextDouble () {
			return Double.parseDouble(next());
		}
		public void close () {
			try {in.close();}
			catch(Exception e){}
		}
	}

}

NO YES NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO YES NO NO NO YES 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 YES

x,y,z,tuno,tdos,ttres=map(int,input().split())

var1=(x-y)

stair=abs(var1)*tuno

var2=(x-z)

eleva=(3*ttres)+((abs(var2))*tdos)+((abs(var1))*tdos)

if stair >= eleva:
      print("YES")
else:
      print("NO")


#include <bits/stdc++.h>
using namespace std;
int main() {
  int ans, w, h, k;
  cin >> w >> h >> k;
  ans = 0;
  for (int i = 0; i < 4 * k; i += 4) {
    ans += 2 * (h - i) + 2 * (w - i) - 4;
  }
  cout << ans << endl;
  return 0;
}

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

public class A {
    static MyScanner sc;
    static PrintWriter pw;

    public static void main(String[] args) throws Throwable {
        sc = new MyScanner();
        pw = new PrintWriter(System.out);

        int n=sc.nextInt();
        int m=sc.nextInt();
        int k=sc.nextInt();
        int ans=0;
        while (k-->0){
            ans+=2*(n+m-2);
            n-=4;
            m-=4;
        }
        pw.println(ans);

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

    static class MyScanner {
        BufferedReader br;
        StringTokenizer st;

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

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

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

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

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

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


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

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

    static class TaskE_Y11 {
        long[] ar = new long[]{
                3L, 6L, 9L, 30L, 51L, 85L, 178L, 380L, 627L, 1396L, 2978L, 5186L, 12915L,
                28192L, 37561L, 115961L, 193662L, 411988L, 759460L, 2051307L, 3785904L,
                5543056L, 16669593L, 25277043L, 54117552L, 106652005L, 171127363L,
                301978141L, 1010305514L, 1490056778L, 3334312633L, 5053127458L, 8719117218L,
                22822628369L, 49600975938L, 114647216755L, 237588158116L, 370580129804L,
                790237091196L, 1995203857444L, 3756928331741L, 5124539310419L, 17410992492778L,
                28647118439686L, 44748220337535L, 113490947496104L, 242887172167920L, 532922278133118L,
                780483731207866L};

        public void solve(int testNumber, InputReader in, PrintWriter out) {
//        for (int i = 2; i <= 50; ++i) {
//            out.print(solve(i) + ",");
//            System.err.println(i + "...");
//        }
            int n = in.nextInt();
            for (int i = 0; i < n; ++i) {
                if (BitUtils.checkBit(ar[n - 2], i)) {
                    out.print(1);
                } else {
                    out.print(0);
                }
                out.print(" ");
            }
            out.println();
            for (int i = 0; i < n; ++i) {
                if (BitUtils.checkBit(1L, i)) {
                    out.print(1);
                } else {
                    out.print(0);
                }
                out.print(" ");
            }
            out.println();
        }

    }

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

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

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

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

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

    }

    static class BitUtils {
        public static boolean checkBit(long mask, int bit) {
            return (mask & (1L << bit)) > 0;
        }

    }
}


def rek(k):
    if k == 1:
        return ('a', 'a')
    elif k == 2:
        return ('aa', 'a')

    s, p = rek((k - 1) // 2)
    x = chr(ord(p[-1]) + 1)

    return (p + x * (2 - k % 2) + s[len(p):] + 2 * x, p + x)

s, p = rek(int(input()))
print(s, p)

#include <bits/stdc++.h>
using namespace std;
struct Node {
  Node() {}
  Node(string s, string p) : s(s), p(p) {}
  string s, p;
} a;
int i, j, k, n, m;
char c;
inline Node Solve(int n) {
  Node Tmp;
  if (n == 1) {
    c = 'a';
    return Node("a", "a");
  }
  if (n == 2) {
    c = 'b';
    return Node("abb", "ab");
  }
  if (n % 2 == 0) {
    Tmp = Solve(n / 2 - 1);
    c++;
    Tmp.s.insert((int)Tmp.p.size(), string(2, c));
    Tmp.s += string(2, c);
    Tmp.p += string(1, c);
    return Tmp;
  }
  Tmp = Solve(n / 2);
  c++;
  Tmp.s.insert((int)Tmp.p.size(), string(1, c));
  Tmp.s += string(2, c);
  Tmp.p += string(1, c);
  return Tmp;
}
int main() {
  scanf("%d", &n);
  a = Solve(n);
  for (i = 0; i < a.s.size(); i++) putchar(a.s[i]);
  putchar(' ');
  for (i = 0; i < a.p.size(); i++) putchar(a.p[i]);
  puts("");
  return 0;
}


n = int(input())
L, R = 0, 0
D = []
for i in range(n):
    l, r = map(int, input().split())
    L += l
    R += r
    D.append((l, r))

ans = abs(L - R)
num = 0
for i in range(n):
    l, r = D[i]
    L1 = L - l + r
    R1 = R - r + l
    if ans < abs(L1 - R1):
        ans = abs(L1 - R1)
        num = i + 1

print(num)

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

public class CodeForces {
    private final BufferedReader reader;
    private final PrintWriter writer;
    private StringTokenizer tokenizer;

    private void solve() {
        int n = nextInt();
        int[] l = new int[n];
        int[] r = new int[n];
        int lSum = 0;
        int rSum = 0;
        for (int i = 0; i < n; i++) {
            lSum += l[i] = nextInt();
            rSum += r[i] = nextInt();
        }
        int res = -1;
        int maxD = Math.abs(lSum - rSum);
        for (int i = 0; i < n; i++) {
            if (Math.abs(lSum - l[i] + r[i] - (rSum - r[i] + l[i])) > maxD) {
                maxD = Math.abs(lSum - l[i] + r[i] - (rSum - r[i] + l[i]));
                res = i;
            }
        }
        writer.print(res == -1 ? 0 : res + 1);
    }

    public static void main(String[] args) {
        new CodeForces(System.in, System.out);
    }

    private CodeForces(InputStream inputStream, OutputStream outputStream) {
        this.reader = new BufferedReader(new InputStreamReader(inputStream));
        this.writer = new PrintWriter(outputStream);
        solve();
        writer.close();
    }

    private String next() {
        while (tokenizer == null || !tokenizer.hasMoreTokens()) {
            tokenizer = new StringTokenizer(readLine());
        }
        return tokenizer.nextToken();
    }

    private String readLine() {
        String line;
        try {
            line = reader.readLine();
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
        return line;
    }

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

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

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

    public boolean hasNext() {
        while (tokenizer == null || !tokenizer.hasMoreTokens()) {
            String line = readLine();
            if (line == null) {
                return false;
            }
            tokenizer = new StringTokenizer(line);
        }
        return true;
    }

    public BigInteger nextBigInteger() {
        return new BigInteger(next());
    }

    public static int upperBinarySearch(int[] array, int start, int finish, int key) {
        int low = 0;
        int high = array.length - 1;
        if (high < 0) return -1;
        while (low < high) {
            int mid = (low + high + 1) >>> 1;
            if (array[mid] <= key) low = mid;
            else high = mid - 1;
        }
        if (array[low] != key) {
            if (array[low] < key) low++;
            low = -(low + 1);
        }
        return low;
    }
}


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

public class C {

    private static final boolean TEST_CASES = false;

    private static class Solver {
        void solve(int testCaseNo) {
		int x = IO.nextInt();
		int y = IO.nextInt();

		if ( y < x ) {
			int t = x;
			x = y;
			y = t;
		}

		int[] a = new int[3];
		a[0] = a[1] = a[2] = x;
		int i = 0, res = 0;
		while (true) {

			if (isDone(a, y)) break;
			if (a[i] == y) {
				i = (i + 1)%3;
				continue;
			}
			checkNget(a, i, y);
			res++;
			i = (i + 1)%3;
		}

		IO.writer.println(res);

	}

	boolean isDone(int[] a, int y) {
		if (a[0] != y) return false;
		if (a[1] != y) return false;
		if (a[2] != y) return false;

		return true;
	}

	void checkNget(int[] a, int i, int y) {

		int j = (i+1)%3;
		int k = (i+2)%3;

		if (isValid(y, a[j], a[k])) {
			a[i] = y;
			return;
		}

		if (y > a[i]) {
			a[i] = a[j] + a[k] - 1;
		} else {
			if (a[j] <= a[k]) {
				a[i] = a[k] - a[j] + 1;
			} else
				a[i] = a[j] - a[k] + 1;
		}
	}

	boolean isValid(int a, int b, int c) {
		if (a >= (b + c)) return false;
		if (b >= (a + c)) return false;
		if (c >= (b + a)) return false;
		return true;
	}

    }

    private static class IO {

        private static final BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        static final PrintWriter writer = new PrintWriter(System.out);

        private static StringTokenizer tokenizer = null;

        static String nextToken() {
            checkTokenizer();
            return tokenizer.nextToken();
        }

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

        static void close() {
            writer.flush();
        }

        private static boolean isTokenizerEmpty() {
            return tokenizer == null || !tokenizer.hasMoreTokens();
        }

        private static void checkTokenizer() {
            while (isTokenizerEmpty()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
        }
    }

    private static void go() {
        int testCases = TEST_CASES ? IO.nextInt() : 1;

        Solver solver = new Solver();
        for (int testCase = 0; testCase < testCases; testCase++) {
            solver.solve(testCase);
        }
    }

    public static void main(String[] args) {
        try {
            go();
        } finally {
            IO.close();
        }
    }
}

x, y = map(int, input().split())

a, b, c = y, y, y
cnt = 0
while True:

    if a >= x and b >= x and c >= x:
        break

    cnt += 1
    if cnt % 3 == 0:
        a = b+c - 1
    elif cnt % 3 == 1:
        b = c + a - 1
    elif cnt % 3 == 2:
        c = b+a - 1

print(cnt)


import java.io.*;
import java.lang.reflect.Array;
import java.math.*;
import java.util.*;

public class icpc
{
    static String s = "";
    static HashSet<String> h = new HashSet<>();
    static HashSet<Integer> h1 = new HashSet<>();
    public static void main(String[] args) throws IOException
    {
//        Reader in = new Reader();
        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        String s = in.readLine();
        int n = s.length();
        boolean[][] DP = new boolean[2][n];
        DP[0][n - 2] = true;
        DP[1][n - 3] = true;
        for (int i = n - 4;i>=5;i--)
        {
            DP[0][i] = DP[1][i + 2] || (DP[0][i + 2] && !s.substring(i, i + 2).equals(s.substring(i + 2, i + 4)));
            DP[1][i] = DP[0][i + 3] || (DP[1][i + 3] && !s.substring(i, i + 3).equals(s.substring(i + 3, i + 6)));
        }
        TreeSet<String> t = new TreeSet<>();
        for (int i=5;i<n;i++)
        {
            if (DP[0][i]) t.add(s.substring(i, i + 2));
            if (DP[1][i]) t.add(s.substring(i, i + 3));
        }
        ArrayList<String> A = new ArrayList<>(t);
        System.out.println(A.size());
        for (int i=0;i<A.size();i++)
            System.out.println(A.get(i));
    }

}
class NumberTheory
{
    public boolean isPrime(long n)
    {
        if(n < 2)
            return false;
        for(long x = 2;x * x <= n;x++)
        {
            if(n % x == 0)
                return false;
        }
        return true;
    }
    public ArrayList<Long> primeFactorisation(long n)
    {
        ArrayList<Long> f = new ArrayList<>();
        for(long x=2;x * x <= n;x++)
        {
            while(n % x == 0)
            {
                f.add(x);
                n /= x;
            }
        }
        if(n > 1)
            f.add(n);
        return f;
    }
    public int[] sieveOfEratosthenes(int n)
    {
        int[] sieve = new int[n + 1];
        for(int x=2;x<=n;x++)
        {
            if(sieve[x] != 0)
                continue;
            sieve[x] = x;
            for(int u=2*x;u<=n;u+=x)
                if(sieve[u] == 0)
                    sieve[u] = x;
        }
        return sieve;
    }
    public long gcd(long a, long b)
    {
        if(b == 0)
            return a;
        return gcd(b, a % b);
    }
    public long phi(long n)
    {
        double result = n;

        for(long p=2;p*p<=n;p++)
        {
            if(n % p == 0)
            {
                while (n % p == 0)
                    n /= p;
                result *= (1.0 - (1.0 / (double)p));
            }
        }
        if(n > 1)
            result *= (1.0 - (1.0 / (double)n));
        return (long)result;
    }
    public Name extendedEuclid(long a, long b)
    {
        if(b == 0)
            return new Name(a, 1, 0);
        Name n1 = extendedEuclid(b, a % b);
        Name n2 = new Name(n1.d, n1.y, n1.x - (long)Math.floor((double)a / b) * n1.y);
        return n2;
    }
    public long modularExponentiation(long a, long b, long n)
    {
        long d = 1L;
        String bString = Long.toBinaryString(b);
        for(int i=0;i<bString.length();i++)
        {
            d = (d * d) % n;
            if(bString.charAt(i) == '1')
                d = (d * a) % n;
        }
        return d;
    }
}
class Name
{
    long d;
    long x;
    long y;

    public Name(long d, long x, long y)
    {
        this.d = d;
        this.x = x;
        this.y = y;
    }
}
class SuffixArray
{
    int ALPHABET_SZ = 256, N;
    int[] T, lcp, sa, sa2, rank, tmp, c;

    public SuffixArray(String str)
    {
        this(toIntArray(str));
    }

    private static int[] toIntArray(String s)
    {
        int[] text = new int[s.length()];
        for (int i = 0; i < s.length(); i++) text[i] = s.charAt(i);
        return text;
    }

    public SuffixArray(int[] text)
    {
        T = text;
        N = text.length;
        sa = new int[N];
        sa2 = new int[N];
        rank = new int[N];
        c = new int[Math.max(ALPHABET_SZ, N)];
        construct();
        kasai();
    }

    private void construct()
    {
        int i, p, r;
        for (i = 0; i < N; ++i) c[rank[i] = T[i]]++;
        for (i = 1; i < ALPHABET_SZ; ++i) c[i] += c[i - 1];
        for (i = N - 1; i >= 0; --i) sa[--c[T[i]]] = i;
        for (p = 1; p < N; p <<= 1)
        {
            for (r = 0, i = N - p; i < N; ++i) sa2[r++] = i;
            for (i = 0; i < N; ++i) if (sa[i] >= p) sa2[r++] = sa[i] - p;
            Arrays.fill(c, 0, ALPHABET_SZ, 0);
            for (i = 0; i < N; ++i) c[rank[i]]++;
            for (i = 1; i < ALPHABET_SZ; ++i) c[i] += c[i - 1];
            for (i = N - 1; i >= 0; --i) sa[--c[rank[sa2[i]]]] = sa2[i];
            for (sa2[sa[0]] = r = 0, i = 1; i < N; ++i)
            {
                if (!(rank[sa[i - 1]] == rank[sa[i]]
                        && sa[i - 1] + p < N
                        && sa[i] + p < N
                        && rank[sa[i - 1] + p] == rank[sa[i] + p])) r++;
                sa2[sa[i]] = r;
            }
            tmp = rank;
            rank = sa2;
            sa2 = tmp;
            if (r == N - 1) break;
            ALPHABET_SZ = r + 1;
        }
    }

    private void kasai()
    {
        lcp = new int[N];
        int[] inv = new int[N];
        for (int i = 0; i < N; i++) inv[sa[i]] = i;
        for (int i = 0, len = 0; i < N; i++)
        {
            if (inv[i] > 0)
            {
                int k = sa[inv[i] - 1];
                while ((i + len < N) && (k + len < N) && T[i + len] == T[k + len]) len++;
                lcp[inv[i] - 1] = len;
                if (len > 0) len--;
            }
        }
    }
}
class ZAlgorithm
{
    public int[] calculateZ(char input[])
    {
        int Z[] = new int[input.length];
        int left = 0;
        int right = 0;
        for(int k = 1; k < input.length; k++) {
            if(k > right) {
                left = right = k;
                while(right < input.length && input[right] == input[right - left]) {
                    right++;
                }
                Z[k] = right - left;
                right--;
            } else {
                //we are operating inside box
                int k1 = k - left;
                //if value does not stretches till right bound then just copy it.
                if(Z[k1] < right - k + 1) {
                    Z[k] = Z[k1];
                } else { //otherwise try to see if there are more matches.
                    left = k;
                    while(right < input.length && input[right] == input[right - left]) {
                        right++;
                    }
                    Z[k] = right - left;
                    right--;
                }
            }
        }
        return Z;
    }
    public ArrayList<Integer> matchPattern(char text[], char pattern[])
    {
        char newString[] = new char[text.length + pattern.length + 1];
        int i = 0;
        for(char ch : pattern) {
            newString[i] = ch;
            i++;
        }
        newString[i] = '$';
        i++;
        for(char ch : text) {
            newString[i] = ch;
            i++;
        }
        ArrayList<Integer> result = new ArrayList<>();
        int Z[] = calculateZ(newString);

        for(i = 0; i < Z.length ; i++) {
            if(Z[i] == pattern.length) {
                result.add(i - pattern.length - 1);
            }
        }
        return result;
    }
}
class KMPAlgorithm
{
    public int[] computeTemporalArray(char[] pattern)
    {
        int[] lps = new int[pattern.length];

        int index = 0;
        for(int i=1;i<pattern.length;)
        {
            if(pattern[i] == pattern[index])
            {
                lps[i] = index + 1;
                index++;
                i++;
            }
            else
            {
                if(index != 0)
                {
                    index = lps[index - 1];
                }
                else
                {
                    lps[i] = 0;
                    i++;
                }
            }
        }
        return lps;
    }

    public ArrayList<Integer> KMPMatcher(char[] text, char[] pattern)
    {
        int[] lps = computeTemporalArray(pattern);

        int j = 0;
        int i = 0;
        int n = text.length;
        int m = pattern.length;
        ArrayList<Integer> indices = new ArrayList<>();
        while(i < n)
        {
            if(pattern[j] == text[i])
            {
                i++;
                j++;
            }
            if(j == m)
            {
                indices.add(i - j);
                j = lps[j - 1];
            }
            else if(i < n && pattern[j] != text[i])
            {
                if(j != 0)
                    j = lps[j - 1];
                else
                    i = i + 1;
            }
        }
        return indices;
    }
}
class Hashing
{
    public long[] computePowers(long p, int n, long m)
    {
        long[] powers = new long[n];
        powers[0] = 1;
        for(int i=1;i<n;i++)
        {
            powers[i] = (powers[i - 1] * p) % m;
        }
        return powers;
    }
    public long computeHash(String s)
    {
        long p = 31;
        long m = 1_000_000_009;
        long hashValue = 0L;
        long[] powers = computePowers(p, s.length(), m);
        for(int i=0;i<s.length();i++)
        {
            char ch = s.charAt(i);
            hashValue = (hashValue + (ch - 'a' + 1) * powers[i]) % m;
        }
        return hashValue;
    }
}
class BasicFunctions
{
    public long min(long[] A)
    {
        long min = Long.MAX_VALUE;
        for(int i=0;i<A.length;i++)
        {
            min = Math.min(min, A[i]);
        }
        return min;
    }
    public long max(long[] A)
    {
        long max = Long.MAX_VALUE;
        for(int i=0;i<A.length;i++)
        {
            max = Math.max(max, A[i]);
        }
        return max;
    }
}
class Matrix
{
    long a;
    long b;
    long c;
    long d;

    public Matrix(long a, long b, long c, long d)
    {
        this.a = a;
        this.b = b;
        this.c = c;
        this.d = d;
    }
}
class MergeSortInt
{
    // Merges two subarrays of arr[].
    // First subarray is arr[l..m]
    // Second subarray is arr[m+1..r]
    void merge(int arr[], int l, int m, int r) {
        // Find sizes of two subarrays to be merged
        int n1 = m - l + 1;
        int n2 = r - m;

        /* Create temp arrays */
        int L[] = new int[n1];
        int R[] = new int[n2];

        /*Copy data to temp arrays*/
        for (int i = 0; i < n1; ++i)
            L[i] = arr[l + i];
        for (int j = 0; j < n2; ++j)
            R[j] = arr[m + 1 + j];

        /* Merge the temp arrays */

        // Initial indexes of first and second subarrays
        int i = 0, j = 0;

        // Initial index of merged subarry array
        int k = l;
        while (i < n1 && j < n2) {
            if (L[i] <= R[j]) {
                arr[k] = L[i];
                i++;
            } else {
                arr[k] = R[j];
                j++;
            }
            k++;
        }

        /* Copy remaining elements of L[] if any */
        while (i < n1) {
            arr[k] = L[i];
            i++;
            k++;
        }

        /* Copy remaining elements of R[] if any */
        while (j < n2) {
            arr[k] = R[j];
            j++;
            k++;
        }
    }

    // Main function that sorts arr[l..r] using
    // merge()
    void sort(int arr[], int l, int r) {
        if (l < r) {
            // Find the middle point
            int m = (l + r) / 2;

            // Sort first and second halves
            sort(arr, l, m);
            sort(arr, m + 1, r);

            // Merge the sorted halves
            merge(arr, l, m, r);
        }
    }

}
class MergeSortLong
{
    // Merges two subarrays of arr[].
    // First subarray is arr[l..m]
    // Second subarray is arr[m+1..r]
    void merge(long arr[], int l, int m, int r) {
        // Find sizes of two subarrays to be merged
        int n1 = m - l + 1;
        int n2 = r - m;

        /* Create temp arrays */
        long L[] = new long[n1];
        long R[] = new long[n2];

        /*Copy data to temp arrays*/
        for (int i = 0; i < n1; ++i)
            L[i] = arr[l + i];
        for (int j = 0; j < n2; ++j)
            R[j] = arr[m + 1 + j];

        /* Merge the temp arrays */

        // Initial indexes of first and second subarrays
        int i = 0, j = 0;

        // Initial index of merged subarry array
        int k = l;
        while (i < n1 && j < n2) {
            if (L[i] <= R[j]) {
                arr[k] = L[i];
                i++;
            } else {
                arr[k] = R[j];
                j++;
            }
            k++;
        }

        /* Copy remaining elements of L[] if any */
        while (i < n1) {
            arr[k] = L[i];
            i++;
            k++;
        }

        /* Copy remaining elements of R[] if any */
        while (j < n2) {
            arr[k] = R[j];
            j++;
            k++;
        }
    }

    // Main function that sorts arr[l..r] using
    // merge()
    void sort(long arr[], int l, int r) {
        if (l < r) {
            // Find the middle point
            int m = (l + r) / 2;

            // Sort first and second halves
            sort(arr, l, m);
            sort(arr, m + 1, r);

            // Merge the sorted halves
            merge(arr, l, m, r);
        }
    }
}
class Node
{
    int sum;
    int len;
    Node(int a, int b)
    {
        this.sum = a;
        this.len = b;
    }

    @Override
    public boolean equals(Object ob)
    {
        if(ob == null)
            return false;
        if(!(ob instanceof Node))
            return false;
        if(ob == this)
            return true;
        Node obj = (Node)ob;
        if(this.sum == obj.sum && this.len == obj.len)
            return true;
        return false;
    }

    @Override
    public int hashCode()
    {
        return (int)this.len;
    }
}
class Reader
{
    final private int BUFFER_SIZE = 1 << 16;
    private DataInputStream din;
    private byte[] buffer;
    private int bufferPointer, bytesRead;

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

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

    public String readLine() throws IOException
    {
        byte[] buf = new byte[64]; // line length
        int cnt = 0, c;
        while ((c = read()) != -1)
        {
            if (c == '\n')
                break;
            buf[cnt++] = (byte) c;
        }
        return new String(buf, 0, cnt);
    }

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

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

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

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

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

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

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

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

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

    public void close() throws IOException
    {
        if (din == null)
            return;
        din.close();
    }
}
class FenwickTree
{
    public void update(long[] fenwickTree,long delta,int index)
    {
        index += 1;
        while(index < fenwickTree.length)
        {
            fenwickTree[index] += delta;
            index = index + (index & (-index));
        }
    }
    public long prefixSum(long[] fenwickTree,int index)
    {
        long sum = 0L;
        index += 1;
        while(index > 0)
        {
            sum += fenwickTree[index];
            index -= (index & (-index));
        }
        return sum;
    }
}
class SegmentTree
{
    public int nextPowerOfTwo(int num)
    {
        if(num == 0)
            return 1;
        if(num > 0 && (num & (num - 1)) == 0)
            return num;
        while((num &(num - 1)) > 0)
        {
            num = num & (num - 1);
        }
        return num << 1;
    }
    public int[] createSegmentTree(int[] input)
    {
        int np2 = nextPowerOfTwo(input.length);
        int[] segmentTree = new int[np2 * 2 - 1];

        for(int i=0;i<segmentTree.length;i++)
            segmentTree[i] = Integer.MIN_VALUE;

        constructSegmentTree(segmentTree,input,0,input.length-1,0);
        return segmentTree;

    }
    private void constructSegmentTree(int[] segmentTree,int[] input,int low,int high,int pos)
    {
        if(low == high)
        {
            segmentTree[pos] = input[low];
            return;
        }
        int mid = (low + high)/ 2;
        constructSegmentTree(segmentTree,input,low,mid,2*pos + 1);
        constructSegmentTree(segmentTree,input,mid+1,high,2*pos + 2);
        segmentTree[pos] = Math.max(segmentTree[2*pos + 1],segmentTree[2*pos + 2]);
    }
    public int rangeMinimumQuery(int []segmentTree,int qlow,int qhigh,int len)
    {
        return rangeMinimumQuery(segmentTree,0,len-1,qlow,qhigh,0);
    }
    private int rangeMinimumQuery(int segmentTree[],int low,int high,int qlow,int qhigh,int pos)
    {
        if(qlow <= low && qhigh >= high){
            return segmentTree[pos];
        }
        if(qlow > high || qhigh < low){
            return Integer.MIN_VALUE;
        }
        int mid = (low+high)/2;
        return Math.max(rangeMinimumQuery(segmentTree, low, mid, qlow, qhigh, 2 * pos + 1),
                rangeMinimumQuery(segmentTree, mid + 1, high, qlow, qhigh, 2 * pos + 2));
    }
}
class Trie
{
    private class TrieNode
    {
        Map<Character, TrieNode> children;
        boolean endOfWord;
        public TrieNode()
        {
            children = new HashMap<>();
            endOfWord = false;
        }
    }

    private final TrieNode root;

    public Trie()
    {
        root = new TrieNode();
    }

    public void insert(String word)
    {
        TrieNode current = root;
        for (int i=0;i<word.length();i++)
        {
            char ch = word.charAt(i);
            TrieNode node = current.children.get(ch);
            if (node == null)
            {
                node = new TrieNode();
                current.children.put(ch, node);
            }
            current.endOfWord = true;
        }
    }

    public boolean search(String word)
    {
        TrieNode current = root;
        for (int i=0;i<word.length();i++)
        {
            char ch = word.charAt(i);
            TrieNode node = current.children.get(ch);
            if (node == null)
                return false;
            current = node;
        }
        return current.endOfWord;
    }

    public void delete(String word)
    {
        delete(root, word, 0);
    }

    private boolean delete(TrieNode current, String word, int index)
    {
        if (index == word.length())
        {
            if (!current.endOfWord)
                return false;
            current.endOfWord = false;
            return current.children.size() == 0;
        }
        char ch = word.charAt(index);
        TrieNode node = current.children.get(ch);
        if (node == null)
            return false;
        boolean shouldDeleteCurrentNode = delete(node, word, index + 1);
        if (shouldDeleteCurrentNode)
        {
            current.children.remove(ch);
            return current.children.size() == 0;
        }
        return false;
    }
}

20
be
beb
bko
bo
bob
eb
ebo
hb
hbe
jh
jhb
ko
kor
ob
or
ror
sj
sjh
ys
ysj

from sys import *
setrecursionlimit(200000)
d = {}
t = set()
s = input() + ' '
def gen(l, ll):
    if (l, ll) in t: return
    t.add((l, ll))
    if l > 6:
        d[s[l - 2 : l]] = 1
        if s[l - 2 : l] != s[l : ll]: gen(l - 2, l)
    if l > 7:
        d[s[l - 3 : l]] = 1
        if s[l - 3 : l] != s[l : ll]: gen(l - 3, l)
gen(len(s) - 1,len(s))
print(len(d))
for k in sorted(d): print(k)


#include <bits/stdc++.h>
using namespace std;
inline bool Ok(long double a, long double b, long double c) {}
int main() {
  long double x1, x2, y1, y2;
  cin >> x1 >> y1 >> x2 >> y2;
  int n, ret = 0;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    long double a, b, c;
    cin >> a >> b >> c;
    long double Y1 = (-a * x1 - c) / b;
    long double Y2 = (-a * x2 - c) / b;
    ret += ((Y1 - y1) * (Y2 - y2) <= 0);
  }
  cout << ret;
  return 0;
}

x1,y1 = [int(i) for i in input().split()]
x2,y2 = [int(i) for i in input().split()]
n = int(input())
m = 0
for i in range(n):
    x,y,c = [int(g) for g in input().split()]
    if(x1*x+y1*y+c>0):
        l = 1
    else:
        l = -1
    if(l==-1)and(x2*x+y2*y+c>0):
        m+=1
    elif(l==1)and(x2*x+y2*y+c<0):
        m+=1
print(m)


import java.util.Scanner;

/**
 * Created by tdph5945 on 2016-06-18.
 */
public class DimaAndContinuousLine {
    public static void main(String... args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt(), first, second, lfirst, lsecond;
        int[] arr = new int[n];
        for (int i = 0; i < n; i++) {
            arr[i] = scanner.nextInt();
        }

        String res = "no";
        outer:
        for (int i = 0; i < n - 1; i++) {

            first = Math.min(arr[i], arr[i + 1]);
            second = Math.max(arr[i], arr[i + 1]);

            for (int j = 0; j < i; j++) {
                lfirst = Math.min(arr[j], arr[j + 1]);
                lsecond = Math.max(arr[j], arr[j + 1]);
                if ((first < lfirst && lfirst < second && second < lsecond) ||
                        (lfirst < first && lsecond < second && first < lsecond)) {
                    res = "yes";
                    break outer;
                }
            }
        }
        System.out.println(res);
    }
}

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

a = list(zip(lst,lst[1:]))

record = []

for x in a:
    s,e = min(x[0],x[1]),max(x[0],x[1])
    for y in record:
        if y[0]<s<y[1]<e or s<y[0]<e<y[1]:
            exit(print("yes"))
    record.append((s,e))
print("no")


n,k = map(int,input().split())
if n*(n-1) <= k*2:
    print('no solution')
else:
    for i in range(n):
        print(0,i)

#include <bits/stdc++.h>
using namespace std;
int GCD(int a, int b) {
  if (!a) return b;
  return GCD(b % a, a);
}
vector<int> x(4000);
vector<int> y(4000);
void D(double x, double y, double x1, double y1) {
  double d = (x - x1) * (x - x1) + (y - y1) * (y - y1);
  cout << sqrt(d) << "\n";
}
int main() {
  int n, k;
  cin >> n >> k;
  int tot = ((n - 1) * n) / 2;
  if (tot > k) {
    y[0] = 0;
    for (int i = 1; i < n; i++) {
      y[i] = y[i - 1] + (100000 - i);
    }
    for (int i = 0; i < n; i++) {
      printf("%d %d\n", i, y[i]);
    }
  } else {
    puts("no solution");
  }
  return 0;
}


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

import com.sun.org.apache.bcel.internal.generic.LLOAD;

/*
	br = new BufferedReader(new FileReader("input.txt"));
	pw = new PrintWriter(new BufferedWriter(new FileWriter("output.txt")));
	br = new BufferedReader(new InputStreamReader(System.in));
	pw = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));

 */

public class Main {
	private static BufferedReader br;
	private static StringTokenizer st;
	private static PrintWriter pw;

	static int[] dx = new int[]{-1,0,1,0};
	static int[] dy = new int[]{0,1,0,-1};

	public static void main(String[] args) throws IOException	{
		br = new BufferedReader(new InputStreamReader(System.in));
		pw = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
		//int qq = 1;
		int qq = Integer.MAX_VALUE;
		//int qq = readInt();
		for(int casenum = 1; casenum <= qq; casenum++)	{
			int n = readInt();
			if(n%4==2 || n%4==3)	{
				pw.println(-1);
			}
			else if(n == 1)	{
				pw.println(1);
			}
			else	{
				int[] list = new int[n];
				if(n%4==1)	{
					int curr = 2;
					for(int i = 0; i < list.length/2; i += 2)	{
						list[i] = curr;
						list[i+1] = (n+1)-(curr-1);
						list[list.length-2-i] = curr-1;
						list[list.length-1-i] = n+1-curr;
						curr += 2;
					}
					list[list.length/2] = (n+1)/2;
				}
				else	{
					int curr = 2;
					for(int i = 0; i < list.length/2; i += 2)	{
						list[i] = curr;
						list[i+1] = n+2-curr;
						curr += 2;
					}
					curr = 1;
					for(int i = list.length-2; i >= list.length/2; i -= 2)	{
						list[i] = curr;
						list[i+1] = n-curr;
						curr += 2;
					}
				}
				StringBuilder sb = new StringBuilder();
				for(int out: list)	{
					sb.append(out + " ");
				}
				pw.println(sb.toString().trim());
			}
		}
		pw.close();
	}

	public static boolean lucky(int[] list)	{
		for (int i = 0; i < list.length; i++) {
			if(list[list[i]-1] != list.length-i)	{
				return false;
			}
		}
		return true;
	}

	private static long readLong() throws IOException	{
		return Long.parseLong(nextToken());
	}

	private static double readDouble() throws IOException	{
		return Double.parseDouble(nextToken());
	}

	private static int readInt() throws IOException	{
		return Integer.parseInt(nextToken());
	}

	private static String nextToken() throws IOException	{
		while(st == null || !st.hasMoreTokens())	{
			if(!br.ready())	{
				pw.close();
				System.exit(0);
			}
			st = new StringTokenizer(br.readLine().trim());
		}
		return st.nextToken();
	}
}

n=int(input())

L=[0]*(n+1)

X=[False]*(n+1)

if(n%4!=0 and n%4!=1):
    print(-1)

else:
    for i in range(1,n+1):
        if(X[i]):
            continue
        X[i]=True
        X[n-i+1]=True
        for j in range(i+1,n+1):
            if(X[j]):
                continue
            X[j]=True
            X[n-j+1]=True
            L[i]=j
            L[n-i+1]=n-j+1
            L[j]=n-i+1
            L[n-j+1]=i
            break
        if(n%4==1):
            L[n//2+1]=n//2+1
    for i in range(1,n):
        print(L[i],end=" ")
    print(L[n])


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

public class RelayRace {
    public static void main(String[] args) {
        MyScanner sc = new MyScanner();

        int N = sc.nextInt();

        int[][] a = new int[N][N];
        for (int i = 0; i < N; i++) {
        	for (int j = 0; j < N; j++) {
        		a[i][j] = sc.nextInt();
        	}
        }

        int diagLen = 2 * N - 1;
//        int[][][] dp = new int[diagLen][N][N];
//        dp[0][0][0] = a[0][0];
        int[][] prev = new int[1][1];
        prev[0][0] = a[0][0];
        for (int d = 1; d < diagLen; d++) {
        	int len = (d < N) ? d : (diagLen - d - 1);
        	int[][] next = new int[len + 1][len + 1];
//        	System.out.println("len = " + len);
        	for (int x = 0; x <= len; x++) {
//        		System.out.println("px:");
        		Location pX = diagToRect(d, x, N);
        		int x0 = (d >= N) ? x : (x - 1);
        		for (int y = x; y <= len; y++) {
//            		System.out.println("py:");
            		int y0 = (d >= N) ? y : (y - 1);
        			Location pY = diagToRect(d, y, N);
        			if (x == y) {
        				int poss1 = getDP(prev, d - 1, x0, y0, N);
        				int poss2 = getDP(prev, d - 1, x0, y0 + 1, N);
        				int poss3 = getDP(prev, d - 1, x0 + 1, y0 + 1, N);
        				int best = Math.max(poss1, Math.max(poss2, poss3));
//        				System.out.format("X == Y: (%d, %d, %d): (%d, %d), p1 = %d, p2 = %d, p3 = %d\n", d, x, y, x0, y0, poss1, poss2, poss3);
//        				dp[d][x][y] = best + a[pX.X][pX.Y];
        				next[x][y] = best + a[pX.R][pX.C];
        			} else {
        				int poss1 = getDP(prev, d - 1, x0, y0, N);
        				int poss2 = getDP(prev, d - 1, x0, y0 + 1, N);
        				int poss3 = getDP(prev, d - 1, x0 + 1, y0, N);
        				int poss4 = getDP(prev, d - 1, x0 + 1, y0 + 1, N);
        				int best = Math.max(poss1, Math.max(poss2,  Math.max(poss3, poss4)));
//        				System.out.format("X != Y: (%d, %d, %d): (%d, %d), p1 = %d, p2 = %d, p3 = %d, p4 = %d\n", d, x, y, x0, y0, poss1, poss2, poss3, poss4);
//        				dp[d][x][y] = best + a[pX.X][pX.Y]+ a[pY.X][pY.Y];
        				next[x][y] = best + a[pX.R][pX.C]+ a[pY.R][pY.C];
        			}
//        			System.out.format("dp[%d][%d][%d] = %d\n", d, x, y, next[x][y]);
        		}
        	}
			prev = next;
        }

        System.out.println(prev[0][0]);
    }

    public static int getDP(int[][][] dp, int d, int x, int y, int N) {
        int diagLen = 2 * N - 1;
    	int len = (d < N) ? d : (diagLen - d - 1);
    	if (x < 0 || x > len || y < 0 || y > len) {
    		return -1000000;
    	} else {
    		return dp[d][x][y];
    	}
    }

    public static int getDP(int[][] dp, int d, int x, int y, int N) {
        int diagLen = 2 * N - 1;
    	int len = (d < N) ? d : (diagLen - d - 1);
    	if (x < 0 || x > len || y < 0 || y > len) {
    		return -1000000;
    	} else {
//    		System.out.println(d + " " + diagLen + " " + len + " " + dp.length);
    		return dp[x][y];
    	}
    }

    public static Location diagToRect(int d, int x, int N) {
    	int r0 = (d < N) ? d : (N - 1);
    	int c0 = (d < N) ? 0 : (d - N + 1);
    	int r = r0 - x;
    	int c = c0 + x;
//    	System.out.format("(%d, %d) => (%d, %d)\n", d, x, r, c);
    	return new Location(r, c);
    }

    public static boolean valid(Location p, int N) {
    	return (p.C >= 0 && p.C < N && p.R >= 0 && p.R < N);
    }

    public static class Location {
    	public int R, C;

    	public Location(int r, int c) {
    		this.R = r;
    		this.C = c;
    	}
    }

    public static class MyScanner {
        BufferedReader br;
        StringTokenizer st;

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

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

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

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

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

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

44

I hope this helps! Let me know if you need anything else.

#include <bits/stdc++.h>
using namespace std;
const int MAXN = 3e2 + 10;
const int INF = 1e8 + 100;
int dp[MAXN][MAXN][MAXN];
bool vis[MAXN][MAXN][MAXN];
int a[MAXN][MAXN];
int memo(int r, int d, int R) {
  if (vis[r][d][R]) return dp[r][d][R];
  vis[r][d][R] = true;
  int D = r + d - R;
  int &res = dp[r][d][R];
  res = -INF;
  if (r + d == 0) {
    res = a[0][0];
    return res;
  }
  int temp = a[r][d] + a[R][D];
  if (R == r) temp = a[r][d];
  if (r && R) res = max(res, temp + memo(r - 1, d, R - 1));
  if (r && D) res = max(res, temp + memo(r - 1, d, R));
  if (d && R) res = max(res, temp + memo(r, d - 1, R - 1));
  if (d && D) res = max(res, temp + memo(r, d - 1, R));
  return res;
}
int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; i++)
    for (int j = 0; j < n; j++) cin >> a[i][j];
  cout << memo(n - 1, n - 1, n - 1);
}


#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  if (n == 1) {
    cout << 1;
    return 0;
  }
  cout << n * (n - 1) * 6 + 1;
  return 0;
}

def star(n):
    a, b = 1, 12
    for i in range(2, n + 1):
        a += b
        b += 12
    return a

print(star(int(input())))


1m 1m 8m
1m 1m 2m
1s 1s 8s
2m 2m 6m
2p 2p 4p
2m 2m 3m
1s 2s 3s
1p 1p 4p
2m 2p 2s
1m 1m 9m
3m 3p 3s
8m 8p 8s
1s 1s 3s
2m 9s 1m
1m 1m 7m
1s 1s 7s
9m 9m 9m
9m 9p 9s
1p 1p 2p
5m 5p 5s
1m 1m 3m
2m 2m 4m
1p 1p 7p
1m 1m 6m
1p 1p 6p
1p 1p 9p
1m 1p 1s
1s 1s 4s
1p 1p 5p
2p 2p 3p
2m 2m 7m
1m 1m 4m
4p 4s 2m
1p 1p 3p
2m 2m 5m
4m 4p 4s
1m 1m 2m
3s 5s 7s
1m 1m 5m
1s 1s 6s
1s 1s 9s
7m 7p 7s
3p 9p 4m
2m 2m 8m
1s 1s 5s
2m 2m 9m
3p 9m 2p
6m 6p 6s
1s 1s 2s
1p 1p 8p

import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        String a = in.next();
        String b = in.next();
        String c = in.next();
        int min = 2;
        if (a.equals(b) && b.equals(c)) {
            min = 0;
        }
        if (a.charAt(1) == b.charAt(1) && b.charAt(1) == c.charAt(1)) {
            int[] arr = new int[]{a.charAt(0) - '0', b.charAt(0) - '0', c.charAt(0) - '0'};
            Arrays.sort(arr);
            if (arr[0] + 1 == arr[1] && arr[1] + 1 == arr[2]) {
                min = 0;
            }
        }
        if (a.equals(b) || b.equals(c) || a.equals(c)) {
            min = Math.min(min, 1);
        }
        int A = a.charAt(0) - '0';
        int B = b.charAt(0) - '0';
        int C = c.charAt(0) - '0';
        if (a.charAt(1) == b.charAt(1) && Math.abs(A - B) <= 2) {
            min = Math.min(min, 1);
        }
        if (a.charAt(1) == c.charAt(1) && Math.abs(A - C) <= 2) {
            min = Math.min(min, 1);
        }
        if (b.charAt(1) == c.charAt(1) && Math.abs(B - C) <= 2) {
            min = Math.min(min, 1);
        }
        System.out.println(min);
    }
}


import java.util.*;

public class Solution
{
	public static void main(String[] args)
	{
		Scanner in=new Scanner(System.in);
		int n=in.nextInt();
		long s,min=999999999,sum=0,t=0;
		s=in.nextLong();
		long v[]=new long[n];
		for(int i=0;i<n;i++)
		{
			v[i]=in.nextLong();
			if(min>v[i])
				min=v[i];
			t+=v[i];
		}
		if(t<s)
			System.out.println(-1);
		else
		{
			for(int i=0;i<n;i++)
			{
				sum+=v[i]-min;
				v[i]=min;
			}
			if(sum>=s)
			{
				System.out.println(min);
			}
			else
			{
				s=s-sum;
				System.out.println((n*min-s)/n);
			}
		}
	}
}

x,y=map(int,input().split())
s=list(map(int,input().split()))
if sum(s)<y:
    print(-1)
else:
    j=sum(s)-y
    if j<x:
        print(0)
    elif x==j:
        print(1)
    else:
        print(min(min(s),j//x))


#include <bits/stdc++.h>
using namespace std;
vector<int> v[102];
bool par[102][102];
bool vis[102];
int cyc = 0;
void dfs(int nd, int p) {
  vis[nd] = true;
  int z = v[nd].size();
  int nx;
  for (int i = 0; i < z; i++) {
    nx = v[nd][i];
    if (vis[nx]) {
      if (nx != p && p != 0) {
        if (par[nx][nd] || par[nd][nx]) continue;
        par[nx][nd] = par[nd][nx] = true;
        cyc++;
      }
    } else
      dfs(nx, nd);
  }
  return;
}
int main() {
  int n, m;
  cin >> n >> m;
  int x, y;
  for (int i = 0; i < m; i++) {
    cin >> x >> y;
    v[x].push_back(y);
    v[y].push_back(x);
  }
  dfs(1, 0);
  bool complete = true;
  for (int i = 1; i <= n; i++) {
    if (!vis[i]) {
      complete = false;
    }
  }
  if (cyc == 1 && complete) {
    cout << "FHTAGN!";
  } else
    cout << "NO";
  return 0;
}

inp = input().split()

n = int(inp[0])
m = int(inp[1])

def dfs(x):

    visited.add(x)

    for y in e[x]:

        if not y in visited:

            dfs(y)

if n >= 3 and n == m:

    visited = set()

    e = [[] for i in range(n + 1)]

    for i in range(m):

        x, y = map(int, input().split())

        e[x].append(y)

        e[y].append(x)

    dfs(1)

    print('FHTAGN!' if len(visited) == n else 'NO')
else:
    print('NO')


#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  while (~scanf("%d%d", &n, &m)) {
    for (int i = 1; i <= n; i++) {
      int u, v;
      cin >> u >> v;
    }
    for (int j = 1; j <= m; j++) {
      int u, v;
      cin >> u >> v;
    }
    if (n == m)
      puts("Yes");
    else
      puts("No");
  }
  return 0;
}

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

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

// Created by @thesupremeone on 30/06/21
public class GuardDuty {

    int r,b;

    void solve() throws IOException {
        r = getInt();
        b = getInt();
        if(r!=b){
            println("No");
            return;
        }
        println("Yes");
    }

    public static void main(String[] args) throws Exception {
        if (isOnlineJudge()) {
            in = new BufferedReader(new InputStreamReader(System.in));
            out = new BufferedWriter(new OutputStreamWriter(System.out));
            new GuardDuty().solve();
            out.flush();
        } else {
            localJudge = new Thread();
            in = new BufferedReader(new FileReader("input.txt"));
            out = new BufferedWriter(new FileWriter("output.txt"));
            localJudge.start();
            new GuardDuty().solve();
            out.flush();
            localJudge.suspend();
        }
    }
    static boolean isOnlineJudge(){
        try {
            return System.getProperty("ONLINE_JUDGE")!=null
                    || System.getProperty("LOCAL")==null;
        }catch (Exception e){
            return true;
        }
    }
    // Fast Input & Output
    static Thread localJudge = null;
    static BufferedReader in;
    static StringTokenizer st;
    static BufferedWriter out;
    static String getLine() throws IOException{
        return in.readLine();
    }
    static String getToken() throws IOException{
        if(st==null || !st.hasMoreTokens())
            st = new StringTokenizer(getLine());
        return st.nextToken();
    }
    static int getInt() throws IOException {
        return Integer.parseInt(getToken());
    }
    static long getLong() throws IOException {
        return Long.parseLong(getToken());
    }
    static void print(Object s) throws IOException{
        out.write(String.valueOf(s));
    }
    static void println(Object s) throws IOException{
        out.write(String.valueOf(s));
        out.newLine();
    }
}


c = int(input())
a = list(map(int, input().split()))
res = 0
b = []
for i in range(len(a)):
    b.append(False)
for i in range(len(a)):
    k = len(a) - i - 1
    m = 0
    while b[k] == False:
        b[k] = True
        k = a[k] - 1
        m = 1
        if (k == -1):
            break
    if m == 1:
        res = res + 1
print(res)

#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, ans = 1;
  cin >> n;
  map<int, int> m;
  m.insert(pair<int, int>(0, 0));
  for (int i = 1; i <= n; i++) {
    int temp;
    cin >> temp;
    if (m.find(temp) != m.end()) {
      m.erase(m.find(temp));
    } else {
      ans++;
    }
    m.insert(pair<int, int>(i, 0));
  }
  cout << ans;
}


import java.io.IOException;
import java.io.InputStream;
import java.util.NoSuchElementException;

public class Main {
	private static long d, k, a, b, t;

	public static void main(String[] args) {
		FastScanner sc = new FastScanner();
		d = sc.nextLong();
		k = sc.nextLong();
		a = sc.nextLong();
		b = sc.nextLong();
		t = sc.nextLong();

		// x [km] [x / k] * (a + t) - (x - [x / k]) * a [s]

		long ret = Long.MAX_VALUE;
		for (long x = Math.max(0, (d / k - 1000000) * k); x <= d + k; x += k) {
			ret = Math.min(ret, f(Math.min(x, d)));
		}
		ret = Math.min(ret, f(Math.min(k, d)));
		System.out.println(ret);
	}

	private static long f(long x) {
		long n = x / k;
		long t1 = n * (a + t) + (x - n) * a;
		if (t1 > 0 && x % k == 0) {
			t1 -= t;
		}
		long t2 = (d - x) * b;
		return t1 + t2;
	}

}

class FastScanner {
	public static String debug = null;

	private final InputStream in = System.in;
	private int ptr = 0;
	private int buflen = 0;
	private byte[] buffer = new byte[1024];
	private boolean eos = false;

	private boolean hasNextByte() {
		if (ptr < buflen) {
			return true;
		} else {
			ptr = 0;
			try {
				if (debug != null) {
					buflen = debug.length();
					buffer = debug.getBytes();
					debug = "";
					eos = true;
				} else {
					buflen = in.read(buffer);
				}
			} catch (IOException e) {
				e.printStackTrace();
			}
			if (buflen < 0) {
				eos = true;
				return false;
			} else if (buflen == 0) {
				return false;
			}
		}
		return true;
	}

	private int readByte() {
		if (hasNextByte())
			return buffer[ptr++];
		else
			return -1;
	}

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

	private void skipUnprintable() {
		while (hasNextByte() && !isPrintableChar(buffer[ptr]))
			ptr++;
	}

	public boolean isEOS() {
		return this.eos;
	}

	public boolean hasNext() {
		skipUnprintable();
		return hasNextByte();
	}

	public String next() {
		if (!hasNext())
			throw new NoSuchElementException();
		StringBuilder sb = new StringBuilder();
		int b = readByte();
		while (isPrintableChar(b)) {
			sb.appendCodePoint(b);
			b = readByte();
		}
		return sb.toString();
	}

	public long nextLong() {
		if (!hasNext())
			throw new NoSuchElementException();
		long n = 0;
		boolean minus = false;
		int b = readByte();
		if (b == '-') {
			minus = true;
			b = readByte();
		}
		if (b < '0' || '9' < b) {
			throw new NumberFormatException();
		}
		while (true) {
			if ('0' <= b && b <= '9') {
				n *= 10;
				n += b - '0';
			} else if (b == -1 || !isPrintableChar(b)) {
				return minus ? -n : n;
			} else {
				throw new NumberFormatException();
			}
			b = readByte();
		}
	}

	public int nextInt() {
		return (int) nextLong();
	}

	public long[] nextLongList(int n) {
		return nextLongTable(1, n)[0];
	}

	public int[] nextIntList(int n) {
		return nextIntTable(1, n)[0];
	}

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

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

#include <bits/stdc++.h>
using namespace std;
long long D;
long long K;
long long CAR_TIME;
long long WALK_TIME;
long long FIX_TIME;
int main() {
  scanf("%lld %lld %lld %lld %lld", &D, &K, &CAR_TIME, &WALK_TIME, &FIX_TIME);
  long long time = min(K, D) * CAR_TIME + max(0LL, D - K) * WALK_TIME;
  long long blocks = D / K;
  long long rem = D % K;
  if (blocks == 0) {
    time = min(time, D * CAR_TIME);
  } else if (rem == 0) {
    time = min(time, (blocks - 1) * (FIX_TIME + K * CAR_TIME) + K * CAR_TIME);
  } else {
    time = min(time, (blocks - 1) * (FIX_TIME + K * CAR_TIME) + K * CAR_TIME +
                         rem * WALK_TIME);
    time = min(time, (blocks) * (FIX_TIME + K * CAR_TIME) + rem * CAR_TIME);
  }
  printf("%lld", time);
}


import java.util.*;
import java.io.*;
import java.math.*;
public class Main implements Runnable {
	final String filename="test";

	final int base = 1<<20;

	int[] tree = new int[base*2];

	void set(int x, int val)
	{
		x+=base;
		while (x>0)
		{
			tree[x] = Math.max(tree[x], val);
			x /=2;
		}
	}

	int getmax(int left, int right)
	{
		left+=base;
		right +=base;
		int ans = 0;
		while (left+1<right)
		{
			if (left%2!=0)
			{
				ans = Math.max(ans, tree[left]);
				left++;
			}
			if (right%2!=0)
			{
				right--;
				ans = Math.max(ans, tree[right]);
			}
			left/=2;
			right/=2;
		}
		if (left<right)
			ans = Math.max(ans, tree[left]);
		return ans;
	}

	void solve() throws Exception
	{
		int n = iread();
		int[] x = new int[n];
		int[] y = new int[n];
		for (int i=0; i<n; i++)
		{
			x[i] = iread()-1;
		}
		for (int j=0; j<n; j++)
		{
			y[iread()-1] = j;
		}
		for (int i=0; i<n; i++)
			x[i] = n-y[x[i]]-1;
		int ans = 0;
		for (int i=0; i<n; i++)
		{
			int v = getmax(0, x[i]) + 1;
			set(x[i], v);
			ans = Math.max(ans, v);
		}
		out.write(ans+"\n");
	}

	public static void main(String[] args) {
		Main inst = new Main();
		new Thread(inst).run();
	}
	int iread()
	{
		return Integer.parseInt(readword());
	}
	long lread()
	{
		return Long.parseLong(readword());
	}
	double dread()
	{
		return Double.parseDouble(readword());
	}

	String readword()
	{
		try
		{
			int c = in.read();
			while (c<=32)
			{
				if (c<0) return "";
				c = in.read();
			}
			StringBuilder sb = new StringBuilder();
			while (c>32)
			{
				sb.append((char)c);
				c = in.read();
			}
			return sb.toString();
		} catch (Exception e)
		{
			e.printStackTrace();
			System.exit(1);
			return "";
		}
	}

	BufferedReader in;
	BufferedWriter out;
	public void run() {
		try
		{
			//in = new BufferedReader(new FileReader(filename+".in"));
			//out = new BufferedWriter(new FileWriter(filename+".out"));
			in = new BufferedReader(new InputStreamReader(System.in));
			out = new BufferedWriter(new OutputStreamWriter(System.out));

			solve();
			out.flush();
		} catch (Exception e)
		{
			e.printStackTrace();
			System.exit(1);
		}
	}

}

#include <bits/stdc++.h>
using namespace std;
const int maxn = 1000005;
struct node {
  int x, y;
} data[maxn];
int pos[maxn], dp[maxn], n;
int getmax(int a, int b) { return a > b ? a : b; }
bool cmp(node a, node b) { return a.x < b.x; }
void init() {
  scanf("%d", &n);
  for (int i = 0; i < n; i++) scanf("%d", &data[i].x);
  for (int i = 0; i < n; i++) scanf("%d", &data[i].y);
}
void work() {
  for (int i = 0; i < n; i++) pos[data[i].y] = i + 1;
  for (int i = 0; i < n; i++) data[i].y = pos[data[i].x];
  int ans = 1;
  dp[1] = data[0].y;
  for (int i = 1; i < n; i++) {
    int ts, te, lower = 1, upper = ans, ret = 0;
    while (lower <= upper) {
      int mid = (lower + upper) >> 1;
      if (dp[mid] > data[i].y) {
        ret = mid;
        lower = mid + 1;
      } else
        upper = mid - 1;
    }
    ret++;
    dp[ret] = getmax(dp[ret], data[i].y);
    ans = getmax(ans, ret);
  }
  printf("%d\n", ans);
}
int main() {
  init();
  work();
  return 0;
}


n=eval(input())
cnt=0
while n:
    a=n%8
    n=n//8
    if a==1:
        cnt+=1
print(cnt)

import java.util.*;
public class Main{
    public static void main(String[] args){
        Scanner cin=new Scanner(System.in);
        int n=cin.nextInt();
        int ans=0;
        while(n!=0){
            if(n%8==1) ans++;
            n/=8;
        }
        System.out.printf("%d",ans);
        return;
    }
}


#include <bits/stdc++.h>
using namespace std;
bool comp(int a, int b) { return a > b; }
int main() {
  int n, m;
  cin >> n >> m;
  int s[n];
  for (int i = 0; i < n; i++) cin >> s[i];
  sort(s, s + n, comp);
  for (int i = 0; i < n; i++) {
    m -= s[i];
    if (m <= 0) {
      cout << i + 1 << endl;
      break;
    }
  }
}

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

public class Main {

    public static void main(String[] args) {
    Scanner sc=new Scanner(System.in);
    int n=sc.nextInt();
    int m=sc.nextInt();
    int size[]=new int[n];
     for(int i=0;i<n;i++)
         {
       size[i]=sc.nextInt();

         }
    java.util.Arrays.sort(size);

int sum=0,count=0;
for(int i=n-1;i>=0;i--)
{
    sum+=size[i];
    count++;
if(sum>=m)
{
          System.out.println(count);
          break;
}

}
     //   System.out.println(0);
    }
}


#include <bits/stdc++.h>
using namespace std;
int main() {
  int u, d, lu, ld, ru, rd;
  scanf("%d%d%d%d%d%d", &u, &lu, &ld, &d, &rd, &ru);
  int nu = min(lu, ru);
  int nd = min(ld, rd);
  int ans = 2 * nu * u + nu * nu;
  ans += 2 * nd * d + nd * nd;
  int t = lu + ld - nu - nd;
  ans += t * (2 * u + 2 * nu);
  printf("%d", ans);
  return 0;
}


#include <bits/stdc++.h>
using namespace std;
double fun(double a, double b) { return (a * (1 - b)) + ((1 - a) * b); }
double Max(double a, double b, double c) { return fmax(fmax(a, b), c); }
double cmp(double a, double b) { return a > b; }
int main() {
  ios::sync_with_stdio(false);
  int n;
  double a[1000], max;
  while (cin >> n) {
    max = 0;
    for (int i = 0; i < n; i++) {
      cin >> a[i];
    }
    sort(a, a + n, cmp);
    double temp = a[0], temp2 = (1.0 - a[0]);
    max = a[0];
    for (int i = 1; i < n; i++) {
      temp = temp * (1.0 - a[i]) + a[i] * temp2;
      max = Max(max, temp, a[i]);
      temp2 *= (1.0 - a[i]);
    }
    cout << fixed << setprecision(12) << max << endl;
  }
  return 0;
}

n=int(input())
from itertools import combinations

a = sorted(list(map(float, input().split())), reverse=True)
#a=[0.01]*100
if max(a) == 1:
    print(1)
    quit()
n=len(a)
pre = [1]*100
pre[0] = 1 - a[0]
for i in range(1, n):
    pre[i] = pre[i-1] * (1-a[i])

ans = 0
for i in range(1,n+1):
    anss=0
    for j in range(i):
        anss = anss + pre[i-1] / (1-a[j]) * a[j]
    ans = max(ans, anss)
print(ans)


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

public class Main {

    static int n,k;
    static int[][] dp;
    static final int INF = 1000000007;

    public static void main(String[] args) {

        Scanner scan = new Scanner(System.in);

        PrintWriter out = new PrintWriter(System.out);

        n = scan.nextInt();
        k = scan.nextInt();
        dp = new int[n+1][k+1];

//      ArrayList<ArrayList<Integer>> divisor = new ArrayList<ArrayList<Integer>>();
//      divisor.add(0,new ArrayList<Integer>());

        short[][] divisor = new short[n+1][];

        for (int i = 1; i <= n ; i++) {
//          ArrayList<Integer> list = new ArrayList<Integer>();
            short[] list = new short[n];
            int cnt = 0;
            for (short j = 1; j <= i ; j++) {
//              if(i%j==0) list.add(j);
                if(i%j==0){
                    list[cnt] = j;
                    cnt++;
                }
            }
//          divisor.add(i, list);
            divisor[i] = list;
        }

        for (int i = 1; i <= n ; i++) {
            dp[i][1] = 1;
        }

        for (int j = 2; j <= k ; j++) {
            for (int i = 1; i <= n ; i++) {
                int sum = 0;
//              ArrayList<Integer> list = divisor.get(i);
                short[] list = divisor[i];
                for (int q = 0; q < n; q++) {
                    if(list[q]==0) break;
                    sum = (sum + dp[list[q]][j-1])% INF;
                }
//              for (Integer p : list) {
//                  sum = (sum + dp[p][j-1]) % INF;
//              }
                dp[i][j] = sum;
            }
        }

        int ans = 0;
        for (int i = 1; i <= n ; i++) {
            ans = (ans + dp[i][k]) % INF;
        }

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

import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)

def main():
    n,k = LI()
    t = [0] * n
    t[0] = 1

    for _ in range(k):
        u = [0] * n
        for i in range(n):
            b = t[i] % mod
            for j in range(i,n,i+1):
                u[j] += b
        t = u

    return sum(t) % mod

print(main())


#include <bits/stdc++.h>
using namespace std;
inline long long read() {
  long long x = 0;
  bool f = false;
  char c = getchar();
  while (c < '0' || c > '9') {
    if (c == '-') f = true;
    c = getchar();
  }
  while (c >= '0' && c <= '9') {
    x = (x << 3) + (x << 1) + (c ^ '0');
    c = getchar();
  }
  return f ? -x : x;
}
inline void write(long long x) {
  if (x < 0) putchar('-'), x = -x;
  if (x > 9) write(x / 10);
  putchar(x % 10 + '0');
}
long long n, k, a[101], b[101][101], ans, cnt1, cnt2;
signed main() {
  n = read();
  k = read();
  for (register long long i = 0; i < n; ++i)
    a[i] = read(), b[i / k][i % k] = a[i];
  for (register long long i = 0; i < k; ++i) {
    cnt1 = cnt2 = 0;
    for (register long long j = 0; j < n / k; ++j)
      b[j][i] == 1 ? ++cnt1 : ++cnt2;
    ans += min(cnt1, cnt2);
  }
  cout << ans;
  return 0;
}

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

print(sum(min(x.count(1), x.count(2)) for x in (a[i::k] for i in range(k))))


#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, a, b;
  scanf("%d", &n);
  vector<int> v(n);
  for (int i = 0; i < n; i++) scanf("%d", &v[i]);
  sort(v.begin(), v.end(), greater<int>());
  v.resize(unique(v.begin(), v.end()) - v.begin());
  scanf("%d%d", &a, &b);
  int count = 0, be = 0;
  while (a > b && be < v.size()) {
    count++;
    int step = 0;
    for (int i = be; i < v.size() && v[i] > step; i++) {
      if (a - a % v[i] >= b)
        step = ((step > (a % v[i])) ? step : (a % v[i]));
      else
        be = i + 1;
    }
    if (step)
      a -= step;
    else
      a--;
  }
  count += a - b;
  printf("%d\n", count);
  return 0;
}

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

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 * @author Alexandr Azizyan
 */
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);
		TaskE solver = new TaskE();
		solver.solve(1, in, out);
		out.close();
	}
}

class TaskE {
    public void solve(int testNumber, Scanner in, PrintWriter out) {
        int n = in.nextInt();
        TreeSet<Integer> x = new TreeSet<Integer>();
        while (n-- > 0)
            x.add(in.nextInt());
        int a = in.nextInt(), b = in.nextInt();

        int[] dp = new int[a - b + 2];
        for (Integer xi : x)
            for (int i = b / xi; i <= a / xi; i++) {
                int tmp = xi * i;
                if (b <= tmp)
                    dp[tmp - b] = xi;
            }

        int[] next = new int[a - b + 2];
        for (int i = 0; i < a - b + 2; i++) {
            next[i] = Math.max(dp[i], 2) - 1 + i;
            if (i != 0)
                next[i] = Math.max(next[i], next[i - 1]);
        }

        int ans = 0;
        for (int p = 0; p < a - b; p = next[p])
            ans++;

        out.println(ans);
    }
}


def f(x):
    return int(x * x + 1e7)

def g(x):
    return -f(x)

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

if(m == 3):
    if(n == 3):
        print('0 0')
        print('1 0')
        print('0 1')
    elif(n == 4):
        print('0 0')
        print('1 1')
        print('10000 0')
        print('0 10000')
    else:
        print(-1)
else:
    for i in range(m):
        print(i, f(i))
    for i in range(n - m):
        print(i, g(i))

#include <bits/stdc++.h>
using namespace std;
const int MOD = 1000000007;
const double eps = 1e-8;
const int nm = 300005;
int n, k, m, t;
long long res;
int a[nm];
char s[nm];
bool check[nm];
long long Pow(int x, int mu) {
  if (mu == 0) return 1ll;
  long long res = Pow(x, mu >> 1);
  res = res * res % MOD;
  if (mu & 1) res = res * x % MOD;
  return res;
}
int main() {
  int i, j, x, y, z, w;
  scanf("%d%d", &n, &m);
  if (m == 3) {
    if (n == 3) {
      cout << "0 0\n1 1\n0 1";
    } else if (n == 4) {
      cout << "0 0\n0 5\n5 0\n1 1";
    } else
      cout << "-1";
  } else {
    for (i = 1; i <= m; i++) {
      cout << i << " " << i * i << "\n";
    }
    for (i = 1; i <= n - m; i++) {
      cout << i << " " << -i * i - 100000 << "\n";
    }
  }
  return 0;
}


#include <bits/stdc++.h>
using namespace std;
bool comp(int x, int y) { return x > y; }
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  ;
  int tt = 1;
  long long m, n, k;
  string st;
  while (tt--) {
    cin >> n;
    int arr[n];
    for (long long i = 0; i < n; i++) cin >> arr[i];
    vector<int> vec;
    for (long long i = 0; i < n; i++) {
      int mxx = arr[i];
      vec.push_back(mxx);
      for (long long j = i + 1; j < n; j++) {
        mxx = mxx ^ arr[j];
        vec.push_back(mxx);
      }
    }
    sort(vec.begin(), vec.end());
    cout << vec.back() << endl;
  }
}

import itertools
import functools
def allSubArrays(xs):
    n = len(xs)
    indices = list(range(n+1))
    for i,j in itertools.combinations(indices,2):
        yield xs[i:j]
n=int(input())
my_list=list(map(int,input().split(" ")))
list_=list(allSubArrays(my_list))
for i in range(len(list_)):
    list_[i]=functools.reduce(lambda x,y:x^y,list_[i])
print(max(list_))


#include <bits/stdc++.h>
using namespace std;
int a[100000] = {0};
string s;
int main() {
  int min1 = 100000;
  cin >> s;
  int n = s.size();
  for (int i = 1; i <= n; i++)
    a[i] = a[i - 1] + (s[i - 1] >= 'A' && s[i - 1] <= 'Z' ? 1 : 0);
  if (a[n] == n || a[n] == 0) {
    cout << 0;
    return 0;
  }
  for (int i = 0; i <= n; i++) {
    int m = (i - a[i]) + (a[n] - a[i]);
    min1 = min(min1, m);
  }
  cout << min1 << endl;
  return 0;
}

XyZxYzX
```

Each of these inputs is a non-empty string consisting of uppercase and lowercase letters, with a length of at most 40 tokens.

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

public class Problem {
    public static void main(String[] args) throws IOException{
      new Problem().run();
    }
     StreamTokenizer in;
   PrintWriter out;

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

   void run() throws IOException
   {
      in = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));
      out = new PrintWriter(new OutputStreamWriter(System.out));
      solve();
      out.flush();
   }
   void solve() throws IOException   {
       in.nextToken();
       char[] text=in.sval.toCharArray();
       int[] count = new int[text.length + 1];
        for(int i = 0; i < text.length; i++)
            if (Character.isLowerCase(text[i]))
                count[i + 1] = count[i]+1;
            else
                count[i + 1] = count[i];
        int ans = text.length;
        for (int i = 0; i <= text.length; i++) {
            int change = count[i] + (text.length - i - (count[text.length] - count[i]));
            ans = Math.min(ans, change);
        }
        out.println(ans);
   }
}


import java.util.*;
public class a {
	public static void main(String args[]) {
		Scanner in = new Scanner(System.in);
		int N = in.nextInt();
		int M = in.nextInt();
		int X = in.nextInt();
		int Y = in.nextInt();

		int[] soldiers = new int[N];

		for(int i = 0; i < N; i++)
			soldiers[i] = in.nextInt();

		int at = 0;
		int count = 0;
		ArrayList<Integer> s = new ArrayList<Integer>();
		ArrayList<Integer> v = new ArrayList<Integer>();
		for(int i = 0; i < M; i++) {
			int vest = in.nextInt();
			if(at == N)
				continue;
			while(soldiers[at] + Y < vest && at + 1 < N)
				at++;
			if(soldiers[at] - X <= vest && soldiers[at] + Y >= vest) {
				s.add(at+1);
				v.add(i+1);
				at++;
			}
		}

		System.out.println(s.size());
		for(int i = 0; i < s.size(); i++) {
			System.out.println(s.get(i).intValue() + " " + v.get(i).intValue());
		}
	}
}

#include <bits/stdc++.h>
using namespace std;
int n, m, x, y;
int a[111111], b[111111];
int p, q;
vector<pair<int, int> > ans;
bool fits(int man, int suit) {
  if (suit >= man - x && suit <= man + y) return true;
  return false;
}
int main() {
  scanf("%d%d%d%d", &n, &m, &x, &y);
  for (int i = 0; i < n; i++) scanf("%d", &a[i]);
  for (int i = 0; i < m; i++) scanf("%d", &b[i]);
  p = q = 0;
  ans.clear();
  while (p < n && q < m) {
    if (fits(a[p], b[q])) {
      p++;
      q++;
      ans.push_back(make_pair(p, q));
      continue;
    }
    if (p == n)
      q++;
    else if (q == m)
      p++;
    else if (a[p] < b[q])
      p++;
    else
      q++;
  }
  printf("%d\n", ans.size());
  for (int i = 0; i < ans.size(); i++)
    printf("%d %d\n", ans[i].first, ans[i].second);
  return 0;
}


import java.util.StringTokenizer;
import java.util.regex.*;
import java.io.*;
public class Task145A {

	PrintWriter out;
	BufferedReader input;
	Task145A() {
		input = new BufferedReader(new InputStreamReader(System.in));
		out = new PrintWriter(System.out);
		try {
			solver();
		} catch(IOException ex) {}
		out.close();
	}
	public void solver() throws IOException{
		String text = input.readLine();
		text = text.replaceAll("\\s+", " ");
		text = text.replaceAll("(\\s*,\\s*|,)", ", ");
		text = text.replaceAll("(\\s*[?]+\\s*|\\b[?]+\\b)", "? ");
		text = text.replaceAll("(\\s*[!]+\\s*|\\b[!]+\\b)", "! ");
		text = text.replaceAll("(\\s*[.]+\\s*|\\b[.]+\\b)", ". ");
		System.out.println(text);
	}
	public static void main(String[] args) {
		new Task145A();
	}

}

mck  . gq   dauqminf      wee   bazyzy     humnv    d pgtvx  , vxntxgrkrc    rg    rwr,  uuyweyz  l

galileo galilei was an   italian physicist  ,mathematician,astronomer

gg    gg,h,h,j,i,jh   , jjj ,  jj ,aadd , jjj jjj

mck. gq dauqminf wee bazyzy humnv d pgtvx, vxntxgrkrc rg rwr, uuyweyz l

galileo galilei was an italian physicist, mathematician, astronomer

gg gg, h, h, j, i, jh, jjj, jj, aadd, jjj jjj

import re
s = input()+"a"
s = re.sub('\s+', ' ', s)
r = '.,?!'
for i in r:
    t = s.split(i)
    s = ""
    for j in t:
        s += j.strip() + i + " "
    s = s[:-2]
print(s[:-1])


import string

alphabet = string.ascii_lowercase

n = int(input())

for i in range(n):
  s = list(input())
  if len(s) > 26 or len(s) > len(set(s)):
    print("No")
  else:
    s.sort()
    ind = alphabet.index(s[0])
    if alphabet[ind+len(s)-1] == s[-1]:
      print("Yes")
    else:
      print("No")

21
nop
qrs
tuv
wxyz
abcde
fghij
klmnop
qrstuv
wxyzab
cdefg

25
t
uvwxy
zabcde
fghijkl
mnopqrst
uvwxyzab
cdefghijk
lmnopqrstu
vwxyzabcdef

22
op
rst
uvw
xyza
bcdef
ghijk
lmnopq
rstuvw
xyzabc
defghi

13
fghij
klmno
pqrst
uvwxy
zabcde
fghij
klmno
pqrst
uvwxy

20
mno
pqr
stu
vwxy
zabc
defg
hijk
lmnop
qrstu

14
ghijk
lmnop
qrstu
vwxyz
abcde
fghij
klmno
pqrst
uvwxy
zabcd

23
pq
rstu
vwxyz
abcde
fghijk
klmnop
qrstuvw
xyzabcde
fghijkl

10
bcdef
ghijk
lmnop
qrstu
vwxyz
abcde
fghij
klmno
pqrst

16
ijklm
nopqr
stuvw
xyzab
cdefg
hijkl
lmnop
qrstu
vwxyz
abcde

28
w
xyzabc
defghijk
lmnopqrstuvwxyzabcd
e
fghijklmnopqrstuvwxyzabcde
f
ghijklmnopqrstuvwxyzabcdef
g
hijklmnopqrstuvwxyzabcdefg

19
lmno
pqrs
tuvw
xyzab
cdefg
hijkl
mnopq
rstuv
wxyza
bcdef

27
v
wxyzab
cdefghi
jklmnopqrstu
vwxyzabcdefghijk
lmnopqrstuvwxyzabc

26
u
vwxyz
abcde
fghijklm
nopqrstuv
wxyzabcdefg
hijklmnopqrst
vwxyzabcdefghi

17
jklmn
opqrs
tuvwx
yzabc
defgh
ijklm
lmnop
qrstu
vwxyz
abcde

24
rs
tuvw
xyza
bcdefg
hijklm
nopqrs
tuvwxyz
abcdefg
hijklmnop

9
uvwxy
zabcd
efghi
jklmn
opqrs
tuvwx
yzabc

15
hijkl
mnopq
rstuv
wxyza
bcdef
ghijk
lmnop
qrstu
vwxyz
abcde

18
klmno
pqrst
uvwxy
zabcde
fghij
klmno
pqrst
uvwxy
zabcd
efghi

12
efghi
jklmn
opqrs
tuvwx
yzabc
defgh
ijklm
nopqr
stuvw

11
cdefg
hijkl
mnopq
rstuv
wxyza
bcdef
ghijk
lmnop
qrstu

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

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

Yes
No
Yes
Yes
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
Yes
No
Yes
Yes
Yes
Yes
No
Yes
No
No
No
No
No
No
No
No
No
No
No
No

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

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

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

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

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

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

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

#include <bits/stdc++.h>
using namespace std;
priority_queue<long long int, vector<long long int>, greater<int> > q;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n;
  cin >> n;
  while (n--) {
    string s;
    cin >> s;
    sort(s.begin(), s.end());
    for (int i = 0; i < s.length() - 1; i++) {
      if (!(s[i] + 1 == s[i + 1])) {
        cout << "No\n";
        goto l;
      }
    }
    cout << "Yes\n";
  l:;
  }
}