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

#define pu push_back
#define fi first
#define se second
#define mp make_pair
#define int long long
#define pii pair<int,int>
#define mm (s+e)/2
#define all(x) x.begin(), x.end()
#define For(i, st, en) for(int i=st; i<en; i++)
#define tr(x) for(auto it=x.begin(); it!=x.end(); it++)
#define fast std::ios::sync_with_stdio(false);cin.tie(NULL);
#define sz 200000
signed main()
{
	
		int x,n;
cin>>x>>n;
set<int>  ss;
for(int i=0;i<n;i++)
{
	int a;
	cin>>a;
	ss.insert(a);
}
for(int i=0;i<=20000;i++)
{
	int y=x-i;
	if(ss.find(y)==ss.end())
	{
		cout<<y<<endl;
		break;
	}
	 y=x+i;
	if(ss.find(y)==ss.end())
	{
		cout<<y<<endl;
		break;
	}
}
	
}


Measured memory_bytes: 3628
n,m = map(int,input().split())
ben = n*(n-1)//2
ans = [ben]
a = []
b = []
for _ in range(m):
  ai,bi = map(int,input().split())
  a.append(ai)
  b.append(bi)
a.reverse()
b.reverse()
class UnionFind:
    def __init__(self, n):
        self.par = [i for i in range(n+1)]
        self.rank = [0] * (n+1)
    def find(self, x):
        if self.par[x] == x:
            return x
        else:
            self.par[x] = self.find(self.par[x])
            return self.par[x]
    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if self.rank[x] < self.rank[y]:
            self.par[x] = y
        else:
            self.par[y] = x
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1
    def same_check(self, x, y):
        return self.find(x) == self.find(y)
u = UnionFind(n)
size = [1 for _ in range(n+1)]
for i in range(m):
  ai = a[i]
  bi = b[i]
  if u.same_check(ai,bi):
    ans.append(ben)
    u.union(ai,bi)
  else:
    x = u.find(ai)
    y = u.find(bi)
    ben -= size[x]*size[y]
    ans.append(ben)
    if u.rank[x] < u.rank[y]:
      size[y] = size[x]+ size[y]
    else:
      size[x] = size[x]+size[y]
    u.union(ai,bi)
    
for j in range(m):
  print(ans[m-1-j])

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

int main() {
  int n,i,c=0;
  cin >> n;
  vector<int> p(n);
  for(i=0; i<n; i++)
    cin >>  p.at(i);
  
  for(i=0; i<n-2; i++)
    if(p.at(i+1)>min(p.at(i),p.at(i+2)) && p.at(i+1)<max(p.at(i),p.at(i+2)))
      c++;
  cout << c << endl;
}

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

using namespace std;

const int MAX_N = 2e5 + 200, INF = 0x3f3f3f3f;

int n, pi[MAX_N], tag[MAX_N], suf[MAX_N];
char str[MAX_N];

struct SegmentTree
{

    int nodes[MAX_N << 2];

#define lson (p << 1)
#define rson ((p << 1) | 1)
#define mid ((l + r) >> 1)

    void build(int l, int r, int p)
    {
        if (l == r)
            return (void)(nodes[p] = -INF + 1);
        build(l, mid, lson), build(mid + 1, r, rson);
        nodes[p] = max(nodes[lson], nodes[rson]);
    }

    void update(int qx, int l, int r, int p, int val)
    {
        if (l == r)
            return (void)(nodes[p] = val);
        if (qx <= mid)
            update(qx, l, mid, lson, val);
        else
            update(qx, mid + 1, r, rson, val);
        nodes[p] = max(nodes[lson], nodes[rson]);
    }

    int query(int ql, int qr, int l, int r, int p)
    {
        if (ql <= l && r <= qr)
            return nodes[p];
        int ret = -INF;
        if (ql <= mid)
            ret = max(ret, query(ql, qr, l, mid, lson));
        if (mid < qr)
            ret = max(ret, query(ql, qr, mid + 1, r, rson));
        return ret;
    }

#undef mid
#undef rson
#undef lson

} tr[2];

bool check(int max_val, int const_term)
{
    if (const_term < 0)
        return false;
    if (const_term & 1)
        return tr[1].query(max_val, n, 1, n, 1) >= const_term;
    else
        return tr[0].query(max_val, n, 1, n, 1) >= const_term;
}

int main()
{
    scanf("%d", &n);
    for (int i = 1, pre_max = 0; i <= n; i++)
    {
        scanf("%d", &pi[i]), tag[i] = 1;
        if (pi[i] > pre_max)
            pre_max = pi[i], tag[i] = 2;
    }
    tr[1].build(1, n, 1);
    for (int i = n; i >= 1; i--)
    {
        int max_val[2] = {tr[0].query(pi[i], n, 1, n, 1), tr[1].query(pi[i], n, 1, n, 1)};
        tr[1].update(pi[i], 1, n, 1, tag[i] + max_val[!(tag[i] & 1)]), tr[0].update(pi[i], 1, n, 1, tag[i] + max_val[(tag[i] & 1)]);
    }
    for (int i = n; i >= 1; i--)
        suf[i] = suf[i + 1] + tag[i] - 1;
    int cntX = 0, cntY = 0, maxX = 0, maxY = 0;
    for (int i = 1; i <= n; i++)
    {
        tr[1].update(pi[i], 1, n, 1, 1 - INF), tr[0].update(pi[i], 1, n, 1, 0);
        if (check(maxY, cntX + suf[i + 1] - cntY + (pi[i] > maxX)))
            str[i] = '0', cntX += pi[i] > maxX, maxX = max(maxX, pi[i]);
        else if (check(max(maxX, pi[i]), cntY + suf[i + 1] - cntX - (pi[i] > maxX)))
            str[i] = '0', cntX += pi[i] > maxX, maxX = max(maxX, pi[i]);
        else
            str[i] = '1', cntY += pi[i] > maxY, maxY = max(maxY, pi[i]);
    }
    if (cntX != cntY)
        puts("-1");
    else
        printf("%s\n", str + 1);
    return 0;
}

Measured memory_bytes: 9216
import bisect

n = int(input())
a = sorted([int(v) for v in input().split()])
b = sorted([int(v) for v in input().split()])
c = sorted([int(v) for v in input().split()])

on_b_nums = []
num = 0
for v in b:
    num += bisect.bisect_left(a, v)
    on_b_nums.append(num)

on_c_nums = []
for v in c:
    i = bisect.bisect_left(b, v)
    if i > 0:
        on_c_nums.append(on_b_nums[i-1])
    else:
        on_c_nums.append(0)

print(sum(on_c_nums))

Measured memory_bytes: 23092
#include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 99999999999999999
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;



#define SIZE 1005

int N;
int table[SIZE];
bool check[SIZE];
map<int,int> MAP;


int main(){

	scanf("%d",&N);
	int minimum = BIG_NUM;

	for(int i = 0; i < N; i++){

		check[i] = false;
	}

	vector<int> V;

	for(int i = 0; i < N; i++){

		scanf("%d",&table[i]);
		V.push_back(table[i]);
		minimum = min(minimum,table[i]);
	}

	sort(V.begin(),V.end());
	for(int i = 0; i < N; i++){

		MAP[V[i]] = i;
	}

	int ans = 0;
	for(int i = 0; i < N; i++){
		if(check[i] == true || MAP[table[i]] == i)continue;

		int num = 1;
		int group_min = BIG_NUM;
		int tmp_sum = 0;
		int index = i;

		while(true){
			tmp_sum += table[index];
			group_min = min(group_min,table[index]);
			check[index] = true;

			index = MAP[table[index]];
			if(check[index]){

				break;
			}
			num++;
		}

		if(num == 2){
			ans += tmp_sum;
			continue;
		}

		ans += min(tmp_sum+(num-2)*group_min,tmp_sum+(num+1)*minimum+group_min);
	}

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

	return 0;
}



Measured memory_bytes: 3320
#pragma GCC optimize ("O3")
#pragma GCC target ("avx")
//#include<bits/stdc++.h>
#include<cstdio>
#include<cstring>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please

//トライ木って何よ
int T[100001][2];
int D[100001];

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


	int N;
	ll L;
	scanf("%d", &N);
	scanf("%lld", &L);
	getchar_unlocked();
	int k = 0;
	rep(i, N) {
		int mae = 0;
		int d = -L;
		char c;
		while ((c = getchar_unlocked()) >= '0') {
			int C = c - '0';
			if (!T[mae][C]) {
				T[mae][C] = ++k;
				D[k] = d;
			}
			mae = T[mae][C];
			d++;
		}
	}
	ll kotae = 0;
	rep1(i, k) {
		kotae ^= 1ll << (D[i] & -D[i]);
	}

	if (kotae) printf("Alice\n");
	else printf("Bob\n");

	Would you please return 0;
}

Measured memory_bytes: 1280
#include <iostream>
#include <cmath>

using namespace std;

int main()
{
    int s, d;
    char dummy;

    double px = 0.0, py = 0.0;
    double dir = 90.0;

    while( cin >> s >> dummy >> d ) {
        if ( s == 0 && d == 0 )
            break;

        px += cos( dir * M_PI / 180.0 ) * s;
        py += sin( dir * M_PI / 180.0 ) * s;
        dir -= d;
    }

    cout << static_cast<int>( px ) << endl << static_cast<int>( py ) << endl;
}

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

int main() {
  int N,D;
  cin >> N >>D;
  
  int x=(2*D)+1;
  
  int y=(N/x);
  
  if (N%x==0){
    cout << y <<endl;
  }
  else{
    cout << y+1 <<endl;
  }
}

Measured memory_bytes: 256
n, m, c = map(int, input().split())
b= list(map(int, input().split()))
a=[]
for i in range(n):
    a.append(list(map(int, input().split())))
    
ans = 0
for i in a:
    point = 0
    for j in range(len(b)):
        point = point + i[j]*b[j]
    if point > -c:
        ans = ans +1
print(ans)

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

signed main(){
    int N, cm = 0, ca = 0, cr = 0, cc = 0, ch = 0; cin >> N;
    for(int i = 0; i < N; i++){
        string s; cin >> s;
        if(s[0] == 'M') cm++;
        if(s[0] == 'A') ca++;
        if(s[0] == 'R') cr++;
        if(s[0] == 'C') cc++;
        if(s[0] == 'H') ch++;
    }
    int ans = 0;
    ans += cm*ca*cr + cm*ca*cc + cm*ca*ch + cm*cr*cc + cm*cr*ch + cm*cc*ch;
    ans += ca*cr*cc + ca*cr*ch + ca*cc*ch + cr*cc*ch;
    cout << ans << endl;
}

Measured memory_bytes: 256
//Find the probability of having more heads than tails
#include<bits/stdc++.h>
using namespace std;
int n;
vector<double >prob(2999,0);
vector<vector<double > >memo(2999,vector<double>(3000,-1));
double calc(int index,int nheads){
	if(index==n && nheads<=n/2)return 0;
  	if(index==n && nheads>n/2)return 1;
  	if(memo[index][nheads]!=-1)return memo[index][nheads];
  else{
  	//Iam tail
  	double maxi;
    maxi = (1-prob[index])*calc(index+1,nheads);
    //Iam head
    maxi += prob[index]*calc(index+1,nheads+1);
    memo[index][nheads]=maxi;
    return maxi;
  }
}
int main(){
	cin>>n;
	for(int i=0;i<n;i++)cin>>prob[i];
cout.precision(9);
  cout<<calc(0,0);
}
//what is a proper subproblem
//P(more heads)given first is tail + P(more heads) given first is head
//happens im
//P(more heads from 1)

Measured memory_bytes: 74032
#include <stdio.h>

int main(){
	int x = 1;
	int y = 1;
	while( scanf("%d %d", &x, &y) != EOF ){
		if(x == 0 && y == 0) {
			break;
		} else {
			if( x < y) {
				printf("%d %d\n", x, y);
			} else {
				printf("%d %d\n", y, x);
			}
		}
	}

	return 0;
}

Measured memory_bytes: 596
a, b=map(int, input().split())
import math
la=math.ceil(a/0.08)
ua=(a+0.9999999)//0.08
lb=math.ceil(b/0.1)
ub=(b+0.9999999)//0.1

if la<=lb and lb<=ua:
  print(lb)
elif lb<=la and la<=ub:
  print(la)
else:
  print(-1)

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

int main() {
	int N;
	while (~scanf("%d", &N)) {
		vector<int> A(N);
		for (int i = 0; i < N; ++ i)
			scanf("%d", &A[i]);
		int sum = accumulate(A.begin(), A.end(), 0);
		bitset<2000 * 2000 + 1> S;
		S.set(0);
		for (int x : A)
			S |= S << x;
		int ans = (sum + 1) / 2; 
		while (!S[ans]) ++ ans;
		printf("%d\n", ans);
	}
	return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define mod 1000000007
#define ll long long
using namespace std;
const int N=2*1e5+100,M=4100;
int n;
int a[N],b[N],MAX;
ll fac[M*2],inv[M*2],dp[M][M];
inline ll m_pow(ll a,int b)
{
	ll ans=1;
	while (b)
	{
		if (b&1) ans=(ans*a)%mod;
		b>>=1;
		a=(a*a)%mod;
	}
	return ans;
}
inline void add(ll &a,ll b){a=(a+b)%mod;}
inline void mul(ll &a,ll b){a=(a*b)%mod;}
inline void sep(ll &a,ll b){a=(a*m_pow(b,mod-2))%mod;}
inline void del(ll &a,ll b){a=(a-b+mod)%mod;}
int main()
{
	scanf("%d",&n);
	for (int i=1;i<=n;i++)
	{
		scanf("%d%d",&a[i],&b[i]);
		dp[2000-a[i]][2000-b[i]]++;
		MAX=max(MAX,a[i]+b[i]);
	}
	fac[0]=1;
	for (int i=1;i<=2*MAX;i++) fac[i]=(fac[i-1]*i)%mod;
	inv[2*MAX]=m_pow(fac[2*MAX],mod-2);
	for (int i=2*MAX-1;i>=1;i--) inv[i]=(inv[i+1]*(i+1))%mod;
	for (int i=0;i<=4000;i++)
	{
		for (int j=0;j<=4000;j++)
		{
			if (i!=0) add(dp[i][j],dp[i-1][j]);
			if (j!=0) add(dp[i][j],dp[i][j-1]);
		}
	}
	ll ans=0,num;
	for (int i=1;i<=n;i++)
	{
		add(ans,dp[a[i]+2000][b[i]+2000]);
		num=fac[a[i]*2+b[i]*2];
		mul(num,inv[a[i]*2]);mul(num,inv[b[i]*2]);
		del(ans,num);
	}
	sep(ans,2);
	printf("%lld\n",ans);
}

Measured memory_bytes: 133684
//----------------------------templates
    #pragma GCC optimize ("Ofast")
    #pragma GCC target ("tune=native")
    #pragma GCC target ("avx")
    //----------------------------
    #include <bits/stdc++.h>
    using namespace std;

    typedef long long ll;
    typedef unsigned long long ull;
    #define int ll

    #define FOR(i,j,n) for (int i=(int)(j);i<(n);i++)
    #define REP(i,n) for (int i=0;i<(int)(n);i++)
    #define REPS(i,n) for (int i=1;i<=(int)(n);i++)
    #define REPN(i,n) for (int i=(int)(n)-1;i>=0;i--)
    #define REPNS(i,n) for (int i=(int)(n);i>0;i--)

    #define I(n) scanf("%lld", &(n))
    #define LL(n) scanf("%lld", &(n))
    #define pb(n) push_back((n))
    #define mp(i,j) make_pair((i),(j))
    #define eb(i,j) emplace_back((i),(j))
    #define y0 y3487465
    #define y1 y8687969
    #define j0 j1347829
    #define j1 j234892
    #define uniq(v) v.erase( unique(v.begin(), v.end()), v.end() )

    #define all(x) (x).begin(),(x).end()
    #define sz(x) ((int)(x).size())

    typedef vector<int> vi;
    typedef pair<int,int> pi;
    typedef vector<pi> vpi;
    typedef vector<vi> vvi;
    typedef vector<vpi> vvpi;
    typedef vector<vvi> vvvi;

    const int mod = 1000000007;

//--------------------------------------------


int n,m;
vpi query;

int keta(int x, int di){
    while(di){
        x /= 10;
        di--;
    }
    return x % 10;
}

signed main(){
    I(n); I(m);
    REP(i,m){
        int si, ci;
        I(si); I(ci);
        query.eb(n-si, ci);
    }
    int st,en;
    if (n == 1) {
        st = 0; en = 10;
    } else if (n == 2){
        st = 10; en = 100;
    } else {
        st = 100; en = 1000;
    }
    FOR(x,st,en){
        bool flag = true;
        for(auto q: query){
            flag &= keta(x, q.first) == q.second; 
        }
        if (flag){
            cout << x << endl;
            return 0;
        }
    }
    cout << -1 << endl;
}

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

using namespace std;


int frog2(const vector<int>& hs, int K) {
    vector<int> res;
    int upper_limit = min(K+1, static_cast<int>(hs.size()));
    for (size_t i = 0; i < upper_limit; ++i)
    {
        res.push_back(abs(hs[i]-hs[0]));
    }
    
    for (size_t i = K+1; i < hs.size(); ++i)
    {
        int j=0;
        int cur_min = res[i-j-1] + abs(hs[i-j-1] - hs[i]);
        for (size_t j = 1; j < K; ++j)
        {
            int temp = res[i-j-1] + abs(hs[i-j-1] - hs[i]);
            if (temp < cur_min) {
                cur_min=temp;
            }
        }
        res.push_back(cur_min);
    }
    
    return res[res.size()-1];
}


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

    int N,K;
    cin >> N >> K;
    vector<int> hs;
    int h;
    for (size_t i = 0; i < N; ++i)
    {  
        cin>>h;
        hs.push_back(h);
    }

    cout << frog2(hs, K) << "\n";

}


Measured memory_bytes: 1400
using System;
class Program
{
    static void Main(string[] args)
    {
        int n = int.Parse(Console.ReadLine());
        string s = Console.ReadLine();

        if (n % 2 != 0)
        {
            Console.WriteLine("No");
            System.Environment.Exit(0);
        }
        string t = s.Substring(0,n/2);
        string t2 = s.Substring(n/2,n/2);

        if(t == t2)
        {
            Console.WriteLine("Yes");
        }
        else
        {
            Console.WriteLine("No");
        }
    }
}

Measured memory_bytes: 11092
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define rep(i, n) FOR(i, 0, n)
#define whole(x) (x).begin(),(x).end()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
using P = pair<int, int>;
#define debug(var) cerr << "[" << #var << "] " << var << endl
#define chmin(x, y) x = min(x, y)
const ll mod = 1000000007;
const int dx[] = {-1,0,1,0};
const int dy[] = {0,-1,0,1};


int main(){
    char b;
    cin >> b;
    string s = "ACTG";
    int x = 0;
    rep(i, 4) {
        if (s[i]==b) x = i;
    }
    char ans = s[(x+2)%4];
    
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <map>
#include <stack>
#include <queue>
#include <sstream>
#define INF 0x3f3f3f3f
using namespace std;

typedef long long ll;
const int mod = 1e9 + 7;
const ll maxn = 1000005;
const double pi = acos(-1.0);

int n,m;

int main()
{
    while(cin >> n >> m)
    {
        int l = 0,r = 0;
        int nowl = -1,nowr = INF;
        for(int i = 0; i < m; i ++)
        {
            int x,y;
            cin >> x >> y;
            l = min(x,y);
            r = max(x,y);
            nowl = max(nowl, l);
            nowr = min(nowr, r);
        }
        nowl = max(nowl, 1);
        nowr = min(nowr, n);
        if(nowr >= nowl)
            cout << nowr - nowl + 1 << endl;
        else
            cout << 0 << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define all(a) (a).begin(), (a).end()
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define sz() size()
#define fr first
#define sc second
#define pb push_back
#define er erase
#define in insert
#define pi pair<int,int>
#define pii pair<pair<int,int>,int>
#define mp make_pair
#define int long long
#define rc(s) return cout<<s,0
#define rcc(s) cout<<s,exit(0)
using namespace std;

const int mod=1e9+7;
const int modx=998244353;
const int per=666013;

int n,dp[1005][20100];

struct block{
    int x,y,z;
    bool operator<(block &blok){
        return x+y < blok.x+blok.y;
    }
}bloc[1005];

int32_t main(){
    ios_base::sync_with_stdio(false);cin.tie(0);cerr.tie(0);cout.tie(0);
    srand(chrono::steady_clock::now().time_since_epoch().count());
    cin >> n;
    for(int i=1;i<=n;i++){
        cin >> bloc[i].x >> bloc[i].y >> bloc[i].z;
    }
    sort(bloc+1,bloc+n+1);
    for(int i = 1; i <= n ; i++){
        for(int w = 0 ; w <= 20005 ; w++){
            dp[i][w] = dp[i-1][w];
            if(w-bloc[i].x >= 0 && w-bloc[i].x <=bloc[i].y ) dp[i][w] = max(dp[i][w],dp[i-1][w-bloc[i].x] + bloc[i].z);
        }
    }
    int res=0LL;
    for(int i=0LL;i<=20005LL;i++) res=max(res,dp[n][i]);
    cout << res;
}


Measured memory_bytes: 157952
def solve(dp, a, i, m):
  if m in dp[i]:
    return dp[i][m]

  if m == 0:
    dp[i][m] = True
  elif i >= len(a):
    dp[i][m] = False
  elif solve(dp, a, i+1, m):
    dp[i][m] = True
  elif solve(dp, a, i+1, m-a[i]):
    dp[i][m] = True
  else:
    dp[i][m] = False

  return dp[i][m]

N = int(input())
A = list(map(int, input().split()))
Q = int(input())
M = list(map(int, input().split()))

dp = {}
for i in range(N+1):
  dp[i] = {}

for m in M:
  if solve(dp, A, 0, m):
    print('yes')
  else:
    print('no')


Measured memory_bytes: 7532
#include <bits/stdc++.h>
typedef long long ll;
#define rep(i,n) for(ll i=0;i<(n);i++)
#define repr(i,n) for(ll i=(n-1);i>=0;i--)
#define pb push_back
#define mp make_pair
#define all(x) x.begin(),x.end()
#define br cout << "\n";
using namespace std;
const int INF = 1e9;
const int MOD = 1e9+7;
using Graph = vector<vector<ll>>;
template<class T> inline bool chmin(T &a, T b) { if(a > b){ a = b; return true;} return false;}
template<class T> inline bool chmax(T &a, T b) { if(a < b){ a = b; return true;} return false;}

// 0 false, 1 true 
// string to int : -48
// ceil(a)  1.2->2.0
// c++17	g++ -std=c++17 a.cpp

int main() {
    std::cout << std::fixed << std::setprecision(15);
    ll k;
    cin >> k;
    vector<ll> vec{1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
    cout << vec[k-1] << endl;

}

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

using namespace std;
using llong = long long int;

#define rep(i, n) for (int i = 0; i < n; ++i)
#define stl_rep(itr, x) for (auto itr = x.begin(); itr != x.end(); ++itr)
#define stl_repr(itr, x) for (auto itr = x.rbegin(); itr != x.rend(); ++itr)
#define all(x) x.begin(), x.end()
#define allr(x) x.rbegin(), x.rend()

const static int MOD = 1000000007;
const static int IINF = INT_MAX;
const static llong LINF = LLONG_MAX;
const static int dx[4] = {1, 0, -1, 0};
const static int dy[4] = {0, 1, 0, -1};

/* --------------- template start --------------- */
template <typename T> 
struct BinaryIndexTree { // [1, n]
    vector<T> array;
    int n;

    BinaryIndexTree(int _n) {
        array.resize(_n + 1, 0);
        n = _n;
    }

    T cumsum(int i) {
        T s = 0;
        while(i > 0) {
            s += array[i];
            i -= i & -i;
        }

        return s;
    }

    T sum(int i, int j) {
        T ret_i = cumsum(i - 1);
        T ret_j = cumsum(j);

        return ret_j - ret_i;
    }

    void add(int i, T x) {
        while (i <= n) {
            array[i] += x;
            i += i & -i;
        }
    }
};

template<typename T>
struct UnionFind {
    vector<int> par;
    vector<T> sz;

    UnionFind(int n) {
        par.resize(n);
        sz.resize(n);
        for (int i = 0; i < n; ++i) {
            par[i] = i;
            sz[i] = 1;
        }
    }

    int find_root(int x) {
        return par[x] == x ? x : par[x] = find_root(par[x]);
    }

    bool same(int x, int y) {
        return find_root(x) == find_root(y);
    }

    void unite(int x, int y) {
        x = find_root(x);
        y = find_root(y);
        if (x == y) return;
        
        if (sz[x] < sz[y]) swap(x, y);
        sz[x] += sz[y];
        par[y] = x;
    }

    T size_of_tree(int x) {
        return sz[find_root(x)];
    }
};
/* --------------- template end --------------- */

/* --------------- function start --------------- */
llong my_gcd(llong a, llong b) {
    return (a ? my_gcd(b % a, a) : b);
}
llong my_lcm(llong a, llong b) {
    return a * b / my_gcd(a, b);    
}

llong facmod(llong n) {
    if (n == 0) return 1;

    llong res = n;
    for (int i = n - 1; i > 0; --i) {
        res = (res * i) % MOD;
    }

    return res;
}
llong powmod(llong a, llong n) {
    llong res = 1;
    while (n > 0) {
        if (n & 1) res = (res * a) % MOD;
        a = (a * a) % MOD;
        n >>= 1;
    }

    return res;
}
llong modinv(llong n) {
    return powmod(n, MOD - 2);
}
llong combmod(llong n, llong k) {
    llong res = 1;
    for (int i = 0; i < k; ++i) {
        res = (res * (n - i)) % MOD;
    }
    res = (res * modinv(facmod(k))) % MOD;

    return res;
}
/* --------------- function end --------------- */

int cnt = 0;
llong recur(llong x) {
    if (x == 0) return 0;
    ++cnt;
    return recur(x / 2);
}
int main(int argc, char *argv[]) {
    cin.tie(0);
    ios::sync_with_stdio(false);

    int h, w;
    cin >> h >> w;
    cout << ceil((double)h / w) << endl;
    
    return 0;
}

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

int64_t CUT(bitset<10> P,vector<char> S,vector<int64_t> c){
  int size=S.size()-1;
  string k;
  for(int i=0;i<S.size();i++){
    k=S.at(size-i)+k;
    if(P.test(i)){
      int64_t a=stoll(k);
      c.push_back(a);
      k="";
    }
  }
  if(k!=""){
     int64_t a=stoll(k);
     c.push_back(a);
  }
  int64_t sum=0;
  for(int i=0;i<c.size();i++){
    sum+=c.at(i);
  }
  return sum;
}


int main(){
  vector<char> S;
  for(int i=0;i<11;i++){
    char s='a';
    cin>>s;
    if(s!='a')
    S.push_back(s);
  }
  int64_t sum=0;
  int PS=S.size()-1;
  for(int i=0;i<(1<<PS);i++){
    bitset<10> P(i);
    vector<int64_t> c;
    sum+=CUT(P,S,c);
   
  }
  cout<<sum<<endl;
}

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

using namespace std;

int brute(int argc, char *argv[]) {
   return 0;
}

int tests(int argc, char *argv[]) {
   return 0;
}

int _main(int argc, char *argv[]) {
   string s;
   cin >> s;
   int c = 0;
   for(int i = 1; i < s.size() - 1; ++i){
      ++c;
   }
   if(s[0] == s[s.size() - 1]) --c;
   if(c % 2 == 0) cout << "Second" << endl;
   else cout << "First" << endl;
   return 0;
}

int main(int argc, char *argv[]){
   if(argc >= 2 && argv[1][0] == '1') {
      brute(argc, argv);
   } else if(argc >= 2 && argv[1][0] == '2') {
      tests(argc, argv);
   } else {
      _main(argc, argv);
   }
   return 0;
}


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

using namespace std;

int main(){
	int n;
	long long ans = 0;
	cin >> n;
	vector<long long> a(n);
	for(int i = 0; i < n; i++){
		cin >> a[i];
	}	
	int r = 1;
	long long t = a[0];
	for(int l = 0; l < n; l++){
		while(r < n){
			if(t + a[r] == (t ^ a[r])){
				t += a[r];
				r++;
			}else{
				break;
			}
		}
		ans += r - l;
		t -= a[l];
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const ll INF = 1LL << 60;
const int MAX = 1000000010;
const ll MOD = 1000000007;
const double PI = acos(-1);

int main() {
    int W, H, N; cin >> W >> H >> N;
    vector<vector<int>> F(H, vector<int>(W,1));
    for (int i = 0; i < N; i++) {
        int x, y, a; cin >> x >> y >> a;
        if (a == 1) {
            for (int h = 0; h < H; h++) {
                for (int w = 0; w < x; w++) {
                    F[h][w] = 0;
                }
            }
        } else if (a == 2) {
            for (int h = 0; h < H; h++) {
                for (int w = x; w < W; w++) {
                    F[h][w] = 0;
                }
            }
        } else if (a == 3) {
            for (int h = 0; h < y; h++) {
                for (int w = 0; w < W; w++) {
                    F[h][w] = 0;
                }
            }
        } else if (a == 4) {
            for (int h = y; h < H; h++) {
                for (int w = 0; w < W; w++) {
                    F[h][w] = 0;
                }
            }
        }
    }

    int area = 0;
    for (int h = 0; h < H; h++) {
        for (int w = 0; w < W; w++) {
            if (F[h][w]) area++;
        }
    }

    cout << area << endl;
    return 0;
}

Measured memory_bytes: 3680
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N;string S;cin>>N;cin>>S;
  vector<int> W_L(N,0); //iよりも左側のWの数
  vector<int> E_R(N,0); //iよりも右側のEの数
  for(int i=1;i<N;i++){W_L[i]=W_L[i-1]+(S[i-1]=='W');}
  for(int i=N-2;i>=0;i--){E_R[i]=E_R[i+1]+(S[i+1]=='E');}
  int ans=N;
  for(int i=0;i<N;i++){ans=min(ans,W_L[i]+E_R[i]);}
  cout<<ans;
}

Measured memory_bytes: 2948
import java.io.IOException;
import java.io.InputStream;
import java.util.NoSuchElementException;

public class Main {
	
    public static void main(String[] args) {
    	FastScanner sc = new FastScanner();
    	int n = sc.nextInt();
    	
    	int a = 0;
    	for(int i=0;i<n;i++){
    		a |= sc.nextInt();
    	}
    	
    	System.out.println(Integer.numberOfTrailingZeros(a));
    }
    
}

class FastScanner {
    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;
    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        }else{
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }
    private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
    private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
    public boolean hasNext() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++; return hasNextByte();}
    public String next() {
        if (!hasNext()) throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while(isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }
    public long nextLong() {
        if (!hasNext()) throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while(true){
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            }else if(b == -1 || !isPrintableChar(b)){
                return minus ? -n : n;
            }else{
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }
    public int nextInt() {
        long nl = nextLong();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException();
        return (int) nl;
    }
    public double nextDouble() { return Double.parseDouble(next());}
}

Measured memory_bytes: 21332
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N,K;
  string S;
  cin >> N >> K >> S;
  int count=1;
  for(int i = 1; i < N; i++){
    if(S[i] != S[i-1]){
      count ++;
    }
  }
  cout <<N+min(-1,-count+2*K)<<endl;
}


Measured memory_bytes: 512
/*
    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 = 110;
const int MAXM = 1000;
const int MAXK = 16;
const int MAXQ = 200010;

int main() {
    ios::sync_with_stdio(0);
    cin.tie(nullptr);
    int a, b, c;
    cin >> a >> b >> c;
    swap(a, b);
    swap(a, c);
    cout << a << ' ' << b << ' ' << c;
    return 0;
}


Measured memory_bytes: 256
<?php

fscanf(STDIN, "%d %d %d %d %d", $a, $b, $c, $x, $y);

if ($a + $b < 2 * $c) {
	echo $x * $a + $y * $b, "\n";
	return;
}

if ($x > $y) {
	echo ($x - $y) * min($a, $c * 2) + 2 * $y * $c, "\n";
	return;
}
echo ($y - $x) * min($b, $c * 2) + 2 * $x * $c, "\n";

Measured memory_bytes: 4728
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    int N,K;
    cin >>N>>K;
    int x;
    int sum=0;
    for(int i=0 ;i<N;i++){
    cin>>x;
    
    if(K-x<=x){
        sum+=2*(K-x);
    }
    else {
        sum+=2*x;
    }
    }
    cout << sum << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include <bitset>
#include<iomanip>//小数点以下を精度良く表示
#include <map>
#include<set>

#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include <numeric>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define INF 2000000000
#define INF2 1000000000000000000
#define PI 3.1415926535
#define rep(i,n) for(int i=0;i<(n);i++)
typedef pair<int, int> P;
const ll MOD = 1000000007;
using Graph = vector<vector<int>>;

#define MAX_N 50005//ここにNの最大値を入れる
#define MAX_K 100005




int main() {
    string a, b, c;
    cin >> a >> b >> c;
    reverse(a.begin(), a.end());
    reverse(b.begin(), b.end());
    reverse(c.begin(), c.end());

    char p = a.back();
    a.pop_back();

    while (true) {
        switch (p) {
        case 'a':
            if (a.empty()) {
                cout << "A" << endl;
                return 0;
            }
            p = a.back();
            a.pop_back();
            break;
        case 'b':
            if (b.empty()) {
                cout << "B" << endl;
                return 0;
            }
            p = b.back();
            b.pop_back();
            break;
        case 'c':
            if (c.empty()) {
                cout << "C" << endl;
                return 0;
            }
            p = c.back();
            c.pop_back();
            break;
        }
    }

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <fstream>
#include <string>
#include <vector>
#include <tuple>
#include <deque>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <utility>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstdio>
#include <numeric>
#include <string.h>
#define rep(i, x) for (int i = 0; i < (int)(x); i++)
#define repn(i, x) for (int i = 1; i <= (int)(x); i++)
#define repr(i, x) for (int i = ((int)(x) - 1); i >= 0; i--)
#define reprn(i, x) for (int i = ((int)(x)); i > 0; i--)
#define all(x) (x).begin(),(x).end()
typedef long long int64;
using namespace std;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const int INF = 1<<29;
const long long INFL = 1e18;
const int MOD = 1000000007;
const int MAX = 210000;

int gcd(int a, int b) {
    return b != 0 ? gcd(b, a % b) : a;
}

//逆元を求める関数
long long fac[MAX], finv[MAX], inv[MAX];
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++) {
      fac[i] = fac[i-1] * i % MOD;
      inv[i] = MOD - inv[MOD%i] * (MOD/i) % MOD;
      finv[i] = finv[i-1] * inv[i] % MOD;
    }
}
//組み合わせ
long long COM (int n, int k) {
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n-k] % MOD) % MOD;
}

void solve() {
		int n; cin >> n;
		int ans = 0;
		repn(i, n) {
			int num = i;
			int cnt = 0;
			while (num > 0) {
				num = num / 10;
				cnt++;
			}
			if (cnt % 2 == 1) ans++;
		}
		cout << ans << endl;
    return;
}

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



Measured memory_bytes: 256
//in the name of god
//if you read this code please search about imam hussain
#include<bits/stdc++.h>

using namespace std;

typedef long long ll;

#define pb push_back
#define endl "\n";
#define migmig ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define read freopen("input.txt", "r", stdin);freopen("output.txt", "w", stdout);

const int maxn=1e5+5;
const int mod=1e9+7;
const int inf=1e9;
const int del=728729;

int main(){
	migmig;
	string s;
	ll cnt=0;
	string ss;
	cin>>s>>ss;
	if(s[0]==ss[0]) cnt++;
	if(s[1]==ss[1]) cnt++;
	if(s[2]==ss[2]) cnt++;
	cout<<cnt;
	return 0;
}



Measured memory_bytes: 256
#include<iostream>
#include<cstring>

using namespace std;
bool map[5001][5001];

int main(void){
	int a,b;
	int n;
	int ans=0;
	int x[3000],y[3000];
	while(1){
		cin >> n;
		if(n==0)break;
		ans=0;
		memset(map,0,sizeof(map));
		for(a=0;a<n;a++){
			int xx,yy;
			cin >> xx >> yy;
			x[a]=xx,y[a]=yy;
			map[x[a]][y[a]]=1;
		}
		for(a=0;a<n-1;a++){
			for(b=a+1;b<n;b++){
				int h=x[a]-x[b];
				int w=y[a]-y[b];
				if(x[a]-w>=0 && x[a]-w<=5000 && y[a]+h>=0 &&  y[a]+h<=5000 && x[b]-w>=0 && x[b]-w<=5000 && y[b]+h>=0 && y[b]+h<=5000)if(map[x[a]-w][y[a]+h]==1 && map[x[b]-w][y[b]+h]==1)ans=max(ans,h*h+w*w);
				if(x[a]+w>=0 && x[a]+w<=5000 && y[a]-h>=0 &&  y[a]-h<=5000 && x[b]+w>=0 && x[b]+w<=5000 && y[b]-h>=0 && y[b]-h<=5000)if(map[x[a]+w][y[a]-h]==1 && map[x[b]+w][y[b]-h]==1)ans=max(ans,h*h+w*w);
			}
		}
		cout << ans << endl;
	}
	return 0;
}

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

int main(void){
    using namespace std;
    string code;
    cin >> code;

    bool isBad = false;
    for (int i = 0; i < 3;i++){
        if(code[i]==code[i+1]) {
            isBad = true;
            break;
        }
    }

    cout << (isBad ? "Bad" : "Good") << endl;
    return 0;
}

Measured memory_bytes: 256
import sys
readlines = sys.stdin.readlines
write = sys.stdout.write

def convert(y, m, d):
    if m <= 2:
        m += 12
        y -= 1
    mjd = int(365.25*y) + (y//400) - (y//100) + int(30.59*(m-2)) + d - 678912
    return mjd

def solve():
    A = convert(1868, 9, 8)
    B = convert(1912, 7, 30)
    C = convert(1926, 12, 25)
    D = convert(1989, 1, 8)
    for line in readlines():
        y, m, d = map(int, line.split())
        X = convert(y, m, d)
        if X < A:
            write("pre-meiji\n")
        elif X < B:
            write("meiji %d %d %d\n" % (y - 1867, m, d))
        elif X < C:
            write("taisho %d %d %d\n" % (y - 1911, m, d))
        elif X < D:
            write("showa %d %d %d\n" % (y - 1925, m, d))
        else:
            write("heisei %d %d %d\n" % (y - 1988, m, d))
solve()



Measured memory_bytes: 5620
#include "bits/stdc++.h"
// Begin Header {{{
#define all(x) (x).begin(), (x).end()
#define rep(i, s, n) for (i64 i = (s), i##_limit = (n); i < i##_limit; ++i)
#define repr(i, s, t) for (i64 i = (s), i##_limit = (t); i >= i##_limit; --i)
#define var(type, ...) \
    type __VA_ARGS__;  \
    read(__VA_ARGS__);
#ifndef DBG
#define dump(...)
#endif
using namespace std;
using i64 = int_fast64_t;
using pii = pair<i64, i64>;
template <class T, class U>
inline bool chmax(T &a, const U &b) {
    return b > a && (a = b, true);
}
template <class T, class U>
inline bool chmin(T &a, const U &b) {
    return b < a && (a = b, true);
}
constexpr int INF = 0x3f3f3f3f;
constexpr i64 LINF = 0x3f3f3f3f3f3f3f3fLL;

template <class T>
inline vector<T> makeV(const T &initValue, size_t sz) {
    return vector<T>(sz, initValue);
}

template <class T, class... Args>
inline auto makeV(const T &initValue, size_t sz, Args... args) {
    return vector<decltype(makeV<T>(initValue, args...))>(
        sz, makeV<T>(initValue, args...));
}

template <class T>
inline istream &operator>>(istream &is, vector<T> &vec) {
    for (auto &e : vec) is >> e;
    return is;
}

inline void read() {}

template <class Head, class... Tail>
inline void read(Head &head, Tail &... tail) {
    cin >> head;
    read(tail...);
}

inline void print() { cout << "\n"; }

template <class Head, class... Tail>
inline void print(Head &&head, Tail &&... tail) {
    cout << head;
    if (sizeof...(tail)) cout << ' ';
    print(forward<Tail>(tail)...);
}

template <class T>
inline ostream &operator<<(ostream &os, const vector<T> &vec) {
    static constexpr const char *delim[] = {" ", ""};
    for (const auto &e : vec) os << e << delim[&e == &vec.back()];
    return os;
}

template <class Container>
struct Rev {
    Container &x_;
    inline Rev(Container &x) : x_(x) {}
    inline auto begin() { return rbegin(x_); }
    inline auto end() { return rend(x_); }
};
// }}} End Header

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    var(int, N);
    vector<int> P(N), Q(N);
    read(P);
    read(Q);

    vector<int> X(N);
    iota(all(X), 1);

    int a = 0;
    int b = 0;
    int cnt = 0;
    do {
        if (X == P) a = cnt;
        if (X == Q) b = cnt;
        ++cnt;
    } while (next_permutation(all(X)));

    print(abs(a - b));

    return 0;
}


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

int main() {
    int n;
    cin >> n;
    int *list = (int *)malloc(sizeof(int) * n);
    int input;
    int sum = 0;
    for (int m = 0; m < n; ++m) {
        cin >> input;
        list[m] = input;
        sum += input;
    }

    int p = round(sum / (double)n);
    int answer = 0;
    for (; n > 0; --n) {
        answer += pow(list[n-1] - p, 2);
    }
    cout << answer;
}

Measured memory_bytes: 256
#include<cstdlib>
#include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#include<string>
#include<cstring>
using namespace std;
typedef long long lng;
typedef unsigned long long ulng;

#define pb push_back
#define SZ(a) int((a).size())
#define ALL(a) (a).begin(), (a).end()
#define FOR(i,a,b) for(int i=(a); i<=(b); ++i)
#define FORD(i,b,a) for(int i=(b); i>=(a); --i)
#define REP(i,n) FOR(i,0,n-1)
#define UNIQUE(a) a.erase(unique(ALL(a)), a.end())

lng power(lng b, lng e) {lng sol=1; while(e>0) {if(e&1) {sol=sol*b;} e>>=1; b*= b;} return sol;}

int N, K;
int a[100000];


int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> N >> K;
    REP(i, N) cin >> a[i];

    int p = 0;
    REP(i, N) {
        if(a[i] < a[p]) p = i;
    }

    int cnt = 0;
    int i = 0;
    while(i < N-1) {
        cnt++;
        i += K - 1;
    }

    cout << cnt << endl;
}


Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <array>
 
int get_hit(std::vector<u_int> *A, std::vector<u_int> *B)
{
    u_int hit = 0;
    for(u_int i = 0; i < A -> size(); ++i)
        if(A -> at(i) == B -> at(i))
            ++hit;
             
    return hit;
}
 
int get_blow(std::vector<u_int> *A, std::vector<u_int> *B)
{
    u_int blow = 0;
    for(u_int i = 0; i < A -> size(); ++i){
        for(u_int j = 0; j < B -> size(); ++j){
            if(A -> at(i) == B -> at(j)){
                if(i != j)
                    ++blow;
                break;
            }
        }
    }
             
    return blow;
}
 
int main()
{
    const u_int number = 4;
    std::vector<u_int> A;
    std::vector<u_int> B;
    A.reserve(number);
    B.reserve(number);
     
    std::array<u_int, number> array;
    bool flag = true;
    while(std::cin >> array[0] >> array[1] >> array[2] >> array[3]){
        if(flag){
            A.clear();
            B.clear();
            for(u_int i = 0; i < number; ++i)
                A.push_back(array.at(i));
            flag = !flag;
        }else{
            for(u_int i = 0; i < number; ++i)
                B.push_back(array.at(i));
            std::cout << get_hit(&A, &B) << " " << get_blow(&A, &B) << std::endl;
            flag = !flag;
        }
    }
         
    return 0;
}

Measured memory_bytes: 1196
s_list = list(input())
a_num = 0
z_num = 0
for i,a in enumerate(s_list):
    if a == 'A':
        a_num = i
        break
rs_list = reversed(s_list)
for j,z in enumerate(rs_list):
    if z == 'Z':
        z_num = j
        break
if z_num == 0:
    print(len(s_list[a_num:]))
else:
    print(len(s_list[a_num:-z_num]))

Measured memory_bytes: 6304
#include <stdio.h>
#include <stdlib.h>

int n=0;
int m=0;
int G[100]={1};
long long sum=0;

void insertionsort(int a[],int n,int g){
    for(int i=g;i<n;i++){
        int v=a[i];
        int j=i-g;
        while(j>=0&&a[j]>v){
            a[j+g]=a[j];
            j=j-g;
        }
        a[j+g]=v;
    }
}
void shellsort(int a[], int n){
    
    int i=1;
    
    while(3*G[i-1]+1<n){
        G[i]=G[i-1]*3+1;
        i++;
    }
    m=i;
    
    for(int i=m-1;i>=0;i--)
        insertionsort(a,n,G[i]);
    
    if(n%2==0){
        for(i=0;i<n;i++)
            sum+=abs(a[i]-a[n/2]);
    }
    else{
        for(i=0;i<n;i++)
            sum+=abs(a[i]-a[(n-1)/2]);
    }
    printf("%lld",sum);
    
}



 
int main(){
    int n;
    scanf("%d",&n);
    int i;
    int a[n],cpy[n];
    for(i=0;i<n;i++){
        scanf("%d",&cpy[i]);
        a[i]=cpy[i]-(i+1);
    }
    shellsort(a,n);
}

Measured memory_bytes: 1664
#include <bits/stdc++.h>
using namespace std;
 
#define rep(i, N) for (int i = 0; i < N; i++)
#define pb push_back
 
typedef long long ll;
typedef pair<ll, int> ll_i;

int main() {
	string s;
    int ans = 0;
    cin >> s;
    for(int i=0;i < 4;i++){
        if (s[i] == '+')ans++;
        else ans--;
    }
    cout << ans;
    return 0;
}

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

#define rep(i,n) for (int i=0;i<(n);i++)
#define rep2(i,a,b) for (int i=(a);i<(b);i++)
#define rrep(i,n) for (int i=(n)-1;i>=0;i--)
#define rrep2(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define all(a) (a).begin(),(a).end()

typedef long long ll;
typedef pair<int, int> Pii;
typedef tuple<int, int, int> TUPLE;
typedef vector<int> V;
typedef vector<V> VV;
typedef vector<VV> VVV;

template <typename T>
struct edge {
    int from, to;
    T cost;
    edge(){}
    edge(int _from, int _to, T _cost) : from(_from), to(_to), cost(_cost) {}
    bool operator< (const edge& e) const {
        return cost == e.cost ? (from == e.from ? to < e.to : from < e.from) : cost < e.cost;
    }
    bool operator> (const edge& e) const {
        return cost == e.cost ? (from == e.from ? to > e.to : from > e.from) : cost > e.cost;
    }
};

template <typename T>
class Prim {
private:
    int n;
    vector<vector<edge<T>>> G;
public:
    Prim(int _n) : n(_n) {
        G.resize(n);
    }
    // undirected
    void addEdge(int u, int v, T c) {
        G[u].emplace_back(u, v, c);
        G[v].emplace_back(v, u, c);
    }
    T calc(int s = 0) {
        T total_weight = 0;
        vector<bool> visited(n);
        int num_visited = 0;
        priority_queue<edge<T>, vector<edge<T>>, greater<edge<T>>> pq;
        pq.push(edge<T>(-1, s, 0));
        while (!pq.empty() && num_visited < n) {
            auto e = pq.top(); pq.pop();
            if (visited[e.to]) continue;
            total_weight += e.cost;
            visited[e.to] = true;
            num_visited++;
            for (const auto& ne: G[e.to]) {
                if (!visited[ne.to]) pq.push(ne);
            }
        }
        return total_weight;
    }
};

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

    int n, m;
    cin >> n >> m;
    Prim<int> prim(n);
    rep(i, m) {
        int a, b, c;
        cin >> a >> b >> c;
        prim.addEdge(a, b, c);
    }

    cout << prim.calc() << endl;
}

Measured memory_bytes: 13884
#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int,int> P;
const long long LINF=1e18;
template<typename T>
void chmin(T &a,T b){
  if(a>b)a=b;
}
template<typename T>
void chmax(T &a,T b){
  if(a<b)a=b;
}

signed main(){
  int n;cin>>n;
  vector<P> b(n);
  int mx=0;
  for(int i=0;i<n;i++){
    int x,y;cin>>x>>y;
    if(x>y)swap(x,y);
    chmax(mx,y);
    b[i]=P(x,y);
  }
  sort(b.begin(),b.end());
  int ans=LINF;
  int A=b[n-1].first-b[0].first;
  int B=LINF;
  for(int i=0;i<n;i++)chmin(B,b[i].second);
  chmin(ans,A*(mx-B));
  map<int,int> m;
  for(int i=0;i<n;i++)m[b[i].first]++;
  for(int i=0;i<n;i++){
    chmin(ans,(mx-b[0].first)*(m.rbegin()->first-m.begin()->first));
    m[b[i].second]++;
    if(--m[b[i].first]==0)m.erase(b[i].first);
  }
  chmin(ans,(mx-b[0].first)*(m.rbegin()->first-m.begin()->first));
  cout<<ans<<endl;
}

/*
解説AC
一番小さいやつが赤のminとしていいまでは思いついたのにね
一番大きいやつも同様に注目して場合分けするだけだった
これ思いつかないのは流石にダメだね
minとmaxが同じ色の時のそれの正当性は？
とにかく青の間を小さくしたくて、途中まで赤そこから先青、じゃない時を考えると
途中で寝返ったやつよりあとのやつはどう考えてもそいつのそれからそうなので
全部を使った最小最大問題は必ず端になるものがそれぞれ見つかるのでそれらの関係性で場合分けするとシンプルになるぞい
*/


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


int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  vector<int> b(n);
  rep(i,n){
    cin >> a[i];
  }
  rep(i,n){
    cin >> b[i];
  }
  int ans = 0;
  rep(i,n){
    if(a[i] - b[i] > 0){
      ans += a[i] - b[i];
    }
  }
  cout << ans;
  return 0;
}




Measured memory_bytes: 3592
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long ll;


int main(void){
  int n,i,a,ex=1,all=1;
  
  cin >> n;
  for (i=0;i<n;i++){
    cin >> a;
    all*=3;
    if (a%2==0) ex*=2;
  }
  
  cout << all-ex << endl;
  
  return 0;
}

Measured memory_bytes: 256