akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;

int main() {

	char a, b;

	cin >> a >> b;

	long ans = 0;
	if (a == 'H' && b=='H') {
		ans = 1;
	}
	if (a == 'H' && b == 'D') {
		ans =0;
	}
	if (a == 'D' && b == 'H') {
		ans = 0;
	}
	if (a == 'D' && b == 'D') {
		ans = 1;
	}

	cout << (ans == 1 ? "H" : "D") << endl;
	return 0;

}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
#define MAX 100000

int parent(int i) { return i / 2; }
int left(int i) { return 2 * i; }
int right(int i) { return 2 * i + 1; }

int main() {
  int H, i, A[MAX + 1];

  cin >> H;
  for ( i = 1; i <= H; i++ ) cin >> A[i];

  for ( i = 1; i<= H; i++ ) {
    cout << "node " << i << ": key = " << A[i] << ", ";
    if ( parent(i) >= 1 ) cout << "parent key = " << A[parent(i)] << ", ";
    if ( left(i) <= H ) cout << "left key = " << A[left(i)] << ", ";
    if ( right(i) <= H ) cout << "right key = " << A[right(i)] << ", ";
    cout << endl;
  }

  return 0;
}

Measured memory_bytes: 3072
#include<stdio.h>
#include<string.h>

int main(){
    char s1[101], s2[101];
    int n,i;
    int taro = 0;
    int hanako = 0;
    scanf("%d", &n);

    for(i = 0; i < n; i++){
        scanf("%s %s", s1, s2);

        if ( strcmp(s1, s2) == 0 ){
            //printf("s1 == s2\n");
            //引き分け
            taro = taro + 1;
            hanako = hanako + 1;

        }else if( strcmp(s1, s2) > 0 ){
            //printf("s1 > s2\n");
            //太郎のかち
            taro = taro + 3;

        }else if ( strcmp(s1, s2) < 0 ){
            //printf("s1 < s2\n");
            //花子のかち
            hanako = hanako + 3;
        }
    }
    printf("%d %d\n",taro,hanako);

    return 0;
}



Measured memory_bytes: 2000
#include <iostream>

using namespace std;

int main(void) {
    double n, d;
    cin >> n >> d;
    if (d >n) {
        cout << 1 << endl;
    }
    else {
        cout << (int)((n/(2*d+1))+0.9) << endl;
    }

    return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=3e5+5,mod=1e9+7;
int n;
ll a[N],b[60];
int main()
{
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
    {
        scanf("%lld",&a[i]);
        for(int j=0;j<60;j++)
            if(a[i]>>j&1) b[j]++;
    }
    ll ans=0;
    for(int i=1;i<=n;i++)
    {
        for(int j=0;j<60;j++)
            if(a[i]>>j&1) b[j]--;
        for(int j=0;j<60;j++)
            if(a[i]>>j&1)
        {
            ans=(ans+(1ll<<j)%mod*(n-i-b[j])%mod)%mod;
        }
        else
        {
            ans=(ans+(1ll<<j)%mod*b[j]%mod)%mod;
        }
    }
    printf("%lld\n",ans);
}


Measured memory_bytes: 2560
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
ll GCD(ll a, ll b) { return b ? GCD(b, a%b) : a; }
int main() {
    ll h;
    cin>>h;
    ll tmp=1,cnt=0;
    while(h!=0){
        h/=2;
        tmp*=2;
        cnt++;
    }
    ll ans=0;
    for(int i=0; i<cnt; i++){
        ans+=pow(2,i);
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 384
# coding: utf-8
from fractions import gcd
N = int(input())
A = list(map(int, input().split()))
l1 = [0] * N
l2 = [0] * N
for i in range(1, N):
    l1[i] = gcd(l1[i-1], A[i-1])
for i in range(N-1)[::-1]:
    l2[i] = gcd(l2[i+1], A[i+1])
ans = 0
for i in range(N):
    ans = max(ans, gcd(l1[i], l2[i]))
print(ans)

Measured memory_bytes: 16144
#include<stdio.h>
#define MAX 100

int m[MAX+1][MAX+1],p[MAX+1];
int i,j,k,l,n;

 int main(){
  int ans;
  scanf("%d", &n);

  for(i=1; i<n+1; i++){
    scanf("%d %d", &p[i-1], &p[i]);}
  for(i=1;i<n+1;i++){m[i][i]=0;}
  for(l=2;l<n+1;l++){
   for(i=1; i<n-l+2;i++){
    j=-1+i+l;
    m[i][j]=(1<<21);
    for(k=i;k<j;k++){
      if(m[i][j] < m[i][k]+m[k+1][j]+p[i-1]*p[k]*p[j]){
	continue;
      }
   else {m[i][j] = m[i][k]+m[k+1][j]+p[i-1]*p[k]*p[j];}
    }}}

  ans = m[1][n];
  
  printf("%d\n",ans);

  
  return 0;
}



Measured memory_bytes: 2056
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
#define rrep(i,n) for(int i=n-1;i>=0;--i)
#define fi first
#define se second
#define sz(x) (int)(x).size()
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
using namespace std;
using ll = long long;
using P = pair<int, int>;
template<typename T> inline bool chmax(T &a,T b){if(a<b){a=b;return 1;}return 0;}
template<typename T> inline bool chmin(T &a,T b){if(b<a){a=b;return 1;}return 0;}
template<typename T> vector<T> make_vec(size_t a){return vector<T>(a);}
template<typename T,typename... Ts>
auto make_vec(size_t a,Ts... ts){return vector<decltype(make_vec<T>(ts...))>(a,make_vec<T>(ts...));}
template<typename T,typename U,typename... V>
typename enable_if<is_same<T,U>::value>::type fill_v(U &u,const V... v){u=U(v...);}
template<typename T,typename U,typename... V>
typename enable_if<!is_same<T,U>::value>::type fill_v(U &u,const V... v){for(auto &e:u)fill_v<T>(e,v...);}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    string s;
    cin >> s;
    int n = sz(s);
    int ans = 100;
    rep(i, 26) {
        char c = 'a'+i;
        vector<int> idx;
        rep(j, n) if (s[j] == c) idx.push_back(j);
        if (sz(idx) == 0) continue;
        else if (sz(idx) == 1) chmin(ans, max(idx[0], n-idx[0]-1));
        else {
            int now = 0;
            rep(j, sz(idx)-1) chmax(now, idx[j+1] - idx[j] - 1);
            chmax(now, idx[0]); chmax(now, n-idx[sz(idx)-1]-1);
            chmin(ans, now);
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 3612
#include <bits/stdc++.h>
using namespace std;
int main () {
  long N;
  cin >> N;
  vector<long> data(N);
  for(int i = 0; i < N; i++){
    cin >> data.at(i);
  }
  long ans = INT_MAX, sub;
  for(int i = 1; i < 101; i++){
    sub = 0;
    for(int j = 0; j < N; j++){
      sub += (data.at(j) - i) * (data.at(j) - i);
    }
    ans = min(ans, sub);
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>

using namespace std;
#define rep(i,n) for (int i =0;i<(n);++i)
using ll = long long;
using P = pair<int, int>;

int main () {

    int N,X,T;
    cin >>N>>X>>T;
    cout <<((N+X-1)/X)*T;
    return 0;
}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
 
using namespace std;
#define repr(i,a,b) for (int i=a; i<b; i++)
#define rep(i,n) for (int i=0; i< (int) n; i++)
#define PI  3.14159265358979323846264338327950
 
int main () {
    int A,B;
    cin >> A >> B;
    int ans = (A+B)%24;
    cout << ans << endl;


}


Measured memory_bytes: 256
#pragma GCC optimize ("O3")
#pragma GCC target ("avx")
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please


int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);


	int P[101] = {};
	int N;
	cin >> N;

	rep1(i, N) {
		int tmp = i;
		for (int j = 2; j <= i; j++) {
			while (tmp % j == 0) {
				P[j]++;
				tmp /= j;
			}
		}
	}

	int P2[1001] = {};

	rep1(i, 100) {
		P2[P[i]]++;
	}
	for (int i = 1000; i > 0; i--) {
		P2[i - 1] += P2[i];
	}

	int kotae = P2[74];
	kotae += (P2[2] - 1) * P2[24];
	kotae += (P2[4] - 1) * P2[14];
	kotae += (P2[2] - 2) * (P2[4] - 1) * P2[4] / 2;

	co(kotae);

	Would you please return 0;
}

Measured memory_bytes: 256
import math
import itertools
num = int(input())
lis = [ i for i in range(1,num+1)]
k = tuple(map(int,input().split()))
t = tuple(map(int,input().split()))
count_k = 0
count_t = 0
count = 0
for i in itertools.permutations(lis):
    count+=1
    if i == k:
        count_k = count
    if i == t:
        count_t = count
    if count_k != 0 and count_t != 0:
        break
print(abs(count_k -count_t))

Measured memory_bytes: 3064
#include<cstdio>
using namespace std;
const int ch[4]={'R','Y','G','B'}; 
int n,m,k;
int main()
{
	scanf("%d%d%d",&n,&m,&k);
	for (int i=1;i<=n;i++)
	{
	  for (int j=1;j<=m;j++)
	  {
	  	 int x=(m+i+j)/k%2,y=(m+i-j)/k%2;
	  	 printf("%c",ch[x*2+y]);
	  } 
	  puts("");
	}
	return 0;
} 

Measured memory_bytes: 384
#include  <bits/stdc++.h>
using namespace std;

int main ()
{
  string a;
  cin>>a;
  if(a.find("111")!= std::string::npos)
  {
    cout<<"3"<<endl;
  }
  else if(a.find("11")!= std::string::npos)
  {
    cout<<"2"<<endl;
  }
  else if(a.find("101")!= std::string::npos)
  {
    cout<<"2"<<endl;
  }
  else if(a.find("1")!= std::string::npos)
  {
    cout<<"1"<<endl;
  }
  else
  {
    cout<<"0"<<endl;
  }
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
typedef long long ll;
ll s[9]={1,1,2,3,5,8,13,21,34};
ll h,w,k;
ll dp[101][8];
int main(void){
    ll mod=1e9+7;
    dp[0][0]=1;
    cin>>h>>w>>k;
    if(w==1){cout<<1<<endl;return 0;}
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            if(j==0){
                dp[i+1][j]=(dp[i][j]*s[w-1]+dp[i][j+1]*s[w-2])%mod;
            }
            else if(j==w-1){
                dp[i+1][j]=(dp[i][j]*s[w-1]+dp[i][j-1]*s[w-2])%mod;
            }
            else dp[i+1][j]=(dp[i][j+1]*s[w-j-2]*s[j]+dp[i][j]*s[w-j-1]*s[j]+dp[i][j-1]*s[j-1]*s[w-j-1])%mod;
        }
    }
    cout<<dp[h][k-1]<<endl;
    /*for(int i=0;i<=h;i++){
        for(int j=0;j<w;j++){
            cout<<dp[i][j];
        }
        cout<<endl;
    }*/
}


Measured memory_bytes: 256
K=int(input())
import math

if K==1:
  print(1)
  exit()
elif K==2:
  print(9)
  exit()
else:
  t=0
  for i in range(1,K-1):
    for j in range(i+1,K):
      for k in range(j+1,K+1):
        a=math.gcd(i,j)
        b=math.gcd(a,k)
        t+=b
  tw=0
  for i in range(1,K):
    for j in range(i+1,K+1):
      c=math.gcd(i,j)
      tw+=c
  
  on=0
  for i in range(1,K+1):
    on+=i
  print(t*6+tw*6+on)


Measured memory_bytes: 9216
n, k = map(int, input().split())
A = list(map(int, input().split()))

hush = {}
for i in range(1, n+1):
    hush[i] = 0

loop = []
cur_town = 1
while hush[cur_town] == 0:
    loop.append(cur_town)
    hush[cur_town] = 1
    cur_town = A[cur_town-1]

root = loop.index(cur_town)

if k < root:
    print(loop[k])
else:
    loop_len = len(loop[root:])
    ind = root + (k-root)%loop_len
    print(loop[ind])

Measured memory_bytes: 40540
#include <iostream>
#include <vector>
#include <cstdlib>  
#include <algorithm>
#include <string>

using namespace std;
 
int main() {
    int n;cin>>n;
    int h[n];
    for(int i = 0;i<n;i++) cin>>h[i];
    sort(h,h+n);
    int g= 0;
    for(int i = 0;i<n-1;i++) g+= h[i];
    if(g > h[n-1]) cout<<"Yes";
    else cout<<"No";
    return 0;
}

Measured memory_bytes: 3020
#include <string>
#include <vector>
#include <iostream>
#include <iomanip>
#include <cmath>
#include <algorithm>
#include <functional>
#include <utility>
#include <numeric>
#include <map>
using namespace std;


#define prec(i) cout << fixed << setprecision(i)

const long long MOD = 1000000007;

long long fact(long long k) {
	long long sum = 1;
	for (long long i = 2; i <= k; i++)
		sum *= i;

	return sum;
}

int ctoi(char c) {
	if (c >= '0' && c <= '9')
		return c - '0';
	else
		return -1;
}

long long pow_mod(int a, int b) {
	long long ans = 1;
	for (int i = 0; i < b; i++)
		ans = (ans * a) % MOD;

	return ans;
}

long long powll(long long a, long long  b) {
	long long ans = 1;
	for (long long  i = 0; i < b; i++)
		ans = ans * a;

	return ans;
}


int main()
{
	long long x, k, ans = 0;

	cin >> k >> x;

	if(k * 500 >= x)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;

int main() {
  int H, W;
  cin >> H >> W;
  
  vector<vector<char>> table(H, vector<char>(W));
  
  for (int h = 0; h < H; h++) {
    for(int w = 0; w < W; w++) {
      cin >> table.at(h).at(w);
    }
  }
  
  vector<int> del_line;
  vector<int> del_row;
  
  for (int h = 0; h < H; h++) {
    bool flag = false;
    for(int w = 0; w < W; w++) {
      if(table.at(h).at(w) == '#'){
        flag = true;
        break;
      }
    }
    if(flag == false) del_line.push_back(h);
  }
  
  for (int w = 0; w < W; w++) {
    bool flag = false;
    for(int h = 0; h < H; h++) {
      if(table.at(h).at(w) == '#'){
        flag = true;
        break;
      }
    }
    if(flag == false) del_row.push_back(w);
  }
  
  for (int h = 0; h < H; h++) {
    bool flag = false;
    for (int i : del_line) {
      if (h == i) {
        flag = true;
        break;
      }
    }
    if(flag == true) continue;
    
    for(int w = 0; w < W; w++) {
      flag = false;
      for (int j : del_row) {
        if (w == j) {
          flag = true;
          break;
        }
      }
      if (flag == true) continue;
      cout << table.at(h).at(w);
    }
    cout << endl;
  }
}


Measured memory_bytes: 256
//#include<bits/stdc++.h>
#include<set>
#include<map>
#include<list>
#include<iomanip>
#include<cmath>
#include<string>
#include<vector>
#include<queue>
#include<stack>
#include<complex>
#include<sstream>
#include<iostream>
#include<fstream>
#include<algorithm>
#include<numeric>
#include<utility>
#include<functional>
#include<stdio.h>
#include<assert.h>
#include<memory.h>
#include<bitset>
#include<stdio.h>
#include <cstdio>
#include <cstring>
#include <string>


using namespace std;

#define ld long double
#define ll long long
#define ff first
#define ss second
#define sz(a) (int)a.size()
#define mem(a, b) memset((a), (b), sizeof(a))
#define pb push_back
#define all(v) (v).begin(), (v).end()
#define pii pair<int ,int >
#define pll pair<ll ,ll >
#define mp make_pair
#define vi vector<int >
#define vii vector<pii>
#define vvi vector < vi >
#define vll vector < ll >
#define vllll vector < pll >
#define vvll vector < vll >
#define forn(i,n) for(int i=0;i<(n);i++)
#define fori(i,s,e) for(int i=s,i<n;i++)
#define qi  queue <int >
#define qll  queue <ll >
#define in_r(x,y,n,m) (x>=0 && x<n && y>=0 && y<m)
#define maxn 1000009


void fast(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
}

const ll MOD = 1e9 + 7;
const double EPS = (1e-8);
const int OO = (int) 1e9 + 7;
const ll OOO = (ll) 1e15 + 7;
double const PI = 3.1415926535897932384626433832795;
const int mxn = 100009;
char c1, c2, c3, c4;
string s, s1, s2, s3;
int   n, m, k, t, q, a, b, c, d, e, x, y, z; int sol = 0;


int sk[15][15];
int C[15];


int main(){
	fast();
	

	cin >> n >> m >> x;
	for (int i = 0; i < n; i++){
		cin >> C[i];
		for (int j = 0; j < m; j++) cin >> sk[i][j];
	}
	sol = 1000000000;
	z = 1 << n;
	for (int mask = 0; mask < z; mask++){
		vi ans(m);
		int ret = 0;
		for (int i = 0; i < n; i++){
			if ((mask >> i) & 1){
				for (int j = 0; j < m; j++) ans[j] += sk[i][j];
				ret += C[i];
			}
		}
		bool ok = 1;
		for (int i = 0; i < m; i++) if (ans[i] < x) ok = 0;
		if (ok) sol = min(sol, ret);
	}
	if (sol == 1000000000) cout << -1;
	else cout << sol;

	

	cout << endl << endl; return 0;
}


Measured memory_bytes: 3648
// clang-format off
#include <bits/stdc++.h>

#define mp make_pair
#define fst first
#define snd second
#define forn(i,n) for (size_t i = 0; i < size_t(n); i++)
#define forn1(i,n) for (size_t i = 1; i <= size_t(n); i++)
#define popcnt __builtin_popcount
#define ffs __builtin_ffs
#define ctz __builtin_ctz
#define clz __builtin_clz
#define all(a) (a).begin(), (a).end()
 
using namespace std;

using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;
using pli = pair<ll,int>;
using pil = pair<int,ll>;
using pll = pair<ll,ll>;
template <typename T> using vec = vector<T>;
using vi = vec<int>;
using vl = vec<ll>;
template <typename T> using que = queue<T>;
template <typename T> using deq = deque<T>;

template <typename T> T id(T b) {return b;};
template <typename T> void chmax(T &x, T y) {if (x < y) x = y;}
template <typename T> void chmin(T &x, T y) {if (x > y) x = y;}
template <typename S, typename K> bool contains(S s, K k) { return s.find(k) != s.end(); }
void fastio() { ios_base::sync_with_stdio(false); cin.tie(nullptr); }
constexpr ll TEN(int n) { if (n == 0) return 1LL; else return 10LL*TEN(n-1); }
// clang-format on

int main() {
    fastio();
    int n;
    string s, t;
    cin >> n >> s >> t;

    forn(i, n) {
        cout << s[i] << t[i];
    }
    cout << endl;

    return 0;
}

Measured memory_bytes: 256
S=[1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
K=int(input())

print(S[K-1])


Measured memory_bytes: 2940
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef priority_queue<int> pqi;
#define ttttyyyy ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define fo(i,n,m) for(int i=n,i<m;i++)
#define endll "\n"
#define ci(x) int x;cin>>x
#define pb(x) push_back(a)
#define mk(a,b) make_pair(a,b)
int main(){
    ttttyyyy
    string s;cin>>s;
    for(int i=0;i<s.size();i++){
        if(s[i]=='7'){
            cout<<"Yes"<<endl;
            return 0;
        }
    }
    cout<<"No"<<endl;
    return 0;
}


Measured memory_bytes: 3644
#include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 99999999999999999
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;


#define NUM 100005

struct Info{
	Info(string arg_color,int arg_value){
		color = arg_color;
		value = arg_value;
	}
	bool operator<(const struct Info &arg) const{
		return value > arg.value;
	}
	string color;
	int value;
};

int N;

int main(){

	scanf("%d",&N);

	int tmp_value;

	priority_queue<Info> Q;

	for(int loop = 0; loop < N; loop++){

		string tmp_str;

		cin >> tmp_str >> tmp_value;
		Q.push(Info(tmp_str,tmp_value));
	}

	int count = 0;

	int num_query;
	scanf("%d",&num_query);

	string tmp_str;
	int pre_weight = BIG_NUM;
	bool FLG = true;

	for(int loop = 0; loop < num_query; loop++){

		cin >> tmp_str;

		if(!FLG)continue;

		FLG = false;

		while(!Q.empty()){

			if(Q.top().color != tmp_str || Q.top().value == pre_weight){
				Q.pop();
			}else{
				count++;
				pre_weight = Q.top().value;
				FLG = true;
				Q.pop();
				break;
			}
		}
	}

	if(count == num_query){
		printf("Yes\n");
	}else{
		printf("No\n");
	}

	return 0;
}



Measured memory_bytes: 12488
macro_rules! input {
    ($ttype:ty) => {
        {
            let mut input = String::new();
            let _= std::io::stdin().read_line(&mut input);
            input.trim().parse::<$ttype>().unwrap()
        }
    };

    ($($ttype:ty),*) => {
        {
            use std::io::BufRead;
            let mut input = String::new();
            let stdin = std::io::stdin();
            let _ = stdin.lock().read_line(&mut input);
            let mut iter = input.trim().split_whitespace();
            (
                $(iter.next().unwrap().parse::<$ttype>().unwrap(),)*
            )
        }
    };

    ($ttype:ty; $x:expr) => {
        {
            use std::io::BufRead;
            let mut input = String::new();
            let stdin = std::io::stdin();
            let _ = stdin.lock().read_line(&mut input);
            let v: Vec<$ttype> = input
                .trim()
                .split_whitespace()
                .map(|x| x.parse().unwrap())
                .collect();
            v
        }
    };

    ($ttype:ty; $x:expr; $y:expr) => {
        {
            use std::io::BufRead;
            let mut matrix = Vec::with_capacity($y);
            for _ in 0..$y {
                let mut input = String::new();
                let stdin = std::io::stdin();
                let _ = stdin.lock().read_line(&mut input);
                let v: Vec<$ttype> = input
                    .trim()
                    .split_whitespace()
                    .map(|x| x.parse().unwrap())
                    .collect();
                matrix.push(v);
            }
            matrix
        }
    };
}

fn main() {
    let N: usize = 300000;
    let mut east = vec![0; N];
    let mut east_cnt = 0;
    let mut west = vec![0; N];
    let mut west_cnt = 0;
    let mut sum = 0;
    let mut max = std::i32::MIN;
    let mut index: usize = 0;
    let n = input!(usize);
    let s = input!(String);
    for (i, c) in s.chars().enumerate() {
        if c == 'E' { 
            east_cnt += 1;
            east[i] = east_cnt;
            west[i] = west_cnt;
            sum += 1;
        } else {
            east[i] = east_cnt;
            west_cnt += 1;
            west[i] = west_cnt;
            sum -= 1;
        }
        if sum > max {
            max = sum;
            index = i;
        }
    }

    if index < 1 {
        println!("{}", east[n-1] - east[index+1]);
    } else if index + 1 >= N {
        println!("{}", west[index-1]);
    } else {
        println!("{}", west[index-1] + (east[n-1] - east[index]));
    }
}


Measured memory_bytes: 6396
#include<iostream>

using namespace std;

int main(void)
{
  int g1[]={1,3,5,7,8,10,12};
  int g2[]={4,6,9,11};
  int g3=2;
  int x,y; cin>>x>>y;
  int count=0;
  
  for(int i=0;i<7;i++){
    if((g1[i]==x)||(g1[i]==y)){count++;}
  }
  if(count==2){puts("Yes"); return 0;}
  
  count=0;
  for(int i=0;i<4;i++){
    if((g2[i]==x)||(g2[i]==y)){count++;}
  }
  if(count==2){puts("Yes"); return 0;}
  
  puts("No");
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll n,a,ans,L;
vector<ll> v;
int main(void){
    cin>>n;
    for(int i=0;i<=100000;i++)v.push_back(-1);
    for(int i=0;i<n;i++){
        cin>>a;
        L=lower_bound(v.begin(),v.end(),a)-v.begin();
        v[L-1]=a;
    }
    for(auto x:v)if(x!=-1)ans++;
    cout<<ans<<endl;
}


Measured memory_bytes: 1400
#!/usr/bin/env python
# coding: utf-8

# In[8]:


import numpy as np


# In[ ]:


N, K, Q = map(int, input().split())
As = [int(input()) for i in range(Q)]
"""
6 3 4
3
1
3
2
"""


# In[17]:


#points = np.array([K]*N)
points = np.array([0]*N)
args = np.arange(1, N+1)


# In[18]:


for i in range(Q):
    #points[args!= int(input())] -= 1
    points[As[i]-1] += 1


# In[22]:


points = points-Q+K


# In[23]:


for b in points >= 1:
    if b:
        print('Yes')
    else:
        print('No')


# In[ ]:






Measured memory_bytes: 19072
# ABC093 C - Same Integers

def is_eaven(n):
    if n%2==0:
        return 1
    else:
        return 0

L=list(map(int,input().split()))
# templ=[l for l in L if is_eaven(l)]
# templ=[lambda l: l%2==0 for l in L ]
ans=0

tempL=[]

if L[0]==L[1]==L[2]:
    print(ans)
    exit()

for l in L:
    tempL.append(is_eaven(l))
if all (tempL) or not any(tempL):   #全て偶数or全て奇数の場合はpass
    pass
elif tempL.count(0)==2:
    for i in range (2):
        if tempL[i]==0:
            L[i]+=1
    ans+=1
elif tempL.count(1)==2:
    for i in range (2):
        if tempL[i]==1:
            L[i]+=1
    ans+=1
else:
    pass

if L[0]==L[1]==L[2]:
    print(ans)
    exit()

L.sort()

ans+=(L[2]-L[0])//2

if L[0]==L[1]==L[2]:
    print(ans)
    exit()

ans+=(L[2]-L[1])//2
print(ans)

Measured memory_bytes: 9224
#include <bits/stdc++.h>
#define rep(i,n)for(long long i=0;i<(n);i++)
using namespace std;
typedef long long ll;
const int MOD=1e9+7;

int main(){
  int p,q,r;
  cin >> p >> q >> r;
  
  cout << min({p+q,q+r,r+p}) << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;
#define  rep(i,a,b)for(long long i=a;i<b;++i)
#define  rrep(i,a,b)for(int i=a;i>=b;--i)
#define  yesno(flag)if(flag)cout<<"Yes"<<endl; else cout<<"No"<<endl;
using namespace std;
const ll INF=1000000000000LL;
const ll r197=1000000007;
typedef pair<ll,ll>P;
typedef pair<int,P>Pa;
bool Inframe(int a,int b,int c,int d,int h,int w){
	if(a+b>=0&&a+b<h&&c+d>=0&&c+d<w)return true;
	return false;
}

ll dp[100005];
int n,h[100005];
int main() {
	rep(i,0,100005)dp[i]=INF;
	cin>>n;
	rep(i,0,n){
		cin>>h[i];
	}
	dp[0]=0;
	rep(i,0,n){
		if(i+1<n){
			dp[i+1]=min(dp[i]+abs(h[i]-h[i+1]),dp[i+1]);
		}
		if(i+2<n){
			dp[i+2]=min(dp[i]+abs(h[i]-h[i+2]),dp[i+2]);
		}
	}
	cout<<dp[n-1]<<endl;
	return 0;
}


Measured memory_bytes: 1408
import sys

input = sys.stdin.readline

N = int(input())
x = sorted(list(map(int, input().split())))
t = 1

for num in x:
    t = t * num
    if t > 10 ** 18:
        print(-1)
        sys.exit()

if (t > 10 ** 18):
    print(-1)
else:
    print(t)

Measured memory_bytes: 21536
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
constexpr ll mod=1e9+7;

ll ans[10020]={};

int main()
{
  for (ll x = 1; x <= 100; ++x)
  {
    for (ll y = 1; y <= 100; ++y)
    {
      for (ll z = 1; z <= 100; ++z)
      {
        ll idx=x*x+y*y+z*z+x*z+y*z+y*x;
        if(idx<10010) ans[idx]++;
      }
    }
  }
  ll n;
  cin>>n;
  for (int i = 1; i <= n; ++i)
  {
    cout<<ans[i]<<endl;
  }
}

Measured memory_bytes: 3556
import java.util.Scanner;

public class Main {
	public static void main(String[] args){
		String[] weather = {"Sunny", "Cloudy","Rainy"};

		Scanner scan = new Scanner(System.in);

		String S = scan.next();

		if(S.equals(weather[0])){
			System.out.println(weather[1]);
		}else if(S.equals(weather[1])){
			System.out.println(weather[2]);
		}else if(S.equals(weather[2])){
			System.out.println(weather[0]);
		}
	}
}


Measured memory_bytes: 19924
#include<stdio.h>
#include<string.h>
 
int main(void)
{
  char nstr[8],jd[5];
  int n,i,count[4]={0,0,0,0};
  
  fgets(nstr,sizeof(nstr),stdin);
  sscanf(nstr,"%d",&n);
  
  for(i=0;i<n;i++)
  {
	fgets(jd,sizeof(jd),stdin);
    if(strcmp(jd,"AC\n")==0)
    {
      count[0]++;
    }else if(strcmp(jd,"WA\n")==0)
    {
      count[1]++;
    }else if(strcmp(jd,"TLE\n")==0)
    {
      count[2]++;
    }else if(strcmp(jd,"RE\n")==0)
    {
      count[3]++;
    }
  }
  
  printf("AC x %d\n",count[0]);
  printf("WA x %d\n",count[1]);
  printf("TLE x %d\n",count[2]);
  printf("RE x %d\n",count[3]);
  
  return 0;
}

Measured memory_bytes: 2156
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
#define PI 3.1415926535897932384626433
#define mod 1000000007

int gcd(int a, int b) { return b ? gcd(b, a%b) : a; }

int lcm(int a, int b) { return a * b / gcd(a, b); }

int main(){
    int n, k;
    cin >> n >> k;
    if(k*2-1 <= n){
        cout << "YES" << endl;
    }else{
        cout << "NO" << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include<cstdio>
using namespace std;

/* #include<cstdio>*/
int main(){
	int a, b;
	cin >> a >> b;
	int d, r;
	double f;
	d = a / b;
	r = a % b;
	f = (double)a / b;
	cout << d << " " << r << " ";
	printf("%.6lf\n", f);

	return 0; 
}




Measured memory_bytes: 3220
import java.io.*;
import java.util.Scanner;
 
class Main {
  public static void main(String args[]) {
	Scanner scanner = new Scanner(System.in);
    int n = scanner.nextInt();
    int i = 0;
    String st = "0";
    int ac = 0;
    int wa = 0;
    int tle = 0;
    int re = 0;
    while(i<=n){
      st = scanner.nextLine();
      if(st.equals("AC")){
        ac = ac + 1;
      };
      if(st.equals("WA")){
        wa = wa + 1;
      }
      if(st.equals("TLE")){
        tle = tle +1;
      }
      if(st.equals("RE")){
        re = re + 1;
      }
      i++;
    }
    System.out.println("AC x " + ac);
    System.out.println("WA x " + wa);
    System.out.println("TLE x " + tle);
    System.out.println("RE x " + re);
  };
};

Measured memory_bytes: 59484
#include<bits/stdc++.h>

using namespace std;

#define allof(x) (x).begin(), (x).end()

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int MAXN = 1e5 + 5;
const ll mod = 1e9 + 7;

int N, M;
int S, T;

ll best[2][MAXN];
vector<pll> adj[MAXN];
vector<int> pth[2][MAXN];

void dijkstra(int tp){
    memset(best[tp], 0x3f, sizeof best[tp]);
    best[tp][tp == 0 ? S : T] = 0;

    priority_queue<pll, vector<pll>, greater<pll>> pq;
    pq.push({0, tp == 0 ? S : T});
    while(!pq.empty()){
        pll top = pq.top();
        pq.pop();

        for(pll p : adj[top.second]){
            if(top.first + p.second < best[tp][p.first]){
                best[tp][p.first] = top.first + p.second;
                pq.push({best[tp][p.first], p.first});
            }
        }
    }
}

int incoming[2][MAXN];
ll pcnt[2][MAXN];

void count_path(int tp){
    pcnt[tp][tp == 0 ? S : T] = 1;
    queue<int> q;
    q.push(tp == 0 ? S : T);
    while(!q.empty()){
        int fr = q.front();
        q.pop();
        for(int i : pth[tp][fr]){
            pcnt[tp][i] += pcnt[tp][fr];
            pcnt[tp][i] %= mod;

            incoming[tp][i]--;
            if(!incoming[tp][i]){
                q.push(i);
            }
        }
    }
}

int main(){
    cin.tie(0);
    cin.sync_with_stdio(0);

    cin >> N >> M;
    cin >> S >> T;
    for(int a = 0; a < M; a++){
        int u, v, c;
        cin >> u >> v >> c;
        adj[u].push_back(pll(v, c));
        adj[v].push_back(pll(u, c));
    }

    dijkstra(0);
    dijkstra(1);

    for(int a = 1; a <= N; a++){
        if(best[0][a] + best[1][a] != best[0][T]){
            continue;
        }
        for(pll p : adj[a]){
            if(best[0][a] + p.second == best[0][p.first] && best[0][p.first] + best[1][p.first] == best[0][T]){
                pth[0][a].push_back(p.first);

                incoming[0][p.first]++;
            }
            if(best[1][a] + p.second == best[1][p.first] && best[0][p.first] + best[1][p.first] == best[0][T]){
                pth[1][a].push_back(p.first);

                incoming[1][p.first]++;
            }
        }
    }
    count_path(0);
    count_path(1);

    ll ans = pcnt[0][T] * pcnt[1][S] % mod;
    //cout << "Initially " << ans << endl;
    for(int a = 1; a <= N; a++){
        //cout << "at " << a << endl;
        if(best[0][a] == best[1][a]){
            ll val = pcnt[0][a] * pcnt[1][a] % mod;
            ans -= val * val;
            ans %= mod;
        }
        for(int i : pth[0][a]){
            //cout << "going to " << i << endl;
            if(best[0][a] * 2 < best[0][T] && best[0][T] < best[0][i] * 2){
                //cout << "B -= " << pcnt[1][i] << " * " << pcnt[0][a] << endl;
                ll val = pcnt[0][a] * pcnt[1][i] % mod;
                ans -= val * val % mod;
                ans %= mod;
            }
        }
        //cout << endl;
    }
    ans %= mod;
    if(ans < 0){
        ans += mod;
    }
    cout << ans % mod;
}


Measured memory_bytes: 28480
import sys, os, math, bisect, itertools, collections, heapq, queue
# from scipy.sparse.csgraph import csgraph_from_dense, floyd_warshall
from decimal import Decimal
from collections import defaultdict, deque

# import fractions

sys.setrecursionlimit(10000000)

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]

lcm = lambda x, y: (x * y) // math.gcd(x, y)
# lcm = lambda x, y: (x * y) // fractions.gcd(x, y)

MOD = 10 ** 9 + 7
MAX = float('inf')


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    N, T = il()
    time = il()

    ret = T
    for n in range(N-1):
        ret += min(abs(time[n] - time[n + 1]), T)
    print(ret)


if __name__ == '__main__':
    main()


Measured memory_bytes: 29212
r,m,I=range,max,input
for lp in r(99):
 W=I()+1
 if W==1:break
 N=I()
 D=[0]*W
 for loop in r(N):
  v,w=map(int,raw_input().split(','))
  for i in r(w,W)[::-1]:D[i]=m(D[i],D[i-w]+v)
 print'Case',str(lp+1)+':'
 print m(D)
 print D.index(m(D))


Measured memory_bytes: 4700
#include<cstdio>
#include<iostream>

using namespace std;

int main(void){

	int N,B=0,C=0,ball,flag=0;

	cin>>N;

	for(int i=0;i<N;i++){
		B=0,C=0,flag=0;
		for(int j=0;j<10;j++){
			cin>>ball;
			if(ball>B){
				if(ball>C){
					if(C>B) C=ball;
					else B=ball;
				}
				else B=ball;
			}
			else if(ball>C){
				C=ball;
			}
			else flag=1;
		}
		if(flag==0) cout<<"YES"<<endl;
		else cout<<"NO"<<endl;
	}

return 0;

}

Measured memory_bytes: 1148
#include<stdio.h>
#include<stdlib.h>
#include<string.h>

typedef struct node{
 int num;
 struct node *left;
 struct node *right;
}node;


node * makenode(int x){

 node *new=malloc(sizeof(node));
 new->right=NULL;
 new->left=NULL;
 new->num=x;

return new;
}


int main(){
 int n,i,x;
 char com[13];
 node *front=NULL;
 node *rear=NULL;
 node *new;
 node **p;
 node *q;

 scanf("%d",&n);

 for(i=0;i<n;i++){
  scanf("%s",com);

  if(com[0]=='i'){
    scanf("%d",&x);
    new=makenode(x);
    new->right=front;
    if(front!=NULL)front->left=new;
    else rear=new;
    front=new;
  }

  else if(strcmp(com,"deleteFirst")==0){
    front=front->right;
    if(front!=NULL){
       free(front->left);
       front->left=NULL;
    }
    else rear=NULL;
  }

  else if(strcmp(com,"deleteLast")==0){
    rear=rear->left;
    if(rear==NULL)front=NULL;
    else {
     free(rear->right);
     rear->right=NULL;
    }
  }

  else if(strcmp(com,"delete")==0){
    scanf("%d",&x);
    p=&front;
    while((*p)!=NULL && (*p)->num != x)p=&((*p)->right);
    if((*p)!=NULL){
     if((*p)->right == NULL){
        rear=rear->left;
        free((*p));
        (*p)=NULL;
     }
     else {
        (*p)->right->left=(*p)->left;
        (*p)=(*p)->right;
     }
    }
  }

 }

 q=front;
 while(q!=NULL){
  if(q==rear)printf("%d\n",q->num);
  else printf("%d ",q->num);
  q=q->right;
 }

return 0;
}


Measured memory_bytes: 32928
#include<bits/stdc++.h>
using namespace std;

vector<int>a[100001];
queue<int>q1,q2;
int vis1[100001]={0}, vis2[100001]={0};
int cnt1=0, cnt2=0;
queue<int>q;
int N;

void bfs(void){

    vis1[1]=1;
    vis2[N]=1;
    q.push(1);
    q.push(N);
    while(!q.empty()){

        int t;
        t=q.front();

        q.pop();
        if( vis1[t]==1 ){
            cnt1++;
            for( int i=0; i < a[t].size(); i++)
                if(!vis1[ a[t][i] ] &&  !vis2[ a[t][i] ]  )
                    vis1[ a[t][i] ]=1,q.push( a[t][i] );
        }
        else{
            cnt2++;
            for(int i=0; i<a[t].size(); i++)
                if(!vis1[a[t][i]] &&  !vis2[a[t][i]])
                    vis2[a[t][i]]=1,q.push( a[t][i] );
        }
    }
}

int main(void){
    cin>>N;
    int u,v;
    for(int i=0; i<N-1; i++){
        scanf("%d%d",&u,&v);
        a[u].push_back(v);
        a[v].push_back(u);
    }
    bfs();

    if(cnt1<=cnt2)
        printf("Snuke\n");
    else
        printf("Fennec\n");

}


Measured memory_bytes: 6656
#include <iostream>
#include <algorithm>
using namespace std;
string s; 
int i, n;
int main() {
cin>>n;
int a[n];
for(i=0; i<n; i++)
  cin>>a[i];
sort(a, a+n);
for(i=0; i<n-1; i++){
  if(a[i]==a[i+1]){
    cout<<"NO";
    return 0;
  }
}
cout<<"YES";
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define chkmin(a,b) ((a)<(b)?(a):(b))
#define chkmax(a,b) ((a)>(b)?(a):(b))
#define f(i,a,b) for(register int i=(a);i<=(b);i=-(~(i)))
using namespace std;
int a,b,flag;
char ans[310][310];
void print1(int x,int y)
{
	ans[(x-1)*4+1][(y-1)*4+1]=1;
	ans[(x-1)*4+1][(y-1)*4+2]=1;
	ans[(x-1)*4+1][(y-1)*4+3]=1;
	ans[(x-1)*4+2][(y-1)*4+1]=1;
	ans[(x-1)*4+2][(y-1)*4+3]=1;
	ans[(x-1)*4+3][(y-1)*4+1]=1;
	ans[(x-1)*4+3][(y-1)*4+2]=1;
	ans[(x-1)*4+3][(y-1)*4+3]=1;
}
void print2(int x,int y)
{
	ans[(x-1)*4+1][(y-1)*4+1]=1;
	ans[(x-1)*4+1][(y-1)*4+2]=1;
	ans[(x-1)*4+1][(y-1)*4+3]=1;
	ans[(x-1)*4+2][(y-1)*4+1]=1;
	ans[(x-1)*4+2][(y-1)*4+2]=1;
	ans[(x-1)*4+2][(y-1)*4+3]=1;
	ans[(x-1)*4+3][(y-1)*4+1]=1;
	ans[(x-1)*4+3][(y-1)*4+2]=1;
	ans[(x-1)*4+3][(y-1)*4+3]=1;	
}
void create()
{
	int nowx=0,nowy=1;
	if(a>b)flag=1,swap(a,b);
	f(i,1,a-1)
	{
		++nowx;
		if(nowx>25)nowx=1,++nowy;
		print1(nowx,nowy);
	}
	f(i,1,b-a+1)
	{
		++nowx;
		if(nowx>25)nowx=1,++nowy;
		print2(nowx,nowy);
	}
}
int main()
{
	scanf("%d %d",&a,&b);
	printf("100 100\n");
	create();
	if(flag)
	f(i,1,100)
	{
	 	f(j,1,100)printf("%c",ans[i][j]?'.':'#');
	 	putchar('\n');
	}
	else
	f(i,1,100)
	{
	 	f(j,1,100)printf("%c",ans[i][j]?'#':'.');
	 	putchar('\n');
	}return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>

int compare(std::string a, std::string b)
{
    for(int i = 0; i < a.size() && i < b.size(); ++i){
        if(a[i] > b[i]) return 1;
        if(a[i] < b[i]) return -1;
    }
    if(a.size() == b.size()) return 0;
    if(a.size() >  b.size()) return 1;
    return -1;
}

int main()
{
    int taro = 0;
    int hana = 0;
    int n;
    std::cin >> n;
    for(int i = 0; i < n; i++){
        std::string t;
        std::string h;
        std::cin >> t >> h;
        // if(compare(t,h) < 0){
        if(t.compare(h) < 0){
            hana += 3;
        }else
        // if(compare(t,h) > 0){
        if(t.compare(h) > 0){
            taro += 3;
        }else{
            hana += 1;
            taro += 1;
        }
    }
    std::cout << taro << " " << hana << std::endl;
    return 0;
}

Measured memory_bytes: 3188
#include <algorithm>
#include <bitset>
#include <iomanip>
#include <ios>
#include <iostream>
#include <numeric>
#include <string>
#include <vector>
using namespace std;

int main()
{
    string s;
    cin >> s;
    cout << s.substr(0, 5) << " ";
    cout << s.substr(6, 7) << " ";
    cout << s.substr(14, 5) << "\n";
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm> //sort()使うなら必要
#include<vector> //vector使うなら必要
#include<cstdlib> //abs()使うなら必要
using namespace std;
 
int main(){
	long long n, m, ans = 0;
    vector<long long> x;

	cin >> n >> m;

    //コマの数が目標地点の数以上ならコマを置くだけで終了するので最小値は0
    if(n >= m){
        cout << 0 << endl;
        return 0;
    }

    //M個の地点を格納
    for(long long i = 0; i < m; i++){
        long long j;
        cin >> j;
        x.push_back(j);
    }
 
    //昇順にソート（昇順なら第3引数要らない）
    sort(x.begin(), x.end());

    //各地点間の距離（の絶対値）を求めてリストにする
    vector<long long> distance;
    for(long long k = 0; k < m - 1; k++){
        distance.push_back(labs(x[k] - x[k+1]));
    }
    
    //距離が短い順（昇順）に並び替える
    sort(distance.begin(), distance.end());

    //distanceのうち、距離が短い順にM-N個選んだ距離の総和が最小値
    for(long long l = 0; l < (m - n); l++){
        ans += distance[l];
    }
 
	cout << ans;
    return 0;
}

Measured memory_bytes: 2548
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<iomanip>
using namespace std;
typedef long long ll;
#define REP(i,n) for(int i=0; i<(n); i++)
#define FOR(i,a,b) for(int i=(a); i<(b); i++)
const long long INF = 1LL << 60;

int main(){
    int n;
    ll T;
    cin >> n >> T;
    vector<ll> t(n);
    REP(i,n){
        cin >> t[i];
    }

    ll ans = 0;
    if(n==1){
        cout << T << endl;
        return 0;
    }
    
    REP(i,n-1){
        if(t[i+1]-t[i]<T){
            ans += t[i + 1] - t[i];
        }
        else{
            ans += T;
        }
    }
    ans += T;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
#define ll long long
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
using namespace std;
int main()
{
  IOS;
  ll t=1;
  //cin>>t;
  while(t--)
  {
    ll i,n,k,sum=0,x,p=0,l,r,ans=0,mx,cnt=0,m,j;
    cin>>n;
    vector<ll>v;
    vector<ll>v1(n,0);
    for(i=0;i<n;i++)
    {
      cin>>p;
      v.push_back(p);
    }
    sort(v.begin(),v.end(),greater<ll>());
    ans=v[0];
    j=1;
    for(i=2;i<n;i=i+2)
    {
      if(i<n-1)
      ans+=2*v[j];
      else
      ans+=v[j];

      j++;
    }
     cout<<ans<<"\n";
  }
    return 0;
}


Measured memory_bytes: 6896
import java.util.*;

public class Main {
	public static void main(String[] args) {  
  		Scanner sc = new Scanner(System.in);
      	int num = sc.nextInt();
      	int[] ary = new int[num];
      	boolean hasOdd = false;	
      
      	for(int i = 0; i < num; i++) {
        	ary[i] = sc.nextInt();
          	if(ary[i] %2 == 1) hasOdd = true;
        }
      	if(hasOdd) {
        	System.out.println(0);  
        } else {
          	int min = Integer.MAX_VALUE;
        	for(int i = 0; i < num; i++) {  
          		int count = 0;
              	while(ary[i] %2 == 0) {
                	ary[i] /= 2;  
                  	count++;
                }
              	if(count < min) min = count;
            }
          	System.out.println(min);
        }
    }
}

Measured memory_bytes: 21076
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define reps(i, n) for (int i = 1, i##_len = (n); i <= i##_len; ++i)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; --i)
#define rreps(i, n) for (int i = ((int)(n)); i > 0; --i)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define repc2(i, s, n) for (int i = (s); i <= (int)(n); i++)
#define inf 2e9
#define linf 9000000000000000000ll
#define all(v) v.begin(), v.end()
using namespace std;
typedef long long ll;

int n;
ll cnt[10009];
int main() {
    cin >> n;
    reps(x, 100) {
        reps(y, 100) {
            reps(z, 100) {
                if (x * x + y * y + z * z + x * y + y * z + z * x <= 10000) {
                    cnt[x * x + y * y + z * z + x * y + y * z + z * x]++;
                }
            }
        }
    }
    reps(i, n) { printf("%lld\n", cnt[i]); }
    return 0;
}

Measured memory_bytes: 3720
#include<bits/stdc++.h>
using namespace std;

int main()
{
    int x,y,a[5];
    cin>>x>>y;
    a[0]=x+y;
    a[1]=x-y;
    a[2]=x*y;
    sort(a,a+3);
    cout<<a[2]<<endl;

    return 0;
}





Measured memory_bytes: 256
#include<stdio.h>
int Partition(int *A,int p,int r){
  int i,x,j,temp;
  x = A[r];
  
  i = p-1;
  for(j = p;j <= r-1;j++){
    if(A[j] <= x){
      i = i + 1;
      temp=A[i];
      A[i]=A[j];
      A[j]=temp;
    }
  } 
  temp=A[i+1];
  A[i+1]=A[r];
  A[r]=temp;
  return i+1;
}
int main(void){
  int n,i,A[100000],p;
  scanf("%d",&n);
  for(i=0;i<n;i++)
    scanf("%d",&A[i]);
  p=Partition(&A[0],0,n-1);
  printf("%d",A[0]);
  for(i=1;i<n;i++)
    if(i==p)
      printf(" [%d]",A[i]);
    else printf(" %d",A[i]);
  printf("\n");
  return 0;
}

Measured memory_bytes: 996
#include<bits/stdc++.h>
#include<cctype>
using namespace std;
#define rep(i,n) for (int i=0;i<(n);i++)
#define all(v) (v).begin(),(v).end()
typedef long long int ll;
#define pi 3.1415926535897932384
#define E9 1000000000
#define eps 1e-4
#define pii pair<int,int>


int main(){
  int H, W; cin >> H >> W;
  string s[H];
  rep(i,H) cin >> s[i];

  queue<pii> q;
  q.push({0,0});
  vector<vector<int>> dist(H,vector<int>(W,-1));
  dist[0][0] = 1;
  int to_r[4] = {0,0,-1,1};
  int to_c[4] = {1,-1,0,0};

  while(!q.empty()){
    auto now = q.front(); q.pop();
    rep(i,4){
      int row = now.first + to_r[i], col = now.second + to_c[i];
      if (row<0 || row >= H || col<0 || col>=W) continue;
      if (s[row][col]=='.' && dist[row][col]==-1) {
        q.push({row,col});
        dist[row][col] = dist[now.first][now.second] + 1;
      }

    }
  }

  if (dist[H-1][W-1]==-1) {
    cout << -1 << endl;
    return 0;
  }

  int ans = 0;
  rep(i,H) rep(j,W) if (s[i][j]=='.') ans++;
  cout << ans - dist[H-1][W-1] << endl;
   

  




  // cout << fixed << setprecision(10);
  
  return 0;
}


Measured memory_bytes: 3628
#include<iostream>
using namespace std;
int main(){

while(1){
int H,W;
cin>>H>>W;
if(H==0&&W==0) break;
for(int i=0; i<H;i++){
for(int j=0; j<W;j++){
if (i ==0||i==H-1||j==0||j==W-1) cout<<"#";
else
cout<<".";
}
cout<<endl;
}cout<<endl;
}return 0;
}


Measured memory_bytes: 3076
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
const ll mod = 1000000007;

int main() {
    int n;
    cin >> n;

    vector<pair<int, int>> red(n), blue(n);
    rep(i, n) {
        int a, b;
        cin >> a >> b;
        red[i] = make_pair(b, a);
    }
    rep(i, n) {
        int c, d;
        cin >> c >> d;
        blue[i] = make_pair(c, d);
    }
    sort(red.begin(), red.end());
    reverse(red.begin(), red.end());  // red(n)をy座標の降順にソート
    sort(blue.begin(), blue.end());  // blue(n)をx座標の昇順にソート

    vector<int> used(n);  // used[j] : 1のときred[j]はすでに選ばれている

    int ans = 0;
    rep(i, n) {
        rep(j, n) {
            if(used[j] == 0 && red[j].second < blue[i].first && red[j].first < blue[i].second) {
                used[j] = 1;
                ans++;
                break;
            }
        }
    }

    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;

int n;
vector<int> va;

int main(){
	cin >> n;
	va.resize(n);
	for(int i = 0; i < n; i++){
		cin >> va[i];
	}
	va.erase(unique(va.begin(), va.end()), va.end());
	for(int i = 0; i < va.size(); i++){
		cout << va[i];
		if(i == va.size() - 1) cout << endl;
		else cout << ' ';
	}
	return 0;
}


Measured memory_bytes: 3096
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vi = vector<int>;    using vvi = vector<vi>;
using vb = vector<bool>;   using vvb = vector<vb>;
using vl = vector<ll>;     using vvl = vector<vl>;
using vd = vector<double>; using vvd = vector<vd>;

#define REP(i,n) for(ll i = 0; i < (n); ++i)
#define ALL(c) (c).begin(), (c).end()
#define FOR(i,s,e) for (ll i = s; i < (ll)e; i++)
#define TEN(x) ((ll)1e##x)


int main() {
#ifdef INPUT_FROM_FILE
	ifstream cin("sample.in");
	ofstream cout("sample.out");
#endif
	cin.tie(0);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(50);
	ll n; cin >> n;
	vl l(2*n); REP(i, 2*n) cin >> l[i];
	sort(ALL(l));
	ll sum = 0;
	for (ll i = 0; i < 2*n; i += 2) sum += l[i];
	cout << sum << endl;
	return 0;
}

Measured memory_bytes: 256
using System;
using System.Linq;

namespace Contest
{


    class Program
    {

        static void Main(string[] args)
        {
            var input = Console.ReadLine().Split().Select(int.Parse).ToArray();
            int n = input[0];
            int m = input[1];
            int x = input[2];

            int[] c = new int[n];
            int[,] a = new int[n,   m];
            
            for(int i = 0; i < n; i++)
            {
                input = Console.ReadLine().Split().Select(int.Parse).ToArray();
                c[i] = input[0];
                for(int j = 0; j < m; j++)
                {
                    a[i, j] = input[j + 1];
                }

            }

            
            long ans = 10000000;

            for(int i = 1; i < (1 << n); i++)
            {
                int bit = 1;
                int shift = 0;
                long cost = 0;
                long[] skills = new long[m];

                while (i >= bit)
                {
                    if((i & bit) == bit)
                    {
                        cost += c[shift];
                        for (int j = 0; j < m; j++)
                        {
                            skills[j] += a[shift, j];
                        }
                    }
                    shift++;
                    bit = bit << 1;
                }

                bool over = true;
                foreach(var skill in skills)
                {
                    if(skill < x)
                    {
                        over = false;
                        break;
                    }
                }

                if(over && ans > cost)
                {
                    ans = cost;
                }

            }
            if (ans == 10000000)
            {
                Console.WriteLine(-1);
            }
            else
            {
                Console.WriteLine(ans);

            }
        }
    }
}

Measured memory_bytes: 28628