akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>     //sort,二分探索,など
#include <bitset>        //固定長bit集合
#include <cmath>         //pow,logなど
#include <complex>       //複素数
#include <deque>         //両端アクセスのキュー
#include <functional>    //sortのgreater
#include <iomanip>       //setprecision(浮動小数点の出力の誤差)
#include <iostream>      //入出力
#include <map>           //map(辞書)
#include <numeric>       //iota(整数列の生成),gcdとlcm(c++17)
#include <queue>         //キュー
#include <set>           //集合
#include <stack>         //スタック
#include <string>        //文字列
#include <unordered_map> //イテレータあるけど順序保持しないmap
#include <unordered_set> //イテレータあるけど順序保持しないset
#include <utility>       //pair
#include <vector>        //可変長配列

using namespace std;
typedef long long ll;

//マクロ
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define REPD(i, n) for (ll i = (ll)(n)-1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = (a); i <= (b); i++)
#define FORD(i, a, b) for (ll i = (a); i >= (b); i--)
#define ALL(x) (x).begin(), (x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size())      //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x))
#define INF 1000000000000
#define MOD 10000007
#define PB push_back
#define MP make_pair
#define F first
#define S second

const int mod = 1000000007;
// const int mod = 998244353;
struct mint
{
  ll x; // typedef long long ll;
  mint(ll x = 0) : x((x % mod + mod) % mod) {}
  mint operator-() const { return mint(-x); }
  mint &operator+=(const mint a)
  {
    if ((x += a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator-=(const mint a)
  {
    if ((x += mod - a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator*=(const mint a)
  {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const { return mint(*this) += a; }
  mint operator-(const mint a) const { return mint(*this) -= a; }
  mint operator*(const mint a) const { return mint(*this) *= a; }
  mint pow(ll t) const
  {
    if (!t)
      return 1;
    mint a = pow(t >> 1);
    a *= a;
    if (t & 1)
      a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const { return pow(mod - 2); }
  mint &operator/=(const mint a) { return *this *= a.inv(); }
  mint operator/(const mint a) const { return mint(*this) /= a; }
};

// O(a)
mint choose(ll n, ll a)
{
  mint x = 1, y = 1;
  rep(i, a)
  {
    x *= n - i;
    y *= i + 1;
  }
  return x / y;
}
ll n, a, b;
int main()
{
  cin >> n;
  cin >> a;
  cin >> b;
  mint ans = mint(2).pow(n);
  ans -= 1;
  ans -= choose(n, a);
  ans -= choose(n, b);
  cout << ans.x << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  long long a, b, x; 
  cin >> a >> b >> x;
  if(a != 0){
  long long S = b/x - (a-1)/x ;
  cout << S << endl;}
 else {long long S = b/x + 1 ;
  cout << S << endl;}
}

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

public class Main {

    public static void main(String[] args) throws NumberFormatException, IOException {
        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        String[] ia; 

        int N = Integer.parseInt(in.readLine());
        for(int n = 0;n < N; ++n){
            ia = in.readLine().split(" ");
            int Y = Integer.parseInt(ia[0]);
            int M = Integer.parseInt(ia[1]);
            int D = Integer.parseInt(ia[2]);
            int days = 0;
            for(int d = D;d < 20; ++d){
                ++days;
            }   
            if(Y % 3 == 0 || M % 2 == 1){ 
                ++days;
            }   
            for(int m = M+1;m <= 10; ++m){
                if(Y % 3 == 0 || m % 2 == 1){ 
                    days += 20; 
                } else {
                    days += 19; 
                }   
            }   
            for(int y = Y+1;y < 1000; ++y){
                if(y % 3 == 0){ 
                    days += 10 * 20; 
                } else {
                    days += 5 * 20 + 5 * 19; 
                }   
            }   
            System.out.println(days);
        }   
    }   
}

Measured memory_bytes: 19664
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<cstdio>
#include<cmath>
#include<deque>
#include<numeric>
#include<queue>
#include<stack>
#include<cstring>
#include<limits>
#include<functional>
#include<unordered_set>
#include<iomanip>
#include<cassert>
#include<regex>
#include<bitset>
#include<complex>
#include<chrono>
#include<random>
#define rep(i,a) for(int i=(int)0;i<(int)a;++i)
#define rrep(i,a) for(int i=(int)a-1;i>=0;--i)
#define REP(i,a,b) for(int i=(int)a;i<(int)b;++i)
#define RREP(i,a,b) for(int i=(int)a-1;i>=b;--i)
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(),x.end()
using ll=long long;
constexpr ll mod = 1e9 + 7;
constexpr ll INF = 1LL << 60;

ll gcd(ll n, ll m) {
	ll tmp;
	while (m!=0) {
		tmp = n % m;
		n = m;
		m = tmp;
	}
	return n;
}

ll lcm(ll n, ll m) {
	return abs(n) / gcd(n, m)*abs(m);//gl=xy
}
 
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
 
using namespace std;

struct SuffixArray{
  const string str;
  vector<int>sa;//接尾辞配列
  vector<int>rank;//何番目に小さいか
  vector<int>tmp;

  SuffixArray(const string& s):str(s){//構築 O(N(log N)^2)
    int n=s.size();
    int k=1;
    sa=vector<int>(n+1);
    rank=vector<int>(n+1);
    tmp=vector<int>(n+1);

    for(int i=0;i<=n;++i){
      sa[i]=i;//1文字から構築
      rank[i]=i<n?str[i]:-1;//ランクは文字コードに
    }
    auto comp=[&](int i,int j){//(rank[i],rank[i+k])と(rank[j],rank[j+k])を比較
      if(rank[i]!=rank[j])return rank[i]<rank[j];
      else return (i+k<=n?rank[i+k]:-1)<(j+k<=n?rank[j+k]:-1);
    };
    for(k=1;k<=n;k*=2){//k文字ソートされているところから2k文字でソートする
      sort(sa.begin(),sa.end(),comp);

      tmp[sa[0]]=0;
      for(int i=1;i<=n;++i)tmp[sa[i]]=tmp[sa[i-1]]+(comp(sa[i-1],sa[i])?1:0);
      for(int i=0;i<=n;i++)rank[i]=tmp[i];
    }
  }

  bool search(const string& t){
    int a=0,b=str.size();
    while(b-a>1){
      int c=(a+b)/2;
      if(str.compare(sa[c],t.size(),t)<0)a=c;//strのsa[c]文字目から|T|文字目までとTを比較
      else b=c;
    }
    return str.compare(sa[b],t.size(),t)==0;
  }
};

void solve(){
  string s;
  cin>>s;
  SuffixArray sa(s);
  int q;
  cin>>q;
  while(q--){
    string t;
    cin>>t;
    if(sa.search(t))cout<<1<<"\n";
    else cout<<0<<"\n";
  }
}

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


Measured memory_bytes: 15812
#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdio>
#include<string>
#include<vector>
#include<bitset>
#include<cmath>
#include<queue>
#include<stack>
#include<map>
#include<set>
using namespace std;
template<class T>inline void read(T &res)
{
    char c;T flag=1;
    while((c=getchar())<'0'|c>'9')if(c=='-')flag=-1;res=c-'0';
    while((c=getchar())>='0'&&c<='9')res=res*10+c-'0';res*=flag;
}
bitset<50>bit;
/*
bit.reset(); bit=n; bit.count();
*/
#define _for(i,a,b) for( int i=(a); i<(b); ++i)
#define rof(i,a,b)  for( int i=b-1;i>=a;i--)
#define rep(i,a,b)  for( int i=(a); i<=(b); ++i)
#define per(i,a,b)  for( int i=(b); i>=a; --i)
#define sd(n) scanf("%d",&n)
#define sdd(n,m) scanf("%d %d",&n,&m)
#define sddd(n,m,k) scanf("%d %d %d",&n,&m,&k)
#define pd(n)    printf("%d\n",n)
#define pd_(n)   printf("%d ",n)
#define pdd(n,m) printf("%d %d",n,m)
#define pddd(n,m,k) printf("%d %d %d",n,m,k)
#define pld(n) printf("%lld\n",n)
#define pldd(n,m) printf("%lld %lld\n",n,m)
#define sld(n)   scanf("%lld",&n)
#define sldd(n,m) scanf("%lld %lld",&n,&m)
#define slddd(n,m,k) scanf("%lld %lld %lld",&n,&m,&k)
#define sf(n)    scanf("%lf",&n)
#define sff(n,m) scanf("lf",&n,&m)
#define sfff(n,m,k) scanf("%lf %lf %lf",&n,&m,&k)
#define ss(str)  scanf("%s",str)
#define mm(a,n)  memset(a, n, sizeof(a))
#define debug(x) cout << #x << ": " << x << endl
#define pb push_back
#define fi first
#define se second
#define mod(x) ((x)%MOD)
typedef long long ll;
typedef pair<int,int> PII;
typedef unsigned long long ull;
typedef long double ld;
const int N=1e9+7;
const int MOD = 1e9 + 7;
//const double eps = 1e-9;
const double PI=atan(1.0)*4;
const int maxn=3e5+5;

int main()
{
    ll n;
    sld(n);
    ll ans=0;
    /*
    if(n==2)
    {
        cout << 0 << endl;
        return 0;
    }
    */
    for(ll i=1;i*i<n;i++)//x
    {
        if(n%i==0)
        {
            ll m=n/i-1;
            if(n%(m)==n/m)
                ans+=m;
        }
    }
    pld(ans);
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		String day = sc.next();
		
	 switch(day) {
	 case "SAT":
	 	System.out.println("1");
	 	break;
	 case "FRI":
		 System.out.println("2");
		 break;
	 case "THU":
		 System.out.println("3");
		 break;
	 case "WED":
		 System.out.println("4");
		 break;
	 case "TUE":
		 System.out.println("5");
		 break;
	 case "MON":
		 System.out.println("6");
		 break;
	 case "SUN":
		 System.out.println("7");
		 break;
	 }

	}

}

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

int main (){
  ll a,b,n;cin>>a>>b>>n;
  ll ans = 0;
  if (n<b){
    cout << a*n/b << endl;
    return 0;
  }
  else {
    ans = (a*n)/b - a*(n/b);
    ans = max(ans,((a*b)/b - a));
    ans = max(ans,((a*(b-1))/b));
  }
  cout << ans << endl;
}

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

using namespace std;

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

#define rep(i, j, k) for (int i = j; i < k; i++)
#define pb push_back
#define all(x) x.begin(), x.end()
#define mt make_tuple

#define iv inline void
#define ii inline int
#define ill inline ll

template <typename S, typename T>
inline bool smin(S &l, T r) {
  return r < l ? l = r, 1 : 0;
}
template <typename S, typename T>
inline bool smax(S &l, T r) {
  return l < r ? l = r, 1 : 0;
}

// constexpr int MOD = 1e9 + 7;
int MOD;

template <typename S>
inline S mod(S &l) {
  return l = (l % MOD + MOD) % MOD;
}
template <typename S, typename T>
inline S add(S &l, T r) {
  return mod(l += r);
}

void fileIO(string s) {
  freopen((s + ".in").c_str(), "r", stdin);
  freopen((s + ".out").c_str(), "w", stdout);
}

constexpr int N = 300 + 10;

int n, k;
ll dp[N][N], pd[N][N], c[N][N];

iv input() { cin >> n >> k >> MOD; }

iv init() {
  rep(i, 0, N) {
    c[i][i] = c[i][0] = 1;
    rep(j, 1, i) add(c[i][j], c[i - 1][j] + c[i - 1][j - 1]);
  }
}

iv faze_0() {
  rep(i, 0, k + 1) {
    dp[1][i] = 1;
    pd[1][i] = k + 1 - i;
  }
  rep(i, 2, n + 2) for (int j = k; ~j; j--) {
    rep(z, 1, i) {
      ll local = (pd[z][j + 1] * dp[i - z][j]) % MOD;
      local *= c[i - 2][z - 1];
      add(dp[i][j], local % MOD);
    }
    add(pd[i][j], pd[i][j + 1] + dp[i][j]);
  }
  cout << dp[n + 1][0] << endl;
}

int main() {
#ifndef LOCAL
  // fileIO("");
#endif

  input();

  init();

  faze_0();

  return 0;
}


Measured memory_bytes: 2432
import sys
input = sys.stdin.buffer.readline

def main():
    n = int(input())
    s = [input() for i in range(n)]

    ac = 0
    wa = 0
    tle = 0
    re = 0

    for i in range(len(s)):
        if s[i].strip().decode() == "AC":
            ac += 1
        elif s[i].strip().decode() == "WA":
            wa += 1
        elif s[i].strip().decode() == "TLE":
            tle += 1
        else:
            re += 1

    print("AC x {}".format(str(ac)))
    print("WA x {}".format(str(wa)))
    print("TLE x {}".format(str(tle)))
    print("RE x {}".format(str(re)))

if __name__ == '__main__':
    main()

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

using namespace std;
using ll = long long;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    int R,G,B,N;cin >> R >> G >> B >> N;
    int ans = 0;
    for(int a = 0;a < N/R+1;a++){
        for(int b = 0;b < N/G+1;b++){
            int w = R * a + b * G;
            int d = N - w;
            int c;
            if(d >= 0)c = d/B;
            else continue;
            if(a * R + b * G + c * B == N){
                ans++;
            }
        }
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string.h>
using namespace std;

int main() {
	bool NonPrime[1000000+1]={0};
	NonPrime[0]=NonPrime[1]=true;
	for(long i=2;i<=1000000;i++){
		if(NonPrime[i]) continue;
		for(long j=2*i;j<=1000000;j+=i) NonPrime[j]=true;
	}
	vector<long> Prime;
	vector<long>::iterator vp;
	for(long i=2;i<=1000000;i++) if(!NonPrime[i]) Prime.push_back(i);
	while(1){
		long n; cin >> n ; if(!n) break;
		long cnt=0;
		for(vp=Prime.begin();vp<Prime.end();vp++){
			if(n-*vp<2 || n-*vp<*vp) break;
			if(!NonPrime[n-*vp]) cnt++;
		}
		cout << cnt << '\n' ;
	}
}

Measured memory_bytes: 2956
import random

D = int(input())
C = list(map(int,input().split()))
S = []
for i in range(D):
    S.append(list(map(int,input().split())))
t = []
for i in range(D):
    #t.append(int(random.uniform(0,26)))
    t.append(int(input()))
lastds = [0]*26
ans = 0
satisfaction = 0
#initial
for d in range(D):
    lastds[t[d]-1] = d+1
    satisfaction += S[d][t[d]-1]
    for i in range(26):
        satisfaction -= C[i] * (d+1-lastds[i])
    print(satisfaction)

Measured memory_bytes: 77912
N, K = map(int, input().split())
digit_str = ''
keta = N
while True:
    keta, amari = keta//K, str(keta%K)
    if keta==0:
        digit_str = digit_str + amari
        break
    digit_str = digit_str + amari

print(len(digit_str))


Measured memory_bytes: 2940
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
typedef long long ll;
#define rep(i,n) for (int i = 0; i < (n); i++)
#define repe(i,n) for (int i = 0; i <= (n); ++i)
#define repe1(i,n) for (int i = 0; i <= (n); ++i)
#define all(x) (x).begin(),(x).end()
#define pb(x) push_back(x)
#define eb(k,v) emplace_back(k,v)
#define ct(res) cout << res << "\n";
#define vi vector<int>
#define vl vector<ll>
using namespace std;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const int INF = 1e9;
const ll MOD = 1000000007;
const double pi = 3.141592653589;
using Graph = vector<vector<int>>;
ll gcd(ll a, ll b) {return (a%b) ? gcd(b, a%b) : b;}
ll modPow(ll x, ll n) {
    if(n==0) return 1;
    ll res = modPow(x*x%MOD, n/2);
    if(n&1) res=res*x%MOD;
    return res;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n;cin>>n;
    vi a(n);
    rep(i,n) cin >> a[i];
    reverse(all(a));
    rep(i,n) {
        if (i) {
            cout << " ";
        }
        cout << a[i];
    }
    cout << "\n";
}


Measured memory_bytes: 3108
#include <iostream>
#include <cmath>
#include <algorithm>
#include <climits>
#include <vector>
#include <string>
#include <set>
#include <iomanip>
#include <map>
#define rep(i,n) for (int i=0;i<(n);++i)
#define REP(i,n) for (int i=0;i<=(n);++i)
#define all(x) (x).begin(), (x).end()
using namespace std;
typedef long long ll;
const int INF = 10000000;

int gcd(int a,int b){return b?gcd(b,a%b):a;}

int main() {
    ll n; cin >> n;
    string ans = "";
    while(n) {
        --n;
        ans += (char)('a' + (n % 26));
        n /= 26;
    }
    reverse(ans.begin(), ans.end());
    cout << ans << endl;
}

Measured memory_bytes: 3624
#include "iostream"
#include "string"
using namespace std;
int main(){
  string a;
  int b=0,c=0,d=0;
  cin>>a;
  for(int i=0;i<3;i++){
    if(a[i]=='a'){
      b++;
    }
    else if(a[i]=='b'){
      d++;
    }
    else{
      c++;
    }

  }

  if((b==1)&&(c==1)&&(d==1)){
    cout<<"Yes"<<endl;
  }
  else{
    cout<<"No"<<endl;
  }
}


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

#define rep(i, n) for (int i = 0; i < int(n); i++)
#define rrep(i, n) for (int i = int(n) - 1; i >= 0; i--)
#define reps(i, n) for (int i = 1; i <= int(n); i++)
#define rreps(i, n) for (int i = int(n); i >= 1; i--)
#define repc(i, n) for (int i = 0; i <= int(n); i++)
#define rrepc(i, n) for (int i = int(n); i >= 0; i--)
#define repi(i, a, b) for (int i = int(a); i < int(b); i++)
#define repic(i, a, b) for (int i = int(a); i <= int(b); i++)
#define each(x, y) for (auto &x : y)
#define all(a) (a).begin(), (a).end()
#define bit(b) (1ll << (b))

using namespace std;

using i32 = int;
using i64 = long long;
using u64 = unsigned long long;
using f80 = long double;
using vi32 = vector<i32>;
using vi64 = vector<i64>;
using vu64 = vector<u64>;
using vf80 = vector<f80>;
using vstr = vector<string>;

inline void yes() { cout << "Yes" << '\n'; exit(0); }
inline void no() { cout << "No" << '\n'; exit(0); }
inline i64 gcd(i64 a, i64 b) { if (min(a, b) == 0) return max(a, b); if (a % b == 0) return b; return gcd(b, a % b); }
inline i64 lcm(i64 a, i64 b) { return a / gcd(a, b) * b; }
inline u64 xorshift() { static u64 x = 88172645463325252ull; x = x ^ (x << 7); return x = x ^ (x >> 9); }
void solve(); int main() { ios::sync_with_stdio(0); cin.tie(0); cout << fixed << setprecision(16); solve(); return 0; }
template <typename T> class pqasc : public priority_queue<T, vector<T>, greater<T>> {};
template <typename T> class pqdesc : public priority_queue<T, vector<T>, less<T>> {};
template <typename T> inline void amax(T &x, T y) { if (x < y) x = y; }
template <typename T> inline void amin(T &x, T y) { if (x > y) x = y; }
template <typename T> inline T power(T x, i64 n, T e = 1) { T r = e; while (n > 0) { if (n & 1) r *= x; x *= x; n >>= 1; } return r; }
template <typename T> istream& operator>>(istream &is, vector<T> &v) { each(x, v) is >> x; return is; }
template <typename T> ostream& operator<<(ostream &os, vector<T> &v) { rep(i, v.size()) { if (i) os << ' '; os << v[i]; } return os; }
template <typename T, typename S> istream& operator>>(istream &is, pair<T, S> &p) { is >> p.first >> p.second; return is; }
template <typename T, typename S> ostream& operator<<(ostream &os, pair<T, S> &p) { os << p.first << ' ' << p.second; return os; }

void solve() {
  int n; cin >> n;
  vi32 d(n); cin >> d;
  int sum = 0;
  rep(i, n) rep(j, i) sum += d[i] * d[j];
  cout << sum << endl;
}


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

typedef long long int ll;
typedef pair<ll, ll> pll;

#define FOR(i, n, m) for (ll(i) = (m); (i) < (n); ++(i))
#define REP(i, n) FOR(i, n, 0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll)1e15;

ll dp[100005];

int main()
{
    ll N, M;
    string S;
    cin >> N >> M >> S;
    REP(i, N)
    {
        dp[i + 1] = INF;
    }
    dp[0] = 0;
    //! (cost,index)
    priority_queue<pll, vector<pll>, function<bool(pll, pll)>> q([](pll a, pll b) { return a.first == b.first ? a.second > b.second : a.first > b.first; });
    q.push(pll(0, 0));
    REP(i, N)
    {
        while (true)
        {
            if (q.empty())
                break;
            auto top = q.top();
            if (i + 1 - top.second > M)
                q.pop();
            else
                break;
        }
        if (q.empty())
        {
            break;
        }
        // if (i >= M)
        // {
        //     if (S[i - M] == '0')
        //         q.pop();
        // }
        if (S[i + 1] == '1')
        {
            dp[i + 1] = -INF;
            continue;
        }
        pll t = q.top();
        dp[i + 1] = t.first + 1;
        q.push(pll(dp[i + 1], i + 1));
    }

    if (dp[N] == INF || dp[N] == -INF)
    {
        cout << -1 << endl;
        return 0;
    }
    vector<ll> v;
    ll min = N;
    ll n = dp[N] - 1;
    ll prev = N;
    for (ll i = N; i > 0; --i)
    {
        if (dp[i] == n - 1)
        {
            v.push_back(prev - min);
            prev = min;
            min = i;
            n--;
            continue;
        }
        if (prev - i > M)
        {
            //! 一つ前から飛ぶ
            v.push_back(prev - min);
            prev = min;
            min = i;
            n--;
            continue;
        }
        if (dp[i] >= 0)
            min = i;

        if (prev - min == M)
        {
            //! 一つ前から飛ぶ
            v.push_back(prev - min);
            prev = min;
            min = i;
            n--;
            continue;
        }
    }
    v.push_back(prev);
    ll num = v.size();
    REP(i, num)
    {
        cout << v[num - 1 - i] << " ";
    }
    cout << endl;

    // REP(i, N + 1)
    // {
    //     cout << dp[i] << " ";
    // }
    // cout << endl;
    return 0;
}

Measured memory_bytes: 2296
import java.util.Scanner;
import java.util.TreeMap;

// Java8
public class Main
{
	Scanner sc = new Scanner(System.in);

	public static void main(String[] args) throws Exception
	{

		new Main().run();
	}

	void run()
	{
		nint();
		int q = nint();
		TreeMap<Integer, Integer> map = new TreeMap<>();
		map.put(-1, Integer.MAX_VALUE);
		while(q-- > 0)
		{
			int cmd = nint();
			if(cmd == 0)
			{
				int s = nint();
				int t = nint();
				int x = nint();
				Integer rightValue = map.floorEntry(t+1).getValue();
				map.subMap(s, t+1).clear();
				map.put(s, x);
				map.put(t+1, rightValue);
			}
			else
			{
				int i = nint();
				System.out.println(map.floorEntry(i).getValue());
			}
		}
	}

	int nint()
	{
		return Integer.parseInt(sc.next());
	}
}

Measured memory_bytes: 88620
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <map>
#include <cmath>
using namespace std;
typedef long long ll;

int main()
{
    int A, B;
    cin >> A >> B;
    int cnt = 0;
    int C = 1;
    if (C >= B)
    {
        cout << cnt << endl;
        return 0;
    }
    while (1)
    {
        C += (A - 1);
        cnt++;
        if (C >= B)
        {
            cout << cnt << endl;
            return 0;
        }
    }
    return 0;
}

Measured memory_bytes: 256
import java.util.*;
public class Main{
 public static void main(String[] args){
   Scanner sc = new Scanner(System.in);

   int N = sc.nextInt();   
   int M = sc.nextInt();
   char[][] img = new char[N][N];
   char[][] tmp = new char[M][M];
   boolean aru = false;
   boolean dame = false;
 
   for(int i=0;i<N;i++)
   {
     img[i] = sc.next().toCharArray();
   }
   for(int i=0;i<M;i++)
   {
     tmp[i] = sc.next().toCharArray();
   }
   
   for(int i=0;i<N-(M-1);i++)
   {
     for(int k=0;k<N-(M-1);k++)
     {
       if(img[i][k]==tmp[0][0])
       {
         aru=true;
         for(int j=0;j<M;j++)
         {
           for(int l=0;l<M;l++)
           {
             if(img[i+j][k+l]!=tmp[j][l])
             {
               dame=true;
               aru=false;
               break;
             }
           }
           if(dame)
           {
             dame = false;
             break;
           }
         }
         
       }
       if(aru)
     {
       break;
     }
     }
     if(aru)
     {
       break;
     }
   }
   String ans="No";
   if(aru) ans = "Yes";
   System.out.println(ans);
 }
}

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

int main(){
  int A,B,C,D;
  cin >> A >> B >> C >> D;
  int L,R;
  L = A+B;
  R = C+D;
  if(L>R){
    cout << "Left" << endl;
  }
  else if(L==R){
    cout << "Balanced" << endl;
  }
  else{
    cout << "Right" << endl;
  }
}

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

int main() {
	int n, cnt = 0;
	cin >> n;
	vector < int > a(n);

	for ( int i = 0; i < n; i++ ) {
		cin >> a[i];
	}
	for ( int i = 0; i < n; i++ ) {
		int ok = 1;
		for ( int j = 0; j < i; j++ ) {
			if ( a[j] > a[i] ) {
				ok = 0;
				break;
			}
		}
		if ( ok ) {
			cnt++;
		}
	}
	cout << cnt;
}


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

using namespace std;

int main(){
    ll n;
    cin >> n;
    
    ll sum = 0;
    for(int i = (n-1); i > 0; i--) {
        sum += i;
    }
    cout << sum << endl;
    
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define sz(x) (int)x.size();
#define all(x) (x).begin(), (x).end()
#define Red ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define rep(i, n) for(int i =0 ; i < n; ++i)
#define Rep(i,a,b) for(int i=a;i<=b;i++)
#define pii pair < int, int >
typedef vector<int> vi;
typedef  long long ll;
const int inf = int(1e9);
const int mod =1e9+7;
const int N = (int)2e5 + 5;

void solve(){
	int r,g,b,n;
	cin>>r>>g>>b>>n;
	int cnt=0;
	for(int i=0;i<=3000;i++){
		for(int j=0;j<=3000;j++){
			int x=i*r+j*g;
			int y=n-x;
			if(n>=x && y%b==0)cnt++;
		}
	}
	printf("%d",cnt);


}
int main(){
	Red;
	int t=1;
	//cin>>t;
	while(t--)
	solve();
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <numeric>
#include <cstdio>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <stack>
using namespace std;
#define MOD 1000000007
#define endl "\n" 
#define rep(i,n) for(int i = 0; i < (n); ++i)
typedef long long ll;


int main(void) {
    cin.tie(0);
    ios::sync_with_stdio(false);
  
    int n, a, b; cin >> n;
    if(n == 1) {
        cout << "Hello World" << endl;
    } else {
        cin >> a >> b;
        cout << a+b << endl;
    }

    return 0;
}


Measured memory_bytes: 256
macro_rules! scan {
    () => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.trim().to_string()
        }
    };
    (;;$n:expr) => {
        (0..$n).map(|_| scan!()).collect::<Vec<_>>()
    };
    ($t:ty) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.trim().parse::<$t>().unwrap()
        }
    };
    ($($t:ty),*) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            (
                $(iter.next().unwrap().parse::<$t>().unwrap(),)*
            )
        }
    };
    ($t:ty;;) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.split_whitespace()
                .map(|t| t.parse::<$t>().unwrap())
                .collect::<Vec<_>>()
        }
    };
    ($t:ty;;$n:expr) => {
        (0..$n).map(|_| scan!($t;;)).collect::<Vec<_>>()
    };
    ($t:ty; $n:expr) => {
        (0..$n).map(|_|
                    scan!($t)
        ).collect::<Vec<_>>()
    };
    ($($t:ty),*; $n:expr) => {
        (0..$n).map(|_|
                    scan!($($t),*)
        ).collect::<Vec<_>>()
    };
}

fn main() {
    let (n, m) = scan!(i64, i64);

    println!("{}", (n - 1) * (m - 1));
}


Measured memory_bytes: 4352
use proconio::input;

fn main() {
    input! {
        n: i64,
    }

    println!(
        "{}",
        (1..n + 1)
            .filter(|n| n % 3 != 0)
            .filter(|n| n % 5 != 0)
            .sum::<i64>()
    );
}


Measured memory_bytes: 2148
#include<bits/stdc++.h>
using namespace std;
signed main(){
  int n,m,sum=0;
  cin>>n>>m;
  for(int i=1;i<n;i++){
    sum+=i;
  }
  for(int j=1;j<m;j++){
    sum+=j;
  }
  cout<<sum<<"\n";
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
const int MOD = 1e9+7;
const int INF = 0x3f3f3f3f;
const double PI = 4*atan(1);
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<double,double> pdd;
// ll gcd(ll a, ll b) { 
//     if (a == 0) return b; 
//     return gcd(b % a, a); 
// }
// ll f(ll x) {
// 	x%=MOD;
// 	if(x<0)x+=MOD;
// 	return x;
// }
// ll power(int base, int power) {
// 	ll prod = 1;
// 	ll b = base;
// 	while(power) {
// 		if (power & 1) {
// 			prod = f(prod*b);
// 		}
// 		b = f(b*b);
// 		power/=2;
// 	}
// 	return prod;
// }
// struct line {
//     int m, c;
//     ll eval(int x) { return 1LL * m * x + c; }
//     double intersectX(line l) { return (double) (c - l.c) / (l.m - m); }
// };

string str;
void solve() {
	cin >> str;
	if (str=="ABC") {
		cout << "ARC\n";
	} else {
		cout << "ABC\n";
	}
}
int main() {

	// int t;
	// cin >> t;
	// for (int i = 1; i <= t; i++) { 
		// cout << "Case #" << i << ": ";
		solve();
	// }
}

Measured memory_bytes: 3624
def main():
    import sys
    input = sys.stdin.readline
    N, M = map(int, input().split())
    INF = float('inf')
    D = [[INF]*N for _ in [0]*N]
    for _ in [0]*M:
        a, b, c = map(int, input().split())
        D[a][b] = c

    for i in range(N):
        D[i][i] = 0

    for i in range(N):
        for j in range(N):
            for k in range(N):
                d = D[j][i]+D[i][k]
                if D[j][k] > d:
                    D[j][k] = d

    for i in range(N):
        if D[i][i] < 0:
            print('NEGATIVE CYCLE')
            return

    for d in D:
        print(' '.join(map(lambda x: str(x) if x < INF else 'INF', d)))


if __name__ == '__main__':
    main()



Measured memory_bytes: 6080
#include <iostream>
#include <algorithm>
using namespace std;
int main(void){
    // Your code here!
    string s;
    cin >> s;
    string t;
    cin >> t;
    sort(s.begin(), s.end());
    sort(t.begin(), t.end(), greater<char>());
    
    if(s < t) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
/* typedef */
typedef long long ll;
typedef pair<int, int> pii;
/* constant */
const int INF = 1 << 30;
const ll LINF = 1LL << 50;
const int NIL = -1;
const int MAX = 10000;
const int mod = 1000000007;
const double pi = 3.141592653589;
/* global variables */
/* function */
/* main */
int main(){
    int n, a;
    cin >> n >> a;
    if (n % 500 <= a) cout << "Yes" << '\n';
    else cout << "No" << '\n';
}


Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <string>
#include <algorithm>
#include <set>
#include <vector>
#include <map>
#include <list>
#include <stack>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <queue>
#define mkp(a, b) make_pair(a, b)
#define pb(t) push_back(t)
#define ft first
#define sc second
#define pt(num) cout << num << "\n"
#define moC(a, s, b) (a)=((a)s(b)+MOD)%MOD
#define max(a, b) ((a)>(b) ? (a):(b))
#define min(a, b) ((a)<(b) ? (a):(b))
#define chmax(a, b) (a<b ? a=b : 0)
#define chmin(a, b) (a>b ? a=b : 0)
#define INF 1000000000000000000
#define MOD 1000000007LL
#define MAX 101010
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef map<ll, ll> Map;




int main(void) {
    ll N, M;
    cin >> N >> M;
    ll use[10]={};
    ll cost[10]={0, 2, 5, 5, 4, 5, 6, 3, 7, 6};
    ll i, j;
    
    for(i=1; i<=M; i++) {
        ll a;
        cin >> a;
        use[a]=1;
    }
    
    string dp[11111];
    for(i=0; i<=N; i++) dp[i]="";
    
    for(i=1; i<10; i++)
        if(use[i]) dp[cost[i]]=(char)(i+'0');
    
    for(i=0; i<=N; i++) {
        if(dp[i]=="") continue;
        for(j=1; j<10; j++) {
            if(use[j]==0) continue;
            if(i+cost[j]>N) continue;
            string s=dp[i]+(char)(j+'0');
            if(dp[i+cost[j]].size()<s.size()) dp[i+cost[j]]=s;
            else if(dp[i+cost[j]].size()==s.size() && dp[i+cost[j]]<s) dp[i+cost[j]]=s;
        }
    }
    
    pt(dp[N]);
}





Measured memory_bytes: 43648
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] drink = new int[n];
        for (int i = 0; i < n; i++) {
            drink[i] = sc.nextInt();
        }
        int x = sc.nextInt();
        for (int i = 0; i < x; i++) {
            int sum = 0;
            int target = sc.nextInt();
            int change = sc.nextInt();
            int tmp = drink[target - 1];
            drink[target - 1] = change;
            for (int j = 0; j < n; j++) {
                sum += drink[j];
            }
            System.out.println(sum);
            drink[target - 1] = tmp;
        }
    }
}


Measured memory_bytes: 21972
t_life, t_attack_p, a_life, a_attack_p = readline.split(' ').map(&:to_i)

a_attack_count = (t_life / a_attack_p) + ((t_life % a_attack_p).zero? ? 0:1)
t_attack_count = (a_life / t_attack_p) + ((a_life % t_attack_p).zero? ? 0:1)

if a_attack_count >= t_attack_count
  puts "Yes"
else
  puts "No"
end


Measured memory_bytes: 14304
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; ++i)
#define ALL(v) v.begin(), v.end()
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1000000007;

int main()
{
   int h ,w;
   cin >> h >> w;
   vector<string> s(h);
   rep(i,h)cin >> s[i];
   vector<vector<char>> ans(h,vector<char>(w,'0'));
   rep(i,h)
   {
      rep(j,w)
      {
         if(s[i][j]=='#')
         {
            ans[i][j]='#';
            if(i-1>=0)        if(ans[i-1][j]!='#')  ans[i-1][j]++;
            if(i-1>=0&&j-1>=0)if(ans[i-1][j-1]!='#')ans[i-1][j-1]++;
            if(i-1>=0&&j+1<w) if(ans[i-1][j+1]!='#')ans[i-1][j+1]++;
            if(i+1<h&&j-1>=0) if(ans[i+1][j-1]!='#')ans[i+1][j-1]++;
            if(i+1<h)         if(ans[i+1][j]!='#')  ans[i+1][j]++;
            if(i+1<h&&j+1<w)  if(ans[i+1][j+1]!='#')ans[i+1][j+1]++;
            if(j+1<w)         if(ans[i][j+1]!='#')  ans[i][j+1]++;
            if(j-1>=0)        if(ans[i][j-1]!='#')  ans[i][j-1]++;
         }
      }
   }
   rep(i,h)
   {
      rep(j,w)
      {
         cout<<ans[i][j];
      }
      cout<<endl;
   }
   return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include <numeric>
#include <functional>
#include <map>
#include <set>
#define Rep(i, n) for(int i=0;i<n;++i)
#define rep(i, n) for(int i=1;i<=n;++i)
#define ll long long
#define INF 10e9

using namespace std;
using P = pair<int, int>;
 
int dx[4] = {0, 1, 0, -1};
int dy[4] = {1, 0, -1, 0};

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

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

int N;
deque<double> que;
int main () {
  cin >> N;
  Rep(i, N) {
    int tmp;
    cin >> tmp;
    que.push_back(tmp);
  }

  sort(que.begin(), que.end());

  Rep(i, N-1) {
    double f = que.front(); que.pop_front();
    double s = que.front(); que.pop_front();
    double ave = (f + s) / 2.0;
    que.push_front(ave);
  }

  printf("%.10f\n", que[0]);
}

Measured memory_bytes: 256
let partition a p r =
  let x = a.(r) in
  let swap i j =
    let t = a.(i) in a.(i) <- a.(j); a.(j) <- t
  in
  let rec doit i j =
    if j >= r then i
    else begin
      if a.(j) <= x then (swap (i + 1) j; doit (i + 1) (j + 1))
      else doit i (j + 1)
    end
  in
  let i = doit (p - 1) p in
  swap (i + 1) r;
  i + 1

let () =
  let n = read_int () in
  let a = Array.init n (fun _ -> Scanf.scanf "%d " (fun e -> e)) in
  let k = partition a 0 (n - 1) in
  Array.iteri (fun i e ->
    Printf.printf (if i = 0 then "%d" else if i = k then " [%d]" else " %d") e) a;
  print_newline ()

Measured memory_bytes: 5464
def LCS():
  X = raw_input()
  Y = raw_input()
  a = len(X)
  b = len(Y)
  c = [ 0 for i in range(b+1) ]
  
  for i in range(a):
    d = c + []
    for j in range(b):
      if X[i] == Y[j]:
        c[j+1] = d[j] + 1
      elif c[j+1] < c[j]:
        c[j+1] = c[j]
  
  return c[-1]
  
q = input()
for k in range(q):
  print LCS()

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

int top,s[1000];
void push(int x){
	s[++top]=x;
}
int pop(){
	top--;
	return s[top+1];
}
int main(){

	int a,b;
	top=0;
	char s[100];
	
	while( scanf("%s",s) != EOF){
		if(s[0]=='+'){
			a=pop();
			b=pop();
			push(a+b);
		}else if(s[0]=='-'){
			b=pop();
			a=pop();
			push(a-b);
		}else if(s[0]=='*'){
			a=pop();
			b=pop();
			push(a*b);
		}else{
			push(atoi(s));
		}
	}
	
	printf("%d\n",pop());
	
	return 0;
}


Measured memory_bytes: 2736
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,m,x;
    cin>>n>>m;
    if(n<=m)
    {
        while(m--) cout<<n;
        cout<<"\n";
    }
    else {
         while(n--) cout<<m;
        cout<<"\n";
    }
    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <vector>
#include <map>

#define MOD 1000000007

using namespace std;

typedef long long ll;

vector< pair<ll, ll> > dp;
vector< vector<int> > e;

pair<ll, ll> solve(ll root, ll v) {
    for (int dv : e.at(v)) if (root != dv) {
        pair<ll, ll> s = solve(v, dv);
        (dp.at(v).first *= s.first) %= MOD;
        (dp.at(v).second *= s.second) %= MOD;
    }
    return {(dp.at(v).first + dp.at(v).second) % MOD, dp.at(v).first};
}

int main() {
    int n, x, y;
    scanf("%d", &n);
    dp = vector< pair<ll, ll> >(n + 1, {1, 1});
    e.resize(n + 1);
    for (int i = 0; i < n - 1; ++i) {
        scanf("%d%d", &x, &y);
        e.at(x).push_back(y);
        e.at(y).push_back(x);
    }
    printf("%lld\n", solve(0, 1).first);
    return 0;
}

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

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef pair<int, int> pii;
typedef pair<char, char> pcc;

#define FOR(i, begin, end) for(int i = (begin); i < (end); i++)
#define rep(i, n) FOR(i,0,n)
#define ALL(a) (a).begin(),(a).end()
#define ZP(a, len) cout << setfill('0') << setw(len) << right << a << endl;
const int INF = 1e9;
const int MOD = 1e9 + 7;
const int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0};

signed main() {
    int n, t;
    cin >> n >> t;
    int ans = 10000;
    rep(i, n) {
        int co, ti;
        cin >> co >> ti;
        if (ti <= t) {
            ans = min(ans, co);
        }
    }

    if (ans == 10000) {
        cout << "TLE" << endl;
    } else {
        cout << ans << endl;
    }
    return 0;
}

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

using namespace std;

#ifdef NeverBeRed
#include "debug.h"
#else
#define debug(...) 9715
#endif
typedef long long ll;
typedef long double ld;
typedef complex<ld> point;
#define F first
#define S second



int main()
{
	#ifdef TurnRed
		//freopen("a.in", "r", stdin);
		//freopen("a.out", "w", stdout);
	#endif

	ios_base::sync_with_stdio(0), cin.tie(0);

	int n, k;
	cin >> n >> k;
	vector<int> a(n);
	for (auto &i : a) cin >> i;

	while (k--)
	{
		vector<int> b(n);
		for (int i = 0; i < n; ++i)
		{
			++b[max(0, i - a[i])];
			if (i + a[i] + 1 < n) --b[i + a[i] + 1];
		}
		partial_sum(b.begin(), b.end(), b.begin());
		if (a == b) break;
		a = b;
	}
  
  	for (auto &i : a) cout << i << " \n"[&i==&a.back()];

	return 0;
}


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

typedef long long ll;

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

  int ans = 0;
  for (int i = 0; i < S.size(); i++) {
    if (S[i] == '+') {
      ans++;
    } else {
      ans--;
    }
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 256
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<n; ++i)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
using namespace std;
using ll = int64_t;
using P = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vi>;

struct UnionFind {
    vector<int> par; // 親を指すvector,-par[親]は木のサイズ
    UnionFind(int n):par(n, -1) {} // uniteで親を埋め込んでいく必要あり
    int root(int x) { // 親をたどる&データの整理
        if(par[x] < 0) return x;
        return par[x] = root(par[x]);
    }
    bool unite(int x, int y) { // データの結合
        x = root(x);
        y = root(y);
        if(x == y) return false;
        if(par[x] > par[y]) swap(x, y);
        par[x] += par[y];
        par[y] = x;
        return true;
    }
    bool same(int x, int y) {return root(x) == root(y);} // 所属判定
    int size(int x) {return -par[root(x)];} // 木のサイズ
} uft(101);

int main() {
    int n;
    cin >> n;
    rep(i, n/2) {
        if(n&1) uft.unite(i+1, n-i-1);
        else uft.unite(i+1, n-i);
    }

    cout << n*(n-1)/2 - n/2 << endl;

    rep(i, n) {
        rep(j, i) {
            if(!uft.same(i+1, j+1)) {
                cout << i+1 << ' ' << j+1 << '\n';
            }
        }
    }
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <algorithm>
#define inf 2000000005
using namespace std;

int n,X,Y,Z,i,j,k,l,u,v;
int id[100005];
long long Max1[400005],Max2[400005],Max3[400005];
int Max1_id[400005],Max2_id[400005],Max3_id[400005];
int A[100005],B[100005],C[100005];
long long ans,val1,val2;

inline bool cmp(const int &a,const int &b){return A[a]-B[a]>A[b]-B[b];}
void update(long long *Max,int *id,int x,long long val)
{
	int w=l+x-1;
	Max[w]=val;id[w]=x;
	for(w>>=1;w;w>>=1)
	if(Max[w<<1]>Max[w<<1|1])Max[w]=Max[w<<1],id[w]=id[w<<1];
	else Max[w]=Max[w<<1|1],id[w]=id[w<<1|1];
}

int main()
{
	scanf("%d%d%d",&X,&Y,&Z);n=X+Y+Z;
	for(i=1;i<=n;++i)scanf("%d%d%d",&A[i],&B[i],&C[i]),id[i]=i;
	sort(id+1,id+n+1,cmp);
	for(i=1;i<=X;++i)ans+=A[id[i]];
	for(i=X+1;i<=n;++i)ans+=B[id[i]];
	
	for(l=1;l<=n;l<<=1);
	for(i=1;i<=l+l;++i)Max1[i]=Max2[i]=Max3[i]=-inf;
	for(i=1;i<=X;++i)update(Max1,Max1_id,id[i],C[id[i]]-A[id[i]]);
	for(i=X+1;i<=n;++i)
	{
		update(Max2,Max2_id,id[i],A[id[i]]-B[id[i]]);
		update(Max3,Max3_id,id[i],C[id[i]]-B[id[i]]);
	}
	
	for(i=1;i<=Z;++i)
	{
		val1=Max1[1]+Max2[1];
		val2=Max3[1];
		if(val1>val2)
		{
			ans+=val1;u=Max1_id[1];v=Max2_id[1];
			update(Max1,Max1_id,u,-inf);
			update(Max1,Max1_id,v,C[v]-A[v]);
			update(Max2,Max2_id,v,-inf);
			update(Max3,Max3_id,v,-inf);
		}
		else
		{
			ans+=val2;u=Max3_id[1];
			update(Max2,Max2_id,u,-inf);
			update(Max3,Max3_id,u,-inf);
		}
	}
	printf("%lld\n",ans);
}

Measured memory_bytes: 14720
#[allow(unused_imports)]
use std::cmp::{max, min, Ordering};
#[allow(unused_imports)]
use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, VecDeque};
#[allow(unused_imports)]
use std::io::{stdin, stdout, BufWriter, Write};
#[allow(unused_imports)]
use std::iter::FromIterator;
mod util {
    use std::fmt::Debug;
    use std::io::{stdin, stdout, BufWriter, StdoutLock};
    use std::str::FromStr;
    #[allow(dead_code)]
    pub fn line() -> String {
        let mut line: String = String::new();
        stdin().read_line(&mut line).unwrap();
        line.trim().to_string()
    }
    #[allow(dead_code)]
    pub fn chars() -> Vec<char> {
        line().chars().collect()
    }
    #[allow(dead_code)]
    pub fn gets<T: FromStr>() -> Vec<T>
    where
        <T as FromStr>::Err: Debug,
    {
        let mut line: String = String::new();
        stdin().read_line(&mut line).unwrap();
        line.split_whitespace()
            .map(|t| t.parse().unwrap())
            .collect()
    }
    #[allow(dead_code)]
    pub fn with_bufwriter<F: FnOnce(BufWriter<StdoutLock>) -> ()>(f: F) {
        let out = stdout();
        let writer = BufWriter::new(out.lock());
        f(writer)
    }
}
#[allow(unused_macros)]
macro_rules ! get { ( [ $ t : ty ] ) => { { let mut line : String = String :: new ( ) ; stdin ( ) . read_line ( & mut line ) . unwrap ( ) ; line . split_whitespace ( ) . map ( | t | t . parse ::<$ t > ( ) . unwrap ( ) ) . collect ::< Vec < _ >> ( ) } } ; ( [ $ t : ty ] ; $ n : expr ) => { ( 0 ..$ n ) . map ( | _ | get ! ( [ $ t ] ) ) . collect ::< Vec < _ >> ( ) } ; ( $ t : ty ) => { { let mut line : String = String :: new ( ) ; stdin ( ) . read_line ( & mut line ) . unwrap ( ) ; line . trim ( ) . parse ::<$ t > ( ) . unwrap ( ) } } ; ( $ ( $ t : ty ) ,* ) => { { let mut line : String = String :: new ( ) ; stdin ( ) . read_line ( & mut line ) . unwrap ( ) ; let mut iter = line . split_whitespace ( ) ; ( $ ( iter . next ( ) . unwrap ( ) . parse ::<$ t > ( ) . unwrap ( ) , ) * ) } } ; ( $ t : ty ; $ n : expr ) => { ( 0 ..$ n ) . map ( | _ | get ! ( $ t ) ) . collect ::< Vec < _ >> ( ) } ; ( $ ( $ t : ty ) ,*; $ n : expr ) => { ( 0 ..$ n ) . map ( | _ | get ! ( $ ( $ t ) ,* ) ) . collect ::< Vec < _ >> ( ) } ; }
#[allow(unused_macros)]
macro_rules ! debug { ( $ ( $ a : expr ) ,* ) => { eprintln ! ( concat ! ( $ ( stringify ! ( $ a ) , " = {:?}, " ) ,* ) , $ ( $ a ) ,* ) ; } }
const BIG_STACK_SIZE: bool = true;
#[allow(dead_code)]
fn main() {
    use std::thread;
    if BIG_STACK_SIZE {
        thread::Builder::new()
            .stack_size(32 * 1024 * 1024)
            .name("solve".into())
            .spawn(solve)
            .unwrap()
            .join()
            .unwrap();
    } else {
        solve();
    }
}
fn solve() {
    let x = get!(usize);

    if [7, 5, 3].into_iter().any(|&y| x == y) {
        println!("YES");
    } else {
        println!("NO");
    }
}


Measured memory_bytes: 8572
//
//  main.cpp
//  programs
//
//  Created by Arunesh Sarker on 18/11/19.
//  Copyright © 2019 Arunesh Sarker. All rights reserved.
//

#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <cctype>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <functional>
#include <unordered_set>
#include <unordered_map>
#include <cstdlib>
using namespace std;
vector<string> st;
typedef unsigned long long ll;
#define mod 1000000007
     
  // Function to return LCM of two numbers
int fact(int n)
{
    // single line to find factorial
    return (n==1 || n==0) ? 1: n * fact(n - 1);
}
 ll gcd(ll a, ll b)
 {
     if (a == 0)
         return b;
     return gcd(b % a, a);
 }
   
 // Function to find gcd of array of
 // numbers
 ll findGCD(ll arr[], ll n)
 {
     ll result = arr[0];
     for (ll i = 1; i < n; i++)
     {
         result = gcd(arr[i], result);
   
         if(result == 1)
         {
            return 1;
         }
     }
     return result;
 }
ll findlcm(ll arr[], ll n)
{
    // Initialize result
    ll ans = arr[0];
  
    // ans contains LCM of arr[0], ..arr[i]
    // after i'th iteration,
    for (ll i = 1; i < n; i++)
        ans = (((arr[i] * ans)) /
                (gcd(arr[i], ans)));
  
    return ans;
}
bool check(ll n)
{
    while(n>0)
    {
        ll t=n%10;
        if(t!=9)
            return false;
        n/=10;
    }
    return true;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int t;
    int h,a;
    cin>>h>>a;
    
    if(a>h)
        cout<<1<<"\n";
    else
    {
        double d=h*1.0;
        cout<<(int)(ceil(d/a))<<"\n";
    }
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<map>
#include<math.h>
#include<algorithm>
#include<iomanip>
#include<deque>

typedef long long ll;
typedef unsigned long long ull;
typedef int itn;
const ll LINF = 1e18;
const int INF = 1e8;

using namespace std;

#define vvint(vec,n,m,l) vector<vector<int>> vec(n,vector<int>(m,l));
#define vvll(vec,n,m,l) vector<vector<ll>> vec(n,vector<ll>(m,l));
#define vint vector<int>;
#define pint pair<int,int>;
#define rep(i,a) for(int i=0;i<(a);i++)
#define all(x) (x).begin(),(x).end()
#define debug system("pause")

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

	int n, k, x, y;
	cin >> n >> k >> x >> y;

	cout << n * x + max(n - k, 0)*(y - x) << endl;

}

Measured memory_bytes: 256