akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <algorithm>
#include <tuple>
#include <queue>
#include <set>

using namespace std;

vector<long> a, b, c;

using T = tuple<int, int, int>;

long read() {
  long n;
  cin >> n;
  return n;
}

long value(const T& v) {
  return a[get<0>(v)] + b[get<1>(v)] + c[get<2>(v)];
}

void output(const T& v) {
  cout << value(v) << endl;
}

int main() {
  int x, y, z, k;
  cin >> x >> y >> z >> k;

  for (int i=0; i<x; ++i)
    a.push_back(read());

  for (int i=0; i<y; ++i)
    b.push_back(read());

  for (int i=0; i<z; ++i)
    c.push_back(read());

  vector<long> all;
  
  sort(a.begin(), a.end());
  sort(b.begin(), b.end());
  sort(c.begin(), c.end());

  set<T> done;
  priority_queue<pair<long, T>> q;
  T t = {x - 1, y - 1, z - 1};
  q.emplace(value(t), t);

  for (int i = 0; i < k; ++i) {
    long val;
    T t;

    tie(val, t) = q.top();
    q.pop();
    cout << val << endl;

    int u, v, w;
    tie(u, v, w) = t;
    T v1 = {u - 1, v, w};
    T v2 = {u, v - 1, w};
    T v3 = {u, v, w - 1};

    if (!done.count(v1) && u - 1 >= 0) {
      q.emplace(value(v1), v1);
      done.insert(v1);
    }
    if (!done.count(v2) && v - 1 >= 0) {
      q.emplace(value(v2), v2);
      done.insert(v2);
    }
    if (!done.count(v3) && w - 1 >= 0) {
      q.emplace(value(v3), v3);
      done.insert(v3);
    }
    
  }
  
  // for (int i = 0; i < k; ++i) {
  //   output(v);
  //   v = next(v);
  // }
  return 0;
}


Measured memory_bytes: 4140
//#pragma GCC optimize("trapv")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("avx,avx2,sse,sse2,fma,tune=native")
#include<bits/stdc++.h>
#define rall(x) x.rbegin(), x.rend()
#define all(x) x.begin(), x.end()
#define pb push_back
#include <x86intrin.h>
#define pb push_back
using namespace std;
using ll = long long;
using pi = pair<int, int>;
using vi = vector<int>;
using vpi = vector<pi>;
using ld = long double;
const int maxn = 5e5 + 55, mod = 1e9 + 7 , i2 = (mod+1)/2;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
template <class T> int sgn(T x) { return (x > 0) - (x < 0); }
template<class T>
struct Point {
	typedef Point P;
	T x, y;
	explicit Point(T x=0, T y=0) : x(x), y(y) {}
	bool operator<(P p) const { return tie(x,y) < tie(p.x,p.y); }
	bool operator==(P p) const { return tie(x,y)==tie(p.x,p.y); }
	P operator+(P p) const { return P(x+p.x, y+p.y); }
	P operator-(P p) const { return P(x-p.x, y-p.y); }
	P operator*(T d) const { return P(x*d, y*d); }
	P operator/(T d) const { return P(x/d, y/d); }
	T dot(P p) const { return x*p.x + y*p.y; }
	T cross(P p) const { return x*p.y - y*p.x; }
	T cross(P a, P b) const { return (a-*this).cross(b-*this); }
	T dist2() const { return x*x + y*y; }
	double dist() const { return sqrt((double)dist2()); }
	// angle to x-axis in interval [-pi, pi]
	double angle() const { return atan2(y, x); }
	P unit() const { return *this/dist(); } // makes dist()=1
	P perp() const { return P(-y, x); } // rotates +90 degrees
	P normal() const { return perp().unit(); }
	// returns point rotated 'a' radians ccw around the origin
	P rotate(double a) const {
		return P(x*cos(a)-y*sin(a),x*sin(a)+y*cos(a)); }
	friend ostream& operator<<(ostream& os, P p) {
		return os << "(" << p.x << "," << p.y << ")"; }
};
typedef Point<double> P;
bool circleInter(P a,P b,double r1,double r2,pair<P, P>* out) {
	if (a == b) { assert(r1 != r2); return false; }
	P vec = b - a;
	double d2 = vec.dist2(), sum = r1+r2, dif = r1-r2,
	       p = (d2 + r1*r1 - r2*r2)/(d2*2), h2 = r1*r1 - p*p*d2;
	if (sum*sum < d2 || dif*dif > d2) return false;
	P mid = a + vec*p, per = vec.perp() * sqrt(fmax(0, h2) / d2);
	*out = {mid + per, mid - per};
	return true;
}
int n, k, c[maxn];
vector<P> pts;
vector<pair<P, ld>> circles;
int count(P p) {
	int t = 0;
	for(auto i : circles)
		if((p-i.first).dist2()-i.second*i.second<1e-6) t++;
	return t;
}
bool can(ld dist) {
	vector<P> a = pts;
	circles.clear();
	for(int i = 0; i < n; i++) {
		circles.pb({pts[i], dist/c[i]});
	}
	pair<P, P> t;
	for(int i = 0; i < n; i++)
		for(int j = i+1; j < n; j++) {
			if(circleInter(circles[i].first, circles[j].first, circles[i].second, circles[j].second, &t)) {
				a.pb(t.first);
				a.pb(t.second);
			}
		}
	for(auto i : a) if(count(i)>=k) return true;
	return false;
}
int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cin >> n >> k;
	for(int x, y, i = 0; i < n; i++) cin >> x >> y >> c[i], pts.pb(P{x, y});
	double l = 0, r = 1e6;
	while(r-l > 1e-10) {
		ld mid = (l+r)/2;
		if(can(mid)) r = mid;
		else l = mid;
	}
	cout << fixed << setprecision(15)<< l;
}



Measured memory_bytes: 512
#include<iostream>
#include <algorithm>
#include<string>
#include <bitset>
#include <vector>
#include <functional>
#include <climits>
#include <iomanip>
#include <utility>
#include <stack>
using namespace std;
using ll = long long;
int main()
{
	ll a, b = 0, c = 0, d = 0;
	char C;
	char s[1000];
	cin >> a;
	cin >> b;
	for (int i = 1; i <= a; i++)
	{
		if (b%2==0&&(i%b)==b/2)
		{
			c++;
		}
		if (i%b==0)
		{
			d++;
		}

	}
	c = c*c*c;
	d = d*d*d;
	//c = pow(c, 3);
	//d = pow(d, 3);

	cout << c+d<<endl;

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <numeric>
#include <cmath>
#include <cassert>
#include <iomanip>
#include <bitset>


using namespace std;

typedef long long int ll;
typedef pair<int,int> P;

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

const ll mod = 1e9+7;
const ll INF = 1e9;

ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

int main()
{
	int n;
	cin>>n;
	vector<int> a(n);
	rep(i,n)cin>>a[i];
	vector<int> id(n);
	iota(all(id),0);
	sort(all(id),[&](int i,int j){return a[i]<a[j];});
	rep(i,n)cout<<id[i]+1<<(i==n-1?"":" ");
	cout<<endl;
	return 0;
}

Measured memory_bytes: 1664
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define pii pair<int,int>
#define piii pair<int,pii>
#define pll pair<ll,ll>
#define plii pair<ll,pii>
#define vi vector<int>
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define SORT(x) sort(x.begin(), x.end())
#define GSORT(x) sort(x.begin(), x.end(), greater<int>())
#define mx 100001
#define eps 0.00000000001
#define mod 1000000007
#define pi acos(-1)
#define inf 100000000
#define loop(i,b,n) for(int i=b;i<n;++i)
#define rev_loop(i,b,n) for(int i=b;i>=n;--i)
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;
int main()
{
    fio;
    int n;
    cin>>n;
    string s1;
    cin>>s1;
    if(n%2!=0){
        cout<<"No\n";
        return 0;
    }
    int k = n/2;
    for(int i=0;i<n/2;i++)
    {
        if(s1[i]!=s1[k+i])
        {
        cout<<"No\n";
        return 0;
        }
    }
    cout<<"Yes\n";
    return 0;
}



Measured memory_bytes: 3640
#define LOCAL
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<(n); ++i)
#define rrep(i, n) for(int i=(n-1); i>=0; --i)
#define rep2(i, s, n) for(int i=s; i<(n); ++i)
#define ALL(v) (v).begin(), (v).end()
#define memr(dp, val) memset(dp, val, sizeof(dp))
using namespace std;
typedef long long ll;
static const int INTINF = (INT_MAX >> 1); // 10^9 + 10^7
static const ll LLINF = (LLONG_MAX >> 1);
static const int MAX = 1e5+1;
static const ll MOD = 1e9+7;
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; }
string to_string(string s) { return '"' + s + '"'; }
string to_string(bool b) { return b ? "true" : "false"; }
template <size_t N> string to_string(bitset<N> bs) {
  string res;
  for (size_t i = 0; i < N; ++i) res += '0' + bs[i];
  return res;
}
string to_string(vector<bool> v) {
  string res = "{";
  for (bool e : v) res += to_string(e) + ", ";
  return res += "}";
}
template <class T, class U> string to_string(pair<T, U> p);
template <class C> string to_string(C c) {
  string res = "{";
  for (auto e : c) res += to_string(e) + ", ";
  return res += "}";
}
template <class T, class U> string to_string(pair<T, U> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
void debug() { cerr << '\n'; }
template <class Head, class... Tail> void debug(Head head, Tail... tail) {
  cerr << '\t' << to_string(head), debug(tail...);
}
#ifdef LOCAL
#define print(...) cerr << "[" << #__VA_ARGS__ << "]:", debug(__VA_ARGS__)
#else
#define print(...)
#endif

long long combi(long long n, long long r) {
    if(r > n) return 0;
    if (r == 0) {
        return 1;
    }

    return (n - r + 1) * combi(n, r - 1) / r;
}
int main(int argc, const char * argv[]) {
	std::cout << std::fixed << std::setprecision(15);

	int N, A, B; cin >> N >> A >> B;
	vector<ll> v(N);
	map<ll, ll> mp;
	rep(i, N) {
		cin >> v[i];
		mp[v[i]]++;
	}
	sort(ALL(v), greater<ll>());
	double ma = 0;
	ll ma_idx = 0;
	double sum = 0;
	rep(i, A){
		sum += v[i];
	}
	rep(i, B+1){
		if(ma < v[i] / (A + i)){
			ma = v[i] / (A + i);
			ma_idx = A + i;
		}
		if(i == B) break;
		sum += v[i];
	}
	bool isSame = false;
	vector<ll> res;
	rep(i, ma_idx){
		res.push_back(v[i]);
	}
	if(res[0] == res[res.size()-1]) isSame = true;
	if(isSame){
		ll ans = 0;
		rep2(i, A, B+1){
			if(i <= mp[res[0]]){
				ans += combi(mp[res[0]], i);
			}
		}
		cout << res[0] << endl;
		cout << ans << endl;
	}
	else
	{
		ll tmp = 0;
		rep(i, res.size()){
			if(res[res.size()-1] == res[i]) tmp++;
		}
		double calc = accumulate(ALL(res), 0.0) / res.size();
		cout <<calc << endl;
		cout << combi(mp[res[res.size()-1]], tmp) << endl;
	}

	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
inline void rd(int &x){
  int k, m=0;
  x=0;
  for(;;){
    k = getchar_unlocked();
    if(k=='-'){
      m=1;
      break;
    }
    if('0'<=k&&k<='9'){
      x=k-'0';
      break;
    }
  }
  for(;;){
    k = getchar_unlocked();
    if(k<'0'||k>'9'){
      break;
    }
    x=x*10+k-'0';
  }
  if(m){
    x=-x;
  }
}
inline void wt_L(char a){
  putchar_unlocked(a);
}
inline void wt_L(int x){
  char f[10];
  int m=0, s=0;
  if(x<0){
    m=1;
    x=-x;
  }
  while(x){
    f[s++]=x%10;
    x/=10;
  }
  if(!s){
    f[s++]=0;
  }
  if(m){
    putchar_unlocked('-');
  }
  while(s--){
    putchar_unlocked(f[s]+'0');
  }
}
int main(){
  int A, P, i, j, k, res;
  rd(A);
  rd(P);
  P += 3*A;
  res = P / 2;
  wt_L(res);
  wt_L('\n');
  return 0;
}
// cLay varsion 20190526-1

// --- original code ---
// {
//   int i, j, k;
//   int A, P, res;
//   rd(A, P);
//   P += 3A;
//   res = P / 2;
//   wt(res);
// }


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
#define all(x) (x).begin(),(x).end()
#define pll pair<ll,ll>
#define pii pair<int,int>
#define rep(i,n) for(int i=0;i<n;i++)
#define sz(x) ((ll)(x).size())
#define pb push_back
#define mp make_pair
#define bit(n) (1LL<<(n))
#define F first
#define S second
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
const ll INF = 1LL<<60;
const ll mod = (int)1e9 + 7;

/*
テストケース全てに目を通す
テストケースが2個以下だったらなんかある
N最小のコーナーケースがないか調べる
制約をしっかりと確認する（1からNまでの順列、全て異なる値などの制約も含め）
制約のn*mとn,mを読み違えない
操作の逆順を考える
オーバーフローしないか確かめる
Codeforcesではscanfを使う
modの引き算には+modをする
エラー出力は消す
エラー出力を消せ！！！！！
cout << fixed;
cout << setprecision(n) << ans;
 */

int main() {
    int n;
    cin >> n;
    vector<pii> r;
    vector<pii> b;
    vector<int> by;
    rep(i,n){
        int x,y;
        cin >> x >> y;
        r.pb(mp(x,y));
    }
    rep(i,n){
        int x,y;
        cin >> x >> y;
        b.pb(mp(x,y));
    }
    sort(all(r));
    reverse(all(r));
    sort(all(b));
    reverse(all(b));
    int now=0;
    int cnt=0;
    rep(i,n){
        while(b[now].F>r[i].F && now<n){
            by.pb(b[now].S);
            now++;
        }
        sort(all(by));
        rep(j,sz(by)){
            if(by[j]>r[i].S){
                cnt++;
                by.erase(by.begin()+j);
              	break;
            }
        }
    }
    cout << cnt;

    


}

/*
Jesus Crisis 即決断
威風堂々と意気揚々
Life goes on　Life goes on
らしく行けよ
*/



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(void)
{
	int n,c,p;
	int i;
	int sum=0;
	int ans;
	
	cin>>n>>c;
	for(i=0;i<c;i++){
		cin>>p;
		sum+=p;
	}
	ans=sum/(n+1);
	if(sum%(n+1)!=0) ans++;
	cout<<ans<<endl;
	
	return 0;
}


Measured memory_bytes: 3132
#include<bits/stdc++.h>
using namespace std;
#define ALL(x) x.begin(),x.end()
#define rep(i,n) for(int i=0;i<n;i++)
#define debug(n,v) cout<<#v<<":";for(int i=0;i<n;i++)cout<<v[i]<<" ";cout<<endl; 
#define INF 1000000000
#define mod 1000000007
typedef long long ll;
const ll LINF = 1001002003004005006ll;
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

int main(){
    ll n;cin>>n;
    vector<ll> a(n),b(n);
    rep(i,n){
        cin>>a[i];
    }
    rep(i,n){
        cin>>b[i];
    }
    ll margin=0;
    rep(i,n){
        ll tmp=a[i]-b[i];
        if(tmp==0) continue;
        if(tmp>0){
            margin-=tmp;
        }
        else if(tmp<0){
            margin+=abs(tmp/2);
        }
    }
    cout<<(margin>=0?"Yes":"No")<<endl;
    return 0;
}


Measured memory_bytes: 512
/*author @dhanush*/

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define boost ios_base::sync_with_stdio(false);cin.tie(NULL)
#define pb push_back
#define se second
#define fi first
ll MOD = 1e9 + 7;
bool cmp(pair<ll, ll>a, pair<ll, ll>b)
{
  return a.se < b.se;
}
ll mypower(ll a, ll b)
{
  a %= MOD;

  ll res = 1;
  while (b)
  {
    if (b & 1)
    {
      b--;
      res = res * a % MOD;

    }
    else
    {
      b /= 2;
      a = a * a % MOD;
    }

  }
  return res;
}
void  icchhipadey()
{
  ll n;
  cin >> n;
  ll ans = mypower(10, n) - 2 * mypower(9, n) + mypower(8, n);
  ans%=MOD;
  if (ans < 0)
  {
    ans = (ans + MOD) % MOD;
  }
  cout << ans << endl;


}
int main()
{


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

  boost;

  icchhipadey();




}









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

int main(){
	int X_i, N_i, N_est;
	int FLAG_exst = 1;
	double N_d, X_d;
	cin >> N_i;
	
	//税抜き価格を計算
	X_i = int(N_i*100/108);
	// cout << X_i << endl;
	
	// 税込み価格を再計算し，一致するか確かめる
	N_est = int(X_i * 1.08);
	// cout << N_est << endl;
	
	//もし税込み価格の推測値<入力値の場合，税抜き価格を1円ずつ上げて確かめる
	if (N_est<N_i){
		while(1){
			X_i += 1;
			N_est = int(X_i * 1.08);
			
			if(N_est == N_i){
				break;
			// 税込み価格推測値 > 入力値の場合，入力値を満たす税抜き価格が存在しない
			} else if(N_est > N_i){
				FLAG_exst = 0;
				break;
			}
		}
	// もし税込み価格の推測値>入力値の場合，税抜き価格を1円ずつ下げて確かめる
	} else if (N_est>N_i){
		while(1){
			X_i -= 1;
			N_est = int(X_i * 1.08);
			
			if(N_est == N_i){
				break;
			// 税込み価格推測値 < 入力値の場合，入力値を満たす税抜き価格が存在しない
			} else if(N_est < N_i){
				FLAG_exst = 0;
				break;
			}
		}
	}
	
	// 税抜き価格又はフラグを出力する
	if(FLAG_exst == 1){
		cout << X_i << endl;
	} else{
		cout << ":(" << endl;
	}
	
	return 0;
}

Measured memory_bytes: 256
/*
  AUTHOR:SOURABH
  CREATED:13:09:20
*/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#define ordered_set tree<ll , null_type, less< ll >, rb_tree_tag, tree_order_statistics_node_update>
#define ll long long int
#define ld long double
#define fi first
#define se second
#define pb push_back
#define pob pop_back
#define W while
#define fn(i,x) for(i=0;i<x;i++)
#define fs(i,s,x) for(i=s;i<x;i++)
#define fr(i,x) for(i=x;i>=0;i--)
#define fit(it,s) for(it=s.begin();it!=s.end();it++)
#define mp make_pair
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vii vector<int>
#define vll vector<ll>
#define mii map<int,int>
#define mll map<ll,ll>
#define mod 1000000007
#define MAXN 10000001
#define M 32

using namespace std;
using namespace __gnu_pbds;

ll modex(ll x,ll y)
{
    x=x%mod;
    ll r=1;
    while(y>0)
    {
        if(y%2==1)
            r=(r*x)%mod;
        y/=2;
        x=(x*x)%mod;
    }
    return r;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

    //freopen("input.txt","r",stdin);
    //freopen("out.txt","w",stdout);

    ll t,n,i,x,y,ans;
    t=1;
    //cin>>t;
    W(t--)
    {
        cin>>n;
        vll a,b,c,d;
        fn(i,n)
        {
            cin>>x>>y;
            a.pb(x+y);
            b.pb(y-x);
            c.pb(x-y);
            d.pb(-(x+y));
        }
        sort(a.begin(),a.end());
        sort(b.begin(),b.end());
        sort(c.begin(),c.end());
        sort(d.begin(),d.end());
        ans=max(a[n-1]-a[0],max(b[n-1]-b[0],max(c[n-1]-c[0],d[n-1]-d[0])));
        cout<<ans;
    }
}












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

int main() {
  int A;
  cin>>A;
  int happy=0;
  
  for(int i=0;A>=500;i++){
    A-=500;
    happy+=1000;
  }
  for(int j=0;A>=5;j++){
    A-=5;
    happy+=5;
  }
  cout<<happy<<endl;
  

}


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

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

Measured memory_bytes: 3620
#include<bits/stdc++.h>
#define ll long long int
using namespace std;

int dp[100001];
int main(void) {
  int n;
  cin >> n;

  dp[1] = 1;

  for (int i = 6; i <= 100000; i*=6) {
    dp[i] = 1;
  }

  for (int i = 9; i <= 100000; i*=9) {
    dp[i] = 1;
  }

  for (int i = 2; i <= 100000; i++) {
    if(dp[i] != 0) continue;
    dp[i] = dp[i-1]+1;

    for(int ii=9; i-ii>=1; ii*=9){
      dp[i] = min(dp[i-ii]+1, dp[i]);
    }

    for(int ii=6; i-ii>=1; ii*=6){
      dp[i] = min(dp[i-ii]+1, dp[i]);
    }
  }

  cout << dp[n] << endl;
  
  return 0;
}


Measured memory_bytes: 640
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<ll, P>IP;
typedef vector<ll> V;
typedef vector<V> V2;
typedef vector<vector<P> > G;
void g_dir(G &graph, ll a, ll b, ll w = 1){graph[a].push_back(P(b, w));}
void g_undir(G &graph, ll a, ll b, ll w = 1){g_dir(graph, a, b, w);g_dir(graph, b, a, w);}
#define rep(i, n) for(ll (i) = 0; (i) < (n); (i)++)
#define rep1(i, n) for(ll (i) = 1; (i) <= (n); (i)++)
#define rrep(i, n) for(ll (i) = (n) - 1; (i) >= 0; (i)--)
#define rrep1(i, n) for(ll (i) = (n); (i) >= 1; (i)--)
template<class T> void chmax(T &a, const T &b){if(a < b){a = b;}}
template<class T> void chmin(T &a, const T &b){if(a > b){a = b;}}
const ll INF = 1145141919;
const ll MOD = 1000000007;
const ll NUM = 101010;

int main(){

    ll ans = 0;
    string s;
    cin >> s;
    rep(i, 1 << (s.size() - 1)){
        ll b = i | (1 << (s.size() - 1));
        ll tmp = 0;
        rep(j, s.size()){
            tmp = tmp * 10 + s[j] - '0';
            if(b & (1 << j)){
                ans += tmp;
                tmp = 0;
            }
        }
    }
    cout << ans << endl;
    
    return 0;
}

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

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

int N;
ll A[202020];

ll dp[202020][2][3];

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N;
	
	FOR(i,N+1) FOR(x,2) FOR(y,3) dp[i][x][y]=-1LL<<60;
	dp[0][1][0]=0;
	
	FOR(i,N) {
		cin>>x;
		FOR(j,2) FOR(k,3) {
			// not take
			if(k+j<3) dp[i+1][1][k+j]=max(dp[i+1][1][k+j],dp[i][j][k]);
			// take
			if(j==1) dp[i+1][0][k]=max(dp[i+1][0][k],dp[i][j][k]+x);
		}
	}
	
	if(N%2==0) cout<<max(dp[N][1][0],dp[N][0][1])<<endl;
	else cout<<max(dp[N][0][2],dp[N][1][1])<<endl;
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}


Measured memory_bytes: 13024
# D - Line++
def main():
    N, X, Y = map(int, input().split())
    dist_cnt = [0] * N
    for i in range(1, N + 1):
        for j in range(i + 1, N + 1):
            dist_cnt[min(j - i, abs(X - i) + abs(Y - j) + 1)] += 1
    print("\n".join(map(str, dist_cnt[1:])))


if __name__ == "__main__":
    main()


Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
#define int long long   // aaaaaaaaaaaaaaaaaa
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define allr(x) (x).rbegin(),(x).rend()
#define in(s,x) s.find(x) != s.end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
#define SIZE(buff) (sizeof(buff)/sizeof(buff[0]))
typedef vector<int> VI;
typedef vector<vector<int> > VVI;
typedef long long ll;
typedef pair<int,int> PII;
typedef vector<pair<int,int>> VPII;
const ll mod=1000000007;
const ll INF= 1LL<<60-1;
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;} ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
template<class T> void chmin(T& a,const T& b) { if(a>b) a=b; }
template<class T> void chmax(T& a,const T& b) { if(a<b) a=b; }
template <class T>ostream &operator<<(ostream &o,const vector<T>&v)
{o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}
template<typename T, typename U>ostream& operator << (ostream& os, pair<T, U>& pair_var)
{os << pair_var.first << " " << pair_var.second ;return os;}
template<class tContainer>
long long sum(tContainer const& iContainer) {return  std::accumulate(std::begin(iContainer), std::end(iContainer), 0LL);}

// head


int m,n,k,res,tmp,tmp2,tmp3,h,w,x,y;
VI a;
deque<PII> que;
string s;
//VI b;
vector<PII> g[2100600];
int b[2100000];
int c[210] = {};
int rui[210000];
set<int> ch;

signed main() {
	cin.tie(0);
  ios::sync_with_stdio(false);
  cin>>n;
  VPII ab;
  rep(i,0,n){
    cin>>x>>y;
    ab.pb({x,y});
  }
  sort(ab.begin(), ab.end(), [](PII &c, PII &d) {
        return c.se < d.se;
  });
  x = 0;
  res = 0;
  rep(i,0,n){
    res += ab[i].fi;
    if (res > ab[i].se){cout << "No" << '\n'; exit(0);}
  }
  cout << "Yes" << '\n';
}

Measured memory_bytes: 57456
import java.util.Scanner;
 
public class Main {
    public static void main(String args[]){
        Scanner stdIn = new Scanner(System.in);
 
        int n = stdIn.nextInt(); //出題問題数
        int m = stdIn.nextInt(); //高橋提出数
        int plo[] = new int[n];
        int penanum[] = new int[n];
        int ac = 0;
        
        for(int i = 0; i < n; i++){
            plo[i] = 0;
            penanum[i] = 0;
        }
        
        //int x = stdIn.nextInt();
        //int num[] = new int[];
        //String s = stdIn.next();
        //String t = stdIn.next();
        //char c[] = s.toCharArray();
        
        for(int i = 0; i < m; i++){
            int num = stdIn.nextInt();
            
            if(plo[num - 1] == 0){
                String res = stdIn.next();
                if(res.equals("AC")){
                    ac++;
                    plo[num - 1] = 1;
                }else{
                    penanum[num - 1]++;
                }
            }else{
                String gomi = stdIn.next();
            }
        }
        
        int pena = 0;
        
        for(int i = 0; i < n; i++){
            if(plo[i] == 1){
                pena += penanum[i];
            }
        }
        
        System.out.println(ac + " " + pena);
 
        //System.out.println();
        //System.out.print();
 
        stdIn.close();
    }
}

Measured memory_bytes: 63672
#include"bits/stdc++.h"
#include<iostream>
using namespace std;
typedef long long ll;
typedef vector<int> vi;

int main(void) {
	int n;
	ll ans=0;

	cin >> n;

	vector<ll> a(n+5);

	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}

	sort(a.begin(),a.end());
	reverse(a.begin(), a.end());

	for (int i = 1; i < n; i++) {
		ans += a[i/2];
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 4780
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<int(n);i++)
#define FOR(i,n,m) for(int i=n;i<int(m);i++)
#define ALL(v) (v).begin(),(v).end()
#define pb push_back
using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;

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

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

const ll mod=1e9+7;
const int INF=INT_MAX/2;
const int N_MAX=100010;

int main(){
	int n;
	vector<ll> a,b,c;
	vector<ll> plus,minus;
	ll suma=0,sumb=0;
	int ans=0;
	cin>>n;
	a=vector<ll>(n);
	b=vector<ll>(n);
	REP(i,n){
		cin>>a[i];
		suma+=a[i];
	}
	REP(i,n){
		cin>>b[i];
		sumb+=b[i];
	}
	if(suma<sumb){
		cout<<-1<<endl;
		return 0;
	}else{
		REP(i,n){
			if(a[i]<b[i]){
				minus.pb(b[i]-a[i]);
			}else if(a[i]>b[i]){
				plus.pb(a[i]-b[i]);
			}
		}
		sort(plus.begin(),plus.end(),greater<int>());
		ll suml=0;
		REP(i,minus.size()){
			suml+=minus[i];
		}
		ans+=minus.size();
		REP(i,plus.size()){
			if(suml>plus[i]){
				suml-=plus[i];
				ans++;
			}else if(suml==0){
				break;
			}else{
				ans++;
				break;
			}
		}
		cout<<ans<<endl;
	}

	return 0;
}



Measured memory_bytes: 2812
#include <stdio.h>
#define maxn 5010
#define LL long long
int d[maxn],a[maxn],zero[maxn];
LL sum[maxn];
int main(){
	int k,q,n,x,m,i,ans,t,z;
	scanf("%d%d",&k,&q);
	for(i=0;i<k;i++)scanf("%d",&d[i]);
	while(q--){
		scanf("%d%d%d",&n,&x,&m);
		x%=m,sum[0]=0,zero[0]=0;
		for(i=0;i<k;i++){
			a[i]=d[i]%m;
			sum[i+1]=sum[i]+a[i];
			zero[i+1]=zero[i]+(a[i]==0);
		}
		z=(n-1)/k*zero[k]+zero[(n-1)%k];
		t=((n-1)/k*sum[k]+sum[(n-1)%k]+x)/m-x/m;
		ans=(n-1)-z-t;
		printf("%d\n",ans);
	}
	return 0;
}

Measured memory_bytes: 256
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")


n = int(input())
from collections import Counter
a = list(map(int, input().split()))
c = Counter(a)
s = set()
for k,v in c.items():
    if v>=2:
        s.add(k)
        
a.sort()
ok = set()
p = set(list(range(1, 10**6+1)))
ck = list(c.keys())
ck.sort()
for num in ck:
    if num in p:
        ok.add(num)
    i = 2
    while num*i<=10**6:
        if num*i in p:
            p.remove(num*i)
        i += 1
tmp = ok
tmp = set(tmp) - s
print(len(tmp))

Measured memory_bytes: 183600
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<int, P> P1;
typedef pair<P, P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define fi first
#define sc second
#define rep(i, x) for (long long i = 0; i < x; i++)
#define repn(i, x) for (long long i = 1; i <= x; i++)
#define SORT(x) sort(x.begin(), x.end())
#define ERASE(x) x.erase(unique(x.begin(), x.end()), x.end())
#define POSL(x, v) (lower_bound(x.begin(), x.end(), v) - x.begin())
#define POSU(x, v) (upper_bound(x.begin(), x.end(), v) - x.begin())
vector<pair<string, P> > vec;
// vector<vector<int>> data(3, vector<int>(4));

void solve(std::string S) {
    if (S == "ABC")
        cout << "ARC" << endl;
    else
        cout << "ABC" << endl;
}

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


Measured memory_bytes: 3596
h, w = map(int, input().split())
n = h*w
INF = 1<<30
field = []
for i in range(h):
    field.append(input())

dist = [[INF] * n for _ in range(n)]

for i in range(h):
    for j in range(w):
        if field[i][j] == "#":continue
        if j + 1 < w and field[i][j+1] != "#":
            dist[i * w + j][i * w + j + 1] = 1
            dist[i * w + j + 1][i * w + j] = 1
        if i + 1 < h and field[i+1][j] != "#":
            dist[i * w + j][(i+1) * w + j] = 1
            dist[(i+1) * w + j][i * w + j] = 1

for i in range(n):
    for j in range(n):
        for k in range(n):
            dist[j][k] = min(dist[j][k], dist[j][i] + dist[i][k])

ans = 0
            
for i in range(n):
    for j in range(n):
        if(i == j):continue
        if(dist[i][j] == INF):continue
        ans = max(ans, dist[i][j])
        

print(ans)

Measured memory_bytes: 43916
#include <iostream>
#include <cstdio>
#include <fstream>
#include <algorithm>
#include <iterator>
#include <math.h>
#include <cmath>
#include <stdlib.h>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <regex>
#include <stdexcept>
#include <unordered_set>
#include <string>
#include <map>
#include <iomanip>
#include <sstream>
#include <cassert>
#include <time.h>
#include <numeric>
#include <complex>

using namespace std;
using ull = unsigned long long;
using ll = long long;
using ld = long double;
using D = double;
using ii = pair<int, int>;
using vi = vector<int>;
using vii = vector<ii>;

#define pb push_back
#define mp make_pair
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(), x.rend()
#define fill(x, y) memset(x, y, sizeof(x))
#define makeunique(x) sort(all(x)), (x).resize(unique(all(x)) - (x).begin())
#define rep(i, x)  for(int i = 0; i < (x); i++)
#define rrep(i, x) for(int i = (x - 1); i >= 0; i--)
#define y1 y1_1234413
#define j1 j1_235
#define y0 y0_235
#define j0 j0_256
#define fi first
#define se second
#define itn int
#define re return
#define prev PREV
#define next NEXT

#define sz(x) ((int)x.size())

const int inf = 2e9;
const ld st = 0.000001;
const ld pi = acos((ld)-1);

#define FILENAME ""

const ll maxn = 500000 + 10;
 
 

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n;
    cin >> n;
    vector <ll> a, b;
    for (int i = 0; i < n; i++) {
        ll x;
        cin >> x;
        a.pb(x);
    }
    for (int i = 0; i < n; i++) {
        ll x;
        cin >> x;
        b.pb(x);
    }
    ll ans = 0;
    for (int i = 0; i < n; i++) {
        ans += max((ll)0, a[i] - b[i]);
    }
    cout << ans;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
 long long int n,k,a,b,mx=0,sum=0,f=0;
    cin>>n;
    for(int i=0;i<n;i++)
    {
        cin>>a>>b;
      sum+=abs(b-a);
      sum+=1;
    }
    cout<<sum<<endl;

}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(void) {
  int K, S;
  cin >> K >> S;

  int ans = 0;

  for(int x = 0; x <= K; ++x){
    for(int y = 0; y <= K; ++y){
      int z = S - x - y;
      if (z >= 0 and z <= K){
        ans += 1;
      }
    }
  }

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

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <cstring>
#include <iomanip>
#include <numeric>
#include <cmath>
#include <cassert>
#include <queue>
#include <map>
#include <set>
using namespace std;
using Int = int64_t;
const Int INF = 1<<30;
const Int MOD = (Int)1e9 + 7;
const Int MAX_N = (Int)1e5 + 5;
#define debug(x) cout << #x << ": " << x << endl
template<typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2>& p) { os << p.first << " " << p.second; return os; }
template<typename T>
ostream &operator<<(ostream &os, const vector<T> &v) { for(int i = 0; i < (int) v.size(); i++) os << v[i] << (i + 1 != v.size() ? " " : ""); return os; }

void solve()
{
    int x, y; cin >> x >> y;
    for(int i = 0; i <= 100; i++)
    {
        for(int j = 0; j <= 100; j++)
        {
            int cnt = 2 * i + 4 * j;
            if(cnt == y && i + j == x)
            {
                cout << "Yes" << endl;
                return;
            }
        }
    }
    cout << "No" << endl;
}

signed main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    solve();
    return 0;
}

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

int keta(int num) {
	int d = 1;
	while(num){
		d *= 10;
		num /= 10;
	}
	return d;
}	

int main() {
	int a, b;
	cin >> a >> b;
	double N = a * keta(b) + b;
	int sn = (int)sqrt((double)N);
	if(sn*sn == N){
		cout << "Yes" << endl;
		return 0;
	}
	cout << "No" << endl;
}

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

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

const long long INF = 1LL << 60;

int main(){
  int a, b, c;
  cin >> a >> b >> c;

  cout << (b-a == c-b ? "YES" : "NO") << endl;

  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;
//import java.io.*;
//import java.util.Arrays;
public class Main {
	public static void main(String[] args) throws java.io.IOException {
		Scanner scan = new Scanner(System.in);
		//InputStreamReader is = new InputStreamReader(System.in);
		//BufferedReader br = new BufferedReader(is);
		int count = 0;
		while(scan.hasNext()){
			String text = scan.next();
			int out = 0;
			char character[] = text.toCharArray();
			if(character.length == 1){
				++count;
			}else{
				for(int i = 0 ; i < (character.length)/2 ; i++){
					for(int j = character.length-1-i ; j > character.length-2-i ; j--){
						if(character[i] == character[j]){
							if(i == (character.length)/2-1){
								++count;
							}
						}else{
							out = 1;
							break;
						}
					}
					if(out == 1){
						break;
					}
				}
			}
		}
		System.out.println(count);
	}
}

Measured memory_bytes: 25884
#include <iostream>
#include <set>
using namespace std;
using int64 = long long;

int solve(int64 a) {
  set<int64> st;
  for (int i = 1; ; ++i) {
    if (!st.insert(a).second)
      return i;
    if (a % 2)
      a = a * 3 + 1;
    else
      a /= 2;
  }
}

int main() {
  int64 s;
  cin >> s;
  cout << solve(s) << "\n";
  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
struct node{
  struct node *prev;
  struct node *next;
  long key;
};
typedef struct node * NP;
NP MN(long);
void IN(NP);
void DN(NP);
void FI(long);
NP dummy;

int main(){
  long int val,i,n;
  char op[12];
  NP roop;

  scanf("%ld",&n);
  dummy = MN(0);

  

  for(i=0;i<n;i++){
    scanf("%s",op);
    
    if(strcmp(op,"insert") == 0){
      scanf("%ld",&val);
      IN(MN(val));
    }
    else if(strcmp(op,"delete") == 0){
      scanf("%ld",&val);
      FI(val);
    }
    else if(strcmp(op,"deleteFirst") == 0){
      DN(dummy->next);
    }
    else if(strcmp(op,"deleteLast") == 0){
      DN(dummy->prev);
    }
  }

  for(roop=dummy->next;roop!=dummy;roop =roop->next){
    printf("%ld",roop->key);
    if(roop->next != dummy)printf(" ");
  }  
  printf("\n");

  return 0;
}


void FI(long value){
  NP n;
  dummy->key = value;
  for(n = dummy->next;;n=n->next){
    if(n->key == value)break;
  }
  if(n != dummy)DN(n);
    
}


void DN(NP th){
  th->prev->next = th->next;
  th->next->prev = th->prev;
  th->prev = th->next = th;
  free(th);
  //delete th;
}


void IN(NP newn){
  newn->next = dummy->next;
  newn->next->prev = newn;
  dummy->next = newn;
  newn->prev = dummy;
}

NP MN(long key){
  NP no = (NP)malloc(sizeof(struct node));
  //n = new struct node();
  no->prev = no;
  no->next = no;
  no->key = key;
  return no;
} 

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

using namespace std;

#define INF 1000000007
#define LINF (1LL << 62)
#define PI 3.14159265358979

typedef long long i64;
typedef pair<i64,i64> P;

inline i64 mod(i64 a, i64 m) { return (a % m + m) % m; }

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



int n, a[101010], b[101010];
P p[101010], pp[101010];
pair<int,P> d[202020];
struct UnionFind {
	vector<int> par, depth, sz;
	UnionFind(int n) : par(n+1), depth(n+1), sz(n+1){
		for(int i = 0; i <= n; i++){
			par[i] = i;
			depth[i] = 0;
			sz[i] = 1;
		}
	}
	int find(int x){
		if(par[x] == x) return x;
		else return par[x] = find(par[x]);
	}
	void unite(int x, int y){
		x = find(x);
		y = find(y);
		if(x == y) return;
		sz[x] += sz[y];
		sz[y] = sz[x];
		if(depth[x] < depth[y]){
			par[x] = y;
		}
		else{
			par[y] = x;
			if(depth[x] == depth[y]) depth[x]++;
		}
	}
	bool same(int x, int y){
		return find(x) == find(y);
	}
	int size(int x){
		return sz[find(x)];
	}
};
void solve(){
	cin >> n;
	for(int i = 0; i < n; i++){
		cin >> a[i] >> b[i];
		p[i] = {a[i], i};
		pp[i] = {b[i], i};
	}
	sort(p,p+n); sort(pp,pp+n);
	
	for(int i = 0; i < n-1; i++){
		int l = p[i].second, r = p[i+1].second;
		d[i*2] = {a[r]-a[l],{l,r}};
		l = pp[i].second; r = pp[i+1].second;
		d[i*2+1] = {b[r]-b[l],{l,r}};
	}
	sort(d,d+n*2-2);
	
	UnionFind uf(n);
	i64 ans = 0;
	for(int i = 0; i < n*2-2; i++){
		int l = d[i].second.first, r = d[i].second.second;
		if(uf.same(l,r)) continue;
		uf.unite(l,r);
		ans += d[i].first;
	}
	cout << ans << endl;
}

int main(){
	std::cin.tie(0);
	std::ios::sync_with_stdio(false);
	int t = 1;
	//cin >> t;
	while(t--){
		solve();
	}
	
	return 0;
}

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

#ifdef _DEBUG
#define debug(x) cerr << "line: " << __LINE__ << ", func: " << __func__ << " ->  " << #x << " = " << x << endl
#else
#define debug(x)
#endif

#define all(s) begin(s), end(s)
#define rall(s) rbegin(s), rend(s)
#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define rrep(i, a, b) for (int i = ((a)-1); i >= (b); i--)
#define pb push_back
#define sz(a) int((a).size())

using namespace std;

using ll = long long;
using ull = unsigned long long;
using i_i = pair<int, int>;
using ll_ll = pair<ll, ll>;
using d_ll = pair<double, ll>;
using ll_d = pair<ll, double>;
using d_d = pair<double, double>;

static constexpr ll LL_INF = 1LL << 60;
static constexpr int I_INF = 1 << 28;
static constexpr double PI = static_cast<double>(3.14159265358979323846264338327950288);
static constexpr double EPS = numeric_limits<double>::epsilon();
static constexpr const char* YES = "Yes";
static constexpr const char* NO = "No";

static map<type_index, const char* const> scanType = {
    {typeid(int), "%d"}, {typeid(ll), "%lld"}, {typeid(double), "%lf"}, {typeid(char), "%c"}};

template <class T> static void scan(vector<T>& v);
[[maybe_unused]] static void scan(vector<string>& v, bool isWord = true);
template <class T> static inline bool chmax(T& a, T b);
template <class T> static inline bool chmin(T& a, T b);
template <class A, size_t N, class T> static void Fill(A (&arr)[N], const T& val);

int main(int argc, char* argv[]) {
  std::string S;
  std::cin >> S;

  map<char, int> m;
  for (char c : S) {
    m[c]++;
  }

  if (sz(m) != 2) {
    cout << NO << endl;
    return 0;
  }

  for (auto p : m) {
    if (p.second != 2) {
      cout << NO << endl;
      return 0;
    }
  }

  cout << YES << endl;
  return 0;
}

template <class T> static void scan(vector<T>& v) {
  auto tFormat = scanType[typeid(T)];
  for (T& n : v) {
    scanf(tFormat, &n);
  }
}

static void scan(vector<string>& v, bool isWord) {
  if (isWord) {
    for (auto& n : v) {
      cin >> n;
    }
    return;
  }

  int i = 0, size = v.size();
  string s;
  getline(cin, s);

  if (s.size() != 0) {
    i++;
    v[0] = s;
  }

  for (; i < size; ++i) {
    getline(cin, v[i]);
  }
}

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

template <class A, size_t N, class T> void Fill(A (&arr)[N], const T& val) {
  std::fill((T*)arr, (T*)(arr + N), val);
}


Measured memory_bytes: 256
from collections import deque
import sys
# from time import time

# start = time()

H, W = map(int, sys.stdin.readline().split())
field = [list(sys.stdin.readline().rstrip()) for i in range(H)]

# print(time() - start)

queue = deque([])

for h in range(H):
    for w in range(W):
        if field[h][w] == "#":
            queue.append([h, w])

dist_from_nearest_black = [[0] * W for i in range(H)]
direction = [[1, 0], [-1, 0], [0, 1], [0, -1]]


def bfs():
    while len(queue) != 0:

        h, w = queue.popleft()

        for dh, dw in direction:
            next_h = h + dh
            next_w = w + dw

            if next_h < 0 or next_h >= H or next_w < 0 or next_w >= W:
                continue
            elif field[next_h][next_w] == "#":
                continue
            else:
                dist_from_nearest_black[next_h][next_w] = dist_from_nearest_black[h][w] + 1
                field[next_h][next_w] = "#"
                queue.append([next_h, next_w])


bfs()

ans = 0

for d in dist_from_nearest_black:
    ans = max(ans, max(d))

print(ans)
# print(time() - start)


Measured memory_bytes: 174812
open Hashtbl
let h, m = create 100100, ref 1
let _ = for _ = 1 to read_int () do let s = read_line () in replace h s @@ try let c = find h s + 1 in m := max !m c; c with _ -> 1 done; List.(fold (fun s c a -> if c = !m then s :: a else a) h [] |> sort compare |> iter print_endline)

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

int main() {
  int N, M;
  cin >> N >> M;
  vector<int> a(M), b(M);
  for (int i = 0; i < M; ++i)
    cin >> a[i] >> b[i];
  vector<pair<int, int>> c(M);
  for (int i = 0; i < M; ++i)
    c[i] = make_pair(b[i], a[i]);
  sort(c.begin(), c.end());
  int ans = 0, t = 0;
  for (int i = 0; i < M; ++i)
    if (t <= c[i].second)
      ++ans, t = c[i].first;
  cout << ans << endl;
}


Measured memory_bytes: 1792
import java.util.Scanner;

public class Main
{
    public static void main(String[] args)
    {
	Scanner In = new Scanner(System.in);
	int N;
	do
	    {
		 N = In.nextInt();
	    }while(1 >= N && N >= 100);
	int i,j;
	int []A = new int[N];
		for(i = 0; i < N; i++)
		    {
			do
			    {
				A[i] = In.nextInt();
			    }while(0 >= A[i] && A[i] >= 1000);
		    }
 
	for(i = 1; i <= N - 1; i++)
	    {
		int v = A[i];
		j = i - 1;
		for(int m = 0; m < N - 1; m++)
		    System.out.print(A[m] + " ");
		System.out.print(A[N - 1]);
		System.out.println();

		while(j >= 0 && A[j] > v)
		    {
			A[j + 1] = A[j];
			j--;
			
		    }
		A[j + 1] = v;
		
	    }
	for(int l = 0; l < N - 1; l++)
		    System.out.print(A[l] + " ");
		
		System.out.print(A[N - 1]);
		System.out.println();
    }
}

Measured memory_bytes: 31652
#include <iostream>
#include <vector>
#include <array>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <algorithm>
#include <iomanip>
#include <cmath>
#include <limits>

using namespace std;

int main (int argc, char* argv[]) {
	int n, q;
	cin >> n >> q;
	string s;
	cin >> s;

	vector<int> c(s.size());
	int current_c = 0;
	for (int i = 1; i < s.size(); i++) {
		if (s[i - 1] == 'A' && s[i] == 'C') {
			current_c++;
		}
		c[i] = current_c;
	}

	for (int i = 0; i < q; i++) {
		int low, high;
		cin >> low >> high;
		low--; high--;
		cout << c[high] - c[low] << endl;
	}
}


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

using namespace std;

typedef long long ll;

int main() {
	int N, K;
	cin >> N >> K;
	int cnt[100 + 10] = {};
	for (int i = 0; i < K; i++) {
		int d;
		cin >> d;
		for (int j = 0; j < d; j++) {
			int a;
			cin >> a;
			cnt[a - 1]++;
		}
	}
	int ans = 0;
	for (int i = 0; i < N; i++)if (cnt[i] == 0)ans++;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3636
#include <iostream>

#include <algorithm>
#include <cmath>
#include<string>
#include<array>
#include<vector>
#include<functional>
#include<unordered_map>
#include<map>
#include<numeric>
#include<limits>
#include<utility>
#include<queue>
#include<random>

using namespace std;
typedef long long LL;

int main() {
	int a;
	
	int A, B;

	LL N,ans=0;

	cin >> N;//N組の団体
	
	//i_n席からl_n席まで=(l-i+1)

	for (int i = 0; i < N; ++i) {
	
		cin >> A >> B;

		ans += (B - A) + 1;
	
	}

	cout << ans << endl;

	//cin >> a;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; i++)
#define reps(i, s, n) for(ll i = (s), i##_len = (n); i < i##_len; i++)
#define rrep(i, n) for(ll i = (n) - 1; i >= 0; i--)
#define rreps(i, e, n) for(ll i = (n) - 1; i >= (e); i--)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) ((ll)(x).size())
#define len(x) ((ll)(x).length())
#define endl "\n"

struct UnionFind {
    UnionFind() {}
    UnionFind(int n) {
        resize(n);
    }
    
    void resize(int n) {
        par.resize(n, -1);
    }
    
    int root(int x) {
        if (par[x] < 0) return x;
        return par[x] = root(par[x]);
    }
    
    bool merge(int x, int y) {
        int rx = root(x);
        int ry = root(y);
        if (rx == ry) return false;
        if (par[rx] > par[ry]) swap(rx, ry);
        par[rx] += par[ry];
        par[ry] = rx;
        return true;
    }
    
    bool is_same(int x, int y) {
        return (root(x) == root(y));
    }
    
    int size(int x) {
        return -par[root(x)];
    }
    
private:
    vector<int> par;
};

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    // ifstream in("input.txt");
    // cin.rdbuf(in.rdbuf());
    ll n, m;
    cin >> n >> m;
    vector<vector<ll>> g(n);
    rep(i, m) {
        ll a, b;
        cin >> a >> b;
        a--; b--;
        g[a].push_back(b);
        g[b].push_back(a);
    }
    deque<ll> dq;
    dq.push_back(0);
    dq.push_back(g[0][0]);
    UnionFind uf(n);
    uf.merge(0, g[0][0]);
    while(true) {
        bool updated = false;
        ll st = dq[0], en = dq[sz(dq) - 1];
        for(auto &x : g[st]) {
            if (uf.root(st) == uf.root(x)) continue;
            uf.merge(st, x);
            dq.push_front(x);
            updated = true;
            break;
        }
        for(auto &x : g[en]) {
            if (uf.root(en) == uf.root(x)) continue;
            uf.merge(en, x);
            dq.push_back(x);
            updated = true;
            break;
        }
        if (!updated) break;
    }
    printf("%lld\n", sz(dq));
    rep(i, sz(dq)) printf("%lld%s", dq[i] + 1, (i == (sz(dq) - 1)) ? "\n" : " ");
    return 0;
}


Measured memory_bytes: 9640
#include <bits/stdc++.h>
using namespace std;
using P = pair<int,int>;
int main(){
  int N, K;
  cin >> N >> K;
  if(K > (N-1)*(N-2)/2){
    cout << -1 << endl;
  }
  else{
    vector<P> vec(0);
    for(int i=1; i<N; i++){
      P p = {1,i+1};
      vec.push_back(p);
    }
    int cnt = (N-1)*(N-2)/2;
    bool end = false;
    for(int i=1; i<N; i++){
      for(int j=i+1; j<N; j++){
        if(cnt == K){
          end = true;
          break;
        }
        P p = {i+1,j+1};
        vec.push_back(p);
        cnt--;
      }
      if(end){
        break;
      }
    }
    cout << vec.size() << endl;
    for(int i=0; i<vec.size(); i++){
      cout << vec[i].first << " " << vec[i].second << endl;
    }
  }
}
          

Measured memory_bytes: 384