#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
#include <string>
#include <vector>
#include <utility>
#include <algorithm>
#include <sstream>

using std::string;
using std::vector;
using std::pair;
using std::make_pair;
using std::random_shuffle;
using std::ostringstream;

string randomKeyword() {
    string rv;
    for (int i = 0; i < 30; i++) {
        rv += (char) ('a' + rand() % 26);
    }
    return rv;
}

string randomSite() {
    string rv = "rwhrharhtjsrtiwtk.isrtj/srtis/tjk.srtisrtk/syk.sgk/tyk.stks/tks.rykdy/ksr.tyksrt/ksrt.jkrf";
    for (int i = 90; i < 100; i++) {
        rv += (char) ('a' + rand() % 26);
        switch (rand() % 10) {
            case 0:
                rv[i] = '/';
                break;
            case 1:
                rv[i] = '.';
                break;
        }
    }
    return rv;
}

int n = 0;

ostringstream output;

void add(const string &keyword, const string &site) {
    output << "Add keyword \"" << keyword << "\" to " << site << std::endl;
    n++;
    assert(n <= 2000);
}

void rem(const string &keyword, const string &site) {
    output << "Remove keyword \"" << keyword << "\" from " << site << std::endl;
    n++;
    assert(n <= 2000);
}

void search(const string &keyword) {
    output << "Search \"" << keyword << "\"" << std::endl;
    n++;
    assert(n <= 2000);
}

void flush() {
    printf("%d\n", n);
    printf("%s", output.str().c_str());
}

int main(int argc, char **argv) {
    srand(atoi(argv[1]));
    int i;
    string kwd1 = randomKeyword();
    string kwd2 = randomKeyword();

    for (i = 0; i < 9; i++) {
        add(kwd1, randomSite());
    }
    search(kwd1);
    string site00 = randomSite();
    add(kwd1, site00);
    search(kwd1);
    add(kwd1, randomSite());
    search(kwd1);
    rem(kwd1, site00);
    search(kwd1);

    vector<string> sites;
    for (i = 0; i < 1000; i++) {
        string site = randomSite();
        add(kwd2, site);
        if (rand() % 2) sites.push_back(site);
    }
    search(kwd2);
    search(kwd1);
    for (i = 0; i < sites.size(); i++) {
        rem(rand() % 2 ? kwd1 : kwd2, sites[i]);    
    }
    search(kwd1);
    search(kwd2);

    flush();

    return 0;    
}
