akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;

int main(){

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

    int q;
    cin >> q;
    for(int i = 0; i < q; ++i){
        int com, b, e;
        cin >> com >> b >> e;
        int res = a[b];
        for(int j = b + 1; j < e; ++j){
            if(com == 0){
                res = min(res, a[j]);
            }
            else{
                res = max(res, a[j]);
            }
        }
        cout << res << endl;
    }

    return 0;
}


Measured memory_bytes: 3096
#pragma GCC optimize("O3")
#include<bits/stdc++.h>
#define INF 2147483647
#define LLINF 9223372036854775807
using namespace std;
int main(){
	int h,a;
	cin>>h>>a;
	if(h%a)h+=a;
	cout<<h/a<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
typedef long long ll;
inline void read(int &x){
    x=0;char ch;bool flag = false;
    while(ch=getchar(),ch<'!');if(ch == '-') ch=getchar(),flag = true;
    while(x=10*x+ch-'0',ch=getchar(),ch>'!');if(flag) x=-x;
}
#define rg register int
#define rep(i,a,b) for(rg i=(a);i<=(b);++i)
#define per(i,a,b) for(rg i=(a);i>=(b);--i)
const int maxn = 200010;
const int mod = 1e9+7;
int Tmx[maxn<<2],Tmn[maxn<<2],T[maxn<<2];
void modify(int rt,int l,int r,int pos,int val){
    if(l == r){
        Tmx[rt] = Tmn[rt] = val;
        T[rt] += val;
        if(T[rt] >= mod) T[rt] -= mod;
        return ;
    }
    int mid = (l+r) >> 1;
    if(pos <= mid) modify(rt<<1,l,mid,pos,val);
    else modify(rt<<1|1,mid+1,r,pos,val);
    Tmx[rt] = max(Tmx[rt<<1],Tmx[rt<<1|1]);
    Tmn[rt] = min(Tmn[rt<<1],Tmn[rt<<1|1]);
    T[rt] = T[rt<<1] + T[rt<<1|1];if(T[rt] >= mod) T[rt] -= mod;
}
int query_min(int rt,int l,int r,int L,int R){
    if(L <= l && r <= R) return Tmn[rt];
    int mid = (l+r) >> 1;
    if(R <= mid) return query_min(rt<<1,l,mid,L,R);
    if(L >  mid) return query_min(rt<<1|1,mid+1,r,L,R);
    return min(query_min(rt<<1,l,mid,L,R),query_min(rt<<1|1,mid+1,r,L,R));
}
int query_max(int rt,int l,int r,int L,int R){
    if(L <= l && r <= R) return Tmx[rt];
    int mid = (l+r) >> 1;
    if(R <= mid) return query_max(rt<<1,l,mid,L,R);
    if(L >  mid) return query_max(rt<<1|1,mid+1,r,L,R);
    return max(query_max(rt<<1,l,mid,L,R),query_max(rt<<1|1,mid+1,r,L,R));
}
int query_sum(int rt,int l,int r,int L,int R){
    if(L <= l && r <= R) return T[rt];
    int mid = (l+r) >> 1;
    if(R <= mid) return query_sum(rt<<1,l,mid,L,R);
    if(L >  mid) return query_sum(rt<<1|1,mid+1,r,L,R);
    return (query_sum(rt<<1,l,mid,L,R) + query_sum(rt<<1|1,mid+1,r,L,R)) % mod;
}
struct Node{
    int x,v;
    bool friend operator < (const Node &a,const Node &b){
        return a.v < b.v;
    }
}a[maxn];
struct seg{
    int L,R;
    bool friend operator < (const seg &a,const seg &b){
        return a.R == b.R ? a.L < b.L : a.R < b.R;
    }
}se[maxn];
int seq[maxn];
int main(){
    int n;read(n);
    rep(i,1,n){
        read(a[i].x);read(a[i].v);
        seq[i] = a[i].x;
    }sort(seq+1,seq+n+1);sort(a+1,a+n+1);
    rep(i,1,n){
        a[i].x = lower_bound(seq+1,seq+n+1,a[i].x) - seq;
    }
    memset(Tmn,0x3f,sizeof Tmn);
    rep(i,1,n){
        if(a[i].x+1 <= n) se[i].L = query_min(1,1,n,a[i].x+1,n);
        else se[i].L = i;
        se[i].L = min(se[i].L,i);
        modify(1,1,n,a[i].x,i);
    }
    memset(Tmx,0,sizeof Tmx);
    per(i,n,1){
        if(a[i].x-1 >= 1) se[i].R = query_max(1,1,n,1,a[i].x-1);
        else se[i].R = i;
        se[i].R = max(se[i].R,i);
        modify(1,1,n,a[i].x,i);
    }
    sort(se+1,se+n+1);
    memset(T,0,sizeof T);
    int ans = 0;
    per(i,n,1){
        int res = 0;
        if(se[i].R == n) res ++ ;
        res += query_sum(1,1,n,1,min(se[i].R+1,n));
        if(res >= mod) res -= mod;
        modify(1,1,n,se[i].L,res);
        if(se[i].L == 1) ans += res;
        if(ans >= mod) ans -= mod;
    }printf("%d\n",ans);
    return 0;
}

Measured memory_bytes: 13440
s = gets.strip.to_s

days = ['SUN', 'MON', 'TUE', 'WED', 'THU', 'FRI', 'SAT' ]
next_day = 0

for x in days 
   if s == x.to_s
      next_day = 7 - days.index(x)
   end
end

puts next_day


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

const int INF = 1000000000;

int main(){
  int n,k;cin>>n>>k;
  vector<int>dp(n),h(n,0);
  for(int i=0;i<n;++i)cin>>h[i];

  dp[0] = 0;
  dp[1] = abs(h[1] - h[0]);
  int cost;
  int minimum_cost = INF;
  int m;
  for(int i=2;i<n;++i){
    if(i<=k)m = i;
    else m = k;
    for(int j=1;j<=m;++j){
      cost = dp[i-j]+abs(h[i]- h[i-j]);
      if(cost<minimum_cost) minimum_cost = cost;
    }
    dp[i] = minimum_cost;
    minimum_cost = INF;
  }
  cout<<dp[n-1]<<endl;

  return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
//INSERT ABOVE HERE
signed main(){
  Int n;
  cin>>n;
  using P = pair<Int, Int>;
  vector<vector<P> > G(n);
  for(Int i=1;i<n;i++){
    Int a,b;
    cin>>a>>b;
    a--;b--;
    G[a].emplace_back(b,i);
    G[b].emplace_back(a,i);
  }
  vector<Int> s(n),sz(n),ans(n,-1);
  for(Int i=0;i<n;i++) cin>>s[i];

  Int idx=-1,idy=-1,idz=-1;
  function<void(Int, Int)> dfs=
    [&](Int v, Int p){
      sz[v]=1;
      for(P e:G[v]){
	Int u=e.first;
	if(u==p) continue;
	dfs(u,v);
	sz[v]+=sz[u];
      }
      
      for(P e:G[v]){
	Int u,k;
	tie(u,k)=e;
	if(u==p) continue;
	if(sz[u]==n-sz[u]){
	  idx=v;idy=u;idz=k;
	  continue;
	}
	ans[k]=abs(s[v]-s[u])/abs(n-sz[u]*2);
      }
    };
  dfs(0,-1);
  
  if(~idx){
    Int sum=0;
    function<void(Int, Int, Int)> dfs2=
      [&](Int v,Int p,Int d){
	sum+=d;
	for(P e:G[v]){
	  Int u,k;
	  tie(u,k)=e;
	  if(u==p) continue;
	  dfs2(u,v,d+ans[k]);
	}
      };
    dfs2(idx,idy,0);
    dfs2(idy,idx,0);    
    ans[idz]=(s[idx]-sum)/(n/2);
  }
  
  for(Int i=1;i<n;i++) cout<<ans[i]<<endl;
  return 0;
}


Measured memory_bytes: 19584
#include <bits/stdc++.h>
#include <atcoder/all>

using namespace std;
using namespace atcoder;

int main(){
    int n, q;
    cin >> n >> q;
    dsu uf(n);
    for(int i = 0; i < q; i++){
        int t, u, v;
        cin >> t >> u >> v;
        if(!t)uf.merge(u, v);
        else cout << uf.same(u, v) << endl;
    }
}


Measured memory_bytes: 3880
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i=0;i<(n);++i)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define all(x) (x).begin(), (x).end()
#define PI 3.14159265358979323846264338327950L
using namespace std;
typedef long long ll;
typedef long double ld;
int main() {
    int k,s;
    cin>>k>>s;
    ll cnt=0;
    rep(x,k+1){
        rep(y,k+1){
            if(s-x-y>=0&&s-x-y<=k) cnt++;
        }
    }
    cout<<cnt;
}

Measured memory_bytes: 3600
#include "bits/stdc++.h"
 
typedef long long ll;
#define int ll
#define fi first
#define se second
#define SORT(a) sort(a.begin(),a.end())
#define rep(i,n) for(int i = 0;i < (n) ; i++) 
#define REP(i,n) for(int i = 0;i < (n) ; i++) 
#define MP(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define INF LLONG_MAX/2
#define all(x) (x).begin(),(x).end()
#define debug(x) cerr<<#x<<": "<<x<<endl
#define debug_vec(v) cerr<<#v<<":";rep(i,v.size())cerr<<" "<<v[i];cerr<<endl
using namespace std;
int MOD = 1000000007;
int n,m;
vector<int> p[100010];
int used[100010] = {0};
int c = 1;
void dfs(int g,int d){
    if(used[g] == 0){
        used[g] = d;
        for(auto x:p[g]){
            dfs(x,-1*d);
        }
    }else{ 
        if(used[g] != d){
            c = 0;
        }
        return;
    }
    return;
}

signed main(){
    cin >> n >> m;
    rep(i,m){
        int a,b;
        cin >> a >> b;
        p[a-1].push_back(b-1);
        p[b-1].push_back(a-1);
    }
    dfs(0,1);
    if(c == 0){
        cout << n*(n-1)/2 - m << endl;
        return 0;
    }
    int cnt = 0;
    rep(i,n){
        if(used[i] == 1){
            cnt++;
        }
    }
    cout << cnt*(n-cnt) - m << endl;

    
    return 0; 
}

// g++ -std=c++14 code1.cpp
// rm -r -f test;oj dl https://arc064.contest.atcoder.jp/tasks/arc064_c
// rm -r -f test;oj dl http://code-festival-2017-qualb.contest.atcoder.jp/tasks/code_festival_2017_qualb_c


Measured memory_bytes: 7552
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, N) for (int i = 0; i < (int)N; ++i)
#define all(a) (a).begin(), (a).end()

int X, t;
int main() {
  cin >> X >> t;
  cout << max(X - t, 0) << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include<math.h>
#include<iomanip>
using namespace std;

#define ll long long
using vt = ll; //ここで数値の型を変えられる
#define rep(i, n) for (vt i = 0; i < (vt)(n); i++)
#define reps(i, s, n) for(vt i = (vt) (s); i < (vt) (n); i++) 
#define MOD 1000000007

int main() {
	vt n, s = 0;
	cin >> n;
	vector<vt> a(n), b(n), c(n - 1);
	rep(i, n) cin >> a.at(i);
	rep(i, n) cin >> b.at(i);
	rep(i, n - 1) cin >> c.at(i);
	s += b.at(a.at(0) - 1);
	reps(i, 1, n) {
		s += b.at(a.at(i) - 1);
		if (a.at(i) - a.at(i - 1) == 1) s += c.at(a.at(i - 1) - 1);
	}
	cout << s;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<cassert>
#include <fstream>
#include <time.h>
#include <iterator>
#include<random>



#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define REVERSE(v,n) reverse(v,v+n);
#define VREVERSE(v) reverse(v.begin(), v.end());
#define ll long long
#define pb(a) push_back(a)
#define m0(x) memset(x,0,sizeof(x))
#define print(x) cout<<x<<endl;
#define pe(x) cout<<x<<" ";
#define lb(v,n) lower_bound(v.begin(), v.end(), n);
#define ub(v,n) upper_bound(v.begin(), v.end(), n);
#define int long long
#define all(x) (x).begin(), (x).end()
using namespace std;
int MOD = (ll)1000000000 + 7;
const ll INF = 1e17;
const double pi = acos(-1);
const double EPS = 1e-10;
typedef pair<int, int>P;
const int MAX = 500050;

int N;
vector<int>v;
signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	cin >> N;
	v.resize(N);
	REP(i, N) {
		cin >> v[i];
	}
	VSORT(v);
	int idx1 = N/2-1, idx2 = N/2;
	int ans = v[idx2] - v[idx1];;
	print(ans);
}


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

int main() {
  int n;
  cin >> n;
  vector<P> points(n);
  rep(i, n) {
    cin >> points[i].first >> points[i].second;
  }

  ll minx = 10000000000, maxx = 0, miny = 10000000000;
  rep(i, n) {
    ll x = points[i].first, y = points[i].second;
    if (x < minx) minx = x;
    if (x > maxx) maxx = x;
    if (y < miny) miny = y;
  }

  //cout << minx << " " << maxx << " " << miny << endl;

  ll minDistBR = 10000000000, maxDistBR = 0;
  rep(i, n) {
    ll x = points[i].first, y = points[i].second;
    ll distBR = abs(x - minx) + abs(y - miny);
    if (distBR < minDistBR) minDistBR = distBR;
    if (distBR > maxDistBR) maxDistBR = distBR;
  }

  ll minDistBL = 10000000000, maxDistBL = 0;
  rep(i, n) {
    ll x = points[i].first, y = points[i].second;
    ll distBL = abs(x - maxx) + abs(y - miny);
    if (distBL < minDistBL) minDistBL = distBL;
    if (distBL > maxDistBL) maxDistBL = distBL;
  }

  ll ans = max( maxDistBR - minDistBR, maxDistBL - minDistBL);

  cout << ans << endl;

  return 0;
}
/*
*/


Measured memory_bytes: 4836
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <string.h>
#include <algorithm>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
#include <bits/stdc++.h>
using namespace std;
 
const double TL = 1.5 * CLOCKS_PER_SEC;
mt19937 rng((unsigned int) chrono::steady_clock::now().time_since_epoch().count());
#define clr(x, y) memset(x, y, sizeof(x))
#define forn(i, n) for (int i = 0; i < n; i++)
#define LL long long
const double pi = acos(-1.0);

char s[200005];
int n;

int main() {
#ifdef LOCAL
  auto start_clock = clock();
  freopen("in", "r", stdin);
#endif
  scanf("%s", s);
  n = strlen(s);
  for (int i = 0; i < n; i++) {
    if (s[i] == '?') {
      s[i] = 'D';
    }
  }
  printf("%s\n", s);

#ifdef LOCAL
 auto end_clock = clock();
 cout << "Time:" << (end_clock - start_clock) / CLOCKS_PER_SEC << endl;
#endif
  return 0;
}

Measured memory_bytes: 3884
#include <iostream>
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
typedef long long int ll;
typedef long double dl;
#define PI  3.14159265358979323846
#define Mod 1000000007
ll fast(ll n,ll a,ll m)
{
    if(n==0)
        return 1;
    else if(n==1)
        return a;
    else
    {
        ll r=fast(n/2,a,m);
        if(n%2==0)
        {
            return (((r%m)*(r%m))%m);
        }
        else
        {
            return (((((r%m)*a)%m)*r)%m);
        }
    }
}
ll ckck(ll N)
{
    ll lo=1,hi=1e10;
    ll  mid,ind;
    ll cnt;
    while(lo<=hi)
    {
        mid=lo+(hi-lo)/2;
        cnt=mid*(mid+1);
        cnt/=2;
        cnt-=1;
        if(N>cnt)
        {
            ind=mid;
            lo=mid+1;
        }
        else
        {
            hi=mid-1;
        }
    }
    return ind;
}

int main()
{
    set<string> st;
    string s;
    int i,n;
    cin>>n;
    for(i=0;i<n;i++)
    {
        cin>>s;
        st.insert(s);
    }
    int d=st.size();
    cout<<d;
}


Measured memory_bytes: 19120
#include<bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define repk(i,k,n) for (ll i = k; i < (ll)(n); ++i)
#define MAX 500000001000000000
#define MOD 1000000007
typedef long long  ll;

using namespace std;

ll ans, cnt;

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

	ll N;
	string s;
	map<char, ll> m;

	string march = "MARCH";
	rep(i, march.size()) {
		m[march[i]] = 0;
	}

	cin >> N;
	rep(i, N) {
		cin >> s;
		m[s[0]]++;
	}

	ans += m['M'] * m['A'] * m['R'];
	ans += m['M'] * m['A'] * m['C'];
	ans += m['M'] * m['A'] * m['H'];
	ans += m['M'] * m['R'] * m['C'];
	ans += m['M'] * m['R'] * m['H'];
	ans += m['M'] * m['C'] * m['H'];
	ans += m['A'] * m['R'] * m['C'];
	ans += m['A'] * m['R'] * m['H'];
	ans += m['A'] * m['C'] * m['H'];
	ans += m['R'] * m['C'] * m['H'];

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
using namespace std;
using ll = long long;

int main(){
    ll a,b,c,d,e,k,m=0,n,l,r,p=0,q,x,y,z,max1=0,ans1=0,ans2=0;
    string s,t,u;
    cin>>n>>q>>s;
    ll o1[n];
    o1[0]=0;
    for (ll i=1; i<n; i++) {
        if (s[i-1]=='A'&&s[i]=='C') {
            m++;
        }
        o1[i]=m;
    }
    for (ll i=0; i<q; i++) {
        cin>>l>>r;
        cout<<o1[r-1]-o1[l-1]<<endl;
    }
    
}




Measured memory_bytes: 1856
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;

typedef long long ll;
typedef pair<int,int> ii;
typedef tree<ii,null_type,less<ii>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;

int eval(vector<vector<ii>> &adj, int K) {
	vector<int> dist(K,INT_MAX);
	deque<int> dq;
	dist[1]=0;
	dq.push_back(1);
	while(!dq.empty()) {
		int cur=dq.front(); dq.pop_front();
		for (auto nxt : adj[cur]) {
			int val=dist[cur]+nxt.second;
			if(dist[nxt.first]>val) {
				dist[nxt.first]=val;
				nxt.second ? dq.push_back(nxt.first) : dq.push_front(nxt.first);
			}
		}
	}
	return dist[0];
}

int main() {
	cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);
	int K; cin>>K;
	vector<vector<ii>> adj(K);
	for (int i=0; i<K; i++)
		adj[i].push_back({(i+1)%K,1}), adj[i].push_back({(i*10)%K,0});
	cout<<1+eval(adj,K)<<"\n";
	return 0;
}

Measured memory_bytes: 6272
def main():
    from math import ceil
    D, G = (int(i) for i in input().split())
    pc = [[int(i) for i in input().split()] for j in range(D)]
    ans = float('inf')
    for bit in range(1<<D):
        completed = []
        tmp = 0
        cur = 0
        for i in range(D):
            if bit & (1<<i):
                completed.append(i)
        for c in completed:
            tmp += (100*(c+1)*pc[c][0] + pc[c][1])
            cur += pc[c][0]
        for d in range(D)[::-1]:
            if d in completed:
                continue
            less = ceil((max(G - tmp,0))/(100 * (d+1)))
            if pc[d][0] < less:
                continue
            tmp += 100*(d+1)*less
            cur += less
            break
        if tmp >= G:
            ans = min(ans,cur)
    print(ans)
if __name__ == '__main__':
    main()

Measured memory_bytes: 41968
str = gets.chomp
mms = ["01","02","03","04","05","06","07","08","09","10","11","12"]
yys = []
100.times do |i|
	yys.push(i)
end
aa = str[0..1]
bb = str[2..3]
am = mms.include?(aa)
bm = mms.include?(bb)
ay = yys.include?(aa.to_i)
by = yys.include?(bb.to_i)

if am && bm && ay && by
	puts("AMBIGUOUS")
elsif (am && by)
	puts("MMYY")
elsif (ay && bm)
	puts("YYMM")
else
	puts("NA")
end

Measured memory_bytes: 1788
#include <iostream>
#include <math.h>
using namespace std;

int main(){
  int n, m;
  int a[2][60], b[2][60];
  
  cin >> n >> m;
  for ( int i = 0; i < n; i ++ ){
    cin >> a[0][i] >> a[1][i];
  }
  for ( int i = 0; i < m; i ++ ){
    cin >> b[0][i] >> b[1][i];
  }
  
  int dist, dmin, ans;
  
  for ( int i = 0; i < n; i ++ ){
    dmin = 3e8;
    for ( int j = 0; j < m; j ++ ){
      dist = fabs(a[0][i] - b[0][j]) + fabs(a[1][i] - b[1][j]);
      if ( dist < dmin ){
        dmin = dist;
        ans = j + 1;
      }
    }
    cout << ans << endl;
  }
}

Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;

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

        int N = scanner.nextInt();
        int M = scanner.nextInt();

        ArrayList<Integer> cordinates = new ArrayList<>();

        for(int i=0; i<M; i++){
            int tmp = scanner.nextInt();
            cordinates.add(tmp);
        }

        if(M <= N){
            System.out.println(0);
            return;
        }

        Collections.sort(cordinates);

        ArrayList<Integer> distances = new ArrayList<>();

        long acc = 0;

        for(int i=0; i<cordinates.size()-1; i++){
            int diff = cordinates.get(i+1) - cordinates.get(i);
            acc += diff;
            distances.add(diff);
        }

        Collections.sort(distances, Collections.reverseOrder());

        for(int i=0; i < N-1; i++){
            acc -= distances.get(i);
        }

        System.out.println(acc);

    }
}

Measured memory_bytes: 50088
#include<bits/stdc++.h>
using namespace std;
typedef vector<int> vec;
typedef vector<vec> mat;


void func(const mat &A){
  for(int i=0;i<(int)A.size();i++){
    for(int j=0;j<(int)A[i].size();j++){
      cout<<A[i][j];
    }
    cout<<endl;
  }
  cout<<endl;
}

bool gauss_jordan(const mat& A, const vec& b) {
  int n = A.size();
  mat B(n, vec(n+1));
  for(int i=0;i<n;i++)
    for(int j=0;j<n;j++)
      B[i][j]=A[i][j];
  for(int i=0;i<n;i++)B[i][n]=b[i];

  for(int i=0;i<n;i++) {
    //    cout<<i<<endl;
    //    func(B);
    int pivot=i;
    for(int j=i;j<n;j++){
      if(B[j][i]>0){
        pivot=j;
        break;
      }
    }
    swap(B[i], B[pivot]);
    //    cout<<pivot<<' '<<'?'<<endl;
    //    func(B);
    if(B[i][i]==0)continue;
    for(int j=0;j<n;j++){
      if(i==j||B[j][i]==0)continue;
      for(int k=0;k<=n;k++){
        B[j][k]+=B[i][k];
        B[j][k]%=2;
      }
    }
  }
  // func(B);
  for(int i=0;i<n;i++){
    if(B[i][i]==0&&B[i][n]>0)return false;
  }
  return true;
}

int n,m,d;
int t[30][30];

int main(){
    while(1){
    cin>>m>>n>>d;
    if(n==0&&m==0&&d==0)break;
    mat A(n*m,vec(n*m,0));
    vec B(n*m);
    for(int i=0;i<n;i++){
      for(int j=0;j<m;j++){
        cin>>t[i][j];
        B[i*m+j]=t[i][j];
        A[i*m+j][i*m+j]=1;
        for(int k=0;k<n;k++){
          for(int l=0;l<m;l++){
            if(abs(i-k)+abs(j-l)==d){
              A[i*m+j][k*m+l]=1;
            }
          }
        }
      }
    }
    cout<<gauss_jordan(A,B)<<endl;
  }
  return 0;
}

Measured memory_bytes: 4244
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner stdle = new Scanner(System.in);
		// 整数の入力
        int A = stdle.nextInt();
        int P = stdle.nextInt();

        int AtoP = A * 3;
        int sumP = P + AtoP;
        int ans = sumP / 2;

        System.out.println(ans);
       
    }
}

Measured memory_bytes: 21972
#include <bits/stdc++.h>
#define rep(i, a) for (ll i = 0; i < (a); ++i)
#define pb push_back
#define all(v) v.begin(),v.end()
#define sort_1(v) sort(v.begin(),v.end())
#define sort_2(v) sort(v.begin(),v.end(),greater<ll>())
#define reverse(v) reverse(v.begin(),v.end())
typedef long long ll;
typedef long double la;
using namespace std;
 
int main(){
  string s,t,u;
  int a,b;
  cin >> s >> t >> a >> b >> u;
  if(s == u){
    a--;
  }
  if(t == u){
    b--;
  }
  cout << a << " " << b << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  int A,B,C;
  cin >> A >> B >> C;
  if((A+B+C)>=22){
    cout << "bust" << endl;
  }
  else if((A+B+C)<=21){
    cout << "win" << endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define fast ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define ll long long int
#define nl cout << endl
#define pb push_back
#define ff first
#define ss second
#define all(ar) ar.begin(), ar.end()
//debugger
#define trace1(x)                cerr << #x << ": " << x << endl;
#define trace2(x, y)             cerr << #x << ": " << x << " | " << #y << ": " << y << endl;
#define trace3(x, y, z)          cerr << #x << ": " << x << " | " << #y << ": " << y << " | " << #z << ": " << z << endl;
#define trace4(a, b, c, d)       cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << endl;
#define trace5(a, b, c, d, e)    cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << endl;
#define trace6(a, b, c, d, e, f) cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << " | " << #f << ": " << f << endl;

int main() {
	fast;
	int n;
	cin >> n;
	string a;
	cin >> a;
	int ans=1;
	for (int i=1; i<n; i++) {
		if (a[i]!=a[i-1]) {
			ans++;
		}
	}
	cout << ans;nl;
	return 0;
}

//notes
/*
 use these format of input when number of inputs not provided
 *while(scanf("%lld",&n)!=EOF)
 *while using getline(cin,s) for taking input of a string which is 
 having white space characters just write cin>>ws; before geline(cin,s)
 to make it work properly
*/

/*
 use 2-D vector for representing the pair<int,pair<int,int> > kind of things
*/

Measured memory_bytes: 512
#include <bits/stdc++.h>
#define ll long long
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define deb(x) cout<<#x<<"="<<x<<endl;
#define endl '\n'
#define M 1000000007
#define int long long
using namespace std;
#define N 100005
 
int a[N], b[N];
signed main()
{
    ll x,k,d;
    cin>>x>>k>>d;
    if(x>0)
    {
        ll mn=x/d;
        if(mn>=k)
        {
            cout<<abs(x-k*d)<<endl;
        }
        else
        {
            k=k-mn;
            if(k%2==0)
            {
                cout<<abs(x-mn*d)<<endl;
            }
            else
            {
                cout<<abs(x-(mn+1)*d)<<endl;
            }
        }
    }
    else if(x<0)
    {
        ll mn=x/d;
        mn=-mn;
        if(mn>=k)
        {
            cout<<abs(x+k*d)<<endl;
        }
        else
        {
            k=k-mn;
            if(k%2==0)
            {
                cout<<abs(x+mn*d)<<endl;
            }
            else
            {
                cout<<abs(x+(mn+1)*d)<<endl;
            }
        }
    }
    else
    {
        if(k%2==0)
        {
            cout<<0<<endl;
        }
        else
        {
            cout<<d<<endl;
        }
    }
}

Measured memory_bytes: 3632
n,k=map(int,input().split())
ans=set()
for i in range(2,n+1):
    ans.add((1,i))
c=0
import itertools
for x,y in itertools.combinations(list(range(2,n+1)),2):
    if c>=(n-1)*(n-2)//2-k:
        break
    c+=1
    ans.add((x,y))

if (n-1)*(n-2)//2-k<0:
    print(-1)
    exit()
print(len(ans))
for i,j in ans:
    print(i,j)


Measured memory_bytes: 4084
import std;

alias sread = () => readln.chomp();
alias lread = () => readln.chomp.to!long();
alias aryread(T = long) = () => readln.split.to!(T[]);
//aryread!string();
void main()
{
    auto r = lread();
    writeln(r ^^ 2);

}

void scan(L...)(ref L A)
{
    auto l = readln.split;
    foreach (i, T; L)
    {
        A[i] = l[i].to!T;
    }
}

void arywrite(T)(T a)
{
    a.map!text.join(' ').writeln;
}


Measured memory_bytes: 3684
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
int main(){ 
    int n;
    cin>>n;
    long long int a=0,b=0,c=0,d=0,e=0;
    vector<string> s(n);
    REP(i,n) cin>>s[i];
    REP(i,n){
    if(s[i][0]=='M'){
        a++;
    }else if(s[i][0]=='A'){
        b++;
    }else if(s[i][0]=='R'){
        c++;
    }else if(s[i][0]=='C'){
        d++;
    }else if(s[i][0]=='H'){
        e++;
    }
    }
    long long int f;
    f=a*b*(c+d+e)+a*c*(d+e)+a*d*e+b*c*(d+e)+b*d*e+c*d*e;
    cout<<f;
    return 0;
}


Measured memory_bytes: 6144
#include<stdio.h>

int main(){
	unsigned long l, r, i, j; 
	int min=2019;
	scanf("%lu %lu", &l, &r);
	for(i=l;i<(r-l<2019?r:l+2019);i++){
		for(j=i+1;j<=(r-l<2019?r:l+2019);j++){
			if((i*j)%2019<min) min = (i*j)%2019;
		}		
	}
	printf("%d", min);
}

Measured memory_bytes: 128
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int d = in.nextInt();
        int[] ci = new int[26];
        int[][] sdi = new int[d][26];
        for(int i=0; i<26; i++) {
            ci[i] = in.nextInt();
        }
        for(int day=0; day<d; day++) {
            for(int i=1; i<26; i++) {
                sdi[day][i] = in.nextInt();
            }
        }
        
        for(int day=0; day<d; day++) {
            int ans = 1;
            if(day<d-26 || true) {
                int maxS = 0;
                int maxStype = 1;
                for(int i=0; i<26; i++) {
                    if(maxS < sdi[day][i]) {
                        maxS = sdi[day][i];
                        maxStype = i;
                    }
                }
                ans = maxStype;
            }
            else {
                ans = d - day; // FIXME
            }
            System.out.println(ans);
        }
    }
}


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

const int maxn = 310;
ll f[maxn][maxn], c[maxn][maxn], sum[maxn][maxn];
ll mod;

void init(int n)
{
	c[0][0] = 1;
	for (int i=1;i<=n;i++)
	{
		c[i][0] = 1;
		for (int j=1;j<=n;j++) c[i][j] = (c[i-1][j-1] + c[i-1][j]) % mod;
	}
}

int main()
{
	//freopen("E.in","r",stdin);
	int n,k;
	cin >> n >> k >> mod;

	init(n);

	for (int i=0;i<=k;i++) f[1][i] = 1, sum[1][i] = i+1;
	for (int i=2;i<=n+1;i++)
	{
		for (int j=0;j<=k;j++)
		{
			for (int t=1;t<=i-1;t++)
			{
				f[i][j] += c[i-2][t-1] * f[i-t][j] % mod * (sum[t][k] - sum[t][j] + mod) % mod;
				f[i][j] %= mod;
			}
			if (j >= 1) sum[i][j] = (sum[i][j-1] + f[i][j]) % mod;
			else sum[i][j] = f[i][j];
		}
	}

	cout << f[n+1][0] << endl;
	return 0;
}


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

#define ll long long
#define pb push_back
#define f first
#define s second
#define mp make_pair
#define gg return 0;
#define pii pair < int, int>

using namespace std;

const int maxn = (int)1e5 + 7;
const int INF = (int)1e9;

ll a,b[4],c,d,cnt,e[(int)2e3 + 1][(int)2e3 + 1],cost[maxn],tout[maxn],mn = INF,mx = -INF,l,r;

ll n,h,k;

ll t1, f1, t2, f2;

int main()
{
	cin >> b[1] >> b[2] >> b[3];
	sort(b + 1, b + 4);
	for(int i = 1; i <= 3; ++i){
		if(i < 3){
			if(b[i] != 5){
				cout << "NO" << endl;
				return 0;
			}
		}
		else{
			if(b[i] != 7){
				cout << "NO" << "\n";
				return 0;
			}
		}
	}
	cout << "YES" << '\n';
	gg;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>//i think this will print all 3 digit numbers 
using namespace std;
int cnt[100*1000+3];
int main(){
    int n;cin>>n;
    for(int i=1;i<=n;++i){
        int va;cin>>va;
        va++;
        cnt[va]+=1;
        cnt[va+1]+=1;
        cnt[va-1]+=1;
    }
    int ans=0;
    for(int i=1;i<=100*1000;++i)ans=max(ans,cnt[i]);
    cout<<ans<<"\n";
    return 0;
}

Measured memory_bytes: 640
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"
#include "cassert"
#include "ctime"
 
using namespace std;

int main() {
  int W, H, N;
  cin >> W >> H >> N;
  
  vector<int> marker_x(W, 1);
  vector<int> marker_y(H, 1);
  int x, y, a;
  for (int i=0; i<N; i++) {
    cin >> x >> y >> a;
    if (a == 1) {
      for (int i=0; i<=x-1; i++) marker_x[i] = 0;
    } else if (a == 2) {
      for (int i=x; i<W; i++) marker_x[i] = 0;
    } else if (a == 3) {
      for (int i=0; i<=y-1; i++) marker_y[i] = 0;
    } else {
      for (int i=y; i<H; i++) marker_y[i] = 0;
    }
  }
  
  int length_x = accumulate(marker_x.begin(), marker_x.end(), 0);
  int length_y = accumulate(marker_y.begin(), marker_y.end(), 0);
  cout << length_x * length_y << endl;
  
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
char s[1000010];
int n,r,b;
int main()
{
  scanf("%d",&n);
  scanf("%s",s+1);
  for(int i=1;i<=n;i++)
    if(s[i]=='B')
      b++;
 	else
      r++;
  puts(r>b?"Yes":"No");
}

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

typedef vector<int> vi;
typedef vector<vi> vvi;

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

  int N, D;
  vvi X;
  int i, j, k;
  int su;
  int rst = 0;

  cin >> N >> D;
  X.resize(N, vi(D));
  for(i = 0; i < N; i++) {
    for(j = 0; j < D; j++) {
      cin >> X[i][j];
    }
  }
  for(i = 0; i < N - 1; i++) {
    for(j = i + 1; j < N; j++) {
      su = 0;
      for(k = 0; k < D; k++) {
        su += (X[i][k] - X[j][k]) * (X[i][k] - X[j][k]);
      }
      for(k = 0; k * k <= 16000; k++) {
        if(su == k * k) {
          rst++;
          break;
        }
      }
    }
  }

  cout << rst << endl;

  return 0;
}


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

using namespace std;
using ll = long long;

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

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

  sort(a.begin(), a.end());
  reverse(a.begin(), a.end());
  ll ans = 0ll;
  for (int i = 0; i < ceil(n / 2); i++) {
    ans += a[i];
  }
  for (int i = 0; i < n / 2 - 1; i++) {
    ans += a[i + 1];
  }
  if (n % 2 == 1)
    ans += a[n / 2];
  cout << ans << endl;

  return 0;
}


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

LL a, b, c, k;

int main()
{
	scanf("%lld%lld%lld%lld", &a, &b, &c, &k);
	if(k&1) printf("%lld\n", b-a);
	else printf("%lld\n", a-b);
}

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

int main() {
  int a, b, c, k;
  cin >> a >> b >> c >> k;
  int ans = ( k > a ) ? a : k;
  k -= (a+b);
  ans -= ( k > 0 ) ? k : 0;
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3632
/*#include <iostream>
#include <cmath>
#include <vector>
#include <algorithm>
#include <array>
#include <vector>
#include <deque>
#include <set>
#include <map>
#include <string>
#include <stack>
#include <queue>
#include <unordered_map>
#include <unordered_set>
*/

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

#define int long long
#define pb push_back
#define mp make_pair
#define F first
#define S second
#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 RALL(a) (a).rbegin(),(a).rend()
#define SORT(c) sort((c).begin(),(c).end())

typedef long long ll;
const ll INF = 1LL<<60;
const ll mod = 1e9 + 7;
const int MAX_N = 5e5 + 5;
int dx[] = { -1,0,1,0 }, dy[] = { 0,1,0,-1 };
vector<ll> prime;

ll inv[MAX_N], fac[MAX_N];

template <class T = ll> T in() { T x; cin >> x; return (x); }
inline ll GCD(ll a, ll b) { ll c; while (b != 0) { c = a % b; a = b; b = c; }return a; }
inline ll LCM(ll a, ll b) { return a * b / GCD(a, b); }
inline ll POW(ll a, ll b) { ll c = 1; while (b > 0) { if (b & 1) { c = a * c%mod; }a = a * a%mod; b >>= 1LL; }return c; }
inline void _nCr() { fac[0] = 1; for (int i = 1LL; i < MAX_N; i++) { fac[i] = fac[i - 1] * i%mod; }for (int i = 0; i < MAX_N; i++) { inv[i] = POW(fac[i], mod - 2); } }
inline ll nCr(ll n, ll r) { return (fac[n] * inv[r] % mod)*inv[n - r] % mod; }
inline void PRI(ll n) { bool a[n + 1]; for (int i = 0; i < n + 1; i++) { a[i] = 1; }for (int i = 2; i < n + 1; i++) { if (a[i]) { prime.pb(i); ll b = i; while (b <= n) { a[b] = 0; b += i; } } } }

typedef pair<int, pair<int, int>> edge;


signed main() {
	int a,b;
	cin >> a >> b;
	int ans = -1;
	ans = max(a * 2 - 1,ans);
	ans = max(b * 2 - 1,ans);
	ans = max(a + b,ans);
	cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,a,n) for(int i=a;i<n;i++)
#define all(a) a.begin(),a.end()
#define o(a) cout<<a<<endl
#define int long long
using namespace std;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;

signed main(){
	int a,b,c;
	cin>>a>>b>>c;
	int ans=-1;
	rep(i,0,10000){
		int tmp=60*i+c;
		if(tmp%(a+b)<=a){
			ans=tmp; break;
		}
	}
	o(ans);
}

Measured memory_bytes: 1156
#include<stdio.h>

int str_count(char *str){
  int i = 0;
  while(str[i] != '\0'){
    i++;
  }
  
  return i;
}

int is_palindrome(char *str, int a, int b){
  for(int i = 0;i <= (a + b) / 2 - a;i++){
    if(str[a + i] != str[b - i]){
      return 0;
    }
  }
  return 1;
}

int main(){
  int n, flag = 0;
  char str[100];
  
  scanf("%s", str);
  
  n = str_count(str);
  
  if(is_palindrome(str, 0, (n - 1) / 2 - 1)){
    if(is_palindrome(str, (n + 3) / 2 - 1 , n - 1)){
      if(is_palindrome(str, 0, n - 1)){
        flag = 1;
      }
    }
  }
 
  if(flag == 1){
    printf("Yes");
  }
  else{
    printf("No");
  }

  
  return 0;
  
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define all(x) (x.begin()),(x.end())
#define sz(x)  ((ll)x.size())
#define PI 3.141592653589793238462643383279502884197169399375105820974944592307816406286
#define FAST_IO ios_base :: sync_with_stdio(false),cin.tie(nullptr),cout.tie(nullptr);
using namespace std;
#ifdef LOCAL
#include "uj.h"
#endif
void tokenize(string str,const char delim,vector<string> & res){
	stringstream p(str);
	string token;
	while(getline(p,token,delim)){
		res.push_back(token);
	}
	return;
}

// Your workSpace ...



void test_case(){
	char ch;
	cin>>ch;
	if(isupper(ch)) cout<<'A';
	else cout<<'a';
	
	
}







int main(){
	FAST_IO;
	int tt;
	//cin>>tt;
	tt = 1;
	while(tt--){
		test_case();
	}
#ifndef ONLINE_JUDGE
 	cerr << "Running Time: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
	return 0;
}


Measured memory_bytes: 3620
import java.util.Scanner;

public class Main {
	static int N;
	static int[] A;
	static int[][] x;
	static int[][] y;
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		N = sc.nextInt();
		A = new int[N];
		x = new int[N][];
		y = new int[N][];
		for(int i=0;i<N;i++) {
			A[i]=sc.nextInt();
			x[i] = new int[A[i]];
			y[i] = new int[A[i]];
			for(int j=0;j<A[i];j++) {
				x[i][j]=sc.nextInt();
				y[i][j]=sc.nextInt();
			}
		}
		
		int[] honestOrUnkind = new int[N];
		int max = 0;
		for(int bit=0;bit < (1<<N);bit++) {
			int count=0;
			for(int i=0;i<N;i++) {
				if((bit & 1<<i)>0) {
					honestOrUnkind[i]=1;
				}else {
					honestOrUnkind[i]=0;
				}
			}
			if(check(honestOrUnkind)) {
				for(int k=0;k<N;k++) {
					if(honestOrUnkind[k]>0) {
						count++;
					}
				}
			}
			max = Math.max(max, count);
		}
		System.out.println(max);
	}
	
	static boolean check(int[] honestOrUnkind) {
		for(int i=0;i<N;i++) {
			if(honestOrUnkind[i]==1) {
				for(int j=0;j<A[i];j++) {
					if(honestOrUnkind[x[i][j]-1]!=y[i][j]) {
						return false;
					}
				}
			}
		}
		return true;
	}
}


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

vector<vector<int> > D(2000, vector<int>(2000, -1));

// Xのi番目以前とYのj番目以前の最長共通部分列の大きさを返す
int lcs(string &X, string &Y, int i, int j)
{
  // メモされているとき
  if (D.at(i).at(j) > -1)
  {
    return D.at(i).at(j);
  }

  // ベースケース
  if (i == 0)
  {
    for (int tmp = 0; tmp <= j; tmp++)
    {
      if (X.at(i) == Y.at(tmp))
      {
        D.at(i).at(j) = 1;
        return 1;
      }
    }
    D.at(i).at(j) = 0;
    return 0;
  }
  if (j == 0)
  {
    for (int tmp = 0; tmp <= i; tmp++)
    {
      if (X.at(tmp) == Y.at(j))
      {
        D.at(i).at(j) = 1;
        return 1;
      }
    }
    D.at(i).at(j) = 0;
    return 0;
  }
  // 再帰ステップ
  int M = 0;
  if (i > 0)
  {
    M = max(M, lcs(X, Y, i - 1, j));
  }
  if (j > 0)
  {
    M = max(M, lcs(X, Y, i, j - 1));
  }
  if ((i > 0 && j > 0) && (X.at(i)) == Y.at(j))
  {
    M = max(M, lcs(X, Y, i - 1, j - 1) + 1);
  }
  D.at(i).at(j) = M;
  return M;
}

int main()
{
  int n;
  cin >> n;
  for (int i = 0; i < n; i++)
  {
    string X, Y;
    cin >> X;
    cin >> Y;
    cout << lcs(X, Y, X.size() - 1, Y.size() - 1) << endl;
    vector<vector<int> > E(2000, vector<int>(2000, -1));
    D = E;
  }
}


Measured memory_bytes: 34620
#include<iostream>
#include<string.h>
#include<queue>
#include<map>
#include<vector>
#include <cstdlib>
#include<algorithm>
#include <cstdio>
#include <cctype>
using namespace std;
const long long INF=10000000000000LL;
typedef long long ll;
typedef pair<ll,ll> P;
ll N,Ma,Mb,K=1,C[45];
ll A[45],B[45];
ll T,a,b;
ll ans=0;
bool h,o;
//bool D[100005];
char str1[55][55],str2[55][55];
map<string,int> m;
vector<int> v[10];
ll dp[45][405][405];
int main(){
	cin>>N>>K>>a>>b;
//	ans+=a;
	if(N<=K)ans=a*N;
	if(N>K)ans+=(N-K)*b+K*a;
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
ll Q=1000000007;

int main(){
  ll x;
  cin >> x;
  ll count = 0;
  if(x%11==0){
    count += (x/11)*2;
    cout << count << endl;
    return 0;
  }else{
    count += (x/11)*2;
    x %= 11;
    x -=6;
    if(x<=0){
      cout << count + 1<<endl;
      return 0;
    }
    cout << count + 2 << endl;
  }
}

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

int main(){
    char a,b;
    cin >> a >> b;
    if(a=='H'){
        cout << b <<endl;
    }else{
        if(b=='H')cout << 'D' << endl;
        else cout << 'H' << endl;
    }
    return 0;
}

Measured memory_bytes: 256
// g++ -std=c++11 a.cpp
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>	
#include<map>
#include<set>
#include<unordered_map>
#include<utility>
#include<cmath>
#include<random>
#include<cstring>
#include<queue>
#include<stack>
#include<bitset>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#include<typeinfo>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define FOR(i,a) for(auto i:a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
#define show1d(v) rep(i,v.size())cout<<" "<<v[i];cout<<endl;
#define show2d(v) rep(i,v.size()){rep(j,v[i].size())cout<<" "<<v[i][j];cout<<endl;}cout<<endl;
using namespace std;
//kaewasuretyuui
typedef long long ll;
//#define int ll
typedef ll Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
//#define mt make_tuple
//typedef tuple<int,int,int> tp;
//typedef vector<tp> vt;
template<typename A,typename B>bool cmin(A &a,const B &b){return a>b?(a=b,true):false;}
template<typename A,typename B>bool cmax(A &a,const B &b){return a<b?(a=b,true):false;}
//template<class C>constexpr int size(const C &c){return (int)c.size();}
//template<class T,size_t N> constexpr int size(const T (&xs)[N])noexcept{return (int)N;}
const double PI=acos(-1);
const double EPS=1e-9;
Def inf = sizeof(Def) == sizeof(long long) ? 2e18 : 1e9+10;
int dx[]={0,1,0,-1};
int dy[]={1,0,-1,0};
class BIT{
	public:
	//[1,i]
	int n;
	vi bit;
//	int bit[MAZ_N+1];
	BIT(int size){
		n=size;
		bit=vi(n+1);
	}
	Def query(int i){//sum
		Def s=0;
		while(i>0){
			s=max(s,bit[i]);
			i-=i&-i;
		}
		return s;
	}
	void add(int i,Def x){
		while(i<=n){
			bit[i]=max(bit[i],x);
			i+=i&-i;
		}
	}
};
int main(){
	ll n;
	cin>>n;
	BIT bit(n);
	rep(i,n){
		int a;cin>>a;
		bit.add(a,bit.query(a)+a);
	}
	cout<<n*(n+1)/2-bit.query(n)<<endl;
}







Measured memory_bytes: 3612
#include <iostream>
#include <vector>
#include <cmath>
#include <deque>
#include <algorithm>
#include <string>
#include <map>
#include <unordered_map>
#include <iomanip>
#include <sstream>
#include <numeric>
using namespace std;
#define ll long long int
#define ld long double
#define vi vector<ll>
#define vvi vector<vi>
#define vs vector<string>
#define pb push_back
#define pf push_front
#define fs first
#define se second
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL);
int main() {
    fastio
    ll n;
    cin>>n;
    string s;
    cin>>s;

    ll sum = 0;
    vvi dp1(3,vi(n,0));

    if(s[n-1]=='R'){
        dp1[0][n-1]++;
    }
    else if(s[n-1]=='G'){
        dp1[1][n-1]++;
    }
    else{
        dp1[2][n-1]++;
    }

    for(ll i=(n-2);i>=0;i--){
        if(s[i]=='R'){
            dp1[0][i]++;
        }
        else if(s[i]=='G'){
            dp1[1][i]++;
        }
        else{
            dp1[2][i]++;
        }
        dp1[0][i] += dp1[0][i+1];
        dp1[1][i] += dp1[1][i+1];
        dp1[2][i] += dp1[2][i+1];
    }

    for(ll i=0;i<(n-2);i++){
        for(ll j=(i+1);j<(n-1);j++){
            if(s[i]!=s[j]){
                ll p = (j-i);
                if((s[i]=='R' && s[j]=='G')||s[i]=='G' && s[j]=='R'){
                    ll t = dp1[2][j+1];
                    if((j+p)<n && s[j+p]=='B'){
                        t--;
                    }
                    sum += t;
                }
                if((s[i]=='G' && s[j]=='B')||s[i]=='B' && s[j]=='G'){
                    ll t = dp1[0][j+1];
                    if((j+p)<n && s[j+p]=='R'){
                        t--;
                    }
                    sum += t;
                }
                if((s[i]=='R' && s[j]=='B')||s[i]=='B' && s[j]=='R'){
                    ll t = dp1[1][j+1];
                    if((j+p)<n && s[j+p]=='G'){
                        t--;
                    }
                    sum += t;
                }
            }
        }
    }
    cout<<sum<<endl;
}


Measured memory_bytes: 3308
#include <stdio.h>

int main(void)
{
    long s=0;
    int n,a,i;
    scanf("%d",&n);
    s-=n;
    for(i=0;i<n;i++){
        scanf("%d",&a);
        s+=a;
    }
    printf("%d\n",s);
    return 0;
}

Measured memory_bytes: 128
import java.util.*;
 
class Main{
  public static void main(String[] args){
    Scanner scan=new Scanner(System.in);
    int kind=scan.nextInt();
    int cho=scan.nextInt();
    PriorityQueue in=new PriorityQueue();
    int full=0;
    for(int a=0; a<kind; a++){
      int input=scan.nextInt();
      full+=input;
      in.offer(input);
    }
    int ans=0;
    for(int a=kind; a>=cho; a--){
      ans=(int)in.poll();
    }
    if(full/(4.0*cho)<=ans){
      System.out.println("Yes");
    }else{
      System.out.println("No");
    }
  }
}

Measured memory_bytes: 21460
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<map>
#define ll long long
using namespace std;
int t;
ll n,a,b,c,d,f[100005];
map<ll,ll>mp;
ll dfs(ll n)
{
	if(!n)return 0;
	if(mp[n])return mp[n];
	mp[n]=1e18;
	mp[n]=min(mp[n],dfs(n/2)+min(a+(n%2)*d,(n-n/2<=1e9?(n-n/2)*d:1000000000000000000)));
	mp[n]=min(mp[n],dfs(n/3)+min(b+(n%3)*d,(n-n/3<=1e9?(n-n/3)*d:1000000000000000000)));
	mp[n]=min(mp[n],dfs(n/5)+min(c+(n%5)*d,(n-n/5<=1e9?(n-n/5)*d:1000000000000000000)));
	mp[n]=min(mp[n],dfs(n/2+1)+min(a+(2-n%2)*d,(n-n/2-1<=1e9?(n-n/2-1)*d:1000000000000000000)));
	mp[n]=min(mp[n],dfs(n/3+1)+min(b+(3-n%3)*d,(n-n/3-1<=1e9?(n-n/3-1)*d:1000000000000000000)));
	mp[n]=min(mp[n],dfs(n/5+1)+min(c+(5-n%5)*d,(n-n/5-1<=1e9?(n-n/5-1)*d:1000000000000000000)));
//	printf("f[%lld]=%lld\n",n,mp[n]);
	return mp[n];
}
int main()
{
	scanf("%d",&t);
	while(t--)
	{
		scanf("%lld%lld%lld%lld%lld",&n,&a,&b,&c,&d);
		mp.clear();
		printf("%lld\n",dfs(n));
	}
	return 0;
}

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

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

  int a, b, h;
  cin >> a >> b >> h;

  cout << (a + b) * h / 2 << endl;

  return (0);
}


Measured memory_bytes: 3516
import java.util.ArrayList;
import java.util.Scanner;

public class Main{
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        long lNmb = 0;
        long n = in.nextLong();

        ArrayList<Long> lucasNumbers = new ArrayList<>();
        lucasNumbers.add(0, (long) 2);
        lucasNumbers.add(1, (long) 1);

        if(n >= 2){
            for(int x = 2; x <= n; x++){
                lucasNumbers.add(x, lucasNumbers.get(x - 2) + lucasNumbers.get(x - 1));
                lNmb = lucasNumbers.get(lucasNumbers.size() - 1);
            }
        } else if(n == 0) lNmb = 2;
        else if(n == 1) lNmb = 1;

        System.out.println(lNmb);
    }
}

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

typedef long long ll;
typedef vector<ll> vint;
typedef vector< vector<ll> > vvint;

#define rep(i,n) for(ll i=0;i<n;i++)
#define repf(i,f,n) for(ll i=f;i<n;i++)
#define repr(i,n) for(ll i=n-1;i>=0;i--)
#define mp make_pair
#define mt make_tuple
#define ALL(obj) (obj).begin(), (obj).end()
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

int dy[]={0, 0, 1, -1, 1, -1, -1, 1};
int dx[]={1, -1, 0, 0, 1, 1, -1, -1};


int main() {
    cout<<fixed<<setprecision(10);


    ll x,n; cin>>x>>n;
    vint p(n); rep(i,n) cin>>p[i];

    ll ans = 0;
    ll div = LLONG_MAX;

    set<ll> s;
    for(auto e:p) s.insert(e);

    repr(i, 100+2){
        if(s.count(i)) continue;
        if(abs(i-x) <= div){
            div = abs(i-x);
            ans = i;
        }
    }

    cout<<ans<<endl;

    return 0;

}


Measured memory_bytes: 3628