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

/**
 *
 * @author usquare
 */

public class ProblemC {

    public static int mod = (int) (1e9+7);
    public static InputReader in;
    public static PrintWriter out;

    public static void solve() throws FileNotFoundException {

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

        int t=in.ni();

        while(t-->0){
            long x=in.nl();
            long y=in.nl();
            long p=in.nl();
            long q=in.nl();
            long s=0;
            long e=(long) 1e9;

            if(p==1 && q==1){
                out.println(x==y?0:-1);
            }
            else if(p==0){
                out.println(x==0?0:-1);
            }
            else{

                while(e-s>0){
                    long m=(e+s)>>1;
                    long t1=p*m-x;
                    long t2=q*m-y;

                    if(t1>=0 && t2>=0 && t1<=t2){
                        e=m;
                    }
                    else s=m+1;
                }
                long ans=q*e-y;
                out.println(ans);
            }

        }

        out.close();
    }

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

    static class Pair implements Comparable<Pair>{

        int x,y,i;

	Pair (int x,int y,int i){
		this.x=x;
		this.y=y;
		this.i=i;
	}

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

	public int compareTo(Pair o) {
		if(this.x!=o.x)
                    return Integer.compare(this.x,o.x);
		else
                    return Integer.compare(this.y,o.y);
		//return 0;
	}

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

    }

    public static long add(long a,long b){
        long x=(a+b);
        while(x>=mod) x-=mod;
        return x;
    }

    public static long sub(long a,long b){
        long x=(a-b);
        while(x<0) x+=mod;
        return x;
    }

    public static long mul(long a,long b){
        a%=mod;
        b%=mod;
        long x=(a*b);
        return x%mod;
    }

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

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

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

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

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

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

        return gcd;
    }

    public static long mulmod(long  a,long b,long m) {
        if (m <= 1000000009) return a * b % m;

        long res = 0;
        while (a > 0) {
            if ((a&1)!=0) {
                res += b;
                if (res >= m) res -= m;
            }
            a >>= 1;
            b <<= 1;
            if (b >= m) b -= m;
        }
        return res;
    }

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

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

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

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

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

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

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

    public static long pow(long n,long p){
	long  result = 1;
	  if(p==0)
	    return 1;
	if (p==1)
	    return n;
	while(p!=0)
	{
	    if(p%2==1)
	        result *= n;
	    p >>=1;
	    n*=n;
	}
	return result;
    }
     public static void debug(Object... o) {
            System.out.println(Arrays.deepToString(o));
    }

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

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

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

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

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

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

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

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

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

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

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

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

    }
}

import math as mt
import sys,string,bisect
input=sys.stdin.readline
import random
from collections import deque,defaultdict
L=lambda : list(map(int,input().split()))
Ls=lambda : list(input().split())
M=lambda : map(int,input().split())
I=lambda :int(input())
d=defaultdict(int)
def extended_gcd(a,b):
    if(a==0):
        return(0,1)
    x,y=extended_gcd(b%a,a)
    return (y-(b//a)*x,x)
def check(x,y,p,q):
    if(p>=x and (y-x)+p<=q):
        return True
    return False

t=I()
for _ in range(t):
    x,y,p,q=M()
    if(p==0 and x!=0):
        print(-1)

    else:
        g=mt.gcd(x,y)
        if(x//g==p and y//g==q):
            print(0)
        elif(p==q):
            print(-1)
        else:
            l=0
            r=1
            while(not(check(x,y,p*r,q*r))):
                l=r
                r*=10
            #print("p",l,r)
            d=0
            while(l<=r):
                m=(l+r)//2
                if(check(x,y,p*m,q*m)):
                    d=m
                    r=m-1
                else:
                    l=m+1
            if((q*d-y)<0):
                print(-1)
            else:
                print(q*d-y)


#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  int n, a, b;
  cin >> n >> a >> b;
  if (n == a + b) {
    cout << 1 << endl;
    return 0;
  }
  long long int val = 0;
  for (long long int i = 1; i < n; i++) {
    val = max(val, min(a / i, b / (n - i)));
  }
  cout << val;
  return 0;
}

import java.util.Scanner;

public class a {

	public static void main(String args[])
	{
		Scanner scan=new Scanner(System.in);
		int n=scan.nextInt();
		int a=scan.nextInt();
		int b=scan.nextInt();
		//i+j==n
		int min=Integer.MIN_VALUE;
		for(int i=1;i<=n-1;i++)
		{
			//distribute a dishen on i playes and distribute b dishes on (n-i) plates
			if(i>a || (n-i)>b)
			{
				continue;
			}
			int disha=a/i;

			int dishb=b/(n-i);

			//System.out.println(ansa+" "+ansb);
			min=Math.max(Math.min(disha, dishb),min);

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


import java.util.Scanner;
public class Hulk2{
	public static void main(String[]args){
		Scanner apple = new Scanner(System.in);
		int n = apple.nextInt();
		int i;
		   for (i = 0; i < n; i++) {
            if (i % 2 == 0) {
                System.out.printf("I hate ");
            }
            else {
                System.out.printf("I love ");
            }
            if (i < n - 1) {
                System.out.printf("that ");
            }
        }
        System.out.printf("it");
}
}

I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love it

I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate that I love that I hate it

x = int(input())

feelings = ''
for _ in range(x):
	if _ == x - 1:
		if _ % 2 != 0:
			feelings = feelings + 'I love it '
		else:
			feelings = feelings + 'I hate it '
	else:
		if _ % 2 != 0:
			feelings = feelings + 'I love that '
		else:
			feelings = feelings + 'I hate that '
print(feelings)


import sys
n = int(input())
arr = list(map(int,input().split()))
arr.sort()
ans = 1
for i in range(1,n+1):
    if arr[i-1]>=ans:
        ans+=1
print(ans)

#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, m;
  cin >> n;
  vector<long long> sm(n);
  for (int i = 0; i < n; i++) {
    cin >> sm[i];
  }
  sort(sm.begin(), sm.end());
  long long now = 1;
  for (int i = 0; i < sm.size(); i++) {
    if (sm[i] >= now) sm[i] = now, now++;
  }
  cout << now;
}


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

public final class Main {

	static boolean flag = false;

	static int[] vis;
	static List<List<Integer>> adj;

	static void dfs(int vertice, int pai){
		vis[vertice] = 1;
		for (Integer vizinho : adj.get(vertice)) {
			if (vis[vizinho] != 1){
				dfs(vizinho, vertice);
			} else if (pai != vizinho){
				flag = true;
			}

		}
	}

	public static void main(String[] args) {
		int N;
	  	int M;
	  	int u;
	  	int v;
	  	int cont = 0;

	    Scanner scanner = new Scanner(System.in);
	    N = scanner.nextInt();
	    M = scanner.nextInt();

	    vis = new int[N+1];
	    adj = new ArrayList<List<Integer>>(N+1);
	    for (int i = 0; i < N+1; i++) {
			adj.add(new ArrayList<Integer>());
		}

	    for (int i = 0; i < M; i++) {
			u = scanner.nextInt();
			v = scanner.nextInt();
			adj.get(u).add(v);
			adj.get(v).add(u);

		}

	    for (int i = 1; i < N+1; i++) {
			if (vis[i] != 1){
				dfs(i, -1);
				if (flag == false) cont++;
				else flag = false;
			}

		}

	    System.out.println(cont);

	}

}

#include <bits/stdc++.h>
using namespace std;
int N, M;
bool group[100001];
bool trip[100001];
vector<int> Map[100001];
bool flag;
void search(int v, int par) {
  group[v] = true;
  trip[v] = true;
  for (int i = 0; i < Map[v].size(); i++) {
    int now = Map[v][i];
    if (now == par) continue;
    if (trip[now]) flag = true;
    if (!group[now]) search(now, v);
  }
  trip[v] = false;
}
int main() {
  scanf("%d%d", &N, &M);
  int a, b;
  for (int i = 0; i < M; i++) {
    scanf("%d%d", &a, &b);
    Map[a].push_back(b);
    Map[b].push_back(a);
  }
  int ans = 0;
  for (int i = 1; i <= N; i++)
    if (!group[i]) {
      flag = false;
      search(i, 0);
      if (!flag) ans++;
    }
  printf("%d\n", ans);
  return 0;
}


import math, re, sys, string, operator, functools, fractions, collections
sys.setrecursionlimit(10**7)
dX= [-1, 1, 0, 0,-1, 1,-1, 1]
dY= [ 0, 0,-1, 1, 1,-1,-1, 1]
RI=lambda x=' ': list(map(int,input().split(x)))
RS=lambda x=' ': input().rstrip().split(x)
mod=int(1e9+7)
eps=1e-6
#################################################
x=RI()[0]
x%=360
if x>180:
    x=x-360
ans=0
val=abs(x)
for i in range(1,4):
    x-=90
    if x<-180:
        x=360+x
    if abs(x)<val:
        val=abs(x)
        ans=i
print(ans)

import java.util.*;
public class CodeForces
{

    public static void main(String[] args)
	{

            Scanner in = new Scanner(System.in);
            long angle = in.nextLong();
            if(angle < 0 ) angle = 360 - (Math.abs(angle)%360);
            else angle = angle%360;

            if(angle == 0 || angle == 360) System.out.println(0);
            else if( angle <= 45 || angle >= 315) System.out.println(0);
            else if( angle <= 135) System.out.println(1);
            else if( angle <= 225) System.out.println(2);
            else if( angle < 315) System.out.println(3);
        }

}


// practice with kaiboy
import java.io.*;
import java.util.*;

public class CF53B extends PrintWriter {
	CF53B() { super(System.out, true); }
	Scanner sc = new Scanner(System.in);
	public static void main(String[] $) {
		CF53B o = new CF53B(); o.main(); o.flush();
	}

	int upper(int n) {
		return (int) (n * 5L / 4);
	}
	void main() {
		int n = sc.nextInt();
		int m = sc.nextInt();
		m = Math.min(m, upper(n));
		n = Math.min(n, upper(m));
		int l = 0;
		while (1 << l + 1 <= n)
			l++;
		int n1 = 1 << l, m1 = Math.min(m, upper(n1));
		l = 0;
		while (1 << l + 1 <= m)
			l++;
		int m2 = 1 << l, n2 = Math.min(n, upper(m2));
		long a1 = (long) n1 * m1;
		long a2 = (long) n2 * m2;
		if (a1 > a2 || a1 == a2 && n1 > n2) {
			n = n1; m = m1;
		} else {
			n = n2; m = m2;
		}
		println(n + " " + m);
	}
}

#include <bits/stdc++.h>
using namespace std;
int main() {
  long long i, j, h, w, tmp_h, tmp_w;
  cin >> h >> w;
  for (i = 0;; i++) {
    if ((long long)(1 << i) > h || (long long)(1 << i) > (5 * w) / 4) {
      i--;
      break;
    }
  }
  for (j = 0;; j++) {
    if ((long long)(1 << j) > w || (long long)(1 << j) > (5 * h) / 4) {
      j--;
      break;
    }
  }
  i = 1 << i;
  j = 1 << j;
  tmp_h = min(j * 5 / 4, h);
  tmp_w = min(i * 5 / 4, w);
  if (i * tmp_w > j * tmp_h)
    cout << i << " " << tmp_w << endl;
  else if (i * tmp_w < j * tmp_h)
    cout << tmp_h << " " << j << endl;
  else
    cout << max(i, tmp_h) << " " << min(j, tmp_w) << endl;
  return 0;
}


def fail():
  print(-1)
  import sys
  sys.exit()

n = int(input())
count = (n + 1) * [ 0 ]
assign = n * [ None ]
for i, x in enumerate(map(int, input().split())):
  if x > n:
    fail()
  count[x] += 1
  assign[i] = count[x]

for i in range(2, n):
  if count[i - 1] < count[i]:
    fail()

print(count[1])
print(' '.join(map(str, assign)))

import java.util.*;
public class D {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] ns = new int[n];
		for (int i=0; i<n; i++) ns[i] = sc.nextInt()-1;
		for (int x : ns) if (x>=n) {System.out.println("-1"); return;}
		int[] count = new int[n];
		for (int x : ns) count[x]++;
		for (int i=0; i<n-1; i++) {
			if (count[i]<count[i+1]) {
				System.out.println("-1");
				return;
			}
		}
		System.out.println(count[0]);
		ArrayList<Stack<Integer>> ls = new ArrayList<Stack<Integer>>();
		for (int i=0; i<n; i++) {
			Stack<Integer> st = new Stack<Integer>();
			ls.add(st);
		}
		for (int i=0; i<n; i++) ls.get(ns[i]).push(i);
		int[] res = new int[n];
		int ctr = 1;
		while (count[0] > 0) {
			for (int i=0; i<n; i++) {
				int tmp = ls.get(i).pop();
				res[tmp] = ctr;
				count[i]--;
				if (i==n-1 || count[i]+1 != count[i+1]) break;
			}
			ctr++;
		}
		for (int x : res) System.out.print(x+" ");
		System.out.println();
	}

}


#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  long long counter = 0;
  for (int i = 0; i < n; i++) {
    int x, y;
    cin >> x >> y;
    if (y - x >= 2) counter++;
  }
  cout << counter;
  return 0;
}

c = 0

for _ in range(int(input())):
    n = [int(x) for x in input().split()]
    n,m = n[0],n[1]

    if m - n >= 2:
        c += 1
print(c)


A=[int(num) for num in input().split(',')]
s_a=sorted(set(A))
prev=None
string=""
count=0
for i in s_a:
    if prev is None:
        prev=i
        string+=str(prev)
        count+=1
    else:
        if i-(prev+count)==0:
            count+=1
        else:
            if count>1:
                string+='-'+str(prev+count-1)+','+str(i)
            else:
                string+=','+str(i)
            count=1
            prev=i
if count>1:
    string+='-'+str(prev+count-1)
print(string)

import java.io.BufferedInputStream;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.Scanner;

public class PageNumbers { //Round #34 - Page Numbers
	public static void main(String[] args) {
		Scanner sc = new Scanner(new BufferedInputStream(System.in));

		String input = sc.next();
		String[] splitted = input.split(",");

		ArrayList<Integer> numbers = new ArrayList<Integer>();
		for(int i = 0; i < splitted.length; i++) {
			numbers.add(Integer.valueOf(splitted[i]));
		}

		Collections.sort(numbers);

		//Remove duplicates
		int previousNum, num = Integer.MIN_VALUE;
		for(Iterator<Integer> it = numbers.iterator(); it.hasNext(); ) {
			previousNum = num;
			num = it.next();

			if(num == previousNum) {
				it.remove();
			}
		}

		StringBuilder sb = new StringBuilder();
		int sequenceStartPos = 0;
		for(int i = 1; i < numbers.size(); i++) {
			if(numbers.get(i) != numbers.get(i - 1) + 1) {
				if(sequenceStartPos == i - 1) {
					sb.append(numbers.get(i - 1) + ",");
				} else {
					sb.append(numbers.get(sequenceStartPos) + "-" + numbers.get(i - 1) + ",");
				}

				sequenceStartPos = i;
			} else if(i == numbers.size() - 1) {
				sb.append(numbers.get(sequenceStartPos) + "-" + numbers.get(i) + ",");
			}
		}

		//Handle last number and when we only have one number in the array
		if(sequenceStartPos == numbers.size() - 1) {
			sb.append(numbers.get(sequenceStartPos));
		}

		//Handle the case where the whole array is a sequence
		if(sb.length() == 0) {
			sb.append(numbers.get(0) + "-" + numbers.get(numbers.size() - 1));
		}

		if(sb.toString().endsWith(",")) {
			System.out.println(sb.substring(0, sb.length() - 1));
		} else {
			System.out.println(sb);
		}
	}
}


import java.util.Scanner;
public class IcePEace {

	public static int searchstring(String s,String S){
		if (s.length()>S.length())
			return -1;
		for(int i=0;i<=(S.length()-s.length());i++){
			if (s.equals(S.substring(i,i+s.length())))
				return i;
		}
		return -1;
	}
	public static String removestring(String s, int i){
		if (i == (s.length()-1)){
			s=s.substring(0, i);
			return s;
		}
		if (i==0){
			s=s.substring(1,s.length());
			return s;
		}
		if (i>=s.length()){
			return s;
		}
		s=s.substring(0,i)+s.substring(i+1, s.length());
		return s;
	}

	public static void main(String[] args){

		Scanner sc = new Scanner(System.in);
		String t = sc.nextLine();
		String ice = sc.nextLine();
		int Boole = 0;
		int possibilities = 0;
		int i = 0;
		int j = 0;
		String na = "";
		while (ice.length()>0){
			//System.out.println("start of outer loop");
			if (ice.length()<t.length())
				break;
			j=0;
			while ((Boole>-1)&&(j<t.length())&&(ice.length()>0)){
				//System.out.println("Start of inner loop");
				na = t.substring(j,j+1);

				if ((na.equals("2")) || (na.equals("5"))){
					Boole = searchstring("2",ice);
					//System.out.println("searching for 2");
					if (Boole == -1){
						//System.out.println("searching for 5");
						Boole = searchstring("5",ice);
					}
					if (Boole != -1){
						ice=removestring(ice,Boole);
					}
				}
				else if (na.equals("6")||na.equals("9")){
						Boole = searchstring("6",ice);
						if (Boole == -1){
							Boole = searchstring("9",ice);
						}
						if (Boole != -1){
							ice=removestring(ice,Boole);
						}
					}
					else {
						//System.out.println("search the char");
						Boole = searchstring(na,ice);
						if (Boole != -1){
							//System.out.println(ice + " before edit");
							ice=removestring(ice,Boole);
							//System.out.println( ice+ " after edit");
					}
					}
				++j;

		}

			if (Boole != -1){
				++possibilities;
			}
			else
				break;
			//System.out.println("end of outer loop , ice = " + ice);

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

def c(a, b):
	a = a.replace('6', '9')
	a = a.replace('2', '5')
	b = b.replace('6', '9')
	b = b.replace('2', '5')
	n = 10000
	for i in '01345789':
		t = a.count(i)
		if t != 0:
			n = min(n, b.count(i)//t)
	return n
a = input()
b = input()
print(c(a, b))


t = input()
j = t[0]
d, s = 0, int(j)
for i in t[1: ]:
    if j != i:
        if d == 1: d, s = 0, s + 1
        else: d = 1
        j = i
    else: d = 1
print(s + (d and j == '1'))

#include <bits/stdc++.h>
using namespace std;
char s[1000005];
int n;
int main() {
  scanf("%s", s + 2);
  n = strlen(s + 2);
  int now = n + 1, ans = 0;
  while (1) {
    while (s[now] == '0') now--;
    if (s[now] == 0) break;
    int m = now;
    while (s[m] == '1') m--;
    if (m + 1 == now)
      ans++, now = m;
    else {
      s[m] = '1';
      now = m;
      ans++;
    }
  }
  cout << ans << endl;
  return 0;
}


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

public class E {
    public static void main(String[] args) {
        try {
            new E().solve();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    int[] grundy = new int[1 << 20];
    int[][] seg = new int[25][];
    int find(int s, int d, int i0, int i1) {
        int len = grundy.length >> d;
        int e = s + len;
        if (e - 1 < i0 || i1 < s) {
            return 0;
        } else if (i0 <= s && e - 1 <= i1) {
            return seg[d][s / len];
        } else {
            return find(s, d + 1, i0, i1) | find((s + e) / 2, d + 1, i0, i1);
        }
    }
    void add(int idx) {
        int s = 0;
        int d = 0;
        int gm = 1 << grundy[idx];
        while (true) {
            int len = grundy.length >> d;
            if (seg[d] == null) {
                seg[d] = new int[grundy.length / len];
            }
            seg[d][s / len] |= gm;

            d++;
            len /= 2;
            if (len == 0) {
                break;
            }
            int e = s + len;
            if (e <= idx) {
                s = e;
                e = s + len;
            }
        }
    }
    void solve() throws IOException {
        Scanner sc = new Scanner(System.in);
        // BufferedReader in = new BufferedReader(new
        // InputStreamReader(System.in));
        // String[] sp;

        int n = sc.nextInt();
        long[] a = new long[n];
        for (int i = 0; i < n; i++) {
            a[i] = sc.nextLong();
        }

        for (int i = 0; i < 4; i++) {
            grundy[i] = 0;
            add(i);
        }
        for (int i = 4; i < grundy.length; i++) {
            int i0 = (int) Math.ceil(Math.sqrt(Math.sqrt(i)));
            int i1 = (int) Math.floor(Math.sqrt(i));
            int mask = find(0, 0, i0, i1);

            for (int jj = 0;; jj++) {
                if ((mask >> jj & 1) == 0) {
                    grundy[i] = jj;
                    break;
                }
            }
            add(i);
        }

        int xor = 0;
        for (int i = 0; i < n; i++) {
            int g;
            if (a[i] < grundy.length) {
                g = grundy[(int) a[i]];
            } else {
                int i0 = (int) Math.ceil(Math.sqrt(Math.sqrt(a[i])));
                int i1 = (int) Math.floor(Math.sqrt(a[i]));
                int mask = find(0, 0, i0, i1);

                for (int jj = 0;; jj++) {
                    if ((mask >> jj & 1) == 0) {
                        g = jj;
                        break;
                    }
                }
            }
            xor ^= g;
        }

        if (xor == 0) {
            System.out.println("Rublo");
        } else {
            System.out.println("Furlo");
        }
    }
}

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

10 1 2 3 4 5 6 7 8 9 1000000000000000000
```

Please note that the last two inputs are not valid according to the input format specified in the problem description, as they exceed the maximum allowed value for the size of a pile.

Rublo Rublo Rublo Furlo Furlo Furlo Rublo Rublo Furlo Furlo Rublo Furlo Furlo Furlo Rublo Furlo Furlo Rublo Furlo Rublo Rublo Furlo Furlo Furlo Furlo Rublo Furlo Rublo Furlo Furlo Furlo Rublo Rublo Furlo Furlo Rublo Furlo Rublo Rublo Rublo Rublo Furlo Rublo Rublo Furlo Furlo Rublo Furlo Rublo Furlo Rublo Furlo Rublo Furlo Furlo Furlo Rublo Furlo Rublo Furlo Rublo Furlo Furlo Furlo Furlo Furlo Rublo Furlo Furlo Rublo

#include <bits/stdc++.h>
using namespace std;
int get_nim(long long x) {
  if (x < 4) return 0;
  if (x < 16) return 1;
  if (x < 82) return 2;
  if (x < 6724) return 0;
  if (x < 50626) return 3;
  if (x < 2562991876LL) return 1;
  return 2;
}
int main() {
  int n, ans = 0;
  long long a;
  cin >> n;
  for (int i = 0; i < n; ++i) {
    cin >> a;
    ans ^= get_nim(a);
  }
  if (ans)
    cout << "Furlo" << endl;
  else
    cout << "Rublo" << endl;
  return 0;
}


n,m=map(int, input().split())
r=3
ar=[]
for i in range (m):
    q=list(map(int, input().split()))
    ar.append (q)
ar.sort()
for i in range (m):
    if n>ar[i][0]:
        n+=ar[i][1]
    else:
        r=5
        print ('NO')
        break
if r!=5:
    print ('YES')

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

#include <bits/stdc++.h>
using namespace std;
int main() {
  int S, n;
  cin >> S >> n;
  pair<int, int> p[n];
  bool f = 0;
  for (int i = 0; i < n; i++) {
    cin >> p[i].first >> p[i].second;
  }
  sort(p, p + n);
  for (int i = 0; i < n; i++) {
    if (S > p[i].first)
      S += p[i].second;
    else
      f = 1;
  }
  if (f)
    printf("NO");
  else
    printf("YES");
}


#include <bits/stdc++.h>
using namespace std;
long long int N, M, K;
int main(void) {
  cin >> N >> M >> K;
  if (K > N) {
    long long int Sol = 1LL;
    for (int i = 0; i < N; i++) Sol = (Sol * M) % 1000000007LL;
    cout << Sol << endl;
    return 0;
  }
  if (K == N) {
    long long int Sol = 1LL;
    for (int i = 0; i < (N + 1) / 2; i++) Sol = (Sol * M) % 1000000007LL;
    cout << Sol << endl;
    return 0;
  }
  if (K == 1) {
    long long int Sol = 1LL;
    for (int i = 0; i < N; i++) Sol = (Sol * M) % 1000000007LL;
    cout << Sol << endl;
    return 0;
  }
  if (K % 2 == 1) {
    cout << (M * M) % 1000000007LL << endl;
    return 0;
  }
  cout << M << endl;
  return 0;
}

n,m,k = map(int,input().split())
mod = 10**9 + 7
if k == 1 or k>n:
    print(pow(m,n,mod))

elif k == n:
    print(pow(m,(n+1)//2,mod))

elif k%2== 0:

    print(m%mod)
else:
    print(pow(m,2,mod))


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

import static java.util.stream.Collectors.*;

public class Main {
    void solve() {
        int n = in.nextInt();
        String a = in.nextLine();
        String b = in.nextLine();
        List<Boolean> list = new ArrayList<>();
        for (int i = 0; i < n; i++) {
            if (a.charAt(i) != b.charAt(i)) {
                list.add(a.charAt(i) == '1');
            }
        }
        int evenOdd = 0;
        for (Boolean el : list) {
            if (el) evenOdd++;
            else evenOdd--;
        }
        if (evenOdd != 0) {
            out.println(-1);
            return;
        }
        if (list.isEmpty()) {
            out.println(0);
            return;
        }
        List<Boolean> list2 = new ArrayList<>(list);
        list2.addAll(list);

        List<Integer> list3 = new ArrayList<>();
        list3.add(list2.get(0) ? 1 : -1);
        for (int i = 1; i < list2.size(); i++) {
            list3.add(list3.get(i - 1) + (list2.get(i) ? 1 : -1));
        }

        int min = Integer.MAX_VALUE;
        int max = Integer.MIN_VALUE;
        for (Integer el : list3) {
            min = Math.min(min, el);
            max = Math.max(max, el);
        }
        out.println(max - min);
    }

    static final boolean MULTI_TEST = false;

    // --------------------------------------------------------------------------------------------------------------
    // --------------------------------------------------HELPER------------------------------------------------------
    // --------------------------------------------------------------------------------------------------------------

    void solve2() {
//        init();
        if (MULTI_TEST) {
            int t = in.nextInt();
            for (int i = 0; i < t; i++) {
                solve();
            }
        } else {
            solve();
        }
    }

    // --------------------ALGORITHM-------------------------

    public void sort(int[] arr) {
        List<Integer> tmp = Arrays.stream(arr).boxed().sorted().collect(Collectors.toList());
        for (int i = 0; i < arr.length; i++) {
            arr[i] = tmp.get(i);
        }
    }

    // --------------------SCANNER-------------------------
    public static class MyScanner {
        BufferedReader br;
        StringTokenizer st;

        public MyScanner(boolean debug) {
            if (debug) {
                try {
                    br = new BufferedReader(new FileReader("input.txt"));
                } catch (FileNotFoundException e) {
                    throw new RuntimeException(e);
                }
            } else {
                br = new BufferedReader(new InputStreamReader(System.in));
            }
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                st = new StringTokenizer(nextLine());
            }
            return st.nextToken();
        }

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

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

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

        public long[] nextLongs(int n) {
            long[] arr = new long[n];
            for (int i = 0; i < n; i++) {
                arr[i] = nextLong();
            }
            return arr;
        }

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

        String nextLine() {
            try {
                String line = br.readLine();
                if (line == null) {
                    throw new RuntimeException("empty line");
                }
                return line;
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }

    }

    // --------------------WRITER-------------------------
    public static class MyWriter extends PrintWriter {

        public MyWriter(OutputStream out) {
            super(out);
        }

        void println(int[] arr) {
            String line = Arrays.stream(arr).mapToObj(String::valueOf).collect(joining(" "));
            println(line);
        }

    }
    // --------------------MAIN-------------------------

    public MyScanner in;
    public MyWriter out;

    public static void main(String[] args) {
        Main m = new Main();
        m.in = new MyScanner(args.length > 0);
        m.out = new MyWriter(new BufferedOutputStream(System.out));
        m.solve2();
        m.out.close();
    }
}


import java.util.*;
import java.math.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);

		BigInteger s = parseBigInteger(sc.next()), num = BigInteger.ZERO;

		int miss = 0;
		while(true) {
			if(num.compareTo(BigInteger.ZERO)==0) {
				num = BigInteger.ONE;
			}
			else {
				num = num.multiply(new BigInteger("4"));
			}
			if(num.compareTo(s)<0)
				miss++;
			else
				break;
		}

		System.out.println(miss);

	}

	private static BigInteger parseBigInteger(String next) {
		BigInteger num = BigInteger.ZERO;
		BigInteger pow = BigInteger.ONE;
		for(int i=next.length()-1;i>=0;i--) {
			if(next.charAt(i)=='1') {
				num = num.add(pow);
			}
			pow = pow.multiply(new BigInteger("2"));
		}
		return num;
	}
}

n=int(input(),2)
temp=0
l=[]
while(4**temp<n):
    l.append(4**temp)
    temp+=1
print(len(l))


#include <bits/stdc++.h>
using namespace std;
int32_t main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  long long n, m;
  cin >> n >> m;
  long long a[n], i, j;
  for (i = 0; i < n; i++) {
    cin >> a[i];
  }
  long long time[101] = {0};
  long long sum = 0;
  for (i = 0; i < n; i++) {
    sum += a[i];
    long long ans = 0;
    if (sum <= m) {
      cout << ans << " ";
      time[a[i]]++;
      continue;
    }
    long long sum1 = sum;
    for (long long t = 100; t >= 1; t--) {
      if (sum1 - t * time[t] <= m) {
        if ((sum1 - m) % t == 0)
          ans += (sum1 - m) / t;
        else
          ans += (sum1 - m) / t + 1;
        break;
      }
      ans += time[t];
      sum1 -= t * time[t];
    }
    cout << ans << " ";
    time[a[i]]++;
  }
  return 0;
}

import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,copy,functools
# import time,random,resource

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

def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(): return [list(map(int, l.split())) for l in sys.stdin.readlines()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)
def pe(s): return print(str(s), file=sys.stderr)
def JA(a, sep): return sep.join(map(str, a))
def JAA(a, s, t): return s.join(t.join(map(str, b)) for b in a)
def IF(c, t, f): return t if c else f
def YES(c): return IF(c, "YES", "NO")
def Yes(c): return IF(c, "Yes", "No")

def main():
    t = 1

    rr = []
    for _ in range(t):
        n,m = LI()
        a = LI()

        r = []
        t = 0
        q1 = []
        q2 = []
        for i,c in enumerate(a):
            if q1 and q2:
                t1 = -heapq.heappop(q1)
                t -= t1
                while q2:
                    t2 = heapq.heappop(q2)
                    if t2 < t1 and t + t2 + c <= m:
                        t += t2
                        heapq.heappush(q1, -t2)
                    else:
                        heapq.heappush(q2, t2)
                        break

                if t + t1 + c <= m:
                    t += t1
                    heapq.heappush(q1, -t1)
                else:
                    heapq.heappush(q2, t1)

            while t + c > m:
                t1 = -heapq.heappop(q1)
                t -= t1
                heapq.heappush(q2, t1)

            t += c
            heapq.heappush(q1, -c)
            r.append(i + 1 - len(q1))

        rr.append(JA(r, " "))

    return JA(rr, "\n")

print(main())


def solve():
    n, m = [int(x) for x in input().split(' ')]
    A = [[int(x) for x in input().split(' ')] for row in range(n)]
    B = [[int(x) for x in input().split(' ')] for row in range(n)]

    def row_par(M, k):
        return sum(M[k]) % 2

    def col_par(M, k):
        return sum([r[k] for r in M]) % 2

    for r in range(n):
        if row_par(A, r) != row_par(B, r):
            return "No"

    for c in range(m):
        if col_par(A, c) != col_par(B, c):
            return "No"

    return "Yes"

print(solve())

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

#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  bool x;
  cin >> n >> m;
  vector<bool> rowAXor(n);
  vector<bool> rowBXor(n);
  vector<bool> colAXor(m);
  vector<bool> colBXor(m);
  int totalBXor = 0, totalAXor = 0;
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) {
      cin >> x;
      totalAXor ^= x;
      rowAXor[i] = (rowAXor[i] ^ x);
      colAXor[j] = (x ^ colAXor[j]);
    }
  }
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) {
      cin >> x;
      totalBXor ^= x;
      rowBXor[i] = (rowBXor[i] ^ x);
      colBXor[j] = (x ^ colBXor[j]);
    }
  }
  bool isValid = (totalAXor == totalBXor);
  for (int i = 0; i < n; ++i) {
    isValid &= (rowAXor[i] == rowBXor[i]);
  }
  for (int i = 0; i < m; ++i) {
    isValid &= (colBXor[i] == colAXor[i]);
  }
  if (isValid) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  return 0;
}


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

public class GoodArray {
    public static void main(String[] args) throws IOException {
        BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in));
        int n = Integer.parseInt(bufferedReader.readLine());
        StringTokenizer stringTokenizer = new StringTokenizer(bufferedReader.readLine());
        List<Integer> nums = new ArrayList<>();

        for (int i = 0; i < n; i++) {
            nums.add(Integer.valueOf(stringTokenizer.nextToken()));
        }
        long sum = 0;
        Map<Long, Integer> map = new HashMap<>();
        for (int i = 0; i < n; i++) {
            sum += nums.get(i);
            if (map.containsKey((long) nums.get(i))) {
                map.put((long) nums.get(i), map.get((long) nums.get(i)) + 1);
            } else {
                map.put((long) nums.get(i), 1);
            }
        }
        List<Integer> list = new ArrayList<>();
        for (int i = 0; i < n; i++) {
            long curSum = sum - nums.get(i);
            if (curSum % 2 == 1) continue;
            if (map.containsKey(curSum / 2)) {
                if (nums.get(i) == (curSum / 2) && map.get(curSum / 2) > 1) {
                    list.add(i + 1);
                }
                if ( nums.get(i) != (curSum / 2) &&map.get(curSum / 2) > 0) list.add(i + 1);

            }
        }
        System.out.println(list.size());
        for (int i = 0; i < list.size(); i++) {
            System.out.print(list.get(i) + " ");
        }
    }
}

n=int(input())
a=list(map(int,input().split()))
s=sum(a)
d=dict()
for i in range(n):
    if a[i] in d:
        d[a[i]].append(i+1)
    else:
        d[a[i]]=[i+1]
ans=[]
for k in d.keys():
    if (s-k)%2>0:
        continue
    m=(s-k)//2
    #print(m)
    if m in d and (m!=k or len(d[k])>1):
        ans+=d[k]
print(len(ans))
print(' '.join([str(i) for i in ans]))


//package CodeForces.Rounds;

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

public class Task1055B {
    FastScanner in;
    PrintWriter out;
    public void solve() throws IOException {
        int n = in.nextInt();
        int m = in.nextInt();
        int l = in.nextInt();
        long[] a = new long[n];
        for(int i = 0; i<n; i++){
            a[i]=in.nextInt();
        }
        int kol = 0;
        for(int i = 0; i<n; i++){
            if(a[i]>l) {
                while (i < n && a[i] > l) {
                    i++;
                }
                i--;
                kol++;
            }
        }
        for(int i = 0; i<m; i++){
            int s = in.nextInt();
            if(s==0){
                out.println(kol);
            }
            else{
                int p = in.nextInt()-1;
                int d = in.nextInt();
                a[p]+=d;
                if(a[p]-d<=l && a[p]>l){
                    if(p==n-1){
                        if(n==1 ||(a[p-1]<=l)){
                            kol++;
                        }
                    }
                    else {
                        if(p==0){
                            if(n==1 || a[p+1]<=l){
                                kol++;
                            }
                        }
                        else{
                            if(a[p-1]<=l && a[p+1]<=l){
                                kol++;
                            }
                            if(a[p-1]>l && a[p+1]>l){
                                kol--;
                            }
                        }
                    }
                }
            }
        }
    }

    public void run() {
        try {
            in = new FastScanner(System.in);
            out = new PrintWriter(System.out);

            solve();

            out.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    class FastScanner {
        BufferedReader br;
        StringTokenizer st;

        FastScanner(File f) {
            try {
                br = new BufferedReader(new FileReader(f));
            } catch (FileNotFoundException e) {
                e.printStackTrace();
            }
        }

        public FastScanner(InputStream in) {
            br = new BufferedReader(new InputStreamReader(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());
        }
        double nextDouble(){
            return Double.parseDouble(next());
        }

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

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

    public static void main(String[] arg) {
        new Task1055B().run();
    }
}

n, m, l = map(int, input().split())
a = list(map(int, input().split()))
nexxt = {}
prevv = {}
nexxt[-1] = n
prevv[n] = -1

summ = 0
p = -1
l += 1
for k in range(n):
    if a[k] < l:
        p1 = p
        p = k
        nexxt[k] = n
        prevv[k] = p1
        nexxt[p1] = k
        if k - prevv[k] > 1:
            summ += 1
prevv[n] = p
if n - p > 1:
    summ += 1
for i in range(m):
    s = input()
    if s == '0':
        print(summ)
    else:
        j, p, d =  map(int, s.split())
        if j != 1:
            continue
        if a[p - 1] < l:
            a[p-1] += d
            if a[p-1] >= l:
                k = p-1
                left = prevv[k]
                right = nexxt[k]
                nexxt[left] = right
                prevv[right] = left
                if k - prevv[k] > 1:
                    summ -= 1
                if nexxt[k] - k > 1:
                    summ -= 1
                summ += 1


#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(0), cin.tie(0);
  int n;
  cin >> n;
  int arr[n][n];
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      cin >> arr[i][j];
    }
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      if (arr[i][j] != 1) {
        bool found = 0;
        for (int k = 0; k < n; k++) {
          if (k != j) {
            int s = arr[i][j] - arr[i][k];
            for (int l = 0; l < n; l++) {
              if (arr[l][j] == s) {
                found = 1;
              }
            }
          }
        }
        if (!found) {
          cout << "No" << '\n';
          return 0;
        }
      }
    }
  }
  cout << "Yes" << '\n';
  return 0;
}

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

//package cf820;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.Reader;
import java.util.StringTokenizer;

public class A {
	static int N, a[][];
	public static void main(String[] args) throws FileNotFoundException {
		InputStream is = System.in;
//		is = new FileInputStream(new File("A.txt"));
		FastScanner sc = new FastScanner(new InputStreamReader(is));
		N = sc.nextInt();
		a=new int[N][N];
		for (int i=0; i<N; i++)
			for (int j=0; j<N; j++)
				a[i][j]=sc.nextInt();
		for (int i=0; i<N; i++) {
			for (int j=0; j<N; j++) {
				if (!yes(i,j)) {
					System.out.println("No");
					System.exit(0);
				}
			}
		}
		System.out.println("Yes");
	}
	static boolean yes(int i1, int j1) {
		if (a[i1][j1]==1) return true;
		for (int i=0; i<N; i++) {
			for (int j=0; j<N; j++) {
				if (i==i1 || j==j1) continue;
				if (a[i][j1]+a[i1][j]==a[i1][j1])
					return true;
			}
		}
		return false;
	}
	static class FastScanner {
	    BufferedReader br;
	    StringTokenizer st;

	    FastScanner(Reader in) {
	        br = new BufferedReader(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());
	    }
	}

}


import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.math.BigInteger;
import java.util.*;
import java.util.Map.Entry;

public class TestClass {
	private static InputStream stream;
	private static byte[] buf = new byte[1024];
	private static int curChar;
	private static int numChars;
	private static SpaceCharFilter filter;
	private static PrintWriter pw;

	public static class Queue{
		private class node{
			int val;
			node next;
			node(int a){
				val = a;
				next = null;
			}
		}
		node head,tail;
		Queue(){
			head = null;
			tail = null;
		}
		public void EnQueue(int a){
			if(head==null){
				node p = new node(a);
				head = p;
				tail = p;
			}
			else{
				node p = new node(a);
				tail.next = p;
				tail = p;
			}
		}
		public int DeQueue(){
			int a = head.val;
			head = head.next;
			return a;
		}
		public boolean isEmpty(){
			return head==null;
		}
	}
	public static long pow(long x,long y,long m){
		if(y==0)
    		return 1;
    	long k = pow(x,y/2,m);
    	if(y%2==0)
    		return (k*k)%m;
    	else
    		return (((k*k)%m)*x)%m;
    }
	static long Inversex = 0,Inversey = 0;
	public static void InverseModulo(long a,long m){
		if(m==0){
			Inversex = 1;
			Inversey = 0;
		}
		else{
    		InverseModulo(m,a%m);
    		long temp = Inversex;
    		Inversex = Inversey;
    		Inversey = temp+ - (a/m)*Inversey;
    	}
    }
    static long mod1 = 1000000007;
    static long mod2 = 1000000009;
	public static long gcd(long a,long b){
		if(a%b==0)
			return b;
		return gcd(b,a%b);
	}
	public static boolean isPrime(long a){
		if(a==1)
			return false;
		else if(a==2||a==3)
			return true;
		for(long i=2;i<=Math.sqrt(a);i++)
			if(a%i==0)
				return false;
		return true;
	}
	public static double distance(int a,int b,int x,int y){
		return Math.sqrt(((long)(a-x)*(long)(a-x))+((long)(b-y)*(long)(b-y)));
	}
	public static class Pair implements Comparable<Pair> {
		long u;
		long v;
		BigInteger bi;
		public Pair(long u, long v) {
			this.u = u;
			this.v = v;
		}
		public int hashCode() {
			int hu = (int) (u ^ (u >>> 32));
			int hv = (int) (v ^ (v >>> 32));
			return 31 * hu + hv;
		}
		public boolean equals(Object o) {
			Pair other = (Pair) o;
			return u == other.u && v == other.v;
		}
		public int compareTo(Pair other) {
			return Long.compare(u, other.u) != 0 ? Long.compare(u, other.u) : Long.compare(v, other.v);
		}
		public String toString() {
			return u+" "+v;
		}
	}
	public static int sieve(int a[],boolean b[]){
		int count = 0;
		b[0] = true;
		b[1] = true;
		for(int i=2;i<a.length;i++){
			if(!b[i]){
				for(int j=2*i;j<a.length;j=j+i){
					b[j] = true;
				}
				a[count++] = i;
			}
		}
		return count;
	}
	public static void MatrixMultiplication(int a[][],int b[][],int c[][]){
		for(int i=0;i<a.length;i++){
			for(int j=0;j<b[0].length;j++){
				c[i][j] = 0;
				for(int k=0;k<b.length;k++)
					c[i][j]=(int)((c[i][j]+((a[i][k]*(long)b[k][j])%mod1))%mod1);
			}
		}
	}
	public static void Equal(int arr[][],int temp[][]){
		for(int i=0;i<arr.length;i++){
			for(int j=0;j<arr.length;j++)
				temp[i][j] = arr[i][j];
		}
	}
	public static class Trie {
		Node head;
		private class Node{
			Node a[] = new Node[2];
			boolean val;
			Node(){
				a[0] = null;
				a[1] = null;
				val = false;
			}
		}
		Trie(){
			head = new Node();
		}
		public void insert(Stack<Integer> s){
			Node temp = head;
			while(!s.isEmpty()){
				int q = s.pop();
				if(temp.a[q]==null)
					temp.a[q] = new Node();
				temp = temp.a[q];
			}
			temp.val = true;
		}
		public Node delete(Stack<Integer> s,Node temp){
			if(s.isEmpty())
				return null;
			int q = s.pop();
			temp.a[q] = delete(s,temp.a[q]);
			if(temp.a[q]==null&&temp.a[q^1]==null)
				return null;
			else
				return temp;
		}
		public void get(Stack<Integer> s,Stack<Integer> p){
			Node temp = head;
			while(!p.isEmpty()){
				int q = p.pop();
				if(temp.a[q]!=null){
					s.push(q);
					temp = temp.a[q];
				}
				else{
					s.push(q^1);
					temp = temp.a[q^1];
				}
			}
		}
	}
	/*public static void Merge(long a[][],int p,int r){
        if(p<r){
            int q = (p+r)/2;
            Merge(a,p,q);
            Merge(a,q+1,r);
            Merge_Array(a,p,q,r);
        }
    }
	public static void get(long a[][],long b[][],int i,int j){
		for(int k=0;k<a[i].length;k++)
			a[i][k] = b[j][k];
	}
    public static void Merge_Array(long a[][],int p,int q,int r){
        long b[][] = new long[q-p+1][a[0].length];
        long c[][] = new long[r-q][a[0].length];
        for(int i=0;i<b.length;i++){
            get(b,a,i,p+i);
        }
        for(int i=0;i<c.length;i++){
            get(c,a,i,q+i+1);
        }
        int i = 0,j = 0;
        for(int k=p;k<=r;k++){
            if(i==b.length){
                get(a,c,k,j);
                j++;
            }
            else if(j==c.length){
                get(a,b,k,i);
                i++;
            }
            else if(b[i][0]<c[j][0]){
                get(a,b,k,i);
                i++;
            }
            else{
                get(a,c,k,j);
                j++;
            }
        }
    }
    public static void powMatrix(long n){
    	if(n<=1)
    		return ;
    	powMatrix(n/2);
    	MatrixMultiplication(temp2,temp2,result);
		Equal(result,temp2);
    	if(n%2==1){
    		MatrixMultiplication(temp2,a,result);
    		Equal(result,temp2);
    	}
    }
    static int result[][] = new int[4][4];
	static int temp[][] = new int[4][4];
	static int temp2[][] = new int[4][4];
	static int a[][] = new int[4][4];
	static int[][] b = new int[4][1];
	static int [][] c = new int[4][1];
    public static int count(long n){
		a[0][0] = 1 ;
		a[0][1] = 1;
		a[1][0] = 1;
		a[2][1] = 1;
		a[3][0] = 1;
		a[3][1] = 1;
		a[3][3] = 1;
		b[0][0] = 1;
		b[1][0] = 1;
		b[2][0] = 0;
		b[3][0] = 2;
		Equal(a,temp2);
		result[0][0] = 1;
		result[1][1] = 1;
		result[2][2] = 1;
		result[3][3] = 1;
		Equal(result,temp);
		if(n<=0)
			return 0;
		else if(n==1)
			return 1;
		else if(n==2)
			return 2;
		n = n-2;
		powMatrix(n);
		MatrixMultiplication(temp2,b,c);
		return c[3][0];
	}*/
	private static void soln(){
		int n = nI();
		int m = nI();
		HashSet<String> a = new HashSet<String>();
		for(int i=0;i<n;i++)
			a.add(nLi());
		boolean u = false;
		int k = m;
		while(k-->0){
			if(a.contains(nLi())){
				if(!u)
					m--;
				else
					n--;
				u = !u;
			}
		}
		if(n>m)
			pw.println("YES");
		else
			pw.println("NO");
	}
	public static void main(String[] args) {
		InputReader(System.in);
		pw = new PrintWriter(System.out);
		soln();
		pw.close();
	}
	// To Get Input
	// Some Buffer Methods
	public static void InputReader(InputStream stream1) {
		stream = stream1;
	}
	private static boolean isWhitespace(int c) {
		return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
	}
	private static boolean isEndOfLine(int c) {
		return c == '\n' || c == '\r' || c == -1;
	}
	private static 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++];
	}
	private static int nI() {
		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;
	}
	private static long nL() {
		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;
	}
	private static String nextToken() {
		int c = read();
		while (isSpaceChar(c))
			c = read();
		StringBuilder res = new StringBuilder();
		do {
			res.appendCodePoint(c);
			c = read();
		} while (!isSpaceChar(c));
		return res.toString();
	}
	private static String nLi() {
		int c = read();
		while (isSpaceChar(c))
			c = read();
		StringBuilder res = new StringBuilder();
		do {
			res.appendCodePoint(c);
			c = read();
		} while (!isEndOfLine(c));
		return res.toString();
	}
	private static int[] nIA(int n) {
		int[] arr = new int[n];
		for (int i = 0; i < n; i++)
			arr[i] = nI();
		return arr;
	}
	private static long[] nLA(int n) {
		long[] arr = new long[n];
		for (int i = 0; i < n; i++)
			arr[i] = nL();
		return arr;
	}
	private static void pArray(int[] arr) {
		for (int i = 0; i < arr.length; i++)
			pw.print(arr[i] + " ");
		pw.println();
		return;
	}
	private static void pArray(long[] arr) {
		for (int i = 0; i < arr.length; i++)
			pw.print(arr[i] + " ");
		pw.println();
		return;
	}
	private static boolean isSpaceChar(int c) {
		if (filter != null)
			return filter.isSpaceChar(c);
		return isWhitespace(c);
	}
	private interface SpaceCharFilter {
		public boolean isSpaceChar(int ch);
	}
}

2 2
kremowka
wadowicka
kremowka
wiedenska

import sys
input = sys.stdin.readline
n, m = input().split()
n = int(n)
m = int(m)
polW = []
eneW = []
turnsP = 0
turnsE = 0
same = 0
for i in range(n):
     polW.append(input())
     turnsP+=1
for i in range(m):
     word = input()
     if word in polW:
          turnsP-=1
          same+=1
     else:
          turnsE+=1
if same%2==1:
     if turnsP >= turnsE:
          print("YES")
     else:
          print("NO")
else:
     if turnsP > turnsE:
          print("YES")
     else:
          print("NO")


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

public class AAndBAndInterstingSubstrings
{
	public static void main(String[] args)
	{
		Scanner sc = new Scanner(System.in);
		int[] arr = new int[26];
		for(int i=0;i<26;i++)
			arr[i] = sc.nextInt();
		String s = sc.next();
		HashMap<Long, Integer> map[] = new HashMap[26];
		for(int i=0;i<26;i++)
			map[i] = new HashMap<>();
		long ans = 0;
		long sum = 0;
		for(int i=0;i<s.length();i++)
		{
			int c = s.charAt(i)-'a';
			Integer add = map[c].get(sum);
			if(add == null) add = 0;
			ans+=add;
			sum+=arr[c];
			Integer prev = map[c].get(sum);
			if(prev == null) prev = 0;
			map[c].put(sum, prev + 1);
		}
		System.out.println(ans);
	}
}

-2 -2 2 1 4 0 -2 4 5 4 -5 -5 2 1 1 -1 0 -5 -2 3 -2 4 5 2 3 -5
qgzhbkitmqwttdyoyvcbxincwjryzknubpacsngorexaldfurondbednowemnnlphhboycfavsovisrmfaefusoobingjhsmrukx

#include <bits/stdc++.h>
using namespace std;
int val[26];
unordered_map<long long, int> ht[26];
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL), cout.tie(NULL);
  for (int i = 0; i < 26; ++i) cin >> val[i];
  string str;
  cin >> str;
  long long cm = 0, ans = 0;
  for (int i = 0; i < ((int)(str).size()); ++i) {
    ans += ht[str[i] - 'a'][cm];
    cm += val[str[i] - 'a'];
    ++ht[str[i] - 'a'][cm];
  }
  cout << ans << '\n';
  return 0;
}


#include <bits/stdc++.h>
using namespace std;
const int N = 5010;
int x[N], y[N], z[N];
double sqr(double x) { return x * x; }
double dis(int i, int j) {
  return sqrt(sqr(x[i] - x[j]) + sqr(y[i] - y[j]) + sqr(z[i] - z[j]));
}
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) {
    scanf("%d%d%d", x + i, y + i, z + i);
  }
  double mn = 1e18;
  for (int i = 2; i <= n; ++i) {
    for (int j = i + 1; j <= n; ++j) {
      mn = min(mn, dis(1, i) + dis(i, j) + dis(1, j));
    }
  }
  printf("%.10f\n", mn / 2);
  return 0;
}

//package school2;

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

public class D {
	Scanner in;
	PrintWriter out;
//	String INPUT = "4 0 0 0 0 0 1 0 1 0 1 0 0";
	String INPUT = "";

	void solve()
	{
		int n = ni();
		int[] x = new int[n];
		int[] y = new int[n];
		int[] z = new int[n];
		double[] u = new double[n];
		for(int i = 0;i < n;i++){
			x[i] = ni();
			y[i] = ni();
			z[i] = ni();
			u[i] = dd(x[0]-x[i], y[0]-y[i], z[0]-z[i]);
		}
		double min = 999999999;
		for(int i = 1;i < n;i++){
			for(int j = 1;j < i;j++){
				min = Math.min(min, (u[i] + u[j] + dd(x[i]-x[j], y[i]-y[j],z[i]-z[j])) / 2);
			}
		}
		out.println(min);
	}

	double dd(double x, double y, double z)
	{
		return Math.sqrt(x * x + y * y + z * z);
	}

	void run() throws Exception
	{
//		int n = 5000;
//		StringBuilder sb = new StringBuilder(n + " ");
//		Random r = new Random();
//		for(int i = 0;i < n;i++){
//			sb.append(r.nextInt(10000) + " ");
//			sb.append(r.nextInt(10000) + " ");
//			sb.append(r.nextInt(10000) + " ");
//		}
//		INPUT = sb.toString();

		in = INPUT.isEmpty() ? new Scanner(System.in) : new Scanner(INPUT);
		out = new PrintWriter(System.out);

		solve();
		out.flush();
	}

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

	int ni() { return Integer.parseInt(in.next()); }
	void tr(Object... o) { if(INPUT.length() != 0)System.out.println(o.length > 1 || o[0].getClass().isArray() ? Arrays.deepToString(o) : o[0]); }
}


#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, s, m, i, sum = 0;
  int a[101];
  m = -1;
  scanf("%d%d", &n, &s);
  for (i = 0; i < n; i++) {
    scanf("%d", &a[i]);
    if (m < a[i]) {
      m = a[i];
    }
    sum += a[i];
  }
  if (sum - m <= s) {
    printf("YES\n");
  } else {
    printf("NO\n");
  }
  return 0;
}

n, s = map(int, input().split())
arr = list(map(int, input().split()))
print("NO" if sum(arr) - max(arr) > s else "YES")


c1,c2,c3 ,c4 = map(int,input().split())
n , m = map(int, input().split())
a = [int(x) for x in input().split()]
b = [int(x) for x in input().split()]
ans1 = 0
ans2 = 0
for i in a:
    ans1 += min(c1 * i,c2)
ans1 = min(ans1, c3)
for i in b:
    ans2 += min(c1 * i,c2)
ans2 = min(ans2, c3)
ans = min(ans1 + ans2, c4)
print(ans)

#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(0), cin.tie(NULL), cout.tie(NULL);
  ;
  int arr[4];
  for (int i = 0; i < 4; ++i) {
    cin >> arr[i];
  }
  int n, m;
  cin >> n >> m;
  vector<int> b(n), t(m);
  for (int i = 0; i < n; ++i) {
    cin >> b[i];
  }
  for (int i = 0; i < m; ++i) {
    cin >> t[i];
  }
  int ansB = 0, ansT = 0, resB = 0, resT = 0, totalB = 0, totalT = 0;
  for (int i = 0; i < n; ++i) {
    ansB = b[i] * arr[0];
    ansB = min(ansB, arr[1]);
    resB += ansB;
  }
  totalB = min(resB, arr[2]);
  for (int i = 0; i < m; ++i) {
    ansT = t[i] * arr[0];
    ansT = min(ansT, arr[1]);
    resT += ansT;
  }
  totalT = min(resT, arr[2]);
  cout << min(arr[3], totalB + totalT);
  return 0;
}


#include <bits/stdc++.h>
using namespace std;
using namespace std;
int n, a[300001], was[300001][3];
long long d[300001][3];
long long calc(int v, int bit) {
  if (v <= 0 || v > n) return 0ll;
  if (v == 1) return -1;
  if (was[v][bit] == 2) return d[v][bit] = -1;
  if (was[v][bit] == 1) return d[v][bit];
  was[v][bit] = 2;
  if (bit) {
    if (calc(v + a[v], bit ? 0 : 1) != -1)
      d[v][bit] = calc(v + a[v], bit ? 0 : 1) + a[v];
    else
      d[v][bit] = -1;
  } else {
    if (calc(v - a[v], bit ? 0 : 1) != -1)
      d[v][bit] = calc(v - a[v], bit ? 0 : 1) + a[v];
    else
      d[v][bit] = -1;
  }
  was[v][bit] = 1;
  return d[v][bit];
}
int main() {
  scanf("%d", &n);
  for (int i = 2; i <= n; ++i) scanf("%d", &a[i]);
  for (int i = 2; i <= n; ++i) {
    if (!was[i][0]) calc(i, 0);
    if (!was[i][1]) calc(i, 1);
  }
  for (int i = 1; i < n; i++)
    if (d[i + 1][0] != -1)
      cout << d[i + 1][0] + i << '\n';
    else
      puts("-1");
  return 0;
}

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

public class cf283b {
  static int n;
  static int INC = 0, DEC = 1;
  static int[] v;
  static Long[][] memo;
  public static void main(String[] args) {
    FastIO in,out;
    in = out = new FastIO();
    n = in.nextInt();
    v = new int[n];
    for(int i=1; i<n; i++) v[i] = in.nextInt();
    memo = new Long[2][n];
    memo[INC][0] = -1L;
    memo[DEC][0] = 0L;
    for(int i=1; i<n; i++) {
      long ans = go(DEC,i);
      if(ans != -1) ans += i;
      out.println(ans);
    }
    out.close();
  }
  static long go(int dir, int pos) {
    if(pos < 0 || pos >= n) return 0;
    if(memo[dir][pos] != null) return memo[dir][pos];
    memo[dir][pos] = -1L;
    long ans = go(1-dir, pos+(dir==INC?v[pos]:-v[pos]));
    if(ans != -1) ans += v[pos];
    return memo[dir][pos] = ans;
  }
  static class FastIO extends PrintWriter {
    BufferedReader br;
    StringTokenizer st;

    public FastIO() {
      this(System.in,System.out);
    }
    public FastIO(InputStream in, OutputStream out) {
      super(new BufferedWriter(new OutputStreamWriter(out)));
      br = new BufferedReader(new InputStreamReader(in));
      scanLine();
    }
    public void scanLine() {
      try {
        st = new StringTokenizer(br.readLine().trim());
      } catch(Exception e) {
        throw new RuntimeException(e.getMessage());
      }
    }
    public int numTokens() {
      if(!st.hasMoreTokens()) {
        scanLine();
        return numTokens();
      }
      return st.countTokens();
    }
    public String next() {
      if(!st.hasMoreTokens()) {
        scanLine();
        return next();
      }
      return st.nextToken();
    }
    public double nextDouble() {
      return Double.parseDouble(next());
    }
    public long nextLong() {
      return Long.parseLong(next());
    }
    public int nextInt() {
      return Integer.parseInt(next());
    }
  }
}


for _ in range(1):
    x=set(list(input()))
    if len(x)%2==0:
        print('CHAT WITH HER!')
    else:

        print("IGNORE HIM!")

IGNORE HIM!
IGNORE HIM!
IGNORE HIM!
IGNORE HIM!
IGNORE HIM!
IGNORE HIM!
IGNORE HIM!
IGNORE HIM!
IGNORE HIM!
IGNORE HIM!
IGNORE HIM!
CHAT WITH HER!
IGNORE HIM!
IGNORE HIM!
CHAT WITH HER!
IGNORE HIM!
IGNORE HIM!
IGNORE HIM!
IGNORE HIM!
IGNORE HIM!
IGNORE HIM!
IGNORE HIM!
IGNORE HIM!
IGNORE HIM!
CHAT WITH HER!
IGNORE HIM!
IGNORE HIM!
IGNORE HIM!
IGNORE HIM!
CHAT WITH HER!
IGNORE HIM!
IGNORE HIM!
CHAT WITH HER!
IGNORE HIM!
IGNORE HIM!
CHAT WITH HER!
IGNORE HIM!
IGNORE HIM!
IGNORE HIM!
IGNORE HIM!
CHAT WITH HER!
CHAT WITH HER!
IGNORE HIM!
IGNORE HIM!
CHAT WITH HER!
IGNORE HIM!
IGNORE HIM!
IGNORE HIM!
IGNORE HIM!
IGNORE HIM!

#include <bits/stdc++.h>
int main() {
  int alfabet[30] = {};
  char string[105];
  int i = 0;
  int isi;
  scanf("%s", string);
  for (int i = 0; i < strlen(string); i++) {
    alfabet[string[i] - 96]++;
  }
  for (int i = 0; i < 27; i++) {
    if (alfabet[i] != 0) {
      isi++;
    }
  }
  if (isi % 2 == 0) {
    printf("IGNORE HIM!\n");
  } else {
    printf("CHAT WITH HER!\n");
  }
}


from math import *;
lineup=[int(x) for x in input().split()]
a,b,c=sorted(lineup[1:4])
n=lineup[0]
value=0
if a==1:
	print(n)
	exit()
for i in range(0,n+1,a):
	for j in range(0,n+1,b):
		z=(n-i-j)/c
		if ceil(z)==floor(z) and int(z)>=0:
			x=i//a
			y=j//b
			z=int(z)
			value=max(value,x+y+z)
print(int(value))

/**
 * Created by Akshay on 10/9/17.
 */
import java.util.*;

public class Week_5_Codeforces_A {
    public static void main(String[] args){
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        int a = scan.nextInt();
        int b = scan.nextInt();
        int c = scan.nextInt();

        int i = 0;
        int j = 0;

        int max = 0;

        while(i*a + j*b <= n){
            while(i*a + j*b <= n){
                if(Math.abs((i*a + j*b) - n)%c == 0){
                    int k = Math.abs((i*a + j*b) - n)/c;
                    if(i + j + k > max){
                        max = i + j + k;
                    }
                }
                j++;
            }
            i++;
            j = 0;
        }
        System.out.println(max);
    }
}


# written with help of passed solutions
from math import sqrt

n, a, d = map(int, input().split())
a = float(a)
ans = [0] * n

tm = 0
for i in range(n):
    t, v = map(int, input().split())
    acc_t = v / a
    add_t = 0

    if acc_t ** 2 * a > 2 * d:
        add_t = sqrt(2 * d / a)
    else:
        add_t = acc_t + (d - acc_t ** 2 * a / 2) / v

    tm = max(tm, t + add_t)
    ans[i] = tm

print('\n'.join(map(str, ans)))

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int n, a, d;
int t[100005], v[100005];
double ans[100005];
int main() {
  cin.tie(0);
  cin >> n >> a >> d;
  for (int i = 1; i <= n; i++) cin >> t[i] >> v[i];
  ans[0] = 0;
  for (int i = 1; i <= n; i++) {
    double tt = 1.0 * v[i] / a;
    double dd = 0.5 * a * tt * tt, res = -1;
    if (dd < d) {
      res = tt + (d - dd) / v[i];
    } else {
      res = sqrt(2.0 * d / a);
    }
    ans[i] = res + t[i];
    ans[i] = max(ans[i], ans[i - 1]);
    cout << fixed << setprecision(10) << ans[i] << endl;
  }
  return 0;
}


import java.util.Scanner;

public class Main {
public static void main(String[] args) {
	Scanner sc = new Scanner(System.in);
	int q = sc.nextInt();
	while((q--)!=0) {
		int n = sc.nextInt();
		int u = sc.nextInt();
		int v = sc.nextInt();
		String s=sc.nextLine();
		String[] a = sc.nextLine().split(" ");
		int z=Integer.parseInt(a[0]);
		int w=0;
		for(int i=1;i<a.length;i++) {
			int d=Integer.parseInt(a[i]);
			w=Math.max(Math.abs(z-d), w);
			z=d;
		}
		if(w==0) {
			if(v<u)System.out.println(2*v);
			else System.out.println(u+v);
		}else if(w==1) {
			System.out.println(Math.min(v, u));
		}else {
			System.out.println("0");
		}
	}
}
}

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

void problem_solver() {
    int n, u, v;
    cin >> n >> u >> v;
    vector<int> a(n);
    bool t1 = false, t2 = false, t3 = false;
    for(int i=0; i<n; i++)   cin >> a[i];
    for(int i=0; i<n-1; i++) {
        if(abs(a[i] - a[i+1]) > 1) {
            cout << 0;
            return;
        }
        if(a[i] - a[i+1] == 0)   t1 = true;
        if(abs(a[i] - a[i+1]) == 1)   t2 = true;
    }
    int cost = INT_MAX;
    if(t1) {
        cost = 2 * v;
        cost = min(cost, u + v);
    }
    if(t2) {
        cost = min(cost, min(u, v));
    }
    cout << cost;
}

int main() {
    int tt;
    cin >> tt;
    for(int t=1; t<=tt; t++) {
        problem_solver();
        cout << "\n";
    }
}


#include <bits/stdc++.h>
using namespace std;
const int N = 100005;
inline int in() {
  int x;
  scanf("%d", &x);
  return x;
}
inline long long lin() {
  long long x;
  scanf("%I64d", &x);
  return x;
}
long long n, a, b;
int main() {
  n = lin();
  a = 1ll * 1e18;
  b = 1ll * -1e18;
  for (long long p = 1; p <= 35000; p++) {
    if (p > n) continue;
    if (n % p == 0) {
      long long aa = p, bb = n / p;
      for (long long q = 1; q * q <= bb; q++) {
        if (bb % q == 0) {
          long long x = q, y = bb / q;
          a = min(a, (aa + 1ll) * (x + 2ll) * (y + 2ll));
          b = max(b, (aa + 1ll) * (x + 2ll) * (y + 2ll));
        }
      }
      for (long long q = 1; q * q <= aa; q++) {
        if (aa % q == 0) {
          long long x = q, y = aa / q;
          a = min(a, (bb + 1ll) * (x + 2ll) * (y + 2ll));
          b = max(b, (bb + 1ll) * (x + 2ll) * (y + 2ll));
        }
      }
    }
  }
  cout << a - n << " " << b - n << '\n';
}

42
```

Note that the problem statement specifies that the input should be an integer between 1 and 10^9, inclusive. However, for the purposes of generating sample inputs, we have restricted the inputs to be between 1 and 42, inclusive, for simplicity.

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

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

    static class TaskC {
        public void solve(int testNumber, FastReader in, PrintWriter out) {
            long n = in.nextLong();
            List<Long> divisors = new ArrayList<>();
            for (long b = 1; b * b <= n; b++)
                if (n % b == 0) {
                    divisors.add(b);
                    divisors.add(n / b);
                }

            long min = Long.MAX_VALUE, max = 0;
            for (int i = 0; i < divisors.size(); i++) {
                long b = divisors.get(i);
                for (int j = i; j < divisors.size(); j++) {
                    long c = divisors.get(j);
                    if (n % (b * c) == 0) {
                        long a = n / (b * c);
                        long res = (a + 1) * (b + 2) * (c + 2) - n;
                        min = Math.min(min, res);
                        max = Math.max(max, res);
                    } else if (b * c > n) break;
                }
            }
            out.println(min + " " + max);
        }

    }

    static class FastReader {
        BufferedReader br;
        StringTokenizer st;

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

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

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

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

    }
}


import sys
input = sys.stdin.readline
hell=1000000007

def meowmeow321():
    n,q=map(int,input().split())
    cnt=0
    mark1 = [0]*(n+5)
    mark2 = [0]*(n+5)
    for i in range(q):
        r,c = map(int,input().split())
        if r==1:
            if mark1[c]:
                cnt-=mark2[c]
                cnt-=mark2[c+1]
                cnt-=mark2[c-1]
            else:
                cnt+=mark2[c]
                cnt+=mark2[c+1]
                cnt+=mark2[c-1]
            mark1[c]=1-mark1[c]
        else:
            if mark2[c]:
                cnt-=mark1[c]
                cnt-=mark1[c+1]
                cnt-=mark1[c-1]
            else:
                cnt+=mark1[c]
                cnt+=mark1[c+1]
                cnt+=mark1[c-1]
            mark2[c]=1-mark2[c]
        if cnt==0:
            print("Yes")
        else:
            print("No")
#t=int(input())
t=1
for i in range(t):
    meowmeow321()

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

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

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

#include <bits/stdc++.h>
using namespace std;
bool op[3][100002];
int t;
bool check(int c) {
  if (!op[1][c] && (!op[2][c] || !op[2][c - 1] || !op[2][c + 1])) {
    return false;
  } else if (!op[2][c] && (!op[1][c] || !op[1][c - 1] || !op[1][c + 1])) {
    return false;
  }
  return true;
}
int main() {
  memset(op, true, sizeof(op));
  int n, q, r, c;
  cin >> n >> q;
  for (int i = 0; i < q; i++) {
    cin >> r >> c;
    bool n1 = check(c);
    bool n2 = check(c - 1);
    bool n3 = check(c + 1);
    op[r][c] = (op[r][c] ? false : true);
    t += int((n1 ? 1 : 0) - (check(c) ? 1 : 0));
    t += int((n2 ? 1 : 0) - (check(c - 1) ? 1 : 0));
    t += int((n3 ? 1 : 0) - (check(c + 1) ? 1 : 0));
    cout << (t == 0 ? "Yes" : "No") << endl;
  }
  return 0;
}


from fractions import Fraction
import bisect
import os
from collections import Counter
import bisect
from collections import defaultdict
import math
import random
import heapq as hq
from math import sqrt
import sys
from functools import reduce, cmp_to_key
from collections import deque
import threading
from itertools import combinations
from io import BytesIO, IOBase
from itertools import accumulate

# sys.setrecursionlimit(200000)
# input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline

def input():
    return sys.stdin.readline().strip()

def iinput():
    return int(input())

def tinput():
    return input().split()

def rinput():
    return map(int, tinput())

def rlinput():
    return list(rinput())

mod = int(1e9)+7

def factors(n):
    return set(reduce(list.__add__,
                      ([i, n//i] for i in range(1, int(n**0.5) + 1) if n % i == 0)))

# ----------------------------------------------------
# sys.stdin = open('input.txt', 'r')
# sys.stdout = open('output.txt', 'w')

def zfunction(s):
    n = len(s)
    l, r = 0, 0
    Z = [0]*n
    for i in range(1, n):
        if i <= r:
            Z[i] = min(r-i+1, Z[i-l])
        while i+Z[i] < n and s[Z[i]] == s[i+Z[i]]:
            Z[i] += 1
        if i+Z[i]-1 > r:
            l, r = i, i+Z[i]-1
    return Z

s = input()
n = len(s)
Z = zfunction(s)
# for i in range(n):
#     Z[i] = min(i,Z[i])
# print(Z)
third = []
for i in range(n):
    if i+Z[i] == n:
        third.append(Z[i])
ll = len(third)
# flg = False
# print(Z)
# print(third)
ans = ""
if ll == 0:
    ans = 'Just a legend'
elif ll == 1:
    if Z.count(third[0]) >= 2 or max(Z) > third[0]:
        ans = s[:third[0]]
    else:
        ans = 'Just a legend'
else:
    if Z.count(third[0]) >= 2 or max(Z) > third[0]:
        ans = s[:third[0]]
    else:
        ans = s[:third[1]]
print(ans)

#include <bits/stdc++.h>
using namespace std;
string s;
void comp_z(vector<long> &z) {
  long n = z.size();
  z[0] = n;
  long L = -1, R = -1;
  for (int i = 1; i < n; i++) {
    if (R < i) {
      L = R = i;
      while (R < n && s[R] == s[R - L]) R++;
      z[i] = R - L;
      R--;
    } else {
      long k = i - L;
      if (z[k] < (R - i + 1)) {
        z[i] = z[k];
      } else {
        L = i;
        while (R < n && s[R] == s[R - L]) R++;
        z[i] = R - L;
        R--;
      }
    }
  }
}
int main(void) {
  cin >> s;
  int n = s.length();
  vector<long> z(n, 0);
  comp_z(z);
  long mx = 0, res = 0;
  long i;
  for (i = 1; i < n; i++) {
    if (z[i] == (n - i) && mx >= (n - i)) {
      res = n - i;
      break;
    }
    mx = max(mx, z[i]);
  }
  if (res)
    cout << s.substr(0, res);
  else
    cout << "Just a legend";
}


import java.io.*; import java.util.*;
public class CF1208F{
  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());
        }

    }

    static int MOD=998244353;
    static int[] f; static int[] g;
    static int M=21;
    public static void main(String[] args){
        FastReader br=new FastReader();
        int N=br.nextInt();
        f=new int[1<<M]; g=new int[1<<M];
        Arrays.fill(f, -1);Arrays.fill(g, -1);
        int j; int[] a=new int[N];
        for(int i=0;i<N;i++) {
        	j=br.nextInt(); a[i]=j;
                  if(f[j]==-1)f[j]=i;
                  else{
                      g[j]=f[j]; f[j]=i;
                  }
        }
        //System.out.println(Arrays.toString(f));System.out.println(Arrays.toString(g));
        for(int i=(1<<M)-1; i>=0; i--) {
        	for( j=0; j<M; j++) {
        		if((i&(1<<j))>0) {
        			merge(g[i],f[i],i^(1<<j));
        			//System.out.println(i+" "+(i^(1<<j)));
        			//System.out.println("f: "+Arrays.toString(f));
        			//System.out.println("g: "+Arrays.toString(g));
        		}
        	}
        }
        //System.out.println(Arrays.toString(f));System.out.println(Arrays.toString(g));
        int max=0; int S;
        for(int i=0;i<N-2;i++) {
        	S=0;
        	for(int b=M-1; b>=0; b--) {
        		if((a[i]&(1<<b))==0) {
        			if(g[S|(1<<b)]>i) {
        				S|=(1<<b);
        			}

        		}
        	}
        	//System.out.println(a[i]|S);
        	max=Math.max(max, a[i]|S);
        }
        System.out.println(max);
    }
    public static void merge(int a, int b, int mask) { // a<b
    	if(b>f[mask]) {
    		g[mask]=f[mask]; f[mask]=b;
    		if(a>g[mask]) {
    			g[mask]=a;
    		}
    	}else if(b>g[mask] && b!=f[mask]) {// NO DUPS!!
    		g[mask]=b;
    	}
    	if(a>g[mask]) {
    		g[mask]=a;
    	}
    }

}
//Debugging:
//Are you sure your algorithm is correct?
//Bounds: long
//Special cases: n=0,1?
//Make sure you remove your debugging code before you submit!

#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e6 + 5;
int n;
int a[maxn];
int f[maxn];
int read() {
  int x;
  scanf("%d", &x);
  return x;
}
int lowbit(int x) { return x & -x; }
int insert(int x, int y) {
  if (f[x | y] > 1) return 0;
  f[x | y]++;
  for (int nx = x, ny = 0; nx; nx ^= lowbit(nx)) {
    insert(nx ^ lowbit(nx), ny | y);
    ny |= lowbit(nx);
  }
  return 0;
}
int main() {
  int i, j;
  n = read();
  for (i = 0; i < n; i++) {
    a[n - i] = read();
  }
  int ans = 0;
  for (i = 1; i <= n; i++) {
    int ret = 0;
    for (j = 20; j >= 0; j--) {
      if ((a[i] >> j) & 1) continue;
      if (f[ret | (1 << j)] > 1) ret |= (1 << j);
    }
    if (i > 2) ans = max(ans, a[i] | ret);
    insert(a[i], 0);
  }
  printf("%d\n", ans);
  return 0;
}


#include <bits/stdc++.h>
using namespace std;
string a, b;
int main() {
  string a, b;
  cin >> a >> b;
  for (int i = 0; i < a.size(); i++) {
    if (char(tolower(a[i])) == char(tolower(b[i]))) {
      continue;
    } else if (char(tolower(a[i])) > char(tolower(b[i]))) {
      cout << 1 << endl;
      return 0;
    } else if (char(tolower(a[i])) < char(tolower(b[i]))) {
      cout << -1 << endl;
      return 0;
    }
  }
  cout << 0 << endl;
}

import java.util.*;
public class Main {
    public static void main(String[] args) {

        Scanner in = new Scanner(System.in);
        int result;
        String str1 = in.nextLine();
        String str2 = in.nextLine();
        //str1 = str1.toLowerCase();
       // str2 = str2.toLowerCase();
        result = str1.compareToIgnoreCase(str2);
        if(result == 0)
            System.out.println("0");
        else if(result!=0 && result <0)
            System.out.println("-1");
        else if(result!=0 && result > 0)
            System.out.println("1");

        }

        }


    import java.util.*;
    import java.io.*;
    public class C{
    	public static void main(String[] args) {
    		MyScanner scan = new MyScanner();
            PrintWriter pw = new PrintWriter(System.out);
            int n = scan.nextInt();
            long sum1 = 0,sum2 = 0;
            for(int i = 0;i < n;i++)
                sum1+=scan.nextInt();
            for(int i = 0;i < n;i++)
                sum2+=scan.nextInt();
            if(sum2 <= sum1)
                System.out.println("Yes");
            else
                System.out.println("No");
            pw.close();
     	}
    }

    //-------------------------------------------------------------------------------------------------------
    class MyScanner {
        BufferedReader br;
        StringTokenizer st;

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

        public int mod(long x) {
            // TODO Auto-generated method stub
            return (int) x % 1000000007;
        }

        public int mod(int x) {
            return x % 1000000007;
        }

        boolean hasNext() {
            if (st.hasMoreElements())
                return true;
            try {
                st = new StringTokenizer(br.readLine());
            } catch (IOException e) {
                e.printStackTrace();
            }
            return st.hasMoreTokens();
        }

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

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

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

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

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

#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const long long int llINF = 0x3f3f3f3f3f3f3f;
int main() {
  int n;
  cin >> n;
  long long int a = 0, b = 0;
  for (int i = 0; i < n; i++) {
    int x;
    cin >> x;
    a += x;
  }
  for (int i = 0; i < n; i++) {
    int x;
    cin >> x;
    b += x;
  }
  if (a >= b)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}


n=int(input())
a=list(map(int,input().split()))
print(2*min(abs(180-sum(a[l:r])) for l in range(n) for r in range(l,n)))

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

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

    static class codefces {
        int[] ar;

        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.nextInt();
            ar = in.nextIntArray(n);
            int pre[] = new int[n + 1];
            for (int i = 1; i <= n; i++) {
                pre[i] += pre[i - 1] + ar[i - 1];
            }
            int min = 360;
            for (int i = 0; i < n; i++) {
                for (int j = i; j < n; j++) {
                    int part1 = pre[j + 1] - pre[i];
                    min = Math.min(min, Math.abs(part1 * 2 - 360));
                }
            }
            out.print(min);

        }

    }

    static class InputReader {
        private final InputStream stream;
        private final byte[] buf = new byte[8192];
        private int curChar;
        private int snumChars;

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

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

        public int nextInt() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            int res = 0;
            do {
                res *= 10;
                res += c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

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

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

    }
}


# Main maut ko takiya, aur kafan ko chaadar banakkar audhta hoon!

a,b=input().split()

if a[:-1]!=b[:-1]:
	print("0")

else:
	ans=1

	for i in range(int(a[-1])+1,int(b[-1])+1):
		ans*=i
		ans=ans%10
	print(ans)

#include <bits/stdc++.h>
using namespace std;
int main() {
  long long A, B;
  cin >> A >> B;
  long long ret = 1;
  for (long long i = A + 1; i <= B; i++) {
    ret *= i;
    ret %= 10;
    if (ret == 0) {
      cout << 0;
      return 0;
    }
  }
  cout << ret;
  return 0;
}


//package neerc2017;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.InputMismatchException;

public class G {
	InputStream is;
	PrintWriter out;
	String INPUT = "";

	void solve()
	{
		int n = ni();
		int[] f = new int[7];
		for(int i = 0;i < n;i++){
			char[] s = ns(7);
			for(int j = 0;j < 7;j++){
				f[j] += s[j]-'0';
			}
		}
		out.println(Arrays.stream(f).max().getAsInt());
	}

	void run() throws Exception
	{
		is = oj ? System.in : new ByteArrayInputStream(INPUT.getBytes());
		out = new PrintWriter(System.out);

		long s = System.currentTimeMillis();
		solve();
		out.flush();
		tr(System.currentTimeMillis()-s+"ms");
	}

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

	private byte[] inbuf = new byte[1024];
	public int lenbuf = 0, ptrbuf = 0;

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

	private boolean isSpaceChar(int c) { return !(c >= 33 && c <= 126); }
	private int skip() { int b; while((b = readByte()) != -1 && isSpaceChar(b)); return b; }

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

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

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

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

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

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

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

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

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

	private boolean oj = System.getProperty("ONLINE_JUDGE") != null;
	private void tr(Object... o) { if(!oj)System.out.println(Arrays.deepToString(o)); }
}

#include <bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
const int N = 300;
int n, cnt[N];
int ans;
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) {
    string st;
    cin >> st;
    for (int j = 0; j < st.size(); j++) {
      if (st[j] == '1') cnt[j]++;
    }
  }
  for (int i = 0; i < 10; i++) {
    ans = max(ans, cnt[i]);
  }
  cout << ans << endl;
  cin.get();
  cin.get();
  return 0;
}


#include <bits/stdc++.h>
using namespace std;
int n, m, maxl, step, tmp;
string s, t;
int main() {
  cin >> n >> m;
  cin >> s >> t;
  for (int i = 0; i <= m - n; i++) {
    tmp = 0;
    for (int j = 0; j < n; j++) {
      if (s[j] == t[i + j]) {
        tmp++;
      }
    }
    if (tmp > maxl) {
      maxl = tmp;
      step = i;
    }
  }
  cout << n - maxl << endl;
  for (int i = 0; i < n; i++) {
    if (s[i] != t[i + step]) {
      cout << i + 1 << ' ';
    }
  }
  return 0;
}

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.util.ArrayList;
import java.util.function.BiConsumer;
import java.util.function.Consumer;

public class Main {

    private BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(System.out));
    private BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));

    private void run() throws IOException {
        String line;
        while ((line = reader.readLine()) != null) {
            Holder holder = new Holder();
            parseLine(line, holder);
            holder.s = reader.readLine()
                             .trim();
            holder.t = reader.readLine()
                             .trim();
            solve(holder);
            writer.newLine();
        }
    }

    private void solve(Holder holder) throws IOException {
        loop(holder.t, (i, ct) -> {
            if (i + holder.s.length() <= holder.t.length()) {
                final ArrayList<Integer> indices = new ArrayList<>();
                loop(holder.s, (j, cs) -> {
                    char c = holder.t.charAt(i + j);
                    if (c != cs) {
                        indices.add(j + 1);
                    }
                });
                if (indices.size() < holder.min) {
                    holder.indices = indices;
                    holder.min = indices.size();
                }
            }
        });
        writer.write(holder.min + "");
        writer.newLine();
        for (Integer index : holder.indices) {
            writer.write(index + "");
            writer.write(" ");
        }
    }

    private void parseLine(String line, Holder holder) {
    }

    private void tearDown() throws IOException {
        writer.flush();
        reader.close();
        writer.close();
    }

    private static void loop(String s, BiConsumer<Integer, Character> consumer) {
        for (int i = 0; i < s.length(); i++) {
            consumer.accept(i, s.charAt(i));
        }
    }

    private static void loop(String s, Consumer<Character> consumer) {
        loop(s, (i, c) -> consumer.accept(c));
    }

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

    private static class Holder {
        public ArrayList<Integer> indices = new ArrayList<>();
        String s, t;
        int min = Integer.MAX_VALUE;
    }

}


#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  string s1, s2;
  cin >> s1 >> s2;
  sort(s1.begin(), s1.end());
  sort(s2.begin(), s2.end());
  int minf = n - 1, maxf = 0;
  for (int i = n - 1; i >= 0; i--) {
    if (s1[i] <= s2[minf]) minf--;
  }
  cout << minf + 1 << endl;
  for (int i = 0; i < n; i++) {
    if (s2[i] > s1[maxf]) maxf++;
  }
  cout << maxf << endl;
  return 0;
}

n = int(input())
s = list(map(int, list(input())))
m = map(int, list(input()))

ma = [0] * 10
for dig in m:
    ma[dig] += 1

ma2 = list(ma)

min_f = 0
for nu in s:
    for x in range(nu, 10):
        if ma[x] > 0:
            ma[x] -= 1
            break
    else:
        min_f += 1
        for z in range(len(ma)):
            if ma[z] > 0:
                ma[z] -= 1
                break

print(min_f)

ma = ma2

max_f = 0
for nu in s:
    for x in range(nu+1, 10):
        if ma[x] > 0:
            ma[x] -= 1
            max_f += 1
            break
    else:
        for z in range(len(ma)):
            if ma[z] > 0:
                ma[z] -= 1
                break

print(max_f)


etaj, kvart = map(int, input().split())
Okna = []

notsleep = 0

for i in range(0, etaj):
    Okna.append(list(map(int, input().split())))

for i in range(0, etaj):
    for j in range(0, (kvart*2)-1, 2):
        if Okna[i][j] or Okna[i][j+1] == 1:
            notsleep += 1

print(notsleep)

#include <bits/stdc++.h>
using namespace std;
int n, m, a = -1;
int main() {
  while (cin >> n >> m) a += n + m > 0;
  cout << a;
}