#include <vector>
#include <string>
#include <iostream>

using namespace std;

void restoreIpAddresses(string &s, string &ip, int pos, int segIndex, vector<string> &result) {
    if (segIndex > 4) {
        if (s.length() == pos) {
            ip.erase(ip.size()-1);
            result.push_back(ip);
        }
        return;
    }

    size_t size = ip.size();
    
    int seg = 0;
    for (int i = 0; i < 3 && pos < s.length(); ++i, ++pos) {
        seg = seg*10 + (s[pos] - '0');
        if (seg >= 256) break;
        
        ip.push_back(s[pos]);
        ip.push_back('.');
        restoreIpAddresses(s, ip, pos+1, segIndex+1, result);
        ip.erase(ip.size()-1);
        
        if (seg == 0) break;
    }
    
    ip.erase(size);
}


vector<string> restoreIpAddresses(string s) {
    vector<string> result;
    vector<size_t> indics;
    string ip = "";
    restoreIpAddresses(s, ip, 0, 1, result);
    
    return result;
}

ostream &operator<<(ostream &out, const vector<string> &v) {
    
    for (int i = 0; i < v.size(); ++i) {
        cout<< v[i] << ", ";
    }
    
    cout << endl;
    return out;
}

int main (int argc, const char * argv[]) {
    
    cout << restoreIpAddresses("010010") << endl;
    cout << restoreIpAddresses("10101010") << endl;
    cout << restoreIpAddresses("123123123") << endl;
    
    return 0;
}