akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <algorithm>

using namespace std;

int main(void)
{
	int d;
	int n, m;
	int ans;
	int coor[100000];
	int query[10000];
	int store[100000];
	int last;
	
	while (1){
		scanf("%d", &d);
		
		if (d == 0){
			break;
		}
		
		scanf("%d%d", &n, &m);
		
		coor[0] = 0;
		for (int i = 1; i < n; i++){
			scanf("%d", &coor[i]);
		}
		for (int i = 0; i < m; i++){
			scanf("%d", &query[i]);
		}
		
		sort(coor, coor + n);
		
		last = (d + coor[n - 1]) / 2 + 1;
		
		for (int i = 1; i < n; i++){
			store[i - 1] = (coor[i] + coor[i - 1]) / 2 + 1;
		}
		store[n - 1] = last - 1;
		/*
		for (int i = 0; i < n; i++){
			printf("%d ", store[i]);
		}
		puts("");
		*/
		ans = 0;
		for (int i = 0; i < m; i++){
			if (query[i] >= last){
				ans += d - query[i];
			}
			else {
				ans += abs(query[i] - coor[(upper_bound(store, store + n, query[i]) - store)]);
			}
		}
		
		printf("%d\n", ans);
	}
	
	return (0);
}

Measured memory_bytes: 1224
#include <iostream>
#include <vector>
#include <algorithm>
 
#define rep(i, n) for(int i = 0; i < (n); ++i)
 
using namespace std;

const int inf = 1e5;

int n;
int s[100];
int dp[101][10];

int main(){
    cin >> n;
    rep(i, n){
        cin >> s[i];
    }

    rep(i, 9){
        dp[0][i + 1] = -inf;
    }
    rep(i, n){
        rep(j, 10){
            int p = (j - s[i] % 10 + 10) % 10;
            dp[i + 1][j] = max(dp[i][j], dp[i][p] + s[i]);
        }
    }
    int ans = 0;
    rep(j, 9){
        ans = max(dp[n][j + 1], ans);
    }
    cout << ans << endl;
    return 0;
}

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

int main() {
  int A, B ,C, D;
  cin >> A >> B >> C >> D;

  if( A + B > C + D){
  cout << "Left" << endl;
  }
  else if (A+B == C+D){
  cout << "Balanced" << endl;
    }
  else{
  cout << "Right" << endl;}

}

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

#define FOR(i, a, b) for (int (i) = (a); (i) < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define TRACE(x) cerr << #x << " " << x << endl
#define eb emplace_back
#define __ << " " <<
typedef long long ll;
typedef std::pair<int, int> P;
#define X first
#define Y second
#define double long double
using namespace std;

const int MaxN = 200100;
const int Mod = 1e9 + 7;

int N;
int x[MaxN], y[MaxN], t[MaxN];

void load(){
  cin>>N;
  bool ok = 1;
  FOR(i,1, N+1){
    scanf("%d%d%d", t + i, x + i, y + i);
      int w = abs(x[i] - x[i - 1]) + abs(y[i] - y[i - 1]);
      if (w > t[i] - t[i - 1]) ok = 0;
      if ((t[i] - t[i - 1] + w) % 2 != 0) ok = 0; 
  }

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

int main(){
    load();	
    return 0;
}



Measured memory_bytes: 1408
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
#include <functional>
#include <iomanip>

using namespace std;

int dp[105][2][5];

int main() {
    string s;
    int k;
    cin >> s >> k;
    int n = s.size();
    
    dp[0][0][0] = 1;
    for(int i = 0; i < n; ++i){
        for(int sm = 0; sm < 2; ++sm){
            for(int j = 0; j < k + 1; ++j){
                for(int x = 0; x <= (sm ? 9 : s[i]-'0'); ++x){
                    dp[i + 1][sm || x < (s[i]-'0')][j+(x>0)] += dp[i][sm][j];          
                }
            }
        }
    }
    cout << dp[n][0][k] + dp[n][1][k];
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define repr(i,a,b) for(long long i=(long long)(a);i<(long long)(b);i++)
#define rep(i,n) repr(i,0,n)
#define reprrev(i,a,b) for(int i=(int)(b)-1;i>=(int)(a);i--)
#define reprev(i,n) reprrev(i,0,n)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define mp make_pair
#define mt make_tuple
#define MOD 1000000007
#define PI 3.1415926535
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> Pi;
typedef pair<ll, ll> Pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<Pi> vPi;
typedef vector<Pll> vPll;
typedef vector<vector<int>> vvi;
typedef vector<vector<bool>> vvb;
typedef vector<vector<ll>> vvll;
typedef vector<vector<char>> vvc;
typedef vector<vector<string>> vvs;
typedef vector<vector<double>> vvd;
typedef vector<vector<Pi>> vvPi;
typedef priority_queue<int, vector<int>, greater<int>> pqli;
typedef priority_queue<ll, vector<ll>, greater<ll>> pqlll;
typedef priority_queue<Pi, vector<Pi>, greater<Pi>> pqlP;
string YN(bool y) { return (y?"YES":"NO"); }
string yn(bool y) { return (y?"Yes":"No"); }
string ON(bool y) { return (y?"OK":"NG"); }
int main(void)
{
	int n, m, xx, yy;

	cin>>n>>m>>xx>>yy;

	vi x(n), y(m);

	rep(i, n) cin>>x[i];

	rep(i, m) cin>>y[i];

	sort(all(x)); sort(all(y));

	if(x[n-1]>=y[0]){
		cout<<"War"<<endl;
	} else{
		bool flag=false;
		repr(i, xx+1, yy+1){
			if(i>x[n-1]&&i<=y[0]){
				flag=true;
			}
		}
		if(flag){
			cout<<"No War"<<endl;
		} else{
			cout<<"War"<<endl;
		}
	}
	
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <cmath>
#define eps 1e-8
#define zero(x) (((x)>0?(x):-(x))<eps)

#define pause cout << " press ansy key to continue...",  cin >> chh
#define file_r(x) freopen(x,  "r",  stdin)
#define file_w(x) freopen(x,  "w",  stdout)
#define lowbit(x) ((x) & (-x))
#define repit(i, c) for (__typeof__((c).begin()) i = (c).begin(); i != (c).end(); i++)
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repe(i, u) for (int i = head[u]; i != -1; i = nxt[i])
#define repd(i, n) for (int i = (n - 1); i >= 0; i--)
#define FOR(i, n, m) for (int i = (n); i <= (m); i++)
#define FORD(i, n, m) for (int i = (n); i >= (m); i--)
#define pb push_back
#define X first
#define Y second
#define ins insert
#define rb rbegin
#define be begin
#define er erase
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define SZ(c) (c).size()
#define ALL(c) (c).begin(), (c).end()
#define sqr(r) ((LL) (r) * (r))
#define dis(x1, y1, x2, y2) (((x1) - (x2)) * ((x1) - (x2)) + ((y1) - (y2)) * ((y1) - (y2)))
#define FASTIO ios::sync_with_stdio(false);cin.tie(0)

#define sc(x) cout << #x" = " << x << endl, system("pause")
#define sc2(x, y) cout << #x" = " << x << " " << #y" = " << y << endl, system("pause")
#define sc3(x, y, z) cout << #x" = " << x << " " << #y" = " << y << " " << #z" = " << z << endl, system("pause")
#define sc4(x, y, z, w) cout << #x" = " << x << " " << #y" = " << y << " " << #z" = " << z << " " << #w" = " << w << endl, system("pause")

#define in(n) scanf("%d", &n)
#define in2(n, m) scanf("%d %d", &n, &m)
#define in3(x, y, z) scanf("%d %d %d", &x, &y, &z)

using namespace std;
int chh;

typedef vector<int> vi;
typedef set<int> si;
typedef map<int, int> mii;
typedef pair<int, int> pii;
typedef pair<int, pii> pi3;
typedef vector< pair<int, int> > vpii;
typedef long long LL;

const int N = 500005;

int n, m, e;
int a[N], c[N], pre[N];
int b[N], ans[N];

typedef pair<pii, int> piii;
piii q[N];

void update(int p, int v) {
	for (; p > 0; p -= lowbit(p)) b[p] += v;
}

int cal(int p) {
	int ans = 0;
	for (; p <= n; p += lowbit(p)) ans += b[p];
	return ans;
}

int main() {
	int now;
	while (~in2(n, m)) {
		e = 0;
		FOR (i, 1, n) in(a[i]), c[e++] = a[i];
		sort(c, c + e);
		e = unique(c, c + e) - c;
		FOR (i, 1, n) a[i] = lower_bound(c, c + e, a[i]) - c + 1;
		
		rep (i, m) in2(q[i].X.Y, q[i].X.X), q[i].Y = i;
		sort(q, q + m);
		
		memset(pre, -1, sizeof(pre));
		memset(b, 0, sizeof(b));
		now = 0;
		FOR (i, 1, n) {
			update(i, 1);
			if (pre[a[i]] != -1) update(pre[a[i]], -1);
			pre[a[i]] = i;
			while (now < m && q[now].X.X <= i) ans[q[now].Y] = cal(q[now].X.Y), now++;
		}
		rep (i, m) printf("%d\n", ans[i]);
	}
	return 0;
}


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

int main(){
  
  int k,x;
  cin >> k >> x;
  for(int i=x-k+1; i<x+k; i++){
    if(i==x+k-1){
      cout << i << endl;
      break;
    }
    cout << i << " " ;
    
    
  
  
  }

}



Measured memory_bytes: 256
//
// Created by 徳備彩人 on 2020/03/08.
//

#include <iostream>
#include <set>
#include <string>
using namespace std;

int main() {
    int n;
    string s;
    int q;
    set<int> pos[26];

    cin >> n;
    cin >> s;
    cin >> q;

    for (int i = 0;i < s.size(); i++) {
        pos[s[i]-'a'].insert(i+1);
    }
    for (int i = 0; i < q; i++) {
        int t;
        cin >> t;
        if (t == 1) {
            int j;
            char c;
            cin >> j >> c;
            for (auto & po : pos) {
                if (po.find(j) != po.end()) {
                    po.erase(j);
                }
            }
            pos[c-'a'].insert(j);
        } else {
            int l, r;
            cin >> l >> r;
            int x = 0;
            for (auto & po : pos) {
                auto it = po.find(l);
                if (it != po.end()) {
                    x += 1;
                } else {
                    it = po.upper_bound(l);
                    if (it != po.end() && *it <= r) {
                        x += 1;
                    }
                }
            }
            cout << x << endl;
        }
    }
}

Measured memory_bytes: 24196
#include <stdio.h>
using namespace std;

int main()
{
  int N;
  scanf("%d", &N);
  long long ans = (long long)N * (N + 1) - 1;
  int i = 2;
  while (i * i <= N)
  {
    int num, min_i;
    long long max_i;
    num = N / i;
    min_i = i * i;
    max_i = i * num;
    ans += (num - i + 1) * (min_i + max_i);
    ans -= min_i;
    i += 1;
  }
  printf("%lld", ans);
}


Measured memory_bytes: 1732
#include <iostream>
#include <fstream>
#include <vector>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;

  vector<vector<int>> matrix(n, vector<int>(m));
  vector<int> vec(m);
  vector<int> res(n);

  for(int i=0; i<n; i++) {
    for(int j=0; j<m; j++) {
      cin >> matrix.at(i).at(j);
    }
  }

  for(int i=0; i<m; i++) {
    cin >> vec.at(i);
  }

  for(int i=0; i<n; i++) {
    for(int j=0; j<m; j++) {
      res.at(i) += matrix.at(i).at(j)*vec.at(j);
    }
    cout << res.at(i) << "\n";
  }
  
  return 0;
}



Measured memory_bytes: 3160
#include <stdio.h>

int main(void)
{
    int N, i=1, sum=1;

    scanf("%d", &N);

    while (sum<N) sum += 1+i++;
    while (N>0) {
        if (N>=i) {
            printf("%d\n", i);
            N-=i;
        }
        i--;
    }

    return 0;
}


Measured memory_bytes: 128
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <fstream>
#include <sstream>
#include <set>
#include <map>
#include <vector>
#include <list>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <string>
#include <stack>
#include <queue>
#include <bitset>     //UWAGA - w czasie kompilacji musi byc znany rozmiar wektora - nie mozna go zmienic
#include <cassert>
#include <iomanip>        //do setprecision
#include <ctime>
#include <complex>
using namespace std;

#define FOR(i,b,e) for(int i=(b);i<(e);++i)
#define FORQ(i,b,e) for(int i=(b);i<=(e);++i)
#define FORD(i,b,e) for(int i=(b)-1;i>=(e);--i)
#define REP(x, n) for(int x = 0; x < (n); ++x)

#define ST first
#define ND second
#define PB push_back
#define PF push_front
#define MP make_pair
#define LL long long
#define ULL unsigned LL
#define LD long double
#define pii pair<int,int>
#define pll pair<LL,LL>

const double pi = 3.14159265358979323846264;
const int mod=1000000007;


//mod演算ライブラリ
//mod=1000000007

LL add(LL a,LL b){
  return (a+b)%mod;
}

LL sub(LL a,LL b){
  return (a+mod-b)%mod;
}

LL mul(LL a,LL b){
  return ((a % mod) * (b % mod)) % mod;
}

LL power(LL x,LL y){//繰り返し二乗法 単品利用可
  if(y==0)return 1;
  else if(y==1)return x%mod;
  else if(y%2==0){
    LL tmp=power(x, y/2) % mod;
    return tmp*tmp%mod;
  }else {
    LL tmp=power(x, y/2) % mod;
    return ((tmp*tmp)%mod)*x%mod;
  }
}

LL dvs(LL a,LL b){
  return mul(a,power(b,mod-2));
}

const int SIZE_mod=200005;
int invfact[SIZE_mod];
int fact[SIZE_mod];

LL factset(int a){//aまでの階乗%mod表を作成
  fact[0]=1;
  FORQ(i,1,a){
    fact[i]=mul(fact[i-1],i);
  }
}

LL cmbset(int a){//1~aまでの階乗と階乗数の逆元のmod(mod)を用意 O(a)
  factset(a);
  invfact[a]=power(fact[a],mod-2);
  invfact[0]=1;
  FORD(i,a,1){
    invfact[i]=mul(invfact[i+1],i+1);
  }

}

LL cmb(int n,int r){//nCr%mod  (cmbset後に使用)
  if(n<r||r<0||n<0)return 0;
  return mul(fact[n],mul(invfact[r],invfact[n-r]));
}

LL prm(int n,int r){//nPr%mod
    return mul(cmb(n,r),fact[n]);
}

LL homo(int n,int r){//nHr%mod
  return cmb(n+r-1,r);
}


int main(){
	 //cin.tie(0);
	//ios::sync_with_stdio(false);
	//std::cout << std::fixed;
	//std::cout << std::setprecision(12);
	//std::cout << std::defaultfloat;
	string s;
	cin>>s;
	int n=s.length();
	vector<LL> dp(n+1,0);
	vector<LL> dp2(n+1,0);
	if(s[n-1]=='0'){
		dp[n-1]=1;
		dp2[n-1]=2;
	}else{
		dp[n-1]=3;
	}
	FORD(i,n-1,0){
		if(s[i]=='0'){
			dp[i]=mul(1,add(dp[i+1],0));
			dp2[i]=add(mul(3,dp2[i+1]),mul(2,dp[i+1]));
		}else{
			dp[i]=add(mul(3,dp[i+1]),mul(1,dp2[i+1]));
			dp2[i]=mul(2,dp2[i+1]);
		}
	}
	cout<<dp[0]<<endl;

	return 0;
}


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

typedef long long ll;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef vector<pair<ll,ll>> vii;
typedef vector<vii> vvii;
typedef pair<ll,ll> ii;

#define pb push_back
#define mp make_pair
#define sz(vs) (ll)(vs.size())
#define rep(i,a,b) for (ll i=a;i<b;i++)
#define rep_(i,a,b) for (ll i=a;i>b;--i)
#define iter(i,c) for (auto i:c)
#define ss second
#define ff first
#define D(x) cout << '>' << #x << ':' << x << endl;
#define D2(x,a) cout << '>' << #x << ':' << x << " >" << #a << ':' << a <<  endl;
#define D3(x,a,b) cout << '>' << #x << ':' << x << " >" << #a << ':' << a << " >" << #b << ':' << b << endl;
#define D4(x,a,b,c) cout << '>' << #x << ':' << x << " >" << #a << ':' << a << " >" << #b << ':' << b << " >" << #c << ':' << c << endl;
#define PS(a,st,e) if (1) {if (st<e) {cout<<a[st];rep(noname,st+1,e) cout<<""<<a[noname];}cout<<"\n";}
#define PA1(a,st,e) if (1) {if (st<e) {cout<<a[st];rep(noname,st+1,e) cout<<" "<<a[noname];}cout<<'\n';}
#define PA(a,st,e) if (1) {cout<<#a<<": [";if (st<e) {cout<<a[st];rep(noname,st+1,e) cout<<", "<<a[noname];}cout<<"]\n";}
#define PSET(c) if (1) {cout<<#c<<": {";for (auto noname:c) cout<<noname<<",";cout<<"}\n";}
#define PM(c) if (1) {cout<<#c<<": {";for (auto noname:c) cout<<noname.first<<":"<<noname.second<<", ";cout<<"}\n";}

#define MAXN 200005
#define MAXK 10006
#define mod 1000000007

ll n, m, k, rem1[MAXN], rem_[MAXN], c1 = 0, f[MAXN], count1[MAXN];
char s[MAXN];
char c;

void find_rems() {
	rem1[0] = 1 % (c1+1);
	if (c1-1>0) rem_[0] = 1 % (c1-1);
	rep(i, 1, MAXN) {
		rem1[i] = (2 * rem1[i-1]) % (c1+1);
		if (c1-1>0) rem_[i] = (2 * rem_[i-1]) % (c1-1);
	}
}

void findfs() {
	count1[0]=0;
	count1[1]=1;
	rep(i, 2, MAXN) {
		if (i&1) count1[i] = count1[i-1] + 1;
		else count1[i] = count1[i/2];
	}
	f[0] = 0;
	f[1] = 1;
	rep(i, 2, MAXN) {
		f[i] = 1  + f[i%count1[i]];
	}
}

void solve() {
	cin>>n;
	rep_(i, n-1, -1) {
		cin>>s[i];
		if (s[i]-'0') c1++;
	}
	find_rems();
	findfs();
	ll r1 = 0, r_ = 0;
	rep_(i, n-1, -1) {
		if (s[i]-'0') {
			r1 = (r1 + rem1[i]) % (c1+1);
			if (c1-1>0) r_ = (r_ + rem_[i]) % (c1-1);
		}
	}
	rep_(i, n-1, -1) {
		if (s[i]=='0') {
			cout<<(1 + f[((r1+rem1[i])%(c1+1)+(c1+1))%(c1+1)])<<endl;
		}
		else {
			if (c1-1==0) cout<<0<<endl;
			else cout<<(1 + f[((r_-rem_[i])%(c1-1)+c1-1)%(c1-1)])<<endl;
		}
	}
}

void aux() {
}

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

Measured memory_bytes: 10068
#include <iostream>
#include<queue>
#include<stack>
#include<vector>
#include<set>
#include<map>
#include<algorithm>
#include<cstring>
#include<string>
#include<cassert>
#include<cmath>
#include<climits>
#include<iomanip>
#include<bitset>
#include<unordered_map>

using namespace std;

#define MOD 998244353
#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define rep(i,j,n) for(ll (i)=(j);(i)<(n);(i)++)
#define FOR(i,c) for(decltype((c).begin())i=(c).begin();i!=(c).end();++i)
#define ll long long
#define ull unsigned long long
#define all(hoge) (hoge).begin(),(hoge).end()
typedef pair<ll, ll> P;
const long long INF = 1LL << 60;
typedef vector<ll> Array;
typedef vector<Array> Matrix;


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

//グラフ関連
struct Edge {//グラフ
	ll to, cap, rev;
	Edge(ll _to, ll _cap, ll _rev) {
		to = _to; cap = _cap; rev = _rev;
	}
};
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;

void add_edge(Graph& G, ll from, ll to, ll cap, bool revFlag, ll revCap) {
	G[from].push_back(Edge(to, cap, (ll)G[to].size()));
	if (revFlag)G[to].push_back(Edge(from, revCap, (ll)G[from].size() - 1));
}

class RmqTree {
private:
	ll _find(ll a, ll b, ll k, ll l, ll r) {
		//区間[l,r)の最小値を持つk番目のノードを探索
		if (r <= a || b <= l)return INF;    // 交差しない
		if (a <= l && r <= b)return dat[k];   // 完全に含む
		else {
			ll s1 = _find(a, b, 2 * k + 1, l, (l + r) / 2); // 左の子
			ll s2 = _find(a, b, 2 * k + 2, (l + r) / 2, r); // 右の子
			return min(s1, s2);
		}
	}
public:
	ll n, height;
	vector<ll> dat;

	// 初期化（_nは最大要素数）
	RmqTree(ll _n) {
		n = 1;
		height = 1;
		while (n < _n) {
			n *= 2;
			height++;
		}
		dat = vector<ll>(2 * n - 1, INF);
	}

	// i番目の値(0-indexed)をxに変更
	void update(ll i, ll x) {
		i += n - 1; // i番目の葉ノードへ
		dat[i] = x;
		while (i > 0) { // 登りながら更新
			i = (i - 1) / 2;//親ノードのインデックス
			dat[i] = min(dat[i * 2 + 1], dat[i * 2 + 2]);
			//子ノードの小さい方の値を代入
		}
	}

	// 区間[a,b)の最小値の取得
	ll find(ll a, ll b) {
		return _find(a, b, 0, 0, n);
	}
};
int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);

	ll n, m;
	cin >> n >> m;
	vector<pair<P, ll>> lrc(m);
	REP(i, m) {
		cin >> lrc[i].first.first >> lrc[i].first.second >> lrc[i].second;
	}
	sort(all(lrc));

	RmqTree rmq(n+10);
	rmq.update(1, 0);
	REP(i, m) {
		ll l = lrc[i].first.first;
		ll r = lrc[i].first.second;
		ll c = lrc[i].second;
		ll min = rmq.find(l, r);
		//cout <<l<<" "<<r<<" "<< min<<" " << c << endl;
		if (rmq.find(r,r+1)>min+c) {
			rmq.update(r, min + c);
		}
	}

	ll ans = rmq.find(n,n+1);
	if (ans == INF) {
		cout << -1 << endl;
	}
	else {
		cout << ans << endl;
	}


	return 0;
}

Measured memory_bytes: 4608
#include <iostream>
#include <string>
#include <utility>
#include <stack>
#include <vector>
#include <queue>
#include <algorithm>
#include <map>
#include <climits>
#include <set>
#include <numeric>
#include <iomanip>
#include <cmath>
#include <cstring>
using namespace std;
string grid[50];
int d[50][50];
int move_h[4] = {0, 1, -1, 0};
int move_w[4] = {1, 0, 0, -1};
int main(){
  int H;
  int W;
  cin >> H >> W;
  for(int i = 0; i < H; i++){
    cin >> grid[i];
  }

  int black_num = 0;
  for(int i = 0; i < H; i++){
    for(int j = 0; j < W; j++){
      if(grid[i][j] == '#'){
        black_num ++;
      }
    }
  }

  for(int i = 0; i < H; i++){
    for(int j = 0; j < W; j++){
      d[i][j] = INT_MAX;
    }
  }

  d[0][0] = 0;
  queue <pair <int, int> > q;
  q.push(make_pair(0, 0));
  while(!q.empty()){
    auto cur = q.front();
    q.pop();
    int cur_h = cur.first;
    int cur_w = cur.second;

    for(int i = 0; i < 4; i++){
      int next_h = cur_h + move_h[i];
      int next_w = cur_w + move_w[i];
      if(0 <= next_h && next_h < H && 0 <= next_w && next_w < W 
          && grid[next_h][next_w] !='#' && d[next_h][next_w] == INT_MAX){
        d[next_h][next_w] = d[cur_h][cur_w] + 1;
        q.push(make_pair(next_h, next_w));
      }
    }
  }

  if(d[H - 1][W - 1] == INT_MAX){
    cout << - 1 << endl;
  } else {
    cout << W * H - (d[H - 1][W - 1] + 1) - black_num << endl;

  }


  return 0;
}


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

#define MOD 1000000007
#define mi 18446744073709551615
 
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n,k,c=0;
    cin>>n>>k;
    map <int,int> m;
    for(int i=0;i<k;i++)
    {
        int d;
        cin>>d;
        for(int j=0;j<d;j++)
        {
            int tem;
            cin>>tem;
            m[tem]++;
        }
    }
    for(int i=1;i<=n;i++)
    {
        if(!m[i])
            c++;
    }
    cout<<c;
    return 0;
}

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

// #define int long long
#define rep(i, n) for (long long i = (long long)(0); i < (long long)(n); ++i)
#define reps(i, n) for (long long i = (long long)(1); i <= (long long)(n); ++i)
#define rrep(i, n) for (long long i = ((long long)(n)-1); i >= 0; i--)
#define rreps(i, n) for (long long i = ((long long)(n)); i > 0; i--)
#define irep(i, m, n) for (long long i = (long long)(m); i < (long long)(n); ++i)
#define ireps(i, m, n) for (long long i = (long long)(m); i <= (long long)(n); ++i)
#define SORT(v, n) sort(v, v + n);
#define REVERSE(v, n) reverse(v, v+n);
#define vsort(v) sort(v.begin(), v.end());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
#define replace_all(s, b, a) replace(s.begin(),s.end(), b, a);
#define PI (acos(-1))
#define FILL(v, n, x) fill(v, v + n, x);
#define sz(x) long long(x.size())

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vs = vector<string>;
using vpll = vector<pair<ll, ll>>;
using vtp = vector<tuple<ll,ll,ll>>;
using vb = vector<bool>;

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 ll INF = 1e9;
const ll MOD = 1e9+7;
const ll LINF = 1e18;

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

ll ngcd(vector<ll> a) {
  ll res = a[0];
  for(ll i=1; i<a.size() && res!=1; i++) res = gcd(a[i], res);
  return res;
}
ll nlcm(vector<ll> a){
  ll res = a[0];
  for(ll i=1; i<a.size(); i++) res = lcm(a[i], res);
  return res;
}
bool is_prime(ll n) {
  if(n < 2) return false;
  for (ll i = 2; i * i <= n; i++) if (n % i == 0) return false;
  return true;
}
ll digsum(ll n) {
  ll res=0;
  while(n) res += n%10, n /= 10;
  return res;
}
ll digcnt(ll n){
  ll res=0;
  while(n) res++, n /= 10;
  return res;
}
vector<ll> divisor(ll n) {
  vector<ll> res;
  for (ll i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      res.push_back(i);
      if (i != n / i) res.push_back(n / i);
    }
  }
  sort(res.begin(), res.end());
  return res;
}
map<ll, ll> prime_factor(ll n) {
  map<ll, ll> res;
  for (ll i = 2; i * i <= n; i++) {
    while (n % i == 0) ++res[i], n /= i;
  }
  if (n != 1) res[n] = 1;
  return res;
}

signed main()
{
  cin.tie( 0 ); ios::sync_with_stdio( false );
  ll n,p; cin>>n>>p;
  auto m=prime_factor(p);
  ll ans=1;
  for(auto e: m){
    if(e.second>=n){
      ans*=round(pow(e.first,(e.second/n)));
    }
  }
  cout<<ans<<endl;
  
}

Measured memory_bytes: 256
#include <string>
#include <queue>
#include <stack>
#include <vector>
#include <sstream>
#include <algorithm>
#include <deque>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <list>
#include <cstdio>
#include <iostream>
#include <cmath>
#include <climits>
#include <bitset>
#include <functional>
#include <numeric>
#include <ctime>
#include <cassert>
#include <cstring>
#include <fstream>

#define FOR(i, a, b) for(int (i)=(a); (i)<(b); (i)++)
#define IFOR(i, a, b) for(int (i)=(a);(i)<=(b);(i)++)
#define RFOR(i, a, b) for(int (i)=(a);(i)>=(b);(i)--)

using namespace std;

int main() {
	int n, a, b;
	cin >> n >> a >> b;
	string s;
	cin >> s;
	int tuuka = 0, kaigai = 0;
	FOR(i, 0, s.size()) {
		bool result = false;
		if (s[i] == 'a') {
			result = (tuuka < a+b);
			if(result) tuuka++;
		}
		else if (s[i] == 'b') {
			result = (tuuka < a + b && kaigai < b);
			if (result) tuuka++, kaigai++;
		}
		cout << (result ? "Yes" : "No") << endl;
	}
	return 0;
}

Measured memory_bytes: 896
#include <iostream>
#include <sstream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>

using namespace std;

#define FOR(i,k,n) for(int i=(k); i<(int)(n); ++i)
#define REP(i,n) FOR(i,0,n)
#define FORIT(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)

template<class T> void debug(T begin, T end){ for(T i = begin; i != end; ++i) cerr<<*i<<" "; cerr<<endl; }
inline bool valid(int x, int y, int W, int H){ return (x >= 0 && y >= 0 && x < W && y < H); }

typedef long long ll;
const int INF = 100000000;
const double EPS = 1e-8;
const int MOD = 1000000007;
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
struct Result{
  bool value;
  int p;
  Result(bool b, int p) : value(b), p(p) {}
};
int S;
Result expr(const string& s, int p);
Result factor(const string& s, int p);
bool is_ope(char c){
  string s = "*+-";
  REP(i, s.size()) if(c == s[i]) return true;
  return false;
}
Result expr(const string& s, int p){
  Result r = factor(s, p);
  while(is_ope(s[r.p])){
    if(s[r.p] == '-') assert(s[r.p + 1] == '>');
    Result r_ = factor(s, (s[r.p] == '-') ? r.p + 2 : r.p + 1);
    if(s[r.p] == '*'){
      r.value = r.value && r_.value;
    }else if(s[r.p] == '+'){
      r.value = r.value || r_.value;
    }else {
      r.value = !r.value || r_.value;
    }
    r.p = r_.p;
  }
  return r;
}
Result factor(const string& s, int p){
  if(s[p] == '('){
    Result r = expr(s, p + 1);
    assert(s[r.p] == ')');
    r.p ++;
    return r;
  }else if(islower(s[p])){
    return Result((S >> (s[p] - 'a')) & 1, p + 1);
  }else if(s[p] == 'T'){
    return Result(true, p + 1);
  }else if(s[p] == 'F'){
    return Result(false, p + 1);
  }else if(s[p] == '-'){
    Result r = factor(s, p + 1);
    r.value ^= 1;
    return r;
  }else {
    assert(false);
  }
}

int main(){
  string s;
  while(cin >> s && s != "#"){
    string a, b;
    REP(i, s.size()) if(s[i] == '='){
      a = s.substr(0, i);
      b = s.substr(i + 1);
    }
    bool equal = true;
    for(S = 0; S < 1<<10; S++){
      if(expr(a, 0).value != expr(b, 0).value) equal = false;
    }
    if(equal) cout << "YES" << endl;
    else cout << "NO" << endl;
  }
  return 0;
}

Measured memory_bytes: 1236
/*
AuThOr GaRyMr
技巧:
1.区别对待大数据&小数据！
2.Dp难推时算贡献！
3.long long (尤其乘法)！
4.long long INF 要大
5.Dp on trees: 换根法，每次清空当前的节点和换到的子节点
6.long double | 输出浮点数
7.注意特判!(prince and princess)
*/
#include<bits/stdc++.h>
#define rb(a,b,c) for(int a=b;a<=c;++a)
#define rl(a,b,c) for(int a=b;a>=c;--a)
#define niv vector<int>
#define LL long long
#define IT iterator
#define PB push_back
#define II(a,b) make_pair(a,b)
#define FIR first
#define SEC second
#define FREO freopen("check.out","w",stdout)
#define rep(a,b) for(int a=0;a<b;++a)
#define KEEP while(1)
#define SRAND mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())
#define random(a) rng()%a
#define ALL(a) a.begin(),a.end()
using namespace std;
const int INF=0x3f3f3f3f;
typedef pair<int,int> mp;
typedef pair<mp,mp> superpair;
int n;mp A[100000+10];mp B[100000+10]; 
vector<int> each[100000+10];
int res=0,degree[100000+10];
bool check(){
	queue<int> Q;
	rb(i,1,n)
		for(auto it:each[i]) degree[it]++;
	int tmp=0;
	rb(i,1,n)
		if(degree[i]);
		else Q.push(i),tmp++;
	while(!Q.empty())
		{
			int now=Q.front();
			Q.pop();
			for(auto it:each[now]){
				degree[it]--;
				if(degree[it]==0)
					Q.push(it),tmp++;
			}
				
		}
	return tmp!=n;
}
int main(){
	cin>>n;
	rb(i,1,n)
		cin>>A[i].FIR,A[i].SEC=i;
	rb(i,1,n) cin>>B[i].FIR,B[i].SEC=i;
	sort(A+1,A+1+n);
	sort(B+1,B+1+n);
	rb(i,1,n)
		if(A[i].FIR>B[i].FIR)
			{
				puts("No");
				return  0;}else if(i!=n)each[A[i].SEC].PB(B[i].SEC);
	rb(i,1,n-1)
		if(A[i+1].FIR<=B[i].FIR){
			puts("Yes");
			return 0;
		}
	
	cout<<(check()? "Yes":"No");
	return 0;
}


Measured memory_bytes: 7680
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0;i<int(N);++i)
using i64 = int64_t;
using ll = long long;
int main() {
  string S;
  cin >> S;
  if(S.at(2) == S.at(3) && S.at(4) == S.at(5)){
    cout << "Yes" <<endl;
  }
  else{
    cout << "No" << endl;
  }
  return 0;
}



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

int main() {
  int N;
  cin >> N;
  vector<double> v(N);
  
  rep(i,N){
    cin >> v.at(i);
  }
  
  sort(v.begin(),v.end());
  
  rep(i,N-1){
    v.at(i+1) = ( v.at(i) + v.at(i+1) )/2;
  }
  
  cout << fixed << setprecision(10);
  cout << v.at(N-1) << endl;
  
  return 0;
}


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

using ll = long long;

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i <= (n); ++i)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
#define ddrep(i, n) for (int i = n; i > 0; --i)
#define srep(i, s, t) for (int i = s; i < t; ++i)
#define ssrep(i, s, t) for (int i = s; i <= t; ++i)

#define rng(a) a.begin(), a.end()
#define pb push_back
#define eb emplace_back
#define fi first
#define se second

#define chmax(x, y) (x = max(x, y))
#define chmin(x, y) (x = min(x, y))

using pi = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using ld = long double;

template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  os << "(" << p.first << "," << p.second << ")";
  return os;
}

template <class T> ostream &operator<<(ostream &os, const vector<T> &v) {
  os << "{";
  rep(i, (int)v.size()) {
    if (i)
      os << ",";
    os << v[i];
  }
  os << "}";
  return os;
}

template <typename T, size_t S> void printArray(const T (&array)[S]) {
  for (auto val : array)
    std::cout << val << ", ";
  std::cout << "\n";
}

const int mod = 1e9 + 7;
const int inf = 1e9 + 5;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << std::setprecision(10);

  int n; std::cin >> n;
  vi cnt(100'000+5);
  rep(i, n) {
    int a; std::cin >> a; a++;
    cnt[a-1]++;
    cnt[a]++;
    cnt[a+1]++;
  }
  int ans = *max_element(rng(cnt));
  std::cout << ans << "\n";
}


Measured memory_bytes: 640
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.HashSet;

public class Main
{
	public static void main(String[] Arguments) throws IOException 
	{
		BufferedReader BR = new BufferedReader(new InputStreamReader(System.in));
		int N = Integer.parseInt(BR.readLine()); HashSet<String> Items = new HashSet<>();
		for (; N > 0; N--)
		{
			Items.add(BR.readLine());
		}
		System.out.println(Items.size());
	}
}


Measured memory_bytes: 59136
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <vector>
using namespace std;

#define pb push_back
#define ri(x) scanf("%d",&x)
#define rii(x,y) ri(x),ri(y)
#define ms(obj,val) memset(obj,val,sizeof(obj))
#define ms2(obj,val,sz) memset(obj,val,sizeof(obj[0])*sz)
#define FOR(i,f,t) for(int i=f;i<(int)t;i++)
#define FORR(i,f,t) for(int i=f;i>(int)t;i--)

typedef long long ll;
typedef vector<int> vi;

const int MAXN = 2e5 + 10;

string str;
ll ans = 1;
int N,cnt[300];

int main() {
	cin >> str;
	N = str.length();
	ms(cnt,0);
	FOR(i,0,N) {
		ans += i - cnt[str[i]];
		cnt[str[i]]++;
	}
	printf("%lld\n",ans);
}


Measured memory_bytes: 640
//#define DEBUG
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>

int N;
int F[100][10];
int P[100][11];
int sel[10] = {0};
long long max=-9000000000000000000;

void maxPrice(int v) {
	int i, j;
	if (v != -1) {
		sel[v] = 1;
		/*
		for (i = 0; i < 10; i++) {
			printf("%d ", select[i]);
		}
		printf("\n");
		//*/
		int s[100] = { 0 };
		for (i = 0; i < 10; i++) {
			if (sel[i] == 1) {
				for (j = 0; j < N; j++) {
					if (F[j][i] == 1)s[j]++;
				}
			}
		}
		long long p = 0;
		for (i = 0; i < N; i++) {
			//printf("%d ", s[i]);
			//printf("P[%d][%d]=%d", i, s[i], P[i][s[i]]);
			p += P[i][s[i]];
		}
		if (max < p)max = p;
		//printf("max=%lld\n", max);
	}
	for (i = v + 1; i < 10; i++) {
		maxPrice(i);
	}
	if (v != -1)sel[v] = 0;
}

int main() {
#ifdef DEBUG

#endif

	scanf("%d", &N);
	int i,j;
	for (i = 0; i < N; i++) {
		for (j = 0; j < 10; j++) {
			scanf("%d", &F[i][j]);
		}
	}
	for (i = 0; i < N; i++) {
		for (j = 0; j < 11; j++) {
			scanf("%d", &P[i][j]);
		}
	}

	maxPrice(-1);
	printf("%d\n", max);
}

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

int main() {
    int n, b;
    string a;
    cin >> n;
    vector<tuple<string, int, int>> A(n);
    for(int i = 0; i < n; i++) {
        cin >> a >> b;
        A[i] = make_tuple(a, -b, i + 1);
    }
    sort(A.begin(), A.end());

    for(int i = 0; i < n; i++) {
        tie(ignore, ignore, b) = A[i];
        cout << b << endl;
    }


    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <complex>
#include <algorithm>
#include <string>
#include <cstring>
#include <cstdlib>

using namespace std;

typedef complex<int> P;

const int base=10000;
bool isOverFlow;
P analyze(string s){
  //cout<<s<<endl;
  if(s.size()==1&&s[0]=='i')return P(0,1);
  if(s[0]>='0'&&s[0]<='9'){
    bool ok=true;
    for(int i=0;i<s.size();i++)
      if(!(s[i]>='0'&&s[i]<='9'))ok=false;
    if(ok){
      int keta=1;
      for(int j=0;j<s.size();j++){
	if(s[j]!='0'){
	  keta=max(keta,(int)s.size()-j);
	  break;
	}
      }
      if(keta>=6){
	isOverFlow=true;
	return P();
      }
      int num=atoi(s.c_str());
      if(num>base){
	isOverFlow=true;
	return P();
      }
      return P(num,0);
    }
  }
  else if(s[0]=='-'){
    if(s.size()==2&&s[1]=='i')return P(0,-1);
    bool ok=true;
    for(int i=1;i<s.size();i++)
      if(!(s[i]>='0'&&s[i]<='9'))ok=false;
    if(ok){
      int keta=1;
      for(int j=1;j<s.size();j++){
	if(s[j]!='0'){
	  keta=max(keta,(int)s.size()-j-1);
	  break;
	}
      }
      if(keta>=6){
	isOverFlow=true;
	return P();
      }
      int num=atoi(s.c_str());
      if(abs(num)>base){
	isOverFlow=true;
	return P();
      }
      return P(num,0);
    }
  }
  if(s[0]=='('){
    int par=1;
    bool ok=true;
    for(int i=1;i<s.size()-1;i++){
      if(s[i]=='(')par++;
      else if(s[i]==')')par--;
      if(par==0)ok=false;
    }
    if(ok&&par==1){
      return analyze(s.substr(1,s.size()-2));
    }
  }
  int par=0;
  for(int i=s.size()-1;i>=1;i--){
    if(s[i]==')')par++;
    else if(s[i]=='(')par--;
    else if(par==0){
      if(s[i]=='+'||s[i]=='-'){
	P p1=analyze(s.substr(0,i));
	P p2=analyze(s.substr(i+1));
	if(abs(p1.real())>base||abs(p2.real())>base
	   ||abs(p1.imag())>base||abs(p2.imag())>base){
	  isOverFlow=true;
	  return P();
	}
	P p3;
	if(s[i]=='+')p3=p1+p2;
	else p3=p1-p2;
	if(abs(p3.real())>base||abs(p3.imag())>base){
	  isOverFlow=true;
	  return P();
	}
	return p3;
      }
    }
  }
  par=0;
  for(int i=s.size()-1;i>=0;i--){
    if(s[i]==')')par++;
    else if(s[i]=='(')par--;
    else if(par==0){
      if(s[i]=='*'){
	P p1=analyze(s.substr(0,i));
	P p2=analyze(s.substr(i+1));
	if(abs(p1.real())>base||abs(p2.real())>base
	   ||abs(p1.imag())>base||abs(p2.imag())>base){
	  isOverFlow=true;
	  return P();
	}
	P p3=p1*p2;
	if(abs(p3.real())>base||abs(p3.imag())>base){
	  isOverFlow=true;
	  return P();
	}
	return p3;
      }
    }
  }
  return P();
}

int main(){

  string s;
  while(getline(cin,s)){
    isOverFlow=false;
    for(int i=1;i<s.size();i++){
      if(s[i]=='i'&&s[i-1]>='0'&&s[i-1]<='9')
	s=s.substr(0,i)+"*"+s.substr(i);
    }
    P res=analyze(s);
    if(isOverFlow)cout<<"overflow"<<endl;
    else{
      if(res.imag()==0&&res.real()==0)cout<<0<<endl;
      else{
	if(res.real()!=0)cout<<res.real();
	if(res.imag()!=0){
	  if(res.imag()<0)cout<<res.imag()<<"i";
	  else{
	    if(res.real()!=0)cout<<"+";
	    cout<<res.imag();
	    cout<<"i";
	  }
	}
	cout<<endl;
      }
    }
  }

  return 0;
}

Measured memory_bytes: 0
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>
#include<stack>
#include<queue>
#include<vector>
#include<algorithm>
#include<string>
#include<iostream>
#include<set>
#include<map>
#include<bitset>

using namespace std;
typedef long long ll;
#define i_7 1000000007
#define i_5 1000000005

ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    else return c+i_7;
}
typedef pair<int,int> i_i;
typedef pair<ll,ll> l_l;
#define inf 100000000/*10^8*/
#define rep(i,l,r) for(int i=l;i<=r;i++)

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


int main(){
    ll n,a,b,c,d;cin>>n>>a>>b>>c>>d;
    bool flag=false;
    rep(k,0,n-1){
        if(-k*d+(n-1-k)*c<=b-a&&b-a<=(n-1-k)*d-k*c)flag=true;
    }
    if(flag)cout<<"YES";
    else cout<<"NO";
    
    return 0;
}



Measured memory_bytes: 256
#include <iostream>

using namespace std;

typedef long long ll;

ll a[100005];
ll b[100005];

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

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

  ll ans = 0;

  for(int i = 0; i < n; i++) {
    if((k | a[i]) == k) ans += b[i];
  }
 
  for(int  i = 1; i < 30; i++) {
    ll s = (1ll << i);
    ll K = k;
    ll tmp = 0;
    if(k & s) {
      K >>= i;
      K <<= i;
      K--;
      for(int j = 0; j < n; j++) {
	if((K | a[j]) == K) tmp += b[j];
      }
      ans = max(ans,tmp);
    }
  }
  cout << ans << endl;
}
      


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

bool isPalin(string s) {
  for (int i = 0; i < s.size()/2; i++) {
	  int j = s.size() - i - 1;
	  if (s[i] != s[j]) {
		  return false;
	  }
  }
  return true;
}

int main(){
  string S;
  cin >> S;
  int len = S.size();
  bool ans = isPalin(S) && isPalin(S.substr(0, (len-1)/2)) && isPalin(S.substr((len+1)/2, (len-1)/2));

  if (ans)	cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}


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

#define fastIO ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
typedef long long ll ;
typedef long double ld ;

const ll MOD = 1E9 + 7, INF = 2E18 + 5 ;
const double PI = 2 * acos(0.0) ;
const long double EPS = 1.0E-14 ;

vector <char> vec ;

int main()
{
    ll n, val, kar, flag = 0 ;
    cin >> n ;
    while (n > 26) {
        val = n / 26 ;
        kar = n % 26 ;
        n = val ;
        if (kar == 0) {
            vec.push_back('z') ;
            n-- ;
        }
        else    vec.push_back('a' + (kar - 1)) ;
    }
    vec.push_back('a' + (n - 1)) ;
    for (int i = vec.size() - 1; i >= 0; i--) {
        cout << vec[i] ;
    }

    return 0 ;
}


Measured memory_bytes: 3636
n,c=map(int,input().split())
xv=[list(map(int,input().split())) for _ in range(n)]
l,r,lret,rret=[],[],[],[]
sl,sr=0,0
for i in range(n):
    sl+=xv[i][1]
    sr+=xv[n-i-1][1]
    l.append(sl-xv[i][0])
    lret.append(sl-2*xv[i][0])
    r.append(sr-(c-xv[n-i-1][0]))
    rret.append(sr-2*(c-xv[n-i-1][0]))
for i in range(1,n):
    lret[i]=max(lret[i],lret[i-1])
    rret[i]=max(rret[i],rret[i-1])
ans=max(0,max(l),max(r))
#print(l)
#print(r)
#print(lret)
#print(rret)
for i in range(n-1):
    ans=max(ans,l[i]+rret[n-i-2],r[i]+lret[n-i-2])
print(ans)

Measured memory_bytes: 43764
#!/usr/bin/env python

from collections import deque

while True:
    n = input()
    if n == 0:
        break
    dq = deque()

    lst = []
    for i in range(n):
        hoge = raw_input().split(" ")
        lst.append(hoge)
    gamma = raw_input()
    delta = raw_input()
    m = {}
    dq.append(gamma)
    num = 0
    while len(dq) > 0:
        sz = len(dq)
        for loop in range(sz):
            S = dq.popleft()
            if S in m:
                continue
            if len(S) > 10:
                continue
            m[S] = num
            for l in lst:
                SS = S.replace(l[0], l[1])
                dq.append(SS)
        num += 1
    
    if delta in m:
        print m[delta]
    else:
        print "-1"


Measured memory_bytes: 5752
import java.util.Scanner;
import java.util.Arrays;
public class Main {
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        
        int N=sc.nextInt();
        long[] C=new long[N-1];
        long[] S=new long[N-1];
        long[] F=new long[N-1];
        for(int i=0;i<N-1;i++){
            C[i]=sc.nextInt();
            S[i]=sc.nextInt();
            F[i]=sc.nextInt();
        }
        
        long[] t=new long[N];
        for(int i=0;i<N;i++){
            t[i]=0;
        }
        
        for(int q=0;q<N-1;q++){
            for(int i=q;i<N-1;i++){
                if(t[q]<=S[i]){
                    t[q]=S[i]+C[i];
                }else if(t[q]%F[i]==0){
                    t[q]+=C[i];
                }else{
                    t[q]=(t[q]/F[i]+1)*F[i]+C[i];
                }
            }
        }
        
        for(int i=0;i<N;i++){
            System.out.println(t[i]);
        }
    }
}


Measured memory_bytes: 26440
#include <iostream>
#include <cassert>
#include <climits>
#include <bitset>
#include <stack>
#include <queue>
#include <iomanip>
#include <limits>
#include <string>
#include <cmath>
#include <set>
#include <map>
#include <math.h>
#include <algorithm>
#include <vector>
#include <string.h>
 
using namespace std;
typedef long long ll;
 
 
typedef pair<ll,ll> P;
long long int INF = 1e18;
double Pi = 3.141592653589;
long long int mod = 1000000007;
// memset(a,0,sizeof(a)); →全部０にする
 
vector<ll> G[100005];
vector<P> tree[100010];
priority_queue <ll> pql;
priority_queue <P> pqp;
//big priority queue
priority_queue <ll,vector<ll>,greater<ll> > pqls;
priority_queue <P,vector<P>,greater<P> > pqps;
//small priority queue
//top pop

int dx[8]={1,0,-1,0,1,1,-1,-1};
int dy[8]={0,1,0,-1,1,-1,-1,1};
//↓,→,↑,←
 
#define p(x) cout<<x<<endl;
#define el cout<<endl;
#define pe(x) cout<<x<<" ";
#define ps(x) cout<<fixed<<setprecision(25)<<x<<endl;
#define pu(x) cout<<x;
#define re(i,a,b) for(i=a;i<=b;i++);
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define deba(x) cout<< #x << " = " << x <<endl

ll rui(ll abc,ll bed){
	//aのb乗を計算する
	if(bed==0){return 1;}
	else{
		ll ced = rui(abc,bed/2);
		ced *= ced;
		ced %= mod;
		if(bed%2==1){ced*=abc; ced%=mod;}
		return ced;
	}
} 

ll i,j,k,ii,jj;
ll n,m,num,sum;
ll ans;
ll a,b,c,d,e,f,g,h,w,v;
char s[500][500];
ll x[800005],y[800005],z[900005];
ll ma1[500005],ma2[500005];

int main(){	
	cin>>n;
	m = (1<<n);
	for(i=0;i<m;i++){
		cin>>x[i];
		ma1[i] = x[i];
	}
	for(j=0;j<n;j++){
		for(i=0;i<m;i++){
			if(!(i & (1<<j))){
				y[0] = ma1[i^(1<<j)];
				y[1] = ma2[i^(1<<j)];
				y[2] = ma1[i];
				y[3] = ma2[i];
				sort(y,y+4);
				ma1[i^(1<<j)] = y[3];
				ma2[i^(1<<j)] = y[2];
			}
		}
	}
	for(i=1;i<m;i++){
		ans = max(num,ma1[i]+ma2[i]);
		num = ans;
		p(ans);
	}
	return 0;
}

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

#define rep(i,n) for(int i=0;i<(n);++i)
#define int long long
#define pb push_back
#define m_p make_pair
#define m_t meke_tuple
#define all(a) a.begin(),a.end()
#define SORT(a) sort(all(a))
#define debg(a) cout<<#a<<" "<<a<<endl;
#define call(a) for(auto i:a)cout<<i<<" ";cout<<endl
#define out(a) cout<<(a)<<endl;
typedef long long ll;
typedef string str;
typedef vector<int> V;
typedef pair<int,int> P;
typedef vector<P> VP;
const int INF = 1LL<<60;
const int MOD = 1e9+7;
int gcd(int a,int b){if(b==0)return a;return gcd(b,a%b);}
int lcm(int a,int b){return a/gcd(a,b)*b;}

signed main(){
    int n;
    cin>>n;
  str s;
  cin>>s;
  int r=0,b=0;
  rep(i,s.length()){
      if(s[i]=='R')r++;
      else b++;
  }
  if(r>b)cout<<"Yes";
  else cout<<"No";
  
  
  
  
  return 0;
}


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

signed main(){
	int n;
    cin>>n;
    string s;
    cin>>s;
    vector<int> r;
    vector<int> w;
    for(int i=0;i<n;i++){
    	if(s[i]=='W') w.push_back(i);
	}
    for(int i=n-1;i>=0;i--){
    	if(s[i]=='R') r.push_back(i);
	}
	int ans=0;
	int m=min(r.size(),w.size());
	for(int i=0;i<m;i++){
    	if(w[i]<r[i]) ans++;
	}
	cout<<ans;
	return 0;
}


Measured memory_bytes: 4500
package main

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

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
	scanner.Scan()
	var n int
	fmt.Sscanf(scanner.Text(), "%d", &n)

	as := make([]int, n/2)
	bs := make([]int, n/2)
	for i := 0; i < n; i++ {
		scanner.Scan()
		if i%2 == 0 {
			fmt.Sscanf(scanner.Text(), "%d", &as[i/2])
		} else {
			fmt.Sscanf(scanner.Text(), "%d", &bs[i/2])
		}
	}

	mpA := make(map[int]int)
	for _, val := range as {
		mpA[val]++
	}
	mpB := make(map[int]int)
	for _, val := range bs {
		mpB[val]++
	}

	// find 1st/2dn mode
	fstA := -1
	fstCntA, sndCntA := 0, 0
	for num, count := range mpA {
		if count > fstCntA {
			fstA = num
			fstCntA, sndCntA = count, fstCntA
		} else if count > sndCntA {
			sndCntA = count
		}
	}

	fstB := -1
	fstCntB, sndCntB := 0, 0
	for num, count := range mpB {
		if count > fstCntB {
			fstB = num
			fstCntB, sndCntB = count, fstCntB
		} else if count > sndCntB {
			sndCntB = count
		}
	}

	var ans int
	if fstA != fstB {
		ans = (n/2 - fstCntA) + (n/2 - fstCntB)
	} else {
		if fstCntA > fstCntB {
			ans = (n/2 - fstCntA) + (n/2 - sndCntB)
		} else if fstCntA < fstCntB {
			ans = (n/2 - sndCntA) + (n/2 - fstCntB)
		} else {
			// fstCntA == fstCntB
			if sndCntA > sndCntB {
				ans = (n/2 - sndCntA) + (n/2 - fstCntB)
			} else if sndCntA < sndCntB {
				ans = (n/2 - fstCntA) + (n/2 - sndCntB)
			} else {
				// sndCntA == sndCntB
				ans = (n/2 - sndCntA) + (n/2 - fstCntB)
			}
		}
	}
	fmt.Println(ans)
}


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

vector<vector<int>> arr;
vector<vector<int>> dp;
int solve(int N, int prev = -1, int row = 0)
{
    if (row == N)
        return 0;
    if (prev != -1 && dp[row][prev] != -1)
        return dp[row][prev];
    int res = 0;
    for (int i = 0; i < 3; i++)
    {
        if (i == prev)
            continue;
      
        res = max(res, arr[row][i] + solve(N, i, row + 1));
        // dp[row][i] = res;
    }
    if (prev == -1)
        return res;
    dp[row][prev] = res;
    return res;
}

int main()
{
    int N;
    cin >> N;
    arr = vector<vector<int>>(N, vector<int>(3));
    dp = vector<vector<int>>(N, vector<int>(3, -1));
    for (int i = 0; i < N; i++)
    {
        for (int j = 0; j < 3; j++)
        {
            cin >> arr[i][j];
        }
    }
    cout << solve(N);
}

Measured memory_bytes: 21916
#include <iostream>
#define REP(i, a, n) for(int i = (a); i < (n); i++)
using namespace std;

int N;
int sum[2000];

int main(void) {
  REP(i, 0, 1001) sum[i] = i;
  REP(i, 1, 1001) sum[i] += sum[i - 1];

  while(cin >> N, N) {
    int ans = 0;
    REP(i, 0, N) REP(j, i + 1, N) {
      if(sum[j] - sum[i] == N) ans++;
    }
    cout << ans << endl;
  }

  return 0;
}

Measured memory_bytes: 3056
#include"bits/stdc++.h"
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REPS(i,n) for(int i=1, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
using ll = long long;
using namespace std;
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<typename A, size_t N, typename T> void Fill(A (&array)[N], const T &val) { std::fill( (T*)array, (T*)(array+N), val ); }
#define INF 1e9
#define PI (acos(-1))
#define mod (int)1e9+7
int main() {
    string s, t;
    cin >> s >> t;
    int ans = 0;
    REP(i, s.size()) {
        if (s[i] != t[i])ans++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3916