akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<cmath>
using namespace std;
long a,b,c,d;
int main ()
{
long a,b,c,k,m,n,d,s;
cin>>a>>b>>c>>d;
if ( a<b and c<d )cout<<a+c<<endl;
else if ( a>b and c>d )cout<<b+d<<endl;
else if ( a<b and c>d)cout<<a+d<<endl;
else if ( a>b and c<d )cout<<b+c<<endl;
else if ( a==b and c<d)cout<<a+c<<endl;
else if ( a==b and c>d)cout<<a+d<<endl;
else if ( a>b and c==d )cout<<b+c<<endl;
else if ( a<b and c==d )cout<<a+c<<endl;
else cout<<a+c<<endl;

return 0;
}


Measured memory_bytes: 256
#pragma region
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <map>
#include <queue>
#include <stack>
#include <set>
#include <list>
#include <iomanip>
#include <cstdint>
#include <cstdlib>

using namespace std;
typedef long long ll;
//#define rep(i, s, e) for (int(i) = (s); (i) < (e); ++(i))
#define rep(i, e) for (int(i) = 0; (i) < (e); ++(i))
#define rrep(i, s) for (int(i) = (s) - 1; (i) >= 0; --(i))
#define all(x) x.begin(),x.end()
#pragma endregion


int main()
{
	int x, y; cin >> x >> y;
	if (x%y == 0)cout << -1 << endl;
	else cout << x << endl;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#define MAX_S 100000
#define MOD 1000000007

int dp[MAX_S+1][13]={};
int i,j,k,s;

int main(void){
    char S[MAX_S];
    scanf("%s",S);
    int m[6] = {1,10,9,12,3,4};
    
    for(i=0;i<13;i++){
        if(S[strlen(S)-1]=='?'){
            if(i<10)dp[0][i]=1;
            else dp[0][i]=0;
        }else{
            s = S[strlen(S)-1] -48;
            if(s==i)dp[0][i]=1;
            else dp[0][i]=0;
        }
    }

    for(i=1;i<strlen(S);i++){
        if(S[strlen(S)-1-i]=='?'){
            for(j=0;j<13;j++){
                for(k=0;k<10;k++){
                    dp[i][(k*m[i%6]+j)%13]= (dp[i][(k*m[i%6]+j)%13]+dp[i-1][j])%MOD;
                }
            }
            
        }else{
            s = S[strlen(S)-1-i] -48;
            for(j=0;j<13;j++){
                    dp[i][(s*m[i%6]+j)%13]= (dp[i][(s*m[i%6]+j)%13]+dp[i-1][j])%MOD;
            }
        }
    }
    printf("%d",dp[strlen(S)-1][5]);
    return 0;
}


Measured memory_bytes: 5376
#include <iostream>
#include <algorithm>
#include <bitset>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <complex>
#include <string.h>
#include <numeric>
using namespace std;

#define int long long
#define reps(i,s,n) for(int (i)=(s);(i)<(n);++(i))
#define rep(i,n) reps(i,0,n)
#define rept(i,n) rep(i,(n)+1)
#define repst(i,s,n) reps(i,s,(n)+1)
#define reprt(i,n,t) for(int (i)=(n);(i)>=(t);--(i))
#define repr(i,n) reprt(i,n,0)
#define each(i,v) for(auto &(i):(v))
#define eachr(i,v) for(auto &(i)=(v).rbegin();(i)!=(v).rend();(i)++)
#define all(c) (c).begin(),(c).end()
#define rall(c) (c).rbegin(),(c).rend()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define tmax(x,y,z) max(x,max(y,z))
#define tmin(x,y,z) min(x,min(y,z))
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
#define ln '\n'
#define bln(i,n) (((i)==(n)-1)?'\n':' ')
#define dbg(x) cout<<#x" = "<<(x)<<ln<<flush
#define dbga(x,n) {cout<<#x" : ";for(int (i)=0;i<(n);++i){cout<<((x)[i])<<(i==((n)-1)?'\n':' ')<<flush;}}
#define zero(a) memset(a,0,sizeof(a))
#define unq(a) sort(all(a)),a.erase(unique(all(a)),a.end())

//typedef complex<double> P;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<string> vst;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
typedef vector<vector<int> > mat;

const ll inf = (ll)1e9+10;
const ll linf = (ll)1e18+10;
const ll mod = (ll)(1e9+7);
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
const int ddx[] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[] = {1, 1, 0, -1, -1, -1, 0, 1};
const double eps = 1e-10;

ll mop(ll a,ll b,ll m=mod) {ll r=1;a%=m;for(;b;b>>=1){if(b&1)r=r*a%m;a=a*a%m;}return r;}
ll gcd(ll a,ll b) {return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b) {return a/gcd(a,b)*b;}
bool ool(int x,int y,int h,int w) {return((x<0)||(h<=x)||(y<0)||(w<=y));}
bool deq(double a,double b) {return abs(a-b)<eps;}

struct oreno_initializer {
	oreno_initializer() {
		cin.tie(0);
		ios::sync_with_stdio(0);
	}
} oreno_initializer;



int n, a[3030], dp[3030][3030];

int rec(int l, int r) {
	if (dp[l][r]!=-1) return dp[l][r];
	bool t = (l + n-r) %2;
	if (l==r) return a[l] * (t ? 1 : -1);
	int le, ri;
	if (t) le = rec(l+1,r) + a[l], ri = rec(l,r-1) + a[r];
	else le = rec(l+1,r) - a[l], ri = rec(l,r-1) - a[r];
	if (t) return dp[l][r] = max(le,ri);
	return dp[l][r] = min(le,ri);
}

signed main() {
	cin >> n;
	reps(i,1,n+1) cin >> a[i];
	memset(dp, -1, sizeof(dp));
	cout << rec(1,n) << endl;
}

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

int main()
{
    long long n;
    scanf("%lld",&n);
    long long res=0;
    long long f=26;
    long long len=0;
    while(res<n){
        res+=f;
        len++;
        f*=26;
    }
    f/=26;
    res-=f;
    n-=res;
    char ans[50];
    int ff=0;
    n--;
    while(len--){
        int x=n%26;
        ans[ff++]=(char)('a'+x);
        n/=26;
    }
    reverse(ans,ans+ff);
    ans[ff]='\0';
    cout<<ans;
    return 0;
}

Measured memory_bytes: 3732
import sys
import math
from collections import deque
MAX_INT = int(10e10)
MIN_INT = -MAX_INT
mod = 1000000007
sys.setrecursionlimit(1000000)
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(sys.stdin.readline())
def S(): return input()

N = I()
a = IL()

ans = [0]*N
for i in a:
  ans[i-1] += 1

for i in ans:
  print(i)

Measured memory_bytes: 91512
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define INF (1LL<<50)
#define MOD 1000000007

vector<vector<int>> edge;

int main(){
    int N;
    cin >> N;
    edge.assign(N,vector<int>());
    rep(i,N-1){
        int a,b;
        cin >> a >> b;
        a--; b--;
        edge[a].push_back(b);
        edge[b].push_back(a);
    }
    queue<int> q_f,q_s;
    vector<int> dist_f(N),dist_s(N);
    q_f.push(0);
    while(!q_f.empty()){
        auto node = q_f.front();
        q_f.pop();
        for(auto next:edge[node]){
            if(dist_f[next]==0){
                q_f.push(next);
                dist_f[next]=dist_f[node]+1;
            }
        }
    }
    q_s.push(N-1);
    while(!q_s.empty()){
        auto node = q_s.front();
        q_s.pop();
        for(auto next:edge[node]){
            if(dist_s[next]==0){
                q_s.push(next);
                dist_s[next]=dist_s[node]+1;
            }
        }
    }
    ll cnt_f=0,cnt_s=0;
    rep(i,N){
        // cout << "f:" << dist_f[i] << " s:" << dist_s[i] << endl;
        if(dist_f[i]<=dist_s[i]) cnt_f++;
        else cnt_s++;
    }
    string ans;
    if(cnt_f>cnt_s) ans = "Fennec";
    else ans = "Snuke";
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 9476
#include<iostream>
#include<cstdio>
#include<cmath>
#include<vector>
#include<map>
using namespace std;
#define INF 1e+10
#define EPS 1e-10
#define EQ(a,b) (abs(a-b)<EPS)

//誤差を考慮して足し算
double add(double a,double b){
	if(abs(a+b) < EPS*(abs(a)+abs(b)))return 0;
	return a+b;
}
struct P{//2次元ベクトル
	double x,y;
	P(){}
	P(double x,double y):x(x),y(y){}
	P operator + (P p){
		return P(add(x,p.x),add(y,p.y));
	}
	P operator - (P p){
		return P(add(x,-p.x),add(y,-p.y));
	}
	P operator * (double d){
		return P(x*d,y*d);
	}
	bool operator ==(P p){
		return x==p.x && y==p.y;
	}
	bool equal(P p){
		return (x-p.x)*(x-p.x)+(y-p.y)*(y-p.y) < EPS*EPS;
	}	
	double dot(P p){//内積
		return add(x*p.x,y*p.y);
	}
	double det(P p){//外積
		return add(x*p.y,-y*p.x);
	}
};
//線分p1-p2上に点qがあるか判定
bool on_seg(P p1,P p2,P q){
	return (p1-q).det(p2-q)==0 && (p1-q).dot(p2-q)<=0;
}
//直線p1-p2と直線q1-q2の交点
P intersection(P p1,P p2,P q1,P q2){
	return p1+(p2-p1)*( (q2-q1).det(q1-p1)/(q2-q1).det(p2-p1) );
}
//線分p1-p2と線分q1-q2が交差するか
bool intersecting(P p1,P p2,P q1,P q2){
	if(on_seg(p1,p2,q1)||on_seg(p1,p2,q2)||on_seg(q1,q2,p1)||on_seg(q1,q2,p2))return true;
	if((p1-p2).det(q1-q2)==0 )return false;//平行
	P a=intersection(p1,p2,q1,q2);
	return on_seg(p1,p2,a) && on_seg(q1,q2,a);
}
P rotate(P p,double rad){
	double s=sin(rad),c=cos(rad);
	return P(c*p.x-s*p.y, s*p.x+c*p.y);
}
double dist(P p,P q){
	p = p-q;
	return sqrt(p.x*p.x+p.y*p.y);
}

//円同士の交点を計算
pair<P,P> circle_intersection(double x1,double y1,double r1,double x2,double y2,double r2){
	x2 -= x1;
	y2 -= y1;
	double rad = atan2(y2,x2);
	P tmp = rotate(P(x2,y2),-rad);
	x2 = tmp.x;
	y2 = tmp.y;
	double x = (r1*r1-r2*r2+x2*x2)/(2*x2);
	if(abs(r1) < abs(x))return make_pair(P(0,0),P(0,0));//交点なし
	double y = sqrt(r1*r1-x*x);
	return make_pair( P(x1,y1)+rotate(P(x,y),rad) ,  P(x1,y1)+rotate(P(x,-y),rad) );
}
//2点を通る円の中心座標
pair<P,P> circle_on_2P(P p,P q,double r){
	if(2*r < dist(p,q))return make_pair(P(0,0),P(0,0));//解なし
	if(q.x < p.x)swap(p,q);
	q = q - p;
	double rad = atan2(q.y,q.x);
	P tmp = rotate(q,-rad);
	double x = tmp.x/2;
	double y = sqrt(4*r*r-tmp.x*tmp.x)/2;
	return make_pair( p+rotate(P(x,y),rad) ,  p+rotate(P(x,-y),rad) );
}

int n;
P c[300];
int calc(P p,P q){
	if (2 < dist(p,q))return 1;
	pair<P,P> pa = circle_on_2P(p,q,1.0);
	int res=0,t=0;
	for(int i=0;i<n;i++){
		if(dist(pa.first,c[i]) <= 1+1e-4)t++;
	}
	res = t;
	t=0;
	for(int i=0;i<n;i++){
		if(dist(pa.second,c[i]) <= 1+1e-4)t++;
	}
	res = max(res,t);
	return res;
}
int main(){
	while(cin>>n&&n){
		for(int i=0;i<n;i++){
			double x,y;
			cin>>x>>y;
			c[i] = P(x,y);
		}
		int ans=1;
		for(int i=0;i<n;i++){
			for(int j=i+1;j<n;j++){
				ans = max(ans,calc(c[i],c[j]));
			}
		}
		cout<<ans<<endl;
	}
	return 0;
}

Measured memory_bytes: 1332
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        MyScanner in = new MyScanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        A solver = new A();
        solver.solve(1, in, out);
        out.close();
    }

    static class A {
        public void solve(int testNumber, MyScanner in, PrintWriter out) {
            int K = in.Int();
            int A = in.Int();
            int B = in.Int();
            int temp = K;
            while (temp < A) {
                temp += K;
            }
            out.println(temp <= B ? "OK" : "NG");
        }

    }

    static class MyScanner {
        private BufferedReader in;
        private StringTokenizer st;

        public MyScanner(InputStream stream) {
            in = new BufferedReader(new InputStreamReader(stream));
        }

        public String next() {
            while (st == null || !st.hasMoreTokens()) {
                try {
                    String rl = in.readLine();
                    if (rl == null) {
                        return null;
                    }
                    st = new StringTokenizer(rl);
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return st.nextToken();
        }

        public int Int() {
            return Integer.parseInt(next());
        }

    }
}



Measured memory_bytes: 32740
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<utility>
#include<map>
#include<set>
#include <sstream>
#include<queue>
#include<stack>
#include<functional>
#include<math.h>
#include <iomanip>
using namespace std;


int main(void){
  long K,N;
  cin >> K >> N;
  vector<long> D;
  long last = 0;

  for(int i = 0; i < N; i++){
    int tmp;
    cin >> tmp;
    int dis = tmp - last;
    D.push_back(dis);
    last = tmp;
    if(i == N -1)
        D[0] += K - tmp;

  }

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

  int sum = 0;
  for(int i =0 ;i < D.size() -1; i++){
    //    cout << D[i] << endl;
    sum += D[i];
  }
  cout << sum << endl;
  return 0;
}

Measured memory_bytes: 5360
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstring>
#include <string>
#include <math.h>
#include <numeric>
using namespace std;
typedef long long ll;
typedef double D;
typedef pair<int,int> P;
#define PB push_back
#define INF 100000000000000000

bool IsPrime(int num)
{
  if (num < 2) return false;
  else if (num == 2) return true;
  else if (num % 2 == 0) return false; // 偶数はあらかじめ除く
  
  double sqrtNum = sqrt(num);
  for (int i = 3; i <= sqrtNum; i += 2)
  {
    if (num % i == 0)
    {
      // 素数ではない
      return false;
    }
  }
  
  // 素数である
  return true;
}

/*********************************************************/
// 最大公約数（Greatest Common Divisor）を返す。
// 引数に０がある場合は０を返す。
//*********************************************************/
ll gcd( ll m, ll n )
{
  // 引数に０がある場合は０を返す
  if ( ( 0 == m ) || ( 0 == n ) )
    return 0;
  
  // ユークリッドの方法
  while( m != n )
  {
    if ( m > n ) m = m - n;
    else         n = n - m;
  }
  return m;
}//gcd

//*********************************************************
// 最小公倍数（Least Common Multiple）を返す。
// 引数に０がある場合は０を返す。
//*********************************************************
ll lcm( ll m, ll n )
{
  // 引数に０がある場合は０を返す
  if ( ( 0 == m ) || ( 0 == n ) )
    return 0;
  
  return ((m / gcd(m, n)) * n); // lcm = m * n / gcd(m,n)
}//lcm

/********************************************************/

int main() {
  ll A,B,K,i;
  cin >> A >> B >> K;
  for(i=0;i<K;i++){
    if(i%2 == 0){
       if(A%2 == 0){
         A = A/2;
         B = B + A;
       } else {
         A = A -1;
         A = A/2;
         B = B + A;
      }
    } else {
       if(B%2 == 0){
         B = B/2;
         A = B + A;
       } else {
         B = B -1;
         B = B/2;
         A = B + A;
      }
    }
  }
  cout << A << " " <<B << endl;
  return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cassert>
#include <cstring>
#include <iostream>
#include <vector>

using namespace std;

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define TRACE(x) cout << #x << " = " << x << endl
#define _ << " _ " <<

typedef long long llint;

char s[111111];

int main(void) {
  scanf("%s", s);

  vector<int> pos, ch;
  int n = strlen(s);
  REP(i, n) {
    if (s[i] != 'x') {
      pos.push_back(i);
      ch.push_back(s[i]);
    }
  }

  bool ok = true;
  int m = ch.size();
  REP(i, m) if (ch[i] != ch[m-i-1]) ok = false;

  if (!ok) {
    puts("-1");
    return 0;
  }

  int prev = -1;

  vector<int> gaps;
  REP(i, m) {
    gaps.push_back(pos[i] - prev - 1);
    prev = pos[i];
  }
  gaps.push_back(n - prev - 1);

  int ret = 0;
  int k = gaps.size();
  for (int i = 0; i <= k-i-1; ++i) {
    ret += abs(gaps[i] - gaps[k-i-1]);
  }

  printf("%d\n", ret);
  return 0;
}


Measured memory_bytes: 1908
#include <iostream> // cin, cout, cerr
#include <algorithm> // minmax, sort, swap
#include <numeric> // iota
#include <cstdio> // printf, scanf
#include <string> // string, stoi, to_string
#include <vector> // vector
#include <queue> // queue, priority_queue
#include <deque> // deque
#include <map> // key-value pairs sorted by keys
#include <set> // set
#include <iomanip> // cout<<setprecision(n)
#include <functional> // function<void(int)>

#define rep(i,n) for(int i = 0; i < (n); i++)
#define ENDL '\n'
#define print(i) std::cout << (i) << '\n'

#define int long long // at least int64 > 9*10^18
#define all(v) (v).begin(), (v).end()
/* libraries */

signed main() {
	const int MAX = 1e5;
	std::vector<int> primes(MAX+1,1);
	primes[0] = 0;
	primes[1] = 0;
	for(int i=2;i<=MAX;i++) {
		if(primes[i]) {
			for(int x = 2; x*i<=MAX; x++) {
				primes[x*i] = 0;
			}
		}
	}

	std::vector<int> v(MAX+1,0);
	for(int i=3;i<=MAX;i+=2) {
		if(primes[i] && primes[(i+1)/2]) {
			v[i] = 1;
		}
	}

	std::vector<int> dp(MAX+1);
	dp[0] = 0;
	for(int i=0;i<MAX;i++) {
		dp[i+1] = dp[i] + v[i+1];
	}
	
	int Q;
	std::cin >> Q;
	rep(i,Q) {
		int l,r;
		std::cin >> l >> r;
		print(dp[r]-dp[l-1]);
	}
	return 0;
}


Measured memory_bytes: 2944
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>

using namespace std;

#define INF 100000000000L

int main() {
	int a, b, q;
	long x;
	long v;

	cin >> a >> b >> q;

	vector<long long> s = { - INF };
	vector<long long> t = { - INF };
	for (int i = 0; i < a; i++) {
		cin >> v;
		s.push_back(v);
	}
	s.push_back(INF);
	for (int i = 0; i < b; i++) {
		cin >> v;
		t.push_back(v);
	}
	t.push_back(INF);
	for (int i = 0; i < q;i++) {
		cin >> x;
		long long result = INF;
		long long s1, s2, t1, t2;
		vector<long long>::iterator it;
		it = lower_bound(s.begin(), s.end(), x);
		s1 = *(it - 1);
		s2 = *it;
		it = lower_bound(t.begin(), t.end(), x);
		t1 = *(it - 1);
		t2 = *it;
		result = min(result, abs(s1 - t1) + abs(t1 - x));
		result = min(result, abs(s1 - t1) + abs(s1 - x));
		result = min(result, abs(s2 - t2) + abs(t2 - x));
		result = min(result, abs(s2 - t2) + abs(s2 - x));
		result = min(result, abs(t2 - s1) + abs(t2 - x));
		result = min(result, abs(t2 - s1) + abs(s1 - x));
		result = min(result, abs(t1 - s2) + abs(s2 - x));
		result = min(result, abs(t1 - s2) + abs(t1 - x));
		cout << result << endl;

	}


}

Measured memory_bytes: 3060
local n = io.read("*n", "*l")
local str = io.read()
local t = {0, 0, 0}
for v in str:gmatch("%d+") do
  local a = tonumber(v)
  if a % 4 == 0 then
    t[1] = t[1] + 1
  elseif a % 2 == 0 then
    t[2] = t[2] + 1
  else
    t[3] = t[3] + 1
  end
end
if n == 1 then
  if t[3] == 1 then
    print("Yes")
  else
    print("No")
  end
elseif t[1] + 1 < t[3] then
  print("No")
elseif t[1] + 1 == t[3] then
  if t[2] == 0 then
    print("Yes")
  else
    print("No")
  end
else
  print("Yes")
end


Measured memory_bytes: 5296
def calc(n):
    return n * (n - 1) // 2


def resolve():
    n, k = map(int, input().split())
    ans = 0
    mod = 10 ** 9 + 7
    m = calc(n + 1)
    for i in range(k, n + 2):
        ans += m - calc(n + 1 - i) - calc(i) + 1
        ans %= mod
    print(ans)


if __name__ == '__main__':
    resolve()


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

void sort(int* array, int N)
{
    int count = 0;
    for(int i=0;i<N;++i)
    {
        int minj = i;
        for(int j=i;j<N;++j)
        {
            if(array[minj] > array[j])
            {
                minj = j;
            }
        }
        if(i != minj){
            swap(array[i], array[minj]);
            ++count;
        }
    }

    for(int i=0;i<N;++i)
    {
        if(i) cout << " ";
        cout << array[i];
    }
    cout << endl << count << endl;
}

int main()
{
    int N;
    int array[100];
    cin >> N;
    for(int i=0;i<N;++i)
    {
        cin >> array[i];
    }
    sort(array, N);
}



Measured memory_bytes: 3100
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
#include <climits>
#include <iomanip>
using namespace std;

#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;


int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, k;
    cin >> n >> k;
    VI h(n);
    REP(i, n) cin >> h[i];
    sort(ALL(h));
    int ans = (int)1e9;
    REP(i, n - k + 1) ans = min(h[i + k - 1] - h[i], ans);
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 640
n, x = map(int, input().split())
a, p = [1], [1]
for i in range(n):
    a.append(2*a[i]+3)
    p.append(2*p[i]+1)
def f(n, x):
    if n==0:
        return 0 if x<=0 else 1
    elif x<=1+a[n-1]:
        return f(n-1, x-1)
    else:
        return p[n-1]+1+f(n-1, x-2-a[n-1])
print(f(n, x))


Measured memory_bytes: 3064
/*input
14
1 2 2 3 3 3 4 4 4 4 1 2 3 4
*/
#include <bits/stdc++.h>
using namespace std;
const long long md=1e9+7;
long long a[1000005],n;

int main(){
	#ifdef ONLINE_JUDGE
	ios_base::sync_with_stdio(0);
	cin.tie(0);cout.tie(0);
	#endif
	long long q,m,k,h,ans=0,sum=0,p,x,y;
	cin>>n;
	for(int i=1;i<=n;++i){
		cin>>a[i];
		if(a[i]==a[i-1]){
			++ans;
			a[i] = 424242;
		}
	}
	cout<<ans;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<string.h>
#define F(i,a,n) for(int i=a; i<n; i++)
#define INF 100000000

int max(int a, int b){
  if(a>b) return a;
  else return b;
}

int main(){
  char s[3001],t[3001];
  scanf("%s",s);
  scanf("%s",t);
  int sn=strlen(s);
  int tn=strlen(t);
  int dp[sn+1][tn+1];
  F(i,0,sn+1){
    F(j,0,tn+1) dp[i][j]=0;
  }
  F(i,0,sn){
    F(j,0,tn){
      if(s[i]==t[j]){
        dp[i+1][j+1]=max(max(dp[i][j+1],dp[i+1][j]),dp[i][j]+1);
      }else{
        dp[i+1][j+1]=max(dp[i+1][j],dp[i][j+1]);
      }
    }
  }
  int si=sn,ti=tn;
  int cnt=dp[sn][tn];
  char ans[cnt];
  ans[cnt]='\0';
  while(cnt){
    if(dp[si-1][ti]==cnt) si--;
    else if(dp[si][ti-1]==cnt) ti--;
    else {
      //putchar(s[si-1]);
      ans[cnt-1]=s[si-1];
      si--;
      ti--;
      cnt--;
    }
  }
  //putchar("");
  printf("%s\n",ans);

  return 0;
}

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

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

using namespace std;

int ans;

void dfs(vector<int> x,int cnt)
{
	if(x[0] >= 1 && x[1] >= 1 && x[2] >= 1)
	{
		x[0]--;
		x[1]--;
		x[2]--;

		dfs(x,cnt+1);
	}
	else if(x[0] >= 2 && x[1] >= 1)
	{
		x[0] -= 2;
		x[1]--;

		dfs(x,cnt+1);
	}
	else if(x[0] >= 3)
	{
		x[0] -= 3;
		dfs(x,cnt+1);
	}

	ans = max(ans,cnt);
}

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

	rep(i,n)
	{
		vector<int> v(3);
		rep(i,3) cin >> v[i];

		ans = 0;
		dfs(v,0);

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

Measured memory_bytes: 1380
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <string>
#include <vector>
#include <deque>
#include <list>
#include <queue>
#include <math.h>
#include <assert.h>
#include <set>
#include <map>
#include <bitset>
#include <ctime>
#include <time.h>
#include <algorithm>
#include <cstdio>
#include <fstream>
#include <stack>
#include <ctype.h>
#include <numeric>
#include <sstream>
#include <unistd.h>
#include <unordered_map>
#include <unordered_set>
#include <limits>
#include <random>
#include <chrono>
#include <iomanip>
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
using ll = long long;
#define endl '\n'
#define debug(name) DEBUG(#name, (name))
template<typename T>
void DEBUG(string label, T value) {
    cerr << "[" << label << " = " << value << "]\n";
}

double dist(double a, double b){
    return sqrt(a * a + b * b);
}
void solve(){
    int n, d;
    cin >> n >> d;
    int ans = 0;
    for(int i = 0; i < n; ++i){
        int a, b;
        cin >> a >> b;
        if(dist(a, b) <= (double)d){
            ++ans;
        }
    }
    cout << ans << endl;
}
int main(){
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

    solve();
}


Measured memory_bytes: 3616
#include<stdio.h>
int main(void)
{
	int a,b;
	scanf("%d%d",&a,&b);
	if(a==1) a=14;
	if(b==1) b=14;
	if(a==b) printf("Draw\n");
	else if(a<b) printf("Bob\n");
	else  printf("Alice\n");
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep1(i, n) for(int i = 1; i < n+1; i++)
#define sort(A) sort(A.begin(),A.end())
#define reverse(A) reverse(A.begin(),A.end());
typedef long long ll;

int main(){
  int n,m;
  cin >> n >> m;
  vector<vector<int>> to(n+1,vector<int>(0));
  rep(i,m){
    int a,b;
    cin >> a >> b;
    to[a].push_back(b);
    to[b].push_back(a);
  }
  rep1(i,n){
    vector<bool> check(n+1,0);
    for(int p : to[i]) check[p] = 1;
    if(check[1]&&check[n]){
      cout << "POSSIBLE" << endl;
      return 0;
    }
  }
  cout << "IMPOSSIBLE" << endl;
}


Measured memory_bytes: 12016
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mit map<int,int>::iterator
#define sit set<int>::iterator
#define itrm(g,x) for(mit g=x.begin();g!=x.end();g++)
#define itrs(g,x) for(sit g=x.begin();g!=x.end();g++)
#define ltype int
#define rep(i,j,k) for(ltype(i)=(j);(i)<=(k);(i)++)
#define rap(i,j,k) for(ltype(i)=(j);(i)<(k);(i)++)
#define per(i,j,k) for(ltype(i)=(j);(i)>=(k);(i)--)
#define pii pair<int,int>
#define fi first
#define se second
#define mpr make_pair
#define pb push_back
#define fastio ios::sync_with_stdio(false)
const int inf=0x3f3f3f3f,mod=1000000007;
const double pi=3.1415926535897932,eps=1e-6;
void chmax(int &x,int y){if(x < y) x = y;}
void chmin(int &x,int y){if(x > y) x = y;}
int n,m;
int main()
{
    scanf("%d%d",&n,&m);
    int odd = (m+1)/2, even = m - odd;
    rep(i,1,odd) printf("%d %d\n",i,n-i+1);
    int sum = (odd + 1) * 2 + (m - m % 2);
    rep(i,(m+1)/2+1,m) printf("%d %d\n",i,sum - i);
    return 0;
}

Measured memory_bytes: 3828
#include <cstdio>
#include <climits>
#include <cassert>
#include <cmath>
#include <iostream>
#include <string>
#include <algorithm>
#include <numeric>
#include <functional>
#include <tuple>
#include <list>
#include <map>
#include <queue>
#include <stack>
#include <set>
#include <vector>
#include <iterator>
#include <regex>

#define REP(i,s,n) for(int i=(int)(s);i<(int)(n);i++)
#define FOR(x,xs) for(auto &x: xs)

using namespace std;
typedef long long ll;
typedef pair<int,int> PI;
typedef pair<ll,ll> PL;
typedef vector<int> VI;
typedef vector<ll> VL;

template <class T, template <class, class> class C, class charT = char>
void vdump(const C<T, allocator<T>> &v, const charT* delimiter = ", ",
           ostream &stream = cout) {
  copy(v.begin(), v.end(), ostream_iterator<T>(stream, delimiter));
  stream << endl;
}

ll solve(const vector<PL> &xs, const vector<PL> &rs) {
  int n = xs.size();
  VL gain(n+1, 0);
  VL rgain(n+1, 0);
  REP(i,0,n) {
    gain[i+1] = gain[i] + xs[i].second;
    rgain[i+1] = rgain[i] + rs[i].second;
  }
  REP(i,0,n) {
    gain[i+1] -= xs[i].first;
    rgain[i+1] -= 2 * rs[i].first;
  }
  ll rmax = 0;
  ll ans = 0;
  REP(i,0,n) {
    rmax = max(rmax, rgain[i]);
    ans = max(ans, gain[n-i] + rmax);
  }
  // vdump(gain);
  // vdump(rgain);
  return ans;
}

int main() {
  ios::sync_with_stdio(false);
  int n;
  ll c;
  cin >> n >> c;
  vector<PL> xs(n);
  FOR(x,xs) {
    cin >> x.first >> x.second;
  }
  vector<PL> rs(n);
  transform(xs.begin(), xs.end(), rs.rbegin(), [=](PL x){return make_pair(c-x.first, x.second);});
  ll l1 = solve(xs, rs);
  ll l2 = solve(rs, xs);
  cout << max(l1, l2) << endl;
  
  return 0;
}


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

#include <iostream>
#include <fstream>

#include <iostream>
#include <vector>
#include <deque>
#include <unordered_map>
#include <unordered_set>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <string>
#include <algorithm>
#include <cstring>

using namespace std;
using pii = pair<int, int>;
using ll = long long;
using pll = pair<ll, ll>;

const int MOD = 1e9+7;

class CWalkingTakahashi {
public:
    void solve(std::istream& in, std::ostream& out) {
        ll x, k, d;
        in >> x >> k >> d;
        x = abs(x);
        ll step = x/d;
        ll remaining = x%d;
        if(step >= k)
            out << x - k * d << endl;
        else
        {
            ll diff = k - step;
            if(diff & 1)
                out << d - remaining << endl;
            else
                out << remaining << endl;
        }
    }
};


int main() {
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    CWalkingTakahashi solver;
    std::istream& in(std::cin);
    std::ostream& out(std::cout);
    solver.solve(in, out);
    return 0;
}


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

using namespace std;
using ll=long long;
using ull=unsigned long long;

typedef pair<int,int>Pi;
typedef pair<long long,long long>P;
typedef pair<long long,P>PP;
typedef pair<P,P>PPP;

const long long MOD=1e9+7;
const long long INF=5e18;
const int di[4]={1,0,-1,0};
const int dj[4]={0,1,0,-1};

#define fr first
#define sc second
#define pb push_back
#define eb emplace_back
#define ALL(x) (x).begin(),(x).end()
#define ALLR(x) (x).rbegin(),(x).rend()

int n,a[3010];
ll dp[3010][3010][2];

ll dfs(int l,int r,int t){
	if(dp[l][r][t]!=-1)return dp[l][r][t];
	if(l==r){
		if(!t)return a[l];
		else return -a[l];
	}
	ll res=0;
	if(t==0)res=max(dfs(l+1,r,1)+a[l],dfs(l,r-1,1)+a[r]);
	else res=min(dfs(l+1,r,0)-a[l],dfs(l,r-1,0)-a[r]);
	return dp[l][r][t]=res;
}

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

void solve(){
	for(int i=0;i<=n;i++){
		for(int j=0;j<=n;j++){
			dp[i][j][0]=dp[i][j][1]=-1;
		}
	}
	cout<<dfs(0,n-1,0)<<endl;
	return;
}

int main(){
	input();
	solve();
	return 0;
}

Measured memory_bytes: 141696
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <vector>
#include <stack>
#include <queue>
#include <string>
#include <sstream>
#include <algorithm>
#include <iomanip>
#include <iostream>
#include <functional>

using namespace std;
#define VARIABLE(x) cerr << #x << "=" << x << endl
#define BINARY(x) static_cast<bitset<16> >(x);
#define if_range(x, w, h) if (w <= x && x <= h)
#define BitCheck(a,b)   (a >> b) & 1
#define BitSet(a,b)       a |= (1 << b)
#define BitunSet(a,b)    a &= ~(1 << b)
#define MAX(a,b) (((a) > (b)) ? (a) : (b))
#define MIN(a,b) (((a) < (b)) ? (a) : (b))
#define Numof(array)  (sizeof (array) / sizeof *(array))
#define BASE 1000000

struct cmp_c {
	bool operator()(pair<int, int> a, pair<int, int> b) {
		return a.second > b.second;
	}
} cmp;


int main(void) {
	int n, m;
	pair<int, int> shu[100] = {};
	while (scanf("%d %d", &n, &m)) {
		memset(shu, 0, sizeof(shu));
		if (n == 0 && m == 0)
			return 0;
		for (int i = 0; n > i; i++)
		{
			int  tmp;
			for (int j = 0; m > j; j++) {
				scanf("%d", &tmp);
				shu[j].second += tmp;
				shu[j].first = j + 1;
			}
		}
		stable_sort(shu, shu + m, cmp_c());
		for (int j = 0; m > j; j++) {
			printf("%d", shu[j].first);
			if (j != m - 1) printf(" ");
		}
		printf("\n");
	}
	return 0;
}

Measured memory_bytes: 1200
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <cmath>
#include <queue>
#include <set>

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

using namespace std;
typedef long long int ll;
const int INF = 1000000000;
const double PI = 3.1415926535897932;
const ll MOD = 1000000007;

int main()
{
    int n, m;
    cin >> n >> m;

    priority_queue<double> pque;
    rep(i, n) {
        int a;
        cin >> a;
        pque.push(double(a));
    }
    rep(i, m) {
        double discount = pque.top() / 2.0;
        pque.pop();
        pque.push(discount);
    }
    ll ans = 0;
    while(!pque.empty()) {
        int price = int(pque.top());
        pque.pop();
        ans += ll(price);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1400
//minamoto
#include<bits/stdc++.h>
#define R register
#define ll long long
#define fp(i,a,b) for(R int i=(a),I=(b)+1;i<I;++i)
#define fd(i,a,b) for(R int i=(a),I=(b)-1;i>I;--i)
#define go(u) for(int i=head[u],v=e[i].v;i;i=e[i].nx,v=e[i].v)
using namespace std;
char buf[1<<21],*p1=buf,*p2=buf;
inline char getc(){return p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*p1++;}
int read(){
    R int res,f=1;R char ch;
    while((ch=getc())>'9'||ch<'0')(ch=='-')&&(f=-1);
    for(res=ch-'0';(ch=getc())>='0'&&ch<='9';res=res*10+ch-'0');
    return res*f;
}
int read(char *s){
    R int len=0;R char ch;while(((ch=getc())>'9'||ch<'0'));
    for(s[++len]=ch;(ch=getc())>='0'&&ch<='9';s[++len]=ch);
    return s[len+1]='\0',len;
}
double readdb()
{
    R double x=0,y=0.1,f=1;R char ch;
    while((ch=getc())>'9'||ch<'0')(ch=='-')&&(f=-1);
    for(x=ch-'0';(ch=getc())>='0'&&ch<='9';x=x*10+ch-'0');
    for(ch=='.'&&(ch=getc());ch>='0'&&ch<='9';x+=(ch-'0')*y,y*=0.1,ch=getc());
    return x*f;
}
char sr[1<<21],z[20];int C=-1,Z=0;
inline void Ot(){fwrite(sr,1,C+1,stdout),C=-1;}
void print(R int x){
    if(C>1<<20)Ot();if(x<0)sr[++C]='-',x=-x;
    while(z[++Z]=x%10+48,x/=10);
    while(sr[++C]=z[Z],--Z);sr[++C]='\n';
}
inline ll calc(R ll x){int t=(x&3);return (t&1)?(t==1):(x+(t==2));}
ll l,r;
int main(){
    scanf("%lld%lld",&l,&r);
    printf("%lld\n",calc(r)^calc(l-1));
    return 0;
}

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

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

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

  cout << max({a, b, c}) - min({a, b, c}) << '\n';

  return (0);
}


Measured memory_bytes: 3572
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <queue>
#include <stack>
#include <tuple>
#include <cmath>
#include <iomanip>
#include <map>
#include <cstring> //memset(dp,0,sizeof(dp))
#include <functional>
#define ll long long
#define rep(i,n) for(int i=0;i<(n);i++)
#define repp(i,n) for(int i=n-1;i>=0;i--)
#define fi first
#define se second
#define pb push_back
#define ppb pop_back()
#define ALL(a) (a).begin(),(a).end()
using namespace std;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
typedef pair<int,int> P;
typedef pair<ll,ll> Pll;

signed main(){
    ll a; cin >> a;
    long double b; cin >> b;
    long double ans=a*b;
    cout << (ll)ans << endl;
}


Measured memory_bytes: 3728
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
typedef long long ll;
struct Pr{
	ll x,y;
}l_r[410000],r_l[410000];

struct Te{
	int ls,rs,lv,rv;
}t[410000];

int n;
ll mid;
vector<Pr>V[410000];

void insert(int x,Pr y){
	int i=V[x].size()-1;
	if(V[x].empty()){V[x].push_back(y);return;}
	if(V[x][i].y<=y.y)return;
	while(!V[x].empty()&&V[x][i].x>=y.x)V[x].pop_back();
	V[x].push_back(y);
}

int dfs(int u){
	V[u].clear();
	int i,j,dt=t[u].lv+t[u].rv,ltor=0,rtol=0;
	int ls=t[u].ls,rs=t[u].rs,lv=t[u].lv,rv=t[u].rv;
	if(t[u].ls==0){
		insert(u,(Pr){0,0});
		return 1;
	}int jud=dfs(t[u].ls)|dfs(t[u].rs);
	if(jud==0)return 0;
	for(i=V[ls].size()-1,j=V[rs].size()-1;i>=0;i--){while(j>=0&&V[ls][i].y+V[rs][j].x+dt>mid)j--;if(j>=0)l_r[++ltor]=(Pr){V[ls][i].x+lv,V[rs][j].y+rv};}
	for(i=V[ls].size()-1,j=V[rs].size()-1;j>=0;j--){while(i>=0&&V[ls][i].x+V[rs][j].y+dt>mid)i--;if(i>=0)r_l[++rtol]=(Pr){V[rs][j].x+rv,V[ls][i].y+lv};}
	reverse(l_r+1,l_r+ltor+1);
	reverse(r_l+1,r_l+rtol+1);
	i=1;j=1;
	while(i<=ltor&&j<=rtol){
		if(l_r[i].x<r_l[j].x){insert(u,l_r[i]);i++;}
		else {insert(u,r_l[j]);j++;}
	}while(i<=ltor){insert(u,l_r[i]);i++;}
	while(j<=rtol){insert(u,r_l[j]);j++;}
	return !V[u].empty();
}

int main(){
	int x,y;
	scanf("%d",&n);
	ll L=-1,R=17179869184ll;
	for(int i=2;i<=n;i++){
		scanf("%d %d",&x,&y);
		if(t[x].ls==0)t[x].ls=i,t[x].lv=y;
		else t[x].rs=i,t[x].rv=y;
	}while(L+1<R){
		mid=(L+R)>>1;
		if(dfs(1)){
			R=mid;
		}else L=mid;
	}printf("%lld\n",R);
	return 0;
}

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

int main(){
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    int ans = 0;
    if(abs(a - c) <= d)ans = 1;
    if(abs(a - b) <= d && abs(b - c) <= d)ans = 1;

    if(ans == 1)cout << "Yes";
    else cout << "No";

    cout << endl;

    return 0;
    
}

Measured memory_bytes: 256
import numpy as np
ans = 0
s = 0
n,d = map(int,input().split())
a =[]
for _ in range(n):
  ar = list(map(int,input().split()))
  a.append(ar)
for i in range(n):
  for j in range(i+1,n):
    for k in range(d):
      s += (a[i][k]- a[j][k])**2
    c = float(np.sqrt(s))
    if c.is_integer() == True:
      ans += 1
    s = 0
print(ans)

Measured memory_bytes: 12512
#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(),(x).end()
#define int long long
#define ll long long
#define vi vector<int>
#define pii pair<int,int>
#define F first
#define S second
#define pb push_back
#define forn(b) for(int i = 0; i < b; i++)
#define rforn(b) for(int i = b - 1 ;i >= 0; i--)
#define It(m) for(auto it = m.begin(); it != m.end(); it++)
#define N 500500
#define PI 3.14159265358979323846264338327950L
#define speed ios_base :: sync_with_stdio(0);cin.tie(0);cout.tie(0);
    
const ll mod = (ll)1e9 + 7;
    
signed main(){
    speed;
    int n, k; cin >> n >> k;
    vi v(n);
    forn(n) cin >> v[i];
    int ans = LONG_LONG_MAX;
    int l = 0, r = 0;
    r = l + k - 1;
    ll sum1 = 0, sum2 = 0;
    while(r < n && l < n) {
        if(v[l] < 0 && v[r] > 0) {
            sum1 += abs(v[r]) + abs(2 * v[l]);
            sum2 += abs(2 * v[r]) + abs(v[l]);
            ans = min(ans, sum1);
            ans = min(ans, sum2);
        }
        else if(v[l] > 0) {
            sum1 += abs(v[r]);
            ans = min(ans, sum1);
        } else if(v[r] < 0) {
            sum2 += abs(v[l]);
            ans = min(ans, sum2);
        }
        if(v[l] > 0 && v[r] > 0) break;
        sum1 = 0, sum2 = 0;
        l++;
        r++;
    } 
    if(ans == LONG_LONG_MAX) ans = 0;
    cout << ans;
}

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


#include "boost/multiprecision/cpp_int.hpp"
#include "boost/multiprecision/cpp_dec_float.hpp"
namespace mp = boost::multiprecision;
typedef mp::cpp_int LL;
typedef mp::number<mp::cpp_dec_float<1024>> DD;// 仮数部が1024ビットの浮動小数点数型(TLEしたら小さくする)


typedef long double dd;
#define i_7 (ll)(1E9+7)
//#define i_7 998244353
#define i_5 i_7-2
ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
typedef pair<ll,ll> l_l;
typedef pair<dd,dd> d_d;
ll inf=(ll)1E16;
#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define pb push_back
ll max(ll a,ll b){if(a<b)return b;else return a;}
ll min(ll a,ll b){if(a>b)return b;else return a;}
void Max(ll &pos,ll val){pos=max(pos,val);}//Max(dp[n],dp[n-1]);
void Min(ll &pos,ll val){pos=min(pos,val);}
void Add(ll &pos,ll val){pos=mod(pos+val);}
dd EPS=1E-9;
#define fastio ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define fi first
#define se second
#define endl "\n"
#define SORT(v) sort(v.begin(),v.end())
#define ERASE(v) v.erase(unique(v.begin(),v.end()),v.end())
#define POSL(v,x) (lower_bound(v.begin(),v.end(),x)-v.begin())
#define POSU(v,x) (upper_bound(v.begin(),v.end(),x)-v.begin())
template<class T>
inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}
template<class T>
inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}

void mod_print(ll k){
    ll P=1000;
    rep(y,1,P){
        ll x=mod(y*k);
        if(x+P>=i_7){
            x-=i_7;
        }
        if(abs(x)<=P){
            cout<<x<<"/"<<y<<endl;
            return;
        }
    }
    cout<<"nun"<<endl;
}
//////////////////////////

ll po(ll i,ll p){
    if(p==0)return 1;
    else{
        i=mod(i);
        if(p==1)return i;
        if(p%2==0)return po(mod(i*i),p/2);
        return mod(i*po(i,p-1));
    }
}
ll bunbo(ll n){
    return po(n,i_5);
}

ll p1=1009;

ll SOLVE(){
    string s,t;cin>>s>>t;
    ll ns=s.size(),nt=t.size();
    while(s.size()<ns+nt){
        s+=s;
    }
    ll N=s.size();
    ll a[N+1];a[0]=0;
    rep(i,0,N-1){
        a[i+1]=mod(a[i]+po(p1,i)*s[i]);
    }
    ll hast=0;
    rep(i,0,nt-1){
        Add(hast,po(p1,i)*t[i]);
    }
    bool f[ns];
    rep(i,0,ns-1){
        f[i]=mod(hast*po(p1,i))==mod(a[i+nt]-a[i]);
    }
    //rep(i,0,ns-1)cout<<f[i]<<" ";cout<<endl;
    ll dp[ns];memset(dp,-1,sizeof(dp));
    rep(i,0,ns-1){
        if(dp[i]!=-1)continue;
        ll pos=i;
        dp[pos]=0;
        while(f[pos]){
            ll nxt=(pos+nt)%ns;
            if(nxt==i){cout<<-1;return 0;}
            if(chmax(dp[nxt],dp[pos]+1)){
                pos=nxt;
            }else break;
        }
    }
    ll ans=0;
    rep(i,0,ns-1)chmax(ans,dp[i]);
    cout<<ans;
    
    return 0;
}

int main(){fastio
    
    clock_t start = clock();
    SOLVE();
    clock_t end = clock();
    const double time = static_cast<double>(end - start) / CLOCKS_PER_SEC * 1000.0;
    cerr<<endl<<time<<"ms"<<endl;
    
    return 0;
}


Measured memory_bytes: 24028
#include <iostream>
using namespace std;
int main(void){
    int n, t;
    cin >> n >> t;
    long long dur=0;
    
    int i;
    int stop=0;
    int pu;
    for(i = 0; i < n; i++){
        cin >> pu;
        if(stop>=pu){
            dur += pu + t - stop;
            stop = pu + t;
        }
        else{
            dur += t;
            stop = pu + t;
        }
    }
    
    cout << dur << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
long long dp[100005];
int main()
{
    int n,k;
    cin>>n>>k;
    int i,j;
    long long a[n+1];
    for(i=1;i<=n;i++)
    {
        cin>>a[i];
    }
    dp[1]=0;
    dp[2]=abs(a[1]-a[2]);
    for(i=3;i<=n;i++)
    {
        long long ans=1e18;
        for(j=1;j<=k;j++)
        {
            if((i-j)>0)
            {
                ans=min(ans,dp[i-j]+abs(a[i-j]-a[i]));
            }
        }
        dp[i]=ans;
    }
    cout<<dp[n]<<endl;
}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const ll inf = 1e18;
int n;
ll cst[26], sat[366][26], last[26], tmp[26];
ll tester(vector<int>v){
	ll res = 0ll;
	memset(last, 0ll, sizeof(last));
	for(int nw, i=0; i<n; i++){
		nw = v[i];
		res += sat[i][nw-1];
		last[nw-1] = i+1;
		for(int j=0; j<26; j++)
			res -= cst[j]*(i+1-last[j]);
	}
	return res;
}
bitset<370>vis;
int rand(int x){return rand()%x+1;}
vector<int>gen(int hm, int x){
	vector<int>res;
	for(int cr=rand()%x+1, times=0; times<hm; cr=rand(x)%x+1, times++)
		res.push_back(cr);
	return res;
}
int randlf(int l, int r){return rand()%(r-l+1)+l;}
vector<int>lgg={1, 2, 4, 8, 16, 32, 64, 128};
vector<int>best;
int main(){
	srand(time(NULL));
	scanf("%d", &n);
	memset(last, 0ll, sizeof(last));
	for(int i=0; i<26; i++) scanf("%lld", &cst[i]);
	for(int i=0; i<n; i++) for(int j=0; j<26; j++)
		scanf("%lld", &sat[i][j]);
	ll res = 0ll;
	vector<int>base;
	for(int nw, i=0; i<n; i++){
		memset(tmp, 0ll, sizeof(tmp));
		for(nw=0; nw<26; nw++){
			tmp[nw] += sat[i][nw];
			for(int j=0; j<26; j++) if(j != nw)
				tmp[nw] -= cst[j] * (i+1-last[j]);
		}
		ll get = -inf; int id = -1;
		for(nw=0; nw<26; nw++) 
			if(get < tmp[nw]){
				get = tmp[nw]; id = nw;
			}else if(get == tmp[nw] && cst[nw] > cst[id]){
				get = tmp[nw]; id = nw;
			}
		base.push_back(id+1); 
		last[id] = i+1; res += tmp[nw];
	}
	best=base;
	for(int times=0; times<200; times++){
		for(int k=7; k>0; k--){
			vector<int>changeid, changeval;
			for(int tt=0; tt<5*(11-k); tt++){
				int cv = randlf(lgg[k-1], lgg[k]);
				changeid = gen(cv, 365);
				changeval = gen(cv, 26);
				vector<int>cur = best;
				for(int i=0; i<cv; i++)
					cur[changeid[i]-1] = changeval[i];
				if(tester(best) < tester(cur))
					best = cur;
			}
		}
	}
	for(int i=0; i<n; i++) printf("%d\n", best[i]);
	return 0;
}

Measured memory_bytes: 3856
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n);i++)
#define sz(x) int(x.size())
typedef long long ll;
typedef pair<int,int> P;
constexpr int INF = 2e9;
int main(){ 
  int n, m;
  cin >> n >> m;
  vector<vector<int>> g(n);

  for (int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    a--; b--;
    g[a].emplace_back(b);
    g[b].emplace_back(a);
  }

  vector<int> prev(n, -1);
  queue<int> que;
  vector<int> d(n, INF);
  que.push(0);
  d[0] = 0;

  while (!que.empty()) {
    int u = que.front();
    que.pop();
    for (auto v : g[u]) {
      if (d[v] != INF) continue;
      prev[v] = u;
      que.push(v);
      d[v] = d[u] + 1;
    }
  }
  int ok = true;
  for (int i = 1; i < n; i++) if (prev[i] == -1) ok = false;
  if (!ok) cout << "No" << endl;
  else {
    cout << "Yes" << endl;
    for (int i = 1; i < n; i++) cout << prev[i] + 1 << endl;
  }
  return 0;
} 

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

const int N = 1e6+5;

bool prime[N];

void seive()
{
    memset(prime,true,sizeof prime);

   for(int i=2;i*i<=N;i++)
   {
       if(prime[i]==true)
       {
           for(int j=i*2;j<=N;j+=i)prime[j]=false;
       }
   }

}
int main()
{
    seive();
    int n;
    cin>>n;

   for(int i=31;i<=55555;i+=30)
   {
       if(prime[i])
       {
           cout<<i<<" ";
           n--;
       }
       if(n==0)break;
   }
}


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

// author: Seong Yong-ju ( @sei40kr )

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

using namespace std;

struct edge {
  int to, cost;
};

void dfs(list<edge> *p_tree, long *p_dp, int i, long cost) {
  if (0 <= p_dp[i]) {
    return;
  }

  p_dp[i] = cost;
  for (auto &edge : p_tree[i]) {
    dfs(p_tree, p_dp, edge.to, cost + edge.cost);
  }
}

int main() {
  cin.tie(nullptr);

  int n;
  cin >> n;
  list<edge> tree[n];
  REP(i, n - 1) {
    int a, b, c;
    cin >> a >> b >> c;
    --a;
    --b;

    tree[a].push_back(edge{b, c});
    tree[b].push_back(edge{a, c});
  }

  int q, k;
  cin >> q >> k;
  --k;

  long dp[n];
  fill(dp, dp + n, -1);
  dfs(tree, dp, k, 0);

  REP(i, q) {
    int x, y;
    cin >> x >> y;
    --x;
    --y;
    cout << (dp[x] + dp[y]) << endl;
  }
}


Measured memory_bytes: 15104
#include<bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef vector<pair<ll, ll>> pll;
 
#define mod 1000000007
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define popcount(x) __builtin_popcountll(x)
 
const long double PI = acos(-1);
 
ll gcd(ll a,ll b){return b ? gcd(b,a%b) : a;}
ll lcm(ll a,ll b){return a / gcd(a,b) * b;}
ll stringcount(string s, char c){return count(s.cbegin(), s.cend(), c);}
bool isInteger(double x){return floor(x) == x;}

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  
  string s;
  cin >> s;
  ll ans = 700;
  cout << ans + (s[0]=='o')*100 + (s[1]=='o')*100 + (s[2]=='o')*100 << endl;
  return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;

namespace Miscelleneous {
   class Program {
      public static int cin() { return int.Parse(Console.ReadLine()); }
      static HashSet<int> Prime;
      static void Main(string[] args) {
         Filt(1<<15);
         int n, Res = 0;
         while (true) { 
            n=cin();
            if (n==0) return;
            if ((n&1)==1)
               Res=Prime.Contains(n-2) ? 1 : 0;
            else {
               for (int j = 2; j<=n>>1; j++)
                  if (Prime.Contains(j)&&Prime.Contains(n-j))
                     Res++;
            }
            Console.WriteLine(Res);
            Res=0;
         }
      }
      static void Filt(int a) { 
         bool[] Compose = new bool[a];
         Compose[0]=true;
         for (int j = 2; j<=Math.Sqrt(a); j++) {
            if (Compose[j-1]) continue;
            for (int k = 2; k*j<=a; k++) Compose[k*j-1]=true;
         }
         Prime = new HashSet<int>(Compose.Select((i,j)=>(i?0:j+1)).Where(i=>i>0));
      }
   }
}

Measured memory_bytes: 10140