import java.util.Random;

class TransferData extends Thread 
{
	private int[] data = null;
	private int i, j;
	public TransferData(int[] a, int type) 
	{
		data = a;
		if(type == 1) 
		{
			i = 0;
			j = 1;
		}else 
		{
			i = 1;
			j = 0;
		}
	}
	
	public void run() 
	{
		Random rand = new Random();
		while(true) 
		{
			int x = rand.nextInt(10)+1;
			data[i] -= x;
			data[j] += x;
			try 
			{
				Thread.sleep(rand.nextInt(5)+1);
			} catch (InterruptedException e)
			{	
			}
		}
	}
}

public class CheckDataError10_3 
{
	public static void main(String[] args) throws Exception 
	{
		int[] a = {4000, 4000};
		new TransferData(a, 1).start();
		new TransferData(a, 2).start();
		for(int i=1; i<=Integer.MAX_VALUE; i++)
		{
			System.out.println(i+": a[0] + a[1] = " + (a[0]+a[1]));
			Thread.sleep(500);
		}
	}
}