#include using namespace std; using ll=long long; using vin=vector; using vll=vector; using vvin=vector>; using vvll=vector>; using vstr=vector; using vvstr=vector>; using vch=vector; using vvch=vector>; using vbo=vector; using vvbo=vector>; using vpii=vector>; using pqsin=priority_queue,greater>; #define mp make_pair #define rep(i,n) for(int i=0;i<(int)(n);i++) #define rep2(i,s,n) for(int i=(s);i<(int)(n);i++) #define all(v) v.begin(),v.end() #define decp(n) cout<>n>>k>>m; vll a(n); vll num1; multiset num2; int tmp=inf;int res;ll sum=(ll)0;int cnt=0; rep(i,n){ cin>>a[i]; if(a[i]==0)cnt++; else if(a[i]<0)res=-1; else res=1; if(a[i]!=0&&tmp==inf){ sum+=a[i]; tmp=res; continue; } if((a[i]!=0&&res!=tmp)||cnt==m){ num1.push_back(abs(sum)); num2.insert(abs(sum)); sum=a[i]; cnt=1; tmp=res; } else if(a[i]!=0){ sum+=a[i]; cnt++; } } num1.push_back(abs(sum)); num2.insert(abs(sum)); int s=num1.size(); while(s>k){ auto p=*num2.begin(); rep(i,num1.size()){ if(num1[i]==p){ if(i!=num1.size()-1){ num2.erase(num2.find(num1[i+1])); num1[i+1]=abs(num1[i+1]-num1[i]); num2.insert(num1[i+1]); } else{ num2.erase(num2.find(num1[i-1])); num1[i-1]=abs(num1[i-1]-num1[i]); num2.insert(num1[i-1]); } num1.erase(num1.begin()+i); s--; break; } } } ll ans=(ll)0; rep(i,num1.size())ans+=num1[i]; cout<