String[] fileNaming(String[] names) {
    List<String> nm = new ArrayList<String>();
    Set<String> s = new HashSet<String>();
    
    for(String str: names){
        String temp = str;
        int t = 0;
        if(!s.contains(temp))
            s.add(temp);
        else
            while(true){
                if(!s.contains(str + "(" + Integer.toString(++t) +")")){
                    s.add(str + "(" + Integer.toString(t) +")");
                    temp = str + "(" + Integer.toString(t) +")";
                    break;
                }
                else
                   temp = str + "(" + Integer.toString(t) +")";
            }
        nm.add(temp);
    }
    String[] uniquenames = nm.toArray(new String[0]);
    return uniquenames;
}
