class Solution {
public:
string validIPAddress(string IP) {
istringstream is(IP);
string s = "";
int cnt = 0;
if(IP.find(".")!=string::npos){ //IPv4
if(IP.back()=='.') return "Neither";
while(getline(is, s, '.')){
cnt++;
for(char a:s){ //all digits
if(a<'0' || a>'9') return "Neither";
}
int t = atoi(s.c_str());
if(t>255 || t<0 || s.size()!=to_string(t).size()) return "Neither";
}
if(cnt==4) return "IPv4";
}else{ //IPv6
if(IP.back()==':') return "Neither";
while(getline(is, s, ':')){
if(s.empty()) return "Neither";
cnt++;
for(char a:s){
if(!((a>='0' && a<='9')||(a>='a' && a<='f')||(a>='A' && a<='F'))) return "Neither";
}
if(s.size()>4) return "Neither";
}
if(cnt==8) return "IPv6";
}
return "Neither";
}
bool isvalid6(string s){
return true;
}
};