akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <utility>
#include <vector>
#define rep(i, n) for(int i = 0, i##_len = (n); i < i##_len; ++i)
#define reps(i, n) for(int i = 1, i##_len = (n); i <= i##_len; ++i)
#define rrep(i, n) for(int i = ((int)(n)-1); i >= 0; --i)
#define rreps(i, n) for(int i = ((int)(n)); i > 0; --i)
#define INF 1000000000000
#define MOD 1000000007

using namespace std;
using ll = long long;

bool isExist(const vector<int> &p, int ans) {
    for(int value : p) {
        if(ans == value) {
            // cout << "ans:" << ans << " exist" << endl;
            return true;
        }
    }
    // cout << "ans:" << ans << "no exist!" << endl;
    return false;
}

int main() {
    int x, n, ans1, ans2;
    cin >> x >> n;
    vector<int> p(n);
    rep(i, n) cin >> p[i];
    ans1 = x, ans2 = x;
    rep(i, 101) {
        // pに含まれていない場合
        if(isExist(p, ans1) == false && (isExist(p, ans2) == false)) {
            // cout << "i: " << i << endl;
            cout << min(ans1, ans2) << endl;
            return 0;
        } else if(isExist(p, ans1) == false) {
            cout << ans1 << endl;
            return 0;
        } else if(isExist(p, ans2) == false) {
            cout << ans2 << endl;
            return 0;
        }
        ans1++;
        ans2--;

    }
    return 0;
}

Measured memory_bytes: 3176
#include <bits/stdc++.h>
#define ll long long int
using namespace std; 
  
void printString(ll n) 
{ 
    ll arr[10000]; 
    ll i = 0; 
  
    // Step 1: Converting to number assuming 
    // 0 in number system 
    while (n) { 
        arr[i] = n % 26; 
        n = n / 26; 
        i++; 
    } 
  
    // Step 2: Getting rid of 0, as 0 is 
    // not part of number system 
    for (ll j = 0; j < i - 1; j++) { 
        if (arr[j] <= 0) { 
            arr[j] += 26; 
            arr[j + 1] = arr[j + 1] - 1; 
        } 
    } 
  
    for (ll j = i; j >= 0; j--) { 
        if (arr[j] > 0) 
            cout << char('a' + arr[j] - 1); 
    } 
  
    cout << endl; 
} 
  
// Driver program to test above function 
int main() 
{ 
    ll n;
    cin>>n;
    printString(n); 
    return 0; 
} 
  

Measured memory_bytes: 3640
from sys import stdin


def get_result(data):
    T = data[0][0]
    S = data[1][0]
    return 'Yes' if T == S[:-1] else 'No'


if __name__ == '__main__':
    raw_data = [val.rstrip() for val in stdin.readlines()]
    data = [list(map(str, val.split(' '))) for val in raw_data]
    result = get_result(data)
    print(result)


Measured memory_bytes: 9124
#include <bits/stdc++.h>
#define PI 3.1415926535897
using namespace std;
typedef long long ll;
const int INF = 1000000000;
const ll LINF = 1000000000000000000; //1e18
const double EPS = 1e-10;

// 、「3 倍する」 操作を何回かやっておくことで、「2 で割る」 操作の回数が増えたり減ったりするで
// しょうか？答えは No です。なぜなら、奇数を掛けて 2 で割れる回数が増えることはなく、整数を掛けて
// 2 で割れる回数が減ることがないからです。

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

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

    int cnt = 0;
    for (int i = 0; i < N; i++)
    {
        while (a[i] % 2 == 0)
        {
            cnt++;
            a[i] /= 2;
        }
    }
    cout << cnt << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
int main()
{
  int x,y,r;
  scanf("%d%d",&x,&y);  
  if(x<y)
    {
      r=x;
      x=y;
      y=r;
    }
  while(1)
    {
      r=x%y;
      x=y;
      y=r;
      if(y==0) break;
    }
  printf("%d\n",x);  
  return 0;
}

Measured memory_bytes: 592
#include<bits/stdc++.h>
#define INF 1e9
#define llINF 1e18
#define MOD 1000000007
#define pb push_back
#define mp make_pair 
#define F first
#define S second
#define ll long long
#define ull unsigned long long
#define vi vector<ll>
#define vvi vector<vi>
#define DBG_N(hoge) cerr<<" "<<(hoge)<<endl;
#define DBG cerr<<"!"<<endl;
#define BITLE(n) (1LL<<((ll)n))
#define BITCNT(n) (__builtin_popcountll(n))
#define SUBS(s,f,t) ((s).substr((f)-1,(t)-(f)+1))
#define ALL(a) (a).begin(),(a).end()
using namespace std;
bool vis[BITLE(19)];
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll n;cin>>n;
  vi A(BITLE(n));
  for(auto &a:A)cin>>a;
  sort(ALL(A),greater<ll>());
  priority_queue<ll> slime[2];
  slime[0].push(A[0]);
  bool ans=true;
  vis[0]=true;
  for(int i=0;i<n;i++){
    ll num=BITLE(i);
    ll cnt=0;
    ll now=slime[0].top();
    for(int j=0;j<BITLE(n);j++){
      if(vis[j]||now<=A[j])continue;
      slime[0].pop();
      slime[1].push(A[j]);
      slime[1].push(now);
      vis[j]=true;
      if(!slime[0].empty())
	now=slime[0].top();
      else break;
    }
    if(!slime[0].empty()){cout<<"No"<<endl;return 0;}
    swap(slime[0],slime[1]);
  }
  if(ans)cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
  return 0;
}


Measured memory_bytes: 5800
my $input = <STDIN>;
chomp $input;

my ($W, $H, $N) = split(/\s/, $input);
my @squares;
for (my $i = 0; $i < $H; $i++) {
    $squares[$i] = 0;
}

my $a1 = 0;
my $a2 = $W;
my $a3 = 0;
my $a4 = $H;

for (my $i = 0; $i < $N; $i++) {
    $input = <STDIN>;
    chomp $input;

    my ($x, $y, $a) = split(/\s/, $input);
    if ($a == 1) {
        $a1 = ($a1 < $x)? $x:$a1;
    } elsif ($a == 2) {
        $a2 = ($a2 > $x)? $x:$a2;
    } elsif ($a == 3) {
        $a3 = ($a3 < $y)? $y:$a3;
    } else {
        $a4 = ($a4 > $y)? $y:$a4;
    }
}

$w = ($a2-$a1 < 0)?0:($a2-$a1);
$h = ($a4-$a3 < 0)?0:($a4-$a3);

my $count = $w*$h;
print $count, "\n";

exit;

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define INF 1e9
#define PI 3.14159265359
#define MOD 1000000007
#define ALL(v) v.begin(),v.end()
#define ALLR(v) v.rbegin(),v.rend()
typedef long long ll;
const int dx[4] = {1,0,-1,0};
const int dy[4] = {0,1,0,-1};
//isPrime
//modpow modinv
//getDigit
int main() {
  cout << fixed << setprecision(10);
  string o;
  string e;
  cin >> o >> e;
  rep(i,e.size()){
    cout << o.at(i);
    cout << e.at(i);
  }
  if(o.size()>e.size()) cout << o.back();
  cout << endl;
}


Measured memory_bytes: 256
open System

let n = stdin.ReadLine() |> int
let a =
    stdin.ReadLine().Split()
    |> Array.map int
    |> Array.sortDescending

let alice =
    Array.mapi (fun i x -> x * (1 - i % 2)) a
    |> Array.sum

let bob =
    Array.mapi (fun i x -> x * (i % 2)) a
    |> Array.sum

printfn "%d" <| alice - bob

Measured memory_bytes: 12112
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <array>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <sstream>
#include <stdio.h>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <list>
#include <numeric>
#include <stack>
#include <iomanip>

using namespace std;

#define Rep(i,a,b) for(int i = a; i < b; i++)
#define rep(i,b) Rep(i,0,b)
#define allof(a) (a).begin(), (a).end()

typedef long long ll;
const int inf = 1e9 + 7;
const ll infll = 1ll << 60ll;
const ll mod = 1e9 + 7;
// 0~3までは右左下上 4~7までは斜め
constexpr int dx[] = { 1, 0, -1, 0, 1, 1, -1, -1 };
constexpr int dy[] = { 0, -1, 0, 1, 1, -1, -1, 1 };

template<typename T> void chmax(T& a, T b) { a = std::max(a, b); }
template<typename T> void chmin(T& a, T b) { a = std::min(a, b); }
template<typename T> void chadd(T& a, T b) { a = a + b; }

namespace {  // 名前なし名前空間
	// gcd, lcm は C++17 でstdに標準入りしたので言語のバージョンに注意
	// 最大公約数
	ll gcd(ll a, ll b) {
		if (b == 0) return a;
		return gcd(b, a % b);
	}

	// 最小公倍数
	ll lcm(ll a, ll b) {
		return a / gcd(a, b) * b;
	}
}

int main() {

	ll n, k, q;
	cin >> n >> k >> q;
	vector<ll> a(q);
	rep(i, q) cin >> a[i];

	vector<ll> life(n, 0);

	rep(i, q) {
		life[a[i] - 1]++;
	}

	rep(i, n) {
		if (q - life[i] < k) cout << "Yes" << endl;
		else cout << "No" << endl;
	}

	return 0;
}


Measured memory_bytes: 2176
// #include <atcoder/all>
// using namespace atcoder;
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)n; ++i)
#define rrep(i, n) for (int i = (int)n-1; i >= 0; --i)
using namespace std;
using ll = long long;
template<typename T>
inline bool chmax(T& a, const T& b) {
    if (a < b){
        a = b;
        return true;
    }
    return false;
}
template<typename T>
inline bool chmin(T& a, const T& b) {
    if (b < a) {
        a = b;
        return true;
    }
    return false;
}
/**
 * @brief 多次元 vector の作成
 * @author えびちゃん
 */
namespace detail {
    template<typename T, int N>
    auto make_vec(vector<int>& sizes, T const& x) {
        if constexpr (N == 1) {
            return vector(sizes[0], x);
        } else {
            int size = sizes[N-1];
            sizes.pop_back();
            return vector(size, make_vec<T, N-1>(sizes, x));
        }
    }
}
template<typename T, int N>
auto make_vec(int const(&sizes)[N], T const& x = T()) {
    vector<int> s(N);
    for (int i = 0; i < N; ++i) s[i] = sizes[N-i-1];
    return detail::make_vec<T, N>(s, x);
}
__attribute__((constructor))
void fast_io() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
}

template <typename E>
struct dual_segment_tree {
    using H = function<E(E, E)>;
    int n, height;
    H h;
    E ei;
    vector<E> lazy;
    dual_segment_tree(H h, E ei) : h(h), ei(ei) {}
    void init(int n_) {
        n = 1; height = 0;
        while (n < n_) n <<= 1, height++;
        lazy.assign(2*n, ei);
    }
    inline void propagete(int i) {
        if (lazy[i] == ei) return;
        lazy[i<<1|0] = h(lazy[i<<1|0], lazy[i]);
        lazy[i<<1|1] = h(lazy[i<<1|1], lazy[i]);
        lazy[i] = ei;
    }
    inline void thrust(int i) {
        for (int k = height; k >= 1; --k) propagete(i>>k);
    }
    void update(int a, int b, E x) {
        a += n; b += n;
        thrust(a);
        thrust(b-1);
        int l = a, r = b;
        while (l < r) {
            if (l & 1) lazy[l] = h(lazy[l], x), l++;
            if (r & 1) --r, lazy[r] = h(lazy[r], x);
            l >>= 1; r >>= 1;
        }
    }
    E get_val(int i) {
        i += n;
        thrust(i);
        return lazy[i];
    }
};

int main() {
    ll n; int q;
    cin >> n >> q;
    ll ans = (n - 2) * (n - 2);
    auto f = [](int a, int b) { return min(a, b); };
    dual_segment_tree<int> seg1(f, n-1), seg2(f, n-1);
    seg1.init(n);
    seg2.init(n);
    while (q--) {
        int t, x;
        cin >> t >> x;
        x--;
        if (t == 1) {
            int res = seg1.get_val(x);
            ans -= res - 1;
            seg2.update(0, res, x);
        } else {
            
            int res = seg2.get_val(x);
            ans -= res - 1;
            seg1.update(0, res, x);
        }
    }
    cout << ans << '\n';
}

Measured memory_bytes: 7484
import math

a, b = map(int, input().split(' '))

def gcd(a, b):
    if a % b == 0 or b % a == 0:
        return min(a, b)
    else:
        if a // b >= b // a:
            c = abs(a - b * (a // b))
        else:
            c = abs(b - a * (b // a))
        d = min(a, b)
        return gcd(c, d)

gcd_ = gcd(a, b)
d = []
for i in range(1, max(4, int(math.sqrt(gcd_))+1)):
    if not gcd_ % i:
        d.extend([i, gcd_ // i])

d.sort()
while d != [] and d[0] == 1:
    del d[0]
ans = [1]

for i in d:
    for j in ans:
        if gcd(i, j) == 1 and j == ans[-1]:
            ans.append(i)
        elif gcd(i, j) != 1:
            break

print(len(ans))

Measured memory_bytes: 3316
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <climits>
#include <map>
using namespace std;
const int SIZEN = 30;
typedef long long LL;
int N;
LL ans = 0;
char s[SIZEN] = {0};
int add[SIZEN] = {0};
void Judge(){
	int i = 1,j = 1;
	while(j <= N){
		while(add[j] == 0 && j < N)j++;
		LL tmp = 0;
		for(int k = i;k <= j;k++) {
			tmp = tmp * 10 + s[k]-'0';
		}
		ans += tmp;
		i= j+1;j++;
	} 
}
void DFS(int x){
	if(x == N){Judge();return;}
	add[x] = 1;
	DFS(x+1);
	add[x] = 0; 
	DFS(x+1);
}
int main(){
    scanf("%s",s+1);
    N = strlen(s+1);
    DFS(1);
    printf("%lld\n",ans);
	return 0;
}
/*
2
1 1
100 0
100 100
1 1
100 100
100 100
*/

Measured memory_bytes: 128
#include <iostream>

using namespace std;

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

	int H, W, h, w;
	cin >> H >> W >> h >> w;
	cout << H * W - H * w - W * h + w * h << '\n';


	return 0;
}


Measured memory_bytes: 888
w,h,n=map(int,input().split())
max_x,min_x,max_y,min_y=w,0,h,0
for i in range(n):
  x,y,a=map(int,input().split())
  if a==1:
    min_x=max(min_x,x)
  elif a==2:
    max_x=min(max_x,x)
  elif a==3:
    min_y=max(min_y,y)
  elif a==4:
    max_y=min(max_y,y)
print(max(0,max_x-min_x)*max(0,max_y-min_y))


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

struct UnionFind{
    vector<int> parent,size;
    
    UnionFind(int n): parent(n,-1),size(n,1){}
    void init(int n){ 
        parent.assign(n,-1);
        size.assign(n,1);
        return;
    }

    int root(int x){
        if (parent[x]<0) return x;
        else return parent[x] = root(parent[x]);
    }

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

    void unite(int x,int y){
        int gx = root(x);
        int gy = root(y);
        if (gx==gy) return;
        else{
            if(size[gx]<size[gy]){
                size[gy]+=size[gx];
                parent[gx]=gy;
            } else{
                size[gx]+=size[gy];
                parent[gy]=gx;
            }
        }
    }
    int get_size(int x){
        return size[root(x)];
    }    
};

int main(){
    int N,M;
    cin >> N >> M;
    vector<int> p(N);
    for(int i=0;i<N;i++){
        cin >> p[i];
        p[i] -= 1;
    }
    vector<pair<int,int> > xy(M);
    for (int i=0;i<M;i++){
        cin >> xy[i].first >> xy[i].second;
        xy[i].first -= 1;
        xy[i].second -= 1;

    }

    UnionFind UF(N);
    int res = 0;
    for (int i=0;i<M;i++){
        UF.unite(xy[i].first,xy[i].second);
    }
    for (int i=0;i<N;i++){
        if(UF.same(i,p[i])) res++;
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 2176
#include<bits/stdc++.h>
typedef long long ll;
#define rep(i, n) for(ll (i)=0 ;i <(n); ++(i))
using namespace std;
#define REP(i,m,n) for(ll (i) = (m); (i) <= (n); ++(i))
#define yorn(f) puts((f)?"Yes":"No")
#define YORN(f) puts((f)? "YES":"NO")
#define all(x) (x).begin(), (x).end()

vector<ll> divisor(ll n) {
  vector<ll> res;
  for(ll i = 1; i*i <= n; i++) {
    if(n%i == 0) {
      res.push_back(i);
      if(i*i != n) res.push_back(n/i);
    }
  }
  sort(all(res));
  return res;
}

ll gcd(ll x, ll y) {
  if(x%y == 0) return y; 
  return gcd(y, x%y);
}

ll lcm(ll x, ll y) {
  return x*y/gcd(x, y);
}

vector<ll> digitNumber(ll x) {
  vector<ll> res;
  while(x) {
    res.push_back(x%10);
    x /= 10;
  }
  return res;
}

ll numberOfDigit(ll x) {
  ll res;
  while(x) {
    x /= 10;
    res++;
  }
  return res;
}

int main() {
  char c;
  cin >> c;
  cout << (char)(c+1) << endl;
  return 0;
}

Measured memory_bytes: 256
using System;

namespace ConsoleApp8
{
    class Program
    {
        static void Main(string[] args)
        {
			string s = Console.ReadLine();

			if(s.Substring(s.Length-1, 1) == "s")
            {
				Console.WriteLine(s + "es");
			}
			else
            {
				Console.WriteLine(s + "s");
			}
		}
	}
}


Measured memory_bytes: 25712
// "include" {{{
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <deque>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <cstring>
#include <iomanip>
#include <tuple>
// }}}
using namespace std;
#define rep(i,n) for(int i=0;i<(n);++i)
#define reps(i,n) for(int i=1;i<=(n);++i)
#define all(x) (x).begin(),(x).end()
#define pii pair<int,int> 
#define int long long
#define setout(n,x) setw(n) << setfill(x)
const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
const long long mod = 1000000007;

signed main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	double r,x;
	cin >> r >> x;
	cout << fixed <<r / x << '\n';
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
        int h,w;
        while(1){
            scanf("%d %d",&h,&w);
                if(h==0) break;
            for(int i=0;i<h;i++){
                    for(int j=0;j<w;j++){
                            printf("#");
                    }
                    printf("\n");
            }
                printf("\n");
        }
        return 0;
}

Measured memory_bytes: 1152
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<set>
#include<map>
#include<queue>
#include<cassert>
#define PB push_back
#define MP make_pair
#define sz(v) (in((v).size()))
#define forn(i,n) for(in i=0;i<(n);++i)
#define forv(i,v) forn(i,sz(v))
#define fors(i,s) for(auto i=(s).begin();i!=(s).end();++i)
#define all(v) (v).begin(),(v).end()
using namespace std;
typedef long long in;
typedef vector<in> VI;
typedef vector<VI> VVI;
int main(){
  ios::sync_with_stdio(0);
  cin.tie(0);
  in s,o,l,r,jnk;
  cin>>s>>o>>jnk>>l>>r>>jnk>>jnk;
  in sm=0;
  in c1=0;
  in c2=0;
  c1=l/2*4+r/2*4+s/2*4;
  if(s && l && r){
    c2=6;
    --s;
    --l;
    --r;
    c2+=l/2*4+r/2*4+s/2*4;
  }
  sm=max(c1,c2);
  sm+=2*o;
  cout<<sm/2<<endl;
  return 0;
}


Measured memory_bytes: 256
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"
#include "cassert"
#include "ctime"

using namespace std;

constexpr long long int MOD = 1000000007;
//constexpr int MOD = 1000000007;
//constexpr int MOD = 998244353;
//constexpr long long int MOD = 998244353;
constexpr double EPS = 1e-12;

//int N, M, K, T, H, W, L, R;
long long int N, M, K, T, H, W, L, R;

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

	while (cin >> T, T) {
		vector<int>v(T);
		for (auto &i:v)cin >> i;
		cin >> N;
		vector<int>w(101, 24);
		while (N--) {
			cin >> L >> R;
			w[L] = min(w[L],(int)R);
		}
		vector<vector<int>>dp(101, vector<int>(T, MOD));
		dp[0][0] = 0;
		for (int i = 0; i < 100; i++) {
			for (int j = 0; j < T; j++) {
				dp[i + 1][1] = min(dp[i + 1][1], dp[i][j] + 1);
				if (w[i + 1] >= v[j]) {
					dp[i + 1][(j + 1) % T] = min(dp[i + 1][(j + 1) % T], dp[i][j]);
				}
			}
		}
		cout << *min_element(dp.back().begin(), dp.back().end()) << endl;
	}
}


Measured memory_bytes: 3108
def main():
    X, N = map(int, input().split())
    P = set(map(int, input().split()))

    d = 1 << 30
    ans = -1
    for v in (0, 101):
        diff = abs(X - v)
        if d > diff or (d == diff and ans > v):
            d = diff
            ans = v

    for v in range(101):
        if v in P: continue
        diff = abs(X - v)
        if d > diff or (d == diff and ans > v):
            d = diff
            ans = v

    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 9148
#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 n;
  cin >> n;
  vector<int> a(n);
  rep(i,n) cin >> a[i];
  set<int> s;
  rep(i,n) s.insert(a[i]);
  if (s.size() == n) cout << "YES" << endl;
  else cout << "NO" << endl;
  return 0;
}

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


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

  int n;
  cin >> n;
  vector<ll> a(n),b(n);

  rep(i,n) {
    cin >> a[i] >> b[i];
  }
  if(n%2==1){
  ll lb = 0;
  ll ub = 3e9;

  while(ub-lb>1){
    ll mid = (ub+lb)/2;
    int cnt=0;
    rep(i,n){
      if(a[i]<=mid) cnt++;
    }
    if(cnt>=(n+1)/2){
      ub = mid;
    }
    else{
      lb = mid;
    }
  }  
  ll ue = ub;
  lb =0;
  ub = 3e9;

  while(ub-lb>1){
    ll mid = (ub+lb)/2;
    int cnt=0;
    rep(i,n){
      if(b[i]>=mid) cnt++;
    }
    if(cnt>=(n+1)/2){
      lb = mid;
    }
    else{
      ub = mid;
    }
  }
  ll sita = lb;
  // if(n%2==0){
  //   int cnt =0;
  //   ll ans =0;
  //   rep(i,n){
  //     if(a[i] <= ue) cnt++;
  //   }
  //   if(cnt==n/2) ans--;
  //   cnt =0;
  //   rep(i,n){
  //     if(b[i] >= sita) cnt++;
  //   }
  //   if(cnt==n/2) ans--;
  //   ans += (sita - ue)*2+1;
  //   // cout << sita << " " << ue << endl;
  //   cout << ans << endl;
  // }
  // else{
    cout << sita - ue +1 << endl;
  }
  else{
    ll lb = 0;
    ll ub = 3e9;

  while(ub-lb>1){
    ll mid = (ub+lb)/2;
    int cnt=0;
    rep(i,n){
      if(a[i]<=mid) cnt++;
    }
    if(cnt>=n/2){
      ub = mid;
    }
    else{
      lb = mid;
    }
  }  
  ll ue = ub;
  lb =0;
  ub = 3e9;

  while(ub-lb>1){
    ll mid = (ub+lb)/2;
    int cnt=0;
    rep(i,n){
      if(a[i]<=mid) cnt++;
    }
    if(cnt>=n/2+1){
      ub = mid;
    }
    else{
      lb = mid;
    }
  }

  ll tans1 = ub+ue;//*2+1後のあたい

  lb =0;
  ub = 3e9;

  while(ub-lb>1){
    ll mid = (ub+lb)/2;
    int cnt=0;
    rep(i,n){
      if(b[i]>=mid) cnt++;
    }
    if(cnt>=n/2){
      lb = mid;
    }
    else{
      ub = mid;
    }
  }
  ll sita = lb;
  lb =0;
  ub = 3e9;

  while(ub-lb>1){
    ll mid = (ub+lb)/2;
    int cnt=0;
    rep(i,n){
      if(b[i]>=mid) cnt++;
    }
    if(cnt>=(n+2)/2){
      lb = mid;
    }
    else{
      ub = mid;
    }
  }
  ll tans2 = sita+lb;
  // cout << tans2 << " " << tans1 << endl;
  cout << tans2 - tans1 +1 << endl;

  }
  
  return 0;
    

}


Measured memory_bytes: 6368
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int length = scanner.nextInt();
		int[] array = new int[length];
		for (int i=0; i<length; i++) {
			array[i] = scanner.nextInt();
		}
		scanner.close();
		printArray(array);
		insertionSort(array, length);
		
		
	}
	
	public static void insertionSort(int[] array, int length) {
		for (int i=1; i<length; i++) {
			int key = array[i];
			int j = i - 1;
			while (j>=0 && key<array[j]) {
				array[j+1] = array[j];
				j--;
			}
			array[j+1] = key;
			
			printArray(array);
		}
	}
	
	public static void printArray(int[] array) {
		for (int i = 0; i < array.length; i++) {
			if (i>0) System.out.print(" ");
			System.out.print(array[i]);
		}
		System.out.print("\n");
	}

}



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

using namespace std;

#define all(x) (x).begin(), (x).end()

typedef long long ll;

const int N = 2e5;
vector<int> edges[N];
int n, diam;
vector<int> dst;
vector<int> d[N];

vector<int> bfs(int s) {
  dst = vector<int>(n, -1); dst[s] = 0; queue<int> q; q.push(s);
  while (!q.empty()) {
    int v = q.front(); q.pop();
    for (int u : edges[v]) {
      if (dst[u] == -1) {
        q.push(u); dst[u] = dst[v] + 1;
      }
    }
  }
  return dst;
}

void solve() {
  cin >> n >> diam;
  for (int i = 0; i < n - 1; i++) {
    int v, u; cin >> v >> u; v--, u--;
    edges[v].push_back(u); edges[u].push_back(v);
  }
  int ans = n;
  for (int v = 0; v < n; v++) {
    d[v] = bfs(v);
    int res = 0;
    for (int u = 0; u < n; u++) {
      if (d[v][u] > diam / 2)
        res++;
    }
    ans = min(ans, res);
  }
  for (int v = 0; v < n; v++) {
    for (int u : edges[v]) {
      int res = 0;
      for (int k = 0; k < n; k++) {
        if (min(d[v][k], d[u][k]) > (diam - 1) / 2)
          res++;
      }
      ans = min(ans, res);
    }
  }
  cout << ans;
}

// CHECK LIMITS (n <= 10^5)
// CHECK CORNER CASES (n == 1)

int main() {
  ios::sync_with_stdio(NULL), cin.tie(0), cout.tie(0);
  cout.setf(ios::fixed), cout.precision(20);
  //cout << 1.0 * clock() / CLOCKS_PER_SEC << endl;
  solve();
}


Measured memory_bytes: 28252
#include <bits/stdc++.h>
#define X first
#define Y second
#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()
#define ini(x, y) memset(x, y, sizeof(x))
#define endl '\n'
#define fastio cin.sync_with_stdio(false); cin.tie(nullptr)
using namespace std;

using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
const int MOD = 1e9 + 7;
const int dx[] = { -1, 0, 1, 0, -1, 1, 1, -1 };
const int dy[] = { 0, 1, 0, -1, 1, 1, -1, -1 };

ll fexp(ll n, ll r) {
	ll ret = 1;
	for (; r; r >>= 1) {
		if (r & 1) ret = ret * n % MOD;
		n = n * n % MOD;
	}
	return ret;
}
int main() {
	fastio;
	int N, K;
	cin >> N >> K;

	ll ans = fexp(K, N);
	int cnt[100001]; fill(cnt, cnt + 100001, 1);

	for (int i = 2; i <= K; ++i) {
		int dif = i - cnt[i];
		ans = (ans + dif * fexp(K / i, N)) % MOD;
		for (int j = i; j <= K; j += i) cnt[j] += dif;
	}

	cout << ans;

	return 0;
}


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

int main() {
    int n;
    string s;
    cin >> n >> s;
    int len = s.length();
    
    while(n--) {
        for(int i = 0; i < len; i++) {
            if(s[i] == 'Z') s[i] = 'A';
            else s[i]++;
        }
    }

    cout << s << endl;

    return 0;
}

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


vector<int> a[500];

int n;
int bin_left(vector<int>& a,int pos)
{
	int l=0;
	int r=a.size()-1;
	int ans=-1;
	if(a[0]<=pos) ans=a[0];
	return ans;
}

int bin_right(vector<int>& a,int pos)
{
	int l=0;
	int r=a.size()-1;
	int ans=-1;
	while(l<=r){
		int mid=(l+r)>>1;
		if(a[mid]>=pos)
		{
			ans=a[mid];
			r=mid-1;
		}else
		{
			l=mid+1;
		}
	}
	return ans;
}

int  main()
{
	string s;
	string t;
	cin>>s>>t;
	n=s.size();
	for(int i=0;i<s.size();i++)
	{
		a[s[i]].pb(i);
	}
	int pos=0;
	long long ans=0;
	for(int i=0;i<t.size();i++)
	{
		char temp=t[i];
		if(a[temp].size()==0)
		{
			puts("-1");
			return 0;
		}
		int right=bin_right(a[temp],pos);
		if(right!=-1)
		{
			ans+=(long long)right-pos+1;
			pos=right+1;
			if(pos==n) pos=0;
		}else
		{
			int left=bin_left(a[temp],pos-1);
			ans+=(long long)(n-pos)+left+1;
			pos=left+1;
			if(pos==n) pos=0;
		}
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 1216
# -*- coding: utf-8 -*-

n, k = map(int,input().split())

odd = n // k
even1 = n // k
even2 = (n + int(k/2)) // k

if k % 2 == 0:
    print(even1 ** 3 + even2 ** 3)
else:
    print(odd ** 3)


Measured memory_bytes: 3064
#include<iostream>
#include<vector>
#include<string>
#include<cmath>
#include<algorithm>
#include <numeric>
 
using namespace std;
using ll=long long;
#define rep(i,n) for(int i=0;i<n;i++)
#define ALL(a) (a).begin(),(a).end()

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

int main(){
    int n;
    cin >> n;
    vector<ll> a(n);
    rep(i, n){
        scanf("%lld", &a[i]);
    }
    
    ll ans = 0;
    rep(i, n)ans += a[i]-1;
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
long n,c,k,ans,t[100001],la,nw,s,i;
main(){
  cin>>n>>c>>k;
  for(i=1;i<=n;i++)cin>>t[i];
  sort(t+1,t+1+n);
  while(nw<n){
    nw++;la=t[nw]+k;s=c-1;
    while(t[nw+1]<=la&&s>0&&nw<n){s--;nw++;}
    ans++;
  }
  cout<<ans;
}


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

int main(){
  int n;cin>>n;
  int a,w,t,r;
  a=w=t=r=0;
  
  for(int i=0;i<n;i++){
    string x;cin>>x;
    if(x=="AC")a++;
    else if(x=="WA")w++;
    else if(x=="TLE")t++;
    else if(x=="RE")r++;
  }
  cout<<"AC x "<<a<<endl;
  cout<<"WA x "<<w<<endl;
  cout<<"TLE x "<<t<<endl;
  cout<<"RE x "<<r<<endl;
}


Measured memory_bytes: 3620
#include<iostream>
using namespace std;
int main(){
	int H, W;
	while (1){
		cin >> H >> W;
		if (H == 0 && W == 0)break;
		for (int i = 0; i < H; i++){
			for (int j = 0; j < W; j++){

				cout << "#";
			}
			cout << endl;
		}
		cout << endl;
	}
		return 0;
	}

Measured memory_bytes: 3092
import sys
import itertools


def main():
    N = int(input())
    songs = []
    time = []
    for _ in range(N):
        s, t = input().split()
        t = int(t)
        songs.append(s)
        time.append(t)
    X = input()
    time = list(itertools.accumulate(time))
    ans = time[-1] - time[songs.index(X)]
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 9044
package main

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

var sc = bufio.NewScanner(os.Stdin)
var out = bufio.NewWriter(os.Stdout)

func next() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	a, _ := strconv.Atoi(next())
	return a
}

func main() {
	buf := make([]byte, 1024*1024)
	sc.Buffer(buf, bufio.MaxScanTokenSize)
	sc.Split(bufio.ScanWords)
	defer out.Flush()

	N, K := nextInt(), nextInt()
	C := make([]int, K)

	for i := 0; i < K; i++ {
		C[i] = nextInt()
	}

	var a_in, a_out int
	for i := K; i < N; i++ {
		a_in = nextInt()
		a_out = C[i%K]
		if a_in > a_out {
			fmt.Fprintln(out, "Yes")
		} else {
			fmt.Fprintln(out, "No")
		}
		C[i%K] = a_in
	}
}


Measured memory_bytes: 6440
#include <bits/stdc++.h>
using namespace std;
int n,a[110];
int main(){
	cin>>n;
	for(int i = 0; i < n; i ++)cin>>a[i];
	sort(a,a+n);
	cout << a[n-1] - a[0] << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, e) for(int (i) = 0; (i) < (e); ++(i))
#define FOR(i, b, e) for(int (i) = (b); (i) < (e); ++(i))
#define ALL(c) (c).begin(), (c).end()
#define PRINT(x) cout << (x) << "\n"
using namespace std;
using ll = long long; using pint = pair<int, int>; using pll = pair<ll, ll>;
template<typename T> auto compare = [](T x, T y) -> bool{return (x < y);};
const int MOD = 1000000007;

signed main(){
    set<string> st;
    int N;
    string S;
    cin >> N;
    REP(i, N){
        cin >> S;
        st.insert(S);
    }
    PRINT(st.size());
    return 0;
}

Measured memory_bytes: 19060
#![allow(unused_macros)]
#![allow(dead_code)]
#![allow(unused_imports)]

use text_io::*;
use proconio::*;
use itertools::Itertools;

const U_INF: usize = 1 << 60;
const I_INF: isize = 1 << 60;

fn main() {
    let n: usize = read!();
    let h: usize = read!();
    let w: usize = read!();
    
    println!("{}", (n - h + 1) * (n - w + 1));
}

Measured memory_bytes: 2108
def main():
    import sys
    sys.setrecursionlimit(10**9)
    input = sys.stdin.readline

    N = int(input())
    A = []
    B = []
    for _ in [0]*N:
        a, b = map(int ,input().split())
        A.append(a)
        B.append(b)
    A.sort()
    B.sort()

    if N % 2 == 0:
        median_min = (A[N//2 - 1] + A[N//2])
        median_max = (B[N//2 - 1] + B[N//2])
    else:
        median_min = A[N//2]
        median_max = B[N//2]
    print(median_max - median_min + 1)
    
main()

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

#define fast ios::sync_with_stdio(false);cin.tie(0); cout.tie(0)

typedef long long ll;
typedef long double ld;
const ll inf = (ll)1e14;
const ll N = (ll)1e6;

ll arr[6];
ld ret;
ll sol,sugar;

int main() {
    fast;
    for (int i = 0; i < 6; i++) cin >> arr[i];

    arr[0] = 100 * arr[0];
    arr[1] = 100 * arr[1];

    for (ll i = 0; i * arr[0] <= arr[5]; i++) {

        for (ll j = 0; i * arr[0] + j * arr[1] <= arr[5]; j++) {

            ll water = i * arr[0] + j * arr[1];

            for (ll p = 0; p * arr[2] * 100 <= arr[4] * water and (p * arr[2] + water) <= arr[5]; p++) {

                for (ll q = 0; (p * arr[2] + q * arr[3]) * 100 <= arr[4] * water and
                               (p * arr[2] + q * arr[3] + water) <= arr[5]; q++) {

                    ll sug = p * arr[2] + q * arr[3];

                    if (ret < ld(sug) * 100 / (water + sug)) {
                        ret = ld(sug) * 100 / (water + sug);
                        sol = water + sug;
                        sugar = sug;
                    }

                }

            }
        }
    }

    if (!sol) sol = arr[0];
    cout << sol << " " << sugar << endl;
    return 0;
}

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


int main() {
  long long n ;
  cin >> n ;
  
  vector < long long > vec(n);
  long long sum = 0;
  for(long long i = 0 ; i < n ; i++ ){
    cin >> vec.at(i) ;
    sum += vec.at(i);
  }
  
  sort(vec.begin(),vec.end());
  
  cout << vec.at(0) << " "  ;
  
  reverse(vec.begin(),vec.end());
  
  cout << vec.at(0) << " "  ;
  
  cout << sum << endl;
}


Measured memory_bytes: 3176
#include <iostream>
#include <vector>
#include <cmath>
#include <queue>
#include <deque>
#include <set>
#include <string>
#include <map>
#include <algorithm>
#include <stack>
#include <cstdlib>
#include <iomanip>
#include <ctime>
using namespace std;
using ll = long long;
using ull = unsigned long long;

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    ll d, t, s;
    cin >> d >> t >> s;
    if (s * t < d)
        cout << "No";
    else
        cout << "Yes";
    return 0;
}


Measured memory_bytes: 3692
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a; i< (int)(b); ++i)
#define ALL(x) (x).begin(),(x).end()
#define rALL(x) (x).rbegin(),(x).rend()
typedef long double ld;
using ll=long long;
using namespace std;
const auto mod=1e9+7;



int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(20);
  
  ll n; 
  cin >> n;
  vector<ll> L(n);
  rep(i,0,n) cin >> L[i] ;
  sort(ALL(L));
  ll ans=0;
  for(ll mid=n-1;mid>=0;mid--){
      for(ll low=mid-1;low>=0;low--){
         auto itr = lower_bound(ALL(L),L[mid]+L[low]);
         ll ng = distance(itr,L.end());
         ans += (n-1-mid)-ng; 
      }
  }
  cout << ans << endl;

}

Measured memory_bytes: 256
#include <algorithm>
#include <cassert>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;

#define rep(i, n) for(ll i = 0; i < n; i++)
#define REP(i, n) for(ll i = 1; i < n + 1; i++)
#define PI 3.14159265359
#define EPS 0.0000000001
#define MOD 1000000007
//cout << std::fixed << std::setprecision(15) << y << endl;


int main(){
    ll H, W;
    cin >> H >> W;

    char s[H + 2][W + 2];
    char S;
    rep(i, H + 2){
        rep(j, W + 2){
            s[i][j] = '.';
        }
    }
    REP(i, H){
        REP(j, W){
            cin >> S;
            s[i][j] = S;
        }
    }

    bool ifNo = false;
    REP(i, H){
        REP(j, W){
            if(s[i][j] == '#'){
                if(s[i - 1][j] == '.' && s[i][j - 1] == '.' && s[i][j + 1] == '.' && s[i + 1][j] == '.'){
                    ifNo = true;
                    break;
                }
            }
        }
        if(ifNo){
            break;
        }
    }

    if(ifNo){
        cout << "No" << endl;
    }else{
        cout << "Yes" << endl;
    }

    return 0;
}

Measured memory_bytes: 3648
public class Hello{
    public static void Main(){
        // Your code here!
        var line = System.Console.ReadLine().Split(' ');
        int N = int.Parse(line[0]);
        int X = int.Parse(line[1]);
        int T = int.Parse(line[2]);
        
        if (N % X != 0)
        {
            System.Console.WriteLine((N / X + 1) * T);
        }
        else
        {
            System.Console.WriteLine((N / X) * T);
        }
    }
}


Measured memory_bytes: 27164
import sys
input = lambda : sys.stdin.readline().rstrip()

n, m = map(int, input().split())

#Union Find

#xの根を求める
def find(x):
    if par[x] < 0:
        return x
    else:
        par[x] = find(par[x])
        return par[x]
#xとyの属する集合の併合
def unite(x,y):
    x = find(x)
    y = find(y)

    if x == y:
        return False
    else:
        #sizeの大きいほうがx
        if par[x] > par[y]:
            x,y = y,x
        par[x] += par[y]
        par[y] = x
        return True

#xとyが同じ集合に属するかの判定
def same(x,y):
    return find(x) == find(y)

#xが属する集合の個数
def size(x):
    return -par[find(x)]

#初期化
#根なら-size,子なら親の頂点
par = [-1]*n

for _ in range(m):
    x, y, z = map(int, input().split())
    unite(x - 1, y - 1)

ans = 0

for i in range(n):
    if find(i) == i:
        ans += 1

print(ans)

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

int main()
{
	int n,k;
	cin >> n >> k;
	vector<int> v(n);
	for(int i = 0;i<n;i++)cin >> v[i];
	sort(v.begin(),v.end());

	int ans = INT_MAX;
	for(int i = 0;i<n-k+1;i++)
	{
		ans = min(v[i+k-1]-v[i],ans);
	}
	cout<<ans<<endl;
}

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

void print(bitset<20> b) {
	for (int i = 0; i < 20; i++) {
		if (b.test(i)) {
			cout << " " << i;
		}
	}
}

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

	bitset<20> b1, b2;

	int n; cin >> n;
	int max = 1 << n;
	int k; cin >> k;
	for (int i = 0; i < k; i++) {
		int x; cin >> x;
		b1.set(x);
	}
	for (int i = 0; i < max; i++) {
		b2 = i;
		if ((b2 | b1) == b2) {
			cout << i << ":";
			print(b2);
			cout << endl;
		}
	}
}


Measured memory_bytes: 3216
import itertools
n,m,q=map(int,input().split())
a=[]
for _ in range(q):
  b=list(map(int,input().split()))
  a.append(b)
  
g=list(range(1,m+1))
c=[]
for v in itertools.combinations_with_replacement(g,n):
  c.append(v)
  
ans1=[]
ans=0
for x in range(len(c)):
  d=c[x]
  ans1=0
  for r in range(q):
    a1=a[r][0]-1
    b1=a[r][1]-1
    c1=a[r][2]
    d1=a[r][3]
    if d[b1]-d[a1]==c1:
      ans1+=d1
      
  ans=max(ans,ans1)
  
print(ans)
    
    




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

int main() {  
 long int N;
  cin >>N;
 long int we,they;
 for(long int i=sqrt(N);i>=1;i--){
 if(N%i==0){we=i;they=N/i;break;}
 }
  cout <<we +they -2 <<endl;
}

Measured memory_bytes: 256
n=int(input())
s=input()

def solve():
    right_E=0
    right_W=0
    left_E=0
    left_W=0
    ans=10**7

    for i in range(0,len(s)):
        if s[i]=="E":
            right_E+=1
        else:
            right_W+=1
    
    for i in range(0,len(s)):
        if s[i]=="E":
            right_E-=1
            cnt=left_W+right_E
            ans=min(ans,cnt)
            left_E+=1
        else:
            right_W-=1
            cnt=left_W+right_E
            ans=min(ans,cnt)
            left_W+=1
    
    print(ans)
    
if __name__ == "__main__":
    solve()

Measured memory_bytes: 9708
#include<iostream>
using namespace std;
#include<cstdio>       // k-D_tree. (k = 2)
#include<algorithm>

class Point
{
public:
    int id, x, y;
    Point(){};
    Point(int no, int pos_x, int pos_y) : id(no), x(pos_x), y(pos_y) {};
    void print(){ printf("%d\n", id); }
};

bool cmp_x(const Point &P1, const Point &P2){ return P1.x < P2.x; }
bool cmp_y(const Point &P1, const Point &P2){ return P1.y < P2.y; }
bool cmp_id(const Point &P1, const Point &P2){ return P1.id < P2.id; }

class node // nodes of 2-D_tree.
{
public:
    Point *mark;
    node *less, *more;
    int depth;   // parity of depth is important.
    node() : mark(NULL), less(NULL), more(NULL), depth(0) {};
    node(Point* pos, node* l, node* m, int d) : mark(pos), less(l), more(m), depth(d) {};
};

node* make_tree(Point S[], int left, int right, int d) // recursive construction of 2-D_tree.
{
    if(left > right){ return NULL; }
    if(left == right){
        node* leaf = new node;
        *leaf = node(&S[left], NULL, NULL, d);    // arrived at leaf.
        return leaf;
    }

	if(d & 1){
        sort(S + left, S + right + 1, cmp_x);
	}else{
        sort(S + left, S + right + 1, cmp_y);
	}

    int mid = (left + right) / 2;

    node* n = new node;   // make a new node.
    n->mark = &S[mid];
    n->depth = d;
    n->less = make_tree(S, left, mid - 1, d + 1);
    n->more = make_tree(S, mid + 1, right, d + 1);

    return n;
}

int cnt;

void find(Point S[], int sx, int tx, int sy, int ty, node* kd_n)
{
    if(kd_n == NULL) return;

    if(sx <= kd_n->mark->x && kd_n->mark->x <= tx && sy <= kd_n->mark->y && kd_n->mark->y <= ty){
        S[cnt] = *(kd_n->mark);
        cnt++;
    }
    int ax = kd_n->mark->x, ay = kd_n->mark->y, d = kd_n->depth;

    if(d & 1){
        if(sx <= ax) find(S, sx, tx, sy, ty, kd_n->less);
        if(ax <= tx) find(S, sx, tx, sy, ty, kd_n->more);
    }else{
        if(sy <= ay) find(S, sx, tx, sy, ty, kd_n->less);
        if(ay <= ty) find(S, sx, tx, sy, ty, kd_n->more);
    }
}

int main()
{
    int i, pos_x, pos_y, n;
    Point P[500000], Q[100];

    scanf("%d", &n);
    for(i = 0; i < n; i++){ scanf("%d %d", &pos_x, &pos_y); P[i] = Point(i, pos_x, pos_y); }
	
    node* root;
    root = make_tree(P, 0, n - 1, 0);  // make a 2-D_tree.

    int q, sx, tx, sy, ty;
    scanf("%d", &q);
    while(q){
        cnt = 0;
        scanf("%d %d %d %d", &sx, &tx, &sy, &ty);      // input data.
        find(Q, sx, tx, sy, ty, root);   // counting.
        sort(Q, Q + cnt, cmp_id);
        for(i = 0; i < cnt; i++){ Q[i].print(); }  // print out.
        cout << endl;
        q--;
    };

    return 0;
}

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

using namespace std;

typedef long long ll;

template<class T>
inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}

template<class T>
inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}

int main(void) {
    ll A, B, K;
    cin >> A >> B >> K;

    ll taka = max(A - K, 0LL);
    ll ao = max(B - max(K - A, 0LL), 0LL);
    cout << taka << " " << ao << endl;

    return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
#include <boost/multi_array.hpp>
#include <boost/optional.hpp>
#include <boost/range/irange.hpp>
#include <boost/range/algorithm.hpp>
#include <boost/range/adaptors.hpp>
#include <boost/operators.hpp>
#include <boost/dynamic_bitset.hpp>

namespace adaptor = boost::adaptors;
using index_t = std::size_t;

void Main()
{
	int N, K;
	std::cin >> N >> K;
	std::int64_t R, S, P;
	std::cin >> R >> S >> P;
	std::string machine;
	std::cin >> machine;
	std::int64_t sum = 0;
	std::string code = "rsp";
	for (auto i : boost::irange(0, K))
	{
		std::array<std::int64_t, 3> dp = {};
		for (auto j : boost::irange(i, N, K))
		{
			std::array<std::int64_t, 3> next = {};
			next[0] = std::max(dp[1], dp[2]) + (machine[j] == code[0] ? P : 0);
			next[1] = std::max(dp[2], dp[0]) + (machine[j] == code[1] ? R : 0);
			next[2] = std::max(dp[0], dp[1]) + (machine[j] == code[2] ? S : 0);
			std::swap(next, dp);
		}
		sum += *boost::max_element(dp);
	}
	std::cout << sum << std::endl;
}

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

Measured memory_bytes: 512
import itertools

n, m ,x = map(int, input().split())
a = [list(map(int, input().split())) for i in range(n)]
ans = 10**10

for i in itertools.product([0,1], repeat=n):
    c = 0
    b = [0]*m
    for j in range(n):
        if i[j] == 1:
            c += a[j][0]
            for k in range(m):
                b[k] += a[j][k+1]
    for l in range(m):
        if b[l] < x:
            break
    else:
        ans = min(ans, c)
if ans == 10**10:
    print(-1)
else:
    print(ans)

Measured memory_bytes: 68456
#include <bits/stdc++.h>
using namespace std;
int main(){
    int n,m,ans;
    cin>>n>>m;
    vector<vector<int>> veci(n,vector<int>(m));
    vector<int> vec(m,0);
    for(int i=0;i<n;i++){
        for(int j=0;j<m;j++){
            cin>>veci.at(i).at(j);
        }
    }
    for(int i=0;i<m;i++){
        cin>>vec.at(i);
    }
    for(int i=0;i<n;i++){
        ans=0;
        for(int j=0;j<m;j++){
            ans+=veci.at(i).at(j)*vec.at(j);
        }
        cout<<ans<<endl;
    }
}


Measured memory_bytes: 3152
#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstring>

using namespace std;

#define MAX 100000
#define INF 2140000000
#define MOD 1000000007

int main() {
	string s, t, u;
	int a, b;

	cin >> s >> t;
	cin >> a >> b;
	cin >> u;

	if (s.compare(u) == 0) {
		cout << a - 1 << " " << b << endl;
	}
	else {
		cout << a << " " << b - 1 << endl;
	}

	return 0;
}

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

int main(){

  int n; cin >> n;
  vector<int> ans(n);
  rep(i,n) cin >> ans[i];
  reverse(ans.begin(), ans.end());

  rep(i,n){
    if(i == n-1){
      cout << ans[i]; 
      break;
    }
    cout << ans[i] << " ";
  }
  cout << endl;
  
  return 0;
}


Measured memory_bytes: 3080
#include <stdio.h>
#include <stdlib.h>

/* ソート関数 */
int int_sort( const void * a , const void * b ) {
  /* 引数はvoid*型と規定されているのでint型にcastする */
  if( *( int * )a < *( int * )b ) {
    return -1;
  }
  else
  if( *( int * )a == *( int * )b ) {
    return 0;
  }
  return 1;
}




int main(void){
    int a[3];
    scanf("%d %d %d",&a[0],&a[1],&a[2]);
      qsort(( void * )a , 3 , sizeof( a[0] ) , int_sort );
    int ans=0;
    while(a[2]-a[0]>1){a[0]+=2;ans++;}
    while(a[2]-a[1]>1){a[1]+=2;ans++;}
    if(a[0]==a[1]&&a[1]!=a[2])ans++;
    else if(a[0]!=a[1])ans+=2;
    printf("%d",ans);
    return 0;
}


Measured memory_bytes: 128
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
using namespace std;
vector<int> v;
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  long long a=0,b,c,d=0,e=0,f=0,g=0,i;
  string s;
  cin >>a;
  cin >>s;
  for(int n=0;n<a;n++){
    if(s[n]=='I'){
      d++;
      if(e<d) e=d;
    }
    else d--;
  }
  cout <<e<<'\n';
  return (0);
}


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

using namespace std;

using ll = long long;

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

    int n;
    cin >> n;

    vector<int> a(n);
    for (int &x: a) cin >> x;

    int ans = INT_MAX;
    for (int i = -100; i <= 100; ++i) {
        int sum = 0;
        for (int j = 0; j < n; ++j)
            sum += (a[j] - i) * (a[j] - i);
        ans = min(ans, sum);
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
#include<cstring>
using namespace std;
int main(void)
{
	int n,i,a,x,cnt;
	cnt=0;
	x=0;
	cin>>n;
	for(i=0;i<n;i++){
		cin>>a;
		if(a==1) cnt=cnt+1;
		if(x<cnt) x=cnt;
		if(a==0) cnt=0;
	}
	x=x+1;
	cout<<x<<endl;
	return 0;
}



Measured memory_bytes: 3120
N = int(input())

h = [int(i) for i in input().split()]

dp = [0] * N
dp[1] = abs(h[0] - h[1])

for x in range(2, N):
    if dp[x - 1] + abs(h[x] - h[x - 1]) < dp[x - 2] + abs(h[x] - h[x - 2]):
        dp[x] = dp[x - 1] + abs(h[x] - h[x - 1])
    else:
        dp[x] = dp[x - 2] + abs(h[x] - h[x - 2])

print(dp[N - 1])


Measured memory_bytes: 13928
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int n;
    long long int a;
    cin>>n;
    std::deque<long long int> deq;
    for (int i=0;i<n;i++) {
        cin>>a;
        deq.emplace_back(a);
    }
    std::deque<long long int> s(n+1,0);
    std::map<long long int, long long int> map;
    for (int i=0;i<n;i++) {
        s[i+1]=s[i]+deq[i];
    }
    for (int i=0;i<n+1;i++) {
        map[s[i]]++;
    }
    long long int sum=0;
    for (auto itr=map.begin();itr!=map.end();itr++) {
        sum+=(itr->second)*(itr->second-1)/2;
    }
    cout<<sum<<endl;
}

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

int main(void) {
  int N;
  bool flag = true;
  char last;
  cin >> N;
  set<string> se;
  string s;
  cin >> s;
  last = s.back();
  se.insert(s);
  for (int i = 1; i < N; i++) {
    cin >> s;
    if (flag && s.front() != last) flag = false;
    last = s.back();
    se.insert(s);
  }
  if ((int)se.size() == N && flag) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }

  return 0;
}

Measured memory_bytes: 256
#![allow(unused_imports)]

use proconio::{input, fastout};
use proconio::marker::*;
use std::mem::swap;

#[fastout]
fn main() {
    input! {
    n: u8
    }
    let mut words = vec![vec!['a']];
    for _ in 1..n {
        let mut prev = vec![];
        swap(&mut words, &mut prev);
        for w in &prev {
            let mw = w.iter().max().unwrap();
            for c in 97..=*mw as u8 + 1  {
                let mut tmp = w.clone();
                tmp.push(c as char);
                words.push(tmp);
            }
        }
    }
    let mut ans: Vec<String> = words.iter().map(|x| x.into_iter().collect::<String>()).collect();
    ans.sort();
    for i in ans {
        println!("{}", i);
    }
}


Measured memory_bytes: 20208