akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>

int main(void){
    char s[16];
    while(scanf("%s",s) != EOF){
        if((s[0] == s[1] && s[1] == s[2]) || (s[0] == s[4] && s[4] == s[8]) || (s[0] == s[3] && s[3] == s[6])){
            if(s[0] != 's'){
                printf("%c\n",s[0]);
                continue;
            }
        }
        if(s[1] == s[4] && s[4] == s[7]){
            if(s[1] != 's'){
                printf("%c\n",s[1]);
                continue;
            }
        }
        if((s[2] == s[5] && s[5] == s[8]) || (s[2] == s[4] && s[4] == s[6])){
            if(s[2] != 's'){
                printf("%c\n",s[2]);
                continue;
            }
        }
        if(s[3] == s[4] && s[4] == s[5]){
            if(s[3] != 's'){
                printf("%c\n",s[3]);
                continue;
            }
        }
        if(s[6] == s[7] && s[7] == s[8]){
            if(s[6] != 's'){
                printf("%c\n",s[6]);
                continue;
            }
        }
        printf("d\n");
    }
    return 0;
}

Measured memory_bytes: 552
#include<iostream>
#include<vector>
#include<queue>
#include<cassert>
using namespace std;

vector<int> P;

inline void init()
{
  int N;
  cin >> N;
  P.resize(N);
  for(int i = 0; i < N; ++i) P[i] = i;
}

inline int root(int a)
{
  if(P[a] == a) return a;
  return (P[a] = root(P[a]));
}

inline int same(int a, int b)
{
  bool ok = root(a) == root(b);
  return ok? 1:0;
}

inline void unite(int a, int b)
{
  P[root(a)] = root(b);
}

int main()
{
  int Q,order,a,b;
  queue<int> answer;
  init();
  cin >> Q;
  for(int i = 0; i < Q; ++i){
    cin >> order;
    assert(order == 0 || order == 1);
    cin >> a >> b;
    order == 0 ? unite(a,b) : answer.push(same(a,b));
  }
  while(!answer.empty()){
    cout << answer.front() << endl;
    answer.pop();
  } 
}

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

#define rep(i,n) for(i = 0;i < n;++i)
#define all(v) v.begin(), v.end()
using ll = long long;

int main()
{
    ll i,j;
    ll n;
    cin >> n;
    vector<ll> a(n);
    for(i = 0;i < n;++i){
        cin >> a.at(i);
    }
    vector<ll> b(n);
    for(i = 0;i < n;++i){
        b.at(a.at(i)-1) = i;
    }
    ll maxlen = 0;
    ll l = 1;
    for(i = 0;i < n-1;++i){
        if(b.at(i) < b.at(i+1)) ++l;
        else{
            maxlen = max(maxlen, l);
            l = 1;
        }
    }
    maxlen = max(maxlen, l);
    cout << n - maxlen << endl;

    return 0;
}

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

using namespace std;

void solve(int N, vector<int> &xs, vector<int> &ys, vector<int> &hs)
{
  int sample;
  for (int i = 0; i < N; i++) {
    if (hs.at(i) > 0) {
      sample = i;
    }
  }

  for (int cx = 0; cx <= 100; cx++) {
    for (int cy = 0; cy <= 100; cy++) {
      int H = hs.at(sample) + abs(xs.at(sample) - cx) + abs(ys.at(sample) - cy);
      bool ok = true;
      for (int i = 0; i < N; i++) {
        int h = hs.at(i) + abs(xs.at(i) - cx) + abs(ys.at(i) - cy);
        if (hs.at(i) == 0) {
          if (H > h) {
            ok = false;
            break;
          }
        } else {
          if (H != h) {
            ok = false;
            break;
          }
        }
      }
      if (ok) {
        cout << cx << " " << cy << " " << H << endl;
      }
    }
  }
}

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

  vector<int> xs(N, 0);
  vector<int> ys(N, 0);
  vector<int> hs(N, 0);

  for(int i = 0; i < N; i++) {
    cin >> xs.at(i);
    cin >> ys.at(i);
    cin >> hs.at(i);
  }

  solve(N, xs, ys, hs);

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define inf 1000000000
#define INF 1000000000000000
#define ll long long
#define ull unsigned long long
#define M 1000000007
#define P pair<int,int>
#define PLL pair<ll,ll>
#define FOR(i,m,n) for(int i=(int)m;i<(int)n;i++)
#define RFOR(i,m,n) for(int i=(int)m;i>=(int)n;i--)
#define rep(i,n) FOR(i,0,n)
#define rrep(i,n) RFOR(i,n,0)
#define all(a) a.begin(),a.end()
#define IN(a,n) rep(i,n){ cin>>a[i]; }
const int vx[4] = {0,1,0,-1};
const int vy[4] = {1,0,-1,0};
#define PI 3.14159265
#define F first
#define S second
#define PB push_back
#define int ll

int n,m;
string s,t;


signed main(){
  cin>>n>>m;
  cin>>s>>t;

  int k = n*m/__gcd(n,m);

  int i=0,j=0;
  bool flag = true;

  while(i!=n&&j!=m){
    if(i*k/n==j*k/m){
      if(s[i]!=t[j]) 
        flag = false;
    }
    if(i*k/n>j*k/m) j++;
    else i++;
  }

  if(flag){
    cout<<k<<endl;
  }
  else{
    cout<<-1<<endl;
  }
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define pb push_back
#define pf push_front
#define mt make_tuple
#define popb pop_back
#define popf pop_front
#define int long long int
#define vi         vector<int>
#define vll        vector<ll>
#define vpii       vector<pair<int,int>>
#define vpll       vector<pair<ll,ll>>
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define sz(container) int((container).size())
#define rep(i,a,b) for(i=a;i<b;i++)
#define tr(container,it)   for(auto it = container.begin(); it != container.end(); it++)
#define present(container, element) (container.find(element) != container.end())      //set,map etc.
#define cpresent(container, element) (find(all(container),element) != container.end())    //vector
#define hell 1000000007
#define PI 3.14159265
#define mod 998244353
#define fs first
#define sc second
#define TIME        cerr << "\nTime elapsed: " << setprecision(5) <<1000.0 * clock() / CLOCKS_PER_SEC << "ms\n";
int maxi(int a, int b, int c)
{return max(a,max(b,c));}
void solve()
{
 int n,w,i,j,k;
 cin>>n>>w;
 int wgt[n],val[n];
 rep(i,0,n)cin>>wgt[i]>>val[i];
 int dp[n+1][w+1];
 rep(i,0,n+1)
 rep(j,0,w+1)
 dp[i][j]=0;
 for(i=1;i<=n;i++)
 {
  for(j=0;j<=w;j++)
  {
    dp[i][j]=dp[i-1][j];
    if(j-wgt[i-1]>=0)
      dp[i][j]=max(dp[i][j],dp[i-1][j-wgt[i-1]]+val[i-1]);
  }
 }
 cout<<dp[n][w];
}
signed main()
{
  fastio
  //freopen("input.txt", "r", stdin);
  //freopen("output.txt", "w", stdout);
  int t;
  t=1;
  //cin>>t;
  while(t--)
  solve();
  TIME
  return 0;
}

Measured memory_bytes: 79232
#include <bits/stdc++.h>
#include <boost/range/algorithm.hpp>
#include <boost/range/numeric.hpp>
#include <boost/range/irange.hpp>
#include <boost/range/adaptor/indexed.hpp>

using namespace std;
using namespace boost::adaptors;
using namespace std::string_literals;
using ll = int64_t;
using vecint = vector<int>;
using vecll = vector<ll>;
using boost::irange;

ll solve(ll x) {
  if (x == 1) {
    return 1;
  } else {
    ll h = solve(x / 2);
    return 2*h+1;
  }
}

int main()
{
  ll h;
  cin>>h;
  cout<<solve(h)<<endl;
  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>

#define M 1046527
#define L 14
#define NIL -1

char H[M][L]; /* Hash Table */

int getChar(char ch) {
	if ( ch == 'A') return 1;
	else if ( ch == 'C') return 2;
	else if ( ch == 'G') return 3;
	else if ( ch == 'T') return 4;
}

/* convert a string into an integer value */
long long getKey(char str[]) {
	long long sum = 0, p = 1, i;
	for ( i = 0; i < strlen(str); i++ ) {
		sum += p*(getChar(str[i]));
		p *= 5;
	}
	return sum;
}

int h1(int key) {
	return key%M;
}
int h2(int key) {
	return 1+(key%(M-1));
}

int find(char str[]) {
	long long key,i,h;
	key=getKey(str);
	for(i=0;; i++) {
		h=(h1(key)+i*h2(key))%M;
		if(strcmp(H[h],str)==0)return 1;
		else if(strlen(H[h])==0) return 0;
	}
	return 0;
}

int insert(char str[]) {

	long long key,i,h;
	key=getKey(str);
	for(i=0;; i++) {
		h=(h1(key)+i*h2(key))%M;
		if(strcmp(H[h],str)==0)return 1;
		else if(strlen(H[h])==0) {
			strcpy(H[h],str);
			return 0;
		}
	}
	return 0;
}

int main() {
	int i, n, h;
	char str[L], com[9];
	for ( i = 0; i < M; i++ ) H[i][0] = '\0';

	scanf("%d", &n);

	for ( i = 0; i < n; i++ ) {
		scanf("%s %s", com, str);

		if ( com[0] == 'i' ) {
			insert(str);
		} else {
			if (find(str)) {
				printf("yes\n");
			} else {
				printf("no\n");
			}
		}
	}

	return 0;
}


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

int main() {
    ll n; 
    cin >> n;
    ll ans = 0;
    ld t, a;
    cin >> t >> a;
    ld mini = INT_MAX;
    for (int i = 1; i <= n; ++i) {
        ld x; 
        cin >> x;
        if(abs(a - (t - x * 0.006)) < mini) {
            ans = i;
            mini = abs(a - (t - x * 0.006));
        }
    }
    cout << ans;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <numeric>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;
const ll MAX_N = 100010;
 
int main() {
    ll n, m;
    cin >> n >> m;
    ll N = 1<<n;

    vl a(m);
    vector<P> v(m);
    rep(i, m) {
        ll b;
        cin >> a[i] >> b;
        ll s = 0;
        rep(j, b) {
            ll c;
            cin >> c;
            c--;
            s |= 1<<c;
        }
        v[i] = make_pair(a[i], s);
    }

    vl dp(N, INF);  // dp[s] : 宝箱の集合Sを開けるのに必要な費用の最小値
    dp[0] = 0;
    rep(s, N) {
        rep(i, m) {
            chmin(dp[s | v[i].second], dp[s] + v[i].first);
        }
    }
    
    if(dp[N-1] == INF) {
        out(-1);
    }
    else {
        out(dp[N-1]);
    }
    
    re0;
}

Measured memory_bytes: 256
n = int(input())
s = input()

w_sum, e_sum = [0] * n, [0] * n

for i, item in enumerate(s):
    if i == 0:
        continue
    if s[i-1] == "W":
        w_sum[i] = w_sum[i-1] + 1
    else:
        w_sum[i] = w_sum[i-1]

s = s[::-1]

for i, item in enumerate(s):
    if i == 0:
        continue
    if s[i-1] == "E":
        e_sum[i] = e_sum[i-1] + 1
    else:
        e_sum[i] = e_sum[i-1]

e_sum = e_sum[::-1]
ans = float("inf")

for i, item in enumerate(s):
    ans = min(ans, e_sum[i] + w_sum[i])

print(ans)


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

int main() {
  int N;
  cin >> N;
  vector<char> S(N);
  vector<char> T(N);
  for(int i = 0; i < N; i++){
    cin >> S.at(i);
  }
  for(int i = 0; i < N; i++){
    cin >> T.at(i);
  }
  
  for(int i = 0; i < N; i++){
    cout << S.at(i) << T.at(i);
  }
  cout << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define rep1(i,n) for(int i=1;i<=(int)n;i++)
typedef long long ll;
using namespace std;
int main(){
    int n;cin>>n;
    map<string,int> mp;
    int maxi=0;
    rep(i,n){
        string s;cin>>s;
        mp[s]++;
        maxi=max(maxi,mp[s]);
    }
    vector<string> st;
    for(auto& p : mp){
        if(p.second==maxi){
            st.push_back(p.first);
        }
    }
    sort(st.begin(),st.end());
    rep(i,st.size()) cout<<st[i]<<endl;
}

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

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

#define YES puts("YES")
#define Yes puts("Yes")
#define NO  puts("NO")
#define No  puts("No")
#define ALL(v) (v).begin(), (v).end()
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
 
 
 
#if 1
//-------------
// DUMPマクロ
// https://www.creativ.xyz/dump-cpp-652/

#define repi(itr, ds) for (auto itr = ds.begin(); itr != ds.end(); itr++)

// vector
template <typename T>
istream& operator>>(istream& is, vector<T>& vec) {
    for (T& x : vec) is >> x;
    return is;
}
// pair
template <typename T, typename U>
ostream& operator<<(ostream& os, pair<T, U>& pair_var) {
    os << "(" << pair_var.first << ", " << pair_var.second << ")";
    return os;
}
// vector
template <typename T>
ostream& operator<<(ostream& os, const vector<T>& vec) {
    os << "{";
    for (int i = 0; i < vec.size(); i++) {
        os << vec[i] << (i + 1 == vec.size() ? "" : ", ");
    }
    os << "}";
    return os;
}
// map
template <typename T, typename U>
ostream& operator<<(ostream& os, map<T, U>& map_var) {
    os << "{";
    repi(itr, map_var) {
        os << *itr;
        itr++;
        if (itr != map_var.end()) os << ", ";
        itr--;
    }
    os << "}";
    return os;
}
// set
template <typename T>
ostream& operator<<(ostream& os, set<T>& set_var) {
    os << "{";
    repi(itr, set_var) {
        os << *itr;
        itr++;
        if (itr != set_var.end()) os << ", ";
        itr--;
    }
    os << "}";
    return os;
}
 
#define DUMPOUT cerr
 
void dump_func() {
    DUMPOUT << endl;
}
template <class Head, class... Tail>
void dump_func(Head&& head, Tail&& ... tail) {
    DUMPOUT << head;
    if (sizeof...(Tail) > 0) {
        DUMPOUT << ", ";
    }
    dump_func(std::move(tail)...);
}
#ifdef DEBUG
#define DEB
#define dump(...)                                                              \
    DUMPOUT << "  " << string(#__VA_ARGS__) << ": "                            \
            << "[" << to_string(__LINE__) << ":" << __FUNCTION__ << "]"        \
            << endl                                                            \
            << "    ",                                                         \
        dump_func(__VA_ARGS__)
#else
#define DEB if (false)
#define dump(...)
#endif

// http://beet-aizu.hatenablog.com/entry/2018/04/08/145516
template<typename T>
vector<T> make_v(size_t a){return vector<T>(a);}

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

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

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

#endif


#define mod 1000000007
typedef pair<int, int> P;
#define INF (1LL<<60)

void solve(){

    int N, M;
    cin >> N >> M;
    
    cout << N*(N-1)/2 + M*(M-1)/2 << endl;

}

signed main(){
    cout << fixed << setprecision(18);
    cerr << fixed << setprecision(18);
    solve();
}


Measured memory_bytes: 256
#include<iostream>
#include <algorithm>
#include <functional>
#include<vector>
#include<math.h>
#include<bitset>
#include<string>
#include <deque>
#include<queue>
#include <iomanip>
#include<map>
#include <random>
#include<type_traits>
#include<stack>
#include <sstream> 
#include <limits>
#include <numeric>
#include<string.h>
using namespace std;
#define ll long long int
#define all(v) begin(v), end(v)
#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define reps(i, s, n) for(int i = (int)(s); i < (int)(n); i++)
//typedef vector<int> V;
//typedef vector<VV> VVV;

template<typename T>
void remove(std::vector<T>& vector, unsigned int index)
{
	vector.erase(vector.begin() + index);
}
long long int ss[200006];

int main() {
	long long int n, count = 200000000;
	string s;
	cin >> n >> s;
	if (s[0] == '#')ss[0] = 1;
	for (long long int i = 1; i < n; i++) {
		if (s[i] == '#') {
			ss[i] = ss[i - 1] + 1;
		}
		else {
			ss[i] = ss[i - 1];
		}
	}

	count = min(count, ss[n - 1]);
	for (int i = 1; i < n; i++) {
		count = min((n-i)-(ss[n - 1] - ss[i-1]) + ss[i-1], count);
		//cout << "i" << i <<" "<< count << endl;
	}
	cout << min(count, n - ss[n - 1]) << endl;
}


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

struct Edge {
	int src, dst;
	Edge() : src(0), dst(0) {}
	Edge(int s, int d) : src(s), dst(d) {}
};
using Edges = std::vector<Edge>;
using Graph = std::vector<Edges>;

vector<int> kosaraju(const Graph &g) {
	int n = g.size(), sz = 0; Graph rg(n);
	vector<int> stk, cmp(n, -1), added(n), visited(n), ord(n);
	for(auto &es : g) {
		sz += es.size();
		for(const Edge &e : es) rg[e.dst].emplace_back(e.dst, e.src);
	}
	stk.resize(n + sz); sz = 0;
	for(int i = 0; i < n; i++) {
		if(visited[i]) continue;
		int s = 0; stk[s++] = i;
		while(s != 0) {
			int v = stk[s - 1]; visited[v] = true;
			bool pushed = false;
			for(auto &e : g[v]) {
				int dst = e.dst;
				if(!visited[dst]) { stk[s++] = dst; pushed = true; }
			}
			if(pushed) continue;
			int t = stk[s - 1];
			if(!added[t]) { added[t] = true; ord[n - ++sz] = t; }
			--s;
		}
	}
	int k = 0;
	for(int &u : ord) {
		if(cmp[u] != -1) continue;
		int s = 0; stk[s++] = u;
		while(s != 0) {
			int v = stk[--s]; cmp[v] = k;
			for(auto &e : rg[v]) {
				int d = e.dst;
				if(cmp[d] == -1) stk[s++] = d;
			}
		}
		++k;
	}
	return cmp;
}

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

	int V, E, Q;
	cin >> V >> E;

	Graph G(V);
	for(int i = 0; i < E; i++) {
		int u, v;
		cin >> u >> v;
		G[u].push_back({ u, v });
	}

	auto res = kosaraju(G);
	cin >> Q;
	while(Q--) {
		int u, v;
		cin >> u >> v;
		cout << (res[u] == res[v]) << endl;
	}
}

Measured memory_bytes: 4364
#define _USE_MATH_DEFINES
#include  <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <string>
#include<math.h>
#include<iomanip>
#include<stdio.h>
#include <stdlib.h>
#include<stdio.h>
#include <queue>
#include<map>
#include <sstream>
#include<set>
#include<stack>

//#include<bits/stdc++.h>


using namespace std;



int main() {

	long long int n;
	vector<long long int>t(5);
	cin >> n;
	for (int i = 0; i < 5; i++)cin >> t[i];

	sort(t.begin(), t.end());
	long long int r = n / t[0];
	if (n%t[0])r++;
	cout << r + 4 << endl;

	return 0;

}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <stdbool.h>
#include <string.h>
#include <math.h>


int main(){
  int a,b,i,n,x=0;
  int h[10001]={};
  scanf("%d",&n);
  for(i=1;i<=n;i++){
    scanf("%d",&h[i]);
    while(h[i]%2==0){
      h[i]=h[i]/2;
      x++;
    }
  }
  printf("%d",x);
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int N=20003;

  int n;
  int a[N],b[N];
int main()
{
  cin>>n;
  for (int i=0;++i<=n;)
    a[i]=a[i-1]+N,
		b[i]=N*N;
  for (int i=0;++i<=n;)
    {
      int x;
      cin>>x;
      b[x]-=n-i+1+a[x];
    }
  for (int i=0;++i<=n;)
    printf("%d ",a[i]);
  puts("");
  for (int i=0;++i<=n;)
    printf("%d ",b[i]);
  exit(0);
}

Measured memory_bytes: 768
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define dunk(n) cout << n << endl
#define all(v) v.begin(), v.end()


int main() {
    int n,x,y;
    cin >> n >> x >> y;
    x--; y--;
    
    vector<int> dist(n);
    
    for(int i = 0; i < n-1; i++){
        for(int j = i+1; j < n; j++){
            dist.at(min(abs(i-j),abs(x-i)+abs(y-j)+1))++;
        }
    }
    
    for(int i = 1; i <= n-1; i++) dunk(dist.at(i));
    
    return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n,m=0,k;
	cin>>n;
	for(int i=1;i<=n;i++){
		cin>>k;
		if(i%2&&k%2) m++;
	}
	cout<<m<<endl;
	return 0;
}


Measured memory_bytes: 3524
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define fi first
#define se second
#define itrfor(itr,A) for(auto itr = A.begin(); itr !=A.end();itr++)
template <class T> using reversed_priority_queue = priority_queue<T, vector<T>, greater<T> >;
typedef long long llong;
char moji[26]={'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
char moji2[26]={'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};
char moji3[10]={'0','1','2','3','4','5','6','7','8','9'};
#define Sort(a) sort(a.begin(),a.end());
#define Reverse(a) reverse(a.begin(),a.end());
#define print(a) cout << a << endl;
#define MAX int( 1e5 +5)


int main(){
    int n,w;
    cin >> n >> w;
    llong ans[MAX];
    REP(i,w+1) ans[i] = 0;


    REP(i,n){
        int tmpw;
        llong v;
        scanf("%d%lld",&tmpw,&v); 
        REPR(i,w - tmpw ){
            if(ans[i] !=0){
                ans[i + tmpw] = max(ans[i + tmpw] ,ans[i] + v);
            }
        }
        ans[tmpw] = max(ans[tmpw],v);
    }
    llong res = 0;
    REP(i,w+1){
        if(res < ans[i]) res = ans[i];
    }
    cout << res << endl;
}

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

using namespace std;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    string s;
    cin >> s;
    int first = stoi(s.substr(0, 2));
    int second = stoi(s.substr(2));
    auto is_month = [&](int k) { return 1 <= k && k <= 12; };
    if (is_month(first)) {
        cout << (is_month(second) ? "AMBIGUOUS" : "MMYY") << endl;
    } else {
        cout << (is_month(second) ? "YYMM" : "NA") << endl;
    }
    return 0;
}


Measured memory_bytes: 384
n,m=map(int,input().split())
abc=[]
for i in range(m):
    abc.append([int(j) for j in input().split()])
b=[float("INF")]*(n+1)
b[1]=0
for i in range(1,n+1):
    for s,t,u in abc:
        if b[t]>b[s]-u:
            b[t]=b[s]-u
            if i==n and t==n:
                print("inf")
                exit()
print(-b[-1])

Measured memory_bytes: 3444
#include <bits/stdc++.h>
using namespace std;
#define INF 1<<30
#define endl '\n'
#define maxn 100005
#define tc printf("Case %d: ", cs)
#define tcn printf("Case %d:\n", cs);
#define FASTIO ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
typedef long long ll;
const double PI = acos(-1.0);

#define dbg1(x) cerr << #x << " = " << x << endl;
#define dbg2(x, y) cerr << #x << " = " << x << ", " << #y << " = " << y << endl;
#define dbg3(x, y, z) cerr << #x << " = " << x << ", " << #y << " = " << y << ", " << #z << " = " << z << endl;
#define dbg4(w,x, y, z) cerr << #w << " = " << w << ", " <<#x << " = " << x << ", " << #y << " = " << y << ", " << #z << " = " << z << endl;

template < typename F, typename S >
ostream& operator << ( ostream& os, const pair< F, S > & p ) {
	return os << "(" << p.first << ", " << p.second << ")";
}

template < typename T >
ostream &operator << ( ostream & os, const vector< T > &v ) {
	os << "{";
	for (auto it = v.begin(); it != v.end(); ++it) {
		if ( it != v.begin() ) os << ", ";
		os << *it;
	}
	return os << "}";
}

template < typename T >
ostream &operator << ( ostream & os, const set< T > &v ) {
	os << "[";
	for (auto it = v.begin(); it != v.end(); ++it) {
		if ( it != v.begin()) os << ", ";
		os << *it;
	}
	return os << "]";
}

template < typename F, typename S >
ostream &operator << ( ostream & os, const map< F, S > &v ) {
	os << "[";
	for (auto it = v.begin(); it != v.end(); ++it) {
		if ( it != v.begin() ) os << ", ";
		os << it -> first << " = " << it -> second ;
	}
	return os << "]";
}

#define dbg(args...) do {cerr << #args << " : "; faltu(args); } while(0)

clock_t tStart = clock();
#define timeStamp dbg("Execution Time: ", (double)(clock() - tStart)/CLOCKS_PER_SEC)

void faltu () { cerr << endl; }

template <typename T>
void faltu( T a[], int n ) {
	for (int i = 0; i < n; ++i) cerr << a[i] << ' ';
	cerr << endl;
}

template <typename T, typename ... hello>
void faltu( T arg, const hello &... rest) { cerr << arg << ' '; faltu(rest...); }
// Program showing a policy-based data structure.
#include <ext/pb_ds/assoc_container.hpp> // Common file 
#include <ext/pb_ds/tree_policy.hpp>
#include <functional> // for less 
#include <iostream>
using namespace __gnu_pbds;
using namespace std;
// GNU link : https://goo.gl/WVDL6g
typedef tree<int, null_type, less_equal<int>, rb_tree_tag,
        tree_order_statistics_node_update>
        new_data_set;

/**___________________________________________________**/

map<ll, ll>mp;

int main()
{
	//FASTIO
	///*
// #ifndef ONLINE_JUDGE
// 	freopen("in.txt", "r", stdin);
// 	freopen("out.txt", "w", stdout);
// 	freopen("error.txt", "w", stderr);
// #endif
//*/
	ll n, k, q;
	cin >> n >> k >> q;
	for (int i = 0; i < q; i++) {
		ll x;
		cin >> x;
		mp[x]++;
	}
	for (int i = 1; i <= n; i++) {
		dbg(k - (q - mp[i]));
		if (k - (q - mp[i]) > 0)printf("Yes\n");
		else printf("No\n");
	}
	return 0;
}

Measured memory_bytes: 6912
#![allow(non_snake_case)]

fn read_line() -> String {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().to_string()
}

fn read_int_tuple() -> (i32, i32) {
    let v: Vec<i32> = read_line().split_whitespace().map(|a| a.parse().unwrap()).collect();
    (v[0], v[1])
}

fn main() {
    let (N, K) = read_int_tuple();
    let h: Vec<i32> = read_line().split_whitespace().map(|a| a.parse().unwrap()).collect();
    let mut count = 0;
    for i in h {
        if i >= K {
            count += 1;
        }
    }
    println!("{}", count);
}


Measured memory_bytes: 4352
#include "bits/stdc++.h"
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size)
#define MOD 1000000007
const long long mod = 1e9+7;
typedef vector<long long> Vl;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<Vl> VVl;
typedef pair<int, int> PII;
typedef long long ll;

int main(){
    int a=0,b=0,c=0,d,n=0,x=0;
    VI m(3);
    string s,s1,s2;
    cin >> a; 
    if(a==3||a==5||a==7)
        cout << "YES" <<endl;
    else  cout << "NO" <<endl;
    return 0;
} 

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

int main(){
  int n;
  cin>>n;
  long cnt=0;
  for(int i=1;i<n+1;i++){
    if(n%i==0){
      cnt+=(n/i)-1;
    }else{
      cnt+=(n/i);
    }
  }
  cout<<cnt;
}

Measured memory_bytes: 3632
// #include <ext/pb_ds/assoc_container.hpp> 
//#include <ext/pb_ds/tree_policy.hpp>
#include <iostream>
#include <iomanip>
#include <sstream>
#include <cstring>
#include <vector>
#include <deque>
#include <queue>
#include <set>
#include <map>
#include <valarray>
#include <iterator>
#include <functional>
#include <limits>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <cassert>
#include <unordered_map>
#include <unordered_set>
#include <stack>
using namespace std;
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define trace(x) cerr << #x << ": " << x << " " << endl;
 
typedef int64_t ll;
 
#define endl '\n'
#define int ll
ll mod=1e9+7;
ll mod1=1e9+5;
ll power(ll a,ll b)
{
    if(b==0) return 1;
    else if(b%2==0)
        return power(((((a)%mod)*((a)%mod))%mod),b/2)%mod;
    else return (((a)%mod)*(power(((((a)%mod)*((a)%mod))%mod),b/2)%mod))%mod;
}
inline ll inverse(ll a,ll md) {
  a %= md;
  if (a < 0) a += md;
  ll b = md, u = 0, v = 1;
  while (a) {
    ll t = b / a;
    b -= t * a; swap(a, b);
    u -= t * v; swap(u, v);
  }
  assert(b == 1);
  if (u < 0) u += md;
  return u;
}
  
  
 //using namespace __gnu_pbds;
 //#define ordered_set tree<pair<int,int>, null_type,less<pair<int,int>>, rb_tree_tag,tree_order_statistics_node_update>
//find_by_order(k)  returns iterator to kth element starting from 0;
//order_of_key(k) returns count of elements strictly smaller than k;
//erase,insert same as normal set
// mt19937 mrand(chrono::high_resolution_clock::now().time_since_epoch().count()); for randomized solution
const int ce=1e9+7;
ll fast_mod(ll input)
{
    return input < ce ? input : input%ce;
}
#define pi 3.14159
pair<int,int> a[2001];
int n;
int dp[2001][2001];
int solve(int l,int r)
{
	if(l>r)
		return 0;
	if(l==r)
	{
		return a[n].first*abs(a[n].second-l);
	}
	int &res=dp[l][r];
	if(res!=-1)
		return res;
	res=0;
	int in=n-(r-l+1)+1;
	res=max(res,a[in].first*abs(a[in].second-l)+solve(l+1,r));
	res=max(res,a[in].first*abs(a[in].second-r)+solve(l,r-1));
	return res;
}
int32_t main()
{
    IOS
   
	
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		int x;
		cin>>x;
		a[i].first=x;
		a[i].second=i;
	}
	sort(a+1,a+n+1);
	reverse(a+1,a+n+1);
	memset(dp,-1,sizeof(dp));
	cout<<solve(1,n);

}       

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

int main() {
    int n, x;
    int m[110];
    cin >> n >> x;
    int min = 1100;
    for(int i = 0; i < n; ++i) {
        cin >> m[i];
        if(min > m[i]) min = m[i];
    }
    
    for(int i = 0; i < n; ++i) x -= m[i];
    
    cout << n + x / min << endl;
}


Measured memory_bytes: 256
import java.util.*;
import java.util.Arrays;
import java.lang.Math;
 
public class Main{
        public static void main(String[] args){
                Scanner scanCnt = new Scanner(System.in);
                int N = scanCnt.nextInt();
                int Array[] = new int[N];
                int sum =0;
                for(int i = 0 ; i < N ; i++ ){
                        Array[i]=scanCnt.nextInt();
                        sum += Array[i];
                }
 
                Arrays.sort(Array);
                int max = Array[N-1];
 
                if(max<sum-max){
                        System.out.println("Yes");
                }else{
                        System.out.println("No");
                }
        }
}

Measured memory_bytes: 22740
#include<stdio.h>

int main(void){
  int i;
  char c;
  
  scanf("%c",&c);
    
  if((c >= 'A')&&(c <= 'Z')){
    printf("A");
  }
  else if((c >= 'a')&&(c <= 'z')){
    printf("a");
  }
  
  return 0;
  
}

Measured memory_bytes: 1596
#include <iostream>
#include <cstdlib>
#include <vector>
#include <string>
#include <algorithm>

using namespace std;

int main()
{
    int n, m;
    cin >> n;
    vector <long long> a(n);
    vector <long long> b;
    vector <long long> c, d, e;
    long long ans, ans1, ans2, ans3, ans4;
    ans = 0;
    ans1 = 0;
    ans2 = 0;
    ans3 = 0;
    ans4 = 0;
    for (int i=0; i<n; ++i){
        cin >> a[i];
    }
    sort(a.begin(), a.end());
    if(n % 2 == 1){
        m = n / 2;
        b.push_back(a[m]);
        c.push_back(a[m]);
        for(int i=0; i<m; ++i){
            b.push_back(a[n-1-i]);
            b.push_back(a[i]);
            c.push_back(a[i]);
            c.push_back(a[n-1-i]);
        }
        //for(int i=0; i<n; ++i){
        //    cout << c[i] << endl;
        //}
        for (int i=0; i<n-1; ++i){
            ans1 += llabs(b[i+1]-b[i]);
            ans2 += llabs(c[i+1]-c[i]);
        }
        if(ans1 >= ans2){
            ans = ans1;
        }
        else {
            ans = ans2;
        }
    }
    else {
        m = n / 2 - 1;
        b.push_back(a[m]);
        c.push_back(a[m+1]);
        d.push_back(a[m+1]);
        e.push_back(a[m]);
        for(int i=0; i<m; ++i){
            b.push_back(a[n-1-i]);
            b.push_back(a[i]);
            c.push_back(a[i]);
            c.push_back(a[n-1-i]);
            d.push_back(a[n-1-i]);
            d.push_back(a[i]);
            e.push_back(a[i]);
            e.push_back(a[n-1-i]);
        }
        b.push_back(a[m+1]);
        c.push_back(a[m]);
        d.push_back(a[m]);
        e.push_back(a[m+1]);
        for (int i=0; i<n-1; ++i){
            ans1 += llabs(b[i+1]-b[i]);
            ans2 += llabs(c[i+1]-c[i]);
            ans3 += llabs(d[i+1]-d[i]);
            ans4 += llabs(e[i+1]-e[i]);
        }
        ans = max(ans1, ans2);
        ans = max(ans, ans3);
        ans = max(ans, ans4);
        ans = max(ans, ans1);
    }
    cout << ans << endl;
}



Measured memory_bytes: 4312
package main

import (
  "fmt"
)

func main() {
  var (
    n,m,a,b,ans int
  )
  fmt.Scan(&n)
  fmt.Scan(&m)
  h := make([]int64, n)
  for i:=0; i<n; i++ {
    fmt.Scan(&h[i])
  }
  p := make([]int, n)
  for c:=0; c<n; c++ {
    p[c] = 1
  }

  for j:=0; j<m; j++ {
    fmt.Scan(&a)
    fmt.Scan(&b)
    a--
    b--
    if h[a] < h[b] {
      p[a] = 0
    } else if h[b] < h[a]{
      p[b] = 0
    } else {
      p[a],p[b] = 0,0
    }
  }
  for _, x := range p {
    ans += x
  }
  fmt.Println(ans)
}


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

int main(){
  int N, K;
  cin >> N >> K;
  string S;
  cin >> S;
  int c = 0;
  int cp = 0;
  int last = 0;
  string cl = "N";
  char pre;
  char now = S[0];
  for(int i = 0; i < N-1; i++){
    pre = now;
    now = S[i+1];
    if(pre == now){
      c++;
    }
    else{
      if(cl == "N") cl = pre + now;
      else if(cl[0] == pre);
      else{
        cl = "N";
        cp++;
      }//if2
    }//if1
    if(i == N-2){
      if(cl != "N") last++;
    }
  }//fori
  int act = min(K,cp);
  if(act == K) last = 0;
  int ans = c + 2*act + last;
  cout << ans << endl;
}

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

using namespace std;
const int MAXN = 200005;
const int MOD = 1000000007;

int n,arr[MAXN];
int dp[MAXN][2];


int main(){
	ios_base::sync_with_stdio(false); cin.tie(0);
	cin >> n;
	for(int i=1;i<=n;i++) cin >> arr[i];
	dp[1][0] = dp[1][1] = 1;
	for(int i=2;i<=n;i++){
		dp[i][0] = dp[i][1] = MAXN;
		if(arr[i] <= arr[i-1]) dp[i][1] = dp[i-1][1];
		if(arr[i] >= arr[i-1]) dp[i][0] = dp[i-1][0];
		dp[i][0] = min(dp[i][0], min(dp[i-1][0],dp[i-1][1]) + 1 );
		dp[i][1] = min(dp[i][1], min(dp[i-1][0],dp[i-1][1]) + 1 );
	}
	cout << min(dp[n][0],dp[n][1]) << '\n';
	return 0;
}


Measured memory_bytes: 1408
/******************************************
* AUTHOR : kamesh_11 *
* INSTITUTION : GVPCOE *
******************************************/

#include <bits/stdc++.h>
using namespace std;

#define pi 3.141592653589793
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define bs binary_search
#define endl '\n'
#define start_clock clock_t beginn=clock()
#define end_clock clock_t endd=clock()
#define cal_exec_time double time_spent=(double)(endd-beginn)/CLOCKS_PER_SEC
#define print_exec_time cout<<endl<<time_spent<<" secs"

typedef long long int ll;

const ll MOD = 1000000007;
const ll INF = 1e15;

ll powmod(ll a,ll b) {ll res=1;a%=MOD; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%MOD;a=a*a%MOD;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}

ll n, arr[405], pref[405];

ll get(ll L, ll R){
	return pref[R] - pref[L-1];
}

ll find_min(ll i, ll j, vector<vector<ll>>& dp){
	if(i == j)
		return dp[i][j] = 0;

	if(dp[i][j] != -1)
		return dp[i][j];

	ll mini = INF;
	for(ll k=i;k<j;k++){
		ll cnt = get(i, j) + find_min(i, k, dp) + find_min(k+1, j, dp);
		if(cnt < mini)
			mini = cnt;
	}

	return dp[i][j] = mini;
}

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

	cin>>n;
	for(ll i=1;i<=n;i++)
		cin>>arr[i];
	for(ll i=1;i<=n;i++)
		pref[i] = pref[i-1] + arr[i];

	vector<vector<ll>>dp(n+1, vector<ll>(n+1, -1));
	cout<<find_min(1, n, dp);

	return 0;
}

Measured memory_bytes: 1536
#include <bits/stdc++.h>
using namespace std;
int main(){
  string S;
  cin >> S;
  int N = S.size();
  bool ok = true;
  stack<pair<char, int>> st;
  st.push(make_pair('$', 0));
  for (int i = 0; i < N; i++){
    if (S[i] == 'm'){
      st.push(make_pair('m', 0));
    }
    if (S[i] == 'e'){
      if (st.top().first != 'm' || st.top().second >= 2){
        ok = false;
        break;
      }
      st.top() = make_pair('e', 0);
    }
    if (S[i] == 'w'){
      if (st.top().first != 'e' || st.top().second >= 2){
        ok = false;
        break;
      }
      st.pop();
      st.top().second++;
    }
  }
  if (st.top() != make_pair('$', 1)){
    ok = false;
  }
  if (ok){
    cout << "Cat" << endl;
  } else {
    cout << "Rabbit" << endl;
  }
}


Measured memory_bytes: 3220
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> P;
map <int,int> mp;
vector<int> V;
#define debug(x) cerr << #x << ": " << x << "\n";
#define INF (1<<29) //53687091
#define INFLL (1ll<<58)
#define EPS (1e-10)
static const int MAX=1e5;
static const int MOD=1e9+7;
static const int NMAX=50;
static const int MMAX=50;
int dx[4]={0,1,0,-1},dy[4]={-1,0,1,0};
const int tx[8] = { -1,0,1,-1,1,-1,0,1 }, ty[8] = { -1,-1,-1,0,0,1,1,1 };
int N;
ll T,A[MAX+2];

void solve(){
    ll max_delta=-INFLL,cunt=0ll,min_a=INFLL,max_a=-INFLL;
    for(int i=0;i<N;i++){
        min_a = min(min_a,A[i]);
        if(A[i]-min_a > max_delta){
            cunt=1ll;
            max_delta = A[i] - min_a;
        }else if(A[i] - min_a == max_delta) cunt++;
    }
    cout << cunt <<"\n";
}

int main(){
    cin.tie(0);  ios::sync_with_stdio(false);
    cin >> N >> T;
    for(int i=0;i<N;i++) cin >> A[i];
    solve();
    
    return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define rep2(i, a, n) for(ll i = a; i < (ll)(n); i++)
#define memi cout << endl
#define kono(n) cout << fixed << setprecision(n)
#define all(c) (c).begin(), (c).end()
#define pb push_back
#define hina cout << ' '
#define in(n) cin >> n
#define in2(n, m) cin >> n >> m
#define in3(n, m, l) cin >> n >> m >> l
#define out(n) cout << n
const ll mei = (ll)1e9 + 7;

int main(){
  ll s, a;
  in(s);
  vector<ll> c(10000009, 0);
  a = 1;
  c[s]++;
  while(true){
    a++;
    if(s % 2 == 0)
      s = s / 2;
    else
      s = 3 * s + 1;
    c[s]++;
    if(c[s] == 2)
      break;
  }
  out(a);
  memi;
}

Measured memory_bytes: 78336
#include<bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define len(x) (int)(x).size()
#define all(x) (x).begin() , (x).end()
#define rall(x) (x).rbegin() , (x).rend()
#define fast_io ios_base::sync_with_stdio(0) , cin.tie(0) , cout.tie(0)
typedef long long ll;
typedef long double ld;
using namespace std;

signed main(){
    int n;cin>>n;
    map < string , int > cnt;
    int mx = 0;
    while(n--){
        string s;cin >> s;
        cnt[s]++;
        mx = max(mx , cnt[s]);
    }
    for(auto u : cnt){
        if(u.se == mx)cout << u.fi << '\n';
    }
    return 0;
}


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

int main() {
  int n; cin >>n;
  int sn = 0;
  int buf = n;
  string ans = "No";
  for (int i=0; i<10; i++){
    sn += buf % 10;
    buf /= 10;
  }
  if (n%sn==0) ans = "Yes";
  cout <<ans;
  cout <<endl;
}


Measured memory_bytes: 256
use std::io::{self, BufRead, BufWriter, Write};

fn solve<R, W>(reader: R, mut writer: W)
where
    R: BufRead,
    W: Write,
{
    let mut lines = reader.lines();
    let n: i32 = lines.next().unwrap().unwrap().parse().unwrap();
    let a: i32 = lines.next().unwrap().unwrap().parse().unwrap();

    let ans = if n % 500 <= a { "Yes" } else { "No" };

    writeln!(&mut writer, "{}", ans).unwrap();
}

fn main() {
    let stdio = io::stdin();
    let input = stdio.lock();

    let stdout = io::stdout();
    let output = BufWriter::new(stdout.lock());

    solve(input, output);
}

#[cfg(test)]
mod tests {
    use super::*;

    const TESTS: &'static [(&'static [u8], &'static [u8])] = &[
        (
            br"2018
218", br"Yes
",
        ),
        (
            br"2763
0", br"No
",
        ),
        (
            br"37
514", br"Yes
",
        ),
    ];

    #[test]
    fn test_a() {
        for &(input, expected) in TESTS {
            let mut output = Vec::new();
            solve(input, &mut output);
            let expected_str = String::from_utf8(expected.to_vec()).unwrap();
            let output_str = String::from_utf8(output).unwrap();
            assert_eq!(expected_str, output_str);
        }
    }
}


Measured memory_bytes: 4352
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <queue>
#include <tuple>
#include <cstring>
#include <cctype>
#include <ctype.h>
#include <ios>
#include <iomanip>

#define INF 200000000
#define MOD 1000000007

using namespace std;

int main()
{
    string s;
    cin >> s;
    string ans;
    int now = 0;
    for (int i = 0; i < s.length(); i++)
    {
        if (s[i] == '0')
        {
            ans.insert(now, "0");
            //cout << ans << endl;
            now++;
        }
        if (s[i] == '1')
        {
            ans.insert(now, "1");
            //cout << ans << endl;
            now++;
        }
        if (s[i] == 'B')
        {
            if (ans.size() != 0)
            {
                ans.pop_back();
            }
            if (now > 0)
                now--;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef pair<int,int> P;
 
const int INF = 1e9;
const int mod = 1e9+7;
const double EPS = 1e-10;
const double PI = acos(-1.0);

int prime[100010];
int cnt[100010];

int main()
{
    for(int i = 2; i <= 100000; i++){
        if(!prime[i]){
            ll tmp = i * 2;
            for(int j = 3; tmp <= 100000; j++){
                prime[tmp] = 1;
                tmp = i * j;
            }
        }
    }
    for(int i = 3; i <= 100000; i+=2){
        cnt[i] = cnt[i-2];
        if(!prime[i] && !prime[(i+1)/2]) cnt[i]++;
    }
    int q;
    cin >> q;
    for(int i = 0; i < q; i++){
        int l,r;
        cin >> l >> r;
        cout << cnt[r]-cnt[l-2] << endl;
    }
    return 0;
}

Measured memory_bytes: 1536
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define rep2(i, a, n) for(ll i = a; i < (ll)(n); i++)
#define memi cout << endl
#define kono(n) cout << fixed << setprecision(n)
#define all(c) (c).begin(), (c).end()
#define pb push_back
#define hina cout << ' '
#define in(n) cin >> n
#define in2(n, m) cin >> n >> m
#define in3(n, m, l) cin >> n >> m >> l
#define out(n) cout << n
const ll mei = (ll)1e9 + 7;

int main(){
  double a, b, x, y;
  in2(a, b);
  in2(x, y);
  kono(10);
  out(a * b / 2);
  hina;
  if(x == 0 || x == a || y == 0 || y == b){
    out(0);
    memi;
    return 0;
  }
  if(x == a / 2){
    if(y == b / 2){
      out(1);
      memi;
    }
    else{
      out(0);
      memi;
    }
  }
  else if(y == b / 2){
    out(0);
    memi;
  }
  else{
    out(0);
    memi;
  }
}

Measured memory_bytes: 256
#include <stdio.h>
int main(void){
	int H,W,c[10][10],i,j,k;
	scanf("%d%d",&H,&W);
	for(i=0;i<10;i++)for(j=0;j<10;j++)scanf("%d",&c[i][j]);
		
	
	for(k=0;k<10;k++){
		for(i=0;i<10;i++){
			for(j=0;j<10;j++){
				int tmp = c[i][k]+c[k][j];
				if(tmp<c[i][j])c[i][j] = tmp;
			}
		}
	}
	
	int ans=0;
	for(i=0;i<H;i++){
		for(j=0;j<W;j++){
			int a;
			scanf("%d",&a);
			if(a>=0)ans +=c[a][1];
		}
	}
	printf("%d",ans);
	
	return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<cmath>
int main() {
	using namespace std;
	int len;
	cin >> len;
	int* prime = new int[len];
	int* num = new int[len];
	int count = 0;
	for (int i = 0; i < len; i++) {
		cin >> num[i];
		int isprime = 1;
		for (int j = 0; j < count; j++) {
			if (num[i] % prime[j] == 0 && num[i] != prime[j]) {
				isprime = 0;
				break;
			}
		}
		if (!isprime) 
			continue;
		for (int j = 2; j <= sqrt(num[i]); j++) {
			if (num[i] % j == 0 && num[i]!=j ) {
				isprime = 0;
				break;
			}
		}
		if (isprime) 
			prime[count++] = num[i];
	}
	cout << count << endl;
	return 0;
}


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

#define endl '\n'

using namespace std;

int main(){

  cin.tie(0);     // cout と cin の同期を切る
  ios::sync_with_stdio(false);  /* cの stdioストリーム (printfとか)と*/

  char buf[256];
 
  while(1){

    int a=0;
    double b=0;

    fgets(buf,sizeof(buf),stdin);
    sscanf(buf,"%d%lf",&a,&b);

    if(a<0){
      break;
    }
      
    int temp=128;
    int ans[8]={ };
    for(int i=0;i<8;i++){

      if(a>=temp){
	a-=temp;
	ans[i]=1;
      }
      temp/=2;
    }

    double tmp=0.5;

    int ans1[4]={ };
    for(int i=0;i<4;i++){
      if(b>=tmp){
	b-=tmp;
	ans1[i]=1;
      }
      tmp/=2;
    }

    if(a==0&&b==0){

      for(int i=0;i<8;i++){
	cout<<ans[i];
      }
      cout<<".";
      for(int i=0;i<4;i++){
	cout<<ans1[i];
      }
      cout<<endl;
    }else{
      cout<<"NA"<<endl;
    }

  }
  

  return 0;

}



Measured memory_bytes: 3212
#include <bits/stdc++.h>
using namespace std;
long long a[200001], sum[200001], n, x, ans;
double s;
int main()
{
	scanf("%d", &n);
	for (register long long i=1; i<=n; ++i)
	{
		scanf("%d", &a[i]);
		++sum[a[i]];
	}
	for (register long long i=1; i<=n; ++i)
		if (sum[a[i]]>=2) s+=(sum[a[i]]-1)*1.0/2;
	x=s; 
	for (register long long i=1; i<=n; ++i)
	{
		ans=x-(sum[a[i]])*(sum[a[i]]-1)/2;
		ans+=(sum[a[i]]-1)*(sum[a[i]]-2)/2;
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 4736
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <map>
#include <unordered_map>
#include <utility>
#include <algorithm>
#include <set>
#include <cmath>
#include <array>
#include <bitset>
using namespace std;
typedef long long ll;
const ll mod=1000000007;
#define rep(i,n) for(int i=0;i<n;i++)
#define Rep(i,a,b) for(int i=a;i<b+1;i++)
#define Per(i,b,a) for(int i=b;i>=a;i--)

int order(int n){
    int ans = 0;
    while(n!=0){
        n = n/2;
        ans+=n;
    }
    return ans;
}

bool check(int n,int *a){
    int orders[1000000];
    rep(i,n) orders[i] = order(i);
    int ans = 0;
    rep(i,n){
        ans += a[i] * (orders[n-1]==(orders[i]+orders[n-1-i]));
    } 
    return ans&1;
}

bool exist1(int n,int *a){
    rep(i,n){
        if(a[i] == 1) return true;
    }
    return false;
}
int main(){
    int N;
    cin>>N;
    string S;
    cin>>S;
    int a[1000000];
    rep(i,N){
        a[i] = S[i] - '1';
    }
    if(!check(N,a)){
        if(exist1(N,a)) cout<<0<<endl;
        else{
            rep(i,N) a[i] = a[i]/2;
            cout<<check(N,a)*2<<endl;
        }
    }else{
        cout<<1<<endl;
    }
    return 0;
}

Measured memory_bytes: 9220
n, y = map(int, input().split())
ans=[]
flag=True
for i in range(n+1):
    for j in range(n+1):
        if i+j<=n:
            k=n-i-j
        else:
            k=0
        if 10000*i+5000*j+1000*k==y and i+j+k==n:
            ans+=i,j,k
            flag=False
            break
    if flag==False:
        break

if len(ans)==0:
    ans+=-1,-1,-1

print(ans[0],ans[1],ans[2])

Measured memory_bytes: 67544
(function (chunk) {
    var line = chunk.split("\n");
    var N = Number(line[0]);
    var A = line[1].split(/ /).map(Number);
    
    console.log(A.join(" "));
    
    // insertion sort
    var i, v, j;
    for (i = 1; i < N; i++) {
        v = A[i];
        j = i - 1;
        while (j >= 0 && A[j] > v) {
            A[j + 1] = A[j];
            j--;
        }
        A[j + 1] = v;
        console.log(A.join(" "));
    }
})(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 16788
import java.util.*;
import java.math.*;
import java.io.*;


public class Main {
    static Scanner sc = new Scanner(System.in);
    public static void main(String args[]) {
        int n = sc.nextInt();
        int[] p = new int[n];
        for(int i = 0; i < n; i++) p[i] = sc.nextInt();
        boolean ans = false;
        boolean ok = true;
        for(int i = 0; i < n; i++) {
            for(int j = 0; j < n; j++) {
                int tmp = p[i];
                p[i] = p[j];
                p[j] = tmp;
                ok = true;


                for(int k = 0; k < n - 1; k++) {
                    if(p[k] >= p[k + 1]) {
                        ok = false;
                        break;
                    }
                }
                ans |= ok;
                p[j] = p[i];
                p[i] = tmp;
            }
        }

        System.out.println(ans?"YES":"NO");

    } 
}

Measured memory_bytes: 23636
import java.util.Scanner;
public class Main {
	public static void main(String[] args){
		Scanner sc=new Scanner(System.in);
		int a=0;
		int b=0;
		int o=0;
		int ab=0;
		while(sc.hasNext()){
			String blood=sc.next().split(",")[1];
			if(blood.equals("A")){
				a++;
			}
			if(blood.equals("B")){
				b++;
			}
			if(blood.equals("O")){
				o++;
			}
			if(blood.equals("AB")){
				ab++;
			}
		}
		System.out.println(a);
		System.out.println(b);
		System.out.println(ab);
		System.out.println(o);
	}
}

Measured memory_bytes: 17156
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;


public class C
{
	public static void Main()
	{
		string[] args;
		
		args = Console.ReadLine().Split(' ');
		int N = Int32.Parse(args[0]);
		int K = Int32.Parse(args[1]);
		
		Console.ReadLine();

		Console.WriteLine((N + K - 3)/(K - 1));
	}	
}





Measured memory_bytes: 13152