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++14 (GCC 5.4.1) (judge verdict: Wrong Answer)

#include <bits/stdc++.h>
using namespace std;
#define int long long int
#define endl "\n"
const int MOD=1e9+7;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef HOME
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define me(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n;
    cin>>n;
    vector<pair<int,int>>v;
    for(int i=0;i<n;i++){
        int a,b;
        cin>>a>>b;
        v.push_back({a,b});
    }
    if(n==1){
        cout<<0<<endl;
        return 0;
    }
    if(n==2){
        cout<<0<<endl;
        return 0;
    }
    sort(v.begin(),v.end());
    int prev1=0;
    int prev2=0;
    int ans=1;
    set<pair<int,int>>s;
    prev1=v[1].first-v[0].first;
    prev2=v[1].second-v[0].second;
    s.insert({prev1,prev2});
    debug()<<me(v) me(prev1) me(prev2);
    for(int i=2;i<n;i++){
        if(v[i].second-v[i-1].second==prev2&&v[i].first-v[i-1].first==prev1){
            continue;
        }else{
            if(s.find({v[i].first-v[i-1].first,v[i].second-v[i-1].second})!=s.end()){
                continue;
            }
            ans++;
            prev2=v[i].second-v[i-1].second;
            prev1=v[i].first-v[i-1].first;
            s.insert({prev1,prev2});
        }
    }
    cout<<ans<<endl;
    return 0;
    
}