import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.StringTokenizer;

public class A {

    public static void main(String[] args) throws FileNotFoundException {
        Scanner in = new Scanner();
        PrintWriter out = new PrintWriter(System.out);
        int n = in.nextInt();
        int k = in.nextInt();
        int result = 0;
        for(int i = 0; i < n; i++){
            if(check(in.nextInt(), k)){
                result ++;
            }
        }
        out.println(result);
        out.close();
    }
    static boolean check(int val , int k){
        boolean []check = new boolean[k + 1];
        int count = 0;
        while(val > 0){
            int a = val % 10;

            if(a > k){

            }else if(!check[a]){
                check[a] = true;
                count++;
            }

            val /=10;
        }
        return count == (k + 1);
    }

    static class Point {

        int x, y;

        public Point(int x, int y) {
            this.x = x;
            this.y = y;

        }
    }

    public static boolean nextPer(int[] data) {
        int i = data.length - 1;
        while (i > 0 && data[i] < data[i - 1]) {
            i--;
        }
        if (i == 0) {
            return false;
        }
        int j = data.length - 1;
        while (data[j] < data[i - 1]) {
            j--;
        }
        int temp = data[i - 1];
        data[i - 1] = data[j];
        data[j] = temp;
        Arrays.sort(data, i, data.length);
        return true;
    }

    static class FT {

        int[] data;

        FT(int n) {
            data = new int[n];
        }

        void update(int index, int val) {
            // System.out.println("UPDATE INDEX " + index);
            while (index < data.length) {
                data[index] += val;
                index += index & (-index);

                //    System.out.println("NEXT " +index);
            }
        }

        int get(int index) {
            //  System.out.println("GET INDEX " + index);
            int result = 0;
            while (index > 0) {
                result += data[index];
                index -= index & (-index);
                // System.out.println("BACK " + index);
            }
            return result;
        }
    }

    static int gcd(int a, int b) {
        if (b == 0) {
            return a;
        } else {
            return gcd(b, a % b);
        }
    }

    static int pow(int a, int b) {
        if (b == 0) {
            return 1;
        }
        if (b == 1) {
            return a;
        }
        int val = pow(a, b / 2);
        if (b % 2 == 0) {

            return val * val;
        } else {
            return val * val * a;
        }
    }

//    static Point intersect(Point a, Point b, Point c) {
//        double D = cross(a, b);
//        if (D != 0) {
//            return new Point(cross(c, b) / D, cross(a, c) / D);
//        }
//        return null;
//    }
//
//    static Point convert(Point a, double angle) {
//        double x = a.x * cos(angle) - a.y * sin(angle);
//        double y = a.x * sin(angle) + a.y * cos(angle);
//        return new Point(x, y);
//    }
//    static Point minus(Point a, Point b) {
//        return new Point(a.x - b.x, a.y - b.y);
//    }
//
//    static Point add(Point a, Point b) {
//        return new Point(a.x + b.x, a.y + b.y);
//    }
//
//    static double cross(Point a, Point b) {
//        return a.x * b.y - a.y * b.x;
//
//
//    }
//
//    static class Point {
//
//        int x, y;
//
//        Point(int x, int y) {
//            this.x = x;
//            this.y = y;
//        }
//
//        @Override
//        public String toString() {
//            return "Point: " + x + " " + y;
//        }
//    }
    static class Scanner {

        BufferedReader br;
        StringTokenizer st;

        public Scanner() throws FileNotFoundException {
            //System.setOut(new PrintStream(new BufferedOutputStream(System.out), true));
            br = new BufferedReader(new InputStreamReader(System.in));
            // br = new BufferedReader(new FileReader(new File("input.txt")));
        }

        public String next() {

            while (st == null || !st.hasMoreTokens()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (Exception e) {
                    throw new RuntimeException();
                }
            }
            return st.nextToken();
        }

        public long nextLong() {
            return Long.parseLong(next());
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

        public double nextDouble() {
            return Double.parseDouble(next());
        }

        public String nextLine() {
            st = null;
            try {
                return br.readLine();
            } catch (Exception e) {
                throw new RuntimeException();
            }
        }

        public boolean endLine() {
            try {
                String next = br.readLine();
                while (next != null && next.trim().isEmpty()) {
                    next = br.readLine();
                }
                if (next == null) {
                    return true;
                }
                st = new StringTokenizer(next);
                return st.hasMoreTokens();
            } catch (Exception e) {
                throw new RuntimeException();
            }
        }
    }
}


import java.util.Scanner;

public class GoodNumber
{
	public static void main(String[] args)
	{
		Scanner input = new Scanner(System.in);
		int n = input.nextInt();
		int k = input.nextInt();
		boolean[] exists = new boolean[k + 1];
		input.nextLine();
		int count = 0;
		String s;
		boolean flag;
		for (int i = 0; i < n; ++i)
		{
			s = input.nextLine();
			if (s.length() != k + 1)
			{
				continue;
			}
			for (int j = 0; j <= k; ++j)
			{
				exists[j] = false;
			}
			flag = true;
			for (int j = 0; j < s.length(); ++j)
			{
				if (exists[s.charAt(j) - '0'])
				{
					flag = false;
					break;
				}
				else
				{
					exists[s.charAt(j) - '0'] = true;
				}
			}
			if (flag)
			{
				++count;
			}
		}
		System.out.println(count);
	}
}


import java.util.Scanner;

public class GoodNumber
{
	public static void main(String[] args)
	{
		Scanner input = new Scanner(System.in);
		int n = input.nextInt();
		int k = input.nextInt();
		boolean[] exists = new boolean[k + 1];
		input.nextLine();
		int count = 0;
		String s;
		boolean flag;
		for (int i = 0; i < n; ++i)
		{
			s = input.nextLine();
			for (int j = 0; j <= k; ++j)
			{
				exists[j] = false;
			}
			for (int j = 0; j < s.length(); ++j)
			{
				if (s.charAt(j) - '0' <= k)
				{
					exists[s.charAt(j) - '0'] = true;
				}
			}
			flag = true;
			for (int j = 0; j <= k; ++j)
			{
				if (!exists[j])
				{
					flag = false;
					break;
				}
			}
			if (flag)
			{
				++count;
			}
		}
		System.out.println(count);
	}
}


import java.util.*;
import java.io.*;

public class Main {
	public static void main (String[] args) throws IOException{
		BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
		String[] split = reader.readLine().split(" ");
		int n = Integer.parseInt(split[0]);
		int k = Integer.parseInt(split[1]);
		int result = 0;
		for (int ii = 0; ii < n; ii++) {
			boolean[] flag = new boolean[10];
			String a = reader.readLine();
			for (int jj = 0; jj < a.length(); jj++) {
				flag[Integer.parseInt(String.valueOf(a.charAt(jj)))] = true;
			}
			boolean check = true;
			for (int jj = 0; jj < k; jj++) {
				//System.out.println();
				if (flag[jj] == false) {
					check = false;
				}
			}
			if (check) result++;
		}
		System.out.println (result);
	}
}


import java.util.*;
import java.io.*;

public class Main {
	public static void main (String[] args) throws IOException{
		BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
		String[] split = reader.readLine().split(" ");
		int n = Integer.parseInt(split[0]);
		int k = Integer.parseInt(split[1]);
		int result = 0;
		for (int ii = 0; ii < n; ii++) {
			boolean[] flag = new boolean[10];
			String a = reader.readLine();
			for (int jj = 0; jj < a.length(); jj++) {
				flag[Integer.parseInt(String.valueOf(a.charAt(jj)))] = true;
			}
			boolean check = true;
			for (int jj = 0; jj <= k; jj++) {
				//System.out.println();
				if (flag[jj] == false) {
					check = false;
				}
			}
			if (check) result++;
		}
		System.out.println (result);
	}
}


import java.io.IOException;
import java.io.InputStream;
import java.util.HashSet;
import java.util.Set;

public class Main {
    public static void main(String[] args) throws IOException {
        FastScanner s = new FastScanner(System.in);
        int n = s.nextInt();
        int k = s.nextInt();
        Set<Integer> set = new HashSet<Integer>();
        int count = 0;
        for (int i = 0; i < n; i++) {
            int t = s.nextInt();
            int m = t;
            boolean kgood = true;

            Set<Integer> set1 = new HashSet<Integer>();
            if (!set.contains(m)) {
                while (t > 0) {
                    int p = t % 10;
                    if (p <= k) {
                        set1.add(p);
                    } else {
                        kgood = false;
                        break;
                    }
                    t /= 10;
                }

                if (kgood && set1.size() == k + 1) {
                    count++;
                    set.add(m);
                }
            } else {
                count++;
            }
        }
        System.out.println(count);
    }
}

class FastScanner {

    InputStream is;
    byte buff[] = new byte[1024];
    int currentChar = -1;
    int buffChars = 0;

    public FastScanner(InputStream inputStream) {
        is = inputStream;
    }

    public boolean hasNext() throws IOException {
        return buffChars >= 0;
    }

    public int nextChar() throws IOException {
        //if we already have that next char read, just return else input
        if (currentChar == -1 || currentChar >= buffChars) {
            currentChar = 0;
            buffChars = is.read(buff);
        }

        if (buffChars <= 0) {
            return -1;
        }

        return (char) buff[currentChar++];
    }

    public String nextString() throws IOException {
        StringBuilder bldr = new StringBuilder();
        int ch;
        while (isSpace(ch = nextChar())) ;

        do {
            bldr.append((char) ch);
        } while (!isSpace(ch = nextChar()));

        return bldr.toString();
    }

    public int nextInt() throws IOException {
        //considering ASCII files--> 8 bit chars,     unicode files has 16 bit chars (byte1 then byte2)
        int result = 0;
        int sign = 1;
        int ch;
        while (isSpace(ch = nextChar())) ;

        if (ch == '-') {
            sign = -1;
            ch = nextChar();
        }

        do {
            if (ch < '0' || ch > '9') {
                throw new NumberFormatException("Found '" + ch + "' while parsing for int.");
            }

            result *= 10;
            result += ch - '0';
        } while (!isSpace(ch = nextChar()));

        return sign * result;
    }

    public long nextLong() throws IOException {
        //considering ASCII files--> 8 bit chars,     unicode files has 16 bit chars (byte1 then byte2)
        long result = 0;
        int sign = 1;
        int ch;
        while (isSpace(ch = nextChar())) ;

        if (ch == '-') {
            sign = -1;
            ch = nextChar();
        }

        do {
            if (ch < '0' || ch > '9') {
                throw new NumberFormatException("Found '" + ch + "' while parsing for int.");
            }

            result *= 10;
            result += ch - '0';
        } while (!isSpace(ch = nextChar()));

        return sign * result;
    }

    private boolean isSpace(int ch) {
        return ch == '\n' || ch == ' ' || ch == '\t' || ch == '\r' || ch == -1;
    }

    public void close() throws IOException {
        is.close();
    }
}


import java.io.IOException;
import java.io.InputStream;
import java.util.HashSet;
import java.util.Set;

public class Main {
    public static void main(String[] args) throws IOException {
        FastScanner s = new FastScanner(System.in);
        int n = s.nextInt();
        int k = s.nextInt();
        Set<Integer> set = new HashSet<Integer>();
        int count = 0;
        for (int i = 0; i < n; i++) {
            int t = s.nextInt();
            int m = t;
            Set<Integer> set1 = new HashSet<Integer>();
            if (!set.contains(m)) {
                while (t > 0) {
                    int p = t % 10;
                    if (p <= k) {
                        set1.add(p);
                    }
                    t /= 10;
                }

                if (set1.size() == k + 1) {
                    count++;
                    set.add(m);
                }
            } else {
                count++;
            }
        }
        System.out.println(count);
    }
}

class FastScanner {

    InputStream is;
    byte buff[] = new byte[1024];
    int currentChar = -1;
    int buffChars = 0;

    public FastScanner(InputStream inputStream) {
        is = inputStream;
    }

    public boolean hasNext() throws IOException {
        return buffChars >= 0;
    }

    public int nextChar() throws IOException {
        //if we already have that next char read, just return else input
        if (currentChar == -1 || currentChar >= buffChars) {
            currentChar = 0;
            buffChars = is.read(buff);
        }

        if (buffChars <= 0) {
            return -1;
        }

        return (char) buff[currentChar++];
    }

    public String nextString() throws IOException {
        StringBuilder bldr = new StringBuilder();
        int ch;
        while (isSpace(ch = nextChar())) ;

        do {
            bldr.append((char) ch);
        } while (!isSpace(ch = nextChar()));

        return bldr.toString();
    }

    public int nextInt() throws IOException {
        //considering ASCII files--> 8 bit chars,     unicode files has 16 bit chars (byte1 then byte2)
        int result = 0;
        int sign = 1;
        int ch;
        while (isSpace(ch = nextChar())) ;

        if (ch == '-') {
            sign = -1;
            ch = nextChar();
        }

        do {
            if (ch < '0' || ch > '9') {
                throw new NumberFormatException("Found '" + ch + "' while parsing for int.");
            }

            result *= 10;
            result += ch - '0';
        } while (!isSpace(ch = nextChar()));

        return sign * result;
    }

    public long nextLong() throws IOException {
        //considering ASCII files--> 8 bit chars,     unicode files has 16 bit chars (byte1 then byte2)
        long result = 0;
        int sign = 1;
        int ch;
        while (isSpace(ch = nextChar())) ;

        if (ch == '-') {
            sign = -1;
            ch = nextChar();
        }

        do {
            if (ch < '0' || ch > '9') {
                throw new NumberFormatException("Found '" + ch + "' while parsing for int.");
            }

            result *= 10;
            result += ch - '0';
        } while (!isSpace(ch = nextChar()));

        return sign * result;
    }

    private boolean isSpace(int ch) {
        return ch == '\n' || ch == ' ' || ch == '\t' || ch == '\r' || ch == -1;
    }

    public void close() throws IOException {
        is.close();
    }
}


import java.io.IOException;
import java.io.InputStream;
import java.util.HashSet;
import java.util.Set;

public class Main {
    public static void main(String[] args) throws IOException {
        FastScanner s = new FastScanner(System.in);
        int n = s.nextInt();
        int k = s.nextInt();
        Set<Integer> set = new HashSet<Integer>();
        int count = 0;
        for (int i = 0; i < n; i++) {
            int t = s.nextInt();
            int m = t;
            boolean kgood = true;

            Set<Integer> set1 = new HashSet<Integer>();
            if (!set.contains(m)) {
                while (t > 0) {
                    int p = t % 10;
                    if (p <= k) {
                        set1.add(p);
                    } else {
                        kgood = false;
                        break;
                    }
                    t /= 10;
                }
            }

            if ((kgood && set1.size()==k+1) || set.contains(m)) {
                count++;
                set.add(m);
            }
        }

        System.out.println(count);
    }
}

class FastScanner {

    InputStream is;
    byte buff[] = new byte[1024];
    int currentChar = -1;
    int buffChars = 0;

    public FastScanner(InputStream inputStream) {
        is = inputStream;
    }

    public boolean hasNext() throws IOException {
        return buffChars >= 0;
    }

    public int nextChar() throws IOException {
        //if we already have that next char read, just return else input
        if (currentChar == -1 || currentChar >= buffChars) {
            currentChar = 0;
            buffChars = is.read(buff);
        }

        if (buffChars <= 0) {
            return -1;
        }

        return (char) buff[currentChar++];
    }

    public String nextString() throws IOException {
        StringBuilder bldr = new StringBuilder();
        int ch;
        while (isSpace(ch = nextChar())) ;

        do {
            bldr.append((char) ch);
        } while (!isSpace(ch = nextChar()));

        return bldr.toString();
    }

    public int nextInt() throws IOException {
        //considering ASCII files--> 8 bit chars,     unicode files has 16 bit chars (byte1 then byte2)
        int result = 0;
        int sign = 1;
        int ch;
        while (isSpace(ch = nextChar())) ;

        if (ch == '-') {
            sign = -1;
            ch = nextChar();
        }

        do {
            if (ch < '0' || ch > '9') {
                throw new NumberFormatException("Found '" + ch + "' while parsing for int.");
            }

            result *= 10;
            result += ch - '0';
        } while (!isSpace(ch = nextChar()));

        return sign * result;
    }

    public long nextLong() throws IOException {
        //considering ASCII files--> 8 bit chars,     unicode files has 16 bit chars (byte1 then byte2)
        long result = 0;
        int sign = 1;
        int ch;
        while (isSpace(ch = nextChar())) ;

        if (ch == '-') {
            sign = -1;
            ch = nextChar();
        }

        do {
            if (ch < '0' || ch > '9') {
                throw new NumberFormatException("Found '" + ch + "' while parsing for int.");
            }

            result *= 10;
            result += ch - '0';
        } while (!isSpace(ch = nextChar()));

        return sign * result;
    }

    private boolean isSpace(int ch) {
        return ch == '\n' || ch == ' ' || ch == '\t' || ch == '\r' || ch == -1;
    }

    public void close() throws IOException {
        is.close();
    }
}


import java.io.IOException;
import java.io.InputStream;
import java.util.HashSet;
import java.util.Set;

public class Main {
    public static void main(String[] args) throws IOException {
        FastScanner s = new FastScanner(System.in);
        int n = s.nextInt();
        int k = s.nextInt();
        Set<Integer> set = new HashSet<Integer>();
        int count = 0;
        for (int i = 0; i < n; i++) {
            int t = s.nextInt();
            int m = t;
            boolean kgood = true;

            Set<Integer> set1 = new HashSet<Integer>();
            if (!set.contains(m)) {
                while (t > 0) {
                    int p = t % 10;
                    if (p <= k) {
                        set1.add(p);
                    } else {
                        kgood = false;
                        break;
                    }
                    t /= 10;
                }
            }

            if ((kgood && set1.size()==k) || set.contains(m)) {
                count++;
                set.add(m);
            }
        }

        System.out.println(count);
    }
}

class FastScanner {

    InputStream is;
    byte buff[] = new byte[1024];
    int currentChar = -1;
    int buffChars = 0;

    public FastScanner(InputStream inputStream) {
        is = inputStream;
    }

    public boolean hasNext() throws IOException {
        return buffChars >= 0;
    }

    public int nextChar() throws IOException {
        //if we already have that next char read, just return else input
        if (currentChar == -1 || currentChar >= buffChars) {
            currentChar = 0;
            buffChars = is.read(buff);
        }

        if (buffChars <= 0) {
            return -1;
        }

        return (char) buff[currentChar++];
    }

    public String nextString() throws IOException {
        StringBuilder bldr = new StringBuilder();
        int ch;
        while (isSpace(ch = nextChar())) ;

        do {
            bldr.append((char) ch);
        } while (!isSpace(ch = nextChar()));

        return bldr.toString();
    }

    public int nextInt() throws IOException {
        //considering ASCII files--> 8 bit chars,     unicode files has 16 bit chars (byte1 then byte2)
        int result = 0;
        int sign = 1;
        int ch;
        while (isSpace(ch = nextChar())) ;

        if (ch == '-') {
            sign = -1;
            ch = nextChar();
        }

        do {
            if (ch < '0' || ch > '9') {
                throw new NumberFormatException("Found '" + ch + "' while parsing for int.");
            }

            result *= 10;
            result += ch - '0';
        } while (!isSpace(ch = nextChar()));

        return sign * result;
    }

    public long nextLong() throws IOException {
        //considering ASCII files--> 8 bit chars,     unicode files has 16 bit chars (byte1 then byte2)
        long result = 0;
        int sign = 1;
        int ch;
        while (isSpace(ch = nextChar())) ;

        if (ch == '-') {
            sign = -1;
            ch = nextChar();
        }

        do {
            if (ch < '0' || ch > '9') {
                throw new NumberFormatException("Found '" + ch + "' while parsing for int.");
            }

            result *= 10;
            result += ch - '0';
        } while (!isSpace(ch = nextChar()));

        return sign * result;
    }

    private boolean isSpace(int ch) {
        return ch == '\n' || ch == ' ' || ch == '\t' || ch == '\r' || ch == -1;
    }

    public void close() throws IOException {
        is.close();
    }
}


import java.util.Scanner;

public class AA {
public static void main(String[] args) {
	Scanner sc =  new Scanner(System.in);
	int n = sc.nextInt();
	int k = sc.nextInt();
	int ans  = 0  ;
	for (int i = 1; i <=n; i++) {
		String s=sc.next();
		boolean f = false;
		for (int j = 0; j <=k; j++) {
			if(s.indexOf((j+""))>=0)
				f=false;
			else{
				f=true;
			break;
			}
		}
		if(!f)
			ans++;
	}
	System.out.println(ans);
}
}


import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.Writer;

import java.util.HashMap;
import java.util.InputMismatchException;

public class june13_A {

    public static boolean Contain(String s,int k){
        boolean flag=true;
        int len=s.length();
        for(int i=0;i<=k;i++){
            if(!s.contains(String.valueOf(i)))
                flag=false;
        }
        return flag;
    }

    public static void main(String args[]){
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        OutputWriter out = new OutputWriter(outputStream);

        int n=in.readInt();

        int k=in.readInt();

        String[] s=new String[n];
        for(int i=0;i<n;i++){
            s[i]=in.next();
            //out.printLine(s[i]);
        }
        int count=0;
        for(int i=0;i<n;i++){
            if(Contain(s[i], k))
                count++;
        }

        out.printLine(count);

        out.close();

        }

}
class InputReader {
    private InputStream stream;
    private byte[] buf = new byte[1024];
    private int curChar;
    private int numChars;

    public InputReader(InputStream stream) {
            this.stream = stream;
    }

    public int read(){
            if (numChars == -1)
            throw new InputMismatchException();
            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (numChars <= 0)
                    return -1;
            }
            return buf[curChar++];
    }
    public int readInt() {
        int c = read();
        while (isSpaceChar(c))
            c = read();
        int sgn = 1;
        if (c == '-') {
            sgn = -1;
            c = read();
        }
        int res = 0;
        do {
            if (c < '0' || c > '9')
                throw new InputMismatchException();
            res *= 10;
            res += c - '0';
            c = read();
        } while (!isSpaceChar(c));
        return res * sgn;
    }
    public long readLong() {
        int c = read();
        while(isSpaceChar(c))
            c = read();
    int sgn = 1;
    if (c == '-') {
        sgn = -1;
        c = read();
    }
    long res = 0;
    do {
        if (c < '0' || c > '9')
            throw new InputMismatchException();
        res *= 10;
        res += c - '0';
        c = read();
    } while (!isSpaceChar(c));
    return res * sgn;
    }
    public String readString() {
        int c = read();
        while (isSpaceChar(c))
            c = read();
        StringBuffer res = new StringBuffer();
        do {
            res.appendCodePoint(c);
            c = read();
        } while (!isSpaceChar(c));
        return res.toString();
    }
    public static boolean isSpaceChar(int c) {
        return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
    }
    public String next() {
        return readString();
    }
    }

class OutputWriter {
    private final PrintWriter writer;
    public OutputWriter(OutputStream outputStream) {
        writer = new PrintWriter(outputStream);
    }
    public OutputWriter(Writer writer) {
        this.writer = new PrintWriter(writer);
    }
    public void print(Object... objects) {
        for (int i = 0; i < objects.length; i++) {
            if (i != 0)
                writer.print(' ');
            writer.print(objects[i]);
        }
    }
    public void printLine(Object... objects) {
        print(objects);
        writer.println();
    }
    public void close() {
    writer.close();
    }
    }


import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.Writer;

import java.util.HashMap;
import java.util.InputMismatchException;

public class june13_A {

    public static boolean isGood(String s,int k){
        int n=s.length();
        boolean flag=true;
        for(int i=0;i<n;i++){

            if(Integer.valueOf(s.charAt(i))-48>k){
                flag=false;
                break;
            }

        }

        return flag;
    }

    public static boolean Contain(String s,int k){
        boolean flag=true;
        int len=s.length();
        for(int i=0;i<=k;i++){
            if(!s.contains(String.valueOf(i)))
                flag=false;
        }
        return flag;
    }

    public static void main(String args[]){
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        OutputWriter out = new OutputWriter(outputStream);

        int n=in.readInt();

        int k=in.readInt();

        String[] s=new String[n];
        for(int i=0;i<n;i++){
            s[i]=in.next();
            //out.printLine(s[i]);
        }
        int count=0;
        for(int i=0;i<n;i++){
            if(Contain(s[i], k)&&isGood(s[i], k))
                count++;
        }

        out.printLine(count);

        out.close();

        }

}
class InputReader {
    private InputStream stream;
    private byte[] buf = new byte[1024];
    private int curChar;
    private int numChars;

    public InputReader(InputStream stream) {
            this.stream = stream;
    }

    public int read(){
            if (numChars == -1)
            throw new InputMismatchException();
            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (numChars <= 0)
                    return -1;
            }
            return buf[curChar++];
    }
    public int readInt() {
        int c = read();
        while (isSpaceChar(c))
            c = read();
        int sgn = 1;
        if (c == '-') {
            sgn = -1;
            c = read();
        }
        int res = 0;
        do {
            if (c < '0' || c > '9')
                throw new InputMismatchException();
            res *= 10;
            res += c - '0';
            c = read();
        } while (!isSpaceChar(c));
        return res * sgn;
    }
    public long readLong() {
        int c = read();
        while(isSpaceChar(c))
            c = read();
    int sgn = 1;
    if (c == '-') {
        sgn = -1;
        c = read();
    }
    long res = 0;
    do {
        if (c < '0' || c > '9')
            throw new InputMismatchException();
        res *= 10;
        res += c - '0';
        c = read();
    } while (!isSpaceChar(c));
    return res * sgn;
    }
    public String readString() {
        int c = read();
        while (isSpaceChar(c))
            c = read();
        StringBuffer res = new StringBuffer();
        do {
            res.appendCodePoint(c);
            c = read();
        } while (!isSpaceChar(c));
        return res.toString();
    }
    public static boolean isSpaceChar(int c) {
        return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
    }
    public String next() {
        return readString();
    }
    }

class OutputWriter {
    private final PrintWriter writer;
    public OutputWriter(OutputStream outputStream) {
        writer = new PrintWriter(outputStream);
    }
    public OutputWriter(Writer writer) {
        this.writer = new PrintWriter(writer);
    }
    public void print(Object... objects) {
        for (int i = 0; i < objects.length; i++) {
            if (i != 0)
                writer.print(' ');
            writer.print(objects[i]);
        }
    }
    public void printLine(Object... objects) {
        print(objects);
        writer.println();
    }
    public void close() {
    writer.close();
    }
    }


import java.io.InputStreamReader;
import java.io.IOException;
import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Hashtable;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.PriorityQueue;
import java.util.Queue;
import java.util.Scanner;
import java.util.Set;
import java.util.TreeSet;
import java.io.BufferedReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.InputStream;
import java.math.BigDecimal;
import java.math.BigInteger;
import javax.naming.BinaryRefAddr;

public class palin {
	public static void main(String[] args) {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		InputReader in = new InputReader(inputStream);
		PrintWriter out = new PrintWriter(System.out);
		Scanner scan = new Scanner(System.in);
		TaskC solver = new TaskC();
		solver.solve(1, in, out);
		out.close();
	}
}

class TaskC {
	public void solve(int testNumber, InputReader in, PrintWriter out) {
		int n = in.nextInt(), k = in.nextInt(), res = 0;
		for (int i = 0; i < n; i++) {
			boolean ok[] = new boolean[k + 1];
			String str = in.next();
			for (int j = 0; j < str.length(); j++) {
				if (str.charAt(j) - '0' <= k) {
					ok[str.charAt(j) - '0'] = true;
				} else {
					ok[0] = false;
					break;
				}
			}
			for (int j = 0; j < ok.length; j++) {
				if (!ok[j]) {
					break;
				} else {
					if (j == ok.length - 1) {
						res++;
					}
				}
			}
		}
		out.print(res);
	}
}

class InputReader {
	BufferedReader br;
	StringTokenizer st;

	public InputReader(InputStream in) {
		br = new BufferedReader(new InputStreamReader(in));
		st = null;
	}

	public String next() {
		while (st == null || !st.hasMoreTokens()) {
			try {
				st = new StringTokenizer(br.readLine());
			} catch (IOException e) {
				throw new RuntimeException(e);
			}
		}
		return st.nextToken();
	}

	public int nextInt() {
		return Integer.parseInt(next());
	}

	public long nextLong() {
		return Long.parseLong(next());
	}

	public float nextFloat() {
		return Float.parseFloat(next());
	}

	public double nextDouble() {
		return Double.parseDouble(next());
	}
}


import java.io.InputStreamReader;
import java.io.IOException;
import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Hashtable;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.PriorityQueue;
import java.util.Queue;
import java.util.Scanner;
import java.util.Set;
import java.util.TreeSet;
import java.io.BufferedReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.InputStream;
import java.math.BigDecimal;
import java.math.BigInteger;
import javax.naming.BinaryRefAddr;

public class palin {
	public static void main(String[] args) {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		InputReader in = new InputReader(inputStream);
		PrintWriter out = new PrintWriter(System.out);
		Scanner scan = new Scanner(System.in);
		TaskC solver = new TaskC();
		solver.solve(1, in, out);
		out.close();
	}
}

class TaskC {
	public void solve(int testNumber, InputReader in, PrintWriter out) {
		int n = in.nextInt(), k = in.nextInt(), res = 0;
		for (int i = 0; i < n; i++) {
			boolean ok[] = new boolean[k + 1];
			String str = in.next();
			for (int j = 0; j < str.length(); j++) {
				if (str.charAt(j) - '0' <= k) {
					ok[str.charAt(j) - '0'] = true;
				} else {
				//	ok[0] = false;
					//break;
				}
			}
			for (int j = 0; j < ok.length; j++) {
				if (!ok[j]) {
					break;
				} else {
					if (j == ok.length - 1) {
						res++;
					}
				}
			}
		}
		out.print(res);
	}
}

class InputReader {
	BufferedReader br;
	StringTokenizer st;

	public InputReader(InputStream in) {
		br = new BufferedReader(new InputStreamReader(in));
		st = null;
	}

	public String next() {
		while (st == null || !st.hasMoreTokens()) {
			try {
				st = new StringTokenizer(br.readLine());
			} catch (IOException e) {
				throw new RuntimeException(e);
			}
		}
		return st.nextToken();
	}

	public int nextInt() {
		return Integer.parseInt(next());
	}

	public long nextLong() {
		return Long.parseLong(next());
	}

	public float nextFloat() {
		return Float.parseFloat(next());
	}

	public double nextDouble() {
		return Double.parseDouble(next());
	}
}


import java.io.*;

public class A {
	public static void main(String[] args) throws IOException {
		Parser in = new Parser(System.in);
		int n = in.nextInt();
		int k = in.nextInt();
		int m = 0;
		for (int i = 0; i < n; i++) {
			int a = in.nextInt();
			boolean[] f = new boolean[10];
			for (int j = 1; j <= a; j*=10)
				f[a/j%10] = true;
			boolean g = true;
			for (int j = 0; j < k; j++)
				g = g && f[j];
			if (g) m++;
		}
		System.out.println(m);
	}
}

class Parser {
	public Parser (InputStream in) {
		this.in = new DataInputStream(in);
	}

	public int nextInt() throws IOException {
		int c;
		while ((c = in.read()) != '-' && (c > '9' || c < '0'));
		boolean neg = c == '-';
		if (neg) c = in.read();
		int r = 0;
		do r = r*10 + c - '0'; while ((c = in.read()) <= '9' && c >= '0');
		if (neg) return -r;
		return r;
	}

	public String nextName() throws IOException {
		int c;
		while (((c = in.read()) > 'Z' || c < 'A') && (c < 'a' || c > 'z'));
		String s = "";
		while (c <= 'Z' && c >= 'A' || c >= 'a' && c <= 'z') {
			s += (char)c;
			c = in.read();
		}
		return s;
	}

	DataInputStream in;
}


import java.io.*;

public class A {
	public static void main(String[] args) throws IOException {
		Parser in = new Parser(System.in);
		int n = in.nextInt();
		int k = in.nextInt();
		int m = 0;
		for (int i = 0; i < n; i++) {
			int a = in.nextInt();
			boolean[] f = new boolean[10];
			for (int j = 1; j <= a; j*=10)
				f[a/j%10] = true;
			boolean g = true;
			for (int j = 0; j <= k; j++)
				g = g && f[j];
			if (g) m++;
		}
		System.out.println(m);
	}
}

class Parser {
	public Parser (InputStream in) {
		this.in = new DataInputStream(in);
	}

	public int nextInt() throws IOException {
		int c;
		while ((c = in.read()) != '-' && (c > '9' || c < '0'));
		boolean neg = c == '-';
		if (neg) c = in.read();
		int r = 0;
		do r = r*10 + c - '0'; while ((c = in.read()) <= '9' && c >= '0');
		if (neg) return -r;
		return r;
	}

	public String nextName() throws IOException {
		int c;
		while (((c = in.read()) > 'Z' || c < 'A') && (c < 'a' || c > 'z'));
		String s = "";
		while (c <= 'Z' && c >= 'A' || c >= 'a' && c <= 'z') {
			s += (char)c;
			c = in.read();
		}
		return s;
	}

	DataInputStream in;
}


import java.util.Scanner;
import java.io.OutputStream;
import java.io.IOException;
import java.util.Arrays;
import java.io.PrintWriter;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskA solver = new TaskA();
        solver.solve(1, in, out);
        out.close();
    }
}

class TaskA {
    String[] s;
    int n, k;
    public void solve(int testNumber, Scanner in, PrintWriter out) {
        n = in.nextInt();
        k = in.nextInt();
        in.nextLine();
        s = new String[n];
        for (int i = 0; i < n; ++i)
            s[i] = in.nextLine();
        char ch = Integer.toString(k).charAt(0);
        int res = 0;
        boolean[] check = new boolean[300];
        for (int i = 0; i < n; ++i) {
            Arrays.fill(check, false);
            for (int j = 0; j < s[i].length(); ++j)
                check[s[i].charAt(j)] = true;
            boolean ok = true;
            for (char j = '0'; j <= ch; ++j)
                if (!check[j])
                    ok = false;
            if (ok) res++;
        }
        out.println(res);
    }
}


/*In The Name Of The God*/

#include <bits/stdc++.h>
using namespace std;
#define Fight_Club cin.tie(0);cout.tie(0);std::ios::sync_with_stdio(false);
typedef long long ll;
typedef long double ld;
ll n,m,k,s[5050],x;
ll mem[5050][5050];
ll re(ll i,ll t){
    if(i-1>n)return(t!=0)*-1e18;
    if(mem[i][t]!=-1)return mem[i][t];
    ll mx=max(re(i+1,t),s[i+m]-s[i]+re(i+m,t-1));
    return mem[i][t]=mx;
}
int main()
{
    //Fight_Club
    memset(mem,-1,sizeof(mem));
    cin>>n>>m>>k;
    for(int i=1;i<=n;i++)cin>>x,s[i]=x+s[i-1];
    cout<<re(0,k);
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
const int M=5010;
long long n,m,k,a[M],s[M],f[M][M];
int main()
{
    cin>>n>>m>>k;
    for(int i=1;i<=n;i++) cin>>a[i];
    s[0]=0;
    for(int i=1;i<=n;i++) s[i]=s[i-1]+a[i];
    for(int i=1;i<=n;i++)
    {
    	for(int j=1;j<=k;j++)
    	{
    		f[i][j]=f[i-1][j];
    		if(i>=m) f[i][j]=max(f[i][j],f[i-m][j-1]+s[i]-s[i-m]);
		}
	}
	cout<<f[n][k]<<endl;
}


#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
int sum[6000],n,m,k,a[6000];
long long f[2][6000];
int main()
{
  cin>>n>>m>>k;
  for(int i=1;i<=n;i++)
  scanf("%d",&a[i]);
  for(int i=1;i<=n;i++)
  sum[i]=sum[i-1]+a[i];
  for(int i=1;i<=k;i++)
  for(int j=1;j<=n;j++)
  {
    int cur=i&1;
  	if(i*m>j) f[cur][j]=0;
    else f[cur][j]=max(f[cur][j-1],f[cur^1][j-m]+sum[j]-sum[j-m]);
  }
  cout<<f[k&1][n];
  return 0;
}


#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<queue>
#include<set>
#include<vector>
using namespace std;
typedef long long ll;
inline int read()
{
    char ch=getchar();int x=0,f=1;
    while(ch<'0' || ch>'9') {
       if(ch=='-') f=-1;
      	  ch=getchar();
    }
    while(ch<='9' && ch>='0') {
       x=x*10+ch-'0';
       ch=getchar();
    }
    return x*f;
}
inline ll readl()
{
    char ch=getchar();ll x=0,f=1;
    while(ch<'0' || ch>'9') {
       if(ch=='-') f=-1;
      	  ch=getchar();
    }
    while(ch<='9' && ch>='0') {
       x=x*10+ch-'0';
       ch=getchar();
    }
    return x*f;
}
const int maxn = 5001;
int n,m,k;
ll sum[maxn],p[maxn];
ll f[maxn][maxn];
int main()
{
	n = read();m = read();k = read();
	for(int i = 1 ;i <= n ;i++)
	p[i] = readl(),sum[i] = sum[i-1] + p[i];
	for(int i = 1  ;i <= n ;i++)
	{
		for(int j = 1; j <= k ;j++)
		{
			f[i][j] = f[i-1][j];
			if(i >= m)f[i][j] = max(f[i][j],f[i-m][j-1] + sum[i] - sum[i-m]);
		}
	}
	cout<<f[n][k];
	return 0;
}
/*
long long
long long
long long
long long
long long
long long
long long
long long
long long
long longlong long
long long
*/


#include<bits/stdc++.h>
#define ll long long
using namespace std;
ll n,m,k,p[5010],s[5010],dp[5010][5010];
int main(){
//	freopen(".in","r",stdin);
//	freopen(".out","w",stdout);
	scanf("%lld%lld%lld",&n,&m,&k);
	for(int i=1;i<=n;i++){
		scanf("%lld",&p[i]);
		s[i]=s[i-1]+p[i];
	}
	for(int i=1;i<=n;i++){
		for(int j=0;j<=k;j++){
			if(i>=m&&j)dp[i][j]=max(dp[i-1][j],dp[i-m][j-1]+s[i]-s[i-m]);
		}
	}
	printf("%lld",dp[n][k]);
//	fclose(stdin);
//	fclose(stdout);
	return 0;
}
/*

*/


#include <iostream>
#include <stdio.h>
#include <string.h>
using namespace std;
typedef long long ll;
ll n,m,k,p[5010],s[5010],ans,f[5010][5010];
int main()
{
	scanf("%lld%lld%lld",&n,&m,&k);
	for(ll i=1;i<=n;i++)
	{
		scanf("%lld",&p[i]);
		s[i]=s[i-1]+p[i];
	}
	for(ll i=m;i<=n;i++)
	{
		ll ss=s[i]-s[i-m];
		for(ll j=1;j<=k;j++)
		{
			f[i][j]=f[i-1][j];
			f[i][j]=max(f[i-m][j-1]+ss,f[i][j]);
		}
	}
	printf("%lld\n",f[n][k]);
}


#include<bits/stdc++.h>
using namespace std;
int n,m,k,bo,s,a[5100];
int main()
{
	cin>>n>>m>>k;
	for(int i=1;i<=n;i++) {scanf("%d",&a[i]);s+=a[i];}
	sort(a+1,a+n+1);
	for(int i=1;i<=n-m*k;i++) s-=a[i];
	cout<<s<<"\n";
	return 0;
 }


// This code writed by chtholly_micromaker(MicroMaker)
#include <bits/stdc++.h>
#define reg register
#define int long long
using namespace std;
const int MaxN=5050;
template <class t> inline void rd(t &s)
{
	s=0;
	reg char c=getchar();
	while(!isdigit(c))
		c=getchar();
	while(isdigit(c))
		s=(s<<3)+(s<<1)+(c^48),c=getchar();
	return;
}
int a[MaxN],g[MaxN];
int f[MaxN][MaxN];
signed main(void)
{
	int n,m,k;
	cin>>n>>m>>k;
	for(int i=1;i<=n;++i)
		rd(a[i]),g[i]=g[i-1]+a[i];
	for(int i=1;i<=k;++i)
		for(int j=1;j<=n;++j)
			if(j-m+1>0)
				f[i][j]=max(f[i][j-1],f[i-1][j-m]+g[j]-g[j-m]);
	reg int ans=0;
	for(int i=1;i<=n;++i)
		ans=max(ans,f[k][i]);
	cout<<ans<<endl;
	return 0;
}


#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
long long n,m,k,a[5005],s[5005],f[5005][5005];//注意用longlong
int main()
{
    scanf("%lld %lld %lld",&n,&m,&k);
    for(int i=1;i<=n;i++) scanf("%d",&a[i]);
    long long tot=0;
    for(int i=1;i<=n;i++)
    {
        tot+=a[i];
        if(i>=m)
        {
            s[i]=tot;
            tot-=a[i-m+1];
        }
    }
    for(int i=m;i<=n;i++)
    {
        for(int j=1;j<=min(i/m,k);j++)
        {
            f[i][j]=f[i-1][j];
            f[i][j]=max(f[i][j],f[i-m][j-1]+s[i]);
            //状态转移方程，别忘记判断
        }
    }
    printf("%lld",f[n][k]);//输出
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int a[5005],sum[5005],f[5005];
int n,m;
int dfs(int l,int r,int k){
	int ans=0;
	if(k==0)return 0;
	for(int i=l;i<=r-k*m+1;i++){
		int j=i+m-1;
		ans=max(ans,sum[j]-sum[i-1]+dfs(j,r,k-1));
	}
	return ans;
}
int main(){
	int k;
	cin>>n>>m>>k;
	for(int i=1;i<=n;i++){
		cin>>a[i];
		sum[i]=sum[i-1]+a[i];
	}
	cout<<dfs(1,n,k)<<endl;

	return 0;
}


#include <bits/stdc++.h>
using namespace std;
const int N=5e3+5;
int n,m,k,x;
int sum[N],f[N][N];
//f[i][j]:前i个，用了j个
int main(){
	scanf("%d%d%d",&n,&m,&k);
	for (register int i=1; i<=n; ++i) scanf("%d",&x),sum[i]=sum[i-1]+x;
	for (register int i=m; i<=n; ++i)
	for (register int j=1; j<=min(i/m,k); ++j)
	{
		f[i][j]=f[i-m][j-1]+sum[i]-sum[i-m];
		f[i][j]=max(f[i][j],f[i-1][j]);
	}
	printf("%d\n",f[n][k]);
return 0;
}


#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
#define N 5000
using namespace std;

int n,m,k,a[N+5],s[N+5];
int f[N+5][N+5],ans;

int main(){

	cin>>n>>m>>k;
	for(int i=1;i<=n;i++){
		scanf("%d",&a[i]);
		s[i]=s[i-1]+a[i];
	}

	for(int i=m;i<=n;i++)f[1][i]=s[i]-s[i-m];
	for(int i=1;i<=k;i++){//选i组
		for(int j=m*i;j<=n;j++){//以j结尾
			if(i==1){
				f[i][j]=s[j]-s[j-m];
				if(i==k)ans=max(ans,f[i][j]);
				continue;
			}
			for(int l=m*(i-1);l<=j-m;l++){//上一个结尾为l
				f[i][j]=max(f[i][j],f[i-1][l]+s[j]-s[j-m]);
			}
			if(i==k)ans=max(ans,f[i][j]);
		}
		/*
		for(int ii=1;ii<=k;ii++){
			for(int jj=1;jj<=n;jj++){
				cout<<f[ii][jj]<<" ";
			}
			cout<<endl;
		}
		cout<<endl;
		*/
	}
	cout<<ans;

	return 0;
}
/*
7 1 7
2 10 7 18 5 33 0
*/


#include <bits/stdc++.h>

using namespace std;

const int MAXN = 5123;

int p[MAXN], n, m, k;
long long f[MAXN][MAXN], s[MAXN], sum;

signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    cin >> n >> m >> k;
    for (int i = 0; i <= n; i++) {
        cin >> p[i];
        if (i - m >= 0) {
            s[i - m] = sum;
            sum -= p[i - m];
        }
        sum += p[i];
    }
    for (int i = n - 1; i >= 0; i--) {
        for (int j = 1; j <= k; j++) {
            f[i][j] = max(f[i][j], max(f[i + 1][j], s[i] + f[i + m][j - 1]));
        }
    }
    cout << f[0][k] << endl;

    return 0;
}
/**
2 2 1 2 1
1 2
2 3
*/


#include<bits/stdc++.h>
#define int long long
using namespace std;
int n,m,k,s[5001],dp[5001][5001];
bool ans;
signed main(){
	cin>>n>>m>>k;
	s[0]=0;
	for(int i=1;i<=n;++i)
	{
		int q;
		cin>>q;
		s[i]=s[i-1]+q;
	}
	for(int i=1;i<=k;++i)
	{
		int mx=0;
		ans=!ans;

		for(int j=m;j<=n;++j)
		{
			dp[ans][j]=max(dp[ans][j],dp[ans][j-1]);
			mx=max(mx,dp[!ans][j-m]);
			dp[ans][j]=max(dp[ans][j],mx+s[j]-s[j-m]);
		}
	}
	cout<<dp[ans][n];
	return 0;
}


#include<bits/stdc++.h>
#define ll long long
using namespace std;
ll sum[100000],n,m,k,dp[10000][500],a[10000];
int main()
{
	cin>>n>>m>>k;
	for(int i=1;i<=n;++i)
	{
		cin>>a[i];
		sum[i]=sum[i-1]+a[i];
	}
	for(int i=0;i<=n;++i)
	{
		for(int j=1;j<=k;++j)
		{
			dp[i][j]=max(dp[i-m][j-1]+sum[i]-sum[i-m],max(dp[i][j],dp[i-1][j]));
		}
	}
	ll mm=0;
	for(int i=1;i<=n;++i) mm=max(mm,dp[i][k]);
	cout<<mm<<endl;
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
const int fs=-1e9-7;
int main(){
    long long f[5005]={};
    int n,m,num;
    cin>>n>>m>>num;
    long long a[5005]={};
    long long sum[5005]={};
    for(int i=1;i<=n;i++){
        scanf("%lld",&a[i]);
        sum[i]=a[i]+sum[i-1];
    }
    for(int i=1;i<=num;i++){
        for(int j=n;j>=1;j--){
            if(j<=m*(i-1)){
                f[j]=fs;
            }
            else{
                for(int k=1;k<=j-m;k++){
                    f[j]=max(f[j],f[k]+sum[j]-sum[j-m]);
                }
            }
        }
    }
    long long mx=0;
    for(int i=1;i<=n;i++){
        mx=max(mx,f[i]);
    }
    cout<<mx;
}


#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#define ll long long
using namespace std;
#define N 5010
long long sum[N];
int n,m,k;
long long x;
long long dp[N][N];
int main(){
   scanf("%d%d%d",&n,&m,&k);
    for(int i=1;i<=n;i++)
    scanf("%lld",&x),sum[i]=sum[i-1]+x;
    memset(dp,-1,sizeof(dp));
    for(int i=0;i<=n;i++)
    dp[i][0]=0;
   	 for(int i=1;i<=n;i++)
    for(int j=1;j<=k;j++)
    {
      dp[i][j]=dp[i-1][j];
      if(i>=m&&dp[i-m][j-1]>-1)
      dp[i][j]=max(dp[i][j],dp[i-m][j-1]+(sum[i]-sum[i-m]));
    }
    printf("%lld",dp[n][k]);
}


#include <cstdio>
#include <queue>
using namespace std;
queue <long long> q[5005];
long long a[5005],sum[5005],f[5005];
int n,len,m;
int main()
{
	scanf("%d%d%d",&n,&len,&m);
	for(int i=1;i<=n;++i)
		scanf("%lld",&a[i]),sum[i]=sum[i-1]+a[i];
	for(int i=len;i<=n;++i)
	{
//		printf("i=%d\n",i);
		for(int j=1;j*len<i&&j<=m;++j)
		{
			f[j]=max(f[j],q[j].front());
			q[j].pop();
		}
		for(int j=1;j*len<=i&&j<=m;++j)
		{
			long long dq=f[j-1]+sum[i]-sum[i-len];
			q[j].push(dq);
//			printf("g(%d)=%d\n",j,dq);
		}
	}
	while(!q[m].empty()) f[m]=max(f[m],q[m].front()),q[m].pop();
	printf("%lld",f[m]);
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int n,m,k,dp[10010][10010],sum[10010],a;
int main()
{
	scanf("%d%d%d",&n,&m,&k);
	for(int i=1;i<=n;i++)
	{
		scanf("%d",&a);
		sum[i]=sum[i-1]+a;
	}
	for(int i=m;i<=n;i++)
		for(int j=1;j<=k;j++)
			dp[i][j]=max(dp[i-1][j],dp[i-m][j-1]+sum[i]-sum[i-m]);
	printf("%d\n",dp[n][k]);
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int n,m,k,a[10005],sum[10005],dp[5005][5005];
int main()
{
	cin>>n>>m>>k;
	for(int i=1;i<=n;i++)
	{
		cin>>a[i];
		sum[i]=sum[i-1]+a[i];
	}
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=k;j++)
		{
			if(i>=m)
				dp[i][j]=max(dp[i-1][j],dp[i-m][j-1]+sum[i]-sum[i-m]);
			else
				dp[i][j]=dp[i-1][j];
		}
	}
	cout<<dp[n][k];
	return 0;
}


#include<cstdio>
#include<algorithm>
using namespace std;
int n,m,k,a[5005];
long long b[5005],maxn;
void dfs(int x,int num,int tot){
	if(num==0){
		if(tot>maxn)	maxn=tot;
		return;
	}
	tot+=b[x+k]-b[x];
	for(int i=x+k;i<=n-k+1;i++){
		dfs(i,num-1,tot);
	}
}
int main(){
	scanf("%d %d %d",&n,&m,&k);
	for(int i=1;i<=n;i++){
		scanf("%d",&a[i]);
		b[i]=a[i]+b[i-1];
	}
	dfs(1,m,0);
	printf("%lld",maxn);
}


#include<iostream>
using namespace std;
long long n,m,k;
long long a[5001];
long long f[5001][5001];
int s(int i){
	int num=0;
	for(int j=i;j>i-m;j--){
		num+=a[j];
	}
	return num;
}
int main(){

	cin>>n>>m>>k;
	for(int i=1;i<=n;i++)
		cin>>a[i];
	for(int kk=1;kk<=k;kk++){
		for(int i=m;i<=n;i++){
			int num=s(i);
			for(int j=m;j<i;j++){

				f[i][kk]=max(f[i][kk],f[j][kk-1]+num);

			}
		}
	}
	long long  MAX=0;
	for(int i=1;i<=n;i++){
	//	cout<<f[i][k]<<endl;
		MAX=max(MAX,f[i][k]);
	}
	cout<<MAX;
	return 0;

}
/*m k
5 2 1
1 2 3 4 5
*/


#include<bits/stdc++.h>
#define N 5005
using namespace std;
int n,m,k;
long long dp[N][N],a[N],s[N];
int main()
{
	scanf("%d%d%d",&n,&m,&k);
	for (int i=1;i<=n;i++)
		scanf("%lld",&a[i]),s[i]=s[i-1]+a[i];
	for (int i=1;i<=n;i++)
		for (int j=0;j<=k;j++)
		{
			dp[i][j]=dp[i-1][j];
			if (i>=m&&j)
				dp[i][j]=max(dp[i][j],dp[i-m][j-1]+s[i]-s[i-m]);
		}
	cout << dp[n][k] << endl;
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int sz=510;
int n,m,k;
ll a[sz],f[sz][sz];//f[i][x]：在区间[1,i]选择x个长为m的区间 的最大值
//f[i][x]=max(f[i][x],f[i-m][x-1]+a[i->i-m+1])
//目标f[n][k]
int main()
{
	scanf("%d%d%d",&n,&m,&k);
	for(int i=1;i<=n;i++)scanf("%lld",&a[i]);
	for(int i=m;i<=n;i++)
	{
		for(int x=1;x<=k;x++)
		{
			if(x*m>i)break;
			int tmp=0;
			for(int T=i-m+1;T<=i;T++)tmp+=a[T];
			f[i][x]=max(f[i][x],f[i-m][x-1]+tmp);
		}
	}
	printf("%lld",f[n][k]);
	return 0;
}
/*
17 5 3
10 9 7 6 12 5 7 6 7 11 3 9 7 13 8 6 11

*/


#include<bits/stdc++.h>
#define y1 y749872
#define next nxt
using namespace std;
int i,j,k,n,s,t,m;
inline int read()
{
	int num=0;
	char ch=getchar();
	while(ch>'9'||ch<'0')
	ch=getchar();
	while(ch<='9'&&ch>='0')
	{
		num=num*10+ch-48;
		ch=getchar();
	}
	return num;
}
const int N=5e3+10;
long long dp[N][N],a[N],sum[N];
int main()
{
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	//freopen(".ans","w",sdtout);
	scanf("%d%d%d",&n,&m,&k);
	for(i=1;i<=n;i++)
	{
		scanf("%lld",&a[i]);
		sum[i]=sum[i-1]+a[i];
	}
	for(i=1;i<=n;i++)
	for(j=1;j<=k;j++)
	dp[i][j]=max(dp[i-m][j-1]+sum[i]-sum[i-m],dp[i-1][j]);
	cout<<dp[n][k];
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int sz=510;
int n,m,k;
ll a[sz],f[sz][sz][sz];//f[i][x]：在区间[1,i]选择x个长为m的区间 的最大值
//f[i][x]=max(f[i][x],f[i-m][x-1]+a[i->i-m+1])
//目标f[n][k]
int main()
{
	scanf("%d%d%d",&n,&m,&k);
	for(int i=1;i<=n;i++)scanf("%lld",&a[i]);
	/*for(int i=m;i<=n;i++)
	{
		for(int x=1;x<=k;x++)
		{
			if(x*m>i)break;
			int tmp=0;
			for(int T=i-m+1;T<=i;T++)tmp+=a[T];
			f[i][x]=max(f[i][x],f[i-m][x-1]+tmp);
		}
	}*/
	for(int l=m;l<=n;l++)
	{
		for(int i=1;i<=n;i++)
		{
			int j=i+l-1;
			if(j>n)break;
			for(int x=1;x<=k;x++)
			{
				if(x*m>l)break;
				int tmp1=0,tmp2=0;
				for(int T=i+m-1;T>=i;T--)tmp1+=a[T];
				for(int T=j-m+1;T<=j;T++)tmp2+=a[T];
				f[i][j][x]=max(f[i][j][x],f[i+m-1][j][x-1]+tmp1);
				f[i][j][x]=max(f[i][j][x],f[i][j-m+1][x-1]+tmp2);
			}
		}
	}
	printf("%lld",f[1][n][k]);
	return 0;
}
/*
17 5 3
10 9 7 6 12 5 7 6 7 11 3 9 7 13 8 6 11

*/


#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<iostream>
using namespace std;
int n,m,k;
int p[5005];
int f[5005][5005];
int s[5005];
int cnt,tot;
int main()
{
	scanf("%d%d%d",&n,&m,&k);
	for(int i=1;i<=n;i++)
	{
	 scanf("%d",&p[i]);
	 tot+=p[i];
	 if(i>=m)
	 {
	  s[i]=tot;
	  tot-=p[i-m+1];
	 }
    }
    memset(f,-1,sizeof(f));
    for(int i=0;i<=n;i++) f[i][0]=0;
    for(int i=1;i<=n;i++)
    {
      for(int j=1;j<=k;j++)
	  {
	     f[i][j]=f[i-1][j];
		 if(i>=m&&f[i-m][j-1]!=-1)
		 f[i][j]=max(f[i][j],f[i-m][j-1]+s[i]);
      }
    }
    printf("%d\n",f[n][k]);
 return 0;
}


#include <iostream>

using namespace std;

long long f[5005][5005], a[5005];

int main() {
    long long n, m, k;
    cin >> n >> m >> k;
    for (int i=1; i<=n; ++i) cin >> a[i], a[i]+=a[i-1];
    for (int i=m; i<=n; ++i) {
        for (int j=1; j<=k; ++j) {
            f[i][j] = max(f[i-1][j], f[i-m][j-1]+a[i]-a[i-m]);
        }
    }
    cout << f[n][k] << endl;
}


#include<queue>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#define lson l,m,rt<<1
#define int long long
using namespace std;
int n,m,k,p,q,a[5001],sum[5001],dp[5001][5001];
int in()
{
	int x=0,f=1;
	char ch=getchar();
	while(!isdigit(ch))
	{
		if(ch=='-')f=-1;
		ch=getchar();
	}
	while(isdigit(ch))
	{
		x=(x<<1)+(x<<3)+(ch^48);
		ch=getchar();
	}
	return x*f;
}
signed main()
{
	n=in();
	m=in();
	k=in();
	memset(dp,-1,sizeof(dp));
	for(int i=1;i<=n;i++)
	{
		a[i]=in();
		p+=a[i];
		if(i>=m)
		{
			sum[i]=p;
			p-=a[i-m+1];
		}
	}
	for(int i=0;i<=n;i++)
	{
		dp[i][0]=0;
	}
	 for(int i=1;i<=n;i++)
	 {
	 	for(int j=1;j<=k;j++)
	 	{
	 		dp[i][j]=dp[i-1][j];
	 		if(dp[i-m][j-1]>-1&&i>=m)dp[i][j]=max(dp[i][j],dp[i-m][j-1]+sum[i]);
		}
	 }
	 printf("%lld",dp[n][k]);
}


#include<iostream>
#include<cmath>
#include<algorithm>
#include<cstdio>
using namespace std;
long long n,m,k,a[5005],sum[5005],dp[5005][5005];
int main()
{
	scanf("%lld %lld %lld",&n,&m,&k);
	for(int i = 1;i <= n; i ++)
	{
		scanf("%lld",&a[i]);
		sum[i] = sum[i - 1] + a[i];
	}
	for(int j = 1;j <= k; j ++)
	{
		for(int i = j * m;i <= n;i ++)
		{
			dp[i][j] = max(dp[i][j],dp[i - m][j - 1] + sum[i] - sum[i - m + 1]);
		}
	}
	printf("%lld\n",dp[k][n]);
	return 0;
}


#include<cstdio>
#include<cstring>
#include<iostream>

const int Maxn = 5005;
typedef long long ll;
using namespace std;

int n,m,k;
ll a[Maxn];
ll sum[Maxn];
ll dp[Maxn][Maxn];

int main(){
	scanf("%d%d%d",&n,&m,&k);
	for(int i=1;i<=n;i++)
		scanf("%lld",&a[i]);
	for(int i=1;i<=n;i++){
		if(i<=m)
			sum[i]=sum[i-1]+a[i];
		else
			sum[i]=sum[i-1]-a[i-m]+a[i];
	//	cout<<sum[i]<<endl;
	}
	for(int i=1;i<=n;i++)
		for(int j=1;j<=k;j++)
			if(i>=m){
				dp[i][j]=max(dp[i][j],dp[i-1][j]);
				dp[i][j]=max(dp[i][j],dp[i-m][j-1]+sum[i]);
			}
	printf("%lld",dp[n][k]);
}


#include<cstdio>
using namespace std;

#define max(x,y) x>y?x:y
long long n,m,k,a[5005],sum[5005],tmp;
long long dp[5005][5005];

int main()
{
	scanf("%lld%lld%lld",&n,&m,&k);
	for(register int i=1;i<=n;i++)
	{
		scanf("%lld",&a[i]);
		tmp+=a[i];
		if(i>=m)
		{
			sum[i]=tmp;
			tmp-=a[i-m+1];
		}
	}
	for(register int i=1;i<=n;i++)
	{
		dp[i][0]=0;
		for(register int j=1;j<=n;j++)
			dp[i][j]=-1;
	}
	for(register int i=1;i<=n;i++)
	{
		for(register int j=1;j<=k;j++)
		{
			dp[i][j]=dp[i-1][j];
			if(i>=m&&dp[i-m][j-1]!=-1)dp[i][j]=max(dp[i][j],dp[i-m][j-1]+sum[i]);
		}
	}
	printf("%lld\n",dp[n][k]);
	return 0;
}


#include <iostream>
#include <cstring>
#include <cstdio>
#include <cmath>
using namespace std;typedef long long int ll;const int N=5007;ll dp[N][4]={0},s[N];int n,m,K;
int main()
{
    ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
    cin>>n>>m>>K;for(int i=1;i<=n;++i)cin>>s[i],s[i]+=s[i-1];
    for(int k=1;k<=K;++k)for(int i=1;i<=n;++i)
        dp[i][k&1]=(i>=m)?max(dp[i-1][k&1],dp[i-m][(k-1)&1]+s[i]-s[i-m]):dp[i-1][k&1];
    cout<<dp[n][K&1];cout<<flush;return 0;
}


#include<iostream>
using namespace std;
int n,m,k;
int a[5001];
int f[5001][5001];
int s(int i){
	int num=0;
	for(int j=i;j>i-m;j--){
		num+=a[j];
	}
	return num;
}
int main(){

	cin>>n>>m>>k;
	for(int i=1;i<=n;i++)
		cin>>a[i];
	for(int kk=1;kk<=k;kk++){
		for(int i=m;i<=n;i++){
			int num=s(i);
			for(int j=m;j<i;j++){

				f[i][kk]=max(f[i][kk],f[j][kk-1]+num);

			}
		}
	}
	int MAX=0;
	for(int i=1;i<=n;i++){
	//	cout<<f[i][k]<<endl;
		MAX=max(MAX,f[i][k]);
	}
	cout<<MAX;
	return 0;

}
/*m k
5 2 1
1 2 3 4 5
*/


#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#define ll long long
using namespace std;
int n, m, k;
ll f[5005][5005],a[5005];
ll s[5005];
inline long long read(){
	long long w=1,s=0;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-') w=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){s=s*10+ch-'0';ch=getchar();}
	return s*w;
}
int main(){
	cin>>n>>m>>k;for(int i=1;i<=n;i++){a[i]=read();s[i]=s[i-1]+a[i];}
	memset(f,-1,sizeof(f));for(int i=0;i<=n;i++) f[i][0]=0;
	for(int i=1;i<=n;i++){
		for(int j=1;j<=k;j++){
			f[i][j]=f[i-1][j];
			if(i>=m) f[i][j]=max(f[i][j],f[i-m][j-1]+s[i]-s[i-m]);
		}
	}
	cout<<f[n][k]<<endl;
}


#include<queue>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long ll;
ll dp[5010][5010];
ll p[5010],sum[5010];
int n,m,k;

int main()
{
	scanf("%d%d%d",&n,&m,&k);
	for(int i=1;i<=n;i++)
	{
		scanf("%lld",&p[i]);
		sum[i]=sum[i-1]+p[i];
		if(i>=m) sum[i]-=p[i-m];
	}
	memset(dp,-1,sizeof(dp));
	dp[0][0]=0;
	for(int i=1;i<=n;i++)
	{
		dp[i][0]=0;
		for(int j=1;j<=k;j++)
		{
			dp[i][j]=dp[i-1][j];
			if(i>=m&&dp[i-m][j-1]!=-1)
				dp[i][j]=max(dp[i][j],dp[i-m][j-1]+sum[i]);
		}
	}
	printf("%lld\n",dp[n][k]);
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll dp[5005][5005];
ll a[5005],sum[5005],s[5005];
int main() {
	int n,m,k;
	cin>>n>>m>>k;
	for(int i=1; i<=n; i++) {
		cin>>a[i];
		sum[i]=sum[i-1]+a[i];
	}
	for(int i=m; i<=n; i++)s[i]=sum[i]-sum[i-m];
	for(int i=1; i<=n; i++)
		for(int j=1; j<=k; j++) {
			dp[i][j]=dp[i-1][j];
			if(i>=m)dp[i][j]=max(dp[i-m][j-1]+s[i],dp[i][j]);
		}
	cout<<dp[n][k];
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
inline long long read(){
	long long num=0;int f=1;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){num=(num<<1)+(num<<3)+ch-48;ch=getchar();}
	return num*f;
}
long long n,m,k;
long long a[5005],s[5005];
long long f[5005][5005];
int main(){
	n=read(),m=read(),k=read();
	memset(f,-1,sizeof(f));
	for(int i=1;i<=n;i++)a[i]=read(),f[i][0]=0,s[i]=s[i-1]+a[i];
	for(int i=1;i<=n;i++){
		for(int j=1;j<=k;j++){
			f[i][j]=f[i-1][j];
			if(i>m&&f[i-m][j-1]!=-1)f[i][j]=max(f[i][j],f[i-m][j-1]+s[i]-s[i-m]);
		}
	}
	printf("%lld\n",f[n][k]);
	return 0;
}


#include<iostream>
#include<cstdio>
using namespace std;
int n,m,k,a[5005],p,f[5005][5005],maxn=-0x7f7f7f7f7f,t;
void de(int where,int num,int ans){
	if(num==0||where>=n){
		if(maxn<ans){
			maxn=ans;
			t++;
		}
		return;
	}
	if(f[where][num]!=0){
		if(maxn<ans+f[where][num]){
			maxn=ans+f[where][num];
			t++;
		}
		return;
	}
	int p=t;
	de(where+m,num-1,ans+a[where+m-1]-a[where-1]);
	de(where+1,num,ans);
	if(p!=t){
		f[where][num]=maxn-ans;
	}
}
int main(){
	scanf("%d",&n);
	scanf("%d",&m);
	scanf("%d",&k);
	for(int i=1;i<=n;i++){
		scanf("%d",&p);
		a[i]=a[i-1]+p;
	}
	de(1,k,0);
	cout<<maxn;
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

const int MAXN = 5123;

int p[MAXN], n, m, k;
long long f[MAXN][MAXN], s[MAXN], sum;

signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    cin >> n >> m >> k;
    for (int i = 0; i <= n; i++) {
        cin >> p[i];
        if (i - m >= 0) {
            s[i - m] = sum;
            sum -= p[i - m];
        }
        sum += p[i];
    }
    for (int i = n - 1; i >= 0; i--) {
        for (int j = 1; j <= k; j++) {
            f[i][j] = max(f[i][j], f[i + 1][j]);
            if (i + m < n) {
                f[i][j] = max(f[i][j], s[i] + f[i + m][j - 1]);
            }
        }
    }
    cout << f[0][k] << endl;

    return 0;
}
/**
2 2 1 2 1
1 2
2 3
*/


#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#define ll long long
using namespace std;

ll read() {
	ll x=0,f=1;
	char ch=getchar();
	while(ch>'9'||ch<'0') {
		if(ch=='-')f=-f;
		ch=getchar();
	}
	while(ch>='0'&&ch<='9') {
		x=x*10+ch-'0';
		ch=getchar();
	}
	return f*x;
}

ll n,m,k,a[5005],s[5005],f[5005][5005];

ll max(ll a,ll b)
{
	return a>b?a:b;
}

int main() {
	n=read();
	m=read();
	k=read();

	for(int i=1; i<=n; i++) a[i]=read();
	ll tot=0;
	for(int i=1; i<=n; i++) {
		tot+=a[i];
		if(i>=m) {
			s[i]=tot;
			tot-=a[i-m+1];
		}
	}

	memset(f,-1,sizeof(f));

	for(int i=0; i<=n; i++) f[i][0]=0;
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=n;j++)
		{
			f[i][j]=f[i-1][j];

			if(i>=m&&f[i-m][j-1]>-1)f[i][j]=max(f[i][j],f[i-m][j-1]+s[i]);
		}
	}
	cout<<f[n][k];

	return 0;
}


#include<bits/stdc++.h>
#define int long long
using namespace std;
inline int read()
{
	int GYH,LZY;
	GYH=0,LZY=1;
	char aqx;
	aqx=getchar();
	while(aqx<'0'||aqx>'9')
	{
		if(aqx=='-')LZY=-1;
		aqx=getchar();
	}
	while(aqx>='0'&&aqx<='9')
	{
		GYH=(GYH<<1)+(GYH<<3)+aqx-'0';
		aqx=getchar();
	}
	return GYH*LZY;
}
const int maxn=5005;
int n,m,k;
int shu[maxn],sum[maxn];
int dp[maxn][maxn];
int ans;
signed main()
{
	n=read(),m=read(),k=read();
	for(int i=1;i<=n;i++)
	{
		shu[i]=read();
		sum[i]=sum[i-1]+shu[i];
	}
	for(int i=1;i<=k;i++)
	for(int j=1;j<=n;j++)
	{
		dp[i][j]=max(dp[i][j],dp[i][j-1]);
		if(j-m>=0)dp[i][j]=max(dp[i][j],dp[i-1][j-m]+sum[j]-sum[j-m]);
	}
	for(int i=1;i<=n;i++)
	ans=max(ans,dp[k][i]);
	cout<<ans;
}


#include<bits/stdc++.h>
using namespace std;
const int N =5005;
long long a[N],dp[N][N];//最后一个是i，j组的最大值
long long cnt,b[N];
int main(){
	int n,m,k,cnt=0;
	cin>>n>>m>>k;
	memset(dp,-1,sizeof(dp));
	for(int i=1;i<=n;i++){
		cin>>a[i];
		if(i>m)cnt-=a[i-m];
		cnt+=a[i];
		if(i>=m)b[i]=cnt;
	}
	for(int i=0;i<=n;i++)dp[i][0]=0;
	for(int i=1;i<=n;i++){
		for(int j=1;j<=k;j++){
			dp[i][j]=dp[i-1][j];
			if(i>=m&&dp[i-m][j-1]!=-1){
				dp[i][j]=max(dp[i][j],dp[i-m][j-1]+b[i]);
			}
		}
	}
	printf("%lld\n",dp[n][k]);
}


#include<bits/stdc++.h>
using namespace std;
#define N 5005
#define ll long long
#define rep(i,l,k) for(int i=(l);i<=(k);i++)
template <typename A, typename B> inline bool Min(A &a,B b){if(a>b) {a=b; return true;} return false;}
template <typename A, typename B> inline bool Max(A &a,B b){if(a<b) {a=b; return true;} return false;}
ll ip(){
    ll x=0,w=0;char ch=0;
    while(!isdigit(ch)) w|=ch=='-',ch=getchar();
    while(isdigit(ch)) x=(x<<1)+(x<<3)+(ch^48),ch=getchar();
    return w?-x:x;
}
ll dp1[N],dp2[N],sum[N],n,m,q,a[N];
int main(){
    n=ip(),m=ip(),q=ip();rep(i,1,n) a[i]=ip();rep(i,1,n) sum[i]=sum[i-1]+a[i];
    rep(kase,1,q){
        memset(dp1,0,sizeof(dp1));
        rep(i,1,n){
            ll now=max(i-m,(ll)0);
            dp1[i]=max(dp1[i],dp1[i-1]);
            dp1[i]=max(dp1[i],dp2[now]+sum[i]-sum[now]);
        }
        rep(i,1,n) dp2[i]=dp1[i];
    }
    printf("%lld",dp1[n]);
    return 0;
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#define ll long long
using namespace std;
const int maxn=5005;
int n,m,k,x;
ll dp[maxn][maxn],A[maxn];
int main(){
	scanf("%d%d%d",&n,&m,&k);
	for(int i=1;i<=n;i++){
		scanf("%d",&x);
		A[i]=A[i-1]+x;
	}
	for(int i=1;i<=n;i++)
	  for(int j=1;j<=k;j++){
	  	dp[i][j]=max(dp[i-1][j],dp[i-m][j-1]+A[i]-A[i-m]);
	  }
	printf("%lld",dp[n][k]);
	return 0;
}


#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<queue>
#include<set>
#include<vector>
using namespace std;
typedef long long ll;
inline int read()
{
    char ch=getchar();int x=0,f=1;
    while(ch<'0' || ch>'9') {
       if(ch=='-') f=-1;
      	  ch=getchar();
    }
    while(ch<='9' && ch>='0') {
       x=x*10+ch-'0';
       ch=getchar();
    }
    return x*f;
}
inline ll readl()
{
    char ch=getchar();ll x=0,f=1;
    while(ch<'0' || ch>'9') {
       if(ch=='-') f=-1;
      	  ch=getchar();
    }
    while(ch<='9' && ch>='0') {
       x=x*10+ch-'0';
       ch=getchar();
    }
    return x*f;
}
const int maxn = 5000;
int n,m,k;
int sum[maxn],p[maxn];
ll f[maxn][maxn];
int main()
{
	n = read();m = read();k = read();
	for(int i = 1 ;i <= n ;i++)
	p[i] = read(),sum[i] = sum[i-1] + p[i];
	for(int i = 1  ;i <= n ;i++)
	{
		for(int j = 1; j <= k ;j++)
		{
			f[i][j] = f[i-1][j];
			if(i >= m)f[i][j] = max(f[i][j],f[i-m][j-1] + sum[i] - sum[i-m]);
		}
	}
	cout<<f[n][k];
	return 0;
}
/*
long long
long long
long long
long long
long long
long long
long long
long long
long long
long longlong long
long long
*/


#include<cstdio>
#include<algorithm>
#include<iostream>
#include<cmath>
#include<map>
#include<iomanip>
#include<cstring>
#define reg register
#define EN std::puts("")
#define LL long long//
inline int read(){
	register int x=0;register int y=1;
	register char c=std::getchar();
	while(c<'0'||c>'9'){if(c=='-') y=0;c=std::getchar();}
	while(c>='0'&&c<='9'){x=x*10+(c^48);c=std::getchar();}
	return y?x:-x;
}
LL sum[5006],f[5006][5006];
int n,m,k;
int main(){
	n=read();m=read();k=read();
	for(reg int i=1;i<=n;i++) sum[i]=sum[i-1]+read();
	f[m][1]=sum[m];
	for(reg int i=m+1;i<=n;i++){
		for(reg int j=1;j<=k;j++)
			f[i][j]=std::max(f[i-1][j],f[i-m][j-1]+sum[i]-sum[i-m]);
	}
	std::printf("%lld",f[n][k]);
	return 0;
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int n,m,k;
long long p[5005];
long long f[5005][5005];
int main()
{
	cin>>n>>m>>k;
	for(int i=1;i<=n;i++)
	{
		cin>>p[i];
		p[i]+=p[i-1];
	}
	for(int i=m;i<=n;i++)
	  for(int j=1;j<=k;j++)
	    f[i][j]=max(f[i-1][j],f[i-m][j-1]+p[i]-p[i-m]);
	cout<<f[n][k]<<endl;
	return 0;
}


#include <bits/stdc++.h>
#define il inline

using namespace std;

typedef long long ll;
const ll N=5e3+5;
ll dp[N][N];
ll sum[N];
ll n,m,k;
ll a[N];

int main()
{
	cin>>n>>m>>k;
	for (ll i=1;i<=n;i++)cin>>a[i],sum[i]=sum[i-1]+a[i];
	dp[n][1]=sum[n];
	for (ll i=1;i<=n;i++)
	{
		for (ll j=1;j*m<=i&&j<=k;j++)
		{
			dp[i][j]=max(dp[i-1][j],dp[i-m][j-1]+sum[i]-sum[i-m]);
		}
	}
	cout<<dp[n][k]<<endl;
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int f[10000][10000];//qian i xuan j ge
int a[10000];
int s[10000];
int main(){
	int n,m,k;
	cin>>n>>m>>k;
	int he=0;
	for(int i=1;i<=n;i++){
		cin>>a[i];
		he+=a[i];
		if(i>=m){
			s[i]=he;
			he-=a[i-m+1];
		}
	}
	for(int i=1;i<=n;i++){
		for(int j=1;j<=k;j++){
			f[i][j]=f[i-1][j];
			if(i>m){
				f[i][j]=max(f[i][j],f[i-m][j-1]+s[i]);
			}
		}
	}
	cout<<f[n][k];
	return 0;
}


#include <bits/stdc++.h>
#define ri register
#define int long long
using namespace std; const int N=5010;
inline int read()
{
   	int s=0,w=1; ri char ch=getchar();
   	while(ch<'0'||ch>'9') {if(ch=='-') w=-1; ch=getchar(); }
   	while(ch>='0'&&ch<='9') s=s*10+ch-'0', ch=getchar();
   	return s*w;
}
int n,m,k,dp[N][N],a[N];
signed main()
{
	n=read(), m=read(), k=read();
	for(ri int i=1;i<=n;i++) a[i]=read(), a[i]+=a[i-1];
	memset(dp,-1,sizeof(dp));
	for(ri int i=0;i<=n;i++) dp[i][0]=0;
	for(ri int i=1;i<=n;i++)
	for(ri int j=1;j<=k;j++)
	{
		dp[i][j]=dp[i-1][j];
		if(i<m) continue;
		if(!(~dp[i-m][j-1])) continue;
		dp[i][j]=max(dp[i][j],dp[i-m][j-1]+a[i]-a[i-m]);
	}
	printf("%lld\n",dp[n][k]);
	return 0;
}


#include<queue>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long ll;
ll dp[5010][5010];
ll p[5010],sum[5010];
int n,m,k;

int main()
{
	scanf("%d%d%d",&n,&m,&k);
	for(int i=1;i<=n;i++)
	{
		scanf("%lld",&p[i]);
		sum[i]=sum[i-1]+p[i];
		if(i>=m) sum[i]-=p[i-m];
	}
	memset(dp,-1,sizeof(dp));
	for(int i=1;i<=n;i++)
	{
		dp[i][0]=0;
		for(int j=1;j<=k;j++)
		{
			dp[i][j]=dp[i-1][j];
			if(i>=m&&dp[i-m][j-1]!=-1)
				dp[i][j]=max(dp[i][j],dp[i-m][j-1]+sum[i]);
		}
	}
	printf("%lld\n",dp[n][k]);
	return 0;
}


#include<bits/stdc++.h>
#define N 5005
#define R register
#define LL long long
using namespace std;
inline LL read(){
	LL f=1,x=0;
	char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-') f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=(x<<3)+(x<<1)+ch-'0';ch=getchar();}
	return x*f;
}
inline LL maxx(LL x,LL y){return x>y?x:y;}
LL n,m,k,a[N],sum[N],dp[N][N],ans;
int main()
{
	n=read(); m=read(); k=read();
	for (LL i=1;i<=n;i++){
		scanf("%lld",&a[i]);
		sum[i]=sum[i-1]+a[i];
	}
	for (LL i=1;i<=n;i++)
		for (LL j=1;j<=k&&j*m<=i;j++)
			dp[i][j]=maxx(dp[i-1][j],dp[i-m][j-1]+sum[i]-sum[i-m]);
	printf("%lld",dp[n][k]);
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
long long n,m,k,a[5005],s[5005],f[5005][5005];//注意用longlong
int main()
{
    scanf("%lld %lld %lld",&n,&m,&k);
    for(int i=1;i<=n;i++) scanf("%d",&a[i]);
    long long tot=0;
    for(int i=1;i<=n;i++)
    {
        tot+=a[i];
        if(i>=m)
        {
            s[i]=tot;//前缀和部分，个人认为这样做比较方便
			//用tot表示现在位置的前缀和，存值之后减掉该段的首个数（越界的数）
			//有点像优先队列【大雾
            tot-=a[i-m+1];
        }
    }
    memset(f,-1,sizeof(f));
    for(int i=0;i<=n;i++) f[i][0]=0;//初值
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=k;j++)
        {
            f[i][j]=f[i-1][j];
            if(i>=m && f[i-m][j-1]>-1) f[i][j]=max(f[i][j],f[i-m][j-1]+s[i]);
            //状态转移方程，别忘记判断
        }
    }
    printf("%lld",f[n][k]);//输出
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define int long long
int read()
{
    int d = 0, w = 1;
    char ch = getchar();
    while (ch != '-' && (ch < '0' || ch > '9'))
        ch = getchar();
    if (ch == '-')
        w = -1, ch = getchar();
    while (ch >= '0' && ch <= '9')
        d = d * 10 + ch - '0', ch = getchar();
    return d * w;
}
void write_(int x)
{
    if (x < 0)
        x = -x, putchar('-');
    if (x > 9)
        write_(x / 10);
    putchar(x % 10 + '0');
}
void writeln(int x)
{
    write_(x);
    putchar('\n');
}
void writesp(int x)
{
    write_(x);
    putchar(' ');
}
int DP[5005][5005]; //前i个数选j组的最大值
int N[5005];
signed main()
{
#ifdef __clang__
    freopen("data.in", "r", stdin);
    freopen("data.out", "w", stdout);
#endif
    int n = read(), m = read(), k = read();
    for (int i = 1; i <= n; ++i)
        N[i] = read() + N[i - 1];
    for (int i = 1; i <= k; ++i)
        for (int j = i * m; j <= n; ++j)
            DP[j][i] = max(DP[j-1][i], DP[j - m][i - 1] + N[j] - N[j - m]);
    cout << DP[n][k] << endl;
    return 0;
}


#include <cstdio>
#include <queue>
using namespace std;
queue <int> q[5005];
int a[5005],sum[5005],f[5005];
int n,len,m;
int main()
{
	scanf("%d%d%d",&n,&len,&m);
	for(int i=1;i<=n;++i)
		scanf("%d",&a[i]),sum[i]=sum[i-1]+a[i];
	for(int i=len;i<=n;++i)
	{
		for(int j=1;j<i/len-1&&j<=m;++j)
		{
//			puts("- -|||");
			f[j]=max(f[j],q[j].front());
			q[j].pop();
		}
		for(int j=1;j<=i/len;++j)
		{
			int dq=f[j-1]+sum[i]-sum[i-len];
			q[j].push(dq);
//			puts("nalanala");
		}
	}
	while(!q[m].empty()) f[m]=max(f[m],q[m].front()),q[m].pop();
	printf("%d",f[m]);
	return 0;
}


#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#define ll long long
using namespace std;
const int N=5010;
ll sum[N];
int n,m,k;
ll x;
ll dp[N][N];
int main()
{
   scanf("%d%d%d",&n,&m,&k);
    for(int i=1;i<=n;i++)
    scanf("%lld",&x),sum[i]=sum[i-1]+x;
    memset(dp,-1,sizeof(dp));
	for(int i=1;i<=n;i++)
    dp[i][0]=0;
   	 for(int i=1;i<=n;i++)
    for(int j=1;j<=k;j++)
    {
	  dp[i][j]=dp[i-1][j];
	  if(i>=m&&~dp[i-m][j-1])
	  dp[i][j]=max(dp[i][j],dp[i-m][j-1]+(sum[i]-sum[i-m]));
	}
	printf("%lld\n",dp[n][k]);
	return 0;
}


#include<cstdio>
using namespace std;

#define max(x,y) x>y?x:y
int n,m,k,a[5005],sum[5005],tmp;
int dp[5005][5005];

int main()
{
	scanf("%d%d%d",&n,&m,&k);
	for(register int i=1;i<=n;i++)
	{
		scanf("%d",&a[i]);
		tmp+=a[i];
		if(i>=m)
		{
			sum[i]=tmp;
			tmp-=a[i-m+1];
		}
	}
	for(register int i=1;i<=n;i++)
	{
		dp[i][0]=0;
		for(register int j=1;j<=n;j++)
			dp[i][j]=-1;
	}
	for(register int i=1;i<=n;i++)
	{
		for(register int j=1;j<=k;j++)
		{
			dp[i][j]=dp[i-1][j];
			if(i>=m&&dp[i-m][j-1]!=-1)dp[i][j]=max(dp[i][j],dp[i-m][j-1]+sum[i]);
		}
	}
	printf("%d\n",dp[n][k]);
	return 0;
}


#include<bits/stdc++.h>
#define Maxn 5010
#define LL long long
using namespace std;

LL sgm[Maxn],dp[Maxn][Maxn];

int main(){
	int n,m,k,x;
	scanf("%d%d%d",&n,&m,&k);
	for (int i=1;i<=n;i++){
		scanf("%d",&x);
		sgm[i]=x+sgm[i-1];
	}
	memset(dp,-1,sizeof(dp));
	for(int i=0;i<=n;i++) dp[i][0]=0;
    for(int i=1;i<=n;i++){
        for(int j=1;j<=k;j++){
            dp[i][j]=dp[i-1][j];
            if(i>=m&&dp[i-m][j-1]!=-1)
				dp[i][j]=max(dp[i][j],dp[i-m][j-1]+sgm[i]-sgm[i-m]);
        }
    }
    printf("%d\n",dp[n][k]);
	return 0;
}


#include<iostream>
int main(){
  std::cout<<"9";
return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define N 5005
#define ll long long
#define rep(i,l,k) for(int i=(l);i<=(k);i++)
template <typename A, typename B> inline bool Min(A &a,B b){if(a>b) {a=b; return true;} return false;}
template <typename A, typename B> inline bool Max(A &a,B b){if(a<b) {a=b; return true;} return false;}
ll ip(){
	ll x=0,w=0;char ch=0;
	while(!isdigit(ch)) w|=ch=='-',ch=getchar();
	while(isdigit(ch)) x=(x<<1)+(x<<3)+(ch^48),ch=getchar();
	return w?-x:x;
}
ll dp1[N],dp2[N],sum[N],n,m,q,a[N];
int main(){
	n=ip(),m=ip(),q=ip();rep(i,1,n) a[i]=ip();rep(i,1,n) sum[i]=sum[i-1]+a[i];
	rep(kase,1,q){
		memset(dp1,0,sizeof(dp1));
		rep(i,1,n){
			ll now=max(i-m,0);
			dp1[i]=max(dp1[i],dp1[i-1]);
			dp1[i]=max(dp1[i],dp2[now]+sum[i]-sum[now]);
		}
		rep(i,1,n) dp2[i]=dp1[i];
	}
	printf("%lld",dp1[n]);
	return 0;
}


#include<cstdio>
#include<cstring>
#include<algorithm>
#define int long long
using namespace std;
int n,m,k,a[5005],s[5005],f[5005][5005];//注意用longlong
signed main()
{
    scanf("%lld %lld %lld",&n,&m,&k);
    for(int i=1;i<=n;i++) scanf("%lld",&a[i]),s[i]=s[i-1]+a[i];
    for(int i=m;i<=n;i++)
    for(int j=1;j<=min(i/m,k);j++)
	{
		f[i][j]=f[i-m][j-1]+s[i]-s[i-m];
		f[i][j]=max(f[i][j],f[i-1][j]);
    }
    printf("%lld",f[n][k]);//输出
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int n,m,k,s[5001],dp[5001][5001];
bool ans;
int main(){
	cin>>n>>m>>k;
	s[0]=0;
	for(int i=1;i<=n;++i)
	{
		int q;
		cin>>q;
		s[i]=s[i-1]+q;
	}
	for(int i=1;i<=k;++i)
	{
		int mx=0;
		ans=!ans;

		for(int j=m;j<=n;++j)
		{
			dp[ans][j]=max(dp[ans][j],dp[ans][j-1]);
			mx=max(mx,dp[!ans][j-m]);
			dp[ans][j]=max(dp[ans][j],mx+s[j]-s[j-m]);
		}
	}
	cout<<dp[ans][n];
	return 0;
}


#include <bits/stdc++.h>
#define endl "\n"
using namespace std;

long long dp[5001][5001], N, K, M, arr[5001], sum[5001];
int main ()
{
    cin>>N>>M>>K;
    for(int i=0;i<N;i++)
    {
        cin>>arr[i];
        sum[i]+=arr[i];
    }
    for(int i=0;i<N;i++)
    {
        sum[i]+=sum[i-1];
    }
    for(int i=1;i<N;i++)
    {
        for(int j=0;j<K;j++)
        {
            if(j==0&&i==M-1)
            {
                dp[i][j]=sum[M-1];
            }
            else if(j==0&&i>M-1)
            {
                dp[i][j]=max(dp[i-1][j], sum[i]-sum[i-M]);
            }
            else if(j*M>i)
                dp[i][j]=-1;
            else if(j>0)
            {
                dp[i][j]=max(dp[i-1][j], sum[i]-sum[i-M]+dp[i-M][j-1]);
            }
        }
    }
    cout<<dp[N-1][K-1];
}


#include <bits/stdc++.h>
#define endl "\n"
using namespace std;

long long dp[5001][5001], N, K, M, arr[5001], sum[5001], sum2[5001];
int main ()
{
    cin>>N>>M>>K;
    for(int i=0;i<N;i++)
    {
        cin>>arr[i];
        sum[i]+=arr[i];
    }
    for(int i=0;i<N;i++)
    {
        sum[i]+=sum[i-1];
    }
    for(int i=1;i<N;i++)
    {
        for(int j=0;j<K;j++)
        {
            if(j==0&&i==M-1)
            {
                dp[i][j]=sum[M-1];
            }
            else if(j==0&&i>M-1)
            {
                dp[i][j]=max(dp[i-1][j], sum[i]-sum[i-M]);
            }
            else if(j*M>i)
                dp[i][j]=-1;
            else if(j>0)
            {
                dp[i][j]=max(dp[i-1][j], sum[i]-sum[i-M]+dp[i-M][j-1]);
            }
        }
    }
    if(K*M==N)
    {
        cout<<sum[N-1]<<endl;
        return 0;
    }
    cout<<max(dp[N-1][K-1], arr[0]);
}


#include <bits/stdc++.h>
#define endl "\n"
using namespace std;

long long dp[5001][5001], N, K, M, arr[5001], sum[5001];
int main ()
{
    cin>>N>>M>>K;
    for(int i=0;i<N;i++)
    {
        cin>>arr[i];
        sum[i]+=arr[i];
    }
    for(int i=0;i<N;i++)
    {
        sum[i]+=sum[i-1];
    }
    for(int i=1;i<N;i++)
    {
        for(int j=0;j<K;j++)
        {
            if(j==0&&i==M-1)
            {
                dp[i][j]=sum[M-1];
            }
            else if(j==0&&i>M-1)
            {
                dp[i][j]=max(dp[i-1][j], sum[i]-sum[i-M]);
            }
            else if(j*M>i)
                dp[i][j]=-1;
            else if(j>0)
            {
                dp[i][j]=max(dp[i-1][j], sum[i]-sum[i-M]+dp[i-M][j-1]);
            }
        }
    }
    cout<<max(dp[N-1][K-1], arr[0]);
}


#include <bits/stdc++.h>
#define endl "\n"
using namespace std;

long long dp[5001][5001], N, K, M, arr[5001], sum[5001];
int main ()
{
    cin>>N>>M>>K;
    for(int i=0;i<N;i++)
    {
        cin>>arr[i];
        sum[i]+=arr[i];
    }
    for(int i=0;i<N;i++)
    {
        sum[i]+=sum[i-1];
    }
    for(int i=1;i<N;i++)
    {
        for(int j=0;j<K;j++)
        {
            if(j==0&&i==M-1)
            {
                dp[i][j]=sum[M-1];
            }
            else if(j==0&&i>M-1)
            {
                dp[i][j]=max(dp[i-1][j], sum[i]-sum[i-M]);
            }
            else if(j*M>i)
                dp[i][j]=-1;
            else if(j>0)
            {
                dp[i][j]=max(dp[i-1][j], sum[i]-sum[i-M]+dp[i-M][j-1]);
            }
        }
    }
    cout<<max((int)dp[N-1][K-1], 1);
}


#include <iostream>
#include <vector>
#include <cmath>
#include <stdio.h>
#include <algorithm>
#include <iterator>
#include <climits>
#include <numeric>
#include <queue>

typedef long long ll;
typedef unsigned long long ull;

typedef std::vector<ll> vll;
typedef std::vector<ull> vull;

typedef std::vector<std::vector<ll> > vvll;

vvll dp(5010,vll(5010,-1));
vll sum(5010,0),val(5010,0);

ll n,m,k;

// int main()
// {
// 	ll n,m,k;
// 	std::cin>>n>>m>>k;

// 	vll val(n,0);

// 	ll summing=0;

// 	for(ll i=0;i<n;++i)
// 	{
// 		std::cin>>val[i];
// 		summing+=val[i];
// 	}

// 	std::cout<<summing<<std::endl;

// 	std::sort(val.begin(),val.end());

// 	ll sum=0,count=0;

// 	vll::iterator index=val.end();
// 	--index;

// 	std::copy(val.begin(),val.end(),std::ostream_iterator<ll>(std::cout," "));
// 	std::cout<<std::endl;
// 	// for(int i=n-1;i>=0;--i)
// 	while(count<k)
// 	{
// 		ll r=*index;
// 		ll l=r-m+1;
// 		++count;

// 		std::cout<<r<<" "<<l<<std::endl;
// 		vll::iterator p=std::find(val.begin(),val.end(),l);

// 		if(p==val.end())
// 		{
// 			--index;
// 			--count;
// 		}

// 		else
// 		{
// 			if(l!=r)
// 				sum+=l+r;

// 			else
// 				sum+=l;
// 			index=p-1;
// 		}

// 	}

// 	std::cout<<sum<<std::endl;
// 	return 0;
// }

ll dy(ll i,ll k)
{
	if(i>n-m+1 && k> 0){return 1e16;}
	if(dp[i][k]!=-1)
	{
		return dp[i][k];
	}

	if(k==0){return 0;}
	ll selected= sum[i+m-1]-sum[i-1] + dy(i+m,k-1);

	// std::cout<<i<<" "<<sum[i+m-1]-sum[i-1]<<" "<<k<<" "<<selected<<std::endl;
	ll notselected=dy(i+1,k);

	return std::max(selected,notselected);

}

int main()
{
	// ll n,m,k;
	std::cin>>n>>m>>k;

	// vll val(n+1,0),sum(n+1,0);

	sum[0]=0;
	for(int i=1;i<=n;++i)
	{
		std::cin>>val[i];
		sum[i]=val[i]+sum[i-1];
		// std::cout<<m<<",";
	}
	// std::cout<<std::endl;

	std::cout<<dy(1,k)<<std::endl;
	// vvll dp(n+1,vll(n+1,0));

	// for(int i=1;i<=n;++i)
	// {
	// 	if(i<m){continue;}

	// 	for(int j=1;j<=k;++j)
	// 	{
	// 		dp[i][j]=sum[i]-sum[i-m]+dp[i-m][j-1];
	// 		dp[i][j]=std::max(dp[i][j],dp[i-1][j]);
	// 	}
	// }

	// for(int i=1;i<=n;++i)
	// {
	// 	for(int j=1;j<=k;++j)
	// 	{
	// 		std::cout<<dp[i][j]<<",";
	// 	}
	// 	std::cout<<std::endl;
	// }
	// std::cout<<dp[n][k]<<std::endl;

}


#include <iostream>
#include <vector>
#include <cmath>
#include <stdio.h>
#include <algorithm>
#include <iterator>
#include <climits>
#include <numeric>
#include <queue>

typedef long long ll;
typedef unsigned long long ull;

typedef std::vector<ll> vll;
typedef std::vector<ull> vull;

typedef std::vector<std::vector<ll> > vvll;

vvll dp(5010,vll(5010,-1));
vll sum(5010,0),val(5010,0);

ll n,m,k;

// int main()
// {
// 	ll n,m,k;
// 	std::cin>>n>>m>>k;

// 	vll val(n,0);

// 	ll summing=0;

// 	for(ll i=0;i<n;++i)
// 	{
// 		std::cin>>val[i];
// 		summing+=val[i];
// 	}

// 	std::cout<<summing<<std::endl;

// 	std::sort(val.begin(),val.end());

// 	ll sum=0,count=0;

// 	vll::iterator index=val.end();
// 	--index;

// 	std::copy(val.begin(),val.end(),std::ostream_iterator<ll>(std::cout," "));
// 	std::cout<<std::endl;
// 	// for(int i=n-1;i>=0;--i)
// 	while(count<k)
// 	{
// 		ll r=*index;
// 		ll l=r-m+1;
// 		++count;

// 		std::cout<<r<<" "<<l<<std::endl;
// 		vll::iterator p=std::find(val.begin(),val.end(),l);

// 		if(p==val.end())
// 		{
// 			--index;
// 			--count;
// 		}

// 		else
// 		{
// 			if(l!=r)
// 				sum+=l+r;

// 			else
// 				sum+=l;
// 			index=p-1;
// 		}

// 	}

// 	std::cout<<sum<<std::endl;
// 	return 0;
// }

ll dy(ll i,ll k)
{
	if(i>n-m+1 && k> 0){return -1e16;}
	if(dp[i][k]!=-1)
	{
		return dp[i][k];
	}

	if(k==0){return 0;}
	ll selected= sum[i+m-1]-sum[i-1] + dy(i+m,k-1);

	// std::cout<<i<<" "<<sum[i+m-1]-sum[i-1]<<" "<<k<<" "<<selected<<std::endl;
	ll notselected=dy(i+1,k);

	return std::max(selected,notselected);

}

int main()
{
	// ll n,m,k;
	std::cin>>n>>m>>k;

	// vll val(n+1,0),sum(n+1,0);

	sum[0]=0;
	for(int i=1;i<=n;++i)
	{
		std::cin>>val[i];
		sum[i]=val[i]+sum[i-1];
		// std::cout<<m<<",";
	}
	// std::cout<<std::endl;

	// std::cout<<dy(1,k)<<std::endl;
	vvll dp(n+1,vll(n+1,0));

	for(int i=1;i<=n;++i)
	{
		if(i<m){continue;}

		for(int j=1;j<=k;++j)
		{
			dp[i][j]=sum[i]-sum[i-m]+dp[i-m][j-1];
			dp[i][j]=std::max(dp[i][j],dp[i-1][j]);
		}
	}

	// for(int i=1;i<=n;++i)
	// {
	// 	for(int j=1;j<=k;++j)
	// 	{
	// 		std::cout<<dp[i][j]<<",";
	// 	}
	// 	std::cout<<std::endl;
	// }
	std::cout<<dp[n][k]<<std::endl;

}


#include <iostream>
#include <vector>
#include <cmath>
#include <stdio.h>
#include <algorithm>
#include <iterator>
#include <climits>
#include <numeric>
#include <queue>

typedef long long ll;
typedef unsigned long long ull;

typedef std::vector<ll> vll;
typedef std::vector<ull> vull;

vll::iterator it;

int main()
{
	ll n,m,k;
	std::cin>>n>>m>>k;

	vll val(n,0);

	for(ll i=0;i<n;++i)
	{
		std::cin>>val[i];
	}

	std::sort(val.begin(),val.end());

	ll sum=0,count=0;

	vll::iterator index=val.end();
	--index;

	// for(int i=n-1;i>=0;--i)
	while(count<k)
	{
		ll r=*index;
		ll l=r-m+1;
		++count;

		// std::cout<<r<<" "<<l<<std::endl;
		vll::iterator p=std::find(val.begin(),val.end(),l);

		if(p==val.end())
		{
			--index;
		}

		else
		{
			if(l!=r)
				sum+=l+r;

			else
				sum+=l;
			index=p-1;
		}

	}

	std::cout<<sum<<std::endl;
	return 0;
}


#include <iostream>
#include <vector>
#include <cmath>
#include <stdio.h>
#include <algorithm>
#include <iterator>
#include <climits>
#include <numeric>
#include <queue>

typedef long long ll;
typedef unsigned long long ull;

typedef std::vector<ll> vll;
typedef std::vector<ull> vull;

typedef std::vector<std::vector<ll> > vvll;

vvll dp(5005,vll(5005,-1));
vll sum(5005,0),val(5005,0);

ll n,m,k;

// int main()
// {
// 	ll n,m,k;
// 	std::cin>>n>>m>>k;

// 	vll val(n,0);

// 	ll summing=0;

// 	for(ll i=0;i<n;++i)
// 	{
// 		std::cin>>val[i];
// 		summing+=val[i];
// 	}

// 	std::cout<<summing<<std::endl;

// 	std::sort(val.begin(),val.end());

// 	ll sum=0,count=0;

// 	vll::iterator index=val.end();
// 	--index;

// 	std::copy(val.begin(),val.end(),std::ostream_iterator<ll>(std::cout," "));
// 	std::cout<<std::endl;
// 	// for(int i=n-1;i>=0;--i)
// 	while(count<k)
// 	{
// 		ll r=*index;
// 		ll l=r-m+1;
// 		++count;

// 		std::cout<<r<<" "<<l<<std::endl;
// 		vll::iterator p=std::find(val.begin(),val.end(),l);

// 		if(p==val.end())
// 		{
// 			--index;
// 			--count;
// 		}

// 		else
// 		{
// 			if(l!=r)
// 				sum+=l+r;

// 			else
// 				sum+=l;
// 			index=p-1;
// 		}

// 	}

// 	std::cout<<sum<<std::endl;
// 	return 0;
// }

ll dy(ll i,ll k)
{
	if(i>n-m+1 && k> 0){return -1e16;}
	if(dp[i][k]!=-1)
	{
		return dp[i][k];
	}

	if(k==0){return 0;}
	ll selected= sum[i+m-1]-sum[i-1] + dy(i+m,k-1);

	// std::cout<<i<<" "<<sum[i+m-1]-sum[i-1]<<" "<<k<<" "<<selected<<std::endl;
	ll notselected=dy(i+1,k);

	return std::max(selected,notselected);

}

int main()
{
	// ll n,m,k;
	std::cin>>n>>m>>k;

	// vll val(n+1,0),sum(n+1,0);

	sum[0]=0;
	for(int i=1;i<=n;++i)
	{
		std::cin>>val[i];
		sum[i]=val[i]+sum[i-1];
		// std::cout<<m<<",";
	}
	// std::cout<<std::endl;

	// std::cout<<dy(1,k)<<std::endl;
	vvll dp(n+1,vll(n+1,0));

	for(int i=1;i<=n;++i)
	{
		if(i<m){continue;}

		for(int j=1;j<=k;++j)
		{
			dp[i][j]=sum[i]-sum[i-m]+dp[i-m][j-1];
			dp[i][j]=std::max(dp[i][j],dp[i-1][j]);
		}
	}

	// for(int i=1;i<=n;++i)
	// {
	// 	for(int j=1;j<=k;++j)
	// 	{
	// 		std::cout<<dp[i][j]<<",";
	// 	}
	// 	std::cout<<std::endl;
	// }
	std::cout<<dp[n][k]<<std::endl;

}


#include <iostream>
#include <vector>
#include <cmath>
#include <stdio.h>
#include <algorithm>
#include <iterator>
#include <climits>
#include <numeric>
#include <queue>

typedef long long ll;
typedef unsigned long long ull;

typedef std::vector<ll> vll;
typedef std::vector<ull> vull;

typedef std::vector<std::vector<ll> > vvll;

// vvll dp(5005,vll(5005,0));
vll sum(5005,0),val(5005,0);

int n,m,k;

// int main()
// {
// 	ll n,m,k;
// 	std::cin>>n>>m>>k;

// 	vll val(n,0);

// 	ll summing=0;

// 	for(ll i=0;i<n;++i)
// 	{
// 		std::cin>>val[i];
// 		summing+=val[i];
// 	}

// 	std::cout<<summing<<std::endl;

// 	std::sort(val.begin(),val.end());

// 	ll sum=0,count=0;

// 	vll::iterator index=val.end();
// 	--index;

// 	std::copy(val.begin(),val.end(),std::ostream_iterator<ll>(std::cout," "));
// 	std::cout<<std::endl;
// 	// for(int i=n-1;i>=0;--i)
// 	while(count<k)
// 	{
// 		ll r=*index;
// 		ll l=r-m+1;
// 		++count;

// 		std::cout<<r<<" "<<l<<std::endl;
// 		vll::iterator p=std::find(val.begin(),val.end(),l);

// 		if(p==val.end())
// 		{
// 			--index;
// 			--count;
// 		}

// 		else
// 		{
// 			if(l!=r)
// 				sum+=l+r;

// 			else
// 				sum+=l;
// 			index=p-1;
// 		}

// 	}

// 	std::cout<<sum<<std::endl;
// 	return 0;
// }

// ll dy(ll i,ll k)
// {
// 	if(i>n-m+1 && k> 0){return -1e16;}
// 	if(dp[i][k]!=-1)
// 	{
// 		return dp[i][k];
// 	}

// 	if(k==0){return 0;}
// 	ll selected= sum[i+m-1]-sum[i-1] + dy(i+m,k-1);

// 	// std::cout<<i<<" "<<sum[i+m-1]-sum[i-1]<<" "<<k<<" "<<selected<<std::endl;
// 	ll notselected=dy(i+1,k);

// 	return std::max(selected,notselected);

// }

int main()
{
	// ll n,m,k;
	std::cin>>n>>m>>k;

	// vll val(n+1,0),sum(n+1,0);

	sum[0]=0;
	for(int i=1;i<=n;++i)
	{
		std::cin>>val[i];
		sum[i]=val[i]+sum[i-1];
		// std::cout<<m<<",";
	}
	// std::cout<<std::endl;

	// std::cout<<dy(1,k)<<std::endl;
	vvll dp(n+1,vll(n+1,0));

	for(int i=1;i<=n;++i)
	{
		if(i<m){continue;}

		for(int j=1;j<=k;++j)
		{
			dp[i][j]=sum[i]-sum[i-m]+dp[i-m][j-1];
			dp[i][j]=std::max(dp[i][j],dp[i-1][j]);
		}
	}

	// for(int i=1;i<=n;++i)
	// {
	// 	for(int j=1;j<=k;++j)
	// 	{
	// 		std::cout<<dp[i][j]<<",";
	// 	}
	// 	std::cout<<std::endl;
	// }
	std::cout<<dp[n][k]<<std::endl;

}


#include <iostream>
#include <vector>
#include <cmath>
#include <stdio.h>
#include <algorithm>
#include <iterator>
#include <climits>
#include <numeric>
#include <queue>

typedef long long ll;
typedef unsigned long long ull;

typedef std::vector<ll> vll;
typedef std::vector<ull> vull;

typedef std::vector<std::vector<ll> > vvll;

vvll dp(5010,vll(5010,-1));
vll sum(5010,0),val(5010,0);

ll n,m,k;

// int main()
// {
// 	ll n,m,k;
// 	std::cin>>n>>m>>k;

// 	vll val(n,0);

// 	ll summing=0;

// 	for(ll i=0;i<n;++i)
// 	{
// 		std::cin>>val[i];
// 		summing+=val[i];
// 	}

// 	std::cout<<summing<<std::endl;

// 	std::sort(val.begin(),val.end());

// 	ll sum=0,count=0;

// 	vll::iterator index=val.end();
// 	--index;

// 	std::copy(val.begin(),val.end(),std::ostream_iterator<ll>(std::cout," "));
// 	std::cout<<std::endl;
// 	// for(int i=n-1;i>=0;--i)
// 	while(count<k)
// 	{
// 		ll r=*index;
// 		ll l=r-m+1;
// 		++count;

// 		std::cout<<r<<" "<<l<<std::endl;
// 		vll::iterator p=std::find(val.begin(),val.end(),l);

// 		if(p==val.end())
// 		{
// 			--index;
// 			--count;
// 		}

// 		else
// 		{
// 			if(l!=r)
// 				sum+=l+r;

// 			else
// 				sum+=l;
// 			index=p-1;
// 		}

// 	}

// 	std::cout<<sum<<std::endl;
// 	return 0;
// }

ll dy(ll i,ll k)
{
	if(dp[i][k]!=-1)
	{
		return dp[i][k];
	}

	if(i>n-m){return 0;}

	if(k==0){return 0;}
	ll selected= sum[i+m]-sum[i] + dy(i+m,k-1);

	// std::cout<<i<<" "<<sum[i+m]-sum[i]<<" "<<k<<" "<<selected<<std::endl;
	ll notselected=dy(i+1,k);

	return std::max(selected,notselected);

}

int main()
{
	// ll n,m,k;
	std::cin>>n>>m>>k;

	// vll val(n+1,0),sum(n+1,0);

	sum[0]=0;
	for(int i=1;i<=n;++i)
	{
		std::cin>>val[i];
		sum[i]=val[i]+sum[i-1];
		// std::cout<<m<<",";
	}
	// std::cout<<std::endl;

	std::cout<<dy(1,k)<<std::endl;
	// vvll dp(n+1,vll(n+1,0));

	// for(int i=1;i<=n;++i)
	// {
	// 	if(i<m){continue;}

	// 	for(int j=1;j<=k;++j)
	// 	{
	// 		dp[i][j]=sum[i]-sum[i-m]+dp[i-m][j-1];
	// 		dp[i][j]=std::max(dp[i][j],dp[i-1][j]);
	// 	}
	// }

	// for(int i=1;i<=n;++i)
	// {
	// 	for(int j=1;j<=k;++j)
	// 	{
	// 		std::cout<<dp[i][j]<<",";
	// 	}
	// 	std::cout<<std::endl;
	// }
	// std::cout<<dp[n][k]<<std::endl;

}


#include <iostream>
#include <vector>
#include <cmath>
#include <stdio.h>
#include <algorithm>
#include <iterator>
#include <climits>
#include <numeric>
#include <queue>

typedef long long ll;
typedef unsigned long long ull;

typedef std::vector<ll> vll;
typedef std::vector<ull> vull;

typedef std::vector<std::vector<ll> > vvll;

vvll dp(5010,vll(5010,-1));
vll sum(5010,0),val(5010,0);

ll n,m,k;

// int main()
// {
// 	ll n,m,k;
// 	std::cin>>n>>m>>k;

// 	vll val(n,0);

// 	ll summing=0;

// 	for(ll i=0;i<n;++i)
// 	{
// 		std::cin>>val[i];
// 		summing+=val[i];
// 	}

// 	std::cout<<summing<<std::endl;

// 	std::sort(val.begin(),val.end());

// 	ll sum=0,count=0;

// 	vll::iterator index=val.end();
// 	--index;

// 	std::copy(val.begin(),val.end(),std::ostream_iterator<ll>(std::cout," "));
// 	std::cout<<std::endl;
// 	// for(int i=n-1;i>=0;--i)
// 	while(count<k)
// 	{
// 		ll r=*index;
// 		ll l=r-m+1;
// 		++count;

// 		std::cout<<r<<" "<<l<<std::endl;
// 		vll::iterator p=std::find(val.begin(),val.end(),l);

// 		if(p==val.end())
// 		{
// 			--index;
// 			--count;
// 		}

// 		else
// 		{
// 			if(l!=r)
// 				sum+=l+r;

// 			else
// 				sum+=l;
// 			index=p-1;
// 		}

// 	}

// 	std::cout<<sum<<std::endl;
// 	return 0;
// }

ll dy(ll i,ll k)
{
	if(i>n-m+1 && k> 0){return -1;}
	if(dp[i][k]!=-1)
	{
		return dp[i][k];
	}

	if(k==0){return 0;}
	ll selected= sum[i+m-1]-sum[i-1] + dy(i+m,k-1);

	// std::cout<<i<<" "<<sum[i+m-1]-sum[i-1]<<" "<<k<<" "<<selected<<std::endl;
	ll notselected=dy(i+1,k);

	return std::max(selected,notselected);

}

int main()
{
	// ll n,m,k;
	std::cin>>n>>m>>k;

	// vll val(n+1,0),sum(n+1,0);

	sum[0]=0;
	for(int i=1;i<=n;++i)
	{
		std::cin>>val[i];
		sum[i]=val[i]+sum[i-1];
		// std::cout<<m<<",";
	}
	// std::cout<<std::endl;

	std::cout<<dy(1,k)<<std::endl;
	// vvll dp(n+1,vll(n+1,0));

	// for(int i=1;i<=n;++i)
	// {
	// 	if(i<m){continue;}

	// 	for(int j=1;j<=k;++j)
	// 	{
	// 		dp[i][j]=sum[i]-sum[i-m]+dp[i-m][j-1];
	// 		dp[i][j]=std::max(dp[i][j],dp[i-1][j]);
	// 	}
	// }

	// for(int i=1;i<=n;++i)
	// {
	// 	for(int j=1;j<=k;++j)
	// 	{
	// 		std::cout<<dp[i][j]<<",";
	// 	}
	// 	std::cout<<std::endl;
	// }
	// std::cout<<dp[n][k]<<std::endl;

}


#include <iostream>
#include <vector>
#include <cmath>
#include <stdio.h>
#include <algorithm>
#include <iterator>
#include <climits>
#include <numeric>
#include <queue>

typedef long long ll;
typedef unsigned long long ull;

typedef std::vector<ll> vll;
typedef std::vector<ull> vull;

typedef std::vector<std::vector<ll> > vvll;

vvll dp(5010,vll(5010,-1));
vll sum(5010,0),val(5010,0);

ll n,m,k;

// int main()
// {
// 	ll n,m,k;
// 	std::cin>>n>>m>>k;

// 	vll val(n,0);

// 	ll summing=0;

// 	for(ll i=0;i<n;++i)
// 	{
// 		std::cin>>val[i];
// 		summing+=val[i];
// 	}

// 	std::cout<<summing<<std::endl;

// 	std::sort(val.begin(),val.end());

// 	ll sum=0,count=0;

// 	vll::iterator index=val.end();
// 	--index;

// 	std::copy(val.begin(),val.end(),std::ostream_iterator<ll>(std::cout," "));
// 	std::cout<<std::endl;
// 	// for(int i=n-1;i>=0;--i)
// 	while(count<k)
// 	{
// 		ll r=*index;
// 		ll l=r-m+1;
// 		++count;

// 		std::cout<<r<<" "<<l<<std::endl;
// 		vll::iterator p=std::find(val.begin(),val.end(),l);

// 		if(p==val.end())
// 		{
// 			--index;
// 			--count;
// 		}

// 		else
// 		{
// 			if(l!=r)
// 				sum+=l+r;

// 			else
// 				sum+=l;
// 			index=p-1;
// 		}

// 	}

// 	std::cout<<sum<<std::endl;
// 	return 0;
// }

ll dy(ll i,ll k)
{
	if(i>n-m+1 && k> 0){return -1e16;}
	if(dp[i][k]!=-1)
	{
		return dp[i][k];
	}

	if(k==0){return 0;}
	ll selected= sum[i+m-1]-sum[i-1] + dy(i+m,k-1);

	// std::cout<<i<<" "<<sum[i+m-1]-sum[i-1]<<" "<<k<<" "<<selected<<std::endl;
	ll notselected=dy(i+1,k);

	return std::max(selected,notselected);

}

int main()
{
	// ll n,m,k;
	std::cin>>n>>m>>k;

	// vll val(n+1,0),sum(n+1,0);

	sum[0]=0;
	for(int i=1;i<=n;++i)
	{
		std::cin>>val[i];
		sum[i]=val[i]+sum[i-1];
		// std::cout<<m<<",";
	}
	// std::cout<<std::endl;

	std::cout<<dy(1,k)<<std::endl;
	// vvll dp(n+1,vll(n+1,0));

	// for(int i=1;i<=n;++i)
	// {
	// 	if(i<m){continue;}

	// 	for(int j=1;j<=k;++j)
	// 	{
	// 		dp[i][j]=sum[i]-sum[i-m]+dp[i-m][j-1];
	// 		dp[i][j]=std::max(dp[i][j],dp[i-1][j]);
	// 	}
	// }

	// for(int i=1;i<=n;++i)
	// {
	// 	for(int j=1;j<=k;++j)
	// 	{
	// 		std::cout<<dp[i][j]<<",";
	// 	}
	// 	std::cout<<std::endl;
	// }
	// std::cout<<dp[n][k]<<std::endl;

}


#include <iostream>
#include <vector>
#include <cmath>
#include <stdio.h>
#include <algorithm>
#include <iterator>
#include <climits>
#include <numeric>
#include <queue>

typedef long long ll;
typedef unsigned long long ull;

typedef std::vector<ll> vll;
typedef std::vector<ull> vull;

typedef std::vector<std::vector<ll> > vvll;

vvll dp(5010,vll(5010,-1));
vll sum(5010,0),val(5010,0);

ll n,m,k;

// int main()
// {
// 	ll n,m,k;
// 	std::cin>>n>>m>>k;

// 	vll val(n,0);

// 	ll summing=0;

// 	for(ll i=0;i<n;++i)
// 	{
// 		std::cin>>val[i];
// 		summing+=val[i];
// 	}

// 	std::cout<<summing<<std::endl;

// 	std::sort(val.begin(),val.end());

// 	ll sum=0,count=0;

// 	vll::iterator index=val.end();
// 	--index;

// 	std::copy(val.begin(),val.end(),std::ostream_iterator<ll>(std::cout," "));
// 	std::cout<<std::endl;
// 	// for(int i=n-1;i>=0;--i)
// 	while(count<k)
// 	{
// 		ll r=*index;
// 		ll l=r-m+1;
// 		++count;

// 		std::cout<<r<<" "<<l<<std::endl;
// 		vll::iterator p=std::find(val.begin(),val.end(),l);

// 		if(p==val.end())
// 		{
// 			--index;
// 			--count;
// 		}

// 		else
// 		{
// 			if(l!=r)
// 				sum+=l+r;

// 			else
// 				sum+=l;
// 			index=p-1;
// 		}

// 	}

// 	std::cout<<sum<<std::endl;
// 	return 0;
// }

ll dy(ll i,ll k)
{
	if(dp[i][k]!=-1)
	{
		return dp[i][k];
	}

	if(i>n-m && k> 0){return -1;}

	if(k==0){return 0;}
	ll selected= sum[i+m-1]-sum[i-1] + dy(i+m,k-1);

	// std::cout<<i<<" "<<sum[i+m-1]-sum[i-1]<<" "<<k<<" "<<selected<<std::endl;
	ll notselected=dy(i+1,k);

	return std::max(selected,notselected);

}

int main()
{
	// ll n,m,k;
	std::cin>>n>>m>>k;

	// vll val(n+1,0),sum(n+1,0);

	sum[0]=0;
	for(int i=1;i<=n;++i)
	{
		std::cin>>val[i];
		sum[i]=val[i]+sum[i-1];
		// std::cout<<m<<",";
	}
	// std::cout<<std::endl;

	std::cout<<dy(1,k)<<std::endl;
	// vvll dp(n+1,vll(n+1,0));

	// for(int i=1;i<=n;++i)
	// {
	// 	if(i<m){continue;}

	// 	for(int j=1;j<=k;++j)
	// 	{
	// 		dp[i][j]=sum[i]-sum[i-m]+dp[i-m][j-1];
	// 		dp[i][j]=std::max(dp[i][j],dp[i-1][j]);
	// 	}
	// }

	// for(int i=1;i<=n;++i)
	// {
	// 	for(int j=1;j<=k;++j)
	// 	{
	// 		std::cout<<dp[i][j]<<",";
	// 	}
	// 	std::cout<<std::endl;
	// }
	// std::cout<<dp[n][k]<<std::endl;

}


#include <bits/stdc++.h>
// KnapSack
using namespace std;

typedef long long int lld;

lld dp[5001][5001];

int main() {

    int n, m, k;
    cin >> n >> m >> k;
    int x[n];
    for (int i = 0; i < n; i++)
        cin >> x[i];

    vector<lld> value;
    for (int i = 0; i < n; i++) {
        if (i + m - 1 >= n)
            break;
        lld sum = 0;
        for (int j = i; j < i + m; j++)
            sum += x[j];
        value.push_back(sum);

    }
    // for (int i = 0 ; i < value.size() ; i++)cout << value[i] << endl;
    for (int i = 0; i < value.size() + 1; i++) {
        for (int j = 0; j <= k; j++) {
            if (i == 0 || j == 0)
                continue;
            dp[i][j] = value[i - 1];
            if (i >= 2)
                dp[i][j] = max(dp[i - 1][j], dp[i][j]);
            if (i - m >= 0)
                dp[i][j] = max(dp[i - 1][j], value[i - 1] + dp[i - m][j - 1]);
        }
    }
    /*
     for (int i = 0; i < value.size() + 1; i++) {
     for (int j = 0; j <= k; j++) {
     cout << dp[i][j] << " ";
     }
     cout << endl;
     }
     */
    cout << dp[value.size()][k] << endl;
}