Problem:
Score : 100 points

Problem Statement

There are N students in a school.

We will divide these students into some groups, and in each group they will discuss some themes.

You think that groups consisting of two or less students cannot have an effective discussion, so you want to have as many groups consisting of three or more students as possible.

Divide the students so that the number of groups consisting of three or more students is maximized.

Constraints

1 \leq N \leq 1000

All input values are integers.

Input

Input is given from Standard Input in the following format:

N

Output

If you can form at most x groups consisting of three or more students, print x.

Sample Input 1

8

Sample Output 1

2

For example, you can form a group of three students and another of five students.

Sample Input 2

2

Sample Output 2

0

Sometimes you cannot form any group consisting of three or more students, regardless of how you divide the students.

Sample Input 3

9

Sample Output 3

3

Solution in C# (Mono 4.6.2.0) (judge verdict: Runtime Error)

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

namespace AtCoder_ABC089_A
{
    class Program
    {
        static void Main(string[] args)
        {
            KeyValuePair<int, int>[] _a;

            int h;
            int w;

            string[] hwd = Console.ReadLine().Split(' ');
            h = int.Parse(hwd[0]);
            w = int.Parse(hwd[1]);
            int d = int.Parse(hwd[2]);

            _a = new KeyValuePair<int, int>[h * w];
            //a = new int[h, w];
            for (int i = 0; i < h; ++i)
            {
                string[] tmp = Console.ReadLine().Split(' ');
                for (int j = 0; j < w; ++j)
                {
                    _a[int.Parse(tmp[j])-1] = new KeyValuePair<int, int>(i, j);
                }
            }

            int q = int.Parse(Console.ReadLine());

            int[] l = new int[q];
            int[] r = new int[q];

            for (int i = 0; i < q; ++i)
            {
                string[] tmp = Console.ReadLine().Split(' ');
                l[i] = int.Parse(tmp[0]);
                r[i] = int.Parse(tmp[1]);
            }


            for (int q_ = 0; q_ < q; ++q_)
            {
                int magic = 0;
                int number = l[q_];
                int row = 0;
                int column = 0;

                {
                    var kvp = _a[number - 1];
                    row = kvp.Key;
                    column = kvp.Value;
                }

                while (number != r[q_])
                {
                    number += d;

                    int row2, column2;
                    {
                        var kvp = _a[number - 1];
                        row2 = kvp.Key;
                        column2 = kvp.Value;
                    }

                    magic += Math.Abs(row - row2) + Math.Abs(column - column2);

                    row = row2;
                    column = column2;
                }

                Console.WriteLine(magic);
            }
        }
    }
}