akhauriyash/Code-Regression huggingface dataset:
#include <array>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <string>
#include <utility>
#include <vector>

#define rep(i, n) for (int i = 0; i < (int)(n); i++)

using namespace std;

int main() {
  int N, M;
  cin >> N >> M;

  if (N > M) {
    rep(i, N) { cout << M; }
    cout << endl;
    return 0;
  }
  rep(i, M) { cout << N; }
  cout << endl;

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
using namespace std;
using namespace __gnu_pbds;

#define TRACE

#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
	cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
	const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif

#define lsc(x)      scanf("%lld",&x)
#define sc(x)       scanf("%d",&x)
#define lpr(x)      printf("%lld ",(long long)x)
#define pr(x)       printf("%d ",x)
#define n_l         printf("\n")
#define VI          vector<int>
#define VII         vector<long long int>
#define m_p         make_pair
#define pb          push_back
#define fi           first
#define se           second
#define mset(x,y)   memset(x,y,sizeof(x))
#define sz(v)       (int)v.size()
#define all(v)      v.begin(), v.end()
#define fr(i, a, n) for(int i=a;i<=n;i++)
#define FIO ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
mt19937 rng32(chrono::steady_clock::now().time_since_epoch().count());
const int N=(int)1e6+5;
const int mod = 1000000007;
typedef long long ll;
// order_of_key (val): returns the no. of values strictly less than val
// find_by_order (k): returns the kth largest element iterator.(0-based)
// vector<int>::iterator itr=lower_bound(v.begin(),v.end(),x);
// s.substr(pos[0-indexed], len(default=till end))
typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;

ll fmod(ll x){if (x<mod) return x;return x%mod;}
ll mul(ll a, ll b, ll c){
	ll ret=0;while(b){if (b%2) ret=(ret+a)%c;a=(a*2)%c;b>>=1;}
    return ret;
}
int modpow(ll a, ll b){
    ll ret=1;while(b){if (b%2) ret=(ret*a)%mod;a=(a*a)%mod;b>>=1;}
    return (int)ret;
}
inline int inv(int x){ return modpow(x, mod-2);}
int isprime[N];
void calc_prime(){
	isprime[1]=1;for(ll i=2;i<N;i++) if (!isprime[i]) for(ll j=i*i;j<N;j+=i) isprime[j]=1;
}
int main(){
    VI v(5);
    int ans = 0;
    fr(i, 1,5){
        sc(v[i-1]);
        if (v[i-1] == 0) ans =i;
    }
    pr(ans);n_l;
    return 0;
}



Measured memory_bytes: 3768
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <string>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <stdio.h>
using namespace std;
#define int long long
int MOD = 1000000007;
set<int> st;
signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N;
	cin >> N;
	st.insert(N);
	int res;
	for (int i = 0;; i++) {
		if (N % 2 == 0) {
			N = N / 2;
		}
		else {
			N = 3 * N + 1;
		}
		if (st.count(N) == 1) {
			res = i + 2;
			break;
		}
		st.insert(N);
	}
	cout << res << endl;
}

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

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 INF2 (1e18)
#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; }

using mint = modint998244353;

const mint inv9 = mint(1) / mint(9);

struct S {
    mint x, w;
    S(mint x=0, mint w=1) : x(x), w(w) {}
};

S op(S a, S b) { return S(a.x*b.w+b.x, a.w*b.w); }

S e() { return S(0, 1); }

S mapping(int f, S s) {
    if (f == 0) return s;
    else return S((s.w-1)*inv9*f, s.w);
}

int composition(int g, int f) {
    if (g == 0) return f;
    else return g;
}

int id() { return 0; }

int main(){
    int n, q;
    cin >> n >> q;
    lazy_segtree<S, op, e, int, mapping, composition, id> seg(n);
    rep(i, n) seg.set(i, S(1, 10));
    rep(i, q) {
        int l, r, d;
        cin >> l >> r >> d;
        --l;
        seg.apply(l, r, d);
        cout << seg.all_prod().x.val() << endl;
    }
    return 0;
}


Measured memory_bytes: 9896
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
const int N=20;
int n;
char s[N];
int main()
{
	scanf("%s",s+1);
	n=strlen(s+1);
	int cnt=0;
	for(int i=1;i<=n;i++)
		if(s[i]=='x') cnt++;
	if(15-cnt>=8) printf("YES");
	else printf("NO");
	return 0;
}

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

int main() {
  string s; cin >> s;
  if (s == "ABC") cout << "ARC" << endl;
  else cout << "ABC" << endl;
  
  return 0;
}

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

#define ll long long
#define N 100005
#define mod 1000000007
#define boost ios_base::sync_with_stdio(false);cin.tie(0)
#define prec(n) fixed<<setprecision(n)

#define pii pair<int,int> 
#define pll pair<ll,ll> 
#define fi first
#define se second
#define pb push_back

vector<pii> adj[15];


int djikstra(int num)
{
    int dis[15],b,i;
    fill(dis,dis+15,2*mod);
    
    dis[1]=0;
    
    priority_queue< pair<int,int> , vector< pair<int,int> > , greater<pair<int,int> > > pq;
    
    pq.push({0,1});
    
    while(!pq.empty())
    {
        b=pq.top().second;
        pq.pop();
        
        for(i=0;i<adj[b].size();i++)
        {
            if(dis[ adj[b][i].first ] >  dis[b]+ adj[b][i].second )
            {
                dis[adj[b][i].first ]=dis[b]+adj[b][i].second ;
                pq.push(make_pair(dis[ adj[b][i].first ],adj[b][i].first));
            }
        }
    }
    return dis[num];
}

int main() 
{
    boost;
    
    int i,j,h,w,num ;
    
    
    cin>>h>>w;
    
    for(i=0;i<10;i++)
    {
        for(j=0;j<10;j++)
        {
            cin>>num;
            adj[j].push_back({i,num});
        }
    }    
    
    int dp[10];
    
    for(i=0;i<10;i++)
    dp[i]=djikstra(i);
    
//    cout<<dp[8]<<endl;
    
    int ans=0;
    for(i=0;i<h;i++)
    {
        for(j=0;j<w;j++)
        {
            cin>>num;
            if(num!=-1)
            {
                ans+=dp[num];
            }
        }
    }
    
    cout<<ans<<endl;
    
       
    return 0;
}

Measured memory_bytes: 256
n = gets.to_i
l = gets.split.map(&:to_i).sort

ans = 0
(n - 2).times do |i|
    k = i + 2
    (i + 1).upto(n - 2) do |j|
        k += 1 if k == j
        k += 1 while k < n && l[k] < l[i] + l[j]
        ans += k - 1 - j
    end
end

puts ans

Measured memory_bytes: 3836
#include<bits/stdc++.h>
#define all(x) (x).begin(),(x).end()
#define ll long long
#define rep(i,n) for(int i = 0; i < int(n); i++)
#define vi vector<int>
using namespace std;
const int INF = 1001001001;
const int MOD = 1e9+7;
const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, 1, 0, -1};
template<class T> inline bool chmax(T &a, const T &b){ if(a<b){ a=b; return 1; } return 0; }
template<class T> inline bool chmin(T &a, const T &b){ if(b<a){ a=b; return 1; } return 0; }

int main(){
  cin.tie(0), ios::sync_with_stdio(false);
  int n; cin >> n;
  vector<vi> to(n);
  rep(i,n-1){
    int a,b; cin >> a >> b;
    --a; --b;
    to[a].push_back(b);
    to[b].push_back(a);
  }
  vi c(n);
  int ans = 0;
  rep(i,n){
    cin >> c[i];
    ans += c[i];
  }
  sort(all(c),greater<int>());
  ans -= c[0];
  cout << ans << endl;
  vi node(n);
  queue<int> q;
  q.push(0);
  node[0] = c[0];
  int i = 1;
  while(!q.empty()){
    int now = q.front(); q.pop();
    for(int next : to[now]){
      if(0 < node[next]) continue;
      node[next] = c[i++];
      q.push(next);
    }
  }
  rep(i,n) cout << node[i] << " ";
  return 0;
}


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

int main(){
	int N,M,C;
  	cin >> N>>M>>C;
  	int A[20][20],B[20];
  	for(int i=0;i<M;i++){
    	cin >> B[i];
    }
  	for(int i=0; i<N; i++){
    	for(int j=0; j<M; j++){
        	cin >>A[i][j];
        }
    }
  
  int ans=0;
  int tmp=0;
  
  for(int i=0; i<N; i++){
  	for(int j=0; j<M; j++){
    	tmp += A[i][j]*B[j];
    }
    if(tmp+C>0)ans++;
      tmp=0;
  }
  cout << ans <<endl;
  
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int N;
long long A[101], B[101];
int op[101], bb, cc, dd;
bool vis[101];
 
long long bf(int n) {
  vis[n] = 1;
  if(n == bb) {
    long long ans = 0;
    for(int i = bb; i < cc; i++) {
      if(op[i] == 0) {
//        vis[i] = 1, vis[i + i] = 1;
        ans += max(0LL, A[i] + (op[i + i] == 0 ? B[i + i] : 0));
      }
    }
    for(int i = cc; i < dd; i++) {
      if(op[i] == 0) {
//        vis[i] = 1;
        ans += B[i];
      }
    }
    for(int i = dd + 1; i <= N; i+=2) {
      if(op[i] == 0) {
//        vis[i] = 1;
        ans += B[i];
      }
    }
    return ans;
  }
  if(op[n]) {
    return bf(n + 1);
  }else {
    long long now = A[n] + bf(n + 1);
    for(int i = n + n; i <= N; i += n) {
      op[i]++;
    }
    now = max(now, bf(n + 1));
    for(int i = n + n; i <= N; i += n) {
      op[i]--;
    }
    return now;
  }
}
 
long long bf2(int n) {
  if(n + n > N) {
    long long ans = 0;
    for(int i = n; i <= N; i++) {
      if(op[i] == 0) ans += B[i];
    }
    return ans;
  }
  if(op[n]) {
    return bf2(n + 1);
  }else {
    long long now = A[n] + bf2(n + 1);
    for(int i = n + n; i <= N; i += n) {
      op[i]++;
    }
    now = max(now, bf2(n + 1));
    for(int i = n + n; i <= N; i += n) {
      op[i]--;
    }
    return now;
  }
}
 
 
int main() {
  scanf("%d", &N);
  bb = N / 3 + 1;
  cc = N / 2 + 1;
  dd = bb + bb;
  for(int i = 1; i <= N; i++) {
    scanf("%lld", &A[i]);
    if(A[i] > 0) B[i] = A[i];
  }
  if(N < 10) printf("%lld\n", max(0LL, A[1] + bf2(2)));
  else printf("%lld\n", max(0LL, A[1] + bf(2)));
//  for(int i = 1; i <= N; i++) if(!vis[i])cout << i << "\n";
  cin >> N;
}

Measured memory_bytes: 3828
#include<bits/stdc++.h>
using namespace std;
#define lli long long int
#define pii pair<int,int>
#define pll pair<lli, lli>
#define vi  vector<int>
#define vii vector<pair<int,int>>
#define vll vector<lli>
#define pb  push_back
#define mpr  make_pair
#define ss  second
#define ff first
#define INF 1000000001
#define inf1 1000000000000000001
#define pie 3.14159265358979323846264338327950L
#define all(x) x.begin(),x.end()
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define testcase() int tc;cin>>tc;while(tc--)
#define clean(x) memset(x,0,sizeof(x))
const lli maxn = 300000+5;
const lli mod= 1000000007;
vector<lli> catlan(int n) {
    vector<lli> dp(n + 1, 0);
    dp[0] = 1;
    dp[1] = 1;
    for (int i = 2; i <= n; i ++) {
        for (int j = 0; j < i; ++ j) {
            dp[i] += dp[j] * dp[i - j - 1];
        }
    }
    return dp;
}
lli digit(lli n){int res=(int)log10(n)+1;return res;}
lli lcm(lli a,lli b){lli ans=(a*b)/(__gcd(a,b));return ans;}
lli b_ex(lli n,lli a){lli res=1;while(n){if(n%2==1)res*=a;n>>=1;a=a*a;}return res;}
lli ncr(lli n,lli k){lli ans=1;if(k>n-k)k=n-k;for(lli i=1;i<=k;i++){ans*=(n-i+1),ans=ans/i;}return ans;}
lli power(lli a , lli n){lli ans = 1;while(n){if(n % 2)ans = (ans * a) % mod;n /= 2;a = (a * a) % mod;}return ans;}
lli set_bits(lli n)
{
    int c=0;
    if(n==0)return 0;
    while(n)
    {
        if((n&1)==1)
        {
           cout<<c<<" ";
        }
        c++;
        n=n>>1;
    }
    return c;
}

lli inf = 5e17;
///=================== ALWAYS CHECK 1 or 0 base case=================================================================================///
///------------------ALWAYS lli-----TEMP TSF99--------------------------------------------------------------------------------------//


void solve()
{
    lli a;cin>>a;
    lli res=a+a*a+a*a*a;
    cout<<res<<endl;
}
int main()
{
    solve();
}


Measured memory_bytes: 3688
#include <iostream>

using namespace std;

int main(){
	string s;
	int ans;
	cin >> s;
	if(s[0] == '1'){
		ans++;
	}if(s[1] == '1'){
		ans++;
	}if(s[2] == '1'){
		ans++;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
defmodule Main do
  def main do
    n = IO.gets("") |> String.trim() |> String.to_integer()
    1..n
    |> Enum.reduce(%{"AC" => 0, "WA" => 0, "TLE" => 0, "RE" => 0}, fn _, acc ->
      s = IO.gets("") |> String.trim()
      Map.update(acc, s, 1, & &1 + 1)
    end)
    |> print()
  end

  defp print(%{"AC" => ac, "WA" => wa, "TLE" => tle, "RE" => re}) do
    IO.puts "AC x #{ac}"
    IO.puts "WA x #{wa}"
    IO.puts "TLE x #{tle}"
    IO.puts "RE x #{re}"
  end
end

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

ll n;

int main()
{
    cin >> n;
    ll a;
    ll ans[n];
    for (ll i = 0; i < n; i++)
        ans[i] = 0;
    for (ll i = 1; i < n; i++)
    {
        cin >> a;
        ans[a - 1]++;
    }
    for (ll i = 0; i < n; i++)
        cout << ans[i] << endl;
    return 0;
}


Measured memory_bytes: 5068
#include <cstdio>
#include <algorithm>
#define fail return puts("-1"), 0

const int N = 1e3 + 5;

int n, sz;
long long x[N], y[N], bin[33];

void solve(long long x, long long y) {
	for (int i = sz - 1; i >= 0; i--) {
		if (std::labs(x) > std::labs(y)) {
			putchar(x < 0 ? 'L' : 'R');
			x < 0 ? x += bin[i] : x -= bin[i];
		} else {
			putchar(y < 0 ? 'D' : 'U');
			y < 0 ? y += bin[i] : y -= bin[i];
		}
	}
	puts("");
}
int main() {
	scanf("%d", &n);
	bool flg1 = false, flg2 = false;
	for (int i = 1; i <= n; i++) {
		scanf("%lld %lld", &x[i], &y[i]);
		((x[i] + y[i]) & 1 ? flg1 : flg2) = true;
	}
	if (flg1 && flg2) fail;
	if (flg1) {
		printf("%d\n", sz = 33);
		for (int i = sz - 1; i >= 0; i--) {
			printf("%lld%c", bin[i] = 1LL << i, " \n"[i == 0]);
		}
	} else {
		printf("%d\n", sz = 34);
		for (int i = sz - 1; i >= 1; i--) {
			printf("%lld ", bin[i] = 1LL << (i - 1));
		}
		printf("%lld\n", bin[0] = 1);
	}
	for (int i = 1; i <= n; i++) solve(x[i], y[i]);
	return 0;
}

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

// マクロ群
#define REP(i,n) for(int i=0;i<n;++i)
#define REP2(i,a,b) for (int i=(a);i<(b);++i)
#define rep(n) REP(i,n)
#define SF(f,v) scanf(f,v)
#define SF_N(v) SF("%d",&v)
#define SF_S(v) SF("%s",v)
#define PF(f,v) printf(f,v)
#define PFS_N(v) PF("%d ",v)
#define PFS_S(v) PF("%s ",v)
#define PFL_N(v) PF("%d\n",v)
#define PFL_S(v) PF("%s\n",v)


using namespace std;

const int ARRMAX = 1024;

void Slove()
{
	int N;
	SF_N(N);
	vector<int> A(N);
	rep(N) SF_N(A[i]);

	int oddCnt = 0;

	rep(N) if (bitset<1>(A[i])[0] != 0) oddCnt++;

	PFL_S(bitset<1>(oddCnt)[0] ? "NO" : "YES");
}

int main()
{
	Slove();
	return 0;
}


Measured memory_bytes: 640
#include <iostream>

using namespace std;

typedef long long ll;

const int MAX = 1e5+10;

ll S[MAX];
ll T[MAX];

int main() {

  string s, t;
  cin >> s >> t;
  for (int i = 0; i < s.length(); i++) S[i+1] = s[i]-'A'+1+S[i];
  for (int i = 0; i < t.length(); i++) T[i+1]= t[i]-'A'+1+T[i];

  int q, a, b, c, d;
  cin >> q;
  for (int i = 0; i < q; i++) {
    cin >> a >> b >> c >> d;
    a--; c--;
    if (((S[b]-S[a]) - (T[d]-T[c]))%3 == 0) cout << "YES" << endl;
    else cout << "NO" << endl;
  }

}

Measured memory_bytes: 2432
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <set>

typedef long long ll;

using namespace std;

int func(int n) {
  if (n % 2 == 0) return n / 2;
  else return 3 * n + 1;
}

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

  set<int> a;

  a.insert(s);
  int num = s;

  for (int i = 0; i < 1000000; i++) {
    num = func(num);
    if (a.find(num) != a.end()) {
      cout << i + 2 << endl;
      break;
    }
    else a.insert(num);
  }

}


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

int main(){
  string S;
  cin >> S;
  if ((S.at(5) == '0') 
      && (S.at(6) == '1' || S.at(6) == '2' || S.at(6) == '3' || S.at(6) == '4')) 
    cout << "Heisei" << endl;
  else cout << "TBD" << endl;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(){
  int n, x, t, total;
  scanf("%d %d %d", &n, &x, &t);

  if(n%x == 0){
    total = (n / x)*t;
  }else{
    total = (n / x + 1)*t;
  }
  printf("%d\n", total);
  return 0;
}


Measured memory_bytes: 1732
using System;

class Program
{
  static void Main(string[] args)
  {
    int A1,A2,A3,sum;
    string[] s = Console.ReadLine().Split(' ');
    A1 = int.Parse(s[0]);
    A2 = int.Parse(s[1]);
    A3 = int.Parse(s[2]);
    sum = A1 + A2 + A3;
    if(sum <= 21)Console.WriteLine("win");
    else Console.WriteLine("bust");
  }
}

Measured memory_bytes: 11092
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N;
  string ans;
  int value = N;
  int sum = 0;
  while(value!=0){
    sum += value%10;
    value /= 10;
  }
  if(N%sum == 0){
    ans = "Yes";
  }else{
    ans = "No";
  }
  cout << ans << endl;
}

Measured memory_bytes: 3656
#include <iostream>
#include <cstdio>
#include <set>
#include <list>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <string>
#include <sstream>
#include <algorithm>
#include <cstring>
#include <cstdlib>
#include <cctype>
#include <cmath>
#include <fstream>
#include <iomanip>
//#include <unordered_map>
using namespace std;
#define dbg(x) cerr << #x " = " << x << endl;
typedef pair<int, int> P;
typedef long long ll;
#define FIN freopen("in.txt", "r", stdin);
const int MAXN = 1e5+5;
struct node
{
    ll num, cnt;
};
node a[MAXN * 2];
int tot = 0;
bool cmp(node a, node b)
{
    return a.num > b.num;
}
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n, m;
    cin >> n >> m;
    for(int i = 0; i < n; i++)
    {
        int num;
        cin >> num;
        a[tot].num = num;
        a[tot++].cnt = 1;
    }
    for(int i = 0; i < m; i++)
    {
        int b, c;
        cin >> b >>c;
        a[tot].num = c;
        a[tot++].cnt = b;
    }
    sort(a, a+ tot, cmp);
    ll ans = 0;
    int i = 0;
    int count = n;
    while(count > a[i].cnt)
    {
        ans += a[i].cnt * a[i].num;
        count -= a[i].cnt;
        i++;
    }
    ans += count * a[i].num;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 6280
N = int(input())
numofAB = 0
numofLastA = 0
numofStartB = 0
numofLastAandStartB = 0
for _ in range(N):
    IN = input()
    numofAB += IN.count('AB')
    if IN[0] == 'B':
        numofStartB += 1
    if IN[-1] == 'A':
        numofLastA += 1
    if IN[0] == 'B' and IN[-1] == 'A':
        numofLastAandStartB += 1

numofLastA -= numofLastAandStartB
numofStartB -= numofLastAandStartB

if numofLastA > numofStartB:
    numofAB += numofStartB + numofLastAandStartB
else:
    numofAB += numofLastA + numofLastAandStartB
if numofLastA == 0 and numofStartB == 0 and numofLastAandStartB>0 :
    numofAB -= 1

print("{}".format(numofAB))


Measured memory_bytes: 3064
#include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include <cmath>
#include <limits>
#include<set>
#include <iomanip>
#include <queue>
#include <string>
#pragma GCC optimize("Ofast")
using namespace std;
const long long INF=20000000000;
//setprecision(2) <<

const int MOD = 1000000007;

long long max(long long a,long long b){
	if(a<b)return b;
	else return a;	
}
long long min(long long a,long long b){
	if(a>b)return b;
	else return a;	
}
long long gcd(long long a,long long b){
	if(a<b)swap(a,b);
	if(a%b==0)return b;
	else return gcd(a%b,b);
}

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

long long com(long long n,long long k){
	
}

int main(){
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	string s;
	string t;
	int a,b,c;
	cin>>a>>c>>b;
	if((a<=b && b<=c) || (c<=b && b<=a)){
		cout<<"Yes"<<endl;
		}else cout<<"No"<<endl;
}

	


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

int main(int, char**) {
        int N;
        std::cin >> N;
        std::set<std::string> keihin;
        for (int i=0; i<N; i++) {
                std::string s;
                std::cin >> s;
                keihin.insert(s);
        }
        std::cout << keihin.size() << std::endl;
        return 0;
}


Measured memory_bytes: 19204
import java.util.Scanner;
import java.util.regex.*;

class Main {

    public static void main(String[] args){

	Scanner stdin = new Scanner(System.in).useDelimiter("[ \t,\n]");
	int n = stdin.nextInt();
	int line = stdin.nextInt();

	int[] nums = new int[n + 1];
	for(int i = 1; i <= n; i++){
	    nums[i] = i;
	}
	stdin.nextLine();
	for(int i = 0; i < line; i++){
	    int sw1 = stdin.nextInt();
	    int sw2 = stdin.nextInt();
	    int temp = nums[sw1];
	    nums[sw1] = nums[sw2];
	    nums[sw2] = temp;
	}
	for(int i = 1; i <= n; i++){
	    System.out.println(nums[i]);
	}
    }
}
	
	

Measured memory_bytes: 12000
N,K = map(int,input().split())
S = input()
Data = []

now = 1
cnt = 0
for s in S:
    if str(now) == s:
        cnt += 1
    else:
        Data.append(cnt)
        cnt = 1
        now = 1 - now
if cnt > 0:
    Data.append(cnt)
if now == 0:
    Data.append(0)

DataSum = [0]
for i in range(len(Data)):
    DataSum.append(Data[i]+DataSum[i])

#print(Data)
#print(DataSum)

len1 = min(2*K+1,len(Data))
ans = 0
for i in range(0,len(Data)-len1+1,2):
    left = i
    right =i+len1
    sum1 = 0
    #for j in range(left,right):
    #    sum1 += Data[j]
    sum1 = DataSum[right]-DataSum[left]
    ans = max(ans,sum1)

print(ans)

Measured memory_bytes: 7932
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define YES cout<<"YES"<<endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl
#define ANS cout << ans << endl
#define all(a) a.begin(),a.end()
#define SORT(a) sort(all(a))
#define REVERSE(a) reverse(all(a))
#define int long long
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define VIin(a) for(int i=0; i<a.size(); i++) cin >> a[i]
#define OUT(a) cout << a << endl
typedef vector<int> VI;
typedef vector<VI> VVI;
const int MOD=1e9+7;
const long long INF = 1LL << 60;
/*最大公約数*/int gcd(int x, int y) { return y ? gcd(y,x%y) : x;}
/*最小公倍数*/int lcm(int a, int b) { int g = gcd(a, b); return a / g * b; }
/*素数判定*/int isPrime(int n){if(n<2){return 0;}for(int i=2; i*i<=n; i++){if(n%i==0){return 0;}}return 1;}
/*約数列挙*/vector<int> getDivisor(int n){vector<int> v; for(int i=1; i*i<=n; i++){if(n%i==0){v.push_back(i);if(i!=n/i){v.push_back(n/i);}}}sort(v.begin(),v.end()); return v;}
//----------------------------------------------
signed main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    
    int x; cin >> x;
    if(x == 7 || x == 5 || x == 3) YES;
    else NO;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <unistd.h>
#define ll long long
#define inf 1000000007
#define inf16 0x3f3f3f3f
#define INF 1000000000000000007LL
#define VI vector<int>
#define VPII vector<pair<int, int> >
#define VLL vector<ll>
#define PII pair<int, int>
#define st first
#define nd second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define endl '\n'
#define ALL(c) (c).begin(), (c).end()
using namespace std;

#define int ll

int h, w, n, k, ans;

int pot[50*50];

int query(int y1, int y2, int x1, int x2)
{
	cout << "? " << y1 << " " << x1 << " " << y2 << " " << x2 << endl;
	int ans;
	cin >> ans;
	return ans;
}

void solve(int y1, int y2, int x1, int x2, int cnt, int split)
{
	if(cnt==0)
		return;

	if(cnt==(y2-y1+1)*(x2-x1+1))
	{
		for(int i = y1; i <= y2; ++i)
		{
			for(int j = x1; j <= x2; ++j)
			{
				ans += pot[i*w+j];
				ans %= k;
			}
		}

		return;
	}

	if(y1!=y2)//split)
	{
		int m = (y1+y2)/2;
		int h = query(y1, m, x1, x2);
		solve(y1, m, x1, x2, h, split^1);
		solve(m+1, y2, x1, x2, cnt-h, split^1);
	}
	else
	{
		int m = (x1+x2)/2;
		int h = query(y1, y2, x1, m);
		solve(y1, y2, x1, m, h, split^1);
		solve(y1, y2, m+1, x2, cnt-h, split^1);
	}
}

int32_t main()
{
	cin >> h >> w >> n >> k;

	pot[0] = 1;

	for(int i = 1; i < 50*50; ++i)
	{
		pot[i] = pot[i-1]*2%k;
	}

	for(int j = 0; j < w; j += 8)
	{
		for(int i = 0; i < h; i += 8)
		{
			solve(i, min(i+7, h-1), j, min(j+7, w-1), query(i, min(i+7, h-1), j, min(j+7, w-1)), 1);
		}
	}

	/*for(int i = 0; i < h; i += 5)
	{
		for(int j = 0; j < w; j += 5)
		{
			solve(i, i+4, j, j+4, query(i, i+4, j, j+4), 1);
		}
	}*/

	//solve(0, h-1, 0, w-1, n, 1);

	cout << "! " << ans << endl;
}

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

const int N=100;
const long long INF=(1LL<<32);

int main(){
	int V, E;
	long long d[N][N];
	
	scanf(" %d %d", &V, &E);
	
	//?????????
	for(int i=0; i<V; ++i){
		for(int j=0; j<V; ++j){
			d[i][j] = ((i==j) ? 0 : INF);		
		}
	}
	
	//????????\???
	for(int i=0; i<E; ++i){
		int s, t;
		long u;
		scanf(" %d %d %ld", &s, &t, &u);
		d[s][t]=u; //????????????????????§??????????????????
	}
	
	//Warshall-Floyd???
	for(int k=0; k<V; ++k){
		for(int i=0; i<V; ++i){
			if(d[i][k]==INF) continue; //?????????????????????
			for(int j=0; j<V; ++j){
				if(d[k][j]==INF) continue; //?????????????????????
				d[i][j] = min(d[i][j], d[i][k]+d[k][j]);		
			}
		}
	}
	
	bool negative=false;
	for(int i=0; i<V; ++i)
		if(d[i][i]<0) negative=true;
		
	if(negative) printf("NEGATIVE CYCLE\n");
	else{
		for(int i=0; i<V; ++i){
			for(int j=0; j<V; ++j){
				if(j>0) printf(" ");	
				
				if(d[i][j]==INF) printf("INF");
				else cout<<d[i][j];
			}
			printf("\n");
		}
	}
}



Measured memory_bytes: 3336
#include <iostream>
#include <iomanip>
#include <vector>
#include <deque>
#include <string>
#include <map>
#include <set>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <utility>
#include <bitset>

#define REP(i,A) for(int i=0;i<A;i++)

using namespace std;

int main() {
	int N;
	cin >> N;
	vector<int> b(N),cnt(N);
	REP(i, N) {
		cin >> b[N-i-1];
		cnt[i] = 0;
	}
	int ans = 0;
	vector<int> n;
	while (ans!=N) {
		for (int i = 0; i <= N; i++) {
			if (i == N){cout << -1; return 0;}

			if (b[i] == cnt[i] + 1) {
				n.push_back(cnt[i] + 1);
				cnt[i] = -10000;
				ans++;
				for (int j = 0; j < i; j++) {
					cnt[j]++;
				}
				break;
			}
		}
	}
	for (auto x : n)cout << x << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i=0; i<(int)(n); i++)
#define all(x) x.begin(), x.end()
#define mod 1000000007
typedef long long ll;

vector<pair<long long, long long> > prime_factorize(long long n) {
    vector<pair<long long, long long> > res;
    for (long long p = 2; p * p <= n; ++p) {
        if (n % p != 0) continue;
        int num = 0;
        while (n % p == 0) { ++num; n /= p; }
        res.push_back(make_pair(p, num));
    }
    if (n != 1) res.push_back(make_pair(n, 1));
    return res;
}

int main() {
    ll n;
    cin >> n;
    auto pf = prime_factorize(n);
    ll res = 0;
    for(auto p : pf){
        ll prime = p.first;
        ll kazu = p.second;
        ll check = 1;
        while(kazu >= check){
            kazu -= check;
            check++;
            res++;
        }
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 3628
#include<iostream>
#include<iomanip>
#include<cmath>
#include<string>
#include<cstring>
#include<vector>
#include<list>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define mp make_pair
#define rep(i, n) for(int i=0;i<n;++i)
#define rrep(i, n) for(int i=n;i>=0;--i)
const int inf=1e9+7;
const ll mod=1e9+7;
const ll mod1=998244353;
const ll big=1e18;
const double PI=2*asin(1);

int bit[200005];

void add(int x) {
  while(x<200005) {
    bit[x]++;
    x += x&-x;
  }
}

ll sum(int x) {
  ll ans = 0;
  while(x>0) {
    ans += bit[x];
    x -= x&-x;
  }
  return ans;
}

int main() {
  string S;
  cin>>S;
  vector<char> arr;
  map<char, int> amap;
  for(int i=0;i<S.size();++i) {
    if(amap[S[i]]==0) arr.push_back(S[i]);
    amap[S[i]]++;
  }
  bool ok = true;
  if(S.size()%2==0) {
    for(int i=0;i<arr.size();++i) {
      if(amap[arr[i]]%2==1) ok = false;
    }
  }
  else {
    int one = 0;
    for(int i=0;i<arr.size();++i) {
      if(amap[arr[i]]%2==1) one++;
    }
    if(one!=1) ok = false;
  }
  if(!ok) {
    cout<<-1<<endl;
    return 0;
  }
  map<char, int> bmap;
  string ans;
  char tmp;
  for(int i=0;i<S.size();++i) {
    if(amap[S[i]]%2==1) {
      if(bmap[S[i]]<amap[S[i]]/2) {
        ans.push_back(S[i]);
        bmap[S[i]]++;
      }
      tmp = S[i];
      continue;
    }
    if(bmap[S[i]]<amap[S[i]]/2) {
      ans.push_back(S[i]);
      bmap[S[i]]++;
    }
  }
  string ans1 = ans;
  if(S.size()%2==1) ans.push_back(tmp);
  for(int i=ans1.size()-1;i>=0;--i) ans.push_back(ans1[i]);
  vector<int> arr1;
  map<char, vector<int> > cmap;
  for(int i=0;i<ans.size();++i) {
    cmap[ans[i]].push_back(i+1);
  }
  map<char, int> dmap;
  for(int i=0;i<S.size();++i) {
    arr1.push_back(cmap[S[i]][dmap[S[i]]]);
    dmap[S[i]]++;
  }
  ll ans2 = 0;
  for(int i=0;i<arr1.size();++i) {
    ans2 += i-sum(arr1[i]);
    add(arr1[i]);
  }
  cout<<ans2<<endl;
}



Measured memory_bytes: 6544
#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,M;
  cin >> N >> M;
  int maxL,minR;
  maxL=0;
  minR=100000;

  rep(i,M){
    int L,R;
    cin >> L >> R;
    maxL=max(maxL,L);
    minR=min(minR,R);
  }
  int ans=0;
  if(maxL<=minR){
    ans=minR-maxL+1;
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
fn main() {
    let n = read::<i64>();
    let v = read_vec::<i64>();
    let sum = v.iter().sum::<i64>();

    if sum % n == 0 {
        let mut ans = 0;
        let ave = sum / n;
        for a in v {
            ans += (a - ave) * (a - ave);
        }
        println!("{}", ans);
    } else {
        let ave1 = sum / n;
        let ave2 = sum / n + 1;
        let mut ans1 = 0;
        let mut ans2 = 0;
        for a in v {
            ans1 += (a - ave1) * (a - ave1);
            ans2 += (a - ave2) * (a - ave2);
        }
        println!("{}", std::cmp::min(ans1, ans2));
    }
}

#[allow(dead_code)]
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}
#[allow(dead_code)]
fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}
#[allow(dead_code)]
fn read_vec2<T: std::str::FromStr>(n: u32) -> Vec<Vec<T>> {
    (0..n).map(|_| read_vec()).collect()
}
#[allow(dead_code)]
fn yn(result: bool) {
    if result {
        println!("Yes");
    } else {
        println!("No");
    }
}


Measured memory_bytes: 4352
from sys import stdin
readline = stdin.readline


class vector:
    def cross(a, b):
        return a.real * b.imag - a.imag * b.real

    def dot(a, b):
        return a.real * b.real + a.imag * b.imag

    def ccw(a, b, c):
        b -= a
        c -= a
        if vector.cross(b, c) > 0:
            return 1 
        if vector.cross(b, c) < 0:
            return 2
        if vector.dot(b, c) < 0:
            return 3
        if abs(b) < abs(c):
            return 4
        return 5

    def polygon(p):
        if len(p) < 3:
            return 0
        return 0.5 * sum(vector.cross(p[i - 1], p[i]) for i in range(len(p)))

    def intersection(p1, p2, p3, p4):
        a1 = p4 - p2
        b1 = p2 - p3
        b2 = p1 - p2
        s1 = vector.cross(a1, b2) / 2
        s2 = vector.cross(a1, b1) / 2
        if s1 + s2 == 0:
            return 0
        c1 = p1 + (p3 - p1) * s1 / (s1 + s2)
        return c1


def main():
    n = int(readline())
    p = [map(float, readline().split()) for _ in range(n)]
    p = [x + y * 1j for x, y in p]
    q = int(readline())

    for _ in range(q):
        p1x, p1y, p2x, p2y = map(float, readline().split())
        p1, p2 = p1x + p1y * 1j, p2x + p2y * 1j

        pre_tmp = vector.ccw(p[-1], p1, p2)
        left = []
        for i in range(len(p)):
            tmp = vector.ccw(p[i], p1, p2)
            if pre_tmp != tmp and all(i in (1, 2) for i in (pre_tmp, tmp)):
                c1 = vector.intersection(p1, p[i - 1], p2, p[i])
                left.append(c1)
            if tmp != 2:
                left.append(p[i])

            pre_tmp = tmp
        print('{:.6f}'.format(vector.polygon(left)))

import sys
if sys.hexversion >= 0x030203F0:
    main()
else:
    print('Error')

Measured memory_bytes: 6860
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>

using namespace std;

int main() {
	int r, g, b;
	cin >> r >> g >> b;
	b += 100 * r + 10 * g;
	cout << ((b % 4) ? "NO" : "YES") << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
using namespace std;
 
#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()
 
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef vector<VI> VVI;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

int ask(int x){
    cout << x << endl;
    string s;
    cin >> s;
    if (s == "Male") return 0;
    if (s == "Female") return 1;
    exit(0);
}

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

    int x = ask(0);
    int y = ask(n/2);

    int sm, la;
    if ((n / 2) % 2 == (x ^ y)){
        swap(x,y);
        sm = n/2;
        la = n;
    }else{
        sm = 0;
        la = n/2;
    }

    while (1){
        int mi = (sm + la + 1) / 2;
        int z = ask(mi);

        // cout << sm << " " << la << " " << mi << endl;
        // cout << x << " " << y << " " << z << endl;

        if ((mi - sm) % 2 != (x ^ z)){
            la = mi;
            y = z;
        }else{
            sm = mi;
            x = z;
        }
    }

    return 0;
}


Measured memory_bytes: 852
import heapq

n,m=map(int,input().split())
*a,=map(int,input().split())

q=[]
for aa in a:
    heapq.heappush(q,-aa)

while m>0:
    aa=heapq.heappop(q)
    heapq.heappush(q,-((-aa)//2))
    m-=1

print(-sum(q))

Measured memory_bytes: 94532
#![allow(unused_imports)]
#![allow(unused_macros)]
#![allow(non_snake_case)]
#![allow(dead_code)]
#![allow(unused_variables)]
#![allow(unused_mut)]
#![allow(unused_assignments)]
use proconio::input;
use proconio::marker::Usize1;
use std::collections::*;
use std::cmp::*;
use std::f64::consts::*;

const MOD: u64 = 1000000007;
const INF: usize = std::usize::MAX / 4;

fn main() {
    input! {
        mut A: i64,
        mut B: i64,
        mut C: i64,
        mut D: i64,
    }

    for i in 0..1000 {
        if i % 2 == 0 {
            C -= B;
            if C <= 0 {
                println!("Yes");
                break;
            }
        } else {
            A -= D;
            if A <= 0 {
                println!("No");
                break;
            }
        }
    }
}


Measured memory_bytes: 2116
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

	    while (true) {
		    String line = br.readLine();
		    int H = Integer.parseInt(line.split(" ")[0]);
		    int W = Integer.parseInt(line.split(" ")[1]);

		    if (H == 0 && W == 0) break;

		    display(H, W);

	    }
	}

	public static void display(int h, int w) {
		for (int i = 0; i < h; i++) {
			for (int j = 0; j < w; j++) {
				System.out.print("#");
			}
			System.out.println("");
		}
		System.out.println("");
	}
}

Measured memory_bytes: 31184
import java.util.Arrays;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        long[] x = new long[n];
        long[] xx = new long[n];
        for (int i = 0; i < n; i++) {
            long temp = Long.parseLong(sc.next());
            x[i] = temp;
            xx[i] = temp;
        }
        Arrays.sort(xx);
        long l1 = xx[n / 2];
        long l2 = xx[n / 2 - 1];
        StringBuilder sb = new StringBuilder();
        if (l1 == l2) {
            for (int i = 0; i < n; i++) {
                sb.append(l1);
                sb.append("\n");
            }
        } else {
            for (int i = 0; i < n; i++) {
                if (x[i] <= l2) {
                    sb.append(l1);
                } else {
                    sb.append(l2);
                }
                sb.append("\n");
            }
        }
        System.out.print(sb.toString());
    }
}

Measured memory_bytes: 59244
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
typedef long long LL;
int N;

int main(){
	string S;
	cin>>S;
	int r=0;
	int b=0;
	int ans=0;
	REP(i,S.size()){
		if(S[i]=='0'){
			r++;
			if(b>0){
				r--;
				b--;
				ans+=2;
			}
		}else{
			b++;
			if(r>0){
				r--;
				b--;
				ans+=2;
			}
		}
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 512
#include <iostream>
#include <algorithm>
#include <bitset>
#include <cmath>
#include <deque>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>

#define Rep(i, b, e) for(int (i) = (b); (i) < (e); ++(i))
#define Repr(i, b, e) for(int (i) = (b) - 1; (i) >= (e); --(i))
#define Print(x) cout << (x) << endl 
#define Min2(a, b) ((a) < (b)) ? (a) : (b)
#define Max2(a, b) ((a) > (b)) ? (a) : (b)

typedef long long ll;

using namespace std;

int main(){
    int R, G, B, N, cnt = 0;
    cin >> R >> G >> B >> N;
    for(int i = 0; i * R <= N; i++){
        for(int j = 0; i * R + j * G <= N; j++){
            if((N - R * i - G * j) % B == 0) cnt++;
        }
    }
    Print(cnt);
    return 0;
}

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

using namespace std;
using ll = long long;

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    double curr=100;
    ll targ;
    cin>>targ;
    int cnt = 0;
    while(curr<targ){
        curr *= 1.01;
        curr = floor(curr);
        cnt++;
    }
    cout<<cnt;
    return 0;
}

Measured memory_bytes: 3648
#include <iostream>
#include <cmath>
#include <numeric>

int main() {
  int N;
  std::cin >> N;

  unsigned int this_digit = 0;
  for (int digit = 5; digit >= 0; digit--) {
    if (N >= std::pow(10, digit)) {
      this_digit = digit + 1;
      break;
    }
  }
  if (this_digit == 1 || this_digit == 2) {
    std::cout << std::min(N, 9) - 1 + 1 << std::endl;
  } else if (this_digit == 3 || this_digit == 4) {
    std::cout << 9 + std::min(N, 999) - 100 + 1 << std::endl;
  } else if (this_digit == 5 || this_digit == 6) {
    std::cout << 9 + (999 - 100 + 1) + std::min(N, 99999) - 10000 + 1 << std::endl;
  }

  return 0;
}


Measured memory_bytes: 256
n = int(input())
a = list(map(int, input().split()))
a.sort(reverse=True)
ans = a[0]
idx = 1
for i in range(1, n):
    if idx == n - 1:
        break
    ans += a[i]
    idx += 1
    if idx == n - 1:
        break
    ans += a[i]
    idx += 1
print(ans)


Measured memory_bytes: 105000
import java.util.Scanner;

public class Main {

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

		int n = s.nextInt();
		int k = s.nextInt();
		int x = s.nextInt();
		int y = s.nextInt();
		int i = 0;
		int sum = 0;

		for (i = 0; i < n; i++) {
			if (i < k) {
				sum = sum + x;
			} else if (i >= k) {
				sum = sum + y;
			}
		}
		System.out.println(sum);
	}

}


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

#define NEW(p,n){p=malloc((n)*sizeof(p[0]));if(p==NULL){printf("not enough memory\n");exit(1);};}
//pの型の変数n個の要素分のメモリを確保し、そのアドレスをpに代入するマクロ

#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) < (b) ? (a) : (b))

typedef struct{
    int a;
    int b;
}data;

//bの昇順→aの昇順でdataをソート
int asc(const void* a, const void* b){
    data p=*(data*)a;
    data q=*(data*)b;
    if(p.b!=q.b) return p.b-q.b;
    else return p.a-q.a;
}

int main(void){
    int N,M;
    scanf("%d%d",&N,&M);

    //A[0]~A[M-1]に格納する
    data* A;
    NEW(A,M);
    for(int i=0;i<M;i++){
        scanf("%d %d",&A[i].a,&A[i].b);
        A[i].a--;
        A[i].b--;
    }
    qsort(A,M,sizeof(data),asc);

    int ans=1;
    int bridge=A[0].b-1;
    for(int i=1;i<M;i++){
        if(A[i].a>bridge){
            bridge=A[i].b-1;
            ans++;
        }
    }
    printf("%d\n",ans);

    return 0;
}

Measured memory_bytes: 1788
#include <bits/stdc++.h>
#define pb push_back
#define all(x) begin(x), end(x)

using namespace std;
using ll = long long int;
const int MOD = 1e9 + 7;

int main()
{
	ios::sync_with_stdio(0); cin.tie(0);
	int n; cin >> n;
	ll a[n];
	ll pref[n];
	for (int i = 0; i < n; ++i)
	{
		cin >> a[i];
		pref[i] = a[i];
		if (i) pref[i] += pref[i-1];
	}
	ll tot = pref[n-1];
	ll ans = 3LL * tot;
	for (int i = 0; i < n - 1; ++i)
	{
		ll x = pref[i];
		ll y = tot - pref[i];
		ans = min(ans, abs(x-y));
	}
	cout << ans;
}

Measured memory_bytes: 3328
#include <bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp>
using namespace std;
//using namespace boost::multiprecision;
typedef long long int ll;
typedef long double ld;
typedef pair<ll,ll> P;
#define PI 3.141592653589793
#define MOD 1000000007
//#define MOD 998244353
#define ALL(obj) (obj).begin(),(obj).end()
const ll INF = 1LL << 60;
//四方向への移動ベクトル
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
bool pairCompare(const pair<double,ll>& firstElof, const pair<double,ll>& secondElof){
    return firstElof.first < secondElof.first;
}

struct edge{//グラフに使うヤツ
    ll from,to,cost;
};

typedef vector<vector<edge> > G;

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

int main() { 
    ll n;
    cin>> n;
    if (n==0)n=1;
    else n=0;
    cout << n  << endl;
    return 0;
}



Measured memory_bytes: 3600
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rapido ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define endl "\n"
#define mod 1000000007

void solve()
{
 int n;cin>>n;
 vector<int>arr1;
 vector<int>arr2;
 
 for(int i=1;i<=n;i++)
 {
     int x;int y;cin>>x>>y;
     arr1.push_back(x+y);
     arr2.push_back(x-y);
 }
 int mini1=*min_element(arr1.begin(),arr1.end());
 int maxi1=*max_element(arr1.begin(),arr1.end());
  int mini2=*min_element(arr2.begin(),arr2.end());
 int maxi2=*max_element(arr2.begin(),arr2.end());
 int ans=abs(mini1-maxi1);
 ans=max(ans,abs(mini2-maxi2));
 cout<<ans<<endl;
}

int32_t main() 
{
    rapido;
    int t;
    // cin>>t;
     t=1;
    while(t--)
    solve();
    return 0;
}




Measured memory_bytes: 6688
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner stdin = new Scanner(System.in);
		int a = stdin.nextInt();
		int b = stdin.nextInt();
		if(a%2==1&&b%2==1) {
			System.out.println("Odd");
		}else {
			System.out.println("Even");
		}


	}

}


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

#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define fr(i,k) for(i=0;i<k;i++)
#define ALL(c) (c).begin(),(c).end()
#define deb(x) cerr<<#x<<"  = "<<x<<endl;
#define SZ(x) (x).size();
#define ll long long
#define MOD 1000000007
#define mp make_pair
#define ff first
#define ss second
#define pb push_back
#define em emplace_back
#define ulli unsigned long long int
#define INF 1e18
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<bool> vb;
typedef pair<int, int> ii;
void solve();

void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
	cerr << *it << " = " << a << endl;
	err(++it, args...);
}

int main() {
	fastio;
/*#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif*/

	int t;
	t=1;

    //cin>>t;
	while (t--)
	{
		solve();
	}
	return 0;
}

ll cc;

void dfs(set<ll> adj[],vb &vis,ll s)
{
    vis[s]=true;
    cc++;

    for(auto k:adj[s])
    {
        if(!vis[k])
        {
            dfs(adj,vis,k);
        }
    }
}

void solve()
{
	ll n,m,i,u,v,ans=0;
	cin>>n>>m;

	set<ll> adj[n+1];
	vb vis(n+1,false);

	for(i=0;i<m;i++)
    {
        cin>>u>>v;
        adj[u].insert(v);
        adj[v].insert(u);
    }

    for(i=1;i<=n;i++)
    {
        if(!vis[i])
        {
            cc=0;
            dfs(adj,vis,i);
            ans=max(ans,cc);
        }
    }

    cout<<ans<<endl;
}


Measured memory_bytes: 41132
a = int(input()) #500
b = int(input()) #100
c = int(input()) #50
x = int(input())

cnt = 0

for i in range(a+1):
    for j in range(b+1):
        for k in range(c+1):
            total = 500 * i + 100 * j + 50 * k
            
            if total == x:
                cnt += 1

print(cnt)

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

#define INF 1001001001
#define LINF 1001001001001001001
#define MOD 1000000007
#define MOD2 998244353

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

#define rep(i,n) for(int i=0,_i=(n);i<_i;++i)
#define rep1(i,a,b) for(int a_=(a),b_=(b),i=a_;i<b_;++i)
#define repr(i,n) for(int _i=(n),i=_i;i>0;--i)

#define db(x) cerr<<#x<<" = "<<x<<" ";
#define db2(x,y) cerr<<"("<<#x<<", "<<#y<<") = ("<<x<<", "<<y<<") ";
#define db3(x,y,z) cerr<<"("<<#x<<", "<<#y<<", "<<#z<<") = ("<<x<<", "<<y<<", "<<z<<") ";
#define ln cout<<endl;

#define all(a)  (a).begin(),(a).end()
#define dig(n)  to_string(n).length()

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define se second
#define fi first

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

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);}

int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

int main(){
    bool flag=false;
    ll ans=0,sum=0;

    ll n,a,b;
    cin>>n>>a>>b;

    ans = a*(n/(a+b)) + min(a,n%(a+b));
    
    cout<<ans<<endl;
    
    //if(flag)cout << "Yes" <<endl;
    //else cout << "No" <<endl;
    
    return 0;
}


Measured memory_bytes: 256