akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;

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

int main(){
    int a, b;
    cin >> a >> b;
    int ans = 0;
    if(a<b){
        rep(i, b){
            ans *= 10;
            ans += a;
        }
    }
    else{
        rep(i, a){
            ans *= 10;
            ans += b;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 3580
// ABC055A - 

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

typedef unsigned long long int ull;
typedef long long int ll;

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

	int x = N * 800;
	int y = N / 15 * 200;

	cout << x - y << endl;

	return 0;
}


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

int main(){
    map<int, int> update;
    int n, a, d, m, x, y, z, k;
    cin >> n >> a >> d >> m;
    while(m-- > 0){
        cin >> x >> y >> z;
        y--, z--;
        if(x == 0){
            int toy = (update.count(z) ? update[z] : z);
            int toz = (update.count(y) ? update[y] : y);
            update[y] = toy, update[z] = toz;
        }else{
            if(update.count(z)){
                update[y] = update[z];
            }else{
                update[y] = z;
            }
        }
    }
    cin >> k; k--;
    cout << (update.count(k) ? a + (update[k])*d : a + k*d) << endl;
    return 0;
}


Measured memory_bytes: 3104
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
 
#define rng(i, a, b) for(int i = int(a); i < int(b); i++)
#define rep(i, b) rng(i, 0, b)
#define pb push_back
#define eb emplace_back
#define bg begin()
#define ed end()
#define all(x) x.bg,x.ed
 
int main() {
  int n, m, ans = 0;
  string s;
  cin >> n >> m;
  vector<int> a(m), b(m);
  //if(1) {}
  rep(i, m) {
    cin >> a.at(i) >> b.at(i);
    if(a.at(i) == 1 && n != 1 && b.at(i) == 0) {
      cout << -1 << endl;
      return 0;
    }
    for(int j = 0; j < i; j++) {
      if(a.at(i) == a.at(j) && b.at(i) != b.at(j)) {
        cout << -1 << endl;
        return 0;
      }
    }
  }
  if(n == 1) s = "0";
  else if(n == 2) s = "10";
  else s = "100";
  rep(i, m) {
    s.at(a.at(i) - 1) = '0' + b.at(i);
  }
  cout << s << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
	long long int n,k,str[200000],i,j,temp,sum=0;
	scanf("%d%d",&n,&k);
	for(i=0;i<n;i++){
		scanf("%lld",&str[i]);
	
	}
	if(k>=n){
		printf("0");
	}else {
		sort(str,str+n);
		for(i=0;i<n-k;i++){
			sum+=str[i];
		}
		printf("%lld",sum);
	}
}

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

int main(){
  int n,a;
  cin >> n;
  vector<int> cnt(3,0);
  for(int i=0;i<n;i++){
    cin >> a;
    if(a%4 == 0){
      cnt[0]++;
    }else if(a%2 == 0){
      cnt[1]++;
    }else {
      cnt[2]++;
    }
  }
  if(cnt[0]+1>=(cnt[1]>0)+cnt[2]){
    cout << "Yes" << endl;
  }else {
    cout << "No" << endl;
  }
}
  

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

#define ll long long
#define INF 99999999
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()

int main()
{
    int N;
    cin >> N;
    int ans = -1;
    rep(i,N+1)
    {
        if(i < 10) ans++;
        else if( i > 99 && i <1000) ans++;
        else if(i > 9999 && i < 100000) ans++;
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int MOD = 1000000007;

long long mod_pow(long long x, long long y){
  return y ? mod_pow(x * x % MOD, y / 2) * (y % 2 ? x : 1) % MOD : 1;
}
long long combination(long long x, long long y){
  long long n = 1, k = 1;
  for(int i = x; i > y; --i){
    n = n * i % MOD;
    k = k * (i - y) % MOD;
  }
  return n * mod_pow(k, MOD - 2) % MOD;
}
int main(){
  int n, k;
  cin >> n >> k;
  for(int i = 1; i <= k; ++i){
    if(n - k + 1 < i) cout << 0 << endl;
    else cout << (combination(k - 1, i - 1) * combination(n - k + 1, i)) % MOD << endl;
  }
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<cmath>
#include<algorithm>
#include <numeric>
#include<map>
#include<unordered_map>
#include <queue>
 
using namespace std;
using ll=long long;
#define rep(i,n)  for(ll i=0;i<n;++i)
#define all_map(itr,mp) for(auto itr=mp.begin();itr!=mp.end();itr++)
#define ALL(a) (a).begin(),(a).end()
 
int main(){
    ll n;
    cin >> n;
    vector<ll> d;
    int cnt[24]={};
    bool flag = false;
    rep(i, n){
        int in;
        cin >> in;
        if(cnt[in]<2)d.push_back(in);
        cnt[in]++;
        if(cnt[in]>2)flag = true;
    }
    if(flag||cnt[0]+cnt[12]>2||d.size()>=24){
        cout << 0;
        return  0;
    }
    if(d.size()>18){
        cout << 1;
        return 0;
    }

    ll ans = 0;
    sort(ALL(d));
    ll mn = min(d.front(), 24-d.back());
    ll time = 0;
    rep(i, (1<<d.size())){
        ll s  = mn;
        rep(j, d.size()){
            ll city1;
            if(i&(1<<j))city1 = d[j];
            else city1 = 24-d[j];
            for(ll k=j+1; k<d.size(); ++k){
                ll city2;
                if(i&(1<<k))city2 = d[k];
                else city2 = 24-d[k];
                ll dif = abs(city1-city2);
                s = min(s, min(dif, 24-dif));
            }
        }
        ans = max(s, ans);
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<n; i++)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define fi first
#define se second
long long mo = 1e9 + 7;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
template<class A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}cout << "\n";}
ld PI=3.14159265358979323846;

int main(){
    ll N;
    cin >> N;
    vector<ll> a(N), b(N), c(N), d(N);
    vector<Pll> R(N), B(N);
    rep(i,N){
        cin >> a[i] >> b[i];
        //a[i];
        //b[i];
        R[i] = Pll(a[i], b[i]);
    }
    vector<vector<ll>> note(2*N+100,vector<ll>(2*N+100));
    rep(i,N){
        cin >> c[i] >> d[i];
        //c[i]++;
        //d[i]++;
        B[i] = Pll(c[i], d[i]);
        /*rep(j,c[i]){
            rep(k,d[i]){
                note[j][k]++;
            }
        }*/
    }
    sort(R.begin(), R.end());
    sort(B.begin(), B.end());
    vector<ll> memo(N*2+100);
    ll ans = 0;
    rep(i,N){
        ll cc = B[i].fi;
        ll dd = B[i].se;
        ll id = -1;
        ll score = -1e18;
        rep(j,N){
            if(memo[j]) continue;
            ll aa = R[j].fi;
            ll bb = R[j].se;
            if(aa < cc && bb < dd){
                if(bb >= score){
                //if(score > note[aa][bb]){
                //    score = note[aa][bb];
                    id = j;
                    score = bb;
                }
                //}
            }
        }
        if(id != -1){
            memo[id] = 1;
            ans++;
        }
        /*
        rep(j,cc){
            rep(k,dd){
                note[j][k]--;
            }
        }*/
    }
    cout << ans << endl;
}

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

using namespace std;
typedef long long ll;
#define int ll

#define REP(i,n) for(int i=0;i<n;++i)
#define ALL(name) name.begin(),name.end()
#define SORT(name) sort(name.begin(), name.end())
#define ZERO(p) memset(p, 0, sizeof(p))
#define MINUS(p) memset(p, -1, sizeof(p))
#if 1
#  define DBG(fmt, ...) printf(fmt, ##__VA_ARGS__)
#else
#  define DBG(fmt, ...)
#endif

const ll LLINF = (1LL<<60);
const int INF = (1LL<<30);
const double DINF = std::numeric_limits<double>::infinity();
const int MOD = 1000000007;
#define MAX_N 100010

ll N;
vector<ll> A, B;

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

    cin >> N;
    A.resize(N+1);
    vector<ll> a_tmp1, a_tmp2;
    REP(i, N+1) {
        cin >> A[i];
        a_tmp1.push_back(A[i]);
        a_tmp2.push_back(A[i]);
    }
    B.resize(N);
    REP(i, N) { cin >> B[i]; }

    ll ans1 = 0;
    // 左から順に倒す
    for(int i = 0; i < N; ++i) {
        int rem_b = 0;
        if(a_tmp1[i] < B[i]) {
            rem_b = B[i] - a_tmp1[i];
            ans1 += a_tmp1[i];
            a_tmp1[i] = 0;
        }
        else if(a_tmp1[i] >= B[i]) {
            rem_b = 0;
            a_tmp1[i] -= B[i];
            ans1 += B[i];
        }

        ans1 += min(a_tmp1[i+1], rem_b);
        a_tmp1[i+1] -= rem_b;
        if(a_tmp1[i+1] < 0) { a_tmp1[i+1] = 0; }
    }

    // 右から順に倒す
    ll ans2 = 0;
    for(int i = N; i > 0; --i) {
        int rem_b = 0;
        if(a_tmp2[i] < B[i-1]) {
            rem_b = B[i-1] - a_tmp2[i];
            ans2 += a_tmp2[i];
            a_tmp2[i] = 0;
        }
        else if(a_tmp2[i] >= B[i-1]) {
            rem_b = 0;
            a_tmp2[i] -= B[i-1];
            ans2 += B[i-1];
        }

        ans2 += min(a_tmp2[i-1], rem_b);
        a_tmp2[i-1] -= rem_b;
        if(a_tmp2[i-1] < 0) { a_tmp2[i-1] = 0; }
    }
    printf("%lld\n", max(ans1, ans2));

    return 0;
}

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

typedef struct{
  int parent;
  int left;
  int right;
}node;

int degree(node*,int,int);
int depth(node*,int,int);
int height(node*,int,int);
void print_type(node*,int);
#define NIL -1

int main(){
  int n,id,frag,count;
  int i,j,k;
  int dep;

  node T[25];
  scanf("%d",&n);
  
  for(i=0;i<n;i++){
    T[i].parent=-1;
    T[i].left=-1;
    T[i].right=-1;
  }

  for(i=0;i<n;i++){
    scanf("%d",&id);
    scanf("%d%d",&T[id].left,&T[id].right);
  }
  for(i=0;i<n;i++){
    for(j=0;j<n;j++){
      if(i==T[j].left){
	T[i].parent=j;
      }
      if(i==T[j].right){
	T[i].parent=j;
      }
    }
  }
  
  for(i=0;i<n;i++){
    printf("node %d: parent = %d, ",i,T[i].parent);
    for(j=0,frag=0;j<n;j++){
      if(i==j) continue;
      if(T[i].parent==T[j].parent){
	printf("sibling = %d, ",j);
	++frag;
	break;
      }
    }
    if(frag==0) printf("sibling = -1, ");
    printf("degree = %d, ",degree(T,n,i));
    printf("depth = %d, ",depth(T,n,i));
    printf("height = %d, ",height(T,n,i));
    print_type(T,i);
  }

  return 0;
}

int degree(node *T,int n,int i){
  int count=0;
  int j;
  for(j=n-1;j>=0;j--){
    if(i==j) continue;
    if(i==T[j].parent){
      count++;
    }
  }
  return count;
}

int depth(node *T,int n,int i){
  int count=0;
  int j;
  for(j=0;j<n;j++){
      if(T[i].parent==j){
	count++;
	i=j;
	j=-1;
      }
  }
  
  
  return count;
}

int height(node *T,int n,int i){
  int count=0;
  int h1=0,h2=0;
  
  if(T[i].left!=-1) h1=height(T,n,T[i].left)+1;
  if(T[i].right!=-1) h2=height(T,n,T[i].right)+1;
  if(h1<h2) return h2;
  else return h1;
  
}

void print_type(node *T,int i){
    if(T[i].parent==NIL) printf("root\n");
    else if(T[i].left==NIL && T[i].right==NIL) printf("leaf\n");
    else printf("internal node\n");
}

Measured memory_bytes: 612
#include <iostream>

using namespace std;

//static const long long MOD = 1000000007;

int main() {
    long long N, *H;

    // input
    cin >> N;

    H = new long long[N];
    for (long long i = 0; i < N; i++) {
        cin >> H[i];
    }

    // process
    for (long long i = N - 2; i >= 0; i--) {
        if (H[i] > H[i + 1]) {
            H[i] -= 1;
            if (H[i] > H[i + 1]) {
                cout << "No";
                return 0;
            }
        }
    }
    cout << "Yes";

    return 0;
}

Measured memory_bytes: 1024
//marico el que lo lea
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <stdlib.h>
#include <assert.h>
using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int, int> ii;

void fastIO() {
	std::ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
}

#define FOR(i,f,t) for(int i=f; i<(int)t; i++)
#define FORR(i,f,t) for(int i=f; i>(int)t; i--)
#define FORE(i,c) for(auto i = (c).begin(); i != (c).end(); i++)
#define pb push_back
#define all(obj) obj.begin(), obj.end()
#define ms(obj, val) memset(obj, val, sizeof(obj))
#define ms2(obj, val, sz) memset(obj, val, sizeof(obj[0])*sz)

#define fst first
#define snd second

template<typename T, typename U> inline void mnze(T &x, U y) { if(y < x) x = y; }
template<typename T, typename U> inline void mxze(T &x, U y) { if(x < y) x = y; }

void _scan( int &x ) { scanf("%d",&x); }
void _scan( long long &x ) { scanf("%lld",&x); }
void _scan( double &x ) { scanf("%lf",&x); }
void _scan( char &x ) { scanf(" %c",&x); }
void _scan( char *x ) { scanf("%s",x); }
void scan() {}
template<typename T, typename... U>
void scan( T& head, U&... tail ) { _scan(head); scan(tail...);}

template<typename T> void _dbg(const char* sdbg, T h) { cerr<<sdbg<<"="<<h<<"\n"; }
template<typename T, typename... U> void _dbg(const char* sdbg, T h, U... t) {
	while(*sdbg != ',')cerr<<*sdbg++; cerr<<"="<<h<<","; _dbg(sdbg+1, t...);
}

#ifdef LOCAL
#define debug(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
#define debugv(x) {{cerr <<#x <<" = "; FORE(_i, (x)) cerr <<*_i <<", "; cerr <<"\n"; }}
#define debuga(x, sz) {{cerr <<#x <<" = "; FOR(_i, 0, sz) cerr << x[_i] <<", "; cerr <<"\n"; }}
#else
#define debug(...) (__VA_ARGS__)
#define debugv(x)
#define debuga(x, sz)
#define cerr if(0)cout
#endif

///////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////

const int MAXN = 1e5+5;
int N, a[MAXN];

int main(){
    scan(N);
    FOR(i,0,N) scan(a[i]);
    int cur=1;
    ll ans = 0;
    FOR(i,0,N){
        if(a[i] == cur){
            cur++;
        }else if(a[i] > cur){
            ans += (a[i]-1)/cur;
        }
        if(cur==1) cur++;
    }
    printf("%lld\n",ans);
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
#define rep(i,n) for (ll i=0; i<(n); ++i)
#define rep1(i,n) for (ll i=1; i<=(n); ++i)
typedef long long ll;
bool debug=false;
string yes = "Yes";
string no = "No";
const ll mod = 998244353;
const double e = 0.000000001;

int main(){
  ll n; cin >> n;
  vector<ll> v;
  ll sum=0;
  rep(i,n){
    ll a; cin >> a;
    v.push_back(a);
    sum +=a;
  }
  ll ave1 = sum/n;
  ll ave2 = ave1+1;
  ll ans1=0,ans2=0;
  for(auto e:v){
    ans1+=pow(ave1-e, 2);
    ans2+=pow(ave2-e, 2);
  }
  cout << min(ans1,ans2);
  return 0;
}

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

#define rep(i,n) for(int i = 0; i < (n); ++i)
#define ll long long
#define P pair<ll,ll>
#define all(v) v.begin(),v.end()
const ll mod = 1e9+7;
const ll INF = 1e18;
const double pi = acos(-1.0);

int main(void)
{
    ll n,m; cin>>n>>m;
    vector<vector<bool>> path(n,vector<bool>(n,false));
    rep(i,m){
        ll a,b; cin>>a>>b;
        a--; b--;
        path[a][b]=path[b][a]=true;
    }

    vector<ll> v(n);
    rep(i,n) v[i]=i;

    ll ans=0;

    do{
        if(v[0]!=0) break;
        bool ok=true;
        rep(i,n-1){
            if(!path[v[i]][v[i+1]]) ok=false;
        }
        if(ok) ans++;
    }while(next_permutation(all(v)));
	
    cout<<ans<<endl;

    return 0;
}

Measured memory_bytes: 3612
#include <bits/stdc++.h>
#define dum(x) cout<<#x<<'='<<x<<endl
#define ll long long
using namespace std;

int main() {
  string s;
  cin >> s;
  ll k;
  cin >> k;

  for (int i = 0; i < s.size(); i++) {
    if (s.at(i) != '1') {
      if (k < i + 1) {
        cout << 1 << endl;
        return 0;
      } else {
        cout << s.at(i) << endl;
        return 0;
      }
    }
  }
  cout << 1 << endl;
  return 0;
}


Measured memory_bytes: 256
// DSL_1_A.cpp
// Set - Disjoint Set???Union Find Tree

#include <iostream>
#include <vector>
using namespace std;
const int N = 10000 + 5;
vector<int> id(N, -1);
vector<int> sz(N, 1);
int root(int x)
{
	while (x != id[x]) {
		id[x] = id[id[x]];
		x = id[x];
	}
	return x;
}

void same(int x, int y)
{
	if (root(x) == root(y)) {
		cout << 1 << endl;
	}
	else cout << 0 << endl;
}

void unite(int x, int y)
{
	int rx = root(x);
	int ry = root(y);
	if (rx == ry) return;
	else if (sz[rx] < sz[ry]) {
		id[rx] = ry;
		sz[ry] += sz[rx];
	}
	else {
		id[ry] = rx;
		sz[rx] += sz[ry];
	}
}
int main()
{
	int n, q;
	cin >> n >> q;
	for (int i = 0; i < n; i++) {
		id[i] = i;
	}
	int cmd, x, y;
	while (q--) {
		cin >> cmd >> x >> y;
		if(cmd) {
			same(x, y);
		}
		else unite(x, y);
	}
	return 0;
}

Measured memory_bytes: 3196
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <algorithm>
#include <numeric>

#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;

// int A, B, F, H, I, J, K, L, M, N, S, T, U;
// long long int A, B, F, H, I, J, K, L, M, N, S, T, U;
string S, T, U;
int A, B;
string ans;

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

	cin >> S;

	if (S == "AAA" || S == "BBB")
		ans = "No";
	else
		ans = "Yes";

	cout << ans << endl;
	return 0;
}

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

int main() {
    ll n, a, b;
    cin >> n >> a >> b;

    vector<ll> x(n);
    rep(i,n) cin >> x.at(i);
    ll ans = 0;
    for(int i=1; i<n; i++){
        ll tmp = x.at(i) - x.at(i-1);
        if(tmp*a > b){
            ans += b;
        }
        else ans += tmp * a;
    }

    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1024
#include <stdio.h>;
     
    int main() {
    	int rate1=0,rate2=0,rate3=0,rate4=0,rate5=0,rate6=0,rate7=0,rate8=0,all=0,N,a[100],i,resmin,resmax;
    	scanf("%d",&N);
    	for(i=0;i<N;i++){
    		scanf("%d",&a[i]);
    	}
    	for(i=0;i<N;i++){
    		if((1<=a[i])&&(a[i]<=399)){
    			rate1=1;
    		}
    		else if((400<=a[i])&&(a[i]<=799)){
    					rate2=1;
    				}
    		else if((800<=a[i])&&(a[i]<=1199)){
    					rate3=1;
    				}
    		else if((1200<=a[i])&&(a[i]<=1599)){
    					rate4=1;
    				}
    		else if((1600<=a[i])&&(a[i]<=1999)){
    					rate5=1;
    				}
    		else if((2000<=a[i])&&(a[i]<=2399)){
    					rate6=1;
    				}
    		else if((2400<=a[i])&&(a[i]<=2799)){
    					rate7=1;
    				}
    		else if((2800<=a[i])&&(a[i]<=3199)){
    					rate8=1;
    				}
    		else if(3200<=a[i]){
    			all++;
    		}
    	}
    	resmin = rate1+rate2+rate3+rate4+rate5+rate6+rate7+rate8;
    	if(resmin==0){
    		resmin = 1;
    	}
    	resmax = rate1+rate2+rate3+rate4+rate5+rate6+rate7+rate8+all;
     
    	printf("%d %d",resmin,resmax);
    	return 0;
    }

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

int main()
{
    int arr[3];
    for(int i = 0; i < 3; i++) cin >> arr[i];
    sort(arr, arr+3);
    int res = abs(arr[2] - arr[1]) + abs(arr[1] - arr[0]);
    cout << res << endl;
}

Measured memory_bytes: 3584
#include<cstdio>
#include<cstring>
#include<algorithm>
#define MN 20005
using namespace std;
inline int in(){
    int x=0;bool f=0; char c;
    for (;(c=getchar())<'0'||c>'9';f=c=='-');
    for (x=c-'0';(c=getchar())>='0'&&c<='9';x=(x<<3)+(x<<1)+c-'0');
    return f?-x:x;
}
int p[MN],rk[MN],a[MN],b[MN],n;
int main()
{
	n=in();
	for (int i=0;i<n;++i){
		a[i]=i*n;b[i]=(n-i)*n;p[i]=in();rk[p[i]-1]=i;
	}
	for (int i=0;i<n;++i) a[i]+=rk[i]; 
	for (int i=0;i<n;++i) printf("%d ",a[i]+1);puts("");
	for (int i=0;i<n;++i) printf("%d ",b[i]+1);return 0;
}

Measured memory_bytes: 896
#include<iostream>
#include<vector>
#include<algorithm>
#include<iomanip>

using namespace std;

#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(a) (a).begin(),(a).end()
#define PI 3.141592653589793238
#define INF 1050000000

using vi = vector<int>;


int main() {

	int H, W, h, w;

	cin >> H >> W >> h >> w;

	cout << (H-h)*(W-w) << endl;

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <regex>
#include <numeric>
using namespace std;

/*--- Macro ---*/
#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 mp make_pair
#define pb push_back

/*---  Type ---*/
typedef long long ll;

/*--- Constants ---*/
template <typename T> const T INF = numeric_limits<T>::max() / 10;
const int MOD = (int)1e9 + 7;

// Floating
const double EPS = 1e-11;
#define EQ0(x) (abs(x) < EPS)
#define EQ(x, y) (abs(a-b) < EPS)

// Util
int max(int a, int b, int c) {return max(a, max(b, c));}
int min(int a, int b, int c) {return min(a, min(b, c));}
ll max(ll x, ll y) {return x > y ? x : y;}
ll min(ll x, ll y) {return x < y ? x : y;}
ll max(ll a, ll b, ll c) {return max(a, max(b, c));}
ll min(ll a, ll b, ll c) {return min(a, min(b, c));}

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



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

  ll ans = 1;
  for(int i = 1; i * i <= n; i++) {
    ans = i * i;
  }
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 256
N = $stdin.gets.to_i
A = ('a'..'z').to_a

def calc(n)
  name = ''
  n -= 1
  loop do
    d, m = n.divmod(26)
    if d == 0
      return A[m]
    elsif d <= 26
      name = A[d - 1] + A[m] + name
      return name
    end
    name = A[m] + name
    n = d - 1
  end
end

puts calc(N)


Measured memory_bytes: 14176
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <numeric>
using namespace std;
#define ll long long
#define rep(i,l,r) for(ll i=(l);i<(r);i++)
int main(void){
    int n,x;
    cin>>n>>x;
    vector<int> m(n);
    rep(i,0,n)cin>>m[i];
    x-=accumulate(m.begin(),m.end(),0);
    int mn=1000000000;
    rep(i,0,n)if(mn>m[i])mn=m[i];
    cout<<(n+x/mn)<<endl;
    return 0;
}

Measured memory_bytes: 256
import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def SI(): return sys.stdin.readline()[:-1]

n=II()
aa=MI()
pa=0
ans=0
for a in aa:
    cur=max(0,pa-a)
    ans+=cur
    pa=a+cur
print(ans)



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

const int maxlen=100;
char s[maxlen+1];
char l[maxlen/2+1];
char r[maxlen/2+1];

int main()
{
	cin>>s;
	int len=strlen(s);
	
	for(int i=0; i<len/2; i++)		l[i]=s[i];
	
	int rbegin;
	if(len%2==0)
		rbegin=len/2;
	else
		rbegin=len/2+1;
		
	for(int j=len-1,i=0; j>=rbegin; j--,i++)
	{
		r[i]=s[j];
	}
	
	int ans=0;
	for(int i=0; i<len/2; i++)
	{	
		if(l[i]!=r[i])
			ans++;
	}
	
	cout<<ans<< endl;
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void){
  int n = 0;
  int xa = 0;
  int a[200000] = {0};
  int i = 0;
  
  scanf("%d",&n);
  for(i = 0; i < n; i++){
    scanf("%d",&a[i]);
    xa ^= a[i];
  }
  
  for(i = 0; i < n; i++){
    printf("%d ",a[i] ^ xa);
  }
  
  return 0;
}

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

#define LL long long
typedef pair<int, int> pii;

template< typename T > inline void read(T &x)
{
    static char _c;
    static bool _f;

    x = 0;
    _f = 0;
    _c = getchar();

    while(_c < '0' || '9' < _c) {if(_c == '-') _f = true; _c = getchar();}
    while('0' <= _c && _c <= '9') {x = (x << 1) + (x << 3) + (_c & 15); _c = getchar();}
    if(_f) x = -x;
}

template < typename T > inline void Min(T &x, T y) {if(y < x) x = y;}
template < typename T > inline void Max(T &x, T y) {if(x < y) x = y;}


#define lowbit(x) ((x) & -(x))
#define lson l,mid,id<<1
#define rson mid+1,r,id<<1|1
#define ls id<<1
#define rs id<<1|1
#define MID(l,r) ((l)+(((r)-(l))>>1))
#define fi first
#define se second
#define mk make_pair
#define pb push_back

const int INF = 0x3f3f3f3f;
const double pi = (double) acos(-1.0);
const double eps = (double) 1e-8;
const int MOD = (int) 1e9 + 7;
//const int MOD = (int) 998244353;
const int maxn = (int) 1e5 + 20;
const int maxm = (int) 1e6 + 20;

inline int sig(double x) {return x < -eps ? -1 : eps < x;}
LL fp(LL a, LL n, LL MOD)
{
    if(n < 0) a = fp(a, MOD - 2, MOD), n = -n;
    LL res = 1; for(; n; n >>= 1, a = a * a % MOD) if(n & 1) res = res * a % MOD; return res;
}

LL po[33];

void pre()
{
    po[0] = 1;
    for(int i = 1; i <= 30; i++) po[i] = po[i - 1] * 3;
}

LL func(int dep, LL a, LL b, LL c, LL d)
{
    if(dep == -1) return abs(b - d);

    LL w = po[dep];

    if(a / w != c / w) return abs(a - c) + abs(b - d);
    if(a / w == 1 && abs(b / w - d / w) >= 2)
    {
        return abs(b - d) + min(a % w + c % w + 2, w * 2 - a % w - c % w);
    }
    return func(dep - 1, a % w, b, c % w, d);
}

void work()
{
    LL a, b, c, d;
    cin >>a >>b >>c >>d;
    a--; b--; c--; d--;

    if(abs(a - c) > abs(b - d))
    {
        swap(a, b);
        swap(c, d);
    }

    cout <<func(29, a, b, c, d) <<endl;
}

int main(int argc, char **argv)
{
#ifdef yukihana0416
freopen("in.txt", "r", stdin);
//freopen("out.txt", "w", stdout);
#endif // yukihana0416
//    get_prime();
    pre();
    int tc = 1;
    read(tc);
    for(int ca = 1; ca <= tc; ca++)
    {
//        printf("Case #%d: ", ca);
        work();
    }
    return 0;
}


Measured memory_bytes: 384
#include <vector>
#include <list>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include <utility>
#include <functional>
#include <sstream>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
#include <cassert>
using namespace std;
inline int toInt(string s) {int v; istringstream sin(s); sin>>v; return v;}
template<class T> inline string toString(T x) {ostringstream sout; sout << x; return sout.str();}
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define EACH(t,i,c) for(t::iterator i=(c).begin(); i!=(c).end(); ++i)
const double EPS = 1e-10;
const double PI = acos(-1.0);

map<string,int> dp;
set<string> visited;

int suite(int n){
	return n/10;
}

int digit(int n){
	return n%10;
}

string boardkey(vvi &c){
	string ret;
	REP(i,4){
		REP(j,8){
			string sc;
			sc+=(char)((c[i][j]/10)+'0');
			sc+=(char)((c[i][j]%10)+'0');
			ret+=sc;
		}
	}
	return ret;
}

const int MAX=INT_MAX/10;

typedef vector<vvi> vvvi;
typedef vector<vvvi> vvvvi;
int dfs(vvi &c,vector<pii> &gaps,map<int,pii> &pos){
	string key=boardkey(c);
	if(EXIST(dp,key)){
		return dp[key];
	}
	if(EXIST(visited,key)){
		return MAX;
	}
	visited.insert(key);
	bool done=true;
	REP(i,4){
		REP(j,8){
			if(c[i][j]!=(i+1)*10+(j+1)&&c[i][j]!=0){
				done=false;
				break;
			}
		}
	}
	if(done){
		return dp[key]=0;
	}
	int ret=MAX;
	REP(i,4){
		if(gaps[i].second>0){
			pii left=make_pair(gaps[i].first,gaps[i].second-1);
			if(digit(c[left.first][left.second])<7&&c[left.first][left.second]){
				vvi nc(c);
				nc[gaps[i].first][gaps[i].second]=c[left.first][left.second]+1;
				pii moved=pos[c[left.first][left.second]+1];
				nc[moved.first][moved.second]=0;
				vector<pii> ngaps(gaps);
				ngaps[i]=moved;
				map<int,pii> newpos(pos);
				newpos[c[left.first][left.second]+1]=gaps[i];
				ret=min(ret,dfs(nc,ngaps,newpos)+1);
			}
		}
	}
	return dp[key]=ret;
}

int main(){
	int tests;
	cin>>tests;
	REP(test,tests){
		vvi c(4,vi(8));
		REP(i,4){
			REP(j,7){
				cin>>c[i][j+1];
				if(digit(c[i][j+1])==1){
					c[suite(c[i][j+1])-1][0]=c[i][j+1];
					c[i][j+1]=0;
				}
			}
		}
		vector<pii> gaps;
		map<int,pii> pos;
		REP(i,4){
			REP(j,8){
				if(c[i][j]==0){
					gaps.push_back(make_pair(i,j));
				}else{
					pos[c[i][j]]=make_pair(i,j);
				}
			}
		}
		sort(ALL(gaps));
		int ans=dfs(c,gaps,pos);
		cout<<(ans==MAX?-1:ans)<<endl;
		dp.clear();
		visited.clear();
	}
}

Measured memory_bytes: 15692
#include<bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ll long long int
#define ull unsigned long long
#define ld long double

#define mod 1000000007
#define EULER 2.7182818284
#define INF 1000000000

#define pb push_back
#define ins insert
#define IT iterator
#define PQ priority_queue

#define fi first
#define se second
#define maxe max_element
#define mine min_element
#define er erase
#define lb lower_bound
#define ub upper_bound

#define vi vector<int>
#define vll vector<ll>
#define vb vector<bool>
#define pi pair<int,int>
#define pll pair<ll,ll>


#define mem(v,i) memset(v,i,sizeof(v)) // v is array. To set all elements to 0 or -1 only. mem(arr,0);


#define FOR(i,a,b) for(int i=(a);i<=(b);i++)
#define FORd(i,a,b) for(int i=(a);i>=(b);i--)
#define FORl(i,a,b) for(ll i=(a);i<=(b);i++)
#define FORN(i,n) for(int i=(0);i<(n);i++)
#define FORR(i,n) for(int i=(n);i>=0;i--)
#define bs bitset
#define bpc(a) __builtin_popcount(a)

ll max(ll a,ll b)
{
    if(a>b)return a;return b;
}
ll min(ll a,ll b)
{
    if(a<b)return a;return b;
}

ll mypow(ll a, ll b) {
    ll res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a;
        a = a * a;
        b >>= 1;
    }
    return res;
}
ll gcd(ll a,ll b)
{
    if(b==0)
    return a;
    return gcd(b,a%b);
}
//..............................!!!!!!Get ready to fight!!!!!!............................
vector<int>vec[200005];
vector<int>ans[100005];
vector<int>dis(100005,INT_MAX);
vector<bool>vis(100005,false);
void bfs(int src)
{
    dis[src]=0;
    queue<int>q;
    q.push(src);
    while(!q.empty())
    {
        int curr=q.front();
        q.pop();
        if(vis[curr])
        continue;
        vis[curr]=true;
        for(int i=0;i<vec[curr].size();i++)
        {
            int child=vec[curr][i];
            ans[child].pb(curr);
            dis[child]=dis[curr]+1;
            q.push(child);
        }
    }
    
}


int main()
{
    fast
    int  n,m;
    cin>>n>>m;
    while(m--)
    {
        int x,y;
        cin>>x>>y;
        vec[x].pb(y);
        vec[y].pb(x);
    }
    bfs(1);
    bool f=true;
    for(int i=1;i<=n;i++)
    {
        if(dis[i]==INT_MAX)
        {
            f=false;
            break;
        }
    }
    if(!f)
    cout<<"No\n";
    else
    {
        cout<<"Yes\n";
        for(int i=2;i<=n;i++)
        cout<<ans[i][0]<<"\n";
    }
    return 0;
}

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

typedef long long ll;

int main()
{
    ll n,i,j;
    cin>>n;
    ll in[n][3];
    for(i=0;i<n;i++)
    {
        for(j=0;j<3;j++)
        {
            cin>>in[i][j];
        }
    }
    ll ans[n][3];
    ans[0][0]=in[0][0];
    ans[0][1]=in[0][1];
    ans[0][2]=in[0][2];
    for(i=1;i<n;i++)
    {
        for(j=0;j<3;j++)
        {
           if(j==0)
           {
               ans[i][j]=in[i][j]+max(ans[i-1][1],ans[i-1][2]);
           }
           else if(j==1)
               ans[i][j]=in[i][j]+max(ans[i-1][0],ans[i-1][2]);
           else if(j==2)
               ans[i][j]=in[i][j]+max(ans[i-1][0],ans[i-1][1]);
        }
    }
    cout<<max(ans[n-1][0],max(ans[n-1][1],ans[n-1][2]));


}


Measured memory_bytes: 4992
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int a = scanner.nextInt();
		int b = scanner.nextInt();
		int c = scanner.nextInt();
		int d = scanner.nextInt();
		if (Math.abs(a - c) <= d || (Math.abs(a - b) <= d && Math.abs(b - c) <= d)) {
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}
	}

}


Measured memory_bytes: 23764
//  Created by Sengxian on 2017/6/24.
//  Copyright (c) 2017年 Sengxian. All rights reserved.
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
inline int readInt() {
	int n = 0, ch = getchar();
	while (!isdigit(ch)) ch = getchar();
	while (isdigit(ch)) n = n * 10 + ch - '0', ch = getchar();
	return n;
}

const int MAX_N = 200000 + 3;
int n, m;

struct Data {
	int l, r;
	Data(int l = 0, int r = 0) : l(l), r(r) {}
	
	bool operator < (const Data &ano) const {
		return l < ano.l;
	}
} a[MAX_N];

int main() {
	n = readInt(), m = readInt();
	for (int i = 0; i < n; ++i) a[i].l = readInt(), a[i].r = readInt();
	sort(a, a + n);
	
	priority_queue<int, vector<int>, greater<int> > pq1, pq2;
	int ans = 0, pos = 1;
	for (int i = 0; i < n; ++i)
		if (a[i].l >= pos && pos <= m) {
			pq1.push(a[i].r);
			++pos, ++ans;
		} else {
			pq1.push(a[i].r);
			pq2.push(pq1.top());
			pq1.pop();
		}
		
	while (!pq2.empty() && pos <= m) {
		int p = pq2.top(); pq2.pop();
		if (p == m + 1) break;
		++ans;
		pos = max(pos, p) + 1;	
	}
	
	printf("%d\n", n - ans);
	
	return 0;
}


Measured memory_bytes: 3320
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(10000)
INF = 1<<32

YES = "YES"  # type: str
NO = "NO"  # type: str

def solve(S: str):
    # print(''.join(S.split('A')))
    if ''.join(S.split('A')) == "KIHBR":
        if 'AA' not in S and 'KIH' in S:
            print(YES)
            exit()
    
    print(NO)

    return



def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    S = next(tokens)  # type: str
    solve(S)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3060
/// kazuki08
/*
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
*/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define int long long
typedef long long ll;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int,int> pi;
typedef vector<pi> vpi;
#define ar array
//#define inf 1000000000
#define mod 1000000007
#define dmp(x) cerr<<"line "<<__LINE__<<" "<<#x<<":"<<x<<endl
#define fs first
#define sc second
#define pb push_back
#define all(c) (c).begin(),(c).end()
#define mt make_tuple
#define IOS ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
template<class S,class T> ostream& operator<<(ostream& o,const pair<S,T> &p){
    return o<<"("<<p.fs<<","<<p.sc<<")";
}
template<class T> ostream& operator<<(ostream& o,const vector<T> &vc){
    o<<"{";
    for(const T& v:vc) o<<v<<",";
    o<<"}";
    return o;
}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const int MAXN = 202000;
int n;
int dp[2][2020];
string s;

signed main(){
IOS;
//freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);
  
  cin >> s;
  n = s.size();
  int ans = 0;
  for(int i=0;i<s.size();i++){
    for(int j=0;j<2019;j++){
      dp[1][(j*10+(s[i]-'0'))%2019]+=dp[0][j];
    }
    dp[1][s[i]%48]++;
    for(int j=0;j<2019;j++){
      dp[0][j]=dp[1][j];
      dp[1][j]=0;
    }
    ans+=dp[0][0];
  }
  cout << ans << endl;
  

return 0;
}
///....


Measured memory_bytes: 3808
n,m = map(int,input().split())
x = list(map(int,input().split()))
y = list(map(int,input().split()))
xs,ys = 0,0
mod = 10**9+7
for i in range(1,n):
  xs += (x[i]-x[i-1])*i*(n-i)%mod
for i in range(1,m):
  ys += (y[i]-y[i-1])*i*(m-i)%mod
print(xs*ys%mod)

Measured memory_bytes: 18556
// Template
#include "bits/stdc++.h"
#include "atcoder/all"
#define rep_override(x, y, z, name, ...) name
#define rep2(i, n) for (int i = 0; i < (int)(n); ++i)
#define rep3(i, l, r) for (int i = (int)(l); i < (int)(r); ++i)
#define rep(...) rep_override(__VA_ARGS__, rep3, rep2)(__VA_ARGS__)
#define per(i, n) for (ll i = (ll)(n) - 1; i >= 0; --i)
#define all(x) (x).begin(), (x).end()
using namespace std;
using namespace atcoder;
using ll = long long;
constexpr int inf = 1001001001;
constexpr ll INF = 3003003003003003003LL;
template <typename T>
inline bool chmin(T &x, const T &y) {
    if (x > y) {
        x = y;
        return true;
    }
    return false;
}
template <typename T> 
inline bool chmax(T &x, const T &y) {
    if (x < y) {
        x = y;
        return true;
    }
    return false;
}
struct IOSET {
    IOSET() {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(10);
    }
} ioset;

// Segment Tree
template <typename Operator>
struct SegmentTree {
    Operator OP;
    using NodeType = decltype(OP.NodeE);
    int length, n_;
    std::vector<NodeType> node;
    SegmentTree (int n) : n_(n) {
        length = 1;
        while (length < n) length <<= 1;
        node.assign(length << 1, OP.NodeE);
    }
    SegmentTree (std::vector<NodeType> &vec) : n_((int)vec.size()) {
        length = 1;
        while (length < vec.size()) length <<= 1;
        node.assign(2 * length, OP.NodeE);
        rep(i, vec.size()) node[i + length] = vec[i];
        for (int i = length - 1; i > 0; --i) node[i] = OP.func(node[(i << 1) + 0], node[(i << 1) + 1]);
    }
    void update(int idx, NodeType val) {
        assert(idx >= 0 && idx < n_);
        idx += length;
        node[idx] = OP.change(node[idx], val);
        while (idx >>= 1) node[idx] = OP.func(node[(idx << 1) + 0], node[(idx << 1) + 1]);
    }
    NodeType get(int l, int r) {
        assert(l >= 0 && l <= n_ && r >= 0 && r <= n_ && l <= r);
        l += length;
        r += length;
        NodeType vl = OP.NodeE, vr = OP.NodeE;
        while (r > l) {
            if (l & 1) vl = OP.func(vl, node[l++]);
            if (r & 1) vr = OP.func(node[--r], vr);
            l >>= 1;
            r >>= 1;
        }
        return OP.func(vl, vr);
    }
};


struct RMQ {
    using NodeType = int;
    NodeType NodeE = 0;
    NodeType change(NodeType x, NodeType y) {return y;}
    NodeType func(NodeType x, NodeType y) {return max(x, y);}
};


// Main
int main() {
    const int maxa = 300000;
    int n, k;
    cin >> n >> k;
    vector<int> a(n);
    rep(i, n) cin >> a[i];
    SegmentTree<RMQ> st(maxa + 1);
    rep(i, n) {
        int x = st.get(max(a[i] - k, 0), min(a[i] + k, maxa) + 1);
        st.update(a[i], x + 1);
    }
    cout << st.get(0, maxa + 1) << "\n";
}

Measured memory_bytes: 8516
from sys import stdin
nii=lambda:map(int,stdin.readline().split())
lnii=lambda:list(map(int,stdin.readline().split()))

n=int(input())
a=lnii()

mod=10**9+7

ans=0
for i in range(60):
  on=0
  off=0
  for j in a:
    if (j>>i)&1:
      on+=1
    else:
      off+=1
  ans+=(on*off)*(2**i)
  ans%=mod

print(ans)

Measured memory_bytes: 112444
#include <iostream>
#include <algorithm>
#include <vector>
#include <deque>
#include <queue>
#include <list>
#include <stack>
#include <string>
#include <tuple>
#include <functional>
#include <numeric>
#include <cmath>
#include <iomanip>
#include <map>
#include <random>
#include <cstdlib>
#define INT_MAX 2147483647
#define INT_MIN -2147483646
#define Loop(i, n) for(int i = 0; i < (int)n; i++)
#define Loop1(i, n) for(int i = 1; i <= (int)n; i++)
#define Loopr(i, n) for(int i = (int)n - 1; i >= 0; i--)
#define Loopr1(i, n) for(int i = (int)n; i >= 1; i--)
using namespace std;
typedef long long int ll;

int h;
vector<int> A(2000005);

void func1(int a) {
	if (a == 0) return;
	int p = A[a], l = A[a * 2], r = A[a * 2 + 1];
	int m = a;
	if (p < l && r <= l) m = a * 2;
	else if (p < r && l <= r) m = a * 2 + 1;
	if (m != a) {
		int pass = A[m];
		A[m] = p;
		A[a] = pass;
		func1(a / 2);
	}
}

void func2(int a) {
	if (a > h / 2) return;
	int p = A[a], l = A[a * 2], r = A[a * 2 + 1];
	int m = a;
	if (p < l && r <= l) m = a * 2;
	else if (p < r && l <= r) m = a * 2 + 1;
	if (m != a) {
		int pass = A[m];
		A[m] = p;
		A[a] = pass;
		func2(m);
	}
}

void insert(int k) {
	h++;
	A[h] = k;
	func1(h / 2);
}

void extract() {
	cout << A[1] << endl;
	A[1] = A[h];
	A[h] = INT_MIN;
	h--;
	func2(1);
}

int main() {
	Loop(i, 2000005) {
		A[i] = INT_MIN;
	}
	h = 0;
	string q;
	int k;
	while (1) {
		cin >> q;
		if (q == "end") break;
		else if (q == "insert") {
			cin >> k;
			insert(k);
		}
		else if (q == "extract") {
			extract();
		}
	}
	return 0;
}

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

int main()
{
	string w;
	int a[26] = {};

	cin >> w;
	for (int i = 0; i < w.size(); i++)
		a[w[i] - 'a']++;
	for (int i = 0; i < 26; i++) {
		if (a[i] % 2) {
			cout << "No\n";
			break;
		}
		if (i == 25) cout << "Yes\n";
	}
	return 0;
}

Measured memory_bytes: 256
#include <cstdio>

int main()
{
    int A, B;
    if (scanf("%d %d", &A, &B) == EOF) return -1;

    int answer;
    if (A < B) {
        answer = B + B - 1;
    } else if (A == B) {
        answer = A + B;
    } else {
        answer = A + A - 1;
    }
    printf("%d\n", answer);
}


Measured memory_bytes: 128
fun main(args: Array<String>) {
    val s = readLine()!!

    when (s) {
        "SUN" -> "7"
        "MON" -> "6"
        "TUE" -> "5"
        "WED" -> "4"
        "THU" -> "3"
        "FRI" -> "2"
        "SAT" -> "1"
        else -> ""
    }.let(::println)
}




Measured memory_bytes: 31836
import java.util.*;
    public class Main {
     
    	public static void main(String[] args) {
    		Scanner scan = new Scanner(System.in);
    		int a=Integer.parseInt(scan.next());
    		int b=Integer.parseInt(scan.next());
    		
    		int c=Integer.parseInt(scan.next());
    		int d=Integer.parseInt(scan.next());
    		
    		System.out.print(a*b>c*d ? a*b:c*d); ;
    		
    		
    		
    				
    	}
     
    }

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

using namespace std;

#define sz(x) (int) x.size()
#define all(a) a.begin(), a.end()

const int MAXN = 55;
const int MX = 2500;

int n, m, s;
vector<pair<int, pair<int, int>>> g[MAXN];
int c[MAXN], ctm[MAXN];
long long dist[MAXN][MX + 123];
priority_queue < pair <long long, pair<int, int> > > q;

int main() {

    scanf("%d %d %d", &n, &m, &s);
    s = min(s, MX);

    for (int i = 0; i < m; i++) {
        int from, to, cost, tm;
        scanf("%d %d %d %d", &from, &to, &cost, &tm);
        from--; to--;
        g[from].push_back({to, {cost, tm}});
        g[to].push_back({from, {cost, tm}});
    }

    for (int i = 0; i < n; i++) {
        scanf("%d %d", &c[i], &ctm[i]);
        c[i] = min(c[i], MX);
    }

    memset(dist, -1, sizeof(dist));
    dist[0][s] = 0;
    q.push({0, {0, s}});

    while (!q.empty()) {
        long long tm = -q.top().first;
        int city = q.top().second.first, coins = q.top().second.second;
        q.pop();
        if (dist[city][coins] != -1 && tm > dist[city][coins])
            continue;

        if (coins < MX) {
            int gocoins = min(MX, coins + c[city]);
            long long goTm = tm + ctm[city];
            if (dist[city][gocoins] == -1 || dist[city][gocoins] > goTm) {
                dist[city][gocoins] = goTm;
                q.push({-goTm, {city, gocoins}});
            }
        }

        for (auto p : g[city]) {
            int to = p.first, cost = p.second.first, travelTm = p.second.second;
            int gocoins = coins - cost;
            long long goTm = tm + travelTm;
            if (gocoins >= 0 && (dist[to][gocoins] == -1 || dist[to][gocoins] > goTm)) {
                dist[to][gocoins] = goTm;
                q.push({-goTm, {to, gocoins}});
            }
        }
    }

    for (int i = 1; i < n; i++) {
        long long ans = -1;
        for (int j = 0; j <= MX; j++) 
            if (dist[i][j] != -1) {
                if (ans == -1 || dist[i][j] < ans)
                    ans = dist[i][j];
            }
        printf("%lld\n", ans);
    }

    return 0;
}


Measured memory_bytes: 6352
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define INF 1000000
using namespace std;
//65 - 90
int main()
{
    int n;
    while (cin >> n, n)
    {
        int table[100] = {};
        char ch, ans;
        int max_fi = 0, max_sec = 0;
        int pos;
        bool flag = false;
        rep(i, n)
        {
            //cout << max_fi << " " << max_sec << endl;
            cin >> ch;
            table[(int)ch]++;
            if (table[(int)ch] > max_sec)
            {
                if (table[(int)ch] > max_fi)
                {
                    max_fi = table[(int)ch];
                    ans = ch;
                    //cout << ans << endl;
                }
                else
                {
                    max_sec = table[(int)ch];
                }
            }
            if (max_fi > (n - i - 1) + max_sec && flag == false)
            {
                pos = i + 1;
                flag = true;
            }
        }
        int cnt_flag = 0;
        for (int i = 65; i <= 90; i++)
        {
            if (table[i] == max_fi)
                cnt_flag++;
        }
        if (cnt_flag > 1)
        {
            cout << "TIE" << endl;
        }
        else
        {
            cout << ans << " " << pos << endl;
        }
    }
    return 0;
}


Measured memory_bytes: 3088
#include "bits/stdc++.h"
using namespace std;

#define ASC(vec) vec.begin(), vec.end()		// 昇順ソート 例：sort(ASC(vec));
#define DESC(vec) vec.rbegin(), vec.rend()	// 降順ソート 例:sort(DESC(vec));
#define rep(i, n) for(i = 0; i < n; i++)

const int inf = (int)1e9 + 7;
const long long INF = 1LL << 60;

typedef long long ll;

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

/*
int N;
ll h[100010];

// DP テーブル
ll dp[100010];
*/

int main()
{
	int ans = 0;
	int N; cin >> N;
	string S; cin >> S;

	for (int i = 1; i < S.size() - 1; i++)
	{
		int memo1[26] = { 0 };
		int memo2[26] = { 0 };
		int tmp = 0;

		for (int j = 0; j < i; j++)
		{
			int num = S[j] - 97;

			if (memo1[num] < 1)
			{
				memo1[num]++;
			}
		}

		for (int j = i; j < S.size(); j++)
		{
			int num = S[j] - 97;

			if (memo2[num] < 1)
			{
				memo2[num]++;
			}
		}

		for (int i = 0; i < 26; i++)
		{
			if (memo1[i] == 1 && memo2[i] == 1)
			{
				tmp++;
			}
		}

		ans = max(ans, tmp);
	}
	cout << ans << endl;
}


Measured memory_bytes: 256
using System;
using System.IO;
using System.Net;
using System.Net.Sockets;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;
using System.Text.RegularExpressions;
using static System.Math;
using MethodImplOptions = System.Runtime.CompilerServices.MethodImplOptions;
using MethodImplAttribute = System.Runtime.CompilerServices.MethodImplAttribute;

public static class P
{
    static int n;
    public static void Main()
    {
        int n = int.Parse(Console.ReadLine());
        var matrix = Enumerable.Repeat(0, n).Select(_ => Console.ReadLine()).ToArray();
        int res = 0;
        for (int target = 0; target < n; target++)
        {
            var arrivedStep = new int[n];
            Queue<State> queue = new Queue<State>();
            queue.Enqueue(new State() { Pos = target, Step = 1 });
            arrivedStep[target] = 1;
            while (queue.Count > 0)
            {
                var state = queue.Dequeue();
                for (int i = 0; i < n; i++)
                {
                    if (matrix[state.Pos][i] == '0') continue;
                    if (arrivedStep[i] != 0 && (arrivedStep[i] < state.Step - 1 || arrivedStep[i] == state.Step)) goto end;
                    if (arrivedStep[i] != 0) continue;
                    arrivedStep[i] = state.Step + 1;
                    queue.Enqueue(new State() { Pos = i, Step = state.Step + 1 });
                }
            }
            res = Max(res, arrivedStep.Max());
        end:;
        }
        Console.WriteLine(res == 0 ? -1 : res);
    }
}

struct State
{
    public int Pos;
    public int Step;
}


Measured memory_bytes: 13524
n, d = list(map(int, input().split()))
x = [list(map(int, input().split())) for i in range(n)]
ans = 0
for i in range(n):
  for j in range(i+1, n):
    t = 0
    for k in range(d):
      t += (x[i][k]-x[j][k])**2
    t = t**(1/2)
    if t.is_integer():
      ans += 1
print(ans)

Measured memory_bytes: 3188