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

// region template
#define rep(i, a, b) for (int i = (a); i < (b); ++i)
#define trav(a, x) for (auto &a : x)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef vector<int> vi;

ll gcd(ll a, ll b) { return __gcd(a, b); }

ll euclid(ll a, ll b, ll &x, ll &y) {
    if (b) { ll d = euclid(b, a % b, y, x);
        return y -= a/b * x, d; }
    return x = 1, y = 0, a;
}

typedef unsigned long long ull;
typedef long double ld;
ull mod_mul(ull a, ull b, ull M) {
    ll ret = a * b - M * ull(ld(a) * ld(b) / ld(M));
    return ret + M * (ret < 0) - M * (ret >= (ll)M);
}
ull mod_pow(ull b, ull e, ull mod) {
    ull ans = 1;
    for (; e; b = mod_mul(b, b, mod), e /= 2)
        if (e & 1) ans = mod_mul(ans, b, mod);
    return ans;
}

const ll mod = 1000000007;
struct Mod {
    ll x;
    Mod(ll xx) : x(xx) {}
    Mod operator+(Mod b) { return Mod((x + b.x) % mod); }
    Mod operator-(Mod b) { return Mod((x - b.x) % mod); }
    Mod operator*(Mod b) { return Mod((x * b.x) % mod); }
    Mod operator/(Mod b) { return *this * invert(b); }
    Mod invert(Mod a) {
        ll x, y, g = euclid(a.x, mod, x, y);
        assert(g == 1); return Mod((x + mod) % mod);
    }
    Mod operator^(ll e) {
        if (!e) return Mod(1);
        Mod r = *this ^ (e / 2); r = r * r;
        return e & 1 ? *this * r : r;
    }
};
// endregion

int main() {
    cin.sync_with_stdio(0); cin.tie(0); cin.exceptions(cin.failbit);

    int n; cin >> n;
    map<int, int> freq;
    vector<int> v(n);
    for (int i = 0; i < n; i++) {
        int t; cin >> t;
        freq[t]++;
        v[i] = t;
    }
    long long ans = 0;
    for (auto p : freq) {
        int r = p.second;
        ans += 1ll * r * (r - 1) / 2;
    }
    for (int i = 0; i < n; i++) {
        int a = v[i];
        int r = freq[a];
        long long nans = ans;
        nans -= 1ll * r * (r - 1) / 2;
        nans += 1ll * (r - 1) * (r - 2) / 2;
        cout << nans << endl;
    }
}

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

int main() {
  int A,B,C,D,E;
  cin >> A >> B >> C >> D >> E;
  
  int a,b,c,d,e;
  a = 10 - A % 10;
  b = 10 - B % 10;
  c = 10 - C % 10;
  d = 10 - D % 10;
  e = 10 - E % 10;
  
  vector<char> N(5);
  N.at(0) = a;
  N.at(1) = b;
  N.at(2) = c;
  N.at(3) = d;
  N.at(4) = e;
  
  for (int i = 0; i < 5; i++) {
    if (N.at(i) == 10){
      N.at(i) = 0;
    }
  }
  sort(N.begin(), N.end());
  int M = N.at(0) + N.at(1) + N.at(2) + N.at(3);
  
  cout << A + B + C + D + E + M << endl;
}
  
  

Measured memory_bytes: 256
#include <iostream>
int main(){
	int x,a,b,c,d,e;
	std::cin >> x;
	for(int y = 1;y <= x;y++){
		if(y == 10000){
			a = y / 10000;
		}
		if(1000 <= y&&y <= 9999){
		    b = y /1000;
		    c = (y - 1000 * b) / 100;
		    d = (y - 1000 * b - 100 * c) / 10;
		    e = (y - 1000 * b - 100 * c - 10 * d);
		}
		if(100 <= y&&y <= 999){
			c = y / 100;
			d = (y - 100 * c) / 10;
			e = (y - 100 * c - 10 * d);
		}
		if(10 <= y&&y <= 99){
			d = y / 10;
			e = y - 10 * d;
		}
		if(1 <= y&&y <= 9){
			e = y;
		}
		if(y % 3 == 0 or a == 3 or b == 3 or c == 3 or d == 3 or e == 3){
			std::cout <<" "<< y;
		}
	}
	std::cout << std::endl;
}

Measured memory_bytes: 3096
#include<bits/stdc++.h>
#define test int t; cin>>t; while(t--)
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
typedef long long ll;
using namespace std;

int main()
{
  long long a,b;
  cin>>a>>b;
  cout<<a+b/2<<endl;
}

Measured memory_bytes: 3572
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <map>
#include <queue>

#define MOD 1000000007
#define INF (1ll<<60)
typedef long long ll;
using namespace std;


int k;

int main(){
    cin >> k;
    if (k % 2 == 0){
        cout << (k/2) * (k/2) << endl;
    } else {
        cout << (k/2) * ((k+1)/2 )<< endl;
    }
}


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

const int N=305;
int n,a[N],S;
int main(){
	scanf("%d",&n);
	rep(i,1,n)scanf("%d",&a[i]),S+=a[i];
	if(S%10)printf("%d\n",S);
	else{
		sort(a+1,a+n+1);
		rep(i,1,n){
			if(a[i]%10){
				printf("%d\n",S-a[i]);
				return 0;
			}
		}
		printf("0");
	}
}

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

using namespace std;
using llong = long long;
using ldbl = long double;
using lpair = pair<llong, llong>;

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

template<typename T>
constexpr T inf = static_cast<T>(pow(10, static_cast<int>(log10(numeric_limits<T>::max())))) + 7;
constexpr llong mod = 1e9+7;

int main() {
	llong N, M;

	cin >> N >> M;

	vector<llong> ac(N + 1, 0);
	vector<llong> wa(N + 1, 0);
	llong p;
	string S;
	for (int i = 0; i < M; ++i) {
		cin >> p >> S;
		if (S == "WA") {
			if (ac[p] == 0) wa[p]++;
		}
		else {
			ac[p] = 1;
		}
	}

	llong solved = 0, penalty = 0;
	for (int i = 1; i <= N; ++i) {
		solved += ac[i];
		penalty += ac[i] * wa[i];
	}

	cout << solved << " " << penalty << endl;

	return 0;
}

Measured memory_bytes: 1792
#include <iostream>
#include <string>
#include <algorithm>
#include <utility>
#include <iomanip>
#include <functional>
#include <queue>
#include <stack>
#include <cmath>
#define INF 100000000
#define MOD 1000000007
using namespace std;


int main(){
    int w;
    cin >> w;
    int bo[w+1];
    for(int i=0; i<=w; i++){
        bo[i]=i;
    }
    
    int n;
    cin >> n;
    
    for(int i=0; i<n; i++){
        char c;
        int a,b;
        
        cin >> a >> c >> b;
        
        swap(bo[a],bo[b]);
    }
    
    for(int i=1; i<=w; i++){
        cout << bo[i]<<endl;
    }
    
    return 0;
}


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

int main(){
  int credit[20],n,com[291];
  for(int i=1;i<=17;i++)credit[i-1] = i*i;
  for(int i=0;i<291;i++)com[i] = 0;
  com[0] = 1;
  for(int i=0;i<17;i++){
    for(int j=1;j<=291;j++){
      if(j>=credit[i])com[j] += com[j-credit[i]];
    }
  }
  while(cin >> n && n){
    cout << com[n] << endl;
  }
  return 0;
}

Measured memory_bytes: 0
#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;
  int x = -1;
  for (int i = 1; i <= 50000; ++i) {
    if ((int)(i * 1.08) == n) {
      x = i;
      break;
    }
  }
  if (x != -1) cout << x << endl;
  else cout << ":(" << endl;
  return 0;
}

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



void solve(){
  int n;
  cin >> n;
  vector<int> v;
  vector<int> c;
  rep(i,n){
    int k;
    cin >> k;
    v.push_back(k); 
  }
  rep(i,n){
    int k;
    cin >> k;
    c.push_back(k); 
  }
  vector<int> d;
  rep(i,n){
    d.push_back(v[i]-c[i]) ;
  }
  int count=0;
  rep(i,n){
    if(d[i]>0){count = count + d[i];} 
  }
  
  cout << count << endl;
}

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


Measured memory_bytes: 256
a, b, c = map(int, input().split())
k = int(input())

x = max(a, b, c)
for i in range(k):
    x *= 2

if max(a, b, c) == a:
    print(x+b+c)
elif max(a, b, c) == b:
    print(a+x+c)
else:
    print(a+b+x)


Measured memory_bytes: 2940
#include <cstdio>
#include <cstring>
#define Maxn 300
#define Maxk 10
#define Inf 0x3f3f3f3f
int f[Maxn+5][Maxn+5];
int d[Maxk+5][Maxk+5];
//f[i][j]表示从S到T的路径上有i个x和j个y时其余边的最小可能长度 
//d[x][y]=min{f[i][j]+i*x+j*y}
//f[i][j]=max{d[x][y]-i*x-j*y}
int mx(int a,int b){
	return a>b?a:b;
}
int mn(int a,int b){
	return a<b?a:b;
}
struct Edge{
	int u,v,w;
}edge[Maxn*Maxn+5];
int n,m;
int main(){
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;i++){
		for(int j=1;j<=m;j++){
			scanf("%d",&d[i][j]);
		}
	}
	for(int i=0;i<=100;i++){
		for(int j=0;j<=100;j++){
			for(int x=1;x<=n;x++){
				for(int y=1;y<=m;y++){
					f[i][j]=mx(f[i][j],d[x][y]-i*x-j*y);
				}
			}
		}
	}
	int now;
	for(int x=1;x<=n;x++){
		for(int y=1;y<=m;y++){
			now=Inf;
			for(int i=0;i<=100;i++){
				for(int j=0;j<=100;j++){
					now=mn(now,f[i][j]+i*x+j*y);
				}
			}
			if(now!=d[x][y]){
				puts("Impossible");
				return 0;
			}
		}
	}
	puts("Possible");
	puts("202 10401");
	for(int i=1;i<=100;i++){
		printf("%d %d X\n",i,i+1);
	}
	for(int i=102;i<202;i++){
		printf("%d %d Y\n",i,i+1);
	}
	for(int i=0;i<=100;i++){
		for(int j=0;j<=100;j++){
			printf("%d %d %d\n",i+1,202-j,f[i][j]);
		}
	}
	puts("1 202");
	return 0;
}


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

int main(){
  string s; cin >> s;
  if(s[0]==s[1]&&s[2]==s[3]&&s[0]!=s[2]) cout << "Yes";
  else if(s[0]==s[2]&&s[1]==s[3]&&s[0]!=s[1]) cout << "Yes";
  else if(s[0]==s[3]&&s[1]==s[2]&&s[0]!=s[1]) cout << "Yes";
  else cout << "No";
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
//ios::sync_with_stdio(false);
//cin.tie(0);
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<pii,int> ppii;
typedef pair<int,pii> pipi;
typedef pair<ll,ll> pll;
typedef pair<pll,ll> ppll;
typedef pair<ll,pll> plpl;
typedef tuple<ll,ll,ll> tl;
ll mod=1000000007;
ll mod2=998244353;
ll mod3=1000003;
ll mod4=998244853;
ll inf=1000000000000000000;
double pi=2*acos(0);
#define rep(i,m,n) for(ll i=m;i<n;i++)
#define rrep(i,n,m) for(ll i=n;i>=m;i--)
int dh[4]={1,-1,0,0};
int dw[4]={0,0,1,-1};
int ddh[8]={-1,-1,-1,0,0,1,1,1};
int ddw[8]={-1,0,1,-1,1,-1,0,1};
ll lmax(ll a,ll b){
    if(a<b)return b;
    else return a;
}
ll lmin(ll a,ll b){
    if(a<b)return a;
    else return b;
}
ll gcd(ll a,ll b){
    if(a<b)swap(a,b);
    if(a%b==0)return b;
    return gcd(b,a%b);
}
ll Pow(ll n,ll k){
    ll ret=1;
    ll now=n;
    while(k>0){
        if(k&1)ret*=now;
        now*=now;
        k/=2;
    }
    return ret;
}
ll gya[200010];
ll kai[200010];
ll beki(ll n,ll k){
    ll ret=1;
    ll now=n;
    while(k>0){
        if(k%2==1){
            ret*=now;
            ret%=mod;
        }
        now*=now;
        now%=mod;
        k/=2;
    }
    return ret;
}
ll gyaku(ll n){
    return beki(n,mod-2);
}
void nckinit(ll n){
    kai[0]=1;
    kai[1]=1;
    for(int i=2;i<=n;i++){
        kai[i]=kai[i-1]*i;
        kai[i]%=mod;
    }
    gya[n]=gyaku(kai[n]);
    for(int i=n-1;i>=1;i--){
        gya[i]=gya[i+1]*(i+1);
        gya[i]%=mod;
    }
    gya[0]=1;
}
ll nck(ll n,ll k){
    if(k<0)return 0;
    if(k==0||n==k)return 1;
    ll ret=kai[n];
    ret*=gya[n-k];
    ret%=mod;
    ret*=gya[k];
    ret%=mod;
    return ret;
}
ll npk(ll n,ll k){
    if(k<0)return 0;
    if(k==0)return 1;
    ll ret=kai[n];
    ret*=gya[n-k];
    ret%=mod;
    return ret;
}
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int m,d;cin>>m>>d;
    int ans=0;
    rep(i,1,m+1){
        rep(j,1,d+1){
            int u=j/10;
            int t=j%10;
            if(u<=1||t<=1)continue;
            if(i==u*t)ans++;
        }
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 256
//Author:: Pham Ngoc Minh- Chuyen Thai Binh
#include<bits/stdc++.h>
using namespace std;
#define f first
#define s second
#define ll long long
#define fl float
#define db double
#define ii pair<ll,ll>
#define pii pair<ii,ii>
#define ford(i,a,b) for(int i=a;i<=b;i++)
#define foru(i,a,b) for(int i=a;i>=b;i--)
#define forv(i,a,b) for(int i=a;i<b;i++)
#define oo 10000000000001
#define ooo -1000000000001
#define bost  ios_base::sync_with_stdio(false); cin.tie(0);
vector<pair<int,int> > a;
int n,k;
int main()
{
    bost;
    cin>>n>>k;
    int val=0;
    for(int i=1; i<=n-2; i++)
        val+=i;
    for(int i=2; i<=n; i++)
        a.push_back(make_pair(1,i));
    if(k>val)
    {
        cout<<-1;
        return 0;
    }
    int low=val-k;
    if(low==0)
    {
        cout<<a.size()<<endl;
        for(int i=0; i<a.size(); i++)
            cout<<a[i].f<<" "<<a[i].s<<endl;
        return 0;
    }
    for(int i=2; i<=n-1; i++)
    {
        for(int j=i+1; j<=n; j++)
        {
            if(low==0)
            {
                cout<<a.size()<<endl;
                for(int i=0; i<a.size(); i++)
                    cout<<a[i].f<<" "<<a[i].s<<endl;
                return 0;
            }
            a.push_back(make_pair(i,j));
            low--;
        }
    }
    cout<<a.size()<<endl;
    for(int i=0; i<a.size(); i++)
        cout<<a[i].f<<" "<<a[i].s<<endl;
    return 0;
}
// I love Chuyen Thai Binh Verry much ! Now, you alaways in my code of me <3
// Chuyen Thai Binh La Nha :>>


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string A,B;cin>>A>>B;
  string ans="";
  if(A.size()>B.size()){
    ans="GREATER";
  }else if(A.size()<B.size()){
    ans="LESS";
  }else{
    if(A>B){
      ans="GREATER";
    }else if(A<B){
      ans="LESS";
    }else{
      ans="EQUAL";
    }
  }
  cout<<ans<< endl;
}

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

int main()
{
	int i, N, A[3][101];
	scanf("%d", &N);
	for (i = 1; i <= N; i++) scanf("%d", &(A[1][i]));
	for (i = 1; i <= N; i++) scanf("%d", &(A[2][i]));
	
	int max = 0;
	for (i = 1; i < N; i++) {
		A[1][i+1] += A[1][i];
		A[2][N-i] += A[2][N-i+1];
	}
	for (i = 1; i <= N; i++) {
		if (A[1][i] + A[2][i] > max) max = A[1][i] + A[2][i];
	}
	
	printf("%ld\n", max);
	fflush(stdout);
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
//节点从0到n-1
#define maxn 100006
struct node { double x, y; };
int n;//有多少个点
int tot;//凸包上的点
node p[maxn];//所有点数组从0开始
node P[maxn];//凸包上的点
const double pi = acos(-1.0);
//三点差积	 
double X(node A, node B, node C) { return (B.x - A.x)*(C.y - A.y) - (C.x - A.x)*(B.y - A.y); }
//两点距离
double len(node A, node B) { return sqrt((A.x - B.x)*(A.x - B.x) + (A.y - B.y)*(A.y - B.y)); }
//角度小的在前面,相同的话距离小的在前面
bool cmp(node A, node B) {
	double pp = X(p[0], A, B);
	if (pp > 0)return true;
	if (pp < 0)return false;
	if (pp == 0)return len(p[0], A) < len(p[0], B);
}
const double eps = 1e-9;
//三点点积	 
double dian(node A, node B, node C) { return (B.x - A.x)*(C.x - A.x) + (C.y - A.y)*(B.y - A.y); }
//建立凸包存到P里//以下是n>=3的情况,n=1,2要特判
void build() {
	//找左下角的点
	for (int i = 0; i < n; i++) {
		if (p[i].y < p[0].y) swap(p[i], p[0]);
		if (p[i].y == p[0].y&&p[i].x < p[0].x) swap(p[i], p[0]);
	}
	sort(p + 1, p + n, cmp);
	P[0] = p[0];
	P[1] = p[1];
	tot = 1;//初始两个点
	for (int i = 2; i < n; i++) {
		//如果需要边上的点 
		while (tot > 0 && X(P[tot - 1], P[tot], p[i]) < 0)tot--;
//		while (tot > 0 && X(P[tot - 1], P[tot], p[i]) <= 0)tot--;//P[tot]在左边 舍弃
		tot++;
		P[tot] = p[i];
	}
	// 如果需要边上点 要这块 
	node endd = P[tot];
	for (int i = n - 1; i >= 0; i--) {
		if (abs(X(P[0], endd, p[i])) <= eps) {
			if (dian(p[i], P[0], endd) < 0) {
				tot++;
				P[tot] = p[i];
			}
		}
		else break;
	}
	// 到这上面是需要注释掉的 
	tot++;
}
int main(){
//	freopen("a.txt","r",stdin);
	scanf("%d",&n);
	for(int i=0;i<n;i++)cin>>p[i].x>>p[i].y;
	build();
	printf("%d\n",tot);
	for(int i=0;i<tot;i++){
		cout<<P[i].x<<' '<<P[i].y<<endl;
	}
	return 0;
}


Measured memory_bytes: 5816
import java.util.*;

public class Main {
	public static void main(String args[] ){
	    Scanner sc = new Scanner(System.in);
	    int num1 = sc.nextInt();
	    int num2 = sc.nextInt();
	    int men = num1 * num2;
	    int syu = (num1*2) + (num2*2);
	    System.out.println(men+" "+syu);
	}
}


Measured memory_bytes: 26280
#include <iostream>

using namespace std;

int main()
{
 int a,b,c ;
 cin>> a >>  b >> c ;
  if (a==b){
     cout<< c; 
}
else if (a==c){
    cout << b ;
}
else {
    cout<< a ; 
}
     return 0 ; 
}     


Measured memory_bytes: 256
fn main() {
  let n: usize = {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().parse().unwrap()
  };
  let p: Vec<i32> = {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.split_whitespace()
      .map(|x| x.parse().unwrap())
      .collect()
  };
  let cnt = (1..n-1).filter(|&i| (p[i-1] < p[i] && p[i] < p[i+1]) || (p[i-1] > p[i] && p[i] > p[i+1])).count();
  println!("{}", cnt);
}

Measured memory_bytes: 2164
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
 
//後ろからTを含めることができるか確認していく。余った?はaにする。
int main(){
    string a;
    string b;
    cin >> a >> b;
    reverse(a.begin(), a.end());
    reverse(b.begin(), b.end());
    int a_len = a.size();
    int b_len = b.size();
    bool skip = false;
    rep(i,a_len-b_len+1){
        rep(j,b_len){
            if(a[i+j] != '?'&&b[j] != a[i+j])break;
            if(j == b_len-1){
                skip = true;
                rep(k,b_len)a[i+k] = b[k];
                i += b_len;
            }
        }
        if(skip)break;
    }
    reverse(a.begin(), a.end());
    rep(i,a_len)if(a[i] == '?')a[i] = 'a';
    if(skip)cout << a << endl;
    else cout << "UNRESTORABLE" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#define ll long long
using namespace std;

ll pow(ll a, ll b){
  if(b==0){
    return 1;
  }else if(b==1){
    return a;
  }else if(b%2==0){
    return pow(a,b/2) * pow(a,b/2);
  }else{
    return a * pow(a,b-1);
  }
}

int main(){
  ll a;
  cin >> a;
  vector<char> v;
  for(int i=1;i<12;i++){
    if(a>pow(26,i)){
      ll temp = (a % pow(26,i)) / pow(26,i-1);
      v.push_back(temp==0 ? 'z' : (char)('a'-1+temp));
      a -= (temp==0 ? 26 : temp) * pow(26,i-1);
    }else{
      ll temp = a / pow(26,i-1);
      if(temp!=0){
        v.push_back((char)('a'-1+temp));
      }
      break;
    }
    
  }
  for(int i=v.size()-1;i>=0;i--){
    cout << v[i];
  }
  return 0;
}

Measured memory_bytes: 3636
from collections import Counter

input()
a = sorted(filter(lambda x: x[1] > 1, Counter(map(int, input().split())).items()), reverse=True)
if a and a[0][1] >= 4:
    print(a[0][0]**2)
else:
    if len(a) < 2:
        print(0)
    else:
        print(a[0][0] * a[1][0])

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

int main(){
	int H,W,i,j;
	
	while(1){
		cin>>H>>W;
		if(H==0 && W==0){
			break;
		}
		for(i=0;i<H;i++){
			for(j=0;j<W;j++){
				cout<<'#';
			}
		cout<<endl;
		}
	cout<<endl;
	}
	return 0;
}

Measured memory_bytes: 3088
#define _USE_MATH_DEFINES
#define INF 100000000

#include <iostream>
#include <sstream>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>
#include <set>
#include <deque>
#include <bitset>
#include <list>
#include <cctype>
#include <utility>

using namespace std;

typedef long long ll;
typedef pair <int,int> P;
typedef pair <int,P> PP;

static const double EPS = 1e-8;

int tx[] = {0,1,0,-1};
int ty[] = {-1,0,1,0};

class Point{
public:
	double x;
	double y;
	Point() : x(0),y(0){}
	Point(double _x,double _y){
		x = _x;
		y = _y;
	}
};

class Region{
public:
	int larger_num;
	int smaller_num;
	double size;
	double x;
	double y;
	Region(double _x,double _y,double _size,int _larger_num,int _smaller_num){
		x = _x;
		y = _y;
		size = _size;
		larger_num = _larger_num;
		smaller_num = _smaller_num;
	}

	bool operator<(const Region& r) const{
		return larger_num < r.larger_num;
	}
};

void save(double x,double y,double size,const vector<Point>& points,priority_queue<Region>& que,int* maxv){
	int larger_num=0;
	int smaller_num=0;
	double cx = x + (size / 2.0);
	double cy = y + (size / 2.0);

	for(int i=0;i<points.size();i++){
		double d = sqrt((points[i].x - cx) * (points[i].x - cx)
			+ (points[i].y - cy) * (points[i].y - cy));
		if(d <= 1.0) smaller_num++;
		if(d <= 1.0 + (size/2.0)*sqrt(2.0)) larger_num++;
	}

	if(*maxv >= larger_num) return;
	*maxv = max(*maxv,smaller_num);

	que.push(Region(x,y,size,larger_num,smaller_num));
}

int main(){
	int n;
	while(~scanf("%d",&n)){
		if(n==0) break;
		vector<Point> points;
		for(int i=0;i<n;i++){
			double x,y;
			scanf("%lf %lf",&x,&y);
			points.push_back(Point(x,y));
		}

		priority_queue<Region> que;

		int maxv = 1;
		save(0,0,10,points,que,&maxv);

		while(!que.empty()){
			Region re = que.top();
			int larger = re.larger_num;
			int smaller = re.smaller_num;
			double size = re.size;
			double x = re.x;
			double y = re.y;

			que.pop();
		
			save(x,y,size/2.0,points,que,&maxv);
			save(x+size/2.0,y,size/2.0,points,que,&maxv);
			save(x,y+size/2.0,size/2.0,points,que,&maxv);
			save(x+size/2.0,y+size/2.0,size/2.0,points,que,&maxv);
		}

		printf("%d\n",maxv);
	}
}

Measured memory_bytes: 972
n, m, v, p = [int(_) for _ in input().split()]
l = [int(_) for _ in input().split()]

l = sorted(l, reverse=True)

# print(l)

s = [0]


for i in range(1, n+1):
    s.append(s[-1] + l[-i])
s = sorted(s, reverse=True)

# print(s)

for i in range(p, n):
    if l[i] + m < l[p - 1]:
        ans = i
        break
    x = (l[i] + m) * (i - p + 1) - (s[p - 1] - s[i])
    # print('i',i)
    # print('(l[i] + m)', (l[i] + m))
    # print('(i - p + 1)', (i - p + 1))
    # print('(s[p - 1] - s[i])', (s[p - 1] - s[i]))
    # print('x',x)
    y = 0
    if v >= (n - i) + (p - 1):
        y = v - (n - i) - (p - 1)

    # print('y * m', y * m)

    if x < y * m:
        ans = i
        break

    if i == n-1:
        ans = n

print(ans)


Measured memory_bytes: 14480
#define _USE_MATH_DEFIMES
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cctype>
#include <climits>
#include <clocale>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

const int MOD = 1'000'000'007;
const int INF = 1'000'000'000; //1e9
const int NIL = -1;
const long long LINF = 1'000'000'000'000'000'000; // 1e18
const long double EPS = 1E-10;

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







int main(){
    int N; std::cin >> N;
    std::vector<int> cnt(60, 0);
    {
        long long A;
        for(int i(0); i < N; ++i){
            std::cin >> A;
            for(int j(0); j < 60; ++j){
                if(A & 1) ++cnt[j];
                A /= 2;
            }
        }
    }
    long long ans(0), weight(1);
    for(int i(0); i < 60; ++i){
        ans = (ans + ((cnt[i] * (long long)(N-cnt[i])) % MOD * weight)) % MOD;
        weight = weight * 2 % MOD;
    }
    std::cout << ans << std::endl;
    return 0;
}


Measured memory_bytes: 3600
n = int(input())
# キュー
from collections import deque

a = [None] * (n+1)
for i in range(1,n+1):
    a_tmp = tuple(map(int, input().split()))
    a[i] = deque(a_tmp)

d = deque(range(1,n+1))

ans = 0
games = 0
while(True):
    players = set()
    while(d):
        tmp = d.pop()
        next = a[tmp][0]
        if(a[next][0] == tmp):
            players.add(tmp)
            players.add(next)

    if(len(players)==0):
        break

    for i in players:
        games += 1
        a[i].popleft()
        if(a[i]):
            d.append(i)

    ans += 1

if(games == n*(n-1)):
    print(ans)
else:
    print(-1)

Measured memory_bytes: 73436
def f(a,b,N):

    tmpa,tmpb=[],[]
    for i in range(3):
        if a[i]<b[i]:
            tmpa.append(a[i])
            tmpb.append(b[i])
    a,b=tmpa,tmpb

    if len(a)==0: return N
    elif len(a)==1: return (N//a[0])*b[0]+N%a[0]

    elif len(a)==2:
        if a[0]<a[1]: a,b=a[::-1],b[::-1]

        i,ans=0,N
        while i*a[0]<=N:
            j=(N-i*a[0])//a[1]
            ans=max(ans,i*b[0]+j*b[1]+(N-i*a[0]-j*a[1]))
            i+=1
        return ans

    else:
        memo=[i for i in range(N+1)]

        for i in range(1,N+1):
            tmp=[]
            for j in range(len(a)):
                if i-a[j]>=0: tmp.append(memo[i-a[j]]+b[j])
            if tmp!=[]: memo[i]=max(tmp)
        return memo[N]

import sys
N=int(input())

A=list(map(int,input().split()))
B=list(map(int,input().split()))

N=f(A,B,N)
N=f(B,A,N)
print(N)

Measured memory_bytes: 3192
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <iomanip>
#include <random>
#include <cstdio>
#include <cmath>
#include <map>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (int) n; i++)

int main() {
    vector<vector<int>> a(3), m(3);
    rep(i,3) {
        a[i].resize(3);
        m[i].resize(3);
    }
    rep(i,3) {
        rep(j,3) {
            cin >> a[i][j];
            m[i][j] = false;
        }
    }
    int n; cin >> n;
    vector<int> b(n);
    rep(i,n) cin >> b[i];
    rep(i,3) {
        rep(j,3) {
            rep(k,n) {
                if (b[k] == a[i][j]) m[i][j] = true;
            }
        }
    }
    // yoko
    rep(i,3) {
        if (m[i][0] && m[i][1] && m[i][2]) {
            cout << "Yes\n";
            return 0;
        }
    }
    // tate
    rep(j,3) {
        if (m[0][j] && m[1][j] && m[2][j]) {
            cout << "Yes\n";
            return 0;
        }
    }
    // naname
    if ((m[0][0] && m[1][1] && m[2][2]) || (m[0][2] && m[1][1] && m[2][0])) {
        cout << "Yes\n";
        return 0;
    }
    cout << "No\n";
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main () {
    int p, q, r;
    int menor;
    scanf("%d %d %d", &p, &q, &r);
    menor = p + q;
    if (p + r < menor){
        menor = p + r;
    } 
    if (r + q < menor){
        menor = r + q;
    }

    printf ("%d\n", menor);
    
    return 0;
}





Measured memory_bytes: 128
def test():
    enki = ["A","C","G","T"]

    b = input()
    if b == "A":
        print("T")
    elif b == "T":
        print("A")
    elif b == "G":
        print("C")
    elif b == "C":
        print("G")


if __name__ == "__main__":
    test()


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


int main(){
    int a,b,ch,x,y;
    int ar[6],n=0;
    scanf("%d %d",&a,&b);
    vector<int> v1[a];
    vector<int>:: iterator it;
    for(int k=0;k<b;k++){
        scanf("%d",&ch);

         if (ch==0){
             scanf("%d %d",&x,&y);
             v1[x].push_back(y);
         }
         else if (ch==1){
             scanf("%d",&x);
             
                  for( it=v1[x].begin();it!=v1[x].end();it++){
                         cout << *it;
                         if(it!= v1[x].end()-1)
                        cout <<" ";}
                   cout<<endl;




         }
         else if (ch==2){
                scanf("%d",&x);

                    v1[x].clear();

         }


    }


     return 0;

}



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

int main() {
	
	int N,score,f,s,t,out,i;
	string event;
	
	for(cin>>N,i=0;i<N;++i){
		score=out=f=s=t=0;
		
		while(out!=3){
			cin >> event;
			
			if(event == "OUT")++out;
			else if(event == "HIT"){
				if(t)++score;
				t=s;
				s=f;
				f=1;
			}else if(event == "HOMERUN"){
				if(f)++score;
				if(s)++score;
				if(t)++score;
				++score;
				f=s=t=0;
			}
		}
		cout<<score<<endl;
	}
	return 0;
}

Measured memory_bytes: 1208
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pii pair<int, int>
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < n; ++i)
#define rep3(i, l, n) for (int i = l; i < n; ++i)
#define chmax(a, b) a = max(a, b)
#define chmin(a, b) a = min(a, b)
#define out(a) cout << a << endl
#define SZ(v) (int)v.size()
#define inf (int)(1e9+7)

int main() {
    int n; cin >> n;
    int sum = 0;
    int t[n]; rep(i, n) { cin >> t[i]; sum += t[i]; }
    int m; cin >> m;
    int p[m], x[m];
    rep(i, m) cin >> p[i] >> x[i];
    rep(i, m) {
        out(sum - t[p[i] - 1] + x[i]);
    }
}




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

int sumsum(int n){
    int wa = 0;

    while(n > 0){
        wa += n % 10;
        n /= 10;
    }

    return wa;
}

int main(){
    int N,lo=0;
    cin >> N;

    lo = sumsum(N);

    if(N % lo == 0)
        cout << "Yes" << endl;
    else
        cout << "No"  << endl;
    
    
}

Measured memory_bytes: 256
#pragma GCC optimize ("O3")
#include <iostream>
#include <iomanip>
#include <istream>
#include <ostream>
#include <sstream>
#include <iterator>
#include <vector>
#include <algorithm>
#include <queue>
#include <deque>
#include <list>
#include <stack>
#include <map>
#include <unordered_map>
#include <set>
#include <bitset>
#include <utility>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <string>
#include <ctime>
#include <cctype>
#include <cstdlib>
#define IINF 10e8
#define INF 10000000000000
#define MOD 1000000007
#define mod 1000000007
#define REP(i, a, n) for (ll i = a; i < (ll)(n); i++)
#define REPE(i, a, n) for (ll i = a; i <= (ll)(n); i++)
#define rep(i,n)for(ll i=0;i<(n);i++)
#define Endl endl
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define eb emplace_back
#define mmax(x,y)(x>y?x:y)
#define mmin(x,y)(x<y?x:y)
#define chmax(x,y) x=mmax(x,y)
#define chmin(x,y) x=mmin(x,y)
#define all(x) (x).begin(),(x).end()
#define siz(x) (ll)(x).size()
#define PI acos(-1.0)
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;
typedef pair<int,int>Pin;
typedef pair<ll,ll>Pll;
template<class T> using V=vector<T>;
long long GCD(long long a, long long b) {return b?GCD(b,a%b):a;}
long long LCM(long long a, long long b) {return a/GCD(a,b)*b;}
int dx[4]={-1,0,1,0};
int dy[4]={0,-1,0,1};
int ddx[8]={-1,0,1,0,1,1,-1,-1};
int ddy[8]={0,-1,0,1,1,-1,1,-1};
ll cmp(pair<ll,ll>a,pair<ll,ll> b){
        if(a.se!=b.se)
        return a.se<b.se;
        else
        return a.fi<b.fi;
}
//----------------------------------------------------------------------

//----------------------------------------------------------------------
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    //-------------------------------  
    //ll begin_time=clock();
    //-------------------------------
    ll n;cin>>n;
    V<ll>a(n);
    for(ll i=0;i<n;i++){
        cin>>a[i];
    }
    ll q;cin>>q;
    while(q--){
        ll l,r;cin>>l>>r;
        reverse(a.begin()+l,a.begin()+r);
    }
    for(ll i=0;i<n;i++){
        if(i)cout<<" "<<a[i];
        else cout<<a[i];
    }
    cout<<endl;
    //-------------------------------  
    //ll end_time=clock();cout<<"time="<<end_time-begin_time<<"ms"<<endl;
    //-------------------------------
    return 0;
}
//----------------------------------------------------------------------













































Measured memory_bytes: 3248
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, [ $t:tt ]) => {
        {
            let len = read_value!($next, usize);
            (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
        }
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
        a: usize,
        b: usize,
        k: usize,
    }
    if k >= a {
        print!("0 ");
    } else {
        print!("{} ", a - k);
    }
    if k < a {
        println!("{}", b);
    } else if k - a >= b {
        println!("0");
    } else {
        println!("{}", b - k + a);
    }
}


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

using namespace std;

int dp[3050][3050];

int main()
{
    string s1, s2;

    cin >> s1 >> s2;
    
    int l1 = s1.length();
    int l2 = s2.length();


    for(int i = 0; i <= l2; i++)
    {
        for(int j = 0; j <= l1; j++)
        {
            dp[i][j] = 0;
        }
    }

    for(int i = l2-1; i >=0; i--)
    {
        for(int j = l1-1; j >=0; j--)
        {
            //cout << "A: " <<  s1[i-1] << " " << s2[j-1] << endl;
            if(s2[i] == s1[j])
                dp[i][j] = dp[i+1][j+1] + 1;
            else
            {
                dp[i][j] = max(dp[i+1][j], dp[i][j+1]);
            }            
        }
    }


    int b1 = 0, b2 = 0;
    string r = "";

    while(b1 < l1 && b2 < l2)
    {
        if(s2[b2] == s1[b1])
            {
                r += s2[b2];
                b1++;
                b2++;
            }
        else
        {
            if(dp[b2+1][b1] < dp[b2][b1+1])
                b1++;
            else
            {
                b2++;
            }            
        }        
    }

    cout << r;

    return 0;
}

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

class Program
{
    static void Main()
    {
        string s = Console.ReadLine();
        string t = Console.ReadLine();

        List<int> start = new List<int>();
        List<int> goal = new List<int>();
        for (int i = 0; i < 26; i++)
        {
            start.Add(-1);
            goal.Add(-1);
        }

        for (int i = 0; i < s.Length; i++)
        {
            int a = s[i] - 'a';
            int b = t[i] - 'a';

            if (start[a] != -1 || goal[b] != -1)
            {
                if (start[a] != b || goal[b] != a)
                {
                    Console.WriteLine("No");
                    return;
                }
            }

            start[a] = b;
            goal[b] = a;
        }
        Console.WriteLine("Yes");
    }
}

Measured memory_bytes: 13232
a = int(input())

if a in [1, 2, 4]:
    print(4)
    exit(0)
ans = 1 + 3

while(a!=4):
    if a%2 ==0:
        a /= 2
    else:
        a = 3 * a+ 1
    ans += 1

print(ans)


Measured memory_bytes: 2940
# coding: utf-8
# Your code here!
def judge(physical , deathblow , deathblow_list):
    for death in deathblow_list:
        physical = physical - death
    return physical

def main():
    monster_physical , deathblow = map(int , input().split())
    deathblow_list = list(map(int , input().split()))
    remaining = judge(monster_physical , deathblow , deathblow_list)
    if remaining <= 0:
        print("Yes")
    else:
        print("No")

if __name__ == "__main__":
    main()
    

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

int main()
{
    int n, *a, *b, *c;
    long long*a_table, *b_table;
    scanf("%d", &n);
    a = new int[n];
    b = new int[n];
    c = new int[n];
    a_table = new long long[n];
    b_table = new long long[n];
    for (int i = 0; i < n; i++)
        scanf("%d", a + i);
    for (int i = 0; i < n; i++)
        scanf("%d", b + i);
    for (int i = 0; i < n; i++)
        scanf("%d", c + i);
    
    std::sort(a, a + n);
    std::sort(b, b + n);
    std::sort(c, c + n);
    std::fill(a_table, a_table + n, 0);
    std::fill(b_table, b_table + n, 0);

    int j{};
    for (int i = 0; i < n; i++)
    {
        if (i) a_table[i] += a_table[i - 1];
        for ( ; j < n && a[j] < b[i]; j++)
            a_table[i]++;
    }
    j = 0;
    for (int i = 0; i < n; i++)
    {
        if (i) b_table[i] += b_table[i - 1];
        for ( ; j < n && b[j] < c[i]; j++)
            b_table[i] += a_table[j];
    }
    
    long long sum{};
    for (int i = 0; i < n; i++)
        sum += b_table[i];

    printf("%lld\n", sum);
    
    delete[] a;
    delete[] b;
    delete[] c;
    delete[] a_table;
    delete[] b_table;
}

Measured memory_bytes: 2944
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int a = scan.nextInt();
		int b = scan.nextInt();
		if (a < b) {
			System.out.println("a < b");
		} else if (a > b) {
			System.out.println("a > b");
		} else {
			System.out.println("a == b");
		}
	}

}


Measured memory_bytes: 26032
fun main(args: Array<String>) = abc156d()

fun abc156d() {
    val (n, a, b) = readLine()!!.split(' ').map { it.toInt() }

    var answer = Mint(2).modPow(n.toLong())
    answer -= 1
    answer -= comb(n, a)
    answer -= comb(n, b)

    println(answer)
}

private const val MOD = (1e9 + 7).toLong()

private fun modPow(n: Long, p: Long, m: Long = MOD): Long {
    var x = n
    var y = p
    var result = 1L

    x %= m
    while (y > 0) {
        if (y % 2 == 1L)
            result = (result * x) % m
        y = y shr 1
        x = (x * x) % m
    }

    return result
}

// useful for big N, and small K
private fun comb(n: Int, k: Int, m: Long = MOD): Long {
    if (n < k) return 0

    val min = Math.min(k, n - k)
    var value = 1L

    for (i in 1L..min) {
        value *= n - i + 1
        value %= m
        value *= modPow(i, m - 2, m)
        value %= m
    }
    return value
}

private class Mint(value: Long = 0L) {
    constructor(other: Mint) : this(other.value)

    private val value = if (value < 0) (value % MOD) + MOD else value % MOD
    operator fun unaryPlus() = this
    operator fun unaryMinus() = Mint(MOD - this.value)
    operator fun inc() = this.plus(1)
    operator fun dec() = this.minus(1)
    operator fun plus(other: Long) = Mint(this.value + other)
    operator fun plus(other: Mint) = this.plus(other.value)
    operator fun minus(other: Long) = Mint(this.value - other)
    operator fun minus(other: Mint) = this.plus(-other)
    operator fun times(other: Long) = Mint(this.value * other)
    operator fun times(other: Mint) = this.times(other.value)
    operator fun div(other: Long) = this.times(Mod.modPow(other, MOD - 2, MOD))
    operator fun div(other: Mint) = this.div(other.value)
    fun modPow(other: Long) = Mint(Mod.modPow(this.value, other, MOD))
    override fun toString() = this.value.toString()
    override fun hashCode() = value.hashCode()
    override fun equals(other: Any?): Boolean {
        if (this === other) return true
        if (javaClass != other?.javaClass) return false
        other as Mint
        return value == other.value
    }

    companion object Mod {
        private fun modPow(n: Long, p: Long, m: Long = MOD): Long {
            var x = n
            var y = p
            var result = 1L
            x %= m
            while (y > 0) {
                if (y % 2 == 1L) result = (result * x) % m
                y = y shr 1
                x = (x * x) % m
            }
            return result
        }
    }
}


Measured memory_bytes: 38052
#include <bits/stdc++.h>
#define int long long
#define endl '\n'
#define FOR(i, a, n) for (int i = (a); i < (n); ++i)
#define REP(i, n) FOR(i, 0, n)
using namespace std;

// Dual Segment Tree
template <class OM = int> struct DST {
    int n, lev;
    vector<OM> lz;
    virtual OM h(OM, OM) = 0;
    const OM e0;

    DST(int n_, const OM& e0) : e0(e0) {
        for (n = 1, lev = 0; n < n_; n <<= 1, ++lev);
        lz.assign(n << 1, e0);
    }

    // k: 0-indexed
    void set(int k, const OM& x) {
        lz[k + n] = x;
    }

    inline void push(int k) {
        for (int i = lev; i > 0; --i) {
            int j = k >> i;
            if (lz[j] == e0) continue;
            lz[(j << 1) | 0] = h(lz[(j << 1) | 0], lz[j]);
            lz[(j << 1) | 1] = h(lz[(j << 1) | 1], lz[j]);
            lz[j] = e0;
        }
    }

    // [l, r)
    // l, r: 0-indexed
    void update(int l, int r, const OM& x) {
        push(l += n);
        push(r += n - 1);
        for (++r; l < r; l >>= 1, r >>= 1) {
            if (l & 1) lz[l] = h(lz[l], x), l++;
            if (r & 1) --r, lz[r] = h(lz[r], x);
        }
    }

    // k: 0-indexed
    OM query(int k) {
        push(k += n);
        return lz[k];
    }

    void dump(int);
};

// Range Add Query (RAQ)
template <class OM> struct RAQ : DST<OM> {
    RAQ(int n, OM e0 = 0) : DST<OM>(n, e0) {}
    OM h(OM a, OM b) override { return a + b; }
};

template <typename T> map<T, int> coordinate_compression(vector<T>& x) {
    sort(x.begin(), x.end());
    x.erase(unique(x.begin(), x.end()), x.end());
    map<T, int> res;
    for (int v : x) res[v] = res.size();
    return res;
}

void _main() {
    int N, D, A;
    cin >> N >> D >> A;
    vector<int> X(N), H(N);
    map<int, int> mp;
    REP (i, N) {
        cin >> X[i] >> H[i];
        mp[X[i]] = H[i];
    }
    auto cc = coordinate_compression<int>(X);
    RAQ<int> raq(N);
    REP (i, N) raq.set(cc[X[i]], mp[X[i]]);
    int ans = 0;
    REP (i, N) {
        int hp = raq.query(i);
        if (hp < 0) continue;
        int num = (hp + A - 1) / A;
        int ub = upper_bound(X.begin(), X.end(), X[i] + 2 * D) - X.begin();
        raq.update(i, ub, -num * A);
        ans += num;
    }
    cout << ans << endl;
}

signed main(signed argc, char **argv) {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(10);
    _main();
    return 0;
}

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

typedef long long ll;

int main(){
  ll n;
  cin >> n;
  ll a[n];
  for(int i=0;i<n;i++) cin >> a[i];
  ll ans=0;
  ll p=0;
  for(int i=0;i<n;i++){
    ans+=(p+a[i])/2;
    p=(p+a[i])%2;
    if(a[i]==0){
      p=0;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 1024
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools,fractions,pprint
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpln(n): return list(int(sys.stdin.readline()) for i in range(n))

s = input()
n = len(s)
if n %2: print('No'); quit()
for i in range(n//2)[::2]:
    if s[i] == 'h' and s[i+1] == 'i':
        continue
    print('No')
    quit()
print('Yes')


Measured memory_bytes: 66156
#include <iostream>
#include <iomanip>
#include <random>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <numeric>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <sstream>
#include <bitset>
#include <cassert>
#include <fstream>

#define len(X) ((int)(X).size())

#ifdef __LOCAL
	#define DBG(X) cout << #X << "=" << (X) << endl;
#else
	#define DBG(X)
	#define endl '\n'
#endif
 
using namespace std;

using ll = long long int;
using ull = unsigned long long int;
using ld  = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

const int INT_INF = (int)(2e9);
const ll  LL_INF  = (ll)(2e18);

const ll mod = 1e9 + 7;
const int NIL = -1;
static mt19937 _g(time(nullptr));

inline ll randint(ll a, ll b) { ll w = (_g() << 31LL) ^ _g(); return a + w % (b - a + 1); }
inline void fast_io() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); };
template<typename T> inline T sign(T x) { return T(x > 0) - T(x < 0); }
template<typename T, typename S> inline ostream& operator<<(ostream& os, const pair<T, S> p) { cout << "[" << p.first << ";" << p.second << "]"; return os; }
template<typename T> inline ostream& operator<<(ostream& os, const vector<T>& v) { for(auto el: v) cout << el << " "; return os; }

void solve()
{
	int n, answ = 0;
	multiset<int> setik;

	cin >> n;

	while(n--)
	{
		int x;
		cin >> x;

		setik.insert(x);
	}

	while(!setik.empty())
	{
		int mx = *prev(setik.end());
		setik.erase(prev(setik.end()));

		for(int s = 0; s < 31; ++s)
		{
			int r = 1 << s;

			if(r - mx < 1 || r - mx > mx)
				continue;

			auto iter = setik.lower_bound(r - mx);

			if(iter == setik.end() || *iter != r - mx)
				continue;

			++answ;
			setik.erase(iter);

			break;
		}
	}

	cout << answ << endl;
}

int main()
{
	fast_io();
	solve();

	return 0;
}


Measured memory_bytes: 9600
using System;

namespace AtCoder
{
    public class Program
    {
        public static void Main()
        {
            long a,b,c,k;

            string line = System.Console.ReadLine();
            string []input = line.Split(' ');
            a = long.Parse(input[0]);
            b = long.Parse(input[1]);
            c = long.Parse(input[2]);
            k = long.Parse(input[3]);
            long rest=0;
            if(k<=a) rest = k;
            else if(k<= a+b) rest = a;
            else {
                rest = a-(k-(a+b));
            }

            Console.WriteLine(rest.ToString());
        }

    }
}

Measured memory_bytes: 27532