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

public class PurgeDupes
{
	public static void main( String args[] ) throws Exception
	{
		if ( args.length < 2 )
			die( "FATAL ERROR: must enter two filenames on command line.\n");

		//  READ IN BOTH SETS INTO PLAIN ARRAYS Of STRING 
		String[] list1 = new String[1];
		String[] list2 = new String[1];
		int count1=0,count2=0;
		Scanner infile = new Scanner( new File(args[0]) );

		while (infile.hasNext())
		{		if (count1==list1.length)
					list1=upSize(list1);
				list1[count1++]=infile.next();
		}
		infile.close();


		infile = new Scanner( new File(args[1]) );
		while (infile.hasNext())
		{		if (count2==list2.length)
					list2=upSize(list2);
				list2[count2++]=infile.next();
		}
		infile.close();

		list1 = trim( list1, count1 ); // trim off the extra blank cells at end
		printList( "original list1: ", list1 );
		count1 = purgeDupes( list1 );  // returns the number of unique elements remaining after purging dulicates
		list1 = trim( list1, count1 ); // trim off the dupes stuff at end
		printList( "purged list1:   ", list1 );

		list2 = trim( list2, count2 ); // trim off the extra blank cells at end
		printList( "original list2: ", list2 );
		count2 = purgeDupes( list2 );  // returns the number of unique elements remaining after purging dulicates
		list2 = trim( list2, count2 ); // trim off the dupes stuff at end
		printList( "purged list2:   ", list2 );

	} // END MAIN

	static void die( String errMsg )
	{
		System.out.println( errMsg );
		System.exit(0); // kills program
	}
	static void printList( String caption, String[] list )
	{	System.out.print( caption );
		for( String word : list )
			System.out.print( word + " " );
		System.out.println();
	}
	static String[] upSize( String[] arr )
	{
		String[] doubleSized = new String[arr.length*2];
		for ( int i=0 ; i < arr.length ; ++i )
			doubleSized[i] = arr[i];
		return doubleSized; // just to make it compile
	}

	static String[] trim( String[] arr, int count )
	{  	String[] trimmedArr = new String[count];
		for ( int i=0 ; i < count ; ++i )
			trimmedArr[i] = arr[i];
		return trimmedArr; // just to make it compile
	}

	// # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
	// Y  O  U     F  I  L  L    I  N     T  H  I  S     M E  T  H  O  D    B  E  L  O  W
	// # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #

	// AFTER PURGING THE DUPES RETURN THE NEW COUNT OF UNIQE ELEMENTS
	static int purgeDupes( String[] list )
	{   
		if ( list.length<=1 ) return list.length;
		int i=0, j=1;
		while ( i < list.length-1 ) 
		{ 	while (j<list.length && list[j].equals(list[i]))
			{	++j;
				if (j==list.length) return i+1;
			}
			list[i+1]=list[j];
			++i;
		}
		return i+1; 
	}
} // EOF