public ArrayList<String> restoreIpAddresses(String s) {
    	ArrayList<String>rel=new ArrayList<>();
    	if (s.length()>12) return rel;
    	int n=s.length();
    	for (int i1=1;i1<n-2;++i1) 
    		for (int i2=i1+1;i2<n-1;++i2)
    			for (int i3=i2+1;i3<n;++i3) {
    				String[]ip=new String[4];
    				ip[0]=s.substring(0,i1);ip[1]=s.substring(i1,i2);ip[2]=s.substring(i2,i3);ip[3]=s.substring(i3);
    				if (validateIP(ip[0])&&validateIP(ip[1])&&validateIP(ip[2])&&validateIP(ip[3]))
    						rel.add(ip[0]+"."+ip[1]+"."+ip[2]+"."+ip[3]);
    			}
    	return rel;
    }