akhauriyash/Code-Regression huggingface dataset:
#pragma warning(disable:4996)

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define _USE_MATH_DEFINES
#include <math.h>
#include <float.h>

#pragma region 定義
typedef long long  ll;
typedef unsigned long long  ull;


#define _itoa(A,N) sprintf(A, "%d", N);

int i_dsort(const void* a, const void* b);
int i_asort(const void* a, const void* b);

int  _gcd(int a, int b);
int  _swp(int* a, int* b);
int _cknum(char* a, int n);
int _atoi(char* s, int len);

int s_asort(const void* a, const void* b);
int s_dsort(const void* a, const void* b);

//昇順
int s_asort(const void* a, const void* b) {
	return(strcmp((char*)a, (char*)b));
}
int s_dsort(const void* a, const void* b) {
	return(strcmp((char*)b, (char*)a));
}

int i_dsort(const void* a, const void* b) {
	return(*(int*)b - *(int*)a);
}
int i_asort(const void* a, const void* b) {
	return(*(int*)a - *(int*)b);
}

int _gcd(int a, int b) {
	int r, tmp;
	if (a < b) { tmp = a; a = b; b = tmp; }
	r = a % b;
	while (r) {
		if (!r) break;
		a = b; b = r;
		r = a % b;
	}
	return(b);
}
// puts("Yes\n") puts("No\n")
// scanf("%d.%d") 浮動小数点入力を整数２つで得る


//#define pai  3.1415926535 
//#define  _USE_MATH_DEFINES でM_PIが使える

#define deg_rad(X)  (X*(M_PI/180))


int _swp(int* a, int* b)
{
	int tmp;
	tmp = *b; *b = *a; *a = tmp;
	return 0;
}
#define _abs(x) ((x)>0?(x):-(x))
#define _min(x,y) ((x)<(y)?(x):(y))
#define _max(x,y) ((x)<(y)?(y):(x))

int _cknum(char* a, int n) {
	int i;
	char t = '0';

	for (i = 0; i < n; i++) {
		if (a[i] < '0' || a[i]>'9') return 1;
	}
	return 0;
}


int _atoi(char* s, int len) {
	char tmp[20];
	memcpy(tmp, s, len);
	tmp[len] = 0x00;
	return (atoi(tmp));
}

//素因数分解　pf素数が入る　pc 素数の数
ll _pfact(ll a);
static ll pf[100000000];
static ll pc;

ll _pfact(ll a) {
	long i, r;
	if (a % 2 == 0) {
		pf[pc] = 2; pc++;
		return(_pfact(a / 2));
	}
	r = sqrt(a);
	for (i = 3; i <= r; i += 2) {
		if (a % i == 0) {
			pf[pc] = i; pc++;
			return(_pfact(a / i));
		}
	}
	if (a != 1) {
		pf[pc] = a; pc++;
	}
	return 0;

}


#pragma endregion

//ABC 165 -B
int main(void) {
	int  i;
	ll   x,a = 100;

	scanf("%lld", &x);

	for(i=0;;i++){
		if(a>=x) break;
		a *= 1.01;
	}
	printf("%d\n", i);
	return 0;
}

Measured memory_bytes: 2152
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<iostream>
#include<queue>
#include<vector>
#include <bitset>
#include <cmath>
#include <limits>
#include <iostream>
#include<stack>
#include<tuple>
using namespace std;
#define INF 1100000000000
#define MAX 100000
#define MOD 100000
typedef long long ll;
typedef pair<int,int> P;
typedef pair<pair<int,int>,int> p;
typedef pair< pair<int,int>, int> p; 
#define bit(n,k) ((n>>k)&1) /*nのk bit目*/
#define rad_to_deg(rad) (((rad)/2/M_PI)*360)

ll dp[110000][3];

int main(){
    int N; cin>>N;
    for(int i=0;i<N;i++){
        int a,b,c; cin>>a>>b>>c;
        for(int j=0;j<3;j++){
            if(j!=0) dp[i+1][0]=max(dp[i+1][0],dp[i][j]+a);
            if(j!=1) dp[i+1][1]=max(dp[i+1][1],dp[i][j]+b);
            if(j!=2) dp[i+1][2]=max(dp[i+1][2],dp[i][j]+c);
        }
    }
    ll ans=0;
    for(int i=0;i<3;i++){
        ans=max(ans,dp[N][i]);
    }
    cout<<ans<<endl;
}



Measured memory_bytes: 2560
#include <iostream>
#include <cstdio>
using namespace std;
int main(){
    int N ,K;
    cin >> N >> K;
    double ans = 0;
    for (int i=1; i<=N; i++){
        double p = 1.0 / N;
        int t = i;
        while(t<K){
            t *= 2;
            p /= 2;                    
        }
        ans += p;
    }
   // cout << ans << endl;
    printf("%.15lf\n", ans);
}

Measured memory_bytes: 256
'use strict'

// inputに入力データ全体が入る
function Main(input) {
  let row = input.split(' ');
  let n = parseInt(row[0], 10);
  let m = parseInt(row[1], 10);
  let r10000 = -1;
  let r5000 = -1;
  let r1000 = -1;
  for(let x = 0; x<= n; x++){
	  for(let y = 0; y<= n; y++){
        let rem = n - x - y;
        let sum = 10000*x + 5000*y + 1000*rem;
        // remのマイナスも許容してたのがよくなかった、0は対象にいれないといけない
        if((sum === m) && (rem > -1)){
        	r10000 = x;
            r5000 = y;
          	r1000 = rem;
          	break;
        }
      }
  }
  console.log('%s',`${r10000} ${r5000} ${r1000}`);
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 9420
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<cmath>
#include<cstdio>
#include<queue>
#include<deque>
#include<map>
#include<stack>
#include<set>
#include<utility>
using namespace std;
typedef pair<int,int> ii;
typedef long long ll;
typedef pair<ll,ll> p;
typedef unsigned long long int ull;
int dy[]={1,0,-1,0};
int dx[]={0,1,0,-1};
const int MAXN=100000;
const int MAXE=100000;
const int MAXV=10000;
const ll INF=2e18;
const ll MOD=1e9+7;

struct UnionFind{
    vector<int> par,rank;
    UnionFind(int n):par(n),rank(n,0){
        for(int i=0;i<n;++i) par[i]=i;
    }
    int root(int x){
        if(par[x]==x) return x;
        return par[x]=root(par[x]);
    }
    void unite(int x,int y){
        int rx=root(x),ry=root(y);
        if(rx==ry) return ;
        if(rank[rx]>rank[ry]) par[ry]=rx;
        else par[rx]=ry;
        if(rank[rx]==rank[ry]) rank[ry]++;
    }
    bool same(int x,int y){
        return root(x)==root(y);
    }
    int cnt(int n){
        int res=0;
        for(int i=0;i<n;++i){
            if(root(i)==i) res++;
        }
        return res;
    }
};

int main(){
    int N;cin>>N;
    vector<int> a(N-1),b(N-1);
    vector<vector<int> > G(N);
    for(int i=0;i<N-1;++i){
        cin>>a[i]>>b[i];
        a[i]--;b[i]--;
        G[a[i]].push_back(b[i]);
        G[b[i]].push_back(a[i]);
    }
    vector<int> c(N);
    for(int i=0;i<N;++i) cin>>c[i];
    sort(c.begin(),c.end(),greater<int>());
    vector<int> res(N,0);
    queue<int> que;
    que.push(0);
    int i=0;
    while(!que.empty()){
        int p=que.front();que.pop();
        res[p]=c[i];
        i++;
        for(auto q:G[p]){
            if(res[q]>0) continue;
            que.push(q);
        }
    }
    int M=0;
    for(int i=1;i<N;++i) M+=c[i];
    cout<<M<<endl;
    for(int i=0;i<N;++i){
        cout<<res[i];
        if(i<N-1) cout<<' ';
    }
    cout<<endl;
    return 0;
}

Measured memory_bytes: 4088
//   _/                _/                 _/_/_/   _/
//_/_/_/_/   _/_/   _/_/_/_/   _/_/    _/       _/_/
// _/     _/    _/   _/     _/    _/  _/_/_/     _/
//_/     _/    _/   _/     _/    _/  _/    _/   _/
// _/_/   _/_/       _/_/   _/_/      _/_/     _/
#include<iostream>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<set>
#include<map>
#include<queue>
#include<vector>
using namespace std;
typedef long long ll;
const int MOD=1e9+7;
const double pi=acos(-1);
const int inf=1e9;
int main() {
  cin.tie(0),cout.tie(0);
  ios::sync_with_stdio(false);
  int a,b,c;
  cin >> a >> b >> c;
  if(a+b+c>=22) {
    cout << "bust" << endl;
  }
  else {
    cout << "win" << endl;
  }
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstdlib>
#include<iostream>
#include<vector>
#include<queue>
#include<bitset>
#include<string>
#include<stack>
#include<set>
#include<unordered_set>
#include<map>
#include<unordered_map>
#include<cstring>
#include<complex>
#include<cmath>
#include<iomanip>
#include<numeric>
#include<algorithm>
#include<list>
#include<functional>
#include<cassert>
#define mp make_pair
#define pb push_back
#define X first
#define Y second
#define y0 y12
#define y1 y22
#define INF 1987654321
#define PI 3.141592653589793238462643383279502884
#define fup(i,a,b,c) for(int (i)=(a);(i)<=(b);(i)+=(c))
#define fdn(i,a,b,c) for(int (i)=(a);(i)>=(b);(i)-=(c))
#define MEM0(a) memset((a),0,sizeof(a));
#define MEM_1(a) memset((a),-1,sizeof(a));
#define ALL(a) a.begin(),a.end()
#define SYNC ios_base::sync_with_stdio(false);cin.tie(0)
using namespace std;
typedef long long ll;
typedef long double ld;
typedef double db;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int, int> Pi;
typedef pair<ll, ll> Pll;
typedef pair<double, double> Pd;
typedef vector<int> Vi;
typedef vector<ll> Vll;
typedef vector<double> Vd;
typedef vector<Pi> VPi;
typedef vector<Pll> VPll;
typedef vector<Pd> VPd;
typedef tuple<int, int, int> iii;
typedef tuple<ll, ll, ll> LLL;
typedef vector<iii> Viii;
typedef vector<LLL> VLLL;
typedef complex<double> base;
const ll MOD = 998244353;
ll POW(ll a, ll b, ll MMM = MOD) {ll ret=1; for(;b;b>>=1,a=(a*a)%MMM)if(b&1)ret=(ret*a)% MMM; return ret; }
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
ll lcm(ll a, ll b) { if (a == 0 || b == 0)return a + b; return a*(b / gcd(a, b)); }
int dx[] = { 0,1,0,-1,1,1,-1,-1 }, dy[] = { 1,0,-1,0,1,-1,1,-1 };

int a[51];
int main() {
	int n;
	scanf("%d",&n);
	fup(i,1,n,1)scanf("%d",a+i);
	int mx=-1,what=-1;
	fup(i,1,n,1)
	{
		if(mx<abs(a[i]))
		{
			mx=abs(a[i]);
			what=i;
		}
	}
	if(a[what]==0)return !printf("0");
	if(a[what]>0)
	{
		printf("%d\n",2*n-1);
		fup(i,1,n,1)
		{
			if(i!=what)printf("%d %d\n",what,i);
			a[i]+=a[what];
		}
		int mx=-1,what=-1;
		fup(i,1,n,1)
		{
			if(mx<a[i])
			{
				mx=a[i];
				what=i;
			}
		}
		printf("%d 1\n",what);
		fup(i,2,n,1)printf("%d %d\n",i-1,i);
	}
	else
	{
		printf("%d\n",2*n-1);
		fup(i,1,n,1)
		{
			if(i!=what)printf("%d %d\n",what,i);
			a[i]+=a[what];
		}
		int mx=1,what=-1;
		fup(i,1,n,1)
		{
			if(mx>a[i])
			{
				mx=a[i];
				what=i;
			}
		}
		printf("%d %d\n",what,n);
		fdn(i,n-1,1,1)printf("%d %d\n",i+1,i);
	}
}

Measured memory_bytes: 256
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <bitset>

using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}

//typedef
//------------------------------------------
typedef long long LL;

typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<string, int> P;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

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

//constant
//--------------------------------------------
const double PI  = acos(-1.0);

//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
const LL MOD = 1e9+7; 
//vector <vector<int>> x(20, vector<int> (20)), y(20,vector<int> (20));
/*int counter_1 (int x) {
    if(x == 0) return 0;
    return counter_1(x >> 1) + (x & 1);
}*/

//int Counter(int x)
/*int factorial(int n) {
    if (n > 0) {
        return n * factorial(n - 1);
    } else {
        return 1;
    }
}*/
int factorial(int n) {
    if (n > 0) {
        return n * factorial(n - 1);
    } else {
        return 1;
    }
}
int main(){
    string s;
    cin >> s;
    bool flg = true;
    if(s[2]!=s[3]) flg=false;
    if(s[4]!=s[5]) flg=false;
    if(flg) cout << "Yes" << endl;
    else cout << "No" << endl;
}
    




Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const long double PI = acos(-1);
typedef long long ll;
typedef pair<int64_t,int64_t> pll;
int dx[]={1,-1,0,0,1,-1,1,-1};
int dy[]={0,0,1,-1,1,-1,-1,1};
#define rep(i,a,b) for (int64_t i = (a); i < (b); i++)
#define REP(i,n) rep(i,0,n)
#define ALL(a) begin(a),end(a)
#define sz(s) (s).size()
#define pb push_back
#define mp make_pair
#define fi first
#define se second




int main()
{
    int n;
    cin>>n;
    vector<vector<ll>>dp(n,vector<ll>(3,0));
    REP(i,3)cin>>dp[0][i];
    int abc[3];
    rep(i,1,n)
    {
        cin>>abc[0]>>abc[1]>>abc[2];
        REP(j,3){
            rep(k,j+1,j+3)
                dp[i][j]=max(dp[i][j],dp[i-1][k%3]+abc[j]);
            //cout<<dp[i][j]<<" ";
        }//cout<<endl;
    }
    //cout<<dp[n-1][0]<<dp[n-1][1]<<dp[n-1][2]<<endl;
    cout<<max({dp[n-1][0],dp[n-1][1],dp[n-1][2]})<<endl;
}

Measured memory_bytes: 5760
import java.util.*;
import java.io.*;

public class Main{
  public static void main(String[] args){
    Scanner scan = new Scanner(System.in);
    int n = scan.nextInt();
    int y = scan.nextInt();
    boolean flag = false;

    outside:for(int i = 0; i <= n; i++){
      for(int j = 0; j <=n-i; j++){
        if(10000*i + 5000*j + 1000*(n-i-j) == y){
          System.out.println(i + " " + j + " " + (n-i-j));
          flag = true;
          break outside;
        }
      }
    }
    if(flag == false){System.out.println((-1) + " " + (-1) + " " + (-1));}
  }
}


Measured memory_bytes: 23252
#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef int ll;
typedef long double ld;
const ll N = 2000005;
char en = '\n';
ll inf = 1e16;
ll mod = 998244353;
ll power(ll x, ll n, ll mod) {
  ll res = 1;
  x %= mod;
  while (n) {
    if (n & 1)
      res = (res * x) % mod;
    x = (x * x) % mod;
    n >>= 1;
  }
  return res;
}
ll pre[N];

bool prime[N];

ld dist(pair<ll, ll> a, pair<ll, ll> b) {
  return sqrt((a.first - b.first) * (a.first - b.first) +
              (a.second - b.second) * (a.second - b.second));
}

int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

  ll n;
  cin >> n;

  ll arr[n + 5][2];
  for (ll i = 1; i <= n; i++) {
    cin >> arr[i][0] >> arr[i][1];
  }

  ll perm[n + 5];
  for (ll i = 1; i <= n; i++)
    perm[i] = i;

  ll cnt = 0;
  ld sum1 = 0;
  do {

    cnt++;
    vector<pair<ll, ll>> curr;

    for (ll i = 1; i <= n; i++)
      curr.push_back({arr[perm[i]][0], arr[perm[i]][1]});

    for (ll i = 0; i < n - 1; i++) {
      sum1 += dist(curr[i], curr[i + 1]);
    }
  } while (next_permutation(perm + 1, perm + n + 1));

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

/*
5
1 2 3 1 2
1
1 5
 */

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

/* 大文字を小文字に変換 */
char tolower(char c) {return (c + 0x20);}
/* 小文字を大文字に変換 */
char toupr(char c) {return (c - 0x20);}

// if('A'<=s[i] && s[i]<='Z') s[i] += 'a'-'A';

/*
string s = "abcdefg"
s.substr(4) "efg"
s.substr(0,3) "abc"
s.substr(2,4) "cdef"

// イテレータ要素のインデックス
distance(A.begin(), itr);
*/

int main()
{
    int N; cin >> N;
    int count = 0;
    for(int i=1; i<=N; i+=2){
        int cnt = 0;
        for(int j=1; j<=i; j++){
            if(i%j == 0) cnt++;
        }
        if(cnt == 8) count++;
    }
    cout << count << endl;
}

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

#ifndef LOCAL
#define cerr dolor_sit_amet
#endif

#define mp make_pair
#define sz(x) ((int)((x).size()))
#define X first
#define Y second
#define all(x) (x).begin(), (x).end()

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair < int , int > ipair;
typedef pair < ll , ll > lpair;
const int IINF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3fll;
const double DINF = numeric_limits<double>::infinity();
const int MOD = 1000000007;
const double EPS = 1e-9;
const double PI = acos(-1.0);
const int DX[] = { 1,  0, -1,  0,  1, -1,  1, -1};
const int DY[] = { 0,  1,  0, -1,  1, -1, -1,  1};
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll sqr(ll x) { return x*x; } ll sqr(int x) { return (ll)x*x; }
double sqr(double x) { return x*x; } ld sqr(ld x) { return x*x; }
mt19937 mmtw(960172);
ll rnd(ll x, ll y) { static uniform_int_distribution<ll> d; return d(mmtw) % (y - x + 1) + x; }

template<typename T> T& updMin(T& a, T const& b) { if (b < a) a = b; return a; }
template<typename T> T& updMax(T& a, T const& b) { if (a < b) a = b; return a; }

// ========================================================================= //

int main() {
    ios::sync_with_stdio(false);

    int n;
    cin >> n;
    multiset<int> s;
    for (int i = 0; i < n; ++i) {
        int x;
        cin >> x;
        s.insert(x);
    }

    int ans = 0;
    while (sz(s) > 1) {
        auto it = s.end();
        --it;
        int x = *it;
        s.erase(it);
        int y = 1;
        while (y <= x)
            y *= 2;
        y -= x;
        it = s.find(y);
        if (it != s.end()) {
            s.erase(it);
            ++ans;
        }
    }
    cout << ans << "\n";

    return 0;
}


Measured memory_bytes: 9600
//#include <bits/stdc++.h>
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <string>
#include <vector>
#include <map>
#include <queue>

using namespace std;

typedef long long ll;
typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<n;++i)
#define mod (ll)(1e9+7)
#define FIX(a) ((a)%mod+mod)%mod
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define fi first
#define se second
#define pb push_back
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
int nmax = 100000;
vector<vector<pair<int,int> > > nei(nmax);
vint node;
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vint bw(n,0);
    bw[0]=1;
    REP(i,n-1){
        int u,v,w;
        cin >> u >> v >> w;
        u--;
        v--;
        nei[u].pb(make_pair(v,w));
        nei[v].pb(make_pair(u,w));
    }
    vint dis(n,0);
    
    node.pb(0);
    while(!node.empty()){
        int t = node.back();
        node.pop_back();
        for(pair<int,int> p : nei[t]){
            int pf = p.fi;
            int ps = p.se;
            if(pf!=0&&dis[pf]==0){
                dis[pf]=dis[t]+ps;
                if(dis[pf]%2==0){
                    bw[pf]=1;
                }else{
                    bw[pf]=0;
                }
                node.pb(pf);
            }
        }
    }
    REP(i,n){
        if(bw[i]==0){
            cout << "0\n";
        }else{
            cout << "1\n";
        }
    }
    return 0;
}

Measured memory_bytes: 7168
def main():
    N, W = (int(i) for i in input().split())
    dp = [0] * (W + 1)
    for _ in range(N):
        v, w = (int(i) for i in input().split())
        for j in range(w, W+1):
            dp[j] = max(dp[j], dp[j-w]+v)
    print(dp[W])


if __name__ == "__main__":
    main()



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

int main(){
  long long a,b,c,k;
  long long tmp1,tmp2,tmp3;
  cin >> a >> b >> c >> k;

  if(k % 2 == 0){
    cout << a - b << endl;
  }else{
    cout << b - a << endl;
  }

  return 0;
}


Measured memory_bytes: 256
#coding uft-8
import copy
a, b, c = map(int,input().split())

def solve(a,b,c):
    ans = 0
    while True:
        if a % 2 == 1 or b % 2 == 1 or c % 2 == 1:
            return ans
        else:
            s = copy.copy(a)
            t = copy.copy(b)
            u = copy.copy(c)
            a = t//2 + u//2
            b = s//2 + u//2
            c = s//2 + t//2
            ans += 1

        

if len(set([a,b,c])) == 1 and a%2==0 and b%2==0 and c%2==0:
    print(-1)
else:
    print(solve(a,b,c))

Measured memory_bytes: 3444
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <list>
#include <vector>
#include <queue>
#include <algorithm>
#include <climits>
#include <cstring>
#include <cmath>
#include <stack>
#include <iomanip>
#include <tuple>
#include <functional>
#include <cfloat>
#include <map>
#include <set>
#include <array>
#include <stdio.h>
#include <string.h>
using ll = long long;
using ull = unsigned long long;
using namespace std;
#define int long long
#define CONTAINS_VEC(v,n) (find((v).begin(), (v).end(), (n)) != (v).end())
#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
#define ARY_SORT(a, size) sort((a), (a)+(size))
#define REMOVE(v,a) (v.erase(remove((v).begin(), (v).end(), (a)), (v).end()))
#define REVERSE(v) (reverse((v).begin(), (v).end()))
#define ARY_REVERSE(v,a) (reverse((v), (v)+(a)))
#define REP(i, n) for (int (i)=0; (i) < (n); (i)++)
#define CONTAINS_MAP(m, a) (m).find((a)) != m.end()
#define CONTAINS_SET(m, a) (m).find((a)) != m.end()
void YesNo(bool b) { cout << (b ? "Yes" : "No") << endl; }
void YESNO(bool b) { cout << (b ? "YES" : "NO") << endl; }


signed main()
{
    int X;
    cin >> X;
    YesNo(X >= 30);
}

 

Measured memory_bytes: 3124
#include <bits/stdc++.h>
using namespace std;
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
#define P(x) cout << (x) << "\n"
#define p(x) cout << (x)
#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
#define vv(type, c, m, n, i) vector<vector<type>> c(m, vector<type>(n, i));
#define rep(i,a,n) for(int i=(a), i##_len=(n); i<i##_len; ++i)
#define rrep(i,a,n) for(int i=(a), i##_len=(n); i>i##_len; --i)
#define len(x) ((int)(x).size())
#define mp make_pair
#define eb emplace_back
#define fi first
#define se second
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<long long> vll;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef complex<double> Point;
typedef Point Vector;
typedef pair<Point, Point> Segment;
typedef Segment Line;
constexpr double EPS = (1e-9L);
enum CCW { ONLINE_FRONT = -2, CLOCKWISE, ON_SEGMENT, COUNTER_CLOCKWISE, ONLINE_BACK };
double dot(const Point& p1, const Point& p2) { return (conj(p1) * p2).real(); }
double cross(const Point& p1, const Point& p2) { return (conj(p1) * p2).imag(); }
constexpr bool eq(double a) { return abs(a) < EPS; }
Point project(Segment s, Point p) {
	Vector base = s.fi - s.se;
	double r = dot(p - s.fi, base) / norm(base);
	return s.fi + base * r;
}
Point reflect(Segment s, Point p) { return p + (project(s, p) - p) * 2.0; }
int ccw(const Point& p1, const Point& p2, const Point& p3) {
	Point a = p2 - p1, b = p3 - p1;
	if (cross(a, b) > EPS) return 1;
	if (cross(a, b) < -EPS) return -1;
	if (dot(a, b) < -EPS) return 2;
	if (norm(a) < norm(b)) return -2;
	return 0;
}
bool intersect(Point &p1, Point &p2, Point &p3, Point &p4) {
	return (ccw(p1, p2, p3) * ccw(p1, p2, p4) <= 0 &&
			ccw(p3, p4, p1) * ccw(p3, p4, p2) <= 0);
}
bool intersect(Segment &s1, Segment &s2) {
	return intersect(s1.fi, s1.se, s2.fi, s2.se);
}
double getDistance(Point &a, Point &b) { return abs(a - b); }
double getDistanceLP(Line &l, Point &p) {
	return abs(cross(l.se - l.fi, p - l.fi) / abs(l.se - l.fi));
}
double getDistanceSP(Segment &s, Point &p) {
	if(dot(s.se - s.fi, p - s.fi) < 0.0) return abs(p - s.fi);
	if(dot(s.fi - s.se, p - s.se) < 0.0) return abs(p - s.se);
	return getDistanceLP(s, p);
}
double getDistance(Segment &s1, Segment &s2) {
	if(intersect(s1, s2)) return 0.0;
	return min(min(getDistanceSP(s1, s2.fi), getDistanceSP(s1, s2.se)),
				min(getDistanceSP(s2, s1.fi), getDistanceSP(s2, s1.se)));
}
int main() {
	cout << setprecision(10) << fixed;
	double x0, y0, x1, y1; cin >> x0 >> y0 >> x1 >> y1;
	Point p0(x0, y0), p1(x1, y1);
	int q; cin >> q;
	int res;
	rep(i, 0, q) {
		cin >> x0 >> y0;
		res = ccw(p0, p1, Point(x0, y0));
		if(res == COUNTER_CLOCKWISE) P("COUNTER_CLOCKWISE");
		else if (res == CLOCKWISE) P("CLOCKWISE");
		else if (res == ONLINE_BACK) P("ONLINE_BACK");
		else if (res == ONLINE_FRONT) P("ONLINE_FRONT");
		else P("ON_SEGMENT");
	}
	return 0;
}

Measured memory_bytes: 3344
#include <bits/stdc++.h>
 
#define ALL(a) (a).begin(), (a).end()
#define llong long long
 
using namespace std;
 
struct E{
	int u,v,w;
 
	E() = default;
	E(int u_, int v_, int w_):u(u_),v(v_),w(w_){}
 
	E rev(){return E(v, u, w);}
 
	bool operator<(const E& rhs)const{
		return w == rhs.w ? u == rhs.u ? v < rhs.v : u < rhs.u : w < rhs.w;
	}
};
 
signed main(){
	int n; cin >> n;
	vector<E> adj(n-1);
	for(auto &e : adj)cin >> e.u >> e.v >> e.w;
	vector<vector<E>> es(n+1);
	for(auto e : adj){
		es[e.u].push_back(e);
		es[e.v].push_back(e.rev());
	}
	vector<bool> color(n+1,false);
	vector<bool> visited(n+1, false);
	queue<int> q;
	q.push(1);
	color[1] = true;
	visited[1] = true;
	while(!q.empty()){
		auto idx = q.front();
		q.pop();
		auto nc = color[idx];
		for(auto e : es[idx]){
			if(visited[e.v])continue;
			if(e.w & 1)color[e.v] = !nc;
			else color[e.v] = nc;
			visited[e.v] = true;
			q.push(e.v);
		}
	}
	for(int i = 1; i <= n; i++){
		cout << color[i] << endl;
	}
			
 
	
 
	return 0;
}

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

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

int dp[2][256];

template <typename T> inline void assign_min(T& x, T v) { if (v < x) x = v; }
template <typename T> inline T square(T x) { return x*x; }

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

    int N, M;
    while (cin >> N >> M, N | M) {
        vector<int> codebook(M);
        vector<int> signals(N+1);
        REP(i, M) cin >> codebook[i];
        REP(i, N) cin >> signals[i+1];

        REP(v, 256) dp[0][v] = 1e8;
        dp[0][128] = 0;

        REP(i, N) {
            int curr = i%2;
            int next = (i+1)%2;
            REP(v, 256) dp[next][v] = 1e8;
            REP(v, 256) {
                REP(j, M) {
                    int value = min(max(v + codebook[j], 0), 255);
                    int diff = value - signals[i+1];
                    assign_min(dp[next][value], dp[curr][v] + square(diff));
                }
            }
        }

        cout << *min_element(dp[N%2], dp[N%2]+256) << '\n';
    }
}

Measured memory_bytes: 3244
#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;

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

    vector<int> cnt(n, 0);
    for (int i = 0; i < n; i++) {
        int a;
        cin >> a;
        cnt[a - 1]++;
    }

    sort(cnt.begin(), cnt.end());

    int res = 0;
    for (int i = 0; i < n - k; i++) {
        res += cnt[i];
    }

    cout << res << endl;
}


Measured memory_bytes: 1024
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <cmath>
#include <numeric>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <time.h>
#include <list>
#include <bitset>

using namespace std;
typedef long long ll;
template<class T=ll> 
T in(){T x;cin>>x;return (x);}
template<class T> 
void print(T &x){cout<<x<<"\n";}
#define rep(i,n) for(int i=0;i<(n);++i)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define reps(x,c) for(auto x:c)
#define all(x) begin(x), end(x)
#define pb(a) emplace_back(a) 
#define mp(a,b) make_pair((a),(b))
#define pl pair<ll,ll>
#define INF 2147483600
#define MOD 1000000007
#define fi first
#define se second
#define dbg(x) cerr << #x"="<< (x) << "\n"
#define dbgv(x) cerr<<#x<<"\n";reps(y,x){cerr<<y<<" ";}cerr<<"\n"

int main(){
  ll n=in(),total=0;
  vector<ll> a(n);  

  rep(i,n){
    scanf("%lld",&a[i]);
    total+=a[i];
  }
  ll snuke=0,ans=INF;
  rep(i,n-1){
    snuke+=a[i];
    ans=min(ans,abs(2*snuke-total));
  }
  dbgv(a);
  print(ans);
  return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define GET_MACRO(_1,_2,_3,_4,_5,_6,_7,_8,NAME,...) NAME
#define pr(...) cerr<< GET_MACRO(__VA_ARGS__,pr8,pr7,pr6,pr5,pr4,pr3,pr2,pr1)(__VA_ARGS__) <<endl
#define pr1(a) (#a)<<"="<<(a)<<" "
#define pr2(a,b) pr1(a)<<pr1(b)
#define pr3(a,b,c) pr1(a)<<pr2(b,c)
#define pr4(a,b,c,d) pr1(a)<<pr3(b,c,d)
#define pr5(a,b,c,d,e) pr1(a)<<pr4(b,c,d,e)
#define pr6(a,b,c,d,e,f) pr1(a)<<pr5(b,c,d,e,f)
#define pr7(a,b,c,d,e,f,g) pr1(a)<<pr6(b,c,d,e,f,g)
#define pr8(a,b,c,d,e,f,g,h) pr1(a)<<pr7(b,c,d,e,f,g,h)
#define prArr(a) {cerr<<(#a)<<"={";int i=0;for(auto t:(a))cerr<<(i++?", ":"")<<t;cerr<<"}"<<endl;}
using namespace std;
using Int = long long;
using _int = int;
using ll = long long;
using Double = long double;
const Int INF = (1LL<<60)+1e9; // ~ 1.15 * 1e18
const Int mod = (1e9)+7;
const Double EPS = 1e-8;
const Double PI = 6.0 * asin((Double)0.5);
using P = pair<Int,Int>;
template<class T> T Max(T &a,T b){return a=max(a,b);}
template<class T> T Min(T &a,T b){return a=min(a,b);}
template<class T1, class T2> ostream& operator<<(ostream& o,pair<T1,T2> p){return o<<"("<<p.first<<","<<p.second<<")";}
template<class T1, class T2, class T3> ostream& operator<<(ostream& o,tuple<T1,T2,T3> t){
  return o<<"("<<get<0>(t)<<","<<get<1>(t)<<","<<get<2>(t)<<")";}
template<class T1, class T2> istream& operator>>(istream& i,pair<T1,T2> &p){return i>>p.first>>p.second;}
template<class T> ostream& operator<<(ostream& o,vector<T> a){Int i=0;for(T t:a)o<<(i++?" ":"")<<t;return o;}
template<class T> istream& operator>>(istream& i,vector<T> &a){for(T &t:a)i>>t;return i;}
//INSERT ABOVE HERE

class Combination{
public:
  typedef long long ll;
  ll N;
  ll mod;
  vector<ll> fac;
  vector<ll> finv;
  vector<ll> inv;
  
  
  Combination(ll N = 1e6,ll mod = 1e9 + 7): N(N), mod(mod), fac(N+1), finv(N+1), inv(N+1){
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for(Int i = 2; i <= N; i++){
      fac[i] = fac[i-1] * i % mod;
      inv[i] = mod - inv[mod%i] * (mod / i) % mod;
      finv[i] = finv[i-1] * inv[i] % mod;
    }
  }

  function<ll(ll,ll)> get = [&](ll n,ll r){
    if( n < r ) return 0LL;
    if( n < 0 || r < 0) return 0LL;
    return fac[n] * (finv[r] * finv[n-r] % mod) % mod;
  };
};
auto nCr = (new Combination())->get;

Int calc(Int N, Int M, Int K){
  Int sum = 0;
  for(Int l=1; l<N; l++){
    Int a = ((N - l) * M % mod) * M % mod;
    Int b = nCr(N * M - 2, K - 2);
    sum += (l * a % mod) * b % mod;
    sum %= mod;
  }
  return sum;
}

signed main(){
  srand((unsigned)time(NULL));
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);

  Int N, M, K;
  cin>>N>>M>>K;
  Int a = calc(N, M, K);
  Int b = calc(M, N, K);
  Int ans = (a + b) % mod;
  cout<<ans<<endl;
  return 0;
}


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

int main()
{
    string S;
    cin >> S;
    int black_counter = 0;
    long long res = 0;
    for (auto s : S)
    {
        if (s == 'W')
        {
            res += black_counter;
        }
        if (s == 'B')
        {
            black_counter++;
        }
    }
    cout << res << endl;
}


Measured memory_bytes: 640
#include <iostream>
#include <string>
#include <algorithm>
#include <map>
#include <set>
#include <vector>
#include <queue>
#include <stack>
#include <cmath>
#define	MOD  1000000007;
#define PI = 3.14159265358979323846;
using namespace std;

static const int N = 51;
static const int MAX = 100000;
static const int NIL = -1;
static const int INF = (1 << 21);

int n;
vector<int> G[N];
int color[N];

void dfs(int r, int c)
{
	stack<int> S;
	S.push(r);
	color[r] = c;

	while (!S.empty())
	{
		int u = S.top();
		S.pop();

		for (int i = 0; i < G[u].size(); i++)
		{
			int v = G[u][i];

			if (color[v] == NIL)
			{
				color[v] = c;
				S.push(v);
			}
		}
	}
}

void assignColor()
{
	int id = 1;

	for (int i = 1; i <= n; i++)
	{
		color[i] = NIL;
	}

	for (int u = 1; u <= n; u++)
	{
		if (color[u] == NIL) {
			dfs(u, id++);
		}
	}
}

int main()
{
	//Input
	int m;
	cin >> n >> m;

	int S[51];
	int T[51];

	for (int i = 0; i < m; i++)
	{
		cin >> S[i] >> T[i];
	}

	int count = 0;
	for (int i = 0; i < m; i++)
	{
		for (int j = 0; j < m; j++)
		{
			G[S[j]].clear();
			G[T[j]].clear();
		}

		for (int j = 0; j < m; j++)
		{
			if (j != i)
			{
				G[S[j]].push_back(T[j]);
				G[T[j]].push_back(S[j]);
			}
		}

		assignColor();

		for (int j = 0; j < m; j++)
		{
			if (color[S[j]] != color[T[j]])
			{
				count++;
			}
		}
	}

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

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int a[100001],ans,cnt;
int main(){
int n;
	scanf("%d",&n);
	for(int i=1;i<=n;i++){
		scanf("%d",&a[i]);
		if(a[i]>a[i-1])cnt=0;
		else cnt++,ans=max(ans,cnt);
	}
	printf("%d",ans);
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
int main() {
    // your code goes here
    #ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    #endif
    ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
    int x;
    cin>>x;
    cout<<!x;


    return 0;
}

Measured memory_bytes: 3648
#include <stdio.h>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>
#include <functional>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef vector<vector<int>> v2int;
typedef vector<vector<vector<int>>> v3int;
typedef vector<ll> vll;
typedef vector<vector<ll>> v2ll;
typedef vector<vector<vector<ll>>> v3ll;
typedef list<int> liint;
typedef pair<int, int> pint;
typedef vector<pair<int, int>> vpint;
typedef vector<pair<ll, ll>> vpll;
typedef vector<pair<ll, int>> vpll_int;
typedef vector<pair<int, ll>> vpint_ll;
typedef set<pair<int, int>> spint;
typedef set<pair<ll, int>> spll;
typedef unordered_map<int, unordered_set<int>> Graph;
const int INF = int(2e9);
const ll LINF = ll(2e9) * ll(2e9);
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
template<class T, class C> void chmax(T& a, C b) { a > b ? : a = b; }
template<class T, class C> void chmin(T& a, C b) { a < b ? : a = b; }



int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int N;
    cin >> N;
    deque<ll> A(N);
    rep(i, N) cin >> A[i];
    sort(A.begin(), A.end(), greater<ll>());
    int t = 1;
    ll ans = 0;
    int i = 0;
    while (t < N) {
        if (i == 0) {
            ans += A[i];
            i++;
            t++;
        }
        else {
            ans += A[i];
            t++;
            if (t >= N) break;
            ans += A[i];
            i++;
            t++;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 4744
import java.util.*;
import java.io.*;
public class Main {
        public static void main(String[] args){
                Scanner sc = new Scanner(System.in);
                Map hs = new HashMap();
                PrintWriter ou = new PrintWriter(System.out);
                String s = sc.next();
                sc.close();
                char[] c = new char[s.length()];
                for(int i = 0 ; i < s.length() ; i++){
                        c[i] = s.charAt(i);
                }
                ou.print("2018/01/" + c[8] + c[9] + "\n");
                ou.flush();
        }
}

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

int n;
vector<ll> a;

bool ok(int idx) {
  ll cur = a[idx];
  for (int i = 0; i < n; ++i) {
    if (i == idx) continue;
    if (a[i] > (cur * 2)) return false;
    cur += a[i];
  }
  return true;
}

int main() {
  cin >> n;
  for (int i = 0; i < n; ++i) {
    ll tmp;
    cin >> tmp;
    a.push_back(tmp);
  }

  sort(a.begin(), a.end());

  int left = -1, right = n;
  while (right - left > 1) {
    int mid = (left + right) / 2;
    if (ok(mid)) right = mid;
    else left = mid;
  }
  int ans = n - right;
  cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 1400
# 入力：N本ある丸太を合計K回切ることができる
N, K = gets.chomp.split.map(&:to_i)

# 入力：N本ある丸太それぞれの長さ
A = gets.chomp.split.map(&:to_i)

# 長さ候補rangeのそれぞれについて、k回で切れるか二分探索
ans = (1 .. A.max).bsearch{|x| A.sum{(_1 - 1) / x} <= K}

# 出力
puts ans

Measured memory_bytes: 29880
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>

#include <iostream>
#include <complex>
#include <string>
#include <algorithm>
#include <numeric>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>

#include <functional>
#include <cassert>

typedef long long ll;
using namespace std;

#ifndef LOCAL
#define debug(x) ;
#else
#define debug(x) cerr << __LINE__ << " : " << #x << " = " << (x) << endl;

template <typename T1, typename T2>
ostream &operator<<(ostream &out, const pair<T1, T2> &p) {
  out << "{" << p.first << ", " << p.second << "}";
  return out;
}

template <typename T>
ostream &operator<<(ostream &out, const vector<T> &v) {
  out << '{';
  for (const T &item : v) out << item << ", ";
  out << "\b\b}";
  return out;
}
#endif

#define mod 1000000007 //1e9+7(prime number)
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define SIZE 200010


int main(){
  int N;
  pair<int, int> p[10];

  cin >> N;

  for (int i=0; i<N; i++) {
    int x, y;
    cin >> x >> y;
    p[i] = {x, y};
  }


  sort(p, p+N);

  double sum = 0;

  do{
    for (int i=0; i<N-1; i++) {
      int dx = p[i].first - p[i+1].first;
      int dy = p[i].second - p[i+1].second;
      sum += sqrt(dx * dx + dy * dy);
    }

  }while(next_permutation(p, p+N));

  for (int i=1; i<=N; i++)
    sum /= i;

  printf("%.10lf\n", sum);

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define INF 2000000000
using namespace std;
typedef long long ll;
int read(){
    int f = 1, x = 0;
    char c = getchar();
    while(c < '0' || c > '9'){if(c == '-') f = -f; c = getchar();}
    while(c >= '0' && c <= '9')x = x * 10 + c - '0', c = getchar();
    return f * x; 
}
string s;
void init(){
    cin >> s;
}
void solve(){
    int l = s.length();
    if (l % 2){
        cout << "No" << endl;
        return ;
    }
    for (int i = 0; i < l; i += 2)
        if (s[i] != 'h' || s[i + 1] != 'i'){
        cout << "No" << endl;
        return ;
    }
    cout << "Yes" << endl;

}
int main(){
    init();
    solve();
    return 0;
}

Measured memory_bytes: 764
import itertools

nums = list(map(int, input().split()))
k = int(input())

indexes = [0,1,2]
flg = False

for com in itertools.combinations_with_replacement(indexes, k):

    nums_calc = nums.copy()

    for val in list(com):
        nums_calc[val] *= 2
    
    if nums_calc[0] < nums_calc[1] and nums_calc[1] < nums_calc[2]:
        flg = True
        break

if flg:
    print('Yes')
else:
    print('No')

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

int main(){
    int n;  cin >> n;
    vector<int> p(n);
    for(int i = 0; i < n; i++) cin >> p[i];
    int ans = 0;
    for(int i = 1; i < n-1; i++){
        if((p[i] >= p[i-1])&&(p[i] <= p[i+1])) ans++;
        if((p[i] <= p[i-1])&&(p[i] >= p[i+1])) ans++;
    }
    cout << ans;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		String [] S = new String [n];
		
		int c_a = 0;
		int c_b = 0;
		int c_ab = 0;
		int count = 0;
		
		for (int i = 0; i<n; i++){
			S [i] = sc.next();
			
			if (S[i].charAt(0)=='B' && S[i].charAt(S[i].length()-1)=='A'){
				c_ab++;
			}

			if (S[i].charAt(0)=='B')
				c_b++;
			
			if (S[i].charAt(S[i].length()-1)=='A')
				c_a++;
			
			int j = 0;
			while (j<S[i].length()-1){
				if (S[i].charAt(j)!='A'){
					j++;
				}
				else {
					if (S[i].charAt(j+1) =='B'){
						count++;
						j++;
					}
					else
						j++;
				}
			}
		}
		sc.close();
		
		if (n==1)
			System.out.println(count);
		
		else if (c_ab!=0 && c_a==c_ab && c_b==c_ab)
			System.out.println(count+c_ab-1);
	
		else
			System.out.println(count+Math.min(c_a, c_b));
	}
}

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

#define ll long long

using namespace std;



int main(){
    int N;
    string S;
    cin >> N;
    cin >> S;
    bool jdg = true;
    int len = S.length();
    if(len % 2 == 1) jdg = false;
    else{
        for(int i = 0; i < S.length()/ 2; i++){
            if(S[i] != S[len/ 2 + i]) {
                jdg = false;
                break;
            }
        }
    }
    (jdg ? cout << "Yes" << endl : cout << "No" << endl);
}

Measured memory_bytes: 256
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, [ $t:tt ]) => {
        {
            let len = read_value!($next, usize);
            (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
        }
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
        n: usize,
        k: usize,
    }
    let x_wo_dashita_toki_no_ok_madeno_coin_furu_kaisu = |x: usize| {
        let mut i = 0;
        let mut j = 1;
        if x >= k {
            return 0;
        }
        loop {
            if x * j >= k {
                return i;
            }
            i += 1;
            j *= 2;
        }
    };
    let x_wo_dashita_toki_no_ok_kakuritsu_no_gyakusu = |x: usize| {
        let count = x_wo_dashita_toki_no_ok_madeno_coin_furu_kaisu(x);
        let mut all = 1;
        for _ in 0..count {
            all *= 2;
        }
        all
    };
    let mut all = 0.0;
    for i in 1..n + 1 {
        all += 1.0 / (n * x_wo_dashita_toki_no_ok_kakuritsu_no_gyakusu(i)) as f64;
    }
    let ans = all;
    println!("{}", ans);
}


Measured memory_bytes: 4352
#include<bits/stdc++.h>
#include<algorithm>
#define ll long long
#define fast_io ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

using namespace std;
int main()
{
    fast_io
    ll t,i,j,n,a,b,c,ans;
    set<ll>color;
    cin>>a>>b>>c;
    color.insert(a);
    color.insert(b);
    color.insert(c);
    cout<<color.size()<<endl;


    return 0;
}





Measured memory_bytes: 3568
N=int(input())
s_n=[int(input()) for i in range(N)]

ans=sum(s_n)
while ans%10==0:
    if s_n==[]:
        ans=0
        break
    ans-=min(s_n)
    if ans%10==0:
        ans+=min(s_n)
        s_n.remove(min(s_n))


print(ans)

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

int toDigit(char ch)
{
    return (ch - '0');
}

int main( )
{
    string s;
    int first, last;
    int is_first_month, is_last_month;
    is_first_month = is_last_month = 0;
    cin >> s;
    first = toDigit(s[0]) * 10 + toDigit(s[1]);
    last = toDigit(s[2]) * 10 + toDigit(s[3]);
    if (first >= 1 && first <= 12) {
        is_first_month = 1;
    }
    if (last >= 1 && last <= 12) {
        is_last_month = 1;
    }
    if (is_first_month == 0 && is_last_month == 0) {
        cout << "NA\n";
    }
    else if (is_first_month == 1 && is_last_month == 1) {
        cout << "AMBIGUOUS\n";
    }
    else if (is_first_month == 1) {
        cout << "MMYY\n";
    }
    else {
        cout << "YYMM\n";
    }
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int n,m,a[200005],b[200005],ans[200005],temp[200005];
void quick_pow(long long k)
{
    for(int i=1;i<=n;++i)
    {
        ans[i]=i;
        b[i]=a[i];
    }
    while(k)
    {
        if(k&1)
        {
            for(int i=1;i<=n;++i)
            {
                temp[i]=b[ans[i]];
            }
            for(int i=1;i<=n;++i)
            {
                ans[i]=temp[i];
            }
        }
        for(int i=1;i<=n;++i)
        {
            temp[i]=b[b[i]];
        }
        for(int i=1;i<=n;++i)
        {
            b[i]=temp[i];
        }
        k>>=1;
    }
    return;
}
int main()
{
    long long k;
    scanf("%d %lld",&n,&k);
    for(int i=1;i<=n;i++)scanf("%d",&a[i]);
    quick_pow(k);
    printf("%d\n",ans[1]);
    return 0;
}

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

#define Max 100000
#define N -1

struct node{
  int l;
  int r;
  int p;
};

 struct node type[Max];
 int D[Max],H[Max];

void setDepth(int u, int d){
  if(u== N) return;
    D[u]=d;
    
    setDepth(type[u].l,d+1);

    
    setDepth(type[u].r,d+1);

}


int setHeight(int u){
  int h1=0,  h2=0;
  if(type[u].l!= N){
    h1=setHeight(type[u].l)+1;
  }

  if(type[u].r!= N) {h2=setHeight(type[u].r)+1;

  }
  return H[u]=(h1>h2? h1:h2);
}

int getSibling(int u){
  if(type[u].p == N){
    return N;}
  
  if(type[type[u].p].l != u && type[type[u].p].l != N)
    {return type[type[u].p].l;
    }
  
  if(type[type[u].p].r != u && type[type[u].p].r != N)
    {
      return type[type[u].p].r; }
  return N;
}

void print(int u){
  printf("node %d: ",u);
  
  printf("parent = %d, ",type[u].p);
  
  printf("sibling = %d, ",getSibling(u));
  int deg=0;
  if(type[u].l!=N) deg++;

  
  if(type[u].r!=N) deg++;
  printf("degree = %d, ",deg);
  printf("depth = %d, ",D[u]);
  
  printf("height = %d, ",H[u]);
  

  if(type[u].p==N){
    printf("root\n");
  }
  
  else if(type[u].l == N && type[u].r == N){
    printf("leaf\n");
  }
  else printf("internal node\n");
  }


int main(){
  int v,l,r,i,n;
  int root=0;
  
  scanf("%d",&n);

  for(i=0;i<n;i++) type[i].p = N;

  for(i=0;i<n;i++){
    scanf("%d%d%d",&v,&l,&r);
    type[v].l=l;
    
    type[v].r=r;
    
    if(l != N) {type[l].p=v;
    }
    
    if(r != N) {
      type[r].p=v;}
  }

  for(i=0;i<n;i++) if(type[i].p == N) root = i;

  setDepth(root,0);
  
  setHeight(root);

  for(i=0;i<n;i++) print(i);

  return 0;
}



Measured memory_bytes: 2128
//g++  7.4.0

#include <iostream>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define MAXN 3005
#define MOD 1000000007
ll dp[MAXN][MAXN];

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    ll N; cin>>N;
    string s; cin>>s;
    
    dp[0][1] = 1;
    for(ll i=1;i<N;++i)
    {
        ll pre[i + 1] = {0};
        for(ll j=1;j<=(i + 1);++j)
            pre[j] = (pre[j - 1] + dp[i - 1][j]) % MOD;
        
        for(ll j=1;j<=(i + 1);++j)
        {
            ll L,R;
            if(s[i - 1] == '<')
            {
                L = 1;
                R = j - 1;
            }
            else
            {
                L = j;
                R = i;
            }
            
            if(L <= R)
                dp[i][j] = (pre[R] - pre[L - 1] + MOD) % MOD;
        }
    }
    
    ll ans = 0;
    for(ll i=1;i<=N;++i)
        ans = (ans + dp[N - 1][i]) % MOD;
    
    cout<<ans<<endl;
}

Measured memory_bytes: 49760