codeparrot/codecomplex huggingface dataset:
// Problem: 1177_B. Digits Sequence (Hard Edition)
// Time complexity: logn
import java.util.Scanner;
 
public class Main {
 
	public static Character solve(long a, long b, long c) {
		long min = a;
		long max;
		long xth = 0;
		long index;
 
		for (index = String.valueOf(a).length() - 1;; index++) {
			long numOfDigits = 0;
			max = (long) Math.pow(10, index + 1) - 1;
			long count = (max - min) / b + 1;
			numOfDigits += count * (index + 1);
 
			if (c - numOfDigits <= 0) {
				break;
			}
			c -= numOfDigits;
			min = min + count * b;
 
		}
 
		// find xth
		if (c % (index + 1) == 0) {
			xth = c / (index + 1);
		} else {
			xth = c / (index + 1) + 1;
		}
		long lastNum = min + b * (xth - 1);
 
		int pos = (int) (c % (index + 1));
 
		// here is the output
		if (pos == 0) {
			return String.valueOf(lastNum).charAt((int) index);
		} else {
			return String.valueOf(lastNum).charAt(pos - 1);
		}
	}
 
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long tc;
		tc = sc.nextLong();
		System.out.println(solve(1, 1, tc));
		}
 
}
// Problem: 1177_B. Digits Sequence (Hard Edition)
// Time complexity: logn
import java.util.Scanner;

public class B1177 {

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        long N = in.nextLong();
        long answer = solve(N, 0, 1, 1);
        System.out.println(answer);
    }

    static long solve(long N, long offset, long start, int digits) {
        long thisSection = digits*start*9;
        long fromOffset = N-offset;
        if (fromOffset > thisSection) {
            return solve(N, offset+thisSection, 10*start, digits+1);
        }
        long number = start + (fromOffset-1)/digits;
        long posInNumber = digits - 1 - (fromOffset-1)%digits;
        while (posInNumber > 0) {
            posInNumber--;
            number /= 10;
        }
        return number%10;
    }

}
// Problem: 1080_D. Olya and magical square
// Time complexity: logn
import java.util.*;
import java.io.*;

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

	FastReader in = new FastReader();
	PrintWriter out = new PrintWriter(System.out);
	void run(){
		int q=in.nextInt();
		for(int i=0;i<q;i++) {
			work();
		}
		out.flush();
	}
	long mod=1000000007;
	long gcd(long a,long b) {
		return a==0?b:b>a?gcd(b%a,a):gcd(b,a);
	}
	void work() {
		long n=in.nextLong();
		long k=in.nextLong();
		if(k==0) {
			out.println("YES"+" "+n);
		}
		long a=0,b=0,c=1,d=1;
		while(--n>=0&&a<=k) {
			b+=c;
			c*=4;
			a+=d;
			d=d*2+1;
			long t=count(c-d,n);
			if(a<=k&&b>=k-t) {
				out.println("YES"+ " "+n);
				return;
			}
		}
		out.println("NO");
	}
	private long count(long l, long n) {
		if(n==0)return 0;
		n--;
		long ret=l;
		for(int i=1;i<=n;i++) {
			long t=ret;
			ret*=4;
			if(ret/4!=t)return Long.MAX_VALUE;
		}
		return ret;
	}
}	



class FastReader
{
	BufferedReader br;
	StringTokenizer st;

	public FastReader()
	{
		br=new BufferedReader(new InputStreamReader(System.in));
	}
	
	
	public String next() 
	{
		if(st==null || !st.hasMoreElements())
		{
			try {
				st = new StringTokenizer(br.readLine());
			} catch (IOException e) {
				e.printStackTrace();
			}
		}
		return st.nextToken();
	}

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

	public long nextLong()
	{
		return Long.parseLong(next());
	}
}
// Problem: 1080_D. Olya and magical square
// Time complexity: logn
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

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

    static class D {
        public void solve(int testNumber, FastScanner in, PrintWriter out) {
            int T = in.ni();
            for (int t = 0; t < T; t++) {
                long n = in.nl(), k = in.nl();
                if (n == 2 && k == 3) {
                    out.println("NO");
                    continue;
                }

                boolean possible = false;
                long size = n;
                long rem = k;
                for (int i = 0; i <= 31 && size > 0 && rem > 0; i++) {
                    long splits = 1L << (i * 2);
                    //System.out.println("splits = " + splits);
                    rem -= splits;
                    size--;
                }
                if (rem > 0) {
                    //System.out.println("rem = " + rem);
                    out.println("NO");
                    continue;
                }
                long path = 1;
                long i = 0;
                size = n;
                long ans = 0;

                while (path <= k && size > 0) {
                    //System.out.printf("path=%d k=%d size=%d%n", path, k, size);
                    k -= path;
                    path = (1L << i + 2) - 1;
                    size--;
                    i++;
                }

                //System.out.printf("size=%d k=%d%n", size, k);
                out.println("YES " + size);


            }
        }

    }

    static class FastScanner {
        private BufferedReader in;
        private StringTokenizer st;

        public FastScanner(InputStream stream) {
            in = new BufferedReader(new InputStreamReader(stream));
        }

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

        public int ni() {
            return Integer.parseInt(ns());
        }

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

    }
}
// Problem: 1080_D. Olya and magical square
// Time complexity: logn
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Scanner;

public class Main {

    static ArrayList<BigInteger> bs = new ArrayList<>();

    static void getBs(int n, BigInteger k) {
        BigInteger four = BigInteger.valueOf(4);
        BigInteger tmp4 = BigInteger.valueOf(1);
        BigInteger sum = BigInteger.ZERO;
        for (int i = 1; i <= n; i++) {
            sum = sum.add(tmp4);
            bs.add(sum);
            if (sum.compareTo(k) >= 0) break;
            tmp4 = tmp4.multiply(four);
        }
    }

    static int ss(int n, BigInteger k) {
        bs = new ArrayList<>();
        BigInteger two = BigInteger.valueOf(2);
        BigInteger s1;
        BigInteger ts = BigInteger.ZERO;
        getBs(n - 1, k);
        int idx = bs.size() - 1;
        BigInteger tx = BigInteger.valueOf(-1);
        int ans = -1;
        for (int i = 1; i <= n; i++) {
            two = two.shiftLeft(1);
            s1 = two.add(BigInteger.valueOf(-i - 2));
            if (idx >= 0) {
                tx = tx.add(BigInteger.ONE).multiply(BigInteger.valueOf(2)).add(BigInteger.ONE);
                ts = ts.add(tx.multiply(bs.get(idx--)));
            }
            if (k.compareTo(s1) >= 0) {
                if (k.subtract(s1).compareTo(ts) <= 0) {
                    ans = n - i;
                    break;
                }
            }
        }
        return ans;
    }

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int T = sc.nextInt();
        while (T-- > 0) {
            int n = sc.nextInt();
            BigInteger k = sc.nextBigInteger();
            int ans = ss(n, k);
            if (ans == -1) {
                System.out.println("NO");
            } else {
                System.out.println("YES " + ans);
            }
        }
    }
}
// Problem: 1080_D. Olya and magical square
// Time complexity: logn
import java.math.*;
import java.text.*;
import java.util.*;
public class Main {

    public static void main(String args[]) {
        Scanner sca = new Scanner(System.in);
        long k,n;
        long ans;
        long[] pw = new long[33];
        pw[1]=4;
        pw[0]=1;
        for(int i=2;i<=31;i++)
            pw[i]=pw[i-1]<<2;
        int t;
        t = sca.nextInt();
        for(int cas=1;cas<=t;cas++) {
            n = sca.nextLong();
            k = sca.nextLong();
            ans = n;
            long last, path = 1;
            for (int i = 0; ; i++) {
                if ((pw[i + 1] - 1) / 3 > k) {
                    ans -= i;
                    last = k - (pw[i] - 1) / 3;
                    break;
                }
                path *= 2;
            }
            long sp = path * 2 - 1;
            if (ans < 0 || (ans == 0 && last > 0)) {
                System.out.println("NO");
                continue;
            }
            BigInteger sq = BigInteger.valueOf(path).multiply(BigInteger.valueOf(path)).subtract(BigInteger.valueOf(sp));
            if (ans == 1 && sq.compareTo(BigInteger.valueOf(last))==-1 && last < sp) {
                System.out.println("NO");
                continue;
            } else if (ans == 1 && last >= sp) {
                ans--;
            }
            System.out.println("YES "+ans);
        }

    }
}
// Problem: 1080_D. Olya and magical square
// Time complexity: logn
import java.io.*;
import java.math.BigInteger;
import java.util.StringTokenizer;
import java.util.function.Function;

public class D {
    public static void main(String[] args) throws IOException {
        try (Input input = new StandardInput(); PrintWriter writer = new PrintWriter(System.out)) {
            long[] s = new long[40];
            for (int i = 1; i < s.length; i++) {
                s[i] = 1 + 4 * s[i - 1];
                if (i >= 32) {
                    s[i] = Long.MAX_VALUE;
                }
            }
            Function<Integer, Long> getS = (i) -> (i < s.length) ? s[i] : Long.MAX_VALUE;
            int t = input.nextInt();
            testCase:
            for (int tt = 0; tt < t; tt++) {
                int n = input.nextInt();
                long k = input.nextLong();
                long kk = 1;
                BigInteger maxDivisions = BigInteger.ZERO;
                for (int division = 1; division <= n; division++) {
                    long needToDivide = (1L << division) - 1;
                    if (needToDivide > k) {
                        writer.println("NO");
                        continue testCase;
                    }
                    k -= needToDivide;
                    maxDivisions = maxDivisions.add(BigInteger.valueOf(kk).multiply(BigInteger.valueOf(getS.apply(n - division))));
                    if (maxDivisions.compareTo(BigInteger.valueOf(k)) >= 0) {
                        writer.println("YES " + (n - division));
                        continue testCase;
                    }
                    kk += (1L << division + 1);
                }
                writer.println("NO");
            }
        }
    }

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

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

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

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

        private StringTokenizer stringTokenizer;

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

        @Override
        public String next() throws IOException {
            if (stringTokenizer == null || !stringTokenizer.hasMoreTokens()) {
                stringTokenizer = new StringTokenizer(reader.readLine());
            }
            return stringTokenizer.nextToken();
        }
    }
}
// Problem: 1080_D. Olya and magical square
// Time complexity: logn
import java.util.Scanner;

public class Solution {
    public static void main(String[] args) {
        Solution solution = new  Solution();
        solution.solve();
    }

    private void solve() {
        Scanner in = new Scanner(System.in);
        int t = in.nextInt();
        while (t -- > 0) {
            long n = in.nextLong();
            long k = in.nextLong();

            System.out.println(solve(n, k));
        }
    }

    private String solve(long n, long k) {
        if (n > 31) return "YES " + (n - 1);
        if (k > f(n)) return "NO";

        long square = 1;
        long splitDone = 0;
        long size = n;
        long splitLeft = 0;
        
        while (splitDone + square <= k && size > 0) {
            splitDone += square;
            --size;
            splitLeft += (square * 2 - 1) * f(size);
            square = square * 2 + 1;
        }
//        System.out.println(square + " " + splitDone + " " + size + " " + splitLeft);
        if (k > splitDone + splitLeft) return "NO";
        else return "YES " + size;
    }

    private long f(long x) {
        return ((1L << (2 * x)) - 1) / 3;
    }
}
// Problem: 1080_D. Olya and magical square
// Time complexity: logn
/*
If you want to aim high, aim high
Don't let that studying and grades consume you
Just live life young
******************************
What do you think? What do you think?
1st on Billboard, what do you think of it
Next is a Grammy, what do you think of it
However you think, I’m sorry, but shit, I have no fcking interest
*******************************
I'm standing on top of my Monopoly board
That means I'm on top of my game and it don't stop
til my hip don't hop anymore
https://www.a2oj.com/Ladder16.html
*******************************
300iq as writer = Sad!
*/
import java.util.*;
import java.io.*;
import java.math.*;

   public class x1080D
   {
      public static void main(String hi[]) throws Exception
      {
         long[] dp = new long[32];
         for(int i=1; i <= 31; i++)
            dp[i] = 1+4*dp[i-1];
         BufferedReader infile = new BufferedReader(new InputStreamReader(System.in));
         StringTokenizer st = new StringTokenizer(infile.readLine());
         int T = Integer.parseInt(st.nextToken());
         StringBuilder sb = new StringBuilder();
         matcha:while(T-->0)
         {
            st = new StringTokenizer(infile.readLine());
            int N = Integer.parseInt(st.nextToken());
            long K = Long.parseLong(st.nextToken());
            if(N >= 32 || K == 1)
               sb.append("YES "+(N-1)+"\n");
            else if(dp[N] == K)
               sb.append("YES 0\n");
            else if(dp[N] < K)
               sb.append("NO\n");
            else
            {
               long total = 3L;
               long length = 2;
               for(int res=N-1; res >= 0; res--)
               {
                  long min = 1+3*dp[N-1-res];
                  long max = min+dp[N-1];
                  long cansplit = total-2*length+1;
                  max += dp[res]*cansplit;
                  if(min <= K && K <= max)
                  {
                     sb.append("YES "+res+"\n");
                     continue matcha;
                  }
                  length <<= 1;
                  total *= 4;
               }
               sb.append("NO\n");
            }
         }
         System.out.print(sb);
      }
   }
// Problem: 1080_D. Olya and magical square
// Time complexity: logn
import java.io.*;
import java.util.*;

public class E implements Runnable {
	public static void main (String[] args) {new Thread(null, new E(), "_cf", 1 << 28).start();}
	
	long oo = (long)2e18;
	
	public void run() {
		FastScanner fs = new FastScanner();
		PrintWriter out = new PrintWriter(System.out);
		System.err.println("Go!");

		int t = fs.nextInt();
		while(t-->0) {
			int n = fs.nextInt();
			long k = fs.nextLong();
			long toCut = 1, numSquares = 1, free = 0;
			int cuts = 0;
			while(true) {
				if(cuts >= n) {
					k = oo;
					break;
				}
				k -= toCut;
				if(k < 0) {
					k = oo;
					break;
				}
				cuts++;
				try {
					free = Math.addExact(free, Math.multiplyExact(numSquares, getVal(n-cuts)));
				} catch (Exception e) {
					k = 0;
					break;
				}
				if(free >= k) {
					k = 0;
					break;
				}
				toCut += (1L<<cuts);
				numSquares += (1L<<(cuts+1));
			}
			if(k == 0) {
				out.printf("YES %d\n", n-cuts);
			}
			else {
				out.printf("NO\n");
			}
		}
		
		out.close();
	}
	
	long getVal(int n) {
		if(n > 31) return oo;
		long last = 0, cur = 0;
		for(int i = 1; i <= n; i++) {
			cur = 1 + 4*last;
			last = cur;
		}
		return cur;
	}
	
	class FastScanner {
		public int BS = 1<<16;
		public char NC = (char)0;
		byte[] buf = new byte[BS];
		int bId = 0, size = 0;
		char c = NC;
		double num = 1;
		BufferedInputStream in;

		public FastScanner() {
			in = new BufferedInputStream(System.in, BS);
		}

		public FastScanner(String s) throws FileNotFoundException {
			in = new BufferedInputStream(new FileInputStream(new File(s)), BS);
		}

		public char nextChar(){
			while(bId==size) {
				try {
					size = in.read(buf);
				}catch(Exception e) {
					return NC;
				}                
				if(size==-1)return NC;
				bId=0;
			}
			return (char)buf[bId++];
		}

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

		public long nextLong() {
			num=1;
			boolean neg = false;
			if(c==NC)c=nextChar();
			for(;(c<'0' || c>'9'); c = nextChar()) {
				if(c=='-')neg=true;
			}
			long res = 0;
			for(; c>='0' && c <='9'; c=nextChar()) {
				res = (res<<3)+(res<<1)+c-'0';
				num*=10;
			}
			return neg?-res:res;
		}

		public double nextDouble() {
			double cur = nextLong();
			return c!='.' ? cur:cur+nextLong()/num;
		}

		public String next() {
			StringBuilder res = new StringBuilder();
			while(c<=32)c=nextChar();
			while(c>32) {
				res.append(c);
				c=nextChar();
			}
			return res.toString();
		}

		public String nextLine() {
			StringBuilder res = new StringBuilder();
			while(c<=32)c=nextChar();
			while(c!='\n') {
				res.append(c);
				c=nextChar();
			}
			return res.toString();
		}

		public boolean hasNext() {
			if(c>32)return true;
			while(true) {
				c=nextChar();
				if(c==NC)return false;
				else if(c>32)return true;
			}
		}
		
		public int[] nextIntArray(int n) {
			int[] res = new int[n];
			for(int i = 0; i < n; i++) res[i] = nextInt();
			return res;
		}
		
	}

	
}
// Problem: 1080_D. Olya and magical square
// Time complexity: logn
import java.util.*;
import java.io.*;

public class code {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		int q = sc.nextInt();
		long[] d = new long[30];
		d[0] = 1;
		for(int i=1;i<30;i++) d[i] = d[i-1]*4;
		for(int z=0;z<q;z++){
		    long r = 0;
		    long n = sc.nextLong();
		    long k = sc.nextLong();
		    long c = 1;
		    while(k>0&&n>=1){
		        if(k<=r) {
		            k=0;
		            break;
		        }
		        n--;
		        k-=c;
		        if(k<=0) break;
		        
		        
		        if(n>30) {
		            k=0;
		            break;
		        }
		        for(int i=0;i<(int)n;i++){
		            r += d[i]*(c*2-1);
		            if(k<=r) {
		                k=0;
		                break;
		            }
		        }
		        if(k<=r) {
		            k=0;
		            break;
		        }
		        c*=2;
		        c++;
		    }
		    if(k==0) System.out.println("YES "+n);
		    else System.out.println("NO");
		}
	}
}


/*
NO
YES 0
YES 0
NO
NO
YES 999999942
YES 59
YES 63
YES 2
NO
YES 1
YES 1
NO
NO
YES 0
YES 0*/
// Problem: 1019_B. The hat
// Time complexity: logn
//package round503;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Random;
import java.util.Scanner;

public class B2 {
	Scanner in;
	PrintWriter out;
	String INPUT = "";
	
	// 12123432
	// 12343212
	
	int qc = 0;
	int n;
	
	int[] table;
	
	int val(int x)
	{
		if(table[x] != Integer.MIN_VALUE)return table[x];
		if(qc > 60)throw new RuntimeException();
		out.println("? " + (x+1));
		out.flush();
		table[x] = ni();
		
		if(table[x] == table[(x+table.length/2) % table.length]){
			if(x >= n/2)x -= n/2;
			out.println("! " + (x+1));
			out.flush();
			throw new IllegalStateException();
		}
		return table[x];
	}
	
	void solve()
	{
		n = ni();
		if(n % 4 != 0){
			out.println("! -1");
			out.flush();
			return;
		}
		table = new int[n];
		Arrays.fill(table, Integer.MIN_VALUE);
		Random gen = new Random(1);
		try{
			outer:
			while(true){
				int pu = gen.nextInt(n);
				int pd = (pu+n/2)%n;
				int pl = (pu + gen.nextInt(n/2-1)+1)%n;
				int pr = (pl+n/2)%n;
				
				int vu = val(pu), vd = val(pd);
				int vl = val(pl), vr = val(pr);
				if(cross(vu, vl, vd, vr)){
				}else if(cross(vu, vr, vd, vl)){
					int npu = pr, npl = pu;
					int npd = pl, npr = pd;
					pu = npu; pl = npl;
					pd = npd; pr = npr;
					vu = val(pu);
					vl = val(pl);
					vd = val(pd);
					vr = val(pr);
				}else{
					continue outer;
				}
				// u-l d-r
				while(true){
					int pul = h(pu, pl, n);
					int vul = val(pul);
					int pdr = h(pd, pr, n);
					int vdr = val(pdr);
					if(cross(vul, vu, vdr, vd)){
						pl = pul; vl = vul;
						pr = pdr; vr = vdr;
					}else{
						pu = pul; vu = vul;
						pd = pdr; vd = vdr;
					}
				}
			}
		}catch(IllegalStateException e)
		{
		}
	}
	
	int h(int a, int b, int n)
	{
		if(a > b){
			b += n;
		}
		int u = (a+b)/2;
		if(u >= n)u -= n;
		return u;
	}
	
	boolean cross(int a, int b, int c, int d)
	{
		return Integer.signum(c-a) != Integer.signum(d-b);
	}
	
	void run() throws Exception
	{
		in = oj ? new Scanner(System.in) : new Scanner(INPUT);
		out = new PrintWriter(System.out);

		long s = System.currentTimeMillis();
		solve();
		out.flush();
		tr(System.currentTimeMillis()-s+"ms");
	}
	
	public static void main(String[] args) throws Exception
	{
		new B2().run();
	}
	
	int ni() { return Integer.parseInt(in.next()); }
	long nl() { return Long.parseLong(in.next()); }
	double nd() { return Double.parseDouble(in.next()); }
	boolean oj = System.getProperty("ONLINE_JUDGE") != null;
	void tr(Object... o) { if(!oj)System.out.println(Arrays.deepToString(o)); }
}
//