akhauriyash/Code-Regression huggingface dataset:
from collections import *
import sys
sys.setrecursionlimit(10**6)

H, W = map(int, input().split())
mas = []
for i in range(H):
    mas.append(input())
    
color = []
for i in range(H):
    color.append([-1] * W)

def DFS(node, c_color):
    x = node[0]
    y = node[1]
    nb = [[x, y-1], [x, y+1], [x+1, y], [x-1, y]]
    deq = deque()
    for i in range(4):
        if(nb[i][0] >= 0 and nb[i][0] < H and nb[i][1] >= 0 and nb[i][1] < W):
            if(color[nb[i][0]][nb[i][1]] == -1):
                deq.append(nb[i])
    deq_ = deque()
    while(deq):
        next_node = deq.popleft()
        if(mas[next_node[0]][next_node[1]] != mas[node[0]][node[1]]):
            color[next_node[0]][next_node[1]] = c_color
            deq_.append(next_node)            
    while(deq_):
        next_node = deq_.popleft()
        DFS(next_node, c_color)
    return
        
current_color = 0
for i in range(H):
    for j in range(W):
        if(color[i][j] >= 0):
            continue
        else:
            color[i][j] = current_color
            DFS([i, j], current_color)
            current_color += 1

color_num = []
for i in range(current_color):
    color_num.append([0, 0])
for i in range(H):
    for j in range(W):
        if(mas[i][j] == '#'):
            color_num[color[i][j]][0] += 1
        else:
            color_num[color[i][j]][1] += 1

ans = 0
for i in range(len(color_num)):
    ans += color_num[i][0] * color_num[i][1]
print(ans)


Measured memory_bytes: 214876
;; B - Popular Vote

(defun can-choose (m a)
  "総得票数の1/(4*m)以上票を得た商品がm個以上あるか"
  (let* ((total (reduce #'+ a))
         (thres (ceiling total (* 4 m)))
         (npop  (count-if #'(lambda (x) (>= x thres)) a)))
    (>= npop m)))

(let* ((n (read))
       (m (read))
       (a (loop repeat n collect (read))))
  (princ (if (can-choose m a) "Yes" "No")))


Measured memory_bytes: 15968
H, W = map(int, input().split())
S = [input() for i in range(H)]

dy = [0, 1, 1, 1, 0, -1, -1, -1]
dx = [1, 1, 0, -1, -1, -1, 0, 1]

ans = [[] for i in range(H)]

for i in range(H):
    for j in range(W):
        if S[i][j] == '.':
            mine = 0
            for k in range(8):
                y = i + dy[k]
                x = j + dx[k]
                if 0 <= y <= H-1 and 0 <= x <= W-1 and S[y][x] == '#':
                    mine += 1
            ans[i].append(mine)
        else:
            ans[i].append('#')

for i in range(H):
    print(*ans[i], sep = '')

Measured memory_bytes: 3444
#include <iostream>
#include <sstream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <utility>
#include <map>
#include <list>
#include <climits>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <bitset>

// #define cerr if(false)cerr
#define watch(x) cerr << "> " << #x << ": " << x << "\n";

using namespace std;

template <typename T>
std::ostream &operator <<(std::ostream &out, vector<T> &v) {
	for (typename vector<T>::size_type i = 0; i < v.size(); ++i)
		out << v[i] << " ";
	out << "\n";
    return out;
}
template <typename T, typename N>
std::ostream &operator <<(std::ostream &out, vector<pair<T, N> > &v) {
	for (size_t i = 0; i < v.size(); ++i)
		out << "(" << v[i].first << ", " << v[i].second << ") ";
	out << "\n";
    return out;
}
template <typename T>
std::ostream &operator <<(std::ostream &out, vector<vector<T> > &v) {
	for (size_t i = 0; i < v.size(); ++i) {
		for (size_t j = 0; j < v[i].size(); ++j) {
			out << v[i][j] << " ";
		}
		out << "\n";
	}
   	return out;
}

int main() {

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

	int x, y, a, b, c;
	cin >> x >> y >> a >> b >> c;

	vector<int> red(a), green(b), colorless(c);
	for (int i = 0; i < a; ++i) {
		cin >> red[i];
	}

	for (int i = 0; i < b; ++i) {
		cin >> green[i];
	}

	for (int i = 0; i < c; ++i) {
		cin >> colorless[i];
	}

	sort(red.rbegin(), red.rend());
	sort(green.rbegin(), green.rend());
	sort(colorless.begin(), colorless.end());

	long long deliciousness = 0;	
	for (int i = 0; i < x; ++i) {
		deliciousness += red[i];
	}

	for (int i = 0; i < y; ++i) {
		deliciousness += green[i];
	}

	int i = x - 1, j = y - 1, k = c - 1;
	while (k >= 0 && i >= 0 && j >= 0 && (colorless[k] > red[i] || colorless[k] > green[j])) {
		if (red[i] < green[j]) {
			deliciousness -= red[i];
			deliciousness += colorless[k];
			--i;
			--k;
		} else {
			deliciousness -= green[j];
			deliciousness += colorless[k];
			--j;
			--k;
		}
	}

	while (k >= 0 && i >= 0 && colorless[k] > red[i]) {
		deliciousness -= red[i];
		deliciousness += colorless[k];
		--i;
		--k;
	}

	while (k >= 0 && j >= 0 && colorless[k] > green[j]) {
		deliciousness -= green[j];
		deliciousness += colorless[k];
		--j;
		--k;
	}	

	cout << deliciousness << "\n";

	return 0;

}

Measured memory_bytes: 4336
from collections import deque
K = int(input())

stack = deque([9,8,7,6,5,4,3,2,1])
count = 0

while stack:
    n = stack.pop()
    count += 1
    if count == K:
        print(n)
        break
    if n%10 != 0:
        stack.appendleft(n*10+n%10-1)
    
    stack.appendleft(n*10+n%10)

    if n%10 != 9:
        stack.appendleft(n*10+n%10+1)
    





Measured memory_bytes: 11872
#include <bits/stdc++.h>
using namespace std;
int main()
{
    char s[256];
    int n;
    cin>>n;
    cin.ignore();
    cin.getline(s,256);
    //cout<<n<<" " <<s<<'\n';
    if (n%2!=0){
        cout<<"No";
    }
    else{
        if(strcmp(strstr(s,s+n/2),s)==0){
            cout<<"Yes";
        }
        else{
            cout<<"No";
        }
    }
    
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
int compare(long *a, long *b){
    if(*a<*b) return 1;
    else if(*b<*a) return -1;
    else return 0;
}
int main(){
    int n,m;
    scanf("%d%d",&n,&m);
    long x[n],y[n],z[n];
    for(int i=0; i<n; i++){
        scanf("%ld%ld%ld",&x[i],&y[i],&z[i]);
    }
    long t1=1,t2=-1,t3=-1;
    long sum[8][n];
  for(int a=0; a<n; a++){
    for(int b=0; b<8; b++){
		sum[b][a]=0;
    }
  }
    long max[8]={0,0,0,0,0,0,0,0};
    for(int j=0; j<8; j++){
        t3 *= -1;
        if(j%2==0) t2 *= -1;
        if(j==4) t1 *= -1;
        for(int k=0; k<n; k++){
            sum[j][k]=t1*x[k]+t2*y[k]+t3*z[k];
        }
        qsort(sum[j],n,sizeof(long),compare);
        for(int l=0; l<m; l++){
            max[j] += sum[j][l];
        }
    }
    qsort(max,8,sizeof(long),compare);
    long max_=max[0];
    printf("%ld\n",max_);
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include<vector>
#include <queue>
#include "math.h"
#include <string>
using namespace std;
int main()
{
	int ans = 0;
	long long x, y;
	cin >> x >> y;
	while(x<=y){
		x *= 2;
		ans++;
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
# include <cmath>
# include <iostream>
# include <iomanip>


using namespace std;


int main() {
    double a, b, x; cin >> a >> b >> x;
    double s = x/a;
    double rad;

    if (s >= a*b/2) {  // triangle
        double h = (a*b-s)*2/a;
        rad = atan2(h, a);
    }
    else {  // rectangle
        double w = s*2/b;
        rad = atan2(b, w);
    }

    double ans = rad/(2*acos(-1))*360;
    cout << setprecision(10) << ans << endl;
    return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
     
    using namespace std;
     
    int main(){
    	
      string s;
      int n;
      cin>>n>>s;
      
      for(int i=0;i<s.size();i++){
      		int x = s[i]-'A';
        	x = (x+n)%26;
        	cout<<(char)('A'+ x);
      	}
      
      cout<<endl;
      return 0;
    }

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

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  long N;
  cin >> N;
  vector<long> A(N);
  for (long i = 0; i < N; i++) cin >> A.at(i);
  long tmp = A.at(0);
  for (long i = 1; i < N; i++) {
    tmp ^= A.at(i);
  }
  for (long i = 0; i < N; i++) {
    cout << (tmp ^ A.at(i)) << "\n";
  }
}

Measured memory_bytes: 4712
l = int(input())

a = map(int, input().split())
a = sorted(a, reverse=True)
#print(a)
if l%2==0:
	print(a[0] + sum(a[1:l//2])*2)
else:
	print(a[0] + sum(a[1:(l-1)//2])*2 + a[(l-1)//2])

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

int main(){
    ll a; cin >> a;
    string b; cin >>b;
    char b1=b[0];
    char b2=b[2];
    char b3=b[3];
    // cout << b1 << endl;
    // cout << b2 << endl;
    // cout << b3 << endl;
    int v1=b1-'0';
    int v2=b2-'0';
    int v3=b3-'0';
    int x=v1+v2+v3;
    a=a*(100*v1+10*v2+v3);
    a/=100;
    cout << a << endl;
}

Measured memory_bytes: 3596
#include <bits/stdc++.h>
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

using namespace std;

#define rep(i, a, b) for (int i = a; i < b; i++)
#define rrep(i, a, b) for (int i = a; i <= b; i++)
#define all(a)  begin((a)),end((a))
#define uniq(c) (c).erase(unique(all((c))), end((c)))

int main()
{
    int N; cin >> N;
    vector<int> A(N);
    rep (i, 0, N) {
        cin >> A[i];
        if (A[i] % 2 == 0) {
            if (A[i] % 3 == 0 or A[i] % 5 == 0) {
                continue;
            }
            else {
                cout << "DENIED" << endl;
                return 0;
            }
        }
    }

    cout << "APPROVED" << endl;
}

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

using namespace std;

typedef long long ll;

#define MOD 998244353
#define rep(i,a,b) for(int i=a;i<b;++i)
#define rrep(i,a,b) for(int i=a;i>b;--i)
#define vi vector<int>
#define vl vector<ll>
#define ld long double
#define vvi vector<vector<int>>
#define vvl vector<vector<long long>>
#define pii pair<int,int>
#define pll pair<long,long>
#define vpii vector<pii>
#define vpll vector<pll>
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define PI 3.1415926535897932384626433832795
#define fix(f,n) fixed<<setprecision(n)<<f
#define all(x) x.begin(),x.end()
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);


ll arr[100001];
bool vis[100001];
ll lvl[100001];



ll powM(ll a,ll b,ll m )
{ 
  a%=m;
  ll ans=1;
  while(b>0)
  {
    if(b&1)ans=ans*a%m;
    a=a*a%m;
    b>>=1;
  }

return ans;
}

ll pow(ll a,ll b)
{ 
  
  ll ans=1;
  while(b)
  {
    if(b&1)ans=ans*a;
    a=a*a;
    b>>=1;
  }

return ans;
}


/*const int N=200000;

ll fac[N+1];
ll inv[N+1];
ll p=998244353;

ll c(ll a, ll b,ll m)
{
  if(a<b)return 0;
  return (fac[a]*inv[b]%m)*(inv[a-b])%m;
}

void fill()
{
inv[0]=1;
fac[0]=1;

for(int i=1;i<=N;i++)
{
  fac[i]=fac[i-1]*i%p;
  inv[i]=powM(fac[i],p-2,p);
}

}
*/
//ld dp[2001][2001];


int main()
{  fast



ll a,b;
cin>>a>>b;
cout<<a*b<<"\n";

 return 0;

}


Measured memory_bytes: 3616
#ifdef DBG1
  #define LOCAL
#endif

#ifdef LOCAL
  #define _GLIBCXX_DEBUG
#endif

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cassert>
#include <cstring>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <set>

#ifdef DBG1
    #define dbg(...) fprintf(stderr, __VA_ARGS__)
#else
    #define dbg(...)
#endif

using namespace std;

const int INF = (1 << 30);

typedef long long ll;
typedef unsigned long long ull;
typedef pair <int, int> pii;

bool solve() {
  int n;
  if (scanf("%d", &n) != 1) { return false; }
  vector <int> pos1(n + 1), pos2(n + 1);
  for (int i = 0; i < 2 * n; ++i) {
    char ch;
    int x;
    scanf(" %c%d", &ch, &x);
    if (ch == 'B') {
      pos1[x] = i;
    } else {
      pos2[x] = i;
    }
  }
  int res = 0;
  for (int i = 1; i <= n; ++i) {
    for (int j = i + 1; j <= n; ++j) {
      if (pos1[i] > pos1[j]) {
        res++;
      }
      if (pos2[i] > pos2[j]) {
        res++;
      }
    }
  } 

  vector <vector<int>> inv1(n + 1, vector<int>(n + 1, 0));
  vector <vector<int>> inv2(n + 1, vector<int>(n + 1, 0));
  for (int i = 1; i <= n; ++i) {
    for (int j = 1; j <= n; ++j) {
      inv1[i][j] = inv1[i - 1][j];
      inv2[i][j] = inv2[i][j - 1];
      if (pos1[i] > pos2[j]) {
        inv1[i][j] += 1;
      }
      if (pos2[j] > pos1[i]) {
        inv2[i][j] += 1;
      }
    }
  }

  vector <vector<int>> dp(n + 1, vector <int>(n + 1, INF));
  dp[0][0] = 0;
  for (int i = 0; i <= n; ++i) {
    for (int j = 0; j <= n; ++j) {
      if (i) {
        dp[i][j] = min(dp[i][j], dp[i - 1][j] + inv2[i][j]);
      }
      if (j) {
        dp[i][j] = min(dp[i][j], dp[i][j - 1] + inv1[i][j]);
      }
    }
  }
  printf("%d\n", res + dp[n][n]);
  return true;
}

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

Measured memory_bytes: 47360
import sys
sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline

n = int(input())
a = list( map(int, input().split()))

a.sort(reverse=True)

from collections import deque
deq = deque([a[1], a[1]])

ans = a[0]

for i in range(2,n):
    ans += deq.popleft()
    deq.append(a[i])
    deq.append(a[i])

print(ans)

Measured memory_bytes: 31456
import re

s = input().strip()
t = input().strip()

ls = len(s)
lt = len(t)

if ls < lt:
    print('UNRESTORABLE')
else:
    s = s.replace('?', '.')
    ans = []
    for i in range(len(s) - len(t) + 1):
        m = re.match(s[i:i + lt], t)
        if m is None:
            continue
        ans.append((s[:i]+t+s[i+lt:]).replace('.', 'a'))
    if not ans:
        print('UNRESTORABLE')
    else:
        print(min(ans))


Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define rrep(i,n) RREP(i,(n)-1,0)
#define all(v) v.begin(), v.end()
#define endk '\n'
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;
const ll mod2 = 998244353;
const ld eps = 1e-10;
template<typename T1, typename T2> inline void chmin(T1 &a, T2 b){if(a>b) a=b;}
template<typename T1, typename T2> inline void chmax(T1 &a, T2 b){if(a<b) a=b;}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int r, c, k; cin >> r >> c >> k;
  vector<vector<ll>> V(r, vector<ll>(c));
  rep(i, k) {
    int r, c; ll v;
    cin >> r >> c >> v;
    r--; c--;
    V[r][c] = v;
  }
  vector<vector<vector<ll>>> dp(4, vector<vector<ll>>(r+1, vector<ll>(c+1)));
  rep(i, r) {
    rep(j, c) {
      rep(k, 4) {
        chmax(dp[k][i][j+1], dp[k][i][j]);
        if(k != 3) chmax(dp[k+1][i][j+1], dp[k][i][j]+V[i][j]);
      }
    }
    rep(j, c+1) {
      rep(k, 4) {
        chmax(dp[0][i+1][j], dp[k][i][j]);
        if(i != r-1 && j != 0) chmax(dp[1][i+1][j], dp[k][i][j]+V[i+1][j-1]);
      }
    }
  }
  ll ans = 0;
  rep(k, 4) chmax(ans, dp[k][r][c]);
  cout << ans << endk;
  return 0;
}


Measured memory_bytes: 425836
// 22
/****************************************************
https://searleser97.gitlab.io/algorithms/template.cpp
****************************************************/

#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define fors(_, x, n, s) for (int _ = x; _ < n; _ += s)
#define forn(_, x, n) fors(_, x, n, 1)
#define rep(_, n) forn(_, 0, n)
#define forrs(_, x, n, s) for (int _ = x; _ > n; _ -= s)
#define forrn(_, x, n) forrs(_, x, n, 1)
#define rrep(_, n) forrn(_, n - 1, -1)
#define fi first
#define se second
#define pb push_back
#define pairii pair<int, int>
#define all(x) x.begin(), x.end()
#ifdef LOCAL
#define cerr(s) cerr << "\033[48;5;196m\033[38;5;15m" s << "\033[0m"
#else
#define cerr(s)
#endif
// typedef __int128_t lli;
typedef long long int li;
typedef long double ld;
const int mod = 1e9 + 7;
// 12
void _main(int tc) {
  int h, w;
  cin >> h >> w;
  vector<string> mat(h);
  rep(i, h) cin >> mat[i];
  vector<vector<int>> mem(h, vector<int>(w));
  mem[h - 1][w - 1] = 1;
  const vector<pairii> moves = {{0, 1}, {1, 0}};
  rrep(i, h) {
    rrep(j, w) {
      for (auto& mv : moves) {
        int new_i = i + mv.fi, new_j = j + mv.se;
        if (new_i < h && new_j < w && mat[i][j] == '.') {
          mem[i][j] += mem[new_i][new_j];
          if (mem[i][j] >= mod) mem[i][j] -= mod;
        }
      }
    }
  }
  cout << mem[0][0] << endl;
}

int main() {
  ios_base::sync_with_stdio(0), cin.tie(0);
  _main(0);
  return 0;
  int tc;
  cin >> tc;
  rep(i, tc) _main(i + 1);
}

Measured memory_bytes: 5248
[a,b,c,d]=list(map(int,input().split()))
ans="No"
chokudai=c//b
if c%b!=0:
    chokudai+=1
aoki=a//d
if a%d!=0:
    aoki+=1
if chokudai<=aoki:
    ans="Yes"
print(ans)

Measured memory_bytes: 9184
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using llpair=pair<ll,ll>;
using llvec=vector<ll>;
using llmat=vector<vector<ll>>;
#define llmattp(name,a,b,num) name(a,vector<ll>(b,num))
#define LLINF 1LL<<60
#define ABS(x) ( (x)>0 ? (x) : -(x) )

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 a, ll b) {
	if(a==0||b==0) return 0;
	if(a<b) swap(a,b);
	ll tmp = a%b;
	while(tmp!=0) {
		a = b;
		b = tmp;
		tmp = a%b;
	}
	return b;
}

ll factorial(ll x) {
	ll f=1;
	for(ll i=2; i<x; i++) {
		f*=i;
	}
	return f;
}

ll nPr(ll n, ll r) {
	ll result=1;
	for(ll i=r+1; i<=n; i++) result*=i;
	return result;
}

ll nCr(ll n, ll r) {

	if (n == 0) { return 0; }
	if (r == 0) { return 1; }
	if (r == 1) { return n; }
	if (n == r) { return 1; }

	if (r > n / 2) { r = n / 2; }

	double result = 1;
	for (double i = 1; i <= r; i++) {
		result *= (n - i + 1) / i;
	}

	return (ll)result;
}

bool IsPrime(ll num) {
	if (num < 2) return false;
	else if (num == 2) return true;
	else if (num % 2 == 0) return false; // 偶数はあらかじめ除く

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

	// 素数である
	return true;
}

ll GreaterBinarySearch(ll *array, ll key, ll max, ll min) {
	if(array[max]<array[min]) {
		return NULL;
	} else {
		ll mid = max + (min-max)/2;
		if(array[mid]<key) {
			return GreaterBinarySearch(array,key,max,mid-1);
		} if(array[mid]>key) {
			return GreaterBinarySearch(array,key,mid+1,min);
		} else {
			return mid;
		}
	}
}

int main() {
	int n; cin>>n;
	int p[n]; for(int i=0; i<n; i++) cin>>p[i];

	int min=n+1;
	int result=0;
	for(int i=0; i<n; i++) {
		if(p[i]<min) {
			result++;
			min=p[i];
		}
	}
	cout<<result<<endl;
}


Measured memory_bytes: 1024
import java.io.*;
import java.util.*;
public class Main
{
  public static void main (String args[]) throws Exception
  {
    Scanner sc = new Scanner(System.in);
    int a = sc.nextInt(), b = sc.nextInt();
    double p= a*b;
    if (p%2==0)
    	System.out.println("Even");
    else
    	System.out.println("Odd");

    
  }
}

Measured memory_bytes: 23124
#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <unordered_map>
#include <queue>
#include <deque>
#include <cmath>
#include <math.h>
#include <string>
#include <time.h>
#include <random>
#include <memory.h>
#include <bitset>
using namespace std;

int n;
bool bpGraph[105][105];

bool bpm(bool bpGraph[105][105], int u,
	bool seen[], int matchR[])
{
	for (int v = 0; v < n; v++)
	{
		if (bpGraph[u][v] && !seen[v])
		{
			seen[v] = true;

			if (matchR[v] < 0 || bpm(bpGraph, matchR[v],
				seen, matchR))
			{
				matchR[v] = u;
				return true;
			}
		}
	}
	return false;
}

int maxBPM(bool bpGraph[105][105])
{
	int matchR[105];

	memset(matchR, -1, sizeof(matchR));

	int result = 0;
	for (int u = 0; u < n; u++)
	{
		bool seen[105];
		memset(seen, 0, sizeof(seen));

		if (bpm(bpGraph, u, seen, matchR))
			result++;
	}
	return result;
}

vector<pair<int, int> > red;
vector<pair<int, int> > blue;

int main()
{
	int i, j, a, b, c, d, x, y;

	cin >> n;

	for (i = 0; i < n; i++)
	{
		cin >> a >> b;
		red.push_back({ a, b });
	}
	for (i = 0; i < n; i++)
	{
		cin >> a >> b;
		blue.push_back({ a, b });
	}

	for (i = 0; i < n; i++)
	{
		for (j = 0; j < n; j++)
		{
			if (red[i].first < blue[j].first && red[i].second < blue[j].second)
			{
				bpGraph[i][j] = 1;
			}
		}
	}

	cout << maxBPM(bpGraph);

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <bitset>
#include<iomanip>
#include<functional>
using namespace std;
typedef long long ll;


long long GCD(long long a, long long b) {
    if (b == 0) return a;
    else return GCD(b, a % b);
}


int main() {
    int n, m;
    cin >> n >> m;
    vector<int> h(n);
    vector<int> road(n, 0);
    for (int i = 0; i < n; i++)cin >> h[i];
    for (int i = 0; i < m; i++) {
        int a, b;
        cin >> a >> b;
        a--;
        b--;
        road[a] = max(road[a], h[b]);
        road[b] = max(road[b], h[a]);
    }
    int ans = 0;
    for (int i = 0; i < n; i++) {
        ans += h[i] > road[i];
    }
    cout << ans << endl;
}


Measured memory_bytes: 4032
import java.util.*;
import java.util.stream.*;
 
public class Main {
	Scanner sc;
	int N;
	int M;
	
	int[] a;
	int[] work;
	
//=============
// constructor
//
	public Main() {
		sc = new Scanner(System.in);
	}
	
//==================
// instance methods
//
	void out(Object o) {
		System.out.println(o);
		System.out.flush();
	}
	
	public void exec() throws Exception {
		input();
		calc();
		output();
	}
	
	private void input() {
		// データ入力
		N = sc.nextInt();
		a = new int[N];
		for (int i = 0; i < N; i++) {
			a[i] = sc.nextInt();
		}
	}
	
	private void calc() {
		// 答えを入れていくワーク用領域
		work = new int[N];
		
		for (int i = N; i > 0; i--) {
			int m = 0;
			for (int j = i; j <= N; j += i) {
				m ^= work[j-1];
			}
			if (m != a[i-1]) work[i-1] = 1;
		}
		
		// work が答えとなる。
		M = (int)IntStream.of(work).filter(n -> n > 0).count();
	}
	
	private void output() {
		
		// 答え出力
		out(M);
		if (M > 0) {
			String result = IntStream.range(0, N)
								.filter(n -> work[n] != 0)
								.mapToObj(n -> String.valueOf(n+1))
								.collect(Collectors.joining(" "));
			out(result);
		}
	}
	
//======
// main
//
	public static void main(String[] args) throws Exception {
		Main m = new Main();
		m.exec();
	}
}


Measured memory_bytes: 64984
#include"bits/stdc++.h"

#define rep(i, N) for(int i = 0;i < N;i++)
typedef long long ll;
const int mod = 1e9 + 7;

using namespace std;

int main(void) {
	int n; cin >> n;
	string S; cin >> S;
	int ans = 0;

	for (int i = 1; i < S.length(); i++) {
		string A = S.substr(0, i), B = S.substr(i, S.length());
		map<char, bool> a, b;

		for (char x : A)a[x] = true;
		for (char x : B)b[x] = true;

		int cnt = 0;
		for (auto x : a)if (b.count(x.first) != 0)cnt++;
		ans = max(ans, cnt);
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>

using namespace std;

vector<int> solve(int N, const vector<vector<pair<int, int>>> &g)
{
	vector<int> c(N - 1, 0);
	
	queue<int> q;
	q.push(0); q.push(0);
	while (!q.empty()) {
		const int prev_color = q.front();
		q.pop();
		const int v = q.front();
		q.pop();
		int next_color = 1;
		for (auto &edge : g[v]) {
			if (c[edge.first] != 0) {
				continue;
			}
			if (next_color == prev_color) {
				++next_color;
			}
			c[edge.first] = next_color;
			q.push(next_color);
			q.push(edge.second);
			++next_color;
		}
	}

	return c;
}

int main()
{
	int N;
	cin >> N;
	vector<vector<pair<int, int>>> g(N);  // list of (edge_id, dst)
	for (int i = 0; i < N - 1; ++i) {
		int a, b;
		cin >> a >> b;
		--a;
		--b;
		g[a].emplace_back(i, b);
		g[b].emplace_back(i, a);
	}
	int K = 0;
	for (auto &edges : g) {
		K = max(K, (int)edges.size());
	}

	cout << K << endl;
	for (auto c : solve(N, g)) {
		cout << c << endl;
	}
}


Measured memory_bytes: 7040
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair <int, int> P;
#define rep( i, n, m ) for(int i = ( n ); i < ( m ); i++)
#define rep_d( i, n, m ) for(int i = ( n ) - 1; i >= ( m ); i--)
#define sort_asc( X ) sort(( X ).begin(), ( X ).end())
#define sort_desc( X ) sort(( X ).begin(), ( X ).end(), greater <>())

template <class T> bool chmax( T& a, T b );
template <class T> bool chmin( T& a, T b );
int* eratosthenes( int N );
bool bit_search( int pattern, int N );
template <class T> void cumulative_sum( T array, size_t N );

const ll INF = 1LL << 60;
const int k_mod = 1e9 + 7;

int main( void ){
	int N, M;
	cin >> N >> M;
	if (N < M){
		int temp = N;
		N = M;
		M = temp;
	}
	if (N - M > 1){
		cout << "0\n";
		return 0;
	}
	ll ans = 1;
	if (N != M){
		ans *= N;
		N--;
	}
	else
		ans *= 2;
	rep( i, 1, N+1 ){
		ans *= i;
		ans %= k_mod;
		ans *= i;
		ans %= k_mod;
	}
	cout << ans << endl;
}
int* eratosthenes( int N ){
	int* prime_array = new int[ N + 1 ];
	int lim = N;
	prime_array[ 0 ] = 0;
	prime_array[ 1 ] = 0;
	rep( i, 2, N + 1 ){
		prime_array[ i ] = 1;
	}
	rep( i, 2, lim ){
		if (prime_array[ i ] == 0)
			continue;
		lim = N / i;
		for(int j = i * 2; j < N + 1; j += i){
			prime_array[ j ] = 0;
		}
	}
	return prime_array;
}
template <class T> void cumulative_sum( T array, size_t N ) {
	rep( i, 1, N + 1 ){
		array[ i ] += array[ i - 1 ];
	}
}
template <class T> bool chmax( T& a, T b ) {
	if (a < b){
		a = b; return true;
	}
	return false;
}
template <class T> bool chmin( T& a, T b ) {
	if (a > b){
		a = b; return true;
	}
	return false;
}
bool bit_search( int pattern, int N ){
	int cnt = 0;
	rep( bit, 0, N ){
		if (pattern & ( 1 << bit )){
			cnt++;
		}
	}
	return true;
}


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

using namespace std;

template<typename T>
T lcm(T a, T b) {
    if (a == 0 || b == 0) return 0;
    return (a * b) / __gcd(a, b);
}

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

    set<int> st;
    long long l = 1;
    for (int i = 0; i < N; ++i) {
        long long a;
        cin >> a;
        a /= 2;
        st.insert(__builtin_ctz(a));
        l = lcm(l, a);
    }

    long long ans;
    if (st.size() != 1 or l > M) {
        ans = 0;
    } else {
        ans = M / l - M / (2 * l);
    }
    cout << ans << endl;
    return 0;
}


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

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

			String in = br.readLine();
			String chr[] = in.split(" ");
			int a = Integer.parseInt(chr[0]);
			int b = Integer.parseInt(chr[1]);
			 System.out.println(Math.max(a+b, Math.max(a-b, a*b)));
		}
	}
}

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


void solve1(int N, int K, string S){
    vector<int> Nums;
    int now = 1;
    int cnt = 0;
    for(int i = 0; i < N; i++){
        if(S[i] == (char)('0' + now)) cnt++;
        else{
            Nums.push_back(cnt);
            now = 1 - now;
            cnt = 1;
        }
    }
    if(cnt != 0) Nums.push_back(cnt);
    if(Nums.size() % 2 == 0) Nums.push_back(0);
    int Add = 2 * K + 1;
    int ans = 0;
    for(int i = 0; i < Nums.size(); i += 2){
        int tmp = 0;
        int left = i;
        int right = min(i + Add, (int)Nums.size());
        for(int j = left; j < right; j++){
            tmp += Nums[j];
        }
        ans = max(tmp, ans);
    }
    cout << ans << endl;
}

void solve2(int N, int K, string S){
    vector<int> Nums;
    int now = 1;
    int cnt = 0;
    for(int i = 0; i < N; i++){
        if(S[i] == (char)('0' + now)) cnt++;
        else{
            Nums.push_back(cnt);
            now = 1 - now;
            cnt = 1;
        }
    }
    if(cnt != 0) Nums.push_back(cnt);
    if(Nums.size() % 2 == 0) Nums.push_back(0);
    int Add = 2 * K + 1;
    int ans = 0;
    int left = 0;
    int right = 0;
    int tmp = 0;

    for(int i = 0; i < Nums.size(); i += 2){
        int Nextleft = i;
        int Nextright = min(i + Add, (int)Nums.size());
        while(Nextleft > left){
            tmp -= Nums[left];
            left++;
        }
        while(Nextright > right){
            tmp += Nums[right];
            right++;
        }
        ans = max(tmp, ans);
    }
    cout << ans << endl;
}

void solve3(int N, int K, string S){

}

int main(){
    int N, K;
    cin >> N >> K;
    string S;
    cin >> S;
    //solve1(N, K, S);
    solve2(N, K, S);
    //solve3(N, K, S);
    return 0;
}

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

int main() {
  
  int N,M;
  cin >> N>>M;
  bool as=true;
  if(M==0){
    as=false;
  }
  if(as){
  vector<vector<int>> a(M, vector<int>(2));
 
  for (int i = 0; i < M; i++) {
    for (int j = 0; j < 2; j++) {
      cin >> a.at(i).at(j);
    }
  }
  sort(a.begin(), a.end());
  bool ans=true;
  if(a.at(0).at(0)==1&&a.at(0).at(1)==0&&N!=1){
    ans=false;
  }
  for (int i = 0; i < M; i++) {
    for (int j = i+1; j < M; j++) {
        if(a.at(i).at(0)==a.at(j).at(0)&&a.at(i).at(1)!=a.at(j).at(1)){
          ans=false;
     
        }
    }
  }
  if(ans){
    
      for (int i = 1; i <=N; i++) {
        bool t=false;
        for (int j = 0; j < M; j++) {
          if(a.at(j).at(0)==i){
            t=true;
            cout<<a.at(j).at(1);
            break;
          }
        }
        if(t){
          continue;
        }
        else{
          if(i==1){
            cout<<1;
          }
          else{
            cout<<0;
          }
        }
      }
    }
  else{
    cout<<-1<<endl;
  }
  }
  else{
    if(N==1){
      cout<<0<<endl;
    }
    else{
    cout<<1;
       for (int i = 2; i <=N; i++) {
         cout<<0;
       }
    }
  }
}







Measured memory_bytes: 256
#include<stdio.h>
int main(){
  int n,d,x,y,i,ans=0;
  scanf("%d %d",&n,&d);
  for(i=1;i<=n;i++){
    scanf("%d %d",&x,&y);
    if(pow(x,2.0)+pow(y,2.0) <= pow(d,2.0)) ans++;
  }
  printf("%d", ans);
  return 0;
}


Measured memory_bytes: 1704
#include <bits/stdc++.h>
using namespace std;
int main(){
  char s[3];
  cin>>s[0]>>s[1]>>s[2];
  if(s[0]==s[1]&&s[0]==s[2]&&s[1]==s[2]){
    cout<<"No"<<endl;
    return 0;
  }
  cout<<"Yes"<<endl;
  return 0;
}

Measured memory_bytes: 256
<?php
while($line = trim(fgets(STDIN))) {
	$deck = array(1,2,3,4,5,6,7,8,9,10);
	list($c1, $c2, $c3) = explode(' ', $line);
	unset($deck[$c1 - 1]);
	unset($deck[$c2 - 1]);
	unset($deck[$c3 - 1]);

	$now = $c1 + $c2;
	$diff = 20 - $now;

	$safe = 0;
	foreach ($deck as $card) {
		if ($card <= $diff) {
			$safe++;
		}
	}
	echo ($safe >= count($deck) - $safe) ? "YES\n" : "NO\n";

}

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

int main(){
    int N;cin>>N;
    vector<pair<int,int> >A(N);
    for(int i=0;i<N;i++){
        cin>>A[i].first;
        A[i].second=i;
    }
    sort(A.begin(),A.end());
    for(int i=0;i<N;i++)cout<<A[i].second+1<<" ";
    cout<<endl;

}

Measured memory_bytes: 1536
import java.util.*;
import java.io.*;
 
public class Main {
    public static void main(String[] args) throws Exception {
        FastScanner sc = new FastScanner(System.in);
        PrintWriter pw = new PrintWriter(System.out);
        int n = sc.nextInt();
        for(int i = 1; i <= 9; i++){
            if(i*111 >= n){
                pw.println(i*111);
                break;
            }
        }
        pw.flush();
    }

    static class GeekInteger {
        public static void save_sort(int[] array) {
            shuffle(array);
            Arrays.sort(array);
        }
 
        public static int[] shuffle(int[] array) {
            int n = array.length;
            Random random = new Random();
            for (int i = 0, j; i < n; i++) {
                j = i + random.nextInt(n - i);
                int randomElement = array[j];
                array[j] = array[i];
                array[i] = randomElement;
            }
            return array;
        }
 
    }
}

class FastScanner {
    private BufferedReader reader = null;
    private StringTokenizer tokenizer = null;
    public FastScanner(InputStream in) {
        reader = new BufferedReader(new InputStreamReader(in));
        tokenizer = null;
    }

    public String next() {
        if (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                tokenizer = new StringTokenizer(reader.readLine());
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return tokenizer.nextToken();
    }

    public String nextLine() {
        if (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                return reader.readLine();
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return tokenizer.nextToken("\n");
    }

    public long nextLong() {
        return Long.parseLong(next());
    }

    public int nextInt() {
        return Integer.parseInt(next());
    }

    public double nextDouble() {
         return Double.parseDouble(next());
    }
    
    public String[] nextArray(int n) {
        String[] a = new String[n];
        for (int i = 0; i < n; i++)
            a[i] = next();
        return a;
    }

    public int[] nextIntArray(int n) {
        int[] a = new int[n];
        for (int i = 0; i < n; i++)
            a[i] = nextInt();
        return a;
    }

    public long[] nextLongArray(int n) {
        long[] a = new long[n];
        for (int i = 0; i < n; i++)
            a[i] = nextLong();
        return a;
    } 
}


Measured memory_bytes: 25296
INT = lambda: int(input())
INTM = lambda: map(int,input().split())
STRM = lambda: map(str,input().split())
STR = lambda: str(input())
LIST = lambda: list(map(int,input().split()))
LISTS = lambda: list(map(str,input().split()))

import itertools, math

def distance(x1,y1,x2,y2):
    return(((x2-x1)**2+(y2-y1)**2)**0.5)

def do():
    xs=[]
    ys=[]
    per=[]
    n=INT()
    ans=0
    for i in range(n):
        x,y=INTM()
        xs.append(x)
        ys.append(y)
        per.append(i)
    
    for i in itertools.permutations(per, n):
        for k in range(n-1):
            ans+=distance(xs[i[k]],ys[i[k]],xs[i[k+1]],ys[i[k+1]])
        #print(ans)
    
    print(ans/math.factorial(n))

    
if __name__=='__main__':
    do()

Measured memory_bytes: 9448
#include <iostream>
#include <string>
#include <algorithm>


int main(){
  std::string s;
  std::cin >> s;
  int numA = std::count(s.begin(), s.end(), 'A');

  if(numA == 0 || numA == 3){
    std::cout << "No";
  }
  else{
    std::cout << "Yes";
  }

  return 0;
}


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

int n, a[10001], sum;

int main() {
    cin >> n;
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
        while (a[i] % 2 == 0){
            a[i] /= 2;
            sum++;
        }
    }
    cout << sum << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
using namespace std;
int main() {
    int A, B, K;
    cin >> A >> B >> K;
    vector<int> v;
    for (int i = 1; i <= A || i <= B; i++) {
        if (A % i == 0 && B % i == 0) v.push_back(i);
    }
    cout << v[v.size() - K] << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define be(v) (v).begin(),(v).end()
#define pb(q) push_back(q)
typedef long long ll;
using namespace std;
const ll mod=1000000007, INF=(1LL<<60);
#define doublecout(a) cout<<fixed<<setprecision(10)<<a<<endl;

int main() {
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    int a;
    vector<int> b(100003, 0);
    for(int i=0;i<n;i++){
    	cin >> a;
    	b[a]++;
    	if(a) b[a-1]++;
    	b[a+1]++; 
    }
    int ans = 0;
    for(int i: b){
    	ans = max(ans, i);
    }
    cout << ans << endl;


    return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define N 1000005
#define ll long long int 	
#define MP make_pair
#define pb push_back
#define ppb pop_back
#define sp " "
#define endl "\n"
#define fi first
#define se second
#define ii pair<int,int>
#define lli pair<ll,ll>
#define fast cin.tie(0);cout.tie(0);ios_base::sync_with_stdio(false)
#define fast2 freopen ("kmp.gir","r",stdin);freopen ("kmp.cik","w",stdout);
#define mod 2019
#define fs(x,y) for(ll i=1;i<=y;i++) cin>>x[i]
#define fo(i,x,y) for(ll i=x;i<=y;i++)
using namespace std;
 
ll n,m,ar[N],sum=INT_MAX,a,b,tut[N],l,r;
 
int main()
{
	fast;
	cin>>l>>r;
	if(r-l>=2019)
		return cout<<0,0;
	ll a=INT_MAX;
	for(ll i=l;i<=r-1;i++)
		for(ll j=i+1;j<=r;j++)
		{
			a=min(a,(i*j)%mod);
			// cout<<
		}
	cout<<a;
 }
 
 
/*     cd onedrive\desktop\kod
cls
 
 
*/

Measured memory_bytes: 256
//============================================================================
// Name        : c.cpp
// Author      :
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <iostream>
#include<vector>
using namespace std;

int main() {
	int n;cin>>n;
	int k;cin>>k;
	vector<int> a(n+2);
	for(int i=0;i<n;i++){
		cin>>a[i+1];
	}
	a[0]=0;a[n+1]=0;
	for(int i=0;i<k;i++){
		int flag=1;
		vector<int> nexta(n+2,0);
		for(int j=1;j<=n;j++){
			int l=max(1,j-a[j]);
			nexta[l]+=1;
			int r=min(n+1,j+1+a[j]);
			nexta[r]+=-1;
		}
//		for(int j=0;j<=n+1;j++){
//			cout<<nexta[j]<<' ';
//		}cout<<endl;
		for(int j=1;j<=n+1;j++){
			nexta[j]+=nexta[j-1];
		}
		a=nexta;
		for(int j=1;j<=n;j++){
			if(a[j]!=n){
				flag=0;
			}
		}
		if(flag)break;
	}
	for(int i=1;i<=n;i++){
		cout<<a[i]<<' ';
	}cout<<endl;
	return 0;
}

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

int main(){
    int n;
    cin>>n;
    int v[n],c[n],sum=0;
    for(int i=0;i<n;i++) cin>>v[i];
    for(int i=0;i<n;i++) cin>>c[i];
    for(int i=0;i<n;i++){
        if(v[i]>c[i]) sum+=v[i]-c[i];
    }
    cout<<sum<<endl;
}

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

int main()
{
    string s;
    ll k;
    cin >> s >> k;
    int n = s.size();
    int t = 0, cnt = 0;
    char c;
    for(int i = 0; i < n; i++){
        if(s[i] != '1'){
            t = 1;
            c = s[i];
            break;
        }else if(s[i] == '1'){
            cnt++;
        }
    }
    if(t == 0 || cnt >= k){
        cout << 1;
    }else{
        cout << c;
    }
}

Measured memory_bytes: 256
n,m=[int(j)for j in input().split()]
l=[[]for i in range(n+1)]
for i in range(m):
    a,b=[int(j)for j in input().split()]
    l[a].append(b)
    l[b].append(a)
ans=[0]*(n+1)
from collections import deque
q=deque([1])
s=set([1])
while q:
    i=q.popleft()
    for k in l[i]:
        if k not in s:
            ans[k]=i
            q.append(k)
            s.add(k)

if 0 not in ans[2:]:
    print("Yes")
    print('\n'.join(map(str,ans[2:])))
else:
    print("No")

Measured memory_bytes: 45612
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int mapx[4][4];
    {
        cin>>mapx[1][1]>>mapx[1][2]>>mapx[2][2];
    }
    mapx[3][1]=mapx[1][1]+mapx[1][2]-mapx[2][2];

    mapx[3][2]=mapx[1][1]-mapx[2][2];
    mapx[3][3]=mapx[1][2]-mapx[2][2];
    int x;
    mapx[1][3]=mapx[1][1]+mapx[1][2]-mapx[3][1]-mapx[3][2]-mapx[3][3];
    x=mapx[1][1]+mapx[1][2]+mapx[1][3];
    mapx[2][1]=x-mapx[1][1]-mapx[3][1];
    mapx[3][2]+=mapx[1][3];
    mapx[3][3]+=mapx[1][3];
    mapx[2][3]=x-mapx[2][1]-mapx[2][2];
    for(int i=1;i<=3;i++)
    {
        for(int j=1;j<=3;j++)
        {
        cout<<mapx[i][j];
        if(j==1||j==2)
        cout<<" ";
        else
        cout<<endl;}
    }
 return 0;
}


Measured memory_bytes: 256
Scanf.scanf "%d %d" (fun n q ->
    let c = Array.init n (fun _ -> Scanf.scanf " %d" (fun a -> a)) in
    let queries = Array.init q (fun i -> Scanf.scanf " %d %d" (fun l r -> r - 1, l - 1, i)) in
    Array.sort compare queries;
    let ans = Array.make q 0 in

    let bit = Array.make (n + 1) 0 in
    let last_visit = Array.make 500001 (-1) in

    let ll  (r, l, i) = l in
    let rr  (r, l, i) = r in
    let idx (r, l, i) = i in

    let update index v =
        let rec loop ii =
            if ii <= n then (
                bit.(ii) <- bit.(ii) + v;
                loop (ii + (ii land (-ii)))
            )
        in
        loop index
    in
    let query index =
        let rec loop ii sum =
            if ii > 0 then (
                loop (ii - (ii land (-ii))) (sum + bit.(ii))
            ) else sum
        in
        loop index 0
    in

    let rec loop i query_counter =
        if i < n then (
            if last_visit.(c.(i)) <> -1 then
                update (last_visit.(c.(i)) + 1) (-1);
            last_visit.(c.(i)) <- i;
            update (i + 1) 1;

            let rec loop2 query_counter =
                if query_counter < q && rr queries.(query_counter) = i then  (
                    ans.(idx queries.(query_counter)) <-
                        query (rr queries.(query_counter) + 1) - query (ll queries.(query_counter));
                    loop2 (query_counter + 1)
                ) else query_counter
            in
            let query_counter = loop2 query_counter in
            loop (i + 1) query_counter
        )
    in
    loop 0 0;
    Array.iter (Printf.printf "%d\n") ans;
)


Measured memory_bytes: 43468
#include <iostream>
#include <cmath>

using namespace std;

int main(){
    int a[4], b[4], hit, blow;
    
    while(cin >> a[0] >> a[1] >> a[2] >> a[3])
    {
        for(int i = 0 ; i < 4 ; i++)
        {
            cin >> b[i];
        }
        hit = 0;
        blow = 0;
        for(int i = 0 ; i < 4 ; i++)
        {
            for(int j = 0 ; j < 4 ; j++)
            {
                if(a[i] == b[j])
                {
                    if(i == j)
                    {
                        hit++;
                    }
                    else
                    {
                        blow++;
                    }
                }
                
            }
        }
        cout << hit << " " << blow << endl;
    }
    return 0;
}

Measured memory_bytes: 3044
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <map>
#include <list>
#include <set>
#include <algorithm>
#include <cmath>
#include <queue>
#include <iterator>
#include <functional>
#include <numeric>
#include <cmath>
#include <stack>

using namespace std;

#define ll long long
#define f0(i,n)for(i=0;i<n;i++)
#define f1(i,n)for(i=1;i<=n;i++)
#define fc(i,c,n)for(i=c;i<=n;i++)
#define f0r(i,n)for(i=n-1;i>=0;i--)
#define f1r(i,n)for(i=n;i>0;i--)
#define fcr(i,c,n)for(i=n;i>=c;i--)
#define IO ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

typedef list<ll> LST;
typedef vector<ll> VEC;
typedef map<ll, ll> MAP;

ll i, j, q;
ll n, m, p, k, t, f, s, v, h;
ll a, b, c, d;
ll x, y, z, w, l, r;
ll one = 1, zero = 0, ans = 0, cnt = 0;
ll mod = 1000000007;
ll INF = 9223372036854775807;
ll a1, a2, a3 = 0 , a4, a5, a6, a7, a8;
string st1, st2, st3, st4;
char ch1, ch2, ch3;

int main() {
	IO;
	ifstream fin("Text.txt");
	
	cin >> n >> x;
	VEC vc(n);
	f0(i, n)
		cin >> vc[i];
	sort(vc.begin(), vc.end());
	i = 0;
	while (i < n && vc[i] <= x) {
		x-=vc[i];
		i++;
	}
	if (x && i==n)
		i--;
	cout << i << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const int maxn=2e5+5;
const int mod=1e9+7;
ll fac[maxn]={1},ifac[maxn];
inline ll fastpow(ll a,ll b) {
	ll ans=1;
	for(;b;b>>=1,a=a*a%mod) if(b&1) ans=ans*a%mod;
	return ans;
}
inline void  init() {
	for(int i=1;i<maxn;i++) fac[i]=fac[i-1]*i%mod;
	ifac[maxn-1]=fastpow(fac[maxn-1],mod-2);
	for(int i=maxn-2;~i;i--) ifac[i]=ifac[i+1]*(i+1)%mod;
}
inline ll C(ll n,ll m) {
	return fac[n]*ifac[m]%mod*ifac[n-m]%mod;
}
int main() {
    init();
    ll h,w,a,b;cin>>h>>w>>a>>b;
    ll ans=0;
    for(int i=b+1;i<=w;i++) {
    	ans=(ans+C(h-1-a+i-1,i-1)*C(w-i+a-1,a-1)%mod)%mod;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 6748
#include<stdio.h>
#define MAX 200000
int max(int,int);
int min(int,int);

int main(){
  int n,i,R[MAX];
  int maxt,mint;

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

  maxt=-2000000000;
  mint=R[0];

  for(i=1;i<n;i++){
    maxt = max(maxt,R[i]-mint);
    mint = min(mint,R[i]);
  }

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

  return 0;
}

int max(int a,int b){
  if(a>b){
    return a;
  }else{return b;}
}

int min(int a,int b){
  if(a<b){
    return a;
  }else{return b;}
}

Measured memory_bytes: 1376
#include <iostream>

#include <vector>

#include <algorithm>
#include <functional>

using std::cin;
using std::cout;
using std::endl;

using std::vector;

using std::greater;
using std::sort;

static int
solve(int N, vector<int> &a)
{
  sort(a.begin(), a.end(), greater<int>());
  int point_a = 0;
  int point_b = 0;
  for (int n = 0; n < N; n++)
  {
    point_a += a[n];
    if (++n < N)
    {
      point_b += a[n];
    }
  }
  return point_a - point_b;
}

int
main()
{
  int N;
  cin >> N;
  vector<int> a(N);
  for (int n = 0; n < N; n++)
  {
    cin >> a[n];
  }
  cout << solve(N, a) << endl;
  return 0;
}


Measured memory_bytes: 256
L = [int(input()) for i in range(5)]

time = 0
flag = 0
Loss = []

for i in range(5):
    if L[i]%10 == 0:
        time+=L[i]
        Loss.append(0)
    else:
        time+=(L[i]-L[i]%10+10)
        Loss.append(10-L[i]%10)

time -= max(Loss)
print(time)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int N;
    cin >> N;
    if (N<=111) cout << 111 <<endl;
    else if (111<N && N<=222) cout << 222 << endl;
    else if (222<N && N<=333) cout << 333 << endl;
    else if (333<N && N<=444) cout << 444 << endl;
    else if (444<N && N<=555) cout << 555 << endl;
    else if (555<N && N<=666) cout << 666 << endl;
    else if (666<N && N<=777) cout << 777 << endl;
    else if (777<N && N<=888) cout << 888 << endl;
    else if (888<N && N<=999) cout << 999 << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cmath>
//#include<bits/stdc++.h>
#define int long long
#define mod 1000000007
#define for0(i, n) for(int i = 0; i < (n); i++)
#define for1(i, n) for(int i = 1; i <= (n);i++)
#define mp make_pair
#define all(x) x.begin(),x.end()
using namespace std;
int n, sum;
int a[123456], b[123456];
bool t[123456];
signed main() {
	cin >> n;
	for1(i, n) cin >> a[i];
	for1(i, n) {
		cin >> b[i];
		a[i] -= b[i];
		sum += a[i];
	}
	if (sum < 0) { cout << "-1\n"; return 0; }
	sort(a + 1, a + n + 1);
	int p = n;
	for1(i, n) {
		while (a[i] < 0) {
			t[i] = 1;
			if (abs(a[i]) < a[p]) {
				a[p] += a[i]; a[i] = 0; t[p] = 1;
			}
			else {
				a[i] += a[p]; a[p] = 0; t[p] = 1; p--;
			}
		}
	}
	int ans = 0; for1(i, n)ans += t[i];
	cout << ans << endl;
}

Measured memory_bytes: 1920
#include<bits/stdc++.h>
#define faster  ios :: sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll long long
#define ull unsigned long long
#define pb push_back
const double PI = acos(-1.0);
using namespace std;

int main()
{
    faster

    int n;
    cin>>n;
    n=2*n;
    int a[2*n];

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

    sort(a,a+n);

    int s=0;

    for(int i=0; i<n; i=i+2)
    {
        s=s+a[i];
    }

    cout<<s<<endl;




    return 0;
}

Measured memory_bytes: 3644
#include <bits/stdc++.h>
#define inf 0x3f3f3f3f
#define pb push_back
#define fi first
#define se second

typedef long long ll;
typedef unsigned long long ull;

using namespace std;

int n;
vector <int> v;

void read() {
  cin >> n;
  for(int i = 0; i < n; ++i) {
    int x;
    cin >> x;
    v.pb(x);
  }
}

void solve() {
  int sol = 0;
  sort(v.begin(), v.end());
  cout << v[n / 2] - v[n / 2 - 1];
}

int main() {
  ios :: sync_with_stdio(false);
  cin.tie(nullptr);
  read();
  solve();
  return 0;
}


Measured memory_bytes: 892