
class A {
	
	protected int x;
	
	public A() {
		x = 2;
	}
	
	public A(int a) {
		x = a;
	}
	
	public void f(A a) {
		System.out.println("1");
		x = a.x + x;
	}
	
	public void f(B b) {
		System.out.println("2");
		x = x + b.x + b.y;
	}
	
	public String toString() {
		return "("+x+")";
	}
}

class B extends A {
	
	protected int y;
	
	public B(int a) {
		y = a;
	}
	
	public void f(A a) {
		System.out.println("3");
		y = a.x + x + y;
	}
	
	public void f(B b) {
		System.out.println("4");
		x = b.x + x;
		y = b.y + y;
	}
	
	public String toString() {
		return "("+x+","+y+")";
	}
}

public class C extends B {
	
	private int z;
	
	public C(int a, int b, int c) {
		super(a);
		z = c;
	}
	
	public void f(A a) {
		System.out.println("5");
		z = z + a.x;
	}
	
	public void f(C c) {
		System.out.println("6");
		x = x + c.x;
		y = y + c.y;
		z = z + c.z;
	}
	
	public String toString() {
		return "("+x+","+y+","+z+")";
	}
	
	public static void main(String[] args) {
		
		A one = new A();
		A two = new B(4);
		B three = new B(7);
		B four = new C(8,1,3);
		C five = new C(2,6,9);
		C six = new C(5,4,6);
		
		one.f(two);
		one.f(four);
		two.f(three);
		four.f(five);
		six.f(five);
		
		System.out.println(one);
		System.out.println(two);
		System.out.println(three);
		System.out.println(four);
		System.out.println(five);
		System.out.println(six);
		
	}
}

