akhauriyash/Code-Regression huggingface dataset:
function MainD(input){
    const arr = input.split('\n');
    const N = arr[0];
    const Ci = arr[1].split('');
    let answer = 0;

    // Wの数を数える
    let Wnum = 0;
    for(let i=0; i<Ci.length; i++){
        if(Ci[i] === 'W'){
            Wnum++;
        }
    }
    if(Wnum===0) return console.log(0); // Wが現れなかったら0を出力

    // Rの数以降のRの数を数える
    for(let i=Ci.length-Wnum; i<Ci.length; i++){
        if(Ci[i] === 'R'){
            answer++;
        }
    }
    console.log(answer);
}
MainD(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 35584
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cstdio>
#include <vector>
#include <utility>
#include <algorithm>
#include <string>
#include <queue>
#include <stack>
#include <tuple>
#include <list>
#include <set>
#include <map>
#include <functional>
#include <cmath>
#include <cstring>
#include <cstdlib>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;

#define xx first
#define yy second
#define $1 first
#define $2 second

void solveCase() {
	ios::sync_with_stdio(false);
	cin.tie(NULL); cout.tie(NULL);
	ll x; cin >> x;
	ll now = 100;
	for (int i = 1; i < 4000; i++) {
		now += ll(now / 100);
		if (now >= x) {
			cout << i;
			return;
		}
	}
}

int main() {

#ifdef _DEBUG
	freopen("input.txt", "r", stdin);
#endif
	solveCase();
}

Measured memory_bytes: 3640
time=[]
for i in range(5):
    temp=[]
    temp.append(int(input()))
    if temp[0]%10==0:
        temp.append(0)
    else:
        temp.append(10-temp[0]%10)
    time.append(temp)
time=sorted(time,key=lambda x:x[1])
sum=0
for i in range(5):
    sum+=time[i][0]
    sum+=time[i][1]
print(sum-time[4][1])

Measured memory_bytes: 3064
n = int(input())
if n >= 64:
    print(64)
elif n >= 32:
    print(32)
elif n >= 16:
    print(16)
elif n >= 8:
    print(8)
elif n >= 4:
    print(4)
elif n >= 2:
    print(2)
else:
    print(1)

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

#define MP make_pair
#define PB push_back
#define ALL(x)      (x).begin(),(x).end()
#define REP(i,n)    for(int i=0;i<(n);i++)
#define REP1(i,n)   for(int i=1;i<(n);i++)
#define REP2(i,d,n) for(int i=(d);i<(n);i++)
#define RREP(i,n)   for(int i=(n);i>=0;i--)
#define CLR(a)      memset((a),0,sizeof(a))
#define MCLR(a)     memset((a),-1,sizeof(a))
#define RANGE(x,y,maxX,maxY) (0 <= (x) && 0 <= (y) && (x) < (maxX) && (y) < (maxY))

typedef long long LL;
typedef unsigned long long ULL;
typedef vector<int> VI;
typedef vector<VI > VVI;
typedef vector<string> VS;
typedef vector<LL> VLL;
typedef pair<int,int> PII;

const int INF = 0x3f3f3f3f;
const LL INFL = 0x3f3f3f3f3f3f3f3fLL;
const double EPS = 1e-9;

const int DX[]={1,0,-1,0},DY[]={0,-1,0,1};


void solve(std::string S, std::string T){
    cout << T << S << endl;
}

int main(){
    std::string S;
    std::cin >> S;
    std::string T;
    std::cin >> T;
    solve(S, T);
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rrep(i,n) for (int i = (n)-1; i >= 0; i--)
#define rep2(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 pb push_back
#define eb emplace_back
#define vi vector<int>
#define vvi vector<vector<int>>
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vd vector<double>
#define vs vector<string>
#define vc vector<char>
#define vb vector<bool>
#define vp vector<P>
using namespace std;
using ll = long long;
using P = pair<int,int>;
using LP = pair<ll,ll>;
template<class S,class T> istream& operator>>(istream &is,pair<S,T> &p) { return is >> p.first >> p.second; }
template<class S,class T> ostream& operator<<(ostream &os,const pair<S,T> &p) { return os<<'{'<<p.first<<","<<p.second<<'}'; }
template<class T> istream& operator>>(istream &is,vector<T> &v) { for(T &t:v){is>>t;} return is; }
template<class T> ostream& operator<<(ostream &os,const vector<T> &v) { os<<'[';rep(i,v.size())os<<v[i]<<(i==v.size()-1?']':','); return os; }
void Yes(bool b) { cout << (b ? "Yes" : "No") << endl; }
void YES(bool b) { cout << (b ? "YES" : "NO") << endl; }
template<class T> bool chmin(T& a,T b) {if(a > b){a = b; return true;} return false;}
template<class T> bool chmax(T& a,T b) {if(a < b){a = b; return true;} return false;}
const int inf = 1001001001;
const ll linf = 1001001001001001001;

class sieve {
    int n;
    vi val;

    void init() {
        rep(i,n+1) val[i] = i;
        for(int i = 2; i*i <= n; i++) {
            if(val[i] != i) continue;
            for(int j = i*2; j <= n; j += i) {
                if(val[j] == j) val[j] = i;
            }
        }
    }

public:
    sieve(int n):n(n),val(n+1) {
        init();
    }
    map<int,int> factorlist(int x) {
        if(n < 2) return {};
        map<int,int> ret;
        int now = x;
        while(now > 1) {
            ret[val[now]]++;
            now /= val[now];
        }
        return ret;
    }
    vi unique_factor(int x) {
        map<int,int> m = factorlist(x);
        vi ret;
        for(P p : m) ret.pb(p.first);
        return ret;
    };
    bool isprime(int x) {
        return x >= 2 and val[x] == x;
    }
    int count_divisor(int x) {
        int ret = 1;
        map<int,int> fl = factorlist(x);
        for(auto p : fl) ret *= p.second+1;
        return ret;
    };
};

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr); cout.tie(nullptr);
    int n;
    cin >> n;
    ll ans = 0;
    sieve sv(n+10);
    rep2(k,1,n+1) {
        ans += ll(k)*sv.count_divisor(k);
    }
    cout << ans << endl;
}

Measured memory_bytes: 42268
#include<bits/stdc++.h>
using namespace std;
 
int main(){
  string N;
  cin >> N;
  int SN,NN;
  SN = atoi(N.c_str());

  for(int i = 0;i<N.size();i++){
      NN +=N[i]-'0';
  }

  


  if( SN % NN== 0){
      cout <<"Yes"<<endl;
      return 0;
  }
  cout <<"No" <<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  
  int N,X;

  cin >> N >> X;

  vector<int> m(N);

  for(int i=0;i<N;i++){
    cin >> m.at(i);
  }//入力終了

  int sumg=0,ming=10000;

  for(int i=0;i<N;i++){
    sumg += m.at(i);

    if(m.at(i) < ming) ming = m.at(i);
  }//全種一つずつ作るための必要粉量と、最も材料が少量なドーナツの特定を同時に行う

  int donuts=N;
  X -= sumg;//N種全てを一つずつ作製
    

  donuts += (X/ming);

 
  cout << donuts << endl;
 
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
using namespace std;
int main(){
  int n,num = 0;
  string s,s1;
  cin >> n >> s;
  for (int i = 0; i < n - 2; i++){
    s1 = s.substr(i, 3);
    if (s1 == "ABC")
      num++;
  }
  cout << num << endl;
}


Measured memory_bytes: 256
"use strict";
    
const main = arg => {
    arg = arg.trim().split("\n");
    const S = parseInt(arg[0].split(" ")[0]);
    const W = parseInt(arg[0].split(" ")[1]);
    
    console.log(S <= W ? "unsafe" : "safe");
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

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

using namespace std;
#define int long long

const int INF = 1 << 30;

int N, M;
int g[17][17];
int lookup[1 << 17];
int dp[1 << 17][16][2];
vector< int > add[1 << 17];

int rec(int mask, int pre, bool get)
{
  if(mask == 0) return (0);
  if(~dp[mask][pre][get]) return(dp[mask][pre][get]);
  int ret = -INF;
  for(int i = mask; i > 0; i = (i - 1) & mask) {
    if(i&1 && (i>>(N-1)) & 1) continue;
    bool nt = get ^ (((i & 1) | ((i >> (N - 1)) & 1)));
    for(auto& j : add[i]) {
      if(g[pre][j] == 0 && get) continue;
      ret = max(ret, rec(mask ^ i, j, nt) + lookup[i] + g[pre][j]);
    }
  }
  return (dp[mask][pre][get] = ret);
}

signed main()
{
  memset(dp, -1, sizeof(dp));

  cin >> N >> M;
  int all = 0;

  for(int i = 0; i < M; i++) {
    int a, b, c;
    cin >> a >> b >> c;
    --a, --b;
    g[a][b] = c;
    g[b][a] = c;
    all += c;
  }
  
  for(int i = 0; i < 1 << N; i++) {
    for(int j = 0; j < N; j++) {
      if((i >> j) & 1) {
        if(i & 1) {
          if(j == 0) add[i].push_back(j);
        } else if((i >> (N - 1)) & 1) {
          if(j == N - 1) add[i].push_back(j);
        } else {
          add[i].push_back(j);
        }
        for(int k = j + 1; k < N; k++) {
          if((i >> k) & 1) lookup[i] += g[j][k];
        }
      }
    }
  }
  cout << all - rec((1 << N) - 1, 15, 0) << endl;
}


Measured memory_bytes: 38528
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 1000000007;
using ll = long long;
using u32 = unsigned;
using u64 = unsigned long long;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;

#define popcnt32 __builtin_popcount
#define popcnt64 __builtin_popcountll

ll pow_ (ll x, ll n, ll M){
    uint64_t u = 1, xx = x;
    while (n > 0){
        if (n&1) u = u * xx % M;
        xx = xx * xx % M;
        n >>= 1;
    }
    return u;
};

int main() {
    int n;
    cin >> n;
    string s;
    cin >> s;
    int M = 300000;
    vector<int> a(M+1);
    for (int i = 1; i <= M; ++i) {
        a[i] = a[i%popcnt32(i)]+1;
    }
    int x = 0, y = 0, val = 0;
    for (int i = 0; i < n; ++i) {
        val += s[i]-'0';
    }
    for (int i = 0; i < n; ++i) {
        x = (x*2 + s[i]-'0')%max(val-1, 1);
        y = (y*2 + s[i]-'0')%(val+1);
    }
    for (int i = 0; i < n; ++i) {
        if(s[i] == '1'){
            if(val == 1) puts("0");
            else {
                int xx = pow_(2, n-i-1, val-1);
                cout << a[(x+val-1-xx)%(val-1)]+1 << "\n";
            }
        }else {
            int yy = pow_(2, n-i-1, val+1);
            cout << a[(y+yy)%(val+1)]+1 << "\n";
        }
    }
    return 0;
}

Measured memory_bytes: 4712
#include<bits/stdc++.h>
using namespace std;
int a[55],n;
long double res;
int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;++i){
		scanf("%d",&a[i]);
	}
	sort(a+1,a+1+n);
	res=a[1];
	for(int i=2;i<=n;++i){
		res=(res+(double)a[i])/2;
	}
	printf("%.8Lf",res);
}

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

template<typename T>
istream& operator >> (istream& istr, vector<T>& vec){
    for(T& x: vec) istr >> x;
    return istr;
}

template<typename T>
ostream& operator << (ostream& ostr, vector<T>& vec){
    if(!vec.empty()){
        ostr << vec.front();
        for(auto itr = ++vec.begin(); itr != vec.end(); itr++)
            ostr << " " << *itr;
    }
    return ostr;
}

template<typename T>
ostream& operator << (ostream& ostr, vector<vector<T>>& mat){
    if(!mat.empty()){
        ostr << mat.front();
        for(auto itr = ++mat.begin(); itr != mat.end(); itr++)
            ostr << endl << *itr;
    }
    return ostr;
}

template<typename T, typename U>
ostream& operator << (ostream& ostr, pair<T,U>& p){
    ostr << p.first << " " << p.second;
    return ostr;
}

template<typename T, typename U>
ostream& operator << (ostream& ostr, vector<pair<T,U>>& mat){
    if(!mat.empty()){
        ostr << mat.front();
        for(auto itr = ++mat.begin(); itr != mat.end(); itr++)
            ostr << endl << *itr;
    }
    return ostr;
}

typedef long long ll;
typedef vector<ll> vll;
typedef vector<char> vc;
// vll x(n); x[i]=a;
typedef vector<vector<ll>> vvll;
typedef vector<vector<char>> vvc;
// vvll x(m,vi(n)); x[i][j]=a;
typedef pair<ll,ll> pll;
typedef vector<pair<ll,ll>> vpll;
// vpll x(n); x[i]={a,b}; x[i].first/second;

#define PI 3.1415926535897932
#define EPS 1e-12
#define REP(i,n) for(ll i=0; i<(n); i++)
#define RREP(i,n) for(ll i=(n)-1; i>=0; i--)
#define FOR(i,a,b) for(ll i=(a); i<(b); i++)
#define FORR(i,a,b) for(ll i=(b)-1; i>=(a); i--)
#define dump(x) cout << #x << " = " << (x) << endl
#define all(x) (x).begin(),(x).end()
// sort(all(x));

int main(){
    ll n, ans = 0;
    cin >> n;
    vll a(n);
    cin >> a;
    sort(all(a));
    REP(i,n-2){
        FOR(j,i+1,n-1){
            ll k = j+1;
            for(k;k<n;k++){
                if(a[i]+a[j] <= a[k]) break;
            }
            ans += k-j-1;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
	int N, x, y, b, p, v1, v2,i1;

	scanf("%d", &N);
	for (i1 = 0; i1 < N; i1++) {
		scanf("%d %d %d %d", &x, &y, &b, &p);
		v1 = x * b + y * p;
		if (b >= 5 && p >= 2)
			v1 = 4 * v1 / 5;
		else {
			if (b < 5)
				b = 5;
			if (p < 2)
				p = 2;
			v2 = 4 * (x * b + y * p) / 5;
			if (v2 < v1)
				v1 = v2;
		}
		printf("%d\n", v1);
	}

	return 0;
}

Measured memory_bytes: 600
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define FOR(i,l,r) for(i=l;i<r;i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(x) x.begin(),x.end()
#define P pair<ll,ll>
#define F first
#define S second
signed main(){
  ll N,M,i,j,ans=0;cin>>N>>M;
  ll a[M],b[M];
  REP(i,M){
    cin>>a[i]>>b[i];a[i]--;b[i]--;
  }
  REP(i,M){
    vector<bool>seen(N,true);
    queue<ll>X;X.push(0);
    while(X.size()){
      ll F=X.front();
      X.pop();
      seen.at(F)=false;
      REP(j,M)if(j!=i){
        if(a[j]==F&&seen.at(b[j]))X.push(b[j]);
        if(b[j]==F&&seen.at(a[j]))X.push(a[j]);
      }
    }
    sort(ALL(seen));
    if(seen.at(N-1))ans++;
  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main () {

	int N;
	cin >> N;

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

		int futsu = x * b + y * p;
		int oome = (x * 5 + y * 2 + x * max(b - 5, 0) + y * max(p - 2, 0)) *8 / 10;

		if (b >= 5 && p >= 2) {
			cout << futsu * 8 / 10 << endl;
		}else if (oome < futsu){
			cout << oome << endl;
		}else {
			cout << futsu << endl;
		}
	}

	return 0;
}

Measured memory_bytes: 1160
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;

const int MAXN = 300;
const int MOD = 998244353;

inline int add(int x, int y) {x += y; return x >= MOD ? x - MOD : x;}
inline int sub(int x, int y) {x -= y; return x < 0 ? x + MOD : x;}
inline int mul(int x, int y) {return (int)(1LL * x * y % MOD);}

int pow_mod(int b, int p) {
	int ret = 1;
	for(int i=p;i;i>>=1,b=mul(b,b))
		if( i & 1 ) ret = mul(ret, b);
	return ret;
}

int comb[2*MAXN + 5][2*MAXN + 5];
int dp[MAXN + 5][MAXN + 5][MAXN + 5];
bool f[MAXN + 5][MAXN + 5][MAXN + 5];
char s[MAXN + 5]; int n;

int main() {
	for(int i=0;i<=2*MAXN;i++) {
		comb[i][0] = 1;
		for(int j=1;j<=i;j++)
			comb[i][j] = add(comb[i-1][j], comb[i-1][j-1]);
	}
	
	scanf("%s", s), n = strlen(s);
	
	for(int i=0;i<=n;i++)
		for(int j=0;j<=n;j++)
			dp[n][i][j] = comb[i + j][i];
	for(int i=n-1;i>=0;i--) {
		for(int j=0;j<=i;j++) {
			for(int k=0;k<=i;k++) {
				dp[i][j][k] = add(dp[i][j][k], dp[i + 1][j][k]);
				if( s[i] == '0' && k ) dp[i][j][k] = add(dp[i][j][k], dp[i][j][k - 1]);
				if( s[i] == '1' && j ) dp[i][j][k] = add(dp[i][j][k], dp[i][j - 1][k]);
			}
		}
	}
	
	f[0][0][0] = true;
	for(int i=0;i<=n;i++) {
		for(int j=i;j>=0;j--) {
			for(int k=i;k>=0;k--) {
				if( j && j + k >= 2 ) f[i][j - 1][k] |= f[i][j][k];
				if( k && j + k >= 2 ) f[i][j][k - 1] |= f[i][j][k];
				
				if( i + 1 <= n ) {
					if( j && s[i] == '1' ) f[i + 1][j - 1][k + 1] |= f[i][j][k];
					if( k && s[i] == '0' ) f[i + 1][j + 1][k - 1] |= f[i][j][k];
					if( j + k ) f[i + 1][j][k] |= f[i][j][k];
				}
				
				if( i + 2 <= n ) {
					if( s[i] == '0' || s[i + 1] == '0' ) f[i + 2][j + 1][k] |= f[i][j][k];
					if( s[i] == '1' || s[i + 1] == '1' ) f[i + 2][j][k + 1] |= f[i][j][k];
				}
			}
		}
	}
	
	int ans = 0;
	for(int i=n;i>=0;i--) {
		for(int j=i;j>=0;j--) {
			for(int k=i;k>=0;k--) {
//				printf("%d %d %d : %d %d\n", i, j, k, f[i][j][k], dp[i][j][k]);
				if( !f[i][j][k] ) continue;
				ans = add(ans, dp[i][j][k]);
				
				int cnt[2] = {};
				for(int l=i-1;l>=0;l--) {
					cnt[s[l] - '0']++;
					if( j < cnt[0] || k < cnt[1] ) break;
					f[l][j - cnt[0]][k - cnt[1]] = false;
				}
			}
		}
	}
	printf("%d\n", ans);
}

Measured memory_bytes: 72972
#include<iostream>
using namespace std;
int main(){
  double v,t,y;
  int sy;
  while(cin>>v){
    t=v/9.8;
    y=4.9*t*t;
    sy=0;
    while(1){
      if((5*sy-5)>y){
	break;
      }
      sy++;
    }
    cout<<sy<<endl;
  }
  return 0;
}

Measured memory_bytes: 1224
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0;i<int(N);++i)
#define rep1(i,N) for(int i=1;i<int(N);++i)
#define all(a) (a).begin(),(a).end()
#define print(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<_<<", "; cerr<<"]"<<endl; }
#define printpair(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<"{"<<_.first<<","<<_.second<<"}"<<", "; cerr<<"]"<<endl; }
#define dump(x) cerr<<#x<<": "<<x<<endl;
#define bit(k) (1LL<<(k))
typedef long long ll;
typedef pair<int, int> i_i;
typedef pair<ll, ll> l_l;
template <class T> using vec = vector<T>;
template <class T> using vvec = vector<vec<T>>;
template< typename T1, typename T2 >
ostream &operator<<(ostream &os, const pair< T1, T2 >& p) {
  os << "{" <<p.first << ", " << p.second << "}";
  return os;
}
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

const int INF = (ll)1e9;
const ll INFLL = (ll)1e18+1;
const ll MOD = (ll)1e9+7;
const double PI = acos(-1.0);
/*
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const string dir = "DRUL";
*/
int N;
int ans;
vector<int> D,times;
map<int, int> mp;
void dfs(int cur){
    if(cur == N){
        int sz = times.size();
        int tmp = INF;
        rep(i,sz)rep(j,sz){
            if(i >= j)continue;
            int d = abs(times[i] - times[j]);
            chmin(tmp, min(d, 24-d));
        }
        chmax(ans, tmp);
        return;
    }
    rep(j,2){
        int add = (j ? 24 - D[cur]: D[cur]);
        times.push_back(add);
        mp[add]++;
        if(mp[add] == 2){
            mp[add]--;
            times.pop_back();
            continue;
        }
        dfs(cur+1);
        mp[add]--;
        times.pop_back();
    }
}
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);

    cin >> N;
    D.resize(N);
    rep(i,N)cin>>D[i];
    ans = 0;
    times.push_back(0);
    mp[0]++;
    dfs(0);
    cout << ans << endl;
}

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

#define REP(i, m, n) for (long long i = (m); i < (long long)(n); i++)
#define rep(i, n) REP(i, 0, n)
#define rrep(i, x) for (long long i = ((long long)(x)-1); i >= 0; i--)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define pb push_back
#define mp make_pair
typedef long long ll;
const ll INF = 1LL << 60;
const 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 (b < a)
    {
        a = b;
        return 1;
    }
    return 0;
}

ll modpow(ll a, ll p)
{
    if (p == 0)
        return 1;
    if (!(p % 2))
    {
        ll halfP = p / 2;
        ll half = modpow(a, halfP);
        return half * half % mod;
    }
    else
    {
        return a * modpow(a, p - 1) % mod;
    }
}

ll comb(long long a, long long b)
{
    if (b > a - b)
        return comb(a, a - b);
    ll ansMul = 1;
    ll ansDiv = 1;
    for (long long i = 0; i < b; i++)
    {
        ansMul *= a - i;
        ansDiv *= i + 1;
        ansMul %= mod;
        ansDiv %= mod;
    }
    ll ans = ansMul * modpow(ansDiv, mod - 2) % mod;
    return ans;
}

/*
long long num = 200010;
vector<ll> fact(num), ifact(num);
fact[0] = 1;
fact[1] = 1;
for (long long i = 2; i < num; i++) {
    fact[i] = fact[i-1] * i;
    fact[i] %= mod;
}
for (long long i = 0; i < num; i++) {
    ifact[i] = modpow(ifact[i], mod-2);
    ifact[i] %= mod;
}
*/

int main() {
    long long N, T; cin >> N >> T;
    vector<long long> A(N), nums;
    rep(i, N) cin >> A[i];
    long long l = A[0];
    long long r = A[0];
    rep(i, N) {
        if (l < A[i]) {
            r = max(r,A[i]);
        } else if (l > A[i]) {
            nums.pb(r - l);
            r = A[i];
            l = A[i];
        }
        if (i == N - 1) {
            if (r - l > 0) {
                nums.pb(r - l);
            }
        }
    }
    sort(rall(nums));
    long long x = nums[0];
    long long cnt = 0;
    while (x == nums[cnt]) cnt++;

    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 1660
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
*/public class Main {
	public static void main(String[] args) {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		Scanner in = new Scanner(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		TaskC solver = new TaskC();
		solver.solve(1, in, out);
		out.close();
	}
static class TaskC   {
public void solve(int testNumber, Scanner in, PrintWriter out) {
        int N = in.nextInt();
        int A[] = new int[N];
        for (int i=0; i<N; i++) {
            A[i] = in.nextInt();
        }

        while(true){
            Arrays.sort(A);
            if(A[N-2] == 0){
                break;
            }
            int idx = 0;
            while(A[idx] == 0){
                idx++;
            }
            for (int i=idx+1; i<=N-1; i++) {
                A[i] = A[i] % A[idx];
            }
        }
        out.println(A[N-1]);
    }

}
}



Measured memory_bytes: 50904
n,k = map(int,input().split())
p = list(map(int,input().split()))

ans = 0
tmp,ind = sum(p[0:k]),0
sumn = tmp

for i in range(len(p)-k):
    #print(p[i+k],p[i])
    tmp += p[i+k]-p[i]
    #print(tmp)
    if tmp >= sumn:
        ind,sumn = i,tmp
        #print(sumn)

print((sumn+k)/2)
"""
for i in p[ind:ind+k]:
    ans += (i+1)/2
else:
    print(ans)
"""


Measured memory_bytes: 25060
package main

import (
	"bufio"
	"fmt"
	"log"
	"math"
	"os"
	"strconv"
	"strings"
)

func isInteger(x, y []int) bool {
	sum := 0
	for i := range x {
		sum += (x[i] - y[i]) * (x[i] - y[i])
	}
	sqrt := math.Sqrt(float64(sum))
	return sqrt*sqrt == math.Floor(sqrt)*math.Floor(sqrt)
}

func main() {
	scanner := makeWordScanner()
	n := eGetInt(scanner)
	d := eGetInt(scanner)
	ds := make([][]int, n)
	for i := 0; i < n; i++ {
		ds[i] = make([]int, d)
		for j := 0; j < d; j++ {
			ds[i][j] = eGetInt(scanner)
		}
	}
	count := 0
	for i := 0; i < n; i++ {
		for j := i + 1; j < n; j++ {
			if isInteger(ds[i], ds[j]) {
				count++
			}
		}
	}
	fmt.Println(count)
}

////////////////////////////////////////////////////////////////////////////////
// ライブラリ
////////////////////////////////////////////////////////////////////////////////
func makeScanner(maxByte int) *bufio.Scanner {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Buffer(make([]uint8, 0, 8192), maxByte)
	return scanner
}
func makeWordScanner() *bufio.Scanner {
	scanner := makeScanner(8192)
	scanner.Split(bufio.ScanWords)
	return scanner
}
func eGetLine(r *bufio.Scanner) string {
	if r.Scan() {
		return r.Text()
	}
	err := r.Err()
	if err != nil {
		log.Fatal(err)
	}
	// EOF
	return ""
}

func eGetInt(r *bufio.Scanner) int {
	line := eGetLine(r)
	return eAtoi(line)
}
func eGetInt64(r *bufio.Scanner) int64 {
	line := eGetLine(r)
	return eAtoInt64(line)
}
func eGetFields(r *bufio.Scanner) []string {
	line := eGetLine(r)
	return strings.Fields(line)
}
func eGetInts(r *bufio.Scanner) []int {
	fields := eGetFields(r)
	ints := make([]int, len(fields))
	for i := 0; i < len(ints); i++ {
		ints[i] = eAtoi(fields[i])
	}
	return ints
}
func eGetInt64s(r *bufio.Scanner) []int64 {
	fields := eGetFields(r)
	ints := make([]int64, len(fields))
	for i := 0; i < len(ints); i++ {
		ints[i] = eAtoInt64(fields[i])
	}
	return ints
}
func eGetChars(r *bufio.Scanner) []string {
	line := eGetLine(r)
	return strings.Split(line, "")
}
func eAtoi(s string) int {
	n, err := strconv.Atoi(s)
	if err != nil {
		log.Fatal(err)
	}
	return n
}
func eAtoInt64(s string) int64 {
	n, err := strconv.ParseInt(s, 10, 64)
	if err != nil {
		log.Fatal(err)
	}
	return n
}


Measured memory_bytes: 640
#include <stdio.h>  
#include <algorithm>  
#include <assert.h>
#include <bitset>
#include <cmath>  
#include <complex>  
#include <deque>  
#include <functional>  
#include <iostream>  
#include <limits.h>  
#include <map>  
#include <math.h>  
#include <queue>  
#include <set>  
#include <stdlib.h>  
#include <string.h>  
#include <string>  
#include <time.h>  
#include <unordered_map>  
#include <unordered_set>  
#include <vector>  
#include <chrono>
#include <random>
#include <time.h>
#define ll long long
#define rep2(i,a,b) for(ll i=a;i<=b;++i)
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep3(i,a,b) for(ll i=a;i>=b;i--)
#define REP(e,v) for(auto e:v)
#define pii pair<int,int>
#define pll pair<ll,ll>
#define tii tuple<int,int,int>
#define pq priority_queue<int>
#define pqg priority_queue<int,vector<int>,greater<int>>
#define pb push_back
#define edge(v,a,b) v[a].pb(b);v[b].pb(a);
#define MAX_V 400010
#define vec vector<int>
#define vecll vector<ll>
#define vecpii vector<pii>
#define endl "\n"
#define ALL(c) (c).begin(),(c).end()
using namespace std;
int in() {int x;scanf("%d",&x);return x;}
ll lin() {ll x;scanf("%lld",&x);return x;}

#define INF 1e9+7
#define LLINF 1e18+7
#define N 500000
ll MOD=1e9+7;

vector<vec>G(N);
int dfs(int x,int p){
  int g=0;
  for(auto e:G[x]){
    if(e!=p){
    g^=(dfs(e,x)+1);}
  }
  return g;
}
main(){
    int n=in();
  rep(i,n-1){
  int a=in(),b=in();
  G[a].pb(b);
  G[b].pb(a);}
  cout<<((dfs(1,0)!=0)?"Alice":"Bob");
}



Measured memory_bytes: 19712
#include <iostream>
#include <vector>

using namespace std;

int main()
{
	long long N = 0;
	cin >> N;

	vector<long long> A(N);
	for (auto& a : A)
	{
		cin >> a;
	}

	bool Is0 = false;
	bool Odd = false;

	long long Min = 1000000001;
	long long Max = 0;

	for (auto& a : A)
	{
		if (a == 0)Is0 = true;
		if (a < 0)Odd = !Odd;

		long long n = abs(a);

		Max += n;
		if (n < Min)Min = n;
	}

	if (Odd && !Is0)
	{
		Max -= Min * 2;
	}

	cout << Max;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
using lint     = long long;
const lint inf = 1LL << 60;
const lint mod = 1000000007;

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    string s, t;
    cin >> s >> t;
    t.pop_back();
    if (s == t)
        cout << "Yes"
             << "\n";
    else
        cout << "No"
             << "\n";
    return 0;
}

Measured memory_bytes: 3620
#include <iostream>
using namespace std;
#include<string.h>
#include<set>
#include<stdio.h>
#include<math.h>
#include<queue>
#include<map>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cstring>
#include <cstdio>
#include <cstdlib>
#include<stack>
#include<vector>
char a[510000];
int main()
{
    cin>>a;
    int len=strlen(a);
    int sum1=0;
    int sum2=0;
    int sum3=0;
    for(int i=0;i<len;i++)
    {
        if(a[i]=='a')
            sum1++;
        else if(a[i]=='b')
            sum2++;
        else
            sum3++;
    }
    int min1=min(sum1,min(sum2,sum3));
    if(sum1-min1<2&&sum2-min1<2&&sum3-min1<2)
        cout<<"YES"<<endl;
    else
        cout<<"NO"<<endl;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
#pragma GCC optimize("O3")
#define maxn 1000000
using namespace std;
int n,m;
vector<int> fr[maxn];
bool vis[maxn];
int dfs(int u) {
    int ret=1;
    vis[u]=true;
    for(auto v:fr[u]) if(!vis[v]) ret+=dfs(v);
    return ret;
}
int main() {
    int a,b;
    scanf("%d %d",&n,&m);
    for(int i=0;i<m;i++) {
        scanf("%d %d",&a,&b);
        fr[a].push_back(b);
        fr[b].push_back(a);
    }
    int ans=0;
    for(int i=1;i<=n;i++) if(!vis[i]) ans=max(ans,dfs(i));
    printf("%d",ans);
	return 0;
}


Measured memory_bytes: 42984
#include <iostream>
#include <vector>
#include <string>

using namespace std;

int main()
{
	string s;
	cin >> s;
	
	vector<int> v(s.length(), 0);
	int j = 0;
	v[j]++;
	for (int i = 1; i < s.length(); i++) {
		if (s[i] == s[i - 1]) {
			v[j]++;
		}
		else {
			j++;
			v[j]++;
		}
	}

	vector<int> ans(s.length(), 0);
	int it = 0;
	for (int i = 0; i < j; i += 2) {
		ans[it + v[i] - 1] = (v[i] + 1) / 2 + v[i + 1] / 2;
		ans[it + v[i]] = (v[i + 1] + 1) / 2 + v[i] / 2;
		it += v[i] + v[i + 1];
	}

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

	return 0;
}

Measured memory_bytes: 1408
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <map>

using namespace std;
typedef long long ll;

ll gcd(ll a, ll b)
{
    if (a < b)
    {
        swap(a, b);
    }
    if (b == 0)
        return a;
    ll r = a % b;
    while (r > 0)
    {
        a = b;
        b = r;
        r = a % b;
    }
    return b;
}

int main()
{
    int n;
    cin >> n;
    vector<ll> a(n);
    for (int i = 0; i < n; i++)
    {
        cin >> a[i];
    }
    vector<ll> leftacc(n + 1);
    vector<ll> rightacc(n + 1);
    for (int i = 0; i < n; i++)
    {
        if (0 == i)
        {
            leftacc[i + 1] = a[i];
            continue;
        }

        leftacc[i + 1] = gcd(leftacc[i], a[i]);
    }
    for (int i = n - 1; i >= 0; i--)
    {
        if (n - 1 == i)
        {
            rightacc[i] = a[i];
            continue;
        }

        rightacc[i] = gcd(rightacc[i + 1], a[i]);
    }
    ll ans = 0;
    for (int i = 0; i < n; i++)
    {
        ans = max(ans, gcd(leftacc[i], rightacc[i + 1]));
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 5620
#pragma once
#include <stdio.h>
#include <sstream>
#include <string>
#include <string.h>
#include <vector>
#include <map>
#include <algorithm>
#include <iostream>
#include <utility>
#include <set>
#include <cctype>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <deque>
#include <limits>
#include <iomanip>
#define _USE_MATH_DEFINES
#include <math.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define bit(x,v) ((ll)x << v)

const ll INF = 1000000007;
const int MAX = 210000;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX; 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;
	}
}

// 二項係数計算
long long COM(int n, int k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a % b);
}
int pr[100010];
void uini(int n) {
	for (size_t i = 0; i <= n; i++)
	{
		pr[i] = i;
	}
}

int parent(int x) {
	if (x == pr[x]) return x;
	return pr[x] = parent(pr[x]);
}

bool unit(int x, int y) {
	int px = parent(x);
	int py = parent(y);

	if (px == py) return false;
	if (px < py) {
		pr[py] = px;
	}
	else {
		pr[px] = py;
	}
	return true;
}

ll a[100010];
ll d[100010];

void solv() {
	int n;
	cin >> n;

	for (size_t i = 0; i < n; i++)
	{
		cin >> a[i];
	}
	for (size_t i = 0; i < n; i++)
	{
		d[i] = a[i] * 2;
	}

	ll off = 0;
	for (size_t i = 1; i <= n; i++)
	{
		off = d[i - 1] - off;
	}

	ll tm = off / 2;
	cout << tm;
	for (size_t i = 1; i < n; i++)
	{
		ll v = d[i - 1] - tm;
		cout << " " << v;
		tm = v;
	}
}

int main() {
	//COMinit();
	solv();

	return 0;
}
 

Measured memory_bytes: 2816
#if !defined(__clang__) && defined(__GNUC__)
#include <bits/stdc++.h>
#else
#include <cstdlib>
#include <climits>
#include <iostream>
#include <cstdint>
#include <vector>
#include <string>
#include <complex>
#include <bitset>
#include <queue>
#include <deque>
#include <stack>
#include <utility>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <regex>
#endif //  !defined(__clang__) && defined(__GNUG__)
#include <boost/lexical_cast.hpp>
#include <boost/algorithm/string.hpp>
#include <boost/multi_array.hpp>
#include <boost/optional.hpp>
#include <boost/math/common_factor_rt.hpp>

#include <boost/range/adaptors.hpp>

using namespace std;


/** 約数計算
    12: 1, 2, 3, 4, 6, 12
 */
std::set<int64_t> divisors(int64_t n)
{
    std::set<int64_t> ret;
    for (int64_t i = 1; i*i <= n; ++i) {
        if (n % i == 0) {
            ret.insert(i);
            if (i != 1 && i * i != n) {
                ret.insert(n/i);
            }
        }
    }
    ret.insert(n);
    return ret;
}


int main()
{
    int64_t N, M;
    std::cin >> N >> M;

    auto mm = divisors(M);

    for (auto m: mm) {
        if (m >= N) {
            std::cout << M / m  << std::endl;
            return 0;
        }
    }
}


Measured memory_bytes: 256
#include<stdio.h>

int main(void){
  long long n,d;
  scanf("%lld %lld",&n,&d);
  long long x[n],y[n];
  int c=0;
  for(long long i=0;i<n;i++){
    scanf("%lld %lld",&x[i],&y[i]);
    if((x[i]*x[i]+y[i]*y[i])<=d*d){
    c++;
  }
  }

  
  printf("%d",c);
  return 0;
}


Measured memory_bytes: 4852
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <set>
#include <queue>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;

#define MOD 1000000007

int main()
{
    ll N, M, Ai, Bi;
    cin >> N >> M;
    vector<ll> A,B;
    for(int i=0;i<N;i++){
        cin >> Ai;
        A.push_back(Ai);
    }
    for(int i=0;i<M;i++){
        cin >> Bi;
        B.push_back(Bi);
    }
    set<ll> A1(A.begin(), A.end());
    set<ll> B1(B.begin(), B.end());
    if(A1.size() != A.size()
     ||B1.size() != B.size()){
        cout<<0<<endl;
        return 0;
    }
    sort(A.begin(), A.end(), std::greater<ll>());
    sort(B.begin(), B.end(), std::greater<ll>());

    ull conv = 1;
    size_t i = 0;
    size_t j = 0;
    for(ll n = N*M; n>=1; n--){
        while(i<N && A[i] >= n) i++;
        while(j<M && B[j] >= n) j++;

        if(A[i-1] == n && B[j-1] == n){
            conv *= 1;
        }else if(A[i-1] == n){
            conv *= j;
            conv %= MOD;
        }else if(B[j-1] == n){
            conv *= i;
            conv %= MOD;
        }else{
            conv *= i * j - (N*M - n);
            conv %= MOD;
        }

        if(conv==0) break;
    }

    cout<<conv<<endl;

    return 0;
}


Measured memory_bytes: 512
#include <iostream>
#include <stdio.h>
#include <vector>
#include <algorithm>
#include<string>
using namespace std;

int main() {
	string S;
	string T;
	int j = 0;
	cin >> S >> T;
	for (int i = 0; i < S.size(); i++) {
		if (S[i] != T[i]) {
			j = 1;
		}
	}
	if (j == 1) {
		cout << "No";
	}
	else {
		cout << "Yes";
	}
	return 0;
}

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

using namespace std;

using int64 = long long;

// Vector
template<typename T> ostream& operator<<(ostream& s, const vector<T>& v) {
	int len = v.size();
  s << "[";
	for (int i = 0; i < len; i++) {
    if (i > 0) s << ", ";
		s << v[i];
	}
  s << "]";
	return s;
}

constexpr int DEBUG = 0;

bool Solve() {
  int n;
  cin >> n;
  vector<int64> xs(1 << n);
  for (int i = 0; i < (1 << n); i++) {
    cin >> xs[i];
  }
  sort(xs.begin(), xs.end());
  reverse(xs.begin(), xs.end());

  vector<int64> cs({xs[0]});
  vector<int64> rs;
  for (int i = 1; i < (1 << n); i++) {
    rs.push_back(xs[i]);
  }

  for (int k = 0; k < n; k++) {
    if (DEBUG) cout << "rs: " << rs << endl;
    if (DEBUG) cout << "rs.size(): " << rs.size() << endl;
    vector<int> used(rs.size());
    int cur = 0;
    for (int64 c : cs) {
      while (cur < rs.size() && rs[cur] >= c) cur++;
      if (cur == rs.size()) return false;
      used[cur] = true;
      cur++;
    }
    vector<int64> new_rs;
    for (int i = 0; i < rs.size(); i++) {
      if (used[i]) {
        cs.push_back(rs[i]);
      } else {
        new_rs.push_back(rs[i]);
      }
    }
    rs = new_rs;

    sort(cs.begin(), cs.end());
    reverse(cs.begin(), cs.end());
    sort(rs.begin(), rs.end());
    reverse(rs.begin(), rs.end());
  }
  return true;
}

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

  if (Solve()) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }


}

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

int main(void)
{
  int a,b,c,ans=3;
  cin >> a >> b >> c;
  if(a == b)
  {
    if(a == c)
    {
      cout << ans - 2;
      return 0;
    }
    else
    {
      cout << ans - 1;
      return 0;
    }
  }
  else
  {
    if(b == c)
    {
      cout << ans - 1;
      return 0;
    }
    else if(a == c)
    {
      cout << ans - 1;
      return 0;
    }
    else
    {
      cout << ans;
      return 0;
    }
  }
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<math.h>
#include<stdlib.h>
#include<cstdlib>
using namespace std;

int a, b, ans = 0, W = 0, B = 0, R = 0;

int tansaku(int iti, int ryo, vector<string> c) {
  int kariAns = 0;
  for(int i = 0; i < b; i++) {
    for(int j = 0; j < ryo; j++) {
      if(c[iti + j][i] != 'B') kariAns++;
    }
    for(int j = 1; j < iti; j++) {
      if(c[iti - j][i] != 'W') kariAns++;
    }
    for(int j = iti + ryo; j < a - 1; j++) {
      if(c[j][i] != 'R') kariAns++;
    }
  }
  if(iti + ryo == a - 1) {
    iti = 1;
    ryo++;
  }else {
    iti++;
  }
  if(ryo >= a - 1) return kariAns;
  return min(kariAns, tansaku(iti, ryo, c));
}

int main() {
  cin >> a >> b;
  vector<string> c(a);
  for(int i = 0; i < a; i++) {
    cin >> c[i];
  }
  for(int i = 0; i < b; i++) {
    if(c[0][i] != 'W') ans++;
    if(c[c.size() - 1][i] != 'R') ans++;
  }
  cout << ans + tansaku(1, 1, c) << endl;
}

Measured memory_bytes: 9148
import itertools

def main():
    N, K = map(int, input().split())
    max_ = int((N - 1) * (N - 2) / 2)
    if K > max_:
        print(-1)
        return
    M = N - 1 + max_ - K
    print(M)
    for i in range(2, N + 1):
        print(1, i)
    for u, v in [(x[0], x[1]) for x in itertools.combinations(range(2, N + 1), 2)][:max_ - K]:
        print(u, v)

main()

Measured memory_bytes: 3992
import java.util.*;

class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		
		int a = sc.nextInt();
		int b = sc.nextInt();
		
		System.out.println( (a*b)%2 == 0 ? "Even" : "Odd" );
	}
}


Measured memory_bytes: 21844
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
// using namespace __gnu_pbds;
using namespace std;

#define ff first
#define ss second
#define int long long
#define pb push_back
#define mp make_pair
#define pii pair<int, int>
#define vi vector<int>
#define mii map<int, int>
#define pqb priority_queue<int>
#define pqs priority_queue<int, vi, greater<int> >
#define setbits(x) __builtin_popcountll(x)
#define zrobits(x) __builtin_ctzll(x)
#define mod 998244353
#define inf 1e18
#define ps(x, y) fixed << setprecision(y) << x
#define mk(arr, n, type) type* arr = new type[n];
#define forn(i, n) for (int i = 1; i <= n; i++)
#define me0(x) memset(x, 0, sizeof(x))
#define me1(x) memset(x, -1, sizeof(x))
#define tests(x) \
    int x;       \
    cin >> x;    \
    while (x--)
// mt19937                 rng(chrono::steady_clock::now().time_since_epoch().count());

// typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
int INF = 1e18;
const int N = 2e5 + 2;
void run() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
}
int n, a[405], dp[405][405];
int sum(int i, int j) {
    int res = 0;
    for (int k = i; k <= j; k++) {
        res += a[k];
    }
    return res;
}
int solve() {
    cin >> n;
    forn(i, n) cin >> a[i];
    for (int i = n; i >= 1; i--) {
        for (int j = i; j <= n; j++) {
            if (i == j) {
                dp[i][j] = 0;
              	continue;
            }
            dp[i][j] = INF;
            int s = sum(i, j);
            for (int k = i; k < j; k++) {
                dp[i][j] = min(dp[i][j], dp[i][k] + dp[k + 1][j] + s);
            }
        }
    }
    return dp[1][n];
}
int32_t main() {
    //run();
    cout << solve();
    return 0;
}

Measured memory_bytes: 1536
#include <iostream>
#include <algorithm>
#include <tuple>
#include <vector>
#include <string>
#include <queue>
#include <cmath>
#include <set>
#include <map>
#include <cassert>

using namespace std;
using ll = long long;

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

const ll mod = 1e9+7;

int main()
{
    ll n, k;
    cin >> n >> k;
    vector<ll> a(n);
    ll ans = 0;
    for(ll i =0 ; i< n; i++){
        cin >> a[i];
    }
    for(ll i =0 ; i <n; i++){
        ll l = 0, r = 0;
        for(ll j = 0; j < n; j++){
            if(i < j && a[i] > a[j]){
                r++;
                l++;
            }else if(i > j && a[i] > a[j]){
                l++;
            }
        }

        // for(int j = i; j < n; ++j) {
		// 	if( a[i] > a[j] ) r++;
		// }
		
		// for(int j = 0; j < n; ++j) {
		// 	if( a[i] > a[j] ) l++;
		// }

        //cout << "l: " << l << "r: " << r << endl;
        ll q=0;
        ans += (r*k)%mod;
        ans %= mod;
        q = (k*(k-1LL)/2LL)%mod;
        l %= mod;
        ans += (l*q) %mod;
        ans %= mod;

        // ans += (k * r) % mod;
		// ans %= mod;
		// ans += (l % mod) * ((k * (k - 1LL) / 2LL) % mod);
		// ans %= mod;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3640
#include<cstdio>
#include<string>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;

char c[110];
int cnt[27];

int main()
{
	scanf("%s",c);
	int n=strlen(c);
	for(int i=0;i<n;i++)
	{
		cnt[c[i]-'a']++;
	}
	for(int i=0;i<26;i++)
	{
		if(cnt[i]&1)
		{
			puts("No");
			return 0;
		}
	}
	puts("Yes");
}

Measured memory_bytes: 256
import sys


def solve():
    readline = sys.stdin.buffer.readline
    mod = 10 ** 9 + 7
    n = int(readline())
    s = str(readline().rstrip().decode('utf-8'))
    mt = 0
    for i in range(0, n):
        zs = s[i:]
        zln = len(zs)
        zl = [0] * zln
        zi = 1
        zj = 0
        while zi < zln:
            while zi + zj < zln and zs[zj] == zs[zi+zj]:
                zj += 1
            zl[zi] = zj
            if zj == 0:
                zi += 1
                continue
            zk = 1
            while zi + zk < zln and zk + zl[zk] < zj:
                zl[zi+zk] = zl[zk]
                zk += 1
            zi += zk
            zj -= zk
        for j in range(len(zl)):
            if zl[j] <= j:
                mt = max(mt, zl[j])
    print(mt)


if __name__ == '__main__':
    solve()


Measured memory_bytes: 47708
#include<stdio.h>

main(){
  int i,n;
  int fib[45];

  scanf("%d",&n);

  fib[0]=1;
  fib[1]=1;
  for(i=2;i<=n;i++){
    fib[i]=fib[i-1]+fib[i-2];
  }
  printf("%d\n",fib[n]);
  return 0;
}

Measured memory_bytes: 596
#include <iostream>
#include <iomanip>
#include <utility>
#include <vector>
#include <algorithm>
typedef long long ll;
using namespace std;
const ll INF = 1e15;
const ll MOD = 1e9 + 7;
#define repi(i, n, init) for (ll i = init; i < (n); i++)

int main()
{
    ll n;
    cin >> n;
    n++;
    vector<ll> a(n, 0);
    vector<ll> range(n, 0);
    repi(i, n, 0)
    {
        cin >> a[i];
    }
    range[n - 1] = a.back();
    // cout << range[n - 1].first << " " << range[n - 1].second << endl;
    for (ll i = n - 2; i >= 0; i--)
    {
        range[i] = range[i + 1] + a[i];
        // cout << range[i].first << " " << range[i].second << endl;
    }
    ll ans = 0, lim = 1;
    repi(i, n, 0)
    {
        if (a[i] > min(lim, range[i]))
        {
            cout << -1 << endl;
            return 0;
        }
        ans += min(lim, range[i]);
        lim = (min(lim, range[i]) - a[i]) * 2;
    }
    if (ans == 0)
    {
        cout << -1 << endl;
    }
    else
    {
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 4700
#![allow(unused_imports, unused_macros, dead_code)]

macro_rules! min {
    (.. $x:expr) => {{
        let mut it = $x.iter();
        it.next().map(|z| it.fold(z, |x, y| min!(x, y)))
    }};
    ($x:expr) => ($x);
    ($x:expr, $($ys:expr),*) => {{
        let t = min!($($ys),*);
        if $x < t { $x } else { t }
    }}
}
macro_rules! max {
    (.. $x:expr) => {{
        let mut it = $x.iter();
        it.next().map(|z| it.fold(z, |x, y| max!(x, y)))
    }};
    ($x:expr) => ($x);
    ($x:expr, $($ys:expr),*) => {{
        let t = max!($($ys),*);
        if $x > t { $x } else { t }
    }}
}


macro_rules! ewriteln {
    ($($args:expr),*) => { let _ = writeln!(&mut std::io::stderr(), $($args),*); };
}
macro_rules! trace {
    ($x:expr) => { ewriteln!(">>> {} = {:?}", stringify!($x), $x) };
    ($($xs:expr),*) => { trace!(($($xs),*)) }
}
macro_rules! put {
    (.. $x:expr) => {{
        let mut it = $x.iter();
        if let Some(x) = it.next() { print!("{}", x); }
        for x in it { print!(" {}", x); }
        println!("");
    }};
    ($x:expr) => { println!("{}", $x) };
    ($x:expr, $($xs:expr),*) => { print!("{} ", $x); put!($($xs),*) }
}

const M: i64 = 1_000_000_007;

fn main() {
    let mut sc = Scanner::new();
    let n: i32 = sc.cin();
    if (0..100).filter(|i| (0..100).filter(|j| 4*i+7*j==n).count()>0).count()>0 {
        put!("Yes");
    } else {
        put!("No");
    }
}

use std::io::{self, Write};
use std::str::FromStr;
use std::collections::VecDeque;

struct Scanner { stdin: io::Stdin, buffer: VecDeque<String>, }
impl Scanner {
    fn new() -> Self { Scanner { stdin: io::stdin(), buffer: VecDeque::new() } }
    fn cin<T: FromStr>(&mut self) -> T {
        while self.buffer.len() == 0 {
            let mut line = String::new();
            let _ = self.stdin.read_line(&mut line);
            for w in line.split_whitespace() {
                self.buffer.push_back(String::from(w));
            }
        }
        self.buffer.pop_front().unwrap().parse::<T>().ok().unwrap()
    }
}


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

long digitLength(long x) {
    long length = 0;
    while(x>0) {
        length ++;
        x/=10;
    }
    return length;
}

long digitFirst(long x) {
    long first = 0;
    vector<long> digit;
    while(x>0) {
        first = x%10;
        digit.push_back(first);
        x /= 10;
    }
    for(int i = 0; i < digit.size()-1; i ++) {
        if(digit[i] != 9) {
            first --;
            break;
        }
    }
    return first;
}

int main() {
    long n; cin >> n;
    long l = digitLength(n);
    long f = digitFirst(n);
    cout << 9*(l-1) + f << endl;
    return 0;
}

Measured memory_bytes: 768