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

int main(){
  int N;
  cin>>N;
  double sum=0,count=1;
  vector<pair<int,int>> xy(N);
  vector<int> v(N);
  for(int i=0; i<N; i++){
    cin>>xy.at(i).first>>xy.at(i).second;
    v.at(i)=i;
  }
  do{
    for(int i=0; i<N-1; i++){
      sum+=sqrt(pow((xy.at(v.at(i)).first)-(xy.at(v.at(i+1)).first),2)+pow((xy.at(v.at(i)).second)-(xy.at(v.at(i+1)).second),2));
    }
  }while(next_permutation(v.begin(),v.end()));
  for(int i=1; i<=N; i++){
    count*=i;
  }
  sum/=count;
  //cout<<sum<<endl<<count<<endl;
  printf("%.10f\n",sum);
}


Measured memory_bytes: 3776
import sys
import os
import math

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]

MOD = 10 ** 9 + 7


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    N, K = il()
    H = il()
    H.sort(reverse=True)
    print(sum(H)-sum(H[0:K]))


if __name__ == '__main__':
    main()


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

int N;
int A[200010], B[200010];
vector<int> C, D;

int f(int x) {
    int s = 0, e = N - 1, p = -1;
    while(s <= e) {
        int m = (s + e)>>1;

        if(D[m] < x) {
            p = m;
            s = m + 1;
        }
        else e = m - 1;
    }
    return p + 1;
}
int g(int l, int r) {
    if(l > r) return 0;
    return f(r + 1) - f(l);
}

int main() {
    scanf("%d", &N);

    for(int i = 0; i < N; i++) {
        scanf("%d", &A[i]);
    }
    for(int i = 0; i < N; i++) {
        scanf("%d", &B[i]);
    }

    int ans = 0;
    for(int i = 0; i < 30; i++) {
        C.clear();
        D.clear();
        for(int j = 0; j < N; j++) {
            C.push_back(A[j] % (1 << (i + 1)));
            D.push_back(B[j] % (1 << (i + 1)));
        }

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

        int cnt = 0;
        for(int j = 0; j < N; j++) {
            if(C[j] & (1 << i)) {
                cnt += g(0, (1 << (i + 1)) - C[j] - 1);
                cnt += g((1 << (i + 1)) + (1 << i) - C[j], (1 << (i + 1)) - 1);
            }
            else {
                cnt += g((1 << i) - C[j], (1 << (i + 1)) - C[j] - 1);
            }
        }
        if(cnt % 2) ans ^= (1 << i);
    }
    printf("%d", ans);
}


Measured memory_bytes: 3572
#include<bits/stdc++.h>
using namespace std;
#define int long long
int n,m;
vector<int>v[100001];
int vis[100001];
int node[100001];
void dfs(int x)
{ 
  vis[x]=1;
  node[x]=1;
  for(int i=0;i<v[x].size();i++)
  { 
    if(vis[v[x][i]]==0)
    {
      dfs(v[x][i]);
    }
    node[x]=max(node[v[x][i]]+1,node[x]);
  }
}
int32_t main()
{  
  cin>>n>>m;
  for(int i=0;i<m;i++)
  {
    int x,y;
    cin>>x>>y;
    v[x].push_back(y);
  }
  for(int i=1;i<=n;i++)
     {
       if(vis[i]==0)
        { 
          dfs(i);
        }
     }  
  int ans=0;
  for(int i=1;i<=n;i++)
  {
    ans=max(ans,node[i]);
    //cerr<<node[i]<<endl;
  }
  cout<<ans-1;
}


Measured memory_bytes: 9344
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx")
using namespace std;

using ll = long long;
using ull = unsigned long long;
using ld = long double;

#define forn(i, a, n) for (int i = (int)(a); i < (int)(n); ++i)
#define ford(i, a, n) for (int i = (int)(n) - 1; i >= (int)(a); --i)
#define fore(i, a, n) for (int i = (int)(a); i <= (int)(n); ++i)
#define all(a) (a).begin(), (a).end()
#define fs first
#define sn second
#define trace(a)\
    for (auto i : a) cerr << i << ' ';\
    cerr << '\n'
#define eb emplace_back

#ifndef M_PI
const ld M_PI = acos(-1.0);
#endif

template<typename T>
inline void setmax(T& a, T b) {
    if (a < b) a = b;
}

template<typename T>
inline void setmin(T& a, T b) {
    if (a > b) a = b;
}

template<typename T, typename S>
istream& operator>> (istream& in, pair<S, T>& p) {
    in >> p.fs >> p.sn;
    return in;
}
template<typename T, typename S>
ostream& operator<< (ostream& out, pair<S, T>& p) {
    out << p.fs << ' ' << p.sn << ' ';
    return out;
}

template<typename T>
istream& operator>> (istream& in, vector<T>& v) {
    for (T& x : v) in >> x;
    return in;
}
template<typename T>
ostream& operator<< (ostream& out, vector<T>& v) {
    for (T& x : v) out << x << ' ';
    return out;
}

const ld eps = 1e-9;
const int INF = 2000000000;
const ll LINF = 1ll * INF * INF;
const ll MOD = 1000000007;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0); 
    srand((unsigned)chrono::high_resolution_clock::now().time_since_epoch().count());
    int n;
    cin >> n;
    vector<int> a(n);
    cin >> a;
    ll ans = 0;
    int r = 0, XOR = 0;
    ll sum = 0;
    forn(i, 0, n) {
        while (r < n && sum == (ll)XOR) {
            sum += a[r];
            XOR ^= a[r];
            ++r;
        }
        if (sum != ll(XOR)) {
            --r;
            sum -= a[r];
            XOR ^= a[r];
        }
        ans += r - i;
        //cerr << i << ' ' << r << '\n';
        sum -= a[i];
        XOR ^= a[i];
    }
    cout << ans << '\n';
}


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

struct RollingHash{
    static const int B1=1007,B2=2009;
    static const int mod1=1000000007,mod2=1000000009;
    vector<long long> hash1,hash2,po1,po2;
    RollingHash(const vector<long long> &vs){init(vs);}
    RollingHash(const string &S){
        vector<long long> vs;
        for (char c:S) vs.emplace_back(c);
        init(vs);
    }
    void init(vector<long long> vs){
        int n=vs.size();
        hash1.assign(n+1,0);
        hash2.assign(n+1,0);
        po1.assign(n+1,1);
        po2.assign(n+1,1);
        for (int i=0;i<n;++i){
            hash1[i+1]=(hash1[i]*B1+vs[i])%mod1;
            hash2[i+1]=(hash2[i]*B2+vs[i])%mod2;
            po1[i+1]=po1[i]*B1%mod1;
            po2[i+1]=po2[i]*B2%mod2;
        }
    }
    inline pair<long long,long long> get(int l,int r) const{
        long long res1=hash1[r]+mod1-hash1[l]*po1[r-l]%mod1
                ,res2=hash2[r]+mod2-hash2[l]*po2[r-l]%mod2;
        return {res1>=mod1?res1-mod1:res1,res2>=mod2?res2-mod2:res2};
    }
    inline int LCP(int a,int b) const{
        int len=min((int)hash1.size()-a,(int)hash1.size()-b);
        int lb=0,ub=len;
        while(ub-lb>1){
            int mid=(lb+ub)>>1;
            (get(a,a+mid)==get(b,b+mid)?lb:ub)=mid;
        }
        return lb;
    }
};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    string T,P; cin >> T >> P;
    int t=T.size(),p=P.size();
    RollingHash rh1(T),rh2(P);
    for (int i=0;i<t-p+1;++i){
        if (rh1.get(i,i+p)==rh2.get(0,p)){
            cout << i << endl;
        }
    }
}


Measured memory_bytes: 51880
#include<iostream>
#include<vector>
#include<complex>
using namespace std;
int main() {
	double n;
	cin >> n;
	vector<double>a(n);
	double sum = 0;
	for (int i = 0;i < n;i++) {
		cin >> a[i];
		sum += a[i];
	}
	sum /= n;
	double min = 10000;
	int number = -1;
	for (int i = 0;i < n;i++) {
		if (abs(sum - a[i]) < min) {
			min = abs(sum - a[i]);
			number = i;
		}
	}
	cout << number << endl;
	return 0;
}

Measured memory_bytes: 256
from sys import stdin

n = int(stdin.readline().rstrip())
li = [list(map(int,stdin.readline().rstrip().split())) for _ in range(n)]

dp = [[-1 for p in range(3)] for q in range(n+1)]
for a in range(3):
    dp[0][a] = 0
for i in range(1,n+1):
    for j in range(3):
        lin = []
        for k in range(3):
            if j != k:
                lin.append((dp[i-1][k]+li[i-1][j]))
        dp[i][j] = max(lin)
print(max(dp[-1]))

Measured memory_bytes: 47344
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
using namespace std;
 
#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()
 
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef vector<VI> VVI;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

int in() { int x; scanf("%d", &x); return x; }
ll lin() { ll x; scanf("%lld", &x); return x; }

const ll mod = 1e9 + 7;

void compress_coordinate(VI &x){
    int n = x.size();
    VI xc;
    xc.push_back(-1);
    REP(i,n) xc.push_back(x[i]);
    sort(ALL(xc));
    xc.erase(unique(ALL(xc)), xc.end());
    map<int,int> mp;
    REP(i,xc.size()) mp[xc[i]] = i;
    REP(i,n) x[i] = mp[x[i]];
}

struct BIT{
    int n;
    VL bit;

    BIT(){}
    BIT(int x){
        n = x;
        bit.assign(n+1, 0);
    }

    void init(int x){
        n = x;
        bit.assign(n+1, 0);
    }

    void add(int i, ll x){
        i++;
        while (i <= n){
            (bit[i] += x) %= mod;
            i += i & -i;
        }
    }

    // [0, i]
    ll sum(int i){
        i++;
        ll ret = 0;
        while (i > 0){
            (ret += bit[i]) %= mod;
            i -= i & -i;
        }
        return ret;
    }

    // [l, r)
    ll sum(int l, int r){
        if (l >= r) return 0;
        return (sum(r-1) - sum(l-1) + mod) % mod;
    }
};

int main() {
    int n, m;
    cin >> n >> m;
    VI x(n), y(m);
    REP(i,n) x[i] = in();
    REP(i,m) y[i] = in();
    VI l, r;
    int k = 0;
    REP(i,n){
        while (k < m && x[i] >= y[k]) k++;
        if (k == 0 || k == m) continue;
        l.push_back(x[i] - y[k-1]);
        r.push_back(y[k] - x[i]);
    }

    n = l.size();

    compress_coordinate(l);
    compress_coordinate(r);

    vector<P> pa(n);
    REP(i,n) pa[i] = P(l[i], -r[i]);
    sort(ALL(pa));

    VVI p(n+1);
    REP(i,n){
        p[pa[i].first].push_back(-pa[i].second);
    }

    BIT bit(n+1);
    bit.add(0, 1);
    REP(i,n+1){
        REP(j,p[i].size()){
            if (j > 0 && p[i][j] == p[i][j-1]) continue;
            int x = p[i][j];
            bit.add(x, bit.sum(x - 1));
        }
    }

    ll ans = bit.sum(n);
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 8412
#include <ios>
#include <iomanip>
#include <iostream>
#include <functional>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <climits>

using namespace std;
typedef long long int ll;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define MOD 1000000007
#define INF (1e9)
#define PI (acos(-1))
#define print(x) cout << x << endl
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl

ll gcd(ll a, ll b) { return b ? gcd(b,a%b) : a;}
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
typedef pair <ll,ll> P;

int main()
{
    ll N;
    cin >> N;
    ll sum = 0;
    rep(i, N) {
        ll l, r;
        cin >> l >> r;
        sum += r-l+1;
    }
    print(sum);
    return 0;
}


Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		String correct = "Yes";
		String incorrectAnswer = "No";
		boolean flag = true;

		Scanner scan = new Scanner(System.in);

		List<String> str = new ArrayList<>();
		str.add(scan.next());
		str.add(scan.next());
		str.add(scan.next());

		for (String s : str) {
			if (!s.equals(str.get(0))) {
				flag = false;
				break;
			}
		}

		if (flag) {
			System.out.println(correct);
		} else {
			System.out.println(incorrectAnswer);
		}
	}
}


Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define rep( i, n, m ) for(int i = ( n ); i < ( m ); i++)
#define rep_d( i, n, m ) for(int i = ( n ) - 1; i >= ( m ); i--)
#define sort_asc( X ) sort(( X ).begin(), ( X ).end())
#define sort_desc( X ) sort(( X ).begin(), ( X ).end(), greater <>())

template <class T> bool chmax( T& a, T b );
template <class T> bool chmin( T& a, T b );
int* eratosthenes( int N );
bool bit_search( int pattern, int N );
template <class T> void cumulative_sum( T array, size_t N );

const ll INF = 1LL << 60;
const int k_mod = 1e9 + 7;

typedef struct {
	vector <int> to;
	int cost;
} edge;
typedef struct {
	int a;
	int b;
} P;
int main( void ){
	ll N, K; cin >> N >> K;
	vector <int> input( N );
	vector <P> n( N );
	rep( i, 0, N )
	cin >> input[ i ];
	rep( i, 0, N ){
		int cnt_a = 0, cnt_b = 0;
		rep( j, i + 1, N )
		if (input[ i ] > input[ j ])
			cnt_a++;
		rep_d( j, i, 0 )
		if (input[ i ] > input[ j ])
			cnt_b++;
		n[ i ] = P{cnt_a, cnt_b};
	}
	ll sum_a = 0, sum_b = 0;
	rep( i, 0, N ){
		sum_a += n[ i ].a;
		sum_b += n[ i ].b;
	}
	ll k_a = ( K * ( K + 1 ) / 2 ) % k_mod;
	ll k_b = ( K * ( K - 1 ) / 2 ) % k_mod;
	sum_a = ( sum_a * k_a ) % k_mod;
	sum_b = ( sum_b * k_b ) % k_mod;
	cout << ( sum_a + sum_b ) % k_mod << endl;
}

int* eratosthenes( int N ){
	int* prime_array = new int[ N + 1 ];
	int lim = N;
	prime_array[ 0 ] = 0;
	prime_array[ 1 ] = 0;
	rep( i, 2, N + 1 ){
		prime_array[ i ] = 1;
	}
	rep( i, 2, lim ){
		if (prime_array[ i ] == 0)
			continue;
		lim = N / i;
		for(int j = i * 2; j < N + 1; j += i){
			prime_array[ j ] = 0;
		}
	}
	return prime_array;
}
template <class T> void cumulative_sum( T array, size_t N ) {
	rep( i, 1, N + 1 ){
		array[ i ] += array[ i - 1 ];
	}
}
template <class T> bool chmax( T& a, T b ) {
	if (a < b){
		a = b; return true;
	}
	return false;
}
template <class T> bool chmin( T& a, T b ) {
	if (a > b){
		a = b; return true;
	}
	return false;
}
bool bit_search( int pattern, int N ){
	int cnt = 0;
	rep( bit, 0, N ){
		if (pattern & ( 1 << bit )){
			cnt++;
		}
	}
	return true;
}


Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#pragma GCC optimize("no-stack-protector")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("unswitch-loops")
#pragma GCC optimize("fast-math")

#pragma GCC target("sse2")
#pragma GCC target("sse3")
#pragma GCC target("ssse3")
#pragma GCC target("sse4.1")
#pragma GCC target("sse4.2")
#pragma GCC target("avx")
#pragma GCC target("popcnt")
#pragma GCC target("abm")
#pragma GCC target("mmx")
#pragma GCC target("tune=native")
#include <iostream>
#include <vector>
#define int long long
using namespace std;
int mod = 1e9 + 7;
int powp(int a, int p) {
	if (p == 0)
		return 1;
	else if (p & 1)
		return powp(a, p - 1) * a % mod;
	else {
		int ans = powp(a, p >> 1);
		return ans * ans % mod;
	}
}
int f(int x) {
	int ans = 0;
	while (x) {
		++ans;
		x /= 10;
	}
	return ans;
}
int len(int l, int r) {
	return max(0ll, r - l + 1);
}
signed main() {
	int s;
	cin >> s;
	int sum = 0;
	int r = 0;
	int ans = 0;
	int lenl = 0;
	int lenr = 0;
	int powl = 1;
	int powr = 1;
	for (int l = 1; l < (int)1e7; ++l)  {
		sum -= f(l - 1);
		while (sum < s) {
			++r;
			if (r == powr) {
				++lenr;
				powr *= 10;
			}
			sum += f(r);
		}
		if (sum == s)
			++ans;
		if (l == powl) {
			++lenl;
			powl *= 10;
		}
		
	}

	for (int n = 8; n <= s / 2; ++n) {
		// n * a + (n + 1) * b = S
		// a = -S
		// b = S
		// a' = -S + (n + 1) * k
		// b' = S - n * k
		//
		// a' > 0
		// -S + (n + 1) * k > 0
		// S < (n + 1) * k
		//
		// b' > 0
		// S - n * k > 0
		// S > n * k
		//

		int l = s / (n + 1) + 1;
		int r = (s - 1) / n;

		ans = (ans + r - l + 1);
		if (ans >= mod)
			ans -= mod;
	}
	//cout.precision(40);
	//cout << (double)clock() / CLOCKS_PER_SEC << endl;
	vector<int> divs;
	for (int n = 1; n * n <= s; ++n) {
		if (s % n == 0) {
			if (n >= 8)
				divs.push_back(n);
			if (s / n >= 8)
				divs.push_back(s / n);
			if (n * n == s && n >= 8)
				divs.pop_back();
		}
	}
	for (int n : divs) {
		if (s % n == 0) {
			int cnt = powp(10, n - 1) * 9 % mod;
			int l = s / n;
			ans = (ans + cnt - l + 1);
			if (ans < 0)
				ans += mod;
			if (ans >= mod)
				ans -= mod;
		}
	}
	//cout << (double)clock() / CLOCKS_PER_SEC << endl;
	cout << ans;
	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <bits/stdc++.h>
#include <cstdint>
#include <iostream>
#include <iterator>
#include <vector>

// lib/util.hpp
#ifndef UTIL_HPP
#define UTIL_HPP


typedef std::int_fast64_t i64;
typedef std::uint_fast64_t u64;
typedef std::int_fast32_t i32;
typedef std::uint_fast32_t u32;

namespace tools {
  template <typename T>
  void read(std::vector<T>& vector, const typename std::vector<T>::size_type size) {
    vector.reserve(size);
    std::copy_n(std::istream_iterator<T>(std::cin), size, std::back_inserter(vector));
  }

  template <typename T, std::size_t N>
  void read(std::array<T, N>& array) {
    std::copy_n(std::istream_iterator<T>(std::cin), N, array.begin());
  }
}

#endif

// main.cpp

int main() {
  i64 H, W;
  std::cin >> H >> W;
  std::vector<std::string> S;
  tools::read(S, H);

  std::vector<std::vector<i64>> L(H, std::vector<i64>(W));
  for (i64 y = 0; y < H; ++y) {
    i64 combo = 0;
    for (i64 x = 0; x < W; ++x) {
      if (S[y][x] == '#') {
        combo = 0;
      } else {
        ++combo;
      }
      L[y][x] = combo;
    }
  }

  std::vector<std::vector<i64>> R(H, std::vector<i64>(W));
  for (i64 y = 0; y < H; ++y) {
    i64 combo = 0;
    for (i64 x = W - 1; x >= 0; --x) {
      if (S[y][x] == '#') {
        combo = 0;
      } else {
        ++combo;
      }
      R[y][x] = combo;
    }
  }

  std::vector<std::vector<i64>> U(H, std::vector<i64>(W));
  for (i64 x = 0; x < W; ++x) {
    i64 combo = 0;
    for (i64 y = 0; y < H; ++y) {
      if (S[y][x] == '#') {
        combo = 0;
      } else {
        ++combo;
      }
      U[y][x] = combo;
    }
  }

  std::vector<std::vector<i64>> D(H, std::vector<i64>(W));
  for (i64 x = 0; x < W; ++x) {
    i64 combo = 0;
    for (i64 y = H - 1; y >= 0; --y) {
      if (S[y][x] == '#') {
        combo = 0;
      } else {
        ++combo;
      }
      D[y][x] = combo;
    }
  }

  i64 answer = 0;
  for (i64 y = 0; y < H; ++y) {
    for (i64 x = 0; x < W; ++x) {
      if (S[y][x] == '.') {
        answer = std::max(answer, L[y][x] + R[y][x] + U[y][x] + D[y][x] - 3);
      }
    }
  }

  std::cout << answer << std::endl;
  return 0;
}

Measured memory_bytes: 129664
while True:
    n = int(raw_input())
    if n == 0:
        break
    numbers = [int(raw_input()) for i in range(n)]
    if max(numbers) <= 0:
        print max(numbers)
    else:
        ans = 0
        for i in range(n):
            tmp = 0
            for j in range(i,n):
                tmp += numbers[j]
                if(ans<tmp):
                    ans = tmp
        print ans

Measured memory_bytes: 23000
#include<stdio.h>
#include<math.h>
#include<string.h>
#include<string>
#include<stack>
#include<map>
#include<set>
#include<queue>
#include<iostream>
#include<algorithm>
#include<unordered_map>
#include<unordered_set>
#define PI acos(-1)
#define pb push_back
#define all(x) x.begin(),x.end()
#define INF 0x3f3f3f3f
#define dd(x) cout<<#x<<" = "<<x<<","
#define de(x) cout<<#x<<" = "<<x<<"\n"
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int N=15;
int a[N][N];
int b[N],c[N];
int ans=INF;
int n,m,x;
void dfs(int now,int cost){
	if(now==n+1){
		for(int i=1;i<=m;i++){
			if(b[i]<x){
				return;
			}
		}
		ans=min(ans,cost);
		return;
	}
	for(int i=1;i<=m;i++){
		b[i]+=a[now][i];
	}
	dfs(now+1,cost+c[now]);
	for(int i=1;i<=m;i++){
		b[i]-=a[now][i];
	}
	dfs(now+1,cost);
}
int main()
{
	scanf("%d%d%d",&n,&m,&x);
	for(int i=1;i<=n;i++){
		scanf("%d",&c[i]);
		for(int j=1;j<=m;j++){
			scanf("%d",&a[i][j]);
		}
	}
	dfs(1,0);
	if(ans==INF){
		printf("-1");
	}
	else{
		printf("%d",ans);
	}
}


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

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0); 
	
	int n, x;
	cin >> n >> x;
	vector<int> a(n);
	for(int i = 0; i < n; i++) {
		cin >> a[i];
	}
	long long tim = LLONG_MAX;
	vector<int> slide(n, INT_MAX);
	for(int i = 0; i < n; i ++) {
		long long tmp = 0;
		tmp += 1LL * i * 1LL * x;
		for(int j = 0; j < n; j++) {
			slide[j] = min(slide[j], a[(j - i + n) % n]);
		}
		for(int j = 0; j < n; j++) {
			tmp += slide[j];
		}
		tim = min(tmp, tim);
	}
	cout << tim << endl;
	return 0;
}



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

int main(){
  long long int n,a=0,b=0,count=0,ab=0,bic=0;
cin >>n;
vector<string> s(n);
for(int i=0;i<n;i++)cin>>s[i];
for(int i=0;i<n;i++){

    if(s[i][0]=='B')b++;
    if(s[i][s[i].size()-1]=='A')a++;
    if(s[i][0]!='B' && s[i][s[i].size()-1]!='A')bic++;
for(long long int j=0;j<s[i].size()-1;j++){
    if(s[i][j]=='A'&&s[i][j+1]=='B')count++;
   }
}
cout <<min(min(a,b),max(n-bic-1,(long long int)0))+count<<endl;
}


Measured memory_bytes: 768
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define gt(n) scanf("%d", &n)
#define gtll(n) scanf("%ld", &n)
#define out(n) printf("%d", n)
#define outll(n) printf("%ld", n)
#define loop(n) for(int i=0; i<n; i++)
#define MAXX 1001
#define mem(x, y) memset(x, y, sizeof(x))
#define loop1(n) for(int i=1; i<=n; i++)
#define ll long long
#define pb push_back
#define pi acos(-1)
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
//(only in c)char[33];itoa(n,buffer,base);printf("%s",buffer);
#define dec_to_bin(n) std::string binary = std::bitset<64>(n).to_string();
#define fast ios_base::sync_with_stdio(false),cin.tie(NULL)
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
int main()
{
fast;
int a,b;
cin>>a>>b;
int sum=a+b;
int sub=a-b;
int mx=max(sum,sub);
 mx=max(mx,a*b);
cout<<mx<<endl;
return 0;
}


Measured memory_bytes: 256
from collections import deque

N, Q = map(int, input().split())
Tree = [[] for i in range(N)]
for i in range(N-1):
    a, b = map(int, input().split())
    Tree[a-1].append(b-1)
    Tree[b-1].append(a-1)
    
count = [0 for i in range(N)]
for i in range(Q):
    p, x = map(int, input().split())
    count[p-1] += x

d = deque()
d.append(0)
visited = set()
while d:
    now = d.pop()
    visited.add(now)
    for v in Tree[now]:
        if v not in visited:
            d.append(v)
            count[v] += count[now]
            
print(*count)

Measured memory_bytes: 62812
#include <stdio.h>

int main(void) {
	int N, i, j;
	long long int ans = 1;
	int pat[52];
	char *S1, *S2;

	scanf("%d", &N);
	getchar();
	S1 = (char *) malloc(sizeof *S1 * N);
	S2 = (char *) malloc(sizeof *S2 * N);
	gets(S1);
	gets(S2);

	for(i = 0; i < N; i++)
		pat[i] = 0;
	j = 0;
	for(i = 0; i < N;) {
		if(S1[i] == S1[i + 1]) {
			pat[j++] = 0;
			i = i + 2;
		}
		else {
			pat[j++] = 1;
			i++;
		}
	}
	if(j == 1 && pat[0] == 0)
		ans = 6;
	else if(j == 1 && pat[0] == 1)
		ans = 3;
	else if(pat[0] == 0 && pat[1] == 0) {
		ans = 18;
	}
	else if(pat[0] == 0 && pat[1] == 1) {
		ans = 6;
	}
	else if(pat[0] == 1 && pat[1] == 0) {
		ans = 6;
	}
	else {
		ans = 6;
	}
	for(i = 1; i < j - 1; i++) {
		if(pat[i] == 0 && pat[i + 1] == 0) {
			ans *= 3;
		}
		else if(pat[i] == 0 && pat[i + 1] == 1) {
			ans *= 1;
		}
		else if(pat[i] == 1 && pat[i + 1] == 0) {
			ans *= 2;
		}
		else {
			ans *= 2;
		}
	}

	printf("%lld", ans % 1000000007);

	free(S1);
	free(S2);
	
	return 0;
}

Measured memory_bytes: 128
S = input()[::-1]
W = []
for w in ['dreamer', 'eraser', 'erase', 'dream']:
    W.append(w[::-1])
idx = 0
while 1:
    flg = False
    for w in W:
        if S.startswith(w, idx):
            idx += len(w)
            flg = True

    if not flg:
        print('NO')
        exit()
    if len(S) <= idx:
        break

print('YES')


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

int solve() {
    int N, M, a, b, v0 = -1;
    cin >> N >> M;
    vector<vector<int>> G(N);
    for ( int i = 0; i < M; i++ ) {
        cin >> a >> b;
        a--, b--;
        G[a].push_back(b);
        G[b].push_back(a);
        if ( v0 < 0 ) v0 = a;
    }

    vector<vector<int>> pt(2);
    vector<bool> used(N, false);
    function<void(int, int, int)> dfs = [&](int v, int p, int k) {
        used[v] = true;
        pt[k].push_back(v);
        for ( int u : G[v] ) {
            if ( u == p ) continue;
            if ( used[u] ) continue;
            dfs(u, v, k);
            break;
        }
    };

    used[v0] = true;
    {
        int v = G[v0][0];
        dfs(v, v0, 0);
    }
    {
        for ( int i = 1; i < G[v0].size(); i++ ) {
            int v = G[v0][i];
            if ( used[v] ) continue;
            dfs(v, v0, 1);
            break;
        }
    }
    std::reverse(pt[1].begin(), pt[1].end());

    vector<int> ans(pt[1]);
    ans.push_back(v0);
    for ( auto x : pt[0] ) ans.push_back(x);
    cout << ans.size() << "\n";
    for ( int i = 0; i < ans.size(); i++ ) {
        cout << (i != 0 ? " " : "") << ans[i] + 1;
    }
    cout << "\n";
    return 0;
}

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

Measured memory_bytes: 11060
#include<iostream>
#include<bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define ll long long
#define N 2*10e5
#define precise cout<<fixed<<setprecision(10)
#pragma GCC optimize("O0")
#pragma GCC optimize ("Ofast")
#pragma GCC target ("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize ("-ffloat-store")
#define rep(i,a,b) for(int i=a;i<b;i++)
using namespace std;
void get(ll arr[],ll n){for(ll i=0;i<n;i++) cin>>arr[i];}
int main()
{
 	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	ll x;
	cin>>x;
	ll t=100,y=0;
	while(t<x)
	{
		t+= t/100;
		y++;
	}
	cout<<y;
}



Measured memory_bytes: 3652
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<cctype>

using namespace std;

#define foreach(itm,o) for(__typeof((o).begin()) itm=(o).begin();itm!=(o).end();++itm)
const int infty = 1<<28;

struct panel{
  int depth;
  string name;
  int x1,y1,x2,y2;
  panel(int x1,int y1,int x2,int y2,string newName,int d):
    x1(x1),y1(y1),x2(x2),y2(y2),name(newName),depth(d){}
  bool isinside(int x, int y){
    return ( x1 <= x && x <= x2 && y1 <= y && y <= y2 );
  }
};

int dig(const string &s, int &pos){
  int n = 0;
  int sign=1;
  if(s[pos]=='-'){sign=-1;++pos;}
  while(isdigit(s[pos])){
    n *= 10;
    n += s[pos]-'0';
    ++pos;
  }
  return sign*n;
}

void parse(const string &s, int &pos, int depth,
	   const string &parent, map<string, vector<panel> > &M){
  string newName;
  if(pos>=s.length())return ;
  if( s[pos] == '<' ){
    ++pos;
    while(s[pos]!='>'){newName+=s[pos];++pos;}
  }
  pos++;
  int x1 = dig(s,pos);++pos;
  int y1 = dig(s,pos);++pos;
  int x2 = dig(s,pos);++pos;
  int y2 = dig(s,pos);
  //cout << newName << endl;
  M[newName];
  //.push_back(tail );
  M[parent].push_back( panel(x1,y1,x2,y2,newName,depth) );
  while( true ){
    if( s[pos]=='<'&&s[pos+1]=='/' ){
      while(s[pos]!='>')++pos;
      ++pos;
      //cout << newName << " END"<<endl;
      break;
    }else{
      //cout << newName << " HAS:"<<endl;
      parse(s,pos,depth+1,newName,M);
      if(pos>=s.length())break;
    }
  }
  return ;
}

int main(){
  while(true){
    int n;
    int pos = 0;
    string tags;
    map< string, vector<panel> > structure;
    cin >> n;if(n==0)break;
    cin >> tags;
    parse(tags,pos,0,"\0\0_0root",structure);
    
    for(int i = 0; i < n; ++i){
      int qx,qy;cin>>qx>>qy;
      int maxdepth = -1,child;
      string ans;
      for(map<string,vector<panel> >::iterator itm=structure.begin(); itm != structure.end(); ++itm){
	for(int j = 0; j < itm->second.size(); ++j){
	  if( itm->second[j].isinside(qx,qy) ){
	    int t = itm->second[j].depth;
	    if( t > maxdepth ){
	      maxdepth = t;
	      child = structure[itm->second[j].name].size();
	      ans = itm->second[j].name;
	    }
	  }
	}
      }
      if( maxdepth == -1 ){
	cout <<"OUT OF MAIN PANEL 1" << endl;
      }else{
	cout << ans << ' ' << child << endl;
      }
    }
  }
  return 0;
}

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

#define ii pair<int, int>
#define lli long long int
#define ll pair<lli, lli>
#define pb push_back
#define mp make_pair
#define fi first
#define se second

using namespace std;

int main() {
	lli n, ans = 0;
	scanf("%lld", &n);
	if (n & 1) {
		puts("0");
		return 0;
	}
	n /= 10;
	ans += n;
	while (n) {
		ans += n / 5;
		n /= 5;
	}
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		StringBuilder a = new StringBuilder(scanner.nextLine());
		int b = Integer.parseInt(scanner.nextLine());
		for (int i = 0; i < b; i++) {
			String[] c = scanner.nextLine().split(" ");
			int d = Integer.parseInt(c[1]);
			int e = Integer.parseInt(c[2]) + 1;
			if (c[0].equals("print")) {
				System.out.println(a.substring(d, e));
			} else if (c[0].equals("reverse")) {
				StringBuilder builder = new StringBuilder(a.substring(d, e))
						.reverse();
				a.replace(d, e, builder.toString());
			} else {
				a.replace(d, e, c[3]);
			}

		}
	}
}


Measured memory_bytes: 28520
#include <bits/stdc++.h>
#define rep(i, a, b) for(int i = a; i < b; i++)
#define Rep(i, a, b) for(int i = a; i <= b; i++)
#define _GLIBCXX_DEBUG
#define Vl vector<ll>
#define Vs vector<string>
#define ll long long
#define ALL(v) (v).begin(),(v).end()
using namespace std;

const double pie = acos(-1.0);

// 最大公約数
ll gcd(ll a, ll b)
{
   if (a%b == 0) {
       return(b);
   } else {
       return(gcd(b, a%b));
   }
}

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

//素数判定
bool is_prime(const unsigned n){
    switch(n){
        case 0: // fall-through
        case 1: return false;
        case 2: // fall-through
        case 3: return true;
    } // n > 3 が保証された
    if(n % 2 == 0 || n % 3 == 0) return false;
    for(unsigned i = 5; i * i <= n; i += 6) {
        if(n % i     == 0) return false; // (6の倍数)-1
        if(n % (i+2) == 0) return false; // (6の倍数)+1
    }
    return true;
}

void solve() {
    ll n; cin >> n;
    ll a[n+2];
    a[0] = 0, a[n+1] = 0;
    Rep(i, 1, n) cin >> a[i];
    ll sum = 0;
    Rep(i, 1, n+1){
        sum += abs(a[i] - a[i-1]);
    }
    Rep(i, 1, n){
        ll ans = sum;
        if(a[i] > a[i-1] && a[i] > a[i+1]) 
        ans -= abs(a[i]-max(a[i-1], a[i+1]))*2;
        else if(a[i] < a[i-1] && a[i] < a[i+1]) 
        ans -= abs(min(a[i-1], a[i+1])-a[i])*2;

        cout << ans << endl;
    }
}

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

    solve();
    return 0;
}


Measured memory_bytes: 2048
//#include <tourist>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> p;
const int INF = 1e9;
const ll LINF = ll(1e18);
const int MOD = 1000000007;
const int dx[4] = {0, 1, 0, -1}, dy[4] = {-1, 0, 1, 0};
const int Dx[8] = {0, 1, 1, 1, 0, -1, -1, -1}, Dy[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl
#define rep(i, n) for (int i = 0; i < n; i++)
#define ALL(v) v.begin(), v.end()
#define debug(v)          \
    cout << #v << ":";    \
    for (auto x : v)      \
    {                     \
        cout << x << ' '; \
    }                     \
    cout << endl;
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;
}
//cout<<fixed<<setprecision(15);有効数字15桁
//-std=c++14
//-std=gnu++17
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll x,a,b;
    cin>>x>>a>>b;
    b-=a;
    if(b<=0)cout<<"delicious"<<"\n";
    else if(x>=b)cout<<"safe"<<"\n";
    else cout<<"dangerous"<<"\n";
}


Measured memory_bytes: 256
// ==============================================
// Library
// ==============================================
#define _CRT_SECURE_NO_WARNINGS

// When you are using the gcc compiler, you need only the following lines.
// #include <bits/stdc++.h>

// When you are using other compilers, you need the following line instead.
#include <cassert>
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>

#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>

using namespace std;

// competitive macro
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (b) - 1; i >= (a); i--)
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i ,n) for (int i = (n) - 1; i >= 0; i--)
#define LL long long
#define ULL unsigned long long

// If you use this function, "cin" speeds up.
// However, you can not mix "cin" and "scanf", "cout" and "printf".
void fastIOS()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
}
// ==============================================
// ==============================================

array<int, 100000> A = { };

int main()
{
	fastIOS();

	int n;
	cin >> n;

	REP(i, n)
	{
		int tmp;
		cin >> tmp;
		A[tmp]++;
	}

	int cnt = 0;
	REP(i, 100000)
	{
		if (A[i] != 0)
			cnt++;
	}

	if (cnt % 2 == 0)
		cout << cnt - 1 << "\n";
	else
		cout << cnt << "\n";
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#include <iostream>
using namespace std;
#define ll long long
#define ld long double
#define mp make_pair
#define pb push_back
#define fo(i,n) for(ll i=0;i<n;i++)
#define fo1(i,n) for(ll i=1;i<=n;i++)
#define loop(i,a,b)for(ll i=a;i<=b;i++)
#define loopr(i,a,b)for(ll i=b;i>=a;i--)
#define all(x) x.begin(), x.end()
#define sz(x) (ll)(x).size()
#define vll vector<ll> 
#define vvl vector<vll>
#define vpll vector<pll>
#define pll pair<ll,ll>
#define F first
#define S second
#define MOD 1000000007
ll max(ll a,ll b){if (a>b) return a; else return b;}
ll gcd(ll a, ll b){if(b==0)return a;return gcd(b, a%b);}
ll lcm(ll a, ll b){return a*b/gcd(a, b);}
ll fexp(ll a, ll b){ll ans = 1;while(b){if(b&1) ans = ans*a%MOD; b/=2;a=a*a%MOD;}return ans;}
ll inverse(ll a, ll p){return fexp(a, p-2);}
int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	ll T=1;
	//cin >> T;
	ll t=0;
	while(t++<T){
		ll n,k;
		cin>>n>>k;
		vll a(n);
		fo(i,n)cin>>a[i];
		ll lo=1,hi=*max_element(all(a)),ans;
		ll m;
		while(lo<=hi){
			m=(lo+hi)/2;
			ll req=0;
			fo(i,n){
				if(a[i]%m==0)req+=a[i]/m-1;
				else req+=a[i]/m;
			}
			if(req<=k){ans=m;hi=m-1;}
			else lo=m+1;
		}
		cout<<ans<<endl;
	}
return 0;
}


Measured memory_bytes: 4688
#define  _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <math.h>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <math.h>
#include <iostream>
#include <random>
#include<map>
#include <iomanip>
#include <time.h>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include<fstream>
#include <unordered_map>
#include <cstdlib>
using namespace std;
#define Ma_PI 3.141592653589793
#define eps 0.00000001
#define LONG_INF 3000000000000000000
#define GOLD 1.61803398874989484820458
#define MAX_MOD 1000000007
#define REP(i,n) for(long long i = 0;i < n;++i)    
#define seg_size 524288
int main() {
	int n;
	cin >> n;
	for (int i = 0; i < 100; ++i) {
		for (int q = 0; q < 100; ++q) {
			if (i * 4 + q * 7 == n) {
				cout << "Yes" << endl;
				return 0;
			}
		}
	}
	cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 888
#include <bits/stdc++.h>
using namespace std;
int main() {
  string S;
  cin >> S;
  int N = S.size();
  bool finished = false;
  for(int i = 0; i < N - 1; i++) {
    for(int j = i + 1; j < N; j++) {
      if(S.at(i) == S.at(j)) {
        finished = true;
        break;
      }
    }
    if(finished) {
      break;
    }
  }
  if(finished) {
    cout << "no" << endl;
  }
  else {
    cout << "yes" << endl;
  }
}

Measured memory_bytes: 3624
#include <stdio.h>
int main(){
int num1;
scanf("%d", &num1);
 if (num1%10==7)
  printf("Yes");
 else {
  int num2=num1/10;
  if (num2%10==7)
  printf("Yes");
   else{
    int num3=num2/10;
    if (num3%10==7)
      printf("Yes");
    else
      printf("No");
   }
 }
}


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

int main()
{
   int n;
    cin >> n;
    int arr[n];
    int count=1;
    for(int i=0;i<n;i++)
    {
        cin >> arr[i];
    }
    
    int temp;
    temp=arr[0];
    for(int i=1;i<n;i++)
    {
        if(arr[i]>=temp)
        {
            count=count+1;
            temp=arr[i];
        }
    }
    
   cout << count << endl;

}

Measured memory_bytes: 256
N = int(input())
P = 0
K = 0
L = 0
ans = 0
for _ in range(N):
  s = input()
  lis = []
  for i in range(len(s) - 1):
    lis.append(s[i:i+2])
    num = lis.count("AB")
  ans += num
  if s[0] == "B" and s[-1] == "A":
    P += 1
  elif s[0] == "B":
    K += 1
  elif s[-1] == "A":
    L += 1
if P >= 1:
  ans += (P - 1)
  if K > 0 and L > 0:
    ans += 2
    ans += min(K -1, L - 1)
  elif K > 0 and L == 0:
    ans += 1
  elif K == 0 and L > 0:
    ans += 1
else:
  ans += min(K, L)
print(ans)

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

total = 0
diff_list = []
smaller_num = 0
for n in range(N):
    if A[n] < B[n]:
        total += B[n] - A[n]
        smaller_num += 1
    else:
        diff_list.append(A[n] - B[n])

diff_list = sorted(diff_list, reverse = True)
diff_total = 0
diff_count = 0
for i, diff in enumerate(diff_list):
    diff_total += diff
    if diff_total >= total:
        diff_count = i + 1
        break

if smaller_num == 0:
    print(0)
elif diff_total < total:
    print(-1)
else:
    print(smaller_num + diff_count)


Measured memory_bytes: 19060
#include <bits/stdc++.h>
#define REP(i, n) for(int i=0; i<(int)(n); i++)
#define REP1(i,a,b) for(int i=a; i<=(int)(b); i++)
#define ALL(x) begin(x),end(x)
#define PB push_back
using namespace std;
typedef int64_t LL;
typedef vector<int> VI;
typedef pair<int,int> PII;
 
LL n, D, x;
vector<pair<LL, LL>> A;
queue<pair<LL, LL>> q;
 
int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cin >> n >> D >> x;
    A.resize(n);
    REP(i, n) {
        cin >> A[i].first >> A[i].second;
    }
    sort(A.begin(), A.end());
    LL ans = 0, cnt=0;
    for(auto a:A) {
        LL i=a.first, j=a.second;
        while(!q.empty() && q.front().first<i-2*D) {
            cnt-=q.front().second; q.pop();
        }
        j -= cnt*x;
        if(j<=0) continue;
        LL k = (j+x-1)/x;
        ans += k;
        cnt += k;
        q.push({i, k});
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 4992
#include<iostream>
#include<vector>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
using namespace std;

int main(){
	int n;
	cin>>n;
	vector<int>a(n,0);
	int tmp;
	rep(i,n-1){
		cin>>tmp;
		a[tmp-1]+=1;
	}
	rep(i,n)cout<<a[i]<<endl;

	return 0;
}

Measured memory_bytes: 4008
/*
          ,     \    /      ,
         / \    )\__/(     / \
        /   \  (_\  /_)   /   \
   ____/_____\__\@  @/___/_____\____
  |             |\../|              |
  |              \VV/               |
  |        ------hoi-------         |
  |_________________________________|
   |    /\ /      \\       \ /\    |
   |  /   V        ))       V   \  |
   |/     `       //        '     \|
   `              V                '
*/

#include <bits/stdc++.h>

#define ull unsigned long long
#define ll long long
#define pb push_back
#define f first
#define se second
#define mp make_pair
#define Speedforce boost();

using namespace std;

void boost(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
}

const int N = 1e6;
const int inf = 1e9 + 7;

int n, k, ans = 1e9;
vector <int> g[N];
int cur;

void dfs1(int v, int pr = -1, int len = 0){
    if(len > k / 2){
        cur ++;
    }
    for(int i = 0;i < g[v].size();i ++){
        int to = g[v][i];
        if(to != pr){
            dfs1(to, v, len + 1);
        }
    }
}

void dfs2(int v){
    for(int i = 0;i < g[v].size();i ++){
        cur = 0;
        int to = g[v][i];
        dfs1(v, to);
        dfs1(to, v);
        ans = min(cur, ans);
    }
}

int main() {
    Speedforce
    cin >> n >> k;
    for(int i = 1;i < n;i ++){
        int x, y;
        cin >> x >> y;
        g[x].pb(y);
        g[y].pb(x);
    }
    if(k & 1){
        for(int i = 1;i <= n;i ++){
            dfs2(i);
        }
    }
    else{
        for(int i = 1;i <= n;i ++){
            cur = 0;
            dfs1(i);
            ans = min(ans, cur);
        }
    }
    cout << ans;
}

Measured memory_bytes: 23936
#include <iostream>
#include <algorithm>
#include <queue>
#include <iterator>
#include <set>

using namespace std;

int N;
int A[100001];
int _A[100001];
int B[100000];
int _B[100000];

long long int rsol(int *a, int *b){
    long long int res = 0;
    for (int i = N - 1; i >= 0; --i) {
        int k2 = min(b[i], a[i+1]);
        res += k2;
        int k1 = min(a[i], b[i] - k2);
        res += k1;
        a[i] -= k1;
    }
    return res;
}

long long int lsol(int *a, int *b) {
    long long int res = 0;
    for (int i = 0; i < N; ++i) {
        int k1 = min(b[i], a[i]);
        res += k1;
        int k2 = min(a[i + 1], b[i] - k1);
        res += k2;
        a[i + 1] -= k2;
    }
    return res;
}

int main()
{
    cin >> N;
    for (int i = 0; i < N + 1; ++i) {
        cin >> A[i];
    }
    for (int i = 0; i < N + 1; ++i) {
        _A[i] = A[i];
    }
    for (int i = 0; i < N; ++i) {
        cin >> B[i];
    }
    for (int i = 0; i < N; ++i) {
        _B[i] = B[i];
    }
    cout << max(rsol(A, B), lsol(_A, _B)) << endl;
}

Measured memory_bytes: 1792
#include <cmath>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
int Q, n;
int main() {
	cin >> Q;
	while (Q--) {
		cin >> n;
		vector<int> a(n);
		for (int i = 0; i < n; i++) cin >> a[i];
		int ret = 0;
		for (int i = 0; i < n; i++) {
			vector<vector<int> > dp(n, vector<int>(n + 1));
			for (int j = 2; j <= n; j++) {
				for (int k = 0; k <= n - j; k++) {
					int r = k + j;
					for (int l = k + 1; l < r; l++) {
						dp[k][r] = max(dp[k][r], dp[k][l] + dp[l][r] + abs(a[k] - a[l]));
					}
				}
			}
			ret = max(ret, dp[0][n]);
			vector<int> b(n);
			for (int j = 0; j < n; j++) b[j] = a[(j + 1) % n];
			a = b;
		}
		cout << ret << endl;
	}
	return 0;
}

Measured memory_bytes: 3076
#include <iostream>
#include <fstream>
#include <vector>

#define FOR(i, n) for (int i = 0; i < n; i++)

using namespace std;

vector<bool> if_has;
vector<vector<int> > neigh;

void DFS(int a, int par, int &piece_count, int &max_help, int &min_help){
    piece_count = 0;
    if (if_has[a])
        piece_count++;
    max_help = 0;
    min_help = 0;
    int cur_max_help = 0, cur_min_help = 0;
//    vector<int> max_helps, min_helps;
    for (int b : neigh[a])
        if (b != par){
            int aaa, bbb, ccc;
            DFS(b, a, aaa, bbb, ccc);
            piece_count += aaa;
            max_help += bbb;
//            min_help += ccc;
            if (bbb > cur_max_help){
                cur_max_help = bbb;
                cur_min_help = ccc;
            }
        }
    if (cur_min_help <= max_help - cur_max_help + 1)
        min_help = max_help % 2;
    else
        min_help = cur_min_help + cur_max_help - max_help;
    max_help += piece_count;
    min_help += piece_count;
//    if (max_help % 2 == 0){
//        if (2 * cur_min_help <= max_help){
//            min_help = 0;
//        }
//        else{
//            min_help = 2 * cur_min_help - max_help;
//        }
//    }
//    else{
//        if (2 * cur_min_help <= max_help + 1){
//            min_help = 1;
//        }
//        else{
//            min_help = 2 * cur_min_help - max_help;
//        }
//    }
}

int main(){
    cin.tie(NULL);
    cout.tie(NULL);
    ios_base::sync_with_stdio(false);
//    ifstream cin("E.in");
    int n;
    cin >> n;
    if_has.resize(n);
    FOR (i, n){
        char a;
        cin >> a;
        if_has[i] = (a == '1');
    }
    neigh.resize(n);
    FOR (i, n - 1){
        int a, b;
        cin >> a >> b;
        a--, b--;
        neigh[a].push_back(b);
        neigh[b].push_back(a);
    }
    const int inf = 1e9;
    int ans = inf;
    FOR (i, n){
        int piece_count, max_help, min_help;
        DFS(i, -1, piece_count, max_help, min_help);
        max_help -= piece_count;
        min_help -= piece_count;
        if (min_help == 0)
            ans = min(ans, max_help / 2);
    }
    if (ans == inf)
        cout << -1 << endl;
    else
        cout << ans << endl;
}


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

int N;

int main(){
	cin>>N;int ans=0,res=100000;
	for(int k=1;k<=N/2;k++){
		ans=0;
		int j=N-k;int i=k;
		while(i){
			ans+=i%10;
			i=i/10;
		}
		while(j){
			ans+=j%10;
			j=j/10;
		}
		if(ans<res)res=ans;
	}
	cout<<res<<endl;
	return 0;
}

Measured memory_bytes: 256
// --------------------------------------------
// ****************  gzhffIThh  ***************
// --------------------------------------------
#pragma GCC optimize(2)
#pragma GCC optimize(3)

using namespace std;

#include<bits/stdc++.h>

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

Measured memory_bytes: 3688