Language: C++

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

namespace Program
{
    interface Output
    {
        void Write(object str);
        void WriteLine(object str);
    }

    interface Input
    {
        int NextInt();
        string NextString();
    }

    class Console_ : Input, Output
    {
        Queue<string> param = new Queue<string>();
        int Input.NextInt()
        {
            if (param.Count == 0)
            {
                foreach (var item in Console.ReadLine().Split(' '))
                {
                    param.Enqueue(item);
                }
            }
            return int.Parse(param.Dequeue());
        }
        string Input.NextString()
        {
            if (param.Count == 0)
            {
                foreach (var item in Console.ReadLine().Split(' '))
                {
                    param.Enqueue(item);
                }
            }
            return param.Dequeue();
        }
        void Output.Write(object str)
        {
            System.Console.Write(str.ToString());
        }
        void Output.WriteLine(object str)
        {
            System.Console.WriteLine(str.ToString());
        }
    }

    class Program
    {
        static void Main(string[] args)
        {
            new Solver(new Console_(), new Console_()).Run();
        }
    }

    class Debug_ : Input
    {
        int i = 0;
        int Input.NextInt()
        {
            return (int)data[i++];
        }
        string Input.NextString()
        {
            return (string)data[i++];
        }
        object[] data =
        {
            15,
            "######...#.#...#...#"
        };
    }

    class Solver
    {
        Input input;
        Output output;
        public Solver(Input input, Output output)
        {
            this.input = input;
            this.output = output;
        }

        public void Run()
        {
            var N = input.NextInt();
            var S = input.NextString().Select(e => e == '.' ? false : true).ToArray();
            var list = new List<int>();
            int firstIdx = 0;
            for (int i = firstIdx; i < S.Length; ++i)
            {
                if (S[i])
                {
                    firstIdx = i;
                    break;
                }
            }
            bool before = true;
            int sumtmp = 0;
            for (int i = firstIdx; i < S.Length; ++i)
            {
                if (S[i] ^ before)
                {
                    list.Add(sumtmp);
                    sumtmp = 1;
                    before = !before;
                }
                else
                {
                    // same
                    ++sumtmp;
                }
            }
            list.Add(sumtmp);

            int sum = 0;
            for (int i = 0; i < list.Count - 1; i += 2)
            {
                int res1 = list[i];
                int res2 = list[i + 1];
                if (list[i] <= list[i + 1])
                {
                    sum += res1;
                    continue;
                }

                if (i + 3 < list.Count)
                {
                    int sum1 = res1;
                    int sum2 = res2;
                    for (int j = i + 2; j < list.Count - 1; j += 2)
                    {
                        sum1 += list[j];
                        sum2 += list[j + 1];
                    }
                    if (sum1 <= sum2)
                    {
                        sum += res1;
                        continue;
                    }
                }

                if (i + 2 < list.Count)
                {
                    list[i + 2] = list[i] + list[i + 1];
                    sum += res2;
                }
                else
                {
                    sum += Math.Min(res1, res2);
                }
            }

            output.WriteLine(sum);
        }

    }
}


Compiler output:
a.cc:1:7: error: expected nested-name-specifier before 'System'
    1 | using System;
      |       ^~~~~~
a.cc:2:7: error: expected nested-name-specifier before 'System'
    2 | using System.Linq;
      |       ^~~~~~
a.cc:3:7: error: expected nested-name-specifier before 'System'
    3 | using System.Collections.Generic;
      |       ^~~~~~
a.cc:4:7: error: expected nested-name-specifier before 'System'
    4 | using System.Text;
      |       ^~~~~~
a.cc:8:5: error: 'interface' does not name a type
    8 |     interface Output
      |     ^~~~~~~~~
a.cc:14:5: error: 'interface' does not name a type
   14 |     interface Input
      |     ^~~~~~~~~
a.cc:20:27: error: expected class-name before ',' token
   20 |     class Console_ : Input, Output
      |                           ^
a.cc:21:5: error: expected class-name before '{' token
   21 |     {
      |     ^
a.cc:22:9: error: 'Queue' does not name a type
   22 |         Queue<string> param = new Queue<string>();
      |         ^~~~~
a.cc:23:13: error: expected ';' at end of member declaration
   23 |         int Input.NextInt()
      |             ^~~~~
      |                  ;
a.cc:23:18: error: expected unqualified-id before '.' token
   23 |         int Input.NextInt()
      |                  ^
a.cc:34:9: error: 'string' does not name a type
   34 |         string Input.NextString()
      |         ^~~~~~
a.cc:45:14: error: variable or field 'Output' declared void
   45 |         void Output.Write(object str)
      |              ^~~~~~
a.cc:45:14: error: expected ';' at end of member declaration
   45 |         void Output.Write(object str)
      |              ^~~~~~
      |                    ;
a.cc:45:20: error: expected unqualified-id before '.' token
   45 |         void Output.Write(object str)
      |                    ^
a.cc:49:14: error: variable or field 'Output' declared void
   49 |         void Output.WriteLine(object str)
      |              ^~~~~~
a.cc:49:14: error: expected ';' at end of member declaration
   49 |         void Output.WriteLine(object str)
      |              ^~~~~~
      |                    ;
a.cc:49:20: error: expected unqualified-id before '.' token
   49 |         void Output.WriteLine(object str)
      |                    ^
a.cc:53:6: error: expected ';' after class definition
   53 |     }
      |      ^
      |      ;
a.cc:57:26: error: 'string' has not been declared
   57 |         static void Main(string[] args)
      |                          ^~~~~~
a.cc:57:35: error: expected ',' or '...' before 'args'
   57 |         static void Main(string[] args)
      |                                   ^~~~
a.cc:61:6: error: expected ';' after class definition
   61 |     }
      |      ^
      |      ;
a.cc: In static member function 'static void Program::Program::Main(int*)':
a.cc:59:17: error: expected type-specifier before 'Solver'
   59 |             new Solver(new Console_(), new Console_()).Run();
      |                 ^~~~~~
a.cc: At global scope:
a.cc:64:5: error: expected class-name before '{' token
   64 |     {
      |     ^
a.cc:66:13: error: expected ';' at end of member declaration
   66 |         int Input.NextInt()
      |             ^~~~~
      |                  ;
a.cc:66:18: error: expected unqualified-id before '.' token
   66 |         int Input.NextInt()
      |                  ^
a.cc:70:9: error: 'string' does not name a type
   70 |         string Input.NextString()
      |         ^~~~~~
a.cc:74:9: error: 'object' does not name a type
   74 |         object[] data =
      |         ^~~~~~
a.cc:79:6: error: expected ';' after class definition
   79 |     }
      |      ^
      |      ;
a.cc:83:9: error: 'Input' does not name a type
   83 |         Input input;
      |         ^~~~~
a.cc:84:9: error: 'Output' does not name a type
   84 |         Output output;
      |         ^~~~~~
a.cc:85:15: error: expected ':' before 'Solver'
   85 |         public Solver(Input input, Output output)
      |               ^~~~~~~
      |               :
a.cc:85:28: error: expected ')' before 'input'
   85 |         public Solver(Input input, Output output)
      |                      ~     ^~~~~~
      |                            )
a.cc:91:15: error: expected ':' before 'void'
   91 |         public void Run()
      |               ^~~~~
      |               :
a.cc:164:6: error: expected ';' after class definition
  164 |     }
      |      ^
      |      ;
a.cc: In member function 'void Program::Solver::Run()':
a.cc:93:13: error: 'var' was not declared in this scope
   93 |             var N = input.NextInt();
      |             ^~~
a.cc:94:17: error: expected ';' before 'S'
   94 |             var S = input.NextString().Select(e => e == '.' ? false : true).ToArray();
      |                 ^
a.cc:95:17: error: expected ';' before 'list'
   95 |             var list = new List<int>();
      |                 ^~~~
a.cc:97:40: error: 'S' was not declared in this scope
   97 |             for (int i = firstIdx; i < S.Length; ++i)
      |                                        ^
a.cc:107:40: error: 'S' was not declared in this scope
  107 |             for (int i = firstIdx; i < S.Length; ++i)
      |                                        ^
a.cc:111:21: error: 'list' was not declared in this scope
  111 |                     list.Add(sumtmp);
      |                     ^~~~
a.cc:121:13: error: 'list' was not declared in this scope
  121 |             list.Add(sumtmp);
      |             ^~~~
a.cc:157:28: error: 'Math' was not declared in this scope
  157 |                     sum += Math.Min(res1, res2);
      |                            ^~~~
a.cc:161:13: error: 'output' was not declared in this scope
  161 |             output.WriteLine(sum);
      |             ^~~~~~