akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <stdint.h> // int64_t

#define max(a,b) ((a) > (b) ? (a) : (b))
#define min(a,b) ((a) > (b) ? (b) : (a))

int get_int(void) {
  int num;
  scanf("%d", &num);
  return num;
}

int get_int2(int *a1, int *a2) {
  scanf("%d %d", a1, a2);
  return 0;
}

#define NUM_MAX 100000
#define POINT_MAX (NUM_MAX*10)

struct point2d {
    int x;
    int y;
};

int asc(const void *a1, const void *a2) {
    struct point2d *p1 = (struct point2d*)a1;
    struct point2d *p2 = (struct point2d*)a2;
    if(p1->x == p2->x) {
        return p1->y - p2->y;
    }
    return p1->x - p2->x;
}

int check(struct point2d p, int row, int col) {
    if(p.x < 0 || p.y < 0) return 0;
    if(p.x >= row-2 || p.y >= col-2) return 0;
    return 1;
}

#define HASH_SIZE 65536

struct list {
    struct point2d p;
    int idx;
    int cnt;
    struct list *next;
};

struct list *create_htable(void) {
    static struct list htable[HASH_SIZE];
    int i;
    for(i = 0; i < HASH_SIZE; i++) {
        htable[i].next = &htable[i];
    }
    return htable;
}

int is_equal(struct point2d p1, struct point2d p2) {
    return p1.x == p2.x && p1.y == p2.y;
}

int get_key(struct point2d p) {
    return (p.x*p.y+p.x+p.y) & (HASH_SIZE-1);
}

struct list* find(struct list *htable, struct point2d p) {
    struct list *head = &htable[get_key(p)];
    struct list *elem;
    for(elem = head->next; elem != head; elem = elem->next) {
        if(is_equal(elem->p, p)) {
            return elem;
        }
    }
    return NULL;
}

int find_cnt(struct list *htable, struct point2d p) {
    struct list *elem = find(htable, p);
    return elem->cnt;
}

void add_elem(struct list *htable, struct point2d p) {
    struct list *elem = find(htable, p);
    if(elem) {
        elem->cnt++;
        return;
    }
    elem = malloc(sizeof(struct list));
    struct list *head = &htable[get_key(p)];
    elem->next = head->next;
    elem->p = p;
    elem->cnt = 1;
    head->next = elem;
}

int64_t sum_up(struct list *htable, int64_t *map) {
    int64_t sum = 0;
    int i;
    for(i = 0; i < HASH_SIZE; i++) {
        struct list *head = &htable[i];
        struct list *elem;
        for(elem = head->next; elem != head; elem = elem->next) {
            map[elem->cnt]++;
            sum++;
        }
    }
    return sum;
}

int main(void) {
    int row, col, num;
    get_int2(&row, &col);
    num = get_int();
    int i, j, k;
    struct list* htable = create_htable();
    for(k = 0; k < num; k++) {
        int x, y;
        get_int2(&x, &y);
        // 1-indexed -> 0-indexed
        x--; y--;
        // put into stack
        for(i = 0; i <= 2; i++) {
            for(j = 0; j <= 2; j++) {
                struct point2d np = (struct point2d){x-i, y-j};
                if(check(np, row, col)) {
                    add_elem(htable, np);
                }
            }
        }
    }
    static int64_t map[10];
    int64_t rem = sum_up(htable, map);
    map[0] = (int64_t)(row-2)*(col-2) - rem;
    for(i = 0; i < 10; i++) {
        printf("%lld\n", map[i]);
    }
    return 0;
}

Measured memory_bytes: 29824
n = int(input())

def collatz(n):
    c = 0
    while not n in (4, 2, 1):
        if n % 2 == 0:
            n = n/2
        else:
            n = n * 3 + 1
        c += 1
        # print(n)
    return c

print(collatz(n) + 4)


Measured memory_bytes: 2940
#include <iostream>
#include <vector>
using namespace std;
 
int main(void){
    int N;
    vector<int> a;
 
    cin >> N;
    a.resize(N);
    for (int i=0; i<N; i++) {
        cin >> a[i];
    }
    
    int colorFlg[10] = {0,};
    int nmaxPoint=0;
    for (int i=0; i<N; i++) {
        if (a[i]>=3200) {
            nmaxPoint++;
        } else {
            colorFlg[a[i]/400] = 1;
        }
    }
    
    int min=0;
    for (int i=0; i<8; i++) {
        min += colorFlg[i];
    }
    int max = min + nmaxPoint;
    if (min==0) min=1;
    
    cout << min << " " << max << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <math.h>
#include <queue>
using namespace std;
typedef long long ll;
#define PI 3.14159265359

int main() {
  ll H, W, M, h, w;
  cin >> H >> W >> M;
  set<pair<ll,ll>> m;
  vector<ll> hh(H, 0);
  vector<ll> ww(W, 0);

  ll h_max = 0, w_max = 0;
  for (auto i = 0;i < M;i ++) {
    cin >> h >> w;
    h --;
    w --;
    hh[h] ++;
    ww[w] ++;
    m.insert(make_pair(h, w));
    h_max = max(hh[h], h_max);
    w_max = max(ww[w], w_max);
  }
  vector<int> w_index;
  w_index.reserve(W);
  for (auto k = 0;k < W;k ++) {
    if (ww[k] == w_max) {
      w_index.push_back(k);
    }
  }
  for (auto i = 0;i < H;i ++) {
    if (hh[i] != h_max) {
      continue;
    }
    for (auto k = w_index.begin();k < w_index.end();k ++) {
      if (m.count(make_pair(i, *k)) == 0) {
        cout << h_max + w_max << endl;
        return 0;
      }
    }
  }
  cout << h_max + w_max - 1 << endl;
  return 0;
}

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

typedef long int lint;
typedef long long int llint;

#define EACH(i, c) for (__typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define ALL(c) (c).begin(), (c).end()
#define FOR(i, s, e) for (int i = (s); i < (int)(e); ++i)
#define REP(i, n) FOR(i, 0, n)
#define endl "\n";

template<typename T>
void print(const std::vector<T>& v, char sep=' ') {
  for (int i = 0; i < (int)v.size(); i++) {
    if (i != 0) cout << sep;
    cout << v[i];
  }
  cout << endl;
}

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  string str;
  stack<char> s;
  cin >> str;

  REP(i, str.size()){
    if (str[i] != 'B'){
      s.push(str[i]);
    }
    else if (str[i] == 'B' && !(s.empty())){
      s.pop();
    }
  }
  str = "";
  while (!(s.empty())){
    str += s.top();
    s.pop();
  }

  reverse(ALL(str));
  cout << str << endl;

}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <unordered_set>
#include <unordered_map>
using namespace std;
 
#define FIND(c, e) ((c).find(e) != (c).end())
#define NFIND(c, e) ((c).find(e) == (c).end())
#define ALL(t) (t).begin(), (t).end()
#define ALLR(t) (t).rbegin(), (t).rend()
#define MP make_pair

const int N = int( 1e5 ) + 1;
const int M = int( 1e6 ) + 1;
const int MOD = int( 1e9 ) + 7;
const double PI = acos(-1.0);
const double eps = 1e-6;
template<class T> T gcd(T a,T b){while(b){T r=a%b;a=b;b=r;}return a;}
template<class T> T lcm(T a,T b){return (a*b)/gcd(a,b);}
template<class T> T max(T a,T b,T c){return max(max(a,b),c);}
template<class T> T min(T a,T b,T c){return min(min(a,b),c);}

struct graph {
	int vertices;
	int edges;
	vector< vector<int> > adj;
	vector< bool > visited;
	vector< int > level;
	graph() { }
	graph(int vertices) {
		this->adj.resize(vertices + 1);
		this->level.resize(vertices + 1, -1);
		this->visited.resize(vertices + 1, false);
		this->vertices = vertices;
		this->edges = 0;
	}
	void add_directed_edge(int from, int to) {
		this->adj[from].emplace_back(to);
		this->edges++;
	}	
	void add_undirected_edge(int from, int to) {
		this->adj[from].emplace_back(to);
		this->adj[to].emplace_back(from);
		this->edges += 2;
	}
	void read_undirected_edges(int edge_count) {
		this->edges += edge_count << 1;
		for (int i = 0; i < edge_count; i++) {
			int from, to;
			cin >> from >> to;
			this->adj[from].emplace_back(to);
			this->adj[to].emplace_back(from);
		}
	}	
	void read_directed_edges(int edge_count) {
		this->edges += edge_count;
		for (int i = 0; i < edge_count; i++) {
			int from, to;
			cin >> from >> to;
			this->adj[from].emplace_back(to);
		}
	}
	void dfs(int src) {
		this->visited[src] = true;
		for(int i : this->adj[src]) {
			if(this->visited[i] == false) {
				this->dfs(i);
			}
		}
	}
	void bfs(int src) {
		this->level[src] = 0;
		queue<int> q;
		q.push(src);
		while (!q.empty()) {
			int cur = q.front();
			q.pop();
			for(int i : this->adj[cur]) {
				if(this->level[i] == -1) {
					this->level[i] = this->level[cur] + 1;
					q.push(i);
				}
			}
		}
	}
};
void __answer()
{
	int n, m;
	cin >> n >> m;
	graph g(n);
	g.read_undirected_edges(m);
	g.bfs(1);
	cout << (g.level[n] == 2 ? "POSSIBLE" : "IMPOSSIBLE");
}  
int main()
{
    ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
	cout.precision(11);
    #ifdef LOCAL
        freopen("sample_input.txt", "r", stdin);
        // freopen("data.txt", "w", stdout);
        // freopen("log.txt", "w", stderr);
    #endif
    __answer();
    return 0;
}  

Measured memory_bytes: 13168
/*  CREATED BY
    STREAM_CIPHER
    7-aug-2020
*/
#include<bits/stdc++.h>
using namespace std;
#define int long long int
#define double long double
#define debug1(a) cout<<#a<<"="<<(a)<<"\n"
#define debug2(a,b) cout<<#a<<"="<<(a)<<","<<#b<<"="<<(b)<<"\n"
#define debug3(a,b,c) cout<<#a<<"="<<(a)<<","<<#b<<"="<<(b)<<","<<#c<<"="<<(c)<<"\n"
#define fix_precision(n) cout << fixed << setprecision(n)
#define all(a) a.begin(),a.end()
const double pi=acos(-1.0);
int inf=0x3f3f3f3f3f3f3f3f;
const int mod=1e9+7;
const int mx=5*1000000;
int dp[3009][3009];
int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    #ifndef ONLINE_JUDGE
        freopen("input.txt","r",stdin);
        // freopen("output.txt","w",stdout);
    #endif
        string a,b;
        cin>>a>>b;
        vector<char>aa,bb;
        for(auto i:a)
            aa.push_back(i);
        for(auto i:b)
            bb.push_back(i);
        // int ans1[6000]={0};
        for(int i=0;i<=a.size();i++)
        {
            for(int j=0;j<=b.size();j++)
            {
                // cout<<aa[i]<<" "<<bb[j]<<endl;
                if(i==0||j==0)
                    continue;
                if(aa[i-1]==bb[j-1])
                    dp[i][j]=max(dp[i-1][j-1]+1,dp[i][j]);
                else
                    dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
            }
        }
    int i=a.size(),j=b.size();
    vector<char>ans;
    while(i>0&&j>0)
    {
        if(aa[i-1]==bb[j-1])
            ans.push_back(aa[i-1]),i--,j--;
        else
            if(dp[i-1][j]>dp[i][j-1])
                i--;
            else
                j--;
    }
    reverse(all(ans));
    for(auto i:ans)
        cout<<i;
}

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

int main()
{
    int a, b, c;
    cin >> a >> b >> c;
    
    int ab = a+b;
    
    if (ab > c){
        cout << b + c << endl;
    }
    else {
        if (ab + 1 < c)
            c = ab + 1;
        cout << b + c << endl;
    }

    return 0;
}


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

#ifdef LOCAL
#include "debug.h"
#else
#define DEBUG(...)
#endif

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  long long a, b, n;
  cin >> a >> b >> n;
  auto res = a * min(b - 1, n) / b;
  cout << res << '\n';
}


Measured memory_bytes: 3660
#include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include<set>
using namespace std;

int main(){
  int N, Q;
  cin >> N >> Q;

  // person q is stopped by construction i
  // S_i <= D_q + X_i < T_i
  // S_i - X_i <= D_q < T_i - X_i
  // for i of smallest X_i

  vector<pair<int, pair<int, int>>> X_interval(N);
  for(int i = 0; i < N; i++){
    int s, t, x;
    cin >> s >> t >> x;
    X_interval[i] = make_pair(x, make_pair(s - x, t - x));
  }

  vector<int> D(Q);
  for(auto& x: D){
    cin >> x;
  }
  
  vector<pair<int, pair<int, bool>>> time_x_add;
  for(int i = 0; i < N; i++){
    int x = X_interval[i].first;
    int begin_time = X_interval[i].second.first, end_time = X_interval[i].second.second;
    time_x_add.push_back(make_pair(begin_time, make_pair(x, true)));
    time_x_add.push_back(make_pair(end_time, make_pair(x, false)));
  }
  sort(time_x_add.begin(), time_x_add.end());
  
  int next_event_idx = 0;
  set<int> X;
  for(int q = 0; q < Q; q++){
    while(next_event_idx < 2 * N && time_x_add[next_event_idx].first <= D[q]){
      int x = time_x_add[next_event_idx].second.first;
      bool add = time_x_add[next_event_idx].second.second;
      if(add){
        X.insert(x);
      }else{
        X.erase(x);
      }
      next_event_idx++;
    }
    if(X.size() > 0){
      cout << *X.begin() << endl;
    }else{
      cout << -1 << endl;
    }
  }

}



Measured memory_bytes: 18412
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll ZERO = 0;
const ll INF = 1e14;
const ll MOD = 1000000007;
const double PI = 3.1415926535897;

int main() {
    int N;
    cin >> N;
    string S;
    cin >> S;
    int ret = 0;
    for(int i = 0;i < N - 2;i++) {
        if(S.at(i) == 'A' && S.at(i + 1) == 'B' && S.at(i + 2) == 'C') {
            ret++;
        }
    }
    cout << ret << endl;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> P;
#define rep(i,n) for(ll i=0;i<n;++i)
const ll INF=1e18+1;

int main(){
  ll n,k;
  cin>>n>>k;
  vector<ll> a(n);
  vector<ll> f(n);
  rep(i,n){
    cin>>a[i];
  }
  rep(i,n){
    cin>>f[i];
  }
  sort(a.begin(),a.end());
  sort(f.rbegin(),f.rend());
  ll l,r;
  l=-1;r=1e12;

//  int cnt=INF;
  while (l+1<r){
    ll c=(l+r)/2;
  //  cout<<c<<endl;
    ll cnt=0;
    rep(i,n){
      cnt+=max(0ll,a[i]-c/f[i]);
    }
    if (cnt<=k) r=c;
    else l=c;
  
  //  cout<<c<<' '<<l<<' '<<r<<endl;

  }
  cout<<r;




  }


Measured memory_bytes: 3328
#!/usr/bin/env python3
import sys, math, itertools, collections, bisect
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
inf = float('inf')
ans = 0 ;count = 0 ;pro = 1

a,b,c=map(int,input().split())
print("YES" if b-a==c-b else "NO")

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

int main(){
    int N, C;
    cin >> N >> C;
    vector<vector<int>> D(C, vector<int>(C));
    vector<vector<int>> c(N, vector<int>(N));
    for(int i=0; i<C; i++)
        for(int j=0; j<C; j++)
            cin >> D[i][j];
    for(int i=0; i<N; i++)
        for(int j=0; j<N; j++)
            cin >> c[i][j];

    if(N == 1){
        cout << 0 << endl;
        return 0;
    }
    vector<vector<int>> v(3, vector<int>(C, 0));
    for(int i=0; i<C; i++){
        for(int j=0; j<N; j++){
            for(int k=0; k<N; k++){
                int l = (j + k) % 3;
                v[l][i] += D[c[j][k]-1][i];
            }
        }
    }
    int ans = 1<<30;
    for(int i=0; i<C; i++)
        for(int j=0; j<C; j++)
            for(int k=0; k<C; k++){
                if(i == j || j == k || k == i) continue;
                int tmp = v[0][i] + v[1][j] + v[2][k];
                ans = min(ans, tmp);
            }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
#define modulo 1000000007
#define mod(mod_x) ((((long long)mod_x+modulo))%modulo)
#define Inf 100000000

struct unionfind{
	vector<int> data;
	vector<int> size;
	unionfind(int n){
		for(int i=0;i<n;i++){
			data.push_back(i);
			size.push_back(1);
		}
	}
	
	int find(int x){
		if(data[x]==x)return x;
		return data[x]=find(data[x]);
	}
	
	bool unite(int x,int y){
		x=find(x);y=find(y);
		if(x==y)return false;
		data[x]=y;
		size[y]+=size[x];
		return true;
	}
	
	bool check(int x,int y){
		return (find(x)==find(y));
	}
	
	int get_size(int x){
		int X = find(x);
		return size[X];
	}
};

int main(){
	
	int N,K,L;
	cin>>N>>K>>L;
	
	unionfind uf1(N),uf2(N);
	
	for(int i=0;i<K;i++){
		int a,b;
		cin>>a>>b;
		a--;b--;
		uf1.unite(a,b);
	}
	
	for(int j=0;j<L;j++){
		int a,b;
		cin>>a>>b;
		a--;b--;
		uf2.unite(a,b);

	}
	
	map<pair<int,int>,int> mp;
	
	for(int i=0;i<N;i++){
		mp[make_pair(uf1.find(i),uf2.find(i))]++;
	}
	for(int i=0;i<N;i++){
		if(i!=0)cout<<' ';
		cout<<mp[make_pair(uf1.find(i),uf2.find(i))];
	}
	
	return 0;
}


Measured memory_bytes: 15124
N = int(input())
S = input()

black = 0
black_counts = [0]*N
white = 0
white_counts = [0]*N
for i in range(N):
    if S[i] == '#':
        black += 1
    black_counts[i] = black

    if S[-1-i] == '.':
        white += 1
    white_counts[N-1-i] = white

min_count = min(black_counts[N-1], white_counts[0])
for i in range(N-1):
    min_count = min(min_count, black_counts[i] + white_counts[i+1])
print(min_count)

Measured memory_bytes: 12800
#C - Prison
N,M = map(int, input().split())
L = [list(map(int, input().split())) for i in range(M)]
a_max = 0
b_min = 10**9
for i in range(M):
    if b_min >= L[i][1]:
        b_min = L[i][1]
    else:
        pass
    if a_max <= L[i][0]:
        a_max = L[i][0]
    else:
        pass

if a_max > b_min:
    print(0)
else:
    print(b_min - a_max + 1)

Measured memory_bytes: 60120
#include <iostream>
#include <vector>
#include <cmath>

int main() {
  unsigned N;
  std::cin >> N;
  auto X = N;
  unsigned logN = 1;
  while (X) {
    ++logN;
    X >>= 1;
  }
  std::vector<unsigned> x(N);
  std::vector<std::vector<unsigned>> reach(logN, std::vector<unsigned>(N));
  for (unsigned i = 0; i < N; ++i) {
    std::cin >> x[i];
  }
  unsigned L;
  std::cin >> L;
  unsigned start = 0;
  for (unsigned i = 1; i < N; ++i) {
    while (start < i) {
      if (x[i] - x[start] <= L) {
        reach[0][start] = i;
        break;
      } else {
        reach[0][start] = i - 1;
        ++start;
      }
    }
  }
  for (unsigned i = start + 1; i < N; ++i) {
    reach[0][i] = N - 1;
  }
  for (unsigned r = 1; r < logN; ++r) {
    for (unsigned i = 0; i < N; ++i) {
      reach[r][i] = reach[r - 1][reach[r - 1][i]];
    }
  }
  unsigned Q;
  std::cin >> Q;
  for (unsigned i = 0; i < Q; ++i) {
    unsigned a, b;
    std::cin >> a >> b;
    if (a > b) { std::swap(a, b); }
    --a;
    --b;
    unsigned sum = 0;
    unsigned ans = 0;
    for (unsigned j = logN; j-- > 0; ) {
      if (reach[j][a] < b) {
        a = reach[j][a];
        sum += std::pow(2u, j);
      } else if (reach[j][a] >= b) {
        ans = sum + std::pow(2u, j);
      }
    }
    std::cout << ans << std::endl;
  }
  return 0;
}

Measured memory_bytes: 9848
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
#define MAX 100000
int main()
{
	string str;
	
	string str2;

	cin >> str;
	
	for (int i = 0; i < str.length(); i++)
	{
		
		str2 += str[i];
		i++;
	}
	
	cout << str2;
	
}



Measured memory_bytes: 512
// author : Saumitra Tripathi
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define pb push_back
#define m_p make_pair
void solve()
{
    ll n;
    cin>>n;
    double arr[n+10],dp[n+10][n+10];
    for(int i=1;i<=n;i++)
        cin>>arr[i];
    dp[0][0]=1;
    for(int i=1;i<=n;i++)
    {
        dp[0][i]=0;
    }
    for(int i=1;i<=n;i++)
    {
        for(int j=0;j<=i;j++)
        {
            if(j==0)
                dp[i][j]=dp[i-1][j]*(1-arr[i]);
            else
            {
                dp[i][j]=dp[i-1][j-1]*arr[i]+dp[i-1][j]*(1-arr[i]);
            }
        }
    }
    double ans=0;
    for(int i=0;i<=n;i++)
    {
        if(i>(n-i))
        {
            ans+=dp[n][i];
        }
    }
    printf("%0.9lf",ans);
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

    solve();
}

Measured memory_bytes: 49964
import java.util.Scanner;

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

	int h = scan.nextInt();
	int w = scan.nextInt();
	String[] s = new String[h+2];
	for(int i = 1; i < h+1; i++){
	    s[i] = scan.next();
	}

	/* 上端と下端 */
	s[0] = "#";
	s[h+1] = "#";

	/* '#'追加操作 */
	for(int i = 0; i < h+2; i++){
	    if(i == 0 || i == h+1){
		for(int j = 0; j < w+1; j++){
		    s[i] += "#";
		}
	    }else{
		s[i] = "#"+s[i]+"#";
	    }
	}

	/* 出力 */
	for(int i = 0; i < h+2; i++){
	    System.out.println(s[i]);
	}
    }
}	


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

using namespace std;

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

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

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

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

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

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

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

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

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


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

struct edge{
    int cost, to;

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

int main() {
    int N;
    cin >> N;
    vector<int>A(N), B(N), C(N);
    ll a_sum=0LL, b_sum=0LL;
    rep(i,N){
        cin >> A[i];
        a_sum+=A[i];
    }
    rep(i,N){
        cin >> B[i];
        b_sum+=B[i];
    }

    if(b_sum>a_sum) {
        cout << -1 << endl;
        return 0;
    }

    rep(i,N){
        C[i]=A[i]-B[i];
    }

    sort(C.begin(), C.end());

    ll need=0LL;
    auto minusp=C.begin();
    for(auto itr=C.begin(); itr<lower_bound(C.begin(),C.end(), 0); itr++ ){
        need+=abs(*itr);
        minusp=itr;
    }

    if(need==0) {
        cout << 0 << endl;
        return 0;
    }
    ll give=0LL;
    int index=N-1;
    while(C[index]+give<need){
        give+=C[index];
        index--;
    }
    cout << N-index+(minusp-C.begin()+1) << endl;
    return 0;
}


Measured memory_bytes: 1408
#include<stdio.h>
int A[1000000],n;

int search(int k){
  int l = 0;
  int r = n;
  int m;

  
  while(l<r) {
    m = (l+r)/2;
    if(k == A[m]) return 1;
    if(k > A[m]) l = m + 1;
    else if (k < A[m]) r = m;
  }
  
    return 0;
  }


int main(){
  int i,q,k,sum=0;

  scanf("%d",&n);
  for(i=0;i<n;i++) scanf("%d",&A[i]);
  
  scanf("%d",&q);
  for(i=0;i<q;i++){
    scanf("%d",&k);
    if(search(k)) sum++;
  }

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

  return 0;
}




Measured memory_bytes: 2144
#include <stdio.h>
#define MAX_N 101

double t[MAX_N], v[MAX_N];

double max(double a, double b)
{
    return a > b? a: b;
}

double min(double a, double b)
{
    return a < b? a: b;
}

int main(void)
{
    int n;
    scanf("%d", &n);
    for (int i = 0; i < n; i++)
        scanf("%lf", &t[i]);
    for (int i = 0; i < n; i++)
        scanf("%lf", &v[i]);
    double cur = 0.;
    double ans = 0.;
    for (int i = 0; i < n; i++) {
        double inc, kep, dec;
        double lim = 1.E8;
        double tmp = 0.;
        for (int j = i + 1; j <= n; j++) {
            lim = min(lim, v[j] + tmp);
            tmp += t[j];
        }
        inc = min(v[i] - cur, (lim + t[i] - cur) * .5);
        inc = min(inc, t[i]);
        dec = max(0., cur + inc - lim);
        kep = t[i] - inc - dec;
        ans += .5 * (cur * 2. + inc) * inc;
        ans += (cur + inc) * kep;
        ans += .5 * ((cur + inc) * 2. - dec) * dec;
        cur += inc;
        cur -= dec;
    }
    printf("%f\n", ans);
    return 0;
}

Measured memory_bytes: 128
S = input()

if S == "SAT":
    print(1)
elif S == "FRI":
    print(2)
elif S == "THU":
    print(3)
elif S == "WED":
    print(4)
elif S == "TUE":
    print(5)
elif S == "MON":
    print(6)
elif S == "SUN":
    print(7)


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

const int MAX_A = 1000005;

int main() {
    int N;
    cin >> N;
    vector<int> A(N);
    vector<int> c(MAX_A);
    rep(i, N) {
        cin >> A[i];
        c[A[i]]++;
    }

    bool pairwise = true;
    for (int i = 2; i < MAX_A; i++) {
        int cnt = 0;
        for (int j = i; j < MAX_A; j += i) {
            cnt += c[j];
        }
        if (cnt > 1) pairwise = false;
    }

    if (pairwise) {
        cout << "pairwise coprime" << endl;
        return 0;
    }

    int g = 0;
    rep(i, N) g = gcd(g, A[i]);
    if (g == 1) {
        cout << "setwise coprime" << endl;
        return 0;
    }

    cout << "not coprime" << endl;

    return 0;
}

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

int main() {
  int N,D;
  cin>>N>>D;
  
  vector<vector<int>> vec(N, vector<int>(D));
  for(int i=0;i<N;i++){
    for(int j=0;j<D;j++){
      cin>>vec.at(i).at(j);
    }
  }
  int kai=0;
  for(int i=0;i<N;i++){
    for(int j=i;j<N;j++){
      int64_t sum=0;
      for(int k=0;k<D;k++){
        sum+=(vec.at(i).at(k)-vec.at(j).at(k))
          *(vec.at(i).at(k)-vec.at(j).at(k));
      }
      for(int m=1;m<=1000;m++){
        if(m*m==sum){
          kai++;
          break;
        }
      }
    }
  }
  cout<<kai<<endl;      
        

}

Measured memory_bytes: 3620
l, r = map(int, input().split())

if r - l >= 2019:
    print(0)
else:
    m = 2019
    for i in range(l, r + 1, 1):
        for j in range(i+1, r + 1, 1):
            m = min(i * j % 2019, m)
    print(m)

Measured memory_bytes: 9120
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        B solver = new B();
        solver.solve(1, in, out);
        out.close();
    }

    static class B {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            // 入力
            int x = Integer.parseInt(in.next());

            long max = Integer.MIN_VALUE;
            long pw = 0;
            if (x == 1) {
                out.println(1);
                return;
            }
            for (int i = 31; i >= 2; --i) {
                for (int j = 10; j >= 2; --j) {
                    pw = (long) Math.pow(i, j);
                    if (pw <= x) {
                        max = Math.max(pw, max);
                    }
                }
            }
            out.println(max);

        }

    }
}



Measured memory_bytes: 22996
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String aStr = sc.next();
		String bStr = sc.next();
		int a = Integer.parseInt(aStr);
		int b = Integer.parseInt(bStr);
		if(a == b) {
			System.out.println("a == b");
		} else if(a > b) {
			System.out.println("a > b");
		} else {
			System.out.println("a < b");
		}
		sc.close();
	}
}

Measured memory_bytes: 26288
#include "bits/stdc++.h"
// Custom Header {{{
#define ALL(x) x.begin(), x.end()
#define rep(i, s, n)      for(int i(s); i < int(n); ++i)
#define endl '\n'
#ifndef YDK
#define eprintf(...)
#endif
using namespace std;
using i64 = long long;
using pii = pair<i64, i64>;
template<class A, class B>inline bool chmax(A &a, const B &b){return b>a ? a=b,1 : 0;}
template<class A, class B>inline bool chmin(A &a, const B &b){return b<a ? a=b,1 : 0;}
constexpr const int INF  = 0x3f3f3f3f;
constexpr const i64 LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr const int MOD  = int(1e9) + 7;
// }}}

// Library {{{

// }}}

i64 dist(pii a, pii b)
{
    return abs(a.first - b.first) + abs(a.second - b.second);
}

signed main()
{
    int N; cin >> N;

    int nowtime = 0;
    pii nowpos(0, 0);

    bool able = true;
    for (int i = 0; i < N; ++i) {
        int t, x, y;
        cin >> t >> x >> y;

        i64 td = t - nowtime;
        i64 d = dist(pii(x, y), nowpos);

        td -= d;
        if (td < 0 || (td & 1)) able = false;
    }

    cout << ((able) ? "Yes" : "No") << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int a[100005],n;
int v[100005];
int main()
{
	while(~scanf("%d",&n))
	{
		bool flag=0;int mi=1e9,ma=0;
		for(int i=1;i<=n;++i)
		{
			scanf("%d",&a[i]);
			mi=min(mi,a[i]);
			ma=max(ma,a[i]);
			v[a[i]]++;
			if(i>1&&a[i]!=a[i-1])flag=1;
		}
		if(ma-mi>1)puts("No");
		else if(!flag)
		{
			if(ma==n-1)puts("Yes");
			else
			{
				if(n/2>=mi)puts("Yes");
				else puts("No");
			}
		}
		else
		{
			if(v[mi]+v[ma]/2>=ma&&ma>v[mi])puts("Yes");
			else puts("No");
		}
	}
	return 0;
}

Measured memory_bytes: 1024
n,m=map(int,input().split())
tasks=[None]*n
for i in range(n):
  a,b=map(int,input().split())
  tasks[i]=[a,b]

tasks=sorted(tasks,key=lambda x:x[0])
import heapq
que=[]
ans=0
heapq.heapify(que)
j=0
for i in range(m,-1,-1):
  left=m-i
  while j<len(tasks):
    if tasks[j][0]<=left:
      heapq.heappush(que, tasks[j][1]*(-1))
    else:
      break
    j+=1
  if len(que)>0:
    val=heapq.heappop(que)*(-1)
    ans+=val
      
print(ans)


Measured memory_bytes: 24140
#include <stdio.h>
#include <math.h>

#define true 1
#define false 0

int IsPrime(int n){
    if(n < 2) return false;
    else if(n==2) return true;
    else if(n%2 == 0) return false;
    
    double sqrtNum = sqrt(n);
    for (int i = 3; i <= sqrtNum; i += 2){
        if (n % i == 0){
            return false;
        }
    }
    return true;
}




int main(){
    
    int num=1,i,cnt,sum;
    
   while(1){
        scanf("%d",&num);
        if(num == 0){
            break;
        }
        cnt = 2;
        sum = 0;
        while(num>0){
            if(IsPrime(cnt)==true){
                sum += cnt;
                num--;
            }
            cnt++;
        }
        printf("%d\n",sum);
    }

	return 0;
}



Measured memory_bytes: 2076
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cstdlib>
#include<queue>
#include<set>
#include<cstdio>

using namespace std;

#define ll long long
#define rep(i, n) for(int i = 0; i < n; i++)
#define P pair<int, int>

typedef vector<int> vec;
typedef vector<vec> mat;

const ll mod = 1000000007;

int main(){
    string s;
    cin >> s;
    s += 'R';
    int num = 1;
    int idx;
    int ans[s.size()];
    fill(ans, ans + s.size(), 0);
    char c = 'R';
    for (int i = 1; i <= s.size(); i++){
        if(c == s[i]) num++;
        else{
            if(c == 'R'){
                idx = i;
                ans[idx] += num / 2;
                ans[idx-1] += num - (num / 2);
                c = 'L';
                num = 1;
            }else{
                ans[idx-1] += num / 2;
                ans[idx] += num - (num / 2);
                c = 'R';
                num = 1;
            }
        }
    }
    rep(i, s.size()-1){
        cout << ans[i] << " ";
    }cout << endl;
}

Measured memory_bytes: 4068
#!/usr/bin/env fsharpi

open System;

let ParseIntN ( str : string ) =
    str.Split(' ')
    |> Array.map System.Int32.Parse

let ParseInt1 ( str : string ) =
    ParseIntN str |> fun arr -> arr.[0]

let ParseInt2 ( str : string ) =
    ParseIntN str |> fun arr -> (arr.[0],arr.[1])

let ParseInt3 ( str : string ) =
    ParseIntN str |> fun arr -> (arr.[0],arr.[1],arr.[2])

let ReadLinesN ( n : int ) =
    fun _ -> Console.ReadLine()
    |> Seq.initInfinite
    |> Seq.take n

let ReadLines =
    fun _ -> Console.ReadLine()
    |> Seq.initInfinite
    |> Seq.takeWhile ((<>) null)

module Primes =
    let mutable primes = [7; 5; 3; 2]
    let mutable upper_bound = 7

    let rec create (n : int) : int list =
        for i = upper_bound + 1 to n do
            if isPrime i then
                primes <- i :: primes
            upper_bound <- i
        done
        List.filter ((>=) n) primes

    and isPrime (n : int) : bool = 
        n / 2
        |> create
        |> List.forall (fun p -> n % p <> 0)

    let factorize (n : int) : int list =
        let rec doit (n : int) (primes : int list) (factors : int list) : int list =
            match primes with
            | hp::tp -> if n % hp = 0 then
                            doit (n / hp) primes (hp::factors)
                        else
                            doit n tp factors
            | [] -> factors
        let primes = create n
        doit n primes []

let n = ParseInt1 <| Console.ReadLine()
let primes = Primes.create n
let counts = new System.Collections.Generic.Dictionary< int, int>()
primes
|> List.iter (fun p -> counts.[p] <- 1)
counts.[1] <- 1

[2 .. n]
|> List.map Primes.factorize
|> List.iter (fun ps -> List.iter (fun p -> counts.[p] <- counts.[p] + 1 ) ps )

counts.Values
|> Seq.fold (fun acc c -> (acc * int64(c)) % 1000000007L) 1L
|> Console.WriteLine


Measured memory_bytes: 15708
#coding=UTF-8

N=int(input())
mozir=input()
hyo=mozir.split(' ')

Rec_LTR=[int(mono) for mono in hyo]

mozir=input()
hyo=mozir.split(' ')

Rec_RTL=[int(mono) for mono in hyo]

LTR_hani=[]
highest=0
for idx in range(0,N,1):
    if Rec_LTR[idx]>highest:
        highest=Rec_LTR[idx]
        LTR_hani.append([highest,highest])
    else:
        LTR_hani.append([highest,1])

RTL_hani=[None]*N
highest=0
for idx in range(N-1,-1,-1):
    if Rec_RTL[idx]>highest:
        highest=Rec_RTL[idx]
        RTL_hani[idx]=[highest,highest]
    else:
        RTL_hani[idx]=[highest,1]

#concat
ans=1
hou=1000000007
for idx in range(0,N,1):
    # prod set
    ue=min(RTL_hani[idx][0],LTR_hani[idx][0])
    shita=max(RTL_hani[idx][1],LTR_hani[idx][1])
    ans=(ans*max((ue-shita+1),0))%hou

print(ans)


Measured memory_bytes: 39744
#include<bits/stdc++.h>
#define ALL(v) std::begin(v),std::end(v)
using lint=long long;
using ld=long double;
template<class T>using numr=std::numeric_limits<T>;
int main(){
    std::cin.tie(nullptr);std::ios_base::sync_with_stdio(false);
    std::cout.setf(std::ios_base::fixed);std::cout.precision(15);
    lint h,w;std::cin>>h>>w;
    std::vector<lint>a(26);
    for(lint i=0;i<h*w;i++){
        char c;std::cin>>c;
        a.at(c-'a')++;
    }
    std::cout<<(
        std::count_if(ALL(a),[](lint x){return x%2;})<=1
        &&std::count_if(ALL(a),[](lint x){return !(x%2)&&x%4;})<=(h/2)*(w%2)+(w/2)*(h%2)
        ?"Yes":"No")<<'\n';
}


Measured memory_bytes: 384
#include <iostream>
#include <algorithm>
using namespace std;
using int64 = int64_t;

const int64 INF = 1e18;

inline void fastin(int64 &num){
  int64 c;
  num = 0;
  c = getchar_unlocked();
  for (; (c > 47 && c < 58); c = getchar_unlocked()) num = (num << 3) + (num << 1) + c - 48;
}

inline void fastout(int64 &n){
  int64 N = n, rev, count = 0;
  rev = N;
  if (N == 0) {putchar_unlocked('0'); putchar_unlocked('\n'); return;}
  while ((rev % 10) == 0) {++count; rev /= 10;}
  rev = 0;
  while (N != 0) {rev = (rev << 3) + (rev << 1) + N % 10; N /= 10;}
  while (rev != 0) {putchar_unlocked(rev % 10 + '0'); rev /= 10;}
  while (count--) putchar_unlocked('0');
}

int main(){
  int64 a, b, q; fastin(a), fastin(b), fastin(q);
  int64 s[a + 2], t[b + 2];

  s[0] = -1 * INF; t[0] = -1 * INF; s[a + 1] = INF; t[b + 1] = INF;

  for (int i = 1; i <= a; ++i) fastin(s[i]);
  for (int i = 1; i <= b; ++i) fastin(t[i]);

  for (int i = 0; i < q; ++i){
    int64 x; fastin(x);
    auto pos1 = lower_bound(s, s + a + 2, x);
    auto pos2 = lower_bound(t, t + b + 2, x);

    int64 ans = min({max(*pos1 - x, *pos2 - x), 
		     max(x - *(pos1 - 1), x - *(pos2 - 1)),
		     2 * (*pos1 - x) + x - *(pos2 - 1),
		     *pos1 - x + 2 * (x - *(pos2 - 1)),
		     2 * (*pos2 - x) + x - *(pos1 - 1),
		     *pos2 - x + 2 * (x - *(pos1 - 1))}); 
    fastout(ans); putchar_unlocked('\n');
  }
  
  return 0;
}


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

int main()
{
    int n,l;
    cin>>n>>l;
    int arr[n+5];
    long long counter=1e8,sum=0,p=0;
    for(int i=1;i<=n;i++)
    {
        arr[i]=(i+l)-1;
        sum+=arr[i];
    }
//cout<<sum<<endl;

//for(int i=1;i<=n;i++)cout<<arr[i]<<" ";cout<<"\n";

    for(int i=1;i<=n;i++)
    {
     if(counter>abs(sum-(sum-arr[i])))
     {
         p=sum-arr[i];
         counter =abs( sum - (sum-arr[i]));
     }
    }
   cout<<p<<endl;
}


Measured memory_bytes: 384
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef long double ld;
const int inf=1e9+7;
const ll longinf=1LL<<60;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define F first
#define S second

const int mx=1000010;
const ll mod=1e9+7;


int main(){
  string s;
  cin >> s;
  int n = s.size();
  int cnt = 15-n;
  rep(i,n)if(s[i]=='o')cnt++;
  if(cnt>=8){
    cout << "YES" << endl;
  } else {
    cout << "NO" << endl;
  }

  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <vector>
#include <iostream>
#include<algorithm>
#include<string>
#include <map>
#include <queue>
#include <stack>
#include<set>

#define DIV 1000000007
#define TE 2e5
using namespace std;
using ll = long long;
using ldb = long double;

int main() {
	string s; cin >> s;
	int ans = 0, temp = 0;
	for (int i = 0; i<3; i++) {
		if (s[i] == 'R') {
			temp++;
			ans = max(ans, temp);
		}
		else temp = 0;
	}

	cout << ans << endl;
}


Measured memory_bytes: 3620
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**7)
    from collections import Counter, deque
    #from collections import defaultdict
    from itertools import combinations, permutations, accumulate, groupby, product
    from bisect import bisect_left,bisect_right
    from heapq import heapify, heappop, heappush
    from math import floor, ceil
    #from operator import itemgetter

    #inf = 10**17
    #mod = 10**9 + 7

    x,a = map(int, input().split())
    if x < a:
        print(0)
    else:
        print(10)
if __name__ == '__main__':
    main()

Measured memory_bytes: 3316
n = int(input())
s = input()
if n%2!=0:
  print('No')
else:
  flag = 0
  for i in range(n//2):
    if s[i] != s[n//2+i]:
      flag = 1
      break
  if flag == 1:
    print('No')
  else:
    print('Yes')
   

Measured memory_bytes: 2940
import java.util.*;

public class Main {
    public static void main(String args[]) throws Exception {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int k = sc.nextInt();
        double[] expect = new double[n];
        for(int i = 0; i < n; i++) {
        	int num = sc.nextInt();
        	expect[i] = (num + 1)  / 2.0;
        }
        double maxE = 0;
        double curE = 0;
        for(int i = 0; i < n; i++) {
        	curE += expect[i];
        	if(i >= k - 1) {
        		maxE = Math.max(maxE, curE);
        		curE -= expect[i - k + 1];
        	} 
        }
        System.out.println(maxE);
    }
}


Measured memory_bytes: 79140
#include <bits/stdc++.h>
using namespace std;
using Int = long long;
typedef pair<int,int> P; typedef pair<Int,Int> Pl;
const int mod = 1e9+7;
#define END {cout<<ans<<'\n'; return 0;}
#define ALL(v) v.begin(),v.end()
#define Pr(type) priority_queue<type>
#define gPr(type) priority_queue<type,vector<type>,greater<type>>
#define V(type) vector<type>
#define rep(i,n) for(int i=0; i<n; i++)
#define rer(i,st,en) for(int i=st; i<en; i++)
#define eb emplace_back
#define pri1(a) cout<<a<<'\n'
#define pri2(a,n) rep(i,n)cout<<a[i]<<'\n'
#define pri3(a,n) rep(i,n-1)cout<<a[i]<<' '; cout<<a[n-1]<<'\n'
template<class T> inline bool cmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool cmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }



int n,m,_,x,y,q;
string s,sb;
bool ok;

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

  cin>>n>>m; 
  cout<<pow(2,m)*(1900*m+100*(n-m))<<'\n';
}

Measured memory_bytes: 256
h,w=map(int,input().split())
s=[]
for i in range(h):
    s.append(list(input()))

#solution:dp

dp=[[float('inf') for _ in range(w)] for _ in range(h)]
dp[0][0] = 0 if s[0][0] == '.' else 1

def update(dp, i, j, ni, nj):
    if s[ni][nj]=='.':
        dp[ni][nj]=min(dp[i][j],dp[ni][nj])
    elif s[i][j]=='#':
        dp[ni][nj]=min(dp[i][j],dp[ni][nj])
    else:
        dp[ni][nj]=min(dp[i][j]+1,dp[ni][nj])
    
for i in range(h):
    for j in range(w):
        if i+1<h:
            update(dp,i,j,i+1,j)
        if j+1<w:
            update(dp,i,j,i,j+1)
print(dp[h-1][w-1])

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

constexpr int inf = 1e9;
constexpr ll linf = 1e18;

class UnionFind
{
public:
    UnionFind(int n = 0) : m_data(n, -1), m_count(n) {}

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

    bool unite(int x, int y)
    {
        x = find(x), y = find(y);
        if (x == y) return false;

        if (m_data[x] > m_data[y]) swap(x, y);
        m_data[x] += m_data[y];
        m_data[y] = x;
        m_count--;
        return true;
    }

    bool same(int x, int y) { return find(x) == find(y); }

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

    int count(void) const { return m_count; }

private:
    vector<int> m_data;
    int m_count;
};

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

    int n, m, k; cin >> n >> m >> k;
    vector<int> a(m), b(m), c(k), d(k);
    for (int i = 0; i < m; i++) {
        cin >> a[i] >> b[i];
        a[i]--, b[i]--;
    }
    for (int i = 0; i < k; i++) {
        cin >> c[i] >> d[i];
        c[i]--, d[i]--;
    }

    UnionFind uf(n);
    for (int i = 0; i < m; i++) uf.unite(a[i], b[i]);

    vector<int> fr(n, 0), bl(n, 0);
    for (int i = 0; i < m; i++) {
        if (uf.same(a[i], b[i])) fr[a[i]]++, fr[b[i]]++;
    }
    for (int i = 0; i < k; i++) {
        if (uf.same(c[i], d[i])) bl[c[i]]++, bl[d[i]]++;
    }
    
    for (int i = 0; i < n; i++) {
        int ans = max(0, uf.size(i) - 1 - fr[i] - bl[i]);
        cout << ans << " \n"[i == n - 1];
    }
    return 0;
}

Measured memory_bytes: 3584
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
#include <array>
using namespace std;
 
#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()
 
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;
typedef vector<double> VD;
typedef vector<VD> VVD;

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

int in() { int x; scanf("%d", &x); return x; }
ll lin() { ll x; scanf("%lld", &x); return x; }

struct bipartite_matching{
    int n, x, y;
    VVI e;
    VI match;
    vector<bool> used;

    void init(int a, int b){
        x = a;
        y = b;
        n = x + y;
        e.resize(n);
        match.resize(n);
        used.resize(n);
    }

    void add_edge(int u, int v){
        e[u].push_back(v + x);
        e[v + x].push_back(u);
    }

    bool dfs(int v){
        used[v] = true;
        for (int u : e[v]){
            int w = match[u];
            if (w < 0 || (!used[w] && dfs(w))){
                match[v] = u;
                match[u] = v;
                return true;
            }
        }
        return false;
    }

    int calc_matching(){
        int res = 0;
        fill(ALL(match), -1);
        REP(v,n){
            if (match[v] < 0){
                used.assign(n, 0);
                if (dfs(v)) res++;
            }
        }
        return res;
    }
};

bool isprime(int x){
    if (x <= 2) return false;
    for (int i = 2; i * i <= x; i++){
        if (x % i == 0) return false;
    }
    return true;
}

int main() {
    int n;
    cin >> n;
    VI a(n);
    REP(i,n) a[i] = in();
    set<int> st;
    REP(i,n){
        if (st.count(a[i])) st.erase(a[i]);
        else st.insert(a[i]);
        st.insert(a[i] + 1);
    }
    VI odd, even;
    for (int x : st){
        // cout << x << endl;
        if (x % 2) odd.push_back(x);
        else even.push_back(x);
    }
    int x = odd.size(), y = even.size();
    bipartite_matching bp;
    bp.init(x, y);
    REP(i,x) REP(j,y){
        if (isprime(abs(odd[i] - even[j]))) bp.add_edge(i, j);
    }
    int c = bp.calc_matching();
    x -= c;
    y -= c;
    int ans = c + x / 2 * 2 + y / 2 * 2 + 3 * (x % 2);
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 384
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
//#define int long long
template<class T, class U> inline bool chmax(T& a,U b) { if (a < b) { a = b; return 1; } return 0; }
template<class T, class U> inline bool chmin(T& a,U b) { if (a > b) { a = b; return 1; } return 0; }
template<class Monoid> struct SegmentTree {
    int n; Monoid id;
    vector<Monoid> node;
    SegmentTree(int sz) {
        id = numeric_limits<Monoid>::max();
        n = 1; while (n < sz) n *= 2;
        node.resize(2*n-1, id);
    }
    void update(int x, int val) {
        x += (n-1); node[x] = val;
        while (x > 0) {
            x = (x-1)/2;
            node[x] = min(node[2*x+1], node[2*x+2]);
        }
    }
    // minimum [a, b)
    Monoid query(int a, int b, int k=0, int l=0, int r=-1) {
        if (r < 0) r = n;
        if (r <= a || b <= l) return id;
        if (a <= l && r <= b) return node[k];
        int vl = query(a, b, 2*k+1, l, (l+r)/2);
        int vr = query(a, b, 2*k+2, (l+r)/2, r);
        return min(vl, vr);
    }
};

int main() {
    int N;
    cin >> N;
    vector<int> A(N);
    vector<pair<int, int>> sec;
    SegmentTree<int> sg(N);
    for (int i = 0; i < N; i++) {
        cin >> A[i]; sg.update(i, A[i]);
    }
    
    auto Binary_Search = [&](int i)->pair<int, int> {
        int ok = i, l = -1, r = N;
        while (abs(ok - l) > 1) {
            int mid = (ok + l) / 2;
            if (sg.query(mid, i+1) == A[i]) ok = mid;
            else l = mid;
        }
        l = ok; ok = i;
        while (abs(ok - r) > 1) {
            int mid = (ok + r) / 2;
            if (sg.query(i, mid+1) == A[i]) ok = mid;
            else r = mid;
        }
        r = ok;
        return make_pair(l, r);
    };
    
    for (int i = 0; i < N; i++) sec.emplace_back(Binary_Search(i));
    
    long long ans = 0;
    for (int i = 0; i < N; i++) {
        int l = abs(sec[i].first-i)+1, r = abs(sec[i].second-i)+1;
        ans += (long long)l * r * A[i];
    }

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

Measured memory_bytes: 5236
#include <bits/stdc++.h>
#define N 100005
#define sp " "
using namespace std;
long long int sum,n,m,ar[N],a,b,c;
int main()
{
	cin.tie(0);
	cout.tie(0);
	ios_base::sync_with_stdio(false);
	cin>>a>>b>>c;
	if(a==b && b==c)
	{
		if(a%2==1)
			cout<<"0";
		else
			cout<<"-1";
		return 0;	
	}
	
	while(1)
	{
		if(a%2==1 || b%2==1 || c%2==1)
		{
			cout<<sum;
			return 0;
		}
		sum++;
		int k,l;
		k=a;
		l=b;
		//~ cout<<sum<<sp<<a<<sp<<b<<sp<<c<<endl;
		a=(b+c)/2;
		b=(c+k)/2;
		c=(l+k)/2;
		
	}
}


Measured memory_bytes: 256
n, m = map(int, input().split())
h = list(map(int, input().split()))

edge = [[] for _ in range(n)]

## 接している各頂点をまとめる
for i in range(m):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    edge[a].append(b)
    edge[b].append(a)

cnt = 0

for node in range(n):
    good = True 
    for neighbor in edge[node]:
        if h[node] <= h[neighbor]:
            good = False
            break;
    if good:
        cnt += 1

print(cnt)

Measured memory_bytes: 29516