akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (ll)n; ++i)
static const int dx[4] = { 0, 1, 0, -1 };
static const int dy[4] = { 1, 0, -1, 0 };
static const char dir[4] = { 'u', 'r', 'd', 'l' };
static const ll INF = 1 << 21;
static const ll MOD = 1e9 + 7;
int N, M;

struct UnionFind {
    vector<int> par;

    UnionFind(int n)
        : par(n, -1)
    {
    }
    void init(int n) { par.assign(n, -1); }

    int root(int x)
    {
        if (par[x] < 0) {
            return x;
        } else {
            return par[x] = root(par[x]);
        }
    }

    bool issame(int x, int y)
    {
        return root(x) == root(y);
    }

    bool merge(int x, int y)
    {
        x = root(x);
        y = root(y);
        if (x == y) {
            return false;
        }
        if (par[x] > par[y]) {
            swap(x, y);
        }
        par[x] += par[y];
        par[y] = x;
        return true;
    }

    int size(int x)
    {
        return -par[root(x)];
    }
};

signed main()
{
    int cnt = 0;
    cin >> N >> M;
    vector<int> p(N);
    UnionFind uf(N + 1);
    rep(i, N)
    {
        cin >> p[i];
    }
    rep(i, M)
    {
        int x, y;
        cin >> x >> y;
        uf.merge(x, y);
    }
    rep(i, N)
    {
        if (uf.issame(i + 1, p[i])) {
            ++cnt;
        }
    }
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 1024
//#include"pch.h"
#include<iostream>
#include<string>
#include<vector>
#include<ctime>
#include<iomanip>
#include<fstream>
#include<stack>
#include<queue>
#include<cassert>
#include<algorithm>
#include<unordered_map>
#include<map>
#include<functional>
#include<exception>
#include<utility>
#define fori(i,z,u) for(i=z;i<u;i++)
#define forz(i,m) for(i=0;i<m;i++)
#define forinc(i,z,u,inc) for(i=z;i<u;i+=inc)
using namespace std;
#define fi first
#define se second
#define vi vector<int>
#define vill vector<long long>
#define vd vector<long double>
#define vvi vector<vector<int>>
#define vs vector<string>
#define vb vector<bool>
#define ump unordered_map
#define debug(x) cout<<#x<<" : "<<x
using ll = long long;
using ld = long double;
using ull = unsigned long long;
#define pii pair<int,int>
#define pll pair<ll,ll>
//#define Onlaptop

int main()
{
	int i{ 0 }, j{ 0 }, k{ 0 }, l{ 0 }, a{ 0 }, b{ 0 }, c{ 0 }, d{ 0 }, t{ 0 }, n{ 0 };

#ifdef Onlaptop
	fstream cin, cout;

	cin.open("input.txt");
	cout.open("output.txt", ios::trunc);
#endif

	string child;
	cin >> child;

	vi vec(child.size());

	c = 0, d = 0;

	int prev = 0;

	size_t you;

	forz(i, child.size())
	{
		if (i == 0)
			you = child.find("RL");
		else
			you = child.find("RL", prev + 1);

		prev = you;

		if (you == string::npos)
			break;

		a = int(you);
		b = int(you + 1);
		vec[a]++; vec[b]++;

		//cout << a <<" "<< b << endl;

		c = a - 1;
		if (c >= 0)
			while (child[c] == 'R')
			{
				if ((a - (c)) % 2 != 0)
				{
					vec[b]++;
				}
				else vec[a]++;
				c--;
				if (c < 0)break;

				//debug("charim");
			}



		d = b + 1;

		if (d < vec.size())
			while (child[d] == 'L')
			{
				if ((d - b) % 2 == 0)
				{
					vec[b]++;
				}
				else
				{
					vec[a]++;
				}
				d++;
				if (d >= vec.size())break;

				//debug("charmi");
			}
	}
	forz(i, vec.size())
		cout << (i == 0 ? "" : " ") << vec[i];
	return 0;
}

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

using namespace std;

#define inf 1<<30
#define llong long long
#define usd unsigned
#define pqueue priority_queue
#define mp make_pair
#define pb push_back
#define fn fill_n
typedef pair<int, int> P;
typedef struct data{
	int now;
	int cost;

	bool operator<(const data &ri) const{
		return cost < ri.cost;
	}
	bool operator>(const data &ri) const{
		return cost > ri.cost;
	}
}data;
int nw[9] = {0, 1, 0, -1, -1, 1, 1, -1, 0};
int nh[9] = {1, 0, -1, 0, 1, 1, -1, -1, 0};



int main(){
	int h, w;
	int blue[50] = {}, red[50] = {}, white[50] = {};
	char in;
	cin >> h >> w;
	for(int i = 0; i < h; i++){
		for(int j = 0; j < w; j++){
			cin >> in;
			if(in == 'W') white[i]++;
			else if(in == 'B') blue[i]++;
			else if(in == 'R') red[i]++;
		}
	}

	int ans = inf;
	int wi = 0;
	for(int i = 0; i < h-2; i++){
		wi += w - white[i];
		int bl = 0;
		for(int j = i+1; j < h-1; j++){
			bl += w - blue[j];
			int re = 0;
			for(int k = j+1; k < h; k++){
				re += w - red[k];
			}
			ans = min(ans, wi+bl+re);
		}
	}

	cout << ans << endl;

	return 0;
}



Measured memory_bytes: 3136
N = int(input())
mat = list()
for i in range(10):
    mat.append([0] * 10)

for i in range(N):
    A = int(str(i + 1)[0])
    B = int(str(i + 1)[-1])
    mat[A][B] += 1
ans = 0
for i in range(N):
    A = int(str(i + 1)[0])
    B = int(str(i + 1)[-1])
    ans += mat[B][A]
print(ans)


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

int main() {
  char a;
  cin >> a;
  if (a == 'a' || a == 'i' || a == 'u' || a =='e' || a == 'o'){
    cout << "vowel" << endl;
  }
  else {
    cout << "consonant" << endl;
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define mp make_pair
#define gc getchar
#define pb push_back
#define eb emplace_back
#define all(x) (x).begin(),(x).end()
#define x1 uvuvwevwevwe
#define y1 onyetenyevwe
#define x2 ugwemubwem
#define y2 ossas
typedef long long LL;
typedef long double LD;
typedef pair<int,int> pii;
template <typename T> void scan(T &angka){
	angka=0;char input=gc();T kali=1;
	while(!(48<=input&&input<=57)){	if(input=='-')	kali=-1;input=gc();}
	while(48<=input&&input<=57)	angka=(angka<<3)+(angka<<1)+input-48,input=gc();angka*=kali;
}
template <typename T1,typename T2> void scan(T1 &angka1,T2 &angka2){
	scan(angka1);scan(angka2);
}
const int MAXN=100;
int pre[MAXN+5],suff[MAXN+5],arr[2][MAXN+6],n,ans;
int main()
{
	scan(n);
	for(int i=0;i<2;i++)
		for(int j=1;j<=n;j++)
			scan(arr[i][j]);
	pre[0]=0;
	for(int i=1;i<=n;i++)
		pre[i]=pre[i-1]+arr[0][i];
	suff[n+1]=0;
	for(int i=n;i>=1;i--)
		suff[i]=suff[i+1]+arr[1][i];
	ans=0;
	for(int i=1;i<=n;i++)
		ans=max(ans,pre[i]+suff[i]);
	cout<<ans<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int,int> pii;
const int inf = 0x3f3f3f3f,oo = inf;
#define IL inline
#define RG register
#define rep(i,a,b) for(RG int i=(a);i<(b);++i)
#define Rep(i,a,b) for(RG int i=(a);i<=(b);++i)
#define Dep(i,a,b) for(RG int i=(a);i>=(b);--i)
#define pc putchar
#define gc getchar
IL ll read(){
    RG ll x=0;char f=0;RG char c=gc();
    for(;!isdigit(c);c=gc())f|=(c=='-');
    for(;isdigit(c);c=gc())x=(x<<1)+(x<<3)+(c^48);
    return f?-x:x;
}
IL double readdb(){
    RG double x=0,p=0.1;RG char f=0,c=gc();
    for(;!isdigit(c);c=gc())f|=(c=='-');
    for(;isdigit(c);c=gc())x=x*10+(c^48);
    if(c=='.')for(c=gc();isdigit(c);c=gc(),p/=10)x=x+(c^48)*p;
    return f?-x:x;
}
IL void write(ll x){if(x<0)x=-x,pc('-');if(x>=10)write(x/10);pc(x%10+'0');}
IL void writeln(ll x){write(x);puts("");}
IL void writeln(ll x,char c,ll y){write(x);pc(c);writeln(y);}
IL void writeln(ll x,char c,ll y,char d,ll z){write(x);pc(c);write(y);pc(d);writeln(z);}
#define debug(x) printf(#x" = %d\n",x);
#define rd() read()
#define rdb() readdb()
#define mem(x,v) memset(x,v,sizeof(x))
#define pb push_back
#define mp make_pair
#define sqr(x) ((x)*(x))
#define lowbit(x) ((x)&(-(x)))
#define firstn(x) freopen(#x".in","r",stdin)
#define fout(x) freopen(#x".out","w",stdout)
#define int ll
#define hash __hash
#define union _union
const int maxn = 1000005;
ll S[3333][3333],C[3333][3333],n,Mod;
ll qpow(ll a,ll b,ll Mod){
	ll ans = 1;
	for(;b;b>>=1,a=1ll*a*a%Mod)
		if(b&1) ans = 1ll * ans * a % Mod;
	return ans;
}
ll w(int i){
	ll res = 0;
	ll tmp1 = 1,tmp2 = qpow(2,qpow(2,n-i,Mod-1),Mod) % Mod;
	ll t = qpow(2,n-i,Mod);
	for(int j=0;j<=i;j++){
		res = (res + S[i][j] * tmp1 % Mod * tmp2 % Mod) % Mod;
		tmp1 = tmp1 * t % Mod;
	}
	return res;
}
void init(){
	n = rd(),Mod = rd();
	C[0][0]=1;
	Rep(i,1,n){
		C[i][0] = 1;
		Rep(j,1,i){
			C[i][j] = (C[i-1][j-1]+C[i-1][j])%Mod;
		}
	}
	S[0][0] = 1;
	Rep(i,1,n){
		S[i][0] = 1;
		Rep(j,1,i){
			S[i][j] = (S[i-1][j-1] + S[i-1][j] * (j+1) % Mod) %  Mod;
		}
	}
	ll ans = 0;
	Rep(i,0,n){
		if(i&1) ans =(ans + 1ll * (Mod-1) * C[n][i] % Mod * w(i) % Mod) % Mod; else
				ans =(ans + 1ll * 1       * C[n][i] % Mod * w(i) % Mod) % Mod;
	}
	writeln(ans);
	
}
signed main(){
	init();
	return 0;
}

Measured memory_bytes: 158208
#include <stdio.h>
int main ()
{
	int a,b;
	int num1 = 1, num2 = 2, num3 = 3;
	scanf("%d",&a);
	scanf("%d", &b);
	
	if (a == 1 && b ==2)
	printf("%d", num3);
	else if (a == 2 && b==3)
	printf("%d", num1);
	else if (a == 3 && b == 1)
	printf("%d", num2);
	else if (a == 3 && b==2)
	printf("%d", num1);
	else if (a == 2 && b ==1)
	printf("%d", num3);
	else if (a == 1 && b == 3)
	printf("%d", num2);
	
	return 0;
}

Measured memory_bytes: 128
void main()
{
    string s = readln.chomp;
    int a = s[0] - '0';
    string t = s[1..4];

    foreach (i; 0 .. (1 << 3))
    {
        int eq = a;
        string left = s[0].to!string;
        foreach (j; 0 .. 3)
        {
            if (i & (1 << j))
            {
                eq += t[j] - '0';
                left ~= "+" ~ t[j];
            }
            else
            {
                eq -= t[j] - '0';
                left ~= "-" ~ t[j];
            }
        }

        if (eq == 7)
        {
            writeln(left, "=7");
            break;
        }
    }
}

import std.stdio;
import std.string;
import std.array;
import std.conv;
import std.algorithm;
import std.range;
import std.math;
import std.numeric;
import std.container;
import std.typecons;
import std.ascii;
import std.uni;

Measured memory_bytes: 256
a, b = map(int, input().split(' '))

tmp = 1
tmp_1 = 0

for i in range(1, 999):
    tmp_1 = tmp + i + 1
    if tmp > a and tmp_1 > b:
        if tmp - a == tmp_1 - b:
            print(tmp - a)
            exit()

    tmp = tmp_1


Measured memory_bytes: 2940
#include <bits/stdc++.h>
#define INF 1e9
using namespace std;

#define REPR(i,n) for(int i=(n); i >= 0; --i)
#define FOR(i, m, n) for(int i = (m); i < (n); ++i)
#define REP(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define ALL(a)  (a).begin(),(a).end()

template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return true; } return false; }
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
int gcd(int a,int b){return b?gcd(b,a%b):a;}
typedef long long ll;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}

void solve() {
    string s;
    cin >> s;
    map<char,int> mp;

    // 初期化
    REP(i,26) mp[(char)(i+'a')] = 0;
    // count
    for(const auto &it: s) mp[it]++;

    bool have_zero = false;
    for (const auto &it: mp) {
        if (it.second == 0) {
            have_zero = true;
            break;
        }
    }
    if (!have_zero) {
        // ある文字において、それよりお大きく、使われていないものを後ろから見つける
        REPR(i,24) {
            // 初期化
            REP(j,26) mp[(char)(j+'a')] = 0;
            // カウント
            REP(j,i) mp[s[j]]++;
            for (const auto &it: mp) {
                if ( (it.first > s[i]) && (it.second == 0)) {
                    // 答えの作成
                    REP(j,i) cout << s[j];
                    cout << it.first << endl;
                    return;
                }
            }
        }
        cout << -1 << endl;
        return;
    }

    // 0になっている部分を探す
    char zero_c = '0';
    for (const auto &it: mp) {
        if (it.second == 0) {
            zero_c = it.first;
            break;
        }
    }

    s.push_back(zero_c);

    cout << s << endl;
}

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


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll      long long
#define pii     pair<int, int>
#define f       first
#define s       second
#define sf(a) scanf("%d", &a)
#define sfl(a) scanf("%lld", &a)
#define pf(a) printf("%d ", a)
#define pfl(a) printf("%lld\n", a)
#define Case(a) printf("Case %d: ", a)

using namespace std;
int main()
{
    int n;
    cin>>n;

    string s;;
    cin>>s;

    int r[n], g[n], b[n], rc = 0, gc = 0, bc = 0;
    for(int i=n-1;i>=0;i--){
        if(s[i] == 'R')
            rc++;
        if(s[i] == 'G')
            gc++;
        if(s[i] == 'B')
            bc++;

        r[i] = rc;
        g[i] = gc;
        b[i] = bc;
    }

    ll ans = 0;
    for(int i=0;i<n-2;i++){
        for(int j=i+1;j<n-1;j++){
            if(j+1 < n){
                if((s[i]=='R' && s[j]=='G') || (s[i]=='G' && s[j]=='R')){
                    ans += b[j+1];
                    if(j+j-i<n){
                        if(s[j+j-i] == 'B')
                            ans--;
                    }
                }

                if((s[i]=='R' && s[j]=='B') || (s[i]=='B' && s[j]=='R')){
                    ans += g[j+1];
                    if(j+j-i<n){
                        if(s[j+j-i] == 'G')
                            ans--;
                    }
                }

                if((s[i]=='B' && s[j]=='G') || (s[i]=='G' && s[j]=='B')){
                    ans += r[j+1];
                    if(j+j-i<n){
                        if(s[j+j-i] == 'R')
                            ans--;
                    }
                }

            }
        }
    }
    cout<<ans;
}



Measured memory_bytes: 3688
#include<bits/stdc++.h>
using namespace std;
#define MAX 114514
signed main(){
  int h,n;
  cin>>h>>n;
  int bi[MAX];
  memset(bi,0,sizeof(bi));
  for(int i=0;i<n;i++){
    int x,y;
    cin>>x>>y;
    bi[y]|=1<<x;
  }
  static int dp[1<<8][MAX];
  memset(dp,-1,sizeof(dp));
  int ms=(1<<8)-1;
  auto p=[&](int x){return x&1;};
  function<int(int,int)> dfs=[&](int b,int y){
    //cout<<bitset<8>(b)<<" "<<y<<"+"<<dp[b][y]<<endl;
    if(~dp[b][y]) return dp[b][y];
    if(y+1==h) return 0;
    int res=dfs(((b<<4)+bi[y+2])&ms,y+1);
    if(b==0){
      res=max(res,dfs(((15<<4)+bi[y+2])&ms,y+1)+2);
    }
    if(p(b>>4)==0&&p(b>>5)==0&&p(b>>0)==0&&p(b>>1)==0){
      res=max(res,dfs((((b+3)<<4)+bi[y+2])&ms,y+1)+1);
    }
    if(p(b>>5)==0&&p(b>>6)==0&&p(b>>1)==0&&p(b>>2)==0){
      res=max(res,dfs((((b+6)<<4)+bi[y+2])&ms,y+1)+1);
    }
    if(p(b>>6)==0&&p(b>>7)==0&&p(b>>2)==0&&p(b>>3)==0){
      res=max(res,dfs((((b+12)<<4)+bi[y+2])&ms,y+1)+1);
    }
    //cout<<bitset<8>(b)<<" "<<y<<":"<<res<<endl;
    return dp[b][y]=res;
  };
  cout<<dfs((bi[0]<<4)+bi[1],0)<<endl;
  return 0;
}

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

using namespace std;

int main(void) {
    int n;
    vector<int> v, w;
    vector<int> vcount(100001, 0), wcount(100001, 0);
    cin >> n;
    for (int i = 0; i < n / 2; i++) {
        int tmp;
        cin >> tmp;
        v.push_back(tmp);
        vcount[tmp]++;
        cin >> tmp;
        w.push_back(tmp);
        wcount[tmp]++;
    }
    int v1 = 0, v2 = 0, w1 = 0, w2 = 0;
    for (int k = 1; k <= 100000; k++) {
        if (vcount[v1] < vcount[k]) {
            v2 = v1;
            v1 = k;
        } else if (vcount[v2] < vcount[k]) {
            v2 = k;
        }
        if (wcount[w1] < wcount[k]) {
            w2 = w1;
            w1 = k;
        } else if (wcount[w2] < wcount[k]) {
            w2 = k;
        }
    }
    if (v1 != w1) {
        cout << n - vcount[v1] - wcount[w1] << endl;
    } else if (vcount[v2] + wcount[w1] < vcount[v1] + wcount[w2]) {
        cout << n - vcount[v1] - wcount[w2] << endl;
    } else {
        cout << n - vcount[v2] - wcount[w1] << endl;
    }
}

Measured memory_bytes: 1660
#define rep(i,n) for (int i = 0; i < n; i++)
#define _USE_MATH_DEFINES
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <cstring>
#include <queue>
#include <functional>
#include <set>
#include <map>
#include <string>
#include <cmath>
#include <math.h>
#include <complex>
#include <cassert>
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> p;
typedef complex<double> com;
const int mod = 1e9 + 7;
const int MOD = 998244353;
const ll INF = 1e18;


int main() {
	ll n, m; cin >> n >> m;
	vector<vector<ll>> a(n);
	rep(i, n) {
		a[i].resize(3);
		rep(j, 3) {
			ll p; cin >> p;
			a[i][j] = p;
		}
	}
	ll ans = -INF;
	rep(i, 8) {
		vector<ll> b(n, 0);
		rep(j, n) {
			if (i&1) b[j] += a[j][0];
			else b[j] -= a[j][0];
			if ((i>>1)&1) b[j] += a[j][1];
			else b[j] -= a[j][1];
			if ((i>>2)&1) b[j] += a[j][2];
			else b[j] -= a[j][2];
		}
		sort(b.begin(), b.end(),greater<ll>());
		ll sub = 0;
		rep(k, m) {
			sub += b[k];
		}
		ans = max(ans, sub);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include"bits/stdc++.h"
using ll=long long;
using namespace std;
#define REP(k,m,n) for(ll (k)=(m);(k)<(n);(k)++)
#define rep(i,n) REP((i),0,(n))


constexpr ll MAX_N=3000;
constexpr ll MOD=1e9+7;
ll N;
ll bit[MAX_N];
ll sum(ll i){
	i++;
	ll s=0;
	while(i>0){
		s+=bit[i];
		i-=i&-i;
	}
	return s;
}

void add(ll i,ll x){
	i++;
	while(i<=N){
		bit[i]+=x;
		i+=i&-i;
	}
}

int main()
{
	rep(i,MAX_N)bit[i]=0;
	ll K;
	cin>>N>>K;
	vector<ll> A(N);
	rep(i,N)cin>>A[i];
	
	ll ans = 0;
	rep(i,N)rep(j,N)if(i<j && A[i]>A[j])ans++;
	(ans*=K)%=MOD;

	map<ll,ll> mp;
	for(auto num:A)mp[num]++;
	
	ll b=0;
	ll tmp = (((K-1)*K)/2)%MOD;
	for(auto itr=mp.begin();itr!=mp.end();++itr){
		ll a = itr->second;
		ll now = (a*b)%MOD;
		(ans+=now*tmp)%=MOD;
		(b+=a)%=MOD;
	}
	cout<<ans%MOD<<endl;

	return 0;
}


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

int main(){
  int d,n;
  cin>>d>>n;
  int a=1;
  rep(i,0,d) a*=100;
  if(n<100) cout<<n*a;
  else cout<<101*a;
}

Measured memory_bytes: 256
n = int(input())
d, x = (int(i) for i in input().split())
A = [None] * n
for i in range(n):
    A[i] = int(input())
    
eated_num = 0
for a in A:
    i = 0
    while True:
        eat_date = i*a + 1
        if eat_date <= d:
            eated_num += 1
            i += 1
        else:
            break
print(eated_num + x)

Measured memory_bytes: 3064
#include "iostream"
#include "algorithm"
#include "string"
#include "vector"
#include "cmath"
#include "bitset"
#include "queue"
#include "functional"
#include "map"
#include "unordered_map"
#include "set"
#include "stack"

#define lp(n) for (int i = 0; i < n; i++)
#define LP(n,i) for (int i = 0; i < n; i++)
#define mod 1000000007
#define sp ' '
#define intmax 2147483647
#define llmax 9223372036854775807
#define nya_n "(=^･ω･^=)"
typedef long long ll;
using namespace std;

int h, w;
char a[100][100];
bool hb[100];
bool wb[100];
int main() {
	cin >> h >> w;
	lp(h) {
		LP(w, j)
			cin >> a[i][j];
	}
	lp(h) {
		hb[i] = false;
		LP(w, j) {
			if (a[i][j] == '#') {
				hb[i] = true;
				break;
			}
		}
	}
	LP(w, j) {
		wb[j] = false;
		lp(h) {
			if (a[i][j] == '#') {
				wb[j] = true;
				break;
			}
		}
	}
	lp(h) {
		if (hb[i]) {
			LP(w, j) {
				if (wb[j])
					cout << a[i][j];
			}
			cout << endl;
		}
	}
	return 0;
}


Measured memory_bytes: 256
import java.util.*;
public class Main {
  public static int countString(String S, String word) {
  	//Sに調べたい文字列を、wordに数えたい文字列を入れる。
    String reS = S.replace(word,"");
    int ans = (S.length() - reS.length())/word.length();
    return ans;
  }
  public static void main (String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    String S = sc.next();
    System.out.println(countString(S,"ABC"));
  }
}

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

using namespace std;

long long gcd(long long a, long long b);

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

	vector<int>	nx(n);
	for (int i = 0; i < n; i++) {
		cin >> nx[i];
		nx[i] = abs(x - nx[i]);
	}
	if (n == 1) {
		cout << nx[0] << endl;
	}
	else {
		for (int i = 1; i < n; i++) {
			nx[i] = gcd(nx[i], nx[i - 1]);
		}
		cout << nx[n - 1] << endl;
	}

	return 0;
}

long long gcd(long long a, long long b)
{
	if (a < b) {
		long long t = a;
		a = b;
		b = t;
	}

	long long r = a % b;
	while (r != 0) {
		a = b;
		b = r;
		r = a % b;
	}

	return b;
}

Measured memory_bytes: 640
# 解説放送の１つめ
N,M = map(int, input().split())
A = list(map(int, input().split()))
f = [-1, 2,5,5,4,5,6,3,7,6] # 1-indexed

# dp[i]: マッチi本数で作れる最大の数(str)
dp = [None]*(N+1)
dp[0] = ""

# strの数の大きいほう
def max_str(s1:str, s2:str)->str:
    """return bigger one"""
    l1, l2 = len(s1), len(s2)
    if l1 != l2:
        return s1 if l1>l2 else s2
    if l1 == l2: 
        return s1 if s1>s2 else s2
    
for i in range(2, N+1):
    nxt = ""
    for aj in A:
        # 配列外参照と，i本ちょうどで作れないものはだめ
        if i-f[aj]<0 or dp[i-f[aj]]==None: continue
        nxt = max_str(nxt, 
                      dp[i-f[aj]]+str(aj))
    if nxt!="":
        dp[i] = nxt
    #print(dp)
print(dp[N])

Measured memory_bytes: 136924
#include <bits/stdc++.h>
using ll = long long;
#define FOR(i, k, n) for(ll i = (k); i < (n); i++)
#define FORe(i, k, n) for(ll i = (k); i <= (n); i++)
#define FORr(i, k, n) for(ll i = (k)-1; i > (n); i--)
#define FORre(i, k, n) for(ll i = (k)-1; i >= (n); i--)
#define REP(i, n) FOR(i, 0, n)
#define REPr(i, n) FORre(i, n, 0)
#define ALL(x) (x).begin(), (x).end()
#define ALLr(x) (x).rbegin(), (x).rend()
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
using namespace std;

const int INF = 1001001001;
const int mod = 1000000007;

struct mint{
  ll x;
  mint(ll x = 0):x((x % mod + mod) % mod){};
  mint pow(ll y) const {
    mint res(1);
    mint a(x);
    while(y>0){
      if(y&1) res *= a;
      a *= a;
      y >>= 1;
    }
    return res;
  }
  mint inv() const{ return pow(mod-2); }
  mint& operator+= (const mint a) noexcept {
    if((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-= (const mint a) noexcept {
    if((x += mod - a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*= (const mint a) noexcept {
    (x *= a.x) %= mod;
    return *this;
  }
  mint& operator/= (const mint a) noexcept {
    return (*this) *= a.inv();
  }
  mint operator+ (const mint a) const noexcept {
    mint res(*this);
    return res += a;
  }
  mint operator- (const mint a) const noexcept {
    mint res(*this);
    return res -= a;
  }
  mint operator* (const mint a) const noexcept {
    mint res(*this);
    return res *= a;
  }
  mint operator/ (const mint a) const noexcept{
    mint res(*this);
    return res /= a;
  }
};

ostream& operator<<(ostream& stream, const mint& n){
  stream << n.x;
  return stream;
};

struct comb{
  vector<mint> fact, ifact;
  comb(int n): fact(n+1), ifact(n+1){
    fact[0] = 1;
    for(int i = 1; i <= n; i++) fact[i] = fact[i-1] * i;
    ifact[n] = fact[n].inv();
    for(int i = n; i >= 1; i--) ifact[i-1] = ifact[i] * i;
  }
  mint operator()(int n, int k) const noexcept{
    if(k < 0 || n < k) return 0;
    return fact[n] * ifact[k] * ifact[n-k];
  }
};

int main(void){
  ll n;
  cin >> n;
  vector<ll> a(n);
  REP(i, n) cin >> a[i];
  sort(ALL(a));
  mint ans = 0;
  if(n%2){
    bool ok = true;
    if(a[0] != 0) ok = false;
    REP(i, n/2){
      ll t = 2*(i+1);
      if(a[2*i+1] != t  || a[2*i+2] !=t) ok = false;
    }
    if(ok) ans = mint(2).pow(n/2);
  }else{
    bool ok = true;
    REP(i, n/2){
      ll t = 2*i+1;
      if(a[2*i] != t || a[2*i+1] != t) ok = false;
    }
    if(ok) ans = mint(2).pow(n/2);
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 1024
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<P, int> Pi;

int main(void){
	string s;
	cin >> s;
	s[5] = ' ';
	s[13] = ' ';
	cout << s << endl;
	return 0;
}


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

using namespace std;
using llong = long long;
using P = pair<llong, llong>;

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

const llong inf = llong(1e18)+7;
const llong mod = 1e9+7;

int main(){
	int n;
	vector<llong> a;

	cin >> n;
	a.resize(n);
	for(int i = 0; i < n; i++)
		cin >> a[i];

	for(int i = n-1; i >= 0; i -= 2)
		cout << a[i] << " ";
	for(int i = n%2 ? 1 : 0; i < n; i += 2){
		cout << a[i];
		if(i+2 < n)
			cout << " ";
	}


	cout << endl;

	return 0;
}

Measured memory_bytes: 3712
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
typedef long long ll;
typedef pair<ll, char> P;
vector<P> V;
string str;
ll n, ans;
const ll mod = 1000000007;

void dfs(ll num, ll moji, ll count){
    if (num == str.length()) return;
    if (count == 0){
        dfs(num + 1, str[num] - 'A', count + 1);
    } else {
        if (str[num] - 'A' == moji){
            dfs(num + 1, moji, count + 1);
        } else {
            (ans *= count) %= mod;
            dfs(num + 1, moji, count - 1);
        }
    }
}

int main(void){
    // Your code here!
    cin >> n;
    for (ll i = 0; i < n; i++){
        ll a;
        cin >> a;
        V.push_back(P(a, 'A'));
    }
    for (ll i = 0; i < n; i++){
        ll b;
        cin >> b;
        V.push_back(P(b, 'B'));
    }
    sort(V.begin(), V.end());
    for (ll i = 0; i < V.size(); i++){
        P p = V[i];
        str += p.second;
    }
    ans = 1;
    dfs(0, 0, 0);
    cout << ans << endl;
}


Measured memory_bytes: 6512
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cstdlib>
#include<vector>
#include<map>
#include<cmath>
#define ll long long
#define maxn 1000005
using namespace std;
int n,k;
int mod=1e9+7;
ll read()
{
    ll l=0,w=1;
    char ch=getchar();
    while(ch<'0'||ch>'9')
    {
        if(ch=='-')
        w=-1;
        else
        ch=getchar();
    }
    while(ch<='9'&&ch>='0')
    {
        l*=10;
        l+=ch-'0';
        ch=getchar();
    }
    return l*w;
}
int main()
{
	n=read(),k=read();
	ll ans=0;
	for(int i=k;i<=n+1;i++)
	{
		ans=(ans+((ll)i*(2*n-i+1)/2-(ll)i*(i-1)/2+1+mod)%mod)%mod;
	}
	printf("%lld\n",ans);
	return 0;
} 

Measured memory_bytes: 3760
/*
      author  : nishi5451
      created : 12.08.2020 23:12:10
*/

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


int main(){
    int w,a,b;
    cin >> w >> a >> b;
    int la = a, ra = a+w;
    int lb = b, rb = b+w;

    if( (la>=lb && la<=rb) || (ra>=lb && ra<=rb) || (la<=lb && ra>=rb) ){
        cout << 0 << endl;
    }
    else{
        if(a>b) cout << a-b-w << endl;
        else if(b>a) cout << b-a-w << endl;
    }

    return 0;
}

Measured memory_bytes: 3588
N,M=map(int,input().split())
*H,=map(int,input().split())

dmax=[0 for _ in range(N+1)]

for j in range(M):
    a,b=map(int,input().split())
    dmax[a-1]=max(dmax[a-1],H[b-1])
    dmax[b-1]=max(dmax[b-1],H[a-1])    
          
goodv = [1 for i in range(N) if dmax[i]<H[i]]
print(len(goodv))



Measured memory_bytes: 20128
#include <iostream>
#include <algorithm>
using namespace std;
int main(void){
    // Your code here!
    int A, B, C, D;
    cin >> A >> B >> C >> D;
    int max_input = max({A, B, C, D});
    
    int alice[110];
    int bob[110];
    for(int i=0; i<110; i++)alice[i] = 0;
    for(int i=0; i<110; i++)bob[i] = 0;
    for(int i=A; i<B; i++){
        alice[i] = 1;
    }
    for(int i=C; i<D; i++){
        bob[i] = 1;
    }
    
    int count = 0;
    for(int i=0; i<max_input; i++){
        if((alice[i] == 1) and (bob[i] == 1))count++;
    }
    cout << count << endl;
}


Measured memory_bytes: 256
#include<iostream>
#define N 500000
#define INF 2000000000
using namespace std;
int c;
void merge(int *A,int l,int m,int r){
  int n1=m-l,n2=r-m;
  int L[N],R[N];
  for(int i=0;i<n1;i++)L[i]=A[l+i];
  for(int i=0;i<n2;i++)R[i]=A[m+i];
  L[n1]=INF,R[n2]=INF;
  int i=0,j=0;
  for(int k=l;k<r;k++){
    if(L[i]<R[j])A[k]=L[i++];
    else A[k]=R[j++];
    c++;
  }
}
void mergesort(int *A,int l,int r){
  if(l+1<r){
    int m=(l+r)/2;
    mergesort(A,l,m);
    mergesort(A,m,r);
    merge(A,l,m,r);
  }
}
 
 
int main(){
  int n,S[N];
  cin>>n;
  for(int i=0;i<n;i++)cin>>S[i];
  mergesort(S,0,n);
  for(int i=0;i<n-1;i++)cout<<S[i]<<" ";
  cout<<S[n-1]<<endl<<c<<endl;
  return 0;
}


Measured memory_bytes: 7000
import java.util.Scanner;
public class Main
{
	public static void main(String arg[])
	{
		Scanner in = new Scanner(System.in);
		int n= in.nextInt();
		while(n--!=0)
		{
			char ch[]=in.next().toCharArray();
			String str = String.valueOf(ch[0]);
			for(int i=3; i<ch.length; i+=3)
			{
				boolean flag = true;
				for(int j=0;j<str.length();j++)
					if(ch[i]==str.charAt(j))
						flag=false;
				if(flag)
					if(ch[i-1]=='>')
						str= str+ch[i];
					else
						str=ch[i]+str;
			}		
			System.out.println(str);
		}
	}
}

Measured memory_bytes: 12000
#include <iostream>
#include <algorithm>
using namespace std;
int N;
int A[100000], B[100000];
int main() {
  cin >> N;
  for(int i = 0; i < N; ++i) {
    cin >> A[i] >> B[i];
  }
  int mm = max_element(A, A + N) - A;
  cout << A[mm] + B[mm] << endl;
}


Measured memory_bytes: 1152
import math

N, X, Y = map(int, input().split())

distnum = [0 for i in range(N)]


for i in range(1, N+1):
  for j in range(i, N+1):
    dist = min(abs(X-i) + 1 + abs(Y-j), abs(X-j)+1+abs(Y-i), abs(i-j))
    distnum[dist] += 1

for i in range(1, N):
  print(distnum[i])

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

#define rep(i, n) for (int (i) = 0; (i) < (n); (i)++)
#define rng(i, a, b) for (int (i) = (a); (i) < (b); (i)++)
#define rbf(i, v) for (auto& (i) : (v))
#define All(x) (x).begin(),(x).end()
#define cAll(x) (x).cbegin(),(x).cend()
#define COL(x) cout << x << endl
#define CO(x) cout << x
#define int long long

typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef vector<PII> VP;

const double PI = 3.141592653589793;
const int MOD = 1000000007;
//const int INF = INT64_MAX;
const int INF = INT_MAX;

template<typename T> inline constexpr auto sqr(T x) { return (x) * (x); }
inline void printd(double x) { printf("%.10lf\n", x); }
inline void upsort(VI& x) { sort((x).begin(), (x).end()); }
inline void downsort(VI& x) { sort((x).begin(), (x).end(), greater<int>()); }

signed main()
{
	int K;
	cin >> K;

	queue<int> que;
	rng(i, 1, 10) que.push(i);

	int lun,x;
	rep(i, K) {
		lun = que.front();
		que.pop();
		x = lun % 10;
		if(x != 0) que.push(10*lun + x-1);
		que.push(10 * lun + x);
		if (x != 9) que.push(10 * lun + x+1);
	}

	COL(lun);

	return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define rep(i,n) for(int (i)=0;(i)<(n);++(i))
#define all(x) (x).begin(),(x).end()
#define dump(x) cout << #x << " = " << (x) << endl
#define YES(n) cout << ((n) ? "YES" : "NO") << endl
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl
#define yes(n) cout << ((n) ? "yes" : "no") << endl

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

const int INF = 1001001001;
const vector<int> di = {-1,  0, 1, 0};
const vector<int> dj = { 0, -1, 0, 1};

void chmin(int &a, int b) { if (a > b) a = b; }

template<typename T>
T gcd(T a, T b) {
    if (b == 0) return a;
    else return gcd(b, a % b);
}
template<typename T>
T lcm(T a, T b) {
    return a / gcd(a, b) * b;
}

ll n;

// cur: 現在の値、use: 7, 5, 3 のうちどれを使ったか, counter: 答え
void dfs(ll cur, int use, ll &counter){
    if (cur > n) return; // ベースケース
    if (use == 0b111) ++counter; // 答えを増やす

    // 7 を付け加える
    dfs(cur * 10 + 7, use | 0b001, counter);

    // 5 を付け加える
    dfs(cur * 10 + 5, use | 0b010, counter);

    // 3 を付け加える
    dfs(cur * 10 + 3, use | 0b100, counter);
}

int main() {
    cin >> n;
    ll res = 0;
    dfs(0, 0, res);
    cout << res << endl;
}

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


using namespace std;

using ll   = long long;
using ii   = pair   < int , int >;
using i3   = pair   < int , ii  >;
using li   = pair   < ll  , int >;
using lii  = pair   < ll  , ii  >;
using pll  = pair   < ll  , ll  >;
using vi   = vector < int       >;
using vl   = vector < ll        >;
using vii  = vector < ii        >;
using vli  = vector < li        >;
using vpll = vector < pll       >;
using vi3  = vector < i3        >;
using vlii = vector < lii       >;


const int N = 2e5 + 5;
const ll INF = 1e17 + 7;
const double eps = 1e-9 , PI = acos(-1);


int n , m;

ll st[N << 2];
int a[N];
int h[N];

void update(int p , int l , int r , int dx , ll val){
    if(l == r){
            st[p] = max(st[p] , val);
            return;
    }

    int mid = l + ((r - l) >> 1);

    if(dx <= mid) update(p << 1     , l       , mid , dx , val);
    else          update(p << 1 | 1 , mid + 1 , r   , dx , val);

    st[p] = max(st[p << 1] , st[p << 1 | 1]);
}

ll query(int p , int l , int r , int S , int E){
    if(l >= S && r <= E) return st[p];
    if(l > E || r < S)   return     0;

    int mid = l + ((r - l) >> 1);

    return max(query(p << 1 , l , mid , S , E) , query(p << 1 | 1 , mid + 1 , r , S , E));
}

void solve(int testCase){

    scanf("%d" , &n);

    for(int i = 1 ; i <= n ; i ++) scanf("%d" , &h[i]);
    for(int i = 1 ; i <= n ; i ++) scanf("%d" , &a[i]);

    ll ans = 0;
    for(int i = 1 ; i <= n ; i ++) {

            ll curr = a[i] + query(1 , 1 , N-1 , 1 , h[i]);

            ans = max(ans , curr);
            update(1 , 1 , N-1 , h[i] , curr);
    }

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

}

main(){

    int t = 1;
    // scanf("%d" , &t);

    for(int testCase = 1 ; testCase <= t ; testCase ++){
            solve(testCase);
    }

    return 0;
}


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

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

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

    vector<double> A(N);
    for (int i = 0; i < A.size(); i++)
        cin >> A.at(i);

    double ans = 0.0;
    for (int i = 0; i < A.size(); i++)
        ans += (1.0 / A.at(i));

    cout << (1.0 / ans) << endl;
}

Measured memory_bytes: 256
/*program by mangoyang*/
#include<bits/stdc++.h>
#define inf (0x7f7f7f7f)
#define Max(a, b) ((a) > (b) ? (a) : (b))
#define Min(a, b) ((a) < (b) ? (a) : (b))
typedef long long ll;
using namespace std;
template <class T>
inline void read(T &x){
    int f = 0, ch = 0; x = 0;
    for(; !isdigit(ch); ch = getchar()) if(ch == '-') f = 1;
    for(; isdigit(ch); ch = getchar()) x = x * 10 + ch - 48;
    if(f) x = -x;
}
int main(){
	ll a, b;
	read(a), read(b);
	if(a + b == 15ll) return puts("+"), 0;
	if(a * b == 15ll) return puts("*"), 0;
	puts("x");
	return 0;
}

Measured memory_bytes: 256
import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        String s = input.next();
        String t = input.next();
        if (s.equals(t.substring(0,s.length()))){
            System.out.println("Yes");
        } else {
            System.out.println("No");
        }
    }
}


Measured memory_bytes: 35708
#include<iostream>
#include<string>
#include<vector>

using namespace std;
typedef long long ll;
vector<ll> num;
ll ans = 0;

ll express(int n, ll tmp){
    int i=1;
    while(n>0){
        n--;
        tmp += num[n]*i;
        i=i*10;
        express(n, tmp);
    }
    ans += tmp;
    //cout << tmp << endl;

    return ans;
}

int main(){
    string S;
    int N;
    
    cin >> S;
    N = S.length();

    num.resize(N);
    for(int i=0; i<N; i++){
        num[i] = static_cast<int>(S[i]) - 48;
    }

    express(N, 0);

    cout << ans/2 << endl;

    return 0;

}

Measured memory_bytes: 256
n=int(input())
A=[]
for i in range(n):
  A.append(int(input()))
A=sorted(A)
if n%2==0:
  B=[]
  C=[]
  for i in range(n//2):
    B.append(A[i])
    C.append(A[i+n//2])
  ans=0
  ans=ans+C[0]-B[0]
  for i in range(1,n//2):
    ans=ans+C[i]*2-B[i-1]-B[i]
  print(ans)
else:
  B=[]
  C=[]
  for i in range((n-1)//2):
    B.append(A[i])
    C.append(A[i+(n+1)//2])
  B.append(A[(n-1)//2])
  ans1=2*sum(C)-2*sum(B)+B[-1]+B[-2]
  B=[]
  C=[]
  for i in range((n-1)//2):
    B.append(A[i])
    C.append(A[i+(n-1)//2])
  C.append(A[-1])
  ans2=2*sum(C)-2*sum(B)-C[0]-C[1]
  print(max(ans1,ans2))

Measured memory_bytes: 8416
// clang-format off
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(ll i=0, i##_len=(n); i<i##_len; ++i)
#define rep1(i,n) for(ll i=1, i##_len=(n); i<=i##_len; ++i)
#define rrep(i,n) for(ll i=n-1; i>=0; --i)
#define rrep1(i,n) for(ll i=n; i>0; --i)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define mp make_pair
#define coutl cout<<fixed<<setprecision(10)
#define ANS(ans) cout<<ans<<endl;
template<class T>bool chmax(T &a, const T &b){if (a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T &a, const T &b){if (b<a){a=b;return 1;}return 0;}
const int INF = 1e9;
const ll LINF = 1e18;
// clang-format on

void solve(long long N, std::string S, std::string T) {
  rep(i, N) { cout << S[i] << T[i]; }
  cout << 
  endl;
}

int main() {
  long long N;
  scanf("%lld", &N);
  std::string S;
  std::cin >> S;
  std::string T;
  std::cin >> T;
  solve(N, S, T);
  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<algorithm>
using namespace std;
long long int nums[10];
void input()
{
	int i;
	for (i = 0; i < 10; i++)
		scanf("%lld", &nums[i]);
	sort(nums,nums+10);
	printf("%lld\n%lld\n%lld\n", nums[9], nums[8], nums[7]);
}
int main()
{
	input();
	return 0;
}

Measured memory_bytes: 1044
using System;
using static System.Console;
using System.Linq;

namespace AC
{
   public class shiokara
   {
      static void Main(string[] args)
      {
         int[] data = ReadLine().Split(' ').Select(int.Parse).ToArray();
         int N = data[0], K = data[1];
         int[] price = ReadLine().Split(' ').Select(int.Parse).ToArray();
         price = price.OrderBy(x => x).ToArray();
         int ans = 0;
         for(int i = 0; i < K; i++){
             ans += price[i];
         }
         WriteLine(ans);
      }
   }
}

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

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

  int ans = 400000;

  vector<int> w(n), e(n);

  if (s[0] == 'W') {
    w[0] = 1;
    e[0] = 0;
  } else {
    w[0] = 0;
    e[0] = 1;
  }

  for (int i = 1; i < s.size(); i++) {
    if (s[i] == 'W') {
      w[i] = w[i - 1] + 1;
      e[i] = e[i - 1];
    } else {
      w[i] = w[i - 1];
      e[i] = e[i - 1] + 1;
    }
  }

  for (int i = 0; i < n; i++) {
    int sum = 0;
    sum += w[i - 1];
    sum += (e[n-1] - e[i]);
    ans = min(ans, sum);
  }
  cout << ans << endl;
}


Measured memory_bytes: 3076
import numpy as np

a, b, h, m = map(int, input().split())

ar = np.radians((360 - (30 * h + m / 2)) + 90)
br = np.radians((360 - (6 * m)) + 90)

xa = a * np.cos(ar)
ya = a * np.sin(ar)

xb = b * np.cos(br)
yb = b * np.sin(br)

al = np.array([xa, ya])
bl = np.array([xb, yb])
u = bl - al
print(np.linalg.norm(u))

Measured memory_bytes: 27148
#include <iostream>

using namespace std;

int main() {
	int k[50001] ={1};
	int g,h;

	k[1] = 1;
	for (int i = 2; i < 50001; i++) {
		if (k[i] == 0) {
			for (int j = 2; j < (50000/i+1); j++) {
				k[i*j] = 1;
			}
		}
	}

	while (cin >> g) {
		if (g == 0) {
			break;
		}
		int counter = 0;
		for (int i = 2; i < 50001; i++) {
			if (i > g/2) {
				break;
			} else {
				if (k[i] == 0 && k[g-i] == 0) {
					counter++;
				}
			}
		}
		cout << counter << endl;
	}

	return 0;
}

Measured memory_bytes: 1360
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <queue>
#include <map>
#include <cmath>
#include <numeric>
#include <iomanip>
#include <set>
#include <string.h>

using namespace std;

typedef long long ll;

#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define REP3(i,st,en) for(ll (i)=(st);(i)<(en);(i)++)

using P = pair<ll, ll>;
const int MOD = 1e9+7;
const ll INF = 1e+14;
const double PI = 3.14159265349;


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

  ll N;
  cin >> N;
  vector<ll> a(N);
  REP(i, N){ cin >> a[i]; }
  
  ll mi = *min_element(a.begin(), a.end());
  ll ma = *max_element(a.begin(), a.end());

  ll min_loss = INF;
  for (ll l=mi; l<=ma; l++){
    ll loss = 0;
    REP(j,N){ loss += (a[j]-l)*(a[j]-l); }
    if (loss<min_loss){
      min_loss = loss;
    } else {
      break;
    }
  }

  cout << min_loss << "\n";
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i=0;i<n;i++){
    cin >> a[i];
  }
  sort(a.begin(),a.end());
  cout << a[n-1]-a[0] << endl;
}


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

using namespace std;

int main() {
	string S;
	cin >> S;
	bool flag = true;
	for (int i = 0; i < S.size(); i++) {
		if (S[i] != S[S.size() - 1 - i])flag = false;
	}
	for (int i = 0; i < (S.size() - 1) / 2; i++) {
		if (S[i] != S[(S.size() - 1) / 2 - 1 - i])flag = false;
	}
	for (int i = (S.size() + 3) / 2 - 1; i < S.size(); i++) {
		if (S[i] != S[S.size() - 1 - i])flag = false;
	}
	if (flag)cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h> //Ithea Myse Valgulious
namespace chtholly{
typedef long long ll;
#define re0 register int
#define rec register char
#define rel register ll
#define gc getchar
#define pc putchar
#define p32 pc(' ')
#define pl puts("")
/*By Citrus*/
inline int read(){
  int x=0,f=1;char c=gc();
  for (;!isdigit(c);c=gc()) f^=c=='-';
  for (;isdigit(c);c=gc()) x=(x<<3)+(x<<1)+(c^'0');
  return f?x:-x;
  }
template <typename mitsuha>
inline bool read(mitsuha &x){
  x=0;int f=1;char c=gc();
  for (;!isdigit(c)&&~c;c=gc()) f^=c=='-';
  if (!~c) return 0;
  for (;isdigit(c);c=gc()) x=(x<<3)+(x<<1)+(c^'0');
  return x=f?x:-x,1;
  }
template <typename mitsuha>
inline int write(mitsuha x){
  if (!x) return 0&pc(48);
  if (x<0) x=-x,pc('-');
  int bit[20],i,p=0;
  for (;x;x/=10) bit[++p]=x%10;
  for (i=p;i;--i) pc(bit[i]+48);
  return 0;
  }
inline char fuhao(){
  char c=gc();
  for (;isspace(c);c=gc());
  return c;
  }
}using namespace chtholly;
using namespace std;
 
int main(){
//int ans=0,n=read(),k=read(),now=1;
//for (;now<n;++ans) now+=k-1;
//write(ans);
int n=read(),k=read();
write((n-2)/(k-1)+1); 
}

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

int main(void) {
  string S;
  cin >> S;
  int ans = 0;
  string mask = "01";
  for (int i = 0; i < S.size(); i++) {
    if (S[i] != mask[i % 2]) ans++;
  }
  cout << min(ans, (int)S.length() - ans) << endl;
  return 0;
}

Measured memory_bytes: 512
#include<iostream>
#include<vector>
#include<functional>
#include<algorithm>
#include<string>
#include<map>
#include<queue>

using namespace std;

typedef long long int ll;

// 最大公約数
ll GCD(ll a,ll b){if(a%b==0)return b;return GCD(b,a%b);}

// 最小公倍数
ll LCM(ll a,ll b){return a*b/GCD(a,b);}

int main(void){

    int n;
    cin >> n;

    cout << LCM(n, 2) << endl;

    return 0;
}

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

using namespace std;

typedef long long ll;
typedef long double ld;
#define gap ' '
#define L(i) ((i) - (&i))

const int MAXN = 1000010;
const int MAX = 1e6 + 1;
const int MOD = 1e9;
const int INF = 1e9;

int main(){	
	int n, k; cin >> n >> k;
	vector<int> a(n,0);
	for(int i = 0; i < n; ++i)
		cin >> a[i];
	vector<int> dp(n,INF);
	dp[0] = 0;
	for(int i = 0; i < n; ++i){
		int e = i+1;
		for(int j = 1; j <= k; ++j){
			if(e < n){
				dp[e] = min(dp[e], dp[i]+abs(a[i]-a[e]));
				e++;
			}
			else
				break;
		}
	}
	cout << dp[n-1] << "\n";
	return 0;
}

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

using namespace std;

int in(){ int a; cin >> a; return a; }
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

int main(){
  ios_base::sync_with_stdio(0); cin.tie(nullptr); cout.tie(0); cerr.tie(0);
  string s, t;
  cin >> s >> t;
  int ans = 0;
  for(int i = 0; i < s.size(); i++){
  	if(s[i] != t[i]) ans++;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3796
#include<bits/stdc++.h>
using namespace std;
 
typedef long long int ll;
#define endl "\n"
#define ff first
#define ss second 
#define pb push_back
#define INF ll(1e18)
#define MOD 1000000007
#define debug(x) cout<<x<<"\n";
#define pll pair<ll,ll>
#define mp make_pair
#define Craig ios_base::sync_with_stdio(false) , cin.tie(NULL);
#define all(v) v.begin(),v.end()
#define MAX 200015
#define vll vector<ll>

int main() 
{ 

    ll i,j=0,k=0,n,m=0;
    cin>>n;
    ll a[n];
    for(i=0;i<n;i++)
        cin>>a[i];

    sort(a,a+n);
    for(i=0;i<n;i++)
    {
        for(j=i+1;j<n;j++)
        {
            for(k=j+1;k<n;k++)
            {
                if(a[i]+a[j]>a[k] && a[i]!=a[j] && a[j]!=a[k] && a[k]!=a[i])
                    m++;
            }
        }
    }
    cout<<m<<endl;;
}


Measured memory_bytes: 3632
from collections import defaultdict
N = int(input())
A = list(map(int,input().split()))
constS = defaultdict(int)
constD = defaultdict(int)
for i in range(N):
    Ss = i + A[i]
    Dd = i - A[i]
    constS[Ss] += 1
    constD[Dd] += 1
ans = 0
for key,val in constS.items():
    ans += val * constD[key]
print(ans)

Measured memory_bytes: 73776
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,k,i,count=0;
    cin>>n>>k;
    int arr[n];
    for(i=0;i<n;i++)
        cin>>arr[i];
    for (i=0;i<n;i++)
    {
        if (arr[i]>=k)
            count++;
    }
    cout<<count<<endl;
}

Measured memory_bytes: 640
import sys
N = int(input())
A ={}
for i in range(1,N+1):
    A[i] = int(input())
#print(A)
ans = 1
x = 1
for j in range(N):
    if A[x] == 2:
        print(ans)
        sys.exit()
    x = A[x]
    ans += 1
print(-1)

Measured memory_bytes: 22060
#include <iostream>
#include <stdio.h>
#include <vector>
#include <algorithm>

using namespace std;

#define INF 1000000
#define MAX 1000000

int main(){
	vector <int> v(200);
	for(int i = 0; i < 200; i++)
		v[i] = i * (i + 1) * (i + 2) / 6;
	
	vector <int> d(MAX + 1, INF);
	vector <int> d2(MAX + 1, INF);
	
	d[0] = d2[0] = 0;
	for(int i = 1; i <= MAX; i++){
		for(int j = 0; v[j] <= i; j++){
			d[i] = min(d[i], d[i - v[j]] + 1);
			if(v[j] % 2 != 0)
				d2[i] = min(d2[i], d2[i - v[j]] + 1);
		}
	}
	
	while(1){
		int s;
		cin >> s;
		
		if(s == 0)
			break;
		
		
		
		
		cout << d[s] << " " << d2[s] << endl;
	}
	
	return 0;
}

Measured memory_bytes: 8792