akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
ll data[1<<18],datb[1<<18];

void add(int a,int b,ll x,int k=0,int l=0,int r=(1<<17)){
	if(r<=a||b<=l) return;
	if(a<=l&&r<=b){
		datb[k]+=x;
		while(k){
			k=(k-1)/2;
			data[k]=max(data[k*2+1]+datb[k*2+1],data[k*2+2]+datb[k*2+2]);
		}
		return;
	}
	add(a,b,x,k*2+1,l,(l+r)/2);
	add(a,b,x,k*2+2,(l+r)/2,r);
}

int qry(int a,int b,int k=0,int l=0,int r=(1<<17)){
	if(r<=a||b<=l) return 0;
	if(a<=l&&r<=b){
		return data[k]+datb[k];
	}
	ll vl=qry(a,b,k*2+1,l,(l+r)/2);
	ll vr=qry(a,b,k*2+2,(l+r)/2,r);
	return max(vl,vr)+datb[k];
}

int main(void){
	int n,H;
	cin >> n >> H;
	priority_queue<pii> q;
	ll cur=H,ans=0;
	rep(i,n-1){
		add(i,i+1,cur);
		ll d,h;
		cin >> d >> h;
		cur-=d;
		q.push(make_pair(h,i));
		while(cur<=0){
			pii heal=q.top();q.pop();
			ll cmax=qry(heal.second,i+1);
			if(heal.first+cmax>H){
				heal.first=H-cmax;
				q.push(heal);
				continue;
			}
			ll num=min(-cur/heal.first+1,(H-cmax)/heal.first);
			ans+=num;
			cur+=heal.first*num;
			add(heal.second,i+1,num*heal.first);
			q.push(heal);
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 5516
import java.io.*;

class Main {
	public static void main(String[] args) throws Exception {
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		StringBuilder sb=new StringBuilder();
		int i=1;
		while(true){
        	String x=br.readLine();
        	if(x.equals("0")) break;
        	sb.append("Case "+i+": "+x+"\n");
    		i++;
        }
		System.out.print(sb);
	}
}

Measured memory_bytes: 27008
#include <bits/stdc++.h>
#define pii pair<int,int>
#define pb push_back
#define nmax 4005
#define inf
using namespace std;
int a[3][nmax];
int get(char c){
    if (c == 'R'){
        return 0;
    }
    if (c == 'G'){
        return 1;
    }
    return 2;
}
int oth(int a, int b){
    if (a > b){
        swap(a, b);
    }
    if (a == 0){
        if (b == 1){
            return 2;
        }
        return 1;
    }
    if (a == 1){
        if (b == 0){
            return 2;
        }
        return 0;
    }
    if (b == 1){
        return 0;
    }
    return 1;
}
char chh(int x){
    if (x == 0){
        return 'R';
    }
    if (x == 1){
        return 'G';
    }
    return 'B';
}
int main()
{
    int n;
    string s;
    cin>>n>>s;
    for (int i=n-1;i>=0;--i){
        for (int j=0;j<3;++j){
            a[j][i] = a[j][i+1];
        }
        int ind = get(s[i]);
        ++a[ind][i];
    }
    long long ans = 0;
    for (int i=0;i<n;++i){
        int ind1 = get(s[i]);
        for (int j=i+1;j<n-1;++j){
            int ind2 = get(s[j]);
            if (ind1 == ind2){
                continue;
            }
            int ot = oth(ind1, ind2);
            int add = a[ot][j+1];
            int diff = j - i;
            if (j + diff < n){
                if (chh(ot) == s[j+diff]){
                    --add;
                }
            }
            ans += add;
        }
    }
    cout<<ans<<'\n';
    return 0;
}


Measured memory_bytes: 3652
#include <iostream>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <algorithm>
#include <cstdlib>
#include <ctime>

using namespace std;
typedef long long ll;
const int mod = 998244353;
const int N = 5e5 + 100;
ll f[N], inv[N];
ll qpow(int x,int y) {
	ll res = 1;
	while (y) {
		if (y & 1) res = res * x % mod;
		x = 1ll * x * x % mod;
		y >>= 1;
	}
	return res;
}

inline ll C(const int &n,const int &m) {
	if (m == 0) return 1;
	if (m < 0) return 0;
	if (n < m) return 0;
	return f[n] * inv[m] % mod * inv[n-m] % mod;
}

void init() {
	f[0] = 1;
	for (int i = 1; i <= 500000; i++) f[i] = f[i - 1] * i % mod; inv[500000] = qpow(f[500000], mod - 2);
	for (int i = 500000 - 1; ~i; i--) inv[i] = inv[i + 1] * (i + 1) % mod;
	//for (int i = 1; i <= 10; i++) cerr << f[i] << " " ;cerr << endl;
}

int main() {
	init();
	int n, k;
	cin >> n >> k;
	ll ans = 0;
//	if (n > k) return puts("0"), 0;
	for (int i = 0; i <= k; i++) {
		int b = i, r = k - i;
		if (r < n) continue;
		if (r < b) continue;
		if (r != b)
		ans = (C(r + b, r) - C(r + b, r + r - n + 1) + ans + mod) % mod;
		else ans = (C(r + b - 1, r) - C(r + b - 1, r + r - n + 1) + ans + mod) % mod;
		//cout << C(r + b, r) << " " << C(r + b,r + r - n + 1) << endl;
		//cerr << r << " " << ans << endl;
	}
	ans = (ans + mod) % mod;
	cout << ans << endl;

}

Measured memory_bytes: 8064
N = int(input())
xy = [list(map(int, input().split())) for _ in range(N)]

def gaisin(a, b, c): #3点の外心を求める
  A = a[0] ** 2 + a[1] ** 2 - b[0] ** 2 - b[1] ** 2
  B = b[0] ** 2 + b[1] ** 2 - c[0] ** 2 - c[1] ** 2
  x = [2 * (b[0] - a[0]), 2 * (c[0] - b[0])]
  y = [2 * (b[1] - a[1]), 2 * (c[1] - b[1])]
  return renritu(x, y, [A, B])

def renritu(x, y, z): #連立方程式を解く
  k = x[1] * y[0] - x[0] * y[1]
  if k == 0: return False, 0, 0
  Cx = -(y[0] * z[1] - y[1] * z[0]) / k
  Cy = (x[0] * z[1] - x[1] * z[0]) / k
  return True, Cx, Cy

def nasu(a, b, c):
  f, Cx, Cy = gaisin(a, b, c)
  if f: return honyamorake(Cx, Cy)
  else: return 10 ** 10

def honya(x, y, Cx, Cy):
  return ((x - Cx) ** 2 + (y - Cy) ** 2) ** (1 / 2)

def honyaraka(a, b):
  Cx = (a[0] + b[0]) / 2
  Cy = (a[1] + b[1]) / 2
  return honyamorake(Cx, Cy)

def honyamorake(Cx, Cy):
  r = honya(xy[0][0], xy[0][1], Cx, Cy)
  for i in range(1, N):
    r = max(r, honya(xy[i][0], xy[i][1], Cx, Cy))
  return r

ans = 10 ** 10
for i in range(N - 2):
  for j in range(i + 1, N - 1):
    for k in range(j + 1, N):
      ans = min(ans, nasu(xy[i], xy[j], xy[k]))
for i in range(N - 1):
  for j in range(i + 1, N):
    ans = min(ans, honyaraka(xy[i], xy[j]))

print(ans)


Measured memory_bytes: 3316
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
#define pb push_back
#define all(c) (c).begin(), (c).end()
#define debug(x) cout << #x << " : " << x << endl
#define mp make_pair
#include <iostream>
#define fastinput ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);


int main()
{    
    fastinput;
    LL n,i,j,k,t,temp;
    cin>>n;
    vector<LL>v;
    for(i=0;i<n;i++)
    {
        cin>>j;
        v.pb(j);
    }

    sort(v.begin(),v.end());
    LL cnt=0;
    for(i=0;i<n-1;i++)
    {
        for(j=i+1;j<n;j++)
        {
            LL lb=j+1,ub=n-1;
            LL pos=j;
            LL search=v[i]+v[j];
            //debug(i);
            //debug(j);
            while(lb<=ub)
            {
                LL mid=(lb+ub)/2;
                if(v[mid]<search)
                {
                    pos=mid;
                    lb=mid+1;;
                }
                else
                {
                    ub=mid-1;
                }                
            }
            cnt+=pos-j;
        }
    }

    cout<<cnt<<endl;
    


    
    return 0;
}



Measured memory_bytes: 384
#include <bits/stdc++.h>
#define db(x) cerr << __LINE__ << ": " << #x << " = " << (x) << endl
#define ll long long
#define ld long double
#define pll pair<ll, ll>
#define MOD 1000000007
using namespace std;
const long long INF = 3*1e18;

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    ll N;
    cin >> N;
    ll ans = 0;
    ll a = N / 500;
    ans += (1000 * a);
    ll left = N - (a * 500);
    ll b = left / 5;
    ans += (5 * b);
    cout << ans << "\n";
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define REP(i,a,b) for(int i=(a);i<(int)(b);++i)
#define rep(i,n) REP(i,0,n)
#define dump(x)  cout << #x << " = " << (x) << endl;
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

using namespace std;
typedef long long ll;

int main() {
    int n;
    cin >> n;
    int a[n], sortedA[n];
    rep(i, n) {
        cin >> a[i];
        a[i] -= i + 1;
        sortedA[i] = a[i];
    }
    sort(sortedA, sortedA + n);
    int mid = sortedA[n / 2];
    ll ans = 0;
    rep(i, n) ans += abs(a[i] - mid);
    cout << ans << endl;
    return 0;
}




Measured memory_bytes: 1792
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#define pi 3.141592653589793238
#define int long long
using namespace __gnu_pbds;
using namespace std;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

long long power(long long a, long long b) {
    long long res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a ;
        a = a * a ;
        b >>= 1;
    }
    return res;
}
int mm[100005];

signed main()
{

ios_base::sync_with_stdio(false);
cin.tie(NULL);  
cout.tie(0);   

#ifndef ONLINE_JUDGE
    if(fopen("INPUT.txt","r"))
    {
    freopen ("INPUT.txt" , "r" , stdin);
    freopen ("OUTPUT.txt" , "w" , stdout);
    }
#endif  

    int n;
    cin>>n;
    int a[n+1];
    int tot=0;
    for(int i=1;i<=n;i++)
    {
        cin>>a[i];
        mm[a[i]]++;
        tot+=a[i];
    }
    
    int q;
    cin>>q;
    int x,y;
    while (q--)
    {
        cin>>x>>y;
        tot-=mm[x]*x;
        tot+=mm[x]*y;
        mm[y]+=mm[x];
        mm[x]=0;
        cout<<tot<<'\n';
    }
        

} 
    
 


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

#define TRACE(x) x
#define WATCH(x) TRACE(cout << #x" = " << x << endl)
#define WATCHR(a, b) TRACE(for (auto it=a; it!=b;) cout << *(it++) << " "; cout << endl)
#define WATCHC(V) TRACE({cout << #V" = "; WATCHR(V.begin(), V.end());})

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

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vb = vector<bool>;
using vs = vector<string>;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

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

    ll A, B, C;
    cin >> A >> B >> C;

    if (A % 2 == 0 || B % 2 == 0 || C % 2 == 0) {
        cout << 0 << endl;
    } else {
        cout << min({ A * B, B * C, A * C}) << endl;
    }

    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG //GCC5.4.1で配列の範囲外アクセスをエラーにする

//cmdで g++ test.cpp とするとコンパイルできる
//制限1秒なら10^6は余裕 10^7は多分間に合う 10^8はよほど単純でないと厳しい
// https://github.com/atcoder/live_library
// cppdbg: test.exeのterminalに標準入力を打てる

#define ALL(x) x.begin(),x.end()
#define get_tp(t,i) get<i>(t)
#define len(x) (ll)(x.size())
#define ub(a,x) (upper_bound(ALL(a),x)-a.begin())
#define lb(a,x) (lower_bound(ALL(a),x)-a.begin())
typedef long long ll; //long long
typedef pair<int,int> pii; //pair<int,int>
typedef pair<long long,long long> pllll; //pair<ll,ll>
typedef vector<int> vi; //vector<int>
typedef vector<vector<int>> vvi; //vector<vector<int>>
typedef vector<ll> vll; //vector<long long>
typedef vector<vector<ll>> vvll; //vector<vector<long long>>
typedef priority_queue<ll, vector<ll>, greater<ll> > gpq; //逆順priority_queue
typedef priority_queue<ll> pq;

//const int MOD=998244353;
const int MOD=1000000007; //10^9+7
const long double PI=3.1415926535897932;

int main(){
    int N;cin>>N;
    double ans=0.0;
    for(int i=0;i<N;i++){
        double x;string cur;cin>>x>>cur;
        if(cur=="JPY"){
            ans+=x;
        }else{
            ans+=380000.0*x;
        }
    }
    cout<<setprecision(18)<<ans<<endl;
}

Measured memory_bytes: 3744
// Practice AtCoder
// author: Leonardone @ NEETSDKASU

fn main() {
    let mut stdin = String::new();
    std::io::Read::read_to_string(
        &mut std::io::stdin(),
        &mut stdin).unwrap();
    let mut stdin = stdin.split_whitespace();
    let mut get = || stdin.next().unwrap();
    macro_rules! get {
        ($t:ty) => (get().parse::<$t>().unwrap());
        () => (get!(i64));
    }
    
    let mut s = get().as_bytes().to_vec();
    s.sort();
    if s[0]==s[1]&&s[1]!=s[2]&&s[2]==s[3] {
        println!("Yes");
    } else {
        println!("No");
    }
}

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

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;

typedef int _loop_int;
#define REP(i,n) for(_loop_int i=0;i<(_loop_int)(n);++i)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i)

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG2(x,y) cout<<#x<<": "<<x<<" "<<#y<<": "<<y<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define DEBUG_ARR(v,n) cout<<#v<<":";REP(i,n)cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

const ll MOD = 1000000007ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

string s,t;
int main() {
    ios::sync_with_stdio(false); cin.tie(0);
    cin>>s>>t;
    cout << t << s<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <set>

using namespace std;

int main() {
  int X;
  int N;
  cin >> X >> N;
  if (N == 0) {
    cout << X << endl;
    return 0;
  }
  set<int> nums;
  for (int n = 0; n < N; ++n) {
    int num;
	cin >> num;
    nums.insert(num);
  }
  for (int i = 0; i <= 100; ++i) {
    {
      int minus = X - i;
      if (nums.count(minus) == 0) {
        cout << minus << endl;
        return 0;
      }
    }
    {
      if (i == 0) continue;
      int plus = X + i;
      if (nums.count(plus) == 0) {
        cout << plus << endl;
        return 0;
      }
    }
  }
  return 0;
}


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

#define rep(i, a, b) for (ll i = (a); i < (b); i++)
typedef uint64_t ull;
typedef int64_t ll;
typedef pair<ll, ll> PLL;

class UnionFind {
 public:
     int n;
     std::vector<int> par;
     std::vector<int> num;

     explicit UnionFind(int n) {  // [0 n)のunion find
         this->n = n;
         this->par.resize(n);
         this->num.resize(n, 1);
         for (int i = 0; i < n; i++) {
             this->par[i] = i;
         }
     }

     int root(int i) {
         if (par[i] == i)
             return i;
         else
             return par[i] = root(par[i]);
     }

     bool same(int i, int j) {
         return root(i) == root(j);
     }

     void unite(int i, int j) {
         int t = root(i);
         int k = root(j);

         if (t == k) return;

         par[t] = k;
         num[k] += num[t];
     }

     int size(int i) {
         return num[root(i)];
     }
};

struct edge{
    ll u,v,cost;
};

struct town{
    ll id,x,y;
};

signed main() {
    ll K, N=50;
    cin>>K;

    ll t = K/N;
    vector<ll> a(N);
    rep(i,0,N){
        a[i] = (N-1) + t;
    }
    rep(i,0,K-t*N){
        rep(j,0,N) {
            if (i==j)
                a[j] += N;
            else
                a[j]--;
        }
    }

    cout<<N<<endl;
    rep(i,0,N){
        cout<<a[i];
        if (i!=N-1)
            cout<<" ";
    }
    cout<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int INF=1e18;
struct edge{
	int u,v,w;
	edge(int uu,int vv,int ww):u(uu),v(vv),w(ww){}
	edge(){}
};
int dis[2567];
vector<edge> E;
vector<int> rev[2567];
bool visit[2567];
int32_t main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	int n,m,p;cin>>n>>m>>p;
	for(int i=0;i<m;i++){
		int u,v,w;cin>>u>>v>>w;
		E.push_back(edge(u,v,-(w-p)));
		rev[v].push_back(u);
	}
	for(int i=0;i<=n;i++) dis[i]=INF;
	dis[1]=0;
	for(int i=0;i<n-1;i++){
		for(int j=0;j<m;j++){
			int u=E[j].u,v=E[j].v,w=E[j].w;
			if(dis[u]+w<dis[v] && dis[u]!=INF) dis[v]=dis[u]+w;
		}
	}
	visit[n]=true;
	queue<int> qu;qu.push(n);
	while(!qu.empty()){
		int cur=qu.front();qu.pop();
		for(int nxt:rev[cur]){
			if(visit[nxt]) continue;
			visit[nxt]=true;
			qu.push(nxt);
		}
	}
	bool flag=false;
	for(int i=0;i<m;i++){
		int u=E[i].u,v=E[i].v,w=E[i].w;
		if(visit[u] && visit[v] && dis[u]+w<dis[v] && dis[u]!=INF){
			flag=true;
			break;
		}
	}
	if(flag) cout<<-1<<endl;
	else cout<<max(0ll,-dis[n])<<endl;
	return 0;
}

Measured memory_bytes: 640
S = input()
T = input()

Skey = sorted(set(S),key=S.index)
Tkey = sorted(set(T),key=T.index)

for idx,i in enumerate(Skey):
  S = S.replace(i,str(idx))
for idx,i in enumerate(Tkey):
  T = T.replace(i,str(idx))

if S==T:
  print("Yes")
else:
  print("No")


Measured memory_bytes: 3996
#include <bits/stdc++.h>
 
#define vi vector<int>
#define ll long long
#define pb push_back
#define mp make_pair
#define endl "\n"
#define ii pair<int,int>
#define qu queue <int>
#define qmax priority_queue <int>
#define qmin priority_queue <int, vector<int>,greater<int>>

using namespace std;

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    int a, b;

    cin>>a>>b;

    if((a*b)%2 != 0)
        cout<<"Yes"<<endl;
    else
        cout<<"No"<<endl;

    return 0;
}

Measured memory_bytes: 3644
#pragma region
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <map>
#include <queue> 
#include <stack>
#include <set>
#include <list>

using namespace std;
typedef long long ll;
//#define rep(i, s, e) for (int(i) = (s); (i) < (e); ++(i))
#define rep(i, e) for (int(i) = 0; (i) < (e); ++(i))
#define all(x) x.begin(),x.end()
#pragma endregion


int main()
{
	map<char, bool> mp;
	mp['S'] = mp['E'] = mp['W'] = mp['N'] = false;
	string s; cin >> s;
	for (char x : s)mp[x] = true;
	if (mp['S'] == mp['N'] && mp['E'] == mp['W'])cout << "Yes" << endl;
	else cout << "No" << endl;
}

Measured memory_bytes: 384
#include <cassert>

#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#define rep(i,j,k) for(int i=(int)j;i<(int)k;i++)
#define ll long long
//#define all(v) ((v).begin(),(v).end())
#define Sort(v) sort(all(v))
#define INF 1000000000
#define END return 0
#define pb push_back
#define se second
#define fi first
#define pb push_back
#define all(v) (v).begin() , (v).end()
#define MP make_pair
using namespace std;
int day[12]={31,28,31,30,31,30,31,31,30,31,30,31};

int main(){
    int n;cin>>n;
    vector<ll> v(n),b(n);
    rep(i,0,n){
        cin>>v[i];
        b[i]=v[i]-i-1;
    }
    Sort(b);
    ll mid=b[n/2];
    ll ans=0;
    rep(i,0,n){
        ans+=abs(v[i]-(mid+i+1));
    }
    cout<<ans<<endl;

    return 0;
}

/*
中央値の添字：
nが奇数→n/2
nが偶数→n/2

*/



Measured memory_bytes: 3328
//==========================Head files==========================
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<vector>
#include<queue>
#include<cmath>
#include<set>
#include<iostream>
#include<map>
#define LL long long
#define db double
#define mp make_pair
#define pr pair<int, int>
#define fir first
#define sec second
#define pb push_back
#define ms(i, j) memset(i, j, sizeof i)
using namespace std;
//==========================Templates==========================
inline int read() {
    int x = 0, f = 1; char c = getchar();
    while(c < '0' || c > '9'){if (c == '-') f = -1; c = getchar();}
    while(c >= '0' && c <= '9'){x = x * 10 + c - '0'; c = getchar();}
    return x * f;
}
inline LL readl() {
    LL x = 0, f = 1; char c = getchar();
    while(c < '0' || c > '9'){if (c == '-') f = -1; c = getchar();}
    while(c >= '0' && c <= '9'){x = x * 10 + c - '0'; c = getchar();}
    return x * f;
}
int power(int a, int b) {
	int ans = 1;
	while (b) {
		if(b & 1) ans = ans * a;
		b >>= 1; a = a * a;
	}
	return ans;
}
int power_mod(int a, int b, int mod) {
	a %= mod;
	int ans = 1;
	while (b) {
		if(b & 1) ans = (ans * a) % mod;
		b >>= 1, a = (a * a) % mod;
	}
	return ans;
}
LL powerl(LL a, LL b) {
	LL ans = 1ll;
	while (b) {
		if(b & 1ll) ans = ans * a;
		b >>= 1ll;a = a * a;
	}
	return ans;
}
LL power_modl(LL a, LL b, LL mod) {
	a %= mod;
	LL ans = 1ll;
	while (b) {
		if(b & 1ll) ans = (ans * a) % mod;
		b >>= 1ll, a = (a * a) % mod;
	}
	return ans;
}
LL gcdl(LL a, LL b) {return b == 0 ? a : gcdl(b, a % b);}
LL abssl(LL a) {return a > 0 ? a : -a;}
int gcd(int a, int b) {return b == 0 ? a : gcd(b, a % b);}
int abss(int a) {return a > 0 ? a : -a;}
//==========================Main body==========================
#define LD "%I64d"
#define D "%d"
#define pt printf
#define sn scanf
#define pty printf("YES\n")
#define ptn printf("NO\n")
//==========================Code here==========================
int main() {
	LL A, B; cin >> A >> B;
	if (B == 1) printf("0\n");
	else if (A >= B) printf("1\n");
	else {
		LL ans = 1, gg = A - 1;
		while (A < B)  ++ans, A += gg;
		printf("%lld\n", ans);
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
#define faster ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
#define mp make_pair
#define mod 1000000007
#define qmod 998244353
#define endl "\n"
#define pb push_back
#define ff first
#define ss second
 
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
 
const int MOD = 1e9 + 7;
const int INF = 1e9 + 5;
const ll LINF = LLONG_MAX;

int main(){
	
	int n,a,b,pass=0,passb=0;
	cin>>n>>a>>b;
	string s;cin>>s;
	for(int i=0;i<s.length();i++){
		if(s[i]=='c') cout<<"No\n";
		if(s[i]=='a'){
			if(pass<(a+b)){
				pass++;cout<<"Yes\n";
			}
			else {
				cout<<"No\n";
			}
		}
		if(s[i]=='b'){
			if(pass<(a+b)&&passb<b){
				cout<<"Yes\n";pass++;passb++;
			}
			else{
				cout<<"No\n";
			}
		}
	}


}

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

using lint = long long;
#define rep(i, n) for(int i = 0; i < int(n); i++)
#define repu(i, a, b, s) for(int i = int(a); i < int(b); i += int(s))
#define repd(i, a, b, s) for(int i = int(a); i > int(b); i += int(s))
#define endl "\n"
constexpr lint INF = 2e18;
constexpr lint MOD = 1e9 + 7;

void solve() {
    lint N;
    cin >> N;

    vector<lint> h(N);
    for(auto &&it : h) {
        cin >> it;
    }

    vector<lint> dp(N, INF);
    dp[0] = 0;

    rep(i, N - 1) {
        dp[i + 1] = min(dp[i + 1], dp[i] + abs(h[i + 1] - h[i]));
        if(i + 2 < N)
            dp[i + 2] = min(dp[i + 2], dp[i] + abs(h[i + 2] - h[i]));
    }

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

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

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

int main() {
    int n;
    cin >> n;

    string t[] = {"AC", "WA", "TLE", "RE"};
    int cnt[4] = {0};
    rep(i, n) {
        string s;
        cin >> s;
        rep(j, 4) {
            if (s == t[j])
                cnt[j]++;
        }
    }

    rep(i, 4) {
        cout << t[i] << " x " << cnt[i] << endl;
    }

    return 0;
}


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

char M[4] = {'U', 'R', 'D', 'L'};

void func(int d, int index){
    for(int i=0; i<d; ++i) cout << M[index];
}
signed main(){
    int sx, sy, tx, ty;
    cin >> sx >> sy >> tx >> ty;
    int dx = tx - sx;
    int dy = ty - sy;
    func(dy, 0);
    func(dx, 1);
    func(dy, 2);
    func(dx+1, 3);
    func(dy+1, 0);
    func(dx+1, 1);
    func(1, 2);
    func(1, 1);
    func(dy+1, 2);
    func(dx+1, 3);
    func(1, 0);
    cout << endl;
    return 0;
}

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

typedef long long int ll;



int h, w, d;
char c[512][512];
int main(void){
	cin >> h >> w >> d;
	for(int i=0;i<h;i++){
		for(int j=0;j<w;j++){
			int b1 = (i+j)/d%2;
			int b2 = (i-j+w)/d%2;
			c[i][j] = "RYGB"[b1*2+b2];
			cout << c[i][j];
		}
		cout << endl;
	}


	return 0;
}


Measured memory_bytes: 768
from heapq import heappop,heappush
n,m=map(int,input().split())
L=[[] for _ in range(m)]
for _ in range(n):
  a,b=map(int,input().split())
  if a<=m:
    L[m-a].append(b)
s=0
h=[]
for i in range(m-1,-1,-1):
  for l in L[i][::-1]:
    heappush(h,-l)
  if len(h)>0:
    s-=heappop(h)
print(s)


Measured memory_bytes: 18584
#include<iostream>
#include <string>
#include <vector>

using namespace std;

int main(){
  int n;
  int p[100];
  cin >> n;
  for(int i=0;i<n;i++) cin >> p[i];
  int count=0;
  for(int i=1;i<n-1;i++){
    if(p[i]<p[i+1] && p[i-1]<=p[i]) count++;
    else if(p[i]<p[i-1] && p[i+1]<=p[i]) count++;
  }
  cout << count << endl;

}


Measured memory_bytes: 256
N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

a, b = [0], [0]
for i in range(N):
    a.append(a[i] + A[i])
for i in range(M):
    b.append(b[i] + B[i])
    
ans, j = 0, M

for i in range(N + 1):
    if a[i] > K:
        break
    while b[j] > K - a[i]:
        j -= 1
    ans = max(ans, i + j)
    
print(ans)

Measured memory_bytes: 47452
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
int compare_int(const void *a, const void *b){
    return *(int*)a - *(int*)b;
}
int main(){
   int n,f,s;
  scanf("%d",&n);
  f=n/10;
  s=f%10;
  if(n/100==7||n%10==7||s==7) printf("Yes");
  else printf("No");
  
  return 0;
}


Measured memory_bytes: 1732
N,K=map(int,input().split())
A=[0]+list(map(int,input().split()))+[0]
p=50

if K<=p:    
    for i in range(K):
        B=[0]+[0]*N+[0]
        for j in range(1,N+1):
            left  = max(0,j-A[j])
            right = min(N+1,j+A[j]+1)
            B[left]  += 1
            B[right] -= 1
        A[0]=B[0]
        for k in range(1,N+1):
            A[k]=A[k-1]+B[k]
else:
    A=[N]*(N+2)
print(*A[1:N+1])

Measured memory_bytes: 169436
import heapq
import math
N,M=[int(x) for x in input().split()]
a = [-int(x) for x in input().split()]
heapq.heapify(a)
for i in range(M):
    aa = heapq.heappop(a)
    aa = math.ceil(aa/2)
    heapq.heappush(a,aa)
print(-sum(a))


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


int main(){
  int a,b,c,d,e,f;
  cin >> a >> b>> c>> d>> e>> f;
  int amax=f/(a*100)+1;
  int bmax=f/(b*100)+1;
  int cmax=f/c+1;
  int dmax=f/d+1;
  double pmax=0;
  int aw=a*100;
  int asu=0;
  rep(ai,amax){
    rep(bi,bmax){
      int w=100*ai*a+100*bi*b;
      //      cout << w << endl;
      if(w>f) break;
      rep(ci,cmax){
	int su=ci*c;
	if(su+w>f) break;
	if(w*e < su*100) break;
	//	if(((double)e) < 100.*((double)su)/((double)(w))) break;
	rep(di,dmax){
	  su =ci*c+di*d;
	  //	  cout << "s " << su << endl;
	  if(su+w>f) break;
	  if(w*e < su*100) break;
	  if(pmax < ((double)su)/((double)(w+su)) ){
	    pmax= ((double)su)/((double)(w+su));
	    aw=w;
	    asu=su;
	  }
	}
      }
    }
  }

  cout << aw+asu << " " << asu << endl;


  
  return 0;

}


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

int main(){
  string s;
  string t;
  cin >> s;
  cin >> t;
  if(s.size()+1!=t.size()){
    cout << "No" <<endl;
    return 0;
  }
  for(int i=0;i<s.size();i++){
    if(s[i]==t[i]){
      continue;
    }
    else{
      cout <<"No" << endl;
      return 0;
    }
  }

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


Measured memory_bytes: 3596
#include <bits/stdc++.h>
using namespace std;
//#include <ext/pb_ds/assoc_container.hpp>
//using namespace __gnu_pbds;
//typedef tree <int,null_type,less <int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
// #include <ext/rope>
// using namespace __gnu_cxx;
typedef long long int ll;
typedef long double ld;
#define FAST ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define rep(g, i, n) for (ll g = i; g < n; g++)
#define rev(g, n, i) for (ll g = n - 1; g >= i; g--)
#define all(v) v.begin(), v.end()
#define pb push_back
#define mxe(v) *max_element(v.begin(),v.end())
#define mne(v) *min_element(v.begin(),v.end())
#define ve vector
#define lb lower_bound
#define ub upper_bound
#define bb break
#define cc continue
#define rem 1000000007
#define PI 3.141592653589793238462643383279502
ll power(ll x, ll y, ll p) 
{ 
    ll res = 1;      // Initialize result 
    x = x % p;  // Update x if it is more than or 
    while (y > 0) 
    { 
        if (y & 1) 
            res = (res*x) % p; 
        y = y>>1; // y = y/2 
        x = (x*x) % p; 
    } 
    return res; 
} 
ll modInverse(ll n, ll p) 
{ 
    return power(n, p-2, p); 
} 
struct point
{
    ll x,y;
};
int main()
{
    FAST
    // freopen("input1.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    /*ll tests;
    cin>>tests;
    rep (gg,0,tests)
    {}*/
    ll n,k;
    cin>>n>>k;
    ve <ll> snack(n+1,0);
    rep (i,0,k)
    {
        ll d;
        cin>>d;
        rep (j,0,d)
        {
            ll x;
            cin>>x;
            snack[x]++;
        }
    }
    ll ans=0;
    rep (i,1,n+1) 
    {
        if (snack[i]==0)
        {
            ans++;
        }
    }
    cout<<ans<<"\n";

}


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

using namespace std;

using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using vvvll = vector<vector<vector<ll>>>;
using vvvvll = vector<vector<vector<vector<ll>>>>;
using pl4 = pair<ll,ll>;
using str = string;
using vpl4 = vector<pair<ll,ll>>;

#define sz size()
#define be begin()
#define en end()
#define fi first
#define se second
#define pb push_back
#define mp make_pair

#define llin(x) ll(x);cin >> (x);
#define stin(x) str(x);cin >> (x);
#define vllin(x,n) vll(x)(n);FOR(i,0,n-1){cin >> (x)[i];}
#define vllin2(a,b,n) vll(a)(n);vll(b)(n);FOR(i,0,n-1){cin >> (a)[i] >> (b)[i];}
#define vllin3(a,b,c,n) vll(a)(n);vll(b)(n);vll(c)(n);FOR(i,0,n-1){cin >> (a)[i] >> (b)[i] >> (c)[i];}
#define vlling(x,n) (x).assign(n,0);FOR(i,0,n-1){cin >> (x)[i];}
#define vlling2(a,b,n) (a).assign(n,0);(b).assign(n,0);FOR(i,0,n-1){cin >> (a)[i] >> (b)[i];}
#define vlling3(a,b,c,n) (a).assign(n,0);(b).assign(n,0);(c).assign(n,0);FOR(i,0,n-1){cin >> (a)[i] >> (b)[i] >> (c)[i];}
#define vpl4in(x,n) vpl4(x)((n),mp(0,0));FOR(i,0,n-1){cin >> x[i].fi >> x[i].se;}
#define FOR(i,a,b) for(ll i=a;i<=b;i++)
#define rFOR(i,b,a) for(ll i=a;i>=b;i--)
#define SORT(x) sort(x.be,x.en)
#define rSORT(x) sort(x.rbegin(),x.rend())
#define say(x) cout << (x);
#define sal(x) cout << (x) << endl;
#define says(x) cout << (x) << (' ');
#define sas cout << (' ');
#define sayR(x) cout << fixed << setprecision(10) << (x);
#define salR(x) cout << fixed << setprecision(10) << (x) << endl;
#define yn(a) cout << ((a) ? "yes" : "no") << endl;
#define Yn(a) cout << ((a) ? "Yes" : "No") << endl;
#define YN(a) cout << ((a) ? "YES" : "NO") << endl;
#define Imp(a) cout << ((a) ? "Possible" : "Impossible") << endl;
#define IMP(a) cout << ((a) ? "POSSIBLE" : "IMPOSSIBLE") << endl;

ll MOD = 1000000007;

signed main()
{
    llin(q);
    ll t,a,b;
    priority_queue<ll,vector<ll>,greater<ll>> g;
    priority_queue<ll> l;
    l.push(-1000000001);
    g.push(1000000001);
    ll bs=0,ls=0,gs=0;
    FOR(qq,0,q-1){
        cin >>t;
        if(t==1){
            cin >>a>>b;
            bs+=b;
            if(g.top()>a){
                l.push(a);
                ls+=a;
            }else{
                g.push(a);
                gs+=a;
            }
            if(l.sz>g.sz+1){
                g.push(l.top());
                ls-=l.top();
                gs+=l.top();
                l.pop();
            }
            if(l.sz<g.sz){
                l.push(g.top());
                ls+=g.top();
                gs-=g.top();
                g.pop();
            }
        }else{
            says(l.top())
            sal(bs+gs-ls+(l.sz>g.sz?l.top():0))
        }
    }    
}

Measured memory_bytes: 3828
n = input().split()
s = []
for i in range(len(n)):
    if n[i] == "+":
        a = s.pop()
        b = s.pop()
        s.append(b + a)
    elif n[i] == "-":
        a = s.pop()
        b = s.pop()
        s.append(b - a)
    elif n[i] == "*":
        a = s.pop()
        b = s.pop()
        s.append(b * a)
    else:
        s.append(int(n[i]))
print(s.pop())


Measured memory_bytes: 5604
require 'pp'
$DEBUG ? define_method(:dpp){|e|pp e} : define_method(:dpp){|e|}

# 入力値を数値で返却する
def gets_i()
  gets.chomp.to_i
end

# 空白区切の入力値を数値の配列で返却する
def gets_i_list()
  gets.chomp.split(" ").map(&:to_i)
end
n = gets_i
a_list = gets_i_list
axor = a_list.inject(&:^)

ans = []

0.upto(n-1) do |i|
  ans.push(axor ^ a_list[i])
end

puts ans.join(" ")

Measured memory_bytes: 39624
#include <stdio.h>

int main (void)

{

int a,b;

scanf("%d %d",&a,&b);

if(a<b)

{

printf("a < b\n");

}

if(a>b)

{

printf("a > b\n");

}

if(a==b)

{

printf("a == b\n");

}

return 0;

}

Measured memory_bytes: 580
str = gets.chomp
key = gets.chomp
 
 
isExist = false
idx = 0
(str.length - key.length + 1).downto(0) do |i|
    key.length.times do |j|
        if str[i+j] != "?" && key[j] != str[i+j]
            break
        end
        if j == key.length-1
            isExist = true
            idx = i
            break
        end
    end
    
    if isExist
        break
    end
end
 
if isExist
    key.length.times do |i|
        str[idx+i] = key[i]
    end
    
    str.length.times do |i|
        str[i] = "a" if str[i] == "?"
    end
    puts str
else
    puts "UNRESTORABLE"
end

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

const int N = 1e5 + 100;
const int K = 3;

int a[N][K];
int dp[N][K];

int main() {
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    for (int i=0; i<n; i++) {
        for (int j=0; j<K; j++) {
            cin >> a[i][j];
        }
    }
    for (int j=0; j<K; j++) {
        dp[0][j] = a[0][j];
    }
    for (int i=1; i<n; i++) {
        for (int j=0; j<K; j++) {
            for (int j2=0; j2<K; j2++) {
                if (j != j2) {
                    dp[i][j] = max(dp[i][j], dp[i-1][j2] + a[i][j]);
                }
            }
        }
    }
    int ans = 0;
    for (int j=0; j<K; j++) {
        ans = max(ans, dp[n-1][j]);
    }
    cout << ans << '\n';
}


Measured memory_bytes: 2560
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define VIEW(x) do {cerr << #x << ": "; for(auto i : x) cerr << i << " "; cerr << endl;} while(0)
#define ALL(x) (x).begin(),(x).end()
template<class T>bool umax(T &a, const T &b) {if(a<b){a=b;return 1;}return 0;}
template<class T>bool umin(T &a, const T &b) {if(b<a){a=b;return 1;}return 0;}

template<typename A,size_t N,typename T> void FILL(A (&array)[N],const T &val){fill((T*)array,(T*)(array+N),val);}
template<typename T> void FILL(vector<T> &v, const T &x) {fill(v.begin(), v.end(), x);}
template<typename T> void FILL(vector<vector<T>> &v, const T &x) {for(auto &i:v)fill(i.begin(), i.end(), x);}


int main() {
  int n; cin >>n;
  vector<vector<int>> adj(n);
  vector<int> d(n);
  rep(i,n-1) {
    int a,b; cin >> a >> b; --a,--b;
    adj[a].push_back(b);
    adj[b].push_back(a);
    d[a]++;
    d[b]++;
  }
  vector<int> c(n);
  rep(i,n) cin >> c[i];
  sort(ALL(c));

  priority_queue<pair<int,int>, vector<pair<int,int>>, greater<pair<int,int>>> q;
  rep(i,n) q.emplace(d[i],i);

  int ans = 0;
  vector<int> _ans(n);
  rep(i, n) {
    while(d[q.top().second] != q.top().first) q.pop();
    auto [ deg, v ] = q.top(); q.pop();
    cerr << "___" << v << " " << c[i] << " " << deg << " " << endl;
    _ans[v] = c[i];
    ans += deg * c[i];
    d[v] = -1;
    for(auto u : adj[v]) if(d[u]!=-1) {
      d[u]--;
      q.emplace(d[u],u);
    }
  }
  cout << ans << endl;
  rep(i,n) cout << _ans[i] << (i==n-1 ? "\n" : " ");
}


Measured memory_bytes: 4244
#include <stdio.h>

int main(void)
{
	int a, b, sum = 0, c = 1;
	while(scanf("%d %d", &a, &b) != EOF){
		
		sum = a + b;
		while(sum / 10 != 0){
			c++;
			sum /= 10;
		}
		printf("%d\n", c);
		c = 1;
	}
	return 0;
}

Measured memory_bytes: 600
import java.util.Scanner;
import java.util.Arrays;

class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int[] L = new int[n];
    
    for(int i=0; i<n; i++){
      L[i] = sc.nextInt();
    }
    
    Arrays.sort(L);
    int count = 0;
    
    for(int i=0; i<n-2; i++){
      for(int j=i+1; j<n-1; j++){
        for(int k=j+1; k<n; k++){
          if(L[k]<L[i]+L[j]){
            count++;
          }
        }
      }
    }
    
    System.out.println(count);
  }
}


Measured memory_bytes: 28436
#include <bits/stdc++.h>
using namespace std;
#define ll double
int n,m;
int md = pow(10,9)+7;
int nx = pow(10,5)+10;
vector<vector<int>> g(nx+1);

vector<int> vis(nx+2);
vector<string>v;

int main() {
    cin>>n;
    ll x;
    ll h[n+1];
    for(int i=0;i<n;i++){
        cin>>x;
        h[i]=x;
    }
    vector<vector<ll>> dp(n+2,vector<ll>(n+2,0));
    
    dp[0][0]=1;
    for(int i=1;i<=n;i++){
        for(int j=0;j<=n;j++){
            if(j==0){
                dp[i][j] = (1-h[i-1])*(dp[i-1][j]);
            }
            else {
                dp[i][j] = (h[i-1]*dp[i-1][j-1])+((1-h[i-1])*(dp[i-1][j]));
            }
        }
    }
    ll s=0;
    for(int i = (n/2)+1;i<=n;i++){
        s+=dp[n][i];
    }
    
    cout<< fixed << setprecision(10) <<s;
    return 0;
    
}

Measured memory_bytes: 73472
#include <algorithm>
#include <iostream>
using namespace std;
typedef long long ll;

int main()
{
    ll n;
    cin >> n;
    ll a[300004];
    ll d[300004] {0};
    for(ll i = 0; i < n; i++){
        cin >> a[i];
        d[a[i]]++;
    }
    sort(d, d + 300004, greater<ll>());
    ll p[1000004];
    ll j = 0;
    for(ll i = 300003; i > 0; i--){
        for(; j < d[i - 1]; j++) p[j] = i;
    }
    for(; j < 1000000; j++) p[j] = 0;
    ll m = 0;
    for(; m < n; m++) if(d[m] == 0) break;
    int rsum[300004] {0};
    for(ll i = 1; i <= n; i++) rsum[i] = rsum[i - 1] + d[i - 1];
    for(ll k = 1; k <= n; k++){
        ll now = 262144;
        ll mid = now / 2;
        while(mid){
            if(now * k - (rsum[k] - rsum[p[now]] + p[now] * now) > n - rsum[k]) now -= mid;
            else now += mid;
            mid /= 2;
        }
        if(now * k - (rsum[k] - rsum[p[now]] + p[now] * now) > n - rsum[k]) now--;
        cout << now << endl;
    }
}

Measured memory_bytes: 14592
#include <iostream>
#include <vector>
using namespace std;
const int MAX = 1024;

int main() {
	int n, k;
	cin >> n >> k;
	int a[MAX][MAX] = {}, b[MAX][MAX] = {};
	for (int i = 0; i < n; i++) {
		int x, y;
		char c;
		cin >> x >> y >> c;
		int ci = c == 'B' ? 1 : 0;
		x %= 2*k; y %= 2*k;
		if (x >= k) x -= k, ci = 1 - ci;
		if (y >= k) y -= k, ci = 1 - ci;
		if (ci == 0) a[x][y] += 1;
		else b[x][y] += 1;
	}
	int sa[MAX][MAX] = {}, sb[MAX][MAX] = {};
	for (int i = 0; i < k; i++) {
		for (int j = 0; j < k; j++) {
			sa[i+1][j+1] = a[i][j];
			sb[i+1][j+1] = b[i][j];
		}
	}
	for (int i = 1; i <= k; i++) {
		for (int j = 1; j <= k; j++) {
			sa[i][j] += sa[i][j-1];
			sb[i][j] += sb[i][j-1];
		}
	}
	for (int i = 1; i <= k; i++) {
		for (int j = 1; j <= k; j++) {
			sa[i][j] += sa[i-1][j];
			sb[i][j] += sb[i-1][j];
		}
	}
	auto sum_rect_a = [&](int x0, int y0, int x1, int y1) {
		return sa[x1][y1] - sa[x0][y1] - sa[x1][y0] + sa[x0][y0];
	};
	auto sum_rect_b = [&](int x0, int y0, int x1, int y1) {
		return sb[x1][y1] - sb[x0][y1] - sb[x1][y0] + sb[x0][y0];
	};
	int ans = 0;
	for (int i = 0; i < k; i++) {
		for (int j = 0; j < k; j++) {
			int now = sum_rect_a(0,0,i,j) + sum_rect_a(i,j,k,k);
			now += sum_rect_b(i,0,k,j) + sum_rect_b(0,j,i,k);
			now = max(now, n-now);
			ans = max(ans, now);
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 19608
#include<iostream>
#include<string>
#include<cstring>
#include<algorithm>
#include<vector>
#include<map>
#include<cmath>
#include<string>
#include<bitset>
#include <sstream>
#include<queue>
#include<set>
#include<iomanip>
#define rep(i,n) for(ll i=0;i<(n);++i)
using namespace std;
typedef long long ll;
typedef pair<int,ll>P;

const ll mod = 1e9+7;
const ll INF = ll(1e18)+1;
const ll MAXN = 1e6;

int main()
{
    int a,b;
    cin>>a>>b;
    if(a<6)
    {
        cout<<0<<endl;
    }
    else if(a<13)
    {
        cout<<b/2<<endl;
    }
    else
    {
        cout<<b<<endl;
    }
    
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
//#include <mylib.h>
using namespace std;
//cin.sync_with_stdio(false);

#define FOR(i,a,b) for(int i = (a); i < (b); ++i)
#define FOR_EQ(i,a,b) for(int i = (a); i <= (b); ++i)
#define FOR_RE(i,a,b) for(int i = (a); i > (b); --i)
#define rep(i,n) FOR(i,0,n)
#define rep_eq(i,n) FOR_EQ(i,0,n)
#define rep_re(i,n) FOR_RE(i,n,0)
//1個上から時計周り
const int ddx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
//上右下左
const int dx[4] = {0, 1, 0, -1};
const int dy[4] = {1, 0, -1, 0};

typedef unsigned long long ull;
typedef long long ll;
typedef vector<int> Vector;
typedef vector<Vector>	DVector;
int n;

int main(int argc, char const *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);

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

Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <string> 
#include <cmath>  
#include <cstdlib>
#include <ctime>
#include <vector>
#include <algorithm>
#include <numeric>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <functional>

using namespace std;
using ll = long long;

#define FOR(i, m, n) for(int i = (m);i < (n);i++)
#define REP(i,n) for(int i = 0; i < int(n); i++)
#define VI vector<int>
#define VVI vector<vector<int>>
#define VVVI vector<vector<vector<int>>>
#define VL vector<ll>
#define VVL vector<vector<ll>>
#define VB vector<bool>
#define VVB vector<vector<bool>>
#define PAIR pair<int,int>
#define MP make_pair
#define VP vector<pair<int,int>>
#define VS vector<string>
#define QUE queue<int>
#define DEQ deque<int>
#define PQUE priority_queue<int> //5,5,4,3,3,2,...
#define REPQUE priority_queue<int, vector<int>, greater<int>> //1,1,2,3,4,4,5,...
#define SUM(obj) accumulate((obj).begin(), (obj).end(), 0)
#define SORT(obj) sort((obj).begin(), (obj).end()) // 1,2,3,4,5...
#define RESORT(obj) sort((obj).begin(), (obj).end(), greater<int>()) // 5,4,3,2,1...
#define UB(obj,n) upper_bound((obj).begin(), (obj).end(), n) //itr > n
#define LB(obj,n) lower_bound((obj).begin(), (obj).end(), n) //itr>= n

const ll INF = (ll)9e18;

int main() {
	int N;
	cin >> N;
	VS S(N);
	VVI alphabet(N, VI(26, 0));
	REP(i, N) {
		cin >> S[i];
		REP(j, S[i].size()) {
			alphabet[i][S[i][j] - 'a']++;
		}
	}

	bool flag = true;
	REP(j,26){
		int minc = 100000000;
		REP(i, N) {
			minc = min(minc, alphabet[i][j]);
		}
		if (minc != 0) flag = false;
		REP(i, minc) {
			cout << (char)(j + 'a');
		}
	}
	if (flag) cout << " ";
	cout << endl;
	return 0;
}



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

int n;
string s , b ;

int main(){
cin>>n;
cin>>s>>b;


for(int i=0;i<=n;i++){
    string a = s.substr(0,i) + b;
    if( a.find(s)==0 ){
        cout<<n+i<<endl;
        return 0;
    }
}
cout<<n+n<<endl;
return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

#define max(a, b) ((a) > (b) ? (a) : (b))

int main(void)
{
	int A, B;
	scanf("%d %d", &A, &B);

	int ans = max(max(A + B, A - B), A * B);
	printf("%d\n", ans);
	return 0;
}


Measured memory_bytes: 128
#include<cstdio>
int main()
{
  int n,k[1000],p[1000],b;
  scanf("%d",&n);
  for(int i=0;i<=n-1;i++) {
    scanf("%d %d",&k[i],&p[i]);
  }
  for(int i=0;i<=n-1;i++) {
    if(k[i]%p[i]==0) printf("%d\n",p[i]);
    else printf("%d\n",k[i]%p[i]);
  }
  return 0;
}

Measured memory_bytes: 1032
#include <cstdio>

int n, p, d1, d2, mp, md;

int main(){
    while(scanf("%d", &n) != EOF){
        if(n == 0) break;

        md = 0;
        for(int i = 0; i < n; i++){
            scanf("%d %d %d", &p, &d1, &d2);

            if(d1 + d2 > md){
                mp = p;
                md = d1 + d2;
            }
        }

        printf("%d %d\n", mp, md);
    }

    return 0;
}

Measured memory_bytes: 2604
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
typedef long long ll;

int main(){
    ll n;cin>>n;
    ll ans=0;
    vector<ll> a(n);
    vector<ll> b(n);
    vector<ll> c(n);
    for(int i=0;i<n;i++) cin>>a[i];
    for(int i=0;i<n;i++) cin>>b[i];
    for(int i=0;i<n;i++) cin>>c[i];
    sort(a.begin(),a.end());
    sort(b.begin(),b.end());
    sort(c.begin(),c.end());
    for(int i=0;i<n;i++){
        auto a_n=lower_bound(a.begin(),a.end(),b[i]);
        ll iter_a=a_n-a.begin();
        auto c_n=upper_bound(c.begin(),c.end(),b[i]);
        ll iter_c=c_n-c.begin();
        ans+=iter_a*(n-iter_c);
    }
    cout<<ans<<endl;
}


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

using namespace std;

char S[1010101];
int A[1010101], B[1010101], F[1010101];
int n;

int calc()
{
	int i, x;

	for(i = 0, x = 0; i < n; i ++){
		if((F[n - 1] == F[i] + F[n - i - 1]) && A[i]) x = !x;
	}

	return x;
}

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

	int i, j;

	cin >> n >> S;

	for(i = 1; i <= n; i ++){
		for(j = 1; i >> j; j ++){
			F[i] += i >> j;
		}
	}

	for(i = 0; i + 1 < n; i ++){
		B[i] = abs(S[i] - S[i + 1]);
	}
	n --;
	for(i = 0; i < n; i ++){
		if(B[i] == 1) break;
	}

	if(i == n){
		for(i = 0; i < n; i ++){
			A[i] = B[i] == 2;
		}
		cout << calc() * 2 << "\n";
	}
	else{
		for(i = 0; i < n; i ++){
			A[i] = B[i] == 1;
		}
		cout << calc() << "\n";
	}

	return 0;
}

Measured memory_bytes: 13056
#include <stdio.h>
#include <stdlib.h>
int main(void){
    int a[3];
    scanf("%d %d %d",&a[0],&a[1],&a[2]);
    if(abs(a[1]-a[0]) > abs(a[2]-a[0]))
        printf("B\n");
    else
        printf("A\n");
}


Measured memory_bytes: 128
# 105 C
N = int(input())
base = -2
n = N
a = []
#pw = base
while True:
    if n==0: break
    if n%base ==0:  b = 0
    else:    b = 1
    a.append(b)
    #print(n, a)#
    n = (n - b)// base
if a==[]: a = [0]
a.reverse()
for x in a: print(x, end='')


Measured memory_bytes: 3060
n,m = map(int,input().split())
map = [[] * m for _ in range(n)]
dp = [[0] * (m+1) for _ in range(n + 1)]

for _ in range(n):
    tmp = input()
    for __ in tmp:
        map[_].append(__)

if map[n-1][m-1] == '#':
    print(0)

for t1 in range(n)[::-1]:
    if map[t1][m-1] != '#':
        dp[t1 + 1][m] = 1
    else:
        break

for t1 in range(m)[::-1]:
    if map[n-1][t1] != '#':
        dp[n][t1 + 1] = 1
    else:
        break

for i in range(1,n+1)[::-1]:
    for j in range(1,m + 1)[::-1]:
        if map[i-1][j-2] != '#' and map[i-2][j-1] != '#':
            dp[i-1][j-1] = dp[i][j-1] + dp[i-1][j]
        elif map[i -1][j-2] == '#' and map[i -2][j-1] != '#':
             dp[i-1][j-1] = dp[i-1][j]
        elif  map[i -1][j-2] != '#' and map[i -2][j-1] == '#':
             dp[i-1][j-1] = dp[i][j-1]
        else:
            dp[i-1][j-1] = 0

print(dp[1][1] % 1000000007)


Measured memory_bytes: 165720
import * as fs from 'fs';
const input = fs.readFileSync("/dev/stdin", "utf8");
// 

const [, ...lines] = input.split("\n");
// const [height, width]= line1.split(" ");

lines
  .reduce((prev, line) => [...prev, line, line], [])
  .forEach(line => console.log(line));



Measured memory_bytes: 30436