using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;

const int NofFixedColumns = 3;

using var infile = new FileStream("list.txt", FileMode.Open, FileAccess.Read);
using var reader = new StreamReader(infile, Encoding.ASCII);

using var outfile = new FileStream("nodup.txt", FileMode.Create, FileAccess.Write);
using var writer = new StreamWriter(outfile, Encoding.ASCII);

writer.NewLine = "\n";

var known = new Dictionary<string, int>();

while (reader.ReadLine() is string line)
{
    var columns = line.Split(';');

    known.Clear();

    foreach (var column in columns.Take(NofFixedColumns))
    {
        writer.Write(column);
        writer.Write(';');
    }

    foreach (var column in columns.Skip(NofFixedColumns).SkipLast(1))
    {
        if (known.TryAdd(column, 0))
        {
            writer.Write(column);
        }
        writer.Write(';');
    }

    writer.WriteLine();
}
