akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <iomanip>
#include <iostream>
#include <vector>
using namespace std;
template <class T>
inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}

typedef long long ll;
ll MOD = 1000000007;

// a^p
// 2^3 = 2 * 2^2
// 2^2 = 2 * (2^1)
// 2^1 = 2
ll modpow(ll a, ll p, ll mod) {
  if (p == 0) return 1;

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

// nCa を求める
ll modCombination(ll n, ll a, ll mod) {
  if (n - a < a) {
    return modCombination(n, n - a, mod);
  }

  ll denominator = 1;  // 分母
  ll numerator = 1;    // 分子

  for (ll i = 0; i < a; i++) {
    denominator *= a - i;
    numerator *= n - i;
    denominator %= mod;
    numerator %= mod;
  }

  return numerator * modpow(denominator, mod - 2, mod) % mod;
}

class UnionFind {
 private:
  vector<ll> parents;

 public:
  UnionFind(ll n) : parents(n, -1) {}

  bool issame(ll x, ll y) { return root(x) == root(y); }

  bool merge(ll x, ll y) {
    if (issame(x, y)) return false;

    ll rx = root(x);
    ll ry = root(y);
    if (parents[rx] > parents[ry]) swap(rx, ry);
    // サイズ情報を更新
    parents[rx] += parents[ry];
    // yの親を更新
    parents[ry] = rx;

    return true;
  }

  ll size(ll x) { return -parents[root(x)]; }

 private:
  ll root(ll x) {
    if (parents[x] < 0) return x;
    // 根の親の値に木の(-)サイズの情報を入れる
    return parents[x] = root(parents[x]);
  }
};

ll gcd(ll a, ll b) {
  if (a % b == 0) {
    return (b);
  } else {
    return (gcd(b, a % b));
  }
}

int main() {
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(15);

  ll N;
  cin >> N;
  vector<ll> H(N);

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

  ll ans = 0;
  for (ll i = 0; i < N;) {
    // cout << i << endl;
    ll current = H[i];
    ll j = i + 1;
    ll count = 0;
    while (j < N && current >= H[j]) {
      current = H[j];
      j++;
      count++;
    }
    i = j;
    ans = max(ans, count);
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define REP2(i, a, b) for (int i = (a); i < (int)(b); i++)
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef long long ll;
#define ALL(V) V.begin(), V.end()


int Main(int A, int B)
{
    int n_tap = 0;
    int n_plug = 1;
    while(n_plug < B) {
        n_plug += A - 1;
        n_tap++;
    }
    return n_tap;
}

int main(void){
    int A, B;
    cin >> A >> B;
    cout << Main(A, B) << endl;
    return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize("O2")
#include <bits/stdc++.h>
using namespace std;
int main()
{
	int cnt=0;
	int t;
	cin>>t;
	for(int i=1; i<=t; i++){
		int a; cin>>a;
		if(i&1 and a&1)cnt++;
	}
	cout<<cnt<<'\n';
}

Measured memory_bytes: 3616
n,*B=map(int,open(0).read().split())
a=[]
while n:
	f=1
	for i,b in enumerate(B[::-1]):
		if b==n-i:
			n-=1
			a+=[B.pop(b-1)]
			f=0
			break
	if f:
		print(-1)
		exit()
print(*a[::-1],sep="\n")

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

void prians(bool answer) {
  if(answer)
    cout << "YES" << endl;
  else
    cout << "NO" << endl;
}

int a, b, c, now = 0;
bool ch[105] = {0};

int main() {
  cin >> a >> b >> c;
  a %= b;
  while(!ch[now]) {
    ch[now] = 1;
    now += a;
    now %= b;
  }
  prians(ch[c]);
  return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int (i) = 0; i < (n); i++)

int main(){
  int a, b, c, k = 0;
  cin >> a >> b >> c;
  
  while(a % 2 == 0 && b % 2 == 0 && c % 2 == 0){
    if(a == b && b ==c) {
       cout << "-1" << endl;
       return 0;
    }
    k++;
    int tmp1 = a;
    int tmp2 = b;
    int tmp3 = c;
    a = (tmp2 + tmp3) / 2;
    b = (tmp1 + tmp3) / 2;
    c = (tmp1 + tmp2) / 2;
  }
  cout << k << endl;
}	

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

int main()
{
    string s,t;
    cin >> s >> t;
    for(int i=0;i<100;i++){
        s=s[s.size()-1]+s;
        s.pop_back();
        if(s==t){
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i,a,b) for(int i=(a),_end_=(b);i<=_end_;i++)
#define DREP(i,a,b) for(int i=(a),_end_=(b);i>=_end_;i--)
#define EREP(i,u) for(int i=start[u];i;i=e[i].next)
#define fi first
#define se second
#define mkr(a,b) make_pair(a,b)
#define SZ(A) ((int)A.size())
template<class T>inline void chkmax(T &a,T b){ if(a<b)a=b;}
template<class T>inline void chkmin(T &a,T b){ if(a>b)a=b;}
inline int read()
{
    int s=0,f=1; char ch=getchar();
    while(!isdigit(ch) && ch!='-')ch=getchar();
    if(ch=='-')ch=getchar(),f=-1;
    while(isdigit(ch))s=s*10+ch-'0',ch=getchar();
    return ~f?s:-s;
}

const int maxn=1e6+20;
const ll mod=998244353;

vector<int>ed[maxn];
int n;

inline void init()
{
    n=read();
    REP(i,1,n-1)
    {
	int u=read(),v=read();
	ed[u].push_back(v);
	ed[v].push_back(u);
    }
}

int cir[maxn],len;

inline int bfs(int S)
{
    static int dis[maxn],pre[maxn];
    memset(dis,-1,sizeof(dis));
    queue<int>q;
    q.push(S); dis[S]=0; pre[S]=0;
    while(!q.empty())
    {
	int u=q.front(); q.pop();
	for(int v:ed[u])
	    if(dis[v]==-1)
		q.push(v),dis[v]=dis[u]+1,pre[v]=u;
    }
    int T=0,tmx=0;
    REP(i,1,n)if(dis[i]>tmx)tmx=dis[i],T=i;
    int x=T;
    len=0;
    while(x)cir[++len]=x,x=pre[x];
    reverse(cir+1,cir+len+1);
    return T;
}

int rt;

inline void find_Len()
{
    int S=bfs(1);
    int T=bfs(S);
    if(len%2==1)rt=cir[len+1>>1];
    else {
	int x=cir[len>>1],y=cir[len+2>>1];
	ed[x].erase(find(ed[x].begin(),ed[x].end(),y));
	ed[y].erase(find(ed[y].begin(),ed[y].end(),x));
	++n;
	ed[x].push_back(n); ed[y].push_back(n);
	ed[n]={x,y};
	rt=n;
    }
}

int ans;

int deep[maxn];
ll dp[maxn][3][3];

void dfs(int u,int fa)
{
    int son=0;
    for(int v:ed[u])
    {
	if(v==fa)continue;
	deep[v]=deep[u]+1;
	dfs(v,u);
	son++;
    }
    if(!son)dp[u][deep[u]==len/2][deep[u]==len/2]=1;
    else {
	dp[u][0][0]=1;
	for(int v:ed[u])
	{
	    if(v==fa)continue;
	    ll g[3][3]={0};
	    REP(a,0,2)REP(b,0,2)REP(c,0,2)REP(d,0,2)REP(edge,-1,1)
		(g[min(a+c*(edge==1),2)][min(b+d*(edge==-1),2)]+=dp[u][a][b]*dp[v][c][d])%=mod;
	    REP(a,0,2)REP(b,0,2)dp[u][a][b]=g[a][b];
	}
    }
}

inline void doing()
{
    find_Len();
    dfs(rt,0);
    printf("%lld\n",(ll)dp[rt][1][1]*(mod+1>>1)%mod);
}

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


Measured memory_bytes: 66304
w, h, n = map(int, input().split())
right, left, lower, upper = 0, w, 0, h
for _ in range(n):
    x, y, a = map(int, input().split())
    if a == 1:
        right = max(right, x)
    if a == 2:
        left = min(left, x)
    if a == 3:
        lower = max(lower, y)
    if a == 4:
        upper = min(upper, y)

a = left - right
b = upper - lower

if a <= 0 or b <= 0:
    print(0)
else:
    print(a*b)

Measured memory_bytes: 9172
#ifdef _MSC_VER
#define _CRT_SECURE_NO_WARNINGS
#endif

#include <bits/stdc++.h>

using namespace std;

#define POW2(X) (1<<(X))
#define CKBIT(S,X) (((S)&POW2(X))!=0)

template<class T> inline void nlmin(T &a,T b){ a=min(a,b); }
template<class T> inline void nlmax(T &a,T b){ a=max(a,b); }
template<class T> inline T sqr(T x){ return x*x; }
#define SIZE(A) ((int)A.size())
#define LENGTH(A) ((int)A.length())

#define PB(X) push_back(X)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define RFOR(i,a,b) for(int i=(a);i>(b);--i)
#define REP(i,n) for(int i=0;i<(n);++i)
#define ALL(A) A.begin(),A.end()
template<class T> int CMP(T a[],const T b[],int n) { return memcmp(a,b,n*sizeof(T)); }
template<class T> void COPY(T a[],const T b[],int n) { memcpy(a,b,n*sizeof(T)); }
template<class T> void SET(T a[],int val,int n) { memset(a,val,n*sizeof(T)); }
//using uint=unsigned int;
typedef long long int64;
//using uint64=unsigned long long;
typedef pair<int,int> pii;
typedef vector<int> VI;
typedef vector<VI> VII;
// using VD=vector<double>;
const int kmod = 1000000007;


int main() {

	int N, W;
	while (cin >> N >> W) {
		VI w(N+1), v(N+1);
		FOR (i, 1, N + 1) cin >> w[i] >> v[i];

		int bound = N * 1000;
		vector<int64> dp(bound + 1, INT_MAX);
		dp[0] = 0;
		FOR (i, 1, N + 1) RFOR (j, bound, v[i] - 1) {
			nlmin(dp[j], dp[j - v[i]] + w[i]);
		}
		int ret = 0;
		FOR (i, 0, bound + 1) {
			if (dp[i] <= W) 
				ret = i;
		}
		cout << ret << endl;

	}
	return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <algorithm>
#include <deque>
using namespace std;
using ll = long long;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n;
    cin >> n;
    int T = n;
    deque<ll>dq;
    bool right = !(n % 2);
    while(T--)
    {
        ll tmp;
        cin >> tmp;
        if(right) {
            dq.push_back(tmp);
        }
        else {
            dq.push_front(tmp);
        }
        right = !right;
    }
    cout<<dq.front();
    dq.pop_front();
    while(!dq.empty()) {
        cout<<" "<<dq.front();
        dq.pop_front();
    }
    cout<<endl;
}

Measured memory_bytes: 3840
#include<stdio.h>

void bubble(int A[], int N){
    int flag = 1;
    int temp = 0;
    int counter = 0;
    while(flag){
        flag = 0;
        for(int j = N-1; j > 0; j--){
            if(A[j]<A[j-1]){
                temp = A[j];
                A[j] = A[j-1];
                A[j-1] = temp;
                flag = 1;
                counter++;
            }  
        }
    }
    for(int i = 0;i < N; i++){
        if(i!=0) printf(" ");
        printf("%d", A[i]);
    }
    printf("\n");
    printf("%d\n", counter);
    return;
}

int main(void){
    int i = 0;
    int N = 0;
    int A[100];
    scanf("%d\n", &N);
    for(i=0; i<N; i++){
        scanf("%d",&A[i]);
    }
    bubble(A, N);
    return 0;
}

Measured memory_bytes: 1756
import math

A,B,H,M = map(int,input().split())

theta_h=2*math.pi*(H+M/60)/12
theta_m=2*math.pi*M/60

vh=[A*math.cos(theta_h), A*math.sin(theta_h)]
vm=[B*math.cos(theta_m), B*math.sin(theta_m)]
print(math.sqrt((vh[0]-vm[0])**2+(vh[1]-vm[1])**2))


Measured memory_bytes: 9512
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
typedef vector<int> vec1;
typedef vector<string> vec2;
typedef vector<double> vec3;

int main() {

  int n;
  cin >> n;
  vector<long> a(n);
  for(int i = 0; i < n; i++) {
    cin >> a.at(i);
  }

  sort(a.begin(), a.end());
  ll ans = a.at(n-1) - a.at(0);
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <sstream>
#include <stdio.h>
#include <vector>
#include <stack>
#include <queue>
#include <algorithm>
#include <math.h>
#include <utility>
#include <string>
#include <ctype.h>
#include <cstring>
#include <cstdio>
#include <sstream>
#include <functional>

using namespace std;

#define FOR(i,k,n) for(int i = (k); i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define INF 1145141919
#define ll long long
//#define scanf scanf_s

int cgcm(int a,int b)
{
	int tmpa = a, tmpb = b;
	if (a < b) swap(a, b);
	while (b)
	{
		a %= b;
		swap(a, b);
	}
	return tmpa / a*tmpb;
}
int main()
{
	int n, a, gcm;
	gcm = 1;
	cin >> n;
	REP(i, n)
	{
		cin >> a;
		gcm = cgcm(a, gcm);
	}
	cout << gcm << endl;
	return 0;
}

Measured memory_bytes: 1160
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<algorithm>
#include<cstring>
#include<ctime>
#include<deque>
#include<sstream>
#include<iomanip>
#include<sstream>
#include<vector>
#include<queue>
#include<stack>
#include<string>
#include<climits>
#include<map>
#include<set>
#include<list>
#include<cassert>
#include<deque>
#define REP(i,s,n) for(int i=s;i<n;i++)
#define rep(i,n) REP(i,0,n)
#define INF 1<<27
#define all(n) n.begin(),n.end()

#define F first
#define S second
#define pb push_back
#define foreach(i,c) for(iter(c) i=(c).begin();i!=(c).end();++i)
using namespace std;
typedef pair<int,int> P;
typedef pair<P,P> PP;
typedef long long ll;
typedef unsigned long long ull;

int main(){
  int N;

  while(cin >> N){  
    int res;
    vector<int> el;
    rep(i,N-1){
      int aa;
      cin >> aa;
      el.pb(aa);
    }
    cin >> res;
    ull cnt = 0;
    ull dp[22][102];
    rep(i,102)rep(j,22)dp[j][i] = 0;
    dp[el[0]][0] = 1;

    rep(i,el.size()-1){
      // cout << "i = " << i << endl;
      rep(j,21){
	if(dp[j][i] == 0)continue;
	int next = j + el[i+1];
	if(0<= next && next <= 20){
	  dp[next][i+1] += dp[j][i];
	} 
	next = j - el[i+1];
	if(0<= next && next <= 20){
	  dp[next][i+1] += dp[j][i];
	}
      }
    }
  

    cout << dp[res][el.size()-1] << endl;

  }
return 0;
}

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

using ll = long long ;
ll M = pow(10,9) + 7;

int main() {
	int n, m;
	cin >> n >> m;
	
	char a[n][m];
	for(int i = 0; i < n; i++)
		for(int j = 0; j < m; j++)
			cin >> a[i][j];
			
	ll dp[n][m];
	memset(dp, 0, sizeof(dp));
	
    dp[0][0] = 1;
	for(int i = 1; i < n; i++)	
		if(a[i][0] == '.')
            dp[i][0] += dp[i-1][0];

	for(int j = 1; j < m; j++)	
		if(a[0][j] == '.')
            dp[0][j] += dp[0][j-1];
		
	
	for(int i = 1; i < n; i++)
		for(int j = 1; j < m; j++) {
			if(a[i][j] == '.')
				dp[i][j] = (dp[i-1][j]%M + dp[i][j-1]%M) % M;
		}

	cout << (dp[n-1][m-1] % M);
	return 0;
}

Measured memory_bytes: 9088
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <tuple>
#include <cmath>
#include <cstdio>
#include <cassert>
#include <functional>
#define _LIBCPP_DEBUG 0
using namespace std;


int main(void){
    int n;
    cin >> n;
    char prev,next;
    cin >> prev;
    int count=1;
    for (int  i = 1; i < n; i++)
    {
        cin >> next;
        if (prev!=next)
        {
            count++;
        }
        prev=next;
    }
    cout << count << endl;
}


Measured memory_bytes: 3640
#include<bits/stdc++.h>
#define long long long
using namespace std;
const int N=1e6,inf=1e9;
int parn[N+2],lv[N+2],n;
vector<int>adj[50+2];
map<pair<int,int>,int>mp;
long dp[52][(1<<20)+2];
void dfs(int node,int par,int l)
{
  parn[node]=par,lv[node]=l;
  for(auto x:adj[node])
  {
    if(x==par)continue;
    dfs(x,node,l+1);
  }
}
int pre[N+2];
void upd(int u,int v,int id)
{
  if(u>v)swap(u,v);
  pre[mp[{u,v}]]|=(1<<(id-1));
}
void lca(int u,int v,int id)
{
  if(lv[u]<lv[v])swap(u,v);
  while(lv[u]>lv[v])
  {
    upd(u,parn[u],id);
    u=parn[u];
  }
  while(u!=v)
  {
    upd(u,parn[u],id);u=parn[u];

    upd(v,parn[v],id);v=parn[v];
  }
}
int q;
long dfs(int i,int msk)
{
  if(i==n)return (msk==((1<<q)-1));
  if(dp[i][msk]!=-1)return dp[i][msk];
  return dp[i][msk]=dfs(i+1,msk)+dfs(i+1,msk|pre[i]);
}
int main()
{
  ios_base::sync_with_stdio(0);cin.tie(0);
  cin>>n;
  for(int i=1;i<n;i++)
  {
    int u,v;cin>>u>>v;if(u>v)swap(u,v);
    adj[u].push_back(v);adj[v].push_back(u);
    mp[{u,v}]=i;
  }
  dfs(1,-1,0);
  cin>>q;
  for(int i=1;i<=q;i++)
  {
    int u,v;cin>>u>>v;lca(u,v,i);
  }
  // for(int i=1;i<n;i++)
  //   cout<<pre[i]<<" ** ";
  // cout<<endl;
  memset(dp,-1,sizeof(dp));
  cout<<dfs(1,0)<<endl;
  return 0;
}

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

#define iota(i,n,b,s) for(int i=int(b);i!=int((b)+(s)*(n));i+=(s))
#define range(i,n,m) iota(i,(((n)>(m))?((n)-(m)):((m)-(n))),(n),((n)>(m)?-1:1))
#define rep(i,n) iota(i,(n),0,1)
#define loop for(;;)

#define INF (1e9)
#define EPS (1e-9)
#define cons(a,b) (make_pair(a,b))
#define car(a) (a.first)
#define cdr(a) (a.second)
#define cadr(a) (car(cdr(a)))
#define cddr(a) (cdr(cdr(a)))
#define all(a) a.begin(), a.end()
#define trace(var) cerr<<">>> "<<#var<<" = "<<var<<endl;

typedef long long Integer;
typedef double Real;
typedef vector<int> vi;
typedef vector<string> vs;
typedef map<string,int> Dictionary;
const Real PI = acos(-1);

template<class S, class T>
ostream& operator<<(ostream& os, pair<S,T> p) {
  os << '(' << car(p) << ", " << cdr(p) << ')';
  return os;
}

template<class T>
ostream& operator<<(ostream& os, vector<T> v) {
  if (v.size() == 0) {
    os << "(empty)";
    return os;
  }
  os << v[0];
  for (int i=1, len=v.size(); i<len; ++i) os << ' ' << v[i];
  return os;
}

int dx[] = { -1, 0, 1, 0 };
int dy[] = {  0, -1, 0, 1 };

int main() {

  int n; cin >> n;
  rep (_, n) {
    int m; cin >> m; --m;
    int x; cin >> x;
    int mn = 0;
    int mx = 0;
    rep (i, m) {
      int y; cin >> y;
      mn = max(mn, x - y);
      mx = max(mx, y - x);
      x = y;
    }
    cout << mx << ' ' << mn << endl;
  }

  return 0;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define mp make_pair
#define pb push_back
#define f(i,x,n) for(int i=x;i<n;i++)
#define all(c) c.begin(),c.end()
#define print(x) cerr << (#x) << "is "<< x << "\n"
using ll = long long;
using pii = pair<int,int>;
const int MOD = 1e9+7, N = 1e5 + 10;

ll a[N],c=0;

int32_t main(){
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	int n;
	cin >> n;
	vector<ll> cn;
	vector<int> arr(n);
	int xr = 0;
	f(i,0,n){
		cin >> arr[i];
		xr = xr^arr[i];
	}
	if(xr == 0){
		cout <<"Yes\n";
	}else{
		cout << "No\n";
	}
	return 0;
}

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

void printAll(std::vector<int> A) {
    for (int i = 0; i < (A.size()-1); i++) {
        std::cout << A[i] << " ";
    }
    std::cout << A.back() << std::endl;
}

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

    int count = 0;
    int mini, tmp;
    for (int i = 0; i < A.size(); i++) {
        mini = i;
        for (int j = i; j < A.size(); j++) {
            if (A[j] < A[mini]) {
                mini = j;
            }
        }

        if (mini != i) {
            tmp = A[mini];
            A[mini] = A[i];
            A[i] = tmp;
            count++;
        }
    }

    printAll(A);
    std::cout << count << std::endl;
    
}


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

#if __has_include("print.hpp")
  #include "print.hpp"
#endif

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define MOD 1000000007

typedef long long ll;
typedef pair<ll, ll> p;


int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  int m, d;
  cin >> m >> d;
  ll res = 0;

  for (int i = 1; i <= m; i++) {
    for (int j = 1; j <= d; j++) {
      if((j / 10) >= 2 && (j % 10) >= 2){
        if((j % 10) * (j / 10) == i){
          res++;
        }
      }
    }
  }
  cout << res << endl;
}


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

int main() {
	
	int n;
	cin >> n;
	
	char ans[100];
	int digit;
	if(n == 0){
		puts("0");
		return 0;
	}else if(n > 0){
		// positive
		digit = 1;
		ll max_num = 1;
		ll min_num;
		while(max_num < n){
			min_num = max_num;
			digit += 2;
			max_num += 1LL << (digit - 1);
		}
		ans[0] = '1';
		for(int i = 1; i < digit; i++){
			int mid = (max_num + min_num) / 2;
			if(n <= mid){
				ans[i] = (i % 2 == 0) ? '0' : '1';
				max_num = mid;
			}
			else{
				ans[i] = (i % 2 == 0) ? '1' : '0';
				min_num = mid;
			}
		}
	}else{
		// negative
		n *= -1;
		digit = 2;
		ll max_num = 2;
		ll min_num;
		while(max_num < n){
			min_num = max_num;
			digit += 2;
			max_num += 1LL << (digit - 1);
		}
		ans[0] = '1';
		for(int i = 1; i < digit; i++){
			int mid = (max_num + min_num) / 2;
			if(n <= mid){
				ans[i] = (i % 2 == 0) ? '0' : '1';
				max_num = mid;
			}
			else{
				ans[i] = (i % 2 == 0) ? '1' : '0';
				min_num = mid;
			}
		}
	}
	
	rep(i, digit){
		printf("%c", ans[i]);
	}
	cout << endl;
	return 0;
}

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

using namespace std;

int main() {

	int w, m;

	while(cin >> w) {
		if(w==-1)
			break;
		m=0;
		if(w>=30) {
			m+=abs((double)(30-w))*160;
			w-=abs((double)(30-w));
		}
		if(w>=20) {
			m+=abs((double)(20-w))*140;
			w-=abs((double)(20-w));
		}
		if(w>=10) {
			m+=abs((double)(10-w))*125;
			w-=abs((double)(10-w));
		}
		if(w<=10)
			m+=1150;
		cout << 4280-m << endl;
	}

	return 0;

}

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

int main(){
	int tmp, a=0, b=0, c=0;
	for(int i=0;i<10;i++){
		cin>>tmp;
		if(tmp>a){
			c=b; b=a; a=tmp;
		}
		else if(tmp>b){
			c=b; b=tmp;
		}
		else if(tmp>c) c=tmp;
	}
	cout<<a<<endl<<b<<endl<<c<<endl;
	return 0;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
#define N 100007
using namespace std;
int r,c,n,v1[N],v2[N],v[N*2],a[N],b[N],mx[N*8];
bool side(int x,int y){
    return !x || x==r || !y || y==c;
}
int value(int x,int y){
    if(!y)return x;
    if(x==r)return r+y;
    if(y==c)return r+c+r-x;
    return r+c+r+c-y;
}
void update(int k,int l,int r,int x,int y){
    if(l==r){mx[k]=y;return;}
    int mid=(l+r)>>1;
    if(x<=mid)update(k*2,l,mid,x,y);
    else update(k*2+1,mid+1,r,x,y);
    mx[k]=max(mx[k*2],mx[k*2+1]);
}
int getmax(int k,int l,int r,int L,int R){
    if(L<=l && r<=R)return mx[k];
    int res=0,mid=(l+r)>>1;
    if(L<=mid)res=max(res,getmax(k*2,l,mid,L,R));
    if(R>mid)res=max(res,getmax(k*2+1,mid+1,r,L,R));
    return res;
}
int main(){
    scanf("%d%d%d",&r,&c,&n);
    int m=0,k=0;
    for(int i=1,x_1,y_1,x_2,y_2;i<=n;++i){
        scanf("%d%d%d%d",&x_1,&y_1,&x_2,&y_2);
        if(side(x_1,y_1) && side(x_2,y_2)){
            v1[++m]=value(x_1,y_1);
            v2[m]=value(x_2,y_2);
            if(v1[m]>v2[m])swap(v1[m],v2[m]);
            v[++k]=v1[m],v[++k]=v2[m];
        }
    }
    sort(v+1,v+k+1);
    k=unique(v+1,v+k+1)-v-1;
    for(int i=1;i<=m;++i){
        a[i]=lower_bound(v+1,v+k+1,v1[i])-v;
        b[i]=lower_bound(v+1,v+k+1,v2[i])-v;
        update(1,1,k,a[i],b[i]);
    }
    for(int i=1;i<=m;++i)
        if(getmax(1,1,k,a[i],b[i])>b[i]){
            puts("NO");
            return 0;
        }
    puts("YES");
}


Measured memory_bytes: 5760
#include <bits/stdc++.h>
#define rep(i, n) for(long long int i = 0; i < n; i++)
#define _rep(i, m, n) for(long long int i = m; i < n; i++)
#define print(n) std::cout << n << std::endl
#define _print(n) std::cout << n
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int N = 1000000;
const ll mod = 1000000007;
using Graph = vector<vector<int>>;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

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


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int,int> P;
int INF = 1e9+7;
int mod = 1e9+7;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
signed main(){
    int N;
    cin >> N;
    vector<int>cnt;
    int ans = 0;
    for(int i = 0; i < N; i++) {
        int A,B;cin >> A >> B;
        cnt.push_back(A+B);
        ans-=B;
    }
    sort(cnt.rbegin(),cnt.rend());
    for(int i = 0; i < N; i+=2) {
        ans+=cnt[i];
    }
    cout << ans << endl;
}


Measured memory_bytes: 4292
#include<bits/stdc++.h>
using namespace std;
int main(){
  int a[3],q=0;
  cin>>a[0]>>a[1]>>a[2];
  sort(a,a+3);
  if(abs(a[0]-a[1])>abs(a[1]-a[2])) swap(a[0],a[2]);
  q=q+abs(a[2]-a[1]);
  q=q+abs(a[1]-a[0]);
  cout<<q<<"\n";
}

    

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
int comp(const void *a, const void *b) {
	return *(const int *)b - *(const int *) a;
}

int main() {
	int n;
	scanf("%d", &n);
	int a[n];
	int b[n];
	for (int i = 0; i < n; i++) scanf("%d", a + i), b[i] = a[i];
	qsort(a, n, sizeof(int), comp);
	for (int i = 0; i < n; i++) {
		if (b[i] == a[0]) printf("%d\n", a[1]);
		else printf("%d\n", a[0]);
	}
	return 0;
}


Measured memory_bytes: 3120
n = int(input())
e = sorted([[int(i) for i in input().split()] for i in range(n)], key=lambda x:x[2])[::-1]

def f():
    for x in range(101):
        for y in range(101):
            flg = True
            H = e[0][2] + abs(x-e[0][0]) + abs(y-e[0][1])
            for e_ in e:
                if (e_[2] == 0):
                    if H > abs(x-e_[0]) + abs(y-e_[1]):
                        flg = False
                        break
                    else:
                        continue
                
                if H != e_[2] + abs(x-e_[0]) + abs(y-e_[1]):
                    flg = False
                    break
            if flg:
                return (x, y, H)
result = f()
print("{} {} {}".format(result[0], result[1], result[2]) )

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

using namespace std;

int main()
{
	int n, k;
	cin >> n >> k;
	unordered_map<int, int> a;
	for (int i = 0; i < n; i++)
	{
		int ai;
		cin >> ai;
		auto it = a.find(ai);
		if (it != a.end()) it->second++;
		else a[ai] = 1;
	}
	multiset<int> aa;
	for (auto&& p : a) aa.insert(p.second);
	int num = 0;
	auto it = aa.begin();
	for (int i = 0; i < (int)aa.size() - k; i++)
	{
		num += *it;
		it++;
	}
	cout << num << endl;
	return 0;
}


Measured memory_bytes: 17864
# ABC 076 D

N = int(input())
t = list(map(int, input().split()))
v = list(map(int, input().split()))

e = sum(t)*2
vmax = [0 for k in range(e+2)]

s = 0
for k in range(N):
    for l in range(1,t[k]*2+1):
        vmax[s+l] = v[k]
    s += t[k]*2

hidari = [0 for k in range(e+1)]
for k in range(1,e+1):
    hidari[k] = min(hidari[k-1]+0.5,vmax[k])

migi = [0 for k in range(e+1)]
for k in range(1,e+1):
    migi[e-k] = min(migi[e-k+1]+0.5,vmax[e-k+1])

ans = 0
for k in range(e+1):
    ans += min(hidari[k],migi[k])
print(ans/2)


Measured memory_bytes: 4120
#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[i];

    vector<int> ans(N);
    for (int i = N - 1; i >= 0; i--){
        int sum = 0;
        for(int j = 1; (i + 1) * j <= N; j++){
            sum += ans[(i + 1) * j - 1];
        }
        ans[i] = abs(sum - A[i]) % 2;
    }

    cout << accumulate(ans.begin(), ans.end(), 0) << endl;
    for(int i = 0; i < N; i++){
        if (ans[i] == 1){
            cout << i+1 << " ";
        }
    }
}

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

int main()
{
  int n,d=0;
  cin>>n;
  for(int i=1;i<=n;i++) 
  {
    int j;
    cin>>j;
    if(i!=j) d++;
  }
  if(d==0 || d==2) cout<<"YES";
  else cout<<"NO";
}

Measured memory_bytes: 256
N = int(raw_input())
S = raw_input()

num = S[1:].count('E')
score_list = []
score_list.append(num)

for i in range(N-1):
	if S[i]=='W':
		num+=1
	if S[i+1]=='E':
		num-=1
	score_list.append(num)
	
print min(score_list)

Measured memory_bytes: 21976
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <memory.h>
#include <math.h>
#include <assert.h>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <string>
#include <algorithm>
#include <iostream>
#include <functional>
#include <unordered_set>
#include <bitset>
#include <time.h>
#include <limits.h>

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define Fi first
#define Se second
#define pb(x) push_back(x)
#define szz(x) (int)x.size()
#define rep(i,n) for(int i=0;i<n;i++)
#define all(x) x.begin(),x.end()
typedef tuple<int, int, int> t3;

int N, M;
vector <int> E[1010], F[1010];
int X[1010][2], save[1010][2];
int idx[1010][1010];
int dif[200020];
vector <int> v;
int svis[1010], scc[1010], sid;

void dfs1(int x) {
	svis[x] = 1;
	for(int e : E[x]) if(svis[e] == 0) {
		dfs1(e);
	}
	v.pb(x);
}

void dfs2(int x) {
	scc[x] = sid;
	svis[x] = 2;
	for(int e : F[x]) if(svis[e] == 1) {
		dfs2(e);
	}
}

pii edge[200020];
int main() {
	scanf("%d%d", &N, &M);
	for(int i=1;i<=M;i++) {
		int x, y; scanf("%d%d", &x, &y);
		E[x].pb(y); F[y].pb(x);
		idx[x][y] = i;
		edge[i] = pii(x, y);
	}
	for(int i=1;i<=N;i++) {
		memset(X, 0, sizeof X);
		memset(save, 0, sizeof save);
		vector <pii> q;
		for(int e : E[i]) {
			save[e][0] = e;
			q.pb(pii(e, 0));
		}
		rep(j, szz(q)) {
			pii t = q[j];
			if(t.Fi == i) continue;
			int p = save[t.Fi][t.Se];
			for(int e : E[t.Fi]) {
				if(save[e][0] == 0) {
					save[e][0] = p;
					q.pb(pii(e, 0));
				}
				else if(save[e][1] == 0 && save[e][0] != p) {
					save[e][1] = p;
					q.pb(pii(e, 1));
				}
			}
		}
		for(int e : E[i]) {
			if(save[e][1]) {
				dif[idx[i][e]] = 1;
			}
		}
	}
	for(int i=1;i<=N;i++) if(svis[i] == 0) dfs1(i);
	reverse(all(v));
	for(int e : v) if(svis[e] == 1) {
		++sid; dfs2(e);
	}
	
	for(int i=1;i<=M;i++) {
		int x = edge[i].Fi, y = edge[i].Se;
		if((scc[x] == scc[y]) ^ dif[i]) puts("diff");
		else puts("same");
	//	printf("%d\n", dif[i]);
	}
	return 0;
}


Measured memory_bytes: 10624
#include <bits/stdc++.h>
#include <vector>
#define rep(i,n) for(int i = 0; i < n; i++)
using ll = long long;
using namespace std;
int main(){
  int n;
  cin >> n;
  int lowScore = 1000000000;
  int lowRank = 0;
  rep(i, n){
    int a;
    cin >> a;
    lowRank = max(lowRank, a);
    int b;
    cin >> b;
    lowScore = min(lowScore, b);
  }
  cout << lowScore + lowRank << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>

using std::cin;
using std::cout;
using std::endl;

int
main()
{
  int N;
  cin >> N;
  int tem = N;
  int sn = 0;
  while (tem != 0)
  {
    sn += tem % 10;
    tem /= 10;
  }
  cout << (N % sn == 0 ? "Yes" : "No") << endl;
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
const int N=200005;
int n,k;
int a[N];
struct BIT
{
	int C[N];
	int lowbit(int x)
	{
		return x&-x;
	}
	void clear()
	{
		memset(C,0,sizeof(C));
		return;
	}
	void add(int x,int y)
	{
		if(x>n) return;
		for(int i=x;i<=n;i+=lowbit(i))
			C[i]+=y;
		return;
	}
	int getsum(int x)
	{
		int res=0;
		for(int i=x;i>0;i-=lowbit(i))
			res+=C[i];
		return res;
	}
	void modify(int l,int r,int v)
	{
		l=max(l,1);
		r=min(r,n);
		add(l,v);
		add(r+1,-v);
		return;
	}
};
BIT T;
bool check()
{
	for(int i=1;i<=n;i++)
		if(a[i]<n) return false;
	return true;
}
int main()
{
	scanf("%d%d",&n,&k);
	for(int i=1;i<=n;i++)
		scanf("%d",&a[i]);
	for(int i=1;i<=k;i++)
	{
		T.clear();
		for(int i=1;i<=n;i++)
			T.modify(i-a[i],i+a[i],1);
		for(int i=1;i<=n;i++)
			a[i]=T.getsum(i);
		if(check()) break;
	}
	for(int i=1;i<=n;i++)
		printf("%d ",a[i]);
	return 0;
}

Measured memory_bytes: 5320
#include <bits/stdc++.h>
    using namespace std;
 
    #define fast ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
    #define mod 1000000007
    #define qmod 998244353
    #define M 1000001
    #define endl "\n"
    #define all(a) (a).begin(),(a).end()
    #define rep(i,a,b) for(int i=a;i<b;++i)
    #define repr(i,a,b) for(int i=a;i>=b;--i)
    #define F first
    #define S second
    #define pb push_back
    #define mp make_pair
 
    typedef long long ll;
    typedef pair<int,int> pii;
    typedef vector<int> vi;
    typedef vector<string> vs;
    typedef vector<pii> vii;
    typedef vector<vi> vvi;

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

        fast;
        int x,y,z;
        cin>>x>>y>>z;
        swap(x,y);
        swap(x,z);
        cout<<x<<" "<<y<<" "<<z;
        return 0;  
    }       
 
 
    //keep it simple stupid


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <tuple>
#include <bitset>
#include <memory>
#include <cmath>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <numeric>
#include <climits>
#include <cfloat>

int main() {
	int n; std::cin >> n;
	std::vector<std::vector<int>> events(n, std::vector<int>(3)); for (auto& event : events) for (auto& e : event) std::cin >> e;
	std::vector<std::vector<long long int>>memo(n, std::vector<long long int>(3, 0));
	for (auto i = 0; i < 3; ++i) memo[0][i] = events[0][i];
	for (auto i = 0; i < n - 1; ++i) {
		for (auto j = 0; j < 3; ++j) {
			for (auto d = 1; d < 3; ++d) {
				memo[i + 1][j] = std::max(memo[i + 1][j], memo[i][(j + d) % 3] + events[i + 1][j]);
			}
		}
	}
	std::cout << *std::max_element(memo.back().begin(), memo.back().end()) << std::endl;
}

Measured memory_bytes: 11136
package main

import (
	"fmt"
	"bufio"
	"os"
	"strconv"
)

//=====I/O=====

var (
	sc = bufio.NewScanner(os.Stdin)
	wr = bufio.NewWriter(os.Stdout)
)

func scanInt() int {
	sc.Scan()
	a,_ := strconv.Atoi(sc.Text())
	return a
}

func scanInt64() int64 {
	sc.Scan()
	a,_ := strconv.ParseInt(sc.Text(),10,64)
	return a
}

func scanFloat64() float64 {
	sc.Scan()
	a,_ := strconv.Atoi(sc.Text())
	return float64(a)
}

func scanInts(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ { res[i] = scanInt() }
	return res
}

func scanText() string {
	sc.Scan()
	return sc.Text()
}

func printInts(a ...int) {
	for i, e := range a {
		fmt.Fprint(wr, e)
		if i != len(a)-1 { fmt.Fprint(wr, " ") }
	}
	fmt.Fprintln(wr)
	wr.Flush()
}

//•*¨*•.¸¸♪func•*¨*•.¸¸♪

//•*¨*•.¸¸♪main•*¨*•.¸¸♪

func main() {
	sc.Split(bufio.ScanWords)
	// sc.Buffer(make([]byte, 10000), 100000000)

	n := scanInt()
	ps := scanInts(n)

	a := 10000000

	cnt := 0

	for i := 0; i < n; i++ {
		if ps[i]<=a {
			cnt++
			a=ps[i]
		}
	}

	fmt.Println(cnt)
}


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

int main() {
  int height, width;
  string str;
  cin >> height >> width;
  char msMatrix[height][width]; // set up a matrix of Minesweeper

  // input to matrix
  for (int i = 0; i < height; i++) {
    cin >> str;
    for (int j = 0; j < width; j++) {
      msMatrix[i][j] = str.at(j);
    }
  }

  // set up a matrix of bomb counter
  int countMatrix[height+2][width+2];
  for (int i = 0; i < height+2; i++) {
    for (int j = 0; j < width+2; j++) {
      countMatrix[i][j] =0; // initialize
    }
  }

  // count bombs up in matrix
  for (int i = 0; i < height; i++) {
    for (int j = 0; j < width; j++) {
      if (msMatrix[i][j] == '#') {
        // add bomb's amount to 9 blocks around the bomb (including his own)
        for (int x = 0; x < 3; x++) {
          for (int y = 0; y < 3; y++) {
              countMatrix[i+x][j+y] += 1;
          }
        }
      } // if (msMatrix[i][j] == '#')
    }
  }
  
  // display the number of bombs
  for (int i = 0; i < height; i++) {
    for (int j = 0; j < width; j++) {
      if (msMatrix[i][j] == '#') {
        cout << '#';
      }
      else {
        cout << countMatrix[i+1][j+1];
      }
    }
    cout << endl;
  }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll int64_t
#define rep(i,n) for(int64_t i=0;i<n;++i)
#define P pair<ll,ll>
#define Graph vector<vector<ll>>
#define fi first
#define se second
constexpr int64_t INF=(1ll<<60);
constexpr int64_t mod=1000000007;
constexpr double pi=3.14159265358979323846;
template<typename T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<typename T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main(){
    ll n,r;cin>>n>>r;
    if(n>=10) cout<<r<<endl;
    else cout<<r+100*(10-n)<<endl;
    return 0;
}

Measured memory_bytes: 3616
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;++i)
#define rrep(i,n) for(int i=(int)n-1;i>=0;--i)
using namespace std;
using ll = long long;
using P = pair<int, int>;
template<typename T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<typename T> inline bool chmin(T& a,T b){if(b<a){a=b;return 1;}return 0;}
template<typename T> vector<T> make_vec(size_t a){return vector<T>(a);}
template<typename T,typename... Ts>
auto make_vec(size_t a,Ts... ts){return vector<decltype(make_vec<T>(ts...))>(a,make_vec<T>(ts...));}
template<typename T,typename U,typename... V>
typename enable_if<is_same<T,U>::value>::type fill_v(U& u,const V... v){u=U(v...);}
template<typename T,typename U,typename... V>
typename enable_if<!is_same<T,U>::value>::type fill_v(U& u,const V... v){for(auto& e:u)fill_v<T>(e,v...);}

const int mod = 1000000007;

struct mint {
    long long x;
    mint(long long x=0) : x((x % mod + mod) % mod) {}
    mint operator-() const { return mint(-x);}
    mint& operator+=(const mint a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator-=(const mint a) {
        if ((x += mod - a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
    mint operator+(const mint a) const { return mint(*this) += a;}
    mint operator-(const mint a) const { return mint(*this) -= a;}
    mint operator*(const mint a) const { return mint(*this) *= a;}
    mint pow(long long t) const {
        if (!t) return 1;
        mint a = pow(t>>1);
        a *= a;
        if (t&1) a *= *this;
        return a;
    }
    mint inv() const { return pow(mod-2);}
    mint& operator/=(const mint a) { return *this *= a.inv();}
    mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    
    int n;
    cin >> n;
    string s;
    cin >> s;
    
    for (int i = 0; i < 2*n; i += 2) s[i] = s[i] ^ 'B' ^ 'W';
    int cnt = 0;
    for (int i = 0; i < 2*n; ++i) if (s[i] == 'W') cnt++;
    if (cnt != n) {
        cout << 0 << endl;
        return 0;
    }
    cnt = 0;
    mint ans = 1;
    for (int i = 0; i < 2*n; ++i) {
        if (s[i] == 'W') cnt++;
        else ans *= cnt--;
    }
    for (int i = 1; i <= n; ++i) ans *= i;
    cout << ans << endl;
}


Measured memory_bytes: 3708
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>

using namespace std;

int main()
{
	int n,k;
	cin >> n >> k;
	vector<int> count(n,0);
	for(int i=0;i<n;i++)
	{
		int a;
		cin >> a;
		a--;
		count[a]++;
	}
	sort(count.begin(),count.end());
	reverse(count.begin(),count.end());
	int ans=0;
	for(int i=k;i<n;i++)
		ans+=count[i];


	cout << ans << endl;


	
}

Measured memory_bytes: 1024
#include<iostream>
int main(){
  int f[2],i,j;
  std::string r,a;
  while(std::cin>>r>>a,r!="0"&&a!="0"){
    for(f[0]=f[1]=i=0;i<4;i++)for(j=4;j-->0;)if(a[i]==r[j])f[i!=j]++;
    std::cout<<f[0]<<" "<<f[1]<<"\n";
  }
}

Measured memory_bytes: 912
#include<set>
#include<map>
#include<list>
#include<queue>
#include<stack>
#include<string>
#include<time.h>
#include<math.h>
#include<memory>
#include<vector>
#include<bitset>
#include<fstream>
#include<stdio.h>
#include<utility>
#include<sstream>
#include<string.h>
#include<iostream>
#include<stdlib.h>
#include<algorithm>
using namespace std;
int main()
{
    #ifdef absi2011
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    #endif
    int n;
    scanf("%d",&n);
    int i;
    long long ans=0;
    long long sum=0;
    int min_ans=1000000007;
    for (i=0;i<n;i++)
    {
        int a,b;
        scanf("%d%d",&a,&b);
        if (a>b)
        {
            sum+=a-b;
            ans+=a;
            min_ans=min(min_ans,b);
        }
        else
        {
            ans+=a;
        }
    }
    if (min_ans==1000000007)
    {
        cout<<0<<endl;
        return 0;
    }
    cout<<ans-min_ans<<endl;
    return 0;
} 


Measured memory_bytes: 256
if __name__ == '__main__':
    s = input()
    K = int(input())

    subs = []
    for i in range(len(s)):
      for j in range(K):
            try:
                subs.append(s[i:i+j+1])
            except:
                break
    subs = set(subs)
    print(sorted(list(subs))[K-1])

Measured memory_bytes: 5004
#include <iostream>
#include <string>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  int N, K;
  string S;
  cin >> N >> K;
  cin >> S;
  S[K-1] = S[K-1] + 'a' - 'A';
  cout << S << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long int
#define ipair pair<ll, ll>
#define debug(a, st, en){for(ll i = st; i <= en; i++){cout << a[i] << " "; } cout << endl;}
#define debuga(a) cout << #a << " = " << a << endl;
#define mp make_pair
#define pb push_back
#define is insert
#define endl "\n"
#define FOR(i, a, b) for(ll i = a; i <= b; i++)
#define FORD(i, a, b) for(ll i = a; i >= b; i--)
#define EACH(it, a) for(__typeof(a.begin()) it = a.begin(); it != a.end(); ++it)
#define cins(_x, a, b) {for(ll $i = a; $i <= b; $i++) cin >> _x[$i];}
#define EPS 0.0000000001
#define fl float
#define db double
#define MOD 1000000007
#define MAX 1000007

using namespace std;

string a, b, c;
ll n;

int main() {
    cin >> n >> a >> b >> c;
    ll _c = 0;
    FOR(i, 0, n-1) {
        set<char> ss;
        ss.is(a[i]);
        ss.is(b[i]);
        ss.is(c[i]);
        _c += (ss.size()-1);
    }
    cout << _c << endl;
    return 0;
}


Measured memory_bytes: 256
//Littleboy123 Template 1.1

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

//pragmas
/*
#pragma comment(linker, "/stack:200000000")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC target ("avx2")
#pragma GCC optimization ("Ofast")
#pragma GCC optimization ("unroll-loops")
*/

typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;

#define FOR(a,b,c) for(ll (a)=(b);(a)<(c);++(a))
#define FORE(a,b,c) for(ll (a)=(b);(a)<=(c);++(a))
#define FORN(a,b,c) for(ll (a)=(b);(a)>(c);--(a))
#define FORNE(a,b,c) for(ll (a)=(b);(a)>=(c);--(a))
#define COUT(a) cout << (a) << '\n'
#define MEM(a,b) memset((a), (b), sizeof((a)))
#define MAX(a,b) (a) = max((a), (b))
#define MIN(a,b) (a) = min((a), (b))
#define nl '\n'
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define pi acos(-1.0)

void init(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
}

//End of template

vi adjlist[200005];
int parent[200005];
int visited[200005];
ll add[200005];
ll ans[200005];

void dfs(int front){
	int sz = adjlist[front].size();
	//cout << front << endl;
	FOR(i, 0, sz){
		//cout << adjlist[front][i] << endl;
		if(visited[adjlist[front][i]] == 0){
			visited[adjlist[front][i]] = 1;
			parent[adjlist[front][i]] = front;
			dfs(adjlist[front][i]);
		}
	}
}

void dfs2(int front, int val){
	val += add[front];
	ans[front] += val;
	int sz = adjlist[front].size();
	FOR(i, 0, sz){
		if(parent[adjlist[front][i]] == front){
			dfs2(adjlist[front][i], val);
		}
	}
}

int main(){  
	init();

	//debug
	/*
	ifstream in("input.in");
	streambuf *cinbuf = std::cin.rdbuf();
	cin.rdbuf(in.rdbuf());

	ofstream out("out.txt");
	streambuf *coutbuf = std::cout.rdbuf();
	cout.rdbuf(out.rdbuf());
	*/
	//end debug

	int n;
	cin >> n;
	int q;
	cin >> q;
	int x, y;
	FOR(i, 1, n){
		cin >> x >> y;
		adjlist[x].pb(y);
		adjlist[y].pb(x);
	}
	MEM(parent, 0);
	MEM(add, 0);
	MEM(ans, 0);
	visited[1] = 1;
	dfs(1);
	FOR(i, 0, q){
		cin >> x >> y;
		add[x] += y;
	}
	dfs2(1, 0);
	FORE(i, 1, n){
		cout << ans[i];
		if(i == n){
			cout << nl;
		}
		else{
			cout << ' ';
		}
	}
	return 0;
}

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

int main() {
  int n,ans = 0;
  string s;
  cin >> n >> s;
  for(int i = 0;i < 1000; i++){
    ostringstream sout;
    sout << setw(3) << setfill('0') << i;
    string t = sout.str();
    int k = 0;
    for (int j = 0; j < n; j++)
    {
      if(s[j] == t[k]){
        k++;
      }
      if(k == 3){
        break;
      }
    }
    if(k == 3){
      ans++;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;
int main (void) {
    int a, b, c;
    cin >> a >> b >> c;
    string s = (a+b >= c) ? "Yes" : "No";
    cout << s << endl;
}


Measured memory_bytes: 256
#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);
  }
  sort(a.begin(), a.end());
  reverse(a.begin(), a.end());
  int ans =0;
  for(int i = 0; i < N;++i){
    if(i%2==0) {
      ans += a.at(i);
    } else{
      ans -= a.at(i);
    }
  }
  cout << ans << endl;
  
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define sz(v)   ((int)(v).size())
#define  all(v)    ((v).begin()),((v).end())
#define  allr(v)    ((v).rbegin()),((v).rend())
#define   pb         push_back
#define   mp         make_pair
#define    clr(v,d)      memset( v, d ,sizeof(v))
typedef  long long     ll ;
using namespace std;
void GO(){ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);}
const int N=1009;
int cnt[12],p[12];
vector< vector<int> > v(12);
int main(){
    GO();
    int n,m;
    cin>>n>>m;
    for(int i=0;i<m;i++){
        int k;
        cin>>k;
        for(int j=0;j<k;j++){
            int no;
            cin>>no;
            no--;
            v[no].pb(i);
        }
    }
    for(int i=0;i<m;i++) cin>>p[i];
    int ans=0;
    for(int i=0;i<(1<<n);i++){
        clr(cnt,0);
        for(int j=0;j<n;j++){
            int d= ((i>>j)&1);
            if(d){
                for(int k=0;k<sz(v[j]);k++){
                    int nw=v[j][k];
                    cnt[nw]++;
                }
            }
        }
        int ok=0;
        for(int j=0;j<m;j++){
            if(cnt[j]%2==p[j])
                ok++;
        }
        if(ok==m)
            ans++;
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <vector>
#include <iostream>
#include <map>
#include <cmath>
#include <string>
#include <algorithm>
#include <math.h>
using namespace std;

#define rep(i, o) for (ll i = 0; i < (o);i++)
#define rep_s(i, o) for (int i = 1; i <= (o);i++)
#define REP(i,a,b)for(int i=(int)(a);(i)<(int)(b);i++)
#define NUM 1e5

typedef long long ll;
typedef unsigned long long ull;

ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
ll lcm(ll c, ll d) { return c / gcd(c, d) * d; }


template<class T>
bool chmax(T &a, const T &b) {
    if (a < b)
    {
        return b;
    }
    return a; 
}

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

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

    REP(i, -100, 201) {
        REP(j, -100, 201) {
            if (i*i*i*i*i - (j*j*j*j*j) == x) 
            {
                cout << i << " " << j << endl;
                return 0;
            }
        }
    }
    return 0;
}

Measured memory_bytes: 3592
# AOJ 0281: Formation
# Python3 2018.6.26 bal4u

Q = int(input())
for i in range(Q):
	c, a, n = map(int, input().split())
	if n <= c and n <= a:
		ans = n
		c -= n
		a -= n
		if a <= c:
			if 2*a >= c: ans += (c >> 1)
			else:
				ans += a
				c -= 2 * a
				ans += c // 3
		else: ans += (c >> 1);
	elif a <= c and a <= n: ans = a + (c-a) // 3
	else: ans = c
	print(ans)


Measured memory_bytes: 5596