akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define finish(x) return cout << x << endl, 0
#define ll long long

const int N = 305;

int n, c[N][N][N], dp[N][N][N], f[N][N], mod = 998244353;
string s;

void go(int idx, int z, int o){
    if(c[idx][z][o]) return;
    c[idx][z][o] = 1;
    if(z >= 2) go(idx, z - 1, o);
    if(o >= 2) go(idx, z, o - 1);
    if(o >= 1 && z >= 1){
        go(idx, z - 1, o);
        go(idx, z, o - 1);
    }
    if(idx < n && s[idx] == '1' && z){
        go(idx + 1, z, o);
        go(idx + 1, z - 1, o + 1);
    }
    if(idx < n && s[idx] == '0' && o){
        go(idx + 1, z, o);
        go(idx + 1, z + 1, o - 1);
    }
    if(idx < n && s[idx] == '0' && z){
        go(idx + 1, z, o);
    }
    if(idx < n && s[idx] == '1' && o){
        go(idx + 1, z, o);
    }
    if(idx + 1 < n && (s[idx] == '0' || s[idx + 1] == '0')){
        go(idx + 2, z + 1, o);
    }
    if(idx + 1 < n && (s[idx] == '1' || s[idx + 1] == '1')){
        go(idx + 2, z, o + 1);
    }
}
int solve(int idx, int z, int o){
    if(idx == n && z == 0 && o == 0) return 1;
    int &ret = dp[idx][z][o];
    if(ret != -1) return ret;
    ret = 0;
    // 0
    if(s[idx] == '0') ret += solve(idx + 1, z, o);
    else if(z) ret += solve(idx, z - 1, o);
    if(ret >= mod) ret -= mod;
    // 1
    if(s[idx] == '1') ret += solve(idx + 1, z, o);
    else if(o) ret += solve(idx, z, o - 1);
    if(ret >= mod) ret -= mod;
    return ret;
}
int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    memset(dp, -1, sizeof dp);
    cin >> s;
    n = s.size();
    go(0, 0, 0);
    vector <int> suff(n + 1);
    for(int i = n - 1 ; i >= 0 ; i--){
        suff[i] = suff[i + 1];
        suff[i] += s[i] - '0';
    }
    memset(f, -1, sizeof f);
    for(int i = 0 ; i <= n ; i++){
        for(int z = 0 ; z <= n ; z++){
            for(int o = 0 ; o <= n ; o++){
                if(c[i][z][o]){
                    int zeros = n - i - suff[i] + z;
                    int ones = suff[i] + o;
                    f[zeros][ones] = i;
                }
            }
        }
    }
    int ans = 0;
    for(int z = 0 ; z <= n ; z++){
        for(int o = 0 ; o <= n ; o++){
            int i = f[z][o];
            if(i == -1) continue;
            int zeros = z - (n - i - suff[i]);
            int ones = o - suff[i];
            ans += solve(i, zeros, ones);
            if(ans >= mod) ans -= mod;
        }
    }
    cout << ans << endl;
}


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

using namespace std;

using ll= long long;

#define sz(x) (int)x.size()
#define all(x) (x).begin(),(x).end()
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);


void solve(){
	int n,k;
	cin>>n>>k;
	int a[n];
	memset(a,0,sizeof a);
	for(int i=0;i<k;i++){
		int d;
		cin>>d;
		for(int j=0,d1;j<d;j++){
			cin>>d1;
			a[d1-1]++;
		}
	}
	int ans=0;
	for(int i=0;i<n;i++){
		if(a[i]==0){
			ans++;
		}
	}
	cout<<ans<<endl;
}

int32_t main(){
	IOS

	int t;
	t=1;
	while(t--){
		solve();
	}
	return 0;
}

/*
   check for overflows int long long
   correct size of array
*/

Measured memory_bytes: 3660
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cmath>
#include<map>
#include<iomanip>
#include<queue>
#include<stack>
#include<time.h>
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<=n;i++)
#define ggr getchar();getchar();return 0;
#define prique priority_queue
constexpr auto mod = 1000000007;
#define inf 1e15
#define key 1e9
using namespace std;
typedef pair<int, int>P;
template<class T> inline void chmax(T& a, T b) {
	a = std::max(a, b);
}
template<class T> inline void chmin(T& a, T b) {
	a = std::min(a, b);
}
//combination(Nが小さい時はこれを使う)
const int MAX = 330000;
int fac[MAX], finv[MAX], inv[MAX];
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX; i++) {
		fac[i] = fac[i - 1] * i % mod;
		inv[i] = mod - inv[mod % i] * (mod / i) % mod;
		finv[i] = finv[i - 1] * inv[i] % mod;
	}
}
int COMB(int n, int k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % mod) % mod;
}

bool prime(int n) {
	int cnt = 0;
	for (int i = 1; i <= sqrt(n); i++) {
		if (n % i == 0)cnt++;
	}
	if (cnt != 1)return false;
	else return n != 1;
}
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x % y);
}
int lcm(int x, int y) {
	return x / gcd(x, y) * y;
}

//繰り返し二乗法（Nが大きい時の場合のcombination)
int mod_pow(int x, int y, int m) {
	int res = 1;
	while (y) {
		if (y & 1) {
			res = res * x % m;
		}
		x = x * x % m;
		y >>= 1;
	}
	return res;
}
int kai(int x, int y) {
	int res = 1;
	for (int i = x - y + 1; i <= x; i++) {
		res *= (i % mod); res %= mod;
	}
	return res;
}
int comb(int x, int y) {
	if (y > x)return 0;
	return kai(x, y) * mod_pow(kai(y, y), mod - 2, mod) % mod;
}
//UnionFind
class UnionFind {
protected:
	int* par, * rank, * size;
public:
	UnionFind(unsigned int size) {
		par = new int[size];
		rank = new int[size];
		this->size = new int[size];
		rep(i, size) {
			par[i] = i;
			rank[i] = 0;
			this->size[i] = 1;
		}
	}
	int find(int n) {
		if (par[n] == n)return n;
		return par[n] = find(par[n]);
	}
	void unite(int n, int m) {
		n = find(n);
		m = find(m);
		if (n == m)return;
		if (rank[n] < rank[m]) {
			par[n] = m;
			size[m] += size[n];
		}
		else {
			par[m] = n;
			size[n] += size[m];
			if (rank[n] == rank[m])rank[n]++;
		}
	}
	bool same(int n, int m) {
		return find(n) == find(m);
	}
	int getsize(int n) {
		return size[find(n)];
	}
};
int dight(int n) {
	int ans = 1;
	while (n >= 10) {
		n /= 10;
		ans++;
	}
	return ans;
}
int dight_sum(int n) {
	int sum = 0;
	rep(i, 20)sum += (n % (int)pow(10, i + 1)) / (pow(10, i));
	return sum;
}
signed main() {
	int n, d;
	cin >> n >> d;
	int p = 2 * d + 1;
	cout << (n + p - 1) / p << endl;
	ggr
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define MOD 998244353
#define MAXT 1100000
using namespace std;
typedef long long LL;
LL powmod(LL a, LL n){
	if(n == 0) return 1;
	if(n % 2) return (a * powmod(a,n-1)) % MOD;
	return powmod((a*a) % MOD,n/2);
}

LL inv(LL a){
	return powmod(a,MOD-2);
}

LL fact[MAXT];
LL invfact[MAXT];
LL pow2[MAXT];
LL invpow2[MAXT];
int main(){
	LL inv2 = inv(2);
	for(int i = 0; i < MAXT; i++){
		if(i == 0){
			fact[i] = 1;
			pow2[i] = 1;
			continue;
		}
		pow2[i] = (2 * pow2[i-1]) % MOD;
		fact[i] = (i*fact[i-1]) % MOD;
	}
	invfact[MAXT-1] = inv(fact[MAXT-1]);
	invpow2[MAXT-1] = inv(pow2[MAXT-1]);
	for(LL j = MAXT-2; j >= 0; j--){
		invfact[j] = ((j+1) * invfact[j+1]) % MOD;
		invpow2[j] = (2 * invpow2[j+1]) % MOD;
	}
	string a, b;
	cin >> a >> b;
	int n11 = 0;
	int n10 = 0;
	for(int i = 0; i < a.size(); i++){
		if(a[i] == '1' && b[i] == '1') n11++;
		if(a[i] == '1' && b[i] == '0') n10++;
	}
	LL ans = 0;
	LL dp[2][11000];
	for(LL n = 0; n <= n10; n++){
		for(LL i = 0; i < 11000; i++){
			dp[n%2][i] = 0;
		}
		if(n == 0){
			dp[0][0] = 1;
			continue;
		}
		for(LL i = 0; i < 11000; i++){
			dp[n%2][i] += (n*n)*(dp[1-n%2][i]) % MOD;
			if(i > 0) dp[n%2][i] += (n*i)*(dp[n%2][i-1]) % MOD;
			dp[n%2][i] %= MOD;
		}
	}
	for(int a = 0; a <= n11; a++){
		LL cur = 1;
		cur = (cur * fact[n11]) % MOD;
		cur = (cur * invfact[a]) % MOD;
		cur = (cur * invfact[n11-a]) % MOD;
		cur = (cur * dp[n10 % 2][n11-a]) % MOD;

		cur = (cur * fact[n11+n10]) % MOD;
		cur = (cur * invfact[a]) % MOD;
		cur = (cur * invfact[n11+n10-a]) % MOD;

		cur = (cur * fact[a]) % MOD;
		cur = (cur * fact[a]) % MOD;
		ans = (ans + cur) % MOD;
		//cout << cur << endl;
	}
	cout << ans << endl;
}


Measured memory_bytes: 35072
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);

		int number = scanner.nextInt();
		int[] numbers = new int[number];
		boolean isEven = true;
		int count = -1;

		for (int i = 0; i < number; i++) {
			numbers[i] = scanner.nextInt();
		}

		do {
			for (int i = 0; i < number; i++) {
				if (numbers[i] % 2 != 0) {
					isEven = false;
					break;
				} else {
					numbers[i] /= 2;
				}
			}
			count++;
		} while (isEven);

		System.out.println(count);

		scanner.close();
	}
}

Measured memory_bytes: 23764
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <queue>
#include <vector>
#include <set>
#include <map>
#include <numeric>
#include <iomanip>
#include <tuple>

using namespace std;

int main(){
   long long n,a,b;
   cin>>n>>a>>b;
   vector<long long> x(n);
   for(int i=0;i<n;i++)cin>>x[i];

   long long ans=0;
   for(int i=0;i<n-1;i++){
       if((x[i+1]-x[i])*a<b)ans+=(x[i+1]-x[i])*a;
       else ans+=b;
   }
   cout<<ans<<endl;
}

   


Measured memory_bytes: 1024
// B - 81
#include <bits/stdc++.h>
using namespace std;
#define rp(i,s,e) for(int i=(s);i<(e);++i)

int main(){
	int N; cin>>N;
	rp(i, 1, 10) rp(j, i, 10) if(i*j == N){ puts("Yes"); return 0; }
	puts("No");
}

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

using namespace std;
using ll = long long;

using Field = vector<vector<int>>;
using Graph = vector<vector<int>>;
using VI = vector<int>;
using VC = vector<char>;
using PI = pair<int, int>;

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

const long long INF = 1LL<<60;
const int mod = 1000000007;

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

const int MAX = 510000;
ll fac[MAX], finv[MAX], inv[MAX];

void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i=2; i<MAX; i++) {
        fac[i] = fac[i-1] * i % mod;
        inv[i] = mod - inv[mod%i] * (mod / i) % mod;
        finv[i] = finv[i - 1] * inv[i] % mod;
    }
}

ll COM(int n, int k) {
    if(n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n-k] % mod) % mod;
}



ll modpow(ll a, ll n, int mod) {
    ll res = 1;
    while (n > 0) {
        if (n & 1) {
            res *= a;
            res %= mod;
        }
        a *= a;
        a %= mod;

        n >>= 1;
    }
    return res;
}

ll nCr(int n, int r) {
    ll a = 1;
    ll b = 1;
    
    for (int i = 0; i < r; ++i) {
        a *= (n - i);
        b *= (i + 1);
        a %= mod;
        b %= mod;
    }
    return (a * modpow(b, mod - 2, mod))%mod;
}

ll N, K;

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

    cin >> N >> K;
    ll ans = 0;

    for (ll i = K; i <= N + 1; i++) {
        ll min = (i - 1) * i / 2;
        ll max = i * (2 * N - i + 1) / 2;
        ll add = max - min + 1;
        ans = (ans + add) % mod;
    }

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

Measured memory_bytes: 3652
#include<bits/stdc++.h>
using namespace std;
int main(){
  int h,w;
  while(cin>>h>>w,h+w!=0){
    for(int i=0;i<h;++i){
      for(int j=0;j<w;++j) cout<<'#';
      cout<<endl;
    }
    cout<<endl;
  }
}


Measured memory_bytes: 3096
#include<cstdint>
#include<climits>
#include<cstdbool>
#include<cmath>
#include<iostream>
#include<vector>
#include<array>
#include<string>
#include<sstream>
#include<algorithm>

int main(){
	int K,N;
	std::cin>>K>>N;
	std::vector<int> A;
	A.reserve(N);
	std::string buff;
	std::cin.get();
	std::getline(std::cin, buff);
	std::stringstream ss(buff);
	std::string temp;
	while(!ss.eof()){
		std::getline(ss, temp, ' ');
		A.push_back(std::stoi(temp));
	}
	std::sort(A.begin(), A.end());
	std::vector<int>B;
	B.reserve(N);
	for(std::vector<int>::iterator it = A.begin(); it+1 < A.end(); ++it)
		B.push_back(*(it+1) - *it);
	B.push_back(K - *(A.end()-1) + *(A.begin()));
	std::sort(B.begin(), B.end());
	std::cout<<K-*(B.end()-1);
}


Measured memory_bytes: 4484
import java.util.*;

public class Main{
	public static void main(String[] $){
		Scanner s=new Scanner(System.in);
		int n=s.nextInt();
		char[]t=s.next().toCharArray();

		ArrayList<TreeSet<Integer>>m=new ArrayList<>(26);
		for(int i=0;i<26;++i)
			m.add(new TreeSet<>());
		for(int i=0;i<n;++i)
			m.get(t[i]-'a').add(i);

		for(int q=s.nextInt();q>0;--q) {
			if(s.nextInt()==1) {
				int a=s.nextInt()-1;
				char b=s.next().charAt(0);
				if(t[a]!=b) {
					m.get(t[a]-'a').remove(a);
					m.get(b-'a').add(a);
					t[a]=b;
				}
			}else {
				int a=s.nextInt();
				int b=s.nextInt();
				int c=0;
				for(TreeSet<Integer> o:m) {
					if(!o.subSet(a-1,b).isEmpty())
						++c;
				}
				System.out.println(c);
			}
		}
	}
}

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

#define ll          long long
#define pb          push_back
#define pii         pair<int,int>
#define vi          vector<int>
#define vii         vector<pii>
#define mi          map<int,int>
#define mii         map<pii,int>
#define all(a)      (a).begin(),(a).end()
#define x           first
#define y           second
#define sz(x)       (int)x.size()
#define endl        '\n'
#define hell        1000000007
#define rep(i,a,b)  for(int i=a;i<b;i++)
using namespace std;
int n,f[200005],vis[200005];
vi a[200005];
int bfs(int node){
	memset(vis,0,sizeof vis);
	int ans=node;
	queue<int> q;
	q.push(node);
	vis[node]=1;
	while(!q.empty()){
		int w=q.front();
		q.pop();
		ans=w;
		for(auto i:a[w]){
			if(!vis[i]){
				vis[i]=vis[w]+1;
				q.push(i);
			}
		}
	}
	return ans;
}
void solve(){
    cin>>n;
    rep(i,0,n-1){
    	int x,y;
    	cin>>x>>y;
    	a[x].pb(y);
    	a[y].pb(x);
    }
    int d=bfs(1);
    d=bfs(d);
    f[0]=0;
    f[1]=1;
    f[2]=0;
    rep(i,3,vis[d]+1){
    	f[i]=(!f[i-1])^(!f[i-2]);
    }
    if(f[vis[d]]) cout<<"First"<<endl;
    else cout<<"Second"<<endl;
}

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

Measured memory_bytes: 14196
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower

using namespace std;
 
int main(){
    string A;
    string B;
    string C;
    cin >> A >> B >> C;
    cout << A.at(0) << B.at(1) << C.at(2) << endl;
}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define y1 zzz
#define fi first
#define se second
#define PII pair<int,int>
#define PII2 pair<int,PII >
#define PII3 pair<PII,int >
#define PII4 pair<PII,PII >
#define all(x) (x).begin(),(x).end()
#define pb push_back
int t[400010],n,a[200010],h[200010];
void upd(int i,int val)
{
    for(t[i+=n]=val;i>1;i>>=1)t[i>>1]=max(t[i],t[i^1]);
}
int query(int l,int r)
{
    int res=0;
    for(l+=n,r+=n;l<r;l>>=1,r>>=1)
    {
        if(l&1)res=max(t[l++],res);
        if(r&1)res=max(t[--r],res);
    }
    return res;
}
void solve()
{
    cin>>n;
    for(int i=0;i<n;i++)
    {
        cin>>h[i];
        --h[i];
    }
    for(int i=0;i<n;i++)cin>>a[i];
    for(int i=0;i<n;i++)
    {
        int res=query(0,h[i])+a[i];
        upd(h[i],res);
    }
    cout<<query(0,n);
}
int32_t main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
    //freopen("XORQUERY.inp","r",stdin);
    //freopen("XORQUERY.out","w",stdout);
    //int t;cin>>t;while(t--)
    solve();
    return 0;
}


Measured memory_bytes: 6656
#include <iostream>
 
using namespace std;
using ll = long long;
 
const ll INF = 1LL << 50;
 
int a[2000];
int b[2000];
ll c[2000];
 
int main()
{
    int N, M;
    cin >> N >> M;
 
    for (int i = 0; i < M;i++)
    {
        cin >> a[i] >> b[i] >> c[i];
        a[i]--;
        b[i]--;
        c[i] = -c[i];
    }
 
    ll dist[1000];
 
    for (int i = 0; i < N;i++)
    {
        dist[i] = INF;
    }
 
    dist[0] = 0;
 
    for (int i = 0; i < N - 1;i++)
    {
        for (int j = 0; j < M;j++)
        {
            int u = a[j];
            int v = b[j];
            if (dist[u] == INF)
            {
                continue;
            }
            if(dist[v] > dist[u] + c[j])
            {
                dist[v] = dist[u] + c[j];
            }
        }
    }
 
    ll ans = dist[N - 1];
 
    bool negative[1000];
 
    for (int i = 0; i < N;i++)
    {
        negative[i] = false;
    }
 
    for (int i = 0; i < N; i++)
    {
        for (int j = 0; j < M; j++)
        {
            int u = a[j];
            int v = b[j];
            if (dist[u] == INF)
            {
                continue;
            }
            if (dist[v] > dist[u] + c[j])
            {
                dist[v] = dist[u] + c[j];
                negative[v] = true;
            }
            if(negative[u] == true)
            {
                negative[v] = true;
            }
        }
    }
 
    if(negative[N - 1] == true)
    {
        cout << "inf" << endl;
    }
    else
    {
        cout << -ans << endl;
    }
 
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
//#include <cstdio>
//#include <cstdlib>
//#include <algorithm>
//#include <cmath>
//#include <vector>
//#include <set>
//#include <map>
//#include <unordered_set>
//#include <unordered_map>
//#include <queue>
//#include <ctime>
//#include <cassert>
//#include <complex>
//#include <string>
//#include <cstring>
//#include <iomanip>
//#include <numeric>

using namespace std;

typedef long long LL;

int main(int argc, const char * argv[]) {

	cin.tie(0);
	ios::sync_with_stdio(false);

    int X;

	cin >> X;

	cout << X * X * X << endl;

	return 0;
}


Measured memory_bytes: 3176
#include <bits/stdc++.h>
#define FOR(v, a, b) for(int v = (a); v < (b); ++v)
#define FORE(v, a, b) for(int v = (a); v <= (b); ++v)
#define REP(v, n) FOR(v, 0, n)
#define REPE(v, n) FORE(v, 0, n)
#define REV(v, a, b) for(int v = (a); v >= (b); --v)
#define ALL(x) (x).begin(), (x).end()
#define ITR(it, c) for(auto it = (c).begin(); it != (c).end(); ++it)
#define RITR(it, c) for(auto it = (c).rbegin(); it != (c).rend(); ++it)
#define EXIST(c,x) ((c).find(x) != (c).end())
#define LLI long long int
#define fst first
#define snd second

#ifdef DEBUG
#include <misc/C++/Debug.cpp>
#else
#define dump(x) ((void)0)
#endif

#define gcd __gcd

using namespace std;
template <class T> constexpr T lcm(T m, T n){return m/gcd(m,n)*n;}

template <typename I> void join(ostream &ost, I s, I t, string d=" "){for(auto i=s; i!=t; ++i){if(i!=s)ost<<d; ost<<*i;}ost<<endl;}
template <typename T> istream& operator>>(istream &is, vector<T> &v){for(auto &a : v) is >> a; return is;}
template <typename T, typename U> istream& operator>>(istream &is, pair<T,U> &p){is >> p.first >> p.second; return is;}

template <typename T, typename U> bool chmin(T &a, const U &b){return (a>b ? a=b, true : false);}
template <typename T, typename U> bool chmax(T &a, const U &b){return (a<b ? a=b, true : false);}
template <typename T, size_t N, typename U> void fill_array(T (&a)[N], const U &v){fill((U*)a, (U*)(a+N), v);}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);

  int N,K;
  string S;
  while(cin >> N >> K >> S){
    vector<int> a;

    if(S[0] == '0') a.push_back(0);

    REP(i,N){
      if(S[i] == '0'){
	if(a.size() % 2 == 1) a.push_back(0);
	++a.back();
      }else{
	if(a.size() % 2 == 0) a.push_back(0);
	++a.back();
      }
    }

    if(S.back() == '0') a.push_back(0);

    vector<int> sum(a.size()+1);
    REP(i,(int)a.size()) sum[i+1] = sum[i] + a[i];

    int ans = 0;

    REP(i,(int)a.size()){
      if(i%2==1) continue;
      int j = min((int)a.size(),i+2*K+1);
      chmax(ans, sum[j] - sum[i]);
    }

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


Measured memory_bytes: 1272
#include <bits/stdc++.h>
#define ll long long int
#define ld long double
#define mod 1000000007
#define inf 1e18
#define inp(arr,n) for(int i=0;i<n;i++) cin>>arr[i]
#define fr(i,a,b) for(int i=a;i<=b;i++)
using namespace std;
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    int n;
    cin>>n;
    int a[n],b[n];
    fr(i,0,n-1){
        cin>>a[i];
        cin>>b[i];
    }
    sort(a,a+n); sort(b,b+n);
    if(n%2==1){
        int A=a[n/2];
        int B=b[n/2];
        cout<<B-A+1<<endl;
    }
    else{
        int A=a[n/2]+a[n/2-1];
        int B=b[n/2]+b[n/2-1];
        cout<<B-A+1<<endl;
    }
    return 0;
}


Measured memory_bytes: 5200
package main

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

func main() {
  sc := bufio.NewScanner(os.Stdin)
  sc.Split(bufio.ScanWords)

  sc.Scan()
  n, _ := strconv.Atoi(sc.Text())

  sc.Scan()
  k, _ := strconv.Atoi(sc.Text())

  var rate float64

  for i := 1; i <= n; i++ {
    tmp := i
    x := 1
    for tmp < k {
      tmp *= 2
      x *= 2
    }
    rate += 1 / float64(x) / float64(n)
  }

  fmt.Println(rate)
}


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

#define int long long
int dp[3123][3123],n,s,v[3123];
//dp[i][j]:sum:2^(n-k)*(i-1番目まで見てk個使って合計がjになる個数)
//dp[i+1][j]=dp[i][j-v[i]]/2+dp[i][j]
//初期値はdp[0][0]=2^n
const int MOD=998244353;
int pw(int n,int k){
  assert(k>=0);
  int res=1;
  while(k){
    if(k&1)(res*=n)%=MOD;
    (n*=n)%=MOD;
    k>>=1;
  }
  return res;
}
int f(int i,int j){
  if(j<0)return 0;
  if(!i)return pw(2,n)*(!j);
  if(~dp[i][j])return dp[i][j];
  return dp[i][j]=(f(i-1,j-v[i-1])*pw(2,MOD-2)+f(i-1,j))%MOD;
}

signed main(){
  memset(dp,-1,sizeof(dp));
  cin>>n>>s;
  for(int i=0;i<n;i++)cin>>v[i];
  cout<<f(n,s)<<endl;
}


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

int main() {
    vector<int> X(3);
    cin >> X[0] >> X[1] >> X[2];
    sort(X.begin(), X.end());
    if ((X[1] - X[0]) % 2 ==0){
        cout << (X[1] - X[0]) / 2 + X[2] - X[1] << endl;
    }
    else {
        cout << (X[1] - X[0]) / 2 + X[2] - X[1] + 2 << endl;
    }
}



Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
	int n;
	int ans=0;
	int sum=0;
	cin >> n;



	if(n%10==0){
		int a=n;
		while(a/10){
			a/=10;
		}
		if(a==1){
			cout << 10 << endl;
			return 0;
		}
		cout << a << endl;
		return 0;
	}

	do{
		sum += n%10;
	}while(n/=10);
	cout << sum << endl;

	return 0;
}

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

#define ll long long

int main(){
    int N;
    int wsum=0, esum=0;
    int ans = 1e9;
    string S;
    cin >> N >> S;
    vector<int> a(N);
    vector<int> e(N);
    vector<int> w(N);
    for(int i = 0; i < N; i++){
        w[i] = wsum;
        if(S[i] == 'E'){
            esum++;
        }else{
            wsum++;
        }
        e[i] = esum;
    }

    for(int i = 0; i < N; i++){
        a[i] = w[i] + esum - e[i];
        // cout << w[i] << esum - e[i] << endl;
        ans = min(a[i], ans);
    }
    cout << ans << endl;

}

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

const int N = 187;
int n, m;
char s[N][N];
int f[2][N][N][N], g[2][N][N][N];

int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++) {
    scanf("%s", s[i] + 1);
  }
  memset(f, -1, sizeof f);
  memset(g, -1, sizeof g);
  for (int k = n; k; k--) {
    for (int l = 1; l <= m; l++) {
      int same = 1;
      for (int r = l; r <= m; r++) {
        if (s[k][r] != s[k][l]) same = 0;
        if (!same) {
          f[0][k][l][r] = -1;
        } else if (k == n || s[k + 1][l] != s[k][l] || f[0][k + 1][l][r] == -1) {
          f[0][k][l][r] = k;
        } else {
          f[0][k][l][r] = f[0][k + 1][l][r];
        }
      }
    }
  }
  for (int k = m; k; k--) {
    for (int l = 1; l <= n; l++) {
      int same = 1;
      for (int r = l; r <= n; r++) {
        if (s[l][k] != s[r][k]) same = 0;
        if (!same) {
          g[0][k][l][r] = -1;
        } else if (k == m || s[l][k + 1] != s[l][k] || g[0][k + 1][l][r] == -1) {
          g[0][k][l][r] = k;
        } else {
          g[0][k][l][r] = g[0][k + 1][l][r];
        }
      }
    }
  }
  for (int tim = 0, p = 0; ; tim++, p = !p) {
    if (f[p][1][1][m] == n) {
      printf("%d\n", tim);
      return 0;
    }
    memset(f[!p], -1, sizeof f[!p]);
    memset(g[!p], -1, sizeof g[!p]);
    for (int k = n; k; k--) {
      for (int l = 1; l <= m; l++) {
        for (int r = l; r <= m; r++) if (f[p][k][l][r] != -1) {
          int s = f[p][k][l][r];
          f[!p][k][l][r] = max(f[!p][k][l][r], s == n || f[p][s + 1][l][r] == -1 ? s : f[p][s + 1][l][r]);
          g[!p][l][k][f[!p][k][l][r]] = max(g[!p][l][k][f[!p][k][l][r]], r);
        }
      }
    }
    for (int k = m; k; k--) {
      for (int l = 1; l <= n; l++) {
        for (int r = l; r <= n; r++) if (g[p][k][l][r] != -1) {
          int s = g[p][k][l][r];
          g[!p][k][l][r] = max(g[!p][k][l][r], s == m || g[p][s + 1][l][r] == -1 ? s : g[p][s + 1][l][r]);
          f[!p][l][k][g[!p][k][l][r]] = max(f[!p][l][k][g[!p][k][l][r]], r);
        }
      }
    }
    for (int k = 1; k <= n; k++) {
      for (int t = m; t; t--) {
        for (int l = 1, r = t; r <= m; l++, r++) {
          if (l > 1) f[!p][k][l][r] = max(f[!p][k][l][r], f[!p][k][l - 1][r]);
          if (r < m) f[!p][k][l][r] = max(f[!p][k][l][r], f[!p][k][l][r + 1]);
        }
      }
    }
    for (int k = 1; k <= m; k++) {
      for (int t = n; t; t--) {
        for (int l = 1, r = t; r <= n; l++, r++) {
          if (l > 1) g[!p][k][l][r] = max(g[!p][k][l][r], g[!p][k][l - 1][r]);
          if (r < n) g[!p][k][l][r] = max(g[!p][k][l][r], g[!p][k][l][r + 1]);
        }
      }
    }
  }
}


Measured memory_bytes: 102400
import java.util.*;

public class Main{
	public static void main(String args[]){
		 Scanner sc = new Scanner(System.in);	   
    int time[][] = new int [3][2];
	for(int i=0;i<3;i++){
		for(int j=0;j<2;j++){
	  time[i][j]+=sc.nextInt()*3600;
	  time[i][j]+=sc.nextInt()*60;
	  time[i][j]+=sc.nextInt();
		}
		time[i][0]=time[i][1]-time[i][0];
	  }
	for(int i=0; i<3;i++){
	System.out.println(time[i][0]/3600+" "+time[i][0]%3600/60+" "+time[i][0]%3600%60);
	}
	}
	}

Measured memory_bytes: 17360
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Globalization;
using System.Diagnostics;
using static System.Console;
using Pair = System.Collections.Generic.KeyValuePair<int, int>;
//using System.Numerics;
//using static System.Math;

class Program
{
    static void Main()
    {
        //SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
        new Program().solve();
        Out.Flush();
    }
    Scanner cin = new Scanner();
    readonly int[] dd = { 0, 1, 0, -1, 0 };
    readonly int mod = 1000000007;
    readonly string alfa = "abcdefghijklmnopqrstuvwxyz";
    readonly string ALFA = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";

    int N;
    void solve()
    {
        var E = cin.scanint;
        Array.Sort(E);
        if (E[0] == E[1])
        {
            WriteLine(E[2]);
        }
        else
        {
            WriteLine(E[0]);
        }
    }

}

class Scanner
{
    string[] s; int i;
    char[] cs = new char[] { ' ' };
    public Scanner() { s = new string[0]; i = 0; }
    public string[] scan { get { return ReadLine().Split(); } }
    public int[] scanint { get { return Array.ConvertAll(scan, int.Parse); } }
    public long[] scanlong { get { return Array.ConvertAll(scan, long.Parse); } }
    public double[] scandouble { get { return Array.ConvertAll(scan, double.Parse); } }
    public string next
    {
        get
        {
            if (i < s.Length) return s[i++];
            string st = ReadLine();
            while (st == "") st = ReadLine();
            s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
            i = 0;
            return next;
        }
    }
    public int nextint { get { return int.Parse(next); } }
    public long nextlong { get { return long.Parse(next); } }
    public double nextdouble { get { return double.Parse(next); } }
}

Measured memory_bytes: 13268
while gets
p [0,0,0,0,0,0,14,9,4,0,0,8,3,2,0,0,15,10,15,10,6,12,7,9,11,6,23,18,13,8,3,23,18,13,8,3,34,29,24,22,17,28,23,24,19,27,34,29,35,30,28,31,28,23,24,28,42,37,32,27,22,42,37,32,27,22,53,48,43,41,36,47,42,43,38,46,64,59,54,49,44,61,56,51,46,44,72,67,62,57,52,72,67,62,57,52,83,78,73,71][$_.to_i]end

Measured memory_bytes: 2216
def LI():
	return [ int(s) for s in input().split() ]

N = input()
A = LI()
 
cnt = 0
 
for a in A:
  odd = False
  while(not odd):
    if a % 2 != 0:
      odd = True
    else:
      a = a//2
      cnt += 1
      
print(cnt)

Measured memory_bytes: 4148
#include <bits/stdc++.h>
using namespace std;
 
int main() {
	int N;
  cin >> N;
  vector<int> x(N);
  
  for(int i = 0; i < N; i++){
  cin >> x.at(i);
  }
  
  sort(x.begin(),x.end());
  
  int min = 1000000000;
  
  for(int i = x.at(0); i <= x.at(N-1); i++){
    int value = 0;
    	for(int j = 0; j<N; j++){
        	value += (i - x.at(j))*(i - x.at(j));
        }
  	if(min > value){min = value;}
  }
  
  cout << min << endl;
}


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

#define int ll
typedef long long ll;

typedef pair<int, int> pii;
typedef pair<ll,ll> pll;

typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;

#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)

#define ALL(s) (s).begin(),(s).end()
#define ALLn(s,n) s,s+n
#define F first
#define S second
#define pb push_back
#define tc(t) int t; cin >> t; while(t--)
#define _ ios_base::sync_with_stdio(false); cin.tie(NULL);
#define D1(x) { cerr << " [" << #x << ": " << x << "]\n"; }
#define D2(x) { cerr << " [" << #x << ": "; for(auto it:x) cerr << it << " "; cerr << "]\n"; }

const ll MOD = 1e9 + 7;
const ll MAXN = 1e6 + 7;
const ll INF = LONG_LONG_MAX;

void solve() {
	int n;
	cin >> n;

	int a[n];
	int cnt = 0;
	F0R(i,n) {
		cin >> a[i];
		if(i%2==0 && a[i]%2==1) cnt++;
	}
	cout << cnt << '\n';
}

int32_t main() {_
	
#ifndef ONLINE_JUDGE
	freopen("in", "r", stdin);
	freopen("out", "w", stdout);
#endif

	// tc(t)
		solve();
	cerr << "[ Time : " << (float)clock() / CLOCKS_PER_SEC << " secs ]" << endl;
}


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

int main() {
  int x,n,ans=1000,l;
  bool check;
  cin >> x >> n;
  vector<int>p(n);
  for (int i = 0; i < n; i++) {
    cin >> p.at(i);
  }
  for (int i = 110; i >=-10; i--) {
    check = 0;
    for (int j=0; j < p.size(); j++) {
      if (p.at(j) == i) {
        check=1;
        break;
      }
    }
    if (check==0) {
      ans = min(ans,abs(x-i));
      if (ans==abs(x-i)) {
      l=i;
    }
    }
  }
  cout << l << endl;
}  

Measured memory_bytes: 3624
#include <cstdio>
#include <cstring>
#define MAX_N 100001

bool IsPrime[MAX_N];

void get_primes() {
    IsPrime[0] = false;
    IsPrime[1] = false;

    for (int i = 2; i*i <= MAX_N; i++) {
        if (IsPrime[i]) {
            for (int j = i*i; j <= MAX_N; j += i) {
                IsPrime[j]= false;
            }
        }
    }
}

int main() {
    int Q, l, r;
    int cnt[MAX_N] = {0};

    memset(IsPrime, 1, sizeof(IsPrime));
    get_primes();

    for (int i = 3; i <= MAX_N; i += 2) {
        if (IsPrime[i] && IsPrime[(i+1)/2]) { cnt[i]++; }
    }
    // 2017 に似てる数の累積和をとっている
    for (int i = 1; i <= MAX_N; i++) {
        cnt[i] += cnt[i-1];
    }

    scanf("%d", &Q);

    while (Q--) {
        scanf("%d %d", &l, &r);
        printf("%d\n", cnt[r] - cnt[l-1]);
    }

    return 0;
}

Measured memory_bytes: 1024
IDENTIFICATION                   DIVISION.
PROGRAM-ID.                      ABC_098_B.
ENVIRONMENT                      DIVISION.
DATA                             DIVISION.
WORKING-STORAGE                  SECTION.
    01 N      PIC 9(3).
    01 S      PIC X(101).

    01 chr    PIC X(1)   VALUE SPACE.
    01 str    PIC X(101) VALUE SPACE.

    01 i      PIC 9(3).
    01 j      PIC 9(3).
    01 k      PIC 9(3).

    01 flg    PIC 9(1)   VALUE 0.
    01 cur    PIC 9(3).

    01 len    PIC 9(1)   VALUE 1.
    01 cnt    PIC 9(2)   VALUE 0.
    01 cntmax PIC 9(2)   VALUE 0.

    01 ans    PIC Z9.

    01 X1.
        03 XNUM PIC 9(2) VALUE 0.
        03 X11 OCCURS 26.
            05 X PIC X(1).

    01 Y1.
        03 YNUM PIC 9(2) VALUE 0.
        03 Y11 OCCURS 26.
            05 Y PIC X(1).

PROCEDURE                        DIVISION.
MAIN.
    ACCEPT N.
    ACCEPT S.

    PERFORM VARYING i FROM 1 BY 1 UNTIL N < i
        MOVE S(i : len) TO chr;

        MOVE 0 TO flg;

        PERFORM VARYING j FROM 1 BY 1 UNTIL XNUM < j
            IF X(j) = chr THEN
                MOVE 1 TO flg
            END-IF;
        END-PERFORM;

        IF flg = 0 THEN
           ADD 1 TO XNUM;
           MOVE chr TO X(XNUM);
        END-IF;

        INITIALIZE Y1;

        COMPUTE cur = i + 1;

        MOVE S(cur : N - i) TO str;

        PERFORM VARYING j FROM 1 BY 1 UNTIL N - 1 < j
            MOVE str(j : len) TO chr;

            MOVE 0 TO flg;

            PERFORM VARYING k FROM 1 BY 1 UNTIL YNUM < k
                IF Y(k) = chr THEN
                    MOVE 1 TO flg
                END-IF;
            END-PERFORM;

            IF flg = 0 THEN
                ADD 1 TO YNUM;
                MOVE chr TO Y(YNUM);
            END-IF;
        END-PERFORM;

        MOVE 0 TO cnt;
        PERFORM VARYING j FROM 1 BY 1 UNTIL XNUM < j

            PERFORM VARYING k FROM 1 BY 1 UNTIL YNUM < k
                IF X(j) = Y(k) THEN
                    ADD 1 TO cnt;
                END-IF;
            END-PERFORM;

        END-PERFORM;

        COMPUTE cntmax = FUNCTION MAX(cntmax, cnt);

    END-PERFORM.

    MOVE cntmax TO ans.
    DISPLAY ans.

    STOP RUN.


Measured memory_bytes: 636
using System;
using System.Collections.Generic;
using static Assistant.Input;
using static Assistant.Debug;
using System.Linq;
using Assistant;

namespace AGC019B
{
    class Program
    {
        static void Main(string[] args)
        {
            var S = Console.ReadLine();
            long N = S.Length;

            long[] count = new long[26];
            foreach (var s in S)
            {
                count[s - 'a']++;
            }

            long ans = N * (N - 1) / 2 + 1;
            foreach (var c in count)
            {
                ans -= c * (c - 1) / 2;
            }

            Console.WriteLine(ans);
        }
    }


}

namespace Assistant
{
    static class Input
    {
        static List<string> line = new List<string>();
        static int index = 0;
        static String RNext()
        {
            if (line.Count <= index) line.AddRange(Console.ReadLine().Split());
            return line[index++];
        }
        public static int RInt => int.Parse(RNext());
        public static long RLong => long.Parse(RNext());
        public static int[] RInts => Console.ReadLine().Split().Select(int.Parse).ToArray();
        public static long[] RLongs => Console.ReadLine().Split().Select(long.Parse).ToArray();
        public static string RString => RNext();
        //以下未テスト
        public static int[] RIntsC(int c) => Enumerable.Repeat(0, c).Select(x => int.Parse(RNext())).ToArray();
        public static long[] RLongsC(int c) => Enumerable.Repeat(0, c).Select(x => long.Parse(RNext())).ToArray();
        public static char[][] RMap(int h) => Enumerable.Repeat(0, h).Select(x => Console.ReadLine().ToCharArray()).ToArray();
    }

    static class Debug
    {
        static public void Draw2D<T>(T[,] map, int mode = 1)
        {
#if DEBUG
            int W = map.GetLength(0);
            int H = map.GetLength(1);

            string[,] map2 = new string[W + 1, H + 1];
            for (int i = 0; i < W + 1; i++)
            {
                for (int j = 0; j < H + 1; j++)
                {
                    if (i == 0 && j == 0) map2[i, j] = 0.ToString();
                    else if (i == 0) map2[i, j] = (j - 1).ToString();
                    else if (j == 0) map2[i, j] = (i - 1).ToString();
                    else map2[i, j] = map[i - 1, j - 1].ToString();
                }
            }

            for (int i = 0; i < W + 1; i++)
            {
                for (int j = 0; j < H + 1; j++)
                {
                    if (mode == 0) Console.Write(map2[i, j].Last());
                    if (mode == 1) Console.Write(map2[i, j] + " ");
                }
                Console.WriteLine();
            }
            Console.WriteLine();
#endif
        }

        public static void Draw1D<T>(T[] array, int mode = 0)
        {
#if DEBUG
            Console.WriteLine(string.Join(" ", array));
#endif
        }
    }
}


Measured memory_bytes: 13240
import sys
a = input().strip()

b = ['+', '-']

for i in b:
    for j in b:
        for k in b:
            c = a[0] + i + a[1] + j + a[2] + k + a[3]
            ans = eval(c)
            if ans == 7:
                print(c+'=7')
                sys.exit()

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#include <cstdlib>  // abs() for integer 絶対値求めやつ
#include <cmath>    // abs() for float, and fabs()
#include <algorithm>
#include <vector>
#include <string>
#include<iomanip>//浮動小数点数を出力する制度の指定
//使い方　数値をnumとして　cout<<setprecision(n)<<num ;nは桁数
#define rep(i,n) for(int i = 0; i < (n);i++)
#define SORT(a) sort((a).begin(),(a).end())
#define REV(a) reverse((a).begin(),(a).end())
using namespace std;
using ll =long long;
using db = double;
#define INF 2000000000
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; }
#define che(a,string) cout<<"//"<<string <<"=="<<(a)<<"//" <<endl;
bool IsInt(double a){int b = a/1;if(a==b){return true;}else {return false;}}
/*覚えてないことメaモ
  数値型から文字列に変換　to_string(number);これは簡単
  文字列から数値型に変換　stoi(number)
  文字列からllに変換　stoll(number)
  __gcd(a,b)は最大公約数を取ってくれる、aとb
  の大きい方をNとしたとき、計算量は√N
 */
const int mod = 1e9 + 7;
//ここから書き始める
int main(){
	int n;
	cin>>n;

	//要素数nの配列を作るテンプレート
	vector<int> A(n);
	for(int i = 0 ; i < n; i ++){
		cin>>A[i];
	}
	ll ans = 0;
	for (int i = 0 ; i < n ; i++){
		for(int j =  i+1 ; j < n ; j++){
			ans += A[i] * A[j];
		}
	}
	cout << ans << endl;


}



Measured memory_bytes: 256
import java.util.*;

public class Main{
    public static void main(String[] args){
	Scanner sc = new Scanner(System.in);
	int N = sc.nextInt();
	int[] X = new int[N];
	for(int i=0;i<N;i++){
	    X[i] = sc.nextInt();
	}
	Arrays.sort(X);
	int min = Integer.MAX_VALUE;

	for(int p=X[0]; p<=X[N-1];p++){ 
	    int count = 0;
	    for(int j=0;j<N;j++){
		count += (X[j] - p)*(X[j] - p);
	    }
	    if(count < min) min = count;
	}
	System.out.print(min);
    }
}


Measured memory_bytes: 22868
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<deque>
#include<map>
#include<queue>
#define maxn 200010
using namespace std;
typedef long long ll;
int read()
{
    int x=0,f=1;
    char ch=getchar();
    while(ch-'0'<0||ch-'0'>9){if(ch=='-') f=-1;ch=getchar();}
    while(ch-'0'>=0&&ch-'0'<=9){x=x*10+ch-'0';ch=getchar();}
    return x*f;
}
struct P{
    int l,r;
}a[maxn];
bool cmp(P x,P y)
{
    return x.l<y.l;
}
int n,m;
int s[maxn],top;
priority_queue<int,vector<int>,greater<int> >q;
int ans;
int main()
{
    n=read();m=read();
    for(int i=1;i<=n;i++)  a[i].l=read(),a[i].r=read();
    sort(a+1,a+n+1,cmp);
    int cnt=0;
    for(int i=1;i<=n;i++)
    {
        q.push(a[i].r);
        if(q.size()>a[i].l||q.size()>m)
        {
            s[++top]=q.top();
            q.pop();
        }
        else cnt++;
    }
    sort(s+1,s+top+1);
    int now=0;
    for(int i=top;i>=1;i--)
    {
        if(now+1>m-cnt||now+1>m-s[i]+1)  ans++;
        else now++;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 3192
#include <iostream>
#include <string>
#include <set>
#include <cctype>
#include <vector>
#include <map>
#include <queue>
#include <list>
#include <algorithm>
#include <ctime>
#include <cstdio>
#include <cstring>
#include <iterator>
#include <limits>
#include <cmath>
#include <typeinfo>

using namespace std;


int main() {	
	int n = 0;
	cin >> n;
	int number = 0;
	for(int i = 0; i < n; i++){
		cin >> number;
		if(number % 2 == 0){
			if(number % 3 != 0 and number % 5 != 0){
				cout << "DENIED" << endl;
				return 0;
			}
		}
	}
	cout << "APPROVED" << endl;

 	return 0;		
    
}

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <math.h> 
#include <algorithm>
#include <numeric>
#include <functional>
#include <vector>
#include <string>
#include <numeric>

using namespace std;
vector<long> a;

//2で割り続けることができる回数を返す関数
long get_even_try(long n){
	long cnt = 0;
	while (1) {
		if (n % 2 == 1) {
			break;
		}
		else {
			cnt++;
		}
		n = n / 2;
	}

	return cnt;
}

int main() {

	long n = 0;
	cin >> n;
	for (long i = 0; i < n; ++i) {
		long tmp = 0;
		cin >> tmp;
		a.push_back(tmp);
	}

	long ans = 0;
	//各要素で偶数を対象にその2で割れる数の合計が答え
	for (long i = 0; i < a.size(); ++i) {
		ans = ans + get_even_try(a.at(i));
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 512
#include<iostream>
#include<vector>
#include<algorithm>
#include<numeric>
using namespace std;
int main()
{
	int n, ans;
	cin>>n;
	vector<int>v(n);
	for(int i=0;i<n;++i)cin>>v[i];
	sort(v.begin(),v.end());
	ans = v.size();
	for(int i=0;i<n-1;++i){
		if(v[i+1] - v[i] == 0){
			ans-=1;
		}
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
 
#define IOS 		ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define sd(n)       scanf("%d", &n)
#define sdd(a,b)    scanf("%d %d", &a, &b)
#define sddd(a,b,c) scanf("%d %d %d", &a, &b, &c)
#define sld(n)      scanf("%lld", &n)
#define slld(a,b)   scanf("%lld %lld", &a, &b)
#define sllld(a,b,c) scanf("%lld %lld %lld", &a, &b, &c)
#define slu(n)      scanf("%llu", &n)
#define sllu(a,b)   scanf("%llu %llu", &a, &b)
#define slllu(a,b,c) scanf("%llu %llu %llu", &a, &b, &c)
#define ss(a)		scanf("%s", a)
#define inStrAftInSome cin.ignore(numeric_limits<streamsize>::max(),'\n')		//input string(with whitespace) after input something(char, int, bool, str)
#define all(a) 		a.begin(),a.end()
#define unq(x)      x.erase(unique(all(x)), x.end()
#define mp 			make_pair
#define mt 			make_tuple
#define sz(av) 		int((av).size())					//return size of vec
#define CLR(arr)    memset(arr, 0, sizeof(arr))			//assign 0 to whole arr
#define SET(vec)    memset(arr, -1, sizeof(arr))		//assign -1 to whole arr
#define CLRV(vec)	fill(vec.begin(), vec.end(), 0)		//assign 0 to whole vec
#define SETV(vec,n,a) vec.assign(n, a)	
#define vtd(rowsize,colsize,type,name) 		vector < vector <type> > name(rowsize,vector <type> (colsize)); 	//assign to first n elements value a in vec
#define SETB(a)		memset(a, true, sizeof(a))			//boolean array initialize by true value
#define CLRB(a)		memset(a, false, sizeof(a))			//boolean array initialize by false value
#define vintitr 	vector<int>::iterator
#define vlnlnitr 	vector<long long>::iterator
#define sintitr 	set<int>::iterator
#define slnlnitr 	set<long long>::iterator
#define aa			first
#define bb			second
#define mod 		1000000007
#define PI 			acos(-1.00)
#define psb 		push_back
#define ppb			pop_back
#define ppb			pop_back
#define psf			push_front
#define ppf			pop_front
#define in 			inset
#define rep(i, n) 	for(int i=0; i<n; i++)
#define repi(i,j,n) for(int i=j; i<n; i++)
#define rof(i, n)   for(int i=n-1; i>=0; i--)
#define roff(i, n, f)	for(int i = n-1; i>=f; i--)
#define min3(a,b,c) (min((c),min((a),(b))))
#define max3(a,b,c) (max((a),max((b),(c))))
#define __lcm(a, b)	a*b / __gcd(a, b)
#define __builtin_zerocount(a)	8*sizeof(a)-__builtin_popcount(a)-__builtin_clz(a)-__builtin_ctz(a)
#define D(t)        cerr << #t " = " <<t  << '\n'
#define DBG         cerr << "Hi!" << '\n'
 
 
typedef long long	 		ll;
typedef unsigned long long	llu;
typedef long double			ld;
typedef vector< int > 		vi;
typedef vector< vi >		vvi;
typedef pair<int, int> 		pii;
typedef tuple<int,int,int>  tiii;

vector <int> occ(101);

int main()
{
//	freopen("t.in","r",stdin);
//	freopen("t.out","w",stdout);
	IOS;
	int t;	cin >> t;
	cout << t*t << endl;
    return 0;
}

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

const long long INF = 1LL << 60;

template <class T> inline void min(T& a, T b) {
	a = a < b ? a : b;
}

int main() {
	long long  n;
	cin >> n;
	int* cou = new int[n+1];
	for (int i = 0; i <= n; i++) {
		cou[i] = 1000;
	}
	cou[0] = 0;
	/*for (int i = 0; i <= n; i++) {
		cout << i << " : " << cou[i] << " ";
	}
	cout << endl;*/

	for (int i = 0; i < n; i++) {
		min(cou[i+1] , cou[i]+1);
		for (int j = 1; j < 8; j++) {
			long long k6 = pow(6, j), k9 = pow(9, j);
			if (i + k6 <= n) min(cou[i + k6] , cou[i] + 1);
			if (i + k9 <= n)min(cou[i + k9] , cou[i] + 1);
		}
		/*for (int i = 0; i <= n; i++) {
			cout << i << " : " << cou[i] << " / ";
		}
		cout << endl;*/
	}



	cout << cou[n] << endl;
	delete[] cou;
}

Measured memory_bytes: 640
class UnionFind:
    def __init__(self, n):
        self.n = n
        self.parent = [None]*n

    def root(self, x):
        if self.parent[x] == None:
            return x
        else:
            return self.root(self.parent[x])

    def union(self, x, y):
        x0 = self.root(x)
        y0 = self.root(y)
        if x0 == y0:
            return
        if x0 > y0:
            x0, y0 = y0, x0
        self.parent[y0] = x0


n = int(input())
m = 10**5
uf = UnionFind(2*m)
X, Y = [], []
for i in range(n):
    x, y = map(int, input().split())
    X.append(x-1)
    Y.append(y-1+m)
    uf.union(x-1, y-1+m)
R = {}
for x, y in zip(X, Y):
    r = uf.root(x)
    try:
        R[r][0].add(x)
        R[r][1].add(y)
    except:
        R[r] = [{x}, {y}]
ans = 0
for r in R.keys():
    ans += len(R[r][0])*len(R[r][1])
print(ans-n)


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

int main() {
	int n;
	cin >> n;
	long long k=0;
	for(int i=1;i<=n;i++)
	{
		if(i%3==0||i%5==0)
		{
			continue;
		}
		k += i;
	}
	cout << k << endl;
	return 0;
}


Measured memory_bytes: 3588
#include <iostream>
#include <vector>
#include <algorithm>

int main() {
  size_t N;

  std::cin >> N;

  std::vector<long> A(N+1);

  A[0] = 0;
  for (size_t i=0; i<N; i++) {
    long a;
    std::cin >> a;

    A[i+1] = A[i] + a;
  }

  std::sort(A.begin(), A.end());

  size_t ans = 0;
  size_t cnt_same = 0;
  long prev = A[0];

  for (size_t i=1; i<N+1; i++) {
    if (prev == A[i]) {
      cnt_same++;
      ans+=cnt_same;
    } else {
      cnt_same = 0;
    }
    prev = A[i];
  }

  std::cout << ans << std::endl;

  return 0;
}


Measured memory_bytes: 1792
import java.util.*;
public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        long n = sc.nextLong();
        long m = sc.nextLong();
        sc.close();
        if(n == 1 && m == 1){
            System.out.println(1);
        }else if(n == 1){
            System.out.println(m - 2);
        }else if(m == 1){
            System.out.println(n - 2);
        }else{
            System.out.println((m - 2) * (n - 2));
        }
    }
}

Measured memory_bytes: 35728
#include <iostream>
#include <string>
#include <vector>
#include <cmath>

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

using std::cin;
using std::cout;
using std::endl;
using std::string;
using std::vector;

int main() {
  int W, H, N;
  cin >> W >> H >> N;

  int xl = 0;
  int xr = W;
  int yt = H;
  int yb = 0;

  int x, y, a;
  rep(i, N) {
    cin >> x >> y >> a;
    switch(a) {
    case 1:
      xl = std::max(xl, x);
      break;
    case 2:
      xr = std::min(xr, x);
      break;
    case 3:
      yb = std::max(yb, y);
      break;
    case 4:
      yt = std::min(yt, y);
      break;
    }
  }

  if (xl >= xr || yb >= yt) cout << 0 << endl;
  else cout << (xr - xl) * (yt - yb) << endl;

  return 0;
}


Measured memory_bytes: 256