akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

#define lli long long int
#define REP(i,s,n) for(int i=s;i<n;i++)
#define NUM 2520
#define INF (1LL<<50)
#define DEBUG 0
#define mp(a,b) make_pair(a,b)
#define SORT(V) sort(V.begin(),V.end())
#define PI (3.141592653589794)
#define TO_STRING(VariableName) # VariableName
#define LOG(x) if(DEBUG)cout<<TO_STRING(x)<<"="<<x<<" "<<endl;
#define LOG2(x,y) if(DEBUG)cout<<TO_STRING(x)<<"="<<x<<" "<<TO_STRING(y)<<"="<<y<<endl;
#define LOG3(x,y,z) if(DEBUG)cout<<TO_STRING(x)<<"="<<x<<" "<<TO_STRING(y)<<"="<<y<<" "<<TO_STRING(z)<<"="<<z<<endl;
#define LOG4(w,x,y,z) if(DEBUG)cout<<TO_STRING(w)<<"="<<w<<" "<<TO_STRING(x)<<"="<<x<<" "<<TO_STRING(y)<<"="<<y<<" "<<TO_STRING(z)<<"="<<z<<endl;

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


void func(long long N, long long K, std::vector<long long> a, std::vector<long long> b){

    map<lli,lli> cnt;
    REP(i,0,N){
        cnt[a[i]] += b[i];
    }

    lli sum=0;
    for(auto e:cnt){
        sum += e.second;
        if(sum >= K){
            cout<<e.first<<endl;
            return;
        }
    }
}

int main(){
    // cout << fixed << setprecision(5);

    long long N;
    scanf("%lld",&N);
    long long K;
    scanf("%lld",&K);
    std::vector<long long> a(N);
    std::vector<long long> b(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&a[i]);
        scanf("%lld",&b[i]);
    }
    func(N, K, std::move(a), std::move(b));
    return 0;
}


Measured memory_bytes: 5760
import java.util.*;

class Main{
 public static void main(String[] args){
   Scanner sc = new Scanner(System.in);
   double W = sc.nextInt();
   double H = sc.nextInt();
   double x = sc.nextInt();
   double y = sc.nextInt();
   
   
   System.out.print(W*H/2);
   if((W/2 == x)&&(H/2 == y)){
   System.out.println(" 1");
   }else{
    System.out.println(" 0"); 
   }
 }
}


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

using namespace std;

long long n,x,y,i,j,base,mid,top,ans;
long long a[1000];

int main() {
	scanf("%lld",&n);
	for (i=0 ; i<n ; i++) scanf("%lld",&a[i]);
	
	base = 0;
	top = 1000000000000000000LL;
	
	while (base != top) {
		mid = (base + top) / 2;
		long long maksimal = n - mid - 1;
		long long pengali = n + 1;
		
		ans = 0;
		for (i=0 ; i<n ; i++) {
			long long jarak = a[i] - maksimal;
			ans += max(0LL,(jarak + pengali - 1) / pengali);
		}
		
		//printf("%lld %lld -- %lld : %lld\n",base,top,mid,ans);
		
		if (ans <= mid) top = mid; else base = mid + 1;
	}
	//printf("%lld\n",top);
	
	for (i=top ; i >= max(0LL,top-10000) ; i--) {
		mid = i;
		long long maksimal = n - mid - 1;
		long long pengali = n + 1;
		
		ans = 0;
		for (j=0 ; j<n ; j++) {
			long long jarak = a[j] - maksimal;
			ans += max(0LL,(jarak + pengali - 1) / pengali);
		}
		if (ans <= mid) top = mid;
		
		//printf("%lld %lld -- %lld : %lld\n",base,top,mid,ans);
	}
	printf("%lld\n",top);
}

Measured memory_bytes: 256
#![allow(unused_imports)]
use itertools::Itertools;
use num_traits::clamp;
use ordered_float::OrderedFloat;
use proconio::{fastout, input, marker::*};
use std::cmp::*;
use std::collections::*;
use superslice::*;

#[fastout()]
fn main() {
    input! {
        n: usize, k: usize,
        mut a: [i64; n],
    }
    let m = 1000000007i64;
    let mod_product = |acc: i64, &value: &i64| {
        (acc * value).rem_euclid(m)
    };

    if k == n || k % 2 == 1 && a.iter().all(|v| *v <= 0) {
        a.sort_by_key(|v| -*v);
        let ans = a.iter().take(k).fold(1, mod_product);
        println!("{}", ans);
        return;
    }

    a.sort_by_key(|v| Reverse(v.abs()));
    let mut plus = Vec::new();
    let mut minus = Vec::new();
    for i in 0..n {
        if a[i] >= 0 {
            plus.push(a[i]);
        } else {
            minus.push(a[i]);
        }
    }

    let mut ppos = 0;
    let mut mpos = 0;
    let mut vals = Vec::new();
    let mut retry = false;
    while vals.len() < k {
        if vals.len() < k - 1 && ppos + 1< plus.len() && mpos + 1 < minus.len() {
            if plus[ppos] * plus[ppos+1] < minus[mpos] * minus[mpos+1] {
                vals.push(minus[mpos]);
                vals.push(minus[mpos+1]);
                mpos += 2;
            } else {
                vals.push(plus[ppos]);
                vals.push(plus[ppos+1]);
                ppos += 2;
            }
        } else if vals.len() < k - 1 && mpos + 1 < minus.len() {
            vals.push(minus[mpos]);
            vals.push(minus[mpos+1]);
            mpos += 2;
        } else if ppos < plus.len() {
            vals.push(plus[ppos]);
            ppos += 1;
        } else {
            retry = true;
            break;
        }
    }
    let ans = if !retry {
        vals.iter().fold(1, mod_product)
    } else {
        a.sort_by_key(|v| v.abs());
        assert!(k % 2 == 1);
        assert!(a[k-1] == a[k]);
        a.iter().take(k).fold(1, mod_product)
    };
    println!("{}", ans);
}


Measured memory_bytes: 9812
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#define REP(i, n) for (int i = 0; i < (n); i++)

using namespace std;

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  string S;
  cin >> S;
  bool f = "01" <= S.substr(0, 2) && S.substr(0, 2) <= "12";
  bool g = "01" <= S.substr(2, 2) && S.substr(2, 2) <= "12";
  if (f && g) {
    cout << "AMBIGUOUS" << '\n';
  } else if (f) {
    cout << "MMYY" << '\n';
  } else if (g) {
    cout << "YYMM" << '\n';
  } else {
    cout << "NA" << '\n';
  }
}


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

#define rep(i, n) for (ll i = 0; i < (n); i++)
#define rep2(i, a, b) for (ll i = (a); i < (b); i++)
#define chmax(x, v) do { x = max(x, v); } while (0)
#define chmin(x, v) do { x = min(x, v); } while (0)
typedef uint64_t ull;
typedef int64_t ll;
typedef std::pair<ll, ll> PLL;

using namespace std;
// Segment Tree {{{
template <typename T>
class SegTree {
 private:
    int _n;
    T _init_val;
    std::vector<T> _data;
    std::function<T(T, T)> _f;

    T _query(int a, int b, int k, int l, int r) {
        // [a b)と[l r]が交差しない
        if (r <= a || b <= l) return _init_val;

        // [a b)が[l r]を含む
        if (a <= l && r <= b) return _data[k];

        T vl = _query(a, b, k*2+1, l, (l+r)/2);
        T vr = _query(a, b, k*2+2, (l+r)/2, r);

        return _f(vl, vr);
    }

 public:
    SegTree(int n, T init_val, std::function<T(T, T)> f) {
        _init_val = init_val;
        _n = 1;
        _f = f;

        while (_n < n)
            _n *= 2;
        _data.resize(2 * _n, init_val);
    }

    T get(int k) {
        return _data[k + _n - 1];
    }

    void update(int k, T a) {
        k += _n-1;
        _data[k] = a;
        while (k > 0) {
            k = (k-1)/2;
            _data[k] = _f(_data[k*2+1], _data[k*2+2]);
        }
    }

    // [a b)の範囲でfを適用
    T query(int a, int b) {
        return _query(a, b, 0, 0, _n);
    }

    // 先頭からチェックし，はじめてxを満たしたインデックス
    int lower_bound(T x) {
        return _lower_bound(x, 0);
    }

    int _lower_bound(T x, int k) {
        if (k >= _n-1) {
            return k - (_n - 1);  // 葉
        } else if (_data[k] < x) {
            return _n;  // 該当なし
        } else if (x <= _data[k * 2 + 1]) {
            return _lower_bound(x, k * 2 + 1);
        } else {
            return _lower_bound(x - _data[k * 2 + 1] , k * 2 + 2);
        }
    }
};
// }}}

ll N;
ll h[300000];
ll a[300000];

ll maxll(ll x, ll y) {
  if (x > y)
    return x;
  return y;
}

// st[h]: 最後の高さをhとしたときの最大の価値
SegTree<ll> st(300000, -1, maxll);

signed main() {
  cin >> N;
  rep(i, N)
    cin >> h[i];
  rep(i, N)
    cin >> a[i];
  ll ans = -1;
  st.update(0, 0);
  rep(i, N) {
    ll aa = st.query(0, h[i]);
    st.update(h[i], aa + a[i]);
    chmax(ans, aa + a[i]);
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 12032
#include <iostream>
#include <cstdio>
#include <cstring>
#include <set>
#define N 100005
using namespace std;
int n, t;
int a[N];
int main() {
  cin>>n>>t;
  for (int i = 0; i < n; ++i) {
    cin>>a[i];
  }
  int minv = 2000000000;
  int maxv = 0;
  for (int i = 0; i < n; ++i) {
    if (i == 0) {
      minv = min(minv, a[i]);
    } else {
      maxv = max(maxv, a[i] - minv);
      minv = min(minv, a[i]);
    }
  }
  int tot=0;
  minv = 2000000000;
  for (int i = 0; i < n; ++i) {
    if (i == 0) minv = min(minv, a[i]);
    else {
      if (a[i] - minv == maxv) {
        tot++;
      }
      minv = min(minv, a[i]);
    }
  }
  cout<<tot<<endl;
  return 0;
}

Measured memory_bytes: 640
S=input()
n=len(S)

res = 0
for i in range(n):
  for j in range(i,n):
    sub = S[i:j+1]
    flg=True
    for c in sub:
      if c not in ["A","G","C","T"]:
        flg = False
    if flg:
      res = max(res,len(sub))
print(res)


Measured memory_bytes: 9000
from sys import stdin

w,h,n = [int(x) for x in stdin.readline().rstrip().split()]
li = [list(map(int,stdin.readline().rstrip().split())) for _ in range(n)]

mix = 0
miy = 0
mx = w
my = h

for i in li:
    if i[2] == 1:
        mix = max(mix,i[0])
    elif i[2] == 2:
        mx = min(mx,i[0])
    elif i[2] == 3:
        miy = max(miy,i[1])
    else:
        my = min(my,i[1])

if mix >= mx or miy >= my:
    print(0)
else:
    print((mx-mix)*(my-miy))

Measured memory_bytes: 3064
a = int(input())
b = int(input())
c = int(input())
d = int(input())
e = int(input())
ans = 0
plus = 0
while plus < a:
    plus += 10
ans += plus

plus = 0
while plus < b:
    plus += 10
ans += plus

plus = 0
while plus < c:
    plus += 10
ans += plus

plus = 0
while plus < d:
    plus += 10
ans += plus

plus = 0
while plus < e:
    plus += 10
ans += plus

minus = [int(str(a)[-1]), int(str(b)[-1]), int(str(c)[-1]), int(str(d)[-1]), int(str(e)[-1])]
minus.sort()
for i in minus:
    if i !=0:
        ans -= 10-i
        break
print(ans)


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

int main() {
	int n,k,x,y,d;
	cin>>n>>k>>x>>y;

	if(n<=k){
		d=n*x;
	}else{
		d=k*x+(n-k)*y;
	}

	cout<<d<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
using namespace std;

int main(){
    string C;
    cin>>C;
    printf("%c\n",(C[0]+1));
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define mod 1000000007
#define ff first
#define ss second
using namespace std;
/*ll power(ll x,ll y)
{
    ll res=1;
    while(y>0)
    {
        if(y%2==1)
            res=(res*x)%mod;
        x=(x*x)%mod;
        y=y/2;
    }
    return res;
}*/

int main()
{
   ll n,i,m;
   vector<ll>v,v1;
   cin>>n;
   for(i=0;i<n;i++)
   {
       cin>>m;
       v.pb(m);
   }
   v1=v;
   sort(v.begin(),v.end(),greater<ll>());
   ll a=v[0],b=v[1];
   for(i=0;i<n;i++)
   {
       if(v1[i]==a)
        cout<<b<<endl;
       else
        cout<<a<<endl;
   }
}


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

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

long long lcm(long long a,long long b)
{
	return a*b/gcd(a,b); // オーバーフローしそう
}

int main(){

	int t;cin >>t;
	
	for(int loop = 0; loop < t ; loop++)
	{
		long long a,b,c,d;cin>>a>>b>>c>>d;
		
		bool ok = true;
		
		if(a < b) ok = false;
		if(d < b) ok = false;
		if(!ok)
		{
			cout << "No" << endl;
			continue;
		}
		
		if(c>=b-1)
		{
			cout << "Yes" << endl;
			continue;
		}
		
		long long henka = d - (d-1)/b * b;
		henka = gcd(henka,b);
		long long tmp=(a-b)/henka;
		long long hikaku = a-henka*tmp;

		
		if(hikaku - henka <= c) cout << "Yes" << endl;
		else cout << "No" << endl;
		
		
	}
	
}

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

int main() {
  int N;
  cin >> N;
  
  for (int i=1; i<=9; i++) {
    if (N <= 100*i+10*i+i) {
      cout << 100*i+10*i+i << endl;
      break;
    }
  }
   
}

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

const long double CHANGE = 1e-8;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge {c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

const int nax = 1e5 + 5;
int n;
int t[nax], pref[nax], suf[nax];
bool zmniejszone = false;

bool rec() {
	bool anything = false;
	while(n >= 1 && t[n] == 1) {
		--n;
		zmniejszone = true;
	}
	for(int i = 1; i <= n; ++i) {
		if(t[i] == 1) {
			zmniejszone = true;
			swap(t[i], t[n]);
			--n;
		}
		if(t[i] != 1) anything = true;
	}
	if(n == 0 || !anything) return false;
	
	long long s = 0, nparz = 0, where = -1;
	for(int i = 1; i <= n; ++i) {
		s += t[i] - 1;
		if(t[i] % 2) {
			nparz++;
			where = i;
		}
	}
	debug() << "tu";
	debug() << imie(s);
	if(s % 2) return true;
	if(zmniejszone) return false;
	if(n % 2 == 0) return false;
	debug() << "nawet tu";
	if(nparz == 1) {
		debug() << "spec";
		--t[where];
		int g = t[1];
		for(int j = 1; j <= n; ++j)
			g = __gcd(g, t[j]);
		assert(g % 2 == 0);
		for(int j = 1; j <= n; ++j) t[j] /= g;
		return !rec();
	}
	return false;
}

int main() {
	scanf("%d", &n);
	for(int i = 1; i <= n; ++i)
		scanf("%d", &t[i]);
	if(n == 1) {
		if(t[1] % 2 == 0) puts("First");
		else puts("Second");
		return 0;
	}
	puts(rec() ? "First" : "Second");
}



Measured memory_bytes: 768
n,m,c = map(int,input().split())
b = list(map(int,input().split()))
a = [list(map(int,input().split()))for _ in range(n)]
ans = 0
total = 0
for i in range(n):
  for j in range(m):
    if j == m - 1:
      total += a[i][j] * b[j]
      total += c
      if total > 0:
        ans += 1
      total = 0
    else:
      total += a[i][j] * b[j]
print(ans)

Measured memory_bytes: 3064
import java.util.*;

public class Main {
    private static final Scanner scn = new Scanner(System.in);
    
    public static void main(String[] args) {
        int a = scn.nextInt(), b = scn.nextInt();
        System.out.println("a " + (a < b ? "<" : (a > b ? ">" : "==")) + " b");
    }
}

Measured memory_bytes: 26088
//#include <bits/stdc++.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cstring>
#include <deque>
#include <queue>
#include <map>
using namespace std;

#define ii pair <int, int>
#define lli long long
#define pb push_back
#define X first
#define Y second

const int Mod = 1E9 + 7;
const int Inf = 1E9 + 7;
const int N = 2E5 + 10;

void Input()
{

}

void Solve()
{
    int x;
    cin >> x;
    cout << 1 - x;
}

#define task "test"
int main()
{
    if (fopen(task ".inp", "r")) {
        freopen(task ".inp", "r", stdin);
        freopen(task ".out", "w", stdout);
    }
    int testcase = 1;
    /// cin >> testcase;
    while (testcase--) {
        Input();
        Solve();
    }
}



Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
#define fastIO std::ios_base::sync_with_stdio(false); std::cin.tie(0); std::cout.tie(0)
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
typedef vector<int> VI;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> PII;
typedef double db;
//mt19937 mrand(random_device{}()); 
//int rnd(int x) { return mrand() % x;}
const ll mod=1000000007;
const int INF = 0x3f3f3f3f;
const double PI = acos(-1.0);
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}

const int maxn = 2e5 + 10; 

int a,b,c,k;

int main()
{
	fastIO;
	cin >> a >> b >> c >> k;
	if(k < a) cout << k << endl;
	else if(k <= a + b) cout << a << endl;
	else cout << a - (k - a - b) << endl;

	return 0;
}

Measured memory_bytes: 3652
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
template<class T,class U> inline bool chmin(T&x,U y){if(x>y){x=y;return true;}return false;}
template<class T,class U> inline bool chmax(T&x,U y){if(x<y){x=y;return true;}return false;}
#define fr(i,n) for(int i=0;i<(n);++i)
#define Fr(i,n) for(int i=1;i<=(n);++i)
#define ifr(i,n) for(int i=(n)-1;i>=0;--i)
#define iFr(i,n) for(int i=(n);i>0;--i)

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n,m;
    cin>>n>>m;
    vector<int> e[100000];
    fr(i,m){
        int a,b;
        cin>>a>>b;
        --a,--b;
        e[a].emplace_back(b);
        e[b].emplace_back(a);
    }
    queue<int> q;
    q.push(0);
    vector<int> ans(n,-1);
    ans[0]=0;
    while(!q.empty()){
        int i=q.front();q.pop();
        for(auto&j:e[i]) if(ans[j]<0){
            ans[j]=i+1;
            q.push(j);
        }
    }
    cout<<"Yes"<<'\n';
    Fr(i,n-1) cout<<ans[i]<<'\n';
}

Measured memory_bytes: 10264
import java.util.Scanner;

public class Main{

    public static void main(String args[]){

        Scanner scan = new Scanner(System.in);
        Integer n = Integer.parseInt(scan.next());
        Integer p[] = new Integer[n];

        for(int i=0;i<n;i++)   
            p[i] = Integer.parseInt(scan.next());

        int cnt = 0;
        for(int i=1;i<n-1;i++){
            if((p[i] < p[i-1] && p[i] > p[i+1]) || (p[i] > p[i-1] && p[i] < p[i+1])){
                cnt++;
            }
        }

        System.out.println(cnt);

    }
}

Measured memory_bytes: 23764
# include <bits/stdc++.h>
using namespace std;
int n,a[100005],dp[100005],k,ans;
int main()
{
	cin>>n>>k;
	for (int i=1; i<=n; i++)
	{
		cin>>a[i];
	}
	if (k==1)
	{
		for(int i=1; i<=n-1; i++)
		ans+=abs(a[i+1]-a[i]);
		cout<<ans<<endl;
		return 0;
	}
	dp[n]=0;
	dp[n-1]=abs(a[n-1]-a[n]);
	for (int i=1; i<=n-2; i++)
	dp[i]=1e9;
 if (n<=2) {
 	cout<<dp[1]<<endl; return 0; 	
 } 
	for (int i=n-2; i>=1; i--)
	{
		for (int j=1; j<=k; j++)
		{
			if (i+j<=n)
			dp[i]=min(dp[i+j]+abs(a[i+j]-a[i]),dp[i]);
		}
	}

	cout<<dp[1]<<endl;
}


Measured memory_bytes: 1024
from functools import reduce


def gcd(a, b):
    if b > a:
        a, b = b, a
    dp = [a, b]
    for i, v in enumerate(dp, start=2):
        dp.append(dp[i - 2] % dp[i - 1])
        if dp[i] == 0:
            break
    return dp[i - 1]


N = int(input())
a = list(map(int, input().split()))
print(reduce(gcd, a))


Measured memory_bytes: 14596
#include <bits/stdc++.h>
using namespace std;
 
int main() {

    int n;
    cin >> n;
    vector<int> a(n);
    for(int i = 0; i < n; ++i){
        cin >> a.at(i);
    }
    bool f = 1;
    int count = 0;
    while(f){
        bool f2 = 1;
        for(int i = 0; i < n; ++i){
            if(a.at(i)%2 != 0)f2 = 0;
        }

        if(f2){
            for(int i = 0; i < n; ++i){
                a.at(i) /= 2;
            }
            ++count;
        }else f = 0;
    }

    cout << count << endl;
}

    





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

ll solve() {
    ll N, K, a;
    cin >> N >> K;
    mcf_graph<ll, ll> g(2*N+2);
    int vs = 2*N, vt = 2*N+1;
    ll MA = 1e9;
    for ( int i = 0; i < N; i++ ) {
        for ( int j = 0; j < N; j++ ) {
            cin >> a;
            g.add_edge(i, N+j, 1, MA-a);
        }
    }
    for ( int i = 0; i < N; i++ ) {
        g.add_edge(vs, i, K, 0);
        g.add_edge(N+i, vt, K, 0);
    }
    g.add_edge(vs, vt, N*K, MA);
    auto f = g.flow(vs, vt, N*K);
    vector<string> ans(N, string(N, '.'));
    for ( auto e : g.edges() ) {
        if ( e.from != vs && e.to != vt && e.flow > 0 ) {
            ans[e.from][e.to-N] = 'X';
        }
    }
    cout << (MA*K*N)-f.second << "\n";
    for ( auto ans1 : ans ) {
        cout << ans1 << "\n";
    }
    return 0;
}

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

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

struct UnionFind {
    vector<int> par;
    vector<int> sz;

    UnionFind(int n=0){ if(n>0) initialize(n); }
    void initialize(int n){
        par.resize(n);
        sz.assign(n, 1);
        for(int i=0; i<n; i++){
            par[i] = i;
        }
    }

    int find(int x){
        if(par[x] == x){
            return x;
        }else{
            return par[x] = find(par[x]);
        }
    }

    bool unite(int x, int y){
        x = find(x), y = find(y);
        if(x == y) return false;
        if(sz[x] > sz[y]) swap(x, y);
        par[x] = y;
        sz[y] += sz[x];
        return true;
    }

    bool same(int x, int y){ return find(x) == find(y); }
    int size(int x){ return sz[find(x)]; }
};

int main(){
    int N;
    cin >> N;
    vector<tuple<int, int, int>> XYI(N);
    for(int i=0; i<N; i++){
        int x, y;
        cin >> x >> y;
        XYI[i] = {x, y, i};
    }
    sort(XYI.begin(), XYI.end());

    UnionFind uf(N);
    set<pair<int, int>> st;
    st.emplace(N+1, N+1);
    for(auto& [x, y, i] : XYI){
        if(st.begin()->first < y){
            uf.unite(i, st.begin()->second);
            auto it = next(st.begin());
            while(it->first < y){
                uf.unite(i, it->second);
                it = st.erase(it);
            }
        }else{
            st.emplace(y, i);
        }
    }

    for(int i=0; i<N; i++) cout << uf.size(i) << endl;
    return 0;
}


Measured memory_bytes: 11452
t = int(input())
hmap = {'AC':0,'WA':0,'TLE':0,'RE':0}
for _ in range(t):
    temp = input()
    hmap[temp] += 1

print("AC x "+str(hmap['AC']))
print("WA x "+str(hmap['WA']))
print("TLE x "+str(hmap['TLE']))
print("RE x "+str(hmap['RE']))

Measured memory_bytes: 9136
#include <iostream>
using namespace std;
int main(void){
    
    int i,n;
    int x[101];
    
    cin >> n;
    
    for(i=0; i<n; i++){
        cin >> x[i];
    }
    
    for(i=n-1; i>=0; i--){
        if (i==0){
            cout << x[i] << endl;
        }
        else{
            cout << x[i] << " ";
        }
    }
    
    return 0;
}



Measured memory_bytes: 3088
#include <iostream>
#include <algorithm>
#include <string>
#include <cmath>
#include <ctype.h>
#include <map>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <cctype>
#include <queue>
#include <set>
#include <list>
#define PI 3.141592653
#define rep(i,a,n) for(int i=a;i<(int)n;++i)
#define SZ(x) ((int)(x).size())	//size() unsigned -> int
#define DescSort(a) sort(a.begin(),a.end(),std::greater<int>())

using namespace std;
typedef long long ll;
const ll INF = 1e9 + 7;

int main(void) {
	int n, k;
	cin >> n >> k;
	vector<int> x(n);
	rep(i, 0, n)cin >> x[i];
	int ans = 0;
	rep(i, 0, n) {
		ans += min(2*x[i],abs(k-x[i])*2);
	}
	cout << ans << endl;
	return 0;
}


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

const int N = 2e5 + 5;

int n;
int a[N], b[N];
int fa[N], fb[N];

int main() {
	ios_base::sync_with_stdio(false);
	cin >> n;
	for (int i = 1; i <= n; ++i) cin >> a[i];
	for (int i = 1; i <= n; ++i) cin >> b[i];
	int res = 0;
	for (int it = 0; it <= 28; ++it) {
		int cnt = 0;
		for (int i = 1; i <= n; ++i) {
			fa[i] = a[i] & ((1 << (it + 1)) - 1);
			fb[i] = b[i] & ((1 << (it + 1)) - 1);
		}
		sort(fb + 1, fb + n + 1);
		for (int i = 1; i <= n; ++i) {
			cnt += lower_bound(fb + 1, fb + n + 1, 2 * (1 << it) - fa[i]) - lower_bound(fb + 1, fb + n + 1, (1 << it) - fa[i]);
			cnt += lower_bound(fb + 1, fb + n + 1, 4 * (1 << it) - fa[i]) - lower_bound(fb + 1, fb + n + 1, 3 * (1 << it) - fa[i]);
			cnt &= 1;
		}
		if (cnt) res += (1 << it);
	}
	cout << res << '\n';
}

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

const int mod = 998244353;
template<typename T>
T add(T x) {
  return x;
}
template<typename T, typename... Ts>
T add(T x, Ts... y) {
  T res = x + add(y...);
  if (res >= mod)
    res -= mod;
  return res;
}
template<typename T, typename... Ts>
T sub(T x, Ts... y) {
  return add(x, mod - add(y...));
}
template<typename T, typename... Ts>
void udd(T &x, Ts... y) {
  x = add(x, y...);
}
template<typename T>
T mul(T x) {
  return x;
}
template<typename T, typename... Ts>
T mul(T x, Ts... y) {
  return (x * 1ll * mul(y...)) % mod;
}
template<typename T, typename... Ts>
void uul(T &x, Ts... y) {
  x = mul(x, y...);
}
int bin(int a, ll deg) {
  int r = 1;
  while (deg) {
    if (deg & 1)
      uul(r, a);
    deg >>= 1;
    uul(a, a);
  }
  return r;
}
int inv(int x) {
  assert(x);
  return bin(x, mod - 2);
}

using Mask = __int128;
map<Mask, int> d[105][2];

Mask cut(Mask m, int n) {
  Mask x = Mask(1) << n;
  return m & (x - 1);
}

int calc(int n, Mask m, bool t) {
  if (d[n][t].count(m)) {
    return d[n][t][m];
  }
  int& res = d[n][t][m] = 0;
  if (n == 1) {
    return res = m + 1;
  }
  for (int i = 1; i < n; ++i) {
    if (!t) {
      Mask m1 = cut(m, i);
      Mask m2 = cut(m >> i, n - i);
      udd(res, mul(calc(i, m1, true), calc(n - i, m2, false)));
    }
    if (n % i == 0) {
      Mask a = (Mask(1) << i) - 1;
      for (int s = 0; s < n; s += i) {
        a &= cut(m >> s, i);
      }
      udd(res, calc(i, a, false));
    }
  }
  return res;
}

signed main() {
#ifdef LOCAL
  assert(freopen("e.in", "r", stdin));
#endif
  string s;
  cin >> s;
  Mask m = 0;
  for (int i = 0; i < (int) s.size(); ++i) {
    if (s[i] == '1') {
      m |= Mask(1) << i;
    }
  }
  cout << calc((int) s.size(), m, false) << '\n';
}


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

int main() {
    ll N, D, A;
    cin >> N >> D >> A;
    vector<pair<ll, ll>> XH(N);

    for(ll i = 0; i < N; i++){
      	ll X, H;
        cin >> X >> H;
      	XH[i] = make_pair(X, H);
    }
	sort(XH.begin(), XH.end());
  
  	ll j = 0, sum_attacks = 0, ans = 0;
  	vector<ll> attacked(N, 0LL);
  	for(ll i = 0; i < N; i++){
        for(; j < i && XH[i].first - XH[j].first > 2 * D; j++){
            sum_attacks -= attacked[j];
        }
      	ll rem = XH[i].second - sum_attacks * A;
        ll now_attacked = rem <= 0LL ? 0LL : (rem - 1) / A + 1;
      	attacked[i] = now_attacked;
      	sum_attacks += now_attacked;
      	ans += now_attacked;
    }

    cout << ans << endl;
}

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

int main() {
  int h, w;
  cin >> h >> w;
  for (int i = 0; i < w + 2; i++)
    cout << "#";
  cout << '\n';
  for (int i = 0; i < h; i++) {
    string s;
    cin >> s;
    cout << "#" << s << "#\n";
  }
  for (int i = 0; i < w + 2; i++)
    cout << "#";
  cout << '\n';
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <iomanip>
using namespace std;
 
int main() {
  int N;
  cin >> N;
  int p = N * 3;
  vector<int> vec(p);
  for (int i = 0 ; i < p ; i++ ) {
    cin >> vec.at(i);
  }
  sort(vec.begin(), vec.end());
  reverse(vec.begin(), vec.end());
  
  long long int sum, x;
  int k;
  int sum10;
  x = 2000000000;
  for (int i = 0 ; i < N; i++ ) {
    k = i*2 + 1;
    sum = sum + vec.at(k);
    
    if ( sum >= x ) {
      sum10++;
      sum = sum % x;
    }
  }
  
  cout << setprecision(20) << sum + sum10 * x << endl;
}

Measured memory_bytes: 1408
# Your code here!

n=gets.to_i
a=gets.split(" ").map(&:to_i)
i=0
z=1
n.times{
    if a[i]==0
        z=z*1
    elsif a[i]%2==0
        z=z*2
    else
        z=z*1
    end
    i+=1
}

print(3**n-z)

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

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

  int ans = 0;
  rep(bh, 1<<H) rep(bw, 1<<W) {
    int n_black = 0;
    rep(h,H) rep(w,W) {
      if (bh >> h & 1) continue;
      if (bw >> w & 1) continue;
      if (C[h][w] == '#') n_black++;
    }
    if (n_black == K) ans++;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3632
/*
    Author: zxy_hhhh
    date: 2020/03/10
*/
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cctype>
#include<cmath>
#include<set>
#include<vector>
#include<map>
#include<queue>
#include<iostream>
#define ll long long
inline ll rd() {
    ll _x=0;int _ch=getchar(),_f=1;
    for(;!isdigit(_ch)&&(_ch!='-')&&(_ch!=EOF);_ch=getchar());
    if (_ch=='-'){_f=0;_ch=getchar();}
    for(;isdigit(_ch);_ch=getchar()) _x=_x*10+_ch-'0';
    return _f?_x:-_x;
}
void write(ll _x){if (_x>=10) write(_x/10),putchar(_x%10+'0'); else putchar(_x+'0'); }
inline void wrt(ll _x,char _p){if (_x<0) putchar('-'),_x=-_x; write(_x); if (_p) putchar(_p);}
#define maxn 200005
#define mod 1000000007
int a[maxn],b[maxn];
int dp[2005][4005],fac[8005],inv[8005];
int n,L,R;
int main() {
    n=rd();
    for(int i=1;i<=n;i++) {
        a[i]=rd(),b[i]=rd();
        L=std::max(L,a[i]),R=std::max(R,b[i]);
    }
    for(int i=1;i<=n;i++) {
        dp[a[i]][b[i]+R]++;
    } 
    for(int i=L;i>=0;i--) {
        for(int j=R;j>=-R;j--) {
            dp[i][j+R]=((ll)dp[i+1][j+R]+dp[i][j+1+R]+dp[i][j+R])%mod;
        }
    }
    // for(int i=0;i<=L;i++) {
    //     for(int j=-R;j<=R;j++) {
    //         wrt(dp[i][j+R],' ');
    //     }
    //     putchar('\n');
    // }
    int ans=0;
    for(int i=-R;i<=R;i++) {
        ans=(ans+1ll*dp[0][i+R]*dp[1][R-i])%mod;
    }
    fac[0]=inv[0]=fac[1]=inv[1]=1;
    for(int i=2;i<=L+L+R+R;i++) {
        fac[i]=1ll*fac[i-1]*i%mod;
        inv[i]=1ll*(mod-mod/i)*inv[mod%i]%mod;
    }
    for(int i=2;i<=L+L+R+R;i++) 
        inv[i]=(1ll*inv[i]*inv[i-1])%mod;
    for(int i=1;i<=n;i++) {
        ans=(ans-1ll*fac[a[i]+b[i]+a[i]+b[i]]*inv[a[i]+a[i]]%mod*inv[b[i]+b[i]]%mod+mod)%mod;
    }
    wrt(1ll*ans*((mod+1)/2)%mod,'\n');
}

Measured memory_bytes: 33280
import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        double tmp = (double)N;
        System.out.println(tmp *  3.14159265358979323846264338327950288 * 2.0000000000000000000000);
    }
}


Measured memory_bytes: 35860
#include <iostream>
#include <set>
#include <vector>
#include <algorithm>

int main()
{
	int n;
	while (true) {
		std::cin >> n;
		if (n==0) break;
		
		std::set<int> rem;
		for (int i=1; i<=n/2; i++) {
			rem.insert((i*i)%n);
		}
		std::vector<int> v(n/2);
		for (std::set<int>::iterator it1 = rem.begin(); it1 != rem.end(); ++it1) {
			int a = *it1;
			for (std::set<int>::iterator it2 = rem.begin(); it2 != rem.end(); ++it2) {
				if (it1 == it2) continue;
				int b = *it2;
				int d = a-b;
				if (d<0) d += n;
				if (d>n/2) d = n - d;
				v[d-1]++;
			}
		}
		for (int i=0; i<n/2; i++) std::cout << v[i] << std::endl;
	}
		
	return 0;
}



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

int main(){
    int N, K;
    cin >> N >> K;
    int h[N];
    int count = 0;
    rep(i, N){
        cin >> h[i];
        if(h[i] >= K){
            count ++;
        }
    }
    cout << count << endl;
}

Measured memory_bytes: 640
#pragma GCC optimize("Ofast", "unroll-loops")

#include <bits/stdc++.h>

using namespace std;

int n;
vector<vector<int>> g;

void input() {
	cin >> n;
	g.resize(n);
	for (int i = 0; i < n - 1; ++i) {
		int x, y;
		cin >> x >> y;
		--x, --y;
		g[x].push_back(y);
		g[y].push_back(x);
	}
}

int grundy(int s = 0, int p = -1) {
	int res = 0;
	for (auto c : g[s]) {
		if (c != p) {
			int tmp = grundy(c, s);
			res ^= (tmp + 1);
		}
	}
	return res;
}

int main() {
	input();
	cout << (grundy() ? "Alice" : "Bob") << endl;
	return 0;
}

Measured memory_bytes: 8832
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i=0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
using ll = long long;
using VL = vector<ll>;
using VVL = vector<vector<ll>>;
using P = pair<ll, ll>;

// chmin, chmax関数
template<typename T, typename U, typename Comp=less<>>
bool chmax(T& xmax, const U& x, Comp comp={}) {
    if(comp(xmax, x)) {
        xmax = x;
        return true;
    }
    return false;
}
template<typename T, typename U, typename Comp=less<>>
bool chmin(T& xmin, const U& x, Comp comp={}) {
    if(comp(x, xmin)) {
        xmin = x;
        return true;
    }
    return false;
}

// Yes-Noを出力する問題で楽をする
void Ans(bool f){
    if(f) cout << "Yes" << endl;
    else cout << "No" << endl;
}

//---------------------------

int main(){
    string s; cin >> s;
    int ans = 0;
    rep(i,3) if(s[i]=='1') ans++;
    cout << ans << endl;
    return 0;
}

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

#define ll long long int
ll mod=1e9+7;

int main()
{
    /* Faster input ouput */
    // ios_base::sync_with_stdio(false);
    // cin.tie(NULL);
    // cout.tie(NULL);

    /* To read input from a file and output to a file */
    // freopen("input.txt","r",stdin);
    // freopen("output.txt","w",stdout);
    
    ll t = 1;
    // cin >> t;
    while(t--)
    {        
        ll n,i,j,k;
        cin >> n >> k;
        ll arr[n];

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

        // ll prod = (ll)1;
        // for(i=0;i<k;i++)
        // {
        //     prod *= arr[i];
        // }

        // ll prev_prod = prod;
        for(i=k;i<n;i++)
        {
            // ll curr_prod = prod;
            // curr_prod *= arr[i];
            // curr_prod /= arr[i-k];
            if(arr[i] > arr[i-k])
            {
                cout << "Yes\n";
            }
            else
            {
                cout << "No\n";
            }

            // prod = curr_prod;
        }
    }
    
    return 0;
}

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

const ll mod = 1000000007;

int main() {
  int N;
  cin >> N;
  vector<ll> A(N);
  rep(i, N) cin >> A[i];
  
  vector<vector<ll> > dp(N + 1, vector<ll>(N + 1, 0));
  vector<P> p;
  rep(i, N) p.emplace_back(A[i], i);
  // A[i]が大きいものから順に並べる
  sort(p.rbegin(), p.rend());

  // dp[i][l]:i番目に大きいAまで既に並べて、左に移動させるものがl個ある状態での最大値
  rep(i, N) {
    int pi = p[i].second;
    rep(l, i + 1) {
      int r = i - l;
      dp[i+1][l+1] = max(dp[i + 1][l + 1], dp[i][l] + ll(pi - l) * A[pi]);
      dp[i+1][l] = max(dp[i + 1][l], dp[i][l] + ll((N - r - 1) - pi) * A[pi]);
    }
  }

  ll ans = 0;
  rep(i, N + 1) ans = max(ans, dp[N][i]);
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 35036
#include <stdio.h>
#include <iostream>
#include <cstdlib>
#include <cmath>
#include <cctype>
#include <string>
#include <cstring>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <ctime>
#include <vector>
#include <fstream>
#include <list>
#include <iomanip>
#include <numeric>
using namespace std;
#define ll long long
#define ull unsigned long long
#define db double
#define REP(i, lim) for(int i=0;i<lim;++i)
#define REPP(i, lim) for(int i=1;i<=lim;++i)
#define DEC(i, lim) for(int i=lim;i>=1;--i)
#define FOR(i,l,r)  for(int i=l;i<r;++i)
#define deBug cout<<"==================================="<<endl;
#define clr(s) memset(s, 0, sizeof(s))
#define lowclr(s) memset(s, -1, sizeof(s))
const int MAXN = 1000055;
const int inf = 0x3f3f3f3f;
const double pi = acos(-1.0);
const db eps = 1e-9;

inline int sgn(db x) { return x<-eps ? -1 : x>eps; }
inline db sqr(db x) { return x*x; }

#define cross(p1, p2, p3) ((p2.x-p1.x)*(p3.y-p1.y)-(p3.x-p1.x)*(p2.y-p1.y))
#define crossOp(p1, p2, p3) sgn(cross(p1, p2, p3))

struct P {
    // information
    P() {}
    P(db _x, db _y) : x(_x), y(_y) {}
    db x, y;

    // operation
    P operator + (P p)   const{ return P(x+p.x, y+p.y); }
    P operator - (P p)   const{ return P(x-p.x, y-p.y); }
    P operator * (db d)  const{ return P(x*d, y*d); }
    P operator / (db d)  const{ return P(x/d, y/d); }

    db dot(P p) { return x * p.x + y * p.y; } // 点积
    db det(P p) { return x * p.y - y + p.x; } // 叉积

    // other
    void input() { scanf("%lf%lf", &x, &y); }
    void print() { printf("(%lf, %lf)\n", x, y); }

    db dis(P p) { return sqrt(sqr(x-p.x) + sqr(y-p.y)); }
    db dis2(P p) { return sqr(dis(p)); }
};

P getProjection(P a, P b, P p) {
    // (p1, q) 在 (p1, q2) 上的投影点
    P dir = b-a;
    return a + dir * ( dir.dot(p-a) / a.dis2(b) );
}
P getReflection(P a, P b, P p) { return getProjection(a, b, p) * 2 - p; }

bool isParallel(P p1, P p2, P q1, P q2) {
    db a1 = cross(q1, q2, p1), a2 = -cross(q1, q2, p2);
    return sgn(a1+a2) == 0;
}

int main()
{
//    freopen("in.txt", "r", stdin);
//    freopen("out.txt", "w", stdout);
//    std::ios::sync_with_stdio(false); cin.tie(0);

    int T;
    scanf("%d", &T);
    while(T--)
    {
        P p1, p2, q1, q2;
        p1.input(); p2.input(), q1.input(); q2.input();

        if(isParallel(p1, p2, q1, q2)) printf("2\n");
        else{
            P qq1 = q1 - (q1-p1), qq2 = q2 - (q1-p1);
            if (sgn((qq2-qq1).dot(p2-p1)) == 0) printf("1\n");
            else                                printf("0\n");
        }
    }
    return 0;
}


Measured memory_bytes: 3248
def red_or_blue(N: int, s: str)->bool:
    r = sum(c == 'R' for c in s)
    return r > N-r


if __name__ == "__main__":
    N = int(input())
    s = input()

    yes = red_or_blue(N, s)
    print('Yes' if yes else 'No')


Measured memory_bytes: 2940
#include <stdio.h>
 
typedef struct pair* ppair;
 
typedef struct pair {
  int first, second;
} pair;
 
 
int size;
pair v[1000000];
int psize;
pair preorder[1000000];
int sorted;
 
void swap(ppair a, ppair b) {
  pair t = *a;
  *a = *b;
  *b = t;
}
 
int getp(int begin, int end) {
  int i;
  int p = begin;
  for(i = begin+1; i < end; ++i) {
    if(v[i].first < v[p].first) {
      p = i;
    }
  }
  swap(&v[end-1], &v[p]);
  return end-1;
}
 
void qsort(int begin, int end) {
  int i, j;
  if(begin >= end) return;
  getp(begin,end);
  preorder[psize++] = v[end-1];
  if(begin+1 == end) return;
  for(i = begin, j = begin; i < end; ++i) {
    if(v[i].second < v[end-1].second) {
      swap(&v[i], &v[j++]);
    }
  }
  swap(&v[j],&v[end-1]);
  qsort(begin, j);
  qsort(j+1, end);
}
 
int binary_search(int k) {
  int l, r;
  l = 0;
  r = size;
  while(l < r) {
    int m = (l+r)/2;
    if(v[m].second == k) {
      return m;
    } else if(v[m].second < k) {
      l = m+1;
    } else {
      r = m;
    }
  }
  return -1;
}
 
int main() {
  int i, j;
  int n, k;
  char s[100];
  size = 0;
  sorted = 0;
  scanf("%d", &n);
  for(i = 0; i < n; ++i) {
    scanf("%s", s);
    if(s[0] == 'i') {
      scanf("%d", &k);
      v[size] = (pair){size,k};
      ++size;
      sorted = 0;
    } else if(s[0] == 'p') {
      if(!sorted) {
        psize = 0;
        qsort(0, size);
        sorted = 1;
      }
      for(j = 0; j < size; ++j) {
        printf(" %d", v[j].second);
      }
      printf("\n");
      for(j = 0; j < size; ++j) {
        printf(" %d", preorder[j].second);
      }
      printf("\n");
    } else {
      scanf("%d", &k);
      if(!sorted) {
        psize = 0;
        qsort(0, size);
        sorted = 1;
      }
      printf(binary_search(k)!=-1?"yes\n":"no\n");
    }
  }
  return 0;
}

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

#define ll long long int

using namespace std;

ll inf=1e9+5;

map<ll,int> s;
vector<ll> pot;
ll h,w;
void goo(ll x)
{
    ll H,W;
    W=x%inf;
    x-=x%inf;
    H=x/inf;
    for(int i=H-2;i<=H;i++)
    {
        for(int j=W-2;j<=W;j++)
        {
            if(i>=1 && i<=h && j>=1 && j<=w)
            {
                ll res=(ll)i*inf+j;
                pot.push_back(res);
            }
        }
    }
}

int cnt[10];

void doo(ll x)
{
    ll H,W;
    W=x%inf;
    x-=x%inf;
    H=x/inf;
    int res=0;
    if(H>=1 && H+2<=h && W>=1 && W+2<=w)
    {
        for(int i=H;i<=H+2;i++)
        {
            for(int j=W;j<=W+2;j++)
            {
                ll akt=(ll)i*inf+j;
                res+=s[akt];
            }
        }
    }
    else return;
    cnt[res]++;
}

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cin>>h>>w;
    int n; cin>>n;
    vector<ll> a;
    for(int i=0;i<n;i++)
    {
        int x,y; cin>>x>>y;
        a.push_back((ll)x*inf+y);
        s[a[i]]=1;
    }
    for(int i=0;i<n;i++)
    {
        goo(a[i]);
    }
    sort(pot.begin(),pot.end());
    for(int i=0;i<pot.size();i++)
    {
        if(i==0 || pot[i]!=pot[i-1])
        {
            doo(pot[i]);
        }
    }
    ll cnn=0;
    for(int i=1;i<=9;i++)
    {
        cnn+=cnt[i];
    }
    cout<<(ll)(w-2)*(h-2)-cnn<<endl;
    for(int i=1;i<=9;i++) cout<<cnt[i]<<endl;
    return 0;
}


Measured memory_bytes: 164584
package main

import (
	"bufio"
	"fmt"
	"os"
)

func main() {
	N, K := ReadInt(), ReadInt()
	m := make(map[int]bool)
	for i := 0; i < K; i++ {
		m[ReadInt()] = true
	}
	v := N
	for {
		if ok(v, m) {
			fmt.Println(v)
			return
		}
		v++
	}
}

func ok(v int, m map[int]bool) bool {
	for v > 0 {
		if m[v%10] {
			return false
		}
		v /= 10
	}
	return true
}

var reader = bufio.NewReader(os.Stdin)

func Scan(a ...interface{}) {
	if _, err := fmt.Fscan(reader, a...); err != nil {
		panic(err)
	}
}
func ReadInt() (i int)       { Scan(&i); return }
func ReadString() (s string) { Scan(&s); return }
func ReadInts(n int) []int {
	v := make([]int, n)
	for i := 0; i < n; i++ {
		Scan(&v[i])
	}
	return v
}


Measured memory_bytes: 1844
#include <bits/stdc++.h>
using namespace std;
void Main();

using i8  = int8_t;   /* -128 ~ 127 */
using u8  = uint8_t;  /* 0 ~ 255 */
using i16 = int16_t;  /* -32,768 ~ 32,767 */
using u16 = uint16_t; /* 0 ~ 65,535 */
using i32 = int32_t;  /* -2,147,483,648 ~ 2,147,483,647 */
using u32 = uint32_t; /* 0 ~ 4,294,967,295 */
using i64 = int64_t;  /* -9,223,372,036,854,775,808 ~ 9,223,372,036,854,775,807 */
using u64 = uint64_t; /* 0 ~ 18,446,744,073,709,551,615 */
using f32 = float;    /* (-3.4 * 10^38) ~ (3.4 * 10^38) */
using f64 = double;   /* (-1.7 * 10^308) ~ (1.7 * 10^308) */
using f80 = __float80;
template <class T> using Vec = vector<T>;
constexpr i64 INF = 1010000000000000017;
constexpr i64 MOD = 1e9 + 7;
constexpr f64 EPS = 1e-12;
constexpr f64 PI = 3.14159265358979323846;
#define ALL(v) v.begin(), v.end()
#define YN(a, b, c) ((c)? a : b)
#define GCD(a, b) __gcd(a, b) /* 最大公約数 */
#define LCM(a, b) (i64)(a / (f64)__gcd(a, b) * b) /* 最小公倍数 */

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(15);
    Main();
    return 0;
}

void Main() {
    i32 N;
    cin >> N;
    Vec<bool> D(N, false);
    for (i32 i = 0; i < N; i++) {
        i32 d1, d2;
        cin >> d1 >> d2;
        if (d1 == d2) {
            D[i] = true;
        }
    }
    i32 r = 0;
    i32 tr = 0;
    for (i32 i = 0; i < N; i++) {
        if (D[i]) tr++;
        else tr = 0;
        if (tr > r) r = tr;
    }
    cout << YN("Yes", "No", r >= 3) << endl;
}


Measured memory_bytes: 3656
#include<algorithm>
#include<cmath>
#include<vector>
#include<string>
#include<iostream>
using namespace std;

int main()
{
	long long int N, M,B, i,D, j, k, l, m, n,  cnt, flag,max,min;
	cin >> N;
	vector<long long int>A(N);
	for (i = 0; i <= N-1; i++) {
		cin >> A[i];
	}
	long long int sum = 0;
	flag = 0;
	cnt = 0;
	max = A[0];
	for (i = 1; i < N; i++) {
		if (A[i] >= max) {
			k = i;
			max = A[i];
		}
	}
	min = A[0];
	for (i = 1; i < N; i++) {
		if (A[i] <= min) {
			j = i;
			min = A[i];
		}
	}
	if (max < 0) {
		cout << N - 1 << endl;
		for (i = N; i >= 2; i--) {
			cout << i << " " << i-1 << endl;
		}
	}
	else if (min>=  0) {
		cout << N - 1 << endl;
		for (i = 1; i <= N-1; i++) {
			cout << i << " " << i + 1 << endl;
		}
	}
	else if (abs(min)>=max) {
		cout << 2*N-1 << endl;
		for (i = 1; i <= N ; i++) {
			cout << j+1 << " " << i  << endl;
		}
		for (i = N; i >= 2; i--) {
			cout << i << " " << i - 1 << endl;
		}
	}
	else  {
		cout << 2 * N - 1 << endl;
		for (i = 1; i <= N; i++) {
			cout << k + 1 << " " << i << endl;
		}
		for (i = 1; i <= N - 1; i++) {
			cout << i << " " << i + 1 << endl;
		}
	}
	return 0;
}



Measured memory_bytes: 256
/*
Task:
Author: John_05
State: Unknown
Lang: C++
Solution:
*/
#include<bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
const int INF=2e9+10;
#define fi first
#define se second
#define pb push_back
#define mp make_pair

int read() {
	int xx=0,ww=1;
	char ch=getchar();
	while(ch>'9'||ch<'0') {
		if(ch=='-') ww=-ww;
		ch=getchar();
	}
	while(ch>='0'&&ch<='9') {
		xx=10*xx+ch-48;
		ch=getchar();
	}
	return xx*ww;
}

int H,W,h,w;

int main() {
	H=read();
	W=read();
	h=read();
	w=read();
	printf("%d\n",max((H-h)*(W-w),0));
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <cstdio>
#include <cstring>
using namespace std;

int main()
{
    cin.tie(0);
    int n;
    cin >> n;

    vector<int> as(n);
    for (auto &a: as) {
        cin >> a;
        a--;
    }

    int ans = 0;
    for (int i = 0; i < n; i++) {
        if (as[as[i]] == i)
            ans++;
    }

    cout << ans / 2 << endl;

    return 0;
}

Measured memory_bytes: 768
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <random>
#include <chrono>
 
using namespace std;
using namespace __gnu_pbds;
 
#define endl '\n'
 
typedef long long ll;
typedef pair<int, int> pii;
typedef tree<int, null_type,less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
 
template<typename T>
static T randint(T lo, T hi){
	return uniform_int_distribution<T>(lo, hi)(rng);
}



int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
 
	// freopen("settling.in", "r", stdin);
	// freopen("settling.out", "w", stdout);

	int x;
	cin >> x;
	cout << 1 - x << endl;

	return 0;
}


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

using namespace std;

const ll mod=1000000007;
const ll inf=1e18;

int main(){

  ll n;
  cin >> n;
  ll a=0,b=0,c=0,d=0;
  for(int i=0;i<n;i++){
    string s;
    cin >> s;
    if(s=="AC")a++;
    else if(s=="WA")b++;
    else if(s=="TLE")c++;
    else d++;
  }

  cout << "AC x " << a << endl;
  cout << "WA x " << b << endl;
  cout << "TLE x " << c << endl;
  cout << "RE x " << d << endl;

}

Measured memory_bytes: 3600
#include <bits/stdc++.h>
#define int long long
const int INF = 1e18L + 5;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
using namespace std;

signed main() {

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

    int n, a, b;
    cin >> n >> a >> b;
    cout << min(a * n, b) << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<unordered_map>
using namespace std;

int main() {
	char CHAR[3] = { 'B','R','W' };
	int a, b;
	cin >> a >> b;
	unordered_map<char, int>c[50]{};
	for (int d = 0; d < a; d++) {
		string e;
		cin >> e;
		for (char f : e) {
			for (int g = 0; g < 3; g++) {
				if (CHAR[g] != f)c[d][CHAR[g]]++;
			}
		}
	}
	int k = 1<<29;
	for (int x = 1; x < a - 1; x++) {
		for (int y = 1; y < a - x; y++) {
			int MAX = 0;
			for (int s = 0; s < x; s++)MAX += c[s]['W'];
			for (int s = x; s < x + y; s++)MAX += c[s]['B'];
			for (int s = x + y; s < a; s++)MAX += c[s]['R'];
			k = min(k, MAX);
		}
	}
	cout << k << endl;
}

Measured memory_bytes: 3164