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

#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define MIN(a) *min_element(all(a))
#define MAX(a) *max_element(all(a))
#define SUM(a) accumulate(all(a), 0LL)
#define REP(i, n) for(int (i)=0; (i)<(n); (i)++)
#define RREP(i, n) for(int (i)=(n)-1; (i)>=0; (i)--)
#define FOR(i, m, n) for(int (i)=(m); (i)<(n); i++)
#define FORR(i, m, n) for(int (i)=(n)-1; (i)>=(m); i--)
#define debug(x) cerr << #x << " = " << x << endl
//#define int long long

typedef long long ll;
//ll const MOD = 998244353;
ll const MOD = 1e9+7;
int const inf = 1e9;
ll const INF = 1e18;

inline void ios_(){cin.tie(0); ios::sync_with_stdio(false);}
template<typename T> int size(const T& a){return (int)a.size();}
template<typename T> T Div(T a, T b){return (a + b - 1) / b;}
template<typename T> bool chmin(T& a, const T& b){if(a > b){a = b; return true;} return false;}
template<typename T> bool chmax(T& a, const T& b){if(a < b){a = b; return true;} return false;}



signed main(){
    ll n, k;
    cin >> n >> k;

    cout << min(n % k, k - (n % k)) << endl;
    return 0;
}


Measured memory_bytes: 256
def get_unique_list(seq):
    seen = []
    return [x for x in seq if x not in seen and not seen.append(x)]

N,M=map(int, input().split())
H=list(map(int, input().split()))
AB = [list(map(int, input().split())) for i in range(int(M))]

AB_unique=list(map(list, set(map(tuple, AB))))

AB_road=[True]*N
for AB in AB_unique:
    if H[AB[0]-1] > H[AB[1]-1]:
        AB_road[AB[1]-1]=False
    elif H[AB[0]-1] < H[AB[1]-1]:
        AB_road[AB[0]-1]=False
    else:
        AB_road[AB[1]-1]=False
        AB_road[AB[0]-1]=False

print(AB_road.count(True))

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

int main(){
  int h, w;
  char c;
  int ans[101][101];
  cin >> h >> w;
  for(int i=0; i<=h; i++) fill(ans[i], ans[i]+w+1, -1);

  for(int i=1; i<=h; i++) {
    for(int j=1; j<=w; j++) {
      cin >> c;
      if( c == 'c' ) ans[i][j] = 0;
      else if( ans[i][j-1] >= 0 ) ans[i][j] = ans[i][j-1]+1;
    }
  }
  
  for(int i=1; i<=h; i++) {
    for(int j=1; j<=w-1; j++) {
      cout << ans[i][j] << ' ';
    }
    cout << ans[i][w] << endl;
  }
}

Measured memory_bytes: 1200
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
using namespace std;
using ll = long long ;
using P = pair<int,int> ;
using pll = pair<long long,long long>;
constexpr int INF = 1e9;
constexpr long long LINF = 1e17;
constexpr int MOD = 1000000007;
constexpr double PI = 3.14159265358979323846;

int main(){
    int x;
    cin >> x;
    if(x>=30) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define all(x) (x).begin(), (x).end()
#define INF 1000000007
#define mod 1005
#define ll long long int
const double mx = 2e6 + 5 ;

void solve()
{
	int n;
	cin>>n;
	string s;
	cin>>s;
	int i = 0;
	string newString = "";
	while(i<n)
	{
		int j = i+1;
		while(j<n && s[i]==s[j])
			j++;
		newString+=s[i];
		i = j;
	}
	cout<<newString.length()<<"\n";
}
int main()
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	int t = 1;
//	cin>>t;
	while(t--)
	{
		solve();
	}
	return 0;
}

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

int main() {
  int s1;
  int s2;
  int s3;
  int x;
  cin >> x;
  s1 = x / 100;
  s2 = ( x - ( 100 * s1 ) ) / 10;
  s3 = x - ( 100 * s1 ) - ( 10 * s2 );
  cout << s1 + s2 + s3 <<endl;
}



Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main() {

	int A, B, C, D;
	cin >> A >> B >> C >> D;

	while (true)
	{
		C -= B;
		if (C <= 0) {
			cout << "Yes" << endl;
			break;
		}

		A -= D;
		if (A <= 0) {
			cout << "No" << endl;
			break;
		}
	}

	return 0;
}

Measured memory_bytes: 3620
import sys
input = sys.stdin.readline
import sys
sys.setrecursionlimit(10**7)
def main():
  n=int(input())
  s=input()
  sw,sb=[0],[0]
  w,b=0,0
  for si in s:
    if si=='#':
      b+=1
    else:
      w+=1
    sw.append(w)
    sb.append(b)
  ans=n
  for i in range(n+1):
    ans=min(ans,sw[n]-sw[i]+sb[i])
  print(ans)
if __name__=='__main__':
  main()
  

Measured memory_bytes: 12752
import copy
N = int(input())
A = list(map(int,input().split()))
B = copy.deepcopy(A)
B.sort()
num = [i for i in range(N)]
data = dict(zip(A,num))
ans = []
for i in B:
    ans.append(data[i]+1)
for i in ans:
    print(i,end=" ")

Measured memory_bytes: 24440
//minamoto
#include<bits/stdc++.h>
#define R register
#define fp(i,a,b) for(R int i=(a),I=(b)+1;i<I;++i)
#define fd(i,a,b) for(R int i=(a),I=(b)-1;i>I;--i)
#define go(u) for(int i=head[u],v=e[i].v;i;i=e[i].nx,v=e[i].v)
template<class T>inline bool cmax(T&a,const T&b){return a<b?a=b,1:0;}
template<class T>inline bool cmin(T&a,const T&b){return a>b?a=b,1:0;}
using namespace std;
const int N=1e5+5;
struct eg{int v,nx;}e[N<<1];int head[N],tot;
inline void add(R int u,R int v){e[++tot]={v,head[u]},head[u]=tot;}
char s[N];int col[N],f[N],deg[N],q[N],vis[N],rt,h,t,n,sum,res;
void dfs(int u,int fa){
//	printf("%d %d %d\n",u,fa,col[u]);
	if(deg[u]==1)return f[u]=0,void();
	go(u)if(v!=fa&&!vis[v])dfs(v,u),cmax(res,f[u]+col[u]+f[v]),cmax(f[u],f[v]);
	f[u]+=col[u];
}
int main(){
//	freopen("testdata.in","r",stdin);
	scanf("%d",&n);
	for(R int i=1,u,v;i<n;++i){
		scanf("%d%d",&u,&v);
		add(u,v),add(v,u),++deg[u],++deg[v];
	}
	scanf("%s",s+1);
	h=1,t=0;
	fp(i,1,n)if(deg[i]==1&&s[i]=='B')q[++t]=i;
	for(R int u;h<=t;){
		u=q[h++],vis[u]=1;
//		printf("%d\n",u);
		go(u)if(!vis[v]&&--deg[v]==1&&s[v]=='B')q[++t]=v;
	}
	fp(i,1,n)if(!vis[i]){
		++sum;
//		printf("OK %d\n",i);
		if(deg[i]>1)rt=i;
	}
	if(!rt){
		R int cnt=0;
		fp(i,1,n)cnt+=!vis[i]&&s[i]=='W';
		return printf("%d\n",cnt),0;
	}
	--sum,sum<<=1;
//	printf("%d\n",sum);
	fp(i,1,n)if(!vis[i])col[i]=(s[i]=='W')^(deg[i]&1),sum+=col[i],col[i]<<=1,cmax(res,col[i]);
	dfs(rt,0);
//	printf("%d %d\n",sum,sum-res-1+1);
	printf("%d\n",sum-res-1+1); 
	return 0;
}

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

const int MOD = 1000000007;
const int INF = 1e9;

int main(){
  string s,t;
  cin >> s >> t;
  int size = s.length();

  int trace1[26], trace2[26];
  for(int i = 0; i < 26; i++){
    trace1[i] = -1;
    trace2[i] = -1;
  }

  string ans = "Yes";

  for(int i = 0; i < size; i++){
    int sint = s[i]-'a';
    int tint = t[i]-'a';
    if(trace1[sint] < 0) trace1[sint] = tint;
    if(trace2[tint] < 0) trace2[tint] = sint;
    if(trace1[sint] >= 0 && trace1[sint] != tint) ans = "No";
    if(trace2[tint] >= 0 && trace2[tint] != sint) ans = "No";
  }

  cout << ans << endl;



  return 0;
}

Measured memory_bytes: 3924
#include<bits/stdc++.h>
#define ll long long
#define endl '\n'
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
int main()
{
   fastio;
   ll n,a=0,b=0,c=0,d=0;
   cin>>n;
   string s;
   for(ll i=0;i<n;i++)
   {
       cin>>s;
       if(s=="AC")
       {
           a++;
       }
       else if(s=="TLE")
       {
           c++;
       }
       else if(s=="WA")
       {
           b++;
       }
       else
       {
           d++;
       }
   }
   cout<<"AC x "<<a<<endl<<"WA x "<<b<<endl<<"TLE x "<<c<<endl<<"RE x "<<d<<endl;
   return 0;
}


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

using namespace std;

#ifdef DEBUG_MODE
	#define DBG(n) n;
#else
	#define DBG(n) ;
#endif
#define REP(i,n) for(ll (i) = (0);(i) < (n);++i)
#define PB push_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {for(int W = 0;W < (n);W++)cerr << v[W] << ' ';cerr << endl << endl;}
#define SHOW2d(v,i,j) {for(int aaa = 0;aaa < i;aaa++){for(int bbb = 0;bbb < j;bbb++)cerr << v[aaa][bbb] << ' ';cerr << endl;}cerr << endl;}
#define ALL(v) v.begin(),v.end()
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL
#define MOD 1000000007

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

/*
0-index
functionの中を書いて使う
宣言の時に単位元を書く
*/
template<typename T>
class segtree{
public:
	int n;vector<T> dat;T ZERO;

	segtree(int n_,T zero):ZERO(zero){
	  n = 1;
	  while(n < n_)n*=2;
	  dat.resize(2*n);
	  for(int i = 0;i < 2*n;i++)dat[i] = ZERO;
	}
	void update(int k, int a){
	  k += n - 1;dat[k] = a;
	  while(k > 0){
		k = (k-1)/2;
		dat[k] = function(dat[k*2+1],dat[k*2+2]);
	  }
	}

	T function(T a,T b){
		return min(a, b);
	}

	T get(int k){return dat[k+n-1];}
	T que(int a,int b){
		T L = ZERO,R = ZERO;
		int A = a + n - 1;
		int B = b + n - 1;
		while(A < B){
			if((A & 1) == 0)L = function(L,dat[A++]);
            if((B & 1) == 0)R = function(R,dat[--B]);
            A = A >> 1;
            B = B >> 1;
		}
		return function(L,R);
	}
};


int main(){

	ll n,e,t;cin >> n >> e >> t;

	vector<ll> v(n+10);
	vector<ll> x(n+10);
	vector<ll> sum_x(n+10);
	REP(i,n){
		cin >> v[i+1];
		x[i+1] = v[i+1] - v[i];
		sum_x[i+1] = x[i+1];
	}
	REP(i,n)sum_x[i+1] += sum_x[i];

	segtree<ll> sg1(n+10, LLINF);
	sg1.update(1, x[1]-3*sum_x[1]);
	segtree<ll> sg2(n+10, LLINF);
	sg2.update(1, x[1]-sum_x[1]);
	ll seica = 1;
	ll ans;

	for(int i = 2;i <= n+1;i++){
		//REP(j,n+3)cout << sg1.get(j) << " ";cout << endl;
		//REP(j,n+3)cout << sg2.get(j) << " ";cout << endl;
		while(seica < i-1 && t - 2 * (sum_x[i-1] - sum_x[seica]) <= 0)seica++;
		ll A = 3 * sum_x[i-1] + sg1.que(1,seica);
		ll B = t + sum_x[i-1] + sg2.que(seica,i);

		ll now = min(A , B);
		if(i != n+1){
			sg1.update(i, now+x[i]-3*sum_x[i]);
			sg2.update(i, now+x[i]-sum_x[i]);
		}
		else {
			ans = now;
		}
		//cout << "          " << i << " " << seica << " " << A << " " << B << endl;
	}

	cout << ans + e - v[n] << endl;

	return 0;
}


Measured memory_bytes: 6656
#include <bits/stdc++.h>
#include <chrono>
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1000000007
using namespace std;

int main(){
  chrono::system_clock::time_point start,end;
  start = chrono::system_clock::now();
  long d;
  cin >> d;
  long n = 26, csum = 0, ccost = 0;
  vector<long> c(n),last(n);
  rep(i,n){
    cin >> c[i];
    csum += c[i];
    last[i] = 0;
  }
  vector<vector<long>> s(d,vector<long>(n));
  rep(i,d)rep(j,n)cin >> s[i][j];
  vector<vector<long>> cand;
  vector<long> score;
  random_device rd{};
  vector<long> yotei(d);
  vector<long> tmp(d);
  long final_ans = 0, final_index;

  rep(jj,100){

    long ans = 0;
    rep(i,n)last[i] = 0;
    rep(i,d)yotei[i] = rd()%n;
    rep(i,d){
      ccost += csum;
      ccost -= c[yotei[i]]*(i+1 - last[yotei[i]]);
      ans -= ccost;
      last[yotei[i]] = i+1;
      ans += s[i][yotei[i]];
    }
    int ii = 0;
    while(ii < 200000){
      long new_day = rd()%d, new_con;
      while(1){
        new_con = rd()%n;
        if(yotei[new_day] != new_con)break;
      }
      long pre_con = yotei[new_day];
      yotei[new_day] = new_con;
      long tmpans = 0;
      ccost = 0;
      rep(i,n)last[i] = 0;
      rep(i,d){
        tmp[i] = yotei[i];
        ccost += csum;
        ccost -= c[yotei[i]]*(i+1 - last[yotei[i]]);
        tmpans -= ccost;
        last[yotei[i]] = i+1;
        tmpans += s[i][yotei[i]];
      }
      if(tmpans < ans)yotei[new_day] = pre_con;
      else{
        ans = tmpans;
        cand.push_back(tmp);
      }
      ii++;
    }
    if(final_ans < ans){
      final_ans = ans;
      final_index = int(cand.size()-1);
    }
    end = chrono::system_clock::now();
    auto time = end - start;
    if(static_cast<double>(chrono::duration_cast<chrono::milliseconds>(time).count()) > 1880)break;
  }
  rep(i,d)cout << cand[final_index][i]+1 << endl;
  return 0;
}

Measured memory_bytes: 30976
n, a, b = map(int, raw_input().split())

def doit(a, b, mask):
    differ = -1
    for i in range(n):
        if mask & (1 << i) == 0 and (a ^ b) & (1 << i) != 0:
            differ = i
    same = -1
    for i in range(n):
        if mask & (1 << i) == 0 and i != differ:
            same = i
    if same == -1:
        return [a, b]
    return (doit(a, a ^ (1 << same), mask | (1 << differ)) +
            doit(a ^ (1 << same) ^ (1 << differ), b, mask | (1 << differ)))

if bin(a ^ b).count('1') % 2 != 1:
    print "NO"
else:
    print "YES"
    ret = doit(a, b, 0)
    print " ".join(map(str, ret))

Measured memory_bytes: 15480
#include <iostream>
#include <algorithm>
#include <math.h>
#include <string>
#include <functional> 
#include <vector>
#include <numeric>
#include <stack>
#include <queue>
#include <utility>
#include <map>
#include <cstdlib>
typedef long long ll;
#define fi first
#define se second
 
using namespace std;
 
int main(){
 
    int n;
    cin >> n;

    if(n <= 2){
        cout << 1;
        return 0;
    }

    int a[n+10],ans =1;
    cin >> a[0];
    int joutai = 0;
    for(int i=1;i<n;i++){
        cin >> a[i];
        if(joutai == 0){
            if(a[i-1] > a[i]) joutai = -1;
            if(a[i-1] < a[i]) joutai = 1;
        }
        else if(a[i-1] < a[i] && joutai == -1){
            ans++;
            joutai = 0;
            //cout << joutai;
        }
        else if(a[i-1] > a[i] && joutai == 1){
            ans++;
            joutai = 0;
            //cout << joutai;
        }

    }
  cout << ans;

    return 0;
}

Measured memory_bytes: 640
// Aizu Vol-1 0136: Frequency Distribution of Height
// 2017.8.1

#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>

char *gets(char *);

#define MAX 50
char buf[MAX + 5], *p;
int freq[6];

int getDouble(void)
{
	int len = 0, n = 0;

	while (isspace(*p)) p++;
	while (isdigit(*p)) n = 10 * n + (*p++ - '0');
	if (*p == '.') p++;
	while (isdigit(*p)) n = 10 * n + (*p++ - '0'), len++;
#define MAGIC 2
	if (len > MAGIC) while (1);
	while (len < MAGIC) n = 10 * n, len++;
	return n;
}

int main()
{
	int k, i, n;

	gets(buf);
	n = atoi(buf);
	for (i = 0; i < n; i++) {
		gets(p = buf);
		k = getDouble();
		if      (k < 16500) freq[0]++;
		else if (k < 17000) freq[1]++;
		else if (k < 17500) freq[2]++;
		else if (k < 18000) freq[3]++;
		else if (k < 18500) freq[4]++;
		else                freq[5]++;
	}
	for (i = 0; i < 6; i++) {
		putchar(i + '1'), putchar(':');
		for (k = 0; k < freq[i]; k++) putchar('*');
		putchar('\n');
	}
	return 0;
}

Measured memory_bytes: 524
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, begin, end) for (ll i = (begin); i < (end); i++)
#define REP(i, n) FOR(i, 0, n)
#define IFOR(i, begin, end) for (ll i = (begin)-1; i >= (end); i--)
#define IREP(i, n) IFOR(i, n, 0)
#define SORT(a) sort(a.begin(), a.end())
#define ISORT(a) sort(a.begin(), a.end(), greater<ll>())
#define REVERSE(a) reverse(a.begin(), a.end())
#define debug(x) cout << #x << "=" << x << endl;
#define vdebug(v)                                          \
  cout << #v << "=(" << v[0];                              \
  FOR(i_debug, 1, v.size()) { cout << "," << v[i_debug]; } \
  cout << ")" << endl;
#define mdebug(m)                                                           \
  cout << #m << "=" << endl;                                                \
  REP(i_debug, m.size())                                                    \
  {                                                                         \
    REP(j_debug, m[i_debug].size()) { cout << m[i_debug][j_debug] << ","; } \
    cout << endl;                                                           \
  }
#define Lower_bound(v, x) \
  distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) \
  distance(v.begin(), upper_bound(v.begin(), v.end(), x))
#define Max(a, b) a = max(a, b)
#define Min(a, b) a = min(a, b)

#define ll long long
#define ld long double
// #define f first
// #define s second
#define mp make_pair
#define pb push_back
#define INF 1000000000000000000

using vec = vector<ll>;
using mat = vector<vec>;
using Pii = pair<ll, ll>;
using PiP = pair<ll, Pii>;
using PPi = pair<Pii, ll>;
using bvec = vector<bool>;
using Pvec = vector<Pii>;

bool is_prime(ll k)
{
  if (k == 1)
    return false;
  for (ll j = 2; j * j <= k; j++)
  {
    if (k % j == 0)
    {
      return false;
    }
  }
  return true;
}

int main()
{
  ll N;
  cin >> N;
  ll Norig = N;

  vec primeid(1000010, 1);
  ll ans = 0;
  if (is_prime(Norig))
  {
    cout << 1 << endl;
    return 0;
  }
  for (ll i = 2; i * i <= Norig; i++)
  {
    // debug(i);
    if (!is_prime(i))
      continue;
    while (N % (ll)pow(i, primeid[i]) == 0)
    {
      // debug(N);
      ans++;
      N /= (ll)pow(i, primeid[i]);
      primeid[i]++;
    }
    while (N % i == 0)
      N /= i;
    if (N == 1)
      break;
  }
  if (is_prime(N))
    ans++;

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 11244
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(x) (x).begin(),(x).end()
const int mod=1000000007,MAX=200005;
const ll INF=1LL<<60;

int main(){
    
    std::ifstream in("text.txt");
    std::cin.rdbuf(in.rdbuf());
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    ll N,M,V,P;cin>>N>>M>>V>>P;
    vector<ll> A(N),S(N+1);
    for(int i=0;i<N;i++) cin>>A[i];
    sort(all(A));
    reverse(all(A));
    
    for(ll i=P-1;i<N;i++){
        S[i+1]=S[i]+A[i];
    }
    
    ll ans=P;
    
    for(ll i=P;i<N;i++){
        if(A[P-1]>A[i]+M) continue;
        
        ll rem=V-(P-1)-1;
        
        if(rem<=0){
            ans++;
            continue;
        }
        
        ll need=rem*M;
        
        ll can=(A[i]+M)*(i-(P-1))-(S[i]-S[P-1])+(N-1-i)*M;
        
        if(can>=need) ans++;
        
        //cout<<i<<" "<<need<<" "<<can<<endl;
    }
    
    cout<<ans<<endl;
}


Measured memory_bytes: 1792
#include<iostream>
#include<algorithm>
#include<functional>
using namespace std;

int main(){
	int person[20], fish[20];
	int n;
	int array[20];
	int fishPerson[20];
	int cont = 0;
	cin >> n;
	for(int i=0; i < n; i++){
		cin >> person[i] >> fish[i];
		array[i] = fish[i];
	}
	sort(array, array+n, greater<int>());

	for(int i=0; i < n; i++){
		if(array[0] == fish[i]){
			fishPerson[cont] = person[i];
			cont++;
		}
	}
	sort(fishPerson, fishPerson+cont);

	for(int i=0; i < 20; i++){
		if(fishPerson[0] == person[i]){
			cout << person[i] << " " << fish[i] << endl;
		}
	}




}

Measured memory_bytes: 1184
N, M =map(int, input().split())
a, b = [], []
for i in range(M):
    a_i, b_i = map(int, input().split())
    a.append(a_i -1)
    b.append(b_i -1)
    
class UnionFind:
    def __init__(self, n):
        self.p = {}
        self.r = {}
        self.s = {}
        for i in range(n):
            self.p[i] = i # 親,グループ番号
            self.r[i] = 1 
            self.s[i] = 1 # サイズ、連結数
            
    def find(self, n):
        path = []
        while n != self.p[n]:
            path.append(n)
            n = self.p[n]
        for m in path:
            self.p[m] = n
        return n 

    def union(self, a, b):
        ap = self.find(a)
        bp = self.find(b)
        if self.r[ap] > self.r[bp]:
            self.p[bp] = ap
            size = self.s[bp] + self.s[ap]
            self.s[ap] = size
        elif self.r[bp] > self.r[ap]:
            self.p[ap] = bp
            size = self.s[bp] + self.s[ap]
            self.s[bp] = size
        elif ap != bp:
            self.p[ap] = bp
            self.r[bp] += 1
            size = self.s[bp] + self.s[ap]
            self.s[bp] = size
            
    def size(self, n):
        np = self.find(n)
        return self.s[np]
    
s = UnionFind(N)
 
ans = (N*(N-1)) // 2
anss = [ans]

for i in range(M):
    j = M - i - 1
    if s.find(a[j]) != s.find(b[j]):
        ans -= s.size(a[j]) * s.size(b[j])
        s.union(a[j], b[j])
    if i != M-1:
        anss.append(ans)
        
sort_ans = sorted(anss)
for i in range(len(sort_ans)):
    print(sort_ans[i])

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

int main() {
	int w, h, n;
	cin >> w >> h >> n;
	int l = 0;
	int r = w;
	int d = 0;
	int u = h;
	for (int i = 0; i < n; i++) {
		int x, y, a;
		cin >> x >> y >> a;
		if (a == 1) l = max(l, x);
		if (a == 2) r = min(r, x);
		if (a == 3) d = max(d, y);
		if (a == 4) u = min(u, y);

	}
	int ans = (r - l) * (u - d);
	if ((r-l) < 0 || (u-d) < 0) ans = 0;
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void) {
	
	int l,m,n;
	
	scanf("%d %d %d",&l,&m,&n);
	
	if(l > m)
	{
		int temp;
		
		temp =l;
		
		l=m;
		m=temp;
		
	}
	if (m>n)
	{
		int temp1;
		
		temp1 =m;
		
		m=n;
		n=temp1;
	}
	if (l>m)
	{
		int temp2;
		
		temp2=l;
		
		l=m;
		m=temp2;
		
	}
	 
	
	
	printf("%d %d %d\n",l,m,n);
	
	// your code goes here
	return 0;
	
	
	
}



Measured memory_bytes: 2080
#include <bits/stdc++.h>
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <cctype>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <functional>
using namespace std; 
#define DEBUG(x) cout << '>' << #x << ':' << x << endl;
#define REP(i,n) for(int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<=(b);i++)
#define FORD(i,a,b) for(int i=(a);i>=(b);i--)
inline bool EQ(double a, double b) { return fabs(a-b) < 1e-9; }
const int INF = 1<<29;
typedef long long int ll;
inline int two(int n) { return 1 << n; }
inline int test(int n, int b) { return (n>>b)&1; }
inline void set_bit(int & n, int b) { n |= two(b); }
inline void unset_bit(int & n, int b) { n &= ~two(b); }
inline int last_bit(int n) { return n & (-n); }
inline int ones(int n) { int res = 0; while(n && ++res) n-=n&(-n); return res; }
template<class T> void chmax(T & a, const T & b) { a = max(a, b); }
template<class T> void chmin(T & a, const T & b) { a = min(a, b); }
const int MOD=1000000007;

bool isPowerOfTwo (ll x)  
{  
    return x && (!(x&(x-1)));  
}
bool isPrime(int n) 
{ 
    if (n <= 1)  return false; 
    if (n <= 3)  return true; 
    if (n%2 == 0 || n%3 == 0) return false; 
  
    for (int i=5; i*i<=n; i=i+6) 
        if (n%i == 0 || n%(i+2) == 0) 
           return false; 
  
    return true; 
}
int highestPowerof2(unsigned int n) 
{ 
    // Invalid input 
    if (n < 1) 
        return 0; 
  
    int res = 1;
    for (int i=0; i<8*sizeof(unsigned int); i++) 
    { 
        int curr = 1 << i; 
        if (curr > n) 
           break; 
  
        res = curr; 
    } 
  
    return res; 
} 
long long binpow(long long a, long long b) {
    long long res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a;
        a = a * a;
        b >>= 1;
    }
    return res;
}
const int dx[] = {1,0,-1,0,1,1,-1,-1};
const int dy[] = {0,-1,0,1,1,-1,-1,1};       
////////////////////////////////////////////////////////////////////

int main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);  
  cout.tie(NULL);
  ll t=1;
  while(t--)
  {
    int n,x;
    cin>>n>>x;
    int a[n];
    REP(i,n)cin>>a[i];
    int u=abs(a[0]-x);
    int y;
    int ans;
    REP(i,n)
    {
        y=abs(x-a[i]);
        ans=__gcd(u,y);
        u=ans;
    }
    cout<<ans;
  }  
  return 0;
}

Measured memory_bytes: 640
#include<math.h>
#include <bits/stdc++.h>
#include <algorithm>
#define rep(i, n) for (int i = 0; i < (int)n; i++)
#define ll long long int
#define py printf("Yes\n")
#define pn printf("No\n")
#define in cin>>
using namespace std;
int INF = 1001001001;

int main()
{
    string s;
    vector<bool> ch(27);
    ch={false};
    in s;
    for(int i=0;s[i]!='\0';i++)
    {
        ch[s[i]-'a']=true;
    }
    for(int i=0;i<26;i++)
    {
        if(!ch[i])
        {
            cout<<(char)(i+'a')<<endl;
            return 0;
        }
    }
    cout<<"None"<<endl;
    return 0;
}


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

using namespace std;

typedef long long ll;
typedef long double ld;
#define mems(p) memset(p,-1,sizeof(p))
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define nl "\n"

const int mxN = 1e5;
const ll MOD = 1e9 + 7;

void fast()
{ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);}

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



int main() {
	fast();
	int n, tmp;
	cin >> n;
	vector<int> ctra(n+1, 0), ctrb(n+1, 0);
	vector<int> a(n), b(n);
	vector<int> ans(n, 0);
	for (int i = 0; i < n; ++i)
	{
		cin >> a[i];
		ctra[a[i]]++;
	}
	for (int i = 0; i < n; ++i)
	{
		cin >> b[i];
		ctrb[b[i]]++;
	}
	for (int i = 1; i <= n; ++i)
	{
		int common = min(ctra[i], ctrb[i]);
		if (common + max(ctra[i],ctrb[i]) > n) {
			cout << "No\n";
			return 0;
		}
	}
	cout << "Yes\n";
	int lb = 0, rb = n - 1;
	while (lb <= rb) {
		int mb = (lb+rb)/2;
		// start frm mb
		int ctr = 0;
		bool fail = false;
		for (int i = mb; i < mb + n; ++i) {
			int idx = i;
			if (idx >= n) idx -= n;
			if (b[ctr] == a[idx]) {
				fail = true;
				if (idx >= mb) {
					lb = mb + 1;
				} else {
					rb = mb - 1;
				}
				break;
			}
			ans[idx] = b[ctr];
			++ctr;
		}
		if (!fail) {
			for (int i = 0; i < n; ++i)
			{
				cout << ans[i] << " ";
			}
			cout << nl;
			return 0;
		}
	}
	cout << "fail?\n";
}

Measured memory_bytes: 7152
#include<stdio.h>
#include<iostream>
#include<algorithm>
using namespace std;
long long a[1000005];
int main()
{
	int n;
	scanf("%d",&n);
	for(int i=0;i<n;i++)
	{
		scanf("%d",&a[i]);
	}
	sort(a,a+n);
	int x=1,p=0;
	for(int i=1;i<n;i++)
	{
		if(a[i]==a[i-1])
		{
		x=(x+1)%2;
		}
		else 
		{
			p+=x;
			x=1;
		}
	}
	if(x%2)
		{
			p++;
		}
		
		printf("%d\n",p);
		
		return 0;
} 

Measured memory_bytes: 1024
#include "bits/stdc++.h"
#define ll long long
#define rep2(i,a,b) for(int i=(a);i<=(b);++i)
#define rep(i,n) rep2(i,0,n-1)

using namespace std;
main(){
    int a,b,c,x,y;
    cin>>a>>b>>c>>x>>y;
    ll int n1=x*a+y*b;
    ll int n2,n3;
    if(x>y){
       n2=y*c*2+(x-y)*a;
        n3=x*2*c;
    }
    else {
        n2=x*c*2+(y-x)*b;
        n3=y*2*c;
    }
    ll int n=min(n1,n2);
    ll int n4=min(n,n3);
    cout<<n4;
    return 0;
}

Measured memory_bytes: 256
//#pragma GCC optimize("O-fast")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")
//#pragma comment(linker, "/STACK:367077216")

#include <iostream>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <algorithm>
#include <iomanip>

using namespace std;

typedef long long ll;
typedef long double ld;

#define pii pair<int, int>
#define F first
#define S second
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define pop pop_back

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	int a, b, c;
	cin >> a >> b >> c;
	int k; cin >> k;
	if (k <= a) cout << k;
	else if (k <= a + b) cout << a;
	else cout << a - (k - a - b);
	return 0;
}

Measured memory_bytes: 3656
N, X = map(int, input().split())
x = X
nums = [1]
p_count = [1]
for i in range(N):
    nums.append(2 * nums[-1] + 3)
    p_count.append(2 * p_count[-1] + 1)


def solve_p(N, X):
    if X <= 0:
        return 0
    elif N == 0:
        return 1
    else:
        if X == (nums[N]+1) // 2:
            return (p_count[N]+1) // 2
        elif X < (nums[N]+1) // 2:
            return solve_p(N - 1, X - 1)
        else:
            #print("num", nums[N])
            return p_count[N-1]+1+solve_p(N-1, X-(nums[N]+1)//2)


print(solve_p(N, X))
"""
burger = ["P"]
for i in range(N):
    burger.append(("B"+burger[i]+"P"+burger[i]+"B"))
# print(burger)  # [N + 1])

# print(burger[N])

print(burger[N][:x].count("P"))
"""


Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <numeric>

#define REP(i, a, b) for (int i = int(a); i < int(b); i++)
using namespace std;
typedef long long int ll;

// clang-format off
#ifdef _DEBUG_
#define dump(...) do{ cerr << __LINE__ << ":\t" << #__VA_ARGS__ << " = "; PPPPP(__VA_ARGS__); cerr << endl; } while(false)
template<typename T> void PPPPP(T t) { cerr << t; }
template<typename T, typename... S> void PPPPP(T t, S... s) { cerr << t << ", "; PPPPP(s...); }
#else
#define dump(...)
#endif
template<typename T> vector<T> make_v(size_t a, T b) { return vector<T>(a, b); }
template<typename... Ts> auto make_v(size_t a, Ts... ts) { return vector<decltype(make_v(ts...))>(a, make_v(ts...)); }
template<typename T>
bool chmin(T &a, T b) { if (a > b) {a = b; return true; } return false;}
template<typename T>
bool chmax(T &a, T b) { if (a < b) {a = b; return true; } return false;}
// clang-format on

#include <utility>
using P = pair<ll, int>;

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<ll> a(n);
    REP(i, 0, n) {
        cin >> a[i];
    }
    vector<P> increase;
    {
        ll prev = -1;
        REP(i, 0, n) {
            if (prev < a[i]) {
                increase.emplace_back(a[i], i);
                prev = a[i];
            }
        }
    }
    sort(a.begin(), a.end());
    if (increase.size() == 1) {
        ll sum = accumulate(a.begin(), a.end(), 0LL);
        cout << sum << endl;
        REP(i, 1, n) {
            cout << 0 << endl;
        }
        return 0;
    }
    vector<ll> ans(n, 0);
    int j = 0;
    ll prev = 0;
    REP(i, 0, n) {
        if (a[i] > increase[j].first) {
            ans[increase[j].second] += (n - i) * (increase[j].first - prev);
            prev = increase[j].first;
            j++;
        }
        int ind = increase[j].second;
        ans[ind] += a[i] - prev;
    }
    REP(i, 0, n) {
        cout << ans[i] << endl;
    }

    return 0;
}


Measured memory_bytes: 4208
#define _USE_MATH_DEFINES
#include<iostream>
#include<algorithm>
#include<cmath>
#include<string>
#include<set>
#include<map>
#include<vector>
#include<utility>
#include<queue>
#include<stdbool.h>
#include<math.h>
#include<sstream>
typedef long long ll;
#define N (1000000000+7)
#define INF (-1000000)
using namespace std;
typedef pair<int, int> P;

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

int d[55][55];

char board[55][55];
int h, w;

int bfs() {
	queue<P>q;
	for (int i = 1;i <= h;i++) {
		for (int j = 1;j <= w;j++) {
			d[i][j] = INF;
		}
	}
	q.push(P(1, 1));
	d[1][1] = 0;
	while (!q.empty()) {
		P p = q.front();q.pop();
		if ((p.first == h) && (p.second == w))break;
		for (int i = 0;i < 4;i++) {
			int nx = p.first + dx[i];
			int ny = p.second + dy[i];
			if ((1 <= nx) && (nx <= h) && (1 <= ny) && (ny <= w) && (board[nx][ny] != '#') && (d[nx][ny] == INF)) {
				q.push(P(nx, ny));
				d[nx][ny] = d[p.first][p.second] + 1;
			}
		}
	}
	return d[h][w];
}


int main(void) {
	ll n;
	double ans = 0, a;
	string t;
	cin >> n;
	for (ll i = 0;i < n;i++) {
		cin >> a;
		cin >> t;
		if (t == "JPY")ans = (double)ans + (double)a;
		else ans = (double)ans + (double)a * 380000;
	}
	printf("%lf\n", ans);
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>
#include<complex>
using namespace std;

//#define int long long
typedef long long ll;

typedef unsigned long long ul;
typedef unsigned int ui;
const ll mod = 1000000007;
const ll INF = (1e+18) + 7;
typedef pair<int, int>P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
#define all(v) (v).begin(),(v).end()
typedef pair<ll, ll> LP;
typedef long double ld;
typedef pair<ld, ld> LDP;
const ld eps = 1e-6;
const ld pi = acos(-1.0);
//typedef vector<vector<ll>> mat;
typedef vector<int> vec;

ll mod_pow(ll a, ll n) {
	ll res = 1;
	while (n) {
		if (n & 1)res = res * a%mod;
		a = a * a%mod; n >>= 1;
	}
	return res;
}

struct modint {
	ll n;
	modint() :n(0) { ; }
	modint(ll m) :n(m) {
		if (n >= mod)n %= mod;
		else if (n < 0)n = (n%mod + mod) % mod;
	}
	operator int() { return n; }
};
bool operator==(modint a, modint b) { return a.n == b.n; }
modint operator+=(modint &a, modint b) { a.n += b.n; if (a.n >= mod)a.n -= mod; return a; }
modint operator-=(modint &a, modint b) { a.n -= b.n; if (a.n < 0)a.n += mod; return a; }
modint operator*=(modint &a, modint b) { a.n = ((ll)a.n*b.n) % mod; return a; }
modint operator+(modint a, modint b) { return a += b; }
modint operator-(modint a, modint b) { return a -= b; }
modint operator*(modint a, modint b) { return a *= b; }
modint operator^(modint a, int n) {
	if (n == 0)return modint(1);
	modint res = (a*a) ^ (n / 2);
	if (n % 2)res = res * a;
	return res;
}

ll inv(ll a, ll p) {
	return (a == 1 ? 1 : (1 - p * inv(p%a, a)) / a + p);
}
modint operator/(modint a, modint b) { return a * modint(inv(b, mod)); }

const int max_n = 1 << 20;
modint fact[max_n], factinv[max_n];
void init() {
	fact[0] = modint(1);
	for (int i = 0; i < max_n - 1; i++) {
		fact[i + 1] = fact[i] * modint(i + 1);
	}
	factinv[max_n - 1] = modint(1) / fact[max_n - 1];
	for (int i = max_n - 2; i >= 0; i--) {
		factinv[i] = factinv[i + 1] * modint(i + 1);
	}
}
modint comb(int a, int b) {
	if (a < 0 || b < 0 || a < b)return 0;
	return fact[a] * factinv[b] * factinv[a - b];
}
void solve() {
	char c; cin >> c;
	c++;
	cout << c << endl;
}

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	//cout << fixed << setprecision(7);
	//init();
	//int t; cin >> t; rep(i, t)solve();
	solve();
	stop
		return 0;
}


Measured memory_bytes: 16768
#include<iostream>
#include<string>
#include<math.h>
using namespace std;

int main() {
	char S[20];
	string T;
	string p;
	string Q;
	double m;
	int a = 0;
	int A = 0;
	int b = 0;
	int B = 0;
	int c = 0;
	int C = 0;
	int q, w, z;
	int n = 0;
	int x = 0;
	int y = 0;
	int ans = 0;
	int X[100] = { 0 };
	cin >> a >> b;
	if (a * b % 2 == 0) {
		cout << "No";
	}
	else {
		cout << "Yes";
	}
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
#include<math.h>
using namespace std;

int keta(int x){
	int i=0;
	while (x/pow(10,i)>=1){
		i++;
	}
	if (x==0){
		return 1;
	}
	else
	return i;
	}


int main(){
int d;
while(cin>>d){
	int sum=0;
	for (int i=0;i<600/d;i++){
		sum+=(i*d)*(i*d)*d;
	}
	cout<<sum<<endl;
}
return 0;
}

Measured memory_bytes: 1160
#include<iostream>
#include<queue>
using namespace std;
int main(){
int a[1000][1000];
int n;
cin>>n;
for(int i=0;i<n;i++){
	for(int j=0;j<n-1;j++){
		cin>>a[i][j];
		a[i][j]--;
	}
}
int ind[1000];
for(int i=0;i<n;i++){ind[i]=0;}
int count=1;
int ans=0;
queue<int> ho;
for(int i=0;i<n;i++){ho.push(i);}
while(count>0){
	count=0;
	int temp[1000];
	for(int i=0;i<n;i++){temp[i]=0;}
	int u=ho.size();
	for(int j=0;j<u;j++){
		int i=ho.front();
		ho.pop();
		if(ind[i]<n-1){
			if(ind[a[i][ind[i]]]<n-1){
				if(a[a[i][ind[i]]][ind[a[i][ind[i]]]]==i and temp[i]==0){
					temp[i]++;
					temp[a[i][ind[i]]]++;
					count++;
					ho.push(i);
					ho.push(a[i][ind[i]]);
				}
			}
		}
	}
	if(count>0){ans++;}
	for(int i=0;i<n;i++){
		ind[i]+=temp[i];
	}
}
for(int i=0;i<n;i++){if(ind[i]!=n-1){cout<<-1<<endl;return 0;}}
cout<<ans<<endl;
return 0;
}


Measured memory_bytes: 4224
/**********************************************
 *Author*        :jxf378440404
 *Created Time*  : 2019/1/13 19:59:06

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

#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <string>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>
#include <queue>
#include <set>
using namespace std;
typedef long long LL;
const int MaxN = 1e5;
const int Inf = 1 << 30;

LL A[MaxN + 5];

int main()
{
	int n,ans,res;
	LL sum,B;
	while(~scanf("%d",&n)){
		sum = 0LL;
		ans = 0;
		for(int i = 1;i <= n;i++){
			scanf("%lld",&A[i]);
			sum += A[i];
		}
		for(int i = 1;i <= n;i++){
			scanf("%lld",&B);
			sum -= B;
			A[i] -= B;
		}
		if(sum >= 0){
			sort(A + 1,A + 1 + n);
			res = n + 1;A[res] = 0;
			for(int i = 1;i <= n;i++){
				if(A[i] >= 0) break;
				if(A[res] + A[i] >= 0){
					A[res] += A[i];
					ans++;
				}
				else{
					A[i] += A[res];
					ans++;
					res--;
					i--;
				}
			}
			printf("%d\n",ans);
		}
		else printf("-1\n");
	}
    return 0;
}

Measured memory_bytes: 896
import java.util.*;
import java.math.RoundingMode;
import java.math.BigDecimal;
 
public class Main {
	
	
	 
	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
        int a[] = new int[n];
        for(int i = 0; i < n; i++) {
        	a[i] = sc.nextInt();
        }
        int count=0;
        int now = 1;
        while(now!=2&&count<=n+1) {
        	now = a[now-1];
        	count++;
        }
        if(now != 2) {
            System.out.println(-1);
        }
        else {
        	System.out.println(count);
        }
	}
}

Measured memory_bytes: 50916
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <climits>
#include <string>
#include <bitset>
#include <cfloat>
#include <unordered_set>
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<ll> > vvll;
#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) - 1; i >= 0; --i)
#define fin(ans) cout<<(ans)<<endl
#define STI(s) atoi(s.c_str())
#define mp(p,q) make_pair(p, q)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define Sort(a) sort(a.begin(), a.end())
#define Rort(a) sort(a.rbegin(), a.rend())
#define MATHPI acos(-1)
#define itn int
template <class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template <class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
struct io{io(){ios::sync_with_stdio(false);cin.tie(0);};};
const ll MOD = 1000000007;
const int INF = INT_MAX;
const ll LLINF = 1LL<<62;


int count(int k, int s, set<int>& ok, set<int> &ng){
    int res=0;

    int ngmax=*max_element(ng.begin(),ng.end());
    
    ok.erase(ok.begin(),lower_bound(ok.begin(),ok.end(),ngmax));

    set<int> oktmp=ok;

    for(auto it=ok.begin();it!=ok.end();it++){
        int nextint=*it;
        if(s<nextint)break;
        oktmp.erase(oktmp.find(nextint));
        ng.insert(nextint);
        
        if(k==1&&s==nextint)res++;
        else res+=count(k-1,s-nextint,oktmp,ng);

        ng.erase(ng.find(nextint));
        oktmp.insert(nextint);
    }
    
    return res;
}

int main(void){

    while(1){
        int n,k,s;
        cin>>n>>k>>s;
        if(n==0)break;
        set<int> ok,ng;
        rep(i,n)ok.insert(i+1);
        cout<<count(k,s,ok,ng)<<endl;

    }

}


Measured memory_bytes: 3068
#include <bits/stdc++.h>
#include <string>
#include <stdio.h>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
using namespace std;

int main(void) {
    int N;
    cin>>N;
    char s[N];
    for(int i=0;i<N;i++){
      cin>>s[i];
    }
    for(int i=0;i<N;i++){
    if(s[i]=='Y'){
      cout<<"Four"<<endl;
        return 0;
    }
  }
cout<<"Three"<<endl;


    return 0;
}


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

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;
}

int main(){
	int n,m;
	while(cin>>n>>m){
		cout<<gcd(n,m)<<" "<<lcm(n,m)<<endl;
	}
}

Measured memory_bytes: 3028
#[allow(dead_code)]
fn main() {
    let (x, y, z) = i::u3();
    let x = x - z;
    println!("{}", x / (y + z));
}

#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::{BTreeMap, BTreeSet, HashMap, HashSet, VecDeque};
#[allow(unused_imports)]
use std::io::*;
#[allow(unused_imports)]
use std::num::*;
#[allow(unused_imports)]
use std::str::*;

#[allow(dead_code)]
mod i {
    use super::*;

    pub fn read<T: FromStr>() -> T {
        stdin()
            .bytes()
            .map(|c| c.unwrap() as char)
            .skip_while(|c| c.is_whitespace())
            .take_while(|c| !c.is_whitespace())
            .collect::<String>()
            .parse::<T>()
            .ok()
            .unwrap()
    }
    pub fn str() -> String {
        read()
    }
    pub fn s() -> Vec<char> {
        str().chars().collect()
    }
    pub fn i() -> i64 {
        read()
    }

    pub fn u() -> usize {
        read()
    }

    pub fn u2() -> (usize, usize) {
        (read(), read())
    }

    pub fn u3() -> (usize, usize, usize) {
        (read(), read(), read())
    }

    pub fn u4() -> (usize, usize, usize, usize) {
        (read(), read(), read(), read())
    }

    pub fn u5() -> (usize, usize, usize, usize, usize) {
        (read(), read(), read(), read(), read())
    }

    pub fn u6() -> (usize, usize, usize, usize, usize, usize) {
        (read(), read(), read(), read(), read(), read())
    }

    pub fn f() -> f64 {
        read()
    }

    pub fn c() -> char {
        read::<String>().pop().unwrap()
    }

    pub fn iv(n: usize) -> Vec<i64> {
        (0..n).map(|_| i()).collect()
    }

    pub fn iv2(n: usize) -> Vec<(i64, i64)> {
        (0..n).map(|_| iv(2)).map(|a| (a[0], a[1])).collect()
    }

    pub fn iv3(n: usize) -> Vec<(i64, i64, i64)> {
        (0..n).map(|_| iv(3)).map(|a| (a[0], a[1], a[2])).collect()
    }

    pub fn uv(n: usize) -> Vec<usize> {
        (0..n).map(|_| u()).collect()
    }

    pub fn uv2(n: usize) -> Vec<(usize, usize)> {
        (0..n).map(|_| uv(2)).map(|a| (a[0], a[1])).collect()
    }

    pub fn uv3(n: usize) -> Vec<(usize, usize, usize)> {
        (0..n).map(|_| uv(3)).map(|a| (a[0], a[1], a[2])).collect()
    }

    pub fn uv4(n: usize) -> Vec<(usize, usize, usize, usize)> {
        (0..n)
            .map(|_| uv(4))
            .map(|a| (a[0], a[1], a[2], a[3]))
            .collect()
    }

    pub fn fv(n: usize) -> Vec<f64> {
        (0..n).map(|_| f()).collect()
    }

    pub fn cmap(h: usize) -> Vec<Vec<char>> {
        (0..h).map(|_| s()).collect()
    }
}


Measured memory_bytes: 4352
n = int(input())
a = list(map(int, input().split()))

def insertionSort(a, n):
    for  i in range(1,n):
        v = a[i]
        j = i-1
        while j >= 0 and a[j] > v:
            a[j+1] = a[j]
            j -= 1
        a[j+1] = v
        print(*a)

print(*a)
insertionSort(a,n)


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

int D = 50;
ll calc(ll n){
    int j = 0;
    ll m = 1;
    m <<= D;
    ll ret = 0;
    for(int i = D;i>=2;i--){
        //cout << m << endl;
        if(m<=n*2){
            //cout << m << endl;
            ret = ret*2 + max(n%m - m/2 + 1,ll(0))%2;
            j++;
        }
        m >>= 1;
    }
    ret = ret*2 + ((n+1)/2)%2;
    return ret;
}

int main(){
    ll a,b;cin >> a >> b;
    ll c = calc(a-1);
    ll d = calc(b);
    cout <<(c^d)<<endl;

    
    //cout << calc(a) << " " << calc(b) << endl;
    // ll c = calc(a)^calc(b);
    // cout <<  c<< endl;

}

Measured memory_bytes: 3640
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <set>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstdio>
#include <cstring>
#include <iterator>
#include <bitset>
#include <unordered_set>
#include <unordered_map>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <utility>
#include <memory>
#include <functional>
#include <deque>
#include <cctype>
#include <ctime>
#include <numeric>
#include <list>
#include <iomanip>

#if __cplusplus >= 201103L
#include <array>
#include <tuple>
#include <initializer_list>
#include <forward_list>

#define cauto const auto&
#else

#endif

using namespace std;


typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;

#define VV(T) vector<vector< T > >

template <class T>
void initvv(vector<vector<T> > &v, int a, int b, const T &t = T()){
    v.assign(a, vector<T>(b, t));
}

template <class F, class T>
void convert(const F &f, T &t){
    stringstream ss;
    ss << f;
    ss >> t;
}

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define reep(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) reep((i),0,(n))
#define ALL(v) (v).begin(),(v).end()
#define PB push_back
#define F first
#define S second
#define mkp make_pair
#define RALL(v) (v).rbegin(),(v).rend()
#define DEBUG
#ifdef DEBUG
#define dump(x)  cout << #x << " = " << (x) << endl;
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
#else
#define dump(x) 
#define debug(x) 
#endif

#define MOD 1000000007LL
#define EPS 1e-8
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3fLL
#define maxs(x,y) x=max(x,y)
#define mins(x,y) x=min(x,y)

void mainmain(){
	int n;
	cin>>n;
	vll v(3*n);
	rep(i,3*n) cin>>v[i];
	sort(ALL(v));
	ll ans = 0;
	rep(i,v.size()){
		if(i<n) continue;
		if((i-n)%2==0){
			ans += v[i];
		}
	}
	cout<<ans<<endl;
}


signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout<<fixed<<setprecision(20);
    mainmain();
}

Measured memory_bytes: 2560
a = []
a.append(list(map(int, input().split())))
a.append(list(map(int, input().split())))
a.append(list(map(int, input().split())))
c = [[False] * 3 for i in range(3)]
n = int(input())
for i in range(n):
    b = int(input())
    ok = False
    for j in range(3):
        for k in range(3):
            if a[j][k] == b:
                c[j][k] = True
                ok = True
                break
        if ok:
            break
if c[0][0] == c[0][1] == c[0][2] == True or c[1][0] == c[1][1] == c[1][2] == True or c[2][0] == c[2][1] == c[2][2] == True or c[0][0] == c[1][0] == c[2][0] == True or c[0][1] == c[1][1] == c[2][1] == True or c[0][2] == c[1][2] == c[2][2] == True or c[0][0] == c[1][1] == c[2][2] == True or c[0][2] == c[1][1] == c[2][0] == True:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 3064
N, M = map(int, input().split())
p = [None]*M
S = [None]*M
for i in range(M):
  p[i], S[i] = input().split()

ac_flag = [0]*N
wa_count = [0]*N

penalty = 0
for i in range(M):
  j = int(p[i])-1
  if S[i] == 'AC':
    if ac_flag[j]:
      pass
    else:
      ac_flag[j] = 1
      penalty += wa_count[j]
  else:
    wa_count[j] += 1
print(*[sum(ac_flag), penalty])

Measured memory_bytes: 17268