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

ll a[100002];
int main()
{
    int n; cin>>n;
    for(int i = 0 ; i < n; i++) cin>>a[i];
    sort(a,a+n);
    ll posE=0,MxN=-10000000;
    vector <ll> odd ;
    for(int i = 0 ; i < n; i++){
       if (a[i] >= 0 ){
        if  (a[i] % 2 ==0) posE+= a[i];
        else odd.push_back(a[i]);
       }
       else if (a[i] < 0 && a[i] % 2 != 0)
        MxN = max(MxN,a[i]);
    }
    if (posE == 0 && odd.size() == 0) cout<<MxN<<endl;
    else if (posE !=0 && odd.size() == 0){
        ll ans = posE + MxN;
        cout<<ans <<endl;
    }
    else if (odd.size() != 0 && posE == 0){
        ll sum =0 ;
        int st =0 ;
        if (odd.size() % 2 == 0) st = 1;
            for(int i = st; i< odd.size() ; i++) sum += odd[i];
        ll ans ;
        if (st == 1)
            ans = max(MxN+sum+odd[0],sum);
        else ans = max(MxN+sum,sum);

        cout<< ans << endl;
    }
    else {
        ll ans = posE;
        int start=0,sum=0;
        if (odd.size() % 2 == 0)
            start = 1;
        for(int i = start ; i < odd.size() ; i++) sum += odd[i];
        ans += sum;
        ll ans2=0;
        if (start == 1)
            ans2 = ans + MxN + odd[0];
        ll ans3 = posE+MxN;
        ll ans4=0;
        if (start == 1) ans4 = MxN+sum+odd[0];
        else ans4 = MxN + sum;
        ll MAX = max(max(ans,ans2),max(ans3,ans4));
        cout<<MAX<<endl;
    }

    return 0;
}


#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <iterator>
using namespace std;

int main()
{
   int n ,a;
   cin>>n;
   vector <int> v , vec;

   for(int i = 0 ; i < n ; i++)
   {
       cin>>a;
       v.push_back(a);
   }

   if (n == 1){
    cout<<v[0]<<endl;
    return 0 ;
   }
   sort(v.begin(),v.end());

  // for(int i = 0 ; i < v.size() ; i++)
    //cout<<v[i]<<" " ;

   int cnteven = 0 , cntodd = 0 , sumeven = 0, sumodd = 0 , ODD = 0, comp = 0;

for(int i = v.size()-1 ; i >= 0  ; i--){

        if(v[i] % 2 == 0 && v[i] > 0){
        cnteven ++ ;
        sumeven += v[i];
        }
        if (v[i] % 2 != 0 && v[i] > 0){
            cntodd ++ ;
            ODD = v[i] ;
            sumodd += v[i];
        }
}

if (cnteven ==0 && cntodd == 0){
    for(int i = v.size()-1 ; i >= 0  ; i--){
        if (v[i] % 2 != 0 ){
            sumodd +=v[i] ;
            break ;
        }
    }

}

if (cntodd == 0 && cnteven !=0){
    for(int i = v.size()-1 ; i >= 0  ; i--){
        if (v[i] % 2 != 0 ){
            sumodd +=v[i] ;
            break ;
        }
    }
}
if (cnteven == 0 && cntodd != 0){
        for(int i = v.size()-1 ; i >= 0  ; i--){
        if (v[i] <= 0){
            if ( (sumodd + v[i]) % 2 != 0){
                sumodd += v[i];
                break ;
            }
        }
    }
}

int sum = 0 ;

if ( (cntodd % 2 == 0) && (sumodd % 2 == 0) ){
    sumodd -= ODD ;
}

sum = sumeven+sumodd;
cout<<sum<<endl;

    return 0;
}


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

ll a[100002];
int main()
{
    int n; cin>>n;
    for(int i = 0 ; i < n; i++) cin>>a[i];
    sort(a,a+n);
    ll posE=0,MxN=-100000;
    vector <ll> odd ;
    for(int i = 0 ; i < n; i++){
       if (a[i] >= 0 ){
        if  (a[i] % 2 ==0) posE+= a[i];
        else odd.push_back(a[i]);
       }
       else if (a[i] < 0 && a[i] % 2 != 0)
        MxN = max(MxN,a[i]);
    }
    if (posE == 0 && odd.size() == 0) cout<<MxN<<endl;
    else if (posE !=0 && odd.size() == 0){
        ll ans = posE + MxN;
        cout<<ans <<endl;
    }
    else if (odd.size() != 0 && posE == 0){
        ll sum =0 ;
        int st =0 ;
        if (odd.size() % 2 == 0) st = 1;
            for(int i = st; i< odd.size() ; i++) sum += odd[i];
        ll ans = max(MxN+sum+odd[0],sum);
        cout<< ans << endl;
    }
    else {
        ll ans = posE;
        int start,End;
        if (odd.size() % 2 != 0){
            start = 0;
        }
        else start = 1;
        End = odd.size();
        for(int i = start ; i < End ; i++) ans += odd[i];
        cout<<ans<<endl;
    }

    return 0;
}


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

ll a[100002];
int main()
{
    int n; cin>>n;
    for(int i = 0 ; i < n; i++) cin>>a[i];
    sort(a,a+n);
    ll posE=0,MxN=-10000000;
    vector <ll> odd ;
    for(int i = 0 ; i < n; i++){
       if (a[i] >= 0 ){
        if  (a[i] % 2 ==0) posE+= a[i];
        else odd.push_back(a[i]);
       }
       else if (a[i] < 0 && a[i] % 2 != 0)
        MxN = max(MxN,a[i]);
    }
    if (posE == 0 && odd.size() == 0) cout<<MxN<<endl;
    else if (posE !=0 && odd.size() == 0){
        ll ans = posE + MxN;
        cout<<ans <<endl;
    }
    else if (odd.size() != 0 && posE == 0){
        ll sum =0 ;
        int st =0 ;
        if (odd.size() % 2 == 0) st = 1;
            for(int i = st; i< odd.size() ; i++) sum += odd[i];
        ll ans ;
        if (st == 1)
            ans = max(MxN+sum+odd[0],sum);
        else ans = max(MxN+sum,sum);

        cout<< ans << endl;
    }
    else {
        ll ans = posE;
        int start=0,sum=0;
        if (odd.size() % 2 == 0)
            start = 1;
        for(int i = start ; i < odd.size() ; i++) sum += odd[i];
        ans += sum;
        ll ans2 = ans + MxN;
        ll ans3 = posE+MxN;
        ll ans4=0;
        if (start == 1) ans4 = MxN+sum+odd[0];
        ll MAX = max(max(ans,ans2),max(ans3,ans4));
        cout<<MAX<<endl;
    }

    return 0;
}


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

ll a[100002];
int main()
{
    int n; cin>>n;
    for(int i = 0 ; i < n; i++) cin>>a[i];
    sort(a,a+n);
    ll posE=0,MxN=-10000000;
    vector <ll> odd ;
    for(int i = 0 ; i < n; i++){
       if (a[i] >= 0 ){
        if  (a[i] % 2 ==0) posE+= a[i];
        else odd.push_back(a[i]);
       }
       else if (a[i] < 0 && a[i] % 2 != 0)
        MxN = max(MxN,a[i]);
    }
    if (posE == 0 && odd.size() == 0) cout<<MxN<<endl;
    else if (posE !=0 && odd.size() == 0){
        ll ans = posE + MxN;
        cout<<ans <<endl;
    }
    else if (odd.size() != 0 && posE == 0){
        ll sum =0 ;
        int st =0 ;
        if (odd.size() % 2 == 0) st = 1;
            for(int i = st; i< odd.size() ; i++) sum += odd[i];
        ll ans ;
        if (st == 1)
            ans = max(MxN+sum+odd[0],sum);
        else ans = max(MxN+sum,sum);

        cout<< ans << endl;
    }
    else {
        ll ans = posE;
        int start=0,sum=0;
        if (odd.size() % 2 == 0)
            start = 1;
        for(int i = start ; i < odd.size() ; i++) sum += odd[i];
        ll ans2 = ans + MxN;
        ll ans3 = posE+MxN;
        ll ans4;
        if (start == 1) ans4 = MxN+sum+odd[0];
        ll MAX = max(max(ans,ans2),max(ans3,ans4));
        cout<<MAX<<endl;
    }

    return 0;
}


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

ll a[100002];
int main()
{
    int n; cin>>n;
    for(int i = 0 ; i < n; i++) cin>>a[i];
    sort(a,a+n);
    ll posE=0,MxN=-10000000;
    vector <ll> odd ;
    for(int i = 0 ; i < n; i++){
       if (a[i] >= 0 ){
        if  (a[i] % 2 ==0) posE+= a[i];
        else odd.push_back(a[i]);
       }
       else if (a[i] < 0 && a[i] % 2 != 0)
        MxN = max(MxN,a[i]);
    }
    if (posE == 0 && odd.size() == 0) cout<<MxN<<endl;
    else if (posE !=0 && odd.size() == 0){
        ll ans = posE + MxN;
        cout<<ans <<endl;
    }
    else if (odd.size() != 0 && posE == 0){
        ll sum =0 ;
        int st =0 ;
        if (odd.size() % 2 == 0) st = 1;
            for(int i = st; i< odd.size() ; i++) sum += odd[i];
        ll ans ;
        if (st == 1)
            ans = max(MxN+sum+odd[0],sum);
        else ans = max(MxN+sum,sum);

        cout<< ans << endl;
    }
    else {
        ll ans = posE;
        int start,End;
        if (odd.size() % 2 != 0){
            start = 0;
        }
        else start = 1;
        End = odd.size();
        for(int i = start ; i < End ; i++) ans += odd[i];
        cout<<ans<<endl;
    }

    return 0;
}


#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <iterator>
using namespace std;

int main()
{
   int n ,a;
   cin>>n;
   vector <int> v , vec;

   for(int i = 0 ; i < n ; i++)
   {
       cin>>a;
       v.push_back(a);
   }

   if (n == 1){
    cout<<v[0]<<endl;
    return 0 ;
   }
   sort(v.begin(),v.end());

  // for(int i = 0 ; i < v.size() ; i++)
    //cout<<v[i]<<" " ;

   int cnteven = 0 , cntodd = 0 , sumeven = 0, sumodd = 0 , ODD = 0, comp = 0;

for(int i = v.size()-1 ; i >= 0  ; i--){

        if(v[i] % 2 == 0 && v[i] > 0){
        cnteven ++ ;
        sumeven += v[i];
        }
        if (v[i] % 2 != 0 && v[i] > 0){
            cntodd ++ ;
            ODD = v[i] ;
            sumodd += v[i];
        }
}

if (cnteven ==0 && cntodd == 0){
    for(int i = v.size()-1 ; i >= 0  ; i--){
        if (v[i] % 2 != 0 ){
            sumodd +=v[i] ;
            break ;
        }
    }

}

if (cntodd == 0 && cnteven !=0){
    for(int i = v.size()-1 ; i >= 0  ; i--){
        if (v[i] % 2 != 0 ){
            sumodd +=v[i] ;
            break ;
        }
    }
}
if (cnteven == 0 && cntodd != 0){
        for(int i = v.size()-1 ; i >= 0  ; i--){
        if (v[i] < 0){
            if ( (sumodd + v[i]) % 2 != 0){
                sumodd += v[i];
                break ;
            }
        }
    }

}

int sum = 0 ;

if ( (cntodd % 2 == 0) && (sumodd % 2 == 0) ){
    sumodd -= ODD ;
}

sum = sumeven+sumodd;
cout<<sum<<endl;

    return 0;
}


#include <iostream>
#include <algorithm>
#include <iomanip>
#include <string>
using namespace std;

int main() {
    long long int n, i, x=0, y=-100000, j;
    cin>>n;
    long long int a[n];
    for(i=0;i<n;i++)
        cin>>a[i];
    sort(a,a+n);
    for(i=n-1;i>=0;i--){
        //cout<<a[i]<<" ";
        x+=a[i];
        if(x%2!=0 && x>y)
            y=x;
    }
    cout<<y;
}


#include <iostream>
#include <algorithm>
#include <iomanip>
#include <string>
using namespace std;

int main() {
    long long int n, i, x=0, y=-100000, j;
    cin>>n;
    long long int a[n];
    for(i=0;i<n;i++)
        cin>>a[i];
    sort(a,a+n);
    for(i=n-1;i>=0;i--){
        if(a[i]<0 && y%2!=0)
            break;
        //cout<<a[i]<<" ";
        if(a[i]<0 && (-1*a[i])%2==0){}
        else
            x+=a[i];
        if(x%2!=0 && x>y)
            y=x;
    }
    cout<<y;
}


#include <iostream>
#include <algorithm>
#include <iomanip>
#include <string>
using namespace std;

int main() {
    long long int n, i, x=0, y=10000000;
    cin>>n;
    long long int a[n];
    for(i=0;i<n;i++){
        cin>>a[i];
        if(a[i]>=0)
            x+=a[i];
        if(a[i]%2!=0 && a[i]>0 && a[i]<y)
            y=a[i];
        if(a[i]<0 && (-1*a[i])%2!=0 && (-1*a[i])<y)
            y=-1*a[i];
    }
    if(x%2!=0)
        y=0;
    cout<<x-y;
}


#include <iostream>
#include <algorithm>
#include <iomanip>
#include <string>
using namespace std;

int main() {
    long long int n, i, x=0, y=-100000, j;
    cin>>n;
    long long int a[n];
    for(i=0;i<n;i++)
        cin>>a[i];
    sort(a,a+n);
    for(i=n-1;i>=0;i--){
        //cout<<a[i]<<" ";
        if(a[i]<0 && (-1*a[i])%2==0){}
        else
            x+=a[i];
        if(x%2!=0 && x>y)
            y=x;
    }
    cout<<y;
}


#include <iostream>
#include <algorithm>
#include <iomanip>
#include <string>
using namespace std;

int main() {
    long long int n, i, x, y, j;
    cin>>n;
    long long int a[n];
    for(i=0;i<n;i++)
        cin>>a[i];
    sort(a,a+n);
    for(i=n-1;i>=0;i--){
        if(a[i]<0)
            break;
        x+=a[i];
    }
    if(x%2!=0)
        cout<<x;
    else{
        for(j=i;j>=0;j--){
            if(-1*a[i]%2!=0){
                y=-1*a[i];
                break;
            }
        }
        while(i<=n){
            if(a[i]%2==0){
                if(y>a[i] && a[i]!=x)
                    y=a[i];
                break;
            }
            i++;
        }
        cout<<x-y;
    }
}


#include<bits/stdc++.h>
using namespace std;
int n,a,ans,mm=0x7f7f7f7f,len;
int main(){
 scanf("%d",&n);
 for(int i=1;i<=n;++i){
  scanf("%d",&a);
  if(a>0)ans+=a;
  if(abs(a)&1)mm=min(mm,abs(a));
 }
 if(ans%2==0)ans-=mm;
 printf("%d",ans);
}


#include<stdio.h>
#include<algorithm>
using namespace std;
int a[100005];
int hh(int k){
	if(k<0)return (-1)*k;
	else return k;
}
int main(){
	int n,k,ans=0,min=2147483647;
    scanf("%d",&n);
    k=n+1;
    for(int i=1;i<=n;++i){
    	scanf("%d",&a[i]);
	}
    sort(a+1,a+k);
    for(int i=1;i<=n;++i){
    	if(a[i]>0){
			k=i;break;
		}
	}
    for(int i=k;i<=n;++i){
    	ans+=a[i];
	}
    if(ans%2){
		printf("%d",ans);return 0;
	}
    for(int i=1;i<=n;++i){
    	a[i]=hh(a[i]);
    	if(a[i]%2){
    		if(a[i]<min)min=a[i];
		}
    }
    printf("%d",ans-min);
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int q=1;
int p=-1;
int b[100010];

int main()
{
   int a;
   int ans=0,cnt,add;
   cin>>a;
   for(int i=0;i<a;i++)
   {
   	cin>>b[i];
   }
   for(int i=0;i<a;i++)
   {
   	if(b[i]>0)
   	ans+=b[i];
   }
   if(ans%2==1)
   {
     cout<<ans;
     return 0;
   }
   if(ans%2==0)
   {
   	for(int i=0;i<a;i++)
   		if(b[i]%2==1&&b[i]>0)
		   {
   		q=min(b[i],q);
   	}
   	add=ans-q;
   	for(int i=0;i<a;i++)
   	{
   		if(b[i]%2==1&&b[i]<0)
   		p=max(b[i],p);
   	}
   	cnt=ans+p;
   	ans=min(add,cnt);
   	   cout<<-ans;
   }

	return 0;
}


// z7z_Eta
#include<cstdio>
#include<cctype>
#include<cstring>
#define re register
#define ll long long
#define il inline
#define rep(i,s,t) for(re int i=(s);i<=(t);i++)
#define each(i,u) for(re int i=head[u];i;i=bow[i].nxt)
#define mem(e,x,s) memset(e,x,(s)*sizeof(int)+4)
#define p(ch) putchar(ch)
#define pi(x) printf("%d",(x))
using namespace std;
//c_ints
il int ci(){
	re char ch;int f=1;
	while(!isdigit(ch=getchar()))ch=='-'? f=-1: 0;
	re int x=ch^'0';
	while(isdigit(ch=getchar()))x=(((x<<2)+x)<<1)+(ch^'0');
	return f*x;
}
template<typename T>
il T Max(const T& a,const T& b){
	return a<b ? b:a ;
}
int f[2][2];
int main(){
	int x, n= ci();
	bool cur,t;
	memset(f,0x80,sizeof(f));
	f[0][0]= 0;
	rep(i,1,n){
		cur= i&1;
		x= ci();
		t= x&1;
		f[cur][1]= Max(f[!cur][1],f[!cur][!t]+x);
		f[cur][0]= Max(f[!cur][0],f[!cur][t]+x);
	}
	pi(f[n&1][1]);
	return 0;
}


#include<bits/stdc++.h>
#include<stdio.h>
using namespace std;
int n,a[1000000+5],sum,ma=-9000000;
int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
		scanf("%d",&a[i]),sum+=a[i]>=0?a[i]:0;
	if(sum%2==1) printf("%d",sum);
	else{
		for(int i=1;i<=n;i++)
			if((sum-abs(a[i]))%2==1) ma=max(ma,sum-abs(a[i]));
		printf("%d",ma);
	}
	return 0;
}


#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <queue>
#include <cstring>
#include <string>
#include <stack>
#include <map>
#include <set>
#include <cmath>
using namespace std;

#define pb push_back
#define All(a) a.begin(), a.end()
#define met(a, b) memset(a, b, sizeof(a))
typedef long long ll;
typedef double db;
const int oo = 0x3f3f3f3f;
const ll INF = 2e18;
const db eps = 1e-8;
const db PI = acos(-1.0);
const int maxn = 1e5 + 7;

int dp1[maxn], dp2[maxn];

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

int main(void)
{
	int n = read();
	bool flag = false;
	int ans = -oo;
	for(int i = 1; i <= n; i++)
	{
		int val = read();
		if(val&1)
		{
			if(!flag)
			{
				dp1[i] = max(val, dp2[i-1]+val);
				dp2[i] = dp2[i-1];
				ans = max(ans, dp1[i]);
				flag = true;
			}
			else
			{
				dp1[i] = max(dp1[i-1], dp2[i-1]+val);
				dp2[i] = max(dp2[i-1], dp1[i-1]+val);
				ans = max(ans, dp1[i]);
			}
		}
		else
		{
			if(!flag)
			{
				dp1[i] = -oo;
				dp2[i] = max(dp2[i-1], dp2[i-1]+val);
				ans = max(ans, dp1[i]);
			}
			else
			{
				dp1[i] = max(dp1[i-1], dp1[i-1]+val);
				dp2[i] = max(dp2[i-1], dp2[i-1]+val);
				ans = max(ans, dp1[i]);
			}
		}
	}
//	for(int i = 1; i <= n; i++)
//	{
//		printf("%d ", dp1[i]);
//	}
//	cout<<endl;
//	for(int i = 1; i <= n; ++i)
//	{
//		printf("%d ", dp2[i]);
//	}
//	cout<<endl;
	printf("%d", ans);

	return 0;
}


#include <bits/stdc++.h>
using namespace std;
long long sum, minn = INT_MAX, maxn = INT_MIN, n, t;
int main() {
	scanf("%lld", &n);
	for(int i = 0; i != n; ++i) {
		scanf("%lld", &t);
		if(t%2 == 1 || (-t)%2 == 1) {
			if(t > 0) minn = min(minn, t);
			if(t < 0) maxn = max(maxn, t);
		}
		if(t > 0) sum += t;
	}
	if(sum%2 == 0) {
		if(minn == INT_MAX && maxn == INT_MIN) {
			printf("-1");
			return 0;
		}
		sum -= min(-maxn, minn);
	}
	printf("%lld", sum);
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
int main()
{
	int a,n,sum=0,minn=10001,mann=-10001;
	cin>>n;
	for (int i=1;i<=n;i++)
	{
	    cin>>a;
	    if (a>0)
	    {
	    	sum+=a;
	    	if ((a%2==1)&&(a<minn)) minn=a;
	    	continue;
		}
		if ((abs(a)%2==1)&&(a>mann)) mann=a;
    }
    if (sum%2==1){cout<<sum;return 0;}
    if ((sum+mann)>(sum-minn)) cout<<(sum+mann);
    else cout<<(sum-minn);
    return 0;
}


#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<iostream>
#include<math.h>
using namespace std;

#define ll long long
#define MAX 500005
ll a[MAX];
bool cmp(int x,int y)
{
    return x>y;
}
int main()
{
    int n;
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
        scanf("%I64d",&a[i]);
    sort(a+1,a+1+n,cmp);
    ll sum=0;
    ll x=MAX;
    for(int i=1;i<=n;i++){
        if(a[i]<0){
            if(a[i]%2==0)
                continue;
        }else{
            sum+=a[i];
        }
        if(abs(a[i])%2==1)
        x=min(abs(x),abs(a[i]));
    }
    if(sum%2==0)
    printf("%I64d\n",sum-x);
    else printf("%I64d\n",sum);
    return 0;
}


#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<iostream>
#include<math.h>
using namespace std;

#define ll long long
#define MAX 500005
ll a[MAX];
bool cmp(int x,int y)
{
    return x>y;
}
int main()
{
    int n;
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
        scanf("%I64d",&a[i]);
    sort(a+1,a+1+n,cmp);
    ll sum=0;
    ll ans=-999999;
    ll x;
    for(int i=1;i<=n;i++)
       if(a[i]%2){
          x=a[i];
          break;
       }
    for(int i=1;i<=n;i++){
        if(a[i]<0){
            if(a[i]%2==0)
                continue;
        }
        if(a[i]<0) a[i]=-min(abs(a[i]),abs(x));
        sum+=a[i];
        if(sum%2==1)ans=max(sum,ans);
    }
    printf("%I64d\n",ans);
    return 0;
}


#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<iostream>
#include<math.h>
using namespace std;

#define ll long long
#define MAX 500005
ll a[MAX];
bool cmp(int x,int y)
{
    return x>y;
}
int main()
{
    int n;
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
        scanf("%I64d",&a[i]);
    sort(a+1,a+1+n,cmp);
    ll sum=0;
    ll x=MAX;
    for(int i=1;i<=n;i++){
        if(a[i]<0){
            if(a[i]%2==0)
                continue;
        }else{
            sum+=a[i];
        }
        x=min(abs(x),abs(a[i]));
    }
    if(sum%2==0)
    printf("%I64d\n",sum-x);
    else printf("%I64d\n",sum);
    return 0;
}


#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<iostream>
#include<math.h>
using namespace std;

#define ll long long
#define MAX 500005
ll a[MAX];
bool cmp(int x,int y)
{
    return x>y;
}
int main()
{
    int n;
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
        scanf("%I64d",&a[i]);
    sort(a+1,a+1+n,cmp);
    ll sum=0;
    ll ans=-999999;
    ll x;
    for(int i=1;i<=n;i++)
       if(a[i]%2){
          x=a[i];
          break;
       }
    for(int i=1;i<=n;i++){
        if(a[i]<0){
            if(a[i]%2==0)
                continue;
        }
        if(a[i]<0){
            if(abs(a[i])>abs(x))
                a[i]=x;
            if(a[i]>0)a[i]=-a[i];
        }
        sum+=a[i];
        if(sum%2)ans=max(sum,ans);
    }
    printf("%I64d\n",ans);
    return 0;
}


#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<iostream>
#include<math.h>
using namespace std;

#define ll long long
#define MAX 500005
ll a[MAX];
bool cmp(int x,int y)
{
    return x>y;
}
int main()
{
    int n;
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
        scanf("%I64d",&a[i]);
    sort(a+1,a+1+n,cmp);
    ll sum=0;
    ll x;
    for(int i=1;i<=n;i++)
       if(a[i]%2==1||a[i]%2==-1){
          x=a[i];
          break;
       }
    for(int i=1;i<=n;i++){
        if(a[i]<0){
            if(a[i]%2==0)
                continue;
            x=min(abs(x),abs(a[i]));
            break;
        }else{
            sum+=a[i];
        }
    }
    if(sum%2==0)
    printf("%I64d\n",sum-x);
    else printf("%I64d\n",sum);
    return 0;
}


#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<iostream>
#include<math.h>
using namespace std;

#define ll long long
#define MAX 500005
ll a[MAX];
bool cmp(int x,int y)
{
    return x>y;
}
int main()
{
    int n;
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
        scanf("%I64d",&a[i]);
    sort(a+1,a+1+n,cmp);
    ll sum=0;
    ll ans=-99999999;
    ll x;
    for(int i=1;i<=n;i++)
       if(a[i]%2==1||a[i]%2==-1){
          x=a[i];
          break;
       }
    for(int i=1;i<=n;i++){
        if(a[i]<0){
            if(a[i]%2==0)
                continue;
            if(abs(a[i])>abs(x)) a[i]=x;
            if(a[i]>0)a[i]=-a[i];
        }
        sum+=a[i];
        if(sum%2)ans=max(sum,ans);
    }
    printf("%I64d\n",ans);
    return 0;
}


#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<iostream>
using namespace std;

#define ll long long
#define MAX 500005
ll a[MAX];
bool cmp(int x,int y)
{
    return x>y;
}
int main()
{
    int n;
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
        scanf("%I64d",&a[i]);
    sort(a+1,a+1+n,cmp);
    ll sum=0;
    ll ans=-99999;
    for(int i=1;i<=n;i++){
        if(a[i]<0){
            if(a[i]%2==0)
                continue;
        }
        sum+=a[i];
        if(sum%2)ans=max(sum,ans);
    }
    printf("%I64d\n",ans);
    return 0;
}


#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<iostream>
using namespace std;

#define ll long long
#define MAX 100005
ll a[MAX];
bool cmp(int x,int y)
{
    return x>y;
}
int main()
{
    int n;
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
        scanf("%I64d",&a[i]);
    sort(a+1,a+1+n,cmp);
    ll sum=0;
    ll ans=-99999;
    for(int i=1;i<=n;i++){
        sum+=a[i];
        if(sum%2)ans=max(sum,ans);
    }
    printf("%I64d\n",ans);
    return 0;
}


#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<iostream>
using namespace std;

#define ll long long
#define MAX 100005
ll a[MAX];
bool cmp(int x,int y)
{
    return x>y;
}
int main()
{
    int n;
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
        scanf("%I64d",&a[i]);
    sort(a+1,a+1+n,cmp);
    ll sum=0;
    ll ans=-99999;
    for(int i=1;i<=n;i++){
        if(a[i]<0){
            if(a[i]%2==0)
                continue;
        }
        sum+=a[i];
        if(sum%2)ans=max(sum,ans);
    }
    printf("%I64d\n",ans);
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
bool cmp(int x,int y);
int main()
{
    int n;
    vector<int>odds,evens,nodds;
    ll e_sum=0,ans1=0,ans2=0;
    scanf("%d",&n);
    for(int i=0;i<n;i++)
    {
        int x;
        scanf("%d",&x);
        if(x<0&&(x*-1)%2)nodds.push_back(x);
        if(x>0)
        {
            if(x%2)odds.push_back(x);
            else e_sum+=x;
        }
    }
    sort(odds.begin(),odds.end(),cmp);
    sort(nodds.begin(),nodds.end(),cmp);
    if(nodds.size()>0)ans2=nodds[0];
    ans1+=e_sum;
    ans2+=e_sum;
    if(odds.size()%2==0&&odds.size()!=0)
    {
        for(int i=0;i<odds.size()-1;i++)
        {
            ans1+=odds[i];
            if(nodds.size()>0)ans2+=odds[i];
        }
        ans2+=odds[odds.size()-1];
    }
    else if(odds.size()%2!=0&&odds.size()!=0)
    {
        for(int i=0;i<odds.size();i++)
        {
            ans1+=odds[i];
            if(i<odds.size()-1&&nodds.size()>0)ans2+=odds[i];
        }
    }
    //cout<<ans1<<" "<<ans2<<endl;
    if(ans1%2!=0&&ans2!=0)
    {
        cout<<max(ans1,ans2)<<endl;
    }
    else if (ans1%2!=0&&ans2%2==0)
    {
        cout<<ans1<<endl;
    }
    else if(ans2%2!=0&&ans1%2==0)
    {
        cout<<ans2<<endl;
    }
    return 0;
}
bool cmp(int x,int y)
{
    if(x>y)return true;
    else return false;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
bool cmp(int x,int y);
int main()
{
    int n;
    vector<int>odds,evens,nodds;
    ll e_sum=0,ans1=0,ans2=0;
    scanf("%d",&n);
    for(int i=0;i<n;i++)
    {
        int x;
        scanf("%d",&x);
        if(x<0&&(x*-1)%2)nodds.push_back(x);
        if(x>0)
        {
            if(x%2)odds.push_back(x);
            else e_sum+=x;
        }
    }
    sort(odds.begin(),odds.end(),cmp);
    sort(nodds.begin(),nodds.end(),cmp);
    if(nodds.size()>0)ans2=nodds[0];
    ans1+=e_sum;
    ans2+=e_sum;
    if(odds.size()%2==0&&odds.size()!=0)
    {
        for(int i=0;i<odds.size()-1;i++)ans1+=odds[i];
    }
    else if(odds.size()%2!=0)
    {
        for(int i=0;i<odds.size();i++)ans1+=odds[i];
    }
    if(ans1%2!=0&&ans2!=0)
    {
        cout<<max(ans1,ans2)<<endl;
    }
    else if (ans1%2!=0&&ans2%2==0)
    {
        cout<<ans1<<endl;
    }
    else if(ans2%2!=0&&ans1%2==0)
    {
        cout<<ans2<<endl;
    }
    return 0;
}
bool cmp(int x,int y)
{
    if(x>y)return true;
    else return false;
}


#include<bits/stdc++.h>
using namespace std;
typedef unsigned long long ll;
vector<ll>vec;
void MSA(int arr[],int n)
{
	int ans = arr[0],sum = 0;
	for(int i = 1;i < n; i++)
		ans=max(ans,arr[i]);
	if(ans<0)vec.push_back(ans);
	ans = 0;
	for(int i = 0 ;i < n; i++)
	{
		if(sum + arr[i] > 0)
			sum+=arr[i];
		else
			sum  = 0;
		vec.push_back(sum);
	}
}
int main()
{
    int n,arr[100500];
    scanf("%d",&n);
    for(int i=0;i<n;i++)
    {
        cin>>arr[i];
    }
    MSA(arr,n);
    int sum=0,ans=-1;
    for(int i=0;i<vec.size();i++)
    {
        if(vec[i]!=0)
        {
            sum+=vec[i];
            if(sum%2!=0)
            {
                if(ans<sum)ans=sum;
            }
        }
    }
    cout<<ans<<endl;

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
bool cmp(int x,int y);
int main()
{
    int n;
    vector<int>odds,evens,nodds;
    ll e_sum=0,ans1=0,ans2=0;
    scanf("%d",&n);
    for(int i=0;i<n;i++)
    {
        int x;
        scanf("%d",&x);
        if(x<0&&(x*-1)%2)nodds.push_back(x);
        if(x>0)
        {
            if(x%2)odds.push_back(x);
            else e_sum+=x;
        }
    }
    sort(odds.begin(),odds.end(),cmp);
    sort(nodds.begin(),nodds.end(),cmp);
    if(nodds.size()>0)ans2=nodds[0];
    ans1+=e_sum;
    ans2+=e_sum;
    if(odds.size()%2==0&&odds.size()!=0)
    {
        for(int i=0;i<odds.size()-1;i++)
        {
            ans1+=odds[i];
            ans2+=odds[i];
        }
        ans2+=odds[odds.size()-1];
    }
    else if(odds.size()%2!=0)
    {
        for(int i=0;i<odds.size();i++)
        {
            ans1+=odds[i];
            if(i<odds.size()-1)ans2+=odds[i];
        }
    }
    if(ans1%2!=0&&ans2!=0)
    {
        cout<<max(ans1,ans2)<<endl;
    }
    else if (ans1%2!=0&&ans2%2==0)
    {
        cout<<ans1<<endl;
    }
    else if(ans2%2!=0&&ans1%2==0)
    {
        cout<<ans2<<endl;
    }
    return 0;
}
bool cmp(int x,int y)
{
    if(x>y)return true;
    else return false;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
bool cmp(int x,int y);
int main()
{
    int n;
    vector<int>odds,evens,nodds;
    int e_sum=0,ans1=0,ans2=0;
    scanf("%d",&n);
    for(int i=0;i<n;i++)
    {
        int x;
        scanf("%d",&x);
        if(x<0&&(x*-1)%2)nodds.push_back(x);
        if(x>0)
        {
            if(x%2)odds.push_back(x);
            else e_sum+=x;
        }
    }
    sort(odds.begin(),odds.end(),cmp);
    sort(nodds.begin(),nodds.end(),cmp);
    if(nodds.size()>0)ans2=nodds[0];
    ans1+=e_sum;
    ans2+=e_sum;
    if(odds.size()%2==0&&odds.size()!=0)
    {
        for(int i=0;i<odds.size()-1;i++)ans1+=odds[i];
    }
    else
    {
        for(int i=0;i<odds.size();i++)ans1+=odds[i];
    }
    if(ans1%2!=0&&ans2!=0)
    {
        cout<<max(ans1,ans2)<<endl;
    }
    else if (ans1%2!=0&&ans2%2==0)
    {
        cout<<ans1<<endl;
    }
    else if(ans2%2!=0&&ans1%2==0)
    {
        cout<<ans2<<endl;
    }

    return 0;
}
bool cmp(int x,int y)
{
    if(x>y)return true;
    else return false;
}


#include<bits/stdc++.h>
using namespace std;
typedef  long long ll;
int main()
{
    int n;
    vector<ll>arr;
    scanf("%d",&n);
    for(int i=0;i<n;i++)
    {
        int x;scanf("%d",&x);
        arr.push_back(x);
    }
    sort(arr.begin(),arr.end());
    ll ans=0,sum=0;
    for(int i=0;i<arr.size();i++)
    {
        if(arr[i]>0)
            sum+=arr[i];
            if(sum%2!=0)
            {
                if(ans<sum)ans=sum;
            }
    }
    if(ans==0)cout<<-1<<endl;
    else cout<<ans<<endl;

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
bool cmp(int x,int y);
int main()
{
    int n;
    vector<int>odds,evens,nodds;
    int e_sum=0,ans1=0,ans2=0;
    scanf("%d",&n);
    for(int i=0;i<n;i++)
    {
        int x;
        scanf("%d",&x);
        if(x<0&&(x*-1)%2)nodds.push_back(x);
        if(x>0)
        {
            if(x%2)odds.push_back(x);
            else e_sum+=x;
        }
    }
    sort(odds.begin(),odds.end(),cmp);
    sort(nodds.begin(),nodds.end(),cmp);
    if(nodds.size()>0)ans2=nodds[0];
    ans1+=e_sum;
    ans2+=e_sum;
    if(odds.size()%2==0&&odds.size()!=0)
    {
        for(int i=0;i<odds.size()-1;i++)ans1+=odds[i];
    }
    else
    {
        for(int i=0;i<odds.size();i++)ans1+=odds[i];
    }
    if(ans1%2)cout<<ans1<<endl;
    else
    {
        if(ans2<0)cout<<ans2<<endl;
    }
    return 0;
}
bool cmp(int x,int y)
{
    if(x>y)return true;
    else return false;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
bool cmp(int x,int y);
int main()
{
    int n;
    vector<int>odds,evens;
    int e_sum=0,ans=0;
    scanf("%d",&n);
    for(int i=0;i<n;i++)
    {
        int x;
        scanf("%d",&x);
        if(x>0)
        {
            if(x%2)odds.push_back(x);
            else e_sum+=x;
        }
    }
    sort(odds.begin(),odds.end(),cmp);
    ans+=e_sum;
    if(odds.size()==0)cout<<-1<<endl;
    else if(odds.size()%2==0)
    {
        for(int i=0;i<odds.size()-1;i++)ans+=odds[i];
        cout<<ans<<endl;
    }
    else
    {
        for(int i=0;i<odds.size();i++)ans+=odds[i];
        cout<<ans<<endl;
    }

    return 0;
}
bool cmp(int x,int y)
{
    if(x>y)return true;
    else return false;
}


#include<bits/stdc++.h>

using namespace std;

long long n, a[100000], j = 0, s = 0, temp;
int main() {
    cin >> n;
    for(int i = 0; i < n; i++) {
        cin >> temp;
        if(temp % 2 == 0 && temp > 0) s += temp;
        else if(temp % 2 != 0) {
            a[j] = temp;
            j++;
        }
    }
    sort(a, a + j);
    s += a[j - 1];
    for(int i = j - 2; i >= 0; i--) {
        if(a[i] > 0) s+= a[i];
        else {
            if(s % 2 == 0) s -= a[i + 1];
            break;
        }
    }
    if(s % 2 == 0) s -= a[1];
    cout << s;
}


#include<bits/stdc++.h>

using namespace std;

long long n, a[100000], j = 0, s = 0, temp;
int main() {
    cin >> n;
    for(int i = 0; i < n; i++) {
        cin >> temp;
        if(temp % 2 == 0 && temp > 0) s += temp;
        else if(temp % 2 != 0) {
            a[j] = temp;
            j++;
        }
    }
    sort(a, a + j);
    s += a[j - 1];
    for(int i = j - 2; j>= 0; j--) {
        if(a[i] > 0) s+= a[i];
        else {
            if(s % 2 == 0) s -= a[i - 1];
            break;
        }
    }
    cout << s;
}


#include<bits/stdc++.h>

using namespace std;

long long n, a[100000], j = 0, s = 0, temp;
int main() {
    cin >> n;
    for(int i = 0; i < n; i++) {
        cin >> temp;
        if(temp % 2 == 0 && temp > 0) s += temp;
        else if(temp % 2 == 1) {
            a[j] = temp;
            j++;
        }
    }
    sort(a, a + j);
    s += a[j - 1];
    for(int i = j - 2; i >= 0; i--) {
        if(a[i] > 0) s+= a[i];
        else {
            if(s % 2 == 0) s -= a[i + 1];
            break;
        }
    }
    cout << s;
}


#include<bits/stdc++.h>

using namespace std;

long long n, a[100000], j = 0, s = 0, temp;
int main() {
    cin >> n;
    for(int i = 0; i < n; i++) {
        cin >> temp;
        if(temp % 2 == 0 && temp > 0) s += temp;
        else if(temp % 2 != 0) {
            a[j] = temp;
            j++;
        }
    }
    sort(a, a + j);
    s += a[j - 1];
    for(int i = j - 2; i >= 0; i--) {
        if(a[i] > 0){
            s += a[i];
            temp = i;
        }
        else break;
    }
    if(s % 2 == 0) s -= a[temp];
    cout << s;
}


#include<bits/stdc++.h>

using namespace std;

long long n, a[100000], j = 0, s = 0, temp;
int main() {
    cin >> n;
    for(int i = 0; i < n; i++) {
        cin >> temp;
        if(temp % 2 == 0 && temp > 0) s += temp;
        else if(temp % 2 != 0) {
            a[j] = temp;
            j++;
        }
    }
    sort(a, a + j);
    s += a[j - 1];
    for(int i = j - 2; i >= 0; i--) {
        if(a[i] > 0) s+= a[i];
        else {
            if(s % 2 == 0) s -= a[i - 1];
            break;
    }
    cout << s;
}


#include<bits/stdc++.h>

using namespace std;

long long n, a[100000], j = 0, s = 0, temp;
int main() {
    cin >> n;
    for(int i = 0; i < n; i++) {
        cin >> temp;
        if(temp % 2 == 0 && temp > 0) s += temp;
        else if(temp % 2 != 0) {
            a[j] = temp;
            j++;
        }
    }
    sort(a, a + j);
    s += a[j - 1];
    for(int i = j - 2; j>= 0; j--) {
        if(a[i] > 0) s+= a[i];
        else break;
    }
    cout << s;
}


#include<bits/stdc++.h>

using namespace std;

long long n, a[100000], j = 0, s = 0, temp;
int main() {
    cin >> n;
    for(int i = 0; i < n; i++) {
        cin >> temp;
        if(temp % 2 == 0 && temp > 0) s += temp;
        else if(temp % 2 != 0) {
            a[j] = temp;
            j++;
        }
    }
    sort(a, a + j);
    s += a[j - 1];
    for(int i = j - 2; i >= 0; i--) {
        if(a[i] > 0) s+= a[i];
        else if(a[i] < 0 || i == 0) {
            if(s % 2 == 0) s -= a[i + 1];
            break;
        }
    }
    cout << s;
}


#include<bits/stdc++.h>

using namespace std;

long long n, a[100000], j = 0, s = 0, temp;
int main() {
    cin >> n;
    for(int i = 0; i < n; i++) {
        cin >> temp;
        if(temp % 2 == 0 && temp > 0) s += temp;
        else if(temp % 2 != 0) {
            a[j] = temp;
            j++;
        }
    }
    sort(a, a + j);
    s += a[j - 1];
    for(int i = j - 2; i >= 0; i--) {
        if(a[i] > 0) s+= a[i];
        else {
            if(s % 2 == 0) s -= a[i + 1];
            break;
        }
    }
    cout << s;
}


#include<bits/stdc++.h>

using namespace std;

long long n, s = 0, temp, maxsum = -1e9, sum = 0;
vector <int> a;
int main() {
    cin >> n;
    for(int i = 0; i < n; i++) {
        cin >> temp;
        if(temp % 2 == 0) {
            if(temp > 0) s += temp;
        }
        else {
            a.push_back(temp);
        }
    }
    sort(a.begin(), a.end());
    reverse(a.begin(), a.end());
    for(int i = 0; i < a.size(); i++) {
        sum += a[i];
        if(i%2 == 0) maxsum = max(maxsum, sum);
    }
    cout << s + sum;
}


#include<bits/stdc++.h>

using namespace std;

long long n, a[100000], j = 0, s = 0, temp;
int main() {
    cin >> n;
    for(int i = 0; i < n; i++) {
        cin >> temp;
        if(temp % 2 == 0 && temp > 0) s += temp;
        else if(temp % 2 != 0) {
            a[j] = temp;
            j++;
        }
    }
    sort(a, a + j);
    s += a[j - 1];
    for(int i = j - 2; j>= 0; j--) {
        if(a[i] > 0) s+= a[i];
        else {
            if(s % 2 == 0) s -= a[i - 1];
            break;
    }
    cout << s;
}


#include<bits/stdc++.h>

using namespace std;

long long n, a[100000], j = 0, s = 0, temp, neg = -1e4;
int main() {
    cin >> n;
    for(int i = 0; i < n; i++) {
        cin >> temp;
        if(temp % 2 == 0 && temp > 0) s += temp;
        else if(temp % 2 != 0) {
            if(temp < 0) neg = max(neg, temp);
            else {
                a[j] = temp;
                j++;
            }
        }
    }
    if(j == 0) cout << s + neg;
    else {
        sort(a, a + j);
        for(int i = j - 1; i >= ((j + 1) % 2); i--) {
            s += a[i];
        }
        cout << s;
    }
}


#include<bits/stdc++.h>

using namespace std;

long long n, s = 0, temp, maxsum = -1e9, sum = 0;
vector <int> a;
int main() {
    cin >> n;
    for(int i = 0; i < n; i++) {
        cin >> temp;
        if(temp % 2 == 0) {
            if(temp > 0) s += temp;
        }
        else {
            a.push_back(temp);
        }
    }
    sort(a.begin(), a.end());
    reverse(a.begin(), a.end());
    for(int i = 0; i < a.size(); i++) {
        sum += a[i];
        if(i%2 == 0) maxsum = max(maxsum, sum);
    }
    cout << s + maxsum;
}


#include<bits/stdc++.h>

using namespace std;

long long n, a[100000], j = 0, s = 0, temp;
int main() {
    cin >> n;
    for(int i = 0; i < n; i++) {
        cin >> temp;
        if(temp % 2 == 0 && temp > 0) s += temp;
        else if(temp % 2 != 0) {
            a[j] = temp;
            j++;
        }
    }
    sort(a, a + j);
    s += a[j - 1];
    for(int i = j - 2; i >= 0; i--) {
        if(a[i] > 0) s+= a[i];
        else {
            if(s % 2 == 0) s -= a[i - 1];
            break;
        }
    }
    cout << s;
}


#include<bits/stdc++.h>

using namespace std;

long long n, a[100000], j = 0, s = 0, temp;
int main() {
    cin >> n;
    for(int i = 0; i < n; i++) {
        cin >> temp;
        if(temp % 2 == 0 && temp > 0) s += temp;
        else if(temp % 2 != 0) {
            a[j] = temp;
            j++;
        }
    }
    sort(a, a + j);
    s += a[j - 1];
    for(int i = j - 2; i >= 0; i--) {
        if(a[i] > 0) s+= a[i];
        else {
            if(s % 2 == 0) s -= a[i + 1];
            break;
        }
    }
    if(s % 2 == 0) s -= a[0];
    cout << s;
}


#include<bits/stdc++.h>

using namespace std;

long long n, a[100000], j = 0, s = 0;
int main() {
    cin >> n;
    for(int i = 0; i < n; i++) {
        cin >> temp;
        if(temp % 2 == 0 && temp > 0) s += temp;
        else if(temp % 2 != 0) {
            a[j] = temp;
            j++;
        }
    }
    sort(a, a + j);
    s += a[j - 1];
    for(int i = j - 2; j>= 0; j--) {
        if(a[i] > 0) s+= a[i];
        else break;
    }
    cout << s;
}


#include <bits/stdc++.h>

#define ll long long
const int MAXX = 1e6;
int arr[MAXX], dp[MAXX];
using namespace std;

int main(){
	// ios_base::sync_with_stdio(0);
	// cin.tie(0);
	// cout.tie(0);
	ll n, k ; int ans = -2*MAXX;
	cin >> n;
	for (int i = 0; i < n; i++ )
		cin >> arr[i];
	memset( dp, ans, sizeof dp );
	dp[0] = arr[0];
	for (int i = 1; i < n; i++ ){
		for (int j = 0; j < n; j++ ) {
			// if( dp[j] + arr[i] % 2 != 0)
				dp[i] = max( dp[i], arr[j] + arr[i] );
		}
		if( dp[i] % 2 != 0 )
			ans = max( ans, dp[i] );
	}
	cout << ans << endl;

	cin >> n;
    return 0;
}


#include <bits/stdc++.h>

#define ll long long
const int MAXX = 1e6;
int arr[MAXX];
using namespace std;

int main(){
	// ios_base::sync_with_stdio(0);
	// cin.tie(0);
	// cout.tie(0);
	ll n; int ans = 0;vector<int> v;
	cin >> n;
	for (int i = 0; i < n; i++ )
		cin >> arr[i];
	sort( arr, arr + n );
		for (int i = n - 1; i >= 0; --i){
			if( arr[i] % 2 == 0 && arr[i] > 0 )
				ans += arr[i];
			else if( arr[i] % 2 != 0 )
				v.push_back(arr[i]);
		}
		sort(v.begin(), v.end());
		reverse(v.begin(), v.end());
		ans += v[0];
		for( int i = 1; i < v.size(); i++ ){
			if( i % 2 != 0 ) continue;
			int t = v[i] + v[ i - 1];
			ans = max( ans, ans + t );
		}

	cout << ans << endl;

	cin >> n;
    return 0;
}


#include <bits/stdc++.h>

#define ll long long
const int MAXX = 1e6;
int arr[MAXX], dp[MAXX];
using namespace std;

int main(){
	// ios_base::sync_with_stdio(0);
	// cin.tie(0);
	// cout.tie(0);
	ll n, k ; int ans = -2*MAXX;
	cin >> n;
	for (int i = 0; i < n; i++ )
		cin >> arr[i];
	memset( dp, ans, sizeof dp );
	dp[0] = ans = arr[0];
	for (int i = 1; i < n; i++ ){
		for (int j = 0; j < n; j++ ) {
			// if( dp[j] + arr[i] % 2 != 0)
				dp[i] = max( dp[i], arr[j] + arr[i] );
		}
		if( dp[i] % 2 != 0 )
			ans = max( ans, dp[i] );
	}
	cout << ans << endl;

	cin >> n;
    return 0;
}


#include <bits/stdc++.h>

#define ll long long
const int MAXX = 1e6;
int arr[MAXX], dp[MAXX];
using namespace std;

int main(){
	// ios_base::sync_with_stdio(0);
	// cin.tie(0);
	// cout.tie(0);
	ll n, k ; int ans = -2*MAXX;
	cin >> n;
	for (int i = 0; i < n; i++ )
		cin >> arr[i];
	memset( dp, ans, sizeof dp );
	dp[0] = ans = arr[0];
	for (int i = 1; i < n; i++ ){
		for (int j = 0; j < n; j++ ) {
			if( arr[j] + arr[i] % 2 != 0)
				dp[i] = max( dp[i], arr[j] + arr[i] );
		}

	}
	cout << dp[n - 1] << endl;

	cin >> n;
    return 0;
}


#include <bits/stdc++.h>

#define ll long long
const int MAXX = 1e6;
int arr[MAXX];
using namespace std;

int main(){
	// ios_base::sync_with_stdio(0);
	// cin.tie(0);
	// cout.tie(0);
	ll n; int ans = 0;vector<int> v;
	cin >> n;
	for (int i = 0; i < n; i++ )
		cin >> arr[i];
	sort( arr, arr + n );
		for (int i = n - 1; i >= 0; --i){
			if( arr[i] % 2 == 0 && arr[i] > 0 )
				ans += arr[i];
			else if( arr[i] % 2 != 0 )
				v.push_back(arr[i]);
		}

		for( int i = 0; i < v.size(); i++ ){
			if( i % 2 != 0 ) continue;
			int t = v[i] + ( i > 0 ? v[ i - 1] : 0 );
			if( ans == 0 ) ans += v[i];
			else ans = max( ans, ans + t );
		}

	cout << ans << endl;

	cin >> n;
    return 0;
}


#include <bits/stdc++.h>

#define ll long long
const int MAXX = 1e6;
int arr[MAXX];
using namespace std;

int main(){
	// ios_base::sync_with_stdio(0);
	// cin.tie(0);
	// cout.tie(0);
	ll n; int ans = 0;vector<int> v;
	cin >> n;
	for (int i = 0; i < n; i++ )
		cin >> arr[i];
	sort( arr, arr + n );
		for (int i = n - 1; i >= 0; --i){
			if( arr[i] % 2 == 0 && arr[i] > 0 )
				ans += arr[i];
			else if( arr[i] % 2 != 0 )
				v.push_back(arr[i]);
		}
		sort(v.begin(), v.end());
		reverse(v.begin(), v.end());
		for( int i = 0; i < v.size(); i++ ){
			if( i % 2 != 0 ) continue;
			int t = v[i] + ( i > 0 ? v[ i - 1] : 0 );
			if( ans == 0 ) ans += v[i];
			else ans += t;
		}

	cout << ans << endl;

	cin >> n;
    return 0;
}


#include <bits/stdc++.h>

#define ll long long
const int MAXX = 1e6;
int arr[MAXX];
using namespace std;

int main(){
	// ios_base::sync_with_stdio(0);
	// cin.tie(0);
	// cout.tie(0);
	ll n; int ans = 0, idx, count = 0, last = MAXX;
	cin >> n;
	for (int i = 0; i < n; i++ )
		cin >> arr[i];
	sort( arr, arr + n );
	if( n == 1 )
		ans = arr[0];
	else {
		for (int i = n - 1; i >= 0; --i){
			if( arr[i] % 2 == 0 && arr[i] > 0 )
				ans += arr[i];
			else if( arr[i] % 2 != 0 ){
				if( ans + arr[i] > ans ){
					count++;idx = (arr[i] < last ? i : idx);
					ans += arr[i];
				}

			}
		}
		if( count % 2 == 0 )
			ans -= arr[idx];
	}

	cout << ans << endl;

	cin >> n;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
int main()
{
	int n,x,sum=0,mxf=-10000000,mnz=10000000;
	cin>>n;
	for(int i=0;i<n;i++)
	{
		cin>>x;
		if(x>=0) sum+=x;
		if(x%2!=0)
		{
			if(x<0) mxf=max(x,mxf);
			else mnz=min(x,mnz);
		}
	}
	if(sum%2!=0) cout<<sum<<endl;
	else cout<<sum-min(abs(mxf),mnz)<<endl;
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
int a[100010], n, ans = -1e9, sum, x, y;
int main() {
	cin >> n;
	for (register int i = 1; i <= n; ++i) scanf("%d", a + i);
	for (register int i = 1; i <= n; ++i) {
		if (a[i] > 0) sum += a[i], ++x;
		else if (a[i] < 0) ++y;
	}
	if (sum & 1) {
		cout << sum << endl;
		return 0;
	} else {
		int minn = -1e9, maxn = 1e9;
		if (y > 1) {
			for (register int i = 1; i <= n; ++i) {
				if ((a[i] & 1) && a[i] < 0) minn = max(minn, a[i]);
			}
			//cout << sum << ' ' << minn << endl;
			ans = max(ans, sum + minn);
			//cout << ans << endl;
		}

		if (x > 1) {
			for (register int i = 1; i <= n; ++i) {
				if ((a[i] & 1) && a[i] > 0) maxn = min(maxn, a[i]);
			}
			ans = max(ans, sum - maxn);
		}

	}
	cout << ans;
}


#include<bits/stdc++.h>
#include<stdio.h>
using namespace std;
int n,a,ma=-1,b[100000+5];
int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++){
		scanf("%d",&a);
		b[i]=b[i-1]+a[i];
	}
	for(int i=1;i<=n;i++)
		for(int j=1;j<i;j++)
			if((b[i]-b[j-1])%2==1)
				ma=maz(ma,b[i]-b[j-1]);
	printf("%d",ma);
	return 0;
}


#include<bits/stdc++.h>
#include<stdio.h>
using namespace std;
int n,a,ma=-1,b[100000+5];
int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++){
		scanf("%d",&a);
		b[i]=b[i-1]+a;
	}
	for(int i=1;i<=n;i++)
		for(int j=1;j<i;j++)
			if((b[i]-b[j-1])%2==1)
				ma=max(ma,b[i]-b[j-1]);
	printf("%d",ma);
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
inline int read(){
    char ch=getchar();int x=0,f=1;
    while(ch>'9' || ch<'0'){
        if(ch=='-') f=-1;
        ch=getchar();
    }
    while(ch>='0' && ch<='9'){
        x=x*10+ch-'0';
        ch=getchar();
    }
    return x*f;
}
int aa=0x7fffffff;
int bb=-0x7fffffff;
int sum;
int main(){
    int n=read();
    for(int i=1;i<=n;i++){
        int d=read();
        if(d>=0) {
            sum+=d;
            if(d%2==1){
                aa=min(aa,d);
            }
        }
        else {
            if(abs(d)%2==1){
                bb=max(bb,d);
            }
        }
    }
    if(sum%2==1)
	{
        printf("%d\n",sum);
        return 0;
    }
    if(aa==0x7fffffff){
        sum=sum+bb;
    }
    else if(bb==-0x7fffffff){
        sum=sum-aa;
    }
    else  {
        sum=max(sum+bb,sum-aa);
    }
    printf("%d\n",sum);
    return 0;
}


#include<bits/stdc++.h>
#include<stdio.h>
using namespace std;
int n,a,sum,ma=-9000000,mi=9000000;
int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++){
		scanf("%d",&a);
		sum+=a>=0?a:0;
		ma=a<0&&abs(a%-2)?max(ma,a):ma;
		mi=a>=0&&a%2?min(mi,a):a;
	}
	if(sum%2)
		printf("%d",sum);
	else
		printf("%d",max(sum-mi,sum+ma));
	return 0;
}


#include <iostream>
#include <cmath>
using namespace std;
int main()
{
	int n;
	cin>>n;
	int a[n],sum,m=9999;
	for(int i=0;i<n;i++){
		cin>>a[i];
		if(a[i]>0)sum+=a[i];
	}
	if(sum%2==0){
		for(int i=0;i<n;i++){
			if(abs(a[i])%2==1&&abs(a[i])<m)m=abs(a[i]);
		}
	}else m=0;
	cout<<sum-m;
}


#include<bits/stdc++.h>
#include<stdio.h>
using namespace std;
int n,a[1000000+5],sum,ma=-9000000;
int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
		scanf("%d",&a[i]),sum+=a[i];
	if(sum%2==1) printf("%d",sum);
	else{
		for(int i=1;i<=n;i++)
			if((sum-abs(a[i]))%2==1) ma=max(ma,sum-abs(a[i]));
		printf("%d",ma);
	}
	return 0;
}


#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <string>
#include <stdlib.h>
#include <vector>
#include <queue>
#include <cmath>
#include <stack>
#include <map>
#include <set>
using namespace std;
typedef long long ll;
const ll inf = (ll)1 << 62;
const ll maxn = 1e5+10;
const int INF=0x3f3f3f3f;
const int mod=1e9+7;
int main() {
int n;
int a[maxn];
int odd[maxn]={0};
cin>>n;
int sum=0,k=0;
int sum2;
bool flag=false;
for(int i=0;i<n;i++)
{scanf("%d",&a[i]);
if(a[i]>0) sum+=a[i];
if(a[i]>0&&a[i]%2)flag=true;}
if(!flag) {
cout<<-1<<endl;
return 0;
}
if(sum%2)
{sort(a,a+n);
sum2=sum;
for(int i=0;i<n;i++)
{if(a[i]>0&&a[i]%2)
{sum-=a[i];break;}}
for(int i=n-1;i>=0;i--)
{if(a[i]<0&&a[i]%2)
{sum+=a[i];break;}}}
cout<<max(sum,sum2)<<endl;
}


#include<iostream>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<queue>
#include<algorithm>
using namespace std;
int n,maxn=-1;
long long a[5005],sum=0;
bool cmp(int a,int b){
	return a>b;
}
int main(){
	priority_queue<int,vector<int> >q;
	//freopen("odd.in","r",stdin);
	//freopen("odd.out","w",stdout);
	cin>>n;
	for(int i=1;i<=n;i++) cin>>a[i];
	sort(a+1,a+n+1,cmp);
	for(int i=1;i<=n;i++){
		sum+=a[i];
		if(sum>maxn && sum%2==1){
			maxn=sum;
		}
	}
	cout<<maxn;
	return 0;
}


#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
int main()
{
    int n;
    cin >> n;
    vector<int> nuo;
    vector<int> nue;
    int sum  = 0;
    for (int i = 0; i < n; ++i)
    {
        int te;
        cin >> te;
        if (abs(te) % 2 == 0)
        {
            if (te > 0)
                sum += te;
        }
        else
            nuo.push_back(te);
    }
    sort(nuo.begin(), nuo.end(), greater<int>());
    int i;
    sum += nuo[0];
    for (i = 1; i < nuo.size(); ++i)
    {
        if (nuo[i] < 0)
        {
            if (i % 2 != 0)
                break;
            else
                sum = max(sum - nuo[i-1], sum + nuo[i]);
        }
        else
            sum += nuo[i];
    }
    if (i > 0 && nuo[i-1] > 0 && sum % 2 == 0)
        sum -= nuo[i-1];
    cout << sum;
    return 0;
}


#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
int main()
{
    int n;
    cin >> n;
    vector<int> nuo;
    vector<int> nue;
    for (int i = 0; i < n; ++i)
    {
        int te;
        cin >> te;
        if (abs(te) % 2 == 0)
            nue.push_back(te);
        else
            nuo.push_back(te);
    }
    sort(nuo.begin(), nuo.end(), greater<int>());
    sort(nue.begin(), nue.end(), greater<int>());
    int sum  = 0;
    for (auto i : nue)
        if (i > 0)
            sum += i;
    for (int i = 0; i < nuo.size(); ++i)
    {
        if (nuo[i] < 0)
        {
            if (i == 0)
            {
                sum += nuo[i];
                break;
            }
            if (sum % 2 == 0)
            {
                sum = max(sum - nuo[i-2], sum + nuo[i]);
                break;
            }
        }
        else
            sum += nuo[i];
    }
    cout << sum;
    return 0;
}


#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
int main()
{
    int n;
    cin >> n;
    vector<int> nuo;
    vector<int> nue;
    for (int i = 0; i < n; ++i)
    {
        int te;
        cin >> te;
        if (abs(te) % 2 == 0)
            nue.push_back(te);
        else
            nuo.push_back(te);
    }
    sort(nuo.begin(), nuo.end(), greater<int>());
    sort(nue.begin(), nue.end(), greater<int>());
    int sum  = 0;
    for (auto i : nue)
        if (i > 0)
            sum += i;
    int i;
    for (i = 0; i < nuo.size(); ++i)
    {
        if (nuo[i] < 0)
        {
            if (i == 0)
            {
                sum += nuo[i];
                break;
            }
            if (sum % 2 == 0)
            {
                sum = max(sum - nuo[i-2], sum + nuo[i]);
                break;
            }
        }
        else
            sum += nuo[i];
    }
    if (nuo[i-1] > 0 && sum % 2 == 0)
        sum -= nuo[i-2];
    cout << sum;
    return 0;
}


#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
int main()
{
    int n;
    cin >> n;
    vector<int> nuo;
    vector<int> nue;
    for (int i = 0; i < n; ++i)
    {
        int te;
        cin >> te;
        if (abs(te) % 2 == 0)
            nue.push_back(te);
        else
            nuo.push_back(te);
    }
    sort(nuo.begin(), nuo.end(), greater<int>());
    sort(nue.begin(), nue.end(), greater<int>());
    int sum  = 0;
    for (auto i : nue)
        if (i > 0)
            sum += i;
    for (int i = 0; i < nuo.size(); ++i)
    {
        if (nuo[i] < 0)
        {
            if (i == 0)
            {
                sum += nuo[i];
                break;
            }
            if (i % 2 == 0)
            {
                sum = max(sum - nuo[i-2], sum + nuo[i]);
                break;
            }
        }
        else
            sum += nuo[i];
    }
    cout << sum;
    return 0;
}


#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
int main()
{
    int n;
    cin >> n;
    vector<int> nuo;
    vector<int> nue;
    int sum  = 0;
    for (int i = 0; i < n; ++i)
    {
        int te;
        cin >> te;
        if (abs(te) % 2 == 0)
            if (te > 0)
                sum += te;
        else
            nuo.push_back(te);
    }
    sort(nuo.begin(), nuo.end(), greater<int>());
    int i;
    sum += nuo[0];
    for (i = 1; i < nuo.size(); ++i)
    {
        if (nuo[i] < 0)
        {
            if (i % 2 != 0)
                break;
            else
                sum = max(sum - nuo[i-1], sum + nuo[i]);
        }
        else
            sum += nuo[i];
    }
    if (i > 0 && nuo[i-1] > 0 && sum % 2 == 0)
        sum -= nuo[i-1];
    cout << sum;
    return 0;
}


#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
int main()
{
    int n;
    cin >> n;
    vector<int> nuo;
    vector<int> nue;
    for (int i = 0; i < n; ++i)
    {
        int te;
        cin >> te;
        if (abs(te) % 2 == 0)
            nue.push_back(te);
        else
            nuo.push_back(te);
    }
    sort(nuo.begin(), nuo.end(), greater<int>());
    sort(nue.begin(), nue.end(), greater<int>());
    int sum  = 0;
    for (auto i : nue)
        if (i > 0)
            sum += i;
    int i;
    sum += nuo[0];
    for (i = 1; i < nuo.size(); ++i)
    {
        if (nuo[i] < 0)
        {
            if (i % 2 != 0)
                break;
            else
                sum = max(sum - nuo[i-1], sum + nuo[i]);
        }
        else
            sum += nuo[i];
    }
    if (i > 0 && nuo[i-1] > 0 && sum % 2 == 0)
        sum -= nuo[i-1];
    cout << sum;
    return 0;
}


#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
int main()
{
    int n;
    cin >> n;
    vector<int> nuo;
    vector<int> nue;
    for (int i = 0; i < n; ++i)
    {
        int te;
        cin >> te;
        if (abs(te) % 2 == 0)
            nue.push_back(te);
        else
            nuo.push_back(te);
    }
    sort(nuo.begin(), nuo.end(), greater<int>());
    sort(nue.begin(), nue.end(), greater<int>());
    int sum  = 0;
    for (auto i : nue)
        if (i > 0)
            sum += i;
    int i;
    for (i = 0; i < nuo.size(); ++i)
    {
        if (nuo[i] < 0)
        {
            if (i == 0)
            {
                sum += nuo[i];
                break;
            }
            if (sum % 2 == 0)
            {
                sum = max(sum - nuo[i-2], sum + nuo[i]);
                break;
            }
        }
        else
            sum += nuo[i];
    }
    if (i > 0 && nuo[i-1] > 0 && sum % 2 == 0)
        sum -= nuo[i-1];
    cout << sum;
    return 0;
}


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

int main()
{
    long long int n,k,x,sum=0,j,l,r;
    cin>>n;
    int arr[n];
    for(int i=0;i<n;i++)
        {
            cin>>arr[i];
            if(arr[i]>0)
                sum+=arr[i];
        }
        if(sum%2!=0)
            cout<<sum;
        else
        {
            sort(arr,arr+n);
            x=0;
            for( j=0;j<n;j++)
                if(arr[j]>=0)
                  break;
              l=j-1;r=j;
             while(arr[l]%2==0)
                 l--;
             while(arr[r]%2==0)
                  r++;
             if(arr[r]<abs(arr[l]))
                sum-=arr[r];
             else
                sum+=arr[l];

            cout<<sum;
        }

}


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

int main()
{
    long long int n,k,x,sum=0,j,l,r;
    cin>>n;
    int arr[n];
    for(int i=0;i<n;i++)
        {
            cin>>arr[i];
            if(arr[i]>0)
                sum+=arr[i];
        }
        if(sum%2!=0)
            cout<<sum;
        else
        {
            sort(arr,arr+n);
            x=0;
            for( j=0;j<n;j++)
                if(arr[j]>=0)
                  break;
              l=j-1;r=j;
             while(l>0&&arr[l]%2==0)
                 l--;
             while(r<n-1&&arr[r]%2==0)
                  r++;
             if(arr[r]<abs(arr[l]))
                sum-=arr[r];
             else
                sum+=arr[l];

            cout<<sum;
        }

}


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

int main()
{
    long long int n,k,x,sum=0,j,l,r;
    cin>>n;
    int arr[n];
    for(int i=0;i<n;i++)
        {
            cin>>arr[i];
            if(arr[i]>0)
                sum+=arr[i];
        }
        if(sum%2!=0)
            cout<<sum;
        else
        {
            sort(arr,arr+n);
            x=0;
            for( j=0;j<n;j++)
                if(arr[j]>=0)
                  break;
              l=j-1;r=j;
             while(l>=0&&arr[l]%2==0)
                 l--;
             while(r<n&&arr[r]%2==0)
                  r++;
             if(arr[r]<abs(arr[l]))
                sum-=arr[r];
             else
                sum+=arr[l];

            cout<<sum;
        }

}


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

int main()
{
    long long int n,k,x,sum=0,j;
    cin>>n;
    int arr[n];
    for(int i=0;i<n;i++)
        {
            cin>>arr[i];
            if(arr[i]>0)
                sum+=arr[i];
        }
        if(sum%2!=0)
            cout<<sum;
        else
        {
            sort(arr,arr+n);
            x=0;
            for( j=0;j<n;j++)
                if(arr[j]>=0)
                  break;
             for(int i=j;i>=0;i--)
             {
                 if(arr[i]%2!=0)
                 {
                    sum+=arr[i];
                    break;
                 }
             }
            cout<<sum;
        }

}


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

int main()
{
    long long int n,k,x,sum=0,j,l,r;
    cin>>n;
    int arr[n];
    for(int i=0;i<n;i++)
        {
            cin>>arr[i];
            if(arr[i]>0)
                sum+=arr[i];
        }
        if(sum%2!=0)
            cout<<sum;
        else
        {
            sort(arr,arr+n);
            x=0;
            for( j=0;j<n;j++)
                if(arr[j]>=0)
                  break;
              l=j-1;r=j;
             while(arr[l]%2==0)
                    l--;
             while(arr[r]%2==0)
                  r++;
             if(arr[r]<abs(arr[l]))
                sum-=arr[r];
             else
                sum+=arr[l];

            cout<<sum;
        }

}


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

int main()
{
    long long int n,k,x,sum=0,j,l,r;
    cin>>n;
    int arr[n];
    for(int i=0;i<n;i++)
        {
            cin>>arr[i];
            if(arr[i]>0)
                sum+=arr[i];
        }
        if(sum%2!=0)
            cout<<sum;
        else
        {
            sort(arr,arr+n);
            x=0;
            for( j=0;j<n;j++)
                if(arr[j]>=0)
                  break;
              l=j-1;r=j;
             while(arr[l]%2==0)
                 l--;
             while(arr[r]%2==0)
                  r++;
             if(r<n&&l>=0)
             {
            if(arr[r]<abs(arr[l]))
                sum-=arr[r];
             else
                sum+=arr[l];
             }
             else if(r>=n&&l>=0)
             sum+=arr[l];
             else if(r<n&&l<0)
             sum-=arr[r];

            cout<<sum;
        }

}


#include <bits/stdc++.h>
using namespace std;
int dmniu(int t[100005],int n);
int mniu(int t[100005],int n);
int main()
{int n,t[100005],vpz=0,mx=-1e9;
scanf("%d",&n);for (int i=0;i<n;i++)scanf("%d",&t[i]);
sort(t,t+n);

for (int i=n-1;i>=0;i--){
if (t[i]<0)break;
vpz+=t[i];
if (vpz%2!=0)
    {
    mx=max(mx,vpz);
    }
}
printf("%d",max(mx,vpz+(max(dmniu(t,n),mniu(t,n)))));

    return 0;
}
int dmniu(int t[100005],int n){
int vv=-1e9,hh=-1e9;
for (int i=n-1;i>=0;i--){
    if (t[i]<0 && (t[i]%2)==0){
        vv=t[i];break;
    }
}
for (int i=n-1;i>=0;i--){
    if (t[i]<0 && (t[i]%2)!=0){
        return vv+t[i];
    }
}
}
int mniu(int t[100005],int n){
for (int i=n-1;i>=0;i--){
    if (t[i]<0 && (t[i]%2)!=0)
        return t[i];
}
}


#include <bits/stdc++.h>
using namespace std;
int dmniu(int t[100005],int n);
int mniu(int t[100005],int n);
int main()
{int n,t[100005],vpz=0,mx=0;
scanf("%d",&n);for (int i=0;i<n;i++)scanf("%d",&t[i]);
sort(t,t+n);

for (int i=n-1;i>=0;i--){
if (t[i]<0)break;
vpz+=t[i];
if (vpz%2!=0)mx=vpz;
}
if (vpz%2==0 &&(max(dmniu(t,n),mniu(t,n))!=0)){
printf("%d",max(mx,vpz+(max(dmniu(t,n),mniu(t,n)))));
}else{
printf("%d",mx);}

    return 0;
}
int dmniu(int t[100005],int n){
int vv=0;
for (int i=n-1;i>=0;i--){
    if (t[i]<0){
    vv+=t[i];
    if (vv%2!=0)return vv;
    }
}
return 0;
}
int mniu(int t[100005],int n){
for (int i=n-1;i>=0;i--){
    if (t[i]<0 && (t[i]%2)!=0)
        return t[i];
}
return 0;
}


#include <bits/stdc++.h>
using namespace std;
int mnn(int t[100005],int n);
int main(void)
{int n,t[100005],vpz=0,mx=-1e9;
scanf("%d",&n);for (int i=0;i<n;i++)scanf("%d",&t[i]);
sort(t,t+n);
for (int i=n-1;i>=0;i--){
        if (t[i]<0)break;
vpz+=t[i];
if (vpz%2!=0){
    mx=max(mx,vpz);
}
}
if (vpz%2==0){
    printf("%d",vpz+mnn(t,n));
}else{
printf("%d",mx);
}
    return 0;
}
int mnn(int t[100005],int n){
int vp=0,vt=0;
for (int i=n-1;i>=0;i--){
    if (t[i]<0 && t[i]%2!=0)
        vp=t[i];
        vt+=t[i];
        if (vt%2!=0 && vp%2!=0)break;
}
return min(vp,vt);
}


#include <bits/stdc++.h>
using namespace std;
int dmniu(int t[100005],int n);
int mniu(int t[100005],int n);
int main()
{int n,t[100005],vpz=0,mx=-1e9;
scanf("%d",&n);for (int i=0;i<n;i++)scanf("%d",&t[i]);
sort(t,t+n);

for (int i=n-1;i>=0;i--){
if (t[i]<0)break;
vpz+=t[i];
if (vpz%2!=0)mx=vpz;
}
if (vpz%2==0 &&(max(dmniu(t,n),mniu(t,n)))!=0){
printf("%d",max(mx,vpz+(max(dmniu(t,n),mniu(t,n)))));
}else{
printf("%d",mx);}

    return 0;
}
int dmniu(int t[100005],int n){
int vv=0;
for (int i=n-1;i>=0;i--){
    if (t[i]<0){
    vv+=t[i];
    if (vv%2!=0)return vv;
    }
}
return 0;
}
int mniu(int t[100005],int n){
for (int i=n-1;i>=0;i--){
    if (t[i]<0 && (t[i]%2)!=0)
        return t[i];
}
return 0;
}


#include <bits/stdc++.h>
using namespace std;
int dmniu(int t[100005],int n);
int mniu(int t[100005],int n);
int main()
{int n,t[100005],vpz=0,mx=-1e9;
scanf("%d",&n);for (int i=0;i<n;i++)scanf("%d",&t[i]);
sort(t,t+n);

for (int i=n-1;i>0;i--){
if (t[i]<0)break;
vpz+=t[i];
if (vpz%2!=0)
    {
    mx=max(mx,vpz);
    }
}
printf("%d",max(mx,vpz+(max(dmniu(t,n),mniu(t,n)))));
printf("%d",max(dmniu(t,n),mniu(t,n)));

    return 0;
}
int dmniu(int t[100005],int n){
int vv=0,hh=0;
for (int i=n-1;i>0;i--){
    if (t[i]<0 && (t[i]%2)==0){
        vv=t[i];break;
    }
}
for (int i=n-1;i>0;i--){
    if (t[i]<0 && (t[i]%2)!=0){
        return vv+t[i];
    }
}
}
int mniu(int t[100005],int n){
for (int i=n-1;i>=0;i--){
    if (t[i]<0 && (t[i]%2)!=0)
        return t[i];
}
}


#include <bits/stdc++.h>
using namespace std;
int dmniu(int t[100005],int n);
int mniu(int t[100005],int n);
int main()
{int n,k,vpz=0,mx=-1e9;
scanf("%d",&n);for (int i=0;i<n;i++){
    scanf("%d",&k);
    if (k>0)vpz+=k;
    if (k%2!=0 && k<0)mx=max(mx,k);
}
if (vpz%2==0){
    printf("%d",vpz+mx);
}else{
printf("%d",vpz);}
return 0;}


#include <bits/stdc++.h>
using namespace std;
int main(void)
{int n,t[100005],vpz=0,mx=-100000;
scanf("%d",&n);for (int i=0;i<n;i++)scanf("%d",&t[i]);
sort(t,t+n);
for (int i=n-1;i>=0;i--){
if (t[i]<0)break;
vpz+=t[i];
if (vpz%2!=0){
mx=max(mx,vpz);
}
}
if (vpz%2==0){
    for (int i=n-1;i>=0;i--){
        if ((vpz+t[i])%2!=0){
            mx=max(mx,vpz+t[i]);break;
        }
    }
}
printf("%d",mx);
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
long long s,n,mi=1e9,gt;
int main()
{
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        cin>>gt;
        if(gt>0) s+=gt;
        if(abs(gt)%2==1) mi=min(mi,abs(gt));
    }
    if(s%2!=0) mi=0;
    cout<<s-mi;
}
return 0;}


#include <bits/stdc++.h>
using namespace std;
int dmniu(int t[100005],int n);
int mniu(int t[100005],int n);
int main()
{int n,k,vpz=0,mx=-1e9;
scanf("%d",&n);for (int i=0;i<n;i++){
    scanf("%d",&k);
    if (k>0)vpz+=k;
    if (k%2!=0)mx=max(mx,k);
}
if (vpz%2==0){
    printf("%d",vpz+mx);
}else{
printf("%d",vpz);}
return 0;}


#include <bits/stdc++.h>
using namespace std;
int dmniu(int t[100005],int n);
int mniu(int t[100005],int n);
int main()
{int n,t[100005],vpz=0,mx=0;
scanf("%d",&n);for (int i=0;i<n;i++)scanf("%d",&t[i]);
sort(t,t+n);

for (int i=n-1;i>=0;i--){
if (t[i]<0)break;
vpz+=t[i];
if (vpz%2!=0)
    {
    mx=max(mx,vpz);
    }
}
if (mx==0){
printf("%d",vpz+(max(dmniu(t,n),mniu(t,n))));
}else{
printf("%d",mx);}

    return 0;
}
int dmniu(int t[100005],int n){
int vv=0,hh=0;
for (int i=n-1;i>=0;i--){
    if (t[i]<0 && (t[i]%2)==0){
        vv=t[i];break;
    }
}
for (int i=n-1;i>=0;i--){
    if (t[i]<0 && (t[i]%2)!=0){
        return vv+t[i];
    }
}
return 0;
}
int mniu(int t[100005],int n){
for (int i=n-1;i>=0;i--){
    if (t[i]<0 && (t[i]%2)!=0)
        return t[i];
}
return 0;
}


#include <bits/stdc++.h>
using namespace std;
int main(void)
{int n,t[100005],vpz=0,mx=-100000;
scanf("%d",&n);for (int i=0;i<n;i++)scanf("%d",&t[i]);
sort(t,t+n);
for (int i=n-1;i>=0;i--){
vpz+=t[i];
if (vpz%2!=0){
    mx=max(mx,vpz);
}
}
printf("%d",mx);
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
int dmniu(int t[100005],int n);
int mniu(int t[100005],int n);
int main()
{int n,t[100005],vpz=0,mx=-1e9;
scanf("%d",&n);for (int i=0;i<n;i++)scanf("%d",&t[i]);
sort(t,t+n);

for (int i=n-1;i>0;i--){
if (t[i]<0)break;
vpz+=t[i];
if (vpz%2!=0)
    {
    mx=max(mx,vpz);
    }
}
printf("%d",max(mx,vpz+(max(dmniu(t,n),mniu(t,n)))));

    return 0;
}
int dmniu(int t[100005],int n){
int vv=0,hh=0;
for (int i=n-1;i>=0;i--){
    if (t[i]<0 && (t[i]%2)==0){
        vv=t[i];break;
    }
}
for (int i=n-1;i>=0;i--){
    if (t[i]<0 && (t[i]%2)!=0){
        return vv+t[i];
    }
}
}
int mniu(int t[100005],int n){
for (int i=n-1;i>=0;i--){
    if (t[i]<0 && (t[i]%2)!=0)
        return t[i];
}
}


#include <bits/stdc++.h>
using namespace std;
int dmniu(int t[100005],int n);
int mniu(int t[100005],int n);
int main()
{int n,t[100005],vpz=0,mx=-1e9;
scanf("%d",&n);for (int i=0;i<n;i++)scanf("%d",&t[i]);
sort(t,t+n);

for (int i=n-1;i>=0;i--){
if (t[i]<0)break;
vpz+=t[i];
if (vpz%2!=0)mx=vpz;
}
if (vpz%2==0 &&(max(dmniu(t,n),mniu(t,n))!=0)){
printf("%d",max(mx,vpz+(max(dmniu(t,n),mniu(t,n)))));
}else{
printf("%d",mx);}

    return 0;
}
int dmniu(int t[100005],int n){
int vv=0,hh=0;
for (int i=n-1;i>=0;i--){
    if (t[i]<0 && (t[i]%2)==0){
        vv=t[i];break;
    }
}
for (int i=n-1;i>=0;i--){
    if (t[i]<0 && (t[i]%2)!=0){
        return vv+t[i];
    }
}
return 0;
}
int mniu(int t[100005],int n){
for (int i=n-1;i>=0;i--){
    if (t[i]<0 && (t[i]%2)!=0)
        return t[i];
}
return 0;
}


#include <bits/stdc++.h>
using namespace std;
int main(void)
{int n,t[100005],vpz=0,mx=-1e9;
scanf("%d",&n);for (int i=0;i<n;i++)scanf("%d",&t[i]);
sort(t,t+n);
for (int i=n-1;i>=0;i--){
        if (t[i]<0)break;
vpz+=t[i];
if (vpz%2!=0){
    mx=max(mx,vpz);
}
}
for (int i=n-1;i>=0;i--){
    if (t[i]<0){
        if ((t[i]+vpz)%2!=0){
            mx=max(mx,vpz+t[i]);break;
        }
    }
}
printf("%d",mx);
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
long long s,n,mi=1e9,gt;
int main()
{
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        cin>>gt;
        if(gt>0) s+=gt;
        if(abs(gt)%2==1) mi=min(mi,abs(gt));
    }
    if(s%2!=0) mi=0;
    cout<<s-mi;
return 0;}


#include <bits/stdc++.h>
using namespace std;
int dmniu(int t[100005],int n);
int mniu(int t[100005],int n);
int main()
{int n,t[100005],vpz=0,mx=-1e9;
scanf("%d",&n);for (int i=0;i<n;i++)scanf("%d",&t[i]);
sort(t,t+n);

for (int i=n-1;i>=0;i--){
if (t[i]<0)break;
vpz+=t[i];
if (vpz%2!=0)mx=vpz;
}
if (vpz%2==0){
printf("%d",max(mx,vpz+(max(dmniu(t,n),mniu(t,n)))));
}else{
printf("%d",vpz);}

    return 0;
}
int dmniu(int t[100005],int n){
int vv=0,hh=0;
for (int i=n-1;i>=0;i--){
    if (t[i]<0 && (t[i]%2)==0){
        vv=t[i];break;
    }
}
for (int i=n-1;i>=0;i--){
    if (t[i]<0 && (t[i]%2)!=0){
        return vv+t[i];
    }
}
return 0;
}
int mniu(int t[100005],int n){
for (int i=n-1;i>=0;i--){
    if (t[i]<0 && (t[i]%2)!=0)
        return t[i];
}
return 0;
}


t = int(input())
for _ in range(t):
    n, k = map(int, input().split())
    s = sorted(input())
    min_s = s[0]
    n_min = 0
    for i in s:
        if i == min_s:
            n_min += 1
        else:
            break
    unique = len(set(s))

    if n_min < k:
        print(s[k-1])
    elif unique == 1:
         print(''.join(s[0]*(n//k+1)))
    elif unique == 2 and n%k == 0:
        print(''.join(s[k-1::k]))
    else:
        print(''.join(s[k-1:]))


t = int(input())
for _ in range(t):
    n, k = map(int, input().split())
    s = sorted(input())
    min_s = s[0]
    n_min = 0
    for i in s:
        if i == min_s:
            n_min += 1
        else:
            break

    if n_min < k:
        print(s[k-1])
    elif n%k == 0:
        print(''.join(s[k-1::k]))
    else:
        print(''.join([s[0]]+s[k:]))


from math import ceil
t = int(input())
for _ in range(t):
    n, k = map(int, input().split())
    s = sorted(input())
    min_s = s[0]
    n_min = 0
    for i in s:
        if i == min_s:
            n_min += 1
        else:
            break
    unique = len(set(s))

    if n_min < k:
        print(s[k-1])
    elif unique == 1:
         print(''.join(s[0]*ceil(n//k)))
    elif unique == 2 and n_min == k and n%k == 0:
        print(''.join(s[k-1::k]))
    else:
        print(''.join(s[k-1:]))


import math

t = int(input())
for a in range(t):
    n,k = map(int,input().split())
    string = sorted(input())
    strings = ["" for i in range(k)]
    firstSame = True
    for b in range(k):
        if string[b] != string[0]:
            firstSame = False
        strings[b] += string[b]
    if(n > k):
        value = string[k]
        same = True
        for b in range(k,n):
            if string[b] != value:
                same = False
        if same and firstSame:
            for b in range(k,n):
                strings[b%k] += string[b]
        else:
            for b in range(k,n):
                strings[0] += string[b]
    print(max(strings))


import math

t = int(input())
for a in range(t):
    n,k = map(int,input().split())
    string = sorted(input())
    strings = ["" for i in range(k)]
    current = 0
    even = True
    for b in range(k):
        strings[b] += string[b]
    value = string[k]
    same = True
    for b in range(k,n):
        if string[b] != value:
            same = False
    if same:
        for b in range(k,n):
            strings[b%k] += string[b]
        print(max(strings))
    else:
        for b in range(k,n):
            strings[0] += string[b]
        print(max(strings))


import math

t = int(input())
for a in range(t):
    n,k = map(int,input().split())
    string = sorted(input())
    strings = ["" for i in range(k)]
    for b in range(k):
        strings[b] += string[b]
    if(n > k):
        value = string[k]
        same = True
        for b in range(k,n):
            if string[b] != value:
                same = False
        if same:
            for b in range(k,n):
                strings[b%k] += string[b]
        else:
            for b in range(k,n):
                strings[0] += string[b]
    print(max(strings))


import random
import math
LI = lambda: list(map(int,input().split()))
MI = lambda: map(int,input().split())
yes = lambda: print("Yes")
no = lambda: print("No")
I = lambda: list(input())
J = lambda x: "".join(x)
II = lambda: int(input())
SI = lambda: input()
#---khan17---template
t = II()
for q in range(t):
	n,k = MI()
	s = sorted(list(SI()))
	l = [0]*26
	boo = True
	for i in s:
		l[ord(i)-97]+=1
	for i in l:
		if i%k!=0:
			boo = False
	if k == 1:
		print("".join(s))
	elif len(set(s)) == 1:
		print((n//k+1)*s[0] if n%k!=0 else (n//k)*s[0])
	else:
		count = 0
		for i in s:
			if i == s[0]:
				count+=1
		if count>=k:
			ans = [s[0]]+s[k:]
			if ans[1] == ans[-1] and len(ans)!=2:
				ttt = l[ord(ans[1])-97]
				if ttt%k != 0:
					ttt = ttt//k+1
				else:
					ttt = ttt//k
				ans = ans[0]+(ttt*ans[1])
			print("".join(ans))
		else:
			print(s[k-1])


import random
import math
LI = lambda: list(map(int,input().split()))
MI = lambda: map(int,input().split())
yes = lambda: print("Yes")
no = lambda: print("No")
I = lambda: list(input())
J = lambda x: "".join(x)
II = lambda: int(input())
SI = lambda: input()
#---khan17---template
t = II()
for q in range(t):
	n,k = MI()
	s = sorted(list(SI()))
	l = [0]*26
	boo = True
	for i in s:
		l[ord(i)-97]+=1
	for i in l:
		if i%k!=0:
			boo = False
	if k == 1:
		print("".join(s))
	elif len(set(s)) == 1:
		print((n//k+1)*s[0])
	elif boo:
		print("".join(sorted(list(set(s)))))
	else:
		count = 0
		for i in s:
			if i == s[0]:
				count+=1
		if count>=k:
			print("".join([s[0]]+s[k:]))
		else:
			print(s[k-1])


import random
import math
LI = lambda: list(map(int,input().split()))
MI = lambda: map(int,input().split())
yes = lambda: print("Yes")
no = lambda: print("No")
I = lambda: list(input())
J = lambda x: "".join(x)
II = lambda: int(input())
SI = lambda: input()
#---khan17---template
t = II()
for q in range(t):
	n,k = MI()
	s = sorted(list(SI()))
	l = [0]*26
	boo = True
	for i in s:
		l[ord(i)-97]+=1
	for i in l:
		if i%k!=0:
			boo = False
	if k == 1:
		print("".join(s))
	elif len(set(s)) == 1:
		print((n//k+1)*s[0])
	elif boo:
		print("".join(sorted(list(set(s)))))
	else:
		count = 0
		for i in s:
			if i == 'a':
				count+=1
		if count>=k:
			print("".join(["a"]+s[k:]))
		else:
			print(s[k-1])


for _ in range(int(input())):
    n,k=map(int,input().split())
    s=input()
    lis=list(s)
    lis.sort()
    s="".join(lis)
    sub=s[:k]
    if k==1:
        print(s)
    elif len(s)==k:
        print(sub[-1])
    else:
        if sub[0]==sub[-1]:
            s=s[k:]
            if s[0]==s[-1]:
                if len(s)%k==0:
                    print(sub[0]+s[0]*(len(s)//k))
                else:
                    print(sub[0]+s[0]*(len(s)//k+1))
            else:
                print(sub[0]+s)
        else:
            print(sub[-1])


for _ in range(int(input())):
    n,k=map(int,input().split())
    s=input()
    lis=list(s)
    lis.sort()
    s="".join(lis)
    sub=s[:k]
    if k==1:
        print(s)
    else:
        if sub[0]==sub[-1]:
            s=s[k:]
            if s[0]==s[-1]:
                if len(s)%k==0:
                    print(sub[0]+s[0]*(len(s)//k))
                else:
                    print(sub[0]+s[0]*(len(s)//k+1))
            else:
                print(sub[0]+s)
        else:
            print(sub[-1])


from collections import deque
def solve():
    n,k=[int(x) for x in input().split()]
    string=input()
    li=deque()
    for ele in string:
        li.append(ele)
    li=list(li)
    li.sort()
    s=''
    for ele in li:
        s+=ele
    if s[0]!=s[k-1]:
        print(s[k-1])
        return
    else:
        if s[k]!=s[n-1]:
            print(s[0]+s[k::])
            return
        else:
            rest=n-k
            if rest%k==0:
                add1=rest//k
                print(s[0]+s[k]*add1)
            else:
                add=rest//k+1
                print(s[0]+s[k]*add)
    return

t=int(input())
for i in range(t):
    solve()


from collections import deque
def solve():
    n,k=[int(x) for x in input().split()]
    string=input()
    li=deque()
    for ele in string:
        li.append(ele)
    li=list(li)
    li.sort()
    s=''
    for ele in li:
        s+=ele
    if n==k:
        print(s[n-1])
        return
    if s[0]!=s[k-1]:
        print(s[k-1])
        return
    else:
        if s[k-1]!=s[n-1]:
            print(s[0]+s[k::])
            return
        else:
            rest=n-k
            if rest%k==0:
                add=rest//k
                print(s[0]+s[k]*add)
            else:
                add=rest//k+1
                print(s[0]+s[k]*add)
    return

t=int(input())
for i in range(t):
    solve()


from collections import deque
def solve():
    n,k=[int(x) for x in input().split()]
    string=input()
    li=deque()
    for ele in string:
        li.append(ele)
    li=list(li)
    li.sort()
    s=''
    for ele in li:
        s+=ele
    if s[0]!=s[k-1]:
        print(s[k-1])
        return
    else:
        if s[k]!=s[n-1]:
            print(s[0]+s[k::])
            return
        else:
            rest=n-k
            if rest%k==0:
                add=rest//k
                print(s[0]+s[k]*add)
            else:
                add=rest//k+1
                print(s[0]+s[k]*add)
    return

t=int(input())
for i in range(t):
    solve()


from collections import deque
def solve():
    n,k=[int(x) for x in input().split()]
    string=input()
    li=deque()
    for ele in string:
        li.append(ele)
    li=list(li)
    li.sort()
    s=''
    for ele in li:
        s+=ele
    if n==k:
        print(s[n-1])
        return
    if s[0]!=s[k-1]:
        print(s[k-1])
        return
    else:
        if s[k]!=s[n-1]:
            print(s[0]+s[k::])
            return
        else:
            rest=n-k
            if rest%k==0:
                add=rest//k
                print(s[0]+s[k]*add)
            else:
                add=rest//k+1
                print(s[0]+s[k]*add)
    return

t=int(input())
for i in range(t):
    solve()


from collections import deque
def solve():
    n,k=[int(x) for x in input().split()]
    string=input()
    li=deque()
    for ele in string:
        li.append(ele)
    li=list(li)
    li.sort()
    s=''
    for ele in li:
        s+=ele
    if s[0]!=s[k-1]:
        print(s[k-1])
        return
    else:
        if s[k]!=s[n-1]:
            print(s[0]+s[k::])
            return
        else:
            rest=n-k
            if rest%k==0:
                add1=rest//k
                print(s[0]+s[k]*add1)
            else:
                add2=rest//k+1
                print(s[0]+s[k]*add2)
    return

t=int(input())
for i in range(t):
    solve()


from sys import stdin,stdout
from itertools import combinations
from collections import defaultdict,Counter
import math

def listIn():
    return list((map(int,stdin.readline().strip().split())))

def stringListIn():
    return([x for x in stdin.readline().split()])

def intIn():
    return (int(stdin.readline()))

def stringIn():
    return (stdin.readline().strip())

if __name__=="__main__":
    t=int(input())
    while(t>0):
        t-=1
        n,k=listIn()
        s=input()
        st=sorted(s)
        di=Counter(s)

        if st[k-1]!=st[0]:
            print(st[k-1])
        else:
            left="".join(st[k:])
            if len(set(left))==1:
                diff=n-k
                if diff%2==0:
                    print(st[0]+left[0:diff//k])
                else:
                    print(st[0]+left[:(diff//k)+1])
            else:
                print(st[0]+left)


from sys import stdin,stdout
from itertools import combinations
from collections import defaultdict,Counter
import math

def listIn():
    return list((map(int,stdin.readline().strip().split())))

def stringListIn():
    return([x for x in stdin.readline().split()])

def intIn():
    return (int(stdin.readline()))

def stringIn():
    return (stdin.readline().strip())

if __name__=="__main__":
    t=int(input())
    while(t>0):
        t-=1
        n,k=listIn()
        s=input()
        st=sorted(s)
        di=Counter(s)

        if st[k-1]!=st[0]:
            print(st[k-1])
        else:
            left="".join(st[k:])
            if len(set(left))==1:
                print(st[0]+left[0:((n-k)//k)+1])
            else:
                print(st[0]+left)


from sys import stdin,stdout
from itertools import combinations
from collections import defaultdict,Counter
import math

def listIn():
    return list((map(int,stdin.readline().strip().split())))

def stringListIn():
    return([x for x in stdin.readline().split()])

def intIn():
    return (int(stdin.readline()))

def stringIn():
    return (stdin.readline().strip())

if __name__=="__main__":
    t=int(input())
    while(t>0):
        t-=1
        n,k=listIn()
        s=input()
        st=sorted(s)
        di=Counter(s)

        if st[k-1]!=st[0]:
            print(st[k-1])
        else:
            left="".join(st[k:])
            if len(set(left))==1:
                print(st[0]+left[0])
            else:
                print(st[0]+left)


from sys import stdin,stdout
from itertools import combinations
from collections import defaultdict,Counter
import math

def listIn():
    return list((map(int,stdin.readline().strip().split())))

def stringListIn():
    return([x for x in stdin.readline().split()])

def intIn():
    return (int(stdin.readline()))

def stringIn():
    return (stdin.readline().strip())

if __name__=="__main__":
    t=int(input())
    while(t>0):
        t-=1
        n,k=listIn()
        s=input()
        st=sorted(s)
        di=Counter(s)

        if st[k-1]!=st[0]:
            print(st[k-1])
        else:
            left="".join(st[k:])
            if len(set(left))==1:
                print(st[0]+left[0:math.ceil((n-k)/k)])
            else:
                print(st[0]+left)


t = int(input())

for ds in range(t):
    n, k = [int(x) for x in input().split()]

    a = input()

    a = list(a)

    a.sort()

    res1 = [''] * k
    res2 = [''] * k

    for i in range(k):
        res1[i] += a[i]

    for i in range(k, n):
        res1[0] += a[i]

    for i in range(n):
        res2[i % k] += a[i]

    print(min(max(res1), max(res2)))


t = int(input())

for ds in range(t):
    n, k = [int(x) for x in input().split()]

    a = input()

    a = list(a)

    a.sort()

    res = [''] * k

    for i in range(n):
        res[i % k] += a[i]

    print(max(res))


t = int(input())

while t>0:
	t-=1
	n,k = list(map(int,input().split(" ")))
	s = sorted(input())
	res = s[k-1]
	n = len(s)
	if s[0]!=s[k-1]:
		pass

	elif s[k] == s[n-1]:
		for i in range(k,n,k):
			res+=s[i]
	else:
		for i in range(k,n):
			res+=s[i]

	print(res)


t = int(input())
ans = ""
while t>0:
	t-=1
	n,k = list(map(int,input().split(" ")))
	s = sorted(input())
	res = s[k-1]
	n = len(s)
	if s[0]!=s[k-1]:
		pass

	elif s[k] == s[n-1]:
		for i in range(k,n,k):
			res+=s[i]
	else:
		for i in range(k,n):
			res+=s[i]

	ans+=res
	ans+="\n"
print(ans)


t = int(input())

while t > 0:
	t-=1
	x= list(map(int,(input().split(" "))))
	n = x[0]
	k = x[1]

	s = sorted(str(input()))
	#print(s)
	strings = ["" for i in range(k)]
	last = ""
	for idx,char in enumerate(s):
		strings[idx%k]+=char
	strings = sorted(strings)
	#print(strings)
	mx = strings[-1][-1]
	for i in range(k-1):
		n = len(strings[i])
		if n==1:
			continue
		for j in range(n-1,0,-1):
			if strings[i][j] < mx:
				last+=strings[i][j]
			else:
				break
	strings[-1]+=last
	final = sorted(strings[-1])
	ans = ""
	for each in final:
		ans+=each
	print(ans)


t = int(input())

while t > 0:
	t-=1
	x= list(map(int,(input().split(" "))))
	n = x[0]
	k = x[1]

	s = sorted(str(input()))

	strings = ["" for i in range(k)]
	last = ""
	for idx,char in enumerate(s):
		strings[idx%k]+=char
	strings = sorted(strings)
	mx = strings[-1][-1]
	for i in range(k-1):
		n = len(strings[i])
		if n==1:
			continue
		for j in range(n-1,0,-1):
			if strings[i][j] < mx:
				last+=strings[i][j]
			else:
				break
	strings[-1]+=last
	final = sorted(strings[-1])
	ans = ""
	for each in final:
		ans+=each
	print(ans)


t = int(input())
ans = ""
while t>0:
	t-=1
	n,k = list(map(int,input().split(" ")))
	s = sorted(input())
	res = s[k-1]
	n = len(s)
	if s[0]!=s[k-1]:
		pass

	elif k<= n-1 and s[k] == s[n-1]:
		for i in range(k,n,k):
			res+=s[i]
	else:
		for i in range(k,n):
			res+=s[i]

	ans+=res
	ans+="\n"
print(ans)


t = int(input())
for i in range(t):
    n, k = map(int, input().split())
    s = list(input())
    s.sort()
    ans = []
    if s[0] == s[k - 1] and s[k] == s[n - 1]:
        ans_s = s[0] + s[k] * ((n - k) // k)
        if n % k == 0:
            print(ans_s)
        else:
            print(ans_s + s[k])
    else:
        if s[0] == s[k - 1]:
            print(s[0] + "".join(list(map(str, s[k:]))))
        else:
            print(s[k - 1])


t = int(input())
for i in range(t):
    n, k = map(int, input().split())
    s = list(input())
    s.sort()
    ans = []
    if k == n:
        print(s[k - 1])
    elif s[0] == s[k - 1] and s[k] == s[n - 1]:
        ans_s = s[0] + s[k] * ((n - k) // k)
        if n % k == 0:
            print(ans_s)
        else:
            print(ans_s + s[k])
    else:
        if s[0] == s[k - 1]:
            print(s[0] + "".join(list(map(str, s[k:]))))
        else:
            print(s[k - 1])


import math

def task(n, k, s):
    s = [char for char in s]
    s.sort()

    mn = min(s[0:k])
    mx = max(s[0:k])

    if mn != mx or k == n:
        print(mx)
        return

    a = [mn]

    mn = min(s[k:])
    mx = max(s[k:])

    if mn != mx:
        a += s[k:]
        print("".join(map(str, a)))
        return

    repeats = math.ceil((n - k) / k)
    a += repeats * mx
    print("".join(map(str, a)))

    #print(n, k, s, mn, mx)

t = int(input())
for i in range(0, t):
    n, k = map(int, input().split())
    s = input()
    task(n, k, s)


import math

def task(n, k, s):
    s = [char for char in s]
    s.sort()

    mn = min(s[0:k])
    mx = max(s[0:k])

    if mn != mx:
        print(mx)
        return

    a = [mn]

    mn = min(s[k:])
    mx = max(s[k:])

    if mn != mx:
        a += s[k:]
        print("".join(map(str, a)))
        return

    repeats = math.ceil((n - k) / k)
    a += repeats * mx
    print("".join(map(str, a)))

    #print(n, k, s, mn, mx)

t = int(input())
for i in range(0, t):
    n, k = map(int, input().split())
    s = input()
    task(n, k, s)


t = int(input())

for i in range(t):
    n, k = map(int, input().split())
    s = input()

    s = sorted(s)
    if s[0] != s[k - 1]:
        print(s[k - 1])
        continue

    if s[k] == s[-1]:
        l = (len(s) - 1) // k
        print(s[0] + s[k] * l)
        continue

    print(s[0] + ''.join(s[k:]))


t = int(input())

for i in range(t):
    n, k = map(int, input().split())
    s = input()

    s = sorted(s)

    if n == k:
        print(s[-1])
        continue

    if s[0] != s[k - 1]:
        print(s[k - 1])
        continue

    if s[k] == s[-1]:
        l = (len(s) - 1) // k
        print(s[0] + s[k] * l)
        continue

    print(s[0] + ''.join(s[k:]))


for i in range(int(input())):
    n,k=map(int,input().split())
    a=input()
    a=list(a)
    a.sort()
    if a[0]!=a[k-1] or n==k:
        print(a[k-1])
    elif a[0]==a[k-1]:
        s=a[0]
        if a[k]!=a[n-1]:
            for j in range(k,n):
                s+=a[j]
        else:
            for j in range(0,(n-k+k-1)//k):
                s+=a[n-1]
        print(s)


for i in range(int(input())):
    n,k=map(int,input().split())
    a=input()
    a=list(a)
    a.sort()
    if a[0]!=a[k-1]:
        print(a[k-1])
    elif a[0]==a[k-1]:
        s=a[0]
        if a[k]!=a[n-1]:
            for j in range(k,n):
                s+=a[j]
            print(s)
            continue
        for j in range(0,(n-k+k-1)//k):
            s+=a[n-1]
        print(s)


for i in range(int(input())):
    n,k=map(int,input().split())
    a=input()
    a=list(a)
    a.sort()
    if a[0]!=a[k-1]:
        print(a[k-1])
    elif a[0]==a[k-1]:
        s=a[0]
        if a[k]!=a[n-1]:
            for j in range(k,n):
                s+=a[j]
            print(s)
        else:
            for j in range(0,(n-k+k-1)//k):
                s+=a[n-1]
            print(s)


from collections import Counter as c
for _ in range(int(input())):
	a,b = map(int,input().split())
	st = input()
	s = c(st)
	t = sorted(s.keys())
	ans =""
	if s[t[0]]<b:
		print(sorted(st)[b-1])
	elif b==1:
		print("".join(sorted(st)))
	elif s[t[0]]==a:
		from math import ceil
		print(t[0]*ceil(a/b))
	else:
		s[t[0]]-=b
		ans+=t[0]
		# print(s)
		if s[t[0]]:
			for i in t:
				ans+="i"*s[i]
		else:
			if len(t)==2:
				from math import ceil
				ans+=t[1]*ceil(s[t[1]]/b)
			else:
				for i in t:
					ans+=i*s[i]
			print(ans)


from collections import Counter as c
for _ in range(int(input())):
	a,b = map(int,input().split())
	st = input()
	s = c(st)
	t = sorted(s.keys())
	ans =""
	if s[t[0]]<b:
		print(sorted(st)[b-1])
	elif b==1:
		print("".join(sorted(st)))
	elif s[t[0]]==a:
		from math import ceil
		print(t[0]*ceil(a/b))
	else:
		s[t[0]]-=b
		ans+=t[0]
		# print(s)
		if s[t[0]]:
			for i in t:
				ans+=i*s[i]
		else:
			if len(t)==2:
				from math import ceil
				ans+=t[1]*ceil(s[t[1]]/b)
			else:
				for i in t:
					ans+=i*s[i]
		print(ans)


import math

for _ in range(int(input())):
    n,k = map(int,input().split())
    s = list(input())
    s.sort()
    l = ['']*k
    flag = True
    for i in range(n):
        if i < k:
            l[i]+=s[i]
        else:
            if l[0] < l[-1]:
                print(l[-1])
                flag = False
                break
            else:
                if s[i] == s[-1]:
                    min_val = min(l)
                    min_val_count = l.count(min_val)
                    l[0]+=s[i]*(math.ceil((n-i)/min_val_count))
                    flag = False
                    print(l[0])
                    break
                else:
                    for j in range(i,n):
                        l[0]+=s[j]
                    print(l[0])
                    flag = False
                    break
    if flag:
        print(max(l))


import math

for _ in range(int(input())):
    n,k = map(int,input().split())
    s = list(input())
    s.sort()
    l = ['']*k
    for i in range(n):
        if i < k:
            l[i]+=s[i]
        else:
            if l[0] < l[-1]:
                print(l[-1])
                break
            else:
                if s[i] == s[-1]:
                    min_val = min(l)
                    min_val_count = l.count(min_val)
                    l[0]+=s[i]*(math.ceil((n-i)/min_val_count))

                    print(l[0])
                    break
                else:
                    for j in range(i,n):
                        l[0]+=s[j]
                    print(l[0])
                    break


import math

for _ in range(int(input())):
    n,k = map(int,input().split())
    s = list(input())
    s.sort()
    l = ['']*k
    flag = True
    for i in range(n):
        if i < k:
            l[i]+=s[i]
        else:
            if l[0] < l[-1]:
                print(l[-1])
                flag = False
                break
            else:
                if s[i] == s[-1]:
                    min_val = min(l)
                    min_val_count = l.count(min_val)
                    l[0]+=s[i]*(math.ceil((n-i)/min_val_count))
                    flag = False
                    print(l[0])
                    break
                else:
                    for j in range(i,n):
                        l[0]+=s[j]
                    print(l[0])
                    flag = False
                    break
    if flag:
        print(l[0])


for _ in range(int(input())):
    n,k = map(int,input().split())
    s = list(input())
    s.sort()
    l = ['']*k
    # print(l)
    for i in range(n):
        if i < k:
            l[i%k] += s[i]
        elif l[0]+s[i] < l[-1] or (s[i] < s[-1] != ''):
            l[0]+=s[i]
        else:
            l[i%k]+=s[i]
        s[i] = ' '
       # print(l[0],l[0]+s[i],l[-1],i)

    print(max(l))


def min_max_lexicographic(string, k):
    s = sorted(list(string))
    n = len(s)
    if s[0] != s[k - 1] or k == n:
        return s[k - 1]

    if s[k] != s[n - 1]:
        return ''.join(s[(k - 1):])

    return ''.join([s[0]] + [s[k]] * ((n - k - 1) // k + 1))

if __name__ == '__main__':
    t = int(input())
    for _ in range(t):
        n, k = [int(k) for k in input().split()]
        s = input()
        print(min_max_lexicographic(s, k))


def min_max_lexicographic(string, k):
    s = sorted(list(string))
    if s[0] != s[k - 1]:
        return s[k - 1]

    n = len(s)
    if s[k] != s[n - 1]:
        return ''.join(s[(k - 1):])

    return ''.join([s[0]] + [s[k]] * ((n - k - 1) // k + 1))

if __name__ == '__main__':
    t = int(input())
    for _ in range(t):
        n, k = [int(k) for k in input().split()]
        s = input()
        print(min_max_lexicographic(s, k))


for _ in range(int(input())):
	n,k = map(int,input().split())
	s = input()
	l = []
	for i in s:
		l.append(i)
	l.sort()

	if l[k-1]!=l[0]:
		print(l[k-1])
	elif l[-1]!=l[k-1]:
		for i in range(k-1,n):
			print(l[i],end="")
		print()
	else:
		print(l[k-1]*(n//k+1))


for _ in range(int(input())):
	n,k = map(int,input().split())
	s = input()
	l = []
	for i in s:
		l.append(i)
	l.sort()

	if n==k:
		print(l[k-1])
	elif l[k-1]!=l[0]:
		print(l[k-1])
	elif l[-1]!=l[k]:
		for i in range(k-1,n):
			print(l[i],end="")
		print()
	else:
		if n%k==0:
			print(l[k-1],end="")
			print(l[k]*((n-k)//k))
		else:
			print(l[k-1],end="")
			print(l[k]*((n-k)//k+1))


from collections import defaultdict as dc
from heapq import *
import math
import bisect
import sys
from collections import deque as dq
from heapq import heapify,heappush,heappop
mod=10**9 +7
def inp():
    p=int(input())
    return p
def line():
    p=list(map(int,input().split()))
    return p
def read_mat():
    n=inp()
    a=[]
    for i in range(n):
        a.append(line())
    return a
def digit(n):
    s=str(n)
    p=0
    for i in s:
        p+=(int(i))**2
    return p

def solve(s,n,k):
    p=['' for i in range(k)]
    s=sorted(s)
    q=''.join(s)
    z=len(set(s))
    q=''.join(s)
    z=0
    for i in range(k):
        p[i]=s[z]
        z+=1
    ans=max(p)
    if z==n:
        return ans
    if s[0]!=s[z-1]:
        return ans
    l=min(p)
    ans=l+q[z:]
    while(z<n):
        for i in range(k):
            p[i]+=q[z]
            z+=1
            if z==n:
                break
    return min(ans,max(p))

for test in range(inp()):
    n,k=line()
    s=str(input())
    l=solve(s,n,k)
    print(l)


from collections import defaultdict as dc
from heapq import *
import math
import bisect
import sys
from collections import deque as dq
from heapq import heapify,heappush,heappop
mod=10**9 +7
def inp():
    p=int(input())
    return p
def line():
    p=list(map(int,input().split()))
    return p
def read_mat():
    n=inp()
    a=[]
    for i in range(n):
        a.append(line())
    return a
def digit(n):
    s=str(n)
    p=0
    for i in s:
        p+=(int(i))**2
    return p

def solve(s,n,k):
    p=['' for i in range(k)]
    s=sorted(s)
    q=''.join(s)
    z=0
    for i in range(k):
        p[i]=s[z]
        z+=1
    ans=max(p)
    if z==n:
        return ans
    if s[0]!=s[z-1]:
        return ans
    heapify(p)
    ans=-1
    while(z<n):
        l=heappop(p)
        if ans==-1:
            ans=l+q[z:]
        else:
            ans=min(ans,l+q[z:])
        heappush(p,l+q[z])
        z+=1
    return min(ans,max(p))
for test in range(inp()):
    n,k=line()
    s=str(input())
    l=solve(s,n,k)
    print(l)


from sys import stdin,stdout
T=int(stdin.readline().strip())
for caso in range(T):
    n,k=map(int,stdin.readline().strip().split())
    #s=list(set(list(map(int,stdin.readline().strip().split()))))
    s=list(stdin.readline().strip())

    s.sort()
    s1=""
    for i in s:
        s1+=i
    s=s1
    if k==1:
        print(s1)
        continue
    if  s[0]!=s[k-1] or k==len(s):
        print(s[k-1])
        continue

    if s[k]==s[-1]:
        x=(len(s)-k)
        y=x//k
        if x%k!=0:
            y+=1
        print(s[k-1]+s[k]*y)
        continue
    print(s1[k-1::])

#n,m=map(int,stdin.readline().strip().split())
#s=list(map(int,stdin.readline().strip().split()))


from sys import stdin,stdout
T=int(stdin.readline().strip())
for caso in range(T):
    n,k=map(int,stdin.readline().strip().split())
    #s=list(set(list(map(int,stdin.readline().strip().split()))))
    s=list(stdin.readline().strip())

    s.sort()
    s1=""
    for i in s:
        s1+=i
    s=s1
    if k==1:
        print(s1)
        continue
    if  s[0]!=s[k-1] or k==len(s):
        print(s[k-1])
        continue

    if s[k]==s[-1]:
        x=(len(s)-k)
        y=x//k
        if x%k!=0:
            y=+1
        print(s[k-1]+s[k]*y)
        continue
    print(s1[k-1::])

#n,m=map(int,stdin.readline().strip().split())
#s=list(map(int,stdin.readline().strip().split()))