#include<cstdio>
#include<algorithm>
using nmaespace std;
#define re register
#define M 1000000007
const int Mxdt=100000;
inline char gc(){
	static char buf[Mxdt],*p1=buf,*p2=buf;
	return p1==p2&&(p2=(p1=buf)+fread(buf,1,Mxdt,stdin),p1==p2)?EOF:*p1++;
}
inline int read(){
	int t=0;char v=gc();
	while(v<'0')v=gc();
	while(v>='0')t=(t<<3)+(t<<1)+v-'0',v=gc();
	return t;
}
int n,m;
long long a[200002],sum;
int main(){
	n=read(),m=read();
	for(re int i=1;i<=n;++i)a[i]=read();
	sort(a+1,a+n+1);
	for(re int i=m+1;i<=n;++i)a[i]+=a[i-m];
	for(re int i=1;i<=n;++i)printf("%lld ",sum+=a[i]);
}


#include<cstdio>
#define re register
#define M 1000000007
const int Mxdt=100000;
inline char gc(){
	static char buf[Mxdt],*p1=buf,*p2=buf;
	return p1==p2&&(p2=(p1=buf)+fread(buf,1,Mxdt,stdin),p1==p2)?EOF:*p1++;
}
inline int read(){
	int t=0;char v=gc();
	while(v<'0')v=gc();
	while(v>='0')t=(t<<3)+(t<<1)+v-'0',v=gc();
	return t;
}
int n,m;
long long a[200002],sum;
int main(){
	n=read(),m=read();
	for(re int i=1;i<=n;++i)a[i]=read();
	for(re int i=m+1;i<=n;++i)a[i]+=a[i-m];
	for(re int i=1;i<=n;++i)printf("%lld ",sum+=a[i]);
}


//R<3S
#include <bits/stdc++.h>
#define FAST std::ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define DECIMAL(n)  std::cout << std::fixed;std::cout << std::setprecision(n);
#define hell 1000000007
#define PI 3.14159265358979323844
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define ALL(v) v.begin(), v.end()
#define SORT(v) sort(ALL(v))
#define REVERSE(v) reverse(ALL(v))
#define endl "\n"
#define maxc(v) max_element(all(v))
#define minc(v) min_element(all(v))
#define GCD(m,n) __gcd(m,n)
#define LCM(m,n) m*(n/GCD(m,n))
#define inputarr(a,n) for(int i=0;i<n;++i) cin>>a[i]
#define initarr(a,n,x) for (int i=0;i<n;++i) a[i]=x
#define rep(i, n)    for(int i = 0; i < (n); ++i)
#define repA(i, a, n)  for(int i = a; i <= (n); ++i)
#define repD(i, a, n)  for(int i = a; i >= (n); --i)
#define trav(a, x) for(auto& a : x)
#define sz(a) (int)a.size()
#define sl(a) (int)a.length()
#define invect(data,n,commands) for(int i = 0;i<n;i++){int tmp;cin>>tmp;data.pb(tmp);commands}
#define inset(data,n,commands) for(int i = 0;i<n;i++){int tmp;cin>>tmp;data.insert(tmp);commands}
#define ll long long
#define ld long double
#define pii std::pair<int, int>
#define pll std::pair<ll, ll>
#define vi vector<int>
#define vvi vector<vi >
#define vii vector<pii >

using namespace std;

void solve()
  {

    int n,m;
    cin>>n>>m;
    int a[n+1];
    repA(i,1,n)cin>>a[i];
    sort(a+1,a+n);
    int dp[n+1],sum[n+1]={0};
    dp[0]=0;
    repA(i,1,n)
    {
      if(i<=m)sum[i]+=a[i];
      else
      {
        sum[i]=sum[i-m]+a[i];
      }
    }
    repA(i,1,n)
    {
      if(i<=m)dp[i]=a[i]+dp[i-1];
      else
      {
        dp[i]=dp[i-1]+sum[i];
      }
    }
    repA(i,1,n)cout<<dp[i]<<" ";
  }

int main()
{
   FAST
   #ifndef ONLINE_JUDGE
     freopen("input.txt","r",stdin);
     freopen("output.txt","w",stdout);
   #endif
   int t;
   t=1;
   //cin>>t;
   while(t--)
  {
      solve();
  }

   return 0;
}


//R<3S
#include <bits/stdc++.h>
#define FAST std::ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define DECIMAL(n)  std::cout << std::fixed;std::cout << std::setprecision(n);
#define hell 1000000007
#define PI 3.14159265358979323844
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define ALL(v) v.begin(), v.end()
#define SORT(v) sort(ALL(v))
#define REVERSE(v) reverse(ALL(v))
#define endl "\n"
#define maxc(v) max_element(all(v))
#define minc(v) min_element(all(v))
#define GCD(m,n) __gcd(m,n)
#define LCM(m,n) m*(n/GCD(m,n))
#define inputarr(a,n) for(int i=0;i<n;++i) cin>>a[i]
#define initarr(a,n,x) for (int i=0;i<n;++i) a[i]=x
#define rep(i, n)    for(int i = 0; i < (n); ++i)
#define repA(i, a, n)  for(int i = a; i <= (n); ++i)
#define repD(i, a, n)  for(int i = a; i >= (n); --i)
#define trav(a, x) for(auto& a : x)
#define sz(a) (int)a.size()
#define sl(a) (int)a.length()
#define invect(data,n,commands) for(int i = 0;i<n;i++){int tmp;cin>>tmp;data.pb(tmp);commands}
#define inset(data,n,commands) for(int i = 0;i<n;i++){int tmp;cin>>tmp;data.insert(tmp);commands}
#define ll long long
#define ld long double
#define pii std::pair<int, int>
#define pll std::pair<ll, ll>
#define vi vector<int>
#define vvi vector<vi >
#define vii vector<pii >

using namespace std;

void solve()
  {

    int n,m;
    cin>>n>>m;
    int a[n+1];
    repA(i,1,n)cin>>a[i];
    sort(a+1,a+(n+1));
    int dp[n+1],sum[n+1]={0};
    dp[0]=0;
    repA(i,1,n)
    { //cout<<a[i]<<" ";
      if(i<=m)sum[i]+=a[i];
      else
      {
        sum[i]=sum[i-m]+a[i];
      }
    }//cout<<endl;
    repA(i,1,n)
    {
      if(i<=m)dp[i]=a[i]+dp[i-1];
      else
      {
        dp[i]=dp[i-1]+sum[i];
      }
    }
    repA(i,1,n)cout<<dp[i]<<" ";
  }

int main()
{
   FAST
   #ifndef ONLINE_JUDGE
     freopen("input.txt","r",stdin);
     freopen("output.txt","w",stdout);
   #endif
   int t;
   t=1;
   //cin>>t;
   while(t--)
  {
      solve();
  }

   return 0;
}


//R<3S
#include <bits/stdc++.h>
#define FAST std::ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define DECIMAL(n)  std::cout << std::fixed;std::cout << std::setprecision(n);
#define hell 1000000007
#define PI 3.14159265358979323844
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define ALL(v) v.begin(), v.end()
#define SORT(v) sort(ALL(v))
#define REVERSE(v) reverse(ALL(v))
#define endl "\n"
#define maxc(v) max_element(all(v))
#define minc(v) min_element(all(v))
#define GCD(m,n) __gcd(m,n)
#define LCM(m,n) m*(n/GCD(m,n))
#define inputarr(a,n) for(int i=0;i<n;++i) cin>>a[i]
#define initarr(a,n,x) for (int i=0;i<n;++i) a[i]=x
#define rep(i, n)    for(int i = 0; i < (n); ++i)
#define repA(i, a, n)  for(int i = a; i <= (n); ++i)
#define repD(i, a, n)  for(int i = a; i >= (n); --i)
#define trav(a, x) for(auto& a : x)
#define sz(a) (int)a.size()
#define sl(a) (int)a.length()
#define invect(data,n,commands) for(int i = 0;i<n;i++){int tmp;cin>>tmp;data.pb(tmp);commands}
#define inset(data,n,commands) for(int i = 0;i<n;i++){int tmp;cin>>tmp;data.insert(tmp);commands}
#define ll long long
#define ld long double
#define pii std::pair<int, int>
#define pll std::pair<ll, ll>
#define vi vector<int>
#define vvi vector<vi >
#define vii vector<pii >

using namespace std;

void solve()
  {

    int n,m;
    cin>>n>>m;
    int a[n+1];
    repA(i,1,n)cin>>a[i];
    sort(a,a+n+1);
    int dp[n+1],sum[n+1]={0};
    dp[0]=0;
    repA(i,1,n)
    {
      if(i<=m)sum[i]+=a[i];
      else
      {
        sum[i]=sum[i-m]+a[i];
      }
    }
    repA(i,1,n)
    {
      if(i<=m)dp[i]=a[i]+dp[i-1];
      else
      {
        dp[i]=dp[i-1]+sum[i];
      }
    }
    repA(i,1,n)cout<<dp[i]<<" ";
  }

int main()
{
   FAST
   #ifndef ONLINE_JUDGE
     freopen("input.txt","r",stdin);
     freopen("output.txt","w",stdout);
   #endif
   int t;
   t=1;
   //cin>>t;
   while(t--)
  {
      solve();
  }

   return 0;
}


//R<3S
#include <bits/stdc++.h>
#define FAST std::ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define DECIMAL(n)  std::cout << std::fixed;std::cout << std::setprecision(n);
#define hell 1000000007
#define PI 3.14159265358979323844
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define ALL(v) v.begin(), v.end()
#define SORT(v) sort(ALL(v))
#define REVERSE(v) reverse(ALL(v))
#define endl "\n"
#define maxc(v) max_element(all(v))
#define minc(v) min_element(all(v))
#define GCD(m,n) __gcd(m,n)
#define LCM(m,n) m*(n/GCD(m,n))
#define inputarr(a,n) for(int i=0;i<n;++i) cin>>a[i]
#define initarr(a,n,x) for (int i=0;i<n;++i) a[i]=x
#define rep(i, n)    for(int i = 0; i < (n); ++i)
#define repA(i, a, n)  for(int i = a; i <= (n); ++i)
#define repD(i, a, n)  for(int i = a; i >= (n); --i)
#define trav(a, x) for(auto& a : x)
#define sz(a) (int)a.size()
#define sl(a) (int)a.length()
#define invect(data,n,commands) for(int i = 0;i<n;i++){int tmp;cin>>tmp;data.pb(tmp);commands}
#define inset(data,n,commands) for(int i = 0;i<n;i++){int tmp;cin>>tmp;data.insert(tmp);commands}
#define ll long long
#define ld long double
#define pii std::pair<int, int>
#define pll std::pair<ll, ll>
#define vi vector<int>
#define vvi vector<vi >
#define vii vector<pii >

using namespace std;

void solve()
  {

    ll n,m;
    cin>>n>>m;
    ll a[n+1];
    repA(i,1,n)cin>>a[i];
    sort(a+1,a+(n+1));
    ll dp[n+1],sum[n+1]={0};
    dp[0]=0;
    repA(i,1,n)
    { //cout<<a[i]<<" ";
      if(i<=m)sum[i]+=a[i];
      else
      {
        sum[i]=sum[i-m]+a[i];
      }
    }//cout<<endl;
    repA(i,1,n)
    {
      if(i<=m)dp[i]=a[i]+dp[i-1];
      else
      {
        dp[i]=dp[i-1]+sum[i];
      }
    }
    repA(i,1,n)cout<<dp[i]<<" ";
  }

int main()
{
   FAST
   #ifndef ONLINE_JUDGE
     freopen("input.txt","r",stdin);
     freopen("output.txt","w",stdout);
   #endif
   int t;
   t=1;
   //cin>>t;
   while(t--)
  {
      solve();
  }

   return 0;
}


//#include<bits/stdc++.h>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <cstring>
#include <iostream>
#include <queue>
#include <vector>
using namespace std;
#define PI acos(-1.0)
const int INF = 0x4f4f4f4f;
const int NINF = -INF - 1;
typedef long long ll;

bool cmp(int a, int b){
    return b < a;
}

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(nullptr);

    ll n, m; cin>>n>>m;
    ll arr[n];
    for(ll i = 0; i < n; i++){cin>>arr[i];}
    sort(arr, arr+n);
    ll dp[n+5]; memset(dp, 0, sizeof(dp)); // the min cost of first n sweets
    for(ll i = 1; i <= n; i++){
        for(ll j = 0; j < i; j++){
            dp[i] += (i-j+1) / 2 * arr[j];
        }
        cout<<dp[i]<<' ';
    }
    cout<<endl;

    return 0;
}


//#include<bits/stdc++.h>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <cstring>
#include <iostream>
#include <queue>
#include <vector>
using namespace std;
#define PI acos(-1.0)
const int INF = 0x4f4f4f4f;
const int NINF = -INF - 1;
typedef long long ll;

bool cmp(int a, int b){
    return b < a;
}

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(nullptr);

    ll n, m; cin>>n>>m;
    ll arr[n];
    for(ll i = 0; i < n; i++){cin>>arr[i];}
    sort(arr, arr+n);
    ll dp[n+5]; memset(dp, 0, sizeof(dp)); // the min cost of first n sweets
    for(ll i = 0; i < n; i++){
        for(ll j = 0; j <= i; j++){
            dp[i] += ((i-j) / m + 1) * arr[j];
        }
        cout<<dp[i]<<' ';
    }
    cout<<endl;
    return 0;
}


//#include<bits/stdc++.h>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <cstring>
#include <iostream>
#include <queue>
#include <vector>
using namespace std;
#define PI acos(-1.0)
const int INF = 0x4f4f4f4f;
const int NINF = -INF - 1;
typedef long long ll;

bool cmp(int a, int b){
    return b < a;
}

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(nullptr);

    ll n, m; cin>>n>>m;
    ll arr[n];
    for(ll i = 0; i < n; i++){cin>>arr[i];}
    sort(arr, arr+n);
    ll dp[n+5]; memset(dp, 0, sizeof(dp)); // the min cost of first n+1 sweets

    dp[0] = 0;
    for(ll i = 1; i <= m; i++){
        dp[i] = dp[i-1] + arr[i-1];
        cout<<dp[i]<<' ';
    }
    for(ll i = m+1; i <= n; i++){
        dp[i] = dp[i-1] + dp[i-m] - dp[i-m-1] + arr[i-1];
        cout<<dp[i]<<' ';
    }
    cout<<endl;
    getchar();
    return 0;
}


//#include<bits/stdc++.h>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <cstring>
#include <iostream>
#include <queue>
#include <vector>
using namespace std;
#define PI acos(-1.0)
const int INF = 0x4f4f4f4f;
const int NINF = -INF - 1;
typedef long long ll;

bool cmp(int a, int b){
    return b < a;
}

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(nullptr);

    ll n, m; cin>>n>>m;
    ll arr[n];
    for(ll i = 0; i < n; i++){cin>>arr[i];}
    sort(arr, arr+n);
    ll dp[n+5]; memset(dp, 0, sizeof(dp)); // the min cost of first n+1 sweets
    dp[0] = arr[0];
    cout<<dp[0]<<' ';
    for(ll i = 1; i < m; i++){
        dp[i] = dp[i-1] + arr[i];
        cout<<dp[i]<<' ';
    }
    dp[m] = dp[m-1] + arr[m] + arr[0];
    if(m < n) cout<<dp[m]<<' ';
    for(ll i = m+1; i < n; i++){
        dp[i] = dp[i-1] + dp[i-m] - dp[i-m-1] + arr[i];
        cout<<dp[i]<<' ';
    }
    cout<<endl;

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
    ll n,m,s=0,t=0,c=0,f=0,k;
    cin>>n>>m;

    ll a[n+10],b[n+10],d[n+10];

    for(int i = 1; i <= n; i++)
    {
        cin>>a[i];
    }

    sort(a+1,a+n+1);

    for(int i = 1; i <= n; i++)
    {
        s += a[i];
        c++;

        if(c == m)
        {
            b[i] = s;
            s -= a[i-m+1];
            c--;
        }
        else
        {
            b[i] = s;
        }
    }

    for(int i = 1; i <= n; i++)
    {
        f = 0,k=i;
        for(int j = 1; j <= i; j++)
        {
            if(k <= m)
            {
                f += (b[k]*j);
                cout<<f<<" ";
                    break;
            }
            else
            {
                f += (b[k]*j);
                k -= m;
            }
        }
    }
    cout<<endl;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll a[200005],b[200005];
int main()
{
    ll n,m,s=0;
    cin>>n>>m;
    for(int i = 1; i <= n; i++)
    {
        cin>>a[i];
    }

    sort(a+1,a+n+1);

    for(int i = 1; i <= n; i++)
    {

        s += a[i];
        b[i] = s;

        if(i > m)
        {
            b[i] += b[i-m];
        }
    }

    for(int i = 1; i <= n; i++)
    {
        cout<<b[i]<<" ";
    }
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ri register int
#define rll register long long
#define For(i,a,b) for(int i=a;i<=b;++i)
#define IOS std::ios::sync_with_stdio(false)
#define L(a) a<<1
#define R(a) a<<1|1
#define P pair<int,int>
#define re read()
#define lowbit(x) ((x)&-(x))
#define Pi 3.1415926

const int dx[4]={0,-1,0,1};
const int dy[4]={-1,0,1,0};
// const int dx[8]={-2,-1,1,2,2,1,-1,-2};
// const int dy[8]={1,2,2,1,-1,-2,-2,-1};
const int inf=0x3f3f3f3f;
const int mod=1e9+7;
//const int ll=9e18;
const int maxn=2e5+10;
const double eps=1e-5;

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

int n,m;
ll p[maxn];
ll cnt[maxn];
int main(){
    n=re,m=re;
    for(int i=1;i<=n;i++) p[i]=re;
    sort(p+1,p+1+n);
    for(int i=1;i<=n;i++) p[i]+=p[i-1];
    for(int i=1;i<=n;i++){
        if(i<=m) cnt[i]=p[i];
        else cnt[i]=p[i]+cnt[i-m];
        printf("%lld ",cnt[i]);
    }
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ri register int
#define rll register long long
#define For(i,a,b) for(int i=a;i<=b;++i)
#define IOS std::ios::sync_with_stdio(false)
#define L(a) a<<1
#define R(a) a<<1|1
#define P pair<int,int>
#define re read()
#define lowbit(x) ((x)&-(x))
#define Pi 3.1415926

const int dx[4]={0,-1,0,1};
const int dy[4]={-1,0,1,0};
// const int dx[8]={-2,-1,1,2,2,1,-1,-2};
// const int dy[8]={1,2,2,1,-1,-2,-2,-1};
const int inf=0x3f3f3f3f;
const int mod=1e9+7;
//const int ll=9e18;
const int maxn=2e5+10;
const double eps=1e-5;

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

int n,m;
int p[maxn];

int main(){
    n=re,m=re;
    for(int i=1;i<=n;i++) p[i]=re;
    sort(p+1,p+1+n);
    for(int i=1;i<=n;i++){
        ll ans=0;
        int base=1;
        for(int j=1;j<=i;j++){
            ans+=base*p[i-j+1];
            if(j%m==0) base++;
        }
        printf("%lld ",ans);
    }
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ri register int
#define rll register long long
#define For(i,a,b) for(int i=a;i<=b;++i)
#define IOS std::ios::sync_with_stdio(false)
#define L(a) a<<1
#define R(a) a<<1|1
#define P pair<int,int>
#define re read()
#define lowbit(x) ((x)&-(x))
#define Pi 3.1415926

const int dx[4]={0,-1,0,1};
const int dy[4]={-1,0,1,0};
// const int dx[8]={-2,-1,1,2,2,1,-1,-2};
// const int dy[8]={1,2,2,1,-1,-2,-2,-1};
const int inf=0x3f3f3f3f;
const int mod=1e9+7;
//const int ll=9e18;
const int maxn=1e5+10;
const double eps=1e-5;

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

int n,m;
int p[maxn];

int main(){

    cin>>n>>m;
    for(int i=1;i<=n;i++) p[i]=re;
    sort(p+1,p+1+n);
    for(int i=1;i<=n;i++){
        int ans=0;
        int base=1;
        for(int j=1;j<=i;j++){
            ans+=base*p[i-j+1];
            if(j%m==0) base++;
        }
        cout<<ans<<" ";
    }
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ri register int
#define rll register long long
#define For(i,a,b) for(int i=a;i<=b;++i)
#define IOS std::ios::sync_with_stdio(false)
#define L(a) a<<1
#define R(a) a<<1|1
#define P pair<int,int>
#define re read()
#define lowbit(x) ((x)&-(x))
#define Pi 3.1415926

const int dx[4]={0,-1,0,1};
const int dy[4]={-1,0,1,0};
// const int dx[8]={-2,-1,1,2,2,1,-1,-2};
// const int dy[8]={1,2,2,1,-1,-2,-2,-1};
const int inf=0x3f3f3f3f;
const int mod=1e9+7;
//const int ll=9e18;
const int maxn=2e5+10;
const double eps=1e-5;

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

int n,m;
int p[maxn];

int main(){

    cin>>n>>m;
    for(int i=1;i<=n;i++) p[i]=re;
    sort(p+1,p+1+n);
    for(int i=1;i<=n;i++){
        ll ans=0;
        int base=1;
        for(int j=1;j<=i;j++){
            ans+=base*p[i-j+1];
            if(j%m==0) base++;
        }
        cout<<ans<<" ";
    }
}


#include<bits/stdc++.h>
using namespace std;
long long ans[200001];
int main(){

	ios::sync_with_stdio(false);
	int n,m;
	int a[200001];

	cin>>n>>m;

	for(int i=1;i<=n;i++){
		cin>>a[i];
	}

	sort(a+1,a+n+1);

	int k=1;
	int s=0;
	ans[1]=a[1];
	cout<<ans[1]<<" ";

	for(int i=2;i<=n;i++){

		if(i>m){
			for(int j=(i%m);j<=i;j+=m){
				ans[i-1]+=a[j];
			}
			ans[i]=ans[i-1];
		}
		else{

			ans[i]=ans[i-1]+a[i];

		}

		cout<<ans[i]<<" ";

	}

	cout<<endl;

	return 0;

}


#include<iostream>
#include<stdio.h>
#include<algorithm>
using namespace std;
typedef long long ll;
ll a[200200],num,sum[200200],ans[200200],n;
ll  com(ll x,ll y)
{return x<y;
}
int main()
{
	scanf("%d%d",&n,&num);
	for(int i=1;i<=n;i++)scanf("%lld",&a[i]);
	sort(a+1,a+1+n);
	a[0]=0;sum[0]=0;ans[0]=0;
	for(int i=1;i<=n;i++)
	{
		if(i>num)
			sum[i]=a[i]+sum[i-num];
		else sum[i]=a[i];
		ans[i]=ans[i-1]+sum[i];

		/*sum[i]=a[i]+sum[i-1];
		if(i-num<1)
		{
		ans[i]=sum[i]+ans[i-num];
		}
		else
		{
		ans[i]=ans[i-num]+sum[i];
		}*/
	}
	for(int i=1;i<=n;i++)
	cout<<ans[i]<<" ";
}


#include<bits/stdc++.h>
#define int long long
using namespace std;
inline int read()
{
	int s=0;char ch;
	do
	{
		ch=getchar();
	}while(ch<'0'||ch>'9');
	while(ch>='0'&&ch<='9')
	{
		s*=10;
		s+=ch-48;
		ch=getchar();
	}
	return s;
}
int a[200005],sum[200005],ans[200005];
signed main()
{
	int n,m,i,j;
	n=read();m=read();
	for(i=1;i<=n;i++) a[i]=read();
	sort(a+1,a+1+n);
	for(i=1;i<=m;i++) sum[i]=a[i];
	for(i=m+1;i<=2*m;i++)
	  for(j=i;j<=n;j+=m)
		sum[j]=sum[j-m]+a[j];
	//for(i=1;i<=n;i++) cout<<sum[i]<<" ";
	printf("%lld",a[1]);
	ans[1]=a[1];
	for(i=2;i<=n;i++)
	{
		ans[i]=ans[i-1]+sum[i];
		printf(" %lld",ans[i]);
	}
}


#include<iostream>
#include<stdio.h>
#include<algorithm>
using namespace std;
typedef long long ll;
ll a[200200],num,sum[200200],ans[200200],n;
ll  com(ll x,ll y)
{return x<y;
}
int main()
{
	scanf("%d%d",&n,&num);
	for(int i=1;i<=n;i++)scanf("%lld",&a[i]);
	sort(a+1,a+1+n);
	a[0]=0;sum[0]=0;ans[0]=0;
	for(int i=1;i<=n;i++)
	{
		/*if(i>num)
			sum[i]=a[i]+sum[i-num];
		else sum[i]=a[i];
		ans[i]=ans[i-1]+sum[i];*/

		sum[i]=a[i]+sum[i-1];
		if(i>num)
		ans[i]=sum[i]+ans[i-num];
		else
		ans[i]=sum[i];

	}
	for(int i=1;i<=n;i++)
	cout<<ans[i]<<" ";
}


#include<iostream>
#include<stdio.h>
#include<algorithm>
using namespace std;
long long a[200200],num,sum[200200],ans[200200],n;
int main()
{
	scanf("%d%d",&n,&num);
	for(int i=1;i<=n;i++)scanf("%d",&a[i]);
	sort(a+1,a+1+n,less<long long>());
	a[0]=0;sum[0]=0;
	for(int i=1;i<=n;i++)
	{
		sum[i]=a[i]+sum[i-1];
		if(i-num<1)
		{
		ans[i]=sum[i]+ans[i-num];
		}
		else
		{
		ans[i]=ans[i-num]+sum[i];
		}
	}
	for(int i=1;i<=n;i++)
	cout<<ans[i]<<" ";
}


#include <bits/stdc++.h>
#define MAXN 200005
#define int long long
using std::sort;
int n,m,i,ans,a[MAXN],s[MAXN];
inline void read(int &x)
{
	short negative=1;
    x=0;
    char c=getchar();
    while(c<'0' || c>'9')
    {
    	if(c=='-')
			negative=-1;
		c=getchar();
	}
    while(c>='0' && c<='9')
        x=(x<<3)+(x<<1)+(c^48),c=getchar();
    x*=negative;
}
inline void print(int x)
{
    if (x<0)
        putchar('-'),x=-x;
    if (x>9)
        print(x/10);
    putchar(x%10+'0');
}
signed main(void)
{
	read(n),read(m);
	for (i=1;i<=n;i++)
		read(a[i]);
	sort(a+1,a+n+1);
	for (i=1;i<=m;i++)
		s[i]=a[i];
	for (i=m+1;i<=n;i++)
		s[i]=a[i]+s[i-m];
	for (i=1;i<=n;i++)
	{
		ans+=a[i];
		if (i>m)
			ans+=s[i-m];
		print(ans),putchar(' ');
	}
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

typedef long long int ll;

ll n,m;
ll a[200010],dp[200010];

//dp[k] 前k个糖果的惩罚
//dp[k] = dp[k-1] + sum[k]

int main()
{
    memset(dp, 0, sizeof(dp));
    scanf("%lld %lld",&n,&m);
    for ( int i = 1; i <= n; i ++ ) scanf("%lld",&a[i]);
    sort(a + 1, a + n + 1);
    ll sum = 0;
    for ( int i = 1; i <= n; i ++ )
    {
        sum += a[i];
        dp[i] = sum;
        if ( i > m ) dp[i] += dp[i - m];
        printf("%lld ",dp[i]);
    }
    printf("\n");

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int ans[200001];
int sum[200001];
int main(){

	ios::sync_with_stdio(false);
	int n,m;
	int a[200001];

	cin>>n>>m;

	int js=0;

	for(int i=1;i<=n;i++){
		cin>>a[i];
	}

	sort(a+1,a+n+1);
	for(int i=1;i<=n;i++){
		if(i<=m){
			sum[i]=a[i];
		}
		else{
			sum[i]=sum[i-m]+a[i];
		}

	}

	int k=1;
	int s=0;
	ans[1]=a[1];
	cout<<ans[1]<<" ";

	for(int i=2;i<=n;i++){

		ans[i]=ans[i-1]+sum[i];

		cout<<ans[i]<<" ";

	}

	cout<<endl;

	return 0;

}


#include <bits/stdc++.h>
#define MAXN 200005
using std::sort;
int n,m,i,ans,a[MAXN],s[MAXN];
inline void read(int &x)
{
	short negative=1;
    x=0;
    char c=getchar();
    while(c<'0' || c>'9')
    {
    	if(c=='-')
			negative=-1;
		c=getchar();
	}
    while(c>='0' && c<='9')
        x=(x<<3)+(x<<1)+(c^48),c=getchar();
    x*=negative;
}
inline void print(int x)
{
    if (x<0)
        putchar('-'),x=-x;
    if (x>9)
        print(x/10);
    putchar(x%10+'0');
}
signed main(void)
{
	read(n),read(m);
	for (i=1;i<=n;i++)
		read(a[i]);
	sort(a+1,a+n+1);
	for (i=1;i<=m;i++)
		s[i]=a[i];
	for (i=m+1;i<=n;i++)
		s[i]=a[i]+s[i-m];
	for (i=1;i<=n;i++)
	{
		ans+=a[i];
		if (i>m)
			ans+=s[i-m];
		print(ans),putchar(' ');
	}
	return 0;
}


#include<iostream>
#include<stdio.h>
#include<algorithm>
using namespace std;
int a[200200],num,sum[200200],ans[200200],n;
int com(int x,int y)
{return x<y;
}
int main()
{
	scanf("%d%d",&n,&num);
	for(int i=1;i<=n;i++)scanf("%d",&a[i]);
	sort(a+1,a+1+n,com);
	a[0]=0;sum[0]=0;
	for(int i=1;i<=n;i++)
	{
		sum[i]=a[i]+sum[i-1];
		if(i-num<1)
		{
		ans[i]=sum[i]+ans[i-num];
		}
		else
		{
		ans[i]=ans[i-num]+sum[i];
		}
	}
	for(int i=1;i<=n;i++)
	cout<<ans[i]<<" ";
}


#include<bits/stdc++.h>
#define int long long
using namespace std;
inline int read()
{
	int s=0;char ch;
	do
	{
		ch=getchar();
	}while(ch<'0'||ch>'9');
	while(ch>='0'&&ch<='9')
	{
		s*=10;
		s+=ch-48;
		ch=getchar();
	}
	return s;
}
int a[200005],sum[200005],ans[200005];
signed main()
{
	int n,m,fym;
	n=read();m=read();
	for(register int i=1;i<=n;i++) a[i]=read();
	sort(a+1,a+1+n);
	for(register int i=1;i<=m;i++) sum[i]=a[i];
	fym=2*m;
	for(register int i=m+1;i<=fym;i++)
	  for(register int j=i;j<=n;j+=m)
		sum[j]=sum[j-m]+a[j];
	//for(i=1;i<=n;i++) cout<<sum[i]<<" ";
	printf("%lld",a[1]);
	ans[1]=a[1];
	for(register int i=2;i<=n;i++)
	{
		ans[i]=ans[i-1]+sum[i];
		printf(" %lld",ans[i]);
	}
}


#include <bits/stdc++.h>
#define For(i,a,b) for ( int i=(a);i<=(b);i++ )
#define Dow(i,b,a) for ( int i=(b);i>=(a);i-- )
#define GO(i,x) for ( int i=head[x];i;i=e[i].nex )
#define mem(x,s) memset(x,s,sizeof(x))
#define cpy(x,s) memcpy(x,s,sizeof(x))
#define YES return puts("YES"),0
#define NO return puts("NO"),0
#define GG return puts("-1"),0
#define pb push_back
#define int long long
using namespace std;

struct IO
{
	#define MAXSIZE (1 << 20)
	#define isdigit(x) (x >= '0' && x <= '9')
  	char buf[MAXSIZE],*p1,*p2;
  	char pbuf[MAXSIZE],*pp;
  	IO():p1(buf),p2(buf),pp(pbuf){}
  	inline char gc() {
  		return getchar();
    	if (p1==p2) p2=(p1=buf)+fread(buf,1,MAXSIZE,stdin);
    	return p1==p2?' ':*p1++;
  	}
	inline bool blank(char ch) {return ch==' '||ch =='\n'||ch == '\r'||ch == '\t';}
  	template <class T>
  	inline void read(T &x)
	{
	    register double tmp=1;register bool sign=0; x=0;
	    register char ch=gc();
	    for (;!isdigit(ch);ch=gc()) if(ch=='-') sign=1;
	    for (;isdigit(ch);ch=gc()) x=x*10+(ch-'0');
	    if (ch=='.') for (ch=gc();isdigit(ch);ch=gc()) tmp/=10.0,x+=tmp*(ch-'0');
	    if (sign) x=-x;
  	}
  	inline void read(char *s)
	{
    	register char ch=gc();
		for (;blank(ch);ch=gc());
		for (;!blank(ch);ch=gc()) *s++=ch;
    	*s=0;
  	}
  	inline void read(char &c) {for(c=gc();blank(c);c=gc());}
  	template<class t> inline void write(t x){
		if(x<0) putchar('-'),write(-x);
		else{if(x>9) write(x/10);putchar('0'+x%10);}
	}
} io;

const int mod=1e9+7;
const int mo=998244353;
const int N=5e5+5;

int n,m,a[N],ans,b[N],Ans[N];

signed main()
{
	io.read(n),io.read(m);
	For(i,1,n) io.read(a[i]);
	sort(a+1,a+n+1);
	For(i,1,n) b[i]=b[i-1]+a[i];
	For(i,1,n)
	{
		if(i<=m) ans+=b[i];
		if(i>m)
		{
			int las=i-m;
			int gs=b[i]-b[las];
			ans+=Ans[las]+gs+b[las];
		}
		Ans[i]=ans;
		ans=0;
	}
	For(i,1,n) io.write(Ans[i]),putchar(' ');
	return 0;
}


#include <bits/stdc++.h>

#define eb emplace_back
#define FOR(i, a, b) for(int i = a; i < (int) b; i++)
#define FORD(i, a, b) for(int i = a; i >= (int) b; i--)

using namespace std;

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpii;
typedef vector<vi> vvi;
typedef vector<vpii> vvpii;
typedef long long i64;
typedef vector<i64> vi64;
typedef vector<vi64> vvi64;
typedef pair<i64, i64> pi64;
typedef vector<pi64> vpi64;

const int N = 2e5 + 5;
i64 dp[N];

int main () {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int n, m;
  cin >> n >> m;
  vi a (n);
  FOR (i, 0, n) {
     cin >> a[i];
  }
  sort (a.begin(), a.end());
  i64 cur = 0;
  FOR (i, 0, n) {
    cur += a[i];
    if (i - m >= 0) {
      dp[i] = cur + dp[i - m];
    } else {
      dp[i] = cur;
    }
    cout << dp[i] << ' ';
  }
  return 0;
}


#include <bits/stdc++.h>

#define eb emplace_back
#define FOR(i, a, b) for(int i = a; i < (int) b; i++)
#define FORD(i, a, b) for(int i = a; i >= (int) b; i--)

using namespace std;

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpii;
typedef vector<vi> vvi;
typedef vector<vpii> vvpii;
typedef long long i64;
typedef vector<i64> vi64;
typedef vector<vi64> vvi64;
typedef pair<i64, i64> pi64;
typedef vector<pi64> vpi64;

const int N = 2e5 + 5;
int dp[N];

int main () {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int n, m;
  cin >> n >> m;
  vi a (n);
  FOR (i, 0, n) {
    cin >> a[i];
  }
  sort (a.begin(), a.end());
  memset (dp, -1, sizeof(dp));
  dp[0] = a[0];
  FOR (i, 0, m) {
    int tot = 0;
    for (int j = i; j < n; j += m) {
      tot += a[j];
      dp[j] = tot;
    }
  }
  i64 tot = 0;
  FOR (i, 0, n) {
    tot += 1LL * ((((n - 1) - i) / m) + 1) * a[i];
  }
  vi64 ans;
  ans.eb(tot);
  for (int i = n - 1; i > m; i--) {
    tot -= a[i];
    tot -= dp[i - m];
    ans.eb(tot);
  }
  tot = 0;
  if ((int)ans.size() != n) {
    FOR (i, 0, m) {
      tot += a[i];
      ans.eb(tot);
    }
}
  sort (ans.begin(), ans.end());
  ans.erase (unique(ans.begin(), ans.end()), ans.end());
  FOR (i, 0, ans.size()) {
    cout << ans[i] << ' ';
  }
   cout << '\n';
  return 0;
}


#include <bits/stdc++.h>

#define eb emplace_back
#define FOR(i, a, b) for(int i = a; i < (int) b; i++)
#define FORD(i, a, b) for(int i = a; i >= (int) b; i--)

using namespace std;

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpii;
typedef vector<vi> vvi;
typedef vector<vpii> vvpii;
typedef long long i64;
typedef vector<i64> vi64;
typedef vector<vi64> vvi64;
typedef pair<i64, i64> pi64;
typedef vector<pi64> vpi64;

const int N = 2e5 + 5;
i64 dp[N];

int main () {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int n, m;
  cin >> n >> m;
  vi a (n);
  FOR (i, 0, n) {
    cin >> a[i];
  }
  sort (a.begin(), a.end());
  memset (dp, -1, sizeof(dp));
  dp[0] = a[0];
  FOR (i, 0, m) {
    i64 tot = 0;
    for (int j = i; j < n; j += m) {
      tot += a[j];
      dp[j] = tot;
    }
  }
  i64 tot = 0;
  FOR (i, 0, n) {
    tot += 1LL * ((((n - 1) - i) / m) + 1) * a[i];
  }
  vi64 ans;
  ans.eb(tot);
  for (int i = n - 1; i > m; i--) {
    tot -= a[i];
    tot -= dp[i - m];
    ans.eb(tot);
  }
  tot = 0;
  if ((int)ans.size() != n) {
    FOR (i, 0, m) {
      tot += a[i];
      ans.eb(tot);
    }
}
  sort (ans.begin(), ans.end());
  ans.erase (unique(ans.begin(), ans.end()), ans.end());
  FOR (i, 0, ans.size()) {
    cout << ans[i] << ' ';
  }
   cout << '\n';
  return 0;
}


#include <bits/stdc++.h>

#define eb emplace_back
#define FOR(i, a, b) for(int i = a; i < (int) b; i++)
#define FORD(i, a, b) for(int i = a; i >= (int) b; i--)

using namespace std;

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpii;
typedef vector<vi> vvi;
typedef vector<vpii> vvpii;
typedef long long i64;
typedef vector<i64> vi64;
typedef vector<vi64> vvi64;
typedef pair<i64, i64> pi64;
typedef vector<pi64> vpi64;

const int N = 2e5 + 5;
i64 dp[N];

int main () {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int n, m;
  cin >> n >> m;
  vi a (n);
  FOR (i, 0, n) {
     cin >> a[i];
  }
  sort (a.begin(), a.end());
  i64 cur = 0;
  FOR (i, 0, n) {
    cur += a[i];
    if (i - m >= 0) {
      dp[i] = cur + dp[i - m];
    } else {
      dp[i] = cur;
    }
    if (i - m >= 0) cout << cur + dp[i - m] << ' ';
    else cout << cur << ' ';
  }
  return 0;
}


#include <bits/stdc++.h>

#define eb emplace_back
#define FOR(i, a, b) for(int i = a; i < (int) b; i++)
#define FORD(i, a, b) for(int i = a; i >= (int) b; i--)

using namespace std;

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpii;
typedef vector<vi> vvi;
typedef vector<vpii> vvpii;
typedef long long i64;
typedef vector<i64> vi64;
typedef vector<vi64> vvi64;
typedef pair<i64, i64> pi64;
typedef vector<pi64> vpi64;

const int N = 2e5 + 5;
int dp[N];

int main () {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int n, m;
  cin >> n >> m;
  vi a (n);
  FOR (i, 0, n) {
    cin >> a[i];
  }
  sort (a.begin(), a.end());
  memset (dp, -1, sizeof(dp));
  dp[0] = a[0];
  FOR (i, 0, m) {
    int tot = 0;
    for (int j = i; j < n; j += m) {
      tot += a[j];
      dp[j] = tot;
    }
  }
  i64 tot = 0;
  FOR (i, 0, n) {
    tot += 1LL * ((((n - 1) - i) / m) + 1) * a[i];
  }
  vi64 ans;
  ans.eb(tot);
  for (int i = n - 1; i > m; i--) {
    tot -= a[i];
    tot -= dp[i - m];
    ans.eb(tot);
  }
  tot = 0;
  if ((int)ans.size() != n) {
    FOR (i, 0, m) {
      tot += a[i];
      cout << tot << ' ';
    }
}
  reverse (ans.begin(), ans.end());
  FOR (i, 0, ans.size()) {
    cout << ans[i] << ' ';
  }
   cout << '\n';
  return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n,m;
	cin>>n>>m;
	int arr[n];
	long long prefix[n];
	for(int i=0;i<n;i++)
		cin>>arr[i];

	long long sum=0;
	sort(arr,arr+n);
	prefix[0]=arr[0];

	for(int i=1;i<n;i++){
		prefix[i]=prefix[i-1]+arr[i];
		//cout<<prefix[i]<<" ";
	}
	//int grps[n/m];
	long long tsum=0;
	for(int i=0;i<n;i++)
	{
		int count=1;sum=0;
		if(m>1){
		for(int k=i;k>=0;k-=m)
		{
			if(k>=m)
			sum += (prefix[k]-prefix[k-m])*count;
			else
				sum += prefix[k]*count;

			count++;
		}}
		if(sum==0){
			tsum += arr[n-i-1]*(i+1);
			sum=tsum;
		}
		cout<<sum<<" ";

	}
	cout<<"\n";
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n,m;
	cin>>n>>m;
	int arr[n+1];
	arr[0]=0;
	long long prefix[n+1];
	for(int i=1;i<=n;i++)
		cin>>arr[i];

	//long long sum=0;
	sort(arr,arr+n+1);
	prefix[0]=0;

	for(int i=1;i<=n;i++){
		prefix[i]=prefix[i-1]+arr[i];
		//cout<<prefix[i]<<" ";
	}
	//int count=1;
	long long sum[n+1];
	sum[0]=0;
	//long long tsum=0;
	for(int i=1;i<=n;i++)
	{
		/*int count=1;sum=0;

		for(int k=i;k>=0;k-=m)
		{
			if(k>=m)
			sum += (prefix[k]-prefix[k-m])*count;
			else
				sum += prefix[k]*count;

			count++;
		}*/
		if(i<=m)
			sum[i] = prefix[i];
		else
		{
			sum[i] = prefix[i]+sum[i-m];

		}

		cout<<sum[i]<<" ";

	}
	cout<<"\n";
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n,m;
	cin>>n>>m;
	int arr[n];
	for(int i=0;i<n;i++)
		cin>>arr[i];
	long long sum=0;
	sort(arr,arr+n);
	//int grps[n/m];

	for(int i=0;i<n;i++)
	{
		int count=1;sum=0;
		for(int j=0;j<=i;j++)
		{
			sum += arr[i-j]*count;
			if((j+1)%m==0)
				count++;
		}
		cout<<sum<<" ";

	}
	cout<<"\n";
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n,m;
	cin>>n>>m;
	int arr[n];
	long long prefix[n];
	for(int i=0;i<n;i++)
		cin>>arr[i];

	long long sum=0;
	sort(arr,arr+n);
	prefix[0]=arr[0];

	for(int i=1;i<n;i++){
		prefix[i]=prefix[i-1]+arr[i];
		//cout<<prefix[i]<<" ";
	}
	//int grps[n/m];

	for(int i=0;i<n;i++)
	{
		int count=1;sum=0;
		for(int k=i;k>=0;k-=m)
		{
			if(k>=m)
			sum += (prefix[k]-prefix[k-m])*count;
			else
				sum += prefix[k]*count;

			count++;
		}
		cout<<sum<<" ";

	}
	cout<<"\n";
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<algorithm>
#include<queue>
#include<vector>
#define ll unsigned long long
using namespace std;
const int maxx=600010;
ll t,n,m;
ll ans=0,total=0,sum=0;
ll a[maxx],b[maxx];
bool cmp(ll x,ll y)
{
	return x>y;
}
int main()
{
	scanf("%lld%lld",&n,&m);
	for(register int i=1;i<=n;i++)scanf("%lld",&a[i]);
	sort(a+1,a+n+1,cmp);
	total=1;
	for(register int i=1;i<=n;i++)
	{
		ans+=total*a[i];
		if(i%m==0)total++;
	}
	sum=n;
	b[sum]=ans;
	total=0;
	while(sum!=1)
	{
		total++;
		sum--;
		ans-=a[n-sum];
		ll l=total;
		while(l<=n)
		{
			ans-=a[l];
			l+=m;
		}
		b[sum]=ans;
	}
	for(register int i=1;i<=n;i++)
		printf("%lld ",b[i]);
	return 0;
}


import java.math.BigInteger;
import java.util.Scanner;

public class test {

	static boolean s[];
	static int a[] ;
	static BigInteger dp[][] = new BigInteger[5005][2005];
	static int N;
	static boolean vis[][] = new boolean [5005][2005];
	/**
	 * @param args
	 */
	static BigInteger val[] = new BigInteger[2005];
	static BigInteger TWO = BigInteger.valueOf(2);

	static BigInteger f(int i,int x)
	{
		if( i == N)
			return BigInteger.ZERO;

		if( dp[i][x] != null )
			return dp[i][x];
		dp[i][x] = f(i+1,x);
		if( s[i] )
			dp[i][x] = dp[i][x].max(f(i+1,a[i]));
		else if( a[i] == x)
			dp[i][x] = dp[i][x].max(f(i+1,2001).add(  val[x] ));

		return dp[i][x];

	}
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		//System.out.println("Hello JAVA!!!");
		Scanner reader = new Scanner(System.in);
		N = reader.nextInt();
		s = new boolean[N];
		a = new int[N];
		String ss;
		for(int i=0;i<N;i++)
		{
			ss = reader.next();
			a[i] = reader.nextInt();
			s[i] = true;
			if( ss.equals("sell") )
			{
					//val[a[i]] = BigInteger.ONE.shiftLeft(a[i]);
				val[a[i]] = TWO.pow(a[i]);
				s[i] = false;
			}
		}

		System.out.println(f(0,2001));

	}

}


import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Scanner;

public class Main {
    static int n;
    static ArrayList<pair> values;
    static BigInteger[] sv;

    static BigInteger dp(int ind) {
        if (ind == n)
            return BigInteger.ZERO;
        if (!sv[ind].equals(BigInteger.valueOf(-1)))
            return sv[ind];
        BigInteger x = dp(ind + 1);
        if (!values.get(ind).sell) {
            for (int i = ind + 1; i < n; i++) {
                if (values.get(i).sell
                        && values.get(ind).value == values.get(i).value) {
                    x = x.max(dp(i + 1).add(BigInteger.valueOf(2).pow(values.get(ind).value)));
                }
            }
        }
        return sv[ind] = x;
    }

    public static void main(String[] args) {
        values = new ArrayList<pair>();
        sv = new BigInteger[5001];
        Scanner scan = new Scanner(System.in);
        n = scan.nextInt();
        String s;
        int x;
        for (int i = 0; i < n; i++) {
            sv[i] = BigInteger.valueOf(-1);
            s = scan.next();
            x = scan.nextInt();
            values.add(new pair(x, s));
        }
        BigInteger max = dp(0);
        System.out.println(max);
    }
}

class pair {
    boolean sell;
    int value;

    public pair(int value, String s) {
        if (s.charAt(0) == 'w')
            sell = false;
        else
            sell = true;
        this.value = value;
    }
}


import java.util.Scanner;
import java.math.*;
public class Main{
    public static void main(String[] args){
        BigInteger mayor[] = new BigInteger[5001];
        int arr[] = new int[5001];
        boolean gano[] = new boolean[5001];
        int donde, n;
        BigInteger tengo;
        Scanner in = new Scanner(System.in);
        n = in.nextInt();
        String cad;
        for(int i = 1; i <= n; i++){
            cad = in.next();
            arr[i] = in.nextInt();
            if(cad.charAt(0) == 'w') gano[i] = true;
        }
        mayor[0] = BigInteger.ZERO;
        for(int i = 1; i <= n; i++){
            mayor[i] = mayor[i - 1].add(BigInteger.ZERO);
            if(!gano[i]){
                donde = -1;
                for(int j = i - 1; j > 0; j--)
                    if((gano[j]) && arr[i] == arr[j]){
                        donde = j;
                        break;
                    }
                if(donde != -1){
                    tengo = new BigInteger("1");
                    tengo = tengo.shiftLeft(arr[i]); // valor
                    mayor[i] = mayor[i].max(tengo.add(mayor[donde - 1]));
                }
            }
        }
        System.out.println(mayor[n]);
    }
}


import java.io.*;
import java.math.BigInteger;
import java.util.*;

public class Main  {

    public static void main(String[] args) throws IOException{
        //InputStream inputStream = new  File("input.txt");
        //OutputStream outputStream = new File("output.txt");

        //Scanner in = new Scanner(new File("input.txt"));
        //PrintWriter out = new PrintWriter(new File("output.txt"));

        Scanner in = new Scanner(System.in);
        PrintWriter out = new PrintWriter(System.out);

        int[] fs = new int[2010];
        int[] ls = new int[2010];
        for(int i = 0; i < 2010; ++i){
            ls[i] = -1;
            fs[i] = -1;
        }

        int n = in.nextInt();
        String s;
        int x;

        for(int i = 0; i < n; ++i){
            s = in.next();
            x = in.nextInt();

            if(Objects.equals(s, "win")){
                if(ls[x] == -1) {
                    fs[x] = i;
                }
            }else{
                ls[x] = i;
            }
        }

        BigInteger sum = BigInteger.ZERO;
        int[] t = new int[5010];
        for(int i = 0; i < 5010; ++i){
            t[i] = -1;
        }
        for(int i = 2000; i >= 0; --i){
            if(fs[i] != -1 && ls[i] != -1 && fs[i] < ls[i]) {
                Boolean b = true;
                for (int j = fs[i]; j <= ls[i]; ++j){
                    if(t[j] != -1){
                        b = false;
                        break;
                    }
                }

                if(b){
                    sum = sum.add(BigInteger.valueOf(2).pow(i));
                    for(int j = fs[i]; j <= ls[i]; ++j){
                        t[j] = 1;
                    }
                }

            }
        }

        out.println(sum.toString());

        out.flush();
    }
}

// Thu Mar 31 2016 20:37:16 GMT+0300 (MSK)


import java.io.*;
import java.math.BigInteger;
import java.util.*;

public class Main  {

    public static void main(String[] args) throws IOException{
        //InputStream inputStream = new  File("input.txt");
        //OutputStream outputStream = new File("output.txt");

        //Scanner in = new Scanner(new File("input.txt"));
        //PrintWriter out = new PrintWriter(new File("output.txt"));

        Scanner in = new Scanner(System.in);
        PrintWriter out = new PrintWriter(System.out);

        int[] fs = new int[2010];
        int[] ls = new int[2010];
        for(int i = 0; i < 2010; ++i){
            ls[i] = -1;
            fs[i] = -1;
        }

        int n = in.nextInt();
        String s;
        int x;

        for(int i = 0; i < n; ++i){
            s = in.next();
            x = in.nextInt();

            if(Objects.equals(s, "win")){
                if(ls[x] == -1) {
                    fs[x] = i;
                }
            }else{
                ls[x] = i;
            }
        }

        BigInteger sum = BigInteger.ZERO;
        int[] t = new int[5010];
        for(int i = 0; i < 5010; ++i){
            t[i] = -1;
        }
        for(int i = 2000; i >= 0; --i){
            if(fs[i] != -1 && ls[i] != -1 && fs[i] < ls[i]) {
                Boolean b = true;
                for (int j = fs[i]; j <= ls[i]; ++j){
                    if(t[j] != -1){
                        b = false;
                        break;
                    }
                }

                if(b){
                    sum = sum.add(BigInteger.valueOf(2).pow(i));
                    for(int j = fs[i]; j <= ls[i]; ++j){
                        t[j] = 1;
                    }
                }

            }
        }

        out.println(sum.toString());

        out.flush();
    }
}

// Thu Mar 31 2016 20:36:19 GMT+0300 (MSK)


import java.io.*;
import java.math.BigInteger;
import java.util.*;

public class Main  {

    public static void main(String[] args) throws IOException{
        //InputStream inputStream = new  File("input.txt");
        //OutputStream outputStream = new File("output.txt");

        //Scanner in = new Scanner(new File("input.txt"));
        //PrintWriter out = new PrintWriter(new File("output.txt"));

        Scanner in = new Scanner(System.in);
        PrintWriter out = new PrintWriter(System.out);

        int[] fs = new int[2010];
        int[] ls = new int[2010];
        for(int i = 0; i < 2010; ++i){
            ls[i] = -1;
            fs[i] = -1;
        }

        int n = in.nextInt();
        String s;
        int x;

        for(int i = 0; i < n; ++i){
            s = in.next();
            x = in.nextInt();

            if(Objects.equals(s, "win")){
                if(ls[x] == -1) {
                    fs[x] = i;
                }
            }else{
                ls[x] = i;
            }
        }

        BigInteger sum = BigInteger.ZERO;
        int[] t = new int[5010];
        for(int i = 0; i < 5010; ++i){
            t[i] = -1;
        }
        for(int i = 2000; i >= 0; --i){
            if(fs[i] != -1 && ls[i] != -1 && fs[i] < ls[i]) {
                Boolean b = true;
                for (int j = fs[i]; j <= ls[i]; ++j){
                    if(t[j] != -1){
                        b = false;
                        break;
                    }
                }

                if(b){
                    sum = sum.add(BigInteger.valueOf(2).pow(i));
                    for(int j = fs[i]; j <= ls[i]; ++j){
                        t[j] = 1;
                    }
                }

            }
        }

        out.println(sum.toString());

        out.flush();
    }
}

// Thu Mar 31 2016 20:39:50 GMT+0300 (MSK)


import java.io.PrintWriter;
import java.math.BigInteger;
import java.util.Scanner;
import java.util.StringJoiner;

public class Main {

    public static void main(String[] args) {

        Scanner in = new Scanner(System.in);
        PrintWriter out = new PrintWriter(System.out);

        int n = in.nextInt();

        int[] day = new int[20000];

        BigInteger[] dp = new BigInteger[n];

        for (int i = 0; i < 20000; i++)
            day[i] = -1;

        BigInteger c = BigInteger.ZERO;

        for (int i = 0; i < n; i++) {
            String s = in.next();
            int d = in.nextInt();
          //  out.println(s);
            if (s.compareTo("sell") == 0) {
                if (day[d] != -1 && c.compareTo(dp[day[d]].add(BigInteger.valueOf(2).pow(d))) == -1) {
                    c = dp[day[d]].add(BigInteger.valueOf(2).pow(d));
                }
            }
            day[d] = i;
            dp[i] = c;
        }
        out.print(c);
        out.flush();
    }
}

// Thu Mar 31 2016 21:58:25 GMT+0300 (MSK)


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

public class Program implements Runnable {
    public static void main(String[] args) throws Exception {
        Scanner in = new Scanner(System.in);
        PrintWriter out = new PrintWriter(System.out);
        Thread thread = new Thread(new Program(in, out));
        thread.start();
        thread.join();
    }

    final Scanner in;
    final PrintWriter out;

    Program(Scanner in, PrintWriter out) {
        this.in = in;
        this.out = out;
    }

    public void run() {
        out.println(solve());
        out.flush();
    }

    class Segment implements Comparable<Segment> {
        final int value;
        final int start;
        final int end;

        public Segment(int value, int start, int end) {
            this.value = value;
            this.start = start;
            this.end = end;
        }

        public int compareTo(Segment other) {
            return this.start - other.start;
        }
    }

    BigInteger solve() {
        final int MAX_MEMORY = 2000;
        List<Segment> segments = new ArrayList<Segment>();
        int[] latestWins = new int[MAX_MEMORY + 1];
        Arrays.fill(latestWins, -1);
        int n = in.nextInt();
        for (int i = 0; i < n; i++) {
            String action = in.next();
            int mem = in.nextInt();
            if (action.equals("win")) {
                latestWins[mem] = i;
            } else {
                int start = latestWins[mem];
                if (start != -1) {
                    segments.add(new Segment(mem, start, i));
                }
            }
        }

        Collections.sort(segments);

        BigInteger revenue = BigInteger.ZERO;

        for (int i = 0; i < segments.size();) {
            boolean take = true;
            Segment seg = segments.get(i);

            i++;
            for (int j = i; j < segments.size(); j++) {
                Segment seg2 = segments.get(j);
                if (seg2.start > seg.end) {
                    i = j;
                    break;
                }
                if (seg2.value > seg.value) {
                    take = false;
                    break;
                }
            }

            if (take) {
                revenue = revenue.flipBit(seg.value);
            }
        }

        return revenue;
    }
}


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

public class Program implements Runnable {
    public static void main(String[] args) throws Exception {
        Scanner in = new Scanner(System.in);
        PrintWriter out = new PrintWriter(System.out);
        Thread thread = new Thread(new Program(in, out));
        thread.start();
        thread.join();
    }

    final Scanner in;
    final PrintWriter out;

    Program(Scanner in, PrintWriter out) {
        this.in = in;
        this.out = out;
    }

    public void run() {
        out.println(solve());
        out.flush();
    }

    class Segment implements Comparable<Segment> {
        final int value;
        final int start;
        final int end;

        public Segment(int value, int start, int end) {
            this.value = value;
            this.start = start;
            this.end = end;
        }

        public int compareTo(Segment other) {
            return this.start - other.start;
        }
    }

    BigInteger solve() {
        final int MAX_MEMORY = 2000;
        List<Segment> segments = new ArrayList<Segment>();
        int[] latestWins = new int[MAX_MEMORY + 1];
        Arrays.fill(latestWins, -1);
        int n = in.nextInt();
        for (int i = 0; i < n; i++) {
            String action = in.next();
            int mem = in.nextInt();
            if (action.equals("win")) {
                latestWins[mem] = i;
            } else {
                int start = latestWins[mem];
                if (start != -1) {
                    segments.add(new Segment(mem, start, i));
                }
            }
        }

        Collections.sort(segments);

        BigInteger revenue = BigInteger.ZERO;

        for (int i = 0; i < segments.size();) {
            boolean take = true;
            Segment seg = segments.get(i);

            int j = i + 1;
            while (j < segments.size()) {
                Segment seg2 = segments.get(j);
                if (seg2.start > seg.end) {
                    break;
                }
                if (seg2.value > seg.value) {
                    take = false;
                    break;
                }
                j++;
            }

            if (take) {
                i = j;
                revenue = revenue.setBit(seg.value);
            } else {
                i++;
            }
        }

        return revenue;
    }
}


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

public class Program implements Runnable {
    public static void main(String[] args) throws Exception {
        Scanner in = new Scanner(System.in);
        PrintWriter out = new PrintWriter(System.out);
        Thread thread = new Thread(new Program(in, out));
        thread.start();
        thread.join();
    }

    final Scanner in;
    final PrintWriter out;

    Program(Scanner in, PrintWriter out) {
        this.in = in;
        this.out = out;
    }

    public void run() {
        out.println(solve());
        out.flush();
    }

    class Segment implements Comparable<Segment> {
        final int value;
        final int start;
        final int end;

        public Segment(int value, int start, int end) {
            this.value = value;
            this.start = start;
            this.end = end;
        }

        public int compareTo(Segment other) {
            return this.start - other.start;
        }
    }

    BigInteger solve() {
        final int MAX_MEMORY = 2000;
        List<Segment> segments = new ArrayList<Segment>();
        int[] latestWins = new int[MAX_MEMORY];
        Arrays.fill(latestWins, -1);
        int n = in.nextInt();
        for (int i = 0; i < n; i++) {
            String action = in.next();
            int mem = in.nextInt();
            if (action.equals("win")) {
                latestWins[mem] = i;
            } else {
                int start = latestWins[mem];
                if (start != -1) {
                    segments.add(new Segment(mem, start, i));
                }
            }
        }

        Collections.sort(segments);

        BigInteger revenue = BigInteger.ZERO;

        for (int i = 0; i < segments.size();) {
            boolean take = true;
            Segment seg = segments.get(i);

            int nextValid = i + 1;
            for (int j = i + 1; j < segments.size(); j++) {
                Segment seg2 = segments.get(j);
                if (seg2.start > seg.end) {
                    nextValid = j;
                    break;
                }
                if (seg2.value > seg.value) {
                    take = false;
                    break;
                }
            }

            if (take) {
                i = nextValid;
                revenue = revenue.flipBit(seg.value);
            } else {
                i++;
            }
        }

        return revenue;
    }
}


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

public class Program implements Runnable {
    public static void main(String[] args) throws Exception {
        Scanner in = new Scanner(System.in);
        PrintWriter out = new PrintWriter(System.out);
        Thread thread = new Thread(new Program(in, out));
        thread.start();
        thread.join();
    }

    final Scanner in;
    final PrintWriter out;

    Program(Scanner in, PrintWriter out) {
        this.in = in;
        this.out = out;
    }

    public void run() {
        out.println(solve());
        out.flush();
    }

    class Segment implements Comparable<Segment> {
        final int value;
        final int start;
        final int end;

        public Segment(int value, int start, int end) {
            this.value = value;
            this.start = start;
            this.end = end;
        }

        public int compareTo(Segment other) {
            //return this.start - other.start;
            return this.value - other.value;
        }

        public boolean intersects(Segment other) {
            boolean left = other.end < this.start;
            boolean right = other.start > this.end;
            return !(left || right);
        }

        public String toString() {
            return "" + value + "(" + start + ", " + end +")";
        }
    }

    BigInteger solve() {
        final int MAX_MEMORY = 2000;
        List<Segment> segments = new ArrayList<Segment>();
        int[] latestWins = new int[MAX_MEMORY + 1];
        Arrays.fill(latestWins, -1);
        int n = in.nextInt();
        for (int i = 0; i < n; i++) {
            String action = in.next();
            int mem = in.nextInt();
            if (action.equals("win")) {
                latestWins[mem] = i;
            } else {
                int start = latestWins[mem];
                if (start != -1) {
                    segments.add(new Segment(mem, start, i));
                }
            }
        }

        Collections.sort(segments);

        BigInteger revenue = BigInteger.ZERO;

        // for (int i = 0; i < segments.size();) {
        //     boolean take = true;
        //     Segment seg = segments.get(i);

        //     int j = i + 1;
        //     while (j < segments.size()) {
        //         Segment seg2 = segments.get(j);
        //         if (seg2.start > seg.end) {
        //             break;
        //         }
        //         if (seg2.value > seg.value) {
        //             take = false;
        //             break;
        //         }
        //         j++;
        //     }

        //     if (take) {
        //         i = j;
        //         revenue = revenue.setBit(seg.value);
        //     } else {
        //         i++;
        //     }
        // }

        List<Segment> taken = new ArrayList<Segment>();
        for (int i = segments.size() - 1; i >= 0; i--) {
            boolean take = true;
            Segment seg = segments.get(i);

            for (Segment seg2 : taken) {
                if (seg.intersects(seg2)) {
                    take = false;
                    break;
                }
                // out.printf("%s does not intersect with %s\n", seg, seg2);
            }

            // out.printf("%s : %s\n", seg, take);
            if (take) {
                taken.add(seg);
                revenue = revenue.setBit(seg.value);
            }
        }

        return revenue;
    }
}


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

public class Program implements Runnable {
    public static void main(String[] args) throws Exception {
        Scanner in = new Scanner(System.in);
        PrintWriter out = new PrintWriter(System.out);
        Thread thread = new Thread(new Program(in, out));
        thread.start();
        thread.join();
    }

    final Scanner in;
    final PrintWriter out;

    Program(Scanner in, PrintWriter out) {
        this.in = in;
        this.out = out;
    }

    public void run() {
        out.println(solve());
        out.flush();
    }

    class Segment implements Comparable<Segment> {
        final int value;
        final int start;
        final int end;

        public Segment(int value, int start, int end) {
            this.value = value;
            this.start = start;
            this.end = end;
        }

        public int compareTo(Segment other) {
            //return this.start - other.start;
            return this.value - other.value;
        }

        public boolean intersects(Segment other) {
            return other.start > start && other.start < end
                || other.end > start && other.end < end;
        }
    }

    BigInteger solve() {
        final int MAX_MEMORY = 2000;
        List<Segment> segments = new ArrayList<Segment>();
        int[] latestWins = new int[MAX_MEMORY + 1];
        Arrays.fill(latestWins, -1);
        int n = in.nextInt();
        for (int i = 0; i < n; i++) {
            String action = in.next();
            int mem = in.nextInt();
            if (action.equals("win")) {
                latestWins[mem] = i;
            } else {
                int start = latestWins[mem];
                if (start != -1) {
                    segments.add(new Segment(mem, start, i));
                }
            }
        }

        Collections.sort(segments);

        BigInteger revenue = BigInteger.ZERO;

        // for (int i = 0; i < segments.size();) {
        //     boolean take = true;
        //     Segment seg = segments.get(i);

        //     int j = i + 1;
        //     while (j < segments.size()) {
        //         Segment seg2 = segments.get(j);
        //         if (seg2.start > seg.end) {
        //             break;
        //         }
        //         if (seg2.value > seg.value) {
        //             take = false;
        //             break;
        //         }
        //         j++;
        //     }

        //     if (take) {
        //         i = j;
        //         revenue = revenue.setBit(seg.value);
        //     } else {
        //         i++;
        //     }
        // }

        List<Segment> taken = new ArrayList<Segment>();
        for (int i = segments.size() - 1; i >= 0; i--) {
            boolean take = true;
            Segment seg = segments.get(i);

            for (Segment seg2 : taken) {
                if (seg.intersects(seg2)) {
                    take = false;
                    break;
                }
            }

            if (take) {
                taken.add(seg);
                revenue = revenue.setBit(seg.value);
            }
        }

        return revenue;
    }
}


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

public class Program implements Runnable {
    public static void main(String[] args) throws Exception {
        Scanner in = new Scanner(System.in);
        PrintWriter out = new PrintWriter(System.out);
        Thread thread = new Thread(new Program(in, out));
        thread.start();
        thread.join();
    }

    final Scanner in;
    final PrintWriter out;

    Program(Scanner in, PrintWriter out) {
        this.in = in;
        this.out = out;
    }

    public void run() {
        out.println(solve());
        out.flush();
    }

    class Segment implements Comparable<Segment> {
        final int value;
        final int start;
        final int end;

        public Segment(int value, int start, int end) {
            this.value = value;
            this.start = start;
            this.end = end;
        }

        public int compareTo(Segment other) {
            return this.start - other.start;
        }
    }

    BigInteger solve() {
        final int MAX_MEMORY = 2000;
        List<Segment> segments = new ArrayList<Segment>();
        int[] latestWins = new int[MAX_MEMORY + 1];
        Arrays.fill(latestWins, -1);
        int n = in.nextInt();
        for (int i = 0; i < n; i++) {
            String action = in.next();
            int mem = in.nextInt();
            if (action.equals("win")) {
                latestWins[mem] = i;
            } else {
                int start = latestWins[mem];
                if (start != -1) {
                    segments.add(new Segment(mem, start, i));
                }
            }
        }

        Collections.sort(segments);

        BigInteger revenue = BigInteger.ZERO;

        for (int i = 0; i < segments.size();) {
            boolean take = true;
            Segment seg = segments.get(i);

            i++;
            int j = i;
            for (j = i; j < segments.size(); j++) {
                Segment seg2 = segments.get(j);
                if (seg2.start > seg.end) {
                    break;
                }
                if (seg2.value > seg.value) {
                    take = false;
                    break;
                }
            }

            if (take) {
                i = j;
                revenue = revenue.flipBit(seg.value);
            }
        }

        return revenue;
    }
}


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

public class Program implements Runnable {
    public static void main(String[] args) throws Exception {
        Scanner in = new Scanner(System.in);
        PrintWriter out = new PrintWriter(System.out);
        Thread thread = new Thread(new Program(in, out));
        thread.start();
        thread.join();
    }

    final Scanner in;
    final PrintWriter out;

    Program(Scanner in, PrintWriter out) {
        this.in = in;
        this.out = out;
    }

    public void run() {
        out.println(solve());
        out.flush();
    }

    class Segment implements Comparable<Segment> {
        final int value;
        final int start;
        final int end;

        public Segment(int value, int start, int end) {
            this.value = value;
            this.start = start;
            this.end = end;
        }

        public int compareTo(Segment other) {
            return this.start - other.start;
        }
    }

    BigInteger solve() {
        final int MAX_MEMORY = 2000;
        List<Segment> segments = new ArrayList<Segment>();
        int[] latestWins = new int[MAX_MEMORY];
        Arrays.fill(latestWins, -1);
        int n = in.nextInt();
        for (int i = 0; i < n; i++) {
            String action = in.next();
            int mem = in.nextInt();
            if (action.equals("win")) {
                latestWins[mem] = i;
            } else {
                int start = latestWins[mem];
                if (start != -1) {
                    segments.add(new Segment(mem, start, i));
                }
            }
        }

        BigInteger revenue = BigInteger.ZERO;

        for (int i = 0; i < segments.size();) {
            boolean take = true;
            Segment seg = segments.get(i);

            int nextValid = i + 1;
            for (int j = i + 1; j < segments.size(); j++) {
                Segment seg2 = segments.get(j);
                if (seg2.start > seg.end) {
                    nextValid = j;
                    break;
                }
                if (seg2.value > seg.value) {
                    take = false;
                    break;
                }
            }

            if (take) {
                i = nextValid;
                revenue = revenue.flipBit(seg.value);
            } else {
                i++;
            }
        }

        return revenue;
    }
}


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

public class Program implements Runnable {
    public static void main(String[] args) throws Exception {
        Scanner in = new Scanner(System.in);
        PrintWriter out = new PrintWriter(System.out);
        Thread thread = new Thread(new Program(in, out));
        thread.start();
        thread.join();
    }

    final Scanner in;
    final PrintWriter out;

    Program(Scanner in, PrintWriter out) {
        this.in = in;
        this.out = out;
    }

    public void run() {
        out.println(solve());
        out.flush();
    }

    class Segment implements Comparable<Segment> {
        final int value;
        final int start;
        final int end;

        public Segment(int value, int start, int end) {
            this.value = value;
            this.start = start;
            this.end = end;
        }

        public int compareTo(Segment other) {
            return this.start - other.start;
        }
    }

    BigInteger solve() {
        final int MAX_MEMORY = 2000;
        List<Segment> segments = new ArrayList<Segment>();
        int[] latestWins = new int[MAX_MEMORY + 1];
        Arrays.fill(latestWins, -1);
        int n = in.nextInt();
        for (int i = 0; i < n; i++) {
            String action = in.next();
            int mem = in.nextInt();
            if (action.equals("win")) {
                latestWins[mem] = i;
            } else {
                int start = latestWins[mem];
                if (start != -1) {
                    segments.add(new Segment(mem, start, i));
                }
            }
        }

        Collections.sort(segments);

        BigInteger revenue = BigInteger.ZERO;

        for (int i = 0; i < segments.size();) {
            boolean take = true;
            Segment seg = segments.get(i);

            int nextValid = i + 1;
            for (int j = i + 1; j < segments.size(); j++) {
                Segment seg2 = segments.get(j);
                if (seg2.start > seg.end) {
                    nextValid = j;
                    break;
                }
                if (seg2.value > seg.value) {
                    take = false;
                    break;
                }
            }

            if (take) {
                i = nextValid;
                revenue = revenue.flipBit(seg.value);
            } else {
                i++;
            }
        }

        return revenue;
    }
}


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

public class Program implements Runnable {
    public static void main(String[] args) throws Exception {
        Scanner in = new Scanner(System.in);
        PrintWriter out = new PrintWriter(System.out);
        Thread thread = new Thread(new Program(in, out));
        thread.start();
        thread.join();
    }

    final Scanner in;
    final PrintWriter out;

    Program(Scanner in, PrintWriter out) {
        this.in = in;
        this.out = out;
    }

    public void run() {
        out.println(solve());
        out.flush();
    }

    class Segment implements Comparable<Segment> {
        final int value;
        final int start;
        final int end;

        public Segment(int value, int start, int end) {
            this.value = value;
            this.start = start;
            this.end = end;
        }

        public int compareTo(Segment other) {
            return this.start - other.start;
        }
    }

    BigInteger solve() {
        final int MAX_MEMORY = 2000;
        List<Segment> segments = new ArrayList<Segment>();
        int[] latestWins = new int[MAX_MEMORY + 1];
        Arrays.fill(latestWins, -1);
        int n = in.nextInt();
        for (int i = 0; i < n; i++) {
            String action = in.next();
            int mem = in.nextInt();
            if (action.equals("win")) {
                latestWins[mem] = i;
            } else {
                int start = latestWins[mem];
                if (start != -1) {
                    segments.add(new Segment(mem, start, i));
                }
            }
        }

        Collections.sort(segments);

        BigInteger revenue = BigInteger.ZERO;

        for (int i = 0; i < segments.size();) {
            boolean take = true;
            Segment seg = segments.get(i);

            i++;
            int j = i + 1;
            for (j = i; j < segments.size(); j++) {
                Segment seg2 = segments.get(j);
                if (seg2.start > seg.end) {
                    break;
                }
                if (seg2.value > seg.value) {
                    take = false;
                    break;
                }
            }

            if (take) {
                i = j;
                revenue = revenue.flipBit(seg.value);
            }
        }

        return revenue;
    }
}


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

public class D implements Runnable {
	BufferedReader in;
	PrintWriter out;
	StringTokenizer st;
	Random rnd;

	final int none = 2001;
	BigInteger[][] d;
	BigInteger[] pows;

	BigInteger getMax(BigInteger a, BigInteger b) {
		if(a == null) {
			return b;
		} else if(b == null) {
			return a;
		} else if(a.compareTo(b) > 0) {
			return a;
		} else {
			return b;
		}
	}

	void solve() throws IOException {
		int n = nextInt();

		pows = new BigInteger[none];

		for(int i = 0; i < none; i++) {
			pows[i] = BigInteger.valueOf(2).pow(i);
		}

		d = new BigInteger[n + 1][none + 1];
		d[0][none] = BigInteger.ZERO;

		for(int i = 1; i <= n; i++) {
			String act = nextToken();
			int x = nextInt();

			BigInteger lastMaxValue = null;

			for(int j = 0; j <= none; j++) {
				d[i][j] = d[i - 1][j];
				lastMaxValue = getMax(lastMaxValue, d[i][j]);
			}

			if(act.equals("win")) {
				d[i][x] = lastMaxValue;
			} else if(act.equals("sell")) {
				if(d[i][x] != null) {

					d[i][none] = getMax(d[i][none], d[i][x].add(pows[x]));
				}

			} else {
				throw new AssertionError();
			}
		}

		BigInteger res = getMax(BigInteger.ZERO, d[n][none]);

		out.println(res);
	}

	public static void main(String[] args) {
		final boolean oldChecker = false;

		if(oldChecker) {
			new Thread(null, new D(), "yarrr", 1 << 24).start();
		} else {

			new D().run();
		}
	}

	public void run() {
		try {
			final String className = this.getClass().getName().toLowerCase();

			try {
				in = new BufferedReader(new FileReader(className + ".in"));
				out = new PrintWriter(new FileWriter(className + ".out"));
			} catch (FileNotFoundException e) {
				in = new BufferedReader(new InputStreamReader(System.in));
				out = new PrintWriter(System.out);
			}

			rnd = new Random();

			solve();

			out.close();
		} catch (IOException e) {
			e.printStackTrace();
			System.exit(42);
		}
	}

	String nextToken() throws IOException {
		while (st == null || !st.hasMoreTokens()) {
			String line = in.readLine();

			if (line == null) {
				return null;
			}

			st = new StringTokenizer(line);
		}

		return st.nextToken();
	}

	int nextInt() throws IOException {
		return Integer.parseInt(nextToken());
	}

	long nextLong() throws IOException {
		return Long.parseLong(nextToken());
	}

	double nextDouble() throws IOException {
		return Double.parseDouble(nextToken());
	}
}


import java.math.BigInteger;
import java.util.LinkedList;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);

        final int SIZE = 2001;
        int N = in.nextInt();
        int[] sell = new int[SIZE];
        int[] win = new int[SIZE];
        boolean[] take = new boolean[SIZE];
        LinkedList<Integer> ranges = new LinkedList<Integer>();

        String word;
        int x;

        for (int i = 1; i <= N; ++i) {
            word = in.next();
            x = in.nextInt();
            if (word.equals("sell")) {
                if (win[x] > 0) {
                    sell[x] = i;
                    take[x] = true;
                }
            } else {
                if (take[x] == false)
                    win[x] = i;
            }
        }

        boolean yeap = false;
        BigInteger sum = new BigInteger("0");
        BigInteger base = new BigInteger("2");
        for (int i = 2000; i >= 0; --i) {
            if (take[i]) {
                yeap = true;
                for (int j : ranges)
                    if (!((win[i] < win[j] && sell[i] < win[j]) || (win[i] > sell[j] && sell[i] > sell[j]))) {
                        yeap = false;
                        break;
                    }
                if (yeap) {
                    sum = sum.add(base.pow(i));
                    ranges.add(i);
                }
            }
        }

        System.out.print(sum);
    }
}


import java.util.LinkedList;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);

        final int SIZE = 2001;
        int N = in.nextInt();
        int[] sell = new int[SIZE];
        int[] win = new int[SIZE];
        boolean[] take = new boolean[SIZE];
        LinkedList<Integer> ranges = new LinkedList<Integer>();

        String word;
        int x;

        for (int i = 1; i <= N; ++i) {
            word = in.next();
            x = in.nextInt();
            if (word.equals("sell")) {
                if (win[x] > 0) {
                    sell[x] = i;
                    take[x] = true;
                }
            } else {
                if (take[x] == false)
                    win[x] = i;
            }
        }

        boolean yeap = false;
        int sum = 0;
        for (int i = 2000; i >= 0; --i) {
            if (take[i]) {
                yeap = true;
                for (int j : ranges)
                    if (!((win[i] < win[j] && sell[i] < win[j]) || (win[i] > sell[j] && sell[i] > sell[j]))) {
                        yeap = false;
                        break;
                    }
                if (yeap) {
                    sum += Math.pow(2, i);
                    ranges.add(i);
                }
            }
        }

        System.out.print(sum);
    }
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.math.BigInteger;
import java.util.StringTokenizer;

public class SellerBob {

	static int[] t;
	static int[] v;
	static BigInteger[][] dp;

	static BigInteger max(BigInteger a, BigInteger b) {
		return a.compareTo(b) > 0 ? a : b;
	}

	static BigInteger pow(int x) {
		if (x == 0)
			return BigInteger.ONE;
		if (x % 2 == 1)
			return BigInteger.valueOf(2).multiply(pow(x - 1));
		BigInteger res = pow(x / 2);
		return res.multiply(res);
	}

	static BigInteger solve(int i, int x) {
		if (i == t.length)
			return BigInteger.ZERO;
		if (dp[i][x + 1] != null)
			return dp[i][x + 1];
		if (t[i] == 0)
			return dp[i][x + 1] = max(solve(i + 1, v[i]), solve(i + 1, x));
		BigInteger ans = solve(i + 1, x);
		if (v[i] == x)
			ans = max(ans, pow(x).add(solve(i + 1, -1)));
		return dp[i][x + 1] = ans;
	}

	public static void main(String[] args) throws IOException {
		br = new BufferedReader(new InputStreamReader(System.in));
		out = new PrintWriter(System.out);
		sc = new StringTokenizer("");
		int n = nxtInt();
		t = new int[n];
		v = new int[n];
		for (int i = 0; i < n; i++) {
			if (nxtTok().equals("win"))
				t[i] = 0;
			else
				t[i] = 1;
			v[i] = nxtInt();
		}
		dp = new BigInteger[n][2002];
		out.println(solve(0, -1));
		br.close();
		out.close();
	}

	static BufferedReader br;
	static StringTokenizer sc;
	static PrintWriter out;

	static String nxtTok() throws IOException {
		while (!sc.hasMoreTokens()) {
			String s = br.readLine();
			if (s == null)
				return null;
			sc = new StringTokenizer(s.trim());
		}
		return sc.nextToken();
	}

	static int nxtInt() throws IOException {
		return Integer.parseInt(nxtTok());
	}

	static long nxtLng() throws IOException {
		return Long.parseLong(nxtTok());
	}

	static double nxtDbl() throws IOException {
		return Double.parseDouble(nxtTok());
	}

	static int[] nxtIntArr(int n) throws IOException {
		int[] a = new int[n];
		for (int i = 0; i < n; i++)
			a[i] = nxtInt();
		return a;
	}

	static long[] nxtLngArr(int n) throws IOException {
		long[] a = new long[n];
		for (int i = 0; i < n; i++)
			a[i] = nxtLng();
		return a;
	}

	static char[] nxtCharArr() throws IOException {
		return nxtTok().toCharArray();
	}
}


import java.util.Scanner;
import java.math.BigInteger;
import java.io.*;

public class Main {
    public static void main(String[] args) {
        Scanner cin = new Scanner(System.in);
        int n = cin.nextInt();
        String []op = new String[n];
        int []val = new int[n];
        BigInteger []dp = new BigInteger[n];
        BigInteger TWO = BigInteger.valueOf(2);
        int i, j;
        for(int i = 0; i <= n; ++i)
        {
            op[i] = cin.next();
            val[i] = cin.nextInt();
        }
        dp[0] = BigInteger.ZERO;
        for(i = 1; i < n; ++i) {
            dp[i] = dp[i-1];
            if(op[i].length() == 4)
                for(j = i - 1; j >= 0; --j)
                    if(val[i] == val[j] && op[j].length() == 3)
                        dp[i] = dp[i].max(dp[j].add(TWO.pow(val[j])));
        }
        System.out.println(dp[n - 1]);
    }
}


import java.util.Scanner;
import java.math.BigInteger;
import java.io.*;

public class Main {
    public static void main(String[] args) {
        Scanner cin = new Scanner(System.in);
        int n = cin.nextInt();
        String []op = new String[n];
        int []val = new int[n];
        BigInteger []dp = new BigInteger[n];
        BigInteger TWO = BigInteger.valueOf(2);
        for(int i = 0; i <= n; ++i)
        {
            op[i] = cin.next();
            val[i] = cin.nextInt();
        }
        dp[0] = BigInteger.ZERO;
        for(i = 1; i < n; ++i) {
            dp[i] = dp[i-1];
            if(op[i].length() == 4)
                for(j = i - 1; j >= 0; --j)
                    if(val[i] == val[j] && op[j].length() == 3)
                        dp[i] = dp[i].max(dp[j].add(TWO.pow(val[j])));
        }
        System.out.println(dp[n - 1]);
    }
}


import java.util.Scanner;
import java.math.BigInteger;
import java.io.*;

public class Main {
    public static void main(String[] args) {
        Scanner cin = new Scanner(System.in);
        int n = cin.nextInt();
        String []op = new String[n];
        int []val = new int[n];
        BigInteger []dp = new BigInteger[n];
        BigInteger TWO = BigInteger.valueOf(2);
        int i, j;
        for(i = 0; i <= n; ++i)
        {
            op[i] = cin.next();
            val[i] = cin.nextInt();
        }
        dp[0] = BigInteger.ZERO;
        for(i = 1; i < n; ++i) {
            dp[i] = dp[i-1];
            if(op[i].length() == 4)
                for(j = i - 1; j >= 0; --j)
                    if(val[i] == val[j] && op[j].length() == 3)
                        dp[i] = dp[i].max(dp[j].add(TWO.pow(val[j])));
        }
        System.out.println(dp[n - 1]);
    }
}


import java.util.Scanner;
import java.math.BigInteger;
import java.io.*;

public class Main {
    public static void main(String[] args) {
        Scanner cin = new Scanner(System.in);
        int n = cin.nextInt();
        String []op = new String[n];
        int []val = new int[n];
        BigInteger []dp = new BigInteger[n];
        BigInteger TWO = BigInteger.valueOf(2);
        int i, j;
        for(i = 0; i < n; ++i)
        {
            op[i] = cin.next();
            val[i] = cin.nextInt();
        }
        dp[0] = BigInteger.ZERO;
        for(i = 1; i < n; ++i) {
            dp[i] = dp[i - 1];
            if(op[i].length() == 4)
                for(j = i - 1; j >= 0; --j)
                    if(val[i] == val[j] && op[j].length() == 3)
                        dp[i] = dp[i].max(dp[j].add(TWO.pow(val[j])));
        }
        System.out.println(dp[n - 1]);
    }
}


import java.math.BigInteger;
import java.util.Scanner;

public class Main {

    static Scanner sc = new Scanner(System.in);
    static int n,v[],ty[];
    //static BigInteger dp[]= new BigInteger[5009];
    static BigInteger dp[][]= new BigInteger[2][2010];
    /*static BigInteger solve(int i,int l)
    {
        if(i==n) return BigInteger.ZERO;
        if(!dp[i][l].equals(new BigInteger("-1"))) return dp[i][l];
        if(ty[i]==0) dp[i][l]=solve(i+1,l).max(solve(i+1,v[i]));
        else if(l==v[i]) dp[i][l]=solve(i+1,n+1).add(new BigInteger("2").pow(l));
        else dp[i][l]=BigInteger.ZERO;
        return dp[i][l];
    }*/
    public static void main(String[] args) {
        n= sc.nextInt();
        v = new int[n];
        ty = new int [n];
        for (int i = 0; i < n; i++) {
            String s = sc.next();
            int r = sc.nextInt();
            ty[i]=((s.charAt(0)=='s')?1:0);
            v[i]=r;

        }
        for (int i = 0; i < 2010; i++) {
            dp[n%2][i]=BigInteger.ZERO;
        }
        for (int i = n-1; i >= 0; i--) {
            for (int j = 0; j < 2010; j++) {
                if(ty[i]==0){//win
                    dp[i%2][j]=dp[(i+1)%2][j].max(dp[(i+1)%2][v[i]]);
                }
                else if(v[i]==j){
                    //System.out.println(j);
                    dp[i%2][j]=dp[(i+1)%2][2001].add(new BigInteger("2").pow(j));
                }
                else dp[i%2][j]=dp[(1+i)%2][j];
            }
        }
        /*BigInteger an=BigInteger.ZERO;
        for (int i = n; i >= 0; i--) {
            an=dp[0][i].max(an);
        }*/
        System.out.println(dp[0][2001]);
        /*
        dp[0]=BigInteger.ZERO;
        for (int i = 1; i < n; i++) {
            if(ty[i]==0){
                dp[i]=dp[i-1];
            }
            else{
                dp[i]=dp[i-1];
                for(int j=0;j<i;j++){
                    if(ty[j]==0&&v[j]==v[i]){
                        dp[i]=dp[i].max(dp[j].add(new BigInteger("2").pow(v[j])));
                    }
                }
            }
        }*/
        //System.out.println(dp[n-1]);
    }

}


import java.math.BigInteger;
import java.util.Scanner;

public class Main {

	static Scanner sc = new Scanner(System.in);
	static int n,v[],ty[];
	//static BigInteger dp[]= new BigInteger[5009];
	static BigInteger dp[][]= new BigInteger[2][2010];
	/*static BigInteger solve(int i,int l)
	{
		if(i==n) return BigInteger.ZERO;
		if(!dp[i][l].equals(new BigInteger("-1"))) return dp[i][l];
		if(ty[i]==0) dp[i][l]=solve(i+1,l).max(solve(i+1,v[i]));
		else if(l==v[i]) dp[i][l]=solve(i+1,n+1).add(new BigInteger("2").pow(l));
		else dp[i][l]=BigInteger.ZERO;
		return dp[i][l];
	}*/
	public static void main(String[] args) {
		n= sc.nextInt();
		v = new int[n];
		ty = new int [n];
		for (int i = 0; i < n; i++) {
			String s = sc.next();
			int r = sc.nextInt();
			ty[i]=((s.charAt(0)=='s')?1:0);
			v[i]=r;

		}
		for (int i = 0; i < 2002; i++) {
			dp[n%2][i]=BigInteger.ZERO;
		}
		for (int i = n-1; i >= 0; i--) {
			for (int j = 0; j < 2002; j++) {
				if(ty[i]==0){//win
					dp[i%2][j]=dp[(i+1)%2][j].max(dp[(i+1)%2][v[i]]);
				}
				else if(v[i]==j){
					//System.out.println(j);
					dp[i%2][j]=dp[(i+1)%2][2001].add(new BigInteger("2").pow(j));
				}
				else dp[i%2][j]=dp[(1+i)%2][j];
			}
		}
		/*BigInteger an=BigInteger.ZERO;
		for (int i = n; i >= 0; i--) {
			an=dp[0][i].max(an);
		}*/
		System.out.println(dp[0][2001]);
		/*
		dp[0]=BigInteger.ZERO;
		for (int i = 1; i < n; i++) {
			if(ty[i]==0){
				dp[i]=dp[i-1];
			}
			else{
				dp[i]=dp[i-1];
				for(int j=0;j<i;j++){
					if(ty[j]==0&&v[j]==v[i]){
						dp[i]=dp[i].max(dp[j].add(new BigInteger("2").pow(v[j])));
					}
				}
			}
		}*/
		//System.out.println(dp[n-1]);
	}

}


import java.math.BigInteger;
import java.util.Scanner;

public class Main {

    static Scanner sc = new Scanner(System.in);
    static int n,v[],ty[];
    static BigInteger dp[]= new BigInteger[5009];
    /*static BigInteger solve(int i,int l)
    {
        if(i==n) return BigInteger.ZERO;
        if(!dp[i][l].equals(new BigInteger("-1"))) return dp[i][l];
        if(ty[i]==0) dp[i][l]=solve(i+1,l).max(solve(i+1,v[i]));
        else if(l==v[i]) dp[i][l]=solve(i+1,n+1).add(new BigInteger("2").pow(l));
        else dp[i][l]=BigInteger.ZERO;
        return dp[i][l];
    }*/
    public static void main(String[] args) {
        n= sc.nextInt();
        v = new int[n];
        ty = new int [n];
        for (int i = 0; i < n; i++) {
            String s = sc.next();
            int r = sc.nextInt();
            ty[i]=((s.charAt(0)=='s')?1:0);
            v[i]=r;

        }
        /*for (int i = 0; i < 2010; i++) {
            dp[n%2][i]=BigInteger.ZERO;
        }
        for (int i = n-1; i >= 0; i--) {
            for (int j = 0; j < 2010; j++) {
                if(ty[i]==0){//win
                    dp[i%2][j]=dp[(i+1)%2][j].max(dp[(i+1)%2][v[i]]);
                }
                else if(v[i]==j){
                    //System.out.println(j);
                    dp[i%2][j]=dp[(i+1)%2][2001].add(new BigInteger("2").pow(j));
                }
                else dp[i%2][j]=BigInteger.ZERO;
            }
        }
        BigInteger an=BigInteger.ZERO;
        for (int i = n; i >= 0; i--) {
            an=dp[0][i].max(an);
        }
        **/
        dp[0]=BigInteger.ZERO;
        for (int i = 1; i < n; i++) {
            if(ty[i]==0){
                dp[i]=dp[i-1];
            }
            else{
                dp[i]=dp[i-1];
                for(int j=0;j<i;j++){
                    if(ty[j]==0&&v[j]==v[i]){
                        dp[i]=dp[i].max(dp[j].add(new BigInteger("2").pow(v[j])));
                    }
                }
            }
        }
        System.out.println(dp[n-1]);
    }

}


import java.math.BigInteger;
import java.util.Scanner;

public class Main {

    static Scanner sc = new Scanner(System.in);
    static int n,v[],ty[];
    //static BigInteger dp[]= new BigInteger[5009];
    static BigInteger dp[][]= new BigInteger[2][2010];
    /*static BigInteger solve(int i,int l)
    {
        if(i==n) return BigInteger.ZERO;
        if(!dp[i][l].equals(new BigInteger("-1"))) return dp[i][l];
        if(ty[i]==0) dp[i][l]=solve(i+1,l).max(solve(i+1,v[i]));
        else if(l==v[i]) dp[i][l]=solve(i+1,n+1).add(new BigInteger("2").pow(l));
        else dp[i][l]=BigInteger.ZERO;
        return dp[i][l];
    }*/
    public static void main(String[] args) {
        n= sc.nextInt();
        v = new int[n];
        ty = new int [n];
        for (int i = 0; i < n; i++) {
            String s = sc.next();
            int r = sc.nextInt();
            ty[i]=((s.charAt(0)=='s')?1:0);
            v[i]=r;

        }        for (int i = 0; i < 2002; i++) {
            dp[n%2][i]=BigInte0er.ZERO;
        }
        for (int i = n-1; i >= 0; i--) {
            for (int j = 0; j < 2002; j++) {
                if(ty[i]==0){//win
                    dp[i%2][j]=dp[(i+1)%2][j].max(dp[(i+1)%2][v[i]]);
                }
                else if(v[i]==j){
                    //System.out.println(j);
                    dp[i%2][j]=dp[(i+1)%2][2001].add(new BigInteger("2").pow(j));
                }
                else dp[i%2][j]=dp[(1+i)%2][j];
            }
        }
        /*BigInteger an=BigInteger.ZERO;
        for (int i = n; i >= 0; i--) {
            an=dp[0][i].max(an);
        }*/
        System.out.println(dp[0][2001]);
        /*
        dp[0]=BigInteger.ZERO;
        for (int i = 1; i < n; i++) {
            if(ty[i]==0){
                dp[i]=dp[i-1];
            }
            else{
                dp[i]=dp[i-1];
                for(int j=0;j<i;j++){
                    if(ty[j]==0&&v[j]==v[i]){
                        dp[i]=dp[i].max(dp[j].add(new BigInteger("2").pow(v[j])));
                    }
                }
            }
        }*/
        //System.out.println(dp[n-1]);
    }

}


import java.util.*;
import java.math.*;

public class Main {
    static BigInteger[] pot;
    static boolean sell[];
    static int x[];
    static BigInteger dp[][];
    static boolean ok[][];

    static ArrayList<Integer> P[];

    static BigInteger solve(int a, int b)
    {
        if(a >= b) return BigInteger.ZERO;

        if(ok[a][b]) return dp[a][b];

        ok[a][b] = true;

        BigInteger ans = solve(a, b-1);

        if(sell[b])
            for(int p : P[x[b]])
                if(p >= a)
                {
                    BigInteger tmp = pot[x[b]].add(solve(a,p-1));
                    if(ans.compareTo(tmp) < 0)
                        ans = tmp;
                }

        dp[a][b] = ans;
        return ans;

    }

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();

        pot = new BigInteger[2001];
        pot[0] = BigInteger.ONE;
        for(int i = 1; i < 2001; ++i)
            pot[i] = pot[i-1].multiply(BigInteger.valueOf(2));

        sell = new boolean[n];
        x = new int[n];
        dp = new BigInteger[n][n];
        ok = new boolean[n][n];

        P = new ArrayList[2001];
        for(int i = 0; i < 2001; ++i)
            P[i] = new ArrayList<Integer>();

        for(int i = 0; i < n; ++i)
        {
            String s = in.next();
            x[i] = in.nextInt();

            if(s.compareTo("sell") == 0)
                sell[i] = true;
            else P[x[i]].add(i);
        }

        System.out.println(solve(0,n-1));

    }

}


import java.util.*;
import java.math.*;

public class Main {
    static BigInteger[] pot;
    static boolean sell[];
    static int x[];
    static BigInteger dp[][];

    static ArrayList<Integer> P[];

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();

        pot = new BigInteger[2001];
        pot[0] = BigInteger.ONE;
        for(int i = 1; i < 2001; ++i)
            pot[i] = pot[i-1].multiply(BigInteger.valueOf(2));

        sell = new boolean[n];
        x = new int[n];
        dp = new BigInteger[n][n];

        P = new ArrayList[2001];
        for(int i = 0; i < 2001; ++i)
            P[i] = new ArrayList<Integer>();

        for(int i = 0; i < n; ++i)
        {
            String s = in.next();
            x[i] = in.nextInt();

            if(s.compareTo("sell") == 0)
                sell[i] = true;
            else P[x[i]].add(i);
        }

        for(int i = 0; i < n; ++i)
            for(int j = 0; j < n; ++j)
                dp[i][j] = BigInteger.ZERO;

        for(int b = 0; b < n; ++b)
            for(int a = 0; a < b; ++a)
            {
                if(b > 0) dp[a][b] = dp[a][b-1].add(BigInteger.ZERO);

                if(sell[b])
                {
                    for(int p : P[x[b]])
                        if(p >= a)
                        {
                            BigInteger tmp = pot[x[b]].add(BigInteger.ZERO);
                            if(p > 0) tmp = tmp.add(dp[a][p-1]);
                            if(dp[a][b].compareTo(tmp) < 0)
                                dp[a][b] = tmp.add(BigInteger.ZERO);
                        }
                }
            }

        System.out.println(dp[0][n-1]);

    }

}


import java.util.*;
import java.math.*;

public class Main {
    static BigInteger[] pot;
    static boolean sell[];
    static int x[];

    static int search(int p, int v)
    {
        for(int i = p; i >= 0; --i)
            if(sell[i] && x[i] == v)
                return i;
        return -1;
    }

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();

        pot = new BigInteger[2001];
        pot[0] = BigInteger.ONE;
        for(int i = 1; i < 2001; ++i)
            pot[i] = pot[i-1].multiply(BigInteger.valueOf(2));

        sell = new boolean[n];
        x = new int[n];

        for(int i = 0; i < n; ++i)
        {
            String s = in.next();
            x[i] = in.nextInt();

            if(s.compareTo("sell") == 0)
                sell[i] = true;
        }

        BigInteger ans = BigInteger.ZERO;

        int pos = n-1;

        for(int last = 2000; last >= 0; --last)
        {
            int tmp = search(pos, last);

            if(tmp == -1) continue;

            for(int i = tmp-1; i >= 0; --i)
                if(x[i] == last && !sell[i])
                {
                    ans = ans.add(BigInteger.valueOf(2).pow(last));
                    pos = i;
                    break;
                }
        }

        System.out.println(ans);

    }

}


import java.util.*;
import java.math.*;

public class Main {
	static BigInteger[] pot;
	static boolean sell[];
	static int x[];
	static BigInteger dp[][];

	static ArrayList<Integer> P[];

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();

		pot = new BigInteger[2001];
		pot[0] = BigInteger.ONE;
		for(int i = 1; i < 2001; ++i)
			pot[i] = pot[i-1].multiply(BigInteger.valueOf(2));

		sell = new boolean[n];
		x = new int[n];
		dp = new BigInteger[n][n];

		P = new ArrayList[2001];
		for(int i = 0; i < 2001; ++i)
			P[i] = new ArrayList<Integer>();

		for(int i = 0; i < n; ++i)
		{
			String s = in.next();
			x[i] = in.nextInt();

			if(s.compareTo("sell") == 0)
				sell[i] = true;
			else P[x[i]].add(i);
		}

		for(int i = 0; i < n; ++i)
			for(int j = 0; j < n; ++j)
				dp[i][j] = BigInteger.ZERO;

		for(int b = 1; b < n; ++b)
			for(int a = 0; a < b; ++a)
			{
				dp[a][b] = dp[a][b-1];

				if(sell[b])
				{
					for(int p : P[x[b]])
						if(p >= a)
						{
							BigInteger tmp = pot[x[b]];
							if(p > 0) tmp = tmp.add(dp[a][p-1]);
							if(dp[a][b].compareTo(tmp) < 0)
								dp[a][b] = tmp;
						}
				}
			}

		System.out.println(dp[0][n-1]);

	}

}


import java.util.*;
import java.math.*;

public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();

        String s[] = new String[n+1];
        int x[] = new int[n+1];
        BigInteger dp[] = new BigInteger[n+1];
        dp[0] = BigInteger.ZERO;

        for(int i = 1; i <= n; ++i)
        {
            s[i] = in.next();
            x[i] = in.nextInt();
            dp[i] = dp[i-1];

            if(s[i].compareTo("sell") == 0)
                for(int j = 1; j < i; ++j)
                    if(x[i] == x[j] && s[j].compareTo("win") == 0){
                        BigInteger tmp = dp[j-1];
                        tmp = tmp.add(BigInteger.valueOf(2).pow(x[i]));
                        if(tmp.compareTo(dp[i]) > 0)
                            dp[i] = tmp;
                    }
        }

        System.out.println(dp[n]);

    }

}


import java.util.*;
import java.math.*;

public class Main {
    static BigInteger[] pot;
    static boolean sell[];
    static int x[];

    static int search(int p, int v)
    {
        for(int i = p; i >= 0; --i)
            if(sell[i] && x[i] == v)
                return i;
        return -1;
    }

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();

        pot = new BigInteger[2001];
        pot[0] = BigInteger.ONE;
        for(int i = 1; i < 2001; ++i)
            pot[i] = pot[i-1].multiply(BigInteger.valueOf(2));

        sell = new boolean[n];
        x = new int[n];

        for(int i = 0; i < n; ++i)
        {
            String s = in.next();
            x[i] = in.nextInt();

            if(s.compareTo("sell") == 0)
                sell[i] = true;
        }

        BigInteger ans = BigInteger.ZERO;

        int pos = n-1;

        for(int last = 2000; last >= 0; --last)
        {
            int tmp = search(pos, last);

            if(tmp == -1) continue;

            for(int i = tmp-1; i >= 0; --i)
                if(x[i] == last && !sell[i])
                {
                    ans = ans.add(BigInteger.valueOf(2).pow(last));
                    pos = i-1;
                    break;
                }
        }

        System.out.println(ans);

    }

}


import java.util.*;
import java.math.*;

public class Main {
    static BigInteger[] pot;
    static boolean sell[];
    static int x[];
    static BigInteger dp[][];

    static ArrayList<Integer> P[];

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();

        pot = new BigInteger[2001];
        pot[0] = BigInteger.ONE;
        for(int i = 1; i < 2001; ++i)
            pot[i] = pot[i-1].multiply(BigInteger.valueOf(2));

        sell = new boolean[n];
        x = new int[n];
        dp = new BigInteger[n][n];

        P = new ArrayList[2001];
        for(int i = 0; i < 2001; ++i)
            P[i] = new ArrayList<Integer>();

        for(int i = 0; i < n; ++i)
        {
            String s = in.next();
            x[i] = in.nextInt();

            if(s.compareTo("sell") == 0)
                sell[i] = true;
            else P[x[i]].add(i);
        }

        for(int i = 0; i < n; ++i)
            for(int j = 0; j < n; ++j)
                dp[i][j] = BigInteger.ZERO;

        for(int b = 0; b < n; ++b)
            for(int a = 0; a <= b; ++a)
            {
                if(b > 0) dp[a][b] = dp[a][b-1];

                if(sell[b])
                {
                    for(int p : P[x[b]])
                        if(p >= a)
                        {
                            BigInteger tmp = pot[x[b]];
                            if(p > 0) tmp = tmp.add(dp[a][p-1]);
                            if(dp[a][b].compareTo(tmp) < 0)
                                dp[a][b] = tmp;
                        }
                }
            }

        System.out.println(dp[0][n-1]);

    }

}


import java.util.*;
import java.math.*;

public class Main {

    static int N = 5000;

    static BigInteger[] pot;
    static boolean sell[];
    static int x[];
    static BigInteger dp[][];
    static boolean ok[][];

    static ArrayList<Integer> P[];

    static BigInteger solve(int a, int b)
    {
        if(a >= b) return BigInteger.ZERO;

        if(ok[a][b]) return dp[a][b];

        ok[a][b] = true;

        BigInteger ans = solve(a, b-1);

        if(sell[b])
            for(int p : P[x[b]])
                if(p >= a)
                {
                    BigInteger tmp = pot[x[b]].add(solve(a,p-1));
                    if(ans.compareTo(tmp) < 0)
                        ans = tmp;
                }

        dp[a][b] = ans;
        return ans;

    }

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();

        pot = new BigInteger[N];
        pot[0] = BigInteger.ONE;
        for(int i = 1; i < N; ++i)
            pot[i] = pot[i-1].multiply(BigInteger.valueOf(2));

        sell = new boolean[N];
        x = new int[N];
        dp = new BigInteger[N][N];
        ok = new boolean[N][N];

        P = new ArrayList[N];
        for(int i = 0; i < N; ++i)
            P[i] = new ArrayList<Integer>();

        for(int i = 0; i < n; ++i)
        {
            String s = in.next();
            x[i] = in.nextInt();

            if(s.compareTo("sell") == 0)
                sell[i] = true;
            else P[x[i]].add(i);
        }

        System.out.println(solve(0,n-1));

    }

}