Problem:
Score : 200 points

Problem Statement

Snuke has N integers. Among them, the smallest is A, and the largest is B.
We are interested in the sum of those N integers. How many different possible sums there are?

Constraints

1 ≤ N,A,B ≤ 10^9

A and B are integers.

Input

Input is given from Standard Input in the following format:

N A B

Output

Print the number of the different possible sums.

Sample Input 1

4 4 6

Sample Output 1

5

There are five possible sums: 18=4+4+4+6, 19=4+4+5+6, 20=4+5+5+6, 21=4+5+6+6 and 22=4+6+6+6.

Sample Input 2

5 4 3

Sample Output 2

0

Sample Input 3

1 7 10

Sample Output 3

0

Sample Input 4

1 3 3

Sample Output 4

1

Solution in Ruby (2.3.3) (judge verdict: Runtime Error)

def f(s, qs)
  counts = s.map{|l|
    # l.inject([0]){|r, c| r + [r.last + c] }
    r = [0]
    l.each{|c| r << r.last + c }
    r
  }.transpose.map{|l|
    # l.inject([0]){|r, c| r + [r.last + c] }
    r = [0]
    l.each{|c| r << r.last + c }
    r
  }.transpose

  horizontals = s.map{|l|
    rr = [0]
    l.inject(0){|r,c| rr << (r + c > 1 ? rr.last + 1 : rr.last); c }
    rr[1..-1]+[rr.last]
    # rr
  }.transpose.map{|l|
    l.inject([0]){|r, c| r + [r.last + c] }
  }.transpose

  verticals = s.transpose.map{|l|
    rr = [0]
    l.inject(0){|r,c| rr << (r + c > 1 ? rr.last + 1 : rr.last); c }
    rr[1..-1]+[rr.last]
    # rr
  }.transpose.map{|l|
    l.inject([0]){|r, c| r + [r.last + c] }
  }
  # p [counts, horizontals, verticals]

  qs.map{|x1, y1, x2, y2|
    g = lambda{|cusum, x1, y1, x2, y2|
      return 0 if x1 > x2 || y1 > y2
      cusum[x2+1][y2+1] - cusum[x2+1][y1] - cusum[x1][y2+1] + cusum[x1][y1]
      # [cusum[x2+1][y2+1], cusum[x2+1][y1], cusum[x1][y2+1], cusum[x1][y1]]
    }
    g.(counts, x1, y1, x2, y2) - g.(horizontals, x1, y1, x2, y2-1) - g.(verticals, x1, y1, x2-1, y2)
    # [g.(counts, x1, y1, x2, y2), g.(horizontals, x1, y1, x2, y2-1) - g.(verticals, x1, y1, x2-1, y2)]
  }
end

N, M, Q = gets.split.take(3).map(&:to_i)

S = N.times.map{gets.chomp.chars.take(M).map(&:to_i)}
Queries = Q.times.map{
  gets.split.take(4).map(&:to_i).map(&:pred)
}
puts f(S, Queries)