akhauriyash/Code-Regression huggingface dataset:
/**
 *    Author:   ElProfesor
 *	       
**/

#include<bits/stdc++.h>

using namespace std;
 
// Competetive Template:
typedef long long int lli;
typedef unsigned long long int ulli;
typedef long double ldb;
typedef vector <lli> vl;
typedef vector <string> vs;
typedef vector < pair <long, long> > vll;

// Debugging :
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
 
#define pb push_back
#define pf push_front
#define popb pop_back
#define popf pop_front
#define ba  back
#define si size()
#define be begin()
#define en end()
#define le length()
#define mp make_pair 
#define mt make_tuple
#define fi first
#define se second
#define gcd __gcd
#define maxe *max_element
#define mine *min_element
#define deb debug
 
#define forz(i,n) for(lli i=0; i<n; i++)
#define rep(i,k,n) for (lli i = k; i < n; i++)
#define deci(n)  fixed<<setprecision(n)
#define high(n) __builtin_popcount(n)
#define parity(n) __builtin_parity(n)
#define ctz(n)  __builtin_ctz(n)
#define mod 1000000007
#define mod2 998244353
#define kira ios::sync_with_stdio(0), cin.tie(0),cout.tie(0)

// Printing Data :
#define pvec(v) forz(i,v.si) cout<<v[i]<<" "; cout<<endl;
#define parr(arr, n) forz(i,n) cout<<arr[i]<<" "; cout<<endl;
#define p1(i) cout<<i<<endl;
#define p2(i, j) cout<<i<<" "<<j<<endl;
#define p3(i, j, k) cout<<i<<" "<<j<<" "<<k<<endl;
#define p4(i, j, k, l) cout<<i<<" "<<j<<" "<<k<<" "<<l<<endl;

typedef pair <lli,lli> pll;
 
// CODE BEGINS :

int main()
{
    kira; 

    lli k, a, b; cin>>k>>a>>b;

    for(lli i=a; i<=b; i++)
    {
        if(i%k==0)
        {
            cout<<"OK"<<endl;
            return 0;
        }
    }

    cout<<"NG"<<endl;

    return 0;
}




















































Measured memory_bytes: 3652
#include <bits/stdc++.h>
using namespace std;
int main() {
	int n; cin >> n;
	long long int a[100005], b[100005];
	int minuscnt = 0;
	long long int sum = 0LL;
	for(int i=0;i<n;i++){
		cin >> a[i];
		if(a[i]<0){
			minuscnt++;
		}
		b[i] = abs(a[i]);
		sum += b[i];
	}
	if(minuscnt%2==0){
		cout << sum << endl;
		return 0;
	}
	sort(b, b+n);
	cout << sum-b[0]*2 << endl;
	return 0;
}

Measured memory_bytes: 1792
// Frog - 1

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

int main(){
    int n,k;
    cin >> n >> k;
    vector<int> v(n+1);
    vector<int> dp(n+1);
    for(int i = 0 ; i < n ; i ++ ){
        cin >> v[i];
    }
    dp[0] = 0;
    for(int i = 1 ; i < n ; i ++ ){
        dp[i] = INT_MAX;
        for(int j = 1 ; j <= k ; j++){
            if(i - j < 0) break;
            dp[i] = min(dp[i], dp[i-j] + abs(v[i] - v[i-j]));
        }
    }
    cout << dp[n-1];
    return 0;
}

Measured memory_bytes: 1024
n = int(input())
p = list(map(int, input().split()))
i = 1
cnt = 0
while i < len(p) - 1:
  l = sorted([p[i - 1], p[i], p[i + 1]])
  if l[1] == p[i]:
    cnt += 1
  i += 1
print(cnt)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(false), cin.tie(0)
#define REP(i, n) for (int i = 0; i < n; i++)
#define FOR(i, a, b) for (int i = a; i < b; i++)
#define ALL(x) (x).begin(), (x).end()
#define dump(x) cout << (x) << endl
#define LMAX 9223372036854775807LL
#define LMIN -9223372036854775807LL
typedef long long ll;
typedef vector<ll> vl;
typedef pair<ll, ll> P;

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

const ll INF = 1e18;
const ll mod = 1e9 + 7;

int main(){
	int n, m;
	cin >> n >> m;
	vector<ll> v;
	for(int i = 1; i * i <= m;i++){
		if(m % i == 0){
			v.push_back(i);
			v.push_back(m / i);
		}
	}
	sort(ALL(v));
	ll ans = 0;
	REP(i,v.size()){
		if(v[i] >= n){
			ans = m/ v[i];
			break;
		}
	}
	dump(ans);
}

Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline

n = int(input())
a = list( map(int, input().split()))

ans=0
up = 0

for i in range(n-1):
    if a[i] < a[i+1]:
        if up == -1:
            ans+=1
            up=0
        elif up==0:
            up=1
    elif a[i] > a[i+1]:
        if up == 1:
            ans+=1
            up=0
        elif up==0:
            up=-1

ans+=1
print(ans)


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

#define ll long long
#define Fi first
#define Se second
#define Pb push_back
#define vi vector<int>
#define vp vector<pair<int,int>>
#define vvi vector<vector<int>>
#define vvp vector<vector<pair<int,int>>>

const int INF = 1e9;
const int MOD = 1e9+7;

#define all(v) v.begin(),v.end()
#define output_s(a) printf("%s\n",(a).c_str())

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define Rep(i,n,m) for(int i=(int)(n);i<(int)(m);i++)
#define RepS(i,n,m) for(int i=(int)(n);i<=(int)(m);i++)
#define RRepS(i,n,m) for(int i=(int)(n);i>=(int)(m);i--)
#define RepA(x) for(auto &item:(x))

void CINT(){}
template <class Head,class... Tail>
void CINT(Head&& head,Tail&&... tail){
    cin>>head;
    CINT(move(tail)...);
}    
#define CIN(...) int __VA_ARGS__;CINT(__VA_ARGS__)
#define LCIN(...) ll __VA_ARGS__;CINT(__VA_ARGS__)
#define SCIN(...) string __VA_ARGS__;CINT(__VA_ARGS__)

template<typename TypeInt> //最大公約数
TypeInt GCD(TypeInt a,TypeInt b){
    if(a%b==0) return b;
    else return GCD(b,a%b);
}
template<typename TypeInt> //最小公倍数
TypeInt LCM(TypeInt a,TypeInt b){
    return a*b/GCD(a,b);
}

//library----------------------------------------------

int tap(int a,int b){
    if(b==0) return 1;
    if(b==1) return a;
    else return a+(a-1)*(b-1);
}

int main(){
    CIN(N);
    double ans=0.0;
    rep(i,N){
        int A;
        scanf("%d",&A);
        ans+=(double)1/A;
    }
    printf("%.10f\n",1/ans);
    return 0;
}

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

#define debug(x) cout <<"DEBUG"<<" "<< #x << ":" << x << '\n'
#define rep(i,n) for(int_fast32_t i = 0; i < ((int_fast32_t)(n)); i++)   // 0-indexed up
#define rep1(i,n) for(int_fast32_t i = 1; i <= ((int_fast32_t)(n)); i++) // 1-indexed up
#define rrep(i,n) for(int_fast32_t i = ((int_fast32_t)(n)-1); i >= 0; i--)  // 0-indexed down
#define rrep1(i,n) for(int_fast32_t i = ((int_fast32_t)(n)); i >= 1; i--)   // 1-indexed down
#define all(x) (x).begin(),(x).end()

using namespace std;

template<typename T>
using vec = vector<T>;
using i32 = int_fast32_t;
using i64 = int_fast64_t;
using u32 = uint_fast32_t;
using u64 = uint_fast64_t;
using ll = long long;
using ld = long double;
using vi = vec<int_fast32_t>;
using vl = vec<int_fast64_t>;
using vld = vec<ld>;
using vii = vec<vi>;
using PII = pair<int_fast32_t, int_fast32_t>;

template<class T>
using maxheap = std::priority_queue<T>;
template<class T>
using minheap = std::priority_queue<T, std::vector<T>, std::greater<T>>;

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

const ld Pi = std::acos(-1.0L);
constexpr ll infll = (1LL<<62)-1;
constexpr int inf = (1<<30)-1;
const int mod = 1000000007;
// const int mod = 998244353;


/*FUNCs=================================================*/


/*MAIN==================================================*/
signed main(){
    int START_TIME = clock();
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
//    cout << fixed << setprecision(15);

    i32 h, n; cin>> h >> n;
    vi a(n), b(n);
    rep(i,n) cin >> a[i] >> b[i];

    vi dp(h+1, inf);  // cost  mons_HP
    dp[h] = 0;
    for(i32 i = h; i >= 0; --i) {
        rep(j,n) {
            chmin(dp[max<i32>(0,i-a[j])], dp[i] + b[j]);
        }
    }

    cout << dp[0] << '\n';

    // printf("ExecutionTime: %d /ms\n",1000*(int)((clock()-START_TIME)/CLOCKS_PER_SEC));
}


Measured memory_bytes: 3756
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;
typedef pair<ll,ll> pll;
const ll mod=1e9+7;
//const ll mod=998244353;
const ll inf=1LL<<61;

struct query{
  ll type;//0=empty, 1=add-sum ,2=set-max
  ll value;
  query(ll a=0,ll b=0):type(a),value(b) {}
};

ll INF=(1LL<<60);

struct segtree{
  ll SIZE;
  vector<query> s;
  vector<ll> t;// sum-add
  vector<ll> u;// max-set

  segtree(ll n=1){
    SIZE=1;
    while(SIZE<n)SIZE*=2;
    s.clear();
    t.clear();
    u.clear();
    s.resize(SIZE*2, query());
    t.resize(SIZE*2, 0);
    u.resize(SIZE*2, 0);
  }
  
  void func(ll k,ll l,ll r,query q){
    if(q.type==1){
      if(s[k].type==0)s[k]=q;
      else s[k].value+=q.value;
      t[k]+=q.value*(r-l);
      u[k]+=q.value;
    }
    if(q.type==2){
      s[k]=q;
      t[k]=q.value*(r-l);
      u[k]=q.value;
    }
  }

  void compute(ll k,ll l,ll r){
    query q=s[k];
    s[k]=query();
    if(q.type==0||r-l==1)return;
    ll m=(l+r)/2;
    func(k*2+1,l,m,q);
    func(k*2+2,m,r,q);
  }

  void Update(ll a,ll b,query x,ll k,ll l,ll r){
    if(b<=l || r<=a)return;
    compute(k,l,r);
    if(a<=l && r<=b){
      func(k,l,r,x);
    }else{
      ll m=(l+r)/2;
      Update(a,b,x,k*2+1,l,m);
      Update(a,b,x,k*2+2,m,r);
      t[k]=t[k*2+1]+t[k*2+2];
      u[k]=max(u[k*2+1],u[k*2+2]);
    }
  }

  ll Dfs(ll type,ll a,ll b,ll k,ll l,ll r){
    if(b<=l || r<=a){
      if(type==1)return 0; //add
      if(type==2)return -INF; // max
    }
    compute(k,l,r);
    if(a<=l && r<=b){
      if(type==1)return t[k];
      if(type==2)return u[k];
    }else{
      ll m=(l+r)/2;
      ll lv=Dfs(type,a,b,k*2+1,l,m);
      ll rv=Dfs(type,a,b,k*2+2,m,r);
      if(type==1)return lv+rv; // add
      if(type==2)return max(lv,rv); // max
    }
  }

  void Add(ll a,ll b,ll x){
    Update(a,b,query(1,x), 0,0,SIZE);
  }
  void Set(ll a,ll b,ll x){
    Update(a,b,query(2,x), 0,0,SIZE);
  }
  ll Getsum(ll a,ll b){
    return Dfs(1,a,b, 0,0,SIZE);
  }

  ll Getmax(ll a,ll b){
    return Dfs(2,a,b, 0,0,SIZE);
  }
  
};

ll med_cnt(vec sum) {
  ll res=0;
  ll n=sum.size();
  if(n>1) {
    segtree cnt(2*n+1);
    cnt.Set(0,2*n+1,0);
    for(ll i=0;i<n;i++) {
      res+=cnt.Getsum(0,sum[i]+n+1);
      cnt.Add(sum[i]+n,sum[i]+n+1,1);
    }
  }
  return res;
}

int main() {
  ll n;
  cin >> n;
  vec a(n);
  for(ll i=0;i<n;i++) cin >> a[i];
  ll l=1,r=1e9+10;
  while(l+1<r) {
    ll m=(l+r)>>1;
    vec b(n+1);
    for(ll i=0;i<n;i++) {
      if(a[i]>=m) b[i+1]=1;
      else b[i+1]=-1;
    }
    for(ll i=0;i<n;i++) {
      b[i+1]+=b[i];
    }
    ll k=med_cnt(b);
    if(k>=((n+1)*n/2+1)/2) l=m;
    else r=m;
  }
  cout << l << endl;
}

Measured memory_bytes: 22020
/* monkukui 競技プログラミング用のテンプレート  (ここから) */
#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <functional>
#include <bitset>

using namespace std;
using lint = long long int;
using ll = long long int;
using lnt = long long int;
using Graph = vector<vector<int>>;
using Wgraph = vector<vector<pair<int, long long int>>>;
constexpr long long int INF = 1001001001001001LL;
constexpr long long int MOD = 1000000007LL;
constexpr double PI = 3.1415926535897932;
constexpr long long int di[] = {-1, 0, 1, 0, -1, 1, 1, -1};
constexpr long long int dj[] = {0, 1, 0, -1, 1, 1, -1, -1};

template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
inline void yes(){ cout << "yes" << endl; }
inline void Yes(){ cout << "Yes" << endl; }
inline void YES(){ cout << "YES" << endl; }
inline void no(){ cout << "no" << endl; }
inline void No(){ cout << "No" << endl; }
inline void NO(){ cout << "NO" << endl; }
inline void possible(){ cout << "possible" << endl; }
inline void Possible(){ cout << "Possible" << endl; }
inline void POSSIBLE(){ cout << "POSSIBLE" << endl; }
inline void impossible(){ cout << "impossible" << endl; }
inline void Impossible(){ cout << "Impossible" << endl; }
inline void IMPOSSIBLE(){ cout << "IMPOSSIBLE" << endl; }

#define REP(i,n) for(int i = 0; i < (n); i++)
#define RREP(i,n) for(int i = 1; i <= (n); i++)
#define DREP(i,n) for(int i = (n)-1; i >= 0; i--)
#define SREP(i,s,t) for(int i = s; i < t; i++)
#define ALL(a) a.begin(),a.end()
#define RALL(a) a.rbegin(),a.rend()
#define PB push_back

/* monkukui 競技プログラミング用のテンプレート (ここまで)*/

int main(){
  
  int a, b; cin >> a >> b;
  int c, d; cin >> c >> d;
  cout << (a != c) << endl;
  return 0;
}


Measured memory_bytes: 764
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ll long long int
const int INF = 2147483647;

using namespace std;

int main()
{
  int n;
  cin >> n;
  priority_queue<double, vector<double>, greater<double>> q;
  REP(i, n)
  {
    double v;
    cin >> v;
    q.push(v);
  }
  while (q.size() > 1)
  {
    double v1 = q.top();
    q.pop();
    double v2 = q.top();
    q.pop();
    q.push((v1 + v2) / 2);
  }
  cout << fixed << setprecision(6) << q.top() << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define SORT(i) sort((i).begin(), (i).end())
#define INF 2000000000
constexpr ll mod = 1e9 + 7;
 
int main(){
    int N;
    cin >> N;
    vector<vector<char>> w(N, vector<char>(2));
    unordered_map<string,int> mp;
    for (int i = 0; i < N; ++i){
        string s;
        cin >> s;
        ++mp[s];
        int a = s.size();
        w[i][0] = s.at(0);
        w[i][1] = s.at(a - 1);
    }

    bool judge = true;
     for (int i = 0; i < N; ++i){
         if(w[i][1] != w[i+1][0]){
             judge = false;
             break;
         }
         if(i == N-2){
             break;
         }
     }
     for(auto p : mp){
         auto b = p.second;
         if(b != 1){
             judge = false;
             break;
         }
     }

     if(judge){
         cout << "Yes" << "\n";
     }
     else {
         cout << "No" << "\n";
     }

    return 0;
}

Measured memory_bytes: 256
#include <string>
#include <vector>
#include <iostream>
#include <algorithm>
#include <functional>
#include <utility>
#include <map>
using namespace std;

const long long int MOD = 1000000007;


int main()
{
	int cnt0 = 0, cnt1 = 0;
	string s;

	cin >> s;

	for (int i = 0; i < (int)s.length(); i++) {
		if (s[i] == '0')
			cnt0++;
		else
			cnt1++;
	}
	
	if(cnt0 < cnt1)
		cout << cnt0 * 2 << endl;
	else
		cout << cnt1 * 2 << endl;


	return 0;

}

Measured memory_bytes: 1020
#include <iostream>
#include <string>
#include <algorithm>

#define dbg if(0)
using namespace std;
#define ll long long

int main(){
    int a,d,n;
    int ans;
    int mnum=1000000;
    bool isprime[mnum];
    for(int i=0;i<mnum;i++){
        isprime[i]=true;
    }
    isprime[0]=false;
    isprime[1]=false;
    for(int i=2;i<1000;i++){
        if (isprime[i]){
            for(int k=i+i;k<mnum;k+=i){
                isprime[k]=false;
            }
        }
    }
    while(1){
        cin >> a>> d>> n;
        if (a==d&& d==n && n==0)break;
        int cnt=0;
        int num=a;
        while(cnt<n){
            if (isprime[num]){
                cnt++;
                ans=num;
            }
            num+=d;
        }
        cout <<ans<<endl;
    }
    return 0;
}


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

using i64 = int_fast64_t;
using f64 = double;

constexpr i64 INF = INT_FAST64_MAX / 2;
constexpr f64 EPS = DBL_EPSILON;

void solve() {
    i64 n;
    cin >> n;
    map<i64, i64, greater<>> cnt;
    for (i64 i = 0; i < n; i++) {
        i64 a;
        cin >> a;
        cnt[a]++;
    }

    i64 ans = 0;
    for (auto& e : cnt) {
        i64 a, c;
        tie(a, c) = e;
        i64 b = (1l << ((i64) log2(a) + 1)) - a;
        if (a == b) {
            ans += cnt[a] / 2;
            continue;
        }
        if (cnt.find(b) == cnt.end()) continue;
        i64 p = min(cnt[b], c);
        ans += p, cnt[b] -= p;
    }

    cout << ans << endl;
}

int main() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    solve();
}


Measured memory_bytes: 12800
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.math.BigDecimal;

public class Main {
	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int n = Integer.parseInt(br.readLine());
		BigDecimal[] a = new BigDecimal[n];
		for (int i = 0; i < n; i++) {
			a[i] = new BigDecimal(br.readLine());
		}
		br.close();

		BigDecimal b = BigDecimal.valueOf(1000000000);
		int[] c2 = new int[n];
		int[] c5 = new int[n];
		for (int i = 0; i < n; i++) {
			long v = a[i].multiply(b).longValue();
			while (v % 2 == 0) {
				v /= 2;
				c2[i]++;
			}
			while (v % 5 == 0) {
				v /= 5;
				c5[i]++;
			}
		}

		int[][] sum = new int[50][50];
		for (int i = 0; i < n; i++) {
			sum[c2[i]][c5[i]]++;
		}
		for (int i = 49; i >= 0; i--) {
			for (int j = 48; j >= 0; j--) {
				sum[i][j] += sum[i][j + 1];
			}
		}
		for (int i = 48; i >= 0; i--) {
			for (int j = 49; j >= 0; j--) {
				sum[i][j] += sum[i + 1][j];
			}
		}

		long ans = 0;
		for (int i = 0; i < n; i++) {
			int m2 = Math.max(18 - c2[i], 0);
			int m5 = Math.max(18 - c5[i], 0);
			ans += sum[m2][m5];
			if (m2 <= c2[i] && m5 <= c5[i]) {
				ans--;
			}
		}
		System.out.println(ans / 2);
	}
}


Measured memory_bytes: 71464
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**6)

n=int(input())
l=[list(map(int,input().split())) for _ in range(n-1)]

nbr=[[] for _ in range(n)]
for i in range(n-1):
    nbr[l[i][0]-1].append(l[i][1]-1)
    nbr[l[i][1]-1].append(l[i][0]-1)
def sm(i,p):
    s=0
    for x in nbr[i]:
        if x!=p:s+=sm(x,i)
    return s+1
flg=False
f=0
c=[]
def dfs(i,p):
    global flg
    global c
    if i==n-1:flg=True
    if not flg:
        for x in nbr[i]:
            if x!=p:dfs(x,i)
            if flg:break
    if flg:
        c.append(i)
dfs(0,-1)
idx=(len(c)+1)//2
print('Fennec' if sm(c[::-1][idx],c[::-1][idx-1])*2<n else 'Snuke')

Measured memory_bytes: 129280
//Created by:Coding_lover(17-06-2020 09:33:33)
#include <bits/stdc++.h>
#define ll long long
#define FASTER ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define endl '\n'
#define INF LLONG_MAX
#define f first
#define s second
#define LB lower_bound
#define UB upper_bound
#define pi pair<long long,long long>
#define pii pair<long long,pi>
#define pb push_back
#define all(v) v.begin(),v.end()
#define sz(v) v.size()
#define vc vector
#define vll vector<long long>
#define rep(i, a, n) for (ll i = a; i < (long long)n; ++i)
#define repe(i, a, n) for (ll i = a; i <= (long long)n; ++i)
#define repr(i, n, a) for (ll i = n; i > (long long)a; --i)
#define repre(i, n, a) for (ll i = n; i >= (long long)a; --i)
using namespace std;
int main() {
  FASTER;
  ll t;
  t=1;
  //cin >> t;
  while (t--) {
  	ll n;
  	cin>>n;
  	vll h(n);
  	rep(i,0,n)cin>>h[i];
  	vll dp(n);
  	dp[1]=abs(h[0]-h[1]);
  	rep(i,2,n)
  	{
  		dp[i]=min(dp[i-1]+abs(h[i-1]-h[i]),dp[i-2]+abs(h[i-2]-h[i]));
  	}
  	cout<<dp[n-1]<<endl;
  }
  return 0;
}


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

namespace test
{
    class Program
    {
        static void Main(string[] args)
        {
            var input = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();
            var N = input[0];
            var x = input[1];
            var a = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).OrderBy(i => i).ToArray();
            var ans = 0;

            for (int i = 0; i < N; i++)
            {
                if (i == N - 1)
                {
                    if (a[i] == x) ans++;
                    break;
                }
                if (a[i] == x)
                {
                    ans++;
                    break;
                }
                else if (a[i] < x)
                {
                    x -= a[i];
                    ans++;
                }
                else
                {
                    break;
                }
            }

            Console.WriteLine(ans);
        }
    }
}

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

typedef long long int ll;

ll n;
ll arr[100005];


ll dp[100005];

ll solve(ll i){
	
	if(i>=n)return INT_MAX;
	
	if(i==n-1)return 0;
	
	if(dp[i]==-1){
		
		ll x = INT_MAX;
		ll y = INT_MAX;
		
		if(i+2<n){
			
			x = solve(i+2)+abs(arr[i+2]-arr[i]);
			
		}
		if(i+1<n){
			y = solve(i+1)+abs(arr[i+1]-arr[i]);
		}
		
		dp[i] = min(x,y);
		
	}
	return dp[i];
	
	
}

int main(){

	memset(dp,-1,sizeof(dp));
    cin>>n;
    
    for(ll i=0;i<n;i++)cin>>arr[i];
	
	cout<<solve(0);
	
}

Measured memory_bytes: 3328
#include <iostream>
#include <cmath>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <map>
#include <set>
using namespace std;
#define MOD (ll)1000000000000000007
#define INF 1<<30
#define LINF (ll)1<<62
#define rep(i,n) for(ll i=0; i<(n); i++)
#define REP(i,a,b) for(ll i=(a); i<(b); i++)
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll, ll> P;
typedef vector<pair<ll, ll>> vpl;
#define MAX 100005



int main(){
    ll n,m; cin >> n >> m;
    ll A,B;
    vector<P> ab;
    rep(i,n){
        cin >> A >> B;
        ab.emplace_back(B,A);
    }
    sort(ab.rbegin(), ab.rend());
    ll ans = 0;
    ll cnt = 0;
    set<ll> st;
    rep(i,m) st.insert(i+1);
    rep(i,n){
        if(cnt == m) break;
        auto itr = st.lower_bound(ab[i].second);
        if(itr != st.end()){
            st.erase(itr);
            ans += ab[i].first;
            cnt++;
        }
    }
    cout << ans << endl;
}


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

int main()
{
	int A,B,C,D;cin>>A>>B>>C>>D;
  	double area=(double)A*B/2.0;
  	if(A==C*2 && B==D*2)
      cout<<fixed<<area<<" "<<1<<endl;
  	else
      cout<<fixed<<area<<" "<<0<<endl;
	return 0;
}


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

/* 繰り返し自乗法. */
int modPow(long long a, long long n, long long p) {
	if (n == 0) return 1; // 0乗にも対応する場合.
	if (n == 1) return a % p;
	if (n % 2 == 1) return (a * modPow(a, n - 1, p)) % p;
	long long t = modPow(a, n / 2, p);
	return (t * t) % p;
}

signed main() {
    string S, T, U;
    int A, B;

    cin >> S >> T;
    cin >> A >> B;
    cin >> U;

    if (S == U) A--;
    if (T == U) B--;

    cout << A << ' ' << B << endl;

}

Measured memory_bytes: 3600
fn main() {
    let ab = read_vec::<i32>();
    let a = ab[0];
    let b = ab[1];

    let mut ma = a + b;
    if ma < a - b {
        ma = a - b;
    }
    if ma < a * b {
        ma = a * b;
    }

    println!("{}", ma);
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().split_whitespace().map(|e| e.parse().ok().unwrap()).collect()
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < n; i++)
#define FOR(i, m, n) for(ll i = m;i < n;i++)
#define VSORT(v) sort(v.begin(), v.end());
#define VREV(v) reverse(v.begin(), v.end());
using namespace std;
using ll = long long;
using pll = pair<ll,ll>;
using vll = vector<ll>;
using vdouble = vector<double>;
using vstr = vector<string>;
typedef pair<int,int> P;
int dx[4] = {1, 0, -1, 0},dy[4] = {0, 1, 0, -1};
ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}
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; }
const long long INF = 1LL << 60;
const long long MOD = 1000000007;
#include <iostream>

using namespace std;

int main() {
   string o,e;
   cin>>o>>e;
   int i=1;
  int len=o.length()+e.length();
   string::iterator it=o.begin();
   string::iterator itt=e.begin();

   for(i=1;i<=len;i++){
    if(i%2==1)
    { cout<<*it;
    ++it;
    }
     else
     {
       cout<<*itt;
       ++itt;
     }
     

   }

   return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define rer(i,l,u) for(int (i)=(int)(l);(i)<=(int)(u);++(i))
#define reu(i,l,u) for(int (i)=(int)(l);(i)<(int)(u);++(i))
static const int INF = 0x3f3f3f3f; static const long long INFL = 0x3f3f3f3f3f3f3f3fLL;
typedef vector<int> vi; typedef pair<int, int> pii; typedef vector<pair<int, int> > vpii; typedef long long ll;
template<typename T, typename U> static void amin(T &x, U y) { if (y < x) x = y; }
template<typename T, typename U> static void amax(T &x, U y) { if (x < y) x = y; }


vector<int> t_parent;
vector<int> t_ord;

void tree_getorder(const vector<vi> &g, int root) {
	int n = g.size();
	t_parent.assign(n, -1);
	t_ord.clear();

	vector<int> stk; stk.push_back(root);
	while (!stk.empty()) {
		int i = stk.back(); stk.pop_back();
		t_ord.push_back(i);
		for (int j = (int)g[i].size() - 1; j >= 0; j --) {
			int c = g[i][j];
			if (t_parent[c] == -1 && c != root) {
				t_parent[c] = i;
				stk.push_back(c);
			}
		}
	}
}

int main() {
	int N;
	while (~scanf("%d", &N)) {
		vector<vector<int> > g(N);
		for (int i = 0; i < N - 1; ++ i) {
			int u, v;
			scanf("%d%d", &u, &v), -- u, -- v;
			g[u].push_back(v);
			g[v].push_back(u);
		}
		tree_getorder(g, 0);
		int n = (int)t_ord.size();
		vector<unsigned> a(n), b(n), f(n);
		unsigned maxf = 0;
		for (int ix = n - 1; ix >= 0; -- ix) {
			int i = t_ord[ix], p = t_parent[i];
			unsigned m = b[i];
			m |= m >> 1;
			m |= m >> 2;
			m |= m >> 4;
			m |= m >> 8;
			m |= m >> 16;
			unsigned fi = ~(a[i] | m);
			fi &= ~fi + 1;
			f[i] = fi;
			if (maxf < fi)
				maxf = fi;
			unsigned S = (a[i] & ~(fi - 1)) | fi;
			if (p != -1) {
				b[p] |= a[p] & S;
				a[p] |= S;
			}
		}
		int ans = 0;
		while (maxf >> 1 >> ans) ++ ans;
		printf("%d\n", ans);
	}
	return 0;
}


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

int main(){
	for(;;){
		int H,W;
		cin>>H>>W;
		if(H==0&&W==0) break;
		for(int i=0;i<H;i++){
			for(int j=0;j<W;j++){
				if(i%2==0&&j%2==0)
					cout<<"#";
				if(i%2==0&&j%2==1)
					cout<<".";
				if(i%2==1&&j%2==0)
					cout<<".";
				if(i%2==1&&j%2==1)
					cout<<"#";
			}
			cout<<endl;
		}
		cout<<endl;
	}
	return 0;
}

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

using namespace std;

#define allof(x) (x).begin(), (x).end()

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;



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

    int x;
    cin >> x;
    if(x < 1200){
        cout << "ABC";
    } else if (x < 2800){
        cout << "ARC";
    } else {
        cout << "AGC";
    }
}


Measured memory_bytes: 256
a,b,c,x,y=gets.split.map &:to_i
mi=10**18
b=[b,2*c].min
a=[a,2*c].min
for i in 0..x
  tmp=x-i
  u=[y-tmp,0].max
  mi=[mi,a*i+b*u+2*c*tmp].min
end
puts mi


Measured memory_bytes: 1788
#include <algorithm>
#include <iostream>
#include <cstdlib>
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <string>
#include <typeinfo>
#include <random>
#include <vector>
 
using namespace std;
typedef long long ll;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef vector<string> vs;
typedef vector<vector<bool>> vvb;
typedef vector<vector<int>> vvi;
 
#define rep(i, n) for (int(i) = 0; (i) < (n); (i)++)
#define all(a) (a).begin(), (a).end()

int gcd(int a,int b){
	int r=a%b;
	if(r==0){
		return b;
	}else{
		return gcd(b,r);
	}
}
 
int main()
{
	int n;
	cin>>n;
	vi a(n);
	rep(i,n){
		cin>>a.at(i);
	}
	sort(all(a));
	int d=a.at(1);
	int ans;
	for(int i=d;i>=1;i--){
		int cnt=0;
		rep(j,n){
			if(a.at(j)%i!=0){
				cnt++;
			}
		}
		if(cnt<2){
			ans=i;
			break;
		}
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 640
import java.util.*;
     
    public class Main{
        
        public static void main(String args[])
        {
            Scanner sc = new Scanner(System.in);
            
            String word;
            String neww=new String();
            word=sc.next();
            int lenth=word.length();
            if(word.charAt(lenth-1)=='s')
            {
                neww=word+"es";
            }
            else
            {
                neww=word+"s";
            }
            System.out.println(neww);
        }
    }

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

import sys

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

N = INT()
S = input()

def bisearch_max(mn, mx, func):
    """ 条件を満たす最大値を見つける二分探索 """

    ok = mn
    ng = mx
    while ok+1 < ng:
        mid = (ok+ng) // 2
        if func(mid):
            # 上を探しに行く
            ok = mid
        else:
            # 下を探しに行く
            ng = mid
    return ok

def calc(m):
    A = {}
    for i in range(N-m+1):
        a = S[i:i+m]
        if a in A:
            # aが2回目以降に出現したindex
            j = A[a]
            # iとjがm以上離れているかどうか
            if i-j >= m:
                return True
        else:
            # aが最初に出現したindex
            A[a] = i
    return False

print(bisearch_max(0, N, calc))


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

void funcB() {
  int k;
  std::string s;
  bool over = false;
  std::cin >> k >> s;
  if (s.size() > k) over = true;
  std::cout << (over ? (s.substr(0, k) + "...") : s);
}

int main(void) {
  funcB();
  return 0;
} 

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

int main(){
	int i, j, N, sleep_time = 0;
	string song_name_sleep;
	vector<string>  song_name(50);
	vector<int> song_length(50);
	
	cin >> N;
	for(i=0;i<N;i++){
		cin >> song_name.at(i) >> song_length.at(i);
	}
	cin >> song_name_sleep;
	
	for(i=0;i<N;i++){
		if(song_name.at(i)==song_name_sleep){
			for(j=i+1;j<N;j++){
				sleep_time += song_length.at(j);
			}
		}
	}
	
	cout << sleep_time << endl;
	
	return 0;
}

Measured memory_bytes: 256
/*
	submission # - User: herp_sy
	https://atcoder.jp/contests/
*/

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <stdbool.h>

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

int main(int argc, char const *argv[])
{
	int a,b;
	char s[13];
	scanf("%d%d",&a,&b);
	scanf("%s",s);
	for (int i = 0; i < a + b + 1; ++i)
	{
		if(i == a){
			if(s[i] != '-'){
				puts("No");
				return 0;
			}
		}
		else{
			if(s[i] == '-'){
				puts("No");
				return 0;
			}
		}
	}
	puts("Yes");
	return 0;
}


Measured memory_bytes: 256
#include<iostream>

unsigned short a, b, c;
int m;
bool flag;

int main()
{
	std::cin >> m;
	for(int i = 0;i < m;++i)
	{
		std::cin >> a >> b >> c;
		if (a==0||b==0||c==0)
		{
			continue;
		}

		flag = false;
		if((a*a)+(b*b)==(c*c))
		{
			flag = true;
		}
		else if((a*a)+(c*c)==(b*b))
		{
			flag = true;
		}
		else if((b*b)+(c*c)==(a*a))
		{
			flag = true;
		}
		if(flag==false)
		{
			printf("NO\n");
		}
		else
		{
			printf("YES\n");
		}
	}
	return 0;
}

Measured memory_bytes: 0
N,K=map(int,input().split())
A=[int(i) for i in input().split()]
cnt=[0 for i in range(N)]
for a in A:
  cnt[a-1]+=1
knd=[]
for i,c in enumerate(cnt):
  if c!=0:
    knd.append((i+1,c))
knd.sort(key=lambda x: x[1],reverse=True)
ans=0
while len(knd)>K:
  j,d=knd.pop()
  ans+=d
print(ans)

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

#define int long long
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(a) (a).begin(), (a).end()
#define SZ(a) (signed)((a).size())
#define EACH(i, c) for (typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define EXIST(s, e) ((s).find(e) != (s).end())
#define SORT(c) sort((c).begin(), (c).end())

using namespace std;

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;

const int MOD = 1000000007;

#define dump(x) cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")"  << " " << __FILE__ << endl;

signed main(void) {
    ios::sync_with_stdio(false);
    cout.setf(ios::fixed, ios::floatfield);
    cout.precision(10);
    cin.tie(0);

    int a, b, c;
    cin >> a >> b >> c;

    if (b - a == c - b) {
        cout << "YES" << endl;
    } else {
        cout << "NO" << endl;
    }

    return 0;
}


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

int main()
{
    int N;
    cin >> N;
    vector<int> d(N);
    for(int i=0; i<N; i++) {
        cin >> d[i];
    }

    int recover = 0;
    for (int i=0; i<N; i++) {
        for (int j=i+1; j<N; j++) {
            recover += d[i] * d[j];
        }
    }
    cout << recover << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define all(c) (c).begin(),(c).end()
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define REP(i,m,n) for(int i=(int)(m);i<(int)(n);i++)
#define rep(i,n) REP(i,0,n)
#define iter(c) __typeof((c).begin())
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
#define mem(a) memset(a,0,sizeof(a))
#define pd(a) printf("%.10f\n",a)
#define pb(a) push_back(a)
#define in(a) insert(a)
#define pi M_PI
#define R cin>>
#define F first
#define S second
#define C class
#define ll long long
#define ln cout<<'\n'
template<C T>void pr(T a){cout<<a;ln;}
template<C T,C T2>void pr(T a,T2 b){cout<<a<<' '<<b;ln;}
template<C T,C T2,C T3>void pr(T a,T2 b,T3 c){cout<<a<<' '<<b<<' '<<c;ln;}
template<C T>void PR(T a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}ln;}
ll check(ll n,ll m,ll x,ll y){return x>=0&&x<n&&y>=0&&y<m;}
const ll MAX=1000000007,MAXL=1LL<<60,dx[4]={-1,0,1,0},dy[4]={0,1,0,-1};
typedef pair<int,int> P;

void Main() {
  int n,a,b;
  string s;
  cin >> n >> a >> b >> s;
  int x=0,y=0;
  rep(i,n) {
    if(s[i]=='a') {
      if(x<a+b) {
        pr("Yes");
        x++;
      } else pr("No");
    } else if(s[i]=='b') {
      if(x<a+b&&y<b) {
        x++;
        y++;
        pr("Yes");
      } else pr("No");
    } else pr("No");
  }
}

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


Measured memory_bytes: 848
import java.util.Arrays;
import java.util.Scanner;
 
public class Main {
	public static void main (String[] args) {
      Scanner in = new Scanner(System.in);
      int N = in.nextInt();
      int K = in.nextInt();
      int[] a = new int[N];
      for (int i = 0; i < N; i++) {
        a[i] = in.nextInt();
      }
      int[] dp = new int[N];
      dp[0] = 0;
      dp[1] = Math.abs(a[0] - a[1]);
      for(int i = 2; i< N ;i++){
        int k = 1;
        int temp = Integer.MAX_VALUE;
        while(k <= K && i-k >=0){
          temp = Math.min(temp, dp[i-k] + Math.abs(a[i] - a[i-k]));
          k++;
        }
        dp[i] = temp;
      }
      System.out.println(dp[N-1]);
	}
}


Measured memory_bytes: 50576
s=input()
t=input()
def C(a, b):
    d={}
    for i in range(len(a)):
        if a[i] in d:
            if d[a[i]]!=b[i]:
                return False
        else:
            d[a[i]]=b[i]
    return True
if C(s, t)and C(t, s):
    print('Yes')
else:
    print('No')

Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
int n, w, value[105] = {}, weight[105] = {};
long long dp[101][100002];
long long findSolution(int pos, int W)
{
    if(pos < 0 || W < 0)
    {
        return 0;
    }
    if(dp[pos][W] != 0)
    {
        return dp[pos][W];
    }
    if(weight[pos] > W)
    {
        long long x = findSolution(pos-1, W);
        //cout << "phase 1: "<<x <<" "<< pos << " " << W << endl;
        //cout << x << endl;
        return x;
    }
    else
    {
        long long x = value[pos]+findSolution(pos-1, W-weight[pos]);
        //cout << "phase 2: "<< x << " "<< pos << " " << W << endl;
        long long y = findSolution(pos-1, W);
        //cout << "phase 1: "<<y << " "<< pos << " " << W << endl;
        //cout << x << " " << y << endl;
        return dp[pos][W] = max(x, y);
    }
    //cout << pos << " " << W << endl;
}
int main()
{
    scanf("%d %d", &n, &w);
    for(int i = 0; i < n; i++)
    {
        scanf("%d %d", &weight[i], &value[i]);
    }
    long long Max = findSolution(n, w);
    printf("%lld\n", Max);
    return 0;
}


Measured memory_bytes: 70048
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; (i) < (n); ++ (i))
#define loop(i,a,n) for (int i = (a); (i) < (n); ++ (i))
#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF (int)1e9
#define MOD 0
//#define int ll
using namespace std;
typedef vector<long long> vl;

signed main() {
  ll N,m,sum=0,a;
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> N >> m;
  rep(i,m) {
    cin >> a;
    sum += a;
  }
  if(N < sum) puts("-1");
  else {
    cout << N - sum << endl;
  }

}



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


const int INF=1e9;
int main(){
    int n;
    cin>>n;
    vector<int> wp(n);
    vector<int> bp(n);
    for(int i=0;i<2*n;i++){
        char c; int a;
        cin>>c>>a;
        a--;
        if(c=='W') wp[a]=i;
        if(c=='B') bp[a]=i;
    }

    vector<vector<int>> cntB(n,vector<int>(n+1,0));
    for(int i=0;i<n;i++){
        for(int j=n-1;j>=0;j--){
            cntB[i][j]=cntB[i][j+1];
            if(bp[j]<wp[i]) cntB[i][j]++;
        }
    }
    vector<vector<int>> cntW(n,vector<int>(n+1,0));
    for(int i=0;i<n;i++){
        for(int j=n-1;j>=0;j--){
            cntW[i][j]=cntW[i][j+1];
            if(wp[j]<bp[i]) cntW[i][j]++;
        }
    }

    vector<vector<int>> dp(n+1,vector<int>(n+1,INF));
    dp[0][0]=0;
    for(int i=0;i<=n;i++){
        for(int j=0;j<=n;j++){
            if(i+1<=n){
                dp[i+1][j]=min(dp[i+1][j],dp[i][j]+cntB[i][j]);
            }
            if(j+1<=n){
                dp[i][j+1]=min(dp[i][j+1],dp[i][j]+cntW[j][i]);
            }
        }
    }
    int sc=0;

    for(int i=0;i<n;i++){
        for(int j=i+1;j<n;j++){
            if(wp[i]>wp[j]) sc++;
            if(bp[i]>bp[j]) sc++;
        }
    }    
    cout<<dp[n][n]+sc<<endl;


    return 0;
}

Measured memory_bytes: 47360
#include <bits/stdc++.h>
#define INF 2e9
#define MOD 1000000007
#define MOD9 998244353
#define intMAX 51000;
#define PI 3.14159265359
using namespace std;
typedef long long llong;
// typedef long double ldouble;

using Graph = vector<vector<int>>;

// int ctoi(const char c){
//   if('0' <= c && c <= '9') return (c-'0');
//   return -1;
// }

// int gcd(int a, int b){
//   int ma = max(a,b);
//   int mi = min(a,b);
//   if(mi == 0) return ma;

//   return gcd(mi, ma%mi);
// }

// llong POW(llong a, llong b){
//   if(b == 0) return 1;
//   else{
//     if(b%2 == 0) return POW(a * a % MOD, b / 2) % MOD;
//     else return a * POW(a * a % MOD, b / 2) % MOD;
//   }
// }

int main(){
  int X, A, B;
  cin >> X >> A >> B;
  X -= A;
  cout << X%B << endl;
}

Measured memory_bytes: 256
#include        "algorithm"
#include        "iostream"
#include        "numeric"
#include        "iomanip"
#include        "cstring"
#include        "math.h"
#include        "bitset"
#include        "string"
#include        "vector"
#include        "random"
#include        "chrono"
#include        "ctime"
#include        "queue"
#include        "stack"
#include        "map"
#include        "set"

#include        "ext/pb_ds/assoc_container.hpp" // Common file
#include        "ext/pb_ds/tree_policy.hpp" // Including tree_order_statistics_node_update
#include        "ext/pb_ds/detail/standard_policies.hpp"

using namespace std;
using namespace __gnu_pbds;


#define          f first
#define          lgn 25
#define          endl '\n'
#define          sc second
#define          pb push_back
#define          N (int)5e5+5
#define          PI acos(-1.0)
#define          int long long 
#define          vi vector<int>
#define          mod 1000000007
#define          ld long double
#define          eb emplace_back
#define          mii map<int,int>
#define          vpii vector<pii>
#define          pii pair<int,int>
#define          pq priority_queue
#define          BLOCK (int)sqrt(N)
#define          test(x) while(x--)
#define          all(x) begin(x),end(x)
#define          allr(x) x.rbegin(),x.rend()
#define          fo(i,a,n) for(int i=a;i<n;i++)
#define          rfo(i,n,a) for(int i=n;i>=a;i--)
#define          FAST ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define          time() cerr << "Time : " << (double)clock() / (double)CLOCKS_PER_SEC << "s\n"
#define          bug(...)       __f (#__VA_ARGS__, __VA_ARGS__)

typedef tree< int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update > 
OS ;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

template <typename Arg1>
void __f (const char* name, Arg1&& arg1) { cout << name << " : " << arg1 << endl; }
template <typename Arg1, typename... Args>
void __f (const char* names, Arg1&& arg1, Args&&... args)
{
     const char* comma = strchr (names + 1, ',');
     cout.write (names, comma - names) << " : " << arg1 << " | "; __f (comma + 1, args...);
}

const int inf = 0x3f3f3f3f;
const int INF = 0x3f3f3f3f3f3f3f3f;

int n,m,k,q;
string s;
vi adj[N];
int vis[N],par[N],a[N];

bool check( int mid )
{
    int cn = 0;
    fo(i,0,n)
    {
        if( a[i] < mid ) continue;
        cn += ( ( a[i] + mid - 1) / mid ) - 1;
    }

    return ( cn <= k );
}

void go()
{
    cin >> n >> k;
    int mx = 0;
    fo(i,0,n) cin >> a[i] , mx = max( mx , a[i] );

    int l = 1 , r = 1e11;
    int ans = mx;

    while( l <= r)
    {
        int mid = l + ( r - l )/2;

        if( check( mid ) )
        {
            ans = mid;
            r = mid - 1;
        }
        else l = mid + 1;
    }

    cout << ans << endl;
}

int32_t main()
{
    FAST;     
    int t=1; 
    // cin>>t;
    test(t) go();
}

 

Measured memory_bytes: 16888
#define _USE_MATH_DEFINES

#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <list>

long long int INF = 1e18;
using namespace std;

typedef pair<long long int, long long int> P;

int main(){
	
	int n;
	cin >> n;
	
	long long int fib[50] = {};
	
	fib[0] = 1;
	fib[1] = 1;
	for(int i = 2; i < 50; i++){
		fib[i] = fib[i - 1] + fib[i - 2];
	}
	
	cout << fib[n] << endl;
	
	return 0;
}


Measured memory_bytes: 3116
#include<iostream>
using namespace std;
int main(){
  int N=100001;
  bool isprime[N];
  for(int i=0;i<N;i++)
    isprime[i]=1;
  isprime[0]=isprime[1]=0;
  for(int i=0;i*i<N;i++){
    if(isprime[i]){
      for(int j=2;i*j<N;j++)
        isprime[i*j]=0;
      }
    }
  int num[100001];
  num[0]=1;
  for(int i=1;i<N;i++){
    if(isprime[i]&&isprime[(i+1)/2])
      num[i]=num[i-1]+1;
    else
      num[i]=num[i-1];
    }
  int n;
  cin>>n;
  for(int i=0;i<n;i++){
    int l,r;
    scanf("%d %d", &l, &r);
    printf("%d\n",num[r]-num[l-1]);
    }
  return 0;
  }

Measured memory_bytes: 1152
#include<bits/stdc++.h>                                                                                                                                                                                     
using namespace std;
int main()
{
  int N,M;
  cin >> N;
  int i;
  int j;
  int k;
  int max=0;
  vector<string> blue(N);
  for(i=0; i<N; i++)
    cin >> blue.at(i);
  cin >> M;
  vector<string> red(M);
  vector<int> count_blue(N);
  vector<int> count_red(M);
  for(i=0; i<M; i++)
    cin >> red.at(i);
  for(i=0; i<N; i++){
    for(j=0; j<N; j++){
      if(blue.at(i)==blue.at(j))
        count_blue.at(i)++;
    }
    for(k=0; k<M; k++){
      if(blue.at(i)==red.at(k))
        count_blue.at(i)--;
    }    
  }
  for(i=0; i<M; i++){
    for(j=0; j<N; j++){
      if(red.at(i)==blue.at(j))
        count_red.at(i)++;
    }
    for(k=0; k<M; k++){
      if(red.at(i)==red.at(k))
        count_red.at(i)--;
    }
  }
  for(i=0; i<N; i++){
    if(max<count_blue.at(i))
      max=count_blue.at(i);
  }
  for(i=0; i<M; i++){
    if(max<count_red.at(i))
      max=count_red.at(i);
  }
  cout << max << endl; 
}                                                                                                                                                                                                           
   

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define SaveTime ios_base::sync_with_stdio(false);cin.tie(NULL);
#define pb push_back 
#define eb emplace_back
#define mx *max_element
#define mi *min_element
#define fn for(int i =0 ;i <n;i++)
#define fn1 for( int i =1;i<=n;i++)
#define fm for(int j =0 ;j <m;j++)
#define fm1 for(int j =1;j<=m;j++)
#define fi first
#define se second
#define MOD 1000000007
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
const int N = 1e6+5;
const int INF = 1e18L;
int ncr(int n,int r){if(n<r)return 0;int p=1,k=1;if(n-r<r)r=n-r;if(r!=0){while(r){p*=n;k*=r;int g=__gcd(p, k);p/=g;k/=g;n--;r--;}}else p=1;return p;}
#define pi 2*acos(0.0)
int ar[N];
int tree[2*N];
int dp[N];
int bit[N];
signed main(){
 	
	SaveTime;
	int T=1;
	// cin >> T;
	while(T--){
		int n;
		cin >> n ;
		string s;
		cin >>s;
		int cnt =0;
		s+='0';
		n++;
		for(int i=1;i<n;i++){
			if(s[i]!=s[i-1]){
				cnt++;
			}
		}
		cout << cnt << endl;
	}
	
	return 0;
}


Measured memory_bytes: 512