akhauriyash/Code-Regression huggingface dataset:
// W i B
#include <bits/stdc++.h>
#define F first
#define S second
#define MOD 1000000007
#define pb push_back
#define bit(x,p) ((x>>p) & 1)
#define ll long long
#define Task "CF"
using namespace std;

const int base = 100003;
const int maxn = 600005;

int n,k,a[maxn];
ll tree[8 * maxn],dp[maxn];

int Get(int node,int l,int r,int u,int v){
    if(u > r || l > v) return 0;
    if(l >= u && r <= v) return tree[node];
    int mid = (l + r) >> 1;
    int L = Get(node * 2,l,mid,u,v);
    int R = Get(node * 2 + 1,mid + 1,r,u,v);
    return max(L,R);
}

void Update(int node,int l,int r,int id,ll val){
    if(l == r){
        tree[node] = val;
        return;
    }
    int mid = (l + r) >> 1;
    if(id <= mid) Update(node * 2,l,mid,id,val);
    else Update(node * 2 + 1,mid + 1,r,id,val);
    tree[node] = max(tree[node * 2],tree[node * 2 + 1]);
}

void Solve(){
    cin >> n >> k;
    for(int i = 1;i <= n;++i) cin >> a[i];
    for(int i = 1;i <= n;++i){
        int l = max(0,a[i] - k);
        int r = min(a[i] + k,maxn);
        ll res = Get(1,0,maxn,l,r);
        dp[i] = max(dp[i],res + 1);
        Update(1,0,maxn,a[i],dp[i]);
    }
    ll ans = 1;
    for(int i = 1;i <= n;++i) ans = max(ans,dp[i]);
    cout << ans;
}
void NumTime(){
    cerr << "Toi" << "\n";cerr << "Di" << "\n";cerr << "Chep" << "\n";cerr << "Code" << "\n";
}


int main(){
    ios_base::sync_with_stdio(0);
    cout.tie(0); cin.tie(0);
	if(fopen(Task".inp","r")){
		freopen(Task".inp","r",stdin);
		freopen(Task".out","w",stdout);
	}
    int test = 1;
//    cin >> test;
    while(test --){
        NumTime();
        Solve();
    }
}
 // V T An


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

using namespace std;

int main(){
	string str[1000];
	string s;
	int size = 0;
	while(getline(cin,s)){
		if(s == "END_OF_TEXT") break;
		str[size++] = s;
	}
	char ch;
	string buf = "";
	int line = 0, pos = 0;
	while(cin >> ch){
		if(ch == '-') break;
		if(ch == 'a') pos = 0;
		if(ch == 'e') pos = str[line].size();
		if(ch == 'p'){
			pos = 0;
			if(line!=0) line--;
		}
		if(ch == 'n'){
			pos = 0;
			if(line+1!=size) line++;
		}
		if(ch == 'f'){
			if(pos != str[line].size()) pos++;
			else if(line+1!=size) { pos = 0; line++; }
		}
		if(ch == 'b'){
			if(pos != 0) pos--;
			else if(line!=0) { line--; pos = str[line].size(); }
		}
		if(ch == 'd'){
			if(pos != str[line].size()){
				str[line] = str[line].substr(0,pos) + str[line].substr(pos+1);
			} else if(line+1!=size){
				str[line] = str[line] + str[line+1];
				for(int i=line+1;i+1<size;i++){
					str[i] = str[i+1];
				}
				str[size-1] = "";
				size--;
			}
		}
		if(ch == 'k'){
			if(pos == str[line].size() && line+1!=size){
				str[line] = str[line] + str[line+1];
				for(int i=line+1;i+1<size;i++){
					str[i] = str[i+1];
				}
				str[size-1] = "";
				size--;
				buf = "IS_BREAK_LINE";
			}
			else if(pos < str[line].size()){
				buf = str[line].substr(pos);
				str[line] = str[line].substr(0,pos);
			}
		}
		if(ch == 'y'){
			if(buf == "IS_BREAK_LINE"){
				for(int i=size-1;i>=line+1;i--){
					str[i+1] = str[i];
				}
				size++;
				str[line+1] = str[line].substr(pos);
				str[line] = str[line].substr(0,pos);
				line++;
				pos = 0;
			} else if(buf != ""){
				str[line] = str[line].substr(0,pos) + buf + str[line].substr(pos);
				pos += buf.size();
			}
		}
		/*
		cout << line << " " << pos << endl;
		for(int i=0;i<size;i++){
			cout << str[i] << endl;	
		}
		puts("");
		*/
	}
	for(int i=0;i<size;i++){
		cout << str[i] << endl;
	}
}

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

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


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

#define _CRT_SECURE_NO_WARNINGS
#define _SILENCE_CXX17_C_HEADER_DEPRECATION_WARNING

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


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

	ios_base::sync_with_stdio(false);
	cin.tie(nullptr), cout.tie(nullptr);

	int n, l;
	cin >> n >> l;
	vector<string> vs(n);
	for (auto& s : vs)
		cin >> s;
	sort(vs.begin(), vs.end());
	for (auto& s : vs)
		cout << s;

	return 0;
}

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

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	int n, h, w; cin >> n >> h >> w;
	cout << (n - h + 1) * (n - w + 1) << '\n';
	return 0;
}

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

int factorial(int n) {
    if (n == 1 || n == 0) {
        return 1;
    }

    return n * factorial(n - 1);
}

int count_order(const std::vector<int>& v) {
    std::vector<int> vec = v;
    int cnt = 0;
    do {
        ++cnt;
    } while (std::next_permutation(vec.begin(), vec.end()));


    return factorial(v.size()) - cnt;
}

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

    std::vector<int> P(N);
    std::vector<int> Q(N);
    for (int i = 0; i < N; ++i) {
        std::cin >> P[i];
    }

    for (int i = 0; i < N; ++i) {
        std::cin >> Q[i];
    }

    std::cout << std::abs(count_order(P) - count_order(Q)) << std::endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cstring>
#include <queue>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <cmath>
#include <algorithm>
#include <functional>
#define inf 1000000
using namespace std;
typedef long long ll;
const int MAXN=1e5+10;
const int MAX=1e2+10;
const double eps=1e-6;


int main(){
    #ifdef ONLINE_JUDGE
    #else
    //freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);
    #endif
 
    int n,m,k;
    cin>>n>>m>>k;
    int juge=0;
	if(!k) juge=1; 
    for(int i=0;i<=n;i++){
    	for(int j=0;j<=m;j++){
    		int temp=i*m+j*n-2*i*j;
    		if(temp==k){
    			juge=1;
    			break;
    		}
    	}
    } 
    if(juge)
    	cout<<"Yes"<<endl;
    else
    	cout<<"No"<<endl;

    return 0;	
}

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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repc(i, a, b) for (int i = a; i <= (int)(b); i++)
#define ll long long
#define vec vector
#define pb push_back
#define ft first
#define sd second
#define all(vec) vec.begin(), vec.end()

typedef pair<int, int> P;

const int MOD = 1e9 + 7;
const int INF = 1001001001;
const int dx[4] = {1, 0,-1, 0};
const int dy[4] = {0, 1, 0,-1};

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

int main(){
  int n;
  cin >> n;
  vec<int> a(n, 0);
  vec<int> b(n, 0);
  vec<int> c(n, 0);
  rep(i, n){
    cin >> a[i] >> b[i] >> c[i];
  }

  int dp[n+1][3];
  rep(i, n+1){
    dp[i][0] = 0;
    dp[i][1] = 0;
    dp[i][2] = 0;
  }

  repc(i, 1, n){
    dp[i][0] = max(dp[i-1][1]+a[i-1], dp[i-1][2]+a[i-1]);
    dp[i][1] = max(dp[i-1][0]+b[i-1], dp[i-1][2]+b[i-1]);
    dp[i][2] = max(dp[i-1][0]+c[i-1], dp[i-1][1]+c[i-1]);
  }

  cout << max(max(dp[n][0],dp[n][1]), dp[n][2]) << endl;

  return 0;
}

Measured memory_bytes: 5552
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned ll
#define pii pair<ll, ll> 
#define pb push_back
#define debug(x) cerr<< #x << " is " <<x<<endl;
#define debug2(x) cerr<<#x<< " is\n"; for (auto &i:x) {cout<<i<<' '; } cout<<endl;
#define f first
#define s second
using namespace std;
const int maxn = 200005;
const ll inf=1ll<<60;
const ll mod = 1e9+7;

ll seg[maxn*4];

ll query(int l, int r, int L, int R, int o){
	if (l>R||r<L) return 0;
	if (l>=L&&r<=R) return seg[o];
	int mid = (l+r)/2;
	ll ql = query(l, mid, L, R, o*2+1);
	ll qr = query(mid+1, r, L, R, o*2+2);
	return max(ql, qr);
}

void modify(int l, int r, int p, ll v, int o){
	if (l>p||r<p) return;
	if (l==r){
		if(l==p) seg[o]=v; return;
	}
	int mid = (l+r)/2;
	modify(l, mid, p, v, o*2+1);
	modify(mid+1, r, p, v, o*2+2);
	seg[o]=max(seg[o*2+1],seg[o*2+2]);
}

int main(){
    ios::sync_with_stdio(false); cin.tie(0);
    int n; cin>>n;
    vector<ll> a(n), b(n); 
    for (int i=0; i<n; i++) cin>>a[i]; 
    for (int i=0; i<n; i++) cin>>b[i]; 
    ll re = 0; 	
    for (int i=0; i<n; i++){
    	ll tmp = query(0,n,0,a[i]-1,0);
    	//debug(tmp+b[i]);
    	re = max(re, tmp+b[i]);
    	modify(0,n,a[i],tmp+b[i],0);
    }
    cout<<re<<'\n';
}

Measured memory_bytes: 9472
#include <bits/stdc++.h>
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define FORR(i,a,b) for (int i=(a);i>=(b);i--)
#define pb push_back
#define pcnt __builtin_popcount
#define show(x) cout<<#x<<" = "<<x<<endl;
#define maxs(x,y) x = max(x,y)
#define mins(x,y) x = min(x,y)
#define fi first
#define se second
#define rng(a) (a.begin()),(a.end())
#define each(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)
#define sz(x) (int)(x).size()
#define mp make_pair

using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vpii;
typedef set<int> si;
typedef pair<ll,ll> pll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<pll> vpll;
typedef set<ll> sl;
typedef __int128_t lll;
typedef pair<lll,lll> plll;
typedef vector<lll> vlll;
template<typename T>string join(vector<T>&v)
{stringstream s;FOR(i,0,sz(v))s<<' '<<v[i];return s.str().substr(1);}
ll gcd(ll a,ll b){if(a>b)swap(a,b);for(;a>0;b%=a,swap(a,b));return b;}
int modpow(ll a,ll n,int m){if(a==0)return a;ll p=1;for(;n>0;n/=2,a=a*a%m)if(n&1)p=p*a%m;return(int)p;}
void dout(double d){printf("%.12f\n",d);}

const int iinf = 1e9;
const ll linf = 1e18;
const int mod = 1e9+7;
const double pi = acos(-1);
const double eps = 1e-10;
int n, w, a[2005], xv, xvv, yv, yvv, v;

main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> n >> w >> w;
  a[0] = w;
  FOR(i, 0, n) cin >> a[i+1];
  xvv = iinf;
  FORR(i, n-1, 0){
    v = abs(a[n]-a[i]);
    xv = max(yvv, v);
    yv = min(xvv, v);
    mins(xvv, xv);
    maxs(yvv, yv);
  }
  cout << xv << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
using namespace std;
#define INF 10000000
int a,b,d;
int cntA,cntB;

void cal2(){//a*i==b*j+d, b*i=a*j+d

  for(int i=0;cntB&&i<100000;i++)
    if((a*i)%b==d%b && cntA+cntB>i+abs((a*i)/b-d/b))cntA=i,cntB=abs((a*i)/b-d/b);

  for(int i=0;cntA&&i<100000;i++)
    if((b*i)%a==d%a && cntA+cntB>i+abs((b*i)/a-d/a))cntA=abs((b*i)/a-d/a),cntB=i;
  
}

int main(){
  while(1){
    cin>>a>>b>>d;
    if(!a&&!b&&!d)break;
    cntA=cntB=INF;
    cal2();
    cout <<cntA<<" "<<cntB<<endl;
  }
  return 0;
}

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

const int N=2100,K=1e4+100;
char ch[N][K];
int n,k,len[N];
bitset<K> f[N];
pair<int,int> v[2][K];

int main()
{
	scanf("%d%d",&n,&k);
	for(int i=1;i<=n;++i)
	{
		scanf("%s",ch[i]+1);
		len[i]=strlen(ch[i]+1);
	}
	f[n+1][0]=1;
	for(int i=n;i>=1;--i)
		f[i]=f[i+1]|(f[i+1]<<len[i]);
	int cnt=0;
	for(int i=1;i<=n;++i)
		if(f[i+1][k-len[i]]) v[0][++cnt]=make_pair(i,1);
	for(int i=1;i<=k;++i)
	{
		char Ans='z'; int ncnt=0,ID=n+1;
		for(int j=1;j<=cnt;++j)
			Ans=min(Ans,ch[v[i-1&1][j].first][v[i-1&1][j].second]);
		putchar(Ans);
		for(int j=1;j<=cnt;++j)
		{
			int id=v[i-1&1][j].first,pos=v[i-1&1][j].second;
			if(ch[id][pos] != Ans) continue;
			if(pos<len[id]) v[i&1][++ncnt]=make_pair(id,pos+1);
			else ID=min(ID,id);
		}
		for(int j=ID+1;j<=n;++j)
			if(k-i-len[j]>=0 && f[j+1][k-i-len[j]]) v[i&1][++ncnt]=make_pair(j,1);
		cnt=ncnt;
	}
	return 0;
}

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

#define INF_LL (int64)1e18
#define INF (int32)1e9
#define REP(i, n) for(int64 i = 0;i < (n);i++)
#define FOR(i, a, b) for(int64 i = (a);i < (b);i++)
#define all(x) x.begin(),x.end()
#define fs first
#define sc second

using int32 = int_fast32_t;
using uint32 = uint_fast32_t;
using int64 = int_fast64_t;
using uint64 = uint_fast64_t;
using PII = pair<int32, int32>;
using PLL = pair<int64, int64>;

const double eps = 1e-10;

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

template<typename T>
vector<T> make_v(size_t a){return vector<T>(a);}

template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
	return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}

template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value!=0>::type
fill_v(U &u,const V... v){u=U(v...);}

template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value==0>::type
fill_v(U &u,const V... v){
	for(auto &e:u) fill_v<T>(e,v...);
}

map<pair<int, string>, int64> mp;
vector<string> S;
vector<int64> C;
int64 N;

void dfs(pair<int, string> ps, int64 cost) {
  int side = ps.fs;
  string s = ps.sc;
//  cout << side << " " << s << " " << cost << endl;
  if (mp.count(ps) && mp[ps] < cost) return;
  string ss = s;
  if (side != 0) reverse(all(ss));

  REP(i, N) {
    string ts = S[i];
    if (side == 0) reverse(all(ts));
    int64 cnt = 0;
    while (cnt < min(ts.size(), ss.size()) && ts[cnt] == ss[cnt]) cnt++;
    if (cnt < min(ts.size(), ss.size())) continue;

    int64 ns = 1-side;
    string ls;
    if (ts.size() > ss.size()) {
      ls = ts.substr(cnt, ts.size() - cnt);
      if (side == 0) reverse(all(ls));
    } else {
      ls = ss.substr(cnt, ss.size() - cnt);
      if (side == 1) reverse(all(ls));
      ns = 1-ns;
    }
//    cout << ss << " " << ts << ": " << ns << " " << ls << endl;
    if (!mp.count(make_pair(ns, ls)) || mp[make_pair(ns, ls)] > cost + C[i]) {
      mp[make_pair(ns, ls)] = cost + C[i];
      dfs(make_pair(ns, ls), cost +C[i]);
    }
  }
}

int main(void) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> N;
  S = vector<string>(N);
  C = vector<int64>(N);
  REP(i, N) cin >> S[i] >> C[i];
  int64 res = INF_LL;
  REP(i, N) {
    dfs(make_pair(0, S[i]), C[i]);
    dfs(make_pair(1, S[i]), C[i]);
    string ss = S[i], ts = S[i];
    reverse(all(ts));
    if (ss == ts) chmin(res, C[i]);
  }
  for (auto &x : mp) {
    string s1 = x.fs.sc, s2 = x.fs.sc;
    reverse(all(s2));

    if (s1 == s2) chmin(res, x.sc);
  }
  if (res == INF_LL) cout << -1 << endl;
  else cout << res << endl;
}


Measured memory_bytes: 3788
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
#define rep(i,j,k) for(int i=j;i<k;i++)
#define all(x) (x).begin(),(x).end()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
#define pb push_back
#define mp make_pair
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000000001
const int  COMMAX = 510000;

long long fac[COMMAX], finv[COMMAX], inv[COMMAX];

int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcd(int a,int b){return a*b / gcd(a,b);}
// テーブルを作る前処理
void COMinit() {
  fac[0] = fac[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  for (int i = 2; i < COMMAX; 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;
}

struct UnionFind {
  vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2
  vector<int> rank;
  int num;
  UnionFind(int N) : par(N) , rank(N) { //最初は全てが根であるとして初期化
    num = N;
    for(int i = 0; i < N; i++){
      par[i] = i;
      rank[i] = 0;
    }
  }

  int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
    if (par[x] == x) return x;
    return par[x] = root(par[x]);
  }

  void unite(int x, int y) { // xとyの木を併合
    int rx = root(x); //xの根をrx
    int ry = root(y); //yの根をry
    if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
    if(rank[rx] < rank[ry]){
      par[rx] = ry;  
    }else{
      par[ry] = rx;
      if(rank[rx] == rank[ry])rank[rx]++;
    }
    num--;
  }

  bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
    return root(x) == root(y);
  }
};

const int MS = 2;
const long long mod[] = {999999937LL, 1000000007LL}, base = 9973;
struct rolling_hash {
    int n;
    vector<long long> hs[MS], pw[MS];
    rolling_hash(){}
    rolling_hash(const string &s) {
        n = s.size();
        for (int i = 0; i < MS; i++) {
            hs[i].assign(n+1,0);
            pw[i].assign(n+1,0);
            hs[i][0] = 0;
            pw[i][0] = 1;
            for (int j = 0; j < n; j++) {
                pw[i][j+1] = pw[i][j]*base%mod[i];
                hs[i][j+1] = (hs[i][j]*base+s[j])%mod[i];
            }
        }
    }

    long long hash(int l, int r, int i) { return ((hs[i][r]-hs[i][l]*pw[i][r-l])%mod[i]+mod[i])%mod[i]; }

    bool match(int l1, int r1, int l2, int r2) {
        bool ret = 1;
        for (int i = 0; i < MS; i++) ret &= hash(l1,r1,i)==hash(l2,r2,i);
        return ret;
    }

    bool match(int l, int r, long long h[]) {
        bool ret = 1;
        for (int i = 0; i < MS; i++) ret &= hash(l,r,i)==h[i];
        return ret;
    }
};
int hako[110];
int main(){
  int n;
  cin >> n;
  double sum = 0;
  rep(i,0,n){
    int a;
    cin >> a;
    sum += a;
    hako[i] = a;
  }
  int ave = round(sum / n);
  int res = 0;
  rep(i,0,n){
    res += pow(hako[i]-ave,2);
  }
  cout << res << endl;
  return 0;
}


Measured memory_bytes: 384
s = input()

for i in range(len(s)):
    if i % 2 == 0:
        if s[i] != 'R' and s[i] != 'U' and s[i] != 'D':
            print("No")
            exit(0)
    else:
        if s[i] != 'L' and s[i] != 'U' and s[i] != 'D':
            print("No")
            exit(0)

print("Yes")

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

int main() {
    int N;
    cin >> N;
    int a[N], b[N], c[N];
    for (int i = 0; i < N; i++)
    {
        cin >> a[i];
    }
    for (int i = 0; i < N; i++)
    {
        cin >> b[i];
    }
    for (int i = 0; i < N; i++)
    {
        cin >> c[i];
    }
    sort(a, a + N);
    sort(b, b + N);
    sort(c, c + N);

    long long ans = 0;
    for (int i = 0; i < N; i++)
    {
        long long x1, x2;
        x1 = lower_bound(a, a + N, b[i]) - a;
        x2 = upper_bound(c, c + N, b[i]) - c;
        ans += x1 * (N - x2);
    }

    cout << ans << endl;
}

Measured memory_bytes: 1408
import           Control.Monad
import qualified Data.ByteString.Char8 as BS
import           Data.Maybe

readInt = fst . fromJust . BS.readInt
readIntList = map readInt . BS.words
getInt = readInt <$> BS.getLine
getIntList = readIntList <$> BS.getLine


primeFactorization :: Int -> [(Int, Int)]
primeFactorization x = pfact x 2 0 []
  where
    sr = floor $ sqrt $ fromIntegral x
    pfact n i r fs | i > sr    = if n > sr then (n,1):fs else fs
                   | otherwise =
                     if n `mod` i == 0
                     then pfact (n `div` i) i (r+1) fs
                     else pfact n (i+1) 0 (if r > 0 then (i,r):fs else fs)

main = do
  [n, p] <- getIntList

  let fs = primeFactorization p
      ans = product $ map (\(i,r) -> i ^ (r `div` n)) fs

  print ans

Measured memory_bytes: 56956
#include <bits/stdc++.h>
#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 per(i,n) for(int i=int(n)-1;i>=0;i--)
#define per1(i,n) for(int i=int(n);i>0;i--)
#define foreach(i,n) for(auto &&i:n)
#define all(x) (x).begin(),(x).end()
#define SORT(x) sort(all(x))
#define GSORT(x) sort(all(x), greater<int>())
#define REV(x) reverse(all(x))
#define MAX(x) *max_element(all(x))
#define MIN(x) *min_element(all(x))
#define LOWitr(x, n) lower_bound(all(x), n)
#define UPRitr(x, n) upper_bound(all(x), n)
#define cii(x) int x;cin >> x
#define cill(x) LL x;cin >> x
#define cis(x) string x;cin >> x
#define co(x) cout << x << endl
#define dump(x)  cout << #x << " = " << (x) << endl
#define truecheck assert
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define fastcin() cin.tie(0);ios::sync_with_stdio(false)
using namespace std;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
typedef long long int64;
template<class T,class U>bool chmax(T &a, const U &b) { if (a<b) { a=b; return true; } return false; }
template<class T,class U>bool chmin(T &a, const U &b) { if (b<a) { a=b; return true; } return false; }
const int INF = 1e9, MOD = 1e9 + 7;
const LL LLINF = 1e16;

int main() {
    fastcin();
    cout << fixed << setprecision(10);
    cis(s);
    string ans = "Good";
    rep(i, 3){
        if (s[i]==s[i+1]){
            ans = "Bad";
        }
    }
    co(ans);
    return 0;
}

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

using namespace std;

int main(void){
  int n,m,k;
  cin>>n>>m>>k;
  int num;
  for(int i=0;i<=n;i++){
    for(int j=0;j<=m;j++){
      num=i*m+(-i+(n-i))*j;
      if(num==k){
        cout <<"Yes"<<endl;
        return 0;
      }
      //black[t++]=num;
    }
  }
  cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 256
from collections import defaultdict, deque

def dfs(q, M, d):
    if d==N:
        res = []

        for qi in q:
            res.append(dic[qi])
        
        print(''.join(res))
        return
        
    for i in range(M+1):
        q.append(i)
        dfs(q, M, d+1)
        q.pop()
    
    q.append(M+1)
    dfs(q, M+1, d+1)
    q.pop()

N = int(input())
dic = defaultdict(int)
c = 0

for a in 'abcdefghijklmnopqrstuvwxyz':
    dic[c] = a
    c += 1

dfs(deque([0]), 0, 1)

Measured memory_bytes: 53212
#include<stdio.h>
int a[10000001];
int main(void)
{
	int n;
	int cnt,i;
	
	scanf("%d",&n);
	while(n!=-1){
		cnt=0;
		i=0;
		while(n>=4){
			cnt++;
			a[i]=n%4;
			i++;
			n=n/4;
		}
		printf("%d",n);
		for(i=cnt-1;i>=0;i--){
			printf("%d",a[i]);
		}
		printf("\n");
		scanf("%d",&n);
	}
	return 0;
}

Measured memory_bytes: 1032
n, m =map(int,input().split())
c = list(map(int,input().split()))

INF = 10**10
dp = [INF]*(n+1)
dp[0] = 0

for i in range (n+1):
    for j in range (len(c)):
        if i-c[j]>=0:
            dp[i] = min(dp[i],dp[i-c[j]]+1)

print(dp[n])


Measured memory_bytes: 7256
#include<bits/stdc++.h>
#define FOR(i, a, b) for (int i = a; i < b; ++i)
#define rep(N) for (int i = 0; i < N; ++i)
#define Rep(a, b) for (int i = a; i < b; ++i)
#define For(i, N) for (int i = 0; i < N; ++i)
#define all(v) v.begin(), v.end()
#define rev(v) v.rbegin(), v.rend()
#define makei(N) int N; cin >> N;
#define makel(N) ll N; cin >> N;
#define makes(s) string s; cin >> s;
#define maked(d) double d; cin >> d;
#define makev(v, N) vi v(N); rep(N)cin >> v[i];
#define mod 1000000007
#define re return 0
#define distance(x1,y1,x2,y2) sqrt((x1 - x2)*(x1 - x2) + (y1 - y2)*(y1 - y2));

using namespace std;
using ll = long long int;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vll = vector<ll>;
using vb = vector<bool>;
using vvb = vector<vector<bool>>;
using vs = vector<string>;
using pii = pair<int, int>;
using pis = pair<int, string>;
using msi = map<string, int>;

template<typename T>
void say(T s) {
	cout << s << "\n";
}

template<typename T>
void say(vector<T> s) {
	auto itr = s.begin();
	cout << *(itr++);
	while (itr != s.end()) {
		cout << " " << *(itr++);
	}
	cout << "\n";
}

void yn(bool b) {
	if (b)say("Yes");
	else say("No");
}

void YN(bool b) {
	if (b)say("YES");
	else say("NO");
}

template<typename T>
void maxi(T &a, T b) {
	a = max(a, b);
}

template<typename T>
void mini(T &a, T b) {
	a = min(a, b);
}

void exact_say(double x) {
	cout << setprecision(numeric_limits<double>::max_digits10) << x << endl;
}

int main() {
	int n, m, Q;
	cin >> n >> m >> Q;
	int v[501][501];
	memset(v, 0, sizeof(v));
	rep(m) {
		int l, r;
		cin >> l >> r;
		Rep(r, 501)++v[l][i];
	}
	rep(Q) {
		ll ans = 0;
		int p, q;
		cin >> p >> q;
		FOR(i, p,501) {
			ans += v[i][q];
		}
		say(ans);
	}
}


Measured memory_bytes: 1920
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <tuple>
#include <cstring>
#include <functional>
using namespace std;
typedef long long ll;
typedef pair<long long, long long> P;
#define rep(i, n) for(long long i=0; i<n; i++)
#define reps(i, s, e) for(long long i=s; i<e; i++)
#define repr(i, n) for(long long i=n-1; i>=0; i--)
#define reprs(i, s, e) for(long long i=e-1; i>=s; i--)

int main(){

    cin.tie(0);
    ios::sync_with_stdio(false);

    int n; cin >> n;

    string s; cin >> s;

    int ans = 1;
    rep(i, n-1){
        if(s[i] != s[i+1]){
            ans++;
        }
    }

    cout << ans;

    return 0;
}

Measured memory_bytes: 512
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;

/**
 * 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;
		InputReader in = new InputReader(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		Task solver = new Task();
		solver.solve(1, in, out);
		out.close();
	}

	static class Task {
		public void solve(int testNumber, InputReader in, PrintWriter out) {
			String S = in.next();
			int count = 0;
			int ans = 0;
			for(int i  = 0; i < S.length(); i++) {
				count = 0;
				for(int j = i; j < S.length(); j++) {
					if(S.charAt(j) == 'A' || S.charAt(j) == 'C' || S.charAt(j) == 'G' || S.charAt(j) == 'T') {
						count++;
					} else {
						break;
					}
					ans = Math.max(count, ans);
				}
			}
			System.out.println(ans);
		}
	}

	static boolean permutation_2(String s, String t) {
		if (s.length() != t.length()) {
			return false;
		}

		int[] letters = new int[256];

		char[] s_array = s.toCharArray();
		for (char c : s_array) {
			letters[c]++;
		}

		for (int i = 0; i < t.length(); i++) {
			int c = (int) t.charAt(i);
			if (--letters[c] < 0) {
				return false;
			}
		}
		return true;
	}

	static class InputReader {
		public BufferedReader reader;
		public StringTokenizer tokenizer;

		public InputReader(InputStream stream) {
			reader = new BufferedReader(new InputStreamReader(stream), 32768);
			tokenizer = null;
		}

		public String next() {
			while (tokenizer == null || !tokenizer.hasMoreTokens()) {
				try {
					tokenizer = new StringTokenizer(reader.readLine());
				} catch (IOException e) {
					throw new RuntimeException(e);
				}
			}
			return tokenizer.nextToken();
		}

		public char nextChar() {
			return next().charAt(0);
		}

		public int nextInt() {
			return Integer.parseInt(next());
		}

		public double nextDouble() {
			return Double.parseDouble(next());
		}

		public long nextLong() {
			return Long.parseLong(next());
		}

	}
}


Measured memory_bytes: 22868
#include <bits/stdc++.h>
#define pb push_back
using namespace std;

inline int read()
{
	int sum=0,ff=1; char ch=getchar();
	while(!isdigit(ch))
	{
		if(ch=='-') ff=-1;
		ch=getchar();
	}
	while(isdigit(ch))
		sum=sum*10+(ch^48),ch=getchar();
	return sum*ff;
}

int n;

int main()
{
	n=read();
	int ans=0;
	for ( int i=1;i<=n;i++ ) 
		for ( int j=1;j<=n;++j ) 
			for ( int k=1;k<=n;k++ ) 
				ans=(ans+__gcd(__gcd(i,j),k));
	printf("%d\n",ans);
	return 0;
}

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

const int nax = 55;

int main()
{
	using ll = long long;
	int n, a;
	cin >> n >> a;
	vector<int> x(n);
	for(int& i: x) cin >> i;
		
	vector<vector<ll>> dp(nax, vector<ll>(nax*nax));
	dp[0][0] = 1;
	for(int i = 0; i < n; i++) {
		for(int j = i; j >= 0; j--) {
			for(int k = 0; k < nax*nax; k++) {
				if(k + x[i] < nax*nax) {
					dp[j+1][k+x[i]] += dp[j][k];
				}
			}
		}
	}
	
	ll ans = 0;
	for (int i = 1; i <= n; i++) {
		ans += dp[i][i * a];
	}
	cout << ans << endl;
}


Measured memory_bytes: 4572
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define pb(x) push_back(x);
#define mp(x,y) make_pair(x,y)
#define mem(dp,a) memset(dp,a,sizeof dp);
#define all(a) a.begin(),a.end()
#define sall(a) sort(all(a))
#define X first
#define Y second
typedef long long int ll;
typedef pair<ll,ll> pp;

#define debug(x) cout << #x << " :: "<< x <<"\n";
#define debug2(x,y) cout << #x << " :: "<< x << "\t" << #y << " :: " << y << "\n";
#define debug3(x,y,z) cout << #x << " :: "<< x << "\t" << #y << " :: " << y << "\t" << #z << " :: " << z << "\n";
#define boost ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_set tree< pp , null_type,less< pp >, rb_tree_tag,tree_order_statistics_node_update>

ll power(ll b, ll exp){
    ll res = 1;
    while(exp > 0){
        if(exp % 2){
            res = 1LL * res * b % mod;
        }
        b = 1LL * b * b % mod;
        exp /= 2;
    }
    return res;
}

int main()
{
    boost
    string S,T;
    cin >> S >> T;
    ll n=S.size(),m=T.size(),ans=m;
    for(ll i=0;i<=n-m;i++)   {
        ll len=0;
        for(ll j=0;j<m;j++) {
            len+=( S[i+j]!=T[j] );
        }
        ans=min(ans,len);
    }
    cout << ans ;
    return 0;
}


Measured memory_bytes: 3616
#include <bits/stdc++.h>
using ll = long long;
#define FOR(i, k, n) for(ll i = (k); i < (n); i++)
#define FORe(i, k, n) for(ll i = (k); i <= (n); i++)
#define FORr(i, k, n) for(ll i = (k)-1; i > (n); i--)
#define FORre(i, k, n) for(ll i = (k)-1; i >= (n); i--)
#define REP(i, n) FOR(i, 0, n)
#define REPr(i, n) FORre(i, n, 0)
#define ALL(x) (x).begin(), (x).end()
#define ALLr(x) (x).rbegin(), (x).rend()
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
using namespace std;

const int INF = 1001001001;

int main(void){
  string c, t;
  cin >> c >> t;
  c += t;
  REP(i, 6){
    if(c[i] != c[5-i]){
      cout << "NO" << endl;
      return 0;
    }
  }
  cout << "YES" << endl;
  return 0;
}

Measured memory_bytes: 256
// questionA.cpp : Defines the entry point for the application.
//

#include <iostream>
#include <map>

using namespace std;

int main()
{
	//cout << "Hello cmake!" << endl;
	int a;
	cin >> a;

	auto plus_one = [&a](int x)->int {return a*(1 + x); };
	cout << plus_one(plus_one(a)) << endl;

	return 0;
}

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

int main(void) {
  int n;
  cin >> n;
  vector<int> as(n);
  for (int &a : as) cin >> a;

  int result = 0;
  for (int i = 0; i < n; i += 2) {
    if (as[i] % 2 == 1) result++;
  }

  cout << result << endl;
  return 0;
}

Measured memory_bytes: 3620
#include<iostream>
#include<algorithm>

using namespace std;

int main(){
    int a,ans=0,e=100000;
    for(int i=0;i<5;i++){
        cin>>a;
        ans+=((a+9)/10)*10;
        e=min(e,(a-1)%10);
    }
    cout<<ans-9+e<<endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
string print="RYGB";
int main(){
    cin.tie(NULL); cout.tie(NULL);
    ios_base:: sync_with_stdio(false);
    ll h,w,d;cin>>h>>w>>d;

    for(ll i=1;i<=h;i++){
        for(ll j=1;j<=w;j++){
            ll x = (w+i+j)/d;
            x%=2;

            ll y = (w+i-j)/d;
            y%=2;

            cout<<print[2*x + y];
        }
        cout<<"\n";
    }
}





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

bool check(int n, int a) {
    if (n == 1) return a == 1;
    if (a >= (1<<(n-1))) return !check(n-1, a^(1<<(n-1)));
    else return check(n-1, a);
}

vector<int> construct(int n, int a) {
    if (n == 1) return {a, a^1};
    if (a >= (1<<(n-1))) {
        int b = a ^ (1<<(n-1)) ^ 1;
        auto v1 = construct(n-1, b);
        for (int &x : v1) x ^= (1<<(n-1)) | 1;
        auto v2 = construct(n-1, 1);
        v1.insert(v1.end(), v2.begin(), v2.end());
        return v1;
    } else {
        auto v1 = construct(n-1, a);
        auto v2 = construct(n-1, *next(v1.rbegin()));
        for (int &x : v2) x ^= (1<<(n-1));
        v1.insert(v1.end()-1, v2.begin(), v2.end());
        return v1;
    }
}

int main() {
    int n, a, b; cin >> n >> a >> b;
    if (!check(n, a^b)) cout << "NO\n";
    else {
        cout << "YES\n";
        auto vec = construct(n, a^b);
        for (int x : vec) cout << (x^b) << ' ';
        cout << endl;
    }
}


Measured memory_bytes: 1648
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const ll maxn = 1e5 + 5;
const ll maxm = 1e3 + 5;
namespace IO{
    const int SIZE = (1 << 20) + 1;
    char ibuf[SIZE], *iS, *iT, obuf[SIZE],*oS = obuf, *oT = obuf + SIZE - 1;
    char _st[55];
    int _qr = 0;
    inline char gc(){
        return (iS == iT ? iT = (iS = ibuf) + fread(ibuf, 1, SIZE, stdin), (iS == iT ? EOF : *iS++) : *iS++);
    }
    inline void qread(){}
    template<class T1, class ...T2>
    inline void qread(T1 &IEE, T2&... ls){
        register T1 __ = 0, ___ = 1;
        register char ch;
        while(!isdigit(ch = gc())) ___ = (ch == '-') ? -___ : ___;
        do{
            __ = (__ << 1) + (__ << 3) + (ch ^ 48);
        }while(isdigit(ch = gc()));
        __ *= ___;
        IEE = __;
        qread(ls...);
        return ;
    }
    inline void flush(){
        fwrite(obuf, 1, oS - obuf, stdout);
        oS = obuf;
        return ;
    }
    inline void putc_(char _x){
        *oS++ = _x;
        if(oS == oT) flush();
    }
    inline void qwrite(){}
    template<class T1, class ...T2>
    inline void qwrite(T1 IEE, T2... ls){
        if(!IEE) putc_('0');
        if(IEE < 0) putc_('-'), IEE = -IEE;
        while(IEE) _st[++_qr] = IEE % 10 + '0', IEE /= 10;
        while(_qr) putc_(_st[_qr--]);
        qwrite(ls...);
        return ;
    }
    struct Flusher_{~Flusher_(){flush();}}io_flusher;
}
using namespace IO;
string s;
int main(){
    cin >> s;
    ll sum = 0;
    for(int i = 0;i < s.size();i++){
        sum += s[i] - '0';
    }
    if(sum % 9 == 0){
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 3720
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<map>
#include<algorithm>
using namespace std;
#define N 100010
#define LL long long

LL a[N];
map<LL,int> vis;
int n,m; 

int main(){
	a[0]=0;
	scanf("%d%d",&n,&m);
	for (int i=1; i<=n; i++){
		scanf("%d",&a[i]);
		a[i]+=a[i-1];
	}
	LL ans=0;
	vis[0]=1;
	//for (int i=1; i<=n; i++) cout<<a[i]<<" "; cout<<endl;
	for (int i=1; i<=n; i++){
		LL x=a[i]%m;
	//	cout<<i<<" "<<x<<endl;
		if (vis[x]!=0) ans+=vis[x];
		vis[x]++;
	}
	cout<<ans<<endl;
} 

Measured memory_bytes: 4992
n = gets.to_i
lines = gets.chomp.split.map(&:to_i)
h = Hash.new(0)
lines.each{|x| h[x] += 1}
lines2 = []
h.each{|k, v|
    lines2 << k if v > 1
    lines2 << k if v > 3
}
lines2.sort!.reverse!
if lines2.length > 1
    puts lines2[0] * lines2[1]
else
    puts 0
end


Measured memory_bytes: 16004
A,B,C = map(int, input().split())
K = int(input())

if B<=A:
    num1=0
    while B*(2**num1)<=A:
        num1+=1
    B=B*(2**num1)
    if C<=B:
        num2=0
        while C*(2**num2)<=B:
            num2+=1
        if K>=(num1+num2):
            print('Yes')
        else:
            print('No')
    else:
        if K>=num1:
            print('Yes')
        else:
            print('No')
            
else:
    if C<=B:
        num2=0
        while C*(2**num2)<=B:
            num2+=1
        if K>=(num2):
            print('Yes')
        else:
            print('No')
    else:
        print('Yes')

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

#define pb push_back


int main()
{
	int N, M;
	int vote;
	float sum = 0;
	vector<int> votes;

	cin>>N>>M;

	for(int i=0; i<N; i++)
	{
		cin>>vote;
		votes.pb(vote);
		sum += vote;
	}
	float over = 4*M;

	float min = sum/over;

	sort(votes.rbegin(), votes.rend() );

	if(M>N)
		cout<<"No"<<endl;
	else
	{
		if(votes[M-1] < min)
			cout<<"No"<<endl;
		else
			cout<<"Yes"<<endl;
	}
	

}


Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define MOD 1000000007
#define INF (1<<30)
#define LINF (1LL<<60)
#define endl "\n"
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define reprev(i,n) for(int (i)=(n-1);(i)>=0;(i)--)
#define Flag(x) (1<<(x))
#define Flagcount(x) __builtin_popcount(x)
#define pint pair<int,int>
#define pdouble pair<double,double>
typedef unsigned long long int ull;
typedef long long lint;
 
int main(void){
  int N,K,Q;
  cin >> N >> K >> Q;
  int A[Q];
  rep(i,Q) cin >> A[i];
  int score[N];
  rep(i,N) score[i]=K-Q;
  rep(i,Q){
    score[A[i]-1]++;
  }
  rep(i,N){
    if(score[i]<=0) cout << "No" << endl;
    else cout << "Yes" << endl;
  }
}

Measured memory_bytes: 1408
#include <stdio.h>
#define MAX 100000
#define SENTINEL 2000000000

struct Card {
  char suit;
  int value;
};

struct Card L[MAX/2+2], R[MAX/2+2];

void merge(struct Card A[], int n, int left, int mid, int right) {
  int i, j, k;
  int n1 = mid - left;
  int n2 = right - mid;
  for(i=0;i<n1;i++) L[i] = A[left + i];
  for(i=0;i<n2;i++) R[i] = A[mid  + i];
  L[n1].value = R[n2].value = SENTINEL;
  i = j = 0;
  for(k=left; k<right; k++) {
    if(L[i].value <= R[j].value) {
      A[k] = L[i++];
    } else {
      A[k] = R[j++];
    }
  }
}

void mergeSort(struct Card A[], int n, int left, int right) {
  if(left+1 < right) {
    int mid = (left+right) / 2;
    mergeSort(A,n,left,mid);
    mergeSort(A,n,mid, right);
    merge(A,n,left,mid,right);
  }
}

int partition(struct Card A[], int n, int p, int r) {
  int i, j;
  struct Card t, x;
  x = A[r];
  i = p-1;
  for(j=p; j<r; j++) {
    if(A[j].value <= x.value) {
      i++;
      t=A[i]; A[i]=A[j]; A[j]=t;
    }
  }
  t=A[i+1]; A[i+1]=A[r]; A[r]=t;
  return i+1;
}

void quickSort(struct Card A[], int n, int p, int r) {
  int q;
  if(p<r) {
    q = partition(A,n,p,r);
    quickSort(A,n,p,q-1);
    quickSort(A,n,q+1,r);
  }
}

int main() {
  int n, i, v;
  struct Card A[MAX], B[MAX];
  char S[10];
  int stable = 1;

  scanf("%d", &n);

  for(i=0;i<n;i++) {
    scanf("%s %d",S,&v);
    A[i].suit =  B[i].suit  = S[0];
    A[i].value = B[i].value = v;
  }

  mergeSort(A,n,0,n);
  quickSort(B,n,0,n-1);

  for(i=0;i<n;i++) {
    if(A[i].suit != B[i].suit) stable = 0;
  }

  if(stable==1) printf("Stable\n");
  else printf("Not stable\n");
  for(i=0;i<n;i++) {
    printf("%c %d\n",B[i].suit,B[i].value);
  }

  return 0;
}

Measured memory_bytes: 4048
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int A,ANS=0;
    cin>>A;
    int B[A];
    for(int i=0;i<A;i++){
        cin>>B[i];
    }
    for(int i=0;i<A;i++){
    for(int j=i+1;j<A;j++){
        ANS+=B[i]*B[j];
    }
        
    }
    cout<<ANS<<endl;
    return 0;
}


Measured memory_bytes: 256
n=int(input())
a=sorted(map(int, input().split()))
a1=[i for i in a if i>=0]
a2=[i for i in a if i<0]
if a1 and a2:
    print(sum(a1)-sum(a2))
    mx,mn=a1[-1], a2[0]
    for i in a1[:-1]:
        print(mn,i)
        mn-=i
    for i in a2[1:]:
        print(mx,i)
        mx-=i
    print(mx,mn)
elif not a2:
    print(sum(a1[1:])-a1[0])
    mx,mn=a1[-1], a1[0]
    for i in a1[1:-1]:
        print(mn,i)
        mn-=i
    print(mx,mn)
else:
    print(a2[-1]-sum(a2[:-1]))
    mx,mn=a2[-1], a2[0]
    for i in a2[1:-1]:
        print(mx,i)
        mx-=i
    print(mx,mn)

Measured memory_bytes: 14060
#include<iostream>
#include<ctype.h>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
inline int read(){
	int x=0,f=0;char ch=getchar();
	while(!isdigit(ch))f|=ch=='-',ch=getchar();
	while(isdigit(ch))x=x*10+(ch^48),ch=getchar();
	return f?-x:x;
}
int a[10001],ans;
int main(){
	int n=read();n+=n;
    for(int i=1;i<=n;i++)a[i]=read();
    sort(a+1,a+1+n);
    for(int i=1;i<=n;i+=2)ans+=a[i];
    printf("%d\n",ans);
    return 0;
}

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

int main(){
    long double a,b,c,l;
    scanf("%Lf",&l);
    a =l/3;
    b =l/3;
    c =l -a-b;
    printf("%.12Lf\n",a*b*c);
    return 0;
}


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

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


Measured memory_bytes: 256
from collections import Counter
n = int(input())
a_input = list(map(int,input().split()))

a_count = Counter(a_input)

score_dic={}
exclude_dic={}

for k,v in a_count.items():
    score_dic[k]=v*(v-1)//2
    exclude_dic[k]=(v-1)*(v-2)//2

score_sum = sum(score_dic.values())

for i in range(n):
    print(score_sum-score_dic[a_input[i]]+exclude_dic[a_input[i]])


Measured memory_bytes: 149484
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
using namespace std;

int main(){
    string s;
    cin>>s;
    if(s=="SUN")
    cout<<7<<endl;
    if(s=="MON")
    cout<<6<<endl;
    if(s=="TUE")
    cout<<5<<endl;
    if(s=="WED")
    cout<<4<<endl;
    if(s=="THU")
    cout<<3<<endl;
    if(s=="FRI")
    cout<<2<<endl;
    if(s=="SAT")
    cout<<1<<endl;
    return 0;
}

Measured memory_bytes: 256
def how_many_times_divisible(n):
	ans = 0
	while n % 2 == 0:
		n /= 2
		ans += 1
	return ans
 
n = int(input())
a = map(int,input().split())
ans = min(map(how_many_times_divisible, a))
 
print (ans)

Measured memory_bytes: 2940
N, M = list(map(int, input().split()))
if (N==1) and (M==0):
  print(0)
  exit()
B = {}
for i in range(M):
  k, v = input().split()
  if (k in B) and (B.get(k)!=v):
    print(-1)
    exit()
  else:
    B[k] = v
if (N!=1) and (B.get("1", "99")=="0"):
  print(-1)
  exit()
ans = B.get("1", "1")
for i in range(2, N+1):
  ans = ans + str(B.get(str(i), 0))
print(ans)

Measured memory_bytes: 3064
#include <iostream>

int main(int, char**) {
  int a, b, c, k;
  std::cin >> a >> b >> c>> k;
  if(k <= a ) {
    std::cout << k << std::endl;;
  } else if(k <= a + b) {
    std::cout << a << std::endl;;
  } else {
    std::cout << a - (k - (a + b)) << std::endl;
  }
}


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

#define rep(i,n) for(int i = 0; i < n; i++)
#define REP(i,n) for(int i = 1; i < n; i++)
#define per(i,n) for(int i = n; i >= 0; i--)
#define sz(x) int(x.size())
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define YesorNo(a) printf(a ? "Yes\n" : "No\n")
#define endl '\n'
#define fi first
#define se second
using ll = long long;
using P = pair<int,int>;
using Pl = pair<ll,ll>;
using vi = vector<int>;
using vii = vector<vi>;
using vl = vector<ll>;
using vll = vector<vl>;
using vs = vector<string>;
using vb = vector<bool>;
using vc = vector<char>;
using vcc = vector<vc>;
const int dx[] = {0,1,0,-1,1,1,-1,-1};
const int dy[] = {1,0,-1,0,1,-1,-1,1};
const int inf = (1<<30)-1;
const ll infll = (1LL<<62)-1;
ll ceil(const ll &a, const ll &b){return ((a)+(b)-1)/b;}
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; }



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

  string s;
  cin >> s;
  string c[4] = {"dream", "dreamer", "erase", "eraser"};
  string t = "";
  while(sz(s)) {
    bool ok = false;
    rep(i,4) {
      if(sz(s) < sz(c[i])) continue;
      if(s.substr(sz(s) - sz(c[i])) == c[i]) {
        ok = true;
        s.erase(sz(s)-sz(c[i]));
      }
    }
    if(ok == false) {
      cout << "NO" << endl;
      return 0;
    }
  }
  cout << "YES" << endl;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)   FOR(i,0,n)
#define pb emplace_back
typedef long long ll;
typedef pair<int,int> pint;

vector<int> g[100001];
int par[100001],dep[100001];
bool nroot[100001];
void dfs(int v,int p,int d){
    par[v]=p,dep[v]=d;
    rep(i,g[v].size()){
        dfs(g[v][i],v,d+1);
    }
}
int main(){
    int n;
    cin>>n;
    int id,k,ci;
    rep(i,n){
        cin>>id>>k;
        rep(i,k){
            cin>>ci;
            g[id].pb(ci);
            nroot[ci]=true;
        }
    }
    int root;
    rep(i,n)if(!nroot[i]) root=i;
    dfs(root,-1,0);
    rep(i,n){
        cout<<"node "<<i<<": parent = "<<par[i]<<", depth = "<<dep[i]<<", ";
        if(root==i) cout<<"root";
        else if(g[i].size()>0) cout<<"internal node";
        else cout<<"leaf";
        cout<<", [";
        rep(j,g[i].size()) cout<<g[i][j]<<(j+1==g[i].size()?"":", ");
        cout<<"]"<<endl;
    }
    return 0;
}


Measured memory_bytes: 7112
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
template<class T>inline bool chmax(T &a, const T &b){if(a < b){a = b; return 1;}return 0;}
template<class T>inline bool chmin(T &a, const T &b){if(a > b){a = b; return 1;}return 0;}
typedef long long ll;
int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N, L; cin >> N >> L;
  vector<pair<int, int> > A(N, pair<int, int>());
  int s = 0;
  REP(i, N){
    int tmp = L + i;
    A[i] = {abs(tmp), tmp};
    s += tmp;
  }
  sort(A.begin(), A.end());
  cout << s - A[0].second << endl;
}

Measured memory_bytes: 256
package main

import (
	"fmt"
)

func main() {
	var n int
	fmt.Scan(&n)

	t := make([][]int,n)
	c := make([][]int,n)

	for i:=0; i<n-1; i++ {
		var u,v,w int
		fmt.Scan(&u,&v,&w)
		u--
		v--
		t[u],c[u] = append(t[u],v),append(c[u],w)
		t[v],c[v] = append(t[v],u),append(c[v],w)
	}

	ans := make([]int,n)
	q := make([]int,0)

	for i:=0; i<n; i++ {
		ans[i] = -1
	}

	ans[0] = 0
	q = append(q,0)

	for ;len(q)!=0; {
		p := q[0]
		q = q[1:]
		for i:=0; i<len(t[p]); i++ {
			if ans[t[p][i]]!=-1 {
				continue
			}
			ans[t[p][i]] = (ans[p]+c[p][i])%2
			q = append(q,t[p][i])
		}
	}

	for i:=0; i<n; i++ {
		fmt.Println(ans[i])
	}
}


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

template<uint32_t N>
struct Sieve_of_Eratosthenes{
  using u32 = uint32_t;
  std::vector<u32> factor;
  Sieve_of_Eratosthenes(){
    factor.resize(N+1);
    for(u32 p=2;p<=N;++p){
      if(factor[p])continue;
      factor[p] = p;
      for(u32 x=p+p;x<=N;x+=p){
        if(factor[x])continue;
        factor[x] = p;
      }
    }
  }
  std::vector<u32> prime_factor(u32 x){
    std::vector<u32> pf;
    while(factor[x]){
      pf.push_back(factor[x]);
      x /= factor[x];
      while(factor[x]==pf.back())x/=factor[x];
    }
    return pf;
  }
};

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

  int n;
  cin>>n;
  vector<int> a(n);
  for(auto& ai:a)cin>>ai;

  constexpr int a_max = 1e6;
  Sieve_of_Eratosthenes<a_max> ushi;

  map<int,int> mp;
  bool pairwise_coprime = true;
  for(auto const& ai:a){
    for(auto const& p:ushi.prime_factor(ai)){
      if(mp.count(p)){
        pairwise_coprime = false;
        break;
      }
      mp[p]++;
    }
  }
  
  if(pairwise_coprime){
    cout<<"pairwise coprime"<<endl;
    return 0;
  }

  bool setwise_coprime = accumulate(begin(a),end(a),0,[](auto a,auto b){return gcd(a,b);}) == 1;
  if(setwise_coprime){
    cout<<"setwise coprime"<<endl;
    return 0;
  }

  cout<<"not coprime"<<endl;


}

Measured memory_bytes: 14580
#include "bits/stdc++.h"
using namespace std;
 
int main(){
	int D;cin>>D; 
  
	if (D==22){
      cout<<"Christmas Eve Eve Eve";}
  else if (D==23){
      cout<<"Christmas Eve Eve";}
	else if (D==24){
      cout<<"Christmas Eve";}
  else cout<< "Christmas";
  return 0;}

Measured memory_bytes: 256