akhauriyash/Code-Regression huggingface dataset:
#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>;

vector<vector<int>> g;
vector<int> coss;
vector<int> k;
vector<int> ans;
int n;
int sum = 1;

int st = 0;

int main(){
	int m;
	cin >> n >> m;
	g = vector<vector<int>>(n, vector<int>(0));
	ans = vector<int>(n);
	coss = vector<int>(n);
	k = vector<int>(n);
	rep(i, n){
		coss.at(i) = 1000000000;
		k.at(i) = 0;
	}
	rep(i, m){
		int a, b;
		cin >> a >> b;
		a--; b--;
		g.at(a).push_back(b);
		g.at(b).push_back(a);
	}
    vector<int> dist(n, -1);
    queue<int> que;

    dist[0] = 0;
    que.push(0);

    while (!que.empty()) {
        int v = que.front();
        que.pop();
        for (int nv : g[v]) {
            if (dist[nv] != -1) continue;
            dist[nv] = dist[v] + 1;
//			cout << nv << ' ' << v+1 << endl;
			ans.at(nv) = v+1;
            que.push(nv);
        }
    }
	cout << "Yes" << endl;
    for (int v = 1; v < n; ++v) cout << ans.at(v) << endl;
	return 0;
}

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

int a[5000000];
int first=0,last=0;
int n,m,q;
string w;

void insert(){
	a[last]=n;
	last++;
}

void deleteFirst(){
	last--;
}

void deleteLast(){
	first++;
}

void _delete(){
	for(int k=last-1;k>=first;k--){
		if(a[k]==n){
			m=k;
			for(int k=m;k<last-1;k++){
				a[k]=a[k+1];
			}
			last--;
			break;
		}
	}
}

void owata(){
	for(int k=last-1;k>=first;k--){
		cout<<a[k];
		if(k==first){
			cout<<endl;
		}
		else{
			cout<<' ';
		}
	}
}

void hantei(){
	if(w=="insert"){
		cin>>n;
		insert();
	}
	if(w=="delete"){
		cin>>n;
		_delete();
	}
	if(w=="deleteFirst"){
		deleteFirst();
	}
	if(w=="deleteLast"){
		deleteLast();
	}
}

int main(){
	cin>>q;
	for(int i=0;i<q;i++){
		cin>>w;
		hantei();
	}
	owata();
	return 0;
}

Measured memory_bytes: 7092
import numpy as np

MOD = 998244353

def main():
    n, s = map(int, input().split())
    a = list(map(int, input().split()))
    dp = np.zeros((n+1, s+1), dtype=np.int64)
    dp[0][0] = 1
    for i, v in enumerate(a):
        dp[i+1] += dp[i]*2
        if v <= s:
            dp[i+1][v:] += dp[i][:-v]
        dp[i+1] %= MOD
    print(int(dp[n][s])%MOD)

if __name__ == "__main__":
    main()


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

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc =new Scanner(System.in);
		int  n=sc.nextInt();
		long a[]=new long[n];
		long s[]=new long[n+1];
		s[0]=0;
		for(int i=0;i<n;i++) {
			a[i]=sc.nextLong();
			s[i+1]=s[i]+a[i];
		}
		Arrays.sort(s);
		long c[]=new long[n+1];
		int j=0;
		c[0]=1;
		for(int i=1;i<=n;i++) {
			if(s[i]==s[i-1]) {
				c[j]++;
			}
			else {
				j++;
				c[j]++;
			}
		}
		long ans=0;
		for(int i=0;i<=j;i++) {
			ans+=c[i]*(c[i]-1)/2;
		}
		System.out.println(ans);
	}
}


Measured memory_bytes: 89140
import numpy as np
a,b = map(int,input().split())
moda=np.mod(a,2019)
modb=np.mod(b,2019)
if (modb<=moda)or((b-a)>=673):
    print(0)
    exit()

num =list(range(moda,modb+1))

ans = 10000
for i,l in enumerate(num):
    if i == len(num)-1:
        break
    for r in num[i+1:]:
        ans = min(np.mod(l*r,2019),ans)
print(ans)

Measured memory_bytes: 12504
#include <bits/stdc++.h>
#define REP(i,n) for (int i=0;i<(n);i++)
#define FOR(i,s,e) for (int i=s;i<(e);i++)
#define All(v) (v).begin(),(v).end()
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
using namespace std;
typedef long long llint;
typedef pair<int, int> P;
const int MOD = (int)1e9 + 7;
const int INF = 999999999;

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

    int N;
    cin >> N;
    int A[2][N];
    REP(i,2){
        REP(j,N){
            cin >> A[i][j];
        }
    }
    int a,b,M;
    M = 0;
    REP(i,N){
        a = 0;
        b = 0;
        for(int j=0;j<=i;j++){
            a += A[0][j];
        }
        for(int j=N-1;j>=i;j--){
            b += A[1][j];
        }
        if (a+b>M){
            M = a+b;
        }
    }
    cout << M <<"\n";
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define all(v) v.begin(), v.end()
int main(){
  int a, b, c, d, e, k; cin >> a >> b >> c >> d >> e >> k;
  if(e-a<=k){
    cout << "Yay!" << endl;
  } else {
    cout << ":(" << endl;
  }
  return 0;
}


Measured memory_bytes: 3588
using System;
using System.Collections.Generic;
using System.Linq;

namespace AOJ0074
{
    class Program
    {
        static void Main()
        {
            var length = TimeSpan.FromHours(2);

            foreach (var remain in ReadInputs().Select(position => length - position))
            {
                Console.WriteLine("{0:c}", remain);
                Console.WriteLine("{0:c}", remain.Multiply(3));
            }
        }

        private static IEnumerable<TimeSpan> ReadInputs()
        {
            string line;
            while ((line = Console.ReadLine()) != null && line != "-1 -1 -1")
            {
                var values = line.Split(' ').Select(int.Parse).ToArray();
                yield return new TimeSpan(values[0], values[1], values[2]);
            }
        }
    }

    public static class TimeSpanExtensions
    {
        public static TimeSpan Multiply(this TimeSpan value, int multiplier)
        {
            return TimeSpan.FromTicks(value.Ticks*multiplier);
        }
    }
}

Measured memory_bytes: 9620
#include<cstdio>
#include<deque>
#include<map>
#include<algorithm>
using namespace std;

int main(){
  while(1){
    int n, m, p, q, r;
    scanf("%d", &n);
    if(n == 0)return 0;
    scanf("%d%d%d%d", &m, &p, &q, &r);
    deque<pair<int, int> > mountain, mounta, mountb;
    mountain.push_back(make_pair(1, n));
    for(int i = 0;i < m;i++){
      int x, y, j = 0;
      scanf("%d%d", &x, &y);
      
      while(j + mountain[0].second - mountain[0].first + 1 < x){
	j += mountain[0].second - mountain[0].first + 1;
	mounta.push_back(mountain[0]);
	mountain.pop_front();
      }
      mounta.push_back(make_pair(mountain[0].first ,mountain[0].first + x - j - 1));
      if(mountain[0].second == mountain[0].first + x - j - 1)mountain.pop_front();
      else mountain[0].first += x - j;
      j = x;

      while(j + mountain[0].second - mountain[0].first + 1 < y){
	j += mountain[0].second - mountain[0].first + 1;
	mountb.push_back(mountain[0]);
	mountain.pop_front();
      }
      mountb.push_back(make_pair(mountain[0].first ,mountain[0].first + y - j - 1));
      if(mountain[0].second == mountain[0].first + y - j - 1)mountain.pop_front();
      else mountain[0].first += y - j;
      
      while(!mountb.empty()){
	mountain.push_back(mountb[0]);
	mountb.pop_front();
      }
      while(!mounta.empty()){
	mountain.push_back(mounta[0]);
	mounta.pop_front();
      }
    }
    int j = 0;
    while(j + mountain[0].second - mountain[0].first + 1 < p - 1){
      j += mountain[0].second - mountain[0].first + 1;
      mountain.pop_front();
    }
    if(mountain[0].second == mountain[0].first + p - j - 2)mountain.pop_front();
    else mountain[0].first += p - j - 1;
    j = p - 1;
    
    int res = 0;
    while(j + mountain[0].second - mountain[0].first + 1 < q){
      res += max(0, min(r, mountain[0].second) - mountain[0].first + 1);
      j += mountain[0].second - mountain[0].first + 1;
      mountain.pop_front();      
    }
    res += max(0, min(r, mountain[0].first + q - j - 1) - mountain[0].first + 1);
    printf("%d\n", res);
  }
}

Measured memory_bytes: 1120
#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 pair<ll,ll> pll;

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 DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

#define CHMIN(a,b) a=min((a),(b))
#define CHMAX(a,b) a=max((a),(b))

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

// floating
typedef double Real;
const Real EPS = 1e-11;
#define EQ0(x) (abs(x)<EPS)
#define EQ(a,b) (abs(a-b)<EPS)
typedef complex<Real> P;

int n;
int a[252521], b[252521];

const int C = 2521;
ll mp[2*C][2*C];

ll fact[25252];
ll inv(ll x){
  ll t = MOD-2;
  ll r = 1;
  while(t){
    if(t&1)r=r*x%MOD;
    x=x*x%MOD;
    t>>=1;
  }
  return r;
}

int main(){
  fact[0] = 1;
  FOR(i,1,25252)fact[i]=i*fact[i-1]%MOD;
  scanf("%d",&n);
  REP(i,n)scanf("%d%d",a+i,b+i);
  REP(i,n){
    mp[C-a[i]][C-b[i]] += 1;
  }
  REP(i,2*C){
    REP(j,2*C){
      mp[i][j] %= MOD;
      if(i+1<2*C)mp[i+1][j]+=mp[i][j];
      if(j+1<2*C)mp[i][j+1]+=mp[i][j];
    }
  }
  ll ans = 0;
  REP(i,n){
    ans += mp[C+a[i]][C+b[i]];
    ans %= MOD;
  }
  REP(i,n){
    // (2a+2b)! / (2a)!(2b)!
    ans -= fact[2*a[i]+2*b[i]] * inv(fact[2*a[i]]) %MOD * inv(fact[2*b[i]]) %MOD;
    ans = FIX(ans);
  }
  ans *= inv(2);
  ans %= MOD;
  printf("%lld\n",ans);
  return 0;
}


Measured memory_bytes: 200576
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
??§???????°?????????????
"""
tra = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
trb = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"
inp = input().strip()
print(inp.translate(str.maketrans(tra,trb)))

Measured memory_bytes: 7480
#include <bits/stdc++.h>
using namespace std;
int main(){
  int T1, T2;
  long long A1, A2, B1, B2;
  cin >> T1 >> T2 >> A1 >> A2 >> B1 >> B2;
  
  long long a=T1*A1-T1*B1, b=T2*A2-T2*B2;
  if(a==-b){
    cout << "infinity"<< endl;
    return 0;
  }
  long long ans=0;
  if((a<0 && a+b>0) || (a>0 && a+b<0)){
    ans=abs(a/(a+b))*2;
    if(a%(a+b)!=0) ans++;
  }
  cout << ans << endl;  
}


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

#define INF 1001001001
#define MAX 200005

int main() {
  int n, q;
  cin >> n >> q;
  dsu d(n);
  vector<int> ans;
  rep(i,q) {
    int t, u, v;
    cin >> t >> u >> v;
    if (t==0) {
      d.merge(u,v);
    } else {
      ans.push_back(d.same(u,v));
    }
  }
  for (auto a : ans) cout << a << endl;

  return 0;
}


Measured memory_bytes: 4528
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define rep(i,s,f) for(i=s;i<f;i++)
#define print(v) for(auto &z:v) cout<<z<<' ';cout<<'\n'
#define db cout<<"db: "
#define pb push_back
#define pii pair<int,int>
#define F first
#define S second
#define B begin()
#define E end()
#define all(v) v.B,v.E
#define sz(v) (int)((v).size())
#define vi vector<int>
#define vii vector<pair<int,int>>
#define boost ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define clk1 clock_t start_time=clock()
#define clk2 cout<<(clock()-start_time)/(double)CLOCKS_PER_SEC
#define clean(arr) memset(arr,0,sizeof(arr))
#define mod 1000000007
#define mod2 998244353
#define space 100005
//<<fixed << setprecision(9)




ll EE(ll a, ll b, ll *x, ll *y)
{
    if (a == 0) 
    { 
        *x = 0, *y = 1; 
        return b; 
    } 
  
    ll x1, y1;
    ll gcd = EE(b%a, a, &x1, &y1); 
  
    *x = y1 - (b/a) * x1; 
    *y = x1; 
  
    return gcd; 
}

ll inverse(ll a, ll m)
{
    ll x,y;
    EE(a,m,&x,&y);
    if(x<0) x += m;
    return x;
}

// works in O(k)*(1 inverse time)
// k!=0    
int choose(ll n,ll k)
{
	ll i;
	ll num=1,den=1;
	for(i=2;i<=k;i++)
	{
		den*=i;
		den%=mod;
	}
	for(i=n-k+1;i<=n;i++)
	{
		num*=i;
		num%=mod;
	}
	i=num*inverse(den,mod);
	i%=mod;
	return i;
}
int main()
{
    int n,i,j,t;
    boost;

    cin>>n;
    ll ans=0;
    rep(i,1,n+1)
    {
        int r = n - 3*i;
        if(r<0) break;
        ans+= choose(r+i-1,i-1);
        ans%=mod;
    }
    cout<<ans;

    return 0;
}

Measured memory_bytes: 3632
#include<stdio.h>
#include<math.h>
#include<string.h>
#include<stdlib.h>

int main(void)
{
  int i,n,a;
  int s[200000]={0};
  scanf("%d",&n);
  for(i=0;i<n-1;i++){
    scanf("%d",&a);
    s[a-1]++;
  }
  for(i=0;i<n;i++)
    printf("%d\n",s[i]);
	return 0;
}


Measured memory_bytes: 2508
package main

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

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Scan()
	var X, Y int
	fmt.Sscanf(scanner.Text(), "%d %d", &X, &Y)

	ans := X + Y/2
	fmt.Println(ans)
}


Measured memory_bytes: 640
#include<iostream>
#include<string>
#include<algorithm>
#include <stdio.h>
#include<iostream>
#include<iomanip>
#include<cmath>
#include<vector>
#include<set>

using namespace std;
int max(int a,int b){
  if(a>= b) return a;
  else return b;
}
int main(){
  int n; cin >>n;
  double sum=0.0;
  for(int i=0 ; i<n ; i++){
    double x; cin >>x;
    string s; cin >>s;

    if(s=="JPY") sum+=x;
    else sum+= 380000.0*x;
  }
  cout <<setprecision(15)<<sum<<endl;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(){
  char in[3], now = 'A';
  while(scanf("%s", in) != EOF){
    if(in[0] == now) now = in[2];
    else if(in[2] == now) now = in[0];
  }

  printf("%c\n", now);
  return 0;
}

Measured memory_bytes: 540
#!/usr/bin/ruby
a=(gets.to_i+1).times.map{gets.split[1].to_i.times.map{v,r=gets.split.map(&:to_f);[v*r,r]}.transpose.map{|e|e.reduce(:+)}.reduce(:/)}
puts a.pop+1e-7<a.max ? :YES: :NO

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

// macros
#define overload_rep(_1, _2 ,_3 ,name, ...) name
#define re_p(i, n) for(int i = 0; i < (n); ++i)
#define r_ep(i, x, y) for(int i = (x); i <= (y); ++i)
#define rep(...) overload_rep(__VA_ARGS__, r_ep, re_p)(__VA_ARGS__)
#define all(a) a.begin(), a.end()
#ifndef STOP_DEBUG
#define debug(...)\
    do { cerr << boolalpha << "[" << #__VA_ARGS__ << "]:";\
    debug_cerr(__VA_ARGS__); cerr << noboolalpha; } while (0)
#else
#define debug(...)
#endif

// functions
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
void debug_cerr(){ cerr << '\n'; }
template<class Head, class... Tail>
void debug_cerr(Head head, Tail... tail){
    cerr << ' ' << head;
    debug_cerr(tail...);
}
template<typename T>
vector<T> make_v(size_t a, T b){ return vector<T>(a, b); }
template<typename... Ts>
auto make_v(size_t a, Ts... ts){
    return vector<decltype(make_v(ts...))>(a, make_v(ts...));
}

// cin/cout setup
struct IoSetup{
    IoSetup(){
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(20);
    }
} iosetup;

// libraries

// declarations
int N;
int a[50], b[50];
int dist[51][51];
bool canuse[51];

void init_wf(){
    rep(i, 0, 50)rep(j, 0, 50)dist[i][j] = 100;
    rep(i, 0, 50){
        dist[i][i] = 0;
        rep(j, 1, 50)if(canuse[j])chmin(dist[i][i % j], 1);
    }
}

void warshall_floyd(){
    rep(k, 0, 50)rep(i, 0, 50)rep(j, 0, 50){
        chmin(dist[i][j], dist[i][k] + dist[k][j]);
    }
}

// solve
int main(){

    cin >> N;
    rep(i, N)cin >> a[i];
    rep(i, N)cin >> b[i];

    rep(i, N){
        if(b[i] != a[i] && b[i] * 2 >= a[i]){
            puts("-1");
            return 0;
        }
    }

    long long ans = 0;
    rep(i, 0, 50)canuse[i] = true;
    for(int i = 50; i >= 1; i--){
        canuse[i] = false;
        init_wf();
        warshall_floyd();
        rep(j, N)if(dist[a[j]][b[j]] >= 100){
            canuse[i] = true;
            ans |= 1ll << i;
            break;
        }
    }

    cout << ans << '\n';
    return 0;

}

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

// #define multitest 1
// #define Debug 1
#ifdef Debug
#define db(...) ZZ(#__VA_ARGS__, __VA_ARGS__);
template <typename Arg1>
void ZZ(const char *name, Arg1 &&arg1)
{
	std::cerr << name << " = " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void ZZ(const char *names, Arg1 &&arg1, Args &&... args)
{
	const char *comma = strchr(names + 1, ',');
	std::cerr.write(names, comma - names) << " = " << arg1;
	ZZ(comma, args...);
}
#else
#define db(...)
#endif

typedef long long ll;
typedef long double ld;
#define f first
#define s second
#define pb push_back
const long long mod = 1000000007;

void solve()
{
	int n, W, w, v;
	cin >> n >> W;
	vector<int> wt(n), val(n);
	ll sum = 0;
	for (int i = 0; i < n; ++i)
	{
		cin >> wt[i] >> val[i];
		sum += val[i];
	}
	vector<ll> Dp(sum + 1, 1e18);
	Dp[0] = 0;
	for (int i = 0; i < n; ++i)
		for (int j = sum - val[i]; j >= 0; --j)
			Dp[j + val[i]] = min(Dp[j + val[i]], Dp[j] + wt[i]);
	ll ans = 0;
	for (int i = 0; i <= sum; ++i)
	{
		db(i,Dp[i]);
		if (Dp[i] <= W)
			ans = i;
	}
	cout << ans;
}

int main()
{
#ifndef Debug
	ios_base::sync_with_stdio(0);
	cin.tie(0);
#endif
	int t = 1;
#ifdef multitest
	cin >> t;
#endif
	while (t--)
		solve();
	return 0;
}

Measured memory_bytes: 1024
import numpy as np
 
H, W = map(int, input().split())
S = np.array([list(input()) for _ in range(H)]) == '.'

#上下左右方向に塗られるマスの数を格納する配列
up = np.zeros((H, W), dtype=int)
down = np.zeros((H, W), dtype=int)
left = np.zeros((H, W), dtype=int)
right = np.zeros((H, W), dtype=int)

for i in range(H):
    up[i] = (up[i-1] + 1) * S[i]
    down[-i-1] = (down[-i] + 1) * S[-i-1]
 
for i in range(W):
    left[:, i] = (left[:, i-1] + 1) * S[:, i]
    right[:, -i-1] = (right[:, -i] + 1) * S[:, -i-1]

print(np.max(up+down+left+right) - 3)

Measured memory_bytes: 219816
#include<algorithm>
#include<bitset>
#include<cmath>
#include<cstdlib>
#include<iomanip>
#include<iostream>
#include<map>
#include<queue>
#include<set>
#include<string>
#include<utility>
#include<vector>

using namespace std;
 
typedef long long ll;

#define PB push_back
#define MP make_pair
#define F first
#define S second

template<typename T,typename U>
bool chmax(T& max, const U& x){
	if(max<x){
		max = x;
		return true;
	}
	return false;
}

template<typename T,typename U>
bool chmin(T& min, const U& x){
	if(min>x){
		min = x;
		return true;
	}
	return false;
}


int main(){
	int sx,sy,tx,ty,x,y;
  	cin >> sx >> sy >> tx >> ty;
  	x=tx-sx; y=ty-sy;
  	string s="";
  	for(int i=0;i<x;i++){
    	s.PB('R');
    }
  	for(int i=0;i<y;i++){
    	s.PB('U');
    }
  	for(int i=0;i<x;i++){
    	s.PB('L');
    }
  	for(int i=0;i<y+1;i++){
    	s.PB('D');
    }
  	for(int i=0;i<x+1;i++){
    	s.PB('R');
    }
  	for(int i=0;i<y+1;i++){
    	s.PB('U');
    }
  	s+="LU";
  	for(int i=0;i<x+1;i++){
    	s.PB('L');
    }
  	for(int i=0;i<y+1;i++){
    	s.PB('D');
    }
  	s.PB('R');
  	cout << s;
}

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

using ll = long long;
#define rep(i,n) for(int i = 0; i < (n); i++)
#define rrep(i,n) for(int i = (n); i > 0; i--)
#define print(n) cout << n << endl

int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    
    string s;
    cin >> s;
    if(s[2] == s[3]) if(s[4]==s[5]){
        print("Yes");
        return 0;
    }
    print("No");
    return 0;
}

Measured memory_bytes: 256
import java.util.*;
import java.lang.*;

public class Main{
    static int [] head;
    static int [] next;
    static int [] to;
    static long [] cost;
    static int [] size;
    static int edgeCount = 0;
    static long ans = 0;
    static int N;

    public static void main(String [] args) {
        Scanner sc = new Scanner(System.in);
        N = sc.nextInt();
        head = new int  [N + 1];
        size = new int  [N + 1];
        next = new int  [N + N + 1];
        to   = new int  [N + N + 1];
        cost = new long [N + N + 1];
        for(int i = 0; i < N - 1; i++) {
            int A = sc.nextInt();
            int B = sc.nextInt();
            int C = sc.nextInt();
            addEdge(A,B,C);
            addEdge(B,A,C);
        }
        calcSize(1);
        dfs(1);
        System.out.println(ans);
    }

    public static void dfs(int root) {
        int maxNodeSize = N - size[root];
        long minEdgeCost = Long.MAX_VALUE;

        for(int e = head[root]; e != 0; e = next[e]) {
            int destination = to[e];
            minEdgeCost = Math.min(minEdgeCost,cost[e]);

            if(size[destination] < size[root]) {
                maxNodeSize = Math.max(maxNodeSize,size[destination]);

                long min = Math.min(size[destination], N - size[destination]);
                ans = ans + min * cost[e] * 2;
                dfs(destination);

                if(min + min == N) {
                    ans = ans - cost[e];
                }
            }
        }

        if(maxNodeSize * 2 < N) {
            ans = ans - minEdgeCost;
        }
    }

    public static int calcSize(int root) {
        size[root] = 1;
        for(int e = head[root]; e != 0; e = next[e]) {
            if(size[to[e]] == 0) {
                size[root] += calcSize(to[e]);
            }
        }
        return size[root];
    }

    public static void addEdge(int A, int B, int C) {
        edgeCount += 1;
        to[edgeCount] = B;
        cost[edgeCount] = C;
        next[edgeCount] = head[A];
        head[A] = edgeCount;
    }
}


Measured memory_bytes: 107120
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<vector>
#include<cmath>
#include<algorithm>
#include<map>
#include<queue>
#include<deque>
#include<iomanip>
#include<tuple>
using namespace std;
typedef long long int LL;
typedef pair<int,int> P;
typedef pair<LL,int> LP;
const int INF=1<<30;
const LL MAX=1e9+7;

void array_show(int *array,int array_n,char middle=' '){
	for(int i=0;i<array_n;i++)printf("%d%c",array[i],(i!=array_n-1?middle:'\n'));
}
void array_show(LL *array,int array_n,char middle=' '){
	for(int i=0;i<array_n;i++)printf("%lld%c",array[i],(i!=array_n-1?middle:'\n'));
}

vector<int> v1;

int main(){
	int n,m;
	int i,j,k;
	int a,b,c;
	for(i=0;i<3;i++){
		cin>>a;
		v1.push_back(a);
	}
	sort(v1.begin(),v1.end());
	if(v1[0]+v1[1]==v1[2])cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES

#include <bits/stdc++.h>
using namespace std;
using i32 = int; using i64 = long long int; using f64 = double; using str = string;
template <typename T> using vec = vector<T>;
template <typename T> using heap = priority_queue<T, vec<T>, greater<T>>;
#define times(n, i) for (i32 i = 0; i < (n); ++i)
#define range(a, b, i) for (i32 i = (a); i < (b); ++i)
#define upto(a, b, i) for (i32 i = (a); i <= (b); ++i)
#define downto(a, b, i) for (i32 i = (a); i >= (b); --i)
#define all(xs) (xs).begin(), (xs).end()
#define sortall(xs) sort(all(xs))
#define reverseall(xs) reverse(all(xs))
#define uniqueall(xs) (xs).erase(unique(all(xs)), (xs).end())
#define even(x) (((x) & 1) == 0)
#define odd(x) (((x) & 1) == 1)
#define append emplace_back
#define findge lower_bound
#define findgt upper_bound
const i64 MOD = 1000000007;
const f64 EPS = 1e-10;

i64 n;


i32 main()
{
    cin >> n;
    i64 c; cin >> c;
    i64 d = 0;
    i64 ans = 1;
    times(n-1, i) {
        i64 a; cin >> a;
        if (d > 0 && c > a) {
            ans++;
            d = 0;
            c = a;
            continue;
        }
        if (d < 0 && c < a) {
            ans++;
            d = 0;
            c = a;
            continue;
        }
        if (c < a) {
            d = 1;
        }
        else if (c > a) {
            d = -1;
        }
        c = a;
    }
    cout << ans << endl;
    return 0;
}

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

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

    int ans = 0;
    if (X == 1) ans = 1;

    for (int b = 1; b <= X; ++b) {
        for (int p = 2; p <= X; ++p) {
            int tmp = pow(b, p);
            if (tmp <= X) {
                ans = max(ans, tmp);
            }
        }
    }
    cout << ans << endl;
}

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

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

  for (int x = 0; x < 8; x++) {
    int sum = abcd.at(0) - '0';
    string ans = "";
    ans += abcd.at(0);
    for (int i = 0; i < 3; i++) {
      if (x & (1 << i)) {
        sum += abcd.at(i + 1) - '0';
        ans += "+";
      } else {
        sum -= abcd.at(i + 1) - '0';
        ans += "-";
      }
      ans += abcd.at(i + 1);
    }
    if (sum == 7) {
      ans += "=7";
      cout << ans << endl;
      return 0;
    }
  }

  return 0;
}

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

int main() {
	ios_base::sync_with_stdio( false );

	int H, W;
	cin >> H >> W;

	vector<string> s( H );
	for( auto& v: s ) { cin >> v; }

	for( int i = 0; i < H; ++i ) {
		for( int j = 0; j < W; ++j ) {
			if( s[i][j] == '#' || s[i][j] == '*' ) {
				bool f = false;
				if( i > 0 && s[i-1][j] == '#' ) { s[i-1][j] = '*'; f = true; }
				if( i < H-1 && s[i+1][j] == '#' ) { s[i+1][j] = '*'; f = true; }
				if( j > 0 && s[i][j-1] == '#' ) { s[i][j-1] = '*'; f = true; }
				if( j < W-1 && s[i][j+1] == '#' ) { s[i][j+1] = '*'; f = true; }
				if( f ) { s[i][j] = '*'; }
			}
		}
	}

	bool result = true;
	for( int i = 0; i < H; ++i ) {
		for( int j = 0; j < W; ++j ) {
			if( s[i][j] == '#' ) {
				result = false;
				break;
			}
		}

		if( !result ) { break; }
	}

	cout << (result ? "Yes" : "No") << endl;

	return 0;
}


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

typedef unsigned long long ull;

int ind(char ch)
{
    switch (ch) {
    case 'R':
        return 0;
    case 'G':
        return 1;
    case 'B':
        return 2;
    default:
        return 3;
    }
}

bool f(const string &s, int a, int b, int c)
{
    int t[3] = {0,0,0};
    t[ind(s[a])] = 1;
    t[ind(s[b])] = 1;
    t[ind(s[c])] = 1;
    return t[0] == 1 && t[1] == 1 && t[2] == 1;
}

int main()
{
    ios_base::sync_with_stdio(false);
    int N;
    string S;
    cin >> N >> S;

    vector<int> v[3];
    for (int i = 0; i < N; ++i) {
        v[ind(S[i])].push_back(i);
    }

    if (v[0].size() == 0 ||
        v[1].size() == 0 ||
        v[2].size() == 0) {
        cout << 0 << endl;
        return 0;
    }

    unsigned long long cnt = 0;

    for (int dist = 1; dist < N; ++dist) {
        for (int i = 0; i + (2*dist) < N; ++i) {
            if (f(S, i, i+dist, i+(2*dist))) {
                ++cnt;
            }
        }
    }

    unsigned long long total = v[0].size() * v[1].size() * v[2].size();

    cout << total - cnt << endl;

}

Measured memory_bytes: 3700
loop do
  line = gets.chomp.split
  m = line[0].to_i
  f = line[1].to_i
  r = line[2].to_i

  break if m == -1 && f == -1 && r == -1

  if m == -1 || f == -1
    puts 'F'
  elsif m + f >= 80
    puts 'A'
  elsif m + f >= 65
    puts 'B'
  elsif m + f >= 50 || r >= 50
    puts 'C'
  elsif m + f >= 30
    puts 'D'
  else
    puts 'F'
  end
end

Measured memory_bytes: 6104
#include <iostream>
#include <vector>
#include <string>
#include <numeric>
#include <deque>
#include <map>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <bitset>

using namespace std;
using ll = long long;

int main() {
    int n, d, a;
    cin >> n >> d >> a;
    vector<int> x(n), h(n);
    vector<int> order(n);
    for (int i = 0; i < n; ++i) {
        cin >> x[i] >> h[i];
        order[i] = i;
    }
    sort(order.begin(), order.end(), [&x](int v1, int v2) {
        return x[v1] < x[v2];
    });
    deque<pair<int, int>> queue;
    ll sum = 0;
    ll res = 0;
    for (int i : order) {
        while (!queue.empty() && queue.front().first + d < x[i]) {
            sum -= queue.front().second * a;
            queue.pop_front();
        }
        if (h[i] > sum) {
            int need = h[i] - (int) sum;
            int count = (need + a - 1) / a;
            res += count;
            sum += count * a;
            queue.emplace_back(x[i] + d, count);
        }
    }
    cout << res << "\n";
    return 0;
}


Measured memory_bytes: 3456
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <cstring>
#include <string>
#include <functional>
#include <set>
#include <map>
#include <cmath>
#include <queue>
#include <stack>

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

int main()
{
	ll A,B,C;
	scanf("%lld %lld %lld",&A,&B,&C);
	if(A%2==0||B%2==0||C%2==0)
	{
		puts("0");
	}
	else
	{
		printf("%lld\n",min(A*B,min(B*C,C*A)));
	}
	return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
const int N=3000,M=3000;
int n,m;
char a[N+5],b[M+5];
int dp[N+1][M+1],pa[N+1][M+1]/*转移路径*/;
int main(){
    int n,m;
    cin>>a+1>>b+1;
    n=strlen(a+1);m=strlen(b+1);
    for(int i=1;i<=n;i++)for(int j=1;j<=m;j++){
        dp[i][j]=dp[i-1][j];pa[i][j]=1;
        if(dp[i][j-1]>dp[i][j])dp[i][j]=dp[i][j-1],pa[i][j]=2;//第2种转移 
        if(a[i]==b[j]&&dp[i-1][j-1]+1>dp[i][j])dp[i][j]=dp[i-1][j-1]+1,pa[i][j]=3;//第3种转移 
    }
    int nowi=n,nowj=m;
    string ans; 
    while(nowi&&nowj)
        if(pa[nowi][nowj]==1)nowi--;
        else if(pa[nowi][nowj]==2)nowj--;
        else ans+=a[nowi],nowi--,nowj--;
    for(int i=ans.size()-1;~i;i--)putchar(ans[i]);
    return 0;
}

Measured memory_bytes: 70656
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        String S = sc.next();
		String T = S.substring(0, N/2);
			if (S.equals(T + T)){
              System.out.println("Yes");
            } else{
              System.out.println("No");
            }
	}
}

Measured memory_bytes: 22868
while True:
    n = int(input())
    if n == 0:
        break

    s = [0]
    for i in range(n):
        s.append(int(input()) + s[i])

    m = -100000 * 5000
    for i in range(0, n):
        for j in range(i + 1, n + 1):
            m = max(m, s[j] - s[i])

    print(m)

Measured memory_bytes: 6764
#include <iostream>
#include <queue>
#include <vector>

using namespace std;

/*--------------------------------------------*/
/* 0 : enqueue                                */
/* 1 : front                                  */
/* 2 : dequeue                                */
/*--------------------------------------------*/

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

  std::vector< std::queue<int> > que(n);

  int order;
  int t, num;

  for(int i=0; i<q; ++i){
    cin >> order >> t;

    if(order == 0){
    cin >> num;
    que[t].push(num);
    }
    else if(order == 1 && !que[t].empty()){
      cout << que[t].front() << endl;
    }
    else if(order == 2 && !que[t].empty()){
      que[t].pop();
    }
  }

  return 0;
}


Measured memory_bytes: 4400
#include <bits/stdc++.h>
#include <algorithm>
#include <iomanip>
using namespace std;
 
#define ll long long
#define ull unsigned long long
#define ld long double
 
#define mp make_pair
#define pb push_back

#define rep(i,a,b) for(ll i=a;i<b;i++)
#define repb(i,a,b) for(ll i=a;i>=b;i--)
 
#define ft first
#define sd second
#define endl "\n"
 
#define pll pair<ll,ll>
#define V vector<ll>
#define S set<ll>
#define VV vector<V>
const long double pi=asin(1)*2;
 
const ll M=1000000007;
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
 
ll pow1(ll a,ll b){
    int res=1;
    while(b>0){
        if(b&1){
        	res=(res*a)%M;
		}
        a=(a*a)%M;
        b>>=1;
    }
    return res%M;
}
const ll N =100001;



int main()
{
	fast;
	int t;
	t=1;
//	cin>>t;
	while(t--)
	{
		ll n;
		cin>>n;
		ll a[n];
		rep(i,0,n)cin>>a[i];
		ll mx=a[0];
		ll ans=0;
		rep(i,0,n){
			mx=max(mx,a[i]);
			ans+=mx-a[i];
		}
		cout<<ans<<endl;
	}
	return 0;
}

Measured memory_bytes: 5164
import sys
from itertools import combinations


def _i(): return int(sys.stdin.readline().strip())


def _ia(): return map(int, sys.stdin.readline().strip().split())


def main():
    n = _i()
    a = list(_ia())

    cnt = 0
    for c in combinations(a, 3):
        l1, l2, l3 = sorted(c)
        if l1 == l2 or l2 == l3 or l3 == l1:
            continue

        if l1 < l2 + l3 and l2 < l3 + l1 and l3 < l1 + l2:
            cnt += 1
    return cnt


if __name__ == "__main__":
    print(main())


Measured memory_bytes: 67996
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
int main(){
    int n;
    cin>>n;
    vector<int> p(n);
    rep(i,n) cin>>p[i];
    int cnt =1;
    int mini =p[0];
    for(int i=1;i<n;i++){
        mini = min(mini,p[i-1]);
        if (mini>=p[i]) cnt++;
    }
    cout << cnt << endl;
}

Measured memory_bytes: 1024
#include<iostream>
using namespace std;
int main() {
    int n, x;
    while (1){
        cin >> n >> x;
        int ans = 0;
        if (n==0 && x==0) break;
        for (int i=1; i<=n-2; i++){
            for (int j=i+1; j<=n-1; j++){
                for (int k=j+1; k<=n; k++){
                    if (i+j+k == x) ans += 1;
                }
            }
        }
        cout << ans << endl;
    }
    return 0;
}


Measured memory_bytes: 3100
mod=10**9+7
N=int(input())
A=list(map(int,input().split()))
B=[0 for i in range(N)]
B[0]=sum(A)-A[0]
count=(A[0]*B[0])%mod
for i in range(1,N):
    B[i]=B[i-1]-A[i]
    count=(count+A[i]*B[i])%mod
print(count)

Measured memory_bytes: 102000
#include<bits/stdc++.h>
using namespace std;
//Optimisations
#pragma GCC target ("avx2")
#pragma GCC optimization ("unroll-loops")
#pragma GCC optimize("O2")
//shortcuts for functions
#define pb push_back
#define mp make_pair
#define ff first 
#define ss second
#define all(v) v.begin(),v.end()
#define prec(n) fixed<<setprecision(n)
#define n_l '\n'
// make it python 
#define gcd __gcd
#define append push_back
#define str to_string
// utility functions shortcuts
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define sswap(a,b) {a=a^b;b=a^b;a=a^b;}
#define swap(a,b) {auto temp=a; a=b; b=temp;}
#define init(dp) memset(dp,-1,sizeof(dp));
#define set0(dp) memset(dp,0,sizeof(dp));
#define bits(x) __builtin_popcount(x)
#define SORT(v) sort(all(v))
#define endl "\n"
#define forr(i,n) for(ll i=0;i<n;i++)
// declaration shortcuts
#define ll long long
// Constants
constexpr int dx[] = {-1, 0, 1, 0, 1, 1, -1, -1};
constexpr int dy[] = {0, -1, 0, 1, 1, -1, 1, -1};
constexpr ll INF = 1999999999999999997; 
constexpr int inf= INT_MAX;
constexpr int MAXSIZE = int(1e6)+5;
constexpr auto PI  = 3.14159265358979323846L;
constexpr auto oo  = numeric_limits<int>::max() / 2 - 2;
constexpr auto eps = 1e-6;
constexpr auto mod = 1000000007;
constexpr auto MOD = 1000000007;
constexpr auto MOD9 = 1000000009;
constexpr auto maxn = 100006;
//void IOfile(){
//freopen(file_name, reade_mode, stdin);
//freopen(file_name, write_mode, stdout);
//}
void fastio(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
}

ll solve(ll n){

	if(n==0) return 1;
	ll ans = 0 ;
	ans+= 2*(solve(n/2));
	return ans;	

}

int main(){
	fastio();
	ll n;
	cin>>n;
	ll ans=0;
	ans+= 2*solve(n/2);
	 cout<<ans-1<<"\n";
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <fstream>
#include <cassert>
#include <cstring>
#include <numeric>
#include <ctime>
#include <complex>
#include <bitset>
#include <random>

using namespace std;

typedef long long ll;
typedef long double ld;

//#define int ll
#define double ld
#define loop(i, n) for(int i = 0; i < (int)n; ++i)
#define loop1(i, n) for(int i = 1; i <= (int)n; ++i)
#define F first
#define S second
#define pb push_back
#define pi pair <int, int>
#define all(x) begin(x), end(x)
#define ti tuple <int, int, int>
#define Point Vect
#define mkt make_tuple
#define no {cout << "-1"; return;}

void solve() {
    string s; cin >> s;
    if (s == "Sunny")
        cout << "Cloudy";
    if (s == "Cloudy")
        cout << "Rainy";
    if (s == "Rainy")
        cout << "Sunny";
}

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    solve();
    return 0;
}

Measured memory_bytes: 3620
import java.io.PrintWriter;
import java.util.*;

public class Main {
	static int N;
	static PrintWriter pw;
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		pw = new PrintWriter(System.out);
		
		N = sc.nextInt();

		char[] str = new char[N];
		print(str, 0, 0);
		
		pw.close();
		sc.close();
	}
	
	static void print(char[] str, int p, int m) {
		if(p==N) {
			pw.println(str);
			return;
		}
		for(int i=0; i<m+1; i++) {
			str[p]=(char)('a'+i);
			print(str, p+1, Math.max(m, i+1));
		}
	}
}


Measured memory_bytes: 25360
#include <algorithm>
#include <cstdint>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#include <cfloat>

using namespace std;

using lint=int64_t;
using uint=uint32_t;
using ulint=uint64_t;

template<class T>
using vector2d=vector<vector<T>>;

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

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

template <class T>
void OutVec(const vector<T>& vec){
  for(int i = 0; i < vec.size() - 1; ++i){
    cout<<vec[i]<<" ";
  }
  cout<<vec.back()<<endl;
}

template <class T>
void OutVec2d(const vector2d<T>& vec){
  for(auto v:vec){
    OutVec(v);
  }
}

lint solve(lint n, lint ga, lint gb, lint sa, lint sb, lint ba, lint bb){
  lint     tmp_max_nuts =n;
  for(lint gi           =0;gi<=5000;gi++){
    for(lint si=0;si<=5000;si++){
      lint nuts=n-gi*ga-si*sa;
      if(nuts<0) continue;
      if(ba<bb){
        lint bi=nuts/ba;
        nuts-=bi*ba;
        nuts+=gi*gb+si*sb+bi*bb;
        UpdateMax(tmp_max_nuts,nuts);
      }else{
        nuts+=gi*gb+si*sb;
        UpdateMax(tmp_max_nuts,nuts);
      }
    }

  }

  lint result=tmp_max_nuts;
  for(lint gi=0;gi<=5000;gi++){
    for(lint si=0;si<=5000;si++){
      lint nuts=tmp_max_nuts-gi*gb-si*sb;
      if(nuts<0) continue;
      if(ba>bb){
        lint bi=nuts/bb;
        nuts-=bi*bb;
        nuts+=gi*ga+si*sa+bi*ba;
        UpdateMax(result,nuts);
      }else{
        nuts+=gi*ga+si*sa;
        UpdateMax(result,nuts);
      }
    }

  }

  return result;
}

int main(){
  cout << std::fixed << std::setprecision(16);
  cin.tie(nullptr);
  std::ios::sync_with_stdio(false);

  lint n,ga,gb,sa,sb,ba,bb;
  cin>>n>>ga>>sa>>ba>>gb>>sb>>bb;

  lint result=n;
  UpdateMax(result,solve(n, ga, gb, sa, sb, ba, bb));
  UpdateMax(result,solve(n, sa, sb, ba, bb, ga, gb));
  UpdateMax(result,solve(n,ba,bb,ga,gb,sa,sb));
  cout<<result<<endl;

  return 0;
}




Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <fstream>
#include <cassert>
#include <cstring>
#include <numeric>
#include <ctime>
#include <complex>
#include <bitset>

using namespace std;

typedef long long ll;
typedef long double ld;

#define int ll
#define ld double
#define loop(i, n) for(int i = 0; i < (int)n; ++i)
#define loop1(i, n) for(int i = 1; i <= (int)n; ++i)
#define F first
#define S second
#define pb push_back
#define pi pair <int, int>
#define len length()
#define all(x) begin(x), end(x)
#define ti tuple <int, int, int>
#define Point Vect

const int N = 2e5 + 7;

int nex[N], tree[4 * N], add[4 * N];
pi z[N];

void push(int v, int l, int r) {
    tree[v] += add[v];
    if (l != r) {
        add[2 * v + 1] += add[v];
        add[2 * v + 2] += add[v];
    }
    add[v] = 0;
}

void delta(int v, int l, int r, int L, int R, int val) {
    push(v, l, r);
    if (l > R || r < L)
        return;
    if (l >= L && r <= R) {
        add[v] += val;
        push(v, l, r);
        return;
    }
    int m = l + r >> 1;
    delta(2 * v + 1, l, m, L, R, val);
    delta(2 * v + 2, m + 1, r, L, R, val);
    tree[v] = tree[2 * v + 1] + tree[2 * v + 2];
}

int ask(int v, int l, int r, int pos) {
    push(v, l, r);
    if (l > pos || r < pos)
        return 0;
    if (l == pos && r == pos)
        return tree[v];
    int m = l + r >> 1;
    if (m >= pos)
        return ask(2 * v + 1, l, m, pos);
    else
        return ask(2 * v + 2, m + 1, r, pos);
}

void solve() {
    int n, d, A, x;
    cin >> n >> d >> A;
    d = 2 * d;
    loop(i, n) {
        cin >> z[i].F >> z[i].S;
        z[i].S = (z[i].S + A - 1) / A;
    }
    sort(z, z + n);
    int R = 0;
    loop(i, n) {
        delta(0, 0, n - 1, i, i, z[i].S);
        if (R < i) R = i;
        while (R < n && z[R].F - z[i].F <= d) ++R;
        nex[i] = R - 1;
    }
    int ans = 0;
    loop(i, n) {
        int ch = ask(0, 0, n - 1, i);
        if (ch > 0) {
            ans += ch;
            delta(0, 0, n - 1, i, nex[i], -ch);
        }
    }
    cout << ans;
}

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    solve();
    return 0;
}

Measured memory_bytes: 17408
n = int(input())
a = list(map(int, input().split()))
a.sort()
b = [0]
for i in range(n-1):
    b.append(b[-1]+a[i])
result = 1
for i in range(1, n+1):
    if b[-i]*2 < a[-i]:
        break
    result += 1
print(result)

Measured memory_bytes: 14252
#include <stdio.h>
#include <stdlib.h>
#include <algorithm>
using namespace std;

int K;

void go(int d, long long u)
{
	if (d == 0){
		if (--K == 0){
			printf ("%lld\n", u);
			exit(0);
		}
		return;
	}

	int v = u % 10;
	for (int k = v - 1; k <= v + 1; k++) if (0 <= k && k <= 9) go(d - 1, u * 10 + k);
}

int main()
{
	scanf ("%d", &K);
	for (int l = 1;; l++) for (int s = 1; s <= 9; s++) go(l - 1, s);

	return 0;
}

Measured memory_bytes: 3196
from collections import Counter, defaultdict

h, w, n = map(int, input().split())
hs, ws = h - 2, w - 2
dd = defaultdict(int)

for a, b in (map(int, input().split()) for _ in range(n)):
    for y in range(max(0, a - 3), min(a, hs)):
        for x in range(max(0, b - 3), min(b, ws)):
            dd[(y, x)] += 1

print(hs * ws - len(dd))

c = Counter(dd.values())
for i in range(1, 10):
    print(c[i] if i in c else 0)


Measured memory_bytes: 152092
#include <bits/stdc++.h>
#ifdef __DEBUG__
    #define DBG(X) cout << #X << " = " << (X) << endl;
    #define SAY(X) cout << (X) << endl;
#else
    #define DBG(X)
    #define SAY(X)
#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>;

int dx[]={1, 0, -1, 0, 1,-1, 1,-1};
int dy[]={0, 1, 0, -1, 1, 1,-1,-1};
const int INT_INF = (int)(2e9);
const ll  LL_INF = (ll)(2e18);

inline void fast_io() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); };
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, typename S> inline ostream& operator<<(ostream& os, const map<T, S> p) { for (auto el : p) cout << "[" << el.first << ";" << el.second << "]"; return os; }
template<typename T> inline ostream& operator<<(ostream& os, const vector<T>& v) { for (auto el : v) cout << el << " "; return os; }
template<typename T> inline ostream& operator<<(ostream& os, const deque<T>& v) { for (auto el : v) cout << el << " "; return os; }
template<typename T> inline ostream& operator<<(ostream& os, const set<T>& v) { for (auto el : v) cout << el << " "; return os; }
template<typename T> inline vector<T> fetch_vec(int sz) { vector<T> ret(sz); for (auto& elem : ret) cin >> elem; return ret; }

int N,M;
vector<int> A;
vector<bool> can_use;
int match[10] = {0,2,5,5,4,5,6,3,7,6};
int rev_match[10];
void chmax(int &a, int b){if(a<b) a=b;}


void input(){
    fast_io();
    cin >> N >> M;
    can_use.assign(10,false);
    for (int i = 0; i < M; i++)
    {
        int a; cin >> a;
        A.push_back(a);
        can_use[match[a]] = true;
    }

    for (int i = 0; i < M; i++)
    {
        chmax(rev_match[match[A[i]]],A[i]);
    }
}

bool change_st(string s, string t){
    if(s.length()>t.length()) return false;
    if(s.length()==t.length()){
        for (int i = 0; i < s.length(); i++)
        {
            if(rev_match[s[i]-'0']>rev_match[t[i]-'0']) return false;
            if(rev_match[s[i]-'0']<rev_match[t[i]-'0']) return true;
        }
    }
    return true;
}

string memo[11000];
string keta(int n){
    if(n==0) return "";
    if(n<0) return "0";
    if(memo[n].length()>0) return memo[n];
    string ret;
    for (int i = 1; i < 10; i++)
    {
        if(can_use[i]){
            string v = to_string(i)+keta(n-i);
            if(v.back()=='0') continue;
            if(change_st(ret,v)) ret = v;
        }
    }
    if(ret.length()==0) return "0";
    return memo[n] = ret;    
}


int solve(){
    string use = keta(N);

    string ans;
    for (int i = 0; i < use.length(); i++)
    {
        ans += to_string(rev_match[use[i]-'0']);
    }
    sort(ans.begin(),ans.end());
    reverse(ans.begin(),ans.end());    
    cout << ans << endl;
    return 0;
}   

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

Measured memory_bytes: 30276
#include <bits/stdc++.h>
#define all(v) (v).begin(), (v).end()
typedef long long int lint;
using namespace std;

int main() {
    int n;
    cin >> n;
    vector<int> x(n), y(n), h(n);
    int s_x, s_y, s_h;
    for (int i = 0; i < n; i++) {
        cin >> x[i] >> y[i] >> h[i];
        if (h[i] != 0) s_x = x[i], s_y = y[i], s_h = h[i];
    }
    //中心を(i,j)と決め打つ
    for (int i = 0; i <= 100; i++) {
        for (int j = 0; j <= 100; j++) {
            int height = s_h + abs(i - s_x) + abs(j - s_y);
            bool isVarid = true;
            for (int k = 0; k < n; k++) {
                if (max(height - abs(x[k] - i) - abs(y[k] - j), 0) != h[k]) {
                    isVarid = false;
                    break;
                }
            }
            if (isVarid) {
                cout << i << " " << j << " " << height << endl;
                return 0;
            }
        }
    }
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int bingo[3][3];
    cin >> bingo[0][0] >> bingo[0][1] >> bingo[0][2] ;
    cin >> bingo[1][0]>> bingo[1][1] >> bingo[1][2];
    cin >> bingo[2][0]>> bingo[2][1] >> bingo[2][2];
    int b;
    cin >> b;
    int num[b];
    for(int i=0;i<b;i++){
        cin >> num[i];
        for(int j=0;j<3;j++){
            for(int k=0;k<3;k++){
                if(bingo[j][k] == num[i]){
                    bingo[j][k] = 0;
                }
            }
        }
    }
    int sum = 1;
    for(int u=0;u<3;u++){
        if(sum==0){
            break;
        }
        sum *= bingo[u][0]+bingo[u][1]+bingo[u][2];
        sum *= bingo[0][u]+bingo[1][u] + bingo[2][u];
        sum *= bingo[0][0] + bingo[1][1] + bingo[2][2];
        sum *= bingo[2][0] + bingo[1][1] + bingo[0][2]; 
        
        
    }
    
    if(sum==0){
        cout << "Yes";
    }else{
        cout <<"No";
    }
    
}


Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
int main()
{
    int i,n,j,k;
    scanf("%d",&n);
    getchar();
    char s[n],t[n],w[2*n];
    scanf("%s%s",&s,&t);
    for(i=0,j=0,k=0;i<n;i++,j++,k+=2)
    {


        w[k]=s[i];
        w[k+1]=t[i];
    }
    w[k]='\0';
    puts(w);
    return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
int n, c, f, i, j;
vector<int> a(200000), vis(1000001), spf(1000001, 2);
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    for (i = 3; i < 1e6; i += 2)
        spf[i] = i;
    for (i = 3; i < 998; i += 2)
        if (spf[i] == i)
            for (j = i * i; j < 1e6; j += i)
                if (spf[j] == j)
                    spf[j] = i;
    cin >> n;
    for (i = 0; i < n; i++)
    {
        cin >> a[i];
        vis[a[i]]++;
    }
    if (vis[1])
    {
        if (vis[1] == 1)
            cout << 1;
        else
            cout << 0;
        return 0;
    }
    for (i = 0; i < n; i++)
        if (vis[a[i]] == 1)
        {
            if (a[i] != spf[a[i]])
                for (j = spf[a[i]]; j * j <= a[i]; j++)
                    if (a[i] % j == 0 && (vis[a[i] / j] || vis[j]))
                    {
                        c++;
                        break;
                    }
        }
        else
            c++;
    cout << n - c;
}

Measured memory_bytes: 11824