akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdlib>
#include <map>
#include <iomanip>
#include <set>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define int long long
#define pie 3.141592653589793238462643383279
#define mod 1000000007
#define INF 1145141919364364
#define all(vec) vec.begin(),vec.end()
#define P pair<int,int>
#define S second
#define F first
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x%y);
}
int lcm(int x, int y) {
	return x / gcd(x, y)*y;
}
bool prime(int x) {
	for (int i = 2; i <= sqrt(x); i++) {
		if (x%i == 0)return false;
	}
	return true;
}

int kai(int x) {
	if (x == 1)return 1;
	return kai(x - 1)*x%mod;
}

int mod_pow(int x, int y, int moder) {
	int res = 1;
	while (y > 0) {
		if (y & 1)res = res * x%moder;
		x = x * x%moder;
		y >>= 1;
	}
	return res;
}

int comb(int x, int y) {
	if (y > x)return 0;
	if (x == y)return 1;
	return kai(x)* mod_pow(kai(x - y), mod - 2, mod) % mod * mod_pow(kai(y), mod - 2, mod) % mod;
}

int n, a, b;

signed main() {
	cin >> n >> a >> b;
	cout << min(n*a, b) << endl;
}

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

using namespace std;

int n, m;
char str[310];
int D[310][310][310];

int main() {
    int i, j, k, l;

    scanf("%s",str); n = strlen(str);
    scanf("%d",&m);
    for (l=0;l<n;l++) {
        for (i=0;i<n-l;i++) {
            j = i+l;
            for (k=0;k<=l+1;k++) {
                if (!l) {
                    D[i][j][k] = 1;
                    continue;
                }
                D[i][j][k]=max({D[i+1][j][k],D[i][j-1][k],D[i+1][j-1][k]+2*(str[i]==str[j])});
                if (k) D[i][j][k]=max({D[i][j][k],D[i+1][j-1][k-1]+2,D[i][j][k-1]});
            }
        }
    }
    printf("%d\n",D[0][n-1][m]);

    return 0;
}


Measured memory_bytes: 112896
#include <cstdio>
#include <algorithm>
#include <vector>
#include <string>
#include <cassert>
#include <cctype>
#include <numeric>

int parseint(const std::string &s, size_t &pos) {
    int res=0;
    while (s[pos] <= '9')
        res = res*10 + s[pos++]-'0';

    return res;
}

int req(const std::string &s, size_t &pos) {
    assert(s[pos] == '[');

    if (isdigit(s[++pos]))
        return parseint(s, pos)/2+1;

    std::vector<int> reqs;
    while (s[pos] == '[') {
        reqs.emplace_back(req(s, pos));
        assert(s[pos] == ']');
        ++pos;
    }

    std::sort(reqs.begin(), reqs.end());
    return std::accumulate(reqs.begin(), reqs.begin()+reqs.size()/2+1, 0);
}

int solve_testcase() {
    char buf[16384];
    scanf("%s", buf);
    std::string s=buf;

    size_t i=0;
    printf("%d\n", req(s, i));
    return 0;
}

int main() {
    int n;
    scanf("%d", &n);

    for (int i=0; i<n; ++i)
        solve_testcase();

    return 0;
}

Measured memory_bytes: 2836
N,K = map(int,input().split())
R,S,P = map(int,input().split())
T = list(input())
for i in range(N):
    if T[i]=='p':
        T[i] = 's'
    elif T[i]=='s':
        T[i] = 'r'
    else:
        T[i] = 'p'
ans = []
for i in range(N):
    ref = '.'
    if i>=K:
        ref = ans[i-K]
    if T[i] != ref:
        ans.append(T[i])
    else:
        for s in 'rsp':
            if s != T[i]:
                if i+K>=N or s!=T[i+K]:
                    ans.append(s)
                    break
s = 0
for i in range(N):
    if ans[i]==T[i]:
        if ans[i]=='p':
            s += P
        elif ans[i]=='r':
            s += R
        else:
            s += S
print(s)

Measured memory_bytes: 53900
#include<iostream>
#include<stdlib.h>
#include<stdio.h>
#include<string.h>
#include<math.h>
#include<algorithm>
#include<functional>
#include<string>
#include<vector>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#define lowbit(a) ((a)&(-(a)))
using namespace std;

void file(bool opt)
{
	if (opt&&fopen("in.txt", "r"))
	{
		freopen("in.txt", "r", stdin);
		freopen("out.txt", "w", stdout);
	}
}

int sum[100000 + 5];

int main()
{
	int n, m;
	scanf("%d%d", &n, &m);
	for(int i=1;i<=m;i++)
	{
		int l, r;
		scanf("%d%d", &l, &r);
		sum[l]++, sum[r + 1]--;
	}
	long long ans = 0;
	for (int i = 1; i <= n; i++)
	{
		sum[i] += sum[i - 1];
		if (sum[i] == m)ans++;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 640
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

using Pair = System.Collections.Generic.KeyValuePair<int, int>;

class Program
{
	public Program() { }

	static void Main(string[] args)
	{
		new Program().prog();
	}
	Scanner cin;
	const int MOD = 1000000007;
	const int INF = int.MaxValue;
	const double EPS = 1e-7;
	const double PI = 3.1415926536;

	void prog()
	{
		cin = new Scanner();
		int[,] dir8 = new int[8, 2] { { -1, -1 }, { -1, 0 }, { -1, 1 }, { 0, -1 }, { 0, 1 }, { 1, -1 }, { 1, 0 }, { 1, 1 } };
		int[,] dir4 = new int[4, 2] { { -1, 0 }, { 0, -1 }, { 0, 1 }, { 1, 0 } };

		int N = cin.nextInt();
		int M = cin.nextInt();
		//int[] x = new int[M];
		//int[] y = new int[M];
		int x, y;
		int[] num = new int[N];
		int[] red = new int[N];
		red[0] = 1;
		for (int i = 0; i < N; i++)
		{
			num[i] = 1;
		}
		for (int i = 0; i < M; i++)
		{
			x = cin.nextInt() - 1;
			y = cin.nextInt() - 1;
			if (red[x] == 1)
			{
				red[y] = 1;
				if (num[x] == 1)
				{
					red[x] = 0;
				}
			}
			num[x]--;
			num[y]++;
		}
		int ans = 0;
		for (int i = 0; i < N; i++)
		{
			ans += red[i];
		}
		Console.WriteLine(ans);
	}
}

class Scanner
{
	string[] s;
	int i;

	char[] cs = new char[] { ' ' };

	public Scanner()
	{
		s = new string[0];
		i = 0;
	}

	public string next()
	{
		if (i < s.Length) return s[i++];
		string st = Console.ReadLine();
		while (st == "") st = Console.ReadLine();
		s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
		i = 0;
		return next();
	}

	public int nextInt()
	{
		return int.Parse(next());
	}

	public long nextLong()
	{
		return long.Parse(next());
	}

	public double nextDouble()
	{
		return double.Parse(next());
	}
}

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

int main(){
    int n,d;
    cin >> n >> d;
    vector<vector<int>> a(n,vector<int>(d));
    for(int i=0;i<n;i++){
        for(int j=0;j<d;j++){
            cin >> a[i][j];
        }
    }
    int ans=0;
    for(int i=0;i<n-1;i++){
        for(int j=i+1;j<n;j++){
            int num=0;
            for(int k=0;k<d;k++){
                num += (a[i][k]-a[j][k]) * (a[i][k]-a[j][k]);
            }
            bool int_flag = false;
            for(int k=1;k<=num;k++){
                if(k*k == num){
                    int_flag = true;
                    break;
                }
            }
            if(int_flag){
                ans++;
            }
        }
    }
    cout << ans <<endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <bits/stdc++.h>
#include<iostream>
#include<string>
using namespace std;
#define rep(i, n) for (int i = 0; i <(int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define ll long long
const ll MOD=1000000007;
vector<int> enum_div(int n){
    vector<int> ret;
for(int i = 1 ; i*i <= n ; ++i){
        if(n%i == 0){
            ret.push_back(i);
            if(i*i != n){
                ret.push_back(n/i);
            }
        }
    }
    return ret;
}
int main(){
    ll n,m;cin>>n>>m;
    vector<int> s;
    ll ans=0;
    s=enum_div(m);
    sort(all(s),greater<int>());
    ll a[n];
    bool ok=false;
    rep(i,s.size()){
        if(m%s[i]==0&&m/s[i]>=n){
            ok=true;
            ans=s[i];
            break;
    }
}
if(ok)cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
using ll=long long;
using vi=vector<int>;
using pii=pair<int,int>;
#define ALL(c) begin(c),end(c)
#define RALL(c) rbegin(c),rend(c)
#define ITR(i,b,e) for(auto i=(b);i!=(e);++i)
#define FORE(x,c) for(auto &x:c)
#define REPF(i,a,n) for(int i=a,i##len=(int)(n);i<i##len;++i)
#define REP(i,n) REPF(i,0,n)
#define REPR(i,n) for(int i=(int)(n);i>=0;--i)
#define SZ(c) ((int)c.size())
#define CONTAIN(c,x) (c.find(x)!=end(c))
#define OUTOFRANGE(y,x,h,w) (y<0||x<0||y>=h||x>=w)
#define dump(...)
const int DX[9]={0,1,0,-1,1,1,-1,-1,0},DY[9]={-1,0,1,0,-1,1,1,-1,0};
template<class T> ostream& operator<<(ostream &os,const vector<T> &v) {
    ITR(i,begin(v),end(v))os<<*i<<(i==end(v)-1?"":" ");return os;}
template<class T> istream& operator>>(istream &is,vector<T> &v) {
    ITR(i,begin(v),end(v)) is>>*i;return is;}
template<class T,class U> istream& operator>>(istream &is, pair<T,U> &p) {
    is>>p.first>>p.second;return is;}
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(a>b){a=b;return 1;}return 0;}
template<class T> using heap=priority_queue<T,vector<T>,greater<T>>;
struct{template<class T> operator T(){T x;cin>>x;return x;}} IN;
struct before_main_function {
    before_main_function() {
        #ifdef int
            #define INF 1001001001001001001LL
            #define stoi stoll
        #else
            #define INF 1001001001
        #endif
        cin.tie(0);ios::sync_with_stdio(false);
        cout<<setprecision(15)<<fixed;
        // #define endl "\n"
    }
} before_main_function;
//------------------8<------------------------------------8<--------------------

signed main() {
    int N=IN;
    vector<int> A(N),B(N);
    REP(i,N) A[i]=IN,B[i]=IN;
    int ans=0;
    REPR(i,N-1) {
        A[i]+=ans;
        int t=(A[i]+B[i]-1)/B[i]*B[i]-A[i];
        ans+=t;
    }
    cout<<ans<<endl;
    return 0;
}


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

vector<int> g[3000];
int vis[3000];

void dfs(int node){
	vis[node]=true;
	
	for (int i=0; i<g[node].size(); i++){
		if (!vis[g[node][i]]) dfs(g[node][i]);
	}
}


struct edge
{
    int a, b, cost;
    edge(int x, int y, int z){
		a=x;
		b=y;
		cost=z;
    }
};

int n, m;
vector<edge> e;
vector<edge> eaux;
const int INF = 1000000000;


int main(){
	int n,m,p;
	cin>>n>>m>>p;
	
	for (int i=0; i<m; i++){
		int from,to,cost;
		cin>>from>>to>>cost;
		
		from--;
		to--;
		
		g[to].push_back(from);
		
		eaux.push_back(edge(from,to,-(cost-p)));
	}
	
	dfs(n-1);
	
	for (int i=0; i<m; i++){
		if (vis[eaux[i].a] and vis[eaux[i].b]){
			e.push_back(eaux[i]);
		}
		
		//cout<<vis[eaux[i].a]<<endl;
		//cout<<eaux[i].a<<endl;
		//cout<<endl;
	}
	
	
	m=e.size();
	
	vector<int> d (n, INF);
    d[0] = 0;
    for (int i=0; i<n-1; ++i)
        for (int j=0; j<m; ++j)
            if (d[e[j].a] < INF)
                d[e[j].b] = min (d[e[j].b], d[e[j].a] + e[j].cost);
                
                
    vector<int> d1;
    for (int i=0; i<n; i++) d1.push_back(d[i]);
 
    for (int i=0; i<n-1; ++i)
        for (int j=0; j<m; ++j)
            if (d1[e[j].a] < INF)
                d1[e[j].b] = min (d1[e[j].b], d1[e[j].a] + e[j].cost); 
                
                
    for (int i=0; i<n; i++){
		if (d1[i]<d[i]){
			cout<<-1<<endl;
			return 0;
		}
	}   
	
	cout<<max(-d[n-1],0)<<endl;         
      


}


Measured memory_bytes: 640
#include <iostream>
#include <algorithm>
#include <string>
#include <cmath>
#include <ctype.h>
#include <map>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <cctype>
#include <queue>
#define REP(i,n) for(int i=0;i<(int)n;++i)
#define REP1(j,n) for(int j=0;j<(int)n;++j)
#define REPD(i,n) for(int i=n;i>=0;--i)
#define REPD1(j,n) for(int j=n;j=>0;--j)
#define REPS(i,n) for(int i=1;i<=(int)n;++i)
#define REPS1(j,n) for(int j=1;j<=(int)n;++j)
#define rep(i,a,n) for(int i=a;i<=(int)n;++i)
#define SZ(x) ((int)(x).size())	//size() unsigned -> int
#define DescSort(a) sort(a.begin(),a.end(),std::greater<int>())

using namespace std;
typedef long long ll;
const ll INF=1e9+7;

int main(void) {
	int a, b;
	cin >> a >> b;
	int ans;
	if (a <= 5)b = 0;
	else if (6 <= a && a <= 12) {
		b /= 2;
	}
	cout << b << endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>

using namespace std;

int main(){

	int n;	cin>>n;

	string str;

	cin>>str;

	if(n<str.size()){

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

	   cout<<str[i];

	  }

	   cout<<"..."<<endl;

	}

	else cout<<str;

	   return 0;

}

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

#define SZ(x) ((int)(x).size())
#define ALL(x) (x).begin(),(x).end()

#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define REP(i,x) for(int i=0;i<(int)(x);i++)
#define REPS(i,x) for(int i=1;i<=(int)(x);i++)
#define RREP(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define RREPS(i,x) for(int i=((int)(x));i>0;i--)

typedef pair<int, int> pint;

#define mp make_pair
#define mt make_tuple
#define pb push_back
#define pf push_front

#define MOD (1000 * 1000 * 1000 + 7)

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

    vector<int> b;
    REP(i, N) {
        int a; cin >> a;
        b.pb(a);
    }

    vector<int> answers;

    bool ng = false;
    REP(i, N) {
        RREP(j, N-i) {
            if (b[j] - 1 == j) {
                b.erase(b.begin() + j, b.begin() + j + 1);
                answers.pb(j+1);
                break;
            }

            if (b[j] - 1 > j) {
                ng = true;
                break;
            }
        }

        if (ng == true) break;
    }

    if (ng) {
        cout << -1 << endl;
    } else {
        RREP(i, N) {
            cout << answers[i] << endl;
        }
    }

    return 0;
}

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

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<int, int> Pi;
typedef vector<ll> Vec;
typedef vector<int> Vi;
typedef vector<string> Vs;
typedef vector<vector<ll>> VV;
typedef vector<vector<int>> VVi;

#define REP(i, a, b) for(ll i=(a); i<(b); i++)
#define PER(i, a, b) for(ll i=(a); i>=(b); i--)
#define rep(i, n) REP(i, 0, n)
#define per(i, n) PER(i, n, 0)
const ll INF=1e16+18;
const ll MAX=100005;
const ll MOD=1000000007;
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl;
#define YES(n) cout << ((n) ? "YES" : "NO") << endl;
#define ALL(v) v.begin(), v.end()
#define pb(x) push_back(x)
#define mp(a, b) make_pair(a,b)
#define Each(a,b) for(auto &a :b)
#define REPM(i, mp) for (auto i = mp.begin(); i != mp.end(); ++i)
#define dbg(x_) cerr << #x_ << ":" << x_ << endl;
#define dbgmap(mp) cerr << #mp << ":"<<endl; for (auto i = mp.begin(); i != mp.end(); ++i) { cerr << i->first <<":"<<i->second << endl;}
#define dbgarr(n,m,arr) rep(i,n){rep(j,m){cerr<<arr[i][j]<<" ";}cerr<<endl;}
#define dbgdp(n,arr) rep(i,n){cerr<<arr[i]<<" ";}cerr<<endl;
#define sum(v) accumulate(ALL(v),0)
#define fi first
#define se second

template<typename T1, typename T2>
ostream &operator<<(ostream &s, const pair<T1, T2> &p) { return s<<"("<<p.first<<", "<<p.second<<")"; }

// vector
template<typename T>
ostream &operator<<(ostream &s, const vector<T> &v) {
    int len=v.size();
    for(int i=0; i<len; ++i) {
        s<<v[i];
        if(i<len-1) s<<"	";
    }
    return s;
}

// 2 dimentional vector
template<typename T>
ostream &operator<<(ostream &s, const vector<vector<T> > &vv) {
    int len=vv.size();
    for(int i=0; i<len; ++i) {
        s<<vv[i]<<endl;
    }
    return s;
}

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

    ll n,k;
    cin>>n>>k;
    vector<Pi> ss;

    priority_queue<ll, vector<P>, function<bool(P, P)>> q([](P a, P b)->ll {
        return a.first>b.first;
    });

    rep(i,n){
        int t,d;
        cin>>t>>d;
        t--;
        ss.emplace_back(d,t);
    }
    sort(ALL(ss));
    reverse(ALL(ss));


    map<ll,ll> mp;
    ll d=0;

    vector<Pi> cng;
    rep(i,n){
        Pi &now =ss[i];
        if(i<=k-1){
            d += now.fi;
            mp[now.se]++;
            if(mp[now.se]>1){
                q.push(mp(now.fi,now.se));
            }
        }else{
            cng.emplace_back(mp(now.fi,now.se));
        }
    }


    sort(ALL(cng));
    reverse(ALL(cng));

    ll ans=mp.size()*mp.size()+d;

    rep(i,cng.size()){
        if(q.empty()){
            break;
        }

        Pi &now = cng[i];
        if(mp[now.se]>0){
            continue;
        }

        mp[now.se]++;
        Pi del = q.top();
        d -= del.fi;
        q.pop();
        d += now.fi;
        ll x = mp.size()*mp.size()+d;
        ans = max(ans, x);
    }
    
    cout<<ans<<endl;
    return  0;
}


Measured memory_bytes: 5876
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cctype>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>
#include<complex>

using namespace std;

#define ll long long
#define ld long double
#define EPS 1e-9
#define INF 1e9
#define LINF (ll)INF*INF
#define MOD 1000000007
#define rep(i,n) for(int i=0;i<(n);i++)
#define loop(i,a,n) for(int i=a;i<(n);i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

#define int ll //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int,int> pii;
typedef pair<pii,int> ppi;
typedef pair<int,pii> pip;
typedef vector<pii> vp;
typedef vector<vi> vvi;

int gcd(int a, int b){if(b==0) return a;return gcd(b,a%b);}
int lcm(int a, int b){return a/gcd(a,b)*b;}


signed main(void) {
    int n,k;
    cin >> n >> k;
    vi a(n),f(n);
    rep(i,n)cin >> a[i];
    rep(i,n)cin >> f[i];
    sort(all(a));
    sort(all(f));
    int ok = a.back()*f.back(), ng = -1;
    reverse(all(f));
    while(ok - ng > 1){
        int mid = (ok + ng)/2;
        int cnt = 0;
        //cout << ok << " " << ng << " " << mid << endl;
        rep(i,n){
            int t = mid/f[i];
            //cout << i << " " << t << endl;
            if(t < a[i])cnt += a[i] - t;
        }
        //cout << "!" << cnt << endl;
        if(cnt <= k)ok = mid;
        else ng = mid;
    }
    cout << ok << endl;
}


Measured memory_bytes: 3328
#!/usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
from bisect import bisect_left, bisect_right
import sys, itertools, math
sys.setrecursionlimit(10**5)
input = sys.stdin.readline
sqrt = math.sqrt
def LI(): return list(map(int, input().split()))
def LF(): return list(map(float, input().split()))
def LI_(): return list(map(lambda x: int(x)-1, input().split()))
def II(): return int(input())
def IF(): return float(input())
def S(): return input().rstrip()
def LS(): return S().split()
def IR(n):
    res = [None] * n
    for i in range(n):
        res[i] = II()
    return res
def LIR(n):
    res = [None] * n
    for i in range(n):
        res[i] = LI()
    return res
def FR(n):
    res = [None] * n
    for i in range(n):
        res[i] = IF()
    return res
def LIR(n):
    res = [None] * n
    for i in range(n):
        res[i] = IF()
    return res
def LIR_(n):
    res = [None] * n
    for i in range(n):
        res[i] = LI_()
    return res
def SR(n):
    res = [None] * n
    for i in range(n):
        res[i] = S()
    return res
def LSR(n):
    res = [None] * n
    for i in range(n):
        res[i] = LS()
    return res
mod = 1000000007
inf = float('INF')

#solve
def solve():
    n,k = LI()
    a = LI()
    def f(x):
        tmp = 0
        for ai in a:
            tmp += int(ai / x) - (ai % x == 0)
        return tmp <= k
    ok = 10 ** 9
    ng = 0
    while ok - ng > 1:
        mid = (ok + ng) // 2
        if f(mid):
            ok = mid
        else:
            ng = mid
    print(ok)
    return


#main
if __name__ == '__main__':
    solve()


Measured memory_bytes: 91672
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush
from bisect import bisect_left,bisect_right 
import sys,math,itertools,fractions,pprint
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))

a,b,c = inpl()
res = 0
for i in range(a,b+1):
    if i%c == 0:
        res += 1
print(res)

Measured memory_bytes: 72476
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<(n); ++i)
#define rep2(i, s, n) for(int i=s; i<(n); ++i)

using namespace std;

typedef long long ll;

static const int INTINF = (2147483647);
static const ll LLINF = (9223372036854775807);
static const int MAX = 100001;
static const ll MOD = 1000000007;

//--global--//

template<typename T>
T gcd(T a, T b){if( b == 0)return a; return gcd(b, a%b); }
template<typename T>
T lcm(T a, T b){return a*b/gcd(a,b); }
void printArr(int *a, int len){for(int i=0; i<len; i++){if(i)cout << " ";cout << a[i];}cout << endl;}
/*******---------------------*******/

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

int main(int argc, const char * argv[]) {
    //提出時、消す----//
    //--------------//

    int N, X;
    int x[MAX];
    cin >> N >> X;
    rep(i, N){
        int a;
        cin >> a;
        x[i] = abs(a-X);
    }

    int res = 0;
    rep(i, N-1){
        if(!i){
            res = gcd(x[i], x[i+1]);
        }
        else{
            res = gcd(res, x[i+1]);
        }
    }
    if(N==1){
        res = x[0];
    }

    cout << res << endl;
    
    return 0;
}


Measured memory_bytes: 640
#include <stdio.h>

#define MAX 100000000

struct NODE {
    int distance;
    int state;
} vertex[101];

int W[101][101];
int n, m;

int min(int a, int b) {
    return (a > b ? b : a);
}

int prim(int start) {
    int x, p, step, sum = 0;

    for (x = 0; x < n; x++) {
	vertex[x].distance = MAX; vertex[x].state = 0;
    }
    vertex[start].distance = 0; 
    for (step = 1; step <= n; step++) {
	int minimum = MAX;
	for (x = 0; x < n; x++)
	    if (vertex[x].state == 0 && vertex[x].distance < minimum) {
		p = x; minimum = vertex[x].distance;
	    }
	vertex[p].state = 1;
	sum += minimum;
	for (x = 0 ; x < n; x++)
		vertex[x].distance = min(vertex[x].distance, W[p][x]);
    }
    return sum;
}

int main(void) {
    int i, j;
    int from, to, cost;
     
    while (1) {
	scanf("%d", &n);
	scanf("%d", &m);
        if (n == 0) break;
         
        for (i = 0; i < n; i++)
            for (j = 0; j < n; j++)
                W[i][j] = MAX;
         
	for (i = 0; i < m; i++) {
            scanf("%d %d %d", &from, &to, &cost);
            W[from][to] = cost;
	    W[to][from] = cost;
        }

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

Measured memory_bytes: 640
import java.util.*;
import static java.lang.System.*;

public class Main {
	static Scanner sc = new Scanner(System.in);
	public static void main(String[] args) {
		int n = sc.nextInt();
		for (int i=1; i<=n; i++) {
			if (i%3==0 || String.valueOf(i).contains("3")) {out.print(" "+i);}
		}
		out.println();
	}
}


Measured memory_bytes: 29160
#include <bits/stdc++.h>
#define REP(i, a, n) for(ll i = ((ll) a); i < ((ll) n); i++)
#define INF (1LL << 60)
#define MOD 1000000007LL
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;
typedef vector<ll> vll;
typedef pair<vll, vll> pvll;

struct state {
  ll d, v, p;

public:
  bool operator<(const state s) const { return d > s.d; }
};

const ll S = 0, G = 1;
ll N, M, A[100000], B[100000], C[100000];
vector< vector<pll> > E1(100000), E2(100000);

pvll dijkstra(vector< vector<pll> > &E, ll s) {
  vll dist(N, INF), cnt(N, 0);
  priority_queue<state> q;
  q.push((state) { 0, s, -1 });

  while(q.size()) {
    ll d = q.top().d, v = q.top().v, p = q.top().p;
    q.pop();

    if(dist[v] < d) continue;
    (cnt[v] += (p != -1 ? cnt[p] : 1)) %= MOD;

    if(dist[v] <= d) continue;

    dist[v] = d;
    REP(i, 0, E[v].size()) {
      ll u = E[v][i].first, c = E[v][i].second;
      if(dist[u] > d + c) q.push((state) { d + c, u, v });
    }
  }

  return pvll(dist, cnt);
}

int main(void) {
  cin >> N >> M;
  REP(i, 0, M) {
    cin >> A[i] >> B[i] >> C[i]; A[i]--; B[i]--;
    E1[A[i]].push_back(pll(B[i], C[i]));
    E2[B[i]].push_back(pll(A[i], C[i]));
  }

  pvll d1 = dijkstra(E1, S), d2 = dijkstra(E2, G);
  vll dist1 = d1.first, dist2 = d2.first, cnt1 = d1.second, cnt2 = d2.second;

  ll orgd = dist1[G];
  ll orgc = cnt1[G];

  REP(i, 0, M) {
    ll u = A[i], v = B[i], cost = C[i];
    if(dist1[v] + cost + dist2[u] < orgd) cout << "HAPPY" << endl;
    else if(dist1[u] + cost + dist2[v] == orgd && (cnt1[u] * cnt2[v]) % MOD == orgc) cout << "SAD" << endl;
    else cout << "SOSO" << endl;
  }
}

Measured memory_bytes: 22304
rev = {"(":")", "[":"]"}

while True:
    s = input()
    if s == '.':
        break
    stack = []
    flag = True
    for i in s:
        if i == '(' or i == '[':
            stack.append(i)
        if i == ')' or i == ']':
            if len(stack) == 0 or rev[stack[-1]] != i:
                flag = False
                break
            else:
                stack.pop()
    if len(stack) == 0 and flag:
        print("yes")
    else:
        print("no")

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

//#define int long long
#define ll long long
#define all(v) (v).begin(), (v).end()
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<n;++i)
#define exrep(i, a, b) for(ll i = a; i < b; i++)
#define out(x) cout << x << endl
#define EPS (1e-7)
#define gearup ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
typedef pair<ll, ll> P;
typedef vector<ll> vl;
typedef vector<vector<ll> > vvl;
typedef vector<vector<vector<ll> > > vvvl;
ll MOD = 1000000007;
const long long L_INF = 1LL << 60;
const int INF = 2147483647; // 2^31-1
const double PI = acos(-1);
//cout<<fixed<<setprecision(10);

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;}
template<class T> void debug(T v){rep(i,v.size()) cout<<v[i]<<" ";cout<<endl;}
const ll dx[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll dy[8] = {0, 1, 1, 1, 0, -1, -1, -1};

//文字列sの中から文字cをカウントする
int stringcount(string s, char c) {
    return count(s.cbegin(), s.cend(), c);
}
signed main()
{   
    gearup;
    string s;cin>>s;
    out(stringcount(s,'1'));
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{

    int n,s=0,t;
    cin>>n;
    t=n;
    while(n>0)
    {
        s+=n%10;
        n=n/10;
    }

    if(t%s==0)
    {
        cout<<"Yes"<<endl;
    }
    else
    {
        cout<<"No"<<endl;
    }
    return 0;
}




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

int main()
{
  int N,M ;
  cin>>N>>M ;
  vector<int>X(M) ;
  for(int i=0;i<M;i++) cin>>X.at(i) ;
  sort(X.begin(),X.end()) ;
  
  if(N>=M){
    cout<<0<<endl ;
    return 0 ;
  }
  vector<int>Y(M-1) ;
  for(int i=0;i<M-1;i++) Y.at(i)=X.at(i+1)-X.at(i) ;
  sort(Y.begin(),Y.end()) ;
  
  int ans=0 ;
  for(int i=0;i<M-N;i++) ans+=Y.at(i) ;
  
  cout<<ans<<endl ;
  
  return 0 ;
}

Measured memory_bytes: 1024
const ab_count = array => {
  var result=0;
  for(var i=0;i<array.length-1;i++){
    if(array[i]=='A' && array[i+1]=='B'){result++;}
  }
  return result;
}

const main = input => {
  const lines = input.split('\n');
  const N = lines[0].split(' ').map(x => parseInt(x))[0];
  lines.shift();
  const S = lines;

  var result = 0;
  var head=0;
  var tail=0;
  var sum=0;
  for(var i=0;i<N;i++){
    var current_s = S[i].split('');
    if(current_s[0]=='B'){head++;}
    if(current_s[current_s.length-1]=='A'){tail++;}
    if(current_s[0]=='B' || current_s[current_s.length-1]=='A'){sum++;}
    result += ab_count(current_s);
//    console.log([current_s,ab_count(current_s)]);
  }
  const addition = Math.min(tail,head, Math.max(0,sum-1));

  console.log(result+addition);
}

main(require('fs').readFileSync('/dev/stdin', 'utf8'));


Measured memory_bytes: 9532
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second

int n;
string name[40];
vector<string> neighbor[40];
map<string,int> name2id;
int a[40],b[40],c[40];
int G[40][40];

const int N=1<<20;
int dp[N];
int NG[40],OK[40];

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

    while(cin >>n,n)
    {
        // initialize
        name2id.clear();
        rep(i,40) neighbor[i].clear();
        memset(G,0,sizeof(G));
        memset(dp,0,sizeof(dp));
        memset(NG,0,sizeof(NG));
        memset(OK,0,sizeof(OK));

        // input
        rep(i,n)
        {
            cin >>name[i] >>b[i] >>c[i];
            neighbor[i].resize(c[i]);
            rep(j,c[i]) cin >>neighbor[i][j];

            a[i] = i;
            name2id[name[i]] = i;
        }

        rep(i,n)rep(j,c[i]) G[i][name2id[neighbor[i][j]]] = 1;

        int X=n/2, Y=n-X;

        // make NG mask
        rep(i,X)rep(j,X)if(G[i][j]) NG[i] |= 1<<j;
        rep(i,Y)rep(j,Y)if(G[X+i][X+j]) NG[X+i] |= 1<<j;

        // make OK mask
        rep(i,X)rep(j,Y)if(G[i][X+j]==0) OK[i] |= 1<<j;

        // ?????????????????????????????¶
        rep(mask,1<<Y)
        {
            bool ok=true;
            int sum=0;
            rep(i,Y)if(mask>>i&1)
            {
                ok &= ((NG[X+i]&mask) == 0);
                sum += b[X+i];
            }

            if(ok) dp[mask] = sum;
        }

        rep(mask,1<<Y)rep(i,Y)if(!(mask>>i&1))
        {
            int nmask = mask|(1<<i);
            dp[nmask] = max(dp[nmask],dp[mask]);
        }

        int ans=0;
        // ?????????????????????????????¶
        for(int mask=1; mask<(1<<X); mask+=2)
        {
            bool ok=true;
            int val = 0, t = (1<<Y)-1;
            rep(i,X)if(mask>>i&1)
            {
                ok &= ((NG[i]&mask) == 0);
                val += b[i];
                t &= OK[i];
            }
            if(!ok) continue;

            ans = max(ans, val+dp[t]);
        }

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

Measured memory_bytes: 7356
#include <bits/stdc++.h>
using namespace std;
const int64_t INF=999999999;

int main() {
   int A,B,C;
   cin>>A>>B>>C;
   int sum=A+B+C;
   int x=max({A,B,C});
   int y=min({A,B,C});
   int z=sum-x-y;
   cout<<10*x+y+z<<endl;
return 0;}

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

void solve()
{
	int n;
	cin>>n;
	cout<<(1000-n%1000)%1000<<endl;
}

int main()
{
	ll t = 1;
// /	cin>>t;
	while(t--)
	{
		solve();
	}
}

Measured memory_bytes: 3548
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
using Graph=vector<vector<ll>>;
ll N,M;
int main(){
  cin>>N>>M;
  Graph G(N);
  for(int i=0;i<M;i++){
  ll u,v;cin>>u>>v;u--;v--;
    G[u].push_back(v);
    G[v].push_back(u);
  }vector<ll>dist(N,-1);
  ll a=0;ll b=0;ll c=0;
  for(int i=0;i<N;i++){
  if(dist[i]==-1){
  bool x=true;
    dist[i]=0;
    queue<ll>que;que.push(i);ll sum=1;
    while(!que.empty()){
    ll u=que.front();
      que.pop();
      for(auto v:G[u]){
      if(dist[v]!=-1 && dist[v]!=dist[u])
        continue;
        else if(dist[v]==dist[u] && x)
          x=false;
        else{
        dist[v]=dist[u]+1;sum++;que.push(v);
        }
      }
     }if(sum==1)b+=1;
    else{
    a++;
      if(x)c++;
    
    }
  
  }
  }ll ans=2*b*(N-b)+(b*b)+(a*a)+(c*c);
  cout<<ans<<endl;
  return 0;
}

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

typedef long long ll;
typedef pair<int,int> P;

const int INF = 1e9;
const int mod = 1e9+7;

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

    cout << (x == 3 || x == 5 || x == 7 ? "YES" : "NO") << endl;

    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<stdint.h>
#include<stdbool.h>
#include<tgmath.h>
#include<sys/queue.h>
#include<time.h>
#define ll long long
#define min(a, b) ((a) > (b) ? (b) : (a))
#define max(a, b) ((a) > (b) ? (a) : (b))
#define miin(a, b, c) min((a), min((b), (c)))
#define maax(a, b, c) max((a), max((b), (c)))
#define mod 1000000007
const int INF = 1000000000;
const int NIL = -1;

int n, k, s;

main(){
    scanf("%d%d%d", &n, &k, &s);
    for(int i=0; i<k; i++){
        printf("%d ", s);
    }
    for(int i=k; i<n; i++){
        printf("%d ", s==INF?1:INF);
    }
    return 0;
}

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

int findSum(int n){
	int sum = 0;
  while(n >0) {
  	sum += n % 10;
    n /= 10;
  }
  return sum;
}
int main(){
	int N, a, b;
  	cin >> N >> a >> b;
  	int total = 0;
  	for(int i = 0; i <= N; i++) {
    	int sum = findSum(i);
      	if (sum >= a && sum <=b) {
        	total += i;
        }
    }
  
  	cout << total << endl;
 
}

Measured memory_bytes: 760
n,m = map(int,input().split())
#L = list(map(int,input().split()))
L = []
s = set()
for i in range(m):
    li = []
    d = int(input())
    e = list(map(int,input().split()))
    li.append(e)
        #s.add(e)
    L.append(*li)
#print(L,s)
for i in range(m):
    for j in range(len(L[i])):
        s.add(L[i][j])
#print(s)
print(n-len(s))

Measured memory_bytes: 9196
#include <stdio.h>
int main(void){
  int i,j,k;
  scanf("%d%d",&i,&j);
  for(k=0;k<100000000;i++,k++){
    if(j%i==0){
      printf("%d",j/i);
      break;
    }
  }
  if(k>=99999999){
    for(int l=10;l>0;l--){
      if(j%l==0) printf("%d",l);
    }
  }
  return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define In_The_Name_Of_Allah_The_Merciful ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define Alhamdulillah return 0;
#define debug(n) cerr << "[" << #n << " = " << n << "]" << endl 

const int N =  1e5;
vector <int> adj[N];
int n;
vector <array<int,2>> edges;
map <pair<int,int>,int> Color;
int numColor;

void dfs (int u = 0 , int p = -1){
    int cur = 1;
    for (int v : adj[u]){
        if (v == p) continue;
        if (Color[{u,p}] == cur)
            ++cur;
        Color[{u,v}] = Color[{v,u}] = cur;
        numColor = max (numColor,cur);
        dfs(v,u);
        ++cur;
    }
}

void Suhaib_Sawalha (){

    cin >> n;
    for (int i = 1 , u , v ; i < n ; ++i){
        cin >> u >> v;
        --u , --v;
        adj[u].push_back(v);
        adj[v].push_back(u);
        edges.push_back({u,v});
    }

    dfs();

    cout << numColor << '\n';
    for (array <int,2> &x : edges)
        cout << Color[{x[0],x[1]}] << '\n';
    
}

int main(){
                                In_The_Name_Of_Allah_The_Merciful   /* بسم الله الرحمن الرحيم  */
#ifndef ONLINE_JUDGE
    freopen("SuhaibSawalha1.txt","r",stdin);
#endif
//int _;for(cin>>_;_;--_,cout<<'\n')
        Suhaib_Sawalha();
                                         Alhamdulillah                    /* الحمد لله */
}

Measured memory_bytes: 23184
#include <iostream>
#include <iomanip>
#include <string>
#include <sstream>
#include <bitset>
#include <algorithm>
#include <cmath>
#include <numeric>
#include <utility>
#include <set>
#include <map>
#include <tuple> 
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <list>
using namespace  std;
using ll = long long;
using P = pair<ll, ll>;
#define REP(i, n) for(long long (i)=0, i_bound = (long long)(n); (i)<i_bound; ++i)
#define FOR(i, a, b) for(long long (i)=(a); (i)<(b); ++i)
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
const long long MOD = static_cast<long long>(1e9) + 7LL;
const long long INF = 1234567891234567890LL;
int main(){
    cin.tie(0);
    cout.sync_with_stdio(false);
    ll N;
    cin>>N;
    vector<ll> A(N);
    vector<ll> C(N+1);
    REP(i, N) cin>>A[i];
    ll sum = 0;
    REP(i, N) C[i+1] = C[i] + A[i];
    ll res = 0;
    ll idx = 0;
    ll dif = C[N];
    REP(i, N){
        if(dif > abs(C[N]-C[i]*2)){
            dif = abs(C[N]-2*C[i]);
            idx = i;
        }
    } 
    res = dif;
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 3456
a,b = map(int,input().split())
def func(x):
    ans = 0
    for i in range(1,41):
        loop = 2**i
        cnt = (x//loop) * (loop//2)
        cnt += max(0,(x%loop)-(loop//2)+1)
        if cnt%2 == 1:
            ans += 2**(i-1)
    return ans

print(func(a-1)^func(b))

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define ll long long
#define rep(i,n) for(int i=0;i<n;i++)
#define rrep(i,n) for(int i=1;i<=n;i++)
#define drep(i,n) for(int i=n;i>=0;i--)
#define INF 100000005
#define MAX 1002
#define mp make_pair
#define pb push_back
#define fi first
#define se second
using namespace std;
//__gcd(a,b), __builtin_popcount(a);

int a[101], b[101], c[101];
int main(){
	int n, m, t, r, ans = 0;
	scanf("%d%d", &n, &m);
	rrep(i,m)scanf("%d", &a[i]);
	
	for(int i = 1;i <= m;i++){
		r = 0;
		for(int j = 1;j <= n;j++){
			scanf("%d", &t);
			if(t == a[i])c[j]++;
			else r++;
		}
		c[a[i]] += r;
	}
	rrep(i,n)printf("%d\n", c[i]);
	return 0;
}

Measured memory_bytes: 3188
#include <iostream>
#include <map>

using namespace std;
int main(void){
    
    map<int, int> m;
    

    int n,q;
    
    cin >> n;
    int tmp;
    for(int i=0; i < n; i++){
        cin >> tmp;
        m[tmp]=1;
    }
    
    int count = 0;
    cin >> q;
    for(int i=0; i < q; i++){
        cin >> tmp;
        if(m[tmp]==1)count++;
        
    }
    cout << count << endl;
    return 0;
}




Measured memory_bytes: 10124
#include <bits/stdc++.h>
#define PI 3.14159265359
using namespace std;
template <class T>
inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T>
inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
const long long INF = 1LL << 60;
using pll = pair<long long, long long>;

int main() {
  // 標準入力が早くなる。Cスタイルの入出力とC++スタイルの入出力を混合させてはならない。
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);

  int S, W;
  cin >> S >> W;

  if (S <= W) {
    cout << "unsafe" << endl;
  } else {
    cout << "safe" << endl;
  }
  return 0;
}


Measured memory_bytes: 3612
import java.util.Scanner;
public class Main {
	public static void main(String[] args){
		Scanner stdIn=new Scanner(System.in);
		int N=stdIn.nextInt();
		int K=stdIn.nextInt();
		int A[]=new int[N];
		int z=0;
		long mi=0,pl=0,min=0;
		while(z<N){
			A[z]=stdIn.nextInt();
			z++;
		}z=1;
		if(A[0]<0)
			mi=A[0]*-1;
		if(A[K-1]>0)
			pl=A[K-1];
		if(mi<=pl)
			min=mi*2+pl;
		else
			min=pl*2+mi;
		K--;
		while(z<N-K){
			if(A[z]<0)
				mi=A[z]*-1;
			else
				mi=0;
			if(A[z+K]>0)
				pl=A[z+K];
			else
				pl=0;
			long a=0;
			if(mi<=pl)
				a=mi*2+pl;
			else
				a=pl*2+mi;
			if(a<min)
				min=a;
			z++;
		}
		System.out.println(min);
	}
}

Measured memory_bytes: 50348
#!/usr/bin/env python3

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

d = I()
if d == 25:
    print('Christmas')
elif d == 24:
    print('Christmas Eve')
elif d == 23:
    print("Christmas Eve Eve")
else:
    print('Christmas Eve Eve Eve')

Measured memory_bytes: 38256
#include <bits/stdc++.h>
#define FOR(i, a, b) for(int i=(a); i<(b); i++)
#define REP(i, n) FOR(i, 0, n)
#define all(x) (x).begin(), (x).end()
#define bit(x) (1L << (x))
using ll = long long;
using namespace std;

template<typename T>
vector<T> make_v(size_t a){return vector<T>(a);}

template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
    return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}

template<typename T,typename V>
typename enable_if<is_class<T>::value==0>::type
fill_v(T &t,const V &v){t=v;}

template<typename T,typename V>
typename enable_if<is_class<T>::value!=0>::type
fill_v(T &t,const V &v){
    for(auto &e:t) fill_v(e,v);
}

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

  char tmp = -1;
  int cnt = 0;
  for(const auto& c: s){
    if(c != tmp){
      tmp = c;
      cnt++;
    }
  }

  cout << cnt - 1 << endl;

  return 0;
}


Measured memory_bytes: 512
#include <stdio.h>

void sort00(int data[], int n);
void sort01(int data[], int n);
int maxindex00(int data[], int from, int to);
int minindex00(int data[], int from, int to);
int pow(int i, int k);

int main()
{
	int i,k,n;
	int x;
	int max=0,min=0;
	int answer;
	int num[8];
	char data[9];
	scanf("%d", &n);
	for(i=0; i<n; i++){
		scanf("%s", data);
		for(k=0; k<8; k++){
			num[k]=data[k]-'0';
		}
		sort01(num, 8);
		for(k=0; k<8; k++){
			max+=num[k]*pow(10,8-1-k);
		}
		sort00(num, 8);
		for(k=0; k<8; k++){
			min+=num[k]*pow(10,8-1-k);
		}
		answer=max-min;
		printf("%d\n", answer);
		max=0;
		min=0;
	}
	return 0;
}

int pow(int i, int k)
{
	int x;
	int result=i;
	if(k!=0){
		for(x=0; x<k-1; x++){
			result*=i;
		}
		return result;
	}
	else{
		return 1;
	}
}

void sort00(int data[],int n)
{
	int i,work,minindex;
	for(i=0;i<n;i++){
		minindex=minindex00(data,i,n);
		work=data[i];
		data[i]=data[minindex];
		data[minindex]=work;
	}
	return;
}

int minindex00(int data[], int from, int to)
{
	int i;
	int result=from;
	for(i=from;i<to;i++){
		if(data[result]>data[i]){
			result=i;
		}
	}
	return result;
}

void sort01(int data[],int n)
{
	int i,work,maxindex;
	for(i=0;i<n;i++){
		maxindex=maxindex00(data,i,n);
		work=data[i];
		data[i]=data[maxindex];
		data[maxindex]=work;
	}
	return;
}

int maxindex00(int data[], int from, int to)
{
	int i;
	int result=from;
	for(i=from;i<to;i++){
		if(data[result]<data[i]){
			result=i;
		}
	}
	return result;
}

Measured memory_bytes: 592
#include<stdio.h>
int main()
{
    int n;
    scanf("%d", &n);
    char s[300005];
    scanf("%s", s);
    int e[300005], w[300005];
    e[0] = w[0] = 0;
    int i;
    for (i = 0; i < n; i++)
    {
        if (s[i] == 'E')
        {
            e[i + 1] = e[i] + 1;
            w[i + 1] = w[i];
        }
        else
        {
            e[i + 1] = e[i];
            w[i + 1] = w[i] + 1;
        }
    }
    int min = 333333;
    int x;
    for (i = 0; i < n; i++)
    {
        x = w[i];
        x += e[n] - e[i + 1];
        if (min > x)
            min = x;
    }
    printf("%d\n", min);
    return 0;
}


Measured memory_bytes: 2816
#include<cstdio>
#include<vector>
#include<cstring>
#include<algorithm>
using namespace std;
int n;
int ws(int a)
{
	int re=0;
	while(a)
	{
		re+=a%10;
		a/=10;
	}
	return re;
}
int main()
{
	scanf("%d",&n);
	int ans=n;
	for(int i=1;i<=n/2;i++)
	{
		int e=ws(i)+ws(n-i);
		ans=min(e,ans);
	}
	printf("%d\n",ans);
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define int long long
#define ll long long 
#define rep(i,a,b) for(signed i=a;i<(b);++i)
#define erep(i,a,b) for(signed i=a;i<=(b);++i)
#define per(i,a,b) for(signed i=(a);i>(b);--i)
#define eper(i,a,b) for(signed i=(a);i>=b;--i)
#define fore(i, x, a) for(auto &&x:a) 
#define ITR(i,b,e) for(auto i=(b);i!=(e);++i)
#define pb emplace_back
#define mp make_pair
#define ALL(x) begin(x),end(x)
#define F first
#define S second
#define debug(x)  cout << #x << ": " << (x) << '\n';
const long long INF=1001001001001001001;
const int MOD=(int)1e9 + 7;
const double EPS=1e-9;
using namespace std;
using Pii = pair<int,int>;
using vii = vector<int>;
template<class T>using  PS_queue = priority_queue<T, vector<T>, greater<T> >;
template<class T>using vv = vector<T>;
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; }
template<typename A, size_t N, typename T> void Fill(A (&array)[N], const T &val){fill( (T*)array, (T*)(array+N), val );}
template<class T> ostream& operator<<(ostream &os,const vector<T> &v) {
    ITR(i,begin(v),end(v))os<<*i<<(i==end(v)-1?"":" ");return os;}
template<class T> ostream& operator<<(ostream &os,const vector<vector<T> > &v) {
    ITR(u,begin(v),end(v))ITR(w,begin(*u),end(*u))os<<*w<<(w==end(*u)-1?"\n":" ");return os;}
template<class T> istream& operator>>(istream &is,vector<T> &v) {
    ITR(i,begin(v),end(v)) is>>*i;return is;}
template<class T,class U> istream& operator>>(istream &is, pair<T,U> &p) {
    is>>p.first>>p.second;return is;}
template<class T>T gcd(T a, T b){ return b ? gcd(b, a % b) : a; }
template<class T>T lcm(T a, T b){ return a / gcd(a, b) * b; }
struct edge { int from, to, cost; };
int dy[]={0, 1, -1, 0}; int dx[]={1, 0, 0, -1};
// cout << fixed << setprecision(10) << val;

int N, p[51];
signed main() {
 cin.tie(0);
 ios::sync_with_stdio(false);
  cin >> N;
  rep(i, 0, N) cin >> p[i];
  vii sorted(N);
  iota(ALL(sorted), 1);

  int diff = 0;
  rep(i, 0, N) {
    if (sorted[i] != p[i]) diff++;
  }
  if (diff <= 2) cout << "YES" << endl;
  else cout << "NO" << endl;
  return 0;
}




Measured memory_bytes: 256
import sys
input = sys.stdin.readline
 
 
def main():
    X = int(input().rstrip())
    f = 0
    for a in range(-150, 150):
        for b in range(-150, 150):
            i = a ** 5 - b ** 5
            if i == X:
                print(a, b)
                f = 1
                break
 
        if f:
            break
 
 
if __name__ == '__main__':
    main()

Measured memory_bytes: 9192
#include<stdio.h>

int main()
{
 char s[100005];
 char out[50005];
 int i;
 int count = 0;

 for(i=0; i<100000; i++)
 {
  scanf("%c",&s[i]);
  if((s[i]<'a')|(s[i]>'z')) break;
  if(i%2 == 0) 
  {
    out[i/2]=s[i];
    count++;
  }
 }

 for(i=0; i<count; i++) printf("%c",out[i]);
 printf("\n");

 return 0;
}


Measured memory_bytes: 384
import fractions
from functools import reduce
N,X=map(int,input().split())
li=list(map(int,input().split()))
li2=[X]*N
a=[abs(x-y) for x,y in zip(li2,li)]
def gcd(*n):
    return reduce(fractions.gcd, n)
print(gcd(*a))

Measured memory_bytes: 16304