import java.beans.IntrospectionException;
import java.util.ArrayList;
import java.util.Scanner;

public class C239 {

	public class solution {
		int x1;
		int y1;
		int x2;
		int y2;
		int x3;
		int y3;

		public solution() {
			x1 = x2 = y1 = y2 = x3 = y3 = 0;
		}

	}

	static boolean perfect(int num) {

		double s = Math.sqrt(num);
		int ss = (int) s;
		if (ss * ss == num)
			return true;
		else
			return false;

	}

	public void run() {
		Scanner in = new Scanner(System.in);
		int a = in.nextInt();
		int b = in.nextInt();

		ArrayList<Integer> x = new ArrayList<Integer>();
		ArrayList<Integer> y = new ArrayList<Integer>();

		for (int xx = 0 - a-a; xx <= a+a; xx++) {

			int inter = a * a - xx * xx;

			if (!perfect(inter) || xx == 0)
				continue;

			int sq = (int) Math.sqrt(inter);

			int y1 = sq;
			int y2 = -sq;

			if (y1 != 0) {
				x.add(xx);
				y.add(y1);
			}

			if (y2 != 0) {
				x.add(xx);
				y.add(y2);
			}

		}

		ArrayList<solution> all = new ArrayList<solution>();
		for (int i = 0; i < x.size(); i++) {
			int xnow = x.get(i);
			int ynow = y.get(i);

			for (int xx = xnow - b-b; xx <= xnow + b+b; xx++) {

				int inter = b * b - (xnow - xx) * (xnow - xx);

				if (!perfect(inter))
					continue;

				int sq = (int) Math.sqrt(inter);

				int yy1 = ynow - sq;

				if ((yy1 - ynow) * ynow == -xnow * (xx - xnow) && yy1 != 0) {
					solution newsol = new solution();
					newsol.x1 = 0;
					newsol.y1 = 0;
					newsol.x2 = xnow;
					newsol.y2 = ynow;
					newsol.x3 = xx;
					newsol.y3 = yy1;

					all.add(newsol);

				}
				int yy2 = sq + ynow;
				if ((yy2 - ynow) * ynow == -xnow * (xx - xnow) && yy2 !=0) {
					solution newsol = new solution();
					newsol.x1 = 0;
					newsol.y1 = 0;
					newsol.x2 = xnow;
					newsol.y2 = ynow;
					newsol.x3 = xx;
					newsol.y3 = yy2;

					all.add(newsol);

				}

			}

		}

		if (all.size() == 0)
			System.out.println("NO");
		else {

			System.out.println("YES");
			solution here = all.get(0);
			System.out.println(here.x1 + " " + here.y1);
			System.out.println(here.x2 + " " + here.y2);
			System.out.println(here.x3 + " " + here.y3);

		}

	}

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		new C239().run();

	}

}


import java.beans.IntrospectionException;
import java.util.ArrayList;
import java.util.Scanner;

public class C239 {

	public class solution {
		int x1;
		int y1;
		int x2;
		int y2;
		int x3;
		int y3;

		public solution() {
			x1 = x2 = y1 = y2 = x3 = y3 = 0;
		}

	}

	static boolean perfect(int num) {

		double s = Math.sqrt(num);
		int ss = (int) s;
		if (ss * ss == num)
			return true;
		else
			return false;

	}

	public void run() {
		Scanner in = new Scanner(System.in);
		int a = in.nextInt();
		int b = in.nextInt();

		ArrayList<Integer> x = new ArrayList<Integer>();
		ArrayList<Integer> y = new ArrayList<Integer>();

		for (int xx = 0 - a; xx <= a; xx++) {

			int inter = a * a - xx * xx;

			if (!perfect(inter) || xx == 0)
				continue;

			int sq = (int) Math.sqrt(inter);

			int y1 = sq;
			int y2 = -sq;

			if (y1 != 0) {
				x.add(xx);
				y.add(y1);
			}

			if (y2 != 0) {
				x.add(xx);
				y.add(y2);
			}

		}

		ArrayList<solution> all = new ArrayList<solution>();
		for (int i = 0; i < x.size(); i++) {
			int xnow = x.get(i);
			int ynow = y.get(i);

			for (int xx = xnow - b; xx <= xnow + b; xx++) {

				int inter = b * b - (xnow - xx) * (xnow - xx);

				if (!perfect(inter))
					continue;

				int sq = (int) Math.sqrt(inter);

				int yy1 = ynow - sq;

				if ((yy1 - ynow) * ynow == -xnow * (xx - xnow)) {
					solution newsol = new solution();
					newsol.x1 = 0;
					newsol.y1 = 0;
					newsol.x2 = xnow;
					newsol.y2 = ynow;
					newsol.x3 = xx;
					newsol.y3 = yy1;

					all.add(newsol);

				}
				int yy2 = sq + ynow;
				if ((yy2 - ynow) * ynow == -xnow * (xx - xnow)) {
					solution newsol = new solution();
					newsol.x1 = 0;
					newsol.y1 = 0;
					newsol.x2 = xnow;
					newsol.y2 = ynow;
					newsol.x3 = xx;
					newsol.y3 = yy2;

					all.add(newsol);

				}

			}

		}

		if (all.size() == 0)
			System.out.println("NO");
		else {

			System.out.println("YES");
			solution here = all.get(0);
			System.out.println(here.x1 + " " + here.y1);
			System.out.println(here.x2 + " " + here.y2);
			System.out.println(here.x3 + " " + here.y3);

		}

	}

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		new C239().run();

	}

}


import java.beans.IntrospectionException;
import java.util.ArrayList;
import java.util.Scanner;

public class C239 {

	public class solution {
		int x1;
		int y1;
		int x2;
		int y2;
		int x3;
		int y3;

		public solution() {
			x1 = x2 = y1 = y2 = x3 = y3 = 0;
		}

	}

	static boolean perfect(int num) {

		double s = Math.sqrt(num);
		int ss = (int) s;
		if (ss * ss == num)
			return true;
		else
			return false;

	}

	public void run() {
		Scanner in = new Scanner(System.in);
		int a = in.nextInt();
		int b = in.nextInt();

		ArrayList<Integer> x = new ArrayList<Integer>();
		ArrayList<Integer> y = new ArrayList<Integer>();

		for (int xx = 0 - a-a; xx <= a+a; xx++) {

			int inter = a * a - xx * xx;

			if (!perfect(inter) || xx == 0)
				continue;

			int sq = (int) Math.sqrt(inter);

			int y1 = sq;
			int y2 = -sq;

			if (y1 != 0) {
				x.add(xx);
				y.add(y1);
			}

			if (y2 != 0) {
				x.add(xx);
				y.add(y2);
			}

		}

		ArrayList<solution> all = new ArrayList<solution>();
		for (int i = 0; i < x.size(); i++) {
			int xnow = x.get(i);
			int ynow = y.get(i);

			for (int xx = xnow - b-b; xx <= xnow + b+b; xx++) {

				int inter = b * b - (xnow - xx) * (xnow - xx);

				if (!perfect(inter) || xx == 0)
					continue;

				int sq = (int) Math.sqrt(inter);

				int yy1 = ynow - sq;

				if ((yy1 - ynow) * ynow == -xnow * (xx - xnow) && yy1 != 0) {
					solution newsol = new solution();
					newsol.x1 = 0;
					newsol.y1 = 0;
					newsol.x2 = xnow;
					newsol.y2 = ynow;
					newsol.x3 = xx;
					newsol.y3 = yy1;

					all.add(newsol);

				}
				int yy2 = sq + ynow;
				if ((yy2 - ynow) * ynow == -xnow * (xx - xnow) && yy2 !=0) {
					solution newsol = new solution();
					newsol.x1 = 0;
					newsol.y1 = 0;
					newsol.x2 = xnow;
					newsol.y2 = ynow;
					newsol.x3 = xx;
					newsol.y3 = yy2;

					all.add(newsol);

				}

			}

		}

		if (all.size() == 0)
			System.out.println("NO");
		else {

			System.out.println("YES");
			solution here = all.get(0);
			System.out.println(here.x1 + " " + here.y1);
			System.out.println(here.x2 + " " + here.y2);
			System.out.println(here.x3 + " " + here.y3);

		}

	}

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		new C239().run();

	}

}


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

public class Main implements Runnable {
  final boolean isFileIO = false;
  BufferedReader in;
  PrintWriter out;
  StringTokenizer st = new StringTokenizer("");
  String delim = " ";

  public static void main(String[] args) {
    new Thread(null, new Main(), "", 268435456).start();
  }

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

  public void initIO() throws IOException {
    if(!isFileIO) {
      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 nextToken() throws IOException {
    if(!st.hasMoreTokens()) {
      st = new StringTokenizer(in.readLine());
    }
    return st.nextToken(delim);
  }

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

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

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

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

  void solve() throws IOException {
    int a, b;
    a = nextInt(); b = nextInt();
    int[] sqrt = new int[1000001];
    Arrays.fill(sqrt, -1);
    for(int i = 1; i <= 1000; i++) {
      sqrt[i * i] = i;
    }
    for(int x_1 = -a; x_1 <= a; x_1++) {
      int y_1 = a * a - x_1 * x_1;
      if(sqrt[y_1] == -1) continue;
      for(int x_2 = -b; x_2 <= b; x_2++) {
        int y_2 = b * b - x_2 * x_2;
        if(sqrt[y_2] == -1) continue;
        if(b * b + a * a == (x_1 - x_2) * (x_1 - x_2) + (sqrt[y_1] - sqrt[y_2]) * (sqrt[y_1] - sqrt[y_2])) {
          if(sqrt[y_1] != sqrt[y_2]) {
            out.println("YES");
            out.println("0 0");
            out.println(x_1 + " " + sqrt[y_1]);
            out.println(x_2 + " " + sqrt[y_2]);
            return;
          }
        }
      }
    }
    out.println("NO");
  }
}


import java.awt.geom.Point2D;
import java.util.*;

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

	public Main(){
		new C().doIt();
	}

	class C{
		double EPS = 1.0e-8;
		Point2D normalVector1(Point2D p){
			return new Point2D.Double(-p.getY(), p.getX());
		}
		Point2D normalVector2(Point2D p){
			return new Point2D.Double(p.getY(), -p.getX());
		}
		void doIt(){
			int sss = in.nextInt();
			int ss = in.nextInt();
			int a = Math.max(sss, ss),b = Math.min(sss, ss);
			double ritu = 1.0*a/b;
			System.out.println(ritu);
			for(int i=0;i<=b;i++)for(int s=0;s<=b;s++){
				Point2D p = new Point2D.Double(i,s);
				if(p.distance(new Point2D.Double())!=b)continue;
				if(s==b||i==a)continue;
				Point2D p2 = normalVector1(p);
				Point2D p4 = new Point2D.Double(p2.getX()*ritu,p2.getY()*ritu);
				Point2D p3 = normalVector2(p);
				Point2D p5 = new Point2D.Double(p3.getX()*ritu,p3.getY()*ritu);
//				System.out.println(p);
//				System.out.println(p4);
//				System.out.println(p5);
//				System.out.println();
				if(Math.abs(p4.distance(new Point2D.Double())-a)<EPS){
					System.out.println("YES");
					System.out.println("0 0");
					System.out.println((int)p.getX()+" "+(int)p.getY());
					System.out.println((int)p4.getX()+" "+(int)p4.getY());
					return;
				}else if(Math.abs(p5.distance(new Point2D.Double())-a)<EPS){
					System.out.println("YES");
					System.out.println("0 0");
					System.out.println((int)p.getX()+" "+(int)p.getY());
					System.out.println((int)p5.getX()+" "+(int)p5.getY());
					return;
				}
			}
			System.out.println("NO");
		}
	}

}


import java.awt.geom.Point2D;
import java.util.*;

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

	public Main(){
		new C().doIt();
	}

	class C{
		double EPS = 1.0e-8;
		Point2D normalVector1(Point2D p){
			return new Point2D.Double(-p.getY(), p.getX());
		}
		Point2D normalVector2(Point2D p){
			return new Point2D.Double(p.getY(), -p.getX());
		}
		void doIt(){
			int sss = in.nextInt();
			int ss = in.nextInt();
			int a = Math.max(sss, ss),b = Math.min(sss, ss);
			for(int i=0;i<=b;i++)for(int s=0;s<=b;s++){
				Point2D p = new Point2D.Double(i,s);
				if(p.distance(new Point2D.Double())!=b)continue;
				if(s==b||i==a)continue;
				Point2D p2 = normalVector1(p);
				Point2D p4 = new Point2D.Double(p2.getX()*(a/b),p2.getY()*(a/b));
				Point2D p3 = normalVector2(p);
				Point2D p5 = new Point2D.Double(p3.getX()*(a/b),p3.getY()*(a/b));
//				System.out.println(p);
//				System.out.println(p4);
				if(Math.abs(p4.distance(new Point2D.Double())-a)<EPS){
					System.out.println("YES");
					System.out.println("0 0");
					System.out.println((int)p.getX()+" "+(int)p.getY());
					System.out.println((int)p4.getX()+" "+(int)p4.getY());
					return;
				}else if(Math.abs(p5.distance(new Point2D.Double())-a)<EPS){
					System.out.println("YES");
					System.out.println("0 0");
					System.out.println((int)p.getX()+" "+(int)p.getY());
					System.out.println((int)p5.getX()+" "+(int)p5.getY());
					return;
				}
			}
			System.out.println("NO");
		}
	}

}


import java.awt.geom.Point2D;
import java.util.*;

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

	public Main(){
		new C().doIt();
	}

	class C{
		double EPS = 1.0e-8;
		Point2D normalVector1(Point2D p){
			return new Point2D.Double(-p.getY(), p.getX());
		}
		Point2D normalVector2(Point2D p){
			return new Point2D.Double(p.getY(), -p.getX());
		}
		void doIt(){
			int sss = in.nextInt();
			int ss = in.nextInt();
			int a = Math.max(sss, ss),b = Math.min(sss, ss);
			for(int i=0;i<=b;i++)for(int s=0;s<=b;s++){
				Point2D p = new Point2D.Double(i,s);
				if(p.distance(new Point2D.Double())!=b)continue;
				if(s==b||i==a)continue;
				Point2D p2 = normalVector1(p);
				Point2D p4 = new Point2D.Double(p2.getX()*(a/b),p2.getY()*(a/b));
				Point2D p3 = normalVector2(p);
				Point2D p5 = new Point2D.Double(p3.getX()*(a/b),p3.getY()*(a/b));
//				System.out.println(p);
//				System.out.println(p4);
				if(Math.abs(p4.distance(new Point2D.Double())-a)<EPS){
					System.out.println("YES");return;
				}else if(Math.abs(p5.distance(new Point2D.Double())-a)<EPS){
					System.out.println("YES");return;
				}
			}
			System.out.println("NO");
		}
	}

}


import java.awt.geom.Point2D;
import java.util.*;

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

	public Main(){
		new C().doIt();
	}

	class C{
		double EPS = 1.0e-8;
		Point2D normalVector1(Point2D p){
			return new Point2D.Double(-p.getY(), p.getX());
		}
		Point2D normalVector2(Point2D p){
			return new Point2D.Double(p.getY(), -p.getX());
		}
		void doIt(){
			int sss = in.nextInt();
			int ss = in.nextInt();
			int a = Math.max(sss, ss),b = Math.min(sss, ss);
			double ritu = 1.0*a/b;
//			System.out.println(ritu);
			for(int i=0;i<=b;i++)for(int s=0;s<=b;s++){
				Point2D p = new Point2D.Double(i,s);
				if(p.distance(new Point2D.Double())!=b)continue;
				if(s==b||i==a)continue;
				Point2D p2 = normalVector1(p);
				Point2D p4 = new Point2D.Double(p2.getX()*ritu,p2.getY()*ritu);
				Point2D p3 = normalVector2(p);
				Point2D p5 = new Point2D.Double(p3.getX()*ritu,p3.getY()*ritu);
//				System.out.println(p);
//				System.out.println(p4);
//				System.out.println(p5);
//				System.out.println();
				if(Math.abs(p4.distance(new Point2D.Double())-a)<EPS){
					System.out.println("YES");
					System.out.println("0 0");
					System.out.println((int)p.getX()+" "+(int)p.getY());
					System.out.println((int)p4.getX()+" "+(int)p4.getY());
					return;
				}else if(Math.abs(p5.distance(new Point2D.Double())-a)<EPS){
					System.out.println("YES");
					System.out.println("0 0");
					System.out.println((int)p.getX()+" "+(int)p.getY());
					System.out.println((int)p5.getX()+" "+(int)p5.getY());
					return;
				}
			}
			System.out.println("NO");
		}
	}

}


import java.awt.geom.Point2D;
import java.util.*;

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

	public Main(){
		new C().doIt();
	}

	class C{
		double EPS = 1.0e-8;
		Point2D normalVector1(Point2D p){
			return new Point2D.Double(-p.getY(), p.getX());
		}
		Point2D normalVector2(Point2D p){
			return new Point2D.Double(p.getY(), -p.getX());
		}

//		boolean

		void doIt(){
			int sss = in.nextInt();
			int ss = in.nextInt();
			int a = Math.max(sss, ss),b = Math.min(sss, ss);
			double ritu = 1.0*a/b;
//			System.out.println(ritu);
			for(int i=0;i<=b;i++)for(int s=0;s<=b;s++){
				if(i==a||s==b)continue;
				if(i==b||s==a)continue;

				Point2D p = new Point2D.Double(i,s);
				if(p.distance(new Point2D.Double())!=b)continue;
				Point2D p2 = normalVector1(p);
				Point2D p4 = new Point2D.Double((int)(p2.getX()*ritu),(int)(p2.getY()*ritu));
				Point2D p3 = normalVector2(p);
				Point2D p5 = new Point2D.Double((int)(p3.getX()*ritu),(int)(p3.getY()*ritu));
//				System.out.println(p);
//				System.out.println(i+" "+s);
//				System.out.println(p4);
//				System.out.println(p5);
//				System.out.println();
				if(Math.abs(p4.distance(new Point2D.Double())-a)<EPS){
//					System.out.println(p4.distance(new Point2D.Double()));
					System.out.println("YES");
					System.out.println("0 0");
					System.out.println((int)p.getX()+" "+(int)p.getY());
					System.out.println((int)p4.getX()+" "+(int)p4.getY());
					return;
				}else if(Math.abs(p5.distance(new Point2D.Double())-a)<EPS){
					System.out.println("YES");
					System.out.println("0 0");
					System.out.println((int)p.getX()+" "+(int)p.getY());
					System.out.println((int)p5.getX()+" "+(int)p5.getY());
					return;
				}
			}
			System.out.println("NO");
		}
	}
}


import java.awt.geom.Point2D;
import java.util.*;

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

	public Main(){
		new C().doIt();
	}

	class C{
		double EPS = 1.0e-8;
		Point2D normalVector1(Point2D p){
			return new Point2D.Double(-p.getY(), p.getX());
		}
		Point2D normalVector2(Point2D p){
			return new Point2D.Double(p.getY(), -p.getX());
		}

//		boolean

		void doIt(){
			int sss = in.nextInt();
			int ss = in.nextInt();
			int a = Math.max(sss, ss),b = Math.min(sss, ss);
			double ritu = 1.0*a/b;
//			System.out.println(ritu);
			for(int i=0;i<=b;i++)for(int s=0;s<=b;s++){
				if(i==a||s==b)continue;
				if(i==b||s==a)continue;

				Point2D p = new Point2D.Double(i,s);
				if(p.distance(new Point2D.Double())!=b)continue;
				Point2D p2 = normalVector1(p);
				Point2D p4 = new Point2D.Double((int)(p2.getX()*ritu),(int)(p2.getY()*ritu));
				Point2D p3 = normalVector2(p);
				Point2D p5 = new Point2D.Double((int)(p3.getX()*ritu),(int)(p3.getY()*ritu));
//				System.out.println(p);
//				System.out.println(i+" "+s);
//				System.out.println(p4);
//				System.out.println(p5);
//				System.out.println();
				if(Math.abs(p4.distance(new Point2D.Double())-a)<EPS){
					if(p.getX()==p4.getX())continue;
					if(p.getY()==p4.getY())continue;
					System.out.println("YES");
					System.out.println("0 0");
					System.out.println((int)p.getX()+" "+(int)p.getY());
					System.out.println((int)p4.getX()+" "+(int)p4.getY());
					return;
				}else if(Math.abs(p5.distance(new Point2D.Double())-a)<EPS){
					if(p.getX()==p5.getX())continue;
					if(p.getY()==p5.getY())continue;
					System.out.println("YES");
					System.out.println("0 0");
					System.out.println((int)p.getX()+" "+(int)p.getY());
					System.out.println((int)p5.getX()+" "+(int)p5.getY());
					return;
				}
			}
			System.out.println("NO");
		}
	}
}


import java.awt.geom.Point2D;
import java.util.*;

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

	public Main(){
		new C().doIt();
	}

	class C{
		double EPS = 1.0e-8;
		Point2D normalVector1(Point2D p){
			return new Point2D.Double(-p.getY(), p.getX());
		}
		Point2D normalVector2(Point2D p){
			return new Point2D.Double(p.getY(), -p.getX());
		}

//		boolean

		void doIt(){
			int sss = in.nextInt();
			int ss = in.nextInt();
			int a = Math.max(sss, ss),b = Math.min(sss, ss);
			double ritu = 1.0*a/b;
//			System.out.println(ritu);
			for(int i=0;i<=b;i++)for(int s=0;s<=b;s++){
				if(i==a||s==b)continue;
				if(i==b||s==a)continue;
				Point2D p = new Point2D.Double(i,s);
				Point2D p2 = normalVector1(p);
				Point2D p4 = new Point2D.Double((int)(p2.getX()*ritu),(int)(p2.getY()*ritu));
				Point2D p3 = normalVector2(p);
				Point2D p5 = new Point2D.Double((int)(p3.getX()*ritu),(int)(p3.getY()*ritu));
//				System.out.println(p);
//				System.out.println(i+" "+s);
//				System.out.println(p4);
//				System.out.println(p5);
//				System.out.println();
				if(Math.abs(p4.distance(new Point2D.Double())-a)<EPS){
					System.out.println("YES");
					System.out.println("0 0");
					System.out.println((int)p.getX()+" "+(int)p.getY());
					System.out.println((int)p4.getX()+" "+(int)p4.getY());
					return;
				}else if(Math.abs(p5.distance(new Point2D.Double())-a)<EPS){
					System.out.println("YES");
					System.out.println("0 0");
					System.out.println((int)p.getX()+" "+(int)p.getY());
					System.out.println((int)p5.getX()+" "+(int)p5.getY());
					return;
				}
			}
			System.out.println("NO");
		}
	}

}


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

/**
 * Created by Praveen on 3/30/14.
 */
public class B
{
    public static void main(String[]args)
    {
        InputReader in=new InputReader(System.in);
        PrintWriter out=new PrintWriter(System.out);
        int a=in.nextInt();
        int b=in.nextInt();
        Vector<Integer> x1=new Vector<Integer>();
        Vector<Integer> y1=new Vector<Integer>();
        Vector<Integer> x2=new Vector<Integer>();
        Vector<Integer> y2=new Vector<Integer>();
        for(int x=-a;x<=a;x++)
            for(int y=-a;y<=a;y++)
            {
                if((long)x*x+(long)y*y==a*a)
                {
                    x1.add(x);
                    y1.add(y);
                }
            }
        for(int x=-b;x<=b;x++)
            for(int y=-b;y<=b;y++)
            {
                if((long)x*x+(long)y*y==b*b)
                {
                    x2.add(x);
                    y2.add(y);
                }
            }
        boolean ok=false;
        int ans1x=0,ans1y = 0,ans2x=0,ans2y=0;
        for(int i=0;i<x1.size();i++)
        {
            if(ok)break;
            for(int j=0;j<x2.size();j++)
            {
                if(x1.get(i)==x2.get(j)&&y1.get(i)==y2.get(j))
                    continue;
                if(x1.get(i)==0||y1.get(i)==0||x2.get(j)==0||y2.get(j)==0)
                    continue;
                if(x1.get(i)==x2.get(j)||y1.get(i)==y2.get(j))
                    continue;
                if(perpendicular(x1.get(i),y1.get(i),x2.get(j),y2.get(j)))
                {
                    ok=true;
                    ans1x=x1.get(i);
                    ans1y=y1.get(i);
                    ans2x=x2.get(j);
                    ans2y=y2.get(j);
                    break;
                }
            }
        }
        if(ok)
        {
            out.println("YES");
            out.println(ans1x + " " + ans1y);
            out.println("0 " + "0");
            out.println(ans2x+" "+ans2y);
        }
        else out.println("NO");
        out.close();
    }

    private static boolean perpendicular(long x1,long y1, long x2, long y2)
    {
        if(y1*y2==-x1*x2)return true;
        return false;
    }

    private static long solve(long a, long b) {
        long res=1;
        while(b>0)
        {
            if((b&1)>0)
            {
                res=(res*a);
                res%=10;
            }
            a=(a*a);
            a%=10;
            b>>=1;
        }
        return res;
    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream)
        {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            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());
        }
    }
}


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

/**
 * Created by Praveen on 3/30/14.
 */
public class B
{
    public static void main(String[]args)
    {
        InputReader in=new InputReader(System.in);
        PrintWriter out=new PrintWriter(System.out);
        int a=in.nextInt();
        int b=in.nextInt();
        Vector<Integer> x1=new Vector<Integer>();
        Vector<Integer> y1=new Vector<Integer>();
        Vector<Integer> x2=new Vector<Integer>();
        Vector<Integer> y2=new Vector<Integer>();
        for(int x=-a;x<=a;x++)
            for(int y=-a;y<=a;y++)
            {
                if((long)x*x+(long)y*y==a*a)
                {
                    x1.add(x);
                    y1.add(y);
                }
            }
        for(int x=-b;x<=b;x++)
            for(int y=-b;y<=b;y++)
            {
                if((long)x*x+(long)y*y==b*b)
                {
                    x2.add(x);
                    y2.add(y);
                }
            }
        boolean ok=false;
        int ans1x=0,ans1y = 0,ans2x=0,ans2y=0;
        for(int i=0;i<x1.size();i++)
        {
            if(ok)break;
            for(int j=0;j<x2.size();j++)
            {
                if(x1.get(i)==x2.get(j)&&y1.get(i)==y2.get(j))
                    continue;
                if(x1.get(i)==0||y1.get(i)==0||x2.get(j)==0||y2.get(j)==0)
                    continue;
                if(perpendicular(x1.get(i),y1.get(i),0,0,x2.get(j),y2.get(j)))
                {
                    ok=true;
                    ans1x=x1.get(i);
                    ans1y=y1.get(i);
                    ans2x=x2.get(j);
                    ans2y=y2.get(j);
                    break;
                }
            }
        }
        if(ok)
        {
            out.println("YES");
            out.println(ans1x + " " + ans1y);
            out.println("0 " + "0");
            out.println(ans2x+" "+ans2y);
        }
        else out.println("NO");
        out.close();
    }

    private static boolean perpendicular(long x1,long y1, long x2, long y2, long x3, long y3)
    {
        if(y1*y2==-x1*x2)return true;
        return false;
    }

    private static long solve(long a, long b) {
        long res=1;
        while(b>0)
        {
            if((b&1)>0)
            {
                res=(res*a);
                res%=10;
            }
            a=(a*a);
            a%=10;
            b>>=1;
        }
        return res;
    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream)
        {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            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());
        }
    }
}


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

/**
 * Created by Praveen on 3/30/14.
 */
public class B
{
    public static void main(String[]args)
    {
        InputReader in=new InputReader(System.in);
        PrintWriter out=new PrintWriter(System.out);
        int a=in.nextInt();
        int b=in.nextInt();
        Vector<Integer> x1=new Vector<Integer>();
        Vector<Integer> y1=new Vector<Integer>();
        Vector<Integer> x2=new Vector<Integer>();
        Vector<Integer> y2=new Vector<Integer>();
        for(int x=-a;x<=a;x++)
            for(int y=-a;y<=a;y++)
            {
                if((long)x*x+(long)y*y==a*a)
                {
                    x1.add(x);
                    y1.add(y);
                }
            }
        for(int x=-b;x<=b;x++)
            for(int y=-b;y<=b;y++)
            {
                if((long)x*x+(long)y*y==b*b)
                {
                    x2.add(x);
                    y2.add(y);
                }
            }
        boolean ok=false;
        int ans1x=0,ans1y = 0,ans2x=0,ans2y=0;
        for(int i=0;i<x1.size();i++)
        {
            if(ok)break;
            for(int j=0;j<x2.size();j++)
            {
                if(x1.get(i).equals(x2.get(j))&&y1.get(i).equals(y2.get(j)))
                    continue;
                if(x1.get(i)==0||y1.get(i)==0||x2.get(j)==0||y2.get(j)==0)
                    continue;
                if((x1.get(i).equals(x2.get(j))||(y1.get(i).equals(y2.get(j)))))
                    continue;
                if(perpendicular(x1.get(i),y1.get(i),x2.get(j),y2.get(j)))
                {
                    ok=true;
                    ans1x=x1.get(i);
                    ans1y=y1.get(i);
                    ans2x=x2.get(j);
                    ans2y=y2.get(j);
                    break;
                }
            }
        }
        if(ok)
        {
            out.println("YES");
            out.println(ans1x + " " + ans1y);
            out.println("0 " + "0");
            out.println(ans2x+" "+ans2y);
        }
        else out.println("NO");
        out.close();
    }

    private static boolean perpendicular(long x1,long y1, long x2, long y2)
    {
        if(y1*y2==-x1*x2)return true;
        return false;
    }

    private static long solve(long a, long b) {
        long res=1;
        while(b>0)
        {
            if((b&1)>0)
            {
                res=(res*a);
                res%=10;
            }
            a=(a*a);
            a%=10;
            b>>=1;
        }
        return res;
    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream)
        {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            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());
        }
    }
}


import java.awt.geom.Point2D;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int m = in.nextInt();
        int y1,x1,y2,x2;
        int cnt = 0;
        for(int i = 1;i < n;i++){
            if(cnt == 1)break;
            double k = n*n - i*i;
            k=Math.sqrt(k);
            if(k == (int)k){
                y1 = (int)k;
                x1 = i;
                for(int j = -1;j > -m;j--){
                    k = m*m - j*j;
                    k=Math.sqrt(k);
                    if(k == (int)k){
                        y2 = (int)k;
                        x2 = j;
                        if(n*n+m*m == (int)(Point2D.distanceSq(x1, y1, x2, y2))){
                            if(x1 != x2 && y1 != y2){
                                System.out.println("YES");
                                System.out.println(x1 + " " + y1);
                                System.out.println(x2 + " " + y2);
                                System.out.println(0 + " " + 0);
                                cnt = 1;
                                break;
                            }
                        }
                    }
                }
                if(cnt == 1)break;
            }
        }
        if(cnt == 0){
            System.out.println("NO");
        }
    }
}


import java.awt.geom.Point2D;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int m = in.nextInt();
        int y1,x1,y2,x2;
        int cnt = 0;
        for(int i = 1;i < n;i++){
            if(cnt == 1)break;
            double k = n*n - i*i;
            k=Math.sqrt(k);
            if(k == (int)k){
                y1 = (int)k;
                x1 = i;
                for(int j = -1;j > -m;j--){
                    k = m*m - j*j;
                    k=Math.sqrt(k);
                    if(k == (int)k){
                        y2 = (int)k;
                        x2 = j;
                        if(n*n+m*m == (int)(Point2D.distanceSq(x1, y1, x2, y2))){
                            System.out.println("YES");
                            System.out.println(x1 + " " + y1);
                            System.out.println(x2 + " " + y2);
                            System.out.println(0 + " " + 0);
                            cnt = 1;
                            break;
                        }
                    }
                }
                if(cnt == 1)break;
            }
        }
        if(cnt == 0){
            System.out.println("NO");
        }
    }
}


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

public class C_Triangle_r239d2 {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int r1 = sc.nextInt();
		int r2 = sc.nextInt();
		HashMap<Integer, Integer> sqrt = new HashMap<Integer, Integer>();
		for(int i = 1; i <= 1011; i++) {
			sqrt.put(i*i, i);
		}

		ArrayList<int[]> p1 = new ArrayList<int[]>();
		for(int x = -r1; x <= r1; x++) {
			int y2 = r1*r1 - x*x;
			Integer y = sqrt.get(y2);
			if(y != null) {
				if(x == 0 || y == 0)
					continue;
				p1.add(new int[]{x, y});
				p1.add(new int[]{x, -y});
			}
		}

		ArrayList<int[]> p2 = new ArrayList<int[]>();
		for(int x = -r2; x <= r2; x++) {
			int y2 = r2*r2 - x*x;
			Integer y = sqrt.get(y2);
			if(y != null) {
				if(x == 0 || y == 0)
					continue;
				p2.add(new int[]{x, y});
				p2.add(new int[]{x, -y});
			}
		}

		for(int c1[] : p1) {
			for(int c2[]: p2) {
				int x1 = c1[0], y1 = c1[1], x2 = c2[0], y2 = c2[1];
				if(Math.abs(y1)*Math.abs(x2) == Math.abs(y2)*Math.abs(x1)) {
					continue;
				}

				if(y1 == y2 || x1 == x2)
					continue;

				System.out.println("YES");
				System.out.println(0+" "+0);
				System.out.println(x1+" "+y1);
				System.out.println(x2+" "+y2);
				return;
			}
		}

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


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

public class C_Triangle_r239d2 {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int r1 = sc.nextInt();
		int r2 = sc.nextInt();
		HashMap<Integer, Integer> sqrt = new HashMap<Integer, Integer>();
		for(int i = 1; i <= 1011; i++) {
			sqrt.put(i*i, i);
		}

		ArrayList<int[]> p1 = new ArrayList<int[]>();
		for(int x = -r1; x <= r1; x++) {
			int y2 = r1*r1 - x*x;
			Integer y = sqrt.get(y2);
			if(y != null) {
				if(x == 0 || y == 0)
					continue;
				p1.add(new int[]{x, y});
			}
		}

		ArrayList<int[]> p2 = new ArrayList<int[]>();
		for(int x = -r2; x <= r2; x++) {
			int y2 = r2*r2 - x*x;
			Integer y = sqrt.get(y2);
			if(y != null) {
				if(x == 0 || y == 0)
					continue;
				p2.add(new int[]{x, y});
			}
		}

		for(int c1[] : p1) {
			for(int c2[]: p2) {
				int x1 = c1[0], x2 = c1[1], y1 = c2[0], y2 = c2[1];
				if(Math.abs(y1)*Math.abs(x2) == Math.abs(y2)*Math.abs(x1)) {
					continue;
				}
				System.out.println("YES");
				System.out.println(0+" "+0);
				System.out.println(x1+" "+y1);
				System.out.println(x2+" "+y2);
				return;
			}
		}

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


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

public class C_Triangle_r239d2 {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int r1 = sc.nextInt();
		int r2 = sc.nextInt();
		HashMap<Integer, Integer> sqrt = new HashMap<Integer, Integer>();
		for(int i = 1; i <= 1011; i++) {
			sqrt.put(i*i, i);
		}

		ArrayList<int[]> p1 = new ArrayList<int[]>();
		for(int x = -r1; x <= r1; x++) {
			int y2 = r1*r1 - x*x;
			Integer y = sqrt.get(y2);
			if(y != null) {
				if(x == 0 || y == 0)
					continue;
				p1.add(new int[]{x, y});
			}
		}

		ArrayList<int[]> p2 = new ArrayList<int[]>();
		for(int x = -r2; x <= r2; x++) {
			int y2 = r2*r2 - x*x;
			Integer y = sqrt.get(y2);
			if(y != null) {
				if(x == 0 || y == 0)
					continue;
				p2.add(new int[]{x, y});
			}
		}

		for(int c1[] : p1) {
			for(int c2[]: p2) {
				int x1 = c1[0], y1 = c1[1], x2 = c2[0], y2 = c2[1];
				if(Math.abs(y1)*Math.abs(x2) == Math.abs(y2)*Math.abs(x1)) {
					continue;
				}

				if(y1 == y2 || x1 == x2)
					continue;

				System.out.println("YES");
				System.out.println(0+" "+0);
				System.out.println(x1+" "+y1);
				System.out.println(x2+" "+y2);
				return;
			}
		}

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


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

public class C_Triangle_r239d2 {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int r1 = sc.nextInt();
		int r2 = sc.nextInt();
		HashMap<Integer, Integer> sqrt = new HashMap<Integer, Integer>();
		for(int i = 1; i <= 1011; i++) {
			sqrt.put(i*i, i);
		}

		ArrayList<int[]> p1 = new ArrayList<int[]>();
		for(int x = -r1; x <= r1; x++) {
			int y2 = r1*r1 - x*x;
			Integer y = sqrt.get(y2);
			if(y != null) {
				if(x == 0 || y == 0)
					continue;
				p1.add(new int[]{x, y});
				p1.add(new int[]{x, -y});
			}
		}

		ArrayList<int[]> p2 = new ArrayList<int[]>();
		for(int x = -r2; x <= r2; x++) {
			int y2 = r2*r2 - x*x;
			Integer y = sqrt.get(y2);
			if(y != null) {
				if(x == 0 || y == 0)
					continue;
				p2.add(new int[]{x, y});
				p2.add(new int[]{x, -y});
			}
		}

		for(int c1[] : p1) {
			for(int c2[]: p2) {
				int x1 = c1[0], y1 = c1[1], x2 = c2[0], y2 = c2[1];
				if(Math.abs(y1)*Math.abs(x2) == Math.abs(y2)*Math.abs(x1)) {
					continue;
				}

				if(x1*x2 + y1*y2 != 0)
					continue;

				if(y1 == y2 || x1 == x2)
					continue;

				System.out.println("YES");
				System.out.println(0+" "+0);
				System.out.println(x1+" "+y1);
				System.out.println(x2+" "+y2);
				return;
			}
		}

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


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

public class C_Triangle_r239d2 {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int r1 = sc.nextInt();
		int r2 = sc.nextInt();
		HashMap<Integer, Integer> sqrt = new HashMap<Integer, Integer>();
		for(int i = 1; i <= 1011; i++) {
			sqrt.put(i*i, i);
		}

		ArrayList<int[]> p1 = new ArrayList<int[]>();
		for(int x = -r1; x <= r1; x++) {
			int y2 = r1*r1 - x*x;
			Integer y = sqrt.get(y2);
			if(y != null) {
				if(x == 0 || y == 0)
					continue;
				p1.add(new int[]{x, y});
			}
		}

		ArrayList<int[]> p2 = new ArrayList<int[]>();
		for(int x = -r2; x <= r2; x++) {
			int y2 = r2*r2 - x*x;
			Integer y = sqrt.get(y2);
			if(y != null) {
				if(x == 0 || y == 0)
					continue;
				p2.add(new int[]{x, y});
			}
		}

		for(int c1[] : p1) {
			for(int c2[]: p2) {
				int x1 = c1[0], x2 = c1[1], y1 = c2[0], y2 = c2[1];
				if(Math.abs(y1)*Math.abs(x2) == Math.abs(y2)*Math.abs(x1)) {
					continue;
				}

				if(y1 == y2 || x1 == x2)
					continue;

				System.out.println("YES");
				System.out.println(0+" "+0);
				System.out.println(x1+" "+y1);
				System.out.println(x2+" "+y2);
				return;
			}
		}

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


import java.util.*;
import java.util.Map.Entry;
import java.io.*;
import java.math.*;

import static java.util.Arrays.*;
import static java.lang.Math.*;
import static java.util.Collections.*;
import static java.lang.System.out;

public class Main {
	static boolean LOCAL = System.getSecurityManager() == null;
	Scanner in = new Scanner(System.in);

	void run() {
		int a = in.nextInt(), b = in.nextInt();
		int[][] A = work(a);
		if (!fit(A, a, b)) {
			out.println("NO");
		}
	}
	private boolean fit(int[][] as, int a, int b) {
		for (int[] A : as) {
			int g = gcd(A[0], A[1]);
			int r = a / g;
			if (b % r == 0) {
				out.println("YES");
				out.println("0 0");
				sort(A);
				out.println(A[0] + " " + A[1]);
				int bt = b / r;
				out.println(-A[1] / g * bt + " " + A[0] / g * bt);
				return true;
			}
		}
		return false;
	}
	private int gcd(int i, int j) {
		while (j != 0) {
			int t = i;
			i = j;
			j = t % j;
		}
		if (i < 0) i = -i;
		return i;
	}
	private int[][] work(int a) {
		ArrayList<int[]> res = new ArrayList<int[]>();
		for (int i = 1; i < a; i++) {
			for (int j = i; j < a; j++) {
				if (i * i + j * j == a * a) res.add(new int[] {i, j});
			}
		}
		return res.toArray(new int[0][]);
	}
	void debug(Object... os) {
		System.err.println(deepToString(os));
	}

	public static void main(String[] args) {
		if (LOCAL) {
			try {
				System.setIn(new FileInputStream("./../in"));
			} catch (IOException e) {
				LOCAL = false;
			}
		}
		new Main().run();
	}
}

class Scanner {
	BufferedReader br;
	StringTokenizer st;

	Scanner(InputStream in) {
		br = new BufferedReader(new InputStreamReader(in));
		eat("");
	}

	private void eat(String string) {
		st = new StringTokenizer(string);
	}

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

	boolean hasNext() {
		while (!st.hasMoreTokens()) {
			String s = nextLine();
			if (s == null)
				return false;
			eat(s);
		}
		return true;
	}

	String next() {
		hasNext();
		return st.nextToken();
	}

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

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

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


import java.util.*;
import java.util.Map.Entry;
import java.io.*;
import java.math.*;

import static java.util.Arrays.*;
import static java.lang.Math.*;
import static java.util.Collections.*;
import static java.lang.System.out;

public class Main {
	static boolean LOCAL = System.getSecurityManager() == null;
	Scanner in = new Scanner(System.in);

	void run() {
		int a = in.nextInt(), b = in.nextInt();
		int[] A = work(a), B = work(b);
		if (A == null || B == null) out.println("NO");
		else {
			out.println("YES");
			out.println("0 0");
			sort(A);
			sort(B);
			out.println(A[0] + " " + A[1]);
			out.println(-B[1] + " " + B[0]);
		}
	}
	private int[] work(int a) {
		for (int i = 1; i < a; i++) {
			for (int j = 1; j < a; j++) {
				if (i * i + j * j == a * a) return new int[] {i, j};
			}
		}
		return null;
	}
	void debug(Object... os) {
		System.err.println(deepToString(os));
	}

	public static void main(String[] args) {
		if (LOCAL) {
			try {
				System.setIn(new FileInputStream("./../in"));
			} catch (IOException e) {
				LOCAL = false;
			}
		}
		new Main().run();
	}
}

class Scanner {
	BufferedReader br;
	StringTokenizer st;

	Scanner(InputStream in) {
		br = new BufferedReader(new InputStreamReader(in));
		eat("");
	}

	private void eat(String string) {
		st = new StringTokenizer(string);
	}

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

	boolean hasNext() {
		while (!st.hasMoreTokens()) {
			String s = nextLine();
			if (s == null)
				return false;
			eat(s);
		}
		return true;
	}

	String next() {
		hasNext();
		return st.nextToken();
	}

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

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

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


import java.util.*;
import java.util.Map.Entry;
import java.io.*;
import java.math.*;

import static java.util.Arrays.*;
import static java.lang.Math.*;
import static java.util.Collections.*;
import static java.lang.System.out;

public class Main {
	static boolean LOCAL = System.getSecurityManager() == null;
	Scanner in = new Scanner(System.in);

	void run() {
		int a = in.nextInt(), b = in.nextInt();
		int[][] A = work(a);
		if (!fit(A, a, b)) {
			out.println("NO");
		}
	}
	private boolean fit(int[][] as, int a, int b) {
		for (int[] A : as) {
			int g = gcd(A[0], A[1]);
			int r = a / g;
			if (b % r == 0) {
				int bt = b / r;
				if (A[0] / g * bt == A[1]) continue;
				out.println("YES");
				out.println("0 0");
				out.println(A[0] + " " + A[1]);
				out.println(-A[1] / g * bt + " " + A[0] / g * bt);
				return true;
			}
		}
		return false;
	}
	private int gcd(int i, int j) {
		while (j != 0) {
			int t = i;
			i = j;
			j = t % j;
		}
		if (i < 0) i = -i;
		return i;
	}
	private int[][] work(int a) {
		ArrayList<int[]> res = new ArrayList<int[]>();
		for (int i = 1; i < a; i++) {
			for (int j = 1; j < a; j++) {
				if (i * i + j * j == a * a) res.add(new int[] {i, j});
			}
		}
		return res.toArray(new int[0][]);
	}
	void debug(Object... os) {
		System.err.println(deepToString(os));
	}

	public static void main(String[] args) {
		if (LOCAL) {
			try {
				System.setIn(new FileInputStream("./../in"));
			} catch (IOException e) {
				LOCAL = false;
			}
		}
		new Main().run();
	}
}

class Scanner {
	BufferedReader br;
	StringTokenizer st;

	Scanner(InputStream in) {
		br = new BufferedReader(new InputStreamReader(in));
		eat("");
	}

	private void eat(String string) {
		st = new StringTokenizer(string);
	}

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

	boolean hasNext() {
		while (!st.hasMoreTokens()) {
			String s = nextLine();
			if (s == null)
				return false;
			eat(s);
		}
		return true;
	}

	String next() {
		hasNext();
		return st.nextToken();
	}

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

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

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


import java.util.*;
import java.util.Map.Entry;
import java.io.*;
import java.math.*;

import static java.util.Arrays.*;
import static java.lang.Math.*;
import static java.util.Collections.*;
import static java.lang.System.out;

public class Main {
	static boolean LOCAL = System.getSecurityManager() == null;
	Scanner in = new Scanner(System.in);

	void run() {
		int a = in.nextInt(), b = in.nextInt();
		int[][] A = work(a);
		if (!fit(A, a, b)) {
			out.println("NO");
		}
	}
	private boolean fit(int[][] as, int a, int b) {
		for (int[] A : as) {
			int g = gcd(A[0], A[1]);
			int r = a / g;
			if (b % r == 0) {
				int bt = b / r;
				if (A[0] / g * bt == A[1]) continue;
				out.println("YES");
				out.println("0 0");
				out.println(A[0] + " " + A[1]);
				out.println(-A[1] / g * bt + " " + A[0] / g * bt);
				return true;
			}
		}
		return false;
	}
	private int gcd(int i, int j) {
		while (j != 0) {
			int t = i;
			i = j;
			j = t % j;
		}
		if (i < 0) i = -i;
		return i;
	}
	private int[][] work(int a) {
		ArrayList<int[]> res = new ArrayList<int[]>();
		for (int i = 1; i < a; i++) {
			int j2 = a * a - i * i;
			int j = (int) (sqrt(j2));
			while (j * j < j2) j++;
			while (j * j > j2) j--;
			if (j * j == j2) res.add(new int[] {i, j});
		}
		return res.toArray(new int[0][]);
	}
	void debug(Object... os) {
		System.err.println(deepToString(os));
	}

	public static void main(String[] args) {
		if (LOCAL) {
			try {
				System.setIn(new FileInputStream("./../in"));
			} catch (IOException e) {
				LOCAL = false;
			}
		}
		new Main().run();
	}
}

class Scanner {
	BufferedReader br;
	StringTokenizer st;

	Scanner(InputStream in) {
		br = new BufferedReader(new InputStreamReader(in));
		eat("");
	}

	private void eat(String string) {
		st = new StringTokenizer(string);
	}

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

	boolean hasNext() {
		while (!st.hasMoreTokens()) {
			String s = nextLine();
			if (s == null)
				return false;
			eat(s);
		}
		return true;
	}

	String next() {
		hasNext();
		return st.nextToken();
	}

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

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

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


import java.util.Scanner;

public class C {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		for (int x_a = 1; x_a <= a; x_a++) {
			double yy_a = a*a - x_a*x_a;
			double y_a = Math.sqrt(yy_a);
			if (y_a == (int) y_a) {
				for (int x_b = 1; x_b <= b; x_b++) {
					double yy_b = b*b - x_b*x_b;
					double y_b = Math.sqrt(yy_b);
					if (y_b == (int) y_b) {
						if (x_a * x_b == y_a * y_b && x_a != -x_b && y_a != y_b) {
							System.out.println("YES");
							System.out.println(0 + " " + 0);
							System.out.println(-x_a + " " + (int)y_a);
							System.out.println(x_b + " " + (int)y_b);
							return;
						}
					}
				}
			}
		}
		System.out.println("NO");
	}
}


import java.util.Scanner;

public class C {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		for (int x_a = 1; x_a <= a; x_a++) {
			double yy_a = a*a - x_a*x_a;
			double y_a = Math.sqrt(yy_a);
			if (y_a == (int) y_a) {
				for (int x_b = 1; x_b <= b; x_b++) {
					double yy_b = b*b - x_b*x_b;
					double y_b = Math.sqrt(yy_b);
					if (y_b == (int) y_b) {
						if (x_a * x_b == y_a * y_b && x_a != x_b && y_a != y_b) {
							System.out.println("YES");
							System.out.println(0 + " " + 0);
							System.out.println(-x_a + " " + (int)y_a);
							System.out.println(x_b + " " + (int)y_b);
							return;
						}
					}
				}
			}
		}
		System.out.println("NO");
	}
}


import java.util.Scanner;

public class C {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		for (int x_a = 1; x_a <= a; x_a++) {
			double yy_a = a*a - x_a*x_a;
			double y_a = Math.sqrt(yy_a);
			if (y_a == (int) y_a) {// 找到了一组可以组成a的勾股数,i和left_a各为一条边
				for (int x_b = 1; x_b <= b; x_b++) {
					double yy_b = b*b - x_b*x_b;
					double y_b = Math.sqrt(yy_b);
					if (y_b == (int) y_b) {// 找到了4条边
						// 现在应该判断这些边是不是可以互相垂直
						if (x_a * x_b == y_a * y_b && x_a != x_b && y_a != y_b) {
							System.out.println("YES");
							System.out.println(0 + " " + 0);
							System.out.println(-x_a + " " + (int)y_a);
							System.out.println(x_b + " " + (int)y_b);
							return;
						}
					}
				}
			}
		}
		System.out.println("NO");
	}
}


import java.util.Scanner;

public class C {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		for (int x_a = 1; x_a <= a; x_a++) {
			double yy_a = a*a - x_a*x_a;
			double y_a = Math.sqrt(yy_a);
			if (y_a == (int) y_a) {
				for (int x_b = 1; x_b <= b; x_b++) {
					double yy_b = b*b - x_b*x_b;
					double y_b = Math.sqrt(yy_b);
					if (y_b == (int) y_b) {
						if (x_a * x_b == y_a * y_b && x_a != x_b || y_a != y_b) {
							System.out.println("YES");
							System.out.println(0 + " " + 0);
							System.out.println(-x_a + " " + (int)y_a);
							System.out.println(x_b + " " + (int)y_b);
							return;
						}
					}
				}
			}
		}
		System.out.println("NO");
	}
}


import java.util.Scanner;

public class C {

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

	public C() {
		Scanner sc = new Scanner(System.in);

		int a = sc.nextInt();
		int b = sc.nextInt();
		boolean found = false;
		int solx1 = 0;
		int solx2 = 0;
		int soly1 = 0;
		int soly2 = 0;
		for (int i = 1; i < a && !found; i++) {
			int j = (int) Math.sqrt(a * a - i * i);
			if ((Math.sqrt(a * a - i * i) - (double) j) > 0.999999)
				j++;
			if (a * a == (i * i + j * j)) {
				int x = b * i / a;
				int y = b * j / a;
				if (x * a == b * i && y * a == b * j) {
					if (j != x) {
						found = true;
						solx1 = i;
						soly1 = j;
						solx2 = -1 * y;
						soly2 = x;
					}
				}
			}
		}
		if (found) {
			System.out.println("YES");
			System.out.println("0 0");
			System.out.println(solx1 + " " + soly1);
			System.out.println(solx2 + " " + soly2);
		} else
			System.out.println("NO");
		sc.close();
	}
}


import java.util.Scanner;

public class C {

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

	public C() {
		Scanner sc = new Scanner(System.in);

		int a = sc.nextInt();
		int b = sc.nextInt();
		boolean found = false;
		int solx1 = 0;
		int solx2 = 0;
		int soly1 = 0;
		int soly2 = 0;
		for (int i = 1; i < a && !found; i++) {
			int j = (int) Math.sqrt(a*a-i*i);
			if (a*a == (i*i + j*j)) {
				int x = b*i/a;
				int y = b*j/a;
				if (x*a == b*i && y*a == b*j) {
					found = true;
					solx1 = i;
					soly1 = j;
					solx2 = -1*y;
					soly2 = x;
				}
			}
		}
		if (found) {
			System.out.println("YES");
			System.out.println("0 0");
			System.out.println(solx1 + " " + soly1);
			System.out.println(solx2 + " " + soly2);
		} else System.out.println("NO");
		sc.close();
	}
}


import java.util.Scanner;

public class C {

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

	public C() {
		Scanner sc = new Scanner(System.in);

		int a = sc.nextInt();
		int b = sc.nextInt();
		boolean found = false;
		int solx1 = 0;
		int solx2 = 0;
		int soly1 = 0;
		int soly2 = 0;
		for (int i = 1; i < a && !found; i++) {
			int j = (int) Math.sqrt(a*a-i*i);
			if ((Math.sqrt(a*a -i*i) - (double)j) > 0.999999) j++;
			if (a*a == (i*i + j*j)) {
				int x = b*i/a;
				int y = b*j/a;
				if (x*a == b*i && y*a == b*j) {
					found = true;
					solx1 = i;
					soly1 = j;
					solx2 = -1*y;
					soly2 = x;
				}
			}
		}
		if (found) {
			System.out.println("YES");
			System.out.println("0 0");
			System.out.println(solx1 + " " + soly1);
			System.out.println(solx2 + " " + soly2);
		} else System.out.println("NO");
		sc.close();
	}
}


#include<iostream>
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<math.h>
#define N 105
#define MOD 10000
using namespace std;
int main()
{
	int a,b;
	scanf("%d%d",&a,&b);
	int c=a*a+b*b,x1,y1,x2,y2;
	bool flag=false;
	for(int i=1; i<a; i++)
	{
		int x=a*a-i*i;
		x=sqrt(x);
		if((x*x+i*i)!=(a*a))
			continue;
		for(int j=1; j<b; j++)
		{
			if(i==j)
				continue;
			int y=b*b-j*j;
			y=sqrt(y);
			if((y*y+j*j)!=(b*b))
				continue;
			if((x+y)*(x+y)+(i-j)*(i-j)==c)
			{
				x1=x,y1=i;
				x2=y,y2=j;
				flag=true;
				break;
			}
		}
		if(flag)
			break;
	}
	if(!flag)
		cout<<"NO"<<endl;
	else
	{
		cout<<"YES"<<endl;
		cout<<-x1<<" "<<y1<<endl;
		cout<<"0 0"<<endl;
		cout<<x2<<" "<<y2<<endl;
	}
}


#include<iostream>
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<math.h>
#define N 105
#define MOD 10000
using namespace std;
int main()
{
	int a,b;
	scanf("%d%d",&a,&b);
	int c=a*a+b*b,x1,y1,x2,y2;
	bool flag=false;
	for(int i=1; i<a; i++)
	{
		int x=a*a-i*i;
		x=sqrt(x);
		if((x*x+i*i)!=(a*a))
			continue;
		for(int j=1; j<b; j++)
		{
			int y=b*b-j*j;
			y=sqrt(y);
			if((y*y+j*j)!=(b*b))
				continue;
			if((x+y)*(x+y)+(i-j)*(i-j)==c)
			{
				x1=x,y1=i;
				x2=y,y2=j;
				flag=true;
				break;
			}
		}
		if(flag)
			break;
	}
	if(!flag)
		cout<<"NO"<<endl;
	else
	{
		cout<<"YES"<<endl;
		cout<<-x1<<" "<<y1<<endl;
		cout<<"0 0"<<endl;
		cout<<x2<<" "<<y2<<endl;
	}
}


#include <bits/stdc++.h>
#include <unordered_map>
#include <unordered_set>
#include <stack>
#include <queue>
#include <deque>
#include <string>
#include <fstream>
#define ni(n) scanf("%d", &n)
#define nl(n) scanf("%I64d", &n)
#define nai(a,n) for (int i = 0; i < (n); i++) ni((a)[i])
#define nal(a,n) for (int i = 0; i < (n); i++) nl((a)[i])
#define case(t) printf("Case #%d: ", (t))
#define pii pair<int, int>
#define vii vector<pii>
#define vi vector<int>
#define pb push_back
#define mp make_pair
#define f first
#define s second
typedef long long ll;
const double pi = acos(-1);
const int MOD = 1e9 + 7;
const int INF = 1e9 + 7;
const int MAXN = 1e5 + 5;
const double eps = 1e-9;
using namespace std;
unordered_set<int> vis;

int main()
{
    for (int i = 1; i <= 1000; i++)
            vis.insert(i * i);
    int a, b;
    ni(a), ni(b);
    for (int i = 1; i < a; i++)
        if (vis.find(a * a - i * i) != vis.end())
        {
            int y = sqrt(a * a - i * i);
            int g = __gcd(i, y);
            int l = a / g;
            if (b % l != 0)
                continue;
            pii p = {-y / g * b / l, i / g * b / l};
            if (p.f == i || p.s == y)
                continue;
            return !printf("YES\n0 0\n%d %d\n%d %d\n", i, y, p.f, p.s);
        }
    return !printf("NO");
}


#include <bits/stdc++.h>
#include <unordered_map>
#include <unordered_set>
#include <stack>
#include <queue>
#include <deque>
#include <string>
#include <fstream>
#define ni(n) scanf("%d", &n)
#define nl(n) scanf("%I64d", &n)
#define nai(a,n) for (int i = 0; i < (n); i++) ni((a)[i])
#define nal(a,n) for (int i = 0; i < (n); i++) nl((a)[i])
#define case(t) printf("Case #%d: ", (t))
#define pii pair<int, int>
#define vii vector<pii>
#define vi vector<int>
#define pb push_back
#define mp make_pair
#define f first
#define s second
typedef long long ll;
const double pi = acos(-1);
const int MOD = 1e9 + 7;
const int INF = 1e9 + 7;
const int MAXN = 1e5 + 5;
const double eps = 1e-9;
using namespace std;
unordered_set<int> vis;

int main()
{
    for (int i = 1; i <= 1000; i++)
            vis.insert(i * i);
    int a, b;
    ni(a), ni(b);
    for (int i = 1; i < a; i++)
        if (vis.find(a * a - i * i) != vis.end())
        {
            int y = sqrt(a * a - i * i);
            int g = __gcd(i, y);
            int l = a / g;
            if (b % l != 0)
                continue;
            pii p = {-y / g * b / l, i / g * b / l};
            if (p.f == i && p.s == y)
                continue;
            return !printf("YES\n0 0\n%d %d\n%d %d\n", i, y, p.f, p.s);
        }
    return !printf("NO");
}


#include <bits/stdc++.h>
using namespace std;
#define all(v) (v).begin(),(v).end()
#define pb push_back
#define sqr(x) ((x)*(x))
#define mp make_pair
#define EPS 1e-9
#define ones(x) __builtin_popcount(x)
#define fast_io() ios_base::sync_with_stdio(0);cin.tie(0);
#define REP(i,x,y) for(int (i)=(x);(i)<(y);(i)++)
#define REPIT(it,A) for(__typeof(A.begin()) it = (A.begin()); it!=A.end();it++)
#define debug(x) cerr << #x << ": " << x << endl;
#define fst first
#define snd second
#define itm1 fst.fst
#define itm2 fst.snd
#define itm3 snd
#define mt(a,b,c) mp(mp(a,b),c)

typedef pair<int,int> ii;
typedef vector<int> vi;
typedef long long ll;
typedef pair<ll,ll> ill;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ill, ll> tri;
typedef pair<int,bool> ib;
typedef unsigned int uint;

const double PI = acos(-1);
const double E = 2.718281828459;
const int  INF = 2e9;
const ll LINF = 1e18 + 5;
const ll MOD = 1e9 + 7;
const int MAXN = 1e5 + 5;
const int MN = 1e6 + 2;

int get(int a, int n){
	int ret = n * n - a * a;
	if(ret < 0) return -1;
	int u = int(sqrt(ret));
	u = max(0, u - 2);
	while(1){
		if(u * u > ret) break;
		if(u * u == ret){
			return u;
		}
		++u;
	}
	return -1;
}

int main(){
	fast_io();
	int a, b; cin >> a >> b;
	int x1, x2, y1, y2;
	bool ok = 0;
	for(int i = -a; i <= a; ++i){
		for(int j = -b; j <= b; ++j){
			x1 = i;
			x2 = j;
			y1 = get(x1, a);
			y2 = get(x2, b);
//			if(x1 == 3 && x2 == -8){
//				debug(y1);
//				debug(y2);
//			}
			if(x1 == 0 || x2 == 0 || y1 == 0 || y2 == 0) continue;
			if(x1 == x2 || y1 == y2) continue;
			if(y1 != -1 && y2 != -1 && (y1 * y2 == -x1 * x2 )){
//				debug(x1);
//				debug(x2);
//				debug(y1);
//				debug(y2);
				ok = 1;
				break;
			}
			y1 = -y1;
			if(x1 == 0 || x2 == 0 || y1 == 0 || y2 == 0) continue;
			if(x1 == x2 || y1 == y2) continue;
			if(y1 != -1 && y2 != -1 && (y1 * y2 == -x1 * x2 )){
//				debug(x1);
//				debug(x2);
//				debug(y1);
//				debug(y2);
				ok = 1;
				break;
			}

		}
		if(ok) break;
	}
	if(!ok) cout << "NO" << endl;
	else{
		cout << "YES" << endl;
		cout << "0 0" << endl;
		cout << x1 << " " << y1 << endl;
		cout << x2 << " " << y2 << endl;
	}
	return 0;
}


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

const int N = 1005;
vector <int > w;
vector <pair<int,int> > v,x,y;

void solve(){
	for(int i = 3; i < N; i += 2){
		int k = i * 2 - 1;
		int p = sqrt(k);
		if(p * p == k) v.push_back(make_pair(p,i - 1)),w.push_back(i);
	}
}

int main(){
	int a,b,c,d,e,f,g,h;
	scanf("%d %d",&a,&b);
	int flag1 = 0,flag2 = 0;
	solve();
	for(int i = 0; i < w.size(); i++){
		if(a % w[i] == 0){ flag1 ++;
			int p = a / w[i];
			x.push_back(make_pair(p * v[i].first,p * v[i].second));
		}
		if(b % w[i] == 0){ flag2 ++;
			int q = b / w[i];
			y.push_back(make_pair(q * v[i].first,q * v[i].second));}
		}
	if(flag1 == 0 || flag2 == 0) puts("NO");
	else {
		if(a == b) {
			puts("YES");
			puts("0 0");
			printf("%d %d\n",x[0].first,x[0].second);
			printf("%d %d\n",-y[0].second,y[0].first);
		}
		else {
		for(int i = 0; i < x.size(); i++)
			for(int j = 0; j < y.size(); j++){
			if(x[i].first * y[i].second - x[i].second * y[i].first == 0){
					puts("YES");   puts("0 0");
					printf("%d %d\n",x[i].first,x[i].second);
					printf("%d %d\n",-y[i].first,y[i].second);
					return 0;
				}
			if(x[i].second * y[i].second - x[i].first * y[i].first == 0){
					puts("YES");   puts("0 0");
					printf("%d %d\n",x[i].second,x[i].first);
					printf("%d %d\n",-y[i].first,y[i].second);
				}
			}
		puts("NO");}
	}
}


#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> pii;
vector<pii> va, vb;

int main(){
    int a, b;
    scanf("%d%d", &a, &b);
    for(int i = 2; i * i < a * a; i ++){
        for(int j = i + 1; j * j < a * a; j ++){
            if(i * i + j * j == a * a) va.push_back(pii(i, j));
        }
    }
    for(int i = 2; i * i < b * b; i ++){
        for(int j = 2; j * j < b * b; j ++){
            if(i * i + j * j == b * b) vb.push_back(pii(i, j));
        }
    }
    if(va.size() == 0 || vb.size() == 0) {puts("NO"); return 0;}
    for(int i = 0; i < va.size(); i ++){
        for(int j = 0; j < vb.size(); j ++){
            int a1 = va[i].first, a2 = va[i].second;
            int b1 = vb[j].first, b2 = vb[j].second;
            if(a1 * b2 != a2 * b1) continue;
            if(a1 != b2){
                puts("YES");
                printf("%d %d\n", 0, 0);
                printf("%d %d\n", -a2, a1);
                printf("%d %d\n", b1, b2);
                return 0;
            }
            if(a2 != b1){
                puts("YES");
                printf("%d %d\n", 0, 0);
                printf("%d %d\n", -a1, a2);
                printf("%d %d\n", b2, b1);
                return 0;
            }
        }
    }
    puts("NO");
    return 0;
}


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

const int N = 1005;
vector <int > w;
vector <pair<int,int> > x,y;

void solve(int a,int t){
    for(int i = 1; i < N; i++)
		for(int j = 1; j < N; j++){
		if(i * i + j * j == a * a && t == 1) x.push_back(make_pair(i,j));
		if(i * i + j * j == a * a && t == 2) y.push_back(make_pair(i,j));
	}
}

bool f = 0;

int main(){
    int a,b;
    scanf("%d %d",&a,&b);
    solve(a,1),solve(b,2);
    if(x.size() == 0 || y.size() == 0) {puts("NO"); return 0;}
        for(int i = 0; i < x.size(); i++)
            for(int j = 0; j < y.size(); j++){
			if(x[i].first * y[j].first - x[i].second * y[j].second == 0){
				if(x[i].second != y[j].second){
					puts("YES"); puts("0 0");
					printf("%d %d\n",x[i].first,x[i].second);
					printf("%d %d\n",-y[j].first,y[j].second);
					return 0;
				}
			}
			if(x[i].first * y[j].second - x[i].second * y[j].first == 0){
				if(x[i].second != y[j].first){
					puts("YES"); puts("0 0");
					printf("%d %d\n",x[i].first,x[i].second);
					printf("%d %d\n",-y[j].second,y[j].first);
					return 0;
				}
			}
            }
        puts("NO");
}


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

int main() {
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    int a, b;
    cin >> a >> b;
    int d = __gcd(a, b);
    for(int i = 1; i < d; i ++) for(int j = 1; j < d; j ++) if(i * i + j * j == d*d) {
        puts("YES");
        puts("0 0");
        printf("%d %d\n", -i*a/d, j*a/d);
        printf("%d %d\n", j*b/d, i*b/d);
        return 0;
    }
    puts("NO");
}


#include <bits/stdc++.h>

using namespace std;
typedef pair < int , int  > pii;

vector  < pii > p, aa, bb;
pii c = pii(0, 0);

void check(int n){
	p.clear();
	for(int i = 1; i < n ; i ++){
		for(int j = 1; j < n ; j ++){
			if(i * i + j * j == n * n && i * j)p.push_back(pii(j, i));
		}
	}
	return ;
}

bool calc(pii a1, pii b1 ){
		if(a1 == c || b1 == c)return 0;
		if(a1.first * (-b1.first) + a1.second * b1.second == 0){
		cout << "YES\n";
		cout << "0 0\n";
		cout << a1.first << " " << a1.second<<endl;
		cout << -b1.first << " " << b1.second ;
		return 1;
	}
	if(a1.first * (-b1.second) + a1.second * b1.first == 0){
		cout << "YES\n";
		cout << "0 0\n";
		cout << a1.first << " " << a1.second<<endl;
		cout << -b1.second << " " << b1.first ;
		return 1;
	}
	if(a1.second * (-b1.first) + a1.first * b1.second == 0){
		cout << "YES\n";
		cout << "0 0\n";
		cout << a1.second << " " << a1.first<<endl;
		cout << -b1.first << " " << b1.second ;
		return 1;
	}
	if(a1.second * (-b1.second) + a1.first * b1.first == 0){
		cout << "YES\n";
		cout << "0 0\n";
		cout << a1.second << " " << a1.first<<endl;
		cout << -b1.second << " " << b1.first ;
		return 1;
	}
}
int main() {
	int a, b;
	pii a1, b1;
	cin >> a >> b;
	aa.clear();bb.clear();
	check(a);if(!p.empty())aa = p;else {cout << "NO";return 0;}
	check(b);if(!p.empty())bb = p;else {cout << "NO";return 0;}
	for(int i = 0; i < aa.size(); i ++){
		for(int j = 0 ; j < bb.size(); j ++){
			if(calc(aa[i], bb[j]))return 0;
		}
	}
	cout << "NO";

}


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

#define N 33

int main() {
    int a, b;
    cin >> a >> b;
    int d = __gcd(a, b);
    int k, l, ans = 0;
    for (k = 1; k < d; k ++) {
        l = sqrt(d * d - k * k);
        if (l * l + k * k == d * d && a * k != b * l) {
            ans = 1; break;
        }
    }
    if (!ans) puts("NO");
    else {
        puts("YES"); a /= d, b /= d;
        printf("%d %d\n", -a * l, a * k);
        puts("0 0");
        printf("%d %d\n", b * k, b * l);
    }

}


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

const int N = 1005;
vector <int > w;
vector <pair<int,int> > v;

void solve(){
	for(int i = 3; i < N; i += 2){
		int k = i * 2 - 1;
		int p = sqrt(k);
		if(p * p == k) v.push_back(make_pair(p,i - 1)),w.push_back(i);
	}
}

int main(){
	int a,b,c,d,e,f,g,h;
	scanf("%d %d",&a,&b);
	int flag = 0;
	solve();
	bool s = 0, t = 0;
	for(int i = 0; i < w.size(); i++){
		if(a % w[i] == 0 && s == 0)
			c = v[i].first,d = v[i].second,flag++,g = a / w[i],s = 1;
		if(b % w[i] == 0 && t == 0)
			e = v[i].first,f = v[i].second,flag++,h = b / w[i],t = 1;}
	if(flag == 2){
		int id = 0,k;
		id = ((c * g) + (f * h)) * ((c * g) + (f * h));
		id += ((d * g) - (e * h)) * ((d * g) - (e * h));
		if(a * a + b * b == id){
			puts("YES");
			puts("0 0");
		if(d * g == e * h){
			printf("%d %d\n",d * g,c * g);
			printf("%d %d\n",-(e * h),f * h);
		}
		else {
		printf("%d %d\n",c * g,d * g);
		printf("%d %d\n",-(f * h),e * h);
		}
		}
		else puts("NO");
	}
	else puts("NO");
}


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

int a, b;

vector<pair<int, int>> a_cd, b_cd;

int pow (int x) {
	return x * x;
}

int main() {
//	freopen("in.txt", "r", stdin);
	ios::sync_with_stdio(0);
	cin.tie(0), cout.tie(0);
	cin >> a >> b;
	for (int i = 1; i < a; i++) {
		for (int j = 1; j < a; j++) {
			if ((pow(i) + pow(j)) == pow(a)) a_cd.push_back(make_pair(i, j));
		}
	}
	for (int i = 1; i < b; i++) {
		for (int j = 1; j < b; j++) {
			if ((pow(i) + pow(j)) == pow(b)) b_cd.push_back(make_pair(i, j));
		}
	}
	for (auto &x : a_cd) x.first *= -1;
	int flag = 0, x1, y1, x2, y2;
	for (auto x : a_cd) {
		for (auto y : b_cd) {
			if (!(x.first * y.first + x.second * y.second) && x.first != y.first) {
				x1 = x.first; y1 = x.second;
				x2 = y.first; y2 = y.second;
				flag = 1; break;
			}
		}
		if (flag) break;
	}
	if (!flag) cout << "NO" << endl;
	else {
		cout << "YES" << endl;
		cout << 0 << " " << 0 << endl;
		cout << x1 << " " << y1 << endl;
		cout << x2 << " " << y2 << endl;
	}
	return 0;
}


#include <bits/stdc++.h>

using namespace std;
typedef pair < int , int  > pii;

vector  < pii > p, aa, bb;
pii c = pii(0, 0);

void check(int n){
	p.clear();
	for(int i = 1; i < n ; i ++){
		for(int j = 1; j < n ; j ++){
			if(i * i + j * j == n * n)p.push_back(pii(j, i));
		}
	}
	return ;
}

bool calc(pii a1, pii b1 ){
		if(a1 == c || b1 == c)return 0;
		if(a1.first * (-b1.first) + a1.second * b1.second == 0){
		cout << "YES\n";
		cout << "0 0\n";
		cout << a1.first << " " << a1.second<<endl;
		cout << -b1.first << " " << b1.second ;
		return 1;
	}
	if(a1.first * (-b1.second) + a1.second * b1.first == 0){
		cout << "YES\n";
		cout << "0 0\n";
		cout << a1.first << " " << a1.second<<endl;
		cout << -b1.second << " " << b1.first ;
		return 1;
	}
	return 0;
}
int main() {
	int a, b;
	pii a1, b1;
	cin >> a >> b;
	aa.clear();bb.clear();
	check(a);if(!p.empty())aa = p;else {cout << "NO";return 0;}
	check(b);if(!p.empty())bb = p;else {cout << "NO";return 0;}
	for(int i = 0; i < aa.size(); i ++){
		for(int j = 0 ; j < bb.size(); j ++){
			if(calc(aa[i], bb[j]))return 0;
		}
	}
	cout << "NO";

}


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

int main() {
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    int a, b;
    cin >> a >> b;
    vector <int> x1, x2, y1, y2;
    for(int i = 1; i < a; i ++) for(int j = 1; j < a; j ++) if(i * i + j * j == a * a) {
        x1.push_back(-i);
        y1.push_back(j);
    }
    for(int i = 1; i < b; i ++) for(int j = 1; j < b; j ++) if(i * i + j * j == b * b) {
        x2.push_back(i);
        y2.push_back(j);
    }
    for(int i = 0; i < x1.size(); i ++) for(int j = 0; j < x2.size(); j ++) {
        if(x1[i] * x2[j] + y1[i] * y2[j] == 0 && y1[i] != y2[j]) {
            puts("YES");
            puts("0 0");
            printf("%d %d\n", x1[i], y1[i]);
            printf("%d %d\n", x2[j], y2[j]);
            return 0;
        }
    }
    puts("NO");
}


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

const int N = 1005;
vector <int > w;
vector <pair<int,int> > v;

void solve(){
	for(int i = 3; i < N; i += 2){
		int k = i * 2 - 1;
		int p = sqrt(k);
		if(p * p == k) v.push_back(make_pair(p,i - 1)),w.push_back(i);
	}
}

int main(){
	int a,b,c,d,e,f,g,h;
	scanf("%d %d",&a,&b);
	int flag = 0;
	solve();
	bool s = 0, t = 0;
	for(int i = 0; i < w.size(); i++){
		if(a % w[i] == 0 && s == 0)
			c = v[i].first,d = v[i].second,flag++,g = a / w[i],s = 1;
		if(b % w[i] == 0 && t == 0)
			e = v[i].first,f = v[i].second,flag++,h = b / w[i],t = 1;}
	if(flag == 2){
		int id = 0,k;
		id = ((c * g) + (f * h)) * ((c * g) + (f * h));
		id += ((d * g) - (e * h)) * ((d * g) - (e * h));
		if(a * a + b * b == id ){
		if(d * g == e * h){
			id = ((d * g) + (e * h)) * ((d * g) + (e * h));
			id += ((c * g) - (f * h)) * ((c * g) - (f * h));
			if(a * a + b * b == id){
				puts("YES");
				puts("0 0");
				printf("%d %d\n",d * g,c * g);
				printf("%d %d\n",-(e * h),f * h);
			}
			else puts("NO");
		}
		else {
		puts("YES");
		puts("0 0");
		printf("%d %d\n",c * g,d * g);
		printf("%d %d\n",-(f * h),e * h);
		}
		}
		else puts("NO");
	}
	else puts("NO");
}


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

int main(){
    int a, b;
    scanf("%d%d", &a, &b);
    if(a % 5 ==0 && b % 5 == 0){
        int a1 = 3 * a / 5;
        int a2 = 4 * a / 5;
        int b1 = 3 * b / 5;
        int b2 = 4 * b / 5;
        if(a1 == b2 && a2 == b1) {puts("NO"); return 0;}
        if(a1 != b2){
            puts("YES");
            printf("0 0\n");
            printf("%d %d\n", -a2, a1);
            printf("%d %d\n", b1, b2);
        }
        else{
            puts("YES");
            printf("%d %d\n", 0, 0);
            printf("%d %d\n", -a1, a2);
            printf("%d %d\n", b2, b1);
        }
    }
    else puts("NO");
}


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

#define N 33

int main() {
    int a, b;
    cin >> a >> b;
    int d = __gcd(a, b);
    int k, l, ans = 0;
    for (k = 1; k * k < d; k ++) {
        l = sqrt(d - k * k);
        if (l * l + k * k == d) {
            ans = 1; break;
        }
    }
    if (!ans) puts("NO");
    else {
        puts("YES"); a /= d, b /= d;
        printf("%d %d\n", -a * l, a * k);
        puts("0 0");
        printf("%d %d\n", b * k, b * l);
    }

}


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

using ll = long long;

#define N

int a, b;

int up = 34;

int main() {
	scanf("%d %d", &a, &b);
    int xa, ya, xb, yb;
    for (xa = -up; xa <= up; xa ++) {
		for (ya = -up; ya <= up; ya ++) {
            if (xa * xa + ya * ya != a * a) continue;
            if (!xa) continue;
            if (!ya) continue;
			for (xb = -up; xb <= up; xb ++) {
				for (yb = -up; yb <= up; yb ++) {
					if (!xb) continue;
					if (!yb) continue;
                    if (xb * xb + yb * yb != b * b) continue;
					if (xa * xb + ya * yb != 0) continue;
					if (xa * yb - ya * xb == 0) continue;
					if (xa == xb) continue;
					if (ya == yb) continue;
                    puts("YES");
                    printf("%d %d\n", xa, ya);
                    printf("%d %d\n", 0, 0);
                    printf("%d %d\n", xb, yb);
                    return 0;
				}
			}
		}
    }
    puts("NO");
	return 0;
}


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

int a, b;

vector<pair<int, int>> a_cd, b_cd;

int pow (int x) {
	return x * x;
}

int main() {
//	freopen("in.txt", "r", stdin);
	ios::sync_with_stdio(0);
	cin.tie(0), cout.tie(0);
	cin >> a >> b;
	for (int i = 1; i < a; i++) {
		for (int j = i; j < a; j++) {
			if ((pow(i) + pow(j)) == pow(a) && (i && j)) a_cd.push_back(make_pair(i, j));
		}
	}
	for (int i = 1; i < b; i++) {
		for (int j = i; j < b; j++) {
			if ((pow(i) + pow(j)) == pow(b) && (i && j)) b_cd.push_back(make_pair(i, j));
		}
	}
	for (auto &x : a_cd) x.first *= -1;
	int flag = 0, x1, y1, x2, y2;
	for (auto x : a_cd) {
		for (auto y : b_cd) {
			if (!(x.first * y.first + x.second * y.second)) {
				x1 = x.first; y1 = x.second;
				x2 = y.first; y2 = y.second;
				flag = 1; break;
			}
		}
		if (flag) break;
	}
	if (!flag) cout << "NO" << endl;
	else {
		cout << "YES" << endl;
		cout << 0 << " " << 0 << endl;
		cout << x1 << " " << y1 << endl;
		cout << x2 << " " << y2 << endl;
	}
	return 0;
}


#include <bits/stdc++.h>

using namespace std;
typedef pair < int , int  > pii;

pii check(int n){
	for(int i = 1; i < n ; i ++){
		for(int j = 1; j < n ; j ++){
			if(i * i + j * j == n * n && i * j)return(pii(j, i));
		}
	}
	return pii(0, 0);
}
int main() {
	int a, b;
	pii a1, b1, c = pii(0, 0);
	cin >> a >> b;
	a1 = check(a);
	b1 = check(b);
	if(a1 != c && b1 != c){
	if(a1.first * (-b1.first) + a1.second * b1.second == 0){
		cout << "YES\n";
		cout << "0 0\n";
		cout << a1.first << " " << a1.second<<endl;
		cout << -b1.first << " " << b1.second ;
		return 0;
	}
	if(a1.first * (-b1.second) + a1.second * b1.first == 0){
		cout << "YES\n";
		cout << "0 0\n";
		cout << a1.first << " " << a1.second<<endl;
		cout << -b1.second << " " << b1.first ;
		return 0;
	}
	if(a1.second * (-b1.first) + a1.first * b1.second == 0){
		cout << "YES\n";
		cout << "0 0\n";
		cout << a1.second << " " << a1.first<<endl;
		cout << -b1.first << " " << b1.second ;
		return 0;
	}
	if(a1.second * (-b1.second) + a1.first * b1.first == 0){
		cout << "YES\n";
		cout << "0 0\n";
		cout << a1.second << " " << a1.first<<endl;
		cout << -b1.second << " " << b1.first ;
		return 0;
	}}
	cout << "NO";

}


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

#define N 33

int main() {
    int a, b;
    cin >> a >> b;
    int d = __gcd(a, b);
    int k, l, ans = 0;
    for (k = 1; k < d; k ++) {
        l = sqrt(d * d - k * k);
        if (l * l + k * k == d * d) {
            ans = 1; break;
        }
    }
    if (!ans) puts("NO");
    else {
        puts("YES"); a /= d, b /= d;
        printf("%d %d\n", -a * l, a * k);
        puts("0 0");
        printf("%d %d\n", b * k, b * l);
    }

}


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

const int N = 1005;
vector <int > w;
vector <pair<int,int> > v,x,y;

void solve(){
	for(int i = 3; i < N; i += 2){
		int k = i * 2 - 1;
		int p = sqrt(k);
		if(p * p == k) v.push_back(make_pair(p,i - 1)),w.push_back(i);
	}
}

int main(){
	int a,b,c,d,e,f,g,h;
	scanf("%d %d",&a,&b);
	int flag1 = 0,flag2 = 0;
	solve();
	for(int i = 0; i < w.size(); i++){
		if(a % w[i] == 0){ flag1 ++;
			int p = a / w[i];
			x.push_back(make_pair(p * v[i].first,p * v[i].second));
		}
		if(b % w[i] == 0){ flag2 ++;
			int q = b / w[i];
			y.push_back(make_pair(q * v[i].first,q * v[i].second));}
		}
	if(flag1 == 0 || flag2 == 0) puts("NO");
	else {
		for(int i = 0; i < x.size(); i++)
			for(int j = 0; j < y.size(); j++){
			if(x[i].first * y[i].second - x[i].second * y[i].first == 0){
					if(x[i].second != y[i].second){
					puts("YES");   puts("0 0");
					printf("%d %d\n",x[i].first,x[i].second);
					printf("%d %d\n",-y[i].first,y[i].second);
					return 0;}
					else {
					puts("YES");   puts("0 0");
					printf("%d %d\n",x[i].first,x[i].second);
					printf("%d %d\n",-y[i].second,y[i].first);
					return 0;
					}
				}
			if(x[i].second * y[i].second - x[i].first * y[i].first == 0){
					if(x[i].second != y[i].first){
					puts("YES");   puts("0 0");
					printf("%d %d\n",x[i].first,x[i].second);
					printf("%d %d\n",-y[i].second,y[i].first);
					return 0;
					}
					else {
					puts("YES");   puts("0 0");
					printf("%d %d\n",x[i].second,x[i].first);
					printf("%d %d\n",-y[i].first,y[i].second);
					return 0;
					}
				}
			}
		puts("NO");}
}


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

int a, b;

vector<pair<int, int>> a_cd, b_cd;

int pow (int x) {
	return x * x;
}

int main() {
//	freopen("in.txt", "r", stdin);
	ios::sync_with_stdio(0);
	cin.tie(0), cout.tie(0);
	cin >> a >> b;
	for (int i = 1; i < a; i++) {
		for (int j = 1; j < a; j++) {
			if ((pow(i) + pow(j)) == pow(a) && (i && j)) a_cd.push_back(make_pair(i, j));
		}
	}
	for (int i = 1; i < b; i++) {
		for (int j = 1; j < b; j++) {
			if ((pow(i) + pow(j)) == pow(b) && (i && j)) b_cd.push_back(make_pair(i, j));
		}
	}
	for (auto &x : a_cd) x.first *= -1;
	int flag = 0, x1, y1, x2, y2;
	for (auto x : a_cd) {
		for (auto y : b_cd) {
			if (!(x.first * y.first + x.second * y.second)) {
				x1 = x.first; y1 = x.second;
				x2 = y.first; y2 = y.second;
				flag = 1; break;
			}
		}
		if (flag) break;
	}
	if (!flag) cout << "NO" << endl;
	else {
		cout << "YES" << endl;
		cout << 0 << " " << 0 << endl;
		cout << x1 << " " << y1 << endl;
		cout << x2 << " " << y2 << endl;
	}
	return 0;
}


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

using ll = long long;

#define N

int a, b;

int up = 34;

int main() {
//	freopen("1.in", "r", stdin);
	scanf("%d %d", &a, &b);
    int xa, ya, xb, yb;
    for (xa = -a; xa <= a; xa ++) {
        ya = sqrt(a * a - xa * xa + 0.25);
		if (ya * ya != a * a - xa * xa) continue;
		if (!xa) continue;
		if (!ya) continue;
		for (xb = -b; xb <= b; xb ++) {
            yb = sqrt(b*b - xb * xb + 0.25);
			if (yb * yb != b * b - xb * xb) continue;
			if (!xb) continue;
			if (!yb) continue;
			if (xa * xb + ya * yb != 0) continue;
			if (xa * yb - ya * xb == 0) continue;
			if (xa == xb) continue;
			if (ya == yb) continue;
			puts("YES");
			printf("%d %d\n", xa, ya);
			printf("%d %d\n", 0, 0);
			printf("%d %d\n", xb, yb);
			return 0;
		}
    }
    puts("NO");
	return 0;
}


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

const int N = 1005;
vector <int > w;
vector <pair<int,int> > x,y;

void solve(int a,int t){
    for(int i = 1; i < N; i++)
		for(int j = 1; j < N; j++){
		if(i * i + j * j == a * a && t == 1) x.push_back(make_pair(i,j));
		if(i * i + j * j == a * a && t == 2) y.push_back(make_pair(i,j));
	}
}

bool f = 0;

int main(){
    int a,b;
    scanf("%d %d",&a,&b);
    solve(a,1),solve(b,2);
    if(x.size() == 0 || y.size() == 0) {puts("NO"); return 0;}
        for(int i = 0; i < x.size(); i++)
            for(int j = 0; j < y.size(); j++){
			if(x[i].first * y[i].first - x[i].second * y[i].second == 0){
				if(x[i].second != y[i].second){
					puts("YES"); puts("0 0");
					printf("%d %d\n",x[i].first,x[i].second);
					printf("%d %d\n",-y[i].first,y[i].second);
					return 0;
				}
			}
			if(x[i].first * y[i].second - x[i].second * y[i].first == 0){
				if(x[i].second != y[i].first){
					puts("YES"); puts("0 0");
					printf("%d %d\n",x[i].first,x[i].second);
					printf("%d %d\n",-y[i].second,y[i].first);
					return 0;
				}
			}
            }
        puts("NO");
}


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

const int N = 1005;
vector <int > w;
vector <pair<int,int> > v;

void solve(){
	for(int i = 3; i < N; i += 2){
		int k = i * 2 - 1;
		int p = sqrt(k);
		if(p * p == k) v.push_back(make_pair(p,i - 1)),w.push_back(i);
	}
}

int main(){
	int a,b,c,d,e,f,g,h;
	scanf("%d %d",&a,&b);
	int flag = 0;
	solve();
	bool s = 0, t = 0;
	for(int i = 0; i < w.size(); i++){
		if(a % w[i] == 0 && s == 0)
			c = v[i].first,d = v[i].second,flag++,g = a / w[i],s = 1;
		if(b % w[i] == 0 && t == 0)
			e = v[i].first,f = v[i].second,flag++,h = b / w[i],t = 1;}
	if(flag == 2){
		int id = 0,k;
		id = ((c * g) + (f * h)) * ((c * g) + (f * h));
		id += ((d * g) + (e * h)) * ((d * g) + (e * h));
		k = sqrt(id);
		if(k * k == id || a == b){
		if(a * a + b * b == id){
			puts("YES");
			puts("0 0");
		if(d * g == e * h){
			printf("%d %d\n",d * g,c * g);
			printf("%d %d\n",-(e * h),f * h);
		}
		else {
		printf("%d %d\n",c * g,d * g);
		printf("%d %d\n",-(f * h),e * h);
		}
			}
			else puts("NO");
		}
		else puts("NO");
	}
	else puts("NO");
}


#include <bits/stdc++.h>
#define pb push_back
#define ll long long
#define endl "\n"
#define mp make_pair
#define all(c) (c).begin(),(c).end()
#define hell 1000000007
#define ff first
#define ss second
#define pii pair<ll,ll>
#define bs binary_search
#define upd upper_bound
#define lbd lower_bound
#define vi vector<ll>
#define vii vector<pii>
#define mi map<ll,ll>
#define mii map<string,ll>
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#pragma comment (linker, "/STACK:256000000")
using namespace std;

#define N 200001

ll i=0,j=0,k=0,cnt=0,sum=0,res=0,start=0,finall=0,maxi=0,mini=hell,len=0,cnt1=0,cnt2=0,ans=0,cnt3=0,eend=0,pos=0;int flag=0;
vi adj[N];
bool visited[N];
ll plu[N];
ll minu[N];
ll c[N];

void dfs(ll v)
{
    visited[v]=true;
    ll a=0,b=0;
    for(auto u :adj[v])
    {
        if(!visited[u])
        {
            dfs(u);
        }
        a=max(a,plu[u]);
        b=max(b,minu[u]);
    }
    ll diff=c[v]-(a-b);
    if(diff>0)a+=diff;
    else
        b-=diff;
    plu[v]=a;
    minu[v]=b;
}
int main()
{
    IOS;
    memset(visited,false,sizeof(visited));
    ll n;
    cin>>n;
    for(i=1;i<n;i++)
    {
        ll a,b;
        cin>>a>>b;
        adj[a].pb(b);
        adj[b].pb(a);
    }
    for(i=1;i<=n;i++)
    {
        ll a;
        cin>>a;
        c[i]=a;
    }
    dfs(1);
    cout<<plu[1]+minu[1]<<endl;
}


    #include <bits/stdc++.h>
    using namespace std;
	int n,w[100003];
	vector<vector<int>>tree;
	vector<pair<int,int>>oper;
	void dfs(int node,int par){
		for(auto i:tree[node]){
			if(i!=par){
				dfs(i,node);
				oper[node].first+=oper[i].first;
				oper[node].second+=oper[i].second;
			}
		}
		w[node]+=oper[node].first-oper[node].second;
		if(w[node]>0) oper[node].second+=w[node];
		else oper[node].first-=w[node];
	}
    int main(){
        ios_base::sync_with_stdio(false);
        cin.tie(NULL);
		cin>>n;
		tree.assign(n+1,vector<int>());
		oper.assign(n+1,{0,0});
		for(int i=0;i<n-1;i++){
			int a,b;
			cin>>a>>b;
			tree[a].push_back(b),tree[b].push_back(a);
		}
		for(int i=1;i<=n;i++) cin>>w[i];
		dfs(1,-1);
		cout<<oper[1].first+oper[1].second;
    }


v    #include <bits/stdc++.h>
    using namespace std;
	int n,w[100003];
	vector<vector<int>>tree;
	vector<pair<int,int>>oper;
	void dfs(int node,int par){
		for(auto i:tree[node]){
			if(i!=par){
				dfs(i,node);
				oper[node].first+=oper[i].first;
				oper[node].second+=oper[i].second;
			}
		}
		w[node]+=oper[node].first-oper[node].second;
		if(w[node]>0) oper[node].second+=w[node];
		else oper[node].first-=w[node];
	}
    int main(){
        ios_base::sync_with_stdio(false);
        cin.tie(NULL);
		cin>>n;
		tree.assign(n+1,vector<int>());
		oper.assign(n+1,{0,0});
		for(int i=0;i<n-1;i++){
			int a,b;
			cin>>a>>b;
			tree[a].push_back(b),tree[b].push_back(a);
		}
		for(int i=1;i<=n;i++) cin>>w[i];
		dfs(1,-1);
		cout<<oper[1].first+oper[1].second;
    }


    #include <bits/stdc++.h>
    using namespace std;
	int n;
	long long w[100003];
	vector<vector<int>>tree;
	vector<pair<long long,long long>>oper;
	void dfs(int node,int par){
		for(auto i:tree[node]){
			if(i!=par){
				dfs(i,node);
				oper[node].first=max(oper[node].first,oper[i].first);
				oper[node].second+=max(oper[node].second,oper[i].second);
			}
		}
		w[node]+=oper[node].first-oper[node].second;
		if(w[node]>0) oper[node].second+=w[node];
		else oper[node].first-=w[node];
	}
    int main(){
        ios_base::sync_with_stdio(false);
        cin.tie(NULL);
		cin>>n;
		tree.assign(n+1,vector<int>());
		oper.assign(n+1,{0,0});
		for(int i=0;i<n-1;i++){
			int a,b;
			cin>>a>>b;
			tree[a].push_back(b),tree[b].push_back(a);
		}
		for(int i=1;i<=n;i++) cin>>w[i];
		dfs(1,-1);
		cout<<oper[1].first+oper[1].second;
    }


    #include <bits/stdc++.h>
    using namespace std;
	int n;
	long long w[100003];
	vector<vector<int>>tree;
	vector<pair<long long,long long>>oper;
	void dfs(int node,int par){
		for(auto i:tree[node]){
			if(i!=par){
				dfs(i,node);
				oper[node].first=max(oper[node].first,oper[i].first);
				oper[node].second=max(oper[node].second,oper[i].second);
			}
		}
		w[node]+=oper[node].first-oper[node].second;
		if(w[node]>0) oper[node].second+=w[node];
		else oper[node].first-=w[node];
	}
    int main(){
        ios_base::sync_with_stdio(false);
        cin.tie(NULL);
		cin>>n;
		tree.assign(n+1,vector<int>());
		oper.assign(n+1,{0,0});
		for(int i=0;i<n-1;i++){
			int a,b;
			cin>>a>>b;
			tree[a].push_back(b),tree[b].push_back(a);
		}
		for(int i=1;i<=n;i++) cin>>w[i];
		dfs(1,-1);
		cout<<oper[1].first+oper[1].second;
    }


    #include <bits/stdc++.h>
    using namespace std;
	int n;
	long long w[100003];
	vector<vector<int>>tree;
	vector<pair<long long,long long>>oper;
	void dfs(int node,int par){
		for(auto i:tree[node]){
			if(i!=par){
				dfs(i,node);
				oper[node].first+=oper[i].first;
				oper[node].second+=oper[i].second;
			}
		}
		w[node]+=oper[node].first-oper[node].second;
		if(w[node]>0) oper[node].second+=w[node];
		else oper[node].first-=w[node];
	}
    int main(){
        ios_base::sync_with_stdio(false);
        cin.tie(NULL);
		cin>>n;
		tree.assign(n+1,vector<int>());
		oper.assign(n+1,{0,0});
		for(int i=0;i<n-1;i++){
			int a,b;
			cin>>a>>b;
			tree[a].push_back(b),tree[b].push_back(a);
		}
		for(int i=1;i<=n;i++) cin>>w[i];
		dfs(1,-1);
		cout<<oper[1].first+oper[1].second;
    }


// Author :mastermindevil/mdragneell
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;

#define ull unsigned long long
#define ll long long
#define int long long
#define ld long double
#define pb push_back
#define pi  pair< int,int >
#define pl  pair< ll,ll >
#define f first
#define s second
#define endl '\n'

const int mod=998244353;
const int N=1e5+5;

ll fact[N];
ll min(ll x,ll y) { if(x < y) return x; else return y; }
ll max(ll x,ll y) { if(x > y) return x; else return y; }
ll gcd(ll x,ll y) { if(x == 0) return (y>0?y:1); else return gcd(y%x,x);}
ll powmod(ll x,ll y){ll res=1;while(y>0){if(y%2==1)res=(res*x)%mod;y>>=1;if(y<=0)break;x=(x*x)%mod;}return res;}
ll factorial () { fact[0]=1; fact[1]=1; for(int i=2;i<N;i++) fact[i]=(fact[i-1]*i)%mod;}

vector<int>g[N];
int n;
int a[N];
int curr=0;

void dfs(int u,int p)
{
    int x=0,y=0,f=0;

    for(auto to:g[u])
    {
        if(to!=p){
           dfs(to,u);
           x=max(x,a[to]);
           y=min(y,a[to]);
           f=1;
        }
    }

    if(!f){
         a[p]+=a[u];
         curr+=abs(a[u]);
    }
    else
    {
        a[p]+=(x+y);
        curr+=(abs(x)+abs(y));
    }

}

void solve()
{

    cin>>n;
    for(int i=0;i<n-1;i++)
    {
        int x,y;
        cin>>x>>y;

        x--;
        y--;
        g[x].pb(y);
        g[y].pb(x);
    }
    for(int i=0;i<n-1;i++)
        cin>>a[i];

    dfs(0,0);
    cout<<curr+abs(a[0])<<endl;

}

signed main()
{

        ios_base::sync_with_stdio(false);
        cin.tie(NULL);

        #ifndef ONLINE_JUDGE
            freopen("input.txt", "r", stdin);
            freopen("output.txt", "w", stdout);
        #endif

        int tt=1; //cin>>tt;
        while(tt--){
            solve();

        }

}


// Author :mastermindevil/mdragneell
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;

#define ull unsigned long long
#define ll long long
#define int long long
#define ld long double
#define pb push_back
#define pi  pair< int,int >
#define pl  pair< ll,ll >
#define f first
#define s second
#define endl '\n'

const int mod=998244353;
const int N=1e5+5;

ll fact[N];
ll min(ll x,ll y) { if(x < y) return x; else return y; }
ll max(ll x,ll y) { if(x > y) return x; else return y; }
ll gcd(ll x,ll y) { if(x == 0) return (y>0?y:1); else return gcd(y%x,x);}
ll powmod(ll x,ll y){ll res=1;while(y>0){if(y%2==1)res=(res*x)%mod;y>>=1;if(y<=0)break;x=(x*x)%mod;}return res;}
ll factorial () { fact[0]=1; fact[1]=1; for(int i=2;i<N;i++) fact[i]=(fact[i-1]*i)%mod;}

vector<int>g[N];
int n;
int a[N];
int curr=0;

void dfs(int u,int p)
{
    int x=0,y=0,f=0;

    for(auto to:g[u])
    {
        if(to!=p){
           dfs(to,u);

           if(a[to]>0)
                x=max(x,a[to]);

           if(a[to]<0)
                y=min(y,a[to]);
           f=1;
        }
    }

    if(u==0)
        curr+=(abs(x)+abs(y));

    if(!f){
         if(p!=-1){
            a[p]+=a[u];

        }

    }
    else
    {
        if(p!=-1){
            a[p]+=(x+y);

        }

    }

}

void solve()
{

    cin>>n;
    for(int i=0;i<n-1;i++)
    {
        int x,y;
        cin>>x>>y;

        x--;
        y--;
        g[x].pb(y);
        g[y].pb(x);
    }
    for(int i=0;i<n;i++)
        cin>>a[i];

    dfs(0,-1);
    cout<<curr<<endl;

}

signed main()
{

        ios_base::sync_with_stdio(false);
        cin.tie(NULL);

        #ifndef ONLINE_JUDGE
            freopen("input.txt", "r", stdin);
            freopen("output.txt", "w", stdout);
        #endif

        int tt=1; //cin>>tt;
        while(tt--){
            solve();

        }

}


// Author :mastermindevil/mdragneell
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;

#define ull unsigned long long
#define ll long long
#define int  long long
#define ld long double
#define pb push_back
#define pi  pair< int,int >
#define pl  pair< ll,ll >
#define f first
#define s second
#define endl '\n'

const int mod=998244353;
const int N=1e5+5;

ll fact[N];
ll min(ll x,ll y) { if(x < y) return x; else return y; }
ll max(ll x,ll y) { if(x > y) return x; else return y; }
ll gcd(ll x,ll y) { if(x == 0) return (y>0?y:1); else return gcd(y%x,x);}
ll powmod(ll x,ll y){ll res=1;while(y>0){if(y%2==1)res=(res*x)%mod;y>>=1;if(y<=0)break;x=(x*x)%mod;}return res;}
void factorial () { fact[0]=1; fact[1]=1; for(int i=2;i<N;i++) fact[i]=(fact[i-1]*i)%mod;}

vector<vector<int>>g,v;
vector<int>add,sub;

int c[N],n;

void dfs(int u,int p)
{

    int tmx=0,tmin=0;
    add[u]=sub[u]=0;
    for(auto to:g[u])
    {
        if(to!=p){
            dfs(to,u);
            add[u]=max(add[u],add[to]);
            sub[u]=min(sub[u],sub[to]);
        }

    }
    c[u]+=add[u]+sub[u];
    add[u]+=(c[u]<0?abs(c[u]):0);
    sub[u]-=(c[u]>0?c[u]:0);

    return ;

}

void solve()
{

    cin>>n;
    g.resize(n+1);
    v.resize(n+1);
    add.resize(n+1);
    sub.resize(n+1);

    for(int i=0;i<n-1;i++)
    {
        int x,y;
        cin>>x>>y;
        x--,y--;

        g[x].pb(y);
        g[y].pb(x);
    }
    for(int i=0;i<n;i++)
        cin>>c[i];
    dfs(0,0);
    int ans=add[0]+abs(sub[0]);
    cout<<ans<<endl;

}

signed main()
{

        ios_base::sync_with_stdio(false);
        cin.tie(NULL);

        #ifndef ONLINE_JUDGE
            freopen("input.txt", "r", stdin);
            freopen("output.txt", "w", stdout);
        #endif

        int tt=1,tc=1; //cin>>tt;
        while(tt--){

            //cout<<"Case #"<<tc<<": ";
            solve();
            tc++;

        }

}


// Author :mastermindevil/mdragneell
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;

#define ull unsigned long long
#define ll long long
#define int  long long
#define ld long double
#define pb push_back
#define pi  pair< int,int >
#define pl  pair< ll,ll >
#define f first
#define s second
#define endl '\n'

const int mod=998244353;
const int N=1e6+5;

ll fact[N];
ll min(ll x,ll y) { if(x < y) return x; else return y; }
ll max(ll x,ll y) { if(x > y) return x; else return y; }
ll gcd(ll x,ll y) { if(x == 0) return (y>0?y:1); else return gcd(y%x,x);}
ll powmod(ll x,ll y){ll res=1;while(y>0){if(y%2==1)res=(res*x)%mod;y>>=1;if(y<=0)break;x=(x*x)%mod;}return res;}
void factorial () { fact[0]=1; fact[1]=1; for(int i=2;i<N;i++) fact[i]=(fact[i-1]*i)%mod;}

vector<int>g[N];
int n;
int c[N];
vector<int>v[N];

int dfs(int u,int p)
{
    int cr=0;
    for(auto to:g[u])
    {
        if(to!=p)
            cr=max(cr,dfs(to,u));
    }
    v[cr].pb(c[u]);
    return cr+1;
}

void solve()
{

    cin>>n;

    for(int i=0;i<n-1;i++)
    {
        int x,y;
        cin>>x>>y;
        x--,y--;

        g[x].pb(y);
        g[y].pb(x);
    }
    for(int i=0;i<n;i++)
        cin>>c[i];

    int curr=0;
    int upto=dfs(0,0);
    int ans=0;
    int sum=0;

    for(int i=0;i<upto;i++)
    {
        int tmax=0,tmin=0;
        for(auto cc:v[i])
        {
            if(cc+sum>0)
                tmax=max(cc+sum,tmax);
            else if(cc+sum<0)
                tmin=min(tmin,cc+sum);
        }
        ans+=(tmax+abs(tmin));
        sum+=(-1*tmax+abs(tmin));
    }
    cout<<ans<<endl;

}

signed main()
{

        ios_base::sync_with_stdio(false);
        cin.tie(NULL);

        #ifndef ONLINE_JUDGE
            freopen("input.txt", "r", stdin);
            freopen("output.txt", "w", stdout);
        #endif

        int tt=1,tc=1; //cin>>tt;
        while(tt--){

            //cout<<"Case #"<<tc<<": ";
            solve();
            tc++;

        }

}


// Author :mastermindevil/mdragneell
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;

#define ull unsigned long long
#define ll long long
#define int long long
#define ld long double
#define pb push_back
#define pi  pair< int,int >
#define pl  pair< ll,ll >
#define f first
#define s second
#define endl '\n'

const int mod=998244353;
const int N=1e5+5;

ll fact[N];
ll min(ll x,ll y) { if(x < y) return x; else return y; }
ll max(ll x,ll y) { if(x > y) return x; else return y; }
ll gcd(ll x,ll y) { if(x == 0) return (y>0?y:1); else return gcd(y%x,x);}
ll powmod(ll x,ll y){ll res=1;while(y>0){if(y%2==1)res=(res*x)%mod;y>>=1;if(y<=0)break;x=(x*x)%mod;}return res;}
ll factorial () { fact[0]=1; fact[1]=1; for(int i=2;i<N;i++) fact[i]=(fact[i-1]*i)%mod;}

vector<int>g[N];
int n;
int a[N];
int curr=0;

void dfs(int u,int p)
{
    int x=0,y=0,f=0;

    for(auto to:g[u])
    {
        if(to!=p){
           dfs(to,u);

           if(a[to]>0)
                x=max(x,a[to]);

           if(a[to]<0)
                y=min(y,a[to]);
           f=1;
        }
    }

    if(!f){
         if(p!=-1){
            a[p]+=a[u];

        }

    }
    else
    {
        if(p!=-1){
            a[p]+=(x+y);

        }

    }

    if(u==0)
        curr+=(abs(x)+abs(y))+(a[u]);

}

void solve()
{

    cin>>n;
    for(int i=0;i<n-1;i++)
    {
        int x,y;
        cin>>x>>y;

        x--;
        y--;
        g[x].pb(y);
        g[y].pb(x);
    }
    for(int i=0;i<n;i++)
        cin>>a[i];

    dfs(0,-1);
    cout<<curr<<endl;

}

signed main()
{

        ios_base::sync_with_stdio(false);
        cin.tie(NULL);

        #ifndef ONLINE_JUDGE
            freopen("input.txt", "r", stdin);
            freopen("output.txt", "w", stdout);
        #endif

        int tt=1; //cin>>tt;
        while(tt--){
            solve();

        }

}


// Author :mastermindevil/mdragneell
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;

#define ull unsigned long long
#define ll long long
#define int  long long
#define ld long double
#define pb push_back
#define pi  pair< int,int >
#define pl  pair< ll,ll >
#define f first
#define s second
#define endl '\n'

const int mod=998244353;
const int N=1e5+5;

ll fact[N];
ll min(ll x,ll y) { if(x < y) return x; else return y; }
ll max(ll x,ll y) { if(x > y) return x; else return y; }
ll gcd(ll x,ll y) { if(x == 0) return (y>0?y:1); else return gcd(y%x,x);}
ll powmod(ll x,ll y){ll res=1;while(y>0){if(y%2==1)res=(res*x)%mod;y>>=1;if(y<=0)break;x=(x*x)%mod;}return res;}
void factorial () { fact[0]=1; fact[1]=1; for(int i=2;i<N;i++) fact[i]=(fact[i-1]*i)%mod;}

vector<vector<int>>g,v;
int n;
int c[N];

int dfs(int u,int p)
{
    int cr=0;
    for(auto to:g[u])
    {
        if(to!=p)
            cr=max(cr,dfs(to,u));
    }
    v[cr].pb(c[u]);
    return cr+1;
}

void solve()
{

    cin>>n;
    g.resize(n+1);
    v.resize(n+1);
    for(int i=0;i<n-1;i++)
    {
        int x,y;
        cin>>x>>y;
        x--,y--;

        g[x].pb(y);
        g[y].pb(x);
    }
    for(int i=0;i<n;i++)
        cin>>c[i];

    int curr=0;
    int upto=dfs(0,0);
    int ans=0;
    int sum=0;

    for(int i=0;i<n;i++)
    {
        int tmax=0,tmin=0;
        for(auto cc:v[i])
        {
            if(cc+sum>0)
                tmax=max(cc+sum,tmax);
            else if(cc+sum<0)
                tmin=min(tmin,cc+sum);
        }
        ans+=(tmax+abs(tmin));
        sum+=(-1*tmax+abs(tmin));
    }
    cout<<ans<<endl;

}

signed main()
{

        ios_base::sync_with_stdio(false);
        cin.tie(NULL);

        #ifndef ONLINE_JUDGE
            freopen("input.txt", "r", stdin);
            freopen("output.txt", "w", stdout);
        #endif

        int tt=1,tc=1; //cin>>tt;
        while(tt--){

            //cout<<"Case #"<<tc<<": ";
            solve();
            tc++;

        }

}