akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<string.h>
#include<stdbool.h>
#include<assert.h>
typedef long long ll;
typedef long double ld;
#define rep(i,l,r)for(ll i=(l);i<(r);i++)
#define repp(i,l,r,k)for(ll i=(l);i<(r);i+=(k))
#define rrep(i,l,r)for(ll i=(l);i>=(r);i--)
#define INF (1LL<<60)
#define MOD1 1000000007
#define MOD2 998244353
#define MAX_N (1 << 17)
#define YES printf("Yes\n")
#define NO printf("No\n")
#define PN printf("\n")
#define charsize 100005 //10^5+5

void swap(ll *a, ll *b){ll c;c=*b;*b=*a;*a= c;}
ll max2(ll a,ll b){return a>=b?a:b;}
ll min2(ll a,ll b){return a>=b?b:a;}
ll min3(ll a, ll b, ll c){return (a<=b && a<=c) ? a : b<=c ? b : c;}
ll max3(ll a, ll b, ll c){return (a>=b && a>=c) ? a : b>=c ? b : c;}
ll minn(ll n, ll a[n]){ll b=INF;rep(i,0,n) b=min2(b,a[i]);return b;}
ll maxn(ll n, ll a[n]){ll b=-INF;rep(i,0,n) b=max2(b,a[i]);return b;}
ll ABS(ll a){return a>=0?a:(-a);}
ll POW(ll a, ll b){ll c=1;rep(i,0,b) c*=a;return c;}
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
ll mod_MOD1(ll n){n+= n<0?((-n)/MOD1+1)*MOD1:0; return n%=MOD1;}
ll mod_p(ll n ,ll p){n+= n<0?((-n)/p+1)*p:0; return n%=p;}
ll change_into_num(char s[] , ll len, ll p){ return !p ? 0 : POW(10,p-1)*(s[len-p]-'0') + change_into_num(s,len,p-1); }

int upll(const void*a, const void*b){return*(ll*)a<*(ll*)b?-1:*(ll*)a>*(ll*)b?1:0;}
int downll(const void*a, const void*b){return*(ll*)a<*(ll*)b?1:*(ll*)a>*(ll*)b?-1:0;}
void sortup(ll*a,int n){qsort(a,n,sizeof(ll),upll);}
void sortdown(ll*a,int n){qsort(a,n,sizeof(ll),downll);}

typedef struct{ ll a , b;}fr;
int cmp1( const void *p, const void *q ) { return ((fr*)p) ->a - ((fr*)q)->a;}
int cmp2( const void *p, const void *q ) { return ((fr*)q) ->a - ((fr*)p)->a;}
void strsortup(fr*a,int n){qsort(a,n,sizeof(fr),cmp1);}
void strsortdown(fr*a,int n){qsort(a,n,sizeof(fr),cmp2);}

int main(void){
    // char ;
    ll a,b,c,x,y;
    ll ans=0;
    scanf("%lld%lld%lld%lld%lld",&a,&b,&c,&x,&y);
    // ll [n];
    // rep(i,0,n){
    //     scanf("%lld",&[i]);
    // }
    ans+=a*x+b*y;
    // printf("%lld ",ans);
    ll cost;
    rep(i,1,max2(x,y)+1 ){
        cost = ans;
        cost-=a+b;
        if(i>y ) cost+=b;
        if(i>x ) cost+=a;
        cost+=c*2;
        ans = min2(ans,cost);
        // printf("%lld ",cost);
    }
    
    printf("%lld\n",ans);
    return 0;
}


Measured memory_bytes: 128
#pragma region include
#include <iostream>
#include <iomanip>
#include <stdio.h>

#include <sstream>
#include <algorithm>
#include <cmath>
#include <complex>

#include <string>
#include <cstring>
#include <vector>
#include <tuple>
#include <bitset>

#include <queue>
#include <complex>
#include <set>
#include <map>
#include <stack>
#include <list>

#include <fstream>
#include <random>
//#include <time.h>
#include <ctime>
#pragma endregion //#include
/////////
#define REP(i, x, n) for(int i = x; i < n; ++i)
#define rep(i,n) REP(i,0,n)
/////////
#pragma region typedef
typedef long long LL;
typedef long double LD;
typedef unsigned long long ULL;
#pragma endregion //typedef
////定数
const int INF = (int)1e9;
const LL MOD = (LL)1e9+7;
const LL LINF = (LL)1e18;
const double PI = acos(-1.0);
const double EPS = 1e-9;
/////////
using namespace::std;

void solve(){
	int N;
	cin >> N;
	vector<int> A(100,0);
	/////8
	vector<int> iro(9,0);
	A[0] = 399;
	A[1] = 799;
	A[2] = 1199;
	A[3] = 1599;
	A[4] = 1999;
	A[5] = 2399;
	A[6] = 2799;
	A[7] = 3199;
	for(int i=0;i<N;++i){
		int R;
		cin >> R;
		for(int j=0;j<8;++j){
			if( R <= A[j] ){
				iro[j]++;
				break;
			}
		}
		if( R >= 3200 ){
			iro[8]++;
		}
	}
	int ans = 0;
	for(int i=0;i<8;++i){
		if( iro[i] ){
			++ans;
		}
	}
	int res = iro[8];
	if( ans == 0 ){
		if( res ){
			cout << 1;
		}else{
			cout << 0;
		}
	}else{
		cout << ans;
	}
	cout << " " << ans+res << endl;
}

#pragma region main
signed main(void){
	std::cin.tie(0);
	std::ios::sync_with_stdio(false);
	std::cout << std::fixed;//小数を10進数表示
	cout << setprecision(16);//小数点以下の桁数を指定//coutとcerrで別	
	
	solve();
}
#pragma endregion //main()


Measured memory_bytes: 256
//main関数

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

vector<int> ranking(vector<int> &v) {
    int n=v.size();
    map<int,int> m;
    for(int i=0;i<n;i++){
        m[v.at(i)]=i;
    }
    vector<int> w(n);
    int i=0;
    for(auto p:m){
        w.at(i)=p.second;
        i++;
    }
    return w;
}

int main(){
    int n;
    cin>>n;
    vector<int>a(n);
    for(auto &p:a) cin>>p;
    vector<int> b(n);
    b=ranking(a);
    for(auto &p:b){
        cout<<p+1<<" ";
    }
}

Measured memory_bytes: 6264
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef vector<LL> VI;
typedef vector<VI> VVI;
typedef pair<LL, LL> PII;
typedef vector<string> VS;
inline LL toInt(string s) {LL v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
#define PB push_back
#define MP make_pair
#define SZ(a) LL((a).size())
#define EACH(x,c) for(auto x: (c))
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define ALL(c) (c).begin(), (c).end()
#define REVERSE(c) reverse(ALL(c))
#define SORT(c) sort(ALL(c))
#define RSORT(c) sort((c).rbegin(),(c).rend())
#define STABLE_SORT(c) stable_sort(ALL(c))
#define STABLE_RSORT(c) stable_sort((c).rbegin(),(c).rend())
#define UNIQUE(c) SORT(c); (c).erase(unique(ALL(c)), (c).end());
#define FOR(i,a,b) for(LL i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
const double INF = 1e7;
const double EPS = 1e-10;
const double PI  = acos(-1.0);
#define dump(x)  cerr << #x << " = " << (x) << endl;


int main() {
	string S;
	cin >> S;
	LL l = 0, max_l = 0;
	REP(i, SZ(S)) {
		if (S[i] == 'A' || S[i] == 'C' || S[i] == 'G' || S[i] == 'T') {
			l++;
		} else {
			if (l > max_l) {
				max_l = l;
			}
			l = 0;
		}
	}
	if (l > max_l) {
		max_l = l;
	}
	cout << max_l << endl;
	
    return 0;
}


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

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


Measured memory_bytes: 3116
#include <iostream>
#include <algorithm>
#include <cmath>
using namespace std;
int a[100];

void init(int n){
	for (int i = 0; i < n; ++i){
		a[i] = 0;
	}
}

int main(){
	int n;
	init(30);
	a[0] = 1;
	a[1] = 1;
	a[2] = 2; 
	for (int i = 3; i < 32; ++i){
		a[i] = a[i-1] + a[i-2] + a[i-3];
	}
	while(cin >> n,n){
		cout << (a[n]/10+1)/365+1 << endl;
	}
	return 0;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define mod 1000000007
#define deb(x) cerr << "\n" \
                    << #x << "=" << x << "\n";
#define deb2(x, y) cerr << "\n"                   \
                        << #x << "=" << x << "\n" \
                        << #y << "=" << y << "\n";
#define w(x)  \
    int x;    \
    cin >> x; \
    while (x--)

int32_t main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n, k;
    cin >> n >> k;
    vector<int> v(n);
    for (int &i : v)
        cin >> i;
    sort(v.begin(), v.end());
    int ans = 0;
    for (int i = 0; i < k; i++)
        ans += v[i];
    cout << ans;
    return 0;
}

Measured memory_bytes: 3660
N = int(input())
t, a = map(int, input().split())
for i in range(N - 1):
  T, A = map(int, input().split())
  x = max((t - 1) // T + 1, (a - 1) // A + 1)
  t = T * x
  a = A * x
print(t + a)

Measured memory_bytes: 71664
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
#include <array>
#include <iomanip>
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<long double> VD;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef vector<VD> VVD;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

template<typename T> void chmin(T &a, T b) { if (a > b) a = b; }
template<typename T> void chmax(T &a, T b) { if (a < b) a = b; }

int in() { int x; scanf("%d", &x); return x; }
ll lin() { ll x; scanf("%lld", &x); return x; }
#define INF 1LL<<60

int main() {
    int N;
    cin >> N;
    vector<int> dp(N+1);
    dp[0] = 1;
    dp[1] = 1;
    FOR(i, 2, N) {
        dp[i] = dp[i-1] + dp[i-2];
    }
    cout << dp[N] << endl;
    return 0;
}


Measured memory_bytes: 3088
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
const ll MOD=(ll)1e9+7;
const ll INF=(ll)1e18+10;

ll f(ll b,ll n){
    if(n<b) return n;
    return f(b,(ll)floor(1.0*n/b))+n%b;
}

int main() {
    ll n,s; cin>>n>>s;
    if(s==n){
        cout<<n+1<<endl;
        return 0;
    }
    if(s>n){
        cout<<-1<<endl;
        return 0;
    }

    for(ll i = 2ll; i <=sqrt(n)+1; ++i){
        if(f(i,n)==s){
            cout<<i<<endl;
            return 0;
        }
    }
    priority_queue<ll,vector<ll>,greater<>> ans;
    for (ll i = 1; i <= sqrt(n) + 1; ++i) {
        ll b=(n-s);
        if(b%i!=0) continue;
        b=b/i+1;
        if(f(b,n)==s){
            //cout<<b<<endl;
            //return 0;
            ans.push(b);
        }
    }

    if(ans.empty())cout<<-1<<endl;
    else cout<<ans.top()<<endl;

    return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
struct card{char suit,value	;};
void buble(struct card a[],int n)
{
	struct card t;
	for(int i=0;i<n;i++)
	{
	    for(int 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(struct card a[],int n)
{
	int minj;
	struct card t;
	for(int i=0;i<n;i++)
	{
		minj=i;
		for(int 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 point(struct card a[],int n)
{
	for(int i=0;i<n;i++)
	{
	if(i>0)cout<<" ";
	cout<<a[i].suit<<a[i].value;
	}
	cout<<endl;
}
bool sp(struct card c1[],struct card c2[],int n)
{
	for(int i=0;i<n;i++){ 
	if(c1[i].suit!=c2[i].suit)
	return false;
}
return true;	
}
int main(){
struct card c1[100],c2[100];
int n;
char ch;
cin>>n;
	for(int i=0;i<n;i++) {
	cin>>c1[i].suit; 
	cin>>c1[i].value;}
	for(int i=0;i<n;i++)
	c2[i]=c1[i];
	buble(c1,n);
	selection(c2,n);
	point(c1,n);
	cout<<"Stable"<<endl;
	point(c2,n);
	if(sp(c1,c2,n)){
		cout<<"Stable"<<endl;
	}else{
		cout<<"Not stable"<<endl;
	}
	return 0;
}


Measured memory_bytes: 3092
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 
using namespace std;
#define lli long long int
#define all(x) x.begin(),x.end()
#define siz(x) x.size()
#define prs(x,y) x.find(y)!=x.end()
#define DEBUG(x) cout << '>' << #x << ':' << x << endl;
#define REP(i,n) for(int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<=(b);i++)
#define FORD(i,a,b) for(int i=(a);i>=(b);i--)
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
inline bool EQ(double a, double b) { return fabs(a-b) < 1e-9; }
const int INF = 1<<29;
typedef long long ll;
inline int two(int n) { return 1 << n; }
inline int test(int n, int b) { return (n>>b)&1; }
inline void set_bit(int & n, int b) { n |= two(b); }
inline void unset_bit(int & n, int b) { n &= ~two(b); }
inline int last_bit(int n) { return n & (-n); }
inline int ones(int n) { int res = 0; while(n && ++res) n-=n&(-n); return res;}
inline int level(int n){int ans=0;while(n%2==0){n/=2;ans++;}return ans;}
lli a[100005];
lli MAX=1e18;
int main()
{
	lli n=0;
	cin>>n;
	bool f=true;
	bool k=false;
	lli mul=1;
	for(int i=0;i<n;i++)
	{
		cin>>a[i];
		if(a[i]==0)
			k=true;
		if(k)
			continue;
		if(MAX/mul<a[i])
			f=false;
		if(f)
			mul*=a[i];
	}
	if(!f)
		mul=-1;
	if(k)
		mul=0;
	cout<<mul;
	return 0;
}



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

using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;

int main(){
	int N; cin>>N;
  if(N==1) printf("1");
  else{
    int cnt=0;
    vector<ll> x(N);
    vector<ll> y(N);
    vector<P> P((N-1)*N/2);
    for(int i=0;i<N;i++) cin>>x[i]>>y[i];

     vector<ll> dx((N-1)*N/2);
    vector<ll> dy((N-1)*N/2);

    for(int i=0;i<=N-2;i++){
      for(int j=i+1;j<=N-1;j++){
          dx[cnt]=x[i]-x[j];
          dy[cnt]=y[i]-y[j];
        //dx-->plus
        if(dx[cnt]<0){
          dx[cnt]*=-1;
          dy[cnt]*=-1;
        }
        else if(dx[cnt]==0 || dy[cnt]==0){
        	if(dx[cnt]+dy[cnt]<0){
            	dx[cnt]*=-1;
         		dy[cnt]*=-1;
            }
        }
        P[cnt]=make_pair(dx[cnt],dy[cnt]);
        cnt++;
      }
    }
    
    sort(P.begin(),P.end());

    ll mem1=P[0].first,mem2=P[0].second,ans=1,tmp=1;
    for(int i=1;i<cnt;i++){
      if(mem1==P[i].first && mem2==P[i].second) tmp++;
      else{
          tmp=1;
          mem1=P[i].first;
          mem2=P[i].second;
      }
      ans=max(ans,tmp);
    }
    printf("%lld",N-ans);
  }
}

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

#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n) for(int i=(s);i<=(n);i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define REPR(i,s,n) for(int i=(s);i>=(n);i--)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define Eunique(v) v.erase(unique(all(v)),v.end())
#define Eback(s) s.erase(s.end()-1,s.end())
#define rev(v) reverse(all(v))
#define minvec(v) *min_element(all(v))
#define maxvec(v) *max_element(all(v))
#define sumvec(v) accumulate(all(v),0)
#define mapmax(v) v.rbegin()->first
#define mapmin(v) v.begin()->first
#define pb push_back
#define pf push_front
#define mod 1000000007
#define m_p make_pair
#define DOUBLE fixed << setprecision(15)
#define OK puts("OK")
#define OK1 puts("OK1")
#define OK2 puts("OK2")
#define SIZE(s) (int)s.size()
#define INF ((1LL<<62)-(1LL<<31))
#define zero(x,n) setw(x) << setfill('0') << n

typedef long long ll;

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<long long> vll;
typedef vector<vll> vvll;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<string> vs;

typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
typedef vector<pair<int,int>> vpii;
typedef vector<pair<ll,ll>> vpll;

const double pi = acos(-1.0);

template<class A, class B>
ostream& operator<<(ostream& ost, const pair<A, B>&p) {
	ost << "{" << p.first << ", " << p.second << "} ";
	return ost;
}

template<class T>
ostream& operator<<(ostream& ost, const vector<T>&v) {
	ost << "{";
	for (int i = 0; i<(int)v.size(); i++) {
		if (i)ost << " ";
		ost << v[i];
	}
	ost << "} \n";
	return ost;
}

template<class A, class B>
ostream& operator<<(ostream& ost, const map<A, B>&v) {
	ost << "{";
	for (auto p:v) {
		ost << "{" << p.first << ", " << p.second << "} ";
	}
	ost << "} ";
	return ost;
}

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

void YES(bool b) {cout << (b?"YES\n":"NO\n");}
void Yes(bool b) {cout << (b?"Yes\n":"No\n");}
void yes(bool b) {cout << (b?"yes\n":"no\n");}
void Yay(bool b) {cout << (b?"Yay!\n":":(\n");}

ll gcd(ll x, ll y) {return __gcd(x,y);}
ll lcm(ll x, ll y) {return x/__gcd(x,y)*y;}

int main()
{
	ll n,m;
	cin >> n >> m;
	cout << n*(n-1)/2+m*(m-1)/2 << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1LL<<62
#define inf 1000000007

priority_queue<ll>a;
int main() {
	ll n,k;
	cin>>n>>k;
	for(ll i=0;i<n;i++){
		ll x;
		cin>>x;
		a.push(x);
	}
	while(k!=0){
		k--;
		ll now=a.top();
		a.pop();
		now/=2;
		a.push(now);
	}
	ll ans=0;
	while(!a.empty()){
		ans+=a.top();
		a.pop();
	}
	cout<<ans;
	// your code goes here
	return 0;
}

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

double calcLength(double x1, double x2, double y1, double y2){
  return sqrt(abs((x2-x1)*(x2-x1) + (y2-y1)*(y2-y1)));
}

int main(void){
  double ans = 0;
  vector<pair<double, double> > p;
  pair<double, double> tmp;
  while(scanf("%lf,%lf", &tmp.first, &tmp.second) != EOF){
    p.push_back(tmp);
  }
  
  for(int i=1; i < p.size() - 1; i++){
    double r[3];
    for(int j=0; j < 2; j++){
      double x1 = p[0].first, x2 = p[i+j].first;
      double y1 = p[0].second, y2 = p[i+j].second;
      r[j] = calcLength(x1, x2, y1, y2);
    }
    double x1 = p[i].first, x2 = p[i+1].first;
    double y1 = p[i].second, y2 = p[i+1].second;
    r[2] = calcLength(x1, x2, y1, y2);
    double z = (r[0] + r[1] + r[2]) / 2;
    ans += sqrt(z*(z-r[0])*(z-r[1])*(z-r[2]));
  }
  printf("%f\n", ans);
  return 0;
}

Measured memory_bytes: 1236
#include<iostream>
#include<math.h>

using namespace std;

int main(void) 
{
	long long n, k;
	cin >> n >> k;
	long long abs_Data = 0;
	while (1)
	{
		if (n > k)
			abs_Data = n % k;
		else
			abs_Data = abs(n - k);
		if (abs_Data >= n)
			break;
		n = abs_Data;
	}

	cout << n;
	return 0;
}


Measured memory_bytes: 256
#if loc||local
#define _GLIBCXX_DEBUG
#endif

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

#define rep(i,n) for(ll i=0;i<(n);++i)
using ll = int_fast64_t;
using pll = pair<ll,ll>;
constexpr ll INF = 1LL<<60;
constexpr ll MOD = 1e9+7;
template<class T> bool chmax(T &a,const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T> bool chmin(T &a,const T &b){if(a>b){a=b;return 1;}return 0;}
#if loc||local
template<class T>void dump(T&& t){cerr<<t<<endl;}
template<class T,class... Ts> void dump(T&& h, Ts&&... t){cerr<<h<<", ";dump(forward<Ts>(t)...);}
#else
void dump(){}
template<class T,class... Ts> void dump(T&& h, Ts&&... t){}
#endif
template<class T> istream &operator>>(istream&is,vector<T>&v){for(auto &elemnt:v)is>>elemnt;return is;}
template<class T,class U> istream &operator>>(istream&is,pair<T,U>&p){is>>p.first>>p.second;return is;}
template<class T> ostream &operator<<(ostream& os,vector<T>const& v){for(auto const& vi:v)os<<vi<<" ";return os;}
template<class T,class U> ostream &operator<<(ostream& os,pair<T,U>const& p){os<<p.first<<","<<p.second;return os;}
template<class T>vector<T> vec(size_t a){return vector<T>(a);}
template<class T, class... Ts>auto vec(size_t a, Ts... ts){return vector<decltype(vec<T>(ts...))>(a, vec<T>(ts...));}

signed main(){

  int n;
  string s;
  cin>>n>>s;

  vector<ll> r(n+1),w(n+1);
  rep(i,n){
    r[i+1] += r[i];
    w[i+1] += w[i];
    if(s[i]=='R')r[i+1]++;
    else w[i+1]++;
  }

  vector<ll> rb(n+1),wb(n+1);
  reverse(begin(s),end(s));
  rep(i,n){
    rb[i+1] += rb[i];
    wb[i+1] += wb[i];
    if(s[i]=='R')rb[i+1]++;
    else wb[i+1]++;
  }
  reverse(begin(rb),end(rb));
  reverse(begin(wb),end(wb));

  dump(r);dump(rb);dump(w);dump(wb);

  ll ans = INF;
  rep(i,n+1){
    ll tmp = w[i]+rb[i]-2*min(w[i],rb[i])+min(w[i],rb[i]);
    dump(w[i],rb[i],tmp);
    chmin(ans,tmp);
  }
  cout<<(ans)<<endl;


}

Measured memory_bytes: 9732
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
using namespace std;

int main() {
    int A, B;
    cin >> A >> B;

    if ((A + B) % 2 == 0) {
        cout << (A + B) / 2 << endl;
    }
    else {
        cout << "IMPOSSIBLE" << endl;
    }
}

Measured memory_bytes: 3640
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define MAX_N 100000
#define MAX_M 100000
const int MAX = 100100;
const int MOD = 1000000007;
#define vec vector<int>
#define vecll vector<ll>
#define vecllvec vector<vector<ll>>
#define vecb vector<bool>
#define vecBvec vector<vector<bool>>
#define vecst vector<string>
#define vecch vector<char>
#define vecd vector<double>
#define vecvec vector<vector<int>>
#define vecDvec vector<vector<double>>
#define vecHvec vector<vector<char>>
#define all(x) (x).begin(),(x).end()
const long long INF = 1LL<<60;
#define PI 3.141592653589793
// cout << setprecision(15) << std::fixed;

// テレンス「もしかしてACですかーッ!?」　ジョセフ「Yse! Yse! Yse!」


int main() {
  int n,g=0,m=0;
  cin>>n;
  int A[n];
  for(int i=0;i<n;i++){
    cin>>A[i];
    g+=A[i];
    m=max(m,A[i]);
  }
  if(m<g-m){
    cout<<"Yes"<<endl;
  }
  else{
    cout<<"No"<<endl;
  }
}


Measured memory_bytes: 256
import java.util.*;
public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        String[] nyu=sc.nextLine().split(" ");
        int A=Integer.parseInt(nyu[0]);
        int B=Integer.parseInt(nyu[1]);
        int C=Integer.parseInt(nyu[2]);
        System.out.println(multi(A,B));
    }
  
  public static int multi(int x, int y){
   return x*y/2; 
  }
}

Measured memory_bytes: 23636
#define _USE_MATH_DEFINES
#include<iostream>
#include<string>
#include<cmath>
#include<queue>
#include<map>
#include<set>
#include<list>
#include<iomanip>
#include<vector>
#include<random>
#include<functional>
#include<algorithm>
#include<cstdio>
#include<unordered_map>
using namespace std;
//---------------------------------------------------
//ライブラリゾーン！！！！
typedef long long ll;
typedef long double ld;
#define str string
#define rep(i,j) for(ll i=0;i<(long long)(j);i++)
const ll Mod = 1000000007;
const ll gosenchou = 5000000000000000;
short gh[2][4] = { { 0,0,-1,1 },{ -1,1,0,0 } };
struct P {
	ll pos;
	ld cost;
};
bool operator<(P a, P b) { return a.cost < b.cost; }
bool operator>(P a, P b) { return a.cost > b.cost; }
struct B {//隣接リスト表現
	ll to;
	ld cost;
};
struct E {//辺の情報を入れる変数
	ll from, to, cost;
};
bool operator<(E a, E b) {
	return a.cost < b.cost;
}
struct H {
	ld x, y;
};
bool operator<(H a, H b) {
	if (a.x != b.x) return a.x < b.x;
	return a.y < b.y;
}
bool operator>(H a, H b) {
	if (a.x != b.x) return a.x > b.x;
	return a.y > b.y;
}
bool operator==(H a, H b) {
	return a.x == b.x&&a.y == b.y;
}
bool operator!=(H a, H b) {
	return a.x != b.x || a.y != b.y;
}
ll gcm(ll i, ll j) {//最大公約数
	if (i > j) swap(i, j);
	if (i == 0) return j;
	return gcm(j%i, i);
}
ld rad(H a, H b) {
	return sqrt(pow(a.x - b.x, 2.0) + pow(a.y - b.y, 2.0));
}//rad＝座標上の2点間の距離
ll ari(ll a, ll b, ll c) {
	return (a + b)*c / 2;
}//等差数列の和
bool suf(ld a, ld b, ld c, ld d) {
	if (b <= c || d <= a) return 0;
	return 1;
}//[a,b),[c,d)
ll fact(ll i, ll z) {
	ll sum = 1;
	for (ll j = max(z, 2LL); j <= i; j++)
		sum = (sum* j) % Mod;
	return sum;
}//階乗(正）
ll mod_pow(ll x, ll n, ll p) {
	ll res = 1;
	while (n > 0) {
		if (n & 1) res = res*x%Mod;
		x = x*x%p;
		n >>= 1;
	}
	return res;
}
#define int long long
const long long inf = 4523372036854775807;
const int iinf = 1500000000;
//----------------------------------------------------
//++++++++++++++++++++++++++++++++++++++++++++++++++++
H s, t;
H c[1002];
int n;
int r[1002];
ld a[1002];
vector<B>e[1002];
signed main() {
	cin >> s.x >> s.y >> t.x >> t.y >> n;
	for (int i = 1; i <= n; i++) {
		cin >> c[i].x >> c[i].y >> r[i];
		a[i] = inf;
	}
	c[0] = s;
	for (int i = 0; i <= n; i++) {
		for (int j = i + 1; j <= n; j++) {
			ld res = max((ld)0, rad(c[i], c[j]) - (r[i] + r[j]));
			e[i].push_back(B{ j,res });
			e[j].push_back(B{ i,res });
		}
		e[i].push_back(B{ n + 1,max((ld)0,rad(c[i],t) - r[i]) });
	}
	a[n + 1] = inf;
	priority_queue<P, vector<P>, greater<P>>p;
	p.push(P{ 0,0 });
	while (!p.empty()) {
		P t = p.top(); p.pop();
		if (a[t.pos] != t.cost) continue;
		for (int i = 0; i < e[t.pos].size(); i++) {
			if (a[e[t.pos][i].to] > a[t.pos] + e[t.pos][i].cost) {
				a[e[t.pos][i].to] = a[t.pos] + e[t.pos][i].cost;
				p.push(P{ e[t.pos][i].to,a[e[t.pos][i].to] });
			}
		}
	}
	printf("%.15LF\n", a[n + 1]);
	getchar(); getchar();
}

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

const int N = 100005;

int n, a[N];
long long ans = 1e18;

void solve() {
	long long cur = 0;
	int need = 1;
	long long sum = 0;
	for (int i = 1; i <= n; ++i) {
		sum += a[i];
		if (need > 0) {
			if (sum < need) cur += need - sum, sum += need - sum;
		} else {
			if (sum > need) cur += sum - need, sum -= sum - need;
		}
		need = -need;
	}
	ans = min(ans, cur);
}

int main() {
	ios_base::sync_with_stdio(false); cin.tie(0);
	cin >> n;
	for (int i = 1; i <= n; ++i) cin >> a[i];

	solve();
	for (int i = 1; i <= n; ++i) a[i] = -a[i];
	solve();

	cout << ans << endl;
}

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

namespace AOJ
{
  class Problem0027
  {
    static void Main()
    {
      string line;
      while ((line = Console.ReadLine()) != null && line.Trim() != "0 0")
      {
        var sp = line.Split(' ').Select(s => int.Parse(s)).ToArray();
        var dt = new DateTime(2004, sp[0], sp[1]);
        Console.WriteLine(dt.DayOfWeek);
      }
    }
  }
}

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

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;

const ll LongINF=1e13+7;
const int INF=1e9+7;
const int dx[]={0,1,0,-1};
const int dy[]={1,0,-1,0};

template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}
template <class T, class Y>T GCD(T a, Y b){if(a<b){int c=a;a=b;b=c;}if (a % b == 0){return b;}return GCD(b, a % b);}
template<class T,class Y>T LCM(T a,Y b){return (a*b)/GCD(a,b);}
void clear(queue<pair<int, int>> &q){queue<pair<int, int>> empty;swap(q, empty);} //queueの中身の型は適時変更を忘れない

using vi=vector<int>;
using vii=vector<vi>;

#define REP(i,a,b) for(ll i=(a);i<(b);i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define rv reverse
#define ALL(a) (a).begin(),(a).end()
#define decimal(x) fixed<<setprecision(x)


int main(){
    int n,k,ans=0;
    cin>>n>>k;
    vi t(n,0);
    rep(i,k){
        int d;
        cin>>d;
        rep(j,d){
            int a;
            cin>>a;
            a--;
            t[a]++;
        }
    }
    rep(i,n){
        if(t[i]==0)ans++;
    }
    cout<<ans<<endl;
    return 0;
}

//a=97,z=122

Measured memory_bytes: 3604
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <ctype.h>
using namespace std;

int main() {
    int A,B,C; cin >> A >> B >> C;
    for (int i=1;i<=100;i++){
        if (A*i%B==C) {
            cout << "YES" << endl;
            return 0;
        }
    }
    cout << "NO" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  long long int N,W,v[110],w[110],V[110][100010];
  //V[i][j]=i番目までの荷物を使い容量jのナップザックに入れるときの価値合計の最大
  //V[N-1][W]を求める
  cin >> N >> W;
  for(int i=1; i<=N; i++){
    cin >> w[i] >> v[i];
  }

  //i=0のときV=0
  for(int i=0; i<100010; i++){
    V[0][i]=0;
  }

  for(int i=1; i<=N; i++){
    for(int j=0; j<=W; j++){
      if(j-w[i]<0){
        V[i][j]=V[i-1][j];
      }else{
        V[i][j]=max(V[i-1][j],V[i-1][j-w[i]]+v[i]);
      }
    }
  }
  cout << V[N][W] << endl;
}  

Measured memory_bytes: 80768
use std::io::*;

const SP: u8 = b' ';
const LF: u8 = b'\n';

struct CharacterInput<'a> {
    locked_stdin: StdinLock<'a>,
    bytes_buffer: Vec<u8>,
}

impl<'a> CharacterInput<'a> {
    fn read(&mut self, delimiter: u8) -> &[u8] {
        self.bytes_buffer.clear();

        let mut len = self
            .locked_stdin
            .read_until(delimiter, &mut self.bytes_buffer)
            .unwrap();

        if len > 0 {
            len -= 1;
        }

        &self.bytes_buffer[0..len]
    }

    fn scan_u(&mut self, delimiter: u8) -> u32 {
        self.read(delimiter)
            .into_iter()
            .fold(0, |accumulator, byte| {
                (byte - b'0') as u32 + accumulator * 10
            })
    }
}

fn create_cin<'a>(input: StdinLock<'a>, buffer_capacity: usize) -> CharacterInput {
    CharacterInput {
        locked_stdin: input,
        bytes_buffer: Vec::with_capacity(buffer_capacity),
    }
}

fn println<T: std::string::ToString>(s: T) {
    println!("{}", s.to_string());
}

// ------------------------------------------------------------------------

#[derive(Copy, Clone)]
struct Task {
    duration: u32,
    limit: u32
}

fn main() {
    let cin = stdin();
    let cin = &mut create_cin(cin.lock(), 64);

    let n = cin.scan_u(LF) as usize;

    let mut tasks: Vec<Task> = (0..n).map(|_| Task { duration: cin.scan_u(SP), limit: cin.scan_u(LF) }).collect();
    tasks.sort_by(|a, b| a.limit.partial_cmp(&b.limit).unwrap());

    let mut accumulated_duration: u32 = 0;

    for task in tasks.into_iter() {
        accumulated_duration += task.duration;
        if accumulated_duration > task.limit {
            println("No");
            return;
        }
    }

    println("Yes");
}


Measured memory_bytes: 6396
#include <iostream>
#include <vector>
#include <cstring>
#include <bitset>

#define INF 1 << 30

using namespace std;

int N, A, B, C;
vector<int> ls;
vector<int> bs;

int main(void) {
  while (cin >> N >> A >> B >> C && N) {
    ls = vector<int>(N);
    for (int i = 0; i < N; i++) cin >> ls[i];

    long long ans = INF;
    for (long long dp = 0; dp < (1 << (2 * N)); dp++) {
      bs = vector<int>(3);
      bs[0] = A;
      bs[1] = B;
      bs[2] = C;

      long long cost = -30;
      for (int i = 0; i < N; i++) {
        int state = (dp >> (2 * i)) & 0b11;
        if (state == 0b11) continue;
        bs[state] -= ls[i];
        cost += 10;
      }
      if (bs[0] == A || bs[1] == B || bs[2] == C) continue;

      for (int i = 0; i < 3; i++) cost += abs(bs[i]);

      //bitset<16> a(dp);
      //cout << a << ": " << cost << endl;

      ans = min(ans, cost);
    }

    cout << ans << endl;
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, from, to) for (int i = from; i < (to); ++i)
#define mp(x,y) make_pair(x,y)
#define all(x) (x).begin(),(x).end()
#define pb push_back
using ll = long long;
using vin=vector<int>;
using vll=vector<ll>;
using vst=vector<string>;
using P = pair<int, int>;
const int inf=1e9+7;
const ll INF=1e18;
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chmax(T &a, T b) { a = max(a, b); }
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
const int dx[4] = { 1, 0, -1, 0 };
const int dy[4] = { 0, 1, 0, -1 };


int main(){cout<<fixed<<setprecision(10);
           string s;
           cin>>s;
           bool ans=false;
           rep(i,0,s.size()-1){
            if(s[i]=='A'&&s[i+1]=='C')ans=true; 
               
           }
           Yes(ans);
}

Measured memory_bytes: 3600
#pragma region template
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
using vld = vector<ld>;
using vvld = vector<vld>;
using vvvld = vector<vvld>;
using vs = vector<string>;
using pll = pair<ll, ll>;
using vp = vector<pll>;
template <typename T>
using pqrev = priority_queue<T, vector<T>, greater<T>>;
#define rep(i, n) for (ll i = 0, i##_end = (n); i < i##_end; i++)
#define repb(i, n) for (ll i = (n)-1; i >= 0; i--)
#define repr(i, a, b) for (ll i = (a), i##_end = (b); i < i##_end; i++)
#define reprb(i, a, b) for (ll i = (b)-1, i##_end = (a); i >= i##_end; i--)
#define ALL(a) (a).begin(), (a).end()
#define SZ(x) ((ll)(x).size())
//
constexpr ll MOD = 1e9 + 7;
/*/
const ll MOD = 998244353;
//*/
constexpr ll INF = 1e+18;
constexpr ld EPS = 1e-12L;
constexpr ld PI = 3.14159265358979323846L;
constexpr ll GCD(ll a, ll b) { return b ? GCD(b, a % b) : a; }
constexpr ll LCM(ll a, ll b) { return a / GCD(a, b) * b; }
template <typename S, typename T>
inline bool chmax(S &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <typename S, typename T>
inline bool chmin(S &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
#ifdef OJ_LOCAL
#include "dump.hpp"
#else
#define dump(...) ((void)0)
#endif
template <typename T>
bool print_(const T &a) {
  cout << a;
  return true;
}
template <typename T>
bool print_(const vector<T> &vec) {
  for (auto &a : vec) {
    cout << a;
    if (&a != &vec.back()) {
      cout << " ";
    }
  }
  return false;
}
template <typename T>
bool print_(const vector<vector<T>> &vv) {
  for (auto &v : vv) {
    for (auto &a : v) {
      cout << a;
      if (&a != &v.back()) {
        cout << " ";
      }
    }
    if (&v != &vv.back()) {
      cout << "\n";
    }
  }
  return false;
}
void print() { cout << "\n"; }
template <typename Head, typename... Tail>
void print(Head &&head, Tail &&... tail) {
  bool f = print_(head);
  if (sizeof...(tail) != 0) {
    cout << (f ? " " : "\n");
  }
  print(forward<Tail>(tail)...);
}
#pragma endregion

vvll g;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(20);
  ll n;
  cin >> n;
  vll a(n-1);
  rep(i, n-1){
    cin >> a[i];
    --a[i];
  }
  g.resize(n);
  rep(i, n-1){
    g[i+1].emplace_back(a[i]);
    g[a[i]].emplace_back(i+1);
  }
  vector<bool> visited(n, false);
  vll res(n);
  auto dfs = [&](auto& Self, int node) -> ll{
    visited[node] = true;
    vll lst;
    for(auto&& e: g[node]){
      if(!visited[e]){
        lst.emplace_back(Self(Self, e));
      }
    }
    if(lst.empty()) return res[node] = 0;
    sort(ALL(lst));
    reverse(ALL(lst));
    rep(i, SZ(lst)){
      lst[i] += i;
    }
    return res[node] = *max_element(ALL(lst))+1;
  };
  dfs(dfs, 0);
  print(res[0]);
}


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

typedef long long LL;
typedef pair<int, int> II;

int main() {
	int n; scanf("%d", &n);
	map<int, int> a;
	for (int i = 1; i <= n; ++i) {
		int x; scanf("%d", &x);
		a[x]++;
	}

	map<int, int> b = a;
	for (map<int, int>::iterator it = a.begin(); it != a.end(); ++it)
		if (it->second < 2) b.erase(it->first);
	a = b;

	LL ans = 0; vector<int> x;
	for (map<int, int>::iterator it = a.begin(); it != a.end(); ++it) {
		int r = it->first;
		if (it->second >= 4) ans = max(ans, (LL) r * r);
		x.push_back(r);
	}

	if (x.size() >= 2) ans = max(ans, (LL) x[(int) x.size() - 1] * x[(int) x.size() - 2]);
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 9600
from collections import deque
 
n = int(input())
path = {}
for i in range(n-1):
    a, b, c = list(map(int, input().split()))
    if not a in path.keys():
        path[a] = [(b, c)]
    else:
        path[a].append((b, c))
        
    if not b in path.keys():
        path[b] = [(a, c)]
    else:
        path[b].append((a, c))
q, k = list(map(int, input().split()))
xy = [list(map(int, input().split())) for _ in range(q)]

dist = [None]*(n+1)
dist[k] = 0
que = deque([(k, 0)])
while len(que) > 0:
    node, d = que.popleft()
    dist[node] = d
    for node_next, d_next in path[node]:
        if dist[node_next] is None:
            que.append((node_next, d+d_next))
# print(dist)
 
for x, y in xy:
    print(dist[x]+dist[y])

Measured memory_bytes: 78052
#include<bits/stdc++.h>
using namespace std;
int n, h, ans;
string s;
int main(){
    cin >> s;
    for(int i = 0; i < s.size(); i++) if(i%2 == s[i] - '0') ans++;
    printf("%d\n", min(ans, (int)s.size() - ans));
}

Measured memory_bytes: 512
#include <iostream>
#include <string>
#include <cstdlib>
#include <vector>
#include <array>
#include <map>
#include <algorithm>
#include <queue>
#include <stack>
#include <cmath>

using namespace std;
typedef long long int ll;

int main(int argc, char const *argv[])
{
    ll n, q;
    cin >> n >> q;
    string s;
    cin >> s;
    vector<ll> v(1, 0);
    ll temp = 0;
    for (ll i = 1; i < n; i++)
    {
        if (s[i - 1] == 'A')
        {
            if (s[i] == 'C')
            {
                temp++;
            }
        }
        v.push_back(temp);
    }

    for(ll i = 0; i < q; i++)
    {   
        ll l, r;
        cin >> l >> r;

        cout << v[r - 1] - v[l - 1] << endl;
    }
    
}

Measured memory_bytes: 1908
package main

import (
	"fmt"
)

func main() {

	var a, b int
	var c []int

	fmt.Scan(&a)

	for i := 0; i < a; i++ {
		fmt.Scan(&b)

		c = append(c, b)
	}

	fmt.Printf("%d", c[len(c)-1])

	for i := len(c) - 2; i >= 0; i-- {
		fmt.Printf(" %d", c[i])
	}

	fmt.Print("\n")

}



Measured memory_bytes: 1128
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N;cin>>N;vector<int>A(N),B(N);
  for(int X=0;X<N;X++){
    cin>>A[X];B[X]=A[X];
  }
  sort(B.begin(),B.end());
  int H=0;
  for(int X=0;X<N;X++){
    if(A[X]!=B[X]){
      H++;
    }
  }
  if(H==2||H==0)cout<<"YES"<<endl;
  else cout<<"NO"<<endl;
}

Measured memory_bytes: 3532
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <map>
#include <stack>
#include <queue>
#include <iomanip>
#include <set>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;

int main()
{
    int n;
    cin >> n;
    vector<string> s(n);
    for (int i = 0; i < n; ++i) cin >> s[i]; 
    ll ab = 0, lb = 0, ra = 0;
    ll ans = 0;
    for (int i = 0; i < n; ++i)
    {
        if (s[i][0] == 'B' && s[i][s[i].size() - 1] == 'A') ++ab;
        else if (s[i][0] == 'B') ++lb;
        else if (s[i][s[i].size() - 1] == 'A') ++ra;
        for (int k = 0; k < s[i].size() - 1; ++k)
        {
            if (s[i][k] == 'A' && s[i][k + 1] == 'B')
                ++ans;
        }
    }

    if (ab == 0)
    {
        ans += min(ra, lb);
    }
    else if (ab > 0 && ra + lb > 0)
    {
        ans += min(ra, lb) + ab;
    }
    else if (ab > 0 && ra + lb == 0)
    {
        ans += ab - 1;
    }
    cout << ans << endl; 
    return 0;
}


Measured memory_bytes: 3680
def main():
    N = int(input())
    H = [int(f) for f in input().split()]

    for i in range(len(H)):
        if i == 0:
            continue
        if H[i] > H[i-1]:
            H[i] -= 1
        elif H[i] == H[i-1]:
            continue
        else:
            print("No")
            exit()
    print("Yes")

    
if __name__ == "__main__":
    main()

Measured memory_bytes: 14396
using System;
using System.Collections.Generic;
class Program
{
	static void Main(string[] args)
	{
		string[] str = Console.ReadLine().Split();
		int A = int.Parse(str[0]);
		int B = int.Parse(str[1]);
		string str2 = Console.ReadLine();
		string ans = "Yes";
		for(var i=0;i<A;i++){
			if(str2.Substring(i,1)=="-"){
				ans = "No";
				break;
			}
		}
		if(str2.Substring(A,1)!="-"){
			ans = "No";
		} else {
			for(var i=A+1;i<A+1+B;i++){
				if(str2.Substring(i,1)=="-"){
					ans = "No";
					break;
				}
			}
		}
		Console.WriteLine(ans);
	}
}

Measured memory_bytes: 11092
#include<bits/stdc++.h>
using namespace std;
int a[4][4];
int main(){
	
    for(int i = 1; i<= 3;i++) {
        for(int j = 1;j <= 3;j ++) {
            cin>>a[i][j];
        }
    }
    for(int k = -100;k <= 100;k++) {
        int a2,a3,b1,b2,b3;
        int a1 = k;
        b1 = a[1][1] - k;
        b2 = a[1][2] - k;
        b3 = a[1][3] - k;
        a2 = a[2][1] - b1;
        a3 = a[3][1] - b1;
        bool flg = false;
        if(a[2][2] != a2 + b2) flg = true;
        if(a[2][3] != a2 + b3) flg = true;
        if(a[3][2] != a3 + b2) flg = true;
        if(a[3][3] != a3 + b3) flg = true;
        if(!flg) {
            cout<<"Yes"<<endl;return 0;
        }

    }
    cout<<"No"<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define P pair<ll,ll>
#define FOR(I,A,B) for(ll I = ll(A); I < ll(B); ++I)
#define FORR(I,A,B) for(ll I = ll((B)-1); I >= ll(A); --I)
#define TO(x,t,f) ((x)?(t):(f))
#define SORT(x) (sort(x.begin(),x.end())) // 0 2 2 3 4 5 8 9
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin()) //xi>=v  x is sorted
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin()) //xi>v  x is sorted
#define NUM(x,v) (POSU(x,v)-POSL(x,v))  //x is sorted
#define REV(x) (reverse(x.begin(),x.end())) //reverse
ll gcd_(ll a,ll b){if(a%b==0)return b;return gcd_(b,a%b);}
ll lcm_(ll a,ll b){ll c=gcd_(a,b);return ((a/c)*(b/c)*c);}
#define NEXTP(x) next_permutation(x.begin(),x.end())
const ll INF=ll(1e16)+ll(7);
const ll MOD=1000000007LL;
#define out(a) cout<<fixed<<setprecision((a))
//tie(a,b,c) = make_tuple(10,9,87);
#define pop_(a) __builtin_popcount((a))
ll keta(ll a){ll r=0;while(a){a/=10;r++;}return r;}





int main(){

  string s,t;
  ll ans = MOD;

  cin >> s >> t;

  ll ss = s.size();
  ll ts = t.size();

  FOR(i,0,ss-ts+1){
    ll cnt = 0;
    FOR(j,0,ts){
    cnt += s[i+j] != t[j];
    }
    ans = min(ans,cnt);
  }

  cout << ans << endl;

}



Measured memory_bytes: 3608
import java.io.PrintWriter
val pw = PrintWriter(System.out)

fun main(args : Array<String>) {
    func()
    pw.flush()
}

fun func() {
    println(when {
        next().toList().groupBy { it }.values.none { it.size % 2 == 1 } -> "Yes"
        else -> "No"
    })
}

fun next() = readLine()!!

fun println(value : Any) {
    pw.println(value)
}

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

#define fi first
#define sd second
#define lson (nd<<1)
#define rson (nd+nd+1)
#define PB push_back
#define mid (l+r>>1)
#define MP make_pair
#define SZ(x) (int)x.size()

using namespace std;

typedef long long LL;

typedef vector<int> VI;

typedef pair<int,int> PII;

inline int read(){
    int res=0, f=1;char ch=getchar();
    while(ch<'0'|ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){res=res*10+ch-'0';ch=getchar();}
    return res*f;
}

const int MAXN = 200005;

const int MOD = 1000000007;

void addmod(int& a, int b){a+=b;if(a>=MOD)a-=MOD;}
int mulmod(int a, int b){return 1ll*a*b%MOD;}

#define go(e,u) for(int e=head[u];e;e=Next[e])
int to[MAXN<<1],Next[MAXN<<1],head[MAXN],tol;

void add_edge(int u,int v){
    Next[++tol]=head[u];to[tol]=v;head[u]=tol;
    Next[++tol]=head[v];to[tol]=u;head[v]=tol;
}

int ans[MAXN];

int cnt[MAXN], pre[MAXN], tp[MAXN];

int sz[MAXN];

int fac[MAXN], inv[MAXN], n;

int powmod(int x, int y){
    int res=1;
    while(y){
        if(y&1)res=1ll*res*x%MOD;
        y>>=1;
        x=1ll*x*x%MOD;
    }

    return res%MOD;
}

void init(){
    fac[1]=fac[0]=1;
    for(int i=2;i<=n;++i)fac[i]=1ll*fac[i-1]*i%MOD;
    inv[0]=inv[1]=1;
    for(int i=2;i<=n;++i)inv[i]=1ll*MOD-1ll*MOD/i*inv[MOD%i]%MOD;
    for(int i=2;i<=n;++i)inv[i]=1ll*inv[i-1]*inv[i]%MOD;
}

int C(int n, int m){
    return 1ll*fac[n]*inv[m]%MOD*inv[n-m]%MOD;
}

void dfs1(int u, int f){
    sz[u]=1;pre[u]=1;
    go(e,u){
        int v=to[e];
        if(v==f) continue;
        dfs1(v,u);
        sz[u]+=sz[v];
        pre[u]=1ll*pre[u]*pre[v]%MOD*C(sz[u]-1,sz[v])%MOD;
    }
}

void dfs2(int u, int f){
    ans[u]=1ll*tp[u]*pre[u]%MOD*C(n-1,n-sz[u])%MOD;
    go(e,u){
        int v=to[e];
        if(v==f)continue;
        tp[v]=1ll*ans[u]*powmod(1ll*pre[v]*C(n-1,sz[v])%MOD,MOD-2)%MOD;
        dfs2(v,u);
    }
}

int main(){
    n=read();
    for(int i=1;i<n;++i){
        int u, v;
        u=read();
        v=read();
        add_edge(u,v);
    }

    init();
    dfs1(1,0);
    tp[1]=1;
    dfs2(1,0);

    for(int i=1;i<=n;++i)cout<<ans[i]<<endl;

    return 0;
}


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

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    
    int n;
    static int64_t a[100001];
    cin >> n;
    for(int i=0;i<=n;++i) cin >> a[i];

    if(n == 0){
        if(a[0] == 1) cout << 1 << endl;
        else cout << -1 << endl;
        return 0;
    }
    if(a[0] != 0){ cout << -1 << endl; return 0; }
    int64_t pinf = INT64_MAX / 3;
    static int64_t dp[100001];
    dp[0] = 1;
    for(int i=1;i<=n;++i){
        dp[i] = (dp[i-1] - a[i-1]) * 2;
        if(dp[i] > pinf) dp[i] = pinf;
        if(i < n && dp[i] <= a[i]){ cout << -1 << endl; return 0; }
    }
    if(dp[n] < a[n]){ cout << -1 << endl; return 0; }
    dp[n] = a[n];
    for(int i=n-1;i>=0;--i){
        int64_t cand = a[i] + dp[i+1];
        if(cand < dp[i]) dp[i] = cand;
        else if(cand >= dp[i]) goto l_ok;
    }
    l_ok:
    int64_t ans = 0;
    for(int i=0;i<=n;++i) ans += dp[i];
    cout << ans << endl;
    
    return 0;
}

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

using namespace std;

int main() {

    int n,m;
    cin>>n>>m;

    vector<vector<int>> res(m,vector<int>(2,0));
    vector<int> num;

    for(int i = 0 ;i < (n - 1)/2;i++)
    {
        if(i % 2 == 0)
            num.push_back(n - 1 -i);
        else
            num.push_back(i + 1);
    }
    sort(num.rbegin(), num.rend());

    for(int i = 0;i<m;i++)
    {
        res[i][1] = n - i;
        res[i][0] = n - i - num[i];
        cout<< res[i][0]<<" "<<res[i][1]<<endl;
    }

    return 0;
}


Measured memory_bytes: 8608
n=[int(i) for i in input().split()]
m=[int(j) for j in input().split()]
a=sum(m)*1/(4*n[1])
l=[]
for k in m:
    if k>=a:
        l.append(k)

if len(l)>=n[1]:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3060
#include<stdio.h>

int ctoi(char c){
  return (int)c-48;
}

void run(int n,char c){
  int i;
  for(i=0;i<n;i++){
    printf("%c",c);
  }
}

void doit(char *s){
  int i=0;
  while(s[i]!='\0'){
    if(s[i]=='@'){
      run(ctoi(s[i+1]),s[i+2]);
      i+=3;
    }
    else{
      printf("%c",s[i]);
      i++;
    }
  }
  printf("\n");
}

int main(){
  char s[101];
  while(scanf("%s",s)!=EOF){
    doit(s);
  }
  return 0;
}

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

int main() {
  int A, B, C, D;
  cin >> A >> B >> C >> D;
  
  if (A + B > C + D){
    cout << "Left" << endl;
  }
  
  if (A + B == C + D){
    cout << "Balanced" << endl;
  }
  
  if (A + B < C + D){
    cout << "Right" << endl;
  }
}

Measured memory_bytes: 3652
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>

using namespace std;

int main() {
	int X;
	cin >> X;
	int prime;
	while (true) {
		bool ok = true;
		int root_X = sqrt(X);
		for (int i = 2; i <= root_X; i++) {
			if (X % i == 0) {
				ok = false;
			}
		}
		if (ok) {
			prime = X;
			break;
		}
		X++;
	}
	cout << prime << endl;
	return 0;
}

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


int main()
{
    int n,k;
    cin>>n>>k;
    long long int h[n];
    for(int i=0;i<n;i++ ) cin>>h[i];
    sort(h,h+n);
    long long int atk=0;
    for(int j=0;j<n-k;j++)
    {
        atk+=h[j];
    }
    cout<<atk<<endl;
}

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

using namespace std;

#define ll long long

int main(void){
    int a, b;
    cin >> a >> b;

    int ans  = a-2*b;
    if(ans < 0){
        cout << "0" << endl;
    }else{
        cout << ans << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include<queue>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<vector>
#include<cmath>
using namespace std;

typedef long long LL;
typedef double DL;

const int INF = 2147483647;

int d,n;

inline int getint()
{
    int ret = 0,f = 1;
    char c = getchar();
    while (c < '0' || c > '9') 
    {
        if (c == '-') f = -1;
        c = getchar();
    }
    while (c >= '0' && c <= '9')
        ret = ret * 10 + c - '0',c = getchar();
    return ret * f;
}

int main()
{
    #ifdef AMC
        freopen("AMC1.txt","r",stdin);
//        freopen("AMC2.txt","w",stdout);
    #endif
    d = getint(); n = getint();
    int x = 1;
    for (int i = 1; i <= d; i++)
    	x *= 100;
    int ans;
    if (n == 100) ans = 101 * x;
	else ans = n * x;
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 128