akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp>
//#include <boost/math/common_factor_rt.hpp>
#define USE_MATH_DEFINES
#define rep(i, n) for (int i = 0; i < (n); i++)
typedef long long ll;

using namespace std;
// namespace mp = boost::multiprecision;
// namespace mt = boost::math
// using Bint = mp::cpp_int;

int main() {
    ll n, i, j, k, kind = 1;
    bool flag = false, flag2 = true;
    cin >> n;
    ll a[n], a2[n], a3[n][2] = {};
    rep(i, n) {
        cin >> a[i];
        a2[i] = a[i];
        if (a[i] != 0)
            flag2 = false;
    }
    if (n == 3) {
        ll tmp = a[0] ^ a[1] ^ a[2];
        if (tmp == 0)
            flag = true;
    }
    sort(a2, a2 + n);
    ll cnt = 0;
    a3[0][0] = a2[0];
    a3[0][1] = 1;
    rep(i, n - 1) {
        if (a2[i] != a2[i + 1]) {
            kind++;
            cnt++;
            a3[cnt][0] = a2[i + 1];
        }
        a3[cnt][1]++;
    }
    // cout << a3[0][1] << a3[1][1];
    if (kind == 2 && a2[0] == 0 && a3[0][1] * 2 == a3[1][1])
        flag = true;
    if (kind == 3 && a3[0][1] == a3[1][1] && a3[1][1] == a3[2][1]) {
        ll tmp = a3[0][0] ^ a3[1][0] ^ a3[2][0];
        if (tmp == 0)
            flag = true;
    }
    if (flag || flag2)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
    // cout << ans << endl;
}

Measured memory_bytes: 3328
#include <iostream>
#include<stdio.h>
#include<string>
#include<string.h>
#include<vector>
#include<set>
#include<map>
#include<algorithm>
#include<cstring>
#include<math.h>
#include<cmath>
using namespace std;
int main()
{
    long long int a;
    cin>>a;
    if(a%2==0)
        cout<<a;
    else
        cout<<a*2;
    return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cmath>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
#define _USE_MATH_DEFINES
#include <math.h>
#include <functional>
#include<complex>
using namespace std;

#define rep(i,x) for(ll i=0;i<x;i++)
#define repn(i,x) for(ll i=1;i<=x;i++)

typedef long long ll;
const ll INF = 1e17;
const ll MOD = 998244353;
const ll MAX = 4000001;
const double eps = 1E-18;

ll max(ll a, ll b) {
	if (a > b) { return a; }
	return b;
}

ll min(ll a, ll b) {
	if (a > b) { return b; }
	return a;
}

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

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

struct edge {
	ll ind;
	ll fr;
	ll to;
	ll d;
};

class mint {
	long long x;
public:
	mint(long long x = 0) : x((x% MOD + MOD) % MOD) {}
	mint operator-() const {
		return mint(-x);
	}
	mint& operator+=(const mint& a) {
		if ((x += a.x) >= MOD) x -= MOD;
		return *this;
	}
	mint& operator-=(const mint& a) {
		if ((x += MOD - a.x) >= MOD) x -= MOD;
		return *this;
	}
	mint& operator*=(const  mint& a) {
		(x *= a.x) %= MOD;
		return *this;
	}
	mint operator+(const mint& a) const {
		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 pow(ll t) const {
		if (!t) return 1;
		mint a = pow(t >> 1);
		a *= a;
		if (t & 1) a *= *this;
		return a;
	}

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

	friend ostream& operator<<(ostream& os, const mint& m) {
		os << m.x;
		return os;
	}
};

mint pw(mint a, ll b) {
	if (b == 0) { return 1; }
	mint ret = pw(a, b>>1);
	ret *= ret;
	if (b & 1) { ret *= a; }
	return ret;
}

typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef vector<vector<vector<ll>>> vvvll;

typedef vector<mint> vmint;
typedef vector<vector<mint>> vvmint;
typedef vector<vector<vector<mint>>> vvvmint;

//////////////////////////////////////
vector<mint> frac, ifrac;
void finit(ll X) {
	frac.assign(X + 1, 1);
	ifrac.assign(X + 1, 1);

	repn(i, X) {
		frac[i] = frac[i - 1] * i;
		ifrac[i] = ifrac[i - 1] / i;
	}

}

mint com(ll n, ll m) {
	if (n < 0 || m < 0 || n < m) { return 0; }
	return frac[n] * ifrac[m] * ifrac[n - m];
}

int main() {
	ll N, X;
	cin >> N >> X;

	mint ans = 0;
	finit(N);

	rep(i, N + 1) {
		rep(j, N+1) {
			if (i + j > N) { continue; }

			vll c(3);
			c[0] = i;
			c[1] = j;
			c[2] = N - i - j;

			ll S = c[1] + 2 * c[2];
			mint t = 0;

			if (S < X) {
				t += com(c[1] + c[2], c[1]) * com(N, c[0]);
			}

			else if((S-X)%2==1) {
				if (j == 0) { t += com(N, c[0]); }
				else {
					ll K = (S - X + 1) / 2;

					t += com(c[1] + c[2] - 2 * K, c[1]) * com(N, c[0]);
				}
			}

			ans += t;
			//cout << i << " " << j << " " << c[2] << " " << t << endl;
		}
	}

	cout << ans << endl;
}


Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;

int N, M;
vector<int> H(100000);
bool isA;
int ans;
void dfs(const Graph &G, int v){
    isA=true;
    for (auto g:G[v])
    {
        if(H[v]<=H[g]){
            isA=false;
            return;
        }
    }
    return;
    
}

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

    for (int i = 0; i < N; i++)
    {
        cin >> H[i];
    }
    Graph G(N);
    for (int i = 0; i < M; i++)
    {
        int a, b;
        cin >> a >> b;
        G[a-1].push_back(b-1);
      	G[b-1].push_back(a-1);
    }
    for (int i = 0; i < N; i++)
    {
        dfs(G, i);
      	if(isA) ans++;
    }
    
   cout << ans << endl;    

}

Measured memory_bytes: 11904
#include<bits/stdc++.h>
using namespace std;
#define i64 long long int
int n,A,B,x[101111];
int main(){
	scanf("%d%d%d%d",&n,&A,&B,&x[0]);
	--n;
	i64 res = 0;
	for(int i=1; i<=n; i++){
		scanf("%d",&x[i]);
		res += min((i64)B,(i64)A*(x[i]-x[i-1]));
	}
	cout << res << endl;
	return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define pb push_back
#define f first
#define s second
using namespace std;
typedef long long ll;
const int MAX=1e5+55;
int x[MAX];
int dp[100000+55];
 int n;
 int cho1=0;
 int cho2=0;
int solve(int i)
{
    //cout<<'1'<<" "<<cho1<<" "<<x[i]<<" "<<i<<" "<<last<<endl;

    if(i==n){
        return 0;
    }
    if(i==n-1)
        return abs(x[i]-x[i+1]);
    int &ret=dp[i];
    if(ret!=-1)
        return ret;
        ret=min(abs(x[i]-x[i+1])+solve(i+1),abs(x[i]-x[i+2])+solve(i+2));
        return ret;




}
int main()
{
 cin>>n;
 memset(dp,-1,sizeof dp);
 for(int i=1;i<=n;i++)
    cin>>x[i];
 cout<<solve(1);

return 0;
}


Measured memory_bytes: 2560
min1,min2=100,100
sum1,sum2=0,0
for i in range(4):
    a=int(input())
    sum1+=a
    if a<min1:
        min1=a
sum1=sum1-min1
for j in range(2):
    b=int(input())
    sum2+=b
    if b<min2:
        min2=b
sum2=sum2-min2
print(sum1+sum2)


Measured memory_bytes: 5596
#include<bits/stdc++.h>
using namespace std;
#define ll long long                                    // long long省略
#define pb push_back                                    // push_back省略
#define mp make_pair                                    // make_pair省略
#define fi first                                        // first省略
#define se second                                       // second省略
#define itn int                                         // int誤字保険
#define count cout                                      // cout誤字保険
#define vecotr vector                                   // vector誤字保険
#define ednl endl                                       // endl誤字保険
#define opt() cin.tie(0); ios::sync_with_stdio(false)   // 入出力速度改善

#define rep(i,l,r) for(ll i=(l);i<(r);i++)               // 範囲[l, r)で刻み1のfor文(順方向)
#define repp(i,l,r,k) for(ll i=(l);i<(r);i+=(k))         // 範囲[l, r)で刻みkのfor文(順方向)
#define rrep(i,l,r) for(ll i=(r-1);i>=(l);i--)           // 範囲[l, r)で刻み1のfor文(逆方向)
#define rrepp(i,l,r,k) for(ll i=(r-1);i>=(l);i-=(k))     // 範囲[l, r)で刻みkのfor文(逆方向)
#define all(x) (x).begin(), (x).end()                   // vectorのポインタ位置指定用
#define max(p,q)((p)>(q)?(p):(q))                       // max拡張
#define min(p,q)((p)<(q)?(p):(q))                       // min拡張
#define bit(n,m)(((n)>>(m))&1)                          // 変数nのm番目のbitを取り出す

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

int dy[]={0, 1, 0, -1};                                 // 4方向近傍
int dx[]={1, 0, -1, 0};                                 // 4方向近傍

int main(){
    ll a,b,c,d;cin>>a>>b>>c>>d;
    if(a+b == c+d) cout << "Balanced" << ednl;
    if(a+b < c+d)  cout << "Right" << ednl;
    if(a+b > c+d)  cout << "Left" << ednl;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>

using namespace std;

#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define MOD 1000000007
#define rep(i,n) for(i=0;i<n;i++)
#define loop(i,a,n) for(i=a;i<n;i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
#define first F
#define second S

typedef vector<int> vi;
typedef pair<int,int> pii;

int main(void) {
  int i,j,n;
  vector<bool> prime(100000,true);
  for(i=2;i<100000;i++)
    if(prime[i])
      for(j=2;i*j<100000;j++)
        prime[i*j]=false;
  prime[0]=prime[1]=false;

  while(scanf("%d",&n)!=EOF){
    int ans=0;
    rep(i,n)
      if(prime[i+1]==true && prime[n-i]==true)ans++;
    cout<<ans<<endl;
  }
}

Measured memory_bytes: 3152
#include <stdio.h>
#define MAX 1000000
int prime_count[MAX];
int main(void){
  int n = 0, i, j;
 
  for(i = 2; i < MAX; ++i){
    if(prime_count[i] != -1){
      for(j = i * 2; j < MAX; j += i){
        prime_count[j] = -1;
      }
      prime_count[i] = ++n;
    }else{
      prime_count[i] = n;
    }
  }
 
  while(scanf("%d", &n) != EOF){
    printf("%d\n", prime_count[n]);
  }
  return 0;
}

Measured memory_bytes: 4496
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <vector>
#define rep(i,n) for(int i=0; i<(n); ++i)
#define outl(x) cout<< (x) << '\n'
using namespace std;
using pii = pair<int,int>;

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

   int N;
   int a[200010];
   int minv;
   int maxv;

   cin >> N;
   cin >> minv;

   int ans = -0x7f7f7f7f;

   for (int i=1, x; i < N; ++i) {
       cin >> x;
        ans = max(ans, x - minv);
        minv = min(minv, x);
   }
   outl(ans);
}




Measured memory_bytes: 3192
import sys
sys.setrecursionlimit(10**6)
readline = sys.stdin.readline
write = sys.stdout.write

N, M = map(int, readline().split())

G = [[] for i in range(N)]
for i in range(M):
    u, v = map(int, readline().split())
    G[u].append(v)
    G[v].append(u)

# a chain decomposition
def construct(G, N):
    P = [0]*N
    G0 = [[] for i in range(N)]
    V = []
    lb = [0]*N
    def dfs(v, p):
        P[v] = p
        V.append(v)
        lb[v] = len(V)
        for w in G[v]:
            if w == p:
                continue
            if lb[w]:
                if lb[v] < lb[w]:
                    # a backedge
                    G0[v].append(w)
                continue
            # a tree edge
            dfs(w, v)
    dfs(0, -1)

    used = [0]*N
    first = 1
    B = []
    used[0] = 1
    ap = [0]*N
    for u in V:
        if not used[u]:
            # (u, p) is a bridge
            p = P[u]
            B.append((u, p) if u < p else (p, u))
            if len(G[u]) > 1:
                ap[u] = 1
            if len(G[p]) > 1:
                ap[p] = 1
        cycle = 0
        for v in G0[u]:
            w = v
            while w != u and not used[w]:
                used[w] = 1
                w = P[w]
            if w == u:
                cycle = 1
        if cycle:
            if not first:
                ap[u] = 1
            first = 0
    # v is a cut vertex
    A = [v for v in range(N) if ap[v]]

    return B, A

B, A = construct(G, N)

B.sort()
for u, v in B:
    write("%d %d\n" % (u, v))


Measured memory_bytes: 22752
#include <iostream>

struct Card {char suit; int value;};

constexpr int MAXNUM = 100000;
constexpr int SENTINEL = 2000000000;


void merge(Card *A, int l, int m, int r) {
    int nl = m - l;
    int nr = r - m;
    Card L[MAXNUM / 2 + 2];
    Card R[MAXNUM / 2 + 2];

    for (int i = 0; i < nl; i++) {
        L[i] = A[l + i];
    }
    for (int i = 0; i < nr; i++) {
        R[i] = A[m + i];
    }
    L[nl].value = SENTINEL;
    R[nr].value = SENTINEL;
    int li = 0, ri = 0;
    for (int i = l; i < r; i++) {
        if(L[li].value <= R[ri].value) {
            A[i] = L[li++];
        }else {
            A[i] = R[ri++];
        }
    }
}

void mergeSort(Card *A, int l, int r) {
    if (l + 1 < r) {
        int m = (r + l) / 2;
        mergeSort(A, l, m);
        mergeSort(A, m, r);
        merge(A, l, m, r);
    }
}



int partition(Card *A, int l, int r) {
    int p = A[r].value;
    int pi = l - 1;
    for (int i = l; i < r; i++) {
        if(A[i].value <= p) {
            pi++;
            std::swap(A[i], A[pi]);
        }
    }
    pi++;
    std::swap(A[r], A[pi]);
    return pi;
}

void quickSort(Card *A, int l, int r) {
    if (l < r) {
        int pi = partition(A, l, r);
        quickSort(A, l, pi-1);
        quickSort(A, pi+1, r);
    }
}

int main(int argc, char** argv){
    int n;
    Card A[MAXNUM], B[MAXNUM];
    std::cin >> n;
    for (int i = 0; i < n; i++){
        char c;
        int v;
        std::cin >> c;
        std::cin >> v;
        A[i].suit = B[i].suit = c;
        A[i].value = B[i].value = v;
    }

    mergeSort(A, 0, n);
    quickSort(B, 0, n - 1);

    int stable = 1;
    for (int i = 0; i < n; i++) {
        if (A[i].suit != B[i].suit) {
            stable = 0;
            break;
        }
    }

    if (stable) {
        std::cout << "Stable" << std::endl;
    }else {
        std::cout << "Not stable" << std::endl;
    }
    for (int i = 0; i < n; i++) {
        std::cout << B[i].suit << " " << B[i].value << std::endl;
    }

}


Measured memory_bytes: 5428
#include <stdio.h>
#include <stdlib.h>
int cmpint(const void *a, const void *b) {
	return *(int *)a - *(int *)b;
}

int main(){
	int n,ans,d[100000]={};
	scanf("%d", &n);
	for (int i = 0; i < n; i++)
		scanf("%d", &d[i]);
	qsort(d,n, sizeof(int), cmpint);
	ans=d[n/2]-d[n/2-1];
	printf("%d\n", ans);
	return 0;
}


Measured memory_bytes: 892
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin >> n;
    int a[n];
    for (int i = 0; i < n; i++)
        cin >> a[i];
    int mx = *max_element(a, a + n);
    bool dp[mx + 1];
    bool vis[mx + 1];
    memset(dp, true, sizeof(dp));
    memset(vis, false, sizeof(vis));
    sort(a, a + n);
    int cnt = 0;
    for (int i = 0; i < n; i++)
    {
        if (dp[a[i]] && !vis[a[i]])
        {
            vis[a[i]] = true;
            for (int p = a[i] * 2; p <= mx; p += a[i])
            {
                dp[p] = false;
            }
        }
        else if (vis[a[i]])
        {
            dp[a[i]] = false;
        }
    }
    for (int i = 0; i < n; i++)
    {
        if (dp[a[i]])
        {
            cnt++;
        }
    }
    cout << cnt;
}

Measured memory_bytes: 6300
#include<iostream>
#include <cstdio>
using namespace std;
int main(){
    int n;
    cin>>n;

    long long min=1000000,max=-1000000,sum=0;
    long long x;
    for(int i=0;i<n;i++){
        cin>>x;
        sum+=x;
        if(min>x){
            min=x;
        }if(max<x){
            max=x;
        }
    }
    cout<<min<<" "<<max<<" "<<sum<<endl;
    return 0;
}


Measured memory_bytes: 3120
n = int(input())
a_l = list(map(int,input().split()))

dp1 = a_l[0] + a_l[1] # last num is not changed
dp2 = -a_l[0] - a_l[1] # last num is changed

for i in range(2,n):
    dp1, dp2 = \
        max(dp1 + a_l[i], dp2 + a_l[i]), \
            max(dp2 + a_l[i-1]*2 - a_l[i], dp1 - a_l[i-1]*2 - a_l[i])

print(max(dp1,dp2))


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

typedef long long ll;
#define all(x) (x).begin(),(x).end()

template<typename T>
T mod(T a, T b){
    return (a + b) % b;
}

template<typename T>
T gcd(T a, T b){
    if (b == 0) return a;
    return gcd(b, a % b);
}

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

// n を素因数分解
map<ll, ll> factor(ll n){
    map<ll, ll> mp;
    for (ll i = 2; i*i <= n; i++) {
        while (n % i == 0) {
            mp[i]++;
            n /= i;
        }
    }

    if (n > 1) {
        mp[n]++;
    }

    return mp;
}

// 文字列に "hoge" が含まれているか
// string str = "hogepiyo";
// if (str.find("hoge") != string::npos) {
//     cout << "文字列が含まれています" << endl;
// }

// char to string
// char c = 'a';
// string str = {c};

void solve(){
    ll N, K, Q;
    cin >> N >> K >> Q;

    vector<ll> A(N, 0);
    for (int i = 0; i < Q; i++) {
        int a; cin >> a; a--;
        A[a]++;
    }

    for (int i = 0; i < N; i++) {
        if (K - (Q - A[i]) > 0) {
            cout << "Yes" << endl;
        } else {
            cout << "No" << endl;
        }
    }


    return;
}

int main(int argc, char const* argv[])
{
    solve();
    return 0;
}


Measured memory_bytes: 1408
#include<bits/stdc++.h>
#include<iostream>
#include<cmath>
#include<vector>
#include<string>
#include<queue>
#include<set>
#include<map>
#include<algorithm>
#include<functional>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
typedef pair<ull, ull> pullull;
typedef pair<ll, int> plli;
typedef pair<int, pii> pipii;
typedef vector<vector<int> > mati;
typedef vector<vector<double> > matd;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef vector<vector<vector<ll>>> vvvll;
typedef vector<bool> vb;
typedef vector<vector<bool>> vvb;
typedef vector<vector<vector<bool>>> vvvb;

#define FOR(i,x,y) for(ll i=(ll)x; i<(ll)y; ++i)
#define REP(i,y) FOR(i, 0, y)

template <typename T>
void vec_print(vector<T> VEC){
  REP(i, VEC.size()){
    cout << VEC[i] << " ";
  }
  cout << "\n";
};

template <typename T>
void mat_print(vector<vector<T> > MAT){
  REP(i, MAT.size()){
    REP(j, MAT[i].size()){
      cout << MAT[i][j] << " ";
    }
    cout << "\n";
  }
};

template <typename CLASS1, typename CLASS2>
class HOGE{
  public:
    CLASS1 key;
    CLASS2 value;
    HOGE(void){
      return;
    };
    HOGE(CLASS1 key, CLASS2 value){
      this->key = key;
      this->value = value;
    };
    ~HOGE(void){
      return;
    };

    void print(void){
      cout << "key : " << key << ", value : " << value << "\n";
      return;
    };
    
    bool operator==(const HOGE &obj){
      return (this->value == obj.value);
    };
    bool operator<(const HOGE &obj){
      return (this->value < obj.value);
    };
    bool operator>(const HOGE &obj){
      return (this->value > obj.value);
    };
};

constexpr int INF = (1<<30);
constexpr ll INFLL = 1LL<<62;
constexpr long double EPS = 1e-12;
constexpr ll MOD = (ll)((1E+9)+7);

int main(){
  cin.tie(0); // cut the cin and cout (default, std::flush is performed after std::cin)
  ios::sync_with_stdio(false); // cut the iostream and stdio (DON'T endl; BUT "\n";)

  ll N, M;
  cin >> N >> M;
  vll tmp(M, 0);
  REP(i, N){
    ll K;
    cin >> K;
    REP(j, K){
      ll A;
      cin >> A;
      tmp[A-1]++;
    }
  }

  ll ans=0;
  REP(i, M){
    if(tmp[i]==N) ans++;
  }

  cout << ans << "\n";

  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, a, b) for (int i = (a); i <= int(b); i++)
#define per(i, a, b) for (int i = (a); i >= int(b); i--)
using namespace std;

typedef long long ll;
const int maxn = 2e6, mod = 1e9 + 7;
int x[10], y[10], fact[maxn + 3], finv[maxn + 3];

int qpow(int a, int b) {
	int c = 1;
	for (; b; b >>= 1, a = 1ll * a * a % mod) if (b & 1) c = 1ll * a * c % mod;
	return c;
}

void prework(int n) {
	fact[0] = 1;
	rep(i, 1, n) fact[i] = 1ll * fact[i - 1] * i % mod;
	finv[n] = qpow(fact[n], mod - 2);
	per(i, n, 1) finv[i - 1] = 1ll * finv[i] * i % mod;
}

int calc(int n, int m) {
	if (n < 0 || m < 0) return 0;
	return 1ll * fact[n + m + 2] * finv[n + 1] % mod * finv[m + 1] % mod;
}

int ask1(int lx, int rx, int ly, int ry, int x, int y) {
	return ((ll)calc(x - lx, y - ly) - calc(x - lx, y - ry - 1) - calc(x - rx - 1, y - ly) + calc(x - rx - 1, y - ry - 1) + mod * 2) % mod;
}

int ask2(int lx, int rx, int ly, int ry, int x, int y) {
	return ((ll)calc(rx - x, ry - y) - calc(rx - x, ly - y - 1) - calc(lx - x - 1, ry - y) + calc(lx - x - 1, ly - y - 1) + mod * 2) % mod;
}

#define mat1 x[1], x[2], y[1], y[2]
#define mat2 x[5], x[6], y[5], y[6]

int main() {
	prework(maxn);
	rep(i, 1, 6) scanf("%d", &x[i]);
	rep(i, 1, 6) scanf("%d", &y[i]);
	int A = 0, B = 0;
	rep(i, x[3], x[4]) {
		A = (A + 1ll * (i + y[3] - 1) * ask1(mat1, i, y[3] - 1) % mod * ask2(mat2, i, y[3])) % mod;
		B = (B + 1ll * (i + y[4]) * ask1(mat1, i, y[4]) % mod * ask2(mat2, i, y[4] + 1)) % mod;
	}
	rep(i, y[3], y[4]) {
		A = (A + 1ll * (x[3] - 1 + i) * ask1(mat1, x[3] - 1, i) % mod * ask2(mat2, x[3], i)) % mod;
		B = (B + 1ll * (x[4] + i) * ask1(mat1, x[4], i) % mod * ask2(mat2, x[4] + 1, i)) % mod;
	}
	printf("%d\n", (B - A + mod) % mod);
	return 0;
}

Measured memory_bytes: 15872
import java.util.Scanner;
import java.util.List;
import java.util.ArrayList;
 
public class Main {
  
  static int N,M;
  
  static List<Integer> s = new ArrayList<>();
  static List<Integer> c = new ArrayList<>();
  
 public static void main(String[] args){
   Scanner scanner = new Scanner(System.in);
   N = scanner.nextInt();
   M = scanner.nextInt();
   for(int i = 0;i < M;i++){
     s.add(scanner.nextInt());
     c.add(scanner.nextInt());
   }
   System.out.println(solve());
 }
  
  public static String solve(){
    for(int i = 0;i < 1000;i++){
      String str = String.valueOf(i);
      if(ok(str))return str;
    }
    return "-1";
  }
  
  public static boolean ok(String str){
    if(str.length() != N) return false;
    for(int i = 0;i < M;i++){
      if(str.charAt(s.get(i) - 1) != (char)((int)c.get(i) + '0')) return false;
    }
    return true;
  }
}

Measured memory_bytes: 21844
#include<stdio.h>
int main(){
  int N,M;
  scanf("%d %d",&N,&M);
  int *p;
  int days = N;
  p = (int *)malloc(M*sizeof(int));
  for ( int i=0; i < M; i++ ){
    scanf("%d ",(p+i));
  }
  for ( int i=0; i < M; i++){
    days = days - *(p+i);
  }
  if ( days >= 0){
    printf("%d", days);
  }
  else{
    printf("-1");
  }
  return(0);
}

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

#define int long long
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,f,n) for(int i=(f);i<(n);i++)
#define all(v) (v).begin(),(v).end()
#define each(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)
#define pb push_back
#define fi first
#define se second
template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

signed main(){
    int N,D;
    cin>>N>>D;

    int ans=D;
    int tmp=N-(D+1);
    ans+=tmp*(tmp-1)/2;
    ans+=tmp*2;
    if(D>=2)ans+=tmp;
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 1156
def main():
    answer = "No"
    head,leg = map(int,input().split())
    for tsuru in range(0,head+1):
        kame = head - tsuru
        if tsuru * 2 + kame * 4 == leg:
            answer = "Yes"
            break

    print(answer)



if __name__ == '__main__':
    main()


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

int n;
vector<vector<int>> v(100000,vector<int> (3));
int dp[100000][3];
int help(int day,int prev){
if(day>=n) return 0;
else{
int &r=dp[day][prev];
if(r!=-1) return r;
for(int i=0;i<3;i++)
if(prev!=i)
r=max(r,help(day+1,i)+v[day][i]);
return r;
}
}
int main()
{
cin>>n;
for(int i=0;i<n;i++)
cin>>v[i][0]>>v[i][1]>>v[i][2];
memset(dp,-1,sizeof(dp));
int val=0;
for(int i=0;i<3;i++)
val=max(val,help(1,i)+v[0][i]);
cout<<val;
return 0;
}


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

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

        int slime=1;
        for(int n=1; n<N; n++) if(S.charAt(n-1)!=S.charAt(n)) slime++;
        System.out.println(slime);
    }
}


Measured memory_bytes: 23820
#include<iostream>
#include<algorithm>
#include<string>
#include<cmath>
#include<vector>
#include<map>
using namespace std;
int main() {
    int N, A, B;
    cin >> N >> A >> B;
    if((B-A)%2 == 0) cout << "Alice" << endl;
    else cout << "Borys" << endl;

    return 0;
}

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

typedef long long ll;

#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)
#define trav(a,x) for (auto& a : x)

#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define ins insert

const char nl = '\n';

int main() {
	ios_base::sync_with_stdio(0); cin.tie(0);
	// freopen("input.in", "r", stdin);
	// freopen("input.out", "w", stdout);
    int n, k; cin >> n >> k;
    vector<ll> a(n + 1);
    FOR(i, 1, n + 1) {
        cin >> a[i];
    }
    FOR(i, k + 1, n + 1) {
        if (a[i - k] < a[i]) cout << "Yes" << nl;
        else cout << "No" << nl;
    }
}

Measured memory_bytes: 4780
#include<bits/stdc++.h>
#pragma g++ optimize(2)
using namespace std;
int n,sum=1;
int tot,root;
struct node{
	int l,r;
	int dat,val;
	int size;
}f[2000010];
void update(int p)
{
	f[p].size=f[f[p].l].size+f[f[p].r].size+1;
}
int New(int val)
{
	f[++tot].val=val;
	f[tot].dat=rand();
	f[tot].size=1;
	return tot;
}
void split(int p,int val,int &x,int &y)
{
	if(p==0)
	{
		x=0,y=0;
		return;
	}
	if(f[p].val<=val)
	{
		x=p;
		split(f[p].r,val,f[p].r,y);
	}
	else
	{
		y=p;
		split(f[p].l,val,x,f[p].l);
	}
	update(p);
}
int merge(int a,int b)
{
	if(!a||!b) return a+b;
	if(f[a].dat<f[b].dat)
	{
		f[a].r=merge(f[a].r,b);
		update(a);
		return a;
	}
	else
	{
		f[b].l=merge(a,f[b].l);
		update(b);
		return b;
	}
}
void insert(int val)
{
	int x,y;
	split(root,val,x,y);
	root=merge(merge(x,New(val)),y);
}
void remove(int val)
{
	int x,y,z;
	split(root,val,x,z);
	split(x,val-1,x,y);
	y=merge(f[y].l,f[y].r);
	root=merge(merge(x,y),z);
}
int getRank(int val)
{
	int x,y;
	split(root,val-1,x,y);
	int ans=f[x].size+1;
	root=merge(x,y);
	return ans;
}
int getVal(int p,int rank)
{
	while(p)
	{
		if(f[f[p].l].size>=rank) p=f[p].l;
		else if(f[f[p].l].size+1==rank) return f[p].val;
		else rank-=f[f[p].l].size+1,p=f[p].r;
	}
}
int getPre(int val)
{
	int x,y;
	split(root,val-1,x,y);
	int ans=getVal(x,f[x].size);
	root=merge(x,y);
	return ans;
}
int getNext(int val)
{
	int x,y;
	split(root,val,x,y);
	int ans=getVal(y,1);
	root=merge(x,y);
	return ans;
}
int a[2000010];
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=pow(2,n);i++)
	{
		int x;
		scanf("%d",&x);
		insert(x);
	}
	insert(-1);
	a[1]=getPre(1999999999);
	remove(a[1]);
	for(int i=0;i<n;i++)
	{
		for(int j=1;j<=pow(2,i);j++)
		{
			int x=getPre(a[j]);
			remove(x);
			if(x==-1)
			{
				cout<<"No"<<endl;
				return 0;
			}
			tot++,a[tot]=x;
		}
		sort(a+1,a+tot+1,greater<int>()); 
	} 
	cout<<"Yes"<<endl;
	return 0;
}

Measured memory_bytes: 12544
#define TEST_MODE true

#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES

#include "bits/stdc++.h"
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep2(i, a, b) for (int i = (a); i < (b); ++i)
#define rrep(i, n) for (int i = (n)-1; i >= 0; --i)
#define rrep2(i, a, b) for (int i = (a)-1; i >= b; --i)
#define range(i, a, b, c) for (int i = a;             \
                               c > 0 ? i < b : i > b; \
                               i += c)
#define chmax(a, b) (a = (a) < (b) ? (b) : (a))
#define chmin(a, b) (a = (a) > (b) ? (b) : (a))
using ll = long long;
using ull = unsigned long long;
using ld = long double;
#define all(a) begin(a), end(a)
#define ifnot(a) if (not(a))
#define int long long

#ifdef LOCAL_ENV

#if TEST_MODE == true
const bool test = true;
#define dump(x) cerr << #x << " = " << (x) << endl
#else
const bool test = false;
#define dump(x) 
#endif

#else
const bool test = false;
#define dump(x) 
#endif

int dx[] = {1, 0, -1, 0};
int dy[] = {0, 1, 0, -1};
const int INF = (int)1 << 60;
const ll INFL = (ll)1 << 60;
ll mod_n = (int)1e9 + 7;
const double eps = 1e-10;
typedef long double Real;
// return -1, 0, 1
int sgn(const Real &r) { return (r > eps) - (r < -eps); }
int sgn(const Real &a, const Real &b) { return sgn(a - b); }

//.....................
const int MAX = (int)2e5 + 5;

vector<string> split(const string &str, char sep)
{
    vector<string> v;
    stringstream ss(str);
    string buffer;
    while (getline(ss, buffer, sep))
    {
        v.push_back(buffer);
    }
    return v;
}

template <class InputIterator>
int sum(InputIterator begin, InputIterator end)
{
    return accumulate(begin, end, 0ll);
}

void solve();

signed main()
{
    cout << fixed << setprecision(20);
    solve();
    while (true)
    {
        char s[MAX];
        if (scanf("%s", s) == EOF)
            break;
        int n = strlen(s);
        for (int i = n - 1; i > -1; i--)
        {
            ungetc(s[i], stdin);
        }
        solve();
    }
    return 0;
}

int n;
int s[105];
bool dp[10005];

void solve() {
    cin >> n;
    rep(i, n) cin >> s[i];
    dp[0] = true;
    rep(i, n) {
        rrep(j, 10003) {
            int cur = j + s[i];
            if (cur > 10003) continue;
            if (dp[j] == false) continue;
            dp[j+s[i]] = true;
        }
    }
    int res = 0;
    rep(i, 10005) {
        if (dp[i] == true && i % 10 != 0) res = i;
    }
    cout << res << endl;
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.HashSet;
import java.util.Set;
import java.util.StringTokenizer;

public class Main {
  public static void main(String[] args) {
	FastReader sc = new FastReader();
	int n = sc.nextInt();
	int res = 0;
	
	for (int i = 0; i < n; i++) {
		int l = sc.nextInt();
		int r = sc.nextInt();
		
		res += (r - l) + 1;
	}
	
	System.out.println(res);
	
  }
  
  static class FastReader {
    BufferedReader br;
    StringTokenizer st;

    public FastReader() {
      br = new BufferedReader(new InputStreamReader(System.in));
    }
  
    String next() { 
      while (st == null || !st.hasMoreElements()) {
        try {
          st = new StringTokenizer(br.readLine());
        } catch (IOException  e) {
          e.printStackTrace();
        }
      }
      return st.nextToken();
    }

    int nextInt() {
      return Integer.parseInt(next());
    }

    long nextLong() {
      return Long.parseLong(next());
    }

    double nextDouble() { 
      return Double.parseDouble(next());
    }

    String nextLine() {
      String str = "";
        try{
            str = br.readLine();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return str;
      }
  }
}


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

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

    int w,h,n;cin>>w>>h>>n;

    int x1=0,x2=w,y1=0,y2=h;

    for(int i=0;i<n;i++)
    {
        int x,y,a;cin>>x>>y>>a;

        if(a==1)x1=max(x1,x);
        if(a==2)x2=min(x2,x);
        if(a==3)y1=max(y1,y);
        if(a==4)y2=min(y2,y);
    }

    int ans=max(x2-x1,0)*max(y2-y1,0);

    cout<<ans<<"\n";

    return 0;
}


Measured memory_bytes: 3648
#include <stdio.h>
int main(){
  int 	a, b, ans=1;
  char	s[16]={0};
  scanf("%d%d", &a, &b);
  scanf("%s", s);
  
  //a
  for(int i=0; i<a; i++){
    if( s[i] < '0' || s[i] > '9' ){ ans = 0; }
  }
  //-
  if( s[a] != '-' ){ ans = 0; }
  //b
  for(int i=a+1; i<a+b+1; i++){
    if( s[i] < '0' || s[i] > '9' ){ ans = 0; }
  }

  if( ans ){ printf("Yes\n"); }
  else	   { printf("No\n");  }
  return 0;
}

Measured memory_bytes: 1620
#include <bits/stdc++.h>
using namespace std;
#define int long long

//pre:O(nlog n)
//query:O(log n)

class LCA {
private:
  int V, LV;
  int root;
  vector<vector<int>> G, parent;
  vector<int> depth;

  void add_edge(int u, int v) {
    G[u].push_back(v);
    G[v].push_back(u);
  }
  void dfs(int v, int p, int d) {
    parent[0][v] = p;
    depth[v] = d;
    for (int i = 0; i < G[v].size(); i++) {
      if (G[v][i] != p)
        dfs(G[v][i], v, d + 1);
    }
  }
  void get_init() {
    dfs(root, -1, 0);
    for (int k = 0; k + 1 < LV; k++) {
      for (int v = 0; v < V; v++) {
        if (parent[k][v] < 0)
          parent[k + 1][v] = -1;
        else
          parent[k + 1][v] = parent[k][parent[k][v]];
      }
    }
  }
  int get_lca(int u, int v) {
    if (depth[u] > depth[v])
      swap(u, v);
    for (int k = 0; k < LV; k++) {
      if ((depth[v] - depth[u]) >> k & 1) {
        v = parent[k][v];
      }
    }
    if (u == v)
      return u;

    for (int k = LV - 1; k >= 0; k--) {
      if (parent[k][u] != parent[k][v]) {
        u = parent[k][u];
        v = parent[k][v];
      }
    }
    return parent[0][u];
  }

public:
  LCA(int V, int root) : V(V), root(root), G(V, vector<int>()), depth(V) {
    int v_ = 1, cnt = 0;
    while (v_ < V) v_ *= 2, cnt++;
    LV = cnt;
    parent.resize(LV, vector<int>(V));
  }

  void init() { return get_init(); }
  void addEdge(int u, int v) { return add_edge(u, v); }
  int get(int u, int v) { return get_lca(u, v); }
};

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

  if (n == 1) {
    cout << 0 << endl;
    return 0;
  }

  LCA lca(n, 0);

  for (int i = 0; i < n; i++) {
    int k;
    cin >> k;
    while (k--) {
      int c;
      cin >> c;
      lca.addEdge(i, c);
    }
  }

  lca.init();

  int q;
  cin >> q;

  while (q--) {
    int u, v;
    cin >> u >> v;
    cout << lca.get(u, v) << endl;
  }

  return 0;
}



Measured memory_bytes: 25832
#include <iostream>
#include<algorithm>
#include<cmath>
#include <string>
#include <vector>
typedef unsigned long long ULL;

 int main (){
	 std::string str;

	 std::cin >> str;

	 for (int i = 0; i < str.size(); ++i) {
		 std::cout << str[str.size() - 1 - i];
	 }
	 std::cout << "" << std::endl;
	 return 0;
}


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

int main() {
  int N, count=0;
  cin >> N;
  vector<int> num(N);
  repi(i,N) cin >> num.at(i);
  for(int i=0; i<N; i+=2) if(num.at(i)%2==1) count++;
  cout << count << endl;
  return 0;
}

Measured memory_bytes: 3584
a,b,c,x,y = map(int,input().split())

k = 0 #価格
if c*2 < a+b:
    z = min([x,y])
    k += z*c*2
    x -= z
    y -= z

if c*2 < a: k += x*c*2
else: k += x*a
    
if c*2 < b: k += y*c*2
else: k += y*b

print(k)

Measured memory_bytes: 3060
#include <vector>
#include <iostream>
#include <set>
#include <queue>
#include <cassert>

using namespace std;

vector<set<int>> G, R;

struct Solver {
    queue<pair<int, int>> q;
    vector<int> link, is_ok;

    Solver(int n) : link(n, -1), is_ok(n, 1) {}

    void try_push(int a, int b) {
        if (!G[a].count(b) or !R[a].count(b))
            return;
        q.emplace(a, b);
    }

    pair<int, int> get() {
        auto ret = q.front();
        q.pop();
        return ret;
    }

    bool empty() {
        return q.empty();
    }

    bool ok(int x) {
        return is_ok[x];
    }

    void unite(int a, int b) {

        assert(a != b);
        if (G[a].size() + R[a].size() > G[b].size() + R[b].size())
            swap(a, b);
        
        G[a].erase(b);
        G[b].erase(a);
        R[a].erase(b);
        R[b].erase(a);

        is_ok[a] = false;

        for (auto x : G[a]) {
            G[x].erase(a);
            G[x].insert(b);
            G[b].insert(x);
        }

        for (auto x : R[a]) {
            R[x].erase(a);
            R[x].insert(b);
            R[b].insert(x);
        }
        
        for (auto x : G[a]) try_push(b, x);
        for (auto x : R[a]) try_push(b, x);
    }
};

int main() {
    int n; cin >> n;
    G.resize(n); R.resize(n);
    
    for (int _ = 0; _ < 2; ++_) {
        for (int i = 1; i < n; ++i) {
            int a, b; cin >> a >> b; 
            G[a - 1].insert(b - 1); 
            G[b - 1].insert(a - 1);
        }
        swap(G, R);
    }

    Solver solver(n);
    
    for (int i = 0; i < n; ++i) {
        for (auto x : R[i]) {
            solver.try_push(i, x);
        }
    }

    for (int i = 1; i < n; ++i) {
        if (solver.empty()) {
            cout << "NO" << endl;
            return 0;
        }
        
        pair<int, int> p = solver.get();
        if (!solver.ok(p.first) or !solver.ok(p.second)) {
            --i;
            continue;
        }
        solver.unite(p.first, p.second);
    }

    cout << "YES" << endl;
    return 0;
}


Measured memory_bytes: 25088
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <complex>
#include <utility>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <tuple>
#include <cmath>
#include <bitset>
#include <cctype>
#include <set>
#include <map>
#include <unordered_map>
#include <numeric>
#include <functional>
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(ll i=ll(a);i<ll(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define PRINT(V) cout << V << "\n"
#define SORT(V) sort((V).begin(),(V).end())
#define RSORT(V) sort((V).rbegin(), (V).rend())
using namespace std;
using ll = long long;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
inline void Yes(bool condition){ if(condition) PRINT("Yes"); else PRINT("No"); }
template<class itr> void cins(itr first,itr last){
    for (auto i = first;i != last;i++){
        cin >> (*i);
    }
}
template<class itr> void array_output(itr start,itr goal){
    string ans = "",k = " ";
    for (auto i = start;i != goal;i++) ans += to_string(*i)+k;
    if (!ans.empty()) ans.pop_back();
    PRINT(ans);
}
ll gcd(ll a, ll b) {
    return a ? gcd(b%a,a) : b;
}
const ll INF = 1e15;
const ll MOD = 1000000007;
const ll MOD2 = 998244353;
typedef pair<ll,ll> P;
const ll MAX = 2010;
constexpr ll nx[8] = {1,0,-1,0,-1,-1,1,1};
constexpr ll ny[8] = {0,1,0,-1,-1,1,-1,1};
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n,a;
    cin >> n >> a;
    Yes(n%500 <= a);
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
typedef long long int ll;
#define FOR(i,l,r) for(i=l;i<r;i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(x) x.begin(),x.end()
#define P pair<ll,ll>
#define F first
#define S second
signed main(){
  ll M,N,i=2,ans;cin>>M;vector<ll>D;
  if(M==1)ans=1;
  else{
    ll N=2*M;
    while(i*i<=N){
      if(N%i==0){
        D.push_back(i);N/=i;
        while(N%i==0){N/=i;D.at(D.size()-1)*=i;}
      }
      i++;
    }
    if(N!=1)D.push_back(N);sort(ALL(D));
    ll s=1;REP(i,D.size())s*=2;
    REP(i,s){
      ll A=1,B=1,j,x=i;
      REP(j,D.size()){if(x%2==0)A*=D.at(j);else B*=D.at(j);x/=2;}
      vector<ll>R(2,0),Q(2,A);R.at(1)=B-1;Q.at(1)=B;P Y=crt(R,Q);
      if(Y.F==0)Y.F+=Y.S;ans=min(ans,Y.F);
    }
  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 3668
#include <bits/stdc++.h> 
using namespace std; 
int main() 
{
  ios_base::sync_with_stdio(false); 
    cin.tie(NULL);    
int n,k;
cin>>n>>k;
vector<int>dp(n,1e9),arr(n);
for(int i=0;i<n;i++) cin>>arr[i];
dp[0]=0;
for(int i=0;i<n;i++) for(int j=1; j<=k&&j<=i; j++) dp[i]=min(dp[i],dp[i-j]+abs(arr[i]-arr[i-j]));
cout<<dp[n-1];
} 


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

double line(double a, double b, double c, double d){

  return sqrt(abs(a-c) * abs(a-c) + abs(b-d) * abs(b-d));

}

int main(){

  double x, y, xx, yy, xxx, yyy, s = 0, z, a, b, c;
  scanf("%lf,%lf", &x, &y);
  scanf("%lf,%lf", &xx, &yy);

  while(~scanf("%lf,%lf", &xxx, &yyy)){
    a = line(x, y, xx, yy);
    b = line(xx, yy, xxx, yyy);
    c = line(x, y, xxx, yyy);

    z = (a + b +c) / 2.0;

    s += sqrt(z * (z-a) * (z-b) * (z-c));

    xx = xxx, yy = yyy;
  }

  printf("%.12lf\n", s);
}

Measured memory_bytes: 1240
import sys
def input(): return sys.stdin.readline().rstrip()
import heapq

N, M = map(int,input().split())
A = list(map(lambda x:int(x) * (-1),input().split()))
heapq.heapify(A)

for i in range(M):
    a = heapq.heappop(A)
    a *= -1
    a //= 2
    a *= -1    
    heapq.heappush(A,a)

print(-sum(A))


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

struct UnionFind {
    vector<int> par;
    UnionFind(int n) : par(n, -1) {}

    int find(int x) {
        if (par[x] < 0)
            return x;
        else
            return par[x] = find(par[x]);
    }

    void unite(int x, int y) {
        x = find(x);
        y = find(y);
        if (x == y)
            return;
        if (par[x] > par[y])
            swap(x, y);
        par[x] += par[y];
        par[y] = x;
    }

    int size(int x) {
        return -par[find(x)];
    }

    bool same(int x, int y) {
        return find(x) == find(y);
    }
};

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

    int n;
    cin >> n;
    int mx = 100005;

    UnionFind uf(200200);

    rep(i, 0, n) {
        int x, y;
        cin >> x >> y;
        uf.unite(x, y + mx);
    }
    map<int, ll> mpx, mpy;

    rep(i, 1, mx) {
        mpx[uf.find(i)]++;
        mpy[uf.find(i + mx)]++;
    }
    ll ans = -n;

    rep(i, 0, 2 * mx) ans += mpx[i] * mpy[i];
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 26112
#include <iostream>
using namespace std;
int main(){
	string s;
	int num[10];
	int tmp[10];
	while(cin>>s){
		for(int i=0;i<s.size();++i)if('0'<=s[i]&&s[i]<='9')num[i]=s[i]-'0';
		for(int i=9;i>0;--i){
			for(int j=0;j<i;++j) tmp[j]=(num[j]+num[j+1])%10;
			for(int j=0;j<i;++j) num[j]=tmp[j];
		}
		cout<<num[0]<<"\n";
	}
	return 0;
}

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

int main(){
	int N,L;
	string A;
	cin >> N >> L;
	vector <string> S(N);
	for(int i=0;i<N;i++){
		cin >> S[i];
	}
	sort(S.begin(),S.end());
	for(int i=0;i<N;i++){
		A+=S[i];
	}
	cout << A << endl;
	return 0;
}


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

int main(){
	int N, X, T;
  	cin >> N >> X >> T;
  	int a = N / X;
 if(N % X != 0) T *= a + 1;
  if(N % X == 0) T *= a;
  cout << T << endl;
}

Measured memory_bytes: 3600
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n,m,x,y;scanf("%d%d%d%d",&n,&m,&x,&y);
	if (m%y)
	{
		cout<<"Yes\n";
		for (int i=1;i<=n;i++)
		for (int j=1;j<=m;j++)
		{
			if (j%y==1) cout<<1000000*(y-1)-1<<' ';else cout<<-1000000<<' ';
			if (j==m) cout<<endl;
		}
		return 0;
	}
	if (n%x)
	{
		cout<<"Yes\n";
		for (int i=1;i<=n;i++)
		for (int j=1;j<=m;j++)
		{
			if (i%x==1) cout<<1000000*(x-1)-1<<' ';else cout<<-1000000<<' ';
			if (j==m) cout<<endl;
		}
		return 0;
	}
	cout<<"No\n";
}

Measured memory_bytes: 2432
#include<bits/stdc++.h>
//#define long long ll ;
#define mod 1e+9;
#define rep for(int i=0;i<n;i++);
#define pb push_back;
#define popb pop_back;
using namespace std;
const int ma=1e6+9;
typedef long long ll;

int main()
{
//     #ifndef ONLINE_JUDGE
// 	freopen("input.txt", "r", stdin);
// 	freopen("output.txt", "w", stdout);
// #endif
   ios_base::sync_with_stdio(0);
    cin.tie(0);
    int k;
    cin >>k;
    ll cnt=0;
    for(int i=1;i<=k;i++)
    {
      cnt=(cnt*10+7)%k;
      if(cnt%k==0)
      {
         cout << i << endl;
        return 0;
      }
    }
    
    cout <<"-1" <<endl;
    //else
      //cout << i << endl;

  }


Measured memory_bytes: 3692
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <stdlib.h>
#include <string.h>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <stdio.h>
#include <tuple>
#include <bitset>
#include <cfloat>
#include <fstream>
#include <limits.h>
#include <list>
#include <math.h>
#include <random>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <numeric>
#include <utility>
#include <sstream>
#define int long long
#define rep(i, n) for (int i = 0; i < (n); i++)
#define P pair<int, int>
#define sz(x) x.size()
#define ALL(x) (x).begin(),(x).end()
#define ALLR(x) (x).rbegin(),(x).rend()
#define V vector<int>
#define COUT(x) cout<<(x)<<endl
#define M map<int,int>
#define S set<int>
#define PQ priority_queue<int>
#define PQG priority_queue<int,V,greater<int>>

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

using namespace std;
typedef long long ll;
using Graph = vector<vector<int>>;
ll gcd(ll a, ll b) {
	if (a < b)swap(a, b);
	if (b == 0) return a;
	return gcd(b, a % b);
}
ll lcm(ll a, ll b) {
	ll g = gcd(a, b);
	return a / g * b;
}
bool prime(int n) {
	for (int i = 2; i <= sqrt(n); i++) {
		if (n%i == 0)return false;
	}
	return n != 1;
}


const long long MOD = 1000000007;
const long long INF = 1LL << 50;

// pair -> vector<pair<int,int>> 
//		   AandB.push_back(make_pair(a[i],b[i]))

signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n; cin >> n;
	int ans = 1;
	rep(i, n) {
		int a; cin >> a;
		ans = lcm(ans, a);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void) {
	char c;
	scanf("%c", &c);
	switch (c) {
		case 97:
		case 101:
		case 105:
		case 111:
		case 117:printf("vowel");break;
		default:printf("consonant");
	}
	return 0;
}

Measured memory_bytes: 128
import sys


if __name__ == "__main__":
    n, m = map(lambda x: int(x), input().split())
    coins = list(map(lambda x: int(x), input().split()))

    table = [sys.maxsize] * (n + 2)
    table[0] = 0
    for i in range(n + 1):
        for coin in coins:
            if (i + coin <= n):
                table[i + coin] = min(table[i + coin], table[i] + 1)

    print(table[n])



Measured memory_bytes: 7260
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<string>
#include<vector>
#include<deque>
#include<queue>

using std::cout;
using std::cin;
using std::setw;
using std::setfill;
using std::string;
using std::pair;
using std::make_pair;
using std::vector;
using std::queue;
using std::deque;
using std::priority_queue;
using std::next_permutation;
//using std::iota;
using std::sort;
using std::greater;
using std::max;
using std::min;

using lli = long long int;
using ulli = unsigned long long int;

#define INF 999999999;
#define MOD 1000000007;

#define EVEL 1

#ifndef EVEL
#define dbug(X) std::cout << #X << ":" <<X<<" " ;
#define dbugf(s) std::cout << s << " ";
#define dbugln std::cout<<"\n";
#else
#define dbug(X) {}
#define dbugf(s) {}
#define dbugln {}
#endif



int D;
string a = "Christmas";

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

	cin >> D;
	for(int i = 25; i > D; i--){
		a = a + " Eve";
	}
	cout << a;

	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define lp3(i,a,b) for(int i=a;i<b;i++)
#define lp2(i,n) for(int i=0;i<n;i++)
#define ll long long
#define W 1000000007
using namespace std;

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


Measured memory_bytes: 256