title: Finding the number of possible arithmetic series of 3 among a given set of numbers
body: <p>Given a set integers, the problem consists of finding the number of possible arithmetic series of length 3. The set of integers may or may not be sorted.</p>
  
  <p>I could implement a simple bruteforce algorithm taking time O(n^3) but time efficiency is important and the set of integers can be as large as 10^5. This means bruteforce obviously won't work. Can anyone suggest some algorithm/pseudocode/code in c++?</p>
  
  <p>An example: there are 4 numbers 5,2,7,8 . Clearly there is only one such possibility - (2,5,8) in which the common difference is 3, so our answer is 1.</p>
  
  <p><strong>EDIT</strong>:I forgot to mention one important property - each number of set given is between 1 to 30000 (inclusive).</p>