#include <fstream>
#include <string>
#include <vector>

int main()
{
  std::ifstream infile("list.txt");
  std::ofstream outfile("nodup.txt", std::ios::out | std::ios::binary);
  constexpr int NofFixedColumns = 3;

  std::string line;
  std::vector<std::string_view> known;

  while (std::getline(infile, line))
  {
    auto it_start = line.cbegin();
    int columnCount = 0;

    known.clear();

    for(auto it_cur = it_start; it_cur != line.cend(); ++it_cur)
    {
      if(*it_cur == ';')
      {
        std::string_view column(&*it_start, std::distance(it_start, it_cur));
        if(columnCount++ < NofFixedColumns)
        {
          outfile.write(column.data(), column.length());
        }
        else
        {
          if(std::find(known.cbegin(), known.cend(), column) == known.cend())
          {
            outfile.write(column.data(), column.length());
            known.emplace_back(column);
          }
        }
        outfile.put(';');
        it_start = it_cur + 1;
      }
    }
    outfile.put('\n');
  }
}
