akhauriyash/Code-Regression huggingface dataset:
//run: g++ -std=c++14 -o run_sol.exe solution.cpp -DLOCAL_JUDGE
#include<bits/stdc++.h>
#define INF 0x7fffffff
#define INFLL 1e17
#define PI 2*acos(0.0)
#define show(x) cout<< #x <<" is "<< x <<"\n"
using namespace std;

#define FS first
#define SC second
#define PB(t) push_back(t)
#define LEN(t) ((int)t.size())
#define ALL(t) t.begin(),t.end()
#define MP(x, y) make_pair((x), (y))
#define Fill(a,c) memset(&a, c, sizeof(a))
#define POPCOUNT __builtin_popcount

typedef long long LL;
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<LL> VLL;
typedef vector<PII> VPII;

vector<VI> G;
VI prof;

int dfs (int node) {
    int res = 0;
    if (prof[node] >= 0) {
        return prof[node];
    }

    for (auto v : G[node]) {
        res = max(res, dfs(v) + 1);
    }

    prof[node] = res;
    return res;
}

int main() {
    #ifdef LOCAL_JUDGE
        freopen("../input.txt", "rt", stdin);
        freopen("../output.txt", "wt", stdout);
    #endif

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

    for (int n, m, u, v; cin >> n >> m ; ) {
        //VI inD(n, 0);
        prof.assign(n, -1);
        G.assign(n, VI());

        for (int i = 0; i < m; i++) {
            cin >> u >> v;
            u--; v--;
            G[u].PB(v);
            // inD[v]++;
        }
        int res = 0;
        for (int i = 0; i < n; i++) {
            // if (inD[i] == 0) {                
                res = max(res, dfs(i));
            // }
        }

        cout << res << "\n";
        
    }
    
return 0;
}

Measured memory_bytes: 8192
#include<bits/stdc++.h>
#define ll long long int
using namespace std;
int main(){
  int n,oddn=0,evenn=0,oddcn=0,evencn=0,oddscn,evenscn;
  int odd,even;
  int oddc[100001],evenc[100001];
  cin>>n;
  for(int i=0;i<100001;i++){
    oddc[i]=evenc[i]=0;
  }
  for(int i=0;i<n/2;i++){
    cin>>odd>>even;
    oddc[odd]++;
    evenc[even]++;
  }
  for(int i=0;i<100001;i++){
    if(oddcn<=oddc[i]){
      oddn=i;
      oddscn=oddcn;
      oddcn=oddc[i];
    }
    else if(oddscn<oddc[i]) oddscn=oddc[i];
    if(evencn<=evenc[i]){
      evenn=i;
      evenscn=evencn;
      evencn=evenc[i];
    }
    else if(evenscn<evenc[i]) evenscn=evenc[i];
  }
  if(oddn!=evenn){
    cout<<n-oddcn-evencn<<endl;
  }
  else{
    if(oddcn+evencn==n){
      cout<<n/2<<endl;
    }
    else if(oddcn>evencn){
      cout<<n-oddcn-evenscn<<endl;
    }
    else if(evencn>oddcn){
      cout<<n-evencn-oddscn<<endl;
    }
    else{
      if(oddscn>=evenscn){
	cout<<n-oddscn-evencn<<endl;
      }else{
	cout<<n-oddcn-evenscn<<endl;
      }
    }
  }
  return 0;
}


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

int main(){
  int a,b;
  string op = " ";
  cin >> a >> op >> b;

while(op != "?"){
  if(op == "+"){
    cout << a+b << endl; 
  } else if(op == "-"){
    cout << a-b << endl;
  }else if(op == "*"){
    cout << a*b << endl;
  }else if(op == "/"){
    cout << a/b << endl;
  }
  cin >> a >> op >> b;
}

  return 0;
}


Measured memory_bytes: 3156
# coding: utf-8
n, m = map(int,input().split())
r = float('inf')
l = 0
L = []
for i in range(m):
    l_, r_ = map(int,input().split())
    L.append([l_,r_])
    l = max(l_, l)
    r = min(r_, r)
ans = 0
print(max(0, r-l+1))

Measured memory_bytes: 87396
# coding: utf-8

#N = int(input())
L = []
p1 = 0
p2 = float('inf')
r1 = float('inf')
r2 = 0
S = list(input())
#print(S)
ans = 0
for s in S:
    if s == "1":
        ans += 1
    
print(ans)

Measured memory_bytes: 9032
#include <bits/stdc++.h>
#define INF 2e9
#define MOD 1000000007
#define MOD9 998244353
#define intMAX 51000;
#define PI 3.14159265359
using namespace std;
typedef long long llong;
typedef long double ldouble;

using Graph = vector<vector<int>>;

int main(){
	int N;
  cin >> N;
  llong ans = INF;
  for(int i=0; i<N; ++i){
    llong A;
    cin >> A;
    llong count = 0;
    while(A%2==0){
      A /= 2;
      ++count;
    }
    ans = min(ans, count);
  }
  cout << ans << endl;
}

Measured memory_bytes: 3608
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int N =1e5+100;
int f[N],a[N],ma[N],ans[N];
int Find(int x){
    if(x==f[x]) return f[x];
    return f[x] =Find(f[x]);
}

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

    int n,m,k;
    cin>>n>>m>>k;
    for(int i=1;i<=n;i++) f[i] =i;
    for(int i=0,x,y;i<m;i++){
        cin>>x>>y;
        a[x]++,a[y]++;
        f[Find(x)]=Find(y);
    }
    for(int i=1;i<=n;i++){
        ma[Find(i)]++;
    }
    for(int i=1;i<=n;i++){
        ans[i] =ma[f[i]]-a[i]-1;
    }
    for(int i=0,x,y;i<k;i++){
        cin>>x>>y;
        if(f[x]==f[y]) ans[x]--,ans[y]--;
    }
    for(int i=1;i<=n;i++){
        cout<<ans[i]<<" ";
    }
    cout<<endl;
    return 0;
}


Measured memory_bytes: 2688
#include<bits/stdc++.h>
using namespace std;
int main()
{
	string s;
	cin>>s;
	for(int i=0;i<s.size();i++)
	{
		if(i%2==0)
		{
			cout<<s[i];
		}
	 } 
	return 0;
 } 

Measured memory_bytes: 512
#include <iostream>
#include <cstdio>
#include <algorithm>

using namespace std;

int main()
{
    string a,b;
    cin >> a >> b;
    sort(b.begin(),b.end());
    reverse(b.begin(),b.end());
    sort(a.begin(),a.end());
    if(b>a)
    {
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }
}

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

const int mod = 1000000007;

int H, W;
int ok[1009][1009];
int dp[1009][1009];

int main() {
    cin >> H >> W;
    for(int i = 1; i <= H; i++)
        for(int j = 1; j <= W; j++) {
            char c;
            cin >> c;
            ok[i][j] = (c == '.');
        }

    dp[1][1] = 1;
    for(int i = 1; i <= H; i++)
        for(int j = (i == 1 ? 2 : 1); j <= W; j++)
            dp[i][j] = ok[i][j] * (dp[i - 1][j] + dp[i][j - 1]) % mod;

    cout << dp[H][W] << endl;
}

Measured memory_bytes: 8192
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <math.h>
#include <iomanip>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdlib>
#include <map>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define pie 3.141592653589793238462643383279
#define INF 1000000007
#define ggr getchar(); getchar();return 0;
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x%y);
}
int lcm(int x, int y) {
	return x / gcd(x, y)*y;
}

string x;
int ta, ans;

signed main() {
	cin >> x;
	for (int i = 0; i < x.size(); i++) {
		if (x[i] == 'S')ta++;
		else if (ta >= 1) {
			ta--;
			ans += 2;
		}
	}
	cout << x.size() - ans << endl;
	ggr
}

Measured memory_bytes: 640
#include <iostream>
#include <string>
#include <cmath>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
#define _USE_MATH_DEFINES
#include <math.h>
#include <functional>
#include<complex>
using namespace std;

#define rep(i,x) for(ll i=0;i<x;i++)
#define repn(i,x) for(ll i=1;i<=x;i++)

typedef long long ll;
const ll INF = 1e17;
const ll MOD = 1000000007;
const ll MAX = 4000001;
const long double eps = 1E-14;

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

ll min(ll a, ll b) {
	if (a > b) { return b; }
	return a;
}

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

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

struct edge {
	ll ind;
	ll fr;
	ll to;
	ll d;
};

class mint {
	long long x;
public:
	mint(long long x = 0) : x((x% MOD + MOD) % MOD) {}
	mint operator-() const {
		return mint(-x);
	}
	mint& operator+=(const mint& a) {
		if ((x += a.x) >= MOD) x -= MOD;
		return *this;
	}
	mint& operator-=(const mint& a) {
		if ((x += MOD - a.x) >= MOD) x -= MOD;
		return *this;
	}
	mint& operator*=(const  mint& a) {
		(x *= a.x) %= MOD;
		return *this;
	}
	mint operator+(const mint& a) const {
		mint res(*this);
		return res += a;
	}
	mint operator-(const mint& a) const {
		mint res(*this);
		return res -= a;
	}
	mint operator*(const mint& a) const {
		mint res(*this);
		return res *= a;
	}

	mint pow(ll t) const {
		if (!t) return 1;
		mint a = pow(t >> 1);
		a *= a;
		if (t & 1) a *= *this;
		return a;
	}

	// for prime MOD
	mint inv() const {
		return pow(MOD - 2);
	}
	mint& operator/=(const mint& a) {
		return (*this) *= a.inv();
	}
	mint operator/(const mint& a) const {
		mint res(*this);
		return res /= a;
	}

	friend ostream& operator<<(ostream& os, const mint& m) {
		os << m.x;
		return os;
	}
};

mint pw(mint a, ll b) {
	if (b == 0) { return 1; }
	mint ret = pw(a, b >> 1);
	ret *= ret;
	if (b & 1) { ret *= a; }
	return ret;
}

typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef vector<vector<vector<ll>>> vvvll;

typedef vector<mint> vmint;
typedef vector<vector<mint>> vvmint;
typedef vector<vector<vector<mint>>> vvvmint;

//////////////////////////////////////

int main() {
	ll N, Q;
	cin >> N >> Q;
	vll q(Q + 1);
	q[0] = N;
	repn(i, Q)cin >> q[i];

	vll a;
	ll mn = 1e18+INF;
	for (ll i = Q; i >= 0; i--) {
		if (q[i] < mn) { a.push_back(q[i]); mn = q[i]; }
	}

	reverse(a.begin(), a.end());
	ll M = a.size();

	//rep(i, M)cout << a[i] << endl;
	
	vector<ll> count(M, 0);
	count[M - 1] = 1;

	vector<ll> c(N + 1, 0);

	for (ll i = M - 1; i >= 0; i--) {

		ll x = a[i];
		while (x > a[0]) {
			auto itr = lower_bound(a.begin(), a.end(), x);
			ll d = distance(a.begin(), itr) - 1;
			count[d] += x / a[d] * count[i];
			x %= a[d];
		}

		c[x] += count[i];

		//cout << i << endl;
		//rep(j, N + 1)cout << j << " " << c[j] << endl;
	}

	//rep(i, N+1)cout <<i<<" "<< c[i] << endl;

	vll ans(N + 1, 0);
	ans[N] = c[N];
	for (ll i = N - 1; i >= 1; i--)ans[i] = ans[i + 1] + c[i];

	repn(i, N)cout << ans[i] << endl;
}

Measured memory_bytes: 7208
// C++ 14
#include <bits/stdc++.h>
using namespace std;
template <typename T>  ostream& operator<<(ostream& os, const vector<T>& v)  {  os << "[";  for (int i = 0; i < v.size(); ++i) {  os << v[i];  if (i != v.size() - 1)  os << ", ";  }  os << "]";  return os;  }
template <typename T> void print(T v, string s = "\n") { cout << v << s; }
template <typename T> void in(T &v) { cin >> v; }
#define ll long long
#define loop(__x, __start, __end) for(int __x = __start; __x < __end; __x++)

int main() {
  vector<int> A(6);
  loop(i,0,6) in(A[i]);
  
  ll max_w = A[0], max_s = 0;
  int n = 101;
  loop(a,0,n) loop(b,0,n) loop(c,0,n) loop(d,0,n) {
    int w = a*A[0] + b*A[1];
    int s = c*A[2] + d*A[3];
    if (w==0 or s == 0) continue;
    if (100*w+s > A[5]) continue;
    if (w*A[4] < s) continue;
    if (max_w+max_s==0) {
      max_w = w; max_s = s; continue;
    }
    if ((w+s)*max_s < (max_w+max_s)*s) {
      max_w = w; max_s = s;
    }
  }
  print(100*max_w+max_s, " ");
  print(max_s);
  return 0;
}


Measured memory_bytes: 3516
#include<algorithm>
#include<iostream>
#include<vector>
using namespace std;
typedef long long lint;
typedef vector<int>vi;
typedef pair<int,int>pii;
#define rep(i,n)for(int i=0;i<(int)(n);++i)

const int A=18;
lint p10[A];


lint dp[A+1][2][6];
int dig[A];

int nxt[6][10];

int main(){
  rep(i,A){
    if(i==0)p10[i]=1;
    else p10[i]=10*p10[i-1];
  }
  lint n;
  cin>>n;
  rep(i,A){
    dig[i]=n%10;
    n/=10;
  }
  dp[A][1][0]=1;
  //states
  nxt[0][5]=1;
  nxt[1][1]=2;
  nxt[1][5]=1;
  rep(i,10)nxt[2][i]=3;
  nxt[2][5]=4;
  nxt[3][3]=5;
  nxt[3][5]=1;
  nxt[4][1]=2;
  nxt[4][3]=5;
  nxt[4][5]=1;
  rep(i,10)nxt[5][i]=5;
  for (int i=A-1;i>=0;--i){
    rep(j,10){
      rep(k,6){
	dp[i][0][nxt[k][j]]+=dp[i+1][0][k];
      }
    }
    rep(j,dig[i]){
      rep(k,6){
	dp[i][0][nxt[k][j]]+=dp[i+1][1][k];
      }
    }
    rep(k,6)
      dp[i][1][nxt[k][dig[i]]]+=dp[i+1][1][k];
  }
  cout<< dp[0][0][5]+dp[0][1][5]<<endl;
}



Measured memory_bytes: 3100
#include <iostream>
#include <string>
#include <set>
#include <vector>
#include <algorithm>
#include <bitset>
#define ll long long
using namespace std;

int main(){
int a,b;cin>>a>>b;
if(b%a==0) cout<<a+b<<endl;
else cout<<b-a<<endl;

  return 0;
}
  


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);i++)
#define ALL(v) (v).begin(),(v).end()
#define int long long
using namespace std;
typedef vector<int>   vint;
typedef pair<int,int> pint;

signed main()
{
    int N; cin>>N;
    vint dp(N+1,N);

    dp[0]=0;
    for(int i=1;i<=N;i++){
        for(int j=1;j<=i;j*=6){
            dp[i]=min(dp[i],dp[i-j]+1);
        }
        for(int j=1;j<=i;j*=9){
            dp[i]=min(dp[i],dp[i-j]+1);
        }
    }
    cout<<dp[N]<<endl;
 
}


Measured memory_bytes: 1024
#from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
from math import gcd
from itertools import combinations,permutations,accumulate, product # (string,3) 3回
#from collections import deque
from collections import deque,defaultdict,Counter
import decimal
import re
import math
import bisect
import heapq
#
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#
# my_round_int = lambda x:np.round((x*2 + 1)//2)
# 四捨五入g
#
# インデックス系
# int min_y = max(0, i - 2), max_y = min(h - 1, i + 2);
# int min_x = max(0, j - 2), max_x = min(w - 1, j + 2);
#
#
import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7
#mod = 9982443453
#mod = 998244353
INF = float('inf')
from sys import stdin
readline = stdin.readline
def readInts():
  return list(map(int,readline().split()))
def readTuples():
    return tuple(map(int,readline().split()))
def I():
    return int(readline())
n = I()
lis = [2**i for i in range(10)]
idx = bisect.bisect_right(lis, n)
print(lis[idx-1])


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

int n, k;
int main() {
  cin >> n >> k;
  
  priority_queue<int> que;
  for (int i = 0; i < n; ++i) {
    int a;
    cin >> a;
    que.push(a);
  }
  
  for (int j = 0; j < k; ++j) {
    int a = que.top(); que.pop();
    que.push(a / 2);
  }
  
  long s = 0;
  while (!que.empty()) {
    int a = que.top(); que.pop();
    s += a;
  }
  cout << s << endl;
}



Measured memory_bytes: 892
// Created by Kshitij Anand NSIT
#include <bits/stdc++.h>
//#include <ext/numeric>
//using namespace __gnu_cxx;


using namespace std;


#define int long long
#define pb push_back
#define P pair<int,int>
#define F first
#define S second
#define vi vector<int>
#define vc vector<char>
#define vb vector<bool>
#define all(x) x.begin(),x.end()
#define sz(x) (int)x.size()
#define mp(a, b) make_pair(a, b)
#define min3(a, b, c) min(min(a, b), c)
#define min4(a, b, c, d) min(min(a, b), min(c, d))
#define max3(a, b, c) max(max(a, b), c)
#define max4(a, b, c, d) max(max(a, b), max(c, d))
#define fill(arr,val) memset(arr,val,sizeof(arr))
#define inf 1e18
#define ps(x,y) fixed<<setprecision(y)<<x
#define db(x)  cout<<#x<<" : "<<x<<endl


const int N = 1000000007;

void solve(){

    int n,a,b,c, ans=0, count=0, sum=0;
    cin>>a>>b>>c;

    float h = (a*1.0)/c;


    
    if(h <=b){
        cout<<"Yes\n";

    }  
    else{
        cout<<"No\n";
    }
}

int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    
    
  //  int t; cin>>t; while(t--)
    {     
      solve();
    }

  return 0;
}


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

using namespace std;

int main() {
  int h, w, m;
  cin >> h >> w >> m;
  set<pair<int, int>> bakudan;
  vector<int> hcount(h), wcount(w);

  for (int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    hcount[a]++;
    wcount[b]++;
    bakudan.emplace(a, b);
  }
  int hmax = 0;
  int wmax = 0;
  for (int i = 0; i < h; i++) hmax = max(hmax, hcount[i]);
  for (int i = 0; i < w; i++) wmax = max(wmax, wcount[i]);

  vector<int> hmaxplace, wmaxplace;
  for (int i = 0; i < h; i++)
    if (hmax == hcount[i]) hmaxplace.emplace_back(i);
  for (int i = 0; i < w; i++)
    if (wmax == wcount[i]) wmaxplace.emplace_back(i);

  int ans = hmax + wmax;

  for (int i : hmaxplace) {
    for (int j : wmaxplace) {
      if (bakudan.count(make_pair(i, j))) continue;
      cout << ans << endl;
      return 0;
    }
  }
  ans--;
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 23736
import java.util.*;

class Main{
    int h,w;
    char[][] grid;
    Boolean B,W;
    int countB,countW;
    int[] dx = {1,-1,0,0};
    int[] dy = {0,0,1,-1};
    char from,to;
    int countGrid;

    void solve(){
	Scanner sc = new Scanner(System.in);
	w = sc.nextInt();
	while(w!=0){
	    h = sc.nextInt();
	    grid = new char[h][w];
	    for(int i=0; i<h; i++){
		String line = sc.next();
		grid[i] = line.toCharArray();
	    }

	    countB = 0;
	    countW = 0;
	    for(int i=0; i<h; i++){
		for(int j=0; j<w; j++){
		    if(grid[i][j]=='.'){
			B = false;
			W = false;
			countGrid = 0;
			dfs(j,i);
			if(B&&!W)countB+=countGrid;
			if(!B&&W)countW+=countGrid;
		    }
		}
	    }

	    System.out.println(countB+" "+countW);

	    w = sc.nextInt();
	}
    }

    void dfs(int x, int y){
	grid[y][x] = 'x';
	countGrid++;
	for(int i=0; i<4; i++){
	    int nx = x+dx[i];
	    int ny = y+dy[i];
	    if(nx<w && nx>=0 && ny<h && ny>=0){
		if(grid[ny][nx]=='B')B = true;
		else if(grid[ny][nx]=='W')W = true;
		else if(grid[ny][nx]=='.'){
		    dfs(nx,ny);
		}
	    }
	}
    }
    
    public static void main(String[] args){
	new Main().solve();
    }
}

Measured memory_bytes: 12000
function main(arg) {
    let n = Number(arg.split("\n")[0])
    let bit = arg.split("\n")[1].split("").map(x=>x=="W"?0:1)
    
    let w=0,r=0
    for(let i=0; i<n; i++) {
        if(bit[i]===0)w++
        else r++
    }
    w=0
    let min=n
    for(let i=0; i<=n; i++) {
        min = Math.min(min,Math.max(w,r))
//        console.log(`w=${w}, r=${r}, min=${min}`)
            if(bit[i]===0) {
                w++
            } else {
                r--
            }
    }
    console.log(min)
    
}


main(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 35528
#include <bits/stdc++.h>
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define pb push_back
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) FOR(i, 0, n)
#define ll long long
using namespace std;

const ll P = 1000000007;
int gcd(int a, int b) { return b != 0 ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a / gcd(a, b) * b; }

int main()
{
  cout << fixed << setprecision(10);
  int N;
  cin >> N;
  if(N%10==3)
  {
    cout << "bon" << endl;
  }
  else if(N%10==0||N%10==1||N%10==6||N%10==8)
  {
    cout << "pon" << endl;
  }
  else
  {
    cout << "hon" << endl;
  }
  return 0;
}


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

int main(void)
{
	int n;
	cin >> n;
	int d[100001] = { 0 };
	for (int i = 0; i < n; i++) cin >> d[i];
	sort(d, d + n);


	int dmax = d[n - 1];
	int ans = 0;

	for (int i = 1; i <= d[n-1]; i++)
	{
		int size = lower_bound(d, d + n, i) - d;
		if (size == n / 2) ans += 1;
	}


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


Measured memory_bytes: 640
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <numeric>
#include <queue>
#include <vector>
#include <cmath>

using namespace std;

typedef long long LL;
typedef pair<int, int> PII;

int main(void){
  int N;
  LL Y;

  cin >> N >> Y;
  int x, y, z;

  for (x = 0; x <= N; x++) {
    for (y = 0; y <= N - x; y++) {
      z = N - x - y;
      if ((x * 10000 + y * 5000 + z * 1000) == Y) {
        cout << x << ' ' << y << ' ' << z << '\n';
        return 0;
      }
    }
  }

  cout << "-1 -1 -1\n";
  return 0;
}

Measured memory_bytes: 256
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
# from fractions import gcd
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from functools import reduce
from bisect import bisect_left, insort_left
from heapq import heapify, heappush, heappop

INPUT = lambda: sys.stdin.readline().rstrip()
INT = lambda: int(INPUT())
MAP = lambda: map(int, INPUT().split())
S_MAP = lambda: map(str, INPUT().split())
LIST = lambda: list(map(int, INPUT().split()))
S_LIST = lambda: list(map(str, INPUT().split()))

sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7


def main():
    X = INT()

    for i in range(1000):
        for j in range(1000):
            if i**5 - j**5 == X:
                print(i, j)
                sys.exit()
            elif i**5 + j**5 == X:
                print(i, j*(-1))
                sys.exit()


if __name__ == '__main__':
    main()

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

int main(){
	string s; cin >> s;
	int K; cin >> K;
	vector<string> S;
	for(int i=0; i<s.size(); i++){
		string c;
		for(int j=0; j<5 && i + j < s.size(); j++){
			if(j == 0) c = s[i];
			else c += s[i+j];
			S.push_back(c);
		}
	}
	sort(S.begin(), S.end());
	int cnt = 0;
	map<string, int> M;
	for(int i=0; i<S.size(); i++){
		M[S[i]]++;
		if(M[S[i]] == 1) cnt++;
		if(cnt == K){
			cout << S[i] << endl;
			return 0;
		}
	}
	return 0;
}

Measured memory_bytes: 1660
/*---------------------------------

 @Author:   Dicer
 @DateTime: 2019-06-17 09:17:14

---------------------------------*/

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
inline ll qpow(ll a,ll b,ll mod){ll res=1;while(b){if(b&1)res = (res*a)%mod;a=(a*a)%mod;b>>=1;}return res;}
const double eps = 1e-8;
const int INF = 0x3f3f3f3f;
const int mod = 1e9+7;
const int MAXN = 2e5 + 7;

int main(int argc, char const *argv[])
{	
	ll w, h, x, y;
	cin >> w >> h >> x >> y;
	if(w == 2*x && h == 2*y){
		cout << w*h/2.0 << ' ' << 1 << endl;
	} else {
		cout << w*h/2.0 << ' ' << 0 << endl;
	}
	return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;

namespace AtCorder
{
    class MainClass
    {
        public static void Main(string[] args)
        {
            var n = int.Parse(Console.ReadLine());
            var points = new List<int[]>();
            for (int i = 0; i < n; i++)
            {
                var rowInput = Console.ReadLine();
                var rowInputArray = rowInput.Split(' ');
                var x = int.Parse(rowInputArray[0]);
                var y = int.Parse(rowInputArray[1]);
                points.Add(new int[] {x,y});
            }

            double sum = 0;

            for (int i = 0; i < points.Count; i++)
            {
                for (int j = 0; j < points.Count; j++)
                {
                    if (i != j)
                        sum += Math.Sqrt(
                            Math.Pow(points[i][0] - points[j][0], 2) +
                            Math.Pow(points[i][1] - points[j][1], 2)); 
                }
            }
            double result = sum / n;
            Console.WriteLine(result);
        }
    }
}


Measured memory_bytes: 11220
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(v) v.begin(), v.end()
using namespace std;
typedef long long ll;

int main() {
	
	int h, w;
	cin >> h >> w;
	vector<string> s(h+2);
	rep(i, w+2){
		s[0] += ".";
		s[h+1] += ".";
	}
	rep(i, h){
		string tmp;
		cin >> tmp;
		s[i+1] = "." + tmp + ".";
	}
	for(int i = 1; i <= h; i++){
		for(int j = 1; j <= w; j++){
			int bomb = 0;
			for(int u = -1; u <= 1; u++){
				for(int t = -1; t <= 1; t++){
					if(u==0 && t==0) continue;
					if(s[i+u][j+t] == '#') bomb++;
				}
			}
			if(s[i][j] == '#') cout << "#";
			else cout << bomb;
		}
		cout << endl;
	}
	
	return 0;
}

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

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

  int r, g, b;
  cin >> r >> g >> b;

  int d = r * 100 + g * 10 + b;
  if (d % 4) cout << "NO\n";
  else cout << "YES\n";

  return (0);
}


Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = 1e13;

int main() {
	int N, M, R;
	cin >> N >> M >> R;
	vector<int> r(R);
	for(int i=0;i<R;i++) {
		cin >> r[i];
		r[i]--;
	}
	vector<vector<ll>> dist(N, vector<ll>(N, INF));
	for(int i=0;i<M;i++) {
		int a, b;
		ll c;
		cin >> a >> b >> c;
		a--, b--;
		dist[a][b] = c;
		dist[b][a] = c;
	}
	for(int i=0;i<N;i++) {
		for(int j=0;j<N;j++) {
			for(int k=0;k<N;k++) {
				dist[j][k] = min(dist[j][k], dist[j][i] + dist[i][k]);
			}
		}
	}
	sort(r.begin(), r.end());
	ll ans = LLONG_MAX;
	do {
		ll tmp_ans = 0;
		int now = r[0];
		for(int i=1;i<R;i++) {
			int next = r[i];
			tmp_ans += dist[now][next];
			now = next;
		}
		ans = min(ans, tmp_ans);
	} while(next_permutation(r.begin(), r.end()));
	
	cout << ans << endl;
}

Measured memory_bytes: 512
a={}
n=io.read()
temp=0
now_max= 0  --最高ジャンプ回数
count=0 --カウント
for i=1, n,1 do
  temp=io.read("*n")
  a[i]=temp
end    

now=a[1] --現在の高さ

for k=2,#a,1 do
  if now >= a[k] then
    now=a[k]
    count=count + 1
  else
    now=a[k]
    count=0
  end
  
  if now_max < count then
    now_max=count
  end
end

if n== 1 then
print(0)
else
print(now_max)
end


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



int main(){
  int N,M;
  cin>>N>>M;
  
  int sum=0;
  for(int i=0;i<M;i++){
    int S;
    cin>>S;
    sum+=S;
  }
  if(N-sum>=0) cout<<N-sum<<endl;
  else cout<<-1<<endl;
}
    
    

Measured memory_bytes: 3592
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define R cin>>
#define Z class
#define ll long long
#define ln cout<<'\n'
#define in(a) insert(a)
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define all(c) (c).begin(),(c).end()
#define iter(c) __typeof((c).begin())
#define rrep(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
template<Z A>void pr(A a){cout<<a;ln;}
template<Z A,Z B>void pr(A a,B b){cout<<a<<' ';pr(b);}
template<Z A,Z B,Z C>void pr(A a,B b,C c){cout<<a<<' ';pr(b,c);}
template<Z A,Z B,Z C,Z D>void pr(A a,B b,C c,D d){cout<<a<<' ';pr(b,c,d);}
template<Z A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}ln;}
ll check(ll n,ll m,ll x,ll y){return x>=0&&x<n&&y>=0&&y<m;}
const ll MAX=1e9+7,MAXL=1LL<<61,dx[4]={-1,0,1,0},dy[4]={0,1,0,-1};
typedef pair<int,int> P;

void Main() {
  int n;
  R n;
  int ans=0;
  REP(x,1,n+1) {
    int cnt=0;
    for(int i=1; i<=n; i+=2) {
      if(x%i==0) cnt++;
    }
    if(cnt==8) ans++;
  }
  pr(ans);
}

int main(){ios::sync_with_stdio(0);cin.tie(0);Main();return 0;}


Measured memory_bytes: 256
def d166(x):

    a = 0
    b = 0

    if x == 0:
        return "1" + " " + "1"
    if x < 0:
        for i in range(10000):
            ax = x + i**5
            if ax > 0:
                a = -i
                for w in range(i):
                    if ax-(w**5) == 0:
                        b = -w
                        return str(a) + " " + str(b)
            else:
                a = -i
                for w in range(i):
                    if ax+(w**5) == 0:
                        b = w
                        return str(a) + " " + str(b)

    else:
        for i in range(10000):
            ax = x - i**5
            if ax < 0:
                a = i
                for w in range(i):
                    if ax+(w**5) == 0:
                        b = w
                        return str(a) + " " + str(b)
            else:
                a = i
                for w in range(i):
                    if ax-(w**5) == 0:
                        b = -w
                        return str(a) + " " + str(b)

def main():
    x = int(input())
    print(d166(x))
if __name__ == '__main__':
    main()

Measured memory_bytes: 63940
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
inline int read()
{
	int x = 0, f = 1; char c = getchar();
	while (!isdigit(c)) {if (c == '-') f = -1; c = getchar();}
	while (isdigit(c)) {x = x * 10 + c - '0', c = getchar();}
	return x * f;
}

const int MAXN = 1005;
const int MAXM = 2e5 + 10;

typedef pair<int, int> mypair;

vector<int> linker[MAXN];
int n, m, vis[MAXN], from[MAXM], to[MAXM];
bool g1[MAXN][MAXN], g2[MAXN][MAXN];
mypair pre[MAXN];

void dfs1(int x)
{
	vis[x] = 1;
	for (int i = 0; i < linker[x].size(); i ++)
	{
		int cur = linker[x][i];
		if (vis[cur]) continue;
		pre[cur] = mypair(x, i), dfs1(cur);
	}
}

void dfs2(int x)
{
	vis[x] = 1;
	for (int i = linker[x].size() - 1; i >= 0; i --)
	{
		int cur = linker[x][i];
		if (vis[cur]) continue;
		pre[cur] = mypair(x, i), dfs2(cur);
	}
}

int main()
{
	n = read(), m = read();
	for (int i = 1; i <= m; i ++)
	{
		from[i] = read(), to[i] = read();
		linker[from[i]].push_back(to[i]);
	}
	for (int s = 1; s <= n; s ++)
	{
		memset(vis, 0, sizeof vis);
		static mypair tmp[MAXN];
		dfs1(s);
		memcpy(tmp, pre, sizeof pre);
		memset(vis, 0, sizeof vis);
		dfs2(s);
		for (int i = 1; i <= n; i ++)
		{
			if (vis[i])
			{
				g1[s][i] = 1;
				if (pre[i].first != s || tmp[i].first != s)
					g2[s][i] = 1;
			}
		}
	}
	for (int i = 1; i <= m; i ++)
	{
		int u = from[i], v = to[i];
		if (g1[v][u] ^ g2[u][v]) puts("diff");
		else puts("same");
	}
	return 0;
}

Measured memory_bytes: 6400
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <utility>
#include <functional>
#include <climits>
#include <cstring>

using namespace std;

#define int long long
#define rep(i, n) for (int i=0;i<(int)n;++i)
#define rep1(i, n) for (int i=1;i<=(int)n;++i)
#define unless(a) if(!(a))
#define all(a) begin(a),end(a)
#define fst first
#define scd second
#define PB emplace_back
#define PPB pop_back

using vi=vector<int>;
using pii=pair<int, int>;

bool chmin(int&a,int b){return a>b?(a=b,true):false;}
bool chmax(int&a,int b){return a<b?(a=b,true):false;}
int read(){int a;scanf("%lld",&a);return a;}

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

signed main()
{
	cin>>N>>X;
	vector<int> x(N);
	rep(i,N)cin>>x[i];
	int ans = 0;
	rep(i, N) {
		ans = gcd(ans, abs(x[i] - X));
	}
	cout<<ans<<endl;
}



Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define rep1(i,n) for(int i=1;i<=(int)n;i++)
#define rep2(i,j,n) for(int j=i;j<n;j++)
#define rep3(i,j,n) for(int j=i;j<=n;j++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define sp(n) cout << fixed << setprecision(n)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
typedef long long ll;
using namespace std;
int main(void){
    ll n;cin>>n;
    map<ll,ll> mp;
    ll res=0;
    rep1(i,n){
        ll a;cin>>a;
        res+=mp[i-a];
        mp[i+a]++;
    }
    cout<<res<<endl;
}

Measured memory_bytes: 26300
import java.util.*;
import java.io.BufferedReader; 
import java.io.IOException; 
import java.io.InputStreamReader; 
import java.util.StringTokenizer;

public class Main {
	static class IO 
    { 
        BufferedReader br; 
        StringTokenizer st; 
  
        public IO() 
        { 
            br = new BufferedReader(new
                     InputStreamReader(System.in)); 
        } 
  
        String next() 
        { 
            while (st == null || !st.hasMoreElements()) 
            { 
                try
                { 
                    st = new StringTokenizer(br.readLine()); 
                } 
                catch (IOException  e) 
                { 
                    e.printStackTrace(); 
                } 
            } 
            return st.nextToken(); 
        } 
  
        int nextInt() 
        { 
            return Integer.parseInt(next()); 
        } 
  
        long nextLong() 
        { 
            return Long.parseLong(next()); 
        } 
  
        double nextDouble() 
        { 
            return Double.parseDouble(next()); 
        } 
  
        String nextLine() 
        { 
            String str = ""; 
            try
            { 
                str = br.readLine(); 
            } 
            catch (IOException e) 
            { 
                e.printStackTrace(); 
            } 
            return str; 
        } 
        int [] readarray(int sz){
            int [] ret = new int[sz];
            for(int i = 0; i<sz; i++)ret[i] = nextInt();
            return ret;
        }
    } 
    public static void main(String[] args){
        IO fs = new IO();
        long n = fs.nextLong(),k = fs.nextLong();
        Set<Long> st = new HashSet<Long>();
        for(long i = 0; i<k; i++){
            st.add(fs.nextLong());
        }
        long ans = 0;
        for(long i = n; i<=10000000; i++){
            long tocheck = i;
            boolean ok = true;
            while(tocheck!=0){
                if(st.contains(tocheck%10)){
                    ok = false;
                    break;
                }
                tocheck/=10;
            }
            if(ok){
                ans = i;
                break;
            }
        }
        System.out.println(ans);
    }
    public static long power(long x,long y){
        long res = 1;
        while(y>0){
            if(y%2 == 1)res = (res*x);
            y>>=1;
            x = x*x;
        }
        return res;
    }
}


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

void print_vec(vector<int> vec) {
  cout << "[";
  for (int i = 0; i < vec.size(); i++) {
    if (i) {
      cout << ", ";
    }
    cout << vec.at(i);
  }
  cout << "]...size: " << vec.size() << endl;
}

int main() {
  string str;
  cin >> str;

  int q;
  cin >> q;

  vector<string> v;

  rep(i, q) {
    string command;
    int a, b;
    cin >> command >> a >> b;

    if (command == "print") {
      v.push_back(str.substr(a, b - a + 1));
    } else if (command == "reverse") {
      string sub = str.substr(a, b - a + 1);
      reverse(all(sub));
      str.replace(a, b - a + 1, sub);
    } else {
      string rep;
      cin >> rep;
      str.replace(a, b - a + 1, rep);
    }
  }

  for (auto &&i : v) {
    printf("%s\n", i.c_str());
  }
}



Measured memory_bytes: 3184
using System;
using System.Linq;

class Program
{
    static void Main(string[] args)
    {
        var l1 = ReadIntArray();
        var hp = l1[0];
        var sp_types = l1[1]; 
        var sp_damage_list = ReadIntArray();

        var damage_total = sp_damage_list.Sum();
        Console.WriteLine(hp > damage_total ? "No" : "Yes");
    }

    static string[] ReadStringArray()
    {
        return Console.ReadLine().Split(' ');
    }

    static int[] ReadIntArray()
    {
        return ReadStringArray().Select(_ => int.Parse(_)).ToArray();
    }
}
 

Measured memory_bytes: 19680
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int N=5e3+2;
const int inf=1e15+2;
int dp[N][N][2],ar[N],sz[N],ndp[N][2];
vector<int> adj[N];
void dfs(int x,int p){
	if(ar[x]>0){
		dp[x][0][0]=ar[x];
	}	
	else{
		dp[x][0][1]=ar[x];
	}
	sz[x]=1;
	for(int i:adj[x]){
		if(i!=p){
			dfs(i,x);
			for(int j=0;j<sz[x]+sz[i];j++){
				ndp[j][0]=ndp[j][1]=inf;
			}
			for(int j=0;j<sz[x];j++){
				for(int k=0;k<sz[i];k++){
					ndp[j+k][0]=min(ndp[j+k][0],dp[x][j][0]+dp[i][k][0]);
					ndp[j+k][1]=min(ndp[j+k][1],min(dp[x][j][1],dp[x][j][0])+min(dp[i][k][1],dp[i][k][0]));
					if(dp[i][k][1]<0||dp[i][k][0]<inf){
						ndp[j+k+1][0]=min(ndp[j+k+1][0],dp[x][j][0]);
						ndp[j+k+1][1]=min(ndp[j+k+1][1],dp[x][j][1]);
					}
				}
			}
			for(int j=0;j<sz[x]+sz[i];j++){
				dp[x][j][0]=ndp[j][0];
				dp[x][j][1]=ndp[j][1];
			}
			sz[x]+=sz[i];
		}
	}
}
signed main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	int n,i,j,k,l;
	cin>>n;
	for(i=1;i<=n;i++){
		cin>>ar[i];
		for(j=0;j<=n;j++){
			dp[i][j][0]=dp[i][j][1]=inf;
		}
	}
	for(i=1;i<n;i++){
		cin>>j>>k;
		adj[j].push_back(k);
		adj[k].push_back(j);
	}
	dfs(1,1);
	for(i=0;i<=n;i++){
		if(dp[1][i][0]<inf||dp[1][i][1]<0){
			cout<<i;
			return 0;
		}
	}
}

Measured memory_bytes: 392192
#include<iostream>
using namespace std;
int main(){
    long long int  n,m;
    cin>>n>>m;
    if(n>m)
    {
        long long int temp=n;
        n=m;
        m=temp;
    }
    if(n==1&&m==1){
        cout<<"1";
        return 0;
    }
    if(n==1)
    {
        cout<<(m-2);    
    }
    else
    cout<<(n-2)*(m-2);
}

Measured memory_bytes: 3620
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <set>
#include <vector>
#include <stack>
#include <queue>
#include <bitset>
#include <algorithm>
#include <numeric>
#include <functional>
using namespace std;

#define Rep(b, e, i) for(int i = b; i <= e; i++)
#define Repr(e, b, i) for(int i = e; i >= b; i--)
#define rep(n, i) Rep(0, n-1, i)
#define repr(n, i) Repr(n-1, 0, i)
#define all(v) (v).begin(), (v).end()
#define pb(x) push_back(x)
#define uniq(x) (x).erase(unique(all(x)),(x).end())

typedef long long ll;
typedef pair<ll, ll> llP;
typedef pair<int, int> intP;
typedef std::priority_queue<int> IntPrioQueue; //Z->A
typedef std::priority_queue<int, std::vector<int>, std::greater<int> > IntReversePrioQueue; //A->Z

const int MAX = 200000;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const int INF = 1<<31-1;
const int MOD = 1000000007;

int ns[3];

void solve(void){
    int K;
    cin >> ns[0] >> ns[1] >> ns[2] >> K;
    sort(ns, ns+3);
    rep(K, i) ns[2] *= 2;
    int ans = ns[2] + ns[0] + ns[1];
    cout << ans << '\n';
}

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


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

struct Pair {
  std::size_t a;
  std::size_t b;
};

int main() {
  std::size_t n, m;
  std::cin >> n >> m;
  
  std::vector<Pair> pairs(n);
  for (auto&& p : pairs) std::cin >> p.a >> p.b;
  std::sort(pairs.begin(), pairs.end(), [](const auto& p1, const auto& p2) {
    return p1.a < p2.a;
  });
  
  std::size_t cost = 0;
  std::size_t num = 0;
  for (auto&& p : pairs) {
    if (num + p.b < m) {
	  cost += p.a*p.b;
	  num += p.b;
	} else {
	  cost += (m - num)*p.a;
	  num = m;
	  break;
	}
  }
  std::cout << cost << std::endl; 
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define fbo find_by_order
#define ook order_of_key

typedef long long ll;
typedef pair<ll,ll> ii;
typedef vector<ll> vi;
typedef long double ld; 
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
typedef set<int>::iterator sit;
typedef map<int,int>::iterator mit;
typedef vector<int>::iterator vit;

ii a[200001];

bool cmp(const ii &a, const ii &b)
{
	if(max(a.fi,a.se)!=max(b.fi,b.se)) return max(a.fi,a.se)<max(b.fi,b.se);
	return a.fi<b.fi;
}

bool cmp2(const ii &a, const ii &b)
{
	if(min(a.fi,a.se)!=min(b.fi,b.se)) return min(a.fi,a.se)<min(b.fi,b.se);
	return a.fi<b.fi;
}
int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0);
	int n; cin>>n;
	vector<ll> x;
	for(int i=0;i<n;i++)
	{
		cin>>a[i].fi>>a[i].se;
		if(a[i].fi<a[i].se) swap(a[i].fi,a[i].se);
		x.pb(a[i].fi); x.pb(a[i].se);
	}
	sort(x.begin(),x.end());
	x.erase(unique(x.begin(),x.end()),x.end());
	ll ans = ll(2e18);
	deque<ii> vec(n);
	ll tmp = 0;
	for(int i=0;i<n;i++)
	{
		vec[i]=a[i];
		tmp=max(tmp,min(vec[i].fi,vec[i].se));
	}
	sort(vec.begin(),vec.end(),cmp);
	for(int i = 1; i < x.size(); i++)
	{
		ll bmin = x[0]; ll rrange = x.back() - x[i];
		if(max(vec.front().fi,vec.front().se)<x[i])
		{
			break;
		}
		ans=min(ans,rrange*(tmp-bmin));
	}
	ll mm = max(vec.front().fi,vec.front().se);
	ll rrange = x.back()-x[0];
	sort(vec.begin(),vec.end(),cmp2);
	for(int i=0;i<x.size();i++)
	{
		if(x[i]>mm) break;
		ll bmin=x[i];
		while(!vec.empty()&&min(vec.front().fi,vec.front().se)<x[i])
		{
			tmp=max(tmp,max(vec.front().fi,vec.front().se));
			vec.pop_front();
		}
		ans=min(ans,(tmp-bmin)*rrange);
	}
	cout<<ans<<'\n';
}


Measured memory_bytes: 10604
using System;

class Program
{
    static void Main()
    {
        var s = Console.ReadLine();
        var t = Console.ReadLine();
        var ans = 0;
        for (int i = 0; i < s.Length; i++)
        {
            if (s[i] == t[i])
            {
                ans++;
            }
        }
        Console.WriteLine(ans);
    }
}

Measured memory_bytes: 11092
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int n,k,d,a;
  cin>>n>>k;
  int ans=0,maxi=0;
  set<int> myset;
  while(k--)
  {
  
    cin>>d;
    while(d--)
    {
    	cin>>a;
    	myset.insert(a);
    }
    
  }
  int m=myset.size();
  cout<<n-m<<endl;
  return 0;
    
}

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

const int N = 100000 + 5;
int n, m;
char st1[N], st2[N];

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

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

map<ll, char> mp;

int main() {
	scanf("%d%d%s%s", &n, &m, st1, st2);
	ll res = lcm(n, m);

	ll x = res / n;
	ll y = res / m;

	for(int i=0; i<n; ++i) {
		mp[i*x + 1] = st1[i];
	}

	for(int i=0; i<m; ++i) {
		char &qwe = mp[i*y+1];
		if(qwe != 0 && qwe != st2[i]) {
			puts("-1");
			return 0;
		}
	}
	printf("%lld\n", res);

	return 0;
}


Measured memory_bytes: 10880
#include <iostream>

using namespace std;

const int maxn = 1e5 + 5;
int n, a[maxn], b[maxn], c[maxn], ans;

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

int main()
{
   ios::sync_with_stdio(false);
   cin.tie(0);
   cin >> n;
   for(int i = 0; i < n; i++) {
       cin >> a[i];
   }
   c[0] = a[0]; b[n - 1] = a[n - 1];
   for(int i = n - 2; i >= 0; i--) {
       b[i] = gcd(a[i], b[i + 1]);
   }
   for(int i = 1; i < n; i++) {
       c[i] = gcd(c[i - 1], a[i]);
   }
   for(int i = 1; i < n - 1; i++) {
       ans = max(ans, gcd(c[i - 1], b[i + 1]));
   }
   if(n >= 2) {
       ans = max(ans, max(b[1], c[n - 2]));
   }
   cout << ans << '\n';
   return 0;
}

Measured memory_bytes: 1408
#include <stdio.h>
#include <algorithm>

using namespace std;

char s[300002];
int l, ps[300002];

int main() {
	scanf("%d %s",&l,&s[1]);
	for(int i=1;i<=l;i++) {
		ps[i]=ps[i-1];
		if(s[i]=='E') ps[i]++;
	}
	int res=(1<<30);
	for(int i=1;i<=l;i++) {
		int ll=0, rr=0;
		if(i>1) {
			ll=i-1-ps[i-1];
		}
		if(i<l) {
			rr=ps[l]-ps[i];
		}
		res=min(res,ll+rr);
	}
	printf("%d\n",res);
	return 0;
}

Measured memory_bytes: 1664
# -*- coding: utf-8 -*-
import sys
sys.setrecursionlimit(10**9)
INF=10**18
MOD=10**9+7
input=lambda: sys.stdin.readline().rstrip()
YesNo=lambda b: bool([print('Yes')] if b else print('No'))
YESNO=lambda b: bool([print('YES')] if b else print('NO'))
int1=lambda x:int(x)-1

def main():
    N=int(input())
    a=list(map(int,input().split()))
    t=0
    f=0
    for i in range(N):
        if a[i]%4==0:
            f+=1
        elif a[i]%2==0:
            t+=1
    YesNo(N//2<=f+t//2)

if __name__ == '__main__':
    main()


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

int main(){
    int n,redkosuu=0,ans=0;
    cin >> n;
    vector<char> A(n);
    for(int i=0;i<n;i++){
        char c;
        cin >> c;
        A.at(i)=c;
        if(c=='R')redkosuu++;
    }
    for(int i=0;i<redkosuu;i++){
        if(A.at(i)!='R')ans++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3536
#include <bits/stdc++.h>
#define pub push_back
#define pob pop_back
#define mp make_pair

using namespace std;
typedef pair<int, int> pii;
typedef long long int ll;

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie();
	
	map<char, ll> m;
	string s;
	cin >> s;
	for (ll i = 0; i < s.length(); i++) {
		m[s[i]]++;
	}
	for (char chr = 'a'; chr <= 'z'; chr++) {
		if (m[chr] % 2) {
			cout << "No";
			return 0;
		}
	}
	cout << "Yes";
	
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,a,n) for(int i=a;i<(a+n);i++)
#define var auto
using namespace std;
using ll = long long;

int main() {
  ios::sync_with_stdio(false);
  string s;
  cin >> s;
  int q;
  cin >> q;
  cin.ignore();

  int ans = 0;

  bool isrev = false;
  // vector<string> a1;
  // vector<string> a2;
  string a1 = "";
  string a2 = "";
  rep(i, 0, q) {
    string s1;    
    getline(cin, s1);

    if (s1[0] == '1') {
      isrev = !isrev;
      // reverse(s.begin(), s.end());
    } else {
      if (s1[2] == '1') {
        if (isrev) a2 = a2 + s1[4];
        else a1 = a1 + s1[4];
        // s = s1[4] + s;
      } else {
        if (isrev) a1 = a1 + s1[4];
        else a2 = a2 + s1[4];
        // s = s + s1[4];
      }
    }
  }


  if (isrev) {
    reverse(s.begin(), s.end());
    reverse(a2.begin(), a2.end());
    s = a2 + s + a1;
  } else {
    reverse(a1.begin(), a1.end());
    s = a1 + s + a2;
  }
  cout << s << endl;
  return 0;
}


Measured memory_bytes: 1700
#include <algorithm>  
#include <iostream>  
#include <sstream>  
#include <string>  
#include <cstring>
#include <vector>  
#include <queue>  
#include <set>  
#include <map>  
#include <cstdio>  
#include <cstdlib>  
#include <cctype>  
#include <cmath>  
#include <list>  
#include <cassert>
#include <ctime>
#include <climits>
using namespace std;  

#define PB push_back  
#define MP make_pair  
#define SZ(v) ((int)(v).size())  
#define FOR(i,a,b) for(int i=(a);i<(b);++i)  
#define REP(i,n) FOR(i,0,n)  
#define FORE(i,a,b) for(int i=(a);i<=(b);++i)  
#define REPE(i,n) FORE(i,0,n)  
#define FORSZ(i,a,v) FOR(i,a,SZ(v))  
#define REPSZ(i,v) REP(i,SZ(v))  
typedef long long ll;
typedef unsigned long long ull;
ll gcd(ll a,ll b) { return b==0?a:gcd(b,a%b); }

const int MAXN=200000;

int n,m;
bool tos[MAXN],tot[MAXN];

void run() {
	scanf("%d%d",&n,&m); REP(i,n) tos[i]=tot[i]=false;
	REP(i,m) { int a,b; scanf("%d%d",&a,&b); --a,--b; if(a>b) swap(a,b); if(a==0) tos[b]=true; if(b==n-1) tot[a]=true; }
	bool ret=false; FOR(i,1,n-1) if(tos[i]&&tot[i]) ret=true;
	printf("%s\n",ret?"POSSIBLE":"IMPOSSIBLE");
}

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


Measured memory_bytes: 640
//
// Created by Mahmoud Rashad on 11/27/19.
//

#include <bits/stdc++.h>


using namespace std;

typedef vector<int> vi;
typedef pair<int, int> ii;
typedef vector<pair<ii, ii>> vii;

int main() {
#ifndef ONLINE_JUDGE
//    freopen("input.txt", "r", stdin);
//    freopen("output.out", "w", stdout);
#endif
    ios::sync_with_stdio(false), cin.tie(0), cout.tie(0), cout.precision(10), cout << fixed;

    int n;
    cin >> n;
    string s;
    cin >> s;
    vector<int> left(n), right(n);
    left[0] = s[0] == 'W';
    for (int i = 1; i < n; ++i) {
        left[i] = left[i - 1] + (s[i] == 'W');
    }
    right[n - 1] = s[n - 1] == 'E';
    for (int i = n - 2; i >= 0; --i) {
        right[i] = right[i + 1] + (s[i] == 'E');
    }

    int ans = INT_MAX;
    for (int i = 0; i < n; ++i) {
        if (i == 0) {
            ans = min(ans, right[i + 1]);
        } else if (i == n - 1) {
            ans = min(ans, left[i - 1]);
        } else {
            ans = min(ans, left[i - 1] + right[i + 1]);
        }
//        cout << ans << endl;
    }

    cout << ans << '\n';

    return 0;
}

Measured memory_bytes: 2964
N = int(input())
A = [int(x) for x in input().split()]
A.sort()
a_half = A[-1] // 2
def binsearch(upper, lower):
  if upper - lower == 1:
    if A[upper] == A[-1] or abs(A[upper] - a_half) > abs(a_half - A[lower]):
      return lower
    else:
      return upper
  med = (upper + lower) // 2
  if A[med] == a_half:
    return med
  elif A[med] > a_half:
    return binsearch(med, lower)
  else:
    return binsearch(upper, med)
print(A[-1], A[binsearch(N - 1, 0)])

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

int main(){
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  string s;
  if((a + b) > (c + d)){
   	 s = "Left";
  }else if ((a + b) < (c + d)){
     s = "Right"; 
  }else{
   	 s = "Balanced";
  }
  cout << s << endl;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
  int a,b;
  cin >> a >> b;
  
  int c = b-a;
  
  int left_tower = 0;
  
  for(int i=0;i<c;i++){
    left_tower += i;
  }
  
  cout << left_tower - a << endl;
  
  return 0;
}

    

Measured memory_bytes: 256