[Question]
  [
# Description
Subtract the next P numbers from a N number. The next number of N is N + 1.
Look at the examples to get what I mean.
# Examples:
```
Input: N=2,P=3
Calculate: n - (n+1) - (n+2) - (n+3)     //Ending with 3, because P=3
Calculate: 2 -  2+1  -  2+2  - 2+3       //Replacing N with 2 from Input
Calculate: 2 -  3    -  4    - 5
Output: -10
Input: N=100,P=5
Calculate: n - (n+1) - (n+2) - (n+3) - (n+4) - (n+5)
Calculate: 100-  101 -  102  -  103  -  104  - 105
Output: -415
Input: N=42,P=0
Calculate: n
Calculate: 42
Output: 42
Input: N=0,P=3
Calculate: n - (n+1) - (n+2) - (n+3)
Calculate: 0 -  1    -  2    -  3
Output: -6
Input: N=0,P=0
Calulate: n
Calculate: 0
Output: 0
```
# Input:
**N**: Integer, positive, negative or 0
**P**: Integer, positive or 0, not negative
# Output:
Integer or String, leading 0 allowed, trailing newline allowed
# Rules:
* No loopholes
* This is code-golf, so shortest code in bytes wins
* Input and Output must be as described
  
[Answer]
# Python 2, ~~26 24~~ 23 bytes
-2 bytes thanks to @Adnan (replace `p*(p+1)/2` with `p*-~p/2`)  
-1 byte thanks to @MartinEnder (replace `-p*-~p/2` with `+p*~p/2`
```
lambda n,p:n-p*n+p*~p/2
```
Tests are on [**ideone**](http://ideone.com/gRzpwa)
[Answer]
# [05AB1E](https://github.com/Adriandmen/05AB1E), ~~5~~ 3 bytes
Saved 2 bytes thanks to [Adnan](https://codegolf.stackexchange.com/users/34388/adnan)
```
Ý+Æ
```
**Explanation**
Takes P then N as input.
```
       # implicit input, ex 5, 100
Ý      # range(0,X): [0,1,2,3,4,5]
 +     # add: [100,101,102,103,104,105]
  Æ    # reduced subtraction: 100-101-102-103-104-105
```
[Answer]
## CJam, 8 bytes
```
{),f+:-}
```
[Test suite.](http://cjam.aditsu.net/#code=2%203%0A100%205%0A42%200%0A0%203%0A0%200%5D2%2F%7B~%0A%0A%7B)%2Cf%2B%3A-%7D%0A%0A~p%7D%2F)
Too bad that the closed form solution is longer. :|
### Explanation
```
),  e# Get range [0 1 ... P].
f+  e# Add N to each value to get [N N+1 ... N+P].
:-  e# Fold subtraction over the list, computing N - (N+1) - (N+2) - ... - (N+P).
```
[Answer]
## Haskell, 21 bytes
```
a#b=foldl1(-)[a..a+b]
```
[Answer]
## Javascript (ES6), ~~20~~ ~~19~~ 18 bytes
```
n=>p=>n+p*(~p/2-n)
```
*Saved 1 byte by currying, as suggested by Zwei*  
*Saved 1 byte thanks to user81655*
### Test
```
let f =
n=>p=>n+p*(~p/2-n)
console.log(f(2)(3))
console.log(f(100)(5))
console.log(f(42)(0))
console.log(f(0)(3))
console.log(f(0)(0))
```
[Answer]
# [Jelly](http://github.com/DennisMitchell/jelly), 4 bytes
```
r+_/
```
[Try it online!](http://jelly.tryitonline.net/#code=citfLw&input=&args=MTAw+NQ)
### How it works
```
r+_/  Main link. Arguments: n, p
 +    Yield n+p.
r     Range; yield [n, ..., n+p].
  _/  Reduce by subtraction.
```
[Answer]
# Haskell, ~~19~~ 18 bytes
```
n#p=n+sum[-n-p..n]
```
Previous 19 bytes solutions
```
n#p=n-n*p-(p*p+p)/2
n#p=n-sum[n+1..n+p]
```
[Answer]
# C#, 21 20 bytes
*Edit: Saved one byte thanks to [TheLethalCoder](https://codegolf.stackexchange.com/users/38550/thelethalcoder)*
```
N=>P=>N-P++*(N+P/2);
```
**[Try it online!](https://ideone.com/IA7KSq)**
Full source, including test cases:
```
using System;
namespace substract
{
    class Program
    {
        static void Main(string[] args)
        {
            Func<int,Func<int,int>>s=N=>P=>N-P++*(N+P/2);
            Console.WriteLine(s(2)(3));     //-10
            Console.WriteLine(s(100)(5));   //-415
            Console.WriteLine(s(42)(0));    //42
            Console.WriteLine(s(0)(3));     //-6
            Console.WriteLine(s(0)(0));     //0
        }
    }
}
```
[Answer]
## Mathematica, 15 bytes
```
#2-##-#(#+1)/2&
```
An unnamed function that receives `P` and `n` as its parameters in that order.
Uses the closed form solution `n - n*p - p(p+1)/2`.
[Answer]
# Perl, ~~23~~ 22 bytes
Includes +1 for `-p`
Give n and p (in that order) on separate lines of STDIN:
```
subtract.pl
2
3
^D
```
`subtract.pl`:
```
#!/usr/bin/perl -p
$_-=eval"+2+\$_++"x<>
```
(using `''` quotes to save the `\` invokes a 2 byte penalty because it can't be combined with `-e`)
Same idea and length:
```
#!/usr/bin/perl -p
$_+=eval"-1-++\$_"x<>
```
Surprisingly doing the actual calculation is shorter than using the direct formula (these `$`'s really hurt for arithmetic)
[Answer]
## C++, ~~54~~ 51 bytes
```
  [](int N,int P){int F=N;while(P--)F-=++N;return F;}
```
~~[](int N,int P){int F;for(F=N;P;F-=++N,P--);return F;}~~
## Test:
```
#include <iostream>
int main(void)
{
    int N, P;
    std::cin >> N >> P;
    auto f = [](int N,int P){int F=N;while(P--)F-=++N;return F;};
    std::cout << f(N,P) << std::endl;
    return 0;
}
```
[Answer]
## Pyke, 6 bytes
```
m+mhs-
```
[Try it here!](http://pyke.catbus.co.uk/?code=m%2Bmhs-&input=100%0A5&warnings=0)
```
m+     -    map(range(input_2), +input_1)
  mh   -   map(^, +1)
    s  -  sum(^)
     - - input_1 - ^
```
[Answer]
# [Brachylog](https://github.com/JCumin/Brachylog), ~~19~~ 17 bytes
```
hHyL,?+y:Lx+$_:H+
```
### Explanation
```
hH                  Input = [H, whatever]
 HyL,               L = [0, …, H]
     ?+             Sum the two elements in the Input
       y            Yield the range from 0 to the result of the sum
        :Lx         Remove all elements of L from that range
           +        Sum the remaining elements
            $_      Negate the result
              :H+   Add H
```
[Answer]
# Forth, 36 bytes
Simple computation of `n - (p*n + (p^2+p) / 2)`
```
: f 2dup dup dup * + 2/ -rot * + - ;
```
[**Try it online**](https://repl.it/DJYh)
[Answer]
# [MATL](https://github.com/lmendo/MATL), 5 bytes
```
:y+s-
```
Inputs are `P` and then `N`.
[Try it at MATL Online!](https://matl.io/?code=%3Ay%2Bs-&inputs=5%0A100&version=19.1.0)
### Explanation
```
:     % Take P implicitly. Range [1 2 ... P]
      %     Stack: [1 2 ... P]
y     % Take N implicitly at the bottom of the stack, and push another copy
      %     Stack: N, [1 2 ... P], N
+     % Add the top two arrays in the stack , element-wise
      %     Stack: N, [N+1 N+2 ... N+P]
s     % Sum of array
      %     Stack: N, N+1+N+2+...+N+P
-     % Subtract the top two numbers
      %     Stack: N-(N+1+N+2+...+N+P)
      % Implicitly display
```
[Answer]
## Batch, 30 bytes
```
@cmd/cset/a%1-(%1*2+%2+1)*%2/2
```
Takes `n` and `p` as command-line parameters and prints the result without a trailing newline.
[Answer]
## [S.I.L.O.S](https://github.com/rjhunjhunwala/S.I.L.O.S), 80 bytes
```
GOTO b
lbla
n+1
m-n
i-1
GOTO d
lblb
readIO
n=i
m=n
readIO
lbld
if i a
printInt m
```
Try it online with test cases:  
[2,3](http://silos.tryitonline.net/#code=R09UTyBiCmxibGEKbisxCm0tbgppLTEKR09UTyBkCmxibGIKcmVhZElPCm49aQptPW4KcmVhZElPCmxibGQKaWYgaSBhCnByaW50SW50IG0&input=&args=Mg+Mw)  
[100,5](http://silos.tryitonline.net/#code=R09UTyBiCmxibGEKbisxCm0tbgppLTEKR09UTyBkCmxibGIKcmVhZElPCm49aQptPW4KcmVhZElPCmxibGQKaWYgaSBhCnByaW50SW50IG0&input=&args=MTAw+NQ)  
[42,0](http://silos.tryitonline.net/#code=R09UTyBiCmxibGEKbisxCm0tbgppLTEKR09UTyBkCmxibGIKcmVhZElPCm49aQptPW4KcmVhZElPCmxibGQKaWYgaSBhCnByaW50SW50IG0&input=&args=NDI+MA)  
[0,3](http://silos.tryitonline.net/#code=R09UTyBiCmxibGEKbisxCm0tbgppLTEKR09UTyBkCmxibGIKcmVhZElPCm49aQptPW4KcmVhZElPCmxibGQKaWYgaSBhCnByaW50SW50IG0&input=&args=MA+Mw)  
[0,0](http://silos.tryitonline.net/#code=R09UTyBiCmxibGEKbisxCm0tbgppLTEKR09UTyBkCmxibGIKcmVhZElPCm49aQptPW4KcmVhZElPCmxibGQKaWYgaSBhCnByaW50SW50IG0&input=&args=MA+MA) 
[Answer]
# R, ~~17~~ 14 bytes
```
N-N*P-sum(0:P)
```
Thanks to billywob for golfing away 3 bytes. Previous answer:
```
N-sum(N+if(P)1:P)
```
Note that 1:0 expands to the vector (1,0) so we need the if(P) condition (or to use `seq_len`, but that is more bytes). Without the condition, we would get the wrong output if P=0.
If P is zero, then the sum expands to `sum(N+NULL)`, then to `sum(numeric(0))`, which is zero.
[Answer]
# PHP, 33 Bytes
```
$n-=$n*$p+array_sum(range(0,$p));
```
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), 7 [bytes](https://github.com/DennisMitchell/jelly/wiki/Code-page)
```
RS+×_×-
```
Arguments are `P, N`  
Test it on [**TryItOnline**](http://jelly.tryitonline.net/#code=UlMrw5dfw5ct&input=&args=NQ+MTAw)
How?
```
RS+×_×-  - takes two arguments: P, N
R        - range(P): [1,2,3, ... ,P]
 S       - sum: 1+2+3+ ... +P
   ×     - multiply: P*N
  +      - add: 1+2+3+ ... +P + P*N
    _    - subtract: 1+2+3+ ... +P + P*N - N
      -  - -1
     ×   - multiply: (1+2+3+ ... +P + P*N - N)*-1
                   = -1-2-3- ... -P - P*N + N
                   = N - (N+1) - (N+2) - (N+3) - ... - (N+P)
```
[Answer]
# Pyth - 6 bytes
```
-F}Q+E
```
[Test Suite](http://pyth.herokuapp.com/?code=-F%7DQ%2BE&test_suite=1&test_suite_input=2%0A3%0A100%0A5%0A42%0A0%0A0%0A3%0A0%0A0&debug=0&input_size=2).
[Answer]
# Java, ~~67~~, 63 bytes
Golfed:
```
int x(int n,int p){return-((p%2<1)?p*p/2+p:p/2*(p+2)+1)+n-p*n;}
```
Ungolfed:
```
int x(int n, int p)
{
    return -((p%2<1) ? p*p/2+p : p/2 * (p+2) + 1) + n - p*n;
}
```
Basically I did some math on the formula. The `n - p*n` part takes care of the all `n`'s in the formula. Then I used a super fun property of summing together linearly increasing set of integers (arithmetic series): I used the sum of first and last integer and then multiply it by `set.length / 2` (I also check for the parity and handle it appropriately).
Try it: <https://ideone.com/DEd85A>
[Answer]
# Java 7, ~~43~~ 40 bytes
```
int c(int n,int p){return n-p*n+p*~p/2;}
```
# Java 8, 19 bytes
```
(n,p)->n-p*n+p*~p/2
```
Shamelessly stolen from [*@JonathanAllan*'s amazing Python 2 formula](https://codegolf.stackexchange.com/a/91915/52210).
**Original answer (~~61~~ 60 bytes):**
```
int c(int n,int p){int r=n,i=1;for(;i<p;r-=n+++i);return r;}
```
**Ungolfed & test cases:**
[Try it here.](https://ideone.com/cwJp03)
```
class M{
  static int c(int n, int p){
    return n - p*n + p*~p / 2;
  }
  public static void main(String[] a){
    System.out.println(c(2, 3));
    System.out.println(c(100, 5));
    System.out.println(c(42, 0));
    System.out.println(c(0, 3));
    System.out.println(c(0, 0));
  }
}
```
**Output:**
```
-10
-415
42
-6
0
```
[Answer]
# [Fourier](http://github.com/beta-decay/fourier), 34 bytes
```
I~No~OI~P>0{1}{@P+N(N^~NO-N~ON)Oo}
```
[**Try it online!**](http://fourier.tryitonline.net/#code=SX5Ob35PSX5QPjB7MX17QFArTihOXn5OTy1Ofk9OKU9vfQ&input=NDIKMA)
[Answer]
## [Labyrinth](https://github.com/m-ender/labyrinth), 15 bytes
```
?:?:}*-{:)*#/-!
```
or
```
??:}`)*{:)*#/-!
```
Uses the closed form solution `n - n*P - P*(P+1)/2`.
[Answer]
# php, 38 bytes
```
<?=$argv[1]*(1-$a=$argv[2])-$a++*$a/2;
```
[Answer]
# [Burlesque](https://github.com/FMNSSun/Burlesque), 12 bytes
```
perz?+{.-}r[
```
[Try it online!](https://tio.run/##SyotykktLixN/f@/ILWoyl67Wk@3tij6/39DAwMFUwA "Burlesque – Try It Online")
```
pe     #Read input as P, N
rz     #Range (0,N)
?+     #Add P to each
{.-}r[ #Reduce via subtraction
```
[Answer]
# [Vyxal](https://github.com/Vyxal/Vyxal), 4 bytes
```
+ṡƒ-
```
[Try it Online!](https://vyxal.pythonanywhere.com/#WyIiLCIiLCIr4bmhxpItIiwiIiwiMTAwXG41Il0=)
Port of Jelly answer.
## How?
```
+ṡƒ-
+ṡ   # Inclusive range [a, a + b]
  ƒ- # Reduce by subtraction
```
[Answer]
# TI-Basic, 17 bytes
```
Prompt N,P
N-NP-.5(P²+P
```
Alternatives:
```
Prompt N,P
N-P(P/2+.5+N
```
```
Prompt N,P
N-NP-.5P(P+1
```
```
Prompt N,P
N-.5P(2N+P+1
```
[Answer]
# Pyth, 11 bytes
```
Ms+Gm_+GdSH
```
A function `g` that takes input of `n` and `p` via argument and prints the result. It can be called in the form `gn p`.
[Try it online](https://pyth.herokuapp.com/?code=Ms%2BGm_%2BGdSH%3B%0Ag2+3%3B%0Ag100+5%3B%0Ag42+0%3B%0Ag0+3%3B%0Ag0+0&debug=0)
**How it works**
```
Ms+Gm_+GdSH  Function g. Inputs: G, H
M            g=lambda G,H:
         SH   1-indexed range, yielding [1, 2, 3, ..., H]
    m_+Gd     Map lambda d:-(G+d) over the above, yielding [-(G+1), -(G+2), -(G+3),
              ..., -(G+H)]
  +G          Add G to the above, yielding [G, -(G+1), -(G+2), -(G+3), ..., -(G+H)]
 s            Reduce on addition with base case 0, yielding G-(G+1)-(G+2)-(G+3)...
              -(G+H)
              Implicitly print
```
]