Problem:
Score : 100 points

Problem Statement

Takahashi is distributing N balls to K persons.

If each person has to receive at least one ball, what is the maximum possible difference in the number of balls received between the person with the most balls and the person with the fewest balls?

Constraints

1 \leq K \leq N \leq 100

All values in input are integers.

Input

Input is given from Standard Input in the following format:

N K

Output

Print the maximum possible difference in the number of balls received.

Sample Input 1

3 2

Sample Output 1

1

The only way to distribute three balls to two persons so that each of them receives at least one ball is to give one ball to one person and give two balls to the other person.

Thus, the maximum possible difference in the number of balls received is 1.

Sample Input 2

3 1

Sample Output 2

0

We have no choice but to give three balls to the only person, in which case the difference in the number of balls received is 0.

Sample Input 3

8 5

Sample Output 3

3

For example, if we give 1, 4, 1, 1, 1 balls to the five persons, the number of balls received between the person with the most balls and the person with the fewest balls would be 3, which is the maximum result.

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

using System;
using System.Collections.Generic;

namespace ConsoleApp2
{
	class Program
	{
		static void Main(string[] args)
		{
			int n = int.Parse(Console.ReadLine());
			var list = new List<Coordinate>(n);

			for (int i = 0; i < n; i++)
			{
				var inputs = Console.ReadLine().Split(' ');
				list.Add(new Coordinate(int.Parse(inputs[0]), int.Parse(inputs[1])));
			}
			list.Sort((a, b) => a.mX - b.mX);

			var dic = new Dictionary<Diff, int>();
			for(int i = 0; i < n - 1; i++)
			{
				for (int j = i + 1; j < n; j++)
				{
					var diff = new Diff(list[i], list[j]);
					if (dic.ContainsKey(diff))
					{
						dic[diff]++;
					}
					else
					{
						dic.Add(diff, 1);
					}
				}
			}
			int sameDiff = 0;
			foreach(var val in dic.Values)
			{
				sameDiff = Math.Max(sameDiff, val);
			}
			// コスト0で回収できる回数
			int zeroCostCount = sameDiff;

			int cost = 1 + (n - 1 - zeroCostCount);

			Console.WriteLine(cost);
		}

		public class Coordinate
		{
			public int mX;
			public int mY;

			public Coordinate(int x, int y)
			{
				mX = x;
				mY = y;
			}
		}

		public struct Diff
		{
			public int mDiffX;
			public int mDiffY;

			public Diff(Coordinate a, Coordinate b)
			{
				mDiffX = b.mX - a.mX;
				mDiffY = b.mY - a.mY;
			}

			public override bool Equals(object obj)
			{
				return ((Diff)obj).mDiffX == mDiffX && ((Diff)obj).mDiffY == mDiffY;
			}

			public override int GetHashCode()
			{
				return mDiffX + mDiffY;
			}
		}
	}
}