#include <vector>
#include <string>
#include <cstdio>
#include <cstdlib>

using namespace std;

struct coder {
string handle;
double score;
vector<string> vs;
};

int findCoder(string handle, vector<coder> &vc) {
	int i;
	for (i = 0; i < vc.size(); i++) if (vc[i].handle == handle) break;
	if (i == vc.size()) {
		coder c;
		c.handle = handle;
		vc.push_back(c);
	}
	return i;
}

int readScores(string html, vector<coder> &vc) {
	int pos = html.find("MemberProfile"), epos;
	pos = html.find("MemberProfile", pos+1);
	while (pos != string::npos) {
		char sz[100];
		sscanf(html.c_str()+pos, "%*[^>]> %99[^<]", sz);
		int idx = findCoder(sz, vc);
		pos = html.find("statLink", pos);
		if (pos == string::npos) break;
		double dbl;
		sscanf(html.c_str()+pos, "statLink\"> %lf", &dbl);
		vc[idx].score = dbl;
		int spos = html.find("<td", pos);
		epos = html.find("</tr>", pos);

		while (spos != string::npos && spos < epos) {
			sscanf(html.c_str()+spos, "%*[^>]> %99[^<]", sz);
			vc[idx].vs.push_back(sz);
			spos = html.find("<td", spos+1);
		}
		pos = html.find("MemberProfile", epos);
	}
	/* find next column */
	pos = html.find("\"scrollRight\"");
	epos = html.find("</td>", pos);
	if (pos != string::npos) {
		pos = html.find("&stc=", pos);
		if (pos == string::npos || pos > epos)
			pos = -1;
		else {
			int ct = sscanf(html.c_str()+pos, "&stc=%d", &pos);
			if (ct < 1) pos = -1;
		}
	} else
		pos = -1;
	printf("%d ", pos);

	/* find next row */
	pos = html.find("\"scrollDown\"");
	epos = html.find("</td>", pos);
	if (pos != string::npos) {
		pos = html.find("&sr=", pos);
		if (pos == string::npos || pos > epos)
			pos = -1;
		else {
			int ct = sscanf(html.c_str()+pos, "&sr=%d", &pos);
			if (ct < 1) pos = -1;
		}
	} else
		pos = -1;
	printf("%d", pos);

	return 0;
}

vector<string> stokens(string s, string sep = ",\n") {
	vector<string> res;
	int start, end = 0;
	while ((start = s.find_first_not_of(sep, end)) != string::npos) {
		end = s.find_first_of(sep, start);
		res.push_back(s.substr(start, end-start));
	}
	return res;
}

void parseCSV(const string &s, vector<coder> &vc) {
	vector<string> vs = stokens(s);
	coder c;
	c.handle = vs[0];
	c.score = atof(vs[1].c_str());
	c.vs.insert(c.vs.end(), vs.begin()+2, vs.end());
	vc.push_back(c);
}

void readCSV(char *fn, vector<coder> &vc) {
	char sz[100000];
	FILE *fh = fopen(fn, "r");
	if (!fh) return;
	string s;
	while (fgets(sz, 100000, fh)) {
		s += sz;
		if (!s.empty() && s[s.size()-1] == '\n') {
			parseCSV(s, vc);
			s.clear();
		}
	}
	if (!s.empty()) parseCSV(s, vc);
	fclose(fh);
}

void writeCSV(char *fn, vector<coder> &vc) {
	FILE *fh = fopen(fn, "w");
	if (!fh) return;
	for (int i = 0; i < vc.size(); i++) {
		fprintf(fh, "%s,%.2f", vc[i].handle.c_str(), vc[i].score);
		for (int j = 0; j < vc[i].vs.size(); j++)
			fprintf(fh, ",%s", vc[i].vs[j].c_str());
		fputc('\n', fh);
	}
	fclose(fh);
}

int main(int argc, char **argv) {
	if (argc < 2) {
		fprintf(stderr, "usage: parseScores CSV-file\n\n");
		return 101;
	}
	if (argv[1][0] == '-') {
		printf("usage: parseScores CSV-file\n\n");
		return 0;
	}
	vector<coder> vc;
	readCSV(argv[1], vc);

	string html;
	char sz[1000];
	while (fgets(sz, 1000, stdin)) html += sz;

	int res = readScores(html, vc);
	writeCSV(argv[1], vc);
	return res;
}


