import java.util.*;
import java.awt.*;
import javax.swing.*;
import java.util.*;
import javax.swing.JOptionPane;

class intset
{   
	int x[];    
	public intset(int n)
    {   x=new int[n];        
        fill(n);
    }
    
    void fill(int n)
    {ArrayList<Integer> v1=new ArrayList<Integer>();
        for(int i=0;i<n;i++) {v1.add(i);}
        Collections.shuffle(v1);
        Iterator i=v1.iterator();
        int j=0;
        while(i.hasNext()) {x[j]=(Integer)i.next();j++;}
    }

    void change(int j,int k)
    {   
	    int n=x.length;
	    int y[]=new int[n];
	    int wj=0;
	    int wk=0;
        for(int i=0;i<n;i++) 
        {  if(i==j) {wj=x[i];}
           else if(i==k) {wk=x[i];}
           else {y[i]=x[i];}
        }
        y[j]=wk;
        y[k]=wj;
        for(int i=0;i<n;i++) {x[i]=y[i];}
    }
    
    void mutate()
    {
	int n=x.length;
	int j=(int)(n*(Math.random()+0.0001));
	int k=(int)(n*(Math.random()+0.0001));
	change(j,k);
	}
	
    public void cross(int j,intset father,intset mother)
    {ArrayList<Integer> vF=new ArrayList<Integer>();    
     int n=father.x.length;
     ArrayList<Integer> vM=new ArrayList<Integer>();
     ArrayList<Integer> vB=new ArrayList<Integer>();
     for(int i=0;i<j;i++) {vB.add(father.x[i]);}
     for(int i=j;i<n;i++) {vM.add(mother.x[i]);}
     for(int i=0;i<j;i++) {vM.add(mother.x[i]);}
     Iterator n2=vM.iterator();
     while(n2.hasNext())
        {
            int nn=(Integer)n2.next();
            if(!vB.contains(nn))  vB.add(nn);
        }
     Iterator i=vB.iterator();
     j=0;
     while(i.hasNext()) {x[j]=(Integer)i.next();j++;}         
     }
     
     public void cross(intset father,intset mother)
     {int n=father.x.length;
	  int j=(int)(n*(Math.random()+0.0001));
      if(Math.random()<=0.5) cross(j,father,mother);
     else cross(j,mother,father);
     }
}