#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
#define all(c) c.begin(),c.end()
#define rep(i,a,b) for(int i=a;i<=b;++i)
#define tr(container,it) \
for(auto it=container.begin();it!=container.end();++it)
typedef long long ll ;
typedef vector<int> vi;
#define sz(x) int(x.size())
#define mod 1000000007
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;
ll exp(ll x,ll y){
  //x%=mod;
  ll res=1;
  while(y){
    if(y&1)
    res=res*x;//%mod;
    x=x*x;//%mod;
    y>>=1;
  }
  return res;
}
ll fact(ll n){
  ll res=1;
  for(ll i=2;i<=n;++i)
  (res*=i)%=mod;
  return res;
}
bool isprime(int n){
  for(int i=2;i*i<=n;++i)
  if(n%i==0) return 0;
  return 1;
}

int main()
{
//freopen("input.txt","r",stdin);
//freopen("output.txt","w",stdout);
//ios::sync_with_stdio(0);
//cin.tie(0);
int t;
cin>>t;
while(t--){
  int n;
  cin>>n;
  vi v(n);
  rep(i,0,n-1) cin>>v[i];
  int ans=0;
  for(int q=0;q<n;++q){
   int sum=0;
   int i=0,j=0;
   while(j<n){
    while(j<n&&sum+v[j]<=v[q]){
      sum+=v[j];
      ++j;
    }
    if(sum==v[q]){
      if(j-i-1>0){
        ++ans;
        break;
      }
      i=j;
      sum=0;
    }
    if(sum+v[j]>v[q]){
      sum-=v[i];
      ++i;
    }
   }
  }
  cout<<ans<<'\n';
}

    return 0;
}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
#define all(c) c.begin(),c.end()
#define rep(i,a,b) for(int i=a;i<=b;++i)
#define tr(container,it) \
for(auto it=container.begin();it!=container.end();++it)
typedef long long ll ;
typedef vector<int> vi;
#define sz(x) int(x.size())
#define mod 1000000007
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;
ll exp(ll x,ll y){
  //x%=mod;
  ll res=1;
  while(y){
    if(y&1)
    res=res*x;//%mod;
    x=x*x;//%mod;
    y>>=1;
  }
  return res;
}
ll fact(ll n){
  ll res=1;
  for(ll i=2;i<=n;++i)
  (res*=i)%=mod;
  return res;
}
bool isprime(int n){
  for(int i=2;i*i<=n;++i)
  if(n%i==0) return 0;
  return 1;
}

int main()
{
//freopen("input.txt","r",stdin);
//freopen("output.txt","w",stdout);
//ios::sync_with_stdio(0);
//cin.tie(0);
int t;
cin>>t;
while(t--){
  int n;
  cin>>n;
  vi v(n);
  rep(i,0,n-1) cin>>v[i];
  int ans=0;
  for(int q=0;q<n;++q){
   int sum=0;
   int i=0,j=0;
   while(j<=n+100){
     if(sum>v[q]){
       sum-=v[i];
       ++i;
     }
     if(sum<v[q]){
       sum+=v[j];
       ++j;
     }
     if(sum==v[q]){
       if(j-i-1>0){
         ++ans;
         break;
       }
       i=j;
       sum=0;
     }

   }
  }
  cout<<ans<<'\n';
}

    return 0;
}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
#define all(c) c.begin(),c.end()
#define rep(i,a,b) for(int i=a;i<=b;++i)
#define tr(container,it) \
for(auto it=container.begin();it!=container.end();++it)
typedef long long ll ;
typedef vector<int> vi;
#define sz(x) int(x.size())
#define mod 1000000007
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;
ll exp(ll x,ll y){
  //x%=mod;
  ll res=1;
  while(y){
    if(y&1)
    res=res*x;//%mod;
    x=x*x;//%mod;
    y>>=1;
  }
  return res;
}
ll fact(ll n){
  ll res=1;
  for(ll i=2;i<=n;++i)
  (res*=i)%=mod;
  return res;
}
bool isprime(int n){
  for(int i=2;i*i<=n;++i)
  if(n%i==0) return 0;
  return 1;
}

int main()
{
//freopen("input.txt","r",stdin);
//freopen("output.txt","w",stdout);
//ios::sync_with_stdio(0);
//cin.tie(0);
int t;
cin>>t;
while(t--){
  int n;
  cin>>n;
  vi v(n);
  rep(i,0,n-1) cin>>v[i];
  int ans=0;
  for(int q=0;q<n;++q){
   int i=0,j=1; int sum=v[0];
   while(j<n){
     if(sum<v[q]){
       sum+=v[j];
       ++j;
     }
     if(sum==v[q]){
       if(j-i>1)
       {
        ++ans;
        break;
       }
       else {
         i=j;
         ++j;

         sum=v[i];
       }
    }

    if(sum>v[q]){
      sum-=v[i];
      ++i;
     continue;
    }
   }
  }
  cout<<ans<<'\n';
}

    return 0;
}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
#define all(c) c.begin(),c.end()
#define rep(i,a,b) for(int i=a;i<=b;++i)
#define tr(container,it) \
for(auto it=container.begin();it!=container.end();++it)
typedef long long ll ;
typedef vector<int> vi;
#define sz(x) int(x.size())
#define mod 1000000007
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;
ll exp(ll x,ll y){
  //x%=mod;
  ll res=1;
  while(y){
    if(y&1)
    res=res*x;//%mod;
    x=x*x;//%mod;
    y>>=1;
  }
  return res;
}
ll fact(ll n){
  ll res=1;
  for(ll i=2;i<=n;++i)
  (res*=i)%=mod;
  return res;
}
bool isprime(int n){
  for(int i=2;i*i<=n;++i)
  if(n%i==0) return 0;
  return 1;
}

int main()
{
//freopen("input.txt","r",stdin);
//freopen("output.txt","w",stdout);
//ios::sync_with_stdio(0);
//cin.tie(0);
int t;
cin>>t;
while(t--){
  int n;
  cin>>n;
  vi v(n);
  rep(i,0,n-1) cin>>v[i];
  int ans=0;
  for(int q=0;q<n;++q){
   int sum=0;
   int i=0,j=0;
   while(j<n){
    while(j<n&&sum+v[j]<=v[q]){
      sum+=v[j];
      ++j;
    }
    if(sum==v[q]){
      if(j-i-1>0){
        ++ans;
        break;
      }

    }
    if(sum+v[j]>v[q]){
      sum-=v[i];
      ++i;
    }
   }
  }
  cout<<ans<<'\n';
}

    return 0;
}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
#define all(c) c.begin(),c.end()
#define rep(i,a,b) for(int i=a;i<=b;++i)
#define tr(container,it) \
for(auto it=container.begin();it!=container.end();++it)
typedef long long ll ;
typedef vector<int> vi;
#define sz(x) int(x.size())
#define mod 1000000007
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;
ll exp(ll x,ll y){
  //x%=mod;
  ll res=1;
  while(y){
    if(y&1)
    res=res*x;//%mod;
    x=x*x;//%mod;
    y>>=1;
  }
  return res;
}
ll fact(ll n){
  ll res=1;
  for(ll i=2;i<=n;++i)
  (res*=i)%=mod;
  return res;
}
bool isprime(int n){
  for(int i=2;i*i<=n;++i)
  if(n%i==0) return 0;
  return 1;
}

int main()
{
//freopen("input.txt","r",stdin);
//freopen("output.txt","w",stdout);
//ios::sync_with_stdio(0);
//cin.tie(0);
int t;
cin>>t;
while(t--){
  int n;
  cin>>n;
  vi v(n);
  rep(i,0,n-1) cin>>v[i];
  int ans=0;
  for(int q=0;q<n;++q){
   int i=0,j=0; int sum=0;bool mk=true;
   while(j<n){
     if(sum<v[q]){
       sum+=v[j];
       ++j;
     }
     if(sum==v[q]){
       if(j-1-i>0){
         ++ans;
         mk=false;
         break;
       }
       i=j;
       sum=0;
     }
     if(sum>v[q]){
       sum-=v[i];
       ++i;
     }
   }
   if(mk)
   while(i<n-1){
     if(sum==v[q]){
       ++ans;
       break;
     }
     sum-=v[i];++i;
   }
  }
  cout<<ans<<'\n';
}

    return 0;
}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
#define all(c) c.begin(),c.end()
#define rep(i,a,b) for(int i=a;i<=b;++i)
#define tr(container,it) \
for(auto it=container.begin();it!=container.end();++it)
typedef long long ll ;
typedef vector<int> vi;
#define sz(x) int(x.size())
#define mod 1000000007
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;
ll exp(ll x,ll y){
  //x%=mod;
  ll res=1;
  while(y){
    if(y&1)
    res=res*x;//%mod;
    x=x*x;//%mod;
    y>>=1;
  }
  return res;
}
ll fact(ll n){
  ll res=1;
  for(ll i=2;i<=n;++i)
  (res*=i)%=mod;
  return res;
}
bool isprime(int n){
  for(int i=2;i*i<=n;++i)
  if(n%i==0) return 0;
  return 1;
}

int main()
{
//freopen("input.txt","r",stdin);
//freopen("output.txt","w",stdout);
//ios::sync_with_stdio(0);
//cin.tie(0);
int t;
cin>>t;
while(t--){
  int n;
  cin>>n;
  vi v(n);
  rep(i,0,n-1) cin>>v[i];
  int ans=0;
  for(int q=0;q<n;++q){
   int sum=0;
   int i=0,j=0;
   while(j<=n){
     if(sum>v[q]){
       sum-=v[i];
       ++i;
     }
     if(sum<v[q]){
       sum+=v[j];
       ++j;
     }
     if(sum==v[q]){
       if(j-i-1>0){
         ++ans;
         break;
       }
       i=j;
       sum=0;
     }

   }
  }
  cout<<ans<<'\n';
}

    return 0;
}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
#define all(c) c.begin(),c.end()
#define rep(i,a,b) for(int i=a;i<=b;++i)
#define tr(container,it) \
for(auto it=container.begin();it!=container.end();++it)
typedef long long ll ;
typedef vector<int> vi;
#define sz(x) int(x.size())
#define mod 1000000007
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;
ll exp(ll x,ll y){
  //x%=mod;
  ll res=1;
  while(y){
    if(y&1)
    res=res*x;//%mod;
    x=x*x;//%mod;
    y>>=1;
  }
  return res;
}
ll fact(ll n){
  ll res=1;
  for(ll i=2;i<=n;++i)
  (res*=i)%=mod;
  return res;
}
bool isprime(int n){
  for(int i=2;i*i<=n;++i)
  if(n%i==0) return 0;
  return 1;
}

int main()
{
//freopen("input.txt","r",stdin);
//freopen("output.txt","w",stdout);
//ios::sync_with_stdio(0);
//cin.tie(0);
int t;
cin>>t;
while(t--){
  int n;
  cin>>n;
  vi v(n);
  rep(i,0,n-1) cin>>v[i];
  int ans=0;
  for(int q=0;q<n;++q){
   int sum=0;
   int i=0,j=0;
   while(j<n){
     if(v[j]>=v[q]){
       ++j;
       i=j;
       sum=0;
       continue;
     }
      if(sum+v[j]>v[q]){
       sum-=v[i];
       ++i;
       continue;
     }

     if(sum+v[j]==v[q]){
       sum+=v[j];
       ++j;
       if(j-1-i>0){
         ++ans;
         break;
       }
       i=j;
       sum=0;
       continue;
     }
   if(sum+v[j]<v[q]){
       sum+=v[j];
       ++j;
     }
   }
  }
  cout<<ans<<'\n';
}

    return 0;
}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
#define all(c) c.begin(),c.end()
#define rep(i,a,b) for(int i=a;i<=b;++i)
#define tr(container,it) \
for(auto it=container.begin();it!=container.end();++it)
typedef long long ll ;
typedef vector<int> vi;
#define sz(x) int(x.size())
#define mod 1000000007
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;
ll exp(ll x,ll y){
  //x%=mod;
  ll res=1;
  while(y){
    if(y&1)
    res=res*x;//%mod;
    x=x*x;//%mod;
    y>>=1;
  }
  return res;
}
ll fact(ll n){
  ll res=1;
  for(ll i=2;i<=n;++i)
  (res*=i)%=mod;
  return res;
}
bool isprime(int n){
  for(int i=2;i*i<=n;++i)
  if(n%i==0) return 0;
  return 1;
}

int main()
{
//freopen("input.txt","r",stdin);
//freopen("output.txt","w",stdout);
//ios::sync_with_stdio(0);
//cin.tie(0);
int t;
cin>>t;
while(t--){
  int n;
  cin>>n;
  vi v(n);
  rep(i,0,n-1) cin>>v[i];
  int ans=0;
  for(int q=0;q<n;++q){
   int sum=0;
   int i=0,j=0;
   while(j<n){
    while(j<n&&sum+v[j]<=v[q]){
      sum+=v[j];
      ++j;
    }
    if(sum==v[q]){
      if(j-i-1>0){
        ++ans;
        break;
      }
    }
    if(sum+v[j]>v[q]){
      sum-=v[i];
      ++i;
    }
   }
  }
  cout<<ans<<'\n';
}

    return 0;
}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
#define all(c) c.begin(),c.end()
#define rep(i,a,b) for(int i=a;i<=b;++i)
#define tr(container,it) \
for(auto it=container.begin();it!=container.end();++it)
typedef long long ll ;
typedef vector<int> vi;
#define sz(x) int(x.size())
#define mod 1000000007
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;
ll exp(ll x,ll y){
  //x%=mod;
  ll res=1;
  while(y){
    if(y&1)
    res=res*x;//%mod;
    x=x*x;//%mod;
    y>>=1;
  }
  return res;
}
ll fact(ll n){
  ll res=1;
  for(ll i=2;i<=n;++i)
  (res*=i)%=mod;
  return res;
}
bool isprime(int n){
  for(int i=2;i*i<=n;++i)
  if(n%i==0) return 0;
  return 1;
}

int main()
{
//freopen("input.txt","r",stdin);
//freopen("output.txt","w",stdout);
//ios::sync_with_stdio(0);
//cin.tie(0);
int t;
cin>>t;
while(t--){
  int n;
  cin>>n;
  vi v(n);
  rep(i,0,n-1) cin>>v[i];
  int ans=0;
  for(int q=0;q<n;++q){
   int i=0,j=0; int sum=0;
   while(j<n){
     if(v[j]>=v[q]){
       ++i;++j;
       sum=0;
       continue;
     }
    if(sum<v[q]){
      sum+=v[j];
      ++j;
    }
    if(sum==v[q]){
      if(j-1-i>0){
        ++ans;
        break;
      }
      i=j;
      sum=0;
    }
    if(sum>v[q]){
      sum-=v[i];
      ++i;
    }

   }
  }
  cout<<ans<<'\n';
}

    return 0;
}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
#define all(c) c.begin(),c.end()
#define rep(i,a,b) for(int i=a;i<=b;++i)
#define tr(container,it) \
for(auto it=container.begin();it!=container.end();++it)
typedef long long ll ;
typedef vector<int> vi;
#define sz(x) int(x.size())
#define mod 1000000007
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;
ll exp(ll x,ll y){
  //x%=mod;
  ll res=1;
  while(y){
    if(y&1)
    res=res*x;//%mod;
    x=x*x;//%mod;
    y>>=1;
  }
  return res;
}
ll fact(ll n){
  ll res=1;
  for(ll i=2;i<=n;++i)
  (res*=i)%=mod;
  return res;
}
bool isprime(int n){
  for(int i=2;i*i<=n;++i)
  if(n%i==0) return 0;
  return 1;
}

int main()
{
//freopen("input.txt","r",stdin);
//freopen("output.txt","w",stdout);
//ios::sync_with_stdio(0);
//cin.tie(0);
int t;
cin>>t;
while(t--){
  int n;
  cin>>n;
  vi v(n);
  rep(i,0,n-1) cin>>v[i];
  int ans=0;
  for(int q=0;q<n;++q){
   int sum=0;
   int i=0,j=0;
   while(j<n){

      if(sum+v[j]>v[q]){
       sum-=v[i];
       ++i;
       continue;
     }

     if(sum+v[j]==v[q]){
       sum+=v[j];
       ++j;
       if(j-1-i>0){
         ++ans;
         break;
       }
       i=j;
       sum=0;
       continue;
     }
   if(sum+v[j]<v[q]){
       sum+=v[j];
       ++j;
     }
   }
  }
  cout<<ans<<'\n';
}

    return 0;
}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
#define all(c) c.begin(),c.end()
#define rep(i,a,b) for(int i=a;i<=b;++i)
#define tr(container,it) \
for(auto it=container.begin();it!=container.end();++it)
typedef long long ll ;
typedef vector<int> vi;
#define sz(x) int(x.size())
#define mod 1000000007
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;
ll exp(ll x,ll y){
  //x%=mod;
  ll res=1;
  while(y){
    if(y&1)
    res=res*x;//%mod;
    x=x*x;//%mod;
    y>>=1;
  }
  return res;
}
ll fact(ll n){
  ll res=1;
  for(ll i=2;i<=n;++i)
  (res*=i)%=mod;
  return res;
}
bool isprime(int n){
  for(int i=2;i*i<=n;++i)
  if(n%i==0) return 0;
  return 1;
}

int main()
{
//freopen("input.txt","r",stdin);
//freopen("output.txt","w",stdout);
//ios::sync_with_stdio(0);
//cin.tie(0);
int t;
cin>>t;
while(t--){
  int n;
  cin>>n;
  vi v(n);
  rep(i,0,n-1) cin>>v[i];
  int ans=0;
  for(int q=0;q<n;++q){
   int i=0,j=0; int sum=0;
   while(j<n){
    while(j<n&&sum+v[j]<v[q]){
       sum+=v[j];
       ++j;
    }
    if(sum==v[q]){
      if(j-1-i>0){
        ++ans;
        break;
      }
      else {
        i=j;
        sum=0;
      }
    }
    if(sum>v[q]){
      sum-=v[i];
      ++i;
      continue;
    }
   }
  }
  cout<<ans<<'\n';
}

    return 0;
}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
#define all(c) c.begin(),c.end()
#define rep(i,a,b) for(int i=a;i<=b;++i)
#define tr(container,it) \
for(auto it=container.begin();it!=container.end();++it)
typedef long long ll ;
typedef vector<int> vi;
#define sz(x) int(x.size())
#define mod 1000000007
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;
ll exp(ll x,ll y){
  //x%=mod;
  ll res=1;
  while(y){
    if(y&1)
    res=res*x;//%mod;
    x=x*x;//%mod;
    y>>=1;
  }
  return res;
}
ll fact(ll n){
  ll res=1;
  for(ll i=2;i<=n;++i)
  (res*=i)%=mod;
  return res;
}
bool isprime(int n){
  for(int i=2;i*i<=n;++i)
  if(n%i==0) return 0;
  return 1;
}

int main()
{
//freopen("input.txt","r",stdin);
//freopen("output.txt","w",stdout);
//ios::sync_with_stdio(0);
//cin.tie(0);
int t;
cin>>t;
while(t--){
  int n;
  cin>>n;
  vi v(n);
  rep(i,0,n-1) cin>>v[i];
  int ans=0;
  for(int q=0;q<n;++q){
   int sum=0;
   int i=0,j=0;
   while(j<n){
     if(sum>v[q]){
       sum-=v[i];
       ++i;
     }
     if(sum<v[q]){
       sum+=v[j];
       ++j;
     }
     if(sum==v[q]){
       if(j-i-1>0){
         ++ans;
         break;
       }
       i=j;
       sum=0;
     }

   }
  }
  cout<<ans<<'\n';
}

    return 0;
}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
#define all(c) c.begin(),c.end()
#define rep(i,a,b) for(int i=a;i<=b;++i)
#define tr(container,it) \
for(auto it=container.begin();it!=container.end();++it)
typedef long long ll ;
typedef vector<int> vi;
#define sz(x) int(x.size())
#define mod 1000000007
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;
ll exp(ll x,ll y){
  //x%=mod;
  ll res=1;
  while(y){
    if(y&1)
    res=res*x;//%mod;
    x=x*x;//%mod;
    y>>=1;
  }
  return res;
}
ll fact(ll n){
  ll res=1;
  for(ll i=2;i<=n;++i)
  (res*=i)%=mod;
  return res;
}
bool isprime(int n){
  for(int i=2;i*i<=n;++i)
  if(n%i==0) return 0;
  return 1;
}

int main()
{
//freopen("input.txt","r",stdin);
//freopen("output.txt","w",stdout);
//ios::sync_with_stdio(0);
//cin.tie(0);
int t;
cin>>t;
while(t--){
  int n;
  cin>>n;
  vi v(n);
  rep(i,0,n-1) cin>>v[i];
  int ans=0;
  for(int q=0;q<n;++q){
   int i=0,j=0; int sum=0;
   while(j<n){
     if(sum<v[q]){
       sum+=v[j];
       ++j;
     }
     if(sum==v[q]){
       if(j-1-i>0){
         ++ans;
         break;
       }
       i=j;
       sum=0;
     }
     if(sum>v[q]){
       sum-=v[i];
       ++i;
     }
   }
   while(i<n){
     if(sum==v[q]){
       ++ans;
       break;
     }
     sum-=v[i];++i;
   }
  }
  cout<<ans<<'\n';
}

    return 0;
}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
#define all(c) c.begin(),c.end()
#define rep(i,a,b) for(int i=a;i<=b;++i)
#define tr(container,it) \
for(auto it=container.begin();it!=container.end();++it)
typedef long long ll ;
typedef vector<int> vi;
#define sz(x) int(x.size())
#define mod 1000000007
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;
ll exp(ll x,ll y){
  //x%=mod;
  ll res=1;
  while(y){
    if(y&1)
    res=res*x;//%mod;
    x=x*x;//%mod;
    y>>=1;
  }
  return res;
}
ll fact(ll n){
  ll res=1;
  for(ll i=2;i<=n;++i)
  (res*=i)%=mod;
  return res;
}
bool isprime(int n){
  for(int i=2;i*i<=n;++i)
  if(n%i==0) return 0;
  return 1;
}

int main()
{
//freopen("input.txt","r",stdin);
//freopen("output.txt","w",stdout);
//ios::sync_with_stdio(0);
//cin.tie(0);
int t;
cin>>t;
while(t--){
  int n;
  cin>>n;
  vi v(n);
  rep(i,0,n-1) cin>>v[i];
  int ans=0;
  for(int q=0;q<n;++q){
   int i=0,j=0; int sum=0;
   while(j<n){
    while(j<n&&sum+v[j]<v[q]){
       sum+=v[j];
       ++j;
    }
    if(sum==v[q]){
      if(j-1-i>0){
        ++ans;
        break;
      }
      else {
        ++i;
        sum=0;
        continue;
      }
    }
    if(sum>v[q]){
      sum-=v[i];
      ++i;
      continue;
    }
   }
  }
  cout<<ans<<'\n';
}

    return 0;
}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
#define all(c) c.begin(),c.end()
#define rep(i,a,b) for(int i=a;i<=b;++i)
#define tr(container,it) \
for(auto it=container.begin();it!=container.end();++it)
typedef long long ll ;
typedef vector<int> vi;
#define sz(x) int(x.size())
#define mod 1000000007
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;
ll exp(ll x,ll y){
  //x%=mod;
  ll res=1;
  while(y){
    if(y&1)
    res=res*x;//%mod;
    x=x*x;//%mod;
    y>>=1;
  }
  return res;
}
ll fact(ll n){
  ll res=1;
  for(ll i=2;i<=n;++i)
  (res*=i)%=mod;
  return res;
}
bool isprime(int n){
  for(int i=2;i*i<=n;++i)
  if(n%i==0) return 0;
  return 1;
}

int main()
{
//freopen("input.txt","r",stdin);
//freopen("output.txt","w",stdout);
//ios::sync_with_stdio(0);
//cin.tie(0);
int t;
cin>>t;
while(t--){
  int n;
  cin>>n;
  vi v(n);
  rep(i,0,n-1) cin>>v[i];
  int ans=0;
  for(int q=0;q<n;++q){
   int sum=0;
   int i=0,j=0;
   while(j<n){
    while(j<n&&sum+v[j]<=v[q]){
      sum+=v[j];
      ++j;
    }
    if(sum==v[q]){
      if(j-i-1>0){
        ++ans;
        break;
      }
    }
    if(sum+v[j]>=v[q]){
      sum-=v[i];
      ++i;
    }
   }
  }
  cout<<ans<<'\n';
}

    return 0;
}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
#define all(c) c.begin(),c.end()
#define rep(i,a,b) for(int i=a;i<=b;++i)
#define tr(container,it) \
for(auto it=container.begin();it!=container.end();++it)
typedef long long ll ;
typedef vector<int> vi;
#define sz(x) int(x.size())
#define mod 1000000007
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;
ll exp(ll x,ll y){
  //x%=mod;
  ll res=1;
  while(y){
    if(y&1)
    res=res*x;//%mod;
    x=x*x;//%mod;
    y>>=1;
  }
  return res;
}
ll fact(ll n){
  ll res=1;
  for(ll i=2;i<=n;++i)
  (res*=i)%=mod;
  return res;
}
bool isprime(int n){
  for(int i=2;i*i<=n;++i)
  if(n%i==0) return 0;
  return 1;
}

int main()
{
//freopen("input.txt","r",stdin);
//freopen("output.txt","w",stdout);
//ios::sync_with_stdio(0);
//cin.tie(0);
int t;
cin>>t;
while(t--){
  int n;
  cin>>n;
  vi v(n);
  rep(i,0,n-1) cin>>v[i];
  int ans=0;
  for(int q=0;q<n;++q){
   int i=0,j=1; int sum=v[0];
   while(j<n){
     if(sum<v[q]){
       sum+=v[j];
       ++j;
     }
     if(sum==v[q]){
       if(j-i>1)
       {
        ++ans;
        break;
       }
       else {
         j=i+1;
         i=j;
         sum=0;
       }
    }

    if(sum>v[q]){
      sum-=v[i];
      ++i;
     continue;
    }
   }
  }
  cout<<ans<<'\n';
}

    return 0;
}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
#define all(c) c.begin(),c.end()
#define rep(i,a,b) for(int i=a;i<=b;++i)
#define tr(container,it) \
for(auto it=container.begin();it!=container.end();++it)
typedef long long ll ;
typedef vector<int> vi;
#define sz(x) int(x.size())
#define mod 1000000007
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;
ll exp(ll x,ll y){
  //x%=mod;
  ll res=1;
  while(y){
    if(y&1)
    res=res*x;//%mod;
    x=x*x;//%mod;
    y>>=1;
  }
  return res;
}
ll fact(ll n){
  ll res=1;
  for(ll i=2;i<=n;++i)
  (res*=i)%=mod;
  return res;
}
bool isprime(int n){
  for(int i=2;i*i<=n;++i)
  if(n%i==0) return 0;
  return 1;
}

int main()
{
//freopen("input.txt","r",stdin);
//freopen("output.txt","w",stdout);
//ios::sync_with_stdio(0);
//cin.tie(0);
int t;
cin>>t;
while(t--){
  int n;
  cin>>n;
  vi v(n);
  rep(i,0,n-1) cin>>v[i];
  int ans=0;
  for(int q=0;q<n;++q){
   int i=0,j=0; int sum=0;
   while(j<n){

     if(sum==v[q]){
       if(j-i>1)
       {
        ++ans;
        break;
       }
       else {
         j=i+1;
         i=j;
         sum=0;
       }
    }
      if(sum<v[q]){
       sum+=v[j];
       ++j;
     }
    if(sum>v[q]){
      sum-=v[i];
      ++i;
     continue;
    }
   }
  }
  cout<<ans<<'\n';
}

    return 0;
}


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

typedef long long int ll;

int main() {
   int n;
   cin >> n;
   vector<int>  v(n);
   for(int& x:v)cin>>x;
   sort(v.begin(), v.end());
   ll s[2];
   s[0] = 0;  s[1] = 0;
   ll points = 0;
   bool aa = false;
   s[0] += v[n-1];
   for(int i=n-2; i>=0; i--){
       if(v[i] == v[i+1]){
           s[(int)aa] += v[i];
       } else if(v[i] == (v[i+1] -1)){
           if(s[aa] < s[!aa]){
               points += s[!aa];
               s[0] = 0;
               s[1] = 0;
           }
           aa = !aa;
           s[(int)aa] += v[i];
       } else {
           points += (s[0] > s[1] )? s[0] : s[1];
           s[0] = 0;
           s[1] = 0;
           s[aa] += v[i];
       }
   }
   points += (s[0] > s[1] )? s[0] : s[1];
   cout<<points;
}


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

int main(){
	int n;
	cin>>n;
	vector<int> a(100000, 0);
	int max = 0;
	for(int i =0; i<n; i++){
		int inp;
		cin>>inp;
		if(inp > max)max = inp;
		a[inp-1]++;
	}
	vector<int> b(max, 0);
	b[0] = a[0];
	b[1] = 2*a[1];
	for(int i = 2; i<max; i++){
		b[i] = (b[i-1] > (b[i-2] + (i+1)*a[i]))? b[i-1]: (b[i-2] + (i+1)*a[i]);
	}
	cout<<b[max-1];
	return 0;
}


//#include <bits/stdc++.h>
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <cstring>
#include <math.h>
using namespace std;

#define in cin>>
#define out cout<<
#define ll long long
#define dd double
#define B break
#define C  continue
#define pf printf
#define sf scanf
#define pb push_back
#define fr(x,y) for(int i=x;i<y;i++)
//////////////////////////////////////
template <class T> T maxi(T a[],int m,int l=0){
	if(l>=m)return max(a[m],a[l]);
	return max(maxi(a,m-1,l+1),max(a[l],a[m]));
}

template <class T> T mini(T a[],int m,int l=0){
	if(l>=m)return min(a[l],a[m]);
	return min(mini(a,m-1,l+1),min(a[l],a[m]));
}

template <class T> T sumi(T a[],int m,int l=0){
	if(l==m)return a[l];
	if(l>m)return 0;
	return sum(a,m-1,l+1)+a[m]+a[l];
}

template <class T> T powi(T x,T y){
	if(y==0)return 1;
	if(y<0){y=-y;

				if(y<2) return 1/x;
		if(y==2)return 1/(x*x);
	if(y%2==1) return 1/(x*powi(x,y-1));
	return 1/(powi(x,y/2)*powi(x,y/2));
	}
	else{
		if(y<2) return x;
		if(y==2)return x*x;
	if(y%2==1) return x*powi(x,y-1);
	return powi(x,y/2)*powi(x,y/2);}
}
/////////////////////////////////////
int a[1000];

ll func(ll a[],int l,int n){
	if (l>=n-3){if(l==n-1) return a[l];
	else if (l>n) return 0;
	else if(l==n-2){
		if(a[l]<a[n-1]) return a[n-1];
		else return a[l];
	}
	else{
		if(a[l]+a[l+2]>a[l+1]) return a[l]+a[l+2];
		else return a[l+1];
	}
	}
else if ((a[l]>=a[l+1])||(a[l+2]>a[l+1]) )return a[l]+func(a,l+2,n);
	else return a[l+1]+func(a,l+3,n);
}

int main(){
ll n,a[100000];ll sum=0;
in n;

fr(0,n){
	in a[i];
}

sum=func(a,0,n);
out sum;
return 0; }


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

#define ll long long
int n,x;
ll a[100010];

int main(){

	cin>>n;
//n=22000;
	for(int i=0;i<n;i++){cin>>x;
	//x=100000;
	a[x]+=x;
	}

	for(int i=2;i<=100000;i++){
		a[i]=max(a[i-1],a[i-2]+a[i]);

	}
	cout<<a[100000];
    return 0;}


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

#define ll long long
ll ans;
int a[100010],k=0;
ll con[100010],q,w;
int n;
ll c[100010],d[100010];
ll com(int b){
	if(b>n)return 0;
	if (con[b]==0) return com(b+1);
	else if(con[b]>con[b+1]) {return con[b]+com(b+2);}
	c[k]=con[b+1]+com(b+3);
	d[k]=con[b]+com(b+2);
	q=c[k];
	w=d[k];
	 if(c[k]>d[k]){ k++;return q;}
	else{k++; return w;}
}

int main(){//int x;
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>a[i];
		con[a[i]]+=a[i];
	}

	sort(a,a+n);

	ans=com(0);
	cout<<ans;
    return 0;}


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

#define ll long long
//int x=100000;
int n,mini=100000;
int a[100010];
int con[100010];
ll ans;

int maxi(int m){
 ll bef,next,now;

 bef=1LL*(m-1)*con[m-1];
 next=1LL*con[m+1]*(m+1);
 now=1LL*con[m]*m;
 if(now>=next+bef){con[m]=0;con[m+1]=0;con[m-1]=0; return now;}
 else { con[m]=0;con[m-1]=0; return maxi(m+2)+bef;}

}

int main(){
    cin>>n;
    for(int i=0;i<n;i++){
    cin>>a[i];
    mini=min(mini,a[i]);
    con[a[i]]++;
	}
	sort(a,a+n);
	for(int i=0;i<n;i++){
	if(a[i]==mini)ans+= maxi(a[i]+1);
	else ans+= maxi(a[i]);
	}
	cout<<ans;

    return 0;}


//#include <bits/stdc++.h>
#include <iostream>
#include <stdio.h>
#include <iomanip>
#include <string.h>
#include <cstring>
#include <math.h>
using namespace std;

#define in cin>>
#define out cout<<
#define ll long long
#define dd double
#define B break
#define C  continue
#define pf printf
#define sf scanf
#define pb push_back
#define fr(x,y) for(int i=x;i<y;i++)
//////////////////////////////////////
template <class T> T maxi(T a[],int m,int l=0){
	if(l>=m)return max(a[m],a[l]);
	return max(maxi(a,m-1,l+1),max(a[l],a[m]));
}

template <class T> T mini(T a[],int m,int l=0){
	if(l>=m)return min(a[l],a[m]);
	return min(mini(a,m-1,l+1),min(a[l],a[m]));
}

template <class T> T sumi(T a[],int m,int l=0){
	if(l==m)return a[l];
	if(l>m)return 0;
	return sum(a,m-1,l+1)+a[m]+a[l];
}

template <class T> T powi(T x,T y){
	if(y==0)return 1;
	if(y<0){y=-y;

				if(y<2) return 1/x;
		if(y==2)return 1/(x*x);
	if(y%2==1) return 1/(x*powi(x,y-1));
	return 1/(powi(x,y/2)*powi(x,y/2));
	}
	else{
		if(y<2) return x;
		if(y==2)return x*x;
	if(y%2==1) return x*powi(x,y-1);
	return powi(x,y/2)*powi(x,y/2);}
}
/////////////////////////////////////
int func(int a[],int now [],int maxo){
	ll z=1LL*maxo*now[maxo];
	ll z2=1LL*(maxo-1)*now[maxo-1];
	if (maxo<=0) return 0;
if (z>=z2) return z+func(a,now,maxo-2) ;
else return z2+func(a,now,maxo-3);

}
int now[100000];

int main(){
int n,a[100000];
int maxo=0;
ll mac=0;
in n;
fr(0,n){
	in a[i];
	if (a[i]>maxo)maxo=a[i];
	now[a[i]]++;
}
mac= func(a,now,maxo);
out mac;
return 0; }


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

#define ll long long
int n,x;
ll a[100010];

int main(){

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

	for(int i=2;i<=n;i++){
		a[i]=max(a[i-1],a[i-2]+a[i]);
	}
	cout<<a[n-1];
    return 0;}


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

#define ll long long
int x=100000;
int n,mini=100000;
int a[100010];
int con[100010];
ll ans;

int maxi(int m){
 ll bef,next,now;

 bef=1LL*(m-1)*con[m-1];
 next=1LL*con[m+1]*(m+1);
 now=1LL*con[m]*m;
 if(now>=next+bef){con[m]=0;con[m+1]=0;con[m-1]=0; return now;}
 else { con[m]=0;con[m-1]=0; return maxi(m+2)+bef;}

}

int main(){
    cin>>n;
    for(int i=0;i<n;i++){
    cin>>a[i];
    mini=min(mini,a[i]);
    con[a[i]]++;
	}
	sort(a,a+n);
	for(int i=0;i<n;i++){
	if(a[i]==mini)ans+= maxi(a[i]+1);
	else ans+= maxi(a[i]);
	}
	cout<<ans;

    return 0;}


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

#define ll long long
ll ans;
int a[100010],k=0;
ll con[100010],q,w;
int n;
ll c[100010],d[100010];
ll com(int b){
	if(b>n)return 0;
	if (con[b]==0) return com(b+1);
	else if(con[b]>con[b+1]) {return con[b]+com(b+2);}
	c[k]=con[b+1]+com(b+3);
	d[k]=con[b]+com(b+2);
	q=c[k];
	w=d[k];
	 if(c[k]>d[k]){ k++;return q;}
	else{k++; return w;}
}

int main(){//int x;
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>a[i];
		con[a[i]]+=a[i];
	}

	sort(a,a+n);

	ans=com(0);
	cout<<ans;
    return 0;}


//#include <bits/stdc++.h>
#include <iostream>
#include <stdio.h>
#include <iomanip>
#include <string.h>
#include <cstring>
#include <math.h>
using namespace std;

#define in cin>>
#define out cout<<
#define ll long long
#define dd double
#define B break
#define C  continue
#define pf printf
#define sf scanf
#define pb push_back
#define fr(x,y) for(int i=x;i<y;i++)
//////////////////////////////////////
template <class T> T maxi(T a[],int m,int l=0){
	if(l>=m)return max(a[m],a[l]);
	return max(maxi(a,m-1,l+1),max(a[l],a[m]));
}

template <class T> T mini(T a[],int m,int l=0){
	if(l>=m)return min(a[l],a[m]);
	return min(mini(a,m-1,l+1),min(a[l],a[m]));
}

template <class T> T sumi(T a[],int m,int l=0){
	if(l==m)return a[l];
	if(l>m)return 0;
	return sum(a,m-1,l+1)+a[m]+a[l];
}

template <class T> T powi(T x,T y){
	if(y==0)return 1;
	if(y<0){y=-y;

				if(y<2) return 1/x;
		if(y==2)return 1/(x*x);
	if(y%2==1) return 1/(x*powi(x,y-1));
	return 1/(powi(x,y/2)*powi(x,y/2));
	}
	else{
		if(y<2) return x;
		if(y==2)return x*x;
	if(y%2==1) return x*powi(x,y-1);
	return powi(x,y/2)*powi(x,y/2);}
}
/////////////////////////////////////
/*int func(int a[],int now [],int maxo){
	ll z=1LL*maxo*now[maxo]
if (z>=1LL*(maxo-1)*now[maxo-1]) return z+func(a,now,maxo-2) ;
else if()

}*/
int now[100000];

int main(){
int n,a[100000];
ll maxo=0,mac=0;
in n;
/*fr(0,n){
	in a[i];
	if (a[i]>maxo)maxo=a[i];
	now[a[i]]++;
}*/

fr(0,n){
	in a[i];
	if(a[i]%2)maxo+=a[i];
	else mac+=a[i];
}
if(mac>maxo)out mac;
else out maxo;

return 0; }


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

#define ll long long
int x=100000;
int n,mini=100000;
int a[100010];
int con[100010];
ll ans;

int maxi(int m){
 ll bef,next,now;

 bef=1LL*(m-1)*con[m-1];
 next=1LL*con[m+1]*(m+1);
 now=1LL*con[m]*m;
 con[m]=0;con[m-1]=0;con[m+1]=0;
 if(now>=next+bef) return now;
 else { con[m+2]=0;con[m-2]=0; return next+bef;}

}

int main(){
    cin>>n;
    for(int i=0;i<n;i++){
    cin>>a[i];
    mini=min(mini,a[i]);
    con[a[i]]++;
	}
	for(int i=0;i<n;i++){
	if(a[i]==mini)continue;
	ans+= maxi(a[i]);
	}
	cout<<ans;

    return 0;}


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

#define ll long long
int n,x;
ll a[100010];

int main(){

	cin>>n;
//n=22000;
	for(int i=0;i<n;i++){cin>>x;
	//x=100000;
	a[x]+=x;
	}

	for(int i=2;i<=100000;i++){
		a[i]=max(a[i-1],a[i-2]+a[i]);

	}
	cout<<a[n];
    return 0;}


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

#define ll long long
int n,x;
ll a[100010];

int main(){

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

	for(int i=2;i<n;i++){
		a[i]=max(a[i-1],a[i-2]+a[i]);
	}
	cout<<a[n-1];
    return 0;}


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

#define ll long long
int x=100000;
int n,mini=100000;
int a[100010];
int con[100010];
ll ans;

int maxi(int m){
 ll bef,next,now;

 bef=1LL*(m-1)*con[m-1];
 next=1LL*con[m+1]*(m+1);
 now=1LL*con[m]*m;
 if(now>=next+bef){con[m]=0;con[m+1]=0;con[m-1]=0; return now;}
 else { con[m]=0;con[m-1]=0; return maxi(m+2)+bef;}

}

int main(){
    cin>>n;
    for(int i=0;i<n;i++){
    cin>>a[i];
    mini=min(mini,a[i]);
    con[a[i]]++;
	}
	sort(a,a+n);
	for(int i=0;i<n;i++){
	if(a[i]==mini)continue;
	ans+= maxi(a[i]);
	}
	cout<<ans;

    return 0;}


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

#define ll long long
int n,x;
ll a[100010];

int main(){

	cin>>n;
//n=22000;
	for(int i=0;i<n;i++){cin>>x;
	//x=100000;
	a[x]+=x;
	}

	for(int i=2;i<=100000;i++){
		a[i]=max(a[i-1],a[i-2]+a[i]);
		cout<<a[i]<<endl;
	}
	cout<<a[n];
    return 0;}


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

#define ll long long
int n,x;
ll a[100010];

int main(){

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

	for(int i=2;i<=n;i++){
		a[i]=max(a[i-1],a[i-2]+a[i]);
	}
	cout<<a[n];
    return 0;}


//#include <bits/stdc++.h>
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <cstring>
#include <math.h>
using namespace std;

#define in cin>>
#define out cout<<
#define ll long long
#define dd double
#define B break
#define C  continue
#define pf printf
#define sf scanf
#define pb push_back
#define fr(x,y) for(int i=x;i<y;i++)
//////////////////////////////////////
template <class T> T maxi(T a[],int m,int l=0){
	if(l>=m)return max(a[m],a[l]);
	return max(maxi(a,m-1,l+1),max(a[l],a[m]));
}

template <class T> T mini(T a[],int m,int l=0){
	if(l>=m)return min(a[l],a[m]);
	return min(mini(a,m-1,l+1),min(a[l],a[m]));
}

template <class T> T sumi(T a[],int m,int l=0){
	if(l==m)return a[l];
	if(l>m)return 0;
	return sum(a,m-1,l+1)+a[m]+a[l];
}

template <class T> T powi(T x,T y){
	if(y==0)return 1;
	if(y<0){y=-y;

				if(y<2) return 1/x;
		if(y==2)return 1/(x*x);
	if(y%2==1) return 1/(x*powi(x,y-1));
	return 1/(powi(x,y/2)*powi(x,y/2));
	}
	else{
		if(y<2) return x;
		if(y==2)return x*x;
	if(y%2==1) return x*powi(x,y-1);
	return powi(x,y/2)*powi(x,y/2);}
}
/////////////////////////////////////
int a[1000];

ll func(ll a[],int l,int n){
	if (l>n-3){if(l==n-1) return a[l];
	else if (l>n) return 0;
	else {
		if(a[l]<a[n-1]) return a[n-1];
		else return a[l];
	}}
else if ((a[l]>=a[l+1])||(a[l+2]>a[l+1]) )return a[l]+func(a,l+2,n);
	else return a[l+1]+func(a,l+3,n);
}

int main(){
ll n,a[100000];ll sum=0;
in n;

fr(0,n){
	in a[i];
}

sum=func(a,0,n);
out sum;
return 0; }


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

#define ll long long
int x=100000;
int n;
int a[100010];
int con[100010];
ll ans;

int maxi(int m){
 ll bef,next,now;

 bef=1LL*(m-1)*con[m-1];
 next=1LL*con[m+1]*(m+1);
 now=1LL*con[m]*m;
 con[m]=0;con[m-1]=0;con[m+1]=0;
 if(now>=next+bef) return now;
 else { con[m+2]=0;con[m-2]=0; return next+bef;}

}

int main(){
    cin>>n;
    for(int i=0;i<n;i++){
    cin>>a[i];
    con[a[i]]++;
	}
	for(int i=1;i<n;i++){
	ans+= maxi(a[i]);
	}
	cout<<ans;

    return 0;}


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

#define ll long long int
#define vi vector<int>
#define pb push_back
#define vli vector<long long int>
#define mp make_pair
#define pii pair<int,int>
#define mod 1000000007

int main()
{
    int n;
    cin>>n;
    int a[n],i,cnt[40005];
    for(i=0;i<n;i++)
     { cin>>a[i];
         cnt[a[i]]++;
     }
      int dp[40005]={0};
      dp[0]=0;
      dp[1]=cnt[1];
      for(i=2;i<=40005;i++)
      {
          dp[i]=max(dp[i-1],dp[i-2]+cnt[i]*i);
      }
      cout<<dp[n];

}


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

#define ll long long int
#define vi vector<int>
#define pb push_back
#define vli vector<long long int>
#define mp make_pair
#define pii pair<int,int>
#define mod 1000000007

int main()
{
    ll n;
    cin>>n;
    ll a[n],i,cnt[40005];
    for(i=0;i<n;i++)
     { cin>>a[i];
         cnt[a[i]]++;
     }
      ll dp[40005]={0};
      dp[0]=0;
      dp[1]=cnt[1];
      for(i=2;i<=40005;i++)
      {
          dp[i]=max(dp[i-1],dp[i-2]+cnt[i]*i);
      }
      cout<<dp[n];

}


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

#define ll long long int
#define vi vector<int>
#define pb push_back
#define vli vector<long long int>
#define mp make_pair
#define pii pair<int,int>
#define mod 1000000007

int main()
{
    ll n;
    cin>>n;
    ll a[n],i,cnt[100005];
    for(i=0;i<n;i++)
     { cin>>a[i];
         cnt[a[i]]++;
     }
      ll dp[100005]={0};
      dp[0]=0;
      dp[1]=cnt[1];
      for(i=2;i<=100001;i++)
      {
          dp[i]=max(dp[i-1],dp[i-2]+cnt[i]*i);
      }
      cout<<dp[n];

}


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

#define ll long long int
#define vi vector<int>
#define pb push_back
#define vli vector<long long int>
#define mp make_pair
#define pii pair<int,int>
#define mod 1000000007

int main()
{
    ll n;
    cin>>n;
    ll a[n],i,cnt[100005];
    for(i=0;i<n;i++)
     { cin>>a[i];
         cnt[a[i]]++;
     }
      ll dp[100005]={0};
      dp[0]=0;
      dp[1]=cnt[1];
      for(i=2;i<=100001;i++)
      {
          dp[i]=max(dp[i-1],dp[i-2]+cnt[i]*i);
      }
      cout<<dp[100000];

}


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

#define ll long long int
#define vi vector<int>
#define pb push_back
#define vli vector<long long int>
#define mp make_pair
#define pii pair<int,int>
#define mod 1000000007

int main()
{
    ll n;
    cin>>n;
    ll a[n],i,cnt[100005];
    for(i=0;i<n;i++)
     { cin>>a[i];
         cnt[a[i]]++;
     }
      ll dp[100005]={0};
      dp[0]=0;
      dp[1]=cnt[1];
      for(i=2;i<=100005;i++)
      {
          dp[i]=max(dp[i-1],dp[i-2]+cnt[i]*i);
      }
      cout<<dp[n];

}


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

#define ll long long int
#define vi vector<int>
#define pb push_back
#define vli vector<long long int>
#define mp make_pair
#define pii pair<int,int>
#define mod 1000000007

int main()
{
    int n;
    cin>>n;
    int a[n],i,cnt[n+1];
    for(i=0;i<n;i++)
     { cin>>a[i];
         cnt[a[i]]++;
     }
      int dp[40005]={0};
      dp[0]=0;
      dp[1]=cnt[1];
      for(i=2;i<n;i++)
      {
          dp[i]=max(dp[i-1],dp[i-2]+cnt[i]*i);
      }
      cout<<dp[n];

}


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

#define ll long long int
#define vi vector<int>
#define pb push_back
#define vli vector<long long int>
#define mp make_pair
#define pii pair<int,int>
#define mod 1000000007

int main()
{
    ll n;
    cin>>n;
    ll a[n],i,cnt[100005];
    for(i=0;i<n;i++)
     { cin>>a[i];
         cnt[a[i]]++;
     }
      ll dp[100005]={0};
      dp[0]=0;
      dp[1]=cnt[1];
      for(i=2;i<=40005;i++)
      {
          dp[i]=max(dp[i-1],dp[i-2]+cnt[i]*i);
      }
      cout<<dp[n];

}


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

#define ll long long int
#define vi vector<int>
#define pb push_back
#define vli vector<long long int>
#define mp make_pair
#define pii pair<int,int>
#define mod 1000000007

int main()
{
    ll n;
    cin>>n;
    ll a[n],i,cnt[1000000];
    for(i=0;i<n;i++)
     { cin>>a[i];
         cnt[a[i]]++;
     }
      ll dp[1000000]={0};
      dp[0]=0;
      dp[1]=cnt[1];
      for(i=2;i<=1000000;i++)
      {
          dp[i]=max(dp[i-1],dp[i-2]+cnt[i]*i);
      }
      cout<<dp[n];

}


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

#define ll long long int
#define vi vector<int>
#define pb push_back
#define vli vector<long long int>
#define mp make_pair
#define pii pair<int,int>
#define mod 1000000007

int main()
{
    ll n;
    cin>>n;
    ll a[n],i,cnt[1000005];
    for(i=0;i<n;i++)
     { cin>>a[i];
         cnt[a[i]]++;
     }
      ll dp[1000005]={0};
      dp[0]=0;
      dp[1]=cnt[1];
      for(i=2;i<=100001;i++)
      {
          dp[i]=max(dp[i-1],dp[i-2]+cnt[i]*i);
      }
      cout<<dp[n];

}


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

#define ll long long int
#define vi vector<int>
#define pb push_back
#define vli vector<long long int>
#define mp make_pair
#define pii pair<int,int>
#define mod 1000000007

int main()
{
    ll n;
    cin>>n;
    ll a[n],i,cnt[40005];
    for(i=0;i<n;i++)
     { cin>>a[i];
         cnt[a[i]]++;
     }
      int dp[40005]={0};
      dp[0]=0;
      dp[1]=cnt[1];
      for(i=2;i<=40005;i++)
      {
          dp[i]=max(dp[i-1],dp[i-2]+cnt[i]*i);
      }
      cout<<dp[n];

}


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

#define ll long long int
#define vi vector<int>
#define pb push_back
#define vli vector<long long int>
#define mp make_pair
#define pii pair<int,int>
#define mod 1000000007

int main()
{
    int n;
    cin>>n;
    int a[n],i,cnt[n+1];
    for(i=0;i<n;i++)
     { cin>>a[i];
         cnt[a[i]]++;
     }
      int dp[40005]={0};
      dp[0]=0;
      dp[1]=cnt[1];
      for(i=2;i<=40005;i++)
      {
          dp[i]=max(dp[i-1],dp[i-2]+cnt[i]*i);
      }
      cout<<dp[n];

}


// #include <bits/stdc++.h>
// #include <unordered_map>
// using namespace std;
// typedef long long ll;
// ll boredom(unordered_map<ll,ll>& mi){
// 	ll* dp = new ll[1000001]();
// 	for(int i=0;i<100001;i++){
// 		dp[i]= 0;
// 	}
// 	dp[1] = mi[1];
// 	for(ll i=2;i<1000001;i++){
// 		dp[i] = max(dp[i-1],(mi[i]*i)+dp[i-2]);
// 		}
// 	ll ans = dp[10000];
// 	delete[] dp;
// 	return ans;
// }
// int main(){
// 	ll n;
// 	cin >> n;
// 	unordered_map<ll,ll> mi;
// 	for(ll i=0;i<n;i++){
// 		ll a;
// 		cin >>a;
// 		mi[a]++;
// 	}
// 	cout << boredom(mi)<<endl;
// }

#include <iostream>
#include <algorithm>
#include <cstring>
using namespace std;

long long int a[100007], n;
long long int dp[100007];

int main() {
    memset(a, 0, sizeof(a));
    cin >> n;
    for (int i = 0; i < n; i++) {
        int j;
        cin >> j;
        a[j]++;
    }
    dp[0] = 0;
    dp[1] = a[1]; // a[1]*1 = a[1]
    for (int i = 2; i <= 100000; i++) { // Finding optimal points until the ith number
        dp[i] = max(dp[i - 1], dp[i - 2] + i*a[i]);
    }
    cout << dp[100000];
    return 0;
}


#include <iostream>
#include <unordered_map>
using namespace std;
typedef long long int ll;
long long int dp[100007];
ll boredom(unordered_map<ll,ll>& mi){
	dp[1] = mi[1];
	for(ll i=2;i<100000;i++){
		dp[i] = max(dp[i-1],(mi[i]*i)+dp[i-2]);
		}
	ll ans = dp[100000];
	delete[] dp;
	return ans;
}
int main(){
	ll n;
	cin >> n;
	unordered_map<ll,ll> mi;
	for(ll i=0;i<n;i++){
		ll a;
		cin >>a;
		mi[a]++;
	}
	cout << boredom(mi)<<endl;
}

// #include <iostream>
// #include <algorithm>
// #include <cstring>
// using namespace std;

// long long int a[100007], n;
// long long int dp[100007];

// int main() {
//     memset(a, 0, sizeof(a));
//     cin >> n;
//     for (int i = 0; i < n; i++) {
//         int j;
//         cin >> j;
//         a[j]++;
//     }
//     dp[0] = 0;
//     dp[1] = a[1]; // a[1]*1 = a[1]
//     for (int i = 2; i <= 100000; i++) { // Finding optimal points until the ith number
//         dp[i] = max(dp[i - 1], dp[i - 2] + i*a[i]);
//     }
//     cout << dp[100000];
//     return 0;
// }


#include <bits/stdc++.h>
#include <unordered_map>
using namespace std;
int boredom(unordered_map<int,int>& mi){
	int* dp = new int[100001]();
	memset(dp,0,100001*sizeof(int));
	dp[0] = 0;
	for(int i=1;i<100001;i++){
		dp[i] = dp[i-1];
			int x = mi[i]*i;
			if(i-2>=0){
				x += dp[i-2];
			}
			dp[i] = max(dp[i],x);
		}
	int ans = dp[1000];
	delete[] dp;
	return ans;
}
int main(){
	int n;
	cin >> n;
	unordered_map<int,int> mi;
	for(int i=0;i<n;i++){
		int a;
		cin >>a;
		mi[a]++;
	}
	cout << boredom(mi)<<endl;
}


#include <bits/stdc++.h>
#include <unordered_map>
using namespace std;
typedef long long int ll;
ll arr[100007];
long long int dp[100007];
ll boredom(){
	dp[0] = 0;
	dp[1] = arr[1];
	for(int i=2;i<=100000;i++){
		dp[i] = max(dp[i-1],(arr[i]*i)+dp[i-2]);
		}
	ll ans = dp[100000];
	return ans;
}
int main(){
	int n;
	cin >> n;
	 memset(arr, 0, sizeof(arr));
	for(ll i=0;i<n;i++){
		int x;
		cin >>x;
		arr[x]++;
	}
	cout << boredom()<<endl;
}

// #include <iostream>
// #include <algorithm>
// #include <cstring>
// using namespace std;

// long long int a[100007], n;
// long long int dp[100007];

// int main() {
//     memset(a, 0, sizeof(a));
//     cin >> n;
//     for (int i = 0; i < n; i++) {
//         int j;
//         cin >> j;
//         a[j]++;
//     }
//     dp[0] = 0;
//     dp[1] = a[1]; // a[1]*1 = a[1]
//     for (int i = 2; i <= 100000; i++) { // Finding optimal points until the ith number
//         dp[i] = max(dp[i - 1], dp[i - 2] + i*a[i]);
//     }
//     cout << dp[100000];
//     return 0;
// }


#include <bits/stdc++.h>
#include <unordered_map>
using namespace std;
typedef unsigned long long int ll;
ll boredom(unordered_map<ll,ll>& mi){
	ll* dp = new ll[100001]();
	for(int i=0;i<100001;i++){
		dp[i]= 0;
	}
	dp[0] = 0;
	for(ll i=1;i<100001;i++){
		dp[i] = dp[i-1];
			ll x = mi[i]*i;
			if(i-2>=0){
				x += dp[i-2];
			}
			dp[i] = max(dp[i],x);
		}
	ll ans = dp[1000];
	delete[] dp;
	return ans;
}
int main(){
	ll n;
	cin >> n;
	unordered_map<ll,ll> mi;
	for(ll i=0;i<n;i++){
		ll a;
		cin >>a;
		mi[a]++;
	}
	cout << boredom(mi)<<endl;
}


#include <bits/stdc++.h>
#include <unordered_map>
using namespace std;
typedef long long int ll;
ll boredom(unordered_map<ll,ll>& mi){
	ll* dp = new ll[1000001]();
	for(int i=0;i<100001;i++){
		dp[i]= 0;
	}
	dp[1] = mi[1];
	for(ll i=2;i<1000001;i++){
		dp[i] = max(dp[i-1],(mi[i]*i)+dp[i-2]);
		}
	ll ans = dp[10000];
	delete[] dp;
	return ans;
}
int main(){
	ll n;
	cin >> n;
	unordered_map<ll,ll> mi;
	for(ll i=0;i<n;i++){
		ll a;
		cin >>a;
		mi[a]++;
	}
	cout << boredom(mi)<<endl;
}


#include <bits/stdc++.h>
#include <unordered_map>
using namespace std;
// int dp[100001];
// int boredom(int* arr,int n){
// 	if(n<=0){
// 		return 0;
// 	}
// 	if(n==1){
// 		return arr[0];
// 	}
//     if(dp[n]!=-1){
//         return dp[n];
//     }
// 	int f_c=0;
// 	while(arr[f_c]==arr[0]){
// 		f_c++;
// 	}
// 	int o1=0;
// 	if(abs(arr[0]-arr[f_c])==1){
// 		int z=f_c;
// 		while(arr[z]==arr[f_c]){
// 			z++;
// 		}
// 		o1 = f_c*arr[0] + boredom(arr+z,n-z);
// 	}else{
// 		o1 = f_c*arr[0] + boredom(arr+f_c,n-f_c);
// 	}
// 	int o2 = boredom(arr+f_c,n-f_c);
// 	dp[n]= max(o1,o2);
//     return dp[n];
// }
// int solve(int n,vector<int>A){
//     int * arr = new int[n];
//     for(int i=0;i<n;i++){
//     	arr[i]= A[i];
//     }
//     sort(arr,arr+n);
//     memset(dp,-1,100001*sizeof(int));
//     return boredom(arr,n);
// }

	// method 2
int boredom(unordered_map<int,int>& m){
	int* dp = new int[1001]();
	memset(dp,0,1001*sizeof(int));
	dp[1] = m[1];

	for(int i=2;i<=1000;i++){
		dp[i] = max((i*m[i])+dp[i-2],dp[i-1]);
	}
	int ans = dp[1000];
	delete[] dp;
	return ans;
}

int main(){
	int n;
	cin >> n;
	unordered_map<int,int> mi;
	for(int i=0;i<n;i++){
		int a;
		cin >>a;
		mi[a]++;
	}
	cout << boredom(mi)<<endl;
}


#include <bits/stdc++.h>
#include <unordered_map>
using namespace std;
typedef long long ll;
long long boredom(unordered_map<ll,ll>& mi){
	long long* dp = new long long[100001]();
	memset(dp,0,100001*sizeof(ll));
	dp[0] = 0;
	for(ll i=1;i<100001;i++){
		dp[i] = dp[i-1];
			long long x = mi[i]*i;
			if(i-2>=0){
				x += dp[i-2];
			}
			dp[i] = max(dp[i],x);
		}
	long long ans = dp[1000];
	delete[] dp;
	return ans;
}
int main(){
	ll n;
	cin >> n;
	unordered_map<ll,ll> mi;
	for(ll i=0;i<n;i++){
		ll a;
		cin >>a;
		mi[a]++;
	}
	cout << boredom(mi)<<endl;
}


#include <bits/stdc++.h>
#include <unordered_map>
using namespace std;
int dp[100001];
int boredom(int* arr,int n){
	if(n<=0){
		return 0;
	}
	if(n==1){
		return arr[0];
	}
    if(dp[n]!=-1){
        return dp[n];
    }
	int f_c=0;
	while(arr[f_c]==arr[0]&&f_c<n){
		f_c++;
	}
	int o1=0;
	if(abs(arr[0]-arr[f_c])==1){
		int z=f_c;
		while(arr[z]==arr[f_c]){
			z++;
		}
		o1 = f_c*arr[0] + boredom(arr+z,n-z);
	}else{
		o1 = f_c*arr[0] + boredom(arr+f_c,n-f_c);
	}
	int o2 = boredom(arr+f_c,n-f_c);
	dp[n]= max(o1,o2);
    return dp[n];
}
// 	// method 2
// int boredom(unordered_map<int,int>& m){
// 	int* dp = new int[1001]();
// 	memset(dp,0,1001*sizeof(int));
// 	dp[1] = m[1];

// 	for(int i=2;i<=1000;i++){
// 		dp[i] = max((i*m[i])+dp[i-2],dp[i-1]);
// 	}
// 	int ans = dp[1000];
// 	delete[] dp;
// 	return ans;
// }

int main(){
	int n;
	cin >> n;
	int* arr =new int[n];
	for(int i=0;i<n;i++){
		cin >> arr[i];
	}
	sort(arr,arr+n);
    memset(dp,-1,100001*sizeof(int));
	cout << boredom(arr,n)<<endl;
}


#include <bits/stdc++.h>
#include <unordered_map>
using namespace std;
typedef long long int ll;
ll boredom(unordered_map<ll,ll>& mi){
	ll* dp = new ll[100001]();
	for(int i=0;i<100001;i++){
		dp[i]= 0;
	}
	dp[0] = 0;
	for(ll i=1;i<100001;i++){
		dp[i] = dp[i-1];
			ll x = mi[i]*i;
			if(i-2>=0){
				x += dp[i-2];
			}
			dp[i] = max(dp[i],x);
		}
	ll ans = dp[1000];
	delete[] dp;
	return ans;
}
int main(){
	ll n;
	cin >> n;
	unordered_map<ll,ll> mi;
	for(ll i=0;i<n;i++){
		ll a;
		cin >>a;
		mi[a]++;
	}
	cout << boredom(mi)<<endl;
}


#include <iostream>
#include <unordered_map>
using namespace std;
typedef long long int ll;
ll arr[100007];
long long int dp[100007];
ll boredom(){
	dp[0] = 0;
	dp[1] = arr[1];
	for(int i=2;i<=100000;i++){
		dp[i] = max(dp[i-1],(arr[i]*i)+dp[i-2]);
		}
	ll ans = dp[100000];
	return ans;
}
int main(){
	int n;
	cin >> n;
	 memset(arr, 0, sizeof(arr));
	for(ll i=0;i<n;i++){
		int x;
		cin >>x;
		arr[x]++;
	}
	cout << boredom()<<endl;
}

// #include <iostream>
// #include <algorithm>
// #include <cstring>
// using namespace std;

// long long int a[100007], n;
// long long int dp[100007];

// int main() {
//     memset(a, 0, sizeof(a));
//     cin >> n;
//     for (int i = 0; i < n; i++) {
//         int j;
//         cin >> j;
//         a[j]++;
//     }
//     dp[0] = 0;
//     dp[1] = a[1]; // a[1]*1 = a[1]
//     for (int i = 2; i <= 100000; i++) { // Finding optimal points until the ith number
//         dp[i] = max(dp[i - 1], dp[i - 2] + i*a[i]);
//     }
//     cout << dp[100000];
//     return 0;
// }


#include <bits/stdc++.h>
#include <unordered_map>
using namespace std;
int dp[100001];
int boredom(int* arr,int n){
	if(n<=0){
		return 0;
	}
	if(n==1){
		return arr[0];
	}
    if(dp[n]!=-1){
        return dp[n];
    }
	int f_c=0;
	while(arr[f_c]==arr[0]){
		f_c++;
	}
	int o1=0;
	if(abs(arr[0]-arr[f_c])==1){
		int z=f_c;
		while(arr[z]==arr[f_c]){
			z++;
		}
		o1 = f_c*arr[0] + boredom(arr+z,n-z);
	}else{
		o1 = f_c*arr[0] + boredom(arr+f_c,n-f_c);
	}
	int o2 = boredom(arr+f_c,n-f_c);
	dp[n]= max(o1,o2);
    return dp[n];
}
// 	// method 2
// int boredom(unordered_map<int,int>& m){
// 	int* dp = new int[1001]();
// 	memset(dp,0,1001*sizeof(int));
// 	dp[1] = m[1];

// 	for(int i=2;i<=1000;i++){
// 		dp[i] = max((i*m[i])+dp[i-2],dp[i-1]);
// 	}
// 	int ans = dp[1000];
// 	delete[] dp;
// 	return ans;
// }

int main(){
	int n;
	cin >> n;
	int* arr =new int[n];
	for(int i=0;i<n;i++){
		cin >> arr[i];
	}
	sort(arr,arr+n);
    memset(dp,-1,100001*sizeof(int));
	cout << boredom(arr,n)<<endl;
}


#include <bits/stdc++.h>
using namespace std;
// int dp[100001];
// int boredom(int* arr,int n){
// 	if(n<=0){
// 		return 0;
// 	}
// 	if(n==1){
// 		return arr[0];
// 	}
//     if(dp[n]!=-1){
//         return dp[n];
//     }
// 	int f_c=0;
// 	while(arr[f_c]==arr[0]){
// 		f_c++;
// 	}
// 	int o1=0;
// 	if(abs(arr[0]-arr[f_c])==1){
// 		int z=f_c;
// 		while(arr[z]==arr[f_c]){
// 			z++;
// 		}
// 		o1 = f_c*arr[0] + boredom(arr+z,n-z);
// 	}else{
// 		o1 = f_c*arr[0] + boredom(arr+f_c,n-f_c);
// 	}
// 	int o2 = boredom(arr+f_c,n-f_c);
// 	dp[n]= max(o1,o2);
//     return dp[n];
// }
// int solve(int n,vector<int>A){
//     int * arr = new int[n];
//     for(int i=0;i<n;i++){
//     	arr[i]= A[i];
//     }
//     sort(arr,arr+n);
//     memset(dp,-1,100001*sizeof(int));
//     return boredom(arr,n);
// }

	// method 2
int boredom(unordered_map<int,int>& m){
	int* dp = new int[1001]();
	memset(dp,0,1001*sizeof(int));
	dp[1] = m[1];

	for(int i=2;i<=1000;i++){
		dp[i] = max((i*m[i])+dp[i-2],dp[i-1]);
	}
	int ans = dp[1000];
	delete[] dp;
	return ans;
}
int solve(int n,vector<int>v){
	unordered_map<int,int> m;
	for(int i=0;i<v.size();i++){
		m[v[i]]++;
	}
	return boredom(m);
}


#include <bits/stdc++.h>
#include <unordered_map>
using namespace std;
typedef unsigned long long int ll;
ll boredom(unordered_map<ll,ll>& mi){
	ll* dp = new ll[100001]();
	memset(dp,0,100001*sizeof(ll));
	dp[0] = 0;
	for(ll i=1;i<100001;i++){
		dp[i] = dp[i-1];
			ll x = mi[i]*i;
			if(i-2>=0){
				x += dp[i-2];
			}
			dp[i] = max(dp[i],x);
		}
	ll ans = dp[1000];
	delete[] dp;
	return ans;
}
int main(){
	ll n;
	cin >> n;
	unordered_map<ll,ll> mi;
	for(ll i=0;i<n;i++){
		ll a;
		cin >>a;
		mi[a]++;
	}
	cout << boredom(mi)<<endl;
}


#include <bits/stdc++.h>
#include <unordered_map>
using namespace std;
typedef long long int ll;
ll boredom(unordered_map<ll,ll>& mi){
	ll* dp = new ll[100001]();
	for(int i=0;i<100001;i++){
		dp[i]= 0;
	}
	dp[1] = mi[1];
	for(ll i=2;i<100001;i++){
		dp[i] = max(dp[i-1],(mi[i]*i)+dp[i-2]);
		}
	ll ans = dp[1000];
	delete[] dp;
	return ans;
}
int main(){
	ll n;
	cin >> n;
	unordered_map<ll,ll> mi;
	for(ll i=0;i<n;i++){
		ll a;
		cin >>a;
		mi[a]++;
	}
	cout << boredom(mi)<<endl;
}


#include <bits/stdc++.h>
#include <unordered_map>
using namespace std;
typedef long long ll;
ll boredom(unordered_map<ll,ll>& mi){
	ll* dp = new ll[1000001]();
	for(int i=0;i<100001;i++){
		dp[i]= 0;
	}
	dp[1] = mi[1];
	for(ll i=2;i<1000001;i++){
		dp[i] = max(dp[i-1],(mi[i]*i)+dp[i-2]);
		}
	ll ans = dp[10000];
	delete[] dp;
	return ans;
}
int main(){
	ll n;
	cin >> n;
	unordered_map<ll,ll> mi;
	for(ll i=0;i<n;i++){
		ll a;
		cin >>a;
		mi[a]++;
	}
	cout << boredom(mi)<<endl;
}


#include <bits/stdc++.h>
#include <unordered_map>
using namespace std;
long long boredom(unordered_map<int,int>& mi){
	long long* dp = new long long[100001]();
	memset(dp,0,100001*sizeof(int));
	dp[0] = 0;
	for(int i=1;i<100001;i++){
		dp[i] = dp[i-1];
			long long x = mi[i]*i;
			if(i-2>=0){
				x += dp[i-2];
			}
			dp[i] = max(dp[i],x);
		}
	long long ans = dp[1000];
	delete[] dp;
	return ans;
}
int main(){
	int n;
	cin >> n;
	unordered_map<int,int> mi;
	for(int i=0;i<n;i++){
		int a;
		cin >>a;
		mi[a]++;
	}
	cout << boredom(mi)<<endl;
}


#include <iostream>
#include <unordered_map>
using namespace std;
typedef long long int ll;
ll arr[100007];
long long int dp[100007];
ll boredom(unordered_map<ll,ll>& mi){
	dp[1] = mi[1];
	for(ll i=2;i<=100000;i++){
		dp[i] = max(dp[i-1],(mi[i]*i)+dp[i-2]);
		}
	ll ans = dp[100000];
	return ans;
}
int main(){
	ll n;
	cin >> n;
	unordered_map<ll,ll> mi;
	for(ll i=0;i<n;i++){
		ll a;
		cin >>a;
		mi[a]++;
	}
	cout << boredom(mi)<<endl;
}


#include <iostream>
#include <map>

using namespace std;

map <int,int> Map;

const int MX=1e5+3;

int r[MX];

int dp(int n);

int main()
{
	int n,a,Max=0,Min=1000000;
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>a;
		if(a>Max)Max=a;
		if(a<Min)Min=a;
		Map[a]++;
	}
	r[Min]=Map[Min]*Min;
	r[Min+1]=max(r[Min],Map[Min+1]*(Min+1));
	cout<<dp(Max);
	return 0;
}
int dp(int n)
{
	if(r[n]!=0) return r[n];
	r[n]=max(dp(n-1),dp(n-2)+Map[n]*n);
	return r[n];
}


#include <bits/stdc++.h>
#include <map>

using namespace std;

const int MX=1e5+3;

int r[MX];
long long int f[MX];
map <int,int> Map;

long long int fun(long long int n);

int main ()
{
    int n,b,ko=1;
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>b;
        Map[b]++;
        if(Map[b]==1){
            r[ko]=b;
            ko++;
        }
    }
    r[0]=0;
    sort(r,r+ko);
    if(ko==2){
        cout<<Map[r[1]]*r[1];
        return 0;
    }
    f[1]=Map[r[1]]*r[1];
    cout<<fun(ko-1);
    return 0;
}
long long int fun(long long int n)
{
    if(n==0) return 0;
    if(f[n]!=0) return f[n];
    long int y=Map[r[n]]*r[n];
    if(r[n]==r[n-1]+1) f[n]=max(fun(n-1),fun(n-2)+y);
    else f[n]=fun(n-1)+y;
    return f[n];
}


#include <iostream>
#include <map>

using namespace std;

map <long int,long int> Map;

const int MX=1e5+3;

long int r[MX];

long int dp(long int n);

int main()
{
	long int n,a,Max=0,Min=1000000;
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>a;
		if(a>Max)Max=a;
		if(a<Min)Min=a;
		Map[a]++;
	}
	r[Min]=Map[Min]*Min;
	r[Min+1]=max(r[Min],Map[Min+1]*(Min+1));
	cout<<dp(Max);
	return 0;
}
long int dp(long int n)
{
	if(r[n]!=0) return r[n];
	r[n]=max(dp(n-1),dp(n-2)+Map[n]*n);
	return r[n];
}


#include <iostream>
#include <map>
using namespace std;
map<long int,long int> Map;

int main()
{
    long int n,m=0,a;
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>a;
        if(a>m)m=a;
        Map[a]+=a;
    }
    int f=1,sum1=0,sum2=0;
    for(int i=1;i<=m;i+=2) sum1+=Map[i];
    for(int i=2;i<=m;i+=2) sum2+=Map[i];
    cout<<max(sum1,sum2);
}


#include <iostream>
#include <map>
using namespace std;
map<long int,long int> Map;

int main()
{
    long int n,m=0,a,sum=0;
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>a;
        if(a>m)m=a;
        Map[a]+=a;
    }
    int f=1;
    for(int i=1;i<=m;i++){
        if(Map[i]>=Map[i-1]+Map[i+1])sum+=Map[i];
        if(Map[1]+Map[3]>Map[2]  && f){
            sum+=Map[1];
            f=0;
        }
    }
    cout<<sum;
}


#include <bits/stdc++.h>
#include <map>

using namespace std;

const int MX=1e5+3;

int r[MX];
long int f[MX];
map <int,int> Map;

long int fun(long int n);

int main ()
{
    int n,b,ko=1;
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>b;
        Map[b]++;
        if(Map[b]==1){
            r[ko]=b;
            ko++;
        }
    }
    r[0]=0;
    sort(r,r+ko);
    f[1]=Map[r[1]]*r[1];
    cout<<fun(ko-1);
    return 0;
}
long int fun(long int n)
{
    if(n==0) return 0;
    if(f[n]!=0) return f[n];
    long int y=Map[r[n]]*r[n];
    if(r[n]==r[n-1]+1) f[n]=max(fun(n-1),fun(n-2)+y);
    else f[n]=fun(n-1)+y;
    return f[n];
}


#include <bits/stdc++.h>
#include <map>

using namespace std;

const int MX=1e5+3;

long int r[MX];
long long int f[MX];
map <long int,long int> Map;

long long int fun(long long int n);

int main ()
{
    long int n,b,ko=1;
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>b;
        Map[b]++;
        if(Map[b]==1){
            r[ko]=b;
            ko++;
        }
    }
    r[0]=0;
    sort(r,r+ko);
    if(ko==2){
        cout<<Map[r[1]]*r[1];
        return 0;
    }
    f[1]=Map[r[1]]*r[1];
    cout<<fun(ko-1);
    return 0;
}
long long int fun(long long int n)
{
    if(n==0) return 0;
    if(f[n]!=0) return f[n];
    long int y=Map[r[n]]*r[n];
    if(r[n]==r[n-1]+1) f[n]=max(fun(n-1),fun(n-2)+y);
    else f[n]=fun(n-1)+y;
    return f[n];
}


#include <bits/stdc++.h>
#include <map>

using namespace std;

const int MX=1e5+3;

int r[MX];
long long int f[MX];
map <int,int> Map;

long long int fun(long long int n);

int main ()
{
    int n,b,ko=1;
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>b;
        Map[b]++;
        if(Map[b]==1){
            r[ko]=b;
            ko++;
        }
    }
    r[0]=0;
    sort(r,r+ko);
    f[1]=Map[r[1]]*r[1];
    cout<<fun(ko-1);
    return 0;
}
long long int fun(long long int n)
{
    if(n==0) return 0;
    if(f[n]!=0) return f[n];
    long int y=Map[r[n]]*r[n];
    if(r[n]==r[n-1]+1) f[n]=max(fun(n-1),fun(n-2)+y);
    else f[n]=fun(n-1)+y;
    return f[n];
}


#include <iostream>
#include <map>

using namespace std;

map <int,int> Map;

const int MX=1e5+3;

int r[MX];

int dp(int n);

int main()
{
	int n,a,Max=0;
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>a;
		if(a>Max)Max=a;
		Map[a]++;
	}
	r[1]=Map[1];
	r[2]=max(r[1],Map[2]*2);
	cout<<dp(n);
	return 0;
}
int dp(int n)
{
	if(r[n]!=0) return r[n];
	r[n]=max(dp(n-1),dp(n-2)+Map[n]*n);
	return r[n];
}


#include <bits/stdc++.h>
#include <map>

using namespace std;

const int MX=1e5+3;
#define ll long long
ll r[MX];
ll f[MX];
map <ll,ll> Map;

ll fun(long long int n);

int main ()
{
    ll n,b,ko=1;
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>b;
        Map[b]++;
        if(Map[b]==1){
            r[ko]=b;
            ko++;
        }
    }
    r[0]=0;
    sort(r,r+ko);
    if(ko==2){
        cout<<Map[r[1]]*r[1];
        return 0;
    }
    f[1]=Map[r[1]]*r[1];
    cout<<fun(ko-1);
    return 0;
}
ll fun(ll int n)
{
    if(n==0) return 0;
    if(f[n]!=0) return f[n];
    ll y=Map[r[n]]*r[n];
    if(r[n]==r[n-1]+1) f[n]=max(fun(n-1),fun(n-2)+y);
    else f[n]=fun(n-1)+y;
    return f[n];
}


#include <bits/stdc++.h>
#include <map>

using namespace std;

const int MX=1e5+3;

long int r[MX];
long long int f[MX];
map <long int,long int> Map;

long long int fun(long long int n);

int main ()
{
    long int n,b,ko=1;
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>b;
        Map[b]++;
        if(Map[b]==1){
            r[ko]=b;
            ko++;
        }
    }
    r[0]=0;
    sort(r,r+ko);
    f[1]=Map[r[1]]*r[1];
    cout<<fun(ko-1);
    return 0;
}
long long int fun(long long int n)
{
    if(n==0) return 0;
    if(f[n]!=0) return f[n];
    long int y=Map[r[n]]*r[n];
    if(r[n]==r[n-1]+1) f[n]=max(fun(n-1),fun(n-2)+y);
    else f[n]=fun(n-1)+y;
    return f[n];
}


#include <bits/stdc++.h>
#include <map>

using namespace std;

const int MX=1e5+3;

int r[MX];
long int f[MX];
map <int,int> Map;

long int fun(long int n);

int main ()
{
    int n,b,ko=1;
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>b;
        Map[b]++;
        if(Map[b]==1){
            r[ko]=b;
            ko++;
        }
    }
    r[0]=0;
    sort(r,r+ko);
    f[1]=Map[r[1]]*r[1];
    cout<<fun(ko-1);
}
long int fun(long int n)
{
    if(n==0) return 0;
    if(f[n]!=0) return f[n];
    long int y=Map[r[n]]*r[n];
    if(r[n]==r[n-1]+1) return max(fun(n-1),fun(n-2)+y);
    else return fun(n-1)+y;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long int n,a;
    cin >> n;
    long long int ara[n+1]={0};
    for(int i=0;i<n;i++)
    {
        cin >> a;
        ara[a]=ara[a]+a;
    }
    for(int i=3;i<=n;i++)
    {
        if(ara[i-3]>=ara[i-2])
        {
            ara[i]+=ara[i-3];
        }
        else
        {
            ara[i]+=ara[i-2];
        }
    }
    if(ara[n]>=ara[n-1])
    {
        cout << ara[n];
    }
    else cout << ara[n-1];
}


#include<bits/stdc++.h>
using namespace std;
long long int ara[100005];
int main()
{
    long long int n,a,mx=0;
    unsigned long long int total1=0,total2=0;
    cin >> n;
    for(int i=0;i<n;i++)
    {
        cin >> a;
        ara[a]=ara[a]+a;
        if(a>mx)
            mx=a;
    }
    for(int i=1;i<=mx;i++)
    {
        if(i%2==0)
            total1+=ara[i];
        else
            total2+=ara[i];
    }
    if(total1 > total2)
        cout << total1;
    else
        cout << total2;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long int n,a;
    cin >> n;
    long long int ara[n+1]={0};
    for(int i=0;i<n;i++)
    {
        cin >> a;
        ara[a]+=a;
    }
    for(int i=3;i<=n;i++)
    {
        if(ara[i-3]>=ara[i-2])
        {
            ara[i]+=ara[i-3];
        }
        else
        {
            ara[i]+=ara[i-2];
        }
    }
    if(ara[n]>=ara[n-1])
    {
        cout << ara[n];
    }
    else cout << ara[n-1];
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    long int n,a;
    cin >> n;
    long int ara[n+1]={0};
    for(int i=0;i<n;i++)
    {
        cin >> a;
        ara[a]+=a;
    }
    for(int i=3;i<=n;i++)
    {
        if(ara[i-3]>=ara[i-2])
        {
            ara[i]+=ara[i-3];
        }
        else
        {
            ara[i]+=ara[i-2];
        }
    }
    if(ara[n]>=ara[n-1])
    {
        cout << ara[n];
    }
    else cout << ara[n-1];
}


#include<bits/stdc++.h>
using namespace std;
int ara[100005],memo[100005];
int func(int x)
{
    if(memo[x]==-1)
    {
        for(int i=x+2;i<100005;i++)
        {
            memo[x]=max(memo[x],ara[x]+func(i));
        }
        return memo[x];
    }
    else return memo[x];
}
int main()
{
    int n,a;
    cin >> n;
    for(int i=0;i<n;i++)
    {
        cin >> a;
        ara[a]+=a;
        memo[a]=-1;
    }
    int x=func(1);
    int y=func(2);
    cout << max(x,y);
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,a;
    cin >> n;
    int ara[n+1]={0};
    for(int i=0;i<n;i++)
    {
        cin >> a;
        ara[a]+=a;
    }
    for(int i=3;i<=n;i++)
    {
        if(ara[i-3]>=ara[i-2])
        {
            ara[i]+=ara[i-3];
        }
        else
        {
            ara[i]+=ara[i-2];
        }
    }
    if(ara[n]>=ara[n-1])
    {
        cout << ara[n];
    }
    else cout << ara[n-1];
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    unsigned long long int n,a;
    cin >> n;
    unsigned long long int ara[n+1]={0};
    for(int i=0;i<n;i++)
    {
        cin >> a;
        ara[a]+=a;
    }
    for(int i=3;i<=n;i++)
    {
        if(ara[i-3]>=ara[i-2])
        {
            ara[i]+=ara[i-3];
        }
        else
        {
            ara[i]+=ara[i-2];
        }
    }
    if(ara[n]>=ara[n-1])
    {
        cout << ara[n];
    }
    else cout << ara[n-1];
}


#include<bits/stdc++.h>
using namespace std;
long long int ara[100005],ara1[100005],ara2[100005];
vector <pair <long long int, long long int>> v;
int main()
{
    long long int n,mx=0,a;
    cin >> n;
    for(int i=0;i<n;i++)
    {
        cin >> a;
        ara[a]=ara[a]+a;
    }
    for(int i=3;i<100005;i++)
    {
        ara1[i]=ara[i-3]+ara[i];
        ara2[i]=ara[i-2]+ara[i];
        if(mx<ara1[i]) mx=ara1[i];
        if(mx<ara2[i]) mx=ara2[i];
    }
    cout << mx;
}


#include<bits/stdc++.h>
using namespace std;
int ara[100005],memo[100005];
int func(int x)
{
    if(memo[x]==-1)
    {
        for(int i=x+2;i<100005;i++)
        {
            memo[x]=max(memo[x],ara[x]+func(i));
        }
        return memo[x];
    }
    else return memo[x];
}
int main()
{
    int n,a;
    cin >> n;
    for(int i=0;i<n;i++)
    {
        cin >> a;
        ara[a]+=a;
        memo[a]=-1;
    }
    int ans=0;
    for(int i=1;i<100005;i++)
    {
        ans=max(ans,func(i));
    }
    cout << ans;
}


#include<bits/stdc++.h>
using namespace std;
long long int ara[100007];
int main()
{
    long long int n,a;
    cin >> n;
    memset(ara,0,sizeof(ara));
    for(int i=0;i<n;i++)
    {
        cin >> a;
        ara[a]=ara[a]+a;
    }
    for(int i=3;i<=100007;i++)
    {
        if(ara[i-3]>=ara[i-2])
        {
            ara[i]+=ara[i-3];
        }
        else
        {
            ara[i]+=ara[i-2];
        }
    }
    if(ara[100007]>=ara[100006])
    {
        cout << ara[100007];
    }
    else cout << ara[100006];
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long int n,a;
    cin >> n;
    long long int ara[n+3]={0};
    for(int i=0;i<n;i++)
    {
        cin >> a;
        ara[a]=ara[a]+a;
    }
    for(int i=3;i<=n;i++)
    {
        if(ara[i-3]>=ara[i-2])
        {
            ara[i]+=ara[i-3];
        }
        else
        {
            ara[i]+=ara[i-2];
        }
    }
    if(ara[n]>=ara[n-1])
    {
        cout << ara[n];
    }
    else cout << ara[n-1];
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long int n,a;
    cin >> n;
    long long int ara[n+3];
    memset(ara,0,sizeof(ara));
    for(int i=0;i<n;i++)
    {
        cin >> a;
        ara[a]=ara[a]+a;
    }
    for(int i=3;i<=n;i++)
    {
        if(ara[i-3]>=ara[i-2])
        {
            ara[i]+=ara[i-3];
        }
        else
        {
            ara[i]+=ara[i-2];
        }
    }
    if(ara[n]>=ara[n-1])
    {
        cout << ara[n];
    }
    else cout << ara[n-1];
}


#include<bits/stdc++.h>
using namespace std;
long long int ara[100007];
int main()
{
    long long int n,a;
    cin >> n;
    memset(ara,0,sizeof(ara));
    for(int i=0;i<n;i++)
    {
        cin >> a;
        ara[a]=ara[a]+a;
    }
    for(int i=3;i<=n;i++)
    {
        if(ara[i-3]>=ara[i-2])
        {
            ara[i]+=ara[i-3];
        }
        else
        {
            ara[i]+=ara[i-2];
        }
    }
    if(ara[n]>=ara[n-1])
    {
        cout << ara[n];
    }
    else cout << ara[n-1];
}


#include<bits/stdc++.h>
using namespace std;
int ara[100005],memo[100005];
int func(int x)
{
    if(x>100000) return 0;
    if(memo[x]==-1)
    {
        for(int i=x+2;i<100005;i++)
        {
            memo[x]=max(memo[x],ara[x]+func(i));
        }
        return memo[x];
    }
    else return memo[x];
}
int main()
{
    int n,a;
    cin >> n;
    int mn=100005;
    for(int i=0;i<n;i++)
    {
        cin >> a;
        ara[a]+=a;
        memo[a]=-1;
        if(a<mn)mn=a;
    }
    int x,y;
    x=func(mn);
    y=func(mn+1);
    cout << max(x,y);
}


#include<bits/stdc++.h>
using namespace std;
long long b[100005];
map<long long ,long long > y;
long long ans[100005]={0};
long long dp(long long  n)
{

    for (long long i=2;i<=n;i++){
        if (b[i]!=b[i-1]+1){
            ans[i]=ans[i-1]+b[i]*y[b[i]];
        }else{
            ans[i]=max(ans[i-1],ans[i-2]+y[b[i]]*b[i]);
        }
    }
    return ans[n];
}
int main()
{
 	long long n;
    scanf("%llu",&n);
    long long a[100005];

    for (long long i=0;i<n;i++){
        scanf("%d",&a[i]);
        if (y[a[i]]){
            y[a[i]]+=1;
        }else{
            y[a[i]]=1;
        }
    }
    sort(a,a+n);
    set<long long > x(a,a+n);
    set<long long> ::iterator it;
    long long j=2;

    for (it=x.begin();it!=x.end();it++){
        b[j]=*it;
        j+=1;
    }
    cout<<dp(j-1);
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
long long b[100005];
map<long long ,long long > y;
long long ans[100005]={0};
long long dp(int n)
{

    for (int i=2;i<=n;i++){
        if (b[i]!=b[i-1]+1){
            ans[i]=ans[i-1]+b[i]*y[b[i]];
        }else{
            ans[i]=max(ans[i-1],ans[i-2]+y[b[i]]*b[i]);
        }
    }
    return ans[n];
}
int main()
{
 	long long n;
    scanf("%llu",&n);
    long long a[100005];

    for (long long i=0;i<n;i++){
        scanf("%d",&a[i]);
        if (y[a[i]]){
            y[a[i]]+=1;
        }else{
            y[a[i]]=1;
        }
    }
    sort(a,a+n);
    set<long long > x(a,a+n);
    set<long long> ::iterator it;
    long long j=2;

    for (it=x.begin();it!=x.end();it++){
        b[j]=*it;
        j+=1;
    }
    cout<<dp(j-1);
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int b[100005];
map<int ,int > y;
int ans[100005];
int dp(int n)
{
    for (int i=2;i<=n;i++){
        if (b[i]!=b[i-1]+1){
            ans[i]=ans[i-1]+b[i]*y[b[i]];
        }else{
            ans[i]=max(ans[i-1],ans[i-2]+y[b[i]]*b[i]);
        }
    }
    return ans[n];
}
int main()
{
    int n;
    scanf("%d",&n);
    int a[100005];

    for (int i=0;i<n;i++){
        scanf("%d",&a[i]);
        if (y[a[i]]){
            y[a[i]]+=1;
        }else{
            y[a[i]]=1;
        }
    }
    sort(a,a+n);
    set<int > x(a,a+n);
    set<int> ::iterator it;
    int j=2;
    for (it=x.begin();it!=x.end();it++){
        b[j]=*it;
        j+=1;
    }
    cout<<dp(j-1);
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int b[100005];
map<int ,int > y;
long long ans[100005]={0};
long long dp(int n)
{

    for (int i=2;i<=n;i++){
        if (b[i]!=b[i-1]+1){
            ans[i]=ans[i-1]+b[i]*y[b[i]];
        }else{
            ans[i]=max(ans[i-1],ans[i-2]+y[b[i]]*b[i]);
        }
    }
    return ans[n];
}
int main()
{
 	long long n;
    scanf("%d",&n);
    long long a[100005];

    for (int i=0;i<n;i++){
        scanf("%d",&a[i]);
        if (y[a[i]]){
            y[a[i]]+=1;
        }else{
            y[a[i]]=1;
        }
    }
    sort(a,a+n);
    set<int > x(a,a+n);
    set<int> ::iterator it;
    int j=2;
    b[1]=-12324;
    for (it=x.begin();it!=x.end();it++){
        b[j]=*it;
        j+=1;
    }
    cout<<dp(j+10);
    return 0;
}


#include <iostream>
using namespace std;
long long a[100001],i,n,k;
int main() {
    cin>>n;
	for(;i<n;i++)cin>>k,a[k]+=k;
	for(i=2;i<100001;i++)a[i]=max(a[i-1],a[i]+a[i-2]);
	cout<<a[i-1];
}


#include<bits/stdc++.h>
using namespace std;
int b[100005];
map<int ,int > y;
int ans[100005];
int dp(int n)
{

    for (int i=2;i<=n;i++){
        if (b[i]!=b[i-1]+1){
            ans[i]=ans[i-1]+b[i]*y[b[i]];
        }else{
            ans[i]=max(ans[i-1],ans[i-2]+y[b[i]]*b[i]);
        }
    }
    return ans[n];
}
int main()
{
    int n;
    scanf("%d",&n);
    int a[100005];

    for (int i=0;i<n;i++){
        scanf("%d",&a[i]);
        if (y[a[i]]){
            y[a[i]]+=1;
        }else{
            y[a[i]]=1;
        }
    }
    sort(a,a+n);
    set<int > x(a,a+n);
    set<int> ::iterator it;
    int j=2;
    b[1]=0;
    for (it=x.begin();it!=x.end();it++){
        b[j]=*it;
        j+=1;
    }
    cout<<dp(j-1);
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int b[100005];
map<int ,int > y;
int ans[100005];
int dp(int n)
{
    ans[2]=b[2]*y[b[2]];
    ans[1]=0;
    for (int i=3;i<=n;i++){
        if (b[i]!=b[i-1]+1){
            ans[i]=ans[i-1]+b[i]*y[b[i]];
        }else{
            ans[i]=max(ans[i-1],ans[i-2]+y[b[i]]*b[i]);
        }
    }
    return ans[n];
}
int main()
{
    int n;
    scanf("%d",&n);
    int a[100005];

    for (int i=0;i<n;i++){
        scanf("%d",&a[i]);
        if (y[a[i]]){
            y[a[i]]+=1;
        }else{
            y[a[i]]=1;
        }
    }
    sort(a,a+n);
    set<int > x(a,a+n);
    set<int> ::iterator it;
    int j=2;

    for (it=x.begin();it!=x.end();it++){
        b[j]=*it;
        j+=1;
    }
    cout<<dp(j-1);
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int b[100005];
map<int ,int > y;
long long ans[100005];
int dp(int n)
{

    for (int i=2;i<=n;i++){
        if (b[i]!=b[i-1]+1){
            ans[i]=ans[i-1]+b[i]*y[b[i]];
        }else{
            ans[i]=max(ans[i-1],ans[i-2]+y[b[i]]*b[i]);
        }
    }
    return ans[n];
}
int main()
{
    int n;
    scanf("%d",&n);
    int a[100005];

    for (int i=0;i<n;i++){
        scanf("%d",&a[i]);
        if (y[a[i]]){
            y[a[i]]+=1;
        }else{
            y[a[i]]=1;
        }
    }
    sort(a,a+n);
    set<int > x(a,a+n);
    set<int> ::iterator it;
    int j=2;
    b[1]=0;
    for (it=x.begin();it!=x.end();it++){
        b[j]=*it;
        j+=1;
    }
    cout<<dp(j-1);
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int b[100005];
map<int ,int > y;
long long ans[100005]={0};
long long dp(int n)
{

    for (int i=2;i<=n;i++){
        if (b[i]!=b[i-1]+1){
            ans[i]=ans[i-1]+b[i]*y[b[i]];
        }else{
            ans[i]=max(ans[i-1],ans[i-2]+y[b[i]]*b[i]);
        }
    }
    return ans[n];
}
int main()
{
 	long long n;
    scanf("%d",&n);
    long long a[100005];

    for (int i=0;i<n;i++){
        scanf("%d",&a[i]);
        if (y[a[i]]){
            y[a[i]]+=1;
        }else{
            y[a[i]]=1;
        }
    }
    sort(a,a+n);
    set<int > x(a,a+n);
    set<int> ::iterator it;
    int j=2;

    for (it=x.begin();it!=x.end();it++){
        b[j]=*it;
        j+=1;
    }
    cout<<dp(j-1);
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int b[100005];
map<int ,int > y;
long long ans[100005]={0};
int dp(int n)
{

    for (int i=2;i<=n;i++){
        if (b[i]!=b[i-1]+1){
            ans[i]=ans[i-1]+b[i]*y[b[i]];
        }else{
            ans[i]=max(ans[i-1],ans[i-2]+y[b[i]]*b[i]);
        }
    }
    return ans[n];
}
int main()
{
  int n;
    scanf("%d",&n);
    int a[100005];

    for (int i=0;i<n;i++){
        scanf("%d",&a[i]);
        if (y[a[i]]){
            y[a[i]]+=1;
        }else{
            y[a[i]]=1;
        }
    }
    sort(a,a+n);
    set<int > x(a,a+n);
    set<int> ::iterator it;
    int j=2;
    b[1]=-12324;
    for (it=x.begin();it!=x.end();it++){
        b[j]=*it;
        j+=1;
    }
    cout<<dp(j-1);
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
long long b[100005];
map<long long ,long long > y;
long long ans[100005]={0};
long long dp(int n)
{

    for (int i=2;i<=n;i++){
        if (b[i]!=b[i-1]+1){
            ans[i]=ans[i-1]+b[i]*y[b[i]];
        }else{
            ans[i]=max(ans[i-1],ans[i-2]+y[b[i]]*b[i]);
        }
    }
    return ans[n];
}
int main()
{
 	long long n;
    scanf("%llu",&n);
    long long a[100005];

    for (long long i=0;i<n;i++){
        scanf("%d",&a[i]);
        if (y[a[i]]){
            y[a[i]]+=1;
        }else{
            y[a[i]]=1;
        }
    }
    sort(a,a+n);
    set<long long > x(a,a+n);
    set<long> ::iterator it;
    long long j=2;

    for (it=x.begin();it!=x.end();it++){
        b[j]=*it;
        j+=1;
    }
    cout<<dp(j-1);
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int ans=0;
int n;
map <int ,int > number;

int main()
{

    int s[100005];
    scanf("%d",&n);
    int a[100005];
    for (int i=0;i<n;i++){
        scanf("%d",&a[i]);

        if (number[a[i]]){
            number[a[i]]+=1;
        }else{
            number[a[i]]=1;
        }

    }
    sort(a,a+n);
    set <int > number2(a,a+n);
    set<int>::iterator it;
    int j=1;
    s[0]=0;
    for (it=number2.begin();it!=number2.end();it++){
        s[j]=*it;
        j++;
    }
    for(int i=1;i<j;i++){
        if (s[i]*number[s[i]]>=s[i-1]*number[s[i-1]]+s[i+1]*number[s[i+1]]){
        if (i==3){
            ans+=s[1]*number[s[1]];
        }
        ans+=s[i]*number[s[i]];
    }
    }
    cout<<ans;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int b[100005];
map<int ,int > y;
int ans[100005];
int dp(int n)
{
    for (int i=2;i<=n;i++){
        if (b[i]!=b[i-1]+1){
            ans[i]=ans[i-1]+b[i]*y[b[i]];
        }else{
            ans[i]=max(ans[i-1],ans[i-2]+y[b[i]]*b[i]);
        }
    }
    return ans[n];
}
int main()
{
    int n;
    scanf("%d",&n);
    int a[100005];

    for (int i=0;i<n;i++){
        scanf("%d",&a[i]);
        if (y[a[i]]){
            y[a[i]]+=1;
        }else{
            y[a[i]]=1;
        }
    }
    sort(a,a+n);
    set<int > x(a,a+n);
    set<int> ::iterator it;
    int j=2;
    b[0]=-2143;
    b[1]=-2134;
    for (it=x.begin();it!=x.end();it++){
        b[j]=*it;
        j+=1;
    }
    cout<<dp(j-1);
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int b[100005];
map<int ,int > y;
long long ans[100005]={0};
int dp(int n)
{

    for (int i=2;i<=n;i++){
        if (b[i]!=b[i-1]+1){
            ans[i]=ans[i-1]+b[i]*y[b[i]];
        }else{
            ans[i]=max(ans[i-1],ans[i-2]+y[b[i]]*b[i]);
        }
    }
    return ans[n];
}
int main()
{
    int n;
    scanf("%d",&n);
    int a[100005];

    for (int i=0;i<n;i++){
        scanf("%d",&a[i]);
        if (y[a[i]]){
            y[a[i]]+=1;
        }else{
            y[a[i]]=1;
        }
    }
    sort(a,a+n);
    set<int > x(a,a+n);
    set<int> ::iterator it;
    int j=2;
    b[1]=0;
    for (it=x.begin();it!=x.end();it++){
        b[j]=*it;
        j+=1;
    }
    cout<<dp(j-1);
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
void s_y() {
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
}

int main() {
    s_y();
    int n;
    cin >> n;
    ll count[100005];
    memset(count, 0, sizeof(count));
    for (int i = 0; i < n; i++) {
        int x; cin >> x;
        count[x] += 1;
    }
    ll max2 = 0;
    ll max1 = 1 * count[1];
    for (int i = 2; i < 100001; i++) {
        int currmax = max(max1, max2 + i * count[i]);
        max2 = max1; \
        max1 = currmax;
    }
    cout << max1 << "\n";

}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
void s_y() {
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
}

int main() {
    s_y();
    int n;
    cin >> n;
    map<ll, ll>m;
    for (int i = 0; i < n; i++) {
        int x; cin >> x;
        m[x] += 1;
    }
    vector<pair<int, int>>v;
    for ( auto it : m) {
        v.push_back(make_pair(it.first, it.second));
    }
    vector<ll>f((int)v.size());
    f[0] = v[0].first * v[0].second;
    for (int i = 1; i < (int)v.size(); i++) {
        int prev = i - 1;
        if (v[i].first == v[prev].first + 1) {
            prev--;
        }
        if (prev >= 0) {
            f[i] = max(f[prev] + (v[i].first) * v[i].second, f[i - 1]);
        }
        else {f[i] = (v[i].first) * v[i].second;}
    }
    cout << f[(int)v.size() - 1] << "\n";

}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
void s_y() {
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
}

int main() {
    s_y();
    int n;
    cin >> n;
    ll count[100005];
    memset(count, 0, sizeof(count));
    for (int i = 0; i < n; i++) {
        int x; cin >> x;
        count[x] += 1;
    }
    ll max2 = 0;
    ll max1 = 1 * count[1];
    for (int i = 2; i < 100001; i++) {
        ll currmax = max(max1, max2 + i * count[i]);
        max2 = max1;
        max1 = currmax;
    }
    cout << max1 << "\n";

}


#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <map>
#include <vector>

using namespace std;

template<class T> T max(T a, T b, T c) {
    return max(a, max(b, c));
}

int nextInt() {
    int x = 0, p = 1;
    char c;
    do {
        c = getchar();
    } while (c <= 32);
    if (c == '-') {
        p = -1;
        c = getchar();
    }
    while (c >= '0' && c <= '9') {
        x = x * 10 + c - '0';
        c = getchar();
    }
    return x * p;
}

const int maxn = 111111;

int n;
map<int, int> m;
vector<pair<int, int> > v;
long long f[maxn];

int main() {
    //freopen("input.txt", "r", stdin);
    n = nextInt();
    while (n--) {
        int x = nextInt();
        m[x]++;
    }
    for (map<int, int>::iterator it = m.begin(); it != m.end(); it++) {
        v.push_back(make_pair(it->first, it->second));
    }
    for (int i = 0; i < (int)v.size(); i++) {
        int pr = i - 1;
        while (pr >= 0 && v[pr].first + 1 == v[i].first) pr--;
        if (pr == -1) f[i] = 1LL * v[i].first * v[i].second;
        else f[i] = f[pr] + 1LL * v[i].first * v[i].second;
        if (i != 0)
            f[i] = max(f[i], f[i - 1]);
    }


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
void s_y() {
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
}

int main() {
    s_y();
    int n;
    cin >> n;
    map<ll, ll>m; m[0] = 0;
    for (int i = 1; i <= 100001; i++) {
        m[i] = 0;
    }
    for (int i = 0; i < n; i++) {
        int x; cin >> x;
        m[x] += 1;
    } ll ans = 0;
    int i = 1;
    while ( i <= 100000 ) {
        ll osum = 0; ll esum = 0; int f = 0;
        while (i <= 100000 && m[i] != 0) {
            if (f == 0) {osum += (m[i] * i); f = 1;}
            else {f = 0; esum += (m[i] * i);}
            i++;
        }
        i++;
        if (osum > esum) {ans += osum;}
        else {ans += esum;}
    }
    cout << ans << "\n";

}


    #include <iostream>
    #include <cstdio>
    #include <cstdlib>
    #include <cstring>
    #include <map>
    #include <vector>

    using namespace std;

    template<class T> T max(T a, T b, T c) {
        return max(a, max(b, c));
    }

    int nextInt() {
        int x = 0, p = 1;
        char c;
        do {
            c = getchar();
        } while (c <= 32);
        if (c == '-') {
            p = -1;
            c = getchar();
        }
        while (c >= '0' && c <= '9') {
            x = x * 10 + c - '0';
            c = getchar();
        }
        return x * p;
    }

    const int maxn = 111111;

    int n;
    map<int, int> m;
    vector<pair<int, int> > v;
    long long f[maxn];

    int main() {
        //freopen("input.txt", "r", stdin);
        n = nextInt();
        while (n--) {
            int x = nextInt();
            m[x]++;
        }
        for (map<int, int>::iterator it = m.begin(); it != m.end(); it++) {
            v.push_back(make_pair(it->first, it->second));
        }
        for (int i = 0; i < (int)v.size(); i++) {
            int pr = i - 1;
            if (pr >= 0 && v[pr].first + 1 == v[i].first) pr--;
            if (pr == -1) f[i] = 1LL * v[i].first * v[i].second;
            else f[i] = f[pr] + 1LL * v[i].first * v[i].second;
            if (i != 0)
                f[i] = max(f[i], f[i - 1]);
        }
        cout << f[(int)v.size() - 1] << '\n';
    }


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
void s_y() {
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
}

int main() {
    s_y();
    int n;
    cin >> n;
    map<ll, ll>m;
    for (int i = 0; i < n; i++) {
        int x; cin >> x;
        m[x] += 1;
    }
    vector<pair<int, int>>v;
    for ( auto it : m) {
        v.push_back(make_pair(it.first, it.second));
    }
    vector<ll>f((int)v.size());
    for (int i = 0; i < (int)f.size(); i++) {
        f[i] = 0;
    }
    f[0] = v[0].first * v[0].second;
    for (int i = 1; i < (int)v.size(); i++) {
        int prev = i - 1;
        if (v[i].first == (v[prev].first + 1)) {
            prev--;
        }
        if (prev >= 0 ) {
            f[i] = max(f[prev] + v[i].first * v[i].second, f[i - 1]);
        }
        else {f[i] = v[i].first* v[i].second;}
    }
    cout << f[(int)v.size() - 1] << "\n";

}


    #include <iostream>
    #include <cstdio>
    #include <cstdlib>
    #include <cstring>
    #include <map>
    #include <vector>

    using namespace std;

    template<class T> T max(T a, T b, T c) {
        return max(a, max(b, c));
    }

    int nextInt() {
        int x = 0, p = 1;
        char c;
        do {
            c = getchar();
        } while (c <= 32);
        if (c == '-') {
            p = -1;
            c = getchar();
        }
        while (c >= '0' && c <= '9') {
            x = x * 10 + c - '0';
            c = getchar();
        }
        return x * p;
    }

    const int maxn = 111111;

    int n;
    map<int, int> m;
    vector<pair<int, int> > v;
    long long f[maxn];

    int main() {
        //freopen("input.txt", "r", stdin);
        n = nextInt();
        while (n--) {
            int x = nextInt();
            m[x]++;
        }
        for (map<int, int>::iterator it = m.begin(); it != m.end(); it++) {
            v.push_back(make_pair(it->first, it->second));
        }
        for (int i = 0; i < (int)v.size(); i++) {
            int pr = i - 1;
            while (pr >= 0 && v[pr].first + 1 == v[i].first) pr--;
            if (pr == -1) f[i] = 1LL * v[i].first * v[i].second;
            else f[i] = f[pr] + 1LL * v[i].first * v[i].second;
            if (i != 0)
                f[i] = max(f[i], f[i - 1]);
        }
        cout << f[(int)v.size() - 1] << '\n';
    }


#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <map>
#include <vector>

using namespace std;

template<class T> T max(T a, T b, T c) {
    return max(a, max(b, c));
}

int nextInt() {
    int x = 0, p = 1;
    char c;
    do {
        c = getchar();
    } while (c <= 32);
    if (c == '-') {
        p = -1;
        c = getchar();
    }
    while (c >= '0' && c <= '9') {
        x = x * 10 + c - '0';
        c = getchar();
    }
    return x * p;
}

const int maxn = 111111;

int n;
map<int, int> m;
vector<pair<int, int> > v;
long long f[maxn];

int main() {
    //freopen("input.txt", "r", stdin);
    n = nextInt();
    while (n--) {
        int x = nextInt();
        m[x]++;
    }
    for (map<int, int>::iterator it = m.begin(); it != m.end(); it++) {
        v.push_back(make_pair(it->first, it->second));
    }
    for (int i = 0; i < (int)v.size(); i++) {
        int pr = i - 1;
        if(pr >= 0 && v[pr].first + 1 == v[i].first) pr--;
        if (pr == -1) f[i] = 1LL * v[i].first * v[i].second;
        else f[i] = f[pr] + 1LL * v[i].first * v[i].second;
        if (i != 0)
            f[i] = max(f[i], f[i - 1]);
    }
    co


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
void s_y() {
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
}

int main() {
    s_y();
    int n;
    cin >> n;
    map<ll, ll>m;
    for (int i = 0; i < n; i++) {
        int x; cin >> x;
        m[x] += 1;
    }
    vector<pair<int, int>>v;
    for ( auto it : m) {
        v.push_back(make_pair(it.first, it.second));
    }
    vector<ll>f((int)v.size());
    for (int i = 0; i < (int)f.size(); i++) {
        f[i] = 0;
    }
    f[0] = v[0].first * v[0].second;
    for (int i = 1; i < (int)v.size(); i++) {
        int prev = i - 1;
        if (v[i].first == v[prev].first + 1) {
            prev--;
        }
        if (prev >= 0) {
            f[i] = max(f[prev] + (v[i].first) * v[i].second, f[i - 1]);
        }
        else {f[i] = (v[i].first) * v[i].second;}
    }
    cout << f[(int)v.size() - 1] << "\n";

}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
void s_y() {
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
}

int main() {
    s_y();
    int n;
    cin >> n;
    map<int, int>m; m[0] = 0;
    for (int i = 1; i <= 100001; i++) {
        m[i] = 0;
    }
    for (int i = 0; i < n; i++) {
        int x; cin >> x;
        m[x] += 1;
    } ll ans = 0;
    int i = 1;
    while ( i <= 100000 ) {
        vector<int>v; int osum = 0; int esum = 0; int f = 0;
        while (i <= 100000 && m[i] != 0) {
            if (f == 0) {osum += (m[i] * i); f = 1;}
            else {f = 0; esum += (m[i] * i);}
            i++;
        }
        i++;
        if (osum > esum) {ans += osum;}
        else {ans += esum;}
    }
    cout << ans << "\n";

}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll a[100001];
ll f[100001];
int main()
{
    ll n, x;
    cin >> n;
    for(ll i=0; i<n; i++)
        {
            cin >> x;
            a[x]++;
        }
    f[0]=0;
    f[1]=a[1];
    for(ll i=2; i<=100000; i++)
    {
        f[i]=max(f[i-1], f[i-2]+a[i]*i);
    }
    cout << f[n] << endl;
    return 0;
}


#include<iostream>
using namespace std;
int main()
{
	int n, k,i,j,count=0;
	cin >> n >> k;
	if (((n*n - k) - k < 1)||k>=n*n) {
		cout << "NO"<<endl;
	}
	else {
		cout << "YES" << endl;
		for (i = 0; i < n; i++) {
			for (j = 0; j < n; j++) {
				cout << 'S';
				if (count < k) {
					cout << 'L'; count++;
					j++;
				}
			}
			cout << endl;
		}
	}
	return 0;
}


#include<iostream>
using namespace std;
int main()
{
	int n, k,i,j,count=0;
	int flag = 1;
	cin >> n >> k;
	if (((n*n - k) - k < 1)||k>=n*n) {
		cout << "NO"<<endl;
	}
	else {
		cout << "YES" << endl;
		for (i = 0; i < n; i++) {
			for (j = 0; j < n; j++) {
				if (flag == 1) {
					if (count < k) {
						cout << 'L'; count++;
						j++;
					}
					cout << 'S';
				}
				else {
					cout << 'S';
					if (count < k) {
						cout << 'L'; count++;
						j++;
					}
				}
			}
			flag = -1 * flag;
			cout << endl;
		}
	}
	return 0;
}


#include<iostream>
#include<iomanip>
#include<cstring>
#include<cmath>
using namespace std;

int main(){
	int n,k;
	cin>>n>>k;
	char *sea=new char[n*n];
	int count=0;
	for(int i=0;i<n*n;i++)
		sea[i]='S';
	if(k==0){// 0
		for(int i=0;i<n*n;i++){
			if((i%n)==0){
				cout<<endl<<sea[i];
			}
			else{
				cout<<sea[i];
			}
		}
		return 0;
	}
	if(((n/2)*2==n)&&(n*n/2<k)){ //even
		cout<<"NO";
		return 0;
	}
	else if((n/2)*2==n){
		cout<<"YES"<<endl;
		for(int i=0;i<n;i++){
			if((i/2)*2==i){
				for(int j=0;j<n;j+=2){
					sea[i*n+j]='L';
					count++;
					if(count==k)	break;
				}
				if(count==k)	break;
			}
			else{
				for(int j=0;j<n;j+=2){
					sea[i*n+j+1]='L';
					count++;
					if(count==k)	break;
				}
				if(count==k)	break;
			}
		}
	}

	if(((n/2)*2!=n)&&((n*n/2+1)<k)){ //odd
		cout<<"NO";
		return 0;
	}
	else if((n/2)*2!=n){
		cout<<"YES"<<endl;
		for(int i=0;i<k;i++){
			sea[2*i]='L';
		}
	}
	for(int i=0;i<n*n;i++){
		if((i%n)==0){
			cout<<endl<<sea[i];
		}
		else{
			cout<<sea[i];
		}
	}
//	cout<<endl<<"k:"<<k<<"   count:"<<count;
}


#include<iostream>
#include<iomanip>
#include<cstring>
#include<cmath>
using namespace std;

int main(){
	int n,k;
	cin>>n>>k;
	char *sea=new char[n*n];
	int count=0;
	for(int i=0;i<n*n;i++)
		sea[i]='S';
	if(k==0){// 0
		cout<<"YES";
		for(int i=0;i<n*n;i++){
			if((i%n)==0){
				cout<<endl<<sea[i];
			}
			else{
				cout<<sea[i];
			}
		}
		return 0;
	}
	if(((n/2)*2==n)&&(n*n/2<k)){ //even
		cout<<"NO";
		return 0;
	}
	else if((n/2)*2==n){
		cout<<"YES"<<endl;
		for(int i=0;i<n;i++){
			if((i/2)*2==i){
				for(int j=0;j<n;j+=2){
					sea[i*n+j]='L';
					count++;
					if(count==k)	break;
				}
				if(count==k)	break;
			}
			else{
				for(int j=0;j<n;j+=2){
					sea[i*n+j+1]='L';
					count++;
					if(count==k)	break;
				}
				if(count==k)	break;
			}
		}
	}

	if(((n/2)*2!=n)&&((n*n/2+1)<k)){ //odd
		cout<<"NO";
		return 0;
	}
	else if((n/2)*2!=n){
		cout<<"YES"<<endl;
		for(int i=0;i<k;i++){
			sea[2*i]='L';
		}
	}
	for(int i=0;i<n*n;i++){
		if((i%n)==0){
			cout<<endl<<sea[i];
		}
		else{
			cout<<sea[i];
		}
	}
//	cout<<endl<<"k:"<<k<<"   count:"<<count;
}


#include<iostream>
#include<iomanip>
#include<cstring>
#include<cmath>
using namespace std;

int main(){
	int n,k;
	cin>>n>>k;
	char *sea=new char[n*n];
	int count=0;
	for(int i=0;i<n*n;i++)
		sea[i]='S';
	if(((n/2)*2==n)&&(n*n/2<k)){ //even
		cout<<"NO";
		return 0;
	}
	else if((n/2)*2==n){
		cout<<"YES"<<endl;
		for(int i=0;i<n;i++){
			if((i/2)*2==i){
				for(int j=0;j<n;j+=2){
					sea[i*n+j]='L';
					count++;
					if(count==k)	break;
				}
				if(count==k)	break;
			}
			else{
				for(int j=0;j<n;j+=2){
					sea[i*n+j+1]='L';
					count++;
					if(count==k)	break;
				}
				if(count==k)	break;
			}
		}
	}

	if(((n/2)*2!=n)&&((n*n/2+1)<k)){ //odd
		cout<<"NO";
		return 0;
	}
	else if((n/2)*2!=n){
		cout<<"YES"<<endl;
		for(int i=0;i<k;i++){
			sea[2*i]='L';
		}
	}
	for(int i=0;i<n*n;i++){
		if((i%n)==0){
			cout<<endl<<sea[i];
		}
		else{
			cout<<sea[i];
		}
	}
//	cout<<endl<<"k:"<<k<<"   count:"<<count;
}


#include <cstdio>
using namespace std;
int main(){
    int n,k;
    scanf("%d%d",&n,&k);
    if(k>(n*n+1)/2)printf("NO\n");
    else{
        printf("YES\n");
        int cou=0;
        for(int i=0;i<n;++i){
            bool flag=!(i%2);
            if(cou>=k)flag=0;
            for(int j=0;j<n;++j){
                printf("%c",flag?'L':'S');
                cou+=flag;
                if(cou<k)flag=!flag;
                else flag=0;
            }
            printf("\n");
        }
    }
    return 0;
}


#include <iostream>
#include <stdio.h>
#include <string.h>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <vector>
#include <math.h>
#include <bitset>
#include <algorithm>
#include <climits>
using namespace std;

#define LS 2*i
#define RS 2*i+1
#define UP(i,x,y) for(i=x;i<=y;i++)
#define DOWN(i,x,y) for(i=x;i>=y;i--)
#define MEM(a,x) memset(a,x,sizeof(a))
#define W(a) while(a)
#define LL long long
#define N 205
#define MOD 19999997
#define INF 0x3f3f3f3f
#define EXP 1e-8

const double Pi = acos(-1.0);

int main()
{
    int n,m,cnt,i,j;
    W(~scanf("%d%d",&n,&m))
    {
        if((n%2==0&&m*2<=n*n)||(n%2&&m*2<=n*n+1))
        {
            printf("YES\n");
            cnt = 0;
            UP(i,1,n)
            {
                UP(j,1,n)
                {
                    if(i%2==j%2 && cnt<m)
                    {
                        printf("L");
                        cnt++;
                    }
                    else
                        printf("S");
                }
                printf("\n");
            }
        }
        else
            printf("NO\n");
    }

    return 0;
}


#include <cstdio>
using namespace std;
int main(){
    int n,k;
    scanf("%d%d",&n,&k);
    if(k>(n*n+1)/2)printf("NO\n");
    else{
        int cou=0;
        for(int i=0;i<n;++i){
            bool flag=!(i%2);
            if(cou>=k)flag=0;
            for(int j=0;j<n;++j){
                printf("%c",flag?'L':'S');
                cou+=flag;
                if(cou<k)flag=!flag;
                else flag=0;
            }
            printf("\n");
        }
    }
    return 0;
}


#include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>
#include<string>
using namespace std;
int main()
{
	int n,k; cin>>n>>k;
	vector<vector<char>>vec(n,vector<char>(n,'S'));
	if (k>ceil(n*1.0/2)*ceil(n*1.0/2)+floor(n*1.0/2)*floor(n*1.0/2))   cout<<"No"<<endl;
	else
	{
		int count=0;
		bool go=1;
		for (int i=0 ; i<n && go ;++i)
		{
			//flag
			int j=-1;
			if (i%2==0)    j=0;
			else           j=1;
			for (j; j<n ; j+=2) {vec[i][j]='L'; ++count;  if (count==k) {go=0;  break;} }
		}
		for (int i=0; i<n ; ++i)
		{
			for (int j=0; j<n ; ++j)
				cout<<vec[i][j];
			cout<<endl;
		}
	}

	return 0;
}


#include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>
#include<string>
using namespace std;
int main()
{
	int n,k; cin>>n>>k;
	vector<vector<char>>vec(n,vector<char>(n,'S'));
	if (k>ceil(n*1.0/2)*ceil(n*1.0/2)+floor(n*1.0/2)*floor(n*1.0/2))   cout<<"No"<<endl;
	else
	{
		int count=0;
		bool go=1;
		for (int i=0 ; i<n && go ;++i)
		{
			//flag
			int j=-1;
			if (i%2==0)    j=0;
			else           j=1;
			for (j; j<n ; j+=2) {vec[i][j]='L'; ++count;  if (count==k) {go=0;  break;} }
		}
		cout<<"Yes"<<endl;
		for (int i=0; i<n ; ++i)
		{
			for (int j=0; j<n ; ++j)
				cout<<vec[i][j];
			cout<<endl;
		}
	}

	return 0;
}


#include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>
#include<string>
using namespace std;
int main()
{
	int n,k; cin>>n>>k;
	vector<vector<char>>vec(n,vector<char>(n,'S'));
	if (k>ceil(n*1.0/2)*ceil(n*1.0/2)+floor(n*1.0/2)*floor(n*1.0/2))   cout<<"NO"<<endl;
	else
	{
		int count=0;
		bool go=1;
		for (int i=0 ; i<n && go ;++i)
		{
			//flag
			int j=-1;
			if (i%2==0)    j=0;
			else           j=1;
			for (j; j<n ; j+=2) {vec[i][j]='L'; ++count;  if (count==k) {go=0;  break;} }
		}
		cout<<"YES"<<endl;
		for (int i=0; i<n ; ++i)
		{
			for (int j=0; j<n ; ++j)
				cout<<vec[i][j];
			cout<<endl;
		}
	}

	return 0;
}