akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <utility>
#include <vector>
using namespace std;
#define mp make_pair
#define pb push_back
#define FI first
#define SE second
#define FOR(i,a,b) for(int (i)=((int)a); (i)<=((int)b); (i)++)
#define REP(i,N) FOR((i), 0, ((int)N)-1)
#define INF (1 << 30)
#define all(x) (x).begin(),(x).end()
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector< vector<int> > vvi;
int gcd(int a, int b){if(a>b) swap(a,b); return a==0 ? b : gcd(b%a,a);}

int N,A,B,C;

int dfs(vi l,int cur,int a,int b,int c){
    if(cur == N)
    return min(min(a,b),c) > 0 ? abs(a-A)+abs(b-B)+abs(c-C)-30 : INF;
    int ret0 = dfs(l,cur+1,a,b,c);
    int ret1 = dfs(l,cur+1,a+l[cur],b,c)+10;
    int ret2 = dfs(l,cur+1,a,b+l[cur],c)+10;
    int ret3 = dfs(l,cur+1,a,b,c+l[cur])+10;
    return min(min(ret0,ret1),min(ret2,ret3));
}

int main(){
    cin >> N >> A >> B >> C;
    vi l(N);
    REP(i,N) cin >> l[i];
    cout << dfs(l,0,0,0,0) << endl;
    return 0;
}

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

#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
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; }
typedef long long ll;

const long long INF = 1LL << 60;

int main()
{
    int D, N, st = 1;
    cin >> D >> N;

    rep(i, D) st *= 100;
    int ans = st * N;
    if (N == 100) ans += st; 
    cout << ans << endl;
    return 0;
}


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

int fr[100001];

int main(){
	int n, m;
	scanf("%d%d", &n, &m);
	f(i, 0, m){
		int a, b;
		scanf("%d%d", &a, &b);
		++fr[a];
		++fr[b];
	}
	f(i, 1, n + 1)if (fr[i] & 1)printf("NO\n"), exit(0);
	printf("YES\n");
}

Measured memory_bytes: 640
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>
#include<complex>
#include<numeric>
#include<array>
using namespace std;

//#define int long long
typedef long long ll;

typedef unsigned long long ul;
typedef unsigned int ui;
constexpr ll mod = 1000000007;
const ll INF = mod * mod;
typedef pair<int, int>P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
#define all(v) (v).begin(),(v).end()
typedef pair<ll, ll> LP;
typedef long double ld;
typedef pair<ld, ld> LDP;
const ld eps = 1e-12;
const ld pi = acosl(-1.0);

ll mod_pow(ll x, ll n, ll m=mod) {
	ll res = 1;
	while (n) {
		if (n & 1)res = res * x % m;
		x = x * x % m; n >>= 1;
	}
	return res;
}
struct modint {
	ll n;
	modint() :n(0) { ; }
	modint(ll m) :n(m) {
		if (n >= mod)n %= mod;
		else if (n < 0)n = (n % mod + mod) % mod;
	}
	operator int() { return n; }
};
bool operator==(modint a, modint b) { return a.n == b.n; }
modint operator+=(modint& a, modint b) { a.n += b.n; if (a.n >= mod)a.n -= mod; return a; }
modint operator-=(modint& a, modint b) { a.n -= b.n; if (a.n < 0)a.n += mod; return a; }
modint operator*=(modint& a, modint b) { a.n = ((ll)a.n * b.n) % mod; return a; }
modint operator+(modint a, modint b) { return a += b; }
modint operator-(modint a, modint b) { return a -= b; }
modint operator*(modint a, modint b) { return a *= b; }
modint operator^(modint a, ll n) {
	if (n == 0)return modint(1);
	modint res = (a * a) ^ (n / 2);
	if (n % 2)res = res * a;
	return res;
}

ll inv(ll a, ll p) {
	return (a == 1 ? 1 : (1 - p * inv(p % a, a)) / a + p);
}
modint operator/(modint a, modint b) { return a * modint(inv(b, mod)); }

const int max_n = 1 << 19;
modint fact[max_n], factinv[max_n];
void init_f() {
	fact[0] = modint(1);
	for (int i = 0; i < max_n - 1; i++) {
		fact[i + 1] = fact[i] * modint(i + 1);
	}
	factinv[max_n - 1] = modint(1) / fact[max_n - 1];
	for (int i = max_n - 2; i >= 0; i--) {
		factinv[i] = factinv[i + 1] * modint(i + 1);
	}
}
modint comb(int a, int b) {
	if (a < 0 || b < 0 || a < b)return 0;
	return fact[a] * factinv[b] * factinv[a - b];
}



void solve() {
	modint ans = 0;
	int n; cin >> n;
	vector<ll> a(n);
	rep(i, n) {
		cin >> a[i]; ans += a[i];
	}
	ans *= ans;
	rep(i, n) {
		ans -= a[i] * a[i];
	}
	ans *= (mod + 1) / 2;
	cout << ans << "\n";
}

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	//cout << fixed << setprecision(15);
	init_f(); 
	//init();
	//expr();
	//int t; cin >> t; rep(i, t)
	solve();
	return 0;
}


Measured memory_bytes: 12932
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); i ++)
using namespace std;
typedef long long ll;
typedef pair<ll,ll> PL;
typedef pair<int,int> P;
const ll INF = 1e12;
const ll MOD = 1e9 + 7;

vector<ll> dijkstra(int n, vector<vector<PL>>& G,int& s) {
    vector<ll> dist(n,INF);
    dist[s] = 0;

    priority_queue<PL,vector<PL>,greater<P>> q;
    q.push({0,s});

    while (!q.empty()) {
        PL p = q.top(); q.pop();
        ll d = p.first;
        int v = p.second;
        if (dist[v] < d) continue;
        for (PL p: G[v]) {
            int e = p.first;
            ll cost = p.second;
            if (dist[e] > dist[v] + cost) {
                dist[e] = dist[v] + cost;
                q.push({dist[e],e});
            }
        }  
    }
    return dist;
}

int main() {
    int v,e,r; scanf("%d %d %d",&v,&e,&r);
    vector<vector<PL>> G(v);
    rep(_,e) {
        int a,b,c; scanf("%d %d %d",&a,&b,&c);
        G[a].push_back({b,c});
    }

    vector<ll> dist = dijkstra(v,G,r);
    rep(i,v) {
        if (dist[i] == INF) puts("INF");
        else printf("%ld\n",dist[i]);
    }
}


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

using VI = vector<int>;
using VVI = vector<VI>;
using PII = pair<int, int>;
using LL = long long;
using VL = vector<LL>;
using VVL = vector<VL>;
using PLL = pair<LL, LL>;
using VS = vector<string>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define MT make_tuple
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))

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

#define FF first
#define SS second

template<class S, class T>
istream& operator>>(istream& is, pair<S,T>& p){
  return is >> p.FF >> p.SS;
}
template<class T>
istream& operator>>(istream& is, vector<T>& xs){
  for(auto& x: xs)
	is >> x;
  return is;
}
template<class S, class T>
ostream& operator<<(ostream& os, const pair<S,T>& p){
  return os << p.FF << " " << p.SS;
}
template<class T>
ostream& operator<<(ostream& os, const vector<T>& xs){
  for(unsigned int i=0;i<xs.size();++i)
	os << (i?" ":"") << xs[i];
  return os;
}
template<class T>
void maxi(T& x, T y){
  if(x < y) x = y;
}
template<class T>
void mini(T& x, T y){
  if(x > y) x = y;
}
void debug(istringstream&){}
template <char sep=',', class Head, class... Tail>
void debug(istringstream& iss, Head&& head, Tail&&... tail)
{
  string name;
  getline(iss, name, ',');
  cerr << sep << name << "=" << head;
  debug(iss, forward<Tail>(tail)...);
}
#define DEBUG(...) \
  do{ \
    istringstream ss(#__VA_ARGS__); \
    debug<' '>(ss, __VA_ARGS__); \
    cerr<<endl; \
  }while(0)

const double EPS = 1e-10;
const double PI  = acos(-1.0);
const LL MOD = 1e9+7;

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

  int H, W, K;
  cin >> H >> W >> K;
  --K;

  VVL dp(2, VL(W));
  int crt = 0, nxt = 1;
  dp[crt][0] = 1;

  REP(h,H){
    fill(ALL(dp[nxt]), 0);
    REP(b,1<<(W-1)){
      bool ok = true;
      for(int i=0;i<W-1;++i){
        if((b>>i&1) && (b>>(i+1)&1)) ok = false;
      }
      if(!ok) continue;

      for(int i=0;i<W;){
        if((b>>i&1)){
          (dp[nxt][i+1] += dp[crt][i]) %= MOD;
          (dp[nxt][i] += dp[crt][i+1]) %= MOD;
          i+=2;
        }
        else{
          (dp[nxt][i] += dp[crt][i]) %= MOD;
          i+=1;
        }
      }
    }
    swap(crt, nxt);
  }

  cout << dp[crt][K] << endl;

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

using namespace std;

const int N = (int) 3e5 + 5;
const int M = (int) 998244353;

typedef long long ll;

int n;
ll a[10][10];

int main() {

    cin >> n;

    for (int i = 1; i <= n; i++) {
        int x = i;
        int y = x % 10;
        while (x > 9) x /= 10;
        a[x][y]++;
    }

    long long res = 0;
    for (int i = 0; i < 10; i++)
        for (int j = 0; j < 10; j++)
            res += a[i][j] * a[j][i];

    cout << res << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>

using namespace std;

string s;

int main(){
  string check_s="abcdefghijklmnopqrstuvwxyz";
  unsigned long check_i[26];
  unsigned long dist,s1,s2;
  unsigned long s_begin,s_end;
  unsigned long result = 105;
  cin >> s;

  for(int i = 0;i<26;i++){
    dist=0;s1=0;s2=0;
    s_begin=-1;s_end=0;
    for(int j = 0;j<s.size();j++){
      if(s[j]==check_s[i]) {
	s1=s2;
	s2=j;
	if(dist<(s2-s1)) dist = s2-s1;
	s_end=j;
	if(s_begin==-1)s_begin=j;
      }
    }
    dist = dist-1;
    dist = max(dist,s_begin);
    dist = max(dist, s.size()-s_end-1);
    check_i[i]=dist;
  }

  for(int i=0;i<26;i++){
    if(check_i[i]!=-1){
      if(result>check_i[i]){
	result = check_i[i];
      }
    }
  }
  //-1なら１文字だけ存在する。
  //それ以外は両方

  if(result == 105) result =0;
  cout << result << endl;
  
  return 0;
}


Measured memory_bytes: 256
//Code is like humor. When you have to explain it, it’s bad.
#define fastio ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL)
#include <bits/stdc++.h>
#define MOD 1000000007
#define int long long
using namespace std;
#define ss second
#define ff first
int32_t main()
{
    fastio;
    int T,n,m,i,j,k,a,b,c;
    T=1;
    string str;
    while(T --> 0)
    {
        cin>>n>>str;
        vector<int> R,G;
        unordered_map<int,bool> B;
        for(i=0;i<n;i++)
        if( str[i] == 'R')
            R.emplace_back(i);
        else if( str[i] == 'G')
            G.emplace_back(i);
        else
            B[i]=true;

        m=B.size();
        int ans=R.size()*G.size()*m;
        for(auto a:R)
        for(auto b:G)
        {
            if( (a+b)%2==0 and B[(a+b)/2] )
                ans--;
            if( B[2*a-b])
                ans--;
            if( B[2*b-a])
                ans--;
        }
        cout<<ans;
    }
    return 0;
}


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

using ll = long long;
using Vi = vector<int>;
using Vl = vector<ll>;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

constexpr int I_INF = numeric_limits<int>::max();
constexpr ll L_INF = numeric_limits<ll>::max();

//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

ll dp[3010][3010];

void solve() {
    ll N, T;
    cin >> N >> T;
    vector<Pll> ds(N);
    for (ll i = 0; i < N; i++) {
        ll a, b;
        cin >> a >> b;
        ds[i] = {a, b};
    }
    sort(ds.begin(), ds.end());

    for (ll i = 0; i <= N; i++) {
        for (ll j = 0; j <= T; j++) {
            dp[i][j] = -L_INF;
        }
    }
    for (ll i = 0; i <= N; i++) {
        dp[i][0] = 0;
    }
    for (ll i = 0; i <= T; i++) {
        dp[0][i] = 0;
    }

    ll ans = 0;

    for (ll i = 0; i < N; i++) {
        auto [ai, bi] = ds[i];
        for (ll j = 0; j <= T; j++) {
            if (j - ai >= 0 && dp[i][j - ai] != -L_INF) {
                dp[i + 1][j] = max(dp[i][j], dp[i][j - ai] + bi);
            }
            else {
                dp[i + 1][j] = dp[i][j];
            }
            if (j - 1 >= 0) {
                dp[i + 1][j] = max(dp[i + 1][j], dp[i + 1][j - 1]);
            }
        }
        ans = max(ans, dp[i][T - 1] + bi);
    }

    cout << ans << "\n";
}

//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

int main() {
#ifdef FASTIO
    cin.tie(0), cout.tie(0);
    ios::sync_with_stdio(false);
#endif
#ifdef FILEINPUT
    ifstream ifs("./in_out/input.txt");
    cin.rdbuf(ifs.rdbuf());
#endif
#ifdef FILEOUTPUT
    ofstream ofs("./in_out/output.txt");
    cout.rdbuf(ofs.rdbuf());
#endif
    solve();
    cout << flush;
    return 0;
}

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

#define rep(i,m,n) for(int i=m;i<n;i++)
#define drep(i,m,n) for(int i=m;i>=n;i--)




int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i,0,n)	cin>>a[i];
  vector<int> in(n,0);
  drep(i,n-1,0){
    int cnt=0;
    for(int j=1;(i+1)*j<=n;j++){
      cnt+=(in[(i+1)*j-1]?1:0);
    }
    if(cnt%2!=a[i]){
      in[i]=1;
    }
  }
  vector<int> ans;
  rep(i,0,n){
  		if(in[i]==1)ans.push_back(i+1);
  }
  
  cout<<ans.size()<<endl;
  rep(i,0,ans.size()){
    cout<< ans[i]<<" "<<endl;
  }
}

Measured memory_bytes: 3192
n = int(input())
dp = [100000000000 for _ in range(n+1)]
dp[0] = 0
for i in range(1,n+1):
    dp[i] = min(dp[i-1]+1,dp[i])
    six = 0
    nine = 0
    while (6**six <= i):
        dp[i] = min(dp[i - 6**six] + 1,dp[i])
        six += 1
    while (9**nine <= i):
        dp[i] = min(dp[i - 9**nine] + 1,dp[i])
        nine += 1
print(dp[n])

Measured memory_bytes: 3864
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int A,B;
    cin>>A>>B;
    if (A+B>=A-B && A+B>=A*B)
        cout<<A+B<<endl;
    else
        if (A-B>=A*B)
            cout<<A-B<<endl;
        else
            cout<<A*B<<endl;
    return 0;
}

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

using namespace std;

using ll = long long;

const int MX = 507;

char b[MX][MX], c[MX][MX];

int main() {
    ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
#ifdef BZ
    freopen("input.txt", "r", stdin);
#endif
    int n, m;
    cin >> n >> m;
    for (int i = 0; i < n; i++) {
        string s;
        cin >> s;
        for (int j = 0; j < m; j++) {
            b[i][j] = s[j];
            c[i][j] = s[j];
        }
    }
    for (int i = 0; i < n; i += 2) {
        for (int j = 1; j < m - 1; j++) {
            b[i][j] = '#';
        }
    }
    for (int i = 0; i < n; i++) {
        b[i][0] = '#';
    }
    for (int i = 1; i < n; i += 2) {
        for (int j = 1; j < m - 1; j++) {
            c[i][j] = '#';
        }
    }
    for (int i = 0; i < n; i++) {
        c[i][m - 1] = '#';
    }
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            cout << b[i][j];
        }
        cout << "\n";
    }
    cout << "\n";
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            cout << c[i][j];
        }
        cout << "\n";
    }
    return 0;
}




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

int main(void) {
  ll n, x;
  cin >> n >> x;
  ll a[n], aa[n];
  rep (i, n) {
    cin >> a[i];
    aa[i] = a[i];
  }

  ll ans = 0, ans2 = 0;

  ans += max(0LL, a[0] - x) + max(0LL, a[n - 1] - x);
  ans2 = ans;
  aa[0] = a[0] = min(a[0], x);
  aa[n - 1] = a[n - 1] = min(a[n - 1], x);



  rep (i, n - 1) {
    ans += max(0LL, a[i] + a[i + 1] - x);
    a[i + 1] = min(a[i + 1], x - a[i]);
  }

  for (int i = n - 1; i >= 1; i--) {
    ans2 += max(0LL, aa[i] + aa[i - 1] - x);
    aa[i - 1] = min(aa[i - 1], x - aa[i]);
  }

  cout << min(ans, ans2) << endl;
  return 0;
}

Measured memory_bytes: 1792
n, m = map(int, input().split())
M = [[] for _ in range(n+1)]
for i in range(1, m+1):
    a, b = map(int, input().split())
    M[a].append(b)
    M[b].append(a)
#print(M)

S = []
Xold =[[1]]
while Xold:
    Xnew = []
    for x in Xold:
        for y in M[x[-1]]:
            if y not in x:
                z = x + [y]
                Xnew.append(z)
                if len(z)== n:
                    S.append(z)
    #print(Xnew)            
    Xold = Xnew.copy()
    
print(len(S))  
#print(S)
 

Measured memory_bytes: 4468
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input!{
        a:i32,
        b:i32,
    }
    let ans = std::cmp::max(a+b, std::cmp::max(a-b, a*b));
    println!("{}", ans);
}

Measured memory_bytes: 4352
#include<bits/stdc++.h>
#define ll long long
#define N 100005
#define M 1000000007
#define pii pair<ll,ll>
#define fast ios_base::sync_with_stdio(0);cin.tie(0);
using namespace std;
main()
{
    ll n,m;
    cin>>n>>m;
    ll s=0;
    for(int i=1;i<=m;i++)
    {
        ll x;
        cin>>x;
        s+=x;
    }
    if(s>n)
        cout<<-1;
    else
        cout<<n-s;

}



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

int main()
{
	int k,s;
	cin >> k >> s;
	int ans = 0;
	for(int x = 0; x <= k; x++){
		for(int y = max(0, s - x - k); y <= k; y++){
			if(s - x - y <= k && s - x - y >= 0){
				ans++;
			}else if(s - x - y < 0){
				break;
			}
		}
	}

	cout << ans << "\n";

	return 0;
}


Measured memory_bytes: 256
/**
 * The Number of Inversions
 * http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_5_D&lang=ja
 */

#include <bits/stdc++.h>
using namespace std;

long long merge(vector<int> &A, int left, int mid, int right) {
  int n1 = mid - left;
  int n2 = right - mid;

  // L[0...n1], R[0...n2] を生成
  vector <int>L(n1 + 1);
  for (int i = 0; i < n1; i++) {
    L.at(i) = A.at(left + i);
  }
  vector <int>R(n2 + 1);
  for (int i = 0; i < n2; i++) {
    R.at(i) = A.at(mid + i);
  }

  L.at(n1) = INT_MAX;
  R.at(n2) = INT_MAX;
  int i = 0;
  int j = 0;
  long long cnt = 0;
  for (int k = left; k < right; k++) {
    if (L.at(i) <= R.at(j)) {
      A.at(k) = L.at(i);
      i = i + 1;
    } else {
      A.at(k) = R.at(j);
      j = j + 1;
      // L.at(i) > R.at(j)
      // Lに含まれマージ後にR[j]よりも後に移動する要素の数
      // つまり、バブルソートにおいても反転される回数となる
      cnt += n1 - i; // = mid + j - k - 1
    }
  }
  return cnt;
}

long long mergeSort(vector<int> &A, int left, int right) {
  if (left + 1 < right) {
    int mid = (left + right) / 2;
    long long c1 = mergeSort(A, left, mid);
    long long c2 = mergeSort(A, mid, right);
    long long c3 = merge(A, left, mid, right);
    return c1 + c2 + c3;
  } else {
    return 0;
  }
}

int main(){
  // １行目に n、２行目に S を表す n 個の整数が与えられます。 
  int n;
  cin >> n;

  // 配列を受け取る
  vector<int> S(n);
  for (int i = 0; i < n; i++) {
    cin >> S.at(i);
  }

  // マージソートの実行
  long long cnt = mergeSort(S, 0, n);
  cout << cnt << endl;
}



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

signed main() {
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	int n, W;
	cin >> n >> W;
	vector<int>v(n);
	vector<int>w(n);
	for (int i = 0; i < n; i++)cin >> w[i] >> v[i];
	vector<vector<int>>dp(n, vector<int>(1e5 + 1, 1e10));
	for (int i = 0; i < n; i++)dp[i][v[i]] = w[i];
	for (int i = 1; i < n; i++) {
		for (int j = 0; j <= 1e5; j++) {
			dp[i][j] = min(dp[i][j], dp[i - 1][j]);
			if (j >= v[i])dp[i][j] = min(dp[i][j], dp[i - 1][j - v[i]] + w[i]);
		}
	}
	int ans = 0;
	for (int i = 0; i <= 1e5; i++) {
		if (dp[n - 1][i] <= W)ans = i;
	}
	cout << ans;
	return 0;
}

Measured memory_bytes: 79488
n, k = gets.split.map(&:to_i)
left = gets.split.map(&:to_i)
right = []

while !left.empty? && left[-1] > 0
    right.push(left.pop)
end

right = right.reverse()
left = left.reverse().map{|n| -n}

puts (k + 1).times.map{|count|
    if count > left.size || k - count > right.size
        300000000
    else
        l = left[count - 1]
        r = right[k - count -1]
        l = 0 if l == nil
        r = 0 if r == nil
        [l, r].min() * 2 + [l, r].max()
    end
}.min()




Measured memory_bytes: 12940
/*------------------------------------
........Bismillahir Rahmanir Rahim....
..........created by Abdul Aziz.......
------------------------------------*/
#include <iostream> 
#include <algorithm> 
#include <stdio.h> 
#include <cmath> 
#include <vector> 
#include <set> 
#include <map> 
#include <cstring> 
#include <unordered_map> 
#include <queue> 
#define   mod  998244353 
#define   ld   long double 
#define   pb   push_back 
#define   vi  vector<int> 
#define   dbg(x)  cerr << #x << " = " << x << '\n' 
#define   sz(x)  (int)x.size() 
#define   all(a) (a.begin(),a.end()) 
#define   ff   first 
#define   ss   second 
#define   pii  pair<int,int> 
#define   lcm(a,b) (a*b)/__gcd(a,b) 
using namespace std; 

int  n;
long double x[9],y[9]; 

long double fun(int i,int j){
    return  sqrt((x[i]-x[j])*(x[i]-x[j]) + (y[i]-y[j])*(y[i]-y[j])) ; 
} 

int fact(int n){
    if (n<=1) return  1 ; 
    return  n*fact(n-1) ; 
}

inline void solve(){
    cin>>n; 
    for (int  i=1 ; i<=n ; i++) cin >> x[i] >> y[i] ; 
    vector<int> v(n);
    for (int i = 1; i <= n; i++) v[i-1] = (i);
    long double  sum = 0.0 ; 
    do {
        for (int i=1;i<n;i++)
            sum += fun(v[i-1],v[i]);
    } while (next_permutation(v.begin(),v.end())); 
    cout.precision(20);
    cout << sum/fact(n) << endl;
}

signed main()
{
    int n=1; // cin>>n;
    while (n--) solve();
    return 0;
}


Measured memory_bytes: 3780
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

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

	vector<long long int> a(n);
	vector<long long int> b(n);
	vector<long long int> c(n);

	for (long long int i = 0; i < n; i++) {
		cin >> a[i];
	}

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

	for (long long int i = 0; i < n; i++) {
		cin >> b[i];
	}

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

	for (long long int i = 0; i < n; i++) {
		cin >> c[i];
	}

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

	vector<long long int> b2(n);
	for (long long int i = 0; i < n; i++) {
		vector<long long int>::iterator ite = upper_bound(c.begin(), c.end(), b[i]);
		b2[i] = c.end() - ite;
		//cout << b2[i] << endl;
	}

	for (long long int i = n - 2; i >= 0; i--) {
		b2[i] += b2[i + 1];
	}

	long long int ans = 0;

	for (long long int i = 0; i < n; i++) {
		vector<long long int>::iterator ite = upper_bound(b.begin(), b.end(), a[i]);
		long long int k = ite - b.begin();
		//cout << k << endl;
		if (k < n) {
			ans += b2[k];
		}
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 3328
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author tatsumack
 */

#include <iostream>
#include <fstream>

#include <bits/stdc++.h>

#define int long long
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define FOR(i, a, b) for (int i = (a), i##_len = (b); i <= i##_len; ++i)
#define REV(i, a, b) for (int i = (a); i >= (b); --i)
#define CLR(a, b) memset((a), (b), sizeof(a))
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define INF 1001001001001001001ll
#define fcout cout << fixed << setprecision(12)

using namespace std;

typedef pair<int, int> P;

class CForbiddenList {
public:
    void solve(std::istream& cin, std::ostream& cout) {
        int X, N;
        cin >> X >> N;
        set<int> s;
        REP(i, N) {
            int p;
            cin >> p;
            s.insert(p);
        }

        int l = X;
        int r = X;
        while (true) {
            if (s.count(l) == 0) {
                cout << l << endl;
                return;
            }
            if (s.count(r) == 0) {
                cout << r << endl;
                return;
            }
            l--, r++;
        }
    }
};


signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    std::istream& in(std::cin);
    std::ostream& out(std::cout);

    CForbiddenList solver;
    solver.solve(in, out);
    return 0;
}


Measured memory_bytes: 3664
#include <bits/stdc++.h>
using namespace std;
int main(){
  int a,s=1,f=2;
  cin>>a;
  if(a==7)
    s--;
  else if(a==5)
    f--;
  cin>>a;
  if(a==7)
    s--;
  else if(a==5)
    f--;
  cin>>a;
  if(a==7)
    s--;
  else if(a==5)
    f--;
  cout<<(s==0&&f==0?"YES":"NO");
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repp(i, a, b) for (int i = a; i <= (b); ++i)
#define repr(i, a, b) for (int i = a; i >= (b); --i)
typedef long long ll;
const int INF = 1001001001;
const ll LINF = 1001001001001001001ll;
const int MOD = 1e9 + 7;

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;
}

int main() {
  string S;
  cin >> S;
  int ans = 0;
  int cnt = 0;
  rep(i, S.size()) {
    if (S[i] == 'A' || S[i] == 'T' || S[i] == 'C' || S[i] == 'G') {
      cnt++;
    } else {
      chmax(ans, cnt);
      cnt = 0;
    }
  }
  chmax(ans, cnt);

  cout << ans << endl;
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <sstream>
#include <iomanip>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cctype>
#include <cstring>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <algorithm>
#include <iterator>
#include <bitset>
#include <ctime>
#include<complex>
#include<unordered_set>
using namespace std;

#define FOR(i,a,b) for(int i = (a); i < (b); i++)
#define RFOR(i,b,a) for(int i = (b) - 1; i >= (a); i--)
#define ITER(it, a) for(typeof(a.begin()) it = a.begin(); it != a.end(); it++)
#define FILL(a, value) memset(a, value, sizeof(a))

#define SZ(a) (int) a.size()
#define ALL(a) a.begin(),a.end()
#define PB push_back
#define MP make_pair

typedef long long LL;
typedef vector<int> VI;
typedef pair<int, int> PII;

const double PI = acos(-1.0);
const LL INF = 1000 * 1000 * 1000 + 7;
const LL LINF = INF * (LL)INF;

const int MAX = 3 * 1000 * 100 + 47;
const int MOD = 998244353;

LL F[MAX];
LL FR[MAX];
LL R[MAX];
string a, b, c, d;
string A, B, C, D;
LL P[MAX];
LL S[MAX];
LL ans = 0;

LL cc(int n, int k)
{
	if (k > n) return 0;
	
	LL res = F[n] * FR[n - k] % MOD;
	res = res * FR[k] % MOD;
	return res;
}

void solve1(string a, string c, string d, LL P[])
{
	int y = 0;
	int z = 0;
	int x = 0;
	FOR(i, 0, SZ(a)) x += a[i] == '1';

	FOR(i, 0, SZ(c))
	{
		if (c[i] == '0' && d[i] == '0')
		{
			continue;
		}

		if (c[i] == '1') y++;
		if (d[i] == '1') z++;

		if (x == 0 && y == 0 && z == 0)
		{
			P[i] = 1;
			continue;
		}

		if (x == 0)
		{
			P[i] = 0;
			continue;
		}

		P[i] = cc(x + y + z - 1, x - 1);
	}
}

void solve(string a, string b, string c, string d)
{
	solve1(a, c, d, P);
	reverse(ALL(c));
	reverse(ALL(d));
	solve1(b, c, d, S);

	reverse(ALL(c));
	reverse(ALL(d));
	reverse(S, S + SZ(c));

	S[SZ(c)] = 1;
	LL cur = 0;
	FOR(i, 0, SZ(c))
	{
		if (c[i] == '0' && d[i] == '0') continue;
		if (i)
		{
			cur = (cur + P[i - 1]) % MOD;
		}
		else
		{
			cur = (cur + 1) % MOD;
		}

		if (c[i] == '1' && d[i] == '1') cur = (cur * 2) % MOD;

		ans = (ans + cur * S[i + 1]) % MOD;
	}
}

int main()
{
	//freopen("in.txt", "r", stdin);
	//freopen("out.txt", "w", stdout);
	ios::sync_with_stdio(false); cin.tie(0);
	F[0] = FR[0] = F[1] = FR[1] = R[1] = 1;

	FOR(i, 2, MAX)
	{
		F[i] = F[i - 1] * i % MOD;
		R[i] = (MOD / i) * R[MOD % i] % MOD;
		R[i] = (MOD - R[i]) % MOD;
		FR[i] = R[i] * FR[i - 1] % MOD;
	}

	int n, m;
	cin >> n >> m >> a >> b >> c >> d;
	FOR(i, 0, SZ(a))
	{
		if (a[i] == '0' && b[i] == '0') continue;
		A += a[i];
		B += b[i];
	}

	FOR(i, 0, SZ(c))
	{
		if (c[i] == '0' && d[i] == '0') continue;
		C += c[i];
		D += d[i];
	}

	solve(A, B, C, D);
	//cout << ans << endl;
	solve(C, D, A, B);

	if (ans == 0) ans = 1;
	cout << ans << endl;
}

Measured memory_bytes: 12508
#include<iostream>
#include<algorithm>
#include<string>
#include<cstdlib>
#include<map>
#include<iomanip>
#include<sstream>
#include<vector>
#include<stack>
#include<math.h>
#include<queue>
#include<complex>
using namespace std;

long long int solve(long long int n){
	if(n==2){return 3;}
	else if(n==4||n==6||n==9||n==11){return 2;}
	else{return 1;}
}

int main() {
	long long int n=1,m,a,b,c,d,e;
	long double z,w;
	string str,str2,str3;
	char ch;
	long long int x[130]={};
	cout << fixed << setprecision(10);
	cin>>a>>b>>c;
	x[a]++;
	x[b]++;
	x[c]++;
	if(x[5]==2&&x[7]==1){
		cout<<"YES";
		
	}else{cout<<"NO";}

	cout<<endl;
} 


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
using namespace std;
const int MAXN = 2000 + 10;
int cnt[MAXN][MAXN],tmp[MAXN][MAXN];
int n;
void update(int x1, int x2, int y1, int y2) {
    while (x2 <= 0) {
        x2 += n;
        x1 += n;
    }
    while (y2 <= 0) {
        y2 += n;
        y1 += n;
    }
    if (x1 < 0) {
        update(0, x2, y1, y2);
        update(n+x1, n, y1, y2);
        return;
    }
    if (y1 < 0) {
        update(x1, x2, 0, y2);
        update(x1, x2, n+y1, n);
        return;
    }
    cnt[x1][y1]++;
    cnt[x1][y2]--;
    cnt[x2][y1]--;
    cnt[x2][y2]++;

    return;
}

int main() {
//    freopen("test.txt", "r", stdin);
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int q;
    cin >> q;
    int k;
    cin >> k;
    n = 2 * k;
    int x, y;
    char c;
    while (q--) {
        cin >> x >> y >> c;
        x = x % n;
        y = y % n;
        if (c == 'W') {
            update(-x, k - x, k - y, n - y);
            update(k - x, n - x, -y, k - y);
        } else {
            update(-x, k - x, -y, k - y);
            update(k - x, n - x, k - y, n - y);
        }

    }
    for (int i = 0; i < n; i++) {
        for (int j = 1; j < n; j++) {
            cnt[i][j] += cnt[i][j - 1];
        }
    }

    for (int j = 0; j < n; j++) {
        for (int i = 1; i < n; i++) {
            cnt[i][j] += cnt[i - 1][j];
        }
    }
    int ret = 0;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            ret = max(ret, cnt[i][j]);
        }
    }
        cout << ret << endl;
        return 0;
}

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

typedef long long ll;
typedef pair<int,int> pp;
const int INF = 1e9;
const int MOD = 1000000007;
const double pi = 3.141592653589793238;

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

void printV(vector<int> &v);
void printVV(vector<vector<int>> &vv);


int main() {
  int A, B, C, N;
  cin >> A >> B >> C >> N;

  int cnt = 0;
  for (int a = 0; a <= A; a++) {
    for (int b = 0; b <= B; b++) {
      for (int c = 0; c <= C; c++) {
        int total = 500*a + 100*b + 50*c; // 合計金額
        if (total == N) cnt++; // 合計金額が X に一致したら答えをインクリメント
      }
    }
  }
  cout << cnt << endl;

  return 0;
}


// ベクターの中身を全部出力
void printV(vector<int> &v) {
  cout << "  [ ";
  for(int i = 0; i < (int)v.size(); i++) {
    cout << v.at(i) << " ";
  }
  cout << "]" << endl;
}

void printVV(vector<vector<int>> &vv) {
  cout << "{" << endl;
  for(int i = 0; i < (int)vv.size(); i++) {
    cout << "  [ ";
    for(int j = 0; j < (int)vv.at(i).size(); j++) {
      cout << vv.at(i).at(j) << " ";
    }
    cout << "]," << endl;
  }
  cout << "}" << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>

using namespace std;

int main() {
  int N, L;
  vector<string> strs(L, "");
  cin >> N >> L;
  for (int i = 0; i < N; i++) cin >> strs[i];
  sort(strs.begin(), strs.end());
  for (auto &s : strs) cout << s;
  return 0;
}


Measured memory_bytes: 512
A, B, C, X, Y = map(lambda x: int(x), raw_input().split())


"""                                                                                                                                                                   
                                                                                                                                                                      
1500 2000 1600 3 2                                                                                                                                                    
                                                                                                                                                                      
A * 3 + B * 2                         = 8500                                                                                                                          
                                                                                                                                                                      
2C + A*2 + B * 1 = 3200 + 4000 + 1600 = 8800                                                                                                                          
4C + A*1 + B * 0 = 6400 + 1500        = 7900                                                                                                                          
6C                                    = 9600                                                                                                                          
                                                                                                                                                                      
"""

acc = []

maxC = 2 * max(X,Y) + 2

for i in range(maxC):
    x=i
    if x % 2 == 0:
        Csize = x/2
        remXsize = X - Csize
        remYsize = Y - Csize
        acc.append( C * x + A * max(remXsize,0) + B * max(remYsize,0) )

#print acc                                                                                                                                                            
print min(acc)

Measured memory_bytes: 12164
#include <stdio.h>

int main(void)
{
  int a[10],i,N1,N2,N3;

  N1=0;
  N2=0;
  N3=0;
  for(i = 0;i < 10; i++){
    scanf("%d", &a[i]);
    if(a[i] > N1){
      N3=N2;
      N2=N1;
      N1=a[i];
    }
    else if(a[i] > N2){
      N3=N2;
      N2=a[i];
    }
    else if(a[i] > N3){
      N3=a[i];
    }
  }
  printf("%d\n%d\n%d\n", N1,N2,N3);
  return 0;
}

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

using namespace std;

int main (void){
  int n;
  cin >> n;
  int r = 0;
  int pre = 0;
  int cur = 0;
  for (int i = 0; i < 4; i++){
    pre = cur;
    cur = n % 10;
    n = n / 10;
    if(cur == pre) {
      r += 1;
      if(r == 3) {
        cout << "Yes" << endl;
        return 0;
    }
    } else {
      r = 1;
    }
  }

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


Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <string>
#include <math.h>
#include <stdio.h>
#include <iomanip>
#include <limits>
#include <list>
#include <queue>
#include <tuple>
#include <map>
#include <set>
#include <sstream>
using namespace std;
#define MOD (long long int)(1e9+7)
#define ll long long int
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define reps(i,n) for(int i=1; i<=(int)(n); i++)
#define REP(i,n) for(int i=n-1; i>=0; i--)
#define REPS(i,n) for(int i=n; i>0; i--)
#define FOR(i,a,b) for(int i=a; i<(int)(b); i++)
#define ALL(x) (x).begin(),(x).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define SORT(c) sort(ALL(x))
#define CLR(a) memset((a), 0 ,sizeof(a))
#define PB push_back
#define MP make_pair
#define SP << " " <<
const int INF = 1001001001;
const ll LINF = 100100100100100100;
const double EPS = 1e-10;
const double PI  = acos(-1.0);
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;

template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

__attribute__((constructor))
void initial(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);
}

signed main(){
  int h,w; cin>>h>>w;
  bool visited[h][w];
  vector<string> a(h);
  rep(i,h){
    cin>>a[i];
    rep(j,w) visited[i][j]=false;
  }
  queue<PII> q;
  q.push({0,0});

  while(!q.empty()){
    PII p = q.front(); q.pop();
    int i=p.first, j=p.second;
    visited[i][j]=true;
    bool c1=false, c2=false;
    if(i-1>-1){ //上方向は未訪問のマスがあるとまずい
      if(!visited[i-1][j]&&a[i-1][j]=='#') break;
    }
    if(j-1>-1){ //左方向は未訪問のマスがあるとまずい
      if(!visited[i][j-1]&&a[i][j-1]=='#') break;
    }
    if(i==h-1&&j==w-1) return cout<<"Possible"<<endl,0;
    if(i+1<h){ //下方向
      if(a[i+1][j]=='#') q.push({i+1,j}), c1=true;
    }
    if(j+1<w){ //右方向
      if(a[i][j+1]=='#') q.push({i,j+1}), c2=true;
    }
    // if(i-1>-1){ //上方向は未訪問のマスがあるとまずい
    //   if(!visited[i-1][j]&&a[i-1][j]=='#') break;
    // }
    // if(j-1>-1){ //左方向は未訪問のマスがあるとまずい
    //   if(!visited[i][j-1]&&a[i][j-1]=='#') break;
    // }
    if(c1==c2) break; //右か下どちらかのみ進むことができる
  }
  cout<<"Impossible"<<endl;

  return 0;
}


Measured memory_bytes: 256
$N=<>;
@S1=<>=~/./g;
@S2=<>=~/./g;
$S1[0]eq$S2[0]?($%=3,$T=1,$i=1):($%=6,$T=0,$i=2);
while($i<$N){
	if($T){
		$S1[$i]eq$S2[$i]?($T=1,++$i):($T=0,$i+=2);
		($%*=2)%=1e9+7;
	}else{
		$S1[$i]eq$S2[$i]?($T=1,++$i):(($%*=3)%=1e9+7,$T=0,$i+=2);
	}
}
print$%,$/


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

int n;
ll a[100000],b[100000];

int main(){
	cin>>n;
	for (int i=1;i<=n;++i){
		scanf("%lld",&a[i]); a[i]*=2;
	}
	ll a1=0;
	for (int i=2;i<=n;i+=2){
		a1+=a[i]-a[i-1];
	}
	a1=(a[n]-a1)/2;
	b[1]=a1;
	for (int i=2;i<=n;++i){
		if (i==n) b[i]=a[n]-b[1];
		else b[i]=a[i-1]-b[i-1];
	}
	for (int i=1;i<=n;++i) printf("%lld ",b[i]);
	return 0;
}

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

using namespace std;

int main()
{
	int n,a[200004],i,k,j;
	scanf("%d%d",&n,&k);
	for(i=1;i<=n;i++)
		scanf("%d",&a[i]);
	int dp[100002];
	for(i=1;i<=n;i++)
		dp[i]=1000000000;
	dp[1]=0;

	for(i=2;i<=n;i++)
	{
		for(j=i-1;j>=max(1,i-k);j--)
			dp[i]=min(dp[j]+abs(a[i]-a[j]),dp[i]);
	}
	printf("%d\n",dp[n] );
	return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <cstring>
#include <climits>
#include <functional>
#include <queue>
#include <cmath>
#include <utility>

using namespace std;

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

int N, A, B;
vector<int> h;

bool check(int m)
{
	vector<int> v = h;

	int counter = 0;

	rep(i, N) {
		v[i] -= B * m;
		if (v[i] <= 0) continue;
		counter += (v[i] + A - B - 1) / (A - B);
		//printf("v[%lld] = %lld, counter += %lld\n", i, v[i], (v[i] + v[i] - 1) / (A - B));
	}
	rep(i, N) {
		//printf("v[%lld] = %lld\n", i, v[i]);
	}

	return counter <= m;
}

signed main()
{
	cin >> N >> A >> B;
	h.resize(N);
	rep(i, N) cin >> h[i];

	sort(begin(h), end(h), greater<int>());

	int l = 0, r = 1000000000;
	while (r - l > 1) {
		int m = (r + l) / 2;

		if (check(m)) {
			r = m;
		} else {
			l = m;
		}

		//printf("[l,r]=[%lld,%lld]\n",l,r);
	}

	cout << r << endl;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = 1LL << 60;

int main() {
    string s, t;
    cin >> s >> t;
    int lens = s.size(), lent = t.size();
    int same_max = 0, same = 0;
    for (int i = 0; i < lens - lent + 1; i++) {
        for (int j = 0; j < lent; j++) {
            if (s[i + j] == t[j]) {
                same++;
            }
        }
        same_max = max(same_max, same);
        same = 0;
    }
    cout << lent - same_max << endl;
    return 0;
}

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

int main() {
	int s; cin >> s;
	int a = s / 100;
	int b = s % 100;

	if (1 <= a && a <= 12) {
		if (1 <= b && b <= 12) cout << "AMBIGUOUS" << endl;
		else cout << "MMYY" << endl;
	}
	else {
		if (1 <= b && b <= 12) cout << "YYMM" << endl;
		else cout << "NA" << endl;
	}

	return 0;
}

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

int data[100100];

int main(void)
{
	int n, L;
	cin >> n >> L;
	
	for (int i = 0; i < n; i++){
		cin >> data[i];
	}
	
	if (n == 1) {
		cout << L - data[0] << endl;
		return 0;
	}
	
	vector <int> a;
	bool flag = ((data[0] < data[1]) ? true : false);
	for (int i = 1; i < n; i++){
		if (flag && data[i] < data[i - 1]) {
			a.push_back(i-1);
			flag = false;
		}
		if (!flag && data[i - 1] < data[i]){
			a.push_back(i-1);
			flag = true;
		}
		// cout << "*" << i-1 << " " << i << endl;
	}
	a.push_back(100550);
	int res = 0, tmp = 0, cnt = 0;
	for (int i = 0; i < n; i++){
		tmp += (L - data[i]);
		//cout << L-data[i] << " ";
		if (i == a[cnt]){
			//cout << tmp << endl;
			cnt++;
			res = max(res, tmp);
			tmp = (L - data[i]);
		}
	}
	res = max(res, tmp);
	cout << res << endl;
	
	return 0;
}

		

Measured memory_bytes: 0
s = input()
paa,goo = 0,0
res = 0

for c in s:
    if c=='g':
        if paa+1<=goo:
            res += 1
            paa += 1
        else:
            goo += 1
    else:
        if paa+1<=goo:
            paa += 1
        else:
            goo += 1
            res -= 1

print(res)


Measured memory_bytes: 3316
//15DTG
//16072020
#include<bits/stdc++.h>
using namespace std;
#define bolt ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define F first
#define S second
#define pb push_back
#define endl "\n"
#define lb lower_bound
#define ub upper_bound
typedef long long ll;
typedef long double ld;
const ld pi=3.1415926535897932384626433;
const int mod = 1e9+7;
int main()
{
   bolt;
   ll n;
   cin>>n;
   vector <ll> v;
   while (n)
   {
      ll rem=n%26;
      if (rem==0)
      {
         v.pb(26);
         n-=26;
      }
      else
      {
         v.pb(rem);
      }
      n/=26;
   }
   reverse(v.begin(),v.end());
   for (auto x: v)
   {
      cout<<char(x+'a'-1);
   }
}


Measured memory_bytes: 3632
// CODE FESTIVAL 2016 qual C
// A - CF

#include <cstdio>
#include <cstring>
#define MAX_S 100
using namespace std;


char s[MAX_S + 1];
bool is_c;

int main() {

  scanf("%s", s);
  for (int i = 0; i < (int)strlen(s); i++) {
    if (s[i] == 'C') {
      is_c = true;
    } else if(is_c && s[i] == 'F') {
      printf("Yes\n");
      return 0;
    }
  }
  printf("No\n");

  return 0;

}




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

using namespace std;

int main(){
    string s;
    cin>>s;
    if(s=="SUN")cout<<7<<endl;
    if(s=="MON")cout<<6<<endl;
    if(s=="TUE")cout<<5<<endl;
    if(s=="WED")cout<<4<<endl;
    if(s=="THU")cout<<3<<endl;
    if(s=="FRI")cout<<2<<endl;
    if(s=="SAT")cout<<1<<endl;

    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>

int main(){
    int i, j, k;
    char s[220000], t[220000];
    int ss[26][26], tt[26][26];
    int length;
    int sint, tint;
    int ans = 0;
    int stmp, ttmp;

    scanf("%s", &s);
    scanf("%s", &t);

    length = strlen(s);

    for(i=0; i<26; i++){
        for(j=0; j<26; j++){
            ss[i][j] = 0;
        }
    }

    for(i=0; i<length; i++){
        sint = (int)s[i]-97;
        tint = (int)t[i]-97;
        ss[sint][tint] = 1;
    }

    for(i=0; i<26; i++){
        stmp = 0;
        ttmp = 0;
        for(j=0; j<26; j++){
            stmp += ss[i][j];
            ttmp += ss[j][i];
        }
        if(stmp>1 || ttmp >1){
            ans = 1;
        }
        //printf("%d %d\n", stmp, ttmp);
    }

    if(ans == 0){
        printf("Yes");
    }else{
        printf("No");
    }

    return 0;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
#define to edge[i].v
#define mp make_pair
#define rint register int
#define fgx cerr<<"-------------"<<endl
#define N 1000000
using namespace std;
typedef long long ll;
typedef long double db;
typedef pair<int,int> pii;
void dbg(){cerr<<endl;}
template<typename A,typename... B>void dbg(A x,B... y){cerr<<x<<" ";dbg(y...);}
#define debug(...) cerr<<#__VA_ARGS__<<"=",dbg(__VA_ARGS__)
const int mod=1e9+7;
int a[N],f[N],g[N];
int main()
{	int n; cin>>n;
	for(rint i=1;i<=n;i++) scanf("%d",&a[i]);
	f[0]=1; int la=0;
	for(rint i=1;i<=n;i++)
	{	if(a[i]!=la) (g[a[i]]+=f[i-1])%=mod,la=a[i];
		f[i]=g[a[i]];
	}
	cout<<f[n];
	return 0;
}



Measured memory_bytes: 9216
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int maxn=200000+10;
const int INF=int(1e9);
#define ll long long
map<ll,ll>maps;
ll num[maxn];
set<ll>s;
int main(){
	int n;
	int u;
	cin>>n;
	ll sum=0;
	for(int i=1;i<=n;i++){
		scanf("%d",&u);
		sum+=u;
		maps[sum]++;
		s.insert(sum);
	}
	ll ans=0;
	for(set<ll>::iterator it=s.begin();it!=s.end();it++){
		ll v=*it;
		ll cnt=maps[v];
		//cout<<v<<" "<<cnt<<endl;
		cnt=cnt*(cnt-1)/2;
		ans+=cnt;
	}
	ans+=maps[0];
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 24192
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define pb push_back
const int maxn=2e5+10;
const int mod=998244353;



int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin>>n;
    string s;
    cin>>s;
    for(auto &v:s)
    {
        int x=v-'A';
        x+=n;
        x%=26;
        v=char('A'+x);
    }
    cout<<s<<'\n';



}


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

int main() {
  string N;
  cin >> N;
  if (N.at(2)==N.at(3) && N.at(4)==N.at(5)){
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256