akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define for(i,a,b) for(int i=a;i<=b;i++)
#define _inline __inline__ __attribute__((always_inline))
using namespace std;
_inline void read(int &x){
	int res=0,f=1;
	char c=getchar();
	if(c=='-') f=-1;
	while(c>'9'||c<'0') c=getchar();
	while(c>='0'&&c<='9'){
		res=res*10+c-'0';
		c=getchar();
	}
	x=res*f;
}
inline void print(int x){
    if(x<0) putchar('-'),x=-x;
    if(x>9) print(x/10);
    putchar(x%10+'0');
}
int main(){
    int n,y;
    read(n),read(y);
    for(i,0,n)
        for(j,0,n-i)
            if(i*10000+j*5000+(n-i-j)*1000==y)
                cout<<i<<' '<<j<<' '<<n-i-j<<"\n",exit(0);
    puts("-1 -1 -1");
    exit(0);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll         = long long;
constexpr ll MOD = 1000000007;
#define REP(i, n) for (ll i = 0; i < (n); i++)
#define REP2(i, x, n) for (ll i = x; i < (n); i++)
#define PR(x) cout << (x) << "\n"
#define PS(x) cout << (x) << " "
#define PRYES(x) PR((x) ? "Yes" : "No")
const long long INF = numeric_limits<long long>::max();
// SourceTest用出力マクロ
#ifdef SOURCE_TEST
#define SPR(x) PR(x)
#define SPS(x) PS(x)
#else
#define SPR(x) \
    {}
#define SPS(x) \
    {}
#endif
int main() {
    ll N;
    cin >> N;

    ll sum  = 1;
    ll sum2 = 1;  // 0or9以外
    ll sum3 = 1;  // 0でも9でもない
    REP(i, N) {
        sum *= 10;
        sum %= MOD;
        sum2 *= 9;
        sum2 %= MOD;
        sum3 *= 8;
        sum3 %= MOD;
    }

    ll ans = sum;
    ans += sum3;
    ans %= MOD;
    ans -= sum2 * 2;
    ans %= MOD;
    if (ans < 0) {
        ans += MOD;
    }
    PR(ans);

    return 0;
}

Measured memory_bytes: 3572
#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>;
vector<int> ans;
int main()
{
    int n,x,y;
    cin >> n >> x >> y;
    ans.resize(n);
    x--;y--;
    rep(i,n)rep(j,n){
        if (i >=j)continue; 
        int d = min({abs(i-j),abs(x-i)+1+abs(y-j),abs(x-j)+1+abs(y-i)});
        ans[d]++;
    }
    rep(i,n-1)cout << ans[i+1] << endl;



    return 0;
}

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

int main() {
  int D, G;
  int p[10], c[10];
  vector< vector <int> > cand;
  vector<int> nums;
  cin >> D >> G;
  for (int i = 0; i < D; i++) {
    cin >> p[i] >> c[i];
  }
  for (int bit = 0; bit < (1<<D); bit++) {
    vector<int> tmp;
    for (int i = 0; i < D; i++) {
      if((bit & 1<<i)) tmp.push_back(i);
    }
    cand.push_back(tmp);
  }
  vector<int> not_solve;
  cand.push_back(not_solve);
  for (vector<int> index_v : cand) {
    int sum_point = 0, sum_num = 0;
    for (int i: index_v) {
      sum_point += 100 * p[i] * (i+1) + c[i];
      sum_num += p[i];
    }
    vector<int> not_solve_all;
    for(int i = 0; i < D; i++) {
      if(binary_search(index_v.begin(), index_v.end(), i)) continue;
      not_solve_all.push_back(i);
    }
    reverse(not_solve_all.begin(), not_solve_all.end());
    for(int i: not_solve_all) {
      for(int j = 0; j < p[i]; j++) {
        if (sum_point >= G) break; 
        sum_point += 100 * (i+1);
        sum_num++;
      }
    }
    nums.push_back(sum_num);
  }
  sort(nums.begin(), nums.end());
  cout << nums[0];
  return 0;
}

Measured memory_bytes: 384
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
int main(void){
int a,b,k;
scanf("%d %d %d",&a,&b,&k);
if(b-a+1<=k*2){
    for(int i=a;i<=b;i++){
        printf("%d\n",i);
    }
}
else{
    for(int i=a;i<a+k;i++){
        printf("%d\n",i);
    }
    for(int i=b-k+1;i<=b;i++){
       printf("%d\n",i);
    }

}

}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  int A, B, C;
  cin >> A >> B >> C;
  if((C > A && C < B) || (C < A && C > B)){
    cout << "Yes" << endl;
  }
  else{
  	cout << "No" << endl;
  }
  return 0;
}

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

double eps = 1e-9;

string ccw(P a,P b,P c){
  P ab=b-a;
  P ac=c-a;
  P k=ac*conj(ab);
  if( k.imag() > eps ){
    return "COUNTER_CLOCKWISE";
  }
  if( k.imag() < -eps ){
    return "CLOCKWISE";
  }
  if( k.real() < -eps ){
    return "ONLINE_BACK";
  }  
  if( abs(ab)+eps < abs(ac) ){
    return "ONLINE_FRONT";
  }
  return "ON_SEGMENT";
}

int main(){
  
  double x0,y0,x1,y1,x2,y2;
  cin>>x0>>y0>>x1>>y1;
  P a(x0,y0);
  P b(x1,y1);
  int n;
  cin>>n;
  while(n--){
    cin>>x2>>y2;
    P c(x2,y2);
    cout<< ccw(a,b,c) <<endl;
  }
  return 0;
}

Measured memory_bytes: 1252
from collections import Counter
n = int(input())
A = list(map(int,input().split()))
oddA = A[0::2]
evenA = A[1::2]

oc = Counter(oddA)
omode = oc.most_common()
ec = Counter(evenA)
emode = ec.most_common()
if omode[0][0] != emode[0][0]:
    print(n-omode[0][1]-emode[0][1])
else:
    if len(omode) == 1 and len(emode) == 1:
        print(n//2)
    elif len(omode) == 1 and len(emode) != 1:
        print(n//2-emode[1][1])
    elif len(emode) == 1 and len(omode) != 1:
        print(n//2-omode[1][1])
    else:
        a = n-omode[0][1]-emode[1][1]
        b = n-omode[1][1]-omode[0][1]
        print(min(a, b))

Measured memory_bytes: 21952
function Main(input) {
  input=input.replace("\n","");
  var b=0;
  var i=0;
  var counter=0;
  while(input[i]){
    if(input[i]==='B'){
      b++;
    }else{
      counter+=b;
    }
    i++;
  }
  console.log(counter);
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 7372
/*input

*/


// assic value of ('0'-'9') is(48 - 57) and (a-z) is (97-122) and (A-Z) is(65-90) and 32 for space
// #pragma GCC target ("avx2")
// #pragma GCC optimization ("O3")
// #pragma GCC optimization ("unroll-loops")
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;

// order_of_key (k) : Number of items strictly smaller than k .
// find_by_order(k) : K-th element in a set (counting from zero).
using namespace __gnu_pbds;
template<class T> using oset=tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define ll          long long int
#define pb          push_back
#define pii         pair<ll ,ll >
#define vpii        vector< pii >
#define vi          vector<ll >
#define vs			vector< string >
#define vvi         vector< vector< ll > >
#define inf			(ll)1e18
#define all(it,a)   for(auto it=(a).begin();it!=(a).end();it++) 
#define F           first
#define S           second
#define sz(x)       (ll )x.size()
#define rep(i,a,b)	for(ll  i=a;i<b;i++)
#define repr(i,a,b) for(ll  i=a;i>b;i--)
#define lbnd        lower_bound
#define ubnd        upper_bound
#define mp          make_pair
#define whatis(x)   cout << #x << " is " << x << "\n";
#define graph(n)    adj(n,vector< ll > () )
//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

#define debug(x)     cout << #x << " " << x << endl;
#define debug_p(x)   cout << #x << " " << x.F << " " << x.S << endl;
#define debug_v(x)   {cout << #x << " "; for (auto ioi : x) cout << ioi << " "; cout << endl;}
#define debug_vp(x)  {cout << #x << " "; for (auto ioi : x) cout << '[' << ioi.F << " " << ioi.S << ']'; cout << endl;}
#define debug_v_v(x) {cout << #x << "/*\n"; for (auto ioi : x) { for (auto ioi2 : ioi) cout << ioi2 << " "; cout << '\n';} cout << "*/" << #x << endl;}

int solve()
{
	ll x;
	cin>>x;
	ll p=100;
	rep(i,1,50000)
	{
		p+=(p/100);
		if(p>=x)
		{
			cout<<i<<"\n";
			return 0;
		}
	}

	return 0;
}

int main()
{
	auto start = chrono::high_resolution_clock::now();

	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);

	ll test_cases=1;
	//cin>>test_cases;
	while(test_cases--)
		solve();

	auto stop = chrono::high_resolution_clock::now();
	auto duration = chrono::duration_cast<chrono::milliseconds>(stop-start);
	//cout<<"\nduration: "<<(double)duration.count()<<" milliseconds";
}

Measured memory_bytes: 3656
S = input()
T = input()

ans = len(T)

for offset in range(len(S) - len(T) + 1):
    ans_offset = 0
    for i in range(len(T)):
        if T[i] != S[offset + i]:
            ans_offset += 1

    ans = min(ans, ans_offset)

print(ans)


Measured memory_bytes: 9036
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using vb=vector<bool>;
using vvb=vector<vb>;
using pii = pair<int,int>;
using pli = pair<ll,int>;
using pll = pair<ll,ll>;
using vpii = vector<pii>;
using vpli = vector<pli>;
using vpll = vector<pll>;

#define rep(i, n) for(int i=0;i<(int)n;i++)
#define rep2(i, s, n) for(int i=(s);i<(int)n;i++)
int INF=1e9+7;

int main() {
  int A,B,M;
  cin >> A >> B >> M;
  vi a(A),b(B),x(M),y(M),c(M);
  int mina=INF,minb=INF;
  rep(i,A) {
    cin >> a[i];
    mina=min(mina,a[i]);
  }
  rep(i,B) {
    cin >> b[i];
    minb=min(minb,b[i]);
  }
  rep(i,M) {
    cin >> x[i] >> y[i] >> c[i];
    x[i]--;y[i]--;
  }
  
  int ans=mina+minb;
  rep(i,M)
    ans=min(ans,a[x[i]]+b[y[i]]-c[i]);
  
  cout << ans << endl;
}

Measured memory_bytes: 5076
/* Author : Aaryan Srivastava ^__^ */ 
#include <bits/stdc++.h>
#include <random>
#include <chrono>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp> 
#define pb push_back
#define mp make_pair
#define ff first
#define ss second   
#define rep(i,n) for(int (i) = 0 ; i < (n) ; i++)
#define repA(i,x,y) for(int i = (x) ; i <= (y) ; i++)
#define repD(i,x,y) for(int i = (x) ; i >= (y) ; i--)
#define all(c) (c).begin(),(c).end()
#define rall(c) (c).rbegin(),(c).end()
#define setval(a,val) memset(a,val,sizeof(a))
#define Randomize mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())
#define trav(x , a) for(auto &x : a)
#define sz(a) ((int)a.size())
typedef long long ll ; 

#define int ll

using namespace std;

const int N = 3e5 +5 ;
const int mod = 1e9 + 7 ;
const ll inf = 1e18 ;
const int SZ = 101 ;
const double eps = 1e-9 ;
using namespace __gnu_pbds;
using ordered_set =  tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ;

typedef pair<int, int> pii; 
typedef pair<int , pii> ipii ;
typedef pair<pii , int> piii ; 
typedef unsigned long long ull ;
typedef long double ld;

ll po(ll x,ll y,ll p = mod) {ll res=1;x%=p;while(y>0){if(y&1)res=(res*x)%p;y=y>>1;x=(x*x)%p;}return res;}

const int MX_PRIME=1e6+5;
int spf[MX_PRIME];
bitset<MX_PRIME> isprime;
void sieve(int n){
    isprime.set(); isprime[0]=isprime[1]=0; spf[2]=2;
    for(int i = 4 ; i < n ; i += 2) isprime[i]=0 , spf[i] = 2;
    for(int i = 3 ; i < n ; i++)if(isprime[i]){
        spf[i]=i;
        for(int j = i * 2; j < n ; j += i){
            if(isprime[j]) spf[j] = i;
            isprime[j] = false;
        }
    }
    /*
        vi primes;
        repA(i,2,n-1)if(isprime[i])primes.pb(i);
    */
}

int F(int n , int k){
    if(n % k == 0){
        while(n % k == 0) n/=k ;
        return(F(n , k));
    } 
    return ((n%k) == 1);
}


void solve()
{
    int n ;
    cin >> n ;
    if(n <= 3){
        cout << n-1;
        return;
    }
    // map<int , int> m;
     int ans = 0;
    // for(int i = 2 ; i <= n ; ++i){
    //     if(F(n , i)) cout << i << '\n';
    // }
    for(int i = 1 ; i*i <= n-1 ; ++i){
        if((n-1)%i) continue ;
        if(i > 1){
            ans++;
            // cout << i << ' ' ;
            // m[i]=1;
        }
        if((n-1)/i != i){
            ans++;
            // cout << (n-1)/i << ' ' ;
            // m[(n-1)/i]=1;
        }
    }
    for(int i = 1 ; i*i <= n ; ++i){
        if(n%i) continue ;
        if(i > 1) ans += F(n , i);
        // if(i > 1 && F(n,i)) cout << i << ' ' ;
        if(i != n/i){
            // if(F(n , n/i)) cout << n/i << ' ';
           ans += F(n , n/i);
        } 
    }

    cout << ans ;
}   

     
int32_t main(int32_t argc, char *argv[])
{
    ios::sync_with_stdio(0);    
    cin.tie(0); cout.tie(0);
    int TC = 1, t = 0;
    //cin >> TC ;
    while(t++ < TC)
    {
        //cout << "Case #" << t << ": " ;
        solve();
        cout << "\n" ;
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main() {
  int K, S;
  cin >> K >> S;
  
  long cnt = 0;
  for (int a = 0; a <= K; ++a) {
    for (int b = 0; b <= K; ++b) {
      if (a + b > S) break;
      if (S - (a + b) <= K) {
        ++cnt;
      }
    }
  }
  cout << cnt << endl;
  
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
        using namespace std;
        #define ll long long int
        #define pb push_back
        #define mk make_pair
        #define ft first
        #define sc second
        #define ppb pop_back
        #define sz size
        #define forn(i,a,n) for(i=a;i<n;i++)
        #define M 998244353 
        #define inf 2e18
        
        int main() {
 
   
        ios_base::sync_with_stdio(false);
        cin.tie(NULL);
        cout.tie(NULL);
        
        ll n,k;
        cin>>n>>k;
        ll ans = n%k;
        ans = min(ans,abs(ans-k));
        cout<<ans;

        return 0;
    }

Measured memory_bytes: 256
import Control.Applicative
import Control.Monad
import Data.List
import Data.Char
import Data.Maybe
strToInt s = (read :: String -> Int) s
strToInteger s = (read :: String -> Integer) s
strToDouble s = (read :: String -> Double) s

main :: IO ()
main = do
    -- 整数の入力
    n <- getLine
    -- スペース区切り整数の入力
    ls <-reverse . sort . map strToInt . words <$> getLine
    let alice =  sum $ map fst $ filter (odd . snd) (zip ls [1..])
        bob   =  sum $ map fst $ filter (even . snd) (zip ls [1..])
    -- 出力
    putStrLn $ show $ alice - bob


Measured memory_bytes: 1020
#include <bits/stdc++.h>
using namespace std;
int main(){
	int k,a,b;
	cin>>k>>a>>b;
	for(int i=1;k*i<=b;i++){
		if(k*i>=a&&k*i<=b){
			cout<<"OK";
			return 0;
		}
	}
	cout<<"NG";
}

Measured memory_bytes: 3636
#include<bits/stdc++.h>
#define ll long long int
using namespace std;
int main()
{

    ll i,j,k,c,d,a,b,e,f,p,q,n,t,m,r,u,x,y;
    vector<ll > vv,v,s;
    string st,et;
    map<ll,ll > pa,ea,ma;
    long double bb,cc,aa;
    cin>>a>>bb;
    aa = a*bb;
    c = aa/1;
    cout<<c<<endl;
}


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

typedef long long ll;

int main(){
    ll N;
    cin>>N;
    vector<ll> A(N);
    for(int i=0; i<N; i++) cin>>A[i];
    vector<ll> sum(N+1,0);
    for(int i=1; i<=N; i++){
        sum[i] = sum[i-1] + A[i-1];
    }   

    map<ll,ll> cnt;

    for(int i=0; i<=N; i++){
        cnt[sum[i]]++;
    }

    ll ans = 0;

    for(auto a : cnt){
        ll num = a.second;
        ll tmp = num*(num-1)/2;

        ans += tmp;
    }

    cout<<ans<<endl;

    return 0;
}

Measured memory_bytes: 15872
#include<stdio.h>
#include<string.h>
#include<iostream>
#include<algorithm>


char str[10];

int main()
{
	int i, len;
	scanf("%s", str);
	len = strlen(str);
	
	for(i = 0; i < len; i++){
		if(str[i] == 'A' && str[i + 1] == 'C') break;
	}
	if(i == len){
		printf("No\n");
	}
	else{
		printf("Yes\n");
	}
	
	return 0;


}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>

using namespace std;
using namespace __gnu_pbds;

template<typename T>
using indexed_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define all(v)			((v).begin()), ((v).end())
#define SZ(v)			((int)((v).size()))
#define clr(v, d)		memset(v, d, sizeof(v))
#define has(c,i) 		((c).find(i) != end(c))
#define has_str(s, c)	((s).find(c) != string::npos)
typedef long long ll;
int main() {
#ifdef LOCAL
    //freopen("input.txt", "r", stdin);
#endif
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    int n;
    cin >> n;
    string a, b;
    cin >> a >> b;
    int ans = 2 * n;
    int ptr = 0;
    for(int i = 0; i < n; ++i) {
        if(a[i] == b[ptr]) {
            ans--;
            ptr++;
        }
    }
    cout << ans << endl;
    return 0;
}

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

const int MAXN = 500 + 10;

vector<int> C[MAXN];
int vis[1 << 20], dp[1 << 20];
int cas;

int solve(const vector<int> &S) {
    int n = S.size(), mx = 0;
    if (n == 0) return 0;
    dp[0] = 0; vis[0] = ++ cas;
    for (int i = 0; i < n; ++ i) {
        int msk = 1 << (S[i]);
        for (int x = mx; x >= 0; -- x) {
            if (vis[x] != cas || (x & (msk - 1))) continue;
            int y = x + msk;
            if (vis[y] != cas) vis[y] = cas, dp[y] = dp[x] + 1, mx = max(mx, y);
            else dp[y] = max(dp[y], dp[x] + 1);
        }
    }
    int ret = 1;
    for (int x = 0; x <= mx; ++ x) {
        if (vis[x] == cas && __builtin_popcount(x) == 1) ret = max(ret, dp[x]);
    }
    return ret;
}

int main() {
    for (int N; scanf("%d", &N) == 1 && N; ) {
        for (int i = 0; i < MAXN; ++ i) C[i].clear();
        for (int i = 0; i < N; ++ i) {
            int x; scanf("%d", &x);
            int p = x;
            while (p % 2 == 0) p /= 2;
            C[p].push_back(__builtin_ctz(x / p));
        }
        int ret = 1;
        for (int i = 0; i < MAXN; ++ i) {
            ret = max(ret, solve(C[i]));
        }
        printf("%d\n", ret);
    }
    return 0;
}

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

int dp[100005], h[100005], n, k;

int main() {
	scanf("%d %d", &n, &k);
	for(int i = 1;i <= n; i++) scanf("%d", &h[i]);
	for(int i = 1;i <= n; i++) dp[i] = 1e9;
	dp[1] = 0;
	for(int i = 2;i <= n; i++) {
		for(int j = 1;j <= k; j++) {
			if(i-j < 1) break;
			dp[i] = min(dp[i], dp[i-j]+abs(h[i-j]-h[i]));
		}
//		printf("dp[%d] = %d\n", i, dp[i]);
	}
	printf("%d\n", dp[n]);
}

Measured memory_bytes: 4500
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <numeric>
#include <string>
#include <vector>
using namespace std;
int main()
{
  int n, a, b;
  cin >> n >> a >> b;
  int price = min(n * a, b);
  cout << price;
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

typedef struct { char suit, value; } Card;

void bubble(Card A[], int N) {
  int i,j;
  Card t;
  for(i = 0; i<N; i++) {
    for(j = N-1; j >= i; j--) {
      if(A[j].value < A[j-1].value) {
        t = A[j]; A[j] = A[j-1]; A[j-1] = t;
      }
    }
  }
}

void selection(Card A[], int N) {
  int i,j,minj;
  Card t;
  for(i=0;i<N;i++) {
    minj = i;
    for(j=i; j<N; j++) {
      if(A[j].value < A[minj].value) minj = j;
    }
    t = A[i]; A[i] = A[minj]; A[minj] = t;
  }
}

void print(Card A[], int N) {
  int i;
  for(i=0; i<N; i++) {
    if(i>0) printf(" ");
      printf("%c%d",A[i].suit,A[i].value);
  }
  printf("\n");
}

int isStable(Card C1[], Card C2[], int N) {
  int i;
  for(i=0; i<N; i++) {
    if(C1[i].suit != C2[i].suit) return 0;
  }
  return 1;
}

/* オリジナル関数を追加 */
void str2Card(Card *t,char str[]) {
    t->suit  = str[0];
    t->value = str[1] - '0';
}

int main(void) {
  Card C1[100], C2[100];
  int N,i;
  char str[3];

  scanf("%d",&N);
  for(i=0;i<N; i++) {
    scanf("%s",str);
    str2Card(&C1[i],str);
  }

  for(i=0; i<N; i++) C2[i] = C1[i];

  bubble(C1,N);
  selection(C2,N);

  print(C1,N);
  printf("Stable\n");
  print(C2,N);
  if(isStable(C1,C2,N)) {
    printf("Stable\n");
  } else {
    printf("Not stable\n");
  }

  return 0;
}



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

using namespace std;
int main(){
    int N;
    vector<long>arr;
    cin >> N;
    for(int i =0;i < N;i++){
        long a;
        cin >> a;
        arr.push_back(a);
    }
    long ans = 0;
    sort(arr.rbegin(),arr.rend());

    for(int i = 0;i < arr.size() - 1;i++){
        ans += arr[(i+1)/2];
    }
    cout << ans << endl;
}


Measured memory_bytes: 5356
/*
 * main.cpp
 *
 *  Created on: 2019/03/15
 *      Author: maleicacid
 */

#include <climits>
#include <cstdio>
#include <set>
#include <algorithm>

using namespace std;

long getSub(set<long>& s, long xpos)
{
	auto pos = s.emplace(xpos).first;
	long cost[2] = {LONG_MAX,LONG_MAX};
	if (pos != s.cbegin())
	{
		cost[0] = xpos - *prev(pos);
	}
	if (next(pos) != s.cend())
	{
		cost[1] = *next(pos) - xpos;
	}
	s.erase(pos);

	return (cost[0] < cost[1]) ? cost[0]: cost[1];
}
long getResult(set<long>& s, set<long>& t , long xpos)
{
	auto pos = s.emplace(xpos).first;
	long cost[4] = {LONG_MAX,LONG_MAX,LONG_MAX,LONG_MAX};
	if (pos != s.cbegin())
	{
		cost[0] = xpos - *prev(pos);
		cost[0] += getSub(t, *prev(pos));
	}
	if (next(pos) != s.cend())
	{
		cost[1] = *next(pos) - xpos;
		cost[1] += getSub(t, *next(pos));
	}
	s.erase(pos);
	cost[2] = (cost[0] < cost[1]) ? cost[0]: cost[1];


	cost[0] = cost[1] = LONG_MAX;


	pos = t.emplace(xpos).first;
	if (pos != t.cbegin())
	{
		cost[0] = xpos - *prev(pos);
		cost[0] += getSub(s, *prev(pos));
	}
	if (next(pos) != t.cend())
	{
		cost[1] = *next(pos) - xpos;
		cost[1] += getSub(s, *next(pos));
	}
	t.erase(pos);
	cost[3] = (cost[0] < cost[1]) ? cost[0]: cost[1];


	return (cost[2] < cost[3]) ? cost[2]: cost[3];
}

int main() {
	int a = 0;
	int b = 0;
	int q = 0;
	scanf("%d", &a);
	scanf("%d", &b);
	scanf("%d", &q);

	set<long> a_;
	set<long> b_;

	long tmp;
	for (int i = 0; i < a; i++) {
		scanf("%ld", &tmp);
		a_.emplace_hint(a_.end(), tmp);
	}
	for (int i = 0; i < b; i++) {
		scanf("%ld", &tmp);
		b_.emplace_hint(b_.end(), tmp);
	}


	for (int i = 0; i < q; i++) {
		long tmp;
		scanf("%ld", &tmp);
		printf("%ld\n" , getResult(a_,b_,tmp));
	}
}



Measured memory_bytes: 10624
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <cmath>
#include <deque>
#include <iterator>
#include <map>
#include <queue>
#include <string>
#include <tuple>
#include <utility>
#include <limits>
#include <iomanip>
using namespace std;

using ll=long long;
template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;
using vll = V<ll>;
using vvll = V<vll>;
#define rep(i, k, n) for (ll i=k; i<(ll)n; ++i)
#define REP(i, n) rep(i, 0, n)
template<class T> inline bool chmax(T& a, T b) {if (a<b) {a=b; return true;} return false;}
template<class T> inline bool chmin(T& a, T b) {if (a>b) {a=b; return true;} return false;}

const ll MOD = 1000000007;
const ll HIGHINF = (ll)1e18;

int main() {
  ll n, k; cin >> n >> k;
  vll d(10, 0);
  REP(i, k) {
    ll tmpd; cin >> tmpd;
    d[tmpd] = 1;
  }
  while (true) {
    ll tmpn = n;
    bool is_d = false;
    while (tmpn>0) {
      if (d[tmpn%10] == 1) {is_d = true; break;}
      else tmpn /= 10;
    }
    if (is_d) {n++; continue;}
    else break;
  }
  cout << n << endl;
  return 0;
}


Measured memory_bytes: 256
import math

def lcm(x, y):
    return (x * y) // math.gcd(x, y)

a,b,c,d=map(int,input().split())

c_div=(b//c)-((a-1)//c)
d_div=(b//d)-((a-1)//d)
cd_div=(b//lcm(c,d))-((a-1)//lcm(c,d))

ans=(b-a+1)-((c_div)+(d_div)-(cd_div))
print(ans)

Measured memory_bytes: 9124
import java.util.*;

public class Main{
    public static void main(String[] args){
        Scanner scan = new Scanner(System.in);
        int l = scan.nextInt();
        int r = scan.nextInt();
        int d = scan.nextInt();
        if(l % d == 0 || r % d == 0) System.out.println((r - l) / d + 1);
        else System.out.println((r - l) / d);
        scan.close();
    }
}


Measured memory_bytes: 26756
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define dbg puts("It's Just Begining.Wait For The End!!!!!\n")
#define CHECK(x) cout << (#x) << " is " << (x) <<"\n";
#define endl printf("\n")
typedef pair<ll,ll> pii;
#define pb push_back
#define ms(a,b) memset(a, b, sizeof(a))
#define in(x) scanf("%lld",&x)
#define out(x) printf("%lld",x)
#define X first
#define Y second
#define sps printf(" ")
#define dou(x) cout<<fixed<<setprecision(6)<<x
#define all(v) v.begin(),v.end()
#define dis(it,it1) distance(it,it1)+1
#define MAX 1000005
#define INF 9223372036854775807LL
#define MOD 1000000007
#define print(cs) printf("Case %lld: ",cs)
#define Yesno(ok) if(ok)puts("YES");else puts("NO")
#define yesno(ok) if(ok)puts("Yes");else puts("No")
ll lcm(ll a,ll b){return ((a*b)/__gcd(a,b));}
bool is_prime[MAX];
vector<ll>prime;
void sieve()
{
    ms(is_prime,true);
    ll i,j;
    for(i=2;i<MAX;i++)
    {
        if(is_prime[i])prime.pb(i);
        else continue;
        for(j=2;i*j<MAX;j++)is_prime[i*j]=true;
    }
}
ll sol(ll num)
{
    ll ans=0;
    for(ll i=1;i<=num;i++,ans++)
    {
        num-=i;
    }
    return ans;
}
int main()
{
     ll test=1,cas=1;
     while(test--)
     {
         sieve();
		 ll i,j,k,l,n,m,r;
		 in(n);
		 ll ans=0;
		 for(ll i=0;i<prime.size()&&prime[i]<=n;i++)
         {
             ll gof=0;
             while(n%prime[i]==0)gof++,n/=prime[i];
             ans+=sol(gof);
         }
         if(n!=1)ans++;
         out(ans);endl;
     }
}


Measured memory_bytes: 12428
#include <iostream>
#include <vector>
#include <map>
#include <string>
#include <algorithm>
#include <deque>

using namespace std;

int main()
{
    int X,Y,Z,K;
    cin >>X>>Y>>Z>>K;

    vector<int64_t> A,B,C;
    int64_t v;
    for (int i=0;i<X;++i) {
        cin >> v;
        A.push_back(v);
    }
    for (int i=0;i<Y;++i) {
        cin >> v;
        B.push_back(v);
    }
    for (int i=0;i<Z;++i) {
        cin >> v;
        C.push_back(v);
    }

    sort(A.begin(),A.end(),greater<int64_t>());
    sort(B.begin(),B.end(),greater<int64_t>());
    sort(C.begin(),C.end(),greater<int64_t>());
 
    int64_t kv = 0;
    vector<int64_t> sum;
    for (int a=0;a<A.size();++a) {
        for (int b=0;b<B.size();++b) {
            sum.reserve(sum.size() + C.size());
            auto first = sum.begin();
            auto mid = sum.end();
            for (int c=0;c<C.size();++c) {
                int64_t v = A[a] + B[b] + C[c];
                if (v < kv) break;
                sum.push_back(v);
            }
            inplace_merge(first, mid, sum.end(), greater<int64_t>());
            if (sum.size() >= K) {
                kv = sum[K-1];
            }
            sum.resize(K);
        }
    }

    sort(sum.begin(), sum.end(),greater<int64_t>());

    for (int i=0;i<K;++i) {
        cout << sum[i] << endl;
    }
    return 0;
}

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


int main() {
	int a[4];
	int b[4];

	while (cin >> a[0] >>a[1] >>a[2]>>a[3]) 
	{
		int hit = 0;
		int blow = 0;
		cin >> b[0]>>b[1]>>b[2]>>b[3] ;
		for (int i = 0; i < 4; i++) {
			for (int j = 0; j < 4; j++) {
				if (a[i] == b[j]) {
					if (i == j) {
						hit++;
					}
					else {
						blow++;
					}
				}
			}
		}
		cout << hit << " "<<blow << endl;
	}
	
	return 0;
}

Measured memory_bytes: 3072
/*
g++ -std=c++11 -o2 -Wall ABC119A.cpp -o .\out\ABC119A.out
.\out\ABC119A.out
*/

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

typedef long long ll;

int x[100005];

int main(){
//  freopen("./input/input.txt", "r", stdin);
  ios::sync_with_stdio(0);
  cin.tie(0);
  string s;
  cin >> s;
  int y = stoi(s.substr(0, 4));
  int m = stoi(s.substr(5, 2));
  int d = stoi(s.substr(8, 2));
  if (y <= 2018 || (y == 2019 && m <= 4)) {
    cout << "Heisei\n";
  } else {
    cout << "TBD\n";
  }
}


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

#define pii pair<int, int>
#define ft  first
#define sd second


const int N = 1e5+5;
vector<pii> vec[N];
long long dis[N];


void dfs(int u, int p){
    for(pii x: vec[u]){
        if(x.ft != p){
            dis[x.ft] = dis[u] + x.sd;
            dfs(x.ft, u);
        }
    }
}
int main(){
    int n;
    cin >> n;
    for(int i = 1 ; i< n; i++){
        int a, b, c;
        cin >> a >> b >> c;
        vec[a].push_back({b, c});
        vec[b].push_back({a, c});
    }
    int q, k;
    cin >> q >> k;
    dfs(k, 0);
    while(q--){
        int x, y;
        cin >> x >> y;
        cout << dis[x] + dis[y] << endl;
    }
}


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

int main() {
  string s;
  while (cin >> s, s != "0") {
    int ans = 0;
    for (int i = 0; i < s.size(); i++) {
      ans += s[i] - '0';
    }
    cout << ans << "\n";
  }
}


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

int main() {
    int w, h, x, y; cin >> w >> h >> x >> y;
    if (w == (Int)2* x && h == (Int)2 * y)
        printf("%.10f %d", (double)w*h/2.0, 1);
    else
        printf("%.10f %d", (double)w*h/2.0, 0);
}

Measured memory_bytes: 3768
from collections import defaultdict

n,x,y=map(int,input().split())

a=defaultdict(int)

for i in range(1,n):
    a[i]=0


for i in range(1,n):
    for j in range(i+1,n+1):
        d = min(j -i,abs(x -i) + abs(j-y) +1 )

        # if(d==8 ):print(i,j)

        a[d] +=1
b=sorted(a.items())

for i,j in b:
    print(j)


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

#define ll long long

ll get_total(string s);

ll divide(string s, int d, int t) {
  if (s.size() == 1 || !d) return stol(s);

  string ls = s.substr(0, d),
         rs = s.substr(d);

  ll li = stol(ls),
     ri = stol(rs);

  ll total = 0;
  for (int i = 0; i < rs.size(); i++) {
    total += li + divide(rs, i, t + li);
    if (i) total += t;
  }

  return total;
}

ll get_total(string s) {
  ll total = 0;
  for (int i = 0; i < s.size(); i++) {
    total += divide(s, i, 0); 
  }

  return total;
}

int main() {
  string s;
  cin >> s;
  
  cout << get_total(s) << endl;
}


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

int solve() {
		
}

int main() {
	double a,b,c,deg;
	cin >> a >> b >> deg;
	double PI = acos(-1);
	double radeg= deg * PI /180;
	c = sqrt(a*a+b*b-2*a*b*cos(radeg));
	printf("%.8lf\n",a*b*sin(radeg)/2 );
	printf("%.8lf\n", a+b+c);
	printf("%.8lf\n", b*sin(radeg));
				
}



Measured memory_bytes: 3448
using System;

public class Hello
{
    static bool[,] map;
    static int[] dx = new int[] { 0, 1, 1, 1, 0, -1, -1, -1 };
    static int[] dy = new int[] { 1, 1, 0, -1, -1, -1, 0, 1 };
    public static void Main()
    {
        while (true)
        {
            string[] line = Console.ReadLine().Trim().Split(' ');
            var w = int.Parse(line[0]);
            var h = int.Parse(line[1]);
            if (w == 0 & h == 0) break;
            map = new bool[h + 2, w + 2];
            for (int i = 0; i < h; i++)
            {
                line = Console.ReadLine().Trim().Split(' ');
                for (int j = 0; j < w; j++)
                    if (line[j] == "1") map[i + 1, j + 1] = true;
            }
            var count = 0;
            for (int i = 0; i < h; i++)
                for (int j = 0; j < w; j++)
                    if (map[i + 1, j + 1]) { goDfs(i + 1, j + 1); count++; }
            Console.WriteLine(count);
        }
    }
    public static void goDfs(int x, int y)
    {
        map[x, y] = false;
        for (int i = 0; i < 8; i++)
        {
            var nx = x + dx[i];
            var ny = y + dy[i];
            if (map[nx, ny]) goDfs(nx, ny);
        }
    }
}


Measured memory_bytes: 9284
#pragma GCC optimize ("O3")
#pragma GCC target ("avx2")
#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 K;
	cin >> K;
	string S;
	cin >> S;


	if (S.size() <= K) {
		co(S);
	}
	else {
		string T = S.substr(0, K);
		cout << T;
		cout << "..." << endl;
	}


	Would you please return 0;
}

Measured memory_bytes: 3652
#include <stdio.h>
#include <stdlib.h>

#include <iostream>
#include <iomanip>
#include <sstream>
#include <fstream>
#include <stdint.h>
#include <string.h>

//#define _USE_MATH_DEFINES
//#include <math.h>

#include <vector>
#include <list>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <stack>
#include <deque>
#include <string>

#include <algorithm>
#include <functional>
#include <bitset>
#include <functional>
#include <chrono>
#include <random>
#define sqr(x) (x) * (x)

typedef unsigned int u32;
typedef int i32;
typedef unsigned long long int u64;
typedef int long long i64;
typedef uint16_t u16;
typedef int16_t i16;
typedef uint8_t u8;
typedef int8_t i8;

using namespace std;
using namespace std::chrono;

const i64 mod = 1000000007ll;
const i64 smod = 998244353ll;
const i64 inf = 1000000007; // 10000000000000007ll;

const double eps = 1e-8;

const i64 MAXN = 300004;

i64 n, k;
i64 a[MAXN];

int main(int argc, char* argv[]) {
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cout.precision(15); cout.setf(ios::fixed);

    cin >> n >> k;
    if (n >= 10) {
        cout << k << endl;
    }
    else {
        cout << k + 100 * (10 - n) << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize ("O3")

#include <bits/stdc++.h>

using namespace std;

#ifdef LOCAL
#include <prettyprint.hpp>
#define debug(...)  cerr << "[" << #__VA_ARGS__ << "]: ", d_err(__VA_ARGS__);
#else
#define debug(...) 83;
#endif

void d_err() {
    cerr << endl;
}

template <typename H, typename... T>
void d_err(H h, T... t) {
    cerr << h << " ";
    d_err(t...);
}

template <typename T>
void print(T x) {
    cout << x << endl;
}

#define ALL(x) (x).begin(), (x).end()
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define REP(i, n) FOR(i, 0, n)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define bcnt __builtin_popcountll

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<ll,ll> Pll;
typedef pair<int,int> Pin;

ll INF = 1e16;
int inf = 1e9;
ll MOD = 1e9+7;

int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    
    string s;
    cin >> s;

    REP(i, s.size() - 1) {
        if (s[i] == s[i + 1]) {
            print("Bad");
            return 0;
        }
    }

    print("Good");
    
}


Measured memory_bytes: 3620
#include <bits/stdc++.h>
#define all(X) (X).begin(),(X).end()
#define rall(X) (X).rbegin(),(X).rend()
#define pub push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define ff first
#define ss second
#define P 1000000007
#define in(x, a, b) (a <= x && x < b)

using namespace std;
using ll = long long;
typedef pair<int, int> ii;
typedef vector<ii> vii; 
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<vii> vvii;
const ll inf = 1000000001, INF = (ll)1e18 + 1;

vi c;
vvi adj;

void dfs(int node, int color) {
	if(!c[node]) c[node] = color;
	else return;
	
	for(int i : adj[node]) {
		dfs(i, color);
	}
} 

void solve() {
	int n, m;
	cin >> n >> m;
	
	adj.resize(n);
	for(int i = 0; i < m; i++) {
		int a, b;
		cin >> a >> b;
		a--; b--;
		
		adj[a].pub(b);
		adj[b].pub(a);
	}
	
	int cl = 1;
	c.resize(n, 0);
	for(int i = 0; i < n; i++) {
		if(!c[i]) dfs(i, cl++);
	}
	
	map<int, int> ccs;
	for(int i = 0; i < n; i++) {
		ccs[c[i]]++;
	}
	
	int ans = 0;
	for(ii i : ccs) {
		ans = max(ans, i.ss);
	}
	
	cout << ans << endl;
}

int main() {
	ios_base::sync_with_stdio(false);
	 solve();
    return 0;
}

Measured memory_bytes: 21136
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int A,B,C,X,Y;
  cin >> A>> B>> C>> X>> Y;
  long long mini=100000000;
  if(A+B<=2*C){
    mini = A*X +B*Y;
  }
  else{
    if(X>=Y){
      mini = min( 2*C*Y +A*(X-Y) , 2*C*X );
    }
    else if(Y>X){
      mini =min(2*C*X +B*(Y-X) , 2*C*Y );
    }
  }
  cout << mini<<endl;
  
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cassert>
#include <chrono>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <vector>

using namespace std;

// BEGIN NO SAD
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()
#define f first
#define s second
typedef vector<int> vi;
// END NO SAD

typedef long long ll;
typedef pair<int, int> pii;
typedef vector<vector<ll>> matrix;

void usacoio(string s) {
  freopen((s+".in").c_str(), "r", stdin);
  freopen((s+".out").c_str(), "w", stdout);
}

void solve() {
  int x;
  cin >> x;
  cout << 360 / __gcd(360, x) << "\n";
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL); cout.tie(NULL);
  solve();
}


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

using namespace std;

const int N = 1e5 + 5;

char use[N];
string moves;

int main() {
    int n, k, r, p, s, ans = 0;
    cin >> n >> k >> r >> s >> p >> moves;
    for (int i = 0; i < moves.size(); i++) {
        if (i - k < 0) {
            if (moves[i] == 'r') ans += p, use[i] = 'p';
            if (moves[i] == 's') ans += r, use[i] = 'r';
            if (moves[i] == 'p') ans += s, use[i] = 's';
        } else if (moves[i] == 'r') {
            if (use[i - k] != 'p') {
                ans += p, use[i] = 'p';
            } else if (i + k < moves.size() && moves[i + k] != 's') {
                use[i] = 'r';
            } else {
                use[i] = 's';
            }
        }  else if (moves[i] == 'p') {
            if (use[i - k] != 's') {
                ans += s, use[i] = 's';
            } else if (i + k < moves.size() && moves[i + k] != 'r') {
                use[i] = 'p';
            } else {
                use[i] = 'r';
            }
        } else {
            if (use[i - k] != 'r') {
                ans += r, use[i] = 'r';
            } else if (i + k < moves.size() && moves[i + k] != 'p') {
                use[i] = 's';
            } else {
                use[i] = 'p';
            }
        }
    }
    cout << ans << '\n';
    return 0;
}


Measured memory_bytes: 512
#include <iostream>
using namespace std ;
int main(){
    int m , f , r , x , y ;
    while ( 1 ){
        cin >> m >> f >> r ;
        if ( m == -1 && f == -1 && r == -1 ) break ;
        else if ( m == -1 || f == -1 )
            cout << "F" << endl ;
        else if ( m + f >= 80 )
            cout << "A" << endl ;
        else if ( m + f >= 65 && m + f < 80 )
            cout << "B" << endl ;
        else if ( m + f >= 50 && m + f < 65 )
            cout << "C" << endl ;
        else if ( m + f >= 30 && m + f < 50 && r >= 50 )
            cout << "C" << endl ;
        else if ( m + f >= 30 && m + f < 50 )
            cout << "D" << endl ;
        else if ( m + f < 30 )
            cout << "F" << endl ;
        }
 
 
}

Measured memory_bytes: 3100
fn read_stdin() -> String {
    use std::io::Read;
    let mut input = String::new();
    std::io::stdin().read_to_string(&mut input).unwrap();
    input
}

fn scan<'a, I: Iterator<Item = &'a str>, T: std::str::FromStr>(tokens: &mut I) -> T {
    tokens.next().unwrap().parse().ok().unwrap()
}

fn main() {
    let input = read_stdin();
    let tokens = &mut input.split_whitespace();
    let n: usize = scan(tokens);
    let mut x = 1;
    let mut ans = 0;
    while x <= n {
        if 10 * x <= n {
            ans += 9 * x;
        } else {
            ans += n - x + 1;
        }
        x *= 100;
    }
    println!("{}", ans);
}


Measured memory_bytes: 4352
from bisect import bisect_left, bisect_right

N = int(input())
A = sorted(list(map(int, input().split())))
B = sorted(list(map(int, input().split())))
C = sorted(list(map(int, input().split())))

ans = 0
# bisect_ リストの挿入できるインデックスを出力
for b in B:
  # 各bに対して使えるaの個数
  left = bisect_left(A, b)
  # 各bに対して使えないcの個数 同じ値がある場合
  right = bisect_right(C, b)
  # left * 各bに対して使えるcの個数
  ans += left*(N-right)
  
print(ans)  

Measured memory_bytes: 23244
#include <bits/stdc++.h>
using namespace std;
const int N=1e3+5;
char S[N][N];
int f[N][N],dr[4][2]={{1,0},{-1,0},{0,1},{0,-1}},que[N*N],s,t,h,w,sx,sy,tx,ty;
signed main(void){
	cin>>h>>w>>sx>>sy>>tx>>ty;
	for(int i=0;i<h;i++) {
		cin>>S[i];
		for(int j=0;j<w;j++)
			f[i][j]=S[i][j]=='#';
	}
	f[--sx][--sy]=1;
	tx--,ty--;
	que[t++]=sx*N+sy;
	while(s<t){
		int s1=s;
		while(s<t){
			int x=que[s++],y=x%N;
			x/=N;
			for(int i=0;i<4;i++){
				int x1=x+dr[i][0],y1=y+dr[i][1];
				if((unsigned)x1>=h||(unsigned)y1>=w||f[x1][y1])
					continue;
				f[x1][y1]=f[x][y];
				que[t++]=x1*N+y1;
			}
		}
		while(s1<s){
			int x=que[s1++],y=x%N;
			x/=N;
			for (int i=-2;i<3;i++) {
				for (int j=-2;j<3;j++) {
					int x1=x+i,y1=y+j;
					if((unsigned)x1>=h||(unsigned)y1>=w||f[x1][y1])
						continue;
					f[x1][y1]=f[x][y]+1;
					que[t++]=x1*N+y1;
				}
			}
		}
	}
	cout<<(f[tx][ty]?f[tx][ty]-1:-1);
	return 0;
}

Measured memory_bytes: 10264
#include <bits/stdc++.h>
//#define int long long

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

#define FOR(i, a, n) for(int i = (int)(a); i < (int)(n); ++i)
#define REP(i, n) FOR(i, 0, n)

#define pb(a) push_back(a)
#define all(x) (x).begin(),(x).end()

const int INF = (int)1e9;
const LL INFL = (LL)1e18;
const int MOD = (int)1e9 + 7;

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

    LL n, x;
    cin >> n >> x;

    LL a = n-x, b = x;
    if(a < b) swap(a, b);

    if(a == b){
        cout << 3LL * x << endl;
    }else{
        LL ans = a + b;
        while(a % b != 0){
            ans += 2LL * (a / b) * b;
            a = a % b;
            swap(a, b);
        }
        ans += (a / b * 2LL - 1) * b;
        cout << ans << endl;
    }

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N;
  cin >> N;
  if(N%10==3)cout << "bon" << endl;
  else if(N%10==0||N%10==1||N%10==6||N%10==8)cout << "pon" << endl;
  else{
    cout << "hon" << endl;
  }
}

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

int main(){
	int n;
	int A, B;
	int res_A, res_B;
	
	while(true){
		scanf("%d", &n);
		
		if(n == 0) return 0;
		
		res_A = 0; res_B = 0;
		for(int i = 0; i < n; i++){
			scanf("%d%d", &A, &B);
			if(A > B) res_A += A + B;
			else if(A < B) res_B += A + B;
			else{
				res_A += A; res_B += B;
			}
		}
		
		printf("%d %d\n", res_A, res_B);
	}
}

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

int main(){
	int data;
	std::cin >> data;  //dataset
	std::cin.ignore();
	
	std::string mis = "Hoshino";
	std::string correct = "Hoshina";
	
	for(int i=0; i<data; ++i){
		std::string  sentence;
		std::getline(std::cin, sentence);
		
		std::string::size_type index = sentence.find(mis);
		
		if(index == std::string::npos){  // Hoshino??
			std::cout << sentence << std::endl; 
		}else{
			while(index != std::string::npos){  // Hoshino???
				sentence.replace(index, mis.length(), correct);
				index = sentence.find(mis, index + correct.length());
			}
			std::cout << sentence << std::endl;
		}
	}
	
	return 0;
}

Measured memory_bytes: 1220
#include <bits/stdc++.h>
using namespace std;
 
int main() 
{
    int a,b,k;
    cin>>a>>b>>k;
    int n = 0;
    vector<int>v(100);
    for(int i = 1; i<=min(a,b); i++){
        if(a % i == 0 && b % i == 0){
            v.at(n) = i;
            n++;
        }
    }
    sort(v.begin(),v.end());
    reverse(v.begin(),v.end());
    cout<<v.at(k - 1)<<endl;
}


Measured memory_bytes: 3640
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repl(i, n) for (ll i = 0; i < (ll)(n); i++)
#define repr(i, n) for(int i = n; i >= 0; i--)
#define reprl(i, n) for(ll i = n; i >= 0; i--)
#define fori(i, m, n) for(int i = m; i < (int)n; i++)
#define forl(i, m, n) for(ll i = m; i < (ll)n; i++)
#define all(v) v.begin(), v.end()
ll gcd(ll a,ll b) {
  return b? gcd(b,a%b): a;  
}
ll lcm(ll a,ll b) {
  return a*b/gcd(a,b);
}
bool isLowerCase(char c){
  return (c>='a'&&c<='z');
}
const string btos(bool ans){
  return (ans?"Yes":"No");
}
int main() {
  string a,b;cin>>a>>b;
  string c=a+b;
  int d=stoi(c);
  int i=1;
  bool ans=false;
  while(i<d){
    if(i*i==d){
      ans=true;
      break;
    }
    i++;
  }
  cout << btos(ans) << endl;
  return 0;
}

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

using namespace std;

const int N = 100005    ;

int n, m;

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    cin >> n >> m;
    priority_queue<int> q;
    for (int i = 1; i <= n; i++) {
        int k; cin >> k;
        q.push(k);
    }
    for (int i = 1; i <= m; i++) {
        int now = q.top();
        q.pop();
        now /= 2;
        q.push(now);
    }
    long long ans = 0;
    while (q.size()) {
        int p = q.top();
        q.pop();
        ans += p;
    }
    cout << ans;
    return 0;
}


Measured memory_bytes: 892
//ツ三ツ角ツ形ツづ個外ツ静堋円ツづ個陳?心ツづ? ツ三ツ角ツ形ツづ個静シツ閉ェツづ個青つ陳シツ禿アツ督卍閉ェツ静シツつェツ古ーツづュツづゥツ湘ェツ渉環づ可づ按づゥ.
//ツつアツづ個づヲツつ、ツづ按甘エツ可スツ学ツ的ツづ按姪「ツ妥ィツづーツ嘉ーツつュツづ?つォツづ? ツ暗按可コツづ個ペ-ツジツづ個δ可イツブツδ可δ環づーツ参ツ考ツづ可つキツづゥツづ?嘉ーツつォツづ「ツつキツつ「.
// - http://www.deqnotes.net/acmicpc/2d_geometry/
// - http://www.prefield.com/algorithm/index.html

#include <iostream>
#include <complex>
#include <vector>
#include <cstdio>
using namespace std;

typedef complex<double> P;

P p[3]; //ツ三ツ角ツ形ツづ個三ツ点

//ツ外ツ静?
double cross(const P &a, const P &b){
  return imag(conj(a) * b);
}

//ツ静シツ閉ェ/ツ陳シツ静シツ用ツづ個型
struct L : public vector<P> {
  L(const P &a, const P &b){
    push_back(a);
    push_back(b);
  }
};

//ツ陳シツ静シ2ツづつづ個古ーツ点ツづーツ仰?づ淞づゥ
P crosspoint(const L &l, const L &m){
  double A = cross(l[1] - l[0], m[1] - m[0]);
  double B = cross(l[1] - l[0], l[1] - m[0]);
  return m[0] + B / A * (m[1] - m[0]);
}

//ツ静シツ閉ェabツづ個青つ陳シツ禿アツ督卍閉ェツ静シツづーツ仰?づ淞づゥ
L getBisection(const P &a, const P &b){
  P s = (a + b) / 2.0; //ツ陳?点
  P t = (b - a) * P(0, 1); //ツ静シツ閉ェabツづ個法ツ静シツベツクツトツδ仰づーツ偲ヲツ督セ

  //ツ静シツ閉ェabツづ個青つ陳シツ禿アツ督卍閉ェツ静シツづ? ツ点sツつゥツづァs+tツづ鳴伸ツづ堕づゥツ陳シツ静シ
  return L(s, s + t);
}

void solve(){
  //ツ三ツ角ツ形ツづ個静シツ閉ェツづ個青つ陳シツ禿アツ督卍閉ェツ静シツづー2ツづつ偲ヲツ督セツつキツづゥ
  L l1 = getBisection(p[0], p[1]);
  L l2 = getBisection(p[1], p[2]);

  //ツ外ツ静堋円ツづ個陳?心ツづ? l1ツづ?2ツつェツ古ーツ債キツつオツつスツ点
  P o = crosspoint(l1, l2);

  //ツ三ツ角ツ形ツづ個任ツ暗督づ個陳クツ点ツつゥツづァ, ツ陳?心ツづ慊づ?づ個仰猟猟」ツづーツ偲ヲツづェツづ? ツ板シツ径ツづ可づ按づゥ
  printf("%.3f %.3f %.3f\n", o.real(), o.imag(), abs(o - p[0]));
}

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

  for(int i = 0; i < n; i++){
    for(int j = 0; j < 3; j++){
      cin >> p[j].real() >> p[j].imag();
    }

    solve();
  }
}

Measured memory_bytes: 1268
from collections import Counter, defaultdict
import sys
sys.setrecursionlimit(10 ** 5 + 10)
# input = sys.stdin.readline
from math import factorial
import heapq, bisect
import math
import itertools





def main():
    num = int(input())
    data = list(map(int, input().split()))

    ans, kari = 0, 0
    pre = 0
    for i in range(num):
        if data[i] <= pre:
            kari += 1
            pre = data[i]
        else:
            ans = max(ans, kari)
            kari = 1
            pre = data[i]
    ans = max(ans, kari)
    print(ans - 1)





if __name__ == '__main__':
    main()



Measured memory_bytes: 63856
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second
#define dbg(x) cout<<#x" = "<<((x))<<endl
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

string solve()
{
    string s;
    cin >>s;
    int S = s.size();
    rep(i,S-1)
    {
        if(s[i]=='A' && s[i+1]=='C') return "Yes";
    }
    return "No";
}

int main()
{
    cout << solve() << endl;
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<iostream>
#include<math.h>
using namespace std;
int main(void){
    
    int N,a[100],i;
    
    scanf("%d",&N);
    
    for(i = 0;i < N;i++){
        scanf("%d",&a[i]);
    }
    for(i = 0;i < N;i++){
        printf("%d",a[N-1-i]);
        if(i != N-1)
            printf(" ");
    }
    printf("\n");
    
    return 0;
}



Measured memory_bytes: 3196
n = int(input())
abc = [list(map(int, input().split())) for _ in range(n)]
dp = [[0,0,0] for _ in range(n)]

dp[0] = abc[0]
ls = [[1,2], [0,2], [0,1]]

if n == 1:
    ans = min(dp[0])
else:
    for i in range(1,n):
        for j in range(3):
            dp[i][j] = max([ dp[i-1][k] for k in ls[j] ]) + abc[i][j]

print(max(dp[-1]))

Measured memory_bytes: 76248