akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
using ll = long long;

#define rep(i,n) for(ll i=0;i<ll(n);i++)
#define YESNO(T) if(T){cout<<"YES"<<endl;}else{cout<<"NO"<<endl;}
#define yesno(T) if(T){cout<<"yes"<<endl;}else{cout<<"no"<<endl;}
#define YesNo(T) if(T){cout<<"Yes"<<endl;}else{cout<<"No"<<endl;}

const ll INF = 1LL << 60;
const ll MOD = 1e9 + 7;
const double pi = 3.14159265358979;



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

    ll n;
    cin >> n;

    ll ans = INF;
    for (ll a = 1; a*a <= n; a++){
        if (n%a != 0){
            continue;
        }

        ll b = n/a;
        string x = to_string(a);
        string y = to_string(b);
        ll m = max(x.size(),y.size());
        ans = min(ans,m);
    }

    cout << ans << endl;
}

Measured memory_bytes: 3700
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <cmath>
using namespace std;

int main()
{
	int in,a,maxer=0,miner=1000;
	int sum=0;
	int i=0;
	double ave=0.0;
	while( cin >> in,in ){
		for(i=0; i<in; i++){
			cin >> a;
			maxer=max(a,maxer);
			miner=min(a,miner);
			sum += a;
		}
		sum = sum - maxer - miner;
		ave = sum/(in-2);
		cout << floor(ave) << endl;
		sum = maxer = ave = 0;
		miner=1000;
	}
}

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

int main()
{
  long long n, m;
  scanf("%lld%lld", &n, &m);
  long long rj = 0;
  if (m < 2 * n) rj += m / 2LL;
  else {
    rj += n;
    m -= 2LL * n;
    rj += m / 4LL;
  }
  printf("%lld\n", rj);
  return 0;
}


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

enum{
	T, F, R, Ba, L, Bo
};

const char* pattern[ 24 ] =
{
	/*
	"012345", "023415", "034125", "041235",
	"104523", "145203", "152043", "120453",
	"201534", "215304", "253014", "230154",
	"302541", "325401", "354021", "340251",
	"403512", "435102", "451032", "410352",
	"514320", "543210", "532140", "521430",
	*/
	"012435", "024315", "043125", "031245",
	"103524", "135204", "152034", "120354",
	"201543", "215403", "254013", "240153",
	"304512", "345102", "351042", "310452",
	"402531", "425301", "453021", "430251",
	"513420", "534210", "542130", "521340",
};

const int contact[ 8 ][ 6 ] =
{
	{ -1, -1, -1, -1, -1, -1 },
	{ -1, -1, 0, -1, -1, -1 },
	{ -1, -1, -1, 0, -1, -1 },
	{ -1, -1, 2, 1, -1, -1 },
	{ 0, -1, -1, -1, -1, -1 },
	{ 1, -1, -1, 4, -1, -1 },
	{ 2, -1, -1, -1, 4, -1 },
	{ 3, -1, -1, 6, 5, -1 },
};

const int touch[] =
{
	Bo, Ba, L, F, R, T,
};

bool rec( vector< string >& dice, vector< pair< int, int > >& put, int n, int selected )
{
	if( n == 8 ){
		return true;
	}

	int offset = 'a' - 'A';
	for( int i = 0; i < 8; ++i ){
		if( selected & ( 1 << i ) ){
			continue;
		}
		for( int j = 0; j < 24; ++j ){
			put.push_back( make_pair( i, j ) );
			bool miss = false;
			for( int k = 0; k < 6; ++k ){
				int pos = contact[ n ][ k ];
				if( pos >= 0 ){
					char c1 = dice[ i ][ pattern[ j ][ k ] - '0' ];
					char c2 = dice[ put[ pos ].first ][ pattern[ put[ pos ].second ][ touch[ k ] ] - '0' ];
					if( c1 > c2 ){
						c1 -= offset;
					}else{
						c2 -= offset;
					}
					if( c1 != c2 ){
						miss = true;
						break;
					}
				}
			}
			if( !miss && rec( dice, put, n + 1, selected | ( 1 << i ) ) ){
				return true;
			}
			put.pop_back();
		}
	}

	return false;
}

string solve( vector< string >& dice )
{
	vector< pair< int, int > > put;
	if( rec( dice, put, 0, 0 ) ){
		return "YES";
	}
	return "NO";
}

int main()
{
	string s;
	while( cin >> s && s != "0" ){
		vector< string > dice;
		dice.push_back( s );
		for( int i = 0; i < 8 - 1; ++i ){
			cin >> s;
			dice.push_back( s );
		}

		cout << solve( dice ) << endl;
	}

	return 0;
}

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

int main() {
    string s;
    cin >> s;
    int sum = 0;
    for (int i = 0; i < s.size(); i++){
        char a;
        a = s.at(i);
        sum += a - '0';
    }
    if(sum % 9 == 0)cout << "Yes" << endl;
    else cout << "No" << endl;
}

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

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

    int n;
    long long int a,b,t;
    vector <long long int> v;

    cin >> n >> a >> b;

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

    sort(v.rbegin(),v.rend());

    long long int lo = 0;
    long long int hi = 1e9;

    while(lo<=hi)
    {
        long long int mid = (lo + hi)/2;
        long long int count = 0;
        for(int i=0;i<n;i++)
        {
            long long int temp = v[i] - (b*mid);
            long long int c = a - b;
            if(temp<=0)
            {
                break;
            }
            count += ceil((1.0*temp)/c);
        }

        bool ok = true;
        if(count > mid)
        {
            ok = false;
        }

        if(ok)
        {
            hi = mid - 1;
        }
        else
        {
            lo = mid + 1;
        }
    }

    cout << lo << '\n';

    return 0;
}


Measured memory_bytes: 1400
from sys import stdin
def main():
    #入力
    readline=stdin.readline
    n,y=map(int,readline().split())

    flag=False
    for i in range(0,n+1):
        for j in range(0,n+1):
            if n<i+j: continue
            k=n-i-j
            if 10000*i+5000*j+1000*k==y:
                print(i,j,k)
                flag=True
                break
        if flag: break

    if flag==False: print(-1,-1,-1)

if __name__=="__main__":
    main()

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

int main(){
    ll a, v, b, w, t;
    cin >> a >> v >> b >> w >> t;

    string ans = "NO";
    if(v <= w){
        cout << ans << endl;
        return 0;
    }

    if(abs(b-a) <= t*(v-w)){
        ans = "YES";
    }

    cout << ans << endl;
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
#define Maxn 200007
int f[Maxn][3],n;
char s[Maxn];
int main()
{
    scanf("%s",s+1);
    n=strlen(s+1);
    for (int i=1;i<=n;i++)
        f[i][1]=-500007,f[i][2]=-500007;
    f[1][1]=1;
    f[2][2]=1;
    if (s[1]!=s[2]) f[2][1]=2;
    for (int i=3;i<=n;i++)
    {
        f[i][1]=max(f[i][1],f[i-1][2]+1);
        if (s[i]!=s[i-1]) f[i][1]=max(f[i][1],f[i-1][1]+1);
        f[i][2]=max(f[i][2],f[i-2][1]+1);
        if ((s[i]!=s[i-2])||(s[i-1]!=s[i-3])) f[i][2]=max(f[i][2],f[i-2][2]+1);
    }
    printf("%d\n",max(f[n][1],f[n][2]));
    return 0;
}

Measured memory_bytes: 6320
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define rrep(i,n) RREP(i,n-1,0)
#define all(v) v.begin(), v.end()
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 998244353;

ll modpow(ll a, ll N) {
  ll ans = 1;
  ll tmp = a;
  while(N > 0) {
    if(N % 2 == 1) (ans *= tmp) %= mod;
    (tmp *= tmp) %= mod;
    N /= 2;
  }
  return ans;
}
ll modinv(ll a, ll m=mod) {
  ll b = m, u = 1, v = 0;
  while(b) {
    ll t = a / b;
    a -= t * b; swap(a, b);
    u -= t * v; swap(u, v);
  }
  u %= m;
  if(u < 0) u += m;
  return u;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll A, B, C, D;
  cin >> A >> B >> C >> D;
  vector<vector<ll>> dp(C+1, vector<ll>(D+1));
  dp[A][B] = 1;
  REP(i, A, C+1) {
    REP(j, B, D+1) {
      if(i > A) (dp[i][j] += dp[i-1][j] * j) %= mod;
      if(j > B) (dp[i][j] += dp[i][j-1] * i) %= mod;
      if(i > A && j > B) (dp[i][j] += mod - (dp[i-1][j-1] * (i-1) * (j-1)) % mod) %= mod;
    }
  }
  cout << dp[C][D] << endl;
  return 0;
}


Measured memory_bytes: 73636
s = [c for c in input()]
result = 'Yes'
for index, step in enumerate(s, start=1):
    if index % 2 == 1:
        if step not in "RUD":
            result = 'No'
            break
    else:
        if step not in "LUD":
            result = 'No'
            break

print(result)


Measured memory_bytes: 8996
#include<iostream>
#include<algorithm>
#include<iomanip>
using lint=long long;
using namespace std;

int main()
{
	int N;
	double p[3010]={};
	
	cin >> N;
	for(int i=1;i<=N;i++)
		cin >> p[i];
	
	double dp[3010][3010]={};
	dp[0][0]=1.0;
	for(int i=1;i<=N;i++)
		dp[i][0]=dp[i-1][0]*(1.0-p[i]);
	for(int i=1;i<=N;i++)
		for(int j=1;j<=N;j++)
			dp[i][j]=dp[i-1][j-1]*p[i]+dp[i-1][j]*(1.0-p[i]);
	
	double ans=0;
	for(int j=0;j<=N;j++)
		if(j>N-j)ans+=dp[N][j];
	
	cout << fixed << setprecision(10);
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 71040
n = int(input())
A = list(map(int, input().split()))
mod = 10**9+7
array = [0] * 60
for a in A:
    for j in range(len(bin(a))-2):
        array[j] += (a >> j) & 1
ans = 0
for i in range(60):
    ans += array[i] * (n-array[i]) * 2**i
print(ans % mod)


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


int main(){
  int n, d;
  cin >> n >> d;
  
  int X[n][d];
  for(int i=0; i<n; i++){
    for(int j=0; j<d; j++){
      cin >> X[i][j];
    }
  }  
  int ans=0;

  for(int i=0; i<n-1; i++){
    for(int j=i+1; j<n; j++){
      int sum=0;
      for(int k=0; k<d; k++){
        sum += pow(X[i][k] - X[j][k], 2);
      }

      if(ceil(sqrt(sum)) == sqrt(sum)){
        ans++;
      }
    }
  }

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

Measured memory_bytes: 256
#include <cmath>
#include <cstdio>

int main() {
  while (1) {
    int n;
    scanf("%d", &n);
    if (n == 0) {
      break;
    }
    int s[1000];
    for (int i = 0; i < n; i++) {
      scanf("%d", &s[i]);
    }

    double m = 0;
    for (int i = 0; i < n; i++) {
      m += s[i];
    }
    m /= n;

    double a = 0;
    for (int i = 0; i < n; i++) {
      a += (s[i] - m) * (s[i] - m) / n;
    }
    a = sqrt(a);

    printf("%f\n", a);
  }

  return 0;
}


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

int main(void){
  int a, b;
  cin >> a;
  cin >> b;
  int count = 1;
  for(int i = 0; i < 100; i++){
    if((a - 1) * count + 1 >= b){
      break;
    } else {
      count++;
    }
  }
  if(b == 1){
    count = 0;
  }
  cout << count;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define rep(i,n) for(ll i=0;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define dunk(a) cout << (a) << endl
using namespace std;
typedef long long ll;

int n,k;
vector<int> h;

ll dp[100100];

template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main(){
    cin >> n >> k;
    h.resize(n); rep(i,n) cin >> h[i];

    rep(i,100100) dp[i] = 1e9;
    dp[0] = 0;

    for(int i=0; i<n; i++){
        for(int j=0; j<=k; j++){
            if(i+j < n) chmin(dp[i+j], dp[i] + abs(h[i+j] - h[i]));
        }
    }

    dunk(dp[n-1]);

}

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

int main(){
    int n;
    cin >> n;
    double a,tmp;
    rep(i,n){
        cin >> a;
        tmp+=1/a;
    }
    cout << 1/tmp << endl;
}

Measured memory_bytes: 256
S = input().strip()
C = {"a":0,"b":0,"c":0}
for i in range(len(S)):
    C[S[i]] += 1
cmin = min(C["a"],C["b"],C["c"])
for x in C:
    C[x] -= cmin
cmax = max(C["a"],C["b"],C["c"])
if cmax<=1:
    print("YES")
else:
    print("NO")

Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
int main(void)
{
	int n;
	cin >> n;
	long long a[n];
	int minus_count = 0;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		if (a[i] < 0) {
			minus_count++;
		}
	}
	long long sumabs = 0;
	for (int i = 0; i < n; i++)
		sumabs += abs(a[i]);
	if (minus_count%2 == 0) {
		cout << sumabs << endl;
	} else {
		long long ans;
		for (int i = 0; i < n; i++) {
			if (i == 0)
				ans = sumabs - abs(a[i])*2;
			else
				ans = max(ans, sumabs - abs(a[i])*2);
		}
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 4344
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <queue>
#include <numeric>

using namespace std;

typedef long long ll;

long long GCD(long long a, long long b){if(b==0)return a;return GCD(b,a%b);}

int main() {
    long long X, Y; cin >> X >> Y;
    int res = 0;
    while (X <= Y) X *= 2, ++res;
    cout << res << endl;
}



Measured memory_bytes: 256
a = [0]*6+[1,0,1,0,0,0,0]*42857
p=[]
for i in range(6,300000,7):
    if a[i]:
        p.append(i)
        for j in range(i**2,300000,i):
            a[j]=0
    if a[i+2]:
        p.append(i+2)
        for j in range((i+2)**2,300000,i+2):
            a[j]=0

while True:
    n=int(input())
    if n==1:
        break
    ans = "{}:".format(n)
    for i in p:
        if n%i==0:
            ans += " {}".format(i)
    print(ans)



Measured memory_bytes: 9940
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
int x,n,a[1000],ans[1000],cnt;
void check()
{
	int anss=1;
	for (int i=1;i<=n;i++)
		anss=anss*ans[i];
	if (!(anss&1))
	{
		cnt++;
	}
}
void dfs(int now)
{
	if (now>n)
		check();
	else
	{
		ans[now]=a[now];
		dfs(now+1);
		ans[now]=a[now]-1;
		dfs(now+1);	
		ans[now]=a[now]+1;
		dfs(now+1);
	}
}
main()
{
	scanf("%d",&n);
	for (int i=1;i<=n;i++)
		scanf("%d",&a[i]);
	dfs(1);
	printf("%d\n",cnt);
}

Measured memory_bytes: 256
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<math.h>
using namespace std;
typedef long long ll;
typedef vector<int> VI;
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define SORT(c) sort((c).begin(),(c).end())
#define rSORT(c) sort((c).rbegin(),(c).rend())
#define INF 1000000000
#define LLINF 9223372036854775807
#define mod 1000000007
//vector<vector<int> > dp;
//vector<vector<vector<int> > > vvvi;
//dp=vector<vector<int> >(N, vector<int>(M,0));
//vector<pair<int,int> > v;
//v.push_back(make_pair(x,y));

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

	int N,A,B;
	cin>>N>>A>>B;
	ll ans=0;
	FOR(i,1,N+1){
		int a;
		if(i<10)a=1;
		else if(i>=10 && i<100)a=2;
		else if(i>=100 && i<1000)a=3;
		else if(i>=1000 && i<10000)a=4;
		else a=5;
		int cnt=0;
		//cout<<s.size()<<endl;
		int b=i;
		while(a!=0){
			cnt+=b%10;
			b/=10;
			a--;
		}
		if(A<=cnt && cnt<=B){
			ans+=i;
			//cout<<i<<endl;
		}
	}
	cout<<ans<<endl;
	
	return 0;
}

Measured memory_bytes: 256
//by yjz
#include<bits/stdc++.h>
using namespace std;
#define FF first
#define SS second
#define PB push_back
#define MP make_pair
#define foreach(it,s) for(__typeof((s).begin()) it=(s).begin();it!=(s).end();it++)
#ifndef LOCAL
#define cerr if(0)cout
#endif
typedef long long ll;
const int mod=1e9+7;
//My i/o stream
struct fastio
{
	char s[100000];
	int it,len;
	fastio(){it=len=0;}
	inline char get()
	{
		if(it<len)return s[it++];it=0;
		len=fread(s,1,100000,stdin);
		if(len==0)return EOF;else return s[it++];
	}
	bool notend()
	{
		char c=get();
		while(c==' '||c=='\n')c=get();
		if(it>0)it--;
		return c!=EOF;
	}
}_buff;
#define geti(x) x=getnum()
#define getii(x,y) geti(x),geti(y)
#define getiii(x,y,z) getii(x,y),geti(z)
#define puti(x) putnum(x),putchar(' ')
#define putii(x,y) puti(x),puti(y)
#define putiii(x,y,z) putii(x,y),puti(z)
#define putsi(x) putnum(x),putchar('\n')
#define putsii(x,y) puti(x),putsi(y)
#define putsiii(x,y,z) putii(x,y),putsi(z)
inline ll getnum()
{
	ll r=0;bool ng=0;char c;c=_buff.get();
	while(c!='-'&&(c<'0'||c>'9'))c=_buff.get();
	if(c=='-')ng=1,c=_buff.get();
	while(c>='0'&&c<='9')r=r*10+c-'0',c=_buff.get();
	return ng?-r:r;
}
template<class T> inline void putnum(T x)
{
	if(x<0)putchar('-'),x=-x;
	register short a[20]={},sz=0;
	while(x)a[sz++]=x%10,x/=10;
	if(sz==0)putchar('0');
	for(int i=sz-1;i>=0;i--)putchar('0'+a[i]);
}
inline char getreal(){char c=_buff.get();while(c<=32)c=_buff.get();return c;}
ll qpow(ll x,ll k){return k==0?1:1ll*qpow(1ll*x*x%mod,k>>1)*(k&1?x:1)%mod;}
int n,a[111];
ll w[111][111],dp[111];
vector<pair<pair<int,int>,int> >V;
int pw2[211];
void solve(int pre,int l,int r)
{
	int mn=a[l];
	for(int i=l;i<=r;i++)mn=min(mn,a[i]);
	V.PB(MP(MP(l,r),mn-pre));
	for(int i=l;i<=r;i)
	{
		if(a[i]==mn)i++;
		else
		{
			int r=i;
			while(a[r]>mn)r++;
			solve(mn,i,r-1);
			i=r;
		}
	}
}
int main()
{
	geti(n);
	for(int i=1;i<=n;i++)
	{
		geti(a[i]);
	}
	solve(0,1,n);
	for(int i=0;i<V.size();i++)pw2[i]=qpow(2,V[i].SS);
	for(int i=1;i<=n;i++)
	{
		for(int j=i;j<=n;j++)
		{
			w[i][j]=1;
			for(int k=0;k<V.size();k++)
			{
				if(i<=V[k].FF.FF&&V[k].FF.SS<=j)
				{
					w[i][j]=1ll*w[i][j]*pw2[k]%mod;
				}
			}
		}
	}
	w[1][n]=1ll*w[1][n]*qpow(2,mod-2)%mod;
	dp[0]=1;
	for(int i=1;i<=n;i++)
	{
		dp[i]=0;
		for(int j=1;j<=i;j++)
		{
			dp[i]=(dp[i]+1ll*w[j][i]*dp[j-1])%mod;
		}
	}
	cout<<(2ll*dp[n]%mod+mod)%mod;
	return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
int main(){
	ios::sync_with_stdio(false);
	int n,k;
	cin>>n>>k;
	int a[n+1];
	for(int i=1;i<=n;++i)cin>>a[i];
	for(int i=1;i<=n-k;++i){
		if(a[i]<a[i+k])
		cout<<"Yes"<<endl;
		else
		cout<<"No"<<endl;
	}
	 return 0;
}

Measured memory_bytes: 4400
#include<iostream>
#include<algorithm>
#include<functional>
#include<cmath>
#include<string>
#include<vector>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<deque>
using namespace std;
#define ll long long
const int mod = 1000000007;
const ll INF = 1000000000000000000;

ll gcd(ll a, ll b)
{
	if (a < b) return gcd(b, a);
	if (b == 0) return a;
	else return gcd(b, a % b);
}

ll lcm(ll a, ll b)
{
	return a * (b / gcd(a, b));
}
ll T[110];

int main()
{
	int N;
	cin >> N;
	for (int i = 0; i < N; i++)cin >> T[i];
	ll ans = T[0];
	for (int i = 1; i < N; i++) ans = lcm(ans, T[i]);
	cout << ans << endl;
}

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

typedef long long ll;
using namespace std;

ll H, N;
vector<ll> A(1000), B(1000);

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> H >> N;
    for (int i = 0; i < N; i++) {
        cin >> A[i] >> B[i];
    }
    ll dp[10001];
    fill(dp, dp + 10000, -1);
    dp[H] = 0;
    for (ll i = H; i >= 0; i--) {
        if (dp[i] == -1) {
            continue;
        }
        for (int k = 0; k < N; k++) {
            ll idx = max((ll)0, i - A[k]);
            if (dp[idx] < 0) {
                dp[idx] = dp[i] + B[k];
            } else {
                dp[idx] = min(dp[i] + B[k], dp[idx]);
            }
        }
    }
    cout << dp[0] << endl;
    return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
int main() {
    int n; cin >> n;
    vector<int> v(n);
    for (int i = 0; i < n; ++i) cin >> v[i];
    sort(v.begin(), v.end());
    int ans = 0;
    for (int i = 0; i < n; ++i) {
        ans += v[i];
        if (i == n-1) ans -= v[i]/2;
    }
    cout << ans << endl;
    return 0; 
}

Measured memory_bytes: 256
import numpy as np
N = int(input())
Nd2 = int(np.ceil(N / 2))
min_total = np.inf
for i in range(1, -~Nd2):
    n = i
    n2 = N - i
    total = 0
    dig = 10
    while n:
        a, b = divmod(n, dig)
        n = a
        total += b
    while n2:
        a, b = divmod(n2, dig)
        n2 = a
        total += b
    min_total = min(min_total, total)

print(min_total)


Measured memory_bytes: 12488
#ifdef DEBUG

#else

#    pragma GCC optimize("O3,no-stack-protector")
#    pragma GCC optimize("unroll-loops")

#    if __cplusplus < 201703L
#        pragma GCC target("avx")
#    else
#        pragma GCC target("avx2")
#    endif

#endif
// 実数の場合
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define dump(x) cout << x << endl
typedef int64_t Int;
typedef long double Ld;

using namespace std;
using Graph = vector<vector<Int>>;

const double pi = M_PI;
const Int MOD = 1000000007;

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

    int n;
    cin >> n;
    set<int> s;
    for (int i = 0; i < n; i++) {
        int a;
        cin >> a;
        if (s.count(a) == 0) {
            s.insert(a);
        } else {
            s.erase(a);
        }
    }

    cout << s.size() << endl;

    return 0;
}

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

map<int,int> m;
int a,L,mi,ma;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    while(cin >> a >> L,L){
        vector<int> num(L);
        m.clear();
        m[a]=1;
        for (int i=2;;++i){
            mi=ma=0;
            for (int j=0;j<L;++j){
                num[j]=a%10; a/=10;
            }
            sort(num.begin(),num.end());
            for (int j=0;j<L;++j)
                mi+=(int)pow(10,L-1-j)*num[j];
            reverse(num.begin(),num.end());
            for (int j=0;j<L;++j)
                ma+=(int)pow(10,L-1-j)*num[j];
            a=ma-mi;
            if (m[a]){
                cout << m[a]-1 << ' ' << a << ' ' << i-m[a] << '\n';
                break;
            } else m[a]=i;
        }
    }
}


Measured memory_bytes: 3328
#include <bits/stdc++.h>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define all(x) (x).begin(),(x).end()

using namespace std;
using ll = long long;
using P = pair<int, int>;

const int INF = 1001001001;
const vector<int> di = {-1,  0, 1, 0};
const vector<int> dj = { 0, -1, 0, 1};

void chmin(int &a, int b) { if (a > b) a = b; }

ll GCD(ll a, ll b) {
    if (b == 0) return a;
    else return GCD(b, a % b);
}
ll LCM(ll a, ll b) { return a * b / GCD(a, b); }

template<typename T>
int numofbits(T bits)
{
    bits = (bits & 0x55555555) + (bits >> 1 & 0x55555555);
    bits = (bits & 0x33333333) + (bits >> 2 & 0x33333333);
    bits = (bits & 0x0f0f0f0f) + (bits >> 4 & 0x0f0f0f0f);
    bits = (bits & 0x00ff00ff) + (bits >> 8 & 0x00ff00ff);
    return (bits & 0x0000ffff) + (bits >>16 & 0x0000ffff);
}

int g[15][15]; // 有向グラフ。i番目の人のj番目の人に対する証言を持つ。

int main(){
    int n;
    cin >> n;
    rep(i, n)rep(j, n) g[i][j] = -1; // まずは、全員何も証言していないと仮定する。
    rep(i, n) { // 証言を全て保存する。
        int m;
        cin >> m;
        rep(j, m) {
            int a, x;
            cin >> a >> x;
            --a; // 0-indexに変更。
            g[i][a] = x;
        }
    }

    int ans = 0;
    rep(i, 1<<n) { // 2^n
        vector<int> d(n, 0); // 0: 不親切な人 1: 正直者 として持つ。
        rep(j, n) if (i>>j&1) { // iのjbit目が立っているかを確認する。
            d[j] = 1; // iのjbit目が立っている場合は、1を代入する。
        }
        bool ok = true;
        rep(j, n) {
            if (d[j]) { // 正直者だった場合。
                rep(k, n) {
                    if (g[j][k] == -1) continue;
                    if (g[j][k] != d[k]) ok = false;
                }
            }
        }
        if (ok) ans = max(ans, numofbits(i));
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;
public class Main {

    public static void main(String[] args) {
        Scanner scan=new Scanner(System.in);
int N= scan.nextInt();
        int K= scan.nextInt();
        int A[]= new int[N];
int i=0;

        while (i<K){int D=scan.nextInt();
            int i1=0;

            while(i1<D){
                int i4=scan.nextInt()-1;

                A[i4]=A[i4]+1;
            i1=i1+1;


            }
            i=i+1;


        }
        int i2=0;
        int i3=0;

        while (i2<N){
            if(A[i2]==0){i3=i3+1;};
            i2=i2+1;

        }

System.out.println(i3);
    }
}


Measured memory_bytes: 46052
#include <bits/stdc++.h>
using intl = long long;
using ld = long double;
using namespace std;
#define rep(i, n) for(intl i = 0; i < (intl)(n); i++)
#define repd(i, n) for(intl i = (intl)(n); i >= 0; i--)
#define repi(i, a, b) for(intl i = (intl)(a); i < (intl)(b); i++)
#define repid(i, a, b) for(intl i = (intl)(a); i >= (intl)(b); i--)
#define max(a, b) ((a) > (b) ? (a) : (b))
#define min(a, b) ((a) < (b) ? (a) : (b))
#define all(x) (x).begin,(x).end()
#define m0(x) memset(x,0,sizeof(x))
#define m1(x) memset(x,1,sizeof(x))
#define fill(x,y) memset(x,y,sizeof(x))
#define alength(a) (sizeof(a) / sizeof(a[0]))
#define cin(i, a) rep(i, alength(a))cin >> a[i]
#define ccin(i, j, a) rep(i, alength(a))rep(j, alength(a[i]))cin >> a[i][j]
#define debug(x) cout << #x << ":" << x << endl
#define rdebug(i,x) rep(i, alength(x))cout << #x << "[" << i << "]:" << x[i] << endl
#define sqrt sqrtl
#define int intl
#define itn intl
#define double ld
#define pb push_back
#define mp make_pair
const intl INF = 1e9;
const intl MOD = 1e9+7;
const ld eps = 1.0e-14;//-9
void fp(bool flag){
    if(flag)cout << "Yes" << endl;
    else cout << "No" << endl;
}
void fp(bool flag, string s, string t){
    if(flag)cout << s << endl;
    else cout << t << endl;
}
intl kai(intl k){
    intl a = 1;
    for(int i = 2; i <= k; i++){
        a *= i;
    }
    return a;
}
intl gcd(intl a, intl b){
    if(!b)return a;
    return gcd(b, a % b);
}
intl digit10(intl a){
    if(!a)return 1;
    intl b = 0;
    while(a){
        a /= 10;
        b++;
    }
    return b;
}
signed main(){
    cout << fixed << setprecision(10);
    intl a,b,c,d;
    cin >> a >> b >> c;
    fp((b - a == c - b),"YES","NO");
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main(){
    double n, k;
    cin >> n >> k;
    double ans = 0;
    for(double i = 1; i < n + 1; i++){
        double i0 = i;
        double memo = 1 / n;
        while(i0 < k){
            memo /= 2;
            i0 *= 2;
        }
        ans += memo;
    }
    printf("%.15f\n", ans);
    return 0;
}

Measured memory_bytes: 256
N=int(input())
i=0
 
flag=0
beforeTxy=[0,0,0]
while i<N:
  afterTxy=list(map(int,input().split()))
  #print(afterTxy)
  #unk=afterTxy[0]-beforeTxy[0]-abs(afterTxy[1]-beforeTxy[1])-abs(afterTxy[2]-beforeTxy[2])
  #unk2=afterTxy[0]-beforeTxy[0]-abs(afterTxy[1]-beforeTxy[1])
  dt=afterTxy[0]-beforeTxy[0]
  dist=abs(afterTxy[1]-beforeTxy[1])+abs(afterTxy[2]-beforeTxy[2])
  #print(dt,dist)
  if dt < dist or dt%2!=dist%2:
    flag=1
  beforeTxy=afterTxy
  i=i+1
 
if flag==0:
  print("Yes")
else:
  print("No")

Measured memory_bytes: 3064
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <utility>
#include <numeric>
#include <algorithm>
#include <bitset>
#include <complex>
#include <fstream>
using namespace std;
typedef long long ll;
typedef vector<int> vint;
typedef pair<int,int> pint;
#define rep(i,n) for(int i = 0; i < n; i++)
#define MSG(a) cout << #a << " " << a << endl;
template<class T, class C> pair<T,C> mp(T a, C b){ return make_pair(a, b);}

const int MOD = 100000;
// x, y, r u, c
ll dp[100][100][2][2];

int main()
{
	memset(dp, 0, sizeof(dp));
	dp[0][0][0][0] = dp[0][0][1][0] = 1;
	for(int i = 0; i < 100; i++) for(int j = 0; j < 100; j++)
	{
		if(i+1 < 100)
		{
			dp[i+1][j][0][0] = (dp[i+1][j][0][0] + dp[i][j][0][0] + dp[i][j][0][1]) % MOD;
			dp[i+1][j][1][1] = (dp[i+1][j][1][1] + dp[i][j][0][0]) % MOD;
		}
		if(j+1 < 100)
		{
			dp[i][j+1][1][0] = (dp[i][j+1][1][0] + dp[i][j][1][0] + dp[i][j][1][1]) % MOD;
			dp[i][j+1][0][1] = (dp[i][j+1][0][1] + dp[i][j][1][0]) % MOD;
		}
	}

	int w, h;
	while(cin >> w >> h && w)
	{
		w--; h--;
		if(!w || !h) cout << 1 << endl;
		else cout << (dp[w-1][h][0][0] + dp[w-1][h][0][1] + dp[w][h-1][1][0] + dp[w][h-1][1][1]) % MOD << endl;
	}
}

Measured memory_bytes: 0
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
int main(void){
    // Your code here!
    int n;
    cin >> n;
    string a, b, c;
    int ans = 0;
    cin >> a >> b >> c;
    for (int i = 0; i < n; i++){
        if ((a[i] == b[i] && b[i] != c[i]) || (a[i] == c[i] && b[i] != c[i]) || (b[i] == c[i] && a[i] != c[i])){
            ans += 1;
        }else if(a[i] != b[i] && b[i] != c[i]){
            ans += 2;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <algorithm>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;

int main() {
  int n;
  cin >> n;
  
  vector<int> a(n),b(n);
  rep(i,n) {
  cin >> a.at(i);
  }
  
  rep(i,n) {
  cin >> b.at(i);
  }
  
  int sum =0;
  
  rep(i,n) {
  if(a.at(i) > b.at(i)) {
   sum += (a.at(i) - b.at(i));
  }
     }
     
     cout << sum;
}

Measured memory_bytes: 3628
#include<bits/stdc++.h>
#define ll long long int
#define ull unsigned long long 
#define ff first
#define ss second
#define fast ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define pb push_back 
#define mp make_pair
#define inf 2000000009
#define mod 1000000007
using namespace std;


int main()
{ 

  
ll r;
cin>>r;
cout<<r*r<<endl;
}


Measured memory_bytes: 256
def dp(n, a, b, c, ary, ans, cnt, lA, lB, lC)
  if cnt == n
    return [lA, lB, lC].min > 0 ? (a - lA).abs + (b - lB).abs + (c - lC).abs - 30 : INF
  else
    mp0 = dp(n, a, b, c, ary, ans, cnt + 1, lA, lB, lC)
    mp1 = dp(n, a, b, c, ary, ans, cnt + 1, lA + ary[cnt], lB, lC) + 10
    mp2 = dp(n, a, b, c, ary, ans, cnt + 1, lA, lB + ary[cnt], lC) + 10
    mp3 = dp(n, a, b, c, ary, ans, cnt + 1, lA, lB, lC + ary[cnt]) + 10
    return [mp0, mp1, mp2, mp3].min
  end
end
INF = 1E9
n, a, b, c = gets.split.map(&:to_i)
ary = []
ans = []

n.times do
  ary << gets.to_i
end

puts dp(n, a, b, c, ary, ans, 0, 0, 0, 0)


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

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = (1<<30) - 1;
const ll LINF = (1LL<<60) - 1;
const int mod = 1e9 + 7;

int main(){
    int n;
    cin >> n;
    ll res = 0;
    for (int i = 1; i <= n; ++i) {
        ll a = n / i;
        res += a * (a+1) / 2 * i;
    }
    cout << res << endl;
}

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

int main() {
  int h, w, k; cin >>h >> w >> k;
  vector<vector<char>> c(h,vector<char>(w));
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      cin >> c[i][j];
    }
  }

  int ret = 0;
  for (int ii = 0; ii < pow(2, h); ii++) {
    for (int jj = 0; jj < pow(2,w); jj++) {
      int tmp = 0;
      string bi = bitset<6>(ii).to_string();
      string bj = bitset<6>(jj).to_string();
      reverse(bi.begin(), bi.end());
      reverse(bj.begin(), bj.end());
      for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
          if (c[i][j]=='#' && bi[i] == '0' && bj[j] == '0') tmp++; 
        }
      }
      if (tmp == k) ret++;
    }
  }

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

Measured memory_bytes: 4076
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double lf;
typedef pair<ll,ll> ii;
typedef pair<ii,ll> iii;
#define REP(i,n) for(int i=0;i<n;i++)
#define REP1(i,n) for(ll i=1;i<=n;i++)
#define RST(i,n) memset(i,n,sizeof i)
#define SZ(a) (int)a.size()
#define ALL(a) a.begin(),a.end()
#define X first
#define Y second
#define mkp make_pair
#define pb push_back
#define eb emplace_back
#define pob pop_back
#ifdef cold66
#define debug(...) do{\
    fprintf(stderr,"%s - %d (%s) = ",__PRETTY_FUNCTION__,__LINE__,#__VA_ARGS__);\
    _do(__VA_ARGS__);\
}while(0)
template<typename T>void _do(T &&_x){cerr<<_x<<endl;}
template<typename T,typename ...S> void _do(T &&_x,S &&..._t){cerr<<_x<<", ";_do(_t...);}
template<typename _a,typename _b> ostream& operator << (ostream &_s,const pair<_a,_b> &_p){return _s<<"("<<_p.X<<","<<_p.Y<<")";}
template<typename It> ostream& _OUTC(ostream &_s,It _ita,It _itb)
{
    _s<<"{";
    for(It _it=_ita;_it!=_itb;_it++)
    {
        _s<<(_it==_ita?"":",")<<*_it;
    }
    _s<<"}";
    return _s;
}
template<typename _a> ostream &operator << (ostream &_s,vector<_a> &_c){return _OUTC(_s,ALL(_c));}
template<typename _a> ostream &operator << (ostream &_s,set<_a> &_c){return _OUTC(_s,ALL(_c));}
template<typename _a,typename _b> ostream &operator << (ostream &_s,map<_a,_b> &_c){return _OUTC(_s,ALL(_c));}
template<typename _t> void pary(_t _a,_t _b){_OUTC(cerr,_a,_b);cerr<<endl;}
#define IOS()
#else
#define debug(...)
#define pary(...)
#define endl '\n'
#define IOS() ios_base::sync_with_stdio(0);cin.tie(0);
#endif // cold66
//}
template<class T> inline bool chkmax(T &a, const T &b) { return b > a ? a = b, true : false; }
template<class T> inline bool chkmin(T &a, const T &b) { return b < a ? a = b, true : false; }
template<class T> using MaxHeap = priority_queue<T>;
template<class T> using MinHeap = priority_queue<T, vector<T>, greater<T>>;

const ll MAXn=1e5+5,MAXlg=__lg(MAXn)+2;
const ll MOD=1000000007;
const ll INF=0x3f3f3f3f;

int main(){
    IOS();
    ll m,k;
    cin >> m >> k;
    if (m == 1) {
        if (k == 0) cout << "0 0 1 1" << endl;
        else cout << -1 << endl;
    }
    else if (k >= (1<<m)) cout << -1 << endl;
    else {
        for (ll i=0;i<(1<<m);i++) {
            if (i != k) cout << i << " ";
        }
        cout << k << " ";
        for (ll i=(1<<m)-1;i>=0;i--) {
            if (i != k) cout << i << " ";
        }
        cout << k << endl;
    }
}


Measured memory_bytes: 1792
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>

using namespace std;

long long cnt;
int l;
int A[1000000];
int n;
vector<int> G;

// ??????????????????????????\?????????
void insertionSort(int A[],int n,int g) {
	for(int i=g;i<n;i++) {
		int v = A[i];
		int j = i - g;
		while(j>=0 && A[j] >v) {
			A[j+g] = A[j];
			j -= g;
			cnt++;
		}
		A[j+g] = v;
	}
}

void shellSort(int A[], int n) {
	// ??°???G = {1, 4, 13, 40, 121, 364, 1093, ...}?????????
	for(int h=1; ;) {
		if(h>n) break;
		G.push_back(h);
		h = 3*h + 1;
	}
	
	// ?????????G[i] = g?????????
	for(int i=G.size()-1; i>=0; i--) {
		insertionSort(A, n, G[i]);
	}
}

int main(void) {
	cin >> n;
	// ??????????????\???scanf??¢??°????????¨
	for(int i=0; i<n; i++) scanf("%d",&A[i]);
	cnt = 0;

	shellSort(A,n);
	
	cout << G.size() << endl;
	for(int i=G.size()-1; i>=0; i--) {
		printf("%d", G[i]);
		if(i) printf(" ");
	}
	printf("\n");
	printf("%d\n",cnt);
	for(int i=0;i<n;i++) printf("%d\n",A[i]);
	
	return 0;
}

Measured memory_bytes: 7108
# -*- coding utf-8 -*-

MOD = 10 ** 9 + 7

N, K = map(int, input().split())
S = 'R' + input() + 'L'

ans = 0
for i in range(1, N + 1):
    j = i + 1 if S[i] == 'R' else i - 1
    if S[i] == S[j]:
        ans += 1

ans = min(ans + 2 * K, N - 1)

print(ans)


Measured memory_bytes: 3316
#include<bits/stdc++.h>
using namespace std;
using ll = long long;

int main(){
  string s;
  cin>>s;
  if(s[s.size()-1]=='s'){
    cout<<s+"es"<<endl;
  }else{
    cout<<s+"s"<<endl;
  }
  return 0;
}

Measured memory_bytes: 3584
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] a = new int[n];
        int[] b = new int[n];
        int[] c = new int[n-1];
        for(int i=0; i<n; i++) {
            a[i] = sc.nextInt();
        }
        for(int i=0; i<n; i++) {
            b[i] = sc.nextInt();
        }
        for(int i=0; i<n-1; i++) {
            c[i] = sc.nextInt();
        }
        int total = 0;
        int d = 0;
        for(int i=0; i<n; i++) {
            d = a[i]-1;
            total += b[d];
            if(i != 0 && d == a[i-1]) {
                total += c[d-1];
            }
        }
        System.out.println(total);
    }
}

Measured memory_bytes: 35616
def main():
    import sys
    input = sys.stdin.readline

    MOD = 998244353

    n, k = map(int, input().split())

    blocks = []
    for _ in range(k):
        l, r = map(int, input().split())
        blocks.append((l, r))

    acc = [0] * (n + 1)
    acc[1] = 1
    dp = [0] * (n + 1)
    dp[1] = 1
    for i in range(2, n + 1):
        t = 0
        for l, r in blocks:
            if i - l >= 0:
                t += acc[i - l]
            if i - r - 1 >= 0:
                t -= acc[i - r - 1]
            t %= MOD
        dp[i] = t
        acc[i] = (acc[i - 1] + t) % MOD

    print(dp[-1] % MOD)


if __name__ == '__main__':
    main()

# def binary_search(*, ok, ng, func):
#     while abs(ok - ng) > 1:
#         mid = (ok + ng) // 2
#         if func(mid):
#             ok = mid
#         else:
#             ng = mid
#     return ok


Measured memory_bytes: 70892
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <utility>
#include <cmath>
#include <tuple>
#include <queue>
#include <bitset>
#include <set>
#include <map>
#include <list>

using ll = long long;
using ld = long double;
using namespace std;
const int INF = 1e9+100;
const ll INF64 = 7e18l;
const int mod = 1000000007;
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define ALL(a) (a).begin(), (a).end()
#define FIN ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);

struct union_find {
    vector<int> parent;
    vector<int> size;
    int components = 0;

    union_find(int n = 0) {
        if (n > 0)
            init(n);
    }

    void init(int n) {
        parent.resize(n + 1);
        size.assign(n + 1, 1);
        components = n;
        for (int i = 0; i <= n; ++i) 
            parent[i] = i;
    }

    int find(int v) {
        return v == parent[v] ? v : parent[v] = find(parent[v]);
    }

    bool unite(int u, int v) {
        u = find(u);
        v = find(v);
        if (u == v)
            return false;
        if (size[u] < size[v]) 
            swap(u, v);
        parent[v] = u;
        size[u] += size[v];
        --components;
        return true;
    }
};



int main(){
    FIN;

    ll n,m;
    cin >> n >> m;
    union_find UF(n);
    for(ll i=0;i<m;i++){
        ll a,b; cin >> a >> b;
        a--; b--;
        UF.unite(a,b);
    }

    map<ll,ll> mp;
    for(ll i=0;i<n;i++){
        ll par_i = UF.find(i);
        mp[par_i]++;
    }

    ll ans = 0;
    map<ll,ll>::iterator it;
    for(it=mp.begin();it!=mp.end();it++){
        ans = max(ans,it->second);
    }

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


Measured memory_bytes: 16940
#include <bits/stdc++.h>
#define REP(i, n) for(int i=0; i<(int)(n); i++)
#define REP1(i,a,b) for(int i=a; i<=(int)(b); i++)
#define ALL(x) begin(x),end(x)
#define RALL(x) rbegin(x),rend(x)
#define PB push_back
using namespace std;
typedef int64_t LL;
typedef vector<int> VI;
typedef pair<int,int> PII;

template<class T> inline bool chmax( T &a, const T &b ) { return b>a ? a=b,true : false; }
template<class T> inline bool chmin( T &a, const T &b ) { return b<a ? a=b,true : false; }
template<class T> using MaxHeap = priority_queue<T>;
template<class T> using MinHeap = priority_queue<T, vector<T>, greater<T>>;
template<class T, class F=less<T>> void sort_uniq( vector<T> &v, F f=F() ) {
    sort(begin(v),end(v),f);
    v.resize(unique(begin(v),end(v))-begin(v));
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    
    int n;
    cin >> n;
    priority_queue<PII> q;
    LL ans=0;
    VI a(n);
    REP(i,n) cin >> a[i];
    sort(RALL(a));
    q.emplace(a[0],a[0]);
    REP1(i,1,n-1) {
        auto p=q.top(); q.pop();
        // cout << p.first << ' ' << p.second << '\n';
        ans+=p.first;
        // int t=a[i];
        q.emplace(min(a[i],p.first),max(a[i],p.first));
        q.emplace(min(a[i],p.second),max(a[i],p.second));
    }
    cout << ans << '\n';
    return 0;
}



Measured memory_bytes: 6112
#include<iostream>
#include<algorithm>

using namespace std;

int main(){
//入力
int n;
cin >>n;
int a,b,c;
cin>>a>>b>>c;

//DPテーブル
 int dp[4][100010];//一旦全て0に
//n日目のabcそれぞれを行った時のの最大値を求める
dp[1][1]=a;//１日目にaを選んだ時の最大値
dp[2][1]=b;
dp[3][1]=c;
int x,y,z;
for(int i=2;i<=n;i++){
cin>>x>>y>>z;
dp[1][i]=x+max(dp[2][i-1],dp[3][i-1]);
dp[2][i]=y+max(dp[1][i-1],dp[3][i-1]);
dp[3][i]=z+max(dp[1][i-1],dp[2][i-1]);
}
long int answer=max(max(dp[1][n],dp[2][n]),dp[3][n]);
cout <<answer <<endl;




return 0;

}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  double p;
  cin >> N;
  if (N % 2 == 0){
    p = (double)1/(double)2;
    cout << fixed << setprecision(10);
    cout << p << endl;
  }
  else{
    p = (double)(N+1) / (double)(2*N);
    cout << fixed << setprecision(10);
    cout << p << endl;
  }
}

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


int main()
{
	int n, sch, min;
	int t = 0, h = 0;
	string tarou, hanako;

	cin >> n;
	for (int i = 0; i < n; i++){
		cin >> tarou >> hanako;
		if (tarou.size() <= hanako.size()){
			min = tarou.size();
		}
		else{
			min = hanako.size();
		}

		for (int i = 0; i < min; i++){
			if (tarou[i] != hanako[i]){
				for (sch = 'a'; sch <= 'z'; sch++){
					if (sch == tarou[i]){
						h = h + 3;
						break;
					}
					else if (sch == hanako[i]){
						t = t + 3;
						break;
					}
				}
				break;
			}
			else if (i == min - 1) {
				if (tarou.size() == hanako.size()){
					t = t + 1;
					h = h + 1;
				}
				else if (tarou.size() > hanako.size()){
					t = t + 3;
				}
				else{
					h = h + 3;
				}
			}
		}
	}
	cout << t << " " << h << endl;
	
	return 0;
}


Measured memory_bytes: 3148
#include <stdio.h>
int main(void){
    int i,sum;
    char num[1001];
    
    for(;;){
        scanf("%s",num);
        if(num[0]=='0') break;
        
        sum=0;
        for(i=0;num[i]!='\0';i++)
            sum+=num[i]-'0';
        printf("%d\n",sum);
    }
    return 0;
    
}


Measured memory_bytes: 2040
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
#include<stdio.h>
#include<queue>
#include <climits>
const int mod = 1e9 + 7;
const int INF = 1e9;
using namespace std;
typedef long long ll;

int main()
{
    char a,b;
    cin >> a >> b;
    if(a < b){
        cout << "<";
    }else if(a==b){
        cout << "=";
    }else{
        cout << ">";
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<n;i++)
using namespace std;
int main(){
  int x,a,b;
  cin>>x;
  cin>>a;
  cin>>b;
  cout<<(x-a)%b<<endl;
  return 0;
}

Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"os"
)

func main() {
	stdin := bufio.NewScanner(os.Stdin)
	stdin.Scan()
	input := stdin.Text()
	yes := true
	if input[2] != input[3] {
		yes = false
	}
	if input[4] != input[5] {
		yes = false
	}
	if yes {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}


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

using namespace std;

int main(void){
    
    int a, b, c, k;
    cin >> a >> b >> c >> k;
    
    int ans = 0;
    
    ans += min(a, k);
    k -= min(a,k);
    
    if (k <= 0){
        cout << ans << endl;
        return 0;
    }
    
    k -= min(b,k);
    if (k <= 0){
        cout << ans << endl;
        return 0;
    }
    
    ans = ans - min(c,k);
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3644
n = int(input())
if n < 105:
    print(0)
elif 105 <= n < 135:
    print(1)
elif 135 <= n < 165:
    print(2)
elif 165 <= n < 189:
    print(3)
elif 189 <= n < 195:
    print(4)
elif 195 <= n:
    print(5)


Measured memory_bytes: 2940
#include<bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int,int>pii;
const int mxN=3e3+10;
int n,t;
pii v[mxN];
int dp[mxN][mxN];
/*bool comp(pii a,pii b){
    if(a.second!=b.second)return a.second<b.second;
    return a.first<b.first;
}*/
int solve(int obj,int aguenta){
    if(obj<0)return 0;
    if(!aguenta)return dp[obj][aguenta]=0;
    if(dp[obj][aguenta]>=0)return dp[obj][aguenta];

    int naoc=solve(obj-1,aguenta);
    if(v[obj].first<=aguenta){
        int col=solve(obj-1,aguenta-v[obj].first)+v[obj].second;

        return dp[obj][aguenta]=max(naoc,col);
    }
    return dp[obj][aguenta]=naoc;
}
int32_t main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    memset(dp,-1,sizeof(dp));
    cin>>n>>t;
    t--;
    for(int i=0;i<n;i++){
        cin>>v[i].first>>v[i].second;
    }
    sort(v,v+n);
    solve(n-1,t);
    int ans=v[0].second;
    for(int i=1;i<n;i++){
        ans=max(ans,(long long)dp[i-1][t] + v[i].second);
    }   

    cout<<ans;
    

}

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

const long long mod = 1e9 + 7;

using ll = long long;
using pii  = pair<int, int>;
using pll = pair<ll, ll>;
#define ull unsigned long long
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define vc vector<char>
#define vs vector<string>
#define vpii vector<pii>
#define vpll vector<pll>

#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; i++)
#define rep1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; i++)
#define repr(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rep1r(i, n) for (int i = ((int)(n)); i >= 1; i--)

#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define RSORT(x) sort(rall(x));
#define pb push_back
#define mp make_pair

#define INF (1e9)
#define PI (acos(-1))
#define EPS (1e-7)

ull gcd(ull a, ull b) { return b ? gcd(b, a % b) : a; }
ull lcm(ull a, ull b) { return a / gcd(a, b) * b; }

int main(){
    int n, k;
    cin >> n >> k;
    int ans = 1;
    rep(i, n) {
        if (ans*2 <= ans+k) ans *= 2;
        else ans += k;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3592
#include <bits/stdc++.h>
#define ll long long int
#define fast ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)

using namespace std;
int a[100005];
int dp[100005];


int _gcd(int a,int b)
{
	return (b==0?a:_gcd(b,a%b));
}
bool cmp(int a,int b)
{
	return a>b;
}



int solve(int n)
{
	
	dp[0]=dp[1]=0;
	dp[2]=abs(a[1]-a[2]);
	for(int i=3;i<=n;++i)
	{
		dp[i]=min(abs(a[i]-a[i-1])+dp[i-1],abs(a[i]-a[i-2])+dp[i-2]);

	}
	
	return dp[n];


}

int main()
{
	fast;
	#ifndef ONLINE_JUDGE
	    freopen("input.txt", "r", stdin);
	    freopen("output.txt", "w", stdout);
	#endif
				ll n;
				cin>>n;
				for(int i=1;i<=n;++i)
				{
					cin>>a[i];
				}
				cout<<solve(n)<<endl;

	return 0;
}


Measured memory_bytes: 4360
#include <bits/stdc++.h>
using namespace std;
// Macros for easier access
#define ll long long
#define endl '\n'
#define F first
#define S second
#define umap unordered_map
#define uset unordered_set
#define test ll cases; cin>>cases; for(ll testCase = 1; testCase <= cases; testCase++)
#define fill(name, val) memset(name, val, sizeof(name));
#define mop(a, op, b)    (a%mod op b%mod)%mod
#define precise fixed<<setprecision(50)
#define vll vector<ll>
#define vvll vector<vll>
#define pll pair<ll, ll>
#define get(a, n)    for(ll it = 0; it < n; it++)    cin>>a[it];
#define boost ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define debug(x) cerr << #x << " : " << (x) << endl
// Constants
#define MX 100001
#define mod 1000000007LL
#define inf 1000000000000000000LL
void init(){
	boost;
	#ifndef ONLINE_JUDGE
		freopen("input.txt", "r", stdin);
		freopen("output.txt", "w", stdout);
	#endif
}

/*	Author: 🆉🅴🅽🅾🅻🆄🆂	*/

ll n, a[401];
ll dp[401][401];
ll calc(ll l, ll r){
	if(l >= r)	return 0;
	if(dp[l][r] != -1)	return dp[l][r];
	ll ans = inf, sum = a[r]; 
	for(ll i = l ; i < r; i++)
		ans = min(ans, calc(l, i) + calc(i+1, r)), sum += a[i];
	return dp[l][r] = ans + sum;
}
int main(){
	init();	fill(dp, -1);
	cin>>n;	get(a, n);
	cout<<calc(0, n-1);
}

Measured memory_bytes: 4976