#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 column = 0;

        known.clear();

        for(auto it_cur = it_start; it_cur != line.cend(); ++it_cur)
        {
            if(*it_cur == ';')
            {
                if(column++ < NofFixedColumns)
                {
                    outfile.write(&*it_start, std::distance(it_start, it_cur));
                }
                else
                {
                    std::string_view column(it_start, it_cur);
                    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');
    }
}
