akhauriyash/Code-Regression huggingface dataset:
// #pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define ll long long
#define rep2(i,a,b) for(ll i=a;i<=b;++i)
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep3(i,a,b) for(ll i=a;i>=b;i--)
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pq priority_queue
#define pb push_back
#define eb emplace_back
#define vec vector<int>
#define vecll vector<ll>
#define vecpii vector<pii>
#define vec2(a,b) vector<vec>(a,vec(b))
#define vec2ll(a,b) vector<vec>(a,vecll(b))
#define vec3(a,b,c) vector<vector<vec>>(a,vec2(b,c))
#define vec3ll(a,b,c) vector<vector<vecll>>(a,vec2ll(b,c))
#define fi first
#define se second
#define endl "\n"
#define all(c) begin(c),end(c)
#define ios ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define lb(c,x) distance(c.begin(),lower_bound(all(c),x))
#define ub(c,x) distance(c.begin(),upper_bound(all(c),x))
#define MM " "
using namespace std;
int in() {int x;cin>>x;return x;}
ll lin() {ll x;cin>>x;return x;}
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
template<class T> inline void print(pair<T,T> p){cout<<"("<<p.first<<","<<p.second<<") ";}
template<class T> inline void print(vector<pair<T,T>> v){for(auto e:v)print(e); cout<<endl;}
template<class T> inline void print(T v){for(auto e:v)cout<<e<<" ";cout<<endl;}



vector<vec> g;
vecll c;
ll sum;
pll dfs(int x,int p){
    vector<pll> v;
    ll mi=0;
    for(auto e:g[x]){
        if(e==p)continue;
        v.pb(dfs(e,x));
        chmin(mi,v.back().fi);
    }
    ll res=1;
    for(auto e:v){
        sum+=(e.fi-mi)*e.se;
        res+=e.se;
        c[x]+=(e.fi-mi);
    }
    sum-=mi;
    c[x]-=(-mi)*g[x].size();
    if(p!=-1)
    c[p]+=-mi;
    pll P={c[x],res};
    return P;
}
main(){
    int n=in();
    g.resize(n);
    // c.resize(n)
    rep(i,n-1){
        int a=in()-1,b=in()-1;
        g[a].pb(b);
        g[b].pb(a);
    }
    vec a,b;
    rep(i,n)c.pb(in());
    rep(i,n)c[i]-=in();
    dfs(0,-1);
    cout<<sum<<endl;
}



Measured memory_bytes: 20564
#include "bits/stdc++.h"
// Custom Header <<<
#define ALL(x) x.begin(), x.end()
#define rep(i, s, n)      for(int i(s); i < int(n); ++i)
#define endl '\n'
#ifndef YDK
#define eprintf(...)
#endif
using namespace std;
using i64 = long long;
using pii = pair<i64, i64>;
template<class A, class B>inline bool chmax(A &a, const B &b){return b>a ? a=b,1 : 0;}
template<class A, class B>inline bool chmin(A &a, const B &b){return b<a ? a=b,1 : 0;}
constexpr int INF  = 0x3f3f3f3f;
constexpr i64 LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr int MOD  = int(1e9) + 7;
// >>>

int N;
string a, b;
int dp[55];

int slv(int k, int prev1 = -1, int prev2 = -1)
{
    if (k >= N) return 1;
    if (~dp[k]) return dp[k];

    i64 ret = 0;

    // tate fill
    if (a[k] == b[k]) {
        for (int color : {0, 1, 2}) {
            if (color != prev1 && color != prev2) {
                ret = (ret + slv(k+1, color, color)) % MOD;
            }
        }
    }
    // yoko fill
    else {
        for (int color1 : {0, 1, 2}) {
            for (int color2 : {0, 1, 2}) {
                if (color1 != prev1 && color2 != prev2 && color1 != color2) {
                    ret = (ret + slv(k+2, color1, color2)) % MOD;
                }
            }
        }
    }

    return dp[k] = ret % MOD;
}

signed main()
{
    cin >> N >> a >> b;

    memset(dp, -1, sizeof(dp));
    cout << slv(0) << endl;
    return 0;
}

/* vim:set foldmethod=marker foldmarker=<<<,>>> : */


Measured memory_bytes: 256
#include<stdio.h>

int main(void){

  int N, S = 0;
  scanf("%d", &N);
  int keep = N;
  
  while(keep){
    S += keep % 10;
    keep /= 10;
  }

  if(N % S == 0){
    puts("Yes");
  }else{
    puts("No");
  }

  return 0;
}

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

int main(int argc, char *argv[]){
	int const count = 3;
	int nums[count];
	//??\???
	for(int i = 0; i < count; i++){
		cin >> nums[i];
	}

	//?°??????????????????????
	for(int i = 0; i < count - 1; i++){
		for(int j = i + 1; j < count; j++){
			if (nums[i] > nums[j]) {
				int temp = nums[i];
				nums[i] = nums[j];
				nums[j] = temp;
			}
		}
	}

	//??????
	for(int i = 0; i < count - 1; i++){
		cout << nums[i] << ' ';
	}
	cout << nums[count - 1];
	cout << "\n";
}

Measured memory_bytes: 3080
// AOJ DPL_1_C Knapsack Problem
// 2018.5.4 bal4u

#include <stdio.h>
#include <string.h>

#if 1
#define gc() getchar_unlocked()
#else
#define gc() getchar()
#endif
int in()
{
	int n = 0, c = gc();
	do n = 10*n + (c & 0xf), c = gc(); while (c >= '0');
	return n;
}

#define MAX_N 102
#define MAX_W 10002

int N, M;
int dp[MAX_W];

// v[]: value, w[]: weight
int knapsack(int N, int W, int *v, int *w)
{
	int i, j;
	
	memset(dp, 0, W<<2);
	for (i = 0; i < N; i++) {
		for (j = w[i]; j <= W; j++) {
			int d = j - w[i], x = dp[d] + v[i];
			if (x > dp[j]) dp[j] = x;
		}
	}
	return dp[W];
}

int val[MAX_N], weight[MAX_N];

int main()
{
	int N, W, i;

	N = in(), W = in();
	for (i = 0; i < N; i++) {
		val[i] = in(), weight[i] = in();
	}
	printf("%d\n", knapsack(N, W, val, weight));
	return 0;
}



Measured memory_bytes: 2128
N, M, Q = map(int, input().split())
LR = [[0] * (N+1) for _ in range(N+1)]
for m in range(M):
    l, r = map(int, input().split())
    LR[l][r] += 1

# 二次元累積和をとる
LR_sum = [[0] * (N+1) for _ in range(N+1)]
LR_sum[1][1] = LR[1][1]
## 初期化
for i in range(1, N+1):
    LR_sum[1][i] = LR_sum[1][i-1] + LR[1][i]
    LR_sum[i][1] = LR_sum[i-1][1] + LR[i][1]
## 累積和をとる
for i in range(2, N+1):
    for j in range(2, N+1):
        LR_sum[i][j] = LR_sum[i-1][j] + LR_sum[i][j-1] - LR_sum[i-1][j-1] + LR[i][j]

for q in range(Q):
    l, r = map(int, input().split())
    print(LR_sum[r][r] - LR_sum[r][l-1] - LR_sum[l-1][r] + LR_sum[l-1][l-1])


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

using namespace std;

int main()
{
	//freopen("input2.txt","r",stdin);freopen("output2.txt","w",stdout);
	int i,j,n,k,a[10],b[10];
    cin>>n>>k;
    fill(a,a+10,0);
    for (i=0;i<k;i++){
    	cin>>j;
    	a[j]++;
    }
    for (i=n;;i++){
    	k=i;
    	fill(b,b+10,0);
    	while (k>0){
    		b[k%10]++;
    		k/=10;
    	}
    	bool q=true;
    	for (j=0;j<10;j++){
    		if (b[j]>0&&a[j]>0){
    			q=false;
    			break;
    		}
    	}
    	if (q==true){
    		cout<<i;
    		break;
    	}
    }
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int dp[3005][3005];
string s,t;
void  lcs(int m,int n)
{
	
	for(int i=0;i<=m;i++)
	{
		for(int j=0;j<=n;j++)
		{
			if(i==0||j==0)
		    dp[i][j]=0;

	}
	}
	for(int i=1;i<=m;i++)
	{
		for(int j=1;j<=n;j++)
		{
			if(s[i-1]==t[j-1])
				dp[i][j]=1+dp[i-1][j-1];
			else
				dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
		}
}


}

int main()
{
 
	
  cin>>s>>t;
  int m=s.length();
  int n=t.length();
   lcs(m,n);
   int i=m;int j=n;

   string str="";
   while(i>0 && j>0)
   {
   	if(s[i-1]==t[j-1])
   	{
         str.push_back(s[i-1]);
         i--;
         j--;
   	}
   	else
   	{
   		if(dp[i][j-1]>dp[i-1][j])
   			j--;
   		else
   			i--;
   	}
   }

   reverse(str.begin(), str.end()); 
   cout<<str;
 
   
}


   


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

int main(){
  int A, B;
  cin >> A >> B;
  int cnt = 0;
  
  for(int i = A; i < B+1; i++){
    string istr = to_string(i);
    if(istr[0] == istr[4] && istr[1] == istr[3]){
      cnt++;
    }
  }
  cout << cnt << endl;
    
}

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

long long int pow(int n,int m){
  long long int res=1;
  for(int i=0;i<m;i++)
    res*=n;
  return res;
}

int main(){
  long long int N,K;
  cin >> N >> K;
  cout << K*pow(K-1,N-1) << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;;
#define ll long long
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

int main(){
    string s; cin >> s;
    if(s.size()==3){
        reverse(s.begin(), s.end());
    }
    cout << s << endl;


}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define pb          push_back
#define mp          make_pair
#define ll          long long
#define pii         pair<int, int>
#define vi          vector<int>
#define vii         vector<pii>
#define mi          map<int, int>
#define mii         map<pii, int>
#define all(a)      (a).begin(),(a).end()
#define x           first
#define y           second
#define sz(x)       (int)x.size()
#define endl        '\n'
#define hell        1000000007
#define debug(x) cout << '>' << #x << ':' << x << endl;
#define rep(i,a,b)  for(int i=a;i<b;i++)
#define rev(i,a,b)  for(int i=a;i>=b;i--)
#define lb          lower_bound
#define ub          upper_bound

#define bg(i)       i.begin()
#define fset(it,s)   for(auto it = s.begin(); it != s.end(); it++)
 
#define track(x)                 cerr<<#x<<": "<<x<<endl
#define track2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define track3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define track4(a, b, c, d)       cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
 
#define ed(i)       i.end()
#define mem(a)	    memset(a, 0, sizeof(a))

#define MOD         1000000007
int mult(int a,int b, int p=MOD){return ((a%p)*(b%p))%p;}
int add(int a, int b, int p=MOD){return (a + b + p)%p;}
int fpow(int n, int k, int p = MOD) {int r = 1; for (; k; k >>= 1LL) {if (k & 1LL) r = mult(r,n,p); n = mult(n,n,p);} return r;}
int inv(int a, int p = MOD) {return fpow(a, p - 2, p);}
void self_max(int &a, int b) {a = max(a, b); }
void self_min(int &a, int b) {a = min(a, b); }
void self_add(int &a, int b, int p = MOD) { a += b; if(a >= p) a -= p;}
void self_sub(int &a, int b, int p = MOD) { a -= b; if(a < 0) a += p;}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
 
const int INF = 1e9 + 5;
#define N	    	400001

int a[N];
int ans = 0;

int getmin(int l, int r) {
    int ans = a[l];
    int ind = l;
    rep(i, l+1, r+1) {
        if(a[i] < ans) {
            ans = a[i];
            ind = i;
        }
    }
    return ind;
}

void dfs(int l, int r, int curr) {
    if(l > r)
        return;
    int ind = getmin(l, r);
    ans += a[ind] - curr;
    curr = a[ind];
    dfs(l, ind-1, curr);
    dfs(ind+1, r, curr);
}
void solve(){
    int n;
    cin>>n;
    rep(i, 0, n) cin>>a[i];
    dfs(0, n-1, 0);
    cout<<ans<<endl;
}
int main() {
	ios::sync_with_stdio(false);
	cout<<fixed<<setprecision(20);
	cin.tie(0);
	cout.tie(0);
	int t = 1;
//	cin>>t;
	while(t--){
		solve();
	}
}

Measured memory_bytes: 3632
N = int(input())

alpha = [chr(i) for i in range(97, 97+26)]


k=0
while N>=0:
    N -= 26**k
    k += 1

A = []
k -= 1
len_k = k
while k >= 0:
    A.append(N//(26**k))
    N %= (26**k)
    k -= 1

res = []
for i in A[-len_k:]:
    res.append(alpha[i])

print("".join(res))

Measured memory_bytes: 61720
#include <bits/stdc++.h>
#define ZERO(a) memset(a,0,sizeof(a))
#define FILL(a,b) memset(a,b,sizeof(a))
#define SORT(v) sort((v).begin(),(v).end())
#define RSORT(v) sort((v).rbegin(),(v).rend())
#define FOR(i,a,b)  for(int i=a, i##_len=(b); i<i##_len; ++i)
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
using namespace std;

int main(void) {
    int Ans[2];
    cin >> Ans[0];
    cin >> Ans[1];
    int i;

    for (i = 1; i <= 3; i++) {
        if (Ans[0] != i && Ans[1] != i) {
            break;
        }
    }
    cout << i << endl;
    return 0;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-


def isDivisor(target, n):
    return n % target == 0


# スペース区切りの整数の入力
a, b = map(int, input().split())

if isDivisor(a, b):
    output = a + b
else:
    output = b - a

print("{}".format(output))

Measured memory_bytes: 2940
H,W,A,B=map(int,input().split())
mod=10**9+7
kaijo=[0]*(H+W+1)
kaijo[0]=1
for i in range(1,H+W+1):
    kaijo[i]=(kaijo[i-1]*i)%mod
gyaku=[0]*(H+W+1)
gyaku[H+W]=pow(kaijo[H+W],mod-2,mod)
for i in range(H+W,0,-1):
    gyaku[i-1]=(gyaku[i]*i)%mod
def conb(x,k):
    return (kaijo[x]*gyaku[k]*gyaku[x-k])%mod
ans=0
for i in range(W-B):
    ans=(ans+conb(H-A-1+B+i,H-A-1)*conb(A-1+W-1-B-i,A-1))%mod
print(ans)

Measured memory_bytes: 18804
#include <iostream>
#include <algorithm>
#include <string>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <vector>
#include <queue>
#include <stack>
#include <cmath>
#include <map>
#include <iomanip>
#include <set>
using namespace std;

#define rep(i, s) for (int i = 0; i < s; ++i)
#define all(v) (v.begin(), v.end())
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
#define VEC(a, n) vector<int>a(n)
#define PQ(a) priority_queue<int>a
#define PQmin(a) priority_queue< int, :vector<int>, greater<int> >a
#define PAIR pair<int, int>
/*
sort(sp.begin(), sp.end(), [](PAIR l, PAIR r){
        return l.first<r.first || (l.first==r.first && l.second > r.second);
        });
*/

typedef long long  ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))


int main() {
   int n,d;
   cin>>n>>d;
   cout<< ((n%(2*d+1)==0) ? n/(2*d+1) : n/(2*d+1)+1) << endl;





    return 0;
}


Measured memory_bytes: 256
use std::io;

fn main() {
    let mut line = String::new();
    io::stdin().read_line(&mut line).unwrap();
    let v: Vec<_> = line.split_whitespace()
        .map(|s| s.parse::<i32>().unwrap())
        .collect();
    let count = (v[0]..(v[1] + 1)).filter(|i| v[2] % i == 0).count();
    println!("{}", count);
}



Measured memory_bytes: 5044
#include <iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<limits>
#include<string.h>
#include<vector>
#include<stack>
#include<queue>
using namespace std;

int main()
{
    int64_t x,k,d;
    cin>>x>>k>>d;
    int64_t a,b;
    if (x>=0)
    {
        if (x/d>=k)
        {
            cout<<x-(k*d)<<endl;
        }else
        {
            if (k%2==0)
            {
                a=x%(2*d);
                b=(2*d)-a;
                cout<<min(b,a)<<endl;               
            }else
            {
                a=(x+d)%(2*d);
                b=(2*d)-a;
                cout<<min(b,a)<<endl;                  
            }
            
            


        }
        
        
    }else
    {
        if (k<=(-x)/d)
        {
            cout<<(-x-(k*d))<<endl;
        }else
        {
            if (k%2==0)
            {
                a=(-x)%(2*d);
                b=(2*d)-a;
                cout<<min(b,a)<<endl;                
            }else
            {
                a=(-x+d)%(2*d);
                b=(2*d)-a;
                cout<<min(b,a)<<endl;   
            }
            
            
            

        }
        
        
    }
    
    

    return 0;
}

Measured memory_bytes: 3580
#include<iostream>
#include<cstdio>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>
#include<map>
#include<bitset>
#include<queue>
using namespace std;
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) FOR(i,0,n)
typedef long long ll;
int main(){
	vector<ll> v;
	rep(i,3){
		ll a;
		cin >> a;
		v.push_back(a);
	}
	if(v[0]%2==0||v[1]%2==0||v[2]%2==0){
		cout << "0" << endl;
	}
	else{
		sort(v.begin(),v.end());
		cout << v[0]*v[1] <<endl;
	}

	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int main(){
	ll n,k;
	cin>>n>>k;
	ll a[n+1]={0};
	for(ll i=0;i<k;i++)
	{
		ll d;
		cin>>d;
		for(ll j=0;j<d;j++)
		{
			ll h;
			cin>>h;
			a[h]++;
		}
	}
	ll g=0;
	for(ll i=1;i<=n;i++)
	{
		if(a[i]==0)g++;
	}
	cout<<g;
}

Measured memory_bytes: 3592
d = int(input())
c = list(map(int,input().split()))
s = []
p = [1]*d
for i in range(d):
    s.append(list(map(int,input().split())))
x = [1]*26
for i in range(d):
    q = 1
    m = -1
    for j in range(26):
        n = s[i][j] + x[j]*c[j]
        x[j] += 1
        if(m < n):
            m = n
            q = j
    x[q] *= 0
    p[i] = q+1
for i in range(d):
    print(p[i])

Measured memory_bytes: 68028
import java.util.*;

public class Main {
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		int[] arr = new int[4];
		int total = 0;
		for (int i = 0; i < 4; i++) {
		    arr[i] = sc.nextInt();
		    total += arr[i];
		}
		int min = Integer.MAX_VALUE;
		for (int i = 1; i < 4; i++) {
		    min = Math.min(min, Math.abs(total - (arr[0] + arr[i]) * 2));
		}
		System.out.println(min);
	}
}



Measured memory_bytes: 26284
#include<iostream>
#include<vector>
#include<string>
#define rep(i, start, end) for (int i = (int)start; i < (int)end; ++i)
#define rrep(i, start, end) for (int i = (int)start - 1; i >= (int)end; --i)
#define all(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;
template<typename T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return 0;}
template<typename T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return 0;}

int f(int x, int y, int z) {
    return x * x + y * y + z * z + x * y + y * z + z * x;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    vector<int> ans(N, 0);
    rep(x, 1, 101) rep(y, 1, 101) rep(z, 1, 101) {
        if (f(x, y, z) <= N) {
            ++ans[f(x, y, z) - 1];
        }
    }
    rep(i, 0, N) {
        cout << ans[i] << endl;
    }
    return 0;
}

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

using namespace std;

#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

void test_case() {
	long long n;
  cin >> n;
  cout << (n*(n + 1))/2;
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int t = 1; 
	// scanf("%d", &t);
	while(t --) {
		test_case();
	}
	return 0;
}


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

const int N = (int) 1e5 + 20;

int n, k;
int a[N];

int main()
{
//    freopen("in.txt", "r", stdin);
    cin >>n >>k;
    for(int i = 1; i <= n; i++) cin >>a[i];

    int ans = 2147483647;

    for(int i = 1, j = i + k - 1; j <= n; i++, j++)
    {
        if(a[i] < 0 && a[j] < 0) ans = min(ans, -a[i]);
        else if(a[i] > 0 && a[j] > 0) ans = min(ans, a[j]);
        else
        {
            ans = min(ans, a[j] - a[i] + min(abs(a[i]), abs(a[j])));
        }
    }

    cout <<ans <<endl;

    return 0;
}


Measured memory_bytes: 640
#include <iostream>
#include <string>

int main()
{
    using namespace std;

    string str;
    cin.tie(0);
    int n, i;
    
    cin >> str >> n;
    
    for (i = 0; i < n; ++i) {
        int a, b;
        string order, temp;
        cin >> order >> a >> b;
        
        if (order == "print") {
                cout << str.substr(a, b - a + 1) << endl;
        } else if (order == "reverse") {
            temp = str.substr(a, b - a + 1);
            for (int j = 0; j < b - a + 1; ++j) {
                str[b - j] = temp[j];
            }
        } else {
            cin >> temp;
            str.replace(a , b - a + 1, temp);
        }
    }

    return 0;
}

Measured memory_bytes: 1220
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
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; }
//---------------------------------------------------------------------------------------------------
/*---------------------------------------------------------------------------------------------------
　　　　　　　　　　　 ∧＿∧  
　　　　　 ∧＿∧ 　（´<_｀ ）　 Welcome to My Coding Space!
　　　　 （ ´_ゝ`）　/　 ⌒i     
　　　　／　　　＼　 　  |　|     
　　　 /　　 /￣￣￣￣/　　|  
　 ＿_(__ﾆつ/　    ＿/ .| .|＿＿＿＿  
　 　　　＼/＿＿＿＿/　（u　⊃  
---------------------------------------------------------------------------------------------------*/





int N, A[101];
//---------------------------------------------------------------------------------------------------
void _main() {
    cin >> N;
    rep(i, 0, N) cin >> A[i];
    sort(A, A + N, greater<int>());

    int v[2] = {0, 0};
    rep(i, 0, N) v[i % 2] += A[i];

    int ans = v[0] - v[1];
    cout << ans << endl;
}

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

struct Card{char suit,value;};

void bubble(struct Card A[],int N){
  for (int i = 0; i < N; i++) {
    for (int j = N-1; j >=i+1; j--) {
      if(A[j].value<A[j-1].value){
        Card t=A[j]; A[j]=A[j-1]; A[j-1]=t;
      }
    }
  }
}

void selection(struct Card A[],int N){
  for (int i = 0; i < N; i++) {
    int minj=i;
    for(int j=i;j<N;j++){
      if(A[j].value<A[minj].value) minj =j;
    }
      Card t=A[i]; A[i]=A[minj]; A[minj]=t;
  }
}

void print(struct Card A[],int N){
    for (int i = 0; i < N; i++){
      if(i>0) cout <<" ";
      cout <<A[i].suit<<A[i].value;
    }
    cout <<endl;
}

bool isStable(struct Card C1[],struct Card C2[],int N){
    for (int i = 0; i < N; i++){
      if(C1[i].suit!=C2[i].suit) return false;
    }
    return true;
}

int main(){
  Card C1[100],C2[100];
  int N;
  char ch;

  cin >>N;
  for (int i = 0; i < N; i++){
    cin >> C1[i].suit>>C1[i].value;
  }

    for (int i = 0; i < N; i++) C2[i] = C1[i];

    bubble(C1,N);
    selection(C2,N);

    print(C1,N);
    cout << "Stable" <<endl;
    print(C2,N);
    if(isStable(C1,C2,N)){
      cout<<"Stable"<<endl;
    }else{
      cout<<"Not stable"<<endl;
    }

    return 0;
}



Measured memory_bytes: 3092
#include <bits/stdc++.h>
using namespace std;
#define int long long
signed main() {
    int N;
	cin >> N;
    vector<int>A(N);
    vector<int>B(N);
    int ans = 0;
    int res = 0;
    vector<int>cnt;
	for (int i = 0; i < N; i++) {
        cin >> A[i];
    }
	for (int i = 0; i < N; i++) {
		cin >> B[i];
		if (A[i] >= B[i]) {
            cnt.push_back(A[i]-B[i]);
        }
		else { 
            res+=(B[i]-A[i]); 
            ans++; 
        }
	}
	sort(cnt.begin(), cnt.end()); 
    reverse(cnt.begin(), cnt.end());
	for (int i = 0; i < cnt.size(); i++) {
		if (res > 0) { 
            res -= cnt[i];
            ans++;
        }
	}
	if (res > 0) {
        ans = -1;
    }
	cout << ans << endl;
}


Measured memory_bytes: 2936
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxx = 1e5 + 7;
const int Inf = 1 << 30;
const ll INF = 1ll << 60;
#define mst(x) memset(x, 0, sizeof(x))
priority_queue <int> qua;
char s[33];
int a[33];

int main() {
	int ans = Inf;
	scanf("%s", s + 1);
	int ln = strlen(s + 1);
	for(int i = 1; i <= ln; i++) a[i] = s[i] - '0';
	for(int i = 1; i <= ln - 2; i++) {
		int tmp = a[i] * 100 + a[i + 1] * 10 + a[i + 2];
		int dd = abs(tmp - 753);
		ans = min(ans, dd);
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
	int d, i, multiple, sum;
	
	while (1) {
		if (scanf("%d", &d) == EOF)
			break;
		sum = 0;
		multiple = d;
		for (i = 1;;i++) {
			multiple = i * d;
			sum = sum + ((multiple * multiple) * d);
			if (multiple == (600 - d)) 
				break;
		}
		printf("%d\n", sum);
	}
	return 0;
}

Measured memory_bytes: 364
use proconio::{input, fastout};

const TYPE_COUNT: usize = 26;

#[fastout]
fn main() {
    input! {
        d: usize,
        cc: [usize; TYPE_COUNT],
        ss: [[usize; TYPE_COUNT]; d],
    }

    let mut last = vec![0; TYPE_COUNT];

    for s in ss {
        let mut max = 0;
        let mut index = 0;
        for (i, x) in s.into_iter().enumerate() {
            let x = x + cc[i] * last[i] * 10;
            if max < x {
                max = x;
                index = i;
            }
        }
        for l in last.iter_mut() {
            *l += 1;
        }
        last[index] = 0;
        println!("{}", index+1);
    }
}

Measured memory_bytes: 2348
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int K = sc.nextInt();
		int xN[] = new int[N];
		for(int i = 0;i < N;i++) {
			xN[i] = sc.nextInt();
		}
		int sum = 0;
		for(int i = 0;i < N;i++) {
			sum += Math.min(Math.abs(K-xN[i])*2,xN[i]*2);
		}
		System.out.print(sum);


	}

}

Measured memory_bytes: 22868
#include<bits/stdc++.h>
using namespace std;
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int a[3],t=0,k=0;
    for(int i=0;i<3;i++){
        cin>>a[i];
        if(a[i]==5)
         t++;
        else if(a[i]==7)
         k++;
    }
    if(t==2 && k==1)
     cout<<"YES";
     else 
      cout<<"NO";
      return 0;
}
     
   

Measured memory_bytes: 3608
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
	int N;
	cin >> N;
	vector<ll> A(N);
	for (auto& x : A) cin >> x;
	for (auto x : A) if (x == 0) {
		cout << 0 << endl;
		return 0;
	}
	ll res = 1;
	for (auto x : A) {
		if ((double)res * x >= 1.1e18) {
			cout << -1 << endl;
			return 0;
		}
		res *= x;
	}
	if (res > 1000000000000000000LL) {
		cout << -1 << endl;
		return 0;
	}
	cout << res << endl;
}


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

string tmp = "qwertasdfgzxcvb";

int main()
{
  string str;

  while (cin >> str, str[0] != '#'){
    int ct = 0;
    for (int i = 1; i < str.size(); i++){
      bool jg1, jg2;
      jg1 = jg2 = false;
      for (int j = 0; j < tmp.size(); j++){
        if (str[i] == tmp[j]) jg1 = true;
        if (str[i - 1] == tmp[j]) jg2 = true;
      }
      ct += (jg1 ^ jg2);
    }
    cout << ct << endl;
  }
  return (0);
}

Measured memory_bytes: 1188
import java.util.Scanner;

class Main{
	static public void main(String agrs[]){
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int d,r=0;

		d = a/b;
		r = a%b;
		System.out.printf("%d %d %f", d, r, (double)a/(double)b);
	}
}

Measured memory_bytes: 26356
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <map>
#include <stack>
#include <utility>
#include <cmath>
#include <cstdio>
#include <functional>

using namespace std;
typedef long long LL;
typedef pair<LL, LL> PII;
LL MOD = 1000000007;

template <typename T>
class SegmentTree {
  int N;
  vector<T> dat;
  function< T (T, T)> oper;
  T identity ;
public:
  SegmentTree(int n, function<T(T, T)> op, T id) {
    oper = op;
    identity = id;
    N = 1;
    while(N < n) N *= 2;
    dat.resize(2*N, identity);
   }
  // update k th element
  void update(int k, T a) {
    k += N-1; // leaf
    dat[k] = a;
    while(k > 0) {
      k = (k - 1) / 2;
      dat[k] = oper(dat[k*2+1], dat[k*2+2]);
    }
  }
  // query[a, b)
  T query(int a, int b) { return query(a, b, 0, 0, N); }
  T query(int a, int b, int k, int l, int r) {
    if(r <= a or b <= l) return identity;
    if(a <= l and r <= b) return dat[k];
    int m = (l + r) / 2;
    return oper(query(a, b, k*2+1, l, m), query(a, b, k*2+2, m, r));
  }
};
 



//
int main() {
    int N;
    cin >> N;
    vector<int> H(N, 0), A(N, 0);
    for(int i=0; i<N; i++) cin >> H[i];
    for(int i=0; i<N; i++) cin >> A[i];
    function<LL(LL, LL)> oper = [] (LL a, LL b) -> LL {
        return max(a, b);
    };
    LL id = 0;
    SegmentTree<LL> seg(N+10, oper, id);

    for(int i=0; i<N; i++) {
        LL ans = seg.query(0, H[i]);
        seg.update(H[i], ans + A[i]);
    }

    //seg.update();
    cout << seg.query(0, N+1) << endl;
    return 0;
}

Measured memory_bytes: 5888
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        //コード
    	Scanner sc = new Scanner(System.in);
//    	File file = new File("src/in.txt");
//    	Scanner sc = new Scanner(file);
    	int A = sc.nextInt();
    	int B = sc.nextInt();
    	int C = sc.nextInt();
    	int K = sc.nextInt();

    	int a = 0;
    	int b = 0;
    	int c = 0;

    	if(K<=A) {
    		a = K;
    	} else {
    		a = A;
    		if(K-A<=B) {
    			b = K-A;
    		} else {
    			b = B;
    		}
    	}
    	c = K-a-b;
    	int sum = a - c;
    	System.out.println(sum);
    }
}

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

public class Main {
	
	public long GCD(long x, long y){
		long max = Math.max(x, y);
		long min = Math.min(x, y);
		if( min == 0 ){
			return max;
		}
		return GCD(max%min, min);
	}
	public long LCM(long x, long y){
		long g = GCD(x, y);
		return x*y/g;
	}
	public long counter(int x, int y){
		long key = x;
		long count = 1;
		while( key != 1 ){
			key = (key*x)%y;
			count++;
		}
		return count;
	}
	public void solve() throws IOException{
		int a1, a2, a3, m1, m2, m3;
		while( (a1 = nextInt()) != 0 | (m1 = nextInt()) != 0 | (a2 = nextInt()) != 0 
				| (m2 = nextInt()) != 0 | (a3 = nextInt()) != 0 | (m3 = nextInt()) != 0 ){
			long x = counter(a1, m1);
			long y = counter(a2, m2);
			long z = counter(a3, m3);
			long ans = LCM(LCM(x, y), z);
			System.out.println(ans);
		}
	}
	
	public static void main (String args[]) throws IOException{
		new Main().run();
	}
	
	BufferedReader reader;
	StringTokenizer tokenizer;
	PrintWriter writer;
	
	public void run() throws IOException{
		try{
			reader = new BufferedReader(new InputStreamReader(System.in));
			tokenizer = null;
			writer = new PrintWriter(System.out);
			solve();
			reader.close();
			writer.close();
		} catch (Exception e){
			e.printStackTrace();
			System.exit(1);
		}
	}
	
	public int nextInt() throws IOException{
		return Integer.parseInt(nextToken());
	}
	
	public String nextToken() throws IOException{
		while( tokenizer == null || !tokenizer.hasMoreTokens() ){
			tokenizer = new StringTokenizer(reader.readLine());
		}
		return tokenizer.nextToken();
	}
}

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

const double PI = acos(-1);

int main() {
  int a, b, h, m; cin >> a >> b >> h >> m;
  double h_rad = double (60 * h + m) / 720 * 2 * PI;
  double m_rad = double (m) / 60 * 2 * PI;

  double d_rad = abs(h_rad - m_rad);
  
  double ans = sqrt(a * a + b * b - 2 * a * b * cos(d_rad));
  
  printf("%.10f\n", ans);
  
  return 0;
}

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

int n, k;
vector<int> x;

int main()
{
	cin >> n >> k;
	x.resize(n);
	for( int i = 0; i < n; i++ ) {
		cin >> x[i];
	}

	int ans = INT32_MAX;
	for( int l = 0; l < n - k + 1; l++ ) {
		int r = l + k -1;
		ans = min( ans, abs(x[l]) + abs(x[r] - x[l]) );
		ans = min( ans, abs(x[r]) + abs(x[r] - x[l]) );
	}

	cout << ans << endl;

	return 0;
}


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

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

int N;
string S;
int Q,K;
int SM[2010101];
ll BTC[2010101];
ll BTC2[2010101];


void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N;
	cin>>S;
	FOR(i,N) {
		SM[i+1]=SM[i]+(S[i]=='M');
		BTC[i+1]=BTC[i];
		BTC2[i+1]=BTC2[i];
		if(S[i]=='C') {
			BTC[i+1]++;
			BTC2[i+1]+=SM[i+1];
		}
	}
	for(i=N+1;i<=2000000;i++) {
		SM[i]=SM[i-1];
		BTC[i]=BTC[i-1];
		BTC2[i]=BTC2[i-1];
	}
	
	cin>>Q;
	while(Q--) {
		cin>>K;
		ll ret=0;
		FOR(i,N) if(S[i]=='D') {
			ll NC=BTC[i+K]-BTC[i];
			ll NC2=BTC2[i+K]-BTC2[i];
			ret+=NC2-NC*SM[i+1];
		}
		cout<<ret<<endl;
	}
	
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}


Measured memory_bytes: 40604
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<string>
#include<string.h>
#include<math.h>
#include<stdlib.h>
#include<vector>
#include<queue>
#include<map>
#include<iomanip>
#include<set>
#include<bitset>
#define rep(index,num) for(int index=0;index<num;index++)
#define rep1(index,num) for(int index=1;index<=num;index++)
#define brep(index,num) for(int index=num-1;index>=0;index--)
#define brep1(index,num) for(int index=num;index>0;index--)
#define scan(argument) cin>>argument
#define prin(argument) cout<<argument<<endl
#define kaigyo cout<<endl
#define eps 1e-7
#define mp(a1,a2) make_pair(a1,a2)
#define ALL(a) (a).begin(),(a).end()
#define rALL(a) (a).rbegin(),(a).rend()
typedef long long ll;
typedef long double ld;
using namespace std;
typedef pair<ll,ll> pll;
typedef pair<int,int> pint;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<pint> vpint;
typedef vector<pll> vpll;
ll INFl=(ll)1e+18+1;
int INF=1e+9+1;
vint adj[51];
int p[51];
bool visited[51]={};
vint edgedepth[51];
map<pint,int> edgenum;
void dfs(int u,int depth){
	visited[u]=1;
	edgedepth[depth].push_back(u);
	int flag=0;
	rep(i,adj[u].size()){
		int v=adj[u][i];
		if(visited[v]==0){
			flag=1;
			p[v]=u;
			dfs(v,depth+1);
		}
	}
}
void pathedge(int u,bool *used){
	if(p[u]!=-1){
		used[edgenum[{u,p[u]}]]^=1;
		pathedge(p[u],used);
	}
}
bitset<51> whitebit[(1<<20)];
int main(){
	int N,M;
	int u[21],v[21];
	ll ans=0;
	scan(N);
	rep(i,N-1){
		int a,b;
		scan(a>>b);
		a--; b--;
		adj[a].push_back(b);
		adj[b].push_back(a);
		edgenum[{a,b}]=i;
		edgenum[{b,a}]=i;
	}
	dfs(0,0);
	p[0]=-1;
	scan(M);
	rep(i,M){
		scan(u[i]>>v[i]);
		u[i]--;	v[i]--;
		bool used[51]={};
		pathedge(u[i],used);
		pathedge(v[i],used);
		rep(j,N){
			if(used[j]) whitebit[1<<i].set(j);
		}
	}
	int bitall=(1<<M);
	rep1(bit,bitall-1){
		rep(i,M){
			whitebit[bit|(1<<i)]=(whitebit[bit]|whitebit[(1<<i)]);
		}
	}
	ll allwhitenum=0;
	rep1(bit,bitall-1){
		//printf("bit:%d ",bit);
		//prin(whitebit[bit]);
		int parity=-1;
		rep(i,M){
			if(bit&(1<<i)) parity*=-1;
		}
		//printf("parity:%d  num:%d\n",parity,(1<<(N-1-whitebit[bit].count())));
		allwhitenum+=parity*(1LL<<(N-1-whitebit[bit].count()));
	}
	prin((1LL<<(N-1))-allwhitenum);
	return 0;
}


Measured memory_bytes: 8448
#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
#define PI 3.1415926535897932384626433
#define mod 1000000007
 
int gcd(int a, int b) { return b ? gcd(b, a%b) : a; }
 
int lcm(int a, int b) { return a * b / gcd(a, b); }
 
int main(){
    ll a, b, c;
    cin >> a >> b >> c;
    ll ans = 0;
    if((a + b + 1) >= c){
        ans += b + c;
    }else{
        ans += b + (a + b + 1);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(){
    long long int a,b,c,d;
    scanf("%lld",&a);
    scanf("%lld",&b);
    scanf("%lld",&c);
    scanf("%lld",&d);

    if(a>=0&&c>=0){
        printf("%lld",b*d);
    }
    else if(b<=0&&d<=0){
        printf("%lld",a*c);
    }
    else if(a>=0&&d<=0){
        printf("%lld",a*d);
    }
    else if(c>=0&&b<=0){
        printf("%lld",b*c);
    }
    else if(a<=0&&b>=0 && c>=0){
        printf("%lld",b*d);
    }
    else if(a<=0&&b>=0 && d<=0){
        printf("%lld",a*c);
    }
    else if(c<=0&&d>=0 && a>=0){
        printf("%lld",b*d);
    }
    else if(c<=0&&d>=0 && b<=0){
        printf("%lld",a*c);
    }
    else if(c<=0&&d>=0 && a<=0&&b>=0){
        if(a*c>=b*d)
            printf("%lld",a*c);
        else if(a*c<b*d)
            printf("%lld",b*d);
    }
    
    return 0;
}

Measured memory_bytes: 1736
N,K= map(int,input().split())
L=[]
for i in range(N):
    L.append([int(j) for j in input().split()][1:])
L=[flatten for inner in L for flatten in inner]
ans=[]
for i in set(L):
    if L.count(i)==N:
        ans.append(i)
print(len(ans))

Measured memory_bytes: 3064
#pragma optimization_level 3
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
#include<bits/stdc++.h>
#define F first
#define S second
#define vec vector
#define ms multiset
#define pb push_back
#define pll pair<ll,ll>
#define pdd pair<ld, ld>
#define pq priority_queue
#define umap unordered_map
#define uset unordered_set
#define pii pair<int, int>
#define pnn pair<Node*, Node*>
#define uid uniform_int_distribution
#define FILE ifstream in("input.txt");ofstream out("output.txt");
#define fast cin.tie(0);cout.tie(0);cin.sync_with_stdio(0);cout.sync_with_stdio(0);
using namespace std;
typedef string str;
typedef long long ll;
typedef long double ld;
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count()); //uid<int> u1(5, 10); u1(rnd);

int main() {
    fast;
    ll a; cin>>a;
    vec<ll> m(a);
    for(int q=0; q<a; q++) cin>>m[q];
    m[0]--;
    for(int q=1; q<a; q++){
        if(m[q]>m[q-1]){
            m[q]--;
            continue;
        }
        else if(m[q]==m[q-1]) continue;
        cout<<"No";
        return 0;
    }
    cout<<"Yes";
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
int main(){
    int a;
    cin >> a;
    while(a>0){
        if(a%10==7){
            cout << "Yes\n";
            return 0;
        }else{
            a = a/10;
        }
    }
    cout << "No\n";
return 0;
}


Measured memory_bytes: 3624
#include <iostream>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <iomanip> // cout<<setprecision(n)
#include <functional> // std::function<void(int)>
using namespace std;
#define All(v) (v).begin(),(v).end()
const long long mod = 1000000007;
const long long inf = mod*mod;
const double EPS=1e-10;
const double INF=1e+10;
const double PI=acos(-1.0);
signed main(){
    int n;
    cin >> n;
    vector<int> h(n);
    for (int i = 0; i < n;i++)
        cin >> h[i];
    h[0]--;
    for (int i = 1; i < n;i++){
        if(h[i]>h[i-1])
            h[i]--;
    }
    bool flag = true;
    for (int i = 1; i < n;i++){
        if(h[i]<h[i-1]){
            flag = false;
        }
    }
    if(flag)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
}

Measured memory_bytes: 640
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<utility>
#include<cmath>
#include<climits>
#include<queue>
#include<stack>
#include<numeric>
#include<set>
#include<iomanip>
using namespace std;


typedef long long ll;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)



int main(){
  ll l, r;
  ll ans = LLONG_MAX;
  cin >> l >> r;
  for(ll i = l; i <= (l + 1000) && l <= r; ++i){
    for(ll j = i + 1; j <= (l + 1000) && j <= r; ++j){
      ans = min(ans, (i * j) % 2019);
    }
  }

  cout << ans << endl;

}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
LL ans=0,n,k;
int main()
{
	scanf("%lld %lld",&n,&k);
	if (n<k/2) ans=0; 
	else 
	if (k&1) ans=(LL)(n/k)*(n/k)*(n/k);
	else ans=(LL)(n/k)*(n/k)*(n/k)+(LL)((n-k/2)/k+1)*((n-k/2)/k+1)*((n-k/2)/k+1);
	printf("%lld",ans);
	return 0;
}

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

using namespace std;

const int MAXN = 100000 + 10;
const int INF = (int)(1e9);

int n, c, k;
int t[MAXN];

void run() {
    cin >> n >> c >> k;
    for(int i = 0; i < n; ++i) cin >> t[i];

    sort(t, t + n);
    int i = 0, res = 0;
    while (i < n) {
        ++res;
        int s = 0, e = t[i] + k;
        while ((s < c) && (i < n) && (t[i] <= e)) {
            ++s; ++i;
        }
    }
    cout << res << endl;
}

int main()
{
    //freopen("input.txt", "r", stdin);

    int ntests = 1;
    //cin >> ntests;
    for(int tc = 1; tc <= ntests; ++tc) {
        run();
    }
}



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

int main()
{
    int x,y;
    cin>>x>>y;
    if(y<=4*x && y>=2*x && y%2==0)
    {
        cout<<"Yes";
    }
    else
    {
        cout<<"No";
    }
    return 0;
}



Measured memory_bytes: 3592
# include "bits/stdc++.h"
using namespace std;
using LL = long long;
using ULL = unsigned long long;
const double PI = acos(-1);
template<class T>constexpr T INF() { return ::std::numeric_limits<T>::max(); }
template<class T>constexpr T HINF() { return INF<T>() / 2; }
template <typename T_char>T_char TL(T_char cX) { return tolower(cX); };
template <typename T_char>T_char TU(T_char cX) { return toupper(cX); };
typedef pair<LL, LL> pii;
const int vy[] = { -1, -1, -1, 0, 1, 1, 1, 0 }, vx[] = { -1, 0, 1, 1, 1, 0, -1, -1 };
const int dx[4] = { 0,1,0,-1 }, dy[4] = { 1,0,-1,0 };
int popcnt(unsigned long long n) { int cnt = 0; for (int i = 0; i < 64; i++)if ((n >> i) & 1)cnt++; return cnt; }
int d_sum(LL n) { int ret = 0; while (n > 0) { ret += n % 10; n /= 10; }return ret; }
int d_cnt(LL n) { int ret = 0; while (n > 0) { ret++; n /= 10; }return ret; }
LL gcd(LL a, LL 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; };
# define ALL(qpqpq)           (qpqpq).begin(),(qpqpq).end()
# define UNIQUE(wpwpw)        sort(ALL((wpwpw)));(wpwpw).erase(unique(ALL((wpwpw))),(wpwpw).end())
# define LOWER(epepe)         transform(ALL((epepe)),(epepe).begin(),TL<char>)
# define UPPER(rprpr)         transform(ALL((rprpr)),(rprpr).begin(),TU<char>)
# define FOR(i,tptpt,ypypy)   for(LL i=(tptpt);i<(ypypy);i++)
# define REP(i,upupu)         FOR(i,0,upupu)
# define INIT                 std::ios::sync_with_stdio(false);std::cin.tie(0)
# pragma warning(disable:4996)


constexpr int MAX_V = 101010;
int V, E;
vector<int> G[MAX_V];  //グラフの隣接リスト表現
vector<int> rG[MAX_V]; //辺の向きを逆にしたグラフ
vector<int> vs;        //帰りがけ順の並び
bool used[MAX_V];      //すでに調べたか
int cmp[MAX_V];        //属する強連結成分のトポロジカル順序

void add_edge(int from, int to) {
	G[from].push_back(to);
	rG[to].push_back(from);
}

void dfs(int v) {
	used[v] = true;
	for (int i = 0; i < G[v].size(); i++) {
		if (!used[G[v][i]])dfs(G[v][i]);
	}
	vs.push_back(v);
}

void rdfs(int v, int k) {
	used[v] = true;
	cmp[v] = k;
	for (int i = 0; i < rG[v].size(); i++) {
		if (!used[rG[v][i]])rdfs(rG[v][i], k);
	}
}

int scc() {
	memset(used, 0, sizeof(used));
	vs.clear();
	for (int v = 0; v < V; v++) {
		if (!used[v])dfs(v);
	}
	memset(used, 0, sizeof(used));
	int k = 0;
	for (int i = vs.size() - 1; i >= 0; i--) {
		if (!used[vs[i]])rdfs(vs[i], k++);
	}
	return k;
}

int main() {
	cin >> V >> E;
	REP(i, E) {
		int s, t;
		cin >> s >> t;
		add_edge(s, t);
	}
	scc();

	int maxl = 0;
	REP(i, V)maxl = max(maxl, cmp[i]);
	cout << (maxl != V - 1 ? 1 : 0) << endl;
}


Measured memory_bytes: 8000
/*************************************************************************
    > File Name: test.cpp
    > Author: Akira 
    > Mail: qaq.febr2.qaq@gmail.com 
 ************************************************************************/

#include<bits/stdc++.h>
typedef long long LL;
typedef unsigned long long ULL;
typedef long double LD;
#define MST(a,b) memset(a,b,sizeof(a))
#define CLR(a) MST(a,0)
#define Sqr(a) ((a)*(a))
using namespace std;

#define MaxN 100001
#define MaxM MaxN*10
#define INF 0x3f3f3f3f
#define PI 3.1415926535897932384626
const int mod = 1E9+7;
const double eps = 1e-6;
#define bug cout<<88888888<<endl;
#define debug(x) cout << #x" = " << x << endl;
int N,M;
struct Node
{
    LL x,y;
}stu[55],che[55];
int main()
{
    //std::ios::sync_with_stdio(false);
    scanf("%d%d", &N, &M);
    for(int i=1;i<=N;i++) 
    {
        scanf("%lld%lld", &stu[i].x, &stu[i].y);
    }
    for(int i=1;i<=M;i++) 
    {
        scanf("%lld%lld", &che[i].x, &che[i].y);
    }
    for(int i=1;i<=N;i++)
    {
        LL dis = INF;
        int index;
        for(int j=1;j<=M;j++)
        {
            int cnt = abs(stu[i].x-che[j].x)+abs(stu[i].y-che[j].y);
            if( cnt  < dis )
            {
                dis = cnt;
                index = j;
            }
        }
        printf("%d\n", index);
    }
    //system("pause");
}


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

int cal(int k,int r){
	int ans=1;
	while(ans<=k) ans*=r;
	return ans/r;
}

int main(){
  int i,j,N;
  cin>>N;
  int dp[100001];
  for(i=0;i<6;i++) dp[i]=i;
  dp[6]=1;
  dp[7]=2;
  dp[8]=3;
  dp[9]=1;
  for(i=10;i<=N;i++){
	dp[i]=min(dp[i-cal(i,6)],dp[i-cal(i,9)])+1;
  }
  cout<<dp[N]<<endl;
  return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
// ==================================================
using i64 = int64_t;
using u64 = uint64_t;
#define rep(i,a,b) for(i64 i=(int64_t)(a);i<(int64_t)(b);i++)
#define repn(i,n) rep(i,0,n)
#define din(t, ...) t __VA_ARGS__;_din(__VA_ARGS__)
#define v(t,n) vector<t> n
void _din() {}
void dout() { cout << endl; }
template <typename T, typename ... Args> inline void _din(T& head, Args& ... rest) { cin >> head; _din(rest...); }
template <typename T, typename ... Args> inline void dout(T head, Args ... rest) { cout << head; if (sizeof...(rest)) cout << ' '; dout(rest...); }
template <typename T>inline void qsortv(vector<T>& v) { qsort(v.data(), v.size(), sizeof(T), [](const void*a, const void*b)->int {if ((*(T*)a) < (*(T*)b))return -1; if ((*(T*)a) == (*(T*)b))return 0; return 1; }); }
template <typename T, typename F>inline void qsortv(vector<T>& v, F func) { qsort(v.data(), v.size(), sizeof(T), func); }
template <typename T>inline void sortv(vector<T>& v) { sort(v.begin(), v.end()); }
// ==================================================

int main()
{
	din(int, n);
	set<string> s;
	bool found = false;
	string last;
	repn(i, n)
	{
		din(string, str);
		if (s.find(str) != s.end())
		{
			found = true;
			break;
		}
		if (last != ""&&str[0] != last[last.size() - 1])
		{
			found = true;
			break;
		}
		s.insert(str);
		last = str;
	}
	if (found) dout("No");
	else dout("Yes");
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n) ;i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define sz(x) ((int)(x).size())
using ll=long long;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define MOD  1000000007
const ll INF=1e18;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b){ a = b; return 1; } return 0; }



int main(int argc, char const *argv[]) {
  int n;
  ll ans=INF;
  cin >> n;
  vector<int> x(n);
  rep(i,n) cin >> x[i];
  sort(all(x));

  for(int i=1; i<=100; i++){
    ll tmp=0;
    int p=i;
    rep(j,n){
      tmp+=(x[j]-p)*(x[j]-p);
    }
    chmin(ans,tmp);
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256