import java.io.*;
import java.util.*;
public class q1
{
  public static void main(String args[])throws IOException
  {
    Scanner in=new Scanner(System.in);
    PrintWriter pw=new PrintWriter(System.out, true);
    int a=in.nextInt();
    int b=in.nextInt();
    int dis=Math.abs(a-b);
    int ma=dis/2;
    int mb=dis/2;
    if(dis%2!=0)
    mb+=1;
    int tot=ma*(ma+1)/2;
    tot+=mb*(mb+1)/2;
    pw.println(tot);
  }
}

#include <bits/stdc++.h>
using namespace std;
int a, b, temp, ans;
int main() {
  cin >> a >> b;
  temp = abs(b - a);
  if (temp % 2 == 0) {
    for (int i = 1; i <= temp / 2; i++) ans += i;
    cout << ans * 2;
  } else {
    for (int i = 1; i <= temp / 2 + 1; i++) {
      ans += i;
    }
    ans *= 2;
    ans -= temp / 2 + 1;
    cout << ans;
  }
}


#include <bits/stdc++.h>
using namespace std;
long long n, k;
long long a[100010];
long long b[100010];
long long BZ[100010][40];
long long Min[100010][40];
long long Sum[100010][40];
int main() {
  scanf("%lld%lld", &n, &k);
  for (long long i = 0; i < n; ++i) scanf("%lld", &BZ[i][0]);
  for (long long i = 0; i < n; ++i) {
    scanf("%lld", &Min[i][0]);
    Sum[i][0] = Min[i][0];
  }
  for (long long i = 1; i < 40; ++i) {
    for (long long j = 0; j < n; ++j) {
      BZ[j][i] = BZ[BZ[j][i - 1]][i - 1];
      Min[j][i] = min(Min[j][i - 1], Min[BZ[j][i - 1]][i - 1]);
      Sum[j][i] = Sum[j][i - 1] + Sum[BZ[j][i - 1]][i - 1];
    }
  }
  for (long long i = 0; i < n; ++i) {
    long long x = 0, y = 2147483647;
    long long d = i;
    long long kk = k;
    for (long long j = 39; j >= 0; --j)
      if (kk >= (1ll << j)) {
        kk -= 1ll << j;
        x += Sum[d][j];
        y = min(y, Min[d][j]);
        d = BZ[d][j];
      }
    printf("%lld %lld\n", x, y);
  }
  return 0;
}

import sys
n, k = map(int, sys.stdin.buffer.readline().decode('utf-8').split())
a = list(map(int, sys.stdin.buffer.readline().decode('utf-8').split()))
b = list(map(int, sys.stdin.buffer.readline().decode('utf-8').split()))

logk = len(bin(k)) - 2
sum_w, sum_w_p = b[:], b[:]
min_w, min_w_p = b[:], b[:]
dest, dest_p = a[:], a[:]

ans_sum, ans_min, pos = [0]*n, b[:], list(range(n))
if k & 1:
    ans_sum = b[:]
    pos = [a[i] for i in range(n)]
k >>= 1

for j in range(1, logk):
    for i in range(n):
        d = dest[i]
        p = 0 if d > i else 1
        dest_p[i] = d
        dest[i] = (dest_p if p else dest)[d]
        sum_w_p[i] = sum_w[i]
        sum_w[i] += (sum_w_p if p else sum_w)[d]
        min_w_p[i] = min_w[i]
        if min_w[i] > (min_w_p if p else min_w)[d]:
            min_w[i] = (min_w_p if p else min_w)[d]

    if k & 1:
        for i in range(n):
            ans_sum[i] += sum_w[pos[i]]
            if ans_min[i] > min_w[pos[i]]:
                ans_min[i] = min_w[pos[i]]
            pos[i] = dest[pos[i]]
    k >>= 1

sys.stdout.buffer.write('\n'.join(
    (str(ans_sum[i]) + ' ' + str(ans_min[i]) for i in range(n))).encode('utf-8'))


#!/usr/bin/python3

import sys
sys.setrecursionlimit(10000)

n = int(input())

a = []

def read(i):
    try:
        1 / (n - i)
        a.append(list(map(int, input().split())))
        read(i + 1);
    except:
        pass

def f(i, j, k):
    try:
        1 / (n - i)
        1 / (n - j)
        1 / (n - k)
        a[j][k] = min(a[j][k], a[j][i] + a[i][k])
        f(i, j, k + 1)
    except:
        try:
            1 / (n - i)
            1 / (n - j)
            f(i, j + 1, 0)
        except:
            try:
                1 / (n - i)
                f(i + 1, 0, 0)
            except:
                pass

def m(i):
    try:
        1 / (n - i)
        return max(max(a[i]), m(i + 1))
    except:
        return 0

read(0)
f(0, 0, 0)
print(m(0))

#include <bits/stdc++.h>
using namespace std;
int main() {
  int maxn = 999999999;
  int m[105][105];
  int n;
  cin >> n;
  for (int i = 0; i < n; i++)
    for (int j = 0; j < n; j++) m[i][j] = maxn;
  for (int i = 0; i < n; i++)
    for (int j = 0; j < n; j++) cin >> m[i][j];
  for (int k = 0; k < n; k++)
    for (int i = 0; i < n; i++)
      for (int j = 0; j < n; j++) {
        if (m[i][j] > m[i][k] + m[k][j]) m[i][j] = m[i][k] + m[k][j];
      }
  int ans = 0;
  for (int i = 0; i < n; i++)
    for (int j = 0; j < n; j++)
      if (m[i][j] < maxn) ans = max(ans, m[i][j]);
  printf("%d\n", ans);
  return 0;
}


#include <bits/stdc++.h>
using namespace std;
int a[15];
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  memset(a, 0, sizeof a);
  for (int i = 1; i <= n; i++) {
    int x;
    scanf("%d", &x);
    a[x]++;
  }
  int ans = 0;
  for (int i = 1; i <= m; i++) {
    for (int j = i + 1; j <= m; j++) {
      ans = ans + a[i] * a[j];
    }
  }
  printf("%d\n", ans);
  return 0;
}

n, m = list(map(int, input().split()))
a = list(map(int, input().split()))
t = 0
for i in range(m):
    cnt = a.count(i + 1)
    t += cnt * (n - cnt)
    n -= cnt
print(t)


#include <bits/stdc++.h>
using namespace std;
string minEquivalent(string s) {
  if (s.length() % 2) return s;
  string s1 = minEquivalent(s.substr(0, s.length() / 2));
  string s2 = minEquivalent(s.substr(s.length() / 2, s.length() / 2));
  if (s1 < s2)
    return s1 + s2;
  else
    return s2 + s1;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  string a, b;
  cin >> a >> b;
  if (minEquivalent(a) == minEquivalent(b)) {
    cout << "YES" << endl;
  } else {
    cout << "NO" << endl;
  }
  return 0;
}

def equals(a, b):
  if (a == b):
    return True

  len_a, len_b = len(a), len(b)

  if (len_a & 1 or len_b & 1):
    return False

  if (len_a == 1):
    return False

  as1 = a[0:len_a//2]
  as2 = a[len_a//2:(len_a//2)*2]
  bs1 = b[:len_b//2]
  bs2 = b[len_b//2:(len_b//2)*2]

  return (equals(as1, bs2) and equals(as2, bs1)) or (equals(as1, bs1) and equals(as2, bs2))

s1 = input()
s2 = input()

if (equals(s1, s2)):
  print("YES")
else:
  print("NO")


import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.InputMismatchException;

public class Main {

	public static void main(String[] args) {
		// TaskA mSol = new TaskA();
		// TaskB mSol = new TaskB();
		// TaskC mSol = new TaskC();
		// TaskD mSol = new TaskD();
		// TaskE mSol = new TaskE();
		TaskF mSol = new TaskF();
		mSol.solve();
		mSol.flush();
		mSol.close();
	}

}

class TaskF {

	public FasterScanner mFScanner;
	public PrintWriter mOut;

	public TaskF() {
		mFScanner = new FasterScanner();
		mOut = new PrintWriter(System.out);
	}

	public void solve() {
		int i, j, k;
		int hpY, atkY, defY;
		int hpM, atkM, defM;
		int h, a, d;
		int nY, nM;
		int res = Integer.MAX_VALUE;
		int temp;
		int hitpoints;
		boolean win;

		hpY = mFScanner.nextInt();
		atkY = mFScanner.nextInt();
		defY = mFScanner.nextInt();
		hpM = mFScanner.nextInt();
		atkM = mFScanner.nextInt();
		defM = mFScanner.nextInt();
		h = mFScanner.nextInt();
		a = mFScanner.nextInt();
		d = mFScanner.nextInt();

		int ratkY = Math.max(0, atkY - defM);
		int ratkM = Math.max(0, atkM - defY);

		for (int attack = 0; attack <= 200; attack++) {

			for (int defence = 0; defence <= 200; defence++) {

				win = false;

				ratkY = Math.max(0, atkY - defM + attack);
				ratkM = Math.max(0, atkM - defY - defence);

				if (ratkY == 0) {
					continue;
				}

				if (ratkM == 0) {
					temp = attack * a + defence * d;
					res = Math.min(res, temp);
					continue;
				}

				nM = (hpM / ratkY) + (hpM % ratkY != 0 ? 1 : 0);
				nY = (hpY / ratkM) + (hpY % ratkM != 0 ? 1 : 0);

				if (nY > nM) {
					temp = attack * a + defence * d;
					res = Math.min(res, temp);
					continue;
				}

				nY = nM * ratkM - hpY;
				nY++;

				temp = nY * h + attack * a + defence * d;
				res = Math.min(res, temp);
			}

		}

//		if (res == Integer.MAX_VALUE)
//			res = 0;

		mOut.println(res);

	}

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

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

class FasterScanner {
	private InputStream mIs;
	private byte[] buf = new byte[1024];
	private int curChar;
	private int numChars;

	public FasterScanner() {
		this(System.in);
	}

	public FasterScanner(InputStream is) {
		mIs = is;
	}

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

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

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

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

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

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

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

}

# HEY STALKER
hp_y, at_y, df_y = map(int, input().split())
hp_m, at_m, df_m = map(int, input().split())
cst_hp, cst_at, cst_df = map(int, input().split())
ans = 2e18
for ati in range(201):
    for dfi in range(201):
        if ati + at_y > df_m:
            k = hp_m // ((at_y + ati) - df_m)
            if hp_m % ((at_y + ati) - df_m) != 0:
                k += 1
            t = max(0, k*(at_m-df_y-dfi) - hp_y+1)
            cost = cst_hp*t + cst_df*dfi + cst_at*ati
            ans = min(ans, cost)
print(ans)


import java.util.*;
public class Study{
	public static boolean ispossible(long mid,long arr[]) {
		long supervisor=0;
		for(int i=0;i<arr.length;i++) {
			if(mid-arr[i]<0)
				return false;
			supervisor+=mid-arr[i];}

		if(supervisor>=mid)
			return true;
		return false;
	}
	public static long bsearch(long arr[],long sum) {
		long l=0;
		long r=sum;
		long answer=sum;
		while(l<=r){
			long mid=(l+r)/2;
			if(ispossible(mid,arr)) {
				answer=mid;
				r=mid-1;}
			else
				l=mid+1;
		}
		return answer;
	}
	public static void main(String args[]) {
		Scanner in=new Scanner(System.in);
		int n=in.nextInt();
		long arr[]=new long[n];
		long sum=0;
		for(int i=0;i<arr.length;i++) {
			arr[i]=in.nextInt();
			sum+=arr[i];}
		long ans=bsearch(arr,sum);
		System.out.println(ans);
	}
}

#include <bits/stdc++.h>
using namespace std;
class sort_map {
 public:
  int num;
  int val;
};
bool myfunc(int a, int b) { return a > b; }
int main() {
  long long n;
  cin >> n;
  vector<long long> input;
  long long mmax = 0, sum = 0;
  for (int i = 0; i < n; i++) {
    long long temp;
    cin >> temp;
    input.push_back(temp);
    sum += temp;
    if (temp > mmax) mmax = temp;
  }
  int e = ceil(sum / (n - 1.0));
  if (e < mmax) e = mmax;
  cout << e;
  return 0;
}


# itne me hi thakk gaye?
n = int(input())
arr = []
for i in range(n):
    arr.append(sorted(input().split()))
to_get = [i-1 for i in list(map(int, input().split()))]
# print(arr)
# print(to_get)
ok = True
checked = ""
for i in to_get:
    if(arr[i][0] > checked):
        curr = arr[i][0]
    else:
        curr = arr[i][1]
    # print(curr, checked)
    if (curr < checked):
        ok = False
        break
    checked = curr
if ok:
    print("YES")
else:
    print("NO")

3
gennady korotkevich
petr mitrichev
gaoyuan chen
3 1 2

10
rean schwarzer
fei claussell
alisa reinford
eliot craig
laura arseid
jusis albarea
machias regnitz
sara valestin
emma millstein
gaius worzel
1 2 3 4 5 6 7 8 9 10

10
rean schwarzer
fei claussell
alisa reinford
eliot craig
laura arseid
jusis albarea
machias regnitz
sara valestin
emma millstein
gaius worzel
2 4 9 6 5 7 1 3 8 10

2 galileo galilei nicolaus copernicus 2 1

3
gennady korotkevich
petr mitrichev
gaoyuan chen
1 2 3

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

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

public class C {

	BufferedReader in;
	StringTokenizer st;
	PrintWriter out;

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

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

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

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

	void solve() throws Exception {
		int n = nextInt();
		String a[] = new String[n];
		String b[] = new String[n];
		String t;
		for (int i = 0; i < n; i++) {
			a[i] = next();
			b[i] = next();
			if (a[i].compareTo(b[i]) > 0) {
				t = a[i];
				a[i] = b[i];
				b[i] = t;
			}
		}

		int p[] = new int[n];
		int r[] = new int[n];

		for (int i = 0; i < n; i++) {
			p[i] = nextInt() - 1;
			r[p[i]] = i;
		}

		String cur = "";

		for (int i = 0; i < n; i++) {
			int ii = p[i];
			if (a[ii].compareTo(cur) > 0)
				cur = a[ii];
			else if (b[ii].compareTo(cur) > 0)
				cur = b[ii];
			else {
				out.println("NO");
				return;
			}
			// System.err.println(cur);
		}

		out.println("YES");

	}

	void run() {
		try {
			Locale.setDefault(Locale.US);
			in = new BufferedReader(new InputStreamReader(System.in));
			out = new PrintWriter(new OutputStreamWriter(System.out));
			solve();
			out.close();
		} catch (Exception e) {
			e.printStackTrace();
			System.exit(1);
		}
	}

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

}


n,m,x,y,z,p=map(int,input().split())
x=x%4
y=y%2
z=z%4
n0,m0=n,m
for i in range(p):
    n,m=n0,m0
    x1,y1=map(int,input().split())
    for j in range(x):
        x1,y1=y1,n-x1+1
        n,m=m,n
    if y==1:
        y1=m-y1+1
#    print(x1,y1)
    for i in range(z):
        x1,y1=m-y1+1,x1
        n,m=m,n
    print(x1,y1)

import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.ArrayDeque;
import java.util.Arrays;
import java.util.InputMismatchException;
import java.util.PriorityQueue;

public class CF {
	static int cmp;
	public static void main(String[] args) {
		FasterScanner sc = new FasterScanner();
		PrintWriter out = new PrintWriter(System.out);
		int H = sc.nextInt();
		int W = sc.nextInt();
		int X = sc.nextInt()%4;
		int Y = sc.nextInt()%2;
		int Z = sc.nextInt()%4;
		int Q = sc.nextInt();
		while(Q-->0){
			int xx = sc.nextInt()-1;
			int yy = sc.nextInt()-1;
			int[] pos = {yy,xx};
			int ch = H;
			int cw = W;
			for(int a=0;a<X;a++){
				pos = clock(pos,ch,cw);
				ch^=cw;
				cw^=ch;
				ch^=cw;
			}
			for(int a=0;a<Y;a++)
				pos = horiz(pos,ch,cw);
			for(int a=0;a<Z;a++){
				pos = counter(pos,ch,cw);
				ch^=cw;
				cw^=ch;
				ch^=cw;
			}
			pos[0]++;
			pos[1]++;
			out.println(pos[1]+" "+pos[0]);
		}
		out.close();
	}

	private static int[] clock(int[] pos, int h, int w) {
		return new int[] {h-pos[1]-1,pos[0]};
	}

	private static int[] horiz(int[] pos, int h, int w) {
		return new int[] {w-pos[0]-1,pos[1]};
	}

	private static int[] counter(int[] pos, int h, int w) {
		return new int[] {pos[1], w-pos[0]-1};
	}

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

		public FasterScanner(){
			stream = System.in;
			//stream = new FileInputStream(new File("dec.in"));

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

		boolean isSpaceChar(int c){
			return c==' '||c=='\n'||c=='\r'||c=='\t'||c==-1;
		}
		boolean isEndline(int c){
			return c=='\n'||c=='\r'||c==-1;
		}
		int nextInt(){
			return Integer.parseInt(next());
		}
		long nextLong(){
			return Long.parseLong(next());
		}
		double nextDouble(){
			return Double.parseDouble(next());
		}
		String next(){
			int c = read();
			while(isSpaceChar(c))
				c=read();
			StringBuilder res = new StringBuilder();
			do{
				res.appendCodePoint(c);
				c=read();
			} while(!isSpaceChar(c));
			return res.toString();
		}
		String nextLine(){
			int c = read();
			while(isEndline(c))
				c=read();
			StringBuilder res = new StringBuilder();
			do{
				res.appendCodePoint(c);
				c = read();
			}while(!isEndline(c));
			return res.toString();
		}

	}

}


import static java.lang.Math.*;
import static java.math.BigInteger.*;
import static java.util.Arrays.*;
import static java.util.Collections.*;

import java.io.*;

public class B {

	final static boolean autoflush = false;

	public B () {
		int N = sc.nextInt();
		sc = null;

		int [] P = new int [2*N];
		for (int i : req(1, N))
			P[i] = i;

		for (int k : req(2, N))
			for (int r : seq(0, (N-1)/k)) {
				int X = r*k + (k-1), Y = min(X+k, N+k-1);
				P[Y] = P[X];
			}

		int [] res = copyOfRange(P, N, 2*N);
		exit(res);
	}

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

	static int [] rep(int N) { return rep(0, N); }
	static int [] rep(int S, int T) { int [] res = new int [max(T-S, 0)]; for (int i = S; i < T; ++i) res[i-S] = i; return res; }
	static int [] req(int S, int T) { return rep(S, T+1); }

	static int [] sep(int N) { return sep(0, N); }
	static int [] sep(int S, int T) { int [] res = new int [max(T-S, 0)]; for (int i = S; i < T; ++i) res[T-i-1] = i; return res; }
	static int [] seq(int S, int T) { return sep(S, T+1); }

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

	/* Dear hacker, don't bother reading below this line, unless you want to help me debug my I/O routines :-) */

	static MyScanner sc = new MyScanner();

	static class MyScanner {
		public String next() {
			readToken();
			return new String(b, T[0], T[1] - T[0]);
		}

		public char nextChar() {
			readToken();
			return (char)b[T[0]];
		}

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

		public long nextLong() {
			readToken();
			return calc(T[0], T[1]);
		}

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

		public String nextLine() {
			readLine();
			return new String(b, T[0], T[1] - T[0]);
		}

		public String [] next(int N) {
			String [] res = new String [N];
			for (int i = 0; i < N; ++i)
				res[i] = next();
			return res;
		}

		public Integer [] nextInt(int N) {
			Integer [] res = new Integer [N];
			for (int i = 0; i < N; ++i)
				res[i] = nextInt();
			return res;
		}

		public Long [] nextLong(int N) {
			Long [] res = new Long [N];
			for (int i = 0; i < N; ++i)
				res[i] = nextLong();
			return res;
		}

		public Double [] nextDouble(int N) {
			Double [] res = new Double [N];
			for (int i = 0; i < N; ++i)
				res[i] = nextDouble();
			return res;
		}

		public String [] nextLine(int N) {
			String [] res = new String [N];
			for (int i = 0; i < N; ++i)
				res[i] = nextLine();
			return res;
		}

		public String [] nextStrings() {
			readLine();
			int s = T[0], c = 0;
			String [] res = new String[count(T[0], T[1])];
			for (int i = T[0]; i < T[1]; ++i)
				if (b[i] == SPACE) {
					res[c++] = new String(b, s, i - s);
					s = i+1;
				}
			res[c] = new String (b, s, T[1] - s);
			return res;
		}

		public char [] nextChars() {
			readToken();
			int c = 0;
			char [] res = new char[T[1] - T[0]];
			for (int i = T[0]; i < T[1]; ++i)
				res[c++] = (char)b[i];
			return res;
		}

		public Integer [] nextInts() {
			readLine();
			int s = T[0], c = 0;
			Integer [] res = new Integer[count(T[0], T[1])];
			for (int i = T[0]; i < T[1]; ++i)
				if (b[i] == SPACE) {
					res[c++] = (int)calc(s, i);
					s = i+1;
				}
			res[c] = (int)calc(s, T[1]);
			return res;
		}

		public Long [] nextLongs() {
			readLine();
			int s = T[0], c = 0;
			Long [] res = new Long[count(T[0], T[1])];
			for (int i = T[0]; i < T[1]; ++i)
				if (b[i] == SPACE) {
					res[c++] = calc(s, i);
					s = i+1;
				}
			res[c] = calc(s, T[1]);
			return res;
		}

		public Double [] nextDoubles() {
			readLine();
			int s = T[0], c = 0;
			Double [] res = new Double[count(T[0], T[1])];
			for (int i = T[0]; i < T[1]; ++i)
				if (b[i] == SPACE) {
					res[c++] = Double.parseDouble(new String(b, s, i - s));
					s = i+1;
				}
			res[c] = Double.parseDouble(new String(b, s, T[1] - s));
			return res;
		}

		String [][] nextStrings(int N) {
			String [][] res = new String [N][];
			for (int i = 0; i < N; ++i)
				res[i] = nextStrings();
			return res;
		}

		char [][] nextChars(int N) {
			char [][] res = new char [N][];
			for (int i = 0; i < N; ++i)
				res[i] = nextChars();
			return res;
		}

		Integer [][] nextInts(int N) {
			Integer [][] res = new Integer [N][];
			for (int i = 0; i < N; ++i)
				res[i] = nextInts();
			return res;
		}

		Long [][] nextLongs(int N) {
			Long [][] res = new Long [N][];
			for (int i = 0; i < N; ++i)
				res[i] = nextLongs();
			return res;
		}

		Double [][] nextDoubles(int N) {
			Double [][] res = new Double [N][];
			for (int i = 0; i < N; ++i)
				res[i] = nextDoubles();
			return res;
		}

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

		private final static int MAX_SZ = (1 << 26);
		private final byte [] b = new byte[MAX_SZ];
		private final int [] T = new int [2];
		private int cur = 0;

		MyScanner () {
			try {
				InputStream is = new BufferedInputStream(System.in);
				while (is.available() == 0)
					Thread.sleep(1);
				start();
				int off = 0, c;
				while ((c = is.read(b, off, MAX_SZ - off)) != -1)
					off += c;
			} catch (Exception e) {
				throw new Error(e);
			}
		}

		private void readLine() {
			int c;
			for (c = cur; b[c] != LF && b[c] != CR && b[c] != 0; ++c);
			T[0] = cur; T[1] = c;
			for (cur = c; b[cur] == LF || b[cur] == CR; ++cur);
		}

		private void readToken() {
			int c;
			for (c = cur; b[c] != SPACE && b[c] != LF && b[c] != CR && b[c] != 0; ++c);
			T[0] = cur; T[1] = c;
			for (cur = c; b[cur] == SPACE || b[cur] == LF || b[cur] == CR; ++cur);
		}

		private int count(int s, int e) {
			int cnt = 1;
			for (int i = s; i < e; ++i)
				if (b[i] == SPACE)
					++cnt;
			return cnt;
		}

		private long calc(int s, int e) {
			long res = 0, f = 1;
			for (int i = s; i < e; ++i)
				if (b[i] == '-')
					f = -1;
				else
					res = 10 * res + b[i] - '0';
			return res * f;
		}

		private static final char LF = '\n';
		private static final char CR = '\r';
		private static final char SPACE = ' ';
	}

	static void print (Object o, Object... a) {
		printDelim(" ", o, a);
	}

	static void cprint (Object o, Object... a) {
		printDelim("", o, a);
	}

	static void printDelim (String delim, Object o, Object... a) {
		pw.println(build(delim, o, a));
	}

	static void exit (Object o, Object... a) {
		print(o, a);
		exit();
	}

	static void exit() {
		pw.close();
		System.out.flush();
		System.err.println("------------------");
		System.err.println("Time: " + ((millis() - t) / 1000.0));
		System.exit(0);
	}

	static void NO() {
		throw new Error("NO!");
	}

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

	static String build (String delim, Object o, Object... a) {
		StringBuilder b = new StringBuilder();
		append(b, o, delim);
		for (Object p : a)
			append(b, p, delim);
		return b.toString().trim();
	}

	static void append(StringBuilder b, Object o, String delim) {
		if (o.getClass().isArray()) {
			int L = java.lang.reflect.Array.getLength(o);
			for (int i : rep(L))
				append(b, java.lang.reflect.Array.get(o, i), delim);
		} else if (o instanceof Iterable<?>)
			for (Object p : (Iterable<?>)o)
				append(b, p, delim);
		else
			b.append(delim).append(o);
	}

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

	static void statics() {
		abs(0);
		valueOf(0);
		asList(new Object [0]);
		reverseOrder();
	}

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

	static void start() {
		t = millis();
	}

	static java.io.PrintWriter pw = new java.io.PrintWriter(System.out, autoflush);

	static long t;

	static long millis() {
		return System.currentTimeMillis();
	}
}

#include <bits/stdc++.h>
using namespace std;
const int di[] = {-1, 0, 1, 0};
const int dj[] = {0, 1, 0, -1};
const long long MOD = 1e9 + 7;
const long long INF = 1e9;
const double EPS = 1e-5;
int main() {
  ios::sync_with_stdio(false), cin.tie(0);
  int n;
  cin >> n;
  deque<int> num(n);
  for (int i = 0; i < n; i++) num[i] = i + 1;
  for (int shft = 2; shft <= n; shft++) {
    int last = num[0];
    for (int i = shft; i < n; i += shft) swap(num[i], last);
    num.pop_front();
    num.push_back(last);
  }
  for (int i = 0; i < n; i++) cout << num[i] << " \n"[i == n - 1];
  cin.ignore(), cin.get();
}


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

#--------------------#
#INCLUDE <HajLorenzo>
#INCLUDE <MUSIC.H>
#Mitchell Broom - Ascension
#--------------------#
_=list(map(int,input().split()))
__=True
____="WTF"
for _i_ in range(_[0]):
    ___=input()
    if((___.count(___[0])!=_[1]) or (___[0]==____)):__=False
    ____=___[0]

print("YES" if(__) else "NO")

'''UseFull Code
a=list(map(int,input().split()))
print("Yes" if() else "No")
def func(a):
    return a
'''


import math

def issqr(x):
    root = int(math.sqrt(x))
    return root*root == x

for i in range(int(input())):
    n = int(input())
    print("YES" if (n % 4 == 0 and issqr(n//4)) or (n % 2 == 0 and issqr(n//2)) else "NO")

NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO

#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define se second
#define fi first
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<int,pii> piii;
typedef pair<ll,ll> pll;
typedef pair<ll,pll> plll;
typedef std::vector<int> vi;
typedef vector<ll> vl;
typedef std::vector<pii> vpi;
typedef std::vector<piii> vpii;
typedef std::vector<pll> vpl;
typedef std::vector<plll> vpll;

int main()
{
    ll i,j,k,l,m,n,a,b,c,d,u,v,w,t=1;
    cin>>t;
    while(t--){
        cin>>n;
        u=0,v=0;
        m=n;
        if(n%2==0){
        n=n/2;
        u=sqrt(n);}
        if(n%2==0){
            m=n/2;
            v=sqrt(m);
        }
        if(u*u==n||v*v==m)
        cout<<"YES\n";
        else
        cout<<"NO\n";
    }
}


t=int(input())
for i in range(t):
    p,a,b,c=map(int,input().split())
    if(p%a==0 or p%b==0 or p%c==0):
        print(0)
    else:
        a1=a-p%a
        b1=b-p%b
        c1=c-p%c
        print(min(a1,b1,c1))

#include<bits/stdc++.h>
using namespace std;

int main()
{
    int t;
    cin >> t;
    while(t--){
        long long int a,b,c,p,m,a1,a2,a3;
        cin >> p >> a >> b >> c;

        a1=((p+a-1)/a)*a;
        a2=((p+b-1)/b)*b;
        a3=((p+c-1)/c)*c;

        if(a1<=a2 && a1<=a3){
            m=a1-p;
        }
        else if(a2<=a1 && a2<=a3){
             m=a2-p;
        }
        else{
            m=a3-p;
        }
        cout << m << endl;
    }

    return 0;
}


#!/usr/bin/env python3
import sys
input = sys.stdin.readline

n, q = [int(item) for item in input().split()]
block = [[0] * (n + 6) for _ in range(2)]
wall = 0
for _ in range(q):
    x, y = [int(item) - 1 for item in input().split()]
    y += 3
    invx = (x + 1) % 2
    if block[x][y]:
        block[x][y] = 0
        wall -= block[invx][y-1] + block[invx][y] + block[invx][y+1]
    else:
        block[x][y] = 1
        wall += block[invx][y-1] + block[invx][y] + block[invx][y+1]
    if wall > 0:
        print("No")
    else:
        print("Yes")

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

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

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

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

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

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

import static java.lang.Math.*;

public class A {

    //
    public static class Cell {
        int x;
        int y;

        public Cell(int x, int y) {
            this.x = x;
            this.y = y;
        }

        @Override
        public boolean equals(Object o) {
            if (this == o) return true;
            if (o == null || getClass() != o.getClass()) return false;

            Cell cell = (Cell) o;

            if (x != cell.x) return false;
            return y == cell.y;

        }

        @Override
        public int hashCode() {
            int result = x;
            result = 31 * result + y;
            return result;
        }
    }

    public static void main(String[] args) {

        MyScanner in = new MyScanner();
        int n = in.nextInt();
        int q = in.nextInt();

        PrintWriter pw = new PrintWriter(System.out);

        Set<Cell> blocked = new HashSet<>();
        Set<Cell> filled = new HashSet<>();

        for (int i = 0; i < q; ++i) {
            int y = in.nextInt() - 1;
            int x = in.nextInt() - 1;

            Cell c = new Cell(x, y);
            if (filled.contains(c)) {
                filled.remove(c);
            }else{
                filled.add(c);
            }
            update(c, filled, blocked);
            pw.println(blocked.size() != 0 ? "No" : "Yes");
        }
        pw.close();

    }

    private static void update(Cell c, Set<Cell> filled, Set<Cell> blocked) {
        for (int nx = c.x - 1; nx <= c.x + 1; ++nx) {
            for (int ny = 0; ny <= 1; ++ny) {
                Cell nc = new Cell(nx, ny);
                blocked.remove(nc);

                if (filled.contains(nc)) {
                    for(int i=-1;i<=1;++i){
                        for(int j=-1;j<=1;++j){
                            if(i==0 && j==0){
                                continue;
                            }
                            if(j==0){
                                continue;
                            }
                            Cell blockingCell = new Cell(nx + i, ny + j);
                            if(filled.contains(blockingCell)){
                                blocked.add(nc);
                                blocked.add(blockingCell);
                            }
                        }
                    }
                }
            }
        }
    }

    // -----------MyScanner class for faster input----------
    public static class MyScanner {
        BufferedReader br;
        StringTokenizer st;

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

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

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

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

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

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

    }
    // --------------------------------------------------------

}


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

public class Codechef
{
	public static void main(String args[]) throws NumberFormatException, IOException
	{
		    BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
			int n=Integer.parseInt(br.readLine());

			long ans=0;
			long arr[]=new long[n];
			String []line=br.readLine().split(" ");
			for(int i=0;i<n;i++)
			{
				arr[i]=Long.parseLong(line[i]);
			}
			Arrays.sort(arr);
			long count2=0,zero=0;
			int flag=0;
			for(int i=0;i<n;i++)
			{
				if(arr[i]>i)
				{
					ans+=arr[i]-i;
				}
				if(i>=2 && arr[i]==arr[i-1] && arr[i-1]==arr[i-2])
				{
					flag=1;
				}
				if(i>=1 && (arr[i]==arr[i-1]))
				{
					count2++;
				}
				if(i>=2 && arr[i]==arr[i-1] && arr[i-1]==arr[i-2]+1)
				{
					flag=1;
				}

			}
			if(n>1)
			{
				if((arr[0]==arr[1] && arr[0]==0) ||(count2>=2))
				{
					flag=1;
				}
			}

			if(flag==1)
				System.out.println("cslnb");
			else
			{
				if(ans%2==0)
					System.out.println("cslnb");
				else
					System.out.println("sjfnb");
			}

	}

}

cslnb sjfnb cslnb cslnb sjfnb cslnb cslnb cslnb

def find(A):
    from collections import defaultdict
    A=sorted(A)
    N=len(A)
    dic=defaultdict(int)
    for i in range(N):
        dic[A[i]]+=1

    checked=[]
    count=set([])
    for x in A:
        if dic[x]>2:
            return "cslnb"
        if dic[x]==2:
            count.add(x)
            y=x-1
            if y in dic:
                return "cslnb"
    if len(count)>1:
        return "cslnb"

    if 0 in count:
        return "cslnb"

    temp=0
    for i in range(N):
        temp+=A[i]-i
    if temp%2==1:
        return "sjfnb"
    return "cslnb"
input()
A=list(map(int,input().strip().split(' ')))
print(find(A))


from bisect import bisect_left as bl, bisect_right as br, insort
import sys
import heapq
# from math import *
from collections import defaultdict as dd, deque
def data(): return sys.stdin.readline().strip()
def mdata(): return map(int, data().split())
# sys.setrecursionlimit(1000000)
mod = 998244353

n=int(data())
s=data()
s1=list(s)
d={'0':0,'1':0,'2':0}
for i in range(n):
    d[s[i]]+=1
t=n//3
if d['0']<t:
    k='0'
for i in range(n):
    if d[s1[i]]>t:
        for j in sorted(d.keys()):
            if d[j]<t and j<s1[i]:
                d[j]+=1
                d[s1[i]] -= 1
                s1[i]=j
                break
for i in range(n-1,-1,-1):
    if d[s1[i]]>t:
        for j in sorted(d.keys(),reverse=True):
            if d[j]<t and j>s1[i]:
                d[j]+=1
                d[s1[i]] -= 1
                s1[i]=j
                break
print(''.join(s1))


d = {'a': 0, 'b': 1}
def process(s, t, k):
    n = len(s)
    answer = 0
    D = 0
    final_i = n
    for i in range(n):
        d1 = d[s[i]]
        d2 = d[t[i]]
        D = 2*(D)+d2-d1
        if D+1 < k:
            answer+=(D+1)
        else:
            final_i = i
            break
    answer+=k*(n-final_i)
    return answer

n, k = [int(x) for x in input().split()]
s = input()
t = input()
print(process(s, t, k))

33 34 aaaaabaabaaaabaaaabaa bbbbaabaabaaabaaaabaaa

35 36 aaaaabaabaaaabaaaabaa bbbbaabaabaaabaaaabaaa

21 22 aaaaabaabaaaabaaaab bbbbaabaabaaabaaaab

28 29 aaaaabaaabaabaaaabaaa bbbbaabaabaaabaaaabaaa

32 33 aaaaabaaabaabaaaabaaa bbbbaabaabaaabaaaabaaa

36 37 aaaaabaaabaabaaaabaaa bbbbaabaabaaabaaaabaaa

24 25 aaaaabaaabaabaaaabaaa bbbbaabaabaaabaaaabaaa

23 24 aaaaabaabaaaabaaaaba bbbbaabaabaaabaaaabaa

26 27 aaaaabaaabaabaaaabaaa bbbbaabaabaaabaaaabaaa

29 30 aaaaabaabaaaabaaaabaa bbbbaabaabaaabaaaabaaa

22 23 aaaaabaaabaabaaaabaa bbbbaabaabaaabaaaaba

20 21 aaaaabaaabaabaaaab bbbbaabaabaaabaaa

37 38 aaaaabaabaaaabaaaabaa bbbbaabaabaaabaaaabaaa

31 32 aaaaabaabaaaabaaaabaa bbbbaabaabaaabaaaabaaa

34 35 aaaaabaaabaabaaaabaaa bbbbaabaabaaabaaaabaaa

30 31 aaaaabaaabaabaaaabaaa bbbbaabaabaaabaaaabaaa

27 28 aaaaabaabaaaabaaaabaa bbbbaabaabaaabaaaabaaa

25 26 aaaaabaabaaaabaaaabaa bbbbaabaabaaabaaaabaaa

#include <bits/stdc++.h>
using namespace std;
const int N = 5e5 + 1;
int c[N];
int main() {
  int i, j, n, k;
  string s, t, s1, t1;
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> k;
  cin >> s >> t;
  if (s == t || k == 1) {
    cout << n;
    return 0;
  }
  for (i = 0; i < s.size(); ++i)
    if (s[i] != t[i]) break;
  while (i < s.size()) {
    s1 += s[i];
    t1 += t[i];
    ++i;
  }
  long long ans = n - s1.size() + 2;
  c[0] = 0;
  for (i = 1; i < s1.size(); ++i) {
    c[i] = c[i - 1] * 2;
    if (s1[i] == 'a') ++c[i];
    if (t1[i] == 'b') ++c[i];
    c[i] = min(c[i], k);
    ans += min(c[i] + 2, k);
  }
  cout << ans;
}


#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 2;
const int M = 1e9 + 7;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long n, m;
  cin >> n >> m;
  vector<pair<int, int> > v(n);
  long long nw = 0, cw = 0;
  for (int i = 0; i < n; i++) {
    cin >> v[i].first >> v[i].second;
    nw += v[i].first;
    cw += v[i].second;
  }
  sort(v.begin(), v.end(),
       [](const pair<int, int> p1, const pair<int, int> p2) {
         int x = p1.first - p1.second;
         int y = p2.first - p2.second;
         return x > y;
       });
  if (nw <= m) {
    cout << 0;
  } else if (cw > m) {
    cout << -1;
  } else {
    long long yo = nw;
    int ans = 0;
    for (int i = 0; i < n; i++) {
      if (yo - v[i].first + v[i].second > m) {
        ans++;
        yo = yo - v[i].first + v[i].second;
      } else {
        ans++;
        break;
      }
    }
    cout << ans;
  }
  return 0;
}

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

songs=list()

for i in range(n):
    songs.append([int(c) for c in input().split()])

def sumList(lista,inx):
    sum=0
    for i in range(len(lista)):
        sum+=lista[i][inx]
    return sum

songs=sorted(songs,key=lambda x: x[1]-x[0])

suma = sumList(songs,0)

for i in range(n):
    if(suma<=m):
        print(i)
        exit()
    suma-= songs[i][0]-songs[i][1]

if(suma<=m):
    print(n)
else:
    print(-1)


n = int(input())

res = []

def sum_digits(x):
    return sum([int(i) for i in x])

for i in range(max(0, n - 80), n):
    # print(sum_digits(str(i)))
    if i + sum_digits(str(i)) == n:
        res.append(i)

print(len(res))

if len(res) != 0:
    for r in sorted(res):
        print(r)

#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  scanf("%d", &n);
  vector<int> ans;
  for (int i = 1; i <= 81; i++) {
    int p = n - i, s = 0;
    while (p) {
      s += (p % 10);
      p /= 10;
    }
    if (s == i) {
      ans.push_back(n - i);
    }
  }
  sort(ans.begin(), ans.end());
  cout << ans.size() << endl;
  for (int i = 0; i < ans.size(); i++) {
    cout << ans[i] << endl;
  }
}


n = int(input())
p = list(map(int, input().split()))
b = list(map(int, input().split()))
s = sum(b[i] for i in range(n))
if s % 2 == 0:
    ans = 1
else:
    ans = 0
visited = [0] * n
ptr = 0
start = 1
visited[0] = 1
q = 1
c = 1
while q < n:
    start = p[start - 1]
    if visited[start - 1] == 1:
        c += 1
        while ptr < n and visited[ptr] == 1:
            ptr += 1
        start = ptr + 1
    else:
        visited[start - 1] = 1
        q += 1
if c == 1:
    print(ans)
else:
    print(ans + c)

#include <bits/stdc++.h>
using namespace std;
const double PI = 3.141592653589793238;
long long powmod(long long a, long long b) {
  long long res = 1;
  a %= 1000000007;
  for (; b; b >>= 1) {
    if (b & 1) res = res * a % 1000000007;
    a = a * a % 1000000007;
  }
  return res;
}
vector<int> vec[200005];
bool vis[200005];
void dfs(int node) {
  vis[node] = true;
  for (int i = 0; i < vec[node].size(); i++) {
    int Node = vec[node][i];
    if (!vis[Node]) {
      dfs(Node);
    }
  }
}
int main() {
  int n, ans, cnt, v;
  ans = cnt = 0;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &v);
    vec[i].push_back(v);
  }
  for (int i = 1; i <= n; i++) {
    scanf("%d", &v);
    if (v) cnt++;
  }
  for (int i = 1; i <= n; i++) {
    if (!vis[i]) {
      dfs(i);
      ans++;
    }
  }
  if (ans == 1) ans = 0;
  ans += (cnt & 1 ? 0 : 1);
  printf("%d\n", ans);
  return 0;
}


"""
 second a and then the next word at second b, then if b - a ≤ c,
 just the new word is appended to other words on the screen.

 If b - a > c, then everything on the screen disappears and after that the word
 you have typed appears on the screen.
"""

num1 = input()
num2 = input()
a = []
b = []

def get_the_data(count, num, arr):
    for i in range(0, len(num)):
        if num[i] == ' ':
            arr.append(int(num[count:i]))
            count = i+1
        elif i == len(num)-1:
            arr.append(int(num[count:len(num)]))
    return arr

arr1 = get_the_data(0, num1, a)
arr2 = get_the_data(0, num2, b)

time = arr1[1]
char = 0
for i in range(len(arr2)):
    if i == 0:
        # first word can be clicked anytime
        char += 1
    else:
        if arr2[i] - arr2[i-1] <= time:
            char += 1
        else:
            char = 1

print(char)

#include <bits/stdc++.h>
const long long MOD = 1000000007;
int main() {
  long long n, c;
  std::cin >> n >> c;
  std::vector<long long> t(n, 0);
  long long ans = 0;
  for (int i = 0; i < n; ++i) {
    std::cin >> t[i];
    ++ans;
    if (i > 0) {
      if (t[i] > t[i - 1] + c) {
        ans = 0;
        ++ans;
      }
    }
  }
  std::cout << ans << std::endl;
  return 0;
}


import java.util.Scanner;

public class Main {
    public static void main(String [] argv){
        Scanner in = new Scanner(System.in);
        int n;
        int [] x = new int [1200];
        while(in.hasNext())
        {
            n = in.nextInt();
            for(int i = 0; i < n; ++i)
                x[i] = in.nextInt();
            int ans = 0;
            for(int i = 0; i < n; ++i)
            {
                if(x[i] == 1)
                    ans ++;
            }
            if(n == 1)
            {
                if(ans == 1)
                    System.out.println("YES");
                else
                    System.out.println("NO");
            }
            else
            {
                if(ans + 1 == n)
                    System.out.println("YES");
                else
                    System.out.println("NO");
            }
        }
        in.close();
    }
}

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

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


n = int(input())

rects = [int(s) for s in input().split()]
rects.sort()

sumsquare = 0
stash = []

i = len(rects) - 1

while i > 0:
	if rects[i] - rects[i-1] == 1 or rects[i] == rects[i-1]:
		if len(stash) == 2:
			sumsquare += stash[0]*stash[1]
			stash.clear()

		stash.append(rects[i-1])
		rects.pop()
		rects.pop()

		i -= 2
	else:
		i -= 1

if len(stash) == 2:
	sumsquare += stash[0]*stash[1]
	stash.clear()

print(sumsquare)

#include <bits/stdc++.h>
using namespace std;
bool comp(int a, int b) { return a < b; }
int main() {
  int n, i;
  cin >> n;
  int a[n];
  for (i = 0; i < n; i++) cin >> a[i];
  long long int ans = 0;
  sort(a, a + n, comp);
  vector<int> arr;
  for (i = n - 1; i > 0; i--) {
    if (a[i] - a[i - 1] < 2) {
      arr.push_back(a[i - 1]);
      i--;
    }
  }
  if (arr.size() < 2) {
    cout << ans << endl;
    return 0;
  }
  for (i = 0; i < arr.size() - 1; i += 2) {
    ans += (long long int)arr[i] * arr[i + 1];
  }
  cout << ans << endl;
  return 0;
}


n = int(input())
s = input()+'R'
r = 0
flag = 'L'
a = 0
for _ in range(n+1):
    if s[_] == '.':
        a+=1
    elif s[_] == 'L':
        if flag =='L':
            a = 0
        else:
            if a%2==1:
                r+=1
            a = 0
            flag = 'L'
    else:
        if flag =='L':
            r += a
            a = 0
            flag = 'R'
        else:
            a = 0
    #print(r,a,flag)
print(r)


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

public class A {

	BufferedReader in;
	StringTokenizer st;
	PrintWriter out;

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

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

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

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

	void solve() throws Exception {
		String s = next();
		int cnt[] = new int[10];
		int zc = 0;
		// BigInteger ans = BigInteger.ONE;

		for (int i = 0; i < s.length(); i++) {
			if (Character.isAlphabetic(s.charAt(i)))
				cnt[s.charAt(i) - 'A']++;
			if (s.charAt(i) == '?')
				zc++;
		}

		int dc = 0;
		for (int i = 0; i < 10; i++) {
			if (cnt[i] > 0)
				dc++;
		}

		int ans = 10;
		if (s.charAt(0) == '?') {
			ans = 9;
			zc--;
			for (int i = 0; i < dc; i++)
				ans *= 10 - i;
		}
		if (Character.isAlphabetic(s.charAt(0))) {
			ans--;
			for (int i = 1; i < dc; i++)
				ans *= 10 - i;
		}
		if (Character.isDigit(s.charAt(0))) {
			ans = 1;
			for (int i = 0; i < dc; i++)
				ans *= 10 - i;
		}
		out.print(ans);
		for (int i = 0; i < zc; i++)
			out.print(0);
	}

	void run() {
		try {
			Locale.setDefault(Locale.US);
			in = new BufferedReader(new InputStreamReader(System.in));
			out = new PrintWriter(new OutputStreamWriter(System.out));
			solve();
			out.close();
		} catch (Exception e) {
			e.printStackTrace();
			System.exit(1);
		}
	}

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

}

Input: 000A
9???
Input: 0A0?A
Input: 00A?A0
Input: 000?0A
Input: 0A?0A
?C
Input: 00AA
Input: A?
Input: 0A0?
Input: ???
Input: 00A
Input: 0A?0A
?H2?H
Input: 00A0
Input: 0A0A0
AJ
Input: 000
Input: 0A?0
Input: 0?A
Input: 00A?
Input: 00A0A0
Input: 00?0A
Input: 000?
Input: 00?A0
Input: 0A0A?
Input: ?A
Input: 00AA0
Input: 00A0?
Input: 000?A0
Input: 00A?0A
Input: 00?A
HH???
Input: 0A?A
Input: 00A0A?
Input: AAA
Input: 0A0
B??C?
Input: 00?0
Input: 0A0AA
Input: 0A?A0
Input: 00?
??JG?
Input: 000A0A
Input: 00A0A
Input: 000A0?
1?AA
Input: 0??
Input: 0A?A0
Input: 000A?

#include <bits/stdc++.h>
using namespace std;
long long cal(long long n, long long k) {
  long long ret = 1;
  while (n--) ret *= k--;
  return ret;
}
char s[100001];
bool vit[10];
int main() {
  long long n, i, q = 0, num = 0, ret;
  scanf("%s", s);
  n = strlen(s);
  for (i = 0; i < n; i++) {
    q += s[i] == '?';
    if ('A' <= s[i] && s[i] <= 'J') vit[s[i] - 'A'] = true;
  }
  for (i = 0; i < 10; i++) num += vit[i];
  if (s[0] == '?') {
    ret = 9 * cal(num, 10);
    q--;
  } else if ('A' <= s[0] && s[0] <= 'J') {
    ret = 9 * cal(num - 1, 9);
  } else {
    ret = cal(num, 10);
  }
  for (i = 0; i < q; i++) s[i] = '0';
  s[q] = '\0';
  printf("%lld%s", ret, s);
  return 0;
}


#start the code from here
n=int(input())
global parent
parent=[i for i in range(n)]
# n is total number of nodes
# finding parent of a node
def find(w):
	global parent
	if parent[w]==w:
			return w
	else:
		return find(parent[w])

def union(a,b):
	global parent
	w=find(a)
	y=find(b)
	if w==y:
		return
	parent[y]=w

#start the code from here
l=[]
ans=0
for i in range(n):
	a,b=map(int,input().split())
	for u in range(len(l)):
		if l[u][0]==a or l[u][1]==b:
			union(u,i)
		else:
			ans+=1
	l.append([a,b])
pset=set()
for i in range(len(l)):
	pset.add(find(i))
print(len(pset)-1)

import java.util.Scanner;
public class e {
    public static boolean[][] f;
    public static boolean[] used;
    public static int n;
    public static void main(String args[]) {
        Scanner in = new Scanner(System.in);

        n = in.nextInt();
        int[] x = new int[n];
        int[] y = new int[n];
        f = new boolean[n][n];

        for (int i=0;i<n;i++) {
            x[i] = in.nextInt();
            y[i] = in.nextInt();
            for (int j=0;j<i;j++) {
                if (x[i] == x[j]) {
                    f[i][j] = true;
                    f[j][i] = true;
                }
                if (y[i] == y[j]) {
                    f[i][j] = true;
                    f[j][i] = true;
                }
            }
        }

        used = new boolean[n];
        int res = 0;

        for (int i=0;i<n;i++) {
            if (!used[i]) {
                res++;
                rec(i);
            }
        }

        System.out.println(res-1);
    }
    public static void rec(int i) {
        used[i] = true;
        for (int j=0;j<n;j++) {
            if (f[i][j] && !used[j]) {
                rec(j);
            }
        }
    }
}


#include <bits/stdc++.h>
using namespace std;
int dx[] = {1, -1, 0, 0};
int dy[] = {0, 0, 1, -1};
int n, m, vis[101][101], cnt;
string s[101];
int dfs(int x, int y) {
  if (x < 0 || x >= n || y < 0 || y >= m || vis[x][y] || s[x][y] == '.')
    return 0;
  vis[x][y] = 1;
  for (int i = 0; i < 4; i++) dfs(x + dx[i], y + dy[i]);
  return 1;
}
void code() {
  cin >> n >> m;
  for (int i = 0; i < n; i++) cin >> s[i];
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      if (s[i][j] == '.') continue;
      cnt++;
      memset(vis, 0, sizeof(vis));
      int tmp = 0;
      s[i][j] = '.';
      for (int k = 0; k < 4; k++) tmp += dfs(i + dx[k], j + dy[k]);
      if (tmp > 1) {
        cout << 1 << '\n';
        return;
      }
      s[i][j] = '#';
    }
  }
  cout << ((cnt < 3) ? -1 : 2) << '\n';
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int t = 1;
  while (t--) {
    code();
  }
}

n, m = map(int, input().split())
p, s = [], {}
x = 0
for i in range(n):
    for j, q in enumerate(input()):
        if q != '#': continue
        s[(i, j)] = x
        p.append([])
        if (i, j - 1) in s:
            p[x] += [x - 1]
            p[x - 1] += [x]
        if (i - 1, j) in s:
            y = s[(i - 1, j)]
            p[x] += [y]
            p[y] += [x]
        x += 1

k = len(p)
if k < 3:
    print(-1)
    exit()

for j in range(k):
    d = [1] * k
    d[j] = 0
    s = [p[j][0]]
    while s:
        j = s.pop()
        if not d[j]: continue
        d[j] = 0
        for i in p[j]:
            if d[i]: s.append(i)

    if 1 in d:
        print(1)
        break

else:
    print(2)


#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
using namespace std;
int main() {
  string str;
  cin >> str;
  if (str.find_first_of("HQ9") != string::npos) {
    cout << "YES" << endl;
  } else {
    cout << "NO" << endl;
  }
}

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

public class Main {
    public static void main(String[] args) {
        String s= new java.util.Scanner(System.in).next();
        if (s.contains("H")||s.contains("Q")||s.contains("9"))
            System.out.println("YES");
        else
            System.out.println("NO");
    }
}


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

/* package codechef; // don't place package name! */

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

/* Name of the class has to be "Main" only if the class is public. */

public class Codechef
{
    public static long sum(long n)
{
    return (n*(n+1))/2;
}
	public static void main (String[] args) throws java.lang.Exception
	{
		 Scanner ob=new Scanner(System.in);
         long n=ob.nextLong();
         long k=ob.nextLong();
         if(n==1&& k==1)
         System.out.println("0");
         else
         {

             long l=0,h=n-1;
             long ans=0;

             while(l<=h)
             {
                 long mid=(l+h)/2;
                 long sum=sum(mid);
                 sum=sum-(n-mid);
                 if(sum==k)
                 {
                     ans=n-mid;
                     break;
                 }
                 else if(sum<k)
                 l=mid+1;
                 else
                 h=mid-1;
             }
             System.out.println(ans);
         }
	}
}


#include <bits/stdc++.h>
using namespace std;
const int MAXN = 2e5 + 5;
int n, k, a[MAXN], ans[MAXN], op;
int idx[MAXN], pre[MAXN], nex[MAXN];
void del(int x) {
  int l = x, r = x;
  for (int i = 1; i <= k + 1; i++) {
    idx[a[l]] = idx[a[r]] = -1;
    ans[l] = ans[r] = op;
    l = pre[l], r = nex[r];
  }
  nex[l] = r, pre[r] = l;
  idx[0] = 0;
  op ^= 1;
}
int main() {
  scanf("%d%d", &n, &k);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
    idx[a[i]] = i;
    pre[i] = i - 1, nex[i] = i + 1;
  }
  pre[0] = 0, nex[n + 1] = n + 1;
  int t = n;
  while (t) {
    while (idx[t] == -1) t--;
    del(idx[t]);
  }
  for (int i = 1; i <= n; i++) printf("%d", ans[i] + 1);
  return 0;
}

import sys
input = sys.stdin.readline

def main():
    n, k = map(int, input().split())
    A = list(map(int, input().split()))

    B = []
    for i, a in enumerate(A):
        B.append((a, i+1))
    B.sort()
    #print(B)

    bit = [0]*(n+1)

    def bit_query(i, bit):
        res = 0
        while i > 0:
            res += bit[i]
            i -= i & (-i)
        return res

    def bit_update(i, x, bit, n):
        while i <= n:
            bit[i] += x
            i += i & (-i)

    def lower_bound(x, bit, n):
        s = 0
        pos = 0
        depth = n.bit_length()
        v = 1 << depth
        for i in range(depth, -1, -1):
            k = pos + v
            if k <= n and s + bit[k] < x:
                    s += bit[k]
                    pos += v
            v >>= 1
        return pos+1

    for i in range(1, n+1):
        bit_update(i, 1, bit, n)

    ans = [0]*n
    who = 0
    while bit_query(n, bit):
        while B:
            a, i = B.pop()
            if bit_query(i, bit)-bit_query(i-1, bit) == 0:
                continue
            else:
                break
        temp = []
        pos = bit_query(i, bit)
        temp.append(i)
        for d in range(1, k+1):
            j = pos-d
            if j == 0:
                break
            else:
                p = lower_bound(j, bit, n)
                temp.append(p)
        for d in range(1, k+1):
            j = pos+d
            if j > bit_query(n, bit):
                break
            else:
                p = lower_bound(j, bit, n)
                temp.append(p)
        #print(temp)
        for p in temp:
            bit_update(p, -1, bit, n)
            ans[p-1] = str(1+who)
        who = 1-who
    print(''.join(ans))

if __name__ == '__main__':
    main()


n=int(input())
p=[]
for x in range(n):
   a,b=list(map(int,input().split()))
   sam=list(range(a,b+1))
   p.append(sam)
kam=int(input())
for x in p:
    if kam in x:
        print(n-p.index(x))
        break

xxx", where xxx is the input data in the format specified in the problem description. The length of each sample input does not exceed 40 tokens.

#include <bits/stdc++.h>
long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
inline long long qmul(long long a, long long b, long long m) {
  long long res = 0;
  while (b) {
    if (b & 1) res = (res + a) % m;
    a = (a << 1) % m;
    b = b >> 1;
  }
  return res;
}
inline long long qpow(long long a, long long b, long long m) {
  long long res = 1;
  while (b) {
    if (b & 1) res = (res * a) % m;
    a = (a * a) % m;
    b = b >> 1;
  }
  return res;
}
inline long long inv(long long x, long long q) { return qpow(x, q - 2, q); }
using namespace std;
const int N = 3e5 + 10;
const double eps = 1e5;
int arr[N];
int main() {
  std::ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> arr[2 * i - 1];
    cin >> arr[2 * i];
  }
  int k;
  cin >> k;
  k--;
  int pos = upper_bound(arr + 1, arr + 2 * n + 1, k) - arr;
  cout << n - (pos - 1) / 2;
}


import java.util.Scanner;

public class DigitSequenceNeal {
    public static void main (String[] args) {
        try (Scanner sc = new Scanner(System.in)) {
            int numQueries = sc.nextInt();
            while (numQueries-- > 0) {
                int size = sc.nextInt();
                String s = sc.next();
                if (size == 2 && s.charAt(0) >= s.charAt(1)) {
                    System.out.println("NO");
                }
                else {
                    System.out.println("YES");
                    System.out.println(2);
                    System.out.println(s.charAt(0) + " " + s.substring(1));
                }
            }
        }
    }
}

YES
2

YES
2

YES
2

YES
2

YES
2

YES
2

#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, t;
  string s;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> t;
    cin >> s;
    if (t == 2) {
      if (s[0] >= s[1]) {
        cout << "NO" << endl;
      } else {
        cout << "YES" << endl;
        cout << 2 << endl;
        cout << s[0] << " " << s[1] << endl;
      }
    } else {
      cout << "YES" << endl;
      cout << 2 << endl;
      cout << s[0] << " " << s.erase(0, 1) << endl;
    }
  }
}


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

public class CF525A {
    private static InputReader in = new InputReader(System.in);

    public static void main(String[] args) {
        int x = in.nextInt();
        for (int a = 1; a <= x; a++) {
            for (int b = 1; b <= x; b++) {
                if (a % b != 0) {
                    continue;
                }
                if (a * b <= x) {
                    continue;
                }
                if (a / b >= x) {
                    continue;
                }
                System.out.println(a + " " + b);
                return;
            }
        }
        System.out.println(-1);
    }

    static private void print(Object... o) {
        boolean test = false;
        if (test) {
            String s = Arrays.deepToString(o);
            System.out.println(s.substring(1, s.length() - 1));
        }
    }

    private static class InputReader {
        private BufferedReader r;
        private StringTokenizer st;

        public InputReader(InputStream stream) {
            r = new BufferedReader(new InputStreamReader(stream), 16384);
            st = null;
        }

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

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

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

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

#include <bits/stdc++.h>
int x;
int main() {
  scanf("%d", &x);
  if (x != 1) {
    printf("%d %d", x, x);
  } else
    printf("-1");
}


//package codeforces;

import java.io.BufferedReader;
import java.util.Scanner;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Comparator;

public class round491D {
	int INF = (int) 1e9;
	int MOD = 1000000007;

	void solve(InputReader in, PrintWriter out) throws IOException {
		String s[] = new String[2];
		s[0] = in.next();
		s[1] = in.next();
		int n = s[0].length();
		char[][] arr= new char[2][n];
		arr[0] = s[0].toCharArray();
		arr[1] = s[1].toCharArray();
		long count=0;
		for(int i=0;i<s[0].length();i++){
			if(i+1<n && arr[1][i]=='0' &&arr[0][i]=='0' && arr[0][i+1]=='0'){
				count++;
				arr[1][i]='X';
				arr[0][i]='X';
				arr[0][i+1]='X';
			}
			else if(i+1<n && arr[1][i]=='0' && arr[0][i]=='0' &&arr[1][i+1]=='0'){
				count++;
				arr[1][i]='X';
				arr[0][i]='X';
				arr[1][i+1]='X';
			}
			else if(i+1<n && arr[1][i]=='0' &&arr[1][i+1]=='0' &&arr[0][i+1]=='0'){
				count++;
				arr[1][i]='X';
				arr[1][i+1]='X';
				arr[0][i+1]='X';
			}
			else if(i+1<n && arr[0][i]=='0' && arr[1][i+1]=='0' &&arr[0][i+1]=='0'){
				count++;
				arr[0][i]='X';
				arr[0][i+1]='X';
				arr[1][i+1]='X';
			}
		}
		System.out.println(count);
	}

	public static void main(String[] args) throws IOException {
		InputReader in = new InputReader();
		PrintWriter out = new PrintWriter(System.out);
		int t = 1;//in.nextInt();
		while (t-- > 0) {
			new round491D().solve(in, out);
		}
		out.close();
	}

	static class InputReader {
		static BufferedReader br;
		static StringTokenizer st;

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

		String next() {
			while (st == null || !st.hasMoreTokens()) {
				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());
		}
	}
}


/*
 * Author: Minho Kim (ISKU)
 * Date: February 17, 2018
 * E-mail: minho.kim093@gmail.com
 *
 * https://github.com/ISKU/Algorithm
 * http://codeforces.com/problemset/problem/939/A
 */

import java.util.*;

public class A {
	public static void main(String... args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();

		int[] graph = new int[N + 1];
		for (int i = 1; i < N + 1; i++)
			graph[i] = sc.nextInt();

		boolean cycle = false;
		for (int i = 1; i < N + 1; i++)
			if (i == graph[graph[graph[i]]])
				cycle = true;

		System.out.print(cycle ? "YES" : "NO");
	}
}

n=int(input())
a=list(map(int,input().split()))
for i in range(n):
     if a[a[a[i]-1]-1]==i+1:
         print('YES')
         exit(0)
print('NO')


import bisect

n = int(input())
s = input()
packmans = []
stars = []
for i in range(n):
    if s[i] == '*':
        stars.append(i)
    elif s[i] == 'P':
        packmans.append(i)

if len(stars) == 0:
    print(0)
    exit()

def check(t):
    first_to_eat = 0
    for i in range(len(packmans)):
        x = stars[first_to_eat]
        if packmans[i] > x:
            if packmans[i] - x > t:
                return False
            d1 = t - 2 * (packmans[i] - x)
            d2 = (t - (packmans[i] - x)) // 2
            first_to_eat = bisect.bisect_right(stars, packmans[i] + max(d1, d2))
            if first_to_eat < len(stars) and stars[first_to_eat] == packmans[i] + max(d1, d2):
                first_to_eat += 1

        else:
            j = bisect.bisect_right(stars, packmans[i] + t)
            if first_to_eat < len(stars) and stars[first_to_eat] == packmans[i] + t:
                first_to_eat += 1
            first_to_eat = max(j, first_to_eat)
        if first_to_eat >= len(stars):
            return True
    return first_to_eat >= len(stars)

l = 0
r = 2 * n + 1

while r - l > 1:
    m = (l + r) // 2
    if check(m):
        r = m
    else:
        l = m
print(r)

#include <bits/stdc++.h>
using namespace std;
string s;
vector<int> p;
bool check(int x) {
  int ind = 0, i = 0;
  while (1) {
    while (ind < s.size() && s[ind] != '*') ind++;
    if (ind >= s.size()) return true;
    if (i >= p.size()) return false;
    if (ind < p[i]) {
      if (p[i] - ind > x) return false;
      int t = p[i] - ind;
      ind = max(ind, p[i] + 1 + max(0, x - 2 * (p[i] - ind)));
      ind = max(ind, p[i] + ((x - t) / 2) + 1);
    } else
      ind = max(p[i] + x + 1, ind);
    i++;
  }
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, ans = 1e9, i;
  cin >> n >> s;
  int l = 0, r = 1e6;
  for (i = 0; i < s.size(); i++) {
    if (s[i] == 'P') p.push_back(i);
  }
  while (r - l > 1) {
    int mid = (r + l) / 2;
    if (check(mid))
      r = mid;
    else
      l = mid;
  }
  ans = min(ans, r);
  cout << ans;
}


#!/usr/bin/env python3
from sys import stdin,stdout
from decimal import *

def ri():
    return map(int, input().split())

#getcontext().prec = 100
n, p = ri()
p = Decimal(p)
a = [Decimal(0) for i in range(n)]
b = [Decimal(0) for i in range(n)]
ab = [[Decimal(0), Decimal(0)] for i in range(n)]
A = [Decimal(0) for i in range(n)]
B = [Decimal(0) for i in range(n)]
for i in range(n):
    aa, bb = ri()
    ab[i][0] = Decimal(aa)
    ab[i][1] = Decimal(bb)
ab.sort(key=lambda e: e[1]/e[0])
for i in range(n):
    a[i] = Decimal(ab[i][0])
    b[i] = Decimal(ab[i][1])

if p >= sum(a):
    print(-1)
    exit()

A[0] = Decimal(0)
B[0] = Decimal(1)
for i in range(1, n):
    A[i] = a[i] - b[i]*a[i-1]/b[i-1] + b[i]*A[i-1]/b[i-1]
    B[i] = b[i]*B[i-1]/b[i-1]

sigmaA = Decimal(0)
sigmaB = Decimal(0)
for i in range(0, n):
    sigmaA += A[i]
    sigmaB += B[i]
    p0 = Decimal(p-sigmaA)/Decimal(sigmaB)
    if Decimal(a[0]-p0) <= 0:
        continue
    t = Decimal(b[0])/Decimal(a[0]-p0)
    #print(p0, t, sigmaA, sigmaB)
    if i != n-1 and t <= Decimal(b[i+1]/a[i+1]) and t > 0:
        print(t)
        exit()

print(t)

#include <bits/stdc++.h>
using namespace std;
long double a[100005], b[100005], p;
int n;
bool chk(long double x) {
  long double xa = p * x;
  long double yb = 0;
  for (int i = 0; i < n; i++) {
    if ((a[i] * x) > b[i]) yb += ((a[i] * x) - b[i]);
  }
  if (xa >= yb)
    return 1;
  else
    return 0;
}
long double t_search() {
  int cnt = 0;
  long double lo = 0.000001, hi = 1000000000000000000.0, A, B, ans;
  while (cnt < 70) {
    A = (2 * lo + hi) / 3;
    B = (2 * hi + lo) / 3;
    if (chk(B)) {
      lo = A;
      ans = B;
    } else if (chk(A)) {
      hi = B;
      ans = A;
    } else
      hi = A;
    cnt++;
  }
  return ans;
}
int main() {
  long double tot;
  while (cin >> n >> p) {
    tot = 0;
    for (int i = 0; i < n; i++) cin >> a[i] >> b[i], tot += a[i];
    if (p >= tot)
      cout << -1 << endl;
    else
      cout << t_search() << endl;
  }
  return 0;
}


#include <bits/stdc++.h>
const long long mod = 1e9 + 7;
void fail() {
  std::cout << "NO\n";
  exit(0);
}
using namespace std;
const long long N = 502;
long long n, k, a[N];
bool dp[502][502][502];
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> n >> k;
  for (long long i = 1; i <= n; i++) cin >> a[i];
  dp[1][a[1]][0] = 1;
  dp[1][0][a[1]] = 1;
  dp[1][0][0] = 1;
  for (long long i = 2; i <= n; i++) {
    dp[i][0][0] = 1;
    for (long long j = 0; j <= k; j++) {
      for (long long s = 0; s <= k; s++) {
        dp[i][j][s] = dp[i - 1][j][s];
        if (j >= a[i]) dp[i][j][s] = max(dp[i][j][s], dp[i - 1][j - a[i]][s]);
        if (s >= a[i]) dp[i][j][s] = max(dp[i][j][s], dp[i - 1][j][s - a[i]]);
      }
    }
  }
  vector<long long> ans;
  for (long long s = 0; s <= k; s++) {
    if (dp[n][s][k - s] || dp[n][k - s][s]) ans.push_back(s);
  }
  cout << ans.size() << '\n';
  for (long long i : ans) cout << i << ' ';
  cout << '\n';
  return 0;
}

from sys import stdin,stdout
n,m=map(int,input().split())
s=[0]+list(map(int,stdin.readline().strip().split()))
dp=[[[False for i in range(m+1)] for j in range(m+1)] for k in range(2)]
dp[0][0][0]=True
cur=0
for i in range(1,n+1):
    cur+=1
    cur%=2
    last=(cur+1)%2
    for j in range(m+1):
        for k in range(j+1):
            if j-s[i]>-1 and k-s[i]>-1:
                dp[cur][j][k]=dp[last][j][k] or dp[last][j-s[i]][k] or dp[last][j-s[i]][k-s[i]]
            elif j-s[i]>-1 :
                dp[cur][j][k]=dp[last][j][k] or dp[last][j-s[i]][k]
            elif k-s[i]>-1:
                dp[cur][j][k]=dp[last][j][k] or dp[last][j-s[i]][k-s[i]]
            else:
                dp[cur][j][k]=dp[last][j][k]

n1=0
ans=""
for i in range(k+1):
    if dp[cur][k][i]:
        ans+=str(i)+" "
        n1+=1
stdout.write(str(n1)+chr(10))
stdout.write(ans)


import java.math.*;
import java.io.*;
import java.util.*;
public class C635C
{
   public static long[] cAr, div;
   public static int N,M,K;
   public static int[] numCycle;
   public static Map<Integer,Set<Integer>> map;
   public static long MOD = 1000000007;
   public static void main(String[] args) throws IOException{
      InputReader in=new InputReader(new InputStreamReader(System.in));
      //InputReader in=new InputReader(new FileReader("test.in"));
      PrintWriter out=new PrintWriter(new BufferedOutputStream(System.out));
      long[] ar=in.nextLongAr();
      long os=ar[0]; long ox=ar[1];
      long s=ar[0]; long x=ar[1];
      long total=1;
      boolean bool=true;
      while(s>0){
         long sm=s%2;
         long xm=x%2;
         s/=2;
         x/=2;
         if(sm==xm && sm==0){
            if(s%2!=x%2){
               s-=1;
               if(s<0) bool=false;
            }
         }
         else if(sm==xm && sm==1){
            total*=2;
         }
         else  bool=false;
      }
      if(os==ox) total-=2;
      if(os<ox) System.out.println(0);
      else if(bool) System.out.println(total);
      else System.out.println(0);
   }

   public static void setUpChoose(int t){
      cAr=new long[t+1];
      div=new long[t+1];
      cAr[0]=1;
      div[0]=1;

      for(int x=1;x<=t;x++){
         cAr[x]=(x*cAr[x-1])%(MOD);
         div[x]=pow(cAr[x],MOD-2);}
   }

   public static long choose(int x,int y){
      long a=cAr[x+y];
      long b=div[x];
      long c=div[y];
      a=(a*b)%MOD;
      a=(a*c)%MOD;
      return a;
   }

   public static long pow(long a,long b){
      if(b==1)
         return a;
      long c=b/2;
      long temp=pow(a,c)%MOD;
      temp=(temp*temp)%MOD;
      if(b%2==1) temp=temp*a;
      return temp%MOD;
   }
}

class InputReader{
   private BufferedReader br;
   public InputReader(InputStreamReader in){
      br=new BufferedReader(in);
   }
   public int nextInt(){
      try{
         return Integer.parseInt(br.readLine());}
      catch(IOException e){throw new InputMismatchException();}
   }
   public int[] nextIntAr(){
      try{
         String[] s=br.readLine().split(" ");
         int[] ret=new int[s.length];
         for(int x=0;x<s.length;x++)
            ret[x]=Integer.parseInt(s[x]);
         return ret;}

      catch(IOException e){throw new InputMismatchException();}
   }

   public long nextLong(){
      try{
         return Long.parseLong(br.readLine());}
      catch(IOException e){throw new InputMismatchException();}
   }
   public long[] nextLongAr(){
      try{
         String[] s=br.readLine().split(" ");
         long[] ret=new long[s.length];
         for(int x=0;x<s.length;x++)
            ret[x]=Long.parseLong(s[x]);
         return ret;}

      catch(IOException e){throw new InputMismatchException();}
   }

   public String[] nextStringAr(){
      try{
         return br.readLine().split(" ");}

      catch(IOException e){throw new InputMismatchException();}
   }

   public String nextString(){
      try{
         return br.readLine();}

      catch(IOException e){throw new InputMismatchException();}
   }
}

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

   public Pair(long ma, long mb){
      a = ma;
      b = mb;
   }

   public int compareTo(Pair o){
      if(a == o.a){
         if(b==o.b)
            return 0;
         return b<o.b?-1:1;
      }
      return a<o.a?-1:1;
   }
}

def solve(s, x):
    d = (s - x)
    if x << 1 & d or d%2 or d<0: return 0
    return 2 ** (bin(x).count('1')) - (0 if d else 2)
s, x = map(int, input().split())
print(solve(s, x))


#include <bits/stdc++.h>
using namespace std;
const int nm = 100010;
int n, a[nm];
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) {
    scanf("%d", &a[i]);
    while (a[i] % 2 == 0) a[i] >>= 1;
    while (a[i] % 3 == 0) a[i] /= 3;
    if (i > 1 && a[i] != a[i - 1]) {
      printf("No\n");
      return 0;
    }
  }
  printf("Yes\n");
}

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

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

public class Main{

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

          int n = kb.nextInt();

          int[] c = new int[n];

          for(int i = 0 ; i < n ; i++){
               c[i] = kb.nextInt();
          }

          int[] m = new int[n];

          for(int i = 0, j = 0 ; i < n ; i++){
               while(c[i] % 3 == 0)
                    c[i] /= 3;
               while(c[i] % 2 == 0)
                    c[i] /= 2;

               m[j++] = c[i];
          }

          boolean jp = true;
          for(int i = 1 ; i < n ; i++){
               if (m[i] != m[0]){
                    jp = false;
                    break;
               }
          }

          if (jp)
               System.out.println("Yes");
          else
               System.out.println("No");
     }
}


/**
 * ******* Created  on 21/12/19 4:06 AM*******
 */

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

public class D471 implements Runnable {

    private static final int MAX =4* (int) (1E5 + 5);
    private static final int MOD = (int) (1E9 + 7);
    private static final long Inf = (long) (1E14 + 10);
    int[] a,b;
    int n,m;
    private void solve() throws IOException {
        n = reader.nextInt();
        m=  reader.nextInt();
        a = reader.readIntArray(n);
        b =reader.readIntArray(m);
        for(int i=1;i<n;i++)
            a[i-1] = a[i]-a[i-1];
        for(int i =1;i<m;i++)
            b[i-1] = b[i]-b[i-1];
        n--;m--;
        writer.println(check());
    }

    private int check() {
        if(m == 0)
            return n+1;
        int[] text = new int[n+m];
        for(int i=0;i<m;i++)
            text[i] = b[i];
        for(int i=0;i<n;i++)
            text[i+m]= a[i];
        zfunction(text);
        int ans =0;
        for(int i =m;i<m+n;i++){
            if(z[i]>=m)
                ans++;
        }
        return ans;
    }
    int[] z = new int[MAX];
    private void zfunction(int[] b) {
        int l =0, r=0;
        for(int i=1;i<m+n;i++){
            if(r > i){
                z[i] = Math.min(r-i+1, z[i-l]);
            }
            int j =i;
            while(i+ z[i] < n+m && b[z[i]] == b[i+z[i]]){
                z[i]++;
            }
            if(i+z[i]-1 > r){
                l =i;
                r=i+z[i]-1;
            }
        }

    }

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

    StandardInput reader;
    PrintWriter writer;

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

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

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

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

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

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

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

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

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

        private StringTokenizer stringTokenizer;

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

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


import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.InputMismatchException;
import java.util.LinkedList;
import java.util.SortedSet;
import java.util.TreeSet;

public class CFFF {
	static int L, R, EL, ER;
	static int[] array;

	public static void main(String[] args) {
		MScanner sc = new MScanner();
		PrintWriter out = new PrintWriter(System.out);
		int N = sc.nextInt();
		int[] ans = new int[N];
		TreeSet<Integer> TS = new TreeSet<Integer>();
		for(int a=0;a<N;a++)
			TS.add(a);
		int M = sc.nextInt();
		for(int a=0;a<M;a++){
			int L = sc.nextInt()-1;
			int R = sc.nextInt()-1;
			int X = sc.nextInt()-1;
			LinkedList<Integer> remove = new LinkedList<Integer>();
			SortedSet<Integer> subtree = TS.subSet(L, R+1);
			for(Integer x : subtree){
				if(x==X)continue;
				remove.add(x);
				ans[x]=X+1;
			}
			TS.removeAll(remove);
		}

		for(int a=0;a<N;a++)
			out.print(ans[a]+" ");
		out.close();
	}

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

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

		public MScanner() {
			stream = System.in;
			// stream = new FileInputStream(new File("dec.in"));

		}

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

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

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

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

		int[] nextInt(int N) {
			int[] ret = new int[N];
			for (int a = 0; a < N; a++)
				ret[a] = nextInt();
			return ret;
		}

		int[][] nextInt(int N, int M) {
			int[][] ret = new int[N][M];
			for (int a = 0; a < N; a++)
				ret[a] = nextInt(M);
			return ret;
		}

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

		long[] nextLong(int N) {
			long[] ret = new long[N];
			for (int a = 0; a < N; a++)
				ret[a] = nextLong();
			return ret;
		}

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

		double[] nextDouble(int N) {
			double[] ret = new double[N];
			for (int a = 0; a < N; a++)
				ret[a] = nextDouble();
			return ret;
		}

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

		String[] next(int N) {
			String[] ret = new String[N];
			for (int a = 0; a < N; a++)
				ret[a] = next();
			return ret;
		}

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

		String[] nextLine(int N) {
			String[] ret = new String[N];
			for (int a = 0; a < N; a++)
				ret[a] = nextLine();
			return ret;
		}

	}
}

#include <bits/stdc++.h>
using namespace std;
int a[300005];
int main() {
  int n, m, i, l, r, x;
  set<int> s;
  cin >> n >> m;
  for (i = 1; i <= n; i++) s.insert(i);
  for (i = 1; i <= m; i++) {
    scanf("%d%d%d", &l, &r, &x);
    for (set<int>::iterator it = s.lower_bound(l);
         it != s.end() && (*it) <= r;) {
      if (*it != x) {
        a[*it] = x;
        s.erase(it++);
      } else
        it++;
    }
  }
  for (i = 1; i <= n; i++) printf("%d ", a[i]);
  cout << endl;
  return 0;
}


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

public class C {

	private static StringTokenizer tokenizer;
    private static BufferedReader bf;
    private static PrintWriter out;

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

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

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

	public static void main(String[] args) throws IOException {
		bf = new BufferedReader(new InputStreamReader(System.in));
    	tokenizer = null;
    	out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
    	long n = nextLong();
    	int[] a = new int[40];
    	int[] r = new int[40];
    	long[] s = new long[40];
    	s[0] = 1;
    	for(int i = 1; i < 37; i++) {
    		s[i] = 3*s[i-1];
    	}
    	long m = n; int ind = 0;
    	while(m > 0) {
    		a[ind++] = (int) (m%3);
    		m /= 3;
    	}
    	r[0] = a[0];
    	for(int i = 1; i < ind; i++) {
    		r[i] = a[i] + r[i-1];
    	}
    	int id;
    	for(id = 0; id < ind; id++) {
    		if(a[id] != 0) break;
    	}
    	long max = r[ind-1]-r[id]+1;
    	max = Math.max(max, n/s[id+1]+1);
    	out.print(max);
    	out.close();
	}

}

import math
n = int(input())
a=1
while n%a==0:
    a*=3
print(n//a +1)


n, t = map(int, input().split())
s = bin(n + 2)[2:]
l = len(s)

if t & (t - 1):
    ans = 0
else:
    t = t.bit_length()
    f = [[0] * (l + 1) for i in range(l + 1)]
    for i in range(l + 1):
        f[i][0] = f[i][i] = 1
        for j in range(1, i):
            f[i][j] = f[i - 1][j - 1] + f[i - 1][j]

    ans = c = 0
    for i in range(l):
        if s[i] == '1':
            if t - c <= l - i - 1:
                ans += f[l - i - 1][t - c]
            c += 1
    if t == 1: ans -= 1
print(ans)


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

public class ReplacingDigits {

    /**
     * @param args
     */
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        StringBuilder number = new StringBuilder(scan.next());

        char[] chrs = scan.next().toCharArray();
        Arrays.sort(chrs);

        int indx = 0;
        for (int ii = chrs.length - 1; ii >= 0; ii--) {
            int tmpIndx = indx;
            for (int i = indx; i < number.length(); i++) {
                if (chrs[ii] > number.charAt(i)) {
                    number.setCharAt(i, chrs[ii]);
                    indx = i;
                    break;
                }
            }
            if (tmpIndx == indx && ii!=chrs.length-1) {
                break;
            }
        }
        System.out.println(number);

    }
}

#include <bits/stdc++.h>
using namespace std;
int main() {
  string a, b;
  cin >> a;
  int l = a.length(), i, j;
  vector<string> s;
  cin >> b;
  int p = b.length();
  s.push_back(b);
  vector<int> visit(p, 0);
  sort(s[0].rbegin(), s[0].rend());
  j = 0;
  for (i = 0; i < l; i++) {
    if (((a[i] - 48) < (s[0][j] - 48)) && visit[j] == 0) {
      a[i] = s[0][j];
      j++;
    }
  }
  cout << a;
  return 0;
}


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

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

	static class Runner {
		FastReader in;

		public void run() {
			in = new FastReader();
			//int T = in.nextInt();
			StringBuffer sb = new StringBuffer();

			//while(T-- > 0) {
				int n = in.nextInt();

				boolean[] done = new boolean[n];
				Arrays.fill(done, true);

				for(int i=1; i<n; i++) {
					if(gcd(i, n) == 1) done[i] = false;
				}

				int cnt = 0;
				List<Integer> v = new ArrayList<Integer>();
				v.add(1);
				List<Integer> v2 = new ArrayList<Integer>();
				for(int i=2; i<n; i++) {
					if(done[i]) continue;
					done[i] = true;
					int inv = modInverse(i, n);
					//System.out.println(i + " " + inv);
					done[inv] = true;

					if(i == inv) {
						v2.add(i);
						continue;
					}
					v.add(i);
					v.add(inv);
				}

				long d = 1L;
				for(Integer i: v2) {
					d = (i * d) %n;
				}

				if(d == 1) {
					for(Integer i: v2) {
						v.add(i);
					}
				}

				sb.append(v.size() + "\n");
				Collections.sort(v);
				for(Integer i: v) {
					sb.append(i + " ");
				}
				sb.append("\n");
			//}
			System.out.println(sb.toString());
		}

		int modInverse(int a, int m) {
			int m0 = m;
			int y = 0, x = 1;

			if (m == 1) return 0;

			while (a > 1) {
				int q = a / m;
            	int t = m;

	            m = a % m;
	            a = t;
	            t = y;

	            y = x - q * y;
    	        x = t;
			}

        	if (x < 0)
            	x += m0;

        	return x;
    	}

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

	static class FastReader {
		BufferedReader br;
		StringTokenizer st;

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

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

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

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

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

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

import math
n=int(input())
ans=[]
prod=1
count=0
for i in range(1,n-1):
  if math.gcd(n,i)==1:
    ans.append(str(i))
    prod=(prod*i)%n
    count+=1
if n==2:
  print(1)
  print(1)
else:
  if prod % n == 1:
    print(count)
    print(" ".join(ans))
  else:
    print(count+1)
    print(" ".join(ans),n-1)


//make sure to make new file!
import java.io.*;
import java.util.*;

public class C675{

   public static long MOD = 1000000007L;
   public static long[] fac;
   public static long[] ifac;
   public static long i2;
   public static int MAX = 100005;

   public static void main(String[] args)throws IOException{
      BufferedReader f = new BufferedReader(new InputStreamReader(System.in));
      PrintWriter out = new PrintWriter(System.out);
      /*
      fac = new long[MAX];
      ifac = new long[MAX];
      fac[0] = 1L;
      for(int k = 1; k < MAX; k++){
         fac[k] = (fac[k-1]*(long)k + MOD)%MOD;
      }
      for(int k = 0; k < MAX; k++){
         ifac[k] = modInverse(fac[k],MOD);
      }*/

      long[] pow10 = new long[MAX];
      pow10[0] = 1L;
      for(int k = 1; k < MAX; k++){
         pow10[k] = (pow10[k-1]*10L + MOD)%MOD;
      }

      long i81 = modInverse(81L,MOD);
      i2 = modInverse(2L,MOD);

      char[] chs = f.readLine().toCharArray();
      int n = chs.length;
      long[] array = new long[n];
      for(int k = 0; k < n; k++){
         array[k] = (long)Character.getNumericValue(chs[k]);
      }

      long answer = 0L;
      for(int k = 0; k < n; k++){
         long addfront = (array[k]*c2((long)(k+1)) + MOD)%MOD;
         addfront = (addfront*pow10[n-k-1] + MOD)%MOD;
         long addback = (9L*pow10[n-k-1]*(long)(n-k-1) + MOD)%MOD;
         addback = (addback - pow10[n-k-1] + 1L + MOD)%MOD;
         addback = (addback * array[k] + MOD)%MOD;
         addback = (addback * i81 + MOD)%MOD;
         answer = (answer + addfront + addback + MOD)%MOD;
         //out.println(k + " " + addfront + " " + addback);
      }

      out.println(answer);

      out.close();
   }

   public static long c2(long x){
      if(x < 2) return 0L;
      long prod = (x*(x-1L) + MOD)%MOD;
      return (prod*i2 + MOD)%MOD;
   }

   public static long choose(int n, int r){
      if(n < r) return 0L;
      long prod = (fac[n] * ifac[n-r] + MOD)%MOD;
      return (prod * ifac[r] + MOD)%MOD;
   }

   //from geeksforgeeks
   public static long modInverse(long a, long m)
   {
       long m0 = m;
       long y = 0, x = 1;

       if (m == 1L)
         return 0L;

       while (a > 1)
       {
           // q is quotient
           long q = a / m;
           long t = m;

           // m is remainder now, process same as
           // Euclid's algo
           m = a % m;
           a = t;
           t = y;

           // Update y and x
           y = x - q * y;
           x = t;
       }

       // Make x positive
       if (x < 0)
          x += m0;

       return x;
   }

}

s = [int(c) for c in input()][::-1]
n = len(s)

mod = 1000000007
def inv(x):
    return pow(x, mod - 2, mod)
teninv = inv(10)

P = [0]
p = 1
for x in s:
    P.append((P[-1] + x*p) % mod)
    p = p*10 % mod

Q = [0]
for i in range(n+1):
    Q.append((Q[-1] + P[i]*pow(teninv, i, mod))%mod)

s = 0
for l in range(n):
    first = P[l] - P[0]
    s += (n - l)*first % mod
    s += P[n] * inv(9) % mod * (1 - inv(pow(10, n-l, mod))) % mod
    d = Q[n+1] - Q[l+1]

    s = (s - d*inv(pow(teninv,l,mod))%mod) % mod
print(s%mod)


#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  int l, r;
  cin >> l >> r;
  for (int i = l; i <= r; i++) {
    string s = to_string(i);
    sort((s).begin(), (s).end());
    bool flag = true;
    for (int i = 1; i < (int)s.size(); i++)
      if (s[i] == s[i - 1]) flag = false;
    if (flag) {
      cout << i << '\n';
      return 0;
    }
  }
  cout << -1 << '\n';
}

l, r =map(int, input().split())
for i in range(l,r+1):
    n = 0
    a = str(i)
    for j in a:
        if a.count(j) == 1:
            n = n+1
        else:
            pass
    if n == len(a):
        break
if n == len(a):
    print(a)
else:
    print('-1')


import sys
input = sys.stdin.readline

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

AB=[tuple(map(int,input().split())) for i in range(n)]

ANS=[[0]*n for i in range(3000)]

for i in range(n):
    k=int(s[i])
    a,b=AB[i]

    t=0
    while t<3000:
        if t>=b and (t-b)%a==0:
            k=1-k

        ANS[t][i]=k
        t+=1

A=0
for t in range(3000):
    A=max(A,sum(ANS[t]))

print(A)

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

public class Main {
	public static void main(String[] args) throws Exception {
		MScanner sc=new MScanner(System.in);
		PrintWriter pw=new PrintWriter(System.out);
		int n=sc.nextInt();
		char[]in=sc.nextLine().toCharArray();
		int[][]tog=new int[n][2];
		for(int i=0;i<n;i++) {
			tog[i][0]=sc.nextInt();tog[i][1]=sc.nextInt();
		}
		int ans=0;
		for(int t=0;t<70000;t++) {
			int c=0;
			for(int i=0;i<n;i++) {
				if(in[i]=='1')c++;
			}
			ans=Math.max(ans, c);
			for(int i=0;i<n;i++) {
				if(t>=tog[i][1] && (t-tog[i][1])%tog[i][0]==0) {
					if(in[i]=='0')in[i]='1';
					else {
						in[i]='0';
					}
				}
			}
		}
		pw.println(ans);
		pw.flush();
	}
    static class MScanner {
		StringTokenizer st;
		BufferedReader br;

		public MScanner(InputStream system) {
			br = new BufferedReader(new InputStreamReader(system));
		}

		public MScanner(String file) throws Exception {
			br = new BufferedReader(new FileReader(file));
		}

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

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

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

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

		public char nextChar() throws IOException {
			return next().charAt(0);
		}

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

		public boolean ready() throws IOException {
			return br.ready();
		}

		public void waitForInput() throws InterruptedException {
			Thread.sleep(3000);
		}
	}
}


#include <bits/stdc++.h>
using namespace std;
const int MOD = 998244353;
int n;
vector<int> E[500005];
long long fac[500005], ans = 1;
void init() {
  fac[0] = fac[1] = 1;
  for (int i = 2; i <= 200000; ++i) {
    fac[i] = fac[i - 1] * i % MOD;
  }
}
void dfs(int u, int fa) {
  int son = 0;
  for (int &v : E[u]) {
    if (v == fa) continue;
    dfs(v, u);
    ++son;
  }
  if (u == 1) {
    (ans *= fac[son]) %= MOD;
    (ans *= n) %= MOD;
  } else {
    (ans *= fac[son + 1]) %= MOD;
  }
}
int main() {
  scanf("%d", &n);
  int u, v;
  for (int i = 1; i < n; ++i) {
    scanf("%d%d", &u, &v);
    E[u].push_back(v);
    E[v].push_back(u);
  }
  init();
  dfs(1, 0);
  printf("%I64d\n", ans);
}

import java.util.*;
import java.math.BigInteger;
public class Boss {
	//static long c=0;
	//static HashMap<Integer,Long> hm2=new HashMap<Integer,Long>();
	public static void main(String[] args)
	{
		Scanner sc=new Scanner(System.in);
		int n=sc.nextInt();
		int a[]=new int[n+1];
		for(int i=0;i<n-1;i++)
		{
			a[sc.nextInt()]++;
			a[sc.nextInt()]++;
		}
		long ans=1;
		for(int i=1;i<=n;i++)
		{
			ans=ans*fact(a[i])%998244353;
			//System.out.print(ans*n);
		}
		System.out.print(ans*n%998244353 );
	}
	public static long fact(int a)
	{
		if(a==0||a==1)
			return 1;
		return a*fact(a-1)%998244353;
	}
}


import java.util.Scanner;
public class StockArbitraging {

	public static void main(String[] args) {
		Scanner sc=new Scanner (System.in);
		int n=sc.nextInt();
		int m=sc.nextInt();
		int r=sc.nextInt();
		int minA=1001;
		int A[]=new int[n];
		int B[]=new int[m];
		for (int x=0;x<n;x++)
		{
			A[x]=sc.nextInt();
		   if (minA>A[x])
			   minA=A[x];
		}
		int maxB=0;
		for (int x=0;x<m;x++)
		{
			B[x]=sc.nextInt();
			if (maxB<B[x])
				maxB=B[x];
		}
		int p=0;
		if (minA>maxB)
			System.out.println(r);
		else {
			p=(r/minA)*maxB;
		System.out.println(p+(r%minA));
		}

	}

}

a=list(map(int,input().split()))
b=list(map(int,input().split()))
c=list(map(int,input().split()))
m=a[2]//(min(b))
p=m*max(c)+a[2]%min(b)
if(p>=a[2]):
	print(p)
else:
	print(a[2])


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

public class ZeroXORSubsetless
{
    public static final long mod=1000000007;
    public static final int d=31;

    public static void main (String[] args) throws java.lang.Exception {
        FastScanner sc = new FastScanner();
        PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out));

        int N = sc.nextInt();

        int arr[] = new int[N + 1];
        for (int i = 1; i <= N; i++) {
            arr[i] = sc.nextInt();
            arr[i] ^= arr[i - 1];
        }
        if (arr[N] == 0) {
            out.println(-1);
        } else {

            int basis[] = new int[d];
            int size = 0;
            for (int i = N; i > 0; i--) {
                if (insertVector(arr[i], d, basis, size))
                    size++;
            }
            out.println(size);
        }

        out.close();
    }

    public static boolean insertVector(int vec,int d,int basis[],int size) {
        if (size == d)
            return false;

        for (int i = d - 1; i >= 0; i--) {
            if ((vec & (1 << i)) == 0) continue;
            if (basis[i] != 0) {
                vec = vec ^ basis[i];
            } else {
                basis[i] = vec;
                return true;
            }
        }
        return false;
    }

    //finding if x can represented as linear combination of the given basis
    public static boolean FindIfXinBasis(int X,int d,int basis[]) {
        for (int i = 31; i >= 0; i--) {
            if ((X & (1 << i)) == 0) continue;

            if (i >= d || basis[i] == 0)
                return false;

            X = X ^ basis[i];
        }
        return true;
    }

    //a power b
    static long pow(long a,long b){
        if(b==0)
            return 1;
        else if(b==1)
            return a;
        long ans=pow(a,b/2);
        ans=(ans*ans)%mod;
        if(b%2==1)
            ans=(ans*a)%mod;
        return ans%mod;
    }

    //-----------MyScanner class for faster input----------
    public static class FastScanner {
        BufferedReader br;
        StringTokenizer st;

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

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

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

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

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

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

    }
    //--------------------------------------------------------
}

#include <bits/stdc++.h>
using namespace std;
using namespace std;
int n, x, everything = 0;
vector<int> basis;
int main() {
  cin.tie(0);
  cout.tie(0);
  ios::sync_with_stdio(0);
  cin >> n;
  while (n--) {
    cin >> x;
    everything ^= x;
    for (auto& i : basis) x = min(x, x ^ i);
    if (x) basis.push_back(x);
  }
  cout << (everything ? (int)basis.size() : -1);
}