output_description: Print the number of possible values of S - T.
  
  * * *
input_description: Input is given from Standard Input in the following format:
  
      
      
      N X D
attempt: import sys
  
  input = sys.stdin.readline
  
  N, X, D = map(int, input().split())
  
  C = {}
  Que = {}
  for l in range(N + 1):
      start = l * X // D + l * (l - 1) // 2
      end = start + l * (N - l)
      key = l * X % D
      if key in Que:
          Que[key].append((start, end))
          C[key] += [start, end, start + 1, end + 1, start - 1, end - 1]
      else:
          Que[key] = [(start, end)]
          C[key] = [start, end, start + 1, end + 1, start - 1, end - 1]
  
  
  ans = 0
  for key, List in C.items():
      ind_to_co = sorted(list(set(List)))
      co_to_ind = {a: i for i, a in enumerate(ind_to_co)}
  
      Imos = [0] * (len(ind_to_co) + 1)
      for start, end in Que[key]:
          Imos[co_to_ind[start]] += 1
          Imos[co_to_ind[end + 1]] -= 1
  
      for i in range(len(ind_to_co) - 1):
          a = ind_to_co[i]
          b = ind_to_co[i + 1]
          Imos[i + 1] += Imos[i]
          if Imos[i + 1] > 0 and Imos[i] > 0:
              ans += b - a
          elif Imos[i] > 0:
              ans += 1
  print(ans)
  
problem_description: Statement
  
  We have an integer sequence A of length N, where A_1 = X, A_{i+1} = A_i + D (1
  \leq i < N ) holds.
  
  Takahashi will take some (possibly all or none) of the elements in this
  sequence, and Aoki will take all of the others.
  
  Let S and T be the sum of the numbers taken by Takahashi and Aoki,
  respectively. How many possible values of S - T are there?
samples: [{"input": "3 4 2", "output": "8\n    \n\nA is (4, 6, 8).\n\nThere are eight ways for (Takahashi, Aoki) to take the elements: ((), (4, 6,\n8)), ((4), (6, 8)), ((6), (4, 8)), ((8), (4, 6))), ((4, 6), (8))), ((4, 8),\n(6))), ((6, 8), (4))), and ((4, 6, 8), ()).\n\nThe values of S - T in these ways are -18, -10, -6, -2, 2, 6, 10, and 18,\nrespectively, so there are eight possible values of S - T.\n\n* * *"}, {"input": "2 3 -3", "output": "2\n    \n\nA is (3, 0). There are two possible values of S - T: -3 and 3.\n\n* * *"}, {"input": "100 14 20", "output": "49805"}]