akhauriyash/Code-Regression huggingface dataset:
/// Be Kind :)
#include <bits/stdc++.h>
using namespace std;
 
#pragma GCC optimize("O2,no-stack-protector,unroll-loops,fast-math")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//#pragma GCC optimize("Os")

/*				I take you to the candy shop								*/

/*				Oh, it's me, myself and I
				Solo ride until I die										*/

/*				So I ball So hard, muh'fuckas wanna find me					*/
 
/*				Bitch, where you when I was walkin'?
				Now I run the game, got the whole world talkin'				*/
 
/*				Niggas been counting me out
				I'm counting my bullets, I'm loading my clips
				I'm writing down names, I'm making a list					*/
 
/*				You never liked us anyway, fuck your friendship, I meant it */
 
/*				The Chanel or Balenciaga, Louis and Vuitton
				She know I got Fendi, Prada when I hit Milan				*/
 
/*				I ran away, I don't think I'm coming back home				*/
 
#define F first
#define S second
#define pb push_back
#define SZ(x) (ll)(x.size())
#define all(x) x.begin(),x.end()
 
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> pll;
 
//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
 
const ll maxn=5e5+10, maxm=1e5+10, lg=17, mod=1e9+7, inf=1e18;

#define bone(x) (__builtin_popcount(x))

void gans(ll n,ll a,ll b){
	if(a==b){ cout<<a<<' '; return; }
	ll x=(a^b)&(-(a^b));
	n^=x;
	ll y=n&(-n);
	gans(n,a,a^y), gans(n,a^y^x,b);
}

int main(){
	ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
	
	ll n,a,b;
	cin>>n>>a>>b;
	if(bone(a)%2==bone(b)%2) return cout<<"NO\n",0;
	cout<<"YES\n";
	gans((1<<n)-1,a,b);
	
	return 0;
}






Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define ll long long
//#define fr(i,j,k) for(int i=j;i<k;i++)
//#define f(n) fr(i,0,n)
//#define f1(n) fr(i,1,n+1)
#define pb push_back
#define F first
#define S second
#define all(x) x.begin(), x.end()
const ll mod = 1e9 + 7;
const int maxn = 2e5+5;
#include<atcoder/all>
using namespace atcoder;
int pull(int a,int b) {
    return max(a, b);
}
int e() {
    return -1;
}
int tar;
bool f(int x) {
    return x < tar;
}
void solve() {
    int n, q;
    cin >> n >> q;
    vector<int>v(n);
    for (auto &i : v) {
        cin >> i;
    }
    segtree<int,pull,e>seg(v);
    for (int i = 0 ; i < q ; i++) {
        int op;
        cin >> op;
        if (op == 1) {
            int x, v;
            cin >> x >> v;
            seg.set(x-1,v);
        }
        else if (op == 2) {
            int l, r;
            cin >> l >> r;
            cout << seg.prod(l-1, r) << '\n';
        }
        else {
            int x, v;
            cin >> x >> v;
            tar = v;
            cout << seg.max_right<f>(x-1) + 1 << '\n';
        }
    }
}
int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int c = 0;
    int t;
    if (!c) {
        t = 1;
    }
    else {
        cin >> t;
    }
    while (t--) {
        solve();
    }
    
}


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

void main() {
    auto s = readln.split.map!(to!int);
    auto K = s[0];
    auto Q = s[1];
    auto D = readln.split.map!(to!long).array;
    auto E = new long[](K);

    while (Q--) {
        s = readln.split.map!(to!int);
        auto N = s[0];
        auto X = s[1].to!long;
        auto M = s[2].to!long;
        X %= M;
        foreach (i; 0..K) E[i] = D[i] % M;
        auto sm = E.sum;
        auto hoge = (1L * (N - 1) / K) * (K - E.count(0)) - (X + sm * ((N - 1) / K)) / M;
        auto fuga = (X + sm * ((N - 1) / K)) % M;
        auto piyo = (N - 1) % K;
        foreach (i; 0..piyo) {
            auto fuga2 = (fuga + E[i]) % M;
            if (fuga2 > fuga) hoge += 1;
            fuga = fuga2;
        }
        hoge.writeln;
    }

}

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

int main() {
    int n,m;cin>>n>>m;
    priority_queue<int> q;
    for (int i=0;i<n;i++) {
        int a;cin>>a;
        q.push(a);
    }
    while (m--) {
        int a=q.top();q.pop();
        q.push(a/2);
    }
    ll ans=0;
    while (q.size()) {
        ans+=q.top();q.pop();
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 892
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repr(i, n) for (int i = (n) - 1; i >= 0; i--)
#define range(a) a.begin(), a.end()

struct unionfind {
  vector<int> dat;

  unionfind(int n) : dat(n, -1) {}

  int find(int x) {
    if (dat[x] < 0) return x;
    return dat[x] = find(dat[x]);
  }

  void unite(int x, int y) {
    x = find(x);
    y = find(y);
    if (x == y) return;
    if (dat[x] > dat[y]) swap(x, y);
    dat[x] += dat[y];
    dat[y] = x;
  }

  int size(int x) {
    return -dat[find(x)];
  }
};

int main() {
  int N, M, K; cin >> N >> M >> K;
  unionfind uf(N);
  vector<int> tomodati(N);
  while (M--) {
    int u, v; cin >> u >> v; u--; v--;
    uf.unite(u, v);
    tomodati[u]++;
    tomodati[v]++;
  }
  vector<vector<int>> G(N);
  while (K--) {
    int u, v; cin >> u >> v; u--; v--;
    G[u].push_back(v);
    G[v].push_back(u);
  }
  rep(i, N) {
    int ans = uf.size(i) - 1 - tomodati[i];
    for (int v : G[i]) {
      if (uf.find(v) == uf.find(i)) {
        ans--;
      }
    }
    cout << ans << " \n"[i == N - 1];
  }
}

Measured memory_bytes: 6784
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdint>
#include <cstdio>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <tuple>
#include <utility>
#include <vector>
using namespace std;

using int64 = int64_t;

constexpr int64 MOD = 1000000007;

int N, K, T, U, V, L, D[200];

int main() {
    cin >> N >> K >> T >> U >> V >> L;
    for (int j = 0; j < N; ++j) cin >> D[j];

    int boosts = 0;
    int r = L;
    for (int j = N-1; j >= 0; --j) {
        int nr = max(D[j], r-V*T);
        if (j+K < N && D[j+K] < nr) {
            boosts -= nr - D[j+K];
            nr = D[j+K];
        }
        r = nr;
    }
    boosts += L - r;

    printf("%.12f\n", (double)boosts / V + (double)(L - boosts) / U);
    return 0;
}

Measured memory_bytes: 3208
#include<iostream>
#include<map>
using namespace std;
int main() {
    int n; cin >> n;
    map<int, int, greater<int>> mp;
    for (int i = 0; i < n; ++i) {
        int a; cin >> a;
        mp[a]++;
    }
    int ans = 0;
    for (auto x : mp) {
        if (x.second >= 4) {
            if (ans == 0) {
                cout << (long long)x.first * x.first << endl;
            } else {
                cout << (long long)ans * x.first << endl;
            }
            return 0;
        }
        if (x.second >= 2) {
            if (ans == 0) {
                ans = x.first;
            } else {
                cout << (long long)ans * x.first << endl;
                return 0;
            }
        }
    }
    cout << 0 << endl;
    return 0;
}


Measured memory_bytes: 4992
#include<stdio.h>
int main(void)
{
	int W,H,x,y,r;
	scanf("%d %d %d %d %d",&W,&H,&x,&y,&r);
	if(W>=(x+r)&&H>=(y+r)&&(x-r)>=0&&(y-r)>=0){
		printf("Yes\n");
	}else{
		printf("No\n");
	}
	return 0;
}

Measured memory_bytes: 584
#include <iostream>
#include<string>
#include<cmath>
#include<algorithm>
#include<cctype>
#include<queue>
#include<deque>
#include<regex>
#include<stack>
#include<stdio.h>
#include<vector>
#include<set>
#include<map>
#include<iomanip>

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

typedef int long long ll;
using namespace std;
typedef pair<int, int> P;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
const ll MOD = 1e9 + 7;
static const int MAX = 100;
static const int INF = (1 << 23);

int main() {
    int n,m;
    cin>>n>>m;
    vector<pair<int,int>> v;


    rep(i,n){
        int a,b;
        cin>>a>>b;
        v.push_back({a,b});
    }
    sort(v.begin(),v.end());
    int hi=0;

    ll ans=0;
    int p=0;

    priority_queue<int> q;

    for(int i=1;i<=m;i++){
        while(true){
            if(v[p].first>i||p>=n)break;
            q.push(v[p].second);

            p++;
        }
        if(!q.empty()) {

            ans += q.top();
            q.pop();

        }

    }



    cout<<ans<<endl;


    return 0;
}


Measured memory_bytes: 1908
// Boudy is 32
// Tsunami is :gift_heart:
// Yassora is :sparkling_heart:
// Zetamoo is :heartbeat:
// Nour is Mo7nk
// Pillow is habd
// Lulu ...... meen Lulu?!!!
#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
using namespace std;

#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/rope>
using namespace __gnu_pbds;
using namespace __gnu_cxx;

template<class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;
/***********************************************/
/* Dear online judge:
 * I've read the problem, and tried to solve it.
 * Even if you don't accept my solution, you should respect my effort.
 * I hope my code compiles and gets accepted.
 *  ___  __     _______    _______      
 * |\  \|\  \  |\  ___ \  |\  ___ \     
 * \ \  \/  /|_\ \   __/| \ \   __/|    
 *  \ \   ___  \\ \  \_|/__\ \  \_|/__  
 *   \ \  \\ \  \\ \  \_|\ \\ \  \_|\ \ 
 *    \ \__\\ \__\\ \_______\\ \_______\
 *     \|__| \|__| \|_______| \|_______|
 */
const long long mod = 1000000007;
//const long long mod = 998244353;
mt19937 rng((int) chrono::steady_clock::now().time_since_epoch().count());

// watch this
using ll = long long;
//typedef long long LL;
#define ll long long
#undef ll

int main(int argc, char** argv) {
#ifdef ONLINE_JUDGE	
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
//	freopen("highways.in", "r", stdin);
//	freopen("highways.out", "w", stdout);
#endif

	long long H, W, h, w;
	cin >> H >> W >> h >> w;
	long long res = H * W - h * W - w * (H - h);
	cout << res << '\n';
	return 0;
}


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

using namespace std;
using ll = long long;

int main() {
    string O, E;
    cin >> O >> E;
    for(int i = 0; i < O.size(); i++) {
        if(O.size() - E.size() && O.size() - 1 == i) {
            cout << O.at(i);
            break;
        }
        cout << O.at(i) << E.at(i);
    }
    cout << endl;


    return 0;
}

Measured memory_bytes: 3576
h,w = map(int,input().split())

hwList = []
hhList = []
whList = []
wwList = []
for i in range(1,h+1):
  sa = i*w
  sb = (h-i)*(w//2)
  sc = (h-i)*(w-(w//2))
  hwList.append(max([sa,sb,sc])-min([sa,sb,sc]))
  sb = (h-i)//2*(w)
  sc = ((h-i)-((h-i)//2))*(w)
  hhList.append(max([sa,sb,sc])-min([sa,sb,sc]))
for i in range(1,w+1):
  sa = i*h
  sb = (w-i)*(h//2)
  sc = (w-i)*(h-(h//2))
  whList.append(max([sa,sb,sc])-min([sa,sb,sc]))
  sb = (w-i)//2*(h)
  sc = ((w-i)-((w-i)//2))*(h)
  wwList.append(max([sa,sb,sc])-min([sa,sb,sc]))

print(min([min(hwList),min(hhList),min(whList),min(wwList)]))


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

#define ll long long
#define ull unsigned long long

using namespace std;

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

	int N = s.size();

	bool ans = true;

	string str = s;
	reverse(str.begin(), str.end());
	for (int ii = 0; ii < N; ++ii){
		if (str[ii] != s[ii]){
			ans = false;
			break;
		}
	}
	// cout << ans << "\n";

	string hoge;
	for (int ii = 0; ii < N/2; ++ii){
		hoge.push_back(s[ii]);
	}
	reverse(hoge.begin(), hoge.end());
	for (int ii = 0; ii < N/2; ++ii){
		if (hoge[ii] != s[ii]){
			ans = false;
			break;
		}
	}
	// cout << ans << "\n";

	string aho;
	for (int ii = N/2 + 1; ii < N; ++ii){
		aho.push_back(s[ii]);
	}
	// cout << aho << "\n";
	reverse(aho.begin(), aho.end());
	for (int ii = N/2 + 1; ii < N; ++ii){
		if (aho[ii-(N/2 + 1)] != s[ii]){
			ans = false;
			break;
		}
	}
	// cout << ans << "\n";


	if (ans){
		cout << "Yes" << "\n";
	} else {
		cout << "No" << "\n";
	}

	return 0;
}


Measured memory_bytes: 256
// #include <ext/pb_ds/assoc_container.hpp> 
//#include <ext/pb_ds/tree_policy.hpp>
#include <iostream>
#include <iomanip>
#include <sstream>
#include <cstring>
#include <vector>
#include <deque>
#include <queue>
#include <set>
#include <map>
#include <valarray>
#include <iterator>
#include <functional>
#include <limits>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <cassert>
#include <unordered_map>
#include <unordered_set>
#include <stack>
using namespace std;
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define trace(x) cerr << #x << ": " << x << " " << endl;
 
typedef int64_t ll;
 
#define endl '\n'
#define int ll
ll mod=1e9+7;
ll mod1=1e9+5;
 
ll power(ll a,ll b)
{
    if(b==0) return 1;
    else if(b%2==0)
        return power((((a%mod)*(a%mod))%mod),b/2)%mod;
    else return ((a%mod)*(power((((a%mod)*(a%mod))%mod),b/2)%mod))%mod;
}
     
 //using namespace __gnu_pbds;
 //#define ordered_set tree<pair<int,int>, null_type,less<pair<int,int>>, rb_tree_tag,tree_order_statistics_node_update>
//find_by_order(k)  returns iterator to kth element starting from 0;
//order_of_key(k) returns count of elements strictly smaller than k;
//erase,insert same as normal set
// mt19937 mrand(chrono::high_resolution_clock::now().time_since_epoch().count()); for randomized solution

int32_t main()
{
    IOS

    
    int n,k;
    cin>>n>>k;

    if(n>=k)
    {
        n=n%k;
    }
    int ans=n;
    ans=min(ans,abs(n-k));
    cout<<ans<<endl;

}       

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
struct node
{
    int val;
    int code;
}a[100009];
int cmp(node a,node b)
{
    return a.val<b.val;
}
int main()
{
    int n;
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
        scanf("%d",&a[i]),a[i].code=i;
    sort(a+1,a+n+1,cmp);
    for(int i=1;i<=n;i++)
        printf("%d ",a[i].code);
    return 0;
}


Measured memory_bytes: 1664
N = int(input())
a = list(map(int, input().split(' ')))

aSorted = sorted(a, reverse=True)

alice = 0
bob = 0

for i in range(N):
    # アリスのターン
    if i % 2 == 0:
        alice += aSorted[i]
    # ボブのターン
    else:
        bob += aSorted[i]

print(alice - bob)


Measured memory_bytes: 9108
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization ("unroll-loops")

#include <bits/stdc++.h>

using namespace std;

void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
#define ll long long int

const ll inf=1e18+10;
const int nax=1e5+10;

int main(){
    int n,w;
    cin>>n>>w;
    vector<vector<ll>> dp(n+1,vector<ll> (nax,inf));
    vector<int> weight(n);
    vector<int> val(n);
    for(int i=0;i<n;i++){
        cin>>weight[i]>>val[i];
    }
    for(int i=0;i<=n;i++){
        dp[i][0]=0;
    }
    for(int i=1;i<=n;i++){
        for(int j=1;j<nax;j++){
            if(j<val[i-1]){
                dp[i][j]=dp[i-1][j];
            }
            else{
                dp[i][j]=min(dp[i-1][j],weight[i-1]+dp[i-1][j-val[i-1]]);
            }
        }
        //debug(dp[i]);
    }
    int max_val=-1;
    for(int i=0;i<nax;i++){
        if(dp[n][i]<=w){
            max_val=i;
        }
    }
    cout<<max_val<<"\n";
    return 0;
}

Measured memory_bytes: 83124
# from itertools import combinations
from bisect import bisect_left

n = int(input())
ls = list(map(int, input().split()))
ls.sort()

count = 0

# for a, b, c in combinations(ls, 3):
#     if a < b + c and b < c + a and c < a + b:
#         count += 1

# for j in range(n - 1, 1, -1):
#     last = ls[j]
#     for a, b in combinations(ls[:j], 2):
#         if a + b > last:
#             count += 1

for i in range(n - 1, 1, -1):
    for j in range(i - 1, 0, -1):
        idx = bisect_left(ls[:j], ls[i] - ls[j] + 1)
        if idx < j:
            count += j - idx

print(count)

Measured memory_bytes: 51576
#include <stdio.h>

void insertionSort(int *,int,int);
void shellSort(int *,int);

static int cnt=0;


int main(void){
  int A[1000000],m,n,i;
  scanf("%d",&n);
  for(i=0;i<n;i++)
    scanf("%d",&A[i]);

  shellSort(A,n);
  printf("\n%d\n",cnt);

  for(i=0;i<n;i++)
    printf("%d\n",A[i]);
  return 0;
}

void insertionSort(int *A,int n,int g){
  int i,j,v;
  for(i=g;i<n;i++){
    v=A[i];
    j=i-g;
    while(j>=0 && A[j]>v){
      A[j+g]=A[j];
      j=j-g;
      cnt++;
    }
    A[j+g]=v;
  }
}

void shellSort(int *A,int n){
  int i,m,h;
  int G[100];
  cnt=0;
  for(h=1,i=0;;i++){
    if(h>n)break;
    G[i]=h;
    h=3*h+1;
  }
  m=i;
  printf("%d\n",m);
  for(i=m-1;i>=0;i--){
    insertionSort(A,n,G[i]);
    printf("%d",G[i]);
    if(i!=0)printf(" ");
  }
}


Measured memory_bytes: 5676
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int n;
    cin >> n;
    vector<int>h(n);
    for(int i = 0; i < n; i++) cin >> h[i];
    int ans = 0;
    int active = 0;
    for(int i = 0; i < n; i++){
        if (active >= h[i]){
            active = h[i];
        }else{
            ans += h[i] - active;
            active = h[i];
        }
    }
    cout << ans;
    
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
using namespace std;
int main()
{
    long long a,b,c,k;
    cin>>a>>b>>c>>k;
    if(k<=a)
    {
        cout<<k;
    }
    else if(k>a&&k<=(a+b))
    {
        cout<<a;
    }
    else if(k>(a+b)&&k<=(a+b+c))
    {
        cout<<a-(k-(a+b));
    }
    return 0;
}

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

int main() {
    int n;
    cin >> n;
    vector<int> b(n-1);
    vector<int> a(n);
    rep(i,n-1) cin >> b[i];
    a[0] = b[0]; a[n-1] = b[n-2];
    for(int i = 1; i <= n-2; ++i) {
        a[i] = min(b[i], b[i-1]);
    }
    ll ans = 0;
    for(auto x : a){
        ans += x;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main()
{
    int H, W;
    cin >> H >> W;
    vector<vector<char>> S(H+2, vector<char>(W+2, '.'));
    for (int i = 1;i<=H;i++){
        for (int j = 1; j <= W;j++){
            cin >> S.at(i).at(j);
        }
    }
    int cnt = 0;
    for (int i = 1; i <= H; i++)
    {
        for (int j = 1; j <= W; j++)
        {
            char a = S.at(i).at(j);
            if (a == '#' && S[i][j - 1] != '#' && S[i - 1][j] != '#' && S[i][j + 1] != '#' && S[i + 1][j] != '#')
                cnt++;
        }
    }
    puts(cnt==0?"Yes":"No");
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <ctime>
#include <cmath>
#include <string>
#include <stdlib.h>
#include <fstream>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <deque>
#include <iterator>
#include <iomanip>
using namespace std;


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

Measured memory_bytes: 3632
#include <cstdio>
#include <functional>
#include <algorithm>
#include <vector>
#include <limits>
#include <numeric>
#include <type_traits>
#include <iostream>
#include <queue>
#include <math.h>
#include <bits/stdc++.h>
#include <queue>
#include <map>

using namespace std;

#define INF (1ll<<60)
#define INFint (1<<30)
#define MOD 1000000007
#define BOUND 27182818284

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

#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)

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

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

// gcd
template<typename T>
T gcd(T a, T b){
    if(a==0)
        return b;
    return gcd(b%a,a);
}

// gcd array
int findGCD(int arr[], int n){
    int result = arr[0];
    for (int i=1; i < n; i++)
        result = gcd(arr[i], result);
    return result;
}

template<typename T>
T lcm( T m, T n ){
    // 引数に0がある場合は0を返す
    if ( ( 0 == m ) || ( 0 == n ) )
        return 0;
    return ((m/gcd(m, n)) * n); // lcm = m * n / gcd(m,n)
}

template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    fill( (T*)array, (T*)(array+N), val );
}


int dx[5]={1,0,-1,0};
int dy[5]={0,1,0,-1};
// v.front() = -BOUND;
// v.back() = BOUND;

struct edge{
    int cost, to;

    edge(int in_cost, int in_to){
        cost=in_cost;
        to=in_to;
    }
    bool operator<(const edge &a) const
    {
        return cost > a.cost;
    }
};

vector<ll>A;
vector<ll>a;
int N,K;
void sum_part(){
    for(int i=0; i<N; i++){
        ll sum=0LL;
        for(int j=i; j<N; j++){
            sum+=a[j];
            A.push_back(sum);
        }
    }
}

int main() {
    string S;
    cin >> S;

    int a_num=0,b_num=0,c_num=0;
    for(auto x: S){
        if(x=='a') a_num++;
        if(x=='b') b_num++;
        if(x=='c') c_num++;
    }

    int chara_min=min({a_num, b_num, c_num});
    a_num-=chara_min, b_num-=chara_min, c_num-=chara_min;

    if(a_num>=2 || b_num>=2 || c_num>=2){
        cout << "NO" << endl;
    }else{
        cout << "YES" << endl;
    }

    return 0;
}


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

int main(){
    int N;
    string S;
    cin >> N >> S;
    if(N%2 == 0) {
        string A,B;
        
        for (int i = 0; i < N / 2;i++){
            A += S.at(i);
        }
        
        for (int i = N / 2; i < N;i++){
            B += S.at(i);
        }

        if (A==B){
            cout << "Yes" << endl;
        }

        else if (A!=B) {
            cout << "No" << endl;
        }
    }
    else
        cout << "No" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll, ll>;
using vi = vector<ll>;
using vvi = vector<vector<ll>>;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
const double eps = 1e-10;
const ll MOD = 1000000007;
const ll INF = 1000000000;
const ll LINF = 1ll<<50;
template<typename T>
void printv(const vector<T>& s) {
  for(ll i=0;i<(ll)(s.size());++i) {
    cout << s[i];
    if(i == (ll)(s.size())-1) cout << endl;
    else cout << " ";
  }
}
bool bs(ll mid, ll n, ll k, const vector<ll> &a) {
  vector<vector<bool>> dp(n+1, vector<bool>(k, false));
  dp[0][0] = true;
  for(ll i=0;i<n;++i) {
    for(ll j=0;j<k;++j) {
      if(!dp[i][j]) continue;
      dp[i+1][j] = dp[i][j];
      if(i != mid && j + a[i] < k) dp[i+1][j+a[i]] = dp[i][j];
    }
  }
  bool need = false;
  for(ll i=max(0ll, k-a[mid]);i<k;++i) {
    need |= dp[n][i];
  }
  return !need;
}
signed main() {
  cin.tie(0);
  cout << fixed << setprecision(10);
  ll n, k; cin >> n >> k;
  vector<ll> a(n);
  for(ll i=0;i<n;++i) {
    cin >> a[i];
  }
  sort(a.begin(), a.end());
  ll l = 0, r = n;
  while(r - l > 1) {
    ll mid = (l + r) / 2;
    if(bs(mid, n, k, a)) {
      l = mid;
    } else {
      r = mid;
    }
  }
  if(l != 0 && l != n-1) cout << l+1 << endl;
  else if(l == 0) cout << (bs(0, n, k, a) ? 1 : 0) << endl;
  else cout << (bs(n-1, n, k, a) ? n : n-1) << endl;
}


Measured memory_bytes: 3660
while 1:
    s = raw_input().replace("north","0").replace("west","1")
    if s == "#": break

    u = 90*int(s[-1])
    d = 1
    s = s[:-1]
    while s:
        u *= 2; d *= 2
        u += 90 if s[-1] == "1" else -90
        s = s[:-1]

    while u%2 == 0 and d > 1:
        u /= 2; d /= 2
    print u if d == 1 else "%d/%d"%(u,d)

Measured memory_bytes: 4224
#include <string>
#include <time.h>
#include <vector>
#include <map>
#include <set>
#include <sstream>
#include <algorithm>
#include <bitset>
#include <utility>
#include <iostream>
#include <cmath>
#include <deque>

#define MOD 998244353
#define pii pair<ll,ll>
#define X first
#define Y second
#define mp make_pair

typedef long long ll;
using namespace std;
#define MAXN 228228
ll x, y, n, m, k;
ll a[MAXN];

int main() {
    cin >> n >> m;
    for (int i = 1; i <= n; i++) {
        for (int j = 20; j <= m; j++) {
            ll x = j % 10;
            ll y = j / 10;
            if (x >= 2 && y >= 2 && x * y == i) {
                k++;
            }
        }
    }
    cout << k << endl;
    return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

class MainClass
{
    static int[] dy = new int[4] { 0, 1, 0, -1 };
    static int[] dx = new int[4] { 1, 0, -1, 0 };
    static string[] dw = new string[4] { "R", "U", "L", "D" };
    static void Main()
    {
        var r = Console.ReadLine().Split().Select(_=>int.Parse(_)+1010 ).ToArray();
        var sp = new int[2] { r[1], r[0] };
        var gp = new int[2] { r[3], r[2] };

        var frags = new bool[2020, 2020];
        var que = new Queue<(int, int,int)>();
        que.Enqueue((sp[0], sp[1],1));

        string ans = "";

        for (int i = 0; i < 4; i++)
        {
            var d = new ValueTuple<int, int>();
            if (i % 2 == 0) d = (gp[0], gp[1]);
            else d = (sp[0], sp[1]);

            var nfrags = new int[2020, 2020];
            

            while (que.Count > 0)
            {
                var t = que.Dequeue();
                int y = t.Item1;
                int x = t.Item2;
                int c = t.Item3;
                nfrags[y,x] = c;

                for (int j = 0; j < 4; j++)
                {
                    int ny = y + dy[j];
                    int nx = x + dx[j];
                    int nc = c + 1;

                    if (!(0 <= ny && ny < 2020 && 0 <= nx && nx < 2020)) continue;
                    if (nfrags[ny,nx]!=0||frags[ny,nx]) continue;
                    nfrags[ny, nx] = nc;
                    que.Enqueue((ny, nx, nc));
                }

                if (nfrags[d.Item1, d.Item2] != 0)
                    break;
            }

            string sb = "";
            int sy = d.Item1;
            int sx = d.Item2;
            for (int j = nfrags[d.Item1,d.Item2]-1; j >= 1; j--)
            {
                for (int k = 0; k < 4; k++)
                {
                    int sdy = sy - dy[k];
                    int sdx = sx - dx[k];
                    if (nfrags[sdy, sdx] == j)
                    {
                        frags[sdy, sdx] = true;
                        sb = dw[k] + sb;
                        
                        sy = sdy;
                        sx = sdx;
                        break;
                    }
                }
            }

            ans += sb;
            frags[sp[0], sp[1]] = false;
            frags[gp[0], gp[1]] = false;
            que = new Queue<(int, int, int)>();
            que.Enqueue((d.Item1,d.Item2,1));
        }

        Console.WriteLine(ans);
    }
}

Measured memory_bytes: 93568
module Main where
import Data.Function
import qualified Data.Map as M
import Data.Maybe
import Control.Monad
main = do
  n:m:_ <- map read . words <$> getLine :: IO [Int]
  ls <- flip fix (M.empty, m) $ \loop (loads,cnt) -> 
    if cnt == 0 then return loads
    else do
    a:b:_ <- map read . words <$> getLine :: IO [Int]    
    let na = fromMaybe 0 $ M.lookup a loads 
    let nb = fromMaybe 0 $ M.lookup b loads
    let loads' = M.insert a (na + 1) $ M.insert b (nb + 1) $ loads
    loop (loads', cnt - 1)
  forM_ [1..n] $ \i -> do
    print $ fromMaybe 0 $ M.lookup i ls
  return ()


Measured memory_bytes: 1020
#define  _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <math.h>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <math.h>
#include <iostream> 
#include<map>
#include <iomanip>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
using namespace std;
#define MAX_MOD 1000000007
#define REP(i,n) for(long long i = 0;i < n;++i)
#define LONG_INF 800000000000000000
int go[300][300] = {};
int hikaku[300][300] = {};
int main() {
	int n, m;
	cin >> n >> m;
	REP(i, n) {
		string s;
		cin >> s;
		REP(q, n) {
			if (s[q] == '#') {
				go[i][q] = 1;
			}
			else go[i][q] = 2;
		}
	}
	REP(i, m) {
		string s;
		cin >> s;
		REP(q, m) {
			if (s[q] == '#') {
				hikaku[i][q] = 1;
			}
			else hikaku[i][q] = 2;
		}
	}
	for (int i = 0;i < n-m+1;++i) {
		for (int q = 0;q < n-m+1;++q) {
			for (int j = 0;j < m;++j) {
				for (int t = 0;t < m;++t) {
					if (go[i + j][q + t] != hikaku[j][t]) goto failed;
				}
			}
			cout << "Yes" << endl;
			return 0;
		failed:;
		}
	}
	cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 384
#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 rep1(i,n) for(int i = 1; i <= (n); i++)
#define rrep1(i,n) for(int i = (n); i > 0; i--)

#define ll long long
#define pi pair<int, int>
#define pll pair<ll, ll>

#define MOD 1000000007
#define INF 1000000000000000LL

using namespace std;

// x^n in mod
ll modpow(ll x, ll n, ll mod){
  if(n==0) return 1;

  if(n%2==0){
    return modpow(x*x%mod, n/2, mod) % mod;
  }else{
    return x * modpow(x, (n-1), mod) % mod;
  }
}

int main(){
  int n;cin>>n;
  vector<ll> t(n), a(n);
  rep(i, n)cin>>t[i];
  rep(i, n)cin>>a[i];

  if(a[0]==t[0] && a.back()==t.back()){
    cout<<modpow(a[0], max<ll>(0, n-2), MOD)<<endl;
    return 0;
  }

  int max_t_i=0, max_a_i=n-1;
  rep(i, n)if(t[max_t_i]<t[i])max_t_i=i;
  rrep(i, n)if(a[max_a_i]<a[i])max_a_i=i;
//cout<<max_t_i<<' '<<max_a_i<<endl;

  if(a[max_a_i] != t[max_t_i] || max_a_i < max_t_i) { cout<<0<<endl; return 0;}

  vector<pll> h_l;
  ll ch=0, cl=0;
  rep(i, n){
    if(ch<t[i]){
      if(ch>0 && cl>0)h_l.push_back({ch, cl});
      ch=t[i]; cl=0;
    }else{
      cl++;
    }
  }

  ch=0, cl=0;
  rrep(i, n){
    if(ch<a[i]){
      if(ch>0 && cl>0)h_l.push_back({ch, cl});
      ch=a[i]; cl=0;
    }else{
      cl++;
    }
  }

  ll result=1;
  for(auto p: h_l){
//cout<<p.first<<','<<p.second<<endl;
    result = ( result * modpow(p.first, p.second, MOD) ) % MOD;
  }

  if(max_a_i != max_t_i)result=( result*modpow(a[max_a_i], max_a_i - max_t_i + 1-2, MOD) ) % MOD;

  cout<<result<<endl;

  return 0;
}

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

#define pb push_back
#define mp make_pair
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef complex<double> point;
#define xx real()
#define yy imag()

#define REP(i, a, b) for(int i = (a); i < (int)(b); i++)
#define REPN(i, a, b) for(int i = (a); i <= (int)(b); i++)
#define FA(it, x) for(__typeof((x).begin()) it = (x).begin(); it != (x).end(); it++)
#define SZ(x) (int)(x).size()
#define BE(x) (x).begin(), (x).end()
#define SORT(x) sort(BE(x))
#define _1 first
#define _2 second

#define x1 gray_cat_x1
#define y1 gray_cat_y1

template<class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }

#define file "I1"

const double EPS = 1e-9;
const double PI = acos(-1.);
const int INF = 1e9;
const ll MOD = 1e9 + 7;

const int MAXN = 1e5 + 5;

set<int> g[MAXN];

set<pair<int, pii> > st;

char col[MAXN];

vi tmp;

int dp[MAXN];
int mx;

int used[MAXN];

set<pii> cur;

void dfs(int s, int prv){
	used[s] = 1;
	FA(it, g[s]){
		int to = *it;
		if (to != prv){
			dfs(to, s);
		}
	}
	
	dp[s] = 0;
	
	cur.clear();
	FA(it, g[s]){
		int to = *it;
		if (to != prv){
			int a = dp[to] + 1;
			if (col[s] == 1){
				a += 1;
			} else {
				a--;
			}
			cur.insert(mp(-a, to));
		}
	}
	if (SZ(cur) >= 1){
		dp[s] = -cur.begin()->_1;
	}
	if (SZ(cur) > 1){
		int cnt = 0;
		int tt[2];
		
		int d[2];
		
		FA(it, cur){
			d[cnt] = it->_2;
			tt[cnt++] = -it->_1;
			if (cnt == 2){
				break;
			}
		}
		int oo = tt[0] + tt[1];
		if (col[s] == 1){
			oo -= 1;
		} else {
			oo++;
		}
		mx = max(mx, oo);
		
		//printf("%d: %d %d %d\n", s, d[0], d[1], mx);
	}
	
	
	//printf("%d %d\n", s, dp[s]);
}

void solve(){
	int n, a, b;
	scanf("%d", &n);
	REP(i, 1, n){
		scanf("%d%d", &a, &b);
		g[a].insert(b);
		g[b].insert(a);
	}
	scanf("%s", &col[1]);
	REPN(i, 1, n){
		col[i] = (col[i] == 'W' ? 1 : 0);
	}
	REPN(i, 1, n){
		st.insert(mp(SZ(g[i]), mp(col[i], i)));
	}
	while(!st.empty()){
		a = st.begin()->_2._2;
		//printf("%d %d %d\n", a, col[a], SZ(g[a]));
		if (SZ(g[a]) > 1 || col[a] == 1){
			break;
		}
		
		tmp.clear();
		FA(it, g[a]){
			tmp.pb(*it);
		}
		
		st.erase(st.begin());
		g[a].clear();
		
		REP(i, 0, SZ(tmp)){
			b = tmp[i];
			st.erase(mp(SZ(g[b]), mp(col[b], b)));
			g[b].erase(a);
			st.insert(mp(SZ(g[b]), mp(col[b], b)));
		}
	}
	
	/*REPN(i, 1, n){
		printf("%d: ", i);
		FA(it, g[i]){
			printf("%d ", *it);
		}
		putchar('\n');
	}*/
	
	if (st.empty()){
		printf("0\n");
		return;
	}
	if (SZ(st) <= 2){
		printf("%d\n", SZ(st));
		return;
	}
	
	int ans = 0;
	REPN(i, 1, n){
		if (SZ(g[i]) & 1){
			col[i] ^= 1;
		}
		if (SZ(g[i])){
			ans += 2;
			if (col[i]){
				ans++;
			}
		}
	}
	ans--;
	//printf("%d\n", ans);
	
	mx = 0;
	
	int s = st.rbegin()->_2._2;
	dfs(s, -1);
	ans -= mx;
	printf("%d\n", ans);
	
}   

int main(){

    //freopen(file".in", "r", stdin); freopen(file".out", "w", stdout);
    int t = 1;
    //cin >> t;
    while(t--){
        solve();    
    }
}


Measured memory_bytes: 30336
#include <iostream>
using namespace std;
int gcd(int p,int q){
    int a=0;
    if (p<q){
        a=p;
    }
    else{
        a=q;
    }
    int b=p+q-a;
    if (b%a==0){
        return a;
    }
    else{
        return gcd(a,b%a);
    }
}
int main(void){
    int N,X;
    cin >> N >> X;
    int x[114514];
    for (int i=0;i<N;i++){
        cin >> x[i];
        x[i]=abs(x[i]-X);
    }
    int ans=x[0];
    for (int i=1;i<N;i++){
        ans=gcd(ans,x[i]);
    }
    cout<< ans<<endl;
    return 0;
}


Measured memory_bytes: 640
from collections import defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inp(): return int(input())
def inpl(): return list(map(int, input().split()))
def inpl_str(): return list(input().split())

def calc(t):
    h,m,s = map(int,t.split(':'))
    return (h*60+m)*60+s


while True:
    n = inp()
    if n == 0:
        break
    else:
        imos = [0]*(60*60*24+5)
        for _ in range(n):
            ts,tt = input().split()
            ts = calc(ts)
            tt = calc(tt)
            imos[ts] += 1
            imos[tt] -= 1

        tmp = 0
        for i in range(60*60*24+5):
            tmp += imos[i]
            imos[i] = tmp
        print(max(imos))



Measured memory_bytes: 11072
#include<bits/stdc++.h>
using namespace std;
#define rep(m,x,r) for((m)=(x);(m)<(r);(m)++)
int main(){
    int n,d,ans;
    cin>>n>>d;
    ans=n/(d*2+1);
    if(n%(d*2+1)!=0)ans++;
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <stdio.h>
int n;
int ten[10]={1,10,100,1000,10000,100000,1000000,10000000,100000000};
int aaa[4]={3,5,7};
int result=0;


int main(){
	int a,b;
	int result=9999;
	scanf("%d",&a);
	
		b=a%10+(a/10)%10+(a/100)%10+(a/1000)%10+(a/10000)%10+(a/100000)%10+(a/1000000)%10+(a/10000000)%10+(a/100000000)%10+(a/1000000000)%10;
		
	if(a%b==0)
	{
		printf("Yes");
		return 0;
	}
	printf("No");
	}


Measured memory_bytes: 128
N = int(input())
E = [[] for _ in range(N+1)]
for _ in range(N-1):
    u, v, w = map(int, input().split())
    E[u].append([v, w])
    E[v].append([u, w])

Ans = [-1]*(N+1)
Ans[1] = 0
q = [1]
Closed = [False]*(N+1)
Closed[1] = True
while len(q):
    v = q.pop()
    col = Ans[v]
    for u, w in E[v]:
        if not Closed[u]:
            Closed[u] = True
            q.append(u)
            Ans[u] = col if w%2==0 else 1-col
print(*Ans[1:], sep="\n")


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

using namespace std;

#define LOG(...) fprintf(stderr,__VA_ARGS__)
//#define LOG(...)
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort(ALL(c))
#define RSORT(c) sort(RALL(c))

typedef long long ll;
typedef unsigned long long ull;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vb> vvb;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

int main() {
    int n;
    while (cin >> n, n) {
        uint64_t dp[50] = {};
        bool schedule[30][50] = {};

        REP(i, n) {
            int m;
            cin >> m;
            REP(j, m) {
                int day;
                cin >> day;
                schedule[day-1][i] = true;
            }
        }

        REP(i, n) dp[i] = (uint64_t)1 << i;

        uint64_t all = ((uint64_t)1 << n) - 1;
        REP(day, 30) {
            uint64_t s = 0;
            REP(i, n) {
                if (schedule[day][i]) s |= dp[i];
            }
            if (s == all) {
                cout << day + 1 << endl;
                goto END;
            }
            REP(i, n) {
                if (schedule[day][i]) dp[i] |= s;
            }
        }
        cout << -1 << endl;
    END : {}
    }
}

Measured memory_bytes: 1160
#include <iostream>
#include <string>
#include <set>
#include <vector>
#include <cstdlib>

using namespace std;


set<int> rec2(string str){
	// ©Ç¤©
	bool f = false;
	for(int i = 0; i < str.size(); i++){
		if(!(str[i] >= '0' && str[i] <= '9')){
			f = true;
			break;
		}
	}
	if(!f){
		set<int> v;
		v.insert(atoi(str.c_str()));
		return v;
	}

	// ©ªÌÊÅÍíêÄ¢éê
	if(str[0] == '('){
		bool ff = false;
		int cnt = 1;
		for(int i = 1; i < str.size(); i++){
			if(str[i] == '('){
				cnt++;
			}
			else if(str[i] == ')'){
				cnt--;
				if(cnt == 0 && i != str.size()-1)
					break;
				if(cnt == 0 && i == str.size()-1){
					return rec2(str.substr(1,str.size()-2));
				}
			}
		}
	}

	set<int> vec;
	for(int i = 0; i < str.size(); i++){
		if(str[i] == '+'){
			set<int> v1 =  rec2(str.substr(0,i));
			set<int> v2 =  rec2(str.substr(i+1));
			for(set<int>::iterator it = v1.begin(); v1.end() != it; it++){
				for(set<int>::iterator iit = v2.begin(); v2.end() != iit; iit++){
					vec.insert((*it) + (*iit));
				}
			}
		}
		else if(str[i] == '*'){
			set<int> v1 =  rec2(str.substr(0,i));
			set<int> v2 =  rec2(str.substr(i+1));
			for(set<int>::iterator it = v1.begin(); v1.end() != it; it++){
				for(set<int>::iterator iit = v2.begin(); v2.end() != iit; iit++){
					vec.insert((*it) * (*iit));
				}
			}
		}
		else if(str[i] == '/'){
			set<int> v1 =  rec2(str.substr(0,i));
			set<int> v2 =  rec2(str.substr(i+1));
			for(set<int>::iterator it = v1.begin(); v1.end() != it; it++){
				for(set<int>::iterator iit = v2.begin(); v2.end() != iit; iit++){
					if((*iit) != 0)
						vec.insert((*it) / (*iit));
				}
			}
		}
		else if(str[i] == '-'){
			set<int> v1 =  rec2(str.substr(0,i));
			set<int> v2 =  rec2(str.substr(i+1));
			for(set<int>::iterator it = v1.begin(); v1.end() != it; it++){
				for(set<int>::iterator iit = v2.begin(); v2.end() != iit; iit++){
					vec.insert((*it) - (*iit));
				}
			}
		}
	}
	return vec;
}

int main(){

	string str;
	while(cin >> str && str != "#"){
		set<int> ss = rec2(str);
		cout << ss.size() << endl;
	}
	
	return 0;
}

Measured memory_bytes: 972
#include <stdio.h>
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
#include <functional>
#include <map>
#include <iomanip>
#include <math.h> 
#include <stack>
#include <queue>
#include <bitset>
#include <cstdlib>
#include <tuple>
#include <cctype>
#include <stdlib.h>

using namespace std;

int main() {
	int i, j, k;
	int n;
	int f[100][10], p[100][11];

	cin >> n;

	for (i = 0; i < n; i++) {
		for (j = 0; j < 10; j++) {
			cin >> f[i][j];
		}
	}

	for (i = 0; i < n; i++) {
		for (j = 0; j < 11; j++) {
			cin >> p[i][j];
		}
	}

	//for (k = 0; k < n; k++) {
		char buff[50];
		int maxn = -9999999999;
		for (i = 1; i <= 1023; i++) {
			//itoa(i, buff, 2);
			string str = bitset<10>(i).to_string();
			int sum = 0;
			for (j = 0; j < n; j++) {
				int cnt = 0;
				for (k = 0; k < 10; k++) {
					if (f[j][k] == 1 && str[k] == '1') {
						cnt++;
					}
				}
				sum += p[j][cnt];
			}
			maxn = max(maxn, sum);
		}

	//}

		cout << maxn << endl;





	getchar();
	getchar();
	return 0;
}

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

using namespace std;

template< typename T >
struct edge
{
  int src, to;
  T cost;

  edge(int to, T cost) : src(-1), to(to), cost(cost) {}

  edge(int src, int to, T cost) : src(src), to(to), cost(cost) {}

  operator int() const { return to; }
};

template< typename T >
using Edges = vector< edge< T > >;
template< typename T >
using WeightedGraph = vector< Edges< T > >;
using UnWeightedGraph = vector< vector< int > >;
template< typename T >
using Matrix = vector< vector< T > >;


template< typename T >
pair< int, int > dfs(const WeightedGraph< T > &g, int idx, int par)
{
  pair< T, int > ret(0, idx);
  for(auto &e : g[idx]) {
    if(e.to == par) continue;
    auto cost = dfs(g, e.to, idx);
    cost.first += e.cost;
    ret = max(ret, cost);
  }
  return ret;
}

template< typename T >
T tree_diameter(const WeightedGraph< T > &g)
{
  auto p = dfs(g, 0, -1);
  auto q = dfs(g, p.second, -1);
  return (q.first);
}

int main()
{
  int V;
  scanf("%d", &V);
  WeightedGraph< int > g(V);
  for(int i = 0; i < V - 1; i++) {
    int x, y, z;
    scanf("%d %d %d", &x, &y, &z);
    g[x].emplace_back(y, z);
    g[y].emplace_back(x, z);
  }
  cout << tree_diameter(g) << endl;
}





Measured memory_bytes: 16008
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define vi vector<int>
#define vl vector<long>
#define vll vector<long long int>
#define vC  vector<char>
#define FastIO ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

int main()
{
    FastIO
    ll n,W,i,j,maxv=0;
    cin>>n>>W;
    vll v(n+1),w(n+1);

    for(i=1;i<n+1;i++)
    {
        cin>>w[i]>>v[i];
        maxv+=v[i];

    }
    ll dp[100001];
    for(i=0;i<100001;i++)
    {
            dp[i]=INT_MAX;
    }
    dp[0]=0;
    for(i=1;i<=n;i++)
    {
        for(j=100000-v[i];j>=0;j--)
        {

                dp[j+v[i]]=min(dp[j+v[i]],dp[j]+w[i]);

        }
    }


    for(i=100000;i>=0;i--)
    {
        if(dp[i]<=W)
        {cout<<i; return 0;}
    }
return 0;

}


Measured memory_bytes: 1024
# -*- coding: utf-8 -*-
import numpy as np
import sys
input = sys.stdin.readline


def main():
    n = int(input())
    a = list(map(int, input().split()))
    a = np.argsort(np.array(a))+1
    # print(a)
    # result = []
    # for i in range(1, n + 1):
    #     result.append(a.where(lambda x: x == i))
    print(*a, sep=' ')


if __name__ == '__main__':
    main()


Measured memory_bytes: 23444
#include <iostream>
#include <vector>
#include <deque>
#include <algorithm>
#include <numeric>
#include <string>
#include <cstring>
#include <list>
#include <unordered_set>
#include <tuple>
#include <cmath>
#include <limits>
#include <type_traits>
#include <iomanip>
#include <map>
#include <unordered_map>
#include <queue>
#include <stack>
#include <set>
#include <bitset>
#include <regex>
#include <random>
#include<bits/stdc++.h>

using namespace std;

typedef long long ll;
#define rep(i,n)for(ll i=0;i<n;++i)
#define exout(x) printf("%.10f\n", x)
const double pi = acos(-1.0);
const ll MOD = 1000000007;
const ll INF = 1e10;
const ll MAX_N = 1010;

//最大公約数
ll gcd(ll x, ll y) {
	return y ? gcd(y, x % y) : x;
}

ll lcm(ll x, ll y) {
	if (x == 0 || y == 0)return 0;
	return (x / gcd(x, y) * y);
}

ll w[110];
ll v[110];
ll dp[101010][110];

//long longしか使わない
//素数は1より大きい
int main() {
	ll N, W;
	cin >> N >> W;
	rep(i, N) {
		cin >> w[i] >> v[i];
	}
	rep(i, N) {
		rep(j, W+1) {
			if (j < w[i])dp[j][i + 1] = dp[j][i];
			else {
				dp[j][i+1] = max(dp[j][i], dp[j - w[i]][i] + v[i]);
			}
		}
	}
	ll ans = 0;
	rep(i, W + 1) {
		ans = max(ans, dp[i][N]);
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 86272
import java.util.Scanner;
import java.math.*;
 class Main
{
  public static void main(String args[])
  {
    Scanner sc=new Scanner(System.in);
    int n=sc.nextInt();
    int a=sc.nextInt();
    int b=sc.nextInt();
    int max=(int)Math.min(a,b);
    int min=0;
    if((a+b)>n)
      	min=(a+b)-n;
   	else
      	min=0;
    System.out.println(max+" "+min);
  }
}

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

using namespace std;
int main()
{
  int N,count=0,ori;
  cin>>N;
  ori=N;
  while(N!=0)
  {
    
    N=N/10;
    count++;
  }
  switch(count)
  {
    case 1: cout<<ori;
            break;
    case 2: cout<<"9";
            break;
    case 3: cout<<ori-90;
            break;
    case 4: cout<<"909";
            break;
    case 5: cout<<ori-9090;
            break;
    case 6: cout<<"90909";
            break;
  }
  return 0;
}

Measured memory_bytes: 256