akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef pair<ll, P> PP;

static const double EPS = 1e-8;
static const double PI = 4.0 * atan(1.0);
static const ll INF = 1023456789;

#define REP(i,n)	for(int i=0;i<n;++i)
#define REPR(i,n)	for(int i=n-1;i>=0;--i)
#define FOR(i,s,n)	for(int i=s;i<n;++i)
#define FORR(i,s,n)	for(int i=n-1;i>=s;--i)
#define ALL(c)		(c).begin(),(c).end()
#define CLEAR(v)	memset(v,0,sizeof(v))
#define MP(a,b)		make_pair((a),(b))
#define ABS(a)		((a)>0?(a):-(a))
#define F			first
#define S			second

int main(int argc, char **argv) {
	ll x;
	REP(i, 5) {
		cin >> x;
		if (x == 0) {
			cout << (i+1) << endl;
			return 0;
		}
	}
	return 0;
}


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

const int MAXN = 200010;
typedef long long LL;
typedef std::vector<LL> V;
V operator + (V a, V b) {
	for (int i = 0; i != 26; ++i) a[i] += b[i];
	return a;
}
struct item {
	V a; char * s;
	item * l, * r; LL L;
	item() { a = V(26, 0); s = NULL, l = r = NULL; L = 0; }
	V qry(LL rr) {
		assert(rr <= L);
		if (s != NULL) {
			V res(26, 0);
			for (int i = 0; i != rr; ++i) ++res[s[i] - 'a'];
			return res;
		} else {
			if (rr <= l->L) return l->qry(rr);
			return l->a + r->qry(rr - l->L);
		}
	}
} is[100];
char buf[MAXN]; int n, fail[MAXN];
char s1[MAXN], s2[MAXN];
LL ansl[MAXN];
int main() {
	std::ios_base::sync_with_stdio(false), std::cin.tie(0);
	std::cin >> buf + 1; n = strlen(buf + 1) / 2;
	for (int i = 1; i <= n; ++i) {
		int now = fail[i - 1];
		while (now && buf[now + 1] != buf[i]) now = fail[now];
		++now, fail[i] = now != i && buf[now] == buf[i] ? now : 0;
	}
	int tl = n - fail[n];
	std::copy(buf + 1, buf + 1 + n, s2);
	std::copy(buf + 1, buf + 1 + tl, s1);
	is[0].L = tl, is[0].s = s1, is[1].L = n, is[1].s = s2;
	is[0].a = is[0].qry(is[0].L);
	is[1].a = is[1].qry(is[1].L);
	LL L, R; std::cin >> L >> R;
	int cur = 1;
	while (is[cur].L < R) {
		++cur;
		is[cur].a = is[cur - 1].a + is[cur - 2].a;
		is[cur].L = is[cur - 1].L + is[cur - 2].L;
		is[cur].l = &is[cur - 1], is[cur].r = &is[cur - 2];
	}
	V aa = is[cur].qry(R);
	V ab = L > 1 ? is[cur].qry(L - 1) : V(26, 0);
	for (int i = 0; i < 26; ++i) std::cout << aa[i] - ab[i] << ' ';
	return 0;
}


Measured memory_bytes: 1152
//#pragma GCC optimize ("O3")
//#pragma GCC target ("tune=native")
//#pragma GCC target ("avx")
//#include <bits/stdc++.h>
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <iostream>
#include <sstream>
#include <functional>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <string>
#include <cstring>
#include <vector>
#include <queue>
#include <stack>
#include <deque>
#include <list>
#include <numeric>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll,ll> P;
typedef pair<P,ll> PPI;
typedef pair<ll,P> PIP;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<P> vp;
#define PQ(T) priority_queue<T,vector<T>,greater<T>>
#define PQ2(T) priority_queue<T>
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const ll INF = 1LL<<29;
const ll mod = 1e9+7;
#define REP(i,a,b) for(ll (i)=a;(i)<(ll)(b);++(i))
#define rep(i,n) REP(i,0,n)
#define rep1(i,n) REP(i,1,n+1)
#define repd(i,n,d) for(ll (i)=0;(i)<(ll)(n);(i)+=(d))
#define all(v) (v).begin(), (v).end()
#define pb(x) push_back(x)
#define mp(x,y) make_pair((x),(y))
#define mset(m,v) memset((m),(v),sizeof(m))
#define chmin(x,y) ((x)=min((x),(y)))
#define chmax(x,y) ((x)=max((x),(y)))
#define fst first
#define snd second
#define UNIQUE(x) (x).erase(unique(all(x)),(x).end())
#define DEBUG(x) cerr<<"line ("<<__LINE__<<")  "<<#x<<": "<<x<<endl;
template<class T> ostream &operator<<(ostream &os, const vector<T> &v){int n=v.size();rep(i,n)os<<v[i]<<(i==n-1?"":" ");return os;}
#define INIT std::ios::sync_with_stdio(false);std::cin.tie(0);

ll a[3][100];

ll f(ll x, ll y){
	ll s = 0;
	if(x%2!=y%2){
		y++;
		s++;
	}
	if(x<y) s += (y-x)/2;
	else s += x-y;
	return s;
}
int main(){
	rep(i, 3){
		ll x;
		cin>>x;
		rep(j, 60) a[i][j] = f(x, j);
	}
	ll res = INF;
	rep(j, 60){
		ll r = 0;
		rep(i, 3) r += a[i][j];
		chmin(res, r);
	}
	cout<<res<<endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template<typename T> using Graph = vector<vector<T>>;

#define REP(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, a) REP(i, 0, a)
#define EACH(i, a) for (auto i: a)
#define ITR(x, a) for (__typeof(a.begin()) x = a.begin(); x != a.end(); x++)
#define ALL(a) (a.begin()), (a.end())
#define HAS(a, x) (a.find(x) != a.end())
#define endl '\n'

int N;
ll A, B;
ll h[100005];

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

  cin >> N >> A >> B;
  rep(i, N) cin >> h[i];

  ll D = A - B;

  ll lo = 0, hi = 1000000000;
  while (hi - lo > 0) {
    ll mi = (hi + lo)/2;
    ll cnt = 0;
    rep(i, N) {
      ll r = h[i] - mi*B;
      if (r > 0) cnt += (r + D - 1)/D;
    }          

    if (cnt <= mi) {
        hi = mi;
    } else {
        lo = mi + 1;
    }
  }

  cout << hi << endl;

  return 0;
}


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

static const double eps = 1e-8;

struct Point {
  double x, y;

  Point() {}
  Point(double x, double y): x(x), y(y) {}

  double distance(Point rhs) {
    return sqrt((x - rhs.x) * (x - rhs.x) + (y - rhs.y) * (y - rhs.y));
  }
};

struct Line {
  double a, b, c;

  double distance(Point point) {
    return fabs(a * point.x + b * point.y + c) / sqrt(a * a + b * b);
  }
};

struct Circle {
  Point center;
  double radius;

  Circle() {}

  vector<Point> intersection(Line line) {
    vector<Point> intersections;
    double dist = line.distance(center);
    if (dist < radius + eps) {
      double x = (-line.a * line.c + line.b * line.b * center.x - line.a * line.b * center.y) / (line.a * line.a + line.b * line.b);
      double y = (-line.b * line.c - line.a * line.b * center.x + line.a * line.a * center.y) / (line.a * line.a + line.b * line.b);
      if (dist > radius - eps) {
        intersections.emplace_back(Point(x, y));
      }
      else {
        double t = sqrt(radius * radius - dist * dist) / sqrt(line.a * line.a + line.b * line.b);
        intersections.emplace_back(Point(x - line.b * t, y + line.a * t));
        intersections.emplace_back(Point(x + line.b * t, y - line.a * t));
      }
    }

    return intersections;  
  }

  vector<Point> intersection(Circle rhs) {
    Line line;
    line.a = 2 * (center.x - rhs.center.x);
    line.b = 2 * (center.y - rhs.center.y);
    line.c = rhs.center.x * rhs.center.x - center.x * center.x + rhs.center.y * rhs.center.y - center.y * center.y + radius * radius - rhs.radius * rhs.radius;
    return intersection(line);
  }
};

int main() {
  int n, k;
  scanf("%d %d", &n, &k);
  vector<int> x(n), y(n), c(n);
  for (int i = 0; i < n; i++)
    scanf("%d %d %d", &x[i], &y[i], &c[i]);

  double l = 0, r = 1e9;
  for (int iter = 0; iter < 150; iter++) {
    double m = (l + r) / 2;
    
    vector<Circle> circles(n);
    for (int i = 0; i < n; i++) {
      circles[i].center = Point(x[i], y[i]);
      circles[i].radius = m / c[i];
    }

    vector<Point> candidates; 
    for (int i = 0; i < n; i++) {
      candidates.emplace_back(circles[i].center);
      for (int j = i + 1; j < n; j++) {
        auto intersections = circles[i].intersection(circles[j]);
        for (auto intersection : intersections)
          candidates.emplace_back(intersection);
      }
    }

    bool found = false;
    for (auto candidate : candidates) {
      int count = 0;
      for (int i = 0; i < circles.size(); i++) {
        double d = candidate.distance(circles[i].center);
        if (d < circles[i].radius + eps) {
          count++;
        }
      }

      if (count >= k) {
        found = true;
        break;
      }
    }

    if (found)
      r = m;
    else
      l = m;
  }
  printf("%.6lf\n", l);

  return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<queue>
using namespace std;

const int maxn=100;
const int maxm=1000;
const int inf=100000008;


int n,m,c,u,v,p,en;
int s[maxn+10],inq[maxn+10],dis[maxn+10][maxn+10];

struct edge{
	int u,v,l,nxt;
}es[maxm+10];

void add_edge(int u,int v,int p){
	es[++en].u=u;
	es[en].v=v;
	es[en].l=p;
	es[en].nxt=s[u];
	s[u]=en;
}
void spfa(int a){
	for(int i=1;i<=n;i++) dis[i][0]=inf;
	memset(inq,0,sizeof(inq));
	queue<int> q;
	dis[1][0]=0;
	inq[1]=1;
	q.push(1);
	while(!q.empty()){
		int p=q.front();
		for(int i=s[p];i;i=es[i].nxt)
			if(dis[p][0]+es[i].l<dis[es[i].v][0]){
				dis[es[i].v][0]=dis[p][0]+es[i].l;
				if(!inq[es[i].v]){
					inq[es[i].v]=1;
					q.push(es[i].v);
				}
			}
		q.pop();
		inq[p]=0;
	}
}

void spf(int a,int d){
	for(int i=1;i<=n;i++) dis[i][d]=inf;
	memset(inq,0,sizeof(inq));
	queue<int> q;
	for(int i=1;i<=en;i++)
		if(dis[es[i].u][d-1]<dis[es[i].v][d]){
			dis[es[i].v][d]=dis[es[i].u][d-1];
			if(!inq[es[i].v]){
				inq[es[i].v]=1;
				q.push(es[i].v);
			}
		}
	while(!q.empty()){
		int p=q.front();
		for(int i=s[p];i;i=es[i].nxt)
			if(dis[p][d]+es[i].l<dis[es[i].v][d]){
				dis[es[i].v][d]=dis[p][d]+es[i].l;
				if(!inq[es[i].v]){
					inq[es[i].v]=1;
					q.push(es[i].v);
				}
			}
		q.pop();
		inq[p]=0;
	}
}

int main(){
	scanf("%d%d%d",&n,&m,&c);
	while(n+m+c){
		en=0;
		memset(s,0,sizeof(s));
		for(int i=0;i<m;i++){
			scanf("%d%d%d",&u,&v,&p);
			add_edge(u,v,p);
		}
		int ans=0;
		spfa(1);
		while(dis[n][ans]>c)
			spf(1,++ans);
		printf("%d\n",ans);
		scanf("%d%d%d",&n,&m,&c);
	}
	return 0;
}

Measured memory_bytes: 1100
// ALDS1_10_C
#include <bits/stdc++.h>
#define endl "\n"
#define _GLIBCXX_DEBUG //配列外参照エラー表示,gcc依存
#define rep(i,n) for(int i=0;i<int(n);i++)
#define SZ(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> ipair;
template <class T>ostream &operator<<(ostream &o,const vector<T>&v)
{o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}
namespace you {
    std::string to_string(char val) {
        return std::string(1, val);
        // return std::string{val};
        // you::to_string(char)
    }
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(12);

    int q;
    cin>>q;
    rep(i,q){
        string a,b;
        cin>>a>>b;
        int la=a.size(),lb=b.size();
        vector<vector<int>> dp(la+10,vector<int>(lb+10,0));
        for(int i=1;i<=la;i++){
            for(int j=1;j<=lb;j++){
                if(a[i-1]==b[j-1]) dp[i][j]=max({dp[i-1][j-1]+1,dp[i-1][j],dp[i][j-1]});
                else dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
            }
        }
        cout<<dp[la][lb]<<endl;
    } 
    return 0;
}


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

int main() {
	int s;
	cin >> s;
	vector<int>a;
	vector<int>a1;
	a.push_back(s);

	int index = 1;
	bool flag = false;
	while (1) {
		if (a[index - 1] % 2 == 0) {
			a.push_back(a[index - 1] / 2);
		}
		else {
			a.push_back(a[index - 1] * 3 + 1);
		}
		a1 = a;
		sort(a1.begin(),a1.end());
		for (int i = 1; i < a1.size(); i++) {
			if (a1[i - 1] == a1[i]) {
				flag = true;
				break;
			}
		}
		if (flag == true) {
			break;
		}
		index++;
	}
	cout << index+1 << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<n; i++)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
long long mo = 1e9 + 7;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
template<class A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}cout << "\n";}

int main(){
    ll N,M;
    string S,T;
    cin >> N >> M;
    vector<ll> k(M), p(M);
    vector<vector<ll>> s(M, vector<ll>(10));
    rep(i,M){
        cin >> k[i];
        rep(j,k[i]){
            cin >> s[i][j];
        }
    }
    rep(i,M){
        cin >> p[i];
    }
    ll ans = 0;
    for(ll i=0;i<(ll(1)<< N);i++){
        bool flag = true; 
        rep(j,M){
            ll cnt = 0;
            rep(m,k[j]){
                if(((i>>(s[j][m]-1))&ll(1))){
                    cnt++;
                }
            }
            //cout << cnt << endl;
            if(cnt % 2 != p[j]){
                flag = false;
                break;
            }
        }
        //cout << flag << endl;
        if(flag) ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <cmath>
#include <iostream>
#include <vector>

using namespace std;
using ll = long long;

int main() {
  ll n;
  cin >> n;
  n = n - 1;

  vector<char> vec;
  while (0 <= n || vec.empty()) {
    vec.push_back('a' + (n) % 26);
    n = n / 26 - 1;
  }

  for (auto itr = vec.rbegin(); itr != vec.rend(); ++itr)
    cout << *itr;
  cout << endl;
}

Measured memory_bytes: 3628
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
#define fr(i,n) for(int i=0;i<(n);++i)
#define Fr(i,n) for(int i=1;i<=(n);++i)
#define ifr(i,n) for(int i=(n)-1;i>=0;--i)
#define iFr(i,n) for(int i=(n);i>0;--i)

template<class T> struct STree{
    int n;
    T e;
    vector<T> dat;

    inline T f(T x,T y){
        return x+y;
    }

    STree() = default;

    void ST(int n_,T e_){
        n=1;e=e_;
        while(n<n_) n<<=1;
        dat.resize((n<<1),e);
    }

    void ud(int k,T c){
        k+=n;
        dat[k]=c;
        while(k){
            dat[k>>1]=f(dat[k],dat[k^1]);
            k>>=1;
        }
    }

    T gt(int l,int r){
        l+=n;r+=n;
        T s=e;
        while(l<r){
            if(r&1){
                --r;
                s=f(s,dat[r]);
            }
            if(l&1){
                s=f(s,dat[l]);
                ++l;
            }
            l>>=1,r>>=1;
        }
        return s;
    }

    T operator[](int i){return dat[i+n];}
};

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    istream& in(cin);
    ostream& out(cout);
    int n,q,f,l,r,j;
    char c;
    string s;
    in>>n>>s>>q;
    vector<STree<int>> st(26);
    fr(i,26) st[i].ST(n,0);
    fr(i,n){
        st[s[i]-'a'].ud(i,1);
    }
    fr(_,q){
        in>>f;
        if(f-1){
            in>>l>>r;
            --l;
            int ans{};
            fr(i,26) if(st[i].gt(l,r)) ++ans;
            cout<<ans<<endl;
        }
        else{
            in>>j>>c;
            --j;
            st[s[j]-'a'].ud(j,0);
            st[c-'a'].ud(j,1);
            s[j]=c;
        }
    }
}

Measured memory_bytes: 107548
<?php
//error_reporting(0);
//$S = trim(fgets(STDIN));
//list($n,$m,$d) = explode(" ",trim(fgets(STDIN)));
$a = explode(" ",trim(fgets(STDIN)));

sort($a);
printf("%d\n",abs($a[2]-$a[1])+abs($a[1]-$a[0]));


Measured memory_bytes: 3828
#include <iostream>
#include <algorithm>
using namespace std;
int main() {
	int a, b, c, k;
	cin >> a >> b >> c >> k;
	for (int i = 0; i < k; i++) {
		if (a < b) swap(a, b);
		if (a < c)swap(a, c);
		if (a < b)swap(b, c);
		a = a * 2;
	}
	cout << a + b + c << endl;
	int x;
	cin >>x;
	return 0;
}

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

using namespace std;

const int INF = 0x3f3f3f3f;
int n, maxn1, maxn2, minn1 = INF, minn2 = INF, x, y;

int main() {
	scanf("%d", &n);
	while (n--) {
		scanf("%d%d", &x, &y);
		y += x;
		if (maxn1 < y) maxn1 = y;
		if (minn1 > y) minn1 = y;
		y -= x * 2;
		if (maxn2 < y) maxn2 = y;
		if (minn2 > y) minn2 = y;
	}
	printf("%d\n", max(maxn1 - minn1, maxn2 - minn2));
	return 0;
}


Measured memory_bytes: 3824
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <bitset>
#include <math.h>
#include <iomanip>
#include <queue>
#include <map>
#define inp(X) cin >> X
#define out(X) cout << X << endl
#define out16(X) cout << setprecision(16) << X << endl
#define rep(i,n) for(int i=0;i<n;i++ )
#define rep2(i,f,n) for(int i=f;i<n;i++ )
#define MAX(A) *max_element(A.begin(),A.end())
#define MIN(A) *min_element(A.begin(),A.end())
#define SORT(A) sort(A.begin(),A.end())
#define REV(A) reverse(A.begin(),A.end())
typedef long long int ll;
using vi = std::vector<int>;
using vvi = std::vector<std::vector<int>>;
using vd = std::vector<double>;
using vvd = std::vector<std::vector<double>>;
using vll = std::vector<ll>;
using vvll = std::vector<std::vector<ll>>;
using namespace std;
#define MOD 1000000007
#define INF 1000000001
#define LL_INF 1001001001001001001

ll gcd(ll x, ll y){
	if(y==0) return x;
	return gcd(y,x%y);
}

bool bfs(vector<vector<int>> g, vector<int> &color, int sv){
	queue<int> q;
	q.push(sv);
	color[sv]=1;
	while(!q.empty()){
		int now = q.front(); q.pop();
		for(auto v : g[now]){
			if(color[v]!=-1) continue;

			q.push(v);
		}
	}
}

int main(void) {
	int n; cin >> n;
	vvi g(n);
	map<pair<int,int>,int> edge;
	rep(i,n-1){
		int a,b; cin >> a >> b;
		--a; --b;
		g[a].push_back(b);
		g[b].push_back(a);
		pair<int,int> p;
		p.first=min(a,b); p.second=max(a,b);
		edge[p] = i;
	}
	vi color(n-1,-1);
	vi rt(n);
	
	queue<int> q;
	q.push(0);
	while(!q.empty()){
		////nowからの枝について開始する
		int now = q.front(); q.pop();
		int cnt = 0;
		pair<int,int> pr; pr.first=min(now,rt[now]); pr.second=max(now,rt[now]);
		int rtcolor = color[edge[pr]];
		for(auto v : g[now]){
			pair<int,int> p; p.first=min(now,v); p.second=max(now,v);
			if(color[edge[p]]!=-1) continue;
			++cnt;
			if(cnt==rtcolor) cnt++;
			color[edge[p]] = cnt;
			rt[v] = now;
			q.push(v);
		}
	}	
	
	//出力
	out(MAX(color));
	rep(i,n-1) out(color[i]);
	
}




Measured memory_bytes: 13056
#include<iostream>
#define ll long long int
using namespace std;
#include<math.h>
#include<bits/stdc++.h>
ll min(ll a,ll b)
{
  return a < b ? a : b;
}
int main()
{
  ll n;
  cin >> n;
  ll a[n];
  for(ll i = 0;i < n;i++)
   	cin >> a[i];
  ll ans[n];
  ans[0] = 0;
  ans[1] = abs(a[0] - a[1]);
  for(int i = 2;i < n;i++)
  {
  	ans[i] = min(abs(a[i]-a[i-1]) + ans[i-1], abs(a[i] - a[i-2]) + ans[i-2]);
  }
  
cout << ans[n-1];

 	return 0;
}


Measured memory_bytes: 1792
#include<algorithm>
#include<cstdio>
#include<iostream>
#include<cstring>
#include<cmath>
#include<map>
#include<queue>
#include<set>
#include<sstream>
#include<stack>
#include<string>
#include<vector>
using namespace std;
int n,a[10100],cnt;
int main(){
	cin>>n;
	for(int i=1;i<=n;i++){
		cin>>a[i];
		while(a[i]%2==0){
			cnt++;
			a[i]/=2;
		}
	}
	cout<<cnt;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<bits/stdc++.h>
#include<cmath>
#include<bitset>
#include<queue>
#define ll long long
#define itn int
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define FFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define RREP(i,n)  FFOR(i,1,n)
#define SORT(V) sort((V).begin(),(V).end())
#define REVERSE(V) reverse((V).begin(),(V).end())
#define INF ((1LL<<62)-(1LL<<31))
#define MOD 1000000007
using namespace std;

int main(){
  ll N,K,ans=INF;
  cin>>N>>K;
  ll X[N];
  REP(i,N) cin>>X[i];
  
  for(int i=0; i<=N-K; ++i){
    if(X[i+K-1]*X[i]>=0) ans=min(ans,max(abs(X[i+K-1]),abs(X[i])));
    else ans=min(ans,X[i+K-1]-X[i]+min(abs(X[i+K-1]),abs(X[i])));
  }
  
  cout<<ans<<endl;
}


Measured memory_bytes: 1024
#include<cstdio>
#include<algorithm>
#define fo(i,a,b) for(i=a;i<=b;i++)
using namespace std;
typedef long long ll;
const int mo=1000000007;
bool bz[15+5][15+5];
int two[300],id[1<<17];
int f[15+5][1<<17],g[15+5][1<<17],dp[1<<17];
int i,j,k,l,r,s,t,n,m,ans;
int lowbit(int x){
	return x&-x;
}
int main(){
	scanf("%d%d",&n,&m);
	fo(i,1,n) id[1<<(i-1)]=i;
	two[0]=1;
	fo(i,1,m) two[i]=(ll)two[i-1]*2%mo;
	fo(i,1,m){
		scanf("%d%d",&j,&k);
		bz[j][k]=1;
	}
	fo(i,1,n)
		fo(s,1,(1<<n)-1)
			f[i][s]=f[i][s-lowbit(s)]+bz[i][id[lowbit(s)]];
	fo(i,1,n)
		fo(s,1,(1<<n)-1){
			k=id[lowbit(s)];
			if (!bz[i][k]) g[i][s]=g[i][s-lowbit(s)];
			else g[i][s]=((ll)g[i][s-lowbit(s)]*2%mo+1)%mo;
		}
	fo(s,1,(1<<n)-1){
		//if (!((s&1)&&(s&2))) continue;
		dp[s]=1;
		t=(s-1)&s;
		while (t){
			if (((s^t)&1)&&(t&2)){
				t=(t-1)&s;
				continue;
			}
			if (((s^t)&2)&&(t&1)){
				t=(t-1)&s;
				continue;
			}
			r=1;
			fo(i,1,n)
				if ((t&(1<<(i-1)))) r=(ll)r*g[i][s^t]%mo;
			l=0;
			fo(i,1,n)
				if (((s^t)&(1<<(i-1)))) l+=f[i][t];
			r=(ll)r*two[l]%mo;
			(dp[s]+=(ll)dp[t]*r%mo)%=mo;
			t=(t-1)&s;
		}
	}
	ans=(two[m]-dp[(1<<n)-1])%mo;
	(ans+=mo)%=mo;
	printf("%d\n",ans);
}

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

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

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

//繰り返し二乗法
ll mod_pow(ll a, ll n, ll m) {
	ll res = 1;
	while (n) {
		if (n & 1)res = res * a%m;
		a = a * a%m; n >>= 1;
	}
	return res;
}

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

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

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

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




void solve() {
    int n; cin >> n;
    cout << "ABC" << n << endl;
}

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


Measured memory_bytes: 7716
#include <stdio.h>
int main(){
  int i,j,n,x,y;
  while (scanf("%d",&n)){
    if (n==0)
      break;
    int data[n][n],cnt=1;;
    for (i=0;i<n;i++)
      for (j=0;j<n;j++)
        data[i][j]=0;
    x=n/2;
    y=n/2+1;
    data[y][x]=cnt++;
    while (cnt<=n*n){
      x++;y++;
      while (data[y][x]!=0 || x<0 || x>=n || y>=n){
        if (x>=n)
          x=0;
        else if (x<0)
          x=n-1;
        if (y>=n)
          y=0;
        if (data[y][x]!=0){
          x--;y++;
        }
      }
      data[y][x]=cnt++;
    }

    for (i=0;i<n;i++){
      for (j=0;j<n;j++)
        printf("%4d",data[i][j]);
      printf("\n");
    }
  }

  return 0;
}

Measured memory_bytes: 616
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int mod=1e9+7;
int dp[10002][102][2];
string s;
int d;
int fun(int idx,int cur,bool gr)
{
    if(idx==s.size()) return !cur;
    int &ret=dp[idx][cur][gr];
    if(~ret)
        return ret;
        ret=0;
    if(!gr)
    {
        for(int i=0;i<s[idx]-'0';i++)
            ret+=fun(idx+1,(cur+i)%d,1)%mod;
        ret+=fun(idx+1,(cur+s[idx]-'0')%d,0)%mod;
    }
    else
    {
        for(int i=0;i<=9;i++)
            ret+=fun(idx+1,(cur+i)%d,1)%mod;
    }
    ret%=mod;
    return ret;
}
signed main()
{
    memset(dp,-1,sizeof dp);
    cin>>s>>d;
    cout<<(fun(0,0,0)+mod-1)%mod<<endl;
}


Measured memory_bytes: 20348
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;

namespace ConsoleApp1
{
    internal class Program
    {
        static void Main(string[] args)
        {
            var tmp = Console.ReadLine().Split(' ');
            var x = int.Parse(tmp[0]);
            var y = int.Parse(tmp[1]);
            var z = int.Parse(tmp[2]);
            var k = int.Parse(tmp[3]);

            var As = Console.ReadLine().Split(' ').Select(d=> long.Parse(d)).ToArray();
            var Bs = Console.ReadLine().Split(' ').Select(d => long.Parse(d)).ToArray();
            var Cs = Console.ReadLine().Split(' ').Select(d => long.Parse(d)).ToArray();

            //As = As.OrderByDescending(d => d).ToArray();
            //Bs = Bs.OrderByDescending(d => d).ToArray();
            //Cs = Cs.OrderByDescending(d => d).ToArray();

            ReverseSort(As);
            ReverseSort(Bs);
            ReverseSort(Cs);

            var ee = new long[Math.Min(x,k) * Math.Min(y, k)];
            var cnt1 = 0;
            foreach(var a in As.Take(k))
            {
                foreach(var b in Bs.Take(k))
                {
                    ee[cnt1] = a + b;
                    cnt1 ++;
                }
            }

            ReverseSort(ee);
            var ans = new long[Math.Min(ee.Length, k) * Math.Min(k,z)];
            var cnt2 = 0;
            foreach (var e in ee.Take(k))
            {
                foreach(var c in Cs.Take(k))
                {
                    ans[cnt2] = e + c;
                    cnt2++;
                }
            }
            ReverseSort(ans);
            foreach (var a in ans.Take(k))
            {
                Console.WriteLine(a);
            }
        }

        static void ReverseSort<T>(T[] items)
        {
            Array.Sort<T>(items);
            Array.Reverse(items);
        }

    }
}


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

using namespace std;

class Cal {
public:
	Cal(int num1, int num2, int num3) {
		CaNum1 = num1;
		CaM = num2;
		CaNum2 = num3;
	}
	void Result();
private:
	int add() { return CaNum1 + CaNum2; };
	int sub() { return CaNum1 - CaNum2; };
	int CaNum1, CaNum2, CaM;
};

void Cal::Result() {
	switch (CaM)
	{
	case '+':
		printf("%d", add());
		break;
	case '-':
		printf("%d", sub());
		break;
	default:
		break;
	}
	return;
}

int takeNum(int num) {
	switch (num)
	{
	case '0':
		return 0;
	case '1':
		return 1;
	case '2':
		return 2;
	case '3':
		return 3;
	case '4':
		return 4;
	case '5':
		return 5;
	case '6':
		return 6;
	case '7':
		return 7;
	case '8':
		return 8;
	case '9':
		return 9;
	default:
		return 0;
		break;
	}
	return 0;
}

int main(void) {
	string str;
	int i = 0;
	bool boo = false;
	int buf[3] = { 0,'+',0 };
	int p = 0;
	int mar = 1;
	getline(cin, str);

	while (str[i] != '\0') {
		if ('0' <= str[i] && str[i] <= '9') {

			buf[p] = (buf[p] * 10) + takeNum(str[i]);
		}
		else if ('-' == str[i] || '+' == str[i]) {
			p++;
			buf[p] = (int)str[i];
			p++;
		}
		i++;
	}

	Cal myCal1{buf[0], buf[1], buf[2]};

	myCal1.Result();
	return 0;
}

Measured memory_bytes: 256
#include<map>
#include<set>
#include<list>
#include<cmath>
#include<queue>
#include<stack>
#include<cstdio>
#include<string>
#include<vector>
#include<complex>
#include<cstdlib>
#include<cstring>
#include<climits>
#include<numeric>
#include<sstream>
#include<iostream>
#include<algorithm>
#include<functional>

using namespace std;

int main(){
	int n;
	int ans=100000;
	cin >> n;
	for(int i=0;i<n;i++){
		ans*=1.05;
		if(ans%1000 != 0){
			ans+=1000;
			ans-=ans%1000;
		}
	}
	cout << ans << endl;
}

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

int main() {
  int n, m, a[50], b[50], c[50], d[50];
  scanf("%d %d", &n, &m);
  for(int i = 0; i < n; i++) scanf("%d %d", &a[i], &b[i]);
  for(int i = 0; i < m; i++) scanf("%d %d", &c[i], &d[i]);
  for(int i = 0; i < n; i++) {
    int o = 1001001001, e;
    for(int j = m - 1; j >= 0; j--) {
      if(o >= abs(a[i] - c[j]) + abs(b[i] - d[j])) {
        o = abs(a[i] - c[j]) + abs(b[i] - d[j]);
        e = j + 1;
      }
    }
    printf("%d\n", e);
  }
}

Measured memory_bytes: 256
import numpy as np

num, k = map(int,input().split())

count = 0.

for i in range(1,num+1):
    if i <= k-1:
        times = np.log2(k/i)
        if times != int(times):
            times = int(times) +1
        else:
            times = int(times)
        count += (1/num) * (1/2)**times
    elif i >= k:
        count += 1/num
print(count)




Measured memory_bytes: 19984
n = int(input())
numbers = [int(n) for n in input().split()]
res = 1
numbers.sort()
printou = False
for i in numbers:
	if(i == 0):
		print(0)
		printou = True
		break
	res *= i
	if(res > 1000000000000000000):
		print(-1)
		printou = True
		break

if not printou:
	print(res)



Measured memory_bytes: 84956
#include<iostream>
#include<vector>

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

using namespace std;

struct Edge{
  int a;
  int b;
  int c;
};


int main(){
  int N, M;
  cin >> N >> M;
  vector<Edge> v(M);
  REP (i, 0, M) {
    cin >> v[i].a >> v[i].b >> v[i].c;
    v[i].a--;
    v[i].b--;
  }

  vector<vector<int> > w(N, vector<int>(N, 1 << 28));
  REP (i, 0, N) w[i][i] = 0;
  REP (i, 0, M) {
    w[v[i].a][v[i].b] = v[i].c;
    w[v[i].b][v[i].a] = v[i].c;
  }
  
  
  REP (k, 0, N) {
    REP (i, 0, N) {
      REP (j, 0, N) {
	w[i][j] = min(w[i][j], w[i][k] + w[k][j]);
      }   
    }
  }

  int ans = 0;
  REP (i, 0, M) {
    if (w[v[i].a][v[i].b] != v[i].c) ans++;
  }

  cout << ans << endl;
  
  return 0;
}


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

int main() {
	int a, b;
	cin >> a >> b;
	if (a <= 0 && 0 <= b) cout << "Zero" << endl;
	else if (0 < a || (b - a) % 2 == 1) cout << "Positive" << endl;
	else cout << "Negative" << endl;
}

Measured memory_bytes: 256
from heapq import heappush, heappop
import sys
input = sys.stdin.readline

q = int(input())
a_sum = b_sum = 0
INF = 10**10
queue_l = [INF]
queue_r = [INF]
for i in range(q):
    s = input()
    if s[0] == '1':
        # update query
        _, a, b = map(int, s.split())

        ql_max = -queue_l[0]
        qr_min = queue_r[0]
        if a < ql_max:
            heappop(queue_l)
            heappush(queue_l, -a)
            heappush(queue_l, -a)
            heappush(queue_r, ql_max)
            a_sum += ql_max - a
        elif a > qr_min:
            heappop(queue_r)
            heappush(queue_r, a)
            heappush(queue_r, a)
            heappush(queue_l, -qr_min)
            a_sum += a - qr_min
        else:
            heappush(queue_l, -a)
            heappush(queue_r, a)

        b_sum += b
    else:
        # evaluation query
        ql_max = -queue_l[0]
        print(ql_max, a_sum + b_sum)


Measured memory_bytes: 19048
#include<iostream>
#include<iomanip> 
using namespace std;
int main(){
	int a,b;
	cin>>a;
	for(int i=1;i<=a;i++){
		if(i%2==1)
		b+=1;
		
	}
	cout<<fixed<<setprecision(10)<<double(b)/a;
	return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include <queue>
#include <cmath>
#include <bitset>
#include <algorithm>
#include <set>
#include <string>

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

using namespace std;

int main(){
    int A, B, C;
    ll K;
    cin >> A >> B >> C >> K;
    int ans = (A - B);
    if(K % 2){
        ans *= -1;
    }

    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
 
ll dp[3001][3001][3], a[3001][3001];
 
int main() {
    ll r,c,items, x , y, v, maxi = 0;
    cin >> r >> c >> items;
    while(items--) {
    	cin >> x >> y >> v;
    	x--, y--;
    	dp[x][y][0] = a[x][y] = v;
    }
    for(int i=0;i<r;i++) for(int j=0;j<c;j++) {
        for(int k=0;k<3;k++) {
            if(k > 0) dp[i][j][k] = max(dp[i][j][k], dp[i][j][k-1]);
            if(j+1 < c) dp[i][j+1][k] = max(dp[i][j+1][k], dp[i][j][k]);
            if(j+1 < c && k > 0) dp[i][j+1][k] = max(dp[i][j+1][k], dp[i][j][k-1] + a[i][j+1]);
        }
        if(i+1 < r) dp[i+1][j][0] = dp[i+1][j][1] = dp[i+1][j][2] = max({dp[i][j][0], dp[i][j][1], dp[i][j][2]}) + a[i+1][j];
    }
    maxi = dp[r-1][c-1][2];
    cout << maxi;
	return 0;
}

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

using namespace std;
typedef long long ll;
#define tr(container, it) \
    for (auto it = container.begin(); it != container.end(); it++)
#define scontains(c, x) ((c).find(x) != (c).end())   //O(log n)
#define contains(c, x) (find((c).begin(),(c).end(),x) != (c).end()) //O(n)
#define ill(_x)  ll _x;scanf("%lld",&_x);
#define idb(_x)  double _x;scanf("%lf",&_x);
#define pll pair<ll,ll>
#define mll map<ll,ll>
#define vll vector<ll>
#define sll set<ll>
#define vs vector<string>
#define in0(x, a, b)((x)>=a && (x)<=b    )
#define in1(x, a, b)((x)>a && (x)<b)
#define  rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
const double pi = 3.14159265358979323846;
const int INF = 0x3f3f3f3f;
const int MOD = (int) (1e9) + 7;

template<typename T>
bool isPrime(T n)
{
    if (n <= 1) return false;
    if (n == 2) return true;
    if (n % 2 == 0) return false;
    T m = sqrt(n);


    for (T i = 3; i <= m; i += 2)
        if (n%i == 0)
            return false;

    return true;
}

void _() {
    ill(a);
    int i=11;
    while (a){
        if(isPrime(i)){
            cout << i <<" ";
            a--;
        }
        i+=5;
    }


};


int main() {
#if __MINGW32__
    freopen("E:\\Workspace\\Desktop\\cpp\\IO\\Input.txt", "r", stdin);
    freopen("E:\\Workspace\\Desktop\\cpp\\IO\\Output.txt", "w", stdout);
#endif

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    _();
    return 0;

}








Measured memory_bytes: 256
#include<stdio.h>
int main();
int solve(int, int);
int n,A[50];
int main(){
  int q,m,i;
  scanf("%d",&n);
  for(i=0;i<n;i++) scanf("%d",&A[i]);
  scanf("%d",&q);
  for(i=0;i<q;i++){
    scanf("%d",&m);
    if(solve(0,m)) printf("yes\n");
    else printf("no\n");
  }
  return 0;
}
int solve(int i,int m){
  int r;
  if(m==0) return 1;
  if(i>=n) return 0;
  r=solve(i+1,m) || solve(i+1,m-A[i]);
  return r;
}



Measured memory_bytes: 2104
import java.util.*;

class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
    	int n = sc.nextInt();
    	long[] right = new long[n];
    	long[] left = new long[n];
    	for(int i = 0; i < n; i++) {
    		int k = sc.nextInt();
    		if(i + k < n) {
    			right[i+k]++;
    		}
    		if(i - k >= 0){
    			left[i-k]++;
    		}
    	}
    	long sum = 0;
    	for(int i = 0; i < n; i++) {
    		sum += right[i] * left[i];
    	}
    	System.out.println(sum);
    }
}

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

bool mat[101][101] = {{false}};

int main()
{
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    for (int m = 0; m != n; ++m){
        int i = 0, k = 0;
        cin >> i;
        cin >> k;
        while (k--){
            int j = 0;
            cin >> j;
            mat[i - 1][j - 1] = true;
        }
    }
    
    for (int i = 0; i != n; ++i){
        cout << mat[i][0];
        for (int j = 1; j != n; ++j){
            cout << ' ' << mat[i][j];
        }
        cout << endl;
    }
    return 0;
}

Measured memory_bytes: 3220
#include "bits/stdc++.h"

using namespace std;

using ll = long long;
using ld = long double;
using P = pair<int, int>;
constexpr ld EPS = 1e-12;
constexpr int INF = numeric_limits<int>::max() / 2;
constexpr int MOD = 1e9 + 7;

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

    int n;
    cin >> n;
    string s;
    cin >> s;
    vector<int> d, m, c;
    int pre = -1;
    vector<ll> msum(n, 0), csum(n, 0), cnum(n, 0);
    for (int i = 0; i < n; i++)
    {
        if (i != 0)
        {
            msum[i] = msum[i - 1];
            csum[i] = csum[i - 1];
            cnum[i] = cnum[i - 1];
        }
        if (s[i] == 'D')
        {
            d.push_back(i);
        }
        else if (s[i] == 'M')
        {
            m.push_back(i);
            msum[i]++;
        }
        else if (s[i] == 'C')
        {
            c.push_back(i);
            cnum[i]++;
            if (pre == -1)
                csum[i] = msum[i];
            else
                csum[i] = csum[pre] + msum[i];
            pre = i;
        }
    }
    int q;
    cin >> q;
    while (q--)
    {
        int k;
        cin >> k;
        ll res = 0;
        for (int i = 0; i < (int)d.size(); i++)
        {
            int pos = d[i];
            auto mi = upper_bound(c.begin(), c.end(), pos);
            if (mi == c.end())
                continue;
            auto ma = lower_bound(c.begin(), c.end(), pos + k);
            ma--;
            int miidx = *mi, maidx = *ma;
            res -= msum[pos] * (cnum[maidx] - cnum[pos]);
            if (mi == c.begin())
            {
                res += csum[maidx];
            }
            else
            {
                res += csum[maidx];
                res -= csum[miidx-1];
            }
        }
        cout << res << endl;
    }
}


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

using namespace std;
typedef long long LL;
typedef pair<int, int> PII;

int main() {
  int N, K;
  cin >> N >> K;
  int upper = (N - 1) * (N - 2) / 2;
  if (K > upper) {
    cout << "-1" << endl;
    return 0;
  }
  int remain = upper - K;
  int M = N - 1 + remain;
  cout << M << endl;
  for (int i = 2; i <= N; i++) {
    cout << 1 << " " << i << endl;
  }
  for (int i = 2; i <= N; i++) {
    for (int j = 2; j < i; j++) {
      if (remain > 0) cout << i << " " << j << endl;
      remain--;
    }
  }

  return 0;
}

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

using ll = long long int;

const int MAX = (int)(1e5 + 5);
const ll INF = (ll)(1e10 + 5);

const int MAX_N = (int)(5e3 + 5);

/////////////////////////////////////////////////////////////
class RollingHash {
 public:
  using hash_type = tuple<ll, ll, ll>;

  string s;

  ll base1;
  ll base2;
  ll base3;

  ll mod1;
  ll mod2;
  ll mod3;

  vector<ll> hash1;
  vector<ll> hash2;
  vector<ll> hash3;

  vector<ll> pow1;
  vector<ll> pow2;
  vector<ll> pow3;

  RollingHash(string s) {
    this->s = s;

    this->base1 = 1009LL;
    this->base2 = 1007LL;
    this->base3 = 1005LL;

    this->mod1 = (ll)(1e9 + 7);
    this->mod2 = (ll)(1e9 + 9);
    this->mod3 = (ll)(999999937);

    init(s);
  }

  void init(const string &s) {
    int n = s.size();

    hash1.assign(n + 1, 0);
    hash2.assign(n + 1, 0);
    hash3.assign(n + 1, 0);

    pow1.assign(n + 1, 1);
    pow2.assign(n + 1, 1);
    pow3.assign(n + 1, 1);

    for (int i = 0; i < n; i++) {
      hash1[i + 1] = (hash1[i] + s[i]) * base1 % mod1;
      hash2[i + 1] = (hash2[i] + s[i]) * base2 % mod2;
      hash3[i + 1] = (hash3[i] + s[i]) * base3 % mod3;

      pow1[i + 1] = pow1[i] * base1 % mod1;
      pow2[i + 1] = pow2[i] * base2 % mod2;
      pow3[i + 1] = pow3[i] * base3 % mod3;
    }
  }

  // 0-indexed, [l, r]
  hash_type get(int l, int r) {
    l += 1;
    r += 1;

    l -= 1;

    ll t1 = ((hash1[r] - hash1[l] * pow1[r - l]) % mod1 + mod1) % mod1;
    ll t2 = ((hash2[r] - hash2[l] * pow2[r - l]) % mod2 + mod2) % mod2;
    ll t3 = ((hash3[r] - hash3[l] * pow3[r - l]) % mod3 + mod3) % mod3;

    return make_tuple(t1, t2, t3);
  }

  // get hash for whole string
  hash_type get_whole() {
    return get(0, s.size() - 1);
  }
};
/////////////////////////////////////////////////////////////

int n;
string s;

bool check(int length, RollingHash &rh) {
  map<RollingHash::hash_type, int> mp;

  for (int i = 0; i < s.size(); ++i) {
    int end_pos = i + length - 1;

    if (end_pos >= s.size()) break;

    int l = i;
    int r = end_pos;

    RollingHash::hash_type hash = rh.get(l, r);

    auto ptr = mp.find(hash);

    if (ptr != mp.end()) {
      if (ptr->second + length - 1 < i) {
        return true;
      }
    } else {
      mp[hash] = i;
    }
  }

  return false;
}

int main(void) {
  // Here your code !
  scanf("%d", &n);

  cin >> s;

  RollingHash rh(s);

  int ok = 0;
  int ng = s.size();

  while (abs(ok - ng) > 1) {
    int next = (ok + ng) / 2;

    if (check(next, rh)) {
      ok = next;
    } else {
      ng = next;
    }
  }

  int ans = ok;

  printf("%d\n", ans);

  return 0;
}


Measured memory_bytes: 896
#include <bits/stdc++.h>
 
using namespace std;
 
long long max(long long a, long long b){
	if(a > b) return a;
	else if(a < b) return b;
	return a;
}
int main(){
	long long a,b,c,d;
	cin >> a >> b >> c >> d;

	long long ans = -1e9;
	
	ans = max(a*c, b*d);
	ans = max(ans, a*d);
	ans = max(ans, b*c);
	//cout << a * c << endl;
	cout << ans << endl;
}

Measured memory_bytes: 3584
#include<iostream>

using namespace std;

int main(){
	
  	int n,k;cin >> n >> k;
  	if(n%2 == 0){
    	
      	k > n/2 ? cout << "NO" : cout << "YES";
      	return 0;
    }else{
    	k > n/2 + 1 ? cout << "NO" : cout << "YES";
      	return 0;
    }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
typedef long long ll;
#define INF 100000000
#define MOD 100000007
int dx[4]={1,0,-1,0},dy[4]={0,-1,0,1};
using namespace std;
int main(void){
    int n;
    cin>>n;
    string ans="";
    while(n!=0){
        //cout<<ans<<" "<<n<<endl;
        int r=n%2;
        if(r<0)r+=2;
        n=(n-r)/(-2);
        ans+=(char)(r+'0');
    }
    reverse(ans.begin(),ans.end());
    if(ans=="")ans="0";
    cout<<ans<<endl;
   return 0;
}

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

int main() {
  int n, counter = 0;
  vector<int> a;

  cin >> n;
  for (int i = 0; i < n; i++) {
    int tmp;
    cin >> tmp;
    a.push_back(tmp);
  }

  while (true) {
    for (int i = 0; i < n; i++) {
      if (a[i] % 2 == 1) {
        cout << counter << endl;
        return 0;
      }
      a[i] = a[i] / 2;
    }
    // for (int i = 0; i < n; i++) {
    //   cout << a[i] << " ";
    // }
    // cout << endl;
    // cout << counter << endl;
    counter++;
  }

  return 0;
}

Measured memory_bytes: 3640
import java.util.Scanner;
import java.util.Arrays;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String s = sc.next();

        int[] cntArray = new int[s.length()];
        int[] pre1CntArray = new int[s.length()];
        int[] pre2CntArray = new int[s.length()];

        //Arrays.fill(cntArray, 1);

        //printCntArray(cntArray);

        sortCntArray(s, cntArray);

        for (int i = 0; i < s.length(); i++) {
            pre2CntArray = pre1CntArray.clone();
            pre1CntArray = cntArray.clone();
            movePosition(s, cntArray, pre1CntArray);

            if (Arrays.equals(pre1CntArray, cntArray)) {
                printCntArray(cntArray);
                break;
            }

            if (Arrays.equals(pre2CntArray, cntArray)) {
                if ((i + 1) % 2 == 0) {
                    printCntArray(cntArray);
                } else {
                    printCntArray(pre1CntArray);
                }
                break;
            }
        }
    }

    public static void movePosition(String s, int[] cntArray, int[] prevCntArray) {

        for (int i = 0; i < s.length(); i++) {
            if (s.charAt(i) == 'R') {
                cntArray[i + 1] += prevCntArray[i];
                cntArray[i] -= prevCntArray[i];
            } else {
                cntArray[i - 1] += prevCntArray[i];
                cntArray[i] -= prevCntArray[i];
            }
        }
    }

    public static void printCntArray(int[] cntArray) {

        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < cntArray.length; i++) {
            sb.append(cntArray[i]);
            sb.append(" ");
        }
        System.out.println(sb);
    }

    public static void sortCntArray(String s, int[] cntArray) {

        char target = 0;
        int matchCnt = 0;
        for (int i = 0; i < s.length(); i += matchCnt) {
            target = s.charAt(i);
            matchCnt = 1;
            for (int j = i + 1; j < s.length(); j++) {
                if (s.charAt(j) == target) {
                    matchCnt++;
                } else {
                    break;
                }
            }

            if (matchCnt == 1) {
                cntArray[i] = matchCnt;
            } else {
                if (target == 'R') {
                    cntArray[i + (matchCnt - 2)] = (matchCnt / 2);
                    cntArray[i + (matchCnt - 1)] = (matchCnt % 2 == 0) ? (matchCnt / 2) : (matchCnt / 2) + 1;
                } else {
                    cntArray[i + 1] = (matchCnt / 2);
                    cntArray[i] = (matchCnt % 2 == 0) ? (matchCnt / 2) : (matchCnt / 2) + 1;
                }
            }
        }
    }
}


Measured memory_bytes: 30572
/*
    Author: Nguyen Tan Bao
    Status:
    Idea:
*/

#include <bits/stdc++.h>
#define FI first
#define SE second
#define EPS 1e-9
#define ALL(a) a.begin(),a.end()
#define SZ(a) int((a).size())
#define MS(s, n) memset(s, n, sizeof(s))
#define FOR(i,a,b) for (int i = (a); i <= (b); i++)
#define FORE(i,a,b) for (int i = (a); i >= (b); i--)
#define FORALL(it, a) for (__typeof((a).begin()) it = (a).begin(); it != (a).end(); it++)
//__builtin_ffs(x) return 1 + index of least significant 1-bit of x
//__builtin_clz(x) return number of leading zeros of x
//__builtin_ctz(x) return number of trailing zeros of x

using namespace std;
using ll = long long;
using ld = double;
typedef pair<int, int> II;
typedef pair<II, int> III;
typedef complex<ld> cd;
typedef vector<cd> vcd;

const ll MODBASE = 1000000007LL;
const int MAXN = 200010;
const int MAXM = 1000;
const int MAXK = 16;
const int MAXQ = 200010;

int n, m, cnt;
vector<int> a[MAXN];
bool visited[MAXN];

void dfs(int u) {
    visited[u] = true;
    cnt++;
    for (int v : a[u]) {
        if (visited[v]) continue;
        dfs(v);
    }
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(nullptr);
    cin >> n >> m;
    FOR(i,1,m) {
        int u, v;
        cin >> u >> v;
        a[u].push_back(v);
        a[v].push_back(u);
    }
    int res = 0;
    FOR(i,1,n)
        if (!visited[i]) {
            cnt = 0;
            dfs(i);
            res = max(res, cnt);
        }
    cout << res;
    return 0;
}


Measured memory_bytes: 21036
#include<iostream>
using namespace std;
void solve(){
	int a,b;cin>>a>>b;
	if(b%2!=0){
		cout<<"No"<<endl;return;
	}
	else{
	for(int i=0;i<=a;i++){
		if((4*(i)+2*(a-i))==b){
			cout<<"Yes"<<endl;return;
		}
	}
	cout<<"No"<<endl;return;
	}
}
int main(){
	solve();
}

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

int main() {
  int x,y;
  for (int i=0;i<3000;i++){
    cin >> x >> y;
    if(x>y)
      swap(x,y);
    if(x==0&&y==0)
      break;
    cout << x << ' ' << y << endl;
  }
}




Measured memory_bytes: 3064