akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <array>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>

#define REP(X, Y, Z) for (ll(X) = (Y); (X) < (Z); (X)++)
#define REV(X, Y, Z) for (ll(X) = (Y); (X) > (Z); (X)--)

using namespace std;
using ll = long long;
using dll = deque<ll>;
using pll = pair<ll, ll>;
using qll = queue<ll>;
using usll = unordered_set<ll>;
using umll = unordered_map<ll, ll>;
using sll = stack<int>;
using vll = vector<ll>;
using vvll = vector<vll>;

constexpr ll kMod = 1e9 + 7;

ll gcd(ll a, ll b) {
  if (a < b) {
    return gcd(b, a);
  }
  ll c = a % b;
  while (c != 0) {
    a = b;
    b = c;
    c = a % b;
  }
  return b;
}

ll lcm(ll a, ll b) {
  return a / gcd(a, b) * b;
}

void init() {
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(15);
}

int main() {
  init();

  ll N, C, K;
  cin >> N >> C >> K;
  vll T(N);
  REP(i, 0, N) {
    cin >> T[i];
  }
  sort(T.begin(), T.end(), less<>());

  ll ans = 1;
  ll cnt = 1;
  ll start = T[0];
  REP(i, 1, N) {
    if (T[i] <= start + K) {
      if (cnt < C) {
        cnt++;
      } else {
        ans++;
        cnt = 1;
        start = T[i];
      }
    } else {
      ans++;
      cnt = 1;
      start = T[i];
    }
  }
  cout << ans << endl;

  return 0;
}


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

int main(){
    int a,b,c,d,e,f;
    cin >>a>>b>>c>>d>>e>>f;
    int score[]={a,b,c,d};
    sort(score,score+4);
    int score2[]={e,f};
    sort(score2,score2+2);
    cout <<score[1]+score[2]+score[3]+score2[1]<<endl;
    
    return 0;
}

Measured memory_bytes: 3164
#include <vector>
#include <functional>

#include <algorithm>
#include <iostream>
#include <utility>

// Segment tree with lazy propagation.
template <class Data, class Operator>
class LazySegmentTree
{
	int size_, height_;

	// (Data, F) is a monoid.
	std::vector<Data> data_;
	using F = std::function<Data(Data, Data)>;
	const F f_;
	const Data data_id_;

	// This is operation.
	using G = std::function<Data(Data, Operator)>;
	const G g_;

	// (Operator, H) is a monoid.
	std::vector<Operator> lazy_;
	using H = std::function<Operator(Operator, Operator)>;
	const H h_;
	const Operator operator_id_;

	void init(int num)
	{
		size_ = 1;
		height_ = 0;
		while (size_ < num)
		{
			size_ <<= 1;
			++height_;
		}
		data_.assign(size_ << 1, data_id_);
		lazy_.assign(size_ << 1, operator_id_);
	}

	inline Data reflect(int k)
	{
		if (lazy_[k] == operator_id_)
		{
			return data_[k];
		}
		else
		{
			return g_(data_[k], lazy_[k]);
		}
	}

	inline void eval(int k)
	{
		if (lazy_[k] == operator_id_)
			return;
		lazy_[(k << 1) | 0] = h_(lazy_[(k << 1) | 0], lazy_[k]);
		lazy_[(k << 1) | 1] = h_(lazy_[(k << 1) | 1], lazy_[k]);
		data_[k] = reflect(k);
		lazy_[k] = operator_id_;
	}

	inline void thrust(int k)
	{
		for (int i = height_; i > 0; --i)
		{
			eval(k >> i);
		}
	}

	inline void recalc(int k)
	{
		while (k >>= 1)
		{
			data_[k] = f_(reflect((k << 1) | 0), reflect((k << 1) | 1));
		}
	}

  public:
	LazySegmentTree(F f, G g, H h, Data data_id, Operator operator_id)
		: f_(f), data_id_(data_id), g_(g), h_(h), operator_id_(operator_id) {}

	void build(const std::vector<Data> &elements)
	{
		const int num = elements.size();
		init(num);
		for (int i = 0; i < num; ++i)
		{
			data_[size_ + i] = elements[i];
		}
		for (int i = size_ - 1; i > 0; --i)
		{
			data_[i] = f_(data_[(i << 1) | 0], data_[(i << 1) | 1]);
		}
	}

	void update(int a, int b, Operator x)
	{
		thrust(a += size_);
		thrust(b += size_ - 1);
		for (int l = a, r = b + 1; l < r; l >>= 1, r >>= 1)
		{
			if (l & 1)
			{
				lazy_[l] = h_(lazy_[l], x);
				++l;
			}
			if (r & 1)
			{
				--r;
				lazy_[r] = h_(lazy_[r], x);
			}
		}
		recalc(a);
		recalc(b);
	}

	void set(int a, Data x)
	{
		thrust(a += size_);
		data_[a] = x;
		lazy_[a] = operator_id_;
		recalc(a);
	}

	Data query(int a, int b)
	{
		thrust(a += size_);
		thrust(b += size_ - 1);
		Data vl = data_id_, vr = data_id_;
		for (int l = a, r = b + 1; l < r; l >>= 1, r >>= 1)
		{
			if (l & 1)
			{
				vl = f_(vl, reflect(l++));
			}
			if (r & 1)
			{
				vr = f_(reflect(--r), vr);
			}
		}
		return f_(vl, vr);
	}
};

int main()
{
	// range add, range sum
	int n, q;
	std::cin >> n >> q;
	using ll = long long;
	auto f = [](ll a, ll b) {
		return std::min(a, b);
	};
	auto g = [](ll a, ll b) {
		return a + b;
	};
	auto h = [](ll a, ll b) { return a + b; };
	LazySegmentTree<ll, ll> seg_tree(f, g, h, 1e12, 0);
	seg_tree.build(std::vector<ll>(n, 0));
	for (int i = 0; i < q; ++i)
	{
		int c, s, t;
		ll x;
		std::cin >> c;
		if (c)
		{
			std::cin >> s >> t;
			std::cout << seg_tree.query(s, t + 1) << std::endl;
		}
		else
		{
			std::cin >> s >> t >> x;
			seg_tree.update(s, t + 1, x);
		}
	}
}


Measured memory_bytes: 7588
# coding:utf-8

import sys
# from collections import Counter, defaultdict

INF = float('inf')
MOD = 10 ** 9 + 7

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def SI(): return input()


S = SI()

for l in range(len(S)):
    for r in range(l, len(S)):
        tmp = S[:l] + S[r:]
        if tmp == 'keyence':
            print('YES')
            exit()

print('NO')


Measured memory_bytes: 3064
#include <iostream>
#include <sstream>
#include <vector>
using namespace std;
int main(void){
  int even, odd;
  vector<int> nmap(200);
  nmap.at(0) = 0;
  
  for(int i=1; i<101; i++){
    nmap.at(i) = i - 1 + nmap.at(i-1);
  }
  
  cin >> even >> odd;

  cout << nmap.at(even) + nmap.at(odd) << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define hi ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
#define pb push_back
#define emb emplace_back
#define mp make_pair
#define srt(a) sort(a.begin(), a.end())
#define rsort(a) sort(a.rbegin(), a.rend())
#define count(a, n) count(a.begin(), a.end(), n)
#define reverse(a) reverse(a.begin(), a.end())
#define F first
#define S second
#define pii pair<int, int>
#define vi vector<int>
#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define de(x) cout << #x << " is " << x << '\n'
typedef long long ll;
using namespace std;
int sum(int n)
{
    int x = 0;
    while (n >= 1)
    {
        x += n % 10;
        n /= 10;
    }
    return x;
}
int main()
{
    hi;
    int n, a, b;
    ll res = 0;
    cin >> n >> a >> b;
    rep(i, 1, n + 1)
    {
        if (sum(i) >= a && sum(i) <= b)
            res += i;
    }
    cout << res << '\n';
    return 0;
}


Measured memory_bytes: 256
n = int(input())
h = [int(i) for i in input().split()]

cur_list = [h[0]]
ans = 0
for cur_h in h[1:]:
    if cur_list[-1] >= cur_h:
        cur_list.append(cur_h)
    else:
        ans = max(ans, len(cur_list) - 1)
        cur_list = [cur_h]
ans = ans = max(ans, len(cur_list) - 1)

print(ans)


Measured memory_bytes: 14252
#pragma GCC optimize ("O2")
#pragma GCC target ("avx2")
//#include<bits/stdc++.h>
#include<iostream>
#include<algorithm>
#include<cstring>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please

const int cm = 1 << 17;
char cn[cm], * ci = cn + cm, ct;
inline char getcha() {
	if (ci - cn == cm) { fread_unlocked(cn, 1, cm, stdin); ci = cn; }
	return *ci++;
}
inline int getint() {
	int A = 0;
	if (ci - cn + 16 > cm) while ((ct = getcha()) >= '0') A = A * 10 + ct - '0';
	else while ((ct = *ci++) >= '0') A = A * 10 + ct - '0';
	return A;
}
const int dm = 1400000;
char dn[dm], * di = dn;
const int MAX = 20000;
class unko {
public:
	char C[MAX * 7 + 10], *K[MAX + 10];
	constexpr unko() : C(), K() {
		auto di = C + 3;
		C[0] = '0';
		C[0] = ' ';
		C[0] = '\n';
		K[0] = C;
		K[1] = di;
		rep1(i, MAX) {
			int X = i;
			int keta = 0;
			char c[10] = {};
			while (X) {
				*(c + keta) = '0' + X % 10;
				X /= 10;
				keta++;
			}
			for (int j = keta - 1; j >= 0; j--)* di++ = (*(c + j));
			*di++ = ' ';
			*di++ = '\n';
			K[i + 1] = di;
		}
	}
};
constexpr unko f;
inline void putint(int X) {
	if (X > 20000) {
		int ue = X / 10;
		for (auto i = f.K[ue]; *i != ' '; i++) *di++ = *i;
		*di++ = '0' + X % 10;
		*di++ = ' ';
	}
	else for (auto i = f.K[X]; *i != '\n'; i++)* di++ = *i;
}

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


	int N = getint(), K = getint();

	int A[200001];
	rep(i, N) A[i] = getint();
	ll owa = ll(N) * N;

	rep(p, K) {
		int B[200001] = {};
		rep(i, N) {
			B[max(0, i - A[i])]++;
			B[min(N, i + A[i] + 1)]--;
		}
		ll kei = B[0];
		A[0] = B[0];
		rep1(i, N - 1) {
			kei += (A[i] = A[i - 1] + B[i]);
		}
		if (kei == owa) break;
	}

	rep(i, N) putint(A[i]);
	fwrite(dn, 1, di - dn, stdout);

	Would you please return 0;
}

Measured memory_bytes: 7244
#include <bits/stdc++.h>
#define inf 1000000000
#define mod 1000000007
using namespace std;

int main(){
    int n;cin>>n;
    int a,b;cin>>a>>b;
    int ans=0;

    for(int i=1;i<=n;i++)
        if( a <= i%10+(i/10)%10+(i/100)%10+(i/1000)%10+(i/10000)%10&&
            b >= i%10+(i/10)%10+(i/100)%10+(i/1000)%10+(i/10000)%10)
            ans+=i;

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



Measured memory_bytes: 256
#include<stdio.h>

int main(void){
	int high[10];
	int temp, i, j;

	for(i = 0;i < 10;i++)
		scanf("%d", &high[i]);

	for(i = 0;i < 3;i++){
		for(j = i+1;j < 10;j++){
			if(high[i] < high[j]){
				temp = high[i];
				high[i] = high[j];
				high[j] = temp;
			}
		}
	}

	for(i = 0;i < 3;i++)
		printf("%d\n", high[i]);

	return 0;
}

Measured memory_bytes: 2756
#include<stdio.h>
#include<math.h>
int main(void){
long x,i,j;
  scanf("%ld",&x);
  int flag;
  for(i=x;;i++){
    flag=0;
for(j=2;j<=sqrt(i);j++){
  if(i%j==0){flag=1;
    break;
}
}
    if(!flag){printf("%ld",i);
              return 0;
             }
  }
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define int long long
#define double long double
#define mod 1000000007
#define F first
#define S second
#define P pair<long long,long long>
#define all(a) a.begin(),a.end()
#define INF 1000000000000000000
#define endl '\n'
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; }
using namespace std;

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n; cin>>n;
    vector<int> a(n);
    rep(i,n)cin>>a.at(i);
    sort(all(a));
    vector<int> sums(n);
    int sum=0;
    rep(i,n){
        sum+=a.at(i);
        sums.at(i)=sum;
    }
    reverse(all(sums));
    int ans=1;
    rep(i,n-1){
        if(sums.at(i+1)*3>=sums.at(i))ans++;
        else break;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
using P=pair<int,int>;
using ll=long long;

int main(){
    string s,t;
    cin>>s>>t;
    int ans=0;
    for(int i=0;i<(int)s.size();i++){
        if(s[i]!=t[i]) ans++;
    }

    cout<<ans<<endl;
}

Measured memory_bytes: 3912
// Copyright 2020 yaito3014
#include <bits/stdc++.h>

#include <boost/range/adaptors.hpp>

int main() {
  using namespace std;
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int N;
  cin >> N;
  vector<string> S(N);
  for (auto& e : S) cin >> e;
  vector<pair<int, int>> ps(N);
  transform(cbegin(S), cend(S), begin(ps), [](const string& s) {
    int A = 0, B = 0;
    for (char c : s) c == '(' ? ++B : B > 0 ? --B : ++A;
    return make_pair(A, B);
  });
  auto iter = partition(begin(ps), end(ps),
                        [](const auto& p) { return p.second >= p.first; });
  sort(begin(ps), iter,
       [](const auto& a, const auto& b) { return a.first < b.first; });
  sort(iter, end(ps),
       [](const auto& a, const auto& b) { return a.second > b.second; });
  vector<int> vec(N * 2);
  transform(cbegin(ps), cend(ps), begin(vec | boost::adaptors::strided(2)),
            [](const auto& p) { return -p.first; });
  transform(
      cbegin(ps), cend(ps),
      begin(vec | boost::adaptors::sliced(1, N) | boost::adaptors::strided(2)),
      [](const auto& p) { return p.second; });
  partial_sum(cbegin(vec), cend(vec), begin(vec));
  bool ans = all_of(cbegin(vec), cend(vec), [](int n) { return n >= 0; }) &&
             vec.back() == 0;
  cout << (ans ? "Yes" : "No") << endl;
}


Measured memory_bytes: 50024
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define VI  vector<ll>
#define lf(i,a,b) for(ll i=a;i<=b;i++)
const ll mod=1e9+7;
double pi = 2 * acos(0.0);
#define FASTIO ios_base::sync_with_stdio(false);cout.tie(NULL);cout.tie(NULL);
ll max(ll a, ll b) { return (a > b) ? a : b; }
ll min(ll a, ll b) { return (a < b) ? a : b; }
bool cmp(pair<ll,ll> a,pair<ll,ll> b)
{
    return (a.first)<(b.first);
}
ll power(ll a,ll b)
{
        ll p=1;
        for(ll i=1;i<=b;i++)
        p*=a;

        return p;
}
ll gcd(ll a, ll b){
    if (a == 0)
        return b;
    return gcd(b % a, a);
 }
void bfs(map<ll,vector<ll> > &g,ll src,vector<ll> &c)
{
    queue<ll> q;
    map<ll,ll> p;
    q.push(src);
    p[src]=src;
    c[src]=1;
    while(!q.empty())
    {
        ll u=q.front();
        q.pop();
        ll i=1;
        for(auto v:g[u])
        {
            if(c[v]==-1)
            {
                q.push(v);
                p[v]=u;
                if(i==c[u]||i==c[p[u]])
                    i++;
                if(i==c[u]||i==c[p[u]])
                    i++;
                c[v]=i;
                i++;
            }
        }
    }
}
ll dp[100005],a[105],n;
ll fun(ll k,ll m)
{

   dp[0]=0;
   ll i,j;
   for(j=1;j<=k;j++)
   {
       ll x=0;
       for(ll i=0;i<n;i++)
       {
           if(j-a[i]>=0)
           {
               if(dp[j-a[i]]==0)
               {
                   x=1;
                   break;
               }
           }
       }
       dp[j]=x;
   }
   return dp[k];
}
int main()
{
    FASTIO;
    ll k,i,m=INT_MAX;
    cin>>n>>k;
    for(i=0;i<n;i++)
        {
            cin>>a[i];
            m=min(m,a[i]);
        }
    if(fun(k,m))
         cout<<"First"<<endl;
    else cout<<"Second"<<endl;
    return 0;
}


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

using namespace std;

typedef long long ll;
typedef pair<ll, ll> Pll;
typedef pair<int, int> Pii;

const ll MOD = 1000000007;
const long double EPS = 1e-10;
const int dyx[4][2] = {
    { 0, 1}, {-1, 0}, {0,-1}, {1, 0}
};

vector<int> graph[10001];
vector<ll> d(10001, 0);
vector<int> used(10001, 0);

ll dfs(int node, int par) {
    used[node] = 1;
    ll ret = 0LL;
    for(int child: graph[node]) {
        if(child == par) continue;
        if(used[child]) continue;
        ret += min(d[node], d[child]) + dfs(child, node);
    }
    return ret;
}

int main() {
    std::ios::sync_with_stdio(0); cin.tie(0);
    int n, a, b;
    cin >> n;
    vector<int> degree(n, 0);
    for(int i=0;i<n-1;++i){
        cin >> a >> b;
        --a; --b;
        graph[a].push_back(b);
        graph[b].push_back(a);
        ++degree[a];
        ++degree[b];
    }
    vector<ll> c(n);
    for(int i=0;i<n;++i){
        cin >> c[i];
    }
    sort(c.rbegin(), c.rend());

    int root = int(max_element(degree.begin(), degree.end()) - degree.begin());

    int ci = 0;
    queue<Pii> que;
    que.emplace(root, -1);
    d[root] = c[ci++];
    while(!que.empty()) {
        Pii p = que.front(); que.pop();
        int node = p.first;
        int par = p.second;
        for(int child: graph[node]) {
            if(child == par) continue;
            if(d[child]) continue;
            que.emplace(child, node);
            d[child] = c[ci++];
        }
    }

    ll m = dfs(0, -1);
    cout << m << endl;
    for(int i=0;i<n-1;++i){
        cout << d[i] << " ";
    }
    cout << d[n-1] << endl;
}


Measured memory_bytes: 1920
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <cstring>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <bitset>
#include <stack>
#include <cmath>
#include <time.h>
#include <unordered_set>
#include <unordered_map>
#define ll long long
#define LINF 0x3f3f3f3f3f3f3f3f
#define INF 0x3f3f3f3f
#define PI 3.14159265
#define RAND (rand()*rand())
#define MAX(x, y) ((x) > (y) ? (x):(y)) 
#define MIN(x, y) ((x) > (y) ? (y):(x))
#define ABS(x) ((x) > 0 ? (x) : -(x))
#define CEIL(x, y) (((x) + (y) - 1)/(y))
using namespace std;
const int MAXN = 5e5 + 5;
const ll MOD = 1e9 + 7;
int N, M, K, Q, T;

int main() {
	int i, j;
	ll x;
	vector<pair<ll, ll>> vec;
	scanf("%lld", &x);
	for (ll d = 1ll; d * d <= x; ++d) {
		if (x % d == 0ll) {
			vec.push_back({ d, x / d });
		}
	}
	ll mini = LINF;
	for (i = 0; i < vec.size(); ++i) {
		mini = MIN(mini, vec[i].first + vec[i].second);
	}
	printf("%lld", mini - 2);
	return 0;
}

Measured memory_bytes: 384
#include <stdio.h>
#include <stdint.h>
#include <inttypes.h>
#include <stdlib.h>
#include <string.h>

typedef unsigned long long int uint64;
typedef long long int          int64;
 
#define MAX(a,b) ((a)>(b)?(a):(b))
#define MIN(a,b) ((a)<(b)?(a):(b))
#define ABS(a) ((a)>(0)?(a):-(a))

void get_N (int64 *n)
{
  int cnt;
  
  cnt = scanf("%lld", n);

  return;
}

void get_NK (int64 *n, int64 *k)
{
  int cnt;
  
  cnt = scanf("%lld %lld", n, k);

  return;
}

void omit_LF (void)
{
  char c;
  int  cnt;
  
  cnt = scanf("%c", &c);
  return;
}

char *get_S (int64 n)
{
  char *buf;
  int  i;
  int  cnt;

  buf = malloc((size_t)(n * sizeof(char)));
  if (buf == NULL) {
    return NULL;
  }

  cnt = scanf("%s", buf);

  return buf;
}

int main()
{
  int64 N = 101;
  char *str;
  int64 i;
  
  str = get_S(N);

  for (i=0; i<N; i++) {
    if (str[i] == '\0') break;
    str[i] = 'x';
  }

  printf("%s",str);

  return 0;
}



Measured memory_bytes: 128
n, a, b = map(int, input().split())
x = 0

for i in range(1, n+1):
  q = i // 10000
  qi = i % 10000
  w = qi // 1000
  wi = qi % 1000
  e = wi // 100
  ei = wi % 100
  r = ei // 10
  ri = ei % 10
  t = ri
  sum = q + w + e + r + t
  if sum >= a and sum <= b:
    x += i
    
print(x)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int INF = 1000000000000;
const int mod = 1000000007;
int test[12345678], aa[1234][1234], bb[1234][1234];
signed main() {
	int n, a, b, cnt = 1, ans = -100000000000;
	cin >> n;
    for (int h = 0; h < n; h++) {
        for (int i = 0; i < 10; i++) { cin >> aa[h][i]; }
    }
    for (int h = 0; h < n; h++) {
        for (int i = 0; i <= 10; i++) { cin >> bb[h][i]; }
    }
    for (int i = 0; i <= (1 << 10); i++) {
        vector<int> sep = { };
        for (int j = 0; j <= 9; j++) {
            if ((i & (1 << j)) > 0) {
                sep.push_back(j);
            }
        }
        if (sep.size() == 0) { continue; }
        int sum = 0;
        for (int h = 0; h < n; h++) {
            cnt = 0;
            for (int j = 0; j < sep.size(); j++) {
                if (aa[h][sep[j]] == 1) { cnt++; }
            }
            sum += bb[h][cnt];
        }
        ans = max(ans, sum);
    }
    cout << ans << endl;
	return 0;
}

Measured memory_bytes: 4736
#include <bits/stdc++.h>
using namespace std;
#define int long long
int mod = 2019;
int INF = (int)2e18;

signed main() {
    string S;
    cin >> S;
    vector<int> ans(S.length(), 0);
    int even = 0, odd = 0;
    int coordinate = -1;
    bool checkRL = false;
    for (int i = 0; i < S.length(); i++) {
        if (i % 2 == 0) ++even;
        else ++odd;
        if (checkRL && (S[i + 1] == 'R' || i == S.length() - 1)) {
            if (coordinate % 2 == 0) {
                ans[coordinate] = even;
                ans[coordinate + 1] = odd;
            } else {
                ans[coordinate] = odd;
                ans[coordinate + 1] = even;
            }
            even = 0;
            odd = 0;
            checkRL = false;
        }
        if (S[i] == 'R' && S[i + 1] == 'L') {
            checkRL = true;
            coordinate = i;
            if (i == S.length() - 2) {
                ans[i] = 1;
                ans[i + 1] = 1;
            }
        }
    }
    for (int i = 0; i < S.length(); i++) {
        if (i != S.length() - 1) {
            cout << ans[i] << " ";
        } else {
            cout << ans[i] << endl;
        }
    }
}

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

long long dp[61][2][2][2];// 桁数, L<=x 確定, x<=R 確定, 最上位bit確定
const long long mo = (long long) 1e9 + 7;

int main() {
  long long l, r;
  std::cin >> l >> r;
  for (int i = 0; i < 61; ++i)
    for (int j = 0; j < 2; ++j)
      for (int k = 0; k < 2; ++k)
	for (int s = 0; s < 2; ++s)
	  dp[i][j][k][s] = 0;
  dp[60][0][0][0] = 1;
  for (int i = 59; i >= 0; --i) {
    int lb = l >> i & 1;
    int ub = r >> i & 1;

    //pre-state
    for (int j = 0; j <= 1; ++j) {
      for (int k = 0; k <= 1; ++k) {
	for (int s = 0; s <= 1; ++s) {
	  if (dp[i + 1][j][k][s] == 0) continue;
	  // next x and y
	  for (int x = 0; x <= 1; ++x) {
	    for (int y = 0; y <= 1; ++y) {
	      if (x && !y) continue;
	      int nj = j, nk = k, ns = s;
	      if (!s && x != y) continue;
	      if (!j && lb && !x) continue;
	      if (!k && !ub && y) continue;
	      if (x && y) ns = 1;
	      if (!j && x && !lb) nj = 1;
	      if (!k && !y && ub) nk = 1;
	      dp[i][nj][nk][ns] += dp[i+1][j][k][s];
	      dp[i][nj][nk][ns] %= mo;
	    }
	  }
	}
      }
    }
  }
  long long ans = 0;
  for (int j = 0; j < 2; ++j)
    for (int k = 0; k < 2; ++k)
      for (int s = 0; s < 2; ++s)
      ans += dp[0][j][k][s];
  ans %= mo;
  std::cout << ans << std::endl;
}


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

#define ll long long

using namespace std;

const int mod = (int)1e9 + 7;
const int N = (int)3e5 + 7;

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

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

int h, w, a, b;
int fact[N], rfact[N];

int binpow(int a, int n) {
  int res = 1;
  while (n) {
    if (n & 1)
      res = mul(res, a);
    a = mul(a, a);
    n >>= 1;
  }
  return res;
}

void precalc() {
  fact[0] = 1;
  for (int i = 1; i < N; i++) {
    fact[i] = mul(fact[i - 1], i);
  }
  rfact[N - 1] = binpow(fact[N - 1], mod - 2);
  for (int i = N - 2; i >= 0; i--) {
    rfact[i] = mul(rfact[i + 1], i + 1);
  }
}

int cnk(int n, int k) {
  return mul(fact[n], mul(rfact[n - k], rfact[k]));
}

int get(int n, int m) {
  return cnk(n + m - 2, n - 1);
}

main() {
  precalc();
  scanf("%d %d %d %d", &h, &w, &a, &b);
  int ans = 0;
  for (int i = b + 1; i <= w; i++) {
    ans = add(ans, mul(get(h - a, i), get(a, w - i + 1)));
  }
  cout << ans;
}


Measured memory_bytes: 2560
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
    int n;
    cin >> n;
    vector<int> a(n);
    for(int i=0;i<n;i++)cin >> a[i];
    sort(a.begin(),a.end());
    cout << a[n-1] - a[0] << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <complex>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <numeric>
#include <cstring>
#include <ctime>
#include <cstdlib>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <cmath>
#include <bitset>
#include <cassert>
#include <queue>
#include <stack>
#include <deque>
#include <random>
#include <iomanip>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<P,P> PP;
const ll MOD=1000000007;
const ll MAX_N=500010;
const ll INF=100100100100100;

int main(){
	ll n,m;
	cin>>n>>m;
	map<ll,ll> mp;
	ll a=0;
	mp[0]=1;
	ll ans=0;
	for(int i=0;i<n;i++){
		ll aa;
		cin>>aa;
		a+=aa;
		a%=m;
		if(mp.count(a)==0){
			mp[a]=1; 
			continue;
		}
		ans+=mp[a];
		mp[a]++;
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 6920
#include <bits/stdc++.h>
  #define endl "\n"
  #define ll long long int
  #define vi vector<int>
  #define vll vector<ll>
  #define vvi vector < vi >
  #define pii pair<int,int>
  #define pll pair<long long, long long>
  #define mod 1000000007
  #define inf 1000000000000000001;
  #define all(c) c.begin(),c.end()
  #define mp(x,y) make_pair(x,y)
  #define mem(a,val) memset(a,val,sizeof(a))
  #define pb push_back
  #define f first
  #define se second
  
  using namespace std;
  ll arr[100005][3];
  ll dp[100005][3];

  ll func(ll x,ll y,ll n){
    if(x>=n)
      return 0;
    if(dp[x][y]!=-1 && y!=-1)
      return dp[x][y];

    ll sum1=0,sum2=0,sum3=0,sum=0;

    if(y!=0)
      sum1=arr[x][0]+func(x+1,0,n);
    
    if(y!=1)
      sum2=arr[x][1]+func(x+1,1,n);
    
    if(y!=2)
      sum3=arr[x][2]+func(x+1,2,n);
    
    sum=max({sum1,sum2,sum3});
    dp[x][y]=sum;

    return sum;
  }

  int main()
  {
    std::ios::sync_with_stdio(false);
    ll n=0,m=0,k=0,x=0,t1=0,t2=0,t3=0,f=0,sum=0,count=0;

    cin>>n;
    mem(arr,0);
    mem(dp,-1);

    for (ll i = 0; i < n; ++i){
      for (ll j = 0; j < 3; ++j)
      {
        cin>>arr[i][j];
      }
    }

    cout<<func(0,-1,n);


    return 0;
  }

Measured memory_bytes: 15988
#include<bits/stdc++.h>
using namespace std;
using Int = long long;

template<typename T> void chmin(T &a,T b){if(a>b) a=b;}
template<typename T> void chmax(T &a,T b){if(a<b) a=b;}

//INSERT ABOVE HERE
signed main(){
  Int n;
  cin>>n;
  using P = pair<Int, Int>;
  vector<P> v;
  for(Int i=0;i<n;i++){
    Int a,b;
    cin>>a>>b;
    v.emplace_back(b,a);
  }
  sort(v.begin(),v.end());
  const Int INF = 1e8;
  vector<Int> dp(n+1,INF);
  dp[0]=0;
  for(Int i=0;i<n;i++)
    for(Int j=n-1;j>=0;j--)
      if(dp[j]+v[i].second<=v[i].first)
	chmin(dp[j+1],dp[j]+v[i].second);
  
  for(Int i=n;i>=0;i--){
    if(dp[i]!=INF){
      cout<<i<<endl;
      return 0;
    }
  }
  return 0;
}



Measured memory_bytes: 3108
maxn=10**5+10
n=int(input())
a=[None]*(n+10)
b=[0]*maxn
c=[0]*maxn
a[1:n+1]=input().split()

for i in range(1,n+1):
    a[i]=int(a[i])
    if i%2==0:
        b[a[i]]+=1
    else:
        c[a[i]]+=1

max1=max2=maxp=0
for i in range(1,maxn):
    if b[i]>=max1:
        max2=max1
        maxp=i
        max1=b[i]
    elif b[i]>=max2:
        max2=b[i]

ans=n
for i in range(1,maxn):
    res=((n+1)//2-c[i])
    if i==maxp:
        res+=n//2-max2
    else:
        res+=n//2-max1
    ans=min(ans,res)

print(ans)

Measured memory_bytes: 13636
#include <iostream>
#include <cmath>
#include <vector>
#include <string>
#include <algorithm>

using namespace std;

#define INF 1e9
#define ll long long
#define vi vector<int>
#define vll vector<long long>
#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)

string S;

void solve(){
    if(S[0] == S[1] && S[1]==S[2]) cout << "Yes" << endl;
    else if (S[1]==S[2] && S[2]==S[3]) cout << "Yes" << endl;
    else cout << "No" << endl;
}

int main(){
    cin >> S;

    solve();
}


Measured memory_bytes: 256
#include <algorithm>
#include <iostream> //標準入出力
#include <fstream>  //ファイルでの入出力
#include <vector>
#include <queue>
#include <functional>
#include <string>
#include <utility> //pair
#include <cmath>  //sqrt 
#include <iomanip> //setprecision
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long
#define ALL(a)  (a).begin(),(a).end()
#define MAX 1000000
#define pair(a) pair<a,a>

int bfs(vector<string>& field,int fb){
    int h=field.size(),w=field[0].size();
    vector<vector<int>> dfroms(h,vector<int>(w,-1));
    queue<pair(int)> later;
    const int dx[4]={0,0,1,-1},dy[4]={1,-1,0,0}; //東西南北の順

    later.push({0,0});
    dfroms[0][0] = 1;

    while(!later.empty()){
        pair(int) now = later.front();
        int x = now.first, y = now.second;
        later.pop();
        rep(i,4){
            pair(int) next = {x+dx[i],y+dy[i]};
            int nx = next.first,ny = next.second;
            if(nx<0||nx>=h||ny<0||ny>w) continue;
            if(field[nx][ny]=='#') continue;
            if(dfroms[nx][ny]==-1){
                dfroms[nx][ny] = dfroms[x][y] + 1;
                later.push(next);
            }
        }
    }
    int out = h*w - dfroms[h-1][w-1] - fb;
    if(dfroms[h-1][w-1] == -1) return -1;
    else return out;
}

void _main(){
    int h,w;
    cin >> h >> w;
    vector<string> field; 
    field.resize(h);
    rep(i,h) cin >> field[i];
    int firstblack = 0;
    rep(i,h) rep(j,w) if(field[i][j]=='#') firstblack++;
    cout << bfs(field,firstblack) << endl;
    
    return;
}
int main() {
    cout << fixed << setprecision(10);
    _main();
    return 0;
}
    

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

int main (){
  int h,w;
  do{
  cin >> h >> w;
  for (int i = 0; i<w; i++){
    cout << '#' ;
  }
  if (h!=0 && w!=0){
  cout << endl;
  }
  for (int i = 2; i<h; i++){
    for (int j = 0; j<w; j++){
      if(j==0 || j==w-1){
        cout << '#';
      } else {
        cout << '.';
      }
    }
    cout << endl;
  }
  
for (int i = 0; i<w; i++){
    cout << '#' ;
}
if (h!=0 && w!=0){
  cout << endl;
  }
  if (h!=0 && w!=0){
  cout << endl;
  }
  }while (h!=0 && w!=0);

  return 0;
}


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

int main() {
	int N,M,X,Y;
	int tmp;
	cin >> N >> M >> X >> Y;
	for (int i=0; i<N; i++) {
		cin >> tmp;
		if (tmp>X) X=tmp;
	}
	for (int i=0; i<M; i++) {
		cin >> tmp;
		if (tmp<Y) Y=tmp;
	}
	if (X>=Y) cout << "War" << endl;
	else cout << "No War" << endl;
	return 0;
}


Measured memory_bytes: 256
while True :
    n, k, m = map(int, input().split())
    if n == 0 and k == 0 and m == 0 :
        break
    
    stone = []
    for i in range(n) :
        stone.append(i+1)
        
    i = m-1
    while True :
        del stone[i]
        if len(stone) == 1 :
            break
        i += k-1
        if i >= len(stone) :
            i = i % len(stone)
    print(stone[0])
    


Measured memory_bytes: 5924
from sys import stdin

numberOfDays = input()
a = []
b = []
c = []

for days in stdin:
    values = days.split(' ')
    a.append(int(values[0]))
    b.append(int(values[1]))
    c.append(int(values[2]))

maxHapNA = [0]
maxHapNB = [0]
maxHapNC = [0]
for day in range(0, len(a)):
    maxHapNA.append(max((maxHapNB[day] + b[day]), (maxHapNC[day] + c[day])))
    maxHapNB.append(max((maxHapNA[day] + a[day]), (maxHapNC[day] + c[day])))
    maxHapNC.append(max((maxHapNA[day] + a[day]), (maxHapNB[day] + b[day])))

print(max(maxHapNA[-1], maxHapNB[-1], maxHapNC[-1]))

Measured memory_bytes: 26804
#include <cstdio>
#include <cstring>
using namespace std;

typedef long long int64;

const int MAX_W = 50000;
const int MAX_Q = 50000;

int H, W, Q;
int ts[MAX_Q], as[MAX_Q], cmd[MAX_Q];
bool visited[2][MAX_W];

bool init(){
	scanf("%d%d%d", &H, &W, &Q);
	for(int i=0; i<Q; i++){
		scanf("%d%d%d", ts+i, as+i, cmd+i);
	}
	memset(visited, false, sizeof(visited));
	return H>0;
}

int64 solve(){
	int64 ret = 0;
	int64 count[2];
	count[0] = count[1] = 0;
	for(int i=Q-1; i>=0; i--){
		int t = ts[i], x = as[i];
		if(visited[t][x]){
			continue;
		}
		visited[t][x] = true;
		count[t]++;
		if(cmd[i] == 1){
			ret += (t == 0 ? W : H) - count[1 - t];
		}
	}

	return ret;
}

int main(){
	while(init()){
		printf("%lld\n", solve());
	}

	return 0;
}

Measured memory_bytes: 1452
import sys
import math
import bisect
import heapq
import copy
sys.setrecursionlimit(1000000)
from collections import deque
from itertools import permutations

class SCC:

    def __init__(self,n):
        self.n = n
        self.Edge = [[] for _ in range(n)]
        self.REdge = [[] for _ in range(n)]
        self.vs = []
        self.used = [False]*n
        self.order = [0]*n

    def add_edge(self,from_,to):
        self.Edge[from_].append(to)
        self.REdge[to].append(from_)

    def dfs(self,v):
        self.used[v] = True
        for u in self.Edge[v]:
            if not self.used[u]:
                self.dfs(u)
        self.vs.append(v)

    def rdfs(self,v,k):
        self.used[v] = True
        self.order[v] = k
        for u in self.REdge[v]:
            if not self.used[u]:
                self.rdfs(u,k)

    def compute(self):
        self.used = [False]*self.n
        self.vs.clear()
        for i in range(self.n):
            if not self.used[i]:
                self.dfs(i)
        self.used = [False]*self.n
        k = 0
        for i in reversed(self.vs):
            if not self.used[i]:
                self.rdfs(i,k)
            k+=1
        return k


def main():
    v,e = map(int,input().split())
    scc = SCC(v) 
    for _ in range(e):
        a,b = map(int,input().split())
        scc.add_edge(a,b)
    k = scc.compute()
    n = int(input())
    for _ in range(n):
        a,b = map(int,input().split())
        print (int(scc.order[a]==scc.order[b]))


if __name__ == '__main__':
    main()




Measured memory_bytes: 20068
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#define x first
#define y second
#define pb push_back
#define mp make_pair
#define all(v) v.begin(),v.end()
#define sz(v) (int)v.size()
#define up_b upper_bound
#define low_b lower_bound
#define nl '\n'

using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef long double ld;

typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;

const int N=1e5+11;
const int M=1e6+11;
const int inf=1e9+1;
const ld EPS=1e-6;
const ll INF=1e18;
const ll mod=/*998244353*/1e9+7;
const int dx[4]={0,0,-1,1};
const int dy[4]={-1,1,0,0};

int main(){
  ios_base::sync_with_stdio(0);
  cin.tie(0),cout.tie(0);
  int a,b,c,k;
  cin>>a>>b>>c>>k;
  if(b<=a){
    while(b<=a){
      k--;
      b*=2;
    }
  }
  if(c<=b){
    while(c<=b){
      k--;
      c*=2;
    }
  }
  if(k>=0)cout<<"Yes";
  else cout<<"No";
}


Measured memory_bytes: 3648
#include <bits/stdc++.h>
#define int long long

using namespace std;
using LL = long long;
using P = pair<int, int>;

#define FOR(i, a, n) for(int i = (int)(a); i < (int)(n); ++i)
#define REP(i, n) FOR(i, 0, n)

#define pb(a) push_back(a)
#define all(x) (x).begin(),(x).end()

const int INF = (int)1e9;
const LL INFL = (LL)1e15;
const int MOD = 1e9 + 7;

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

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

    int n;
    cin >> n;
    vector<int> a(n), b(n);
    REP(i, n) cin >> a[i];

    REP(i, n) {
        b[i] = (a[i] - (i+1));
    }
    
    sort(all(b));
    int ans = INF;
    int mid = b[n/2];
    int sum = 0;
    REP(i, n) sum += abs(b[i] - mid);
    cout << sum << endl;
}


Measured memory_bytes: 3456
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define P pair<int,int>
#define fi first
#define se second
#define rep(i,n) for(int i=0;i<n;i++)
#define all(v) v.begin(),v.end()
#define pb push_back
template<class T>void chmax(T &a,T b){if(a<b)a=b;}
template<class T>void chmin(T &a,T b){if(a>b)a=b;}
constexpr int INF=2000000000000000000;
constexpr int mod=998244353;
int dx[]={0,1,0,-1},dy[]={1,0,-1,0};
int kaijo[2000010];
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;
}
bool prime(int a){
    if(a==1)return false;
    for(int i=2;i*i<=a;i++){
        if(a%i==0)return false;
    }
    return true;
}
void init_fact(){
    kaijo[0]=1;
    for(int i=1;i<=2000000;i++){
        kaijo[i]=kaijo[i-1]*i;
        kaijo[i]%=mod;
    }
}
int modpow(int a,int b){
    if(b==0)return 1;
    if(b%2)return modpow(a,b-1)*a%mod;
    int memo=modpow(a,b/2);
    return memo*memo%mod;
}
int comb(int a,int b){
    if(!kaijo[0])init_fact();
    return kaijo[a]*modpow(kaijo[a-b],mod-2)%mod*modpow(kaijo[b],mod-2)%mod;
}
int inv(int x){
    x=modpow(x,mod-2);
    return x;
}
bool kosa(double ax,double ay,double bx,double by,double cx,double cy,double dx,double dy){
    double ta=(cx-dx)*(ay-cy)+(cy-dy)*(cx-ax);
    double tb=(cx-dx)*(by-cy)+(cy-dy)*(cx-bx);
    double tc=(ax-bx)*(cy-ay)+(ay-by)*(ax-cx);
    double td=(ax-bx)*(dy-ay)+(ay-by)*(ax-dx);
    return tc*td<0&&ta*tb<0;
}
int n;
int K;
vector<P>v[100010];
bool used[100010];//edge
int ans[100010];
void dfs(int x,int cl){
    used[x]=true;
    int now=1;
    for(P p:v[x]){
        if(used[p.fi])continue;
        if(now==cl)now++;
        ans[p.se]=now;
        dfs(p.fi,now);
        now++;
    }
}
signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin>>n;
    rep(i,n-1){
        int a,b;
        cin>>a>>b;
        a--,b--;
        v[a].pb({b,i});
        v[b].pb({a,i});
    }
    rep(i,n){
        chmax(K,(int)v[i].size());
    }
    dfs(0,-1);
    cout<<K<<endl;
    rep(i,n-1)cout<<ans[i]<<endl;
    return 0;
}



Measured memory_bytes: 9856
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <cmath>
#include <algorithm>
#define rep(i, a, b) for (int i = (a), _ = (b); i <= _; ++ i)
#define per(i, a, b) for (int i = (a), _ = (b); i >= _; -- i)
#define For(i, a, b) for (int i = (a), _ = (b); i < _; ++ i)
#define fore(e, u, v) for (int p = e(u), v = e[p].y; p; v = e[p = e[p].nxt].y)
#define ri rd<int>
using namespace std;
const int maxN = 2e5 + 7;

template<class T> inline T rd() {
	bool f = 1; char c = getchar(); for (; !isdigit(c); c = getchar()) if (c == '-') f = 0;
	T x = 0; for (; isdigit(c); c = getchar()) x = x * 10 + c - 48; return f ? x : -x;
}

inline void NIE() { puts("-1"); exit(0); }

int n, m;
int a[maxN], b[maxN];
int occa[maxN], occb[maxN];
bool vis[maxN]; int cc, tag;
int res = 0;

struct vec {
	static const int maxE = maxN;
	int g[maxN], te;
	struct edge {int y, nxt;} e[maxE << 1];
	inline void push(int x, int y) { e[++te] = (edge){y, g[x]}; g[x] = te; }
	inline void link(int x, int y) { push(x, y), push(y, x); }
	inline int& operator () (int x) { return g[x]; }
	inline edge& operator [] (int x) { return e[x]; }
}e;

void gao() {
	static int val[maxN];
	rep (i, 1, n) val[i] = a[i], val[i+n] = b[i];
	val[m = 2*n+1] = a[n+1];
	sort(val+1, val+m+1);
	m = unique(val+1, val+m+1) - (val+1);
	rep (i, 1, n+1) a[i] = lower_bound(val+1, val+m+1, a[i]) - val;
	rep (i, 1, n) b[i] = lower_bound(val+1, val+m+1, b[i]) - val;
}

void dfs(int x) {
	vis[x] = 1;
	if (x == a[n+1]) tag = 1;
	fore (e, x, y) {
		if (!vis[y]) dfs(y);
		++ cc;
	}
}

int main() {

	n = ri();
	rep (i, 1, n) a[n+1] ^= (a[i] = ri());
	rep (i, 1, n) b[i] = ri();
	gao();

	memset(occa, 0, sizeof occa); memset(occb, 0, sizeof occb);
	rep (i, 1, n) ++ occa[a[i]], ++ occb[b[i]]; ++occa[a[n+1]];
	rep (i, 1, m) if (occa[i] > occb[i]) {
		if (occa[i] > occb[i] + 1) NIE();
		if (b[n+1]) NIE();
		b[n+1] = i;
	}

	memset(occa, 0, sizeof occa); memset(occb, 0, sizeof occb);
	rep (i, 1, n+1) ++ occa[a[i]], ++ occb[b[i]];
	rep (i, 1, m) if (occa[i] != occb[i]) NIE();

	rep (i, 1, n+1) if (a[i] != b[i]) e.link(a[i], b[i]);
	rep (i, 1, m) if (!vis[i]) {
		cc = 0, tag = 0; dfs(i);
		cc >>= 1; 
		if (cc > 1) res += tag ? cc - (a[n+1] != b[n+1]) : cc + 1;
	}

	printf("%d\n", res);

	return 0;
}

Measured memory_bytes: 8704
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,l,r) for(long long i=(l);i<(r);++i)
#define REP(i,n) FOR(i,0,n)
#define int long long

signed main(){
    int N,ans,Ma;
    bool before;
    ans=Ma=0;
    cin>>N;
    int h[N];
    REP(i,N){
        cin>>h[i];
        Ma=max(Ma,h[i]);
    }
    REP(i,Ma){
        before=false;
        REP(j,N){
            if(h[j]>0){
                h[j]--;
                if(before==false){
                    ans++;
                    before=true;
                }
            }
            else before=false;
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a),i##_len=(b);i<i##_len;++i)
#define BUGAVOID(x) x
#define rep(...) BUGAVOID(_overload3(__VA_ARGS__,repi,_rep,_rep)(__VA_ARGS__))
#define all(c) c.begin(),c.end()
#define mp make_pair
#define write(x) cout<<(x)<<"\n"
using namespace std; typedef long long ll;
typedef vector<int> vi; typedef vector<ll> vll; template<class T>using vv = vector<vector<T>>;
template<class T>vv<T> vvec(size_t n, size_t m, T v) { return vv<T>(n, vector<T>(m, v)); }
template<class T>bool chmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }
template<class T>bool chmin(T& a, const T& b) { return b < a ? a = b, 1 : 0; }
constexpr int INF = 1 << 28, MOD = 1e9 + 7; constexpr ll LINF = 1ll << 60; constexpr double EPS = 1e-6;
struct aaa { aaa() { cin.tie(0); ios::sync_with_stdio(0); }; }aaaa;

int N, K;
vi A;
vv<ll> dp;

int main() {
    cin >> N >> K;
    A.resize(N);
    rep(i, N) cin >> A[i];
    sort(all(A));
    int M = (lower_bound(all(A), K) - A.begin());
    
    dp.resize(M + 1, vector<ll>(K + 1, 0));
    int ng = -1;
    int ok = M;
    while (abs(ok - ng) > 1) {
        int mid = (ng + ok) / 2;

        rep(i, M + 1) {
            rep(j, K + 1) dp[i][j] = 0;
        }
        dp[0][0] = 1;

        rep(i, 0, M) {
            if (i == mid) {
                rep(j, 0, K + 1) {
                    dp[i + 1][j] = dp[i][j];
                }
            }
            else {
                rep(j, 0, K - A[i] + 1) {
                    dp[i + 1][j] += dp[i][j];
                    dp[i + 1][j + A[i]] += dp[i][j];
                }
                rep(j, K - A[i] + 1, K + 1) {
                    dp[i + 1][K] += dp[i][j];
                }
            }
        }

        bool b = false;
        rep(i, K - A[mid], K) {
            if (dp[M][i] > 0) b = true;
        }

        if (b) ok = mid;
        else ng = mid;
    }

    write(ok);
}

Measured memory_bytes: 195840
#include <bits/stdc++.h>
#define rep(i,cc,n) for(int i=cc;i<=n;++i)
#define drep(i,cc,n) for(int i=cc;i>=n;--i)
#define sz(s) (int)(s.size())
#define vecprint(v) rep(i,0,v.size()-1)cout << v[i] << " ";cout << endl;
using namespace std;
const int mod=1000000007;
typedef long long ll;
typedef pair<int,int> P;
bool IsPrime(ll num)
{
    if (num < 2) return false;
    else if (num == 2) return true;
    else if (num % 2 == 0) return false; // 偶数はあらかじめ除く

    double sqrtNum = sqrt(num);
    for (ll i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            // 素数ではない
            return false;
        }
    }

    // 素数である
    return true;
}
int main(){
    ll x;
    cin >> x;
    ll ans;
    while(true){
        if(IsPrime(x)){
            cout << x << endl;
            return 0;
        }
        ++x;
    }

    // cout << ans << endl;
//  printf("%.10f\n",ans);

    return 0;
}

Measured memory_bytes: 256
#include<vector>
#include<iostream>
#include<string>
#include<algorithm>
#include<numeric>


int main(){
    int N,K;
    std::cin >> N >> K;
    if((N - 1) * (N - 2) /2 < K ) return puts("-1") * 0;
    std::vector<std::vector<int>>connect(N);
    for(int i = 1; i < connect.size(); ++i){
        connect[0].push_back(i);
        connect[i].push_back(0);
    }
    int crt = (N - 1) * (N - 2) / 2;
    for(int i = 0; i < crt - K; ++i){
        bool Exist = false;
        for(int v = 0; v < N and not Exist; ++v){
            for(int u = 0; u < N and not Exist; ++u){
                if(u == v ) continue;
                auto& nu = connect[u];
                if(std::find(nu.begin(),nu.end(),v) == nu.end()){
                    nu.push_back(v);
                    connect[v].push_back(u);
                    Exist = true;
                }
            }
        }
        if(not Exist)
            return puts("-1") * 0;
    }
    int sum = 0;
    for(auto v : connect)
        sum += v.size();
    std::cout << sum / 2 << std::endl;
    int cv = 0;
    for(auto v : connect ){
        for(auto e : v){
            if(cv < e) std::cout <<  cv + 1 << " " << e + 1 << std::endl;
        }
        ++cv;
    }
}




Measured memory_bytes: 384
#include <bits/stdc++.h>
#include <math.h>
#define _GLIBCXX_DEBUG
#define _LIBCPP_DEBUG 0

using namespace std;
#define ll long long
#define rep(i,n) for (int i = 0; i < n; i++)
#define MOD (1000000007)
#define vi vector<int>
#define vvi vector<vi>
#define pii pair<int, int>
#define pb push_back
#define mp make_pair
#define all(a) (a).begin(),(a).end()

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

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

const ll INF = 1LL << 60;

const int dh[4] = {1,0,-1,0};
const int dw[4] = {0,1,0,-1};

int main(){
  int H, W; cin >> H >> W;
  vector<string> s(H); rep(h, H) cin >> s[h];

  vvi dist(H, vi(W, -1));
  queue<pii> q;
  dist[0][0] = 1;// 最短経路で踏む.の数を数えたいから1スタート
  q.push(mp(0, 0));

  while (!q.empty()) {
    pii v = q.front(); q.pop();
    int h = v.first;
    int w = v.second;
    rep(dir, 4){
      int nh = h + dh[dir];
      int nw = w + dw[dir];
      if(nh < 0 || nh == H || nw < 0 || nw == W) continue;
      if(s[nh][nw] == '#' || dist[nh][nw] != -1) continue;
      dist[nh][nw] = dist[h][w] + 1;
      q.push(mp(nh, nw));
    }
  }

  int cnt = 0;//.の数
  rep(h, H) rep(w, W) if(s[h][w] == '.') cnt++;

  int ans;
  if(dist[H-1][W-1] == -1) ans = -1;
  else ans = cnt - dist[H-1][W-1];

  std::cout << ans << '\n';
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef set<int> si;
typedef pair<int,int> pii;
#define rep(i,a,b) for(int i=(a); i<(b); ++i)
#define per(i,a,b) for(int i=(b)-1; i>=(a); --i)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define F first
#define S second

const ll INF = 1e18;

struct RMQ {
    int n;
    vl rangeMin;
    RMQ(const vl& array) {
        n = array.size();
        rangeMin.resize(n * 4);
        init(array, 0, n-1, 1);
    }
    ll init(const vl& array, int left, int right, int node) {
        if(left == right)
            return rangeMin[node] = array[left];
        int mid = (left + right) / 2;
        ll leftMin = init(array, left, mid, node * 2);
        ll rightMin = init(array, mid + 1, right, node * 2 + 1);
        return rangeMin[node] = min(leftMin, rightMin);
    }
    ll query(int left, int right, int node, int nodeLeft, int nodeRight) {
        if(right < nodeLeft || nodeRight < left) return INF;
        if(left <= nodeLeft && nodeRight <= right)
            return rangeMin[node];
        int mid = (nodeLeft + nodeRight) / 2;
        return min(query(left, right, node*2, nodeLeft, mid),
            query(left, right, node*2+1, mid+1, nodeRight));
    }
    ll query(int left, int right) {
        return query(left, right, 1, 0, n-1);
    }
    ll update(int index, ll newValue, int node, int nodeLeft, int nodeRight) {
        if(index < nodeLeft || nodeRight < index) 
            return rangeMin[node];
        if(nodeLeft == nodeRight) return rangeMin[node] = newValue;
        int mid = (nodeLeft + nodeRight) / 2;
        return rangeMin[node] = min(
            update(index, newValue, node*2, nodeLeft, mid),
            update(index, newValue, node*2+1, mid+1, nodeRight));
    }
    ll update(int index, ll newValue) {
        return update(index, newValue, 1, 0, n-1);
    }
};


int main(void) {
	ios_base::sync_with_stdio(false); cin.tie(0);
	//freopen("in.txt", "r", stdin);
	int n, m;
	cin >> n >> m;
	vector<pair<pii, ll> > v(m);
	rep(i,0,m) {
		ll l, r, c;
		cin >> l >> r >> c;
		--l; --r;
		v[i] = mp(mp(l,r), c);
	}
	vl d(n, INF);
	d[0] = 0;
	RMQ myR(d);
	sort(all(v));
	rep(i,0,m) {
		int l = v[i].F.F;
		int r = v[i].F.S;
		ll c = v[i].S;

		ll lc = myR.query(l,n-1);
		ll rc = myR.query(r,r);
		if(lc + c < rc) {
			myR.update(r, lc+c);
		}
	}
	ll ret = myR.query(n-1,n-1);
	if(ret == INF) {
		cout << -1 << '\n';
	} else {
		cout << ret << '\n';
	}
	return 0;
}


Measured memory_bytes: 5632