Problem:
Score : 100 points

Problem Statement

We have two bottles for holding water.

Bottle 1 can hold up to A milliliters of water, and now it contains B milliliters of water.

Bottle 2 contains C milliliters of water.

We will transfer water from Bottle 2 to Bottle 1 as much as possible.

How much amount of water will remain in Bottle 2?

Constraints

All values in input are integers.

1 \leq B \leq A \leq 20

1 \leq C \leq 20

Input

Input is given from Standard Input in the following format:

A B C

Output

Print the integer representing the amount of water, in milliliters, that will remain in Bottle 2.

Sample Input 1

6 4 3

Sample Output 1

1

We will transfer two milliliters of water from Bottle 2 to Bottle 1, and one milliliter of water will remain in Bottle 2.

Sample Input 2

8 3 9

Sample Output 2

4

Sample Input 3

12 3 7

Sample Output 3

0

Solution in Go (1.6) (judge verdict: Wrong Answer)

package main

import (
	"bufio"
	"fmt"
	"io"
	"math"
	"os"
	"sort"
	"strconv"
)

func sumR(a []int, n int, mod int) (ret int) {
	for i := n; i < len(a); i++ {
		ret += mod - a[i]
	}
	return
}

func sumL(a []int, n int) (ret int) {
	for i := 0; i <= n; i++ {
		ret += a[i]
	}
	return
}

func Solve(stdin io.Reader, stdout io.Writer) {
	sc := bufio.NewScanner(stdin)

	/* 単語ごとに入力するならこれ */
	sc.Split(bufio.ScanWords)

	sc.Scan()
	n, _ := strconv.Atoi(sc.Text())

	sc.Scan()
	k, _ := strconv.Atoi(sc.Text())

	a := make([]int, n)
	b := make([]int, n)

	sum := 0

	for i := 0; i < n; i++ {
		sc.Scan()
		a[i], _ = strconv.Atoi(sc.Text())
		sum += a[i]
	}
	var divs []int

	sqrt := int(math.Sqrt(float64(sum)))
	for i := 1; i <= sqrt; i++ {
		if sum%i == 0 {
			divs = append(divs, i)
			if i != sum/i {
				divs = append(divs, sum/i)
			}
		}
	}
	sort.Sort(sort.Reverse(sort.IntSlice(divs)))

	ret := 1
	sort.Ints(a)
	for _, i := range divs {
		if sum % i != 0 {
			continue
		}
		for j := 0; j < len(a); j++ {
			b[j] = a[j] % i
		}
		sort.Ints(b)
		for j := 1; j < len(b); j++ {
			b[j] += b[j - 1]
		}
		for j := 0; j < len(b) - 1; j++ {
			if b[j] == i * (len(b) - 1 - j) - b[len(b) - 1] + b[j] && b[j] <= k {
				_, _ = fmt.Fprintf(stdout, "%d\n", i)
				os.Exit(0)
			}
		}
	}
	_, _ = fmt.Fprintf(stdout, "%d\n", ret)
}

func main() {
	Solve(os.Stdin, os.Stdout)
	return
}