#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iterator>
#include <set>
#include <map>

const int MAX_BUFFER = 0x1000;

using namespace std;

void process_data(map<int,set<int>> &documents) {
  fprintf(stderr, "Processing data\n");
  for (auto it1 = documents.begin(); it1 != documents.end(); it1++) {
    for (auto it2 = documents.begin(); it2 != documents.end(); it2++) {
      if (it1->first >= it2->first) {
        continue;
      }

      set<int> union_set;
      set<int> intersection_set;

      for (auto el = it1->second.begin(); el != it1->second.end(); el++) {
        union_set.insert(*el);
        if (auto search = it2->second.find(*el); search != it2->second.end()) {
          intersection_set.insert(*el);
        }
      }

      for (auto el = it2->second.begin(); el != it2->second.end(); el++) {
        union_set.insert(*el);
      }

      auto common_count = intersection_set.size();
      auto union_count = union_set.size();

      if (common_count) {
        
        fprintf(stderr, "Documents %d and %d have %.2f sparse\n",
            it1->first, it2->first, (double)common_count / (double)union_count);
      }
    }
  }
}

void process_input(map<int,set<int>> &documents, char *buffer) {
  char *it = buffer;
  set<int> items;

  int doc_id = atoi(it);
  fprintf(stderr, "Got document id: %d\n", doc_id);

  while (*it && *it != '{') {
    it++;
  }

  ++it;
  
  do {
    auto nr = atoi(it);
    fprintf(stderr, "Got number: %d\n", nr);
    items.insert(nr);
    while (*it && *it != ',' && *it != '}') {
      ++it;
    }

    if (*it == '}') {
      break;
    }

    ++it;

  } while(true);

  fprintf(stderr, "The set contains %d elements\n", items.size());

  documents[doc_id] = items;
}

int main() {
  char buffer[MAX_BUFFER];
  map<int, set<int>> documents;
  fprintf(stderr, "Provide input: \n");
  while(1) {
    if (!fgets(buffer, MAX_BUFFER, stdin)) {
      fprintf(stderr, "End of file or error\n");
      break;
    }

    if (strlen(buffer) <= 0 || buffer[0] == '\n') {
      break;
    }

    process_input(documents, buffer);
  }

  process_data(documents);
  fprintf(stderr, "Execution finished\n");
	return 0;
}
