akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
int main() {
    int N;
    cin >> N;
    vector<int> a(N);
    for(int i = 0; i < N; i++) cin >> a.at(i);
    
    int ans = -1;
    for(int i = 0; i < N; i++) {
        for(int j = 0; j < N; j++) {
            ans = max(ans, abs(a.at(i)-a.at(j)));
        }
    }
    
    cout << ans << endl;
}



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

int nCnt=0;

void insertionSort(int nIn[],int nNum,int nG)
{
	int nMin=0;
	int j=0;
	for(int i=nG;i<=nNum-1;++i)
	{
		nMin=nIn[i];
		j=i-nG;
		while(j>=0 && nIn[j]>nMin)
		{
			nIn[j+nG]=nIn[j];
			j-=nG;
			nCnt++;
		}
		nIn[j+nG]=nMin;
	}
}

void shellsort(int nIn[],int nNum,vector<int>& vecG)
{
	for(int i=1;i<=nNum;)
	{
		vecG.push_back(i);
		i=i*3+1;
	}
	cout<<vecG.size()<<endl;
	for(int i=vecG.size()-1;i>=0;i--)
	{
		cout<<vecG[i];
		if (i!=0)
		{
			cout<<" ";
		}
	}
	cout<<endl;
	for(int i=vecG.size()-1;i>=0;--i)
	{
		insertionSort(nIn,nNum,vecG[i]);
	}
	cout<<nCnt<<endl;
}

int main()
{
	int nNum=0;
	cin>>nNum;
	int nIn[1000000]={0};
	for(int i=0;i<nNum;++i)
	{
		cin>>nIn[i];
	}
	vector<int> vecG;
	shellsort(nIn,nNum,vecG);
	for(int i=0;i< nNum;++i)
	{
		cout<<nIn[i]<<endl;
	}
	return 0;
}


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

int main(){
    int c[3][3];
    for(int i=0;i<3;i++){
        for(int j=0;j<3;j++){
            cin>>c[i][j];
        }
    }
    bool flag=true;
    for(int i=0;i<2;i++){
        if(!(c[i+1][0]-c[i][0]==c[i+1][1]-c[i][1]&&c[i+1][1]-c[i][1]==c[i+1][2]-c[i][2]&&c[i+1][2]-c[i][2]==c[i+1][0]-c[i][0])){
            flag=false;
        }
    }
    if(flag)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define rrep(i,n) RREP(i,n-1,0)
#define all(v) v.begin(), v.end()
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;
const ld eps = 1e-10;

void find_divisor(ll N, vector<ll>& divisor) {
  for(int i=1; i<=sqrt(N); i++) {
    if(N % i == 0)
      divisor.push_back(i);
  }
  int n = divisor.size();
  for(int i=n-1; i>=0; i--) {
    if(N != (ll)pow(divisor[i], 2))
      divisor.push_back(N / divisor[i]);
  }
}
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int k; cin >> k;
  set<ll> rem;
  int ans = 1;
  ll tmp = 7;
  while(tmp < k) {
    tmp = tmp*10+7;
    ans++;
  }
  while(true) {
    ll r = tmp%k;
    if(r == 0) {
      cout << ans << "\n";
      return 0;
    } else if(rem.count(r)) {
      cout << -1 << "\n";
      return 0;
    } else {
      rem.insert(r);
      tmp = r*10+7;
      ans++;
    }
  }
  return 0;
}


Measured memory_bytes: 50364
#include <bits/stdc++.h>
#include<vector>
using namespace std;
#define ll long long int
void minprice(int c[],int und[12][12],int n,int m,int x,string s,int *pr)
{
    if(s.size()==n)
    {
        int *mx=new int[m];
        for(int i=0;i<m;i++)
            mx[i]=0;
         for(int i=0;i<n;i++)
        {
            for(int j=0;j<m;j++)
            {
                if(s[i]=='1')
                    mx[j]+=und[i][j];
            }
        }
        int flag=1;
        for(int i=0;i<m;i++)
        {
            if(mx[i]<x)
                flag=0;
        }
        if(flag)
        {
            int pc=0;
            for(int i=0;i<n;i++)
                if(s[i]=='1')
                    pc+=c[i];
            if(pc<(*pr))
            {
                *pr=pc;
            }
        }
    }
    else
    {
        minprice(c,und,n,m,x,s+'1',pr);
        minprice(c,und,n,m,x,s+'0',pr);
    }
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n,m,x;
    cin>>n>>m>>x;
    int *c=new int[n];
    int und[12][12];
    int *mx=new int[m];
    for(int i=0;i<n;i++)
    {
        cin>>c[i];
        for(int j=0;j<m;j++)
            {
                cin>>und[i][j];
                mx[j]=0;
            }
    }

    for(int i=0;i<n;i++)
    {
        for(int j=0;j<m;j++)
        {
            mx[j]+=und[i][j];
        }
    }
    int flag=1;
    for(int i=0;i<m;i++)
    {
        if(mx[i]<x)
            flag=0;
    }
    if(flag)
    {
        int price=12000000;
        string s1="0";
        string s2="1";
        minprice(c,und,n,m,x,s1,&price);
        minprice(c,und,n,m,x,s2,&price);
        cout<<price<<"\n";
    }
    else
    {
        cout<<"-1\n";
    }
}


Measured memory_bytes: 3884
nn = 2002002
P = 10**9+7
fa = [1]
for i in range(1, nn): fa.append(fa[-1] * i % P)
f = lambda a, b: fa[a+b+2] * pow(fa[a+1] * fa[b+1], P-2, P) % P - 1
r1, c1, r2, c2 = map(int, input().split())
print((f(r2, c2) - f(r2, c1-1) - f(r1-1, c2) + f(r1-1, c1-1)) % P)

Measured memory_bytes: 107144
#include <iostream>
#include <limits.h>
using namespace std;

int main() {
	char s[100100];
	int n = 0;
	cin >> s;
	while (s[n] != '\0') n++;
	for (int i = 0; i < n; i = i + 2) {
	    cout << s[i];
	}
	return 0;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
int main(){
string s,t;
cin>>s>>t;
if(s.length()>t.length()){string te=t;t=s;s=te;}
vector<vector<pair<int,char>>>mat;
//d->match l->left a->above b->break
vector<pair<int,char>>ins(t.length()+1);
for(int i=0;i<t.length()+1;i++){ins[i].first=0;ins[i].second='b';}
for(int i=0;i<s.length()+1;i++){mat.push_back(ins);}
for(int i=1;i<s.length()+1;i++){
	for(int j=1;j<t.length()+1;j++){
		if(s[i-1]==t[j-1]){mat[i][j].first=mat[i-1][j-1].first+1;mat[i][j].second='d';}
		else if(mat[i-1][j].first>mat[i][j-1].first){mat[i][j].first=mat[i-1][j].first;mat[i][j].second='u';}
		else{mat[i][j].first=mat[i][j-1].first;mat[i][j].second='l';}
	//cout<<"<"<<mat[i][j].first<<","<<mat[i][j].second<<"> ";
	}//cout<<endl;
}
int x=s.length(),y=t.length();
string ans;
while(mat[x][y].second!='b'){
	if(mat[x][y].second=='d'){ans+=s[x-1];x--;y--;}
	else if(mat[x][y].second=='l'){y--;}
	else{x--;}
}
for(int i=ans.length()-1;i>=0;i--){cout<<ans[i];}
}


Measured memory_bytes: 70784
N = int(input())
p = [list(map(int, input().split())) for _ in range(N)]
ans = True
for i in range(N):
    if p[i][1] + p[i][2] > p[i][0]:
        ans = False
        break
    if (p[i][1] + p[i][2]) % 2 != p[i][0] % 2:
        ans = False
        break
if ans:
    print("Yes")
else:
    print("No")


Measured memory_bytes: 27300
#include <bits/stdc++.h>
using namespace std;
#define int long long
template <class T>
istream& operator>>(istream& is, vector<T>& v) {
  for (T& x : v)
    is >> x;
  return is;
}
 
template <class T>
ostream& operator<<(ostream& os, const vector<T>& v) {
  if (!v.empty()) {
    for (int i = 0; i < v.size(); ++i)
      os << v[i] << " ";
    os << '\n';
  }
  return os;
}
#define N 200005
int seg_row[3*N];
int seg_col[3*N];
int mar_row[3*N];
int mar_col[3*N];
void push_row(int v) {
    if (mar_row[v]) {
        seg_row[v*2] = seg_row[v*2+1] = seg_row[v];
        mar_row[v*2] = mar_row[v*2+1] = true;
        mar_row[v] = false;
    }
}
void push_col(int v) {
    if (mar_col[v]) {
        seg_col[v*2] = seg_col[v*2+1] = seg_col[v];
        mar_col[v*2] = mar_col[v*2+1] = true;
        mar_col[v] = false;
    }
}
 
void update_row(int v, int tl, int tr, int l, int r, int new_val) {
    if (l > r) 
        return;
    if (l == tl && tr == r) {
        seg_row[v] = new_val;
        mar_row[v] = true;
    } else {
        push_row(v);
        int tm = (tl + tr) / 2;
        update_row(v*2, tl, tm, l, min(r, tm), new_val);
        update_row(v*2+1, tm+1, tr, max(l, tm+1), r, new_val);
    }
}
void update_col(int v, int tl, int tr, int l, int r, int new_val) {
    if (l > r) 
        return;
    if (l == tl && tr == r) {
        seg_col[v] = new_val;
        mar_col[v] = true;
    } else {
        push_col(v);
        int tm = (tl + tr) / 2;
        update_col(v*2, tl, tm, l, min(r, tm), new_val);
        update_col(v*2+1, tm+1, tr, max(l, tm+1), r, new_val);
    }
}
 
int get_row(int v, int tl, int tr, int pos) {
    if (tl == tr) {
        return seg_row[v];
    }
    push_row(v);
    int tm = (tl + tr) / 2;
    if (pos <= tm) 
        return get_row(v*2, tl, tm, pos);
    else
        return get_row(v*2+1, tm+1, tr, pos);
}
 
int get_col(int v, int tl, int tr, int pos) {
    if (tl == tr) {
        return seg_col[v];
    }
    push_col(v);
    int tm = (tl + tr) / 2;
    if (pos <= tm) 
        return get_col(v*2, tl, tm, pos);
    else
        return get_col(v*2+1, tm+1, tr, pos);
}
 
signed main() {
    int n, q;
    cin >> n >> q;
    update_row(1, 1, n, 1, n, n);
    update_col(1, 1, n, 1, n, n);
    int ans = (n-2)*(n-2);
    int i;
    int rm = n, cm = n;
    //cout << ans << endl;
    for(i=1;i<=q;i++)
    {
        int a, b;
        cin >> a >> b;
        if(a == 1)
        {
            // (1, b)
            int low = get_col(1, 1, n, b);
            
            if(low == 2)
                continue;
            ans-=(low - 2);
            //rm = min(rm, b);
            if(rm > b)
                rm = b, update_row(1, 1, n, 2, low - 1, rm);
        }
        else
        {
            int low = get_row(1, 1, n, b);
           // cout << a << " " << low << '\n';
            if(low == 2)
                continue;
            ans-=(low - 2);
            //cm = min(cm, b);
            if(cm > b)
                cm = b, update_col(1, 1, n, 2, low - 1, cm);
        }
        //cout << ans << '\n';
    }
    cout << ans;
    
}

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

using namespace std;

#define int long long
#define all(v) (v).begin(), (v).end()
#define resz(v, ...) (v).clear(), (v).resize(__VA_ARGS__)
#define reps(i, m, n) for(int i = (int)(m); i < (int)(n); i++)
#define rep(i, n) reps(i, 0, n)

template<class T1, class T2> void chmin(T1 &a, T2 b){if(a>b)a=b;}
template<class T1, class T2> void chmax(T1 &a, T2 b){if(a<b)a=b;}

using Pi = pair<int, int>;
using Tapris = tuple<int, int, int>;
using vint = vector<int>;

const int inf = 1LL << 55;
const int mod = 1e9 + 7;

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

  int n;
  cin >> n;
  vint a(n);
  int mni = 0;
  int mxi = 0;
  rep(i, n) {
    cin >> a[i];
    if(a[i] < a[mni]) mni = i;
    if(a[i] > a[mxi]) mxi = i;
  }
  vector<Pi> ans;
  //rep(i, n) cout << a[i] << " \n"[i==n-1];
  if(llabs(a[mni] == llabs(a[mxi]))) {
  } else if(llabs(a[mni]) < llabs(a[mxi])) {
    rep(i, n) {
      if(mxi == i) continue;
      ans.emplace_back(mxi, i);
      a[i] += a[mxi];
    }
    ans.emplace_back(mxi, mxi);
    a[mxi] += a[mxi];
    rep(i, n-1) {
      ans.emplace_back(i, i+1);
      a[i+1] += a[i];
    }
  } else {
    rep(i, n) {
      if(mni == i) continue;
      ans.emplace_back(mni, i);
      a[i] += a[mni];
    }
    ans.emplace_back(mni, mni);
    a[mni] += a[mni];
    for(int i = n-1; i > 0; --i) {
      ans.emplace_back(i, i-1);
      a[i-1] += a[i];
    }
  }
  //rep(i, n) cout << a[i] << " \n"[i==n-1];
  cout << ans.size() << endl;
  for(Pi p : ans) {
    cout << p.first+1 << " " << p.second+1 << endl;
  }

  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<unordered_set>
#include<unordered_map>
#include<bitset>
using namespace std;
#define INF 2147483647
#define LINF 9223372036854775807
#define MOD 1000000007
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define MODE 1
#ifdef MODE
#define DEB(X) cout<< #X <<": "<<X<<" ";
#define ARDEB(i,X) cout<< #X <<"["<<i<<"]: "<<X[i]<<" ";
#define END cout<<endl;
#else
#define DEB(X) {}
#define ARDEB(i,X) {}
#define END {}
#endif
//typedef long long int ll;
 

signed main(){
    
    int n;
    pair<int,int> r[111111];
    pair<int,int> b[111111];
    cin>>n;
    rep(i,n){
        int h,g;
        cin>>h>>g;
        r[i]=make_pair(h,g);b[i]=make_pair(h,g);
    }
    rep(i,n){
        int h,g;
        cin>>h>>g;
        b[i]=make_pair(h,g);
    }
    
    sort(b,b+n);
    int f[111111]={0},ans=0;
    rep(i,n){
        vector<pair<pair<int,int>,int>> v;
        //cout<<b[i].first<<" "<<b[i].second<<endl;
        rep(j,n){
            if(f[j])continue;
            if(r[j].first<b[i].first && r[j].second<b[i].second){
                v.push_back(make_pair(make_pair(r[j].second,r[j].first),j));
            }
        }
        //v.push_back(make_pair(make_pair(-INF,-INF),-INF));
        if(v.size()==0)continue;
        sort(v.begin(),v.end());
        f[v[v.size()-1].second]=1;
        //cout<<v[v.size()-1].first.second<<" "<<v[v.size()-1].first.first<<endl;
        ans++;
    }
    //cout<<ans<<endl;

	cout<<ans<<endl;
}

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


int main(){
    string s;
    string ans;
    cin >> s;

    if (s.size() == 2){
        ans = s;
    }else{
        char tmp;
        tmp = s[0];
        s[0] = s[2];
        s[2] = tmp;
        ans = s;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
def slove():
    import sys
    input = sys.stdin.readline
    n, a, b = list(map(int, input().rstrip('\n').split()))
    x = list(map(int, input().rstrip('\n').split()))
    lp = x[0]
    t = 0
    for i in range(1, n):
        if (x[i] - lp) * a <= b:
            t += ((x[i] - lp) * a)
        else:
            t += b
        lp = x[i]
    print(t)


if __name__ == '__main__':
    slove()


Measured memory_bytes: 62704
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD=1e9+7;
const int INF=1e9;

int main(){
    int n,d;
    cin>>n>>d;
    int x[10][10];
    for(int i=0;i<n;i++){
        for(int j=0;j<d;j++){
            cin>>x[i][j];
        }
    }
    int ans=0;
    for(int i=0;i<n;i++){
        for(int j=i+1;j<n;j++){
            int num=0;
            for(int k=0;k<d;k++){
                num+=(x[i][k]-x[j][k])*(x[i][k]-x[j][k]);
            }
            for(int k=1;k<200;k++){
                if(num==k*k)ans++;
            }
        }
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 256
import std.stdio, std.array, std.string, std.conv, std.algorithm;
import std.typecons, std.range, std.random, std.math, std.container;
import std.numeric, std.bigint, core.bitop, core.stdc.string;

immutable long MOD = 10^^9 + 7;
long[] F, FI;

void main() {
    auto N = readln.chomp.to!int;
    auto G = new int[][](N);
    foreach (_; 0..N-1) {
        auto s = readln.split.map!(to!int);
        G[s[0]-1] ~= s[1]-1;
        G[s[1]-1] ~= s[0]-1;
    }

    F = new long[](N+1);
    FI = new long[](N+1);
    F[0] = FI[0] = 1;
    foreach (i; 1..N+1) F[i] = F[i-1] * i % MOD;
    foreach (i; 1..N+1) FI[i] = FI[i-1] * powmod(i, MOD-2, MOD) % MOD;

    int c = -1;
    int c2 = -1;
    int[] A;

    int dfs(int n, int p) {
        bool center = true;
        int s = 0;
        int[] a;
        foreach (m; G[n]) {
            if (m == p) continue;
            int t = dfs(m, n);
            if (t > N / 2) center = false;
            s += t;
            a ~= t;
        }
        if (N - s - 1 > N / 2) {
            center = false;
        }
        if (center && c == -1) {
            c = n;
            A = a.dup ~ (N - s - 1);
        } else if (center) {
            c2 = n;
        }
        return s + 1;
    }

    dfs(0, -1);

    if (c2 != -1) {
        writeln(F[N/2] * F[N/2] % MOD);
        return;
    }


    int M = A.length.to!int;
    auto dp = new long[][](M+1, N+1);
    dp[0][0] = 1;

    foreach (i; 0..M) {
        foreach (j; 0..N) {
            if (dp[i][j] == 0) continue;
            foreach (k; 0..A[i]+1) {
                dp[i+1][j+k] += dp[i][j] * perm(A[i], k) % MOD * comb(A[i], k) % MOD;
                dp[i+1][j+k] %= MOD;
            }
        }
    }

    long ans = 0;

    foreach (i; 0..N+1) {
        long tmp = dp[M][i] * F[N-i] % MOD;
        if (i % 2 == 1) tmp *= -1;
        ans += tmp;
        ans %= MOD;
    }

    ans = (ans + MOD) % MOD;
    ans.writeln;
}

long comb(long n, long r) {
    return F[n] * FI[n-r] % MOD * FI[r] % MOD;
}

long perm(long n, long r) {
    return F[n] * FI[n-r] % MOD;
}

long powmod(long a, long x, long m) {
    long ret = 1;
    while (x) {
        if (x % 2) ret = ret * a % m;
        a = a * a % m;
        x /= 2;
    }
    return ret;
}


Measured memory_bytes: 203004
#include<iostream>
#include<cmath>
using namespace std;
 
int main(){
    int n,a[10],c;
     
    while(cin>>n){
        c=0;
        for(int i=0;i<10;i++) a[i]=0;
        for(int i=9;i>=0;i--){
            if(n>=pow(2,i)){
                n-=pow(2,i);
                a[i]++;
            }
        }
        for(int i=0;i<10;i++){
            if(a[i]!=0){
                if(c!=0) cout << " ";
                cout << pow(2,i);
                c++;
            }
        }
        cout << endl;
    }
}

Measured memory_bytes: 1276
#include <stdio.h>
int main(void){
	int h,m1,m2,m3,w;
	m1=0;
	m2=0;
	m3=0;
	for(int i=0;i<10;i++){
		scanf("%d",&h);
		if(m3<h){
			m3=h;
			if(m2<m3){
				w=m2;
				m2=m3;
				m3=w;
				if(m1<m2){
					w=m1;
					m1=m2;
					m2=w;
				}
			}
		}
	}
	printf("%d\n%d\n%d\n",m1,m2,m3);
	return 0;
}


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

int main() {
  int i,N, K, x, sum=0;
  cin >> N >> K;
  for (i=0; i<N; i++) {
    cin >> x;
    if(x < abs(K-x)) {
      sum += 2*x;
    } else {
      sum += 2*abs(K-x);
    }
  }
  cout << sum << endl;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
	int n, s[400], i, sum;
	
	while (scanf("%d", &n), n != 0){
		sum = 0;
		for (i = 0; i < n / 4; i++){
			scanf("%d", &s[i]);
			sum += s[i];
		}
		printf("%d\n", sum);
	}
	
	return 0;
}

Measured memory_bytes: 600
#include<bits/stdc++.h>
#define INF 1e9
#define llINF 1e18
#define MOD 1000000007
#define pb push_back
#define mp make_pair 
#define F first
#define S second
#define ll long long
#define vi vector<ll>
#define vvi vector<vi>
#define BITLE(n) (1LL<<((ll)n))
#define SHIFT_LEFT(n) (1LL<<((ll)n))
#define SUBS(s,f,t) ((s).substr((f),(t)-(f)))
#define ALL(a) (a).begin(),(a).end()
using namespace std;

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll x,a,b;cin>>x>>a>>b;
  if(b-a <= 0){
    cout<<"delicious"<<endl;
  }else if(b-a <= x){
    cout<<"safe"<<endl;
  }else{
    cout<<"dangerous"<<endl;
  }
  return 0;
}

Measured memory_bytes: 256
//高知能系Vtuberの高井茅乃です。
//Twitter: https://twitter.com/takaichino
//YouTube: https://www.youtube.com/channel/UCTOxnI3eOI_o1HRgzq-LEZw

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

#define INTINF 1999999999
#define REP(i,n) for(int i=0;i<n;i++)
#define REP1(i,n) for(int i=1;i<=n;i++)
#define MODA 1000000007 

int main() {
	int ans = 0;
	int tmp;
	string s;
	cin >> s;
	int o= 0, z = 0;
	REP(i, s.size()){
		if(s[i] == '0') z++;
		else o ++;
	}
	cout << 2 * min(o,z) << endl;
}

Measured memory_bytes: 512
#include <iostream>
#include <map>
#include <vector>
#include <algorithm>
#include <map>
#include <string>
#include <queue>
#include <set>
#include <math.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const ll mod = 1000000007;
ll bit[100010], num;
ll n, m, par[100010], p, q, c;
vector<P> road[300010];
map<P, ll> mp;
struct edge { ll to, cost; };
ll d[300010];

void dijkstra(ll s)
{
	priority_queue<P, vector<P>, greater<P>> que;
	for (int i = 0; i < 300005; i++)
	{
		d[i] = 1000000000000;
	}
	d[s] = 0;
	que.push(P(0, s));

	while (!que.empty())
	{
		P p = que.top(); que.pop();
		ll v = p.second;
		if (d[v] < p.first) continue;
		for (int i = 0; i < road[v].size(); i++)
		{
			P e = road[v][i];
			if (d[e.first] > d[v] + e.second)
			{
				d[e.first] = d[v] + e.second;
				que.push(P(d[e.first], e.first));
			}
		}
	}
}

ll sum(ll i)
{
	ll s = 0;
	while (i > 0)
	{
		s += bit[i];
		i -= i & -i;
	}
	return s;
}

void add(ll i, ll x)
{
	while (i <= num)
	{
		bit[i] += x;
		i += i & -i;
	}
}

ll po(ll x, ll y)
{
	if (y == 0) return 1;
	if (y % 2)
	{
		return po(x, y - 1) * x % mod;
	}
	else
	{
		ll yyy = po(x, y / 2);
		return yyy * yyy % mod;
	}
}

ll div(ll x)
{
	return po(x, mod - 2);
}

int main(void)
{
	cin >> n >> m;
	for (int i = 1; i <= m; i++)
	{
		cin >> p >> q >> c;
		road[p].push_back(P(i + n, 1));
		road[i + n].push_back(P(p, 1));
		road[q].push_back(P(i + n, 1));
		road[i + n].push_back(P(q, 1));
		if (mp[P(p, c)] != 0)
		{
			road[i + n].push_back(P(mp[P(p, c)], 0));
			road[mp[P(p, c)]].push_back(P(i + n, 0));
		}
		if (mp[P(q, c)] != 0)
		{
			road[i + n].push_back(P(mp[P(q, c)], 0));
			road[mp[P(q, c)]].push_back(P(i + n, 0));
		}
		mp[P(p, c)] = i + n;
		mp[P(q, c)] = i + n;
	}
	dijkstra(1);

	if (d[n] > 10000000000)
	{
		cout << -1 << endl;
	}
	else
	{
		cout << d[n] / 2 << endl;
	}
	int www;
	cin >> www;
}


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

using namespace std;

int a[26];
int ok;
string str;

int main()
{
	cin >> str;

	for (int i = 0; i < str.length(); ++i)
		a[str[i] - 'a']++;
	
	for (int i = 0; i < 26; ++i)
		if (a[i] % 2)
			ok = true;

	if (ok)
		cout << "No" << endl;
	else
		cout << "Yes" << endl;

	return 0;
}

Measured memory_bytes: 256
N, M = map(int, input().split())
A_list = []
for i in range(1, M+1):
    A_list.append("A_" + str(i))
A_list = map(int, input().split())

answer = N - sum(A_list)

if answer >= 0 :
    print(answer)
else:
    print(-1) 

Measured memory_bytes: 10388
def main():
    t = input()
    if t == '?':
        return 'D'
    n = len(t)
    ans = list(t)
    for i, c in enumerate(t):
        if c == '?':
            if i == 0:
                if t[i+1] == 'P':
                    s = 'D'
                else:
                    s = 'P'
            elif i == n-1:
                s = 'D'
            else:
                if ans[i-1] == 'D' and t[i+1] == 'P':
                    s = 'D'
                elif ans[i-1] == 'D' and t[i+1] == 'D':
                    s = 'P'
                elif ans[i-1] == 'P' and t[i+1] == 'P':
                    s = 'D'
                elif ans[i-1] == 'P' and t[i+1] == 'D':
                    s = 'D'
                elif ans[i-1] == 'P' and t[i+1] == '?':
                    s = 'D'
                elif ans[i-1] == 'D' and t[i+1] == '?':
                    s = 'P'
        else:
            s = c
        ans[i] = s
    return ''.join(ans)

print(main())

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

int main()
{
  int N;
  cin >> N;
  int H;
  cin >> H;
  int i = 1;
  for (; i < N; ++i)
  {
    int _H;
    cin >> _H;
    if (_H < H)
      break;
    H = (H < _H ? _H - 1 : _H);
  }
  cout << (N == i ? "Yes" : "No");
  return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#define int long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
using namespace std;

signed main(){

    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    
    string s; cin >> s;
    int n = s.size();
    int cnt = 0;
    rep(i,n/2){
        if(s[i] != s[n-1-i]){
            s[i] = s[n-1-i];
            cnt++;
        }
    }
    cout << cnt << endl;
    return 0;
}

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

int main()
{
	int D;
	scanf("%d", &D);

	switch (D) {
	case 25:
		printf("Christmas\n");
		break;
	case 24:
		printf("Christmas Eve\n");
		break;
	case 23:
		printf("Christmas Eve Eve\n");
		break;
	default:
		printf("Christmas Eve Eve Eve\n");
	}

	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
int main(){
    string S;
    cin>>S;
    int N=S.size();
    map<char,int> m;
    for(int i=0;i<N;i++){
        m[S[i]]++;
    }
    for(int i=0;i<26;i++){
        if(m['a'+i]>1){cout<<"no"<<endl;exit(0);}
    }
    cout<<"yes"<<endl;
}

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

#define watch(x) cerr << (#x) << ": " << (x) << endl
#define int long long

const int N = 1000;
int x, y, z;
int a[N], b[N], c[N];
int k;

int32_t main() {

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    cin >> x >> y >> z >> k;
    for(int i = 0; i < x; ++i) cin >> a[i];
    for(int i = 0; i < y; ++i) cin >> b[i];
    for(int i = 0; i < z; ++i) cin >> c[i];

    sort(a, a+x, greater<int>());
    sort(b, b+y, greater<int>());
    sort(c, c+z, greater<int>());

    vector<int> cands;
    for(int i = 0; i < x; ++i) {
        for(int j = 0; j < y; ++j) {
            for(int l = 0; l < z; ++l) {
                if((i+1)*(j+1)*(l+1) <= k) {
                    cands.push_back(a[i]+b[j]+c[l]);
                }
            }
        }
    }
    sort(cands.begin(), cands.end(), greater<int>());

    for(int i = 0; i < k; ++i)
        cout << cands[i] << '\n';

    return 0;
}


Measured memory_bytes: 1528
import java.util.*;
public class Main {
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int count = 0;
		int cnt = 0;
		for (int i = 1; i <= n; i += 2) {

				for (int j = 1; j <= i; j++) {

					if (i % j == 0) {
						count++;
					}
				}
				if (count == 8) {
					cnt++;
				}
				count = 0;
			}
		System.out.println(cnt);
	}
}

Measured memory_bytes: 22612
from collections import deque
from heapq import heappush, heappop
n, k = map(int, input().split())
v = list(map(int, input().split()))

ans = 0
for i in range(n + 1):
    for j in range(n + 1):
        rest = k - i - j
        if i + j > n or rest < 0:
            continue
        tans = 0
        q = deque(v)
        poppen = []
        for _ in range(i):
            tans += q[0]
            heappush(poppen, q.popleft())
        for _ in range(j):
            tans += q[-1]
            heappush(poppen, q.pop())
        for _ in range(rest):
            if not poppen or poppen[0] >= 0:
                break
            tans -= heappop(poppen)
        ans = max(ans, tans)
print(ans)


Measured memory_bytes: 3316
import scala.collection.mutable
import java.io.{BufferedReader, InputStreamReader}

object Main extends App {
  val in = new BufferedReader(new InputStreamReader(System.in))
  val map = mutable.HashMap[Long,Int]()

  val n = in.readLine.toInt
  in.readLine.split(" ").map(_.toLong)
    .foreach(e => {
      if(!map.contains(e)) map += e -> 1
      else map(e) +=1
    })

  val ite = map.filter(e => e._2 > 3).keys
  val keys1 = if(ite.isEmpty) 0 else ite.max
  val keys2 = map.filter(e => e._2 > 1).keys.toVector.sorted
    .takeRight(2)
  val res1 = keys1 * keys1
  val res2 = if(keys2.size != 2) 0 else keys2.head * keys2.last

  val ans = math.max(res1,res2)
  println(ans)
}

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

int main(){
  int H;
  int N;
  cin >> H >> N;
  vector<int> skill(N);
  int total = 0;

  
  for (int i = 0; i < N; i++) {
    cin >> skill[i];
    total += skill[i];
  }
  if(total >= H){
    cout << "Yes";
  }
  else{
    cout << "No";
  }
  

}

Measured memory_bytes: 640
n,k=[int(j) for j in input().split()]
from numpy import *
a=array([int(j) for j in input().split()])
a.sort()
lm=a[a<0]
lp=a[a>0]
lz=a[a==0]
np=len(lp)
nm=len(lm)
nz=len(lz)

import bisect
import math
def f(x):
    c=0
    if x>=0:
        c+=nz*n
    c+=searchsorted(a,x//lp,side="right").sum()
    c+=(n-searchsorted(a,(-x-1)//(-lm),side="right")).sum()
    c-=count_nonzero(a*a<=x)
    return c//2

left=-10**20
right=10**20
while right-left>1:
    mid=(left+right)//2
    if f(mid)>=k:
        right=mid
    else:
        left=mid
print(right)





Measured memory_bytes: 32284
#include <stdio.h>
#include <algorithm>

using namespace std;

int main() {
	int n, t, a, h, avg, diff, min = 1000000000, ans;
	scanf("%d %d %d", &n, &t, &a);
	for (int i = 1; i <= n; i++) {
		scanf("%d", &h);
		avg = (500 * t) - (3 * h);
		diff = abs(avg - (500 * a));
		if (diff < min) {
			min = diff;
			ans = i;
		}
	}
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<string>
#include<vector>
#include<cmath>
#include<queue>
#include<stack>
#include<set>
#include<algorithm>
using namespace std;
typedef long long ll;
const ll mod = 1000000007;
const int INF = 1001001001;

ll pow_mod(ll x, ll y) {
	ll res = 1;
	for (ll i = 0; i < y; i++) res = res * x % mod;
	return res;
}

int main() {
	int n;
	cin >> n;
	ll ans = 0;
	for (int i = 1; i < n + 1; i++) {
		if (i % 3 != 0 && i % 5 != 0) {
			ans += i;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3612
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#define int long long
#define mkp make_pair
#define pb push_back
#define ff first
#define ss second
#define debug1(a) cout<<a<<endl;
#define debug2(a,b) cout<<a<<' '<<b<<endl;
#define debug3(a,b,c) cout<<a<' '<<b<<' '<<c<<endl;
#define rep(i,n) for(int i=0;i<n;i++)
#define repre(i,a,b)for(int i=a;i<=b;i++)
#define clr1(arr) memset(arr,-1,sizeof(arr));
#define clr0(arr) memset(arr,0,sizeof(arr));
#define pi pair<int,int>
#define pii pair<int,pi>
#define aint(v) v.begin(),v.end()
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace __gnu_pbds;
using namespace std;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> orderedSet;
typedef tree<int,null_type,less_equal<int>,rb_tree_tag,tree_order_statistics_node_update> orderedMSet;
struct custom_hash {
static uint64_t splitmix64(uint64_t x) {
        // http://xorshift.di.unimi.it/splitmix64.c
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};
#define ump gp_hash_table<int,int,custom_hash>
//*p.find_by_order(index) return value at index
//p.order_of_key(key) return index
/*int **dp,in main function,int row,col;dp=new int*[n];rep(i,n)dp[i]=new int[m]*/
//**** Maths Section*******/
int power(int x,int y);
bool isPrime(int n);
int modInv(int a,int b);
int gcdExtended(int a,int b,int *x,int* y);
int mpower(int a,int b,int p);
/***************************/
int32_t main()
{
//freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);
  fastio
  int n;
  cin>>n;
  string s;
  cin>>s;
  int ans=0;
  repre(i,0,s.size()-3)
  {
    if(s[i]=='A' && s[i+1]=='B' && s[i+2]=='C')ans++;
  }
  cout<<ans<<endl;
  return 0;
}

int modInv(int a, int m)
{
int x, y;
int g = gcdExtended(a, m, &x, &y);
int res = (x%m + m) % m;
return res;
}

int gcdExtended(int a, int b, int *x, int *y)
{
if (a == 0){
    *x = 0, *y = 1;
    return b;
  }
  int x1, y1;
  int gcd = gcdExtended(b%a, a, &x1, &y1);
  *x = y1 - (b/a) * x1;
  *y = x1;
  return gcd;
}

int mpower(int x, int y, int p)
{
int res = 1;
x = x % p;
while(y > 0){
    if(y & 1) res = (res*x) % p;
      y = y>>1;
      x = (x*x) % p;
    }
    return res;
}
int power(int x, int y)
{
int res = 1;
while (y > 0){
    if (y & 1) res = res*x;
      y = y>>1;
      x = x*x;
    }
    return res;
}

bool isPrime(int n)
{
if (n <= 1)  return false;
  if (n <= 3)  return true;
    if (n%2 == 0 || n%3 == 0) return false;
      int p=sqrt(n);
      for(int i=5;i<=p;i=i+6)
        if (n%i == 0 || n%(i+2) == 0)
          return false;
      return true;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define M 1000000007
typedef long long ll;
#define pb push_back
#define f first
#define s second
#define M5 100050
#define M6 2000009
typedef pair<ll,ll> pll;
ll power(ll x,ll n){
    if(x==0) return 0;
    ll ret=1;
    while(n>0){
        if(n&1) ret=(ret*x);
        x=(x*x);
        n/=2;
    }
    return ret;
}
ll ar[M5],m,n;
int  main()
{   ll test=1,t,i,j,k,l,a,b,ans,flag; string s,s2,s3;
    //cin>>test;
    t=1;
    while(t<=test){
        cin>>n;
        for(i=1;i<=n;i++) cin>>ar[i];
            ans=0;
        for(i=2;i<=n;i++) ans+=abs(ar[i]-ar[i-1]);
        ans+=abs(ar[1])+abs(ar[n]);
        for(i=1;i<=n;i++){
            cout<<ans-abs(ar[i]-ar[i-1])-abs(ar[i+1]-ar[i])+abs(ar[i+1]-ar[i-1])<<"\n";
        }
        t++;
    }
    return 0;
} 

Measured memory_bytes: 2048
#include <bits/stdc++.h>
#define int long long

#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(int)a, i##_len=(b); i<i##_len; i++)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)

#define all(box) box.begin(), box.end()

using namespace std;

using P = pair<int,int>;
using ll = long long;

const long long INF = LLONG_MAX/3;

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; }
inline void Yes (bool condition) { if(condition) { cout << "Yes" << endl; } else { cout << "No" << endl;} }

struct UnionFind{
	std::vector<int> par,siz;
	void init(int n){
		par.resize(n);
		for(int i=0;i<n;i++)par[i]=i;
		siz.resize(n,1);
	}
	UnionFind(int n){
		init(n);
	}
	int root(int n){
		if(par[n]==n)return n;
		else return par[n]=root(par[n]);
	}
	bool issame(int x,int y){
		return (root(x)==root(y));
	}
	bool marge(int a,int b){
		if(issame(a,b))return false;
		else{
			a=root(a),b=root(b);
			if(siz[a]<siz[b])swap(a,b);
			siz[b]+=siz[a];
			par[a]=par[b];
			return true;
		}
	}
	int size(int n){
		return siz[root(n)];
	}
};

long long gcd(long long a,long long b){
    if(b==0)return a;
    return gcd(b,a%b);
}
long long lcm(long long i,long long j){
    return i*(j/gcd(i,j));
}

const int MOD=998244353;
long long fac[510000], finv[510000], inv[510000];
long long MAX=510000;
bool COMinited=false;
long long COM(int n, int k){
	if(COMinited==false){
		fac[0] = fac[1] = 1;
    	finv[0] = finv[1] = 1;
    	inv[1] = 1;
    	for (int i = 2; i < MAX; i++){
        	fac[i] = fac[i - 1] * i % MOD;
        	inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        	finv[i] = finv[i - 1] * inv[i] % MOD;
    	}
		COMinited=true;
	}
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
long long modinv(long long a, long long mod) {
    return modpow(a, mod - 2, mod);
}
template< typename T >
struct BinaryIndexedTree {
  vector< T > data;

  BinaryIndexedTree(int sz) {
    data.assign(++sz, 0);
  }

  T sum(int k) {
    T ret = 0;
    for(++k; k > 0; k -= k & -k) ret += data[k];
    return (ret);
  }

  void add(int k, T x) {
    for(++k; k < data.size(); k += k & -k) data[k] += x;
  }
};
signed main(){
	int n,x,y;
	cin>>n>>x>>y;
	int cnt[2010]={};
	rep(i,1,n+1){
		//rep(i,1,n)cout<<cnt[i]<<" ";
		//cout<<endl;
		rep(j,i+1,n+1){
			if(i<=x){
				if(j<y)cnt[min(j-i,x-i+y-j+1)]++;
				else cnt[x-i+j-y+1]++;
			}else if(i<y){
				if(j<=x)cnt[min(j-i,j-x+1+y-j)]++;
				else if(j<y)cnt[min(j-i,i-x+1+y-j)]++;
				else cnt[min(i-x+1+j-y,j-i)]++;
			}else{
				cnt[j-i]++;
			}
		}
	}
	rep(i,1,n)cout<<cnt[i]<<endl;

}

Measured memory_bytes: 256
def divide(x): #約数配列
    div=[1]
    check=2
    for check in range(1,int(x**0.5)+1):
        if(x%check==0):
            div.append(check)
            div.append(x//check)
    div.sort()
    return div

def main():
    n,m = map(int,input().split())
    di=divide(m)
    for i in range(len(di)):
        if di[len(di)-1-i]<=m//n:
            print(di[len(di)-1-i])
            return
    
if __name__ == "__main__":
    main()

Measured memory_bytes: 38768
#!/usr/bin/env python3
#CODEFESTIVAL 2017 B

import sys
import math
import bisect
sys.setrecursionlimit(1000000000)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

s = input()
c = list(Counter(s).items())
c.sort(key = itemgetter(1))
if len(s) == 1:
    print('YES')
elif len(s) == 2:
    if s[0] == s[-1]:
        print('NO')
    else:
        print('YES')
else:
    if len(c) != 3:
        print('NO')
    else:
        if c[-1][1] - c[0][1] <= 1:
            print('YES')
        else:
            print('NO')


Measured memory_bytes: 39280
#include <stdio.h>

int main(){
  char ins[5];
  int flg=0;
  scanf("%s",ins);

  if(ins[0] == ins[1]){
    flg=1;
  }else if(ins[1] == ins[2]){
    flg=1;
  }else if(ins[2] == ins[0]){
    flg=1;
  }

  if(flg == 1){
    printf("No\n");
  }else{
    printf("Yes\n");
  }

  return 0;


}

Measured memory_bytes: 128
// include
// ------------------------------------------------
#include <bits/stdc++.h>
#include <math.h>

using namespace std;

// func
// ------------------------------------------------
int CalcSumOfDigit(int n);      // 各桁の和を計算する。
int getDigit(int n);            // 数字の桁数を取得する。
string upper(string str);       // 英字を大文字に変換する。
string lower(string str);       // 英字を小文字に変換する。

// class
// ------------------------------------------------
class Combi
{
  public:
    Combi();
    long long Combination(long long n, long long k);
    long long nPk_modp(long long n, long long k, long long p);
  private:
    vector<vector<long long>> memo;
    long long n_num;
    long long k_num;
    void Resize(long long n, long long k);
};

// define
// ------------------------------------------------
#define all(a)        (a).begin(),(a).end()
#define rall(a)       (a).rbegin(),(a).rend()
#define sz(a)         int((a).size())
#define rep(i,n)      for(int(i)=0;(i)<(n);(i)++)
#define repe(i,n)     for(int(i)=0;(i)<=(n);(i)++)
#define vsort(v)      sort((v).begin(),(v).end())
#define rvsort(v)     sort(rall((v)))
#define vi            vector<int>
#define GCD(a,b)      __gcd((a),(b))
#define LCM(a,b)      (a)/GCD((a),(b))*(b)
#define kiriage(a,b)  ((a)+(b)-1)/(b)

const int INF = 1e9;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<long> vll;
// code
// ------------------------------------------------
int main() {

    ll m1,m2,d1,d2;

    cin >> m1 >> d1 >> m2 >> d2 ;

    if(m1 != m2)    cout << 1 << endl;
    else cout << 0 << endl;


    return 0;
}
// funcの実体
// ------------------------------------------------
int getDigit(int n)
{
  int i = 1;
  while(1)
  {
    n = n / 10;
    if(n == 1)
      break;
    i++;
  }
  return i;
}
int CalcSumOfDigit(int n)
{
  int s = 0;
  while(n)
  {
    s += n % 10;
    n = n / 10;
  }
  return s;
}

string upper(string str)
{
  for(auto itr = str.begin();itr != str.end() ; itr++)
  {
    if(97 <= *itr && *itr <= 122)
    {
      *itr = *itr - 32;
    }
  }
  return str;
}

string lower(string str)
{
  for(auto itr = str.begin();itr != str.end() ; itr++)
  {
    if(65 <= *itr && *itr <= 90)
    {
      *itr = *itr + 32;
    }
  }
  return str;
}


Combi::Combi(){
  n_num = -1;
  k_num = -1;
};
ll Combi::Combination(ll n, ll k)
{
  Resize(n,k);

  ll ret;
  if(memo[n][k] != 0)
  {
    ret = memo[n][k];
  }
  else if(n == k || k == 0)
  {
    memo[n][k] = 1;
    ret = 1;
  }
  else
  {
    ret = Combination(n - 1, k - 1) + Combination(n - 1, k);
    memo[n][k] = ret;
  }
  return ret;
}

void Combi::Resize(ll n, ll k)
{
  if(n_num <= n || k_num <= k)
  {
    n_num = (n + 1) * 2;
    k_num = (k + 1) * 2;
    memo.resize(n_num);
    for(auto itr = memo.begin(); itr != memo.end(); ++itr)
    {
      itr->resize(k_num);
    }
  }
}

long long Combi::nPk_modp(long long n, long long k, long long p)
{
  ll ans = 1;
  for(long long i = k; i <= n; i++)
  {
    ans = (ans * i) % p;
  }

  return ans;
};


Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
#include <climits>
using namespace std;

#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;


int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    map<int, int> hash_cnt;
    REP(i, n) {
        int a;
        cin >> a;
        hash_cnt[a]++;
    }

    int ans = 0;
    for(auto& pair : hash_cnt) {
        int x = pair.first;
        int cnt = pair.second;
        if(x > cnt) ans += cnt;
        else ans += cnt - x;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 4736
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll=long long;
using vi = vector<int>;
using Graph = vector<vi>;
using P = pair<int,int>;
const int MOD=(int)1e9+7;
const int INF=(int)1e9;
const ll LINF=(ll)1e18;
/*
void call(vector<vector<bool>> m){
    rep(i,m.size()){
        rep(j,m[i].size()){
            cout << (m[i][j]? 1:0) << " ";
        }
        cout << endl;
    }
    return ;
}*/

// 1 2 3 4
// ← → ↓ ↑
int main(){
    int w,h,n;
    cin >> w >> h >> n;
    vector<vector<bool>> m(h,vector<bool>(w,0));
    //m[h-1][w-1] = 1;
    rep(i,n){
        int x,y,a;
        cin >> x >> y >> a;
        if(a==1){
            rep(j,x){
                rep(k,h){
                    m[k][j] = true;
                }
            }
            //call(m);
        }else if(a==2){
            for(int j=w-1;j>=x;j--){
                rep(k,h){
                    m[k][j] = true;
                }
            }
            //call(m);
        }else if(a==3){
            rep(j,y){
                rep(k,w){
                    m[j][k] = true;
                }
            }
            //call(m);
        }else if(a==4){
            for(int j=h-1;j>=y;j--){
                rep(k,w){
                    m[j][k] = true;
                }
            }
            //call(m);
        }
    }
    int ans = 0;
    rep(i,h) rep(j,w){
        if(!m[i][j]) ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define typeof(x) __typeof__(x)
#define int long long int
#define double long double
#define mod(x) ((x % MOD) + MOD) % MOD
#define REP(i,a,b) for(int i=(a);i<(b);++i)
#define RREP(i,a,b) for(int i=(b)-1;i>=(a);--i)
#define ALL(c) (c).begin(),(c).end()
#define RALL(c) (c).rbegin(),(c).rend()
#define SZ(c) (int)((c).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define SORT(c) sort(ALL(c))
#define RSORT(c) sort(RALL(c))
#define LB(c,x) (int)(lower_bound(ALL(c),x)-(c).begin())
#define UB(c,x) (int)(upper_bound(ALL(c),x)-(c).begin())
#define COUNT(c,x) UB(c,x)-LB(c,x)
#define UNIQUE(c) SORT(c); (c).erase(unique(ALL(c)),(c).end());
#define COPY(c1,c2) copy(ALL(c1),(c2).begin())
#define EXIST(s,e) (s).find(e)!=(s).end()
#define PB push_back
#define MP make_pair
#define vec vector
#define dump(x)  cerr << #x << " = " << (x) << endl;

using namespace std;

typedef pair<int,int> P;
struct edge { int from, to; double cost; };
ostream& operator << (ostream& s, const edge& e) {
   s << "(" << e.from << "->" << e.to << ": " << e.cost << ")";
   return s;
}
bool operator< (const edge &edge1, const edge &edge2){
   return edge1.cost < edge2.cost;
};

const int INF = 1e18;
const int MOD = 1e9+7;

template<typename T> ostream& operator << (ostream& s, const vector<T>& v) {
   s << "[";
   for (int i = 0; i < v.size(); i++) { s << v[i]; if (i < v.size() - 1) s << " "; }
   s << "]";
   return s;
}
template<typename T1, typename T2> ostream& operator << (ostream& s, const pair<T1,T2>& p) {
   s << "(" << p.first << "," << p.second << ")";
   return s;
}
template<typename T1, typename T2> ostream& operator << (ostream& s, const map<T1,T2>& m) {
   s << "{";
   for (auto i = m.begin(); i != m.end(); ++i) {
      s << i->first << ":" << i->second;
      if (next(i) != m.end()) s << ", ";
   }
   s << "}";
   return s;
}

signed main()
{
   string S;
   cin >> S;
   dump(S)
   int Bnum = 0, ans = 0;
   REP(i, 0, SZ(S)) {
      if (S[i] == 'B') {
         Bnum++;
      } else {
         ans += Bnum;
      }
   }
   cout << ans << endl;
   return 0;
}


Measured memory_bytes: 640
#include<cstdio>
#include<functional>
#include<algorithm>
#include<cstring>
using namespace std;
int main(void)
{
	int n,l,i,j;
	char s[100][101],wk[101];
	scanf("%d %d",&n,&l);
	for(i=0;i<n;i++)	scanf("%s",s[i]);
//	for(i=0;i<n;i++)	sort(s[i],s[i]+l);
	for(i=0;i<n-1;i++)	{
		for(j=i+1;j<n;j++)	{
			if(strcmp(s[i],s[j])>0)	{
				swap(s[i],s[j]);
			}
		}
	}
	for(i=0;i<n;i++)	printf("%s",s[i]);
	printf("\n");
	return 0;
}

Measured memory_bytes: 128
def main():
    n, k = map(int, input().split())
    a = list(map(int, input().split()))
    a.sort()
    cnt = 0
    pre_n = a[0]
    cnt_kind = []
    for i in a:
        if pre_n == i:
            cnt += 1
            pre_n = i
        else:
            cnt_kind.append(cnt)
            cnt = 1
            pre_n = i

    cnt_kind.append(cnt)
    cnt_kind.sort()
    if len(cnt_kind) <= k:
        print(0)
    else:
        print(sum(cnt_kind[:len(cnt_kind)-k]))


if __name__ == '__main__':
    main()

Measured memory_bytes: 97312
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		while (true) {
			int n = scanner.nextInt();
			if (n == 0)
				break;
			double min = Integer.MAX_VALUE;
			int id = -1;
			while (n-- > 0) {
				int num = scanner.nextInt();
				double a = scanner.nextDouble()/100;
				double b = scanner.nextDouble();
				double bmi = b / a / a;
				double ans = Math.abs(22 - bmi);
				if (min > ans) {
					min = ans;
					id = num;
				} else if (min == ans) {
					if (id > num) {
						id = num;
					}
				}
			}
			System.out.println(id);
		}
	}
}

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

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();}
template<class T> inline T sqr(T x) {return x*x;}

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 pb push_back
#define mp make_pair
#define each(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define exist(s,e) ((s).find(e)!=(s).end())
#define range(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  range(i,0,n)
#define clr(a,b) memset((a), (b) ,sizeof(a))
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

const double eps = 1e-10;
const double pi  = acos(-1.0);
const ll INF =1LL << 62;
const int inf =1 << 29;

int main(void){
    int N; cin >> N;
    while(N--){
        int p, q; cin >> p >> q;

        int dpq = p * p + q * q;
        int cnt = 0;
        for(int m = 0; m * m <= dpq; m++){
            for(int n = 0; n * n <= dpq; n++){
                int dmn = m * m + n * n;
                if(dmn < 1) continue;
                if(((m * p + n * q) % dmn == 0) &&
                    (m * q - n * p) % dmn == 0)
                    cnt++;
            }
        }

        if(cnt * 2 <= 8) cout << "P" << endl;
        else cout << "C" << endl;
    }

	return 0;
}

Measured memory_bytes: 1152
#include <iostream>
#include <string>
#include <stdlib.h>
using namespace std;
int main(void){
    // Here your code !
    int n;
    string m;
    while(1) {
        n = 0;
        cin >> m;
        if(m == "0")
            break;
        
        for(int i=0;i<m.size();i++) {
            int k = m[i] - '0';
            n = n + k;
        }
        cout << n << endl;
    }
    
}

Measured memory_bytes: 3124