akhauriyash/Code-Regression huggingface dataset:
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
//#include<cctype>
#include<climits>
#include<iostream>
#include<string>
#include<vector>
#include<map>
//#include<list>
#include<queue>
#include<deque>
#include<algorithm>
//#include<numeric>
#include<utility>
//#include<memory>
#include<functional>
#include<cassert>
#include<set>
#include<stack>
#include<random>

const int dx[] = {1, 0, -1, 0};
const int dy[] = {0, -1, 0, 1};
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int, int> pii;

int N, M;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    while (cin >> N >> M) {
        if (N==0 && M==0) break;
        vector<int> W(N), i2g(N);
        vector<vector<int> > g2i(N);
        // init
        for (int i = 0; i < N; i++) {
            i2g[i] = i;
            g2i[i].push_back(i);
        }
        while (M--) {
            char c;
            cin >> c;
            if (c == '!') {
                int a, b, w;
                cin >> a >> b >> w;
                a--; b--;
                if (i2g[a] == i2g[b]) {
                    assert(W[b]-W[a] == w);
                } else {
                    // merge
                    if (g2i[i2g[a]].size() < g2i[i2g[b]].size()) {
                        swap(a, b);
                        w = -w;
                    }
                    int ga = i2g[a], gb = i2g[b];
                    int diff = (W[a]+w) - W[b];
                    for (int el : g2i[gb]) {
                        i2g[el] = ga; 
                        W[el] += diff;
                    }
                    g2i[ga].insert(g2i[ga].end(), g2i[gb].begin(), g2i[gb].end());
                    g2i[gb].clear();
                }
            } else {
                int a, b;
                cin >> a >> b;
                a--; b--;
                if (i2g[a] != i2g[b]) {
                    cout << "UNKNOWN" << endl;
                } else {
                    cout << W[b]-W[a] << endl;
                }
            }
        }
    }
    return 0;
}

Measured memory_bytes: 9948
#include <stdio.h>
struct dice{
    int val[6];
    void in(){
        for(int i=0;i<6;i++)scanf("%d",&val[i]);
        return ;
    }
    void spin(){
        int temp=val[1];
        val[1]=val[2];
        val[2]=val[4];
        val[4]=val[3];
        val[3]=temp;
        return ;
    }
    void change(){
        int temp=val[0];
        val[0]=val[1];
        val[1]=val[5];
        val[5]=val[4];
        val[4]=temp;
        return ;
    }
    bool operator ==(const dice &a){
        for(int i=0;i<6;i++)if(a.val[i]!=val[i])return false;
        return true;
    }
};
const int N=1e2+10;
int main(){
    int n;
    dice a[N];
    scanf("%d",&n);
    for(int i=0;i<n;i++){
        a[i].in();
        for(int j=0;j<i;j++){
            for(int k=0;k<4;k++){
                a[i].spin();
                for(int r=0;r<4;r++){
                    for(int l=0;l<4;l++){
                        if(a[i]==a[j]){
                            printf("No\n");
                            return 0;
                        }
                        a[i].spin();
                    }
                    a[i].change();
                }
            }
        }
    }
    printf("Yes\n");
}



Measured memory_bytes: 2700
#include <iostream>
#include <stdio.h>
using namespace std;

int main(){
  double r;
  cin >> r;
  double s, v, pi;
  pi = 3.14159265358979;
  
  s = r*r*pi;
  v = 2*r*pi;

  printf("%f %f\n", s, v);
}

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

int main() {
	int n,k;
	cin>>n>>k;
	int ans =0;
	while(n--){
		int temp;
		cin>>temp;
		if(temp>=k) ans++;
	}
	cout<<ans<<endl;
	
	return 0;
}

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

using namespace std;
int n, k;
int r, s, p;

int get(char m, int st){
    if(m == 'r') {
        if(st == 2) return p;
    } else if( m == 's'){
        if(st == 0) return r;
    } else if(st == 1) return s;
    return 0;
}

int score(string str){
    int len = str.size();
    vector<vector<int>> dp (len + 1, vector<int>(3, 0));
    for(int i = 1; i <= len; i ++)
    {
        dp[i][0] = max(dp[i-1][1], dp[i-1][2]) + get(str[i-1], 0);
        dp[i][1] = max(dp[i-1][0], dp[i-1][2]) + get(str[i-1], 1);
        dp[i][2] = max(dp[i-1][0], dp[i-1][1]) + get(str[i-1], 2);
    }
    return max(max(dp[len][0], dp[len][1]), dp[len][2]);
}

int main(){
    cin >> n >> k;
    cin >> r >> s >> p;
    string t;
    cin >> t;
    int res = 0;
    vector<string> temp (k, "");
    for(int i = 0; i < n; i ++){
        temp[i%k] += t[i];
    }
    for(int i = 0; i < k; i ++){
        res += score(temp[i]);
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 6016
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <queue>
#include <stack>
#include <cmath>
#include <iomanip>
#define ll long long
#define rep(i,n) for(ll i=0;i<(n);i++)
#define repp(i,n) for(int i=1;i<=n;i++)
using namespace std;
ll n,k;
vector<ll> a(200005);
ll f[200005];

bool can(ll c){
    priority_queue<ll> pq;
    ll kk = k;
    rep(i,n) pq.push(c/f[i]);
    rep(i,n){
        ll t = pq.top();
        if(a[i]>t) kk -= a[i]-t;
        pq.pop();
        if(kk<0) return false;
    }
    return true;
}

int main(){
    cin >> n >> k;
    rep(i,n) cin >> a[i];
    rep(i,n) cin >> f[i];
    if(n==1){
        ll ans = (a[0]-k)*f[0];
        if(ans<0) ans = 0;
        cout << ans << endl;
        return 0;
    }
    sort(a.begin(),a.end(),greater<int>());
    ll lb = -1;
    ll ub = 1001001001001;
    while(ub-lb>1){
        ll mid = (lb+ub)/2;
        if(can(mid)){
            ub = mid;
        }else lb = mid;
    }
    if(ub<0) ub = 0;
    cout << ub << endl;
}


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


using namespace std;

#define REP(i, n) for(ll i = 0;i < n;i++)
#define REPR(i, n) for(ll i = n;i >= 0;i--)
#define FOR(i, m, n) for(ll i = m;i < n;i++)
#define FORR(i, m, n) for(ll i = m;i >= n;i--)
#define REPO(i, n) for(ll i = 1;i <= n;i++)
#define ll long long
#define INF (ll)1 << 60
#define MINF (-1 * INF)
#define ALL(n) n.begin(),n.end()
#define MOD (ll)1000000007
#define P pair<ll, ll>


ll ans, n, s[110000];

int main() {
	cin >> n;
	REP(i, n - 1)cin >> s[i];
	ans += s[0];
	REP(i, n - 2) {
		ans += min(s[i], s[i + 1]);
	}
	ans += s[n - 2];
	cout << ans << endl;
}
	


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

typedef long long ll;
#define all(x) (x).begin(),(x).end()
const int mod=1000000007,MAX=100005;
const ll INF=1LL<<60;

int main(){
    
    int N;cin>>N;
    vector<ll> A(N),B(N),sa(N);
    ll sumA=0,sumB=0;
    for(int i=0;i<N;i++){
        cin>>A[i];
        sumA+=A[i];
    }
    for(int i=0;i<N;i++){
        cin>>B[i];
        sumB+=B[i];
    }
    for(int i=0;i<N;i++){
        sa[i]=A[i]-B[i];
        if(sa[i]<0) sa[i]=INF;
    }
    
    sort(all(sa));
    
    if(sumA<sumB) cout<<-1<<endl;
    else{
        ll can=sumA-sumB;
        int ans=0;
        for(int i=0;i<N;i++){
            if(can>=sa[i]){
                ans++;
                can-=sa[i];
            }else break;
        }
        cout<<N-ans<<endl;
    }
}


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

#define loop(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) for (int i = 0; i < n; ++i)
#define dump(a) cerr << #a << " = " << (a) << "(L:" << __LINE__ << ")" << endl

template <typename T>
struct BIT {
    int N;
    vector<T> bit;
    BIT(int N) : N(N), bit(N + 1) {}
    void add(int a, T v) {
        for (int x = a; x <= N; x += x & -x) {
            bit[x] += v;
        }
    }
    T sum(T a) {
        int ret = 0;
        for (int x = a; 0 < x; x -= x & -x) {
            ret += bit[x];
        }
        return ret;
    }
};

void solve(long long N, long long Q, std::vector<long long> c,
           std::vector<long long> l, std::vector<long long> r) {
    vector<pair<pair<int, bool>, int> > pairs;
    map<long long, int> tmp;
    rep(i, N) {
        if (tmp.find(c[i]) != tmp.end())
            pairs.emplace_back(make_pair(tmp[c[i]], true), i);
        tmp[c[i]] = i;
    }
    rep(i, Q) { pairs.emplace_back(make_pair(--l[i], false), --r[i]); }

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

    BIT<int> bit(N);
    map<pair<long long, long long>, int> ans_map;
    for (int i = pairs.size() - 1; 0 <= i; i--) {
        auto range = make_pair(pairs[i].first.first, pairs[i].second);
        bool q = !pairs[i].first.second;

        if (q)
            ans_map[range] = bit.sum(range.second);
        else
            bit.add(range.second, 1);
    }

    rep(i, Q) {
        cout << r[i] - l[i] + 1 - ans_map[make_pair(l[i], r[i])] << endl;
    }
}

int main() {
    long long N;
    scanf("%lld", &N);
    long long Q;
    scanf("%lld", &Q);
    std::vector<long long> c(N);
    for (int i = 0; i < N; i++) {
        scanf("%lld", &c[i]);
    }
    std::vector<long long> l(Q);
    std::vector<long long> r(Q);
    for (int i = 0; i < Q; i++) {
        scanf("%lld", &l[i]);
        scanf("%lld", &r[i]);
    }
    solve(N, Q, std::move(c), std::move(l), std::move(r));
    return 0;
}


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

int main()
{
    int A[4];
    string S;
    cin >> S;
    A[0] = S[0] - '0', A[1] = S[1] - '0', A[2] = S[2] - '0', A[3] = S[3] - '0';
    int now = A[0];
    string tmp;
    for (int bit = 0; bit < (1 << 3); bit++)
    {
        now = A[0];
        tmp = S[0];
        for (int i = 0; i < 3; i++)
        {
            if (bit & (1 << i))
            {
                tmp += "+";
                now += A[i + 1];
            }
            else
            {
                tmp += "-";

                now -= A[i + 1];
            }
            tmp += A[i + 1] + '0';
        }
        if (now == 7)
        {
            cout << tmp << "=7" << endl;
            return 0;
        }
    }
    return 0;
}

Measured memory_bytes: 256
def main():
    n, x = map(int, input().split())
    aa = list(map(int, input().split()))
    res = 0
    for i in range(1, n):
        sub = aa[i - 1] + aa[i] - x
        if sub > 0:
            aa[i] -= sub
            if aa[i] < 0:
                aa[i - 1] += aa[i]
                aa[i] = 0
            res += sub
    print(res)


if __name__ == '__main__':
    main()


Measured memory_bytes: 14540
#include<cstdio>
typedef long long int ll;
int main(){
	ll n,a[100000],b[100000];
	ll total = 0;
	bool flag = true;
	scanf("%lld",&n);
	for(int i=0;i<n;i++){
		scanf("%lld",a+i);
		total += a[i];
	}
	if(total%(n*(n+1)/2)==0) total /= n*(n+1)/2;
	else flag = false;
	for(int i=0;i<n;i++) if(a[(i+1)%n] - a[i] - total > 0) flag = false;
	for(int i=0;i<n;i++) if((a[(i+1)%n] - a[i] - total)%n!=0) flag = false;
	if(flag) printf("YES\n");
	else printf("NO\n");
}


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

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

  int t_point = 0;
  int h_point = 0;
  for (int i = 0; i < n; i++) {
    string t_string, h_string;
    cin >> t_string >> h_string;

    if (t_string > h_string) {
      t_point += 3;
    } else if (t_string < h_string) {
      h_point += 3;
    } else {
      t_point += 1;
      h_point += 1;
    }
  }

  cout << t_point << " " << h_point << endl;
  return 0;
}



Measured memory_bytes: 3156
def resolve():
    n = int(input())
    h = list(map(int, input().split()))
    c = 0
    ans = 0
    for i in range(n - 1):
        if h[i + 1] <= h[i]:
            c += 1
            if c > ans:
                ans = c
        else:
            c = 0
    print(ans)


if __name__ == "__main__":
    resolve()


Measured memory_bytes: 14252
#include <iostream>
#include <vector>
#include <cstdlib>  
#include <algorithm>
#include <string>
using namespace std;
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;
}
const long long INF = 1LL<<60;
int n;
long long w, weight[110], value[110]; // 品物の個数は 100 個なので少し余裕持たせてサイズ 110 に

// DPテーブル
long long dp[110][100100] ;

int main() {
   cin >>n>>w;
   for(int i = 0;i<n;i++) cin >> weight[i]>>value[i];
   for(int i = 0;i<110;i++)for(int j = 0;j<100100;j++) dp[i][j] = INF;
   dp[0][0] = 0;
   for(int i = 0;i<n;i++){
     for(int s = 0;s<100100;s++){
       if(s-value[i] >= 0) chmin(dp[i+1][s],dp[i][s-value[i]]+weight[i]);
         chmin(dp[i+1][s], dp[i][s]);
     }
   }
   long long ko;
   for(int i = 0;i<100100;i++){
       if(dp[n][i] <= w) ko = i;
       
   }
   cout<<ko;
 
    return 0;
}

Measured memory_bytes: 86272
#include<stdio.h>

int main(void){
    int i,n,m;
    scanf("%d",&n);
    scanf("%d",&m);
    int a[m];
    for(i=0;i<m;i++){
        scanf("%d",&a[i]);
    }

    for(i=0;i<m;i++){
        n-=a[i];
    }

    if(n<0) printf("%d\n",-1);
    else    printf("%d\n",n);
    
    return 0;
}

Measured memory_bytes: 1752
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <memory>
#include <algorithm>
#include <cmath>
#include <vector>
#include <stack>
#include <queue>
#include <ctime>
#include <algorithm>
#define time_seed srand((unsigned)time(NULL))
#define mset(x,y) (memset(x,y,sizeof(x)))
#define inf 0x3fffffff
#define pf printf
#define pf1(x) printf("%d\n",x)
#define pf2(x,y) printf("%d %d\n",x,y)
#define pf3(x,y,z) printf("%d %d %d\n",x,y,z)
#define sc scanf
#define sc1(x) scanf("%d",&x)
#define sc2(x,y) scanf("%d%d",&x,&y)
#define sc3(x,y,z) scanf("%d%d%d",&x,&y,&z)
#define for0(n) for(int i=0 ; i<n ;++i)
#define for1(n) for(int i=1 ; i<=n ;++i)
#define _for0(n) for(int i=n ; i>=0 ;--i)
#define _for1(n) for(int i=n ; i>0 ;--i)
#define ls (id<<1)
#define rs ((id<<1)|1)
#define pi 3.1415926535898
typedef long long ll;
using namespace std;
const int Max=32;
int n, m;
double a[Max], b[Max], c[Max], ans, dis[Max][Max];
bool flag[Max];

void dfs(int p, int k, double sum) 
{
    if (p == n) 
{
        if (k == m)
            ans = max(ans, sum);
        return;
    }
    if (k + n - p > m)
        dfs(p + 1, k, sum);
    if (k == m)
        return;
    for (int j = 0; j < p; ++j)
        if (flag[j])
            sum += dis[j][p];
    flag[p] = true;
    dfs(p + 1, k + 1, sum);
    flag[p] = false;
}

int main()
 {
    while (scanf("%d%d", &n, &m) != EOF)
	{
		for (int i = 0; i < n; ++i) 
		{
        scanf("%lf%lf%lf", &a[i], &b[i], &c[i]);
        for (int j = 0; j < i; ++j) 
		{
            dis[i][j] = dis[j][i] = (a[i] - a[j]) * (a[i] - a[j]) + (b[i] - b[j]) * (b[i] - b[j]) + (c[i] - c[j]) * (c[i] - c[j]);
        }
    }
    ans = 0.0;
    memset(flag, 0, sizeof(flag));
    dfs(0, 0, 0);
    printf("%.5lf\n", ans);
	}
    return 0;
}

Measured memory_bytes: 892
#include<iostream>
using namespace std;
int main(){
  int W,H,x,y,r;
  cin >> W >> H >> x >> y >> r ;
  if(0<=x-r && r+x<=W && 0<=y-r && y+r<=H){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }




}



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

//Common
using namespace std;using f64 = double;using i64=long long;using u64=unsigned long long;
template<typename T> using Arr=vector<T>;template<typename T> using Func=function<T>;template<typename T> using Str=basic_string<T>;
#define hfor(v, s, e) for(int v=(s);(s)<=v&&v<(e);++v)//half-opened range
#define hfori(v, s, e) for(int v=(e)-1;(s)<=v&&v<(e);--v)//inversion
#define hforo(v, s, e) int v=(s);for(;(s)<=v&&v<(e);++v)//out declaration
#define hforoi(v, s, e) int v=(e)-1; for(;(s)<=v&&v<(e);--v)
#define cfor(v, s, e) hfor(v,(s),(e)+1)//closed range
#define cfori(v, s, e) hfori(v,(s),(e)+1)
#define cforo(v, s, e) hforo(v,(s),(e)+1)
#define cforoi(v, s, e) hforoi(v,(s),(e)+1)
#define rep(v,x) hfor(v,0,(x))
#define repi(v,x) hfori(v,0,(x))
#define repo(v,x) hforo(v,0,(x))
#define all(x) (x).begin(),(x).end()
#define pushb push_back
#define pushf push_front
#define popb pop_back
#define popf pop_front
#define empl emplace
#define emplb emplace_back
#define emplf emplace_front
#define fi first
#define se second
#define cxp constexpr
#define PQ std::priority_queue

//Math
template<typename T> cxp T inf() { return numeric_limits<T>::max() / 2; }
template<typename T> inline T sq(T x){return x*x;}
cxp int lgc(int x){return 64-__builtin_clzll(x-1);}
cxp int lgf(int x){return 63-__builtin_clzll(x);}
int rd(int lb, int ub){static mt19937 rng(time(0)^i64(new int)); return uniform_int_distribution<int>(lb, ub-1)(rng);}
int rd(int ub=inf<int>()){return rd(0,ub);}
const f64 pi=acosl(-1), eps=1e-10;

//IO
template<typename T>ostream& operator<<(ostream& s, const Arr<T>& a) {for(auto i:a) cout<<i<<' '; return s;}
int getint(){int x;cin>>x;return x;}
char getchr(){char x;cin>>x;return x;}
#ifndef DEBUG
	//#pragma GCC optimize ("Ofast") //somtimes it become more slower
	auto __PRE_RUN__=(ios::sync_with_stdio(0), cin.tie(0), cout.tie(0),(cout<<fixed<<setprecision(11)), 0);
#endif

//Misc
int sz(const auto& x){return x.size();}
auto split(auto s, auto p){
	Arr<decltype(s)> ret;
	auto it1=s.begin();
	for(auto it2=it1; (it2 = find(it1,s.end(),p)) != s.end(); it1=it2+1)
		ret.pushb({it1, it2});
	ret.pushb({it1,s.end()});
	return ret;
}
template<typename T> T rev(const T& a){return {a.rbegin(),a.rend()};}
Arr<int> range(int n){ Arr<int> ret(n); rep(i,n)ret[i]=i; return ret; }
struct defer{ defer(auto f):f(f){} ~defer(){f();} function<void()> f; };
#define defer(x) auto _##__COUNTER__ = defer([&](){x;});
#define lam(expr, ...) [&](__VA_ARGS__){return expr;}
#define reduce accumulate

#define endl '\n'//not interactive?
#define int i64//MLE?
using pint = pair<int,int>;
using tint = tuple<int,int,int>;

signed main(){
	string s; cin>>s;
	cout<<s.substr(0,3)<<endl;
	return 0;
}



Measured memory_bytes: 3652
import sys
sys.setrecursionlimit(10 ** 6)
# input = sys.stdin.readline    ####
int1 = lambda x: int(x) - 1
def II(): return int(input())

def MI(): return map(int, input().split())
def MI1(): return map(int1, input().split())

def LI(): return list(map(int, input().split()))
def LI1(): return list(map(int1, input().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]

INF = float('inf')
#from fractions import gcd
from math import gcd

def solve():
    k = II() + 1
    ans = 0
    for a in range(1, k):
        for b in range(1, k):
            g = gcd(a, b)
            for c in range(1, k):
                ans += gcd(g, c)
    print(ans)


if __name__ == '__main__':
    solve()


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

int main(){

    double n, m, d;
    cin >> n >> m >> d;
    cout << fixed << setprecision(15);
    if(d) cout << 2*(n-d)*(m-1)/n/n << '\n';
    else cout << (m-1)/n << '\n';

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define REP(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) REP((i),0,(n))
#define RREP(i,a,b) for(int i=(int)(a);i>=(int)(b);i--)
#define rrep(i,n) RREP(i,n,0)
#define each(it,X) for(__typeof((X).begin())  it=(X).begin();it!=(X).end();it++)
#define all(v) ((v).begin(),(v).end())
#define fi first
#define se second
#define pb push_back
typedef pair<int,int>pr;
typedef vector<int>vi;
typedef vector<vi>vvi;
typedef set<int>si;
const int INF=1000000000000000ll;
const int mod=1000000007ll;

int n,a[100],b[100];
int dp[100][100];
signed main(){
    cin.tie(0);ios_base::sync_with_stdio(0);

    cin>>n;rep(i,n)cin>>a[i]>>b[i];
    fill_n(*dp,10000,INF);
    rep(i,n)dp[i][i]=0;

    REP(i,1,n){
        for(int j=0;j+i<n;j++){
            ///[j,j+i]
            int mi=INF;
            for(int k=j;k<j+i;k++){
                int cost=dp[j][k]+dp[k+1][i+j];
                cost+=a[j]*b[k]*a[k+1]*b[i+j];
                mi=min(mi,cost);
            }
            dp[j][j+i]=mi;
        }
    }
    cout<<dp[0][n-1]<<endl;
    return 0;
}

Measured memory_bytes: 1268
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;} return 0;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;} return 0;}
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(vec) vec.begin(),vec.end()
typedef long long ll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
const ll mod=1e9+7;
const int inf=1<<30;

int main(){
  ll h,w; cin >> h >> w;
  if(h%3==0||w%3==0){
    cout << 0 << endl;
    return 0;
  }
  ll a=h*2/3;
  ll b=w/2;
  ll ans=inf;
  for(int i=a;i<=a+1;i++){
    ll s1=i*b;
    ll s2=i*(w-b);
    ll s3=(h-i)*w;
    chmin(ans,max(s1,max(s2,s3))-min(s1,min(s2,s3)));
  }
  ll s1=h*(w/3);
  ll s2=h*((w-w/3)/2);
  ll s3=h*w-s1-s2;
  chmin(ans,max(s1,max(s2,s3))-min(s1,min(s2,s3)));
  //cout << ans << endl;
  swap(h,w);
  a=h*2/3;
  b=w/2;
  for(int i=a;i<=a+1;i++){
    ll s1=i*b;
    ll s2=i*(w-b);
    ll s3=(h-i)*w;
    chmin(ans,max(s1,max(s2,s3))-min(s1,min(s2,s3)));
  }
  s1=h*(w/3);
  s2=h*((w-w/3)/2);
  s3=h*w-s1-s2;
  chmin(ans,max(s1,max(s2,s3))-min(s1,min(s2,s3)));
  cout << ans << endl;
  
}

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

int main() {
    string s;
    ll k,ans=0,tmp=0;
    cin>>s>>k;
    ll n = s.size();
    ll a=1;
    for(int i=0; i<n; i++) {
        if(s[i]==s[i+1]) a++;
        else {
          	if(a == 1) a--;
            ans += a/2;
          	tmp++;
          	a=1;
        }
    }
  	if(tmp == 1) cout<<n * k / 2<<endl;
    else if(s.front() == s.back()) {
      	ll fr = 0, ba = 0;
        for(int i=0; i<n; i++) {
            fr++;
            if(s[i] != s[i+1]) break;
        }
        for(int i=n-1; i>=0; i--) {
            ba++;
            if(s[i] != s[i-1]) break;
        }
        cout<<ans * k - (k-1) * ((fr/2) + (ba/2) - (fr+ba)/2)<<"\n";
    }
  	else cout<<ans * k<<endl;
}

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

#define _CRT_SECURE_NO_WARNINGS
#define TLong long long
#define TBMod 1000000007

int main(int argc, char const *argv[])
{
	TLong n;
	TLong temp;
	scanf("%lld",&n);
	for (TLong i = 1; i * i <= n; ++i)	temp = i * i;
	printf("%lld\n", temp);
	return 0;
}


Measured memory_bytes: 384
#include<stdio.h>

int main(){
    int N, D;
    int X[11][11];
    int i, j, k;
    int ans = 0;
    int tmp, tmp2;

    scanf("%d %d", &N, &D);

    for(i=0; i<N; i++){
        for(j=0; j<D; j++){
            scanf("%d", &X[i][j]);
        }
    }

    for(i=0; i<N; i++){
        for(j=i+1; j<N; j++){
            tmp = 0;
            for(k=0; k<D; k++){
                tmp += (X[i][k]-X[j][k])*(X[i][k]-X[j][k]);
            }
            //printf("%d\n", tmp);
            for(k=1; k<10000; k++){
                tmp2 = tmp/k;
                //printf("%d ", tmp2);
                if(tmp2==k && tmp%k==0){
                    ans++;
                    break;
                }
                if(tmp2<k){
                    break;
                }       
            }
            //printf("\n");
        }
        //printf("%d\n", tmp);
    }
    printf("%d",ans);

    return 0;
}

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

int main(){
    string T;
    cin >> T;
    ll count=0;
  
  
    for(ll i=0;i<(int)T.size();i++){
       if(T.at(i)=='?'){
         T.at(i)='D';
       }
    }
  
  for(ll i=0;i<(int)T.size();i++){
    cout << T.at(i);
  }
        
    

}

Measured memory_bytes: 3724
#include<stdio.h>
int main()
{
	int x=0,n,s,i;
	scanf("%d",&n);
	while(n--)
	{
		scanf("%d",&s);
		printf("Case %d:\n",++x);
		for(i=0;i<10;++i)
			printf("%d\n",(s= (s*s)/100%10000));
	}
	return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <tuple>
#include <algorithm>
#include <map>
using namespace std;
#define REP(n) for(int i=0;i<n;i++)

int flowers[101] = { 0 };

int type_cnt[100001] = { 0 };
int main() {
	long long N,K;
	cin >> N >> K;
	vector<int> h(N);
	map<int,int> h_cnt;
	long long ans = 0;
	REP(N) {
		cin >> h[i];
		h_cnt[h[i]] += 1;
	}
	sort(h.begin(), h.end());

	int diff = 0x7f000000;
	for(int i=0;i<N;) {
		diff = min(diff,abs(h[i] - h[i+K-1]));
		i += h_cnt[h[i]];
		if (i + K - 1 >= N) {
			break;
		}
	}

	cout << diff << endl;
	return 0;
}

Measured memory_bytes: 5376
#include <bits/stdc++.h>
#define rep(i, n) for (lli i = 0; i < (n); i++)
#define rrep(i, n) for (lli i = (n)-1; i >= 0; i--)
using namespace std;
using lli = long long int;
template <class T>
class bit2d
{
public:
    vector<vector<T>> dat;
    int h, w;

    bit2d(int h, int w) : h(h), w(w)
    {
        vector<T> tmp(w, 0);
        dat.assign(h, tmp);
    }
    bit2d(int h, int w, T ini) : h(h), w(w)
    {
        // vector<T> tmp(w, ini);
        // dat.assign(tmp, h);
    }
    // [(r,c)]閉区間
    T sum(int r, int c)
    {
        T ret = 0;
        for (int i = r; i >= 0; i = (i & (i + 1)) - 1)
            for (int j = c; j >= 0; j = (j & (j + 1)) - 1)
                ret += dat[i][j];
        return ret;
    }
    T sum(int r1, int c1, int r2, int c2)
    {
        return sum(r2, c2) - sum(r1 - 1, c2) - sum(r2, c1 - 1) + sum(r1 - 1, c1 - 1);
    }
    T get(int r, int c)
    {
        return sum(r, c, r, c);
    }


    // add x to i
    void add(int r, int c, T x)
    {
        for (int i = r; i < h; i |= i + 1)
            for (int j = c; j < w; j |= j + 1)
                dat[i][j] += x;
    }
};
int main()
{
    int n, k;
    cin >> n >> k;
    int a, b;
    char c;
    int k2 = k * 2;
    bit2d<int> biw(k2 + 3, k2 + 3), bib(k2 + 3, k2 + 3);
    int cntw = 0, cntb = 0;
    rep(i, n)
    {
        cin >> a >> b >> c;
        a %= k2;
        b %= k2;
        if (c == 'W') {
            biw.add(a, b, 1);
            cntw++;
        } else {
            bib.add(a, b, 1);
            cntb++;
        }
    }
    int ans = 0;
    for (int i = 0; i < k; i++)
        for (int j = 0; j < k; j++) {
            //cout << i << " " << j << endl;
            //cout << i << " " << j << " " << bib.sum(0, 0, i, j) << endl;
            //lli sumb = bib.sum(0, 0, i, j) + bib.sum(i + 1, j + 1, i + k, j + k) + bib.sum(0, j + k + 1, i, k2) + bib.sum(i + k + 1, j + k + 1, k2, k2) + bib.sum(i + k + 1, 0, k2, j);
            int sumb = cntb - (bib.sum(i + 1, 0, i + k, j) + bib.sum(0, j + 1, i, j + k) + bib.sum(i + 1, j + k + 1, i + k, k2) + bib.sum(i + k + 1, j + 1, k2, j + k));


            int sumw = biw.sum(i + 1, 0, i + k, j) + biw.sum(0, j + 1, i, j + k) + biw.sum(i + 1, j + k + 1, i + k, k2) + biw.sum(i + k + 1, j + 1, k2, j + k);

            ans = max(sumb + sumw, max(cntb + cntw - sumb - sumw, ans));
            //cout << sumb << " " << sumw << endl;
        }
    cout << ans << endl;
}


Measured memory_bytes: 31744
s = input()[::-1]
word = ["dream", "dreamer", "erase", "eraser"]
dream = "dream"[::-1]
dreamer = "dreamer"[::-1]
erase = "erase"[::-1]
eraser = "eraser"[::-1]
while True:
    if s[:5] == dream or s[:5] == erase:
        s = s[5:]
        continue
    elif s[:6] == eraser:
        s = s[6:]
        continue
    elif s[:7] == dreamer:
        s = s[7:]
        continue
    break
if len(s) == 0:
    print("YES")
else:
    print("NO")

Measured memory_bytes: 134296
#!/usr/bin/env python3
import sys


def solve(n: int, p: "List[int]"):
    result = 0
    for i in range(len(p) - 2):
        if p[i] < p[i + 1] and p[i + 1] < p[i + 2]:
            result += 1
        elif p[i] > p[i + 1] and p[i + 1] > p[i + 2]:
            result += 1
    print(result)
    return


# Generated by 1.1.5 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    n = int(next(tokens))  # type: int
    p = [int(next(tokens)) for _ in range(n)]  # type: "List[int]"
    solve(n, p)

if __name__ == '__main__':
    main()


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

int main(){
  int a,b;
  cin >> a >> b;
  int i=0;
  bool flag = true;
  if(b == 1){
    cout << "0" << endl;
    return 0;
  }
  while(flag == true){
    i += 1;
    if((a-1)*i+1 >= b){
      cout << i << endl;
      return 0;
    }
  }
}

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

int main(){
	std::ios_base::sync_with_stdio(0);
	cin.tie(NULL); int o;

	string s; cin >> s;
	int m = s.length(); int p = 0, k = 0;;
	int l=s.find("A");
	for (int i = l; i <m; i++){
		if (s[i] == 'Z') {
			p = i;
		}
	}
	cout << (p - l)+1 << endl;
	return 0;
}




Measured memory_bytes: 3796
#include "bits/stdc++.h"
#include<unordered_map>
#pragma warning(disable:4996)
using namespace std;

const int My_Inf=2147483647;
const long long int My_LInf=9223372036854775807;


int main() {
	while (1) {
		int N; cin >> N;
		if (!N)break;
		int ans = 0;
		bool lu = false;
		bool ru = false;
		bool down = true;
		for (int i = 0; i < N; ++i) {
			string st; cin >> st;
			if (st == "lu") {
				lu = true;
				if (down&&lu&&ru) {
					ans++;
					down = !down;
				}
			}
			else if (st == "ru") {
				ru = true;
				if (down&&lu&&ru) {
					ans++;
					down = !down;
				}
			}
			else if (st == "ld") {
				lu = false;
				if (!down&&!lu&&!ru) {
					ans++;
					down = !down;
				}
			}
			else {
				ru = false;
				if (!down&&!lu&&!ru) {
					ans++;
					down = !down;
				}
			}
		}
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 2992
//
// Created by wulang on 10/1/16.
//

#include <iostream>
#include <algorithm>
#include <list>
using namespace std;

void solve();
int main(int argc, char *argv[]) {
    if (argc == 2) {
        freopen(argv[1], "r", stdin);
    } else if (argc == 3) {
        freopen(argv[1], "r", stdin);
        freopen(argv[2], "w", stdout);
    }
    solve();
    return 0;
}

const int N=200000+10;
int n, a[N], pre[N], nxt[N];
void solve(){
    while(cin>>n){
        for(int i=1;i<=n;i++) cin>>a[i];
        a[0]=a[n+1]=0;
        for(int i=1;i<=n;i++) {
            int k=i-1;
            while(a[k]>a[i]) k=pre[k];
            pre[i]=k;
        }

        for(int i=n;i>=1;i--) {
            int k=i+1;
            while(a[k]>a[i]) k=nxt[k];
            nxt[i]=k;
        }

        long long ans=0;
        for(int i=1;i<=n;i++) ans+= (long long)(i-pre[i])*(nxt[i]-i)*a[i];
        cout<<ans<<endl;
    }

}




Measured memory_bytes: 2688
//{
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double lf;
typedef pair<ll,ll> ii;
#define REP(i,n) for(ll i=0;i<n;i++)
#define REP1(i,n) for(ll i=1;i<=n;i++)
#define FILL(i,n) memset(i,n,sizeof i)
#define X first
#define Y second
#define SZ(_a) (int)_a.size()
#define ALL(_a) _a.begin(),_a.end()
#define pb push_back
#ifdef brian
#define debug(...) do{\
    fprintf(stderr,"%s - %d (%s) = ",__PRETTY_FUNCTION__,__LINE__,#__VA_ARGS__);\
    _do(__VA_ARGS__);\
}while(0)
template<typename T>void _do(T &&_x){cerr<<_x<<endl;}
template<typename T,typename ...S> void _do(T &&_x,S &&..._t){cerr<<_x<<" ,";_do(_t...);}
template<typename _a,typename _b> ostream& operator << (ostream &_s,const pair<_a,_b> &_p){return _s<<"("<<_p.X<<","<<_p.Y<<")";}
template<typename It> ostream& _OUTC(ostream &_s,It _ita,It _itb)
{
    _s<<"{";
    for(It _it=_ita;_it!=_itb;_it++)
    {
        _s<<(_it==_ita?"":",")<<*_it;
    }
    _s<<"}";
    return _s;
}
template<typename _a> ostream &operator << (ostream &_s,vector<_a> &_c){return _OUTC(_s,ALL(_c));}
template<typename _a> ostream &operator << (ostream &_s,set<_a> &_c){return _OUTC(_s,ALL(_c));}
template<typename _a,typename _b> ostream &operator << (ostream &_s,map<_a,_b> &_c){return _OUTC(_s,ALL(_c));}
template<typename _t> void pary(_t _a,_t _b){_OUTC(cerr,_a,_b);cerr<<endl;}
#define IOS()
#else
#define debug(...)
#define pary(...)
#define endl '\n'
#define IOS() ios_base::sync_with_stdio(0);cin.tie(0);
#endif // brian
//}


const ll MAXn=1e5+5,MAXlg=__lg(MAXn)+2;
const ll MOD=1000000007;
const ll INF=ll(1e15);

int main()
{
    IOS();
    ll n;
    cin>>n;
    if(n==1)
    {
      cout<<"Hello World"<<endl;
    }
    else{
      ll a,b;
      cin>>a>>b;
      cout<<a+b<<endl;
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1e9;
int main() {
  int a, b;
  cin >> a >> b;
  printf((a * b) % 2 == 0 ? "No" : "Yes");
  cout << endl;
}

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

using namespace std;

typedef long long int li;
typedef long double ld;
typedef vector<li> vi;
typedef pair<li,li> pi;
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define B begin()
#define E end()
#define f(i,l,r) for(li i=l;i<=r;++i)
#define fr(i,l,r) for(li i=l;i>=r;--i)
#define u_map unordered_map
#define endl "\n"
#define debug(x) cout<<#x<<" = "<<x<<endl;

li fastpow(li base,li exp,li M) 
{
    li res=1;
    while(exp>0) {
        if(exp&1)
            res=(res*base)%M;

        base=(base*base)%M;
        exp>>=1;
    }
    return res;
}

void solve()
{
    string s,t;

    cin>>s>>t;

    li n=s.length();

    li cnt=0;

    f(i,0,n-1)
    {
    	if(s[i]!=t[i])
    		cnt++;
    }

    cout<<cnt;
}

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

    li t=1;

    // cin>>t;

    while(t--)
    {
        solve();
    }

    return 0;
}

Measured memory_bytes: 3764
n, m = [int(i) for i in input().split()]

matrix = []
for ni in range(n):
   matrix.append([int(a) for a in input().split()])
   
vector = []
for mi in range(m):
    vector.append(int(input()))

b = []
for ni in range(n):
    sum = 0
    for mi in range(m):
       sum += matrix[ni][mi] * vector[mi]
    
    print(sum)

Measured memory_bytes: 8016
def div(N):
    ans = []
    for i in range(1, int(N ** 0.5) + 1):
        if N % i == 0:
            ans.append(i)
            if N // i != i:
                ans.append(N // i)
    ans.sort()
    return ans
import fractions

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

g=fractions.gcd(A,B)

if g==1:
    print(1)
    exit()
cnt=0
di=div(g)

for i in di:
    f=True
    for j in range(2,int(i**0.5)+1):
        if i%j==0:
            f=False
            break
    if f:
        cnt+=1
print(cnt)





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

int main() {
	int n;
	cin >> n;
	int a[210];
	for (int i = 0; i < n; i++)cin >> a[i];
	int counter = 0;
	bool flag = false;

	while (true) {
		for (int i = 0; i < n; i++) {
			if (a[i] % 2)flag = true;
			a[i] = a[i] / 2;
		}
		if (flag)break;
		counter++;
	}
	cout << counter << endl;
	cin >> n;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll gcd(ll a,ll b)
{

    if(b==0)
        return a;
    else
        return gcd(b,a%b);
}

ll lcm(ll a,ll b)
{
    return (a/(gcd(a,b)))*b;

}
int main()
{

    //  #ifndef oj
    //freopen("in", "r", stdin);
    //freopen("out.txt","w",stdout);
    //#endif
    // system("cls");
    //getchar();

    ll a,b;
    cin>>a>>b;
    cout<<lcm(a,b)<<endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<memory>
#include<functional>
#include<cstring>
#include <iomanip>

using namespace std;

#ifdef LDEBUG
#define debug(x) cout << #x << ":" << x << endl
#else
#define debug(...)
#endif

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

typedef unsigned long long u64;
typedef long long i64;


i64 m,k;

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

        cin >> m >> k;

        i64 a = (1 << m) -1;

        if (k > a) {
                cout << "-1" << endl;
                return 0;
        }

        if (m == 1) {
                if (k == 0) {
                        cout << "0 0 1 1" << endl;
                } else {
                        cout << "-1" << endl;
                }
                return 0;
        }

        for (i64 i=0; i<=a; i++) {
                if (i == k)
                        continue;
                cout << i << " ";
        }
        cout << k << " ";
        for (i64 i=a; i>=0; i--) {
                if (i == k)
                        continue;
                cout << i << " ";
        }
        cout << k << endl;

        return 0;
}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int INF = 0x3f3f3f3f;
const ll inf = 0x3f3f3f3f3f3f3f3f;
const ll mod = 1e9 + 7;
const int N = 1e6 + 10;
ll fac[N], inv[N];
ll power(ll a, int x) {
	ll ans = 1;
	while (x) {
		if (x & 1) ans = (ans * a) % mod;
		a = (a * a) % mod;
		x >>= 1;
	}
	return ans;
}
void init() {
	fac[0] = 1;
	for (int i = 1; i < N; i++) {
		fac[i] = fac[i - 1] * i %mod;
	}
	inv[N - 1] = power(fac[N - 1], mod - 2);
	for (int i = N - 2; i >= 0; i--) {
		inv[i] = inv[i + 1] * (i + 1) % mod;
	}
}
int n, m;
ll P(int n, int k) {
	return fac[n] * inv[n - k] % mod;
}
ll C(int n, int k) {
	return fac[n] * inv[n - k] % mod*inv[k] % mod;
}
int main() {
	scanf("%d%d", &n, &m);
	init();
	ll ans = P(m, n)*P(m, n) % mod;
	for (int i = 1; i <= n; i++) {
		ll tmp = C(n, i)*P(m, i) % mod*P(m - i, n - i) % mod*P(m - i, n - i) % mod;
		if (i & 1)ans = (ans - tmp + mod) % mod;
		else ans = (ans + tmp) % mod;
	}
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 19420
#include<bits/stdc++.h>
using namespace std;
string s;
int main()
{
    long long num;
    long long sum=0;
    long long n,t,x;
    long long Max;
    long long Maxinf=-(1<<31-1);
    cin>>n>>x;
    cin>>num;
    Max=num;
    for(int i=1;i<n;i++)
    {
        cin>>num;
        Max=min(num,Max);
        if(Maxinf<num-Max)
        {
            sum=1;
            Maxinf=num-Max;
        }
        else if(Maxinf<=num-Max)
        {
            sum++;
            Maxinf=num-Max;
        }
    }
    cout<<sum<<endl;
   // cout<<min(sum,x)<<endl;
    return 0;
}


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

int main() {
  int N,n,a,b,c;
  bool flag=0;
  a=0;
  b=0;
  c=0;
  cin >> N;
  vector<string>s(N);
  vector<int>vec(N);
  vector<int>max(N);
  for(int i=0;i<N;i++){
    cin >> s.at(i);
  }
  n=0;
  for(int i=0;i<N;i++){
    int m;
    for(int j=1;j<s.at(i).size();j++){
      if(s.at(i).at(j)=='B'&&s.at(i).at(j-1)=='A'){
        vec.at(i)++;
      }
    }
    n= n + vec.at(i);
    flag=0;
    if(s.at(i).at(0)=='B'){
      m=s.at(i).size()-1;
      if(s.at(i).at(m)=='A'){
        a++;
      }
    }
    if(s.at(i).at(0)=='B'){
      m=s.at(i).size()-1;
      if(s.at(i).at(m)!='A'){
        b++;
      }
    }
    if(s.at(i).at(0)!='B'){
      m=s.at(i).size()-1;
      if(s.at(i).at(m)=='A'){
        c++;
      }
    }
  }

  if(a==0){
    n=n+min(c,b);
  }else if((c+b)>0){
    n=n+a+min(c,b);
  }else{
    n=n+a-1;
  }
  cout << n << endl;
}




Measured memory_bytes: 896
#include <iostream>
#include <fstream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <cstdlib>
#include <cstdio>
#include <string>
#include <cstring>
#include <cassert>
#include <utility>
#include <iomanip>
#include <chrono>
#include <random>
#include <bitset>

using namespace std;

#define sz(x) (int) x.size()
#define unique(x) x.erase(unique(x.begin(), x.end()), x.end())
#define all(a) a.begin(), a.end()
#define sqr(x) ((x) * (x)) 
#define y1 aksjdaskdjksjfksdjf
#define left kdnvldvoiwejifejg
#define right lkdsjflksdjfdjfk
#define prev asdasfsadjkjsdfjs
#define tm aklsjdasjdasjdkdjjf
#define lcm hddalkwjeidjjhasda
#define random_shuffle asdasdd

const int MAXN = 2 * 105000;

int n;
long long c;
long long h[MAXN];
long long dp[MAXN];

vector <long long> mvals, bvals;
int cur = 0;

// Suppose the last 3 lines added are : (l1, l2, l3)
// Line l2 becomes irrelevant, if l1/l3 x-intersection is to the left of l1/l2 x-intersection
bool bad(long long m1, long long b1, long long m2, long long b2, long long m3, long long b3) {
    // Cast to double to avoid long long overflow
    return 1.0 * (b1 - b3) * (m2 - m1) < 1.0 * (b1 - b2) * (m3 - m1);
}

void add(long long m, long long b) {
    while ( (int) mvals.size() >= 2 && bad(mvals[mvals.size() - 2], bvals[bvals.size() - 2], mvals[mvals.size() - 1], bvals[bvals.size() - 1], m, b)) {
        mvals.pop_back(); bvals.pop_back();
    }
    mvals.push_back(m); bvals.push_back(b);
}

void setCur(long long x) {
    if (cur > (int) mvals.size() - 1)
        cur = (int) mvals.size() - 1;
    // Best-line pointer goes to the right only when queries are non-decreasing (x argument grows)
    while (cur < (int) mvals.size() - 1 && 1.0 * mvals[cur + 1] * x + bvals[cur + 1] <= 1.0 * mvals[cur] * x + bvals[cur])
        cur++;
}

int main() { 

  scanf("%d %lld", &n, &c);
  for (int i = 0; i < n; i++) {
    scanf("%lld", &h[i]);
  }

  for (int i = 0; i < n; i++) {
    if (i > 0) {
      setCur(h[i]);
      dp[i] = mvals[cur] * h[i] + bvals[cur] + c + sqr(h[i]);
    }
    add(-2 * h[i] , sqr(h[i]) + dp[i]);
  }

  cout << dp[n - 1] << endl;

  return 0;
}


Measured memory_bytes: 6756
//g++ -std=c++17 -Wshadow -Wall -fsanitize=address -fsanitize=undefined -D_GLIBCXX_DEBUG -g PROGRAM -o OUTPUT -DLOCAL -lasan -lubsan
#include <bits/stdc++.h>

#define ll long long
#define ull unsigned long long
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define eps 1e-6
#define pi 3.141592653589793
using namespace std;

typedef vector<int> VII;
typedef vector<ll> VLL;
typedef pair<int, int> PII;
typedef vector<pair<int, int>> VPII;
typedef vector<pair<int, PII>> VPPI;
const int MOD = 1e9 + 7;
const int INF = 1e9;


inline ll modulo(ll a, ll m)
{
    return (a % m + m) % m;
}

inline ll modInverse(ll a, ll m)
{
    assert(__gcd(a, m) == 1);
    ll m0 = m;
    ll y = 0, x = 1;

    if (m == 1)
        return 0;

    while (a > 1)
    {
        ll q = a / m;
        ll t = m;

        m = a % m, a = t;
        t = y;

        y = x - q * y;
        x = t;
    }

    if (x < 0)
        x += m0;

    return x;
}

inline ll modPow(ll x, ll y, ll m)
{ //x^y % m
    if (y == 0)
        return 1LL;
    else if (y == 1)
        return x;
    else
    {
        ll ans = modPow(x, y / 2, m) % m;
        if (y & 1)
        {
            return (((ans * ans) % m) * x) % m;
        }
        else
        {
            return (ans * ans) % m;
        }
    }
}

vector<string> split(char d,string s)
{
    stringstream ss(s);
    string t;
    vector<string> words;
    while(getline(ss,t,d))
    {
        words.pb(t);
    }

    return words;
}
vector<ll> dp(2001, -1);
ll solve(int s){
    if(s==0)
        return 1;
    ll ans = 0;
    if(dp[s]!=-1)
        return dp[s];
    for (int i = 3; i <= s;++i){
        ans += solve(s - i)%MOD;
    }

    return dp[s]=ans%MOD;
}
int main(int argc, char *argv[])
{
    
    ios::sync_with_stdio(false);
    cin.tie(NULL);

    int n;
    cin >> n;
    // vector<ll> dp(n + 1, 0);
    // if(n<=2)
    //     cout << 0, exit(0);

    // dp[3] = 1;
    // for (int i = 4; i <= n;++i){
    //     for (int j = 3; j <= i;++j){
    //         dp[i] =((dp[i]%MOD)+(dp[i - j]%MOD))%MOD;
    //         cout << i << ' ' << j << ' ' << dp[i] << endl;
    //     }
    // }
    // cout << dp[n];

    cout << solve(n);
    return 0;
}


Measured memory_bytes: 3676
#include <iostream>
#include <vector>
#include <cstdio>
#include <algorithm>
using namespace std;

int main(){
	vector<int> s;
	for(int j = 0 ; j < 2 ; j++){
		int N;
		cin >> N;
		for(int i = 0 ; i < N ; i++){
			int a,b;
			cin >> a >> b;
			s.push_back(a*60+b);
		}
	}
	sort(s.begin(),s.end());
	s.erase(unique(s.begin(),s.end()),s.end());
	for(int i = 0 ; i < s.size() ; i++){
		if(i) cout << " ";
		printf("%d:%02d",s[i]/60,s[i]%60);
	}
	cout << endl;
}

Measured memory_bytes: 1252
#include<bits/stdc++.h>
#define forn(i,n) for(int i = 0; i < n; i++)
#define forr(i,a,n) for(int i = a; i<= n; i++)
#define __ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define fi first
#define se second
#define pb push_back
#define all(u) u.begin(),u.end()
#define lli long long int
#define ld long double

using namespace std;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef vector<vi> vvi;
const int mxn = 2e5+100;
pair<lli,lli> p[mxn];
lli ans, n, d;
int main(){__
	cin >> n >> d;
	forn(i,n) cin >> p[i].fi >> p[i].se;
	forn(i,n){
		if(p[i].fi*p[i].fi + p[i].se*p[i].se <= d*d) ans++;
	}
	cout << ans << '\n';
	return 0;
}



Measured memory_bytes: 6684
#include <bits/stdc++.h>
using namespace std;
 
#define rep(i, n) for (int i = (int)(0); i < (int)(n); ++i)
#define reps(i, n) for (int i = (int)(1); i <= (int)(n); ++i)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rreps(i, n) for (int i = ((int)(n)); i > 0; i--)
#define irep(i, m, n) for (int i = (int)(m); i < (int)(n); ++i)
#define ireps(i, m, n) for (int i = (int)(m); i <= (int)(n); ++i)
#define FOR(e, c) for (auto &e : c)
#define SORT(v, n) sort(v, v + n);
#define vsort(v) sort(v.begin(), v.end());
#define rvisort(v) sort(v.begin(), v.end(), greater<int>());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
 
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using vpii = vector<pii>;
using vs = vector<string>;
using vd = vector<double>;
using ul = unsigned long;
 
template<class T, class C> void chmax(T& a, C b){ a>b?:a=b; }
template<class T, class C> void chmin(T& a, C b){ a<b?:a=b; }
 
const int mod=1e9+7;
 
struct mint {
  ll x;
  mint(ll x=0):x(x%mod){}
  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 {
    mint res(*this);
    return res+=a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res-=a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res*=a;
  }
};
 
mint c[4005][4005];
void init() {
  c[0][0] = 1;
  for (int i = 0; i <= 4000; i++) {
    for (int j = 0; j <= i; j++) {
      c[i+1][j] += c[i][j];
      c[i+1][j+1] += c[i][j];
    }
  }
}
mint comb(int n, int k) {
  return c[n][k];
}
 
bool IsPrime(int num)
{
    if (num < 2) return false;
    else if (num == 2) return true;
    else if (num % 2 == 0) return false;
 
    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            return false;
        }
    }
 
    return true;
}
 
map<ll, ll> primeFact(ll n) {
  map<ll, ll> res;
  for (ll i = 2; i * i <= n; i++) {
    while (n % i == 0) {
      res[i]++;
      n /= i;
    }
  }
  if (n != 1) res[n]++;
  return res;
}
 
void printv(vi& v){
  rep(i,v.size()) cout << v[i] << " ";
  cout << endl;
}
void printv(vll& v){
  rep(i,v.size()) cout << v[i] << " ";
  cout << endl;
}
int vtotal(vi& v){
  int total=0;
  rep(i,v.size()) total+=v[i];
  return total;
}
 
int main()
{
  //init(); // mint初期化
  cin.tie( 0 );
  ios::sync_with_stdio( false );
  
  int x,t;cin>>x>>t;
  int ans=x-t;
  if(ans<0)ans=0;
  cout(ans);
  
  return 0;
}

Measured memory_bytes: 125568
import math

def main():
    n = int(input())
    order_list = list(map(int, input().split(" ")))
    count = 0
    for i in range(n-2):
        dif1 = order_list[i+1]-order_list[i]
        dif2 = order_list[i+2]-order_list[i+1]
        if dif1*dif2 > 0:
            count = count + 1
        else:
            pass

    print(count)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3060