akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
using Graph = vector<vector<int>>;
int main(void) {
    int N,M;
    cin >> N >> M;
    Graph G;
    G.assign(N,vector<int>());
    rep(i,M){
        int A,B;
        cin >> A >> B;
        --A,--B;
        G[A].push_back(B);
        G[B].push_back(A);
    }
    vector<int> dist(N,-1);
    vector<int> prev(N,-1);
    queue<int> que;
    que.push(0);
    dist[0] = 0;
    while(!que.empty()){
        // queから先頭頂点を取り出す
        int v = que.front();
        que.pop();
        // 先頭頂点からたどれる頂点を全て調べる
        for(auto nv:G[v]){
            if(dist[nv] == -1){
               dist[nv] = dist[v] + 1;
            prev[nv] = v;
            que.push(nv);
            }
        }
    }
    cout << "Yes" << endl;
    for (int i = 1; i < N; ++i) cout << prev[i] + 1 << endl;


    return 0;
}

Measured memory_bytes: 10652
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();
		//int k = sc.nextInt();

		long count=0;

		if(n==m) {
			System.out.println(n*2);
		}else {
			System.out.println(Math.max(n, m)+Math.max(n, m)-1);
		}
	}
}




Measured memory_bytes: 22740
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<string>
#include<cmath>
#include<cstring>
#include<ctime>
#include<cstdlib>
using namespace std;
typedef long long ll;
#define N 10006

int f[N];

int main(){
    ios::sync_with_stdio(false);
    int n,i,j,k;
    cin>>n;
    for(i=1;i<=100;i++){
        for(j=1;j<=100;j++){
            if(i*i+j*j+1+i*j+i+j>10000)
                break;
            for(k=1;k<=100;k++){
                if(i*i+j*j+k*k+i*j+i*k+j*k>10000)
                    break;
                f[i*i+j*j+k*k+i*j+i*k+j*k]++;
            }
        }
    }
    for(i=1;i<=n;i++){
        cout<<f[i]<<endl;
    }
    return 0;
}


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

typedef long long ll;

ll mod=1e9+7;

ll modfac(ll n){
  ll ans=1;
  for(int i=1;i<=n;i++){
    ans=(ans*i)%mod;
  }
  return ans;
}

int main(){
  ll a,b;
  cin >> a >> b;
  if(abs(a-b)>1){
    cout << 0 << endl;
  }
  else if(a==b){
    cout << (2*modfac(a)*modfac(b))%mod << endl;
  }
  else{
    cout << (modfac(a)*modfac(b))%mod << endl;
  }
}

Measured memory_bytes: 256
import random
def dice_move(a,s):
    if s=="E":
        return [a[3],a[1],a[0],a[5],a[4],a[2]]
    elif s=="S":
        return [a[4],a[0],a[2],a[3],a[5],a[1]]
    elif s=="W":
        return [a[2],a[1],a[5],a[0],a[4],a[3]]
    elif s=="N":
        return [a[1],a[5],a[2],a[3],a[0],a[4]]
    
n=int(input())
a=[list(map(int,input().split())) for _ in range(n)]
h=("N","W","S","E")
judge=[True]*n
cnt=0
for i in range(30000):
    num=random.randrange(4)
    a[0]=dice_move(a[0],h[num])
    for i in range(1,n):
        if judge[i] and a[0]==a[i]:
            cnt+=1
            judge[i]=False
print("Yes" if cnt==0 else "No")


Measured memory_bytes: 8240
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<stack>
#include<queue>
#include<set>
#include<map>
#include<vector>
#include<list>
#include<cmath>
#include<algorithm>
#include<bitset>
#define lson node<<1,st,mid
#define rson node<<1|1,mid+1,ed
#define mem(a,x) memset(a,x,sizeof(a))
#define me(a) memset(a,0,sizeof(a))
#define IOS ios::sync_with_stdio(false)
#define lowbit(x) x&(-x)
#define up(i,x,y) for(long long i=x;i<y;i++)
#define down(i,x,y) for(long long i=x;i>=y;i--)
#define in freopen("in.txt","r",stdin)
#define out freopen("out.txt","w",stdout)   
typedef long long ll;
const ll mod = 998244353;
const ll INF = 0x3f3f3f3f;
const ll maxn = 1e6 + 5;
const double pi = acos(-1.0);
const double eps=1e-9;
using namespace std;
ll qpow(ll a, ll b) { ll s = 1; while (b > 0) { if (b & 1)s = s * a % mod; a = a * a % mod; b >>= 1; }return s; }

ll n;
ll b[maxn];
char a[maxn];
void dg(ll j){
	ll i;
	if(j==n){
		for(i=0;i<n;i++)
			cout<<a[i];
		cout<<endl;
		return;
	}
	for(i=0;i<=j;i++){
		a[j]='a'+i;
		if(j!=0)
			if(a[j]-'a'-b[j-1]>1)
				continue;
		if(j!=0)
			b[j]=b[j-1];
		if(b[j]<i)
			b[j]=i;
		
		dg(j+1);
	}
}
int main(){
	cin>>n;
	for(ll i=0;i<n;i++){
		a[i]='a';
		b[i]=0;
	}
	dg(0);
}

Measured memory_bytes: 1536
#include<algorithm>
#include<bitset>
#include<cmath>
#include<complex>
#include<cstdlib>
#include<iomanip>
#include<iostream>
#include<map>
#include<queue>
#include<set>
#include<string>
#include<utility>
#include<vector>

using namespace std;

#define ll long long
#define pal pair<ll,ll>
#define pad pair<double,double>
#define PB push_back
#define MP make_pair
#define F first
#define S second

const ll MOD = 1e9+7;
const ll INF = 1e18;
const double EPS = 1e-8;

long long MODPOW(long long x, long long n) {
    long long ret = 1;
    while (n > 0) {
        if (n & 1) ret = ret * x % MOD;
        x = x * x % MOD;
        n >>= 1;
    }
    return ret;
}

template<typename T,typename U>
bool chmax(T& max, const U& x){
	if(max<x){
		max = x;
		return true;
	}
	return false;
}

template<typename T,typename U>
bool chmin(T& min, const U& x){
	if(min>x){
		min = x;
		return true;
	}
	return false;
}


int main(){
	ll f[6][6];
    fill(f[0],f[0]+36,0);
    ll h,w,k;
    cin >> h >> w >> k;
    for(ll i=0;i<h;i++){
        string tmp;
        cin >> tmp;
        for(ll j=0;j<w;j++){
            if(tmp[j]=='#'){
                f[i][j]=1;
            }
        }
    }

    ll ans=0;
    //bit全探索
for (int bit = 0; bit < (1 << h); ++bit) { 
        for(int bit2=0;bit2 < (1<<w); ++bit2){
            ll tmp =0;
            for (int i = 0; i < h; i++) {
                for( int j=0;j<w;j++){
                    if (bit & (1 << i) && bit2 & (1 << j)){
                        if(f[i][j]==1) tmp++;
	    	        }
                }
        	    
            }

        if(tmp==k) ans++;
    }
	
}
cout << ans << endl;
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
set<int> l;
int main()
{
    ll a,b,c;
    cin >> a >> b >> c;
    for(int i = 1; ; i++){
        if(l.count(a * i % b))
        {
            cout << "NO" << endl;
            return 0;
        }
        else if(a * i % b == c){
            cout <<"YES" << endl;
            return 0;
        }
        l.insert(a * i % b);
    }
}

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

int main()
{
    int N, l, r, a;
    int ans = 0;
    cin >> N;

    for (int i = 0; i < N; i++)
    {
        cin >> l >> r;
        a = l - r;
        if(a == 0 || a > 0)
        {
            a++;
        }
        else
        {
            a = a * -1 + 1;
        }
        ans += a;
    }
    cout << ans << endl;
}

Measured memory_bytes: 3644
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mp make_pair
#define pb push_back
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)

//0-indexed                                                                         
struct UnionFind {
  vector<int> data;
  UnionFind(int size) : data(size, -1) { }
  //木の根なら-(size of tree) それ以外は木の根のindexが入っている。                 
  bool unite(int x, int y) {
    x = root(x); y = root(y);
    if (x != y) {
      if (data[y] < data[x]) swap(x, y);
      data[x] += data[y]; data[y] = x;
    }
    return x != y;
  }
  bool same(int x, int y) {
    return root(x) == root(y);
  }
  int root(int x) {
    return data[x] < 0 ? x : data[x] = root(data[x]);
  }
  int size(int x) {
    return -data[root(x)];
  }
};

bool in_room(int y, int x, int h, int w){
  if(y>=0 && x>=0 && y<h && x<w) return true;
  else return false;

}

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

  int h,w;
  cin >> h >> w;
  string s[h];
  rep(i,h) cin >> s[i];
  UnionFind uf(h*w);

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

  rep(xi,w){
    rep(yi,h){
      rep(k,4){
	if(in_room(yi+dy[k],xi+dx[k],h,w)){
	  if(s[yi][xi]!=s[yi+dy[k]][xi+dx[k]]) uf.unite(w*yi+xi, w*(yi+dy[k])+xi+dx[k]);
	}
      }
    }
  }

  ll bw[h*w][2];
  rep(i,h*w) rep(j,2) bw[i][j]=0;
  rep(xi,w) rep(yi,h){
    if(s[yi][xi]=='#'){
      bw[uf.root(w*yi+xi)][1]++;
    }
    else{
      bw[uf.root(w*yi+xi)][0]++;
    }
  }
  ll ans=0;
  rep(xi,w) rep(yi,h){
    ans+=bw[w*yi+xi][0]*bw[w*yi+xi][1];
    //    cout << ans << endl;
  }
  cout << ans << endl;

  
  return 0;
    

}


Measured memory_bytes: 3584
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
typedef long long ll;
#define ALL(v) v.begin(), v.end()
#define vmax(v) *max_element(ALL(v))
#define vmin(v) *min_element(ALL(v))
#define chmax(x, a) x = max(x, a)
#define chmin(x, a) x = min(x, a)
#define MOD 998244353

const int MAX = 510000;

long long fac[MAX], finv[MAX], inv[MAX];


void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}


long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}



int main() {
    COMinit();
    ll N, M, K;
    cin >> N >> M >> K;
    ll ans = 0;
    ll tmp = M*modpow(M-1, N-K-1, MOD) % MOD;
    for (ll i = K; i >= 0; i--) {
        ans += tmp * COM(N-1, i) % MOD;
        ans %= MOD;
        tmp = (tmp*(M-1))%MOD;
    }
    cout << ans << endl;
}


Measured memory_bytes: 15592
#include<iostream>
#include<cstdio>
#define N 1000010
using namespace std;
int n,k,a[N];
char c[N];
int main()
{
	scanf("%d%d%s",&n,&k,c+1);
	for(int i=1;i<=n;i++) a[i]=c[i]=='A';
	int l=1,r=n,op=0;
	for(int i=1;i<=k;i++)
	{
		if(a[l]!=op) a[l]=op;
		else
		{
			l++;
			r++;
			op^=1;
			a[r]=op^1;
		}
		if(i>n*2&&i%2==k%2) break;
	}
	for(int i=l;i<=r;i++) putchar(a[i]^op?'A':'B');
}

Measured memory_bytes: 3712
#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

const int N=3700000;
const int INF=123456789;

int f[11];
int dp1[N], dp2[N];

inline int get_idx(const vector<int> &a)
{
    int n = a.size();
    int ret=0;

    vector<bool> use(n,false);
    rep(i,n)
    {
        int ct=0;
        rep(j,a[i])if(!use[j]) ++ct;

        ret += ct*f[n-1-i];

        use[a[i]]=true;
    }
    return ret;
}

inline vector<int> get_vec(int n, int idx)
{
    vector<int> ret(n);
    vector<bool> use(n,false);
    rep(i,n)
    {
        int s = idx/f[n-1-i];
        int j=0,ct=0;
        while(1)
        {
            if(!use[j])
            {
                ++ct;
                if(ct==s+1) break;
            }
            ++j;
        }

        use[j]=true;
        ret[i]=j;
        idx -= s*f[n-1-i];
    }
    return ret;
}

int main()
{
    f[0]=1;
    for(int i=1; i<=10; ++i) f[i] = f[i-1]*i;

    int n;
    cin >>n;
    vector<int> a(n);
    rep(i,n)
    {
        cin >>a[i];
        --a[i];
    }

    int g = get_idx(a);
    queue<int> que;

    fill(dp1,dp1+N,INF);
    dp1[0]=0;
    que.push(0);
    while(!que.empty())
    {
        int now = que.front();
        que.pop();

        vector<int> x = get_vec(n,now);
        // printf(" now %d\n", now);
        rep(i,n)for(int j=i+1; j<=n; ++j)
        {
            reverse(x.begin()+i, x.begin()+j);

            int nx = get_idx(x);
            // printf("  nx %d\n", nx);
            if(dp1[nx]>dp1[now]+1)
            {
                dp1[nx] = dp1[now]+1;
                if(dp1[nx]<4) que.push(nx);
            }

            reverse(x.begin()+i, x.begin()+j);
        }
    }

    fill(dp2,dp2+N,INF);
    dp2[g]=0;
    que.push(g);
    while(!que.empty())
    {
        int now = que.front();
        que.pop();

        vector<int> x = get_vec(n,now);
        rep(i,n)for(int j=i+1; j<=n; ++j)
        {
            reverse(x.begin()+i, x.begin()+j);

            int nx = get_idx(x);
            if(dp2[nx]>dp2[now]+1)
            {
                dp2[nx] = dp2[now]+1;
                if(dp2[nx]<4) que.push(nx);
            }

            reverse(x.begin()+i, x.begin()+j);
        }
    }

    int ans=9;
    rep(i,N)if(dp1[i]<INF && dp2[i]<INF) ans=min(ans,dp1[i]+dp2[i]);

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

Measured memory_bytes: 32288
#include <algorithm>
#include <cassert>
#include <cmath>
#include <climits>
#include <cstdlib>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define DEBUG 1
using namespace std;
constexpr int kMod = 1000000007;
typedef long long LL;


typedef pair<LL, int> P;  // cost, vertex_idx
struct Edge {
  int to;
  LL cost;
  Edge(LL a, int b) : to(a), cost(b) {}
};

vector<LL> dijkstra(int s, const vector<vector<Edge>>& G) {
  priority_queue<P, vector<P>, greater<P>> que;

  vector<LL> d(G.size(), LLONG_MAX);
  d[s] = 0;
  que.push(P(0, s));

  while (!que.empty()) {
    auto p = que.top(); que.pop();
    LL dist = p.first;
    int v = p.second;

    if (d[v] < dist) continue;
    for (const auto& e : G[v]) {
      if (d[e.to] > d[v] + e.cost) {
        d[e.to] = d[v] + e.cost;
        que.push(P(d[e.to], e.to));
      }
    }
  }

  return d;
}

int main() {
  int N, X, Y; cin >> N >> X >> Y;
  --X; --Y;
  vector<vector<Edge>> G(N);
  for (int i = 0; i < N - 1; ++i) {
    G[i].push_back(Edge(i+1, 1));
    G[i+1].push_back(Edge(i, 1));
  }
  G[X].push_back(Edge(Y, 1));
  G[Y].push_back(Edge(X, 1));

  map<LL, LL> m;
  for (int i = 0; i < N; ++i) {
    auto d = dijkstra(i, G);
    for (int i = 0; i < N; ++i) m[d[i]]++;
  }
  for (int i = 1; i < N; ++i) {
    cout << m[i]/2 << endl;
  }
}


Measured memory_bytes: 512
#include<stdio.h>
 
int main(){
    int a;
    while(~scanf("%d",&a)){
        int ans=0;
        for(int i=0;i<10;i++)
            for(int j=0;j<10;j++)
                for(int k=0;k<10;k++)
                    for(int l=0;l<10;l++)
                        if(i+j+k+l==a)ans++;
        printf("%d\n",ans);
    }
}


Measured memory_bytes: 2656
#include <bits/stdc++.h>
#define int long long
#define rep(i, a, n) for(int i = (int)(a);(i) < (int)(n);++(i))
#define repe(i, a, n) for(int i = (int)(a);(i) <= (int)(n);++(i))
#define repif(i, a, x) for(int i = (int)(a);(x);++(i))
#define repr(i, a, n) for(int i = ((int)(a)-1);(i) >= (int)(n);--(i))
#define reper(i, a, n) for(int i = (int)(a);(i) >= (int)(n);--(i))
#define SZ(x) ((int)(x).size())
#define ALL(x) begin(x), end(x)
#define RNG(x, a, n) &((x)[a]), &((x)[n])
#define ADD(a, b) (((a%MOD+MOD)%MOD+(b%MOD+MOD)%MOD)%MOD)
#define SUB(a, b) (((a%MOD+MOD)%MOD-(b%MOD+MOD)%MOD+MOD)%MOD)
#define MUL(a, b) ((((a%MOD+MOD)%MOD)*((b%MOD+MOD)%MOD))%MOD)
#define CHADD(a, b) (a = ADD(a, b))
#define CHMUL(a, b) (a = MUL(a, b))
#define CEIL(x) ((int)ceil(((double)x)))
#define POW(x, y) ((int)pow(x, y))
#define UNIQUE(x) (x).erase(unique(ALL((x))), (x).end())
#define gcd(x, y) __gcd(x, y)
#define lcm(x, y) (x/gcd(x,y)*y)
#define YES cout << "YES" << endl
#define NO cout << "NO" << endl
#define Yes cout << "Yes" << endl
#define No cout << "No" << endl
#define yes cout << "yes" << endl
#define no cout << "no" << endl
#define fcout cout << fixed << setprecision(10)
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define PI (acos(-1))
#define EPS (1e-10)
#define INF LLONG_MAX
#define MOD 1000000007LL
using namespace std;
using VI = vector<int>;
using PII = pair<int, int>;
using VPII = vector<PII>;
using Complex = complex<double>;
template<typename T, template<typename> typename C = less> using PQ = priority_queue<T, vector<T>, C<T>>;
template<typename T> bool chmax(T& a, const T& b){ if(a<b){ a=b; return true; } return false; }
template<typename T> bool chmin(T& a, const T& b){ if(a>b){ a=b; return true; } return false; }
template<typename I> int ACC(I f, I l, int i){ return accumulate(f, l, i); }


int N, M;
int S[2010], T[2010];
int dp[2010][2010];


signed main(){
    cin >> N >> M;
	rep(i, 0, N) cin >> S[i];
    rep(i, 0, M) cin >> T[i];

    repe(i, 0, N) dp[i][0] = 1;
    repe(i, 0, M) dp[0][i] = 1;
    repe(i, 1, N) repe(j, 1, M){
		CHADD(dp[i][j], ADD(dp[i-1][j], SUB(dp[i][j-1], dp[i-1][j-1])));
        if(S[i-1] == T[j-1]) CHADD(dp[i][j], dp[i-1][j-1]);
    }

	cout << dp[N][M] << endl;

    return 0;
}

Measured memory_bytes: 31744
//https://atcoder.jp/contests/abc155/tasks/abc155_c

#include <iostream>
#include <vector>
#include <string>
#include <array>
#include <map>
#include <algorithm>

using namespace std;

int main ()
{
    
    int N;
    cin >> N;
    vector <string> S(N);
    vector <string> ans;
    map<string, int> mapAns;
    int max = 0;
    
    for (int i = 0; i < N; ++i)
    {
        cin >> S.at(i);
    }

    for (int i = 0; i < N; ++i)
    {
        mapAns[S.at(i)]++;

        if (mapAns[S.at(i)] >= max)
        {
            max = mapAns[S.at(i)];
        }
    }

    for (auto const& mp : mapAns)
    {
        if (mp.second == max)
        {
            ans.push_back(mp.first);
        }
    }

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

    for (string outS : ans)
    {
        cout << outS << endl;
    }
    


    return 0;
}

Measured memory_bytes: 28404
#include<bits/stdc++.h>
using namespace std;
#define Sheryang main
#define TYPE int
const int maxn=1e6+7;
typedef long long ll;
const int mod=1e9+7;
void Smax(TYPE &a,TYPE b){if(a<b) a=b;}
void Smin(TYPE &a,TYPE b){if(a>b) a=b;}
///#define getchar()(p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1 << 21, stdin), p1 == p2) ? EOF : *p1++)
///char buf[(1 << 21) + 1], *p1 = buf, *p2 = buf;
#define IO cin.tie(0),ios::sync_with_stdio(false);
#define pi acos(-1)
#define PII pair<ll,ll>
ll read(){ll c = getchar(),Nig = 1,x = 0;while(!isdigit(c) && c!='-')c = getchar();if(c == '-')Nig = -1,c = getchar();while(isdigit(c))x = ((x<<1) + (x<<3)) + (c^'0'),c = getchar();return Nig*x;}
#define read read()
/** keep hungry and keep calm! **/

int Sheryang(){
	
	int a=read,b=read,c=read;
	
	if(a==b && b==c){
		printf("Yes\n");
	}else{
		printf("No\n");
	}
    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
    int N, M, sum = 0;
    cin >> N;
    vector<int> T(N);
    for (int i = 0; i < N; i++){
        cin >> T.at(i);
        sum += T.at(i);
    }
    cin >> M;
    vector<int> P(M), X(M);
    for (int i = 0; i < M; i++){
        cin >> P.at(i) >> X.at(i);
    }
    for (int i = 0; i < M; i++){
        cout << sum - T.at(P.at(i) - 1) + X.at(i) << endl;
    }
}

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

const char wall = '#';
vector<vector<char>> fields;
vector<vector<bool>> used;
vector<vector<ll>> dist;
const int dx[4] = {0, -1, 0, 1};
const int dy[4] = {1, 0, -1, 0};

vector<ll> A;
// vectorのリサイズ
// A.resize(N);

ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a*b/gcd(a, b);}

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

  ll a, b;
  cin >> a >> b;
  int ans = 0;
  if (b == 1) {
    cout << 0 << endl;
    return 0;
  }
  while (b > 0) {
    if (ans == 0) b -= a;
    else b -= a-1;
    ++ans;
  }
  cout << ans << endl;
  return 0;
}


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

lint n, k;
vector<lint> a;

int main() {
    cin >> n >> k;
    a.resize(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    while (k--) {
        vector<lint> imos(n + 1);
        for (int i = 0; i < n; i++) {
            lint left = max(0LL, i - a[i]);
            lint right = min(n, i + a[i] + 1);
            imos[left]++;
            imos[right]--;
        }
        lint now = 0;
        bool finish = true;
        for (int i = 0; i < n; i++) {
            now += imos[i];
            a[i] = now;
            if (a[i] != n) {
                finish = false;
            }
        }
        if (finish) {
            break;
        }
    }
    for (auto e : a) {
        cout << e << ' ';
    }
    cout << endl;
}

Measured memory_bytes: 6400
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<cstdio>
#include<cmath>
#include<deque>
#include<numeric>
#include<queue>
#include<stack>
#include<cstring>
#include<limits>
#include<functional>
#include<unordered_set>
#include<iomanip>
#include<cassert>
#include<regex>
#include<bitset>
#include<complex>
#include<chrono>
#define rep(i,a) for(int i=(int)0;i<(int)a;++i)
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(),x.end()
using ll=long long;
constexpr ll mod = 1e9 + 7;
constexpr ll INF = 1LL << 60;

ll gcd(ll n, ll m) {
	ll tmp;
	while (m!=0) {
		tmp = n % m;
		n = m;
		m = tmp;
	}
	return n;
}

ll lcm(ll n, ll m) {
	return abs(n * m) / gcd(n, m);//gl=xy
}
 
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;
}
 
using namespace std;

//ここから
template< typename T >
vector< T > convert_base(T x, T b) {
  vector< T > ret;
  T t = 1, k = abs(b);
  while(x) {
    ret.emplace_back((x * t) % k);
    if(ret.back() < 0) ret.back() += k;
    x -= ret.back() * t;
    x /= k;
    t *= b / k;
  }
  if(ret.empty()) ret.emplace_back(0);
  reverse(begin(ret), end(ret));
  return ret;
}

void solve(){
  ll n,k;
  cin>>n>>k;
  vector<ll>v=convert_base(n,k);
  cout<<v.size();
}

int main(){
	ios::sync_with_stdio(false);
  cin.tie(0);
	cout<<fixed<<setprecision(15);
  solve();
	return 0;
}

Measured memory_bytes: 256
#include"iostream"
#include<stdlib.h>
#include<stdio.h>
#include<time.h>
#include<list>
#include<map>
#include<algorithm>
#include<string>
#include <queue> 
#include <sstream>
#include <fstream>
#include<cmath>
#include"bits/stdc++.h"
#define LL long long
using namespace std;
#define INF 1000000000





LL A,B,C,D,E,F,N,M,xx[100000],W,ans;

vector<LL>x,y;

string s;
int main() {
  
	cin>>N>>M;
	LL k[11],s[11][11];
	for(int i=0;i<M;i++){
		cin>>k[i];
		for(int j=0;j<k[i];j++){
			cin>>s[i][j];
			s[i][j]--;
		}
	}
	LL p[11];
	for(int i=0;i<M;i++)cin>>p[i];
		bool a;
	for(int bit=0;bit<(1<<N);bit++){
		a=true;
		for(int i=0;i<M;i++){
			LL b=0;
			for(int j=0;j<k[i];j++){
				if(bit&(1<<s[i][j]))b++;
			}
			if(b%2!=p[i])a=false;
		}
		if(a)ans++;
	}

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

Measured memory_bytes: 256
import std.algorithm, std.container, std.conv, std.math, std.range, std.typecons, std.stdio, std.string;

auto rdsp(){return readln.splitter;}
void pick(R,T)(ref R r,ref T t){t=r.front.to!T;r.popFront;}
void readV(T...)(ref T t){auto r=rdsp;foreach(ref v;t)pick(r,v);}

void main()
{
  int a; readV(a);
  int b; readV(b);
  int h; readV(h);
  writeln((a+b)*h/2);
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0; i<(int)n; i++)
#define rep1(i,n) for(int i=1; i<(int)n; i++)
#define repa(i,a,n) for(int i=(a); i<(int)(n); i++)
#define all(vec) vec.begin(),vec.end()
#define COUT(x) cout<<(x)<<endl
#define YES(x) cout<<(x?"YES":"NO")<<endl
#define Yes(x) cout<<(x?"Yes":"No")<<endl
using vi = vector<int>;
using vs = vector<string>;
using vvi = vector<vi>;
using pii = pair<int, int>;
using psi = pair<string, int>;
const int dx[4] = {1, 0,-1, 0};
const int dy[4] = {0, 1, 0,-1};
const int mod = 1e9+7;
int gcd(int a, int b){if(a%b == 0){return(b);}else{return(gcd(b, a%b));}}
int lcm(int a, int b){return a / gcd(a, b)*b;}
//cout << fixed << setprecision(15);
int N, M, K, H, W, L, R, X, Y;
string S, T;

signed main(){
  cin >> N;
  vi A(N);
  int ans = 0;
  rep(i,N){
    int a; cin >> a;
    ans += a-1;
  }
  COUT(ans);
  return 0;
}

Measured memory_bytes: 3640
from collections import Counter

n = int(input())
s = input()
cnt = Counter(s)
ans = cnt['R'] * cnt['G'] * cnt['B']

for i in range(n):
    l = 1
    si = s[i]
    while i + l * 2 < n:
        if si != s[i + l] and si != s[i + l * 2] and s[i + l] != s[i + l * 2]:
            ans -= 1
        l += 1
print(ans)


Measured memory_bytes: 9464
#include <iostream>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <algorithm>
#include <tuple>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#define REP(i, n) for(LL i = 0;i < n;i++)
#define REPR(i, n) for(LL i = n;i >= 0;i--)
#define FOR(i, m, n) for(LL i = m;i < n;i++)
#define FORR(i, m, n) for(LL i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define pb(a) push_back(a)
#define all(x) (x).begin(),(x).end()
#define INF 999999999
#define MOD 1000000007
using namespace std;
typedef long long LL;
typedef pair<int, int> P;
typedef pair<LL, LL> LP;
typedef pair<int, P> PP;
typedef pair<LL, LP> LPP;
int dy[]={0, 0, 1, -1, 0};
int dx[]={1, -1, 0, 0, 0};

/*************** using variables ***************/
int n, m;
double ans = 0;
int cnt = 1;
double kakuritu;
/**********************************************/

int main(){
    cin >> n >> m;
    kakuritu = 1 / pow(2, m);
    while(1){
        int sum = 1900 * m + (n-m) * 100;
        double part = (sum * cnt) * kakuritu * pow(1 - kakuritu, cnt-1);
        if(part <= 0) break;
        ans += part;
        cnt++;
    }

    cout << int(ans + 0.5) << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<stack>

using namespace std;

bool check(const string & str)
{
	stack<int> stk;

	for (const auto & c : str)
	{
		if (c == '(')
		{
			stk.push(0);
		}
		else if (c == ')')
		{
			if (stk.empty())return false;
			int s = stk.top(); stk.pop();
			if (s != 0)return false;
		}
		else if (c == '[')
		{
			stk.push(1);
		}
		else if (c == ']')
		{
			if (stk.empty())return false;
			int s = stk.top(); stk.pop();
			if (s != 1)return false;
		}
	}

	if (stk.empty())return true;

	return false;
}

int main()
{
	while (true)
	{
		string str;
		getline(cin, str);
		
		if (str == ".")return 0;

		if (check(str))
		{
			cout << "yes" << endl;
		}
		else
		{
			cout << "no" << endl;
		}
	}
}


Measured memory_bytes: 3228
#include<iostream>
#include<cstdio>
using namespace std;
#define MAX 150000
int binarySearch(int *A,int n,int key){
    int right = n;
    int left = 0;
    int mid = 0;
    while(left < right){
        mid = (right + left) /2;
        if(A[mid] == key) return 1;
        else if(A[mid] < key){
          left = mid+1 ;
        }else if (A[mid] > key)
        {
            right = mid;
        }
    }
    return 0;
}
int main(){
    int A[MAX];
    int n,m;
    int key;
    int sum = 0;
    cin >> n;
    for(int i=0;i<n;i++){
        cin >> A[i];
    }
    cin >> m;
    for(int i=0;i<m;i++){
        cin >> key;
        sum += binarySearch(A,n,key);
    }
    cout << sum << endl;
    return 0;
}


Measured memory_bytes: 3440
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <limits.h>
#include <math.h>

long long g(long long x)
{
    long long a;
    long long y;

    // f(0, x & ~0x03LL) = x & ~0x03LL
    y = x & ~0x03LL;

    for (a = y + 1; a <= x; a++) {
        y ^= a;
    }

    return y;
}

int main(int argc, char *argv[])
{
    long long a, b;
    long long ans;

    scanf("%lld %lld", &a, &b);

    // f(a, b) = f(0, a - 1) ^ f(0, b) となる
    ans = g(a - 1) ^ g(b);

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

    return 0;
}


Measured memory_bytes: 128
#include<iostream>
using namespace std;
int main() {
	long long a, b, k;
	cin>>a>>b>>k;
	if(a>=k){
	    cout<<a-k<<" "<<b<<endl;
	}else{
	    k-=a;
	    cout<<0<<" "<<b-min(b, k)<<endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
#define popCnt(x) (__builtin_popcountll(x))
typedef unsigned long long Long;

int n;

int getLSB(int x) {
  return x & ~(x - 1);
}

vector<int> solve(int a, int b, int unused_mask) {
  if (popCnt(unused_mask) == 1) {
    return {a , b};
  }

  int diff = -1;
  for (int i = 0; i < n; ++i) {
    if ((~unused_mask >> i) & 1) continue;
    if (((a ^ b) >> i) & 1) {
      diff = i;
      break;
    }
  }

  vector<int> res;

  unused_mask ^= (1 << diff);

  int c = a ^ getLSB(unused_mask);

  res = solve(a, c, unused_mask);

  auto tmp = solve(c ^ (1 << diff), b, unused_mask);
  res.insert(res.end(), tmp.begin(), tmp.end());

  return res;
}

int main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#ifdef Local
  freopen("test.in", "r", stdin);
#else
#define endl '\n'
#endif

  int a, b;
  cin >> n >> a >> b;

  if (popCnt(a ^ b) % 2 == 0) {
    cout << "NO" << endl;
    return 0;
  }

  auto res = solve(a, b, (1 << n) - 1);

  cout << "YES" << endl;
  for (int x : res) {
    cout << x << " ";
  }

}



Measured memory_bytes: 1648
#include <bits/stdc++.h>
#include <string>
using namespace std;
 
int main() {
  string S,T;
  cin >> S >> T;
  int check = 0;
  for(int i=0;i<S.size();i++){
		if(S.at(i)!=T.at(i)){
          check++;
        }
    }

  if(check>0){
    cout << "No" <<endl;
  }else{
    cout << "Yes" << endl;
  }
}

Measured memory_bytes: 3592
#include<bits/stdc++.h>
 
using namespace std;
 
#define LL long long int
#define FASTIO ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
const int N = 1e5 + 5;
const int M = 21;
const int oo = 1e9 + 5;
const LL ooll = (LL)1e18 + 5;
const int MOD = 1e9 + 7;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define rand(l, r) uniform_int_distribution<int>(l, r)(rng)

clock_t start = clock();

void solve() {
    string s, t;
    cin >> s >> t;
    int n = s.size(), m = t.size(), ans = m;
    for (int i=0;i+m-1<n;++i) {
        int cur = 0;
        for (int j=0;j<m;++j) cur += (t[j] != s[i+j]);
        ans = min(ans, cur);
    }
    cout << ans << '\n';
}

int main() {
    FASTIO;
    int T = 1;
    // cin >> T;
    for (int t=1;t<=T;++t) {
        solve();
    }
    // cerr << fixed << setprecision(10);
    // cerr << (clock() - start) / ((long double)CLOCKS_PER_SEC) << '\n';
    return 0;
} 

Measured memory_bytes: 3668
#!/usr/bin/env python3
#
# Author: Tetsuya Ishikawa <tiskw111@gmail.com>
# Date  : July 05, 2020
##################################################### SOURCE START #####################################################

import itertools

import numpy as np

H, W, K = tuple(map(int, input().strip().split()))

C = np.zeros((H, W))

for h in range(H):
    cs = input().strip()
    for w in range(W):
        C[h, w] = 1 if cs[w] == "#" else 0

count = 0

for max_h in range(H + 1):
    for max_w in range(W + 1):
        for hs in itertools.combinations(range(H), max_h):
            for ws in itertools.combinations(range(W), max_w):

                tmp = np.array(C)

                for h in hs:
                    for w in range(W): tmp[h, w] = 0

                for w in ws:
                    for h in range(H): tmp[h, w] = 0

                if int(np.sum(tmp)) == K:
                    count += 1

print(count)

##################################################### SOURCE FINISH ####################################################
# vim: expandtab tabstop=4 shiftwidth=4 fdm=marker


Measured memory_bytes: 27184
#include <iostream>
#include <vector>
#include <set>
#define tenmillion 1000000
using namespace std;

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

    set<int> st;
    st.insert(s);
    for (int i = 0 ; i < tenmillion; i++){
        if(s % 2 == 0) s /= 2;
        else s = 3 * s + 1;

        if (st.count(s)){
            cout << i + 2 << endl;
            return 0;
        }
        else{
            st.insert(s);
        }
    }
}

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

using namespace std;

string divide[4] = {"dream", "dreamer", "erase", "eraser"};

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

    reverse(s.begin(), s.end());

    for (int i = 0; i < 4; i++) {
        reverse(divide[i].begin(), divide[i].end());
    }
    
    bool can = true;
    for (int i = 0; i < s.size();) {
        bool flag = false;
        for (int j = 0; j < 4; j++) {
            string d = divide[j];
            if (s.substr(i, d.size()) == d) {
                flag = true;
                i += d.size();
            }
        }

        if (flag != true) {
            can = false;
            break;
        }
    }

    if (can) {
        cout << "YES" << endl;
    } else {
        cout << "NO" << endl;
    }
    
    return 0;
}

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

using namespace std;

int main()
{
    int k;
    cin>>k;
    string s;
    cin>>s;
    if(k >= s.size())
    {
        cout<<s<<endl;
    }
    else
    {
        for(int i = 0;i<k;i++)
            cout<<s[i];
        cout<<"..."<<endl;
    }
}

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

using namespace std;

int main(){
    int h,n,maxdamege = 0;
    cin >> h >> n;
    for(int i = 0;i < n;i++){
        int x;cin >> x;
        maxdamege += x;
    }
    if(maxdamege >= h)cout << "Yes";
    else cout << "No";
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <vector>
using namespace std;
  
#define MAX_N 101
#define MAX_M 101
#define INF (1<<29)
  
int M, N;
int X1[MAX_M], Y1[MAX_M];
int X2[MAX_N], Z2[MAX_N];
  
double width(int* X, int* Y, int n, double x){
  double lb = INF, ub = -INF;
  for(int i = 0 ; i < n ; i++){
    double x1 = X[i], y1 = Y[i], x2 = X[(i+1)%n], y2 = Y[(i+1)%n];
    if((x1 - x) * (x2 - x) <= 0 && x1 != x2){
      double y = y1 + (y2-y1) * (x-x1) / (x2-x1);
      lb = min(lb, y);
      ub = max(ub, y);
    }
  }
  return max(0.0, ub - lb);
}
  
void solve(){
  int min1 = *min_element(X1, X1+M), max1 = *max_element(X1, X1+M);
  int min2 = *min_element(X2, X2+N), max2 = *max_element(X2, X2+N);
  vector<int> xs;
  for(int i = 0 ; i < M ; i++) xs.push_back(X1[i]);
  for(int i = 0 ; i < N ; i++) xs.push_back(X2[i]);
  sort(xs.begin(), xs.end());
    
  double res = 0;
    
  for(int i = 0 ; i+1 < xs.size() ; i++){
    double a = xs[i], b = xs[i+1], c = (a+b)/2;
    if(min1 <= c && c <= max1 && min2 <= c && c <= max2){
      double fa = width(X1, Y1, M, a) * width(X2, Z2, N, a);
      double fb = width(X1, Y1, M, b) * width(X2, Z2, N, b);
      double fc = width(X1, Y1, M, c) * width(X2, Z2, N, c);
      res += (b-a)/6*(fa+4*fc+fb);
    }
  }
  printf("%.10f\n", res);
}
  
int main(void){
  
  while(cin >> M >> N,N|M){
    for(int i=0;i<M;i++){
      cin >> X1[i] >> Y1[i];
    }
    for(int i=0;i<N;i++){
      cin >> X2[i] >> Z2[i];
    }
    solve();
  }
  
  return 0;
}

Measured memory_bytes: 1248
//#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#define black_tree tree<ll,null_type,less_equal<ll>,rb_tree_tag,tree_order_statistics_node_update>
#define pair_black_tree tree<pair<ll,ll>,null_type,less<pair<ll,ll> >,rb_tree_tag,tree_order_statistics_node_update>
#define gp __gnu_pbds
#define INF 1000000000
#define MOD 1000000007
#define MAX 1000001
#define endl '\n'
#define ll long long
#define ld long double
#define lli long long int
#define ull unsigned long long
#define ulli unsigned long long int
#define pb push_back
#define pf push_front
#define ook order_of_key
#define fbo find_by_order
#define np next_permutation
#define mp make_pair
#define eb emplace_back
#define mae max_element
#define mie min_element
#define lb lower_bound 
#define ub upper_bound
#define bs binary_search
#define ff first
#define ss second
using namespace std;
using namespace gp;
ll n,x,y,f,ans;
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin>>n;
    for(int i=1;i<=n;i++){
    	cin>>x>>y;
    	if(x==y){
    		ans++;
		}
		else{
			if(ans>=3){
				f=1;
			}
			ans=0;
		}
	}
	if(f || ans>=3){
		cout<<"Yes";
	}
	else{
		cout<<"No";
	}
}

Measured memory_bytes: 3612
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int INF=pow(10,9);

int main(){
    int n;
    cin >> n;
    map<int, int> even;
    map<int, int> odd;
    for(int i=0; i<n; i++){
        int s;
        cin >> s;
        if(i%2 == 0) even[s]++;
        else odd[s]++;
    }
    int e_first,e_second,e_third,o_first,o_second,o_third;
    vector<pair<int,int>> even_v;
    vector<pair<int,int>> odd_v;
    for(auto p:even){
        auto k = p.first;
        auto v = p.second;
        pair<int,int> q = make_pair(v,k);
        even_v.push_back(q);
    }
    for(auto p:odd){
        auto k = p.first;
        auto v = p.second;
        pair<int,int> q = make_pair(v,k);
        odd_v.push_back(q);
    }
    sort(even_v.begin(), even_v.end());
    reverse(even_v.begin(), even_v.end());
    sort(odd_v.begin(), odd_v.end());
    reverse(odd_v.begin(), odd_v.end());

    if(even_v.at(0).second != odd_v.at(0).second){
        cout << n-even_v.at(0).first-odd_v.at(0).first << endl;
    }
    else{
        cout << n-even_v.at(0).first-max(even_v[1].first,odd_v[1].first) << endl;
    }
}

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

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;

#define ll long long
#define db double
#define el "\n"
#define ld long double
#define rep(i,n) for(int i=0;i<n;i++)
#define rev(i,n) for(int i=n;i>=0;i--)
#define rep_a(i,a,n) for(int i=a;i<n;i++)
#define tr(ds, it) for(auto it=ds.begin(); it!=ds.end(); it++)
#define rtr(ds, it) for(auto it=ds.rbegin(); it!=ds.rend(); it--)
#define all(ds) ds.begin(), ds.end()
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
typedef priority_queue <int> pq;
typedef vector< long long > vi;
typedef pair<long long, long long> ii;
#define o_set tree<ii, null_type,less<ii>, rb_tree_tag,tree_order_statistics_node_update>
#define graph vector<vi>
#define Mod 1000000007
#define fastio ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

vector < vector < int > > Q;
ll ans;

void cal (int arr[], int q) {
	
	ll curr = 0;
	
	rep(i, q) {
		
		int x = Q[i][1] - 1;
		int y = Q[i][0] - 1;
		
		if (arr[x] - arr[y] == Q[i][2])
			curr += 1ll * Q[i][3];
	}
	
	ans = max(ans, curr);
}

void dfs (int arr[], int value, int index, int n, int m, int q) {
	
	if (index == n) {
		
		cal(arr, q);
		return;
	}
	
	if (value > m)
		return;
		
	arr[index] = value;
	dfs(arr, value, index + 1, n, m, q);
	dfs(arr, value + 1,index, n, m, q);
}

int main()
{
    fastio;
//	#ifndef ONLINE_JUDGE
//    freopen("input.txt", "r" , stdin);
//    freopen("output.txt", "w" , stdout);
//    #endif
    
	int n, m, q,a,b,c,d;
	cin >> n >> m >> q;
	ans = 0; 
	    
	rep(i, q) {
		cin >> a >> b >> c >> d;
		vector<int> temp{a, b, c, d};
		Q.pb(temp);
	}
	
	int arr[n];
	dfs(arr, 1, 0,  n, m, q);
	
	cout << ans;
	//code
	return 0;
}


Measured memory_bytes: 3668
#include <stdio.h>
#define INF 214748364

int prim();
int n,w[100][100];

int main(){
  int i,j,d;

  scanf("%d",&n);
  for(i=0;i<n;i++){
    for(j=0;j<n;j++){
      scanf("%d",&w[i][j]);
    }
  }
  d=prim();
  printf("%d\n",d);
  
  return 0;
}

int prim(){
  int dis=0,i,u,v,mincost,color[n],d[n],pi[n];

  for(u=0;u<n;u++){
    d[u]=INF;
    pi[u]=-1;
    color[u]=-1;
  }

  d[0]=0;

  while(1){
    mincost=INF;

    for(i=0;i<n;i++){
      if(color[i]!=1&&d[i]<mincost){
	mincost=d[i];
	u=i;
      }
    }

    if(mincost==INF) break;

    color[u]=1;

    for(v=0;v<n;v++){
      if(color[v]!=1&&w[u][v]<d[v]&&w[u][v]!=-1){
	pi[v]=u;
	d[v]=w[u][v];
      }
    }
  }
  for(i=0;i<n;i++){
    dis+=w[i][pi[i]];
  }
  return dis;
}

Measured memory_bytes: 636
#include<stdio.h>
int main()
{
	double t;
	int i,x,n,g[6]={0};
	scanf("%d",&n);
	for(i=n;i>0;i--)
	{
		scanf("%lf",&t);
		x=((int)t-165);
		if(x<0)g[0]++;
		else if(x>=20)g[5]++;
		else g[x/5+1]++;
	}
	for(i=0;i<6;puts(""),i++)
	{
		printf("%d:",i+1);
		for(;g[i]>0;putchar('*'),g[i]--);
	}
	return 0;
}

Measured memory_bytes: 648
while True:
  n, x = map(int, input().split())

  if n == 0 and x == 0:
    break

  ans = 0

  for i in range(1,n+1):
    for j in range(i+1,n+1):
      k = x-(i+j)
      if k >= 1 and k <= n and k > j:
        ans += 1

  print(ans)

Measured memory_bytes: 7572
#include <iostream>
#include <cstring>
#include <vector>
using namespace std;
#define rep(i, n) for( int i = 0; i < n; i++ )

int main(){
    int n;
    cin >> n;
    int data[4][3][10];
    memset(data, 0, sizeof(data));
    rep(i, n){
        int b, f, r, v;
        cin >> b >> f >> r >> v;
        data[b-1][f-1][r-1] += v;
    }
    rep(i, 4){
        if( i > 0 ) cout << "####################" << endl;
        rep(j, 3){
            rep(k, 10){
                cout << ' ';
                cout << data[i][j][k];
                if( k == 9 ) cout << endl;
            }
        }
    }
}

Measured memory_bytes: 1160
const main = (input) => {
  input = input.trim().split('\n')
  const [n, k] = input[0].split(' ').map(Number)
  const [, ...arr] = input

  const his = {}

  while (arr.length) {
    arr.shift()
    const t = arr.shift()
    t.split(' ').forEach(v => his[v] = 1)
  }

  let count = 0
  for (let i=1; i<=n; i++) if (~~his[i] === 0) count++

  return console.log(count)
}

process.env.MYTEST
  ? (process.env.MYTEST === 'test' ? test() : main(require('fs').readFileSync('dev/stdin', 'utf8')))
  : main(require('fs').readFileSync('/dev/stdin', 'utf8'))

Measured memory_bytes: 29640
/**
 *    author  : 𝒌𝒚𝒐𝒎𝒖𝒌𝒚𝒐𝒎𝒖𝒑𝒖𝒓𝒊𝒏
 *    created : 2020-03-13 02:32:36
**/

#include <iostream>
#include <deque>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <complex>
#include <numeric>
#include <bitset>
#include <cassert>
#include <cctype>
#include <iomanip>
#include <random>
#include <utility>
#include <chrono>

using namespace std;

using int64 = long long;

template<class T> using binary_heap = std::priority_queue<T, std::vector<T>, std::greater<T>>;
template<class T> std::ostream& operator<<(std::ostream& os, const std::vector<T>& vec) { os << '{'; size_t n = vec.size(); for (size_t i = 0; i < n; ++i) { os << vec[i]; if (i != n - 1) os << ','; } os << '}'; return os; }
template<class T, class U> std::ostream& operator<<(std::ostream& os, const std::pair<T, U>& p) { return os << '{' << p.first << " " << p.second << '}'; }
template<class T, class U> std::ostream& operator<<(std::ostream& os, const std::map<T, U>& mp) { os << '{'; for (auto it = mp.begin(); it != mp.end(); ++it) { os << '{' << it->first << ':' << it->second << '}'; if (it != --mp.end()) os << ','; } os << '}'; return os; }
template<class T> std::ostream& operator<<(std::ostream& os, const std::set<T>& st) { os << '{'; for (auto it = st.begin(); it != st.end(); ++it) { os << *it; if (it != --st.end()) os << ','; } os << '}'; return os; }
template<class T> std::istream& operator>>(std::istream& is, std::vector<T>& vec) { size_t n = vec.size(); for (size_t i = 0; i < n; ++i) is >> vec[i]; return is; }

#define all(_) begin(_), end(_)
#define rall(_) rbegin(_), rend(_)

#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]: ", debug_out(__VA_ARGS__)
#else
#define debug(...) 1728
#endif

void debug_out() { std::cerr << '\n'; }

template <class Head, class... Tail>
void debug_out(Head&& head, Tail&&... tail) {
  std::cerr << head;
  if (sizeof...(Tail) != 0) std::cerr << ", ";
  debug_out(std::forward<Tail>(tail)...);
}

using graph = std::vector<std::vector<int>>;

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

  int n, q; cin >> n >> q;
  graph g(n);

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

  queue<int> que;
  vector<int> visited(n, 0);
  vector<int> counter(n, 0);

  for (int i = 0; i < q; ++i) {
    int p, x; cin >> p >> x;
    --p;
    counter[p] += x;
  }

  que.emplace(0);
  visited[0] = 1;

  while (!que.empty()) {
    int cur = que.front(); que.pop();
    for (int next : g[cur]) {
      if (visited[next]) continue;
      visited[next] = 1;
      counter[next] += counter[cur];
      que.emplace(next);
    }
  }

  for (int i = 0; i < n; ++i) {
    cout << counter[i] << " ";
  }
  cout << '\n';

  return 0;
}

Measured memory_bytes: 16372
abcd = list(map(int,list(input())))
bins = []

for i in range(2**3):
    bins.append(list(str(format(i,'b').zfill(3))))

for i in range(8):
    res=abcd[0]
    ans = str(abcd[0])
    for j in range(3):
        if bins[i][j] == '0':
            res += (abcd[j+1])
            ans += '+'
            ans += str(abcd[j+1])
        
        else:
            res -= (abcd[j+1])
            ans += '-'
            ans += str(abcd[j+1])
    
    if res == 7:
        print(ans+'=7')
        break

Measured memory_bytes: 38384
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define reps(i,s,n) for(int i=(s); i<(n); i++)
#define all(v) v.begin(),v.end()
#define res(n) resize(n)
#define rev(v) reverse(v.begin(),v.end())
#define sor(v) sort(v.begin(),v.end())
#define outve(v) for(auto i : v) cout << i << " ";cout << endl
#define in(n,v) for(int i=0; i<(n); i++){cin >> v[i];}
#define out(n) cout << (n) << endl
#define fi first
#define se second
#define ve vector
#define pq priority_queue
#define vi vector<int>
#define vl vector<long long>
#define vii vector<vector<int>>
using namespace std;
typedef long long ll;
typedef long double ld;
const ll mod = 1000000007;



int main()
{
    int N,K;cin>>N>>K;
    vi A(3);
    in(3,A);
    string T;
    cin >> T;
    
    int ans = 0;
    
    map<char,int> S;
    S['r'] = A[2];
    S['s'] = A[0];
    S['p'] = A[1];
    
    rep(i,K){
        ans += S[T[i]];
        bool d = false;
        for (int j = i+K; j < N; j+=K) {
            if(!d && T[j-K] == T[j]){
                d = true;
                continue;
            }else if(d){
                d = false;
                ans += S[T[j]];
            }else{
                ans += S[T[j]];
            }
        }
    }

    out(ans);

    return 0;
}


Measured memory_bytes: 512
//58
#include<iostream>
#include<algorithm>

using namespace std;

int x,y,n;
int a[16];
int g[10][10];

int dfs(int (*c)[10],bool (*u)[10]){
  /*
    for(int i=0;i<y;i++){
    for(int j=0;j<x;j++){
      cout<<c[i][j];
    }
    cout<<endl;
  }
  cout<<"---"<<endl;
  */
  int s=0;
  for(int i=0;i<y;i++){
    for(int j=0;j<x;j++){
      if(u[i][j]==false){
	for(int h=0;i+h<y;h++){
	  int cn=0,ci;
	  for(int w=0;j+w<x;w++){
	    for(int ch=0;ch<=h;ch++){
	      if(c[i+ch][j+w]){
		cn++;
		ci=c[i+ch][j+w];
	      }
	    }
	    if(cn==1){
	      if((h+1)*(w+1)==a[ci]){
		int n[10][10];
		copy(c[0],c[10],n[0]);
		bool nu[10][10];
		copy(u[0],u[10],nu[0]);
		for(int ii=i;ii<i+h+1;ii++){
		  for(int jj=j;jj<j+w+1;jj++){
		    n[ii][jj]=ci;
		    nu[ii][jj]=true;
		  }
		}
		s+=dfs(n,nu);
		break;
	      }
	    }
	    if(cn>1){
	      break;
	    }
	  }
	}
	return s;
      }
    }
  }
  copy(c[0],c[10],g[0]);
  return 1;
}
	      
	    

int main(){
  while(cin>>x>>y>>n,x|y|n){
    for(int i=0;i<n;i++){
      int b,k;
      cin>>b>>k;
      a[b]=k;
    }
    for(int i=0;i<y;i++){
      for(int j=0;j<x;j++){
	cin>>g[i][j];
      }
    }
    int c[10][10];
    copy(g[0],g[10],c[0]);
    bool u[10][10]={};
    if(dfs(c,u)==1){
      for(int i=0;i<y;i++){
	for(int j=0;j<x;j++){
	  cout<<g[i][j]<<((j==x-1)?'\n':' ');
	}
      }
    }else{
      cout<<"NA"<<endl;
    }
  }
  return 0;
}

Measured memory_bytes: 1184