import java.io.Closeable;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.InputMismatchException;
/**
* njudge compatible version
*/
public class main {
public static void main(String[] args) throws IOException {
IO io = new IO();
int retekSzama = io.nextInt();
int K = io.nextInt();
int szabadRetek = 0;
for (int i = 0; i < retekSzama; i++) {
if (io.nextInt() == 1) szabadRetek++;
}
int N = szabadRetek-K+1;
if (szabadRetek >= K) io.write((N)*(N+1)/2); //write the sum of all positive integers up to N (inclusive)
else io.write(0);
io.close();
}
/**
* (mester package)
* @author Bence Hornák
*/
public static class IO implements Closeable {
private static final int BUF_SIZE = 4096;
private final byte[] buf = new byte[BUF_SIZE];
private int pointer = 0;
private int available = 0;
private final InputStream in;
private final OutputStream out;
public IO() {
in = System.in;
out = System.out;
}
@Override
public void close() throws IOException {
in.close();
out.close();
}
public int nextInt() throws InputMismatchException, IOException {
// popWhitespace();
while (!isEOF() && isWhiteSpace(peekChar())) {
popChar();
}
int sign = popSign();
throwIfEOF();
int num = 0;
int c;
for(;;){
if (pointer >= available && available >= 0) {
available = in.read(buf, 0, BUF_SIZE);
pointer = 0;
}
if (available == -1) {
c= -1;
}else{
c= buf[pointer];
}
if('0' <= c && c <= '9'){
num = num * 10 + (c - '0');
pointer++;
}else{
break;
}
}
return sign * num;
}
public long nextLong() throws InputMismatchException, IOException {
// popWhitespace();
while (!isEOF() && isWhiteSpace(peekChar())) {
popChar();
}
int sign = popSign();
throwIfEOF();
long num = 0;
int c;
for(;;){
if (pointer >= available && available >= 0) {
available = in.read(buf, 0, BUF_SIZE);
pointer = 0;
}
if (available == -1) {
c= -1;
}else{
c= buf[pointer];
}
if('0' <= c && c <= '9'){
num = num * 10 + (c - '0');
pointer++;
}else{
break;
}
}
return sign * num;
}
public String next() throws InputMismatchException, IOException {
popWhitespace();
StringBuilder sb = new StringBuilder();
throwIfEOF();
int c;
while (!isWhiteSpace(c = peekChar())) {
sb.append((char) c);
popChar();
}
return sb.toString();
}
public String getLine() throws InputMismatchException, IOException {
throwIfEOF();
StringBuilder sb = new StringBuilder();
int c;
while (!isEOF() && (c = peekChar()) != '\n') {
popChar();
sb.append((char)c);
}
if (peekChar() == '\n') {
popChar();
}
return sb.toString();
}
public char getChar() throws InputMismatchException, IOException {
throwIfEOF();
char c = (char) peekChar();
popChar();
return c;
}
public void write(int x) throws IOException {
out.write(Integer.toString(x).getBytes());
}
public void writeLn(int x) throws IOException {
out.write(Integer.toString(x).getBytes());
out.write('\n');
out.flush();
}
public void write(long x) throws IOException {
out.write(Long.toString(x).getBytes());
}
public void writeLn(long x) throws IOException {
out.write(Long.toString(x).getBytes());
out.write('\n');
out.flush();
}
public void write(String s) throws IOException {
out.write(s.getBytes());
}
public void writeLn(String s) throws IOException {
out.write(s.getBytes());
out.write('\n');
out.flush();
}
private void throwIfEOF() throws InputMismatchException, IOException {
if (isEOF()) {
throw new InputMismatchException("EOF");
}
}
private boolean isEOF() throws IOException {
if (pointer < available) {
return false;
} else if (available >= 0) {
available = in.read(buf, 0, BUF_SIZE);
pointer = 0;
return available < 0;
} else {
return true;
}
}
private void popChar() throws IOException {
loadBufferIfNeeded();
++pointer;
}
private int peekChar() throws IOException {
loadBufferIfNeeded();
if (available == -1) {
return -1;
}
return buf[pointer];
}
private void loadBufferIfNeeded() throws IOException {
if (pointer < available || available < 0) {
return;
}
available = in.read(buf, 0, BUF_SIZE);
pointer = 0;
}
private static boolean isWhiteSpace(int n) {
return n == ' ' || n == '\n' || n == '\r' || n == '\t' || n == -1;
}
private static boolean isDigit(int n) {
return '0' <= n && n <= '9';
}
private void popWhitespace() throws IOException {
while (!isEOF() && isWhiteSpace(peekChar())) {
popChar();
}
}
/**
* Returns +1, if there is no sign character, -1, if there is a minus sign.
*/
private int popSign() throws IOException {
if (peekChar() == '-') {
popChar();
return -1;
} else {
return +1;
}
}
}
}