akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <sstream>
#include <fstream>
#include <string>
#include <vector>
#include <tuple>
#include <deque>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <utility>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstdio>
#include <numeric>
#include <string.h>
#define rep(i, x) for (int i = 0; i < (int)(x); i++)
#define repn(i, x) for (int i = 1; i <= (int)(x); i++)
#define repr(i, x) for (int i = ((int)(x) - 1); i >= 0; i--)
#define reprn(i, x) for (int i = ((int)(x)); i > 0; i--)
#define all(x) (x).begin(),(x).end()
typedef long long int64;
using namespace std;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const int INF = 1<<29;
const long long INFL = 1e18;
const int MOD = 1000000007;
const int MAX = 210000;

int gcd(int a, int b) {
    return b != 0 ? gcd(b, a % b) : a;
}

//逆元を求める関数
long long fac[MAX], finv[MAX], inv[MAX];
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++) {
      fac[i] = fac[i-1] * i % MOD;
      inv[i] = MOD - inv[MOD%i] * (MOD/i) % MOD;
      finv[i] = finv[i-1] * inv[i] % MOD;
    }
}
//組み合わせ
long long COM (int n, int k) {
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n-k] % MOD) % MOD;
}

void solve() {
		long long n; cin >> n;
		vector<long long> a(n);
		rep (i, n) {
			cin >> a[i];
		}
		long long ans = 0;
		for (int i = 0; i < 60; ++i) {
			long long tmp = 0;
			long long cnt = 0;
			//ビット毎に2^nで割り切れる(1となる)数をカウントする
			for (int j = 0; j < n; ++j) {
				cnt += a[j] >> i & 1;	
			}
			//2^nで割り切れない数(0となる)数をカウントする
			tmp = (n - cnt) * cnt % MOD;
			//2を掛けて求める答えを得る
			for (int j = 0; j < i; ++j) {
				tmp = (tmp * 2) % MOD;	
			}
			ans = (ans + tmp) % MOD;
		}
		cout << ans << endl;
    return;
}

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



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

int main() {
    int N;
    cin >> N;
    vector<int64_t> L(N + 1);
    L.at(0) = 2;
    L.at(1) = 1;
    for (int i = 2; i <= N; i++) {
        L.at(i) = L.at(i - 1) + L.at(i - 2);
    }

    cout << L.at(N) << endl;

    return 0;
}

Measured memory_bytes: 256
def ascan; gets.split.map(&:to_i); end
def scan; gets.to_i; end

MD = 1000000007

n, m = ascan

def fact(n)
    t = 1
    2.upto(n) {|i|
        t = (t*i) % MD
    }
    t
end


# MEMO : 逆元...powm(n,E107-2,E107)

def powm(x, q, mod=1000000007)
    y=1
    x=x%mod
    while (0<q)
        y=(y*x)%mod if q%2==1
        x=(x*x)%mod
        q/=2
    end
    return y
end



if (n - m).abs > 1
    p 0
elsif n == m
    t = (fact(n)*fact(m)*2) % MD
    p t
else
    n, m = m, n if n.even?
    
    p (fact(n)*fact(m)) % MD

end




Measured memory_bytes: 1788
#pragma GCC optimize ("O2")
#pragma GCC diagnostic ignored "-Wunused-variable"
#pragma GCC diagnostic ignored "-Wunused-result"
#pragma GCC diagnostic ignored "-Wunused-label"

#define DEBUG 1
#define dd if (DEBUG)

#include <bits/stdc++.h>
using namespace std;

#define rep(i, a, b) for (int i = (a); i < (b); ++i)
#define trav(a, A) for (auto & a : A)
#define all(a) (a).begin (), (a).end ()
#define rall(a) (a).rbegin (), (a).rend ()
#define sz(a) (int) (a).size ()
#define szl(a) (int) (a).length ()
#define FASTIO cin.sync_with_stdio (0); cin.tie (0); cin.exceptions (cin.failbit);

typedef long long ll;
typedef pair <int, int> pii;
#define f first
#define s second
#define mp(a, b) make_pair((a), (b))
typedef vector <int> vi;
typedef vector <vi> mi;
typedef vector <ll> vll;
typedef vector <vll> mll;
#define pb(a) push_back ((a))

const ll MOD = 1e+9+7;
const ll INF = 0x3f3f3f3f3f3f3f3f;
const int INFi = 0x3f3f3f3f;
const ll MAXN = 1e+6+7;
int comeca[10], termina[10];
ll table[10][10];
int main ()
{
    FASTIO;
    int i, j, n;
    cin >> n;
    rep(i, 1, n+1){
        int x = i, first = 1, primeiro, ultimo;
        while (x > 0){
            if (first){
                ultimo = x % 10;
                first= 0;
            }
            if (x/10 == 0){
                primeiro = x % 10;
                break;
            }
            x /= 10;
        }
        table[primeiro][ultimo]++;
    }
    
    ll ans = 0;
    rep(i, 1, 10){
        rep(j, 1, 10){
            ans += table[i][j]*table[j][i];
        }
        //ans += (ll)comeca[i]*(ll)termina[i];
    }
    cout << ans << '\n';
    return 0;
}




Measured memory_bytes: 256
#include <bits/stdc++.h> //JuniorMonster a.k.a Sho10
#define ll long long int
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#define all(a) (a).begin(), (a).end()
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define sz size
#define f first
#define s second
#define pb push_back
#define er erase
#define in insert
#define mp make_pair
#define pi pair
#define rc(s) return cout<<s,0
#define mod 1000000007
#define PI 3.14159265359
#define CODE_START  ios_base::sync_with_stdio();cin.tie();cout.tie();
using namespace std;
ll n,ans=0;
string s[100005];
int32_t main(){
    cin>>n;
    for(ll i=0;i<n;i++)
    {
        cin>>s[i];
        sort(s[i].begin(),s[i].end());
    }
    sort(s,s+n);
    ll d=1;
    for(ll i=0;i<n;i++)
    if(s[i]==s[i+1]&&i+1<n){
        d++;
    }else {
    ans=ans+d*(d-1)/2;
    d=1;
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 7296
#include <bits/stdc++.h>
#define ALL(a)  (a).begin(),(a).end()
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<long long, long long> Pll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<long long> vll;
typedef vector<vector<long long>> vvll;
template <typename T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template <typename T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const long long INF = 1LL << 60;
const int INT_INF = 1 << 30;
#define MOD 1000000007LL
#define endl "\n"

struct UnionFind {
  vi par, count;

  UnionFind(int N) : par(N), count(N, 1){
    for(int i = 0; i < N; i++) par.at(i) = i;
  }

  int root(int x){
    if(par.at(x) == x) return x;
    return par.at(x) = root(par.at(x));
  }

  int unite(int x, int y){
    if(root(x) == root(y)) return 0;
    if(size(x) < size(y)){
      count.at(root(y)) += count.at(root(x));
      par.at(root(x)) = root(y);
    }
    else{
      count.at(root(x)) += count.at(root(y));
      par.at(root(y)) = root(x);
    }
    return 1;
  }

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

  int size(int x){
    return count.at(root(x));
  }
};

int main(){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  ll N, M;
  cin >> N >> M;
  vll a(M), b(M);
  for(int i = 0; i < M; i++){
    cin >> a.at(i) >> b.at(i);
    a.at(i)--; b.at(i)--;
  }
  ll ans = 0;
  for(int i = 0; i < M; i++){
    UnionFind uf(N);
    for(int j = 0; j < M; j++){
      if(i == j) continue;
      uf.unite(a.at(j), b.at(j));
    }
    if(uf.size(0) != N) ans++;
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int MAXN = 5005;
const int P = 1e9 + 7;
typedef long long ll;
template <typename T> void chkmax(T &x, T y) {x = max(x, y); }
template <typename T> void chkmin(T &x, T y) {x = min(x, y); } 
template <typename T> void read(T &x) {
	x = 0; int f = 1;
	char c = getchar();
	for (; !isdigit(c); c = getchar()) if (c == '-') f = -f;
	for (; isdigit(c); c = getchar()) x = x * 10 + c - '0';
	x *= f;
}
int n, a, b, dp[MAXN][MAXN], two[MAXN];
int pd[MAXN][MAXN], aux[MAXN];
void update(int &x, int y) {
	x += y;
	if (x >= P) x -= P;
}
int main() {
	read(n), read(a), read(b);
	if (a < b) swap(a, b); two[0] = 1;
	for (int i = 1; i <= n; i++)
		two[i] = 2ll * two[i - 1] % P;
	dp[0][0] = 1;
	for (int i = 0; i <= n; i++) {
		if (i != 0) update(aux[i], aux[i - 1]);
		update(dp[i][1], aux[i]);
		for (int j = 1; j <= a; j++) {
			update(dp[i][j], pd[i][j]);
			update(pd[i + 1][min(j + 1, a)], pd[i][j]);
		}
		if (i == n) break;
		for (int j = 0; j <= a - 1; j++) {
			update(dp[i + 1][j + 1], dp[i][j]);
			
			update(aux[i + 2], dp[i][j]);
			if (i + b + 1 <= n) update(aux[i + b + 1], P - dp[i][j]);
			
			if (i + b + 1 <= n) update(pd[i + b + 1][min(j + b + 1, a)], dp[i][j]);
			
			if (n - i >= b) update(dp[n][min(j + n - i, a)], dp[i][j]);
		}
	}
	int ans = 0;
	for (int i = 1; i <= n; i++)
		update(ans, 1ll * dp[i][a] * two[n - i] % P);
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 199228
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef double db;
#define go(u) for(int i = head[u], v = e[i].to; i; i=e[i].lst, v=e[i].to)
#define rep(i, a, b) for(int i = a; i <= b; ++i)
#define pb push_back
#define re(x) memset(x, 0, sizeof x)
inline int gi() {
    int x = 0,f = 1;
    char ch = getchar();
    while(!isdigit(ch)) { if(ch == '-') f = -1; ch = getchar();}
    while(isdigit(ch)) { x = (x << 3) + (x << 1) + ch - 48; ch = getchar();}
    return x * f;
}
template <typename T> inline bool Max(T &a, T b){return a < b ? a = b, 1 : 0;}
template <typename T> inline bool Min(T &a, T b){return a > b ? a = b, 1 : 0;}
const int N = 1e5 + 7;
int n;
int a[N], f[N];
bool cmp(int a, int b) {
	return a > b;
}
void out(int x) {
	if(x) puts("First");
	else puts("Second");	
}
int main() {
#ifndef ONLINE_JUDGE
#endif
	n = gi();
	rep(i, 1, n) a[i] = gi();
	sort(a + 1, a + 1 + n, cmp);
	for(int i = n; i; --i) if(a[i] != a[i + 1]) f[i] = 0;
	else f[i] = f[i + 1] ^ 1;
	rep(i, 1, n) if(a[i] == i) {
		return out(f[i]), 0;
	}else if(a[i] > i && a[i + 1] < i) {
		return out((a[i] - i) & 1), 0;
	}else if(i == a[i + 1]) {
		return out(((a[i] - (i + 1)) & 1) & f[i + 1] ^ 1), 0;
	}
	return 0;
}

Measured memory_bytes: 1024
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<iostream>
#include<string>
#include<stack>
#include<queue>
#include<vector>
#include<map>
#include<set>
#include<algorithm>

#define rep(n) for(int i=0;i<n;i++)
#define repp(j, n) for(int j=0;j<n;j++)
#define reppp(i, m, n) for(int i=m;i<=n;i++)
#define all(c) c.begin(), c.end()
#define rall(c) c.rbegin(), c.rend()
#define pb(x) push_back(x)
#define eb(x,y) emplace_back(x,y)
#define MOD 1000000007
#define MAX 1000000001
#define MAX_V 100000
#define INF 1410065408
#define EPS 1e-9
 
using namespace std;
typedef long long ll;
typedef pair<ll, ll> Pll;
typedef pair<int, int> Pii;
struct edge{int to; ll cap; int rev;};

vector<edge> G[MAX_V];
vector<int> level(MAX_V);
vector<int> iter(MAX_V, 0);
int H, W, s, t;

void add_edge(int from, int to, ll cap){
    /*
        ある点vに対する辺の集合はvectorで管理されているので，
        そのvectorの中の何番目の辺に対応しているかを記憶する→rev
    */
    G[from].push_back({to, cap, (int)G[to].size()});
    G[to].push_back({from, 0, (int)G[from].size()-1});
}

void bfs(int s){
    level = vector<int>(MAX_V, -1);
    queue<int> que;
    level[s] = 0;
    que.push(s);
    while(!que.empty()){
        int v = que.front(); que.pop();
        for(edge e : G[v]){
            if(e.cap > 0 && level[e.to] == -1){
                level[e.to] = level[v] + 1;
                que.push(e.to);
            }
        }
    }
}

ll dfs(int v, int t, ll f){
    if(v == t) return f;
    rep((int)G[v].size()){
        edge &e = G[v][i]; //eの中身を書き換えたいのでポインタを使用
        if(level[v] < level[e.to] && e.cap > 0){
            ll d = dfs(e.to, t, min(f, e.cap));
            if(d > 0){
                e.cap -= d;
                G[e.to][e.rev].cap += d;
                return d;
            }
        }
    }
    return 0;
}

ll dicnic(int s, int t){
    ll max_flow = 0;
    while(true){
        bfs(s);
        if(level[t] < 0) return max_flow;
        ll f;
        while((f = dfs(s, t, INF)) > 0){
            max_flow += f;
        }
    }

    return max_flow;
}

signed main(){
    cin >> H >> W;
    rep(H){
        string tmp;
        cin >> tmp;
        repp(j, W){
            if(tmp[j] == 'S'){
                s = W*i + j;
                add_edge(W+H, i, INF);
                add_edge(W+H, H+j, INF);
            }else if(tmp[j] == 'T'){
                t = W*i + j;
                add_edge(i, W+H+1, INF);
                add_edge(H+j, W+H+1, INF);
            }else if(tmp[j] == 'o'){
                add_edge(i, H+j, 1);
                add_edge(H+j, i, 1);
            }
        }
    }
    
    if(s / W == t / W || s % W == t % W){
        cout << -1;
    }else{
        cout << dicnic(W+H, W+H+1);
    }
}


Measured memory_bytes: 4992
//  Shuffle.cpp
//  2013/01/02.

#if 1

#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <ctime>
#include <cassert>
#include <iostream>
#include <cctype>
#include <sstream>
#include <string>
#include <list>
#include <vector>
#include <queue>
#include <set>
#include <stack>
#include <map>
#include <utility>
#include <numeric>
#include <algorithm>
#include <iterator>
#include <bitset>
#include <complex>
#include <fstream>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef pair<int, int> pint;
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
template<class T> T RoundOff(T a){ return int(a+.5-(a<0)); }
template<class T, class C> void chmax(T& a, C b){ if(a < b) a = b; }
template<class T, class C> void chmin(T& a, C b){ if(b < a) a = b; }
template<class T, class C> pair<T, C> mp(T a, C b){ return make_pair(a, b); }

typedef vector<pint> VP;

pair<VP, VP> take(VP cards, int x)
{
	VP head, tail;

	int num = 0;
	
	rep(i, cards.size())
	{
		if(num + cards[i].second <= x) head.push_back(cards[i]);
		else if(x <= num) tail.push_back(cards[i]);
		else if(x < num + cards[i].second)
		{
			head.push_back(mp(cards[i].first, x - num));
			tail.push_back(mp(cards[i].first + x - num, cards[i].second - (x - num)));
		}
		
		num += cards[i].second;
	}
	
 	return mp(head, tail);
}


int count(VP cards, int r)
{
	int res = 0;
	
	rep(i, cards.size()) if(cards[i].first <= r) res += min(r - cards[i].first + 1, cards[i].second);
	
	return res;
}


int main()
{
	for(int n; cin >> n; )
	{
		if(n == 0) break;
		
		int m, p, q, r;
		cin >> m >> p >> q >> r;
		
		VP cards(1, mp(1, n));
		
		
		rep(i, m)
		{
			int x, y;
			cin >> x >> y;
			
			VP a, b, c;
			pair<VP, VP> tmp;
			
			tmp = take(cards, x);
			a = tmp.first;
			tmp = take(tmp.second, y - x);
			b = tmp.first;
			c = tmp.second;
			
			cards.clear();
			rep(i, c.size()) cards.push_back(c[i]);
			rep(i, b.size()) cards.push_back(b[i]);
			rep(i, a.size()) cards.push_back(a[i]);
		}
		
		cout << count(take(take(cards, p-1).second, q-p+1).first, r) << endl;
	}
}

/*
 while (n = gets.chomp.to_i) != 0
 m = gets.chomp.to_i
 p, q, r = gets.split.map(&:to_i)
 
 cards = [[1, n]]
 
 m.times do
 x, y = gets.split.map(&:to_i)
 
 a, cards = take(cards, x)
 b, c = take(cards, y - x)
 
 cards = c + b + a
 end
 
 
 puts count(take(take(cards, p-1)[1], q - p + 1)[0], r)
 end
 

 */


#endif

Measured memory_bytes: 1588
#include <bits/stdc++.h> //全てのヘッダファイルをインクルード

//ループ
#define rep(i, n) for(int i = 0; i < (n); i++) //普通のループ
#define repr(i, n) for(int i = n; i >= 0; i--) //逆ループ

//型名省略
typedef long long ll;
//値
static const ll MX = 100005;
static const ll MX_ll = 1e18;

using namespace std;

//ソート
#define SIZE_OF_ARRAY(array) (sizeof(array)/sizeof(array[0]))

//#include "./lib/generic/search.h"

int main(){
    int n;
    cin >> n;
    int a[n];
    rep(i, n) cin >> a[i];
    int cnt = 0;
    rep(i, n){
        if((i+1)%2==0) continue;
        if(a[i]%2!=0) cnt++;
    }

    cout << cnt << endl;
    return 0;
}

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

using namespace std;

typedef pair<int, int> P;

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

int mp[102][102];
int w, h;

void bfs_fill()
{
	queue<P>  que;
	que.push(make_pair(1, 0));

	mp[1][0] = -1;

	while (que.size()) {
		P p = que.front(); que.pop();
		for (int i = 0; i < 6; ++i) {
			int ny = p.first + dy[i], nx = p.second + dx[p.first % 2][i];
			if (0 <= ny && ny <= h + 1 && 0 <= nx && nx <= w + 1 && mp[ny][nx] == 0) {
				que.push(make_pair(ny, nx));
				mp[ny][nx] = -1;
			}
		}
	}
}

int main()
{
	cin >> w >> h;
	for (int i = 1; i <= h; ++i) {
		for (int j = 1; j <= w; ++j) {
			cin >> mp[i][j];
		}
	}

	bfs_fill();

	int cnt = 0;

	for (int y = 0; y <= h+1; ++y) {
		for (int x = 0; x <= w+1; ++x) {
			if (mp[y][x] != -1) continue;
			for (int i = 0; i < 6; ++i) {
				int ny = y + dy[i], nx = x + dx[y % 2][i];
				if (1 <= ny && ny <= h && 1 <= nx && nx <= w && mp[ny][nx] == 1) cnt++;
			}
		}
	}

	printf("%d\n", cnt);
}

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

typedef long long ll;

int main(){
  string s;
  cin >> s;
  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;
  }
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
#define FOR(I,A,B) for(int I=int(A);I<int(B);++I)

int INF = 2147483647;
struct RUQ{//平方分割 0-index
	int n,rn,bn,Q=0;
	vector<P> a,b;
	RUQ(int n_){
		n = n_;
		rn = sqrt(n);if(rn>1)rn*=2;
		bn = ceil((double)n/rn);
		a.resize(n,{2147483647,0});
		b.resize(bn,{2147483647,0});
	}
	int value(int s){
		if(a[s].second < b[s/rn].second){
			a[s] = b[s/rn];
		}
		return a[s].first;
	}
	void updete(int s,int t,int x){
		Q++;
		FOR(i,s,t+1){
			if(i%rn==0 && (i+rn-1)<=t){
				b[i/rn] = {x,Q};
				i += rn-1;
			}else{
				a[i] = {x,Q};
			}
		}
	}
};

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	int N,Q;
	cin >> N >> Q;
	priority_queue<pair<int,P>> pq;
	vector<int> D(Q+1,INF);
	FOR(i,0,N){
		int s,t,x;
		cin >> s >> t >> x;
		pq.push({x,{s-x,t-x}});
	}
	FOR(i,0,Q){
		cin >> D[i];
	}
	RUQ ruq(Q+1);
	FOR(i,0,N){
		int s = pq.top().second.first;
		int t = pq.top().second.second;
		int x = pq.top().first;
		pq.pop();
		s = (lower_bound(D.begin(),D.end(),s)-D.begin());
		t = (lower_bound(D.begin(),D.end(),t)-D.begin());
		ruq.updete(s,t-1,x);
	}
	FOR(i,0,Q){
		int ans = ruq.value(i);
		if(ans==INF) ans = -1;
		cout << ans << '\n';
	}
}


Measured memory_bytes: 7280
#include <cstdio>

int main(int argc, char const* argv[])
{
	int r, c;
	scanf("%d %d", &r, &c);
	int **a = new int*[r];
	int *b = new int[c];
	for(int i = 0; i < c; i++)b[i] = 0;
	for(int i = 0; i < r; i++){
			a[i] = new int[c];
			for(int j = 0; j < c; j++){
					scanf("%d", a[i]+j);
					b[j] += a[i][j];
			}
	}
	for(int i = 0; i < r; i++){
			int sum = 0;
			for(int j = 0; j < c; j++){
					sum += a[i][j];
					printf("%d ", a[i][j]);
			}
			printf("%d\n", sum);
	}
	int sum = 0;
	for(int i = 0; i < c; i++){
			printf("%d ", b[i]);
			sum += b[i];
	}
	printf("%d\n", sum);
	return 0;
}



Measured memory_bytes: 2680
#include<iostream>
#include<cstdlib>
#include<cmath>
#include<algorithm>
#include<cstring>
#include<cstdlib>
#include<queue>
using namespace std;
int n,m;
int x,y;
int ans;
int main()
{
	cin>>n>>m;
	cin>>x>>y;
	ans=n*m-x*m-y*n+x*y;
	cout<<ans;
}

Measured memory_bytes: 256
#include<iostream>
#include<cmath>
#include<string>
#include<cstdlib>
#include<ctime>
#include<map>
#include<vector>
#include<list>
#include<set>
#include<string>
using namespace std;

#define ll long long
#define ld long double
#define uint unsigned int
#define alloc(n,type) (type*)calloc(n,sizeof(type))
#define MODULE 1
#define RAND(min,max) (rand()%(max-min+1)+min)
#define repeat(i,condition) for(int i = 0; condition; i++)
#define LOG(log) cout<<#log<<" : "<<log<<'\n'
#define DEBUG() {cout<<"DEBUG "<<num_debug<<'\n'; num_debug++;}
int num_debug = 0;
bool* IsPrime;
vector<int> Prime;

int compare_int(const void* a, const void* b);
void PrimeEnable(int n);
class Math;
class Module;

int main(void) {
	srand((unsigned)time(NULL));

	int N;
	cin >> N;
	int *D[2];
	repeat(i, i < 2)
		D[i] = alloc(N, int);
	repeat(i, i < N) {
		scanf("%d%d", &D[0][i], &D[1][i]);
	}

	int times = 0;
	bool flag = false;
	repeat(i, i < N) {
		if (D[0][i] == D[1][i])
			times++;
		else
			times = 0;

		if (times >= 3) {
			flag = true;
			break;
		}
	}

	if (flag)
		cout << "Yes";
	else
		cout << "No";

	repeat(i, i < 2)
		free(D[i]);
	return 0;
}

int compare_int(const void* a, const void* b) {
	//昇順
	return *(int*)a - *(int*)b;
}
void PrimeEnable(int n) {
	//initialize IsPrime
	IsPrime = (bool*)calloc(n + 1, sizeof(bool));
	for (int i = 0; i <= n; i++)
		IsPrime[i] = true;

	//IsPrime 
	IsPrime[0] = IsPrime[1] = false;
	for (int i = 2; i * i <= n; i++) {
		if (IsPrime[i])
			for (int j = i; i * j <= n; j++) {
				IsPrime[i * j] = false;
			}
	}

	//push back to Prime
	for (int i = 0; i <= n; i++) {
		if (IsPrime[i])
			Prime.push_back(i);
	}
}
class Math {
public:
	template<typename T> static T Fac(int n) {
		T ans = 1;
		for (int i = 2; i <= n; i++) {
			ans *= i;
		}
		return ans;
	}
public:
	template<typename Tout, typename Tin> static Tout P(Tin n, Tin r) {
		Tout ans = 1;
		for (Tin i = 0; i < r; i++) {
			ans *= n - i;
		}
		return ans;
	}
public:
	template<typename T>static T C(int n, int r) {
		T nmr = 1;
		T dnm = 1;
		if (n - r < r)
			r = n - r;
		for (int i = 0; i < r; i++) {
			nmr *= n - i;
			dnm *= r - i;
		}
		return nmr / dnm;
	}
};
class Module {
public:
	static const int mod = MODULE;

public:
	static int add(int a, int b) {
		long ans = (long)a + b;
		if (ans < 0)
			ans += mod;
		ans %= mod;
		return ans;
	}
public:
	static int mult(int a, int b) {
		long ans = (long)a * b;
		return ans % mod;
	}

public:
	static int Pow(int a, int b) {
		int base = a % mod;
		if (mod / 2 < abs(base))
			if (base < 0) {
				base += mod;  //negative
			}
			else {
				base -= mod;  //positive
			}

		return pow(base, b);
	}
};
//template name is "AtCoder_C++"

Measured memory_bytes: 3772
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <queue>
#include <stack>
#include <map>
#include <algorithm>
#include <math.h>
#include <cassert>
#define rep(i,n) for(int i = 0; i < n; ++i )
using namespace std;
using ll = long long;
using P = pair<int,int>;

bool d[10];
bool f(int n){
  while(n>0){
    if(d[n%10]) return false;
    n /= 10;
  }
  return true;
}
int main() {
  int n,k;
  cin >> n >> k;
  rep(_,k){
    int i;
    cin >> i;
    d[i] = true;
  }
  while(!f(n)) ++n;
  cout << n << endl;
}


Measured memory_bytes: 3612
#include <bits/stdc++.h>
#define pb push_back
#define pll pair <ll, ll>
#define mp make_pair
#define pyshnapyshnakaa ios_base :: sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define x first
#define y second
#pragma GCC optimize("O3")
// #pragma GCC optimize("Ofast")
// #pragma GCC optimize("unroll-loops")
#define plll pair <ll, pair <ll, ll>>
#define pllll pair <pair <ll, ll>, pair <ll, ll> >
#define psl pair <string, ll>
#define all(a) a.begin(), a.end()
#define vvl vector <vector <ll> >
 
typedef long long ll;
 
typedef long double ld;
 
using namespace std;
 
const ll maxn = 1e6 + 100;

ll n, m, k, t;

ll A[maxn];

ll B[maxn];

int main() {
    pyshnapyshnakaa;
    ll q, w, e, a, b, c;
    cin >> n;
    for (q = 0; q < n; q++) {
        cin >> A[q];
    }
    set <pll> S;
    for (q = 0; q < n; q++) {
        cin >> B[q];
        if (B[q] < A[q]) {
            cout << -1;
            return 0;
        }
        if (A[q] != B[q]) {
            S.insert(mp(B[q], q));
        }
    }
    ll ans = 0;
    while (!S.empty()) {
        pll p = (*(--S.end()));
        S.erase(p);
        ll i = p.second;
        ll j = (i + 1) % n;
        ll k = (i - 1 + n) % n;
        ll s = B[j] + B[k];
        ll mx = max({B[j], B[k], A[i]});
        // cout << B[j] << " " << B[i] << " " << B[k] << endl;
        ll cnt = (B[i] - mx + s - 1) / s;
        ans += cnt;
        B[i] -= s * cnt;
        assert(cnt != 0);
        if (B[i] < A[i]) {
            cout << -1;
            return 0;
        }
        if (B[i] != A[i]) {
            S.insert(mp(B[i], i));
        }
    }
    cout << ans;
    return 0;
}


Measured memory_bytes: 19180
read K;printf %d\\n {1{,0{{0..8}999999999999,99{,9{,9{,9{,9{,9{,9{,9{,9{,9{,9{,9}}}}}}}}}}}},{1..8}99{,9{,9{,9{,9{,9{,9{,9{,9{,9{,9{,9}}}}}}}}}}}},2{,{0..8}999{,9{,9{,9{,9{,9{,9{,9{,9{,9{,9}}}}}}}}}}},3{,{0..8}9999{,9{,9{,9{,9{,9{,9{,9{,9{,9}}}}}}}}}},4{,{0..8}99999{,9{,9{,9{,9{,9{,9{,9{,9}}}}}}}}},5{,{0..8}999999{,9{,9{,9{,9{,9{,9{,9}}}}}}}},6{,{0..8}9999999{,9{,9{,9{,9{,9{,9}}}}}}},7{,{0..8}99999999{,9{,9{,9{,9{,9}}}}}},8{,{0..8}999999999{,9{,9{,9{,9}}}}},9{,{0..8}9999999999{,9{,9{,9}}}},{1..9}9{,9{,9{,9{,9{,9{,9{,9{,9{,9{,9{,9{,9{,9}}}}}}}}}}}}}}|sort -n|head -$K

Measured memory_bytes: 844
#include<bits/stdc++.h>
using namespace std;
int main()
{
   int arr[]={1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
   int n;
   cin>>n;
   cout<<arr[n-1]<<endl;
}



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

#define rep(i, n) for(int i = 0; i<(n); i++)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
typedef long long ll;

typedef pair<int, ll> P;

bool visited[110000];
ll dp[110000];
vector<vector<P>> to(110000, vector<P>());

bool dfs(int i) {
    visited[i] = true;
    for (auto p : to[i]) {
        if (visited[p.first]) {
            if (dp[p.first] != dp[i] + p.second) return false;
        } else {
            dp[p.first] = dp[i] + p.second;
            if (!dfs(p.first)) return false;
        }
    }

    return true;
}

int main() {
    ll N, M;
    cin >> N >> M;
    rep(i, M) {
        int l, r;
        ll d;
        cin >> l >> r >> d;
        l--;
        r--;
        to[l].push_back(make_pair(r, d));
        to[r].push_back(make_pair(l, -1L * d));
    }

    rep(i, N) {
        if (!dfs(i)) {
            cout << "No" << endl;
            return 0;
        }
    }

    cout << "Yes" << endl;
}

Measured memory_bytes: 15872
S=input()
s=[int(S[i]) for i in range(len(S))]
N=len(s)
B=[]
for i in range(2**(N-1)):
    ans=[[s[0]]]
    for j in range(N-1):
        if ((i>>j)&1):# 順に右にシフトさせ最下位bitのチェックを行う
            ans[-1].append(s[j+1])    
        else:
            ans.append([s[j+1]])
    for k in ans:
        for l, val in enumerate(reversed(k)):
            B.append((10**l)*val)
print(sum(B))

Measured memory_bytes: 3064
#include "bits/stdc++.h"
using namespace std;
const int N=1e5+20;
int n;
pair <int,int> p[N];
int main()
{
	scanf("%d",&n);
	for(int i=0;i<n;i++)
	{
		scanf("%d",&p[i].first);
		p[i].second=i+1;
	}

	sort(p,p+n);
	for(int i=0;i<n;i++) printf("%d ",p[i].second);
}

Measured memory_bytes: 1536
import java.io.*;

class Main
{
 public static void main(String[] args) throws IOException
 {
  BufferedReader br = new BufferedReader (new InputStreamReader(System.in));

  String[] str = br.readLine().split(" ");

  int a=Integer.parseInt(str[0]),b=Integer.parseInt(str[1]);

  if(a>b)
   System.out.println("a > b");
  else if(a==b)
   System.out.println("a == b");
  else
   System.out.println("a < b");
 }
}

Measured memory_bytes: 24476
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class Main {
	public static void main(String[] args) throws IOException {
		try (BufferedReader br = new BufferedReader(new InputStreamReader(System.in))) {
			String[] array = br.readLine().split(" ");
			int N = Integer.parseInt(array[0]);
			int C = Integer.parseInt(array[1]);

			List<TVData> list = new ArrayList<>();
			for (int i = 0; i < N; i++) {
				list.add(new TVData(br.readLine()));
			}
			final int[] table = new int[2 * 100_001];
			final boolean[] tmp = new boolean[2 * 100_001];
			for (int channel = 1; channel <= C; channel++, init(tmp)) {
				final int c = channel;
				list.parallelStream().filter(data -> data.channel == c).forEach(data -> {
					for (int i = data.start * 2 - 1; i <= data.end * 2; i++) {
						tmp[i] = true;
					}
				});
				for (int i = 0; i < table.length; i++) {
					if (tmp[i]) {
						table[i]++;
					}
				}
			}

			System.out.println(Arrays.stream(table).max().getAsInt());
		}
	}

	private static void init(boolean[] tmp) {
		for (int i = 0; i < tmp.length; i++) {
			tmp[i] = false;
		}
	}

	public static class TVData {
		private final int channel;
		private final int start;
		private final int end;

		public TVData(String line) {
			int[] tmp = Arrays.stream(line.split(" ")).mapToInt(Integer::parseInt).toArray();
			start = tmp[0];
			end = tmp[1];
			channel = tmp[2];
		}
	}

}


Measured memory_bytes: 64692
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define FOR(i,a,n) for(int i=(a); i<(n); i++)
#define all(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9+7;

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

    while (true) {
        int n; cin >> n;
        if (!n) break;

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

        float ave = accumulate(all(a), 0.0) / n;
        int ans = 0;
        sort(all(a));

        for(const auto aa: a) if (aa<=ave) ans++;

        cout << ans << endl;
    }
}


Measured memory_bytes: 3204
#include<iostream>
#include<cstdio>
#include<cstring>
#include <cstdlib>  
#include <math.h>
#include <cmath>
#include<complex>
#include<cctype>
#include<string>
#include<set>
#include<iomanip>
#include <map>
#include<algorithm>
#include <functional>
#include<vector>
#include<climits>
#include<stack>
#include<queue>
#include<bitset>
#include <deque>
#include <climits>
#include <typeinfo>
#include <utility> 
#include <numeric>
using namespace std;
using Complex = complex<double>;
using ll = long long;
template<typename T>using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
const ll inf = 1145141919810364364LL;
double PI = acos(-1.0);
#define all(x) (x).begin(),(x).end()
#define puts(x) cout << x << endl
#define rep(i,m,n) for(ll i = m;i < n;++i)
#define pb push_back
#define fore(i,a) for(auto &i:a)
#define rrep(i,m,n) for(ll i = m;i >= n;--i)
 
 
ll dp[202020][2];
 
int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
 
	int N;
	cin >> N;
	vector<ll>A(N);
	for (int i = 0; i < N; i++)cin >> A[i];
 
	dp[1][0] = -inf;
	dp[1][1] = A[0];
	dp[2][0] = A[1];
	dp[3][0] = A[2];
	dp[3][1] = A[0] + A[2];
	for (int i = 4; i <= N; i++) {
		if (i % 2 == 0) {
			ll pre2 = dp[i-2][0];
			ll pre3 = dp[i-3][1];
			dp[i][0] = max(pre2,pre3) + A[i-1];
		}
		else {
			ll pre2_0 = dp[i-2][0];
			ll pre3_0 = dp[i-3][0];
			ll pre4_0 = dp[i-4][1];
			dp[i][0] = max(pre2_0,max(pre3_0,pre4_0)) + A[i - 1];
			dp[i][1] = dp[i-2][1] + A[i - 1];
		}
	}
 
	if (N % 2 == 0) {
		puts(max(dp[N][0],dp[N-1][1]));
	}
	else {
		puts(max(dp[N][0],max(dp[N-1][0],dp[N-2][1])));
	}
 
	return 0;
}

Measured memory_bytes: 7640
import sys
sys.setrecursionlimit(10**7) #再帰関数の上限,10**5以上の場合python
import math
from copy import copy, deepcopy
from operator import itemgetter
from bisect import bisect_left, bisect, bisect_right#2分探索
#bisect_left(l,x), bisect(l,x)#aはソート済みである必要あり。aの中からx未満の要素数を返す。rightだと以下
from collections import deque
#deque(l), pop(), append(x), popleft(), appendleft(x)
##listでqueの代用をするとO(N)の計算量がかかってしまうので注意
from collections import Counter#文字列を個数カウント辞書に、
#S=Counter(l),S.most_common(x),S.keys(),S.values(),S.items()
from itertools import accumulate#累積和
#list(accumulate(l))
from heapq import heapify,heappop,heappush
#heapify(q),heappush(q,a),heappop(q) #q=heapify(q)としないこと、返り値はNone
#import fractions#古いatcoderコンテストの場合GCDなどはここからimportする
from functools import lru_cache#pypyでもうごく
#@lru_cache(maxsize = None)#maxsizeは保存するデータ数の最大値、2**nが最も高効率

def input(): return sys.stdin.readline()[:-1]
def printl(li): print(*li, sep="\n")
def argsort(s, return_sorted=False): 
    inds=sorted(range(len(s)), key=lambda k: s[k])
    if return_sorted: return inds, [s[i] for i in inds]
    return inds
def alp2num(c,cap=False): return ord(c)-97 if not cap else ord(c)-65
def num2alp(i,cap=False): return chr(i+97) if not cap else chr(i+65)
def matmat(A,B):
    K,N,M=len(B),len(A),len(B[0])
    return [[sum([(A[i][k]*B[k][j]) for k in range(K)]) for j in range(M)] for i in range(N)]
def matvec(M,v):
    N,size=len(v),len(M)
    return [sum([M[i][j]*v[j] for j in range(N)]) for i in range(size)]
def T(M):
    n,m=len(M),len(M[0])
    return [[M[j][i] for j in range(n)] for i in range(m)]
def main():
    mod = 10**9+7
    #w.sort(key=itemgetter(1),reversed=True)  #二個目の要素で降順並び替え

    N = int(input())
    #N, K = map(int, input().split())
    #A = tuple(map(int, input().split())) #1行ベクトル
    #L = tuple(int(input()) for i in range(N)) #改行ベクトル
    #S = tuple(tuple(map(int, input().split())) for i in range(N)) #改行行列
    print(0)
    sys.stdout.flush()
    s=input()
    if s=='Vacant':
        return 
    if s=='Male':
        ini=0
    else:
        ini=1

    def hantei(mid,ini,val):
        if mid%2==1:
            ini=(~ini)&1
        if val==ini:
            return 1
        else:
            return 0

    start=0
    end=N-1
    while end-start>1:
        mid=(end+start)//2
        print(mid)
        sys.stdout.flush()
        s=input()
        if s=='Vacant':
            return 
        if s=='Male':
            flag=hantei(mid,ini,0)
        else:
            flag=hantei(mid,ini,1)
        if flag:
            start=mid
        else:
            end=mid
    print(start)
    sys.stdout.flush()
    s=input()
    if s=='Vacant':
        return 
    print(end)
    sys.stdout.flush()
    s=input()
    if s=='Vacant':
        return 


if __name__ == "__main__":
    main()

Measured memory_bytes: 39104
N = int(input())
Red = []
for i in range(N):
	Red.append(list(map(int,input().split())))
Blue = []
for i in range(N):
	Blue.append(list(map(int,input().split())))

Red = sorted(Red, key=lambda x: -x[1])
Blue.sort()

res = 0
for i in range(N):
	for j in range(len(Blue)):
		if Red[i][0] < Blue[j][0] and Red[i][1] < Blue[j][1]:
			res += 1
			del Blue[j]
			break

print(res)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define rep(i,n) for (int i=0; i<(n); ++i)
using namespace std;
using ll=long long;
int main(){
    int n,x;
    cin>>n>>x;
    vector<int>a(n);
    rep(i,n){
        cin>>a[i];
    }
    int cnt=0;
    sort(a.begin(),a.end());
    rep(i,n){
        x-=a[i];
        if(x<0)break;
        else cnt++;
    }
    if(x>0)cnt--;
    cout<<cnt<<endl;
}


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

using namespace std;

const int INF = 1 << 29;
typedef long long ll;
typedef pair<int,int> PI;

int n, s, t, res;

void dfs(int n, int t, int sum){
	if(n == 0 && sum == s) {
		res++;
		return ;
	}
	if(sum > s || n <= 0 || t > s-sum) return ;
	for(int i=t+1; i<=10; ++i){
		dfs(n-1, i, sum+i-1);
	}
}

int main(void){
	while(cin >> n >> s, n|s){
		if(n == 0 && s == 0) break;
		res = 0;
		int ans;
		dfs(n, 0, 0);
		cout << res << endl;
	}

	return 0;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>  // g++ -std=c++14 -o a a.cpp

using namespace std;

typedef pair<int, int> P;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define repto(i, n) for(int i = 0; i <= (n); i++)
#define all(c) (c).begin(), (c).end()
#define uniq(c) c.erase(unique(all(c)), (c).end()) // ユニークなvectorにする。連続した値を除去して切り出す。
#define _1 first
#define _2 second
#define pb push_back
#define INF 1145141919
#define MOD 1000000007
#define DEBUG(x) cout << #x << ": " << x << endl;

__attribute__((constructor))
void initial() {
  cin.tie(0);
  ios::sync_with_stdio(false);
}

long getDigit(long num){
  long digit = 0;
  while (num != 0){
      num /= 10;
      digit++;
  }
  return digit;
}

int main() {
  long N;
  cin >> N;
  double r = sqrt(N);
  long minResult = INF;

  // r から試し割して一番最初に見つかった整数が最も大きく割れる奴
  long divider = r;
  while (divider > 0) {
    if (N % divider == 0) {
      long result = max(getDigit(divider), getDigit(N / divider));
      minResult = min(result, minResult);
      // DEBUG(divider);
      // DEBUG(minResult);
    }
    divider--;
  }

  cout << minResult << endl;
}


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

#define FOR(i,a,b) for(int i = (a); i < (b); ++i)
#define REP(i,n) FOR(i,0,n)
typedef long long ll;
using ll = long long;
using vi = vector<int>;
using mii = map<int, int>;
using msi = map<string, int>;
using pii = pair<int, int>;

#define MOD 1000000007
int main()
{
    ios::sync_with_stdio(false);

    int N;
    cin >> N;

    ll ans = 1;
    FOR(i, 1, N + 1) {
        ans *= i;
        ans %= MOD;
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long int ll;
typedef long double ld;
#define pb push_back
#define pii pair < int , int >
#define F first
#define S second
#define endl '\n'
#define int long long
#define sync ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math")
#define kill(x) return cout<<x<<'\n', 0;
using namespace std;
const int N=2e5+100,mod=998244353;
ll dp[N][3];
ll pd[N][3][3];
int32_t main(){
    sync;
    string s;
    cin >> s;
    ll n=s.size();
    ll a=0,b=0,c=0;
    for (int i=0;i<n;i++){
        if (s[i]=='a') a++;
        if (s[i]=='b') b++;
        if (s[i]=='c') c++;
    }
    if (a==n || b==n || c==n) kill(1);

    if (n==3){
        if (a==1 && b==c){
            kill(3);
        }
        if (s[0]==s[2] && s[1]!=s[0]) kill(7);
        kill(6);
    }
    dp[0][0]=1;
    for (int i=0;i<n;i++){
        for (int j=0;j<3;j++){
            for (int k=0;k<3;k++){
                ll z=(k+j)%3;
                dp[i+1][z]+=dp[i][j];
                dp[i+1][z]%=mod;
            }
        }
    }
    ll z=0*a+1*b+2*c;
    ll ans=dp[n][z%3];
    pd[1][0][0]=1;
    pd[1][1][1]=1;
    pd[1][2][2]=1;
    for (int i=1;i<n;i++){
        for (int j=0;j<3;j++){
            for (int k=0;k<3;k++){
                for (int p=0;p<3;p++){
                    if (p==k) continue;
                    ll z=j+p;
                    z%=3;
                    pd[i+1][z][p]+=pd[i][j][k];
                    pd[i+1][z][p]%=mod;
                }
            }
        }
    }
    for (int i=0;i<3;i++)
        ans-=pd[n][z%3][i];
    ans+=4*mod;
    ll p1=1;
    for (int i=0;i<n-1;i++){
        if (s[i]==s[i+1]) p1=0;
    }
    cout << (ans+p1)%mod;





}
/*abbbabbabbababababbbcccccbbcbcbccbcbccaccacacacaccacabbabacacabba*/


Measured memory_bytes: 22520
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;


class Main{
  public static void main(String[] args)throws IOException{
	 int w,h;//size of map
	 int x=0,y=0;//temp
   	 int c=0;
   	 int map[][]=new int[50][50];//map[???][?¨?]
   	 BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
	  while(true){		  
		  c=0;
    	 
    	 String str = br.readLine();
    	 //System.out.println(str);
    	 String[] a=str.split(" ");
    	 w=Integer.parseInt(a[0]);
    	 h=Integer.parseInt(a[1]);
    	 if(w==0&&h==0){
    		 
    		 break;
    	 }
    	 
    	 //??????????????\????????????
    	 for(int i=0;i<h;i++){
    		 str=br.readLine();
    		 a=str.split(" ");
    		 for(int j=0;j<w;j++){
    			 map[i][j]=Integer.parseInt(a[j]);
    		 }
    	 }
    	 //??°??????
    	 for(int i=0;i<h;i++){
    		 for(int j=0;j<w;j++){
    			 if(map[i][j]==1){
    				 c++;
    				 //System.out.println(i+","+j);
    				 count(map,i,j);
    			 }
    		 	
    		 	
    		 }
    	 }
    	 System.out.println(c);
     }      
   
  }
  static void count(int map[][],int x,int y){
	  if(x<0||y<0||49<x||49<y){
		  return;
	  }else if(map[x][y]==0){
		  return;
	  }
	  else if(map[x][y]==1){
		  map[x][y]=0;
		  count(map,x+1,y+1);
		  count(map,x+1,y);
		  count(map,x,y+1);
		  count(map,x-1,y-1);
		  count(map,x-1,y);
		  count(map,x,y-1);
		  count(map,x-1,y+1);
		  count(map,x+1,y-1);
	  }
	  
  }
}

Measured memory_bytes: 28932
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD = 1000000007;
const double PI = acos(-1);  

int main(){
  string s; cin >> s;
  string bef = "", now="";

  ll cnt=0;
  for(int i=0; i<s.size(); i++){
    now += s[i];
    if(bef==now) continue;
    bef=now;   now="";  cnt += 1;
  }
  cout << cnt << endl;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
 
#define f(i,n) for (int i = 0; i < n; i++)
using pii = pair<int,int>;
 
int di[] = {0,0,1,-1};
int dj[] = {1,-1,0,0};
 
int main() {
	int n,m;
	cin >> n >> m;
	int dp[n][m];
	queue<pii> pq;
	f(i,n) {
		string s; cin >> s;
		f(j,m) {
			dp[i][j] = s[j] == '#'?0:n+m+1;
			if (!dp[i][j]) pq.push(pii(i,j));
		}
	}
	auto IN = [&](int i, int j) {
		return i>=0&&i<n&&j>=0&&j<m;
	};
	int ans = 0;
	while (pq.size()) {
		pii pp = pq.front(); pq.pop();
		int i = pp.first, j = pp.second;	
		f(k,4) {
			int ni = i+di[k], nj = j+dj[k];
			if (IN(ni,nj) && dp[ni][nj] == n+m+1) {
				dp[ni][nj] = dp[i][j]+1;
				pq.push(pii(ni,nj));
				ans = max(ans,dp[ni][nj]);
			}
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 12304
fun main(args : Array<String>) {
    val n = readLine()!!.toInt()
    val d = readLine()!!.split(" ").map { it.toLong() }.toMutableList()
    d.sort()

    val median1 = d[n/2]
    val median2 = d[n/2 - 1]

    if (median1 - median2 > 0) {
        println(median1 - median2)
    } else {
        println(0)
    }
}

Measured memory_bytes: 54360
#include<bits/stdc++.h>
using namespace std;
int n;
int a[100006],d[100006];
int l,r;
int runn(int i)
{
	l=i,r=i;
	int sum=a[i];
	
	do{
		l++;
		r--;
		sum=a[l]+a[r]-sum;
	}while(r!=1); 
	d[1]=sum/2;
//	printf("%d\n",d[1]);
	
}
int main()
{
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		scanf("%d",&a[i]);
	}
//	if(n%2==1)
//	{
	int z=n/2+1;
	runn(z);
	for(int i=1;i<=n;i++)
	{
		d[i+1]=a[i]-d[i];
		printf("%d ",2*d[i]);
		
	}
	
}

Measured memory_bytes: 2048
#!/usr/bin/env python3
import sys


def solve(ABCD: str):
    from itertools import product
    base = '{}{{}}{}{{}}{}{{}}{}'.format(*ABCD)
    for ops in product('+-', repeat=3):
        exp = base.format(*ops)
        if eval(exp) == 7:
            return exp + '=7'
    raise


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    ABCD = next(tokens)
    print(solve(ABCD))

def test():
    import doctest
    doctest.testmod()

if __name__ == '__main__':
    #test()
    main()


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

int main(){

	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    const double pi = 3.1415926535897;
    double r;
    cin >> r;
    std::cout << std::fixed;
    std::cout << std::setprecision(5);
    
    cout << 2*pi*r;

    

	return 0;
}

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

using namespace std;

int main()
{
    int W, H, x, y, r;
    
    cin >> W >> H >> x >> y >> r;
    
    if( x - r < 0 || W < x + r)
    { cout << "No" << endl; }
    else if( y - r < 0 || H < y + r)
    { cout << "No" << endl; }
    else 
    { cout << "Yes" << endl; }
   

    return 0;
}


Measured memory_bytes: 3092
class MapChecker
    def initialize(width, height)
        @checker = Array.new(height) do
            Array.new(width) do false end
        end
    end
    
    def check(position)
        @checker[position[:y]][position[:x]] = true
    end
    
    def checked?(position)
        @checker[position[:y]][position[:x]]
    end
end

class Field
    def initialize(map, width, height)
        @map = map
        @width = width
        @height = height
        @map_checker = MapChecker.new(width, height)
    end
    
    def next_lands(position)
        width = @map[0].length
        height = @map.length
        lands = []
        [[0, 1], [0, -1], [1, 0], [-1, 0], [1, 1], [1, -1], [-1, -1], [-1, 1]].each do |dif|
            new_x = position[:x] + dif[0]
            new_y = position[:y] + dif[1]
            new_position = {x: new_x, y: new_y}
            next if !land?(new_x, new_y)
            next if @map_checker.checked?(new_position)
            @map_checker.check(new_position)
            lands.push(new_position)
        end
        lands
    end
    
    def start_point
        point = nil
        @height.times do |y|
            @width.times do |x|
                if @map[y][x] == 1 && !@map_checker.checked?({x: x, y: y})
                    point = {x: x, y: y}
                    break
                end
            end
            break if !point.nil?
        end
        return nil if point.nil?
        @map_checker.check(point)
        point
    end
    
    private
    
    def land?(x, y)
        return false if x >= @width || y >= @height
        return false if x < 0 || y < 0
        return false if @map[y][x] == 0
        true
    end
end


while true
    width, height = gets.split(' ').map(&:to_i)
    break if width == 0 && height == 0
    map = []
    height.times do
        row = gets.split(' ').map(&:to_i)
        map.push(row)
    end
    
    field = Field.new(map, width, height)
    lands = 0
    while true
        position_queue = []
        start = field.start_point
        break if start.nil?
        position_queue.push(start)
        lands += 1
        while true
            new_positions = position_queue.map do |position|
                field.next_lands(position)
            end.flatten
            break if new_positions.length == 0
            position_queue = new_positions
        end
    end
    puts lands
end

Measured memory_bytes: 13296
#include <iostream>
#include <fstream>
#include <vector>
#include <map>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <numeric>
#include <queue>
using namespace std;
 
#define LOCAL  1
#define UPLOAD 2
 
#define ll long long
const long long INF = 1LL << 60;
 
template <class T = long long> T input(){T x;cin >> x;return x;}
template <class T> void output(T x){cout << x << endl;}
#define debug(x) cerr << #x<< ": " << x<< '\n';
#define debugBit(x,n) cerr << #x<< ": " << std::bitset<n>(x) << '\n';
#define REP(i,M) for(int i=0;i<M;i++)
 
template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}
ll gcd(ll x,ll y){return y?gcd(y,x%y):x;}
 
int main()
{
#if ENVIRONMENT == LOCAL
    std::ifstream in("input.txt");
    std::cin.rdbuf(in.rdbuf());
#endif
  
  ll N = input();

  output(ceil(N/2.0));
  
  return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;
//�f���Ȃ�P���̑��Ȃ�O���o��
int is_prime(int a){
  int i,count=0;
  for(i=a-1;i>1;i--){
    if(a%i==0)
      count++;
  }
  if(count>0)
    return 0;
  else
    return 1;
}


int main(){

  int X;
  cin >>X;
  for(int i=X;;i++){
    if(is_prime(i)==1){
      cout<<i<<endl;
      return 0;
    }
  }


  return 0;
}


Measured memory_bytes: 256