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

int main(){
	long long int n;
	cin>>n;
	
	for(long long int i=1;i<3501;i++){
		for(long long int j=1;j<3501;j++){
			long long int p=n*i*j;
			long long int q=4*i*j-n*i-n*j;
			if(q>0&&p%q==0){
				cout<<i<<" "<<j<<" "<<p/q<<endl;
				return 0;
			}
		}
	}
	
	return 0;
}

Measured memory_bytes: 256
c=[0,2,5,5,4,5,6,3,7,6];N,M=gets.split.map &:to_i;A=gets.split.map &:to_i;d=[0]+Array.new(N);0.upto(N){|i|q=A.map{|x|c[x]<=i&&d[t=i-c[x]]?d[t]*10+x:p}.compact;q.any?&&d[i]=q.max};p d[N]

Measured memory_bytes: 36220
#include<iostream>
using namespace std;
int main()
{
    string s;
    cin>>s;
    int j,l;
    l = s.length();
    bool i = false;
    if( s[2]==s[3] )
        if( s[4]==s[5] ){
            cout<<"Yes"<<endl;
            i = true;
            }


    if(i==false)
        cout<<"No"<<endl;


}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace mondai0045
{
	class Program
	{
		static void Main(string[] args)
		{
			int	cnt	= 0;
			int	sum	= 0;
			int	num	= 0;

			while( true ) {
				var	line	= Console.ReadLine();
				if( line == null ) {
					break;
				}
				var	str	= line.Split( ',' );
				var	t	= int.Parse( str[ 0 ] );
				var	s	= int.Parse( str[ 1 ] );
				sum	+= t * s;
				num	+= s;
				cnt++;
			}

			Console.WriteLine( sum );
			Console.WriteLine( (int)((float)num / (float)cnt + 0.5f) );
		}
	}
}

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

//Math/ModInt
template<long long mod = 1000000007>
struct modint{
	long long a;

	constexpr modint() : a(0){}
	constexpr modint(long long t){
		a = t % mod;
		if(a < 0) a += mod;
	}

	constexpr operator long long() const{ return a; }

	constexpr bool operator==(const modint &x) const{ return a == x.a; }
	constexpr bool operator!=(const modint &x) const{ return a != x.a; }

	constexpr modint operator-() const{ return modint(a ? (mod - a) : 0); }
	constexpr modint operator~() const{ return pow(mod - 2); }

	constexpr modint operator+(const modint &x) const{ return modint(*this) += x; }
	constexpr modint operator-(const modint &x) const{ return modint(*this) -= x; }
	constexpr modint operator*(const modint &x) const{ return modint(*this) *= x; }
	constexpr modint operator/(const modint &x) const{ return modint(*this) /= x; }

	constexpr modint &operator+=(const modint &x){
		a += x.a;
		if(a >= mod) a -= mod;
		return *this;
	}
	constexpr modint &operator-=(const modint &x){
		a -= x.a;
		if(a < 0) a += mod;
		return *this;
	}
	constexpr modint &operator*=(const modint &x){
		a = a * x.a % mod;
		return *this;
	}
	constexpr modint &operator/=(const modint &x){
		a = a * (~x).a % mod; 
		return *this;
	}

	constexpr modint &operator++(){ return (*this) += 1; }
	constexpr modint &operator--(){ return (*this) -= 1; }
	constexpr modint &operator++(int){
		modint tmp = *this;
		(*this) += 1;
		return tmp;
	}
	constexpr modint &operator--(int){
		modint tmp = *this;
		(*this) -= 1;
		return tmp;
	}

	friend ostream &operator<<(ostream &os,const modint &x){
		return os << x.a;
	}
	friend istream &operator>>(istream &is,modint &x){
		long long t;
		is >> t;
		x = modint(t);
		return is;
	}

	constexpr modint pow(long long x) const{
		modint ret = 1,tmp = a;
		for(;x;tmp *= tmp,x >>= 1){
			if(x & 1) ret *= tmp;
		}
		return ret;
	}
};

//Math/Combination
template<class T>
struct Combination{
	vector<T> fact,factinv;
	Combination(int n) : fact(n + 1),factinv(n + 1){
		fact[0] = 1;
		for(int i = 1;i <= n;i++) fact[i] = fact[i - 1] * T(i);
		factinv[n] = ~fact[n];
		for(int i = n;i >= 1;i--) factinv[i - 1] = factinv[i] * T(i);
	}
	T nCr(int n,int r){
		if(r < 0 || n < r) return 0;
		return fact[n] * factinv[r] * factinv[n - r];
	}
};

const int MOD = 1000003;

signed main(){
	int q;
	scanf("%d",&q);
	Combination<modint<MOD>> comb(MOD - 1);
	for(int i = 0;i < q;i++){
		int x,d,n;
		scanf("%d %d %d",&x,&d,&n);
		modint<MOD> mx = x,md = d;
		if(!d) cout << mx.pow(n) << endl;
		else if(n >= MOD) cout << 0 << endl;
		else cout << comb.fact[n] * comb.nCr(-mx / md,n) * (-md).pow(n) << endl;
	}
}


Measured memory_bytes: 16512
#include <bits/stdc++.h>
 
using namespace std;
int N, M;
int A[10010];
 
int main()
{
	cin>>N>>M;
    int total = 0;
    for(int i = 0; i < M; ++i)
    {
    	cin>>A[i];
        total += A[i];
    }
    cout<<((total > N) ? -1 : (N - total))<<endl;
    return 0;
 
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using Graph = vector<vector<pii>>;
const int INF = 1e9 + 1;
const ll LLINF = 1e18;
const int MOD = 1e9 + 7;

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

    int N;
    cin >> N;
    vector<pii> range(N);
    for (int i = 0; i < N; ++i) {
        int X, L;
        cin >> X >> L;
        range[i].first = X - L;
        range[i].second = X + L;
    }
    sort(range.begin(), range.end());

    int ans = 1;
    int r = range[0].second;
    for (int i = 1; i < N; ++i) {
        if (range[i].first < r && range[i].second >= r)
            continue;
        if (range[i].second < r) {
            r = range[i].second;
            continue;
        }
        ans++;
        r = range[i].second;
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0;i<n;i++)
#define rep2(i,a,n) for(int i=a;i<n;i++)
#define been(ix) (ix).begin(),(ix).end()
using namespace std;
typedef long long ll; 
typedef vector<int> vi;
typedef vector<long long> vl;
const ll INFL = 1e18;
const int INF = 1001001001; 
typedef pair<int,int> P;
#define foreach(ix,i) for(auto& (ix) : (i))
typedef long double ld;
const int mod =1000000007;
const double PI = acos(-1);
int main(){
    int n;cin>>n;
    vector<ll>a(n,0);
    ll ans =0;
    rep(i,n){
        ll b;cin>>a[i];
        //ans+=b/2;
        //if(b%2)a[i]=true;
    }
    rep(i,n){
        ans+=a[i]/2;
        if(a[i]%2&&i!=n-1&&a[i+1]!=0){
            a[i+1]--;
            ans++;
        }
    }
    cout<<ans<<endl;
}

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

int main(){
  int n, i, count4=0, count2=0, a;
  cin >> n;
  for (i=0; i<n; ++i) {
    cin >> a;
    if (a%4 == 0) count4 += 1;
    else if (a%2 == 0) count2 += 1;
  }
  n = n - (count2 / 2) * 2;
  if ( n > count4 * 2 + 1) cout << "No" << endl;
  else cout << "Yes" << endl;
  return 0;
}


Measured memory_bytes: 384
import java.util.Scanner;

public class Main {
	static Scanner s = new Scanner(System.in);

	public static void main(String[] args) {
		int a=s.nextInt(),b=s.nextInt();
		if(a<=0&&0<=b)
			System.out.println("Zero");
		else
			System.out.println((Math.min(0,b)-Math.min(-1,a))%2==1?"Positive":"Negative");
	}
}


Measured memory_bytes: 24020
#define _USE_MATH_DEFINES
#include "bits/stdc++.h"
#define rep(i,a,b) for (int i = (a); i < (b); i++)
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> P;
typedef complex<double> com;
const int mod = 1e9 + 7;
const int MOD = 998244353;
const int inf = 2e9;



int main(){
	int n; cin >> n;
	rep(i, 0, n) {
		int p; cin >> p;
		if (p % 2) {
			printf("first");
			return 0;
		}
	}
	printf("second");
	return 0;
}


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


int main() {
  int n; cin>>n;
  vector<int> v(n);
  rep(i,n){
    cin>>v[i];
  }
  sort(v.begin(),v.end());
  int count=0;
  for(int i=n-1; i>=2; i--){
    for(int j=i-1; j>=1; j--){
      for(int k=j-1; k>=0; k--){
        if(v[i]>=v[j]+v[k]){break;}
        else{count++;}
      }
    }
  }
  cout<<count;
}

Measured memory_bytes: 3620
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <cfloat>
#include <ctime>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <numeric>

using namespace std;

#ifdef _MSC_VER
#define __typeof__ decltype

template <class T>
int __builtin_popcount(T n) { return n ? 1 + __builtin_popcount(n & (n - 1)) : 0; }
#endif

#define foreach(it, c) for (__typeof__((c).begin()) it=(c).begin(); it != (c).end(); ++it)
#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
#define popcount __builtin_popcount

const double EPS = 1e-8;
typedef long long ll;
typedef pair<int, int> pint;


int main()
{
	int n;
	while (scanf("%d", &n), n)
	{
		int ap, ad = -1;
		while (n--)
		{
			int p, d1, d2;
			scanf("%d%d%d", &p, &d1, &d2);
			int d = d1 + d2;
			if (d > ad)
			{
				ad = d;
				ap = p;
			}
		}
		printf("%d %d\n", ap, ad);
	}

	return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
double esp=1e-8;
//#pragma comment(linker, "/STACK:1024000000,1024000000")
#define fi first
#define se second
#define all(a) (a).begin(),(a).end()
#define cle(a) while(!a.empty())a.pop()
#define mem(p,c) memset(p,c,sizeof(p))
#define mp(A, B) make_pair(A, B)
#define pb push_back
typedef long long int LL;
const long double PI = acos((long double)-1);
const int INF=0x3f3f3f3fll;
const int MOD =1e9+7ll;
const int maxn=201000;
pair<int,int> tr[2][maxn];
int num[2][maxn],N;
void update(int pos,int val)
{
    int t=pos&1;
    num[t][pos]=val;
    for (int x=pos; x&&x<=N; x+=x&-x)
        tr[t][x]=min(tr[t][x],mp(val,pos));
}
pair<int,int> query(int pos)
{
    int t=pos&1;
    pair<int,int> sum=mp(INF,INF);
    for (int x=pos; x; x^=x&-x)
        sum=min(sum,tr[t][x]);
    return sum;
}
pair<int,int> query(int t,int l,int r)   //询问[l,r]区间最大值  logn
{
    pair<int,int> ans = mp(num[t][r],r);
    while(1)
    {
        ans = min(ans , mp(num[t][r],r));
        if(l == r) break;
        for(r--;r-l >=(r&-r);r ^= r&-r)
            ans = min(ans , tr[t][r]);
    }
    //printf("qq %d %d %d %d %d\n",t,l,r,ans.fi,ans.se);
    return ans;
}
vector<int>ans;
int A[maxn];
priority_queue<pair<pair<int,int>,pair<int,int> >, vector<pair<pair<int,int>,pair<int,int> > >, greater<pair<pair<int,int>,pair<int,int> > > > q;
pair<int,int> qu(int l,int r)
{
    pair<int,int> mi=query(l&1,l,r);            //printf("mi %d %d %d %d\n",l,r,mi.fi,mi.se);
//    if(mi.se==r)
//    {
//        mi=min(query(0,l,r-1),query(1,l,r-1));
//        return mp(mi.se,query(mi.se&1,mi.se+1,r).se);
//    }
//    else
        return mp(mi.se,query(mi.se&1^1,mi.se+1,r).se);
}
pair<int,int> f(pair<int,int> a)
{
    return mp(A[a.fi],A[a.se]);
}
int main()
{
    //freopen("in.txt", "r", stdin);
    //freopen("pentagon.in", "r", stdin);
    //freopen("out.txt", "w", stdout);
    for(int x=0;x<maxn;x++)tr[0][x]=tr[1][x]=mp(INF,INF);
    mem(num,0x3f);
    ans.clear();
    int n;
    scanf("%d",&n);
    N=n;
    for(int x=1;x<=n;x++)
    {
        scanf("%d",&A[x]);
        update(x,A[x]);
    }
    cle(q);
    q.push(mp(f(qu(1,n)),mp(1,n)));
    ans.clear();
    for(int x=1;x<=n/2;x++)
    if(!q.empty())
    {
        auto t=q.top();
        int L=t.se.fi,R=t.se.se;
        q.pop();
        ans.pb(t.fi.fi);
        ans.pb(t.fi.se);
        auto tt=qu(L,R);
        int l=tt.fi,r=tt.se;                //printf("%d %d %d %d\n",l,r,L,R);
        if(l-L>0)
            q.push(mp(f(qu(L,l-1)),mp(L,l-1)));//printf("**%d %d %d %d\n",qu(L,l-1).fi,qu(L,l-1).se,L,l-1);
        if(r-l-1>0)
            q.push(mp(f(qu(l+1,r-1)),mp(l+1,r-1)));//printf("**%d %d %d %d\n",qu(l+1,r-1).fi,qu(l+1,r-1).se,l+1,r-1);
        if(R-r>0)
            q.push(mp(f(qu(r+1,R)),mp(r+1,R)));//printf("**%d %d %d %d\n",qu(r+1,R).fi,qu(r+1,R).se,r+1,R);
    }
    for(int x=0;x<n;x++)
        printf("%d%c",ans[x]," \n"[x==n-1]);
    return 0;
}


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

int main()
{
    // 入力
    int N;
    cin >> N;

    vector<int> v(N);
    rep (i, N) {
        cin >> v[i];
    }
    sort(v.begin(), v.end());

    double sum = v[0];
    for (int i = 1; i < N; i++) {
        sum += v[i];
        sum = sum / 2;
    }

    // 出力
    cout << sum << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repa(i, a, n) for (int i = (int)(a); i < (int)(n); i++)
#define ALL(a) (a).begin(), (a).end()
#define COUT(x) cout << (x) << endl;
#define _GLIBCXX_DEBUG

int main(){
  
  char a, b;
  cin >> a >> b;

  if((a == 'H' && b == 'H') || (a == 'D' && b == 'D')){
    COUT('H');
  }
  else COUT('D');

}


Measured memory_bytes: 256
#include<algorithm>
#include<iostream>
#include<vector>
#include<cstring>
#include<queue>
using namespace std;
typedef long long lint;
typedef vector<int>vi;
typedef pair<int,int>pii;
#define rep(i,n)for(int i=0;i<(int)(n);++i)

using namespace std;

#define all(a) (a).begin(), (a).end()


// http://algoogle.hadrori.jp/algorithm/aho-corasick.html
struct PMA {
    PMA* next[256];
    vector<int> matched;
    PMA() { memset(next, 0, sizeof(next)); }
    ~PMA() { for(int i = 0; i < 256; i++) if(next[i]) delete next[i]; }
};

vector<int> set_union(const vector<int> &a,const vector<int> &b) {
    vector<int> res;
    set_union(all(a), all(b), back_inserter(res));
    return res;
}

PMA *buildPMA(vector<string> pattern) {
    PMA *root = new PMA, *now;
    root->next[0] = root;
    for(int i = 0; i < pattern.size(); i++) {
        now = root;
        for(int j = 0; j < pattern[i].size(); j++) {
            if(now->next[(int)pattern[i][j]] == 0)
                now->next[(int)pattern[i][j]] = new PMA;
            now = now->next[(int)pattern[i][j]];
        }
        now->matched.push_back(i);
    }

    queue<PMA*> que;
    for(int i = 1; i < 256; i++) {
        if(!root->next[i]) root->next[i] = root;
        else {
            root->next[i]->next[0] = root;
            que.push(root->next[i]);
        }
    }
    while(!que.empty()) {
        now = que.front(); que.pop();
        for(int i = 1; i < 256; i++) {
            if(now->next[i]){
                PMA *nxt = now->next[0];
                while(!nxt->next[i]) nxt = nxt->next[0];
                now->next[i]->next[0] = nxt->next[i];
                now->next[i]->matched = set_union(now->next[i]->matched, nxt->next[i]->matched);
                que.push(now->next[i]);
            }
        }
    }
    return root;
}

int match(PMA* &pma, const string &s) {
  PMA*root=pma;
  int cnt=0;
    for(int i = 0; i < s.size(); i++){
        int c = s[i];
        while(!pma->next[c])
            pma = pma->next[0];
        pma = pma->next[c];
	if(pma->matched.size()>0){
	  cnt++;
	  pma=root;
	}
    }
    return cnt;
}

int main(){
  string s;
  int n;
  cin>>s>>n;
  vector<string>p(n);
  rep(i,n)cin>>p[i];
  PMA*pma=buildPMA(p);
  cout<<match(pma,s)<<endl;
}



Measured memory_bytes: 174008
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define reps(i,s,n) for(int i=(s); i<(n); i++)
#define all(v) v.begin(),v.end()
#define outve(v) for(auto i : v) cout << i << " ";cout << endl
#define outmat(v) for(auto i : v){for(auto j : i) cout << j << " ";cout << endl;}
#define in(n,v) for(int i=0; i<(n); i++){cin >> v[i];}
#define out(n) cout << (n) << endl
#define fi first
#define se second
#define pb push_back
#define mod 1000000007
#define infi 1900000000
#define infl 1100000000000000000
#define cyes cout << "Yes" << endl
#define cno cout << "No" << endl
#define csp << " " <<
#define outset(n) cout << fixed << setprecision(n);
using namespace std;
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
template<typename T> using ve = vector<T>;
template<typename T> using pq2 = priority_queue<T>;
template<typename T> using pq1 = priority_queue<T,vector<T>,greater<T>>;




int main()
{
    int N,K;
    cin >> N >> K;
    vl p(N);
    in(N,p);
    
    ll num = 1;
    ll bb = 1;
    ll nn = 0;
    int s = 0,t = K-1;
    rep(i,K){
        //num *= p[i];
        //bb *= p[i];
        nn += (p[i]+1);
    }
    ld ans = 0;
    
    for (int t = K-1; t < N; t++) {
        //ll an = 0;
        //ld a = (ld)num/2/(ld)bb;
        ld a = (ld)nn/2;
        //an = num*nn/2;
        //ld a = (ld)an / (ld)bb;
        
        //bb/=p[s];
        //num/=p[s];
        nn -= (p[s]+1);
        if(t+1 <= N-1){
            //num *= p[t+1];
            //bb *= p[t+1];
            nn += p[t+1]+1;
        }
        
        s++;
        ans = max(ans,a);
        
    }
    cout << fixed << setprecision(16);
    cout << ans << endl;
    
    
    
    

    return 0;
}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
int a,b,c,d;
int main(){
	cin>>a>>b>>c>>d;
	if((abs(a-b)<=d&&abs(c-b)<=d)||abs(a-c)<=d) {
		cout<<"Yes";
	}
	else{
		cout<<"No";
	} 
}

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

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

  int ans = 0;

  for(int c = 1; c < N; c++){
    int N_C = N - c;  
    int sqrt_NC = sqrt(N_C);
    for(int i = 1; i <= sqrt_NC; i++){
      if(N_C % i == 0){
        if(N_C == i * i){
          ans += 1;
        }else{
          ans += 2;
        }
      }
    }    
  }

  cout << ans << endl;
}



Measured memory_bytes: 3676
import java.util.*;

public class Main{
	public static void main(String[] args){
		Scanner sc=new Scanner(System.in);
		int a=sc.nextInt();
		int b=sc.nextInt();
		if (a<=b){
			System.out.println(a);
		}else{
			System.out.println(a-1);
		}
	}
}

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

int main(){
	int n,m;
	cin>>n>>m;
	n++;
	m++;

	int x[n];
	cin>>x[0];
	int y[m];
	cin>>y[0];
	
	for(int i=1; i<n; i++) cin>>x[i];
	for(int i=1; i<m; i++) cin>>y[i];
	sort(x,x+n);
	sort(y,y+m);


	if(x[n-1]>=y[0]) cout << "War" << endl;
	else cout << "No War" << endl;

}

Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <set>
#include <bitset>
#include <map>
#include <stack>
#include <algorithm>
#include <math.h>
#include <queue>
#include <vector>
#include <string.h>
#define mem(x,b) memset(x,b,sizeof(x))
#define mp(a,b) make_pair(a,b)
#define debug(a) cout<<a<<endl
#define maxn 200005
using namespace std;
typedef long long ll;
typedef double db;
const int mod=1e9+7;
int a[15][15];
int k[15];
int c[15];
int n,m,x,ans=2000000000;
int isrt(){
	for(int i=0;i<m;i++){
		if(k[i]<x){
			return 0;
		}
	}
	return 1;
}
int main()
{
    scanf("%d%d%d",&n,&m,&x);
    for(int i=0;i<n;i++){
    	scanf("%d",&c[i]);
    	for(int j=0;j<m;j++){
    		scanf("%d",&a[i][j]);
    	}
    }
    for(int i=0;i<=(1<<n)-1;i++){
    	mem(k,0);
    	int cost=0;
    	int t=i;
    	for(int j=0;j<n;j++){
    		if(t&1){
    			for(int l=0;l<m;l++){
    				k[l]+=a[j][l];
    			}
    			cost+=c[j];
    		}
    		t/=2;
    	}
    	if(isrt()){
    		ans=min(cost,ans);
    	}
    }
    if(ans==2000000000){
    	puts("-1");
    }else{
    	printf("%d\n",ans);
    }
    return 0;
}


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

#define int long long
using ll = long long;
using ull = unsigned long long;
#define repi(n) for (long long i = 0; i < (n); ++i)
#define repj(n) for (long long j = 0; j < (n); ++j)
#define repk(n) for (long long k = 0; k < (n); ++k)
#define rep(i, a, b) for (auto i = (a); i < (b); ++i)
#define itr(itr) for (auto&& v : (itr))
#define updatemax(t, v) ((t) = std::max((t), (v)))
#define updatemin(t, v) ((t) = std::min((t), (v)))

ll value[3000][3000];
ll dp[3001][3001][4];
signed main() {
  int r, c, _k;
  cin >> r >> c >> _k;
  repi(_k) {
    int r, c;
    ll v;
    cin >> r >> c >> v;
    --r;
    --c;
    value[r][c] = v;
  }
  repi(r) repj(c) repk(4) {
    updatemax(dp[i + 1][j][0], dp[i][j][k]);
    updatemax(dp[i][j + 1][k], dp[i][j][k]);
    if (value[i][j] > 0 && k < 3) {
      updatemax(dp[i + 1][j][0], dp[i][j][k] + value[i][j]);
      updatemax(dp[i][j + 1][k + 1], dp[i][j][k] + value[i][j]);
    }
  }
  cout << dp[r][c - 1][0] << endl;
}


Measured memory_bytes: 355296
#include <iostream> // cout, endl, cin
#include <cmath> //sqrt pow
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // dequef
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower

#define rep(i,n) for(int i = 0; i < n; i++)
#define vi vector<int>
#define vvi vector<vi>
#define pii pair<int, int>
#define all(a) (a).begin(), (a).end()
#define mod 1000000007
using ll = long long;
using namespace std;
int main(){
  int n;
  cin >> n;
  map<string, ll> cnt;
  rep(i, n){
    string s;
    cin >> s;
    sort(all(s));
    cnt[s]++;
  }
  ll ans = 0;
  for(auto a : cnt){
    ans += a.second * (a.second - 1) / 2;
  }
  cout << ans << endl;
}

Measured memory_bytes: 11296
#include <iostream>
#include <sstream>
#include <fstream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <utility>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstdio>
#include <numeric>
#include <string.h>
#define rep(i, x) for (int i = 0; i < (int)(x); i++)
#define repn(i, x) for (int i = 1; i <= (int)(x); i++)
#define repr(i, x) for (int i = ((int)(x) - 1); i >= 0; i--)
#define reprn(i, x) for (int i = ((int)(x)); i > 0; i--)
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long int64;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const int INF = 1<<29;
const long long  INFL = 1e18;
const int MOD = 1000000007;
void solve() {
	int N, K; cin >> N >> K;
	vector<int> cnt(N);
	for (int i = 0; i < K; ++i) {
		int d; cin >> d;
		for (int j = 0; j < d; ++j) {
			int a; cin >> a;
			--a;
			cnt[a]++;
		}
	}
	int ans = 0;
	for (int i = 0; i < cnt.size(); ++i) {
		if (cnt[i] == 0) {
			ans++;
		}
	}
	cout << ans << endl;
	return;
}

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

Measured memory_bytes: 3628
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <stdio.h>
#include <queue>
#include <deque>
#include <cstdio>
using namespace std;
int main() {
	int n, k;
	double p;
	double r[200000] = { 0 };
	double max = 0;
	r[0] = 0;
	cin >> n >> k;
	for (int i = 0; i < n; i++) {
		cin >> p;
		r[i+1] = p+r[i];
	}
	for (int j = k; j <= n; j++) {
		if (max < r[j] - r[j - k]) {
			max = r[j] - r[j - k];
		}
	}
  	max=(max+k)/2;
	cout << fixed << setprecision(7) << (double)max << endl;
	return 0;
}


Measured memory_bytes: 1792
import scala.io.StdIn

object Main extends App {

  var head = 0
  var tail = 0
  
  val Array(n, q) = StdIn.readLine().trim.split(' ').map(_.toInt)
  val max  = n + 1 
  val myqueue: Array[(String, Int)] = new Array[(String, Int)](max)

  //case class ProceesInfo(name: String, time: Int) 
  
  def isEmpty() = head == tail
  
  def isFull() = head == ((tail + 1) % max)
  
  def enqueue(p: (String, Int)) = {
    if(isFull()) throw new RuntimeException
    else {
      myqueue(tail) = p
      if(tail + 1 == max){
        tail = 0
      } else {
        tail += 1
      }
    }
  }
  
  def dequeue(): (String, Int) = {
    if(head == tail) throw new RuntimeException
    else {
      val ret = myqueue(head)
      if(head + 1 == max){
        head = 0
      } else {
        head += 1
      }
      ret
    }
  }
  
  (0 until n).foreach{ _ =>
    val Array(ename, etime) = StdIn.readLine().trim.split(' ')
    enqueue((ename, etime.toInt))
  }
  var executeTime: Int = 0
  while(head != tail){
    val (cname, ctime) = dequeue()
    val remaintime = if((ctime - q) < 0) 0 else ctime - q
    
    executeTime  += (if((ctime - q) < 0) ctime else q)
    
    if(remaintime == 0){
      println(cname + " " + executeTime)
    } else {
      enqueue((cname, remaintime))
    }
  }
  
}



Measured memory_bytes: 123012
/*
If you want to aim high, aim high
Don't let that studying and grades consume you
Just live life young
******************************
What do you think? What do you think?
1st on Billboard, what do you think of it
Next is a Grammy, what do you think of it
However you think, I’m sorry, but shit, I have no fcking interest
*******************************
I'm standing on top of my Monopoly board
That means I'm on top of my game and it don't stop
til my hip don't hop anymore
https://www.a2oj.com/Ladder16.html
*******************************
300iq as writer = Sad!
*/
import java.util.*;
import java.io.*;
import java.math.*;

   public class Main
   {
      public static void main(String hi[]) throws Exception
      {
         BufferedReader infile = new BufferedReader(new InputStreamReader(System.in));
         StringTokenizer st = new StringTokenizer(infile.readLine());
         int N = Integer.parseInt(st.nextToken());
         int K = Integer.parseInt(st.nextToken());
         StringBuilder sb = new StringBuilder();
         int[] arr = new int[N];
         st = new StringTokenizer(infile.readLine());
         for(int i=0; i < N; i++)
            arr[i] = Integer.parseInt(st.nextToken());
         Arrays.sort(arr);
         long sum = 0L;
         for(int i=0; i < K; i++)
            sum += arr[i];
         System.out.println(sum);
      }
   }

Measured memory_bytes: 32692
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int sum = 0;
		int[] a = new int[N];
		int c = sc.nextInt();
		for(int i = 0;i<N;i++) {
			a[i]=sc.nextInt();
		}
		int count = 0;
		for(int b : a) {
			if(b>=c) {
				count++;
			}
		}
		System.out.println(count);
	}
}


Measured memory_bytes: 48744
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		int a = Integer.parseInt(sc.next());
		int b = Integer.parseInt(sc.next());
		int c = Integer.parseInt(sc.next());

		if (a < c && c < b || b < c && c < a){
			System.out.println("Yes");
		}else {
			System.out.println("No");
		}
	}
}

Measured memory_bytes: 22868
#include <bits/stdc++.h>
using namespace std;
int main () {
    string div[4] = {"dream","dreamer","erase","eraser"};
    string s;
    cin >> s;

    reverse(s.begin(), s.end());
    for(int i = 0; i < 4; i++) reverse(div[i].begin(), div[i].end());
    string res = "YES";

    for(int i = 0; i < s.size();) {
        bool check = false;
        for(int j = 0; j<4; j++) {
            string tmp = div[j];
            if(s.substr(i, tmp.size()) == tmp) {
                check = true;
                i += tmp.size();
            }
        }
        if(!check) {
            res = "NO";
            break;
        }
    }
    cout << res << endl;

    return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#define ll long long
#define ALL(x) x.begin(),x.end()
#define MOD (1000000000+7)
using namespace std;
#define PI 3.14159265359
#define tMOD 998244353
#define mkpr(x,y) make_pair(x,y)

int main(){
string s;
string t;
ll A;ll B;
string U;
cin>>s>>t>>A>>B>>U;

if(U==s){
  A--;
}
else{
  B--;
}
cout<<A<<" "<<B<<endl;

}

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

#define MOD 1000000007
#define rep(i, n) for(ll i=0; i < (n); i++)
#define rrep(i, n) for(ll i=(n)-1; i >=0; i--)
#define ALL(v) v.begin(),v.end()
#define rALL(v) v.rbegin(),v.rend()
#define FOR(i, j, k) for(ll i=j;i<k;i++)
#define debug_print(var) cerr << #var << "=" << var <<endl;
#define DUMP(i, v)for(ll i=0;i<v.size();i++)cerr<<v[i]<<" "

using namespace std;
typedef long long int ll;
typedef vector<ll> llvec;
typedef vector<double> dvec;
typedef pair<ll, ll> P;
typedef long double ld;
struct edge{ll x, c;};

ll mod(ll a, ll mod){
  ll res = a%mod;
  if(res<0)res=res + mod;
  return res;
}

ll modpow(ll a, ll n, ll mod){
  ll res=1;
  while(n>0){
    if(n&1) res=res*a%mod;
    a=a*a%mod;
    n>>=1;
  }
  return res;
}

ll modinv(ll a, ll mod){
  return modpow(a, mod-2, mod);
}

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

bool is_prime(ll n){
  ll i = 2;
  if(n==1)return false;
  if(n==2)return true;
  bool res = true;
  while(i*i <n){
    if(n%i==0){
      res = false;
    }
    i = i+1;
  }

  //if(i==1)res = false;
  if(n%i==0)res=false;
  return res;
}

struct UnionFind{
  ll N;
  llvec p;
  llvec cnt;
  UnionFind(ll n){
    N = n;
    p=llvec(N);
    cnt=llvec(N, 0);
    rep(i, N){
      p[i] = i;
      cnt[i] = 1;
    }
  }

  void con(ll a, ll b){
    P at = root(a);
    P bt = root(b);
    if(at.second!=bt.second){
      if(at.first>bt.first){
        swap(at, bt);
        swap(a, b);
      }
      p[at.second] = bt.second;
      cnt[bt.second]+=cnt[at.second];
      p[a]=bt.second;
    }
  }

  P root(ll a){
    ll atmp = a;
    ll c=0;
    while(atmp!=p[atmp]){
      atmp = p[atmp];
      c++;
    }
    p[a] = atmp;
    return {c, atmp};
  }

  bool is_con(ll a, ll b){
    P at=root(a);
    P bt=root(b);
    return at.second == bt.second;
  }
  
};

struct dijkstra{
  ll N;
  llvec d;
  vector<vector<edge>> e;
  dijkstra(ll n){
    N = n;
    //d = llvec(N, 1e18);
    e = vector<vector<edge>>(N);
  }

  void add_edge(ll from, ll to, ll cost){
    e[from].push_back({to, cost});
  }

  void run(ll start){
    priority_queue<P, vector<P>, greater<P>> que;
    que.push({0, start});
    d = llvec(N, 1e18);
    d[start]=0;
    while(!que.empty()){
      P q = que.top();que.pop();
      ll dc = q.first;
      ll x = q.second;
      if(dc>d[x]){
        continue;
      }else{
        for(auto ip: e[x]){
          if(d[ip.x]<=d[x]+ip.c){
            continue;
          }else{
            d[ip.x]= d[x]+ip.c;
            que.push({d[ip.x], ip.x});
          }
        }
      }
    }
  }  
};


/**************************************
** A main function starts from here  **
***************************************/
int main(){
  ll N;
  cin >> N;
  llvec A(N);
  map<ll, ll> mp;
  rep(i, N){
    cin >> A[i];
    mp[A[i]]++;
  }
  ll s=0;
  for(auto imp:mp){
    s += imp.first*imp.second;
  }
  ll Q;
  cin >> Q;
  llvec B(Q), C(Q);
  rep(i, Q){
    cin >> B[i] >> C[i];
    ll nb=mp[B[i]];
    s-=nb*B[i];
    s+=nb*C[i];
    mp[B[i]]=0;
    mp[C[i]]+=nb;    
    cout << s << endl;
  }
  
  return 0;
}


Measured memory_bytes: 11388
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication4
{
    class Program
    {
        static void Main(string[] args)
        {
            int slimesNum = int.Parse(Console.ReadLine());
            string slimes = Console.ReadLine();

            char slime = ' ';
            int fusedSlimesNum = 0;
            for (int slimeNo = 0 ; slimeNo < slimesNum; slimeNo++)
            {
                if (slimes[slimeNo] != slime)
                {
                    slime = slimes[slimeNo];
                    fusedSlimesNum++;
                }
            }
            Console.WriteLine(fusedSlimesNum);
       }
    }
}


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

using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef pair<int, int> PII;

#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
#define MOD 1000000007
#define INF (1LL << 25) // 33554432
#define PI 3.14159265359
#define EPS 1e-12
//#define int ll

int pc[10010][1300];

signed main(void) {
  while (true) {
    int n, m, r, q;
    cin >> n >> m;
    if(!n && !m) break;
    REP(i, m) FOR(j, 540, 1300) pc[i][j] = 0;
    cin >> r;
    REP(i, r) {
      int a, b, c, d;
      cin >> a >> b >> c >> d;
      if (d)
        pc[c][a]++;
      else
        pc[c][a+1]--;
    }
    REP(i, m+1) FOR(j, 541, 1300) {
      pc[i][j] += pc[i][j - 1];
    }

    cin >> q;
    REP(i, q) {
      int a, b, c;
      cin >> a >> b >> c;
      int s = 0, ret = 0;
      bool flag = false;
      FOR(j, a, b+1) {
        //cout << pc[c][j] << " ";
        if (!flag && pc[c][j]) {
          s = j;
          flag = true;
        } else if(flag && !pc[c][j]) {
          ret += (j-s-1);
          flag = false;
        }
        if(j == b && pc[c][j]) {
          ret += (j-s);
        }
        //cout << s << " " << j << endl;
      }
      cout << ret << endl;
    }
  }

  return 0;
}

Measured memory_bytes: 52220
#include<cstdio>
#include<cstdlib>
#include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#include<string>
#include<cmath>
#include<cstdint>
//#include<>
using namespace std;
 
#define rep(i,j) for(int i=0;i<(int)(j);i++)
const int INF=1<<30;//=10E10
 
 
struct Edge{
  int to,cost;
  Edge(int to_,int cost_):to(to_),cost(cost_){;}
};
 
vector< vector<Edge> > G;//??\??¶??????????
 
 
//????????????????????????????????????´????????´??????????§??????
vector<int> BellmanFord(int start){
  vector<int> dist(G.size(),INF);
  dist[start]=0;
  rep(cnt,G.size()){
    bool update=false;
    rep(i,G.size()){
      for(Edge e : G[i]){
        if(dist[i]!=INF && dist[e.to]>dist[i]+e.cost){
          dist[e.to]=dist[i]+e.cost;
          update=true;
          if(cnt==(int)G.size()-1)return vector<int>(0);
        }
      }
    }
    if(!update)break;
  }
  return dist;
}
 
 
 
int main()
{
  int v,e,r;cin>>v>>e>>r;
  G.resize(v);
   
  rep(i,e){
    int s,t,d;cin>>s>>t>>d;
    G[s].push_back(Edge(t,d));
  }
   
  vector<int> dist=BellmanFord(r);
  if(dist.size()==0)cout<<"NEGATIVE CYCLE"<<endl;
  else{
    for(auto d : dist){
      if(d==INF)cout<<"INF"<<endl;
      else cout<<d<<endl;
    }
  }
  return 0;
}

Measured memory_bytes: 10236
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod=(ll)(1e9+7);
ll run();
int main() {
#ifdef home
    freopen("i", "r", stdin);
    freopen("d", "w", stderr);
#endif
    cout.precision(15);
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    run();
    return 0;
}
const ll inf = (1e18+5);

void max_self(int &a, int b){
    a= max(a,b);
}

void min_self(ll &a, ll b){
    a=min(a,b);
}

ll run() {
    int n;
    cin>>n;
    vector<double> dp(n+1,0);
    dp[0]=1;

    for(int i=1;i<=n;i++){
        double p;
        cin>>p;
        for(int h=i;h>=0;h--){
           dp[h] = dp[h-1]*p + dp[h]*(1-p);
        }
    }

    double ans = 0;
    for(int i=(n/2+1);i<=n;i++)
        ans+= dp[i];
    printf("%.12lf",ans);
}


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

int main () {
    int N;
    cin >> N;
    vector<int> tyokkei(N);
    for (int i = 0; i < N; i++) {
        cin >> tyokkei.at(i);
    }
    sort(tyokkei.begin(), tyokkei.end());
    reverse(tyokkei.begin(), tyokkei.end());

    int high = 1;
    for (int i = 0; i < tyokkei.size(); i++) {
        if ( i != 0 && tyokkei.at(i) != tyokkei.at(i - 1)) {
            high++;
        }
    }
    cout << high << endl;
}

Measured memory_bytes: 384
#pragma GCC target ("avx2")
#pragma GCC optimize ("unroll-loops")
#pragma GCC optimize ("O3")
#include "bits/stdc++.h"
#include <unordered_set>
#include <unordered_map>
#include <random>
using namespace std;
typedef long long ll;
const ll MOD = 1'000'000'007LL; /*998'244'353LL;*/
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for(int (i)=0; (i)<(n); (i)++)
const int dx[4]={ 1,0,-1,0 };
const int dy[4]={ 0,1,0,-1 };

string S;
vector<int> p[26];

int dp[200001];
int solve(int n){
    if(dp[n] != INT_MAX) return dp[n];
    rep(i, 26){
        int idx = lower_bound(all(p[i]), n) - p[i].begin();
        if(idx == p[i].size()) dp[n] = 1;
        else dp[n] = min(dp[n], 1 + solve(p[i][idx]+1));
    }
    return dp[n];
}

void print(int n){
    rep(i, 26){
        int idx = lower_bound(all(p[i]), n) - p[i].begin();
        if(idx == p[i].size()){
            cout << (char)('a'+i) << endl;
            exit(0);
        }
        else{
            if(dp[n] == 1 + solve(p[i][idx]+1)){
                cout << (char)('a'+i);
                print(p[i][idx]+1);
            }
        }
    }
}

signed main(){
    cin >> S;
    rep(i, S.size()){
        p[S[i]-'a'].pb(i);
        dp[i] = INT_MAX;
    }
    dp[S.size()] = 1;
    solve(0);
    print(0);
}

Measured memory_bytes: 5632
#include <iostream>
#include <algorithm>
#include <string>
#include <queue>
#include <vector>
#include <math.h>
using namespace std;

typedef long long ll;

/*
const ll M = 1000000007;
vector<ll> fac(3001);
vector<ll> ifac(3001);
ll mpow(ll x, ll n){
    ll ans = 1;
    while(n != 0){
        if(n&1) ans = ans*x % M;
        x = x*x % M;
        n = n >> 1;
    }
    return ans;
}
 
ll comb(ll a, ll b){
    if(a == 0 && b == 0)return 1;
    if(a < b || a < 0 || b < 0)return 0;
    ll tmp = ifac[a-b]* ifac[b] % M;
    return tmp * fac[a] % M;
}
*/


ll lcm(ll a,ll b){
 
  ll r, x, tmp;
  x = a * b;
  if(a<b){
    tmp = a;
    a = b;
    b = tmp;
  }
 
  r = a % b;
  while(r!=0){
    a = b;
    b = r;
    r = a % b;
  }
  return x/b;
}

ll gcd(ll a ,ll b){
    if(a==0){return b;}
    else if(b==0){return a;}
    else{
    ll tmp,r;
    if(a<b){
        tmp = a;
        a = b;
        b = tmp;
    }
    
    r = a % b;
    while(r!=0){
        a = b;
        b = r;
        r = a % b;
    }
    return b;
    }
}

bool sosu(ll p){
    bool ans = true;
    double psqrtd = pow(p, 0.5);
    ll psqrt = psqrtd;
    for(ll i = 2; i <= psqrt; i++){
        if(p%i==0)ans = false;
    }
    if(p==1)ans = false;
    return ans;
}

vector< bool > prime_table(ll n) {
  vector< bool > prime(n + 1, true);
  if(n >= 0) prime[0] = false;
  if(n >= 1) prime[1] = false;
  for(int i = 2; i * i <= n; i++) {
    if(!prime[i]) continue;
    for(int j = i + i; j <= n; j += i) {
      prime[j] = false;
    }
  }
  return prime;
}

int main(void){
    ll n;
    ll a = 2;
    ll b = 1;
    ll ans = 0;
    ll j,k;
    cin >> j >> k;
    n = gcd(j,k);
    for(ll i=2;i*i<=n;i++){
        while(n % i == 0) {
        if(b!=i)ans++;
        b = i;
        n /= i;
    }
    }
    if(n != 1)ans++;
    cout << ans+1 << endl;
    return 0;
}


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

using namespace std;

typedef long long ll;

const int N = 100000;
int a[N+1], b[N+1];

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n, x;
    cin >> n;
    for (int i = 0; i < n; i++)
    {
        cin >> x;
        if (i%2)
        {
            b[x]++;
        }
        else
        {
            a[x]++;
        }
    }
    int ma = 0, ai = 0;
    int mb = 0, bi = 0;
    for (int i = 0; i <= N; i++)
    {
        if (a[i] > ma)
        {
            ma = a[i];
            ai = i;
        }
        if (b[i] > mb)
        {
            mb = b[i];
            bi = i;
        }
    }
    int s = ma+mb;
    if (ai == bi)
    {
        int m = 0;
        for (int i = 0; i <= N; i++)
        {
            if (i == ai) continue;
            m = max(m, a[i]);
        }
        s = mb+m;
        m = 0;
        for (int i = 0; i <= N; i++)
        {
            if (i == bi) continue;
            m = max(m, b[i]);
        }
        s = max(s, ma+m);
    }
    cout << n - s << endl;
    return 0;
}


Measured memory_bytes: 1024
/*
	最多有 n^2 个状态
	而且第 i 步后肯定有一个棋子在 x[i]
	设 f[i][j] 表示有一个棋子在 x[i], 另一个棋子在 j
	的最小移动步数
	首先 f[i][j] = f[i - 1][j] + abs(x[i] - x[i - 1]);
	直接区间加就好了
	其次,若 j = a[i],有 f[i][a[i - 1]] = min{f[i][j] + abs(j - a[i])};
	弄两颗线段树,分情况做就好了
*/
#include <iostream>
#include <cstring>
#include <cstdio>
#define N 200005

using namespace std;

int n, Q, A, B;
int x[N];

inline void read(int &x) {
	x = 0; char ch = getchar();
	while(!isdigit(ch)) ch = getchar();
	while(isdigit(ch)) x = x * 10 + ch - '0', ch = getchar();
}

bool op;
int ll, rr;
long long arr[N], delta;

struct SMT {
#define tSize (N << 2)
#define ls(x) (x << 1)
#define rs(x) (x << 1 | 1)
	long long val[tSize], tag[tSize];
	inline void update(int u) { val[u] = min(val[ls(u)], val[rs(u)]); }
	inline void pushdown(int u) {
		if(tag[u]) {
			val[ls(u)] += tag[u], tag[ls(u)] += tag[u];
			val[rs(u)] += tag[u], tag[rs(u)] += tag[u];
			tag[u] = 0;
		}
		return;
	}
	inline void build(int l, int r, int u = 1) {
		if(l == r) return val[u] = arr[l], void();
		int mid = l + r >> 1;
		build(l, mid, ls(u)), build(mid + 1, r, rs(u));
		update(u);
		return;
	}
	inline void modify(int l, int r, int u = 1) {
		if(ll <= l && r <= rr) {
			if(op) { // add
				val[u] += delta, tag[u] += delta;
			} else { // change
				val[u] = min(val[u], delta), tag[u] = 0;
			}
			return;
		}
		pushdown(u);
		int mid = l + r >> 1;
		if(ll <= mid) modify(l, mid, ls(u));
		if(mid < rr) modify(mid + 1, r, rs(u));
		update(u);
		return;
	}
	inline long long query(int l, int r, int u = 1) {
		if(ll <= l && r <= rr) return val[u];
		pushdown(u);
		int mid = l + r >> 1;
		if(rr <= mid) return query(l, mid, ls(u));
		else if(mid < ll) return query(mid + 1, r, rs(u));
		else return min(query(l, mid, ls(u)), query(mid + 1, r, rs(u)));
	}
#undef ls
#undef rs
}func, Inc, Dec;

int main() {
	read(n), read(Q), read(A), read(B);
	
	memset(arr, 31, sizeof arr);
	x[0] = A, arr[B] = 0;
	func.build(1, n);
	
	arr[B] += B;
	Inc.build(1, n);
	
	arr[B] -= (B << 1);
	Dec.build(1, n);
	
	for(int i = 1; i <= Q; ++i) {
		read(x[i]);
		long long las = 1e16;
		ll = 1, rr = x[i];
		las = min(las, x[i] + Dec.query(1, n, 1));
		ll = x[i], rr = n;
		las = min(las, Inc.query(1, n, 1) - x[i]);
		
		op = 1, ll = 1, rr = n, delta = abs(x[i] - x[i - 1]);
		func.modify(1, n, 1);
		Inc.modify(1, n, 1);
		Dec.modify(1, n, 1);
		
		op = 0, ll = x[i - 1], rr = x[i - 1];
		delta = las;
		func.modify(1, n, 1);
		delta = las + x[i - 1];
		Inc.modify(1, n, 1);
		delta = las - x[i - 1];
		Dec.modify(1, n, 1);
	}
	ll = 1, rr = n;
	cout << func.query(1, n) << endl;
	return 0;
}

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

int main() {

  ll N;
  cin >> N;

  ll cnt = 0;
  for(int i = 1; i < N; i++){
    if(N % i == 0){
      cnt += N / i - 1;
    }else{
      cnt += N / i;
    }
  }
  cout << cnt << endl;
}

Measured memory_bytes: 3648
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<utility>
#include<set>
#include<stack>
#include<list>
#include<deque>
#include<bitset>
#include<iomanip>
#include<cstring>
#include<sstream>
#include<cstdio>
#include<cstdlib>
#include<climits>
#include<cmath>
#include<cctype>


#define pb push_back
#define mp make_pair
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define ren(i,a,b) for(int i=a;i>=b;i--)
#define ff first
#define ss second
#define pll pair<long long int,long long int>
#define pii pair<int,int>
#define vll vector<long long int>
#define vii vector<int>
#define gi(n) scanf("%d",&n)
#define gll(n) scanf("%lld",&n)
#define gstr(n) scanf("%s",n)
#define gl(n) cin >> n
#define oi(n) printf("%d",n)
#define oll(n) printf("%lld",n)
#define ostr(n) printf("%s",n)
#define ol(n) cout << n
#define os cout<<" "
#define on cout<<"\n"
#define o2(a,b) cout<<a<<" "<<b
#define all(n) n.begin(),n.end()
#define present(s,x) (s.find(x) != s.end())
#define cpresent(s,x) (find(all(s),x) != s.end())
#define tr(container, it) for(__typeof(container.begin()) it = container.begin(); it != container.end(); it++)
using namespace std;

typedef unsigned long long int ull;
typedef long long int ll;
typedef long double ld;
typedef vector<vector<ll> > mat;


int main()
{ios_base::sync_with_stdio(false);
ll x;
cin>>x;
ll ans=0,cnt=1;
while(1)
{
	if(x<=0)break;
	ans+=cnt;
	x/=2;
	cnt*=2;
}
ol(ans);
return 0;
}



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

int main() {
  int h, w;
  cin >> h >> w;
  vector<vector<int>> field(h, vector<int>(w));
  for(int i=0;i<h;i++) {
    for(int j=0;j<w;j++) {
      cin >> field[i][j];
    }
  }

  vector<vector<int>> output(0, vector<int>(4));

  for(int i=0;i<h;i++) {
    for(int j=0;j<w-1;j++) {
      if(field[i][j] % 2 != 0) {
        field[i][j]--;
        field[i][j+1]++;
        vector<int> vec = {i+1, j+1, i+1, j+2};
        output.emplace_back(vec);
      }
    }
  }

  for(int i=0;i<h-1;i++) {
    if(field[i][w-1] % 2 != 0) {
      field[i][w-1]--;
      field[i+1][w-1]++;
      vector<int> vec = {i+1, w, i+2, w};
      output.emplace_back(vec);
    }
  }

  cout << output.size() << endl;

  for(int i=0;i<output.size();i++) {
    cout << output[i][0] << " " << output[i][1] << " " << output[i][2] << " " << output[i][3] << endl;
  }
}

Measured memory_bytes: 10032
import Data.List

main = do
  [n,k] <- map read . words <$> getLine :: IO [Int]
  hs <- map read . words <$> getLine :: IO [Int]
  putStrLn $ show (ans k hs)

ans :: Int -> [Int] -> Int
ans k hs = sum $ drop k ((reverse . sort) hs)


Measured memory_bytes: 82812
#include<bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < n; ++i)
#define rrep(i,n) for (int i = n-1; i >= 0; i--)
#define rep2(i,s,n) for (int i = s; i < n; ++i)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define tmax(a,b,c) max(a,max(b,c))
#define tmin(a,b,c) min(a,min(b,c))
#define pb push_back
#define eb emplace_back
#define vi vector<int>
#define vvi vector<vector<int>>
#define vl vector<ll>
#define vs vector<string>
#define vc vector<char>
#define vb vector<bool>
#define vp vector<P>
using namespace std;
using ll = long long;
using P = pair<int,int>;
using LP = pair<ll,ll>;
template<class T> istream& operator>>(istream& is,vector<T>& v) { for(T& t:v){is>>t;} return is; }
template<class T> ostream& operator<<(ostream& os,const vector<T>& v) { for(T t:v){os<<t<<" ";} os<<"\n"; return os; }
void Yes(bool b) { cout << (b ? "Yes" : "No") << endl; }
void YES(bool b) { cout << (b ? "YES" : "NO") << endl; }
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 int inf = 1001001001;
const ll linf = 1001001001001001001;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr); cout.tie(nullptr);
    int r,g,b,n;
    cin >> r >> g >> b >> n;
    ll ans = 0;
    for(int i = 0; i*r <= n; i++) {
        for(int j = 0; i*r+j*g <= n; j++) {
            int rem = n-i*r-j*g;
            if(rem%b == 0) ans++;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const unsigned int M = 1000000007;
#define ll long long
int main() {
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    char n;
    while(cin>>n){
        n+=1;
        cout<<n<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
fun main() = Thread(null, ::msolutions2020b, "(^o^)", 128 * 1024 * 1024).apply { start() }.join()

@OptIn(ExperimentalStdlibApi::class)
fun msolutions2020b() {
    var (a, b, c) = readLine()!!.split(" ").map { it.toInt() }
    val k = readLine()!!.toInt()

    repeat(k) {
        if (b <= a) b *= 2
        else if (c <= b) c *= 2
    }

    val answer = if (b in (a + 1) until c) "Yes" else "No"

    println(answer)
}


Measured memory_bytes: 36720
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,sum=0,a,b;
    cin>>n;
    for(int i=0;i<n;i++)
    {
        cin>>a>>b;
        sum+=(b-a+1);
    }
    cout<<sum<<"\n";
    return 0;
}


Measured memory_bytes: 3588