The only difference between easy and hard versions is the constraints.

Vova likes pictures with kittens. The news feed in the social network he uses can be represented as an array of $n$ consecutive pictures (with kittens, of course). Vova likes all these pictures, but some are more beautiful than the others: the $i$-th picture has beauty $a_i$.

Vova wants to repost exactly $x$ pictures in such a way that:   each segment of the news feed of at least $k$ consecutive pictures has at least one picture reposted by Vova;  the sum of beauty values of reposted pictures is maximum possible. 

For example, if $k=1$ then Vova has to repost all the pictures in the news feed. If $k=2$ then Vova can skip some pictures, but between every pair of consecutive pictures Vova has to repost at least one of them.

Your task is to calculate the maximum possible sum of values of reposted pictures if Vova follows conditions described above, or say that there is no way to satisfy all conditions.


-----Input-----

The first line of the input contains three integers $n, k$ and $x$ ($1 \le k, x \le n \le 200$) — the number of pictures in the news feed, the minimum length of segment with at least one repost in it and the number of pictures Vova is ready to repost.

The second line of the input contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^9$), where $a_i$ is the beauty of the $i$-th picture.


-----Output-----

Print -1 if there is no way to repost some pictures to satisfy all the conditions in the problem statement.

Otherwise print one integer — the maximum sum of values of reposted pictures if Vova follows conditions described in the problem statement.


-----Examples-----
Input
5 2 3
5 1 3 10 1

Output
18

Input
6 1 5
10 30 30 70 10 10

Output
-1

Input
4 3 1
1 100 1 1

Output
100

Difficulty: introductory

Starter code:

Solutions:
import sys
from math import *

def minp():
	return sys.stdin.readline().strip()

def mint():
	return int(minp())

def mints():
	return map(int, minp().split())

n, k, x = mints()
a = list(mints())
d = [None]*(n+1)
p = [None]*(n+1)
for i in range(0,k):
	d[i] = a[i]
for xx in range(2,x+1):
	d,p = p,d
	for nn in range(n):
		m = None
		for i in range(max(0,nn-k),nn):
			if p[i] != None:
				if m == None:
					m = p[i]
				else:
					m = max(m, p[i])
		if m != None:
			d[nn] = m + a[nn]
		else:
			d[nn] = None
m = -1
for i in range(n-k,n):
	if d[i] != None:
		m = max(m, d[i])
print(m)

# -*- coding: utf-8 -*-

import math
import collections
import bisect
import heapq
import time
import itertools
import sys

"""
created by shhuan at 2018/11/17 00:27


"""

N, K, X = map(int, input().split())
A = [0] + [int(x) for x in input().split()]

dp = [[float('-inf') for _ in range(X+1)] for _ in range(N+1)]
dp[0][X] = 0

for i in range(1, N+1):
    for x in range(X):
        for p in range(1, K+1):
            if i-p < 0:
                break
            if dp[i-p][x+1] < 0:
                continue
            dp[i][x] = max(dp[i][x], dp[i-p][x+1] + A[i])

ans = max([max(v) for v in dp[N-K+1:]])
if ans < 0:
    print(-1)
else:
    print(ans)

N,K,X = list(map(int,input().split()))
arr = [0] + [int(i) for i in input().split()]

dp = [[float('-inf') for _ in range(X+1)] for _ in range(N+1)]
dp[0][X] = 0

for i in range(1,N+1):
    for x in range(X):
        for p in range(1,K+1):
            if i - p < 0:
                break
            if dp[i-p][x+1] < 0:
                continue
            dp[i][x] = max(dp[i][x], dp[i-p][x+1] + arr[i])

ans = max([max(v) for v in dp[N-K+1:]])

if ans < 0:
    print(-1)
else:
    print(ans)


n, k, x = list(map(int, input().split()))
a = [None] + list(map(int, input().split()))
dp = [[-1] * (n + 1) for i in range(x + 1)]
dp[0][0] = 0
for i in range(1, x + 1):
    for j in range(1, n + 1):
        dp[i][j] = max(dp[i - 1][j2] for j2 in range(max(0, j - k), j))
        if dp[i][j] != -1: dp[i][j] += a[j]
ans = max(dp[x][j] for j in range(n - k + 1, n + 1))
print(ans)


n, k, x = map(int, input().split())
a = [None] + list(map(int, input().split()))
dp = [[-1] * (n + 1) for i in range(x + 1)]
dp[0][0] = 0
for i in range(1, x + 1):
    for j in range(1, n + 1):
        dp[i][j] = max(dp[i - 1][max(0, j - k):j])
        if dp[i][j] != -1: dp[i][j] += a[j]
ans = max(dp[x][n - k + 1:n + 1])
print(ans)

from functools import lru_cache

n, k, x = list(map(int, input().split()))

arr = list(map(int, input().split()))

@lru_cache(maxsize=50000)
def dp(i,y):
    if i>=0 and i<k and y==0:
        return 0
    elif i < 0 or y<= 0:
        return -1000000000001
    return max(dp(i-delta-1, y-1) + arr[i-delta-1] for delta in range(min(k,i+1)))

print(max(dp(n,x),-1))


from sys import stdin, stdout
import collections

#T = int(input())
#s = input()
N,K,X = [int(x) for x in stdin.readline().split()]
arr = [int(x) for x in stdin.readline().split()]

if X < N//K:
    print(-1)
    quit()
    
dp = [[0]*N for _ in range(X)]

for i in range(K):
    dp[0][i] = arr[i]
    
for i in range(X-1):
    for j in range(N):
        if dp[i][j]!=0:
            for z in range(j+1,min(j+K+1,N)):
                #print(i,j,i+1,z)
                dp[i+1][z] = max(dp[i+1][z], dp[i][j] + arr[z])
                

res = 0        
for i in range(N-K,N):
    res = max(res,dp[X-1][i])
    
print(res)

import sys
S = sys.stdin.read()
S = list([list(map(int, x)) for x in list([x.split() for x in [x for x in S.split('\n') if len(x) > 1]])])
n, k, x, B = S[0][0], S[0][1], S[0][2], S[1]

X = [[-1 for i in range(x+1)] for i in range(n+1)]
X[0][0] = 0
for i in range(1, n+1): 
    for j in range(1, x+1): 
        X[i][j] = max([X[i][j], max([-1] + [X[i-l][j-1]+B[i-1] for l in range(1, min([i, k])+1) if X[i-l][j-1] != -1])])
print(max(list(map(max, X[n-k+1:n+1]))))


# -*- coding: utf-8 -*-

import sys

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return list(map(int, input().split()))
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
INF = 10 ** 18
MOD = 10 ** 9 + 7

N, K, X = MAP()
A = LIST()

dp = list2d(X+1, N+1, -1)
dp[0][0] = 0
for i in range(X):
    for j in range(N):
        if dp[i][j] == -1:
            continue
        for k in range(j, min(j+K, N)):
            dp[i+1][k+1] = max(dp[i+1][k+1], dp[i][j] + A[k])
ans = max(dp[X][-K:])
print(ans)


# -*- coding: utf-8 -*-

import sys

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return list(map(int, input().split()))
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
INF = 10 ** 18
MOD = 10 ** 9 + 7

N, K, X = MAP()
A = [0] + LIST()

dp = list2d(X+1, N+1, -1)
dp[0][0] = 0
for i in range(X):
    for j in range(N):
        if dp[i][j] == -1:
            continue
        for k in range(j+1, min(j+K+1, N+1)):
            dp[i+1][k] = max(dp[i+1][k], dp[i][j] + A[k])
ans = max(dp[X][-K:])
print(ans)


# -*- coding: utf-8 -*-

import sys

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return list(map(int, input().split()))
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
INF = 10 ** 18
MOD = 10 ** 9 + 7

N, K, X = MAP()
A = [0] + LIST()

dp = list2d(X+1, N+1, -1)
dp[0][0] = 0
for i in range(X):
    for j in range(i, N):
        if dp[i][j] == -1:
            continue
        for k in range(j+1, min(j+K+1, N+1)):
            dp[i+1][k] = max(dp[i+1][k], dp[i][j] + A[k])
ans = max(dp[X][-K:])
print(ans)