#include <bits/stdc++.h>
using namespace std;
const int MaxN = int(2e5);
const long double pi = 3.1415926535897932384626433832795;
char s[MaxN];
int main() {
  while (gets(s)) {
    int len = strlen(s);
    int tmp = (len - 2) / 2 + len % 2;
    int one = 0, two = 0;
    for (int i = (0); i <= (len - 1); i++) {
      one += s[i] == '1';
      two += s[i] == '?';
    }
    if (one <= tmp) puts("00");
    if (one + two >= tmp + 1 && one < tmp + 2) {
      if (s[len - 1] == '1' || (s[len - 1] == '?' && one < tmp + 1)) puts("01");
      if (s[len - 1] == '0' || (s[len - 1] == '?' && one + two - 1 > tmp))
        puts("10");
    }
    if (one + two >= tmp + 2) puts("11");
    puts("");
  }
  return 0;
}

def evaluate(a):
    c1 = a.count('1')
    c0 = a.count('0')
    n = len(a)

    A = (n - 1) // 2
    B = (n - 2) // 2

    if c1 <= A:
        return '00'
    if c0 <= B:
        return '11'
    p1 = a.rfind('1')
    p0 = a.rfind('0')
    if p0 < p1:
        return '01'
    else:
        return '10'

a = input()
x = []
x.append(evaluate(a.replace('?', '0')))
x.append(evaluate(a.replace('?', '1')))
n = len(a)
c1 = a.count('1')
c0 = a.count('0')
A = (n - 1) // 2
B = (n - 2) // 2

x.append(evaluate(a.replace('?', '0', B + 1 - c0).replace('?', '1')))
x.append(evaluate(a.replace('?', '1', A + 1 - c1).replace('?', '0')))

for ans in sorted(list(set(x))):
    print(ans)


import sys

reader = (line.rstrip() for line in sys.stdin)
input = reader.__next__

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

def limit(n):
    if n < 3:
        return 0
    if n ^ 1:
        return ((n - 1) * (n - 1)) >> 2
    else:
        return ((n - 2) * n) >> 2

if m > limit(n):
    print(-1)
    sys.exit()
elif not m:
    ans = [10 ** 8 + 1]
    while len(ans) < n:
        ans.append(ans[-1] + 10 ** 4)
    print(*ans)
    sys.exit()

L = 3
R = n + 1
while L + 1 < R:
    k = (L + R) >> 1
    if limit(k) > m:
        R = k
    else:
        L = k
k = L
ans = list(range(1, k + 1))

req = m - limit(k)
if req > 0:
    ans.append(ans[-1] + ans[-2 * req])
    k += 1
big_num = 10 ** 8 + 1
for i in range(k, n):
    ans.append(big_num)
    big_num += 10 ** 4

print(*ans)

import java.util.Arrays;
import java.util.*;
public class ozon
{
	public static void main (String[] args)
	 {
		Scanner sc=new Scanner(System.in);
		long t,i;
		long n=sc.nextInt();
		long m=sc.nextInt();
		if(n<3&&m==0)
		{
			if(n==1)
				System.out.print(1);
			else
				System.out.print(1+" "+2);
			return;
		}
		else if(n<3&&m!=0)
		{
			System.out.println(-1);
			return;
		}
		ArrayList<Integer> ans=new ArrayList();
		while(m>0)
		{
			long vo=1;
			i=1;
			while(m>vo)
			{
				vo=i*i;
				i++;
			}
			i-=2;
			long ve=(vo + i*i)/2;
			vo=i*i;
			i=i*2+1;
			long dev=m-ve;
			if(dev>=0)
			{
				i++;
				m-=ve;
			}
			else
				m-=vo;
			if(ve==1)
			{
				i++;
				i=i*2+1;
			}
			for(int j=1;j<=i;j++)
				ans.add(j);
			if(m==0)
				break;
			else
			{
				int c=ans.get(ans.size()-1-(int)m);
				int d=ans.get(ans.size()-(int)m);
				ans.add(c+d);
			}
			break;
		}
		int v;
		if(ans.isEmpty())
			v=1;
		else
			v=ans.get(ans.size()-1);
		i=3;
		while(ans.size()<n)
		{
			if(ans.isEmpty())
				ans.add(1);

			int g=v*(int)i;
			ans.add(g);
			i+=2;
		}
		if(ans.size()>n)
		{
			System.out.println(-1);
			return;
		}
		else
		{
			for(i=0;i<ans.size();i++)
				System.out.print(ans.get((int)i)+" ");
		}
	}
}


#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
const int MOD = 1e9 + 7;
char s[N];
int dp[N];
int main() {
  scanf("%s", s + 1);
  memset(dp, 0, sizeof(dp));
  int len = strlen(s + 1);
  dp[0] = 1;
  dp[1] = 1;
  for (int i = 2; i <= len; i++) {
    if (s[i] == 'n' || s[i] == 'u') {
      if (s[i] == s[i - 1]) {
        dp[i] = (dp[i - 2] + dp[i - 1]) % MOD;
        continue;
      }
    } else if (s[i] == 'm' || s[i] == 'w') {
      dp[len] = 0;
      break;
    }
    dp[i] = dp[i - 1];
  }
  if (s[1] == 'm' || s[1] == 'w') dp[len] = 0;
  printf("%d\n", dp[len]);
}


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

public class Main implements Runnable
{
    boolean multiple = false;
    long MOD = 998244353;

    @SuppressWarnings("Duplicates")
    void solve() throws Exception
    {
        int n = sc.nextInt();
        String s = sc.nextToken();
        int one = 0, zero = 0;
        for (int i = 0; i < n; i++)
            if (s.charAt(i) == 'n') one++; else if (s.charAt(i) == 'z') zero++;
        for (int i = 0; i < one; i++)
            p(1 + " ");
        for (int i = 0; i < zero; i++)
            p(0 + " ");
        pl();
    }

    StringBuilder ANS = new StringBuilder();
    void p(String s) { ANS.append(s); } void p(double s) {ANS.append(s); } void p(long s) {ANS.append(s); } void p(char s) {ANS.append(s); }
    void pl(String s) { ANS.append(s); ANS.append('\n'); } void pl(double s) { ANS.append(s); ANS.append('\n'); } void pl(long s) { ANS.append(s); ANS.append('\n'); } void pl(char s) { ANS.append(s); ANS.append('\n'); } void pl() { ANS.append(('\n')); }
    /*I/O, and other boilerplate*/ @Override public void run() { try { in = new BufferedReader(new InputStreamReader(System.in));out = new PrintWriter(System.out);sc = new FastScanner(in);if (multiple) { int q = sc.nextInt();for (int i = 0; i < q; i++) solve(); } else solve(); System.out.print(ANS); } catch (Throwable uncaught) { Main.uncaught = uncaught; } finally { out.close(); }} public static void main(String[] args) throws Throwable{ Thread thread = new Thread(null, new Main(), "", (1 << 26));thread.start();thread.join();if (Main.uncaught != null) {throw Main.uncaught;} } static Throwable uncaught; BufferedReader in; FastScanner sc; PrintWriter out; } class FastScanner { BufferedReader in; StringTokenizer st; public FastScanner(BufferedReader in) {this.in = in;}public String nextToken() throws Exception { while (st == null || !st.hasMoreTokens()) { st = new StringTokenizer(in.readLine()); }return st.nextToken(); }public int nextInt() throws Exception { return Integer.parseInt(nextToken()); }public long nextLong() throws Exception { return Long.parseLong(nextToken()); }public double nextDouble() throws Exception { return Double.parseDouble(nextToken()); }
}

n = int(input())
s = input()
for i in range(s.count('n')): print(1, end = ' ')
for i in range(s.count('z')): print(0, end = ' ')


#include <bits/stdc++.h>
using namespace std;
string s, s1;
bool check(string ans) {
  int pos = 0;
  for (int i = 0; i < ans.size(); i++) {
    if (ans[i] == s1[pos]) {
      pos++;
    }
  }
  if (pos == s1.size())
    return true;
  else
    return false;
}
int main() {
  cin >> s >> s1;
  int ans = 0;
  for (int i = 0; i < s.size(); i++) {
    for (int j = 0; j < s.size() - i + 1; j++) {
      string res = "";
      for (int k = 0; k < i; k++) res += s[k];
      for (int k = j + i; k < s.size(); k++) res += s[k];
      if (check(res)) {
        ans = max(ans, j);
      }
    }
  }
  cout << ans << endl;
}

big=input()
small=input()
pre=[]
post=[]
i=0
j=0
while 1:
    if j==len(small):
        break
    if big[i]==small[j]:
        pre.append(i)
        i+=1
        j+=1
    else:
        i+=1

big=big[::-1]
small=small[::-1]
i=0
j=0

while 1:
    if j==len(small):
        break
    if big[i]==small[j]:
        post.append(i)
        i+=1
        j+=1
    else:
        i+=1

for i in range(len(small)):
    post[i]=(len(big)-1)-post[i]

post.reverse()

ans=max(post[0],(len(big)-(pre[-1]+1)   ))

for i in range(len(small)-1):
    ans=max(ans,(post[i+1]-(pre[i]+1)  ))
print(ans)


n = int(input())
l = []
se = set()
for _ in range(n):
    st = input()
    s = st[0:1]
    l.append(s)
    se.add(s)

su = 0
for s in se:
    c = l.count(s)
    if c>1:
        x = c//2
        y = c-x
        su += ((x*(x-1))+(y*(y-1)))//2

print(su)

7
kambei
gorobei
shichiroji
kyuzo
heihachi
katsushiro
kikuchiyo

10
nr
bifiedubnohaektjox
zxghhzkwfpbsmfsrvzry
jkv
qppaqotfnqkogvsxyphj
gjewi
dzonunipvwclfwfngx
iwu
zafueotqtrbntjy
nvp

7
alpha
beta
gamma
delta
epsilon
epsilon
zeta

7
alpha
alpha
alpha
alpha
alpha
alpha
alpha

6
alpha
beta
gamma
delta
epsilon
epsilon

20
grkbifiedu
gohaektjox
yxghhzkwfp
gmfsrvzr
jjkvyqppaq
mfnqko
ysxyphjvgj
jixdzo
ynipv
ilfwfngxa
gutza
geotqtrb
gjytnvppb
myllmkvnot
jafckw
jfccigs
jwabzf
mjzeoxrui
gctsja
yvxpeybbh

6
olivia
jacob
tanya
jack
oliver
jessica

7
bravo
charlie
delta
echo
foxtrot
golf
hotel

100
m
g
m
m
m
g
g
m
g
m
g
g
g
m
g
g
g
m
m
m
g
m
g
g
g
m
g
g
g
g
m
g
g
m
g
g
m
m
g
m
m
m
g
g
g
g
m
m
m
m
m
g
g
g
m
m
m
m
g
g
g
m
g
m
m
g
g
g
m
g
g
g
g
m
g
g
m
g
g
g
m
g
m
m
m
m
g
g
g
g
g
m
m
g
g
m
g
m
m
m

20
mrkbifiedu
mohaektjox
gxghhzkwfp
mmfsrvzr
mjkvyqppaq
mfnqko
msxyphjvgj
mixdzo
mnipv
glfwfngxa
mutza
meotqtrb
mjytnvppb
gyllmkvnot
gafckw
mfccigs
mwabzf
mjzeoxrui
gctsja
mvxpeybbh

import java.io.*;

public class Main1166A
{
    static int count[] = new int[26];
    static int dp[][] = new int[51][3];
    public static void main(String[] args) throws IOException
    {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
        int N = Integer.parseInt(br.readLine());
        int sum = 0;
        for(int i=0;i<N;++i)
        {
            char c = br.readLine().charAt(0);
            count[c-'a']++;
        }
        dp[2][0] = 1; dp[2][1] = 2; dp[2][2] = 1;
        for(int i=3;i<51;++i)
        {
            dp[i][0] = 1;
            dp[i][1] = dp[i-1][0] + dp[i-1][1];
            dp[i][2] = dp[i-1][1] + dp[i-1][2];
        }
        for(int i=0;i<26;++i)
        {
            sum += (((count[i]/2)>=2)?(dp[count[i]/2][2]):0);
            sum += ((count[i]-count[i]/2))>=2?dp[(count[i]-count[i]/2)][2]:0;
        }
        bw.write(sum+"");
        bw.close();
    }

}


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

import math

k = ['', 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine', 'ten', 'eleven', 'twelve', 'thirteen', 'fourteen', 'fifteen', 'sixteen', 'seventeen', 'eighteen', 'nineteen']
n = ['', '', 'twenty', 'thirty', 'forty', 'fifty', 'sixty', 'seventy', 'eighty', 'ninety']

a = int(input())
if a < 20:
    a = k[a]
else:
    a = n[a // 10]+k[a % 10]
b = 'k' in a or 'a' in a or 'n' in a
print('NO' if b else 'YES')


n,k=map(int,input().split())
if(n>(k*(k-1))):
    print('NO')
else:
    ans=[0 for i in range(n)]
    for i in range(len(ans)):
        ans[i]=(i+1)%k
        if(ans[i]==0):
            ans[i]=k
    count=1
    temp=[0 for i in range(len(ans))]
    for i in range(len(ans)):
        if(i%k==0):
            temp[i]=count+1
            count+=1
        else:
            temp[i]=temp[i-1]+1
            if(temp[i]>k):
                temp[i]%=k
    print('YES')
    for i in range(n):
        print(ans[i],temp[i])

#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long n, k;
  cin >> n >> k;
  vector<array<int, 2>> ats;
  for (int i = 1; i <= k; i++)
    for (int j = i + 1; j <= k; j++) {
      ats.push_back({i, j});
      ats.push_back({j, i});
      if (ats.size() >= n) break;
    }
  if (ats.size() < n) return cout << "NO", 0;
  cout << "YES\n";
  for (int i = 0; i < n; i++) cout << ats[i][0] << " " << ats[i][1] << "\n";
}


#include <bits/stdc++.h>
using namespace std;
long long sz;
bool valido(const long long &p) { return (p < sz); }
int main() {
  string s, r, b, o;
  cin >> s;
  sz = int(s.size());
  for (long long i = 0; i < sz; i++) {
    if (s[i] == '1')
      r += s[i];
    else
      b += s[i];
  }
  bool a = false;
  for (long long i = 0; i < int(b.size()) && !a; i++) {
    if (b[i] == '2') {
      b.insert(i, r);
      a = true;
    }
  }
  if (!a) b += r;
  if (int(b.size()))
    cout << b << "\n";
  else
    cout << r << "\n";
  return 0;
}

s = input()
s = list(s)
n = len(s)
i=0
j = i
while j<n and s[j]!='2':
    j+=1

a = sorted(s[i:j])

one = []
others = []
while j<n:
    if s[j]=='1':
        one+=[s[j]]
    else:
        others+=[s[j]]
    j+=1

ans = a+one+others

print(''.join(ans))


import java.io.*;
import java.util.*;
/* REMINDERS
 * CHECK INT VS LONG, IF YOU NEED TO STORE LARGE NUMBERS
 * CHECK CONSTRAINTS, C <= N <= F...
 * CHECK SPECIAL CASES, N = 1...
 * CHECK ARRAY BOUNDS, HOW BIG ARRAY HAS TO BE
 * TO TEST TLE/MLE, PLUG IN MAX VALS ALLOWED AND SEE WHAT HAPPENS
 * ALSO CALCULATE BIG-O, OVERALL TIME COMPLEXITY
 */

public class FadiLCMEfficient {
	public static void main(String[] args) throws IOException {
		//get input separately
		BufferedReader b = new BufferedReader(new InputStreamReader(System.in));
		PrintWriter p = new PrintWriter(new BufferedOutputStream(System.out));
		StringTokenizer s = new StringTokenizer(b.readLine());
		long x = Long.parseLong(s.nextToken());

		//edge case: x = 1
		long[] ints = new long[] {1,1};
		if (x != 1) {
			ints = printDivisors(x);
			Arrays.sort(ints);
		}
		p.println(ints[0] + " " + ints[1]);
		p.close();

	}

	// Recursive method to return gcd of a and b
	public static long gcd(long a, long b)
    {
    if (a == 0)
        return b;
    return gcd(b % a, a);
    }

    // method to return LCM of two numbers
    public static long lcm(long a, long b)
    {
        return (a*b)/gcd(a, b);
    }
    public static long[] printDivisors(long n)
    {
    	//find smallest such factors, taking the max
    	long curr = n;
    	long first = 0;
    	long sec = 0;

        //find first divisors under sqrt n
    	for (long i = (long)(Math.sqrt(n)); i > 0; i--) {
    		if (n % i == 0 && lcm(i, n / i) == n) {
    			curr = i;
    			break;
    		}
    	}

        return new long[] {curr, n / curr};

    }

}

def LMC(a, b):
    n = a * b
    while a != 0 and b != 0:
        if a > b:
            a = a % b
        else:
            b = b % a
    nod = a + b
    nok = n // nod

    return nok

from math import sqrt, ceil
n = int(input())
dividers = []
for i in range(1, ceil(sqrt(n))):
    if n % i == 0:
        dividers.append([i, n // i])
dividers_with_LMC = []
for el in dividers:
    if LMC(el[0], el[1]) == n:
        dividers_with_LMC.append(el)
if n == 1:
    print('1 1')
else:
    print(*dividers_with_LMC[-1])


import sys
from sys import argv

def extendedEuclideanAlgorithm(old_r, r):
    negative = False
    s, old_t = 0, 0
    old_s, t = 1, 1

    if (r < 0):
        r = abs(r)
        negative = True

    while r > 0:
        q = old_r // r
        #MCD:
        r, old_r = old_r - q * r, r
        #Coeficiente s:
        s, old_s = old_s - q * s, s
        #Coeficiente t:
        t, old_t = old_t - q * t, t

    if negative:
        old_t = old_t * -1

    return old_r, old_s, old_t

n, p, w, d = [int(i) for i in input().split()]

mcd, s, t = extendedEuclideanAlgorithm(w, d)
if p % mcd == 0:
    a1, b1, c1 = -w // mcd, d // mcd, p // mcd
    x1, y1 = s * c1, t * c1

    k = y1 * mcd // w
    x0 = x1 + (d * k) // mcd
    y0 = y1 - (w * k) // mcd

    if x0 + y0 <= n and x0 >= 0 and y0 >= 0:
        print(x0, y0, n - x0 - y0)
    else:
        print(-1)
else:
    print(-1)

import java.util.*;
import java.io.*;
public class C592
{
    public static void main(String [] args)
    {
        MyScanner sc = new MyScanner();
        PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out));
        long n = sc.nextLong(); long p = sc.nextLong(); long w = sc.nextLong(); long d = sc.nextLong();
        boolean ok = false; long x = -1; long q = -1; long z = -1;
        for (int y = 0; y <= w - 1; y++) {
            long dif = p - y * d;
            if (dif % w == 0 && dif / w + y <= n && dif / w >= 0 && dif / w + y >= 0) {
                ok = true; q = y; x = dif / w; z = n - x - q; break;
            }
        }
        if (ok) {
            out.println(x + " " + q + " " + z);
        } else out.println(-1);
        out.close();
    }

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

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

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

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

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

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

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

    }

}


#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, y, x, sum = 0;
  string str;
  cin >> n >> x >> y >> str;
  int len = str.size() - 1;
  for (int i = len; i > len - x; i--) {
    if (str[i] == '1') sum++;
  }
  if (str[len - y] == '0')
    sum++;
  else
    sum--;
  cout << sum << endl;
  return 0;
}


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

public class temp
{
	void solve()
	{
		FastReader sc = new FastReader();
		int n = sc.nextInt();
		int k = sc.nextInt();

		TreeMap<Integer,Integer> tm = new TreeMap<>();

		for(int i=0;i<n;i++)
		{
			int x = sc.nextInt();
			if(tm.containsKey(x))
				tm.put(x,tm.get(x)+1);
			else
				tm.put(x,1);
		}

		int ans = 0;
		int prek = tm.firstKey();
		int precount = tm.get(prek);
		tm.remove(prek);

		while(!tm.isEmpty())
		{
			int key = tm.firstKey();
			int count = tm.get(key);
			tm.remove(key);

			if(prek + k >= key)
				ans+=precount;

			prek = key;
			precount = count;
		}

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

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

    static class FastReader
    {
        BufferedReader br;
        StringTokenizer st;

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

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

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

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

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

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

#include <bits/stdc++.h>
using namespace std;
const int N = 200 * 1000 + 555;
int n, k, a[N];
int main() {
  cin >> n >> k;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  sort(a, a + n);
  a[n++] = int(2e9);
  int ans = 0, u = 0;
  for (int i = 0; i < n - 1; i++) {
    while (u < n && a[i] == a[u]) u++;
    if (a[u] - a[i] > k) ans++;
  }
  cout << ans << endl;
  return 0;
}


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

public class A443 {

	public static void main(String[] args) {
		InputReader in = new InputReader(System.in);
		OutputWriter out = new OutputWriter(System.out);
		int n = in.readInt();
		int arr[] = new int[n];
		int flag = 3;
		int j = 0;
		int ans = 0;
		while (j < n) {
			arr[j] = in.readInt();
			if (arr[j] == flag) {
				ans = -1;
				break;
			} else {
				if (arr[j] == 1) {
					if (flag == 2) {
						flag = 3;
					} else {
						flag = 2;
					}
				} else if (arr[j] == 2) {
					if (flag == 1) {
						flag = 3;
					} else {
						flag = 1;
					}
				} else {
					if (flag == 1) {
						flag = 2;
					} else {
						flag = 1;
					}
				}
			}
			j++;
		}
		if (ans == 0) {
			System.out.println("YES");
		} else {
			System.out.println("NO");
		}
		out.close();
	}

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

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

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

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

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

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

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

		public String next() {
			return readString();
		}
	}

	private static class OutputWriter {
		private final PrintWriter writer;

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

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

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

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

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

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


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

public class D {

	public static void main(String[] args){
		FastScanner scan = new FastScanner();
		PrintWriter out = new PrintWriter(System.out);
		int n = scan.nextInt(), g = scan.nextInt();
		int[] a = new int[n], b = new int[n];
		double[] p = new double[n];
		for(int i = 0; i < n; i++) {
			a[i] = scan.nextInt();
			b[i] = scan.nextInt();
			p[i] = scan.nextDouble()/100.0;
		}
		double lo = 0, hi = 1e9;
		for(int bs = 0; bs < 100; bs++) {
			double mid = (lo+hi)/2;
			double[][] dp = new double[60][5010];
			for(int i = 0; i <= g; i++) dp[n][i] = i;
			for(int i = g+1; i < dp[0].length; i++) dp[n][i] = 1e9;
			for(int i = n-1; i >= 0; i--) {
				for(int j = 0; j < dp[0].length-100; j++) {
					dp[i][j] += Math.min(mid+a[i]+j, dp[i+1][j+a[i]])*p[i];
					dp[i][j] += Math.min(mid+b[i]+j, dp[i+1][j+b[i]])*(1.0-p[i]);
				}
			}
			if(dp[0][0] < mid) hi = mid;
			else lo = mid;
		}
		out.println(hi);
		out.close();
	}

	static class FastScanner {
		BufferedReader br;
		StringTokenizer st;

		public FastScanner() {
			try	{
				br = new BufferedReader(new InputStreamReader(System.in));
				st = new StringTokenizer(br.readLine());
			} catch (Exception e){e.printStackTrace();}
		}

		public String next() {
			if (st.hasMoreTokens())	return st.nextToken();
			try {st = new StringTokenizer(br.readLine());}
			catch (Exception e) {e.printStackTrace();}
			return st.nextToken();
		}

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

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

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

		public String nextLine() {
			String line = "";
			if(st.hasMoreTokens()) line = st.nextToken();
			else try {return br.readLine();}catch(IOException e){e.printStackTrace();}
			while(st.hasMoreTokens()) line += " "+st.nextToken();
			return line;
		}

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

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

		public double[] nextDoubleArray(int n){
			double[] a = new double[n];
			for(int i = 0; i < n; i++) a[i] = nextDouble();
			return a;
		}

		public char[][] nextGrid(int n, int m){
			char[][] grid = new char[n][m];
			for(int i = 0; i < n; i++) grid[i] = next().toCharArray();
			return grid;
		}
	}

}


n, k, m = list(map(int, input().split()))
t = sorted(map(int, input().split()))
res = 0
for x in range(min(m//sum(t),n)+1):
    rem = m - x*sum(t)
    r = x*(k+1)
    for i in range(k):
        div = min(rem//t[i], n-x)
        rem -= div*t[i]
        r += div
    res = max(res, r)
print(res)

#include <bits/stdc++.h>
using namespace std;
const int INF = numeric_limits<int>::max();
const long long LLINF = numeric_limits<long long>::max();
const unsigned long long ULLINF = numeric_limits<unsigned long long>::max();
const double PI = acos(-1.0);
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  long long t[50];
  long long n, k, M;
  cin >> n >> k >> M;
  long long sum = 0;
  for (int i = 0; i < k; i++) cin >> t[i], sum += t[i];
  sort(t, t + k);
  long long ans = 0;
  for (int s = 0; s <= n; s++) {
    if (sum * s > M) break;
    long long p = n - s;
    long long T = M - sum * s;
    long long cur = (k + 1) * s;
    for (int i = 0; i < k; i++) {
      long long take = min(T / t[i], p);
      cur += take;
      T -= take * t[i];
    }
    ans = max(ans, cur);
  }
  cout << ans;
  return 0;
}


#include <bits/stdc++.h>
int main(void) {
  int Count, Number;
  char E[5];
  scanf("%d", &Number);
  gets(E);
  char String[Number + 1];
  gets(String);
  for (Count = 0; Count < Number; Count++) {
    if (String[Count] != 'a' && String[Count] != 'e' && String[Count] != 'i' &&
        String[Count] != 'o' && String[Count] != 'u' && String[Count] != 'y')
      printf("%c", String[Count]);
    else {
      if (String[Count] != String[Count - 1]) printf("%c", String[Count]);
      if ((String[Count] == 'e' || String[Count] == 'o') &&
          String[Count - 1] == String[Count] &&
          String[Count - 2] != String[Count] &&
          String[Count + 1] != String[Count])
        printf("%c", String[Count]);
    }
  }
  printf("\n");
  return 0;
}

pobeda aoiuyeggghhh eoo implemeentatioon aeiouyaeeioouy o a aeiouyaeeioouyaeiouy

import math
from sys import stdin, stdout

fin = stdin
fout = stdout

n = int(fin.readline().strip())
s = fin.readline().strip()
ans = []

gl = frozenset({'a', 'e', 'i', 'y', 'o', 'u'})

met = False
cdel = False
for i in range(n):

    if i > 0:
        if s[i] != s[i - 1]:
            met = False
            cdel = False
            ans.append(s[i])
        else:
            if s[i] in gl:
                if s[i] == 'e' or s[i] == 'o':
                    if not met:
                        ans.append(s[i])
                    elif not cdel:
                        ans.pop()
                        cdel = True
                met = True
            else:
                ans.append(s[i])
    else:
        ans.append(s[i])

fout.write(''.join(ans))


f = lambda: map(int, input().split())
n, k = f()
p = sorted(f())

m, d = n // k, n % k
u, v = d + 1, k - d + 1
g = [0] * u * v

i = 0
for a in range(u):
    j = a * m + a - 1
    for b in range(v):
        x = g[i - 1] + p[j] - p[j - m + 1] if b else 9e9
        y = g[i - v] + p[j] - p[j - m] if a else 9e9
        if i: g[i] = min(x, y)
        i += 1
        j += m
print(g[-1])

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
const ll inf = 1E17;
const ll mod = 1;
ll a[300010];
int n, k, chnk;
ll dp[5001][5001];
ll solve(int pos, int xtra, int l) {
  if (pos == 0) {
    if (xtra == 0) return 0;
    return inf;
  }
  ll &ret = dp[pos][xtra];
  if (ret != -1) return ret;
  ret = a[l + chnk - 1] - a[l] + solve(pos - 1, xtra, l + chnk);
  if (xtra)
    ret = min(ret, a[l + chnk] - a[l] + solve(pos - 1, xtra - 1, l + chnk + 1));
  return ret;
}
int main() {
  ios_base::sync_with_stdio(false);
  while (cin >> n >> k) {
    for (int i = 1; i <= n; i++) {
      cin >> a[i];
    }
    sort(a + 1, a + n + 1);
    memset(dp, -1, sizeof dp);
    chnk = n / k;
    cout << solve(k, n % k, 1) << endl;
  }
  return 0;
}


#include <bits/stdc++.h>
using namespace std;
int main() {
  int t = 0, sl = 0;
  char s[100010];
  cin >> s;
  for (int i = 0; i < strlen(s); i++)
    if (s[i] == '#') {
      t++;
    } else if (s[i] == '(')
      sl++;
    else
      sl--;
  if (sl <= 0)
    cout << "-1";
  else {
    int t1 = 0, t2 = 0;
    for (int i = 0; i < strlen(s); i++) {
      if (s[i] == '#') {
        t1++;
        if (t1 != t) {
          t2--;
        } else
          t2 = t2 - sl + t - 1;
      } else if (s[i] == '(')
        t2++;
      else
        t2--;
      if (t2 < 0) {
        cout << "-1";
        return 0;
      }
    }
    for (int i = 1; i < t; i++) cout << '1' << endl;
    cout << sl - t + 1;
  }
}

#!/usr/bin/env python3

s = input()
count = 0
res = []
last = s.rfind("#")

for i, c in enumerate(s):
    if c == '(':
        count += 1
    elif c == ')':
        count -= 1
    else:
        if i < last:
            res.append(1)
            count -= 1
        else:
            num = max(1, 1 + s.count("(") - s.count("#") - s.count(")"))
            res.append(num)
            count -= num
    if count < 0:
        res = []
        print(-1)
        break
for i in res:
    print(i)


#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ;
  long long int n;
  cin >> n;
  if (n == 1)
    cout << "1";
  else if (n == 2)
    cout << "2";
  else if (n & 1)
    cout << n * (n - 1) * (n - 2);
  else {
    if (n % 3 == 0)
      cout << (n - 1) * (n - 2) * (n - 3);
    else
      cout << n * (n - 1) * (n - 3);
  }
  return 0;
}

import sys, math
input = sys.stdin.readline

def getInts():
    return [int(s) for s in input().split()]

def getInt():
    return int(input())

def getStrs():
    return [s for s in input().split()]

def getStr():
    return input()

def listStr():
    return list(input())

import collections as col
import math

def solve():
    N = getInt()
    if N == 1:
        return 1
    if N == 2:
        return 2
    if N % 2 == 1:
        return N*(N-1)*(N-2)
    return max(N*(N-1)*(N-2)//2,(N-1)*(N-2)*(N-3), N*(N-1)*(N-3) if N % 3 > 0 else 0)
    #can we make a bigger number using N? N*(N-1), we can't use (N-2), we could use N-3

print(solve())


T=int(input())
list=[]
c=-1
d=-1
for i in range(T):
  n=int(input())
  k="Yes"
  for j in range(n):
    a,b=map(int,input().split())
    if a>=b and c<=a and d<=b and (b-d)<=(a-c):
        g=0
    else:
        k="No"
    c=a
    d=b
  c=-1
  d=-1
  list.append(k)
for i in range(len(list)):
  print(list[i])

import java.io.BufferedOutputStream;

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

public class thing {

	static boolean isPossible = true;
	static int reps;
	public static void main(String[] args) throws IOException {
        Scanner sc = new Scanner(System.in);
        PrintWriter pw = new PrintWriter(new BufferedOutputStream(System.out));

        int num =sc.nextInt();

        while(num>0) {
        	 ;
        	reps =sc.nextInt();
        	isPossible = true;

        	if(reps > 1) {

        	int numa = sc.nextInt();
        	int numb = sc.nextInt();
        	int numc = sc.nextInt();
        	int numd = sc.nextInt();

        	if(reps > 2) {
        	while(reps > 2) {
        		if(numb > numa) {
        			isPossible = false;

        		}
        		if(numd-numb > numc-numa) {
        			isPossible = false;

        		}
        		if(numd<numb) {
        			isPossible = false;

        		}
        		if(numc<numa) {
        			isPossible = false;

        		}

        		numa = numc;
        		numb = numd;
        		numc = sc.nextInt();
        		numd = sc.nextInt();

        	reps--;
        	}
        	}

        	if(numb > numa) {
    			isPossible = false;
    		}
    		if(numd > numc) {
    			isPossible = false;

    		}
    		if(numd-numb > numc-numa) {
    			isPossible = false;

    		}
    		if(numd<numb) {
    			isPossible = false;

    		}
    		if(numc<numa) {
    			isPossible = false;
    		}

        	} else {

        		int numa = sc.nextInt();
            	int numb = sc.nextInt();

            	if(numb > numa) {
            		isPossible = false;
            	} else {
            		isPossible = true;
            	}

        	}

        	if(isPossible) {
            	pw.println("YES");
            } else {
            	pw.println("NO");
            }

        	num--;
        }

        sc.close();
        pw.close();

}

}


import java.util.*;
import java.io.*;
public class B1269{
    public static void main(String args[]) throws Exception{
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int arr[] = PA(br.readLine().split(" "));
        int n = arr[0] ;
        int m = arr[1];
        int a[] = PA(br.readLine().split(" "));
        Arrays.sort(a);
        int b[] = PA(br.readLine().split(" "));
        Arrays.sort(b);
        int min=Integer.MAX_VALUE;
        for(int i=0;i<n;i++){
           for(int j=0;j<n;j++){
               int x = ((b[j]-a[i])%m+m)%m;
               if(isValid(x,a,b,i,j,m))
                min = Math.min(min,x);
           }
        }
        System.out.println(min);
    }

    private static boolean isValid(int x, int[] a, int[] b, int n, int m,int M) {
        for(int i=0;i<a.length;i++){
            int A = (a[(i+n)%a.length] + x)%M;
            int B = (b[(i+m)%a.length])%M;
            if(A!=B)
                return false;
        }
        return true;
    }

    static int PI(String s) {
        return Integer.parseInt(s);
    }
    static int[] PA(String temp[]){
        int arr[] =new int[temp.length];
        for(int i=0;i<arr.length;i++){
            arr[i] = PI(temp[i]);
        }
        return arr;
    }
}

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  ll n, m;
  cin >> n >> m;
  vector<ll> ar(n);
  vector<ll> br(n);
  map<ll, ll> a, b;
  for (auto &x : ar) {
    cin >> x;
    a[x]++;
  }
  for (auto &x : br) {
    cin >> x;
    b[x]++;
  }
  ll res = 1.01e18;
  for (int i = 0; i < n; ++i) {
    ll x = (br[i] - ar[0] + m) % m;
    bool can = true;
    for (auto ex : a) {
      can &= (ex.second == b[(ex.first + x) % m]);
    }
    if (can) res = min(res, x);
  }
  cout << res << '\n';
  return 0;
}


#!/usr/bin/python3

def cds(a, b, x, y):
    return (x + y) // (2 * a), (x - y) // (2 * b)

def norm(x, y):
    return max(x, y)

a, b, x1, y1, x2, y2 = map(int, input().split())
xp1, yp1 = cds(a, b, x1, y1)
xp2, yp2 = cds(a, b, x2, y2)
print(norm(abs(xp1 - xp2), abs(yp1 - yp2)))


/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
/**
 *
 * @author BATCH1
 */
import java.util.*;
public class ques1 {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int c= 0;
        String s = sc.next();
        for(int i =0;i<n;i++)
            if(s.charAt(i)=='1')
                c++;
        if(c*2!=n){
            System.out.println(1);
            System.out.println(s);
        }
        else{
            System.out.println(2);
            System.out.println(s.substring(0,1) + " " + s.substring(1));
        }
    }
}


n, k=map(int ,input().split())
if n==k and n%2==1:
    print(n)
else:
    print(2)

#include <bits/stdc++.h>
using namespace std;
long long a, b, c, d, n, m, k, q, l, r;
string s;
int main() {
  ios::sync_with_stdio(false);
  cin >> l >> r;
  a = r - l;
  if (r - l < 100) {
    map<long long, long long> mp;
    map<long long, long long>::iterator it;
    for (int i = l; i <= r; i++) {
      a = i;
      for (int x = 2; x * x <= a; x++) {
        if (a % x == 0) {
          mp[a / x]++;
          mp[x]++;
        }
      }
      if (a > 1) {
        mp[a]++;
      }
    }
    for (it = mp.begin(); it != mp.end(); it++) {
      b = max(b, it->second);
    }
    for (it = mp.begin(); it != mp.end(); it++) {
      if (it->second == b) {
        cout << it->first;
        return 0;
      }
    }
  } else {
    cout << 2;
  }
}


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

public class Main {

    public static void main(String[] args) throws IOException {
        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        String line = "";
        HashSet<String> peopleSet = new HashSet<String>();
        char[] chars;
        int total = 0;
        while(in.ready())
        {
            line = in.readLine();
            chars = line.toCharArray();
            if(chars[0] == '+')
            {
                peopleSet.add(line.substring(1, line.length()));
            }
            else if(chars[0] == '-')
            {
                //if(peopleSet.contains(line.substring(1, line.length())))
                    peopleSet.remove(line.substring(1, line.length()));
            }
            else
            {
                int index = -1;
                for(int i=0; i<chars.length ;i++)
                {
                    if(chars[i]==':')
                    {
                        index = i;
                        break;
                    }
                }
                if(index!=-1)
                {
                    total+= peopleSet.size() * (line.length()-(index+1));
                }
            }
        }
        System.out.println(total);
    }

}

+Mike
Mike:hello
+Kate
+Dmitry
-Dmitry
Kate:hi
-Kate

+8UjgAJ
8UjgAJ:02hR7UBc1tqqfL
-8UjgAJ
+zdi
-zdi

+adabacaba
-adabacaba
+aca
aca:caba
-aca
+bacaba
-bacaba
+aba
-aba
+bad

+Mike
-Mike
+Mike
Mike:Hi   I am here
-Mike
+Kate
-Kate

+Dmitry
+Mike
Dmitry:All letters will be used
Dmitry:qwertyuiopasdfghjklzxcvbnm QWERTYUIOPASDFGHJKLZXCVBNM
Dmitry:And digits too
Dmitry:1234567890 0987654321
-Dmitry

#include <bits/stdc++.h>
using namespace std;
int main() {
  int m = 0, a = 0;
  for (int i = 0; i < 100; i++) {
    string s;
    getline(cin, s);
    if (s[0] == '+') {
      m++;
      continue;
    }
    if (s[0] == '-') {
      m--;
      continue;
    }
    int c = 1;
    int t = 0;
    for (int j = 0; j < s.size(); j++) {
      if (s[j] == ':' && c == 1) {
        c = 0;
        continue;
      }
      if (c == 0) {
        a += (s.size() - j) * m;
        break;
      }
    }
  }
  cout << a;
  return 0;
}


import java.util.Scanner;

public class A {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		String s = sc.next();
		for (int i = 0; i < n; i++) {
			for (int j = 1; j < n; j++) {
				boolean f = true;
				for(int k = 0; k < 5; k++)
					if(i + k * j < n && s.charAt(i + k * j) == '*')
						;
					else f = false;
				if(f){
					System.out.println("yes");
					System.exit(0);
				}
			}
		}

		System.out.println("no");
	}
}

yes no yes yes yes yes yes yes yes yes yes yes yes yes yes yes no yes no yes yes yes yes yes no no yes yes no yes yes yes yes yes yes yes yes yes yes yes yes no

#include <bits/stdc++.h>
using namespace std;
using std::map;
const int CMAX = 100005;
const char Cfd[] = "", Cfr[] = "";
int main() {
  int n;
  string s;
  cin >> n >> s;
  for (int i = 0; i < s.length(); i++)
    if (s[i] == '*')
      for (int j = 1; i + 4 * j < s.length(); j++)
        if (s[i + j] == '*' && s[i + 2 * j] == '*' && s[i + 3 * j] == '*' &&
            s[i + 4 * j] == '*') {
          cout << "yes";
          return 0;
        }
  cout << "no";
  return 0;
}


n,m=map(int,input().split())
weight=[int(i) for i in input().split()]
order=[int(i) for i in input().split()]
stack=[]
for i in order:
    if i-1 not in stack:
        stack.append(i-1)
#print(stack)
ans=0
for i in order:
    #i=i-1
    currlift=sum(weight[i] for i in stack[0:stack.index(i-1)])
    ans+=currlift
    temp=i-1
    stack.remove(i-1)
    stack.insert(0,temp)
    #print(currlift)
    #print(stack)
print(ans)

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

public class TaskC {

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int m = in.nextInt();
        int[] w = new int[n];
        int[] b = new int[m];
        for (int i = 0; i < n; i++) {
            w[i] = in.nextInt();
        }
        for (int i = 0; i < m; i++) {
            b[i] = in.nextInt() - 1;
        }
        int ans = 0;
        for (int i = 0; i < n; i++) {
            boolean[] existed = new boolean[n];
            int cur = 0;
            for (int j = 0; j < m; j++) {
                if (b[j] != i) {
                    if (!existed[b[j]]) {
                        cur += w[b[j]];
                        existed[b[j]] = true;
                    }
                } else {
                    ans += cur;
                    existed = new boolean[n];
                    cur = 0;
                }
            }
        }
        System.out.println(ans);
    }
}


import java.util.Scanner ;
public class A478_InitialBet {

	public static void main(String[] args) {
		Scanner ss =new Scanner (System.in) ;
		int one = ss.nextInt() ;
		int two = ss.nextInt() ;
		int three = ss.nextInt() ;
		int four = ss.nextInt() ;
		int five = ss.nextInt() ;
		int sum = one + two + three + four + five ;
		if (sum%5 == 0 && sum!=0)
			System.out.println(sum/5);

		else
			System.out.println(-1);
	}

}

l=list(map(int,input().split()))
x=sum(l)
if(x%5==0 and x!=0):
    print(int(x/5))
else:
    print(-1)


#include <bits/stdc++.h>
using namespace std;
const int max1 = 100010;
long long a[max1], b[max1];
int main() {
  int n, x, y = 0, z = 0;
  cin >> n;
  if (n == 1) {
    cout << "NO\n";
  } else {
    for (int i = 0; i < n; i++) {
      cin >> x;
      if (x == 200) {
        z++;
      }
      y += x;
    }
    if ((y % 200 == 0)) {
      if ((z == n) && (z % 2 != 0)) {
        cout << "NO\n";
      } else {
        cout << "YES\n";
      }
    } else {
      cout << "NO\n";
    }
  }
}

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

import java.util.Scanner;

/**
 * Created by zephyr on 5/30/14.
 */
public class GIft {
    public static void main(String args[]){
        System.out.println(gift());
    }

    public static String gift(){
        Scanner scanner = new Scanner(System.in);
        int number = scanner.nextInt();
        int x100 = 0;
        int x200 = 0;
        while(number-- > 0){
        if (scanner.nextInt() == 100){
            x100 ++;
        }else{
            x200 ++;
        }
        }
        if (x100 % 2 != 0){
            return "NO";
        }else if(x200 % 2 == 0){
            return "YES";
        }else{
            if (x100 < 2){
                return "NO";
            }else{
                return "YES";
            }
        }
    }
}


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

public class E {
	FastScanner in = new FastScanner(System.in);
	PrintWriter out = new PrintWriter(System.out);

	boolean[] visited;
	HashSet<Long> usedEdge = new HashSet<Long>();
	ArrayList<Integer>[] g;
	StringBuilder res = new StringBuilder();

	final int CONV_CONST = 150000;
	long convert(long a, long b) {
		return a * CONV_CONST + b;
	}

	int dfs(int u) {
		if (visited[u]) return -1;
		visited[u] = true;

		Queue<Integer> q = new LinkedList<Integer>();
		for (int v : g[u]) {
			if (!usedEdge.contains(convert(u, v))) {
				usedEdge.add(convert(u, v));
				usedEdge.add(convert(v, u));
				q.add(v);
			}
		}

		int prev = -1;
		while (!q.isEmpty()) {
			int v = q.poll();
			int rest = dfs(v);

			if (rest != -1) {
				res.append((u+1) + " " + (v+1) + " " + (rest+1) + "\n");
			} else if (prev != -1) {
				res.append((v+1) + " " + (u+1) + " " + (prev+1) + "\n");
				prev = -1;
			} else {
				prev = v;
			}
		}

		return prev;
	}

	public void run() {
		int n = in.nextInt(), m = in.nextInt();
		if (m % 2 != 0) {
			System.out.println("No solution");
			return;
		}

		g = new ArrayList[n];
		for (int i = 0; i < n; i++)
			g[i] = new ArrayList<Integer>();

		for (int i = 0; i < m; i++) {
			int a = in.nextInt() - 1, b = in.nextInt() - 1;
			g[a].add(b);
			g[b].add(a);
		}

		visited = new boolean[n];
		dfs(0);
		out.println(res);

		out.close();
	}

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

	public void mapDebug(int[][] a) {
		System.out.println("--------map display---------");

		for (int i = 0; i < a.length; i++) {
			for (int j = 0; j < a[i].length; j++) {
				System.out.printf("%3d ", a[i][j]);
			}
			System.out.println();
		}

		System.out.println("----------------------------");
		System.out.println();
	}

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

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

		public FastScanner(InputStream stream) {
			this.stream = stream;
			//stream = new FileInputStream(new File("dec.in"));

		}

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

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

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

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

		int[] nextIntArray(int n) {
			int[] array = new int[n];
			for (int i = 0; i < n; i++)
				array[i] = nextInt();

			return array;
		}

		int[][] nextIntMap(int n, int m) {
			int[][] map = new int[n][m];
			for (int i = 0; i < n; i++) {
				map[i] = in.nextIntArray(m);
			}
			return map;
		}

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

		long[] nextLongArray(int n) {
			long[] array = new long[n];
			for (int i = 0; i < n; i++)
				array[i] = nextLong();

			return array;
		}

		long[][] nextLongMap(int n, int m) {
			long[][] map = new long[n][m];
			for (int i = 0; i < n; i++) {
				map[i] = in.nextLongArray(m);
			}
			return map;
		}

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

		double[] nextDoubleArray(int n) {
			double[] array = new double[n];
			for (int i = 0; i < n; i++)
				array[i] = nextDouble();

			return array;
		}

		double[][] nextDoubleMap(int n, int m) {
			double[][] map = new double[n][m];
			for (int i = 0; i < n; i++) {
				map[i] = in.nextDoubleArray(m);
			}
			return map;
		}

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

		String[] nextStringArray(int n) {
			String[] array = new String[n];
			for (int i = 0; i < n; i++)
				array[i] = next();

			return array;
		}

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

#include <bits/stdc++.h>
using namespace std;
int n, m;
int visit[111111];
vector<int> v[111111], mark[111111];
int dfs(int t) {
  vector<int> v1;
  int i;
  for (i = 0; i < v[t].size(); i++) {
    int u = v[t][i];
    if (visit[mark[t][i]] == 0) {
      visit[mark[t][i]] = 1;
      int w = dfs(u);
      if (w == 0)
        v1.push_back(u);
      else
        printf("%d %d %d\n", t, u, w);
    }
  }
  while (v1.size() > 1) {
    printf("%d %d %d\n", v1[v1.size() - 1], t, v1[v1.size() - 2]);
    v1.pop_back();
    v1.pop_back();
  }
  if (v1.size() == 1)
    return v1[0];
  else
    return 0;
}
int main() {
  memset(visit, 0, sizeof(visit));
  scanf("%d%d", &n, &m);
  int i;
  for (i = 0; i < m; i++) {
    int a, b;
    scanf("%d%d", &a, &b);
    v[a].push_back(b);
    v[b].push_back(a);
    mark[a].push_back(i);
    mark[b].push_back(i);
  }
  if (m % 2)
    printf("No solution\n");
  else {
    for (i = 1; i <= n; i++) dfs(i);
  }
}


n, c = map(int, input().split())
l = list(map(int, input().split()))

ans = 0
for i in range(n - 1):
	d = l[i] - l[i + 1] - c
	ans = max(ans, d)

print(ans)

import java.util.Scanner;
public class freebie{
public static void main(String[] args){
int n,c;
Scanner sc = new Scanner(System.in);
n=sc.nextInt();
c=sc.nextInt();
int[] array = new int[n+1];
array[n] = 0 ;
for(int i = 0;i<n;i++){
array[i]=sc.nextInt();}
int [] difference = new int[n];
int temp = 0 ;
for(int i=0;i<(n-1);i++){
difference[i] = array[i] - array[i+1] -c;
if(temp<difference[i])
temp = difference[i];}
System.out.println(temp);
}}


#include <bits/stdc++.h>
using namespace std;
int main() {
  string s, x, z;
  cin >> s;
  for (int i = 0; i < s.size(); i++) {
    if (s[i] == '+') {
      continue;
    }
    for (int j = 0; j < s.size(); j++) {
      if (s[j] == '+') {
        continue;
      }
      if (s[i] < s[j]) {
        swap(s[j], s[i]);
      }
    }
  }
  for (int i = 0; i < s.size(); i++) {
    cout << s[i];
  }
  return 0;
}

x=input()
x=x.replace("+","")
x=sorted(x)
for i in range(1,2*len(x)-1,2):
    x.insert(i,"+")
x=''.join(x)
print(x)


import java.util.*;

public class B {
  public static void main(String[] args) {
    Scanner in = new Scanner(System.in);
    int count = in.nextInt();
    int me = in.nextInt()-1;
    int[] map = new int[count];
    int[] reverseMap = new int[count];
    Arrays.fill(reverseMap,-1);
    for(int i=0;i<count;++i) {
      map[i] = in.nextInt()-1;
      if (map[i] != -1) {
        reverseMap[map[i]] = i;
      }
    }
    HashMap<Integer, Integer> cycles = new HashMap<Integer, Integer>();
    boolean[] done = new boolean[count];
    boolean isUs = false;
    int ourLength = 0;
    int ourLoc = 0; // how many people are behind us?
    // so our location from the front is ourLength-ourLoc, right? yes.
    for(int i=0;i<count;++i) {
      isUs = false;
      if (done[i]) continue;
      done[i] = true;
      int cur = i;
      if (reverseMap[i] == -1 && map[i] == -1) {
        if (cur == me) {
          ourLength = 1;
          ourLoc = 0;
        } else {
          if (cycles.containsKey(1)) {
            cycles.put(1,cycles.get(1)+1);
          } else {
            cycles.put(1,1);
          }
        }
      } else {
        while(reverseMap[cur] != -1) {
          cur = reverseMap[cur];
        }
        int cycleLength = 1;
        done[cur] = true;
        if(cur == me) {
          isUs = true;
          ourLoc = 0;
        }
        while(map[cur] != -1) {
          cur = map[cur];
          done[cur] = true;
          ++cycleLength;
          if(cur == me) {
            isUs = true;
            ourLoc = cycleLength-1;
          }
        }
        if (isUs) {
          ourLength = cycleLength;
        } else {
          if (cycles.containsKey(cycleLength)) {
            cycles.put(cycleLength,cycles.get(cycleLength)+1);
          } else {
            cycles.put(cycleLength,1);
          }
        }
      }
    }
    // shit two cases: we are at a 0 or we aren't.
    // if we aren't at a 0 we need to know what cycle we're in
    // now that we have all the cycles, we need to know what's possible
    // System.err.println(ourLength + " " + ourLoc);
    // System.err.println(cycles);
    boolean[] dp = new boolean[count+1];
    Arrays.fill(dp, false);
    dp[0] = true;
    for(int key : cycles.keySet()) {
      for(int z=0;z<cycles.get(key);++z) {
        for(int i=count;i>=key;--i) {
          dp[i] = (dp[i]||dp[i-key]);
        }
      }
      // System.err.println(Arrays.toString(dp));
    }
    for(int i=0;i<count;++i) {
      if (dp[i]) {
        System.out.println(i+(ourLength-ourLoc));
      }
    }
  }
}

#include <bits/stdc++.h>
using namespace std;
int s[5555], b[5555];
bool mark[5555], moze[5555];
int main() {
  int n, x, i, j, t, q, br, of, bb;
  scanf("%d%d", &n, &x);
  for (i = 0; i <= n; i++) mark[i] = false;
  for (i = 1; i <= n; i++) {
    scanf("%d", &s[i]);
    mark[s[i]] = true;
  }
  br = 0;
  of = 0;
  q = -1;
  for (i = 1; i <= n; i++) {
    if (!mark[i]) {
      t = i;
      bb = 0;
      b[br] = 0;
      while (t != 0) {
        b[br]++;
        if (bb) of++;
        if (t == x) {
          of++;
          bb = 1;
        }
        t = s[t];
      }
      if (bb) q = br;
      br++;
    }
  }
  for (i = 0; i <= 1555; i++) moze[i] = false;
  moze[of] = true;
  for (i = 0; i < br; i++)
    if (i != q) {
      for (j = 1234; j > b[i]; j--)
        if (moze[j - b[i]]) moze[j] = true;
    }
  for (i = 1; i <= 1234; i++)
    if (moze[i]) printf("%d\n", i);
  return 0;
}


text = input().lower()
caps = int(input())+97
for letter in text:
	print(letter.upper(), end='')if letter < chr(caps) else print(letter, end='')
print()

import java.io.*;
public class Main {

    public static void main(String[] args) {
       BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        try{
            String s = br.readLine();
            int n = Integer.parseInt(br.readLine());
            s = s.toLowerCase();
            String ans = "";
            for(int i = 0; i < s.length(); ++i)
            {
                char c = s.charAt(i);
                if(c < n + 97)
                {
                  ans = ans + Character.toUpperCase(c);
                }
                else{
                    ans = ans + Character.toLowerCase(c);
                }
            }
            System.out.println(ans);
        }
        catch(Exception e){

        }
    }
}


n=int(input())
mat=[]
for i in range(n):
    mat.append(list(map(int, input().rstrip().split())))
b=0
for i in range (n):
    for j in range (n):
        if mat[i][0]==mat[j][1]:
            b=b+1
print(b)

#include <bits/stdc++.h>
using namespace std;
int main() {
  int home[30];
  int away[30];
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> home[i];
    cin >> away[i];
  }
  int cnt = 0;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      if (i == j) continue;
      if (home[i] == away[j]) cnt++;
    }
  }
  cout << cnt << '\n';
  return 0;
}


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

/**
 * <a href="http://codeforces.ru/problemset/problem/219/A"/>
 *
 * @author pvasilyev
 * @since 07 Jan 2014
 */
public class Problem084 {

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

        solve(reader, writer);

        reader.close();
        writer.close();
    }

    private static void solve(final Scanner reader, final PrintWriter writer) {
        final int k = reader.nextInt();
        final char[] string = reader.next().toCharArray();
        if (string.length % k != 0) {
            writer.println(-1);
            return;
        }
        int[] counts = new int[26];
        for (int i = 0; i < string.length; i++) {
            counts[string[i]-'a']++;
        }
        if (!accepts(counts, k)) {
            writer.println(-1);
            return;
        }
        final StringBuilder stringBuilder = new StringBuilder();
        for (int i = 0; i < counts.length; i++) {
            final int count = counts[i] / k;
            for (int j = 0; j < count; ++j) {
                stringBuilder.append((char)('a'+i));
            }
        }
        final StringBuilder result = new StringBuilder();
        for (int i = 0; i < k; ++i) {
            result.append(stringBuilder);
        }

        writer.println(result.toString());
    }

    private static boolean accepts(final int[] counts, final int k) {
        for (int i = 0; i < counts.length; i++) {
            if (counts[i] % k != 0) {
                return false;
            }
        }
        return true;
    }

}

#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  string s;
  cin >> s;
  int ara[26];
  for (int i = 0; i < 26; i++) {
    ara[i] = 0;
  }
  for (int i = 0, len = s.length(); i < len; i++) {
    ara[s[i] - 'a']++;
  }
  for (int i = 0; i < 26; i++) {
    if (ara[i] % n != 0) {
      printf("-1");
      return 0;
    }
    ara[i] /= n;
  }
  for (int k = 0; k < n; k++) {
    for (int i = 0; i < 26; i++) {
      for (int j = 0; j < ara[i]; j++) {
        printf("%c", i + 'a');
      }
    }
  }
  printf("\n");
}


import java.util.Scanner;

public class P7 {
    public static void main(String[] arg) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();

        int tot = a*c;
        int cont = 0;

        while(tot > 0){
            tot = tot -b;
            cont++;
        }

        tot = a*c;

        int f = 0;
        int cont2 = 0;

        while(f + c*b < tot){
            cont2++;
            f=f+b;
        }

        System.out.println(cont2);

    }
}

#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:64000000")
using namespace std;
inline int gcd(int a, int b) {
  if (a < b) {
    a ^= b;
    b ^= a;
    a ^= b;
  };
  return (a > b) ? gcd(a - b, b) : a;
}
inline int abs(int x) { return x > 0 ? x : -x; }
void solve() {
  int a, b, c, t, all;
  bool fin = false;
  cin >> a >> b >> c;
  if (b >= a) {
    cout << 0;
    return;
  }
  t = 0;
  all = (c * a + b - 1) / b;
  while (++t)
    if (all * b >= (all - t) * a) break;
  cout << t;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  solve();
  return 0;
}


t = int(input())

while t>0:

    x, y, z = [int(i) for i in input().split()]

    s = 0
    f = -1
    z = z//2
    if y >= z:
        y = y - z
        s = z*2 + z
    else:
        s = y*2 + y
        f = 1

    if f == -1:
        y = y//2
        if x >= y:
            s = s + 2*y + y
        else:
            s = s + 2*x + x

    print(s)

    t-=1

#include <bits/stdc++.h>
using namespace std;
const long long maxn = 1e5 + 1, mod = 1e9 + 7, inf = 1e18;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int t, a, b, c;
  cin >> t;
  for (int i = 1; i <= t; i++) {
    cin >> a >> b >> c;
    int tmp = min(b, c / 2);
    b -= tmp;
    tmp += min(a, b / 2);
    cout << tmp * 3 << endl;
  }
  return 0;
}


#include <bits/stdc++.h>
using namespace std;
int n, m, a, b, c, d;
struct node {
  int a, b;
};
bool cmp(node x, node y) {
  if (x.a == y.a) return x.b > y.b;
  return x.a > y.a;
}
string s;
int num[30];
char cr, cr1;
int check(char cc) {
  for (int i = cc - 'a' + 1; i < 26; ++i) {
    if (num[i]) return num[i];
  }
  return 0;
}
int main() {
  cin >> n;
  getchar();
  while ((cr = getchar()) && cr != '\n') {
    m++;
    if (!num[cr - 'a']) {
      num[cr - 'a'] = m;
    }
    if (check(cr)) {
      cout << "YES" << endl;
      cout << check(cr) << " " << m << endl;
      return 0;
    }
  }
  cout << "NO" << endl;
  return 0;
}

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

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

    static class codeforces1 {
        public void solve(int testNumber, Scanner leer, PrintWriter out) {
            int n = leer.nextInt();
            String cad = leer.next();
            int p1 = 0, p2 = 0;
            boolean t = false;
            for (int i = 0; i < n - 1; i++) {
                char a = cad.charAt(i);
                char b = cad.charAt(i + 1);
                if (b < a) {
                    p1 = i;
                    p2 = i + 1;
                    t = true;
                    //out.println(a+" "+b);
                    break;
                }
            }
            p1++;
            p2++;
            if (t) {
                out.println("YES");
                out.println(p1 + " " + p2);
            } else {
                out.println("NO");
            }
        }

    }
}


import math
n = int(input())
l= list(map(int,input().split()))
s = 2*sum(l)
z= s/n
p = max(l)
an = int(z+1)
print(max(p,an))

#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  int ans = 0;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    ans = max(ans, a[i]);
  }
  for (int i = ans; i < 1000; i++) {
    int cur = 0;
    for (int j = 0; j < n; j++) {
      cur += i - a[j] * 2;
    }
    if (cur > 0) {
      cout << i;
      return 0;
    }
  }
  return 0;
}


def is_prime(a):
    return all(a % i for i in range(2, a))

n, k = map(int, input().split())
l = [int(x) for x in input().split()]
if is_prime(k):
    if k in l:
        print(1)
    else:
        print(k)
else:
    ll = []
    for i in range(len(l)):
        if k % l[i] == 0:
            ll.append(l[i])
    print(k // max(ll))

3 6
```

I hope these sample inputs are helpful. Let me know if you have any other questions.

1 40
```

I hope these sample inputs are helpful. Let me know if you have any other questions.

#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, k, result;
  scanf("%d %d", &n, &k);
  for (int i = 0; i < n; i++) {
    int a;
    scanf("%d", &a);
    if (k % a == 0) result = min(result, k / a);
  }
  printf("%d\n", result);
  return 0;
}


one=input()
num=int(input())
twos=[]
for i in range(num):
  twos.append(input())

if (one in twos) or (one[::-1] in twos):
  print("YES")

else:
  flag1,flag2=False,False
  for i in range(num):
    if twos[i][0]==one[1]:
      flag1=True
    if twos[i][1]==one[0]:
      flag2=True
  if(flag1 and flag2):
    print("YES")
  else:
    print("NO")

bn
100
df
yb
ze
ml
yr
of
nw
fm
dw
lv
zr
hu
zt
lw
ld
mo
xz
tp
mr
ou
me
px
vp
es
xi
nr
bx
qc
gm
js
kn
tw
rq
kz
uc
vc
qr
ab
na
ro
ya
qy
gu
vk
qk
gs
yq
op
hw
rj
eo
lz
bh
kr
kb
ma
rd
za
uf
hq
mc
mn
ti
wn
sh
ax
si
nd
tz
du
fj
kl
ws
ow
nf
vr
ye
zc
iw
fv
kv
oo
sm
bc
rs
au
uz
uv
gh
su
jn
dz
rl
wj
bk
zl
as
ms
it
wu

ke
20
zk
ra
bq
qz
wt
zg
mz
uk
ge
uv
ud
fd
eh
dm
sk
ki
fv
tp
at
fb

import java.util.Scanner;

public class Codechef {

    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        String x = input.next();
        int n = input.nextInt(), c = 0, c1 = 0;
        String[] s = new String[n];
        for (int i = 0; i < n; i++) {
            s[i] = input.next();
        }

        for (int i = 0; i < n; i++) {
            if (x.equals(s[i])) {
                System.out.println("Yes");
                c++;
                break;
            }
        }

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

                if (s[i].charAt(1) == x.charAt(0)) {
                    for (int j = 0; j < n; j++) {
                        if (s[j].charAt(0) == x.charAt(1)) {
                            System.out.println("Yes");
                            c++;
                            break;
                        }

                    }
                    if(c==1){
                        break;
                    }

                }

            }
        }
        if (c == 0) {
            System.out.println("No");
        }

    }

}


#include <bits/stdc++.h>
const double Pi = acos(-1.0);
using namespace std;
const int maxN = 100005;
const long long inf = (long long)1e15;
int n;
long long b[maxN];
long long k[maxN];
long long req[maxN];
vector<int> G[maxN];
void dfs(int cur) {
  for (int i = 0; i < (int)G[cur].size(); i++) {
    int nxt = G[cur][i];
    dfs(nxt);
    if (req[nxt] < 0) {
      if (inf / k[nxt] < (-req[nxt])) {
        puts("NO");
        exit(0);
      }
      req[cur] += k[nxt] * req[nxt];
    } else
      req[cur] += req[nxt];
  }
}
int main(int argc, char** argv) {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%lld", &b[i]);
  long long a;
  for (int i = 1; i <= n; i++) {
    scanf("%lld", &a);
    req[i] = b[i] - a;
  }
  int x;
  for (int i = 2; i <= n; i++) {
    scanf("%d %lld", &x, &k[i]);
    G[x].push_back(i);
  }
  dfs(1);
  puts((req[1] < 0) ? "NO" : "YES");
  return 0;
}

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

import sys

# @profile
def main():
    f = sys.stdin
    # f = open('input.txt', 'r')
    # fo = open('log.txt', 'w')
    n = int(f.readline())
    # b = []
    # for i in range(n):
    #    b.append()
    b = list(map(int, f.readline().strip().split(' ')))
    a = list(map(int, f.readline().strip().split(' ')))
    # return
    b = [b[i] - a[i] for i in range(n)]
    c = [[0, 0]]
    for i in range(n - 1):
        line = f.readline().strip().split(' ')
        c.append([int(line[0]), int(line[1])])
    # print(c)
    for i in range(n - 1, 0, -1):
        # print(i)
        fa = c[i][0] - 1
        if b[i] >= 0:
            b[fa] += b[i]
        else:
            b[fa] += b[i] * c[i][1]
            if b[fa] < -1e17:
                print('NO')
                return 0
    # for x in b:
    #    fo.write(str(x) + '\n')
    if b[0] >= 0:
        print('YES')
    else:
        print('NO')

main()


import java.io.*;
import java.util.*;
import java.text.*;
import java.math.*;
import java.util.regex.*;
import java.lang.*;

public class A {
	static long mod = 1000000007;

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

		//int t=in.readInt();
		//while(t-->0)
		//{
		String x=in.readString();
		String y=in.readString();
		pw.println(x+" "+y);
		int n=in.readInt();
		for(int i=0;i<n;i++)
		{
			String a=in.readString();
			String b=in.readString();
			if(a.compareTo(x)==0)
			{
				pw.println(b+" "+y);
				x=b;
			}
			else if(a.compareTo(y)==0)
			{
				pw.println(x+" "+b);
				y=b;
			}
		}
		//long n=in.readLong();
		/*int a[]=new int[n];
		for(int i=0;i<n;i++)
		{
			a[i]=in.readInt();
		}*/
		//String a=in.readString();

		//pw.println("");

		//}

		pw.close();
	}

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

	}

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

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

		public int compareTo(Pair o) {
			// TODO Auto-generated method stub
			if (this.a != o.a)
				return Integer.compare(this.a, o.a);
			else
				return Integer.compare(this.b, o.b);
			//return 0;
		}

		public boolean equals(Object o) {
			if (o instanceof Pair) {
				Pair p = (Pair) o;
				return p.a == a && p.b == b;
			}
			return false;
		}

		public int hashCode() {
			return new Integer(a).hashCode() * 31 + new Integer(b).hashCode();
		}

		public String toString() {
			return a + " " + b;
		}
	}

	static long sort(int a[]) {
		int n = a.length;
		int b[] = new int[n];
		return mergeSort(a, b, 0, n - 1);
	}

	static long mergeSort(int a[], int b[], long left, long right) {
		long c = 0;
		if (left < right) {
			long mid = left + (right - left) / 2;
			c = mergeSort(a, b, left, mid);
			c += mergeSort(a, b, mid + 1, right);
			c += merge(a, b, left, mid + 1, right);
		}
		return c;
	}

	static long merge(int a[], int b[], long left, long mid, long right) {
		long c = 0;
		int i = (int) left;
		int j = (int) mid;
		int k = (int) left;
		while (i <= (int) mid - 1 && j <= (int) right) {
			if (a[i] <= a[j]) {
				b[k++] = a[i++];
			} else {
				b[k++] = a[j++];
				c += mid - i;
			}
		}
		while (i <= (int) mid - 1)
			b[k++] = a[i++];
		while (j <= (int) right)
			b[k++] = a[j++];
		for (i = (int) left; i <= (int) right; i++)
			a[i] = b[i];
		return c;
	}

	public static int[] radixSort(int[] f) {
		int[] to = new int[f.length];
		{
			int[] b = new int[65537];
			for (int i = 0; i < f.length; i++)
				b[1 + (f[i] & 0xffff)]++;
			for (int i = 1; i <= 65536; i++)
				b[i] += b[i - 1];
			for (int i = 0; i < f.length; i++)
				to[b[f[i] & 0xffff]++] = f[i];
			int[] d = f;
			f = to;
			to = d;
		}
		{
			int[] b = new int[65537];
			for (int i = 0; i < f.length; i++)
				b[1 + (f[i] >>> 16)]++;
			for (int i = 1; i <= 65536; i++)
				b[i] += b[i - 1];
			for (int i = 0; i < f.length; i++)
				to[b[f[i] >>> 16]++] = f[i];
			int[] d = f;
			f = to;
			to = d;
		}
		return f;
	}

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

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

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

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

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

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

		public double readDouble() {
			int c = read();
			while (isSpaceChar(c))
				c = read();
			int sgn = 1;
			if (c == '-') {
				sgn = -1;
				c = read();
			}
			double res = 0;
			while (!isSpaceChar(c) && c != '.') {
				if (c == 'e' || c == 'E')
					return res * Math.pow(10, readInt());
				if (c < '0' || c > '9')
					throw new InputMismatchException();
				res *= 10;
				res += c - '0';
				c = read();
			}
			if (c == '.') {
				c = read();
				double m = 1;
				while (!isSpaceChar(c)) {
					if (c == 'e' || c == 'E')
						return res * Math.pow(10, readInt());
					if (c < '0' || c > '9')
						throw new InputMismatchException();
					m /= 10;
					res += (c - '0') * m;
					c = read();
				}
			}
			return res * sgn;
		}

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

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

		public String next() {
			return readString();
		}

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

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

	//BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
	//StringBuilder sb=new StringBuilder("");
	//InputReader in = new InputReader(System.in);
	//PrintWriter pw=new PrintWriter(System.out);
	//String line=br.readLine().trim();

	//int t=Integer.parseInt(br.readLine());
	//	while(t-->0)
	//{
	//int n=Integer.parseInt(br.readLine());
	//long n=Long.parseLong(br.readLine());
	//String l[]=br.readLine().split(" ");
	//int m=Integer.parseInt(l[0]);
	//int k=Integer.parseInt(l[1]);
	//String l[]=br.readLine().split(" ");
	//l=br.readLine().split(" ");
	/*int a[]=new int[n];
	for(int i=0;i<n;i++)
	{
		a[i]=Integer.parseInt(l[i]);
	}*/
	//System.out.println(" ");

	//}

}

wxz hbeqwqp
7
hbeqwqp cpieghnszh
cpieghnszh tlqrpd
tlqrpd ttwrtio
ttwrtio xapvds
xapvds zk
wxz yryk
zk b

wwwww w
8
wwwww wwwwwwww
wwwwwwww wwwwwwwww
wwwwwwwww wwwwwwwwww
w www
wwwwwwwwww wwww
wwww ww
www wwwwww
wwwwww wwwwwww

k d
17
k l
d v
v z
l r
z i
r s
s p
p w
w j
j h
i c
h m
m q
c o
o g
q x
x n

ross rachel
4
ross joey
rachel phoebe
phoebe monica
monica chandler

bwyplnjn zkms
26
zkms nzmcsytxh
nzmcsytxh yujsb
bwyplnjn gtbzhudpb
gtbzhudpb hpk
yujsb xvy
hpk wrwnfokml
wrwnfokml ndouuikw
ndouuikw ucgrja
ucgrja tgfmpldz
xvy nycrfphn
nycrfphn quvs
quvs htdy
htdy k
tgfmpldz xtdpkxm
xtdpkxm suwqxs
k fv
suwqxs qckllwy
qckllwy diun
fv lefa
lefa gdoqjysx
diun dhpz
gdoqjysx bdmqdyt
dhpz dgz
dgz v
bdmqdyt aswy
aswy ydkayhlrnm

iii iiiiii
7
iii iiiiiiiiii
iiiiiiiiii iiii
iiii i
iiiiii iiiiiiii
iiiiiiii iiiiiiiii
i iiiii
iiiii ii

ze udggmyop
4
ze szhrbmft
udggmyop mjorab
szhrbmft ojdtfnzxj
ojdtfnzxj yjlkg

wwwww w
wwwwwwww w
wwwwwwwww w
wwwwwwwwww w
wwwwwwwwww www
wwww www
ww www
ww wwwwww
ww wwwwwww

k d
l d
l v
l z
r z
r i
s i
p i
w i
j i
h i
h c
m c
q c
q o
q g
x g
n g

wxz hbeqwqp
wxz cpieghnszh
wxz tlqrpd
wxz ttwrtio
wxz xapvds
wxz zk
yryk zk
yryk b

ross rachel
joey rachel
joey phoebe
joey monica
joey chandler

bwyplnjn zkms
bwyplnjn nzmcsytxh
bwyplnjn yujsb
gtbzhudpb yujsb
hpk yujsb
hpk xvy
wrwnfokml xvy
ndouuikw xvy
ucgrja xvy
tgfmpldz xvy
tgfmpldz nycrfphn
tgfmpldz quvs
tgfmpldz htdy
tgfmpldz k
xtdpkxm k
suwqxs k
suwqxs fv
qckllwy fv
diun fv
diun lefa
diun gdoqjysx
dhpz gdoqjysx
dhpz bdmqdyt
dgz bdmqdyt
v bdmqdyt
v aswy
v ydkayhlrnm

iii iiiiii
iiiiiiiiii iiiiii
iiii iiiiii
i iiiiii
i iiiiiiii
i iiiiiiiii
iiiii iiiiiiiii
ii iiiiiiiii

ze udggmyop
szhrbmft udggmyop
szhrbmft mjorab
ojdtfnzxj mjorab
yjlkg mjorab

def main():
    l = input().split()
    print(*l)
    for _ in range(int(input())):
        a, b = input().split()
        l[a == l[1]] = b
        print(*l)

if __name__ == '__main__':
    main()


#include <bits/stdc++.h>
using namespace std;
void solve() {
  int n, k;
  cin >> n >> k;
  vector<int> mas(k, 0);
  for (int i = 0; i < n; i++) {
    int m;
    cin >> m;
    for (int i = 0; i < m; i++) {
      int x;
      cin >> x;
      mas[x - 1]++;
    }
  }
  for (int i = 0; i < k; i++) {
    if (mas[i] == 0) {
      cout << "NO";
      return;
    }
  }
  cout << "YES";
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int tst = 1;
  while (tst--) solve();
  return 0;
}

import java.util.*;
public class Za {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();
		String x = " ";
		for (int i = 1; i <= m; i++)
			x += i + " ";
		for (int j = 1; j <= n; j++) {
			int k = sc.nextInt();
			for (int l = 0; l < k; l++) {
				int p = sc.nextInt();
				if (x.contains(" " + p + " "))
					x = x.replaceAll(" " + p + " ", " ");
			}
		}
		boolean zaza = true;
		for (int q = 0; q < x.length(); q++) {
			if (Character.isDigit(x.charAt(q))) {
				zaza = false;
				break;
			}
		}
		if (zaza) System.out.print("YES");
		else System.out.print("NO");
	}
}


#include <bits/stdc++.h>
using namespace std;
int N;
vector<int> xs, ys;
string generateFunc(int i, int x) {
  char str[1024];
  sprintf(str, "(%d*((1-abs((t-%d)))+abs((abs((t-%d))-1))))", x / 2, i, i);
  return string(str);
}
string solve(vector<int>& xs) {
  string rv;
  rv += generateFunc(0, xs[0]);
  for (int i = 1; i < N; ++i)
    rv = "(" + rv + "+" + generateFunc(i, xs[i]) + ")";
  return rv;
}
int main() {
  cin >> N;
  for (int i = 0; i < N; ++i) {
    int x, y, r;
    cin >> x >> y >> r;
    xs.emplace_back(x);
    ys.emplace_back(y);
  }
  cout << solve(xs) << endl;
  cout << solve(ys) << endl;
  return 0;
}

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

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

    static class TaskC {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.nextInt();
            int[] x = new int[n], y = new int[n];

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

            out.println(solve(x) + "\n" + solve(y));
        }

        private String solve(int[] a) {
            String result = "";
            String pattern = "(%d*((1-abs((t-%d)))+abs((abs((t-%d))-1))))";
            for (int i = 0; i < a.length; ++i) {
                String current = String.format(pattern, a[i] / 2, i, i);
                if (i > 0) result = "(" + result + "+" + current + ")";
                else result = current;
            }
            return result;
        }

    }

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

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

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

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

        public String next() {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            StringBuffer res = new StringBuffer();
            do {
                res.appendCodePoint(c);
                c = read();
            } while (!isSpaceChar(c));

            return res.toString();
        }

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

    }
}


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

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

/* Name of the class has to be "Main" only if the class is public. */
public class Trees
{
	public static void main (String[] args) throws java.lang.Exception
	{
		// your code goes here
		Scanner scan = new Scanner(System.in);
		int numTrees = scan.nextInt();
		int ans = 0;
		int[] positions = new int[numTrees];
		int[] heights = new int[numTrees];

		if(numTrees == 1)
			ans = 1;
		else
		{
			if(numTrees > 1) ans = 2; //if there are at least two trees, we can at least fell them in opposite directions
			for(int i = 0; i < numTrees; i++)
			{
				positions[i] = scan.nextInt();
				heights[i] = scan.nextInt();
			}
			for(int j = 1; j < numTrees-1; j++)
			{
				//System.out.println("right? " + positions[j] + "+" + heights[j] + "<?" + positions[j+1]);
				if(positions[j] - heights[j] > positions[j-1])
				{
					ans++;
					// System.out.println("fell tree " + j + " of height " + heights[j] + " to the left");
				}
				else if(positions[j] + heights[j] < positions[j+1])
				{
					ans++;
					// System.out.println("fell tree " + j + " of height " + heights[j] + " to the right");
					positions[j] += heights[j];
				}

			}
		}

		System.out.println(ans);
	}
}

#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
const int INF = INT_MAX;
const long long int LINF = LLONG_MAX;
int main() {
  ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
  int n, maxx = -INF, x, h, res = 0;
  cin >> n;
  pair<int, int> tree[n];
  for (int i = 0; i < n; ++i) cin >> tree[i].first >> tree[i].second;
  for (int i = 0; i < n; ++i) {
    int cx = tree[i].first, ch = tree[i].second;
    if (cx - ch > maxx) {
      res++;
      maxx = cx;
    } else if (i == n - 1 || cx + ch < tree[i + 1].first) {
      res++;
      maxx = cx + ch;
    } else {
      maxx = cx;
    }
  }
  cout << res;
  return 0;
}


import java.util.Scanner;

/**
 *
 * @author Marco
 */
public class CompilationErrors {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        // TODO code application logic here

        Scanner in = new Scanner(System.in);
        int cantidad = in.nextInt();
    long aux = 0, suma = 0;
        int num1, num2;
        for (int i = 0; i < cantidad; i++) {
            suma += in.nextInt();

        }
        for (int i = 0; i < cantidad - 1; i++) {
        aux += in.nextInt();

        }
        num1 = (int) (suma - aux);
        aux = 0;
        System.out.println(num1);
        for (int i = 0; i < cantidad - 2; i++) {
            aux += in.nextInt();

        }

        num2 = (int) (suma - aux - num1);
        System.out.println(num2);

    }

}

n = int(input())
a_sum = sum(map(int, input().split()))
b_sum = sum(map(int, input().split()))
c_sum = sum(map(int, input().split()))
print(a_sum - b_sum)
print(b_sum - c_sum)


def nik(rudy,x,y,z,cot):

    for i in range(z+1):
        for j in range(y+1):
            t = rudy - i*2 -j
            if t>=0 and x*0.5 >= t:
                cot+=1
    return cot
rudy, x, y, z = list(map(int,input().split()))
cot = 0
print(nik(rudy,x,y,z,cot))

#include <bits/stdc++.h>
using namespace std;
int main() {
  double n;
  int a, b, c, ans = 0;
  cin >> n >> a >> b >> c;
  for (int i = min(int(n / 2), c); i >= 0; i--) {
    for (int j = min(int(n - 2 * i), b); j >= 0; j--) {
      if (a / 2 + j + i * 2 >= n) {
        ans++;
      }
    }
  }
  cout << ans;
  return 0;
}


#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
int inline in() {
  int x = 0, c;
  for (; (unsigned)((c = getchar()) - '0') >= 10;) {
    if (c == '-') return -in();
    if (!~c) throw ~0;
  }
  do {
    x = (x << 3) + (x << 1) + (c - '0');
  } while ((unsigned)((c = getchar()) - '0') < 10);
  return x;
}
int k;
int main() {
  cin >> k;
  for (int i = 0; i < (k - 1); i++) {
    for (int j = 0; j < (k - 1); j++) {
      int pro = (i + 1) * (j + 1);
      if (pro >= k) {
        int tmp = pro / k;
        pro %= k;
        pro += tmp * 10;
      }
      cout << pro << ' ';
    }
    cout << endl;
  }
  return 0;
}

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

public class Main {

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

        int n = in.nextInt();

        for (int i = 1; i < n; i++) {
            for (int j = 1; j < n; j++) {
                Num a = new Num(n, 0, i);
                Num b = new Num(n, 0, j);

                out.print(a.mul(b));
                out.print(" ");
            }
            out.println();
        }

        out.flush();
    }

    private static class Num {

        int osn;
        int first;
        int second;

        public Num(int o, int f, int s) {
            osn = o;
            first = f;
            second = s;
        }

        public String mul(Num a) {
            Integer ansSecond = second * a.second;
            Integer ansFirst = ansSecond / osn;
            ansSecond %= osn;
            String ans;
            if (ansFirst == 0) {
                ans = ansSecond.toString();
            } else {
                ans = ansFirst.toString() + ansSecond.toString();
            }
            return ans;
        }
    }
}


#include <bits/stdc++.h>
using namespace std;
const int mod = 1000 * 1000 * 1000 + 7;
const int INF = 1e9 + 100;
const long long LINF = 1e18 + 100;
int32_t main(void) {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  ;
  int a, b;
  cin >> a >> b;
  int x = 0, ans = 0;
  while (a) {
    ans += a;
    x += a;
    a = x / b;
    x %= b;
  }
  cout << ans << '\n';
  return 0;
}

import java.util.Scanner;

public class Main {

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

		int a = in.nextInt();
		int b = in.nextInt();

		int num_hours = a;

		while (true) {
			if (a < b) {
				break;
			}
			num_hours += a / b;
			a = a / b + a % b;
		}

		System.out.println(num_hours);
	}

}


import java.util.Scanner;

public class b {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        double a = sc.nextDouble(), b = sc.nextDouble(), c = sc.nextDouble();
        sc.close();

        if (a == 0 && b == 0 && c == 0) {
            System.out.println("-1");
            return;
        }

        if (a == 0 && b == 0) {
            System.out.println("0");
            return;
        }

        if (a == 0) {
            System.out.printf("1\n%.10f\n", -c / b);
            return;
        }

        double d = (b * b) - (4 * a * c);

        if (d > 0) {
            double x1 = (-b - Math.sqrt(d)) / (a * 2), x2 = (-b + Math.sqrt(d)) / (a * 2);

            System.out.printf("2\n%.10f\n%.10f\n", Math.min(x1, x2), Math.max(x1, x2));
        } else if (d == 0) {
            System.out.printf("1\n%.10f\n", -b / (2 * a));
        } else {
            System.out.println("0");
        }
    }
}

#include <bits/stdc++.h>
using namespace std;
int main() {
  double A, B, C;
  double D;
  cin >> A >> B >> C;
  double x1, x2;
  if (!A) {
    if (!B) {
      if (!C) {
        printf("-1");
        return 0;
      } else {
        printf("0");
        return 0;
      }
    } else {
      printf("1\n");
      printf("%lf", -C / B);
    }
  } else {
    D = pow(B, 2) - (4 * A * C);
    if (D < 0) {
      printf("0");
      return 0;
    } else {
      D = sqrt(D);
    }
    x1 = (-B + D) / (2 * A);
    x2 = (-B - D) / (2 * A);
    if (x1 == x2) {
      cout << "1" << endl;
      printf("%lf", x1);
    } else {
      (x1 > x2) ? printf("2\n%lf\n%lf", x2, x1) : printf("2\n%lf\n%lf", x1, x2);
    }
  }
}


num,wiz,per = map(int,input().split())
k = 0
while (k+wiz)/num*100 < per:
    k += 1
print(k)

import java.util.Scanner;

public class WizardMeeting {

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

        int minCount = (int) Math.ceil( (double)(n)*(double)(y)/100 );
        minCount-=x;
        if (minCount<0) minCount=0;
        System.out.print(minCount);
    }
}


import java.util.*;

public class BadTriangle {
  public static void main(String[] args) {
    Scanner s = new Scanner(System.in);
    int t = s.nextInt();
    while (t-- > 0) {
      int n = s.nextInt();
      int[] a = new int[n];
      for (int i = 0; i < n; ++i) {
        a[i] = s.nextInt();
      }
      if (a[n - 1] >= a[0] + a[1]) {
        System.out.println("1 2 " + n);
      } else {
        System.out.println(-1);
      }
    }
  }
}

t=int(input())
for z in range(t):
    n=int(input())
    arr=list(map(int,input().split()))
    min= arr[0] + arr[1]
    pos=True
    for i in range(2,n):
        if(arr[i]>=min):
            pos=False
            posf=i
            break
    if(pos):
        print("-1")
    else:
        print("1 2", posf+1)


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

public class Codeforces
{
    public static void main(String args[])throws Exception
    {
        BufferedReader bu=new BufferedReader(new InputStreamReader(System.in));
        StringBuilder sb=new StringBuilder();
        String s[]=bu.readLine().split(" ");
        int n=Integer.parseInt(s[0]),k=Integer.parseInt(s[1]);
        ArrayList<Integer> ab=new ArrayList<>();
        ArrayList<Integer> a=new ArrayList<>();
        ArrayList<Integer> b=new ArrayList<>();
        int i,al=0,bo=0,x,y,z;
        for(i=0;i<n;i++)
        {
            s=bu.readLine().split(" ");
            x=Integer.parseInt(s[0]); y=Integer.parseInt(s[1]); z=Integer.parseInt(s[2]);
            if(y==1) al++;
            if(z==1) bo++;
            if(y==1 && z==1) ab.add(x);
            else if(y==1) a.add(x);
            else if(z==1) b.add(x);
        }
        if(al<k || bo<k) {System.out.print("-1"); return;}
        Collections.sort(ab); Collections.sort(a); Collections.sort(b);

        ArrayList<Integer> alb=new ArrayList<>();
        for(i=0;i<Math.min(a.size(),b.size());i++)
            alb.add(a.get(i)+b.get(i));
        int min=0,c=0;
        if(alb.size()==0)
        {
            for(i=0;i<k;i++)
                min+=ab.get(i);
            System.out.print(min);
            return;
        }
        if(ab.size()==0)
        {
            for(i=0;i<k;i++)
                min+=alb.get(i);
            System.out.print(min);
            return;
        }

        x=0; y=0;
        while(x<ab.size() && y<alb.size() && c<k)
        {
            if(ab.get(x)<alb.get(y)) {min+=ab.get(x); x++;}
            else {min+=alb.get(y); y++;}
            c++;
        }
        if(c==k) {System.out.print(min); return;}

        while(x<ab.size() && c<k)
        {
            min+=ab.get(x);
            x++;
            c++;
        }
        while(y<alb.size() && c<k)
        {
            min+=alb.get(y);
            y++;
            c++;
        }
        System.out.print(min);
    }
}

#include <bits/stdc++.h>
using namespace std;
template <typename T>
using minpq = priority_queue<T, vector<T>, greater<T>>;
int n, k, a, b;
long long t;
vector<long long> ve[2][2];
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> n >> k;
  for (int i = (0); i < (n); i++) {
    cin >> t >> a >> b;
    ve[a][b].push_back(t);
  }
  sort((ve[0][1]).begin(), (ve[0][1]).end());
  sort((ve[1][0]).begin(), (ve[1][0]).end());
  vector<long long> sums;
  for (long long x : ve[1][1]) sums.push_back(x);
  for (int i = 0; i < min(((int)(ve[0][1]).size()), ((int)(ve[1][0]).size()));
       i++) {
    sums.push_back(ve[0][1][i] + ve[1][0][i]);
  }
  sort((sums).begin(), (sums).end());
  if (((int)(sums).size()) < k) {
    cout << "-1\n";
    return 0;
  }
  cout << accumulate(sums.begin(), sums.begin() + k, 0LL) << '\n';
}


# -*- coding:utf-8 -*-

"""

created by shuangquan.huang at 2020/7/1

"""

import collections
import time
import os
import sys
import bisect
import heapq
from typing import List

def solve(n, l, r):
    # 1, 2, 1, 3, ..., 1, n
    # 2, 3, 2, 4, ..., 2, n
    # ...
    # n-1, n
    # 1

    lo, hi = 1, n
    while lo <= hi:
        k = (lo + hi) // 2
        s = k * (2*n-1-k)
        if s < l:
            lo = k + 1
        else:
            hi = k - 1

    k = lo
    s = k * (2*n-1-k)
    b = k

    # [b, b+1, b, b+2, ..., b, n]
    row = []
    for i in range(b+1, n+1):
        row.append(b)
        row.append(i)
    ans = row[l-s-1:]
    d = r-l+1
    if len(ans) >= d:
        return ans[:d]

    while len(ans) < d:
        b += 1
        row = []
        for i in range(b + 1, n + 1):
            row.append(b)
            row.append(i)
        if not row:
            break
        ans += row

    ans.append(1)
    # print(ans[:d])
    return ans[:d]

if __name__ == '__main__':
    T = int(input())
    ans = []
    for ti in range(T):
        N, L, R = map(int, input().split())
        ans.append(solve(N, L, R))
    print('\n'.join([' '.join(map(str, v)) for v in ans]))

#include <bits/stdc++.h>
using namespace std;
long long n;
int tc = 0;
int solve();
int main() {
  ios_base::sync_with_stdio(0);
  if (tc < 0) {
    cout << "TC!\n";
    cin.ignore(1e8);
  } else if (!tc)
    cin >> tc;
  while (tc--) solve();
  return 0;
}
int solve() {
  long long l, r;
  cin >> n >> l >> r;
  l--;
  r--;
  long long a = 1;
  while (1) {
    if (l > 2 * (n - a)) {
      l -= 2 * (n - a);
      r -= 2 * (n - a);
      a++;
    } else
      break;
  }
  vector<long long> ans;
  int b = a + 1;
  while (ans.size() <= r + 1) {
    ans.push_back(a);
    ans.push_back(b);
    b++;
    if (b == n + 1) {
      a++;
      if (a == n) {
        ans.push_back(1);
        break;
      }
      b = a + 1;
    }
  }
  for (int i = l; i <= r; i++) cout << ans[i] << " ";
  cout << endl;
  return 0;
}