public static void main(String[] args){
		
		Set<Integer> amicable = new HashSet<Integer>();
		int[] div = new int[10000];
		
		for (int i=1;i<10000;i++){
			div[i] = sumOfDivs(i);
		}
		for (int i=1;i<10000;i++){
			for (int j=1;j<10000;j++){
				if (i==j) continue;
				if (div[i]==j && div[j]==i){
					amicable.add(i);
					amicable.add(j);
				}
			}
		}
		int sum=0;
		for(Integer n : amicable){
			System.out.println(n);
			sum+=n;
		}
		System.out.println(sum);
	}