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

/*
 * 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 Andy Phan
 */
public class p1173e {
    static int MOD = 998244353;
    static int n;
    static int m;
    static long[] invert;
    static long[][] f;
    static long[][] g;
    static boolean[][] df;
    static boolean[][] dg;
    static int[] sum;
    public static void main(String[] args) {
        FS in = new FS(System.in);
        PrintWriter out = new PrintWriter(System.out);
        n = in.nextInt();
        m = in.nextInt();
        invert = new long[2*m];
        int[] like = new int[n];
        sum = new int[2];
        int[] weight = new int[n];
        for(int i = 0; i < n; i++) like[i] = in.nextInt();
        for(int i = 0; i < n; i++) {
            weight[i] = in.nextInt();
            sum[1-like[i]] += weight[i];
        }
        for(int i = -(m-1); i < m; i++) invert[i+m-1] = modInv(sum[0]+sum[1]+i, MOD);
        f = new long[m][m];
        g = new long[m][m];
        df = new boolean[m][m];
        dg = new boolean[m][m];
        for(int i = 0; i < n; i++) if(like[i] == 0) out.println((g(0, 0)*weight[i])%MOD); else System.out.println((f(0, 0)*weight[i])%MOD);
        out.close();
    }

    static long f(int i, int j) {
        if(i+j == m) return 1;
        if(df[i][j]) return f[i][j];
        df[i][j] = true;
        return f[i][j] = (((((sum[0]+i+1)*invert[i-j+m-1])%MOD)*f(i+1, j))%MOD+((((sum[1]-j)*invert[i-j+m-1])%MOD)*f(i, j+1))%MOD)%MOD;
    }

    static long g(int i, int j) {
        if(i+j == m) return 1;
        if(dg[i][j]) return g[i][j];
        dg[i][j] = true;
        return g[i][j] = (((((sum[0]+i)*invert[i-j+m-1])%MOD)*g(i+1, j))%MOD+((((sum[1]-j-1)*invert[i-j+m-1])%MOD)*g(i, j+1))%MOD)%MOD;
    }

    //@
    static long gcd(long a, long b) { return b == 0 ? a : gcd(b, a % b); }
    static long lcm(long a, long b) { return a / gcd(a, b) * b; }

    //@
    // Computes the modular inverse of x
    // Returns 0 if the GCD of x and mod is not 1
    // O(log n)  :  Can be converted to use BigIntegers
    static long modInv(long x, long mod) {
            if(x == 1) return 1;
            if(gcd(x, mod) != 1) return 0;
            long r = mod % x;
            return (modInv(r, x % r, 0, 1, mod / x, x / r)+mod)%mod;
    }

    static long modInv(long a, long b, long y0, long y1, long q0, long q1) {
            long y2 = y0 - y1*q0;
            return b == 0 ? y2 : modInv(b, a % b, y1, y2, q1, a / b);
    }
    static class FS {
        BufferedReader in;
        StringTokenizer t;

        public FS(InputStream i) {
            in = new BufferedReader(new InputStreamReader(i));
        }

        public String next() {
            try {
                while(t == null || !t.hasMoreElements()) {
                    t = new StringTokenizer(in.readLine());
                }
            } catch(Exception e) {}
            return t.nextToken();
        }

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


import java.util.*;
public class queueAtSchool {
    public static void main(String [] args){
        Scanner s = new Scanner(System.in);
        int i, n = s.nextInt();
        int m = s.nextInt();
        String st = s.next();
        char ch[] = st.toCharArray();
        while(m!=0){
            for(i=1;i<n;i++){
                if(ch[i] == 'G' && ch[i-1] == 'B'){
                    ch[i] = 'B';
                    ch[i-1] = 'G';
                }
            }
        }
        for(i=0;i<n;i++){
            System.out.print(ch[i]);
        }
        System.out.println();
    }
}


import java.util.*;
public class Main
{
	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		int x=sc.nextInt();
		int h=sc.nextInt();
		int m=sc.nextInt();
		int count=0;
		if(h%10==7){
		    System.out.println(count);
		}
		else{
    		while(m%10!=7){
    		    m=m-x;
    		    count++;
    		    if(m<0){
    		        m=60+m;
    		        if(h==1){
    		            h=24;
    		        }
    		        else{
    		            h--;
    		        }
    		    }
    		    if(h%10==7){
    		        break;
    		    }
    	    }
    	    System.out.println(count);
		}
	}
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;
public class LOL {
	public static void main(String [] args)throws IOException {
		Scanner sc=new Scanner(System.in);
		int n=sc.nextInt();
		int x=sc.nextInt()-1;
		int y=sc.nextInt()-1;
		int count=0;
		if(Math.abs(x-y)>=n/2) {
			System.out.println("Final!");
		}
		else {
			while(x!=y) {
				System.out.println(count);
				count++;
				if(x!=1) {
					x=x/2;
				}
				if(y!=1) {
					y=y/2;
				}

			}

		System.out.println(count);
		}

	}

	static class Scanner {
		StringTokenizer st;
		BufferedReader br;

		public Scanner(InputStream s) {
			br = new BufferedReader(new InputStreamReader(s));
		}

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

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

		public int[] nextIntArr(int n) throws IOException {
			int[] arr = new int[n];
			for (int i = 0; i < n; i++)
				arr[i] = nextInt();
			return arr;
		}

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

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

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

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

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


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

public class C {

	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		PrintWriter out = new PrintWriter(System.out);
		String x = sc.next();
		int n = x.length();
		long all = Long.parseLong(x, 2);
		BigInteger m = BigInteger.valueOf(2).modPow(BigInteger.valueOf(n - 1), BigInteger.valueOf(1000000007));
		BigInteger res = m.multiply(BigInteger.valueOf(all).mod(BigInteger.valueOf(1000000007)));
		res = res.mod(BigInteger.valueOf(1000000007));
		out.println(res);
		out.flush();
		out.close();
	}

	static class Scanner {
		StringTokenizer st;
		BufferedReader br;

		public Scanner(InputStream s) {
			br = new BufferedReader(new InputStreamReader(s));
		}

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

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

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

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

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

	}
}


package algorithms;

import java.util.Scanner;

public class B910 {

	static int sizeA;
	static int sizeB;
	static int sizeN;

	static void doit(int a, int b, int size, int count){
		if(a == 0 && b == 0) res = Math.min(res, count);
		else {
			if(a > 0 && size >= sizeA) doit(a-1,b,size-sizeA,count);
			if(a > 0 && size < sizeA) doit(a,b,sizeN,count+1);
			if(b > 0 && size >= sizeB) doit(a,b-1,size-sizeB,count);
			if(b > 0 && size < sizeB) doit(a,b,sizeN,count+1);
		}
	}

	static int res = 10;

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

		sizeN = in.nextInt();
		sizeA = in.nextInt();
		sizeB = in.nextInt();
		doit(4,2, sizeN,1);
		System.out.println(res);

		in.close();
	}
}


import java.awt.Point;
import java.io.*;
import java.math.BigInteger;
import java.util.*;
import static java.lang.Math.*;

public class C {

	final boolean ONLINE_JUDGE = System.getProperty("ONLINE_JUDGE") != null;
	BufferedReader in;
	PrintWriter out;
	StringTokenizer tok = new StringTokenizer("");

	void solve() throws IOException {
		long n = readLong();
		long t = readLong();
		long[][] dp = dp();
		int pow = 0;
		long cur = 1;
		for (int i = 0; cur <= t; i++) {
			if (cur == t) {
				pow = i;
				break;
			} else {
				cur *= 2;
			}
		}
		if (cur != t) {
			out.println(0);
			return;
		}

		long res = 0;
		int curPow = 1;
		long curCh = 2;
		while (curCh * 2 <= n) {
			res += dp[curPow][pow];
			curPow++;
			curCh *= 2;
		}
		res += res(n, curPow, pow, curCh, curCh*2 -1, dp);
		out.println(res);
	}

	long res(long n, int i, int j, long left, long right, long[][] dp){
		long res = 0;
		if(i == 0){
			res += dp[i][j];
			return res;
		}
		long mid = (left+right)/2;

		if(n > mid){
			res += dp[i-1][j];
			res += res(n, i-1, j-1, mid+1, right, dp);
		}
		else{
			res =  res(n, i-1, j, left, mid, dp);
		}
		return res;
	}

	long[][] dp() {
		long[][] dp = new long[42][42];
		dp[0][0] = 1;
		for (int i = 1; i < 42; i++) {
			dp[i][0] = 1;
			for (int j = 1; j < 42; j++) {
				dp[i][j] = dp[i - 1][j] + dp[i - 1][j - 1];
			}
		}
		return dp;
	}

	void init() throws FileNotFoundException {
		if (ONLINE_JUDGE) {
			in = new BufferedReader(new InputStreamReader(System.in));
			out = new PrintWriter(System.out);
		} else {
			in = new BufferedReader(new FileReader("input.txt"));
			out = new PrintWriter("output.txt");
		}
	}

	String readString() throws IOException {
		while (!tok.hasMoreTokens()) {
			tok = new StringTokenizer(in.readLine());
		}
		return tok.nextToken();
	}

	int readInt() throws IOException {
		return Integer.parseInt(readString());
	}

	long readLong() throws IOException {
		return Long.parseLong(readString());
	}

	double readDouble() throws IOException {
		return Double.parseDouble(readString());
	}

	int[] readArr(int n) throws IOException {
		int[] res = new int[n];
		for (int i = 0; i < n; i++) {
			res[i] = readInt();
		}
		return res;
	}

	long[] readArrL(int n) throws IOException {
		long[] res = new long[n];
		for (int i = 0; i < n; i++) {
			res[i] = readLong();
		}
		return res;
	}

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

	public void run() {
		try {
			long t1 = System.currentTimeMillis();
			init();
			solve();
			out.close();
			long t2 = System.currentTimeMillis();
			System.err.println("Time = " + (t2 - t1));
		} catch (Exception e) {
			e.printStackTrace(System.err);
			System.exit(-1);
		}
	}
}


package codeforces.r236;
import java.io.InputStream;
import java.util.Scanner;

public class CF236A {

	String solve(int k, int a, int b, int v) {
		int cnt = 0;
		while (a > 0) {
			int y = Math.min(b, k - 1);
			b -= y;
			a -= (y + 1) * v;
			cnt += 1;
		}
		return cnt + "";
	}

	String solve(InputStream in) {
		Scanner sc = new Scanner(in);
		int k = sc.nextInt();
		int a = sc.nextInt();
		int b = sc.nextInt();
		int v = sc.nextInt();
		return solve(k, a, b, v);
	}

	public static void main(String[] args) {
		System.out.println(new CF236A().solve(System.in));
	}
}


package SetA;

import java.util.Scanner;

public class A750_NewYearAndHurry {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int k = scanner.nextInt();
        int rem = 240 - k;
        int i = 0;
        while (i <= n && rem >= 0) {
            i++;
            rem -= 5 * i;
        }
        System.out.println(i - 1);
    }
}


package math;

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

public class RoadToPostOffice {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer tk = new StringTokenizer(br.readLine());
		long d = Long.parseLong(tk.nextToken());
		long k = Long.parseLong(tk.nextToken());
		int a = Integer.parseInt(tk.nextToken());
		int b = Integer.parseInt(tk.nextToken());
		int t = Integer.parseInt(tk.nextToken());

		if( d <= k)
			System.out.println(a*d);
		else
		{
			if( b*k <= k*a + t  )
			{
				System.out.println(a*k +b*(d-k));
			}
			else{
				long usedCar = d/k;
				long res = usedCar*a*k +  (Math.max((usedCar-1) , 0)*t);
				long rem = d % k;

				long foot = rem*b;
				long withCar = rem*a;
				res+= Math.min(foot, withCar+t);
				System.out.println(res);
			}
		}
	}

}


//  أليلتنا بذي حسم انيري*** إذا انت انقضيت فلا تحوري
//فإن يكن بالذنائب طال ليلي *** فقد ابكي من الليل القصيري
import java.util.Scanner;
public class JavaApplication1 {
    public static void main(String[] args){
       Scanner read = new Scanner(System.in);
       int x,k;
       x=read.nextLong();
       k=read.nextLong();
       if(x!=k){
           System.out.println("1");
       }
       else{
           System.out.println(k);
       }
    }
}


import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;
public class Restore {
    public static void main(String[] args) throws IOException {
         BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
        String brr[]=br.readLine().trim().split(" ");
        String s=brr[0];
       int i,j,k=0;
       int crr[]=new int[10];
       String p,d;
        for(i=0;i<10;i++)
        {
            brr=br.readLine().trim().split(" ");
            p=brr[0];
            for(j=0;j<8;j++)
            {

                d=s.substring(j*10, (j+1)*10);
              // System.out.println(p+" "+d);
                if(p.equals(d))
                {
                    crr[k]=j;
                    k++
                     break;
                }
            }
        }
        for(i=0;i<k;i++)
            System.out.print(crr[i]);
    }
}


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

// SHIVAM GUPTA :
//NSIT
//decoder_1671
//BEING PERFECTIONIST IS NOT AN OPTION.
// STOP NOT TILL IT IS DONE OR U DIE .
//EITHER MAKE IT OR BREAK IT.
//NEVER UNDERESTIMATE URSELF.
// U KNOW THAT IF THIS DAY WILL BE URS THEN NO ONE CAN DEFEAT U
// REST ..HAVE FAITH ON DESTINY

// ASCII = 48 + i ;

// 2^28 = 268,435,456  > 10^8

// log 10 base 2 = 3.3219

// odd:: (x^2+1)/2 , (x^2-1)/2 ; x>=3

// even:: (x^2/4)+1 ,(x^2/4)-1  x >=4

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

public class Main
{

    // static int[] arr = new int[100002] ;
    // static int[] dp = new int[100002] ;

     static PrintWriter out;

	static class FastReader{
		BufferedReader br;
		StringTokenizer st;
		public FastReader(){
			br=new BufferedReader(new InputStreamReader(System.in));
			out=new PrintWriter(System.out);
		}
		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;
		}
	}

////////////////////////////////////////////////////////////////////////////////////
 public static int countDigit(long n)
    {
        return (int)Math.floor(Math.log10(n) + 1);
    }

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

 public static int sumOfDigits(long n)
 {

  if( n< 0)return -1 ;

  int sum = 0;

  while( n > 0)
  {
      sum = sum + (int)( n %10) ;

      n /= 10 ;
  }

  return sum ;

 }

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

public static long arraySum(int[] arr , int start , int end)
{
    long ans = 0 ;

    for(int i = start ; i <= end  ; i++)ans += arr[i] ;

    return ans  ;
}

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

public static int mod(int x)
{
      if(x <0)return -1*x ;
      else return x ;
}
public static long mod(long x)
{
      if(x <0)return -1*x ;
      else return x ;
}

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

public static void swapArray(int[] arr , int start , int end)
{
    while(start < end)
    {
        int temp = arr[start] ;
        arr[start] = arr[end];
        arr[end] = temp;
        start++ ;end-- ;
    }
}

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

public static int[][] rotate(int[][] input){

int n =input.length;
int m = input[0].length ;
int[][] output = new int [m][n];

for (int i=0; i<n; i++)
	for (int j=0;j<m; j++)
		output [j][n-1-i] = input[i][j];
return output;
}
///////////////////////////////////////////////////////////////////////////////////////////////////////

public static int countBits(long number)
    {

        // log function in base 2
        // take only integer part
        return (int)(Math.log(number) /
                     Math.log(2) + 1);
    }
/////////////////////////////////////////// ////////////////////////////////////////////////

public static boolean isPowerOfTwo(long n)
{
    if(n==0)
    return false;

if(((n ) & (n-1)) == 0 ) return true ;
else return false  ;

}

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

public static int  min(int a ,int b , int c, int d)
{
     int[] arr = new int[4] ;
      arr[0] = a;arr[1] = b ;arr[2] = c;arr[3] = d;Arrays.sort(arr) ;

       return arr[0];
}
 /////////////////////////////////////////////////////////////////////////////
public static int  max(int a ,int b , int c, int d)
{
     int[] arr = new int[4] ;
      arr[0] = a;arr[1] = b ;arr[2] = c;arr[3] = d;Arrays.sort(arr) ;

       return arr[3];
}

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

public static String reverse(String input)
{
   StringBuilder str  = new StringBuilder("") ;

    for(int i =input.length()-1 ; i >= 0  ; i-- )
    {
        str.append(input.charAt(i));
    }

return str.toString() ;
}
///////////////////////////////////////////////////////////////////////////////////////////

public static boolean sameParity(long a  ,long b )
{
      if(a %2 ==0 && b % 2 == 0)return true ;
      else return false  ;
}

////////////////////////////////////////////////////////////////////////////////////////////////////
public static boolean isPossibleTriangle(int a  ,int b , int c)
{
      if( a + b > c && c+b > a && a +c > b)return true  ;
      else return false  ;
}

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

public static int gcd(int a, int b )
{

if(b==0)return a ;

else return gcd(b,a%b) ;

}

public static long gcd(long a, long b )
{

if(b==0)return a ;

else return gcd(b,a%b) ;

}

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

public static int lcm(int a, int b ,int c , int d )
{

int temp = lcm(a,b , c) ;

 int ans = lcm(temp ,d ) ;

return ans  ;

}

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

public static int lcm(int a, int b ,int c )
{

int temp = lcm(a,b) ;

int ans =  lcm(temp ,c) ;

return ans  ;

}

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

public static int lcm(int a , int b )
{

int gc = gcd(a,b);

return (a*b)/gc ;
}

///////////////////////////////////////////////////////////////////////////////////////////
static boolean isPrime(long n)
{
      if(n==1)
      {
            return false  ;
      }

      boolean ans =  true  ;

      for(long i = 2L; i*i <= n ;i++)
      {
            if(n% i ==0)
            {
                  ans = false  ;break ;
            }
      }

      return ans  ;
}
///////////////////////////////////////////////////////////////////////////

static int sieve =  1000000 ;

static boolean[] prime =  new boolean[sieve + 1] ;

public static void sieveOfEratosthenes()
    {
        // FALSE == prime

        // TRUE ==  COMPOSITE

        // FALSE== 1

        // time complexity = 0(NlogLogN)== o(N)

        // gives prime nos bw 1 to N

        for(int i = 2; i<= sieve ; i++)
        {
            prime[i] = true  ;
            i++ ;
        }

        for(int p = 3; p*p <= sieve; p++)
        {

            if(prime[p] == false)
            {

                for(int i = p*p; i <= sieve; i += p)
                    prime[i] = true;
            }

            p++ ;
        }

    }

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

public static void sortD(int[] arr , int s  , int e)
{
      sort(arr ,s , e) ;

      int i =s ; int j = e  ;

      while( i < j)
      {
            int temp = arr[i] ;
            arr[i] =arr[j] ;
            arr[j] = temp ;
            i++ ; j-- ;
      }

      return ;
}

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

public static long countSubarraysSumToK(long[] arr ,long sum )
    {
      HashMap<Long,Long> map = new HashMap<>() ;

      int n = arr.length ;

      long prefixsum = 0 ;

      long count = 0L ;
      for(int i  = 0; i < n ; i++)
      {
          prefixsum  = prefixsum +  arr[i] ;

          if(sum == prefixsum)count = count+1 ;

          if(map.containsKey(prefixsum -sum))
          {
              count = count + map.get(prefixsum -sum) ;
          }

          if(map.containsKey(prefixsum ))
          {
              map.put(prefixsum , map.get(prefixsum) +1 );
          }

          else{
              map.put(prefixsum , 1L );
          }

      }

      return count  ;

    }

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

 // CALCULATE TOTIENT Fn FOR ALL VALUES FROM 1 TO n
    // TOTIENT(N) = count of nos less than n and grater than 1 whose gcd with n is 1
    // or n and the no  will be coprime in nature
    //time : O(n*(log(logn)))

    public static void eulerTotientFunction(int[] arr ,int n )
    {

      for(int i = 1; i <= n  ;i++)arr[i] =i  ;

      for(int i= 2 ; i<= n ;i++)
      {
          if(arr[i] == i)
          {
              arr[i] =i-1 ;

              for(int j =2*i ; j<= n  ; j+= i )
              {
                  arr[j] = (arr[j]*(i-1))/i ;
              }

          }
      }

      return  ;

    }

/////////////////////////////////////////////////////////////////////////////////////////////
public static long nCr(int n,int k)
{
    long ans=1;
    k=k>n-k?n-k:k;
    int j=1;
    for(;j<=k;j++,n--)
    {
        if(n%j==0)
        {
            ans*=n/j;
        }else
        if(ans%j==0)
        {
            ans=ans/j*n;
        }else
        {
            ans=(ans*n)/j;
        }
    }
    return ans;
}

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

public static ArrayList<Integer> allFactors(int n)
{
      ArrayList<Integer> list = new ArrayList<>() ;

    for(int i = 1; i*i <= n ;i++)
    {
          if( n % i == 0)
          {
              if(i*i == n)
              {
                    list.add(i) ;
              }
              else{
                    list.add(i) ;
                    list.add(n/i) ;

              }
          }
    }

     return list ;

}

public static ArrayList<Long> allFactors(long n)
{
      ArrayList<Long> list = new ArrayList<>() ;

    for(long i = 1L; i*i <= n ;i++)
    {
          if( n % i == 0)
          {
              if(i*i == n)
              {
                    list.add(i) ;
              }
              else{
                    list.add(i) ;
                    list.add(n/i) ;

              }
          }
    }

     return list ;

}
////////////////////////////////////////////////////////////////////////////////////////////////////

  static final int MAXN = 100001;

    static int spf[] = new int[MAXN];

    static void sieve()
    {
        spf[1] = 1;
        for (int i=2; i<MAXN; i++)

            spf[i] = i;

        for (int i=4; i<MAXN; i+=2)
            spf[i] = 2;

        for (int i=3; i*i<MAXN; i++)
        {

            if (spf[i] == i)
            {

                for (int j=i*i; j<MAXN; j+=i)

                    if (spf[j]==j)
                        spf[j] = i;
            }
        }
    }

// The above code works well for n upto the order of 10^7.
// Beyond this we will face memory issues.

// Time Complexity: The precomputation for smallest prime factor is done in O(n log log n)
// using sieve.
// Where as in the calculation step we are dividing the number every time by
// the smallest prime number till it becomes 1.
// So, let’s consider a worst case in which every time the SPF is 2 .
// Therefore will have log n division steps.

// Hence, We can say that our Time Complexity will be O(log n) in worst case.

    static Vector<Integer> getFactorization(int x)
    {
        Vector<Integer> ret = new Vector<>();
        while (x != 1)
        {
            ret.add(spf[x]);
            x = x / spf[x];
        }
        return ret;
    }

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

public static void merge(int arr[], int l, int m, int r)
    {
        // Find sizes of two subarrays to be merged
        int n1 = m - l + 1;
        int n2 = r - m;

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

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

        /* Merge the temp arrays */

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

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

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

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

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

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

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

public static void sort(long arr[], int l, int r)
    {
        if (l < r)
        {
            // Find the middle point
            int m = (l+r)/2;

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

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

public static void merge(long arr[], int l, int m, int r)
    {
        // Find sizes of two subarrays to be merged
        int n1 = m - l + 1;
        int n2 = r - m;

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

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

        /* Merge the temp arrays */

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

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

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

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

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

	public static long knapsack(int[] weight,long value[],int maxWeight){

        int n=  value.length ;

	//dp[i] stores the profit with KnapSack capacity "i"
  long []dp = new long[maxWeight+1];

    //initially profit with 0 to W KnapSack capacity is 0
    Arrays.fill(dp, 0);

    // iterate through all items
    for(int i=0; i < n; i++)

        //traverse dp array from right to left
        for(int j = maxWeight; j >= weight[i]; j--)
            dp[j] = Math.max(dp[j] , value[i] + dp[j - weight[i]]);

    /*above line finds out maximum of dp[j](excluding ith element value)
    and val[i] + dp[j-wt[i]] (including ith element value and the
    profit with "KnapSack capacity - ith element weight") */
    return dp[maxWeight];
	}

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

// to return max sum of any subarray in given array
public static long kadanesAlgorithm(long[] arr)
{
      long[] dp = new long[arr.length] ;

      dp[0] = arr[0] ;
      long max =  dp[0] ;

      for(int i = 1; i <  arr.length ; i++)
      {
            if(dp[i-1] > 0)
            {
                  dp[i] = dp[i-1] + arr[i] ;
            }
            else{
                  dp[i] = arr[i] ;
            }

            if(dp[i] >  max)max = dp[i] ;

      }

      return max  ;

}
/////////////////////////////////////////////////////////////////////////////////////////////
public static long kadanesAlgorithm(int[] arr)
{
      long[] dp = new long[arr.length] ;

      dp[0] = arr[0] ;
      long max =  dp[0] ;

      for(int i = 1; i <  arr.length ; i++)
      {
            if(dp[i-1] > 0)
            {
                  dp[i] = dp[i-1] + arr[i] ;
            }
            else{
                  dp[i] = arr[i] ;
            }

            if(dp[i] >  max)max = dp[i] ;

      }

      return max  ;

}

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

// Arrays.sort(arr, new Comparator<Pair>() {
// 			@Override
// 			public int compare(Pair first, Pa second) {
// 				if (first.getAge() != second.getAge()) {
// 					return first.getAge() - second.getAge();
// 				}
// 				return first.getName().compareTo(second.getName());
// 			}
// 		});

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

public static long binarySerachGreater(int[] arr , int start , int end , int val)
{

      // fing total no of elements strictly grater than val in sorted array arr

      if(start >  end)return  0 ; //Base case

      int mid = (start + end)/2  ;

      if(arr[mid] <=val)
      {
          return binarySerachGreater(arr,mid+1, end ,val) ;

      }
      else{

         return binarySerachGreater(arr,start , mid -1,val) + end-mid+1 ;

      }

}

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

//TO GENERATE ALL(DUPLICATE ALSO EXIST) PERMUTATIONS OF A STRING

// JUST CALL generatePermutation( str,  start,  end) start :inclusive ,end : exclusive

//Function for swapping the characters at position I with character at position j
    public static String swapString(String a, int i, int j) {
        char[] b =a.toCharArray();
        char ch;
        ch = b[i];
        b[i] = b[j];
        b[j] = ch;
        return String.valueOf(b);
    }

//Function for generating different permutations of the string
    public static void generatePermutation(String str, int start, int end)
    {
        //Prints the permutations
        if (start == end-1)
            System.out.println(str);
        else
        {
            for (int i = start; i < end; i++)
            {
                //Swapping the string by fixing a character
                str = swapString(str,start,i);
                //Recursively calling function generatePermutation() for rest of the characters
                generatePermutation(str,start+1,end);
                //Backtracking and swapping the characters again.
                str = swapString(str,start,i);
            }
        }
    }

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

public static long factMod(long n, long mod) {
    if (n <= 1) return 1;
    long ans = 1;
    for (int i = 1; i <= n; i++) {
      ans = (ans * i) % mod;
    }
    return ans;
  }

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

public static long power(int x  ,int n)
    {
        //time comp : o(logn)

        if(n==0)return 1 ;
        if(n==1)return x;

        long ans =1L  ;

      while(n>0)
      {
          if(n % 2 ==1)
          {
              ans = ans *x ;
          }

          n /= 2 ;

          x =  x*x ;

      }

      return ans ;
    }

////////////////////////////////////////////////////////////////////////////////////////////////////
public static long powerMod(long x, long n, long mod) {
    //time comp : o(logn)

    if(n==0)return 1L ;
        if(n==1)return x;

    long ans = 1;
    while (n > 0) {
      if (n % 2 == 1) ans = (ans * x) % mod;
      x = (x * x) % mod;
      n /= 2;
    }
    return ans;
  }

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

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

/*
lowerBound - finds largest element equal or less than value paased
upperBound - finds smallest element equal or more than value passed

if not present return -1;

*/

public static long lowerBound(long[] arr,long k)
	{
		long ans=-1;

		int start=0;
		int end=arr.length-1;

		while(start<=end)
		{
			int mid=(start+end)/2;

			if(arr[mid]<=k)
			{
				ans=arr[mid];
				start=mid+1;
			}
			else
			{
				end=mid-1;
			}

		}

		return ans;

	}

	public static int lowerBound(int[] arr,int k)
	{
		int ans=-1;

		int start=0;
		int end=arr.length-1;

		while(start<=end)
		{
			int mid=(start+end)/2;

			if(arr[mid]<=k)
			{
				ans=arr[mid];
				start=mid+1;
			}
			else
			{
				end=mid-1;
			}

		}

		return ans;

	}

	public static long upperBound(long[] arr,long k)
	{
		long ans=-1;

		int start=0;
		int end=arr.length-1;

		while(start<=end)
		{
			int mid=(start+end)/2;

			if(arr[mid]>=k)
			{
				ans=arr[mid];
				end=mid-1;
			}
			else
			{
				start=mid+1;
			}

		}

		return ans;
	}

	public static int upperBound(int[] arr,int k)
	{
		int ans=-1;

		int start=0;
		int end=arr.length-1;

		while(start<=end)
		{
			int mid=(start+end)/2;

			if(arr[mid]>=k)
			{
				ans=arr[mid];
				end=mid-1;
			}
			else
			{
				start=mid+1;
			}

		}

		return ans;
	}

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

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

public static void solve()
{
FastReader scn = new FastReader() ;

//int[] store = {2 ,3, 5 , 7  ,11 , 13 , 17 , 19 , 23 , 29 , 31 , 37 } ;

// product of first 11 prime nos is gre ater than 10 ^ 12;

//ArrayList<Integer> list = new ArrayList<>() ;
ArrayList<Long> list = new ArrayList<>() ;
ArrayList<Integer> lista = new ArrayList<>() ;
ArrayList<Integer> listb = new ArrayList<>() ;

//HashMap<Integer,Integer> map = new HashMap<>() ;
HashMap<Long,Integer> map = new HashMap<>() ;
HashMap<Integer,Integer> map1  = new HashMap<>() ;
HashMap<Integer,Integer> map2  = new HashMap<>() ;
//HashMap<String,Integer> maps = new HashMap<>() ;
//HashMap<Integer,Boolean> mapb = new HashMap<>() ;
//HashMap<Point,Integer> point = new HashMap<>() ;

Set<Integer> set = new HashSet<>() ;
Set<Integer> setx = new HashSet<>() ;
Set<Integer> sety = new HashSet<>() ;

//if(map.containsKey(arr[i]))map.put(arr[i] , map.get(arr[i]) +1 ) ;
//else map.put(arr[i],1) ;

// if(map.containsKey(temp))map.put(temp , map.get(temp) +1 ) ;
// else map.put(temp,1) ;

int t = 1;
 t = scn.nextInt() ;

while(t-- > 0)
{

 //String str  = scn.next() ;
 long n = scn.nextLong() ;
  long k = scn.nextLong() ;
  //long a = scn.nextLong() ;
  //long b = scn.nextLong() ;

 //int n = scn.nextInt() ;
 //int m = scn.nextInt() ;
 // int x  = scn.nextInt() ;
// int y = scn.nextInt() ;
//int k = scn.nextInt() ;
//int a = scn.nextInt() ;
//int c = scn.nextInt() ;
// int d = scn.nextInt() ;
//int b = scn.nextInt() ;

if( k==1)
{
  out.println(n) ;
}

else{

    long bit = countBits(n) ;

    long ans =  Math.pow(2.0,(1.0*bit)) ;

    out.println(ans-1) ;
}

//for(int i = 0; i < n; i++)out.print(arr[i]+ " ") ;

//out.println() ;

list.clear() ;
map.clear() ;
map1.clear() ;
map2.clear() ;
set.clear() ;
} // test case  end loop

out.flush() ;
}

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

solve() ;

}

}

 class Pair
{
  int first ;

  int second  ;

@Override
	public String toString() {

	String ans = "" ;
	ans  += this.first ;
	ans += " ";
	ans += this.second ;

	return ans  ;
	}

}


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

public class B948 {

    boolean[] prime;

    private void solve() throws Exception {
        int max = 1000000;
        prime = new boolean[max+1];
        Arrays.fill(prime, true);
        prime[1] = false;
        for(int i = 2; i*i <= max; i++) if(prime[i]) for(int j = 2*i; j <= max; j = j + i) prime[j] = false;
        int X = nextInt();
        doit(X,2);
        out.println(min);
    }

    int min = 1<<30;

    void doit(int X, int i) {
        if(i == 0) min = Math.min(X, min);
        else {
            for(int p = 2; p*p <= X; p++) {
                if(X%p == 0) {
                    int q = X/p;
                    if(prime[p]) for(int j = X-p+1; j <= X; j++) doit(j,i-1);
                    if(prime[q]) for(int j = X-q+1; j <= X; j++) doit(j,i-1);
                }
            }
        }
    }

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

	private BufferedReader in;
	private PrintWriter out;
	private StringTokenizer tokenizer;

	public void run() {
		try {
			in = new BufferedReader(new InputStreamReader(System.in));
			tokenizer = null;
			out = new PrintWriter(System.out);
			solve();
			in.close();
			out.close();
		} catch (Exception e) {
			e.printStackTrace();
			System.exit(1);
		}
	}

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

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

	private float nextFloat() throws IOException {
		return Float.parseFloat(nextToken());
	}

	private String nextLine() throws IOException {
		return new String(in.readLine());
	}

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

}


import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.Scanner;
import java.util.Vector;
public class Main {
	static final long mod=1000000007;
	public static void main(String[] args) {
		long a[]=new long[20];
		Scanner sc=new Scanner(System.in);
		int n=sc.nextInt();
		long s=sc.nextLong();
		for(int i=0;i<n;i++)
				a[i]=sc.nextLong();
		int len=(1<<n);
		long ans=0;
		for(int i=0;i<len;i++){
			long x=s;
			int flag=1;
			for(int j=0;j<len;j++)
				if(((i>>j)&1)==1){
					flag*=-1;
					x-=a[j]+1;
				}
			if(x<0)
				continue;
			ans=(ans+flag*lucas(x+n-1,n-1))%mod;
			ans=(ans+mod)%mod;
		}
		System.out.println(ans);
	}
	static long lucas(long a,long b){
		if(b==0)
			return 1;
		return getc(a%mod,b%mod)*lucas(a/mod,b/mod)%mod;
	}
	static long getc(long a,long b){
		if(a<b)
			return 0;
		long ans=1;
		for(long i=a-b+1;i<=a;i++)
			ans=ans*i%mod;
		long t=1;
		for(long i=1;i<=b;i++)
			t=t*i%mod;
		return ans*qpow(t,mod-2)%mod;
	}
	static long qpow(long a,long b){
		long ans=1;
		while(b!=0){
			if((b&1)==1){
				ans=a*ans%mod;
			}
			a=a*a%mod;
			b>>=1;
		}
		return ans;
	}
}


package codeforces;

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

public class Task451E {

	private static final long MOD = 1000000007;

	private FastScanner in;
	private PrintWriter out;

	private long inverseNMinusOneFactorial;
	private long nMinusOne;

	public Task451E(InputStream in, OutputStream out) {
		this.in = new FastScanner(in);
		this.out = new PrintWriter(out);
	}

	public void solve() throws IOException {
		int n = nextInt();
		long s = nextLong();
		long f[] = new long[n];
		for (int i = 0; i < n; ++i) {
			f[i] = nextLong();
		}
		preCalc(n);
		long result = 0;
		mask:
		for (int mask = 0; mask < (1 << n); ++mask) {
			long restS = s;
			boolean subtract = false;
			for (int bit = 0; bit < n; ++bit) {
				if (((1 << bit) & mask) != 0) {
					restS -= f[bit] + 1;
					if (restS < 0) {
						continue mask;
					}
					subtract = !subtract;
				}
			}
			if (subtract) {
				result = (result + (MOD - c(restS))) % MOD;
			}
			else {
				result = (result + c(restS)) % MOD;
			}
		}
		out.println(result);
	}

	private void preCalc(int n) {
		long factorial = 1;
		for (int i = 1; i < n; ++i) {
			factorial = (factorial * i) % MOD;
		}
		nMinusOne = n - 1;
		inverseNMinusOneFactorial = powerMod(factorial, MOD - 2);
	}

	private long powerMod(long n, long power) {
		long result = 1;
		n = n % MOD;
		for (int bit = 1; bit <= power; bit <<= 1) {
			if ((power & bit) != 0) {
				result = (result * n) % MOD;
			}
			n = (n * n) % MOD;
		}
		return result;
	}

	public long c(long restS) {
		long result = 1;
		for (long i = restS + 1; i <= (restS + nMinusOne); ++i) {
			result = (result * (i % MOD)) % MOD;
		}
		return (result * inverseNMinusOneFactorial) % MOD;
	}

	public void run() {
		try {
			solve();
			out.close();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

	class FastScanner {
		BufferedReader br;
		StringTokenizer st;

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

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

	}

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

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

	public static void main(String[] arg) {
		new Task451E(System.in, System.out).run();
	}
}


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

public class deathStar{
    public static void main(String[] args){
        Scanner sc=new Scanner(System.in);
        int n=sc.nextInt();
        char[][] arr1=new char[n][n];
        char[][] arr2=new char[n][n];
        for(int i=0; i<n; i++){
            for(int j=0; j<n; j++){
                arr1[i][j]=sc.next().charAt(0);
            }
        }

        for(int i=0; i<n; i++){
            for(int j=0; j<n; j++){
                arr2[i][j]=sc.next().charAt(0);
            }
        }

        deathStar ds=new deathStar();

        boolean result=ds.isEqual(arr1,arr2,n);
        if(!result){
            int res=ds.check(arr1,arr2,n);
            if(res!=0){
                ds.flipV(arr1,n);
                result=ds.isEqual(arr1,arr2,n);
                if(!result) res=ds.check(arr1,arr2,n);
                else{
                    System.out.println("YES");
                    return;
                }
            }
            if(res!=0){
                ds.flipV(arr1,n);
                ds.flipH(arr1,n);
                result=ds.isEqual(arr1,arr2,n);
                if(!result) res=ds.check(arr1,arr2,n);
                else{
                    System.out.println("YES");
                    return;
                }
            }
            if(res!=0) System.out.println("NO");
        }
        else System.out.println("YES");
    }

    public void flipV(char[][] arr1,int n){
        for(char[] arr:arr1){
            int i=0;
            int j=n-1;
            while(i<j){
                char temp=arr[i];
                arr[i]=arr[j];
                arr[j]=temp;
                i++;
                j--;
            }
        }

    }
    public void flipH(char[][] arr1,int n){
        for(int j=0; j<n; j++){
            for(int i=0; i<n; i++){
                int temp=arr1[i][j];
                arr1[i][j]=arr1[n-1-i][j];
                arr1[n-1-i][j]=temp;
            }
        }
    }

    public void printArr(char[][] arr, int n){
        for(char[] pointer:arr){
            System.out.println();
            for(int i=0; i<n; i++){
                if(pointer[i]==' ' || pointer[i]=='\n') System.out.print('a'+" ");
                else System.out.print(pointer[i]+" ");
            }
        }
    }

    public int check(char[][] arr1,char[][] arr2, int n){
        int i=0;
        while(i<1){
            rotate(arr1,n);
            if(isEqual(arr1,arr2,n)){
                System.out.println("YES");
                return 0;
            }
            i++;
        }
        rotate(arr1,n);
        return -1;
    }

    public boolean isEqual(char[][] arr1,char[][] arr2, int n){
        for(int i=0; i<n; i++){
            for(int j=0; j<n; j++){
                if(arr1[i][j]!=arr2[i][j]){
                    return false;
                }
            }
        }
        return true;
    }

    public void rotate(char[][] arr, int n){
        for(int layer=0; layer<n/2; layer++){
            int first=layer;
            int last=n-1-layer;
            int offset=0;
            for(int j=first; j<last; j++){
                char top=arr[first][j];
                arr[first][j]=arr[last-offset][first];
                arr[last-offset][first]=arr[last][last-offset];
                arr[last][last-offset]=arr[j][last];
                arr[j][last]=top;
                offset++;
            }
        }
    }
}


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

public class deathStar{
    public static void main(String[] args){
        Scanner sc=new Scanner(System.in);
        int n=sc.nextInt();
        char[][] arr1=new char[n][n];
        char[][] arr2=new char[n][n];
        sc.nextLine();
        for(int i=0; i<n; i++){
            arr1[i]=sc.nextLine().toCharArray();
        }

        for(int i=0; i<n; i++){
            arr2[i]=sc.nextLine().toCharArray();
        }

        deathStar ds=new deathStar();
        boolean result=ds.isEqual(arr1,arr2,n);
        if(!result){
            int res=ds.check(arr1,arr2,n);
            if(res!=0){
                ds.flip(arr1,n,true);
                result=ds.isEqual(arr1,arr2,n);
                if(!result) res=ds.check(arr1,arr2,n);
                else{
                    System.out.println("YES");
                    return;
                }
            }
            if(res!=0){
                ds.flip(arr1,true);
                ds.flip(arr1,false);
                result=ds.isEqual(arr1,arr2,n);
                if(!result) res=ds.check(arr1,arr2,n);
                else{
                    System.out.println("YES");
                    return;
                }
            }
            if(res!=0) System.out.println("NO");
        }
        else System.out.println("YES");
    }

    public void flip(char[][] arr1,int n, boolean flipV){
        for(int j=0; j<n; j++){
            for(int i=0; i<n; i++){

                int a=(!flipV)?i:j;
                int b=(!flipV)?j:i;
                int c=(!flipV)?n-1-i:j;
                int d=(!flipV)?j:n-1-i;

                char temp=arr1[a][b];
                arr1[a][b]=arr1[c][d];
                arr1[c][d]=temp;
            }
        }
    }

    public int check(char[][] arr1,char[][] arr2, int n){
        int i=0;
        while(i<3){
            rotate(arr1,n);
            if(isEqual(arr1,arr2,n)){
                System.out.println("YES");
                return 0;
            }
            i++;
        }
        rotate(arr1,n);
        return -1;
    }

    public boolean isEqual(char[][] arr1,char[][] arr2, int n){
        for(int i=0; i<n; i++){
            for(int j=0; j<n; j++){
                if(arr1[i][j]!=arr2[i][j]){
                    return false;
                }
            }
        }
        return true;
    }

    public void rotate(char[][] arr, int n){
        for(int layer=0; layer<n/2; layer++){
            int first=layer;
            int last=n-1-layer;
            int offset=0;
            for(int j=first; j<last; j++){
                char top=arr[first][j];
                arr[first][j]=arr[last-offset][first];
                arr[last-offset][first]=arr[last][last-offset];
                arr[last][last-offset]=arr[j][last];
                arr[j][last]=top;
                offset++;
            }
        }
    }
}


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

/**
 * @author Don Li
 */
public class PuttingBoxesTogether {

    int N = (int) 2e5 + 10;
    int MOD = (int) 1e9 + 7;

    int n;
    long[] t1 = new long[N];
    long[] t2 = new long[N];

    void solve() {
        n = in.nextInt(); int Q = in.nextInt();
        int[] a = new int[n];
        for (int i = 0; i < n; i++) a[i] = in.nextInt();
        int[] w = new int[n];
        for (int i = 0; i < n; i++) w[i] = in.nextInt();

        for (int i = 0; i < n; i++) a[i] -= i;

        for (int i = 0; i < n; i++) {
            add(t1, i, w[i]);
            add(t2, i, (long) a[i] * w[i] % MOD);
        }

        while (Q-- > 0) {
            int x = in.nextInt();
            if (x < 0) {
                int i = -x - 1, nw = in.nextInt();
                long delta1 = nw - w[i];
                long delta2 = (a[i] * nw % MOD - a[i] * w[i] % MOD + MOD) % MOD;
                w[i] = nw;
                add(t1, i, delta1);
                add(t2, i, delta2);
            } else {
                int l = x - 1, r = in.nextInt();
                long tot = sum(t1, l, r);
                int lb = l, ub = r;
                while (ub - lb > 1) {
                    int m = (lb + ub) >> 1;
                    if (sum(t1, l, m) * 2 <= tot) lb = m;
                    else ub = m;
                }
                int k = lb;
                long ans = norm(mul(a[k], nsum(t1, l, k)) - nsum(t2, l, k));
                ans = norm(ans + norm(nsum(t2, k + 1, r) - mul(a[k], nsum(t1, k + 1, r))));
                out.println(ans);
            }
        }
    }

    long nsum(long[] t, int l, int r) {
        return norm(sum(t, r - 1) - sum(t, l - 1));
    }

    long sum(long[] t, int l, int r) {
        return sum(t, r - 1) - sum(t, l - 1);
    }

    long sum(long[] t, int i) {
        long res = 0;
        for (int x = i; x >= 0; x = (x & x + 1) - 1) res += t[x];
        return res;
    }

    void add(long[] t, int i, long delta) {
        for (int x = i; x < n; x = x | x + 1) t[x] += delta;
    }

    long mul(long a, long b) {
        return a * b % MOD;
    }

    long norm(long a) {
        a %= MOD;
        if (a > MOD) a -= MOD;
        if (a < 0) a += MOD;
        return a;
    }

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

    static FastScanner in;
    static PrintWriter out;

    static class FastScanner {
        BufferedReader in;
        StringTokenizer st;

        public FastScanner(BufferedReader in) {
            this.in = in;
        }

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

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

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

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


import java.util.*;
public class C147 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        boolean nt[] = new boolean[1000006];
        nt[1] = true;
        int j;
        for(int i=2;i<=1000000;i++){
            if(!nt[i]){
                j=2;
                while((i*j)<=1000000){
                    nt[i*j] = true;
                    j++;
                }
            }
        }
        int a, b, k;
        a = sc.nextInt();
        b = sc.nextInt();
        k = sc.nextInt();


import java.io.InputStreamReader;
import java.io.PrintStream;
import java.util.*;

public class CF214C {
    private Readable in;
    private PrintStream out;
    public CF214C(Readable in, PrintStream out){this.in=in;this.out=out;}

    private ArrayList<Step> steps = new ArrayList<>();
    private Map<Integer, TreeSet<Integer>> available = new HashMap<>();
    private int computer;
    private int[][] moveCost = new int[][] { { 0, 1, 2 },
                                                     { 2, 0, 1 },
                                                     { 1, 2, 0 } };
    public void runner() {
        Scanner scanner = new Scanner(in);
        int parts = scanner.nextInt(); scanner.nextLine();
        String computers = scanner.nextLine();
        Arrays.stream(computers.split(" "))
            .mapToInt(Integer::parseInt)
            .forEach(comp -> {
                steps.add(new Step(steps.size(), comp));
            });
        for (int i = 0; i < parts; i++) {
            int[] line = Arrays.stream(scanner.nextLine().split(" "))
                            .mapToInt(Integer::parseInt)
                            .toArray();
            for (int j = 1; j <= line[0]; j++) {
                getStep(i).addDependency(line[j]-1);
            }
            if (getStep(i).isAvailable()) {
                addAvailable(getStep(i));
            }
        }
        int bestSteps = Integer.MAX_VALUE;
        for (Integer startFrom : available.keySet()) {
            computer = startFrom;
            bestSteps = Math.min(bestSteps, stepsToWin());
        }
        out.println(bestSteps);
    }
    private Step getStep(int id) {
        return steps.get(id);
    }
    private void addAvailable(Step step) {
        if (!available.containsKey(step.computer))
            available.put(step.computer, new TreeSet<>());
        available.get(step.computer).add(step.id);
    }
    int moveCost(int a, int b) {
        return moveCost[a-1][b-1];
    }
    public int stepsToWin() {
        int stepCount = 0;
        while (!available.isEmpty()) {
            int nextComputer = available.keySet().stream()
                .min((x, y) -> new Integer(moveCost(computer,x))
                        .compareTo(new Integer(moveCost(computer,y)))
                ).get();
            stepCount += moveCost(computer, nextComputer);
            computer = nextComputer;

            Step perform = getStep(available.get(computer).pollFirst());
            steps.set(perform.id, null);
            if (available.get(computer).isEmpty()) {
                available.remove(computer);
            }

            for (Step step : steps) {
                if (step == null) continue;
                if (step.hasDependency(perform.id))
                    step.removeDependency(perform.id);
                if (step.isAvailable())
                    addAvailable(step);
            }
            stepCount++;
        }
        return stepCount;
    }

    private class Step {
        private Set<Integer> dependencies = new HashSet<>();
        public int id, computer;
        public Step(int id, int c) { this.id = id; this.computer = c; }
        public void addDependency(int i) {
            dependencies.add(i);
        }
        public boolean hasDependency(Integer i) {
            return dependencies.contains(i);
        }
        public void removeDependency(Integer i) {
            dependencies.remove(i);
        }
        public boolean isAvailable() {
            return dependencies.isEmpty();
        }
        @Override public String toString() {
            return String.format("s%d (c%d): %s", id, computer, dependencies);
        }
    }

    public static void main(String... args) {
        new CF214C(new InputStreamReader(System.in), System.out).runner();
    }
}


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

public class Main {
    static final long MOD = 1000000007L;
    static int n;
    static int search(int pos, int[][] map, boolean[][] depend, boolean[] finished, int count) {
        int res = 0;
        for (int i = 0; i < map[pos].length; i++) {
            int val = map[pos][i];
            if (finished[val]) {
                continue;
            }
            boolean check = true;
            for (int j = 0; j < n; j++) {
                if (depend[val][j] && !finished[j]) {
                    check = false;
                    break;
                }
            }
            if (check) {
                finished[val] = true;
                count++;
                res++;
            }
        }
        if (count == n) {
            return res;
        }
        else {
            return res + 1 + search((pos + 1) % 3, map, depend, finished, count);
        }
    }

    public static void main(String[] args) throws Exception {
        Scanner scan = new Scanner(System.in);
        n = scan.nextInt();
        int[] require = new int[n];
        int[] count = new int[3];
        for (int i = 0; i < n; i++) {
            require[i] = scan.nextInt() - 1;
            count[require[i]]++;
        }
        final boolean[][] depend = new boolean[n][n];
        for (int i = 0; i < n; i++) {
            int k = scan.nextInt();
            for (int j = 0; j < k; j++) {
                depend[i][scan.nextInt() - 1] = true;
            }
        }
        int[][] map = new int[3][];
        for (int i = 0; i < 3; i++) {
            map[i] = new int[count[i]];
            for (int j = 0, k = 0; j < n; j++) {
                if (require[j] == i) {
                    map[i][k++] = j;
                }
            }
        }
        for (int i = 0; i < 3; i++) {
            int[] temp = new int[map[i].length];
            HashSet<Integer> checker = new HashSet<Integer>();
            for (int j = 0; j < temp.length; j++) {
                int res = -1;
                for (int k = 0; k < n; k++) {
                    if (require[k] != i || checker.contains(k)) {
                        continue;
                    }
                    if (res == -1 || depend[res][k]) {
                        res = k;
                    }
                }
                temp[j] = res;
                checker.add(res);
            }
            for (int j = 0; j < temp.length; j++) {
                map[i][j] = temp[j];
            }
            for (int j = 0; j < temp.length; j++) {
                for (int k = j + 1; k < temp.length; k++) {
                    if (depend[temp[j]][temp[k]]) {
                        throw new Exception();
                    }
                }
            }
        }

        int result = Integer.MAX_VALUE;
        for (int i = 0; i < 3; i++) {
            result = Math.min(result, search(i, map, depend, new boolean[n], 0));
        }
        System.out.println(result);
    }
}


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

public class C118 {
        public static void main(String[] args) {
                InputStream inputStream = System.in;
                OutputStream outputStream = System.out;
                InputReader in = new InputReader(inputStream);
                PrintWriter out = new PrintWriter(outputStream);
                CodeC118 solver = new CodeC118();
                solver.solve(1, in, out);
                out.close();
        }
}

class CodeC118
{
public void solve(int testNumber, InputReader in, PrintWriter out)
{
	long mod=1000000007;
	long n=in.nextLong();
	long ans = (pow(2*n-1)%mod+pow(n-1)%mod)%mod;
	out.println(ans);
}
public long pow(long p)
{
	long mod=1000000007;
	long ret=2;
	long i=1;
	if(p==0)
	{
		return 1;
	}
	if(p==1)
	{
		return 2;
	}
	for(i=1;(2*i)<=p;i*=2)
	{
		ret=(ret*ret)%mod;
	}
	//System.out.println(ret+" "+i);
	if(i/2!=p)
	{
		ret=(ret*pow(p-i))%mod;
	}
	// System.out.println("Final: "+ret);
	return ret;
}

}

class InputReader {
    private BufferedReader reader;
    private StringTokenizer tokenizer;

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

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

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

    public long nextLong() {
        return Long.parseLong(next());
    }
	public void inputShuffleArrayInt(int arr[])
	{
		int l=arr.length;
		for(int i=0;i<l;i++)
		{
			if(i%2==0)
			{
				arr[i/2]=nextInt();
			}
			else
			{
				arr[l-((i+1)/2)]=nextInt();
			}
		}
	}

    }


import java.util.*;
public class Main{
public static void main(String[] args)
{
Scanner in=new Scanner(System.in);
int n=in.nextInt();
for(int i=0;i<n;i++)
{
for(int j=0;j<n;j++)
{
if(i==0||j==0)
{
a[i][j]=1;
}
else
{
a[i][j]=a[i-1][j]+a[i][j-1];
}
}
}
System.out.println(a[n-1][n-1]);
}
}


import java.util.Scanner;
public class Solution {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        long res = 1;
        long fact = 1;
        for (int i=0; i < n; i++) {
            res *= 2*n-i;
            fact *= (i+1)
        }
        System.out.println(res/fact);
    }
}


public class SolutionB {

      public static void main(String args[])throws IOException{
              Scanner sc = new Scanner(System.in);
              int a = sc.nextInt();
              int b = sc.nextInt();
              int mask = 0;
              a++;
              while(mask != b){
                     int m = 1;
                     int d = a;
                     mask = 0;
                     while(d > 0){
                            int dig = d % 10;
                            d /= 10;
                            if((dig == 4) || (dig == 7)){
                                   mask = m * dig + mask;
                                   m *= 10;
                            }
                     }
                    // System.out.println(mask);
                     if(mask == b)break;
                     a++;
              }
              System.out.println(a);
      }
}


import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Scanner;

public class CF_146B_LuckyMask {
	static int luckyDivision(int num){
		int resultt = 0 ;
		int mult = 1;
		while(num>0){
		if(num%10==7||num%10==4){result+=num%10*mult;mult*=10; }
		num=num/10;
		}
	return resultt ;
	}
public static void main(String[]args)throws Exception{
Scanner sc = new Scanner(System.in);
int a  = sc.nextInt();
int b = sc.nextInt();
if(b>a){
	System.out.println(b);
	return;
}

int result = a+1;
while( luckyDivision(result)!=b){
	result++;
}
System.out.println(result);
}
}


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

public class CF {
	static int cmp;
	public static void main(String[] args) {
		FasterScanner sc = new FasterScanner();
		PrintWriter out = new PrintWriter(System.out);
		int N = sc.nextInt();
		int K = sc.nextInt()-1;
		PriorityQueue<Person> TIE = new PriorityQueue<Person>();
		PriorityQueue<Person> OTHER = new PriorityQueue<Person>();
		Person[] ppl = new Person[N];
		for(int a=0;a<N;a++){
			ppl[a]=new Person(sc.nextInt(),sc.nextInt());
		}
		cmp = 0;
		Arrays.sort(ppl);
		int safe = -1;
		int i = K;
		int goal = ppl[K].P;
		while(ppl[i].P==goal){
			safe++;
			if(i==0)break;
			i--;
		}
		if(ppl[K].P>N){
			out.println("-1");
			out.close();
			return;
		}
//		System.out.println(safe+" "+K);
		cmp = 1;
		PriorityQueue<Person> LAZY = new PriorityQueue<Person>();
		for(int a=0;a<N;a++){
			LAZY.add(ppl[a]);
			if(ppl[a].P==goal||ppl[a].P==goal-1)
				TIE.add(ppl[a]);
			else OTHER.add(ppl[a]);
		}
		long used = 0;
		long eff2 = 0;
		for(int a=0;a<=goal;a++){
			eff2+=LAZY.poll().E;
		}

		while(TIE.size()>safe){
			used+=TIE.poll().E;
			goal--;
//			System.out.println("H");
//			if(goal<=0)break;
		}
		OTHER.addAll(TIE);
		while(goal>0){
			K++;
			used+=OTHER.poll().E;
		}

		out.println(Math.min(used,eff2));

		out.close();
	}

	static class Person implements Comparable<Person>{
		int P,E;
		Person(int p, int e){
			P=p;
			E=e;
		}
		@Override
		public int compareTo(Person o) {
			if(cmp==0)return o.P-this.P;
			return this.E-o.E;
		}
	}

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

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

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

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

	}

}


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

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

class Knights {
    final int[] dx = { -2, -2, -1, 1, 2, 2, 1, -1 };
    final int[] dy = { -1, 1, 2, 2, 1, -1, -2, -2 };
    public void solve(int testNumber, PandaScanner in, PrintWriter out) {
        int n = in.nextInt();
        int ways[][] = new int[n][n];
        int dist[][] = new int[n][n];
        for (int i = 0; i < n; i++) {
            Arrays.fill(dist[i], Integer.MAX_VALUE);
        }
        dist[0][0] = 0;
        ways[0][0] = 1;
        ArrayDeque<Integer> q = new ArrayDeque<>();
        q.add(0);
        while (!q.isEmpty()) {
            int u = q.poll();
            int x = u / n;
            int y = u % n;
            for (int d = 0; d < dx.length; d++) {
                int nx = x + dx[d];
                int ny = y + dy[d];
                if (Math.min(nx, ny) >= 0 && Math.max(nx, ny) < n && dist[nx][ny] > dist[x][y]) {
                    ways[nx][ny] += ways[x][y];
                    if (dist[nx][ny] > dist[x][y] + 1) {
                        dist[nx][ny] = dist[x][y] + 1;
                        q.add(nx * n + ny);
                    }
                }
            }
        }
        out.println(ways[n - 1][n - 1]);
    }
}

class PandaScanner {
    public BufferedReader br;
    public StringTokenizer st;
    public InputStream in;

    public PandaScanner(InputStream in) {
        br = new BufferedReader(new InputStreamReader(this.in = in));
    }

    public String nextLine() {
        try {
            return br.readLine();
        }
        catch (Exception e) {
            return null;
        }
    }

    public String next() {
        if (st == null || !st.hasMoreTokens()) {
            st = new StringTokenizer(nextLine().trim());
            return next();
        }
        return st.nextToken();
    }

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

    }


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

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

class TaskE {

    private int vertexCounter, edgeCounter, value;
    private int[] path;
    private long[] initial, desired;
    private List<Integer>[] graph;
    private DSU dsu;
    private List<Integer> more, less;
    private boolean[] ready;
    private List<Transfusion> answer;

    public void solve(int testNumber, InputReader in, PrintWriter out) {

        vertexCounter = in.nextInt();
        value = in.nextInt();
        edgeCounter = in.nextInt();

        initial = new long[vertexCounter];
        desired = new long[vertexCounter];
        ready = new boolean[vertexCounter];
        more = new ArrayList<Integer>();
        less = new ArrayList<Integer>();
        answer = new ArrayList<Transfusion>();
        graph = new ArrayList[vertexCounter];
        for (int i = 0; i < vertexCounter; ++i)
            graph[i] = new ArrayList<Integer>();

        for (int i = 0; i < vertexCounter; ++i)
            initial[i] = in.nextInt();
        for (int i = 0; i < vertexCounter; ++i)
            desired[i] = in.nextInt();

        dsu = new DSU(vertexCounter, initial, desired);

        int v, u;
        for (int i = 0; i < edgeCounter; ++i) {
            v = in.nextInt() - 1;
            u = in.nextInt() - 1;
            graph[u].add(v);
            graph[v].add(u);
            dsu.union(v, u);
        }

        if (!dsu.check()) {
            out.println("NO");
            return;
        }

        for (int i = 0; i < vertexCounter; ++i)
            if (initial[i] == desired[i])
                ready[i] = true;
            else if (initial[i] > desired[i])
                more.add(i);
            else
                less.add(i);

        Comparator<Integer> cmp = new Comparator<Integer>() {
            @Override
            public int compare(Integer o1, Integer o2) {
                return Integer.compare(dsu.getSet(o1), dsu.getSet(o2));
            }
        };
        Collections.sort(more, cmp);
        Collections.sort(less, cmp);

        int current = 0;
        for (int i = 0; i < more.size(); ++i)
            if (initial[more.get(i)] - desired[more.get(i)] > desired[less.get(current)] - initial[less.get(current)]) {
                transfusion(more.get(i), less.get(current), (int) (desired[less.get(current)] - initial[less.get(current)]));
                ready[less.get(current)] = true;
                current++;
                i--;
            } else {
                transfusion(more.get(i), less.get(current), (int) (initial[more.get(i)] - desired[more.get(i)]));
                ready[more.get(i)] = true;
            }

        out.println(answer.size());
        for (Transfusion transfusion : answer)
            transfusion.println(out);
    }

    private void transfusion(int from, int to, int delta) {
        path = new int[vertexCounter];
        Arrays.fill(path, -1);
        bfs(to, from);
        flow(from, to, delta);
    }

    private void flow(int from, int to, int delta) {
        if (from == to)
            return;
        if (initial[path[from]] + delta <= value) {

            answer.add(new Transfusion(from, path[from], delta));
                initial[from] -= delta;
                initial[path[from]] += delta;

            flow(path[from], to, delta);
        } else if (path[from] >= delta) {
            flow(path[from], to, delta);

            answer.add(new Transfusion(from, path[from], delta));
                initial[from] -= delta;
                initial[path[from]] += delta;
        } else {
            int difference = (int) (delta - initial[path[from]]);

            answer.add(new Transfusion(from, path[from], difference));
                initial[from] -= difference;
                initial[path[from]] += difference;

            flow(path[from], to, delta);

            answer.add(new Transfusion(from, path[from], delta - difference));
                initial[from] -= delta - difference;
                initial[path[from]] += delta - difference;
        }
    }

    private void bfs(int start, int finish) {
        int[] queue = new int[vertexCounter];
        int size = 0;
        int next = 0;
        queue[size++] = start;
        while (size > 0) {
            int v = queue[next++];
            for (int u : graph[v])
                if (path[u] == -1) {
                    path[u] = v;
                    if (u == finish)
                        return;
                    queue[size++] = u;
                }
        }
    }

}

class DSU {

    public int[] parent, rank;
    private long[] initial, desired;

    public DSU (int size, long[] initial, long[] desired) {
        parent = new int[size];
        rank = new int[size];
        this.initial = Arrays.copyOf(initial, initial.length);
        this.desired = Arrays.copyOf(desired, desired.length);
        for (int i = 0; i < size; ++i)
            parent[i] = i;
        for (int i = 0; i < size; ++i) {
            this.initial[getSet(i)] += initial[i];
            this.desired[getSet(i)] += desired[i];
        }
    }

    public int getSet(int v) {
        if (parent[v] == v)
            return v;
        return parent[v] = getSet(parent[v]);
    }

    public void union(int v, int u) {
        int a = getSet(v);
        int b = getSet(u);
        if (a != b) {
            if (rank[a] < rank[b]) {
                a ^= b;
                b ^= a;
                a ^= b;
            }
            parent[b] = a;
            if (rank[a] == rank[b])
                ++rank[a];
        }
    }

    public boolean check() {
        for (int v = 0; v < initial.length; ++v) {
            int p = getSet(v);
            if (p != v) {
                initial[p] += initial[v];
                desired[p] += desired[v];
                initial[v] = 0;
                desired[v] = 0;
            }
        }
        for (int i = 0; i < initial.length; ++i)
            if (initial[i] != desired[i])
                return false;
        return true;
    }

}

class Transfusion {

    public int from, to, value;

    public Transfusion(int x, int y, int v) {
        from = x;
        to = y;
        value = v;
    }

    public void println(PrintWriter out) {
        out.print(from + 1);
        out.print(" ");
        out.print(to + 1);
        out.print(" ");
        out.println(value);
    }

}

class InputReader {

    private static BufferedReader bufferedReader;
    private static StringTokenizer stringTokenizer;

    public InputReader(InputStream inputStream) {
        bufferedReader = new BufferedReader(new InputStreamReader(inputStream));
        stringTokenizer = null;
    }

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

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

    }


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

public class test2
{

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

	PrintWriter out = null;
	int[] dp = null;

	int play(int n)
	{
		if (n == 1)
			return 1;

		if (dp[n] > 0)
			return dp[n];

		int max = 0;
		for (int i = 2; i <= n; i++)
		{
			if (n % i == 0)
				max = Math.max(max, play(n / i));
		}

		dp[n] = n + max;
		return dp[n];
	}

	void run() throws Exception
	{
		Scanner in = new Scanner(System.in);
		out = new PrintWriter(System.out);

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

		out.println(play(n));
		out.close();
	}
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Scanner;
import java.util.StringTokenizer;

public class puzzles {
	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;
		}
	}

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

		Arrays.sort(p);
		int dp[] = new int[m-1];
		for(int i=1;i<m;i++)
			dp[i-1] = p[i]-p[i-1];
		HashSet<Integer> mm = new HashSet<>();
		int count=0;
		boolean arr[]=new boolean[m-1];
			while(count!=n) {
				int min=0;int mini=Integer.MAX_VALUE;
				for(int i=0;i<dp.length;i++) {
					if(arr[i]==false && dp[i]<mini) {
					mini=dp[i];
					min=i;
					}
				}

						if(min>=1 && arr[min-1]==true)
						{
							mm.add(p[min+1]);
							count++;}
						else if(min>=1 && arr[min-1]==false) {
							mm.add(p[min+1]);
							mm.add(p[min]);
							count+=2;}
						else {
							mm.add(p[min+1]);
							mm.add(p[min]);
							count+=2;
						}
						arr[min]=true;
					}
			int max=Integer.MIN_VALUE;int mi=Integer.MAX_VALUE;
			for(int i : mm) {
				if(i<mi)
					mi=i;
				if(i>max)
					max=i;
			}

		System.out.println(max-mi);

	}

}


import java.util.*;
public class ConvertToOnes
{
	public static void main(String[] args)
	{
	    Scanner sc = new Scanner(system.in);
	    int min = 33;
	    int third = 0;
	    int len = sc.nextInt();
	    for (int i = 0; i < len; i++)
	    {
	        int now = sc.nextInt();
	        if (i == 2)
	            third = now;
	        if (now < min)
	            min = now;
	    }
	    int res = third ^ min + 2;
	    System.out.println(res);

	}
}


import java.util.Scanner;

public class Test{
    public static void main(String[] args){
        Scanner scan=new Scanner(System.in);
        int nb=scan.nextInt();
        int[] T=new int[nb];
        for(int i=0;i<nb;i++)T[i]=scan.nextInt();
        System.out.println((Math.min(T)^T[2])+2);
    }
}


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

public class Candies {

    private void solve() {
        int n = readInt();
        int m = readInt();
        long res = 0;
        long[] mV = new long[m];
        if(m == 1){
            long x = n;
            out.print(x*x);
            return;
        }
        for(long i = 0;i<n;i++){
            long x = (i + 1) * (i + 1);
            mV[x < m ? (int) x : (int) x % m]++;
        }
        res += mV[0]*mV[0];
        int left = 1;
        int right = m - 1;
        while(left < right){
            res += mV[left] * mV[right] * 2;
            right--;
            left++;
        }
        if(left == right){
            res += mV[left]*mV[left];
        }
        out.print(res);
    }

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

    private void run() {
        try {
            init();
            solve();
            out.close();
        } catch (Exception e) {
            e.printStackTrace();
            System.exit(-1);
        }
    }

    private BufferedReader in;
    private StringTokenizer tok = new StringTokenizer("");

    private PrintWriter out;

    private void init() {
        in = new BufferedReader(new InputStreamReader(System.in));
        out = new PrintWriter(System.out);
    }

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

    private String readString() {
        while (!tok.hasMoreTokens()) {
            String nextLine = readLine();
            if (nextLine == null) return null;
            tok = new StringTokenizer(nextLine);
        }

        return tok.nextToken();
    }

    private int readInt() {
        return Integer.parseInt(readString());
    }

    private long readLong() {
        return Long.parseLong(readString());
    }
}


import jdk.internal.util.xml.impl.Input;

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

public class Main {

    public static void main(String[] args) {
        InputReader in = new InputReader(System.in);
        OutputWriter out = new OutputWriter(System.out);
        int n = in.nextInt();
        int m = in.nextInt();
        long ans=0;
        for (int i =1;i<=Math.min(n,m);i++)
            for (int j =1;j<=Math.min(n,m);j++)
            {
                if ((i*i+j*j)%m==0)
                {
                    ans+=(long)((long)((n-i)/m+1)*((long)(n-j)/m+1));
                }
            }

            out.printLine(ans);
        out.flush();

    }
    static int binarySearch(int []arr,int n,int p)
    {

        int st = 0;
        int end = n-1;
        int mid = (st + end)/2;
        int temp = 0;
        while(st <= end)
        {
            mid = (st + end)/2;

            if(p >= arr[mid])
            {
                st = mid+1;

            }
            else if(p < arr[mid])
            {
                end = mid-1;

            }
            temp = st;

        }

        return temp;
    }
    static void MergeSort(int[] a, int[] b,  int p, int r)
    {
        if (p < r)
        {
            int q = (r + p) / 2;
            MergeSort(a, b,  p, q);
            MergeSort(a, b,  q + 1, r);
            Merge(a, b, p, q, r);
        }
    }
    static void Merge(int[] a, int[] b,int p, int q, int r)
    {
        int n1 = q - p + 1;
        int n2 = r - q;
        int[] R = new int[n1 + 1];
        int[] L = new int[n2 + 1];
        int[] R1 = new int[n1];
        int[] L1 = new int[n2];

        for (int i = 0; i < n1; i++)
        {
            R[i] = a[p + i];
            R1[i] = b[p + i];

        }
        R[n1] = Integer.MAX_VALUE;
        for (int i = 0; i < n2; i++)
        {
            L[i] = a[q + i + 1];
            L1[i] = b[q + i + 1];

        }
        L[n2] =Integer.MAX_VALUE;
        int n = a.length;
        int j = 0;
        int k = 0;
        for (int i = p; i <= r; i++)
        {
            if (L[j] < R[k])
            {
                a[i] = L[j];
                b[i] = L1[j];

                j++;
            }
            else if (L[j]>R[k])
            {
                a[i] = R[k];
                b[i] = R1[k];

                k++;
            }
            else
            {
                if (L1[j] < R1[k])
                {
                    a[i] = L[j];
                    b[i] = L1[j];

                    j++;
                }
                else
                {
                    a[i] = R[k];
                    b[i] = R1[k];

                    k++;
                }
            }

        }
    }
}

class pair  implements Comparable
{

    int key;
    int value;
    public pair(Object key, Object value) {

        this.key = (int)key;
        this.value=(int)value;
    }

    @Override
    public int compareTo(Object o) {
        pair temp =(pair)o;
        return  key-temp.key;
    }
}
class Graph {

    int n;
    ArrayList<Integer>[] adjList;

    public Graph(int n) {
        this.n = n;
        adjList = new ArrayList[n];
        for (int i = 0; i < n; i++)
            adjList[i] = new ArrayList<>();
    }

}

class InputReader {

    private final InputStream stream;
    private final byte[] buf = new byte[8192];
    private int curChar, snumChars;

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

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

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

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

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

    public 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 nextLine() {
        int c = read();
        while (isSpaceChar(c))
            c = read();
        StringBuilder res = new StringBuilder();
        do {
            res.appendCodePoint(c);
            c = read();
        } while (!isEndOfLine(c));
        return res.toString();
    }

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

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

}

class OutputWriter {
    private final PrintWriter writer;

    public OutputWriter(OutputStream outputStream) {
        writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(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();
    }

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

}


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

/**
 * @auther chao
 * @date 16/1/31
 */

public class CF4 {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        PrintWriter pw = new PrintWriter(new OutputStreamWriter(System.out));

        Scanner in = new Scanner(System.in);
        double x = in.nextDouble();
        double y = in.nextDouble();
        double z = in.nextDouble();
        EXP[] exps = new EXP[9];
        exps[0] = new EXP(x, y,   z, "x^y^z", 0);
        exps[1] = new EXP(x, z,   y, "x^z^y", 1);
        exps[2] = new EXP(x, y*z, 1, "(x^y)^z", 2);
        exps[3] = new EXP(y, x,   z, "y^x^z", 3);
        exps[4] = new EXP(y, z,   x, "y^z^x", 4);
        exps[5] = new EXP(y, x*z, 1, "(y^x)^z", 5);
        exps[6] = new EXP(z, x,   y, "z^x^y", 6);
        exps[7] = new EXP(z, y,   x, "z^y^x", 7);
        exps[8] = new EXP(z, x*y, 1, "(z^x)^y", 8);
        /*
        int p = 0;
        for (int i = 1; i < 9; i++) {
            if (exps[i].compareTo(exps[p]) > 0) p =i;
        }*/
        Arrays.sort(exps);
        System.out.println(exps[p].exp);

    }
}
class EXP implements Comparable<EXP>{
    double x;
    double y;
    double z;
    int p;
    String exp;
    public EXP(double x, double y, double z, String exp, int p) {
        this.x = x;
        this.y = y;
        this.z = z;
        this.exp = exp;
        this.p = p;
    }
    public int compareTo(EXP exp) {
        double lnx1 = Math.log(x);
        double lnx2 = Math.log(exp.x);
        double cmp;
        int op = 1;
        if (lnx1 * lnx2 > 0) {
            if (lnx1 < 0) {
                op = -1;
                lnx1 = -lnx1;
                lnx2 = -lnx2;
            }
            cmp = (z*Math.log(y)+Math.log(lnx1))-(exp.z*Math.log(exp.y)+Math.log(lnx2));
        } else {
            cmp = lnx1 - lnx2;
        }
        if (op < 0) cmp = -cmp;
        if (cmp == 0) return exp.p - p;
        return cmp > 0 ? 1 : -1;

    }
}


import java.util.Scanner;
public class Ishu
{
	public static void main(String[] args)
	{
	Scanner scan=new Scanner(System.in);
	int i,link=0,pearl=0;
	String str;
	str=scan.next();
	for(i=0;i<str.length();++i)
		{
		if(str.substring(i,i+1).equals("-"))
			++link;
		else
			++pearl;
		}
	if(link%pearl==0)
		System.out.println("YES");
	else
		System.out.println("NO");
	}
}


import java.io.*;

import java.util.*;

public class CodeForces {

	public void solve() throws IOException {
		int n = nextInt();
		long sum = n;
		boolean arr[] = new boolean[n + 1];
		Arrays.fill(arr, true);
		int a = 2;
		List<Integer> ls = new ArrayList<Integer>();
		double sq = Math.sqrt(n);
		while (a <= sq) {
			if (arr[a]) {
				int t = 2 * a;
				while (t <= sq) {
					arr[t] = false;
					t += a;
				}
				ls.add(a);
			}
			a++;
		}
		int l = ls.size();
		while (n > 1) {
			int i = 0;
			while (i<l && n % ls.get(i) != 0) {
				i++;
			}
			if(i==l) {
				n = 1;
			} else {
				n = n / ls.get(i);
			}
			sum += n;
		}
		out.println(sum);

	}

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

	int NOD(int a, int b) {
		while (a != 0 && b != 0) {
			if (a >= b)
				a = a % b;
			else
				b = b % a;
		}
		return a + b;
	}

	BufferedReader reader;
	StringTokenizer tokenizer;
	PrintWriter out;
	boolean isOuterFile = false;

	public void run() {
		try {
			if (isOuterFile) {
				reader = new BufferedReader(new FileReader("input.txt"));
				out = new PrintWriter(new BufferedWriter(new FileWriter(
						"output.txt")));
			} else {
				reader = new BufferedReader(new InputStreamReader(System.in));
				out = new PrintWriter(System.out);
			}

			tokenizer = null;
			//long time = new Date().getTime();
			solve();
			//out.println(time - new Date().getTime());
			reader.close();
			out.close();
		} catch (Exception e) {
			e.printStackTrace();
			System.exit(1);
		}
	}

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

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

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

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


import java.io.DataInputStream;
import java.io.IOException;
import java.util.Arrays;

public class Main {
	public static void main(String[] args){
		StdIn scan = new StdIn();
		char[] c = scan.next().toCharArray();
		int[] A = new int[3], B = new int[3];
		A[0] = c[0] - '0';
		A[1] = c[1] - '0';
		A[2] = c[2] - '0';
		B[0] = c[3] - '0';
		B[1] = c[4] - '0';
		B[2] = c[5] - '0';
		Arrays.sort(A);
		Arrays.sort(B);
		int a = A[0] + A[1] + A[2];
		int b = B[0] + B[1] + B[2];
		int count = 0;
		if(a < b) count = solve(A, B, b - a);
		else if(a > b) count = solve(B, A, a - b);
		System.out.println(count);
	}

	static int solve(int[] a, int[] b, int diff){
		boolean changeA = true;
		int change = 9 - a[0];
		if(diff < b[0]){
			diff = b[0];
			changeA = false;
		}
		if(change >= diff) return 1;
		diff -= change;
		if(changeA) a[0] = 9;
		else b[0] = 0;
		Arrays.sort(a);
		Arrays.sort(b);
		return 1 + solve(a, b, diff);
	}

	// Custom Scanner

	interface Input {
		public String next();
		public String nextLine();
		public int nextInt();
		public long nextLong();
		public double nextDouble();
	}
	static class StdIn implements Input {
		final private int BUFFER_SIZE = 1 << 16;
		private DataInputStream din;
		private byte[] buffer;
		private int bufferPointer, bytesRead;
		public StdIn() {
			din = new DataInputStream(System.in);
			buffer = new byte[BUFFER_SIZE];
			bufferPointer = bytesRead = 0;
		}
		private void fillBuffer() throws IOException {
			bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE);
			if (bytesRead == -1)
				buffer[0] = -1;
		}
		private byte read() {
			try {
				if (bufferPointer == bytesRead)
					fillBuffer();
				return buffer[bufferPointer++];
			} catch (IOException e) {
				throw new RuntimeException();
			}
		}
		public String next() {
			int c;
			while ((c = read()) != -1 && (c == ' ' || c == '\n' || c == '\r'))
				;
			StringBuilder s = new StringBuilder();
			while (c != -1) {
				if (c == ' ' || c == '\n' || c == '\r')
					break;
				s.append((char) c);
				c = read();
			}
			return s.toString();
		}
		public String nextLine() {
			int c;
			while ((c = read()) != -1 && (c == ' ' || c == '\n' || c == '\r'))
				;
			StringBuilder s = new StringBuilder();
			while (c != -1) {
				if (c == '\n' || c == '\r')
					break;
				s.append((char) c);
				c = read();
			}
			return s.toString();
		}
		public int nextInt() {
			int ret = 0;
			byte c = read();
			while (c <= ' ')
				c = read();
			boolean neg = (c == '-');
			if (neg)
				c = read();
			do {
				ret = ret * 10 + c - '0';
			} while ((c = read()) >= '0' && c <= '9');

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

			if (c == '.') {
				while ((c = read()) >= '0' && c <= '9') {
					ret += (c - '0') / (div *= 10);
				}
			}
			if (neg)
				return -ret;
			return ret;
		}
		public void close() throws IOException {
			if (din == null)
				return;
			din.close();
		}
	}
}